blob: 4b2b184d1bbc881e9e1c2f2b879e3f0653477188 [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.HOME_STACK_ID;
Jaewan Kim49117872016-01-19 17:24:08 +090022import static android.content.pm.PackageManager.FEATURE_PICTURE_IN_PICTURE;
23import static android.content.pm.PackageManager.FEATURE_TELEVISION;
24import static android.content.pm.PackageManager.FEATURE_WATCH;
Wale Ogunwaledfc18622016-04-16 15:08:48 -070025import static android.content.res.Configuration.EMPTY;
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_LEFT;
29import static android.view.WindowManager.DOCKED_RIGHT;
Jorim Jaggi73294b62016-10-26 18:02:36 -070030import static android.view.WindowManager.DOCKED_TOP;
Winson41275482016-10-10 15:17:45 -070031import static android.view.WindowManager.INPUT_CONSUMER_NAVIGATION;
Jorim Jaggi73294b62016-10-26 18:02:36 -070032import static android.view.WindowManager.LayoutParams.FIRST_APPLICATION_WINDOW;
33import static android.view.WindowManager.LayoutParams.FIRST_SUB_WINDOW;
34import static android.view.WindowManager.LayoutParams.FIRST_SYSTEM_WINDOW;
35import static android.view.WindowManager.LayoutParams.FLAG_ALLOW_LOCK_WHILE_SCREEN_ON;
36import static android.view.WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS;
37import static android.view.WindowManager.LayoutParams.FLAG_FORCE_NOT_FULLSCREEN;
38import static android.view.WindowManager.LayoutParams.FLAG_FULLSCREEN;
39import static android.view.WindowManager.LayoutParams.FLAG_LAYOUT_ATTACHED_IN_DECOR;
40import static android.view.WindowManager.LayoutParams.FLAG_LAYOUT_INSET_DECOR;
41import static android.view.WindowManager.LayoutParams.FLAG_LAYOUT_IN_OVERSCAN;
42import static android.view.WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN;
43import static android.view.WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS;
44import static android.view.WindowManager.LayoutParams.FLAG_SHOW_WALLPAPER;
45import static android.view.WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED;
46import static android.view.WindowManager.LayoutParams.LAST_APPLICATION_WINDOW;
47import static android.view.WindowManager.LayoutParams.LAST_SUB_WINDOW;
48import static android.view.WindowManager.LayoutParams.LAST_SYSTEM_WINDOW;
49import static android.view.WindowManager.LayoutParams.MATCH_PARENT;
50import static android.view.WindowManager.LayoutParams.PRIVATE_FLAG_FORCE_DRAW_STATUS_BAR_BACKGROUND;
51import static android.view.WindowManager.LayoutParams.PRIVATE_FLAG_FORCE_STATUS_BAR_VISIBLE_TRANSPARENT;
52import static android.view.WindowManager.LayoutParams.PRIVATE_FLAG_KEYGUARD;
53import static android.view.WindowManager.LayoutParams.PRIVATE_FLAG_SHOW_FOR_ALL_USERS;
Jorim Jaggi02886a82016-12-06 09:10:06 -080054import static android.view.WindowManager.LayoutParams.PRIVATE_FLAG_TASK_SNAPSHOT;
Jorim Jaggi73294b62016-10-26 18:02:36 -070055import static android.view.WindowManager.LayoutParams.PRIVATE_FLAG_SYSTEM_ERROR;
56import static android.view.WindowManager.LayoutParams.ROTATION_ANIMATION_CROSSFADE;
57import static android.view.WindowManager.LayoutParams.ROTATION_ANIMATION_JUMPCUT;
58import static android.view.WindowManager.LayoutParams.ROTATION_ANIMATION_ROTATE;
59import static android.view.WindowManager.LayoutParams.ROTATION_ANIMATION_SEAMLESS;
60import static android.view.WindowManager.LayoutParams.SOFT_INPUT_ADJUST_NOTHING;
61import static android.view.WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE;
62import static android.view.WindowManager.LayoutParams.SOFT_INPUT_MASK_ADJUST;
63import static android.view.WindowManager.LayoutParams.TYPE_ACCESSIBILITY_OVERLAY;
64import static android.view.WindowManager.LayoutParams.TYPE_APPLICATION_ABOVE_SUB_PANEL;
65import static android.view.WindowManager.LayoutParams.TYPE_APPLICATION_ATTACHED_DIALOG;
66import static android.view.WindowManager.LayoutParams.TYPE_APPLICATION_MEDIA;
67import static android.view.WindowManager.LayoutParams.TYPE_APPLICATION_MEDIA_OVERLAY;
68import static android.view.WindowManager.LayoutParams.TYPE_APPLICATION_PANEL;
69import static android.view.WindowManager.LayoutParams.TYPE_APPLICATION_STARTING;
70import static android.view.WindowManager.LayoutParams.TYPE_APPLICATION_SUB_PANEL;
71import static android.view.WindowManager.LayoutParams.TYPE_BOOT_PROGRESS;
72import static android.view.WindowManager.LayoutParams.TYPE_DISPLAY_OVERLAY;
73import static android.view.WindowManager.LayoutParams.TYPE_DOCK_DIVIDER;
74import static android.view.WindowManager.LayoutParams.TYPE_DRAG;
75import static android.view.WindowManager.LayoutParams.TYPE_DREAM;
76import static android.view.WindowManager.LayoutParams.TYPE_INPUT_CONSUMER;
77import static android.view.WindowManager.LayoutParams.TYPE_INPUT_METHOD;
78import static android.view.WindowManager.LayoutParams.TYPE_INPUT_METHOD_DIALOG;
79import static android.view.WindowManager.LayoutParams.TYPE_KEYGUARD_DIALOG;
80import static android.view.WindowManager.LayoutParams.TYPE_MAGNIFICATION_OVERLAY;
81import static android.view.WindowManager.LayoutParams.TYPE_NAVIGATION_BAR;
82import static android.view.WindowManager.LayoutParams.TYPE_NAVIGATION_BAR_PANEL;
83import static android.view.WindowManager.LayoutParams.TYPE_PHONE;
84import static android.view.WindowManager.LayoutParams.TYPE_POINTER;
Wale Ogunwale5b6714c2016-11-01 20:54:46 -070085import static android.view.WindowManager.LayoutParams.TYPE_PRESENTATION;
Jorim Jaggi73294b62016-10-26 18:02:36 -070086import static android.view.WindowManager.LayoutParams.TYPE_PRIORITY_PHONE;
87import static android.view.WindowManager.LayoutParams.TYPE_PRIVATE_PRESENTATION;
88import static android.view.WindowManager.LayoutParams.TYPE_QS_DIALOG;
89import static android.view.WindowManager.LayoutParams.TYPE_SCREENSHOT;
90import static android.view.WindowManager.LayoutParams.TYPE_SEARCH_BAR;
91import static android.view.WindowManager.LayoutParams.TYPE_SECURE_SYSTEM_OVERLAY;
92import static android.view.WindowManager.LayoutParams.TYPE_STATUS_BAR;
93import static android.view.WindowManager.LayoutParams.TYPE_STATUS_BAR_PANEL;
94import static android.view.WindowManager.LayoutParams.TYPE_STATUS_BAR_SUB_PANEL;
95import static android.view.WindowManager.LayoutParams.TYPE_SYSTEM_ALERT;
96import static android.view.WindowManager.LayoutParams.TYPE_SYSTEM_DIALOG;
97import static android.view.WindowManager.LayoutParams.TYPE_SYSTEM_ERROR;
98import static android.view.WindowManager.LayoutParams.TYPE_SYSTEM_OVERLAY;
99import static android.view.WindowManager.LayoutParams.TYPE_TOAST;
100import static android.view.WindowManager.LayoutParams.TYPE_VOICE_INTERACTION;
101import static android.view.WindowManager.LayoutParams.TYPE_VOICE_INTERACTION_STARTING;
102import static android.view.WindowManager.LayoutParams.TYPE_VOLUME_OVERLAY;
103import static android.view.WindowManager.LayoutParams.TYPE_WALLPAPER;
Muyuan Li6ca619f2016-03-08 13:30:42 -0800104import static android.view.WindowManager.TAKE_SCREENSHOT_FULLSCREEN;
105import static android.view.WindowManager.TAKE_SCREENSHOT_SELECTED_REGION;
Jaewan Kim49117872016-01-19 17:24:08 +0900106import static android.view.WindowManagerPolicy.WindowManagerFuncs.CAMERA_LENS_COVERED;
Wale Ogunwale6e94a9e2015-10-07 15:35:49 -0700107import static android.view.WindowManagerPolicy.WindowManagerFuncs.CAMERA_LENS_COVER_ABSENT;
108import static android.view.WindowManagerPolicy.WindowManagerFuncs.CAMERA_LENS_UNCOVERED;
Jaewan Kim49117872016-01-19 17:24:08 +0900109import static android.view.WindowManagerPolicy.WindowManagerFuncs.LID_ABSENT;
110import static android.view.WindowManagerPolicy.WindowManagerFuncs.LID_CLOSED;
111import static android.view.WindowManagerPolicy.WindowManagerFuncs.LID_OPEN;
Wale Ogunwale6e94a9e2015-10-07 15:35:49 -0700112
Jorim Jaggife762342016-10-13 14:33:27 +0200113import android.annotation.Nullable;
Dianne Hackborna4972e92012-03-14 10:38:05 -0700114import android.app.ActivityManager;
Jorim Jaggi86905582016-02-09 21:36:09 -0800115import android.app.ActivityManager.StackId;
Jeff Brown061ea992015-04-17 19:55:47 -0700116import android.app.ActivityManagerInternal;
117import android.app.ActivityManagerInternal.SleepToken;
Dianne Hackbornc2293022013-02-06 23:14:49 -0800118import android.app.AppOpsManager;
Daniel Sandler6396c722013-04-16 20:19:09 -0400119import android.app.IUiModeManager;
Dianne Hackborn661cd522011-08-22 00:26:20 -0700120import android.app.ProgressDialog;
Jeff Brownde7a8ea2012-06-13 18:28:57 -0700121import android.app.SearchManager;
John Spurlock97642182013-07-29 17:58:39 -0400122import android.app.StatusBarManager;
Dianne Hackborn78968392010-03-04 20:47:56 -0800123import android.app.UiModeManager;
Dianne Hackborn39c2d712009-09-22 11:41:31 -0700124import android.content.ActivityNotFoundException;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800125import android.content.BroadcastReceiver;
Daniel Sandler0601eb72011-04-13 01:01:32 -0400126import android.content.ComponentName;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800127import android.content.ContentResolver;
128import android.content.Context;
129import android.content.Intent;
Mike Lockwood1753f7f2009-08-24 14:49:07 -0700130import android.content.IntentFilter;
Winson Chung9112ec32011-06-27 13:15:32 -0700131import android.content.ServiceConnection;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800132import android.content.pm.ActivityInfo;
Svet Ganov03f2afc2016-03-04 16:13:03 -0800133import android.content.pm.ApplicationInfo;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800134import android.content.pm.PackageManager;
Daniel Sandler6396c722013-04-16 20:19:09 -0400135import android.content.pm.ResolveInfo;
Dianne Hackborn2f0b1752011-05-31 17:59:49 -0700136import android.content.res.CompatibilityInfo;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800137import android.content.res.Configuration;
138import android.content.res.Resources;
Wale Ogunwaledfc18622016-04-16 15:08:48 -0700139import android.content.res.TypedArray;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800140import android.database.ContentObserver;
Dianne Hackbornc777e072010-02-12 13:07:59 -0800141import android.graphics.PixelFormat;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800142import android.graphics.Rect;
Jinsuk Kime601b712015-07-07 08:01:02 +0900143import android.hardware.hdmi.HdmiControlManager;
144import android.hardware.hdmi.HdmiPlaybackClient;
145import android.hardware.hdmi.HdmiPlaybackClient.OneTouchPlayCallback;
Andrii Kulian112d0562016-03-08 10:44:22 -0800146import android.hardware.input.InputManagerInternal;
Ruchi Kandoi0d434042016-10-03 09:12:02 -0700147import android.hardware.power.V1_0.PowerHint;
John Spurlock7b414672014-07-18 13:02:39 -0400148import android.media.AudioAttributes;
Michael Jurka7a348952012-02-27 13:07:58 -0800149import android.media.AudioManager;
John Spurlock61560172015-02-06 19:46:04 -0500150import android.media.AudioSystem;
Michael Jurka7a348952012-02-27 13:07:58 -0800151import android.media.IAudioService;
Svetoslav Ganov7befb7d2012-09-27 16:49:23 -0700152import android.media.Ringtone;
153import android.media.RingtoneManager;
RoboErik8a2cfc32014-05-16 11:19:38 -0700154import android.media.session.MediaSessionLegacyHelper;
Billy Laucbe540f2015-06-25 01:51:44 +0100155import android.os.Binder;
Svet Ganov03f2afc2016-03-04 16:13:03 -0800156import android.os.Build;
Dianne Hackborn38e29a62011-09-18 14:43:08 -0700157import android.os.Bundle;
Craig Mautner276a6eb2014-11-04 15:32:57 -0800158import android.os.Debug;
Jeff Brown9a538ee2012-08-20 14:56:57 -0700159import android.os.FactoryTest;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800160import android.os.Handler;
161import android.os.IBinder;
Dianne Hackbornb6683c42015-06-18 17:40:33 -0700162import android.os.IDeviceIdleController;
Jeff Brown32cbc38552011-12-01 14:01:49 -0800163import android.os.Looper;
Dianne Hackbornfc8fa632011-08-17 16:20:47 -0700164import android.os.Message;
165import android.os.Messenger;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800166import android.os.PowerManager;
Nick Armstrong-Crews56ecfcc2015-09-07 21:46:50 -0700167import android.os.PowerManagerInternal;
Billy Laucbe540f2015-06-25 01:51:44 +0100168import android.os.Process;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800169import android.os.RemoteException;
170import android.os.ServiceManager;
171import android.os.SystemClock;
172import android.os.SystemProperties;
Dianne Hackbornad7fa7f2011-01-07 14:06:50 -0800173import android.os.UEventObserver;
Dianne Hackbornf02b60a2012-08-16 10:48:27 -0700174import android.os.UserHandle;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800175import android.os.Vibrator;
Michael Wright3818c922014-09-02 13:59:07 -0700176import android.provider.MediaStore;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800177import android.provider.Settings;
Jose Lima9546b202014-07-02 17:21:51 -0700178import android.service.dreams.DreamManagerInternal;
John Spurlockc8b46ca2013-04-08 12:59:26 -0400179import android.service.dreams.DreamService;
180import android.service.dreams.IDreamManager;
Michael Wrightdc63f7b2014-08-21 19:05:21 -0700181import android.speech.RecognizerIntent;
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700182import android.telecom.TelecomManager;
Dianne Hackborn81e56d52011-05-26 00:55:58 -0700183import android.util.DisplayMetrics;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800184import android.util.EventLog;
185import android.util.Log;
Jorim Jaggi73294b62016-10-26 18:02:36 -0700186import android.util.LongSparseArray;
Jorim Jaggif1cdf952016-04-05 21:41:06 -0700187import android.util.MutableBoolean;
Jeff Browna41ca772010-08-11 14:46:32 -0700188import android.util.Slog;
Jeff Brown6651a632011-11-28 12:59:11 -0800189import android.util.SparseArray;
Dianne Hackbornf87d1962012-04-04 12:48:24 -0700190import android.view.Display;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800191import android.view.Gravity;
192import android.view.HapticFeedbackConstants;
Dianne Hackborne0f085d2011-11-30 18:41:15 -0800193import android.view.IApplicationToken;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800194import android.view.IWindowManager;
Jeff Browna41ca772010-08-11 14:46:32 -0700195import android.view.InputChannel;
Jeff Brown4d396052010-10-29 21:50:21 -0700196import android.view.InputDevice;
Jeff Brown4952dfd2011-11-30 19:23:22 -0800197import android.view.InputEvent;
Jeff Brown32cbc38552011-12-01 14:01:49 -0800198import android.view.InputEventReceiver;
Jeff Brown6b53e8d2010-11-10 16:03:06 -0800199import android.view.KeyCharacterMap;
Craig Mautnerae446592012-12-06 19:05:05 -0800200import android.view.KeyCharacterMap.FallbackAction;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800201import android.view.KeyEvent;
202import android.view.MotionEvent;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800203import android.view.Surface;
204import android.view.View;
205import android.view.ViewConfiguration;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800206import android.view.WindowManager;
Jorim Jaggife762342016-10-13 14:33:27 +0200207import android.view.WindowManager.LayoutParams;
Craig Mautnerae446592012-12-06 19:05:05 -0800208import android.view.WindowManagerGlobal;
Craig Mautner8a0da012014-05-31 15:13:37 -0700209import android.view.WindowManagerInternal;
Jorim Jaggife762342016-10-13 14:33:27 +0200210import android.view.WindowManagerInternal.AppTransitionListener;
Craig Mautnerae446592012-12-06 19:05:05 -0800211import android.view.WindowManagerPolicy;
Craig Mautnerae446592012-12-06 19:05:05 -0800212import android.view.accessibility.AccessibilityEvent;
Svetoslav8e3feb12014-02-24 13:46:47 -0800213import android.view.accessibility.AccessibilityManager;
Craig Mautnerae446592012-12-06 19:05:05 -0800214import android.view.animation.Animation;
Jorim Jaggi76a16232014-08-08 17:00:47 +0200215import android.view.animation.AnimationSet;
Craig Mautnerae446592012-12-06 19:05:05 -0800216import android.view.animation.AnimationUtils;
Jorim Jaggi73294b62016-10-26 18:02:36 -0700217
Craig Mautnerae446592012-12-06 19:05:05 -0800218import com.android.internal.R;
Jason Monk8f7f3182015-11-18 16:35:14 -0500219import com.android.internal.logging.MetricsLogger;
Jorim Jaggi241ae102016-11-02 21:57:33 -0700220import com.android.internal.policy.IKeyguardDismissCallback;
Muyuan Li94ce94e2016-02-24 16:20:54 -0800221import com.android.internal.policy.IShortcutService;
Jorim Jaggi73294b62016-10-26 18:02:36 -0700222import com.android.internal.policy.PhoneWindow;
Craig Mautnerae446592012-12-06 19:05:05 -0800223import com.android.internal.statusbar.IStatusBarService;
Filip Gruszczynski2217f612015-05-26 11:32:08 -0700224import com.android.internal.util.ScreenShapeHelper;
Craig Mautnerae446592012-12-06 19:05:05 -0800225import com.android.internal.widget.PointerLocationView;
Adrian Roos5941c982015-09-03 15:59:49 -0700226import com.android.server.GestureLauncherService;
Craig Mautner8a0da012014-05-31 15:13:37 -0700227import com.android.server.LocalServices;
Jorim Jaggib10e33f2015-02-04 21:57:40 +0100228import com.android.server.policy.keyguard.KeyguardServiceDelegate;
Jorim Jaggi4cfdcf52015-07-09 12:13:59 -0700229import com.android.server.policy.keyguard.KeyguardServiceDelegate.DrawnListener;
Jorim Jaggie69c9312016-10-31 18:24:38 -0700230import com.android.server.policy.keyguard.KeyguardStateMonitor.StateCallback;
Jorim Jaggi86905582016-02-09 21:36:09 -0800231import com.android.server.statusbar.StatusBarManagerInternal;
Jorim Jaggife762342016-10-13 14:33:27 +0200232import com.android.server.wm.AppTransition;
Ruben Brunkfecb6152016-10-28 20:18:57 -0700233import com.android.server.vr.VrManagerInternal;
Craig Mautnerae446592012-12-06 19:05:05 -0800234
235import java.io.File;
236import java.io.FileReader;
237import java.io.IOException;
238import java.io.PrintWriter;
Craig Mautner276a6eb2014-11-04 15:32:57 -0800239import java.util.List;
Craig Mautnerae446592012-12-06 19:05:05 -0800240
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800241/**
The Android Open Source Project0727d222009-03-11 12:11:58 -0700242 * WindowManagerPolicy implementation for the Android phone UI. This
243 * introduces a new method suffix, Lp, for an internal lock of the
244 * PhoneWindowManager. This is used to protect some internal state, and
John Spurlock04db1762013-05-13 12:46:41 -0400245 * 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 -0700246 * of both of those when held.
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800247 */
248public class PhoneWindowManager implements WindowManagerPolicy {
249 static final String TAG = "WindowManager";
250 static final boolean DEBUG = false;
Joe Onorato43a17652011-04-06 19:22:23 -0700251 static final boolean localLOGV = false;
Jeff Brown40013652012-05-16 21:22:36 -0700252 static final boolean DEBUG_INPUT = false;
Craig Mautnerc0d2d0a2014-10-31 16:25:15 -0700253 static final boolean DEBUG_KEYGUARD = false;
254 static final boolean DEBUG_LAYOUT = false;
Jorim Jaggiba41f4b2016-12-14 17:43:07 -0800255 static final boolean DEBUG_SPLASH_SCREEN = false;
Craig Mautner8a0da012014-05-31 15:13:37 -0700256 static final boolean DEBUG_WAKEUP = false;
Jorim Jaggiba41f4b2016-12-14 17:43:07 -0800257 static final boolean SHOW_SPLASH_SCREENS = true;
Joe Onoratod208e702010-10-08 16:22:43 -0400258
Daniel Sandler6396c722013-04-16 20:19:09 -0400259 // Whether to allow dock apps with METADATA_DOCK_HOME to temporarily take over the Home key.
keunyounga7710492015-09-23 11:33:58 -0700260 // No longer recommended for desk docks;
Daniel Sandler6396c722013-04-16 20:19:09 -0400261 static final boolean ENABLE_DESK_DOCK_HOME_CAPTURE = false;
262
Justin Paupore01915a12016-09-28 17:41:26 -0700263 static final boolean ALTERNATE_CAR_MODE_NAV_SIZE = false;
264
Jeff Brown6d8fd272014-05-20 21:24:38 -0700265 static final int SHORT_PRESS_POWER_NOTHING = 0;
266 static final int SHORT_PRESS_POWER_GO_TO_SLEEP = 1;
267 static final int SHORT_PRESS_POWER_REALLY_GO_TO_SLEEP = 2;
268 static final int SHORT_PRESS_POWER_REALLY_GO_TO_SLEEP_AND_GO_HOME = 3;
Bryce Lee01b0c5f2015-02-05 18:24:04 -0800269 static final int SHORT_PRESS_POWER_GO_HOME = 4;
Jeff Brown6d8fd272014-05-20 21:24:38 -0700270
Joe Onoratod208e702010-10-08 16:22:43 -0400271 static final int LONG_PRESS_POWER_NOTHING = 0;
272 static final int LONG_PRESS_POWER_GLOBAL_ACTIONS = 1;
273 static final int LONG_PRESS_POWER_SHUT_OFF = 2;
Jeff Brown9a538ee2012-08-20 14:56:57 -0700274 static final int LONG_PRESS_POWER_SHUT_OFF_NO_CONFIRM = 3;
Michael Jurka3b1fc472011-06-13 10:54:40 -0700275
Anthony Hugh34f09ca2016-03-04 12:03:37 -0800276 static final int LONG_PRESS_BACK_NOTHING = 0;
277 static final int LONG_PRESS_BACK_GO_TO_VOICE_ASSIST = 1;
278
Jeff Brown13f00f02014-10-31 14:45:50 -0700279 static final int MULTI_PRESS_POWER_NOTHING = 0;
280 static final int MULTI_PRESS_POWER_THEATER_MODE = 1;
281 static final int MULTI_PRESS_POWER_BRIGHTNESS_BOOST = 2;
282
Anthony Hugh96e9cc52016-07-12 15:17:24 -0700283 // Number of presses needed before we induce panic press behavior on the back button
284 static final int PANIC_PRESS_BACK_COUNT = 4;
285 static final int PANIC_PRESS_BACK_NOTHING = 0;
286 static final int PANIC_PRESS_BACK_HOME = 1;
287
Michael Jurka3b1fc472011-06-13 10:54:40 -0700288 // These need to match the documentation/constant in
289 // core/res/res/values/config.xml
Joe Onorato46b0d682010-11-22 17:37:27 -0800290 static final int LONG_PRESS_HOME_NOTHING = 0;
Michael Wrightc9ebea72013-01-16 19:25:02 -0800291 static final int LONG_PRESS_HOME_RECENT_SYSTEM_UI = 1;
Jeff Browncaca8812013-05-09 13:34:33 -0700292 static final int LONG_PRESS_HOME_ASSIST = 2;
Jaewan Kim76b7d0d2016-02-12 19:01:02 +0900293 static final int LAST_LONG_PRESS_HOME_BEHAVIOR = LONG_PRESS_HOME_ASSIST;
Jeff Browncaca8812013-05-09 13:34:33 -0700294
295 static final int DOUBLE_TAP_HOME_NOTHING = 0;
296 static final int DOUBLE_TAP_HOME_RECENT_SYSTEM_UI = 1;
Joe Onorato46b0d682010-11-22 17:37:27 -0800297
Jaewan Kim49117872016-01-19 17:24:08 +0900298 static final int SHORT_PRESS_WINDOW_NOTHING = 0;
299 static final int SHORT_PRESS_WINDOW_PICTURE_IN_PICTURE = 1;
300
Filip Gruszczynskia483a1d2015-03-17 19:06:58 +0000301 static final int SHORT_PRESS_SLEEP_GO_TO_SLEEP = 0;
302 static final int SHORT_PRESS_SLEEP_GO_TO_SLEEP_AND_GO_HOME = 1;
303
Anthony Hugh4b13ab82016-05-17 13:03:00 -0700304 static final int PENDING_KEY_NULL = -1;
305
Yorke Lee9b2ffb32016-03-07 20:42:01 -0800306 // Controls navigation bar opacity depending on which workspace stacks are currently
307 // visible.
308 // Nav bar is always opaque when either the freeform stack or docked stack is visible.
309 static final int NAV_BAR_OPAQUE_WHEN_FREEFORM_OR_DOCKED = 0;
310 // Nav bar is always translucent when the freeform stack is visible, otherwise always opaque.
311 static final int NAV_BAR_TRANSLUCENT_WHEN_FREEFORM_OPAQUE_OTHERWISE = 1;
312
Dianne Hackborn5cb8d792009-05-21 17:34:15 -0700313 static final int APPLICATION_MEDIA_SUBLAYER = -2;
314 static final int APPLICATION_MEDIA_OVERLAY_SUBLAYER = -1;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800315 static final int APPLICATION_PANEL_SUBLAYER = 1;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800316 static final int APPLICATION_SUB_PANEL_SUBLAYER = 2;
Wale Ogunwale0a4dc222015-04-14 12:58:42 -0700317 static final int APPLICATION_ABOVE_SUB_PANEL_SUBLAYER = 3;
Craig Mautner88400d32012-09-30 12:35:45 -0700318
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800319 static public final String SYSTEM_DIALOG_REASON_KEY = "reason";
320 static public final String SYSTEM_DIALOG_REASON_GLOBAL_ACTIONS = "globalactions";
321 static public final String SYSTEM_DIALOG_REASON_RECENT_APPS = "recentapps";
Joe Onoratof275f0c2009-11-24 16:11:13 -0500322 static public final String SYSTEM_DIALOG_REASON_HOME_KEY = "homekey";
Jeff Brownde7a8ea2012-06-13 18:28:57 -0700323 static public final String SYSTEM_DIALOG_REASON_ASSIST = "assist";
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800324
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -0700325 /**
326 * These are the system UI flags that, when changing, can cause the layout
327 * of the screen to change.
328 */
329 static final int SYSTEM_UI_CHANGING_LAYOUT =
John Spurlocke1f366f2013-08-05 12:22:40 -0400330 View.SYSTEM_UI_FLAG_HIDE_NAVIGATION
John Spurlock7f4820a2013-10-08 12:54:35 -0400331 | View.SYSTEM_UI_FLAG_FULLSCREEN
332 | View.STATUS_BAR_TRANSLUCENT
Adrian Roosea562512014-05-05 13:33:03 +0200333 | View.NAVIGATION_BAR_TRANSLUCENT
Jorim Jaggi4fa78922015-11-30 17:13:56 -0800334 | View.STATUS_BAR_TRANSPARENT
335 | View.NAVIGATION_BAR_TRANSPARENT;
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -0700336
John Spurlock7b414672014-07-18 13:02:39 -0400337 private static final AudioAttributes VIBRATION_ATTRIBUTES = new AudioAttributes.Builder()
338 .setContentType(AudioAttributes.CONTENT_TYPE_SONIFICATION)
339 .setUsage(AudioAttributes.USAGE_ASSISTANCE_SONIFICATION)
340 .build();
341
Adrian Roosddc8b272015-05-21 16:28:27 -0700342 // The panic gesture may become active only after the keyguard is dismissed and the immersive
343 // app shows again. If that doesn't happen for 30s we drop the gesture.
344 private static final long PANIC_GESTURE_EXPIRATION = 30000;
345
Winson44dbe292016-03-10 14:00:14 -0800346 private static final String SYSUI_PACKAGE = "com.android.systemui";
347 private static final String SYSUI_SCREENSHOT_SERVICE =
348 "com.android.systemui.screenshot.TakeScreenshotService";
349 private static final String SYSUI_SCREENSHOT_ERROR_RECEIVER =
350 "com.android.systemui.screenshot.ScreenshotServiceErrorReceiver";
351
Adrian Roos85d202b2016-06-02 16:27:47 -0700352 private static final int NAV_BAR_BOTTOM = 0;
353 private static final int NAV_BAR_RIGHT = 1;
354 private static final int NAV_BAR_LEFT = 2;
355
Jim Miller5ecd8112013-01-09 18:50:26 -0800356 /**
357 * Keyguard stuff
358 */
Jeff Brown3ee549c2014-09-22 20:14:39 -0700359 private boolean mKeyguardDrawnOnce;
Jim Miller5ecd8112013-01-09 18:50:26 -0800360
Jeff Brown6651a632011-11-28 12:59:11 -0800361 /* Table of Application Launch keys. Maps from key codes to intent categories.
362 *
363 * These are special keys that are used to launch particular kinds of applications,
364 * such as a web browser. HID defines nearly a hundred of them in the Consumer (0x0C)
365 * usage page. We don't support quite that many yet...
366 */
367 static SparseArray<String> sApplicationLaunchKeyCategories;
368 static {
369 sApplicationLaunchKeyCategories = new SparseArray<String>();
370 sApplicationLaunchKeyCategories.append(
371 KeyEvent.KEYCODE_EXPLORER, Intent.CATEGORY_APP_BROWSER);
372 sApplicationLaunchKeyCategories.append(
373 KeyEvent.KEYCODE_ENVELOPE, Intent.CATEGORY_APP_EMAIL);
374 sApplicationLaunchKeyCategories.append(
375 KeyEvent.KEYCODE_CONTACTS, Intent.CATEGORY_APP_CONTACTS);
376 sApplicationLaunchKeyCategories.append(
377 KeyEvent.KEYCODE_CALENDAR, Intent.CATEGORY_APP_CALENDAR);
378 sApplicationLaunchKeyCategories.append(
379 KeyEvent.KEYCODE_MUSIC, Intent.CATEGORY_APP_MUSIC);
380 sApplicationLaunchKeyCategories.append(
381 KeyEvent.KEYCODE_CALCULATOR, Intent.CATEGORY_APP_CALCULATOR);
382 }
383
Craig Mautnerc3daedd2014-09-13 11:17:23 -0700384 /** Amount of time (in milliseconds) to wait for windows drawn before powering on. */
Jorim Jaggi0d210f62015-07-10 14:24:44 -0700385 static final int WAITING_FOR_DRAWN_TIMEOUT = 1000;
Craig Mautnerc3daedd2014-09-13 11:17:23 -0700386
Svetoslav Ganovaa076532016-08-01 19:16:43 -0700387 /** Amount of time (in milliseconds) a toast window can be shown. */
388 public static final int TOAST_WINDOW_TIMEOUT = 3500; // 3.5 seconds
389
Dianne Hackborndf89e652011-10-06 22:35:11 -0700390 /**
391 * Lock protecting internal state. Must not call out into window
392 * manager with lock held. (This lock will be acquired in places
393 * where the window manager is calling in with its own lock held.)
394 */
Craig Mautner0bf6ec92012-12-18 08:33:27 -0800395 private final Object mLock = new Object();
Dianne Hackborndf89e652011-10-06 22:35:11 -0700396
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800397 Context mContext;
398 IWindowManager mWindowManager;
Dianne Hackborndf89e652011-10-06 22:35:11 -0700399 WindowManagerFuncs mWindowManagerFuncs;
Craig Mautner8a0da012014-05-31 15:13:37 -0700400 WindowManagerInternal mWindowManagerInternal;
Jeff Brown96307042012-07-27 15:51:34 -0700401 PowerManager mPowerManager;
Jeff Brown061ea992015-04-17 19:55:47 -0700402 ActivityManagerInternal mActivityManagerInternal;
Andrii Kulian112d0562016-03-08 10:44:22 -0800403 InputManagerInternal mInputManagerInternal;
Jose Lima9546b202014-07-02 17:21:51 -0700404 DreamManagerInternal mDreamManagerInternal;
Michael Wrighta4d22d72015-09-16 23:19:26 +0100405 PowerManagerInternal mPowerManagerInternal;
Joe Onorato93056472010-09-10 10:30:46 -0400406 IStatusBarService mStatusBarService;
Jorim Jaggi86905582016-02-09 21:36:09 -0800407 StatusBarManagerInternal mStatusBarManagerInternal;
Jeff Browncaca8812013-05-09 13:34:33 -0700408 boolean mPreloadedRecentApps;
Dianne Hackborn42e620c2012-06-24 13:20:51 -0700409 final Object mServiceAquireLock = new Object();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800410 Vibrator mVibrator; // Vibrator for giving feedback of orientation changes
Jeff Brownde7a8ea2012-06-13 18:28:57 -0700411 SearchManager mSearchManager;
Svetoslav8e3feb12014-02-24 13:46:47 -0800412 AccessibilityManager mAccessibilityManager;
Filip Gruszczynskicfb31852015-02-25 21:47:12 +0000413 BurnInProtectionHelper mBurnInProtectionHelper;
Billy Laucbe540f2015-06-25 01:51:44 +0100414 AppOpsManager mAppOpsManager;
Wale Ogunwale6b15ea52016-04-04 07:28:27 -0700415 private boolean mHasFeatureWatch;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800416
Dianne Hackborn181ceb52009-08-27 22:16:40 -0700417 // Vibrator pattern for haptic feedback of a long press.
418 long[] mLongPressVibePattern;
Craig Mautner88400d32012-09-30 12:35:45 -0700419
Dianne Hackborn181ceb52009-08-27 22:16:40 -0700420 // Vibrator pattern for haptic feedback of virtual key press.
421 long[] mVirtualKeyVibePattern;
Craig Mautner967212c2013-04-13 21:10:58 -0700422
Amith Yamasanic33cb712010-02-10 15:21:49 -0800423 // Vibrator pattern for a short vibration.
424 long[] mKeyboardTapVibePattern;
425
Fabrice Di Meglioeeff63a2013-08-05 12:07:24 -0700426 // Vibrator pattern for a short vibration when tapping on an hour/minute tick of a Clock.
427 long[] mClockTickVibePattern;
428
Fabrice Di Megliobd9152f2013-10-01 11:21:31 -0700429 // Vibrator pattern for a short vibration when tapping on a day/month/year date of a Calendar.
430 long[] mCalendarDateVibePattern;
431
Dianne Hackbornb1a79802009-09-29 15:18:31 -0700432 // Vibrator pattern for haptic feedback during boot when safe mode is disabled.
433 long[] mSafeModeDisabledVibePattern;
Craig Mautner967212c2013-04-13 21:10:58 -0700434
Dianne Hackbornb1a79802009-09-29 15:18:31 -0700435 // Vibrator pattern for haptic feedback during boot when safe mode is enabled.
436 long[] mSafeModeEnabledVibePattern;
Romain Guy8154cd32010-03-29 14:41:15 -0700437
Mady Mellore8608912015-06-05 09:02:55 -0700438 // Vibrator pattern for haptic feedback of a context click.
439 long[] mContextClickVibePattern;
Mady Mellore82067b2015-04-30 09:58:35 -0700440
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800441 /** If true, hitting shift & menu will broadcast Intent.ACTION_BUG_REPORT */
442 boolean mEnableShiftMenuBugReports = false;
Mike Lockwoodd747dc82011-09-13 16:28:22 -0400443
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800444 boolean mSafeMode;
445 WindowState mStatusBar = null;
Dianne Hackborn69cb8752011-05-19 18:13:32 -0700446 int mStatusBarHeight;
Daniel Sandler8956dbb2011-04-22 07:55:02 -0400447 WindowState mNavigationBar = null;
Daniel Sandler36412a72011-08-04 09:35:13 -0400448 boolean mHasNavigationBar = false;
Daniel Sandler4a066c52012-04-20 14:49:13 -0400449 boolean mNavigationBarCanMove = false; // can the navigation bar ever move to the side?
Adrian Roos85d202b2016-06-02 16:27:47 -0700450 int mNavigationBarPosition = NAV_BAR_BOTTOM;
Sriram Viswanathan9ebbe6a2015-11-16 17:59:22 -0800451 int[] mNavigationBarHeightForRotationDefault = new int[4];
452 int[] mNavigationBarWidthForRotationDefault = new int[4];
453 int[] mNavigationBarHeightForRotationInCarMode = new int[4];
454 int[] mNavigationBarWidthForRotationInCarMode = new int[4];
Daniel Sandler8956dbb2011-04-22 07:55:02 -0400455
Muyuan Li94ce94e2016-02-24 16:20:54 -0800456 private LongSparseArray<IShortcutService> mShortcutKeyServices = new LongSparseArray<>();
457
keunyounga7710492015-09-23 11:33:58 -0700458 // Whether to allow dock apps with METADATA_DOCK_HOME to temporarily take over the Home key.
459 // This is for car dock and this is updated from resource.
460 private boolean mEnableCarDockHomeCapture = true;
461
Craig Mautnera631d492014-08-05 15:16:01 -0700462 boolean mBootMessageNeedsHiding;
Jim Miller5ecd8112013-01-09 18:50:26 -0800463 KeyguardServiceDelegate mKeyguardDelegate;
Craig Mautner13f6ea72014-06-23 14:57:02 -0700464 final Runnable mWindowManagerDrawCallback = new Runnable() {
Craig Mautner8a0da012014-05-31 15:13:37 -0700465 @Override
Craig Mautner13f6ea72014-06-23 14:57:02 -0700466 public void run() {
Craig Mautner8a0da012014-05-31 15:13:37 -0700467 if (DEBUG_WAKEUP) Slog.i(TAG, "All windows ready for display!");
468 mHandler.sendEmptyMessage(MSG_WINDOW_MANAGER_DRAWN_COMPLETE);
469 }
470 };
Jorim Jaggi4cfdcf52015-07-09 12:13:59 -0700471 final DrawnListener mKeyguardDrawnCallback = new DrawnListener() {
Craig Mautner8a0da012014-05-31 15:13:37 -0700472 @Override
Jorim Jaggi4cfdcf52015-07-09 12:13:59 -0700473 public void onDrawn() {
474 if (DEBUG_WAKEUP) Slog.d(TAG, "mKeyguardDelegate.ShowListener.onDrawn.");
Craig Mautner8a0da012014-05-31 15:13:37 -0700475 mHandler.sendEmptyMessage(MSG_KEYGUARD_DRAWN_COMPLETE);
476 }
477 };
478
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800479 GlobalActions mGlobalActions;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800480 Handler mHandler;
satok1bc0a492012-04-25 22:47:12 +0900481 WindowState mLastInputMethodWindow = null;
482 WindowState mLastInputMethodTargetWindow = null;
Jeff Brown4aed78b2011-01-14 17:36:55 -0800483
Jeff Brown13f00f02014-10-31 14:45:50 -0700484 // FIXME This state is shared between the input reader and handler thread.
485 // Technically it's broken and buggy but it has been like this for many years
486 // and we have not yet seen any problems. Someday we'll rewrite this logic
487 // so that only one thread is involved in handling input policy. Unfortunately
488 // it's on a critical path for power management so we can't just post the work to the
489 // handler thread. We'll need to resolve this someday by teaching the input dispatcher
490 // to hold wakelocks during dispatch and eliminating the critical path.
491 volatile boolean mPowerKeyHandled;
Anthony Hugh34f09ca2016-03-04 12:03:37 -0800492 volatile boolean mBackKeyHandled;
Bryce Leed9268e32014-11-17 17:40:59 -0800493 volatile boolean mBeganFromNonInteractive;
Jeff Brown13f00f02014-10-31 14:45:50 -0700494 volatile int mPowerKeyPressCounter;
Anthony Hugh96e9cc52016-07-12 15:17:24 -0700495 volatile int mBackKeyPressCounter;
Jeff Brown13f00f02014-10-31 14:45:50 -0700496 volatile boolean mEndCallKeyHandled;
Jorim Jaggif1cdf952016-04-05 21:41:06 -0700497 volatile boolean mCameraGestureTriggeredDuringGoingToSleep;
498 volatile boolean mGoingToSleep;
Jaewan Kimf0fd2182016-04-20 21:17:58 +0900499 volatile boolean mRecentsVisible;
500 volatile boolean mTvPictureInPictureVisible;
Jeff Brown13f00f02014-10-31 14:45:50 -0700501
Anthony Hugh4b13ab82016-05-17 13:03:00 -0700502 // Used to hold the last user key used to wake the device. This helps us prevent up events
503 // from being passed to the foregrounded app without a corresponding down event
504 volatile int mPendingWakeKey = PENDING_KEY_NULL;
505
Winson Chung1e8d71b2014-05-16 17:05:22 -0700506 int mRecentAppsHeldModifiers;
Jeff Browncf39bdf2012-05-18 14:41:19 -0700507 boolean mLanguageSwitchKeyPressed;
Jeff Brown68b909d2011-12-07 16:36:01 -0800508
Jeff Brown2e7760e2012-04-11 15:14:55 -0700509 int mLidState = LID_ABSENT;
Michael Wright3818c922014-09-02 13:59:07 -0700510 int mCameraLensCoverState = CAMERA_LENS_COVER_ABSENT;
Jeff Browndaa37532012-05-01 15:54:03 -0700511 boolean mHaveBuiltInKeyboard;
Jeff Brown4aed78b2011-01-14 17:36:55 -0800512
Dianne Hackbornc777e072010-02-12 13:07:59 -0800513 boolean mSystemReady;
Dianne Hackbornba24e4d2011-09-01 11:17:06 -0700514 boolean mSystemBooted;
Adrian Roos3542f7d2015-07-13 15:57:53 -0700515 private boolean mDeferBindKeyguard;
Dianne Hackbornad7fa7f2011-01-07 14:06:50 -0800516 boolean mHdmiPlugged;
Jinsuk Kime601b712015-07-07 08:01:02 +0900517 HdmiControl mHdmiControl;
Jeff Brown4f5fa282014-06-12 19:19:15 -0700518 IUiModeManager mUiModeManager;
Daniel Sandler6396c722013-04-16 20:19:09 -0400519 int mUiMode;
Dianne Hackborn867ab6472010-04-29 13:28:56 -0700520 int mDockMode = Intent.EXTRA_DOCK_STATE_UNDOCKED;
Mike Lockwood1753f7f2009-08-24 14:49:07 -0700521 int mLidOpenRotation;
Mike Lockwood2d1efbd2009-09-16 12:15:53 -0400522 int mCarDockRotation;
523 int mDeskDockRotation;
Jeff Brownc82c89ed2013-04-17 17:18:15 -0700524 int mUndockedHdmiRotation;
525 int mDemoHdmiRotation;
526 boolean mDemoHdmiRotationLock;
Chong Zhangae6119ff2014-11-11 18:54:39 -0800527 int mDemoRotation;
528 boolean mDemoRotationLock;
Daniel Sandlerb73617d2010-08-17 00:41:00 -0400529
Jeff Browna20dda42014-05-27 20:57:24 -0700530 boolean mWakeGestureEnabledSetting;
531 MyWakeGestureListener mWakeGestureListener;
532
Craig Mautner46ac6fa2013-08-01 10:06:34 -0700533 // Default display does not rotate, apps that require non-default orientation will have to
534 // have the orientation emulated.
535 private boolean mForceDefaultOrientation = false;
536
Daniel Sandlerb73617d2010-08-17 00:41:00 -0400537 int mUserRotationMode = WindowManagerPolicy.USER_ROTATION_FREE;
538 int mUserRotation = Surface.ROTATION_0;
Jeff Brown207673cd2012-06-05 17:47:11 -0700539 boolean mAccelerometerDefault;
Daniel Sandlerb73617d2010-08-17 00:41:00 -0400540
Jeff Brownbcdfc622014-03-06 19:13:04 -0800541 boolean mSupportAutoRotation;
Jeff Brownd3187e32011-09-21 19:26:44 -0700542 int mAllowAllRotations = -1;
Mike Lockwoode9867d22009-09-20 01:59:02 -0400543 boolean mCarDockEnablesAccelerometer;
544 boolean mDeskDockEnablesAccelerometer;
Dianne Hackborn2862fff2009-09-15 22:56:29 -0700545 int mLidKeyboardAccessibility;
546 int mLidNavigationAccessibility;
Edward Savage-Jones7def60d2015-11-13 13:27:03 +0100547 boolean mLidControlsScreenLock;
Jeff Brownc458ce92012-04-30 14:58:40 -0700548 boolean mLidControlsSleep;
Jeff Brown13f00f02014-10-31 14:45:50 -0700549 int mShortPressOnPowerBehavior;
550 int mLongPressOnPowerBehavior;
551 int mDoublePressOnPowerBehavior;
552 int mTriplePressOnPowerBehavior;
Anthony Hugh34f09ca2016-03-04 12:03:37 -0800553 int mLongPressOnBackBehavior;
Anthony Hugh96e9cc52016-07-12 15:17:24 -0700554 int mPanicPressOnBackBehavior;
Filip Gruszczynskia483a1d2015-03-17 19:06:58 +0000555 int mShortPressOnSleepBehavior;
Jaewan Kim49117872016-01-19 17:24:08 +0900556 int mShortPressWindowBehavior;
Jeff Brown3ee549c2014-09-22 20:14:39 -0700557 boolean mAwake;
558 boolean mScreenOnEarly;
559 boolean mScreenOnFully;
560 ScreenOnListener mScreenOnListener;
561 boolean mKeyguardDrawComplete;
562 boolean mWindowManagerDrawComplete;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800563 boolean mOrientationSensorEnabled = false;
564 int mCurrentAppOrientation = ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800565 boolean mHasSoftInput = false;
Daniel Sandlerdd73ee42013-10-11 22:19:59 -0400566 boolean mTranslucentDecorEnabled = true;
RoboErik001c59c2015-01-26 15:53:51 -0800567 boolean mUseTvRouting;
Craig Mautner967212c2013-04-13 21:10:58 -0700568
Jeff Brown70825162012-03-28 17:27:48 -0700569 int mPointerLocationMode = 0; // guarded by mLock
Joe Onorato664644d2011-01-23 17:53:23 -0800570
571 // The last window we were told about in focusChanged.
572 WindowState mFocusedWindow;
Dianne Hackborne0f085d2011-11-30 18:41:15 -0800573 IApplicationToken mFocusedApp;
Joe Onorato664644d2011-01-23 17:53:23 -0800574
Jeff Brown70825162012-03-28 17:27:48 -0700575 PointerLocationView mPointerLocationView;
Jeff Brown32cbc38552011-12-01 14:01:49 -0800576
Dianne Hackbornc652de82013-02-15 16:32:56 -0800577 // The current size of the screen; really; extends into the overscan area of
578 // the screen and doesn't account for any system elements like the status bar.
579 int mOverscanScreenLeft, mOverscanScreenTop;
580 int mOverscanScreenWidth, mOverscanScreenHeight;
581 // The current visible size of the screen; really; (ir)regardless of whether the status
582 // bar can be hidden but not extending into the overscan area.
Joe Onorato29fc2c92010-11-24 10:26:50 -0800583 int mUnrestrictedScreenLeft, mUnrestrictedScreenTop;
584 int mUnrestrictedScreenWidth, mUnrestrictedScreenHeight;
Dianne Hackborn313440842013-02-19 19:22:59 -0800585 // Like mOverscanScreen*, but allowed to move into the overscan region where appropriate.
586 int mRestrictedOverscanScreenLeft, mRestrictedOverscanScreenTop;
587 int mRestrictedOverscanScreenWidth, mRestrictedOverscanScreenHeight;
Dianne Hackborn82de1ae2010-10-28 11:28:39 -0700588 // The current size of the screen; these may be different than (0,0)-(dw,dh)
589 // if the status bar can't be hidden; in that case it effectively carves out
590 // that area of the display from all other windows.
Joe Onorato29fc2c92010-11-24 10:26:50 -0800591 int mRestrictedScreenLeft, mRestrictedScreenTop;
592 int mRestrictedScreenWidth, mRestrictedScreenHeight;
Dianne Hackborn5c58de32012-04-28 19:52:37 -0700593 // During layout, the current screen borders accounting for any currently
594 // visible system UI elements.
595 int mSystemLeft, mSystemTop, mSystemRight, mSystemBottom;
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -0700596 // For applications requesting stable content insets, these are them.
597 int mStableLeft, mStableTop, mStableRight, mStableBottom;
Dianne Hackborn5b5cc4d2012-05-16 13:15:00 -0700598 // For applications requesting stable content insets but have also set the
599 // fullscreen window flag, these are the stable dimensions without the status bar.
600 int mStableFullscreenLeft, mStableFullscreenTop;
601 int mStableFullscreenRight, mStableFullscreenBottom;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800602 // During layout, the current screen borders with all outer decoration
603 // (status bar, input method dock) accounted for.
604 int mCurLeft, mCurTop, mCurRight, mCurBottom;
605 // During layout, the frame in which content should be displayed
606 // to the user, accounting for all screen decoration except for any
607 // space they deem as available for other content. This is usually
608 // the same as mCur*, but may be larger if the screen decor has supplied
609 // content insets.
610 int mContentLeft, mContentTop, mContentRight, mContentBottom;
Dianne Hackborne30e02f2014-05-27 18:24:45 -0700611 // During layout, the frame in which voice content should be displayed
612 // to the user, accounting for all screen decoration except for any
613 // space they deem as available for other content.
614 int mVoiceContentLeft, mVoiceContentTop, mVoiceContentRight, mVoiceContentBottom;
Dianne Hackborn8e11ef02010-11-18 19:47:42 -0800615 // During layout, the current screen borders along which input method
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800616 // windows are placed.
617 int mDockLeft, mDockTop, mDockRight, mDockBottom;
618 // During layout, the layer at which the doc window is placed.
619 int mDockLayer;
Dianne Hackborn5c58de32012-04-28 19:52:37 -0700620 // During layout, this is the layer of the status bar.
621 int mStatusBarLayer;
Dianne Hackborne26ab702011-10-16 13:21:33 -0700622 int mLastSystemUiFlags;
623 // Bits that we are in the process of clearing, so we want to prevent
624 // them from being set by applications until everything has been updated
625 // to have them clear.
626 int mResettingSystemUiFlags = 0;
627 // Bits that we are currently always keeping cleared.
628 int mForceClearedSystemUiFlags = 0;
Jorim Jaggi86905582016-02-09 21:36:09 -0800629 int mLastFullscreenStackSysUiFlags;
630 int mLastDockedStackSysUiFlags;
631 final Rect mNonDockedStackBounds = new Rect();
632 final Rect mDockedStackBounds = new Rect();
633 final Rect mLastNonDockedStackBounds = new Rect();
634 final Rect mLastDockedStackBounds = new Rect();
635
Dianne Hackborn4eff8d32011-11-10 19:38:40 -0800636 // What we last reported to system UI about whether the compatibility
637 // menu needs to be displayed.
638 boolean mLastFocusNeedsMenu = false;
Adrian Roosddc8b272015-05-21 16:28:27 -0700639 // If nonzero, a panic gesture was performed at that time in uptime millis and is still pending.
640 private long mPendingPanicGestureUptime;
Dianne Hackborndf89e652011-10-06 22:35:11 -0700641
Selim Cinekf83e8242015-05-19 18:08:14 -0700642 InputConsumer mInputConsumer = null;
Dianne Hackborndf89e652011-10-06 22:35:11 -0700643
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800644 static final Rect mTmpParentFrame = new Rect();
645 static final Rect mTmpDisplayFrame = new Rect();
Dianne Hackbornc4aad012013-02-22 15:05:25 -0800646 static final Rect mTmpOverscanFrame = new Rect();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800647 static final Rect mTmpContentFrame = new Rect();
648 static final Rect mTmpVisibleFrame = new Rect();
John Spurlock46646232013-09-30 22:32:42 -0400649 static final Rect mTmpDecorFrame = new Rect();
Adrian Roosfa104232014-06-20 16:10:14 -0700650 static final Rect mTmpStableFrame = new Rect();
Dianne Hackborn1f903c32011-09-13 19:18:06 -0700651 static final Rect mTmpNavigationFrame = new Rect();
Filip Gruszczynski2217f612015-05-26 11:32:08 -0700652 static final Rect mTmpOutsetFrame = new Rect();
Jorim Jaggi23bf5462016-05-13 15:24:39 -0700653 private static final Rect mTmpRect = new Rect();
Craig Mautner967212c2013-04-13 21:10:58 -0700654
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800655 WindowState mTopFullscreenOpaqueWindowState;
Adrian Rooscd3884d2015-02-18 17:25:23 +0100656 WindowState mTopFullscreenOpaqueOrDimmingWindowState;
Jorim Jaggi86905582016-02-09 21:36:09 -0800657 WindowState mTopDockedOpaqueWindowState;
658 WindowState mTopDockedOpaqueOrDimmingWindowState;
Joe Onorato93056472010-09-10 10:30:46 -0400659 boolean mTopIsFullscreen;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800660 boolean mForceStatusBar;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -0700661 boolean mForceStatusBarFromKeyguard;
Selim Cinek4a4a2bddc2015-05-07 12:50:19 -0700662 private boolean mForceStatusBarTransparent;
Yorke Lee9b2ffb32016-03-07 20:42:01 -0800663 int mNavBarOpacityMode = NAV_BAR_OPAQUE_WHEN_FREEFORM_OR_DOCKED;
Dianne Hackborn891d3fb2013-01-09 18:31:37 -0800664 boolean mForcingShowNavBar;
665 int mForcingShowNavBarLayer;
Craig Mautnerad09bcc2012-10-08 13:33:11 -0700666
Jorim Jaggife762342016-10-13 14:33:27 +0200667 private boolean mPendingKeyguardOccluded;
668 private boolean mKeyguardOccludedChanged;
Craig Mautnerc9457fa2014-06-06 14:27:48 -0700669
Dianne Hackborn7ad44382012-10-18 17:46:00 -0700670 boolean mShowingDream;
Jorim Jaggi77e10432016-10-26 17:43:56 -0700671 private boolean mLastShowingDream;
Dianne Hackborn7ad44382012-10-18 17:46:00 -0700672 boolean mDreamingLockscreen;
Jeff Brown061ea992015-04-17 19:55:47 -0700673 boolean mDreamingSleepTokenNeeded;
674 SleepToken mDreamingSleepToken;
Jeff Brown48d1b142015-06-10 16:36:03 -0700675 SleepToken mScreenOffSleepToken;
Jim Millerab954542014-10-10 18:21:49 -0700676 volatile boolean mKeyguardOccluded;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800677 boolean mHomePressed;
Jeff Browncaca8812013-05-09 13:34:33 -0700678 boolean mHomeConsumed;
679 boolean mHomeDoubleTapPending;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800680 Intent mHomeIntent;
Dianne Hackborn39c2d712009-09-22 11:41:31 -0700681 Intent mCarDockIntent;
682 Intent mDeskDockIntent;
Jeff Brownfd23e3e2012-05-09 13:34:28 -0700683 boolean mSearchKeyShortcutPending;
684 boolean mConsumeSearchKeyUp;
Jeff Brownde7a8ea2012-06-13 18:28:57 -0700685 boolean mAssistKeyLongPressed;
Michael Wright6a62e552014-06-03 19:19:48 -0700686 boolean mPendingMetaAction;
Andrii Kulian112d0562016-03-08 10:44:22 -0800687 boolean mPendingCapsLockToggle;
688 int mMetaState;
689 int mInitialMetaState;
Jorim Jaggi0ffd49c2016-02-12 15:04:21 -0800690 boolean mForceShowSystemBars;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800691
Mike Lockwood28569302010-01-28 11:54:40 -0500692 // support for activating the lock screen while the screen is on
693 boolean mAllowLockscreenWhenOn;
694 int mLockScreenTimeout;
695 boolean mLockScreenTimerActive;
696
David Brownbaf8d092010-03-08 21:52:59 -0800697 // Behavior of ENDCALL Button. (See Settings.System.END_BUTTON_BEHAVIOR.)
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800698 int mEndcallBehavior;
David Brownbaf8d092010-03-08 21:52:59 -0800699
700 // Behavior of POWER button while in-call and screen on.
701 // (See Settings.Secure.INCALL_POWER_BUTTON_BEHAVIOR.)
702 int mIncallPowerBehavior;
703
Bryce Leedb776ce2016-09-03 15:02:00 -0700704 // Behavior of Back button while in-call and screen on
705 int mIncallBackBehavior;
706
Dianne Hackbornf87d1962012-04-04 12:48:24 -0700707 Display mDisplay;
708
Filip Gruszczynski2987f612015-06-30 15:03:30 -0700709 private int mDisplayRotation;
710
Dianne Hackborn9d132642011-04-21 17:26:39 -0700711 int mLandscapeRotation = 0; // default landscape rotation
712 int mSeascapeRotation = 0; // "other" landscape rotation, 180 degrees from mLandscapeRotation
713 int mPortraitRotation = 0; // default portrait rotation
714 int mUpsideDownRotation = 0; // "other" portrait rotation
Mitsuru Oshima831d0d92009-06-16 18:27:18 -0700715
Dianne Hackbornc652de82013-02-15 16:32:56 -0800716 int mOverscanLeft = 0;
717 int mOverscanTop = 0;
718 int mOverscanRight = 0;
719 int mOverscanBottom = 0;
720
Joe Onorato46b0d682010-11-22 17:37:27 -0800721 // What we do when the user long presses on home
Jeff Browncaca8812013-05-09 13:34:33 -0700722 private int mLongPressOnHomeBehavior;
723
724 // What we do when the user double-taps on home
725 private int mDoubleTapOnHomeBehavior;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800726
Bryce Lee584a4452014-10-21 15:55:55 -0700727 // Allowed theater mode wake actions
728 private boolean mAllowTheaterModeWakeFromKey;
729 private boolean mAllowTheaterModeWakeFromPowerKey;
730 private boolean mAllowTheaterModeWakeFromMotion;
Bryce Lee812d7022014-11-10 13:33:28 -0800731 private boolean mAllowTheaterModeWakeFromMotionWhenNotDreaming;
Bryce Lee584a4452014-10-21 15:55:55 -0700732 private boolean mAllowTheaterModeWakeFromCameraLens;
733 private boolean mAllowTheaterModeWakeFromLidSwitch;
734 private boolean mAllowTheaterModeWakeFromWakeGesture;
735
Bryce Leed3b28402015-03-09 15:49:13 +0000736 // Whether to support long press from power button in non-interactive mode
737 private boolean mSupportLongPressPowerWhenNonInteractive;
738
Bryce Lee55e846d2014-11-04 12:43:44 -0800739 // Whether to go to sleep entering theater mode from power button
740 private boolean mGoToSleepOnButtonPressTheaterMode;
741
Winson Chung9112ec32011-06-27 13:15:32 -0700742 // Screenshot trigger states
Jeff Brownd5bb82d2011-10-12 13:57:59 -0700743 // Time to volume and power must be pressed within this interval of each other.
744 private static final long SCREENSHOT_CHORD_DEBOUNCE_DELAY_MILLIS = 150;
Winson Chung1cea2f32012-10-08 20:42:01 -0700745 // Increase the chord delay when taking a screenshot from the keyguard
746 private static final float KEYGUARD_SCREENSHOT_CHORD_DELAY_MULTIPLIER = 2.5f;
Christopher Tatee90585f2012-03-05 18:56:25 -0800747 private boolean mScreenshotChordEnabled;
Jeff Brown13f00f02014-10-31 14:45:50 -0700748 private boolean mScreenshotChordVolumeDownKeyTriggered;
749 private long mScreenshotChordVolumeDownKeyTime;
750 private boolean mScreenshotChordVolumeDownKeyConsumed;
751 private boolean mScreenshotChordVolumeUpKeyTriggered;
752 private boolean mScreenshotChordPowerKeyTriggered;
753 private long mScreenshotChordPowerKeyTime;
Winson Chung9112ec32011-06-27 13:15:32 -0700754
Michael Wrightb854e242013-02-05 17:54:02 -0800755 /* The number of steps between min and max brightness */
756 private static final int BRIGHTNESS_STEPS = 10;
757
Christopher Tate5e08af02012-09-21 17:17:22 -0700758 SettingsObserver mSettingsObserver;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800759 ShortcutManager mShortcutManager;
760 PowerManager.WakeLock mBroadcastWakeLock;
Jeff Brown13f00f02014-10-31 14:45:50 -0700761 PowerManager.WakeLock mPowerKeyWakeLock;
Jeff Brown40013652012-05-16 21:22:36 -0700762 boolean mHavePendingMediaKeyRepeatWithWakeLock;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800763
Craig Mautnerd625ab22013-09-06 13:40:31 -0700764 private int mCurrentUserId;
765
Justin Kohd378ad72013-04-01 12:18:26 -0700766 // Maps global key codes to the components that will handle them.
767 private GlobalKeyManager mGlobalKeyManager;
768
Jeff Brownfd23e3e2012-05-09 13:34:28 -0700769 // Fallback actions by key code.
770 private final SparseArray<KeyCharacterMap.FallbackAction> mFallbackActions =
771 new SparseArray<KeyCharacterMap.FallbackAction>();
Jeff Brown49ed71d2010-12-06 17:13:33 -0800772
Jorim Jaggi76a16232014-08-08 17:00:47 +0200773 private final LogDecelerateInterpolator mLogDecelerateInterpolator
774 = new LogDecelerateInterpolator(100, 0);
775
Jorim Jaggif1cdf952016-04-05 21:41:06 -0700776 private final MutableBoolean mTmpBoolean = new MutableBoolean(false);
Wale Ogunwale6b15ea52016-04-04 07:28:27 -0700777
Jeff Brown70825162012-03-28 17:27:48 -0700778 private static final int MSG_ENABLE_POINTER_LOCATION = 1;
779 private static final int MSG_DISABLE_POINTER_LOCATION = 2;
Jeff Brown40013652012-05-16 21:22:36 -0700780 private static final int MSG_DISPATCH_MEDIA_KEY_WITH_WAKE_LOCK = 3;
781 private static final int MSG_DISPATCH_MEDIA_KEY_REPEAT_WITH_WAKE_LOCK = 4;
Craig Mautner8a0da012014-05-31 15:13:37 -0700782 private static final int MSG_KEYGUARD_DRAWN_COMPLETE = 5;
783 private static final int MSG_KEYGUARD_DRAWN_TIMEOUT = 6;
784 private static final int MSG_WINDOW_MANAGER_DRAWN_COMPLETE = 7;
Craig Mautner84984fa2014-06-19 11:19:20 -0700785 private static final int MSG_DISPATCH_SHOW_RECENTS = 9;
Alan Viverettee34560b22014-07-10 14:50:06 -0700786 private static final int MSG_DISPATCH_SHOW_GLOBAL_ACTIONS = 10;
Craig Mautnera631d492014-08-05 15:16:01 -0700787 private static final int MSG_HIDE_BOOT_MESSAGE = 11;
Michael Wright869a67c2014-08-26 19:33:06 -0700788 private static final int MSG_LAUNCH_VOICE_ASSIST_WITH_WAKE_LOCK = 12;
Jeff Brown13f00f02014-10-31 14:45:50 -0700789 private static final int MSG_POWER_DELAYED_PRESS = 13;
790 private static final int MSG_POWER_LONG_PRESS = 14;
Jeff Brown061ea992015-04-17 19:55:47 -0700791 private static final int MSG_UPDATE_DREAMING_SLEEP_TOKEN = 15;
Jun Mukaid2e7e352015-07-22 17:14:02 -0700792 private static final int MSG_REQUEST_TRANSIENT_BARS = 16;
Jaewan Kimf0fd2182016-04-20 21:17:58 +0900793 private static final int MSG_SHOW_TV_PICTURE_IN_PICTURE_MENU = 17;
Anthony Hugh34f09ca2016-03-04 12:03:37 -0800794 private static final int MSG_BACK_LONG_PRESS = 18;
Chong Zhang9f7fb092016-05-20 17:03:08 -0700795 private static final int MSG_DISPOSE_INPUT_CONSUMER = 19;
Anthony Hugh96e9cc52016-07-12 15:17:24 -0700796 private static final int MSG_BACK_DELAYED_PRESS = 20;
Jun Mukaid2e7e352015-07-22 17:14:02 -0700797
798 private static final int MSG_REQUEST_TRANSIENT_BARS_ARG_STATUS = 0;
799 private static final int MSG_REQUEST_TRANSIENT_BARS_ARG_NAVIGATION = 1;
Jeff Brown70825162012-03-28 17:27:48 -0700800
801 private class PolicyHandler extends Handler {
802 @Override
803 public void handleMessage(Message msg) {
804 switch (msg.what) {
805 case MSG_ENABLE_POINTER_LOCATION:
806 enablePointerLocation();
807 break;
808 case MSG_DISABLE_POINTER_LOCATION:
809 disablePointerLocation();
810 break;
Jeff Brown40013652012-05-16 21:22:36 -0700811 case MSG_DISPATCH_MEDIA_KEY_WITH_WAKE_LOCK:
812 dispatchMediaKeyWithWakeLock((KeyEvent)msg.obj);
813 break;
814 case MSG_DISPATCH_MEDIA_KEY_REPEAT_WITH_WAKE_LOCK:
815 dispatchMediaKeyRepeatWithWakeLock((KeyEvent)msg.obj);
816 break;
Craig Mautner84984fa2014-06-19 11:19:20 -0700817 case MSG_DISPATCH_SHOW_RECENTS:
Jorim Jaggi681fc7b2016-04-14 22:02:39 -0700818 showRecentApps(false, msg.arg1 != 0);
Craig Mautner84984fa2014-06-19 11:19:20 -0700819 break;
Alan Viverettee34560b22014-07-10 14:50:06 -0700820 case MSG_DISPATCH_SHOW_GLOBAL_ACTIONS:
821 showGlobalActionsInternal();
822 break;
Craig Mautner8a0da012014-05-31 15:13:37 -0700823 case MSG_KEYGUARD_DRAWN_COMPLETE:
824 if (DEBUG_WAKEUP) Slog.w(TAG, "Setting mKeyguardDrawComplete");
Jeff Brown36c4db82014-09-19 12:05:31 -0700825 finishKeyguardDrawn();
Craig Mautner8a0da012014-05-31 15:13:37 -0700826 break;
827 case MSG_KEYGUARD_DRAWN_TIMEOUT:
828 Slog.w(TAG, "Keyguard drawn timeout. Setting mKeyguardDrawComplete");
Jeff Brown36c4db82014-09-19 12:05:31 -0700829 finishKeyguardDrawn();
Craig Mautner8a0da012014-05-31 15:13:37 -0700830 break;
831 case MSG_WINDOW_MANAGER_DRAWN_COMPLETE:
832 if (DEBUG_WAKEUP) Slog.w(TAG, "Setting mWindowManagerDrawComplete");
Jeff Brown36c4db82014-09-19 12:05:31 -0700833 finishWindowsDrawn();
Craig Mautner8a0da012014-05-31 15:13:37 -0700834 break;
Craig Mautnera631d492014-08-05 15:16:01 -0700835 case MSG_HIDE_BOOT_MESSAGE:
836 handleHideBootMessage();
837 break;
Michael Wright869a67c2014-08-26 19:33:06 -0700838 case MSG_LAUNCH_VOICE_ASSIST_WITH_WAKE_LOCK:
839 launchVoiceAssistWithWakeLock(msg.arg1 != 0);
840 break;
Jeff Brown13f00f02014-10-31 14:45:50 -0700841 case MSG_POWER_DELAYED_PRESS:
842 powerPress((Long)msg.obj, msg.arg1 != 0, msg.arg2);
843 finishPowerKeyPress();
844 break;
845 case MSG_POWER_LONG_PRESS:
846 powerLongPress();
847 break;
Jeff Brown061ea992015-04-17 19:55:47 -0700848 case MSG_UPDATE_DREAMING_SLEEP_TOKEN:
849 updateDreamingSleepToken(msg.arg1 != 0);
850 break;
Jun Mukaid2e7e352015-07-22 17:14:02 -0700851 case MSG_REQUEST_TRANSIENT_BARS:
852 WindowState targetBar = (msg.arg1 == MSG_REQUEST_TRANSIENT_BARS_ARG_STATUS) ?
853 mStatusBar : mNavigationBar;
854 if (targetBar != null) {
855 requestTransientBars(targetBar);
856 }
857 break;
Jaewan Kimf0fd2182016-04-20 21:17:58 +0900858 case MSG_SHOW_TV_PICTURE_IN_PICTURE_MENU:
859 showTvPictureInPictureMenuInternal();
Jaewan Kimc552b042016-01-18 16:08:45 +0900860 break;
Anthony Hugh34f09ca2016-03-04 12:03:37 -0800861 case MSG_BACK_LONG_PRESS:
862 backLongPress();
Anthony Hugh96e9cc52016-07-12 15:17:24 -0700863 finishBackKeyPress();
Anthony Hugh34f09ca2016-03-04 12:03:37 -0800864 break;
Chong Zhang9f7fb092016-05-20 17:03:08 -0700865 case MSG_DISPOSE_INPUT_CONSUMER:
866 disposeInputConsumer((InputConsumer) msg.obj);
867 break;
Anthony Hugh96e9cc52016-07-12 15:17:24 -0700868 case MSG_BACK_DELAYED_PRESS:
869 backMultiPressAction((Long) msg.obj, msg.arg1);
870 finishBackKeyPress();
871 break;
Jeff Brown70825162012-03-28 17:27:48 -0700872 }
873 }
874 }
875
Dianne Hackbornad7fa7f2011-01-07 14:06:50 -0800876 private UEventObserver mHDMIObserver = new UEventObserver() {
877 @Override
878 public void onUEvent(UEventObserver.UEvent event) {
879 setHdmiPlugged("1".equals(event.get("SWITCH_STATE")));
880 }
881 };
882
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800883 class SettingsObserver extends ContentObserver {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800884 SettingsObserver(Handler handler) {
885 super(handler);
886 }
David Brownbaf8d092010-03-08 21:52:59 -0800887
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800888 void observe() {
Christopher Tate5e08af02012-09-21 17:17:22 -0700889 // Observe all users' changes
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800890 ContentResolver resolver = mContext.getContentResolver();
891 resolver.registerContentObserver(Settings.System.getUriFor(
Christopher Tate5e08af02012-09-21 17:17:22 -0700892 Settings.System.END_BUTTON_BEHAVIOR), false, this,
893 UserHandle.USER_ALL);
David Brownbaf8d092010-03-08 21:52:59 -0800894 resolver.registerContentObserver(Settings.Secure.getUriFor(
Christopher Tate5e08af02012-09-21 17:17:22 -0700895 Settings.Secure.INCALL_POWER_BUTTON_BEHAVIOR), false, this,
896 UserHandle.USER_ALL);
Jeff Browna20dda42014-05-27 20:57:24 -0700897 resolver.registerContentObserver(Settings.Secure.getUriFor(
Bryce Leedb776ce2016-09-03 15:02:00 -0700898 Settings.Secure.INCALL_BACK_BUTTON_BEHAVIOR), false, this,
899 UserHandle.USER_ALL);
900 resolver.registerContentObserver(Settings.Secure.getUriFor(
Jeff Browna20dda42014-05-27 20:57:24 -0700901 Settings.Secure.WAKE_GESTURE_ENABLED), false, this,
902 UserHandle.USER_ALL);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800903 resolver.registerContentObserver(Settings.System.getUriFor(
Christopher Tate5e08af02012-09-21 17:17:22 -0700904 Settings.System.ACCELEROMETER_ROTATION), false, this,
905 UserHandle.USER_ALL);
Mike Lockwood28569302010-01-28 11:54:40 -0500906 resolver.registerContentObserver(Settings.System.getUriFor(
Christopher Tate5e08af02012-09-21 17:17:22 -0700907 Settings.System.USER_ROTATION), false, this,
908 UserHandle.USER_ALL);
Daniel Sandlerb73617d2010-08-17 00:41:00 -0400909 resolver.registerContentObserver(Settings.System.getUriFor(
Christopher Tate5e08af02012-09-21 17:17:22 -0700910 Settings.System.SCREEN_OFF_TIMEOUT), false, this,
911 UserHandle.USER_ALL);
Dianne Hackbornc777e072010-02-12 13:07:59 -0800912 resolver.registerContentObserver(Settings.System.getUriFor(
Christopher Tate5e08af02012-09-21 17:17:22 -0700913 Settings.System.POINTER_LOCATION), false, this,
914 UserHandle.USER_ALL);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800915 resolver.registerContentObserver(Settings.Secure.getUriFor(
Christopher Tate5e08af02012-09-21 17:17:22 -0700916 Settings.Secure.DEFAULT_INPUT_METHOD), false, this,
917 UserHandle.USER_ALL);
John Spurlockd9b70bd2014-02-06 17:02:44 -0500918 resolver.registerContentObserver(Settings.Secure.getUriFor(
John Spurlockf1a36642013-10-12 17:50:42 -0400919 Settings.Secure.IMMERSIVE_MODE_CONFIRMATIONS), false, this,
Christopher Tate5e08af02012-09-21 17:17:22 -0700920 UserHandle.USER_ALL);
John Spurlockc6d1c602014-01-17 15:22:06 -0500921 resolver.registerContentObserver(Settings.Global.getUriFor(
922 Settings.Global.POLICY_CONTROL), false, this,
923 UserHandle.USER_ALL);
Dianne Hackbornc777e072010-02-12 13:07:59 -0800924 updateSettings();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800925 }
926
927 @Override public void onChange(boolean selfChange) {
Dianne Hackbornc777e072010-02-12 13:07:59 -0800928 updateSettings();
Jeff Brown01a98dd2011-09-20 15:08:29 -0700929 updateRotation(false);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800930 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800931 }
Craig Mautner967212c2013-04-13 21:10:58 -0700932
Jeff Browna20dda42014-05-27 20:57:24 -0700933 class MyWakeGestureListener extends WakeGestureListener {
934 MyWakeGestureListener(Context context, Handler handler) {
935 super(context, handler);
936 }
937
938 @Override
939 public void onWakeUp() {
940 synchronized (mLock) {
941 if (shouldEnableWakeGestureLp()) {
Jeff Browne07b94b2014-06-18 15:56:27 -0700942 performHapticFeedbackLw(null, HapticFeedbackConstants.VIRTUAL_KEY, false);
Dianne Hackborn280a64e2015-07-13 14:48:08 -0700943 wakeUp(SystemClock.uptimeMillis(), mAllowTheaterModeWakeFromWakeGesture,
944 "android.policy:GESTURE");
Jeff Browna20dda42014-05-27 20:57:24 -0700945 }
946 }
947 }
948 }
949
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800950 class MyOrientationListener extends WindowOrientationListener {
Chong Zhang5aaa0b32015-08-28 10:22:36 -0700951 private final Runnable mUpdateRotationRunnable = new Runnable() {
952 @Override
953 public void run() {
Tim Murray1f407642015-10-01 17:07:12 -0700954 // send interaction hint to improve redraw performance
Ruchi Kandoi0d434042016-10-03 09:12:02 -0700955 mPowerManagerInternal.powerHint(PowerHint.INTERACTION, 0);
Chong Zhang5aaa0b32015-08-28 10:22:36 -0700956 updateRotation(false);
957 }
958 };
959
Craig Mautnereee29c42013-01-17 14:44:34 -0800960 MyOrientationListener(Context context, Handler handler) {
961 super(context, handler);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800962 }
Craig Mautner967212c2013-04-13 21:10:58 -0700963
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800964 @Override
Jeff Brownc0347aa2011-09-23 17:26:09 -0700965 public void onProposedRotationChanged(int rotation) {
Craig Mautnereda67292013-04-28 13:50:14 -0700966 if (localLOGV) Slog.v(TAG, "onProposedRotationChanged, rotation=" + rotation);
Chong Zhang5aaa0b32015-08-28 10:22:36 -0700967 mHandler.post(mUpdateRotationRunnable);
Jeff Brown01a98dd2011-09-20 15:08:29 -0700968 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800969 }
970 MyOrientationListener mOrientationListener;
971
Jorim Jaggi24bec7c2015-02-04 12:40:14 +0100972 private final StatusBarController mStatusBarController = new StatusBarController();
John Spurlock5b9145b2013-08-20 15:13:47 -0400973
John Spurlock27735a42013-08-14 17:57:38 -0400974 private final BarController mNavigationBarController = new BarController("NavigationBar",
John Spurlock5b9145b2013-08-20 15:13:47 -0400975 View.NAVIGATION_BAR_TRANSIENT,
976 View.NAVIGATION_BAR_UNHIDE,
John Spurlockbd957402013-10-03 11:38:39 -0400977 View.NAVIGATION_BAR_TRANSLUCENT,
978 StatusBarManager.WINDOW_NAVIGATION_BAR,
Jorim Jaggi4fa78922015-11-30 17:13:56 -0800979 WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION,
980 View.NAVIGATION_BAR_TRANSPARENT);
John Spurlock5b9145b2013-08-20 15:13:47 -0400981
John Spurlockf1a36642013-10-12 17:50:42 -0400982 private ImmersiveModeConfirmation mImmersiveModeConfirmation;
John Spurlock32beb2c2013-03-11 10:16:47 -0400983
Craig Mautner037aa8d2013-06-07 10:35:44 -0700984 private SystemGesturesPointerEventListener mSystemGestures;
John Spurlock32beb2c2013-03-11 10:16:47 -0400985
Dianne Hackborn42e620c2012-06-24 13:20:51 -0700986 IStatusBarService getStatusBarService() {
987 synchronized (mServiceAquireLock) {
988 if (mStatusBarService == null) {
989 mStatusBarService = IStatusBarService.Stub.asInterface(
990 ServiceManager.getService("statusbar"));
991 }
992 return mStatusBarService;
993 }
994 }
995
Jorim Jaggi86905582016-02-09 21:36:09 -0800996 StatusBarManagerInternal getStatusBarManagerInternal() {
997 synchronized (mServiceAquireLock) {
998 if (mStatusBarManagerInternal == null) {
999 mStatusBarManagerInternal =
1000 LocalServices.getService(StatusBarManagerInternal.class);
1001 }
1002 return mStatusBarManagerInternal;
1003 }
1004 }
1005
Suchi Amalapurapua9e1b162009-03-24 22:24:47 -07001006 /*
1007 * We always let the sensor be switched on by default except when
1008 * the user has explicitly disabled sensor based rotation or when the
1009 * screen is switched off.
1010 */
The Android Open Source Project0727d222009-03-11 12:11:58 -07001011 boolean needSensorRunningLp() {
Jeff Brownbcdfc622014-03-06 19:13:04 -08001012 if (mSupportAutoRotation) {
1013 if (mCurrentAppOrientation == ActivityInfo.SCREEN_ORIENTATION_SENSOR
1014 || mCurrentAppOrientation == ActivityInfo.SCREEN_ORIENTATION_FULL_SENSOR
1015 || mCurrentAppOrientation == ActivityInfo.SCREEN_ORIENTATION_SENSOR_PORTRAIT
1016 || mCurrentAppOrientation == ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE) {
1017 // If the application has explicitly requested to follow the
1018 // orientation, then we need to turn the sensor on.
1019 return true;
1020 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001021 }
Dianne Hackborn867ab6472010-04-29 13:28:56 -07001022 if ((mCarDockEnablesAccelerometer && mDockMode == Intent.EXTRA_DOCK_STATE_CAR) ||
Jeff Brown1a693182011-11-08 14:44:16 -08001023 (mDeskDockEnablesAccelerometer && (mDockMode == Intent.EXTRA_DOCK_STATE_DESK
1024 || mDockMode == Intent.EXTRA_DOCK_STATE_LE_DESK
1025 || mDockMode == Intent.EXTRA_DOCK_STATE_HE_DESK))) {
Mike Lockwoode9867d22009-09-20 01:59:02 -04001026 // enable accelerometer if we are docked in a dock that enables accelerometer
1027 // orientation management,
1028 return true;
1029 }
Jeff Brown207673cd2012-06-05 17:47:11 -07001030 if (mUserRotationMode == USER_ROTATION_LOCKED) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001031 // If the setting for using the sensor by default is enabled, then
1032 // we will always leave it on. Note that the user could go to
1033 // a window that forces an orientation that does not use the
1034 // sensor and in theory we could turn it off... however, when next
1035 // turning it on we won't have a good value for the current
1036 // orientation for a little bit, which can cause orientation
1037 // changes to lag, so we'd like to keep it always on. (It will
1038 // still be turned off when the screen is off.)
Suchi Amalapurapua9e1b162009-03-24 22:24:47 -07001039 return false;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001040 }
Jeff Brownbcdfc622014-03-06 19:13:04 -08001041 return mSupportAutoRotation;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001042 }
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001043
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001044 /*
1045 * Various use cases for invoking this function
1046 * screen turning off, should always disable listeners if already enabled
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001047 * screen turned on and current app has sensor based orientation, enable listeners
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001048 * if not already enabled
1049 * screen turned on and current app does not have sensor orientation, disable listeners if
1050 * already enabled
1051 * screen turning on and current app has sensor based orientation, enable listeners if needed
1052 * screen turning on and current app has nosensor based orientation, do nothing
1053 */
The Android Open Source Project0727d222009-03-11 12:11:58 -07001054 void updateOrientationListenerLp() {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001055 if (!mOrientationListener.canDetectOrientation()) {
1056 // If sensor is turned off or nonexistent for some reason
1057 return;
1058 }
Stefan Kuhne9326dc12015-06-12 09:25:32 -10001059 // Could have been invoked due to screen turning on or off or
1060 // change of the currently visible window's orientation.
Jeff Brown3ee549c2014-09-22 20:14:39 -07001061 if (localLOGV) Slog.v(TAG, "mScreenOnEarly=" + mScreenOnEarly
1062 + ", mAwake=" + mAwake + ", mCurrentAppOrientation=" + mCurrentAppOrientation
Stefan Kuhne9326dc12015-06-12 09:25:32 -10001063 + ", mOrientationSensorEnabled=" + mOrientationSensorEnabled
1064 + ", mKeyguardDrawComplete=" + mKeyguardDrawComplete
1065 + ", mWindowManagerDrawComplete=" + mWindowManagerDrawComplete);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001066 boolean disable = true;
Stefan Kuhne9326dc12015-06-12 09:25:32 -10001067 // Note: We postpone the rotating of the screen until the keyguard as well as the
1068 // window manager have reported a draw complete.
1069 if (mScreenOnEarly && mAwake &&
1070 mKeyguardDrawComplete && mWindowManagerDrawComplete) {
The Android Open Source Project0727d222009-03-11 12:11:58 -07001071 if (needSensorRunningLp()) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001072 disable = false;
1073 //enable listener if not already enabled
The Android Open Source Project0727d222009-03-11 12:11:58 -07001074 if (!mOrientationSensorEnabled) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001075 mOrientationListener.enable();
Craig Mautnereda67292013-04-28 13:50:14 -07001076 if(localLOGV) Slog.v(TAG, "Enabling listeners");
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001077 mOrientationSensorEnabled = true;
1078 }
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001079 }
1080 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001081 //check if sensors need to be disabled
The Android Open Source Project0727d222009-03-11 12:11:58 -07001082 if (disable && mOrientationSensorEnabled) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001083 mOrientationListener.disable();
Craig Mautnereda67292013-04-28 13:50:14 -07001084 if(localLOGV) Slog.v(TAG, "Disabling listeners");
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001085 mOrientationSensorEnabled = false;
1086 }
1087 }
1088
Anthony Hugh96e9cc52016-07-12 15:17:24 -07001089 private void interceptBackKeyDown() {
Nimrod Gileadi580135c2016-10-31 20:42:19 +00001090 MetricsLogger.count(mContext, "key_back_down", 1);
Anthony Hugh96e9cc52016-07-12 15:17:24 -07001091 // Reset back key state for long press
1092 mBackKeyHandled = false;
1093
1094 // Cancel multi-press detection timeout.
1095 if (hasPanicPressOnBackBehavior()) {
1096 if (mBackKeyPressCounter != 0
1097 && mBackKeyPressCounter < PANIC_PRESS_BACK_COUNT) {
1098 mHandler.removeMessages(MSG_BACK_DELAYED_PRESS);
1099 }
1100 }
1101
1102 if (hasLongPressOnBackBehavior()) {
1103 Message msg = mHandler.obtainMessage(MSG_BACK_LONG_PRESS);
1104 msg.setAsynchronous(true);
1105 mHandler.sendMessageDelayed(msg,
1106 ViewConfiguration.get(mContext).getDeviceGlobalActionKeyTimeout());
1107 }
1108 }
1109
1110 // returns true if the key was handled and should not be passed to the user
1111 private boolean interceptBackKeyUp(KeyEvent event) {
1112 // Cache handled state
1113 boolean handled = mBackKeyHandled;
1114
1115 if (hasPanicPressOnBackBehavior()) {
1116 // Check for back key panic press
1117 ++mBackKeyPressCounter;
1118
1119 final long eventTime = event.getDownTime();
1120
1121 if (mBackKeyPressCounter <= PANIC_PRESS_BACK_COUNT) {
1122 // This could be a multi-press. Wait a little bit longer to confirm.
1123 Message msg = mHandler.obtainMessage(MSG_BACK_DELAYED_PRESS,
Bryce Leedb776ce2016-09-03 15:02:00 -07001124 mBackKeyPressCounter, 0, eventTime);
Anthony Hugh96e9cc52016-07-12 15:17:24 -07001125 msg.setAsynchronous(true);
1126 mHandler.sendMessageDelayed(msg, ViewConfiguration.getMultiPressTimeout());
1127 }
1128 }
1129
1130 // Reset back long press state
1131 cancelPendingBackKeyAction();
1132
Bryce Leedb776ce2016-09-03 15:02:00 -07001133 if (mHasFeatureWatch) {
1134 TelecomManager telecomManager = getTelecommService();
1135
1136 if (telecomManager != null) {
1137 if (telecomManager.isRinging()) {
1138 // Pressing back while there's a ringing incoming
1139 // call should silence the ringer.
1140 telecomManager.silenceRinger();
1141
1142 // It should not prevent navigating away
1143 return false;
1144 } else if (
1145 (mIncallBackBehavior & Settings.Secure.INCALL_BACK_BUTTON_BEHAVIOR_HANGUP) != 0
1146 && telecomManager.isInCall()) {
1147 // Otherwise, if "Back button ends call" is enabled,
1148 // the Back button will hang up any current active call.
1149 return telecomManager.endCall();
1150 }
1151 }
1152 }
1153
Anthony Hugh96e9cc52016-07-12 15:17:24 -07001154 return handled;
1155 }
1156
Jeff Brown13f00f02014-10-31 14:45:50 -07001157 private void interceptPowerKeyDown(KeyEvent event, boolean interactive) {
1158 // Hold a wake lock until the power key is released.
1159 if (!mPowerKeyWakeLock.isHeld()) {
1160 mPowerKeyWakeLock.acquire();
1161 }
1162
1163 // Cancel multi-press detection timeout.
1164 if (mPowerKeyPressCounter != 0) {
1165 mHandler.removeMessages(MSG_POWER_DELAYED_PRESS);
1166 }
1167
1168 // Detect user pressing the power button in panic when an application has
1169 // taken over the whole screen.
1170 boolean panic = mImmersiveModeConfirmation.onPowerKeyDown(interactive,
Adrian Roos7aaa5512016-07-12 15:27:24 -07001171 SystemClock.elapsedRealtime(), isImmersiveMode(mLastSystemUiFlags),
1172 isNavBarEmpty(mLastSystemUiFlags));
Jeff Brown13f00f02014-10-31 14:45:50 -07001173 if (panic) {
Adrian Roosddc8b272015-05-21 16:28:27 -07001174 mHandler.post(mHiddenNavPanic);
Jeff Brown13f00f02014-10-31 14:45:50 -07001175 }
1176
1177 // Latch power key state to detect screenshot chord.
1178 if (interactive && !mScreenshotChordPowerKeyTriggered
1179 && (event.getFlags() & KeyEvent.FLAG_FALLBACK) == 0) {
1180 mScreenshotChordPowerKeyTriggered = true;
1181 mScreenshotChordPowerKeyTime = event.getDownTime();
1182 interceptScreenshotChord();
1183 }
1184
1185 // Stop ringing or end call if configured to do so when power is pressed.
1186 TelecomManager telecomManager = getTelecommService();
1187 boolean hungUp = false;
1188 if (telecomManager != null) {
1189 if (telecomManager.isRinging()) {
1190 // Pressing Power while there's a ringing incoming
1191 // call should silence the ringer.
1192 telecomManager.silenceRinger();
1193 } else if ((mIncallPowerBehavior
1194 & Settings.Secure.INCALL_POWER_BUTTON_BEHAVIOR_HANGUP) != 0
1195 && telecomManager.isInCall() && interactive) {
1196 // Otherwise, if "Power button ends call" is enabled,
1197 // the Power button will hang up any current active call.
1198 hungUp = telecomManager.endCall();
1199 }
1200 }
1201
Adrian Roos5941c982015-09-03 15:59:49 -07001202 GestureLauncherService gestureService = LocalServices.getService(
1203 GestureLauncherService.class);
1204 boolean gesturedServiceIntercepted = false;
1205 if (gestureService != null) {
Jorim Jaggif1cdf952016-04-05 21:41:06 -07001206 gesturedServiceIntercepted = gestureService.interceptPowerKeyDown(event, interactive,
1207 mTmpBoolean);
1208 if (mTmpBoolean.value && mGoingToSleep) {
1209 mCameraGestureTriggeredDuringGoingToSleep = true;
1210 }
Adrian Roos5941c982015-09-03 15:59:49 -07001211 }
1212
Jeff Brown13f00f02014-10-31 14:45:50 -07001213 // If the power key has still not yet been handled, then detect short
1214 // press, long press, or multi press and decide what to do.
1215 mPowerKeyHandled = hungUp || mScreenshotChordVolumeDownKeyTriggered
Adrian Roos5941c982015-09-03 15:59:49 -07001216 || mScreenshotChordVolumeUpKeyTriggered || gesturedServiceIntercepted;
Jeff Brown13f00f02014-10-31 14:45:50 -07001217 if (!mPowerKeyHandled) {
1218 if (interactive) {
1219 // When interactive, we're already awake.
1220 // Wait for a long press or for the button to be released to decide what to do.
1221 if (hasLongPressOnPowerBehavior()) {
1222 Message msg = mHandler.obtainMessage(MSG_POWER_LONG_PRESS);
1223 msg.setAsynchronous(true);
1224 mHandler.sendMessageDelayed(msg,
1225 ViewConfiguration.get(mContext).getDeviceGlobalActionKeyTimeout());
1226 }
1227 } else {
Bryce Leed9268e32014-11-17 17:40:59 -08001228 wakeUpFromPowerKey(event.getDownTime());
Bryce Leed9268e32014-11-17 17:40:59 -08001229
Bryce Leed3b28402015-03-09 15:49:13 +00001230 if (mSupportLongPressPowerWhenNonInteractive && hasLongPressOnPowerBehavior()) {
1231 Message msg = mHandler.obtainMessage(MSG_POWER_LONG_PRESS);
1232 msg.setAsynchronous(true);
1233 mHandler.sendMessageDelayed(msg,
1234 ViewConfiguration.get(mContext).getDeviceGlobalActionKeyTimeout());
Bryce Leed9268e32014-11-17 17:40:59 -08001235 mBeganFromNonInteractive = true;
Bryce Leed3b28402015-03-09 15:49:13 +00001236 } else {
1237 final int maxCount = getMaxMultiPressPowerCount();
1238
1239 if (maxCount <= 1) {
1240 mPowerKeyHandled = true;
1241 } else {
1242 mBeganFromNonInteractive = true;
1243 }
Jeff Brown13f00f02014-10-31 14:45:50 -07001244 }
1245 }
Jeff Brown4d396052010-10-29 21:50:21 -07001246 }
1247 }
1248
Jeff Brown13f00f02014-10-31 14:45:50 -07001249 private void interceptPowerKeyUp(KeyEvent event, boolean interactive, boolean canceled) {
1250 final boolean handled = canceled || mPowerKeyHandled;
1251 mScreenshotChordPowerKeyTriggered = false;
1252 cancelPendingScreenshotChordAction();
1253 cancelPendingPowerKeyAction();
1254
1255 if (!handled) {
1256 // Figure out how to handle the key now that it has been released.
1257 mPowerKeyPressCounter += 1;
1258
1259 final int maxCount = getMaxMultiPressPowerCount();
1260 final long eventTime = event.getDownTime();
1261 if (mPowerKeyPressCounter < maxCount) {
1262 // This could be a multi-press. Wait a little bit longer to confirm.
1263 // Continue holding the wake lock.
1264 Message msg = mHandler.obtainMessage(MSG_POWER_DELAYED_PRESS,
1265 interactive ? 1 : 0, mPowerKeyPressCounter, eventTime);
1266 msg.setAsynchronous(true);
1267 mHandler.sendMessageDelayed(msg, ViewConfiguration.getDoubleTapTimeout());
1268 return;
1269 }
1270
1271 // No other actions. Handle it immediately.
1272 powerPress(eventTime, interactive, mPowerKeyPressCounter);
Jeff Brown4d396052010-10-29 21:50:21 -07001273 }
Jeff Brown13f00f02014-10-31 14:45:50 -07001274
1275 // Done. Reset our state.
1276 finishPowerKeyPress();
1277 }
1278
1279 private void finishPowerKeyPress() {
Bryce Leed9268e32014-11-17 17:40:59 -08001280 mBeganFromNonInteractive = false;
Jeff Brown13f00f02014-10-31 14:45:50 -07001281 mPowerKeyPressCounter = 0;
1282 if (mPowerKeyWakeLock.isHeld()) {
1283 mPowerKeyWakeLock.release();
1284 }
Jeff Brownd5bb82d2011-10-12 13:57:59 -07001285 }
1286
Anthony Hugh96e9cc52016-07-12 15:17:24 -07001287 private void finishBackKeyPress() {
1288 mBackKeyPressCounter = 0;
1289 }
1290
Jeff Brownd5bb82d2011-10-12 13:57:59 -07001291 private void cancelPendingPowerKeyAction() {
1292 if (!mPowerKeyHandled) {
Jeff Brown13f00f02014-10-31 14:45:50 -07001293 mPowerKeyHandled = true;
1294 mHandler.removeMessages(MSG_POWER_LONG_PRESS);
Jeff Brownd5bb82d2011-10-12 13:57:59 -07001295 }
Jeff Brown13f00f02014-10-31 14:45:50 -07001296 }
1297
Anthony Hugh34f09ca2016-03-04 12:03:37 -08001298 private void cancelPendingBackKeyAction() {
1299 if (!mBackKeyHandled) {
1300 mBackKeyHandled = true;
1301 mHandler.removeMessages(MSG_BACK_LONG_PRESS);
1302 }
1303 }
1304
Anthony Hugh96e9cc52016-07-12 15:17:24 -07001305 private void backMultiPressAction(long eventTime, int count) {
1306 if (count >= PANIC_PRESS_BACK_COUNT) {
1307 switch (mPanicPressOnBackBehavior) {
1308 case PANIC_PRESS_BACK_NOTHING:
1309 break;
1310 case PANIC_PRESS_BACK_HOME:
1311 launchHomeFromHotKey();
1312 break;
1313 }
1314 }
1315 }
1316
Jeff Brown13f00f02014-10-31 14:45:50 -07001317 private void powerPress(long eventTime, boolean interactive, int count) {
1318 if (mScreenOnEarly && !mScreenOnFully) {
1319 Slog.i(TAG, "Suppressed redundant power key press while "
1320 + "already in the process of turning the screen on.");
1321 return;
Jeff Brownff204712011-10-25 21:27:54 -07001322 }
Jeff Brown13f00f02014-10-31 14:45:50 -07001323
1324 if (count == 2) {
1325 powerMultiPressAction(eventTime, interactive, mDoublePressOnPowerBehavior);
1326 } else if (count == 3) {
1327 powerMultiPressAction(eventTime, interactive, mTriplePressOnPowerBehavior);
Bryce Leed9268e32014-11-17 17:40:59 -08001328 } else if (interactive && !mBeganFromNonInteractive) {
Jeff Brown13f00f02014-10-31 14:45:50 -07001329 switch (mShortPressOnPowerBehavior) {
1330 case SHORT_PRESS_POWER_NOTHING:
1331 break;
1332 case SHORT_PRESS_POWER_GO_TO_SLEEP:
1333 mPowerManager.goToSleep(eventTime,
1334 PowerManager.GO_TO_SLEEP_REASON_POWER_BUTTON, 0);
1335 break;
1336 case SHORT_PRESS_POWER_REALLY_GO_TO_SLEEP:
1337 mPowerManager.goToSleep(eventTime,
1338 PowerManager.GO_TO_SLEEP_REASON_POWER_BUTTON,
1339 PowerManager.GO_TO_SLEEP_FLAG_NO_DOZE);
1340 break;
1341 case SHORT_PRESS_POWER_REALLY_GO_TO_SLEEP_AND_GO_HOME:
1342 mPowerManager.goToSleep(eventTime,
1343 PowerManager.GO_TO_SLEEP_REASON_POWER_BUTTON,
1344 PowerManager.GO_TO_SLEEP_FLAG_NO_DOZE);
1345 launchHomeFromHotKey();
1346 break;
Bryce Lee01b0c5f2015-02-05 18:24:04 -08001347 case SHORT_PRESS_POWER_GO_HOME:
Bryce Lee662ed802015-04-10 20:11:39 +00001348 launchHomeFromHotKey(true /* awakenFromDreams */, false /*respectKeyguard*/);
Bryce Lee01b0c5f2015-02-05 18:24:04 -08001349 break;
Jeff Brown13f00f02014-10-31 14:45:50 -07001350 }
1351 }
1352 }
1353
1354 private void powerMultiPressAction(long eventTime, boolean interactive, int behavior) {
1355 switch (behavior) {
1356 case MULTI_PRESS_POWER_NOTHING:
1357 break;
1358 case MULTI_PRESS_POWER_THEATER_MODE:
Bryce Lee3ae447e2015-06-30 12:31:41 -07001359 if (!isUserSetupComplete()) {
1360 Slog.i(TAG, "Ignoring toggling theater mode - device not setup.");
1361 break;
1362 }
1363
Jeff Brown13f00f02014-10-31 14:45:50 -07001364 if (isTheaterModeEnabled()) {
1365 Slog.i(TAG, "Toggling theater mode off.");
1366 Settings.Global.putInt(mContext.getContentResolver(),
1367 Settings.Global.THEATER_MODE_ON, 0);
1368 if (!interactive) {
1369 wakeUpFromPowerKey(eventTime);
1370 }
1371 } else {
1372 Slog.i(TAG, "Toggling theater mode on.");
1373 Settings.Global.putInt(mContext.getContentResolver(),
1374 Settings.Global.THEATER_MODE_ON, 1);
Bryce Lee55e846d2014-11-04 12:43:44 -08001375
1376 if (mGoToSleepOnButtonPressTheaterMode && interactive) {
Jeff Brown13f00f02014-10-31 14:45:50 -07001377 mPowerManager.goToSleep(eventTime,
1378 PowerManager.GO_TO_SLEEP_REASON_POWER_BUTTON, 0);
1379 }
1380 }
1381 break;
1382 case MULTI_PRESS_POWER_BRIGHTNESS_BOOST:
Jeff Brown7b5be5e2014-11-12 18:45:31 -08001383 Slog.i(TAG, "Starting brightness boost.");
1384 if (!interactive) {
1385 wakeUpFromPowerKey(eventTime);
1386 }
Jeff Brown13f00f02014-10-31 14:45:50 -07001387 mPowerManager.boostScreenBrightness(eventTime);
1388 break;
1389 }
1390 }
1391
1392 private int getMaxMultiPressPowerCount() {
1393 if (mTriplePressOnPowerBehavior != MULTI_PRESS_POWER_NOTHING) {
1394 return 3;
1395 }
1396 if (mDoublePressOnPowerBehavior != MULTI_PRESS_POWER_NOTHING) {
1397 return 2;
1398 }
1399 return 1;
1400 }
1401
1402 private void powerLongPress() {
1403 final int behavior = getResolvedLongPressOnPowerBehavior();
1404 switch (behavior) {
1405 case LONG_PRESS_POWER_NOTHING:
1406 break;
1407 case LONG_PRESS_POWER_GLOBAL_ACTIONS:
1408 mPowerKeyHandled = true;
1409 if (!performHapticFeedbackLw(null, HapticFeedbackConstants.LONG_PRESS, false)) {
1410 performAuditoryFeedbackForAccessibilityIfNeed();
1411 }
1412 showGlobalActionsInternal();
1413 break;
1414 case LONG_PRESS_POWER_SHUT_OFF:
1415 case LONG_PRESS_POWER_SHUT_OFF_NO_CONFIRM:
1416 mPowerKeyHandled = true;
1417 performHapticFeedbackLw(null, HapticFeedbackConstants.LONG_PRESS, false);
1418 sendCloseSystemWindows(SYSTEM_DIALOG_REASON_GLOBAL_ACTIONS);
1419 mWindowManagerFuncs.shutdown(behavior == LONG_PRESS_POWER_SHUT_OFF);
1420 break;
1421 }
1422 }
1423
Anthony Hugh34f09ca2016-03-04 12:03:37 -08001424 private void backLongPress() {
1425 mBackKeyHandled = true;
1426
1427 switch (mLongPressOnBackBehavior) {
1428 case LONG_PRESS_BACK_NOTHING:
1429 break;
1430 case LONG_PRESS_BACK_GO_TO_VOICE_ASSIST:
Nancy Zheng0d85ee22016-09-29 09:15:56 -07001431 final boolean keyguardActive = mKeyguardDelegate == null
1432 ? false
1433 : mKeyguardDelegate.isShowing();
1434 if (!keyguardActive) {
1435 Intent intent = new Intent(Intent.ACTION_VOICE_ASSIST);
1436 startActivityAsUser(intent, UserHandle.CURRENT_OR_SELF);
1437 }
Anthony Hugh34f09ca2016-03-04 12:03:37 -08001438 break;
1439 }
1440 }
1441
Chong Zhang9f7fb092016-05-20 17:03:08 -07001442 private void disposeInputConsumer(InputConsumer inputConsumer) {
1443 if (inputConsumer != null) {
1444 inputConsumer.dismiss();
1445 }
1446 }
1447
Nick Vaccarob593a812015-05-15 11:23:05 -07001448 private void sleepPress(long eventTime) {
1449 if (mShortPressOnSleepBehavior == SHORT_PRESS_SLEEP_GO_TO_SLEEP_AND_GO_HOME) {
1450 launchHomeFromHotKey(false /* awakenDreams */, true /*respectKeyguard*/);
1451 }
1452 }
1453
1454 private void sleepRelease(long eventTime) {
Filip Gruszczynskia483a1d2015-03-17 19:06:58 +00001455 switch (mShortPressOnSleepBehavior) {
1456 case SHORT_PRESS_SLEEP_GO_TO_SLEEP:
Filip Gruszczynskia483a1d2015-03-17 19:06:58 +00001457 case SHORT_PRESS_SLEEP_GO_TO_SLEEP_AND_GO_HOME:
Nick Vaccarob593a812015-05-15 11:23:05 -07001458 Slog.i(TAG, "sleepRelease() calling goToSleep(GO_TO_SLEEP_REASON_SLEEP_BUTTON)");
1459 mPowerManager.goToSleep(eventTime,
1460 PowerManager.GO_TO_SLEEP_REASON_SLEEP_BUTTON, 0);
Filip Gruszczynskia483a1d2015-03-17 19:06:58 +00001461 break;
1462 }
1463 }
1464
Jeff Brown13f00f02014-10-31 14:45:50 -07001465 private int getResolvedLongPressOnPowerBehavior() {
1466 if (FactoryTest.isLongPressOnPowerOffEnabled()) {
1467 return LONG_PRESS_POWER_SHUT_OFF_NO_CONFIRM;
1468 }
1469 return mLongPressOnPowerBehavior;
1470 }
1471
1472 private boolean hasLongPressOnPowerBehavior() {
1473 return getResolvedLongPressOnPowerBehavior() != LONG_PRESS_POWER_NOTHING;
Jeff Brownd5bb82d2011-10-12 13:57:59 -07001474 }
1475
Anthony Hugh34f09ca2016-03-04 12:03:37 -08001476 private boolean hasLongPressOnBackBehavior() {
1477 return mLongPressOnBackBehavior != LONG_PRESS_BACK_NOTHING;
1478 }
1479
Anthony Hugh96e9cc52016-07-12 15:17:24 -07001480 private boolean hasPanicPressOnBackBehavior() {
1481 return mPanicPressOnBackBehavior != PANIC_PRESS_BACK_NOTHING;
1482 }
1483
Jeff Brownd5bb82d2011-10-12 13:57:59 -07001484 private void interceptScreenshotChord() {
Christopher Tatee90585f2012-03-05 18:56:25 -08001485 if (mScreenshotChordEnabled
Jeff Brown13f00f02014-10-31 14:45:50 -07001486 && mScreenshotChordVolumeDownKeyTriggered && mScreenshotChordPowerKeyTriggered
1487 && !mScreenshotChordVolumeUpKeyTriggered) {
Jeff Brownd5bb82d2011-10-12 13:57:59 -07001488 final long now = SystemClock.uptimeMillis();
Jeff Brown13f00f02014-10-31 14:45:50 -07001489 if (now <= mScreenshotChordVolumeDownKeyTime + SCREENSHOT_CHORD_DEBOUNCE_DELAY_MILLIS
1490 && now <= mScreenshotChordPowerKeyTime
1491 + SCREENSHOT_CHORD_DEBOUNCE_DELAY_MILLIS) {
1492 mScreenshotChordVolumeDownKeyConsumed = true;
Jeff Brownd5bb82d2011-10-12 13:57:59 -07001493 cancelPendingPowerKeyAction();
Muyuan Li6ca619f2016-03-08 13:30:42 -08001494 mScreenshotRunnable.setScreenshotType(TAKE_SCREENSHOT_FULLSCREEN);
Jeff Sharkey2991fa32012-12-05 18:06:43 -08001495 mHandler.postDelayed(mScreenshotRunnable, getScreenshotChordLongPressDelay());
Jeff Brownd5bb82d2011-10-12 13:57:59 -07001496 }
1497 }
1498 }
1499
Winson Chung1cea2f32012-10-08 20:42:01 -07001500 private long getScreenshotChordLongPressDelay() {
Jim Miller5ecd8112013-01-09 18:50:26 -08001501 if (mKeyguardDelegate.isShowing()) {
Winson Chung1cea2f32012-10-08 20:42:01 -07001502 // Double the time it takes to take a screenshot from the keyguard
1503 return (long) (KEYGUARD_SCREENSHOT_CHORD_DELAY_MULTIPLIER *
Justin Kohfeabd2c2014-05-02 10:02:44 -07001504 ViewConfiguration.get(mContext).getDeviceGlobalActionKeyTimeout());
Winson Chung1cea2f32012-10-08 20:42:01 -07001505 }
Justin Kohfeabd2c2014-05-02 10:02:44 -07001506 return ViewConfiguration.get(mContext).getDeviceGlobalActionKeyTimeout();
Winson Chung1cea2f32012-10-08 20:42:01 -07001507 }
1508
Jeff Brownd5bb82d2011-10-12 13:57:59 -07001509 private void cancelPendingScreenshotChordAction() {
Jeff Sharkey2991fa32012-12-05 18:06:43 -08001510 mHandler.removeCallbacks(mScreenshotRunnable);
Jeff Brown4d396052010-10-29 21:50:21 -07001511 }
1512
Jeff Brown13f00f02014-10-31 14:45:50 -07001513 private final Runnable mEndCallLongPress = new Runnable() {
Craig Mautnerf1b67412012-09-19 13:18:29 -07001514 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001515 public void run() {
Jeff Brown13f00f02014-10-31 14:45:50 -07001516 mEndCallKeyHandled = true;
1517 if (!performHapticFeedbackLw(null, HapticFeedbackConstants.LONG_PRESS, false)) {
1518 performAuditoryFeedbackForAccessibilityIfNeed();
Joe Onoratod208e702010-10-08 16:22:43 -04001519 }
Jeff Brown13f00f02014-10-31 14:45:50 -07001520 showGlobalActionsInternal();
Jeff Brownd5bb82d2011-10-12 13:57:59 -07001521 }
1522 };
1523
Muyuan Li6ca619f2016-03-08 13:30:42 -08001524 private class ScreenshotRunnable implements Runnable {
1525 private int mScreenshotType = TAKE_SCREENSHOT_FULLSCREEN;
1526
1527 public void setScreenshotType(int screenshotType) {
1528 mScreenshotType = screenshotType;
1529 }
1530
Craig Mautner0bf6ec92012-12-18 08:33:27 -08001531 @Override
Jeff Brownd5bb82d2011-10-12 13:57:59 -07001532 public void run() {
Muyuan Li6ca619f2016-03-08 13:30:42 -08001533 takeScreenshot(mScreenshotType);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001534 }
Muyuan Li6ca619f2016-03-08 13:30:42 -08001535 }
1536
1537 private final ScreenshotRunnable mScreenshotRunnable = new ScreenshotRunnable();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001538
Alan Viverettee34560b22014-07-10 14:50:06 -07001539 @Override
1540 public void showGlobalActions() {
1541 mHandler.removeMessages(MSG_DISPATCH_SHOW_GLOBAL_ACTIONS);
1542 mHandler.sendEmptyMessage(MSG_DISPATCH_SHOW_GLOBAL_ACTIONS);
1543 }
1544
1545 void showGlobalActionsInternal() {
1546 sendCloseSystemWindows(SYSTEM_DIALOG_REASON_GLOBAL_ACTIONS);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001547 if (mGlobalActions == null) {
Jeff Brown7304c342012-05-11 18:42:42 -07001548 mGlobalActions = new GlobalActions(mContext, mWindowManagerFuncs);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001549 }
Jim Millerab954542014-10-10 18:21:49 -07001550 final boolean keyguardShowing = isKeyguardShowingAndNotOccluded();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001551 mGlobalActions.showDialog(keyguardShowing, isDeviceProvisioned());
1552 if (keyguardShowing) {
1553 // since it took two seconds of long press to bring this up,
1554 // poke the wake lock so they have some time to see the dialog.
Jim Miller25190572013-02-28 17:36:24 -08001555 mPowerManager.userActivity(SystemClock.uptimeMillis(), false);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001556 }
1557 }
1558
1559 boolean isDeviceProvisioned() {
Jeff Brownbf6f6f92012-09-25 15:03:20 -07001560 return Settings.Global.getInt(
1561 mContext.getContentResolver(), Settings.Global.DEVICE_PROVISIONED, 0) != 0;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001562 }
1563
Maurice Lam99c6e072014-04-28 18:24:28 -07001564 boolean isUserSetupComplete() {
1565 return Settings.Secure.getIntForUser(mContext.getContentResolver(),
1566 Settings.Secure.USER_SETUP_COMPLETE, 0, UserHandle.USER_CURRENT) != 0;
1567 }
1568
Jeff Brown13f00f02014-10-31 14:45:50 -07001569 private void handleShortPressOnHome() {
Jinsuk Kime601b712015-07-07 08:01:02 +09001570 // Turn on the connected TV and switch HDMI input if we're a HDMI playback device.
Andrii Kulianeb4a7942016-12-21 12:18:05 -08001571 final HdmiControl hdmiControl = getHdmiControl();
1572 if (hdmiControl != null) {
1573 hdmiControl.turnOnTv();
1574 }
Jinsuk Kime601b712015-07-07 08:01:02 +09001575
Jeff Brown13f00f02014-10-31 14:45:50 -07001576 // If there's a dream running then use home to escape the dream
1577 // but don't actually go home.
1578 if (mDreamManagerInternal != null && mDreamManagerInternal.isDreaming()) {
1579 mDreamManagerInternal.stopDream(false /*immediate*/);
1580 return;
1581 }
1582
1583 // Go home!
1584 launchHomeFromHotKey();
1585 }
1586
Jinsuk Kime601b712015-07-07 08:01:02 +09001587 /**
1588 * Creates an accessor to HDMI control service that performs the operation of
1589 * turning on TV (optional) and switching input to us. If HDMI control service
1590 * is not available or we're not a HDMI playback device, the operation is no-op.
Andrii Kulianeb4a7942016-12-21 12:18:05 -08001591 * @return {@link HdmiControl} instance if available, null otherwise.
Jinsuk Kime601b712015-07-07 08:01:02 +09001592 */
1593 private HdmiControl getHdmiControl() {
1594 if (null == mHdmiControl) {
Andrii Kulianeb4a7942016-12-21 12:18:05 -08001595 if (!mContext.getPackageManager().hasSystemFeature(PackageManager.FEATURE_HDMI_CEC)) {
1596 return null;
1597 }
Jinsuk Kime601b712015-07-07 08:01:02 +09001598 HdmiControlManager manager = (HdmiControlManager) mContext.getSystemService(
1599 Context.HDMI_CONTROL_SERVICE);
1600 HdmiPlaybackClient client = null;
1601 if (manager != null) {
1602 client = manager.getPlaybackClient();
1603 }
1604 mHdmiControl = new HdmiControl(client);
1605 }
1606 return mHdmiControl;
1607 }
1608
1609 private static class HdmiControl {
1610 private final HdmiPlaybackClient mClient;
1611
1612 private HdmiControl(HdmiPlaybackClient client) {
1613 mClient = client;
1614 }
1615
1616 public void turnOnTv() {
1617 if (mClient == null) {
1618 return;
1619 }
1620 mClient.oneTouchPlay(new OneTouchPlayCallback() {
1621 @Override
1622 public void onComplete(int result) {
1623 if (result != HdmiControlManager.RESULT_SUCCESS) {
1624 Log.w(TAG, "One touch play failed: " + result);
1625 }
1626 }
1627 });
1628 }
1629 }
1630
Jaewan Kim76b7d0d2016-02-12 19:01:02 +09001631 private void handleLongPressOnHome(int deviceId) {
Jaewan Kim52632e22016-01-14 18:01:52 +09001632 if (mLongPressOnHomeBehavior == LONG_PRESS_HOME_NOTHING) {
1633 return;
1634 }
1635 mHomeConsumed = true;
1636 performHapticFeedbackLw(null, HapticFeedbackConstants.LONG_PRESS, false);
Patrick Dubroyece94522011-02-23 18:35:01 -08001637
Jaewan Kim52632e22016-01-14 18:01:52 +09001638 switch (mLongPressOnHomeBehavior) {
1639 case LONG_PRESS_HOME_RECENT_SYSTEM_UI:
Jeff Browncaca8812013-05-09 13:34:33 -07001640 toggleRecentApps();
Jaewan Kim52632e22016-01-14 18:01:52 +09001641 break;
1642 case LONG_PRESS_HOME_ASSIST:
Tim Kilbourn0e5f1102015-06-05 16:18:09 -07001643 launchAssistAction(null, deviceId);
Jaewan Kim52632e22016-01-14 18:01:52 +09001644 break;
Jaewan Kim52632e22016-01-14 18:01:52 +09001645 default:
Jaewan Kim76b7d0d2016-02-12 19:01:02 +09001646 Log.w(TAG, "Undefined home long press behavior: " + mLongPressOnHomeBehavior);
Jaewan Kim52632e22016-01-14 18:01:52 +09001647 break;
Jim Millere6ad1a82010-08-20 19:25:39 -07001648 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001649 }
Patrick Dubroyece94522011-02-23 18:35:01 -08001650
Jeff Browncaca8812013-05-09 13:34:33 -07001651 private void handleDoubleTapOnHome() {
1652 if (mDoubleTapOnHomeBehavior == DOUBLE_TAP_HOME_RECENT_SYSTEM_UI) {
1653 mHomeConsumed = true;
1654 toggleRecentApps();
1655 }
1656 }
1657
Jaewan Kimf0fd2182016-04-20 21:17:58 +09001658 private void showTvPictureInPictureMenu(KeyEvent event) {
1659 if (DEBUG_INPUT) Log.d(TAG, "showTvPictureInPictureMenu event=" + event);
1660 mHandler.removeMessages(MSG_SHOW_TV_PICTURE_IN_PICTURE_MENU);
1661 Message msg = mHandler.obtainMessage(MSG_SHOW_TV_PICTURE_IN_PICTURE_MENU);
Jaewan Kimc552b042016-01-18 16:08:45 +09001662 msg.setAsynchronous(true);
1663 msg.sendToTarget();
1664 }
1665
Jaewan Kimf0fd2182016-04-20 21:17:58 +09001666 private void showTvPictureInPictureMenuInternal() {
1667 StatusBarManagerInternal statusbar = getStatusBarManagerInternal();
1668 if (statusbar != null) {
1669 statusbar.showTvPictureInPictureMenu();
Jaewan Kimc552b042016-01-18 16:08:45 +09001670 }
Jaewan Kim52632e22016-01-14 18:01:52 +09001671 }
1672
Jeff Browncaca8812013-05-09 13:34:33 -07001673 private final Runnable mHomeDoubleTapTimeoutRunnable = new Runnable() {
1674 @Override
1675 public void run() {
1676 if (mHomeDoubleTapPending) {
1677 mHomeDoubleTapPending = false;
Jeff Brown13f00f02014-10-31 14:45:50 -07001678 handleShortPressOnHome();
Jeff Browncaca8812013-05-09 13:34:33 -07001679 }
1680 }
1681 };
1682
Mark Renoufc1256912015-03-11 14:38:23 -04001683 private boolean isRoundWindow() {
Adam Powell01f280d2015-05-18 16:07:42 -07001684 return mContext.getResources().getConfiguration().isScreenRound();
Mark Renoufc1256912015-03-11 14:38:23 -04001685 }
1686
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001687 /** {@inheritDoc} */
Craig Mautner0bf6ec92012-12-18 08:33:27 -08001688 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001689 public void init(Context context, IWindowManager windowManager,
Jeff Brown96307042012-07-27 15:51:34 -07001690 WindowManagerFuncs windowManagerFuncs) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001691 mContext = context;
1692 mWindowManager = windowManager;
Dianne Hackborndf89e652011-10-06 22:35:11 -07001693 mWindowManagerFuncs = windowManagerFuncs;
Craig Mautner8a0da012014-05-31 15:13:37 -07001694 mWindowManagerInternal = LocalServices.getService(WindowManagerInternal.class);
Jeff Brown061ea992015-04-17 19:55:47 -07001695 mActivityManagerInternal = LocalServices.getService(ActivityManagerInternal.class);
Andrii Kulian112d0562016-03-08 10:44:22 -08001696 mInputManagerInternal = LocalServices.getService(InputManagerInternal.class);
Jose Lima9546b202014-07-02 17:21:51 -07001697 mDreamManagerInternal = LocalServices.getService(DreamManagerInternal.class);
Michael Wrighta4d22d72015-09-16 23:19:26 +01001698 mPowerManagerInternal = LocalServices.getService(PowerManagerInternal.class);
Billy Laucbe540f2015-06-25 01:51:44 +01001699 mAppOpsManager = (AppOpsManager) mContext.getSystemService(Context.APP_OPS_SERVICE);
Wale Ogunwale6b15ea52016-04-04 07:28:27 -07001700 mHasFeatureWatch = mContext.getPackageManager().hasSystemFeature(FEATURE_WATCH);
Mark Renoufc1256912015-03-11 14:38:23 -04001701
1702 // Init display burn-in protection
1703 boolean burnInProtectionEnabled = context.getResources().getBoolean(
1704 com.android.internal.R.bool.config_enableBurnInProtection);
1705 // Allow a system property to override this. Used by developer settings.
1706 boolean burnInProtectionDevMode =
1707 SystemProperties.getBoolean("persist.debug.force_burn_in", false);
1708 if (burnInProtectionEnabled || burnInProtectionDevMode) {
1709 final int minHorizontal;
1710 final int maxHorizontal;
1711 final int minVertical;
1712 final int maxVertical;
1713 final int maxRadius;
1714 if (burnInProtectionDevMode) {
1715 minHorizontal = -8;
1716 maxHorizontal = 8;
1717 minVertical = -8;
1718 maxVertical = -4;
1719 maxRadius = (isRoundWindow()) ? 6 : -1;
1720 } else {
1721 Resources resources = context.getResources();
1722 minHorizontal = resources.getInteger(
1723 com.android.internal.R.integer.config_burnInProtectionMinHorizontalOffset);
1724 maxHorizontal = resources.getInteger(
1725 com.android.internal.R.integer.config_burnInProtectionMaxHorizontalOffset);
1726 minVertical = resources.getInteger(
1727 com.android.internal.R.integer.config_burnInProtectionMinVerticalOffset);
1728 maxVertical = resources.getInteger(
1729 com.android.internal.R.integer.config_burnInProtectionMaxVerticalOffset);
1730 maxRadius = resources.getInteger(
1731 com.android.internal.R.integer.config_burnInProtectionMaxRadius);
1732 }
1733 mBurnInProtectionHelper = new BurnInProtectionHelper(
1734 context, minHorizontal, maxHorizontal, minVertical, maxVertical, maxRadius);
Filip Gruszczynskicfb31852015-02-25 21:47:12 +00001735 }
Craig Mautner8a0da012014-05-31 15:13:37 -07001736
Jeff Brown70825162012-03-28 17:27:48 -07001737 mHandler = new PolicyHandler();
Jeff Browna20dda42014-05-27 20:57:24 -07001738 mWakeGestureListener = new MyWakeGestureListener(mContext, mHandler);
Craig Mautnereee29c42013-01-17 14:44:34 -08001739 mOrientationListener = new MyOrientationListener(mContext, mHandler);
Jeff Brownc0347aa2011-09-23 17:26:09 -07001740 try {
1741 mOrientationListener.setCurrentRotation(windowManager.getRotation());
1742 } catch (RemoteException ex) { }
Christopher Tate5e08af02012-09-21 17:17:22 -07001743 mSettingsObserver = new SettingsObserver(mHandler);
1744 mSettingsObserver.observe();
Svetoslav683914b2015-01-15 14:22:26 -08001745 mShortcutManager = new ShortcutManager(context);
Daniel Sandler6396c722013-04-16 20:19:09 -04001746 mUiMode = context.getResources().getInteger(
1747 com.android.internal.R.integer.config_defaultUiModeType);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001748 mHomeIntent = new Intent(Intent.ACTION_MAIN, null);
1749 mHomeIntent.addCategory(Intent.CATEGORY_HOME);
1750 mHomeIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK
1751 | Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED);
keunyounga7710492015-09-23 11:33:58 -07001752 mEnableCarDockHomeCapture = context.getResources().getBoolean(
1753 com.android.internal.R.bool.config_enableCarDockHomeLaunch);
Dianne Hackborn39c2d712009-09-22 11:41:31 -07001754 mCarDockIntent = new Intent(Intent.ACTION_MAIN, null);
1755 mCarDockIntent.addCategory(Intent.CATEGORY_CAR_DOCK);
1756 mCarDockIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK
1757 | Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED);
1758 mDeskDockIntent = new Intent(Intent.ACTION_MAIN, null);
1759 mDeskDockIntent.addCategory(Intent.CATEGORY_DESK_DOCK);
1760 mDeskDockIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK
1761 | Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED);
Jim Millere6ad1a82010-08-20 19:25:39 -07001762
Jeff Brown96307042012-07-27 15:51:34 -07001763 mPowerManager = (PowerManager)context.getSystemService(Context.POWER_SERVICE);
1764 mBroadcastWakeLock = mPowerManager.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK,
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001765 "PhoneWindowManager.mBroadcastWakeLock");
Jeff Brown13f00f02014-10-31 14:45:50 -07001766 mPowerKeyWakeLock = mPowerManager.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK,
1767 "PhoneWindowManager.mPowerKeyWakeLock");
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001768 mEnableShiftMenuBugReports = "1".equals(SystemProperties.get("ro.debuggable"));
Jeff Brownbcdfc622014-03-06 19:13:04 -08001769 mSupportAutoRotation = mContext.getResources().getBoolean(
1770 com.android.internal.R.bool.config_supportAutoRotation);
Dianne Hackborn2862fff2009-09-15 22:56:29 -07001771 mLidOpenRotation = readRotation(
Mike Lockwood2d1efbd2009-09-16 12:15:53 -04001772 com.android.internal.R.integer.config_lidOpenRotation);
1773 mCarDockRotation = readRotation(
1774 com.android.internal.R.integer.config_carDockRotation);
1775 mDeskDockRotation = readRotation(
1776 com.android.internal.R.integer.config_deskDockRotation);
Jeff Brownc82c89ed2013-04-17 17:18:15 -07001777 mUndockedHdmiRotation = readRotation(
1778 com.android.internal.R.integer.config_undockedHdmiRotation);
Mike Lockwoode9867d22009-09-20 01:59:02 -04001779 mCarDockEnablesAccelerometer = mContext.getResources().getBoolean(
1780 com.android.internal.R.bool.config_carDockEnablesAccelerometer);
1781 mDeskDockEnablesAccelerometer = mContext.getResources().getBoolean(
1782 com.android.internal.R.bool.config_deskDockEnablesAccelerometer);
Dianne Hackborn2862fff2009-09-15 22:56:29 -07001783 mLidKeyboardAccessibility = mContext.getResources().getInteger(
1784 com.android.internal.R.integer.config_lidKeyboardAccessibility);
1785 mLidNavigationAccessibility = mContext.getResources().getInteger(
1786 com.android.internal.R.integer.config_lidNavigationAccessibility);
Edward Savage-Jones7def60d2015-11-13 13:27:03 +01001787 mLidControlsScreenLock = mContext.getResources().getBoolean(
1788 com.android.internal.R.bool.config_lidControlsScreenLock);
Jeff Brownc458ce92012-04-30 14:58:40 -07001789 mLidControlsSleep = mContext.getResources().getBoolean(
1790 com.android.internal.R.bool.config_lidControlsSleep);
Daniel Sandlerdd73ee42013-10-11 22:19:59 -04001791 mTranslucentDecorEnabled = mContext.getResources().getBoolean(
1792 com.android.internal.R.bool.config_enableTranslucentDecor);
Bryce Lee584a4452014-10-21 15:55:55 -07001793
1794 mAllowTheaterModeWakeFromKey = mContext.getResources().getBoolean(
1795 com.android.internal.R.bool.config_allowTheaterModeWakeFromKey);
1796 mAllowTheaterModeWakeFromPowerKey = mAllowTheaterModeWakeFromKey
1797 || mContext.getResources().getBoolean(
1798 com.android.internal.R.bool.config_allowTheaterModeWakeFromPowerKey);
1799 mAllowTheaterModeWakeFromMotion = mContext.getResources().getBoolean(
1800 com.android.internal.R.bool.config_allowTheaterModeWakeFromMotion);
Bryce Lee812d7022014-11-10 13:33:28 -08001801 mAllowTheaterModeWakeFromMotionWhenNotDreaming = mContext.getResources().getBoolean(
1802 com.android.internal.R.bool.config_allowTheaterModeWakeFromMotionWhenNotDreaming);
Bryce Lee584a4452014-10-21 15:55:55 -07001803 mAllowTheaterModeWakeFromCameraLens = mContext.getResources().getBoolean(
1804 com.android.internal.R.bool.config_allowTheaterModeWakeFromCameraLens);
1805 mAllowTheaterModeWakeFromLidSwitch = mContext.getResources().getBoolean(
1806 com.android.internal.R.bool.config_allowTheaterModeWakeFromLidSwitch);
1807 mAllowTheaterModeWakeFromWakeGesture = mContext.getResources().getBoolean(
1808 com.android.internal.R.bool.config_allowTheaterModeWakeFromGesture);
1809
Bryce Lee55e846d2014-11-04 12:43:44 -08001810 mGoToSleepOnButtonPressTheaterMode = mContext.getResources().getBoolean(
1811 com.android.internal.R.bool.config_goToSleepOnButtonPressTheaterMode);
1812
Bryce Leed3b28402015-03-09 15:49:13 +00001813 mSupportLongPressPowerWhenNonInteractive = mContext.getResources().getBoolean(
1814 com.android.internal.R.bool.config_supportLongPressPowerWhenNonInteractive);
1815
Anthony Hugh34f09ca2016-03-04 12:03:37 -08001816 mLongPressOnBackBehavior = mContext.getResources().getInteger(
1817 com.android.internal.R.integer.config_longPressOnBackBehavior);
Anthony Hugh96e9cc52016-07-12 15:17:24 -07001818 mPanicPressOnBackBehavior = mContext.getResources().getInteger(
1819 com.android.internal.R.integer.config_backPanicBehavior);
Anthony Hugh34f09ca2016-03-04 12:03:37 -08001820
Jeff Brown13f00f02014-10-31 14:45:50 -07001821 mShortPressOnPowerBehavior = mContext.getResources().getInteger(
1822 com.android.internal.R.integer.config_shortPressOnPowerBehavior);
1823 mLongPressOnPowerBehavior = mContext.getResources().getInteger(
1824 com.android.internal.R.integer.config_longPressOnPowerBehavior);
1825 mDoublePressOnPowerBehavior = mContext.getResources().getInteger(
1826 com.android.internal.R.integer.config_doublePressOnPowerBehavior);
1827 mTriplePressOnPowerBehavior = mContext.getResources().getInteger(
1828 com.android.internal.R.integer.config_triplePressOnPowerBehavior);
Filip Gruszczynskia483a1d2015-03-17 19:06:58 +00001829 mShortPressOnSleepBehavior = mContext.getResources().getInteger(
1830 com.android.internal.R.integer.config_shortPressOnSleepBehavior);
Jeff Brown13f00f02014-10-31 14:45:50 -07001831
John Spurlock61560172015-02-06 19:46:04 -05001832 mUseTvRouting = AudioSystem.getPlatformType(mContext) == AudioSystem.PLATFORM_TELEVISION;
RoboErik001c59c2015-01-26 15:53:51 -08001833
Jeff Brownf71343d2013-05-31 17:59:11 -07001834 readConfigurationDependentBehaviors();
Jeff Browncaca8812013-05-09 13:34:33 -07001835
Svetoslav8e3feb12014-02-24 13:46:47 -08001836 mAccessibilityManager = (AccessibilityManager) context.getSystemService(
1837 Context.ACCESSIBILITY_SERVICE);
1838
Mike Lockwood1753f7f2009-08-24 14:49:07 -07001839 // register for dock events
Dianne Hackborn78968392010-03-04 20:47:56 -08001840 IntentFilter filter = new IntentFilter();
1841 filter.addAction(UiModeManager.ACTION_ENTER_CAR_MODE);
1842 filter.addAction(UiModeManager.ACTION_EXIT_CAR_MODE);
1843 filter.addAction(UiModeManager.ACTION_ENTER_DESK_MODE);
1844 filter.addAction(UiModeManager.ACTION_EXIT_DESK_MODE);
Dianne Hackborn867ab6472010-04-29 13:28:56 -07001845 filter.addAction(Intent.ACTION_DOCK_EVENT);
1846 Intent intent = context.registerReceiver(mDockReceiver, filter);
1847 if (intent != null) {
1848 // Retrieve current sticky dock event broadcast.
1849 mDockMode = intent.getIntExtra(Intent.EXTRA_DOCK_STATE,
1850 Intent.EXTRA_DOCK_STATE_UNDOCKED);
1851 }
Daniel Sandler7e37df52011-11-16 22:08:23 -08001852
Jeff Brown6aaf2952012-10-05 16:01:08 -07001853 // register for dream-related broadcasts
1854 filter = new IntentFilter();
1855 filter.addAction(Intent.ACTION_DREAMING_STARTED);
1856 filter.addAction(Intent.ACTION_DREAMING_STOPPED);
1857 context.registerReceiver(mDreamReceiver, filter);
1858
Christopher Tate5e08af02012-09-21 17:17:22 -07001859 // register for multiuser-relevant broadcasts
1860 filter = new IntentFilter(Intent.ACTION_USER_SWITCHED);
1861 context.registerReceiver(mMultiuserReceiver, filter);
1862
John Spurlock57306e62013-04-22 09:48:49 -04001863 // monitor for system gestures
Craig Mautner037aa8d2013-06-07 10:35:44 -07001864 mSystemGestures = new SystemGesturesPointerEventListener(context,
1865 new SystemGesturesPointerEventListener.Callbacks() {
John Spurlock57306e62013-04-22 09:48:49 -04001866 @Override
1867 public void onSwipeFromTop() {
John Spurlock04db1762013-05-13 12:46:41 -04001868 if (mStatusBar != null) {
John Spurlocke1f366f2013-08-05 12:22:40 -04001869 requestTransientBars(mStatusBar);
John Spurlock04db1762013-05-13 12:46:41 -04001870 }
John Spurlockad3e6cb2013-04-30 08:47:43 -04001871 }
1872 @Override
1873 public void onSwipeFromBottom() {
Adrian Roos85d202b2016-06-02 16:27:47 -07001874 if (mNavigationBar != null && mNavigationBarPosition == NAV_BAR_BOTTOM) {
John Spurlocke1f366f2013-08-05 12:22:40 -04001875 requestTransientBars(mNavigationBar);
John Spurlockad3e6cb2013-04-30 08:47:43 -04001876 }
1877 }
1878 @Override
1879 public void onSwipeFromRight() {
Adrian Roos85d202b2016-06-02 16:27:47 -07001880 if (mNavigationBar != null && mNavigationBarPosition == NAV_BAR_RIGHT) {
1881 requestTransientBars(mNavigationBar);
1882 }
1883 }
1884 @Override
1885 public void onSwipeFromLeft() {
1886 if (mNavigationBar != null && mNavigationBarPosition == NAV_BAR_LEFT) {
John Spurlocke1f366f2013-08-05 12:22:40 -04001887 requestTransientBars(mNavigationBar);
John Spurlockad3e6cb2013-04-30 08:47:43 -04001888 }
1889 }
1890 @Override
Michael Wrighta4d22d72015-09-16 23:19:26 +01001891 public void onFling(int duration) {
1892 if (mPowerManagerInternal != null) {
1893 mPowerManagerInternal.powerHint(
Ruchi Kandoi0d434042016-10-03 09:12:02 -07001894 PowerHint.INTERACTION, duration);
Michael Wrighta4d22d72015-09-16 23:19:26 +01001895 }
1896 }
1897 @Override
John Spurlockad3e6cb2013-04-30 08:47:43 -04001898 public void onDebug() {
John Spurlockd67ec252013-09-05 11:31:54 -04001899 // no-op
John Spurlockad3e6cb2013-04-30 08:47:43 -04001900 }
Adrian Roos3595be42015-03-05 16:31:15 +01001901 @Override
1902 public void onDown() {
1903 mOrientationListener.onTouchStart();
1904 }
1905 @Override
1906 public void onUpOrCancel() {
1907 mOrientationListener.onTouchEnd();
1908 }
Jun Mukaid2e7e352015-07-22 17:14:02 -07001909 @Override
1910 public void onMouseHoverAtTop() {
1911 mHandler.removeMessages(MSG_REQUEST_TRANSIENT_BARS);
1912 Message msg = mHandler.obtainMessage(MSG_REQUEST_TRANSIENT_BARS);
1913 msg.arg1 = MSG_REQUEST_TRANSIENT_BARS_ARG_STATUS;
1914 mHandler.sendMessageDelayed(msg, 500);
1915 }
1916 @Override
1917 public void onMouseHoverAtBottom() {
1918 mHandler.removeMessages(MSG_REQUEST_TRANSIENT_BARS);
1919 Message msg = mHandler.obtainMessage(MSG_REQUEST_TRANSIENT_BARS);
1920 msg.arg1 = MSG_REQUEST_TRANSIENT_BARS_ARG_NAVIGATION;
1921 mHandler.sendMessageDelayed(msg, 500);
1922 }
1923 @Override
1924 public void onMouseLeaveFromEdge() {
1925 mHandler.removeMessages(MSG_REQUEST_TRANSIENT_BARS);
1926 }
John Spurlockad3e6cb2013-04-30 08:47:43 -04001927 });
John Spurlockf1a36642013-10-12 17:50:42 -04001928 mImmersiveModeConfirmation = new ImmersiveModeConfirmation(mContext);
Craig Mautner037aa8d2013-06-07 10:35:44 -07001929 mWindowManagerFuncs.registerPointerEventListener(mSystemGestures);
John Spurlock32beb2c2013-03-11 10:16:47 -04001930
Jeff Brownc2346132012-04-13 01:55:38 -07001931 mVibrator = (Vibrator)context.getSystemService(Context.VIBRATOR_SERVICE);
Dianne Hackbornb1a79802009-09-29 15:18:31 -07001932 mLongPressVibePattern = getLongIntArray(mContext.getResources(),
1933 com.android.internal.R.array.config_longPressVibePattern);
1934 mVirtualKeyVibePattern = getLongIntArray(mContext.getResources(),
1935 com.android.internal.R.array.config_virtualKeyVibePattern);
Amith Yamasanic33cb712010-02-10 15:21:49 -08001936 mKeyboardTapVibePattern = getLongIntArray(mContext.getResources(),
1937 com.android.internal.R.array.config_keyboardTapVibePattern);
Fabrice Di Meglioeeff63a2013-08-05 12:07:24 -07001938 mClockTickVibePattern = getLongIntArray(mContext.getResources(),
1939 com.android.internal.R.array.config_clockTickVibePattern);
Fabrice Di Megliobd9152f2013-10-01 11:21:31 -07001940 mCalendarDateVibePattern = getLongIntArray(mContext.getResources(),
1941 com.android.internal.R.array.config_calendarDateVibePattern);
Dianne Hackbornb1a79802009-09-29 15:18:31 -07001942 mSafeModeDisabledVibePattern = getLongIntArray(mContext.getResources(),
1943 com.android.internal.R.array.config_safeModeDisabledVibePattern);
1944 mSafeModeEnabledVibePattern = getLongIntArray(mContext.getResources(),
1945 com.android.internal.R.array.config_safeModeEnabledVibePattern);
Mady Mellore8608912015-06-05 09:02:55 -07001946 mContextClickVibePattern = getLongIntArray(mContext.getResources(),
1947 com.android.internal.R.array.config_contextClickVibePattern);
Daniel Sandler40427442010-07-16 11:44:52 -04001948
Christopher Tatee90585f2012-03-05 18:56:25 -08001949 mScreenshotChordEnabled = mContext.getResources().getBoolean(
1950 com.android.internal.R.bool.config_enableScreenshotChord);
1951
Justin Kohd378ad72013-04-01 12:18:26 -07001952 mGlobalKeyManager = new GlobalKeyManager(mContext);
1953
Joe Onoratoea495d42011-04-06 11:41:11 -07001954 // Controls rotation and the like.
1955 initializeHdmiState();
Dianne Hackborn40011092011-09-22 13:37:48 -07001956
1957 // Match current screen state.
Craig Mautnera631d492014-08-05 15:16:01 -07001958 if (!mPowerManager.isInteractive()) {
Jeff Brown416c49c2015-05-26 19:50:18 -07001959 startedGoingToSleep(WindowManagerPolicy.OFF_BECAUSE_OF_USER);
1960 finishedGoingToSleep(WindowManagerPolicy.OFF_BECAUSE_OF_USER);
Dianne Hackborn40011092011-09-22 13:37:48 -07001961 }
Jorim Jaggi24bec7c2015-02-04 12:40:14 +01001962
1963 mWindowManagerInternal.registerAppTransitionListener(
1964 mStatusBarController.getAppTransitionListener());
Jorim Jaggife762342016-10-13 14:33:27 +02001965 mWindowManagerInternal.registerAppTransitionListener(new AppTransitionListener() {
1966 @Override
1967 public int onAppTransitionStartingLocked(int transit, IBinder openToken,
1968 IBinder closeToken,
1969 Animation openAnimation, Animation closeAnimation) {
1970 return handleStartTransitionForKeyguardLw(transit, openAnimation);
1971 }
1972
1973 @Override
1974 public void onAppTransitionCancelledLocked(int transit) {
1975 handleStartTransitionForKeyguardLw(transit, null /* transit */);
1976 }
1977 });
Mike Lockwood1753f7f2009-08-24 14:49:07 -07001978 }
1979
Jeff Brownf71343d2013-05-31 17:59:11 -07001980 /**
1981 * Read values from config.xml that may be overridden depending on
1982 * the configuration of the device.
1983 * eg. Disable long press on home goes to recents on sw600dp.
1984 */
1985 private void readConfigurationDependentBehaviors() {
Jaewan Kimc552b042016-01-18 16:08:45 +09001986 final Resources res = mContext.getResources();
1987
1988 mLongPressOnHomeBehavior = res.getInteger(
Jeff Brownf71343d2013-05-31 17:59:11 -07001989 com.android.internal.R.integer.config_longPressOnHomeBehavior);
1990 if (mLongPressOnHomeBehavior < LONG_PRESS_HOME_NOTHING ||
Jaewan Kim52632e22016-01-14 18:01:52 +09001991 mLongPressOnHomeBehavior > LAST_LONG_PRESS_HOME_BEHAVIOR) {
Jeff Brownf71343d2013-05-31 17:59:11 -07001992 mLongPressOnHomeBehavior = LONG_PRESS_HOME_NOTHING;
1993 }
1994
Jaewan Kimc552b042016-01-18 16:08:45 +09001995 mDoubleTapOnHomeBehavior = res.getInteger(
Jeff Brownf71343d2013-05-31 17:59:11 -07001996 com.android.internal.R.integer.config_doubleTapOnHomeBehavior);
1997 if (mDoubleTapOnHomeBehavior < DOUBLE_TAP_HOME_NOTHING ||
1998 mDoubleTapOnHomeBehavior > DOUBLE_TAP_HOME_RECENT_SYSTEM_UI) {
1999 mDoubleTapOnHomeBehavior = LONG_PRESS_HOME_NOTHING;
2000 }
Jaewan Kim49117872016-01-19 17:24:08 +09002001
2002 mShortPressWindowBehavior = SHORT_PRESS_WINDOW_NOTHING;
2003 if (mContext.getPackageManager().hasSystemFeature(FEATURE_PICTURE_IN_PICTURE)) {
2004 mShortPressWindowBehavior = SHORT_PRESS_WINDOW_PICTURE_IN_PICTURE;
2005 }
Yorke Lee2e4b7322016-03-02 17:33:06 -08002006
Yorke Lee9b2ffb32016-03-07 20:42:01 -08002007 mNavBarOpacityMode = res.getInteger(
2008 com.android.internal.R.integer.config_navBarOpacityMode);
Jeff Brownf71343d2013-05-31 17:59:11 -07002009 }
2010
Craig Mautner0bf6ec92012-12-18 08:33:27 -08002011 @Override
Dianne Hackborndde331c2012-08-03 14:01:57 -07002012 public void setInitialDisplaySize(Display display, int width, int height, int density) {
Jeff Brownef981a42013-08-07 14:13:37 -07002013 // This method might be called before the policy has been fully initialized
2014 // or for other displays we don't care about.
Andrii Kulian3a507b52016-09-19 18:14:12 -07002015 // TODO(multi-display): Define policy for secondary displays.
Jeff Brownef981a42013-08-07 14:13:37 -07002016 if (mContext == null || display.getDisplayId() != Display.DEFAULT_DISPLAY) {
2017 return;
Dianne Hackbornc652de82013-02-15 16:32:56 -08002018 }
Dianne Hackbornf87d1962012-04-04 12:48:24 -07002019 mDisplay = display;
2020
Craig Mautner46ac6fa2013-08-01 10:06:34 -07002021 final Resources res = mContext.getResources();
Dianne Hackbornf87d1962012-04-04 12:48:24 -07002022 int shortSize, longSize;
Dianne Hackborn9d132642011-04-21 17:26:39 -07002023 if (width > height) {
Dianne Hackborn81e56d52011-05-26 00:55:58 -07002024 shortSize = height;
Dianne Hackbornf87d1962012-04-04 12:48:24 -07002025 longSize = width;
Dianne Hackborn9d132642011-04-21 17:26:39 -07002026 mLandscapeRotation = Surface.ROTATION_0;
2027 mSeascapeRotation = Surface.ROTATION_180;
Craig Mautner46ac6fa2013-08-01 10:06:34 -07002028 if (res.getBoolean(com.android.internal.R.bool.config_reverseDefaultRotation)) {
Dianne Hackborn9d132642011-04-21 17:26:39 -07002029 mPortraitRotation = Surface.ROTATION_90;
2030 mUpsideDownRotation = Surface.ROTATION_270;
2031 } else {
2032 mPortraitRotation = Surface.ROTATION_270;
2033 mUpsideDownRotation = Surface.ROTATION_90;
2034 }
2035 } else {
Dianne Hackborn81e56d52011-05-26 00:55:58 -07002036 shortSize = width;
Dianne Hackbornf87d1962012-04-04 12:48:24 -07002037 longSize = height;
Dianne Hackborn9d132642011-04-21 17:26:39 -07002038 mPortraitRotation = Surface.ROTATION_0;
2039 mUpsideDownRotation = Surface.ROTATION_180;
Craig Mautner46ac6fa2013-08-01 10:06:34 -07002040 if (res.getBoolean(com.android.internal.R.bool.config_reverseDefaultRotation)) {
Dianne Hackborn9d132642011-04-21 17:26:39 -07002041 mLandscapeRotation = Surface.ROTATION_270;
2042 mSeascapeRotation = Surface.ROTATION_90;
2043 } else {
2044 mLandscapeRotation = Surface.ROTATION_90;
2045 mSeascapeRotation = Surface.ROTATION_270;
2046 }
2047 }
Dianne Hackborn81e56d52011-05-26 00:55:58 -07002048
Daniel Sandler4a066c52012-04-20 14:49:13 -04002049 // SystemUI (status bar) layout policy
Dianne Hackborndde331c2012-08-03 14:01:57 -07002050 int shortSizeDp = shortSize * DisplayMetrics.DENSITY_DEFAULT / density;
Craig Mautner46ac6fa2013-08-01 10:06:34 -07002051 int longSizeDp = longSize * DisplayMetrics.DENSITY_DEFAULT / density;
Daniel Sandler4a066c52012-04-20 14:49:13 -04002052
Devin Kimd7b12b42014-05-05 14:34:58 -07002053 // Allow the navigation bar to move on non-square small devices (phones).
2054 mNavigationBarCanMove = width != height && shortSizeDp < 600;
Daniel Sandler36412a72011-08-04 09:35:13 -04002055
Craig Mautner46ac6fa2013-08-01 10:06:34 -07002056 mHasNavigationBar = res.getBoolean(com.android.internal.R.bool.config_showNavigationBar);
Jorim Jaggi11c62e12016-04-05 20:41:21 -07002057
John Spurlock80f00c12013-06-13 11:10:51 -04002058 // Allow a system property to override this. Used by the emulator.
2059 // See also hasNavigationBar().
2060 String navBarOverride = SystemProperties.get("qemu.hw.mainkeys");
2061 if ("1".equals(navBarOverride)) {
Dianne Hackbornf87d1962012-04-04 12:48:24 -07002062 mHasNavigationBar = false;
John Spurlock80f00c12013-06-13 11:10:51 -04002063 } else if ("0".equals(navBarOverride)) {
2064 mHasNavigationBar = true;
Daniel Sandler0c4ccff2011-10-19 16:39:14 -04002065 }
2066
Jeff Brown27f1d672012-10-17 18:32:34 -07002067 // For demo purposes, allow the rotation of the HDMI display to be controlled.
2068 // By default, HDMI locks rotation to landscape.
Erik Gilling9a41ef82011-09-26 19:21:03 -07002069 if ("portrait".equals(SystemProperties.get("persist.demo.hdmirotation"))) {
Jeff Brownc82c89ed2013-04-17 17:18:15 -07002070 mDemoHdmiRotation = mPortraitRotation;
Erik Gilling9a41ef82011-09-26 19:21:03 -07002071 } else {
Jeff Brownc82c89ed2013-04-17 17:18:15 -07002072 mDemoHdmiRotation = mLandscapeRotation;
Erik Gilling9a41ef82011-09-26 19:21:03 -07002073 }
Jeff Brownc82c89ed2013-04-17 17:18:15 -07002074 mDemoHdmiRotationLock = SystemProperties.getBoolean("persist.demo.hdmirotationlock", false);
Craig Mautner46ac6fa2013-08-01 10:06:34 -07002075
Chong Zhangae6119ff2014-11-11 18:54:39 -08002076 // For demo purposes, allow the rotation of the remote display to be controlled.
2077 // By default, remote display locks rotation to landscape.
2078 if ("portrait".equals(SystemProperties.get("persist.demo.remoterotation"))) {
2079 mDemoRotation = mPortraitRotation;
2080 } else {
2081 mDemoRotation = mLandscapeRotation;
2082 }
2083 mDemoRotationLock = SystemProperties.getBoolean(
2084 "persist.demo.rotationlock", false);
2085
Craig Mautner46ac6fa2013-08-01 10:06:34 -07002086 // Only force the default orientation if the screen is xlarge, at least 960dp x 720dp, per
2087 // http://developer.android.com/guide/practices/screens_support.html#range
2088 mForceDefaultOrientation = longSizeDp >= 960 && shortSizeDp >= 720 &&
2089 res.getBoolean(com.android.internal.R.bool.config_forceDefaultOrientation) &&
2090 // For debug purposes the next line turns this feature off with:
2091 // $ adb shell setprop config.override_forced_orient true
2092 // $ adb shell wm size reset
2093 !"true".equals(SystemProperties.get("config.override_forced_orient"));
2094 }
2095
Alan Viverette5a0f4ec2013-10-07 15:10:29 -07002096 /**
2097 * @return whether the navigation bar can be hidden, e.g. the device has a
2098 * navigation bar and touch exploration is not enabled
2099 */
2100 private boolean canHideNavigationBar() {
Alan Viverette817f3cd2015-08-13 11:40:14 -04002101 return mHasNavigationBar;
Alan Viverette5a0f4ec2013-10-07 15:10:29 -07002102 }
2103
Craig Mautner46ac6fa2013-08-01 10:06:34 -07002104 @Override
2105 public boolean isDefaultOrientationForced() {
2106 return mForceDefaultOrientation;
Dianne Hackborn9d132642011-04-21 17:26:39 -07002107 }
2108
Dianne Hackbornc652de82013-02-15 16:32:56 -08002109 @Override
2110 public void setDisplayOverscan(Display display, int left, int top, int right, int bottom) {
Andrii Kulian3a507b52016-09-19 18:14:12 -07002111 // TODO(multi-display): Define policy for secondary displays.
Dianne Hackbornc652de82013-02-15 16:32:56 -08002112 if (display.getDisplayId() == Display.DEFAULT_DISPLAY) {
2113 mOverscanLeft = left;
2114 mOverscanTop = top;
2115 mOverscanRight = right;
2116 mOverscanBottom = bottom;
2117 }
2118 }
2119
Dianne Hackbornc777e072010-02-12 13:07:59 -08002120 public void updateSettings() {
2121 ContentResolver resolver = mContext.getContentResolver();
2122 boolean updateRotation = false;
Dianne Hackbornc777e072010-02-12 13:07:59 -08002123 synchronized (mLock) {
Christopher Tate5e08af02012-09-21 17:17:22 -07002124 mEndcallBehavior = Settings.System.getIntForUser(resolver,
David Brownbaf8d092010-03-08 21:52:59 -08002125 Settings.System.END_BUTTON_BEHAVIOR,
Christopher Tate5e08af02012-09-21 17:17:22 -07002126 Settings.System.END_BUTTON_BEHAVIOR_DEFAULT,
2127 UserHandle.USER_CURRENT);
2128 mIncallPowerBehavior = Settings.Secure.getIntForUser(resolver,
David Brownbaf8d092010-03-08 21:52:59 -08002129 Settings.Secure.INCALL_POWER_BUTTON_BEHAVIOR,
Christopher Tate5e08af02012-09-21 17:17:22 -07002130 Settings.Secure.INCALL_POWER_BUTTON_BEHAVIOR_DEFAULT,
2131 UserHandle.USER_CURRENT);
Bryce Leedb776ce2016-09-03 15:02:00 -07002132 mIncallBackBehavior = Settings.Secure.getIntForUser(resolver,
2133 Settings.Secure.INCALL_BACK_BUTTON_BEHAVIOR,
2134 Settings.Secure.INCALL_BACK_BUTTON_BEHAVIOR_DEFAULT,
2135 UserHandle.USER_CURRENT);
Daniel Sandlerb73617d2010-08-17 00:41:00 -04002136
Jeff Browna20dda42014-05-27 20:57:24 -07002137 // Configure wake gesture.
2138 boolean wakeGestureEnabledSetting = Settings.Secure.getIntForUser(resolver,
2139 Settings.Secure.WAKE_GESTURE_ENABLED, 0,
2140 UserHandle.USER_CURRENT) != 0;
2141 if (mWakeGestureEnabledSetting != wakeGestureEnabledSetting) {
2142 mWakeGestureEnabledSetting = wakeGestureEnabledSetting;
2143 updateWakeGestureListenerLp();
2144 }
2145
Jeff Brown207673cd2012-06-05 17:47:11 -07002146 // Configure rotation lock.
Christopher Tate5e08af02012-09-21 17:17:22 -07002147 int userRotation = Settings.System.getIntForUser(resolver,
2148 Settings.System.USER_ROTATION, Surface.ROTATION_0,
2149 UserHandle.USER_CURRENT);
Jeff Brown207673cd2012-06-05 17:47:11 -07002150 if (mUserRotation != userRotation) {
2151 mUserRotation = userRotation;
2152 updateRotation = true;
2153 }
Christopher Tate5e08af02012-09-21 17:17:22 -07002154 int userRotationMode = Settings.System.getIntForUser(resolver,
2155 Settings.System.ACCELEROMETER_ROTATION, 0, UserHandle.USER_CURRENT) != 0 ?
Jeff Brown207673cd2012-06-05 17:47:11 -07002156 WindowManagerPolicy.USER_ROTATION_FREE :
2157 WindowManagerPolicy.USER_ROTATION_LOCKED;
2158 if (mUserRotationMode != userRotationMode) {
2159 mUserRotationMode = userRotationMode;
2160 updateRotation = true;
Dianne Hackbornc777e072010-02-12 13:07:59 -08002161 updateOrientationListenerLp();
2162 }
Daniel Sandlerb73617d2010-08-17 00:41:00 -04002163
Dianne Hackbornc777e072010-02-12 13:07:59 -08002164 if (mSystemReady) {
Christopher Tate5e08af02012-09-21 17:17:22 -07002165 int pointerLocation = Settings.System.getIntForUser(resolver,
2166 Settings.System.POINTER_LOCATION, 0, UserHandle.USER_CURRENT);
Dianne Hackbornc777e072010-02-12 13:07:59 -08002167 if (mPointerLocationMode != pointerLocation) {
2168 mPointerLocationMode = pointerLocation;
Jeff Brown70825162012-03-28 17:27:48 -07002169 mHandler.sendEmptyMessage(pointerLocation != 0 ?
2170 MSG_ENABLE_POINTER_LOCATION : MSG_DISABLE_POINTER_LOCATION);
Dianne Hackbornc777e072010-02-12 13:07:59 -08002171 }
2172 }
2173 // use screen off timeout setting as the timeout for the lockscreen
Christopher Tate5e08af02012-09-21 17:17:22 -07002174 mLockScreenTimeout = Settings.System.getIntForUser(resolver,
2175 Settings.System.SCREEN_OFF_TIMEOUT, 0, UserHandle.USER_CURRENT);
2176 String imId = Settings.Secure.getStringForUser(resolver,
2177 Settings.Secure.DEFAULT_INPUT_METHOD, UserHandle.USER_CURRENT);
Dianne Hackbornc777e072010-02-12 13:07:59 -08002178 boolean hasSoftInput = imId != null && imId.length() > 0;
2179 if (mHasSoftInput != hasSoftInput) {
2180 mHasSoftInput = hasSoftInput;
2181 updateRotation = true;
2182 }
John Spurlockf1a36642013-10-12 17:50:42 -04002183 if (mImmersiveModeConfirmation != null) {
John Spurlock4355a532014-02-19 09:49:25 -05002184 mImmersiveModeConfirmation.loadSetting(mCurrentUserId);
John Spurlockd67ec252013-09-05 11:31:54 -04002185 }
tiger_huangcc6366d2015-06-29 17:17:30 +08002186 }
2187 synchronized (mWindowManagerFuncs.getWindowManagerLock()) {
John Spurlockc6d1c602014-01-17 15:22:06 -05002188 PolicyControl.reloadFromSetting(mContext);
Dianne Hackbornc777e072010-02-12 13:07:59 -08002189 }
2190 if (updateRotation) {
Jeff Brown01a98dd2011-09-20 15:08:29 -07002191 updateRotation(true);
Dianne Hackbornc777e072010-02-12 13:07:59 -08002192 }
Jeff Brown70825162012-03-28 17:27:48 -07002193 }
2194
Jeff Browna20dda42014-05-27 20:57:24 -07002195 private void updateWakeGestureListenerLp() {
2196 if (shouldEnableWakeGestureLp()) {
2197 mWakeGestureListener.requestWakeUpTrigger();
2198 } else {
2199 mWakeGestureListener.cancelWakeUpTrigger();
2200 }
2201 }
2202
2203 private boolean shouldEnableWakeGestureLp() {
Jeff Brown3ee549c2014-09-22 20:14:39 -07002204 return mWakeGestureEnabledSetting && !mAwake
Jeff Browna20dda42014-05-27 20:57:24 -07002205 && (!mLidControlsSleep || mLidState != LID_CLOSED)
2206 && mWakeGestureListener.isSupported();
2207 }
2208
Jeff Brown70825162012-03-28 17:27:48 -07002209 private void enablePointerLocation() {
2210 if (mPointerLocationView == null) {
2211 mPointerLocationView = new PointerLocationView(mContext);
2212 mPointerLocationView.setPrintCoords(false);
Dianne Hackbornc777e072010-02-12 13:07:59 -08002213 WindowManager.LayoutParams lp = new WindowManager.LayoutParams(
2214 WindowManager.LayoutParams.MATCH_PARENT,
2215 WindowManager.LayoutParams.MATCH_PARENT);
Jeff Brown3b2b3542010-10-15 00:54:27 -07002216 lp.type = WindowManager.LayoutParams.TYPE_SECURE_SYSTEM_OVERLAY;
Jeff Brownbfcb60a2011-09-08 18:51:14 -07002217 lp.flags = WindowManager.LayoutParams.FLAG_FULLSCREEN
2218 | WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE
2219 | WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE
2220 | WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN;
Jeff Brown90fc9052012-10-01 14:44:24 -07002221 if (ActivityManager.isHighEndGfx()) {
2222 lp.flags |= WindowManager.LayoutParams.FLAG_HARDWARE_ACCELERATED;
2223 lp.privateFlags |=
2224 WindowManager.LayoutParams.PRIVATE_FLAG_FORCE_HARDWARE_ACCELERATED;
2225 }
Dianne Hackbornc777e072010-02-12 13:07:59 -08002226 lp.format = PixelFormat.TRANSLUCENT;
2227 lp.setTitle("PointerLocation");
Dianne Hackborn5fd21692011-06-07 14:09:47 -07002228 WindowManager wm = (WindowManager)
Dianne Hackbornc777e072010-02-12 13:07:59 -08002229 mContext.getSystemService(Context.WINDOW_SERVICE);
Jeff Browncc4f7db2011-08-30 20:34:48 -07002230 lp.inputFeatures |= WindowManager.LayoutParams.INPUT_FEATURE_NO_INPUT_CHANNEL;
Jeff Brown70825162012-03-28 17:27:48 -07002231 wm.addView(mPointerLocationView, lp);
Michael Wrightc9c487e2013-11-07 18:55:09 -08002232 mWindowManagerFuncs.registerPointerEventListener(mPointerLocationView);
Dianne Hackbornc777e072010-02-12 13:07:59 -08002233 }
Dianne Hackbornc777e072010-02-12 13:07:59 -08002234 }
Jeff Brown70825162012-03-28 17:27:48 -07002235
2236 private void disablePointerLocation() {
Jeff Brown70825162012-03-28 17:27:48 -07002237 if (mPointerLocationView != null) {
Michael Wrightc9c487e2013-11-07 18:55:09 -08002238 mWindowManagerFuncs.unregisterPointerEventListener(mPointerLocationView);
2239 WindowManager wm = (WindowManager) mContext.getSystemService(Context.WINDOW_SERVICE);
Jeff Brown70825162012-03-28 17:27:48 -07002240 wm.removeView(mPointerLocationView);
2241 mPointerLocationView = null;
2242 }
2243 }
2244
Mike Lockwood2d1efbd2009-09-16 12:15:53 -04002245 private int readRotation(int resID) {
Mike Lockwood1753f7f2009-08-24 14:49:07 -07002246 try {
2247 int rotation = mContext.getResources().getInteger(resID);
2248 switch (rotation) {
2249 case 0:
2250 return Surface.ROTATION_0;
2251 case 90:
2252 return Surface.ROTATION_90;
2253 case 180:
2254 return Surface.ROTATION_180;
2255 case 270:
2256 return Surface.ROTATION_270;
Mike Lockwood1753f7f2009-08-24 14:49:07 -07002257 }
2258 } catch (Resources.NotFoundException e) {
Mike Lockwood2d1efbd2009-09-16 12:15:53 -04002259 // fall through
Mike Lockwood1753f7f2009-08-24 14:49:07 -07002260 }
Mike Lockwood2d1efbd2009-09-16 12:15:53 -04002261 return -1;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002262 }
2263
2264 /** {@inheritDoc} */
Craig Mautner88400d32012-09-30 12:35:45 -07002265 @Override
Dianne Hackbornc2293022013-02-06 23:14:49 -08002266 public int checkAddPermission(WindowManager.LayoutParams attrs, int[] outAppOp) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002267 int type = attrs.type;
Dianne Hackbornc2293022013-02-06 23:14:49 -08002268
2269 outAppOp[0] = AppOpsManager.OP_NONE;
2270
Wale Ogunwale74bf0652015-01-12 10:24:36 -08002271 if (!((type >= FIRST_APPLICATION_WINDOW && type <= LAST_APPLICATION_WINDOW)
2272 || (type >= FIRST_SUB_WINDOW && type <= LAST_SUB_WINDOW)
2273 || (type >= FIRST_SYSTEM_WINDOW && type <= LAST_SYSTEM_WINDOW))) {
2274 return WindowManagerGlobal.ADD_INVALID_TYPE;
2275 }
2276
2277 if (type < FIRST_SYSTEM_WINDOW || type > LAST_SYSTEM_WINDOW) {
2278 // Window manager will make sure these are okay.
Jeff Brown98365d72012-08-19 20:30:52 -07002279 return WindowManagerGlobal.ADD_OKAY;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002280 }
2281 String permission = null;
2282 switch (type) {
2283 case TYPE_TOAST:
2284 // XXX right now the app process has complete control over
2285 // this... should introduce a token to let the system
2286 // monitor/control what they are doing.
Jason Monk1c7c3192014-06-26 12:52:18 -04002287 outAppOp[0] = AppOpsManager.OP_TOAST_WINDOW;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002288 break;
Daniel Sandler7d276c32012-01-30 14:33:52 -05002289 case TYPE_DREAM:
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002290 case TYPE_INPUT_METHOD:
Dianne Hackbornb7cd8b92009-08-08 20:53:03 -07002291 case TYPE_WALLPAPER:
Wale Ogunwale5b6714c2016-11-01 20:54:46 -07002292 case TYPE_PRESENTATION:
keunyounga446bf02013-06-21 19:07:57 -07002293 case TYPE_PRIVATE_PRESENTATION:
Dianne Hackborne30e02f2014-05-27 18:24:45 -07002294 case TYPE_VOICE_INTERACTION:
Svetoslav3a5c7212014-10-14 09:54:26 -07002295 case TYPE_ACCESSIBILITY_OVERLAY:
Jason Monk8f7f3182015-11-18 16:35:14 -05002296 case TYPE_QS_DIALOG:
Dianne Hackbornb7cd8b92009-08-08 20:53:03 -07002297 // The window manager will check these.
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002298 break;
2299 case TYPE_PHONE:
2300 case TYPE_PRIORITY_PHONE:
2301 case TYPE_SYSTEM_ALERT:
2302 case TYPE_SYSTEM_ERROR:
2303 case TYPE_SYSTEM_OVERLAY:
2304 permission = android.Manifest.permission.SYSTEM_ALERT_WINDOW;
Dianne Hackbornc2293022013-02-06 23:14:49 -08002305 outAppOp[0] = AppOpsManager.OP_SYSTEM_ALERT_WINDOW;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002306 break;
2307 default:
2308 permission = android.Manifest.permission.INTERNAL_SYSTEM_WINDOW;
2309 }
2310 if (permission != null) {
Svet Ganov9cea80cd2016-02-16 11:47:00 -08002311 if (android.Manifest.permission.SYSTEM_ALERT_WINDOW.equals(permission)) {
Billy Laucbe540f2015-06-25 01:51:44 +01002312 final int callingUid = Binder.getCallingUid();
Billy Lau060275f2015-07-15 22:29:19 +01002313 // system processes will be automatically allowed privilege to draw
Billy Laucbe540f2015-06-25 01:51:44 +01002314 if (callingUid == Process.SYSTEM_UID) {
2315 return WindowManagerGlobal.ADD_OKAY;
2316 }
2317
Billy Lau060275f2015-07-15 22:29:19 +01002318 // check if user has enabled this operation. SecurityException will be thrown if
2319 // this app has not been allowed by the user
Svet Ganov03f2afc2016-03-04 16:13:03 -08002320 final int mode = mAppOpsManager.checkOpNoThrow(outAppOp[0], callingUid,
Billy Laucbe540f2015-06-25 01:51:44 +01002321 attrs.packageName);
Billy Lau060275f2015-07-15 22:29:19 +01002322 switch (mode) {
2323 case AppOpsManager.MODE_ALLOWED:
2324 case AppOpsManager.MODE_IGNORED:
2325 // although we return ADD_OKAY for MODE_IGNORED, the added window will
2326 // actually be hidden in WindowManagerService
2327 return WindowManagerGlobal.ADD_OKAY;
2328 case AppOpsManager.MODE_ERRORED:
Svet Ganov03f2afc2016-03-04 16:13:03 -08002329 try {
2330 ApplicationInfo appInfo = mContext.getPackageManager()
2331 .getApplicationInfo(attrs.packageName,
2332 UserHandle.getUserId(callingUid));
2333 // Don't crash legacy apps
2334 if (appInfo.targetSdkVersion < Build.VERSION_CODES.M) {
2335 return WindowManagerGlobal.ADD_OKAY;
2336 }
2337 } catch (PackageManager.NameNotFoundException e) {
2338 /* ignore */
2339 }
Billy Laucbe540f2015-06-25 01:51:44 +01002340 return WindowManagerGlobal.ADD_PERMISSION_DENIED;
Billy Lau060275f2015-07-15 22:29:19 +01002341 default:
2342 // in the default mode, we will make a decision here based on
2343 // checkCallingPermission()
2344 if (mContext.checkCallingPermission(permission) !=
2345 PackageManager.PERMISSION_GRANTED) {
2346 return WindowManagerGlobal.ADD_PERMISSION_DENIED;
2347 } else {
2348 return WindowManagerGlobal.ADD_OKAY;
2349 }
Billy Laucbe540f2015-06-25 01:51:44 +01002350 }
Billy Laucbe540f2015-06-25 01:51:44 +01002351 }
2352
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002353 if (mContext.checkCallingOrSelfPermission(permission)
2354 != PackageManager.PERMISSION_GRANTED) {
Jeff Brown98365d72012-08-19 20:30:52 -07002355 return WindowManagerGlobal.ADD_PERMISSION_DENIED;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002356 }
2357 }
Jeff Brown98365d72012-08-19 20:30:52 -07002358 return WindowManagerGlobal.ADD_OKAY;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002359 }
Craig Mautner88400d32012-09-30 12:35:45 -07002360
2361 @Override
2362 public boolean checkShowToOwnerOnly(WindowManager.LayoutParams attrs) {
2363
2364 // If this switch statement is modified, modify the comment in the declarations of
2365 // the type in {@link WindowManager.LayoutParams} as well.
2366 switch (attrs.type) {
2367 default:
2368 // These are the windows that by default are shown only to the user that created
2369 // them. If this needs to be overridden, set
2370 // {@link WindowManager.LayoutParams.PRIVATE_FLAG_SHOW_FOR_ALL_USERS} in
2371 // {@link WindowManager.LayoutParams}. Note that permission
2372 // {@link android.Manifest.permission.INTERNAL_SYSTEM_WINDOW} is required as well.
2373 if ((attrs.privateFlags & PRIVATE_FLAG_SHOW_FOR_ALL_USERS) == 0) {
2374 return true;
2375 }
2376 break;
2377
2378 // These are the windows that by default are shown to all users. However, to
2379 // protect against spoofing, check permissions below.
2380 case TYPE_APPLICATION_STARTING:
2381 case TYPE_BOOT_PROGRESS:
2382 case TYPE_DISPLAY_OVERLAY:
Selim Cinekf83e8242015-05-19 18:08:14 -07002383 case TYPE_INPUT_CONSUMER:
Craig Mautner88400d32012-09-30 12:35:45 -07002384 case TYPE_KEYGUARD_DIALOG:
2385 case TYPE_MAGNIFICATION_OVERLAY:
2386 case TYPE_NAVIGATION_BAR:
2387 case TYPE_NAVIGATION_BAR_PANEL:
2388 case TYPE_PHONE:
2389 case TYPE_POINTER:
2390 case TYPE_PRIORITY_PHONE:
Craig Mautner88400d32012-09-30 12:35:45 -07002391 case TYPE_SEARCH_BAR:
2392 case TYPE_STATUS_BAR:
2393 case TYPE_STATUS_BAR_PANEL:
2394 case TYPE_STATUS_BAR_SUB_PANEL:
2395 case TYPE_SYSTEM_DIALOG:
Craig Mautner88400d32012-09-30 12:35:45 -07002396 case TYPE_VOLUME_OVERLAY:
Wale Ogunwale5b6714c2016-11-01 20:54:46 -07002397 case TYPE_PRESENTATION:
keunyounga446bf02013-06-21 19:07:57 -07002398 case TYPE_PRIVATE_PRESENTATION:
Filip Gruszczynski466f3212015-09-21 17:57:57 -07002399 case TYPE_DOCK_DIVIDER:
Craig Mautner88400d32012-09-30 12:35:45 -07002400 break;
2401 }
2402
2403 // Check if third party app has set window to system window type.
2404 return mContext.checkCallingOrSelfPermission(
2405 android.Manifest.permission.INTERNAL_SYSTEM_WINDOW)
2406 != PackageManager.PERMISSION_GRANTED;
2407 }
2408
Craig Mautner967212c2013-04-13 21:10:58 -07002409 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002410 public void adjustWindowParamsLw(WindowManager.LayoutParams attrs) {
2411 switch (attrs.type) {
2412 case TYPE_SYSTEM_OVERLAY:
Jeff Brown3b2b3542010-10-15 00:54:27 -07002413 case TYPE_SECURE_SYSTEM_OVERLAY:
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002414 // These types of windows can't receive input events.
2415 attrs.flags |= WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE
2416 | WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE;
Jeff Brownbfcb60a2011-09-08 18:51:14 -07002417 attrs.flags &= ~WindowManager.LayoutParams.FLAG_WATCH_OUTSIDE_TOUCH;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002418 break;
Jorim Jaggi380ecb82014-03-14 17:25:20 +01002419 case TYPE_STATUS_BAR:
2420
2421 // If the Keyguard is in a hidden state (occluded by another window), we force to
2422 // remove the wallpaper and keyguard flag so that any change in-flight after setting
2423 // the keyguard as occluded wouldn't set these flags again.
2424 // See {@link #processKeyguardSetHiddenResultLw}.
Jorim Jaggife762342016-10-13 14:33:27 +02002425 if (mKeyguardOccluded) {
Jorim Jaggi380ecb82014-03-14 17:25:20 +01002426 attrs.flags &= ~WindowManager.LayoutParams.FLAG_SHOW_WALLPAPER;
2427 attrs.privateFlags &= ~WindowManager.LayoutParams.PRIVATE_FLAG_KEYGUARD;
2428 }
2429 break;
Svetoslav Ganovaa076532016-08-01 19:16:43 -07002430
Muyuan Li36ca72c2016-08-06 20:24:06 -07002431 case TYPE_SCREENSHOT:
2432 attrs.flags |= WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE;
2433 break;
Svetoslav Ganovaa076532016-08-01 19:16:43 -07002434
2435 case TYPE_TOAST:
2436 // While apps should use the dedicated toast APIs to add such windows
2437 // it possible legacy apps to add the window directly. Therefore, we
2438 // make windows added directly by the app behave as a toast as much
2439 // as possible in terms of timeout and animation.
2440 if (attrs.hideTimeoutMilliseconds < 0
2441 || attrs.hideTimeoutMilliseconds > TOAST_WINDOW_TIMEOUT) {
2442 attrs.hideTimeoutMilliseconds = TOAST_WINDOW_TIMEOUT;
2443 }
2444 attrs.windowAnimations = com.android.internal.R.style.Animation_Toast;
2445 break;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002446 }
Adrian Roos38502112014-04-09 21:04:11 +02002447
2448 if (attrs.type != TYPE_STATUS_BAR) {
2449 // The status bar is the only window allowed to exhibit keyguard behavior.
2450 attrs.privateFlags &= ~WindowManager.LayoutParams.PRIVATE_FLAG_KEYGUARD;
2451 }
Adrian Roosea562512014-05-05 13:33:03 +02002452
Jorim Jaggi4fa78922015-11-30 17:13:56 -08002453 if (ActivityManager.isHighEndGfx()) {
2454 if ((attrs.flags & FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS) != 0) {
2455 attrs.subtreeSystemUiVisibility |= View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION;
2456 }
Jorim Jaggi8f5701b2016-04-04 18:36:02 -07002457 final boolean forceWindowDrawsStatusBarBackground =
2458 (attrs.privateFlags & PRIVATE_FLAG_FORCE_DRAW_STATUS_BAR_BACKGROUND)
2459 != 0;
Jorim Jaggi4fa78922015-11-30 17:13:56 -08002460 if ((attrs.flags & FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS) != 0
Jorim Jaggi8f5701b2016-04-04 18:36:02 -07002461 || forceWindowDrawsStatusBarBackground
2462 && attrs.height == MATCH_PARENT && attrs.width == MATCH_PARENT) {
Jorim Jaggi4fa78922015-11-30 17:13:56 -08002463 attrs.subtreeSystemUiVisibility |= View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN;
2464 }
Adrian Roosea562512014-05-05 13:33:03 +02002465 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002466 }
RoboErik8a2cfc32014-05-16 11:19:38 -07002467
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002468 void readLidState() {
Jeff Brown2e7760e2012-04-11 15:14:55 -07002469 mLidState = mWindowManagerFuncs.getLidState();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002470 }
RoboErik8a2cfc32014-05-16 11:19:38 -07002471
Michael Wright3818c922014-09-02 13:59:07 -07002472 private void readCameraLensCoverState() {
2473 mCameraLensCoverState = mWindowManagerFuncs.getCameraLensCoverState();
2474 }
2475
Jeff Browndaa37532012-05-01 15:54:03 -07002476 private boolean isHidden(int accessibilityMode) {
2477 switch (accessibilityMode) {
2478 case 1:
2479 return mLidState == LID_CLOSED;
2480 case 2:
2481 return mLidState == LID_OPEN;
2482 default:
2483 return false;
Dianne Hackborn2862fff2009-09-15 22:56:29 -07002484 }
Dianne Hackborn2862fff2009-09-15 22:56:29 -07002485 }
Jeff Brownd04a88c2011-01-16 14:05:47 -08002486
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002487 /** {@inheritDoc} */
Craig Mautner967212c2013-04-13 21:10:58 -07002488 @Override
Jeff Browndaa37532012-05-01 15:54:03 -07002489 public void adjustConfigurationLw(Configuration config, int keyboardPresence,
2490 int navigationPresence) {
2491 mHaveBuiltInKeyboard = (keyboardPresence & PRESENCE_INTERNAL) != 0;
2492
Jeff Brownf71343d2013-05-31 17:59:11 -07002493 readConfigurationDependentBehaviors();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002494 readLidState();
Jeff Brownd04a88c2011-01-16 14:05:47 -08002495
Jeff Browndaa37532012-05-01 15:54:03 -07002496 if (config.keyboard == Configuration.KEYBOARD_NOKEYS
2497 || (keyboardPresence == PRESENCE_INTERNAL
2498 && isHidden(mLidKeyboardAccessibility))) {
Jeff Brownd04a88c2011-01-16 14:05:47 -08002499 config.hardKeyboardHidden = Configuration.HARDKEYBOARDHIDDEN_YES;
Jeff Browndaa37532012-05-01 15:54:03 -07002500 if (!mHasSoftInput) {
2501 config.keyboardHidden = Configuration.KEYBOARDHIDDEN_YES;
2502 }
Jeff Brownd04a88c2011-01-16 14:05:47 -08002503 }
2504
Jeff Browndaa37532012-05-01 15:54:03 -07002505 if (config.navigation == Configuration.NAVIGATION_NONAV
2506 || (navigationPresence == PRESENCE_INTERNAL
2507 && isHidden(mLidNavigationAccessibility))) {
Jeff Brownd04a88c2011-01-16 14:05:47 -08002508 config.navigationHidden = Configuration.NAVIGATIONHIDDEN_YES;
Jeff Brownd04a88c2011-01-16 14:05:47 -08002509 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002510 }
Jeff Brownd04a88c2011-01-16 14:05:47 -08002511
Jorim Jaggi11c62e12016-04-05 20:41:21 -07002512 @Override
2513 public void onConfigurationChanged() {
Andrii Kulian3a507b52016-09-19 18:14:12 -07002514 // TODO(multi-display): Define policy for secondary displays.
Jorim Jaggi11c62e12016-04-05 20:41:21 -07002515 final Resources res = mContext.getResources();
2516
2517 mStatusBarHeight =
2518 res.getDimensionPixelSize(com.android.internal.R.dimen.status_bar_height);
2519
2520 // Height of the navigation bar when presented horizontally at bottom
2521 mNavigationBarHeightForRotationDefault[mPortraitRotation] =
2522 mNavigationBarHeightForRotationDefault[mUpsideDownRotation] =
2523 res.getDimensionPixelSize(com.android.internal.R.dimen.navigation_bar_height);
2524 mNavigationBarHeightForRotationDefault[mLandscapeRotation] =
2525 mNavigationBarHeightForRotationDefault[mSeascapeRotation] = res.getDimensionPixelSize(
2526 com.android.internal.R.dimen.navigation_bar_height_landscape);
2527
2528 // Width of the navigation bar when presented vertically along one side
2529 mNavigationBarWidthForRotationDefault[mPortraitRotation] =
2530 mNavigationBarWidthForRotationDefault[mUpsideDownRotation] =
2531 mNavigationBarWidthForRotationDefault[mLandscapeRotation] =
2532 mNavigationBarWidthForRotationDefault[mSeascapeRotation] =
2533 res.getDimensionPixelSize(com.android.internal.R.dimen.navigation_bar_width);
2534
Justin Paupore01915a12016-09-28 17:41:26 -07002535 if (ALTERNATE_CAR_MODE_NAV_SIZE) {
2536 // Height of the navigation bar when presented horizontally at bottom
2537 mNavigationBarHeightForRotationInCarMode[mPortraitRotation] =
2538 mNavigationBarHeightForRotationInCarMode[mUpsideDownRotation] =
2539 res.getDimensionPixelSize(
2540 com.android.internal.R.dimen.navigation_bar_height_car_mode);
2541 mNavigationBarHeightForRotationInCarMode[mLandscapeRotation] =
2542 mNavigationBarHeightForRotationInCarMode[mSeascapeRotation] = res.getDimensionPixelSize(
2543 com.android.internal.R.dimen.navigation_bar_height_landscape_car_mode);
Jorim Jaggi11c62e12016-04-05 20:41:21 -07002544
Justin Paupore01915a12016-09-28 17:41:26 -07002545 // Width of the navigation bar when presented vertically along one side
2546 mNavigationBarWidthForRotationInCarMode[mPortraitRotation] =
2547 mNavigationBarWidthForRotationInCarMode[mUpsideDownRotation] =
2548 mNavigationBarWidthForRotationInCarMode[mLandscapeRotation] =
2549 mNavigationBarWidthForRotationInCarMode[mSeascapeRotation] =
2550 res.getDimensionPixelSize(
2551 com.android.internal.R.dimen.navigation_bar_width_car_mode);
2552 }
Jorim Jaggi11c62e12016-04-05 20:41:21 -07002553 }
2554
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002555 /** {@inheritDoc} */
Craig Mautner967212c2013-04-13 21:10:58 -07002556 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002557 public int windowTypeToLayerLw(int type) {
2558 if (type >= FIRST_APPLICATION_WINDOW && type <= LAST_APPLICATION_WINDOW) {
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07002559 return 2;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002560 }
2561 switch (type) {
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07002562 case TYPE_WALLPAPER:
2563 // wallpaper is at the bottom, though the window manager may move it.
Wale Ogunwale3a931692016-11-02 16:49:48 -07002564 return 1;
2565 case TYPE_PRESENTATION:
2566 case TYPE_PRIVATE_PRESENTATION:
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07002567 return 2;
Filip Gruszczynskie95b0ae2015-09-30 10:55:33 -07002568 case TYPE_DOCK_DIVIDER:
2569 return 2;
Jason Monk8f7f3182015-11-18 16:35:14 -05002570 case TYPE_QS_DIALOG:
2571 return 2;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07002572 case TYPE_PHONE:
2573 return 3;
2574 case TYPE_SEARCH_BAR:
Jorim Jaggi225d3b52015-04-01 11:18:57 -07002575 case TYPE_VOICE_INTERACTION_STARTING:
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07002576 return 4;
Dianne Hackborne30e02f2014-05-27 18:24:45 -07002577 case TYPE_VOICE_INTERACTION:
2578 // voice interaction layer is almost immediately above apps.
2579 return 5;
Selim Cinekf83e8242015-05-19 18:08:14 -07002580 case TYPE_INPUT_CONSUMER:
Dianne Hackborne30e02f2014-05-27 18:24:45 -07002581 return 6;
Selim Cinekf83e8242015-05-19 18:08:14 -07002582 case TYPE_SYSTEM_DIALOG:
2583 return 7;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07002584 case TYPE_TOAST:
2585 // toasts and the plugged-in battery thing
Selim Cinekf83e8242015-05-19 18:08:14 -07002586 return 8;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07002587 case TYPE_PRIORITY_PHONE:
2588 // SIM errors and unlock. Not sure if this really should be in a high layer.
Selim Cinekf83e8242015-05-19 18:08:14 -07002589 return 9;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07002590 case TYPE_DREAM:
2591 // used for Dreams (screensavers with TYPE_DREAM windows)
Selim Cinekf83e8242015-05-19 18:08:14 -07002592 return 10;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07002593 case TYPE_SYSTEM_ALERT:
2594 // like the ANR / app crashed dialogs
Selim Cinekf83e8242015-05-19 18:08:14 -07002595 return 11;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07002596 case TYPE_INPUT_METHOD:
2597 // on-screen keyboards and other such input method user interfaces go here.
Selim Cinekf83e8242015-05-19 18:08:14 -07002598 return 12;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07002599 case TYPE_INPUT_METHOD_DIALOG:
2600 // on-screen keyboards and other such input method user interfaces go here.
Selim Cinekf83e8242015-05-19 18:08:14 -07002601 return 13;
Filip Gruszczynski466f3212015-09-21 17:57:57 -07002602 case TYPE_STATUS_BAR_SUB_PANEL:
Filip Gruszczynskie95b0ae2015-09-30 10:55:33 -07002603 return 15;
Filip Gruszczynski466f3212015-09-21 17:57:57 -07002604 case TYPE_STATUS_BAR:
Filip Gruszczynskie95b0ae2015-09-30 10:55:33 -07002605 return 16;
Filip Gruszczynski466f3212015-09-21 17:57:57 -07002606 case TYPE_STATUS_BAR_PANEL:
Filip Gruszczynskie95b0ae2015-09-30 10:55:33 -07002607 return 17;
Filip Gruszczynski466f3212015-09-21 17:57:57 -07002608 case TYPE_KEYGUARD_DIALOG:
Filip Gruszczynskie95b0ae2015-09-30 10:55:33 -07002609 return 18;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07002610 case TYPE_VOLUME_OVERLAY:
2611 // the on-screen volume indicator and controller shown when the user
2612 // changes the device volume
Filip Gruszczynskie95b0ae2015-09-30 10:55:33 -07002613 return 19;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07002614 case TYPE_SYSTEM_OVERLAY:
2615 // the on-screen volume indicator and controller shown when the user
2616 // changes the device volume
Filip Gruszczynskie95b0ae2015-09-30 10:55:33 -07002617 return 20;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07002618 case TYPE_NAVIGATION_BAR:
2619 // the navigation bar, if available, shows atop most things
Filip Gruszczynskie95b0ae2015-09-30 10:55:33 -07002620 return 21;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07002621 case TYPE_NAVIGATION_BAR_PANEL:
2622 // some panels (e.g. search) need to show on top of the navigation bar
Filip Gruszczynskie95b0ae2015-09-30 10:55:33 -07002623 return 22;
Muyuan Li6ca619f2016-03-08 13:30:42 -08002624 case TYPE_SCREENSHOT:
2625 // screenshot selection layer shouldn't go above system error, but it should cover
2626 // navigation bars at the very least.
2627 return 23;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07002628 case TYPE_SYSTEM_ERROR:
2629 // system-level error dialogs
Muyuan Li6ca619f2016-03-08 13:30:42 -08002630 return 24;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07002631 case TYPE_MAGNIFICATION_OVERLAY:
2632 // used to highlight the magnified portion of a display
Muyuan Li6ca619f2016-03-08 13:30:42 -08002633 return 25;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07002634 case TYPE_DISPLAY_OVERLAY:
2635 // used to simulate secondary display devices
Muyuan Li6ca619f2016-03-08 13:30:42 -08002636 return 26;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07002637 case TYPE_DRAG:
2638 // the drag layer: input for drag-and-drop is associated with this window,
2639 // which sits above all other focusable windows
Muyuan Li6ca619f2016-03-08 13:30:42 -08002640 return 27;
Svetoslav3a5c7212014-10-14 09:54:26 -07002641 case TYPE_ACCESSIBILITY_OVERLAY:
2642 // overlay put by accessibility services to intercept user interaction
Filip Gruszczynskie95b0ae2015-09-30 10:55:33 -07002643 return 28;
Muyuan Li6ca619f2016-03-08 13:30:42 -08002644 case TYPE_SECURE_SYSTEM_OVERLAY:
Filip Gruszczynskie95b0ae2015-09-30 10:55:33 -07002645 return 29;
Muyuan Li6ca619f2016-03-08 13:30:42 -08002646 case TYPE_BOOT_PROGRESS:
2647 return 30;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07002648 case TYPE_POINTER:
2649 // the (mouse) pointer layer
Muyuan Li6ca619f2016-03-08 13:30:42 -08002650 return 31;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002651 }
2652 Log.e(TAG, "Unknown window type: " + type);
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07002653 return 2;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002654 }
2655
2656 /** {@inheritDoc} */
Craig Mautner46ac6fa2013-08-01 10:06:34 -07002657 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002658 public int subWindowTypeToLayerLw(int type) {
2659 switch (type) {
2660 case TYPE_APPLICATION_PANEL:
2661 case TYPE_APPLICATION_ATTACHED_DIALOG:
2662 return APPLICATION_PANEL_SUBLAYER;
2663 case TYPE_APPLICATION_MEDIA:
2664 return APPLICATION_MEDIA_SUBLAYER;
Dianne Hackborn5cb8d792009-05-21 17:34:15 -07002665 case TYPE_APPLICATION_MEDIA_OVERLAY:
2666 return APPLICATION_MEDIA_OVERLAY_SUBLAYER;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002667 case TYPE_APPLICATION_SUB_PANEL:
2668 return APPLICATION_SUB_PANEL_SUBLAYER;
Wale Ogunwale0a4dc222015-04-14 12:58:42 -07002669 case TYPE_APPLICATION_ABOVE_SUB_PANEL:
2670 return APPLICATION_ABOVE_SUB_PANEL_SUBLAYER;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002671 }
2672 Log.e(TAG, "Unknown sub-window type: " + type);
2673 return 0;
2674 }
2675
Craig Mautner46ac6fa2013-08-01 10:06:34 -07002676 @Override
Dianne Hackbornabe0da02009-09-18 01:55:39 -07002677 public int getMaxWallpaperLayer() {
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07002678 return windowTypeToLayerLw(TYPE_STATUS_BAR);
Dianne Hackbornabe0da02009-09-18 01:55:39 -07002679 }
2680
Sriram Viswanathan9ebbe6a2015-11-16 17:59:22 -08002681 private int getNavigationBarWidth(int rotation, int uiMode) {
Justin Paupore01915a12016-09-28 17:41:26 -07002682 if (ALTERNATE_CAR_MODE_NAV_SIZE && (uiMode & UI_MODE_TYPE_MASK) == UI_MODE_TYPE_CAR) {
Sriram Viswanathan9ebbe6a2015-11-16 17:59:22 -08002683 return mNavigationBarWidthForRotationInCarMode[rotation];
2684 } else {
2685 return mNavigationBarWidthForRotationDefault[rotation];
2686 }
2687 }
2688
Craig Mautner46ac6fa2013-08-01 10:06:34 -07002689 @Override
Andrii Kuliandb8e1062016-11-15 18:30:27 -08002690 public int getNonDecorDisplayWidth(int fullWidth, int fullHeight, int rotation, int uiMode,
2691 int displayId) {
2692 // TODO(multi-display): Support navigation bar on secondary displays.
2693 if (displayId == Display.DEFAULT_DISPLAY && mHasNavigationBar) {
Dianne Hackborn077ee852012-04-09 16:27:07 -07002694 // For a basic navigation bar, when we are in landscape mode we place
2695 // the navigation bar to the side.
Daniel Sandler4a066c52012-04-20 14:49:13 -04002696 if (mNavigationBarCanMove && fullWidth > fullHeight) {
Sriram Viswanathan9ebbe6a2015-11-16 17:59:22 -08002697 return fullWidth - getNavigationBarWidth(rotation, uiMode);
Dianne Hackborn077ee852012-04-09 16:27:07 -07002698 }
Dianne Hackborn1f903c32011-09-13 19:18:06 -07002699 }
2700 return fullWidth;
Dianne Hackborne2515ee2011-04-27 18:52:56 -04002701 }
2702
Sriram Viswanathan9ebbe6a2015-11-16 17:59:22 -08002703 private int getNavigationBarHeight(int rotation, int uiMode) {
Justin Paupore01915a12016-09-28 17:41:26 -07002704 if (ALTERNATE_CAR_MODE_NAV_SIZE && (uiMode & UI_MODE_TYPE_MASK) == UI_MODE_TYPE_CAR) {
Sriram Viswanathan9ebbe6a2015-11-16 17:59:22 -08002705 return mNavigationBarHeightForRotationInCarMode[rotation];
2706 } else {
2707 return mNavigationBarHeightForRotationDefault[rotation];
2708 }
2709 }
2710
Jose Lima9546b202014-07-02 17:21:51 -07002711 @Override
Andrii Kuliandb8e1062016-11-15 18:30:27 -08002712 public int getNonDecorDisplayHeight(int fullWidth, int fullHeight, int rotation, int uiMode,
2713 int displayId) {
2714 // TODO(multi-display): Support navigation bar on secondary displays.
2715 if (displayId == Display.DEFAULT_DISPLAY && mHasNavigationBar) {
Dianne Hackborn077ee852012-04-09 16:27:07 -07002716 // For a basic navigation bar, when we are in portrait mode we place
2717 // the navigation bar to the bottom.
Daniel Sandler4a066c52012-04-20 14:49:13 -04002718 if (!mNavigationBarCanMove || fullWidth < fullHeight) {
Sriram Viswanathan9ebbe6a2015-11-16 17:59:22 -08002719 return fullHeight - getNavigationBarHeight(rotation, uiMode);
Dianne Hackborn077ee852012-04-09 16:27:07 -07002720 }
2721 }
2722 return fullHeight;
Dianne Hackborn69cb8752011-05-19 18:13:32 -07002723 }
2724
Jose Lima9546b202014-07-02 17:21:51 -07002725 @Override
Andrii Kuliandb8e1062016-11-15 18:30:27 -08002726 public int getConfigDisplayWidth(int fullWidth, int fullHeight, int rotation, int uiMode,
2727 int displayId) {
2728 return getNonDecorDisplayWidth(fullWidth, fullHeight, rotation, uiMode, displayId);
Dianne Hackborn69cb8752011-05-19 18:13:32 -07002729 }
2730
Jose Lima9546b202014-07-02 17:21:51 -07002731 @Override
Andrii Kuliandb8e1062016-11-15 18:30:27 -08002732 public int getConfigDisplayHeight(int fullWidth, int fullHeight, int rotation, int uiMode,
2733 int displayId) {
John Spurlock80f00c12013-06-13 11:10:51 -04002734 // There is a separate status bar at the top of the display. We don't count that as part
2735 // of the fixed decor, since it can hide; however, for purposes of configurations,
Dianne Hackborn077ee852012-04-09 16:27:07 -07002736 // we do want to exclude it since applications can't generally use that part
2737 // of the screen.
Andrii Kuliandb8e1062016-11-15 18:30:27 -08002738 // TODO(multi-display): Support status bars on secondary displays.
2739 if (displayId == Display.DEFAULT_DISPLAY) {
2740 return getNonDecorDisplayHeight(fullWidth, fullHeight, rotation, uiMode, displayId)
2741 - mStatusBarHeight;
2742 }
2743 return fullHeight;
Dianne Hackborne2515ee2011-04-27 18:52:56 -04002744 }
2745
Craig Mautnera3f4bf52012-10-10 20:37:48 -07002746 @Override
Jorim Jaggi0d674622014-05-21 01:34:15 +02002747 public boolean isKeyguardHostWindow(WindowManager.LayoutParams attrs) {
2748 return attrs.type == TYPE_STATUS_BAR;
2749 }
2750
2751 @Override
Jorim Jaggife762342016-10-13 14:33:27 +02002752 public boolean canBeHiddenByKeyguardLw(WindowState win) {
2753 switch (win.getAttrs().type) {
Craig Mautnera3f4bf52012-10-10 20:37:48 -07002754 case TYPE_STATUS_BAR:
2755 case TYPE_NAVIGATION_BAR:
2756 case TYPE_WALLPAPER:
2757 case TYPE_DREAM:
Craig Mautnera3f4bf52012-10-10 20:37:48 -07002758 return false;
2759 default:
Adrian Roos461829d2015-06-03 14:41:18 -07002760 // Hide only windows below the keyguard host window.
2761 return windowTypeToLayerLw(win.getBaseType())
2762 < windowTypeToLayerLw(TYPE_STATUS_BAR);
Craig Mautnera3f4bf52012-10-10 20:37:48 -07002763 }
Dianne Hackborn01ad2f42009-09-24 19:24:56 -07002764 }
Craig Mautner8e4df6c2012-05-23 16:57:23 -07002765
Jorim Jaggife762342016-10-13 14:33:27 +02002766 private boolean shouldBeHiddenByKeyguard(WindowState win, WindowState imeTarget) {
2767
2768 // Keyguard visibility of window from activities are determined over activity visibility.
2769 if (win.getAppToken() != null) {
2770 return false;
2771 }
2772
2773 final LayoutParams attrs = win.getAttrs();
2774 final boolean showImeOverKeyguard = imeTarget != null && imeTarget.isVisibleLw() &&
2775 ((imeTarget.getAttrs().flags & FLAG_SHOW_WHEN_LOCKED) != 0
2776 || !canBeHiddenByKeyguardLw(imeTarget));
2777
2778 // Show IME over the keyguard if the target allows it
2779 boolean allowWhenLocked = (win.isInputMethodWindow() || imeTarget == this)
2780 && showImeOverKeyguard;;
2781
2782 if (isKeyguardLocked() && isKeyguardOccluded()) {
2783 // Show SHOW_WHEN_LOCKED windows if Keyguard is occluded.
2784 allowWhenLocked |= (attrs.flags & FLAG_SHOW_WHEN_LOCKED) != 0
2785 // Show error dialogs over apps that are shown on lockscreen
2786 || (attrs.privateFlags & PRIVATE_FLAG_SYSTEM_ERROR) != 0;
2787 }
2788
2789 boolean keyguardLocked = isKeyguardLocked();
2790 boolean hideDockDivider = attrs.type == TYPE_DOCK_DIVIDER
2791 && !mWindowManagerInternal.isStackVisible(DOCKED_STACK_ID);
2792 return (keyguardLocked && !allowWhenLocked && win.getDisplayId() == Display.DEFAULT_DISPLAY)
2793 || hideDockDivider;
Craig Mautner7d7808f2014-09-11 18:02:38 -07002794 }
2795
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002796 /** {@inheritDoc} */
Craig Mautner8e4df6c2012-05-23 16:57:23 -07002797 @Override
Jorim Jaggiba41f4b2016-12-14 17:43:07 -08002798 public StartingSurface addSplashScreen(IBinder appToken, String packageName, int theme,
2799 CompatibilityInfo compatInfo, CharSequence nonLocalizedLabel, int labelRes, int icon,
2800 int logo, int windowFlags, Configuration overrideConfig) {
2801 if (!SHOW_SPLASH_SCREENS) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002802 return null;
2803 }
2804 if (packageName == null) {
2805 return null;
2806 }
Craig Mautner8e4df6c2012-05-23 16:57:23 -07002807
Mathias Jeppssond1443e92012-08-24 15:25:32 +02002808 WindowManager wm = null;
2809 View view = null;
2810
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002811 try {
Dianne Hackborn867ab6472010-04-29 13:28:56 -07002812 Context context = mContext;
Jorim Jaggiba41f4b2016-12-14 17:43:07 -08002813 if (DEBUG_SPLASH_SCREEN) Slog.d(TAG, "addSplashScreen " + packageName
Craig Mautner6fbda632012-07-03 09:26:39 -07002814 + ": nonLocalizedLabel=" + nonLocalizedLabel + " theme="
2815 + Integer.toHexString(theme));
Dianne Hackborn247fe742011-01-08 17:25:57 -08002816 if (theme != context.getThemeResId() || labelRes != 0) {
Dianne Hackborn867ab6472010-04-29 13:28:56 -07002817 try {
2818 context = context.createPackageContext(packageName, 0);
Dianne Hackborn247fe742011-01-08 17:25:57 -08002819 context.setTheme(theme);
Dianne Hackborn867ab6472010-04-29 13:28:56 -07002820 } catch (PackageManager.NameNotFoundException e) {
2821 // Ignore
2822 }
2823 }
Craig Mautner8e4df6c2012-05-23 16:57:23 -07002824
Andrii Kuliana8a9bc52016-10-14 11:00:13 -07002825 if (overrideConfig != null && !overrideConfig.equals(EMPTY)) {
Jorim Jaggiba41f4b2016-12-14 17:43:07 -08002826 if (DEBUG_SPLASH_SCREEN) Slog.d(TAG, "addSplashScreen: creating context based"
2827 + " on overrideConfig" + overrideConfig + " for splash screen");
Wale Ogunwaledfc18622016-04-16 15:08:48 -07002828 final Context overrideContext = context.createConfigurationContext(overrideConfig);
2829 overrideContext.setTheme(theme);
2830 final TypedArray typedArray = overrideContext.obtainStyledAttributes(
2831 com.android.internal.R.styleable.Window);
2832 final int resId = typedArray.getResourceId(R.styleable.Window_windowBackground, 0);
2833 if (resId != 0 && overrideContext.getDrawable(resId) != null) {
2834 // We want to use the windowBackground for the override context if it is
2835 // available, otherwise we use the default one to make sure a themed starting
2836 // window is displayed for the app.
Jorim Jaggiba41f4b2016-12-14 17:43:07 -08002837 if (DEBUG_SPLASH_SCREEN) Slog.d(TAG, "addSplashScreen: apply overrideConfig"
Wale Ogunwaledfc18622016-04-16 15:08:48 -07002838 + overrideConfig + " to starting window resId=" + resId);
2839 context = overrideContext;
2840 }
2841 }
2842
2843 final PhoneWindow win = new PhoneWindow(context);
Jorim Jaggia16cc152015-06-01 16:55:05 -07002844 win.setIsStartingWindow(true);
Craig Mautner8e4df6c2012-05-23 16:57:23 -07002845
Phil Weaver155edc62016-06-09 10:24:53 -07002846 CharSequence label = context.getResources().getText(labelRes, null);
2847 // Only change the accessibility title if the label is localized
2848 if (label != null) {
2849 win.setTitle(label, true);
2850 } else {
2851 win.setTitle(nonLocalizedLabel, false);
2852 }
Craig Mautner8e4df6c2012-05-23 16:57:23 -07002853
Dianne Hackborn867ab6472010-04-29 13:28:56 -07002854 win.setType(
2855 WindowManager.LayoutParams.TYPE_APPLICATION_STARTING);
Adrian Roos602c68e2015-04-24 16:03:47 -07002856
2857 synchronized (mWindowManagerFuncs.getWindowManagerLock()) {
2858 // Assumes it's safe to show starting windows of launched apps while
2859 // the keyguard is being hidden. This is okay because starting windows never show
2860 // secret information.
Jorim Jaggife762342016-10-13 14:33:27 +02002861 if (mKeyguardOccluded) {
Adrian Roos602c68e2015-04-24 16:03:47 -07002862 windowFlags |= FLAG_SHOW_WHEN_LOCKED;
2863 }
2864 }
2865
Dianne Hackborn867ab6472010-04-29 13:28:56 -07002866 // Force the window flags: this is a fake window, so it is not really
2867 // touchable or focusable by the user. We also add in the ALT_FOCUSABLE_IM
2868 // flag because we do know that the next window will take input
2869 // focus, so we want to get the IME window up on top of us right away.
2870 win.setFlags(
Dianne Hackborn7eec10e2010-11-12 18:03:47 -08002871 windowFlags|
Dianne Hackborn867ab6472010-04-29 13:28:56 -07002872 WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE|
2873 WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE|
2874 WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM,
Dianne Hackborn7eec10e2010-11-12 18:03:47 -08002875 windowFlags|
Dianne Hackborn867ab6472010-04-29 13:28:56 -07002876 WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE|
2877 WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE|
2878 WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM);
Craig Mautner8e4df6c2012-05-23 16:57:23 -07002879
Adam Powell04fe6eb2013-05-31 14:39:48 -07002880 win.setDefaultIcon(icon);
2881 win.setDefaultLogo(logo);
2882
Dianne Hackborn867ab6472010-04-29 13:28:56 -07002883 win.setLayout(WindowManager.LayoutParams.MATCH_PARENT,
Dianne Hackborn2f0b1752011-05-31 17:59:49 -07002884 WindowManager.LayoutParams.MATCH_PARENT);
Craig Mautner8e4df6c2012-05-23 16:57:23 -07002885
Phil Weaver266ed9a2016-06-08 00:34:40 +00002886 final WindowManager.LayoutParams params = win.getAttributes();
Dianne Hackborn867ab6472010-04-29 13:28:56 -07002887 params.token = appToken;
2888 params.packageName = packageName;
2889 params.windowAnimations = win.getWindowStyle().getResourceId(
2890 com.android.internal.R.styleable.Window_windowAnimationStyle, 0);
John Reck61375a82014-09-18 19:27:48 +00002891 params.privateFlags |=
2892 WindowManager.LayoutParams.PRIVATE_FLAG_FAKE_HARDWARE_ACCELERATED;
Craig Mautner88400d32012-09-30 12:35:45 -07002893 params.privateFlags |= WindowManager.LayoutParams.PRIVATE_FLAG_SHOW_FOR_ALL_USERS;
Adam Lesinski95c42972013-10-02 10:13:27 -07002894
2895 if (!compatInfo.supportsScreen()) {
2896 params.privateFlags |= WindowManager.LayoutParams.PRIVATE_FLAG_COMPATIBLE_WINDOW;
2897 }
2898
Jorim Jaggiba41f4b2016-12-14 17:43:07 -08002899 params.setTitle("Splash Screen " + packageName);
Dianne Hackborn867ab6472010-04-29 13:28:56 -07002900
Mathias Jeppssond1443e92012-08-24 15:25:32 +02002901 wm = (WindowManager)context.getSystemService(Context.WINDOW_SERVICE);
2902 view = win.getDecorView();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002903
Jorim Jaggiba41f4b2016-12-14 17:43:07 -08002904 if (DEBUG_SPLASH_SCREEN) Slog.d(TAG, "Adding splash screen window for "
Wale Ogunwaledfc18622016-04-16 15:08:48 -07002905 + packageName + " / " + appToken + ": " + (view.getParent() != null ? view : null));
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002906
2907 wm.addView(view, params);
2908
2909 // Only return the view if it was successfully added to the
2910 // window manager... which we can tell by it having a parent.
Jorim Jaggi02886a82016-12-06 09:10:06 -08002911 return view.getParent() != null ? new SplashScreenSurface(view, appToken) : null;
Jeff Brown98365d72012-08-19 20:30:52 -07002912 } catch (WindowManager.BadTokenException e) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002913 // ignore
Craig Mautner42bf39e2014-02-21 16:46:22 -08002914 Log.w(TAG, appToken + " already running, starting window not displayed. " +
2915 e.getMessage());
Dianne Hackborn867ab6472010-04-29 13:28:56 -07002916 } catch (RuntimeException e) {
2917 // don't crash if something else bad happens, for example a
2918 // failure loading resources because we are loading from an app
2919 // on external storage that has been unmounted.
2920 Log.w(TAG, appToken + " failed creating starting window", e);
Mathias Jeppssond1443e92012-08-24 15:25:32 +02002921 } finally {
2922 if (view != null && view.getParent() == null) {
2923 Log.w(TAG, "view not successfully added to wm, removing view");
2924 wm.removeViewImmediate(view);
2925 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002926 }
2927
2928 return null;
2929 }
2930
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002931 /**
2932 * Preflight adding a window to the system.
RoboErik8a2cfc32014-05-16 11:19:38 -07002933 *
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002934 * Currently enforces that three window types are singletons:
2935 * <ul>
2936 * <li>STATUS_BAR_TYPE</li>
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002937 * <li>KEYGUARD_TYPE</li>
2938 * </ul>
RoboErik8a2cfc32014-05-16 11:19:38 -07002939 *
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002940 * @param win The window to be added
2941 * @param attrs Information about the window to be added
RoboErik8a2cfc32014-05-16 11:19:38 -07002942 *
Jeff Brown98365d72012-08-19 20:30:52 -07002943 * @return If ok, WindowManagerImpl.ADD_OKAY. If too many singletons,
2944 * WindowManagerImpl.ADD_MULTIPLE_SINGLETON
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002945 */
Jose Lima9546b202014-07-02 17:21:51 -07002946 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002947 public int prepareAddWindowLw(WindowState win, WindowManager.LayoutParams attrs) {
2948 switch (attrs.type) {
2949 case TYPE_STATUS_BAR:
Joe Onorato8bc6c512010-06-04 16:21:12 -04002950 mContext.enforceCallingOrSelfPermission(
2951 android.Manifest.permission.STATUS_BAR_SERVICE,
2952 "PhoneWindowManager");
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002953 if (mStatusBar != null) {
Dianne Hackbornf87d1962012-04-04 12:48:24 -07002954 if (mStatusBar.isAlive()) {
Jeff Brown98365d72012-08-19 20:30:52 -07002955 return WindowManagerGlobal.ADD_MULTIPLE_SINGLETON;
Dianne Hackbornf87d1962012-04-04 12:48:24 -07002956 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002957 }
2958 mStatusBar = win;
John Spurlock27735a42013-08-14 17:57:38 -04002959 mStatusBarController.setWindow(win);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002960 break;
Daniel Sandler8956dbb2011-04-22 07:55:02 -04002961 case TYPE_NAVIGATION_BAR:
2962 mContext.enforceCallingOrSelfPermission(
2963 android.Manifest.permission.STATUS_BAR_SERVICE,
2964 "PhoneWindowManager");
Dianne Hackbornf87d1962012-04-04 12:48:24 -07002965 if (mNavigationBar != null) {
2966 if (mNavigationBar.isAlive()) {
Jeff Brown98365d72012-08-19 20:30:52 -07002967 return WindowManagerGlobal.ADD_MULTIPLE_SINGLETON;
Dianne Hackbornf87d1962012-04-04 12:48:24 -07002968 }
2969 }
Daniel Sandler8956dbb2011-04-22 07:55:02 -04002970 mNavigationBar = win;
John Spurlock27735a42013-08-14 17:57:38 -04002971 mNavigationBarController.setWindow(win);
Craig Mautnereda67292013-04-28 13:50:14 -07002972 if (DEBUG_LAYOUT) Slog.i(TAG, "NAVIGATION BAR: " + mNavigationBar);
Daniel Sandler8956dbb2011-04-22 07:55:02 -04002973 break;
Jim Millere898ac52012-04-06 17:10:57 -07002974 case TYPE_NAVIGATION_BAR_PANEL:
Dianne Hackborn08743722009-12-21 12:16:51 -08002975 case TYPE_STATUS_BAR_PANEL:
Joe Onorato29fc2c92010-11-24 10:26:50 -08002976 case TYPE_STATUS_BAR_SUB_PANEL:
Jorim Jaggi225d3b52015-04-01 11:18:57 -07002977 case TYPE_VOICE_INTERACTION_STARTING:
Joe Onorato29fc2c92010-11-24 10:26:50 -08002978 mContext.enforceCallingOrSelfPermission(
2979 android.Manifest.permission.STATUS_BAR_SERVICE,
2980 "PhoneWindowManager");
Joe Onorato29fc2c92010-11-24 10:26:50 -08002981 break;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002982 }
Jeff Brown98365d72012-08-19 20:30:52 -07002983 return WindowManagerGlobal.ADD_OKAY;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002984 }
2985
2986 /** {@inheritDoc} */
Jose Lima9546b202014-07-02 17:21:51 -07002987 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002988 public void removeWindowLw(WindowState win) {
2989 if (mStatusBar == win) {
2990 mStatusBar = null;
John Spurlock27735a42013-08-14 17:57:38 -04002991 mStatusBarController.setWindow(null);
Jorim Jaggi73294b62016-10-26 18:02:36 -07002992 } else if (mNavigationBar == win) {
Daniel Sandler8956dbb2011-04-22 07:55:02 -04002993 mNavigationBar = null;
John Spurlock27735a42013-08-14 17:57:38 -04002994 mNavigationBarController.setWindow(null);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002995 }
2996 }
2997
2998 static final boolean PRINT_ANIM = false;
RoboErik8a2cfc32014-05-16 11:19:38 -07002999
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003000 /** {@inheritDoc} */
Craig Mautner4b71aa12012-12-27 17:20:01 -08003001 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003002 public int selectAnimationLw(WindowState win, int transit) {
3003 if (PRINT_ANIM) Log.i(TAG, "selectAnimation in " + win
3004 + ": transit=" + transit);
Dianne Hackbornf87d1962012-04-04 12:48:24 -07003005 if (win == mStatusBar) {
Jorim Jaggi380ecb82014-03-14 17:25:20 +01003006 boolean isKeyguard = (win.getAttrs().privateFlags & PRIVATE_FLAG_KEYGUARD) != 0;
Craig Mautner4b71aa12012-12-27 17:20:01 -08003007 if (transit == TRANSIT_EXIT
3008 || transit == TRANSIT_HIDE) {
Jorim Jaggi380ecb82014-03-14 17:25:20 +01003009 return isKeyguard ? -1 : R.anim.dock_top_exit;
Craig Mautner4b71aa12012-12-27 17:20:01 -08003010 } else if (transit == TRANSIT_ENTER
3011 || transit == TRANSIT_SHOW) {
Jorim Jaggi380ecb82014-03-14 17:25:20 +01003012 return isKeyguard ? -1 : R.anim.dock_top_enter;
Dianne Hackbornf87d1962012-04-04 12:48:24 -07003013 }
3014 } else if (win == mNavigationBar) {
Jorim Jaggi0d210f62015-07-10 14:24:44 -07003015 if (win.getAttrs().windowAnimations != 0) {
3016 return 0;
3017 }
Adrian Roos85d202b2016-06-02 16:27:47 -07003018 // This can be on either the bottom or the right or the left.
3019 if (mNavigationBarPosition == NAV_BAR_BOTTOM) {
Craig Mautner4b71aa12012-12-27 17:20:01 -08003020 if (transit == TRANSIT_EXIT
3021 || transit == TRANSIT_HIDE) {
Jorim Jaggi48832812016-09-06 12:38:23 -07003022 if (isKeyguardShowingAndNotOccluded()) {
3023 return R.anim.dock_bottom_exit_keyguard;
3024 } else {
3025 return R.anim.dock_bottom_exit;
3026 }
Craig Mautner4b71aa12012-12-27 17:20:01 -08003027 } else if (transit == TRANSIT_ENTER
3028 || transit == TRANSIT_SHOW) {
Dianne Hackbornf87d1962012-04-04 12:48:24 -07003029 return R.anim.dock_bottom_enter;
3030 }
Adrian Roos85d202b2016-06-02 16:27:47 -07003031 } else if (mNavigationBarPosition == NAV_BAR_RIGHT) {
Craig Mautner4b71aa12012-12-27 17:20:01 -08003032 if (transit == TRANSIT_EXIT
3033 || transit == TRANSIT_HIDE) {
Dianne Hackbornf87d1962012-04-04 12:48:24 -07003034 return R.anim.dock_right_exit;
Craig Mautner4b71aa12012-12-27 17:20:01 -08003035 } else if (transit == TRANSIT_ENTER
3036 || transit == TRANSIT_SHOW) {
Dianne Hackbornf87d1962012-04-04 12:48:24 -07003037 return R.anim.dock_right_enter;
3038 }
Adrian Roos85d202b2016-06-02 16:27:47 -07003039 } else if (mNavigationBarPosition == NAV_BAR_LEFT) {
3040 if (transit == TRANSIT_EXIT
3041 || transit == TRANSIT_HIDE) {
3042 return R.anim.dock_left_exit;
3043 } else if (transit == TRANSIT_ENTER
3044 || transit == TRANSIT_SHOW) {
3045 return R.anim.dock_left_enter;
3046 }
Dianne Hackbornf87d1962012-04-04 12:48:24 -07003047 }
Filip Gruszczynski57f76f12015-11-04 16:10:54 -08003048 } else if (win.getAttrs().type == TYPE_DOCK_DIVIDER) {
Jorim Jaggi81ba11e2016-02-03 22:04:22 -08003049 return selectDockedDividerAnimationLw(win, transit);
Craig Mautner4b71aa12012-12-27 17:20:01 -08003050 }
3051
3052 if (transit == TRANSIT_PREVIEW_DONE) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003053 if (win.hasAppShownWindows()) {
3054 if (PRINT_ANIM) Log.i(TAG, "**** STARTING EXIT");
3055 return com.android.internal.R.anim.app_starting_exit;
3056 }
Dianne Hackborn7ad44382012-10-18 17:46:00 -07003057 } else if (win.getAttrs().type == TYPE_DREAM && mDreamingLockscreen
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07003058 && transit == TRANSIT_ENTER) {
3059 // Special case: we are animating in a dream, while the keyguard
3060 // is shown. We don't want an animation on the dream, because
3061 // we need it shown immediately with the keyguard animating away
3062 // to reveal it.
3063 return -1;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003064 }
3065
3066 return 0;
3067 }
3068
Jorim Jaggi81ba11e2016-02-03 22:04:22 -08003069 private int selectDockedDividerAnimationLw(WindowState win, int transit) {
3070 int insets = mWindowManagerFuncs.getDockedDividerInsetsLw();
3071
3072 // If the divider is behind the navigation bar, don't animate.
Jorim Jaggi0cb0f722016-03-25 20:49:41 -07003073 final Rect frame = win.getFrameLw();
3074 final boolean behindNavBar = mNavigationBar != null
Adrian Roos85d202b2016-06-02 16:27:47 -07003075 && ((mNavigationBarPosition == NAV_BAR_BOTTOM
Jorim Jaggi0cb0f722016-03-25 20:49:41 -07003076 && frame.top + insets >= mNavigationBar.getFrameLw().top)
Adrian Roos85d202b2016-06-02 16:27:47 -07003077 || (mNavigationBarPosition == NAV_BAR_RIGHT
3078 && frame.left + insets >= mNavigationBar.getFrameLw().left)
3079 || (mNavigationBarPosition == NAV_BAR_LEFT
3080 && frame.right - insets <= mNavigationBar.getFrameLw().right));
Jorim Jaggi0cb0f722016-03-25 20:49:41 -07003081 final boolean landscape = frame.height() > frame.width();
3082 final boolean offscreenLandscape = landscape && (frame.right - insets <= 0
3083 || frame.left + insets >= win.getDisplayFrameLw().right);
3084 final boolean offscreenPortrait = !landscape && (frame.top - insets <= 0
3085 || frame.bottom + insets >= win.getDisplayFrameLw().bottom);
3086 final boolean offscreen = offscreenLandscape || offscreenPortrait;
3087 if (behindNavBar || offscreen) {
Jorim Jaggi81ba11e2016-02-03 22:04:22 -08003088 return 0;
3089 }
3090 if (transit == TRANSIT_ENTER || transit == TRANSIT_SHOW) {
3091 return R.anim.fade_in;
3092 } else if (transit == TRANSIT_EXIT) {
3093 return R.anim.fade_out;
3094 } else {
3095 return 0;
3096 }
3097 }
3098
Craig Mautner3c174372013-02-21 17:54:37 -08003099 @Override
3100 public void selectRotationAnimationLw(int anim[]) {
3101 if (PRINT_ANIM) Slog.i(TAG, "selectRotationAnimation mTopFullscreen="
3102 + mTopFullscreenOpaqueWindowState + " rotationAnimation="
3103 + (mTopFullscreenOpaqueWindowState == null ?
3104 "0" : mTopFullscreenOpaqueWindowState.getAttrs().rotationAnimation));
Robert Carrfd10cd12016-06-29 16:41:50 -07003105 if (mTopFullscreenOpaqueWindowState != null) {
3106 int animationHint = mTopFullscreenOpaqueWindowState.getRotationAnimationHint();
3107 if (animationHint < 0 && mTopIsFullscreen) {
3108 animationHint = mTopFullscreenOpaqueWindowState.getAttrs().rotationAnimation;
3109 }
3110 switch (animationHint) {
Craig Mautner3c174372013-02-21 17:54:37 -08003111 case ROTATION_ANIMATION_CROSSFADE:
Robert Carr57d9fbd2016-08-15 12:00:35 -07003112 case ROTATION_ANIMATION_SEAMLESS: // Crossfade is fallback for seamless.
Craig Mautner3c174372013-02-21 17:54:37 -08003113 anim[0] = R.anim.rotation_animation_xfade_exit;
3114 anim[1] = R.anim.rotation_animation_enter;
3115 break;
3116 case ROTATION_ANIMATION_JUMPCUT:
3117 anim[0] = R.anim.rotation_animation_jump_exit;
3118 anim[1] = R.anim.rotation_animation_enter;
3119 break;
3120 case ROTATION_ANIMATION_ROTATE:
3121 default:
3122 anim[0] = anim[1] = 0;
3123 break;
3124 }
3125 } else {
3126 anim[0] = anim[1] = 0;
3127 }
3128 }
3129
3130 @Override
3131 public boolean validateRotationAnimationLw(int exitAnimId, int enterAnimId,
3132 boolean forceDefault) {
3133 switch (exitAnimId) {
3134 case R.anim.rotation_animation_xfade_exit:
3135 case R.anim.rotation_animation_jump_exit:
3136 // These are the only cases that matter.
3137 if (forceDefault) {
3138 return false;
3139 }
3140 int anim[] = new int[2];
3141 selectRotationAnimationLw(anim);
3142 return (exitAnimId == anim[0] && enterAnimId == anim[1]);
3143 default:
3144 return true;
3145 }
3146 }
3147
3148 @Override
Jorim Jaggife762342016-10-13 14:33:27 +02003149 public Animation createHiddenByKeyguardExit(boolean onWallpaper,
Jorim Jaggi84a3e7a2014-08-13 17:58:58 +02003150 boolean goingToNotificationShade) {
3151 if (goingToNotificationShade) {
3152 return AnimationUtils.loadAnimation(mContext, R.anim.lock_screen_behind_enter_fade_in);
Craig Mautnerb8340802014-11-04 15:32:57 -08003153 }
Craig Mautner276a6eb2014-11-04 15:32:57 -08003154
3155 AnimationSet set = (AnimationSet) AnimationUtils.loadAnimation(mContext, onWallpaper ?
3156 R.anim.lock_screen_behind_enter_wallpaper :
3157 R.anim.lock_screen_behind_enter);
3158
3159 // TODO: Use XML interpolators when we have log interpolators available in XML.
3160 final List<Animation> animations = set.getAnimations();
3161 for (int i = animations.size() - 1; i >= 0; --i) {
3162 animations.get(i).setInterpolator(mLogDecelerateInterpolator);
3163 }
3164
3165 return set;
Jorim Jaggi76a16232014-08-08 17:00:47 +02003166 }
3167
3168
3169 @Override
Jorim Jaggife762342016-10-13 14:33:27 +02003170 public Animation createKeyguardWallpaperExit(boolean goingToNotificationShade) {
Jorim Jaggi84a3e7a2014-08-13 17:58:58 +02003171 if (goingToNotificationShade) {
3172 return null;
3173 } else {
3174 return AnimationUtils.loadAnimation(mContext, R.anim.lock_screen_wallpaper_exit);
3175 }
Dianne Hackborn01ad2f42009-09-24 19:24:56 -07003176 }
John Spurlockc8b46ca2013-04-08 12:59:26 -04003177
3178 private static void awakenDreams() {
3179 IDreamManager dreamManager = getDreamManager();
3180 if (dreamManager != null) {
3181 try {
3182 dreamManager.awaken();
3183 } catch (RemoteException e) {
3184 // fine, stay asleep then
3185 }
3186 }
3187 }
3188
3189 static IDreamManager getDreamManager() {
3190 return IDreamManager.Stub.asInterface(
3191 ServiceManager.checkService(DreamService.DREAM_SERVICE));
3192 }
3193
Tyler Gunnef9f6f92014-09-12 22:16:17 -07003194 TelecomManager getTelecommService() {
3195 return (TelecomManager) mContext.getSystemService(Context.TELECOM_SERVICE);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003196 }
3197
Jeff Brown4d396052010-10-29 21:50:21 -07003198 static IAudioService getAudioService() {
3199 IAudioService audioService = IAudioService.Stub.asInterface(
3200 ServiceManager.checkService(Context.AUDIO_SERVICE));
3201 if (audioService == null) {
3202 Log.w(TAG, "Unable to find IAudioService interface.");
3203 }
3204 return audioService;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003205 }
3206
3207 boolean keyguardOn() {
Jim Millerab954542014-10-10 18:21:49 -07003208 return isKeyguardShowingAndNotOccluded() || inKeyguardRestrictedKeyInputMode();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003209 }
3210
3211 private static final int[] WINDOW_TYPES_WHERE_HOME_DOESNT_WORK = {
3212 WindowManager.LayoutParams.TYPE_SYSTEM_ALERT,
3213 WindowManager.LayoutParams.TYPE_SYSTEM_ERROR,
3214 };
3215
3216 /** {@inheritDoc} */
Jeff Brown00fa7bd2010-07-02 15:37:36 -07003217 @Override
Jeff Brownd5bb82d2011-10-12 13:57:59 -07003218 public long interceptKeyBeforeDispatching(WindowState win, KeyEvent event, int policyFlags) {
Jeff Brown00fa7bd2010-07-02 15:37:36 -07003219 final boolean keyguardOn = keyguardOn();
Jeff Brown1f245102010-11-18 20:53:46 -08003220 final int keyCode = event.getKeyCode();
3221 final int repeatCount = event.getRepeatCount();
3222 final int metaState = event.getMetaState();
Jeff Brownd5bb82d2011-10-12 13:57:59 -07003223 final int flags = event.getFlags();
Jeff Brown1f245102010-11-18 20:53:46 -08003224 final boolean down = event.getAction() == KeyEvent.ACTION_DOWN;
3225 final boolean canceled = event.isCanceled();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003226
Jeff Brown40013652012-05-16 21:22:36 -07003227 if (DEBUG_INPUT) {
Jeff Brown00fa7bd2010-07-02 15:37:36 -07003228 Log.d(TAG, "interceptKeyTi keyCode=" + keyCode + " down=" + down + " repeatCount="
Jeff Brownfd23e3e2012-05-09 13:34:28 -07003229 + repeatCount + " keyguardOn=" + keyguardOn + " mHomePressed=" + mHomePressed
3230 + " canceled=" + canceled);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003231 }
3232
Jeff Brownd5bb82d2011-10-12 13:57:59 -07003233 // If we think we might have a volume down & power key chord on the way
3234 // but we're not sure, then tell the dispatcher to wait a little while and
3235 // try again later before dispatching.
Christopher Tatee90585f2012-03-05 18:56:25 -08003236 if (mScreenshotChordEnabled && (flags & KeyEvent.FLAG_FALLBACK) == 0) {
Jeff Brown13f00f02014-10-31 14:45:50 -07003237 if (mScreenshotChordVolumeDownKeyTriggered && !mScreenshotChordPowerKeyTriggered) {
Jeff Brownd5bb82d2011-10-12 13:57:59 -07003238 final long now = SystemClock.uptimeMillis();
Jeff Brown13f00f02014-10-31 14:45:50 -07003239 final long timeoutTime = mScreenshotChordVolumeDownKeyTime
3240 + SCREENSHOT_CHORD_DEBOUNCE_DELAY_MILLIS;
Jeff Brownd5bb82d2011-10-12 13:57:59 -07003241 if (now < timeoutTime) {
3242 return timeoutTime - now;
3243 }
3244 }
3245 if (keyCode == KeyEvent.KEYCODE_VOLUME_DOWN
Jeff Brown13f00f02014-10-31 14:45:50 -07003246 && mScreenshotChordVolumeDownKeyConsumed) {
Jeff Brownd5bb82d2011-10-12 13:57:59 -07003247 if (!down) {
Jeff Brown13f00f02014-10-31 14:45:50 -07003248 mScreenshotChordVolumeDownKeyConsumed = false;
Jeff Brownd5bb82d2011-10-12 13:57:59 -07003249 }
3250 return -1;
3251 }
3252 }
3253
Michael Wright6a62e552014-06-03 19:19:48 -07003254 // Cancel any pending meta actions if we see any other keys being pressed between the down
3255 // of the meta key and its corresponding up.
Michael Wright251e35d2014-08-22 15:40:27 -07003256 if (mPendingMetaAction && !KeyEvent.isMetaKey(keyCode)) {
Michael Wright6a62e552014-06-03 19:19:48 -07003257 mPendingMetaAction = false;
3258 }
Andrii Kulian112d0562016-03-08 10:44:22 -08003259 // Any key that is not Alt or Meta cancels Caps Lock combo tracking.
3260 if (mPendingCapsLockToggle && !KeyEvent.isMetaKey(keyCode) && !KeyEvent.isAltKey(keyCode)) {
3261 mPendingCapsLockToggle = false;
3262 }
Michael Wright6a62e552014-06-03 19:19:48 -07003263
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003264 // First we always handle the home key here, so applications
3265 // can never break it, although if keyguard is on, we do let
3266 // it handle it, because that gives us the correct 5 second
3267 // timeout.
Jeff Brown00fa7bd2010-07-02 15:37:36 -07003268 if (keyCode == KeyEvent.KEYCODE_HOME) {
Michael Jurka7f2668c2012-03-27 07:49:52 -07003269
Jeff Brown49ed71d2010-12-06 17:13:33 -08003270 // If we have released the home key, and didn't do anything else
3271 // while it was pressed, then it is time to go home!
Michael Jurka7f2668c2012-03-27 07:49:52 -07003272 if (!down) {
Jeff Browncaca8812013-05-09 13:34:33 -07003273 cancelPreloadRecentApps();
3274
Jeff Brown49ed71d2010-12-06 17:13:33 -08003275 mHomePressed = false;
Jeff Browncaca8812013-05-09 13:34:33 -07003276 if (mHomeConsumed) {
3277 mHomeConsumed = false;
Michael Jurka7f2668c2012-03-27 07:49:52 -07003278 return -1;
Jeff Brown49ed71d2010-12-06 17:13:33 -08003279 }
Jeff Browncaca8812013-05-09 13:34:33 -07003280
3281 if (canceled) {
3282 Log.i(TAG, "Ignoring HOME; event canceled.");
3283 return -1;
3284 }
3285
Jeff Browncaca8812013-05-09 13:34:33 -07003286 // Delay handling home if a double-tap is possible.
3287 if (mDoubleTapOnHomeBehavior != DOUBLE_TAP_HOME_NOTHING) {
3288 mHandler.removeCallbacks(mHomeDoubleTapTimeoutRunnable); // just in case
3289 mHomeDoubleTapPending = true;
3290 mHandler.postDelayed(mHomeDoubleTapTimeoutRunnable,
3291 ViewConfiguration.getDoubleTapTimeout());
3292 return -1;
3293 }
3294
Jeff Brown13f00f02014-10-31 14:45:50 -07003295 handleShortPressOnHome();
Jeff Browncaca8812013-05-09 13:34:33 -07003296 return -1;
Jeff Brown49ed71d2010-12-06 17:13:33 -08003297 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003298
3299 // If a system window has focus, then it doesn't make sense
3300 // right now to interact with applications.
3301 WindowManager.LayoutParams attrs = win != null ? win.getAttrs() : null;
3302 if (attrs != null) {
3303 final int type = attrs.type;
Jorim Jaggi73294b62016-10-26 18:02:36 -07003304 if (type == TYPE_KEYGUARD_DIALOG
Jorim Jaggi380ecb82014-03-14 17:25:20 +01003305 || (attrs.privateFlags & PRIVATE_FLAG_KEYGUARD) != 0) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003306 // the "app" is keyguard, so give it the key
Jeff Brownd5bb82d2011-10-12 13:57:59 -07003307 return 0;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003308 }
3309 final int typeCount = WINDOW_TYPES_WHERE_HOME_DOESNT_WORK.length;
3310 for (int i=0; i<typeCount; i++) {
3311 if (type == WINDOW_TYPES_WHERE_HOME_DOESNT_WORK[i]) {
3312 // don't do anything, but also don't pass it to the app
Jeff Brownd5bb82d2011-10-12 13:57:59 -07003313 return -1;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003314 }
3315 }
3316 }
Jeff Browncaca8812013-05-09 13:34:33 -07003317
3318 // Remember that home is pressed and handle special actions.
3319 if (repeatCount == 0) {
3320 mHomePressed = true;
3321 if (mHomeDoubleTapPending) {
3322 mHomeDoubleTapPending = false;
3323 mHandler.removeCallbacks(mHomeDoubleTapTimeoutRunnable);
3324 handleDoubleTapOnHome();
3325 } else if (mLongPressOnHomeBehavior == LONG_PRESS_HOME_RECENT_SYSTEM_UI
3326 || mDoubleTapOnHomeBehavior == DOUBLE_TAP_HOME_RECENT_SYSTEM_UI) {
3327 preloadRecentApps();
Michael Jurka7f2668c2012-03-27 07:49:52 -07003328 }
Jeff Browncaca8812013-05-09 13:34:33 -07003329 } else if ((event.getFlags() & KeyEvent.FLAG_LONG_PRESS) != 0) {
3330 if (!keyguardOn) {
Jaewan Kim76b7d0d2016-02-12 19:01:02 +09003331 handleLongPressOnHome(event.getDeviceId());
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003332 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003333 }
Jeff Brownd5bb82d2011-10-12 13:57:59 -07003334 return -1;
Jeff Brown00fa7bd2010-07-02 15:37:36 -07003335 } else if (keyCode == KeyEvent.KEYCODE_MENU) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003336 // Hijack modified menu keys for debugging features
3337 final int chordBug = KeyEvent.META_SHIFT_ON;
3338
3339 if (down && repeatCount == 0) {
Jeff Brown00fa7bd2010-07-02 15:37:36 -07003340 if (mEnableShiftMenuBugReports && (metaState & chordBug) == chordBug) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003341 Intent intent = new Intent(Intent.ACTION_BUG_REPORT);
Dianne Hackborn5ac72a22012-08-29 18:32:08 -07003342 mContext.sendOrderedBroadcastAsUser(intent, UserHandle.CURRENT,
3343 null, null, null, 0, null, null);
Jeff Brownd5bb82d2011-10-12 13:57:59 -07003344 return -1;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003345 }
3346 }
Jeff Brown00fa7bd2010-07-02 15:37:36 -07003347 } else if (keyCode == KeyEvent.KEYCODE_SEARCH) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003348 if (down) {
3349 if (repeatCount == 0) {
Jeff Brownfd23e3e2012-05-09 13:34:28 -07003350 mSearchKeyShortcutPending = true;
3351 mConsumeSearchKeyUp = false;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003352 }
Jeff Brownfd23e3e2012-05-09 13:34:28 -07003353 } else {
3354 mSearchKeyShortcutPending = false;
3355 if (mConsumeSearchKeyUp) {
3356 mConsumeSearchKeyUp = false;
Jeff Brownd5bb82d2011-10-12 13:57:59 -07003357 return -1;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003358 }
3359 }
Jeff Brownd5bb82d2011-10-12 13:57:59 -07003360 return 0;
Jeff Brown49ed71d2010-12-06 17:13:33 -08003361 } else if (keyCode == KeyEvent.KEYCODE_APP_SWITCH) {
Michael Wrightc9ebea72013-01-16 19:25:02 -08003362 if (!keyguardOn) {
Jeff Browncaca8812013-05-09 13:34:33 -07003363 if (down && repeatCount == 0) {
3364 preloadRecentApps();
3365 } else if (!down) {
3366 toggleRecentApps();
Michael Wrightc9ebea72013-01-16 19:25:02 -08003367 }
Jeff Brown49ed71d2010-12-06 17:13:33 -08003368 }
Jeff Brownd5bb82d2011-10-12 13:57:59 -07003369 return -1;
Jun Mukaid21b3c82015-04-23 14:09:34 -07003370 } else if (keyCode == KeyEvent.KEYCODE_N && event.isMetaPressed()) {
3371 if (down) {
3372 IStatusBarService service = getStatusBarService();
3373 if (service != null) {
3374 try {
3375 service.expandNotificationsPanel();
3376 } catch (RemoteException e) {
3377 // do nothing.
3378 }
3379 }
3380 }
Muyuan Li6ca619f2016-03-08 13:30:42 -08003381 } else if (keyCode == KeyEvent.KEYCODE_S && event.isMetaPressed()
3382 && event.isCtrlPressed()) {
3383 if (down && repeatCount == 0) {
3384 int type = event.isShiftPressed() ? TAKE_SCREENSHOT_SELECTED_REGION
3385 : TAKE_SCREENSHOT_FULLSCREEN;
3386 mScreenshotRunnable.setScreenshotType(type);
3387 mHandler.post(mScreenshotRunnable);
3388 return -1;
3389 }
Clara Bayarrif2debb12015-07-10 14:47:17 +01003390 } else if (keyCode == KeyEvent.KEYCODE_SLASH && event.isMetaPressed()) {
Andrei Stingaceanu002f7122016-03-30 12:22:05 +01003391 if (down && repeatCount == 0 && !isKeyguardLocked()) {
3392 toggleKeyboardShortcutsMenu(event.getDeviceId());
Clara Bayarrif2debb12015-07-10 14:47:17 +01003393 }
Jeff Brownde7a8ea2012-06-13 18:28:57 -07003394 } else if (keyCode == KeyEvent.KEYCODE_ASSIST) {
3395 if (down) {
3396 if (repeatCount == 0) {
3397 mAssistKeyLongPressed = false;
3398 } else if (repeatCount == 1) {
3399 mAssistKeyLongPressed = true;
3400 if (!keyguardOn) {
3401 launchAssistLongPressAction();
3402 }
3403 }
3404 } else {
3405 if (mAssistKeyLongPressed) {
3406 mAssistKeyLongPressed = false;
3407 } else {
3408 if (!keyguardOn) {
Tim Kilbourn0e5f1102015-06-05 16:18:09 -07003409 launchAssistAction(null, event.getDeviceId());
Jeff Brownde7a8ea2012-06-13 18:28:57 -07003410 }
3411 }
3412 }
3413 return -1;
Michael Wrightdc63f7b2014-08-21 19:05:21 -07003414 } else if (keyCode == KeyEvent.KEYCODE_VOICE_ASSIST) {
3415 if (!down) {
3416 Intent voiceIntent;
Michael Wright869a67c2014-08-26 19:33:06 -07003417 if (!keyguardOn) {
Michael Wrightdc63f7b2014-08-21 19:05:21 -07003418 voiceIntent = new Intent(RecognizerIntent.ACTION_WEB_SEARCH);
3419 } else {
Dianne Hackbornb6683c42015-06-18 17:40:33 -07003420 IDeviceIdleController dic = IDeviceIdleController.Stub.asInterface(
3421 ServiceManager.getService(Context.DEVICE_IDLE_CONTROLLER));
3422 if (dic != null) {
3423 try {
3424 dic.exitIdle("voice-search");
3425 } catch (RemoteException e) {
3426 }
3427 }
Michael Wrightdc63f7b2014-08-21 19:05:21 -07003428 voiceIntent = new Intent(RecognizerIntent.ACTION_VOICE_SEARCH_HANDS_FREE);
Michael Wright869a67c2014-08-26 19:33:06 -07003429 voiceIntent.putExtra(RecognizerIntent.EXTRA_SECURE, true);
Michael Wrightdc63f7b2014-08-21 19:05:21 -07003430 }
Bart Sears8b1c27c2015-03-18 23:51:02 +00003431 startActivityAsUser(voiceIntent, UserHandle.CURRENT_OR_SELF);
Michael Wrightdc63f7b2014-08-21 19:05:21 -07003432 }
Jeff Sharkey2991fa32012-12-05 18:06:43 -08003433 } else if (keyCode == KeyEvent.KEYCODE_SYSRQ) {
3434 if (down && repeatCount == 0) {
Muyuan Li6ca619f2016-03-08 13:30:42 -08003435 mScreenshotRunnable.setScreenshotType(TAKE_SCREENSHOT_FULLSCREEN);
Jeff Sharkey2991fa32012-12-05 18:06:43 -08003436 mHandler.post(mScreenshotRunnable);
3437 }
3438 return -1;
Michael Wrightb854e242013-02-05 17:54:02 -08003439 } else if (keyCode == KeyEvent.KEYCODE_BRIGHTNESS_UP
3440 || keyCode == KeyEvent.KEYCODE_BRIGHTNESS_DOWN) {
3441 if (down) {
3442 int direction = keyCode == KeyEvent.KEYCODE_BRIGHTNESS_UP ? 1 : -1;
3443
3444 // Disable autobrightness if it's on
3445 int auto = Settings.System.getIntForUser(
3446 mContext.getContentResolver(),
3447 Settings.System.SCREEN_BRIGHTNESS_MODE,
3448 Settings.System.SCREEN_BRIGHTNESS_MODE_MANUAL,
3449 UserHandle.USER_CURRENT_OR_SELF);
3450 if (auto != 0) {
3451 Settings.System.putIntForUser(mContext.getContentResolver(),
3452 Settings.System.SCREEN_BRIGHTNESS_MODE,
3453 Settings.System.SCREEN_BRIGHTNESS_MODE_MANUAL,
3454 UserHandle.USER_CURRENT_OR_SELF);
3455 }
3456
3457 int min = mPowerManager.getMinimumScreenBrightnessSetting();
3458 int max = mPowerManager.getMaximumScreenBrightnessSetting();
3459 int step = (max - min + BRIGHTNESS_STEPS - 1) / BRIGHTNESS_STEPS * direction;
3460 int brightness = Settings.System.getIntForUser(mContext.getContentResolver(),
3461 Settings.System.SCREEN_BRIGHTNESS,
3462 mPowerManager.getDefaultScreenBrightnessSetting(),
3463 UserHandle.USER_CURRENT_OR_SELF);
3464 brightness += step;
3465 // Make sure we don't go beyond the limits.
3466 brightness = Math.min(max, brightness);
3467 brightness = Math.max(min, brightness);
3468
3469 Settings.System.putIntForUser(mContext.getContentResolver(),
3470 Settings.System.SCREEN_BRIGHTNESS, brightness,
3471 UserHandle.USER_CURRENT_OR_SELF);
Bart Sears8b1c27c2015-03-18 23:51:02 +00003472 startActivityAsUser(new Intent(Intent.ACTION_SHOW_BRIGHTNESS_DIALOG),
Alan Viverette5a399492014-07-14 16:19:38 -07003473 UserHandle.CURRENT_OR_SELF);
Michael Wrightb854e242013-02-05 17:54:02 -08003474 }
3475 return -1;
Jaewan Kim765487f2016-01-12 14:45:42 +09003476 } else if (keyCode == KeyEvent.KEYCODE_VOLUME_UP
3477 || keyCode == KeyEvent.KEYCODE_VOLUME_DOWN
3478 || keyCode == KeyEvent.KEYCODE_VOLUME_MUTE) {
3479 if (mUseTvRouting) {
3480 // On TVs volume keys never go to the foreground app.
3481 dispatchDirectAudioEvent(event);
3482 return -1;
3483 }
Muyuan Li94ce94e2016-02-24 16:20:54 -08003484 }
3485
Andrii Kulian112d0562016-03-08 10:44:22 -08003486 // Toggle Caps Lock on META-ALT.
3487 boolean actionTriggered = false;
3488 if (KeyEvent.isModifierKey(keyCode)) {
3489 if (!mPendingCapsLockToggle) {
3490 // Start tracking meta state for combo.
3491 mInitialMetaState = mMetaState;
3492 mPendingCapsLockToggle = true;
3493 } else if (event.getAction() == KeyEvent.ACTION_UP) {
3494 int altOnMask = mMetaState & KeyEvent.META_ALT_MASK;
3495 int metaOnMask = mMetaState & KeyEvent.META_META_MASK;
3496
3497 // Check for Caps Lock toggle
3498 if ((metaOnMask != 0) && (altOnMask != 0)) {
3499 // Check if nothing else is pressed
3500 if (mInitialMetaState == (mMetaState ^ (altOnMask | metaOnMask))) {
3501 // Handle Caps Lock Toggle
3502 mInputManagerInternal.toggleCapsLock(event.getDeviceId());
3503 actionTriggered = true;
3504 }
3505 }
3506
3507 // Always stop tracking when key goes up.
3508 mPendingCapsLockToggle = false;
3509 }
3510 }
3511 // Store current meta state to be able to evaluate it later.
3512 mMetaState = metaState;
3513
3514 if (actionTriggered) {
3515 return -1;
3516 }
3517
Muyuan Li94ce94e2016-02-24 16:20:54 -08003518 if (KeyEvent.isMetaKey(keyCode)) {
Michael Wright6a62e552014-06-03 19:19:48 -07003519 if (down) {
3520 mPendingMetaAction = true;
3521 } else if (mPendingMetaAction) {
Tim Kilbourn0e5f1102015-06-05 16:18:09 -07003522 launchAssistAction(Intent.EXTRA_ASSIST_INPUT_HINT_KEYBOARD, event.getDeviceId());
Michael Wright6a62e552014-06-03 19:19:48 -07003523 }
3524 return -1;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003525 }
Jeff Browncaab4d02010-12-09 22:13:41 -08003526
Jeff Brownc1fb48d2010-12-08 16:52:09 -08003527 // Shortcuts are invoked through Search+key, so intercept those here
Jeff Browncaab4d02010-12-09 22:13:41 -08003528 // Any printing key that is chorded with Search should be consumed
3529 // even if no shortcut was invoked. This prevents text from being
3530 // inadvertently inserted when using a keyboard that has built-in macro
3531 // shortcut keys (that emit Search+x) and some of them are not registered.
Jeff Brownfd23e3e2012-05-09 13:34:28 -07003532 if (mSearchKeyShortcutPending) {
Jeff Browncaab4d02010-12-09 22:13:41 -08003533 final KeyCharacterMap kcm = event.getKeyCharacterMap();
3534 if (kcm.isPrintingKey(keyCode)) {
Jeff Brownfd23e3e2012-05-09 13:34:28 -07003535 mConsumeSearchKeyUp = true;
3536 mSearchKeyShortcutPending = false;
Jeff Browncaab4d02010-12-09 22:13:41 -08003537 if (down && repeatCount == 0 && !keyguardOn) {
3538 Intent shortcutIntent = mShortcutManager.getIntent(kcm, keyCode, metaState);
3539 if (shortcutIntent != null) {
3540 shortcutIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
Jeff Brownf0a3cc52011-01-26 18:42:46 -08003541 try {
Bart Sears8b1c27c2015-03-18 23:51:02 +00003542 startActivityAsUser(shortcutIntent, UserHandle.CURRENT);
Andrei Stingaceanu0bf096f2016-04-14 18:11:57 +01003543 dismissKeyboardShortcutsMenu();
Jeff Brownf0a3cc52011-01-26 18:42:46 -08003544 } catch (ActivityNotFoundException ex) {
3545 Slog.w(TAG, "Dropping shortcut key combination because "
3546 + "the activity to which it is registered was not found: "
Jeff Brownfd23e3e2012-05-09 13:34:28 -07003547 + "SEARCH+" + KeyEvent.keyCodeToString(keyCode), ex);
Jeff Brownf0a3cc52011-01-26 18:42:46 -08003548 }
Jeff Browncaab4d02010-12-09 22:13:41 -08003549 } else {
3550 Slog.i(TAG, "Dropping unregistered shortcut key combination: "
Jeff Brownfd23e3e2012-05-09 13:34:28 -07003551 + "SEARCH+" + KeyEvent.keyCodeToString(keyCode));
Jeff Brown49ed71d2010-12-06 17:13:33 -08003552 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003553 }
Jeff Brownd5bb82d2011-10-12 13:57:59 -07003554 return -1;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003555 }
3556 }
3557
Jeff Brown68b909d2011-12-07 16:36:01 -08003558 // Invoke shortcuts using Meta.
Jeff Brown602ab322012-05-16 13:33:47 -07003559 if (down && repeatCount == 0 && !keyguardOn
Jeff Brown68b909d2011-12-07 16:36:01 -08003560 && (metaState & KeyEvent.META_META_ON) != 0) {
3561 final KeyCharacterMap kcm = event.getKeyCharacterMap();
Jeff Brown602ab322012-05-16 13:33:47 -07003562 if (kcm.isPrintingKey(keyCode)) {
3563 Intent shortcutIntent = mShortcutManager.getIntent(kcm, keyCode,
3564 metaState & ~(KeyEvent.META_META_ON
3565 | KeyEvent.META_META_LEFT_ON | KeyEvent.META_META_RIGHT_ON));
3566 if (shortcutIntent != null) {
3567 shortcutIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
3568 try {
Bart Sears8b1c27c2015-03-18 23:51:02 +00003569 startActivityAsUser(shortcutIntent, UserHandle.CURRENT);
Andrei Stingaceanu0bf096f2016-04-14 18:11:57 +01003570 dismissKeyboardShortcutsMenu();
Jeff Brown602ab322012-05-16 13:33:47 -07003571 } catch (ActivityNotFoundException ex) {
3572 Slog.w(TAG, "Dropping shortcut key combination because "
3573 + "the activity to which it is registered was not found: "
3574 + "META+" + KeyEvent.keyCodeToString(keyCode), ex);
3575 }
3576 return -1;
Jeff Brown68b909d2011-12-07 16:36:01 -08003577 }
Jeff Brown68b909d2011-12-07 16:36:01 -08003578 }
3579 }
3580
Jeff Brown6651a632011-11-28 12:59:11 -08003581 // Handle application launch keys.
Jeff Brown602ab322012-05-16 13:33:47 -07003582 if (down && repeatCount == 0 && !keyguardOn) {
Jeff Brown6651a632011-11-28 12:59:11 -08003583 String category = sApplicationLaunchKeyCategories.get(keyCode);
3584 if (category != null) {
Dianne Hackbornf5b86712011-12-05 17:42:41 -08003585 Intent intent = Intent.makeMainSelectorActivity(Intent.ACTION_MAIN, category);
Jeff Brown6651a632011-11-28 12:59:11 -08003586 intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
3587 try {
Bart Sears8b1c27c2015-03-18 23:51:02 +00003588 startActivityAsUser(intent, UserHandle.CURRENT);
Andrei Stingaceanu0bf096f2016-04-14 18:11:57 +01003589 dismissKeyboardShortcutsMenu();
Jeff Brown6651a632011-11-28 12:59:11 -08003590 } catch (ActivityNotFoundException ex) {
3591 Slog.w(TAG, "Dropping application launch key because "
3592 + "the activity to which it is registered was not found: "
3593 + "keyCode=" + keyCode + ", category=" + category, ex);
3594 }
Jeff Brown68b909d2011-12-07 16:36:01 -08003595 return -1;
Jeff Brown6651a632011-11-28 12:59:11 -08003596 }
3597 }
3598
Michael Wright61c46752014-08-21 16:57:33 -07003599 // Display task switcher for ALT-TAB.
Jeff Brown68b909d2011-12-07 16:36:01 -08003600 if (down && repeatCount == 0 && keyCode == KeyEvent.KEYCODE_TAB) {
Michael Wrightd847ad52015-10-24 13:24:15 +01003601 if (mRecentAppsHeldModifiers == 0 && !keyguardOn && isUserSetupComplete()) {
Jeff Brown68b909d2011-12-07 16:36:01 -08003602 final int shiftlessModifiers = event.getModifiers() & ~KeyEvent.META_SHIFT_MASK;
Michael Wright61c46752014-08-21 16:57:33 -07003603 if (KeyEvent.metaStateHasModifiers(shiftlessModifiers, KeyEvent.META_ALT_ON)) {
Winson Chung1e8d71b2014-05-16 17:05:22 -07003604 mRecentAppsHeldModifiers = shiftlessModifiers;
Winson14db3622016-05-09 13:34:07 -07003605 showRecentApps(true, false);
Jeff Brown68b909d2011-12-07 16:36:01 -08003606 return -1;
3607 }
3608 }
Winson Chung1e8d71b2014-05-16 17:05:22 -07003609 } else if (!down && mRecentAppsHeldModifiers != 0
3610 && (metaState & mRecentAppsHeldModifiers) == 0) {
3611 mRecentAppsHeldModifiers = 0;
Winson Chungcdcd4872014-08-05 18:00:13 -07003612 hideRecentApps(true, false);
Jeff Brown68b909d2011-12-07 16:36:01 -08003613 }
3614
Yohei Yukawaae61f712015-12-09 13:00:10 -08003615 // Handle input method switching.
Jeff Browncf39bdf2012-05-18 14:41:19 -07003616 if (down && repeatCount == 0
3617 && (keyCode == KeyEvent.KEYCODE_LANGUAGE_SWITCH
3618 || (keyCode == KeyEvent.KEYCODE_SPACE
Yohei Yukawaae61f712015-12-09 13:00:10 -08003619 && (metaState & KeyEvent.META_META_MASK) != 0))) {
3620 final boolean forwardDirection = (metaState & KeyEvent.META_SHIFT_MASK) == 0;
3621 mWindowManagerFuncs.switchInputMethod(forwardDirection);
Jeff Browncf39bdf2012-05-18 14:41:19 -07003622 return -1;
3623 }
3624 if (mLanguageSwitchKeyPressed && !down
3625 && (keyCode == KeyEvent.KEYCODE_LANGUAGE_SWITCH
3626 || keyCode == KeyEvent.KEYCODE_SPACE)) {
3627 mLanguageSwitchKeyPressed = false;
3628 return -1;
3629 }
3630
Jeff Brown13f00f02014-10-31 14:45:50 -07003631 if (isValidGlobalKey(keyCode)
3632 && mGlobalKeyManager.handleGlobalKey(mContext, keyCode, event)) {
Justin Kohd378ad72013-04-01 12:18:26 -07003633 return -1;
3634 }
3635
Muyuan Li94ce94e2016-02-24 16:20:54 -08003636 if (down) {
Jim Millere4044bb2016-05-10 18:38:25 -07003637 long shortcutCode = keyCode;
Muyuan Li94ce94e2016-02-24 16:20:54 -08003638 if (event.isCtrlPressed()) {
3639 shortcutCode |= ((long) KeyEvent.META_CTRL_ON) << Integer.SIZE;
3640 }
3641
3642 if (event.isAltPressed()) {
3643 shortcutCode |= ((long) KeyEvent.META_ALT_ON) << Integer.SIZE;
3644 }
3645
3646 if (event.isShiftPressed()) {
3647 shortcutCode |= ((long) KeyEvent.META_SHIFT_ON) << Integer.SIZE;
3648 }
3649
3650 if (event.isMetaPressed()) {
3651 shortcutCode |= ((long) KeyEvent.META_META_ON) << Integer.SIZE;
3652 }
3653
3654 IShortcutService shortcutService = mShortcutKeyServices.get(shortcutCode);
3655 if (shortcutService != null) {
3656 try {
Muyuan Lib5dd0492016-04-14 13:22:20 -07003657 if (isUserSetupComplete()) {
3658 shortcutService.notifyShortcutKeyPressed(shortcutCode);
3659 }
Muyuan Li94ce94e2016-02-24 16:20:54 -08003660 } catch (RemoteException e) {
3661 mShortcutKeyServices.delete(shortcutCode);
3662 }
3663 return -1;
3664 }
3665 }
3666
Michael Wright6a62e552014-06-03 19:19:48 -07003667 // Reserve all the META modifier combos for system behavior
Michael Wrightce0c13a2014-07-30 10:49:21 -07003668 if ((metaState & KeyEvent.META_META_ON) != 0) {
Michael Wright6a62e552014-06-03 19:19:48 -07003669 return -1;
3670 }
3671
Jeff Brown68b909d2011-12-07 16:36:01 -08003672 // Let the application handle the key.
Jeff Brownd5bb82d2011-10-12 13:57:59 -07003673 return 0;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003674 }
3675
Jeff Brown3915bb82010-11-05 15:02:16 -07003676 /** {@inheritDoc} */
3677 @Override
Jeff Brown49ed71d2010-12-06 17:13:33 -08003678 public KeyEvent dispatchUnhandledKey(WindowState win, KeyEvent event, int policyFlags) {
Jeff Brown54875002011-04-06 15:33:01 -07003679 // Note: This method is only called if the initial down was unhandled.
Jeff Brown40013652012-05-16 21:22:36 -07003680 if (DEBUG_INPUT) {
Jeff Brown1f245102010-11-18 20:53:46 -08003681 Slog.d(TAG, "Unhandled key: win=" + win + ", action=" + event.getAction()
3682 + ", flags=" + event.getFlags()
3683 + ", keyCode=" + event.getKeyCode()
3684 + ", scanCode=" + event.getScanCode()
3685 + ", metaState=" + event.getMetaState()
3686 + ", repeatCount=" + event.getRepeatCount()
3687 + ", policyFlags=" + policyFlags);
Jeff Brown3915bb82010-11-05 15:02:16 -07003688 }
Jeff Brown49ed71d2010-12-06 17:13:33 -08003689
Jeff Brownfd23e3e2012-05-09 13:34:28 -07003690 KeyEvent fallbackEvent = null;
Jeff Brown49ed71d2010-12-06 17:13:33 -08003691 if ((event.getFlags() & KeyEvent.FLAG_FALLBACK) == 0) {
3692 final KeyCharacterMap kcm = event.getKeyCharacterMap();
Jeff Brownc1fb48d2010-12-08 16:52:09 -08003693 final int keyCode = event.getKeyCode();
3694 final int metaState = event.getMetaState();
Jeff Brownfd23e3e2012-05-09 13:34:28 -07003695 final boolean initialDown = event.getAction() == KeyEvent.ACTION_DOWN
3696 && event.getRepeatCount() == 0;
Jeff Brown49ed71d2010-12-06 17:13:33 -08003697
Jeff Brown54875002011-04-06 15:33:01 -07003698 // Check for fallback actions specified by the key character map.
Jeff Brownfd23e3e2012-05-09 13:34:28 -07003699 final FallbackAction fallbackAction;
3700 if (initialDown) {
3701 fallbackAction = kcm.getFallbackAction(keyCode, metaState);
3702 } else {
3703 fallbackAction = mFallbackActions.get(keyCode);
3704 }
3705
3706 if (fallbackAction != null) {
Jeff Brown40013652012-05-16 21:22:36 -07003707 if (DEBUG_INPUT) {
Jeff Brownfd23e3e2012-05-09 13:34:28 -07003708 Slog.d(TAG, "Fallback: keyCode=" + fallbackAction.keyCode
3709 + " metaState=" + Integer.toHexString(fallbackAction.metaState));
Jeff Brown49ed71d2010-12-06 17:13:33 -08003710 }
3711
Jeff Brownfd23e3e2012-05-09 13:34:28 -07003712 final int flags = event.getFlags() | KeyEvent.FLAG_FALLBACK;
3713 fallbackEvent = KeyEvent.obtain(
Jeff Brown49ed71d2010-12-06 17:13:33 -08003714 event.getDownTime(), event.getEventTime(),
Jeff Brownfd23e3e2012-05-09 13:34:28 -07003715 event.getAction(), fallbackAction.keyCode,
3716 event.getRepeatCount(), fallbackAction.metaState,
Jeff Brown49ed71d2010-12-06 17:13:33 -08003717 event.getDeviceId(), event.getScanCode(),
3718 flags, event.getSource(), null);
Jeff Brownfd23e3e2012-05-09 13:34:28 -07003719
3720 if (!interceptFallback(win, fallbackEvent, policyFlags)) {
3721 fallbackEvent.recycle();
3722 fallbackEvent = null;
Jeff Brown49ed71d2010-12-06 17:13:33 -08003723 }
Jeff Brownfd23e3e2012-05-09 13:34:28 -07003724
3725 if (initialDown) {
3726 mFallbackActions.put(keyCode, fallbackAction);
3727 } else if (event.getAction() == KeyEvent.ACTION_UP) {
3728 mFallbackActions.remove(keyCode);
3729 fallbackAction.recycle();
3730 }
Jeff Brown49ed71d2010-12-06 17:13:33 -08003731 }
3732 }
3733
Jeff Brown40013652012-05-16 21:22:36 -07003734 if (DEBUG_INPUT) {
Jeff Brownfd23e3e2012-05-09 13:34:28 -07003735 if (fallbackEvent == null) {
3736 Slog.d(TAG, "No fallback.");
3737 } else {
3738 Slog.d(TAG, "Performing fallback: " + fallbackEvent);
3739 }
Jeff Brown49ed71d2010-12-06 17:13:33 -08003740 }
Jeff Brownfd23e3e2012-05-09 13:34:28 -07003741 return fallbackEvent;
Jeff Brown3915bb82010-11-05 15:02:16 -07003742 }
3743
Jeff Brownfd23e3e2012-05-09 13:34:28 -07003744 private boolean interceptFallback(WindowState win, KeyEvent fallbackEvent, int policyFlags) {
Jeff Brown037c33e2014-04-09 00:31:55 -07003745 int actions = interceptKeyBeforeQueueing(fallbackEvent, policyFlags);
Jeff Brownfd23e3e2012-05-09 13:34:28 -07003746 if ((actions & ACTION_PASS_TO_USER) != 0) {
3747 long delayMillis = interceptKeyBeforeDispatching(
3748 win, fallbackEvent, policyFlags);
3749 if (delayMillis == 0) {
3750 return true;
3751 }
3752 }
3753 return false;
Jeff Brown6f2fba42011-02-19 01:08:02 -08003754 }
3755
Jim Millere4044bb2016-05-10 18:38:25 -07003756 @Override
Muyuan Li94ce94e2016-02-24 16:20:54 -08003757 public void registerShortcutKey(long shortcutCode, IShortcutService shortcutService)
3758 throws RemoteException {
3759 synchronized (mLock) {
3760 IShortcutService service = mShortcutKeyServices.get(shortcutCode);
Muyuan Li24d24ac2016-03-03 21:15:02 -08003761 if (service != null && service.asBinder().pingBinder()) {
3762 throw new RemoteException("Key already exists.");
Muyuan Li94ce94e2016-02-24 16:20:54 -08003763 }
3764
3765 mShortcutKeyServices.put(shortcutCode, shortcutService);
3766 }
3767 }
3768
Adrian Roosd88eb262016-08-04 14:50:48 -07003769 @Override
Jorim Jaggife762342016-10-13 14:33:27 +02003770 public void onKeyguardOccludedChangedLw(boolean occluded) {
3771 if (mKeyguardDelegate != null && mKeyguardDelegate.isShowing()) {
3772 mPendingKeyguardOccluded = occluded;
3773 mKeyguardOccludedChanged = true;
3774 } else {
3775 setKeyguardOccludedLw(occluded);
3776 }
3777 }
3778
3779 private int handleStartTransitionForKeyguardLw(int transit, @Nullable Animation anim) {
3780 if (mKeyguardOccludedChanged) {
3781 if (DEBUG_KEYGUARD) Slog.d(TAG, "transition/occluded changed occluded="
3782 + mPendingKeyguardOccluded);
3783 mKeyguardOccludedChanged = false;
3784 if (setKeyguardOccludedLw(mPendingKeyguardOccluded)) {
3785 return FINISH_LAYOUT_REDO_LAYOUT | FINISH_LAYOUT_REDO_WALLPAPER;
3786 }
3787 }
3788 if (AppTransition.isKeyguardGoingAwayTransit(transit)) {
Jorim Jaggi8d786932016-10-26 19:08:36 -07003789 if (DEBUG_KEYGUARD) Slog.d(TAG, "Starting keyguard exit animation");
Jorim Jaggife762342016-10-13 14:33:27 +02003790 final long startTime = anim != null
3791 ? SystemClock.uptimeMillis() + anim.getStartOffset()
3792 : SystemClock.uptimeMillis();
3793 final long duration = anim != null
3794 ? anim.getDuration()
3795 : 0;
3796 startKeyguardExitAnimation(startTime, duration);
3797 }
3798 return 0;
Adrian Roosd88eb262016-08-04 14:50:48 -07003799 }
3800
Jeff Brownde7a8ea2012-06-13 18:28:57 -07003801 private void launchAssistLongPressAction() {
3802 performHapticFeedbackLw(null, HapticFeedbackConstants.LONG_PRESS, false);
3803 sendCloseSystemWindows(SYSTEM_DIALOG_REASON_ASSIST);
3804
3805 // launch the search activity
3806 Intent intent = new Intent(Intent.ACTION_SEARCH_LONG_PRESS);
3807 intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
3808 try {
RoboErik8a2cfc32014-05-16 11:19:38 -07003809 // TODO: This only stops the factory-installed search manager.
Jim Miller45308b12012-06-18 19:23:39 -07003810 // Need to formalize an API to handle others
Jeff Brownde7a8ea2012-06-13 18:28:57 -07003811 SearchManager searchManager = getSearchManager();
3812 if (searchManager != null) {
3813 searchManager.stopSearch();
3814 }
Bart Sears8b1c27c2015-03-18 23:51:02 +00003815 startActivityAsUser(intent, UserHandle.CURRENT);
Jeff Brownde7a8ea2012-06-13 18:28:57 -07003816 } catch (ActivityNotFoundException e) {
3817 Slog.w(TAG, "No activity to handle assist long press action.", e);
3818 }
3819 }
3820
Tim Kilbourn0e5f1102015-06-05 16:18:09 -07003821 private void launchAssistAction(String hint, int deviceId) {
Jeff Brownde7a8ea2012-06-13 18:28:57 -07003822 sendCloseSystemWindows(SYSTEM_DIALOG_REASON_ASSIST);
Maurice Lam39d13812015-07-23 20:49:20 -07003823 if (!isUserSetupComplete()) {
3824 // Disable opening assist window during setup
3825 return;
3826 }
Tim Kilbourn0e5f1102015-06-05 16:18:09 -07003827 Bundle args = null;
3828 if (deviceId > Integer.MIN_VALUE) {
3829 args = new Bundle();
3830 args.putInt(Intent.EXTRA_ASSIST_INPUT_DEVICE_ID, deviceId);
Jeff Brownde7a8ea2012-06-13 18:28:57 -07003831 }
Jorim Jaggi165ce062015-07-06 16:18:11 -07003832 if ((mContext.getResources().getConfiguration().uiMode
3833 & Configuration.UI_MODE_TYPE_MASK) == Configuration.UI_MODE_TYPE_TELEVISION) {
3834 // On TV, use legacy handling until assistants are implemented in the proper way.
3835 ((SearchManager) mContext.getSystemService(Context.SEARCH_SERVICE))
3836 .launchLegacyAssist(hint, UserHandle.myUserId(), args);
3837 } else {
Adrian Roosf2efdd82016-04-15 17:43:18 -07003838 if (hint != null) {
3839 if (args == null) {
3840 args = new Bundle();
Jorim Jaggi165ce062015-07-06 16:18:11 -07003841 }
Adrian Roosf2efdd82016-04-15 17:43:18 -07003842 args.putBoolean(hint, true);
3843 }
3844 StatusBarManagerInternal statusbar = getStatusBarManagerInternal();
3845 if (statusbar != null) {
3846 statusbar.startAssist(args);
Jorim Jaggi165ce062015-07-06 16:18:11 -07003847 }
3848 }
Jeff Brownde7a8ea2012-06-13 18:28:57 -07003849 }
3850
Bart Sears8b1c27c2015-03-18 23:51:02 +00003851 private void startActivityAsUser(Intent intent, UserHandle handle) {
3852 if (isUserSetupComplete()) {
3853 mContext.startActivityAsUser(intent, handle);
3854 } else {
3855 Slog.i(TAG, "Not starting activity because user setup is in progress: " + intent);
3856 }
3857 }
3858
Jeff Brownde7a8ea2012-06-13 18:28:57 -07003859 private SearchManager getSearchManager() {
3860 if (mSearchManager == null) {
3861 mSearchManager = (SearchManager) mContext.getSystemService(Context.SEARCH_SERVICE);
3862 }
3863 return mSearchManager;
3864 }
3865
Jeff Browncaca8812013-05-09 13:34:33 -07003866 private void preloadRecentApps() {
3867 mPreloadedRecentApps = true;
Adrian Roosf2efdd82016-04-15 17:43:18 -07003868 StatusBarManagerInternal statusbar = getStatusBarManagerInternal();
3869 if (statusbar != null) {
3870 statusbar.preloadRecentApps();
Jeff Browncaca8812013-05-09 13:34:33 -07003871 }
3872 }
3873
3874 private void cancelPreloadRecentApps() {
3875 if (mPreloadedRecentApps) {
3876 mPreloadedRecentApps = false;
Adrian Roosf2efdd82016-04-15 17:43:18 -07003877 StatusBarManagerInternal statusbar = getStatusBarManagerInternal();
3878 if (statusbar != null) {
3879 statusbar.cancelPreloadRecentApps();
Jeff Browncaca8812013-05-09 13:34:33 -07003880 }
3881 }
3882 }
3883
3884 private void toggleRecentApps() {
3885 mPreloadedRecentApps = false; // preloading no longer needs to be canceled
Adrian Roosf2efdd82016-04-15 17:43:18 -07003886 StatusBarManagerInternal statusbar = getStatusBarManagerInternal();
3887 if (statusbar != null) {
3888 statusbar.toggleRecentApps();
Winson Chung1e8d71b2014-05-16 17:05:22 -07003889 }
3890 }
3891
Craig Mautner84984fa2014-06-19 11:19:20 -07003892 @Override
Jorim Jaggi681fc7b2016-04-14 22:02:39 -07003893 public void showRecentApps(boolean fromHome) {
Craig Mautner84984fa2014-06-19 11:19:20 -07003894 mHandler.removeMessages(MSG_DISPATCH_SHOW_RECENTS);
Jorim Jaggi681fc7b2016-04-14 22:02:39 -07003895 mHandler.obtainMessage(MSG_DISPATCH_SHOW_RECENTS, fromHome ? 1 : 0, 0).sendToTarget();
Craig Mautner84984fa2014-06-19 11:19:20 -07003896 }
3897
Jorim Jaggi681fc7b2016-04-14 22:02:39 -07003898 private void showRecentApps(boolean triggeredFromAltTab, boolean fromHome) {
Winson Chung1e8d71b2014-05-16 17:05:22 -07003899 mPreloadedRecentApps = false; // preloading no longer needs to be canceled
Adrian Roosf2efdd82016-04-15 17:43:18 -07003900 StatusBarManagerInternal statusbar = getStatusBarManagerInternal();
3901 if (statusbar != null) {
3902 statusbar.showRecentApps(triggeredFromAltTab, fromHome);
Jeff Browncaca8812013-05-09 13:34:33 -07003903 }
3904 }
3905
Clara Bayarri4e850ff2016-03-02 11:12:32 -08003906 private void toggleKeyboardShortcutsMenu(int deviceId) {
Adrian Roosf2efdd82016-04-15 17:43:18 -07003907 StatusBarManagerInternal statusbar = getStatusBarManagerInternal();
3908 if (statusbar != null) {
3909 statusbar.toggleKeyboardShortcutsMenu(deviceId);
Clara Bayarrif2debb12015-07-10 14:47:17 +01003910 }
3911 }
3912
Andrei Stingaceanu0bf096f2016-04-14 18:11:57 +01003913 private void dismissKeyboardShortcutsMenu() {
3914 StatusBarManagerInternal statusbar = getStatusBarManagerInternal();
3915 if (statusbar != null) {
3916 statusbar.dismissKeyboardShortcutsMenu();
3917 }
3918 }
3919
Winson Chungcdcd4872014-08-05 18:00:13 -07003920 private void hideRecentApps(boolean triggeredFromAltTab, boolean triggeredFromHome) {
Winson Chung1e8d71b2014-05-16 17:05:22 -07003921 mPreloadedRecentApps = false; // preloading no longer needs to be canceled
Adrian Roosf2efdd82016-04-15 17:43:18 -07003922 StatusBarManagerInternal statusbar = getStatusBarManagerInternal();
3923 if (statusbar != null) {
3924 statusbar.hideRecentApps(triggeredFromAltTab, triggeredFromHome);
Winson Chung1e8d71b2014-05-16 17:05:22 -07003925 }
3926 }
3927
Filip Gruszczynskia483a1d2015-03-17 19:06:58 +00003928 void launchHomeFromHotKey() {
Bryce Lee662ed802015-04-10 20:11:39 +00003929 launchHomeFromHotKey(true /* awakenFromDreams */, true /*respectKeyguard*/);
Filip Gruszczynskia483a1d2015-03-17 19:06:58 +00003930 }
3931
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003932 /**
3933 * A home key -> launch home action was detected. Take the appropriate action
3934 * given the situation with the keyguard.
3935 */
Bryce Lee662ed802015-04-10 20:11:39 +00003936 void launchHomeFromHotKey(final boolean awakenFromDreams, final boolean respectKeyguard) {
3937 if (respectKeyguard) {
3938 if (isKeyguardShowingAndNotOccluded()) {
3939 // don't launch home if keyguard showing
3940 return;
3941 }
3942
Jorim Jaggife762342016-10-13 14:33:27 +02003943 if (!mKeyguardOccluded && mKeyguardDelegate.isInputRestricted()) {
Bryce Lee662ed802015-04-10 20:11:39 +00003944 // when in keyguard restricted mode, must first verify unlock
3945 // before launching home
3946 mKeyguardDelegate.verifyUnlock(new OnKeyguardExitResult() {
3947 @Override
3948 public void onKeyguardExitResult(boolean success) {
3949 if (success) {
3950 try {
Sudheer Shankadc589ac2016-11-10 15:30:17 -08003951 ActivityManager.getService().stopAppSwitches();
Bryce Lee662ed802015-04-10 20:11:39 +00003952 } catch (RemoteException e) {
3953 }
3954 sendCloseSystemWindows(SYSTEM_DIALOG_REASON_HOME_KEY);
3955 startDockOrHome(true /*fromHomeKey*/, awakenFromDreams);
Dianne Hackborn256dd3b2009-05-19 18:51:21 -07003956 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003957 }
Bryce Lee662ed802015-04-10 20:11:39 +00003958 });
3959 return;
3960 }
3961 }
3962
3963 // no keyguard stuff to worry about, just launch home!
3964 try {
Sudheer Shankadc589ac2016-11-10 15:30:17 -08003965 ActivityManager.getService().stopAppSwitches();
Bryce Lee662ed802015-04-10 20:11:39 +00003966 } catch (RemoteException e) {
3967 }
3968 if (mRecentsVisible) {
3969 // Hide Recents and notify it to launch Home
3970 if (awakenFromDreams) {
3971 awakenDreams();
3972 }
Bryce Lee662ed802015-04-10 20:11:39 +00003973 hideRecentApps(false, true);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003974 } else {
Bryce Lee662ed802015-04-10 20:11:39 +00003975 // Otherwise, just launch Home
3976 sendCloseSystemWindows(SYSTEM_DIALOG_REASON_HOME_KEY);
3977 startDockOrHome(true /*fromHomeKey*/, awakenFromDreams);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003978 }
3979 }
3980
John Spurlock04db1762013-05-13 12:46:41 -04003981 private final Runnable mClearHideNavigationFlag = new Runnable() {
3982 @Override
3983 public void run() {
3984 synchronized (mWindowManagerFuncs.getWindowManagerLock()) {
3985 // Clear flags.
3986 mForceClearedSystemUiFlags &=
3987 ~View.SYSTEM_UI_FLAG_HIDE_NAVIGATION;
3988 }
3989 mWindowManagerFuncs.reevaluateStatusBarVisibility();
Dianne Hackborne26ab702011-10-16 13:21:33 -07003990 }
3991 };
3992
3993 /**
3994 * Input handler used while nav bar is hidden. Captures any touch on the screen,
3995 * to determine when the nav bar should be shown and prevent applications from
3996 * receiving those touches.
3997 */
Jeff Brown32cbc38552011-12-01 14:01:49 -08003998 final class HideNavInputEventReceiver extends InputEventReceiver {
3999 public HideNavInputEventReceiver(InputChannel inputChannel, Looper looper) {
4000 super(inputChannel, looper);
4001 }
4002
Dianne Hackborndf89e652011-10-06 22:35:11 -07004003 @Override
Jeff Brown32cbc38552011-12-01 14:01:49 -08004004 public void onInputEvent(InputEvent event) {
Dianne Hackborndf89e652011-10-06 22:35:11 -07004005 boolean handled = false;
4006 try {
Jeff Brown4952dfd2011-11-30 19:23:22 -08004007 if (event instanceof MotionEvent
4008 && (event.getSource() & InputDevice.SOURCE_CLASS_POINTER) != 0) {
4009 final MotionEvent motionEvent = (MotionEvent)event;
4010 if (motionEvent.getAction() == MotionEvent.ACTION_DOWN) {
Dianne Hackborndf89e652011-10-06 22:35:11 -07004011 // When the user taps down, we re-show the nav bar.
4012 boolean changed = false;
John Spurlock04db1762013-05-13 12:46:41 -04004013 synchronized (mWindowManagerFuncs.getWindowManagerLock()) {
Chong Zhang9f7fb092016-05-20 17:03:08 -07004014 if (mInputConsumer == null) {
4015 return;
4016 }
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07004017 // Any user activity always causes us to show the
4018 // navigation controls, if they had been hidden.
4019 // We also clear the low profile and only content
4020 // flags so that tapping on the screen will atomically
4021 // restore all currently hidden screen decorations.
4022 int newVal = mResettingSystemUiFlags |
4023 View.SYSTEM_UI_FLAG_HIDE_NAVIGATION |
4024 View.SYSTEM_UI_FLAG_LOW_PROFILE |
4025 View.SYSTEM_UI_FLAG_FULLSCREEN;
Dianne Hackborne26ab702011-10-16 13:21:33 -07004026 if (mResettingSystemUiFlags != newVal) {
4027 mResettingSystemUiFlags = newVal;
Dianne Hackborndf89e652011-10-06 22:35:11 -07004028 changed = true;
4029 }
Dianne Hackborne26ab702011-10-16 13:21:33 -07004030 // We don't allow the system's nav bar to be hidden
4031 // again for 1 second, to prevent applications from
4032 // spamming us and keeping it from being shown.
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07004033 newVal = mForceClearedSystemUiFlags |
4034 View.SYSTEM_UI_FLAG_HIDE_NAVIGATION;
Dianne Hackborne26ab702011-10-16 13:21:33 -07004035 if (mForceClearedSystemUiFlags != newVal) {
4036 mForceClearedSystemUiFlags = newVal;
4037 changed = true;
John Spurlock04db1762013-05-13 12:46:41 -04004038 mHandler.postDelayed(mClearHideNavigationFlag, 1000);
Dianne Hackborne26ab702011-10-16 13:21:33 -07004039 }
Dianne Hackborndf89e652011-10-06 22:35:11 -07004040 }
4041 if (changed) {
4042 mWindowManagerFuncs.reevaluateStatusBarVisibility();
4043 }
4044 }
4045 }
4046 } finally {
Jeff Brown32cbc38552011-12-01 14:01:49 -08004047 finishInputEvent(event, handled);
Dianne Hackborndf89e652011-10-06 22:35:11 -07004048 }
4049 }
Jeff Brown32cbc38552011-12-01 14:01:49 -08004050 }
Dianne Hackborndf89e652011-10-06 22:35:11 -07004051
4052 @Override
Winsonab216602016-08-09 14:05:20 -07004053 public void setRecentsVisibilityLw(boolean visible) {
4054 mRecentsVisible = visible;
4055 }
4056
4057 @Override
4058 public void setTvPipVisibilityLw(boolean visible) {
4059 mTvPictureInPictureVisible = visible;
4060 }
4061
4062 @Override
Dianne Hackborndf89e652011-10-06 22:35:11 -07004063 public int adjustSystemUiVisibilityLw(int visibility) {
John Spurlock5b9145b2013-08-20 15:13:47 -04004064 mStatusBarController.adjustSystemUiVisibilityLw(mLastSystemUiFlags, visibility);
4065 mNavigationBarController.adjustSystemUiVisibilityLw(mLastSystemUiFlags, visibility);
John Spurlock27735a42013-08-14 17:57:38 -04004066
Dianne Hackborndf89e652011-10-06 22:35:11 -07004067 // Reset any bits in mForceClearingStatusBarVisibility that
4068 // are now clear.
Dianne Hackborne26ab702011-10-16 13:21:33 -07004069 mResettingSystemUiFlags &= visibility;
Dianne Hackborndf89e652011-10-06 22:35:11 -07004070 // Clear any bits in the new visibility that are currently being
4071 // force cleared, before reporting it.
Dianne Hackborne26ab702011-10-16 13:21:33 -07004072 return visibility & ~mResettingSystemUiFlags
4073 & ~mForceClearedSystemUiFlags;
Dianne Hackborndf89e652011-10-06 22:35:11 -07004074 }
4075
Craig Mautner69b08182012-09-05 13:07:13 -07004076 @Override
Jorim Jaggi23bf5462016-05-13 15:24:39 -07004077 public boolean getInsetHintLw(WindowManager.LayoutParams attrs, Rect taskBounds,
4078 int displayRotation, int displayWidth, int displayHeight, Rect outContentInsets,
4079 Rect outStableInsets, Rect outOutsets) {
John Spurlockc6d1c602014-01-17 15:22:06 -05004080 final int fl = PolicyControl.getWindowFlags(null, attrs);
John Spurlock1db8b682014-02-18 11:18:59 -05004081 final int sysuiVis = PolicyControl.getSystemUiVisibility(null, attrs);
4082 final int systemUiVisibility = (sysuiVis | attrs.subtreeSystemUiVisibility);
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07004083
Filip Gruszczynski2987f612015-06-30 15:03:30 -07004084 final boolean useOutsets = outOutsets != null && shouldUseOutsets(attrs, fl);
4085 if (useOutsets) {
4086 int outset = ScreenShapeHelper.getWindowOutsetBottomPx(mContext.getResources());
4087 if (outset > 0) {
4088 if (displayRotation == Surface.ROTATION_0) {
4089 outOutsets.bottom += outset;
4090 } else if (displayRotation == Surface.ROTATION_90) {
4091 outOutsets.right += outset;
4092 } else if (displayRotation == Surface.ROTATION_180) {
4093 outOutsets.top += outset;
4094 } else if (displayRotation == Surface.ROTATION_270) {
4095 outOutsets.left += outset;
4096 }
4097 }
4098 }
4099
Dianne Hackborn5b5cc4d2012-05-16 13:15:00 -07004100 if ((fl & (FLAG_LAYOUT_IN_SCREEN | FLAG_LAYOUT_INSET_DECOR))
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004101 == (FLAG_LAYOUT_IN_SCREEN | FLAG_LAYOUT_INSET_DECOR)) {
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07004102 int availRight, availBottom;
Alan Viverette5a0f4ec2013-10-07 15:10:29 -07004103 if (canHideNavigationBar() &&
Dianne Hackborn5b5cc4d2012-05-16 13:15:00 -07004104 (systemUiVisibility & View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION) != 0) {
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07004105 availRight = mUnrestrictedScreenLeft + mUnrestrictedScreenWidth;
4106 availBottom = mUnrestrictedScreenTop + mUnrestrictedScreenHeight;
4107 } else {
4108 availRight = mRestrictedScreenLeft + mRestrictedScreenWidth;
4109 availBottom = mRestrictedScreenTop + mRestrictedScreenHeight;
4110 }
Dianne Hackborn5b5cc4d2012-05-16 13:15:00 -07004111 if ((systemUiVisibility & View.SYSTEM_UI_FLAG_LAYOUT_STABLE) != 0) {
4112 if ((fl & FLAG_FULLSCREEN) != 0) {
Adrian Roos37d7a682014-11-06 18:15:16 +01004113 outContentInsets.set(mStableFullscreenLeft, mStableFullscreenTop,
Dianne Hackborn5b5cc4d2012-05-16 13:15:00 -07004114 availRight - mStableFullscreenRight,
4115 availBottom - mStableFullscreenBottom);
4116 } else {
Adrian Roos37d7a682014-11-06 18:15:16 +01004117 outContentInsets.set(mStableLeft, mStableTop,
Dianne Hackborn5b5cc4d2012-05-16 13:15:00 -07004118 availRight - mStableRight, availBottom - mStableBottom);
4119 }
Dianne Hackbornc652de82013-02-15 16:32:56 -08004120 } else if ((fl & FLAG_FULLSCREEN) != 0 || (fl & FLAG_LAYOUT_IN_OVERSCAN) != 0) {
Adrian Roos37d7a682014-11-06 18:15:16 +01004121 outContentInsets.setEmpty();
Dianne Hackborn5b5cc4d2012-05-16 13:15:00 -07004122 } else if ((systemUiVisibility & (View.SYSTEM_UI_FLAG_FULLSCREEN
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07004123 | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN)) == 0) {
Adrian Roos37d7a682014-11-06 18:15:16 +01004124 outContentInsets.set(mCurLeft, mCurTop,
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07004125 availRight - mCurRight, availBottom - mCurBottom);
4126 } else {
Adrian Roos37d7a682014-11-06 18:15:16 +01004127 outContentInsets.set(mCurLeft, mCurTop,
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07004128 availRight - mCurRight, availBottom - mCurBottom);
4129 }
Adrian Roos37d7a682014-11-06 18:15:16 +01004130
4131 outStableInsets.set(mStableLeft, mStableTop,
4132 availRight - mStableRight, availBottom - mStableBottom);
Jorim Jaggi23bf5462016-05-13 15:24:39 -07004133 if (taskBounds != null) {
4134 calculateRelevantTaskInsets(taskBounds, outContentInsets,
4135 displayWidth, displayHeight);
4136 calculateRelevantTaskInsets(taskBounds, outStableInsets,
4137 displayWidth, displayHeight);
4138 }
Jorim Jaggi0ffd49c2016-02-12 15:04:21 -08004139 return mForceShowSystemBars;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004140 }
Adrian Roos37d7a682014-11-06 18:15:16 +01004141 outContentInsets.setEmpty();
4142 outStableInsets.setEmpty();
Jorim Jaggi0ffd49c2016-02-12 15:04:21 -08004143 return mForceShowSystemBars;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004144 }
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07004145
Jorim Jaggi23bf5462016-05-13 15:24:39 -07004146 /**
4147 * For any given task bounds, the insets relevant for these bounds given the insets relevant
4148 * for the entire display.
4149 */
4150 private void calculateRelevantTaskInsets(Rect taskBounds, Rect inOutInsets, int displayWidth,
4151 int displayHeight) {
4152 mTmpRect.set(0, 0, displayWidth, displayHeight);
4153 mTmpRect.inset(inOutInsets);
4154 mTmpRect.intersect(taskBounds);
4155 int leftInset = mTmpRect.left - taskBounds.left;
4156 int topInset = mTmpRect.top - taskBounds.top;
4157 int rightInset = taskBounds.right - mTmpRect.right;
4158 int bottomInset = taskBounds.bottom - mTmpRect.bottom;
4159 inOutInsets.set(leftInset, topInset, rightInset, bottomInset);
4160 }
4161
Filip Gruszczynski2987f612015-06-30 15:03:30 -07004162 private boolean shouldUseOutsets(WindowManager.LayoutParams attrs, int fl) {
4163 return attrs.type == TYPE_WALLPAPER || (fl & (WindowManager.LayoutParams.FLAG_FULLSCREEN
4164 | WindowManager.LayoutParams.FLAG_LAYOUT_IN_OVERSCAN)) != 0;
4165 }
4166
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004167 /** {@inheritDoc} */
Craig Mautner69b08182012-09-05 13:07:13 -07004168 @Override
4169 public void beginLayoutLw(boolean isDefaultDisplay, int displayWidth, int displayHeight,
Sriram Viswanathan9ebbe6a2015-11-16 17:59:22 -08004170 int displayRotation, int uiMode) {
Filip Gruszczynski2987f612015-06-30 15:03:30 -07004171 mDisplayRotation = displayRotation;
Dianne Hackbornc652de82013-02-15 16:32:56 -08004172 final int overscanLeft, overscanTop, overscanRight, overscanBottom;
4173 if (isDefaultDisplay) {
4174 switch (displayRotation) {
4175 case Surface.ROTATION_90:
4176 overscanLeft = mOverscanTop;
4177 overscanTop = mOverscanRight;
4178 overscanRight = mOverscanBottom;
4179 overscanBottom = mOverscanLeft;
4180 break;
4181 case Surface.ROTATION_180:
4182 overscanLeft = mOverscanRight;
4183 overscanTop = mOverscanBottom;
4184 overscanRight = mOverscanLeft;
4185 overscanBottom = mOverscanTop;
4186 break;
4187 case Surface.ROTATION_270:
4188 overscanLeft = mOverscanBottom;
4189 overscanTop = mOverscanLeft;
4190 overscanRight = mOverscanTop;
4191 overscanBottom = mOverscanRight;
4192 break;
4193 default:
4194 overscanLeft = mOverscanLeft;
4195 overscanTop = mOverscanTop;
4196 overscanRight = mOverscanRight;
4197 overscanBottom = mOverscanBottom;
4198 break;
4199 }
4200 } else {
4201 overscanLeft = 0;
4202 overscanTop = 0;
4203 overscanRight = 0;
4204 overscanBottom = 0;
4205 }
Dianne Hackborn313440842013-02-19 19:22:59 -08004206 mOverscanScreenLeft = mRestrictedOverscanScreenLeft = 0;
4207 mOverscanScreenTop = mRestrictedOverscanScreenTop = 0;
4208 mOverscanScreenWidth = mRestrictedOverscanScreenWidth = displayWidth;
4209 mOverscanScreenHeight = mRestrictedOverscanScreenHeight = displayHeight;
Dianne Hackbornc652de82013-02-15 16:32:56 -08004210 mSystemLeft = 0;
4211 mSystemTop = 0;
4212 mSystemRight = displayWidth;
4213 mSystemBottom = displayHeight;
4214 mUnrestrictedScreenLeft = overscanLeft;
4215 mUnrestrictedScreenTop = overscanTop;
4216 mUnrestrictedScreenWidth = displayWidth - overscanLeft - overscanRight;
4217 mUnrestrictedScreenHeight = displayHeight - overscanTop - overscanBottom;
4218 mRestrictedScreenLeft = mUnrestrictedScreenLeft;
4219 mRestrictedScreenTop = mUnrestrictedScreenTop;
John Spurlockad3e6cb2013-04-30 08:47:43 -04004220 mRestrictedScreenWidth = mSystemGestures.screenWidth = mUnrestrictedScreenWidth;
4221 mRestrictedScreenHeight = mSystemGestures.screenHeight = mUnrestrictedScreenHeight;
Dianne Hackborne30e02f2014-05-27 18:24:45 -07004222 mDockLeft = mContentLeft = mVoiceContentLeft = mStableLeft = mStableFullscreenLeft
Dianne Hackbornc652de82013-02-15 16:32:56 -08004223 = mCurLeft = mUnrestrictedScreenLeft;
Dianne Hackborne30e02f2014-05-27 18:24:45 -07004224 mDockTop = mContentTop = mVoiceContentTop = mStableTop = mStableFullscreenTop
Dianne Hackbornc652de82013-02-15 16:32:56 -08004225 = mCurTop = mUnrestrictedScreenTop;
Dianne Hackborne30e02f2014-05-27 18:24:45 -07004226 mDockRight = mContentRight = mVoiceContentRight = mStableRight = mStableFullscreenRight
Dianne Hackbornc652de82013-02-15 16:32:56 -08004227 = mCurRight = displayWidth - overscanRight;
Dianne Hackborne30e02f2014-05-27 18:24:45 -07004228 mDockBottom = mContentBottom = mVoiceContentBottom = mStableBottom = mStableFullscreenBottom
Dianne Hackbornc652de82013-02-15 16:32:56 -08004229 = mCurBottom = displayHeight - overscanBottom;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004230 mDockLayer = 0x10000000;
Dianne Hackborn5c58de32012-04-28 19:52:37 -07004231 mStatusBarLayer = -1;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004232
Daniel Sandler8956dbb2011-04-22 07:55:02 -04004233 // start with the current dock rect, which will be (0,0,displayWidth,displayHeight)
4234 final Rect pf = mTmpParentFrame;
4235 final Rect df = mTmpDisplayFrame;
Dianne Hackbornc4aad012013-02-22 15:05:25 -08004236 final Rect of = mTmpOverscanFrame;
Daniel Sandler8956dbb2011-04-22 07:55:02 -04004237 final Rect vf = mTmpVisibleFrame;
John Spurlock46646232013-09-30 22:32:42 -04004238 final Rect dcf = mTmpDecorFrame;
Dianne Hackbornc4aad012013-02-22 15:05:25 -08004239 pf.left = df.left = of.left = vf.left = mDockLeft;
4240 pf.top = df.top = of.top = vf.top = mDockTop;
4241 pf.right = df.right = of.right = vf.right = mDockRight;
4242 pf.bottom = df.bottom = of.bottom = vf.bottom = mDockBottom;
John Spurlock46646232013-09-30 22:32:42 -04004243 dcf.setEmpty(); // Decor frame N/A for system bars.
Daniel Sandler8956dbb2011-04-22 07:55:02 -04004244
Craig Mautner69b08182012-09-05 13:07:13 -07004245 if (isDefaultDisplay) {
4246 // For purposes of putting out fake window up to steal focus, we will
4247 // drive nav being hidden only by whether it is requested.
John Spurlocke1f366f2013-08-05 12:22:40 -04004248 final int sysui = mLastSystemUiFlags;
4249 boolean navVisible = (sysui & View.SYSTEM_UI_FLAG_HIDE_NAVIGATION) == 0;
Adrian Roosea562512014-05-05 13:33:03 +02004250 boolean navTranslucent = (sysui
Jorim Jaggi4fa78922015-11-30 17:13:56 -08004251 & (View.NAVIGATION_BAR_TRANSLUCENT | View.NAVIGATION_BAR_TRANSPARENT)) != 0;
John Spurlockf1a36642013-10-12 17:50:42 -04004252 boolean immersive = (sysui & View.SYSTEM_UI_FLAG_IMMERSIVE) != 0;
4253 boolean immersiveSticky = (sysui & View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY) != 0;
4254 boolean navAllowedHidden = immersive || immersiveSticky;
4255 navTranslucent &= !immersiveSticky; // transient trumps translucent
Jorim Jaggife762342016-10-13 14:33:27 +02004256 boolean isKeyguardShowing = isStatusBarKeyguard() && !mKeyguardOccluded;
Adrian Roos4fb3ee32014-08-22 19:29:09 +02004257 if (!isKeyguardShowing) {
4258 navTranslucent &= areTranslucentBarsAllowed();
4259 }
Jaewan Kim33284332016-05-12 18:55:46 +09004260 boolean statusBarExpandedNotKeyguard = !isKeyguardShowing && mStatusBar != null
Adrian Roosdb1bc6b2016-04-14 17:49:43 -07004261 && mStatusBar.getAttrs().height == MATCH_PARENT
4262 && mStatusBar.getAttrs().width == MATCH_PARENT;
Dianne Hackborne26ab702011-10-16 13:21:33 -07004263
Craig Mautner69b08182012-09-05 13:07:13 -07004264 // When the navigation bar isn't visible, we put up a fake
4265 // input window to catch all touch events. This way we can
4266 // detect when the user presses anywhere to bring back the nav
4267 // bar and ensure the application doesn't see the event.
John Spurlockf1a36642013-10-12 17:50:42 -04004268 if (navVisible || navAllowedHidden) {
Selim Cinekf83e8242015-05-19 18:08:14 -07004269 if (mInputConsumer != null) {
Chong Zhang9f7fb092016-05-20 17:03:08 -07004270 mHandler.sendMessage(
4271 mHandler.obtainMessage(MSG_DISPOSE_INPUT_CONSUMER, mInputConsumer));
Selim Cinekf83e8242015-05-19 18:08:14 -07004272 mInputConsumer = null;
Craig Mautner69b08182012-09-05 13:07:13 -07004273 }
Selim Cinekf83e8242015-05-19 18:08:14 -07004274 } else if (mInputConsumer == null) {
Winson41275482016-10-10 15:17:45 -07004275 mInputConsumer = mWindowManagerFuncs.createInputConsumer(mHandler.getLooper(),
4276 INPUT_CONSUMER_NAVIGATION,
4277 (channel, looper) -> new HideNavInputEventReceiver(channel, looper));
Dianne Hackborne26ab702011-10-16 13:21:33 -07004278 }
Dianne Hackborne26ab702011-10-16 13:21:33 -07004279
Craig Mautner69b08182012-09-05 13:07:13 -07004280 // For purposes of positioning and showing the nav bar, if we have
4281 // decided that it can't be hidden (because of the screen aspect ratio),
4282 // then take that into account.
Alan Viverette5a0f4ec2013-10-07 15:10:29 -07004283 navVisible |= !canHideNavigationBar();
Dianne Hackbornf87d1962012-04-04 12:48:24 -07004284
Filip Gruszczynski83dd9552015-09-17 17:50:36 -07004285 boolean updateSysUiVisibility = layoutNavigationBar(displayWidth, displayHeight,
Adrian Roos85d202b2016-06-02 16:27:47 -07004286 displayRotation, uiMode, overscanLeft, overscanRight, overscanBottom, dcf, navVisible, navTranslucent,
Adrian Roosdb1bc6b2016-04-14 17:49:43 -07004287 navAllowedHidden, statusBarExpandedNotKeyguard);
Craig Mautnereda67292013-04-28 13:50:14 -07004288 if (DEBUG_LAYOUT) Slog.i(TAG, String.format("mDock rect: (%d,%d - %d,%d)",
Craig Mautner69b08182012-09-05 13:07:13 -07004289 mDockLeft, mDockTop, mDockRight, mDockBottom));
Filip Gruszczynski83dd9552015-09-17 17:50:36 -07004290 updateSysUiVisibility |= layoutStatusBar(pf, df, of, vf, dcf, sysui, isKeyguardShowing);
John Spurlockad3e6cb2013-04-30 08:47:43 -04004291 if (updateSysUiVisibility) {
4292 updateSystemUiVisibilityLw();
4293 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004294 }
4295 }
4296
Filip Gruszczynski83dd9552015-09-17 17:50:36 -07004297 private boolean layoutStatusBar(Rect pf, Rect df, Rect of, Rect vf, Rect dcf, int sysui,
4298 boolean isKeyguardShowing) {
4299 // decide where the status bar goes ahead of time
4300 if (mStatusBar != null) {
4301 // apply any navigation bar insets
4302 pf.left = df.left = of.left = mUnrestrictedScreenLeft;
4303 pf.top = df.top = of.top = mUnrestrictedScreenTop;
4304 pf.right = df.right = of.right = mUnrestrictedScreenWidth + mUnrestrictedScreenLeft;
4305 pf.bottom = df.bottom = of.bottom = mUnrestrictedScreenHeight
4306 + mUnrestrictedScreenTop;
4307 vf.left = mStableLeft;
4308 vf.top = mStableTop;
4309 vf.right = mStableRight;
4310 vf.bottom = mStableBottom;
4311
4312 mStatusBarLayer = mStatusBar.getSurfaceLayer();
4313
4314 // Let the status bar determine its size.
4315 mStatusBar.computeFrameLw(pf /* parentFrame */, df /* displayFrame */,
4316 vf /* overlayFrame */, vf /* contentFrame */, vf /* visibleFrame */,
4317 dcf /* decorFrame */, vf /* stableFrame */, vf /* outsetFrame */);
4318
4319 // For layout, the status bar is always at the top with our fixed height.
4320 mStableTop = mUnrestrictedScreenTop + mStatusBarHeight;
4321
4322 boolean statusBarTransient = (sysui & View.STATUS_BAR_TRANSIENT) != 0;
4323 boolean statusBarTranslucent = (sysui
Jorim Jaggi4fa78922015-11-30 17:13:56 -08004324 & (View.STATUS_BAR_TRANSLUCENT | View.STATUS_BAR_TRANSPARENT)) != 0;
Filip Gruszczynski83dd9552015-09-17 17:50:36 -07004325 if (!isKeyguardShowing) {
4326 statusBarTranslucent &= areTranslucentBarsAllowed();
4327 }
4328
4329 // If the status bar is hidden, we don't want to cause
4330 // windows behind it to scroll.
4331 if (mStatusBar.isVisibleLw() && !statusBarTransient) {
4332 // Status bar may go away, so the screen area it occupies
4333 // is available to apps but just covering them when the
4334 // status bar is visible.
4335 mDockTop = mUnrestrictedScreenTop + mStatusBarHeight;
4336
4337 mContentTop = mVoiceContentTop = mCurTop = mDockTop;
4338 mContentBottom = mVoiceContentBottom = mCurBottom = mDockBottom;
4339 mContentLeft = mVoiceContentLeft = mCurLeft = mDockLeft;
4340 mContentRight = mVoiceContentRight = mCurRight = mDockRight;
4341
4342 if (DEBUG_LAYOUT) Slog.v(TAG, "Status bar: " +
4343 String.format(
4344 "dock=[%d,%d][%d,%d] content=[%d,%d][%d,%d] cur=[%d,%d][%d,%d]",
4345 mDockLeft, mDockTop, mDockRight, mDockBottom,
4346 mContentLeft, mContentTop, mContentRight, mContentBottom,
4347 mCurLeft, mCurTop, mCurRight, mCurBottom));
4348 }
4349 if (mStatusBar.isVisibleLw() && !mStatusBar.isAnimatingLw()
4350 && !statusBarTransient && !statusBarTranslucent
4351 && !mStatusBarController.wasRecentlyTranslucent()) {
4352 // If the opaque status bar is currently requested to be visible,
4353 // and not in the process of animating on or off, then
4354 // we can tell the app that it is covered by it.
4355 mSystemTop = mUnrestrictedScreenTop + mStatusBarHeight;
4356 }
4357 if (mStatusBarController.checkHiddenLw()) {
4358 return true;
4359 }
4360 }
4361 return false;
4362 }
4363
4364 private boolean layoutNavigationBar(int displayWidth, int displayHeight, int displayRotation,
Adrian Roos85d202b2016-06-02 16:27:47 -07004365 int uiMode, int overscanLeft, int overscanRight, int overscanBottom, Rect dcf,
4366 boolean navVisible, boolean navTranslucent, boolean navAllowedHidden,
Adrian Roosdb1bc6b2016-04-14 17:49:43 -07004367 boolean statusBarExpandedNotKeyguard) {
Filip Gruszczynski83dd9552015-09-17 17:50:36 -07004368 if (mNavigationBar != null) {
4369 boolean transientNavBarShowing = mNavigationBarController.isTransientShowing();
4370 // Force the navigation bar to its appropriate place and
4371 // size. We need to do this directly, instead of relying on
4372 // it to bubble up from the nav bar, because this needs to
4373 // change atomically with screen rotations.
Adrian Roos85d202b2016-06-02 16:27:47 -07004374 mNavigationBarPosition = navigationBarPosition(displayWidth, displayHeight,
4375 displayRotation);
4376 if (mNavigationBarPosition == NAV_BAR_BOTTOM) {
Filip Gruszczynski83dd9552015-09-17 17:50:36 -07004377 // It's a system nav bar or a portrait screen; nav bar goes on bottom.
4378 int top = displayHeight - overscanBottom
Sriram Viswanathan9ebbe6a2015-11-16 17:59:22 -08004379 - getNavigationBarHeight(displayRotation, uiMode);
Filip Gruszczynski83dd9552015-09-17 17:50:36 -07004380 mTmpNavigationFrame.set(0, top, displayWidth, displayHeight - overscanBottom);
4381 mStableBottom = mStableFullscreenBottom = mTmpNavigationFrame.top;
4382 if (transientNavBarShowing) {
4383 mNavigationBarController.setBarShowingLw(true);
4384 } else if (navVisible) {
4385 mNavigationBarController.setBarShowingLw(true);
4386 mDockBottom = mTmpNavigationFrame.top;
4387 mRestrictedScreenHeight = mDockBottom - mRestrictedScreenTop;
4388 mRestrictedOverscanScreenHeight = mDockBottom - mRestrictedOverscanScreenTop;
4389 } else {
Adrian Roosdb1bc6b2016-04-14 17:49:43 -07004390 // We currently want to hide the navigation UI - unless we expanded the status
4391 // bar.
4392 mNavigationBarController.setBarShowingLw(statusBarExpandedNotKeyguard);
Filip Gruszczynski83dd9552015-09-17 17:50:36 -07004393 }
4394 if (navVisible && !navTranslucent && !navAllowedHidden
4395 && !mNavigationBar.isAnimatingLw()
4396 && !mNavigationBarController.wasRecentlyTranslucent()) {
4397 // If the opaque nav bar is currently requested to be visible,
4398 // and not in the process of animating on or off, then
4399 // we can tell the app that it is covered by it.
4400 mSystemBottom = mTmpNavigationFrame.top;
4401 }
Adrian Roos85d202b2016-06-02 16:27:47 -07004402 } else if (mNavigationBarPosition == NAV_BAR_RIGHT) {
Filip Gruszczynski83dd9552015-09-17 17:50:36 -07004403 // Landscape screen; nav bar goes to the right.
4404 int left = displayWidth - overscanRight
Sriram Viswanathan9ebbe6a2015-11-16 17:59:22 -08004405 - getNavigationBarWidth(displayRotation, uiMode);
Filip Gruszczynski83dd9552015-09-17 17:50:36 -07004406 mTmpNavigationFrame.set(left, 0, displayWidth - overscanRight, displayHeight);
4407 mStableRight = mStableFullscreenRight = mTmpNavigationFrame.left;
4408 if (transientNavBarShowing) {
4409 mNavigationBarController.setBarShowingLw(true);
4410 } else if (navVisible) {
4411 mNavigationBarController.setBarShowingLw(true);
4412 mDockRight = mTmpNavigationFrame.left;
4413 mRestrictedScreenWidth = mDockRight - mRestrictedScreenLeft;
4414 mRestrictedOverscanScreenWidth = mDockRight - mRestrictedOverscanScreenLeft;
4415 } else {
Adrian Roosdb1bc6b2016-04-14 17:49:43 -07004416 // We currently want to hide the navigation UI - unless we expanded the status
4417 // bar.
4418 mNavigationBarController.setBarShowingLw(statusBarExpandedNotKeyguard);
Filip Gruszczynski83dd9552015-09-17 17:50:36 -07004419 }
4420 if (navVisible && !navTranslucent && !navAllowedHidden
4421 && !mNavigationBar.isAnimatingLw()
4422 && !mNavigationBarController.wasRecentlyTranslucent()) {
4423 // If the nav bar is currently requested to be visible,
4424 // and not in the process of animating on or off, then
4425 // we can tell the app that it is covered by it.
4426 mSystemRight = mTmpNavigationFrame.left;
4427 }
Adrian Roos85d202b2016-06-02 16:27:47 -07004428 } else if (mNavigationBarPosition == NAV_BAR_LEFT) {
4429 // Seascape screen; nav bar goes to the left.
4430 int right = overscanLeft + getNavigationBarWidth(displayRotation, uiMode);
4431 mTmpNavigationFrame.set(overscanLeft, 0, right, displayHeight);
4432 mStableLeft = mStableFullscreenLeft = mTmpNavigationFrame.right;
4433 if (transientNavBarShowing) {
4434 mNavigationBarController.setBarShowingLw(true);
4435 } else if (navVisible) {
4436 mNavigationBarController.setBarShowingLw(true);
4437 mDockLeft = mTmpNavigationFrame.right;
4438 // TODO: not so sure about those:
4439 mRestrictedScreenLeft = mRestrictedOverscanScreenLeft = mDockLeft;
4440 mRestrictedScreenWidth = mDockRight - mRestrictedScreenLeft;
4441 mRestrictedOverscanScreenWidth = mDockRight - mRestrictedOverscanScreenLeft;
4442 } else {
4443 // We currently want to hide the navigation UI - unless we expanded the status
4444 // bar.
4445 mNavigationBarController.setBarShowingLw(statusBarExpandedNotKeyguard);
4446 }
4447 if (navVisible && !navTranslucent && !navAllowedHidden
4448 && !mNavigationBar.isAnimatingLw()
4449 && !mNavigationBarController.wasRecentlyTranslucent()) {
4450 // If the nav bar is currently requested to be visible,
4451 // and not in the process of animating on or off, then
4452 // we can tell the app that it is covered by it.
4453 mSystemLeft = mTmpNavigationFrame.right;
4454 }
Filip Gruszczynski83dd9552015-09-17 17:50:36 -07004455 }
4456 // Make sure the content and current rectangles are updated to
4457 // account for the restrictions from the navigation bar.
4458 mContentTop = mVoiceContentTop = mCurTop = mDockTop;
4459 mContentBottom = mVoiceContentBottom = mCurBottom = mDockBottom;
4460 mContentLeft = mVoiceContentLeft = mCurLeft = mDockLeft;
4461 mContentRight = mVoiceContentRight = mCurRight = mDockRight;
4462 mStatusBarLayer = mNavigationBar.getSurfaceLayer();
4463 // And compute the final frame.
4464 mNavigationBar.computeFrameLw(mTmpNavigationFrame, mTmpNavigationFrame,
4465 mTmpNavigationFrame, mTmpNavigationFrame, mTmpNavigationFrame, dcf,
4466 mTmpNavigationFrame, mTmpNavigationFrame);
4467 if (DEBUG_LAYOUT) Slog.i(TAG, "mNavigationBar frame: " + mTmpNavigationFrame);
4468 if (mNavigationBarController.checkHiddenLw()) {
4469 return true;
4470 }
4471 }
4472 return false;
4473 }
4474
Adrian Roos85d202b2016-06-02 16:27:47 -07004475 private int navigationBarPosition(int displayWidth, int displayHeight, int displayRotation) {
4476 if (mNavigationBarCanMove && displayWidth > displayHeight) {
4477 if (displayRotation == Surface.ROTATION_270) {
4478 return NAV_BAR_LEFT;
4479 } else {
4480 return NAV_BAR_RIGHT;
4481 }
4482 }
4483 return NAV_BAR_BOTTOM;
Jorim Jaggi737af722015-12-31 10:42:27 +01004484 }
4485
Dianne Hackborn85afd1b2012-05-13 13:31:06 -07004486 /** {@inheritDoc} */
Craig Mautner967212c2013-04-13 21:10:58 -07004487 @Override
John Spurlock46646232013-09-30 22:32:42 -04004488 public int getSystemDecorLayerLw() {
Bryce Lee2ed3e5f2015-04-01 22:09:19 +00004489 if (mStatusBar != null && mStatusBar.isVisibleLw()) {
4490 return mStatusBar.getSurfaceLayer();
4491 }
4492
4493 if (mNavigationBar != null && mNavigationBar.isVisibleLw()) {
4494 return mNavigationBar.getSurfaceLayer();
4495 }
4496
Dianne Hackborn85afd1b2012-05-13 13:31:06 -07004497 return 0;
4498 }
4499
Craig Mautner967212c2013-04-13 21:10:58 -07004500 @Override
4501 public void getContentRectLw(Rect r) {
4502 r.set(mContentLeft, mContentTop, mContentRight, mContentBottom);
4503 }
4504
Dianne Hackbornc4aad012013-02-22 15:05:25 -08004505 void setAttachedWindowFrames(WindowState win, int fl, int adjust, WindowState attached,
4506 boolean insetDecors, Rect pf, Rect df, Rect of, Rect cf, Rect vf) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004507 if (win.getSurfaceLayer() > mDockLayer && attached.getSurfaceLayer() < mDockLayer) {
4508 // Here's a special case: if this attached window is a panel that is
4509 // above the dock window, and the window it is attached to is below
4510 // the dock window, then the frames we computed for the window it is
4511 // attached to can not be used because the dock is effectively part
4512 // of the underlying window and the attached window is floating on top
4513 // of the whole thing. So, we ignore the attached window and explicitly
4514 // compute the frames that would be appropriate without the dock.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08004515 df.left = of.left = cf.left = vf.left = mDockLeft;
4516 df.top = of.top = cf.top = vf.top = mDockTop;
4517 df.right = of.right = cf.right = vf.right = mDockRight;
4518 df.bottom = of.bottom = cf.bottom = vf.bottom = mDockBottom;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004519 } else {
4520 // The effective display frame of the attached window depends on
4521 // whether it is taking care of insetting its content. If not,
4522 // we need to use the parent's content frame so that the entire
4523 // window is positioned within that content. Otherwise we can use
Wale Ogunwale393b1c12014-10-18 16:22:01 -07004524 // the overscan frame and let the attached window take care of
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004525 // positioning its content appropriately.
Dianne Hackborndea3ef72010-10-28 14:24:22 -07004526 if (adjust != SOFT_INPUT_ADJUST_RESIZE) {
Wale Ogunwale393b1c12014-10-18 16:22:01 -07004527 // Set the content frame of the attached window to the parent's decor frame
4528 // (same as content frame when IME isn't present) if specifically requested by
4529 // setting {@link WindowManager.LayoutParams#FLAG_LAYOUT_ATTACHED_IN_DECOR} flag.
4530 // Otherwise, use the overscan frame.
4531 cf.set((fl & FLAG_LAYOUT_ATTACHED_IN_DECOR) != 0
4532 ? attached.getContentFrameLw() : attached.getOverscanFrameLw());
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004533 } else {
4534 // If the window is resizing, then we want to base the content
4535 // frame on our attached content frame to resize... however,
4536 // things can be tricky if the attached window is NOT in resize
4537 // mode, in which case its content frame will be larger.
4538 // Ungh. So to deal with that, make sure the content frame
4539 // we end up using is not covering the IM dock.
4540 cf.set(attached.getContentFrameLw());
Dianne Hackborne30e02f2014-05-27 18:24:45 -07004541 if (attached.isVoiceInteraction()) {
4542 if (cf.left < mVoiceContentLeft) cf.left = mVoiceContentLeft;
4543 if (cf.top < mVoiceContentTop) cf.top = mVoiceContentTop;
4544 if (cf.right > mVoiceContentRight) cf.right = mVoiceContentRight;
4545 if (cf.bottom > mVoiceContentBottom) cf.bottom = mVoiceContentBottom;
4546 } else if (attached.getSurfaceLayer() < mDockLayer) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004547 if (cf.left < mContentLeft) cf.left = mContentLeft;
4548 if (cf.top < mContentTop) cf.top = mContentTop;
4549 if (cf.right > mContentRight) cf.right = mContentRight;
4550 if (cf.bottom > mContentBottom) cf.bottom = mContentBottom;
4551 }
4552 }
4553 df.set(insetDecors ? attached.getDisplayFrameLw() : cf);
Dianne Hackbornc4aad012013-02-22 15:05:25 -08004554 of.set(insetDecors ? attached.getOverscanFrameLw() : cf);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004555 vf.set(attached.getVisibleFrameLw());
4556 }
4557 // The LAYOUT_IN_SCREEN flag is used to determine whether the attached
4558 // window should be positioned relative to its parent or the entire
4559 // screen.
4560 pf.set((fl & FLAG_LAYOUT_IN_SCREEN) == 0
4561 ? attached.getFrameLw() : df);
4562 }
Dianne Hackborn5b5cc4d2012-05-16 13:15:00 -07004563
4564 private void applyStableConstraints(int sysui, int fl, Rect r) {
4565 if ((sysui & View.SYSTEM_UI_FLAG_LAYOUT_STABLE) != 0) {
4566 // If app is requesting a stable layout, don't let the
4567 // content insets go below the stable values.
4568 if ((fl & FLAG_FULLSCREEN) != 0) {
4569 if (r.left < mStableFullscreenLeft) r.left = mStableFullscreenLeft;
4570 if (r.top < mStableFullscreenTop) r.top = mStableFullscreenTop;
4571 if (r.right > mStableFullscreenRight) r.right = mStableFullscreenRight;
4572 if (r.bottom > mStableFullscreenBottom) r.bottom = mStableFullscreenBottom;
4573 } else {
4574 if (r.left < mStableLeft) r.left = mStableLeft;
4575 if (r.top < mStableTop) r.top = mStableTop;
4576 if (r.right > mStableRight) r.right = mStableRight;
4577 if (r.bottom > mStableBottom) r.bottom = mStableBottom;
4578 }
4579 }
4580 }
4581
Jorim Jaggiaa806142015-05-20 18:04:16 -07004582 private boolean canReceiveInput(WindowState win) {
4583 boolean notFocusable =
4584 (win.getAttrs().flags & WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE) != 0;
4585 boolean altFocusableIm =
4586 (win.getAttrs().flags & WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM) != 0;
4587 boolean notFocusableForIm = notFocusable ^ altFocusableIm;
4588 return !notFocusableForIm;
4589 }
4590
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004591 /** {@inheritDoc} */
Craig Mautner69b08182012-09-05 13:07:13 -07004592 @Override
Craig Mautnerc9457fa2014-06-06 14:27:48 -07004593 public void layoutWindowLw(WindowState win, WindowState attached) {
Jorim Jaggiaa806142015-05-20 18:04:16 -07004594 // We've already done the navigation bar and status bar. If the status bar can receive
4595 // input, we need to layout it again to accomodate for the IME window.
4596 if ((win == mStatusBar && !canReceiveInput(win)) || win == mNavigationBar) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004597 return;
4598 }
Jorim Jaggiaa806142015-05-20 18:04:16 -07004599 final WindowManager.LayoutParams attrs = win.getAttrs();
Craig Mautner69b08182012-09-05 13:07:13 -07004600 final boolean isDefaultDisplay = win.isDefaultDisplay();
4601 final boolean needsToOffsetInputMethodTarget = isDefaultDisplay &&
satok1bc0a492012-04-25 22:47:12 +09004602 (win == mLastInputMethodTargetWindow && mLastInputMethodWindow != null);
4603 if (needsToOffsetInputMethodTarget) {
Craig Mautnereda67292013-04-28 13:50:14 -07004604 if (DEBUG_LAYOUT) Slog.i(TAG, "Offset ime target window by the last ime window state");
satok1bc0a492012-04-25 22:47:12 +09004605 offsetInputMethodWindowLw(mLastInputMethodWindow);
4606 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004607
John Spurlockc6d1c602014-01-17 15:22:06 -05004608 final int fl = PolicyControl.getWindowFlags(win, attrs);
Jorim Jaggi8f5701b2016-04-04 18:36:02 -07004609 final int pfl = attrs.privateFlags;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004610 final int sim = attrs.softInputMode;
John Spurlock1db8b682014-02-18 11:18:59 -05004611 final int sysUiFl = PolicyControl.getSystemUiVisibility(win, null);
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07004612
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004613 final Rect pf = mTmpParentFrame;
4614 final Rect df = mTmpDisplayFrame;
Dianne Hackbornc4aad012013-02-22 15:05:25 -08004615 final Rect of = mTmpOverscanFrame;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004616 final Rect cf = mTmpContentFrame;
4617 final Rect vf = mTmpVisibleFrame;
John Spurlock46646232013-09-30 22:32:42 -04004618 final Rect dcf = mTmpDecorFrame;
Adrian Roosfa104232014-06-20 16:10:14 -07004619 final Rect sf = mTmpStableFrame;
Filip Gruszczynski2217f612015-05-26 11:32:08 -07004620 Rect osf = null;
John Spurlock46646232013-09-30 22:32:42 -04004621 dcf.setEmpty();
Craig Mautner69b08182012-09-05 13:07:13 -07004622
4623 final boolean hasNavBar = (isDefaultDisplay && mHasNavigationBar
Daniel Sandler36412a72011-08-04 09:35:13 -04004624 && mNavigationBar != null && mNavigationBar.isVisibleLw());
Daniel Sandler8956dbb2011-04-22 07:55:02 -04004625
Craig Mautnerf683b562012-10-02 11:10:57 -07004626 final int adjust = sim & SOFT_INPUT_MASK_ADJUST;
4627
Adrian Roosfa104232014-06-20 16:10:14 -07004628 if (isDefaultDisplay) {
4629 sf.set(mStableLeft, mStableTop, mStableRight, mStableBottom);
4630 } else {
4631 sf.set(mOverscanLeft, mOverscanTop, mOverscanRight, mOverscanBottom);
4632 }
4633
Craig Mautner69b08182012-09-05 13:07:13 -07004634 if (!isDefaultDisplay) {
4635 if (attached != null) {
4636 // If this window is attached to another, our display
4637 // frame is the same as the one we are attached to.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08004638 setAttachedWindowFrames(win, fl, adjust, attached, true, pf, df, of, cf, vf);
Craig Mautner69b08182012-09-05 13:07:13 -07004639 } else {
4640 // Give the window full screen.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08004641 pf.left = df.left = of.left = cf.left = mOverscanScreenLeft;
4642 pf.top = df.top = of.top = cf.top = mOverscanScreenTop;
4643 pf.right = df.right = of.right = cf.right
Dianne Hackbornc652de82013-02-15 16:32:56 -08004644 = mOverscanScreenLeft + mOverscanScreenWidth;
Dianne Hackbornc4aad012013-02-22 15:05:25 -08004645 pf.bottom = df.bottom = of.bottom = cf.bottom
Dianne Hackbornc652de82013-02-15 16:32:56 -08004646 = mOverscanScreenTop + mOverscanScreenHeight;
Craig Mautner69b08182012-09-05 13:07:13 -07004647 }
Jorim Jaggi225d3b52015-04-01 11:18:57 -07004648 } else if (attrs.type == TYPE_INPUT_METHOD) {
Dianne Hackbornc4aad012013-02-22 15:05:25 -08004649 pf.left = df.left = of.left = cf.left = vf.left = mDockLeft;
4650 pf.top = df.top = of.top = cf.top = vf.top = mDockTop;
4651 pf.right = df.right = of.right = cf.right = vf.right = mDockRight;
John Spurlockc68d5772013-10-08 11:47:58 -04004652 // IM dock windows layout below the nav bar...
John Spurlock57beb3b2013-10-10 10:27:44 -04004653 pf.bottom = df.bottom = of.bottom = mUnrestrictedScreenTop + mUnrestrictedScreenHeight;
John Spurlockc68d5772013-10-08 11:47:58 -04004654 // ...with content insets above the nav bar
4655 cf.bottom = vf.bottom = mStableBottom;
Adrian Roosdd654ea2016-05-27 11:46:10 -07004656 if (mStatusBar != null && mFocusedWindow == mStatusBar && canReceiveInput(mStatusBar)) {
4657 // The status bar forces the navigation bar while it's visible. Make sure the IME
4658 // avoids the navigation bar in that case.
Adrian Roos85d202b2016-06-02 16:27:47 -07004659 if (mNavigationBarPosition == NAV_BAR_RIGHT) {
4660 pf.right = df.right = of.right = cf.right = vf.right = mStableRight;
4661 } else if (mNavigationBarPosition == NAV_BAR_LEFT) {
4662 pf.left = df.left = of.left = cf.left = vf.left = mStableLeft;
4663 }
Adrian Roosdd654ea2016-05-27 11:46:10 -07004664 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004665 // IM dock windows always go to the bottom of the screen.
4666 attrs.gravity = Gravity.BOTTOM;
4667 mDockLayer = win.getSurfaceLayer();
Jorim Jaggi225d3b52015-04-01 11:18:57 -07004668 } else if (attrs.type == TYPE_VOICE_INTERACTION) {
Stefan Kuhne2f280d062015-06-18 07:20:33 -10004669 pf.left = df.left = of.left = mUnrestrictedScreenLeft;
Jorim Jaggi225d3b52015-04-01 11:18:57 -07004670 pf.top = df.top = of.top = mUnrestrictedScreenTop;
Stefan Kuhne2f280d062015-06-18 07:20:33 -10004671 pf.right = df.right = of.right = mUnrestrictedScreenLeft + mUnrestrictedScreenWidth;
4672 pf.bottom = df.bottom = of.bottom = mUnrestrictedScreenTop + mUnrestrictedScreenHeight;
Jorim Jaggi4b74f4d2016-04-27 18:44:08 -07004673 if (adjust != SOFT_INPUT_ADJUST_RESIZE) {
4674 cf.left = mDockLeft;
4675 cf.top = mDockTop;
4676 cf.right = mDockRight;
4677 cf.bottom = mDockBottom;
4678 } else {
4679 cf.left = mContentLeft;
4680 cf.top = mContentTop;
4681 cf.right = mContentRight;
4682 cf.bottom = mContentBottom;
4683 }
4684 if (adjust != SOFT_INPUT_ADJUST_NOTHING) {
4685 vf.left = mCurLeft;
4686 vf.top = mCurTop;
4687 vf.right = mCurRight;
4688 vf.bottom = mCurBottom;
4689 } else {
4690 vf.set(cf);
4691 }
Jorim Jaggi526505d2016-05-24 00:29:19 -07004692 } else if (attrs.type == TYPE_WALLPAPER) {
4693 layoutWallpaper(win, pf, df, of, cf);
Jorim Jaggiaa806142015-05-20 18:04:16 -07004694 } else if (win == mStatusBar) {
Jorim Jaggie0700182014-08-21 01:12:37 +02004695 pf.left = df.left = of.left = mUnrestrictedScreenLeft;
4696 pf.top = df.top = of.top = mUnrestrictedScreenTop;
4697 pf.right = df.right = of.right = mUnrestrictedScreenWidth + mUnrestrictedScreenLeft;
4698 pf.bottom = df.bottom = of.bottom = mUnrestrictedScreenHeight + mUnrestrictedScreenTop;
4699 cf.left = vf.left = mStableLeft;
4700 cf.top = vf.top = mStableTop;
4701 cf.right = vf.right = mStableRight;
4702 vf.bottom = mStableBottom;
Adrian Roosdc5b4532016-01-06 20:49:41 +01004703
4704 if (adjust == SOFT_INPUT_ADJUST_RESIZE) {
4705 cf.bottom = mContentBottom;
4706 } else {
4707 cf.bottom = mDockBottom;
4708 vf.bottom = mContentBottom;
4709 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004710 } else {
John Spurlock46646232013-09-30 22:32:42 -04004711
4712 // Default policy decor for the default display
4713 dcf.left = mSystemLeft;
4714 dcf.top = mSystemTop;
4715 dcf.right = mSystemRight;
4716 dcf.bottom = mSystemBottom;
John Spurlockbd957402013-10-03 11:38:39 -04004717 final boolean inheritTranslucentDecor = (attrs.privateFlags
4718 & WindowManager.LayoutParams.PRIVATE_FLAG_INHERIT_TRANSLUCENT_DECOR) != 0;
John Spurlock65567d42013-10-08 10:08:32 -04004719 final boolean isAppWindow =
4720 attrs.type >= WindowManager.LayoutParams.FIRST_APPLICATION_WINDOW &&
4721 attrs.type <= WindowManager.LayoutParams.LAST_APPLICATION_WINDOW;
4722 final boolean topAtRest =
4723 win == mTopFullscreenOpaqueWindowState && !win.isAnimatingLw();
4724 if (isAppWindow && !inheritTranslucentDecor && !topAtRest) {
John Spurlockbd957402013-10-03 11:38:39 -04004725 if ((sysUiFl & View.SYSTEM_UI_FLAG_FULLSCREEN) == 0
4726 && (fl & WindowManager.LayoutParams.FLAG_FULLSCREEN) == 0
Adrian Roosea562512014-05-05 13:33:03 +02004727 && (fl & WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS) == 0
4728 && (fl & WindowManager.LayoutParams.
Jorim Jaggi4fa78922015-11-30 17:13:56 -08004729 FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS) == 0
Jorim Jaggi8f5701b2016-04-04 18:36:02 -07004730 && (pfl & PRIVATE_FLAG_FORCE_DRAW_STATUS_BAR_BACKGROUND) == 0) {
John Spurlock46646232013-09-30 22:32:42 -04004731 // Ensure policy decor includes status bar
4732 dcf.top = mStableTop;
4733 }
John Spurlockbd957402013-10-03 11:38:39 -04004734 if ((fl & WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION) == 0
Adrian Roosea562512014-05-05 13:33:03 +02004735 && (sysUiFl & View.SYSTEM_UI_FLAG_HIDE_NAVIGATION) == 0
4736 && (fl & WindowManager.LayoutParams.
4737 FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS) == 0) {
John Spurlock46646232013-09-30 22:32:42 -04004738 // Ensure policy decor includes navigation bar
4739 dcf.bottom = mStableBottom;
4740 dcf.right = mStableRight;
4741 }
4742 }
4743
Dianne Hackbornc4aad012013-02-22 15:05:25 -08004744 if ((fl & (FLAG_LAYOUT_IN_SCREEN | FLAG_LAYOUT_INSET_DECOR))
4745 == (FLAG_LAYOUT_IN_SCREEN | FLAG_LAYOUT_INSET_DECOR)) {
RoboErik8a2cfc32014-05-16 11:19:38 -07004746 if (DEBUG_LAYOUT) Slog.v(TAG, "layoutWindowLw(" + attrs.getTitle()
Dianne Hackbornc4aad012013-02-22 15:05:25 -08004747 + "): IN_SCREEN, INSET_DECOR");
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004748 // This is the case for a normal activity window: we want it
4749 // to cover all of the screen space, and it can take care of
4750 // moving its contents to account for screen decorations that
4751 // intrude into that space.
4752 if (attached != null) {
4753 // If this window is attached to another, our display
4754 // frame is the same as the one we are attached to.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08004755 setAttachedWindowFrames(win, fl, adjust, attached, true, pf, df, of, cf, vf);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004756 } else {
Daniel Sandler8956dbb2011-04-22 07:55:02 -04004757 if (attrs.type == TYPE_STATUS_BAR_PANEL
4758 || attrs.type == TYPE_STATUS_BAR_SUB_PANEL) {
Joe Onorato29fc2c92010-11-24 10:26:50 -08004759 // Status bar panels are the only windows who can go on top of
4760 // the status bar. They are protected by the STATUS_BAR_SERVICE
4761 // permission, so they have the same privileges as the status
4762 // bar itself.
Daniel Sandler8956dbb2011-04-22 07:55:02 -04004763 //
Daniel Sandler8e8b4152011-07-21 01:16:43 -04004764 // However, they should still dodge the navigation bar if it exists.
Daniel Sandler8956dbb2011-04-22 07:55:02 -04004765
Dianne Hackbornc4aad012013-02-22 15:05:25 -08004766 pf.left = df.left = of.left = hasNavBar
4767 ? mDockLeft : mUnrestrictedScreenLeft;
4768 pf.top = df.top = of.top = mUnrestrictedScreenTop;
4769 pf.right = df.right = of.right = hasNavBar
4770 ? mRestrictedScreenLeft+mRestrictedScreenWidth
4771 : mUnrestrictedScreenLeft + mUnrestrictedScreenWidth;
4772 pf.bottom = df.bottom = of.bottom = hasNavBar
4773 ? mRestrictedScreenTop+mRestrictedScreenHeight
4774 : mUnrestrictedScreenTop + mUnrestrictedScreenHeight;
Daniel Sandler8956dbb2011-04-22 07:55:02 -04004775
Craig Mautnereda67292013-04-28 13:50:14 -07004776 if (DEBUG_LAYOUT) Slog.v(TAG, String.format(
Daniel Sandler8e8b4152011-07-21 01:16:43 -04004777 "Laying out status bar window: (%d,%d - %d,%d)",
4778 pf.left, pf.top, pf.right, pf.bottom));
John Spurlock46646232013-09-30 22:32:42 -04004779 } else if ((fl & FLAG_LAYOUT_IN_OVERSCAN) != 0
Dianne Hackbornc652de82013-02-15 16:32:56 -08004780 && attrs.type >= WindowManager.LayoutParams.FIRST_APPLICATION_WINDOW
4781 && attrs.type <= WindowManager.LayoutParams.LAST_SUB_WINDOW) {
4782 // Asking to layout into the overscan region, so give it that pure
4783 // unrestricted area.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08004784 pf.left = df.left = of.left = mOverscanScreenLeft;
4785 pf.top = df.top = of.top = mOverscanScreenTop;
4786 pf.right = df.right = of.right = mOverscanScreenLeft + mOverscanScreenWidth;
4787 pf.bottom = df.bottom = of.bottom = mOverscanScreenTop
4788 + mOverscanScreenHeight;
Alan Viverette5a0f4ec2013-10-07 15:10:29 -07004789 } else if (canHideNavigationBar()
Dianne Hackbornf87d1962012-04-04 12:48:24 -07004790 && (sysUiFl & View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION) != 0
Jorim Jaggi380ecb82014-03-14 17:25:20 +01004791 && attrs.type >= WindowManager.LayoutParams.FIRST_APPLICATION_WINDOW
4792 && attrs.type <= WindowManager.LayoutParams.LAST_SUB_WINDOW) {
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07004793 // Asking for layout as if the nav bar is hidden, lets the
Dianne Hackbornc652de82013-02-15 16:32:56 -08004794 // application extend into the unrestricted overscan screen area. We
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07004795 // only do this for application windows to ensure no window that
4796 // can be above the nav bar can do this.
Dianne Hackborn313440842013-02-19 19:22:59 -08004797 pf.left = df.left = mOverscanScreenLeft;
4798 pf.top = df.top = mOverscanScreenTop;
4799 pf.right = df.right = mOverscanScreenLeft + mOverscanScreenWidth;
4800 pf.bottom = df.bottom = mOverscanScreenTop + mOverscanScreenHeight;
Dianne Hackbornc4aad012013-02-22 15:05:25 -08004801 // We need to tell the app about where the frame inside the overscan
4802 // is, so it can inset its content by that amount -- it didn't ask
4803 // to actually extend itself into the overscan region.
4804 of.left = mUnrestrictedScreenLeft;
4805 of.top = mUnrestrictedScreenTop;
4806 of.right = mUnrestrictedScreenLeft + mUnrestrictedScreenWidth;
4807 of.bottom = mUnrestrictedScreenTop + mUnrestrictedScreenHeight;
Joe Onorato29fc2c92010-11-24 10:26:50 -08004808 } else {
Dianne Hackborn313440842013-02-19 19:22:59 -08004809 pf.left = df.left = mRestrictedOverscanScreenLeft;
4810 pf.top = df.top = mRestrictedOverscanScreenTop;
4811 pf.right = df.right = mRestrictedOverscanScreenLeft
4812 + mRestrictedOverscanScreenWidth;
4813 pf.bottom = df.bottom = mRestrictedOverscanScreenTop
4814 + mRestrictedOverscanScreenHeight;
Dianne Hackbornc4aad012013-02-22 15:05:25 -08004815 // We need to tell the app about where the frame inside the overscan
4816 // is, so it can inset its content by that amount -- it didn't ask
4817 // to actually extend itself into the overscan region.
4818 of.left = mUnrestrictedScreenLeft;
4819 of.top = mUnrestrictedScreenTop;
4820 of.right = mUnrestrictedScreenLeft + mUnrestrictedScreenWidth;
4821 of.bottom = mUnrestrictedScreenTop + mUnrestrictedScreenHeight;
Joe Onorato29fc2c92010-11-24 10:26:50 -08004822 }
Craig Mautner69b08182012-09-05 13:07:13 -07004823
John Spurlock46646232013-09-30 22:32:42 -04004824 if ((fl & FLAG_FULLSCREEN) == 0) {
Dianne Hackborne30e02f2014-05-27 18:24:45 -07004825 if (win.isVoiceInteraction()) {
4826 cf.left = mVoiceContentLeft;
4827 cf.top = mVoiceContentTop;
4828 cf.right = mVoiceContentRight;
4829 cf.bottom = mVoiceContentBottom;
Dianne Hackbornc4aad012013-02-22 15:05:25 -08004830 } else {
Dianne Hackborne30e02f2014-05-27 18:24:45 -07004831 if (adjust != SOFT_INPUT_ADJUST_RESIZE) {
4832 cf.left = mDockLeft;
4833 cf.top = mDockTop;
4834 cf.right = mDockRight;
4835 cf.bottom = mDockBottom;
4836 } else {
4837 cf.left = mContentLeft;
4838 cf.top = mContentTop;
4839 cf.right = mContentRight;
4840 cf.bottom = mContentBottom;
4841 }
Dianne Hackbornc4aad012013-02-22 15:05:25 -08004842 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004843 } else {
Dianne Hackbornc4aad012013-02-22 15:05:25 -08004844 // Full screen windows are always given a layout that is as if the
4845 // status bar and other transient decors are gone. This is to avoid
4846 // bad states when moving from a window that is not hding the
4847 // status bar to one that is.
4848 cf.left = mRestrictedScreenLeft;
4849 cf.top = mRestrictedScreenTop;
4850 cf.right = mRestrictedScreenLeft + mRestrictedScreenWidth;
4851 cf.bottom = mRestrictedScreenTop + mRestrictedScreenHeight;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004852 }
Dianne Hackborn5b5cc4d2012-05-16 13:15:00 -07004853 applyStableConstraints(sysUiFl, fl, cf);
Dianne Hackborndea3ef72010-10-28 14:24:22 -07004854 if (adjust != SOFT_INPUT_ADJUST_NOTHING) {
4855 vf.left = mCurLeft;
4856 vf.top = mCurTop;
4857 vf.right = mCurRight;
4858 vf.bottom = mCurBottom;
4859 } else {
4860 vf.set(cf);
4861 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004862 }
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07004863 } else if ((fl & FLAG_LAYOUT_IN_SCREEN) != 0 || (sysUiFl
4864 & (View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
4865 | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION)) != 0) {
Craig Mautnereda67292013-04-28 13:50:14 -07004866 if (DEBUG_LAYOUT) Slog.v(TAG, "layoutWindowLw(" + attrs.getTitle() +
4867 "): IN_SCREEN");
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004868 // A window that has requested to fill the entire screen just
4869 // gets everything, period.
Daniel Sandler8956dbb2011-04-22 07:55:02 -04004870 if (attrs.type == TYPE_STATUS_BAR_PANEL
John Spurlock67a0f852015-06-15 15:35:47 -04004871 || attrs.type == TYPE_STATUS_BAR_SUB_PANEL
4872 || attrs.type == TYPE_VOLUME_OVERLAY) {
Dianne Hackbornc4aad012013-02-22 15:05:25 -08004873 pf.left = df.left = of.left = cf.left = hasNavBar
4874 ? mDockLeft : mUnrestrictedScreenLeft;
4875 pf.top = df.top = of.top = cf.top = mUnrestrictedScreenTop;
4876 pf.right = df.right = of.right = cf.right = hasNavBar
Daniel Sandler8e8b4152011-07-21 01:16:43 -04004877 ? mRestrictedScreenLeft+mRestrictedScreenWidth
Dianne Hackbornc652de82013-02-15 16:32:56 -08004878 : mUnrestrictedScreenLeft + mUnrestrictedScreenWidth;
Dianne Hackbornc4aad012013-02-22 15:05:25 -08004879 pf.bottom = df.bottom = of.bottom = cf.bottom = hasNavBar
Daniel Sandler8e8b4152011-07-21 01:16:43 -04004880 ? mRestrictedScreenTop+mRestrictedScreenHeight
Dianne Hackbornc652de82013-02-15 16:32:56 -08004881 : mUnrestrictedScreenTop + mUnrestrictedScreenHeight;
Craig Mautnereda67292013-04-28 13:50:14 -07004882 if (DEBUG_LAYOUT) Slog.v(TAG, String.format(
Daniel Sandler36412a72011-08-04 09:35:13 -04004883 "Laying out IN_SCREEN status bar window: (%d,%d - %d,%d)",
4884 pf.left, pf.top, pf.right, pf.bottom));
Jim Millere898ac52012-04-06 17:10:57 -07004885 } else if (attrs.type == TYPE_NAVIGATION_BAR
4886 || attrs.type == TYPE_NAVIGATION_BAR_PANEL) {
Daniel Sandler8e8b4152011-07-21 01:16:43 -04004887 // The navigation bar has Real Ultimate Power.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08004888 pf.left = df.left = of.left = mUnrestrictedScreenLeft;
4889 pf.top = df.top = of.top = mUnrestrictedScreenTop;
4890 pf.right = df.right = of.right = mUnrestrictedScreenLeft
4891 + mUnrestrictedScreenWidth;
4892 pf.bottom = df.bottom = of.bottom = mUnrestrictedScreenTop
4893 + mUnrestrictedScreenHeight;
Craig Mautnereda67292013-04-28 13:50:14 -07004894 if (DEBUG_LAYOUT) Slog.v(TAG, String.format(
Daniel Sandler8e8b4152011-07-21 01:16:43 -04004895 "Laying out navigation bar window: (%d,%d - %d,%d)",
4896 pf.left, pf.top, pf.right, pf.bottom));
Dianne Hackborn01011c32012-02-21 13:54:21 -08004897 } else if ((attrs.type == TYPE_SECURE_SYSTEM_OVERLAY
Muyuan Li6ca619f2016-03-08 13:30:42 -08004898 || attrs.type == TYPE_BOOT_PROGRESS
4899 || attrs.type == TYPE_SCREENSHOT)
Jeff Brownbfcb60a2011-09-08 18:51:14 -07004900 && ((fl & FLAG_FULLSCREEN) != 0)) {
Muyuan Li6ca619f2016-03-08 13:30:42 -08004901 // Fullscreen secure system overlays get what they ask for. Screenshot region
4902 // selection overlay should also expand to full screen.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08004903 pf.left = df.left = of.left = cf.left = mOverscanScreenLeft;
4904 pf.top = df.top = of.top = cf.top = mOverscanScreenTop;
4905 pf.right = df.right = of.right = cf.right = mOverscanScreenLeft
4906 + mOverscanScreenWidth;
4907 pf.bottom = df.bottom = of.bottom = cf.bottom = mOverscanScreenTop
4908 + mOverscanScreenHeight;
Craig Mautner165be0c2015-01-27 15:16:58 -08004909 } else if (attrs.type == TYPE_BOOT_PROGRESS) {
Dianne Hackborn01011c32012-02-21 13:54:21 -08004910 // Boot progress screen always covers entire display.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08004911 pf.left = df.left = of.left = cf.left = mOverscanScreenLeft;
4912 pf.top = df.top = of.top = cf.top = mOverscanScreenTop;
4913 pf.right = df.right = of.right = cf.right = mOverscanScreenLeft
4914 + mOverscanScreenWidth;
4915 pf.bottom = df.bottom = of.bottom = cf.bottom = mOverscanScreenTop
4916 + mOverscanScreenHeight;
John Spurlock46646232013-09-30 22:32:42 -04004917 } else if ((fl & FLAG_LAYOUT_IN_OVERSCAN) != 0
Dianne Hackbornc652de82013-02-15 16:32:56 -08004918 && attrs.type >= WindowManager.LayoutParams.FIRST_APPLICATION_WINDOW
4919 && attrs.type <= WindowManager.LayoutParams.LAST_SUB_WINDOW) {
4920 // Asking to layout into the overscan region, so give it that pure
4921 // unrestricted area.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08004922 pf.left = df.left = of.left = cf.left = mOverscanScreenLeft;
4923 pf.top = df.top = of.top = cf.top = mOverscanScreenTop;
4924 pf.right = df.right = of.right = cf.right
Dianne Hackbornc652de82013-02-15 16:32:56 -08004925 = mOverscanScreenLeft + mOverscanScreenWidth;
Dianne Hackbornc4aad012013-02-22 15:05:25 -08004926 pf.bottom = df.bottom = of.bottom = cf.bottom
Dianne Hackbornc652de82013-02-15 16:32:56 -08004927 = mOverscanScreenTop + mOverscanScreenHeight;
Alan Viverette5a0f4ec2013-10-07 15:10:29 -07004928 } else if (canHideNavigationBar()
Dianne Hackbornf87d1962012-04-04 12:48:24 -07004929 && (sysUiFl & View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION) != 0
Craig Mautnerbeac1062014-06-03 14:38:57 -07004930 && (attrs.type == TYPE_STATUS_BAR
4931 || attrs.type == TYPE_TOAST
Jorim Jaggi81fe2d12015-12-21 14:45:18 +01004932 || attrs.type == TYPE_DOCK_DIVIDER
Jorim Jaggi2fdeeab2015-04-01 15:13:03 -07004933 || attrs.type == TYPE_VOICE_INTERACTION_STARTING
John Spurlock34e13d92013-08-10 06:52:28 -04004934 || (attrs.type >= WindowManager.LayoutParams.FIRST_APPLICATION_WINDOW
4935 && attrs.type <= WindowManager.LayoutParams.LAST_SUB_WINDOW))) {
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07004936 // Asking for layout as if the nav bar is hidden, lets the
4937 // application extend into the unrestricted screen area. We
John Spurlock34e13d92013-08-10 06:52:28 -04004938 // only do this for application windows (or toasts) to ensure no window that
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07004939 // can be above the nav bar can do this.
4940 // XXX This assumes that an app asking for this will also
4941 // ask for layout in only content. We can't currently figure out
4942 // what the screen would be if only laying out to hide the nav bar.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08004943 pf.left = df.left = of.left = cf.left = mUnrestrictedScreenLeft;
4944 pf.top = df.top = of.top = cf.top = mUnrestrictedScreenTop;
4945 pf.right = df.right = of.right = cf.right = mUnrestrictedScreenLeft
4946 + mUnrestrictedScreenWidth;
4947 pf.bottom = df.bottom = of.bottom = cf.bottom = mUnrestrictedScreenTop
4948 + mUnrestrictedScreenHeight;
Jorim Jaggi9f6798a2016-02-10 22:16:06 -08004949 } else if ((sysUiFl & View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN) != 0) {
4950 pf.left = df.left = of.left = mRestrictedScreenLeft;
4951 pf.top = df.top = of.top = mRestrictedScreenTop;
4952 pf.right = df.right = of.right = mRestrictedScreenLeft + mRestrictedScreenWidth;
4953 pf.bottom = df.bottom = of.bottom = mRestrictedScreenTop
4954 + mRestrictedScreenHeight;
4955 if (adjust != SOFT_INPUT_ADJUST_RESIZE) {
4956 cf.left = mDockLeft;
4957 cf.top = mDockTop;
4958 cf.right = mDockRight;
4959 cf.bottom = mDockBottom;
4960 } else {
4961 cf.left = mContentLeft;
4962 cf.top = mContentTop;
4963 cf.right = mContentRight;
4964 cf.bottom = mContentBottom;
4965 }
Joe Onorato29fc2c92010-11-24 10:26:50 -08004966 } else {
Dianne Hackbornc4aad012013-02-22 15:05:25 -08004967 pf.left = df.left = of.left = cf.left = mRestrictedScreenLeft;
4968 pf.top = df.top = of.top = cf.top = mRestrictedScreenTop;
4969 pf.right = df.right = of.right = cf.right = mRestrictedScreenLeft
4970 + mRestrictedScreenWidth;
4971 pf.bottom = df.bottom = of.bottom = cf.bottom = mRestrictedScreenTop
4972 + mRestrictedScreenHeight;
Joe Onorato29fc2c92010-11-24 10:26:50 -08004973 }
Craig Mautner69b08182012-09-05 13:07:13 -07004974
Dianne Hackborn5b5cc4d2012-05-16 13:15:00 -07004975 applyStableConstraints(sysUiFl, fl, cf);
Craig Mautner69b08182012-09-05 13:07:13 -07004976
Dianne Hackborndea3ef72010-10-28 14:24:22 -07004977 if (adjust != SOFT_INPUT_ADJUST_NOTHING) {
4978 vf.left = mCurLeft;
4979 vf.top = mCurTop;
4980 vf.right = mCurRight;
4981 vf.bottom = mCurBottom;
4982 } else {
4983 vf.set(cf);
4984 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004985 } else if (attached != null) {
Craig Mautnereda67292013-04-28 13:50:14 -07004986 if (DEBUG_LAYOUT) Slog.v(TAG, "layoutWindowLw(" + attrs.getTitle() +
4987 "): attached to " + attached);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004988 // A child window should be placed inside of the same visible
4989 // frame that its parent had.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08004990 setAttachedWindowFrames(win, fl, adjust, attached, false, pf, df, of, cf, vf);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004991 } else {
Craig Mautnereda67292013-04-28 13:50:14 -07004992 if (DEBUG_LAYOUT) Slog.v(TAG, "layoutWindowLw(" + attrs.getTitle() +
4993 "): normal window");
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004994 // Otherwise, a normal window must be placed inside the content
4995 // of all screen decorations.
John Spurlock67a0f852015-06-15 15:35:47 -04004996 if (attrs.type == TYPE_STATUS_BAR_PANEL || attrs.type == TYPE_VOLUME_OVERLAY) {
4997 // Status bar panels and the volume dialog are the only windows who can go on
4998 // top of the status bar. They are protected by the STATUS_BAR_SERVICE
Dianne Hackborna239c842011-06-01 12:28:20 -07004999 // permission, so they have the same privileges as the status
5000 // bar itself.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08005001 pf.left = df.left = of.left = cf.left = mRestrictedScreenLeft;
5002 pf.top = df.top = of.top = cf.top = mRestrictedScreenTop;
5003 pf.right = df.right = of.right = cf.right = mRestrictedScreenLeft
5004 + mRestrictedScreenWidth;
5005 pf.bottom = df.bottom = of.bottom = cf.bottom = mRestrictedScreenTop
5006 + mRestrictedScreenHeight;
John Spurlock67a0f852015-06-15 15:35:47 -04005007 } else if (attrs.type == TYPE_TOAST || attrs.type == TYPE_SYSTEM_ALERT) {
John Spurlock414c1f02013-12-04 13:47:36 -05005008 // These dialogs are stable to interim decor changes.
John Spurlockbd957402013-10-03 11:38:39 -04005009 pf.left = df.left = of.left = cf.left = mStableLeft;
5010 pf.top = df.top = of.top = cf.top = mStableTop;
5011 pf.right = df.right = of.right = cf.right = mStableRight;
5012 pf.bottom = df.bottom = of.bottom = cf.bottom = mStableBottom;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005013 } else {
Dianne Hackborna239c842011-06-01 12:28:20 -07005014 pf.left = mContentLeft;
5015 pf.top = mContentTop;
5016 pf.right = mContentRight;
5017 pf.bottom = mContentBottom;
Dianne Hackborn20d94742014-05-29 18:35:45 -07005018 if (win.isVoiceInteraction()) {
5019 df.left = of.left = cf.left = mVoiceContentLeft;
5020 df.top = of.top = cf.top = mVoiceContentTop;
5021 df.right = of.right = cf.right = mVoiceContentRight;
5022 df.bottom = of.bottom = cf.bottom = mVoiceContentBottom;
5023 } else if (adjust != SOFT_INPUT_ADJUST_RESIZE) {
Dianne Hackbornc4aad012013-02-22 15:05:25 -08005024 df.left = of.left = cf.left = mDockLeft;
5025 df.top = of.top = cf.top = mDockTop;
5026 df.right = of.right = cf.right = mDockRight;
5027 df.bottom = of.bottom = cf.bottom = mDockBottom;
Dianne Hackborna239c842011-06-01 12:28:20 -07005028 } else {
Dianne Hackbornc4aad012013-02-22 15:05:25 -08005029 df.left = of.left = cf.left = mContentLeft;
5030 df.top = of.top = cf.top = mContentTop;
5031 df.right = of.right = cf.right = mContentRight;
5032 df.bottom = of.bottom = cf.bottom = mContentBottom;
Dianne Hackborna239c842011-06-01 12:28:20 -07005033 }
5034 if (adjust != SOFT_INPUT_ADJUST_NOTHING) {
5035 vf.left = mCurLeft;
5036 vf.top = mCurTop;
5037 vf.right = mCurRight;
5038 vf.bottom = mCurBottom;
5039 } else {
5040 vf.set(cf);
5041 }
Dianne Hackborndea3ef72010-10-28 14:24:22 -07005042 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005043 }
5044 }
Craig Mautner69b08182012-09-05 13:07:13 -07005045
Craig Mautnerb816bed2013-07-23 10:26:17 -07005046 // TYPE_SYSTEM_ERROR is above the NavigationBar so it can't be allowed to extend over it.
Wale Ogunwale9185fb02016-03-11 18:06:14 -08005047 // Also, we don't allow windows in multi-window mode to extend out of the screen.
5048 if ((fl & FLAG_LAYOUT_NO_LIMITS) != 0 && attrs.type != TYPE_SYSTEM_ERROR
Andrii Kulian933076d2016-03-29 17:04:42 -07005049 && !win.isInMultiWindowMode()) {
Dianne Hackborn067e5f62014-09-07 23:14:30 -07005050 df.left = df.top = -10000;
5051 df.right = df.bottom = 10000;
5052 if (attrs.type != TYPE_WALLPAPER) {
5053 of.left = of.top = cf.left = cf.top = vf.left = vf.top = -10000;
5054 of.right = of.bottom = cf.right = cf.bottom = vf.right = vf.bottom = 10000;
5055 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005056 }
5057
Filip Gruszczynski2217f612015-05-26 11:32:08 -07005058 // If the device has a chin (e.g. some watches), a dead area at the bottom of the screen we
5059 // need to provide information to the clients that want to pretend that you can draw there.
Filip Gruszczynskib0c673b2015-06-05 09:43:06 -07005060 // We only want to apply outsets to certain types of windows. For example, we never want to
5061 // apply the outsets to floating dialogs, because they wouldn't make sense there.
Filip Gruszczynski2987f612015-06-30 15:03:30 -07005062 final boolean useOutsets = shouldUseOutsets(attrs, fl);
Filip Gruszczynskib0c673b2015-06-05 09:43:06 -07005063 if (isDefaultDisplay && useOutsets) {
Filip Gruszczynski2217f612015-05-26 11:32:08 -07005064 osf = mTmpOutsetFrame;
5065 osf.set(cf.left, cf.top, cf.right, cf.bottom);
5066 int outset = ScreenShapeHelper.getWindowOutsetBottomPx(mContext.getResources());
5067 if (outset > 0) {
Filip Gruszczynski2987f612015-06-30 15:03:30 -07005068 int rotation = mDisplayRotation;
Filip Gruszczynski2217f612015-05-26 11:32:08 -07005069 if (rotation == Surface.ROTATION_0) {
5070 osf.bottom += outset;
5071 } else if (rotation == Surface.ROTATION_90) {
5072 osf.right += outset;
5073 } else if (rotation == Surface.ROTATION_180) {
5074 osf.top -= outset;
5075 } else if (rotation == Surface.ROTATION_270) {
5076 osf.left -= outset;
5077 }
5078 if (DEBUG_LAYOUT) Slog.v(TAG, "applying bottom outset of " + outset
5079 + " with rotation " + rotation + ", result: " + osf);
5080 }
5081 }
5082
Craig Mautnereda67292013-04-28 13:50:14 -07005083 if (DEBUG_LAYOUT) Slog.v(TAG, "Compute frame " + attrs.getTitle()
The Android Open Source Project11267662009-03-18 17:39:47 -07005084 + ": sim=#" + Integer.toHexString(sim)
RoboErik8a2cfc32014-05-16 11:19:38 -07005085 + " attach=" + attached + " type=" + attrs.type
Daniel Sandler8956dbb2011-04-22 07:55:02 -04005086 + String.format(" flags=0x%08x", fl)
The Android Open Source Project11267662009-03-18 17:39:47 -07005087 + " pf=" + pf.toShortString() + " df=" + df.toShortString()
Dianne Hackbornc4aad012013-02-22 15:05:25 -08005088 + " of=" + of.toShortString()
John Spurlock46646232013-09-30 22:32:42 -04005089 + " cf=" + cf.toShortString() + " vf=" + vf.toShortString()
Adrian Roosfa104232014-06-20 16:10:14 -07005090 + " dcf=" + dcf.toShortString()
Filip Gruszczynski2217f612015-05-26 11:32:08 -07005091 + " sf=" + sf.toShortString()
5092 + " osf=" + (osf == null ? "null" : osf.toShortString()));
Craig Mautner69b08182012-09-05 13:07:13 -07005093
Filip Gruszczynski2217f612015-05-26 11:32:08 -07005094 win.computeFrameLw(pf, df, of, cf, vf, dcf, sf, osf);
Craig Mautner69b08182012-09-05 13:07:13 -07005095
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005096 // Dock windows carve out the bottom of the screen, so normal windows
5097 // can't appear underneath them.
Jorim Jaggib0d27342016-11-01 16:10:42 -07005098 if (attrs.type == TYPE_INPUT_METHOD && win.isVisibleLw()
5099 && !win.getGivenInsetsPendingLw()) {
satok1bc0a492012-04-25 22:47:12 +09005100 setLastInputMethodWindowLw(null, null);
5101 offsetInputMethodWindowLw(win);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005102 }
Jorim Jaggib0d27342016-11-01 16:10:42 -07005103 if (attrs.type == TYPE_VOICE_INTERACTION && win.isVisibleLw()
Dianne Hackborne30e02f2014-05-27 18:24:45 -07005104 && !win.getGivenInsetsPendingLw()) {
5105 offsetVoiceInputWindowLw(win);
5106 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005107 }
5108
Jorim Jaggi526505d2016-05-24 00:29:19 -07005109 private void layoutWallpaper(WindowState win, Rect pf, Rect df, Rect of, Rect cf) {
5110
5111 // The wallpaper also has Real Ultimate Power, but we want to tell
5112 // it about the overscan area.
5113 pf.left = df.left = mOverscanScreenLeft;
5114 pf.top = df.top = mOverscanScreenTop;
5115 pf.right = df.right = mOverscanScreenLeft + mOverscanScreenWidth;
5116 pf.bottom = df.bottom = mOverscanScreenTop + mOverscanScreenHeight;
5117 of.left = cf.left = mUnrestrictedScreenLeft;
5118 of.top = cf.top = mUnrestrictedScreenTop;
5119 of.right = cf.right = mUnrestrictedScreenLeft + mUnrestrictedScreenWidth;
5120 of.bottom = cf.bottom = mUnrestrictedScreenTop + mUnrestrictedScreenHeight;
5121 }
5122
satok1bc0a492012-04-25 22:47:12 +09005123 private void offsetInputMethodWindowLw(WindowState win) {
Craig Mautner4774f6a2015-03-23 11:42:55 -07005124 int top = Math.max(win.getDisplayFrameLw().top, win.getContentFrameLw().top);
satok1bc0a492012-04-25 22:47:12 +09005125 top += win.getGivenContentInsetsLw().top;
5126 if (mContentBottom > top) {
5127 mContentBottom = top;
5128 }
Dianne Hackborne30e02f2014-05-27 18:24:45 -07005129 if (mVoiceContentBottom > top) {
5130 mVoiceContentBottom = top;
5131 }
satok1bc0a492012-04-25 22:47:12 +09005132 top = win.getVisibleFrameLw().top;
5133 top += win.getGivenVisibleInsetsLw().top;
5134 if (mCurBottom > top) {
5135 mCurBottom = top;
5136 }
Craig Mautnereda67292013-04-28 13:50:14 -07005137 if (DEBUG_LAYOUT) Slog.v(TAG, "Input method: mDockBottom="
satok1bc0a492012-04-25 22:47:12 +09005138 + mDockBottom + " mContentBottom="
5139 + mContentBottom + " mCurBottom=" + mCurBottom);
5140 }
5141
Dianne Hackborne30e02f2014-05-27 18:24:45 -07005142 private void offsetVoiceInputWindowLw(WindowState win) {
Craig Mautner4774f6a2015-03-23 11:42:55 -07005143 int top = Math.max(win.getDisplayFrameLw().top, win.getContentFrameLw().top);
Dianne Hackbornae6688b2015-02-11 17:02:41 -08005144 top += win.getGivenContentInsetsLw().top;
5145 if (mVoiceContentBottom > top) {
5146 mVoiceContentBottom = top;
Dianne Hackborne30e02f2014-05-27 18:24:45 -07005147 }
5148 }
5149
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005150 /** {@inheritDoc} */
Craig Mautner61ac6bb2012-02-02 17:29:33 -08005151 @Override
5152 public void finishLayoutLw() {
5153 return;
Dianne Hackborn5f3063e2010-03-10 16:01:58 -08005154 }
5155
5156 /** {@inheritDoc} */
Craig Mautnerad09bcc2012-10-08 13:33:11 -07005157 @Override
Craig Mautner39834192012-09-02 07:47:24 -07005158 public void beginPostLayoutPolicyLw(int displayWidth, int displayHeight) {
Dianne Hackborn5f3063e2010-03-10 16:01:58 -08005159 mTopFullscreenOpaqueWindowState = null;
Adrian Rooscd3884d2015-02-18 17:25:23 +01005160 mTopFullscreenOpaqueOrDimmingWindowState = null;
Jorim Jaggi86905582016-02-09 21:36:09 -08005161 mTopDockedOpaqueWindowState = null;
5162 mTopDockedOpaqueOrDimmingWindowState = null;
Dianne Hackborn5f3063e2010-03-10 16:01:58 -08005163 mForceStatusBar = false;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07005164 mForceStatusBarFromKeyguard = false;
Selim Cinek4a4a2bddc2015-05-07 12:50:19 -07005165 mForceStatusBarTransparent = false;
Dianne Hackborn891d3fb2013-01-09 18:31:37 -08005166 mForcingShowNavBar = false;
5167 mForcingShowNavBarLayer = -1;
RoboErik8a2cfc32014-05-16 11:19:38 -07005168
Dianne Hackborn5f3063e2010-03-10 16:01:58 -08005169 mAllowLockscreenWhenOn = false;
Dianne Hackborn7ad44382012-10-18 17:46:00 -07005170 mShowingDream = false;
Dianne Hackborn5f3063e2010-03-10 16:01:58 -08005171 }
5172
5173 /** {@inheritDoc} */
Craig Mautnerad09bcc2012-10-08 13:33:11 -07005174 @Override
Yohei Yukawad1a09222015-06-30 16:22:05 -07005175 public void applyPostLayoutPolicyLw(WindowState win, WindowManager.LayoutParams attrs,
Jorim Jaggife762342016-10-13 14:33:27 +02005176 WindowState attached, WindowState imeTarget) {
Jorim Jaggi02886a82016-12-06 09:10:06 -08005177 final boolean visible = !win.isGoneForLayoutLw();
Jorim Jaggib0d27342016-11-01 16:10:42 -07005178 if (DEBUG_LAYOUT) Slog.i(TAG, "Win " + win + ": isVisible=" + visible);
Jorim Jaggife762342016-10-13 14:33:27 +02005179 applyKeyguardPolicyLw(win, imeTarget);
John Spurlockc6d1c602014-01-17 15:22:06 -05005180 final int fl = PolicyControl.getWindowFlags(win, attrs);
Jorim Jaggib0d27342016-11-01 16:10:42 -07005181 if (mTopFullscreenOpaqueWindowState == null && visible && attrs.type == TYPE_INPUT_METHOD) {
John Spurlock414c1f02013-12-04 13:47:36 -05005182 mForcingShowNavBar = true;
5183 mForcingShowNavBarLayer = win.getSurfaceLayer();
Dianne Hackborn891d3fb2013-01-09 18:31:37 -08005184 }
Selim Cinek4a4a2bddc2015-05-07 12:50:19 -07005185 if (attrs.type == TYPE_STATUS_BAR) {
5186 if ((attrs.privateFlags & PRIVATE_FLAG_KEYGUARD) != 0) {
5187 mForceStatusBarFromKeyguard = true;
5188 }
5189 if ((attrs.privateFlags & PRIVATE_FLAG_FORCE_STATUS_BAR_VISIBLE_TRANSPARENT) != 0) {
5190 mForceStatusBarTransparent = true;
5191 }
Jorim Jaggiafd4a552014-04-08 15:13:05 +02005192 }
Adrian Roos602c68e2015-04-24 16:03:47 -07005193
Jorim Jaggi02886a82016-12-06 09:10:06 -08005194 // Don't allow snapshots to influence SystemUI visibility flags.
5195 // TODO: Revisit this once SystemUI flags for snapshots are handled correctly
Adrian Roos602c68e2015-04-24 16:03:47 -07005196 boolean appWindow = attrs.type >= FIRST_APPLICATION_WINDOW
Jorim Jaggi02886a82016-12-06 09:10:06 -08005197 && attrs.type < FIRST_SYSTEM_WINDOW
5198 && (attrs.privateFlags & PRIVATE_FLAG_TASK_SNAPSHOT) == 0;
Jorim Jaggi86905582016-02-09 21:36:09 -08005199 final int stackId = win.getStackId();
Jorim Jaggib0d27342016-11-01 16:10:42 -07005200 if (mTopFullscreenOpaqueWindowState == null && visible) {
John Spurlockc6d1c602014-01-17 15:22:06 -05005201 if ((fl & FLAG_FORCE_NOT_FULLSCREEN) != 0) {
Jorim Jaggife762342016-10-13 14:33:27 +02005202 mForceStatusBar = true;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07005203 }
Dianne Hackborn7ad44382012-10-18 17:46:00 -07005204 if (attrs.type == TYPE_DREAM) {
Jeff Brownc8018eb2012-10-29 21:33:27 -07005205 // If the lockscreen was showing when the dream started then wait
5206 // for the dream to draw before hiding the lockscreen.
5207 if (!mDreamingLockscreen
5208 || (win.isVisibleLw() && win.hasDrawnLw())) {
5209 mShowingDream = true;
Craig Mautnerab55e522014-03-03 13:26:03 -08005210 appWindow = true;
Dianne Hackborn7ad44382012-10-18 17:46:00 -07005211 }
5212 }
Craig Mautnerab55e522014-03-03 13:26:03 -08005213
Yohei Yukawad1a09222015-06-30 16:22:05 -07005214 // For app windows that are not attached, we decide if all windows in the app they
5215 // represent should be hidden or if we should hide the lockscreen. For attached app
5216 // windows we defer the decision to the window it is attached to.
5217 if (appWindow && attached == null) {
Jorim Jaggi86905582016-02-09 21:36:09 -08005218 if (isFullscreen(attrs) && StackId.normallyFullscreenWindows(stackId)) {
Craig Mautnerab55e522014-03-03 13:26:03 -08005219 if (DEBUG_LAYOUT) Slog.v(TAG, "Fullscreen window: " + win);
5220 mTopFullscreenOpaqueWindowState = win;
Adrian Rooscd3884d2015-02-18 17:25:23 +01005221 if (mTopFullscreenOpaqueOrDimmingWindowState == null) {
5222 mTopFullscreenOpaqueOrDimmingWindowState = win;
5223 }
Craig Mautner00156ec2014-03-06 22:29:02 -08005224 if ((fl & FLAG_ALLOW_LOCK_WHILE_SCREEN_ON) != 0) {
Craig Mautnerab55e522014-03-03 13:26:03 -08005225 mAllowLockscreenWhenOn = true;
5226 }
Dianne Hackborn5f3063e2010-03-10 16:01:58 -08005227 }
Adrian Roos602c68e2015-04-24 16:03:47 -07005228 }
Dianne Hackborn5f3063e2010-03-10 16:01:58 -08005229 }
Jorim Jaggi86905582016-02-09 21:36:09 -08005230
Jorim Jaggi90859bc2016-06-28 16:25:23 -07005231 // Voice interaction overrides both top fullscreen and top docked.
Jorim Jaggib0d27342016-11-01 16:10:42 -07005232 if (visible && win.getAttrs().type == TYPE_VOICE_INTERACTION) {
Jorim Jaggi90859bc2016-06-28 16:25:23 -07005233 if (mTopFullscreenOpaqueWindowState == null) {
5234 mTopFullscreenOpaqueWindowState = win;
5235 if (mTopFullscreenOpaqueOrDimmingWindowState == null) {
5236 mTopFullscreenOpaqueOrDimmingWindowState = win;
5237 }
5238 }
5239 if (mTopDockedOpaqueWindowState == null) {
5240 mTopDockedOpaqueWindowState = win;
5241 if (mTopDockedOpaqueOrDimmingWindowState == null) {
5242 mTopDockedOpaqueOrDimmingWindowState = win;
5243 }
5244 }
5245 }
5246
5247 // Keep track of the window if it's dimming but not necessarily fullscreen.
Jorim Jaggib0d27342016-11-01 16:10:42 -07005248 if (mTopFullscreenOpaqueOrDimmingWindowState == null && visible
Jorim Jaggi86905582016-02-09 21:36:09 -08005249 && win.isDimming() && StackId.normallyFullscreenWindows(stackId)) {
Adrian Rooscd3884d2015-02-18 17:25:23 +01005250 mTopFullscreenOpaqueOrDimmingWindowState = win;
5251 }
Jorim Jaggi86905582016-02-09 21:36:09 -08005252
5253 // We need to keep track of the top "fullscreen" opaque window for the docked stack
5254 // separately, because both the "real fullscreen" opaque window and the one for the docked
5255 // stack can control View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR.
Jorim Jaggib0d27342016-11-01 16:10:42 -07005256 if (mTopDockedOpaqueWindowState == null && visible && appWindow && attached == null
Jorim Jaggi86905582016-02-09 21:36:09 -08005257 && isFullscreen(attrs) && stackId == DOCKED_STACK_ID) {
5258 mTopDockedOpaqueWindowState = win;
5259 if (mTopDockedOpaqueOrDimmingWindowState == null) {
5260 mTopDockedOpaqueOrDimmingWindowState = win;
5261 }
5262 }
5263
5264 // Also keep track of any windows that are dimming but not necessarily fullscreen in the
5265 // docked stack.
Jorim Jaggib0d27342016-11-01 16:10:42 -07005266 if (mTopDockedOpaqueOrDimmingWindowState == null && visible && win.isDimming()
Jorim Jaggi86905582016-02-09 21:36:09 -08005267 && stackId == DOCKED_STACK_ID) {
5268 mTopDockedOpaqueOrDimmingWindowState = win;
5269 }
5270 }
5271
Jorim Jaggife762342016-10-13 14:33:27 +02005272 private void applyKeyguardPolicyLw(WindowState win, WindowState imeTarget) {
5273 if (canBeHiddenByKeyguardLw(win)) {
5274 if (shouldBeHiddenByKeyguard(win, imeTarget)) {
5275 win.hideLw(false /* doAnimation */);
5276 } else {
5277 win.showLw(false /* doAnimation */);
5278 }
5279 }
5280 }
5281
Jorim Jaggi86905582016-02-09 21:36:09 -08005282 private boolean isFullscreen(WindowManager.LayoutParams attrs) {
5283 return attrs.x == 0 && attrs.y == 0
5284 && attrs.width == WindowManager.LayoutParams.MATCH_PARENT
5285 && attrs.height == WindowManager.LayoutParams.MATCH_PARENT;
Dianne Hackborn5f3063e2010-03-10 16:01:58 -08005286 }
5287
5288 /** {@inheritDoc} */
Craig Mautnerad09bcc2012-10-08 13:33:11 -07005289 @Override
Craig Mautner39834192012-09-02 07:47:24 -07005290 public int finishPostLayoutPolicyLw() {
Dianne Hackborn39c2d712009-09-22 11:41:31 -07005291 int changes = 0;
Joe Onorato93056472010-09-10 10:30:46 -04005292 boolean topIsFullscreen = false;
Daniel Sandlere02d8082010-10-08 15:13:22 -04005293
5294 final WindowManager.LayoutParams lp = (mTopFullscreenOpaqueWindowState != null)
5295 ? mTopFullscreenOpaqueWindowState.getAttrs()
5296 : null;
5297
Jeff Brownc8018eb2012-10-29 21:33:27 -07005298 // If we are not currently showing a dream then remember the current
5299 // lockscreen state. We will use this to determine whether the dream
5300 // started while the lockscreen was showing and remember this state
5301 // while the dream is showing.
Dianne Hackborn7ad44382012-10-18 17:46:00 -07005302 if (!mShowingDream) {
Jorim Jaggi8d786932016-10-26 19:08:36 -07005303 mDreamingLockscreen = isKeyguardShowingAndNotOccluded();
Jeff Brown061ea992015-04-17 19:55:47 -07005304 if (mDreamingSleepTokenNeeded) {
5305 mDreamingSleepTokenNeeded = false;
5306 mHandler.obtainMessage(MSG_UPDATE_DREAMING_SLEEP_TOKEN, 0, 1).sendToTarget();
5307 }
5308 } else {
5309 if (!mDreamingSleepTokenNeeded) {
5310 mDreamingSleepTokenNeeded = true;
5311 mHandler.obtainMessage(MSG_UPDATE_DREAMING_SLEEP_TOKEN, 1, 1).sendToTarget();
5312 }
Dianne Hackborn7ad44382012-10-18 17:46:00 -07005313 }
5314
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005315 if (mStatusBar != null) {
Craig Mautnereda67292013-04-28 13:50:14 -07005316 if (DEBUG_LAYOUT) Slog.i(TAG, "force=" + mForceStatusBar
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07005317 + " forcefkg=" + mForceStatusBarFromKeyguard
Dianne Hackbornd70bc2f2009-10-06 23:25:51 -07005318 + " top=" + mTopFullscreenOpaqueWindowState);
Selim Cinek4a4a2bddc2015-05-07 12:50:19 -07005319 boolean shouldBeTransparent = mForceStatusBarTransparent
5320 && !mForceStatusBar
5321 && !mForceStatusBarFromKeyguard;
5322 if (!shouldBeTransparent) {
5323 mStatusBarController.setShowTransparent(false /* transparent */);
5324 } else if (!mStatusBar.isVisibleLw()) {
5325 mStatusBarController.setShowTransparent(true /* transparent */);
5326 }
Adrian Roosdb1bc6b2016-04-14 17:49:43 -07005327
5328 WindowManager.LayoutParams statusBarAttrs = mStatusBar.getAttrs();
5329 boolean statusBarExpanded = statusBarAttrs.height == MATCH_PARENT
5330 && statusBarAttrs.width == MATCH_PARENT;
5331 if (mForceStatusBar || mForceStatusBarFromKeyguard || mForceStatusBarTransparent
5332 || statusBarExpanded) {
Craig Mautnereda67292013-04-28 13:50:14 -07005333 if (DEBUG_LAYOUT) Slog.v(TAG, "Showing status bar: forced");
John Spurlock27735a42013-08-14 17:57:38 -04005334 if (mStatusBarController.setBarShowingLw(true)) {
5335 changes |= FINISH_LAYOUT_REDO_LAYOUT;
5336 }
Craig Mautner81defc72013-10-29 11:10:42 -07005337 // Maintain fullscreen layout until incoming animation is complete.
5338 topIsFullscreen = mTopIsFullscreen && mStatusBar.isAnimatingLw();
John Spurlockf92b6162013-11-11 15:01:16 -05005339 // Transient status bar on the lockscreen is not allowed
5340 if (mForceStatusBarFromKeyguard && mStatusBarController.isTransientShowing()) {
5341 mStatusBarController.updateVisibilityLw(false /*transientAllowed*/,
5342 mLastSystemUiFlags, mLastSystemUiFlags);
5343 }
Adrian Roosdb1bc6b2016-04-14 17:49:43 -07005344 if (statusBarExpanded && mNavigationBar != null) {
5345 if (mNavigationBarController.setBarShowingLw(true)) {
5346 changes |= FINISH_LAYOUT_REDO_LAYOUT;
5347 }
5348 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005349 } else if (mTopFullscreenOpaqueWindowState != null) {
John Spurlockc6d1c602014-01-17 15:22:06 -05005350 final int fl = PolicyControl.getWindowFlags(null, lp);
Joe Onorato93056472010-09-10 10:30:46 -04005351 if (localLOGV) {
Craig Mautnereda67292013-04-28 13:50:14 -07005352 Slog.d(TAG, "frame: " + mTopFullscreenOpaqueWindowState.getFrameLw()
Filip Gruszczynski2a6a2c22015-10-14 12:00:53 -07005353 + " shown position: "
5354 + mTopFullscreenOpaqueWindowState.getShownPositionLw());
Craig Mautnereda67292013-04-28 13:50:14 -07005355 Slog.d(TAG, "attr: " + mTopFullscreenOpaqueWindowState.getAttrs()
John Spurlockc6d1c602014-01-17 15:22:06 -05005356 + " lp.flags=0x" + Integer.toHexString(fl));
Joe Onorato93056472010-09-10 10:30:46 -04005357 }
John Spurlockc6d1c602014-01-17 15:22:06 -05005358 topIsFullscreen = (fl & WindowManager.LayoutParams.FLAG_FULLSCREEN) != 0
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07005359 || (mLastSystemUiFlags & View.SYSTEM_UI_FLAG_FULLSCREEN) != 0;
Joe Onorato93056472010-09-10 10:30:46 -04005360 // The subtle difference between the window for mTopFullscreenOpaqueWindowState
Mark Dolinerd0646dc2014-08-27 16:04:02 -07005361 // and mTopIsFullscreen is that mTopIsFullscreen is set only if the window
Joe Onorato93056472010-09-10 10:30:46 -04005362 // has the FLAG_FULLSCREEN set. Not sure if there is another way that to be the
5363 // case though.
John Spurlock27735a42013-08-14 17:57:38 -04005364 if (mStatusBarController.isTransientShowing()) {
5365 if (mStatusBarController.setBarShowingLw(true)) {
John Spurlock32beb2c2013-03-11 10:16:47 -04005366 changes |= FINISH_LAYOUT_REDO_LAYOUT;
5367 }
Wale Ogunwale6e94a9e2015-10-07 15:35:49 -07005368 } else if (topIsFullscreen
5369 && !mWindowManagerInternal.isStackVisible(FREEFORM_WORKSPACE_STACK_ID)
5370 && !mWindowManagerInternal.isStackVisible(DOCKED_STACK_ID)) {
Craig Mautnereda67292013-04-28 13:50:14 -07005371 if (DEBUG_LAYOUT) Slog.v(TAG, "** HIDING status bar");
John Spurlock27735a42013-08-14 17:57:38 -04005372 if (mStatusBarController.setBarShowingLw(false)) {
Dianne Hackbornf87d1962012-04-04 12:48:24 -07005373 changes |= FINISH_LAYOUT_REDO_LAYOUT;
Craig Mautnereda67292013-04-28 13:50:14 -07005374 } else {
Craig Mautnerc5a6e442013-06-05 17:22:35 -07005375 if (DEBUG_LAYOUT) Slog.v(TAG, "Status bar already hiding");
Daniel Sandler40427442010-07-16 11:44:52 -04005376 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005377 } else {
Craig Mautnereda67292013-04-28 13:50:14 -07005378 if (DEBUG_LAYOUT) Slog.v(TAG, "** SHOWING status bar: top is not fullscreen");
John Spurlock27735a42013-08-14 17:57:38 -04005379 if (mStatusBarController.setBarShowingLw(true)) {
5380 changes |= FINISH_LAYOUT_REDO_LAYOUT;
5381 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005382 }
5383 }
5384 }
Daniel Sandlere02d8082010-10-08 15:13:22 -04005385
Craig Mautner81defc72013-10-29 11:10:42 -07005386 if (mTopIsFullscreen != topIsFullscreen) {
5387 if (!topIsFullscreen) {
5388 // Force another layout when status bar becomes fully shown.
5389 changes |= FINISH_LAYOUT_REDO_LAYOUT;
5390 }
5391 mTopIsFullscreen = topIsFullscreen;
5392 }
Daniel Sandlere02d8082010-10-08 15:13:22 -04005393
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07005394 if ((updateSystemUiVisibilityLw()&SYSTEM_UI_CHANGING_LAYOUT) != 0) {
Dianne Hackborndf89e652011-10-06 22:35:11 -07005395 // If the navigation bar has been hidden or shown, we need to do another
5396 // layout pass to update that window.
5397 changes |= FINISH_LAYOUT_REDO_LAYOUT;
5398 }
Joe Onorato664644d2011-01-23 17:53:23 -08005399
Jorim Jaggi77e10432016-10-26 17:43:56 -07005400 if (mShowingDream != mLastShowingDream) {
5401 mLastShowingDream = mShowingDream;
5402 mWindowManagerFuncs.notifyShowingDreamChanged();
5403 }
5404
Mike Lockwood28569302010-01-28 11:54:40 -05005405 // update since mAllowLockscreenWhenOn might have changed
5406 updateLockScreenTimeout();
Dianne Hackborn39c2d712009-09-22 11:41:31 -07005407 return changes;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005408 }
5409
Jorim Jaggi380ecb82014-03-14 17:25:20 +01005410 /**
Jim Millerab954542014-10-10 18:21:49 -07005411 * Updates the occluded state of the Keyguard.
Jorim Jaggi380ecb82014-03-14 17:25:20 +01005412 *
Jorim Jaggi380ecb82014-03-14 17:25:20 +01005413 * @return Whether the flags have changed and we have to redo the layout.
5414 */
Jim Millerab954542014-10-10 18:21:49 -07005415 private boolean setKeyguardOccludedLw(boolean isOccluded) {
Jorim Jaggife762342016-10-13 14:33:27 +02005416 if (DEBUG_KEYGUARD) Slog.d(TAG, "setKeyguardOccluded occluded=" + isOccluded);
Jim Millerab954542014-10-10 18:21:49 -07005417 boolean wasOccluded = mKeyguardOccluded;
5418 boolean showing = mKeyguardDelegate.isShowing();
5419 if (wasOccluded && !isOccluded && showing) {
5420 mKeyguardOccluded = false;
Jorim Jaggi6626f542016-08-22 13:08:44 -07005421 mKeyguardDelegate.setOccluded(false, true /* animate */);
Jorim Jaggi380ecb82014-03-14 17:25:20 +01005422 mStatusBar.getAttrs().privateFlags |= PRIVATE_FLAG_KEYGUARD;
Jorim Jaggid11d1a92016-08-16 16:02:32 -07005423 if (!mKeyguardDelegate.hasLockscreenWallpaper()) {
5424 mStatusBar.getAttrs().flags |= FLAG_SHOW_WALLPAPER;
5425 }
Jorim Jaggi380ecb82014-03-14 17:25:20 +01005426 return true;
Jim Millerab954542014-10-10 18:21:49 -07005427 } else if (!wasOccluded && isOccluded && showing) {
5428 mKeyguardOccluded = true;
Jorim Jaggi6626f542016-08-22 13:08:44 -07005429 mKeyguardDelegate.setOccluded(true, false /* animate */);
Jorim Jaggi380ecb82014-03-14 17:25:20 +01005430 mStatusBar.getAttrs().privateFlags &= ~PRIVATE_FLAG_KEYGUARD;
5431 mStatusBar.getAttrs().flags &= ~FLAG_SHOW_WALLPAPER;
5432 return true;
Adrian Roos909fe2d2016-10-12 12:03:24 -07005433 } else if (wasOccluded != isOccluded) {
5434 mKeyguardOccluded = isOccluded;
5435 mKeyguardDelegate.setOccluded(isOccluded, false /* animate */);
5436 return false;
Jorim Jaggi380ecb82014-03-14 17:25:20 +01005437 } else {
5438 return false;
5439 }
5440 }
5441
5442 private boolean isStatusBarKeyguard() {
5443 return mStatusBar != null
5444 && (mStatusBar.getAttrs().privateFlags & PRIVATE_FLAG_KEYGUARD) != 0;
5445 }
5446
Jose Lima9546b202014-07-02 17:21:51 -07005447 @Override
Dianne Hackborn08743722009-12-21 12:16:51 -08005448 public boolean allowAppAnimationsLw() {
Jorim Jaggife762342016-10-13 14:33:27 +02005449 if (mShowingDream) {
Craig Mautner28816302013-10-10 20:31:00 -07005450 // If keyguard or dreams is currently visible, no reason to animate behind it.
Dianne Hackborn08743722009-12-21 12:16:51 -08005451 return false;
5452 }
Dianne Hackborn08743722009-12-21 12:16:51 -08005453 return true;
5454 }
5455
Jose Lima9546b202014-07-02 17:21:51 -07005456 @Override
Dianne Hackborndf89e652011-10-06 22:35:11 -07005457 public int focusChangedLw(WindowState lastFocus, WindowState newFocus) {
Joe Onorato664644d2011-01-23 17:53:23 -08005458 mFocusedWindow = newFocus;
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07005459 if ((updateSystemUiVisibilityLw()&SYSTEM_UI_CHANGING_LAYOUT) != 0) {
Dianne Hackborndf89e652011-10-06 22:35:11 -07005460 // If the navigation bar has been hidden or shown, we need to do another
5461 // layout pass to update that window.
5462 return FINISH_LAYOUT_REDO_LAYOUT;
5463 }
5464 return 0;
Joe Onorato664644d2011-01-23 17:53:23 -08005465 }
5466
Dianne Hackborn0ecadf72009-03-31 18:00:37 -07005467 /** {@inheritDoc} */
Jose Lima9546b202014-07-02 17:21:51 -07005468 @Override
Jeff Brown46b9ac02010-04-22 18:58:52 -07005469 public void notifyLidSwitchChanged(long whenNanos, boolean lidOpen) {
5470 // lid changed state
Jeff Brownc458ce92012-04-30 14:58:40 -07005471 final int newLidState = lidOpen ? LID_OPEN : LID_CLOSED;
5472 if (newLidState == mLidState) {
5473 return;
5474 }
Jeff Brown01a98dd2011-09-20 15:08:29 -07005475
Jeff Brownc458ce92012-04-30 14:58:40 -07005476 mLidState = newLidState;
5477 applyLidSwitchState();
Jeff Brown01a98dd2011-09-20 15:08:29 -07005478 updateRotation(true);
Jeff Brownc458ce92012-04-30 14:58:40 -07005479
5480 if (lidOpen) {
Dianne Hackborn280a64e2015-07-13 14:48:08 -07005481 wakeUp(SystemClock.uptimeMillis(), mAllowTheaterModeWakeFromLidSwitch,
5482 "android.policy:LID");
Jeff Brownc458ce92012-04-30 14:58:40 -07005483 } else if (!mLidControlsSleep) {
Jeff Brown96307042012-07-27 15:51:34 -07005484 mPowerManager.userActivity(SystemClock.uptimeMillis(), false);
Jeff Brown46b9ac02010-04-22 18:58:52 -07005485 }
5486 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005487
Michael Wright3818c922014-09-02 13:59:07 -07005488 @Override
5489 public void notifyCameraLensCoverSwitchChanged(long whenNanos, boolean lensCovered) {
5490 int lensCoverState = lensCovered ? CAMERA_LENS_COVERED : CAMERA_LENS_UNCOVERED;
5491 if (mCameraLensCoverState == lensCoverState) {
5492 return;
5493 }
5494 if (mCameraLensCoverState == CAMERA_LENS_COVERED &&
5495 lensCoverState == CAMERA_LENS_UNCOVERED) {
5496 Intent intent;
5497 final boolean keyguardActive = mKeyguardDelegate == null ? false :
5498 mKeyguardDelegate.isShowing();
5499 if (keyguardActive) {
5500 intent = new Intent(MediaStore.INTENT_ACTION_STILL_IMAGE_CAMERA_SECURE);
5501 } else {
5502 intent = new Intent(MediaStore.INTENT_ACTION_STILL_IMAGE_CAMERA);
5503 }
Dianne Hackborn280a64e2015-07-13 14:48:08 -07005504 wakeUp(whenNanos / 1000000, mAllowTheaterModeWakeFromCameraLens,
5505 "android.policy:CAMERA_COVER");
Bart Sears8b1c27c2015-03-18 23:51:02 +00005506 startActivityAsUser(intent, UserHandle.CURRENT_OR_SELF);
Michael Wright3818c922014-09-02 13:59:07 -07005507 }
5508 mCameraLensCoverState = lensCoverState;
5509 }
5510
Dianne Hackbornad7fa7f2011-01-07 14:06:50 -08005511 void setHdmiPlugged(boolean plugged) {
5512 if (mHdmiPlugged != plugged) {
5513 mHdmiPlugged = plugged;
Dianne Hackbornf87d1962012-04-04 12:48:24 -07005514 updateRotation(true, true);
Dianne Hackbornad7fa7f2011-01-07 14:06:50 -08005515 Intent intent = new Intent(ACTION_HDMI_PLUGGED);
Joe Onoratodc100302011-01-11 17:07:41 -08005516 intent.addFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY_BEFORE_BOOT);
Dianne Hackbornad7fa7f2011-01-07 14:06:50 -08005517 intent.putExtra(EXTRA_HDMI_PLUGGED_STATE, plugged);
Dianne Hackborn5ac72a22012-08-29 18:32:08 -07005518 mContext.sendStickyBroadcastAsUser(intent, UserHandle.ALL);
Dianne Hackbornad7fa7f2011-01-07 14:06:50 -08005519 }
5520 }
5521
Joe Onoratoea495d42011-04-06 11:41:11 -07005522 void initializeHdmiState() {
Joe Onorato7ba631f2011-05-04 15:28:00 -07005523 boolean plugged = false;
Joe Onoratoea495d42011-04-06 11:41:11 -07005524 // watch for HDMI plug messages if the hdmi switch exists
5525 if (new File("/sys/devices/virtual/switch/hdmi/state").exists()) {
5526 mHDMIObserver.startObserving("DEVPATH=/devices/virtual/switch/hdmi");
5527
Joe Onoratoea495d42011-04-06 11:41:11 -07005528 final String filename = "/sys/class/switch/hdmi/state";
5529 FileReader reader = null;
5530 try {
5531 reader = new FileReader(filename);
5532 char[] buf = new char[15];
5533 int n = reader.read(buf);
5534 if (n > 1) {
5535 plugged = 0 != Integer.parseInt(new String(buf, 0, n-1));
5536 }
5537 } catch (IOException ex) {
5538 Slog.w(TAG, "Couldn't read hdmi state from " + filename + ": " + ex);
5539 } catch (NumberFormatException ex) {
5540 Slog.w(TAG, "Couldn't read hdmi state from " + filename + ": " + ex);
5541 } finally {
5542 if (reader != null) {
5543 try {
5544 reader.close();
5545 } catch (IOException ex) {
5546 }
Joe Onoratodc100302011-01-11 17:07:41 -08005547 }
5548 }
5549 }
Joe Onorato7ba631f2011-05-04 15:28:00 -07005550 // This dance forces the code in setHdmiPlugged to run.
5551 // Always do this so the sticky intent is stuck (to false) if there is no hdmi.
5552 mHdmiPlugged = !plugged;
5553 setHdmiPlugged(!mHdmiPlugged);
Joe Onoratodc100302011-01-11 17:07:41 -08005554 }
5555
Dianne Hackbornc0e3f242011-08-19 14:19:10 -07005556 final Object mScreenshotLock = new Object();
Dianne Hackbornfc8fa632011-08-17 16:20:47 -07005557 ServiceConnection mScreenshotConnection = null;
Dianne Hackbornfc8fa632011-08-17 16:20:47 -07005558
Jeff Brownd5bb82d2011-10-12 13:57:59 -07005559 final Runnable mScreenshotTimeout = new Runnable() {
5560 @Override public void run() {
5561 synchronized (mScreenshotLock) {
5562 if (mScreenshotConnection != null) {
5563 mContext.unbindService(mScreenshotConnection);
5564 mScreenshotConnection = null;
Winson44dbe292016-03-10 14:00:14 -08005565 notifyScreenshotError();
Dianne Hackbornfc8fa632011-08-17 16:20:47 -07005566 }
Winson Chung9112ec32011-06-27 13:15:32 -07005567 }
Jeff Brownd5bb82d2011-10-12 13:57:59 -07005568 }
5569 };
5570
5571 // Assume this is called from the Handler thread.
Muyuan Li6ca619f2016-03-08 13:30:42 -08005572 private void takeScreenshot(final int screenshotType) {
Jeff Brownd5bb82d2011-10-12 13:57:59 -07005573 synchronized (mScreenshotLock) {
5574 if (mScreenshotConnection != null) {
5575 return;
5576 }
Winson44dbe292016-03-10 14:00:14 -08005577 final ComponentName serviceComponent = new ComponentName(SYSUI_PACKAGE,
5578 SYSUI_SCREENSHOT_SERVICE);
5579 final Intent serviceIntent = new Intent();
5580 serviceIntent.setComponent(serviceComponent);
Jeff Brownd5bb82d2011-10-12 13:57:59 -07005581 ServiceConnection conn = new ServiceConnection() {
5582 @Override
5583 public void onServiceConnected(ComponentName name, IBinder service) {
5584 synchronized (mScreenshotLock) {
5585 if (mScreenshotConnection != this) {
5586 return;
5587 }
5588 Messenger messenger = new Messenger(service);
Muyuan Li6ca619f2016-03-08 13:30:42 -08005589 Message msg = Message.obtain(null, screenshotType);
Jeff Brownd5bb82d2011-10-12 13:57:59 -07005590 final ServiceConnection myConn = this;
5591 Handler h = new Handler(mHandler.getLooper()) {
5592 @Override
5593 public void handleMessage(Message msg) {
5594 synchronized (mScreenshotLock) {
5595 if (mScreenshotConnection == myConn) {
5596 mContext.unbindService(mScreenshotConnection);
5597 mScreenshotConnection = null;
5598 mHandler.removeCallbacks(mScreenshotTimeout);
5599 }
5600 }
5601 }
5602 };
5603 msg.replyTo = new Messenger(h);
Winson Chunga63bb842011-10-17 10:26:28 -07005604 msg.arg1 = msg.arg2 = 0;
5605 if (mStatusBar != null && mStatusBar.isVisibleLw())
5606 msg.arg1 = 1;
5607 if (mNavigationBar != null && mNavigationBar.isVisibleLw())
5608 msg.arg2 = 1;
Jeff Brownd5bb82d2011-10-12 13:57:59 -07005609 try {
5610 messenger.send(msg);
5611 } catch (RemoteException e) {
5612 }
5613 }
5614 }
Winson44dbe292016-03-10 14:00:14 -08005615
Jeff Brownd5bb82d2011-10-12 13:57:59 -07005616 @Override
Winson44dbe292016-03-10 14:00:14 -08005617 public void onServiceDisconnected(ComponentName name) {
Geoffrey Pitschb2d6ed32016-08-24 10:37:19 -04005618 synchronized (mScreenshotLock) {
5619 if (mScreenshotConnection != null) {
5620 mContext.unbindService(mScreenshotConnection);
5621 mScreenshotConnection = null;
5622 mHandler.removeCallbacks(mScreenshotTimeout);
5623 notifyScreenshotError();
5624 }
5625 }
Winson44dbe292016-03-10 14:00:14 -08005626 }
Jeff Brownd5bb82d2011-10-12 13:57:59 -07005627 };
Winson44dbe292016-03-10 14:00:14 -08005628 if (mContext.bindServiceAsUser(serviceIntent, conn,
5629 Context.BIND_AUTO_CREATE | Context.BIND_FOREGROUND_SERVICE_WHILE_AWAKE,
5630 UserHandle.CURRENT)) {
Jeff Brownd5bb82d2011-10-12 13:57:59 -07005631 mScreenshotConnection = conn;
5632 mHandler.postDelayed(mScreenshotTimeout, 10000);
5633 }
5634 }
Winson Chung9112ec32011-06-27 13:15:32 -07005635 }
5636
Winson44dbe292016-03-10 14:00:14 -08005637 /**
5638 * Notifies the screenshot service to show an error.
5639 */
5640 private void notifyScreenshotError() {
5641 // If the service process is killed, then ask it to clean up after itself
5642 final ComponentName errorComponent = new ComponentName(SYSUI_PACKAGE,
5643 SYSUI_SCREENSHOT_ERROR_RECEIVER);
Dianne Hackborna8c16932016-05-24 12:58:21 -07005644 Intent errorIntent = new Intent(Intent.ACTION_USER_PRESENT);
Winson44dbe292016-03-10 14:00:14 -08005645 errorIntent.setComponent(errorComponent);
5646 errorIntent.addFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY_BEFORE_BOOT |
5647 Intent.FLAG_RECEIVER_FOREGROUND);
Winson538c2262016-05-19 10:06:18 -07005648 mContext.sendBroadcastAsUser(errorIntent, UserHandle.CURRENT);
Winson44dbe292016-03-10 14:00:14 -08005649 }
5650
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005651 /** {@inheritDoc} */
Jeff Brown00fa7bd2010-07-02 15:37:36 -07005652 @Override
Jeff Brown037c33e2014-04-09 00:31:55 -07005653 public int interceptKeyBeforeQueueing(KeyEvent event, int policyFlags) {
Jeff Brown96307042012-07-27 15:51:34 -07005654 if (!mSystemBooted) {
5655 // If we have not yet booted, don't let key events do anything.
5656 return 0;
5657 }
5658
Jeff Brown037c33e2014-04-09 00:31:55 -07005659 final boolean interactive = (policyFlags & FLAG_INTERACTIVE) != 0;
Jeff Brown1f245102010-11-18 20:53:46 -08005660 final boolean down = event.getAction() == KeyEvent.ACTION_DOWN;
5661 final boolean canceled = event.isCanceled();
5662 final int keyCode = event.getKeyCode();
Jeff Browne20c9e02010-10-11 14:20:19 -07005663
Jeff Brown3122e442010-10-11 23:32:49 -07005664 final boolean isInjected = (policyFlags & WindowManagerPolicy.FLAG_INJECTED) != 0;
Jeff Brown3122e442010-10-11 23:32:49 -07005665
Mike Lockwoodc72b15f2009-11-28 20:58:22 -05005666 // If screen is off then we treat the case where the keyguard is open but hidden
5667 // the same as if it were open and in front.
5668 // This will prevent any keys other than the power button from waking the screen
5669 // when the keyguard is hidden by another activity.
Jim Miller5ecd8112013-01-09 18:50:26 -08005670 final boolean keyguardActive = (mKeyguardDelegate == null ? false :
Jeff Brown037c33e2014-04-09 00:31:55 -07005671 (interactive ?
Jim Millerab954542014-10-10 18:21:49 -07005672 isKeyguardShowingAndNotOccluded() :
Jim Miller5ecd8112013-01-09 18:50:26 -08005673 mKeyguardDelegate.isShowing()));
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005674
Jeff Brown40013652012-05-16 21:22:36 -07005675 if (DEBUG_INPUT) {
Jeff Brown00fa7bd2010-07-02 15:37:36 -07005676 Log.d(TAG, "interceptKeyTq keycode=" + keyCode
Jeff Brown037c33e2014-04-09 00:31:55 -07005677 + " interactive=" + interactive + " keyguardActive=" + keyguardActive
Jeff Brown26875502014-01-30 21:47:47 -08005678 + " policyFlags=" + Integer.toHexString(policyFlags));
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005679 }
5680
Jeff Brown037c33e2014-04-09 00:31:55 -07005681 // Basic policy based on interactive state.
Jeff Brown4d396052010-10-29 21:50:21 -07005682 int result;
Michael Wright337d9d22014-04-22 15:03:48 -07005683 boolean isWakeKey = (policyFlags & WindowManagerPolicy.FLAG_WAKE) != 0
5684 || event.isWakeKey();
Michael Wrightfc01f042014-09-08 14:12:24 -07005685 if (interactive || (isInjected && !isWakeKey)) {
RoboErikde9ba392014-09-26 12:51:01 -07005686 // When the device is interactive or the key is injected pass the
5687 // key to the application.
Jeff Brown4d396052010-10-29 21:50:21 -07005688 result = ACTION_PASS_TO_USER;
Jose Lima9546b202014-07-02 17:21:51 -07005689 isWakeKey = false;
Anthony Hugh4b13ab82016-05-17 13:03:00 -07005690
5691 if (interactive) {
5692 // If the screen is awake, but the button pressed was the one that woke the device
5693 // then don't pass it to the application
5694 if (keyCode == mPendingWakeKey && !down) {
5695 result = 0;
5696 }
5697 // Reset the pending key
5698 mPendingWakeKey = PENDING_KEY_NULL;
5699 }
5700 } else if (!interactive && shouldDispatchInputWhenNonInteractive(event)) {
Michael Wrightfc01f042014-09-08 14:12:24 -07005701 // If we're currently dozing with the screen on and the keyguard showing, pass the key
5702 // to the application but preserve its wake key status to make sure we still move
5703 // from dozing to fully interactive if we would normally go from off to fully
5704 // interactive.
5705 result = ACTION_PASS_TO_USER;
Anthony Hugh4b13ab82016-05-17 13:03:00 -07005706 // Since we're dispatching the input, reset the pending key
5707 mPendingWakeKey = PENDING_KEY_NULL;
Jeff Brown4d396052010-10-29 21:50:21 -07005708 } else {
5709 // When the screen is off and the key is not injected, determine whether
5710 // to wake the device but don't pass the key to the application.
5711 result = 0;
Jeff Brown26875502014-01-30 21:47:47 -08005712 if (isWakeKey && (!down || !isWakeKeyWhenScreenOff(keyCode))) {
5713 isWakeKey = false;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005714 }
Anthony Hugh4b13ab82016-05-17 13:03:00 -07005715 // Cache the wake key on down event so we can also avoid sending the up event to the app
5716 if (isWakeKey && down) {
5717 mPendingWakeKey = keyCode;
5718 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005719 }
5720
Justin Kohd378ad72013-04-01 12:18:26 -07005721 // If the key would be handled globally, just return the result, don't worry about special
5722 // key processing.
Jeff Brown13f00f02014-10-31 14:45:50 -07005723 if (isValidGlobalKey(keyCode)
5724 && mGlobalKeyManager.shouldHandleGlobalKey(keyCode, event)) {
Michael Wright85b1af62014-06-04 14:51:58 -07005725 if (isWakeKey) {
Dianne Hackborn280a64e2015-07-13 14:48:08 -07005726 wakeUp(event.getEventTime(), mAllowTheaterModeWakeFromKey, "android.policy:KEY");
Michael Wright85b1af62014-06-04 14:51:58 -07005727 }
Justin Kohd378ad72013-04-01 12:18:26 -07005728 return result;
5729 }
5730
Jeff Brownbae8e772014-06-12 19:59:45 -07005731 boolean useHapticFeedback = down
5732 && (policyFlags & WindowManagerPolicy.FLAG_VIRTUAL) != 0
5733 && event.getRepeatCount() == 0;
5734
Jeff Brown4d396052010-10-29 21:50:21 -07005735 // Handle special keys.
5736 switch (keyCode) {
Anthony Hugh34f09ca2016-03-04 12:03:37 -08005737 case KeyEvent.KEYCODE_BACK: {
5738 if (down) {
Anthony Hugh96e9cc52016-07-12 15:17:24 -07005739 interceptBackKeyDown();
Anthony Hugh34f09ca2016-03-04 12:03:37 -08005740 } else {
Anthony Hugh96e9cc52016-07-12 15:17:24 -07005741 boolean handled = interceptBackKeyUp(event);
Anthony Hugh34f09ca2016-03-04 12:03:37 -08005742
Anthony Hugh96e9cc52016-07-12 15:17:24 -07005743 // Don't pass back press to app if we've already handled it via long press
Anthony Hugh34f09ca2016-03-04 12:03:37 -08005744 if (handled) {
5745 result &= ~ACTION_PASS_TO_USER;
5746 }
5747 }
5748 break;
5749 }
5750
Jeff Brown4d396052010-10-29 21:50:21 -07005751 case KeyEvent.KEYCODE_VOLUME_DOWN:
Jeff Brownb0418da2010-11-01 15:24:01 -07005752 case KeyEvent.KEYCODE_VOLUME_UP:
5753 case KeyEvent.KEYCODE_VOLUME_MUTE: {
Jeff Brownd5bb82d2011-10-12 13:57:59 -07005754 if (keyCode == KeyEvent.KEYCODE_VOLUME_DOWN) {
5755 if (down) {
Jeff Brown13f00f02014-10-31 14:45:50 -07005756 if (interactive && !mScreenshotChordVolumeDownKeyTriggered
Jeff Brownd5bb82d2011-10-12 13:57:59 -07005757 && (event.getFlags() & KeyEvent.FLAG_FALLBACK) == 0) {
Jeff Brown13f00f02014-10-31 14:45:50 -07005758 mScreenshotChordVolumeDownKeyTriggered = true;
5759 mScreenshotChordVolumeDownKeyTime = event.getDownTime();
5760 mScreenshotChordVolumeDownKeyConsumed = false;
Jeff Brownd5bb82d2011-10-12 13:57:59 -07005761 cancelPendingPowerKeyAction();
5762 interceptScreenshotChord();
5763 }
5764 } else {
Jeff Brown13f00f02014-10-31 14:45:50 -07005765 mScreenshotChordVolumeDownKeyTriggered = false;
Jeff Brownd5bb82d2011-10-12 13:57:59 -07005766 cancelPendingScreenshotChordAction();
5767 }
5768 } else if (keyCode == KeyEvent.KEYCODE_VOLUME_UP) {
5769 if (down) {
Jeff Brown13f00f02014-10-31 14:45:50 -07005770 if (interactive && !mScreenshotChordVolumeUpKeyTriggered
Jeff Brownd5bb82d2011-10-12 13:57:59 -07005771 && (event.getFlags() & KeyEvent.FLAG_FALLBACK) == 0) {
Jeff Brown13f00f02014-10-31 14:45:50 -07005772 mScreenshotChordVolumeUpKeyTriggered = true;
Jeff Brownd5bb82d2011-10-12 13:57:59 -07005773 cancelPendingPowerKeyAction();
5774 cancelPendingScreenshotChordAction();
5775 }
5776 } else {
Jeff Brown13f00f02014-10-31 14:45:50 -07005777 mScreenshotChordVolumeUpKeyTriggered = false;
Jeff Brownd5bb82d2011-10-12 13:57:59 -07005778 cancelPendingScreenshotChordAction();
5779 }
5780 }
Jeff Brown4d396052010-10-29 21:50:21 -07005781 if (down) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -07005782 TelecomManager telecomManager = getTelecommService();
5783 if (telecomManager != null) {
5784 if (telecomManager.isRinging()) {
Santos Cordon6848f722014-05-21 15:22:12 -07005785 // If an incoming call is ringing, either VOLUME key means
5786 // "silence ringer". We handle these keys here, rather than
5787 // in the InCallScreen, to make sure we'll respond to them
5788 // even if the InCallScreen hasn't come to the foreground yet.
5789 // Look for the DOWN event here, to agree with the "fallback"
5790 // behavior in the InCallScreen.
5791 Log.i(TAG, "interceptKeyBeforeQueueing:"
5792 + " VOLUME key-down while ringing: Silence ringer!");
Jeff Brown4d396052010-10-29 21:50:21 -07005793
Santos Cordon6848f722014-05-21 15:22:12 -07005794 // Silence the ringer. (It's safe to call this
5795 // even if the ringer has already been silenced.)
Tyler Gunnef9f6f92014-09-12 22:16:17 -07005796 telecomManager.silenceRinger();
Jeff Brown4d396052010-10-29 21:50:21 -07005797
Santos Cordon6848f722014-05-21 15:22:12 -07005798 // And *don't* pass this key thru to the current activity
5799 // (which is probably the InCallScreen.)
5800 result &= ~ACTION_PASS_TO_USER;
5801 break;
5802 }
Tyler Gunnef9f6f92014-09-12 22:16:17 -07005803 if (telecomManager.isInCall()
Santos Cordon6848f722014-05-21 15:22:12 -07005804 && (result & ACTION_PASS_TO_USER) == 0) {
5805 // If we are in call but we decided not to pass the key to
RoboErik430fc482014-06-12 15:49:20 -07005806 // the application, just pass it to the session service.
5807
5808 MediaSessionLegacyHelper.getHelper(mContext)
RoboErik3c45c292014-07-08 16:47:31 -07005809 .sendVolumeKeyEvent(event, false);
Santos Cordon6848f722014-05-21 15:22:12 -07005810 break;
Jeff Brown4d396052010-10-29 21:50:21 -07005811 }
5812 }
Jaewan Kim765487f2016-01-12 14:45:42 +09005813 }
5814 if (mUseTvRouting) {
5815 // On TVs, defer special key handlings to
5816 // {@link interceptKeyBeforeDispatching()}.
5817 result |= ACTION_PASS_TO_USER;
5818 } else if ((result & ACTION_PASS_TO_USER) == 0) {
5819 // If we aren't passing to the user and no one else
5820 // handled it send it to the session manager to
5821 // figure out.
5822 MediaSessionLegacyHelper.getHelper(mContext)
5823 .sendVolumeKeyEvent(event, true);
Jeff Brown4d396052010-10-29 21:50:21 -07005824 }
5825 break;
5826 }
5827
5828 case KeyEvent.KEYCODE_ENDCALL: {
5829 result &= ~ACTION_PASS_TO_USER;
5830 if (down) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -07005831 TelecomManager telecomManager = getTelecommService();
Jeff Brown4d396052010-10-29 21:50:21 -07005832 boolean hungUp = false;
Tyler Gunnef9f6f92014-09-12 22:16:17 -07005833 if (telecomManager != null) {
5834 hungUp = telecomManager.endCall();
Jeff Brown4d396052010-10-29 21:50:21 -07005835 }
Jeff Brown13f00f02014-10-31 14:45:50 -07005836 if (interactive && !hungUp) {
5837 mEndCallKeyHandled = false;
5838 mHandler.postDelayed(mEndCallLongPress,
5839 ViewConfiguration.get(mContext).getDeviceGlobalActionKeyTimeout());
5840 } else {
5841 mEndCallKeyHandled = true;
5842 }
Jeff Brown4d396052010-10-29 21:50:21 -07005843 } else {
Jeff Brown13f00f02014-10-31 14:45:50 -07005844 if (!mEndCallKeyHandled) {
5845 mHandler.removeCallbacks(mEndCallLongPress);
5846 if (!canceled) {
5847 if ((mEndcallBehavior
5848 & Settings.System.END_BUTTON_BEHAVIOR_HOME) != 0) {
5849 if (goHome()) {
5850 break;
5851 }
Dianne Hackborn0041e972009-07-24 17:14:43 -07005852 }
Jeff Brown13f00f02014-10-31 14:45:50 -07005853 if ((mEndcallBehavior
5854 & Settings.System.END_BUTTON_BEHAVIOR_SLEEP) != 0) {
5855 mPowerManager.goToSleep(event.getEventTime(),
5856 PowerManager.GO_TO_SLEEP_REASON_POWER_BUTTON, 0);
5857 isWakeKey = false;
5858 }
Jeff Brown4d396052010-10-29 21:50:21 -07005859 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005860 }
Jeff Brown4d396052010-10-29 21:50:21 -07005861 }
5862 break;
5863 }
5864
5865 case KeyEvent.KEYCODE_POWER: {
5866 result &= ~ACTION_PASS_TO_USER;
Jeff Brown13f00f02014-10-31 14:45:50 -07005867 isWakeKey = false; // wake-up will be handled separately
Jeff Brown4d396052010-10-29 21:50:21 -07005868 if (down) {
Jeff Brown13f00f02014-10-31 14:45:50 -07005869 interceptPowerKeyDown(event, interactive);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005870 } else {
Jeff Brown13f00f02014-10-31 14:45:50 -07005871 interceptPowerKeyUp(event, interactive, canceled);
Jeff Brown4d396052010-10-29 21:50:21 -07005872 }
5873 break;
5874 }
5875
Jim Miller07e03842016-06-22 15:18:13 -07005876 case KeyEvent.KEYCODE_SYSTEM_NAVIGATION_DOWN:
Jim Millerf4c0a132016-05-17 18:11:52 -07005877 // fall through
Jim Miller07e03842016-06-22 15:18:13 -07005878 case KeyEvent.KEYCODE_SYSTEM_NAVIGATION_UP:
Jim Millerf4c0a132016-05-17 18:11:52 -07005879 // fall through
Jim Miller07e03842016-06-22 15:18:13 -07005880 case KeyEvent.KEYCODE_SYSTEM_NAVIGATION_LEFT:
Jim Millerf4c0a132016-05-17 18:11:52 -07005881 // fall through
Jim Miller07e03842016-06-22 15:18:13 -07005882 case KeyEvent.KEYCODE_SYSTEM_NAVIGATION_RIGHT: {
5883 result &= ~ACTION_PASS_TO_USER;
5884 interceptSystemNavigationKey(event);
Jim Millerf4c0a132016-05-17 18:11:52 -07005885 break;
5886 }
5887
Jeff Brown6212a492014-03-07 13:58:47 -08005888 case KeyEvent.KEYCODE_SLEEP: {
5889 result &= ~ACTION_PASS_TO_USER;
Filip Gruszczynskia483a1d2015-03-17 19:06:58 +00005890 isWakeKey = false;
Jeff Brownbae8e772014-06-12 19:59:45 -07005891 if (!mPowerManager.isInteractive()) {
5892 useHapticFeedback = false; // suppress feedback if already non-interactive
5893 }
Nick Vaccarob593a812015-05-15 11:23:05 -07005894 if (down) {
5895 sleepPress(event.getEventTime());
5896 } else {
5897 sleepRelease(event.getEventTime());
5898 }
Jeff Brown6212a492014-03-07 13:58:47 -08005899 break;
5900 }
5901
Nick Armstrong-Crews56ecfcc2015-09-07 21:46:50 -07005902 case KeyEvent.KEYCODE_SOFT_SLEEP: {
5903 result &= ~ACTION_PASS_TO_USER;
5904 isWakeKey = false;
5905 if (!down) {
5906 mPowerManagerInternal.setUserInactiveOverrideFromWindowManager();
5907 }
5908 break;
5909 }
5910
Jeff Brown6212a492014-03-07 13:58:47 -08005911 case KeyEvent.KEYCODE_WAKEUP: {
5912 result &= ~ACTION_PASS_TO_USER;
Jose Lima9546b202014-07-02 17:21:51 -07005913 isWakeKey = true;
Jeff Brown6212a492014-03-07 13:58:47 -08005914 break;
5915 }
5916
Jeff Brown4d396052010-10-29 21:50:21 -07005917 case KeyEvent.KEYCODE_MEDIA_PLAY:
5918 case KeyEvent.KEYCODE_MEDIA_PAUSE:
5919 case KeyEvent.KEYCODE_MEDIA_PLAY_PAUSE:
Jeff Brown4d396052010-10-29 21:50:21 -07005920 case KeyEvent.KEYCODE_HEADSETHOOK:
5921 case KeyEvent.KEYCODE_MUTE:
5922 case KeyEvent.KEYCODE_MEDIA_STOP:
5923 case KeyEvent.KEYCODE_MEDIA_NEXT:
5924 case KeyEvent.KEYCODE_MEDIA_PREVIOUS:
5925 case KeyEvent.KEYCODE_MEDIA_REWIND:
5926 case KeyEvent.KEYCODE_MEDIA_RECORD:
Jaekyun Seokbfdad8e2013-07-08 13:53:21 +09005927 case KeyEvent.KEYCODE_MEDIA_FAST_FORWARD:
5928 case KeyEvent.KEYCODE_MEDIA_AUDIO_TRACK: {
RoboErikde9ba392014-09-26 12:51:01 -07005929 if (MediaSessionLegacyHelper.getHelper(mContext).isGlobalPriorityActive()) {
5930 // If the global session is active pass all media keys to it
5931 // instead of the active window.
5932 result &= ~ACTION_PASS_TO_USER;
5933 }
Jeff Brown4d396052010-10-29 21:50:21 -07005934 if ((result & ACTION_PASS_TO_USER) == 0) {
5935 // Only do this if we would otherwise not pass it to the user. In that
5936 // case, the PhoneWindow class will do the same thing, except it will
5937 // only do it if the showing app doesn't process the key on its own.
Jeff Brown40013652012-05-16 21:22:36 -07005938 // Note that we need to make a copy of the key event here because the
5939 // original key event will be recycled when we return.
Jeff Brown4d396052010-10-29 21:50:21 -07005940 mBroadcastWakeLock.acquire();
Jeff Brown40013652012-05-16 21:22:36 -07005941 Message msg = mHandler.obtainMessage(MSG_DISPATCH_MEDIA_KEY_WITH_WAKE_LOCK,
5942 new KeyEvent(event));
5943 msg.setAsynchronous(true);
5944 msg.sendToTarget();
Jeff Brown4d396052010-10-29 21:50:21 -07005945 }
5946 break;
Jeff Brown00fa7bd2010-07-02 15:37:36 -07005947 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005948
Jeff Brown4d396052010-10-29 21:50:21 -07005949 case KeyEvent.KEYCODE_CALL: {
5950 if (down) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -07005951 TelecomManager telecomManager = getTelecommService();
5952 if (telecomManager != null) {
5953 if (telecomManager.isRinging()) {
Santos Cordon6848f722014-05-21 15:22:12 -07005954 Log.i(TAG, "interceptKeyBeforeQueueing:"
5955 + " CALL key-down while ringing: Answer the call!");
Tyler Gunnef9f6f92014-09-12 22:16:17 -07005956 telecomManager.acceptRingingCall();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005957
Santos Cordon6848f722014-05-21 15:22:12 -07005958 // And *don't* pass this key thru to the current activity
5959 // (which is presumably the InCallScreen.)
5960 result &= ~ACTION_PASS_TO_USER;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005961 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005962 }
Jeff Brown00fa7bd2010-07-02 15:37:36 -07005963 }
Jeff Brown4d396052010-10-29 21:50:21 -07005964 break;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005965 }
Michael Wright869a67c2014-08-26 19:33:06 -07005966 case KeyEvent.KEYCODE_VOICE_ASSIST: {
5967 // Only do this if we would otherwise not pass it to the user. In that case,
5968 // interceptKeyBeforeDispatching would apply a similar but different policy in
5969 // order to invoke voice assist actions. Note that we need to make a copy of the
5970 // key event here because the original key event will be recycled when we return.
5971 if ((result & ACTION_PASS_TO_USER) == 0 && !down) {
5972 mBroadcastWakeLock.acquire();
5973 Message msg = mHandler.obtainMessage(MSG_LAUNCH_VOICE_ASSIST_WITH_WAKE_LOCK,
5974 keyguardActive ? 1 : 0, 0);
5975 msg.setAsynchronous(true);
5976 msg.sendToTarget();
5977 }
Jaewan Kim49117872016-01-19 17:24:08 +09005978 break;
5979 }
5980 case KeyEvent.KEYCODE_WINDOW: {
5981 if (mShortPressWindowBehavior == SHORT_PRESS_WINDOW_PICTURE_IN_PICTURE) {
Jaewan Kimf0fd2182016-04-20 21:17:58 +09005982 if (mTvPictureInPictureVisible) {
5983 // Consumes the key only if picture-in-picture is visible
5984 // to show picture-in-picture control menu.
5985 // This gives a chance to the foreground activity
5986 // to customize PIP key behavior.
5987 if (!down) {
5988 showTvPictureInPictureMenu(event);
5989 }
5990 result &= ~ACTION_PASS_TO_USER;
Jaewan Kim49117872016-01-19 17:24:08 +09005991 }
Jaewan Kim49117872016-01-19 17:24:08 +09005992 }
5993 break;
Michael Wright869a67c2014-08-26 19:33:06 -07005994 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005995 }
Jeff Brown26875502014-01-30 21:47:47 -08005996
Jeff Brownbae8e772014-06-12 19:59:45 -07005997 if (useHapticFeedback) {
5998 performHapticFeedbackLw(null, HapticFeedbackConstants.VIRTUAL_KEY, false);
5999 }
6000
Jeff Brown26875502014-01-30 21:47:47 -08006001 if (isWakeKey) {
Dianne Hackborn280a64e2015-07-13 14:48:08 -07006002 wakeUp(event.getEventTime(), mAllowTheaterModeWakeFromKey, "android.policy:KEY");
Jeff Brown26875502014-01-30 21:47:47 -08006003 }
Bryce Lee584a4452014-10-21 15:55:55 -07006004
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006005 return result;
6006 }
6007
Jeff Brown1c2e4942012-11-06 16:32:01 -08006008 /**
Jim Millerf4c0a132016-05-17 18:11:52 -07006009 * Handle statusbar expansion events.
6010 * @param event
6011 */
Jim Miller07e03842016-06-22 15:18:13 -07006012 private void interceptSystemNavigationKey(KeyEvent event) {
Doris Ling628cea42016-06-09 10:35:02 -07006013 if (event.getAction() == KeyEvent.ACTION_UP && areSystemNavigationKeysEnabled()) {
Jim Millerf4c0a132016-05-17 18:11:52 -07006014 IStatusBarService sbar = getStatusBarService();
6015 if (sbar != null) {
6016 try {
Jim Miller07e03842016-06-22 15:18:13 -07006017 sbar.handleSystemNavigationKey(event.getKeyCode());
Jim Millerf4c0a132016-05-17 18:11:52 -07006018 } catch (RemoteException e1) {
6019 // oops, no statusbar. Ignore event.
6020 }
6021 }
6022 }
6023 }
6024
6025 /**
Jeff Brown13f00f02014-10-31 14:45:50 -07006026 * Returns true if the key can have global actions attached to it.
6027 * We reserve all power management keys for the system since they require
6028 * very careful handling.
6029 */
6030 private static boolean isValidGlobalKey(int keyCode) {
6031 switch (keyCode) {
6032 case KeyEvent.KEYCODE_POWER:
6033 case KeyEvent.KEYCODE_WAKEUP:
6034 case KeyEvent.KEYCODE_SLEEP:
6035 return false;
6036 default:
6037 return true;
6038 }
6039 }
6040
6041 /**
Jeff Brown1c2e4942012-11-06 16:32:01 -08006042 * When the screen is off we ignore some keys that might otherwise typically
6043 * be considered wake keys. We filter them out here.
6044 *
6045 * {@link KeyEvent#KEYCODE_POWER} is notably absent from this list because it
6046 * is always considered a wake key.
6047 */
6048 private boolean isWakeKeyWhenScreenOff(int keyCode) {
6049 switch (keyCode) {
6050 // ignore volume keys unless docked
6051 case KeyEvent.KEYCODE_VOLUME_UP:
6052 case KeyEvent.KEYCODE_VOLUME_DOWN:
6053 case KeyEvent.KEYCODE_VOLUME_MUTE:
6054 return mDockMode != Intent.EXTRA_DOCK_STATE_UNDOCKED;
6055
6056 // ignore media and camera keys
6057 case KeyEvent.KEYCODE_MUTE:
6058 case KeyEvent.KEYCODE_HEADSETHOOK:
6059 case KeyEvent.KEYCODE_MEDIA_PLAY:
6060 case KeyEvent.KEYCODE_MEDIA_PAUSE:
6061 case KeyEvent.KEYCODE_MEDIA_PLAY_PAUSE:
6062 case KeyEvent.KEYCODE_MEDIA_STOP:
6063 case KeyEvent.KEYCODE_MEDIA_NEXT:
6064 case KeyEvent.KEYCODE_MEDIA_PREVIOUS:
6065 case KeyEvent.KEYCODE_MEDIA_REWIND:
6066 case KeyEvent.KEYCODE_MEDIA_RECORD:
6067 case KeyEvent.KEYCODE_MEDIA_FAST_FORWARD:
Jaekyun Seokbfdad8e2013-07-08 13:53:21 +09006068 case KeyEvent.KEYCODE_MEDIA_AUDIO_TRACK:
Jeff Brown1c2e4942012-11-06 16:32:01 -08006069 case KeyEvent.KEYCODE_CAMERA:
6070 return false;
6071 }
6072 return true;
6073 }
6074
6075
Jeff Brown56194eb2011-03-02 19:23:13 -08006076 /** {@inheritDoc} */
6077 @Override
Michael Wright70af00a2014-09-03 19:30:20 -07006078 public int interceptMotionBeforeQueueingNonInteractive(long whenNanos, int policyFlags) {
6079 if ((policyFlags & FLAG_WAKE) != 0) {
Dianne Hackborn280a64e2015-07-13 14:48:08 -07006080 if (wakeUp(whenNanos / 1000000, mAllowTheaterModeWakeFromMotion,
6081 "android.policy:MOTION")) {
Bryce Lee5c138322014-11-03 08:26:09 -08006082 return 0;
6083 }
Michael Wright70af00a2014-09-03 19:30:20 -07006084 }
Bryce Lee5c138322014-11-03 08:26:09 -08006085
Anthony Hugh4b13ab82016-05-17 13:03:00 -07006086 if (shouldDispatchInputWhenNonInteractive(null)) {
Michael Wright70af00a2014-09-03 19:30:20 -07006087 return ACTION_PASS_TO_USER;
6088 }
Bryce Lee5c138322014-11-03 08:26:09 -08006089
Bryce Lee812d7022014-11-10 13:33:28 -08006090 // If we have not passed the action up and we are in theater mode without dreaming,
6091 // there will be no dream to intercept the touch and wake into ambient. The device should
6092 // wake up in this case.
6093 if (isTheaterModeEnabled() && (policyFlags & FLAG_WAKE) != 0) {
Dianne Hackborn280a64e2015-07-13 14:48:08 -07006094 wakeUp(whenNanos / 1000000, mAllowTheaterModeWakeFromMotionWhenNotDreaming,
6095 "android.policy:MOTION");
Bryce Lee812d7022014-11-10 13:33:28 -08006096 }
6097
Jeff Brown037c33e2014-04-09 00:31:55 -07006098 return 0;
Jeff Brown56194eb2011-03-02 19:23:13 -08006099 }
6100
Anthony Hugh4b13ab82016-05-17 13:03:00 -07006101 private boolean shouldDispatchInputWhenNonInteractive(KeyEvent event) {
Wale Ogunwale6b15ea52016-04-04 07:28:27 -07006102 final boolean displayOff = (mDisplay == null || mDisplay.getState() == Display.STATE_OFF);
6103
6104 if (displayOff && !mHasFeatureWatch) {
6105 return false;
6106 }
6107
6108 // Send events to keyguard while the screen is on and it's showing.
6109 if (isKeyguardShowingAndNotOccluded() && !displayOff) {
Bryce Lee5c138322014-11-03 08:26:09 -08006110 return true;
6111 }
6112
Anthony Hugh4b13ab82016-05-17 13:03:00 -07006113 // Watches handle BACK specially
6114 if (mHasFeatureWatch
6115 && event != null
6116 && (event.getKeyCode() == KeyEvent.KEYCODE_BACK
6117 || event.getKeyCode() == KeyEvent.KEYCODE_STEM_PRIMARY)) {
6118 return false;
6119 }
6120
Bryce Lee5c138322014-11-03 08:26:09 -08006121 // Send events to a dozing dream even if the screen is off since the dream
6122 // is in control of the state of the screen.
6123 IDreamManager dreamManager = getDreamManager();
6124
6125 try {
6126 if (dreamManager != null && dreamManager.isDreaming()) {
6127 return true;
6128 }
6129 } catch (RemoteException e) {
6130 Slog.e(TAG, "RemoteException when checking if dreaming", e);
6131 }
6132
6133 // Otherwise, consume events since the user can't see what is being
6134 // interacted with.
6135 return false;
Michael Wright70af00a2014-09-03 19:30:20 -07006136 }
6137
RoboErik001c59c2015-01-26 15:53:51 -08006138 private void dispatchDirectAudioEvent(KeyEvent event) {
6139 if (event.getAction() != KeyEvent.ACTION_DOWN) {
6140 return;
6141 }
6142 int keyCode = event.getKeyCode();
John Spurlockb94f2d62015-03-17 14:11:57 -04006143 int flags = AudioManager.FLAG_SHOW_UI | AudioManager.FLAG_PLAY_SOUND
6144 | AudioManager.FLAG_FROM_KEY;
RoboErik001c59c2015-01-26 15:53:51 -08006145 String pkgName = mContext.getOpPackageName();
6146 switch (keyCode) {
6147 case KeyEvent.KEYCODE_VOLUME_UP:
6148 try {
John Spurlockee5ad722015-03-03 16:17:21 -05006149 getAudioService().adjustSuggestedStreamVolume(AudioManager.ADJUST_RAISE,
John Spurlock90874332015-03-10 16:00:54 -04006150 AudioManager.USE_DEFAULT_STREAM_TYPE, flags, pkgName, TAG);
RoboErik001c59c2015-01-26 15:53:51 -08006151 } catch (RemoteException e) {
6152 Log.e(TAG, "Error dispatching volume up in dispatchTvAudioEvent.", e);
6153 }
6154 break;
6155 case KeyEvent.KEYCODE_VOLUME_DOWN:
6156 try {
John Spurlockee5ad722015-03-03 16:17:21 -05006157 getAudioService().adjustSuggestedStreamVolume(AudioManager.ADJUST_LOWER,
John Spurlock90874332015-03-10 16:00:54 -04006158 AudioManager.USE_DEFAULT_STREAM_TYPE, flags, pkgName, TAG);
RoboErik001c59c2015-01-26 15:53:51 -08006159 } catch (RemoteException e) {
6160 Log.e(TAG, "Error dispatching volume down in dispatchTvAudioEvent.", e);
6161 }
6162 break;
6163 case KeyEvent.KEYCODE_VOLUME_MUTE:
6164 try {
6165 if (event.getRepeatCount() == 0) {
John Spurlockee5ad722015-03-03 16:17:21 -05006166 getAudioService().adjustSuggestedStreamVolume(
6167 AudioManager.ADJUST_TOGGLE_MUTE,
John Spurlock90874332015-03-10 16:00:54 -04006168 AudioManager.USE_DEFAULT_STREAM_TYPE, flags, pkgName, TAG);
RoboErik001c59c2015-01-26 15:53:51 -08006169 }
6170 } catch (RemoteException e) {
6171 Log.e(TAG, "Error dispatching mute in dispatchTvAudioEvent.", e);
6172 }
6173 break;
6174 }
6175 }
6176
Jeff Brown40013652012-05-16 21:22:36 -07006177 void dispatchMediaKeyWithWakeLock(KeyEvent event) {
6178 if (DEBUG_INPUT) {
6179 Slog.d(TAG, "dispatchMediaKeyWithWakeLock: " + event);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006180 }
6181
Jeff Brown40013652012-05-16 21:22:36 -07006182 if (mHavePendingMediaKeyRepeatWithWakeLock) {
6183 if (DEBUG_INPUT) {
6184 Slog.d(TAG, "dispatchMediaKeyWithWakeLock: canceled repeat");
6185 }
6186
6187 mHandler.removeMessages(MSG_DISPATCH_MEDIA_KEY_REPEAT_WITH_WAKE_LOCK);
6188 mHavePendingMediaKeyRepeatWithWakeLock = false;
6189 mBroadcastWakeLock.release(); // pending repeat was holding onto the wake lock
6190 }
6191
6192 dispatchMediaKeyWithWakeLockToAudioService(event);
6193
6194 if (event.getAction() == KeyEvent.ACTION_DOWN
6195 && event.getRepeatCount() == 0) {
6196 mHavePendingMediaKeyRepeatWithWakeLock = true;
6197
6198 Message msg = mHandler.obtainMessage(
6199 MSG_DISPATCH_MEDIA_KEY_REPEAT_WITH_WAKE_LOCK, event);
6200 msg.setAsynchronous(true);
6201 mHandler.sendMessageDelayed(msg, ViewConfiguration.getKeyRepeatTimeout());
6202 } else {
6203 mBroadcastWakeLock.release();
6204 }
6205 }
6206
6207 void dispatchMediaKeyRepeatWithWakeLock(KeyEvent event) {
6208 mHavePendingMediaKeyRepeatWithWakeLock = false;
6209
6210 KeyEvent repeatEvent = KeyEvent.changeTimeRepeat(event,
6211 SystemClock.uptimeMillis(), 1, event.getFlags() | KeyEvent.FLAG_LONG_PRESS);
6212 if (DEBUG_INPUT) {
6213 Slog.d(TAG, "dispatchMediaKeyRepeatWithWakeLock: " + repeatEvent);
6214 }
6215
6216 dispatchMediaKeyWithWakeLockToAudioService(repeatEvent);
6217 mBroadcastWakeLock.release();
6218 }
6219
6220 void dispatchMediaKeyWithWakeLockToAudioService(KeyEvent event) {
Sudheer Shankafc46e9b2016-10-21 17:55:27 -07006221 if (mActivityManagerInternal.isSystemReady()) {
RoboErik430fc482014-06-12 15:49:20 -07006222 MediaSessionLegacyHelper.getHelper(mContext).sendMediaButtonEvent(event, true);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006223 }
6224 }
6225
Michael Wright869a67c2014-08-26 19:33:06 -07006226 void launchVoiceAssistWithWakeLock(boolean keyguardActive) {
Dianne Hackbornb6683c42015-06-18 17:40:33 -07006227 IDeviceIdleController dic = IDeviceIdleController.Stub.asInterface(
6228 ServiceManager.getService(Context.DEVICE_IDLE_CONTROLLER));
6229 if (dic != null) {
6230 try {
6231 dic.exitIdle("voice-search");
6232 } catch (RemoteException e) {
6233 }
6234 }
Michael Wright869a67c2014-08-26 19:33:06 -07006235 Intent voiceIntent =
6236 new Intent(RecognizerIntent.ACTION_VOICE_SEARCH_HANDS_FREE);
6237 voiceIntent.putExtra(RecognizerIntent.EXTRA_SECURE, keyguardActive);
Bart Sears8b1c27c2015-03-18 23:51:02 +00006238 startActivityAsUser(voiceIntent, UserHandle.CURRENT_OR_SELF);
Michael Wright869a67c2014-08-26 19:33:06 -07006239 mBroadcastWakeLock.release();
6240 }
6241
Mike Lockwood1753f7f2009-08-24 14:49:07 -07006242 BroadcastReceiver mDockReceiver = new BroadcastReceiver() {
Craig Mautnereee29c42013-01-17 14:44:34 -08006243 @Override
Mike Lockwood1753f7f2009-08-24 14:49:07 -07006244 public void onReceive(Context context, Intent intent) {
Dianne Hackborn867ab6472010-04-29 13:28:56 -07006245 if (Intent.ACTION_DOCK_EVENT.equals(intent.getAction())) {
6246 mDockMode = intent.getIntExtra(Intent.EXTRA_DOCK_STATE,
6247 Intent.EXTRA_DOCK_STATE_UNDOCKED);
Daniel Sandler6396c722013-04-16 20:19:09 -04006248 } else {
6249 try {
6250 IUiModeManager uiModeService = IUiModeManager.Stub.asInterface(
6251 ServiceManager.getService(Context.UI_MODE_SERVICE));
6252 mUiMode = uiModeService.getCurrentModeType();
6253 } catch (RemoteException e) {
6254 }
Dianne Hackborn80fa1662009-10-07 14:02:10 -07006255 }
Jeff Brown01a98dd2011-09-20 15:08:29 -07006256 updateRotation(true);
Craig Mautnereee29c42013-01-17 14:44:34 -08006257 synchronized (mLock) {
6258 updateOrientationListenerLp();
6259 }
Mike Lockwood1753f7f2009-08-24 14:49:07 -07006260 }
6261 };
6262
Jeff Brown6aaf2952012-10-05 16:01:08 -07006263 BroadcastReceiver mDreamReceiver = new BroadcastReceiver() {
6264 @Override
6265 public void onReceive(Context context, Intent intent) {
6266 if (Intent.ACTION_DREAMING_STARTED.equals(intent.getAction())) {
Jim Miller5ecd8112013-01-09 18:50:26 -08006267 if (mKeyguardDelegate != null) {
6268 mKeyguardDelegate.onDreamingStarted();
Jeff Brown6aaf2952012-10-05 16:01:08 -07006269 }
6270 } else if (Intent.ACTION_DREAMING_STOPPED.equals(intent.getAction())) {
Jim Miller5ecd8112013-01-09 18:50:26 -08006271 if (mKeyguardDelegate != null) {
6272 mKeyguardDelegate.onDreamingStopped();
Jeff Brown6aaf2952012-10-05 16:01:08 -07006273 }
6274 }
6275 }
6276 };
6277
Christopher Tate5e08af02012-09-21 17:17:22 -07006278 BroadcastReceiver mMultiuserReceiver = new BroadcastReceiver() {
6279 @Override
6280 public void onReceive(Context context, Intent intent) {
6281 if (Intent.ACTION_USER_SWITCHED.equals(intent.getAction())) {
6282 // tickle the settings observer: this first ensures that we're
6283 // observing the relevant settings for the newly-active user,
6284 // and then updates our own bookkeeping based on the now-
6285 // current user.
6286 mSettingsObserver.onChange(false);
John Spurlockce479d82012-11-29 09:52:21 -05006287
6288 // force a re-application of focused window sysui visibility.
6289 // the window may never have been shown for this user
6290 // e.g. the keyguard when going through the new-user setup flow
John Spurlock04db1762013-05-13 12:46:41 -04006291 synchronized (mWindowManagerFuncs.getWindowManagerLock()) {
John Spurlockce479d82012-11-29 09:52:21 -05006292 mLastSystemUiFlags = 0;
6293 updateSystemUiVisibilityLw();
6294 }
Christopher Tate5e08af02012-09-21 17:17:22 -07006295 }
6296 }
6297 };
6298
Adrian Roosddc8b272015-05-21 16:28:27 -07006299 private final Runnable mHiddenNavPanic = new Runnable() {
John Spurlockd9b70bd2014-02-06 17:02:44 -05006300 @Override
6301 public void run() {
Adrian Roosddc8b272015-05-21 16:28:27 -07006302 synchronized (mWindowManagerFuncs.getWindowManagerLock()) {
6303 if (!isUserSetupComplete()) {
6304 // Swipe-up for navigation bar is disabled during setup
6305 return;
6306 }
6307 mPendingPanicGestureUptime = SystemClock.uptimeMillis();
Adrian Roos1f425902016-07-22 10:37:50 -07006308 if (!isNavBarEmpty(mLastSystemUiFlags)) {
6309 mNavigationBarController.showTransient();
6310 }
Adrian Roosddc8b272015-05-21 16:28:27 -07006311 }
John Spurlockd9b70bd2014-02-06 17:02:44 -05006312 }
6313 };
6314
John Spurlocke1f366f2013-08-05 12:22:40 -04006315 private void requestTransientBars(WindowState swipeTarget) {
John Spurlock04db1762013-05-13 12:46:41 -04006316 synchronized (mWindowManagerFuncs.getWindowManagerLock()) {
Maurice Lam99c6e072014-04-28 18:24:28 -07006317 if (!isUserSetupComplete()) {
6318 // Swipe-up for navigation bar is disabled during setup
6319 return;
6320 }
John Spurlock27735a42013-08-14 17:57:38 -04006321 boolean sb = mStatusBarController.checkShowTransientBarLw();
Adrian Roos1f425902016-07-22 10:37:50 -07006322 boolean nb = mNavigationBarController.checkShowTransientBarLw()
6323 && !isNavBarEmpty(mLastSystemUiFlags);
John Spurlockad3e6cb2013-04-30 08:47:43 -04006324 if (sb || nb) {
Adrian Roos62b65e42015-02-25 18:05:34 +01006325 // Don't show status bar when swiping on already visible navigation bar
6326 if (!nb && swipeTarget == mNavigationBar) {
John Spurlocke1f366f2013-08-05 12:22:40 -04006327 if (DEBUG) Slog.d(TAG, "Not showing transient bar, wrong swipe target");
John Spurlockad3e6cb2013-04-30 08:47:43 -04006328 return;
6329 }
John Spurlock27735a42013-08-14 17:57:38 -04006330 if (sb) mStatusBarController.showTransient();
6331 if (nb) mNavigationBarController.showTransient();
John Spurlockf1a36642013-10-12 17:50:42 -04006332 mImmersiveModeConfirmation.confirmCurrentPrompt();
John Spurlockad3e6cb2013-04-30 08:47:43 -04006333 updateSystemUiVisibilityLw();
John Spurlock32beb2c2013-03-11 10:16:47 -04006334 }
John Spurlockad3e6cb2013-04-30 08:47:43 -04006335 }
6336 }
6337
Jeff Brown3ee549c2014-09-22 20:14:39 -07006338 // Called on the PowerManager's Notifier thread.
Jeff Brownc38c9be2012-10-04 13:16:19 -07006339 @Override
Jeff Brown416c49c2015-05-26 19:50:18 -07006340 public void startedGoingToSleep(int why) {
6341 if (DEBUG_WAKEUP) Slog.i(TAG, "Started going to sleep... (why=" + why + ")");
Jorim Jaggif1cdf952016-04-05 21:41:06 -07006342 mCameraGestureTriggeredDuringGoingToSleep = false;
6343 mGoingToSleep = true;
Jorim Jaggid175b6c2015-05-27 15:39:09 -07006344 if (mKeyguardDelegate != null) {
6345 mKeyguardDelegate.onStartedGoingToSleep(why);
6346 }
Jeff Brown416c49c2015-05-26 19:50:18 -07006347 }
6348
6349 // Called on the PowerManager's Notifier thread.
6350 @Override
6351 public void finishedGoingToSleep(int why) {
Dianne Hackborn74489012009-03-24 20:50:09 -07006352 EventLog.writeEvent(70000, 0);
Jeff Brown416c49c2015-05-26 19:50:18 -07006353 if (DEBUG_WAKEUP) Slog.i(TAG, "Finished going to sleep... (why=" + why + ")");
Chris Wren9bb290b2015-06-29 12:02:13 -04006354 MetricsLogger.histogram(mContext, "screen_timeout", mLockScreenTimeout / 1000);
Jeff Brown3ee549c2014-09-22 20:14:39 -07006355
Jorim Jaggif1cdf952016-04-05 21:41:06 -07006356 mGoingToSleep = false;
6357
Jeff Brown3ee549c2014-09-22 20:14:39 -07006358 // We must get this work done here because the power manager will drop
6359 // the wake lock and let the system suspend once this function returns.
The Android Open Source Project0727d222009-03-11 12:11:58 -07006360 synchronized (mLock) {
Jeff Brown3ee549c2014-09-22 20:14:39 -07006361 mAwake = false;
Jeff Browna20dda42014-05-27 20:57:24 -07006362 updateWakeGestureListenerLp();
The Android Open Source Project0727d222009-03-11 12:11:58 -07006363 updateOrientationListenerLp();
Mike Lockwood28569302010-01-28 11:54:40 -05006364 updateLockScreenTimeout();
The Android Open Source Project0727d222009-03-11 12:11:58 -07006365 }
Jeff Brown3ee549c2014-09-22 20:14:39 -07006366 if (mKeyguardDelegate != null) {
Jorim Jaggif1cdf952016-04-05 21:41:06 -07006367 mKeyguardDelegate.onFinishedGoingToSleep(why,
6368 mCameraGestureTriggeredDuringGoingToSleep);
Jeff Brown3ee549c2014-09-22 20:14:39 -07006369 }
Jorim Jaggif1cdf952016-04-05 21:41:06 -07006370 mCameraGestureTriggeredDuringGoingToSleep = false;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006371 }
6372
Jeff Brown3ee549c2014-09-22 20:14:39 -07006373 // Called on the PowerManager's Notifier thread.
Jeff Brownc38c9be2012-10-04 13:16:19 -07006374 @Override
Jeff Brown416c49c2015-05-26 19:50:18 -07006375 public void startedWakingUp() {
Dianne Hackborn74489012009-03-24 20:50:09 -07006376 EventLog.writeEvent(70000, 1);
Jeff Brown416c49c2015-05-26 19:50:18 -07006377 if (DEBUG_WAKEUP) Slog.i(TAG, "Started waking up...");
Craig Mautner8a0da012014-05-31 15:13:37 -07006378
Jeff Brown3ee549c2014-09-22 20:14:39 -07006379 // Since goToSleep performs these functions synchronously, we must
6380 // do the same here. We cannot post this work to a handler because
6381 // that might cause it to become reordered with respect to what
6382 // may happen in a future call to goToSleep.
The Android Open Source Project0727d222009-03-11 12:11:58 -07006383 synchronized (mLock) {
Jeff Brown3ee549c2014-09-22 20:14:39 -07006384 mAwake = true;
Jeff Brown3ee549c2014-09-22 20:14:39 -07006385
Jeff Browna20dda42014-05-27 20:57:24 -07006386 updateWakeGestureListenerLp();
The Android Open Source Project0727d222009-03-11 12:11:58 -07006387 updateOrientationListenerLp();
Mike Lockwood28569302010-01-28 11:54:40 -05006388 updateLockScreenTimeout();
The Android Open Source Project0727d222009-03-11 12:11:58 -07006389 }
Jeff Brownc38c9be2012-10-04 13:16:19 -07006390
Jim Miller5ecd8112013-01-09 18:50:26 -08006391 if (mKeyguardDelegate != null) {
Jorim Jaggi4cfdcf52015-07-09 12:13:59 -07006392 mKeyguardDelegate.onStartedWakingUp();
Jeff Brownc38c9be2012-10-04 13:16:19 -07006393 }
Jeff Brown36c4db82014-09-19 12:05:31 -07006394 }
6395
Jeff Brown416c49c2015-05-26 19:50:18 -07006396 // Called on the PowerManager's Notifier thread.
6397 @Override
6398 public void finishedWakingUp() {
6399 if (DEBUG_WAKEUP) Slog.i(TAG, "Finished waking up...");
6400 }
6401
6402 private void wakeUpFromPowerKey(long eventTime) {
Dianne Hackborn280a64e2015-07-13 14:48:08 -07006403 wakeUp(eventTime, mAllowTheaterModeWakeFromPowerKey, "android.policy:POWER");
Jeff Brown416c49c2015-05-26 19:50:18 -07006404 }
6405
Dianne Hackborn280a64e2015-07-13 14:48:08 -07006406 private boolean wakeUp(long wakeTime, boolean wakeInTheaterMode, String reason) {
Bryce Leed3896842015-06-23 17:06:51 -07006407 final boolean theaterModeEnabled = isTheaterModeEnabled();
6408 if (!wakeInTheaterMode && theaterModeEnabled) {
Jeff Brown416c49c2015-05-26 19:50:18 -07006409 return false;
6410 }
6411
Bryce Leed3896842015-06-23 17:06:51 -07006412 if (theaterModeEnabled) {
6413 Settings.Global.putInt(mContext.getContentResolver(),
6414 Settings.Global.THEATER_MODE_ON, 0);
6415 }
6416
Dianne Hackborn280a64e2015-07-13 14:48:08 -07006417 mPowerManager.wakeUp(wakeTime, reason);
Jeff Brown416c49c2015-05-26 19:50:18 -07006418 return true;
6419 }
6420
Jeff Brown36c4db82014-09-19 12:05:31 -07006421 private void finishKeyguardDrawn() {
Jeff Brown3ee549c2014-09-22 20:14:39 -07006422 synchronized (mLock) {
Jorim Jaggif3255482015-07-24 12:32:42 -07006423 if (!mScreenOnEarly || mKeyguardDrawComplete) {
Stefan Kuhne9326dc12015-06-12 09:25:32 -10006424 return; // We are not awake yet or we have already informed of this event.
Jeff Brown3ee549c2014-09-22 20:14:39 -07006425 }
6426
Jeff Brown36c4db82014-09-19 12:05:31 -07006427 mKeyguardDrawComplete = true;
Jeff Brown3ee549c2014-09-22 20:14:39 -07006428 if (mKeyguardDelegate != null) {
6429 mHandler.removeMessages(MSG_KEYGUARD_DRAWN_TIMEOUT);
6430 }
Jorim Jaggi4cfdcf52015-07-09 12:13:59 -07006431 mWindowManagerDrawComplete = false;
Jeff Brown3ee549c2014-09-22 20:14:39 -07006432 }
6433
Jorim Jaggi4cfdcf52015-07-09 12:13:59 -07006434 // ... eventually calls finishWindowsDrawn which will finalize our screen turn on
6435 // as well as enabling the orientation change logic/sensor.
6436 mWindowManagerInternal.waitForAllWindowsDrawn(mWindowManagerDrawCallback,
6437 WAITING_FOR_DRAWN_TIMEOUT);
Jeff Brown3ee549c2014-09-22 20:14:39 -07006438 }
6439
6440 // Called on the DisplayManager's DisplayPowerController thread.
6441 @Override
6442 public void screenTurnedOff() {
6443 if (DEBUG_WAKEUP) Slog.i(TAG, "Screen turned off...");
6444
Jeff Brown48d1b142015-06-10 16:36:03 -07006445 updateScreenOffSleepToken(true);
Jeff Brown3ee549c2014-09-22 20:14:39 -07006446 synchronized (mLock) {
6447 mScreenOnEarly = false;
6448 mScreenOnFully = false;
Jorim Jaggi95c6dae2015-07-29 15:17:23 -07006449 mKeyguardDrawComplete = false;
Jeff Brown3ee549c2014-09-22 20:14:39 -07006450 mWindowManagerDrawComplete = false;
6451 mScreenOnListener = null;
6452 updateOrientationListenerLp();
Jorim Jaggi0d210f62015-07-10 14:24:44 -07006453
6454 if (mKeyguardDelegate != null) {
6455 mKeyguardDelegate.onScreenTurnedOff();
6456 }
Jeff Brown36c4db82014-09-19 12:05:31 -07006457 }
Ruben Brunkfecb6152016-10-28 20:18:57 -07006458 reportScreenStateToVrManager(false);
Jeff Brown36c4db82014-09-19 12:05:31 -07006459 }
6460
Jeff Brown3ee549c2014-09-22 20:14:39 -07006461 // Called on the DisplayManager's DisplayPowerController thread.
Jeff Brown36c4db82014-09-19 12:05:31 -07006462 @Override
6463 public void screenTurningOn(final ScreenOnListener screenOnListener) {
Jeff Brown36c4db82014-09-19 12:05:31 -07006464 if (DEBUG_WAKEUP) Slog.i(TAG, "Screen turning on...");
Jeff Brown36c4db82014-09-19 12:05:31 -07006465
Jeff Brown48d1b142015-06-10 16:36:03 -07006466 updateScreenOffSleepToken(false);
Jeff Brown3ee549c2014-09-22 20:14:39 -07006467 synchronized (mLock) {
6468 mScreenOnEarly = true;
6469 mScreenOnFully = false;
Jorim Jaggi95c6dae2015-07-29 15:17:23 -07006470 mKeyguardDrawComplete = false;
Jeff Brown3ee549c2014-09-22 20:14:39 -07006471 mWindowManagerDrawComplete = false;
6472 mScreenOnListener = screenOnListener;
Jeff Brown36c4db82014-09-19 12:05:31 -07006473
Jorim Jaggi4cfdcf52015-07-09 12:13:59 -07006474 if (mKeyguardDelegate != null) {
Jorim Jaggia4b51bc2015-08-10 18:20:43 -07006475 mHandler.removeMessages(MSG_KEYGUARD_DRAWN_TIMEOUT);
6476 mHandler.sendEmptyMessageDelayed(MSG_KEYGUARD_DRAWN_TIMEOUT, 1000);
Jorim Jaggi4cfdcf52015-07-09 12:13:59 -07006477 mKeyguardDelegate.onScreenTurningOn(mKeyguardDrawnCallback);
6478 } else {
6479 if (DEBUG_WAKEUP) Slog.d(TAG,
6480 "null mKeyguardDelegate: setting mKeyguardDrawComplete.");
6481 finishKeyguardDrawn();
6482 }
6483 }
Jeff Brown36c4db82014-09-19 12:05:31 -07006484 }
6485
Jorim Jaggi0d210f62015-07-10 14:24:44 -07006486 // Called on the DisplayManager's DisplayPowerController thread.
6487 @Override
6488 public void screenTurnedOn() {
6489 synchronized (mLock) {
6490 if (mKeyguardDelegate != null) {
6491 mKeyguardDelegate.onScreenTurnedOn();
6492 }
6493 }
Ruben Brunkfecb6152016-10-28 20:18:57 -07006494 reportScreenStateToVrManager(true);
6495 }
6496
6497 private void reportScreenStateToVrManager(boolean isScreenOn) {
6498 VrManagerInternal vrService = LocalServices.getService(VrManagerInternal.class);
6499 if (vrService == null) {
6500 return;
6501 }
6502 vrService.onScreenStateChanged(isScreenOn);
Jorim Jaggi0d210f62015-07-10 14:24:44 -07006503 }
6504
Jeff Brown36c4db82014-09-19 12:05:31 -07006505 private void finishWindowsDrawn() {
Jeff Brown3ee549c2014-09-22 20:14:39 -07006506 synchronized (mLock) {
6507 if (!mScreenOnEarly || mWindowManagerDrawComplete) {
Stefan Kuhne9326dc12015-06-12 09:25:32 -10006508 return; // Screen is not turned on or we did already handle this case earlier.
Jeff Brown3ee549c2014-09-22 20:14:39 -07006509 }
6510
Jeff Brown36c4db82014-09-19 12:05:31 -07006511 mWindowManagerDrawComplete = true;
Jeff Brown36c4db82014-09-19 12:05:31 -07006512 }
Jeff Brown3ee549c2014-09-22 20:14:39 -07006513
6514 finishScreenTurningOn();
Jeff Brownc38c9be2012-10-04 13:16:19 -07006515 }
6516
Craig Mautner8a0da012014-05-31 15:13:37 -07006517 private void finishScreenTurningOn() {
Stefan Kuhne9326dc12015-06-12 09:25:32 -10006518 synchronized (mLock) {
6519 // We have just finished drawing screen content. Since the orientation listener
6520 // gets only installed when all windows are drawn, we try to install it again.
6521 updateOrientationListenerLp();
6522 }
Jeff Brown3ee549c2014-09-22 20:14:39 -07006523 final ScreenOnListener listener;
6524 final boolean enableScreen;
Jeff Brown36c4db82014-09-19 12:05:31 -07006525 synchronized (mLock) {
Jeff Brown3ee549c2014-09-22 20:14:39 -07006526 if (DEBUG_WAKEUP) Slog.d(TAG,
6527 "finishScreenTurningOn: mAwake=" + mAwake
6528 + ", mScreenOnEarly=" + mScreenOnEarly
6529 + ", mScreenOnFully=" + mScreenOnFully
6530 + ", mKeyguardDrawComplete=" + mKeyguardDrawComplete
6531 + ", mWindowManagerDrawComplete=" + mWindowManagerDrawComplete);
6532
6533 if (mScreenOnFully || !mScreenOnEarly || !mWindowManagerDrawComplete
6534 || (mAwake && !mKeyguardDrawComplete)) {
6535 return; // spurious or not ready yet
Jeff Brown36c4db82014-09-19 12:05:31 -07006536 }
6537
Jeff Brown3ee549c2014-09-22 20:14:39 -07006538 if (DEBUG_WAKEUP) Slog.i(TAG, "Finished screen turning on...");
6539 listener = mScreenOnListener;
Craig Mautner13f6ea72014-06-23 14:57:02 -07006540 mScreenOnListener = null;
Jeff Brown3ee549c2014-09-22 20:14:39 -07006541 mScreenOnFully = true;
6542
6543 // Remember the first time we draw the keyguard so we know when we're done with
6544 // the main part of booting and can enable the screen and hide boot messages.
6545 if (!mKeyguardDrawnOnce && mAwake) {
6546 mKeyguardDrawnOnce = true;
6547 enableScreen = true;
6548 if (mBootMessageNeedsHiding) {
6549 mBootMessageNeedsHiding = false;
6550 hideBootMessages();
6551 }
6552 } else {
6553 enableScreen = false;
6554 }
Jeff Brownc38c9be2012-10-04 13:16:19 -07006555 }
6556
Jeff Brown3ee549c2014-09-22 20:14:39 -07006557 if (listener != null) {
6558 listener.onScreenOn();
6559 }
Jeff Brown4fc45272012-10-10 18:28:14 -07006560
Jeff Brown3ee549c2014-09-22 20:14:39 -07006561 if (enableScreen) {
6562 try {
6563 mWindowManager.enableScreenIfNeeded();
6564 } catch (RemoteException unhandled) {
Jeff Brown36c4db82014-09-19 12:05:31 -07006565 }
Craig Mautnera631d492014-08-05 15:16:01 -07006566 }
6567 }
6568
6569 private void handleHideBootMessage() {
Jeff Brown3ee549c2014-09-22 20:14:39 -07006570 synchronized (mLock) {
6571 if (!mKeyguardDrawnOnce) {
6572 mBootMessageNeedsHiding = true;
6573 return; // keyguard hasn't drawn the first time yet, not done booting
6574 }
Craig Mautnera631d492014-08-05 15:16:01 -07006575 }
Jeff Brown3ee549c2014-09-22 20:14:39 -07006576
6577 if (mBootMsgDialog != null) {
6578 if (DEBUG_WAKEUP) Slog.d(TAG, "handleHideBootMessage: dismissing");
6579 mBootMsgDialog.dismiss();
6580 mBootMsgDialog = null;
Craig Mautnera631d492014-08-05 15:16:01 -07006581 }
Jeff Brownc38c9be2012-10-04 13:16:19 -07006582 }
6583
6584 @Override
Jeff Brown3ee549c2014-09-22 20:14:39 -07006585 public boolean isScreenOn() {
6586 return mScreenOnFully;
Dianne Hackborn08743722009-12-21 12:16:51 -08006587 }
Jeff Brownc38c9be2012-10-04 13:16:19 -07006588
Dianne Hackborn08743722009-12-21 12:16:51 -08006589 /** {@inheritDoc} */
Jose Lima9546b202014-07-02 17:21:51 -07006590 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006591 public void enableKeyguard(boolean enabled) {
Jim Miller5ecd8112013-01-09 18:50:26 -08006592 if (mKeyguardDelegate != null) {
6593 mKeyguardDelegate.setKeyguardEnabled(enabled);
Mike Lockwood3a74bd32011-08-12 13:55:22 -07006594 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006595 }
6596
6597 /** {@inheritDoc} */
Jose Lima9546b202014-07-02 17:21:51 -07006598 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006599 public void exitKeyguardSecurely(OnKeyguardExitResult callback) {
Jim Miller5ecd8112013-01-09 18:50:26 -08006600 if (mKeyguardDelegate != null) {
6601 mKeyguardDelegate.verifyUnlock(callback);
Mike Lockwood3a74bd32011-08-12 13:55:22 -07006602 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006603 }
6604
Tony Mak2c0d6dc2016-04-29 16:16:54 +01006605 @Override
6606 public boolean isKeyguardShowingAndNotOccluded() {
Jim Miller5ecd8112013-01-09 18:50:26 -08006607 if (mKeyguardDelegate == null) return false;
Jim Millerab954542014-10-10 18:21:49 -07006608 return mKeyguardDelegate.isShowing() && !mKeyguardOccluded;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006609 }
6610
Jorim Jaggife762342016-10-13 14:33:27 +02006611 @Override
6612 public boolean isKeyguardTrustedLw() {
6613 if (mKeyguardDelegate == null) return false;
6614 return mKeyguardDelegate.isTrusted();
6615 }
6616
Mike Lockwood520d8bc2011-02-18 13:23:13 -05006617 /** {@inheritDoc} */
Jose Lima9546b202014-07-02 17:21:51 -07006618 @Override
Mike Lockwood520d8bc2011-02-18 13:23:13 -05006619 public boolean isKeyguardLocked() {
6620 return keyguardOn();
6621 }
6622
6623 /** {@inheritDoc} */
Jose Lima9546b202014-07-02 17:21:51 -07006624 @Override
Jim Millere4044bb2016-05-10 18:38:25 -07006625 public boolean isKeyguardSecure(int userId) {
Jim Miller5ecd8112013-01-09 18:50:26 -08006626 if (mKeyguardDelegate == null) return false;
Jim Millere4044bb2016-05-10 18:38:25 -07006627 return mKeyguardDelegate.isSecure(userId);
Mike Lockwood520d8bc2011-02-18 13:23:13 -05006628 }
6629
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006630 /** {@inheritDoc} */
Jose Lima9546b202014-07-02 17:21:51 -07006631 @Override
Jorim Jaggife762342016-10-13 14:33:27 +02006632 public boolean isKeyguardOccluded() {
6633 if (mKeyguardDelegate == null) return false;
6634 return mKeyguardOccluded;
Adrian Roos461829d2015-06-03 14:41:18 -07006635 }
6636
6637 /** {@inheritDoc} */
6638 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006639 public boolean inKeyguardRestrictedKeyInputMode() {
Jim Miller5ecd8112013-01-09 18:50:26 -08006640 if (mKeyguardDelegate == null) return false;
6641 return mKeyguardDelegate.isInputRestricted();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006642 }
6643
Jose Lima9546b202014-07-02 17:21:51 -07006644 @Override
Jorim Jaggi241ae102016-11-02 21:57:33 -07006645 public void dismissKeyguardLw(IKeyguardDismissCallback callback) {
RoboErik8a2cfc32014-05-16 11:19:38 -07006646 if (mKeyguardDelegate != null && mKeyguardDelegate.isShowing()) {
Craig Mautnerc0d2d0a2014-10-31 16:25:15 -07006647 if (DEBUG_KEYGUARD) Slog.d(TAG, "PWM.dismissKeyguardLw");
Jorim Jaggi8d786932016-10-26 19:08:36 -07006648
6649 // ask the keyguard to prompt the user to authenticate if necessary
Jorim Jaggi241ae102016-11-02 21:57:33 -07006650 mKeyguardDelegate.dismiss(callback);
6651 } else if (callback != null) {
6652 try {
6653 callback.onDismissError();
6654 } catch (RemoteException e) {
6655 Slog.w(TAG, "Failed to call callback", e);
6656 }
Dianne Hackborn90c52de2011-09-23 12:57:44 -07006657 }
6658 }
6659
Jorim Jaggicff0acb2014-03-31 16:35:15 +02006660 @Override
6661 public boolean isKeyguardDrawnLw() {
6662 synchronized (mLock) {
Jeff Brown3ee549c2014-09-22 20:14:39 -07006663 return mKeyguardDrawnOnce;
Jorim Jaggicff0acb2014-03-31 16:35:15 +02006664 }
6665 }
6666
Jorim Jaggi0d674622014-05-21 01:34:15 +02006667 @Override
Jorim Jaggi77e10432016-10-26 17:43:56 -07006668 public boolean isShowingDreamLw() {
6669 return mShowingDream;
6670 }
6671
6672 @Override
Jorim Jaggie29b2db2014-05-30 23:17:03 +02006673 public void startKeyguardExitAnimation(long startTime, long fadeoutDuration) {
Jorim Jaggi0d674622014-05-21 01:34:15 +02006674 if (mKeyguardDelegate != null) {
Craig Mautnerc0d2d0a2014-10-31 16:25:15 -07006675 if (DEBUG_KEYGUARD) Slog.d(TAG, "PWM.startKeyguardExitAnimation");
Jorim Jaggie29b2db2014-05-30 23:17:03 +02006676 mKeyguardDelegate.startKeyguardExitAnimation(startTime, fadeoutDuration);
Jorim Jaggi0d674622014-05-21 01:34:15 +02006677 }
6678 }
6679
Jorim Jaggi737af722015-12-31 10:42:27 +01006680 @Override
6681 public void getStableInsetsLw(int displayRotation, int displayWidth, int displayHeight,
6682 Rect outInsets) {
6683 outInsets.setEmpty();
Jorim Jaggi82c9dc92016-02-05 15:10:33 -08006684
6685 // Navigation bar and status bar.
6686 getNonDecorInsetsLw(displayRotation, displayWidth, displayHeight, outInsets);
Matthew Ngca4c1a32016-12-13 16:55:09 -08006687 outInsets.top = mStatusBarHeight;
Jorim Jaggi82c9dc92016-02-05 15:10:33 -08006688 }
6689
6690 @Override
6691 public void getNonDecorInsetsLw(int displayRotation, int displayWidth, int displayHeight,
6692 Rect outInsets) {
6693 outInsets.setEmpty();
6694
6695 // Only navigation bar
Matthew Ngca4c1a32016-12-13 16:55:09 -08006696 if (mHasNavigationBar) {
Adrian Roos85d202b2016-06-02 16:27:47 -07006697 int position = navigationBarPosition(displayWidth, displayHeight, displayRotation);
6698 if (position == NAV_BAR_BOTTOM) {
Jorim Jaggi737af722015-12-31 10:42:27 +01006699 outInsets.bottom = getNavigationBarHeight(displayRotation, mUiMode);
Adrian Roos85d202b2016-06-02 16:27:47 -07006700 } else if (position == NAV_BAR_RIGHT) {
Jorim Jaggi737af722015-12-31 10:42:27 +01006701 outInsets.right = getNavigationBarWidth(displayRotation, mUiMode);
Adrian Roos85d202b2016-06-02 16:27:47 -07006702 } else if (position == NAV_BAR_LEFT) {
6703 outInsets.left = getNavigationBarWidth(displayRotation, mUiMode);
Jorim Jaggi737af722015-12-31 10:42:27 +01006704 }
6705 }
6706 }
6707
Jorim Jaggi5060bd82016-02-19 17:12:19 -08006708 @Override
Jorim Jaggi0ffd49c2016-02-12 15:04:21 -08006709 public boolean isNavBarForcedShownLw(WindowState windowState) {
Jorim Jaggie5638a62016-03-25 22:57:01 -07006710 return mForceShowSystemBars;
Jorim Jaggi0ffd49c2016-02-12 15:04:21 -08006711 }
6712
6713 @Override
Jorim Jaggi5060bd82016-02-19 17:12:19 -08006714 public boolean isDockSideAllowed(int dockSide) {
6715
6716 // We do not allow all dock sides at which the navigation bar touches the docked stack.
6717 if (!mNavigationBarCanMove) {
6718 return dockSide == DOCKED_TOP || dockSide == DOCKED_LEFT || dockSide == DOCKED_RIGHT;
6719 } else {
6720 return dockSide == DOCKED_TOP || dockSide == DOCKED_LEFT;
6721 }
6722 }
6723
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006724 void sendCloseSystemWindows() {
Jorim Jaggib10e33f2015-02-04 21:57:40 +01006725 PhoneWindow.sendCloseSystemWindows(mContext, null);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006726 }
6727
6728 void sendCloseSystemWindows(String reason) {
Jorim Jaggib10e33f2015-02-04 21:57:40 +01006729 PhoneWindow.sendCloseSystemWindows(mContext, reason);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006730 }
Mitsuru Oshima831d0d92009-06-16 18:27:18 -07006731
Jeff Brown01a98dd2011-09-20 15:08:29 -07006732 @Override
6733 public int rotationForOrientationLw(int orientation, int lastRotation) {
Daniel Sandler2ed6ad62011-02-22 14:54:17 -05006734 if (false) {
6735 Slog.v(TAG, "rotationForOrientationLw(orient="
6736 + orientation + ", last=" + lastRotation
6737 + "); user=" + mUserRotation + " "
6738 + ((mUserRotationMode == WindowManagerPolicy.USER_ROTATION_LOCKED)
6739 ? "USER_ROTATION_LOCKED" : "")
6740 );
6741 }
6742
Craig Mautner46ac6fa2013-08-01 10:06:34 -07006743 if (mForceDefaultOrientation) {
6744 return Surface.ROTATION_0;
6745 }
6746
The Android Open Source Project0727d222009-03-11 12:11:58 -07006747 synchronized (mLock) {
Jeff Brownc0347aa2011-09-23 17:26:09 -07006748 int sensorRotation = mOrientationListener.getProposedRotation(); // may be -1
6749 if (sensorRotation < 0) {
Jeff Brown0f862b42012-09-27 21:11:01 -07006750 sensorRotation = lastRotation;
Jeff Brownc0347aa2011-09-23 17:26:09 -07006751 }
Jeff Brown01a98dd2011-09-20 15:08:29 -07006752
Jeff Browndec6cf42011-11-15 14:08:20 -08006753 final int preferredRotation;
Jeff Brown2e7760e2012-04-11 15:14:55 -07006754 if (mLidState == LID_OPEN && mLidOpenRotation >= 0) {
Jeff Brown01a98dd2011-09-20 15:08:29 -07006755 // Ignore sensor when lid switch is open and rotation is forced.
6756 preferredRotation = mLidOpenRotation;
6757 } else if (mDockMode == Intent.EXTRA_DOCK_STATE_CAR
Jeff Brownc0347aa2011-09-23 17:26:09 -07006758 && (mCarDockEnablesAccelerometer || mCarDockRotation >= 0)) {
Jeff Brown01a98dd2011-09-20 15:08:29 -07006759 // Ignore sensor when in car dock unless explicitly enabled.
6760 // This case can override the behavior of NOSENSOR, and can also
6761 // enable 180 degree rotation while docked.
Jeff Brownc0347aa2011-09-23 17:26:09 -07006762 preferredRotation = mCarDockEnablesAccelerometer
Jeff Brown01a98dd2011-09-20 15:08:29 -07006763 ? sensorRotation : mCarDockRotation;
Jeff Brown1a693182011-11-08 14:44:16 -08006764 } else if ((mDockMode == Intent.EXTRA_DOCK_STATE_DESK
6765 || mDockMode == Intent.EXTRA_DOCK_STATE_LE_DESK
6766 || mDockMode == Intent.EXTRA_DOCK_STATE_HE_DESK)
Jeff Brownc0347aa2011-09-23 17:26:09 -07006767 && (mDeskDockEnablesAccelerometer || mDeskDockRotation >= 0)) {
Jeff Brown01a98dd2011-09-20 15:08:29 -07006768 // Ignore sensor when in desk dock unless explicitly enabled.
6769 // This case can override the behavior of NOSENSOR, and can also
6770 // enable 180 degree rotation while docked.
Jeff Brownc0347aa2011-09-23 17:26:09 -07006771 preferredRotation = mDeskDockEnablesAccelerometer
Jeff Brown01a98dd2011-09-20 15:08:29 -07006772 ? sensorRotation : mDeskDockRotation;
Jeff Brownc82c89ed2013-04-17 17:18:15 -07006773 } else if (mHdmiPlugged && mDemoHdmiRotationLock) {
6774 // Ignore sensor when plugged into HDMI when demo HDMI rotation lock enabled.
Jeff Browneb3e4b92011-12-06 19:54:24 -08006775 // Note that the dock orientation overrides the HDMI orientation.
Jeff Brownc82c89ed2013-04-17 17:18:15 -07006776 preferredRotation = mDemoHdmiRotation;
6777 } else if (mHdmiPlugged && mDockMode == Intent.EXTRA_DOCK_STATE_UNDOCKED
6778 && mUndockedHdmiRotation >= 0) {
6779 // Ignore sensor when plugged into HDMI and an undocked orientation has
6780 // been specified in the configuration (only for legacy devices without
6781 // full multi-display support).
6782 // Note that the dock orientation overrides the HDMI orientation.
6783 preferredRotation = mUndockedHdmiRotation;
Chong Zhangae6119ff2014-11-11 18:54:39 -08006784 } else if (mDemoRotationLock) {
6785 // Ignore sensor when demo rotation lock is enabled.
6786 // Note that the dock orientation and HDMI rotation lock override this.
6787 preferredRotation = mDemoRotation;
Dianne Hackbornb9ec1ac2013-04-10 17:34:25 -07006788 } else if (orientation == ActivityInfo.SCREEN_ORIENTATION_LOCKED) {
6789 // Application just wants to remain locked in the last rotation.
6790 preferredRotation = lastRotation;
Jeff Brownbcdfc622014-03-06 19:13:04 -08006791 } else if (!mSupportAutoRotation) {
6792 // If we don't support auto-rotation then bail out here and ignore
6793 // the sensor and any rotation lock settings.
6794 preferredRotation = -1;
Jeff Brown207673cd2012-06-05 17:47:11 -07006795 } else if ((mUserRotationMode == WindowManagerPolicy.USER_ROTATION_FREE
Jeff Brown01a98dd2011-09-20 15:08:29 -07006796 && (orientation == ActivityInfo.SCREEN_ORIENTATION_USER
Dianne Hackbornb9ec1ac2013-04-10 17:34:25 -07006797 || orientation == ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED
6798 || orientation == ActivityInfo.SCREEN_ORIENTATION_USER_LANDSCAPE
6799 || orientation == ActivityInfo.SCREEN_ORIENTATION_USER_PORTRAIT
6800 || orientation == ActivityInfo.SCREEN_ORIENTATION_FULL_USER))
Jeff Brown01a98dd2011-09-20 15:08:29 -07006801 || orientation == ActivityInfo.SCREEN_ORIENTATION_SENSOR
6802 || orientation == ActivityInfo.SCREEN_ORIENTATION_FULL_SENSOR
6803 || orientation == ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE
6804 || orientation == ActivityInfo.SCREEN_ORIENTATION_SENSOR_PORTRAIT) {
6805 // Otherwise, use sensor only if requested by the application or enabled
6806 // by default for USER or UNSPECIFIED modes. Does not apply to NOSENSOR.
Jeff Brownd3187e32011-09-21 19:26:44 -07006807 if (mAllowAllRotations < 0) {
6808 // Can't read this during init() because the context doesn't
6809 // have display metrics at that time so we cannot determine
6810 // tablet vs. phone then.
6811 mAllowAllRotations = mContext.getResources().getBoolean(
6812 com.android.internal.R.bool.config_allowAllRotations) ? 1 : 0;
6813 }
Jeff Brown01a98dd2011-09-20 15:08:29 -07006814 if (sensorRotation != Surface.ROTATION_180
Jeff Brownd3187e32011-09-21 19:26:44 -07006815 || mAllowAllRotations == 1
Dianne Hackbornb9ec1ac2013-04-10 17:34:25 -07006816 || orientation == ActivityInfo.SCREEN_ORIENTATION_FULL_SENSOR
6817 || orientation == ActivityInfo.SCREEN_ORIENTATION_FULL_USER) {
Jeff Brown01a98dd2011-09-20 15:08:29 -07006818 preferredRotation = sensorRotation;
6819 } else {
6820 preferredRotation = lastRotation;
6821 }
Jeff Brown207673cd2012-06-05 17:47:11 -07006822 } else if (mUserRotationMode == WindowManagerPolicy.USER_ROTATION_LOCKED
6823 && orientation != ActivityInfo.SCREEN_ORIENTATION_NOSENSOR) {
6824 // Apply rotation lock. Does not apply to NOSENSOR.
6825 // The idea is that the user rotation expresses a weak preference for the direction
6826 // of gravity and as NOSENSOR is never affected by gravity, then neither should
6827 // NOSENSOR be affected by rotation lock (although it will be affected by docks).
Jeff Brown4dfce202011-10-05 12:00:10 -07006828 preferredRotation = mUserRotation;
Jeff Browndec6cf42011-11-15 14:08:20 -08006829 } else {
6830 // No overriding preference.
6831 // We will do exactly what the application asked us to do.
6832 preferredRotation = -1;
Jeff Brown01a98dd2011-09-20 15:08:29 -07006833 }
6834
Dianne Hackborne5439f22010-10-02 16:53:50 -07006835 switch (orientation) {
6836 case ActivityInfo.SCREEN_ORIENTATION_PORTRAIT:
Jeff Browndec6cf42011-11-15 14:08:20 -08006837 // Return portrait unless overridden.
6838 if (isAnyPortrait(preferredRotation)) {
6839 return preferredRotation;
6840 }
Dianne Hackborne5439f22010-10-02 16:53:50 -07006841 return mPortraitRotation;
Dianne Hackborne5439f22010-10-02 16:53:50 -07006842
Jeff Brown01a98dd2011-09-20 15:08:29 -07006843 case ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE:
Jeff Browndec6cf42011-11-15 14:08:20 -08006844 // Return landscape unless overridden.
6845 if (isLandscapeOrSeascape(preferredRotation)) {
6846 return preferredRotation;
6847 }
Jeff Brown01a98dd2011-09-20 15:08:29 -07006848 return mLandscapeRotation;
6849
6850 case ActivityInfo.SCREEN_ORIENTATION_REVERSE_PORTRAIT:
Jeff Browndec6cf42011-11-15 14:08:20 -08006851 // Return reverse portrait unless overridden.
6852 if (isAnyPortrait(preferredRotation)) {
6853 return preferredRotation;
6854 }
Jeff Brown01a98dd2011-09-20 15:08:29 -07006855 return mUpsideDownRotation;
6856
6857 case ActivityInfo.SCREEN_ORIENTATION_REVERSE_LANDSCAPE:
Jeff Browndec6cf42011-11-15 14:08:20 -08006858 // Return seascape unless overridden.
6859 if (isLandscapeOrSeascape(preferredRotation)) {
6860 return preferredRotation;
6861 }
Jeff Brown01a98dd2011-09-20 15:08:29 -07006862 return mSeascapeRotation;
6863
6864 case ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE:
Dianne Hackbornb9ec1ac2013-04-10 17:34:25 -07006865 case ActivityInfo.SCREEN_ORIENTATION_USER_LANDSCAPE:
Jeff Brown01a98dd2011-09-20 15:08:29 -07006866 // Return either landscape rotation.
6867 if (isLandscapeOrSeascape(preferredRotation)) {
6868 return preferredRotation;
6869 }
6870 if (isLandscapeOrSeascape(lastRotation)) {
Jeff Brown4519f072011-01-23 13:16:01 -08006871 return lastRotation;
6872 }
Jeff Brown01a98dd2011-09-20 15:08:29 -07006873 return mLandscapeRotation;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006874
Jeff Brown01a98dd2011-09-20 15:08:29 -07006875 case ActivityInfo.SCREEN_ORIENTATION_SENSOR_PORTRAIT:
Dianne Hackbornb9ec1ac2013-04-10 17:34:25 -07006876 case ActivityInfo.SCREEN_ORIENTATION_USER_PORTRAIT:
Jeff Brown01a98dd2011-09-20 15:08:29 -07006877 // Return either portrait rotation.
6878 if (isAnyPortrait(preferredRotation)) {
6879 return preferredRotation;
6880 }
6881 if (isAnyPortrait(lastRotation)) {
6882 return lastRotation;
6883 }
6884 return mPortraitRotation;
6885
6886 default:
Jeff Brown4dfce202011-10-05 12:00:10 -07006887 // For USER, UNSPECIFIED, NOSENSOR, SENSOR and FULL_SENSOR,
6888 // just return the preferred orientation we already calculated.
Jeff Brown01a98dd2011-09-20 15:08:29 -07006889 if (preferredRotation >= 0) {
6890 return preferredRotation;
6891 }
Dianne Hackborndacea8c2011-04-21 17:26:39 -07006892 return Surface.ROTATION_0;
Daniel Sandlere7e5ac22011-02-22 16:10:21 -05006893 }
6894 }
Steve Howarda7bfe6a2010-09-23 16:47:49 -07006895 }
6896
Jeff Brown01a98dd2011-09-20 15:08:29 -07006897 @Override
6898 public boolean rotationHasCompatibleMetricsLw(int orientation, int rotation) {
6899 switch (orientation) {
6900 case ActivityInfo.SCREEN_ORIENTATION_PORTRAIT:
6901 case ActivityInfo.SCREEN_ORIENTATION_REVERSE_PORTRAIT:
6902 case ActivityInfo.SCREEN_ORIENTATION_SENSOR_PORTRAIT:
6903 return isAnyPortrait(rotation);
6904
6905 case ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE:
6906 case ActivityInfo.SCREEN_ORIENTATION_REVERSE_LANDSCAPE:
6907 case ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE:
6908 return isLandscapeOrSeascape(rotation);
6909
6910 default:
6911 return true;
6912 }
Steve Howarda7bfe6a2010-09-23 16:47:49 -07006913 }
6914
Jeff Brownc0347aa2011-09-23 17:26:09 -07006915 @Override
6916 public void setRotationLw(int rotation) {
6917 mOrientationListener.setCurrentRotation(rotation);
6918 }
6919
Jeff Brown01a98dd2011-09-20 15:08:29 -07006920 private boolean isLandscapeOrSeascape(int rotation) {
6921 return rotation == mLandscapeRotation || rotation == mSeascapeRotation;
Dianne Hackborne5439f22010-10-02 16:53:50 -07006922 }
6923
Jeff Brown01a98dd2011-09-20 15:08:29 -07006924 private boolean isAnyPortrait(int rotation) {
6925 return rotation == mPortraitRotation || rotation == mUpsideDownRotation;
Dianne Hackborne5439f22010-10-02 16:53:50 -07006926 }
6927
Jose Lima9546b202014-07-02 17:21:51 -07006928 @Override
Svetoslav Ganov80943d82013-01-02 10:25:37 -08006929 public int getUserRotationMode() {
6930 return Settings.System.getIntForUser(mContext.getContentResolver(),
Brett Chabot7e55c402013-05-16 19:38:08 -07006931 Settings.System.ACCELEROMETER_ROTATION, 0, UserHandle.USER_CURRENT) != 0 ?
6932 WindowManagerPolicy.USER_ROTATION_FREE :
6933 WindowManagerPolicy.USER_ROTATION_LOCKED;
Svetoslav Ganov80943d82013-01-02 10:25:37 -08006934 }
Daniel Sandlerb73617d2010-08-17 00:41:00 -04006935
6936 // User rotation: to be used when all else fails in assigning an orientation to the device
Jose Lima9546b202014-07-02 17:21:51 -07006937 @Override
Daniel Sandlerb73617d2010-08-17 00:41:00 -04006938 public void setUserRotationMode(int mode, int rot) {
6939 ContentResolver res = mContext.getContentResolver();
Daniel Sandler2ed6ad62011-02-22 14:54:17 -05006940
6941 // mUserRotationMode and mUserRotation will be assigned by the content observer
Daniel Sandlerb73617d2010-08-17 00:41:00 -04006942 if (mode == WindowManagerPolicy.USER_ROTATION_LOCKED) {
Christopher Tate5e08af02012-09-21 17:17:22 -07006943 Settings.System.putIntForUser(res,
Daniel Sandlerb73617d2010-08-17 00:41:00 -04006944 Settings.System.USER_ROTATION,
Christopher Tate5e08af02012-09-21 17:17:22 -07006945 rot,
6946 UserHandle.USER_CURRENT);
6947 Settings.System.putIntForUser(res,
Daniel Sandler2ed6ad62011-02-22 14:54:17 -05006948 Settings.System.ACCELEROMETER_ROTATION,
Christopher Tate5e08af02012-09-21 17:17:22 -07006949 0,
6950 UserHandle.USER_CURRENT);
Daniel Sandlerb73617d2010-08-17 00:41:00 -04006951 } else {
Christopher Tate5e08af02012-09-21 17:17:22 -07006952 Settings.System.putIntForUser(res,
Daniel Sandlerb73617d2010-08-17 00:41:00 -04006953 Settings.System.ACCELEROMETER_ROTATION,
Christopher Tate5e08af02012-09-21 17:17:22 -07006954 1,
6955 UserHandle.USER_CURRENT);
Daniel Sandlerb73617d2010-08-17 00:41:00 -04006956 }
6957 }
6958
Jose Lima9546b202014-07-02 17:21:51 -07006959 @Override
Jeff Brownac143512012-04-05 18:57:33 -07006960 public void setSafeMode(boolean safeMode) {
6961 mSafeMode = safeMode;
6962 performHapticFeedbackLw(null, safeMode
6963 ? HapticFeedbackConstants.SAFE_MODE_ENABLED
6964 : HapticFeedbackConstants.SAFE_MODE_DISABLED, true);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006965 }
Craig Mautnereda67292013-04-28 13:50:14 -07006966
Dianne Hackborn181ceb52009-08-27 22:16:40 -07006967 static long[] getLongIntArray(Resources r, int resid) {
6968 int[] ar = r.getIntArray(resid);
6969 if (ar == null) {
6970 return null;
6971 }
6972 long[] out = new long[ar.length];
6973 for (int i=0; i<ar.length; i++) {
6974 out[i] = ar[i];
6975 }
6976 return out;
6977 }
Craig Mautnereda67292013-04-28 13:50:14 -07006978
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006979 /** {@inheritDoc} */
Craig Mautnereda67292013-04-28 13:50:14 -07006980 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006981 public void systemReady() {
Jorim Jaggie69c9312016-10-31 18:24:38 -07006982 mKeyguardDelegate = new KeyguardServiceDelegate(mContext,
6983 new StateCallback() {
6984 @Override
6985 public void onTrustedChanged() {
6986 mWindowManagerFuncs.notifyKeyguardTrustedChanged();
6987 }
6988 });
Mike Lockwooded8902d2013-11-15 11:01:47 -08006989 mKeyguardDelegate.onSystemReady();
6990
Michael Wright3818c922014-09-02 13:59:07 -07006991 readCameraLensCoverState();
Jeff Brown4f5fa282014-06-12 19:19:15 -07006992 updateUiMode();
Adrian Roos3542f7d2015-07-13 15:57:53 -07006993 boolean bindKeyguardNow;
Dianne Hackbornb1a79802009-09-29 15:18:31 -07006994 synchronized (mLock) {
6995 updateOrientationListenerLp();
Dianne Hackbornc777e072010-02-12 13:07:59 -08006996 mSystemReady = true;
6997 mHandler.post(new Runnable() {
Craig Mautnereda67292013-04-28 13:50:14 -07006998 @Override
Dianne Hackbornc777e072010-02-12 13:07:59 -08006999 public void run() {
7000 updateSettings();
7001 }
7002 });
Adrian Roos3542f7d2015-07-13 15:57:53 -07007003
7004 bindKeyguardNow = mDeferBindKeyguard;
7005 if (bindKeyguardNow) {
7006 // systemBooted ran but wasn't able to bind to the Keyguard, we'll do it now.
7007 mDeferBindKeyguard = false;
7008 }
7009 }
7010
7011 if (bindKeyguardNow) {
7012 mKeyguardDelegate.bindService(mContext);
7013 mKeyguardDelegate.onBootCompleted();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08007014 }
Michael Wrighta4d22d72015-09-16 23:19:26 +01007015 mSystemGestures.systemReady();
Amith Yamasani02a03812016-04-22 17:32:00 -07007016 mImmersiveModeConfirmation.systemReady();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08007017 }
Dianne Hackborn661cd522011-08-22 00:26:20 -07007018
Dianne Hackbornba24e4d2011-09-01 11:17:06 -07007019 /** {@inheritDoc} */
Jose Lima9546b202014-07-02 17:21:51 -07007020 @Override
Dianne Hackbornba24e4d2011-09-01 11:17:06 -07007021 public void systemBooted() {
Adrian Roos3542f7d2015-07-13 15:57:53 -07007022 boolean bindKeyguardNow = false;
7023 synchronized (mLock) {
7024 // Time to bind Keyguard; take care to only bind it once, either here if ready or
7025 // in systemReady if not.
7026 if (mKeyguardDelegate != null) {
7027 bindKeyguardNow = true;
7028 } else {
7029 // Because mKeyguardDelegate is null, we know that the synchronized block in
7030 // systemReady didn't run yet and setting this will actually have an effect.
7031 mDeferBindKeyguard = true;
7032 }
7033 }
7034 if (bindKeyguardNow) {
Jason Monk5eeebf52014-09-26 12:36:51 -04007035 mKeyguardDelegate.bindService(mContext);
Jim Millere5f910a2013-10-16 18:15:46 -07007036 mKeyguardDelegate.onBootCompleted();
7037 }
Dianne Hackbornba24e4d2011-09-01 11:17:06 -07007038 synchronized (mLock) {
7039 mSystemBooted = true;
7040 }
Jeff Brown416c49c2015-05-26 19:50:18 -07007041 startedWakingUp();
Jeff Brown36c4db82014-09-19 12:05:31 -07007042 screenTurningOn(null);
Jorim Jaggic0496072015-08-19 15:14:52 -07007043 screenTurnedOn();
Dianne Hackbornba24e4d2011-09-01 11:17:06 -07007044 }
7045
Dianne Hackborn661cd522011-08-22 00:26:20 -07007046 ProgressDialog mBootMsgDialog = null;
7047
7048 /** {@inheritDoc} */
Jose Lima9546b202014-07-02 17:21:51 -07007049 @Override
Dianne Hackborn661cd522011-08-22 00:26:20 -07007050 public void showBootMessage(final CharSequence msg, final boolean always) {
7051 mHandler.post(new Runnable() {
7052 @Override public void run() {
7053 if (mBootMsgDialog == null) {
Craig Stout4c0cb8a2014-04-04 13:03:10 -07007054 int theme;
Michael Kwan5a861672016-06-09 19:44:04 -07007055 if (mContext.getPackageManager().hasSystemFeature(FEATURE_TELEVISION)) {
Craig Stout4c0cb8a2014-04-04 13:03:10 -07007056 theme = com.android.internal.R.style.Theme_Leanback_Dialog_Alert;
7057 } else {
7058 theme = 0;
7059 }
Vinod Krishnanfa8fc412014-04-18 14:35:53 -07007060
7061 mBootMsgDialog = new ProgressDialog(mContext, theme) {
Dianne Hackborn295e3c22011-08-25 13:19:08 -07007062 // This dialog will consume all events coming in to
7063 // it, to avoid it trying to do things too early in boot.
7064 @Override public boolean dispatchKeyEvent(KeyEvent event) {
7065 return true;
7066 }
7067 @Override public boolean dispatchKeyShortcutEvent(KeyEvent event) {
7068 return true;
7069 }
7070 @Override public boolean dispatchTouchEvent(MotionEvent ev) {
7071 return true;
7072 }
7073 @Override public boolean dispatchTrackballEvent(MotionEvent ev) {
7074 return true;
7075 }
7076 @Override public boolean dispatchGenericMotionEvent(MotionEvent ev) {
7077 return true;
7078 }
7079 @Override public boolean dispatchPopulateAccessibilityEvent(
7080 AccessibilityEvent event) {
7081 return true;
7082 }
7083 };
Jeff Hao9f60c082014-10-28 18:51:07 -07007084 if (mContext.getPackageManager().isUpgrade()) {
7085 mBootMsgDialog.setTitle(R.string.android_upgrading_title);
7086 } else {
7087 mBootMsgDialog.setTitle(R.string.android_start_title);
7088 }
Dianne Hackborn661cd522011-08-22 00:26:20 -07007089 mBootMsgDialog.setProgressStyle(ProgressDialog.STYLE_SPINNER);
7090 mBootMsgDialog.setIndeterminate(true);
7091 mBootMsgDialog.getWindow().setType(
Dianne Hackborn29aae6f2011-08-18 18:30:09 -07007092 WindowManager.LayoutParams.TYPE_BOOT_PROGRESS);
Dianne Hackborn661cd522011-08-22 00:26:20 -07007093 mBootMsgDialog.getWindow().addFlags(
7094 WindowManager.LayoutParams.FLAG_DIM_BEHIND
7095 | WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN);
7096 mBootMsgDialog.getWindow().setDimAmount(1);
Dianne Hackbornd9efb952011-12-07 14:56:51 -08007097 WindowManager.LayoutParams lp = mBootMsgDialog.getWindow().getAttributes();
7098 lp.screenOrientation = ActivityInfo.SCREEN_ORIENTATION_NOSENSOR;
7099 mBootMsgDialog.getWindow().setAttributes(lp);
Dianne Hackborn661cd522011-08-22 00:26:20 -07007100 mBootMsgDialog.setCancelable(false);
7101 mBootMsgDialog.show();
7102 }
7103 mBootMsgDialog.setMessage(msg);
7104 }
7105 });
7106 }
7107
7108 /** {@inheritDoc} */
Jose Lima9546b202014-07-02 17:21:51 -07007109 @Override
Dianne Hackborn661cd522011-08-22 00:26:20 -07007110 public void hideBootMessages() {
Craig Mautnera631d492014-08-05 15:16:01 -07007111 mHandler.sendEmptyMessage(MSG_HIDE_BOOT_MESSAGE);
Dianne Hackborn661cd522011-08-22 00:26:20 -07007112 }
7113
Mike Lockwood28569302010-01-28 11:54:40 -05007114 /** {@inheritDoc} */
Jose Lima9546b202014-07-02 17:21:51 -07007115 @Override
Mike Lockwood28569302010-01-28 11:54:40 -05007116 public void userActivity() {
Dianne Hackborndf89e652011-10-06 22:35:11 -07007117 // ***************************************
7118 // NOTE NOTE NOTE NOTE NOTE NOTE NOTE NOTE
7119 // ***************************************
7120 // THIS IS CALLED FROM DEEP IN THE POWER MANAGER
7121 // WITH ITS LOCKS HELD.
7122 //
7123 // This code must be VERY careful about the locks
7124 // it acquires.
7125 // In fact, the current code acquires way too many,
7126 // and probably has lurking deadlocks.
7127
Mike Lockwood28569302010-01-28 11:54:40 -05007128 synchronized (mScreenLockTimeout) {
7129 if (mLockScreenTimerActive) {
7130 // reset the timer
7131 mHandler.removeCallbacks(mScreenLockTimeout);
7132 mHandler.postDelayed(mScreenLockTimeout, mLockScreenTimeout);
7133 }
7134 }
Daniel Sandler0601eb72011-04-13 01:01:32 -04007135 }
7136
Adam Cohenf7522022012-10-03 20:03:18 -07007137 class ScreenLockTimeout implements Runnable {
7138 Bundle options;
7139
7140 @Override
Mike Lockwood28569302010-01-28 11:54:40 -05007141 public void run() {
7142 synchronized (this) {
7143 if (localLOGV) Log.v(TAG, "mScreenLockTimeout activating keyguard");
Jim Miller5ecd8112013-01-09 18:50:26 -08007144 if (mKeyguardDelegate != null) {
7145 mKeyguardDelegate.doKeyguardTimeout(options);
Mike Lockwood3a74bd32011-08-12 13:55:22 -07007146 }
Mike Lockwood28569302010-01-28 11:54:40 -05007147 mLockScreenTimerActive = false;
Adam Cohenf7522022012-10-03 20:03:18 -07007148 options = null;
Mike Lockwood28569302010-01-28 11:54:40 -05007149 }
7150 }
Mike Lockwood28569302010-01-28 11:54:40 -05007151
Adam Cohenf7522022012-10-03 20:03:18 -07007152 public void setLockOptions(Bundle options) {
7153 this.options = options;
7154 }
7155 }
7156
7157 ScreenLockTimeout mScreenLockTimeout = new ScreenLockTimeout();
7158
Jose Lima9546b202014-07-02 17:21:51 -07007159 @Override
Adam Cohenf7522022012-10-03 20:03:18 -07007160 public void lockNow(Bundle options) {
Jim Miller93c518e2012-01-17 15:55:31 -08007161 mContext.enforceCallingOrSelfPermission(android.Manifest.permission.DEVICE_POWER, null);
7162 mHandler.removeCallbacks(mScreenLockTimeout);
Adam Cohenf7522022012-10-03 20:03:18 -07007163 if (options != null) {
7164 // In case multiple calls are made to lockNow, we don't wipe out the options
7165 // until the runnable actually executes.
7166 mScreenLockTimeout.setLockOptions(options);
7167 }
Jim Miller93c518e2012-01-17 15:55:31 -08007168 mHandler.post(mScreenLockTimeout);
7169 }
7170
Mike Lockwood28569302010-01-28 11:54:40 -05007171 private void updateLockScreenTimeout() {
7172 synchronized (mScreenLockTimeout) {
Jeff Brown3ee549c2014-09-22 20:14:39 -07007173 boolean enable = (mAllowLockscreenWhenOn && mAwake &&
Jim Millere4044bb2016-05-10 18:38:25 -07007174 mKeyguardDelegate != null && mKeyguardDelegate.isSecure(mCurrentUserId));
Mike Lockwood28569302010-01-28 11:54:40 -05007175 if (mLockScreenTimerActive != enable) {
7176 if (enable) {
7177 if (localLOGV) Log.v(TAG, "setting lockscreen timer");
Jim Miller2967f482016-01-07 15:05:32 -08007178 mHandler.removeCallbacks(mScreenLockTimeout); // remove any pending requests
Mike Lockwood28569302010-01-28 11:54:40 -05007179 mHandler.postDelayed(mScreenLockTimeout, mLockScreenTimeout);
7180 } else {
7181 if (localLOGV) Log.v(TAG, "clearing lockscreen timer");
7182 mHandler.removeCallbacks(mScreenLockTimeout);
7183 }
7184 mLockScreenTimerActive = enable;
7185 }
7186 }
7187 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08007188
Jeff Brown061ea992015-04-17 19:55:47 -07007189 private void updateDreamingSleepToken(boolean acquire) {
7190 if (acquire) {
7191 if (mDreamingSleepToken == null) {
7192 mDreamingSleepToken = mActivityManagerInternal.acquireSleepToken("Dream");
7193 }
7194 } else {
7195 if (mDreamingSleepToken != null) {
7196 mDreamingSleepToken.release();
Jeff Brown48d1b142015-06-10 16:36:03 -07007197 mDreamingSleepToken = null;
7198 }
7199 }
7200 }
7201
7202 private void updateScreenOffSleepToken(boolean acquire) {
7203 if (acquire) {
7204 if (mScreenOffSleepToken == null) {
7205 mScreenOffSleepToken = mActivityManagerInternal.acquireSleepToken("ScreenOff");
7206 }
7207 } else {
7208 if (mScreenOffSleepToken != null) {
7209 mScreenOffSleepToken.release();
7210 mScreenOffSleepToken = null;
Jeff Brown061ea992015-04-17 19:55:47 -07007211 }
7212 }
7213 }
7214
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08007215 /** {@inheritDoc} */
Craig Mautnereda67292013-04-28 13:50:14 -07007216 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08007217 public void enableScreenAfterBoot() {
7218 readLidState();
Jeff Brownc458ce92012-04-30 14:58:40 -07007219 applyLidSwitchState();
Jeff Brown01a98dd2011-09-20 15:08:29 -07007220 updateRotation(true);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08007221 }
Dianne Hackbornf54c8f92009-09-19 14:03:57 -07007222
Jeff Brownc458ce92012-04-30 14:58:40 -07007223 private void applyLidSwitchState() {
Jeff Brownc458ce92012-04-30 14:58:40 -07007224 if (mLidState == LID_CLOSED && mLidControlsSleep) {
Jeff Brown6d8fd272014-05-20 21:24:38 -07007225 mPowerManager.goToSleep(SystemClock.uptimeMillis(),
Jeff Brownc12035c2014-08-13 18:52:25 -07007226 PowerManager.GO_TO_SLEEP_REASON_LID_SWITCH,
Jeff Brown6d8fd272014-05-20 21:24:38 -07007227 PowerManager.GO_TO_SLEEP_FLAG_NO_DOZE);
Edward Savage-Jones7def60d2015-11-13 13:27:03 +01007228 } else if (mLidState == LID_CLOSED && mLidControlsScreenLock) {
7229 mWindowManagerFuncs.lockDeviceNow();
Jeff Brownc458ce92012-04-30 14:58:40 -07007230 }
Jeff Browna20dda42014-05-27 20:57:24 -07007231
7232 synchronized (mLock) {
7233 updateWakeGestureListenerLp();
7234 }
Jeff Brown01a98dd2011-09-20 15:08:29 -07007235 }
7236
Jeff Brown4f5fa282014-06-12 19:19:15 -07007237 void updateUiMode() {
7238 if (mUiModeManager == null) {
7239 mUiModeManager = IUiModeManager.Stub.asInterface(
7240 ServiceManager.getService(Context.UI_MODE_SERVICE));
7241 }
7242 try {
7243 mUiMode = mUiModeManager.getCurrentModeType();
7244 } catch (RemoteException e) {
7245 }
7246 }
7247
Jeff Brown01a98dd2011-09-20 15:08:29 -07007248 void updateRotation(boolean alwaysSendConfiguration) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08007249 try {
7250 //set orientation on WindowManager
Dianne Hackbornf87d1962012-04-04 12:48:24 -07007251 mWindowManager.updateRotation(alwaysSendConfiguration, false);
7252 } catch (RemoteException e) {
7253 // Ignore
7254 }
7255 }
7256
7257 void updateRotation(boolean alwaysSendConfiguration, boolean forceRelayout) {
7258 try {
7259 //set orientation on WindowManager
7260 mWindowManager.updateRotation(alwaysSendConfiguration, forceRelayout);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08007261 } catch (RemoteException e) {
7262 // Ignore
7263 }
7264 }
7265
Daniel Sandler6396c722013-04-16 20:19:09 -04007266 /**
7267 * Return an Intent to launch the currently active dock app as home. Returns
7268 * null if the standard home should be launched, which is the case if any of the following is
7269 * true:
7270 * <ul>
7271 * <li>The device is not in either car mode or desk mode
keunyounga7710492015-09-23 11:33:58 -07007272 * <li>The device is in car mode but mEnableCarDockHomeCapture is false
Daniel Sandler6396c722013-04-16 20:19:09 -04007273 * <li>The device is in desk mode but ENABLE_DESK_DOCK_HOME_CAPTURE is false
7274 * <li>The device is in car mode but there's no CAR_DOCK app with METADATA_DOCK_HOME
7275 * <li>The device is in desk mode but there's no DESK_DOCK app with METADATA_DOCK_HOME
7276 * </ul>
Craig Mautnereda67292013-04-28 13:50:14 -07007277 * @return A dock intent.
Daniel Sandler6396c722013-04-16 20:19:09 -04007278 */
7279 Intent createHomeDockIntent() {
7280 Intent intent = null;
7281
7282 // What home does is based on the mode, not the dock state. That
7283 // is, when in car mode you should be taken to car home regardless
7284 // of whether we are actually in a car dock.
7285 if (mUiMode == Configuration.UI_MODE_TYPE_CAR) {
keunyounga7710492015-09-23 11:33:58 -07007286 if (mEnableCarDockHomeCapture) {
Daniel Sandler6396c722013-04-16 20:19:09 -04007287 intent = mCarDockIntent;
7288 }
7289 } else if (mUiMode == Configuration.UI_MODE_TYPE_DESK) {
7290 if (ENABLE_DESK_DOCK_HOME_CAPTURE) {
7291 intent = mDeskDockIntent;
7292 }
Jeff Brown4f5fa282014-06-12 19:19:15 -07007293 } else if (mUiMode == Configuration.UI_MODE_TYPE_WATCH
7294 && (mDockMode == Intent.EXTRA_DOCK_STATE_DESK
7295 || mDockMode == Intent.EXTRA_DOCK_STATE_HE_DESK
7296 || mDockMode == Intent.EXTRA_DOCK_STATE_LE_DESK)) {
7297 // Always launch dock home from home when watch is docked, if it exists.
7298 intent = mDeskDockIntent;
Daniel Sandler6396c722013-04-16 20:19:09 -04007299 }
7300
7301 if (intent == null) {
7302 return null;
7303 }
7304
7305 ActivityInfo ai = null;
7306 ResolveInfo info = mContext.getPackageManager().resolveActivityAsUser(
7307 intent,
John Spurlockf56bef12013-07-09 09:51:46 -04007308 PackageManager.MATCH_DEFAULT_ONLY | PackageManager.GET_META_DATA,
Craig Mautnerd625ab22013-09-06 13:40:31 -07007309 mCurrentUserId);
Daniel Sandler6396c722013-04-16 20:19:09 -04007310 if (info != null) {
7311 ai = info.activityInfo;
7312 }
7313 if (ai != null
7314 && ai.metaData != null
7315 && ai.metaData.getBoolean(Intent.METADATA_DOCK_HOME)) {
7316 intent = new Intent(intent);
7317 intent.setClassName(ai.packageName, ai.name);
7318 return intent;
7319 }
7320
7321 return null;
7322 }
7323
Filip Gruszczynskia483a1d2015-03-17 19:06:58 +00007324 void startDockOrHome(boolean fromHomeKey, boolean awakenFromDreams) {
7325 if (awakenFromDreams) {
7326 awakenDreams();
7327 }
Daniel Sandler6396c722013-04-16 20:19:09 -04007328
7329 Intent dock = createHomeDockIntent();
7330 if (dock != null) {
7331 try {
Bryce Lee01b0c5f2015-02-05 18:24:04 -08007332 if (fromHomeKey) {
7333 dock.putExtra(WindowManagerPolicy.EXTRA_FROM_HOME_KEY, fromHomeKey);
7334 }
Bart Sears8b1c27c2015-03-18 23:51:02 +00007335 startActivityAsUser(dock, UserHandle.CURRENT);
Daniel Sandler6396c722013-04-16 20:19:09 -04007336 return;
7337 } catch (ActivityNotFoundException e) {
7338 }
7339 }
7340
Bryce Lee01b0c5f2015-02-05 18:24:04 -08007341 Intent intent;
7342
7343 if (fromHomeKey) {
7344 intent = new Intent(mHomeIntent);
7345 intent.putExtra(WindowManagerPolicy.EXTRA_FROM_HOME_KEY, fromHomeKey);
7346 } else {
7347 intent = mHomeIntent;
7348 }
7349
Bryce Lee9fc0b6f2015-03-19 21:37:45 +00007350 startActivityAsUser(intent, UserHandle.CURRENT);
Dianne Hackborn39c2d712009-09-22 11:41:31 -07007351 }
Craig Mautnereda67292013-04-28 13:50:14 -07007352
Dianne Hackborn39c2d712009-09-22 11:41:31 -07007353 /**
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08007354 * goes to the home screen
7355 * @return whether it did anything
7356 */
7357 boolean goHome() {
Bart Sears8b1c27c2015-03-18 23:51:02 +00007358 if (!isUserSetupComplete()) {
7359 Slog.i(TAG, "Not going home because user setup is in progress.");
7360 return false;
7361 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08007362 if (false) {
7363 // This code always brings home to the front.
Dianne Hackborn256dd3b2009-05-19 18:51:21 -07007364 try {
Sudheer Shankadc589ac2016-11-10 15:30:17 -08007365 ActivityManager.getService().stopAppSwitches();
Dianne Hackborn256dd3b2009-05-19 18:51:21 -07007366 } catch (RemoteException e) {
7367 }
Dianne Hackborn94a679d2009-07-28 17:51:07 -07007368 sendCloseSystemWindows();
Filip Gruszczynskia483a1d2015-03-17 19:06:58 +00007369 startDockOrHome(false /*fromHomeKey*/, true /* awakenFromDreams */);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08007370 } else {
7371 // This code brings home to the front or, if it is already
7372 // at the front, puts the device to sleep.
7373 try {
Wink Savilled2e6a332010-02-12 12:12:06 -08007374 if (SystemProperties.getInt("persist.sys.uts-test-mode", 0) == 1) {
7375 /// Roll back EndcallBehavior as the cupcake design to pass P1 lab entry.
7376 Log.d(TAG, "UTS-TEST-MODE");
7377 } else {
Sudheer Shankadc589ac2016-11-10 15:30:17 -08007378 ActivityManager.getService().stopAppSwitches();
Wink Savilled2e6a332010-02-12 12:12:06 -08007379 sendCloseSystemWindows();
Daniel Sandler6396c722013-04-16 20:19:09 -04007380 Intent dock = createHomeDockIntent();
7381 if (dock != null) {
Sudheer Shankadc589ac2016-11-10 15:30:17 -08007382 int result = ActivityManager.getService()
Daniel Sandler6396c722013-04-16 20:19:09 -04007383 .startActivityAsUser(null, null, dock,
7384 dock.resolveTypeIfNeeded(mContext.getContentResolver()),
7385 null, null, 0,
7386 ActivityManager.START_FLAG_ONLY_IF_NEEDED,
Jeff Hao1b012d32014-08-20 10:35:34 -07007387 null, null, UserHandle.USER_CURRENT);
Daniel Sandler6396c722013-04-16 20:19:09 -04007388 if (result == ActivityManager.START_RETURN_INTENT_TO_CALLER) {
7389 return false;
7390 }
7391 }
Dianne Hackborn39c2d712009-09-22 11:41:31 -07007392 }
Sudheer Shankadc589ac2016-11-10 15:30:17 -08007393 int result = ActivityManager.getService()
Dianne Hackbornf265ea92013-01-31 15:00:51 -08007394 .startActivityAsUser(null, null, mHomeIntent,
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08007395 mHomeIntent.resolveTypeIfNeeded(mContext.getContentResolver()),
Dianne Hackborna4972e92012-03-14 10:38:05 -07007396 null, null, 0,
7397 ActivityManager.START_FLAG_ONLY_IF_NEEDED,
Jeff Hao1b012d32014-08-20 10:35:34 -07007398 null, null, UserHandle.USER_CURRENT);
Dianne Hackborna4972e92012-03-14 10:38:05 -07007399 if (result == ActivityManager.START_RETURN_INTENT_TO_CALLER) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08007400 return false;
7401 }
7402 } catch (RemoteException ex) {
7403 // bummer, the activity manager, which is in this process, is dead
7404 }
7405 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08007406 return true;
7407 }
Craig Mautnereda67292013-04-28 13:50:14 -07007408
7409 @Override
The Android Open Source Project0727d222009-03-11 12:11:58 -07007410 public void setCurrentOrientationLw(int newOrientation) {
7411 synchronized (mLock) {
7412 if (newOrientation != mCurrentAppOrientation) {
7413 mCurrentAppOrientation = newOrientation;
7414 updateOrientationListenerLp();
7415 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08007416 }
7417 }
Amith Yamasanic33cb712010-02-10 15:21:49 -08007418
Svetoslav Ganov7befb7d2012-09-27 16:49:23 -07007419 private void performAuditoryFeedbackForAccessibilityIfNeed() {
7420 if (!isGlobalAccessibilityGestureEnabled()) {
7421 return;
7422 }
7423 AudioManager audioManager = (AudioManager) mContext.getSystemService(
7424 Context.AUDIO_SERVICE);
7425 if (audioManager.isSilentMode()) {
7426 return;
7427 }
7428 Ringtone ringTone = RingtoneManager.getRingtone(mContext,
7429 Settings.System.DEFAULT_NOTIFICATION_URI);
7430 ringTone.setStreamType(AudioManager.STREAM_MUSIC);
7431 ringTone.play();
7432 }
Craig Mautnereda67292013-04-28 13:50:14 -07007433
Bryce Lee584a4452014-10-21 15:55:55 -07007434 private boolean isTheaterModeEnabled() {
7435 return Settings.Global.getInt(mContext.getContentResolver(),
7436 Settings.Global.THEATER_MODE_ON, 0) == 1;
7437 }
7438
Svetoslav Ganov7befb7d2012-09-27 16:49:23 -07007439 private boolean isGlobalAccessibilityGestureEnabled() {
7440 return Settings.Global.getInt(mContext.getContentResolver(),
7441 Settings.Global.ENABLE_ACCESSIBILITY_GLOBAL_GESTURE_ENABLED, 0) == 1;
7442 }
7443
Doris Ling628cea42016-06-09 10:35:02 -07007444 private boolean areSystemNavigationKeysEnabled() {
Doris Ling34331b72016-08-09 12:02:28 -07007445 return Settings.Secure.getIntForUser(mContext.getContentResolver(),
7446 Settings.Secure.SYSTEM_NAVIGATION_KEYS_ENABLED, 0, UserHandle.USER_CURRENT) == 1;
Doris Ling628cea42016-06-09 10:35:02 -07007447 }
7448
Craig Mautnereda67292013-04-28 13:50:14 -07007449 @Override
The Android Open Source Project0727d222009-03-11 12:11:58 -07007450 public boolean performHapticFeedbackLw(WindowState win, int effectId, boolean always) {
Svetoslav Ganov96179212012-10-10 14:17:45 -07007451 if (!mVibrator.hasVibrator()) {
7452 return false;
7453 }
Christopher Tate5e08af02012-09-21 17:17:22 -07007454 final boolean hapticsDisabled = Settings.System.getIntForUser(mContext.getContentResolver(),
7455 Settings.System.HAPTIC_FEEDBACK_ENABLED, 0, UserHandle.USER_CURRENT) == 0;
Jeff Brown82379ba2014-07-25 19:03:28 -07007456 if (hapticsDisabled && !always) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08007457 return false;
7458 }
Amith Yamasanic33cb712010-02-10 15:21:49 -08007459 long[] pattern = null;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08007460 switch (effectId) {
7461 case HapticFeedbackConstants.LONG_PRESS:
Amith Yamasanic33cb712010-02-10 15:21:49 -08007462 pattern = mLongPressVibePattern;
7463 break;
Dianne Hackbornb1a79802009-09-29 15:18:31 -07007464 case HapticFeedbackConstants.VIRTUAL_KEY:
Amith Yamasanic33cb712010-02-10 15:21:49 -08007465 pattern = mVirtualKeyVibePattern;
7466 break;
7467 case HapticFeedbackConstants.KEYBOARD_TAP:
7468 pattern = mKeyboardTapVibePattern;
7469 break;
Fabrice Di Meglioeeff63a2013-08-05 12:07:24 -07007470 case HapticFeedbackConstants.CLOCK_TICK:
7471 pattern = mClockTickVibePattern;
7472 break;
Fabrice Di Megliobd9152f2013-10-01 11:21:31 -07007473 case HapticFeedbackConstants.CALENDAR_DATE:
7474 pattern = mCalendarDateVibePattern;
7475 break;
Dianne Hackbornb1a79802009-09-29 15:18:31 -07007476 case HapticFeedbackConstants.SAFE_MODE_DISABLED:
Amith Yamasanic33cb712010-02-10 15:21:49 -08007477 pattern = mSafeModeDisabledVibePattern;
7478 break;
Dianne Hackbornb1a79802009-09-29 15:18:31 -07007479 case HapticFeedbackConstants.SAFE_MODE_ENABLED:
Amith Yamasanic33cb712010-02-10 15:21:49 -08007480 pattern = mSafeModeEnabledVibePattern;
7481 break;
Mady Mellore8608912015-06-05 09:02:55 -07007482 case HapticFeedbackConstants.CONTEXT_CLICK:
7483 pattern = mContextClickVibePattern;
Mady Mellore82067b2015-04-30 09:58:35 -07007484 break;
Amith Yamasanic33cb712010-02-10 15:21:49 -08007485 default:
7486 return false;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08007487 }
Dianne Hackbornf265ea92013-01-31 15:00:51 -08007488 int owningUid;
7489 String owningPackage;
7490 if (win != null) {
7491 owningUid = win.getOwningUid();
7492 owningPackage = win.getOwningPackage();
7493 } else {
7494 owningUid = android.os.Process.myUid();
Dianne Hackborn95d78532013-09-11 09:51:14 -07007495 owningPackage = mContext.getOpPackageName();
Dianne Hackbornf265ea92013-01-31 15:00:51 -08007496 }
Amith Yamasanic33cb712010-02-10 15:21:49 -08007497 if (pattern.length == 1) {
7498 // One-shot vibration
John Spurlock7b414672014-07-18 13:02:39 -04007499 mVibrator.vibrate(owningUid, owningPackage, pattern[0], VIBRATION_ATTRIBUTES);
Amith Yamasanic33cb712010-02-10 15:21:49 -08007500 } else {
7501 // Pattern vibration
John Spurlock7b414672014-07-18 13:02:39 -04007502 mVibrator.vibrate(owningUid, owningPackage, pattern, -1, VIBRATION_ATTRIBUTES);
Amith Yamasanic33cb712010-02-10 15:21:49 -08007503 }
7504 return true;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08007505 }
Jeff Brownc38c9be2012-10-04 13:16:19 -07007506
7507 @Override
7508 public void keepScreenOnStartedLw() {
Daniel Sandler0601eb72011-04-13 01:01:32 -04007509 }
7510
Jeff Brownc38c9be2012-10-04 13:16:19 -07007511 @Override
7512 public void keepScreenOnStoppedLw() {
Jim Millerab954542014-10-10 18:21:49 -07007513 if (isKeyguardShowingAndNotOccluded()) {
Jim Miller25190572013-02-28 17:36:24 -08007514 mPowerManager.userActivity(SystemClock.uptimeMillis(), false);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08007515 }
7516 }
Mike Lockwoodfcb39242009-10-21 23:01:07 -04007517
Dianne Hackborndf89e652011-10-06 22:35:11 -07007518 private int updateSystemUiVisibilityLw() {
Joe Onorato664644d2011-01-23 17:53:23 -08007519 // If there is no window focused, there will be nobody to handle the events
7520 // anyway, so just hang on in whatever state we're in until things settle down.
Adrian Roosdab15162016-09-12 15:08:35 -07007521 WindowState winCandidate = mFocusedWindow != null ? mFocusedWindow
Adrian Roos53f28ec2014-10-29 17:26:12 +01007522 : mTopFullscreenOpaqueWindowState;
Adrian Roosdab15162016-09-12 15:08:35 -07007523 if (winCandidate == null) {
Dianne Hackborndf89e652011-10-06 22:35:11 -07007524 return 0;
7525 }
Adrian Roosdab15162016-09-12 15:08:35 -07007526 if (winCandidate.getAttrs().token == mImmersiveModeConfirmation.getWindowToken()) {
7527 // The immersive mode confirmation should never affect the system bar visibility,
7528 // otherwise it will unhide the navigation bar and hide itself.
7529 winCandidate = isStatusBarKeyguard() ? mStatusBar : mTopFullscreenOpaqueWindowState;
7530 if (winCandidate == null) {
7531 return 0;
7532 }
7533 }
7534 final WindowState win = winCandidate;
Jorim Jaggife762342016-10-13 14:33:27 +02007535 if ((win.getAttrs().privateFlags & PRIVATE_FLAG_KEYGUARD) != 0 && mKeyguardOccluded) {
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07007536 // We are updating at a point where the keyguard has gotten
7537 // focus, but we were last in a state where the top window is
7538 // hiding it. This is probably because the keyguard as been
7539 // shown while the top window was displayed, so we want to ignore
7540 // it here because this is just a very transient change and it
7541 // will quickly lose focus once it correctly gets hidden.
7542 return 0;
7543 }
John Spurlock32beb2c2013-03-11 10:16:47 -04007544
John Spurlock1db8b682014-02-18 11:18:59 -05007545 int tmpVisibility = PolicyControl.getSystemUiVisibility(win, null)
Dianne Hackborne26ab702011-10-16 13:21:33 -07007546 & ~mResettingSystemUiFlags
7547 & ~mForceClearedSystemUiFlags;
John Spurlock79da8332013-09-20 12:04:47 -04007548 if (mForcingShowNavBar && win.getSurfaceLayer() < mForcingShowNavBarLayer) {
John Spurlockc6d1c602014-01-17 15:22:06 -05007549 tmpVisibility &= ~PolicyControl.adjustClearableFlags(win, View.SYSTEM_UI_CLEARABLE_FLAGS);
Dianne Hackborn891d3fb2013-01-09 18:31:37 -08007550 }
Thanh Hai Mai6c009f52015-09-01 16:27:32 -07007551
Jorim Jaggi86905582016-02-09 21:36:09 -08007552 final int fullscreenVisibility = updateLightStatusBarLw(0 /* vis */,
7553 mTopFullscreenOpaqueWindowState, mTopFullscreenOpaqueOrDimmingWindowState);
7554 final int dockedVisibility = updateLightStatusBarLw(0 /* vis */,
7555 mTopDockedOpaqueWindowState, mTopDockedOpaqueOrDimmingWindowState);
7556 mWindowManagerFuncs.getStackBounds(HOME_STACK_ID, mNonDockedStackBounds);
7557 mWindowManagerFuncs.getStackBounds(DOCKED_STACK_ID, mDockedStackBounds);
John Spurlock79da8332013-09-20 12:04:47 -04007558 final int visibility = updateSystemBarsLw(win, mLastSystemUiFlags, tmpVisibility);
John Spurlockad3e6cb2013-04-30 08:47:43 -04007559 final int diff = visibility ^ mLastSystemUiFlags;
Jorim Jaggi86905582016-02-09 21:36:09 -08007560 final int fullscreenDiff = fullscreenVisibility ^ mLastFullscreenStackSysUiFlags;
7561 final int dockedDiff = dockedVisibility ^ mLastDockedStackSysUiFlags;
John Spurlock79da8332013-09-20 12:04:47 -04007562 final boolean needsMenu = win.getNeedsMenuLw(mTopFullscreenOpaqueWindowState);
Jorim Jaggi86905582016-02-09 21:36:09 -08007563 if (diff == 0 && fullscreenDiff == 0 && dockedDiff == 0 && mLastFocusNeedsMenu == needsMenu
7564 && mFocusedApp == win.getAppToken()
7565 && mLastNonDockedStackBounds.equals(mNonDockedStackBounds)
7566 && mLastDockedStackBounds.equals(mDockedStackBounds)) {
Dianne Hackborndf89e652011-10-06 22:35:11 -07007567 return 0;
7568 }
Dianne Hackborne26ab702011-10-16 13:21:33 -07007569 mLastSystemUiFlags = visibility;
Jorim Jaggi86905582016-02-09 21:36:09 -08007570 mLastFullscreenStackSysUiFlags = fullscreenVisibility;
7571 mLastDockedStackSysUiFlags = dockedVisibility;
Dianne Hackborn4eff8d32011-11-10 19:38:40 -08007572 mLastFocusNeedsMenu = needsMenu;
John Spurlock79da8332013-09-20 12:04:47 -04007573 mFocusedApp = win.getAppToken();
Jorim Jaggi86905582016-02-09 21:36:09 -08007574 final Rect fullscreenStackBounds = new Rect(mNonDockedStackBounds);
7575 final Rect dockedStackBounds = new Rect(mDockedStackBounds);
Dianne Hackborndf89e652011-10-06 22:35:11 -07007576 mHandler.post(new Runnable() {
Craig Mautnereda67292013-04-28 13:50:14 -07007577 @Override
Dianne Hackborndf89e652011-10-06 22:35:11 -07007578 public void run() {
Jorim Jaggi86905582016-02-09 21:36:09 -08007579 StatusBarManagerInternal statusbar = getStatusBarManagerInternal();
7580 if (statusbar != null) {
7581 statusbar.setSystemUiVisibility(visibility, fullscreenVisibility,
7582 dockedVisibility, 0xffffffff, fullscreenStackBounds,
7583 dockedStackBounds, win.toString());
7584 statusbar.topAppWindowChanged(needsMenu);
Joe Onorato664644d2011-01-23 17:53:23 -08007585 }
Dianne Hackborndf89e652011-10-06 22:35:11 -07007586 }
7587 });
7588 return diff;
Joe Onorato664644d2011-01-23 17:53:23 -08007589 }
7590
Jorim Jaggi86905582016-02-09 21:36:09 -08007591 private int updateLightStatusBarLw(int vis, WindowState opaque, WindowState opaqueOrDimming) {
Jorim Jaggife762342016-10-13 14:33:27 +02007592 WindowState statusColorWin = isStatusBarKeyguard() && !mKeyguardOccluded
Adrian Rooscd3884d2015-02-18 17:25:23 +01007593 ? mStatusBar
Jorim Jaggi86905582016-02-09 21:36:09 -08007594 : opaqueOrDimming;
Adrian Rooscd3884d2015-02-18 17:25:23 +01007595
7596 if (statusColorWin != null) {
Jorim Jaggi86905582016-02-09 21:36:09 -08007597 if (statusColorWin == opaque) {
Adrian Rooscd3884d2015-02-18 17:25:23 +01007598 // If the top fullscreen-or-dimming window is also the top fullscreen, respect
7599 // its light flag.
7600 vis &= ~View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR;
7601 vis |= PolicyControl.getSystemUiVisibility(statusColorWin, null)
7602 & View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR;
7603 } else if (statusColorWin != null && statusColorWin.isDimming()) {
7604 // Otherwise if it's dimming, clear the light flag.
7605 vis &= ~View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR;
7606 }
7607 }
7608 return vis;
7609 }
7610
Jorim Jaggi40db0292016-06-27 17:58:03 -07007611 private int updateLightNavigationBarLw(int vis, WindowState opaque,
7612 WindowState opaqueOrDimming) {
7613 final WindowState imeWin = mWindowManagerFuncs.getInputMethodWindowLw();
7614
7615 final WindowState navColorWin;
7616 if (imeWin != null && imeWin.isVisibleLw()) {
7617 navColorWin = imeWin;
7618 } else {
7619 navColorWin = opaqueOrDimming;
7620 }
7621
7622 if (navColorWin != null) {
7623 if (navColorWin == opaque) {
7624 // If the top fullscreen-or-dimming window is also the top fullscreen, respect
7625 // its light flag.
7626 vis &= ~View.SYSTEM_UI_FLAG_LIGHT_NAVIGATION_BAR;
7627 vis |= PolicyControl.getSystemUiVisibility(navColorWin, null)
7628 & View.SYSTEM_UI_FLAG_LIGHT_NAVIGATION_BAR;
7629 } else if (navColorWin.isDimming() || navColorWin == imeWin) {
7630 // Otherwise if it's dimming or it's the IME window, clear the light flag.
7631 vis &= ~View.SYSTEM_UI_FLAG_LIGHT_NAVIGATION_BAR;
7632 }
7633 }
7634 return vis;
7635 }
7636
Jorim Jaggi8f5701b2016-04-04 18:36:02 -07007637 private boolean drawsSystemBarBackground(WindowState win) {
7638 return win == null || (win.getAttrs().flags & FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS) != 0;
7639 }
7640
7641 private boolean forcesDrawStatusBarBackground(WindowState win) {
7642 return win == null || (win.getAttrs().privateFlags
7643 & PRIVATE_FLAG_FORCE_DRAW_STATUS_BAR_BACKGROUND) != 0;
7644 }
7645
John Spurlock79da8332013-09-20 12:04:47 -04007646 private int updateSystemBarsLw(WindowState win, int oldVis, int vis) {
Wale Ogunwale6e94a9e2015-10-07 15:35:49 -07007647 final boolean dockedStackVisible = mWindowManagerInternal.isStackVisible(DOCKED_STACK_ID);
7648 final boolean freeformStackVisible =
7649 mWindowManagerInternal.isStackVisible(FREEFORM_WORKSPACE_STACK_ID);
Jorim Jaggi9511b0f2016-01-29 19:12:44 -08007650 final boolean resizing = mWindowManagerInternal.isDockedDividerResizing();
7651
7652 // We need to force system bars when the docked stack is visible, when the freeform stack
7653 // is visible but also when we are resizing for the transitions when docked stack
7654 // visibility changes.
Jorim Jaggi0ffd49c2016-02-12 15:04:21 -08007655 mForceShowSystemBars = dockedStackVisible || freeformStackVisible || resizing;
Yorke Lee9b2ffb32016-03-07 20:42:01 -08007656 final boolean forceOpaqueStatusBar = mForceShowSystemBars && !mForceStatusBarFromKeyguard;
Wale Ogunwale6e94a9e2015-10-07 15:35:49 -07007657
John Spurlockbd957402013-10-03 11:38:39 -04007658 // apply translucent bar vis flags
Jorim Jaggife762342016-10-13 14:33:27 +02007659 WindowState fullscreenTransWin = isStatusBarKeyguard() && !mKeyguardOccluded
Jorim Jaggi380ecb82014-03-14 17:25:20 +01007660 ? mStatusBar
John Spurlockbd957402013-10-03 11:38:39 -04007661 : mTopFullscreenOpaqueWindowState;
Jorim Jaggi8f5701b2016-04-04 18:36:02 -07007662 vis = mStatusBarController.applyTranslucentFlagLw(fullscreenTransWin, vis, oldVis);
7663 vis = mNavigationBarController.applyTranslucentFlagLw(fullscreenTransWin, vis, oldVis);
7664 final int dockedVis = mStatusBarController.applyTranslucentFlagLw(
7665 mTopDockedOpaqueWindowState, 0, 0);
7666
7667 final boolean fullscreenDrawsStatusBarBackground =
7668 (drawsSystemBarBackground(mTopFullscreenOpaqueWindowState)
7669 && (vis & View.STATUS_BAR_TRANSLUCENT) == 0)
7670 || forcesDrawStatusBarBackground(mTopFullscreenOpaqueWindowState);
7671 final boolean dockedDrawsStatusBarBackground =
7672 (drawsSystemBarBackground(mTopDockedOpaqueWindowState)
7673 && (dockedVis & View.STATUS_BAR_TRANSLUCENT) == 0)
7674 || forcesDrawStatusBarBackground(mTopDockedOpaqueWindowState);
John Spurlockbd957402013-10-03 11:38:39 -04007675
John Spurlock27735a42013-08-14 17:57:38 -04007676 // prevent status bar interaction from clearing certain flags
Selim Cinekf83e8242015-05-19 18:08:14 -07007677 int type = win.getAttrs().type;
7678 boolean statusBarHasFocus = type == TYPE_STATUS_BAR;
John Spurlock08ffcf52014-07-11 10:13:46 -04007679 if (statusBarHasFocus && !isStatusBarKeyguard()) {
John Spurlockad3e6cb2013-04-30 08:47:43 -04007680 int flags = View.SYSTEM_UI_FLAG_FULLSCREEN
7681 | View.SYSTEM_UI_FLAG_HIDE_NAVIGATION
John Spurlockcfc359a2013-09-05 10:42:03 -04007682 | View.SYSTEM_UI_FLAG_IMMERSIVE
Jorim Jaggi73fef8d2015-02-16 17:32:28 +01007683 | View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY
7684 | View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR;
Jorim Jaggife762342016-10-13 14:33:27 +02007685 if (mKeyguardOccluded) {
Jorim Jaggi5cf17872014-03-26 18:31:48 +01007686 flags |= View.STATUS_BAR_TRANSLUCENT | View.NAVIGATION_BAR_TRANSLUCENT;
7687 }
John Spurlockbd957402013-10-03 11:38:39 -04007688 vis = (vis & ~flags) | (oldVis & flags);
John Spurlockad3e6cb2013-04-30 08:47:43 -04007689 }
John Spurlockad3e6cb2013-04-30 08:47:43 -04007690
Jorim Jaggi8f5701b2016-04-04 18:36:02 -07007691 if (fullscreenDrawsStatusBarBackground && dockedDrawsStatusBarBackground) {
7692 vis |= View.STATUS_BAR_TRANSPARENT;
7693 vis &= ~View.STATUS_BAR_TRANSLUCENT;
7694 } else if ((!areTranslucentBarsAllowed() && fullscreenTransWin != mStatusBar)
Yorke Lee9b2ffb32016-03-07 20:42:01 -08007695 || forceOpaqueStatusBar) {
7696 vis &= ~(View.STATUS_BAR_TRANSLUCENT | View.STATUS_BAR_TRANSPARENT);
Alan Viverette5a0f4ec2013-10-07 15:10:29 -07007697 }
7698
Yorke Lee9b2ffb32016-03-07 20:42:01 -08007699 vis = configureNavBarOpacity(vis, dockedStackVisible, freeformStackVisible, resizing);
Yorke Lee2e4b7322016-03-02 17:33:06 -08007700
John Spurlock27735a42013-08-14 17:57:38 -04007701 // update status bar
John Spurlockf1a36642013-10-12 17:50:42 -04007702 boolean immersiveSticky =
7703 (vis & View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY) != 0;
Wale Ogunwale6e94a9e2015-10-07 15:35:49 -07007704 final boolean hideStatusBarWM =
7705 mTopFullscreenOpaqueWindowState != null
7706 && (PolicyControl.getWindowFlags(mTopFullscreenOpaqueWindowState, null)
John Spurlock27735a42013-08-14 17:57:38 -04007707 & WindowManager.LayoutParams.FLAG_FULLSCREEN) != 0;
Wale Ogunwale6e94a9e2015-10-07 15:35:49 -07007708 final boolean hideStatusBarSysui =
John Spurlock27735a42013-08-14 17:57:38 -04007709 (vis & View.SYSTEM_UI_FLAG_FULLSCREEN) != 0;
Wale Ogunwale6e94a9e2015-10-07 15:35:49 -07007710 final boolean hideNavBarSysui =
John Spurlockf1a36642013-10-12 17:50:42 -04007711 (vis & View.SYSTEM_UI_FLAG_HIDE_NAVIGATION) != 0;
John Spurlockad3e6cb2013-04-30 08:47:43 -04007712
Wale Ogunwale6e94a9e2015-10-07 15:35:49 -07007713 final boolean transientStatusBarAllowed = mStatusBar != null
Jorim Jaggi0ffd49c2016-02-12 15:04:21 -08007714 && (statusBarHasFocus || (!mForceShowSystemBars
Wale Ogunwale6e94a9e2015-10-07 15:35:49 -07007715 && (hideStatusBarWM || (hideStatusBarSysui && immersiveSticky))));
John Spurlock27735a42013-08-14 17:57:38 -04007716
Wale Ogunwale6e94a9e2015-10-07 15:35:49 -07007717 final boolean transientNavBarAllowed = mNavigationBar != null
Jorim Jaggi0ffd49c2016-02-12 15:04:21 -08007718 && !mForceShowSystemBars && hideNavBarSysui && immersiveSticky;
John Spurlockf1a36642013-10-12 17:50:42 -04007719
Adrian Roosddc8b272015-05-21 16:28:27 -07007720 final long now = SystemClock.uptimeMillis();
7721 final boolean pendingPanic = mPendingPanicGestureUptime != 0
7722 && now - mPendingPanicGestureUptime <= PANIC_GESTURE_EXPIRATION;
7723 if (pendingPanic && hideNavBarSysui && !isStatusBarKeyguard() && mKeyguardDrawComplete) {
7724 // The user performed the panic gesture recently, we're about to hide the bars,
7725 // we're no longer on the Keyguard and the screen is ready. We can now request the bars.
7726 mPendingPanicGestureUptime = 0;
7727 mStatusBarController.showTransient();
Adrian Roos1f425902016-07-22 10:37:50 -07007728 if (!isNavBarEmpty(vis)) {
7729 mNavigationBarController.showTransient();
7730 }
Adrian Roosddc8b272015-05-21 16:28:27 -07007731 }
7732
Wale Ogunwale6e94a9e2015-10-07 15:35:49 -07007733 final boolean denyTransientStatus = mStatusBarController.isTransientShowRequested()
John Spurlockf1a36642013-10-12 17:50:42 -04007734 && !transientStatusBarAllowed && hideStatusBarSysui;
Wale Ogunwale6e94a9e2015-10-07 15:35:49 -07007735 final boolean denyTransientNav = mNavigationBarController.isTransientShowRequested()
John Spurlockf1a36642013-10-12 17:50:42 -04007736 && !transientNavBarAllowed;
Jorim Jaggi0ffd49c2016-02-12 15:04:21 -08007737 if (denyTransientStatus || denyTransientNav || mForceShowSystemBars) {
John Spurlock27735a42013-08-14 17:57:38 -04007738 // clear the clearable flags instead
John Spurlockf1a36642013-10-12 17:50:42 -04007739 clearClearableFlagsLw();
tiger_huangc58d7562014-10-23 20:24:19 +08007740 vis &= ~View.SYSTEM_UI_CLEARABLE_FLAGS;
John Spurlockad3e6cb2013-04-30 08:47:43 -04007741 }
John Spurlock27735a42013-08-14 17:57:38 -04007742
Selim Cinekf98702e2015-05-20 22:48:40 -07007743 final boolean immersive = (vis & View.SYSTEM_UI_FLAG_IMMERSIVE) != 0;
7744 immersiveSticky = (vis & View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY) != 0;
7745 final boolean navAllowedHidden = immersive || immersiveSticky;
7746
Selim Cinekd6623612015-05-22 18:56:22 -07007747 if (hideNavBarSysui && !navAllowedHidden && windowTypeToLayerLw(win.getBaseType())
7748 > windowTypeToLayerLw(TYPE_INPUT_CONSUMER)) {
Selim Cinekf98702e2015-05-20 22:48:40 -07007749 // We can't hide the navbar from this window otherwise the input consumer would not get
7750 // the input events.
7751 vis = (vis & ~View.SYSTEM_UI_FLAG_HIDE_NAVIGATION);
7752 }
7753
John Spurlock27735a42013-08-14 17:57:38 -04007754 vis = mStatusBarController.updateVisibilityLw(transientStatusBarAllowed, oldVis, vis);
7755
7756 // update navigation bar
John Spurlockf1a36642013-10-12 17:50:42 -04007757 boolean oldImmersiveMode = isImmersiveMode(oldVis);
7758 boolean newImmersiveMode = isImmersiveMode(vis);
7759 if (win != null && oldImmersiveMode != newImmersiveMode) {
John Spurlock79da8332013-09-20 12:04:47 -04007760 final String pkg = win.getOwningPackage();
Amith Yamasani02a03812016-04-22 17:32:00 -07007761 mImmersiveModeConfirmation.immersiveModeChangedLw(pkg, newImmersiveMode,
Adrian Roos7aaa5512016-07-12 15:27:24 -07007762 isUserSetupComplete(), isNavBarEmpty(win.getSystemUiVisibility()));
John Spurlock34e13d92013-08-10 06:52:28 -04007763 }
John Spurlock27735a42013-08-14 17:57:38 -04007764
John Spurlockf1a36642013-10-12 17:50:42 -04007765 vis = mNavigationBarController.updateVisibilityLw(transientNavBarAllowed, oldVis, vis);
7766
Jorim Jaggi40db0292016-06-27 17:58:03 -07007767 vis = updateLightNavigationBarLw(vis, mTopFullscreenOpaqueWindowState,
7768 mTopFullscreenOpaqueOrDimmingWindowState);
7769
John Spurlocke1f366f2013-08-05 12:22:40 -04007770 return vis;
John Spurlockad3e6cb2013-04-30 08:47:43 -04007771 }
7772
Yorke Lee9b2ffb32016-03-07 20:42:01 -08007773 /**
7774 * @return the current visibility flags with the nav-bar opacity related flags toggled based
7775 * on the nav bar opacity rules chosen by {@link #mNavBarOpacityMode}.
7776 */
7777 private int configureNavBarOpacity(int visibility, boolean dockedStackVisible,
7778 boolean freeformStackVisible, boolean isDockedDividerResizing) {
7779 if (mNavBarOpacityMode == NAV_BAR_OPAQUE_WHEN_FREEFORM_OR_DOCKED) {
7780 if (dockedStackVisible || freeformStackVisible || isDockedDividerResizing) {
7781 visibility = setNavBarOpaqueFlag(visibility);
7782 }
7783 } else if (mNavBarOpacityMode == NAV_BAR_TRANSLUCENT_WHEN_FREEFORM_OPAQUE_OTHERWISE) {
7784 if (isDockedDividerResizing) {
7785 visibility = setNavBarOpaqueFlag(visibility);
7786 } else if (freeformStackVisible) {
7787 visibility = setNavBarTranslucentFlag(visibility);
7788 } else {
7789 visibility = setNavBarOpaqueFlag(visibility);
7790 }
7791 }
7792
7793 if (!areTranslucentBarsAllowed()) {
7794 visibility &= ~View.NAVIGATION_BAR_TRANSLUCENT;
7795 }
7796 return visibility;
7797 }
7798
7799 private int setNavBarOpaqueFlag(int visibility) {
7800 return visibility &= ~(View.NAVIGATION_BAR_TRANSLUCENT | View.NAVIGATION_BAR_TRANSPARENT);
7801 }
7802
7803 private int setNavBarTranslucentFlag(int visibility) {
7804 visibility &= ~View.NAVIGATION_BAR_TRANSPARENT;
7805 return visibility |= View.NAVIGATION_BAR_TRANSLUCENT;
7806 }
7807
John Spurlockf1a36642013-10-12 17:50:42 -04007808 private void clearClearableFlagsLw() {
7809 int newVal = mResettingSystemUiFlags | View.SYSTEM_UI_CLEARABLE_FLAGS;
7810 if (newVal != mResettingSystemUiFlags) {
7811 mResettingSystemUiFlags = newVal;
7812 mWindowManagerFuncs.reevaluateStatusBarVisibility();
7813 }
7814 }
7815
7816 private boolean isImmersiveMode(int vis) {
7817 final int flags = View.SYSTEM_UI_FLAG_IMMERSIVE | View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY;
John Spurlock34e13d92013-08-10 06:52:28 -04007818 return mNavigationBar != null
7819 && (vis & View.SYSTEM_UI_FLAG_HIDE_NAVIGATION) != 0
Daniel Sandler900ece52013-10-18 15:53:27 -04007820 && (vis & flags) != 0
7821 && canHideNavigationBar();
John Spurlock34e13d92013-08-10 06:52:28 -04007822 }
7823
Adrian Roos7aaa5512016-07-12 15:27:24 -07007824 private static boolean isNavBarEmpty(int systemUiFlags) {
7825 final int disableNavigationBar = (View.STATUS_BAR_DISABLE_HOME
7826 | View.STATUS_BAR_DISABLE_BACK
7827 | View.STATUS_BAR_DISABLE_RECENT);
7828
7829 return (systemUiFlags & disableNavigationBar) == disableNavigationBar;
7830 }
7831
Alan Viverette5a0f4ec2013-10-07 15:10:29 -07007832 /**
Daniel Sandlerdd73ee42013-10-11 22:19:59 -04007833 * @return whether the navigation or status bar can be made translucent
7834 *
7835 * This should return true unless touch exploration is not enabled or
7836 * R.boolean.config_enableTranslucentDecor is false.
Alan Viverette5a0f4ec2013-10-07 15:10:29 -07007837 */
Daniel Sandlerdd73ee42013-10-11 22:19:59 -04007838 private boolean areTranslucentBarsAllowed() {
Alan Viverette817f3cd2015-08-13 11:40:14 -04007839 return mTranslucentDecorEnabled;
Alan Viverette5a0f4ec2013-10-07 15:10:29 -07007840 }
7841
Daniel Sandler0c4ccff2011-10-19 16:39:14 -04007842 // Use this instead of checking config_showNavigationBar so that it can be consistently
7843 // overridden by qemu.hw.mainkeys in the emulator.
Craig Mautnereda67292013-04-28 13:50:14 -07007844 @Override
Daniel Sandler0c4ccff2011-10-19 16:39:14 -04007845 public boolean hasNavigationBar() {
7846 return mHasNavigationBar;
7847 }
7848
satok1bc0a492012-04-25 22:47:12 +09007849 @Override
7850 public void setLastInputMethodWindowLw(WindowState ime, WindowState target) {
7851 mLastInputMethodWindow = ime;
7852 mLastInputMethodTargetWindow = target;
7853 }
7854
Craig Mautnerf1b67412012-09-19 13:18:29 -07007855 @Override
Satoshi Kataoka658c7b82013-10-10 17:03:51 +09007856 public int getInputMethodWindowVisibleHeightLw() {
7857 return mDockBottom - mCurBottom;
7858 }
7859
7860 @Override
Craig Mautnerf1b67412012-09-19 13:18:29 -07007861 public void setCurrentUserLw(int newUserId) {
Craig Mautnerd625ab22013-09-06 13:40:31 -07007862 mCurrentUserId = newUserId;
Jim Miller5ecd8112013-01-09 18:50:26 -08007863 if (mKeyguardDelegate != null) {
7864 mKeyguardDelegate.setCurrentUser(newUserId);
Craig Mautnerf1b67412012-09-19 13:18:29 -07007865 }
Adrian Roosf2efdd82016-04-15 17:43:18 -07007866 StatusBarManagerInternal statusBar = getStatusBarManagerInternal();
Adrian Roos2a629102016-04-15 16:28:03 -07007867 if (statusBar != null) {
Adrian Roosf2efdd82016-04-15 17:43:18 -07007868 statusBar.setCurrentUser(newUserId);
John Spurlock13451a22012-09-28 14:40:41 -04007869 }
Dianne Hackborn2ea9bae2012-11-02 18:43:48 -07007870 setLastInputMethodWindowLw(null, null);
Craig Mautnerf1b67412012-09-19 13:18:29 -07007871 }
7872
7873 @Override
Evan Rosky18396452016-07-27 15:19:37 -07007874 public void setSwitchingUser(boolean switching) {
7875 mKeyguardDelegate.setSwitchingUser(switching);
7876 }
7877
7878 @Override
Svetoslav Ganov545252f2012-12-10 18:29:24 -08007879 public boolean canMagnifyWindow(int windowType) {
7880 switch (windowType) {
7881 case WindowManager.LayoutParams.TYPE_INPUT_METHOD:
7882 case WindowManager.LayoutParams.TYPE_INPUT_METHOD_DIALOG:
7883 case WindowManager.LayoutParams.TYPE_NAVIGATION_BAR:
7884 case WindowManager.LayoutParams.TYPE_MAGNIFICATION_OVERLAY: {
7885 return false;
7886 }
7887 }
7888 return true;
7889 }
7890
7891 @Override
7892 public boolean isTopLevelWindow(int windowType) {
7893 if (windowType >= WindowManager.LayoutParams.FIRST_SUB_WINDOW
7894 && windowType <= WindowManager.LayoutParams.LAST_SUB_WINDOW) {
7895 return (windowType == WindowManager.LayoutParams.TYPE_APPLICATION_ATTACHED_DIALOG);
7896 }
7897 return true;
7898 }
7899
Jim Miller4eeb4f62012-11-08 00:04:29 -08007900 @Override
Robert Carr6da3cc02016-06-16 15:17:07 -07007901 public boolean shouldRotateSeamlessly(int oldRotation, int newRotation) {
7902 // For the upside down rotation we don't rotate seamlessly as the navigation
7903 // bar moves position.
7904 // Note most apps (using orientation:sensor or user as opposed to fullSensor)
7905 // will not enter the reverse portrait orientation, so actually the
7906 // orientation won't change at all.
7907 if (oldRotation == mUpsideDownRotation || newRotation == mUpsideDownRotation) {
7908 return false;
7909 }
Robert Carr0b9ac5a2016-10-26 14:12:14 -07007910 // If the navigation bar can't change sides, then it will
7911 // jump when we change orientations and we don't rotate
7912 // seamlessly.
7913 if (!mNavigationBarCanMove) {
7914 return false;
7915 }
Robert Carr6da3cc02016-06-16 15:17:07 -07007916 int delta = newRotation - oldRotation;
7917 if (delta < 0) delta += 4;
7918 // Likewise we don't rotate seamlessly for 180 degree rotations
Geoffrey Pitschb2d6ed32016-08-24 10:37:19 -04007919 // in this case the surfaces never resize, and our logic to
Robert Carr6da3cc02016-06-16 15:17:07 -07007920 // revert the transformations on size change will fail. We could
7921 // fix this in the future with the "tagged" frames idea.
7922 if (delta == Surface.ROTATION_180) {
7923 return false;
7924 }
7925
Robert Carr57d9fbd2016-08-15 12:00:35 -07007926 final WindowState w = mTopFullscreenOpaqueWindowState;
Robert Carr828ec3dc2016-08-22 13:32:34 -07007927 if (w != mFocusedWindow) {
7928 return false;
7929 }
Robert Carr57d9fbd2016-08-15 12:00:35 -07007930
Robert Carr606f4d52016-06-30 14:36:27 -07007931 // We only enable seamless rotation if the top window has requested
7932 // it and is in the fullscreen opaque state. Seamless rotation
7933 // requires freezing various Surface states and won't work well
7934 // with animations, so we disable it in the animation case for now.
Robert Carr1ccd4252016-08-15 12:05:21 -07007935 if (w != null && !w.isAnimatingLw() &&
Robert Carr57d9fbd2016-08-15 12:00:35 -07007936 ((w.getAttrs().rotationAnimation == ROTATION_ANIMATION_JUMPCUT) ||
7937 (w.getAttrs().rotationAnimation == ROTATION_ANIMATION_SEAMLESS))) {
Robert Carr6da3cc02016-06-16 15:17:07 -07007938 return true;
7939 }
7940 return false;
7941 }
7942
7943 @Override
Jeff Brownd7a04de2012-06-17 14:17:52 -07007944 public void dump(String prefix, PrintWriter pw, String[] args) {
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08007945 pw.print(prefix); pw.print("mSafeMode="); pw.print(mSafeMode);
Dianne Hackbornba24e4d2011-09-01 11:17:06 -07007946 pw.print(" mSystemReady="); pw.print(mSystemReady);
7947 pw.print(" mSystemBooted="); pw.println(mSystemBooted);
Jeff Brown2e7760e2012-04-11 15:14:55 -07007948 pw.print(prefix); pw.print("mLidState="); pw.print(mLidState);
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08007949 pw.print(" mLidOpenRotation="); pw.print(mLidOpenRotation);
Michael Wright3818c922014-09-02 13:59:07 -07007950 pw.print(" mCameraLensCoverState="); pw.print(mCameraLensCoverState);
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08007951 pw.print(" mHdmiPlugged="); pw.println(mHdmiPlugged);
Dianne Hackborne26ab702011-10-16 13:21:33 -07007952 if (mLastSystemUiFlags != 0 || mResettingSystemUiFlags != 0
7953 || mForceClearedSystemUiFlags != 0) {
7954 pw.print(prefix); pw.print("mLastSystemUiFlags=0x");
7955 pw.print(Integer.toHexString(mLastSystemUiFlags));
7956 pw.print(" mResettingSystemUiFlags=0x");
7957 pw.print(Integer.toHexString(mResettingSystemUiFlags));
7958 pw.print(" mForceClearedSystemUiFlags=0x");
7959 pw.println(Integer.toHexString(mForceClearedSystemUiFlags));
Dianne Hackborndf89e652011-10-06 22:35:11 -07007960 }
Dianne Hackborn4eff8d32011-11-10 19:38:40 -08007961 if (mLastFocusNeedsMenu) {
7962 pw.print(prefix); pw.print("mLastFocusNeedsMenu=");
7963 pw.println(mLastFocusNeedsMenu);
7964 }
Jeff Browna20dda42014-05-27 20:57:24 -07007965 pw.print(prefix); pw.print("mWakeGestureEnabledSetting=");
7966 pw.println(mWakeGestureEnabledSetting);
7967
Jeff Brownbcdfc622014-03-06 19:13:04 -08007968 pw.print(prefix); pw.print("mSupportAutoRotation="); pw.println(mSupportAutoRotation);
Daniel Sandler6396c722013-04-16 20:19:09 -04007969 pw.print(prefix); pw.print("mUiMode="); pw.print(mUiMode);
7970 pw.print(" mDockMode="); pw.print(mDockMode);
keunyounga7710492015-09-23 11:33:58 -07007971 pw.print(" mEnableCarDockHomeCapture="); pw.print(mEnableCarDockHomeCapture);
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08007972 pw.print(" mCarDockRotation="); pw.print(mCarDockRotation);
7973 pw.print(" mDeskDockRotation="); pw.println(mDeskDockRotation);
7974 pw.print(prefix); pw.print("mUserRotationMode="); pw.print(mUserRotationMode);
7975 pw.print(" mUserRotation="); pw.print(mUserRotation);
Daniel Sandler2ed6ad62011-02-22 14:54:17 -05007976 pw.print(" mAllowAllRotations="); pw.println(mAllowAllRotations);
Dianne Hackborn6e2281d2012-06-19 17:48:32 -07007977 pw.print(prefix); pw.print("mCurrentAppOrientation="); pw.println(mCurrentAppOrientation);
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08007978 pw.print(prefix); pw.print("mCarDockEnablesAccelerometer=");
7979 pw.print(mCarDockEnablesAccelerometer);
7980 pw.print(" mDeskDockEnablesAccelerometer=");
7981 pw.println(mDeskDockEnablesAccelerometer);
7982 pw.print(prefix); pw.print("mLidKeyboardAccessibility=");
7983 pw.print(mLidKeyboardAccessibility);
7984 pw.print(" mLidNavigationAccessibility="); pw.print(mLidNavigationAccessibility);
Edward Savage-Jones7def60d2015-11-13 13:27:03 +01007985 pw.print(" mLidControlsScreenLock="); pw.println(mLidControlsScreenLock);
Dianne Hackborn6e2281d2012-06-19 17:48:32 -07007986 pw.print(" mLidControlsSleep="); pw.println(mLidControlsSleep);
Jeff Brown6d8fd272014-05-20 21:24:38 -07007987 pw.print(prefix);
Anthony Hugh34f09ca2016-03-04 12:03:37 -08007988 pw.print(" mLongPressOnBackBehavior="); pw.println(mLongPressOnBackBehavior);
7989 pw.print(prefix);
Jeff Brown6d8fd272014-05-20 21:24:38 -07007990 pw.print("mShortPressOnPowerBehavior="); pw.print(mShortPressOnPowerBehavior);
7991 pw.print(" mLongPressOnPowerBehavior="); pw.println(mLongPressOnPowerBehavior);
Jeff Brown13f00f02014-10-31 14:45:50 -07007992 pw.print(prefix);
7993 pw.print("mDoublePressOnPowerBehavior="); pw.print(mDoublePressOnPowerBehavior);
7994 pw.print(" mTriplePressOnPowerBehavior="); pw.println(mTriplePressOnPowerBehavior);
Jeff Brown6d8fd272014-05-20 21:24:38 -07007995 pw.print(prefix); pw.print("mHasSoftInput="); pw.println(mHasSoftInput);
Jeff Brown3ee549c2014-09-22 20:14:39 -07007996 pw.print(prefix); pw.print("mAwake="); pw.println(mAwake);
7997 pw.print(prefix); pw.print("mScreenOnEarly="); pw.print(mScreenOnEarly);
7998 pw.print(" mScreenOnFully="); pw.println(mScreenOnFully);
7999 pw.print(prefix); pw.print("mKeyguardDrawComplete="); pw.print(mKeyguardDrawComplete);
8000 pw.print(" mWindowManagerDrawComplete="); pw.println(mWindowManagerDrawComplete);
8001 pw.print(prefix); pw.print("mOrientationSensorEnabled=");
8002 pw.println(mOrientationSensorEnabled);
Dianne Hackbornc652de82013-02-15 16:32:56 -08008003 pw.print(prefix); pw.print("mOverscanScreen=("); pw.print(mOverscanScreenLeft);
8004 pw.print(","); pw.print(mOverscanScreenTop);
8005 pw.print(") "); pw.print(mOverscanScreenWidth);
8006 pw.print("x"); pw.println(mOverscanScreenHeight);
8007 if (mOverscanLeft != 0 || mOverscanTop != 0
8008 || mOverscanRight != 0 || mOverscanBottom != 0) {
8009 pw.print(prefix); pw.print("mOverscan left="); pw.print(mOverscanLeft);
8010 pw.print(" top="); pw.print(mOverscanTop);
8011 pw.print(" right="); pw.print(mOverscanRight);
8012 pw.print(" bottom="); pw.println(mOverscanBottom);
8013 }
Dianne Hackborn313440842013-02-19 19:22:59 -08008014 pw.print(prefix); pw.print("mRestrictedOverscanScreen=(");
8015 pw.print(mRestrictedOverscanScreenLeft);
8016 pw.print(","); pw.print(mRestrictedOverscanScreenTop);
8017 pw.print(") "); pw.print(mRestrictedOverscanScreenWidth);
8018 pw.print("x"); pw.println(mRestrictedOverscanScreenHeight);
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08008019 pw.print(prefix); pw.print("mUnrestrictedScreen=("); pw.print(mUnrestrictedScreenLeft);
8020 pw.print(","); pw.print(mUnrestrictedScreenTop);
8021 pw.print(") "); pw.print(mUnrestrictedScreenWidth);
8022 pw.print("x"); pw.println(mUnrestrictedScreenHeight);
8023 pw.print(prefix); pw.print("mRestrictedScreen=("); pw.print(mRestrictedScreenLeft);
8024 pw.print(","); pw.print(mRestrictedScreenTop);
8025 pw.print(") "); pw.print(mRestrictedScreenWidth);
8026 pw.print("x"); pw.println(mRestrictedScreenHeight);
Dianne Hackborn5b5cc4d2012-05-16 13:15:00 -07008027 pw.print(prefix); pw.print("mStableFullscreen=("); pw.print(mStableFullscreenLeft);
8028 pw.print(","); pw.print(mStableFullscreenTop);
8029 pw.print(")-("); pw.print(mStableFullscreenRight);
8030 pw.print(","); pw.print(mStableFullscreenBottom); pw.println(")");
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07008031 pw.print(prefix); pw.print("mStable=("); pw.print(mStableLeft);
8032 pw.print(","); pw.print(mStableTop);
8033 pw.print(")-("); pw.print(mStableRight);
8034 pw.print(","); pw.print(mStableBottom); pw.println(")");
Dianne Hackborn5c58de32012-04-28 19:52:37 -07008035 pw.print(prefix); pw.print("mSystem=("); pw.print(mSystemLeft);
8036 pw.print(","); pw.print(mSystemTop);
8037 pw.print(")-("); pw.print(mSystemRight);
8038 pw.print(","); pw.print(mSystemBottom); pw.println(")");
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08008039 pw.print(prefix); pw.print("mCur=("); pw.print(mCurLeft);
8040 pw.print(","); pw.print(mCurTop);
8041 pw.print(")-("); pw.print(mCurRight);
8042 pw.print(","); pw.print(mCurBottom); pw.println(")");
8043 pw.print(prefix); pw.print("mContent=("); pw.print(mContentLeft);
8044 pw.print(","); pw.print(mContentTop);
8045 pw.print(")-("); pw.print(mContentRight);
8046 pw.print(","); pw.print(mContentBottom); pw.println(")");
Dianne Hackborne30e02f2014-05-27 18:24:45 -07008047 pw.print(prefix); pw.print("mVoiceContent=("); pw.print(mVoiceContentLeft);
8048 pw.print(","); pw.print(mVoiceContentTop);
8049 pw.print(")-("); pw.print(mVoiceContentRight);
8050 pw.print(","); pw.print(mVoiceContentBottom); pw.println(")");
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08008051 pw.print(prefix); pw.print("mDock=("); pw.print(mDockLeft);
8052 pw.print(","); pw.print(mDockTop);
8053 pw.print(")-("); pw.print(mDockRight);
8054 pw.print(","); pw.print(mDockBottom); pw.println(")");
Dianne Hackborn5c58de32012-04-28 19:52:37 -07008055 pw.print(prefix); pw.print("mDockLayer="); pw.print(mDockLayer);
8056 pw.print(" mStatusBarLayer="); pw.println(mStatusBarLayer);
Jorim Jaggi8d786932016-10-26 19:08:36 -07008057 pw.print(prefix); pw.print("mShowingDream="); pw.print(mShowingDream);
Jeff Brown061ea992015-04-17 19:55:47 -07008058 pw.print(" mDreamingLockscreen="); pw.print(mDreamingLockscreen);
8059 pw.print(" mDreamingSleepToken="); pw.println(mDreamingSleepToken);
Dianne Hackborn2ea9bae2012-11-02 18:43:48 -07008060 if (mLastInputMethodWindow != null) {
8061 pw.print(prefix); pw.print("mLastInputMethodWindow=");
8062 pw.println(mLastInputMethodWindow);
8063 }
8064 if (mLastInputMethodTargetWindow != null) {
8065 pw.print(prefix); pw.print("mLastInputMethodTargetWindow=");
8066 pw.println(mLastInputMethodTargetWindow);
8067 }
8068 if (mStatusBar != null) {
8069 pw.print(prefix); pw.print("mStatusBar=");
Dianne Hackbornae6688b2015-02-11 17:02:41 -08008070 pw.print(mStatusBar); pw.print(" isStatusBarKeyguard=");
8071 pw.println(isStatusBarKeyguard());
Dianne Hackborn2ea9bae2012-11-02 18:43:48 -07008072 }
8073 if (mNavigationBar != null) {
8074 pw.print(prefix); pw.print("mNavigationBar=");
8075 pw.println(mNavigationBar);
8076 }
Dianne Hackborn2ea9bae2012-11-02 18:43:48 -07008077 if (mFocusedWindow != null) {
8078 pw.print(prefix); pw.print("mFocusedWindow=");
8079 pw.println(mFocusedWindow);
8080 }
8081 if (mFocusedApp != null) {
8082 pw.print(prefix); pw.print("mFocusedApp=");
8083 pw.println(mFocusedApp);
8084 }
Dianne Hackborn2ea9bae2012-11-02 18:43:48 -07008085 if (mTopFullscreenOpaqueWindowState != null) {
8086 pw.print(prefix); pw.print("mTopFullscreenOpaqueWindowState=");
8087 pw.println(mTopFullscreenOpaqueWindowState);
8088 }
Adrian Rooscd3884d2015-02-18 17:25:23 +01008089 if (mTopFullscreenOpaqueOrDimmingWindowState != null) {
8090 pw.print(prefix); pw.print("mTopFullscreenOpaqueOrDimmingWindowState=");
8091 pw.println(mTopFullscreenOpaqueOrDimmingWindowState);
8092 }
Dianne Hackborn891d3fb2013-01-09 18:31:37 -08008093 if (mForcingShowNavBar) {
8094 pw.print(prefix); pw.print("mForcingShowNavBar=");
8095 pw.println(mForcingShowNavBar); pw.print( "mForcingShowNavBarLayer=");
8096 pw.println(mForcingShowNavBarLayer);
8097 }
Dianne Hackborn7ad44382012-10-18 17:46:00 -07008098 pw.print(prefix); pw.print("mTopIsFullscreen="); pw.print(mTopIsFullscreen);
Jorim Jaggife762342016-10-13 14:33:27 +02008099 pw.print(" mKeyguardOccluded="); pw.println(mKeyguardOccluded);
Jorim Jaggi8d786932016-10-26 19:08:36 -07008100 pw.print(" mKeyguardOccludedChanged="); pw.println(mKeyguardOccludedChanged);
8101 pw.print(" mPendingKeyguardOccluded="); pw.println(mPendingKeyguardOccluded);
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07008102 pw.print(prefix); pw.print("mForceStatusBar="); pw.print(mForceStatusBar);
8103 pw.print(" mForceStatusBarFromKeyguard=");
8104 pw.println(mForceStatusBarFromKeyguard);
Jorim Jaggife762342016-10-13 14:33:27 +02008105 pw.print(prefix); pw.print("mHomePressed="); pw.println(mHomePressed);
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08008106 pw.print(prefix); pw.print("mAllowLockscreenWhenOn="); pw.print(mAllowLockscreenWhenOn);
8107 pw.print(" mLockScreenTimeout="); pw.print(mLockScreenTimeout);
8108 pw.print(" mLockScreenTimerActive="); pw.println(mLockScreenTimerActive);
8109 pw.print(prefix); pw.print("mEndcallBehavior="); pw.print(mEndcallBehavior);
8110 pw.print(" mIncallPowerBehavior="); pw.print(mIncallPowerBehavior);
Bryce Leedb776ce2016-09-03 15:02:00 -07008111 pw.print(" mIncallBackBehavior="); pw.print(mIncallBackBehavior);
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08008112 pw.print(" mLongPressOnHomeBehavior="); pw.println(mLongPressOnHomeBehavior);
8113 pw.print(prefix); pw.print("mLandscapeRotation="); pw.print(mLandscapeRotation);
8114 pw.print(" mSeascapeRotation="); pw.println(mSeascapeRotation);
8115 pw.print(prefix); pw.print("mPortraitRotation="); pw.print(mPortraitRotation);
8116 pw.print(" mUpsideDownRotation="); pw.println(mUpsideDownRotation);
Jeff Brownc82c89ed2013-04-17 17:18:15 -07008117 pw.print(prefix); pw.print("mDemoHdmiRotation="); pw.print(mDemoHdmiRotation);
8118 pw.print(" mDemoHdmiRotationLock="); pw.println(mDemoHdmiRotationLock);
8119 pw.print(prefix); pw.print("mUndockedHdmiRotation="); pw.println(mUndockedHdmiRotation);
Jeff Brown600f0032014-05-22 17:06:00 -07008120
Tim Kilbournd7c0c2e2014-05-29 16:08:10 -07008121 mGlobalKeyManager.dump(prefix, pw);
John Spurlock27735a42013-08-14 17:57:38 -04008122 mStatusBarController.dump(pw, prefix);
8123 mNavigationBarController.dump(pw, prefix);
John Spurlockc6d1c602014-01-17 15:22:06 -05008124 PolicyControl.dump(prefix, pw);
Jeff Brown600f0032014-05-22 17:06:00 -07008125
Jeff Browna20dda42014-05-27 20:57:24 -07008126 if (mWakeGestureListener != null) {
8127 mWakeGestureListener.dump(pw, prefix);
8128 }
Jeff Brown600f0032014-05-22 17:06:00 -07008129 if (mOrientationListener != null) {
8130 mOrientationListener.dump(pw, prefix);
8131 }
Filip Gruszczynskicfb31852015-02-25 21:47:12 +00008132 if (mBurnInProtectionHelper != null) {
8133 mBurnInProtectionHelper.dump(prefix, pw);
8134 }
Jorim Jaggi84dc08a2015-09-11 17:45:22 -07008135 if (mKeyguardDelegate != null) {
8136 mKeyguardDelegate.dump(prefix, pw);
8137 }
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08008138 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08008139}