blob: e1a029964279952bb32d907767088ab0387f0aaf [file] [log] [blame]
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001/*
Jeff Brown37df39a92015-02-25 15:42:31 -08002 * Copyright (C) 2006 The Android Open Source Project
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
Jorim Jaggib10e33f2015-02-04 21:57:40 +010017package com.android.server.policy;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -080018
Wale Ogunwale3797c222015-10-27 14:21:58 -070019import static android.app.ActivityManager.StackId.DOCKED_STACK_ID;
20import static android.app.ActivityManager.StackId.FREEFORM_WORKSPACE_STACK_ID;
Jorim Jaggi86905582016-02-09 21:36:09 -080021import static android.app.ActivityManager.StackId.FULLSCREEN_WORKSPACE_STACK_ID;
22import static android.app.ActivityManager.StackId.HOME_STACK_ID;
Jaewan Kim49117872016-01-19 17:24:08 +090023import static android.content.pm.PackageManager.FEATURE_PICTURE_IN_PICTURE;
24import static android.content.pm.PackageManager.FEATURE_TELEVISION;
25import static android.content.pm.PackageManager.FEATURE_WATCH;
Sriram Viswanathan9ebbe6a2015-11-16 17:59:22 -080026import static android.content.res.Configuration.UI_MODE_TYPE_CAR;
27import static android.content.res.Configuration.UI_MODE_TYPE_MASK;
Jorim Jaggi5060bd82016-02-19 17:12:19 -080028import static android.view.WindowManager.DOCKED_TOP;
29import static android.view.WindowManager.DOCKED_LEFT;
30import static android.view.WindowManager.DOCKED_RIGHT;
Wale Ogunwale6e94a9e2015-10-07 15:35:49 -070031import static android.view.WindowManager.LayoutParams.*;
Jaewan Kim49117872016-01-19 17:24:08 +090032import static android.view.WindowManagerPolicy.WindowManagerFuncs.CAMERA_LENS_COVERED;
Wale Ogunwale6e94a9e2015-10-07 15:35:49 -070033import static android.view.WindowManagerPolicy.WindowManagerFuncs.CAMERA_LENS_COVER_ABSENT;
34import static android.view.WindowManagerPolicy.WindowManagerFuncs.CAMERA_LENS_UNCOVERED;
Jaewan Kim49117872016-01-19 17:24:08 +090035import static android.view.WindowManagerPolicy.WindowManagerFuncs.LID_ABSENT;
36import static android.view.WindowManagerPolicy.WindowManagerFuncs.LID_CLOSED;
37import static android.view.WindowManagerPolicy.WindowManagerFuncs.LID_OPEN;
Wale Ogunwale6e94a9e2015-10-07 15:35:49 -070038
Svet Ganov9cea80cd2016-02-16 11:47:00 -080039import android.Manifest;
Dianne Hackborna4972e92012-03-14 10:38:05 -070040import android.app.ActivityManager;
Jorim Jaggi86905582016-02-09 21:36:09 -080041import android.app.ActivityManager.StackId;
Jeff Brown061ea992015-04-17 19:55:47 -070042import android.app.ActivityManagerInternal;
43import android.app.ActivityManagerInternal.SleepToken;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -080044import android.app.ActivityManagerNative;
Dianne Hackbornc2293022013-02-06 23:14:49 -080045import android.app.AppOpsManager;
Daniel Sandler6396c722013-04-16 20:19:09 -040046import android.app.IUiModeManager;
Dianne Hackborn661cd522011-08-22 00:26:20 -070047import android.app.ProgressDialog;
Jeff Brownde7a8ea2012-06-13 18:28:57 -070048import android.app.SearchManager;
John Spurlock97642182013-07-29 17:58:39 -040049import android.app.StatusBarManager;
Dianne Hackborn78968392010-03-04 20:47:56 -080050import android.app.UiModeManager;
Dianne Hackborn39c2d712009-09-22 11:41:31 -070051import android.content.ActivityNotFoundException;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -080052import android.content.BroadcastReceiver;
Daniel Sandler0601eb72011-04-13 01:01:32 -040053import android.content.ComponentName;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -080054import android.content.ContentResolver;
55import android.content.Context;
56import android.content.Intent;
Mike Lockwood1753f7f2009-08-24 14:49:07 -070057import android.content.IntentFilter;
Winson Chung9112ec32011-06-27 13:15:32 -070058import android.content.ServiceConnection;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -080059import android.content.pm.ActivityInfo;
60import android.content.pm.PackageManager;
Daniel Sandler6396c722013-04-16 20:19:09 -040061import android.content.pm.ResolveInfo;
Dianne Hackborn2f0b1752011-05-31 17:59:49 -070062import android.content.res.CompatibilityInfo;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -080063import android.content.res.Configuration;
64import android.content.res.Resources;
65import android.database.ContentObserver;
Dianne Hackbornc777e072010-02-12 13:07:59 -080066import android.graphics.PixelFormat;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -080067import android.graphics.Rect;
Jinsuk Kime601b712015-07-07 08:01:02 +090068import android.hardware.hdmi.HdmiControlManager;
69import android.hardware.hdmi.HdmiPlaybackClient;
70import android.hardware.hdmi.HdmiPlaybackClient.OneTouchPlayCallback;
John Spurlock7b414672014-07-18 13:02:39 -040071import android.media.AudioAttributes;
Michael Jurka7a348952012-02-27 13:07:58 -080072import android.media.AudioManager;
John Spurlock61560172015-02-06 19:46:04 -050073import android.media.AudioSystem;
Michael Jurka7a348952012-02-27 13:07:58 -080074import android.media.IAudioService;
Svetoslav Ganov7befb7d2012-09-27 16:49:23 -070075import android.media.Ringtone;
76import android.media.RingtoneManager;
RoboErik8a2cfc32014-05-16 11:19:38 -070077import android.media.session.MediaSessionLegacyHelper;
Billy Laucbe540f2015-06-25 01:51:44 +010078import android.os.Binder;
Dianne Hackborn38e29a62011-09-18 14:43:08 -070079import android.os.Bundle;
Craig Mautner276a6eb2014-11-04 15:32:57 -080080import android.os.Debug;
Jeff Brown9a538ee2012-08-20 14:56:57 -070081import android.os.FactoryTest;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -080082import android.os.Handler;
83import android.os.IBinder;
Dianne Hackbornb6683c42015-06-18 17:40:33 -070084import android.os.IDeviceIdleController;
Jeff Brown32cbc38552011-12-01 14:01:49 -080085import android.os.Looper;
Dianne Hackbornfc8fa632011-08-17 16:20:47 -070086import android.os.Message;
87import android.os.Messenger;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -080088import android.os.PowerManager;
Nick Armstrong-Crews56ecfcc2015-09-07 21:46:50 -070089import android.os.PowerManagerInternal;
Billy Laucbe540f2015-06-25 01:51:44 +010090import android.os.Process;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -080091import android.os.RemoteException;
92import android.os.ServiceManager;
93import android.os.SystemClock;
94import android.os.SystemProperties;
Dianne Hackbornad7fa7f2011-01-07 14:06:50 -080095import android.os.UEventObserver;
Dianne Hackbornf02b60a2012-08-16 10:48:27 -070096import android.os.UserHandle;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -080097import android.os.Vibrator;
Michael Wright3818c922014-09-02 13:59:07 -070098import android.provider.MediaStore;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -080099import android.provider.Settings;
Jose Lima9546b202014-07-02 17:21:51 -0700100import android.service.dreams.DreamManagerInternal;
John Spurlockc8b46ca2013-04-08 12:59:26 -0400101import android.service.dreams.DreamService;
102import android.service.dreams.IDreamManager;
Michael Wrightdc63f7b2014-08-21 19:05:21 -0700103import android.speech.RecognizerIntent;
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700104import android.telecom.TelecomManager;
Dianne Hackborn81e56d52011-05-26 00:55:58 -0700105import android.util.DisplayMetrics;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800106import android.util.EventLog;
107import android.util.Log;
Jeff Browna41ca772010-08-11 14:46:32 -0700108import android.util.Slog;
Jeff Brown6651a632011-11-28 12:59:11 -0800109import android.util.SparseArray;
Dianne Hackbornf87d1962012-04-04 12:48:24 -0700110import android.view.Display;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800111import android.view.Gravity;
112import android.view.HapticFeedbackConstants;
Dianne Hackborne0f085d2011-11-30 18:41:15 -0800113import android.view.IApplicationToken;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800114import android.view.IWindowManager;
Jeff Browna41ca772010-08-11 14:46:32 -0700115import android.view.InputChannel;
Jeff Brown4d396052010-10-29 21:50:21 -0700116import android.view.InputDevice;
Jeff Brown4952dfd2011-11-30 19:23:22 -0800117import android.view.InputEvent;
Jeff Brown32cbc38552011-12-01 14:01:49 -0800118import android.view.InputEventReceiver;
Jeff Brown6b53e8d2010-11-10 16:03:06 -0800119import android.view.KeyCharacterMap;
Craig Mautnerae446592012-12-06 19:05:05 -0800120import android.view.KeyCharacterMap.FallbackAction;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800121import android.view.KeyEvent;
122import android.view.MotionEvent;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800123import android.view.Surface;
124import android.view.View;
125import android.view.ViewConfiguration;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800126import android.view.WindowManager;
Craig Mautnerae446592012-12-06 19:05:05 -0800127import android.view.WindowManagerGlobal;
Craig Mautner8a0da012014-05-31 15:13:37 -0700128import android.view.WindowManagerInternal;
Craig Mautnerae446592012-12-06 19:05:05 -0800129import android.view.WindowManagerPolicy;
Craig Mautnerae446592012-12-06 19:05:05 -0800130import android.view.accessibility.AccessibilityEvent;
Svetoslav8e3feb12014-02-24 13:46:47 -0800131import android.view.accessibility.AccessibilityManager;
Craig Mautnerae446592012-12-06 19:05:05 -0800132import android.view.animation.Animation;
Jorim Jaggi76a16232014-08-08 17:00:47 +0200133import android.view.animation.AnimationSet;
Craig Mautnerae446592012-12-06 19:05:05 -0800134import android.view.animation.AnimationUtils;
Craig Mautnerae446592012-12-06 19:05:05 -0800135import com.android.internal.R;
Jason Monk8f7f3182015-11-18 16:35:14 -0500136import com.android.internal.logging.MetricsLogger;
137import com.android.internal.policy.PhoneWindow;
Craig Mautnerae446592012-12-06 19:05:05 -0800138import com.android.internal.statusbar.IStatusBarService;
Filip Gruszczynski2217f612015-05-26 11:32:08 -0700139import com.android.internal.util.ScreenShapeHelper;
Craig Mautnerae446592012-12-06 19:05:05 -0800140import com.android.internal.widget.PointerLocationView;
Adrian Roos5941c982015-09-03 15:59:49 -0700141import com.android.server.GestureLauncherService;
Craig Mautner8a0da012014-05-31 15:13:37 -0700142import com.android.server.LocalServices;
Jorim Jaggib10e33f2015-02-04 21:57:40 +0100143import com.android.server.policy.keyguard.KeyguardServiceDelegate;
Jorim Jaggi4cfdcf52015-07-09 12:13:59 -0700144import com.android.server.policy.keyguard.KeyguardServiceDelegate.DrawnListener;
Jorim Jaggi86905582016-02-09 21:36:09 -0800145import com.android.server.statusbar.StatusBarManagerInternal;
Craig Mautnerae446592012-12-06 19:05:05 -0800146
147import java.io.File;
148import java.io.FileReader;
149import java.io.IOException;
150import java.io.PrintWriter;
Craig Mautner2bc789b2014-03-19 19:48:38 -0700151import java.util.HashSet;
Craig Mautner276a6eb2014-11-04 15:32:57 -0800152import java.util.List;
Craig Mautnerae446592012-12-06 19:05:05 -0800153
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800154/**
The Android Open Source Project0727d222009-03-11 12:11:58 -0700155 * WindowManagerPolicy implementation for the Android phone UI. This
156 * introduces a new method suffix, Lp, for an internal lock of the
157 * PhoneWindowManager. This is used to protect some internal state, and
John Spurlock04db1762013-05-13 12:46:41 -0400158 * 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 -0700159 * of both of those when held.
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800160 */
161public class PhoneWindowManager implements WindowManagerPolicy {
162 static final String TAG = "WindowManager";
163 static final boolean DEBUG = false;
Joe Onorato43a17652011-04-06 19:22:23 -0700164 static final boolean localLOGV = false;
Jeff Brown40013652012-05-16 21:22:36 -0700165 static final boolean DEBUG_INPUT = false;
Craig Mautnerc0d2d0a2014-10-31 16:25:15 -0700166 static final boolean DEBUG_KEYGUARD = false;
167 static final boolean DEBUG_LAYOUT = false;
Craig Mautner6fbda632012-07-03 09:26:39 -0700168 static final boolean DEBUG_STARTING_WINDOW = false;
Craig Mautner8a0da012014-05-31 15:13:37 -0700169 static final boolean DEBUG_WAKEUP = false;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800170 static final boolean SHOW_STARTING_ANIMATIONS = true;
171 static final boolean SHOW_PROCESSES_ON_ALT_MENU = false;
Joe Onoratod208e702010-10-08 16:22:43 -0400172
Daniel Sandler6396c722013-04-16 20:19:09 -0400173 // Whether to allow dock apps with METADATA_DOCK_HOME to temporarily take over the Home key.
keunyounga7710492015-09-23 11:33:58 -0700174 // No longer recommended for desk docks;
Daniel Sandler6396c722013-04-16 20:19:09 -0400175 static final boolean ENABLE_DESK_DOCK_HOME_CAPTURE = false;
176
Jeff Brown6d8fd272014-05-20 21:24:38 -0700177 static final int SHORT_PRESS_POWER_NOTHING = 0;
178 static final int SHORT_PRESS_POWER_GO_TO_SLEEP = 1;
179 static final int SHORT_PRESS_POWER_REALLY_GO_TO_SLEEP = 2;
180 static final int SHORT_PRESS_POWER_REALLY_GO_TO_SLEEP_AND_GO_HOME = 3;
Bryce Lee01b0c5f2015-02-05 18:24:04 -0800181 static final int SHORT_PRESS_POWER_GO_HOME = 4;
Jeff Brown6d8fd272014-05-20 21:24:38 -0700182
Joe Onoratod208e702010-10-08 16:22:43 -0400183 static final int LONG_PRESS_POWER_NOTHING = 0;
184 static final int LONG_PRESS_POWER_GLOBAL_ACTIONS = 1;
185 static final int LONG_PRESS_POWER_SHUT_OFF = 2;
Jeff Brown9a538ee2012-08-20 14:56:57 -0700186 static final int LONG_PRESS_POWER_SHUT_OFF_NO_CONFIRM = 3;
Michael Jurka3b1fc472011-06-13 10:54:40 -0700187
Jeff Brown13f00f02014-10-31 14:45:50 -0700188 static final int MULTI_PRESS_POWER_NOTHING = 0;
189 static final int MULTI_PRESS_POWER_THEATER_MODE = 1;
190 static final int MULTI_PRESS_POWER_BRIGHTNESS_BOOST = 2;
191
Michael Jurka3b1fc472011-06-13 10:54:40 -0700192 // These need to match the documentation/constant in
193 // core/res/res/values/config.xml
Joe Onorato46b0d682010-11-22 17:37:27 -0800194 static final int LONG_PRESS_HOME_NOTHING = 0;
Michael Wrightc9ebea72013-01-16 19:25:02 -0800195 static final int LONG_PRESS_HOME_RECENT_SYSTEM_UI = 1;
Jeff Browncaca8812013-05-09 13:34:33 -0700196 static final int LONG_PRESS_HOME_ASSIST = 2;
Jaewan Kim76b7d0d2016-02-12 19:01:02 +0900197 static final int LAST_LONG_PRESS_HOME_BEHAVIOR = LONG_PRESS_HOME_ASSIST;
Jeff Browncaca8812013-05-09 13:34:33 -0700198
199 static final int DOUBLE_TAP_HOME_NOTHING = 0;
200 static final int DOUBLE_TAP_HOME_RECENT_SYSTEM_UI = 1;
Joe Onorato46b0d682010-11-22 17:37:27 -0800201
Jaewan Kim49117872016-01-19 17:24:08 +0900202 static final int SHORT_PRESS_WINDOW_NOTHING = 0;
203 static final int SHORT_PRESS_WINDOW_PICTURE_IN_PICTURE = 1;
204
Filip Gruszczynskia483a1d2015-03-17 19:06:58 +0000205 static final int SHORT_PRESS_SLEEP_GO_TO_SLEEP = 0;
206 static final int SHORT_PRESS_SLEEP_GO_TO_SLEEP_AND_GO_HOME = 1;
207
Dianne Hackborn5cb8d792009-05-21 17:34:15 -0700208 static final int APPLICATION_MEDIA_SUBLAYER = -2;
209 static final int APPLICATION_MEDIA_OVERLAY_SUBLAYER = -1;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800210 static final int APPLICATION_PANEL_SUBLAYER = 1;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800211 static final int APPLICATION_SUB_PANEL_SUBLAYER = 2;
Wale Ogunwale0a4dc222015-04-14 12:58:42 -0700212 static final int APPLICATION_ABOVE_SUB_PANEL_SUBLAYER = 3;
Craig Mautner88400d32012-09-30 12:35:45 -0700213
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800214 static public final String SYSTEM_DIALOG_REASON_KEY = "reason";
215 static public final String SYSTEM_DIALOG_REASON_GLOBAL_ACTIONS = "globalactions";
216 static public final String SYSTEM_DIALOG_REASON_RECENT_APPS = "recentapps";
Joe Onoratof275f0c2009-11-24 16:11:13 -0500217 static public final String SYSTEM_DIALOG_REASON_HOME_KEY = "homekey";
Jeff Brownde7a8ea2012-06-13 18:28:57 -0700218 static public final String SYSTEM_DIALOG_REASON_ASSIST = "assist";
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800219
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -0700220 /**
221 * These are the system UI flags that, when changing, can cause the layout
222 * of the screen to change.
223 */
224 static final int SYSTEM_UI_CHANGING_LAYOUT =
John Spurlocke1f366f2013-08-05 12:22:40 -0400225 View.SYSTEM_UI_FLAG_HIDE_NAVIGATION
John Spurlock7f4820a2013-10-08 12:54:35 -0400226 | View.SYSTEM_UI_FLAG_FULLSCREEN
227 | View.STATUS_BAR_TRANSLUCENT
Adrian Roosea562512014-05-05 13:33:03 +0200228 | View.NAVIGATION_BAR_TRANSLUCENT
Jorim Jaggi4fa78922015-11-30 17:13:56 -0800229 | View.STATUS_BAR_TRANSPARENT
230 | View.NAVIGATION_BAR_TRANSPARENT;
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -0700231
John Spurlock7b414672014-07-18 13:02:39 -0400232 private static final AudioAttributes VIBRATION_ATTRIBUTES = new AudioAttributes.Builder()
233 .setContentType(AudioAttributes.CONTENT_TYPE_SONIFICATION)
234 .setUsage(AudioAttributes.USAGE_ASSISTANCE_SONIFICATION)
235 .build();
236
Adrian Roosddc8b272015-05-21 16:28:27 -0700237 // The panic gesture may become active only after the keyguard is dismissed and the immersive
238 // app shows again. If that doesn't happen for 30s we drop the gesture.
239 private static final long PANIC_GESTURE_EXPIRATION = 30000;
240
Jim Miller5ecd8112013-01-09 18:50:26 -0800241 /**
242 * Keyguard stuff
243 */
244 private WindowState mKeyguardScrim;
Jorim Jaggi380ecb82014-03-14 17:25:20 +0100245 private boolean mKeyguardHidden;
Jeff Brown3ee549c2014-09-22 20:14:39 -0700246 private boolean mKeyguardDrawnOnce;
Jim Miller5ecd8112013-01-09 18:50:26 -0800247
Jeff Brown6651a632011-11-28 12:59:11 -0800248 /* Table of Application Launch keys. Maps from key codes to intent categories.
249 *
250 * These are special keys that are used to launch particular kinds of applications,
251 * such as a web browser. HID defines nearly a hundred of them in the Consumer (0x0C)
252 * usage page. We don't support quite that many yet...
253 */
254 static SparseArray<String> sApplicationLaunchKeyCategories;
255 static {
256 sApplicationLaunchKeyCategories = new SparseArray<String>();
257 sApplicationLaunchKeyCategories.append(
258 KeyEvent.KEYCODE_EXPLORER, Intent.CATEGORY_APP_BROWSER);
259 sApplicationLaunchKeyCategories.append(
260 KeyEvent.KEYCODE_ENVELOPE, Intent.CATEGORY_APP_EMAIL);
261 sApplicationLaunchKeyCategories.append(
262 KeyEvent.KEYCODE_CONTACTS, Intent.CATEGORY_APP_CONTACTS);
263 sApplicationLaunchKeyCategories.append(
264 KeyEvent.KEYCODE_CALENDAR, Intent.CATEGORY_APP_CALENDAR);
265 sApplicationLaunchKeyCategories.append(
266 KeyEvent.KEYCODE_MUSIC, Intent.CATEGORY_APP_MUSIC);
267 sApplicationLaunchKeyCategories.append(
268 KeyEvent.KEYCODE_CALCULATOR, Intent.CATEGORY_APP_CALCULATOR);
269 }
270
Craig Mautnerc3daedd2014-09-13 11:17:23 -0700271 /** Amount of time (in milliseconds) to wait for windows drawn before powering on. */
Jorim Jaggi0d210f62015-07-10 14:24:44 -0700272 static final int WAITING_FOR_DRAWN_TIMEOUT = 1000;
Craig Mautnerc3daedd2014-09-13 11:17:23 -0700273
Dianne Hackborndf89e652011-10-06 22:35:11 -0700274 /**
275 * Lock protecting internal state. Must not call out into window
276 * manager with lock held. (This lock will be acquired in places
277 * where the window manager is calling in with its own lock held.)
278 */
Craig Mautner0bf6ec92012-12-18 08:33:27 -0800279 private final Object mLock = new Object();
Dianne Hackborndf89e652011-10-06 22:35:11 -0700280
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800281 Context mContext;
282 IWindowManager mWindowManager;
Dianne Hackborndf89e652011-10-06 22:35:11 -0700283 WindowManagerFuncs mWindowManagerFuncs;
Craig Mautner8a0da012014-05-31 15:13:37 -0700284 WindowManagerInternal mWindowManagerInternal;
Jeff Brown96307042012-07-27 15:51:34 -0700285 PowerManager mPowerManager;
Jeff Brown061ea992015-04-17 19:55:47 -0700286 ActivityManagerInternal mActivityManagerInternal;
Jose Lima9546b202014-07-02 17:21:51 -0700287 DreamManagerInternal mDreamManagerInternal;
Michael Wrighta4d22d72015-09-16 23:19:26 +0100288 PowerManagerInternal mPowerManagerInternal;
Joe Onorato93056472010-09-10 10:30:46 -0400289 IStatusBarService mStatusBarService;
Jorim Jaggi86905582016-02-09 21:36:09 -0800290 StatusBarManagerInternal mStatusBarManagerInternal;
Jeff Browncaca8812013-05-09 13:34:33 -0700291 boolean mPreloadedRecentApps;
Dianne Hackborn42e620c2012-06-24 13:20:51 -0700292 final Object mServiceAquireLock = new Object();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800293 Vibrator mVibrator; // Vibrator for giving feedback of orientation changes
Jeff Brownde7a8ea2012-06-13 18:28:57 -0700294 SearchManager mSearchManager;
Svetoslav8e3feb12014-02-24 13:46:47 -0800295 AccessibilityManager mAccessibilityManager;
Filip Gruszczynskicfb31852015-02-25 21:47:12 +0000296 BurnInProtectionHelper mBurnInProtectionHelper;
Billy Laucbe540f2015-06-25 01:51:44 +0100297 AppOpsManager mAppOpsManager;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800298
Dianne Hackborn181ceb52009-08-27 22:16:40 -0700299 // Vibrator pattern for haptic feedback of a long press.
300 long[] mLongPressVibePattern;
Craig Mautner88400d32012-09-30 12:35:45 -0700301
Dianne Hackborn181ceb52009-08-27 22:16:40 -0700302 // Vibrator pattern for haptic feedback of virtual key press.
303 long[] mVirtualKeyVibePattern;
Craig Mautner967212c2013-04-13 21:10:58 -0700304
Amith Yamasanic33cb712010-02-10 15:21:49 -0800305 // Vibrator pattern for a short vibration.
306 long[] mKeyboardTapVibePattern;
307
Fabrice Di Meglioeeff63a2013-08-05 12:07:24 -0700308 // Vibrator pattern for a short vibration when tapping on an hour/minute tick of a Clock.
309 long[] mClockTickVibePattern;
310
Fabrice Di Megliobd9152f2013-10-01 11:21:31 -0700311 // Vibrator pattern for a short vibration when tapping on a day/month/year date of a Calendar.
312 long[] mCalendarDateVibePattern;
313
Dianne Hackbornb1a79802009-09-29 15:18:31 -0700314 // Vibrator pattern for haptic feedback during boot when safe mode is disabled.
315 long[] mSafeModeDisabledVibePattern;
Craig Mautner967212c2013-04-13 21:10:58 -0700316
Dianne Hackbornb1a79802009-09-29 15:18:31 -0700317 // Vibrator pattern for haptic feedback during boot when safe mode is enabled.
318 long[] mSafeModeEnabledVibePattern;
Romain Guy8154cd32010-03-29 14:41:15 -0700319
Mady Mellore8608912015-06-05 09:02:55 -0700320 // Vibrator pattern for haptic feedback of a context click.
321 long[] mContextClickVibePattern;
Mady Mellore82067b2015-04-30 09:58:35 -0700322
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800323 /** If true, hitting shift & menu will broadcast Intent.ACTION_BUG_REPORT */
324 boolean mEnableShiftMenuBugReports = false;
Mike Lockwoodd747dc82011-09-13 16:28:22 -0400325
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800326 boolean mSafeMode;
327 WindowState mStatusBar = null;
Dianne Hackborn69cb8752011-05-19 18:13:32 -0700328 int mStatusBarHeight;
Daniel Sandler8956dbb2011-04-22 07:55:02 -0400329 WindowState mNavigationBar = null;
Daniel Sandler36412a72011-08-04 09:35:13 -0400330 boolean mHasNavigationBar = false;
Dianne Hackbornf87d1962012-04-04 12:48:24 -0700331 boolean mCanHideNavigationBar = false;
Daniel Sandler4a066c52012-04-20 14:49:13 -0400332 boolean mNavigationBarCanMove = false; // can the navigation bar ever move to the side?
333 boolean mNavigationBarOnBottom = true; // is the navigation bar on the bottom *right now*?
Sriram Viswanathan9ebbe6a2015-11-16 17:59:22 -0800334 int[] mNavigationBarHeightForRotationDefault = new int[4];
335 int[] mNavigationBarWidthForRotationDefault = new int[4];
336 int[] mNavigationBarHeightForRotationInCarMode = new int[4];
337 int[] mNavigationBarWidthForRotationInCarMode = new int[4];
Daniel Sandler8956dbb2011-04-22 07:55:02 -0400338
keunyounga7710492015-09-23 11:33:58 -0700339 // Whether to allow dock apps with METADATA_DOCK_HOME to temporarily take over the Home key.
340 // This is for car dock and this is updated from resource.
341 private boolean mEnableCarDockHomeCapture = true;
342
Craig Mautnera631d492014-08-05 15:16:01 -0700343 boolean mBootMessageNeedsHiding;
Jim Miller5ecd8112013-01-09 18:50:26 -0800344 KeyguardServiceDelegate mKeyguardDelegate;
Craig Mautner13f6ea72014-06-23 14:57:02 -0700345 final Runnable mWindowManagerDrawCallback = new Runnable() {
Craig Mautner8a0da012014-05-31 15:13:37 -0700346 @Override
Craig Mautner13f6ea72014-06-23 14:57:02 -0700347 public void run() {
Craig Mautner8a0da012014-05-31 15:13:37 -0700348 if (DEBUG_WAKEUP) Slog.i(TAG, "All windows ready for display!");
349 mHandler.sendEmptyMessage(MSG_WINDOW_MANAGER_DRAWN_COMPLETE);
350 }
351 };
Jorim Jaggi4cfdcf52015-07-09 12:13:59 -0700352 final DrawnListener mKeyguardDrawnCallback = new DrawnListener() {
Craig Mautner8a0da012014-05-31 15:13:37 -0700353 @Override
Jorim Jaggi4cfdcf52015-07-09 12:13:59 -0700354 public void onDrawn() {
355 if (DEBUG_WAKEUP) Slog.d(TAG, "mKeyguardDelegate.ShowListener.onDrawn.");
Craig Mautner8a0da012014-05-31 15:13:37 -0700356 mHandler.sendEmptyMessage(MSG_KEYGUARD_DRAWN_COMPLETE);
357 }
358 };
359
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800360 GlobalActions mGlobalActions;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800361 Handler mHandler;
satok1bc0a492012-04-25 22:47:12 +0900362 WindowState mLastInputMethodWindow = null;
363 WindowState mLastInputMethodTargetWindow = null;
Jeff Brown4aed78b2011-01-14 17:36:55 -0800364
Jeff Brown13f00f02014-10-31 14:45:50 -0700365 // FIXME This state is shared between the input reader and handler thread.
366 // Technically it's broken and buggy but it has been like this for many years
367 // and we have not yet seen any problems. Someday we'll rewrite this logic
368 // so that only one thread is involved in handling input policy. Unfortunately
369 // it's on a critical path for power management so we can't just post the work to the
370 // handler thread. We'll need to resolve this someday by teaching the input dispatcher
371 // to hold wakelocks during dispatch and eliminating the critical path.
372 volatile boolean mPowerKeyHandled;
Bryce Leed9268e32014-11-17 17:40:59 -0800373 volatile boolean mBeganFromNonInteractive;
Jeff Brown13f00f02014-10-31 14:45:50 -0700374 volatile int mPowerKeyPressCounter;
375 volatile boolean mEndCallKeyHandled;
376
Winson Chungd42a6cf2014-06-03 16:24:04 -0700377 boolean mRecentsVisible;
Winson Chung1e8d71b2014-05-16 17:05:22 -0700378 int mRecentAppsHeldModifiers;
Jeff Browncf39bdf2012-05-18 14:41:19 -0700379 boolean mLanguageSwitchKeyPressed;
Jeff Brown68b909d2011-12-07 16:36:01 -0800380
Jeff Brown2e7760e2012-04-11 15:14:55 -0700381 int mLidState = LID_ABSENT;
Michael Wright3818c922014-09-02 13:59:07 -0700382 int mCameraLensCoverState = CAMERA_LENS_COVER_ABSENT;
Jeff Browndaa37532012-05-01 15:54:03 -0700383 boolean mHaveBuiltInKeyboard;
Jeff Brown4aed78b2011-01-14 17:36:55 -0800384
Dianne Hackbornc777e072010-02-12 13:07:59 -0800385 boolean mSystemReady;
Dianne Hackbornba24e4d2011-09-01 11:17:06 -0700386 boolean mSystemBooted;
Adrian Roos3542f7d2015-07-13 15:57:53 -0700387 private boolean mDeferBindKeyguard;
Dianne Hackbornad7fa7f2011-01-07 14:06:50 -0800388 boolean mHdmiPlugged;
Jinsuk Kime601b712015-07-07 08:01:02 +0900389 HdmiControl mHdmiControl;
Jeff Brown4f5fa282014-06-12 19:19:15 -0700390 IUiModeManager mUiModeManager;
Daniel Sandler6396c722013-04-16 20:19:09 -0400391 int mUiMode;
Dianne Hackborn867ab6472010-04-29 13:28:56 -0700392 int mDockMode = Intent.EXTRA_DOCK_STATE_UNDOCKED;
Mike Lockwood1753f7f2009-08-24 14:49:07 -0700393 int mLidOpenRotation;
Mike Lockwood2d1efbd2009-09-16 12:15:53 -0400394 int mCarDockRotation;
395 int mDeskDockRotation;
Jeff Brownc82c89ed2013-04-17 17:18:15 -0700396 int mUndockedHdmiRotation;
397 int mDemoHdmiRotation;
398 boolean mDemoHdmiRotationLock;
Chong Zhangae6119ff2014-11-11 18:54:39 -0800399 int mDemoRotation;
400 boolean mDemoRotationLock;
Daniel Sandlerb73617d2010-08-17 00:41:00 -0400401
Jeff Browna20dda42014-05-27 20:57:24 -0700402 boolean mWakeGestureEnabledSetting;
403 MyWakeGestureListener mWakeGestureListener;
404
Craig Mautner46ac6fa2013-08-01 10:06:34 -0700405 // Default display does not rotate, apps that require non-default orientation will have to
406 // have the orientation emulated.
407 private boolean mForceDefaultOrientation = false;
408
Daniel Sandlerb73617d2010-08-17 00:41:00 -0400409 int mUserRotationMode = WindowManagerPolicy.USER_ROTATION_FREE;
410 int mUserRotation = Surface.ROTATION_0;
Jeff Brown207673cd2012-06-05 17:47:11 -0700411 boolean mAccelerometerDefault;
Daniel Sandlerb73617d2010-08-17 00:41:00 -0400412
Jeff Brownbcdfc622014-03-06 19:13:04 -0800413 boolean mSupportAutoRotation;
Jeff Brownd3187e32011-09-21 19:26:44 -0700414 int mAllowAllRotations = -1;
Mike Lockwoode9867d22009-09-20 01:59:02 -0400415 boolean mCarDockEnablesAccelerometer;
416 boolean mDeskDockEnablesAccelerometer;
Dianne Hackborn2862fff2009-09-15 22:56:29 -0700417 int mLidKeyboardAccessibility;
418 int mLidNavigationAccessibility;
Edward Savage-Jones7def60d2015-11-13 13:27:03 +0100419 boolean mLidControlsScreenLock;
Jeff Brownc458ce92012-04-30 14:58:40 -0700420 boolean mLidControlsSleep;
Jeff Brown13f00f02014-10-31 14:45:50 -0700421 int mShortPressOnPowerBehavior;
422 int mLongPressOnPowerBehavior;
423 int mDoublePressOnPowerBehavior;
424 int mTriplePressOnPowerBehavior;
Filip Gruszczynskia483a1d2015-03-17 19:06:58 +0000425 int mShortPressOnSleepBehavior;
Jaewan Kim49117872016-01-19 17:24:08 +0900426 int mShortPressWindowBehavior;
Jeff Brown3ee549c2014-09-22 20:14:39 -0700427 boolean mAwake;
428 boolean mScreenOnEarly;
429 boolean mScreenOnFully;
430 ScreenOnListener mScreenOnListener;
431 boolean mKeyguardDrawComplete;
432 boolean mWindowManagerDrawComplete;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800433 boolean mOrientationSensorEnabled = false;
434 int mCurrentAppOrientation = ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800435 boolean mHasSoftInput = false;
Daniel Sandlerdd73ee42013-10-11 22:19:59 -0400436 boolean mTranslucentDecorEnabled = true;
RoboErik001c59c2015-01-26 15:53:51 -0800437 boolean mUseTvRouting;
Craig Mautner967212c2013-04-13 21:10:58 -0700438
Jeff Brown70825162012-03-28 17:27:48 -0700439 int mPointerLocationMode = 0; // guarded by mLock
Joe Onorato664644d2011-01-23 17:53:23 -0800440
441 // The last window we were told about in focusChanged.
442 WindowState mFocusedWindow;
Dianne Hackborne0f085d2011-11-30 18:41:15 -0800443 IApplicationToken mFocusedApp;
Joe Onorato664644d2011-01-23 17:53:23 -0800444
Jeff Brown70825162012-03-28 17:27:48 -0700445 PointerLocationView mPointerLocationView;
Jeff Brown32cbc38552011-12-01 14:01:49 -0800446
Dianne Hackbornc652de82013-02-15 16:32:56 -0800447 // The current size of the screen; really; extends into the overscan area of
448 // the screen and doesn't account for any system elements like the status bar.
449 int mOverscanScreenLeft, mOverscanScreenTop;
450 int mOverscanScreenWidth, mOverscanScreenHeight;
451 // The current visible size of the screen; really; (ir)regardless of whether the status
452 // bar can be hidden but not extending into the overscan area.
Joe Onorato29fc2c92010-11-24 10:26:50 -0800453 int mUnrestrictedScreenLeft, mUnrestrictedScreenTop;
454 int mUnrestrictedScreenWidth, mUnrestrictedScreenHeight;
Dianne Hackborn313440842013-02-19 19:22:59 -0800455 // Like mOverscanScreen*, but allowed to move into the overscan region where appropriate.
456 int mRestrictedOverscanScreenLeft, mRestrictedOverscanScreenTop;
457 int mRestrictedOverscanScreenWidth, mRestrictedOverscanScreenHeight;
Dianne Hackborn82de1ae2010-10-28 11:28:39 -0700458 // The current size of the screen; these may be different than (0,0)-(dw,dh)
459 // if the status bar can't be hidden; in that case it effectively carves out
460 // that area of the display from all other windows.
Joe Onorato29fc2c92010-11-24 10:26:50 -0800461 int mRestrictedScreenLeft, mRestrictedScreenTop;
462 int mRestrictedScreenWidth, mRestrictedScreenHeight;
Dianne Hackborn5c58de32012-04-28 19:52:37 -0700463 // During layout, the current screen borders accounting for any currently
464 // visible system UI elements.
465 int mSystemLeft, mSystemTop, mSystemRight, mSystemBottom;
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -0700466 // For applications requesting stable content insets, these are them.
467 int mStableLeft, mStableTop, mStableRight, mStableBottom;
Dianne Hackborn5b5cc4d2012-05-16 13:15:00 -0700468 // For applications requesting stable content insets but have also set the
469 // fullscreen window flag, these are the stable dimensions without the status bar.
470 int mStableFullscreenLeft, mStableFullscreenTop;
471 int mStableFullscreenRight, mStableFullscreenBottom;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800472 // During layout, the current screen borders with all outer decoration
473 // (status bar, input method dock) accounted for.
474 int mCurLeft, mCurTop, mCurRight, mCurBottom;
475 // During layout, the frame in which content should be displayed
476 // to the user, accounting for all screen decoration except for any
477 // space they deem as available for other content. This is usually
478 // the same as mCur*, but may be larger if the screen decor has supplied
479 // content insets.
480 int mContentLeft, mContentTop, mContentRight, mContentBottom;
Dianne Hackborne30e02f2014-05-27 18:24:45 -0700481 // During layout, the frame in which voice content should be displayed
482 // to the user, accounting for all screen decoration except for any
483 // space they deem as available for other content.
484 int mVoiceContentLeft, mVoiceContentTop, mVoiceContentRight, mVoiceContentBottom;
Dianne Hackborn8e11ef02010-11-18 19:47:42 -0800485 // During layout, the current screen borders along which input method
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800486 // windows are placed.
487 int mDockLeft, mDockTop, mDockRight, mDockBottom;
488 // During layout, the layer at which the doc window is placed.
489 int mDockLayer;
Dianne Hackborn5c58de32012-04-28 19:52:37 -0700490 // During layout, this is the layer of the status bar.
491 int mStatusBarLayer;
Dianne Hackborne26ab702011-10-16 13:21:33 -0700492 int mLastSystemUiFlags;
493 // Bits that we are in the process of clearing, so we want to prevent
494 // them from being set by applications until everything has been updated
495 // to have them clear.
496 int mResettingSystemUiFlags = 0;
497 // Bits that we are currently always keeping cleared.
498 int mForceClearedSystemUiFlags = 0;
Jorim Jaggi86905582016-02-09 21:36:09 -0800499 int mLastFullscreenStackSysUiFlags;
500 int mLastDockedStackSysUiFlags;
501 final Rect mNonDockedStackBounds = new Rect();
502 final Rect mDockedStackBounds = new Rect();
503 final Rect mLastNonDockedStackBounds = new Rect();
504 final Rect mLastDockedStackBounds = new Rect();
505
Dianne Hackborn4eff8d32011-11-10 19:38:40 -0800506 // What we last reported to system UI about whether the compatibility
507 // menu needs to be displayed.
508 boolean mLastFocusNeedsMenu = false;
Adrian Roosddc8b272015-05-21 16:28:27 -0700509 // If nonzero, a panic gesture was performed at that time in uptime millis and is still pending.
510 private long mPendingPanicGestureUptime;
Dianne Hackborndf89e652011-10-06 22:35:11 -0700511
Selim Cinekf83e8242015-05-19 18:08:14 -0700512 InputConsumer mInputConsumer = null;
Dianne Hackborndf89e652011-10-06 22:35:11 -0700513
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800514 static final Rect mTmpParentFrame = new Rect();
515 static final Rect mTmpDisplayFrame = new Rect();
Dianne Hackbornc4aad012013-02-22 15:05:25 -0800516 static final Rect mTmpOverscanFrame = new Rect();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800517 static final Rect mTmpContentFrame = new Rect();
518 static final Rect mTmpVisibleFrame = new Rect();
John Spurlock46646232013-09-30 22:32:42 -0400519 static final Rect mTmpDecorFrame = new Rect();
Adrian Roosfa104232014-06-20 16:10:14 -0700520 static final Rect mTmpStableFrame = new Rect();
Dianne Hackborn1f903c32011-09-13 19:18:06 -0700521 static final Rect mTmpNavigationFrame = new Rect();
Filip Gruszczynski2217f612015-05-26 11:32:08 -0700522 static final Rect mTmpOutsetFrame = new Rect();
Craig Mautner967212c2013-04-13 21:10:58 -0700523
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800524 WindowState mTopFullscreenOpaqueWindowState;
Adrian Rooscd3884d2015-02-18 17:25:23 +0100525 WindowState mTopFullscreenOpaqueOrDimmingWindowState;
Jorim Jaggi86905582016-02-09 21:36:09 -0800526 WindowState mTopDockedOpaqueWindowState;
527 WindowState mTopDockedOpaqueOrDimmingWindowState;
Craig Mautner2bc789b2014-03-19 19:48:38 -0700528 HashSet<IApplicationToken> mAppsToBeHidden = new HashSet<IApplicationToken>();
Jorim Jaggic13fcac2014-09-11 17:36:57 +0200529 HashSet<IApplicationToken> mAppsThatDismissKeyguard = new HashSet<IApplicationToken>();
Joe Onorato93056472010-09-10 10:30:46 -0400530 boolean mTopIsFullscreen;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800531 boolean mForceStatusBar;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -0700532 boolean mForceStatusBarFromKeyguard;
Selim Cinek4a4a2bddc2015-05-07 12:50:19 -0700533 private boolean mForceStatusBarTransparent;
Dianne Hackborn39c2d712009-09-22 11:41:31 -0700534 boolean mHideLockScreen;
Dianne Hackborn891d3fb2013-01-09 18:31:37 -0800535 boolean mForcingShowNavBar;
536 int mForcingShowNavBarLayer;
Craig Mautnerad09bcc2012-10-08 13:33:11 -0700537
538 // States of keyguard dismiss.
539 private static final int DISMISS_KEYGUARD_NONE = 0; // Keyguard not being dismissed.
540 private static final int DISMISS_KEYGUARD_START = 1; // Keyguard needs to be dismissed.
541 private static final int DISMISS_KEYGUARD_CONTINUE = 2; // Keyguard has been dismissed.
542 int mDismissKeyguard = DISMISS_KEYGUARD_NONE;
543
544 /** The window that is currently dismissing the keyguard. Dismissing the keyguard must only
545 * be done once per window. */
546 private WindowState mWinDismissingKeyguard;
547
tingna_sunge785ffa2015-05-12 13:23:15 +0800548 /** When window is currently dismissing the keyguard, dismissing the keyguard must handle
549 * the keygaurd secure state change instantly case, e.g. the use case of inserting a PIN
550 * lock SIM card. This variable is used to record the previous keyguard secure state for
551 * monitoring secure state change on window dismissing keyguard. */
552 private boolean mSecureDismissingKeyguard;
553
Craig Mautnerc9457fa2014-06-06 14:27:48 -0700554 /** The window that is currently showing "over" the keyguard. If there is an app window
555 * belonging to another app on top of this the keyguard shows. If there is a fullscreen
556 * app window under this, still dismiss the keyguard but don't show the app underneath. Show
557 * the wallpaper. */
558 private WindowState mWinShowWhenLocked;
559
Dianne Hackborn7ad44382012-10-18 17:46:00 -0700560 boolean mShowingLockscreen;
561 boolean mShowingDream;
562 boolean mDreamingLockscreen;
Jeff Brown061ea992015-04-17 19:55:47 -0700563 boolean mDreamingSleepTokenNeeded;
564 SleepToken mDreamingSleepToken;
Jeff Brown48d1b142015-06-10 16:36:03 -0700565 SleepToken mScreenOffSleepToken;
Jim Millerab954542014-10-10 18:21:49 -0700566 boolean mKeyguardSecure;
567 boolean mKeyguardSecureIncludingHidden;
568 volatile boolean mKeyguardOccluded;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800569 boolean mHomePressed;
Jeff Browncaca8812013-05-09 13:34:33 -0700570 boolean mHomeConsumed;
571 boolean mHomeDoubleTapPending;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800572 Intent mHomeIntent;
Dianne Hackborn39c2d712009-09-22 11:41:31 -0700573 Intent mCarDockIntent;
574 Intent mDeskDockIntent;
Jeff Brownfd23e3e2012-05-09 13:34:28 -0700575 boolean mSearchKeyShortcutPending;
576 boolean mConsumeSearchKeyUp;
Jeff Brownde7a8ea2012-06-13 18:28:57 -0700577 boolean mAssistKeyLongPressed;
Michael Wright6a62e552014-06-03 19:19:48 -0700578 boolean mPendingMetaAction;
Jorim Jaggi0ffd49c2016-02-12 15:04:21 -0800579 boolean mForceShowSystemBars;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800580
Mike Lockwood28569302010-01-28 11:54:40 -0500581 // support for activating the lock screen while the screen is on
582 boolean mAllowLockscreenWhenOn;
583 int mLockScreenTimeout;
584 boolean mLockScreenTimerActive;
585
David Brownbaf8d092010-03-08 21:52:59 -0800586 // Behavior of ENDCALL Button. (See Settings.System.END_BUTTON_BEHAVIOR.)
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800587 int mEndcallBehavior;
David Brownbaf8d092010-03-08 21:52:59 -0800588
589 // Behavior of POWER button while in-call and screen on.
590 // (See Settings.Secure.INCALL_POWER_BUTTON_BEHAVIOR.)
591 int mIncallPowerBehavior;
592
Dianne Hackbornf87d1962012-04-04 12:48:24 -0700593 Display mDisplay;
594
Filip Gruszczynski2987f612015-06-30 15:03:30 -0700595 private int mDisplayRotation;
596
Dianne Hackborn9d132642011-04-21 17:26:39 -0700597 int mLandscapeRotation = 0; // default landscape rotation
598 int mSeascapeRotation = 0; // "other" landscape rotation, 180 degrees from mLandscapeRotation
599 int mPortraitRotation = 0; // default portrait rotation
600 int mUpsideDownRotation = 0; // "other" portrait rotation
Mitsuru Oshima831d0d92009-06-16 18:27:18 -0700601
Dianne Hackbornc652de82013-02-15 16:32:56 -0800602 int mOverscanLeft = 0;
603 int mOverscanTop = 0;
604 int mOverscanRight = 0;
605 int mOverscanBottom = 0;
606
Joe Onorato46b0d682010-11-22 17:37:27 -0800607 // What we do when the user long presses on home
Jeff Browncaca8812013-05-09 13:34:33 -0700608 private int mLongPressOnHomeBehavior;
609
610 // What we do when the user double-taps on home
611 private int mDoubleTapOnHomeBehavior;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800612
Bryce Lee584a4452014-10-21 15:55:55 -0700613 // Allowed theater mode wake actions
614 private boolean mAllowTheaterModeWakeFromKey;
615 private boolean mAllowTheaterModeWakeFromPowerKey;
616 private boolean mAllowTheaterModeWakeFromMotion;
Bryce Lee812d7022014-11-10 13:33:28 -0800617 private boolean mAllowTheaterModeWakeFromMotionWhenNotDreaming;
Bryce Lee584a4452014-10-21 15:55:55 -0700618 private boolean mAllowTheaterModeWakeFromCameraLens;
619 private boolean mAllowTheaterModeWakeFromLidSwitch;
620 private boolean mAllowTheaterModeWakeFromWakeGesture;
621
Bryce Leed3b28402015-03-09 15:49:13 +0000622 // Whether to support long press from power button in non-interactive mode
623 private boolean mSupportLongPressPowerWhenNonInteractive;
624
Bryce Lee55e846d2014-11-04 12:43:44 -0800625 // Whether to go to sleep entering theater mode from power button
626 private boolean mGoToSleepOnButtonPressTheaterMode;
627
Winson Chung9112ec32011-06-27 13:15:32 -0700628 // Screenshot trigger states
Jeff Brownd5bb82d2011-10-12 13:57:59 -0700629 // Time to volume and power must be pressed within this interval of each other.
630 private static final long SCREENSHOT_CHORD_DEBOUNCE_DELAY_MILLIS = 150;
Winson Chung1cea2f32012-10-08 20:42:01 -0700631 // Increase the chord delay when taking a screenshot from the keyguard
632 private static final float KEYGUARD_SCREENSHOT_CHORD_DELAY_MULTIPLIER = 2.5f;
Christopher Tatee90585f2012-03-05 18:56:25 -0800633 private boolean mScreenshotChordEnabled;
Jeff Brown13f00f02014-10-31 14:45:50 -0700634 private boolean mScreenshotChordVolumeDownKeyTriggered;
635 private long mScreenshotChordVolumeDownKeyTime;
636 private boolean mScreenshotChordVolumeDownKeyConsumed;
637 private boolean mScreenshotChordVolumeUpKeyTriggered;
638 private boolean mScreenshotChordPowerKeyTriggered;
639 private long mScreenshotChordPowerKeyTime;
Winson Chung9112ec32011-06-27 13:15:32 -0700640
Michael Wrightb854e242013-02-05 17:54:02 -0800641 /* The number of steps between min and max brightness */
642 private static final int BRIGHTNESS_STEPS = 10;
643
Christopher Tate5e08af02012-09-21 17:17:22 -0700644 SettingsObserver mSettingsObserver;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800645 ShortcutManager mShortcutManager;
646 PowerManager.WakeLock mBroadcastWakeLock;
Jeff Brown13f00f02014-10-31 14:45:50 -0700647 PowerManager.WakeLock mPowerKeyWakeLock;
Jeff Brown40013652012-05-16 21:22:36 -0700648 boolean mHavePendingMediaKeyRepeatWithWakeLock;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800649
Craig Mautnerd625ab22013-09-06 13:40:31 -0700650 private int mCurrentUserId;
651
Justin Kohd378ad72013-04-01 12:18:26 -0700652 // Maps global key codes to the components that will handle them.
653 private GlobalKeyManager mGlobalKeyManager;
654
Jeff Brownfd23e3e2012-05-09 13:34:28 -0700655 // Fallback actions by key code.
656 private final SparseArray<KeyCharacterMap.FallbackAction> mFallbackActions =
657 new SparseArray<KeyCharacterMap.FallbackAction>();
Jeff Brown49ed71d2010-12-06 17:13:33 -0800658
Jorim Jaggi76a16232014-08-08 17:00:47 +0200659 private final LogDecelerateInterpolator mLogDecelerateInterpolator
660 = new LogDecelerateInterpolator(100, 0);
661
Jorim Jaggi4fa78922015-11-30 17:13:56 -0800662 private boolean mForceWindowDrawsStatusBarBackground;
663
Jeff Brown70825162012-03-28 17:27:48 -0700664 private static final int MSG_ENABLE_POINTER_LOCATION = 1;
665 private static final int MSG_DISABLE_POINTER_LOCATION = 2;
Jeff Brown40013652012-05-16 21:22:36 -0700666 private static final int MSG_DISPATCH_MEDIA_KEY_WITH_WAKE_LOCK = 3;
667 private static final int MSG_DISPATCH_MEDIA_KEY_REPEAT_WITH_WAKE_LOCK = 4;
Craig Mautner8a0da012014-05-31 15:13:37 -0700668 private static final int MSG_KEYGUARD_DRAWN_COMPLETE = 5;
669 private static final int MSG_KEYGUARD_DRAWN_TIMEOUT = 6;
670 private static final int MSG_WINDOW_MANAGER_DRAWN_COMPLETE = 7;
Craig Mautner84984fa2014-06-19 11:19:20 -0700671 private static final int MSG_DISPATCH_SHOW_RECENTS = 9;
Alan Viverettee34560b22014-07-10 14:50:06 -0700672 private static final int MSG_DISPATCH_SHOW_GLOBAL_ACTIONS = 10;
Craig Mautnera631d492014-08-05 15:16:01 -0700673 private static final int MSG_HIDE_BOOT_MESSAGE = 11;
Michael Wright869a67c2014-08-26 19:33:06 -0700674 private static final int MSG_LAUNCH_VOICE_ASSIST_WITH_WAKE_LOCK = 12;
Jeff Brown13f00f02014-10-31 14:45:50 -0700675 private static final int MSG_POWER_DELAYED_PRESS = 13;
676 private static final int MSG_POWER_LONG_PRESS = 14;
Jeff Brown061ea992015-04-17 19:55:47 -0700677 private static final int MSG_UPDATE_DREAMING_SLEEP_TOKEN = 15;
Jun Mukaid2e7e352015-07-22 17:14:02 -0700678 private static final int MSG_REQUEST_TRANSIENT_BARS = 16;
Jaewan Kimc552b042016-01-18 16:08:45 +0900679 private static final int MSG_REQUEST_TV_PICTURE_IN_PICTURE = 17;
Jun Mukaid2e7e352015-07-22 17:14:02 -0700680
681 private static final int MSG_REQUEST_TRANSIENT_BARS_ARG_STATUS = 0;
682 private static final int MSG_REQUEST_TRANSIENT_BARS_ARG_NAVIGATION = 1;
Jeff Brown70825162012-03-28 17:27:48 -0700683
684 private class PolicyHandler extends Handler {
685 @Override
686 public void handleMessage(Message msg) {
687 switch (msg.what) {
688 case MSG_ENABLE_POINTER_LOCATION:
689 enablePointerLocation();
690 break;
691 case MSG_DISABLE_POINTER_LOCATION:
692 disablePointerLocation();
693 break;
Jeff Brown40013652012-05-16 21:22:36 -0700694 case MSG_DISPATCH_MEDIA_KEY_WITH_WAKE_LOCK:
695 dispatchMediaKeyWithWakeLock((KeyEvent)msg.obj);
696 break;
697 case MSG_DISPATCH_MEDIA_KEY_REPEAT_WITH_WAKE_LOCK:
698 dispatchMediaKeyRepeatWithWakeLock((KeyEvent)msg.obj);
699 break;
Craig Mautner84984fa2014-06-19 11:19:20 -0700700 case MSG_DISPATCH_SHOW_RECENTS:
701 showRecentApps(false);
702 break;
Alan Viverettee34560b22014-07-10 14:50:06 -0700703 case MSG_DISPATCH_SHOW_GLOBAL_ACTIONS:
704 showGlobalActionsInternal();
705 break;
Craig Mautner8a0da012014-05-31 15:13:37 -0700706 case MSG_KEYGUARD_DRAWN_COMPLETE:
707 if (DEBUG_WAKEUP) Slog.w(TAG, "Setting mKeyguardDrawComplete");
Jeff Brown36c4db82014-09-19 12:05:31 -0700708 finishKeyguardDrawn();
Craig Mautner8a0da012014-05-31 15:13:37 -0700709 break;
710 case MSG_KEYGUARD_DRAWN_TIMEOUT:
711 Slog.w(TAG, "Keyguard drawn timeout. Setting mKeyguardDrawComplete");
Jeff Brown36c4db82014-09-19 12:05:31 -0700712 finishKeyguardDrawn();
Craig Mautner8a0da012014-05-31 15:13:37 -0700713 break;
714 case MSG_WINDOW_MANAGER_DRAWN_COMPLETE:
715 if (DEBUG_WAKEUP) Slog.w(TAG, "Setting mWindowManagerDrawComplete");
Jeff Brown36c4db82014-09-19 12:05:31 -0700716 finishWindowsDrawn();
Craig Mautner8a0da012014-05-31 15:13:37 -0700717 break;
Craig Mautnera631d492014-08-05 15:16:01 -0700718 case MSG_HIDE_BOOT_MESSAGE:
719 handleHideBootMessage();
720 break;
Michael Wright869a67c2014-08-26 19:33:06 -0700721 case MSG_LAUNCH_VOICE_ASSIST_WITH_WAKE_LOCK:
722 launchVoiceAssistWithWakeLock(msg.arg1 != 0);
723 break;
Jeff Brown13f00f02014-10-31 14:45:50 -0700724 case MSG_POWER_DELAYED_PRESS:
725 powerPress((Long)msg.obj, msg.arg1 != 0, msg.arg2);
726 finishPowerKeyPress();
727 break;
728 case MSG_POWER_LONG_PRESS:
729 powerLongPress();
730 break;
Jeff Brown061ea992015-04-17 19:55:47 -0700731 case MSG_UPDATE_DREAMING_SLEEP_TOKEN:
732 updateDreamingSleepToken(msg.arg1 != 0);
733 break;
Jun Mukaid2e7e352015-07-22 17:14:02 -0700734 case MSG_REQUEST_TRANSIENT_BARS:
735 WindowState targetBar = (msg.arg1 == MSG_REQUEST_TRANSIENT_BARS_ARG_STATUS) ?
736 mStatusBar : mNavigationBar;
737 if (targetBar != null) {
738 requestTransientBars(targetBar);
739 }
740 break;
Jaewan Kimc552b042016-01-18 16:08:45 +0900741 case MSG_REQUEST_TV_PICTURE_IN_PICTURE:
742 requestTvPictureInPictureInternal();
743 break;
Jeff Brown70825162012-03-28 17:27:48 -0700744 }
745 }
746 }
747
Dianne Hackbornad7fa7f2011-01-07 14:06:50 -0800748 private UEventObserver mHDMIObserver = new UEventObserver() {
749 @Override
750 public void onUEvent(UEventObserver.UEvent event) {
751 setHdmiPlugged("1".equals(event.get("SWITCH_STATE")));
752 }
753 };
754
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800755 class SettingsObserver extends ContentObserver {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800756 SettingsObserver(Handler handler) {
757 super(handler);
758 }
David Brownbaf8d092010-03-08 21:52:59 -0800759
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800760 void observe() {
Christopher Tate5e08af02012-09-21 17:17:22 -0700761 // Observe all users' changes
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800762 ContentResolver resolver = mContext.getContentResolver();
763 resolver.registerContentObserver(Settings.System.getUriFor(
Christopher Tate5e08af02012-09-21 17:17:22 -0700764 Settings.System.END_BUTTON_BEHAVIOR), false, this,
765 UserHandle.USER_ALL);
David Brownbaf8d092010-03-08 21:52:59 -0800766 resolver.registerContentObserver(Settings.Secure.getUriFor(
Christopher Tate5e08af02012-09-21 17:17:22 -0700767 Settings.Secure.INCALL_POWER_BUTTON_BEHAVIOR), false, this,
768 UserHandle.USER_ALL);
Jeff Browna20dda42014-05-27 20:57:24 -0700769 resolver.registerContentObserver(Settings.Secure.getUriFor(
770 Settings.Secure.WAKE_GESTURE_ENABLED), false, this,
771 UserHandle.USER_ALL);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800772 resolver.registerContentObserver(Settings.System.getUriFor(
Christopher Tate5e08af02012-09-21 17:17:22 -0700773 Settings.System.ACCELEROMETER_ROTATION), false, this,
774 UserHandle.USER_ALL);
Mike Lockwood28569302010-01-28 11:54:40 -0500775 resolver.registerContentObserver(Settings.System.getUriFor(
Christopher Tate5e08af02012-09-21 17:17:22 -0700776 Settings.System.USER_ROTATION), false, this,
777 UserHandle.USER_ALL);
Daniel Sandlerb73617d2010-08-17 00:41:00 -0400778 resolver.registerContentObserver(Settings.System.getUriFor(
Christopher Tate5e08af02012-09-21 17:17:22 -0700779 Settings.System.SCREEN_OFF_TIMEOUT), false, this,
780 UserHandle.USER_ALL);
Dianne Hackbornc777e072010-02-12 13:07:59 -0800781 resolver.registerContentObserver(Settings.System.getUriFor(
Christopher Tate5e08af02012-09-21 17:17:22 -0700782 Settings.System.POINTER_LOCATION), false, this,
783 UserHandle.USER_ALL);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800784 resolver.registerContentObserver(Settings.Secure.getUriFor(
Christopher Tate5e08af02012-09-21 17:17:22 -0700785 Settings.Secure.DEFAULT_INPUT_METHOD), false, this,
786 UserHandle.USER_ALL);
John Spurlockd9b70bd2014-02-06 17:02:44 -0500787 resolver.registerContentObserver(Settings.Secure.getUriFor(
John Spurlockf1a36642013-10-12 17:50:42 -0400788 Settings.Secure.IMMERSIVE_MODE_CONFIRMATIONS), false, this,
Christopher Tate5e08af02012-09-21 17:17:22 -0700789 UserHandle.USER_ALL);
John Spurlockc6d1c602014-01-17 15:22:06 -0500790 resolver.registerContentObserver(Settings.Global.getUriFor(
791 Settings.Global.POLICY_CONTROL), false, this,
792 UserHandle.USER_ALL);
Dianne Hackbornc777e072010-02-12 13:07:59 -0800793 updateSettings();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800794 }
795
796 @Override public void onChange(boolean selfChange) {
Dianne Hackbornc777e072010-02-12 13:07:59 -0800797 updateSettings();
Jeff Brown01a98dd2011-09-20 15:08:29 -0700798 updateRotation(false);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800799 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800800 }
Craig Mautner967212c2013-04-13 21:10:58 -0700801
Jeff Browna20dda42014-05-27 20:57:24 -0700802 class MyWakeGestureListener extends WakeGestureListener {
803 MyWakeGestureListener(Context context, Handler handler) {
804 super(context, handler);
805 }
806
807 @Override
808 public void onWakeUp() {
809 synchronized (mLock) {
810 if (shouldEnableWakeGestureLp()) {
Jeff Browne07b94b2014-06-18 15:56:27 -0700811 performHapticFeedbackLw(null, HapticFeedbackConstants.VIRTUAL_KEY, false);
Dianne Hackborn280a64e2015-07-13 14:48:08 -0700812 wakeUp(SystemClock.uptimeMillis(), mAllowTheaterModeWakeFromWakeGesture,
813 "android.policy:GESTURE");
Jeff Browna20dda42014-05-27 20:57:24 -0700814 }
815 }
816 }
817 }
818
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800819 class MyOrientationListener extends WindowOrientationListener {
Chong Zhang5aaa0b32015-08-28 10:22:36 -0700820 private final Runnable mUpdateRotationRunnable = new Runnable() {
821 @Override
822 public void run() {
Tim Murray1f407642015-10-01 17:07:12 -0700823 // send interaction hint to improve redraw performance
824 mPowerManagerInternal.powerHint(PowerManagerInternal.POWER_HINT_INTERACTION, 0);
Chong Zhang5aaa0b32015-08-28 10:22:36 -0700825 updateRotation(false);
826 }
827 };
828
Craig Mautnereee29c42013-01-17 14:44:34 -0800829 MyOrientationListener(Context context, Handler handler) {
830 super(context, handler);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800831 }
Craig Mautner967212c2013-04-13 21:10:58 -0700832
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800833 @Override
Jeff Brownc0347aa2011-09-23 17:26:09 -0700834 public void onProposedRotationChanged(int rotation) {
Craig Mautnereda67292013-04-28 13:50:14 -0700835 if (localLOGV) Slog.v(TAG, "onProposedRotationChanged, rotation=" + rotation);
Chong Zhang5aaa0b32015-08-28 10:22:36 -0700836 mHandler.post(mUpdateRotationRunnable);
Jeff Brown01a98dd2011-09-20 15:08:29 -0700837 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800838 }
839 MyOrientationListener mOrientationListener;
840
Jorim Jaggi24bec7c2015-02-04 12:40:14 +0100841 private final StatusBarController mStatusBarController = new StatusBarController();
John Spurlock5b9145b2013-08-20 15:13:47 -0400842
John Spurlock27735a42013-08-14 17:57:38 -0400843 private final BarController mNavigationBarController = new BarController("NavigationBar",
John Spurlock5b9145b2013-08-20 15:13:47 -0400844 View.NAVIGATION_BAR_TRANSIENT,
845 View.NAVIGATION_BAR_UNHIDE,
John Spurlockbd957402013-10-03 11:38:39 -0400846 View.NAVIGATION_BAR_TRANSLUCENT,
847 StatusBarManager.WINDOW_NAVIGATION_BAR,
Jorim Jaggi4fa78922015-11-30 17:13:56 -0800848 WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION,
849 View.NAVIGATION_BAR_TRANSPARENT);
John Spurlock5b9145b2013-08-20 15:13:47 -0400850
John Spurlockf1a36642013-10-12 17:50:42 -0400851 private ImmersiveModeConfirmation mImmersiveModeConfirmation;
John Spurlock32beb2c2013-03-11 10:16:47 -0400852
Craig Mautner037aa8d2013-06-07 10:35:44 -0700853 private SystemGesturesPointerEventListener mSystemGestures;
John Spurlock32beb2c2013-03-11 10:16:47 -0400854
Dianne Hackborn42e620c2012-06-24 13:20:51 -0700855 IStatusBarService getStatusBarService() {
856 synchronized (mServiceAquireLock) {
857 if (mStatusBarService == null) {
858 mStatusBarService = IStatusBarService.Stub.asInterface(
859 ServiceManager.getService("statusbar"));
860 }
861 return mStatusBarService;
862 }
863 }
864
Jorim Jaggi86905582016-02-09 21:36:09 -0800865 StatusBarManagerInternal getStatusBarManagerInternal() {
866 synchronized (mServiceAquireLock) {
867 if (mStatusBarManagerInternal == null) {
868 mStatusBarManagerInternal =
869 LocalServices.getService(StatusBarManagerInternal.class);
870 }
871 return mStatusBarManagerInternal;
872 }
873 }
874
Suchi Amalapurapua9e1b162009-03-24 22:24:47 -0700875 /*
876 * We always let the sensor be switched on by default except when
877 * the user has explicitly disabled sensor based rotation or when the
878 * screen is switched off.
879 */
The Android Open Source Project0727d222009-03-11 12:11:58 -0700880 boolean needSensorRunningLp() {
Jeff Brownbcdfc622014-03-06 19:13:04 -0800881 if (mSupportAutoRotation) {
882 if (mCurrentAppOrientation == ActivityInfo.SCREEN_ORIENTATION_SENSOR
883 || mCurrentAppOrientation == ActivityInfo.SCREEN_ORIENTATION_FULL_SENSOR
884 || mCurrentAppOrientation == ActivityInfo.SCREEN_ORIENTATION_SENSOR_PORTRAIT
885 || mCurrentAppOrientation == ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE) {
886 // If the application has explicitly requested to follow the
887 // orientation, then we need to turn the sensor on.
888 return true;
889 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800890 }
Dianne Hackborn867ab6472010-04-29 13:28:56 -0700891 if ((mCarDockEnablesAccelerometer && mDockMode == Intent.EXTRA_DOCK_STATE_CAR) ||
Jeff Brown1a693182011-11-08 14:44:16 -0800892 (mDeskDockEnablesAccelerometer && (mDockMode == Intent.EXTRA_DOCK_STATE_DESK
893 || mDockMode == Intent.EXTRA_DOCK_STATE_LE_DESK
894 || mDockMode == Intent.EXTRA_DOCK_STATE_HE_DESK))) {
Mike Lockwoode9867d22009-09-20 01:59:02 -0400895 // enable accelerometer if we are docked in a dock that enables accelerometer
896 // orientation management,
897 return true;
898 }
Jeff Brown207673cd2012-06-05 17:47:11 -0700899 if (mUserRotationMode == USER_ROTATION_LOCKED) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800900 // If the setting for using the sensor by default is enabled, then
901 // we will always leave it on. Note that the user could go to
902 // a window that forces an orientation that does not use the
903 // sensor and in theory we could turn it off... however, when next
904 // turning it on we won't have a good value for the current
905 // orientation for a little bit, which can cause orientation
906 // changes to lag, so we'd like to keep it always on. (It will
907 // still be turned off when the screen is off.)
Suchi Amalapurapua9e1b162009-03-24 22:24:47 -0700908 return false;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800909 }
Jeff Brownbcdfc622014-03-06 19:13:04 -0800910 return mSupportAutoRotation;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800911 }
Craig Mautner46ac6fa2013-08-01 10:06:34 -0700912
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800913 /*
914 * Various use cases for invoking this function
915 * screen turning off, should always disable listeners if already enabled
Craig Mautner46ac6fa2013-08-01 10:06:34 -0700916 * screen turned on and current app has sensor based orientation, enable listeners
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800917 * if not already enabled
918 * screen turned on and current app does not have sensor orientation, disable listeners if
919 * already enabled
920 * screen turning on and current app has sensor based orientation, enable listeners if needed
921 * screen turning on and current app has nosensor based orientation, do nothing
922 */
The Android Open Source Project0727d222009-03-11 12:11:58 -0700923 void updateOrientationListenerLp() {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800924 if (!mOrientationListener.canDetectOrientation()) {
925 // If sensor is turned off or nonexistent for some reason
926 return;
927 }
Stefan Kuhne9326dc12015-06-12 09:25:32 -1000928 // Could have been invoked due to screen turning on or off or
929 // change of the currently visible window's orientation.
Jeff Brown3ee549c2014-09-22 20:14:39 -0700930 if (localLOGV) Slog.v(TAG, "mScreenOnEarly=" + mScreenOnEarly
931 + ", mAwake=" + mAwake + ", mCurrentAppOrientation=" + mCurrentAppOrientation
Stefan Kuhne9326dc12015-06-12 09:25:32 -1000932 + ", mOrientationSensorEnabled=" + mOrientationSensorEnabled
933 + ", mKeyguardDrawComplete=" + mKeyguardDrawComplete
934 + ", mWindowManagerDrawComplete=" + mWindowManagerDrawComplete);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800935 boolean disable = true;
Stefan Kuhne9326dc12015-06-12 09:25:32 -1000936 // Note: We postpone the rotating of the screen until the keyguard as well as the
937 // window manager have reported a draw complete.
938 if (mScreenOnEarly && mAwake &&
939 mKeyguardDrawComplete && mWindowManagerDrawComplete) {
The Android Open Source Project0727d222009-03-11 12:11:58 -0700940 if (needSensorRunningLp()) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800941 disable = false;
942 //enable listener if not already enabled
The Android Open Source Project0727d222009-03-11 12:11:58 -0700943 if (!mOrientationSensorEnabled) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800944 mOrientationListener.enable();
Craig Mautnereda67292013-04-28 13:50:14 -0700945 if(localLOGV) Slog.v(TAG, "Enabling listeners");
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800946 mOrientationSensorEnabled = true;
947 }
Craig Mautner46ac6fa2013-08-01 10:06:34 -0700948 }
949 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800950 //check if sensors need to be disabled
The Android Open Source Project0727d222009-03-11 12:11:58 -0700951 if (disable && mOrientationSensorEnabled) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800952 mOrientationListener.disable();
Craig Mautnereda67292013-04-28 13:50:14 -0700953 if(localLOGV) Slog.v(TAG, "Disabling listeners");
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800954 mOrientationSensorEnabled = false;
955 }
956 }
957
Jeff Brown13f00f02014-10-31 14:45:50 -0700958 private void interceptPowerKeyDown(KeyEvent event, boolean interactive) {
959 // Hold a wake lock until the power key is released.
960 if (!mPowerKeyWakeLock.isHeld()) {
961 mPowerKeyWakeLock.acquire();
962 }
963
964 // Cancel multi-press detection timeout.
965 if (mPowerKeyPressCounter != 0) {
966 mHandler.removeMessages(MSG_POWER_DELAYED_PRESS);
967 }
968
969 // Detect user pressing the power button in panic when an application has
970 // taken over the whole screen.
971 boolean panic = mImmersiveModeConfirmation.onPowerKeyDown(interactive,
Craig Mautner0124980e92014-11-30 21:15:34 -0800972 SystemClock.elapsedRealtime(), isImmersiveMode(mLastSystemUiFlags));
Jeff Brown13f00f02014-10-31 14:45:50 -0700973 if (panic) {
Adrian Roosddc8b272015-05-21 16:28:27 -0700974 mHandler.post(mHiddenNavPanic);
Jeff Brown13f00f02014-10-31 14:45:50 -0700975 }
976
977 // Latch power key state to detect screenshot chord.
978 if (interactive && !mScreenshotChordPowerKeyTriggered
979 && (event.getFlags() & KeyEvent.FLAG_FALLBACK) == 0) {
980 mScreenshotChordPowerKeyTriggered = true;
981 mScreenshotChordPowerKeyTime = event.getDownTime();
982 interceptScreenshotChord();
983 }
984
985 // Stop ringing or end call if configured to do so when power is pressed.
986 TelecomManager telecomManager = getTelecommService();
987 boolean hungUp = false;
988 if (telecomManager != null) {
989 if (telecomManager.isRinging()) {
990 // Pressing Power while there's a ringing incoming
991 // call should silence the ringer.
992 telecomManager.silenceRinger();
993 } else if ((mIncallPowerBehavior
994 & Settings.Secure.INCALL_POWER_BUTTON_BEHAVIOR_HANGUP) != 0
995 && telecomManager.isInCall() && interactive) {
996 // Otherwise, if "Power button ends call" is enabled,
997 // the Power button will hang up any current active call.
998 hungUp = telecomManager.endCall();
999 }
1000 }
1001
Adrian Roos5941c982015-09-03 15:59:49 -07001002 GestureLauncherService gestureService = LocalServices.getService(
1003 GestureLauncherService.class);
1004 boolean gesturedServiceIntercepted = false;
1005 if (gestureService != null) {
1006 gesturedServiceIntercepted = gestureService.interceptPowerKeyDown(event, interactive);
1007 }
1008
Jeff Brown13f00f02014-10-31 14:45:50 -07001009 // If the power key has still not yet been handled, then detect short
1010 // press, long press, or multi press and decide what to do.
1011 mPowerKeyHandled = hungUp || mScreenshotChordVolumeDownKeyTriggered
Adrian Roos5941c982015-09-03 15:59:49 -07001012 || mScreenshotChordVolumeUpKeyTriggered || gesturedServiceIntercepted;
Jeff Brown13f00f02014-10-31 14:45:50 -07001013 if (!mPowerKeyHandled) {
1014 if (interactive) {
1015 // When interactive, we're already awake.
1016 // Wait for a long press or for the button to be released to decide what to do.
1017 if (hasLongPressOnPowerBehavior()) {
1018 Message msg = mHandler.obtainMessage(MSG_POWER_LONG_PRESS);
1019 msg.setAsynchronous(true);
1020 mHandler.sendMessageDelayed(msg,
1021 ViewConfiguration.get(mContext).getDeviceGlobalActionKeyTimeout());
1022 }
1023 } else {
Bryce Leed9268e32014-11-17 17:40:59 -08001024 wakeUpFromPowerKey(event.getDownTime());
Bryce Leed9268e32014-11-17 17:40:59 -08001025
Bryce Leed3b28402015-03-09 15:49:13 +00001026 if (mSupportLongPressPowerWhenNonInteractive && hasLongPressOnPowerBehavior()) {
1027 Message msg = mHandler.obtainMessage(MSG_POWER_LONG_PRESS);
1028 msg.setAsynchronous(true);
1029 mHandler.sendMessageDelayed(msg,
1030 ViewConfiguration.get(mContext).getDeviceGlobalActionKeyTimeout());
Bryce Leed9268e32014-11-17 17:40:59 -08001031 mBeganFromNonInteractive = true;
Bryce Leed3b28402015-03-09 15:49:13 +00001032 } else {
1033 final int maxCount = getMaxMultiPressPowerCount();
1034
1035 if (maxCount <= 1) {
1036 mPowerKeyHandled = true;
1037 } else {
1038 mBeganFromNonInteractive = true;
1039 }
Jeff Brown13f00f02014-10-31 14:45:50 -07001040 }
1041 }
Jeff Brown4d396052010-10-29 21:50:21 -07001042 }
1043 }
1044
Jeff Brown13f00f02014-10-31 14:45:50 -07001045 private void interceptPowerKeyUp(KeyEvent event, boolean interactive, boolean canceled) {
1046 final boolean handled = canceled || mPowerKeyHandled;
1047 mScreenshotChordPowerKeyTriggered = false;
1048 cancelPendingScreenshotChordAction();
1049 cancelPendingPowerKeyAction();
1050
1051 if (!handled) {
1052 // Figure out how to handle the key now that it has been released.
1053 mPowerKeyPressCounter += 1;
1054
1055 final int maxCount = getMaxMultiPressPowerCount();
1056 final long eventTime = event.getDownTime();
1057 if (mPowerKeyPressCounter < maxCount) {
1058 // This could be a multi-press. Wait a little bit longer to confirm.
1059 // Continue holding the wake lock.
1060 Message msg = mHandler.obtainMessage(MSG_POWER_DELAYED_PRESS,
1061 interactive ? 1 : 0, mPowerKeyPressCounter, eventTime);
1062 msg.setAsynchronous(true);
1063 mHandler.sendMessageDelayed(msg, ViewConfiguration.getDoubleTapTimeout());
1064 return;
1065 }
1066
1067 // No other actions. Handle it immediately.
1068 powerPress(eventTime, interactive, mPowerKeyPressCounter);
Jeff Brown4d396052010-10-29 21:50:21 -07001069 }
Jeff Brown13f00f02014-10-31 14:45:50 -07001070
1071 // Done. Reset our state.
1072 finishPowerKeyPress();
1073 }
1074
1075 private void finishPowerKeyPress() {
Bryce Leed9268e32014-11-17 17:40:59 -08001076 mBeganFromNonInteractive = false;
Jeff Brown13f00f02014-10-31 14:45:50 -07001077 mPowerKeyPressCounter = 0;
1078 if (mPowerKeyWakeLock.isHeld()) {
1079 mPowerKeyWakeLock.release();
1080 }
Jeff Brownd5bb82d2011-10-12 13:57:59 -07001081 }
1082
1083 private void cancelPendingPowerKeyAction() {
1084 if (!mPowerKeyHandled) {
Jeff Brown13f00f02014-10-31 14:45:50 -07001085 mPowerKeyHandled = true;
1086 mHandler.removeMessages(MSG_POWER_LONG_PRESS);
Jeff Brownd5bb82d2011-10-12 13:57:59 -07001087 }
Jeff Brown13f00f02014-10-31 14:45:50 -07001088 }
1089
1090 private void powerPress(long eventTime, boolean interactive, int count) {
1091 if (mScreenOnEarly && !mScreenOnFully) {
1092 Slog.i(TAG, "Suppressed redundant power key press while "
1093 + "already in the process of turning the screen on.");
1094 return;
Jeff Brownff204712011-10-25 21:27:54 -07001095 }
Jeff Brown13f00f02014-10-31 14:45:50 -07001096
1097 if (count == 2) {
1098 powerMultiPressAction(eventTime, interactive, mDoublePressOnPowerBehavior);
1099 } else if (count == 3) {
1100 powerMultiPressAction(eventTime, interactive, mTriplePressOnPowerBehavior);
Bryce Leed9268e32014-11-17 17:40:59 -08001101 } else if (interactive && !mBeganFromNonInteractive) {
Jeff Brown13f00f02014-10-31 14:45:50 -07001102 switch (mShortPressOnPowerBehavior) {
1103 case SHORT_PRESS_POWER_NOTHING:
1104 break;
1105 case SHORT_PRESS_POWER_GO_TO_SLEEP:
1106 mPowerManager.goToSleep(eventTime,
1107 PowerManager.GO_TO_SLEEP_REASON_POWER_BUTTON, 0);
1108 break;
1109 case SHORT_PRESS_POWER_REALLY_GO_TO_SLEEP:
1110 mPowerManager.goToSleep(eventTime,
1111 PowerManager.GO_TO_SLEEP_REASON_POWER_BUTTON,
1112 PowerManager.GO_TO_SLEEP_FLAG_NO_DOZE);
1113 break;
1114 case SHORT_PRESS_POWER_REALLY_GO_TO_SLEEP_AND_GO_HOME:
1115 mPowerManager.goToSleep(eventTime,
1116 PowerManager.GO_TO_SLEEP_REASON_POWER_BUTTON,
1117 PowerManager.GO_TO_SLEEP_FLAG_NO_DOZE);
1118 launchHomeFromHotKey();
1119 break;
Bryce Lee01b0c5f2015-02-05 18:24:04 -08001120 case SHORT_PRESS_POWER_GO_HOME:
Bryce Lee662ed802015-04-10 20:11:39 +00001121 launchHomeFromHotKey(true /* awakenFromDreams */, false /*respectKeyguard*/);
Bryce Lee01b0c5f2015-02-05 18:24:04 -08001122 break;
Jeff Brown13f00f02014-10-31 14:45:50 -07001123 }
1124 }
1125 }
1126
1127 private void powerMultiPressAction(long eventTime, boolean interactive, int behavior) {
1128 switch (behavior) {
1129 case MULTI_PRESS_POWER_NOTHING:
1130 break;
1131 case MULTI_PRESS_POWER_THEATER_MODE:
Bryce Lee3ae447e2015-06-30 12:31:41 -07001132 if (!isUserSetupComplete()) {
1133 Slog.i(TAG, "Ignoring toggling theater mode - device not setup.");
1134 break;
1135 }
1136
Jeff Brown13f00f02014-10-31 14:45:50 -07001137 if (isTheaterModeEnabled()) {
1138 Slog.i(TAG, "Toggling theater mode off.");
1139 Settings.Global.putInt(mContext.getContentResolver(),
1140 Settings.Global.THEATER_MODE_ON, 0);
1141 if (!interactive) {
1142 wakeUpFromPowerKey(eventTime);
1143 }
1144 } else {
1145 Slog.i(TAG, "Toggling theater mode on.");
1146 Settings.Global.putInt(mContext.getContentResolver(),
1147 Settings.Global.THEATER_MODE_ON, 1);
Bryce Lee55e846d2014-11-04 12:43:44 -08001148
1149 if (mGoToSleepOnButtonPressTheaterMode && interactive) {
Jeff Brown13f00f02014-10-31 14:45:50 -07001150 mPowerManager.goToSleep(eventTime,
1151 PowerManager.GO_TO_SLEEP_REASON_POWER_BUTTON, 0);
1152 }
1153 }
1154 break;
1155 case MULTI_PRESS_POWER_BRIGHTNESS_BOOST:
Jeff Brown7b5be5e2014-11-12 18:45:31 -08001156 Slog.i(TAG, "Starting brightness boost.");
1157 if (!interactive) {
1158 wakeUpFromPowerKey(eventTime);
1159 }
Jeff Brown13f00f02014-10-31 14:45:50 -07001160 mPowerManager.boostScreenBrightness(eventTime);
1161 break;
1162 }
1163 }
1164
1165 private int getMaxMultiPressPowerCount() {
1166 if (mTriplePressOnPowerBehavior != MULTI_PRESS_POWER_NOTHING) {
1167 return 3;
1168 }
1169 if (mDoublePressOnPowerBehavior != MULTI_PRESS_POWER_NOTHING) {
1170 return 2;
1171 }
1172 return 1;
1173 }
1174
1175 private void powerLongPress() {
1176 final int behavior = getResolvedLongPressOnPowerBehavior();
1177 switch (behavior) {
1178 case LONG_PRESS_POWER_NOTHING:
1179 break;
1180 case LONG_PRESS_POWER_GLOBAL_ACTIONS:
1181 mPowerKeyHandled = true;
1182 if (!performHapticFeedbackLw(null, HapticFeedbackConstants.LONG_PRESS, false)) {
1183 performAuditoryFeedbackForAccessibilityIfNeed();
1184 }
1185 showGlobalActionsInternal();
1186 break;
1187 case LONG_PRESS_POWER_SHUT_OFF:
1188 case LONG_PRESS_POWER_SHUT_OFF_NO_CONFIRM:
1189 mPowerKeyHandled = true;
1190 performHapticFeedbackLw(null, HapticFeedbackConstants.LONG_PRESS, false);
1191 sendCloseSystemWindows(SYSTEM_DIALOG_REASON_GLOBAL_ACTIONS);
1192 mWindowManagerFuncs.shutdown(behavior == LONG_PRESS_POWER_SHUT_OFF);
1193 break;
1194 }
1195 }
1196
Nick Vaccarob593a812015-05-15 11:23:05 -07001197 private void sleepPress(long eventTime) {
1198 if (mShortPressOnSleepBehavior == SHORT_PRESS_SLEEP_GO_TO_SLEEP_AND_GO_HOME) {
1199 launchHomeFromHotKey(false /* awakenDreams */, true /*respectKeyguard*/);
1200 }
1201 }
1202
1203 private void sleepRelease(long eventTime) {
Filip Gruszczynskia483a1d2015-03-17 19:06:58 +00001204 switch (mShortPressOnSleepBehavior) {
1205 case SHORT_PRESS_SLEEP_GO_TO_SLEEP:
Filip Gruszczynskia483a1d2015-03-17 19:06:58 +00001206 case SHORT_PRESS_SLEEP_GO_TO_SLEEP_AND_GO_HOME:
Nick Vaccarob593a812015-05-15 11:23:05 -07001207 Slog.i(TAG, "sleepRelease() calling goToSleep(GO_TO_SLEEP_REASON_SLEEP_BUTTON)");
1208 mPowerManager.goToSleep(eventTime,
1209 PowerManager.GO_TO_SLEEP_REASON_SLEEP_BUTTON, 0);
Filip Gruszczynskia483a1d2015-03-17 19:06:58 +00001210 break;
1211 }
1212 }
1213
Jeff Brown13f00f02014-10-31 14:45:50 -07001214 private int getResolvedLongPressOnPowerBehavior() {
1215 if (FactoryTest.isLongPressOnPowerOffEnabled()) {
1216 return LONG_PRESS_POWER_SHUT_OFF_NO_CONFIRM;
1217 }
1218 return mLongPressOnPowerBehavior;
1219 }
1220
1221 private boolean hasLongPressOnPowerBehavior() {
1222 return getResolvedLongPressOnPowerBehavior() != LONG_PRESS_POWER_NOTHING;
Jeff Brownd5bb82d2011-10-12 13:57:59 -07001223 }
1224
1225 private void interceptScreenshotChord() {
Christopher Tatee90585f2012-03-05 18:56:25 -08001226 if (mScreenshotChordEnabled
Jeff Brown13f00f02014-10-31 14:45:50 -07001227 && mScreenshotChordVolumeDownKeyTriggered && mScreenshotChordPowerKeyTriggered
1228 && !mScreenshotChordVolumeUpKeyTriggered) {
Jeff Brownd5bb82d2011-10-12 13:57:59 -07001229 final long now = SystemClock.uptimeMillis();
Jeff Brown13f00f02014-10-31 14:45:50 -07001230 if (now <= mScreenshotChordVolumeDownKeyTime + SCREENSHOT_CHORD_DEBOUNCE_DELAY_MILLIS
1231 && now <= mScreenshotChordPowerKeyTime
1232 + SCREENSHOT_CHORD_DEBOUNCE_DELAY_MILLIS) {
1233 mScreenshotChordVolumeDownKeyConsumed = true;
Jeff Brownd5bb82d2011-10-12 13:57:59 -07001234 cancelPendingPowerKeyAction();
1235
Jeff Sharkey2991fa32012-12-05 18:06:43 -08001236 mHandler.postDelayed(mScreenshotRunnable, getScreenshotChordLongPressDelay());
Jeff Brownd5bb82d2011-10-12 13:57:59 -07001237 }
1238 }
1239 }
1240
Winson Chung1cea2f32012-10-08 20:42:01 -07001241 private long getScreenshotChordLongPressDelay() {
Jim Miller5ecd8112013-01-09 18:50:26 -08001242 if (mKeyguardDelegate.isShowing()) {
Winson Chung1cea2f32012-10-08 20:42:01 -07001243 // Double the time it takes to take a screenshot from the keyguard
1244 return (long) (KEYGUARD_SCREENSHOT_CHORD_DELAY_MULTIPLIER *
Justin Kohfeabd2c2014-05-02 10:02:44 -07001245 ViewConfiguration.get(mContext).getDeviceGlobalActionKeyTimeout());
Winson Chung1cea2f32012-10-08 20:42:01 -07001246 }
Justin Kohfeabd2c2014-05-02 10:02:44 -07001247 return ViewConfiguration.get(mContext).getDeviceGlobalActionKeyTimeout();
Winson Chung1cea2f32012-10-08 20:42:01 -07001248 }
1249
Jeff Brownd5bb82d2011-10-12 13:57:59 -07001250 private void cancelPendingScreenshotChordAction() {
Jeff Sharkey2991fa32012-12-05 18:06:43 -08001251 mHandler.removeCallbacks(mScreenshotRunnable);
Jeff Brown4d396052010-10-29 21:50:21 -07001252 }
1253
Jeff Brown13f00f02014-10-31 14:45:50 -07001254 private final Runnable mEndCallLongPress = new Runnable() {
Craig Mautnerf1b67412012-09-19 13:18:29 -07001255 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001256 public void run() {
Jeff Brown13f00f02014-10-31 14:45:50 -07001257 mEndCallKeyHandled = true;
1258 if (!performHapticFeedbackLw(null, HapticFeedbackConstants.LONG_PRESS, false)) {
1259 performAuditoryFeedbackForAccessibilityIfNeed();
Joe Onoratod208e702010-10-08 16:22:43 -04001260 }
Jeff Brown13f00f02014-10-31 14:45:50 -07001261 showGlobalActionsInternal();
Jeff Brownd5bb82d2011-10-12 13:57:59 -07001262 }
1263 };
1264
Jeff Sharkey2991fa32012-12-05 18:06:43 -08001265 private final Runnable mScreenshotRunnable = new Runnable() {
Craig Mautner0bf6ec92012-12-18 08:33:27 -08001266 @Override
Jeff Brownd5bb82d2011-10-12 13:57:59 -07001267 public void run() {
1268 takeScreenshot();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001269 }
1270 };
1271
Alan Viverettee34560b22014-07-10 14:50:06 -07001272 @Override
1273 public void showGlobalActions() {
1274 mHandler.removeMessages(MSG_DISPATCH_SHOW_GLOBAL_ACTIONS);
1275 mHandler.sendEmptyMessage(MSG_DISPATCH_SHOW_GLOBAL_ACTIONS);
1276 }
1277
1278 void showGlobalActionsInternal() {
1279 sendCloseSystemWindows(SYSTEM_DIALOG_REASON_GLOBAL_ACTIONS);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001280 if (mGlobalActions == null) {
Jeff Brown7304c342012-05-11 18:42:42 -07001281 mGlobalActions = new GlobalActions(mContext, mWindowManagerFuncs);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001282 }
Jim Millerab954542014-10-10 18:21:49 -07001283 final boolean keyguardShowing = isKeyguardShowingAndNotOccluded();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001284 mGlobalActions.showDialog(keyguardShowing, isDeviceProvisioned());
1285 if (keyguardShowing) {
1286 // since it took two seconds of long press to bring this up,
1287 // poke the wake lock so they have some time to see the dialog.
Jim Miller25190572013-02-28 17:36:24 -08001288 mPowerManager.userActivity(SystemClock.uptimeMillis(), false);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001289 }
1290 }
1291
1292 boolean isDeviceProvisioned() {
Jeff Brownbf6f6f92012-09-25 15:03:20 -07001293 return Settings.Global.getInt(
1294 mContext.getContentResolver(), Settings.Global.DEVICE_PROVISIONED, 0) != 0;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001295 }
1296
Maurice Lam99c6e072014-04-28 18:24:28 -07001297 boolean isUserSetupComplete() {
1298 return Settings.Secure.getIntForUser(mContext.getContentResolver(),
1299 Settings.Secure.USER_SETUP_COMPLETE, 0, UserHandle.USER_CURRENT) != 0;
1300 }
1301
Jeff Brown13f00f02014-10-31 14:45:50 -07001302 private void handleShortPressOnHome() {
Jinsuk Kime601b712015-07-07 08:01:02 +09001303 // Turn on the connected TV and switch HDMI input if we're a HDMI playback device.
1304 getHdmiControl().turnOnTv();
1305
Jeff Brown13f00f02014-10-31 14:45:50 -07001306 // If there's a dream running then use home to escape the dream
1307 // but don't actually go home.
1308 if (mDreamManagerInternal != null && mDreamManagerInternal.isDreaming()) {
1309 mDreamManagerInternal.stopDream(false /*immediate*/);
1310 return;
1311 }
1312
1313 // Go home!
1314 launchHomeFromHotKey();
1315 }
1316
Jinsuk Kime601b712015-07-07 08:01:02 +09001317 /**
1318 * Creates an accessor to HDMI control service that performs the operation of
1319 * turning on TV (optional) and switching input to us. If HDMI control service
1320 * is not available or we're not a HDMI playback device, the operation is no-op.
1321 */
1322 private HdmiControl getHdmiControl() {
1323 if (null == mHdmiControl) {
1324 HdmiControlManager manager = (HdmiControlManager) mContext.getSystemService(
1325 Context.HDMI_CONTROL_SERVICE);
1326 HdmiPlaybackClient client = null;
1327 if (manager != null) {
1328 client = manager.getPlaybackClient();
1329 }
1330 mHdmiControl = new HdmiControl(client);
1331 }
1332 return mHdmiControl;
1333 }
1334
1335 private static class HdmiControl {
1336 private final HdmiPlaybackClient mClient;
1337
1338 private HdmiControl(HdmiPlaybackClient client) {
1339 mClient = client;
1340 }
1341
1342 public void turnOnTv() {
1343 if (mClient == null) {
1344 return;
1345 }
1346 mClient.oneTouchPlay(new OneTouchPlayCallback() {
1347 @Override
1348 public void onComplete(int result) {
1349 if (result != HdmiControlManager.RESULT_SUCCESS) {
1350 Log.w(TAG, "One touch play failed: " + result);
1351 }
1352 }
1353 });
1354 }
1355 }
1356
Jaewan Kim76b7d0d2016-02-12 19:01:02 +09001357 private void handleLongPressOnHome(int deviceId) {
Jaewan Kim52632e22016-01-14 18:01:52 +09001358 if (mLongPressOnHomeBehavior == LONG_PRESS_HOME_NOTHING) {
1359 return;
1360 }
1361 mHomeConsumed = true;
1362 performHapticFeedbackLw(null, HapticFeedbackConstants.LONG_PRESS, false);
Patrick Dubroyece94522011-02-23 18:35:01 -08001363
Jaewan Kim52632e22016-01-14 18:01:52 +09001364 switch (mLongPressOnHomeBehavior) {
1365 case LONG_PRESS_HOME_RECENT_SYSTEM_UI:
Jeff Browncaca8812013-05-09 13:34:33 -07001366 toggleRecentApps();
Jaewan Kim52632e22016-01-14 18:01:52 +09001367 break;
1368 case LONG_PRESS_HOME_ASSIST:
Tim Kilbourn0e5f1102015-06-05 16:18:09 -07001369 launchAssistAction(null, deviceId);
Jaewan Kim52632e22016-01-14 18:01:52 +09001370 break;
Jaewan Kim52632e22016-01-14 18:01:52 +09001371 default:
Jaewan Kim76b7d0d2016-02-12 19:01:02 +09001372 Log.w(TAG, "Undefined home long press behavior: " + mLongPressOnHomeBehavior);
Jaewan Kim52632e22016-01-14 18:01:52 +09001373 break;
Jim Millere6ad1a82010-08-20 19:25:39 -07001374 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001375 }
Patrick Dubroyece94522011-02-23 18:35:01 -08001376
Jeff Browncaca8812013-05-09 13:34:33 -07001377 private void handleDoubleTapOnHome() {
1378 if (mDoubleTapOnHomeBehavior == DOUBLE_TAP_HOME_RECENT_SYSTEM_UI) {
1379 mHomeConsumed = true;
1380 toggleRecentApps();
1381 }
1382 }
1383
Jaewan Kimc552b042016-01-18 16:08:45 +09001384 private void requestTvPictureInPicture(KeyEvent event) {
1385 if (DEBUG_INPUT) Log.d(TAG, "requestTvPictureInPicture event=" + event);
1386 mHandler.removeMessages(MSG_REQUEST_TV_PICTURE_IN_PICTURE);
1387 Message msg = mHandler.obtainMessage(MSG_REQUEST_TV_PICTURE_IN_PICTURE);
1388 msg.setAsynchronous(true);
1389 msg.sendToTarget();
1390 }
1391
1392 private void requestTvPictureInPictureInternal() {
1393 try {
1394 IStatusBarService statusbar = getStatusBarService();
1395 if (statusbar != null) {
1396 statusbar.requestTvPictureInPicture();
1397 }
1398 } catch (RemoteException|IllegalArgumentException e) {
1399 Slog.e(TAG, "Cannot handle picture-in-picture key", e);
1400 // re-acquire status bar service next time it is needed.
1401 mStatusBarService = null;
1402 }
Jaewan Kim52632e22016-01-14 18:01:52 +09001403 }
1404
Jeff Browncaca8812013-05-09 13:34:33 -07001405 private final Runnable mHomeDoubleTapTimeoutRunnable = new Runnable() {
1406 @Override
1407 public void run() {
1408 if (mHomeDoubleTapPending) {
1409 mHomeDoubleTapPending = false;
Jeff Brown13f00f02014-10-31 14:45:50 -07001410 handleShortPressOnHome();
Jeff Browncaca8812013-05-09 13:34:33 -07001411 }
1412 }
1413 };
1414
Mark Renoufc1256912015-03-11 14:38:23 -04001415 private boolean isRoundWindow() {
Adam Powell01f280d2015-05-18 16:07:42 -07001416 return mContext.getResources().getConfiguration().isScreenRound();
Mark Renoufc1256912015-03-11 14:38:23 -04001417 }
1418
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001419 /** {@inheritDoc} */
Craig Mautner0bf6ec92012-12-18 08:33:27 -08001420 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001421 public void init(Context context, IWindowManager windowManager,
Jeff Brown96307042012-07-27 15:51:34 -07001422 WindowManagerFuncs windowManagerFuncs) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001423 mContext = context;
1424 mWindowManager = windowManager;
Dianne Hackborndf89e652011-10-06 22:35:11 -07001425 mWindowManagerFuncs = windowManagerFuncs;
Craig Mautner8a0da012014-05-31 15:13:37 -07001426 mWindowManagerInternal = LocalServices.getService(WindowManagerInternal.class);
Jeff Brown061ea992015-04-17 19:55:47 -07001427 mActivityManagerInternal = LocalServices.getService(ActivityManagerInternal.class);
Jose Lima9546b202014-07-02 17:21:51 -07001428 mDreamManagerInternal = LocalServices.getService(DreamManagerInternal.class);
Michael Wrighta4d22d72015-09-16 23:19:26 +01001429 mPowerManagerInternal = LocalServices.getService(PowerManagerInternal.class);
Billy Laucbe540f2015-06-25 01:51:44 +01001430 mAppOpsManager = (AppOpsManager) mContext.getSystemService(Context.APP_OPS_SERVICE);
Mark Renoufc1256912015-03-11 14:38:23 -04001431
1432 // Init display burn-in protection
1433 boolean burnInProtectionEnabled = context.getResources().getBoolean(
1434 com.android.internal.R.bool.config_enableBurnInProtection);
1435 // Allow a system property to override this. Used by developer settings.
1436 boolean burnInProtectionDevMode =
1437 SystemProperties.getBoolean("persist.debug.force_burn_in", false);
1438 if (burnInProtectionEnabled || burnInProtectionDevMode) {
1439 final int minHorizontal;
1440 final int maxHorizontal;
1441 final int minVertical;
1442 final int maxVertical;
1443 final int maxRadius;
1444 if (burnInProtectionDevMode) {
1445 minHorizontal = -8;
1446 maxHorizontal = 8;
1447 minVertical = -8;
1448 maxVertical = -4;
1449 maxRadius = (isRoundWindow()) ? 6 : -1;
1450 } else {
1451 Resources resources = context.getResources();
1452 minHorizontal = resources.getInteger(
1453 com.android.internal.R.integer.config_burnInProtectionMinHorizontalOffset);
1454 maxHorizontal = resources.getInteger(
1455 com.android.internal.R.integer.config_burnInProtectionMaxHorizontalOffset);
1456 minVertical = resources.getInteger(
1457 com.android.internal.R.integer.config_burnInProtectionMinVerticalOffset);
1458 maxVertical = resources.getInteger(
1459 com.android.internal.R.integer.config_burnInProtectionMaxVerticalOffset);
1460 maxRadius = resources.getInteger(
1461 com.android.internal.R.integer.config_burnInProtectionMaxRadius);
1462 }
1463 mBurnInProtectionHelper = new BurnInProtectionHelper(
1464 context, minHorizontal, maxHorizontal, minVertical, maxVertical, maxRadius);
Filip Gruszczynskicfb31852015-02-25 21:47:12 +00001465 }
Craig Mautner8a0da012014-05-31 15:13:37 -07001466
Jeff Brown70825162012-03-28 17:27:48 -07001467 mHandler = new PolicyHandler();
Jeff Browna20dda42014-05-27 20:57:24 -07001468 mWakeGestureListener = new MyWakeGestureListener(mContext, mHandler);
Craig Mautnereee29c42013-01-17 14:44:34 -08001469 mOrientationListener = new MyOrientationListener(mContext, mHandler);
Jeff Brownc0347aa2011-09-23 17:26:09 -07001470 try {
1471 mOrientationListener.setCurrentRotation(windowManager.getRotation());
1472 } catch (RemoteException ex) { }
Christopher Tate5e08af02012-09-21 17:17:22 -07001473 mSettingsObserver = new SettingsObserver(mHandler);
1474 mSettingsObserver.observe();
Svetoslav683914b2015-01-15 14:22:26 -08001475 mShortcutManager = new ShortcutManager(context);
Daniel Sandler6396c722013-04-16 20:19:09 -04001476 mUiMode = context.getResources().getInteger(
1477 com.android.internal.R.integer.config_defaultUiModeType);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001478 mHomeIntent = new Intent(Intent.ACTION_MAIN, null);
1479 mHomeIntent.addCategory(Intent.CATEGORY_HOME);
1480 mHomeIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK
1481 | Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED);
keunyounga7710492015-09-23 11:33:58 -07001482 mEnableCarDockHomeCapture = context.getResources().getBoolean(
1483 com.android.internal.R.bool.config_enableCarDockHomeLaunch);
Dianne Hackborn39c2d712009-09-22 11:41:31 -07001484 mCarDockIntent = new Intent(Intent.ACTION_MAIN, null);
1485 mCarDockIntent.addCategory(Intent.CATEGORY_CAR_DOCK);
1486 mCarDockIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK
1487 | Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED);
1488 mDeskDockIntent = new Intent(Intent.ACTION_MAIN, null);
1489 mDeskDockIntent.addCategory(Intent.CATEGORY_DESK_DOCK);
1490 mDeskDockIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK
1491 | Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED);
Jim Millere6ad1a82010-08-20 19:25:39 -07001492
Jeff Brown96307042012-07-27 15:51:34 -07001493 mPowerManager = (PowerManager)context.getSystemService(Context.POWER_SERVICE);
1494 mBroadcastWakeLock = mPowerManager.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK,
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001495 "PhoneWindowManager.mBroadcastWakeLock");
Jeff Brown13f00f02014-10-31 14:45:50 -07001496 mPowerKeyWakeLock = mPowerManager.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK,
1497 "PhoneWindowManager.mPowerKeyWakeLock");
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001498 mEnableShiftMenuBugReports = "1".equals(SystemProperties.get("ro.debuggable"));
Jeff Brownbcdfc622014-03-06 19:13:04 -08001499 mSupportAutoRotation = mContext.getResources().getBoolean(
1500 com.android.internal.R.bool.config_supportAutoRotation);
Dianne Hackborn2862fff2009-09-15 22:56:29 -07001501 mLidOpenRotation = readRotation(
Mike Lockwood2d1efbd2009-09-16 12:15:53 -04001502 com.android.internal.R.integer.config_lidOpenRotation);
1503 mCarDockRotation = readRotation(
1504 com.android.internal.R.integer.config_carDockRotation);
1505 mDeskDockRotation = readRotation(
1506 com.android.internal.R.integer.config_deskDockRotation);
Jeff Brownc82c89ed2013-04-17 17:18:15 -07001507 mUndockedHdmiRotation = readRotation(
1508 com.android.internal.R.integer.config_undockedHdmiRotation);
Mike Lockwoode9867d22009-09-20 01:59:02 -04001509 mCarDockEnablesAccelerometer = mContext.getResources().getBoolean(
1510 com.android.internal.R.bool.config_carDockEnablesAccelerometer);
1511 mDeskDockEnablesAccelerometer = mContext.getResources().getBoolean(
1512 com.android.internal.R.bool.config_deskDockEnablesAccelerometer);
Dianne Hackborn2862fff2009-09-15 22:56:29 -07001513 mLidKeyboardAccessibility = mContext.getResources().getInteger(
1514 com.android.internal.R.integer.config_lidKeyboardAccessibility);
1515 mLidNavigationAccessibility = mContext.getResources().getInteger(
1516 com.android.internal.R.integer.config_lidNavigationAccessibility);
Edward Savage-Jones7def60d2015-11-13 13:27:03 +01001517 mLidControlsScreenLock = mContext.getResources().getBoolean(
1518 com.android.internal.R.bool.config_lidControlsScreenLock);
Jeff Brownc458ce92012-04-30 14:58:40 -07001519 mLidControlsSleep = mContext.getResources().getBoolean(
1520 com.android.internal.R.bool.config_lidControlsSleep);
Daniel Sandlerdd73ee42013-10-11 22:19:59 -04001521 mTranslucentDecorEnabled = mContext.getResources().getBoolean(
1522 com.android.internal.R.bool.config_enableTranslucentDecor);
Bryce Lee584a4452014-10-21 15:55:55 -07001523
1524 mAllowTheaterModeWakeFromKey = mContext.getResources().getBoolean(
1525 com.android.internal.R.bool.config_allowTheaterModeWakeFromKey);
1526 mAllowTheaterModeWakeFromPowerKey = mAllowTheaterModeWakeFromKey
1527 || mContext.getResources().getBoolean(
1528 com.android.internal.R.bool.config_allowTheaterModeWakeFromPowerKey);
1529 mAllowTheaterModeWakeFromMotion = mContext.getResources().getBoolean(
1530 com.android.internal.R.bool.config_allowTheaterModeWakeFromMotion);
Bryce Lee812d7022014-11-10 13:33:28 -08001531 mAllowTheaterModeWakeFromMotionWhenNotDreaming = mContext.getResources().getBoolean(
1532 com.android.internal.R.bool.config_allowTheaterModeWakeFromMotionWhenNotDreaming);
Bryce Lee584a4452014-10-21 15:55:55 -07001533 mAllowTheaterModeWakeFromCameraLens = mContext.getResources().getBoolean(
1534 com.android.internal.R.bool.config_allowTheaterModeWakeFromCameraLens);
1535 mAllowTheaterModeWakeFromLidSwitch = mContext.getResources().getBoolean(
1536 com.android.internal.R.bool.config_allowTheaterModeWakeFromLidSwitch);
1537 mAllowTheaterModeWakeFromWakeGesture = mContext.getResources().getBoolean(
1538 com.android.internal.R.bool.config_allowTheaterModeWakeFromGesture);
1539
Bryce Lee55e846d2014-11-04 12:43:44 -08001540 mGoToSleepOnButtonPressTheaterMode = mContext.getResources().getBoolean(
1541 com.android.internal.R.bool.config_goToSleepOnButtonPressTheaterMode);
1542
Bryce Leed3b28402015-03-09 15:49:13 +00001543 mSupportLongPressPowerWhenNonInteractive = mContext.getResources().getBoolean(
1544 com.android.internal.R.bool.config_supportLongPressPowerWhenNonInteractive);
1545
Jeff Brown13f00f02014-10-31 14:45:50 -07001546 mShortPressOnPowerBehavior = mContext.getResources().getInteger(
1547 com.android.internal.R.integer.config_shortPressOnPowerBehavior);
1548 mLongPressOnPowerBehavior = mContext.getResources().getInteger(
1549 com.android.internal.R.integer.config_longPressOnPowerBehavior);
1550 mDoublePressOnPowerBehavior = mContext.getResources().getInteger(
1551 com.android.internal.R.integer.config_doublePressOnPowerBehavior);
1552 mTriplePressOnPowerBehavior = mContext.getResources().getInteger(
1553 com.android.internal.R.integer.config_triplePressOnPowerBehavior);
Filip Gruszczynskia483a1d2015-03-17 19:06:58 +00001554 mShortPressOnSleepBehavior = mContext.getResources().getInteger(
1555 com.android.internal.R.integer.config_shortPressOnSleepBehavior);
Jeff Brown13f00f02014-10-31 14:45:50 -07001556
John Spurlock61560172015-02-06 19:46:04 -05001557 mUseTvRouting = AudioSystem.getPlatformType(mContext) == AudioSystem.PLATFORM_TELEVISION;
RoboErik001c59c2015-01-26 15:53:51 -08001558
Jeff Brownf71343d2013-05-31 17:59:11 -07001559 readConfigurationDependentBehaviors();
Jeff Browncaca8812013-05-09 13:34:33 -07001560
Svetoslav8e3feb12014-02-24 13:46:47 -08001561 mAccessibilityManager = (AccessibilityManager) context.getSystemService(
1562 Context.ACCESSIBILITY_SERVICE);
1563
Mike Lockwood1753f7f2009-08-24 14:49:07 -07001564 // register for dock events
Dianne Hackborn78968392010-03-04 20:47:56 -08001565 IntentFilter filter = new IntentFilter();
1566 filter.addAction(UiModeManager.ACTION_ENTER_CAR_MODE);
1567 filter.addAction(UiModeManager.ACTION_EXIT_CAR_MODE);
1568 filter.addAction(UiModeManager.ACTION_ENTER_DESK_MODE);
1569 filter.addAction(UiModeManager.ACTION_EXIT_DESK_MODE);
Dianne Hackborn867ab6472010-04-29 13:28:56 -07001570 filter.addAction(Intent.ACTION_DOCK_EVENT);
1571 Intent intent = context.registerReceiver(mDockReceiver, filter);
1572 if (intent != null) {
1573 // Retrieve current sticky dock event broadcast.
1574 mDockMode = intent.getIntExtra(Intent.EXTRA_DOCK_STATE,
1575 Intent.EXTRA_DOCK_STATE_UNDOCKED);
1576 }
Daniel Sandler7e37df52011-11-16 22:08:23 -08001577
Jeff Brown6aaf2952012-10-05 16:01:08 -07001578 // register for dream-related broadcasts
1579 filter = new IntentFilter();
1580 filter.addAction(Intent.ACTION_DREAMING_STARTED);
1581 filter.addAction(Intent.ACTION_DREAMING_STOPPED);
1582 context.registerReceiver(mDreamReceiver, filter);
1583
Christopher Tate5e08af02012-09-21 17:17:22 -07001584 // register for multiuser-relevant broadcasts
1585 filter = new IntentFilter(Intent.ACTION_USER_SWITCHED);
1586 context.registerReceiver(mMultiuserReceiver, filter);
1587
John Spurlock57306e62013-04-22 09:48:49 -04001588 // monitor for system gestures
Craig Mautner037aa8d2013-06-07 10:35:44 -07001589 mSystemGestures = new SystemGesturesPointerEventListener(context,
1590 new SystemGesturesPointerEventListener.Callbacks() {
John Spurlock57306e62013-04-22 09:48:49 -04001591 @Override
1592 public void onSwipeFromTop() {
John Spurlock04db1762013-05-13 12:46:41 -04001593 if (mStatusBar != null) {
John Spurlocke1f366f2013-08-05 12:22:40 -04001594 requestTransientBars(mStatusBar);
John Spurlock04db1762013-05-13 12:46:41 -04001595 }
John Spurlockad3e6cb2013-04-30 08:47:43 -04001596 }
1597 @Override
1598 public void onSwipeFromBottom() {
John Spurlock04db1762013-05-13 12:46:41 -04001599 if (mNavigationBar != null && mNavigationBarOnBottom) {
John Spurlocke1f366f2013-08-05 12:22:40 -04001600 requestTransientBars(mNavigationBar);
John Spurlockad3e6cb2013-04-30 08:47:43 -04001601 }
1602 }
1603 @Override
1604 public void onSwipeFromRight() {
John Spurlock04db1762013-05-13 12:46:41 -04001605 if (mNavigationBar != null && !mNavigationBarOnBottom) {
John Spurlocke1f366f2013-08-05 12:22:40 -04001606 requestTransientBars(mNavigationBar);
John Spurlockad3e6cb2013-04-30 08:47:43 -04001607 }
1608 }
1609 @Override
Michael Wrighta4d22d72015-09-16 23:19:26 +01001610 public void onFling(int duration) {
1611 if (mPowerManagerInternal != null) {
1612 mPowerManagerInternal.powerHint(
1613 PowerManagerInternal.POWER_HINT_INTERACTION, duration);
1614 }
1615 }
1616 @Override
John Spurlockad3e6cb2013-04-30 08:47:43 -04001617 public void onDebug() {
John Spurlockd67ec252013-09-05 11:31:54 -04001618 // no-op
John Spurlockad3e6cb2013-04-30 08:47:43 -04001619 }
Adrian Roos3595be42015-03-05 16:31:15 +01001620 @Override
1621 public void onDown() {
1622 mOrientationListener.onTouchStart();
1623 }
1624 @Override
1625 public void onUpOrCancel() {
1626 mOrientationListener.onTouchEnd();
1627 }
Jun Mukaid2e7e352015-07-22 17:14:02 -07001628 @Override
1629 public void onMouseHoverAtTop() {
1630 mHandler.removeMessages(MSG_REQUEST_TRANSIENT_BARS);
1631 Message msg = mHandler.obtainMessage(MSG_REQUEST_TRANSIENT_BARS);
1632 msg.arg1 = MSG_REQUEST_TRANSIENT_BARS_ARG_STATUS;
1633 mHandler.sendMessageDelayed(msg, 500);
1634 }
1635 @Override
1636 public void onMouseHoverAtBottom() {
1637 mHandler.removeMessages(MSG_REQUEST_TRANSIENT_BARS);
1638 Message msg = mHandler.obtainMessage(MSG_REQUEST_TRANSIENT_BARS);
1639 msg.arg1 = MSG_REQUEST_TRANSIENT_BARS_ARG_NAVIGATION;
1640 mHandler.sendMessageDelayed(msg, 500);
1641 }
1642 @Override
1643 public void onMouseLeaveFromEdge() {
1644 mHandler.removeMessages(MSG_REQUEST_TRANSIENT_BARS);
1645 }
John Spurlockad3e6cb2013-04-30 08:47:43 -04001646 });
John Spurlockf1a36642013-10-12 17:50:42 -04001647 mImmersiveModeConfirmation = new ImmersiveModeConfirmation(mContext);
Craig Mautner037aa8d2013-06-07 10:35:44 -07001648 mWindowManagerFuncs.registerPointerEventListener(mSystemGestures);
John Spurlock32beb2c2013-03-11 10:16:47 -04001649
Jeff Brownc2346132012-04-13 01:55:38 -07001650 mVibrator = (Vibrator)context.getSystemService(Context.VIBRATOR_SERVICE);
Dianne Hackbornb1a79802009-09-29 15:18:31 -07001651 mLongPressVibePattern = getLongIntArray(mContext.getResources(),
1652 com.android.internal.R.array.config_longPressVibePattern);
1653 mVirtualKeyVibePattern = getLongIntArray(mContext.getResources(),
1654 com.android.internal.R.array.config_virtualKeyVibePattern);
Amith Yamasanic33cb712010-02-10 15:21:49 -08001655 mKeyboardTapVibePattern = getLongIntArray(mContext.getResources(),
1656 com.android.internal.R.array.config_keyboardTapVibePattern);
Fabrice Di Meglioeeff63a2013-08-05 12:07:24 -07001657 mClockTickVibePattern = getLongIntArray(mContext.getResources(),
1658 com.android.internal.R.array.config_clockTickVibePattern);
Fabrice Di Megliobd9152f2013-10-01 11:21:31 -07001659 mCalendarDateVibePattern = getLongIntArray(mContext.getResources(),
1660 com.android.internal.R.array.config_calendarDateVibePattern);
Dianne Hackbornb1a79802009-09-29 15:18:31 -07001661 mSafeModeDisabledVibePattern = getLongIntArray(mContext.getResources(),
1662 com.android.internal.R.array.config_safeModeDisabledVibePattern);
1663 mSafeModeEnabledVibePattern = getLongIntArray(mContext.getResources(),
1664 com.android.internal.R.array.config_safeModeEnabledVibePattern);
Mady Mellore8608912015-06-05 09:02:55 -07001665 mContextClickVibePattern = getLongIntArray(mContext.getResources(),
1666 com.android.internal.R.array.config_contextClickVibePattern);
Daniel Sandler40427442010-07-16 11:44:52 -04001667
Christopher Tatee90585f2012-03-05 18:56:25 -08001668 mScreenshotChordEnabled = mContext.getResources().getBoolean(
1669 com.android.internal.R.bool.config_enableScreenshotChord);
Jorim Jaggi406585a2015-12-21 10:58:56 +01001670 mForceWindowDrawsStatusBarBackground = mContext.getResources().getBoolean(
1671 R.bool.config_forceWindowDrawsStatusBarBackground);
Christopher Tatee90585f2012-03-05 18:56:25 -08001672
Justin Kohd378ad72013-04-01 12:18:26 -07001673 mGlobalKeyManager = new GlobalKeyManager(mContext);
1674
Joe Onoratoea495d42011-04-06 11:41:11 -07001675 // Controls rotation and the like.
1676 initializeHdmiState();
Dianne Hackborn40011092011-09-22 13:37:48 -07001677
1678 // Match current screen state.
Craig Mautnera631d492014-08-05 15:16:01 -07001679 if (!mPowerManager.isInteractive()) {
Jeff Brown416c49c2015-05-26 19:50:18 -07001680 startedGoingToSleep(WindowManagerPolicy.OFF_BECAUSE_OF_USER);
1681 finishedGoingToSleep(WindowManagerPolicy.OFF_BECAUSE_OF_USER);
Dianne Hackborn40011092011-09-22 13:37:48 -07001682 }
Jorim Jaggi24bec7c2015-02-04 12:40:14 +01001683
1684 mWindowManagerInternal.registerAppTransitionListener(
1685 mStatusBarController.getAppTransitionListener());
Mike Lockwood1753f7f2009-08-24 14:49:07 -07001686 }
1687
Jeff Brownf71343d2013-05-31 17:59:11 -07001688 /**
1689 * Read values from config.xml that may be overridden depending on
1690 * the configuration of the device.
1691 * eg. Disable long press on home goes to recents on sw600dp.
1692 */
1693 private void readConfigurationDependentBehaviors() {
Jaewan Kimc552b042016-01-18 16:08:45 +09001694 final Resources res = mContext.getResources();
1695
1696 mLongPressOnHomeBehavior = res.getInteger(
Jeff Brownf71343d2013-05-31 17:59:11 -07001697 com.android.internal.R.integer.config_longPressOnHomeBehavior);
1698 if (mLongPressOnHomeBehavior < LONG_PRESS_HOME_NOTHING ||
Jaewan Kim52632e22016-01-14 18:01:52 +09001699 mLongPressOnHomeBehavior > LAST_LONG_PRESS_HOME_BEHAVIOR) {
Jeff Brownf71343d2013-05-31 17:59:11 -07001700 mLongPressOnHomeBehavior = LONG_PRESS_HOME_NOTHING;
1701 }
1702
Jaewan Kimc552b042016-01-18 16:08:45 +09001703 mDoubleTapOnHomeBehavior = res.getInteger(
Jeff Brownf71343d2013-05-31 17:59:11 -07001704 com.android.internal.R.integer.config_doubleTapOnHomeBehavior);
1705 if (mDoubleTapOnHomeBehavior < DOUBLE_TAP_HOME_NOTHING ||
1706 mDoubleTapOnHomeBehavior > DOUBLE_TAP_HOME_RECENT_SYSTEM_UI) {
1707 mDoubleTapOnHomeBehavior = LONG_PRESS_HOME_NOTHING;
1708 }
Jaewan Kim49117872016-01-19 17:24:08 +09001709
1710 mShortPressWindowBehavior = SHORT_PRESS_WINDOW_NOTHING;
1711 if (mContext.getPackageManager().hasSystemFeature(FEATURE_PICTURE_IN_PICTURE)) {
1712 mShortPressWindowBehavior = SHORT_PRESS_WINDOW_PICTURE_IN_PICTURE;
1713 }
Jeff Brownf71343d2013-05-31 17:59:11 -07001714 }
1715
Craig Mautner0bf6ec92012-12-18 08:33:27 -08001716 @Override
Dianne Hackborndde331c2012-08-03 14:01:57 -07001717 public void setInitialDisplaySize(Display display, int width, int height, int density) {
Jeff Brownef981a42013-08-07 14:13:37 -07001718 // This method might be called before the policy has been fully initialized
1719 // or for other displays we don't care about.
1720 if (mContext == null || display.getDisplayId() != Display.DEFAULT_DISPLAY) {
1721 return;
Dianne Hackbornc652de82013-02-15 16:32:56 -08001722 }
Dianne Hackbornf87d1962012-04-04 12:48:24 -07001723 mDisplay = display;
1724
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001725 final Resources res = mContext.getResources();
Dianne Hackbornf87d1962012-04-04 12:48:24 -07001726 int shortSize, longSize;
Dianne Hackborn9d132642011-04-21 17:26:39 -07001727 if (width > height) {
Dianne Hackborn81e56d52011-05-26 00:55:58 -07001728 shortSize = height;
Dianne Hackbornf87d1962012-04-04 12:48:24 -07001729 longSize = width;
Dianne Hackborn9d132642011-04-21 17:26:39 -07001730 mLandscapeRotation = Surface.ROTATION_0;
1731 mSeascapeRotation = Surface.ROTATION_180;
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001732 if (res.getBoolean(com.android.internal.R.bool.config_reverseDefaultRotation)) {
Dianne Hackborn9d132642011-04-21 17:26:39 -07001733 mPortraitRotation = Surface.ROTATION_90;
1734 mUpsideDownRotation = Surface.ROTATION_270;
1735 } else {
1736 mPortraitRotation = Surface.ROTATION_270;
1737 mUpsideDownRotation = Surface.ROTATION_90;
1738 }
1739 } else {
Dianne Hackborn81e56d52011-05-26 00:55:58 -07001740 shortSize = width;
Dianne Hackbornf87d1962012-04-04 12:48:24 -07001741 longSize = height;
Dianne Hackborn9d132642011-04-21 17:26:39 -07001742 mPortraitRotation = Surface.ROTATION_0;
1743 mUpsideDownRotation = Surface.ROTATION_180;
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001744 if (res.getBoolean(com.android.internal.R.bool.config_reverseDefaultRotation)) {
Dianne Hackborn9d132642011-04-21 17:26:39 -07001745 mLandscapeRotation = Surface.ROTATION_270;
1746 mSeascapeRotation = Surface.ROTATION_90;
1747 } else {
1748 mLandscapeRotation = Surface.ROTATION_90;
1749 mSeascapeRotation = Surface.ROTATION_270;
1750 }
1751 }
Dianne Hackborn81e56d52011-05-26 00:55:58 -07001752
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001753 mStatusBarHeight =
1754 res.getDimensionPixelSize(com.android.internal.R.dimen.status_bar_height);
Dianne Hackbornf87d1962012-04-04 12:48:24 -07001755
Daniel Sandler9f65c4c2012-04-26 01:35:35 -04001756 // Height of the navigation bar when presented horizontally at bottom
Sriram Viswanathan9ebbe6a2015-11-16 17:59:22 -08001757 mNavigationBarHeightForRotationDefault[mPortraitRotation] =
1758 mNavigationBarHeightForRotationDefault[mUpsideDownRotation] =
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001759 res.getDimensionPixelSize(com.android.internal.R.dimen.navigation_bar_height);
Sriram Viswanathan9ebbe6a2015-11-16 17:59:22 -08001760 mNavigationBarHeightForRotationDefault[mLandscapeRotation] =
1761 mNavigationBarHeightForRotationDefault[mSeascapeRotation] = res.getDimensionPixelSize(
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001762 com.android.internal.R.dimen.navigation_bar_height_landscape);
Daniel Sandler9f65c4c2012-04-26 01:35:35 -04001763
1764 // Width of the navigation bar when presented vertically along one side
Sriram Viswanathan9ebbe6a2015-11-16 17:59:22 -08001765 mNavigationBarWidthForRotationDefault[mPortraitRotation] =
1766 mNavigationBarWidthForRotationDefault[mUpsideDownRotation] =
1767 mNavigationBarWidthForRotationDefault[mLandscapeRotation] =
1768 mNavigationBarWidthForRotationDefault[mSeascapeRotation] =
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001769 res.getDimensionPixelSize(com.android.internal.R.dimen.navigation_bar_width);
Daniel Sandler4a066c52012-04-20 14:49:13 -04001770
Sriram Viswanathan9ebbe6a2015-11-16 17:59:22 -08001771 // Height of the navigation bar when presented horizontally at bottom
1772 mNavigationBarHeightForRotationInCarMode[mPortraitRotation] =
1773 mNavigationBarHeightForRotationInCarMode[mUpsideDownRotation] =
1774 res.getDimensionPixelSize(
1775 com.android.internal.R.dimen.navigation_bar_height_car_mode);
1776 mNavigationBarHeightForRotationInCarMode[mLandscapeRotation] =
1777 mNavigationBarHeightForRotationInCarMode[mSeascapeRotation] = res.getDimensionPixelSize(
1778 com.android.internal.R.dimen.navigation_bar_height_landscape_car_mode);
1779
1780 // Width of the navigation bar when presented vertically along one side
1781 mNavigationBarWidthForRotationInCarMode[mPortraitRotation] =
1782 mNavigationBarWidthForRotationInCarMode[mUpsideDownRotation] =
1783 mNavigationBarWidthForRotationInCarMode[mLandscapeRotation] =
1784 mNavigationBarWidthForRotationInCarMode[mSeascapeRotation] =
1785 res.getDimensionPixelSize(
1786 com.android.internal.R.dimen.navigation_bar_width_car_mode);
1787
Daniel Sandler4a066c52012-04-20 14:49:13 -04001788 // SystemUI (status bar) layout policy
Dianne Hackborndde331c2012-08-03 14:01:57 -07001789 int shortSizeDp = shortSize * DisplayMetrics.DENSITY_DEFAULT / density;
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001790 int longSizeDp = longSize * DisplayMetrics.DENSITY_DEFAULT / density;
Daniel Sandler4a066c52012-04-20 14:49:13 -04001791
Devin Kimd7b12b42014-05-05 14:34:58 -07001792 // Allow the navigation bar to move on non-square small devices (phones).
1793 mNavigationBarCanMove = width != height && shortSizeDp < 600;
Daniel Sandler36412a72011-08-04 09:35:13 -04001794
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001795 mHasNavigationBar = res.getBoolean(com.android.internal.R.bool.config_showNavigationBar);
John Spurlock80f00c12013-06-13 11:10:51 -04001796 // Allow a system property to override this. Used by the emulator.
1797 // See also hasNavigationBar().
1798 String navBarOverride = SystemProperties.get("qemu.hw.mainkeys");
1799 if ("1".equals(navBarOverride)) {
Dianne Hackbornf87d1962012-04-04 12:48:24 -07001800 mHasNavigationBar = false;
John Spurlock80f00c12013-06-13 11:10:51 -04001801 } else if ("0".equals(navBarOverride)) {
1802 mHasNavigationBar = true;
Daniel Sandler0c4ccff2011-10-19 16:39:14 -04001803 }
1804
Jeff Brown27f1d672012-10-17 18:32:34 -07001805 // For demo purposes, allow the rotation of the HDMI display to be controlled.
1806 // By default, HDMI locks rotation to landscape.
Erik Gilling9a41ef82011-09-26 19:21:03 -07001807 if ("portrait".equals(SystemProperties.get("persist.demo.hdmirotation"))) {
Jeff Brownc82c89ed2013-04-17 17:18:15 -07001808 mDemoHdmiRotation = mPortraitRotation;
Erik Gilling9a41ef82011-09-26 19:21:03 -07001809 } else {
Jeff Brownc82c89ed2013-04-17 17:18:15 -07001810 mDemoHdmiRotation = mLandscapeRotation;
Erik Gilling9a41ef82011-09-26 19:21:03 -07001811 }
Jeff Brownc82c89ed2013-04-17 17:18:15 -07001812 mDemoHdmiRotationLock = SystemProperties.getBoolean("persist.demo.hdmirotationlock", false);
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001813
Chong Zhangae6119ff2014-11-11 18:54:39 -08001814 // For demo purposes, allow the rotation of the remote display to be controlled.
1815 // By default, remote display locks rotation to landscape.
1816 if ("portrait".equals(SystemProperties.get("persist.demo.remoterotation"))) {
1817 mDemoRotation = mPortraitRotation;
1818 } else {
1819 mDemoRotation = mLandscapeRotation;
1820 }
1821 mDemoRotationLock = SystemProperties.getBoolean(
1822 "persist.demo.rotationlock", false);
1823
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001824 // Only force the default orientation if the screen is xlarge, at least 960dp x 720dp, per
1825 // http://developer.android.com/guide/practices/screens_support.html#range
1826 mForceDefaultOrientation = longSizeDp >= 960 && shortSizeDp >= 720 &&
1827 res.getBoolean(com.android.internal.R.bool.config_forceDefaultOrientation) &&
1828 // For debug purposes the next line turns this feature off with:
1829 // $ adb shell setprop config.override_forced_orient true
1830 // $ adb shell wm size reset
1831 !"true".equals(SystemProperties.get("config.override_forced_orient"));
1832 }
1833
Alan Viverette5a0f4ec2013-10-07 15:10:29 -07001834 /**
1835 * @return whether the navigation bar can be hidden, e.g. the device has a
1836 * navigation bar and touch exploration is not enabled
1837 */
1838 private boolean canHideNavigationBar() {
Alan Viverette817f3cd2015-08-13 11:40:14 -04001839 return mHasNavigationBar;
Alan Viverette5a0f4ec2013-10-07 15:10:29 -07001840 }
1841
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001842 @Override
1843 public boolean isDefaultOrientationForced() {
1844 return mForceDefaultOrientation;
Dianne Hackborn9d132642011-04-21 17:26:39 -07001845 }
1846
Dianne Hackbornc652de82013-02-15 16:32:56 -08001847 @Override
1848 public void setDisplayOverscan(Display display, int left, int top, int right, int bottom) {
1849 if (display.getDisplayId() == Display.DEFAULT_DISPLAY) {
1850 mOverscanLeft = left;
1851 mOverscanTop = top;
1852 mOverscanRight = right;
1853 mOverscanBottom = bottom;
1854 }
1855 }
1856
Dianne Hackbornc777e072010-02-12 13:07:59 -08001857 public void updateSettings() {
1858 ContentResolver resolver = mContext.getContentResolver();
1859 boolean updateRotation = false;
Dianne Hackbornc777e072010-02-12 13:07:59 -08001860 synchronized (mLock) {
Christopher Tate5e08af02012-09-21 17:17:22 -07001861 mEndcallBehavior = Settings.System.getIntForUser(resolver,
David Brownbaf8d092010-03-08 21:52:59 -08001862 Settings.System.END_BUTTON_BEHAVIOR,
Christopher Tate5e08af02012-09-21 17:17:22 -07001863 Settings.System.END_BUTTON_BEHAVIOR_DEFAULT,
1864 UserHandle.USER_CURRENT);
1865 mIncallPowerBehavior = Settings.Secure.getIntForUser(resolver,
David Brownbaf8d092010-03-08 21:52:59 -08001866 Settings.Secure.INCALL_POWER_BUTTON_BEHAVIOR,
Christopher Tate5e08af02012-09-21 17:17:22 -07001867 Settings.Secure.INCALL_POWER_BUTTON_BEHAVIOR_DEFAULT,
1868 UserHandle.USER_CURRENT);
Daniel Sandlerb73617d2010-08-17 00:41:00 -04001869
Jeff Browna20dda42014-05-27 20:57:24 -07001870 // Configure wake gesture.
1871 boolean wakeGestureEnabledSetting = Settings.Secure.getIntForUser(resolver,
1872 Settings.Secure.WAKE_GESTURE_ENABLED, 0,
1873 UserHandle.USER_CURRENT) != 0;
1874 if (mWakeGestureEnabledSetting != wakeGestureEnabledSetting) {
1875 mWakeGestureEnabledSetting = wakeGestureEnabledSetting;
1876 updateWakeGestureListenerLp();
1877 }
1878
Jeff Brown207673cd2012-06-05 17:47:11 -07001879 // Configure rotation lock.
Christopher Tate5e08af02012-09-21 17:17:22 -07001880 int userRotation = Settings.System.getIntForUser(resolver,
1881 Settings.System.USER_ROTATION, Surface.ROTATION_0,
1882 UserHandle.USER_CURRENT);
Jeff Brown207673cd2012-06-05 17:47:11 -07001883 if (mUserRotation != userRotation) {
1884 mUserRotation = userRotation;
1885 updateRotation = true;
1886 }
Christopher Tate5e08af02012-09-21 17:17:22 -07001887 int userRotationMode = Settings.System.getIntForUser(resolver,
1888 Settings.System.ACCELEROMETER_ROTATION, 0, UserHandle.USER_CURRENT) != 0 ?
Jeff Brown207673cd2012-06-05 17:47:11 -07001889 WindowManagerPolicy.USER_ROTATION_FREE :
1890 WindowManagerPolicy.USER_ROTATION_LOCKED;
1891 if (mUserRotationMode != userRotationMode) {
1892 mUserRotationMode = userRotationMode;
1893 updateRotation = true;
Dianne Hackbornc777e072010-02-12 13:07:59 -08001894 updateOrientationListenerLp();
1895 }
Daniel Sandlerb73617d2010-08-17 00:41:00 -04001896
Dianne Hackbornc777e072010-02-12 13:07:59 -08001897 if (mSystemReady) {
Christopher Tate5e08af02012-09-21 17:17:22 -07001898 int pointerLocation = Settings.System.getIntForUser(resolver,
1899 Settings.System.POINTER_LOCATION, 0, UserHandle.USER_CURRENT);
Dianne Hackbornc777e072010-02-12 13:07:59 -08001900 if (mPointerLocationMode != pointerLocation) {
1901 mPointerLocationMode = pointerLocation;
Jeff Brown70825162012-03-28 17:27:48 -07001902 mHandler.sendEmptyMessage(pointerLocation != 0 ?
1903 MSG_ENABLE_POINTER_LOCATION : MSG_DISABLE_POINTER_LOCATION);
Dianne Hackbornc777e072010-02-12 13:07:59 -08001904 }
1905 }
1906 // use screen off timeout setting as the timeout for the lockscreen
Christopher Tate5e08af02012-09-21 17:17:22 -07001907 mLockScreenTimeout = Settings.System.getIntForUser(resolver,
1908 Settings.System.SCREEN_OFF_TIMEOUT, 0, UserHandle.USER_CURRENT);
1909 String imId = Settings.Secure.getStringForUser(resolver,
1910 Settings.Secure.DEFAULT_INPUT_METHOD, UserHandle.USER_CURRENT);
Dianne Hackbornc777e072010-02-12 13:07:59 -08001911 boolean hasSoftInput = imId != null && imId.length() > 0;
1912 if (mHasSoftInput != hasSoftInput) {
1913 mHasSoftInput = hasSoftInput;
1914 updateRotation = true;
1915 }
John Spurlockf1a36642013-10-12 17:50:42 -04001916 if (mImmersiveModeConfirmation != null) {
John Spurlock4355a532014-02-19 09:49:25 -05001917 mImmersiveModeConfirmation.loadSetting(mCurrentUserId);
John Spurlockd67ec252013-09-05 11:31:54 -04001918 }
tiger_huangcc6366d2015-06-29 17:17:30 +08001919 }
1920 synchronized (mWindowManagerFuncs.getWindowManagerLock()) {
John Spurlockc6d1c602014-01-17 15:22:06 -05001921 PolicyControl.reloadFromSetting(mContext);
Dianne Hackbornc777e072010-02-12 13:07:59 -08001922 }
1923 if (updateRotation) {
Jeff Brown01a98dd2011-09-20 15:08:29 -07001924 updateRotation(true);
Dianne Hackbornc777e072010-02-12 13:07:59 -08001925 }
Jeff Brown70825162012-03-28 17:27:48 -07001926 }
1927
Jeff Browna20dda42014-05-27 20:57:24 -07001928 private void updateWakeGestureListenerLp() {
1929 if (shouldEnableWakeGestureLp()) {
1930 mWakeGestureListener.requestWakeUpTrigger();
1931 } else {
1932 mWakeGestureListener.cancelWakeUpTrigger();
1933 }
1934 }
1935
1936 private boolean shouldEnableWakeGestureLp() {
Jeff Brown3ee549c2014-09-22 20:14:39 -07001937 return mWakeGestureEnabledSetting && !mAwake
Jeff Browna20dda42014-05-27 20:57:24 -07001938 && (!mLidControlsSleep || mLidState != LID_CLOSED)
1939 && mWakeGestureListener.isSupported();
1940 }
1941
Jeff Brown70825162012-03-28 17:27:48 -07001942 private void enablePointerLocation() {
1943 if (mPointerLocationView == null) {
1944 mPointerLocationView = new PointerLocationView(mContext);
1945 mPointerLocationView.setPrintCoords(false);
Dianne Hackbornc777e072010-02-12 13:07:59 -08001946 WindowManager.LayoutParams lp = new WindowManager.LayoutParams(
1947 WindowManager.LayoutParams.MATCH_PARENT,
1948 WindowManager.LayoutParams.MATCH_PARENT);
Jeff Brown3b2b3542010-10-15 00:54:27 -07001949 lp.type = WindowManager.LayoutParams.TYPE_SECURE_SYSTEM_OVERLAY;
Jeff Brownbfcb60a2011-09-08 18:51:14 -07001950 lp.flags = WindowManager.LayoutParams.FLAG_FULLSCREEN
1951 | WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE
1952 | WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE
1953 | WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN;
Jeff Brown90fc9052012-10-01 14:44:24 -07001954 if (ActivityManager.isHighEndGfx()) {
1955 lp.flags |= WindowManager.LayoutParams.FLAG_HARDWARE_ACCELERATED;
1956 lp.privateFlags |=
1957 WindowManager.LayoutParams.PRIVATE_FLAG_FORCE_HARDWARE_ACCELERATED;
1958 }
Dianne Hackbornc777e072010-02-12 13:07:59 -08001959 lp.format = PixelFormat.TRANSLUCENT;
1960 lp.setTitle("PointerLocation");
Dianne Hackborn5fd21692011-06-07 14:09:47 -07001961 WindowManager wm = (WindowManager)
Dianne Hackbornc777e072010-02-12 13:07:59 -08001962 mContext.getSystemService(Context.WINDOW_SERVICE);
Jeff Browncc4f7db2011-08-30 20:34:48 -07001963 lp.inputFeatures |= WindowManager.LayoutParams.INPUT_FEATURE_NO_INPUT_CHANNEL;
Jeff Brown70825162012-03-28 17:27:48 -07001964 wm.addView(mPointerLocationView, lp);
Michael Wrightc9c487e2013-11-07 18:55:09 -08001965 mWindowManagerFuncs.registerPointerEventListener(mPointerLocationView);
Dianne Hackbornc777e072010-02-12 13:07:59 -08001966 }
Dianne Hackbornc777e072010-02-12 13:07:59 -08001967 }
Jeff Brown70825162012-03-28 17:27:48 -07001968
1969 private void disablePointerLocation() {
Jeff Brown70825162012-03-28 17:27:48 -07001970 if (mPointerLocationView != null) {
Michael Wrightc9c487e2013-11-07 18:55:09 -08001971 mWindowManagerFuncs.unregisterPointerEventListener(mPointerLocationView);
1972 WindowManager wm = (WindowManager) mContext.getSystemService(Context.WINDOW_SERVICE);
Jeff Brown70825162012-03-28 17:27:48 -07001973 wm.removeView(mPointerLocationView);
1974 mPointerLocationView = null;
1975 }
1976 }
1977
Mike Lockwood2d1efbd2009-09-16 12:15:53 -04001978 private int readRotation(int resID) {
Mike Lockwood1753f7f2009-08-24 14:49:07 -07001979 try {
1980 int rotation = mContext.getResources().getInteger(resID);
1981 switch (rotation) {
1982 case 0:
1983 return Surface.ROTATION_0;
1984 case 90:
1985 return Surface.ROTATION_90;
1986 case 180:
1987 return Surface.ROTATION_180;
1988 case 270:
1989 return Surface.ROTATION_270;
Mike Lockwood1753f7f2009-08-24 14:49:07 -07001990 }
1991 } catch (Resources.NotFoundException e) {
Mike Lockwood2d1efbd2009-09-16 12:15:53 -04001992 // fall through
Mike Lockwood1753f7f2009-08-24 14:49:07 -07001993 }
Mike Lockwood2d1efbd2009-09-16 12:15:53 -04001994 return -1;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001995 }
1996
1997 /** {@inheritDoc} */
Craig Mautner88400d32012-09-30 12:35:45 -07001998 @Override
Dianne Hackbornc2293022013-02-06 23:14:49 -08001999 public int checkAddPermission(WindowManager.LayoutParams attrs, int[] outAppOp) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002000 int type = attrs.type;
Dianne Hackbornc2293022013-02-06 23:14:49 -08002001
2002 outAppOp[0] = AppOpsManager.OP_NONE;
2003
Wale Ogunwale74bf0652015-01-12 10:24:36 -08002004 if (!((type >= FIRST_APPLICATION_WINDOW && type <= LAST_APPLICATION_WINDOW)
2005 || (type >= FIRST_SUB_WINDOW && type <= LAST_SUB_WINDOW)
2006 || (type >= FIRST_SYSTEM_WINDOW && type <= LAST_SYSTEM_WINDOW))) {
2007 return WindowManagerGlobal.ADD_INVALID_TYPE;
2008 }
2009
2010 if (type < FIRST_SYSTEM_WINDOW || type > LAST_SYSTEM_WINDOW) {
2011 // Window manager will make sure these are okay.
Jeff Brown98365d72012-08-19 20:30:52 -07002012 return WindowManagerGlobal.ADD_OKAY;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002013 }
2014 String permission = null;
2015 switch (type) {
2016 case TYPE_TOAST:
2017 // XXX right now the app process has complete control over
2018 // this... should introduce a token to let the system
2019 // monitor/control what they are doing.
Jason Monk1c7c3192014-06-26 12:52:18 -04002020 outAppOp[0] = AppOpsManager.OP_TOAST_WINDOW;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002021 break;
Daniel Sandler7d276c32012-01-30 14:33:52 -05002022 case TYPE_DREAM:
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002023 case TYPE_INPUT_METHOD:
Dianne Hackbornb7cd8b92009-08-08 20:53:03 -07002024 case TYPE_WALLPAPER:
keunyounga446bf02013-06-21 19:07:57 -07002025 case TYPE_PRIVATE_PRESENTATION:
Dianne Hackborne30e02f2014-05-27 18:24:45 -07002026 case TYPE_VOICE_INTERACTION:
Svetoslav3a5c7212014-10-14 09:54:26 -07002027 case TYPE_ACCESSIBILITY_OVERLAY:
Jason Monk8f7f3182015-11-18 16:35:14 -05002028 case TYPE_QS_DIALOG:
Dianne Hackbornb7cd8b92009-08-08 20:53:03 -07002029 // The window manager will check these.
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002030 break;
2031 case TYPE_PHONE:
2032 case TYPE_PRIORITY_PHONE:
2033 case TYPE_SYSTEM_ALERT:
2034 case TYPE_SYSTEM_ERROR:
2035 case TYPE_SYSTEM_OVERLAY:
2036 permission = android.Manifest.permission.SYSTEM_ALERT_WINDOW;
Dianne Hackbornc2293022013-02-06 23:14:49 -08002037 outAppOp[0] = AppOpsManager.OP_SYSTEM_ALERT_WINDOW;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002038 break;
2039 default:
2040 permission = android.Manifest.permission.INTERNAL_SYSTEM_WINDOW;
2041 }
2042 if (permission != null) {
Svet Ganov9cea80cd2016-02-16 11:47:00 -08002043 if (android.Manifest.permission.SYSTEM_ALERT_WINDOW.equals(permission)) {
Billy Laucbe540f2015-06-25 01:51:44 +01002044 final int callingUid = Binder.getCallingUid();
Billy Lau060275f2015-07-15 22:29:19 +01002045 // system processes will be automatically allowed privilege to draw
Billy Laucbe540f2015-06-25 01:51:44 +01002046 if (callingUid == Process.SYSTEM_UID) {
2047 return WindowManagerGlobal.ADD_OKAY;
2048 }
2049
Billy Lau060275f2015-07-15 22:29:19 +01002050 // check if user has enabled this operation. SecurityException will be thrown if
2051 // this app has not been allowed by the user
Billy Laucbe540f2015-06-25 01:51:44 +01002052 final int mode = mAppOpsManager.checkOp(outAppOp[0], callingUid,
2053 attrs.packageName);
Billy Lau060275f2015-07-15 22:29:19 +01002054 switch (mode) {
2055 case AppOpsManager.MODE_ALLOWED:
2056 case AppOpsManager.MODE_IGNORED:
2057 // although we return ADD_OKAY for MODE_IGNORED, the added window will
2058 // actually be hidden in WindowManagerService
2059 return WindowManagerGlobal.ADD_OKAY;
2060 case AppOpsManager.MODE_ERRORED:
Billy Laucbe540f2015-06-25 01:51:44 +01002061 return WindowManagerGlobal.ADD_PERMISSION_DENIED;
Billy Lau060275f2015-07-15 22:29:19 +01002062 default:
2063 // in the default mode, we will make a decision here based on
2064 // checkCallingPermission()
2065 if (mContext.checkCallingPermission(permission) !=
2066 PackageManager.PERMISSION_GRANTED) {
2067 return WindowManagerGlobal.ADD_PERMISSION_DENIED;
2068 } else {
2069 return WindowManagerGlobal.ADD_OKAY;
2070 }
Billy Laucbe540f2015-06-25 01:51:44 +01002071 }
Billy Laucbe540f2015-06-25 01:51:44 +01002072 }
2073
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002074 if (mContext.checkCallingOrSelfPermission(permission)
2075 != PackageManager.PERMISSION_GRANTED) {
Jeff Brown98365d72012-08-19 20:30:52 -07002076 return WindowManagerGlobal.ADD_PERMISSION_DENIED;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002077 }
2078 }
Jeff Brown98365d72012-08-19 20:30:52 -07002079 return WindowManagerGlobal.ADD_OKAY;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002080 }
Craig Mautner88400d32012-09-30 12:35:45 -07002081
2082 @Override
2083 public boolean checkShowToOwnerOnly(WindowManager.LayoutParams attrs) {
2084
2085 // If this switch statement is modified, modify the comment in the declarations of
2086 // the type in {@link WindowManager.LayoutParams} as well.
2087 switch (attrs.type) {
2088 default:
2089 // These are the windows that by default are shown only to the user that created
2090 // them. If this needs to be overridden, set
2091 // {@link WindowManager.LayoutParams.PRIVATE_FLAG_SHOW_FOR_ALL_USERS} in
2092 // {@link WindowManager.LayoutParams}. Note that permission
2093 // {@link android.Manifest.permission.INTERNAL_SYSTEM_WINDOW} is required as well.
2094 if ((attrs.privateFlags & PRIVATE_FLAG_SHOW_FOR_ALL_USERS) == 0) {
2095 return true;
2096 }
2097 break;
2098
2099 // These are the windows that by default are shown to all users. However, to
2100 // protect against spoofing, check permissions below.
2101 case TYPE_APPLICATION_STARTING:
2102 case TYPE_BOOT_PROGRESS:
2103 case TYPE_DISPLAY_OVERLAY:
Selim Cinekf83e8242015-05-19 18:08:14 -07002104 case TYPE_INPUT_CONSUMER:
Jim Miller5ecd8112013-01-09 18:50:26 -08002105 case TYPE_KEYGUARD_SCRIM:
Craig Mautner88400d32012-09-30 12:35:45 -07002106 case TYPE_KEYGUARD_DIALOG:
2107 case TYPE_MAGNIFICATION_OVERLAY:
2108 case TYPE_NAVIGATION_BAR:
2109 case TYPE_NAVIGATION_BAR_PANEL:
2110 case TYPE_PHONE:
2111 case TYPE_POINTER:
2112 case TYPE_PRIORITY_PHONE:
Craig Mautner88400d32012-09-30 12:35:45 -07002113 case TYPE_SEARCH_BAR:
2114 case TYPE_STATUS_BAR:
2115 case TYPE_STATUS_BAR_PANEL:
2116 case TYPE_STATUS_BAR_SUB_PANEL:
2117 case TYPE_SYSTEM_DIALOG:
Craig Mautner88400d32012-09-30 12:35:45 -07002118 case TYPE_VOLUME_OVERLAY:
keunyounga446bf02013-06-21 19:07:57 -07002119 case TYPE_PRIVATE_PRESENTATION:
Filip Gruszczynski466f3212015-09-21 17:57:57 -07002120 case TYPE_DOCK_DIVIDER:
Craig Mautner88400d32012-09-30 12:35:45 -07002121 break;
2122 }
2123
2124 // Check if third party app has set window to system window type.
2125 return mContext.checkCallingOrSelfPermission(
2126 android.Manifest.permission.INTERNAL_SYSTEM_WINDOW)
2127 != PackageManager.PERMISSION_GRANTED;
2128 }
2129
Craig Mautner967212c2013-04-13 21:10:58 -07002130 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002131 public void adjustWindowParamsLw(WindowManager.LayoutParams attrs) {
2132 switch (attrs.type) {
2133 case TYPE_SYSTEM_OVERLAY:
Jeff Brown3b2b3542010-10-15 00:54:27 -07002134 case TYPE_SECURE_SYSTEM_OVERLAY:
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002135 // These types of windows can't receive input events.
2136 attrs.flags |= WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE
2137 | WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE;
Jeff Brownbfcb60a2011-09-08 18:51:14 -07002138 attrs.flags &= ~WindowManager.LayoutParams.FLAG_WATCH_OUTSIDE_TOUCH;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002139 break;
Jorim Jaggi380ecb82014-03-14 17:25:20 +01002140 case TYPE_STATUS_BAR:
2141
2142 // If the Keyguard is in a hidden state (occluded by another window), we force to
2143 // remove the wallpaper and keyguard flag so that any change in-flight after setting
2144 // the keyguard as occluded wouldn't set these flags again.
2145 // See {@link #processKeyguardSetHiddenResultLw}.
2146 if (mKeyguardHidden) {
2147 attrs.flags &= ~WindowManager.LayoutParams.FLAG_SHOW_WALLPAPER;
2148 attrs.privateFlags &= ~WindowManager.LayoutParams.PRIVATE_FLAG_KEYGUARD;
2149 }
2150 break;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002151 }
Adrian Roos38502112014-04-09 21:04:11 +02002152
2153 if (attrs.type != TYPE_STATUS_BAR) {
2154 // The status bar is the only window allowed to exhibit keyguard behavior.
2155 attrs.privateFlags &= ~WindowManager.LayoutParams.PRIVATE_FLAG_KEYGUARD;
2156 }
Adrian Roosea562512014-05-05 13:33:03 +02002157
Jorim Jaggi4fa78922015-11-30 17:13:56 -08002158 if (ActivityManager.isHighEndGfx()) {
2159 if ((attrs.flags & FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS) != 0) {
2160 attrs.subtreeSystemUiVisibility |= View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION;
2161 }
2162 if ((attrs.flags & FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS) != 0
Jorim Jaggi406585a2015-12-21 10:58:56 +01002163 || (mForceWindowDrawsStatusBarBackground
2164 && attrs.height == MATCH_PARENT && attrs.width == MATCH_PARENT)) {
Jorim Jaggi4fa78922015-11-30 17:13:56 -08002165 attrs.subtreeSystemUiVisibility |= View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN;
2166 }
Adrian Roosea562512014-05-05 13:33:03 +02002167 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002168 }
RoboErik8a2cfc32014-05-16 11:19:38 -07002169
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002170 void readLidState() {
Jeff Brown2e7760e2012-04-11 15:14:55 -07002171 mLidState = mWindowManagerFuncs.getLidState();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002172 }
RoboErik8a2cfc32014-05-16 11:19:38 -07002173
Michael Wright3818c922014-09-02 13:59:07 -07002174 private void readCameraLensCoverState() {
2175 mCameraLensCoverState = mWindowManagerFuncs.getCameraLensCoverState();
2176 }
2177
Jeff Browndaa37532012-05-01 15:54:03 -07002178 private boolean isHidden(int accessibilityMode) {
2179 switch (accessibilityMode) {
2180 case 1:
2181 return mLidState == LID_CLOSED;
2182 case 2:
2183 return mLidState == LID_OPEN;
2184 default:
2185 return false;
Dianne Hackborn2862fff2009-09-15 22:56:29 -07002186 }
Dianne Hackborn2862fff2009-09-15 22:56:29 -07002187 }
Jeff Brownd04a88c2011-01-16 14:05:47 -08002188
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002189 /** {@inheritDoc} */
Craig Mautner967212c2013-04-13 21:10:58 -07002190 @Override
Jeff Browndaa37532012-05-01 15:54:03 -07002191 public void adjustConfigurationLw(Configuration config, int keyboardPresence,
2192 int navigationPresence) {
2193 mHaveBuiltInKeyboard = (keyboardPresence & PRESENCE_INTERNAL) != 0;
2194
Jeff Brownf71343d2013-05-31 17:59:11 -07002195 readConfigurationDependentBehaviors();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002196 readLidState();
Jeff Brownc458ce92012-04-30 14:58:40 -07002197 applyLidSwitchState();
Jeff Brownd04a88c2011-01-16 14:05:47 -08002198
Jeff Browndaa37532012-05-01 15:54:03 -07002199 if (config.keyboard == Configuration.KEYBOARD_NOKEYS
2200 || (keyboardPresence == PRESENCE_INTERNAL
2201 && isHidden(mLidKeyboardAccessibility))) {
Jeff Brownd04a88c2011-01-16 14:05:47 -08002202 config.hardKeyboardHidden = Configuration.HARDKEYBOARDHIDDEN_YES;
Jeff Browndaa37532012-05-01 15:54:03 -07002203 if (!mHasSoftInput) {
2204 config.keyboardHidden = Configuration.KEYBOARDHIDDEN_YES;
2205 }
Jeff Brownd04a88c2011-01-16 14:05:47 -08002206 }
2207
Jeff Browndaa37532012-05-01 15:54:03 -07002208 if (config.navigation == Configuration.NAVIGATION_NONAV
2209 || (navigationPresence == PRESENCE_INTERNAL
2210 && isHidden(mLidNavigationAccessibility))) {
Jeff Brownd04a88c2011-01-16 14:05:47 -08002211 config.navigationHidden = Configuration.NAVIGATIONHIDDEN_YES;
Jeff Brownd04a88c2011-01-16 14:05:47 -08002212 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002213 }
Jeff Brownd04a88c2011-01-16 14:05:47 -08002214
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002215 /** {@inheritDoc} */
Craig Mautner967212c2013-04-13 21:10:58 -07002216 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002217 public int windowTypeToLayerLw(int type) {
2218 if (type >= FIRST_APPLICATION_WINDOW && type <= LAST_APPLICATION_WINDOW) {
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07002219 return 2;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002220 }
2221 switch (type) {
keunyounga446bf02013-06-21 19:07:57 -07002222 case TYPE_PRIVATE_PRESENTATION:
2223 return 2;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07002224 case TYPE_WALLPAPER:
2225 // wallpaper is at the bottom, though the window manager may move it.
2226 return 2;
Filip Gruszczynskie95b0ae2015-09-30 10:55:33 -07002227 case TYPE_DOCK_DIVIDER:
2228 return 2;
Jason Monk8f7f3182015-11-18 16:35:14 -05002229 case TYPE_QS_DIALOG:
2230 return 2;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07002231 case TYPE_PHONE:
2232 return 3;
2233 case TYPE_SEARCH_BAR:
Jorim Jaggi225d3b52015-04-01 11:18:57 -07002234 case TYPE_VOICE_INTERACTION_STARTING:
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07002235 return 4;
Dianne Hackborne30e02f2014-05-27 18:24:45 -07002236 case TYPE_VOICE_INTERACTION:
2237 // voice interaction layer is almost immediately above apps.
2238 return 5;
Selim Cinekf83e8242015-05-19 18:08:14 -07002239 case TYPE_INPUT_CONSUMER:
Dianne Hackborne30e02f2014-05-27 18:24:45 -07002240 return 6;
Selim Cinekf83e8242015-05-19 18:08:14 -07002241 case TYPE_SYSTEM_DIALOG:
2242 return 7;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07002243 case TYPE_TOAST:
2244 // toasts and the plugged-in battery thing
Selim Cinekf83e8242015-05-19 18:08:14 -07002245 return 8;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07002246 case TYPE_PRIORITY_PHONE:
2247 // SIM errors and unlock. Not sure if this really should be in a high layer.
Selim Cinekf83e8242015-05-19 18:08:14 -07002248 return 9;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07002249 case TYPE_DREAM:
2250 // used for Dreams (screensavers with TYPE_DREAM windows)
Selim Cinekf83e8242015-05-19 18:08:14 -07002251 return 10;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07002252 case TYPE_SYSTEM_ALERT:
2253 // like the ANR / app crashed dialogs
Selim Cinekf83e8242015-05-19 18:08:14 -07002254 return 11;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07002255 case TYPE_INPUT_METHOD:
2256 // on-screen keyboards and other such input method user interfaces go here.
Selim Cinekf83e8242015-05-19 18:08:14 -07002257 return 12;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07002258 case TYPE_INPUT_METHOD_DIALOG:
2259 // on-screen keyboards and other such input method user interfaces go here.
Selim Cinekf83e8242015-05-19 18:08:14 -07002260 return 13;
Jim Miller5ecd8112013-01-09 18:50:26 -08002261 case TYPE_KEYGUARD_SCRIM:
2262 // the safety window that shows behind keyguard while keyguard is starting
Filip Gruszczynskie95b0ae2015-09-30 10:55:33 -07002263 return 14;
Filip Gruszczynski466f3212015-09-21 17:57:57 -07002264 case TYPE_STATUS_BAR_SUB_PANEL:
Filip Gruszczynskie95b0ae2015-09-30 10:55:33 -07002265 return 15;
Filip Gruszczynski466f3212015-09-21 17:57:57 -07002266 case TYPE_STATUS_BAR:
Filip Gruszczynskie95b0ae2015-09-30 10:55:33 -07002267 return 16;
Filip Gruszczynski466f3212015-09-21 17:57:57 -07002268 case TYPE_STATUS_BAR_PANEL:
Filip Gruszczynskie95b0ae2015-09-30 10:55:33 -07002269 return 17;
Filip Gruszczynski466f3212015-09-21 17:57:57 -07002270 case TYPE_KEYGUARD_DIALOG:
Filip Gruszczynskie95b0ae2015-09-30 10:55:33 -07002271 return 18;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07002272 case TYPE_VOLUME_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 19;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07002276 case TYPE_SYSTEM_OVERLAY:
2277 // the on-screen volume indicator and controller shown when the user
2278 // changes the device volume
Filip Gruszczynskie95b0ae2015-09-30 10:55:33 -07002279 return 20;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07002280 case TYPE_NAVIGATION_BAR:
2281 // the navigation bar, if available, shows atop most things
Filip Gruszczynskie95b0ae2015-09-30 10:55:33 -07002282 return 21;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07002283 case TYPE_NAVIGATION_BAR_PANEL:
2284 // some panels (e.g. search) need to show on top of the navigation bar
Filip Gruszczynskie95b0ae2015-09-30 10:55:33 -07002285 return 22;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07002286 case TYPE_SYSTEM_ERROR:
2287 // system-level error dialogs
Filip Gruszczynskie95b0ae2015-09-30 10:55:33 -07002288 return 23;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07002289 case TYPE_MAGNIFICATION_OVERLAY:
2290 // used to highlight the magnified portion of a display
Filip Gruszczynskie95b0ae2015-09-30 10:55:33 -07002291 return 24;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07002292 case TYPE_DISPLAY_OVERLAY:
2293 // used to simulate secondary display devices
Filip Gruszczynskie95b0ae2015-09-30 10:55:33 -07002294 return 25;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07002295 case TYPE_DRAG:
2296 // the drag layer: input for drag-and-drop is associated with this window,
2297 // which sits above all other focusable windows
Filip Gruszczynskie95b0ae2015-09-30 10:55:33 -07002298 return 26;
Svetoslav3a5c7212014-10-14 09:54:26 -07002299 case TYPE_ACCESSIBILITY_OVERLAY:
2300 // overlay put by accessibility services to intercept user interaction
Filip Gruszczynskie95b0ae2015-09-30 10:55:33 -07002301 return 27;
Filip Gruszczynski466f3212015-09-21 17:57:57 -07002302 case TYPE_SECURE_SYSTEM_OVERLAY:
Filip Gruszczynskie95b0ae2015-09-30 10:55:33 -07002303 return 28;
Filip Gruszczynski466f3212015-09-21 17:57:57 -07002304 case TYPE_BOOT_PROGRESS:
Filip Gruszczynskie95b0ae2015-09-30 10:55:33 -07002305 return 29;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07002306 case TYPE_POINTER:
2307 // the (mouse) pointer layer
Filip Gruszczynskie95b0ae2015-09-30 10:55:33 -07002308 return 30;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002309 }
2310 Log.e(TAG, "Unknown window type: " + type);
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07002311 return 2;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002312 }
2313
2314 /** {@inheritDoc} */
Craig Mautner46ac6fa2013-08-01 10:06:34 -07002315 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002316 public int subWindowTypeToLayerLw(int type) {
2317 switch (type) {
2318 case TYPE_APPLICATION_PANEL:
2319 case TYPE_APPLICATION_ATTACHED_DIALOG:
2320 return APPLICATION_PANEL_SUBLAYER;
2321 case TYPE_APPLICATION_MEDIA:
2322 return APPLICATION_MEDIA_SUBLAYER;
Dianne Hackborn5cb8d792009-05-21 17:34:15 -07002323 case TYPE_APPLICATION_MEDIA_OVERLAY:
2324 return APPLICATION_MEDIA_OVERLAY_SUBLAYER;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002325 case TYPE_APPLICATION_SUB_PANEL:
2326 return APPLICATION_SUB_PANEL_SUBLAYER;
Wale Ogunwale0a4dc222015-04-14 12:58:42 -07002327 case TYPE_APPLICATION_ABOVE_SUB_PANEL:
2328 return APPLICATION_ABOVE_SUB_PANEL_SUBLAYER;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002329 }
2330 Log.e(TAG, "Unknown sub-window type: " + type);
2331 return 0;
2332 }
2333
Craig Mautner46ac6fa2013-08-01 10:06:34 -07002334 @Override
Dianne Hackbornabe0da02009-09-18 01:55:39 -07002335 public int getMaxWallpaperLayer() {
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07002336 return windowTypeToLayerLw(TYPE_STATUS_BAR);
Dianne Hackbornabe0da02009-09-18 01:55:39 -07002337 }
2338
Sriram Viswanathan9ebbe6a2015-11-16 17:59:22 -08002339 private int getNavigationBarWidth(int rotation, int uiMode) {
2340 if ((uiMode & UI_MODE_TYPE_MASK) == UI_MODE_TYPE_CAR) {
2341 return mNavigationBarWidthForRotationInCarMode[rotation];
2342 } else {
2343 return mNavigationBarWidthForRotationDefault[rotation];
2344 }
2345 }
2346
Craig Mautner46ac6fa2013-08-01 10:06:34 -07002347 @Override
Sriram Viswanathan9ebbe6a2015-11-16 17:59:22 -08002348 public int getNonDecorDisplayWidth(int fullWidth, int fullHeight, int rotation,
2349 int uiMode) {
Dianne Hackborn077ee852012-04-09 16:27:07 -07002350 if (mHasNavigationBar) {
2351 // For a basic navigation bar, when we are in landscape mode we place
2352 // the navigation bar to the side.
Daniel Sandler4a066c52012-04-20 14:49:13 -04002353 if (mNavigationBarCanMove && fullWidth > fullHeight) {
Sriram Viswanathan9ebbe6a2015-11-16 17:59:22 -08002354 return fullWidth - getNavigationBarWidth(rotation, uiMode);
Dianne Hackborn077ee852012-04-09 16:27:07 -07002355 }
Dianne Hackborn1f903c32011-09-13 19:18:06 -07002356 }
2357 return fullWidth;
Dianne Hackborne2515ee2011-04-27 18:52:56 -04002358 }
2359
Sriram Viswanathan9ebbe6a2015-11-16 17:59:22 -08002360 private int getNavigationBarHeight(int rotation, int uiMode) {
2361 if ((uiMode & UI_MODE_TYPE_MASK) == UI_MODE_TYPE_CAR) {
2362 return mNavigationBarHeightForRotationInCarMode[rotation];
2363 } else {
2364 return mNavigationBarHeightForRotationDefault[rotation];
2365 }
2366 }
2367
Jose Lima9546b202014-07-02 17:21:51 -07002368 @Override
Sriram Viswanathan9ebbe6a2015-11-16 17:59:22 -08002369 public int getNonDecorDisplayHeight(int fullWidth, int fullHeight, int rotation,
2370 int uiMode) {
Dianne Hackborn077ee852012-04-09 16:27:07 -07002371 if (mHasNavigationBar) {
2372 // For a basic navigation bar, when we are in portrait mode we place
2373 // the navigation bar to the bottom.
Daniel Sandler4a066c52012-04-20 14:49:13 -04002374 if (!mNavigationBarCanMove || fullWidth < fullHeight) {
Sriram Viswanathan9ebbe6a2015-11-16 17:59:22 -08002375 return fullHeight - getNavigationBarHeight(rotation, uiMode);
Dianne Hackborn077ee852012-04-09 16:27:07 -07002376 }
2377 }
2378 return fullHeight;
Dianne Hackborn69cb8752011-05-19 18:13:32 -07002379 }
2380
Jose Lima9546b202014-07-02 17:21:51 -07002381 @Override
Sriram Viswanathan9ebbe6a2015-11-16 17:59:22 -08002382 public int getConfigDisplayWidth(int fullWidth, int fullHeight, int rotation, int uiMode) {
2383 return getNonDecorDisplayWidth(fullWidth, fullHeight, rotation, uiMode);
Dianne Hackborn69cb8752011-05-19 18:13:32 -07002384 }
2385
Jose Lima9546b202014-07-02 17:21:51 -07002386 @Override
Sriram Viswanathan9ebbe6a2015-11-16 17:59:22 -08002387 public int getConfigDisplayHeight(int fullWidth, int fullHeight, int rotation, int uiMode) {
John Spurlock80f00c12013-06-13 11:10:51 -04002388 // There is a separate status bar at the top of the display. We don't count that as part
2389 // of the fixed decor, since it can hide; however, for purposes of configurations,
Dianne Hackborn077ee852012-04-09 16:27:07 -07002390 // we do want to exclude it since applications can't generally use that part
2391 // of the screen.
Sriram Viswanathan9ebbe6a2015-11-16 17:59:22 -08002392 return getNonDecorDisplayHeight(
2393 fullWidth, fullHeight, rotation, uiMode) - mStatusBarHeight;
Dianne Hackborne2515ee2011-04-27 18:52:56 -04002394 }
2395
Craig Mautnera3f4bf52012-10-10 20:37:48 -07002396 @Override
Craig Mautnerc9457fa2014-06-06 14:27:48 -07002397 public boolean isForceHiding(WindowManager.LayoutParams attrs) {
2398 return (attrs.privateFlags & PRIVATE_FLAG_KEYGUARD) != 0 ||
Jim Millerab954542014-10-10 18:21:49 -07002399 (isKeyguardHostWindow(attrs) &&
2400 (mKeyguardDelegate != null && mKeyguardDelegate.isShowing())) ||
Adrian Roos69e510d2014-07-13 14:57:59 +02002401 (attrs.type == TYPE_KEYGUARD_SCRIM);
Dianne Hackborn01ad2f42009-09-24 19:24:56 -07002402 }
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07002403
Craig Mautnera3f4bf52012-10-10 20:37:48 -07002404 @Override
Jorim Jaggi0d674622014-05-21 01:34:15 +02002405 public boolean isKeyguardHostWindow(WindowManager.LayoutParams attrs) {
2406 return attrs.type == TYPE_STATUS_BAR;
2407 }
2408
2409 @Override
Dianne Hackborn01ad2f42009-09-24 19:24:56 -07002410 public boolean canBeForceHidden(WindowState win, WindowManager.LayoutParams attrs) {
Craig Mautnera3f4bf52012-10-10 20:37:48 -07002411 switch (attrs.type) {
2412 case TYPE_STATUS_BAR:
2413 case TYPE_NAVIGATION_BAR:
2414 case TYPE_WALLPAPER:
2415 case TYPE_DREAM:
Jim Miller5ecd8112013-01-09 18:50:26 -08002416 case TYPE_KEYGUARD_SCRIM:
Craig Mautnera3f4bf52012-10-10 20:37:48 -07002417 return false;
2418 default:
Adrian Roos461829d2015-06-03 14:41:18 -07002419 // Hide only windows below the keyguard host window.
2420 return windowTypeToLayerLw(win.getBaseType())
2421 < windowTypeToLayerLw(TYPE_STATUS_BAR);
Craig Mautnera3f4bf52012-10-10 20:37:48 -07002422 }
Dianne Hackborn01ad2f42009-09-24 19:24:56 -07002423 }
Craig Mautner8e4df6c2012-05-23 16:57:23 -07002424
Craig Mautner7d7808f2014-09-11 18:02:38 -07002425 @Override
2426 public WindowState getWinShowWhenLockedLw() {
2427 return mWinShowWhenLocked;
2428 }
2429
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002430 /** {@inheritDoc} */
Craig Mautner8e4df6c2012-05-23 16:57:23 -07002431 @Override
Dianne Hackborn2f0b1752011-05-31 17:59:49 -07002432 public View addStartingWindow(IBinder appToken, String packageName, int theme,
2433 CompatibilityInfo compatInfo, CharSequence nonLocalizedLabel, int labelRes,
Adam Powell04fe6eb2013-05-31 14:39:48 -07002434 int icon, int logo, int windowFlags) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002435 if (!SHOW_STARTING_ANIMATIONS) {
2436 return null;
2437 }
2438 if (packageName == null) {
2439 return null;
2440 }
Craig Mautner8e4df6c2012-05-23 16:57:23 -07002441
Mathias Jeppssond1443e92012-08-24 15:25:32 +02002442 WindowManager wm = null;
2443 View view = null;
2444
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002445 try {
Dianne Hackborn867ab6472010-04-29 13:28:56 -07002446 Context context = mContext;
Craig Mautner6fbda632012-07-03 09:26:39 -07002447 if (DEBUG_STARTING_WINDOW) Slog.d(TAG, "addStartingWindow " + packageName
2448 + ": nonLocalizedLabel=" + nonLocalizedLabel + " theme="
2449 + Integer.toHexString(theme));
Dianne Hackborn247fe742011-01-08 17:25:57 -08002450 if (theme != context.getThemeResId() || labelRes != 0) {
Dianne Hackborn867ab6472010-04-29 13:28:56 -07002451 try {
2452 context = context.createPackageContext(packageName, 0);
Dianne Hackborn247fe742011-01-08 17:25:57 -08002453 context.setTheme(theme);
Dianne Hackborn867ab6472010-04-29 13:28:56 -07002454 } catch (PackageManager.NameNotFoundException e) {
2455 // Ignore
2456 }
2457 }
Craig Mautner8e4df6c2012-05-23 16:57:23 -07002458
Jorim Jaggia16cc152015-06-01 16:55:05 -07002459 PhoneWindow win = new PhoneWindow(context);
2460 win.setIsStartingWindow(true);
Craig Mautner8e4df6c2012-05-23 16:57:23 -07002461
Dianne Hackborn867ab6472010-04-29 13:28:56 -07002462 Resources r = context.getResources();
2463 win.setTitle(r.getText(labelRes, nonLocalizedLabel));
Craig Mautner8e4df6c2012-05-23 16:57:23 -07002464
Dianne Hackborn867ab6472010-04-29 13:28:56 -07002465 win.setType(
2466 WindowManager.LayoutParams.TYPE_APPLICATION_STARTING);
Adrian Roos602c68e2015-04-24 16:03:47 -07002467
2468 synchronized (mWindowManagerFuncs.getWindowManagerLock()) {
2469 // Assumes it's safe to show starting windows of launched apps while
2470 // the keyguard is being hidden. This is okay because starting windows never show
2471 // secret information.
2472 if (mKeyguardHidden) {
2473 windowFlags |= FLAG_SHOW_WHEN_LOCKED;
2474 }
2475 }
2476
Dianne Hackborn867ab6472010-04-29 13:28:56 -07002477 // Force the window flags: this is a fake window, so it is not really
2478 // touchable or focusable by the user. We also add in the ALT_FOCUSABLE_IM
2479 // flag because we do know that the next window will take input
2480 // focus, so we want to get the IME window up on top of us right away.
2481 win.setFlags(
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,
Dianne Hackborn7eec10e2010-11-12 18:03:47 -08002486 windowFlags|
Dianne Hackborn867ab6472010-04-29 13:28:56 -07002487 WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE|
2488 WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE|
2489 WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM);
Craig Mautner8e4df6c2012-05-23 16:57:23 -07002490
Adam Powell04fe6eb2013-05-31 14:39:48 -07002491 win.setDefaultIcon(icon);
2492 win.setDefaultLogo(logo);
2493
Dianne Hackborn867ab6472010-04-29 13:28:56 -07002494 win.setLayout(WindowManager.LayoutParams.MATCH_PARENT,
Dianne Hackborn2f0b1752011-05-31 17:59:49 -07002495 WindowManager.LayoutParams.MATCH_PARENT);
Craig Mautner8e4df6c2012-05-23 16:57:23 -07002496
Dianne Hackborn867ab6472010-04-29 13:28:56 -07002497 final WindowManager.LayoutParams params = win.getAttributes();
2498 params.token = appToken;
2499 params.packageName = packageName;
2500 params.windowAnimations = win.getWindowStyle().getResourceId(
2501 com.android.internal.R.styleable.Window_windowAnimationStyle, 0);
John Reck61375a82014-09-18 19:27:48 +00002502 params.privateFlags |=
2503 WindowManager.LayoutParams.PRIVATE_FLAG_FAKE_HARDWARE_ACCELERATED;
Craig Mautner88400d32012-09-30 12:35:45 -07002504 params.privateFlags |= WindowManager.LayoutParams.PRIVATE_FLAG_SHOW_FOR_ALL_USERS;
Adam Lesinski95c42972013-10-02 10:13:27 -07002505
2506 if (!compatInfo.supportsScreen()) {
2507 params.privateFlags |= WindowManager.LayoutParams.PRIVATE_FLAG_COMPATIBLE_WINDOW;
2508 }
2509
Dianne Hackborn867ab6472010-04-29 13:28:56 -07002510 params.setTitle("Starting " + packageName);
2511
Mathias Jeppssond1443e92012-08-24 15:25:32 +02002512 wm = (WindowManager)context.getSystemService(Context.WINDOW_SERVICE);
2513 view = win.getDecorView();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002514
Craig Mautner6fbda632012-07-03 09:26:39 -07002515 if (DEBUG_STARTING_WINDOW) Slog.d(
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002516 TAG, "Adding starting window for " + packageName
2517 + " / " + appToken + ": "
2518 + (view.getParent() != null ? view : null));
2519
2520 wm.addView(view, params);
2521
2522 // Only return the view if it was successfully added to the
2523 // window manager... which we can tell by it having a parent.
2524 return view.getParent() != null ? view : null;
Jeff Brown98365d72012-08-19 20:30:52 -07002525 } catch (WindowManager.BadTokenException e) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002526 // ignore
Craig Mautner42bf39e2014-02-21 16:46:22 -08002527 Log.w(TAG, appToken + " already running, starting window not displayed. " +
2528 e.getMessage());
Dianne Hackborn867ab6472010-04-29 13:28:56 -07002529 } catch (RuntimeException e) {
2530 // don't crash if something else bad happens, for example a
2531 // failure loading resources because we are loading from an app
2532 // on external storage that has been unmounted.
2533 Log.w(TAG, appToken + " failed creating starting window", e);
Mathias Jeppssond1443e92012-08-24 15:25:32 +02002534 } finally {
2535 if (view != null && view.getParent() == null) {
2536 Log.w(TAG, "view not successfully added to wm, removing view");
2537 wm.removeViewImmediate(view);
2538 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002539 }
2540
2541 return null;
2542 }
2543
2544 /** {@inheritDoc} */
Jose Lima9546b202014-07-02 17:21:51 -07002545 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002546 public void removeStartingWindow(IBinder appToken, View window) {
Craig Mautner276a6eb2014-11-04 15:32:57 -08002547 if (DEBUG_STARTING_WINDOW) Slog.v(TAG, "Removing starting window for " + appToken + ": "
2548 + window + " Callers=" + Debug.getCallers(4));
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002549
2550 if (window != null) {
Dianne Hackborn5fd21692011-06-07 14:09:47 -07002551 WindowManager wm = (WindowManager)mContext.getSystemService(Context.WINDOW_SERVICE);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002552 wm.removeView(window);
2553 }
2554 }
2555
2556 /**
2557 * Preflight adding a window to the system.
RoboErik8a2cfc32014-05-16 11:19:38 -07002558 *
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002559 * Currently enforces that three window types are singletons:
2560 * <ul>
2561 * <li>STATUS_BAR_TYPE</li>
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002562 * <li>KEYGUARD_TYPE</li>
2563 * </ul>
RoboErik8a2cfc32014-05-16 11:19:38 -07002564 *
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002565 * @param win The window to be added
2566 * @param attrs Information about the window to be added
RoboErik8a2cfc32014-05-16 11:19:38 -07002567 *
Jeff Brown98365d72012-08-19 20:30:52 -07002568 * @return If ok, WindowManagerImpl.ADD_OKAY. If too many singletons,
2569 * WindowManagerImpl.ADD_MULTIPLE_SINGLETON
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002570 */
Jose Lima9546b202014-07-02 17:21:51 -07002571 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002572 public int prepareAddWindowLw(WindowState win, WindowManager.LayoutParams attrs) {
2573 switch (attrs.type) {
2574 case TYPE_STATUS_BAR:
Joe Onorato8bc6c512010-06-04 16:21:12 -04002575 mContext.enforceCallingOrSelfPermission(
2576 android.Manifest.permission.STATUS_BAR_SERVICE,
2577 "PhoneWindowManager");
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002578 if (mStatusBar != null) {
Dianne Hackbornf87d1962012-04-04 12:48:24 -07002579 if (mStatusBar.isAlive()) {
Jeff Brown98365d72012-08-19 20:30:52 -07002580 return WindowManagerGlobal.ADD_MULTIPLE_SINGLETON;
Dianne Hackbornf87d1962012-04-04 12:48:24 -07002581 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002582 }
2583 mStatusBar = win;
John Spurlock27735a42013-08-14 17:57:38 -04002584 mStatusBarController.setWindow(win);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002585 break;
Daniel Sandler8956dbb2011-04-22 07:55:02 -04002586 case TYPE_NAVIGATION_BAR:
2587 mContext.enforceCallingOrSelfPermission(
2588 android.Manifest.permission.STATUS_BAR_SERVICE,
2589 "PhoneWindowManager");
Dianne Hackbornf87d1962012-04-04 12:48:24 -07002590 if (mNavigationBar != null) {
2591 if (mNavigationBar.isAlive()) {
Jeff Brown98365d72012-08-19 20:30:52 -07002592 return WindowManagerGlobal.ADD_MULTIPLE_SINGLETON;
Dianne Hackbornf87d1962012-04-04 12:48:24 -07002593 }
2594 }
Daniel Sandler8956dbb2011-04-22 07:55:02 -04002595 mNavigationBar = win;
John Spurlock27735a42013-08-14 17:57:38 -04002596 mNavigationBarController.setWindow(win);
Craig Mautnereda67292013-04-28 13:50:14 -07002597 if (DEBUG_LAYOUT) Slog.i(TAG, "NAVIGATION BAR: " + mNavigationBar);
Daniel Sandler8956dbb2011-04-22 07:55:02 -04002598 break;
Jim Millere898ac52012-04-06 17:10:57 -07002599 case TYPE_NAVIGATION_BAR_PANEL:
Dianne Hackborn08743722009-12-21 12:16:51 -08002600 case TYPE_STATUS_BAR_PANEL:
Joe Onorato29fc2c92010-11-24 10:26:50 -08002601 case TYPE_STATUS_BAR_SUB_PANEL:
Jorim Jaggi225d3b52015-04-01 11:18:57 -07002602 case TYPE_VOICE_INTERACTION_STARTING:
Joe Onorato29fc2c92010-11-24 10:26:50 -08002603 mContext.enforceCallingOrSelfPermission(
2604 android.Manifest.permission.STATUS_BAR_SERVICE,
2605 "PhoneWindowManager");
Joe Onorato29fc2c92010-11-24 10:26:50 -08002606 break;
Jim Miller5ecd8112013-01-09 18:50:26 -08002607 case TYPE_KEYGUARD_SCRIM:
Jim Miller25190572013-02-28 17:36:24 -08002608 if (mKeyguardScrim != null) {
2609 return WindowManagerGlobal.ADD_MULTIPLE_SINGLETON;
2610 }
Jim Miller5ecd8112013-01-09 18:50:26 -08002611 mKeyguardScrim = win;
2612 break;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002613 }
Jeff Brown98365d72012-08-19 20:30:52 -07002614 return WindowManagerGlobal.ADD_OKAY;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002615 }
2616
2617 /** {@inheritDoc} */
Jose Lima9546b202014-07-02 17:21:51 -07002618 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002619 public void removeWindowLw(WindowState win) {
2620 if (mStatusBar == win) {
2621 mStatusBar = null;
John Spurlock27735a42013-08-14 17:57:38 -04002622 mStatusBarController.setWindow(null);
Jim Millerc0b676d2013-03-22 16:11:08 -07002623 mKeyguardDelegate.showScrim();
Jim Miller5ecd8112013-01-09 18:50:26 -08002624 } else if (mKeyguardScrim == win) {
2625 Log.v(TAG, "Removing keyguard scrim");
2626 mKeyguardScrim = null;
2627 } if (mNavigationBar == win) {
Daniel Sandler8956dbb2011-04-22 07:55:02 -04002628 mNavigationBar = null;
John Spurlock27735a42013-08-14 17:57:38 -04002629 mNavigationBarController.setWindow(null);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002630 }
2631 }
2632
2633 static final boolean PRINT_ANIM = false;
RoboErik8a2cfc32014-05-16 11:19:38 -07002634
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002635 /** {@inheritDoc} */
Craig Mautner4b71aa12012-12-27 17:20:01 -08002636 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002637 public int selectAnimationLw(WindowState win, int transit) {
2638 if (PRINT_ANIM) Log.i(TAG, "selectAnimation in " + win
2639 + ": transit=" + transit);
Dianne Hackbornf87d1962012-04-04 12:48:24 -07002640 if (win == mStatusBar) {
Jorim Jaggi380ecb82014-03-14 17:25:20 +01002641 boolean isKeyguard = (win.getAttrs().privateFlags & PRIVATE_FLAG_KEYGUARD) != 0;
Craig Mautner4b71aa12012-12-27 17:20:01 -08002642 if (transit == TRANSIT_EXIT
2643 || transit == TRANSIT_HIDE) {
Jorim Jaggi380ecb82014-03-14 17:25:20 +01002644 return isKeyguard ? -1 : R.anim.dock_top_exit;
Craig Mautner4b71aa12012-12-27 17:20:01 -08002645 } else if (transit == TRANSIT_ENTER
2646 || transit == TRANSIT_SHOW) {
Jorim Jaggi380ecb82014-03-14 17:25:20 +01002647 return isKeyguard ? -1 : R.anim.dock_top_enter;
Dianne Hackbornf87d1962012-04-04 12:48:24 -07002648 }
2649 } else if (win == mNavigationBar) {
Jorim Jaggi0d210f62015-07-10 14:24:44 -07002650 if (win.getAttrs().windowAnimations != 0) {
2651 return 0;
2652 }
Dianne Hackbornf87d1962012-04-04 12:48:24 -07002653 // This can be on either the bottom or the right.
2654 if (mNavigationBarOnBottom) {
Craig Mautner4b71aa12012-12-27 17:20:01 -08002655 if (transit == TRANSIT_EXIT
2656 || transit == TRANSIT_HIDE) {
Dianne Hackbornf87d1962012-04-04 12:48:24 -07002657 return R.anim.dock_bottom_exit;
Craig Mautner4b71aa12012-12-27 17:20:01 -08002658 } else if (transit == TRANSIT_ENTER
2659 || transit == TRANSIT_SHOW) {
Dianne Hackbornf87d1962012-04-04 12:48:24 -07002660 return R.anim.dock_bottom_enter;
2661 }
2662 } else {
Craig Mautner4b71aa12012-12-27 17:20:01 -08002663 if (transit == TRANSIT_EXIT
2664 || transit == TRANSIT_HIDE) {
Dianne Hackbornf87d1962012-04-04 12:48:24 -07002665 return R.anim.dock_right_exit;
Craig Mautner4b71aa12012-12-27 17:20:01 -08002666 } else if (transit == TRANSIT_ENTER
2667 || transit == TRANSIT_SHOW) {
Dianne Hackbornf87d1962012-04-04 12:48:24 -07002668 return R.anim.dock_right_enter;
2669 }
2670 }
Filip Gruszczynski57f76f12015-11-04 16:10:54 -08002671 } else if (win.getAttrs().type == TYPE_DOCK_DIVIDER) {
Jorim Jaggi81ba11e2016-02-03 22:04:22 -08002672 return selectDockedDividerAnimationLw(win, transit);
Craig Mautner4b71aa12012-12-27 17:20:01 -08002673 }
2674
2675 if (transit == TRANSIT_PREVIEW_DONE) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002676 if (win.hasAppShownWindows()) {
2677 if (PRINT_ANIM) Log.i(TAG, "**** STARTING EXIT");
2678 return com.android.internal.R.anim.app_starting_exit;
2679 }
Dianne Hackborn7ad44382012-10-18 17:46:00 -07002680 } else if (win.getAttrs().type == TYPE_DREAM && mDreamingLockscreen
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07002681 && transit == TRANSIT_ENTER) {
2682 // Special case: we are animating in a dream, while the keyguard
2683 // is shown. We don't want an animation on the dream, because
2684 // we need it shown immediately with the keyguard animating away
2685 // to reveal it.
2686 return -1;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002687 }
2688
2689 return 0;
2690 }
2691
Jorim Jaggi81ba11e2016-02-03 22:04:22 -08002692 private int selectDockedDividerAnimationLw(WindowState win, int transit) {
2693 int insets = mWindowManagerFuncs.getDockedDividerInsetsLw();
2694
2695 // If the divider is behind the navigation bar, don't animate.
2696 if (mNavigationBar != null
2697 && (win.getFrameLw().top + insets >= mNavigationBar.getFrameLw().top
2698 || win.getFrameLw().left + insets >= mNavigationBar.getFrameLw().left)) {
2699 return 0;
2700 }
2701 if (transit == TRANSIT_ENTER || transit == TRANSIT_SHOW) {
2702 return R.anim.fade_in;
2703 } else if (transit == TRANSIT_EXIT) {
2704 return R.anim.fade_out;
2705 } else {
2706 return 0;
2707 }
2708 }
2709
Craig Mautner3c174372013-02-21 17:54:37 -08002710 @Override
2711 public void selectRotationAnimationLw(int anim[]) {
2712 if (PRINT_ANIM) Slog.i(TAG, "selectRotationAnimation mTopFullscreen="
2713 + mTopFullscreenOpaqueWindowState + " rotationAnimation="
2714 + (mTopFullscreenOpaqueWindowState == null ?
2715 "0" : mTopFullscreenOpaqueWindowState.getAttrs().rotationAnimation));
2716 if (mTopFullscreenOpaqueWindowState != null && mTopIsFullscreen) {
2717 switch (mTopFullscreenOpaqueWindowState.getAttrs().rotationAnimation) {
2718 case ROTATION_ANIMATION_CROSSFADE:
2719 anim[0] = R.anim.rotation_animation_xfade_exit;
2720 anim[1] = R.anim.rotation_animation_enter;
2721 break;
2722 case ROTATION_ANIMATION_JUMPCUT:
2723 anim[0] = R.anim.rotation_animation_jump_exit;
2724 anim[1] = R.anim.rotation_animation_enter;
2725 break;
2726 case ROTATION_ANIMATION_ROTATE:
2727 default:
2728 anim[0] = anim[1] = 0;
2729 break;
2730 }
2731 } else {
2732 anim[0] = anim[1] = 0;
2733 }
2734 }
2735
2736 @Override
2737 public boolean validateRotationAnimationLw(int exitAnimId, int enterAnimId,
2738 boolean forceDefault) {
2739 switch (exitAnimId) {
2740 case R.anim.rotation_animation_xfade_exit:
2741 case R.anim.rotation_animation_jump_exit:
2742 // These are the only cases that matter.
2743 if (forceDefault) {
2744 return false;
2745 }
2746 int anim[] = new int[2];
2747 selectRotationAnimationLw(anim);
2748 return (exitAnimId == anim[0] && enterAnimId == anim[1]);
2749 default:
2750 return true;
2751 }
2752 }
2753
2754 @Override
Jorim Jaggi84a3e7a2014-08-13 17:58:58 +02002755 public Animation createForceHideEnterAnimation(boolean onWallpaper,
2756 boolean goingToNotificationShade) {
2757 if (goingToNotificationShade) {
2758 return AnimationUtils.loadAnimation(mContext, R.anim.lock_screen_behind_enter_fade_in);
Craig Mautnerb8340802014-11-04 15:32:57 -08002759 }
Craig Mautner276a6eb2014-11-04 15:32:57 -08002760
2761 AnimationSet set = (AnimationSet) AnimationUtils.loadAnimation(mContext, onWallpaper ?
2762 R.anim.lock_screen_behind_enter_wallpaper :
2763 R.anim.lock_screen_behind_enter);
2764
2765 // TODO: Use XML interpolators when we have log interpolators available in XML.
2766 final List<Animation> animations = set.getAnimations();
2767 for (int i = animations.size() - 1; i >= 0; --i) {
2768 animations.get(i).setInterpolator(mLogDecelerateInterpolator);
2769 }
2770
2771 return set;
Jorim Jaggi76a16232014-08-08 17:00:47 +02002772 }
2773
2774
2775 @Override
Jorim Jaggi84a3e7a2014-08-13 17:58:58 +02002776 public Animation createForceHideWallpaperExitAnimation(boolean goingToNotificationShade) {
2777 if (goingToNotificationShade) {
2778 return null;
2779 } else {
2780 return AnimationUtils.loadAnimation(mContext, R.anim.lock_screen_wallpaper_exit);
2781 }
Dianne Hackborn01ad2f42009-09-24 19:24:56 -07002782 }
John Spurlockc8b46ca2013-04-08 12:59:26 -04002783
2784 private static void awakenDreams() {
2785 IDreamManager dreamManager = getDreamManager();
2786 if (dreamManager != null) {
2787 try {
2788 dreamManager.awaken();
2789 } catch (RemoteException e) {
2790 // fine, stay asleep then
2791 }
2792 }
2793 }
2794
2795 static IDreamManager getDreamManager() {
2796 return IDreamManager.Stub.asInterface(
2797 ServiceManager.checkService(DreamService.DREAM_SERVICE));
2798 }
2799
Tyler Gunnef9f6f92014-09-12 22:16:17 -07002800 TelecomManager getTelecommService() {
2801 return (TelecomManager) mContext.getSystemService(Context.TELECOM_SERVICE);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002802 }
2803
Jeff Brown4d396052010-10-29 21:50:21 -07002804 static IAudioService getAudioService() {
2805 IAudioService audioService = IAudioService.Stub.asInterface(
2806 ServiceManager.checkService(Context.AUDIO_SERVICE));
2807 if (audioService == null) {
2808 Log.w(TAG, "Unable to find IAudioService interface.");
2809 }
2810 return audioService;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002811 }
2812
2813 boolean keyguardOn() {
Jim Millerab954542014-10-10 18:21:49 -07002814 return isKeyguardShowingAndNotOccluded() || inKeyguardRestrictedKeyInputMode();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002815 }
2816
2817 private static final int[] WINDOW_TYPES_WHERE_HOME_DOESNT_WORK = {
2818 WindowManager.LayoutParams.TYPE_SYSTEM_ALERT,
2819 WindowManager.LayoutParams.TYPE_SYSTEM_ERROR,
2820 };
2821
2822 /** {@inheritDoc} */
Jeff Brown00fa7bd2010-07-02 15:37:36 -07002823 @Override
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002824 public long interceptKeyBeforeDispatching(WindowState win, KeyEvent event, int policyFlags) {
Jeff Brown00fa7bd2010-07-02 15:37:36 -07002825 final boolean keyguardOn = keyguardOn();
Jeff Brown1f245102010-11-18 20:53:46 -08002826 final int keyCode = event.getKeyCode();
2827 final int repeatCount = event.getRepeatCount();
2828 final int metaState = event.getMetaState();
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002829 final int flags = event.getFlags();
Jeff Brown1f245102010-11-18 20:53:46 -08002830 final boolean down = event.getAction() == KeyEvent.ACTION_DOWN;
2831 final boolean canceled = event.isCanceled();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002832
Jeff Brown40013652012-05-16 21:22:36 -07002833 if (DEBUG_INPUT) {
Jeff Brown00fa7bd2010-07-02 15:37:36 -07002834 Log.d(TAG, "interceptKeyTi keyCode=" + keyCode + " down=" + down + " repeatCount="
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002835 + repeatCount + " keyguardOn=" + keyguardOn + " mHomePressed=" + mHomePressed
2836 + " canceled=" + canceled);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002837 }
2838
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002839 // If we think we might have a volume down & power key chord on the way
2840 // but we're not sure, then tell the dispatcher to wait a little while and
2841 // try again later before dispatching.
Christopher Tatee90585f2012-03-05 18:56:25 -08002842 if (mScreenshotChordEnabled && (flags & KeyEvent.FLAG_FALLBACK) == 0) {
Jeff Brown13f00f02014-10-31 14:45:50 -07002843 if (mScreenshotChordVolumeDownKeyTriggered && !mScreenshotChordPowerKeyTriggered) {
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002844 final long now = SystemClock.uptimeMillis();
Jeff Brown13f00f02014-10-31 14:45:50 -07002845 final long timeoutTime = mScreenshotChordVolumeDownKeyTime
2846 + SCREENSHOT_CHORD_DEBOUNCE_DELAY_MILLIS;
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002847 if (now < timeoutTime) {
2848 return timeoutTime - now;
2849 }
2850 }
2851 if (keyCode == KeyEvent.KEYCODE_VOLUME_DOWN
Jeff Brown13f00f02014-10-31 14:45:50 -07002852 && mScreenshotChordVolumeDownKeyConsumed) {
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002853 if (!down) {
Jeff Brown13f00f02014-10-31 14:45:50 -07002854 mScreenshotChordVolumeDownKeyConsumed = false;
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002855 }
2856 return -1;
2857 }
2858 }
2859
Michael Wright6a62e552014-06-03 19:19:48 -07002860 // Cancel any pending meta actions if we see any other keys being pressed between the down
2861 // of the meta key and its corresponding up.
Michael Wright251e35d2014-08-22 15:40:27 -07002862 if (mPendingMetaAction && !KeyEvent.isMetaKey(keyCode)) {
Michael Wright6a62e552014-06-03 19:19:48 -07002863 mPendingMetaAction = false;
2864 }
2865
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002866 // First we always handle the home key here, so applications
2867 // can never break it, although if keyguard is on, we do let
2868 // it handle it, because that gives us the correct 5 second
2869 // timeout.
Jeff Brown00fa7bd2010-07-02 15:37:36 -07002870 if (keyCode == KeyEvent.KEYCODE_HOME) {
Michael Jurka7f2668c2012-03-27 07:49:52 -07002871
Jeff Brown49ed71d2010-12-06 17:13:33 -08002872 // If we have released the home key, and didn't do anything else
2873 // while it was pressed, then it is time to go home!
Michael Jurka7f2668c2012-03-27 07:49:52 -07002874 if (!down) {
Jeff Browncaca8812013-05-09 13:34:33 -07002875 cancelPreloadRecentApps();
2876
Jeff Brown49ed71d2010-12-06 17:13:33 -08002877 mHomePressed = false;
Jeff Browncaca8812013-05-09 13:34:33 -07002878 if (mHomeConsumed) {
2879 mHomeConsumed = false;
Michael Jurka7f2668c2012-03-27 07:49:52 -07002880 return -1;
Jeff Brown49ed71d2010-12-06 17:13:33 -08002881 }
Jeff Browncaca8812013-05-09 13:34:33 -07002882
2883 if (canceled) {
2884 Log.i(TAG, "Ignoring HOME; event canceled.");
2885 return -1;
2886 }
2887
Yorke Lee4f803242014-12-15 23:22:06 +00002888 // If an incoming call is ringing, HOME is totally disabled.
2889 // (The user is already on the InCallUI at this point,
2890 // and his ONLY options are to answer or reject the call.)
2891 TelecomManager telecomManager = getTelecommService();
2892 if (telecomManager != null && telecomManager.isRinging()) {
2893 Log.i(TAG, "Ignoring HOME; there's a ringing incoming call.");
2894 return -1;
2895 }
2896
Jeff Browncaca8812013-05-09 13:34:33 -07002897 // Delay handling home if a double-tap is possible.
2898 if (mDoubleTapOnHomeBehavior != DOUBLE_TAP_HOME_NOTHING) {
2899 mHandler.removeCallbacks(mHomeDoubleTapTimeoutRunnable); // just in case
2900 mHomeDoubleTapPending = true;
2901 mHandler.postDelayed(mHomeDoubleTapTimeoutRunnable,
2902 ViewConfiguration.getDoubleTapTimeout());
2903 return -1;
2904 }
2905
Jeff Brown13f00f02014-10-31 14:45:50 -07002906 handleShortPressOnHome();
Jeff Browncaca8812013-05-09 13:34:33 -07002907 return -1;
Jeff Brown49ed71d2010-12-06 17:13:33 -08002908 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002909
2910 // If a system window has focus, then it doesn't make sense
2911 // right now to interact with applications.
2912 WindowManager.LayoutParams attrs = win != null ? win.getAttrs() : null;
2913 if (attrs != null) {
2914 final int type = attrs.type;
Jorim Jaggi380ecb82014-03-14 17:25:20 +01002915 if (type == WindowManager.LayoutParams.TYPE_KEYGUARD_SCRIM
2916 || type == WindowManager.LayoutParams.TYPE_KEYGUARD_DIALOG
2917 || (attrs.privateFlags & PRIVATE_FLAG_KEYGUARD) != 0) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002918 // the "app" is keyguard, so give it the key
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002919 return 0;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002920 }
2921 final int typeCount = WINDOW_TYPES_WHERE_HOME_DOESNT_WORK.length;
2922 for (int i=0; i<typeCount; i++) {
2923 if (type == WINDOW_TYPES_WHERE_HOME_DOESNT_WORK[i]) {
2924 // don't do anything, but also don't pass it to the app
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002925 return -1;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002926 }
2927 }
2928 }
Jeff Browncaca8812013-05-09 13:34:33 -07002929
2930 // Remember that home is pressed and handle special actions.
2931 if (repeatCount == 0) {
2932 mHomePressed = true;
2933 if (mHomeDoubleTapPending) {
2934 mHomeDoubleTapPending = false;
2935 mHandler.removeCallbacks(mHomeDoubleTapTimeoutRunnable);
2936 handleDoubleTapOnHome();
2937 } else if (mLongPressOnHomeBehavior == LONG_PRESS_HOME_RECENT_SYSTEM_UI
2938 || mDoubleTapOnHomeBehavior == DOUBLE_TAP_HOME_RECENT_SYSTEM_UI) {
2939 preloadRecentApps();
Michael Jurka7f2668c2012-03-27 07:49:52 -07002940 }
Jeff Browncaca8812013-05-09 13:34:33 -07002941 } else if ((event.getFlags() & KeyEvent.FLAG_LONG_PRESS) != 0) {
2942 if (!keyguardOn) {
Jaewan Kim76b7d0d2016-02-12 19:01:02 +09002943 handleLongPressOnHome(event.getDeviceId());
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002944 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002945 }
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002946 return -1;
Jeff Brown00fa7bd2010-07-02 15:37:36 -07002947 } else if (keyCode == KeyEvent.KEYCODE_MENU) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002948 // Hijack modified menu keys for debugging features
2949 final int chordBug = KeyEvent.META_SHIFT_ON;
2950
2951 if (down && repeatCount == 0) {
Jeff Brown00fa7bd2010-07-02 15:37:36 -07002952 if (mEnableShiftMenuBugReports && (metaState & chordBug) == chordBug) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002953 Intent intent = new Intent(Intent.ACTION_BUG_REPORT);
Dianne Hackborn5ac72a22012-08-29 18:32:08 -07002954 mContext.sendOrderedBroadcastAsUser(intent, UserHandle.CURRENT,
2955 null, null, null, 0, null, null);
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002956 return -1;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002957 } else if (SHOW_PROCESSES_ON_ALT_MENU &&
Jeff Brown00fa7bd2010-07-02 15:37:36 -07002958 (metaState & KeyEvent.META_ALT_ON) == KeyEvent.META_ALT_ON) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002959 Intent service = new Intent();
2960 service.setClassName(mContext, "com.android.server.LoadAverageService");
2961 ContentResolver res = mContext.getContentResolver();
Jeff Sharkey8d9a1f62012-10-18 15:38:14 -07002962 boolean shown = Settings.Global.getInt(
2963 res, Settings.Global.SHOW_PROCESSES, 0) != 0;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002964 if (!shown) {
2965 mContext.startService(service);
2966 } else {
2967 mContext.stopService(service);
2968 }
Jeff Sharkey8d9a1f62012-10-18 15:38:14 -07002969 Settings.Global.putInt(
2970 res, Settings.Global.SHOW_PROCESSES, shown ? 0 : 1);
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002971 return -1;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002972 }
2973 }
Jeff Brown00fa7bd2010-07-02 15:37:36 -07002974 } else if (keyCode == KeyEvent.KEYCODE_SEARCH) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002975 if (down) {
2976 if (repeatCount == 0) {
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002977 mSearchKeyShortcutPending = true;
2978 mConsumeSearchKeyUp = false;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002979 }
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002980 } else {
2981 mSearchKeyShortcutPending = false;
2982 if (mConsumeSearchKeyUp) {
2983 mConsumeSearchKeyUp = false;
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002984 return -1;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002985 }
2986 }
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002987 return 0;
Jeff Brown49ed71d2010-12-06 17:13:33 -08002988 } else if (keyCode == KeyEvent.KEYCODE_APP_SWITCH) {
Michael Wrightc9ebea72013-01-16 19:25:02 -08002989 if (!keyguardOn) {
Jeff Browncaca8812013-05-09 13:34:33 -07002990 if (down && repeatCount == 0) {
2991 preloadRecentApps();
2992 } else if (!down) {
2993 toggleRecentApps();
Michael Wrightc9ebea72013-01-16 19:25:02 -08002994 }
Jeff Brown49ed71d2010-12-06 17:13:33 -08002995 }
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002996 return -1;
Jun Mukaid21b3c82015-04-23 14:09:34 -07002997 } else if (keyCode == KeyEvent.KEYCODE_N && event.isMetaPressed()) {
2998 if (down) {
2999 IStatusBarService service = getStatusBarService();
3000 if (service != null) {
3001 try {
3002 service.expandNotificationsPanel();
3003 } catch (RemoteException e) {
3004 // do nothing.
3005 }
3006 }
3007 }
Clara Bayarrif2debb12015-07-10 14:47:17 +01003008 } else if (keyCode == KeyEvent.KEYCODE_SLASH && event.isMetaPressed()) {
3009 if (down) {
3010 if (repeatCount == 0) {
Andrei Stingaceanuc22ab792016-01-07 12:39:38 +00003011 toggleKeyboardShortcutsMenu();
Clara Bayarrif2debb12015-07-10 14:47:17 +01003012 }
3013 }
Jeff Brownde7a8ea2012-06-13 18:28:57 -07003014 } else if (keyCode == KeyEvent.KEYCODE_ASSIST) {
3015 if (down) {
3016 if (repeatCount == 0) {
3017 mAssistKeyLongPressed = false;
3018 } else if (repeatCount == 1) {
3019 mAssistKeyLongPressed = true;
3020 if (!keyguardOn) {
3021 launchAssistLongPressAction();
3022 }
3023 }
3024 } else {
3025 if (mAssistKeyLongPressed) {
3026 mAssistKeyLongPressed = false;
3027 } else {
3028 if (!keyguardOn) {
Tim Kilbourn0e5f1102015-06-05 16:18:09 -07003029 launchAssistAction(null, event.getDeviceId());
Jeff Brownde7a8ea2012-06-13 18:28:57 -07003030 }
3031 }
3032 }
3033 return -1;
Michael Wrightdc63f7b2014-08-21 19:05:21 -07003034 } else if (keyCode == KeyEvent.KEYCODE_VOICE_ASSIST) {
3035 if (!down) {
3036 Intent voiceIntent;
Michael Wright869a67c2014-08-26 19:33:06 -07003037 if (!keyguardOn) {
Michael Wrightdc63f7b2014-08-21 19:05:21 -07003038 voiceIntent = new Intent(RecognizerIntent.ACTION_WEB_SEARCH);
3039 } else {
Dianne Hackbornb6683c42015-06-18 17:40:33 -07003040 IDeviceIdleController dic = IDeviceIdleController.Stub.asInterface(
3041 ServiceManager.getService(Context.DEVICE_IDLE_CONTROLLER));
3042 if (dic != null) {
3043 try {
3044 dic.exitIdle("voice-search");
3045 } catch (RemoteException e) {
3046 }
3047 }
Michael Wrightdc63f7b2014-08-21 19:05:21 -07003048 voiceIntent = new Intent(RecognizerIntent.ACTION_VOICE_SEARCH_HANDS_FREE);
Michael Wright869a67c2014-08-26 19:33:06 -07003049 voiceIntent.putExtra(RecognizerIntent.EXTRA_SECURE, true);
Michael Wrightdc63f7b2014-08-21 19:05:21 -07003050 }
Bart Sears8b1c27c2015-03-18 23:51:02 +00003051 startActivityAsUser(voiceIntent, UserHandle.CURRENT_OR_SELF);
Michael Wrightdc63f7b2014-08-21 19:05:21 -07003052 }
Jeff Sharkey2991fa32012-12-05 18:06:43 -08003053 } else if (keyCode == KeyEvent.KEYCODE_SYSRQ) {
3054 if (down && repeatCount == 0) {
3055 mHandler.post(mScreenshotRunnable);
3056 }
3057 return -1;
Michael Wrightb854e242013-02-05 17:54:02 -08003058 } else if (keyCode == KeyEvent.KEYCODE_BRIGHTNESS_UP
3059 || keyCode == KeyEvent.KEYCODE_BRIGHTNESS_DOWN) {
3060 if (down) {
3061 int direction = keyCode == KeyEvent.KEYCODE_BRIGHTNESS_UP ? 1 : -1;
3062
3063 // Disable autobrightness if it's on
3064 int auto = Settings.System.getIntForUser(
3065 mContext.getContentResolver(),
3066 Settings.System.SCREEN_BRIGHTNESS_MODE,
3067 Settings.System.SCREEN_BRIGHTNESS_MODE_MANUAL,
3068 UserHandle.USER_CURRENT_OR_SELF);
3069 if (auto != 0) {
3070 Settings.System.putIntForUser(mContext.getContentResolver(),
3071 Settings.System.SCREEN_BRIGHTNESS_MODE,
3072 Settings.System.SCREEN_BRIGHTNESS_MODE_MANUAL,
3073 UserHandle.USER_CURRENT_OR_SELF);
3074 }
3075
3076 int min = mPowerManager.getMinimumScreenBrightnessSetting();
3077 int max = mPowerManager.getMaximumScreenBrightnessSetting();
3078 int step = (max - min + BRIGHTNESS_STEPS - 1) / BRIGHTNESS_STEPS * direction;
3079 int brightness = Settings.System.getIntForUser(mContext.getContentResolver(),
3080 Settings.System.SCREEN_BRIGHTNESS,
3081 mPowerManager.getDefaultScreenBrightnessSetting(),
3082 UserHandle.USER_CURRENT_OR_SELF);
3083 brightness += step;
3084 // Make sure we don't go beyond the limits.
3085 brightness = Math.min(max, brightness);
3086 brightness = Math.max(min, brightness);
3087
3088 Settings.System.putIntForUser(mContext.getContentResolver(),
3089 Settings.System.SCREEN_BRIGHTNESS, brightness,
3090 UserHandle.USER_CURRENT_OR_SELF);
Bart Sears8b1c27c2015-03-18 23:51:02 +00003091 startActivityAsUser(new Intent(Intent.ACTION_SHOW_BRIGHTNESS_DIALOG),
Alan Viverette5a399492014-07-14 16:19:38 -07003092 UserHandle.CURRENT_OR_SELF);
Michael Wrightb854e242013-02-05 17:54:02 -08003093 }
3094 return -1;
Jaewan Kim765487f2016-01-12 14:45:42 +09003095 } else if (keyCode == KeyEvent.KEYCODE_VOLUME_UP
3096 || keyCode == KeyEvent.KEYCODE_VOLUME_DOWN
3097 || keyCode == KeyEvent.KEYCODE_VOLUME_MUTE) {
3098 if (mUseTvRouting) {
3099 // On TVs volume keys never go to the foreground app.
3100 dispatchDirectAudioEvent(event);
3101 return -1;
3102 }
Michael Wrightce0c13a2014-07-30 10:49:21 -07003103 } else if (KeyEvent.isMetaKey(keyCode)) {
Michael Wright6a62e552014-06-03 19:19:48 -07003104 if (down) {
3105 mPendingMetaAction = true;
3106 } else if (mPendingMetaAction) {
Tim Kilbourn0e5f1102015-06-05 16:18:09 -07003107 launchAssistAction(Intent.EXTRA_ASSIST_INPUT_HINT_KEYBOARD, event.getDeviceId());
Michael Wright6a62e552014-06-03 19:19:48 -07003108 }
3109 return -1;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003110 }
Jeff Browncaab4d02010-12-09 22:13:41 -08003111
Jeff Brownc1fb48d2010-12-08 16:52:09 -08003112 // Shortcuts are invoked through Search+key, so intercept those here
Jeff Browncaab4d02010-12-09 22:13:41 -08003113 // Any printing key that is chorded with Search should be consumed
3114 // even if no shortcut was invoked. This prevents text from being
3115 // inadvertently inserted when using a keyboard that has built-in macro
3116 // shortcut keys (that emit Search+x) and some of them are not registered.
Jeff Brownfd23e3e2012-05-09 13:34:28 -07003117 if (mSearchKeyShortcutPending) {
Jeff Browncaab4d02010-12-09 22:13:41 -08003118 final KeyCharacterMap kcm = event.getKeyCharacterMap();
3119 if (kcm.isPrintingKey(keyCode)) {
Jeff Brownfd23e3e2012-05-09 13:34:28 -07003120 mConsumeSearchKeyUp = true;
3121 mSearchKeyShortcutPending = false;
Jeff Browncaab4d02010-12-09 22:13:41 -08003122 if (down && repeatCount == 0 && !keyguardOn) {
3123 Intent shortcutIntent = mShortcutManager.getIntent(kcm, keyCode, metaState);
3124 if (shortcutIntent != null) {
3125 shortcutIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
Jeff Brownf0a3cc52011-01-26 18:42:46 -08003126 try {
Bart Sears8b1c27c2015-03-18 23:51:02 +00003127 startActivityAsUser(shortcutIntent, UserHandle.CURRENT);
Jeff Brownf0a3cc52011-01-26 18:42:46 -08003128 } catch (ActivityNotFoundException ex) {
3129 Slog.w(TAG, "Dropping shortcut key combination because "
3130 + "the activity to which it is registered was not found: "
Jeff Brownfd23e3e2012-05-09 13:34:28 -07003131 + "SEARCH+" + KeyEvent.keyCodeToString(keyCode), ex);
Jeff Brownf0a3cc52011-01-26 18:42:46 -08003132 }
Jeff Browncaab4d02010-12-09 22:13:41 -08003133 } else {
3134 Slog.i(TAG, "Dropping unregistered shortcut key combination: "
Jeff Brownfd23e3e2012-05-09 13:34:28 -07003135 + "SEARCH+" + KeyEvent.keyCodeToString(keyCode));
Jeff Brown49ed71d2010-12-06 17:13:33 -08003136 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003137 }
Jeff Brownd5bb82d2011-10-12 13:57:59 -07003138 return -1;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003139 }
3140 }
3141
Jeff Brown68b909d2011-12-07 16:36:01 -08003142 // Invoke shortcuts using Meta.
Jeff Brown602ab322012-05-16 13:33:47 -07003143 if (down && repeatCount == 0 && !keyguardOn
Jeff Brown68b909d2011-12-07 16:36:01 -08003144 && (metaState & KeyEvent.META_META_ON) != 0) {
3145 final KeyCharacterMap kcm = event.getKeyCharacterMap();
Jeff Brown602ab322012-05-16 13:33:47 -07003146 if (kcm.isPrintingKey(keyCode)) {
3147 Intent shortcutIntent = mShortcutManager.getIntent(kcm, keyCode,
3148 metaState & ~(KeyEvent.META_META_ON
3149 | KeyEvent.META_META_LEFT_ON | KeyEvent.META_META_RIGHT_ON));
3150 if (shortcutIntent != null) {
3151 shortcutIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
3152 try {
Bart Sears8b1c27c2015-03-18 23:51:02 +00003153 startActivityAsUser(shortcutIntent, UserHandle.CURRENT);
Jeff Brown602ab322012-05-16 13:33:47 -07003154 } catch (ActivityNotFoundException ex) {
3155 Slog.w(TAG, "Dropping shortcut key combination because "
3156 + "the activity to which it is registered was not found: "
3157 + "META+" + KeyEvent.keyCodeToString(keyCode), ex);
3158 }
3159 return -1;
Jeff Brown68b909d2011-12-07 16:36:01 -08003160 }
Jeff Brown68b909d2011-12-07 16:36:01 -08003161 }
3162 }
3163
Jeff Brown6651a632011-11-28 12:59:11 -08003164 // Handle application launch keys.
Jeff Brown602ab322012-05-16 13:33:47 -07003165 if (down && repeatCount == 0 && !keyguardOn) {
Jeff Brown6651a632011-11-28 12:59:11 -08003166 String category = sApplicationLaunchKeyCategories.get(keyCode);
3167 if (category != null) {
Dianne Hackbornf5b86712011-12-05 17:42:41 -08003168 Intent intent = Intent.makeMainSelectorActivity(Intent.ACTION_MAIN, category);
Jeff Brown6651a632011-11-28 12:59:11 -08003169 intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
3170 try {
Bart Sears8b1c27c2015-03-18 23:51:02 +00003171 startActivityAsUser(intent, UserHandle.CURRENT);
Jeff Brown6651a632011-11-28 12:59:11 -08003172 } catch (ActivityNotFoundException ex) {
3173 Slog.w(TAG, "Dropping application launch key because "
3174 + "the activity to which it is registered was not found: "
3175 + "keyCode=" + keyCode + ", category=" + category, ex);
3176 }
Jeff Brown68b909d2011-12-07 16:36:01 -08003177 return -1;
Jeff Brown6651a632011-11-28 12:59:11 -08003178 }
3179 }
3180
Michael Wright61c46752014-08-21 16:57:33 -07003181 // Display task switcher for ALT-TAB.
Jeff Brown68b909d2011-12-07 16:36:01 -08003182 if (down && repeatCount == 0 && keyCode == KeyEvent.KEYCODE_TAB) {
Michael Wrightd847ad52015-10-24 13:24:15 +01003183 if (mRecentAppsHeldModifiers == 0 && !keyguardOn && isUserSetupComplete()) {
Jeff Brown68b909d2011-12-07 16:36:01 -08003184 final int shiftlessModifiers = event.getModifiers() & ~KeyEvent.META_SHIFT_MASK;
Michael Wright61c46752014-08-21 16:57:33 -07003185 if (KeyEvent.metaStateHasModifiers(shiftlessModifiers, KeyEvent.META_ALT_ON)) {
Winson Chung1e8d71b2014-05-16 17:05:22 -07003186 mRecentAppsHeldModifiers = shiftlessModifiers;
3187 showRecentApps(true);
Jeff Brown68b909d2011-12-07 16:36:01 -08003188 return -1;
3189 }
3190 }
Winson Chung1e8d71b2014-05-16 17:05:22 -07003191 } else if (!down && mRecentAppsHeldModifiers != 0
3192 && (metaState & mRecentAppsHeldModifiers) == 0) {
3193 mRecentAppsHeldModifiers = 0;
Winson Chungcdcd4872014-08-05 18:00:13 -07003194 hideRecentApps(true, false);
Jeff Brown68b909d2011-12-07 16:36:01 -08003195 }
3196
Yohei Yukawaae61f712015-12-09 13:00:10 -08003197 // Handle input method switching.
Jeff Browncf39bdf2012-05-18 14:41:19 -07003198 if (down && repeatCount == 0
3199 && (keyCode == KeyEvent.KEYCODE_LANGUAGE_SWITCH
3200 || (keyCode == KeyEvent.KEYCODE_SPACE
Yohei Yukawaae61f712015-12-09 13:00:10 -08003201 && (metaState & KeyEvent.META_META_MASK) != 0))) {
3202 final boolean forwardDirection = (metaState & KeyEvent.META_SHIFT_MASK) == 0;
3203 mWindowManagerFuncs.switchInputMethod(forwardDirection);
Jeff Browncf39bdf2012-05-18 14:41:19 -07003204 return -1;
3205 }
3206 if (mLanguageSwitchKeyPressed && !down
3207 && (keyCode == KeyEvent.KEYCODE_LANGUAGE_SWITCH
3208 || keyCode == KeyEvent.KEYCODE_SPACE)) {
3209 mLanguageSwitchKeyPressed = false;
3210 return -1;
3211 }
3212
Jeff Brown13f00f02014-10-31 14:45:50 -07003213 if (isValidGlobalKey(keyCode)
3214 && mGlobalKeyManager.handleGlobalKey(mContext, keyCode, event)) {
Justin Kohd378ad72013-04-01 12:18:26 -07003215 return -1;
3216 }
3217
Michael Wright6a62e552014-06-03 19:19:48 -07003218 // Reserve all the META modifier combos for system behavior
Michael Wrightce0c13a2014-07-30 10:49:21 -07003219 if ((metaState & KeyEvent.META_META_ON) != 0) {
Michael Wright6a62e552014-06-03 19:19:48 -07003220 return -1;
3221 }
3222
Jeff Brown68b909d2011-12-07 16:36:01 -08003223 // Let the application handle the key.
Jeff Brownd5bb82d2011-10-12 13:57:59 -07003224 return 0;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003225 }
3226
Jeff Brown3915bb82010-11-05 15:02:16 -07003227 /** {@inheritDoc} */
3228 @Override
Jeff Brown49ed71d2010-12-06 17:13:33 -08003229 public KeyEvent dispatchUnhandledKey(WindowState win, KeyEvent event, int policyFlags) {
Jeff Brown54875002011-04-06 15:33:01 -07003230 // Note: This method is only called if the initial down was unhandled.
Jeff Brown40013652012-05-16 21:22:36 -07003231 if (DEBUG_INPUT) {
Jeff Brown1f245102010-11-18 20:53:46 -08003232 Slog.d(TAG, "Unhandled key: win=" + win + ", action=" + event.getAction()
3233 + ", flags=" + event.getFlags()
3234 + ", keyCode=" + event.getKeyCode()
3235 + ", scanCode=" + event.getScanCode()
3236 + ", metaState=" + event.getMetaState()
3237 + ", repeatCount=" + event.getRepeatCount()
3238 + ", policyFlags=" + policyFlags);
Jeff Brown3915bb82010-11-05 15:02:16 -07003239 }
Jeff Brown49ed71d2010-12-06 17:13:33 -08003240
Jeff Brownfd23e3e2012-05-09 13:34:28 -07003241 KeyEvent fallbackEvent = null;
Jeff Brown49ed71d2010-12-06 17:13:33 -08003242 if ((event.getFlags() & KeyEvent.FLAG_FALLBACK) == 0) {
3243 final KeyCharacterMap kcm = event.getKeyCharacterMap();
Jeff Brownc1fb48d2010-12-08 16:52:09 -08003244 final int keyCode = event.getKeyCode();
3245 final int metaState = event.getMetaState();
Jeff Brownfd23e3e2012-05-09 13:34:28 -07003246 final boolean initialDown = event.getAction() == KeyEvent.ACTION_DOWN
3247 && event.getRepeatCount() == 0;
Jeff Brown49ed71d2010-12-06 17:13:33 -08003248
Jeff Brown54875002011-04-06 15:33:01 -07003249 // Check for fallback actions specified by the key character map.
Jeff Brownfd23e3e2012-05-09 13:34:28 -07003250 final FallbackAction fallbackAction;
3251 if (initialDown) {
3252 fallbackAction = kcm.getFallbackAction(keyCode, metaState);
3253 } else {
3254 fallbackAction = mFallbackActions.get(keyCode);
3255 }
3256
3257 if (fallbackAction != null) {
Jeff Brown40013652012-05-16 21:22:36 -07003258 if (DEBUG_INPUT) {
Jeff Brownfd23e3e2012-05-09 13:34:28 -07003259 Slog.d(TAG, "Fallback: keyCode=" + fallbackAction.keyCode
3260 + " metaState=" + Integer.toHexString(fallbackAction.metaState));
Jeff Brown49ed71d2010-12-06 17:13:33 -08003261 }
3262
Jeff Brownfd23e3e2012-05-09 13:34:28 -07003263 final int flags = event.getFlags() | KeyEvent.FLAG_FALLBACK;
3264 fallbackEvent = KeyEvent.obtain(
Jeff Brown49ed71d2010-12-06 17:13:33 -08003265 event.getDownTime(), event.getEventTime(),
Jeff Brownfd23e3e2012-05-09 13:34:28 -07003266 event.getAction(), fallbackAction.keyCode,
3267 event.getRepeatCount(), fallbackAction.metaState,
Jeff Brown49ed71d2010-12-06 17:13:33 -08003268 event.getDeviceId(), event.getScanCode(),
3269 flags, event.getSource(), null);
Jeff Brownfd23e3e2012-05-09 13:34:28 -07003270
3271 if (!interceptFallback(win, fallbackEvent, policyFlags)) {
3272 fallbackEvent.recycle();
3273 fallbackEvent = null;
Jeff Brown49ed71d2010-12-06 17:13:33 -08003274 }
Jeff Brownfd23e3e2012-05-09 13:34:28 -07003275
3276 if (initialDown) {
3277 mFallbackActions.put(keyCode, fallbackAction);
3278 } else if (event.getAction() == KeyEvent.ACTION_UP) {
3279 mFallbackActions.remove(keyCode);
3280 fallbackAction.recycle();
3281 }
Jeff Brown49ed71d2010-12-06 17:13:33 -08003282 }
3283 }
3284
Jeff Brown40013652012-05-16 21:22:36 -07003285 if (DEBUG_INPUT) {
Jeff Brownfd23e3e2012-05-09 13:34:28 -07003286 if (fallbackEvent == null) {
3287 Slog.d(TAG, "No fallback.");
3288 } else {
3289 Slog.d(TAG, "Performing fallback: " + fallbackEvent);
3290 }
Jeff Brown49ed71d2010-12-06 17:13:33 -08003291 }
Jeff Brownfd23e3e2012-05-09 13:34:28 -07003292 return fallbackEvent;
Jeff Brown3915bb82010-11-05 15:02:16 -07003293 }
3294
Jeff Brownfd23e3e2012-05-09 13:34:28 -07003295 private boolean interceptFallback(WindowState win, KeyEvent fallbackEvent, int policyFlags) {
Jeff Brown037c33e2014-04-09 00:31:55 -07003296 int actions = interceptKeyBeforeQueueing(fallbackEvent, policyFlags);
Jeff Brownfd23e3e2012-05-09 13:34:28 -07003297 if ((actions & ACTION_PASS_TO_USER) != 0) {
3298 long delayMillis = interceptKeyBeforeDispatching(
3299 win, fallbackEvent, policyFlags);
3300 if (delayMillis == 0) {
3301 return true;
3302 }
3303 }
3304 return false;
Jeff Brown6f2fba42011-02-19 01:08:02 -08003305 }
3306
Jeff Brownde7a8ea2012-06-13 18:28:57 -07003307 private void launchAssistLongPressAction() {
3308 performHapticFeedbackLw(null, HapticFeedbackConstants.LONG_PRESS, false);
3309 sendCloseSystemWindows(SYSTEM_DIALOG_REASON_ASSIST);
3310
3311 // launch the search activity
3312 Intent intent = new Intent(Intent.ACTION_SEARCH_LONG_PRESS);
3313 intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
3314 try {
RoboErik8a2cfc32014-05-16 11:19:38 -07003315 // TODO: This only stops the factory-installed search manager.
Jim Miller45308b12012-06-18 19:23:39 -07003316 // Need to formalize an API to handle others
Jeff Brownde7a8ea2012-06-13 18:28:57 -07003317 SearchManager searchManager = getSearchManager();
3318 if (searchManager != null) {
3319 searchManager.stopSearch();
3320 }
Bart Sears8b1c27c2015-03-18 23:51:02 +00003321 startActivityAsUser(intent, UserHandle.CURRENT);
Jeff Brownde7a8ea2012-06-13 18:28:57 -07003322 } catch (ActivityNotFoundException e) {
3323 Slog.w(TAG, "No activity to handle assist long press action.", e);
3324 }
3325 }
3326
Tim Kilbourn0e5f1102015-06-05 16:18:09 -07003327 private void launchAssistAction(String hint, int deviceId) {
Jeff Brownde7a8ea2012-06-13 18:28:57 -07003328 sendCloseSystemWindows(SYSTEM_DIALOG_REASON_ASSIST);
Maurice Lam39d13812015-07-23 20:49:20 -07003329 if (!isUserSetupComplete()) {
3330 // Disable opening assist window during setup
3331 return;
3332 }
Tim Kilbourn0e5f1102015-06-05 16:18:09 -07003333 Bundle args = null;
3334 if (deviceId > Integer.MIN_VALUE) {
3335 args = new Bundle();
3336 args.putInt(Intent.EXTRA_ASSIST_INPUT_DEVICE_ID, deviceId);
Jeff Brownde7a8ea2012-06-13 18:28:57 -07003337 }
Jorim Jaggi165ce062015-07-06 16:18:11 -07003338 if ((mContext.getResources().getConfiguration().uiMode
3339 & Configuration.UI_MODE_TYPE_MASK) == Configuration.UI_MODE_TYPE_TELEVISION) {
3340 // On TV, use legacy handling until assistants are implemented in the proper way.
3341 ((SearchManager) mContext.getSystemService(Context.SEARCH_SERVICE))
3342 .launchLegacyAssist(hint, UserHandle.myUserId(), args);
3343 } else {
3344 try {
3345 if (hint != null) {
3346 if (args == null) {
3347 args = new Bundle();
3348 }
3349 args.putBoolean(hint, true);
3350 }
3351 IStatusBarService statusbar = getStatusBarService();
3352 if (statusbar != null) {
3353 statusbar.startAssist(args);
3354 }
3355 } catch (RemoteException e) {
3356 Slog.e(TAG, "RemoteException when starting assist", e);
3357 // re-acquire status bar service next time it is needed.
3358 mStatusBarService = null;
3359 }
3360 }
Jeff Brownde7a8ea2012-06-13 18:28:57 -07003361 }
3362
Bart Sears8b1c27c2015-03-18 23:51:02 +00003363 private void startActivityAsUser(Intent intent, UserHandle handle) {
3364 if (isUserSetupComplete()) {
3365 mContext.startActivityAsUser(intent, handle);
3366 } else {
3367 Slog.i(TAG, "Not starting activity because user setup is in progress: " + intent);
3368 }
3369 }
3370
Jeff Brownde7a8ea2012-06-13 18:28:57 -07003371 private SearchManager getSearchManager() {
3372 if (mSearchManager == null) {
3373 mSearchManager = (SearchManager) mContext.getSystemService(Context.SEARCH_SERVICE);
3374 }
3375 return mSearchManager;
3376 }
3377
Jeff Browncaca8812013-05-09 13:34:33 -07003378 private void preloadRecentApps() {
3379 mPreloadedRecentApps = true;
3380 try {
3381 IStatusBarService statusbar = getStatusBarService();
3382 if (statusbar != null) {
3383 statusbar.preloadRecentApps();
3384 }
3385 } catch (RemoteException e) {
3386 Slog.e(TAG, "RemoteException when preloading recent apps", e);
3387 // re-acquire status bar service next time it is needed.
3388 mStatusBarService = null;
3389 }
3390 }
3391
3392 private void cancelPreloadRecentApps() {
3393 if (mPreloadedRecentApps) {
3394 mPreloadedRecentApps = false;
3395 try {
3396 IStatusBarService statusbar = getStatusBarService();
3397 if (statusbar != null) {
3398 statusbar.cancelPreloadRecentApps();
3399 }
3400 } catch (RemoteException e) {
Winson Chung1e8d71b2014-05-16 17:05:22 -07003401 Slog.e(TAG, "RemoteException when cancelling recent apps preload", e);
Jeff Browncaca8812013-05-09 13:34:33 -07003402 // re-acquire status bar service next time it is needed.
3403 mStatusBarService = null;
3404 }
3405 }
3406 }
3407
3408 private void toggleRecentApps() {
3409 mPreloadedRecentApps = false; // preloading no longer needs to be canceled
Jeff Browncaca8812013-05-09 13:34:33 -07003410 try {
3411 IStatusBarService statusbar = getStatusBarService();
3412 if (statusbar != null) {
3413 statusbar.toggleRecentApps();
3414 }
3415 } catch (RemoteException e) {
Winson Chung1e8d71b2014-05-16 17:05:22 -07003416 Slog.e(TAG, "RemoteException when toggling recent apps", e);
3417 // re-acquire status bar service next time it is needed.
3418 mStatusBarService = null;
3419 }
3420 }
3421
Craig Mautner84984fa2014-06-19 11:19:20 -07003422 @Override
3423 public void showRecentApps() {
3424 mHandler.removeMessages(MSG_DISPATCH_SHOW_RECENTS);
3425 mHandler.sendEmptyMessage(MSG_DISPATCH_SHOW_RECENTS);
3426 }
3427
Winson Chung1e8d71b2014-05-16 17:05:22 -07003428 private void showRecentApps(boolean triggeredFromAltTab) {
3429 mPreloadedRecentApps = false; // preloading no longer needs to be canceled
3430 try {
3431 IStatusBarService statusbar = getStatusBarService();
3432 if (statusbar != null) {
3433 statusbar.showRecentApps(triggeredFromAltTab);
3434 }
3435 } catch (RemoteException e) {
Jeff Browncaca8812013-05-09 13:34:33 -07003436 Slog.e(TAG, "RemoteException when showing recent apps", e);
3437 // re-acquire status bar service next time it is needed.
3438 mStatusBarService = null;
3439 }
3440 }
3441
Andrei Stingaceanuc22ab792016-01-07 12:39:38 +00003442 private void toggleKeyboardShortcutsMenu() {
Clara Bayarrif2debb12015-07-10 14:47:17 +01003443 try {
3444 IStatusBarService statusbar = getStatusBarService();
3445 if (statusbar != null) {
Andrei Stingaceanuc22ab792016-01-07 12:39:38 +00003446 statusbar.toggleKeyboardShortcutsMenu();
Clara Bayarrif2debb12015-07-10 14:47:17 +01003447 }
3448 } catch (RemoteException e) {
3449 Slog.e(TAG, "RemoteException when showing keyboard shortcuts menu", e);
3450 }
3451 }
3452
Winson Chungcdcd4872014-08-05 18:00:13 -07003453 private void hideRecentApps(boolean triggeredFromAltTab, boolean triggeredFromHome) {
Winson Chung1e8d71b2014-05-16 17:05:22 -07003454 mPreloadedRecentApps = false; // preloading no longer needs to be canceled
3455 try {
3456 IStatusBarService statusbar = getStatusBarService();
3457 if (statusbar != null) {
Winson Chungcdcd4872014-08-05 18:00:13 -07003458 statusbar.hideRecentApps(triggeredFromAltTab, triggeredFromHome);
Winson Chung1e8d71b2014-05-16 17:05:22 -07003459 }
3460 } catch (RemoteException e) {
3461 Slog.e(TAG, "RemoteException when closing recent apps", e);
3462 // re-acquire status bar service next time it is needed.
3463 mStatusBarService = null;
3464 }
3465 }
3466
Filip Gruszczynskia483a1d2015-03-17 19:06:58 +00003467 void launchHomeFromHotKey() {
Bryce Lee662ed802015-04-10 20:11:39 +00003468 launchHomeFromHotKey(true /* awakenFromDreams */, true /*respectKeyguard*/);
Filip Gruszczynskia483a1d2015-03-17 19:06:58 +00003469 }
3470
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003471 /**
3472 * A home key -> launch home action was detected. Take the appropriate action
3473 * given the situation with the keyguard.
3474 */
Bryce Lee662ed802015-04-10 20:11:39 +00003475 void launchHomeFromHotKey(final boolean awakenFromDreams, final boolean respectKeyguard) {
3476 if (respectKeyguard) {
3477 if (isKeyguardShowingAndNotOccluded()) {
3478 // don't launch home if keyguard showing
3479 return;
3480 }
3481
3482 if (!mHideLockScreen && mKeyguardDelegate.isInputRestricted()) {
3483 // when in keyguard restricted mode, must first verify unlock
3484 // before launching home
3485 mKeyguardDelegate.verifyUnlock(new OnKeyguardExitResult() {
3486 @Override
3487 public void onKeyguardExitResult(boolean success) {
3488 if (success) {
3489 try {
3490 ActivityManagerNative.getDefault().stopAppSwitches();
3491 } catch (RemoteException e) {
3492 }
3493 sendCloseSystemWindows(SYSTEM_DIALOG_REASON_HOME_KEY);
3494 startDockOrHome(true /*fromHomeKey*/, awakenFromDreams);
Dianne Hackborn256dd3b2009-05-19 18:51:21 -07003495 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003496 }
Bryce Lee662ed802015-04-10 20:11:39 +00003497 });
3498 return;
3499 }
3500 }
3501
3502 // no keyguard stuff to worry about, just launch home!
3503 try {
3504 ActivityManagerNative.getDefault().stopAppSwitches();
3505 } catch (RemoteException e) {
3506 }
3507 if (mRecentsVisible) {
3508 // Hide Recents and notify it to launch Home
3509 if (awakenFromDreams) {
3510 awakenDreams();
3511 }
Bryce Lee662ed802015-04-10 20:11:39 +00003512 hideRecentApps(false, true);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003513 } else {
Bryce Lee662ed802015-04-10 20:11:39 +00003514 // Otherwise, just launch Home
3515 sendCloseSystemWindows(SYSTEM_DIALOG_REASON_HOME_KEY);
3516 startDockOrHome(true /*fromHomeKey*/, awakenFromDreams);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003517 }
3518 }
3519
John Spurlock04db1762013-05-13 12:46:41 -04003520 private final Runnable mClearHideNavigationFlag = new Runnable() {
3521 @Override
3522 public void run() {
3523 synchronized (mWindowManagerFuncs.getWindowManagerLock()) {
3524 // Clear flags.
3525 mForceClearedSystemUiFlags &=
3526 ~View.SYSTEM_UI_FLAG_HIDE_NAVIGATION;
3527 }
3528 mWindowManagerFuncs.reevaluateStatusBarVisibility();
Dianne Hackborne26ab702011-10-16 13:21:33 -07003529 }
3530 };
3531
3532 /**
3533 * Input handler used while nav bar is hidden. Captures any touch on the screen,
3534 * to determine when the nav bar should be shown and prevent applications from
3535 * receiving those touches.
3536 */
Jeff Brown32cbc38552011-12-01 14:01:49 -08003537 final class HideNavInputEventReceiver extends InputEventReceiver {
3538 public HideNavInputEventReceiver(InputChannel inputChannel, Looper looper) {
3539 super(inputChannel, looper);
3540 }
3541
Dianne Hackborndf89e652011-10-06 22:35:11 -07003542 @Override
Jeff Brown32cbc38552011-12-01 14:01:49 -08003543 public void onInputEvent(InputEvent event) {
Dianne Hackborndf89e652011-10-06 22:35:11 -07003544 boolean handled = false;
3545 try {
Jeff Brown4952dfd2011-11-30 19:23:22 -08003546 if (event instanceof MotionEvent
3547 && (event.getSource() & InputDevice.SOURCE_CLASS_POINTER) != 0) {
3548 final MotionEvent motionEvent = (MotionEvent)event;
3549 if (motionEvent.getAction() == MotionEvent.ACTION_DOWN) {
Dianne Hackborndf89e652011-10-06 22:35:11 -07003550 // When the user taps down, we re-show the nav bar.
3551 boolean changed = false;
John Spurlock04db1762013-05-13 12:46:41 -04003552 synchronized (mWindowManagerFuncs.getWindowManagerLock()) {
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07003553 // Any user activity always causes us to show the
3554 // navigation controls, if they had been hidden.
3555 // We also clear the low profile and only content
3556 // flags so that tapping on the screen will atomically
3557 // restore all currently hidden screen decorations.
3558 int newVal = mResettingSystemUiFlags |
3559 View.SYSTEM_UI_FLAG_HIDE_NAVIGATION |
3560 View.SYSTEM_UI_FLAG_LOW_PROFILE |
3561 View.SYSTEM_UI_FLAG_FULLSCREEN;
Dianne Hackborne26ab702011-10-16 13:21:33 -07003562 if (mResettingSystemUiFlags != newVal) {
3563 mResettingSystemUiFlags = newVal;
Dianne Hackborndf89e652011-10-06 22:35:11 -07003564 changed = true;
3565 }
Dianne Hackborne26ab702011-10-16 13:21:33 -07003566 // We don't allow the system's nav bar to be hidden
3567 // again for 1 second, to prevent applications from
3568 // spamming us and keeping it from being shown.
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07003569 newVal = mForceClearedSystemUiFlags |
3570 View.SYSTEM_UI_FLAG_HIDE_NAVIGATION;
Dianne Hackborne26ab702011-10-16 13:21:33 -07003571 if (mForceClearedSystemUiFlags != newVal) {
3572 mForceClearedSystemUiFlags = newVal;
3573 changed = true;
John Spurlock04db1762013-05-13 12:46:41 -04003574 mHandler.postDelayed(mClearHideNavigationFlag, 1000);
Dianne Hackborne26ab702011-10-16 13:21:33 -07003575 }
Dianne Hackborndf89e652011-10-06 22:35:11 -07003576 }
3577 if (changed) {
3578 mWindowManagerFuncs.reevaluateStatusBarVisibility();
3579 }
3580 }
3581 }
3582 } finally {
Jeff Brown32cbc38552011-12-01 14:01:49 -08003583 finishInputEvent(event, handled);
Dianne Hackborndf89e652011-10-06 22:35:11 -07003584 }
3585 }
Jeff Brown32cbc38552011-12-01 14:01:49 -08003586 }
3587 final InputEventReceiver.Factory mHideNavInputEventReceiverFactory =
3588 new InputEventReceiver.Factory() {
3589 @Override
3590 public InputEventReceiver createInputEventReceiver(
3591 InputChannel inputChannel, Looper looper) {
3592 return new HideNavInputEventReceiver(inputChannel, looper);
3593 }
Dianne Hackborndf89e652011-10-06 22:35:11 -07003594 };
3595
3596 @Override
3597 public int adjustSystemUiVisibilityLw(int visibility) {
John Spurlock5b9145b2013-08-20 15:13:47 -04003598 mStatusBarController.adjustSystemUiVisibilityLw(mLastSystemUiFlags, visibility);
3599 mNavigationBarController.adjustSystemUiVisibilityLw(mLastSystemUiFlags, visibility);
Winson Chungd42a6cf2014-06-03 16:24:04 -07003600 mRecentsVisible = (visibility & View.RECENT_APPS_VISIBLE) > 0;
John Spurlock27735a42013-08-14 17:57:38 -04003601
Dianne Hackborndf89e652011-10-06 22:35:11 -07003602 // Reset any bits in mForceClearingStatusBarVisibility that
3603 // are now clear.
Dianne Hackborne26ab702011-10-16 13:21:33 -07003604 mResettingSystemUiFlags &= visibility;
Dianne Hackborndf89e652011-10-06 22:35:11 -07003605 // Clear any bits in the new visibility that are currently being
3606 // force cleared, before reporting it.
Dianne Hackborne26ab702011-10-16 13:21:33 -07003607 return visibility & ~mResettingSystemUiFlags
3608 & ~mForceClearedSystemUiFlags;
Dianne Hackborndf89e652011-10-06 22:35:11 -07003609 }
3610
Craig Mautner69b08182012-09-05 13:07:13 -07003611 @Override
Jorim Jaggi0ffd49c2016-02-12 15:04:21 -08003612 public boolean getInsetHintLw(WindowManager.LayoutParams attrs, int displayRotation,
Filip Gruszczynski2987f612015-06-30 15:03:30 -07003613 Rect outContentInsets, Rect outStableInsets, Rect outOutsets) {
John Spurlockc6d1c602014-01-17 15:22:06 -05003614 final int fl = PolicyControl.getWindowFlags(null, attrs);
John Spurlock1db8b682014-02-18 11:18:59 -05003615 final int sysuiVis = PolicyControl.getSystemUiVisibility(null, attrs);
3616 final int systemUiVisibility = (sysuiVis | attrs.subtreeSystemUiVisibility);
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07003617
Filip Gruszczynski2987f612015-06-30 15:03:30 -07003618 final boolean useOutsets = outOutsets != null && shouldUseOutsets(attrs, fl);
3619 if (useOutsets) {
3620 int outset = ScreenShapeHelper.getWindowOutsetBottomPx(mContext.getResources());
3621 if (outset > 0) {
3622 if (displayRotation == Surface.ROTATION_0) {
3623 outOutsets.bottom += outset;
3624 } else if (displayRotation == Surface.ROTATION_90) {
3625 outOutsets.right += outset;
3626 } else if (displayRotation == Surface.ROTATION_180) {
3627 outOutsets.top += outset;
3628 } else if (displayRotation == Surface.ROTATION_270) {
3629 outOutsets.left += outset;
3630 }
3631 }
3632 }
3633
Dianne Hackborn5b5cc4d2012-05-16 13:15:00 -07003634 if ((fl & (FLAG_LAYOUT_IN_SCREEN | FLAG_LAYOUT_INSET_DECOR))
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003635 == (FLAG_LAYOUT_IN_SCREEN | FLAG_LAYOUT_INSET_DECOR)) {
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07003636 int availRight, availBottom;
Alan Viverette5a0f4ec2013-10-07 15:10:29 -07003637 if (canHideNavigationBar() &&
Dianne Hackborn5b5cc4d2012-05-16 13:15:00 -07003638 (systemUiVisibility & View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION) != 0) {
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07003639 availRight = mUnrestrictedScreenLeft + mUnrestrictedScreenWidth;
3640 availBottom = mUnrestrictedScreenTop + mUnrestrictedScreenHeight;
3641 } else {
3642 availRight = mRestrictedScreenLeft + mRestrictedScreenWidth;
3643 availBottom = mRestrictedScreenTop + mRestrictedScreenHeight;
3644 }
Dianne Hackborn5b5cc4d2012-05-16 13:15:00 -07003645 if ((systemUiVisibility & View.SYSTEM_UI_FLAG_LAYOUT_STABLE) != 0) {
3646 if ((fl & FLAG_FULLSCREEN) != 0) {
Adrian Roos37d7a682014-11-06 18:15:16 +01003647 outContentInsets.set(mStableFullscreenLeft, mStableFullscreenTop,
Dianne Hackborn5b5cc4d2012-05-16 13:15:00 -07003648 availRight - mStableFullscreenRight,
3649 availBottom - mStableFullscreenBottom);
3650 } else {
Adrian Roos37d7a682014-11-06 18:15:16 +01003651 outContentInsets.set(mStableLeft, mStableTop,
Dianne Hackborn5b5cc4d2012-05-16 13:15:00 -07003652 availRight - mStableRight, availBottom - mStableBottom);
3653 }
Dianne Hackbornc652de82013-02-15 16:32:56 -08003654 } else if ((fl & FLAG_FULLSCREEN) != 0 || (fl & FLAG_LAYOUT_IN_OVERSCAN) != 0) {
Adrian Roos37d7a682014-11-06 18:15:16 +01003655 outContentInsets.setEmpty();
Dianne Hackborn5b5cc4d2012-05-16 13:15:00 -07003656 } else if ((systemUiVisibility & (View.SYSTEM_UI_FLAG_FULLSCREEN
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07003657 | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN)) == 0) {
Adrian Roos37d7a682014-11-06 18:15:16 +01003658 outContentInsets.set(mCurLeft, mCurTop,
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07003659 availRight - mCurRight, availBottom - mCurBottom);
3660 } else {
Adrian Roos37d7a682014-11-06 18:15:16 +01003661 outContentInsets.set(mCurLeft, mCurTop,
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07003662 availRight - mCurRight, availBottom - mCurBottom);
3663 }
Adrian Roos37d7a682014-11-06 18:15:16 +01003664
3665 outStableInsets.set(mStableLeft, mStableTop,
3666 availRight - mStableRight, availBottom - mStableBottom);
Jorim Jaggi0ffd49c2016-02-12 15:04:21 -08003667 return mForceShowSystemBars;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003668 }
Adrian Roos37d7a682014-11-06 18:15:16 +01003669 outContentInsets.setEmpty();
3670 outStableInsets.setEmpty();
Jorim Jaggi0ffd49c2016-02-12 15:04:21 -08003671 return mForceShowSystemBars;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003672 }
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07003673
Filip Gruszczynski2987f612015-06-30 15:03:30 -07003674 private boolean shouldUseOutsets(WindowManager.LayoutParams attrs, int fl) {
3675 return attrs.type == TYPE_WALLPAPER || (fl & (WindowManager.LayoutParams.FLAG_FULLSCREEN
3676 | WindowManager.LayoutParams.FLAG_LAYOUT_IN_OVERSCAN)) != 0;
3677 }
3678
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003679 /** {@inheritDoc} */
Craig Mautner69b08182012-09-05 13:07:13 -07003680 @Override
3681 public void beginLayoutLw(boolean isDefaultDisplay, int displayWidth, int displayHeight,
Sriram Viswanathan9ebbe6a2015-11-16 17:59:22 -08003682 int displayRotation, int uiMode) {
Filip Gruszczynski2987f612015-06-30 15:03:30 -07003683 mDisplayRotation = displayRotation;
Dianne Hackbornc652de82013-02-15 16:32:56 -08003684 final int overscanLeft, overscanTop, overscanRight, overscanBottom;
3685 if (isDefaultDisplay) {
3686 switch (displayRotation) {
3687 case Surface.ROTATION_90:
3688 overscanLeft = mOverscanTop;
3689 overscanTop = mOverscanRight;
3690 overscanRight = mOverscanBottom;
3691 overscanBottom = mOverscanLeft;
3692 break;
3693 case Surface.ROTATION_180:
3694 overscanLeft = mOverscanRight;
3695 overscanTop = mOverscanBottom;
3696 overscanRight = mOverscanLeft;
3697 overscanBottom = mOverscanTop;
3698 break;
3699 case Surface.ROTATION_270:
3700 overscanLeft = mOverscanBottom;
3701 overscanTop = mOverscanLeft;
3702 overscanRight = mOverscanTop;
3703 overscanBottom = mOverscanRight;
3704 break;
3705 default:
3706 overscanLeft = mOverscanLeft;
3707 overscanTop = mOverscanTop;
3708 overscanRight = mOverscanRight;
3709 overscanBottom = mOverscanBottom;
3710 break;
3711 }
3712 } else {
3713 overscanLeft = 0;
3714 overscanTop = 0;
3715 overscanRight = 0;
3716 overscanBottom = 0;
3717 }
Dianne Hackborn313440842013-02-19 19:22:59 -08003718 mOverscanScreenLeft = mRestrictedOverscanScreenLeft = 0;
3719 mOverscanScreenTop = mRestrictedOverscanScreenTop = 0;
3720 mOverscanScreenWidth = mRestrictedOverscanScreenWidth = displayWidth;
3721 mOverscanScreenHeight = mRestrictedOverscanScreenHeight = displayHeight;
Dianne Hackbornc652de82013-02-15 16:32:56 -08003722 mSystemLeft = 0;
3723 mSystemTop = 0;
3724 mSystemRight = displayWidth;
3725 mSystemBottom = displayHeight;
3726 mUnrestrictedScreenLeft = overscanLeft;
3727 mUnrestrictedScreenTop = overscanTop;
3728 mUnrestrictedScreenWidth = displayWidth - overscanLeft - overscanRight;
3729 mUnrestrictedScreenHeight = displayHeight - overscanTop - overscanBottom;
3730 mRestrictedScreenLeft = mUnrestrictedScreenLeft;
3731 mRestrictedScreenTop = mUnrestrictedScreenTop;
John Spurlockad3e6cb2013-04-30 08:47:43 -04003732 mRestrictedScreenWidth = mSystemGestures.screenWidth = mUnrestrictedScreenWidth;
3733 mRestrictedScreenHeight = mSystemGestures.screenHeight = mUnrestrictedScreenHeight;
Dianne Hackborne30e02f2014-05-27 18:24:45 -07003734 mDockLeft = mContentLeft = mVoiceContentLeft = mStableLeft = mStableFullscreenLeft
Dianne Hackbornc652de82013-02-15 16:32:56 -08003735 = mCurLeft = mUnrestrictedScreenLeft;
Dianne Hackborne30e02f2014-05-27 18:24:45 -07003736 mDockTop = mContentTop = mVoiceContentTop = mStableTop = mStableFullscreenTop
Dianne Hackbornc652de82013-02-15 16:32:56 -08003737 = mCurTop = mUnrestrictedScreenTop;
Dianne Hackborne30e02f2014-05-27 18:24:45 -07003738 mDockRight = mContentRight = mVoiceContentRight = mStableRight = mStableFullscreenRight
Dianne Hackbornc652de82013-02-15 16:32:56 -08003739 = mCurRight = displayWidth - overscanRight;
Dianne Hackborne30e02f2014-05-27 18:24:45 -07003740 mDockBottom = mContentBottom = mVoiceContentBottom = mStableBottom = mStableFullscreenBottom
Dianne Hackbornc652de82013-02-15 16:32:56 -08003741 = mCurBottom = displayHeight - overscanBottom;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003742 mDockLayer = 0x10000000;
Dianne Hackborn5c58de32012-04-28 19:52:37 -07003743 mStatusBarLayer = -1;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003744
Daniel Sandler8956dbb2011-04-22 07:55:02 -04003745 // start with the current dock rect, which will be (0,0,displayWidth,displayHeight)
3746 final Rect pf = mTmpParentFrame;
3747 final Rect df = mTmpDisplayFrame;
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003748 final Rect of = mTmpOverscanFrame;
Daniel Sandler8956dbb2011-04-22 07:55:02 -04003749 final Rect vf = mTmpVisibleFrame;
John Spurlock46646232013-09-30 22:32:42 -04003750 final Rect dcf = mTmpDecorFrame;
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003751 pf.left = df.left = of.left = vf.left = mDockLeft;
3752 pf.top = df.top = of.top = vf.top = mDockTop;
3753 pf.right = df.right = of.right = vf.right = mDockRight;
3754 pf.bottom = df.bottom = of.bottom = vf.bottom = mDockBottom;
John Spurlock46646232013-09-30 22:32:42 -04003755 dcf.setEmpty(); // Decor frame N/A for system bars.
Daniel Sandler8956dbb2011-04-22 07:55:02 -04003756
Craig Mautner69b08182012-09-05 13:07:13 -07003757 if (isDefaultDisplay) {
3758 // For purposes of putting out fake window up to steal focus, we will
3759 // drive nav being hidden only by whether it is requested.
John Spurlocke1f366f2013-08-05 12:22:40 -04003760 final int sysui = mLastSystemUiFlags;
3761 boolean navVisible = (sysui & View.SYSTEM_UI_FLAG_HIDE_NAVIGATION) == 0;
Adrian Roosea562512014-05-05 13:33:03 +02003762 boolean navTranslucent = (sysui
Jorim Jaggi4fa78922015-11-30 17:13:56 -08003763 & (View.NAVIGATION_BAR_TRANSLUCENT | View.NAVIGATION_BAR_TRANSPARENT)) != 0;
John Spurlockf1a36642013-10-12 17:50:42 -04003764 boolean immersive = (sysui & View.SYSTEM_UI_FLAG_IMMERSIVE) != 0;
3765 boolean immersiveSticky = (sysui & View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY) != 0;
3766 boolean navAllowedHidden = immersive || immersiveSticky;
3767 navTranslucent &= !immersiveSticky; // transient trumps translucent
Adrian Roos4fb3ee32014-08-22 19:29:09 +02003768 boolean isKeyguardShowing = isStatusBarKeyguard() && !mHideLockScreen;
3769 if (!isKeyguardShowing) {
3770 navTranslucent &= areTranslucentBarsAllowed();
3771 }
Dianne Hackborne26ab702011-10-16 13:21:33 -07003772
Craig Mautner69b08182012-09-05 13:07:13 -07003773 // When the navigation bar isn't visible, we put up a fake
3774 // input window to catch all touch events. This way we can
3775 // detect when the user presses anywhere to bring back the nav
3776 // bar and ensure the application doesn't see the event.
John Spurlockf1a36642013-10-12 17:50:42 -04003777 if (navVisible || navAllowedHidden) {
Selim Cinekf83e8242015-05-19 18:08:14 -07003778 if (mInputConsumer != null) {
3779 mInputConsumer.dismiss();
3780 mInputConsumer = null;
Craig Mautner69b08182012-09-05 13:07:13 -07003781 }
Selim Cinekf83e8242015-05-19 18:08:14 -07003782 } else if (mInputConsumer == null) {
3783 mInputConsumer = mWindowManagerFuncs.addInputConsumer(mHandler.getLooper(),
3784 mHideNavInputEventReceiverFactory);
Dianne Hackborne26ab702011-10-16 13:21:33 -07003785 }
Dianne Hackborne26ab702011-10-16 13:21:33 -07003786
Craig Mautner69b08182012-09-05 13:07:13 -07003787 // For purposes of positioning and showing the nav bar, if we have
3788 // decided that it can't be hidden (because of the screen aspect ratio),
3789 // then take that into account.
Alan Viverette5a0f4ec2013-10-07 15:10:29 -07003790 navVisible |= !canHideNavigationBar();
Dianne Hackbornf87d1962012-04-04 12:48:24 -07003791
Filip Gruszczynski83dd9552015-09-17 17:50:36 -07003792 boolean updateSysUiVisibility = layoutNavigationBar(displayWidth, displayHeight,
Sriram Viswanathan9ebbe6a2015-11-16 17:59:22 -08003793 displayRotation, uiMode, overscanRight, overscanBottom, dcf, navVisible, navTranslucent,
Filip Gruszczynski83dd9552015-09-17 17:50:36 -07003794 navAllowedHidden);
Craig Mautnereda67292013-04-28 13:50:14 -07003795 if (DEBUG_LAYOUT) Slog.i(TAG, String.format("mDock rect: (%d,%d - %d,%d)",
Craig Mautner69b08182012-09-05 13:07:13 -07003796 mDockLeft, mDockTop, mDockRight, mDockBottom));
Filip Gruszczynski83dd9552015-09-17 17:50:36 -07003797 updateSysUiVisibility |= layoutStatusBar(pf, df, of, vf, dcf, sysui, isKeyguardShowing);
John Spurlockad3e6cb2013-04-30 08:47:43 -04003798 if (updateSysUiVisibility) {
3799 updateSystemUiVisibilityLw();
3800 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003801 }
3802 }
3803
Filip Gruszczynski83dd9552015-09-17 17:50:36 -07003804 private boolean layoutStatusBar(Rect pf, Rect df, Rect of, Rect vf, Rect dcf, int sysui,
3805 boolean isKeyguardShowing) {
3806 // decide where the status bar goes ahead of time
3807 if (mStatusBar != null) {
3808 // apply any navigation bar insets
3809 pf.left = df.left = of.left = mUnrestrictedScreenLeft;
3810 pf.top = df.top = of.top = mUnrestrictedScreenTop;
3811 pf.right = df.right = of.right = mUnrestrictedScreenWidth + mUnrestrictedScreenLeft;
3812 pf.bottom = df.bottom = of.bottom = mUnrestrictedScreenHeight
3813 + mUnrestrictedScreenTop;
3814 vf.left = mStableLeft;
3815 vf.top = mStableTop;
3816 vf.right = mStableRight;
3817 vf.bottom = mStableBottom;
3818
3819 mStatusBarLayer = mStatusBar.getSurfaceLayer();
3820
3821 // Let the status bar determine its size.
3822 mStatusBar.computeFrameLw(pf /* parentFrame */, df /* displayFrame */,
3823 vf /* overlayFrame */, vf /* contentFrame */, vf /* visibleFrame */,
3824 dcf /* decorFrame */, vf /* stableFrame */, vf /* outsetFrame */);
3825
3826 // For layout, the status bar is always at the top with our fixed height.
3827 mStableTop = mUnrestrictedScreenTop + mStatusBarHeight;
3828
3829 boolean statusBarTransient = (sysui & View.STATUS_BAR_TRANSIENT) != 0;
3830 boolean statusBarTranslucent = (sysui
Jorim Jaggi4fa78922015-11-30 17:13:56 -08003831 & (View.STATUS_BAR_TRANSLUCENT | View.STATUS_BAR_TRANSPARENT)) != 0;
Filip Gruszczynski83dd9552015-09-17 17:50:36 -07003832 if (!isKeyguardShowing) {
3833 statusBarTranslucent &= areTranslucentBarsAllowed();
3834 }
3835
3836 // If the status bar is hidden, we don't want to cause
3837 // windows behind it to scroll.
3838 if (mStatusBar.isVisibleLw() && !statusBarTransient) {
3839 // Status bar may go away, so the screen area it occupies
3840 // is available to apps but just covering them when the
3841 // status bar is visible.
3842 mDockTop = mUnrestrictedScreenTop + mStatusBarHeight;
3843
3844 mContentTop = mVoiceContentTop = mCurTop = mDockTop;
3845 mContentBottom = mVoiceContentBottom = mCurBottom = mDockBottom;
3846 mContentLeft = mVoiceContentLeft = mCurLeft = mDockLeft;
3847 mContentRight = mVoiceContentRight = mCurRight = mDockRight;
3848
3849 if (DEBUG_LAYOUT) Slog.v(TAG, "Status bar: " +
3850 String.format(
3851 "dock=[%d,%d][%d,%d] content=[%d,%d][%d,%d] cur=[%d,%d][%d,%d]",
3852 mDockLeft, mDockTop, mDockRight, mDockBottom,
3853 mContentLeft, mContentTop, mContentRight, mContentBottom,
3854 mCurLeft, mCurTop, mCurRight, mCurBottom));
3855 }
3856 if (mStatusBar.isVisibleLw() && !mStatusBar.isAnimatingLw()
3857 && !statusBarTransient && !statusBarTranslucent
3858 && !mStatusBarController.wasRecentlyTranslucent()) {
3859 // If the opaque status bar is currently requested to be visible,
3860 // and not in the process of animating on or off, then
3861 // we can tell the app that it is covered by it.
3862 mSystemTop = mUnrestrictedScreenTop + mStatusBarHeight;
3863 }
3864 if (mStatusBarController.checkHiddenLw()) {
3865 return true;
3866 }
3867 }
3868 return false;
3869 }
3870
3871 private boolean layoutNavigationBar(int displayWidth, int displayHeight, int displayRotation,
Sriram Viswanathan9ebbe6a2015-11-16 17:59:22 -08003872 int uiMode, int overscanRight, int overscanBottom, Rect dcf, boolean navVisible,
Filip Gruszczynski83dd9552015-09-17 17:50:36 -07003873 boolean navTranslucent, boolean navAllowedHidden) {
3874 if (mNavigationBar != null) {
3875 boolean transientNavBarShowing = mNavigationBarController.isTransientShowing();
3876 // Force the navigation bar to its appropriate place and
3877 // size. We need to do this directly, instead of relying on
3878 // it to bubble up from the nav bar, because this needs to
3879 // change atomically with screen rotations.
Jorim Jaggi737af722015-12-31 10:42:27 +01003880 mNavigationBarOnBottom = isNavigationBarOnBottom(displayWidth, displayHeight);
Filip Gruszczynski83dd9552015-09-17 17:50:36 -07003881 if (mNavigationBarOnBottom) {
3882 // It's a system nav bar or a portrait screen; nav bar goes on bottom.
3883 int top = displayHeight - overscanBottom
Sriram Viswanathan9ebbe6a2015-11-16 17:59:22 -08003884 - getNavigationBarHeight(displayRotation, uiMode);
Filip Gruszczynski83dd9552015-09-17 17:50:36 -07003885 mTmpNavigationFrame.set(0, top, displayWidth, displayHeight - overscanBottom);
3886 mStableBottom = mStableFullscreenBottom = mTmpNavigationFrame.top;
3887 if (transientNavBarShowing) {
3888 mNavigationBarController.setBarShowingLw(true);
3889 } else if (navVisible) {
3890 mNavigationBarController.setBarShowingLw(true);
3891 mDockBottom = mTmpNavigationFrame.top;
3892 mRestrictedScreenHeight = mDockBottom - mRestrictedScreenTop;
3893 mRestrictedOverscanScreenHeight = mDockBottom - mRestrictedOverscanScreenTop;
3894 } else {
3895 // We currently want to hide the navigation UI.
3896 mNavigationBarController.setBarShowingLw(false);
3897 }
3898 if (navVisible && !navTranslucent && !navAllowedHidden
3899 && !mNavigationBar.isAnimatingLw()
3900 && !mNavigationBarController.wasRecentlyTranslucent()) {
3901 // If the opaque nav bar is currently requested to be visible,
3902 // and not in the process of animating on or off, then
3903 // we can tell the app that it is covered by it.
3904 mSystemBottom = mTmpNavigationFrame.top;
3905 }
3906 } else {
3907 // Landscape screen; nav bar goes to the right.
3908 int left = displayWidth - overscanRight
Sriram Viswanathan9ebbe6a2015-11-16 17:59:22 -08003909 - getNavigationBarWidth(displayRotation, uiMode);
Filip Gruszczynski83dd9552015-09-17 17:50:36 -07003910 mTmpNavigationFrame.set(left, 0, displayWidth - overscanRight, displayHeight);
3911 mStableRight = mStableFullscreenRight = mTmpNavigationFrame.left;
3912 if (transientNavBarShowing) {
3913 mNavigationBarController.setBarShowingLw(true);
3914 } else if (navVisible) {
3915 mNavigationBarController.setBarShowingLw(true);
3916 mDockRight = mTmpNavigationFrame.left;
3917 mRestrictedScreenWidth = mDockRight - mRestrictedScreenLeft;
3918 mRestrictedOverscanScreenWidth = mDockRight - mRestrictedOverscanScreenLeft;
3919 } else {
3920 // We currently want to hide the navigation UI.
3921 mNavigationBarController.setBarShowingLw(false);
3922 }
3923 if (navVisible && !navTranslucent && !navAllowedHidden
3924 && !mNavigationBar.isAnimatingLw()
3925 && !mNavigationBarController.wasRecentlyTranslucent()) {
3926 // If the nav bar is currently requested to be visible,
3927 // and not in the process of animating on or off, then
3928 // we can tell the app that it is covered by it.
3929 mSystemRight = mTmpNavigationFrame.left;
3930 }
3931 }
3932 // Make sure the content and current rectangles are updated to
3933 // account for the restrictions from the navigation bar.
3934 mContentTop = mVoiceContentTop = mCurTop = mDockTop;
3935 mContentBottom = mVoiceContentBottom = mCurBottom = mDockBottom;
3936 mContentLeft = mVoiceContentLeft = mCurLeft = mDockLeft;
3937 mContentRight = mVoiceContentRight = mCurRight = mDockRight;
3938 mStatusBarLayer = mNavigationBar.getSurfaceLayer();
3939 // And compute the final frame.
3940 mNavigationBar.computeFrameLw(mTmpNavigationFrame, mTmpNavigationFrame,
3941 mTmpNavigationFrame, mTmpNavigationFrame, mTmpNavigationFrame, dcf,
3942 mTmpNavigationFrame, mTmpNavigationFrame);
3943 if (DEBUG_LAYOUT) Slog.i(TAG, "mNavigationBar frame: " + mTmpNavigationFrame);
3944 if (mNavigationBarController.checkHiddenLw()) {
3945 return true;
3946 }
3947 }
3948 return false;
3949 }
3950
Jorim Jaggi737af722015-12-31 10:42:27 +01003951 private boolean isNavigationBarOnBottom(int displayWidth, int displayHeight) {
3952 return !mNavigationBarCanMove || displayWidth < displayHeight;
3953 }
3954
Dianne Hackborn85afd1b2012-05-13 13:31:06 -07003955 /** {@inheritDoc} */
Craig Mautner967212c2013-04-13 21:10:58 -07003956 @Override
John Spurlock46646232013-09-30 22:32:42 -04003957 public int getSystemDecorLayerLw() {
Bryce Lee2ed3e5f2015-04-01 22:09:19 +00003958 if (mStatusBar != null && mStatusBar.isVisibleLw()) {
3959 return mStatusBar.getSurfaceLayer();
3960 }
3961
3962 if (mNavigationBar != null && mNavigationBar.isVisibleLw()) {
3963 return mNavigationBar.getSurfaceLayer();
3964 }
3965
Dianne Hackborn85afd1b2012-05-13 13:31:06 -07003966 return 0;
3967 }
3968
Craig Mautner967212c2013-04-13 21:10:58 -07003969 @Override
3970 public void getContentRectLw(Rect r) {
3971 r.set(mContentLeft, mContentTop, mContentRight, mContentBottom);
3972 }
3973
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003974 void setAttachedWindowFrames(WindowState win, int fl, int adjust, WindowState attached,
3975 boolean insetDecors, Rect pf, Rect df, Rect of, Rect cf, Rect vf) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003976 if (win.getSurfaceLayer() > mDockLayer && attached.getSurfaceLayer() < mDockLayer) {
3977 // Here's a special case: if this attached window is a panel that is
3978 // above the dock window, and the window it is attached to is below
3979 // the dock window, then the frames we computed for the window it is
3980 // attached to can not be used because the dock is effectively part
3981 // of the underlying window and the attached window is floating on top
3982 // of the whole thing. So, we ignore the attached window and explicitly
3983 // compute the frames that would be appropriate without the dock.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003984 df.left = of.left = cf.left = vf.left = mDockLeft;
3985 df.top = of.top = cf.top = vf.top = mDockTop;
3986 df.right = of.right = cf.right = vf.right = mDockRight;
3987 df.bottom = of.bottom = cf.bottom = vf.bottom = mDockBottom;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003988 } else {
3989 // The effective display frame of the attached window depends on
3990 // whether it is taking care of insetting its content. If not,
3991 // we need to use the parent's content frame so that the entire
3992 // window is positioned within that content. Otherwise we can use
Wale Ogunwale393b1c12014-10-18 16:22:01 -07003993 // the overscan frame and let the attached window take care of
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003994 // positioning its content appropriately.
Dianne Hackborndea3ef72010-10-28 14:24:22 -07003995 if (adjust != SOFT_INPUT_ADJUST_RESIZE) {
Wale Ogunwale393b1c12014-10-18 16:22:01 -07003996 // Set the content frame of the attached window to the parent's decor frame
3997 // (same as content frame when IME isn't present) if specifically requested by
3998 // setting {@link WindowManager.LayoutParams#FLAG_LAYOUT_ATTACHED_IN_DECOR} flag.
3999 // Otherwise, use the overscan frame.
4000 cf.set((fl & FLAG_LAYOUT_ATTACHED_IN_DECOR) != 0
4001 ? attached.getContentFrameLw() : attached.getOverscanFrameLw());
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004002 } else {
4003 // If the window is resizing, then we want to base the content
4004 // frame on our attached content frame to resize... however,
4005 // things can be tricky if the attached window is NOT in resize
4006 // mode, in which case its content frame will be larger.
4007 // Ungh. So to deal with that, make sure the content frame
4008 // we end up using is not covering the IM dock.
4009 cf.set(attached.getContentFrameLw());
Dianne Hackborne30e02f2014-05-27 18:24:45 -07004010 if (attached.isVoiceInteraction()) {
4011 if (cf.left < mVoiceContentLeft) cf.left = mVoiceContentLeft;
4012 if (cf.top < mVoiceContentTop) cf.top = mVoiceContentTop;
4013 if (cf.right > mVoiceContentRight) cf.right = mVoiceContentRight;
4014 if (cf.bottom > mVoiceContentBottom) cf.bottom = mVoiceContentBottom;
4015 } else if (attached.getSurfaceLayer() < mDockLayer) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004016 if (cf.left < mContentLeft) cf.left = mContentLeft;
4017 if (cf.top < mContentTop) cf.top = mContentTop;
4018 if (cf.right > mContentRight) cf.right = mContentRight;
4019 if (cf.bottom > mContentBottom) cf.bottom = mContentBottom;
4020 }
4021 }
4022 df.set(insetDecors ? attached.getDisplayFrameLw() : cf);
Dianne Hackbornc4aad012013-02-22 15:05:25 -08004023 of.set(insetDecors ? attached.getOverscanFrameLw() : cf);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004024 vf.set(attached.getVisibleFrameLw());
4025 }
4026 // The LAYOUT_IN_SCREEN flag is used to determine whether the attached
4027 // window should be positioned relative to its parent or the entire
4028 // screen.
4029 pf.set((fl & FLAG_LAYOUT_IN_SCREEN) == 0
4030 ? attached.getFrameLw() : df);
4031 }
Dianne Hackborn5b5cc4d2012-05-16 13:15:00 -07004032
4033 private void applyStableConstraints(int sysui, int fl, Rect r) {
4034 if ((sysui & View.SYSTEM_UI_FLAG_LAYOUT_STABLE) != 0) {
4035 // If app is requesting a stable layout, don't let the
4036 // content insets go below the stable values.
4037 if ((fl & FLAG_FULLSCREEN) != 0) {
4038 if (r.left < mStableFullscreenLeft) r.left = mStableFullscreenLeft;
4039 if (r.top < mStableFullscreenTop) r.top = mStableFullscreenTop;
4040 if (r.right > mStableFullscreenRight) r.right = mStableFullscreenRight;
4041 if (r.bottom > mStableFullscreenBottom) r.bottom = mStableFullscreenBottom;
4042 } else {
4043 if (r.left < mStableLeft) r.left = mStableLeft;
4044 if (r.top < mStableTop) r.top = mStableTop;
4045 if (r.right > mStableRight) r.right = mStableRight;
4046 if (r.bottom > mStableBottom) r.bottom = mStableBottom;
4047 }
4048 }
4049 }
4050
Jorim Jaggiaa806142015-05-20 18:04:16 -07004051 private boolean canReceiveInput(WindowState win) {
4052 boolean notFocusable =
4053 (win.getAttrs().flags & WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE) != 0;
4054 boolean altFocusableIm =
4055 (win.getAttrs().flags & WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM) != 0;
4056 boolean notFocusableForIm = notFocusable ^ altFocusableIm;
4057 return !notFocusableForIm;
4058 }
4059
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004060 /** {@inheritDoc} */
Craig Mautner69b08182012-09-05 13:07:13 -07004061 @Override
Craig Mautnerc9457fa2014-06-06 14:27:48 -07004062 public void layoutWindowLw(WindowState win, WindowState attached) {
Jorim Jaggiaa806142015-05-20 18:04:16 -07004063 // We've already done the navigation bar and status bar. If the status bar can receive
4064 // input, we need to layout it again to accomodate for the IME window.
4065 if ((win == mStatusBar && !canReceiveInput(win)) || win == mNavigationBar) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004066 return;
4067 }
Jorim Jaggiaa806142015-05-20 18:04:16 -07004068 final WindowManager.LayoutParams attrs = win.getAttrs();
Craig Mautner69b08182012-09-05 13:07:13 -07004069 final boolean isDefaultDisplay = win.isDefaultDisplay();
4070 final boolean needsToOffsetInputMethodTarget = isDefaultDisplay &&
satok1bc0a492012-04-25 22:47:12 +09004071 (win == mLastInputMethodTargetWindow && mLastInputMethodWindow != null);
4072 if (needsToOffsetInputMethodTarget) {
Craig Mautnereda67292013-04-28 13:50:14 -07004073 if (DEBUG_LAYOUT) Slog.i(TAG, "Offset ime target window by the last ime window state");
satok1bc0a492012-04-25 22:47:12 +09004074 offsetInputMethodWindowLw(mLastInputMethodWindow);
4075 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004076
John Spurlockc6d1c602014-01-17 15:22:06 -05004077 final int fl = PolicyControl.getWindowFlags(win, attrs);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004078 final int sim = attrs.softInputMode;
John Spurlock1db8b682014-02-18 11:18:59 -05004079 final int sysUiFl = PolicyControl.getSystemUiVisibility(win, null);
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07004080
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004081 final Rect pf = mTmpParentFrame;
4082 final Rect df = mTmpDisplayFrame;
Dianne Hackbornc4aad012013-02-22 15:05:25 -08004083 final Rect of = mTmpOverscanFrame;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004084 final Rect cf = mTmpContentFrame;
4085 final Rect vf = mTmpVisibleFrame;
John Spurlock46646232013-09-30 22:32:42 -04004086 final Rect dcf = mTmpDecorFrame;
Adrian Roosfa104232014-06-20 16:10:14 -07004087 final Rect sf = mTmpStableFrame;
Filip Gruszczynski2217f612015-05-26 11:32:08 -07004088 Rect osf = null;
John Spurlock46646232013-09-30 22:32:42 -04004089 dcf.setEmpty();
Craig Mautner69b08182012-09-05 13:07:13 -07004090
4091 final boolean hasNavBar = (isDefaultDisplay && mHasNavigationBar
Daniel Sandler36412a72011-08-04 09:35:13 -04004092 && mNavigationBar != null && mNavigationBar.isVisibleLw());
Daniel Sandler8956dbb2011-04-22 07:55:02 -04004093
Craig Mautnerf683b562012-10-02 11:10:57 -07004094 final int adjust = sim & SOFT_INPUT_MASK_ADJUST;
4095
Adrian Roosfa104232014-06-20 16:10:14 -07004096 if (isDefaultDisplay) {
4097 sf.set(mStableLeft, mStableTop, mStableRight, mStableBottom);
4098 } else {
4099 sf.set(mOverscanLeft, mOverscanTop, mOverscanRight, mOverscanBottom);
4100 }
4101
Craig Mautner69b08182012-09-05 13:07:13 -07004102 if (!isDefaultDisplay) {
4103 if (attached != null) {
4104 // If this window is attached to another, our display
4105 // frame is the same as the one we are attached to.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08004106 setAttachedWindowFrames(win, fl, adjust, attached, true, pf, df, of, cf, vf);
Craig Mautner69b08182012-09-05 13:07:13 -07004107 } else {
4108 // Give the window full screen.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08004109 pf.left = df.left = of.left = cf.left = mOverscanScreenLeft;
4110 pf.top = df.top = of.top = cf.top = mOverscanScreenTop;
4111 pf.right = df.right = of.right = cf.right
Dianne Hackbornc652de82013-02-15 16:32:56 -08004112 = mOverscanScreenLeft + mOverscanScreenWidth;
Dianne Hackbornc4aad012013-02-22 15:05:25 -08004113 pf.bottom = df.bottom = of.bottom = cf.bottom
Dianne Hackbornc652de82013-02-15 16:32:56 -08004114 = mOverscanScreenTop + mOverscanScreenHeight;
Craig Mautner69b08182012-09-05 13:07:13 -07004115 }
Jorim Jaggi225d3b52015-04-01 11:18:57 -07004116 } else if (attrs.type == TYPE_INPUT_METHOD) {
Dianne Hackbornc4aad012013-02-22 15:05:25 -08004117 pf.left = df.left = of.left = cf.left = vf.left = mDockLeft;
4118 pf.top = df.top = of.top = cf.top = vf.top = mDockTop;
4119 pf.right = df.right = of.right = cf.right = vf.right = mDockRight;
John Spurlockc68d5772013-10-08 11:47:58 -04004120 // IM dock windows layout below the nav bar...
John Spurlock57beb3b2013-10-10 10:27:44 -04004121 pf.bottom = df.bottom = of.bottom = mUnrestrictedScreenTop + mUnrestrictedScreenHeight;
John Spurlockc68d5772013-10-08 11:47:58 -04004122 // ...with content insets above the nav bar
4123 cf.bottom = vf.bottom = mStableBottom;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004124 // IM dock windows always go to the bottom of the screen.
4125 attrs.gravity = Gravity.BOTTOM;
4126 mDockLayer = win.getSurfaceLayer();
Jorim Jaggi225d3b52015-04-01 11:18:57 -07004127 } else if (attrs.type == TYPE_VOICE_INTERACTION) {
Stefan Kuhne2f280d062015-06-18 07:20:33 -10004128 pf.left = df.left = of.left = mUnrestrictedScreenLeft;
Jorim Jaggi225d3b52015-04-01 11:18:57 -07004129 pf.top = df.top = of.top = mUnrestrictedScreenTop;
Stefan Kuhne2f280d062015-06-18 07:20:33 -10004130 pf.right = df.right = of.right = mUnrestrictedScreenLeft + mUnrestrictedScreenWidth;
4131 pf.bottom = df.bottom = of.bottom = mUnrestrictedScreenTop + mUnrestrictedScreenHeight;
Jorim Jaggi225d3b52015-04-01 11:18:57 -07004132 cf.bottom = vf.bottom = mStableBottom;
Stefan Kuhne2f280d062015-06-18 07:20:33 -10004133 // Note: In Phone landscape mode, the button bar should also be excluded.
4134 cf.right = vf.right = mStableRight;
4135 cf.left = vf.left = mStableLeft;
Jorim Jaggi225d3b52015-04-01 11:18:57 -07004136 cf.top = vf.top = mStableTop;
Jorim Jaggiaa806142015-05-20 18:04:16 -07004137 } else if (win == mStatusBar) {
Jorim Jaggie0700182014-08-21 01:12:37 +02004138 pf.left = df.left = of.left = mUnrestrictedScreenLeft;
4139 pf.top = df.top = of.top = mUnrestrictedScreenTop;
4140 pf.right = df.right = of.right = mUnrestrictedScreenWidth + mUnrestrictedScreenLeft;
4141 pf.bottom = df.bottom = of.bottom = mUnrestrictedScreenHeight + mUnrestrictedScreenTop;
4142 cf.left = vf.left = mStableLeft;
4143 cf.top = vf.top = mStableTop;
4144 cf.right = vf.right = mStableRight;
4145 vf.bottom = mStableBottom;
Adrian Roosdc5b4532016-01-06 20:49:41 +01004146
4147 if (adjust == SOFT_INPUT_ADJUST_RESIZE) {
4148 cf.bottom = mContentBottom;
4149 } else {
4150 cf.bottom = mDockBottom;
4151 vf.bottom = mContentBottom;
4152 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004153 } else {
John Spurlock46646232013-09-30 22:32:42 -04004154
4155 // Default policy decor for the default display
4156 dcf.left = mSystemLeft;
4157 dcf.top = mSystemTop;
4158 dcf.right = mSystemRight;
4159 dcf.bottom = mSystemBottom;
John Spurlockbd957402013-10-03 11:38:39 -04004160 final boolean inheritTranslucentDecor = (attrs.privateFlags
4161 & WindowManager.LayoutParams.PRIVATE_FLAG_INHERIT_TRANSLUCENT_DECOR) != 0;
John Spurlock65567d42013-10-08 10:08:32 -04004162 final boolean isAppWindow =
4163 attrs.type >= WindowManager.LayoutParams.FIRST_APPLICATION_WINDOW &&
4164 attrs.type <= WindowManager.LayoutParams.LAST_APPLICATION_WINDOW;
4165 final boolean topAtRest =
4166 win == mTopFullscreenOpaqueWindowState && !win.isAnimatingLw();
4167 if (isAppWindow && !inheritTranslucentDecor && !topAtRest) {
John Spurlockbd957402013-10-03 11:38:39 -04004168 if ((sysUiFl & View.SYSTEM_UI_FLAG_FULLSCREEN) == 0
4169 && (fl & WindowManager.LayoutParams.FLAG_FULLSCREEN) == 0
Adrian Roosea562512014-05-05 13:33:03 +02004170 && (fl & WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS) == 0
4171 && (fl & WindowManager.LayoutParams.
Jorim Jaggi4fa78922015-11-30 17:13:56 -08004172 FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS) == 0
4173 && !mForceWindowDrawsStatusBarBackground) {
John Spurlock46646232013-09-30 22:32:42 -04004174 // Ensure policy decor includes status bar
4175 dcf.top = mStableTop;
4176 }
John Spurlockbd957402013-10-03 11:38:39 -04004177 if ((fl & WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION) == 0
Adrian Roosea562512014-05-05 13:33:03 +02004178 && (sysUiFl & View.SYSTEM_UI_FLAG_HIDE_NAVIGATION) == 0
4179 && (fl & WindowManager.LayoutParams.
4180 FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS) == 0) {
John Spurlock46646232013-09-30 22:32:42 -04004181 // Ensure policy decor includes navigation bar
4182 dcf.bottom = mStableBottom;
4183 dcf.right = mStableRight;
4184 }
4185 }
4186
Dianne Hackbornc4aad012013-02-22 15:05:25 -08004187 if ((fl & (FLAG_LAYOUT_IN_SCREEN | FLAG_LAYOUT_INSET_DECOR))
4188 == (FLAG_LAYOUT_IN_SCREEN | FLAG_LAYOUT_INSET_DECOR)) {
RoboErik8a2cfc32014-05-16 11:19:38 -07004189 if (DEBUG_LAYOUT) Slog.v(TAG, "layoutWindowLw(" + attrs.getTitle()
Dianne Hackbornc4aad012013-02-22 15:05:25 -08004190 + "): IN_SCREEN, INSET_DECOR");
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004191 // This is the case for a normal activity window: we want it
4192 // to cover all of the screen space, and it can take care of
4193 // moving its contents to account for screen decorations that
4194 // intrude into that space.
4195 if (attached != null) {
4196 // If this window is attached to another, our display
4197 // frame is the same as the one we are attached to.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08004198 setAttachedWindowFrames(win, fl, adjust, attached, true, pf, df, of, cf, vf);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004199 } else {
Daniel Sandler8956dbb2011-04-22 07:55:02 -04004200 if (attrs.type == TYPE_STATUS_BAR_PANEL
4201 || attrs.type == TYPE_STATUS_BAR_SUB_PANEL) {
Joe Onorato29fc2c92010-11-24 10:26:50 -08004202 // Status bar panels are the only windows who can go on top of
4203 // the status bar. They are protected by the STATUS_BAR_SERVICE
4204 // permission, so they have the same privileges as the status
4205 // bar itself.
Daniel Sandler8956dbb2011-04-22 07:55:02 -04004206 //
Daniel Sandler8e8b4152011-07-21 01:16:43 -04004207 // However, they should still dodge the navigation bar if it exists.
Daniel Sandler8956dbb2011-04-22 07:55:02 -04004208
Dianne Hackbornc4aad012013-02-22 15:05:25 -08004209 pf.left = df.left = of.left = hasNavBar
4210 ? mDockLeft : mUnrestrictedScreenLeft;
4211 pf.top = df.top = of.top = mUnrestrictedScreenTop;
4212 pf.right = df.right = of.right = hasNavBar
4213 ? mRestrictedScreenLeft+mRestrictedScreenWidth
4214 : mUnrestrictedScreenLeft + mUnrestrictedScreenWidth;
4215 pf.bottom = df.bottom = of.bottom = hasNavBar
4216 ? mRestrictedScreenTop+mRestrictedScreenHeight
4217 : mUnrestrictedScreenTop + mUnrestrictedScreenHeight;
Daniel Sandler8956dbb2011-04-22 07:55:02 -04004218
Craig Mautnereda67292013-04-28 13:50:14 -07004219 if (DEBUG_LAYOUT) Slog.v(TAG, String.format(
Daniel Sandler8e8b4152011-07-21 01:16:43 -04004220 "Laying out status bar window: (%d,%d - %d,%d)",
4221 pf.left, pf.top, pf.right, pf.bottom));
John Spurlock46646232013-09-30 22:32:42 -04004222 } else if ((fl & FLAG_LAYOUT_IN_OVERSCAN) != 0
Dianne Hackbornc652de82013-02-15 16:32:56 -08004223 && attrs.type >= WindowManager.LayoutParams.FIRST_APPLICATION_WINDOW
4224 && attrs.type <= WindowManager.LayoutParams.LAST_SUB_WINDOW) {
4225 // Asking to layout into the overscan region, so give it that pure
4226 // unrestricted area.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08004227 pf.left = df.left = of.left = mOverscanScreenLeft;
4228 pf.top = df.top = of.top = mOverscanScreenTop;
4229 pf.right = df.right = of.right = mOverscanScreenLeft + mOverscanScreenWidth;
4230 pf.bottom = df.bottom = of.bottom = mOverscanScreenTop
4231 + mOverscanScreenHeight;
Alan Viverette5a0f4ec2013-10-07 15:10:29 -07004232 } else if (canHideNavigationBar()
Dianne Hackbornf87d1962012-04-04 12:48:24 -07004233 && (sysUiFl & View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION) != 0
Jorim Jaggi380ecb82014-03-14 17:25:20 +01004234 && attrs.type >= WindowManager.LayoutParams.FIRST_APPLICATION_WINDOW
4235 && attrs.type <= WindowManager.LayoutParams.LAST_SUB_WINDOW) {
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07004236 // Asking for layout as if the nav bar is hidden, lets the
Dianne Hackbornc652de82013-02-15 16:32:56 -08004237 // application extend into the unrestricted overscan screen area. We
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07004238 // only do this for application windows to ensure no window that
4239 // can be above the nav bar can do this.
Dianne Hackborn313440842013-02-19 19:22:59 -08004240 pf.left = df.left = mOverscanScreenLeft;
4241 pf.top = df.top = mOverscanScreenTop;
4242 pf.right = df.right = mOverscanScreenLeft + mOverscanScreenWidth;
4243 pf.bottom = df.bottom = mOverscanScreenTop + mOverscanScreenHeight;
Dianne Hackbornc4aad012013-02-22 15:05:25 -08004244 // We need to tell the app about where the frame inside the overscan
4245 // is, so it can inset its content by that amount -- it didn't ask
4246 // to actually extend itself into the overscan region.
4247 of.left = mUnrestrictedScreenLeft;
4248 of.top = mUnrestrictedScreenTop;
4249 of.right = mUnrestrictedScreenLeft + mUnrestrictedScreenWidth;
4250 of.bottom = mUnrestrictedScreenTop + mUnrestrictedScreenHeight;
Joe Onorato29fc2c92010-11-24 10:26:50 -08004251 } else {
Dianne Hackborn313440842013-02-19 19:22:59 -08004252 pf.left = df.left = mRestrictedOverscanScreenLeft;
4253 pf.top = df.top = mRestrictedOverscanScreenTop;
4254 pf.right = df.right = mRestrictedOverscanScreenLeft
4255 + mRestrictedOverscanScreenWidth;
4256 pf.bottom = df.bottom = mRestrictedOverscanScreenTop
4257 + mRestrictedOverscanScreenHeight;
Dianne Hackbornc4aad012013-02-22 15:05:25 -08004258 // We need to tell the app about where the frame inside the overscan
4259 // is, so it can inset its content by that amount -- it didn't ask
4260 // to actually extend itself into the overscan region.
4261 of.left = mUnrestrictedScreenLeft;
4262 of.top = mUnrestrictedScreenTop;
4263 of.right = mUnrestrictedScreenLeft + mUnrestrictedScreenWidth;
4264 of.bottom = mUnrestrictedScreenTop + mUnrestrictedScreenHeight;
Joe Onorato29fc2c92010-11-24 10:26:50 -08004265 }
Craig Mautner69b08182012-09-05 13:07:13 -07004266
John Spurlock46646232013-09-30 22:32:42 -04004267 if ((fl & FLAG_FULLSCREEN) == 0) {
Dianne Hackborne30e02f2014-05-27 18:24:45 -07004268 if (win.isVoiceInteraction()) {
4269 cf.left = mVoiceContentLeft;
4270 cf.top = mVoiceContentTop;
4271 cf.right = mVoiceContentRight;
4272 cf.bottom = mVoiceContentBottom;
Dianne Hackbornc4aad012013-02-22 15:05:25 -08004273 } else {
Dianne Hackborne30e02f2014-05-27 18:24:45 -07004274 if (adjust != SOFT_INPUT_ADJUST_RESIZE) {
4275 cf.left = mDockLeft;
4276 cf.top = mDockTop;
4277 cf.right = mDockRight;
4278 cf.bottom = mDockBottom;
4279 } else {
4280 cf.left = mContentLeft;
4281 cf.top = mContentTop;
4282 cf.right = mContentRight;
4283 cf.bottom = mContentBottom;
4284 }
Dianne Hackbornc4aad012013-02-22 15:05:25 -08004285 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004286 } else {
Dianne Hackbornc4aad012013-02-22 15:05:25 -08004287 // Full screen windows are always given a layout that is as if the
4288 // status bar and other transient decors are gone. This is to avoid
4289 // bad states when moving from a window that is not hding the
4290 // status bar to one that is.
4291 cf.left = mRestrictedScreenLeft;
4292 cf.top = mRestrictedScreenTop;
4293 cf.right = mRestrictedScreenLeft + mRestrictedScreenWidth;
4294 cf.bottom = mRestrictedScreenTop + mRestrictedScreenHeight;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004295 }
Dianne Hackborn5b5cc4d2012-05-16 13:15:00 -07004296 applyStableConstraints(sysUiFl, fl, cf);
Dianne Hackborndea3ef72010-10-28 14:24:22 -07004297 if (adjust != SOFT_INPUT_ADJUST_NOTHING) {
4298 vf.left = mCurLeft;
4299 vf.top = mCurTop;
4300 vf.right = mCurRight;
4301 vf.bottom = mCurBottom;
4302 } else {
4303 vf.set(cf);
4304 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004305 }
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07004306 } else if ((fl & FLAG_LAYOUT_IN_SCREEN) != 0 || (sysUiFl
4307 & (View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
4308 | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION)) != 0) {
Craig Mautnereda67292013-04-28 13:50:14 -07004309 if (DEBUG_LAYOUT) Slog.v(TAG, "layoutWindowLw(" + attrs.getTitle() +
4310 "): IN_SCREEN");
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004311 // A window that has requested to fill the entire screen just
4312 // gets everything, period.
Daniel Sandler8956dbb2011-04-22 07:55:02 -04004313 if (attrs.type == TYPE_STATUS_BAR_PANEL
John Spurlock67a0f852015-06-15 15:35:47 -04004314 || attrs.type == TYPE_STATUS_BAR_SUB_PANEL
4315 || attrs.type == TYPE_VOLUME_OVERLAY) {
Dianne Hackbornc4aad012013-02-22 15:05:25 -08004316 pf.left = df.left = of.left = cf.left = hasNavBar
4317 ? mDockLeft : mUnrestrictedScreenLeft;
4318 pf.top = df.top = of.top = cf.top = mUnrestrictedScreenTop;
4319 pf.right = df.right = of.right = cf.right = hasNavBar
Daniel Sandler8e8b4152011-07-21 01:16:43 -04004320 ? mRestrictedScreenLeft+mRestrictedScreenWidth
Dianne Hackbornc652de82013-02-15 16:32:56 -08004321 : mUnrestrictedScreenLeft + mUnrestrictedScreenWidth;
Dianne Hackbornc4aad012013-02-22 15:05:25 -08004322 pf.bottom = df.bottom = of.bottom = cf.bottom = hasNavBar
Daniel Sandler8e8b4152011-07-21 01:16:43 -04004323 ? mRestrictedScreenTop+mRestrictedScreenHeight
Dianne Hackbornc652de82013-02-15 16:32:56 -08004324 : mUnrestrictedScreenTop + mUnrestrictedScreenHeight;
Craig Mautnereda67292013-04-28 13:50:14 -07004325 if (DEBUG_LAYOUT) Slog.v(TAG, String.format(
Daniel Sandler36412a72011-08-04 09:35:13 -04004326 "Laying out IN_SCREEN status bar window: (%d,%d - %d,%d)",
4327 pf.left, pf.top, pf.right, pf.bottom));
Jim Millere898ac52012-04-06 17:10:57 -07004328 } else if (attrs.type == TYPE_NAVIGATION_BAR
4329 || attrs.type == TYPE_NAVIGATION_BAR_PANEL) {
Daniel Sandler8e8b4152011-07-21 01:16:43 -04004330 // The navigation bar has Real Ultimate Power.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08004331 pf.left = df.left = of.left = mUnrestrictedScreenLeft;
4332 pf.top = df.top = of.top = mUnrestrictedScreenTop;
4333 pf.right = df.right = of.right = mUnrestrictedScreenLeft
4334 + mUnrestrictedScreenWidth;
4335 pf.bottom = df.bottom = of.bottom = mUnrestrictedScreenTop
4336 + mUnrestrictedScreenHeight;
Craig Mautnereda67292013-04-28 13:50:14 -07004337 if (DEBUG_LAYOUT) Slog.v(TAG, String.format(
Daniel Sandler8e8b4152011-07-21 01:16:43 -04004338 "Laying out navigation bar window: (%d,%d - %d,%d)",
4339 pf.left, pf.top, pf.right, pf.bottom));
Dianne Hackborn01011c32012-02-21 13:54:21 -08004340 } else if ((attrs.type == TYPE_SECURE_SYSTEM_OVERLAY
4341 || attrs.type == TYPE_BOOT_PROGRESS)
Jeff Brownbfcb60a2011-09-08 18:51:14 -07004342 && ((fl & FLAG_FULLSCREEN) != 0)) {
4343 // Fullscreen secure system overlays get what they ask for.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08004344 pf.left = df.left = of.left = cf.left = mOverscanScreenLeft;
4345 pf.top = df.top = of.top = cf.top = mOverscanScreenTop;
4346 pf.right = df.right = of.right = cf.right = mOverscanScreenLeft
4347 + mOverscanScreenWidth;
4348 pf.bottom = df.bottom = of.bottom = cf.bottom = mOverscanScreenTop
4349 + mOverscanScreenHeight;
Craig Mautner165be0c2015-01-27 15:16:58 -08004350 } else if (attrs.type == TYPE_BOOT_PROGRESS) {
Dianne Hackborn01011c32012-02-21 13:54:21 -08004351 // Boot progress screen always covers entire display.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08004352 pf.left = df.left = of.left = cf.left = mOverscanScreenLeft;
4353 pf.top = df.top = of.top = cf.top = mOverscanScreenTop;
4354 pf.right = df.right = of.right = cf.right = mOverscanScreenLeft
4355 + mOverscanScreenWidth;
4356 pf.bottom = df.bottom = of.bottom = cf.bottom = mOverscanScreenTop
4357 + mOverscanScreenHeight;
John Spurlockef4adae2013-08-26 17:58:58 -04004358 } else if (attrs.type == TYPE_WALLPAPER) {
Dianne Hackborn067e5f62014-09-07 23:14:30 -07004359 // The wallpaper also has Real Ultimate Power, but we want to tell
4360 // it about the overscan area.
4361 pf.left = df.left = mOverscanScreenLeft;
4362 pf.top = df.top = mOverscanScreenTop;
4363 pf.right = df.right = mOverscanScreenLeft + mOverscanScreenWidth;
4364 pf.bottom = df.bottom = mOverscanScreenTop + mOverscanScreenHeight;
4365 of.left = cf.left = mUnrestrictedScreenLeft;
4366 of.top = cf.top = mUnrestrictedScreenTop;
4367 of.right = cf.right = mUnrestrictedScreenLeft + mUnrestrictedScreenWidth;
4368 of.bottom = cf.bottom = mUnrestrictedScreenTop + mUnrestrictedScreenHeight;
John Spurlock46646232013-09-30 22:32:42 -04004369 } else if ((fl & FLAG_LAYOUT_IN_OVERSCAN) != 0
Dianne Hackbornc652de82013-02-15 16:32:56 -08004370 && attrs.type >= WindowManager.LayoutParams.FIRST_APPLICATION_WINDOW
4371 && attrs.type <= WindowManager.LayoutParams.LAST_SUB_WINDOW) {
4372 // Asking to layout into the overscan region, so give it that pure
4373 // unrestricted area.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08004374 pf.left = df.left = of.left = cf.left = mOverscanScreenLeft;
4375 pf.top = df.top = of.top = cf.top = mOverscanScreenTop;
4376 pf.right = df.right = of.right = cf.right
Dianne Hackbornc652de82013-02-15 16:32:56 -08004377 = mOverscanScreenLeft + mOverscanScreenWidth;
Dianne Hackbornc4aad012013-02-22 15:05:25 -08004378 pf.bottom = df.bottom = of.bottom = cf.bottom
Dianne Hackbornc652de82013-02-15 16:32:56 -08004379 = mOverscanScreenTop + mOverscanScreenHeight;
Alan Viverette5a0f4ec2013-10-07 15:10:29 -07004380 } else if (canHideNavigationBar()
Dianne Hackbornf87d1962012-04-04 12:48:24 -07004381 && (sysUiFl & View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION) != 0
Craig Mautnerbeac1062014-06-03 14:38:57 -07004382 && (attrs.type == TYPE_STATUS_BAR
4383 || attrs.type == TYPE_TOAST
Jorim Jaggi81fe2d12015-12-21 14:45:18 +01004384 || attrs.type == TYPE_DOCK_DIVIDER
Jorim Jaggi2fdeeab2015-04-01 15:13:03 -07004385 || attrs.type == TYPE_VOICE_INTERACTION_STARTING
John Spurlock34e13d92013-08-10 06:52:28 -04004386 || (attrs.type >= WindowManager.LayoutParams.FIRST_APPLICATION_WINDOW
4387 && attrs.type <= WindowManager.LayoutParams.LAST_SUB_WINDOW))) {
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07004388 // Asking for layout as if the nav bar is hidden, lets the
4389 // application extend into the unrestricted screen area. We
John Spurlock34e13d92013-08-10 06:52:28 -04004390 // only do this for application windows (or toasts) to ensure no window that
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07004391 // can be above the nav bar can do this.
4392 // XXX This assumes that an app asking for this will also
4393 // ask for layout in only content. We can't currently figure out
4394 // what the screen would be if only laying out to hide the nav bar.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08004395 pf.left = df.left = of.left = cf.left = mUnrestrictedScreenLeft;
4396 pf.top = df.top = of.top = cf.top = mUnrestrictedScreenTop;
4397 pf.right = df.right = of.right = cf.right = mUnrestrictedScreenLeft
4398 + mUnrestrictedScreenWidth;
4399 pf.bottom = df.bottom = of.bottom = cf.bottom = mUnrestrictedScreenTop
4400 + mUnrestrictedScreenHeight;
Jorim Jaggi9f6798a2016-02-10 22:16:06 -08004401 } else if ((sysUiFl & View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN) != 0) {
4402 pf.left = df.left = of.left = mRestrictedScreenLeft;
4403 pf.top = df.top = of.top = mRestrictedScreenTop;
4404 pf.right = df.right = of.right = mRestrictedScreenLeft + mRestrictedScreenWidth;
4405 pf.bottom = df.bottom = of.bottom = mRestrictedScreenTop
4406 + mRestrictedScreenHeight;
4407 if (adjust != SOFT_INPUT_ADJUST_RESIZE) {
4408 cf.left = mDockLeft;
4409 cf.top = mDockTop;
4410 cf.right = mDockRight;
4411 cf.bottom = mDockBottom;
4412 } else {
4413 cf.left = mContentLeft;
4414 cf.top = mContentTop;
4415 cf.right = mContentRight;
4416 cf.bottom = mContentBottom;
4417 }
Joe Onorato29fc2c92010-11-24 10:26:50 -08004418 } else {
Dianne Hackbornc4aad012013-02-22 15:05:25 -08004419 pf.left = df.left = of.left = cf.left = mRestrictedScreenLeft;
4420 pf.top = df.top = of.top = cf.top = mRestrictedScreenTop;
4421 pf.right = df.right = of.right = cf.right = mRestrictedScreenLeft
4422 + mRestrictedScreenWidth;
4423 pf.bottom = df.bottom = of.bottom = cf.bottom = mRestrictedScreenTop
4424 + mRestrictedScreenHeight;
Joe Onorato29fc2c92010-11-24 10:26:50 -08004425 }
Craig Mautner69b08182012-09-05 13:07:13 -07004426
Dianne Hackborn5b5cc4d2012-05-16 13:15:00 -07004427 applyStableConstraints(sysUiFl, fl, cf);
Craig Mautner69b08182012-09-05 13:07:13 -07004428
Dianne Hackborndea3ef72010-10-28 14:24:22 -07004429 if (adjust != SOFT_INPUT_ADJUST_NOTHING) {
4430 vf.left = mCurLeft;
4431 vf.top = mCurTop;
4432 vf.right = mCurRight;
4433 vf.bottom = mCurBottom;
4434 } else {
4435 vf.set(cf);
4436 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004437 } else if (attached != null) {
Craig Mautnereda67292013-04-28 13:50:14 -07004438 if (DEBUG_LAYOUT) Slog.v(TAG, "layoutWindowLw(" + attrs.getTitle() +
4439 "): attached to " + attached);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004440 // A child window should be placed inside of the same visible
4441 // frame that its parent had.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08004442 setAttachedWindowFrames(win, fl, adjust, attached, false, pf, df, of, cf, vf);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004443 } else {
Craig Mautnereda67292013-04-28 13:50:14 -07004444 if (DEBUG_LAYOUT) Slog.v(TAG, "layoutWindowLw(" + attrs.getTitle() +
4445 "): normal window");
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004446 // Otherwise, a normal window must be placed inside the content
4447 // of all screen decorations.
John Spurlock67a0f852015-06-15 15:35:47 -04004448 if (attrs.type == TYPE_STATUS_BAR_PANEL || attrs.type == TYPE_VOLUME_OVERLAY) {
4449 // Status bar panels and the volume dialog are the only windows who can go on
4450 // top of the status bar. They are protected by the STATUS_BAR_SERVICE
Dianne Hackborna239c842011-06-01 12:28:20 -07004451 // permission, so they have the same privileges as the status
4452 // bar itself.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08004453 pf.left = df.left = of.left = cf.left = mRestrictedScreenLeft;
4454 pf.top = df.top = of.top = cf.top = mRestrictedScreenTop;
4455 pf.right = df.right = of.right = cf.right = mRestrictedScreenLeft
4456 + mRestrictedScreenWidth;
4457 pf.bottom = df.bottom = of.bottom = cf.bottom = mRestrictedScreenTop
4458 + mRestrictedScreenHeight;
John Spurlock67a0f852015-06-15 15:35:47 -04004459 } else if (attrs.type == TYPE_TOAST || attrs.type == TYPE_SYSTEM_ALERT) {
John Spurlock414c1f02013-12-04 13:47:36 -05004460 // These dialogs are stable to interim decor changes.
John Spurlockbd957402013-10-03 11:38:39 -04004461 pf.left = df.left = of.left = cf.left = mStableLeft;
4462 pf.top = df.top = of.top = cf.top = mStableTop;
4463 pf.right = df.right = of.right = cf.right = mStableRight;
4464 pf.bottom = df.bottom = of.bottom = cf.bottom = mStableBottom;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004465 } else {
Dianne Hackborna239c842011-06-01 12:28:20 -07004466 pf.left = mContentLeft;
4467 pf.top = mContentTop;
4468 pf.right = mContentRight;
4469 pf.bottom = mContentBottom;
Dianne Hackborn20d94742014-05-29 18:35:45 -07004470 if (win.isVoiceInteraction()) {
4471 df.left = of.left = cf.left = mVoiceContentLeft;
4472 df.top = of.top = cf.top = mVoiceContentTop;
4473 df.right = of.right = cf.right = mVoiceContentRight;
4474 df.bottom = of.bottom = cf.bottom = mVoiceContentBottom;
4475 } else if (adjust != SOFT_INPUT_ADJUST_RESIZE) {
Dianne Hackbornc4aad012013-02-22 15:05:25 -08004476 df.left = of.left = cf.left = mDockLeft;
4477 df.top = of.top = cf.top = mDockTop;
4478 df.right = of.right = cf.right = mDockRight;
4479 df.bottom = of.bottom = cf.bottom = mDockBottom;
Dianne Hackborna239c842011-06-01 12:28:20 -07004480 } else {
Dianne Hackbornc4aad012013-02-22 15:05:25 -08004481 df.left = of.left = cf.left = mContentLeft;
4482 df.top = of.top = cf.top = mContentTop;
4483 df.right = of.right = cf.right = mContentRight;
4484 df.bottom = of.bottom = cf.bottom = mContentBottom;
Dianne Hackborna239c842011-06-01 12:28:20 -07004485 }
4486 if (adjust != SOFT_INPUT_ADJUST_NOTHING) {
4487 vf.left = mCurLeft;
4488 vf.top = mCurTop;
4489 vf.right = mCurRight;
4490 vf.bottom = mCurBottom;
4491 } else {
4492 vf.set(cf);
4493 }
Dianne Hackborndea3ef72010-10-28 14:24:22 -07004494 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004495 }
4496 }
Craig Mautner69b08182012-09-05 13:07:13 -07004497
Craig Mautnerb816bed2013-07-23 10:26:17 -07004498 // TYPE_SYSTEM_ERROR is above the NavigationBar so it can't be allowed to extend over it.
4499 if ((fl & FLAG_LAYOUT_NO_LIMITS) != 0 && attrs.type != TYPE_SYSTEM_ERROR) {
Dianne Hackborn067e5f62014-09-07 23:14:30 -07004500 df.left = df.top = -10000;
4501 df.right = df.bottom = 10000;
4502 if (attrs.type != TYPE_WALLPAPER) {
4503 of.left = of.top = cf.left = cf.top = vf.left = vf.top = -10000;
4504 of.right = of.bottom = cf.right = cf.bottom = vf.right = vf.bottom = 10000;
4505 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004506 }
4507
Filip Gruszczynski2217f612015-05-26 11:32:08 -07004508 // If the device has a chin (e.g. some watches), a dead area at the bottom of the screen we
4509 // need to provide information to the clients that want to pretend that you can draw there.
Filip Gruszczynskib0c673b2015-06-05 09:43:06 -07004510 // We only want to apply outsets to certain types of windows. For example, we never want to
4511 // apply the outsets to floating dialogs, because they wouldn't make sense there.
Filip Gruszczynski2987f612015-06-30 15:03:30 -07004512 final boolean useOutsets = shouldUseOutsets(attrs, fl);
Filip Gruszczynskib0c673b2015-06-05 09:43:06 -07004513 if (isDefaultDisplay && useOutsets) {
Filip Gruszczynski2217f612015-05-26 11:32:08 -07004514 osf = mTmpOutsetFrame;
4515 osf.set(cf.left, cf.top, cf.right, cf.bottom);
4516 int outset = ScreenShapeHelper.getWindowOutsetBottomPx(mContext.getResources());
4517 if (outset > 0) {
Filip Gruszczynski2987f612015-06-30 15:03:30 -07004518 int rotation = mDisplayRotation;
Filip Gruszczynski2217f612015-05-26 11:32:08 -07004519 if (rotation == Surface.ROTATION_0) {
4520 osf.bottom += outset;
4521 } else if (rotation == Surface.ROTATION_90) {
4522 osf.right += outset;
4523 } else if (rotation == Surface.ROTATION_180) {
4524 osf.top -= outset;
4525 } else if (rotation == Surface.ROTATION_270) {
4526 osf.left -= outset;
4527 }
4528 if (DEBUG_LAYOUT) Slog.v(TAG, "applying bottom outset of " + outset
4529 + " with rotation " + rotation + ", result: " + osf);
4530 }
4531 }
4532
Craig Mautnereda67292013-04-28 13:50:14 -07004533 if (DEBUG_LAYOUT) Slog.v(TAG, "Compute frame " + attrs.getTitle()
The Android Open Source Project11267662009-03-18 17:39:47 -07004534 + ": sim=#" + Integer.toHexString(sim)
RoboErik8a2cfc32014-05-16 11:19:38 -07004535 + " attach=" + attached + " type=" + attrs.type
Daniel Sandler8956dbb2011-04-22 07:55:02 -04004536 + String.format(" flags=0x%08x", fl)
The Android Open Source Project11267662009-03-18 17:39:47 -07004537 + " pf=" + pf.toShortString() + " df=" + df.toShortString()
Dianne Hackbornc4aad012013-02-22 15:05:25 -08004538 + " of=" + of.toShortString()
John Spurlock46646232013-09-30 22:32:42 -04004539 + " cf=" + cf.toShortString() + " vf=" + vf.toShortString()
Adrian Roosfa104232014-06-20 16:10:14 -07004540 + " dcf=" + dcf.toShortString()
Filip Gruszczynski2217f612015-05-26 11:32:08 -07004541 + " sf=" + sf.toShortString()
4542 + " osf=" + (osf == null ? "null" : osf.toShortString()));
Craig Mautner69b08182012-09-05 13:07:13 -07004543
Filip Gruszczynski2217f612015-05-26 11:32:08 -07004544 win.computeFrameLw(pf, df, of, cf, vf, dcf, sf, osf);
Craig Mautner69b08182012-09-05 13:07:13 -07004545
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004546 // Dock windows carve out the bottom of the screen, so normal windows
4547 // can't appear underneath them.
Craig Mautner8bd206b2012-10-03 10:32:02 -07004548 if (attrs.type == TYPE_INPUT_METHOD && win.isVisibleOrBehindKeyguardLw()
4549 && !win.getGivenInsetsPendingLw()) {
satok1bc0a492012-04-25 22:47:12 +09004550 setLastInputMethodWindowLw(null, null);
4551 offsetInputMethodWindowLw(win);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004552 }
Dianne Hackborne30e02f2014-05-27 18:24:45 -07004553 if (attrs.type == TYPE_VOICE_INTERACTION && win.isVisibleOrBehindKeyguardLw()
4554 && !win.getGivenInsetsPendingLw()) {
4555 offsetVoiceInputWindowLw(win);
4556 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004557 }
4558
satok1bc0a492012-04-25 22:47:12 +09004559 private void offsetInputMethodWindowLw(WindowState win) {
Craig Mautner4774f6a2015-03-23 11:42:55 -07004560 int top = Math.max(win.getDisplayFrameLw().top, win.getContentFrameLw().top);
satok1bc0a492012-04-25 22:47:12 +09004561 top += win.getGivenContentInsetsLw().top;
4562 if (mContentBottom > top) {
4563 mContentBottom = top;
4564 }
Dianne Hackborne30e02f2014-05-27 18:24:45 -07004565 if (mVoiceContentBottom > top) {
4566 mVoiceContentBottom = top;
4567 }
satok1bc0a492012-04-25 22:47:12 +09004568 top = win.getVisibleFrameLw().top;
4569 top += win.getGivenVisibleInsetsLw().top;
4570 if (mCurBottom > top) {
4571 mCurBottom = top;
4572 }
Craig Mautnereda67292013-04-28 13:50:14 -07004573 if (DEBUG_LAYOUT) Slog.v(TAG, "Input method: mDockBottom="
satok1bc0a492012-04-25 22:47:12 +09004574 + mDockBottom + " mContentBottom="
4575 + mContentBottom + " mCurBottom=" + mCurBottom);
4576 }
4577
Dianne Hackborne30e02f2014-05-27 18:24:45 -07004578 private void offsetVoiceInputWindowLw(WindowState win) {
Craig Mautner4774f6a2015-03-23 11:42:55 -07004579 int top = Math.max(win.getDisplayFrameLw().top, win.getContentFrameLw().top);
Dianne Hackbornae6688b2015-02-11 17:02:41 -08004580 top += win.getGivenContentInsetsLw().top;
4581 if (mVoiceContentBottom > top) {
4582 mVoiceContentBottom = top;
Dianne Hackborne30e02f2014-05-27 18:24:45 -07004583 }
4584 }
4585
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004586 /** {@inheritDoc} */
Craig Mautner61ac6bb2012-02-02 17:29:33 -08004587 @Override
4588 public void finishLayoutLw() {
4589 return;
Dianne Hackborn5f3063e2010-03-10 16:01:58 -08004590 }
4591
4592 /** {@inheritDoc} */
Craig Mautnerad09bcc2012-10-08 13:33:11 -07004593 @Override
Craig Mautner39834192012-09-02 07:47:24 -07004594 public void beginPostLayoutPolicyLw(int displayWidth, int displayHeight) {
Dianne Hackborn5f3063e2010-03-10 16:01:58 -08004595 mTopFullscreenOpaqueWindowState = null;
Adrian Rooscd3884d2015-02-18 17:25:23 +01004596 mTopFullscreenOpaqueOrDimmingWindowState = null;
Jorim Jaggi86905582016-02-09 21:36:09 -08004597 mTopDockedOpaqueWindowState = null;
4598 mTopDockedOpaqueOrDimmingWindowState = null;
Craig Mautner2bc789b2014-03-19 19:48:38 -07004599 mAppsToBeHidden.clear();
Jorim Jaggic13fcac2014-09-11 17:36:57 +02004600 mAppsThatDismissKeyguard.clear();
Dianne Hackborn5f3063e2010-03-10 16:01:58 -08004601 mForceStatusBar = false;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07004602 mForceStatusBarFromKeyguard = false;
Selim Cinek4a4a2bddc2015-05-07 12:50:19 -07004603 mForceStatusBarTransparent = false;
Dianne Hackborn891d3fb2013-01-09 18:31:37 -08004604 mForcingShowNavBar = false;
4605 mForcingShowNavBarLayer = -1;
RoboErik8a2cfc32014-05-16 11:19:38 -07004606
Dianne Hackborn5f3063e2010-03-10 16:01:58 -08004607 mHideLockScreen = false;
4608 mAllowLockscreenWhenOn = false;
Craig Mautnerad09bcc2012-10-08 13:33:11 -07004609 mDismissKeyguard = DISMISS_KEYGUARD_NONE;
Dianne Hackborn7ad44382012-10-18 17:46:00 -07004610 mShowingLockscreen = false;
4611 mShowingDream = false;
Craig Mautnerc9457fa2014-06-06 14:27:48 -07004612 mWinShowWhenLocked = null;
Jim Millerab954542014-10-10 18:21:49 -07004613 mKeyguardSecure = isKeyguardSecure();
4614 mKeyguardSecureIncludingHidden = mKeyguardSecure
4615 && (mKeyguardDelegate != null && mKeyguardDelegate.isShowing());
Dianne Hackborn5f3063e2010-03-10 16:01:58 -08004616 }
4617
4618 /** {@inheritDoc} */
Craig Mautnerad09bcc2012-10-08 13:33:11 -07004619 @Override
Yohei Yukawad1a09222015-06-30 16:22:05 -07004620 public void applyPostLayoutPolicyLw(WindowState win, WindowManager.LayoutParams attrs,
4621 WindowState attached) {
Dianne Hackbornbc1aa7b2011-09-20 11:20:31 -07004622 if (DEBUG_LAYOUT) Slog.i(TAG, "Win " + win + ": isVisibleOrBehindKeyguardLw="
4623 + win.isVisibleOrBehindKeyguardLw());
John Spurlockc6d1c602014-01-17 15:22:06 -05004624 final int fl = PolicyControl.getWindowFlags(win, attrs);
John Spurlock414c1f02013-12-04 13:47:36 -05004625 if (mTopFullscreenOpaqueWindowState == null
4626 && win.isVisibleLw() && attrs.type == TYPE_INPUT_METHOD) {
4627 mForcingShowNavBar = true;
4628 mForcingShowNavBarLayer = win.getSurfaceLayer();
Dianne Hackborn891d3fb2013-01-09 18:31:37 -08004629 }
Selim Cinek4a4a2bddc2015-05-07 12:50:19 -07004630 if (attrs.type == TYPE_STATUS_BAR) {
4631 if ((attrs.privateFlags & PRIVATE_FLAG_KEYGUARD) != 0) {
4632 mForceStatusBarFromKeyguard = true;
Jorim Jaggie1de9f62015-09-23 14:59:50 -07004633 mShowingLockscreen = true;
Selim Cinek4a4a2bddc2015-05-07 12:50:19 -07004634 }
4635 if ((attrs.privateFlags & PRIVATE_FLAG_FORCE_STATUS_BAR_VISIBLE_TRANSPARENT) != 0) {
4636 mForceStatusBarTransparent = true;
4637 }
Jorim Jaggiafd4a552014-04-08 15:13:05 +02004638 }
Adrian Roos602c68e2015-04-24 16:03:47 -07004639
4640 boolean appWindow = attrs.type >= FIRST_APPLICATION_WINDOW
4641 && attrs.type < FIRST_SYSTEM_WINDOW;
4642 final boolean showWhenLocked = (fl & FLAG_SHOW_WHEN_LOCKED) != 0;
4643 final boolean dismissKeyguard = (fl & FLAG_DISMISS_KEYGUARD) != 0;
Jorim Jaggi86905582016-02-09 21:36:09 -08004644 final int stackId = win.getStackId();
Dianne Hackborn5f3063e2010-03-10 16:01:58 -08004645 if (mTopFullscreenOpaqueWindowState == null &&
Dianne Hackborn01b02a72012-01-12 14:05:03 -08004646 win.isVisibleOrBehindKeyguardLw() && !win.isGoneForLayoutLw()) {
John Spurlockc6d1c602014-01-17 15:22:06 -05004647 if ((fl & FLAG_FORCE_NOT_FULLSCREEN) != 0) {
Jorim Jaggi380ecb82014-03-14 17:25:20 +01004648 if ((attrs.privateFlags & PRIVATE_FLAG_KEYGUARD) != 0) {
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07004649 mForceStatusBarFromKeyguard = true;
4650 } else {
4651 mForceStatusBar = true;
4652 }
4653 }
Dianne Hackborn7ad44382012-10-18 17:46:00 -07004654 if (attrs.type == TYPE_DREAM) {
Jeff Brownc8018eb2012-10-29 21:33:27 -07004655 // If the lockscreen was showing when the dream started then wait
4656 // for the dream to draw before hiding the lockscreen.
4657 if (!mDreamingLockscreen
4658 || (win.isVisibleLw() && win.hasDrawnLw())) {
4659 mShowingDream = true;
Craig Mautnerab55e522014-03-03 13:26:03 -08004660 appWindow = true;
Dianne Hackborn7ad44382012-10-18 17:46:00 -07004661 }
4662 }
Craig Mautnerab55e522014-03-03 13:26:03 -08004663
Yohei Yukawad1a09222015-06-30 16:22:05 -07004664 final IApplicationToken appToken = win.getAppToken();
4665
4666 // For app windows that are not attached, we decide if all windows in the app they
4667 // represent should be hidden or if we should hide the lockscreen. For attached app
4668 // windows we defer the decision to the window it is attached to.
4669 if (appWindow && attached == null) {
Jorim Jaggic13fcac2014-09-11 17:36:57 +02004670 if (showWhenLocked) {
Craig Mautnerc9457fa2014-06-06 14:27:48 -07004671 // Remove any previous windows with the same appToken.
Jorim Jaggic13fcac2014-09-11 17:36:57 +02004672 mAppsToBeHidden.remove(appToken);
4673 mAppsThatDismissKeyguard.remove(appToken);
Craig Mautnerca0a1242014-12-02 12:25:14 -08004674 if (mAppsToBeHidden.isEmpty()) {
Craig Mautner192d6042014-12-02 23:24:48 -08004675 if (dismissKeyguard && !mKeyguardSecure) {
4676 mAppsThatDismissKeyguard.add(appToken);
Selim Cinek90b5e072015-08-28 17:05:56 -07004677 } else if (win.isDrawnLw() || win.hasAppShownWindows()) {
Craig Mautnerca0a1242014-12-02 12:25:14 -08004678 mWinShowWhenLocked = win;
4679 mHideLockScreen = true;
4680 mForceStatusBarFromKeyguard = false;
Craig Mautnerca0a1242014-12-02 12:25:14 -08004681 }
Craig Mautnerc9457fa2014-06-06 14:27:48 -07004682 }
Jorim Jaggic13fcac2014-09-11 17:36:57 +02004683 } else if (dismissKeyguard) {
Jim Millerab954542014-10-10 18:21:49 -07004684 if (mKeyguardSecure) {
Jorim Jaggic13fcac2014-09-11 17:36:57 +02004685 mAppsToBeHidden.add(appToken);
4686 } else {
4687 mAppsToBeHidden.remove(appToken);
4688 }
4689 mAppsThatDismissKeyguard.add(appToken);
Craig Mautner2bc789b2014-03-19 19:48:38 -07004690 } else {
Jorim Jaggic13fcac2014-09-11 17:36:57 +02004691 mAppsToBeHidden.add(appToken);
Craig Mautner2bc789b2014-03-19 19:48:38 -07004692 }
Jorim Jaggi86905582016-02-09 21:36:09 -08004693 if (isFullscreen(attrs) && StackId.normallyFullscreenWindows(stackId)) {
Craig Mautnerab55e522014-03-03 13:26:03 -08004694 if (DEBUG_LAYOUT) Slog.v(TAG, "Fullscreen window: " + win);
4695 mTopFullscreenOpaqueWindowState = win;
Adrian Rooscd3884d2015-02-18 17:25:23 +01004696 if (mTopFullscreenOpaqueOrDimmingWindowState == null) {
4697 mTopFullscreenOpaqueOrDimmingWindowState = win;
4698 }
Jorim Jaggic13fcac2014-09-11 17:36:57 +02004699 if (!mAppsThatDismissKeyguard.isEmpty() &&
4700 mDismissKeyguard == DISMISS_KEYGUARD_NONE) {
4701 if (DEBUG_LAYOUT) Slog.v(TAG,
4702 "Setting mDismissKeyguard true by win " + win);
tingna_sunge785ffa2015-05-12 13:23:15 +08004703 mDismissKeyguard = (mWinDismissingKeyguard == win
4704 && mSecureDismissingKeyguard == mKeyguardSecure)
4705 ? DISMISS_KEYGUARD_CONTINUE : DISMISS_KEYGUARD_START;
Jorim Jaggic13fcac2014-09-11 17:36:57 +02004706 mWinDismissingKeyguard = win;
tingna_sunge785ffa2015-05-12 13:23:15 +08004707 mSecureDismissingKeyguard = mKeyguardSecure;
Jim Millerab954542014-10-10 18:21:49 -07004708 mForceStatusBarFromKeyguard = mShowingLockscreen && mKeyguardSecure;
Selim Cinek90b5e072015-08-28 17:05:56 -07004709 } else if (mAppsToBeHidden.isEmpty() && showWhenLocked
4710 && (win.isDrawnLw() || win.hasAppShownWindows())) {
Jorim Jaggic13fcac2014-09-11 17:36:57 +02004711 if (DEBUG_LAYOUT) Slog.v(TAG,
4712 "Setting mHideLockScreen to true by win " + win);
4713 mHideLockScreen = true;
4714 mForceStatusBarFromKeyguard = false;
Craig Mautnerab55e522014-03-03 13:26:03 -08004715 }
Craig Mautner00156ec2014-03-06 22:29:02 -08004716 if ((fl & FLAG_ALLOW_LOCK_WHILE_SCREEN_ON) != 0) {
Craig Mautnerab55e522014-03-03 13:26:03 -08004717 mAllowLockscreenWhenOn = true;
4718 }
Dianne Hackborn5f3063e2010-03-10 16:01:58 -08004719 }
Craig Mautnerc9457fa2014-06-06 14:27:48 -07004720
4721 if (mWinShowWhenLocked != null &&
Adrian Roos602c68e2015-04-24 16:03:47 -07004722 mWinShowWhenLocked.getAppToken() != win.getAppToken() &&
4723 (attrs.flags & FLAG_SHOW_WHEN_LOCKED) == 0) {
Craig Mautnerc9457fa2014-06-06 14:27:48 -07004724 win.hideLw(false);
4725 }
Dianne Hackborn5f3063e2010-03-10 16:01:58 -08004726 }
Adrian Roos602c68e2015-04-24 16:03:47 -07004727 } else if (mTopFullscreenOpaqueWindowState == null && mWinShowWhenLocked == null) {
4728 // No TopFullscreenOpaqueWindow is showing, but we found a SHOW_WHEN_LOCKED window
4729 // that is being hidden in an animation - keep the
4730 // keyguard hidden until the new window shows up and
4731 // we know whether to show the keyguard or not.
Adrian Roosb85e1ec2015-05-29 15:23:18 -07004732 if (win.isAnimatingLw() && appWindow && showWhenLocked && mKeyguardHidden) {
Adrian Roos602c68e2015-04-24 16:03:47 -07004733 mHideLockScreen = true;
4734 mWinShowWhenLocked = win;
4735 }
Dianne Hackborn5f3063e2010-03-10 16:01:58 -08004736 }
Jorim Jaggi86905582016-02-09 21:36:09 -08004737
4738 // Keep track of the window if it's dimming but not necessarily fullscreen.
4739 final boolean reallyVisible = win.isVisibleOrBehindKeyguardLw() && !win.isGoneForLayoutLw();
4740 if (mTopFullscreenOpaqueOrDimmingWindowState == null && reallyVisible
4741 && win.isDimming() && StackId.normallyFullscreenWindows(stackId)) {
Adrian Rooscd3884d2015-02-18 17:25:23 +01004742 mTopFullscreenOpaqueOrDimmingWindowState = win;
4743 }
Jorim Jaggi86905582016-02-09 21:36:09 -08004744
4745 // We need to keep track of the top "fullscreen" opaque window for the docked stack
4746 // separately, because both the "real fullscreen" opaque window and the one for the docked
4747 // stack can control View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR.
4748 if (mTopDockedOpaqueWindowState == null && reallyVisible && appWindow && attached == null
4749 && isFullscreen(attrs) && stackId == DOCKED_STACK_ID) {
4750 mTopDockedOpaqueWindowState = win;
4751 if (mTopDockedOpaqueOrDimmingWindowState == null) {
4752 mTopDockedOpaqueOrDimmingWindowState = win;
4753 }
4754 }
4755
4756 // Also keep track of any windows that are dimming but not necessarily fullscreen in the
4757 // docked stack.
4758 if (mTopDockedOpaqueOrDimmingWindowState == null && reallyVisible && win.isDimming()
4759 && stackId == DOCKED_STACK_ID) {
4760 mTopDockedOpaqueOrDimmingWindowState = win;
4761 }
4762 }
4763
4764 private boolean isFullscreen(WindowManager.LayoutParams attrs) {
4765 return attrs.x == 0 && attrs.y == 0
4766 && attrs.width == WindowManager.LayoutParams.MATCH_PARENT
4767 && attrs.height == WindowManager.LayoutParams.MATCH_PARENT;
Dianne Hackborn5f3063e2010-03-10 16:01:58 -08004768 }
4769
4770 /** {@inheritDoc} */
Craig Mautnerad09bcc2012-10-08 13:33:11 -07004771 @Override
Craig Mautner39834192012-09-02 07:47:24 -07004772 public int finishPostLayoutPolicyLw() {
Craig Mautnerc5e73bf2015-04-21 15:41:26 +00004773 if (mWinShowWhenLocked != null && mTopFullscreenOpaqueWindowState != null &&
4774 mWinShowWhenLocked.getAppToken() != mTopFullscreenOpaqueWindowState.getAppToken()
4775 && isKeyguardLocked()) {
Craig Mautnerc9457fa2014-06-06 14:27:48 -07004776 // A dialog is dismissing the keyguard. Put the wallpaper behind it and hide the
4777 // fullscreen window.
4778 // TODO: Make sure FLAG_SHOW_WALLPAPER is restored when dialog is dismissed. Or not.
4779 mWinShowWhenLocked.getAttrs().flags |= FLAG_SHOW_WALLPAPER;
4780 mTopFullscreenOpaqueWindowState.hideLw(false);
4781 mTopFullscreenOpaqueWindowState = mWinShowWhenLocked;
4782 }
4783
Dianne Hackborn39c2d712009-09-22 11:41:31 -07004784 int changes = 0;
Joe Onorato93056472010-09-10 10:30:46 -04004785 boolean topIsFullscreen = false;
Daniel Sandlere02d8082010-10-08 15:13:22 -04004786
4787 final WindowManager.LayoutParams lp = (mTopFullscreenOpaqueWindowState != null)
4788 ? mTopFullscreenOpaqueWindowState.getAttrs()
4789 : null;
4790
Jeff Brownc8018eb2012-10-29 21:33:27 -07004791 // If we are not currently showing a dream then remember the current
4792 // lockscreen state. We will use this to determine whether the dream
4793 // started while the lockscreen was showing and remember this state
4794 // while the dream is showing.
Dianne Hackborn7ad44382012-10-18 17:46:00 -07004795 if (!mShowingDream) {
4796 mDreamingLockscreen = mShowingLockscreen;
Jeff Brown061ea992015-04-17 19:55:47 -07004797 if (mDreamingSleepTokenNeeded) {
4798 mDreamingSleepTokenNeeded = false;
4799 mHandler.obtainMessage(MSG_UPDATE_DREAMING_SLEEP_TOKEN, 0, 1).sendToTarget();
4800 }
4801 } else {
4802 if (!mDreamingSleepTokenNeeded) {
4803 mDreamingSleepTokenNeeded = true;
4804 mHandler.obtainMessage(MSG_UPDATE_DREAMING_SLEEP_TOKEN, 1, 1).sendToTarget();
4805 }
Dianne Hackborn7ad44382012-10-18 17:46:00 -07004806 }
4807
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004808 if (mStatusBar != null) {
Craig Mautnereda67292013-04-28 13:50:14 -07004809 if (DEBUG_LAYOUT) Slog.i(TAG, "force=" + mForceStatusBar
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07004810 + " forcefkg=" + mForceStatusBarFromKeyguard
Dianne Hackbornd70bc2f2009-10-06 23:25:51 -07004811 + " top=" + mTopFullscreenOpaqueWindowState);
Selim Cinek4a4a2bddc2015-05-07 12:50:19 -07004812 boolean shouldBeTransparent = mForceStatusBarTransparent
4813 && !mForceStatusBar
4814 && !mForceStatusBarFromKeyguard;
4815 if (!shouldBeTransparent) {
4816 mStatusBarController.setShowTransparent(false /* transparent */);
4817 } else if (!mStatusBar.isVisibleLw()) {
4818 mStatusBarController.setShowTransparent(true /* transparent */);
4819 }
4820 if (mForceStatusBar || mForceStatusBarFromKeyguard || mForceStatusBarTransparent) {
Craig Mautnereda67292013-04-28 13:50:14 -07004821 if (DEBUG_LAYOUT) Slog.v(TAG, "Showing status bar: forced");
John Spurlock27735a42013-08-14 17:57:38 -04004822 if (mStatusBarController.setBarShowingLw(true)) {
4823 changes |= FINISH_LAYOUT_REDO_LAYOUT;
4824 }
Craig Mautner81defc72013-10-29 11:10:42 -07004825 // Maintain fullscreen layout until incoming animation is complete.
4826 topIsFullscreen = mTopIsFullscreen && mStatusBar.isAnimatingLw();
John Spurlockf92b6162013-11-11 15:01:16 -05004827 // Transient status bar on the lockscreen is not allowed
4828 if (mForceStatusBarFromKeyguard && mStatusBarController.isTransientShowing()) {
4829 mStatusBarController.updateVisibilityLw(false /*transientAllowed*/,
4830 mLastSystemUiFlags, mLastSystemUiFlags);
4831 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004832 } else if (mTopFullscreenOpaqueWindowState != null) {
John Spurlockc6d1c602014-01-17 15:22:06 -05004833 final int fl = PolicyControl.getWindowFlags(null, lp);
Joe Onorato93056472010-09-10 10:30:46 -04004834 if (localLOGV) {
Craig Mautnereda67292013-04-28 13:50:14 -07004835 Slog.d(TAG, "frame: " + mTopFullscreenOpaqueWindowState.getFrameLw()
Filip Gruszczynski2a6a2c22015-10-14 12:00:53 -07004836 + " shown position: "
4837 + mTopFullscreenOpaqueWindowState.getShownPositionLw());
Craig Mautnereda67292013-04-28 13:50:14 -07004838 Slog.d(TAG, "attr: " + mTopFullscreenOpaqueWindowState.getAttrs()
John Spurlockc6d1c602014-01-17 15:22:06 -05004839 + " lp.flags=0x" + Integer.toHexString(fl));
Joe Onorato93056472010-09-10 10:30:46 -04004840 }
John Spurlockc6d1c602014-01-17 15:22:06 -05004841 topIsFullscreen = (fl & WindowManager.LayoutParams.FLAG_FULLSCREEN) != 0
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07004842 || (mLastSystemUiFlags & View.SYSTEM_UI_FLAG_FULLSCREEN) != 0;
Joe Onorato93056472010-09-10 10:30:46 -04004843 // The subtle difference between the window for mTopFullscreenOpaqueWindowState
Mark Dolinerd0646dc2014-08-27 16:04:02 -07004844 // and mTopIsFullscreen is that mTopIsFullscreen is set only if the window
Joe Onorato93056472010-09-10 10:30:46 -04004845 // has the FLAG_FULLSCREEN set. Not sure if there is another way that to be the
4846 // case though.
John Spurlock27735a42013-08-14 17:57:38 -04004847 if (mStatusBarController.isTransientShowing()) {
4848 if (mStatusBarController.setBarShowingLw(true)) {
John Spurlock32beb2c2013-03-11 10:16:47 -04004849 changes |= FINISH_LAYOUT_REDO_LAYOUT;
4850 }
Wale Ogunwale6e94a9e2015-10-07 15:35:49 -07004851 } else if (topIsFullscreen
4852 && !mWindowManagerInternal.isStackVisible(FREEFORM_WORKSPACE_STACK_ID)
4853 && !mWindowManagerInternal.isStackVisible(DOCKED_STACK_ID)) {
Craig Mautnereda67292013-04-28 13:50:14 -07004854 if (DEBUG_LAYOUT) Slog.v(TAG, "** HIDING status bar");
John Spurlock27735a42013-08-14 17:57:38 -04004855 if (mStatusBarController.setBarShowingLw(false)) {
Dianne Hackbornf87d1962012-04-04 12:48:24 -07004856 changes |= FINISH_LAYOUT_REDO_LAYOUT;
Craig Mautnereda67292013-04-28 13:50:14 -07004857 } else {
Craig Mautnerc5a6e442013-06-05 17:22:35 -07004858 if (DEBUG_LAYOUT) Slog.v(TAG, "Status bar already hiding");
Daniel Sandler40427442010-07-16 11:44:52 -04004859 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004860 } else {
Craig Mautnereda67292013-04-28 13:50:14 -07004861 if (DEBUG_LAYOUT) Slog.v(TAG, "** SHOWING status bar: top is not fullscreen");
John Spurlock27735a42013-08-14 17:57:38 -04004862 if (mStatusBarController.setBarShowingLw(true)) {
4863 changes |= FINISH_LAYOUT_REDO_LAYOUT;
4864 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004865 }
4866 }
4867 }
Daniel Sandlere02d8082010-10-08 15:13:22 -04004868
Craig Mautner81defc72013-10-29 11:10:42 -07004869 if (mTopIsFullscreen != topIsFullscreen) {
4870 if (!topIsFullscreen) {
4871 // Force another layout when status bar becomes fully shown.
4872 changes |= FINISH_LAYOUT_REDO_LAYOUT;
4873 }
4874 mTopIsFullscreen = topIsFullscreen;
4875 }
Daniel Sandlere02d8082010-10-08 15:13:22 -04004876
Craig Mautner39834192012-09-02 07:47:24 -07004877 // Hide the key guard if a visible window explicitly specifies that it wants to be
4878 // displayed when the screen is locked.
Jorim Jaggi5cf17872014-03-26 18:31:48 +01004879 if (mKeyguardDelegate != null && mStatusBar != null) {
4880 if (localLOGV) Slog.v(TAG, "finishPostLayoutPolicyLw: mHideKeyguard="
4881 + mHideLockScreen);
Jim Millerab954542014-10-10 18:21:49 -07004882 if (mDismissKeyguard != DISMISS_KEYGUARD_NONE && !mKeyguardSecure) {
Jorim Jaggi5cf17872014-03-26 18:31:48 +01004883 mKeyguardHidden = true;
Jim Millerab954542014-10-10 18:21:49 -07004884 if (setKeyguardOccludedLw(true)) {
Dianne Hackborn39c2d712009-09-22 11:41:31 -07004885 changes |= FINISH_LAYOUT_REDO_LAYOUT
4886 | FINISH_LAYOUT_REDO_CONFIG
4887 | FINISH_LAYOUT_REDO_WALLPAPER;
4888 }
Jorim Jaggi5cf17872014-03-26 18:31:48 +01004889 if (mKeyguardDelegate.isShowing()) {
4890 mHandler.post(new Runnable() {
4891 @Override
4892 public void run() {
4893 mKeyguardDelegate.keyguardDone(false, false);
4894 }
4895 });
4896 }
4897 } else if (mHideLockScreen) {
4898 mKeyguardHidden = true;
Jorim Jaggi7d85ea92015-05-20 17:20:40 -07004899 mWinDismissingKeyguard = null;
Jim Millerab954542014-10-10 18:21:49 -07004900 if (setKeyguardOccludedLw(true)) {
Jorim Jaggi5cf17872014-03-26 18:31:48 +01004901 changes |= FINISH_LAYOUT_REDO_LAYOUT
4902 | FINISH_LAYOUT_REDO_CONFIG
4903 | FINISH_LAYOUT_REDO_WALLPAPER;
4904 }
4905 } else if (mDismissKeyguard != DISMISS_KEYGUARD_NONE) {
Jorim Jaggi7d85ea92015-05-20 17:20:40 -07004906 mKeyguardHidden = false;
4907 if (setKeyguardOccludedLw(false)) {
4908 changes |= FINISH_LAYOUT_REDO_LAYOUT
4909 | FINISH_LAYOUT_REDO_CONFIG
4910 | FINISH_LAYOUT_REDO_WALLPAPER;
4911 }
Jorim Jaggi5cf17872014-03-26 18:31:48 +01004912 if (mDismissKeyguard == DISMISS_KEYGUARD_START) {
4913 // Only launch the next keyguard unlock window once per window.
Jorim Jaggi5cf17872014-03-26 18:31:48 +01004914 mHandler.post(new Runnable() {
4915 @Override
4916 public void run() {
4917 mKeyguardDelegate.dismiss();
4918 }
4919 });
4920 }
4921 } else {
4922 mWinDismissingKeyguard = null;
tingna_sunge785ffa2015-05-12 13:23:15 +08004923 mSecureDismissingKeyguard = false;
Jorim Jaggi5cf17872014-03-26 18:31:48 +01004924 mKeyguardHidden = false;
Jim Millerab954542014-10-10 18:21:49 -07004925 if (setKeyguardOccludedLw(false)) {
Jorim Jaggi5cf17872014-03-26 18:31:48 +01004926 changes |= FINISH_LAYOUT_REDO_LAYOUT
4927 | FINISH_LAYOUT_REDO_CONFIG
4928 | FINISH_LAYOUT_REDO_WALLPAPER;
4929 }
Suchi Amalapurapu9cdc9032009-05-14 18:01:07 -07004930 }
4931 }
Joe Onorato664644d2011-01-23 17:53:23 -08004932
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07004933 if ((updateSystemUiVisibilityLw()&SYSTEM_UI_CHANGING_LAYOUT) != 0) {
Dianne Hackborndf89e652011-10-06 22:35:11 -07004934 // If the navigation bar has been hidden or shown, we need to do another
4935 // layout pass to update that window.
4936 changes |= FINISH_LAYOUT_REDO_LAYOUT;
4937 }
Joe Onorato664644d2011-01-23 17:53:23 -08004938
Mike Lockwood28569302010-01-28 11:54:40 -05004939 // update since mAllowLockscreenWhenOn might have changed
4940 updateLockScreenTimeout();
Dianne Hackborn39c2d712009-09-22 11:41:31 -07004941 return changes;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004942 }
4943
Jorim Jaggi380ecb82014-03-14 17:25:20 +01004944 /**
Jim Millerab954542014-10-10 18:21:49 -07004945 * Updates the occluded state of the Keyguard.
Jorim Jaggi380ecb82014-03-14 17:25:20 +01004946 *
Jorim Jaggi380ecb82014-03-14 17:25:20 +01004947 * @return Whether the flags have changed and we have to redo the layout.
4948 */
Jim Millerab954542014-10-10 18:21:49 -07004949 private boolean setKeyguardOccludedLw(boolean isOccluded) {
4950 boolean wasOccluded = mKeyguardOccluded;
4951 boolean showing = mKeyguardDelegate.isShowing();
4952 if (wasOccluded && !isOccluded && showing) {
4953 mKeyguardOccluded = false;
4954 mKeyguardDelegate.setOccluded(false);
Jorim Jaggi380ecb82014-03-14 17:25:20 +01004955 mStatusBar.getAttrs().privateFlags |= PRIVATE_FLAG_KEYGUARD;
4956 mStatusBar.getAttrs().flags |= FLAG_SHOW_WALLPAPER;
4957 return true;
Jim Millerab954542014-10-10 18:21:49 -07004958 } else if (!wasOccluded && isOccluded && showing) {
4959 mKeyguardOccluded = true;
4960 mKeyguardDelegate.setOccluded(true);
Jorim Jaggi380ecb82014-03-14 17:25:20 +01004961 mStatusBar.getAttrs().privateFlags &= ~PRIVATE_FLAG_KEYGUARD;
4962 mStatusBar.getAttrs().flags &= ~FLAG_SHOW_WALLPAPER;
4963 return true;
4964 } else {
4965 return false;
4966 }
4967 }
4968
4969 private boolean isStatusBarKeyguard() {
4970 return mStatusBar != null
4971 && (mStatusBar.getAttrs().privateFlags & PRIVATE_FLAG_KEYGUARD) != 0;
4972 }
4973
Jose Lima9546b202014-07-02 17:21:51 -07004974 @Override
Dianne Hackborn08743722009-12-21 12:16:51 -08004975 public boolean allowAppAnimationsLw() {
Jorim Jaggi380ecb82014-03-14 17:25:20 +01004976 if (isStatusBarKeyguard() || mShowingDream) {
Craig Mautner28816302013-10-10 20:31:00 -07004977 // If keyguard or dreams is currently visible, no reason to animate behind it.
Dianne Hackborn08743722009-12-21 12:16:51 -08004978 return false;
4979 }
Dianne Hackborn08743722009-12-21 12:16:51 -08004980 return true;
4981 }
4982
Jose Lima9546b202014-07-02 17:21:51 -07004983 @Override
Dianne Hackborndf89e652011-10-06 22:35:11 -07004984 public int focusChangedLw(WindowState lastFocus, WindowState newFocus) {
Joe Onorato664644d2011-01-23 17:53:23 -08004985 mFocusedWindow = newFocus;
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07004986 if ((updateSystemUiVisibilityLw()&SYSTEM_UI_CHANGING_LAYOUT) != 0) {
Dianne Hackborndf89e652011-10-06 22:35:11 -07004987 // If the navigation bar has been hidden or shown, we need to do another
4988 // layout pass to update that window.
4989 return FINISH_LAYOUT_REDO_LAYOUT;
4990 }
4991 return 0;
Joe Onorato664644d2011-01-23 17:53:23 -08004992 }
4993
Dianne Hackborn0ecadf72009-03-31 18:00:37 -07004994 /** {@inheritDoc} */
Jose Lima9546b202014-07-02 17:21:51 -07004995 @Override
Jeff Brown46b9ac02010-04-22 18:58:52 -07004996 public void notifyLidSwitchChanged(long whenNanos, boolean lidOpen) {
4997 // lid changed state
Jeff Brownc458ce92012-04-30 14:58:40 -07004998 final int newLidState = lidOpen ? LID_OPEN : LID_CLOSED;
4999 if (newLidState == mLidState) {
5000 return;
5001 }
Jeff Brown01a98dd2011-09-20 15:08:29 -07005002
Jeff Brownc458ce92012-04-30 14:58:40 -07005003 mLidState = newLidState;
5004 applyLidSwitchState();
Jeff Brown01a98dd2011-09-20 15:08:29 -07005005 updateRotation(true);
Jeff Brownc458ce92012-04-30 14:58:40 -07005006
5007 if (lidOpen) {
Dianne Hackborn280a64e2015-07-13 14:48:08 -07005008 wakeUp(SystemClock.uptimeMillis(), mAllowTheaterModeWakeFromLidSwitch,
5009 "android.policy:LID");
Jeff Brownc458ce92012-04-30 14:58:40 -07005010 } else if (!mLidControlsSleep) {
Jeff Brown96307042012-07-27 15:51:34 -07005011 mPowerManager.userActivity(SystemClock.uptimeMillis(), false);
Jeff Brown46b9ac02010-04-22 18:58:52 -07005012 }
5013 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005014
Michael Wright3818c922014-09-02 13:59:07 -07005015 @Override
5016 public void notifyCameraLensCoverSwitchChanged(long whenNanos, boolean lensCovered) {
5017 int lensCoverState = lensCovered ? CAMERA_LENS_COVERED : CAMERA_LENS_UNCOVERED;
5018 if (mCameraLensCoverState == lensCoverState) {
5019 return;
5020 }
5021 if (mCameraLensCoverState == CAMERA_LENS_COVERED &&
5022 lensCoverState == CAMERA_LENS_UNCOVERED) {
5023 Intent intent;
5024 final boolean keyguardActive = mKeyguardDelegate == null ? false :
5025 mKeyguardDelegate.isShowing();
5026 if (keyguardActive) {
5027 intent = new Intent(MediaStore.INTENT_ACTION_STILL_IMAGE_CAMERA_SECURE);
5028 } else {
5029 intent = new Intent(MediaStore.INTENT_ACTION_STILL_IMAGE_CAMERA);
5030 }
Dianne Hackborn280a64e2015-07-13 14:48:08 -07005031 wakeUp(whenNanos / 1000000, mAllowTheaterModeWakeFromCameraLens,
5032 "android.policy:CAMERA_COVER");
Bart Sears8b1c27c2015-03-18 23:51:02 +00005033 startActivityAsUser(intent, UserHandle.CURRENT_OR_SELF);
Michael Wright3818c922014-09-02 13:59:07 -07005034 }
5035 mCameraLensCoverState = lensCoverState;
5036 }
5037
Dianne Hackbornad7fa7f2011-01-07 14:06:50 -08005038 void setHdmiPlugged(boolean plugged) {
5039 if (mHdmiPlugged != plugged) {
5040 mHdmiPlugged = plugged;
Dianne Hackbornf87d1962012-04-04 12:48:24 -07005041 updateRotation(true, true);
Dianne Hackbornad7fa7f2011-01-07 14:06:50 -08005042 Intent intent = new Intent(ACTION_HDMI_PLUGGED);
Joe Onoratodc100302011-01-11 17:07:41 -08005043 intent.addFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY_BEFORE_BOOT);
Dianne Hackbornad7fa7f2011-01-07 14:06:50 -08005044 intent.putExtra(EXTRA_HDMI_PLUGGED_STATE, plugged);
Dianne Hackborn5ac72a22012-08-29 18:32:08 -07005045 mContext.sendStickyBroadcastAsUser(intent, UserHandle.ALL);
Dianne Hackbornad7fa7f2011-01-07 14:06:50 -08005046 }
5047 }
5048
Joe Onoratoea495d42011-04-06 11:41:11 -07005049 void initializeHdmiState() {
Joe Onorato7ba631f2011-05-04 15:28:00 -07005050 boolean plugged = false;
Joe Onoratoea495d42011-04-06 11:41:11 -07005051 // watch for HDMI plug messages if the hdmi switch exists
5052 if (new File("/sys/devices/virtual/switch/hdmi/state").exists()) {
5053 mHDMIObserver.startObserving("DEVPATH=/devices/virtual/switch/hdmi");
5054
Joe Onoratoea495d42011-04-06 11:41:11 -07005055 final String filename = "/sys/class/switch/hdmi/state";
5056 FileReader reader = null;
5057 try {
5058 reader = new FileReader(filename);
5059 char[] buf = new char[15];
5060 int n = reader.read(buf);
5061 if (n > 1) {
5062 plugged = 0 != Integer.parseInt(new String(buf, 0, n-1));
5063 }
5064 } catch (IOException ex) {
5065 Slog.w(TAG, "Couldn't read hdmi state from " + filename + ": " + ex);
5066 } catch (NumberFormatException ex) {
5067 Slog.w(TAG, "Couldn't read hdmi state from " + filename + ": " + ex);
5068 } finally {
5069 if (reader != null) {
5070 try {
5071 reader.close();
5072 } catch (IOException ex) {
5073 }
Joe Onoratodc100302011-01-11 17:07:41 -08005074 }
5075 }
5076 }
Joe Onorato7ba631f2011-05-04 15:28:00 -07005077 // This dance forces the code in setHdmiPlugged to run.
5078 // Always do this so the sticky intent is stuck (to false) if there is no hdmi.
5079 mHdmiPlugged = !plugged;
5080 setHdmiPlugged(!mHdmiPlugged);
Joe Onoratodc100302011-01-11 17:07:41 -08005081 }
5082
Dianne Hackbornc0e3f242011-08-19 14:19:10 -07005083 final Object mScreenshotLock = new Object();
Dianne Hackbornfc8fa632011-08-17 16:20:47 -07005084 ServiceConnection mScreenshotConnection = null;
Dianne Hackbornfc8fa632011-08-17 16:20:47 -07005085
Jeff Brownd5bb82d2011-10-12 13:57:59 -07005086 final Runnable mScreenshotTimeout = new Runnable() {
5087 @Override public void run() {
5088 synchronized (mScreenshotLock) {
5089 if (mScreenshotConnection != null) {
5090 mContext.unbindService(mScreenshotConnection);
5091 mScreenshotConnection = null;
Dianne Hackbornfc8fa632011-08-17 16:20:47 -07005092 }
Winson Chung9112ec32011-06-27 13:15:32 -07005093 }
Jeff Brownd5bb82d2011-10-12 13:57:59 -07005094 }
5095 };
5096
5097 // Assume this is called from the Handler thread.
5098 private void takeScreenshot() {
5099 synchronized (mScreenshotLock) {
5100 if (mScreenshotConnection != null) {
5101 return;
5102 }
5103 ComponentName cn = new ComponentName("com.android.systemui",
5104 "com.android.systemui.screenshot.TakeScreenshotService");
5105 Intent intent = new Intent();
5106 intent.setComponent(cn);
5107 ServiceConnection conn = new ServiceConnection() {
5108 @Override
5109 public void onServiceConnected(ComponentName name, IBinder service) {
5110 synchronized (mScreenshotLock) {
5111 if (mScreenshotConnection != this) {
5112 return;
5113 }
5114 Messenger messenger = new Messenger(service);
5115 Message msg = Message.obtain(null, 1);
5116 final ServiceConnection myConn = this;
5117 Handler h = new Handler(mHandler.getLooper()) {
5118 @Override
5119 public void handleMessage(Message msg) {
5120 synchronized (mScreenshotLock) {
5121 if (mScreenshotConnection == myConn) {
5122 mContext.unbindService(mScreenshotConnection);
5123 mScreenshotConnection = null;
5124 mHandler.removeCallbacks(mScreenshotTimeout);
5125 }
5126 }
5127 }
5128 };
5129 msg.replyTo = new Messenger(h);
Winson Chunga63bb842011-10-17 10:26:28 -07005130 msg.arg1 = msg.arg2 = 0;
5131 if (mStatusBar != null && mStatusBar.isVisibleLw())
5132 msg.arg1 = 1;
5133 if (mNavigationBar != null && mNavigationBar.isVisibleLw())
5134 msg.arg2 = 1;
Jeff Brownd5bb82d2011-10-12 13:57:59 -07005135 try {
5136 messenger.send(msg);
5137 } catch (RemoteException e) {
5138 }
5139 }
5140 }
5141 @Override
5142 public void onServiceDisconnected(ComponentName name) {}
5143 };
Amith Yamasani27b89e62013-01-16 12:30:11 -08005144 if (mContext.bindServiceAsUser(
5145 intent, conn, Context.BIND_AUTO_CREATE, UserHandle.CURRENT)) {
Jeff Brownd5bb82d2011-10-12 13:57:59 -07005146 mScreenshotConnection = conn;
5147 mHandler.postDelayed(mScreenshotTimeout, 10000);
5148 }
5149 }
Winson Chung9112ec32011-06-27 13:15:32 -07005150 }
5151
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005152 /** {@inheritDoc} */
Jeff Brown00fa7bd2010-07-02 15:37:36 -07005153 @Override
Jeff Brown037c33e2014-04-09 00:31:55 -07005154 public int interceptKeyBeforeQueueing(KeyEvent event, int policyFlags) {
Jeff Brown96307042012-07-27 15:51:34 -07005155 if (!mSystemBooted) {
5156 // If we have not yet booted, don't let key events do anything.
5157 return 0;
5158 }
5159
Jeff Brown037c33e2014-04-09 00:31:55 -07005160 final boolean interactive = (policyFlags & FLAG_INTERACTIVE) != 0;
Jeff Brown1f245102010-11-18 20:53:46 -08005161 final boolean down = event.getAction() == KeyEvent.ACTION_DOWN;
5162 final boolean canceled = event.isCanceled();
5163 final int keyCode = event.getKeyCode();
Jeff Browne20c9e02010-10-11 14:20:19 -07005164
Jeff Brown3122e442010-10-11 23:32:49 -07005165 final boolean isInjected = (policyFlags & WindowManagerPolicy.FLAG_INJECTED) != 0;
Jeff Brown3122e442010-10-11 23:32:49 -07005166
Mike Lockwoodc72b15f2009-11-28 20:58:22 -05005167 // If screen is off then we treat the case where the keyguard is open but hidden
5168 // the same as if it were open and in front.
5169 // This will prevent any keys other than the power button from waking the screen
5170 // when the keyguard is hidden by another activity.
Jim Miller5ecd8112013-01-09 18:50:26 -08005171 final boolean keyguardActive = (mKeyguardDelegate == null ? false :
Jeff Brown037c33e2014-04-09 00:31:55 -07005172 (interactive ?
Jim Millerab954542014-10-10 18:21:49 -07005173 isKeyguardShowingAndNotOccluded() :
Jim Miller5ecd8112013-01-09 18:50:26 -08005174 mKeyguardDelegate.isShowing()));
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005175
Jeff Brown40013652012-05-16 21:22:36 -07005176 if (DEBUG_INPUT) {
Jeff Brown00fa7bd2010-07-02 15:37:36 -07005177 Log.d(TAG, "interceptKeyTq keycode=" + keyCode
Jeff Brown037c33e2014-04-09 00:31:55 -07005178 + " interactive=" + interactive + " keyguardActive=" + keyguardActive
Jeff Brown26875502014-01-30 21:47:47 -08005179 + " policyFlags=" + Integer.toHexString(policyFlags));
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005180 }
5181
Jeff Brown037c33e2014-04-09 00:31:55 -07005182 // Basic policy based on interactive state.
Jeff Brown4d396052010-10-29 21:50:21 -07005183 int result;
Michael Wright337d9d22014-04-22 15:03:48 -07005184 boolean isWakeKey = (policyFlags & WindowManagerPolicy.FLAG_WAKE) != 0
5185 || event.isWakeKey();
Michael Wrightfc01f042014-09-08 14:12:24 -07005186 if (interactive || (isInjected && !isWakeKey)) {
RoboErikde9ba392014-09-26 12:51:01 -07005187 // When the device is interactive or the key is injected pass the
5188 // key to the application.
Jeff Brown4d396052010-10-29 21:50:21 -07005189 result = ACTION_PASS_TO_USER;
Jose Lima9546b202014-07-02 17:21:51 -07005190 isWakeKey = false;
Michael Wrightfc01f042014-09-08 14:12:24 -07005191 } else if (!interactive && shouldDispatchInputWhenNonInteractive()) {
5192 // If we're currently dozing with the screen on and the keyguard showing, pass the key
5193 // to the application but preserve its wake key status to make sure we still move
5194 // from dozing to fully interactive if we would normally go from off to fully
5195 // interactive.
5196 result = ACTION_PASS_TO_USER;
Jeff Brown4d396052010-10-29 21:50:21 -07005197 } else {
5198 // When the screen is off and the key is not injected, determine whether
5199 // to wake the device but don't pass the key to the application.
5200 result = 0;
Jeff Brown26875502014-01-30 21:47:47 -08005201 if (isWakeKey && (!down || !isWakeKeyWhenScreenOff(keyCode))) {
5202 isWakeKey = false;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005203 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005204 }
5205
Justin Kohd378ad72013-04-01 12:18:26 -07005206 // If the key would be handled globally, just return the result, don't worry about special
5207 // key processing.
Jeff Brown13f00f02014-10-31 14:45:50 -07005208 if (isValidGlobalKey(keyCode)
5209 && mGlobalKeyManager.shouldHandleGlobalKey(keyCode, event)) {
Michael Wright85b1af62014-06-04 14:51:58 -07005210 if (isWakeKey) {
Dianne Hackborn280a64e2015-07-13 14:48:08 -07005211 wakeUp(event.getEventTime(), mAllowTheaterModeWakeFromKey, "android.policy:KEY");
Michael Wright85b1af62014-06-04 14:51:58 -07005212 }
Justin Kohd378ad72013-04-01 12:18:26 -07005213 return result;
5214 }
5215
Jeff Brownbae8e772014-06-12 19:59:45 -07005216 boolean useHapticFeedback = down
5217 && (policyFlags & WindowManagerPolicy.FLAG_VIRTUAL) != 0
5218 && event.getRepeatCount() == 0;
5219
Jeff Brown4d396052010-10-29 21:50:21 -07005220 // Handle special keys.
5221 switch (keyCode) {
5222 case KeyEvent.KEYCODE_VOLUME_DOWN:
Jeff Brownb0418da2010-11-01 15:24:01 -07005223 case KeyEvent.KEYCODE_VOLUME_UP:
5224 case KeyEvent.KEYCODE_VOLUME_MUTE: {
Jeff Brownd5bb82d2011-10-12 13:57:59 -07005225 if (keyCode == KeyEvent.KEYCODE_VOLUME_DOWN) {
5226 if (down) {
Jeff Brown13f00f02014-10-31 14:45:50 -07005227 if (interactive && !mScreenshotChordVolumeDownKeyTriggered
Jeff Brownd5bb82d2011-10-12 13:57:59 -07005228 && (event.getFlags() & KeyEvent.FLAG_FALLBACK) == 0) {
Jeff Brown13f00f02014-10-31 14:45:50 -07005229 mScreenshotChordVolumeDownKeyTriggered = true;
5230 mScreenshotChordVolumeDownKeyTime = event.getDownTime();
5231 mScreenshotChordVolumeDownKeyConsumed = false;
Jeff Brownd5bb82d2011-10-12 13:57:59 -07005232 cancelPendingPowerKeyAction();
5233 interceptScreenshotChord();
5234 }
5235 } else {
Jeff Brown13f00f02014-10-31 14:45:50 -07005236 mScreenshotChordVolumeDownKeyTriggered = false;
Jeff Brownd5bb82d2011-10-12 13:57:59 -07005237 cancelPendingScreenshotChordAction();
5238 }
5239 } else if (keyCode == KeyEvent.KEYCODE_VOLUME_UP) {
5240 if (down) {
Jeff Brown13f00f02014-10-31 14:45:50 -07005241 if (interactive && !mScreenshotChordVolumeUpKeyTriggered
Jeff Brownd5bb82d2011-10-12 13:57:59 -07005242 && (event.getFlags() & KeyEvent.FLAG_FALLBACK) == 0) {
Jeff Brown13f00f02014-10-31 14:45:50 -07005243 mScreenshotChordVolumeUpKeyTriggered = true;
Jeff Brownd5bb82d2011-10-12 13:57:59 -07005244 cancelPendingPowerKeyAction();
5245 cancelPendingScreenshotChordAction();
5246 }
5247 } else {
Jeff Brown13f00f02014-10-31 14:45:50 -07005248 mScreenshotChordVolumeUpKeyTriggered = false;
Jeff Brownd5bb82d2011-10-12 13:57:59 -07005249 cancelPendingScreenshotChordAction();
5250 }
5251 }
Jeff Brown4d396052010-10-29 21:50:21 -07005252 if (down) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -07005253 TelecomManager telecomManager = getTelecommService();
5254 if (telecomManager != null) {
5255 if (telecomManager.isRinging()) {
Santos Cordon6848f722014-05-21 15:22:12 -07005256 // If an incoming call is ringing, either VOLUME key means
5257 // "silence ringer". We handle these keys here, rather than
5258 // in the InCallScreen, to make sure we'll respond to them
5259 // even if the InCallScreen hasn't come to the foreground yet.
5260 // Look for the DOWN event here, to agree with the "fallback"
5261 // behavior in the InCallScreen.
5262 Log.i(TAG, "interceptKeyBeforeQueueing:"
5263 + " VOLUME key-down while ringing: Silence ringer!");
Jeff Brown4d396052010-10-29 21:50:21 -07005264
Santos Cordon6848f722014-05-21 15:22:12 -07005265 // Silence the ringer. (It's safe to call this
5266 // even if the ringer has already been silenced.)
Tyler Gunnef9f6f92014-09-12 22:16:17 -07005267 telecomManager.silenceRinger();
Jeff Brown4d396052010-10-29 21:50:21 -07005268
Santos Cordon6848f722014-05-21 15:22:12 -07005269 // And *don't* pass this key thru to the current activity
5270 // (which is probably the InCallScreen.)
5271 result &= ~ACTION_PASS_TO_USER;
5272 break;
5273 }
Tyler Gunnef9f6f92014-09-12 22:16:17 -07005274 if (telecomManager.isInCall()
Santos Cordon6848f722014-05-21 15:22:12 -07005275 && (result & ACTION_PASS_TO_USER) == 0) {
5276 // If we are in call but we decided not to pass the key to
RoboErik430fc482014-06-12 15:49:20 -07005277 // the application, just pass it to the session service.
5278
5279 MediaSessionLegacyHelper.getHelper(mContext)
RoboErik3c45c292014-07-08 16:47:31 -07005280 .sendVolumeKeyEvent(event, false);
Santos Cordon6848f722014-05-21 15:22:12 -07005281 break;
Jeff Brown4d396052010-10-29 21:50:21 -07005282 }
5283 }
Jaewan Kim765487f2016-01-12 14:45:42 +09005284 }
5285 if (mUseTvRouting) {
5286 // On TVs, defer special key handlings to
5287 // {@link interceptKeyBeforeDispatching()}.
5288 result |= ACTION_PASS_TO_USER;
5289 } else if ((result & ACTION_PASS_TO_USER) == 0) {
5290 // If we aren't passing to the user and no one else
5291 // handled it send it to the session manager to
5292 // figure out.
5293 MediaSessionLegacyHelper.getHelper(mContext)
5294 .sendVolumeKeyEvent(event, true);
Jeff Brown4d396052010-10-29 21:50:21 -07005295 }
5296 break;
5297 }
5298
5299 case KeyEvent.KEYCODE_ENDCALL: {
5300 result &= ~ACTION_PASS_TO_USER;
5301 if (down) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -07005302 TelecomManager telecomManager = getTelecommService();
Jeff Brown4d396052010-10-29 21:50:21 -07005303 boolean hungUp = false;
Tyler Gunnef9f6f92014-09-12 22:16:17 -07005304 if (telecomManager != null) {
5305 hungUp = telecomManager.endCall();
Jeff Brown4d396052010-10-29 21:50:21 -07005306 }
Jeff Brown13f00f02014-10-31 14:45:50 -07005307 if (interactive && !hungUp) {
5308 mEndCallKeyHandled = false;
5309 mHandler.postDelayed(mEndCallLongPress,
5310 ViewConfiguration.get(mContext).getDeviceGlobalActionKeyTimeout());
5311 } else {
5312 mEndCallKeyHandled = true;
5313 }
Jeff Brown4d396052010-10-29 21:50:21 -07005314 } else {
Jeff Brown13f00f02014-10-31 14:45:50 -07005315 if (!mEndCallKeyHandled) {
5316 mHandler.removeCallbacks(mEndCallLongPress);
5317 if (!canceled) {
5318 if ((mEndcallBehavior
5319 & Settings.System.END_BUTTON_BEHAVIOR_HOME) != 0) {
5320 if (goHome()) {
5321 break;
5322 }
Dianne Hackborn0041e972009-07-24 17:14:43 -07005323 }
Jeff Brown13f00f02014-10-31 14:45:50 -07005324 if ((mEndcallBehavior
5325 & Settings.System.END_BUTTON_BEHAVIOR_SLEEP) != 0) {
5326 mPowerManager.goToSleep(event.getEventTime(),
5327 PowerManager.GO_TO_SLEEP_REASON_POWER_BUTTON, 0);
5328 isWakeKey = false;
5329 }
Jeff Brown4d396052010-10-29 21:50:21 -07005330 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005331 }
Jeff Brown4d396052010-10-29 21:50:21 -07005332 }
5333 break;
5334 }
5335
5336 case KeyEvent.KEYCODE_POWER: {
5337 result &= ~ACTION_PASS_TO_USER;
Jeff Brown13f00f02014-10-31 14:45:50 -07005338 isWakeKey = false; // wake-up will be handled separately
Jeff Brown4d396052010-10-29 21:50:21 -07005339 if (down) {
Jeff Brown13f00f02014-10-31 14:45:50 -07005340 interceptPowerKeyDown(event, interactive);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005341 } else {
Jeff Brown13f00f02014-10-31 14:45:50 -07005342 interceptPowerKeyUp(event, interactive, canceled);
Jeff Brown4d396052010-10-29 21:50:21 -07005343 }
5344 break;
5345 }
5346
Jeff Brown6212a492014-03-07 13:58:47 -08005347 case KeyEvent.KEYCODE_SLEEP: {
5348 result &= ~ACTION_PASS_TO_USER;
Filip Gruszczynskia483a1d2015-03-17 19:06:58 +00005349 isWakeKey = false;
Jeff Brownbae8e772014-06-12 19:59:45 -07005350 if (!mPowerManager.isInteractive()) {
5351 useHapticFeedback = false; // suppress feedback if already non-interactive
5352 }
Nick Vaccarob593a812015-05-15 11:23:05 -07005353 if (down) {
5354 sleepPress(event.getEventTime());
5355 } else {
5356 sleepRelease(event.getEventTime());
5357 }
Jeff Brown6212a492014-03-07 13:58:47 -08005358 break;
5359 }
5360
Nick Armstrong-Crews56ecfcc2015-09-07 21:46:50 -07005361 case KeyEvent.KEYCODE_SOFT_SLEEP: {
5362 result &= ~ACTION_PASS_TO_USER;
5363 isWakeKey = false;
5364 if (!down) {
5365 mPowerManagerInternal.setUserInactiveOverrideFromWindowManager();
5366 }
5367 break;
5368 }
5369
Jeff Brown6212a492014-03-07 13:58:47 -08005370 case KeyEvent.KEYCODE_WAKEUP: {
5371 result &= ~ACTION_PASS_TO_USER;
Jose Lima9546b202014-07-02 17:21:51 -07005372 isWakeKey = true;
Jeff Brown6212a492014-03-07 13:58:47 -08005373 break;
5374 }
5375
Jeff Brown4d396052010-10-29 21:50:21 -07005376 case KeyEvent.KEYCODE_MEDIA_PLAY:
5377 case KeyEvent.KEYCODE_MEDIA_PAUSE:
5378 case KeyEvent.KEYCODE_MEDIA_PLAY_PAUSE:
Jeff Brown4d396052010-10-29 21:50:21 -07005379 case KeyEvent.KEYCODE_HEADSETHOOK:
5380 case KeyEvent.KEYCODE_MUTE:
5381 case KeyEvent.KEYCODE_MEDIA_STOP:
5382 case KeyEvent.KEYCODE_MEDIA_NEXT:
5383 case KeyEvent.KEYCODE_MEDIA_PREVIOUS:
5384 case KeyEvent.KEYCODE_MEDIA_REWIND:
5385 case KeyEvent.KEYCODE_MEDIA_RECORD:
Jaekyun Seokbfdad8e2013-07-08 13:53:21 +09005386 case KeyEvent.KEYCODE_MEDIA_FAST_FORWARD:
5387 case KeyEvent.KEYCODE_MEDIA_AUDIO_TRACK: {
RoboErikde9ba392014-09-26 12:51:01 -07005388 if (MediaSessionLegacyHelper.getHelper(mContext).isGlobalPriorityActive()) {
5389 // If the global session is active pass all media keys to it
5390 // instead of the active window.
5391 result &= ~ACTION_PASS_TO_USER;
5392 }
Jeff Brown4d396052010-10-29 21:50:21 -07005393 if ((result & ACTION_PASS_TO_USER) == 0) {
5394 // Only do this if we would otherwise not pass it to the user. In that
5395 // case, the PhoneWindow class will do the same thing, except it will
5396 // only do it if the showing app doesn't process the key on its own.
Jeff Brown40013652012-05-16 21:22:36 -07005397 // Note that we need to make a copy of the key event here because the
5398 // original key event will be recycled when we return.
Jeff Brown4d396052010-10-29 21:50:21 -07005399 mBroadcastWakeLock.acquire();
Jeff Brown40013652012-05-16 21:22:36 -07005400 Message msg = mHandler.obtainMessage(MSG_DISPATCH_MEDIA_KEY_WITH_WAKE_LOCK,
5401 new KeyEvent(event));
5402 msg.setAsynchronous(true);
5403 msg.sendToTarget();
Jeff Brown4d396052010-10-29 21:50:21 -07005404 }
5405 break;
Jeff Brown00fa7bd2010-07-02 15:37:36 -07005406 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005407
Jeff Brown4d396052010-10-29 21:50:21 -07005408 case KeyEvent.KEYCODE_CALL: {
5409 if (down) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -07005410 TelecomManager telecomManager = getTelecommService();
5411 if (telecomManager != null) {
5412 if (telecomManager.isRinging()) {
Santos Cordon6848f722014-05-21 15:22:12 -07005413 Log.i(TAG, "interceptKeyBeforeQueueing:"
5414 + " CALL key-down while ringing: Answer the call!");
Tyler Gunnef9f6f92014-09-12 22:16:17 -07005415 telecomManager.acceptRingingCall();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005416
Santos Cordon6848f722014-05-21 15:22:12 -07005417 // And *don't* pass this key thru to the current activity
5418 // (which is presumably the InCallScreen.)
5419 result &= ~ACTION_PASS_TO_USER;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005420 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005421 }
Jeff Brown00fa7bd2010-07-02 15:37:36 -07005422 }
Jeff Brown4d396052010-10-29 21:50:21 -07005423 break;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005424 }
Michael Wright869a67c2014-08-26 19:33:06 -07005425 case KeyEvent.KEYCODE_VOICE_ASSIST: {
5426 // Only do this if we would otherwise not pass it to the user. In that case,
5427 // interceptKeyBeforeDispatching would apply a similar but different policy in
5428 // order to invoke voice assist actions. Note that we need to make a copy of the
5429 // key event here because the original key event will be recycled when we return.
5430 if ((result & ACTION_PASS_TO_USER) == 0 && !down) {
5431 mBroadcastWakeLock.acquire();
5432 Message msg = mHandler.obtainMessage(MSG_LAUNCH_VOICE_ASSIST_WITH_WAKE_LOCK,
5433 keyguardActive ? 1 : 0, 0);
5434 msg.setAsynchronous(true);
5435 msg.sendToTarget();
5436 }
Jaewan Kim49117872016-01-19 17:24:08 +09005437 break;
5438 }
5439 case KeyEvent.KEYCODE_WINDOW: {
5440 if (mShortPressWindowBehavior == SHORT_PRESS_WINDOW_PICTURE_IN_PICTURE) {
5441 if (!down) {
Jaewan Kimc552b042016-01-18 16:08:45 +09005442 requestTvPictureInPicture(event);
Jaewan Kim49117872016-01-19 17:24:08 +09005443 }
5444 result &= ~ACTION_PASS_TO_USER;
5445 }
5446 break;
Michael Wright869a67c2014-08-26 19:33:06 -07005447 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005448 }
Jeff Brown26875502014-01-30 21:47:47 -08005449
Jeff Brownbae8e772014-06-12 19:59:45 -07005450 if (useHapticFeedback) {
5451 performHapticFeedbackLw(null, HapticFeedbackConstants.VIRTUAL_KEY, false);
5452 }
5453
Jeff Brown26875502014-01-30 21:47:47 -08005454 if (isWakeKey) {
Dianne Hackborn280a64e2015-07-13 14:48:08 -07005455 wakeUp(event.getEventTime(), mAllowTheaterModeWakeFromKey, "android.policy:KEY");
Jeff Brown26875502014-01-30 21:47:47 -08005456 }
Bryce Lee584a4452014-10-21 15:55:55 -07005457
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005458 return result;
5459 }
5460
Jeff Brown1c2e4942012-11-06 16:32:01 -08005461 /**
Jeff Brown13f00f02014-10-31 14:45:50 -07005462 * Returns true if the key can have global actions attached to it.
5463 * We reserve all power management keys for the system since they require
5464 * very careful handling.
5465 */
5466 private static boolean isValidGlobalKey(int keyCode) {
5467 switch (keyCode) {
5468 case KeyEvent.KEYCODE_POWER:
5469 case KeyEvent.KEYCODE_WAKEUP:
5470 case KeyEvent.KEYCODE_SLEEP:
5471 return false;
5472 default:
5473 return true;
5474 }
5475 }
5476
5477 /**
Jeff Brown1c2e4942012-11-06 16:32:01 -08005478 * When the screen is off we ignore some keys that might otherwise typically
5479 * be considered wake keys. We filter them out here.
5480 *
5481 * {@link KeyEvent#KEYCODE_POWER} is notably absent from this list because it
5482 * is always considered a wake key.
5483 */
5484 private boolean isWakeKeyWhenScreenOff(int keyCode) {
5485 switch (keyCode) {
5486 // ignore volume keys unless docked
5487 case KeyEvent.KEYCODE_VOLUME_UP:
5488 case KeyEvent.KEYCODE_VOLUME_DOWN:
5489 case KeyEvent.KEYCODE_VOLUME_MUTE:
5490 return mDockMode != Intent.EXTRA_DOCK_STATE_UNDOCKED;
5491
5492 // ignore media and camera keys
5493 case KeyEvent.KEYCODE_MUTE:
5494 case KeyEvent.KEYCODE_HEADSETHOOK:
5495 case KeyEvent.KEYCODE_MEDIA_PLAY:
5496 case KeyEvent.KEYCODE_MEDIA_PAUSE:
5497 case KeyEvent.KEYCODE_MEDIA_PLAY_PAUSE:
5498 case KeyEvent.KEYCODE_MEDIA_STOP:
5499 case KeyEvent.KEYCODE_MEDIA_NEXT:
5500 case KeyEvent.KEYCODE_MEDIA_PREVIOUS:
5501 case KeyEvent.KEYCODE_MEDIA_REWIND:
5502 case KeyEvent.KEYCODE_MEDIA_RECORD:
5503 case KeyEvent.KEYCODE_MEDIA_FAST_FORWARD:
Jaekyun Seokbfdad8e2013-07-08 13:53:21 +09005504 case KeyEvent.KEYCODE_MEDIA_AUDIO_TRACK:
Jeff Brown1c2e4942012-11-06 16:32:01 -08005505 case KeyEvent.KEYCODE_CAMERA:
5506 return false;
5507 }
5508 return true;
5509 }
5510
5511
Jeff Brown56194eb2011-03-02 19:23:13 -08005512 /** {@inheritDoc} */
5513 @Override
Michael Wright70af00a2014-09-03 19:30:20 -07005514 public int interceptMotionBeforeQueueingNonInteractive(long whenNanos, int policyFlags) {
5515 if ((policyFlags & FLAG_WAKE) != 0) {
Dianne Hackborn280a64e2015-07-13 14:48:08 -07005516 if (wakeUp(whenNanos / 1000000, mAllowTheaterModeWakeFromMotion,
5517 "android.policy:MOTION")) {
Bryce Lee5c138322014-11-03 08:26:09 -08005518 return 0;
5519 }
Michael Wright70af00a2014-09-03 19:30:20 -07005520 }
Bryce Lee5c138322014-11-03 08:26:09 -08005521
Michael Wright70af00a2014-09-03 19:30:20 -07005522 if (shouldDispatchInputWhenNonInteractive()) {
5523 return ACTION_PASS_TO_USER;
5524 }
Bryce Lee5c138322014-11-03 08:26:09 -08005525
Bryce Lee812d7022014-11-10 13:33:28 -08005526 // If we have not passed the action up and we are in theater mode without dreaming,
5527 // there will be no dream to intercept the touch and wake into ambient. The device should
5528 // wake up in this case.
5529 if (isTheaterModeEnabled() && (policyFlags & FLAG_WAKE) != 0) {
Dianne Hackborn280a64e2015-07-13 14:48:08 -07005530 wakeUp(whenNanos / 1000000, mAllowTheaterModeWakeFromMotionWhenNotDreaming,
5531 "android.policy:MOTION");
Bryce Lee812d7022014-11-10 13:33:28 -08005532 }
5533
Jeff Brown037c33e2014-04-09 00:31:55 -07005534 return 0;
Jeff Brown56194eb2011-03-02 19:23:13 -08005535 }
5536
Michael Wright70af00a2014-09-03 19:30:20 -07005537 private boolean shouldDispatchInputWhenNonInteractive() {
Joe LaPennaf2b9b2d2015-11-17 22:22:37 +00005538 // Send events to keyguard while the screen is on.
5539 if (isKeyguardShowingAndNotOccluded() && mDisplay != null
5540 && mDisplay.getState() != Display.STATE_OFF) {
Bryce Lee5c138322014-11-03 08:26:09 -08005541 return true;
5542 }
5543
5544 // Send events to a dozing dream even if the screen is off since the dream
5545 // is in control of the state of the screen.
5546 IDreamManager dreamManager = getDreamManager();
5547
5548 try {
5549 if (dreamManager != null && dreamManager.isDreaming()) {
5550 return true;
5551 }
5552 } catch (RemoteException e) {
5553 Slog.e(TAG, "RemoteException when checking if dreaming", e);
5554 }
5555
5556 // Otherwise, consume events since the user can't see what is being
5557 // interacted with.
5558 return false;
Michael Wright70af00a2014-09-03 19:30:20 -07005559 }
5560
RoboErik001c59c2015-01-26 15:53:51 -08005561 private void dispatchDirectAudioEvent(KeyEvent event) {
5562 if (event.getAction() != KeyEvent.ACTION_DOWN) {
5563 return;
5564 }
5565 int keyCode = event.getKeyCode();
John Spurlockb94f2d62015-03-17 14:11:57 -04005566 int flags = AudioManager.FLAG_SHOW_UI | AudioManager.FLAG_PLAY_SOUND
5567 | AudioManager.FLAG_FROM_KEY;
RoboErik001c59c2015-01-26 15:53:51 -08005568 String pkgName = mContext.getOpPackageName();
5569 switch (keyCode) {
5570 case KeyEvent.KEYCODE_VOLUME_UP:
5571 try {
John Spurlockee5ad722015-03-03 16:17:21 -05005572 getAudioService().adjustSuggestedStreamVolume(AudioManager.ADJUST_RAISE,
John Spurlock90874332015-03-10 16:00:54 -04005573 AudioManager.USE_DEFAULT_STREAM_TYPE, flags, pkgName, TAG);
RoboErik001c59c2015-01-26 15:53:51 -08005574 } catch (RemoteException e) {
5575 Log.e(TAG, "Error dispatching volume up in dispatchTvAudioEvent.", e);
5576 }
5577 break;
5578 case KeyEvent.KEYCODE_VOLUME_DOWN:
5579 try {
John Spurlockee5ad722015-03-03 16:17:21 -05005580 getAudioService().adjustSuggestedStreamVolume(AudioManager.ADJUST_LOWER,
John Spurlock90874332015-03-10 16:00:54 -04005581 AudioManager.USE_DEFAULT_STREAM_TYPE, flags, pkgName, TAG);
RoboErik001c59c2015-01-26 15:53:51 -08005582 } catch (RemoteException e) {
5583 Log.e(TAG, "Error dispatching volume down in dispatchTvAudioEvent.", e);
5584 }
5585 break;
5586 case KeyEvent.KEYCODE_VOLUME_MUTE:
5587 try {
5588 if (event.getRepeatCount() == 0) {
John Spurlockee5ad722015-03-03 16:17:21 -05005589 getAudioService().adjustSuggestedStreamVolume(
5590 AudioManager.ADJUST_TOGGLE_MUTE,
John Spurlock90874332015-03-10 16:00:54 -04005591 AudioManager.USE_DEFAULT_STREAM_TYPE, flags, pkgName, TAG);
RoboErik001c59c2015-01-26 15:53:51 -08005592 }
5593 } catch (RemoteException e) {
5594 Log.e(TAG, "Error dispatching mute in dispatchTvAudioEvent.", e);
5595 }
5596 break;
5597 }
5598 }
5599
Jeff Brown40013652012-05-16 21:22:36 -07005600 void dispatchMediaKeyWithWakeLock(KeyEvent event) {
5601 if (DEBUG_INPUT) {
5602 Slog.d(TAG, "dispatchMediaKeyWithWakeLock: " + event);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005603 }
5604
Jeff Brown40013652012-05-16 21:22:36 -07005605 if (mHavePendingMediaKeyRepeatWithWakeLock) {
5606 if (DEBUG_INPUT) {
5607 Slog.d(TAG, "dispatchMediaKeyWithWakeLock: canceled repeat");
5608 }
5609
5610 mHandler.removeMessages(MSG_DISPATCH_MEDIA_KEY_REPEAT_WITH_WAKE_LOCK);
5611 mHavePendingMediaKeyRepeatWithWakeLock = false;
5612 mBroadcastWakeLock.release(); // pending repeat was holding onto the wake lock
5613 }
5614
5615 dispatchMediaKeyWithWakeLockToAudioService(event);
5616
5617 if (event.getAction() == KeyEvent.ACTION_DOWN
5618 && event.getRepeatCount() == 0) {
5619 mHavePendingMediaKeyRepeatWithWakeLock = true;
5620
5621 Message msg = mHandler.obtainMessage(
5622 MSG_DISPATCH_MEDIA_KEY_REPEAT_WITH_WAKE_LOCK, event);
5623 msg.setAsynchronous(true);
5624 mHandler.sendMessageDelayed(msg, ViewConfiguration.getKeyRepeatTimeout());
5625 } else {
5626 mBroadcastWakeLock.release();
5627 }
5628 }
5629
5630 void dispatchMediaKeyRepeatWithWakeLock(KeyEvent event) {
5631 mHavePendingMediaKeyRepeatWithWakeLock = false;
5632
5633 KeyEvent repeatEvent = KeyEvent.changeTimeRepeat(event,
5634 SystemClock.uptimeMillis(), 1, event.getFlags() | KeyEvent.FLAG_LONG_PRESS);
5635 if (DEBUG_INPUT) {
5636 Slog.d(TAG, "dispatchMediaKeyRepeatWithWakeLock: " + repeatEvent);
5637 }
5638
5639 dispatchMediaKeyWithWakeLockToAudioService(repeatEvent);
5640 mBroadcastWakeLock.release();
5641 }
5642
5643 void dispatchMediaKeyWithWakeLockToAudioService(KeyEvent event) {
5644 if (ActivityManagerNative.isSystemReady()) {
RoboErik430fc482014-06-12 15:49:20 -07005645 MediaSessionLegacyHelper.getHelper(mContext).sendMediaButtonEvent(event, true);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005646 }
5647 }
5648
Michael Wright869a67c2014-08-26 19:33:06 -07005649 void launchVoiceAssistWithWakeLock(boolean keyguardActive) {
Dianne Hackbornb6683c42015-06-18 17:40:33 -07005650 IDeviceIdleController dic = IDeviceIdleController.Stub.asInterface(
5651 ServiceManager.getService(Context.DEVICE_IDLE_CONTROLLER));
5652 if (dic != null) {
5653 try {
5654 dic.exitIdle("voice-search");
5655 } catch (RemoteException e) {
5656 }
5657 }
Michael Wright869a67c2014-08-26 19:33:06 -07005658 Intent voiceIntent =
5659 new Intent(RecognizerIntent.ACTION_VOICE_SEARCH_HANDS_FREE);
5660 voiceIntent.putExtra(RecognizerIntent.EXTRA_SECURE, keyguardActive);
Bart Sears8b1c27c2015-03-18 23:51:02 +00005661 startActivityAsUser(voiceIntent, UserHandle.CURRENT_OR_SELF);
Michael Wright869a67c2014-08-26 19:33:06 -07005662 mBroadcastWakeLock.release();
5663 }
5664
Mike Lockwood1753f7f2009-08-24 14:49:07 -07005665 BroadcastReceiver mDockReceiver = new BroadcastReceiver() {
Craig Mautnereee29c42013-01-17 14:44:34 -08005666 @Override
Mike Lockwood1753f7f2009-08-24 14:49:07 -07005667 public void onReceive(Context context, Intent intent) {
Dianne Hackborn867ab6472010-04-29 13:28:56 -07005668 if (Intent.ACTION_DOCK_EVENT.equals(intent.getAction())) {
5669 mDockMode = intent.getIntExtra(Intent.EXTRA_DOCK_STATE,
5670 Intent.EXTRA_DOCK_STATE_UNDOCKED);
Daniel Sandler6396c722013-04-16 20:19:09 -04005671 } else {
5672 try {
5673 IUiModeManager uiModeService = IUiModeManager.Stub.asInterface(
5674 ServiceManager.getService(Context.UI_MODE_SERVICE));
5675 mUiMode = uiModeService.getCurrentModeType();
5676 } catch (RemoteException e) {
5677 }
Dianne Hackborn80fa1662009-10-07 14:02:10 -07005678 }
Jeff Brown01a98dd2011-09-20 15:08:29 -07005679 updateRotation(true);
Craig Mautnereee29c42013-01-17 14:44:34 -08005680 synchronized (mLock) {
5681 updateOrientationListenerLp();
5682 }
Mike Lockwood1753f7f2009-08-24 14:49:07 -07005683 }
5684 };
5685
Jeff Brown6aaf2952012-10-05 16:01:08 -07005686 BroadcastReceiver mDreamReceiver = new BroadcastReceiver() {
5687 @Override
5688 public void onReceive(Context context, Intent intent) {
5689 if (Intent.ACTION_DREAMING_STARTED.equals(intent.getAction())) {
Jim Miller5ecd8112013-01-09 18:50:26 -08005690 if (mKeyguardDelegate != null) {
5691 mKeyguardDelegate.onDreamingStarted();
Jeff Brown6aaf2952012-10-05 16:01:08 -07005692 }
5693 } else if (Intent.ACTION_DREAMING_STOPPED.equals(intent.getAction())) {
Jim Miller5ecd8112013-01-09 18:50:26 -08005694 if (mKeyguardDelegate != null) {
5695 mKeyguardDelegate.onDreamingStopped();
Jeff Brown6aaf2952012-10-05 16:01:08 -07005696 }
5697 }
5698 }
5699 };
5700
Christopher Tate5e08af02012-09-21 17:17:22 -07005701 BroadcastReceiver mMultiuserReceiver = new BroadcastReceiver() {
5702 @Override
5703 public void onReceive(Context context, Intent intent) {
5704 if (Intent.ACTION_USER_SWITCHED.equals(intent.getAction())) {
5705 // tickle the settings observer: this first ensures that we're
5706 // observing the relevant settings for the newly-active user,
5707 // and then updates our own bookkeeping based on the now-
5708 // current user.
5709 mSettingsObserver.onChange(false);
John Spurlockce479d82012-11-29 09:52:21 -05005710
5711 // force a re-application of focused window sysui visibility.
5712 // the window may never have been shown for this user
5713 // e.g. the keyguard when going through the new-user setup flow
John Spurlock04db1762013-05-13 12:46:41 -04005714 synchronized (mWindowManagerFuncs.getWindowManagerLock()) {
John Spurlockce479d82012-11-29 09:52:21 -05005715 mLastSystemUiFlags = 0;
5716 updateSystemUiVisibilityLw();
5717 }
Christopher Tate5e08af02012-09-21 17:17:22 -07005718 }
5719 }
5720 };
5721
Adrian Roosddc8b272015-05-21 16:28:27 -07005722 private final Runnable mHiddenNavPanic = new Runnable() {
John Spurlockd9b70bd2014-02-06 17:02:44 -05005723 @Override
5724 public void run() {
Adrian Roosddc8b272015-05-21 16:28:27 -07005725 synchronized (mWindowManagerFuncs.getWindowManagerLock()) {
5726 if (!isUserSetupComplete()) {
5727 // Swipe-up for navigation bar is disabled during setup
5728 return;
5729 }
5730 mPendingPanicGestureUptime = SystemClock.uptimeMillis();
5731 mNavigationBarController.showTransient();
5732 }
John Spurlockd9b70bd2014-02-06 17:02:44 -05005733 }
5734 };
5735
John Spurlocke1f366f2013-08-05 12:22:40 -04005736 private void requestTransientBars(WindowState swipeTarget) {
John Spurlock04db1762013-05-13 12:46:41 -04005737 synchronized (mWindowManagerFuncs.getWindowManagerLock()) {
Maurice Lam99c6e072014-04-28 18:24:28 -07005738 if (!isUserSetupComplete()) {
5739 // Swipe-up for navigation bar is disabled during setup
5740 return;
5741 }
John Spurlock27735a42013-08-14 17:57:38 -04005742 boolean sb = mStatusBarController.checkShowTransientBarLw();
5743 boolean nb = mNavigationBarController.checkShowTransientBarLw();
John Spurlockad3e6cb2013-04-30 08:47:43 -04005744 if (sb || nb) {
Adrian Roos62b65e42015-02-25 18:05:34 +01005745 // Don't show status bar when swiping on already visible navigation bar
5746 if (!nb && swipeTarget == mNavigationBar) {
John Spurlocke1f366f2013-08-05 12:22:40 -04005747 if (DEBUG) Slog.d(TAG, "Not showing transient bar, wrong swipe target");
John Spurlockad3e6cb2013-04-30 08:47:43 -04005748 return;
5749 }
John Spurlock27735a42013-08-14 17:57:38 -04005750 if (sb) mStatusBarController.showTransient();
5751 if (nb) mNavigationBarController.showTransient();
John Spurlockf1a36642013-10-12 17:50:42 -04005752 mImmersiveModeConfirmation.confirmCurrentPrompt();
John Spurlockad3e6cb2013-04-30 08:47:43 -04005753 updateSystemUiVisibilityLw();
John Spurlock32beb2c2013-03-11 10:16:47 -04005754 }
John Spurlockad3e6cb2013-04-30 08:47:43 -04005755 }
5756 }
5757
Jeff Brown3ee549c2014-09-22 20:14:39 -07005758 // Called on the PowerManager's Notifier thread.
Jeff Brownc38c9be2012-10-04 13:16:19 -07005759 @Override
Jeff Brown416c49c2015-05-26 19:50:18 -07005760 public void startedGoingToSleep(int why) {
5761 if (DEBUG_WAKEUP) Slog.i(TAG, "Started going to sleep... (why=" + why + ")");
Jorim Jaggid175b6c2015-05-27 15:39:09 -07005762 if (mKeyguardDelegate != null) {
5763 mKeyguardDelegate.onStartedGoingToSleep(why);
5764 }
Jeff Brown416c49c2015-05-26 19:50:18 -07005765 }
5766
5767 // Called on the PowerManager's Notifier thread.
5768 @Override
5769 public void finishedGoingToSleep(int why) {
Dianne Hackborn74489012009-03-24 20:50:09 -07005770 EventLog.writeEvent(70000, 0);
Jeff Brown416c49c2015-05-26 19:50:18 -07005771 if (DEBUG_WAKEUP) Slog.i(TAG, "Finished going to sleep... (why=" + why + ")");
Chris Wren9bb290b2015-06-29 12:02:13 -04005772 MetricsLogger.histogram(mContext, "screen_timeout", mLockScreenTimeout / 1000);
Jeff Brown3ee549c2014-09-22 20:14:39 -07005773
5774 // We must get this work done here because the power manager will drop
5775 // the wake lock and let the system suspend once this function returns.
The Android Open Source Project0727d222009-03-11 12:11:58 -07005776 synchronized (mLock) {
Jeff Brown3ee549c2014-09-22 20:14:39 -07005777 mAwake = false;
Jeff Browna20dda42014-05-27 20:57:24 -07005778 updateWakeGestureListenerLp();
The Android Open Source Project0727d222009-03-11 12:11:58 -07005779 updateOrientationListenerLp();
Mike Lockwood28569302010-01-28 11:54:40 -05005780 updateLockScreenTimeout();
The Android Open Source Project0727d222009-03-11 12:11:58 -07005781 }
Jeff Brown3ee549c2014-09-22 20:14:39 -07005782 if (mKeyguardDelegate != null) {
Jorim Jaggid175b6c2015-05-27 15:39:09 -07005783 mKeyguardDelegate.onFinishedGoingToSleep(why);
Jeff Brown3ee549c2014-09-22 20:14:39 -07005784 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005785 }
5786
Jeff Brown3ee549c2014-09-22 20:14:39 -07005787 // Called on the PowerManager's Notifier thread.
Jeff Brownc38c9be2012-10-04 13:16:19 -07005788 @Override
Jeff Brown416c49c2015-05-26 19:50:18 -07005789 public void startedWakingUp() {
Dianne Hackborn74489012009-03-24 20:50:09 -07005790 EventLog.writeEvent(70000, 1);
Jeff Brown416c49c2015-05-26 19:50:18 -07005791 if (DEBUG_WAKEUP) Slog.i(TAG, "Started waking up...");
Craig Mautner8a0da012014-05-31 15:13:37 -07005792
Jeff Brown3ee549c2014-09-22 20:14:39 -07005793 // Since goToSleep performs these functions synchronously, we must
5794 // do the same here. We cannot post this work to a handler because
5795 // that might cause it to become reordered with respect to what
5796 // may happen in a future call to goToSleep.
The Android Open Source Project0727d222009-03-11 12:11:58 -07005797 synchronized (mLock) {
Jeff Brown3ee549c2014-09-22 20:14:39 -07005798 mAwake = true;
Jeff Brown3ee549c2014-09-22 20:14:39 -07005799
Jeff Browna20dda42014-05-27 20:57:24 -07005800 updateWakeGestureListenerLp();
The Android Open Source Project0727d222009-03-11 12:11:58 -07005801 updateOrientationListenerLp();
Mike Lockwood28569302010-01-28 11:54:40 -05005802 updateLockScreenTimeout();
The Android Open Source Project0727d222009-03-11 12:11:58 -07005803 }
Jeff Brownc38c9be2012-10-04 13:16:19 -07005804
Jim Miller5ecd8112013-01-09 18:50:26 -08005805 if (mKeyguardDelegate != null) {
Jorim Jaggi4cfdcf52015-07-09 12:13:59 -07005806 mKeyguardDelegate.onStartedWakingUp();
Jeff Brownc38c9be2012-10-04 13:16:19 -07005807 }
Jeff Brown36c4db82014-09-19 12:05:31 -07005808 }
5809
Jeff Brown416c49c2015-05-26 19:50:18 -07005810 // Called on the PowerManager's Notifier thread.
5811 @Override
5812 public void finishedWakingUp() {
5813 if (DEBUG_WAKEUP) Slog.i(TAG, "Finished waking up...");
5814 }
5815
5816 private void wakeUpFromPowerKey(long eventTime) {
Dianne Hackborn280a64e2015-07-13 14:48:08 -07005817 wakeUp(eventTime, mAllowTheaterModeWakeFromPowerKey, "android.policy:POWER");
Jeff Brown416c49c2015-05-26 19:50:18 -07005818 }
5819
Dianne Hackborn280a64e2015-07-13 14:48:08 -07005820 private boolean wakeUp(long wakeTime, boolean wakeInTheaterMode, String reason) {
Bryce Leed3896842015-06-23 17:06:51 -07005821 final boolean theaterModeEnabled = isTheaterModeEnabled();
5822 if (!wakeInTheaterMode && theaterModeEnabled) {
Jeff Brown416c49c2015-05-26 19:50:18 -07005823 return false;
5824 }
5825
Bryce Leed3896842015-06-23 17:06:51 -07005826 if (theaterModeEnabled) {
5827 Settings.Global.putInt(mContext.getContentResolver(),
5828 Settings.Global.THEATER_MODE_ON, 0);
5829 }
5830
Dianne Hackborn280a64e2015-07-13 14:48:08 -07005831 mPowerManager.wakeUp(wakeTime, reason);
Jeff Brown416c49c2015-05-26 19:50:18 -07005832 return true;
5833 }
5834
Jeff Brown36c4db82014-09-19 12:05:31 -07005835 private void finishKeyguardDrawn() {
Jeff Brown3ee549c2014-09-22 20:14:39 -07005836 synchronized (mLock) {
Jorim Jaggif3255482015-07-24 12:32:42 -07005837 if (!mScreenOnEarly || mKeyguardDrawComplete) {
Stefan Kuhne9326dc12015-06-12 09:25:32 -10005838 return; // We are not awake yet or we have already informed of this event.
Jeff Brown3ee549c2014-09-22 20:14:39 -07005839 }
5840
Jeff Brown36c4db82014-09-19 12:05:31 -07005841 mKeyguardDrawComplete = true;
Jeff Brown3ee549c2014-09-22 20:14:39 -07005842 if (mKeyguardDelegate != null) {
5843 mHandler.removeMessages(MSG_KEYGUARD_DRAWN_TIMEOUT);
5844 }
Jorim Jaggi4cfdcf52015-07-09 12:13:59 -07005845 mWindowManagerDrawComplete = false;
Jeff Brown3ee549c2014-09-22 20:14:39 -07005846 }
5847
Jorim Jaggi4cfdcf52015-07-09 12:13:59 -07005848 // ... eventually calls finishWindowsDrawn which will finalize our screen turn on
5849 // as well as enabling the orientation change logic/sensor.
5850 mWindowManagerInternal.waitForAllWindowsDrawn(mWindowManagerDrawCallback,
5851 WAITING_FOR_DRAWN_TIMEOUT);
Jeff Brown3ee549c2014-09-22 20:14:39 -07005852 }
5853
5854 // Called on the DisplayManager's DisplayPowerController thread.
5855 @Override
5856 public void screenTurnedOff() {
5857 if (DEBUG_WAKEUP) Slog.i(TAG, "Screen turned off...");
5858
Jeff Brown48d1b142015-06-10 16:36:03 -07005859 updateScreenOffSleepToken(true);
Jeff Brown3ee549c2014-09-22 20:14:39 -07005860 synchronized (mLock) {
5861 mScreenOnEarly = false;
5862 mScreenOnFully = false;
Jorim Jaggi95c6dae2015-07-29 15:17:23 -07005863 mKeyguardDrawComplete = false;
Jeff Brown3ee549c2014-09-22 20:14:39 -07005864 mWindowManagerDrawComplete = false;
5865 mScreenOnListener = null;
5866 updateOrientationListenerLp();
Jorim Jaggi0d210f62015-07-10 14:24:44 -07005867
5868 if (mKeyguardDelegate != null) {
5869 mKeyguardDelegate.onScreenTurnedOff();
5870 }
Jeff Brown36c4db82014-09-19 12:05:31 -07005871 }
5872 }
5873
Jeff Brown3ee549c2014-09-22 20:14:39 -07005874 // Called on the DisplayManager's DisplayPowerController thread.
Jeff Brown36c4db82014-09-19 12:05:31 -07005875 @Override
5876 public void screenTurningOn(final ScreenOnListener screenOnListener) {
Jeff Brown36c4db82014-09-19 12:05:31 -07005877 if (DEBUG_WAKEUP) Slog.i(TAG, "Screen turning on...");
Jeff Brown36c4db82014-09-19 12:05:31 -07005878
Jeff Brown48d1b142015-06-10 16:36:03 -07005879 updateScreenOffSleepToken(false);
Jeff Brown3ee549c2014-09-22 20:14:39 -07005880 synchronized (mLock) {
5881 mScreenOnEarly = true;
5882 mScreenOnFully = false;
Jorim Jaggi95c6dae2015-07-29 15:17:23 -07005883 mKeyguardDrawComplete = false;
Jeff Brown3ee549c2014-09-22 20:14:39 -07005884 mWindowManagerDrawComplete = false;
5885 mScreenOnListener = screenOnListener;
Jeff Brown36c4db82014-09-19 12:05:31 -07005886
Jorim Jaggi4cfdcf52015-07-09 12:13:59 -07005887 if (mKeyguardDelegate != null) {
Jorim Jaggia4b51bc2015-08-10 18:20:43 -07005888 mHandler.removeMessages(MSG_KEYGUARD_DRAWN_TIMEOUT);
5889 mHandler.sendEmptyMessageDelayed(MSG_KEYGUARD_DRAWN_TIMEOUT, 1000);
Jorim Jaggi4cfdcf52015-07-09 12:13:59 -07005890 mKeyguardDelegate.onScreenTurningOn(mKeyguardDrawnCallback);
5891 } else {
5892 if (DEBUG_WAKEUP) Slog.d(TAG,
5893 "null mKeyguardDelegate: setting mKeyguardDrawComplete.");
5894 finishKeyguardDrawn();
5895 }
5896 }
Jeff Brown36c4db82014-09-19 12:05:31 -07005897 }
5898
Jorim Jaggi0d210f62015-07-10 14:24:44 -07005899 // Called on the DisplayManager's DisplayPowerController thread.
5900 @Override
5901 public void screenTurnedOn() {
5902 synchronized (mLock) {
5903 if (mKeyguardDelegate != null) {
5904 mKeyguardDelegate.onScreenTurnedOn();
5905 }
5906 }
5907 }
5908
Jeff Brown36c4db82014-09-19 12:05:31 -07005909 private void finishWindowsDrawn() {
Jeff Brown3ee549c2014-09-22 20:14:39 -07005910 synchronized (mLock) {
5911 if (!mScreenOnEarly || mWindowManagerDrawComplete) {
Stefan Kuhne9326dc12015-06-12 09:25:32 -10005912 return; // Screen is not turned on or we did already handle this case earlier.
Jeff Brown3ee549c2014-09-22 20:14:39 -07005913 }
5914
Jeff Brown36c4db82014-09-19 12:05:31 -07005915 mWindowManagerDrawComplete = true;
Jeff Brown36c4db82014-09-19 12:05:31 -07005916 }
Jeff Brown3ee549c2014-09-22 20:14:39 -07005917
5918 finishScreenTurningOn();
Jeff Brownc38c9be2012-10-04 13:16:19 -07005919 }
5920
Craig Mautner8a0da012014-05-31 15:13:37 -07005921 private void finishScreenTurningOn() {
Stefan Kuhne9326dc12015-06-12 09:25:32 -10005922 synchronized (mLock) {
5923 // We have just finished drawing screen content. Since the orientation listener
5924 // gets only installed when all windows are drawn, we try to install it again.
5925 updateOrientationListenerLp();
5926 }
Jeff Brown3ee549c2014-09-22 20:14:39 -07005927 final ScreenOnListener listener;
5928 final boolean enableScreen;
Jeff Brown36c4db82014-09-19 12:05:31 -07005929 synchronized (mLock) {
Jeff Brown3ee549c2014-09-22 20:14:39 -07005930 if (DEBUG_WAKEUP) Slog.d(TAG,
5931 "finishScreenTurningOn: mAwake=" + mAwake
5932 + ", mScreenOnEarly=" + mScreenOnEarly
5933 + ", mScreenOnFully=" + mScreenOnFully
5934 + ", mKeyguardDrawComplete=" + mKeyguardDrawComplete
5935 + ", mWindowManagerDrawComplete=" + mWindowManagerDrawComplete);
5936
5937 if (mScreenOnFully || !mScreenOnEarly || !mWindowManagerDrawComplete
5938 || (mAwake && !mKeyguardDrawComplete)) {
5939 return; // spurious or not ready yet
Jeff Brown36c4db82014-09-19 12:05:31 -07005940 }
5941
Jeff Brown3ee549c2014-09-22 20:14:39 -07005942 if (DEBUG_WAKEUP) Slog.i(TAG, "Finished screen turning on...");
5943 listener = mScreenOnListener;
Craig Mautner13f6ea72014-06-23 14:57:02 -07005944 mScreenOnListener = null;
Jeff Brown3ee549c2014-09-22 20:14:39 -07005945 mScreenOnFully = true;
5946
5947 // Remember the first time we draw the keyguard so we know when we're done with
5948 // the main part of booting and can enable the screen and hide boot messages.
5949 if (!mKeyguardDrawnOnce && mAwake) {
5950 mKeyguardDrawnOnce = true;
5951 enableScreen = true;
5952 if (mBootMessageNeedsHiding) {
5953 mBootMessageNeedsHiding = false;
5954 hideBootMessages();
5955 }
5956 } else {
5957 enableScreen = false;
5958 }
Jeff Brownc38c9be2012-10-04 13:16:19 -07005959 }
5960
Jeff Brown3ee549c2014-09-22 20:14:39 -07005961 if (listener != null) {
5962 listener.onScreenOn();
5963 }
Jeff Brown4fc45272012-10-10 18:28:14 -07005964
Jeff Brown3ee549c2014-09-22 20:14:39 -07005965 if (enableScreen) {
5966 try {
5967 mWindowManager.enableScreenIfNeeded();
5968 } catch (RemoteException unhandled) {
Jeff Brown36c4db82014-09-19 12:05:31 -07005969 }
Craig Mautnera631d492014-08-05 15:16:01 -07005970 }
5971 }
5972
5973 private void handleHideBootMessage() {
Jeff Brown3ee549c2014-09-22 20:14:39 -07005974 synchronized (mLock) {
5975 if (!mKeyguardDrawnOnce) {
5976 mBootMessageNeedsHiding = true;
5977 return; // keyguard hasn't drawn the first time yet, not done booting
5978 }
Craig Mautnera631d492014-08-05 15:16:01 -07005979 }
Jeff Brown3ee549c2014-09-22 20:14:39 -07005980
5981 if (mBootMsgDialog != null) {
5982 if (DEBUG_WAKEUP) Slog.d(TAG, "handleHideBootMessage: dismissing");
5983 mBootMsgDialog.dismiss();
5984 mBootMsgDialog = null;
Craig Mautnera631d492014-08-05 15:16:01 -07005985 }
Jeff Brownc38c9be2012-10-04 13:16:19 -07005986 }
5987
5988 @Override
Jeff Brown3ee549c2014-09-22 20:14:39 -07005989 public boolean isScreenOn() {
5990 return mScreenOnFully;
Dianne Hackborn08743722009-12-21 12:16:51 -08005991 }
Jeff Brownc38c9be2012-10-04 13:16:19 -07005992
Dianne Hackborn08743722009-12-21 12:16:51 -08005993 /** {@inheritDoc} */
Jose Lima9546b202014-07-02 17:21:51 -07005994 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005995 public void enableKeyguard(boolean enabled) {
Jim Miller5ecd8112013-01-09 18:50:26 -08005996 if (mKeyguardDelegate != null) {
5997 mKeyguardDelegate.setKeyguardEnabled(enabled);
Mike Lockwood3a74bd32011-08-12 13:55:22 -07005998 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005999 }
6000
6001 /** {@inheritDoc} */
Jose Lima9546b202014-07-02 17:21:51 -07006002 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006003 public void exitKeyguardSecurely(OnKeyguardExitResult callback) {
Jim Miller5ecd8112013-01-09 18:50:26 -08006004 if (mKeyguardDelegate != null) {
6005 mKeyguardDelegate.verifyUnlock(callback);
Mike Lockwood3a74bd32011-08-12 13:55:22 -07006006 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006007 }
6008
Jim Millerab954542014-10-10 18:21:49 -07006009 private boolean isKeyguardShowingAndNotOccluded() {
Jim Miller5ecd8112013-01-09 18:50:26 -08006010 if (mKeyguardDelegate == null) return false;
Jim Millerab954542014-10-10 18:21:49 -07006011 return mKeyguardDelegate.isShowing() && !mKeyguardOccluded;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006012 }
6013
Mike Lockwood520d8bc2011-02-18 13:23:13 -05006014 /** {@inheritDoc} */
Jose Lima9546b202014-07-02 17:21:51 -07006015 @Override
Mike Lockwood520d8bc2011-02-18 13:23:13 -05006016 public boolean isKeyguardLocked() {
6017 return keyguardOn();
6018 }
6019
6020 /** {@inheritDoc} */
Jose Lima9546b202014-07-02 17:21:51 -07006021 @Override
Mike Lockwood520d8bc2011-02-18 13:23:13 -05006022 public boolean isKeyguardSecure() {
Jim Miller5ecd8112013-01-09 18:50:26 -08006023 if (mKeyguardDelegate == null) return false;
6024 return mKeyguardDelegate.isSecure();
Mike Lockwood520d8bc2011-02-18 13:23:13 -05006025 }
6026
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006027 /** {@inheritDoc} */
Jose Lima9546b202014-07-02 17:21:51 -07006028 @Override
Adrian Roos461829d2015-06-03 14:41:18 -07006029 public boolean isKeyguardShowingOrOccluded() {
6030 return mKeyguardDelegate == null ? false : mKeyguardDelegate.isShowing();
6031 }
6032
6033 /** {@inheritDoc} */
6034 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006035 public boolean inKeyguardRestrictedKeyInputMode() {
Jim Miller5ecd8112013-01-09 18:50:26 -08006036 if (mKeyguardDelegate == null) return false;
6037 return mKeyguardDelegate.isInputRestricted();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006038 }
6039
Jose Lima9546b202014-07-02 17:21:51 -07006040 @Override
Dianne Hackborn90c52de2011-09-23 12:57:44 -07006041 public void dismissKeyguardLw() {
RoboErik8a2cfc32014-05-16 11:19:38 -07006042 if (mKeyguardDelegate != null && mKeyguardDelegate.isShowing()) {
Craig Mautnerc0d2d0a2014-10-31 16:25:15 -07006043 if (DEBUG_KEYGUARD) Slog.d(TAG, "PWM.dismissKeyguardLw");
Daniel Sandler1ce804392012-11-07 15:07:12 -05006044 mHandler.post(new Runnable() {
Jose Lima9546b202014-07-02 17:21:51 -07006045 @Override
Daniel Sandler1ce804392012-11-07 15:07:12 -05006046 public void run() {
Jorim Jaggi8de4311c2014-08-11 22:36:20 +02006047 // ask the keyguard to prompt the user to authenticate if necessary
6048 mKeyguardDelegate.dismiss();
6049 }
6050 });
6051 }
6052 }
6053
6054 public void notifyActivityDrawnForKeyguardLw() {
6055 if (mKeyguardDelegate != null) {
6056 mHandler.post(new Runnable() {
6057 @Override
6058 public void run() {
6059 mKeyguardDelegate.onActivityDrawn();
Daniel Sandler1ce804392012-11-07 15:07:12 -05006060 }
6061 });
Dianne Hackborn90c52de2011-09-23 12:57:44 -07006062 }
6063 }
6064
Jorim Jaggicff0acb2014-03-31 16:35:15 +02006065 @Override
6066 public boolean isKeyguardDrawnLw() {
6067 synchronized (mLock) {
Jeff Brown3ee549c2014-09-22 20:14:39 -07006068 return mKeyguardDrawnOnce;
Jorim Jaggicff0acb2014-03-31 16:35:15 +02006069 }
6070 }
6071
Jorim Jaggi0d674622014-05-21 01:34:15 +02006072 @Override
Jorim Jaggie29b2db2014-05-30 23:17:03 +02006073 public void startKeyguardExitAnimation(long startTime, long fadeoutDuration) {
Jorim Jaggi0d674622014-05-21 01:34:15 +02006074 if (mKeyguardDelegate != null) {
Craig Mautnerc0d2d0a2014-10-31 16:25:15 -07006075 if (DEBUG_KEYGUARD) Slog.d(TAG, "PWM.startKeyguardExitAnimation");
Jorim Jaggie29b2db2014-05-30 23:17:03 +02006076 mKeyguardDelegate.startKeyguardExitAnimation(startTime, fadeoutDuration);
Jorim Jaggi0d674622014-05-21 01:34:15 +02006077 }
6078 }
6079
Jorim Jaggi737af722015-12-31 10:42:27 +01006080 @Override
6081 public void getStableInsetsLw(int displayRotation, int displayWidth, int displayHeight,
6082 Rect outInsets) {
6083 outInsets.setEmpty();
Jorim Jaggi82c9dc92016-02-05 15:10:33 -08006084
6085 // Navigation bar and status bar.
6086 getNonDecorInsetsLw(displayRotation, displayWidth, displayHeight, outInsets);
Jorim Jaggi737af722015-12-31 10:42:27 +01006087 if (mStatusBar != null) {
6088 outInsets.top = mStatusBarHeight;
6089 }
Jorim Jaggi82c9dc92016-02-05 15:10:33 -08006090 }
6091
6092 @Override
6093 public void getNonDecorInsetsLw(int displayRotation, int displayWidth, int displayHeight,
6094 Rect outInsets) {
6095 outInsets.setEmpty();
6096
6097 // Only navigation bar
Jorim Jaggi737af722015-12-31 10:42:27 +01006098 if (mNavigationBar != null) {
6099 if (isNavigationBarOnBottom(displayWidth, displayHeight)) {
6100 outInsets.bottom = getNavigationBarHeight(displayRotation, mUiMode);
6101 } else {
6102 outInsets.right = getNavigationBarWidth(displayRotation, mUiMode);
6103 }
6104 }
6105 }
6106
Jorim Jaggi5060bd82016-02-19 17:12:19 -08006107 @Override
Jorim Jaggi0ffd49c2016-02-12 15:04:21 -08006108 public boolean isNavBarForcedShownLw(WindowState windowState) {
6109 return mForceShowSystemBars
6110 && !windowState.getFrameLw().equals(windowState.getDisplayFrameLw());
6111 }
6112
6113 @Override
Jorim Jaggi5060bd82016-02-19 17:12:19 -08006114 public boolean isDockSideAllowed(int dockSide) {
6115
6116 // We do not allow all dock sides at which the navigation bar touches the docked stack.
6117 if (!mNavigationBarCanMove) {
6118 return dockSide == DOCKED_TOP || dockSide == DOCKED_LEFT || dockSide == DOCKED_RIGHT;
6119 } else {
6120 return dockSide == DOCKED_TOP || dockSide == DOCKED_LEFT;
6121 }
6122 }
6123
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006124 void sendCloseSystemWindows() {
Jorim Jaggib10e33f2015-02-04 21:57:40 +01006125 PhoneWindow.sendCloseSystemWindows(mContext, null);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006126 }
6127
6128 void sendCloseSystemWindows(String reason) {
Jorim Jaggib10e33f2015-02-04 21:57:40 +01006129 PhoneWindow.sendCloseSystemWindows(mContext, reason);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006130 }
Mitsuru Oshima831d0d92009-06-16 18:27:18 -07006131
Jeff Brown01a98dd2011-09-20 15:08:29 -07006132 @Override
6133 public int rotationForOrientationLw(int orientation, int lastRotation) {
Daniel Sandler2ed6ad62011-02-22 14:54:17 -05006134 if (false) {
6135 Slog.v(TAG, "rotationForOrientationLw(orient="
6136 + orientation + ", last=" + lastRotation
6137 + "); user=" + mUserRotation + " "
6138 + ((mUserRotationMode == WindowManagerPolicy.USER_ROTATION_LOCKED)
6139 ? "USER_ROTATION_LOCKED" : "")
6140 );
6141 }
6142
Craig Mautner46ac6fa2013-08-01 10:06:34 -07006143 if (mForceDefaultOrientation) {
6144 return Surface.ROTATION_0;
6145 }
6146
The Android Open Source Project0727d222009-03-11 12:11:58 -07006147 synchronized (mLock) {
Jeff Brownc0347aa2011-09-23 17:26:09 -07006148 int sensorRotation = mOrientationListener.getProposedRotation(); // may be -1
6149 if (sensorRotation < 0) {
Jeff Brown0f862b42012-09-27 21:11:01 -07006150 sensorRotation = lastRotation;
Jeff Brownc0347aa2011-09-23 17:26:09 -07006151 }
Jeff Brown01a98dd2011-09-20 15:08:29 -07006152
Jeff Browndec6cf42011-11-15 14:08:20 -08006153 final int preferredRotation;
Jeff Brown2e7760e2012-04-11 15:14:55 -07006154 if (mLidState == LID_OPEN && mLidOpenRotation >= 0) {
Jeff Brown01a98dd2011-09-20 15:08:29 -07006155 // Ignore sensor when lid switch is open and rotation is forced.
6156 preferredRotation = mLidOpenRotation;
6157 } else if (mDockMode == Intent.EXTRA_DOCK_STATE_CAR
Jeff Brownc0347aa2011-09-23 17:26:09 -07006158 && (mCarDockEnablesAccelerometer || mCarDockRotation >= 0)) {
Jeff Brown01a98dd2011-09-20 15:08:29 -07006159 // Ignore sensor when in car dock unless explicitly enabled.
6160 // This case can override the behavior of NOSENSOR, and can also
6161 // enable 180 degree rotation while docked.
Jeff Brownc0347aa2011-09-23 17:26:09 -07006162 preferredRotation = mCarDockEnablesAccelerometer
Jeff Brown01a98dd2011-09-20 15:08:29 -07006163 ? sensorRotation : mCarDockRotation;
Jeff Brown1a693182011-11-08 14:44:16 -08006164 } else if ((mDockMode == Intent.EXTRA_DOCK_STATE_DESK
6165 || mDockMode == Intent.EXTRA_DOCK_STATE_LE_DESK
6166 || mDockMode == Intent.EXTRA_DOCK_STATE_HE_DESK)
Jeff Brownc0347aa2011-09-23 17:26:09 -07006167 && (mDeskDockEnablesAccelerometer || mDeskDockRotation >= 0)) {
Jeff Brown01a98dd2011-09-20 15:08:29 -07006168 // Ignore sensor when in desk dock unless explicitly enabled.
6169 // This case can override the behavior of NOSENSOR, and can also
6170 // enable 180 degree rotation while docked.
Jeff Brownc0347aa2011-09-23 17:26:09 -07006171 preferredRotation = mDeskDockEnablesAccelerometer
Jeff Brown01a98dd2011-09-20 15:08:29 -07006172 ? sensorRotation : mDeskDockRotation;
Jeff Brownc82c89ed2013-04-17 17:18:15 -07006173 } else if (mHdmiPlugged && mDemoHdmiRotationLock) {
6174 // Ignore sensor when plugged into HDMI when demo HDMI rotation lock enabled.
Jeff Browneb3e4b92011-12-06 19:54:24 -08006175 // Note that the dock orientation overrides the HDMI orientation.
Jeff Brownc82c89ed2013-04-17 17:18:15 -07006176 preferredRotation = mDemoHdmiRotation;
6177 } else if (mHdmiPlugged && mDockMode == Intent.EXTRA_DOCK_STATE_UNDOCKED
6178 && mUndockedHdmiRotation >= 0) {
6179 // Ignore sensor when plugged into HDMI and an undocked orientation has
6180 // been specified in the configuration (only for legacy devices without
6181 // full multi-display support).
6182 // Note that the dock orientation overrides the HDMI orientation.
6183 preferredRotation = mUndockedHdmiRotation;
Chong Zhangae6119ff2014-11-11 18:54:39 -08006184 } else if (mDemoRotationLock) {
6185 // Ignore sensor when demo rotation lock is enabled.
6186 // Note that the dock orientation and HDMI rotation lock override this.
6187 preferredRotation = mDemoRotation;
Dianne Hackbornb9ec1ac2013-04-10 17:34:25 -07006188 } else if (orientation == ActivityInfo.SCREEN_ORIENTATION_LOCKED) {
6189 // Application just wants to remain locked in the last rotation.
6190 preferredRotation = lastRotation;
Jeff Brownbcdfc622014-03-06 19:13:04 -08006191 } else if (!mSupportAutoRotation) {
6192 // If we don't support auto-rotation then bail out here and ignore
6193 // the sensor and any rotation lock settings.
6194 preferredRotation = -1;
Jeff Brown207673cd2012-06-05 17:47:11 -07006195 } else if ((mUserRotationMode == WindowManagerPolicy.USER_ROTATION_FREE
Jeff Brown01a98dd2011-09-20 15:08:29 -07006196 && (orientation == ActivityInfo.SCREEN_ORIENTATION_USER
Dianne Hackbornb9ec1ac2013-04-10 17:34:25 -07006197 || orientation == ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED
6198 || orientation == ActivityInfo.SCREEN_ORIENTATION_USER_LANDSCAPE
6199 || orientation == ActivityInfo.SCREEN_ORIENTATION_USER_PORTRAIT
6200 || orientation == ActivityInfo.SCREEN_ORIENTATION_FULL_USER))
Jeff Brown01a98dd2011-09-20 15:08:29 -07006201 || orientation == ActivityInfo.SCREEN_ORIENTATION_SENSOR
6202 || orientation == ActivityInfo.SCREEN_ORIENTATION_FULL_SENSOR
6203 || orientation == ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE
6204 || orientation == ActivityInfo.SCREEN_ORIENTATION_SENSOR_PORTRAIT) {
6205 // Otherwise, use sensor only if requested by the application or enabled
6206 // by default for USER or UNSPECIFIED modes. Does not apply to NOSENSOR.
Jeff Brownd3187e32011-09-21 19:26:44 -07006207 if (mAllowAllRotations < 0) {
6208 // Can't read this during init() because the context doesn't
6209 // have display metrics at that time so we cannot determine
6210 // tablet vs. phone then.
6211 mAllowAllRotations = mContext.getResources().getBoolean(
6212 com.android.internal.R.bool.config_allowAllRotations) ? 1 : 0;
6213 }
Jeff Brown01a98dd2011-09-20 15:08:29 -07006214 if (sensorRotation != Surface.ROTATION_180
Jeff Brownd3187e32011-09-21 19:26:44 -07006215 || mAllowAllRotations == 1
Dianne Hackbornb9ec1ac2013-04-10 17:34:25 -07006216 || orientation == ActivityInfo.SCREEN_ORIENTATION_FULL_SENSOR
6217 || orientation == ActivityInfo.SCREEN_ORIENTATION_FULL_USER) {
Jeff Brown01a98dd2011-09-20 15:08:29 -07006218 preferredRotation = sensorRotation;
6219 } else {
6220 preferredRotation = lastRotation;
6221 }
Jeff Brown207673cd2012-06-05 17:47:11 -07006222 } else if (mUserRotationMode == WindowManagerPolicy.USER_ROTATION_LOCKED
6223 && orientation != ActivityInfo.SCREEN_ORIENTATION_NOSENSOR) {
6224 // Apply rotation lock. Does not apply to NOSENSOR.
6225 // The idea is that the user rotation expresses a weak preference for the direction
6226 // of gravity and as NOSENSOR is never affected by gravity, then neither should
6227 // NOSENSOR be affected by rotation lock (although it will be affected by docks).
Jeff Brown4dfce202011-10-05 12:00:10 -07006228 preferredRotation = mUserRotation;
Jeff Browndec6cf42011-11-15 14:08:20 -08006229 } else {
6230 // No overriding preference.
6231 // We will do exactly what the application asked us to do.
6232 preferredRotation = -1;
Jeff Brown01a98dd2011-09-20 15:08:29 -07006233 }
6234
Dianne Hackborne5439f22010-10-02 16:53:50 -07006235 switch (orientation) {
6236 case ActivityInfo.SCREEN_ORIENTATION_PORTRAIT:
Jeff Browndec6cf42011-11-15 14:08:20 -08006237 // Return portrait unless overridden.
6238 if (isAnyPortrait(preferredRotation)) {
6239 return preferredRotation;
6240 }
Dianne Hackborne5439f22010-10-02 16:53:50 -07006241 return mPortraitRotation;
Dianne Hackborne5439f22010-10-02 16:53:50 -07006242
Jeff Brown01a98dd2011-09-20 15:08:29 -07006243 case ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE:
Jeff Browndec6cf42011-11-15 14:08:20 -08006244 // Return landscape unless overridden.
6245 if (isLandscapeOrSeascape(preferredRotation)) {
6246 return preferredRotation;
6247 }
Jeff Brown01a98dd2011-09-20 15:08:29 -07006248 return mLandscapeRotation;
6249
6250 case ActivityInfo.SCREEN_ORIENTATION_REVERSE_PORTRAIT:
Jeff Browndec6cf42011-11-15 14:08:20 -08006251 // Return reverse portrait unless overridden.
6252 if (isAnyPortrait(preferredRotation)) {
6253 return preferredRotation;
6254 }
Jeff Brown01a98dd2011-09-20 15:08:29 -07006255 return mUpsideDownRotation;
6256
6257 case ActivityInfo.SCREEN_ORIENTATION_REVERSE_LANDSCAPE:
Jeff Browndec6cf42011-11-15 14:08:20 -08006258 // Return seascape unless overridden.
6259 if (isLandscapeOrSeascape(preferredRotation)) {
6260 return preferredRotation;
6261 }
Jeff Brown01a98dd2011-09-20 15:08:29 -07006262 return mSeascapeRotation;
6263
6264 case ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE:
Dianne Hackbornb9ec1ac2013-04-10 17:34:25 -07006265 case ActivityInfo.SCREEN_ORIENTATION_USER_LANDSCAPE:
Jeff Brown01a98dd2011-09-20 15:08:29 -07006266 // Return either landscape rotation.
6267 if (isLandscapeOrSeascape(preferredRotation)) {
6268 return preferredRotation;
6269 }
6270 if (isLandscapeOrSeascape(lastRotation)) {
Jeff Brown4519f072011-01-23 13:16:01 -08006271 return lastRotation;
6272 }
Jeff Brown01a98dd2011-09-20 15:08:29 -07006273 return mLandscapeRotation;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006274
Jeff Brown01a98dd2011-09-20 15:08:29 -07006275 case ActivityInfo.SCREEN_ORIENTATION_SENSOR_PORTRAIT:
Dianne Hackbornb9ec1ac2013-04-10 17:34:25 -07006276 case ActivityInfo.SCREEN_ORIENTATION_USER_PORTRAIT:
Jeff Brown01a98dd2011-09-20 15:08:29 -07006277 // Return either portrait rotation.
6278 if (isAnyPortrait(preferredRotation)) {
6279 return preferredRotation;
6280 }
6281 if (isAnyPortrait(lastRotation)) {
6282 return lastRotation;
6283 }
6284 return mPortraitRotation;
6285
6286 default:
Jeff Brown4dfce202011-10-05 12:00:10 -07006287 // For USER, UNSPECIFIED, NOSENSOR, SENSOR and FULL_SENSOR,
6288 // just return the preferred orientation we already calculated.
Jeff Brown01a98dd2011-09-20 15:08:29 -07006289 if (preferredRotation >= 0) {
6290 return preferredRotation;
6291 }
Dianne Hackborndacea8c2011-04-21 17:26:39 -07006292 return Surface.ROTATION_0;
Daniel Sandlere7e5ac22011-02-22 16:10:21 -05006293 }
6294 }
Steve Howarda7bfe6a2010-09-23 16:47:49 -07006295 }
6296
Jeff Brown01a98dd2011-09-20 15:08:29 -07006297 @Override
6298 public boolean rotationHasCompatibleMetricsLw(int orientation, int rotation) {
6299 switch (orientation) {
6300 case ActivityInfo.SCREEN_ORIENTATION_PORTRAIT:
6301 case ActivityInfo.SCREEN_ORIENTATION_REVERSE_PORTRAIT:
6302 case ActivityInfo.SCREEN_ORIENTATION_SENSOR_PORTRAIT:
6303 return isAnyPortrait(rotation);
6304
6305 case ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE:
6306 case ActivityInfo.SCREEN_ORIENTATION_REVERSE_LANDSCAPE:
6307 case ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE:
6308 return isLandscapeOrSeascape(rotation);
6309
6310 default:
6311 return true;
6312 }
Steve Howarda7bfe6a2010-09-23 16:47:49 -07006313 }
6314
Jeff Brownc0347aa2011-09-23 17:26:09 -07006315 @Override
6316 public void setRotationLw(int rotation) {
6317 mOrientationListener.setCurrentRotation(rotation);
6318 }
6319
Jeff Brown01a98dd2011-09-20 15:08:29 -07006320 private boolean isLandscapeOrSeascape(int rotation) {
6321 return rotation == mLandscapeRotation || rotation == mSeascapeRotation;
Dianne Hackborne5439f22010-10-02 16:53:50 -07006322 }
6323
Jeff Brown01a98dd2011-09-20 15:08:29 -07006324 private boolean isAnyPortrait(int rotation) {
6325 return rotation == mPortraitRotation || rotation == mUpsideDownRotation;
Dianne Hackborne5439f22010-10-02 16:53:50 -07006326 }
6327
Jose Lima9546b202014-07-02 17:21:51 -07006328 @Override
Svetoslav Ganov80943d82013-01-02 10:25:37 -08006329 public int getUserRotationMode() {
6330 return Settings.System.getIntForUser(mContext.getContentResolver(),
Brett Chabot7e55c402013-05-16 19:38:08 -07006331 Settings.System.ACCELEROMETER_ROTATION, 0, UserHandle.USER_CURRENT) != 0 ?
6332 WindowManagerPolicy.USER_ROTATION_FREE :
6333 WindowManagerPolicy.USER_ROTATION_LOCKED;
Svetoslav Ganov80943d82013-01-02 10:25:37 -08006334 }
Daniel Sandlerb73617d2010-08-17 00:41:00 -04006335
6336 // User rotation: to be used when all else fails in assigning an orientation to the device
Jose Lima9546b202014-07-02 17:21:51 -07006337 @Override
Daniel Sandlerb73617d2010-08-17 00:41:00 -04006338 public void setUserRotationMode(int mode, int rot) {
6339 ContentResolver res = mContext.getContentResolver();
Daniel Sandler2ed6ad62011-02-22 14:54:17 -05006340
6341 // mUserRotationMode and mUserRotation will be assigned by the content observer
Daniel Sandlerb73617d2010-08-17 00:41:00 -04006342 if (mode == WindowManagerPolicy.USER_ROTATION_LOCKED) {
Christopher Tate5e08af02012-09-21 17:17:22 -07006343 Settings.System.putIntForUser(res,
Daniel Sandlerb73617d2010-08-17 00:41:00 -04006344 Settings.System.USER_ROTATION,
Christopher Tate5e08af02012-09-21 17:17:22 -07006345 rot,
6346 UserHandle.USER_CURRENT);
6347 Settings.System.putIntForUser(res,
Daniel Sandler2ed6ad62011-02-22 14:54:17 -05006348 Settings.System.ACCELEROMETER_ROTATION,
Christopher Tate5e08af02012-09-21 17:17:22 -07006349 0,
6350 UserHandle.USER_CURRENT);
Daniel Sandlerb73617d2010-08-17 00:41:00 -04006351 } else {
Christopher Tate5e08af02012-09-21 17:17:22 -07006352 Settings.System.putIntForUser(res,
Daniel Sandlerb73617d2010-08-17 00:41:00 -04006353 Settings.System.ACCELEROMETER_ROTATION,
Christopher Tate5e08af02012-09-21 17:17:22 -07006354 1,
6355 UserHandle.USER_CURRENT);
Daniel Sandlerb73617d2010-08-17 00:41:00 -04006356 }
6357 }
6358
Jose Lima9546b202014-07-02 17:21:51 -07006359 @Override
Jeff Brownac143512012-04-05 18:57:33 -07006360 public void setSafeMode(boolean safeMode) {
6361 mSafeMode = safeMode;
6362 performHapticFeedbackLw(null, safeMode
6363 ? HapticFeedbackConstants.SAFE_MODE_ENABLED
6364 : HapticFeedbackConstants.SAFE_MODE_DISABLED, true);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006365 }
Craig Mautnereda67292013-04-28 13:50:14 -07006366
Dianne Hackborn181ceb52009-08-27 22:16:40 -07006367 static long[] getLongIntArray(Resources r, int resid) {
6368 int[] ar = r.getIntArray(resid);
6369 if (ar == null) {
6370 return null;
6371 }
6372 long[] out = new long[ar.length];
6373 for (int i=0; i<ar.length; i++) {
6374 out[i] = ar[i];
6375 }
6376 return out;
6377 }
Craig Mautnereda67292013-04-28 13:50:14 -07006378
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006379 /** {@inheritDoc} */
Craig Mautnereda67292013-04-28 13:50:14 -07006380 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006381 public void systemReady() {
Jim Millerab954542014-10-10 18:21:49 -07006382 mKeyguardDelegate = new KeyguardServiceDelegate(mContext);
Mike Lockwooded8902d2013-11-15 11:01:47 -08006383 mKeyguardDelegate.onSystemReady();
6384
Michael Wright3818c922014-09-02 13:59:07 -07006385 readCameraLensCoverState();
Jeff Brown4f5fa282014-06-12 19:19:15 -07006386 updateUiMode();
Adrian Roos3542f7d2015-07-13 15:57:53 -07006387 boolean bindKeyguardNow;
Dianne Hackbornb1a79802009-09-29 15:18:31 -07006388 synchronized (mLock) {
6389 updateOrientationListenerLp();
Dianne Hackbornc777e072010-02-12 13:07:59 -08006390 mSystemReady = true;
6391 mHandler.post(new Runnable() {
Craig Mautnereda67292013-04-28 13:50:14 -07006392 @Override
Dianne Hackbornc777e072010-02-12 13:07:59 -08006393 public void run() {
6394 updateSettings();
6395 }
6396 });
Adrian Roos3542f7d2015-07-13 15:57:53 -07006397
6398 bindKeyguardNow = mDeferBindKeyguard;
6399 if (bindKeyguardNow) {
6400 // systemBooted ran but wasn't able to bind to the Keyguard, we'll do it now.
6401 mDeferBindKeyguard = false;
6402 }
6403 }
6404
6405 if (bindKeyguardNow) {
6406 mKeyguardDelegate.bindService(mContext);
6407 mKeyguardDelegate.onBootCompleted();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006408 }
Michael Wrighta4d22d72015-09-16 23:19:26 +01006409 mSystemGestures.systemReady();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006410 }
Dianne Hackborn661cd522011-08-22 00:26:20 -07006411
Dianne Hackbornba24e4d2011-09-01 11:17:06 -07006412 /** {@inheritDoc} */
Jose Lima9546b202014-07-02 17:21:51 -07006413 @Override
Dianne Hackbornba24e4d2011-09-01 11:17:06 -07006414 public void systemBooted() {
Adrian Roos3542f7d2015-07-13 15:57:53 -07006415 boolean bindKeyguardNow = false;
6416 synchronized (mLock) {
6417 // Time to bind Keyguard; take care to only bind it once, either here if ready or
6418 // in systemReady if not.
6419 if (mKeyguardDelegate != null) {
6420 bindKeyguardNow = true;
6421 } else {
6422 // Because mKeyguardDelegate is null, we know that the synchronized block in
6423 // systemReady didn't run yet and setting this will actually have an effect.
6424 mDeferBindKeyguard = true;
6425 }
6426 }
6427 if (bindKeyguardNow) {
Jason Monk5eeebf52014-09-26 12:36:51 -04006428 mKeyguardDelegate.bindService(mContext);
Jim Millere5f910a2013-10-16 18:15:46 -07006429 mKeyguardDelegate.onBootCompleted();
6430 }
Dianne Hackbornba24e4d2011-09-01 11:17:06 -07006431 synchronized (mLock) {
6432 mSystemBooted = true;
6433 }
Jeff Brown416c49c2015-05-26 19:50:18 -07006434 startedWakingUp();
Jeff Brown36c4db82014-09-19 12:05:31 -07006435 screenTurningOn(null);
Jorim Jaggic0496072015-08-19 15:14:52 -07006436 screenTurnedOn();
Dianne Hackbornba24e4d2011-09-01 11:17:06 -07006437 }
6438
Dianne Hackborn661cd522011-08-22 00:26:20 -07006439 ProgressDialog mBootMsgDialog = null;
6440
6441 /** {@inheritDoc} */
Jose Lima9546b202014-07-02 17:21:51 -07006442 @Override
Dianne Hackborn661cd522011-08-22 00:26:20 -07006443 public void showBootMessage(final CharSequence msg, final boolean always) {
6444 mHandler.post(new Runnable() {
6445 @Override public void run() {
6446 if (mBootMsgDialog == null) {
Craig Stout4c0cb8a2014-04-04 13:03:10 -07006447 int theme;
Jaewan Kim49117872016-01-19 17:24:08 +09006448 if (mContext.getPackageManager().hasSystemFeature(FEATURE_WATCH)) {
Craig Stout4c0cb8a2014-04-04 13:03:10 -07006449 theme = com.android.internal.R.style.Theme_Micro_Dialog_Alert;
Jaewan Kim49117872016-01-19 17:24:08 +09006450 } else if (mContext.getPackageManager().hasSystemFeature(FEATURE_TELEVISION)) {
Craig Stout4c0cb8a2014-04-04 13:03:10 -07006451 theme = com.android.internal.R.style.Theme_Leanback_Dialog_Alert;
6452 } else {
6453 theme = 0;
6454 }
Vinod Krishnanfa8fc412014-04-18 14:35:53 -07006455
6456 mBootMsgDialog = new ProgressDialog(mContext, theme) {
Dianne Hackborn295e3c22011-08-25 13:19:08 -07006457 // This dialog will consume all events coming in to
6458 // it, to avoid it trying to do things too early in boot.
6459 @Override public boolean dispatchKeyEvent(KeyEvent event) {
6460 return true;
6461 }
6462 @Override public boolean dispatchKeyShortcutEvent(KeyEvent event) {
6463 return true;
6464 }
6465 @Override public boolean dispatchTouchEvent(MotionEvent ev) {
6466 return true;
6467 }
6468 @Override public boolean dispatchTrackballEvent(MotionEvent ev) {
6469 return true;
6470 }
6471 @Override public boolean dispatchGenericMotionEvent(MotionEvent ev) {
6472 return true;
6473 }
6474 @Override public boolean dispatchPopulateAccessibilityEvent(
6475 AccessibilityEvent event) {
6476 return true;
6477 }
6478 };
Jeff Hao9f60c082014-10-28 18:51:07 -07006479 if (mContext.getPackageManager().isUpgrade()) {
6480 mBootMsgDialog.setTitle(R.string.android_upgrading_title);
6481 } else {
6482 mBootMsgDialog.setTitle(R.string.android_start_title);
6483 }
Dianne Hackborn661cd522011-08-22 00:26:20 -07006484 mBootMsgDialog.setProgressStyle(ProgressDialog.STYLE_SPINNER);
6485 mBootMsgDialog.setIndeterminate(true);
6486 mBootMsgDialog.getWindow().setType(
Dianne Hackborn29aae6f2011-08-18 18:30:09 -07006487 WindowManager.LayoutParams.TYPE_BOOT_PROGRESS);
Dianne Hackborn661cd522011-08-22 00:26:20 -07006488 mBootMsgDialog.getWindow().addFlags(
6489 WindowManager.LayoutParams.FLAG_DIM_BEHIND
6490 | WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN);
6491 mBootMsgDialog.getWindow().setDimAmount(1);
Dianne Hackbornd9efb952011-12-07 14:56:51 -08006492 WindowManager.LayoutParams lp = mBootMsgDialog.getWindow().getAttributes();
6493 lp.screenOrientation = ActivityInfo.SCREEN_ORIENTATION_NOSENSOR;
6494 mBootMsgDialog.getWindow().setAttributes(lp);
Dianne Hackborn661cd522011-08-22 00:26:20 -07006495 mBootMsgDialog.setCancelable(false);
6496 mBootMsgDialog.show();
6497 }
6498 mBootMsgDialog.setMessage(msg);
6499 }
6500 });
6501 }
6502
6503 /** {@inheritDoc} */
Jose Lima9546b202014-07-02 17:21:51 -07006504 @Override
Dianne Hackborn661cd522011-08-22 00:26:20 -07006505 public void hideBootMessages() {
Craig Mautnera631d492014-08-05 15:16:01 -07006506 mHandler.sendEmptyMessage(MSG_HIDE_BOOT_MESSAGE);
Dianne Hackborn661cd522011-08-22 00:26:20 -07006507 }
6508
Mike Lockwood28569302010-01-28 11:54:40 -05006509 /** {@inheritDoc} */
Jose Lima9546b202014-07-02 17:21:51 -07006510 @Override
Mike Lockwood28569302010-01-28 11:54:40 -05006511 public void userActivity() {
Dianne Hackborndf89e652011-10-06 22:35:11 -07006512 // ***************************************
6513 // NOTE NOTE NOTE NOTE NOTE NOTE NOTE NOTE
6514 // ***************************************
6515 // THIS IS CALLED FROM DEEP IN THE POWER MANAGER
6516 // WITH ITS LOCKS HELD.
6517 //
6518 // This code must be VERY careful about the locks
6519 // it acquires.
6520 // In fact, the current code acquires way too many,
6521 // and probably has lurking deadlocks.
6522
Mike Lockwood28569302010-01-28 11:54:40 -05006523 synchronized (mScreenLockTimeout) {
6524 if (mLockScreenTimerActive) {
6525 // reset the timer
6526 mHandler.removeCallbacks(mScreenLockTimeout);
6527 mHandler.postDelayed(mScreenLockTimeout, mLockScreenTimeout);
6528 }
6529 }
Daniel Sandler0601eb72011-04-13 01:01:32 -04006530 }
6531
Adam Cohenf7522022012-10-03 20:03:18 -07006532 class ScreenLockTimeout implements Runnable {
6533 Bundle options;
6534
6535 @Override
Mike Lockwood28569302010-01-28 11:54:40 -05006536 public void run() {
6537 synchronized (this) {
6538 if (localLOGV) Log.v(TAG, "mScreenLockTimeout activating keyguard");
Jim Miller5ecd8112013-01-09 18:50:26 -08006539 if (mKeyguardDelegate != null) {
6540 mKeyguardDelegate.doKeyguardTimeout(options);
Mike Lockwood3a74bd32011-08-12 13:55:22 -07006541 }
Mike Lockwood28569302010-01-28 11:54:40 -05006542 mLockScreenTimerActive = false;
Adam Cohenf7522022012-10-03 20:03:18 -07006543 options = null;
Mike Lockwood28569302010-01-28 11:54:40 -05006544 }
6545 }
Mike Lockwood28569302010-01-28 11:54:40 -05006546
Adam Cohenf7522022012-10-03 20:03:18 -07006547 public void setLockOptions(Bundle options) {
6548 this.options = options;
6549 }
6550 }
6551
6552 ScreenLockTimeout mScreenLockTimeout = new ScreenLockTimeout();
6553
Jose Lima9546b202014-07-02 17:21:51 -07006554 @Override
Adam Cohenf7522022012-10-03 20:03:18 -07006555 public void lockNow(Bundle options) {
Jim Miller93c518e2012-01-17 15:55:31 -08006556 mContext.enforceCallingOrSelfPermission(android.Manifest.permission.DEVICE_POWER, null);
6557 mHandler.removeCallbacks(mScreenLockTimeout);
Adam Cohenf7522022012-10-03 20:03:18 -07006558 if (options != null) {
6559 // In case multiple calls are made to lockNow, we don't wipe out the options
6560 // until the runnable actually executes.
6561 mScreenLockTimeout.setLockOptions(options);
6562 }
Jim Miller93c518e2012-01-17 15:55:31 -08006563 mHandler.post(mScreenLockTimeout);
6564 }
6565
Mike Lockwood28569302010-01-28 11:54:40 -05006566 private void updateLockScreenTimeout() {
6567 synchronized (mScreenLockTimeout) {
Jeff Brown3ee549c2014-09-22 20:14:39 -07006568 boolean enable = (mAllowLockscreenWhenOn && mAwake &&
Jim Miller5ecd8112013-01-09 18:50:26 -08006569 mKeyguardDelegate != null && mKeyguardDelegate.isSecure());
Mike Lockwood28569302010-01-28 11:54:40 -05006570 if (mLockScreenTimerActive != enable) {
6571 if (enable) {
6572 if (localLOGV) Log.v(TAG, "setting lockscreen timer");
Jim Miller2967f482016-01-07 15:05:32 -08006573 mHandler.removeCallbacks(mScreenLockTimeout); // remove any pending requests
Mike Lockwood28569302010-01-28 11:54:40 -05006574 mHandler.postDelayed(mScreenLockTimeout, mLockScreenTimeout);
6575 } else {
6576 if (localLOGV) Log.v(TAG, "clearing lockscreen timer");
6577 mHandler.removeCallbacks(mScreenLockTimeout);
6578 }
6579 mLockScreenTimerActive = enable;
6580 }
6581 }
6582 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006583
Jeff Brown061ea992015-04-17 19:55:47 -07006584 private void updateDreamingSleepToken(boolean acquire) {
6585 if (acquire) {
6586 if (mDreamingSleepToken == null) {
6587 mDreamingSleepToken = mActivityManagerInternal.acquireSleepToken("Dream");
6588 }
6589 } else {
6590 if (mDreamingSleepToken != null) {
6591 mDreamingSleepToken.release();
Jeff Brown48d1b142015-06-10 16:36:03 -07006592 mDreamingSleepToken = null;
6593 }
6594 }
6595 }
6596
6597 private void updateScreenOffSleepToken(boolean acquire) {
6598 if (acquire) {
6599 if (mScreenOffSleepToken == null) {
6600 mScreenOffSleepToken = mActivityManagerInternal.acquireSleepToken("ScreenOff");
6601 }
6602 } else {
6603 if (mScreenOffSleepToken != null) {
6604 mScreenOffSleepToken.release();
6605 mScreenOffSleepToken = null;
Jeff Brown061ea992015-04-17 19:55:47 -07006606 }
6607 }
6608 }
6609
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006610 /** {@inheritDoc} */
Craig Mautnereda67292013-04-28 13:50:14 -07006611 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006612 public void enableScreenAfterBoot() {
6613 readLidState();
Jeff Brownc458ce92012-04-30 14:58:40 -07006614 applyLidSwitchState();
Jeff Brown01a98dd2011-09-20 15:08:29 -07006615 updateRotation(true);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006616 }
Dianne Hackbornf54c8f92009-09-19 14:03:57 -07006617
Jeff Brownc458ce92012-04-30 14:58:40 -07006618 private void applyLidSwitchState() {
Jeff Brownc458ce92012-04-30 14:58:40 -07006619 if (mLidState == LID_CLOSED && mLidControlsSleep) {
Jeff Brown6d8fd272014-05-20 21:24:38 -07006620 mPowerManager.goToSleep(SystemClock.uptimeMillis(),
Jeff Brownc12035c2014-08-13 18:52:25 -07006621 PowerManager.GO_TO_SLEEP_REASON_LID_SWITCH,
Jeff Brown6d8fd272014-05-20 21:24:38 -07006622 PowerManager.GO_TO_SLEEP_FLAG_NO_DOZE);
Edward Savage-Jones7def60d2015-11-13 13:27:03 +01006623 } else if (mLidState == LID_CLOSED && mLidControlsScreenLock) {
6624 mWindowManagerFuncs.lockDeviceNow();
Jeff Brownc458ce92012-04-30 14:58:40 -07006625 }
Jeff Browna20dda42014-05-27 20:57:24 -07006626
6627 synchronized (mLock) {
6628 updateWakeGestureListenerLp();
6629 }
Jeff Brown01a98dd2011-09-20 15:08:29 -07006630 }
6631
Jeff Brown4f5fa282014-06-12 19:19:15 -07006632 void updateUiMode() {
6633 if (mUiModeManager == null) {
6634 mUiModeManager = IUiModeManager.Stub.asInterface(
6635 ServiceManager.getService(Context.UI_MODE_SERVICE));
6636 }
6637 try {
6638 mUiMode = mUiModeManager.getCurrentModeType();
6639 } catch (RemoteException e) {
6640 }
6641 }
6642
Jeff Brown01a98dd2011-09-20 15:08:29 -07006643 void updateRotation(boolean alwaysSendConfiguration) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006644 try {
6645 //set orientation on WindowManager
Dianne Hackbornf87d1962012-04-04 12:48:24 -07006646 mWindowManager.updateRotation(alwaysSendConfiguration, false);
6647 } catch (RemoteException e) {
6648 // Ignore
6649 }
6650 }
6651
6652 void updateRotation(boolean alwaysSendConfiguration, boolean forceRelayout) {
6653 try {
6654 //set orientation on WindowManager
6655 mWindowManager.updateRotation(alwaysSendConfiguration, forceRelayout);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006656 } catch (RemoteException e) {
6657 // Ignore
6658 }
6659 }
6660
Daniel Sandler6396c722013-04-16 20:19:09 -04006661 /**
6662 * Return an Intent to launch the currently active dock app as home. Returns
6663 * null if the standard home should be launched, which is the case if any of the following is
6664 * true:
6665 * <ul>
6666 * <li>The device is not in either car mode or desk mode
keunyounga7710492015-09-23 11:33:58 -07006667 * <li>The device is in car mode but mEnableCarDockHomeCapture is false
Daniel Sandler6396c722013-04-16 20:19:09 -04006668 * <li>The device is in desk mode but ENABLE_DESK_DOCK_HOME_CAPTURE is false
6669 * <li>The device is in car mode but there's no CAR_DOCK app with METADATA_DOCK_HOME
6670 * <li>The device is in desk mode but there's no DESK_DOCK app with METADATA_DOCK_HOME
6671 * </ul>
Craig Mautnereda67292013-04-28 13:50:14 -07006672 * @return A dock intent.
Daniel Sandler6396c722013-04-16 20:19:09 -04006673 */
6674 Intent createHomeDockIntent() {
6675 Intent intent = null;
6676
6677 // What home does is based on the mode, not the dock state. That
6678 // is, when in car mode you should be taken to car home regardless
6679 // of whether we are actually in a car dock.
6680 if (mUiMode == Configuration.UI_MODE_TYPE_CAR) {
keunyounga7710492015-09-23 11:33:58 -07006681 if (mEnableCarDockHomeCapture) {
Daniel Sandler6396c722013-04-16 20:19:09 -04006682 intent = mCarDockIntent;
6683 }
6684 } else if (mUiMode == Configuration.UI_MODE_TYPE_DESK) {
6685 if (ENABLE_DESK_DOCK_HOME_CAPTURE) {
6686 intent = mDeskDockIntent;
6687 }
Jeff Brown4f5fa282014-06-12 19:19:15 -07006688 } else if (mUiMode == Configuration.UI_MODE_TYPE_WATCH
6689 && (mDockMode == Intent.EXTRA_DOCK_STATE_DESK
6690 || mDockMode == Intent.EXTRA_DOCK_STATE_HE_DESK
6691 || mDockMode == Intent.EXTRA_DOCK_STATE_LE_DESK)) {
6692 // Always launch dock home from home when watch is docked, if it exists.
6693 intent = mDeskDockIntent;
Daniel Sandler6396c722013-04-16 20:19:09 -04006694 }
6695
6696 if (intent == null) {
6697 return null;
6698 }
6699
6700 ActivityInfo ai = null;
6701 ResolveInfo info = mContext.getPackageManager().resolveActivityAsUser(
6702 intent,
John Spurlockf56bef12013-07-09 09:51:46 -04006703 PackageManager.MATCH_DEFAULT_ONLY | PackageManager.GET_META_DATA,
Craig Mautnerd625ab22013-09-06 13:40:31 -07006704 mCurrentUserId);
Daniel Sandler6396c722013-04-16 20:19:09 -04006705 if (info != null) {
6706 ai = info.activityInfo;
6707 }
6708 if (ai != null
6709 && ai.metaData != null
6710 && ai.metaData.getBoolean(Intent.METADATA_DOCK_HOME)) {
6711 intent = new Intent(intent);
6712 intent.setClassName(ai.packageName, ai.name);
6713 return intent;
6714 }
6715
6716 return null;
6717 }
6718
Filip Gruszczynskia483a1d2015-03-17 19:06:58 +00006719 void startDockOrHome(boolean fromHomeKey, boolean awakenFromDreams) {
6720 if (awakenFromDreams) {
6721 awakenDreams();
6722 }
Daniel Sandler6396c722013-04-16 20:19:09 -04006723
6724 Intent dock = createHomeDockIntent();
6725 if (dock != null) {
6726 try {
Bryce Lee01b0c5f2015-02-05 18:24:04 -08006727 if (fromHomeKey) {
6728 dock.putExtra(WindowManagerPolicy.EXTRA_FROM_HOME_KEY, fromHomeKey);
6729 }
Bart Sears8b1c27c2015-03-18 23:51:02 +00006730 startActivityAsUser(dock, UserHandle.CURRENT);
Daniel Sandler6396c722013-04-16 20:19:09 -04006731 return;
6732 } catch (ActivityNotFoundException e) {
6733 }
6734 }
6735
Bryce Lee01b0c5f2015-02-05 18:24:04 -08006736 Intent intent;
6737
6738 if (fromHomeKey) {
6739 intent = new Intent(mHomeIntent);
6740 intent.putExtra(WindowManagerPolicy.EXTRA_FROM_HOME_KEY, fromHomeKey);
6741 } else {
6742 intent = mHomeIntent;
6743 }
6744
Bryce Lee9fc0b6f2015-03-19 21:37:45 +00006745 startActivityAsUser(intent, UserHandle.CURRENT);
Dianne Hackborn39c2d712009-09-22 11:41:31 -07006746 }
Craig Mautnereda67292013-04-28 13:50:14 -07006747
Dianne Hackborn39c2d712009-09-22 11:41:31 -07006748 /**
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006749 * goes to the home screen
6750 * @return whether it did anything
6751 */
6752 boolean goHome() {
Bart Sears8b1c27c2015-03-18 23:51:02 +00006753 if (!isUserSetupComplete()) {
6754 Slog.i(TAG, "Not going home because user setup is in progress.");
6755 return false;
6756 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006757 if (false) {
6758 // This code always brings home to the front.
Dianne Hackborn256dd3b2009-05-19 18:51:21 -07006759 try {
6760 ActivityManagerNative.getDefault().stopAppSwitches();
6761 } catch (RemoteException e) {
6762 }
Dianne Hackborn94a679d2009-07-28 17:51:07 -07006763 sendCloseSystemWindows();
Filip Gruszczynskia483a1d2015-03-17 19:06:58 +00006764 startDockOrHome(false /*fromHomeKey*/, true /* awakenFromDreams */);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006765 } else {
6766 // This code brings home to the front or, if it is already
6767 // at the front, puts the device to sleep.
6768 try {
Wink Savilled2e6a332010-02-12 12:12:06 -08006769 if (SystemProperties.getInt("persist.sys.uts-test-mode", 0) == 1) {
6770 /// Roll back EndcallBehavior as the cupcake design to pass P1 lab entry.
6771 Log.d(TAG, "UTS-TEST-MODE");
6772 } else {
6773 ActivityManagerNative.getDefault().stopAppSwitches();
6774 sendCloseSystemWindows();
Daniel Sandler6396c722013-04-16 20:19:09 -04006775 Intent dock = createHomeDockIntent();
6776 if (dock != null) {
6777 int result = ActivityManagerNative.getDefault()
6778 .startActivityAsUser(null, null, dock,
6779 dock.resolveTypeIfNeeded(mContext.getContentResolver()),
6780 null, null, 0,
6781 ActivityManager.START_FLAG_ONLY_IF_NEEDED,
Jeff Hao1b012d32014-08-20 10:35:34 -07006782 null, null, UserHandle.USER_CURRENT);
Daniel Sandler6396c722013-04-16 20:19:09 -04006783 if (result == ActivityManager.START_RETURN_INTENT_TO_CALLER) {
6784 return false;
6785 }
6786 }
Dianne Hackborn39c2d712009-09-22 11:41:31 -07006787 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006788 int result = ActivityManagerNative.getDefault()
Dianne Hackbornf265ea92013-01-31 15:00:51 -08006789 .startActivityAsUser(null, null, mHomeIntent,
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006790 mHomeIntent.resolveTypeIfNeeded(mContext.getContentResolver()),
Dianne Hackborna4972e92012-03-14 10:38:05 -07006791 null, null, 0,
6792 ActivityManager.START_FLAG_ONLY_IF_NEEDED,
Jeff Hao1b012d32014-08-20 10:35:34 -07006793 null, null, UserHandle.USER_CURRENT);
Dianne Hackborna4972e92012-03-14 10:38:05 -07006794 if (result == ActivityManager.START_RETURN_INTENT_TO_CALLER) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006795 return false;
6796 }
6797 } catch (RemoteException ex) {
6798 // bummer, the activity manager, which is in this process, is dead
6799 }
6800 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006801 return true;
6802 }
Craig Mautnereda67292013-04-28 13:50:14 -07006803
6804 @Override
The Android Open Source Project0727d222009-03-11 12:11:58 -07006805 public void setCurrentOrientationLw(int newOrientation) {
6806 synchronized (mLock) {
6807 if (newOrientation != mCurrentAppOrientation) {
6808 mCurrentAppOrientation = newOrientation;
6809 updateOrientationListenerLp();
6810 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006811 }
6812 }
Amith Yamasanic33cb712010-02-10 15:21:49 -08006813
Svetoslav Ganov7befb7d2012-09-27 16:49:23 -07006814 private void performAuditoryFeedbackForAccessibilityIfNeed() {
6815 if (!isGlobalAccessibilityGestureEnabled()) {
6816 return;
6817 }
6818 AudioManager audioManager = (AudioManager) mContext.getSystemService(
6819 Context.AUDIO_SERVICE);
6820 if (audioManager.isSilentMode()) {
6821 return;
6822 }
6823 Ringtone ringTone = RingtoneManager.getRingtone(mContext,
6824 Settings.System.DEFAULT_NOTIFICATION_URI);
6825 ringTone.setStreamType(AudioManager.STREAM_MUSIC);
6826 ringTone.play();
6827 }
Craig Mautnereda67292013-04-28 13:50:14 -07006828
Bryce Lee584a4452014-10-21 15:55:55 -07006829 private boolean isTheaterModeEnabled() {
6830 return Settings.Global.getInt(mContext.getContentResolver(),
6831 Settings.Global.THEATER_MODE_ON, 0) == 1;
6832 }
6833
Svetoslav Ganov7befb7d2012-09-27 16:49:23 -07006834 private boolean isGlobalAccessibilityGestureEnabled() {
6835 return Settings.Global.getInt(mContext.getContentResolver(),
6836 Settings.Global.ENABLE_ACCESSIBILITY_GLOBAL_GESTURE_ENABLED, 0) == 1;
6837 }
6838
Craig Mautnereda67292013-04-28 13:50:14 -07006839 @Override
The Android Open Source Project0727d222009-03-11 12:11:58 -07006840 public boolean performHapticFeedbackLw(WindowState win, int effectId, boolean always) {
Svetoslav Ganov96179212012-10-10 14:17:45 -07006841 if (!mVibrator.hasVibrator()) {
6842 return false;
6843 }
Christopher Tate5e08af02012-09-21 17:17:22 -07006844 final boolean hapticsDisabled = Settings.System.getIntForUser(mContext.getContentResolver(),
6845 Settings.System.HAPTIC_FEEDBACK_ENABLED, 0, UserHandle.USER_CURRENT) == 0;
Jeff Brown82379ba2014-07-25 19:03:28 -07006846 if (hapticsDisabled && !always) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006847 return false;
6848 }
Amith Yamasanic33cb712010-02-10 15:21:49 -08006849 long[] pattern = null;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006850 switch (effectId) {
6851 case HapticFeedbackConstants.LONG_PRESS:
Amith Yamasanic33cb712010-02-10 15:21:49 -08006852 pattern = mLongPressVibePattern;
6853 break;
Dianne Hackbornb1a79802009-09-29 15:18:31 -07006854 case HapticFeedbackConstants.VIRTUAL_KEY:
Amith Yamasanic33cb712010-02-10 15:21:49 -08006855 pattern = mVirtualKeyVibePattern;
6856 break;
6857 case HapticFeedbackConstants.KEYBOARD_TAP:
6858 pattern = mKeyboardTapVibePattern;
6859 break;
Fabrice Di Meglioeeff63a2013-08-05 12:07:24 -07006860 case HapticFeedbackConstants.CLOCK_TICK:
6861 pattern = mClockTickVibePattern;
6862 break;
Fabrice Di Megliobd9152f2013-10-01 11:21:31 -07006863 case HapticFeedbackConstants.CALENDAR_DATE:
6864 pattern = mCalendarDateVibePattern;
6865 break;
Dianne Hackbornb1a79802009-09-29 15:18:31 -07006866 case HapticFeedbackConstants.SAFE_MODE_DISABLED:
Amith Yamasanic33cb712010-02-10 15:21:49 -08006867 pattern = mSafeModeDisabledVibePattern;
6868 break;
Dianne Hackbornb1a79802009-09-29 15:18:31 -07006869 case HapticFeedbackConstants.SAFE_MODE_ENABLED:
Amith Yamasanic33cb712010-02-10 15:21:49 -08006870 pattern = mSafeModeEnabledVibePattern;
6871 break;
Mady Mellore8608912015-06-05 09:02:55 -07006872 case HapticFeedbackConstants.CONTEXT_CLICK:
6873 pattern = mContextClickVibePattern;
Mady Mellore82067b2015-04-30 09:58:35 -07006874 break;
Amith Yamasanic33cb712010-02-10 15:21:49 -08006875 default:
6876 return false;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006877 }
Dianne Hackbornf265ea92013-01-31 15:00:51 -08006878 int owningUid;
6879 String owningPackage;
6880 if (win != null) {
6881 owningUid = win.getOwningUid();
6882 owningPackage = win.getOwningPackage();
6883 } else {
6884 owningUid = android.os.Process.myUid();
Dianne Hackborn95d78532013-09-11 09:51:14 -07006885 owningPackage = mContext.getOpPackageName();
Dianne Hackbornf265ea92013-01-31 15:00:51 -08006886 }
Amith Yamasanic33cb712010-02-10 15:21:49 -08006887 if (pattern.length == 1) {
6888 // One-shot vibration
John Spurlock7b414672014-07-18 13:02:39 -04006889 mVibrator.vibrate(owningUid, owningPackage, pattern[0], VIBRATION_ATTRIBUTES);
Amith Yamasanic33cb712010-02-10 15:21:49 -08006890 } else {
6891 // Pattern vibration
John Spurlock7b414672014-07-18 13:02:39 -04006892 mVibrator.vibrate(owningUid, owningPackage, pattern, -1, VIBRATION_ATTRIBUTES);
Amith Yamasanic33cb712010-02-10 15:21:49 -08006893 }
6894 return true;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006895 }
Jeff Brownc38c9be2012-10-04 13:16:19 -07006896
6897 @Override
6898 public void keepScreenOnStartedLw() {
Daniel Sandler0601eb72011-04-13 01:01:32 -04006899 }
6900
Jeff Brownc38c9be2012-10-04 13:16:19 -07006901 @Override
6902 public void keepScreenOnStoppedLw() {
Jim Millerab954542014-10-10 18:21:49 -07006903 if (isKeyguardShowingAndNotOccluded()) {
Jim Miller25190572013-02-28 17:36:24 -08006904 mPowerManager.userActivity(SystemClock.uptimeMillis(), false);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006905 }
6906 }
Mike Lockwoodfcb39242009-10-21 23:01:07 -04006907
Dianne Hackborndf89e652011-10-06 22:35:11 -07006908 private int updateSystemUiVisibilityLw() {
Joe Onorato664644d2011-01-23 17:53:23 -08006909 // If there is no window focused, there will be nobody to handle the events
6910 // anyway, so just hang on in whatever state we're in until things settle down.
Adrian Roos53f28ec2014-10-29 17:26:12 +01006911 final WindowState win = mFocusedWindow != null ? mFocusedWindow
6912 : mTopFullscreenOpaqueWindowState;
John Spurlock79da8332013-09-20 12:04:47 -04006913 if (win == null) {
Dianne Hackborndf89e652011-10-06 22:35:11 -07006914 return 0;
6915 }
Jorim Jaggi380ecb82014-03-14 17:25:20 +01006916 if ((win.getAttrs().privateFlags & PRIVATE_FLAG_KEYGUARD) != 0 && mHideLockScreen == true) {
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07006917 // We are updating at a point where the keyguard has gotten
6918 // focus, but we were last in a state where the top window is
6919 // hiding it. This is probably because the keyguard as been
6920 // shown while the top window was displayed, so we want to ignore
6921 // it here because this is just a very transient change and it
6922 // will quickly lose focus once it correctly gets hidden.
6923 return 0;
6924 }
John Spurlock32beb2c2013-03-11 10:16:47 -04006925
John Spurlock1db8b682014-02-18 11:18:59 -05006926 int tmpVisibility = PolicyControl.getSystemUiVisibility(win, null)
Dianne Hackborne26ab702011-10-16 13:21:33 -07006927 & ~mResettingSystemUiFlags
6928 & ~mForceClearedSystemUiFlags;
John Spurlock79da8332013-09-20 12:04:47 -04006929 if (mForcingShowNavBar && win.getSurfaceLayer() < mForcingShowNavBarLayer) {
John Spurlockc6d1c602014-01-17 15:22:06 -05006930 tmpVisibility &= ~PolicyControl.adjustClearableFlags(win, View.SYSTEM_UI_CLEARABLE_FLAGS);
Dianne Hackborn891d3fb2013-01-09 18:31:37 -08006931 }
Thanh Hai Mai6c009f52015-09-01 16:27:32 -07006932
6933 if (mUiMode == Configuration.UI_MODE_TYPE_CAR) {
6934 tmpVisibility |= StatusBarManager.DISABLE_RECENT;
6935 }
6936
Jorim Jaggi86905582016-02-09 21:36:09 -08006937 final int fullscreenVisibility = updateLightStatusBarLw(0 /* vis */,
6938 mTopFullscreenOpaqueWindowState, mTopFullscreenOpaqueOrDimmingWindowState);
6939 final int dockedVisibility = updateLightStatusBarLw(0 /* vis */,
6940 mTopDockedOpaqueWindowState, mTopDockedOpaqueOrDimmingWindowState);
6941 mWindowManagerFuncs.getStackBounds(HOME_STACK_ID, mNonDockedStackBounds);
6942 mWindowManagerFuncs.getStackBounds(DOCKED_STACK_ID, mDockedStackBounds);
John Spurlock79da8332013-09-20 12:04:47 -04006943 final int visibility = updateSystemBarsLw(win, mLastSystemUiFlags, tmpVisibility);
John Spurlockad3e6cb2013-04-30 08:47:43 -04006944 final int diff = visibility ^ mLastSystemUiFlags;
Jorim Jaggi86905582016-02-09 21:36:09 -08006945 final int fullscreenDiff = fullscreenVisibility ^ mLastFullscreenStackSysUiFlags;
6946 final int dockedDiff = dockedVisibility ^ mLastDockedStackSysUiFlags;
John Spurlock79da8332013-09-20 12:04:47 -04006947 final boolean needsMenu = win.getNeedsMenuLw(mTopFullscreenOpaqueWindowState);
Jorim Jaggi86905582016-02-09 21:36:09 -08006948 if (diff == 0 && fullscreenDiff == 0 && dockedDiff == 0 && mLastFocusNeedsMenu == needsMenu
6949 && mFocusedApp == win.getAppToken()
6950 && mLastNonDockedStackBounds.equals(mNonDockedStackBounds)
6951 && mLastDockedStackBounds.equals(mDockedStackBounds)) {
Dianne Hackborndf89e652011-10-06 22:35:11 -07006952 return 0;
6953 }
Dianne Hackborne26ab702011-10-16 13:21:33 -07006954 mLastSystemUiFlags = visibility;
Jorim Jaggi86905582016-02-09 21:36:09 -08006955 mLastFullscreenStackSysUiFlags = fullscreenVisibility;
6956 mLastDockedStackSysUiFlags = dockedVisibility;
Dianne Hackborn4eff8d32011-11-10 19:38:40 -08006957 mLastFocusNeedsMenu = needsMenu;
John Spurlock79da8332013-09-20 12:04:47 -04006958 mFocusedApp = win.getAppToken();
Jorim Jaggi86905582016-02-09 21:36:09 -08006959 final Rect fullscreenStackBounds = new Rect(mNonDockedStackBounds);
6960 final Rect dockedStackBounds = new Rect(mDockedStackBounds);
Dianne Hackborndf89e652011-10-06 22:35:11 -07006961 mHandler.post(new Runnable() {
Craig Mautnereda67292013-04-28 13:50:14 -07006962 @Override
Dianne Hackborndf89e652011-10-06 22:35:11 -07006963 public void run() {
Jorim Jaggi86905582016-02-09 21:36:09 -08006964 StatusBarManagerInternal statusbar = getStatusBarManagerInternal();
6965 if (statusbar != null) {
6966 statusbar.setSystemUiVisibility(visibility, fullscreenVisibility,
6967 dockedVisibility, 0xffffffff, fullscreenStackBounds,
6968 dockedStackBounds, win.toString());
6969 statusbar.topAppWindowChanged(needsMenu);
Joe Onorato664644d2011-01-23 17:53:23 -08006970 }
Dianne Hackborndf89e652011-10-06 22:35:11 -07006971 }
6972 });
6973 return diff;
Joe Onorato664644d2011-01-23 17:53:23 -08006974 }
6975
Jorim Jaggi86905582016-02-09 21:36:09 -08006976 private int updateLightStatusBarLw(int vis, WindowState opaque, WindowState opaqueOrDimming) {
Adrian Rooscd3884d2015-02-18 17:25:23 +01006977 WindowState statusColorWin = isStatusBarKeyguard() && !mHideLockScreen
6978 ? mStatusBar
Jorim Jaggi86905582016-02-09 21:36:09 -08006979 : opaqueOrDimming;
Adrian Rooscd3884d2015-02-18 17:25:23 +01006980
6981 if (statusColorWin != null) {
Jorim Jaggi86905582016-02-09 21:36:09 -08006982 if (statusColorWin == opaque) {
Adrian Rooscd3884d2015-02-18 17:25:23 +01006983 // If the top fullscreen-or-dimming window is also the top fullscreen, respect
6984 // its light flag.
6985 vis &= ~View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR;
6986 vis |= PolicyControl.getSystemUiVisibility(statusColorWin, null)
6987 & View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR;
6988 } else if (statusColorWin != null && statusColorWin.isDimming()) {
6989 // Otherwise if it's dimming, clear the light flag.
6990 vis &= ~View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR;
6991 }
6992 }
6993 return vis;
6994 }
6995
John Spurlock79da8332013-09-20 12:04:47 -04006996 private int updateSystemBarsLw(WindowState win, int oldVis, int vis) {
Wale Ogunwale6e94a9e2015-10-07 15:35:49 -07006997 final boolean dockedStackVisible = mWindowManagerInternal.isStackVisible(DOCKED_STACK_ID);
6998 final boolean freeformStackVisible =
6999 mWindowManagerInternal.isStackVisible(FREEFORM_WORKSPACE_STACK_ID);
Jorim Jaggi9511b0f2016-01-29 19:12:44 -08007000 final boolean resizing = mWindowManagerInternal.isDockedDividerResizing();
7001
7002 // We need to force system bars when the docked stack is visible, when the freeform stack
7003 // is visible but also when we are resizing for the transitions when docked stack
7004 // visibility changes.
Jorim Jaggi0ffd49c2016-02-12 15:04:21 -08007005 mForceShowSystemBars = dockedStackVisible || freeformStackVisible || resizing;
7006 final boolean forceOpaqueSystemBars = mForceShowSystemBars && !mForceStatusBarFromKeyguard;
Wale Ogunwale6e94a9e2015-10-07 15:35:49 -07007007
John Spurlockbd957402013-10-03 11:38:39 -04007008 // apply translucent bar vis flags
Jorim Jaggi380ecb82014-03-14 17:25:20 +01007009 WindowState transWin = isStatusBarKeyguard() && !mHideLockScreen
7010 ? mStatusBar
John Spurlockbd957402013-10-03 11:38:39 -04007011 : mTopFullscreenOpaqueWindowState;
7012 vis = mStatusBarController.applyTranslucentFlagLw(transWin, vis, oldVis);
7013 vis = mNavigationBarController.applyTranslucentFlagLw(transWin, vis, oldVis);
7014
John Spurlock27735a42013-08-14 17:57:38 -04007015 // prevent status bar interaction from clearing certain flags
Selim Cinekf83e8242015-05-19 18:08:14 -07007016 int type = win.getAttrs().type;
7017 boolean statusBarHasFocus = type == TYPE_STATUS_BAR;
John Spurlock08ffcf52014-07-11 10:13:46 -04007018 if (statusBarHasFocus && !isStatusBarKeyguard()) {
John Spurlockad3e6cb2013-04-30 08:47:43 -04007019 int flags = View.SYSTEM_UI_FLAG_FULLSCREEN
7020 | View.SYSTEM_UI_FLAG_HIDE_NAVIGATION
John Spurlockcfc359a2013-09-05 10:42:03 -04007021 | View.SYSTEM_UI_FLAG_IMMERSIVE
Jorim Jaggi73fef8d2015-02-16 17:32:28 +01007022 | View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY
7023 | View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR;
John Spurlock08ffcf52014-07-11 10:13:46 -04007024 if (mHideLockScreen) {
Jorim Jaggi5cf17872014-03-26 18:31:48 +01007025 flags |= View.STATUS_BAR_TRANSLUCENT | View.NAVIGATION_BAR_TRANSLUCENT;
7026 }
John Spurlockbd957402013-10-03 11:38:39 -04007027 vis = (vis & ~flags) | (oldVis & flags);
John Spurlockad3e6cb2013-04-30 08:47:43 -04007028 }
John Spurlockad3e6cb2013-04-30 08:47:43 -04007029
Wale Ogunwale6e94a9e2015-10-07 15:35:49 -07007030 if ((!areTranslucentBarsAllowed() && transWin != mStatusBar)
7031 || forceOpaqueSystemBars) {
Adrian Roosea562512014-05-05 13:33:03 +02007032 vis &= ~(View.NAVIGATION_BAR_TRANSLUCENT | View.STATUS_BAR_TRANSLUCENT
7033 | View.SYSTEM_UI_TRANSPARENT);
Alan Viverette5a0f4ec2013-10-07 15:10:29 -07007034 }
7035
Jorim Jaggi4fa78922015-11-30 17:13:56 -08007036 if (mForceWindowDrawsStatusBarBackground) {
7037 vis |= View.STATUS_BAR_TRANSPARENT;
7038 vis &= ~View.STATUS_BAR_TRANSLUCENT;
7039 }
7040
John Spurlock27735a42013-08-14 17:57:38 -04007041 // update status bar
John Spurlockf1a36642013-10-12 17:50:42 -04007042 boolean immersiveSticky =
7043 (vis & View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY) != 0;
Wale Ogunwale6e94a9e2015-10-07 15:35:49 -07007044 final boolean hideStatusBarWM =
7045 mTopFullscreenOpaqueWindowState != null
7046 && (PolicyControl.getWindowFlags(mTopFullscreenOpaqueWindowState, null)
John Spurlock27735a42013-08-14 17:57:38 -04007047 & WindowManager.LayoutParams.FLAG_FULLSCREEN) != 0;
Wale Ogunwale6e94a9e2015-10-07 15:35:49 -07007048 final boolean hideStatusBarSysui =
John Spurlock27735a42013-08-14 17:57:38 -04007049 (vis & View.SYSTEM_UI_FLAG_FULLSCREEN) != 0;
Wale Ogunwale6e94a9e2015-10-07 15:35:49 -07007050 final boolean hideNavBarSysui =
John Spurlockf1a36642013-10-12 17:50:42 -04007051 (vis & View.SYSTEM_UI_FLAG_HIDE_NAVIGATION) != 0;
John Spurlockad3e6cb2013-04-30 08:47:43 -04007052
Wale Ogunwale6e94a9e2015-10-07 15:35:49 -07007053 final boolean transientStatusBarAllowed = mStatusBar != null
Jorim Jaggi0ffd49c2016-02-12 15:04:21 -08007054 && (statusBarHasFocus || (!mForceShowSystemBars
Wale Ogunwale6e94a9e2015-10-07 15:35:49 -07007055 && (hideStatusBarWM || (hideStatusBarSysui && immersiveSticky))));
John Spurlock27735a42013-08-14 17:57:38 -04007056
Wale Ogunwale6e94a9e2015-10-07 15:35:49 -07007057 final boolean transientNavBarAllowed = mNavigationBar != null
Jorim Jaggi0ffd49c2016-02-12 15:04:21 -08007058 && !mForceShowSystemBars && hideNavBarSysui && immersiveSticky;
John Spurlockf1a36642013-10-12 17:50:42 -04007059
Adrian Roosddc8b272015-05-21 16:28:27 -07007060 final long now = SystemClock.uptimeMillis();
7061 final boolean pendingPanic = mPendingPanicGestureUptime != 0
7062 && now - mPendingPanicGestureUptime <= PANIC_GESTURE_EXPIRATION;
7063 if (pendingPanic && hideNavBarSysui && !isStatusBarKeyguard() && mKeyguardDrawComplete) {
7064 // The user performed the panic gesture recently, we're about to hide the bars,
7065 // we're no longer on the Keyguard and the screen is ready. We can now request the bars.
7066 mPendingPanicGestureUptime = 0;
7067 mStatusBarController.showTransient();
7068 mNavigationBarController.showTransient();
7069 }
7070
Wale Ogunwale6e94a9e2015-10-07 15:35:49 -07007071 final boolean denyTransientStatus = mStatusBarController.isTransientShowRequested()
John Spurlockf1a36642013-10-12 17:50:42 -04007072 && !transientStatusBarAllowed && hideStatusBarSysui;
Wale Ogunwale6e94a9e2015-10-07 15:35:49 -07007073 final boolean denyTransientNav = mNavigationBarController.isTransientShowRequested()
John Spurlockf1a36642013-10-12 17:50:42 -04007074 && !transientNavBarAllowed;
Jorim Jaggi0ffd49c2016-02-12 15:04:21 -08007075 if (denyTransientStatus || denyTransientNav || mForceShowSystemBars) {
John Spurlock27735a42013-08-14 17:57:38 -04007076 // clear the clearable flags instead
John Spurlockf1a36642013-10-12 17:50:42 -04007077 clearClearableFlagsLw();
tiger_huangc58d7562014-10-23 20:24:19 +08007078 vis &= ~View.SYSTEM_UI_CLEARABLE_FLAGS;
John Spurlockad3e6cb2013-04-30 08:47:43 -04007079 }
John Spurlock27735a42013-08-14 17:57:38 -04007080
Selim Cinekf98702e2015-05-20 22:48:40 -07007081 final boolean immersive = (vis & View.SYSTEM_UI_FLAG_IMMERSIVE) != 0;
7082 immersiveSticky = (vis & View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY) != 0;
7083 final boolean navAllowedHidden = immersive || immersiveSticky;
7084
Selim Cinekd6623612015-05-22 18:56:22 -07007085 if (hideNavBarSysui && !navAllowedHidden && windowTypeToLayerLw(win.getBaseType())
7086 > windowTypeToLayerLw(TYPE_INPUT_CONSUMER)) {
Selim Cinekf98702e2015-05-20 22:48:40 -07007087 // We can't hide the navbar from this window otherwise the input consumer would not get
7088 // the input events.
7089 vis = (vis & ~View.SYSTEM_UI_FLAG_HIDE_NAVIGATION);
7090 }
7091
John Spurlock27735a42013-08-14 17:57:38 -04007092 vis = mStatusBarController.updateVisibilityLw(transientStatusBarAllowed, oldVis, vis);
7093
7094 // update navigation bar
John Spurlockf1a36642013-10-12 17:50:42 -04007095 boolean oldImmersiveMode = isImmersiveMode(oldVis);
7096 boolean newImmersiveMode = isImmersiveMode(vis);
7097 if (win != null && oldImmersiveMode != newImmersiveMode) {
John Spurlock79da8332013-09-20 12:04:47 -04007098 final String pkg = win.getOwningPackage();
Maurice Lam99c6e072014-04-28 18:24:28 -07007099 mImmersiveModeConfirmation.immersiveModeChanged(pkg, newImmersiveMode,
7100 isUserSetupComplete());
John Spurlock34e13d92013-08-10 06:52:28 -04007101 }
John Spurlock27735a42013-08-14 17:57:38 -04007102
John Spurlockf1a36642013-10-12 17:50:42 -04007103 vis = mNavigationBarController.updateVisibilityLw(transientNavBarAllowed, oldVis, vis);
7104
John Spurlocke1f366f2013-08-05 12:22:40 -04007105 return vis;
John Spurlockad3e6cb2013-04-30 08:47:43 -04007106 }
7107
John Spurlockf1a36642013-10-12 17:50:42 -04007108 private void clearClearableFlagsLw() {
7109 int newVal = mResettingSystemUiFlags | View.SYSTEM_UI_CLEARABLE_FLAGS;
7110 if (newVal != mResettingSystemUiFlags) {
7111 mResettingSystemUiFlags = newVal;
7112 mWindowManagerFuncs.reevaluateStatusBarVisibility();
7113 }
7114 }
7115
7116 private boolean isImmersiveMode(int vis) {
7117 final int flags = View.SYSTEM_UI_FLAG_IMMERSIVE | View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY;
John Spurlock34e13d92013-08-10 06:52:28 -04007118 return mNavigationBar != null
7119 && (vis & View.SYSTEM_UI_FLAG_HIDE_NAVIGATION) != 0
Daniel Sandler900ece52013-10-18 15:53:27 -04007120 && (vis & flags) != 0
7121 && canHideNavigationBar();
John Spurlock34e13d92013-08-10 06:52:28 -04007122 }
7123
Alan Viverette5a0f4ec2013-10-07 15:10:29 -07007124 /**
Daniel Sandlerdd73ee42013-10-11 22:19:59 -04007125 * @return whether the navigation or status bar can be made translucent
7126 *
7127 * This should return true unless touch exploration is not enabled or
7128 * R.boolean.config_enableTranslucentDecor is false.
Alan Viverette5a0f4ec2013-10-07 15:10:29 -07007129 */
Daniel Sandlerdd73ee42013-10-11 22:19:59 -04007130 private boolean areTranslucentBarsAllowed() {
Alan Viverette817f3cd2015-08-13 11:40:14 -04007131 return mTranslucentDecorEnabled;
Alan Viverette5a0f4ec2013-10-07 15:10:29 -07007132 }
7133
Daniel Sandler0c4ccff2011-10-19 16:39:14 -04007134 // Use this instead of checking config_showNavigationBar so that it can be consistently
7135 // overridden by qemu.hw.mainkeys in the emulator.
Craig Mautnereda67292013-04-28 13:50:14 -07007136 @Override
Daniel Sandler0c4ccff2011-10-19 16:39:14 -04007137 public boolean hasNavigationBar() {
7138 return mHasNavigationBar;
7139 }
7140
satok1bc0a492012-04-25 22:47:12 +09007141 @Override
7142 public void setLastInputMethodWindowLw(WindowState ime, WindowState target) {
7143 mLastInputMethodWindow = ime;
7144 mLastInputMethodTargetWindow = target;
7145 }
7146
Craig Mautnerf1b67412012-09-19 13:18:29 -07007147 @Override
Satoshi Kataoka658c7b82013-10-10 17:03:51 +09007148 public int getInputMethodWindowVisibleHeightLw() {
7149 return mDockBottom - mCurBottom;
7150 }
7151
7152 @Override
Craig Mautnerf1b67412012-09-19 13:18:29 -07007153 public void setCurrentUserLw(int newUserId) {
Craig Mautnerd625ab22013-09-06 13:40:31 -07007154 mCurrentUserId = newUserId;
Jim Miller5ecd8112013-01-09 18:50:26 -08007155 if (mKeyguardDelegate != null) {
7156 mKeyguardDelegate.setCurrentUser(newUserId);
Craig Mautnerf1b67412012-09-19 13:18:29 -07007157 }
John Spurlock13451a22012-09-28 14:40:41 -04007158 if (mStatusBarService != null) {
7159 try {
7160 mStatusBarService.setCurrentUser(newUserId);
7161 } catch (RemoteException e) {
7162 // oh well
7163 }
7164 }
Dianne Hackborn2ea9bae2012-11-02 18:43:48 -07007165 setLastInputMethodWindowLw(null, null);
Craig Mautnerf1b67412012-09-19 13:18:29 -07007166 }
7167
7168 @Override
Svetoslav Ganov545252f2012-12-10 18:29:24 -08007169 public boolean canMagnifyWindow(int windowType) {
7170 switch (windowType) {
7171 case WindowManager.LayoutParams.TYPE_INPUT_METHOD:
7172 case WindowManager.LayoutParams.TYPE_INPUT_METHOD_DIALOG:
7173 case WindowManager.LayoutParams.TYPE_NAVIGATION_BAR:
7174 case WindowManager.LayoutParams.TYPE_MAGNIFICATION_OVERLAY: {
7175 return false;
7176 }
7177 }
7178 return true;
7179 }
7180
7181 @Override
7182 public boolean isTopLevelWindow(int windowType) {
7183 if (windowType >= WindowManager.LayoutParams.FIRST_SUB_WINDOW
7184 && windowType <= WindowManager.LayoutParams.LAST_SUB_WINDOW) {
7185 return (windowType == WindowManager.LayoutParams.TYPE_APPLICATION_ATTACHED_DIALOG);
7186 }
7187 return true;
7188 }
7189
Jim Miller4eeb4f62012-11-08 00:04:29 -08007190 @Override
Jeff Brownd7a04de2012-06-17 14:17:52 -07007191 public void dump(String prefix, PrintWriter pw, String[] args) {
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08007192 pw.print(prefix); pw.print("mSafeMode="); pw.print(mSafeMode);
Dianne Hackbornba24e4d2011-09-01 11:17:06 -07007193 pw.print(" mSystemReady="); pw.print(mSystemReady);
7194 pw.print(" mSystemBooted="); pw.println(mSystemBooted);
Jeff Brown2e7760e2012-04-11 15:14:55 -07007195 pw.print(prefix); pw.print("mLidState="); pw.print(mLidState);
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08007196 pw.print(" mLidOpenRotation="); pw.print(mLidOpenRotation);
Michael Wright3818c922014-09-02 13:59:07 -07007197 pw.print(" mCameraLensCoverState="); pw.print(mCameraLensCoverState);
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08007198 pw.print(" mHdmiPlugged="); pw.println(mHdmiPlugged);
Dianne Hackborne26ab702011-10-16 13:21:33 -07007199 if (mLastSystemUiFlags != 0 || mResettingSystemUiFlags != 0
7200 || mForceClearedSystemUiFlags != 0) {
7201 pw.print(prefix); pw.print("mLastSystemUiFlags=0x");
7202 pw.print(Integer.toHexString(mLastSystemUiFlags));
7203 pw.print(" mResettingSystemUiFlags=0x");
7204 pw.print(Integer.toHexString(mResettingSystemUiFlags));
7205 pw.print(" mForceClearedSystemUiFlags=0x");
7206 pw.println(Integer.toHexString(mForceClearedSystemUiFlags));
Dianne Hackborndf89e652011-10-06 22:35:11 -07007207 }
Dianne Hackborn4eff8d32011-11-10 19:38:40 -08007208 if (mLastFocusNeedsMenu) {
7209 pw.print(prefix); pw.print("mLastFocusNeedsMenu=");
7210 pw.println(mLastFocusNeedsMenu);
7211 }
Jeff Browna20dda42014-05-27 20:57:24 -07007212 pw.print(prefix); pw.print("mWakeGestureEnabledSetting=");
7213 pw.println(mWakeGestureEnabledSetting);
7214
Jeff Brownbcdfc622014-03-06 19:13:04 -08007215 pw.print(prefix); pw.print("mSupportAutoRotation="); pw.println(mSupportAutoRotation);
Daniel Sandler6396c722013-04-16 20:19:09 -04007216 pw.print(prefix); pw.print("mUiMode="); pw.print(mUiMode);
7217 pw.print(" mDockMode="); pw.print(mDockMode);
keunyounga7710492015-09-23 11:33:58 -07007218 pw.print(" mEnableCarDockHomeCapture="); pw.print(mEnableCarDockHomeCapture);
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08007219 pw.print(" mCarDockRotation="); pw.print(mCarDockRotation);
7220 pw.print(" mDeskDockRotation="); pw.println(mDeskDockRotation);
7221 pw.print(prefix); pw.print("mUserRotationMode="); pw.print(mUserRotationMode);
7222 pw.print(" mUserRotation="); pw.print(mUserRotation);
Daniel Sandler2ed6ad62011-02-22 14:54:17 -05007223 pw.print(" mAllowAllRotations="); pw.println(mAllowAllRotations);
Dianne Hackborn6e2281d2012-06-19 17:48:32 -07007224 pw.print(prefix); pw.print("mCurrentAppOrientation="); pw.println(mCurrentAppOrientation);
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08007225 pw.print(prefix); pw.print("mCarDockEnablesAccelerometer=");
7226 pw.print(mCarDockEnablesAccelerometer);
7227 pw.print(" mDeskDockEnablesAccelerometer=");
7228 pw.println(mDeskDockEnablesAccelerometer);
7229 pw.print(prefix); pw.print("mLidKeyboardAccessibility=");
7230 pw.print(mLidKeyboardAccessibility);
7231 pw.print(" mLidNavigationAccessibility="); pw.print(mLidNavigationAccessibility);
Edward Savage-Jones7def60d2015-11-13 13:27:03 +01007232 pw.print(" mLidControlsScreenLock="); pw.println(mLidControlsScreenLock);
Dianne Hackborn6e2281d2012-06-19 17:48:32 -07007233 pw.print(" mLidControlsSleep="); pw.println(mLidControlsSleep);
Jeff Brown6d8fd272014-05-20 21:24:38 -07007234 pw.print(prefix);
7235 pw.print("mShortPressOnPowerBehavior="); pw.print(mShortPressOnPowerBehavior);
7236 pw.print(" mLongPressOnPowerBehavior="); pw.println(mLongPressOnPowerBehavior);
Jeff Brown13f00f02014-10-31 14:45:50 -07007237 pw.print(prefix);
7238 pw.print("mDoublePressOnPowerBehavior="); pw.print(mDoublePressOnPowerBehavior);
7239 pw.print(" mTriplePressOnPowerBehavior="); pw.println(mTriplePressOnPowerBehavior);
Jeff Brown6d8fd272014-05-20 21:24:38 -07007240 pw.print(prefix); pw.print("mHasSoftInput="); pw.println(mHasSoftInput);
Jeff Brown3ee549c2014-09-22 20:14:39 -07007241 pw.print(prefix); pw.print("mAwake="); pw.println(mAwake);
7242 pw.print(prefix); pw.print("mScreenOnEarly="); pw.print(mScreenOnEarly);
7243 pw.print(" mScreenOnFully="); pw.println(mScreenOnFully);
7244 pw.print(prefix); pw.print("mKeyguardDrawComplete="); pw.print(mKeyguardDrawComplete);
7245 pw.print(" mWindowManagerDrawComplete="); pw.println(mWindowManagerDrawComplete);
7246 pw.print(prefix); pw.print("mOrientationSensorEnabled=");
7247 pw.println(mOrientationSensorEnabled);
Dianne Hackbornc652de82013-02-15 16:32:56 -08007248 pw.print(prefix); pw.print("mOverscanScreen=("); pw.print(mOverscanScreenLeft);
7249 pw.print(","); pw.print(mOverscanScreenTop);
7250 pw.print(") "); pw.print(mOverscanScreenWidth);
7251 pw.print("x"); pw.println(mOverscanScreenHeight);
7252 if (mOverscanLeft != 0 || mOverscanTop != 0
7253 || mOverscanRight != 0 || mOverscanBottom != 0) {
7254 pw.print(prefix); pw.print("mOverscan left="); pw.print(mOverscanLeft);
7255 pw.print(" top="); pw.print(mOverscanTop);
7256 pw.print(" right="); pw.print(mOverscanRight);
7257 pw.print(" bottom="); pw.println(mOverscanBottom);
7258 }
Dianne Hackborn313440842013-02-19 19:22:59 -08007259 pw.print(prefix); pw.print("mRestrictedOverscanScreen=(");
7260 pw.print(mRestrictedOverscanScreenLeft);
7261 pw.print(","); pw.print(mRestrictedOverscanScreenTop);
7262 pw.print(") "); pw.print(mRestrictedOverscanScreenWidth);
7263 pw.print("x"); pw.println(mRestrictedOverscanScreenHeight);
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08007264 pw.print(prefix); pw.print("mUnrestrictedScreen=("); pw.print(mUnrestrictedScreenLeft);
7265 pw.print(","); pw.print(mUnrestrictedScreenTop);
7266 pw.print(") "); pw.print(mUnrestrictedScreenWidth);
7267 pw.print("x"); pw.println(mUnrestrictedScreenHeight);
7268 pw.print(prefix); pw.print("mRestrictedScreen=("); pw.print(mRestrictedScreenLeft);
7269 pw.print(","); pw.print(mRestrictedScreenTop);
7270 pw.print(") "); pw.print(mRestrictedScreenWidth);
7271 pw.print("x"); pw.println(mRestrictedScreenHeight);
Dianne Hackborn5b5cc4d2012-05-16 13:15:00 -07007272 pw.print(prefix); pw.print("mStableFullscreen=("); pw.print(mStableFullscreenLeft);
7273 pw.print(","); pw.print(mStableFullscreenTop);
7274 pw.print(")-("); pw.print(mStableFullscreenRight);
7275 pw.print(","); pw.print(mStableFullscreenBottom); pw.println(")");
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07007276 pw.print(prefix); pw.print("mStable=("); pw.print(mStableLeft);
7277 pw.print(","); pw.print(mStableTop);
7278 pw.print(")-("); pw.print(mStableRight);
7279 pw.print(","); pw.print(mStableBottom); pw.println(")");
Dianne Hackborn5c58de32012-04-28 19:52:37 -07007280 pw.print(prefix); pw.print("mSystem=("); pw.print(mSystemLeft);
7281 pw.print(","); pw.print(mSystemTop);
7282 pw.print(")-("); pw.print(mSystemRight);
7283 pw.print(","); pw.print(mSystemBottom); pw.println(")");
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08007284 pw.print(prefix); pw.print("mCur=("); pw.print(mCurLeft);
7285 pw.print(","); pw.print(mCurTop);
7286 pw.print(")-("); pw.print(mCurRight);
7287 pw.print(","); pw.print(mCurBottom); pw.println(")");
7288 pw.print(prefix); pw.print("mContent=("); pw.print(mContentLeft);
7289 pw.print(","); pw.print(mContentTop);
7290 pw.print(")-("); pw.print(mContentRight);
7291 pw.print(","); pw.print(mContentBottom); pw.println(")");
Dianne Hackborne30e02f2014-05-27 18:24:45 -07007292 pw.print(prefix); pw.print("mVoiceContent=("); pw.print(mVoiceContentLeft);
7293 pw.print(","); pw.print(mVoiceContentTop);
7294 pw.print(")-("); pw.print(mVoiceContentRight);
7295 pw.print(","); pw.print(mVoiceContentBottom); pw.println(")");
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08007296 pw.print(prefix); pw.print("mDock=("); pw.print(mDockLeft);
7297 pw.print(","); pw.print(mDockTop);
7298 pw.print(")-("); pw.print(mDockRight);
7299 pw.print(","); pw.print(mDockBottom); pw.println(")");
Dianne Hackborn5c58de32012-04-28 19:52:37 -07007300 pw.print(prefix); pw.print("mDockLayer="); pw.print(mDockLayer);
7301 pw.print(" mStatusBarLayer="); pw.println(mStatusBarLayer);
Dianne Hackborn7ad44382012-10-18 17:46:00 -07007302 pw.print(prefix); pw.print("mShowingLockscreen="); pw.print(mShowingLockscreen);
7303 pw.print(" mShowingDream="); pw.print(mShowingDream);
Jeff Brown061ea992015-04-17 19:55:47 -07007304 pw.print(" mDreamingLockscreen="); pw.print(mDreamingLockscreen);
7305 pw.print(" mDreamingSleepToken="); pw.println(mDreamingSleepToken);
Dianne Hackborn2ea9bae2012-11-02 18:43:48 -07007306 if (mLastInputMethodWindow != null) {
7307 pw.print(prefix); pw.print("mLastInputMethodWindow=");
7308 pw.println(mLastInputMethodWindow);
7309 }
7310 if (mLastInputMethodTargetWindow != null) {
7311 pw.print(prefix); pw.print("mLastInputMethodTargetWindow=");
7312 pw.println(mLastInputMethodTargetWindow);
7313 }
7314 if (mStatusBar != null) {
7315 pw.print(prefix); pw.print("mStatusBar=");
Dianne Hackbornae6688b2015-02-11 17:02:41 -08007316 pw.print(mStatusBar); pw.print(" isStatusBarKeyguard=");
7317 pw.println(isStatusBarKeyguard());
Dianne Hackborn2ea9bae2012-11-02 18:43:48 -07007318 }
7319 if (mNavigationBar != null) {
7320 pw.print(prefix); pw.print("mNavigationBar=");
7321 pw.println(mNavigationBar);
7322 }
Dianne Hackborn2ea9bae2012-11-02 18:43:48 -07007323 if (mFocusedWindow != null) {
7324 pw.print(prefix); pw.print("mFocusedWindow=");
7325 pw.println(mFocusedWindow);
7326 }
7327 if (mFocusedApp != null) {
7328 pw.print(prefix); pw.print("mFocusedApp=");
7329 pw.println(mFocusedApp);
7330 }
7331 if (mWinDismissingKeyguard != null) {
7332 pw.print(prefix); pw.print("mWinDismissingKeyguard=");
7333 pw.println(mWinDismissingKeyguard);
7334 }
7335 if (mTopFullscreenOpaqueWindowState != null) {
7336 pw.print(prefix); pw.print("mTopFullscreenOpaqueWindowState=");
7337 pw.println(mTopFullscreenOpaqueWindowState);
7338 }
Adrian Rooscd3884d2015-02-18 17:25:23 +01007339 if (mTopFullscreenOpaqueOrDimmingWindowState != null) {
7340 pw.print(prefix); pw.print("mTopFullscreenOpaqueOrDimmingWindowState=");
7341 pw.println(mTopFullscreenOpaqueOrDimmingWindowState);
7342 }
Dianne Hackborn891d3fb2013-01-09 18:31:37 -08007343 if (mForcingShowNavBar) {
7344 pw.print(prefix); pw.print("mForcingShowNavBar=");
7345 pw.println(mForcingShowNavBar); pw.print( "mForcingShowNavBarLayer=");
7346 pw.println(mForcingShowNavBarLayer);
7347 }
Dianne Hackborn7ad44382012-10-18 17:46:00 -07007348 pw.print(prefix); pw.print("mTopIsFullscreen="); pw.print(mTopIsFullscreen);
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08007349 pw.print(" mHideLockScreen="); pw.println(mHideLockScreen);
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07007350 pw.print(prefix); pw.print("mForceStatusBar="); pw.print(mForceStatusBar);
7351 pw.print(" mForceStatusBarFromKeyguard=");
7352 pw.println(mForceStatusBarFromKeyguard);
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08007353 pw.print(prefix); pw.print("mDismissKeyguard="); pw.print(mDismissKeyguard);
Craig Mautnerad09bcc2012-10-08 13:33:11 -07007354 pw.print(" mWinDismissingKeyguard="); pw.print(mWinDismissingKeyguard);
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08007355 pw.print(" mHomePressed="); pw.println(mHomePressed);
7356 pw.print(prefix); pw.print("mAllowLockscreenWhenOn="); pw.print(mAllowLockscreenWhenOn);
7357 pw.print(" mLockScreenTimeout="); pw.print(mLockScreenTimeout);
7358 pw.print(" mLockScreenTimerActive="); pw.println(mLockScreenTimerActive);
7359 pw.print(prefix); pw.print("mEndcallBehavior="); pw.print(mEndcallBehavior);
7360 pw.print(" mIncallPowerBehavior="); pw.print(mIncallPowerBehavior);
7361 pw.print(" mLongPressOnHomeBehavior="); pw.println(mLongPressOnHomeBehavior);
7362 pw.print(prefix); pw.print("mLandscapeRotation="); pw.print(mLandscapeRotation);
7363 pw.print(" mSeascapeRotation="); pw.println(mSeascapeRotation);
7364 pw.print(prefix); pw.print("mPortraitRotation="); pw.print(mPortraitRotation);
7365 pw.print(" mUpsideDownRotation="); pw.println(mUpsideDownRotation);
Jeff Brownc82c89ed2013-04-17 17:18:15 -07007366 pw.print(prefix); pw.print("mDemoHdmiRotation="); pw.print(mDemoHdmiRotation);
7367 pw.print(" mDemoHdmiRotationLock="); pw.println(mDemoHdmiRotationLock);
7368 pw.print(prefix); pw.print("mUndockedHdmiRotation="); pw.println(mUndockedHdmiRotation);
Jeff Brown600f0032014-05-22 17:06:00 -07007369
Tim Kilbournd7c0c2e2014-05-29 16:08:10 -07007370 mGlobalKeyManager.dump(prefix, pw);
John Spurlock27735a42013-08-14 17:57:38 -04007371 mStatusBarController.dump(pw, prefix);
7372 mNavigationBarController.dump(pw, prefix);
John Spurlockc6d1c602014-01-17 15:22:06 -05007373 PolicyControl.dump(prefix, pw);
Jeff Brown600f0032014-05-22 17:06:00 -07007374
Jeff Browna20dda42014-05-27 20:57:24 -07007375 if (mWakeGestureListener != null) {
7376 mWakeGestureListener.dump(pw, prefix);
7377 }
Jeff Brown600f0032014-05-22 17:06:00 -07007378 if (mOrientationListener != null) {
7379 mOrientationListener.dump(pw, prefix);
7380 }
Filip Gruszczynskicfb31852015-02-25 21:47:12 +00007381 if (mBurnInProtectionHelper != null) {
7382 mBurnInProtectionHelper.dump(prefix, pw);
7383 }
Jorim Jaggi84dc08a2015-09-11 17:45:22 -07007384 if (mKeyguardDelegate != null) {
7385 mKeyguardDelegate.dump(prefix, pw);
7386 }
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08007387 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08007388}