blob: 6afd69dcf137a2309d7c77c384dd36c0d53201f7 [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 Ogunwale5cd907d2017-01-26 14:14:08 -080019import static android.Manifest.permission.INTERNAL_SYSTEM_WINDOW;
20import static android.Manifest.permission.SYSTEM_ALERT_WINDOW;
Wale Ogunwale3797c222015-10-27 14:21:58 -070021import static android.app.ActivityManager.StackId.DOCKED_STACK_ID;
22import static android.app.ActivityManager.StackId.FREEFORM_WORKSPACE_STACK_ID;
Jorim Jaggi86905582016-02-09 21:36:09 -080023import static android.app.ActivityManager.StackId.HOME_STACK_ID;
Wale Ogunwale5cd907d2017-01-26 14:14:08 -080024import static android.app.AppOpsManager.OP_SYSTEM_ALERT_WINDOW;
25import static android.app.AppOpsManager.OP_TOAST_WINDOW;
Robert Carr7ad24ba2017-06-20 17:26:06 -070026import static android.content.Context.CONTEXT_RESTRICTED;
Andrii Kulianfb1bf692017-01-17 11:17:34 -080027import static android.content.Context.DISPLAY_SERVICE;
28import static android.content.Context.WINDOW_SERVICE;
Jaewan Kim49117872016-01-19 17:24:08 +090029import static android.content.pm.PackageManager.FEATURE_PICTURE_IN_PICTURE;
Dmitri Plotnikov82e6dfc2017-02-24 18:10:54 -080030import static android.content.pm.PackageManager.FEATURE_LEANBACK;
Jaewan Kim49117872016-01-19 17:24:08 +090031import static android.content.pm.PackageManager.FEATURE_WATCH;
Wale Ogunwale5cd907d2017-01-26 14:14:08 -080032import static android.content.pm.PackageManager.PERMISSION_GRANTED;
Wale Ogunwaledfc18622016-04-16 15:08:48 -070033import static android.content.res.Configuration.EMPTY;
Sriram Viswanathan9ebbe6a2015-11-16 17:59:22 -080034import static android.content.res.Configuration.UI_MODE_TYPE_CAR;
35import static android.content.res.Configuration.UI_MODE_TYPE_MASK;
Wale Ogunwale5cd907d2017-01-26 14:14:08 -080036import static android.os.Build.VERSION_CODES.M;
37import static android.os.Build.VERSION_CODES.O;
Jorim Jaggi5060bd82016-02-19 17:12:19 -080038import static android.view.WindowManager.DOCKED_LEFT;
39import static android.view.WindowManager.DOCKED_RIGHT;
Jorim Jaggi73294b62016-10-26 18:02:36 -070040import static android.view.WindowManager.DOCKED_TOP;
Winson41275482016-10-10 15:17:45 -070041import static android.view.WindowManager.INPUT_CONSUMER_NAVIGATION;
Jorim Jaggi73294b62016-10-26 18:02:36 -070042import static android.view.WindowManager.LayoutParams.FIRST_APPLICATION_WINDOW;
43import static android.view.WindowManager.LayoutParams.FIRST_SUB_WINDOW;
44import static android.view.WindowManager.LayoutParams.FIRST_SYSTEM_WINDOW;
45import static android.view.WindowManager.LayoutParams.FLAG_ALLOW_LOCK_WHILE_SCREEN_ON;
46import static android.view.WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS;
47import static android.view.WindowManager.LayoutParams.FLAG_FORCE_NOT_FULLSCREEN;
48import static android.view.WindowManager.LayoutParams.FLAG_FULLSCREEN;
49import static android.view.WindowManager.LayoutParams.FLAG_LAYOUT_ATTACHED_IN_DECOR;
50import static android.view.WindowManager.LayoutParams.FLAG_LAYOUT_INSET_DECOR;
51import static android.view.WindowManager.LayoutParams.FLAG_LAYOUT_IN_OVERSCAN;
52import static android.view.WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN;
53import static android.view.WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS;
54import static android.view.WindowManager.LayoutParams.FLAG_SHOW_WALLPAPER;
55import static android.view.WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED;
56import static android.view.WindowManager.LayoutParams.LAST_APPLICATION_WINDOW;
57import static android.view.WindowManager.LayoutParams.LAST_SUB_WINDOW;
58import static android.view.WindowManager.LayoutParams.LAST_SYSTEM_WINDOW;
59import static android.view.WindowManager.LayoutParams.MATCH_PARENT;
60import static android.view.WindowManager.LayoutParams.PRIVATE_FLAG_FORCE_DRAW_STATUS_BAR_BACKGROUND;
61import static android.view.WindowManager.LayoutParams.PRIVATE_FLAG_FORCE_STATUS_BAR_VISIBLE_TRANSPARENT;
62import static android.view.WindowManager.LayoutParams.PRIVATE_FLAG_KEYGUARD;
63import static android.view.WindowManager.LayoutParams.PRIVATE_FLAG_SHOW_FOR_ALL_USERS;
64import static android.view.WindowManager.LayoutParams.PRIVATE_FLAG_SYSTEM_ERROR;
65import static android.view.WindowManager.LayoutParams.ROTATION_ANIMATION_CROSSFADE;
66import static android.view.WindowManager.LayoutParams.ROTATION_ANIMATION_JUMPCUT;
67import static android.view.WindowManager.LayoutParams.ROTATION_ANIMATION_ROTATE;
68import static android.view.WindowManager.LayoutParams.ROTATION_ANIMATION_SEAMLESS;
69import static android.view.WindowManager.LayoutParams.SOFT_INPUT_ADJUST_NOTHING;
70import static android.view.WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE;
71import static android.view.WindowManager.LayoutParams.SOFT_INPUT_MASK_ADJUST;
72import static android.view.WindowManager.LayoutParams.TYPE_ACCESSIBILITY_OVERLAY;
Jorim Jaggi73294b62016-10-26 18:02:36 -070073import static android.view.WindowManager.LayoutParams.TYPE_APPLICATION_STARTING;
Wale Ogunwale5cd907d2017-01-26 14:14:08 -080074import static android.view.WindowManager.LayoutParams.TYPE_APPLICATION_OVERLAY;
Jorim Jaggi73294b62016-10-26 18:02:36 -070075import static android.view.WindowManager.LayoutParams.TYPE_BOOT_PROGRESS;
76import static android.view.WindowManager.LayoutParams.TYPE_DISPLAY_OVERLAY;
77import static android.view.WindowManager.LayoutParams.TYPE_DOCK_DIVIDER;
Jorim Jaggi73294b62016-10-26 18:02:36 -070078import static android.view.WindowManager.LayoutParams.TYPE_DREAM;
79import static android.view.WindowManager.LayoutParams.TYPE_INPUT_CONSUMER;
80import static android.view.WindowManager.LayoutParams.TYPE_INPUT_METHOD;
Jorim Jaggi73294b62016-10-26 18:02:36 -070081import static android.view.WindowManager.LayoutParams.TYPE_KEYGUARD_DIALOG;
82import static android.view.WindowManager.LayoutParams.TYPE_MAGNIFICATION_OVERLAY;
83import static android.view.WindowManager.LayoutParams.TYPE_NAVIGATION_BAR;
84import static android.view.WindowManager.LayoutParams.TYPE_NAVIGATION_BAR_PANEL;
85import static android.view.WindowManager.LayoutParams.TYPE_PHONE;
86import static android.view.WindowManager.LayoutParams.TYPE_POINTER;
Wale Ogunwale5b6714c2016-11-01 20:54:46 -070087import static android.view.WindowManager.LayoutParams.TYPE_PRESENTATION;
Jorim Jaggi73294b62016-10-26 18:02:36 -070088import static android.view.WindowManager.LayoutParams.TYPE_PRIORITY_PHONE;
89import static android.view.WindowManager.LayoutParams.TYPE_PRIVATE_PRESENTATION;
90import static android.view.WindowManager.LayoutParams.TYPE_QS_DIALOG;
91import static android.view.WindowManager.LayoutParams.TYPE_SCREENSHOT;
92import static android.view.WindowManager.LayoutParams.TYPE_SEARCH_BAR;
93import static android.view.WindowManager.LayoutParams.TYPE_SECURE_SYSTEM_OVERLAY;
94import static android.view.WindowManager.LayoutParams.TYPE_STATUS_BAR;
95import static android.view.WindowManager.LayoutParams.TYPE_STATUS_BAR_PANEL;
96import static android.view.WindowManager.LayoutParams.TYPE_STATUS_BAR_SUB_PANEL;
97import static android.view.WindowManager.LayoutParams.TYPE_SYSTEM_ALERT;
98import static android.view.WindowManager.LayoutParams.TYPE_SYSTEM_DIALOG;
99import static android.view.WindowManager.LayoutParams.TYPE_SYSTEM_ERROR;
100import static android.view.WindowManager.LayoutParams.TYPE_SYSTEM_OVERLAY;
101import static android.view.WindowManager.LayoutParams.TYPE_TOAST;
102import static android.view.WindowManager.LayoutParams.TYPE_VOICE_INTERACTION;
103import static android.view.WindowManager.LayoutParams.TYPE_VOICE_INTERACTION_STARTING;
104import static android.view.WindowManager.LayoutParams.TYPE_VOLUME_OVERLAY;
105import static android.view.WindowManager.LayoutParams.TYPE_WALLPAPER;
Wale Ogunwale5cd907d2017-01-26 14:14:08 -0800106import static android.view.WindowManager.LayoutParams.isSystemAlertWindowType;
Muyuan Li6ca619f2016-03-08 13:30:42 -0800107import static android.view.WindowManager.TAKE_SCREENSHOT_FULLSCREEN;
108import static android.view.WindowManager.TAKE_SCREENSHOT_SELECTED_REGION;
Wale Ogunwale5cd907d2017-01-26 14:14:08 -0800109import static android.view.WindowManagerGlobal.ADD_OKAY;
110import static android.view.WindowManagerGlobal.ADD_PERMISSION_DENIED;
Jaewan Kim49117872016-01-19 17:24:08 +0900111import static android.view.WindowManagerPolicy.WindowManagerFuncs.CAMERA_LENS_COVERED;
Wale Ogunwale6e94a9e2015-10-07 15:35:49 -0700112import static android.view.WindowManagerPolicy.WindowManagerFuncs.CAMERA_LENS_COVER_ABSENT;
113import static android.view.WindowManagerPolicy.WindowManagerFuncs.CAMERA_LENS_UNCOVERED;
Jaewan Kim49117872016-01-19 17:24:08 +0900114import static android.view.WindowManagerPolicy.WindowManagerFuncs.LID_ABSENT;
115import static android.view.WindowManagerPolicy.WindowManagerFuncs.LID_CLOSED;
116import static android.view.WindowManagerPolicy.WindowManagerFuncs.LID_OPEN;
Wale Ogunwale6e94a9e2015-10-07 15:35:49 -0700117
Jorim Jaggife762342016-10-13 14:33:27 +0200118import android.annotation.Nullable;
Dianne Hackborna4972e92012-03-14 10:38:05 -0700119import android.app.ActivityManager;
Jorim Jaggi86905582016-02-09 21:36:09 -0800120import android.app.ActivityManager.StackId;
Jeff Brown061ea992015-04-17 19:55:47 -0700121import android.app.ActivityManagerInternal;
122import android.app.ActivityManagerInternal.SleepToken;
Dianne Hackbornc2293022013-02-06 23:14:49 -0800123import android.app.AppOpsManager;
Daniel Sandler6396c722013-04-16 20:19:09 -0400124import android.app.IUiModeManager;
Dianne Hackborn661cd522011-08-22 00:26:20 -0700125import android.app.ProgressDialog;
Jeff Brownde7a8ea2012-06-13 18:28:57 -0700126import android.app.SearchManager;
John Spurlock97642182013-07-29 17:58:39 -0400127import android.app.StatusBarManager;
Dianne Hackborn78968392010-03-04 20:47:56 -0800128import android.app.UiModeManager;
Dianne Hackborn39c2d712009-09-22 11:41:31 -0700129import android.content.ActivityNotFoundException;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800130import android.content.BroadcastReceiver;
Daniel Sandler0601eb72011-04-13 01:01:32 -0400131import android.content.ComponentName;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800132import android.content.ContentResolver;
133import android.content.Context;
134import android.content.Intent;
Mike Lockwood1753f7f2009-08-24 14:49:07 -0700135import android.content.IntentFilter;
Winson Chung9112ec32011-06-27 13:15:32 -0700136import android.content.ServiceConnection;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800137import android.content.pm.ActivityInfo;
Svet Ganov03f2afc2016-03-04 16:13:03 -0800138import android.content.pm.ApplicationInfo;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800139import android.content.pm.PackageManager;
Daniel Sandler6396c722013-04-16 20:19:09 -0400140import android.content.pm.ResolveInfo;
Dianne Hackborn2f0b1752011-05-31 17:59:49 -0700141import android.content.res.CompatibilityInfo;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800142import android.content.res.Configuration;
143import android.content.res.Resources;
Wale Ogunwaledfc18622016-04-16 15:08:48 -0700144import android.content.res.TypedArray;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800145import android.database.ContentObserver;
Dianne Hackbornc777e072010-02-12 13:07:59 -0800146import android.graphics.PixelFormat;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800147import android.graphics.Rect;
Jorim Jaggi7d0d1022017-02-23 15:35:51 +0100148import android.graphics.drawable.Drawable;
Andrii Kulianfb1bf692017-01-17 11:17:34 -0800149import android.hardware.display.DisplayManager;
Jinsuk Kime601b712015-07-07 08:01:02 +0900150import android.hardware.hdmi.HdmiControlManager;
151import android.hardware.hdmi.HdmiPlaybackClient;
152import android.hardware.hdmi.HdmiPlaybackClient.OneTouchPlayCallback;
Vladislav Kaznacheev19dab2d2017-02-07 10:12:51 -0800153import android.hardware.input.InputManager;
Andrii Kulian112d0562016-03-08 10:44:22 -0800154import android.hardware.input.InputManagerInternal;
Ruchi Kandoi0d434042016-10-03 09:12:02 -0700155import android.hardware.power.V1_0.PowerHint;
John Spurlock7b414672014-07-18 13:02:39 -0400156import android.media.AudioAttributes;
Michael Jurka7a348952012-02-27 13:07:58 -0800157import android.media.AudioManager;
John Spurlock61560172015-02-06 19:46:04 -0500158import android.media.AudioSystem;
Michael Jurka7a348952012-02-27 13:07:58 -0800159import android.media.IAudioService;
RoboErik8a2cfc32014-05-16 11:19:38 -0700160import android.media.session.MediaSessionLegacyHelper;
Billy Laucbe540f2015-06-25 01:51:44 +0100161import android.os.Binder;
Svet Ganov03f2afc2016-03-04 16:13:03 -0800162import android.os.Build;
Dianne Hackborn38e29a62011-09-18 14:43:08 -0700163import android.os.Bundle;
Jeff Brown9a538ee2012-08-20 14:56:57 -0700164import android.os.FactoryTest;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800165import android.os.Handler;
166import android.os.IBinder;
Dianne Hackbornb6683c42015-06-18 17:40:33 -0700167import android.os.IDeviceIdleController;
Jeff Brown32cbc38552011-12-01 14:01:49 -0800168import android.os.Looper;
Dianne Hackbornfc8fa632011-08-17 16:20:47 -0700169import android.os.Message;
170import android.os.Messenger;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800171import android.os.PowerManager;
Nick Armstrong-Crews56ecfcc2015-09-07 21:46:50 -0700172import android.os.PowerManagerInternal;
Billy Laucbe540f2015-06-25 01:51:44 +0100173import android.os.Process;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800174import android.os.RemoteException;
175import android.os.ServiceManager;
176import android.os.SystemClock;
177import android.os.SystemProperties;
Dianne Hackbornad7fa7f2011-01-07 14:06:50 -0800178import android.os.UEventObserver;
Dianne Hackbornf02b60a2012-08-16 10:48:27 -0700179import android.os.UserHandle;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800180import android.os.Vibrator;
Michael Wright71216972017-01-31 18:33:54 +0000181import android.os.VibrationEffect;
Michael Wright3818c922014-09-02 13:59:07 -0700182import android.provider.MediaStore;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800183import android.provider.Settings;
Jose Lima9546b202014-07-02 17:21:51 -0700184import android.service.dreams.DreamManagerInternal;
John Spurlockc8b46ca2013-04-08 12:59:26 -0400185import android.service.dreams.DreamService;
186import android.service.dreams.IDreamManager;
Santos Cordonc09d89c2017-04-13 16:12:02 -0700187import android.service.vr.IPersistentVrStateCallbacks;
Michael Wrightdc63f7b2014-08-21 19:05:21 -0700188import android.speech.RecognizerIntent;
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700189import android.telecom.TelecomManager;
Dianne Hackborn81e56d52011-05-26 00:55:58 -0700190import android.util.DisplayMetrics;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800191import android.util.EventLog;
192import android.util.Log;
Jorim Jaggi73294b62016-10-26 18:02:36 -0700193import android.util.LongSparseArray;
Jorim Jaggif1cdf952016-04-05 21:41:06 -0700194import android.util.MutableBoolean;
Jeff Browna41ca772010-08-11 14:46:32 -0700195import android.util.Slog;
Jeff Brown6651a632011-11-28 12:59:11 -0800196import android.util.SparseArray;
Dianne Hackbornf87d1962012-04-04 12:48:24 -0700197import android.view.Display;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800198import android.view.Gravity;
199import android.view.HapticFeedbackConstants;
Dianne Hackborne0f085d2011-11-30 18:41:15 -0800200import android.view.IApplicationToken;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800201import android.view.IWindowManager;
Jeff Browna41ca772010-08-11 14:46:32 -0700202import android.view.InputChannel;
Jeff Brown4d396052010-10-29 21:50:21 -0700203import android.view.InputDevice;
Jeff Brown4952dfd2011-11-30 19:23:22 -0800204import android.view.InputEvent;
Jeff Brown32cbc38552011-12-01 14:01:49 -0800205import android.view.InputEventReceiver;
Jeff Brown6b53e8d2010-11-10 16:03:06 -0800206import android.view.KeyCharacterMap;
Craig Mautnerae446592012-12-06 19:05:05 -0800207import android.view.KeyCharacterMap.FallbackAction;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800208import android.view.KeyEvent;
209import android.view.MotionEvent;
Vladislav Kaznacheev19dab2d2017-02-07 10:12:51 -0800210import android.view.PointerIcon;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800211import android.view.Surface;
212import android.view.View;
213import android.view.ViewConfiguration;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800214import android.view.WindowManager;
Jorim Jaggife762342016-10-13 14:33:27 +0200215import android.view.WindowManager.LayoutParams;
Craig Mautnerae446592012-12-06 19:05:05 -0800216import android.view.WindowManagerGlobal;
Craig Mautner8a0da012014-05-31 15:13:37 -0700217import android.view.WindowManagerInternal;
Jorim Jaggife762342016-10-13 14:33:27 +0200218import android.view.WindowManagerInternal.AppTransitionListener;
Craig Mautnerae446592012-12-06 19:05:05 -0800219import android.view.WindowManagerPolicy;
Craig Mautnerae446592012-12-06 19:05:05 -0800220import android.view.accessibility.AccessibilityEvent;
Svetoslav8e3feb12014-02-24 13:46:47 -0800221import android.view.accessibility.AccessibilityManager;
Craig Mautnerae446592012-12-06 19:05:05 -0800222import android.view.animation.Animation;
Jorim Jaggi76a16232014-08-08 17:00:47 +0200223import android.view.animation.AnimationSet;
Craig Mautnerae446592012-12-06 19:05:05 -0800224import android.view.animation.AnimationUtils;
Felipe Leme5f978802017-06-08 13:01:13 -0700225import android.view.autofill.AutofillManagerInternal;
Yohei Yukawad6475a62017-04-17 10:35:27 -0700226import android.view.inputmethod.InputMethodManagerInternal;
Yohei Yukawaabbe1ac2017-04-18 09:43:05 -0700227
Craig Mautnerae446592012-12-06 19:05:05 -0800228import com.android.internal.R;
Jason Monk8f7f3182015-11-18 16:35:14 -0500229import com.android.internal.logging.MetricsLogger;
Jorim Jaggi241ae102016-11-02 21:57:33 -0700230import com.android.internal.policy.IKeyguardDismissCallback;
Muyuan Li94ce94e2016-02-24 16:20:54 -0800231import com.android.internal.policy.IShortcutService;
Jorim Jaggi73294b62016-10-26 18:02:36 -0700232import com.android.internal.policy.PhoneWindow;
Craig Mautnerae446592012-12-06 19:05:05 -0800233import com.android.internal.statusbar.IStatusBarService;
Filip Gruszczynski2217f612015-05-26 11:32:08 -0700234import com.android.internal.util.ScreenShapeHelper;
Craig Mautnerae446592012-12-06 19:05:05 -0800235import com.android.internal.widget.PointerLocationView;
Adrian Roos5941c982015-09-03 15:59:49 -0700236import com.android.server.GestureLauncherService;
Craig Mautner8a0da012014-05-31 15:13:37 -0700237import com.android.server.LocalServices;
Keun-young Park4136d2d2017-05-08 14:51:59 -0700238import com.android.server.SystemServiceManager;
Jorim Jaggib10e33f2015-02-04 21:57:40 +0100239import com.android.server.policy.keyguard.KeyguardServiceDelegate;
Jorim Jaggi4cfdcf52015-07-09 12:13:59 -0700240import com.android.server.policy.keyguard.KeyguardServiceDelegate.DrawnListener;
Jorim Jaggie69c9312016-10-31 18:24:38 -0700241import com.android.server.policy.keyguard.KeyguardStateMonitor.StateCallback;
Jorim Jaggi86905582016-02-09 21:36:09 -0800242import com.android.server.statusbar.StatusBarManagerInternal;
Jorim Jaggife762342016-10-13 14:33:27 +0200243import com.android.server.wm.AppTransition;
Ruben Brunkfecb6152016-10-28 20:18:57 -0700244import com.android.server.vr.VrManagerInternal;
Craig Mautnerae446592012-12-06 19:05:05 -0800245
246import java.io.File;
247import java.io.FileReader;
248import java.io.IOException;
249import java.io.PrintWriter;
Craig Mautner276a6eb2014-11-04 15:32:57 -0800250import java.util.List;
Craig Mautnerae446592012-12-06 19:05:05 -0800251
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800252/**
The Android Open Source Project0727d222009-03-11 12:11:58 -0700253 * WindowManagerPolicy implementation for the Android phone UI. This
254 * introduces a new method suffix, Lp, for an internal lock of the
255 * PhoneWindowManager. This is used to protect some internal state, and
John Spurlock04db1762013-05-13 12:46:41 -0400256 * 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 -0700257 * of both of those when held.
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800258 */
259public class PhoneWindowManager implements WindowManagerPolicy {
260 static final String TAG = "WindowManager";
261 static final boolean DEBUG = false;
Joe Onorato43a17652011-04-06 19:22:23 -0700262 static final boolean localLOGV = false;
Jeff Brown40013652012-05-16 21:22:36 -0700263 static final boolean DEBUG_INPUT = false;
Craig Mautnerc0d2d0a2014-10-31 16:25:15 -0700264 static final boolean DEBUG_KEYGUARD = false;
265 static final boolean DEBUG_LAYOUT = false;
Jorim Jaggiba41f4b2016-12-14 17:43:07 -0800266 static final boolean DEBUG_SPLASH_SCREEN = false;
Craig Mautner8a0da012014-05-31 15:13:37 -0700267 static final boolean DEBUG_WAKEUP = false;
Jorim Jaggiba41f4b2016-12-14 17:43:07 -0800268 static final boolean SHOW_SPLASH_SCREENS = true;
Joe Onoratod208e702010-10-08 16:22:43 -0400269
Daniel Sandler6396c722013-04-16 20:19:09 -0400270 // Whether to allow dock apps with METADATA_DOCK_HOME to temporarily take over the Home key.
keunyounga7710492015-09-23 11:33:58 -0700271 // No longer recommended for desk docks;
Daniel Sandler6396c722013-04-16 20:19:09 -0400272 static final boolean ENABLE_DESK_DOCK_HOME_CAPTURE = false;
273
Zak Cohendb6ca492017-01-26 14:09:00 -0800274 // Whether to allow devices placed in vr headset viewers to have an alternative Home intent.
275 static final boolean ENABLE_VR_HEADSET_HOME_CAPTURE = true;
276
Justin Paupore01915a12016-09-28 17:41:26 -0700277 static final boolean ALTERNATE_CAR_MODE_NAV_SIZE = false;
278
Jeff Brown6d8fd272014-05-20 21:24:38 -0700279 static final int SHORT_PRESS_POWER_NOTHING = 0;
280 static final int SHORT_PRESS_POWER_GO_TO_SLEEP = 1;
281 static final int SHORT_PRESS_POWER_REALLY_GO_TO_SLEEP = 2;
282 static final int SHORT_PRESS_POWER_REALLY_GO_TO_SLEEP_AND_GO_HOME = 3;
Bryce Lee01b0c5f2015-02-05 18:24:04 -0800283 static final int SHORT_PRESS_POWER_GO_HOME = 4;
Yohei Yukawad6475a62017-04-17 10:35:27 -0700284 static final int SHORT_PRESS_POWER_CLOSE_IME_OR_GO_HOME = 5;
Jeff Brown6d8fd272014-05-20 21:24:38 -0700285
Joe Onoratod208e702010-10-08 16:22:43 -0400286 static final int LONG_PRESS_POWER_NOTHING = 0;
287 static final int LONG_PRESS_POWER_GLOBAL_ACTIONS = 1;
288 static final int LONG_PRESS_POWER_SHUT_OFF = 2;
Jeff Brown9a538ee2012-08-20 14:56:57 -0700289 static final int LONG_PRESS_POWER_SHUT_OFF_NO_CONFIRM = 3;
Michael Jurka3b1fc472011-06-13 10:54:40 -0700290
Anthony Hugh34f09ca2016-03-04 12:03:37 -0800291 static final int LONG_PRESS_BACK_NOTHING = 0;
292 static final int LONG_PRESS_BACK_GO_TO_VOICE_ASSIST = 1;
293
Jeff Brown13f00f02014-10-31 14:45:50 -0700294 static final int MULTI_PRESS_POWER_NOTHING = 0;
295 static final int MULTI_PRESS_POWER_THEATER_MODE = 1;
296 static final int MULTI_PRESS_POWER_BRIGHTNESS_BOOST = 2;
297
Anthony Hugh96e9cc52016-07-12 15:17:24 -0700298 // Number of presses needed before we induce panic press behavior on the back button
299 static final int PANIC_PRESS_BACK_COUNT = 4;
300 static final int PANIC_PRESS_BACK_NOTHING = 0;
301 static final int PANIC_PRESS_BACK_HOME = 1;
302
Michael Jurka3b1fc472011-06-13 10:54:40 -0700303 // These need to match the documentation/constant in
304 // core/res/res/values/config.xml
Joe Onorato46b0d682010-11-22 17:37:27 -0800305 static final int LONG_PRESS_HOME_NOTHING = 0;
Sid Soundararajanff662fa2017-03-15 16:24:24 -0700306 static final int LONG_PRESS_HOME_ALL_APPS = 1;
Jeff Browncaca8812013-05-09 13:34:33 -0700307 static final int LONG_PRESS_HOME_ASSIST = 2;
Jaewan Kim76b7d0d2016-02-12 19:01:02 +0900308 static final int LAST_LONG_PRESS_HOME_BEHAVIOR = LONG_PRESS_HOME_ASSIST;
Jeff Browncaca8812013-05-09 13:34:33 -0700309
310 static final int DOUBLE_TAP_HOME_NOTHING = 0;
311 static final int DOUBLE_TAP_HOME_RECENT_SYSTEM_UI = 1;
Joe Onorato46b0d682010-11-22 17:37:27 -0800312
Jaewan Kim49117872016-01-19 17:24:08 +0900313 static final int SHORT_PRESS_WINDOW_NOTHING = 0;
314 static final int SHORT_PRESS_WINDOW_PICTURE_IN_PICTURE = 1;
315
Filip Gruszczynskia483a1d2015-03-17 19:06:58 +0000316 static final int SHORT_PRESS_SLEEP_GO_TO_SLEEP = 0;
317 static final int SHORT_PRESS_SLEEP_GO_TO_SLEEP_AND_GO_HOME = 1;
318
Anthony Hugh4b13ab82016-05-17 13:03:00 -0700319 static final int PENDING_KEY_NULL = -1;
320
Yorke Lee9b2ffb32016-03-07 20:42:01 -0800321 // Controls navigation bar opacity depending on which workspace stacks are currently
322 // visible.
323 // Nav bar is always opaque when either the freeform stack or docked stack is visible.
324 static final int NAV_BAR_OPAQUE_WHEN_FREEFORM_OR_DOCKED = 0;
325 // Nav bar is always translucent when the freeform stack is visible, otherwise always opaque.
326 static final int NAV_BAR_TRANSLUCENT_WHEN_FREEFORM_OPAQUE_OTHERWISE = 1;
327
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800328 static public final String SYSTEM_DIALOG_REASON_KEY = "reason";
329 static public final String SYSTEM_DIALOG_REASON_GLOBAL_ACTIONS = "globalactions";
330 static public final String SYSTEM_DIALOG_REASON_RECENT_APPS = "recentapps";
Joe Onoratof275f0c2009-11-24 16:11:13 -0500331 static public final String SYSTEM_DIALOG_REASON_HOME_KEY = "homekey";
Jeff Brownde7a8ea2012-06-13 18:28:57 -0700332 static public final String SYSTEM_DIALOG_REASON_ASSIST = "assist";
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800333
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -0700334 /**
335 * These are the system UI flags that, when changing, can cause the layout
336 * of the screen to change.
337 */
338 static final int SYSTEM_UI_CHANGING_LAYOUT =
John Spurlocke1f366f2013-08-05 12:22:40 -0400339 View.SYSTEM_UI_FLAG_HIDE_NAVIGATION
John Spurlock7f4820a2013-10-08 12:54:35 -0400340 | View.SYSTEM_UI_FLAG_FULLSCREEN
341 | View.STATUS_BAR_TRANSLUCENT
Adrian Roosea562512014-05-05 13:33:03 +0200342 | View.NAVIGATION_BAR_TRANSLUCENT
Jorim Jaggi4fa78922015-11-30 17:13:56 -0800343 | View.STATUS_BAR_TRANSPARENT
344 | View.NAVIGATION_BAR_TRANSPARENT;
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -0700345
John Spurlock7b414672014-07-18 13:02:39 -0400346 private static final AudioAttributes VIBRATION_ATTRIBUTES = new AudioAttributes.Builder()
347 .setContentType(AudioAttributes.CONTENT_TYPE_SONIFICATION)
348 .setUsage(AudioAttributes.USAGE_ASSISTANCE_SONIFICATION)
349 .build();
350
Adrian Roosddc8b272015-05-21 16:28:27 -0700351 // The panic gesture may become active only after the keyguard is dismissed and the immersive
352 // app shows again. If that doesn't happen for 30s we drop the gesture.
353 private static final long PANIC_GESTURE_EXPIRATION = 30000;
354
Winson44dbe292016-03-10 14:00:14 -0800355 private static final String SYSUI_PACKAGE = "com.android.systemui";
356 private static final String SYSUI_SCREENSHOT_SERVICE =
357 "com.android.systemui.screenshot.TakeScreenshotService";
358 private static final String SYSUI_SCREENSHOT_ERROR_RECEIVER =
359 "com.android.systemui.screenshot.ScreenshotServiceErrorReceiver";
360
Jim Miller5ecd8112013-01-09 18:50:26 -0800361 /**
362 * Keyguard stuff
363 */
Jeff Brown3ee549c2014-09-22 20:14:39 -0700364 private boolean mKeyguardDrawnOnce;
Jim Miller5ecd8112013-01-09 18:50:26 -0800365
Jeff Brown6651a632011-11-28 12:59:11 -0800366 /* Table of Application Launch keys. Maps from key codes to intent categories.
367 *
368 * These are special keys that are used to launch particular kinds of applications,
369 * such as a web browser. HID defines nearly a hundred of them in the Consumer (0x0C)
370 * usage page. We don't support quite that many yet...
371 */
372 static SparseArray<String> sApplicationLaunchKeyCategories;
373 static {
374 sApplicationLaunchKeyCategories = new SparseArray<String>();
375 sApplicationLaunchKeyCategories.append(
376 KeyEvent.KEYCODE_EXPLORER, Intent.CATEGORY_APP_BROWSER);
377 sApplicationLaunchKeyCategories.append(
378 KeyEvent.KEYCODE_ENVELOPE, Intent.CATEGORY_APP_EMAIL);
379 sApplicationLaunchKeyCategories.append(
380 KeyEvent.KEYCODE_CONTACTS, Intent.CATEGORY_APP_CONTACTS);
381 sApplicationLaunchKeyCategories.append(
382 KeyEvent.KEYCODE_CALENDAR, Intent.CATEGORY_APP_CALENDAR);
383 sApplicationLaunchKeyCategories.append(
384 KeyEvent.KEYCODE_MUSIC, Intent.CATEGORY_APP_MUSIC);
385 sApplicationLaunchKeyCategories.append(
386 KeyEvent.KEYCODE_CALCULATOR, Intent.CATEGORY_APP_CALCULATOR);
387 }
388
Craig Mautnerc3daedd2014-09-13 11:17:23 -0700389 /** Amount of time (in milliseconds) to wait for windows drawn before powering on. */
Jorim Jaggi0d210f62015-07-10 14:24:44 -0700390 static final int WAITING_FOR_DRAWN_TIMEOUT = 1000;
Craig Mautnerc3daedd2014-09-13 11:17:23 -0700391
Svetoslav Ganovaa076532016-08-01 19:16:43 -0700392 /** Amount of time (in milliseconds) a toast window can be shown. */
393 public static final int TOAST_WINDOW_TIMEOUT = 3500; // 3.5 seconds
394
Dianne Hackborndf89e652011-10-06 22:35:11 -0700395 /**
396 * Lock protecting internal state. Must not call out into window
397 * manager with lock held. (This lock will be acquired in places
398 * where the window manager is calling in with its own lock held.)
399 */
Craig Mautner0bf6ec92012-12-18 08:33:27 -0800400 private final Object mLock = new Object();
Dianne Hackborndf89e652011-10-06 22:35:11 -0700401
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800402 Context mContext;
403 IWindowManager mWindowManager;
Dianne Hackborndf89e652011-10-06 22:35:11 -0700404 WindowManagerFuncs mWindowManagerFuncs;
Craig Mautner8a0da012014-05-31 15:13:37 -0700405 WindowManagerInternal mWindowManagerInternal;
Jeff Brown96307042012-07-27 15:51:34 -0700406 PowerManager mPowerManager;
Jeff Brown061ea992015-04-17 19:55:47 -0700407 ActivityManagerInternal mActivityManagerInternal;
Felipe Leme5f978802017-06-08 13:01:13 -0700408 AutofillManagerInternal mAutofillManagerInternal;
Andrii Kulian112d0562016-03-08 10:44:22 -0800409 InputManagerInternal mInputManagerInternal;
Yohei Yukawad6475a62017-04-17 10:35:27 -0700410 InputMethodManagerInternal mInputMethodManagerInternal;
Jose Lima9546b202014-07-02 17:21:51 -0700411 DreamManagerInternal mDreamManagerInternal;
Michael Wrighta4d22d72015-09-16 23:19:26 +0100412 PowerManagerInternal mPowerManagerInternal;
Joe Onorato93056472010-09-10 10:30:46 -0400413 IStatusBarService mStatusBarService;
Jorim Jaggi86905582016-02-09 21:36:09 -0800414 StatusBarManagerInternal mStatusBarManagerInternal;
Jeff Browncaca8812013-05-09 13:34:33 -0700415 boolean mPreloadedRecentApps;
Dianne Hackborn42e620c2012-06-24 13:20:51 -0700416 final Object mServiceAquireLock = new Object();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800417 Vibrator mVibrator; // Vibrator for giving feedback of orientation changes
Jeff Brownde7a8ea2012-06-13 18:28:57 -0700418 SearchManager mSearchManager;
Svetoslav8e3feb12014-02-24 13:46:47 -0800419 AccessibilityManager mAccessibilityManager;
Filip Gruszczynskicfb31852015-02-25 21:47:12 +0000420 BurnInProtectionHelper mBurnInProtectionHelper;
Billy Laucbe540f2015-06-25 01:51:44 +0100421 AppOpsManager mAppOpsManager;
Wale Ogunwale6b15ea52016-04-04 07:28:27 -0700422 private boolean mHasFeatureWatch;
Dmitri Plotnikov82e6dfc2017-02-24 18:10:54 -0800423 private boolean mHasFeatureLeanback;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800424
Zak Cohen732aeb02017-01-29 14:19:52 -0800425 // Assigned on main thread, accessed on UI thread
426 volatile VrManagerInternal mVrManagerInternal;
427
Dianne Hackborn181ceb52009-08-27 22:16:40 -0700428 // Vibrator pattern for haptic feedback of a long press.
429 long[] mLongPressVibePattern;
Craig Mautner88400d32012-09-30 12:35:45 -0700430
Fabrice Di Megliobd9152f2013-10-01 11:21:31 -0700431 // Vibrator pattern for a short vibration when tapping on a day/month/year date of a Calendar.
432 long[] mCalendarDateVibePattern;
433
Dianne Hackbornb1a79802009-09-29 15:18:31 -0700434 // Vibrator pattern for haptic feedback during boot when safe mode is enabled.
435 long[] mSafeModeEnabledVibePattern;
Romain Guy8154cd32010-03-29 14:41:15 -0700436
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800437 /** If true, hitting shift & menu will broadcast Intent.ACTION_BUG_REPORT */
438 boolean mEnableShiftMenuBugReports = false;
Mike Lockwoodd747dc82011-09-13 16:28:22 -0400439
Phil Weaver106fe732016-11-22 18:18:39 -0800440 /** Controller that supports enabling an AccessibilityService by holding down the volume keys */
441 private AccessibilityShortcutController mAccessibilityShortcutController;
442
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800443 boolean mSafeMode;
444 WindowState mStatusBar = null;
Dianne Hackborn69cb8752011-05-19 18:13:32 -0700445 int mStatusBarHeight;
Daniel Sandler8956dbb2011-04-22 07:55:02 -0400446 WindowState mNavigationBar = null;
Daniel Sandler36412a72011-08-04 09:35:13 -0400447 boolean mHasNavigationBar = false;
Daniel Sandler4a066c52012-04-20 14:49:13 -0400448 boolean mNavigationBarCanMove = false; // can the navigation bar ever move to the side?
Adrian Roos85d202b2016-06-02 16:27:47 -0700449 int mNavigationBarPosition = NAV_BAR_BOTTOM;
Sriram Viswanathan9ebbe6a2015-11-16 17:59:22 -0800450 int[] mNavigationBarHeightForRotationDefault = new int[4];
451 int[] mNavigationBarWidthForRotationDefault = new int[4];
452 int[] mNavigationBarHeightForRotationInCarMode = new int[4];
453 int[] mNavigationBarWidthForRotationInCarMode = new int[4];
Daniel Sandler8956dbb2011-04-22 07:55:02 -0400454
Muyuan Li94ce94e2016-02-24 16:20:54 -0800455 private LongSparseArray<IShortcutService> mShortcutKeyServices = new LongSparseArray<>();
456
keunyounga7710492015-09-23 11:33:58 -0700457 // Whether to allow dock apps with METADATA_DOCK_HOME to temporarily take over the Home key.
458 // This is for car dock and this is updated from resource.
459 private boolean mEnableCarDockHomeCapture = true;
460
Craig Mautnera631d492014-08-05 15:16:01 -0700461 boolean mBootMessageNeedsHiding;
Jim Miller5ecd8112013-01-09 18:50:26 -0800462 KeyguardServiceDelegate mKeyguardDelegate;
Keun-young Park4136d2d2017-05-08 14:51:59 -0700463 private boolean mKeyguardBound;
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;
Winson Chungac52f282017-03-30 14:44:52 -0700500 volatile boolean mPictureInPictureVisible;
Santos Cordonc09d89c2017-04-13 16:12:02 -0700501 // Written by vr manager thread, only read in this class.
502 volatile private boolean mPersistentVrModeEnabled;
Yohei Yukawaabbe1ac2017-04-18 09:43:05 -0700503 volatile private boolean mDismissImeOnBackKeyPressed;
Jeff Brown13f00f02014-10-31 14:45:50 -0700504
Anthony Hugh4b13ab82016-05-17 13:03:00 -0700505 // Used to hold the last user key used to wake the device. This helps us prevent up events
506 // from being passed to the foregrounded app without a corresponding down event
507 volatile int mPendingWakeKey = PENDING_KEY_NULL;
508
Winson Chung1e8d71b2014-05-16 17:05:22 -0700509 int mRecentAppsHeldModifiers;
Jeff Browncf39bdf2012-05-18 14:41:19 -0700510 boolean mLanguageSwitchKeyPressed;
Jeff Brown68b909d2011-12-07 16:36:01 -0800511
Jeff Brown2e7760e2012-04-11 15:14:55 -0700512 int mLidState = LID_ABSENT;
Michael Wright3818c922014-09-02 13:59:07 -0700513 int mCameraLensCoverState = CAMERA_LENS_COVER_ABSENT;
Jeff Browndaa37532012-05-01 15:54:03 -0700514 boolean mHaveBuiltInKeyboard;
Jeff Brown4aed78b2011-01-14 17:36:55 -0800515
Dianne Hackbornc777e072010-02-12 13:07:59 -0800516 boolean mSystemReady;
Dianne Hackbornba24e4d2011-09-01 11:17:06 -0700517 boolean mSystemBooted;
Dianne Hackbornad7fa7f2011-01-07 14:06:50 -0800518 boolean mHdmiPlugged;
Jinsuk Kime601b712015-07-07 08:01:02 +0900519 HdmiControl mHdmiControl;
Jeff Brown4f5fa282014-06-12 19:19:15 -0700520 IUiModeManager mUiModeManager;
Daniel Sandler6396c722013-04-16 20:19:09 -0400521 int mUiMode;
Dianne Hackborn867ab6472010-04-29 13:28:56 -0700522 int mDockMode = Intent.EXTRA_DOCK_STATE_UNDOCKED;
Mike Lockwood1753f7f2009-08-24 14:49:07 -0700523 int mLidOpenRotation;
Mike Lockwood2d1efbd2009-09-16 12:15:53 -0400524 int mCarDockRotation;
525 int mDeskDockRotation;
Jeff Brownc82c89ed2013-04-17 17:18:15 -0700526 int mUndockedHdmiRotation;
527 int mDemoHdmiRotation;
528 boolean mDemoHdmiRotationLock;
Chong Zhangae6119ff2014-11-11 18:54:39 -0800529 int mDemoRotation;
530 boolean mDemoRotationLock;
Daniel Sandlerb73617d2010-08-17 00:41:00 -0400531
Jeff Browna20dda42014-05-27 20:57:24 -0700532 boolean mWakeGestureEnabledSetting;
533 MyWakeGestureListener mWakeGestureListener;
534
Craig Mautner46ac6fa2013-08-01 10:06:34 -0700535 // Default display does not rotate, apps that require non-default orientation will have to
536 // have the orientation emulated.
537 private boolean mForceDefaultOrientation = false;
538
Daniel Sandlerb73617d2010-08-17 00:41:00 -0400539 int mUserRotationMode = WindowManagerPolicy.USER_ROTATION_FREE;
540 int mUserRotation = Surface.ROTATION_0;
Jeff Brown207673cd2012-06-05 17:47:11 -0700541 boolean mAccelerometerDefault;
Daniel Sandlerb73617d2010-08-17 00:41:00 -0400542
Jeff Brownbcdfc622014-03-06 19:13:04 -0800543 boolean mSupportAutoRotation;
Jeff Brownd3187e32011-09-21 19:26:44 -0700544 int mAllowAllRotations = -1;
Mike Lockwoode9867d22009-09-20 01:59:02 -0400545 boolean mCarDockEnablesAccelerometer;
546 boolean mDeskDockEnablesAccelerometer;
Dianne Hackborn2862fff2009-09-15 22:56:29 -0700547 int mLidKeyboardAccessibility;
548 int mLidNavigationAccessibility;
Edward Savage-Jones7def60d2015-11-13 13:27:03 +0100549 boolean mLidControlsScreenLock;
Jeff Brownc458ce92012-04-30 14:58:40 -0700550 boolean mLidControlsSleep;
Jeff Brown13f00f02014-10-31 14:45:50 -0700551 int mShortPressOnPowerBehavior;
552 int mLongPressOnPowerBehavior;
553 int mDoublePressOnPowerBehavior;
554 int mTriplePressOnPowerBehavior;
Anthony Hugh34f09ca2016-03-04 12:03:37 -0800555 int mLongPressOnBackBehavior;
Anthony Hugh96e9cc52016-07-12 15:17:24 -0700556 int mPanicPressOnBackBehavior;
Filip Gruszczynskia483a1d2015-03-17 19:06:58 +0000557 int mShortPressOnSleepBehavior;
Jaewan Kim49117872016-01-19 17:24:08 +0900558 int mShortPressWindowBehavior;
Adrian Roose94c15c2017-05-09 13:17:54 -0700559 volatile boolean mAwake;
Jeff Brown3ee549c2014-09-22 20:14:39 -0700560 boolean mScreenOnEarly;
561 boolean mScreenOnFully;
562 ScreenOnListener mScreenOnListener;
563 boolean mKeyguardDrawComplete;
564 boolean mWindowManagerDrawComplete;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800565 boolean mOrientationSensorEnabled = false;
566 int mCurrentAppOrientation = ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800567 boolean mHasSoftInput = false;
Daniel Sandlerdd73ee42013-10-11 22:19:59 -0400568 boolean mTranslucentDecorEnabled = true;
RoboErik001c59c2015-01-26 15:53:51 -0800569 boolean mUseTvRouting;
Craig Mautner967212c2013-04-13 21:10:58 -0700570
Karthik Ravi Shankar86ecf342017-04-28 15:35:58 -0700571 private boolean mHandleVolumeKeysInWM;
572
Jeff Brown70825162012-03-28 17:27:48 -0700573 int mPointerLocationMode = 0; // guarded by mLock
Joe Onorato664644d2011-01-23 17:53:23 -0800574
575 // The last window we were told about in focusChanged.
576 WindowState mFocusedWindow;
Dianne Hackborne0f085d2011-11-30 18:41:15 -0800577 IApplicationToken mFocusedApp;
Joe Onorato664644d2011-01-23 17:53:23 -0800578
Jeff Brown70825162012-03-28 17:27:48 -0700579 PointerLocationView mPointerLocationView;
Jeff Brown32cbc38552011-12-01 14:01:49 -0800580
Dianne Hackbornc652de82013-02-15 16:32:56 -0800581 // The current size of the screen; really; extends into the overscan area of
582 // the screen and doesn't account for any system elements like the status bar.
583 int mOverscanScreenLeft, mOverscanScreenTop;
584 int mOverscanScreenWidth, mOverscanScreenHeight;
585 // The current visible size of the screen; really; (ir)regardless of whether the status
586 // bar can be hidden but not extending into the overscan area.
Joe Onorato29fc2c92010-11-24 10:26:50 -0800587 int mUnrestrictedScreenLeft, mUnrestrictedScreenTop;
588 int mUnrestrictedScreenWidth, mUnrestrictedScreenHeight;
Dianne Hackborn313440842013-02-19 19:22:59 -0800589 // Like mOverscanScreen*, but allowed to move into the overscan region where appropriate.
590 int mRestrictedOverscanScreenLeft, mRestrictedOverscanScreenTop;
591 int mRestrictedOverscanScreenWidth, mRestrictedOverscanScreenHeight;
Dianne Hackborn82de1ae2010-10-28 11:28:39 -0700592 // The current size of the screen; these may be different than (0,0)-(dw,dh)
593 // if the status bar can't be hidden; in that case it effectively carves out
594 // that area of the display from all other windows.
Joe Onorato29fc2c92010-11-24 10:26:50 -0800595 int mRestrictedScreenLeft, mRestrictedScreenTop;
596 int mRestrictedScreenWidth, mRestrictedScreenHeight;
Dianne Hackborn5c58de32012-04-28 19:52:37 -0700597 // During layout, the current screen borders accounting for any currently
598 // visible system UI elements.
599 int mSystemLeft, mSystemTop, mSystemRight, mSystemBottom;
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -0700600 // For applications requesting stable content insets, these are them.
601 int mStableLeft, mStableTop, mStableRight, mStableBottom;
Dianne Hackborn5b5cc4d2012-05-16 13:15:00 -0700602 // For applications requesting stable content insets but have also set the
603 // fullscreen window flag, these are the stable dimensions without the status bar.
604 int mStableFullscreenLeft, mStableFullscreenTop;
605 int mStableFullscreenRight, mStableFullscreenBottom;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800606 // During layout, the current screen borders with all outer decoration
607 // (status bar, input method dock) accounted for.
608 int mCurLeft, mCurTop, mCurRight, mCurBottom;
609 // During layout, the frame in which content should be displayed
610 // to the user, accounting for all screen decoration except for any
611 // space they deem as available for other content. This is usually
612 // the same as mCur*, but may be larger if the screen decor has supplied
613 // content insets.
614 int mContentLeft, mContentTop, mContentRight, mContentBottom;
Dianne Hackborne30e02f2014-05-27 18:24:45 -0700615 // During layout, the frame in which voice content should be displayed
616 // to the user, accounting for all screen decoration except for any
617 // space they deem as available for other content.
618 int mVoiceContentLeft, mVoiceContentTop, mVoiceContentRight, mVoiceContentBottom;
Dianne Hackborn8e11ef02010-11-18 19:47:42 -0800619 // During layout, the current screen borders along which input method
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800620 // windows are placed.
621 int mDockLeft, mDockTop, mDockRight, mDockBottom;
622 // During layout, the layer at which the doc window is placed.
623 int mDockLayer;
Dianne Hackborn5c58de32012-04-28 19:52:37 -0700624 // During layout, this is the layer of the status bar.
625 int mStatusBarLayer;
Dianne Hackborne26ab702011-10-16 13:21:33 -0700626 int mLastSystemUiFlags;
627 // Bits that we are in the process of clearing, so we want to prevent
628 // them from being set by applications until everything has been updated
629 // to have them clear.
630 int mResettingSystemUiFlags = 0;
631 // Bits that we are currently always keeping cleared.
632 int mForceClearedSystemUiFlags = 0;
Jorim Jaggi86905582016-02-09 21:36:09 -0800633 int mLastFullscreenStackSysUiFlags;
634 int mLastDockedStackSysUiFlags;
635 final Rect mNonDockedStackBounds = new Rect();
636 final Rect mDockedStackBounds = new Rect();
637 final Rect mLastNonDockedStackBounds = new Rect();
638 final Rect mLastDockedStackBounds = new Rect();
639
Dianne Hackborn4eff8d32011-11-10 19:38:40 -0800640 // What we last reported to system UI about whether the compatibility
641 // menu needs to be displayed.
642 boolean mLastFocusNeedsMenu = false;
Adrian Roosddc8b272015-05-21 16:28:27 -0700643 // If nonzero, a panic gesture was performed at that time in uptime millis and is still pending.
644 private long mPendingPanicGestureUptime;
Dianne Hackborndf89e652011-10-06 22:35:11 -0700645
Selim Cinekf83e8242015-05-19 18:08:14 -0700646 InputConsumer mInputConsumer = null;
Dianne Hackborndf89e652011-10-06 22:35:11 -0700647
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800648 static final Rect mTmpParentFrame = new Rect();
649 static final Rect mTmpDisplayFrame = new Rect();
Dianne Hackbornc4aad012013-02-22 15:05:25 -0800650 static final Rect mTmpOverscanFrame = new Rect();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800651 static final Rect mTmpContentFrame = new Rect();
652 static final Rect mTmpVisibleFrame = new Rect();
John Spurlock46646232013-09-30 22:32:42 -0400653 static final Rect mTmpDecorFrame = new Rect();
Adrian Roosfa104232014-06-20 16:10:14 -0700654 static final Rect mTmpStableFrame = new Rect();
Dianne Hackborn1f903c32011-09-13 19:18:06 -0700655 static final Rect mTmpNavigationFrame = new Rect();
Filip Gruszczynski2217f612015-05-26 11:32:08 -0700656 static final Rect mTmpOutsetFrame = new Rect();
Jorim Jaggi23bf5462016-05-13 15:24:39 -0700657 private static final Rect mTmpRect = new Rect();
Craig Mautner967212c2013-04-13 21:10:58 -0700658
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800659 WindowState mTopFullscreenOpaqueWindowState;
Adrian Rooscd3884d2015-02-18 17:25:23 +0100660 WindowState mTopFullscreenOpaqueOrDimmingWindowState;
Jorim Jaggi86905582016-02-09 21:36:09 -0800661 WindowState mTopDockedOpaqueWindowState;
662 WindowState mTopDockedOpaqueOrDimmingWindowState;
Joe Onorato93056472010-09-10 10:30:46 -0400663 boolean mTopIsFullscreen;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800664 boolean mForceStatusBar;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -0700665 boolean mForceStatusBarFromKeyguard;
Selim Cinek4a4a2bddc2015-05-07 12:50:19 -0700666 private boolean mForceStatusBarTransparent;
Yorke Lee9b2ffb32016-03-07 20:42:01 -0800667 int mNavBarOpacityMode = NAV_BAR_OPAQUE_WHEN_FREEFORM_OR_DOCKED;
Dianne Hackborn891d3fb2013-01-09 18:31:37 -0800668 boolean mForcingShowNavBar;
669 int mForcingShowNavBarLayer;
Craig Mautnerad09bcc2012-10-08 13:33:11 -0700670
Jorim Jaggife762342016-10-13 14:33:27 +0200671 private boolean mPendingKeyguardOccluded;
672 private boolean mKeyguardOccludedChanged;
Craig Mautnerc9457fa2014-06-06 14:27:48 -0700673
Dianne Hackborn7ad44382012-10-18 17:46:00 -0700674 boolean mShowingDream;
Jorim Jaggi77e10432016-10-26 17:43:56 -0700675 private boolean mLastShowingDream;
Dianne Hackborn7ad44382012-10-18 17:46:00 -0700676 boolean mDreamingLockscreen;
Jeff Brown061ea992015-04-17 19:55:47 -0700677 boolean mDreamingSleepTokenNeeded;
678 SleepToken mDreamingSleepToken;
Jeff Brown48d1b142015-06-10 16:36:03 -0700679 SleepToken mScreenOffSleepToken;
Jim Millerab954542014-10-10 18:21:49 -0700680 volatile boolean mKeyguardOccluded;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800681 boolean mHomePressed;
Jeff Browncaca8812013-05-09 13:34:33 -0700682 boolean mHomeConsumed;
683 boolean mHomeDoubleTapPending;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800684 Intent mHomeIntent;
Dianne Hackborn39c2d712009-09-22 11:41:31 -0700685 Intent mCarDockIntent;
686 Intent mDeskDockIntent;
Zak Cohendb6ca492017-01-26 14:09:00 -0800687 Intent mVrHeadsetHomeIntent;
Jeff Brownfd23e3e2012-05-09 13:34:28 -0700688 boolean mSearchKeyShortcutPending;
689 boolean mConsumeSearchKeyUp;
Jeff Brownde7a8ea2012-06-13 18:28:57 -0700690 boolean mAssistKeyLongPressed;
Michael Wright6a62e552014-06-03 19:19:48 -0700691 boolean mPendingMetaAction;
Andrii Kulian112d0562016-03-08 10:44:22 -0800692 boolean mPendingCapsLockToggle;
693 int mMetaState;
694 int mInitialMetaState;
Jorim Jaggi0ffd49c2016-02-12 15:04:21 -0800695 boolean mForceShowSystemBars;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800696
Mike Lockwood28569302010-01-28 11:54:40 -0500697 // support for activating the lock screen while the screen is on
698 boolean mAllowLockscreenWhenOn;
699 int mLockScreenTimeout;
700 boolean mLockScreenTimerActive;
701
David Brownbaf8d092010-03-08 21:52:59 -0800702 // Behavior of ENDCALL Button. (See Settings.System.END_BUTTON_BEHAVIOR.)
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800703 int mEndcallBehavior;
David Brownbaf8d092010-03-08 21:52:59 -0800704
705 // Behavior of POWER button while in-call and screen on.
706 // (See Settings.Secure.INCALL_POWER_BUTTON_BEHAVIOR.)
707 int mIncallPowerBehavior;
708
Bryce Leedb776ce2016-09-03 15:02:00 -0700709 // Behavior of Back button while in-call and screen on
710 int mIncallBackBehavior;
711
Dianne Hackbornf87d1962012-04-04 12:48:24 -0700712 Display mDisplay;
713
Filip Gruszczynski2987f612015-06-30 15:03:30 -0700714 private int mDisplayRotation;
715
Dianne Hackborn9d132642011-04-21 17:26:39 -0700716 int mLandscapeRotation = 0; // default landscape rotation
717 int mSeascapeRotation = 0; // "other" landscape rotation, 180 degrees from mLandscapeRotation
718 int mPortraitRotation = 0; // default portrait rotation
719 int mUpsideDownRotation = 0; // "other" portrait rotation
Mitsuru Oshima831d0d92009-06-16 18:27:18 -0700720
Dianne Hackbornc652de82013-02-15 16:32:56 -0800721 int mOverscanLeft = 0;
722 int mOverscanTop = 0;
723 int mOverscanRight = 0;
724 int mOverscanBottom = 0;
725
Joe Onorato46b0d682010-11-22 17:37:27 -0800726 // What we do when the user long presses on home
Jeff Browncaca8812013-05-09 13:34:33 -0700727 private int mLongPressOnHomeBehavior;
728
729 // What we do when the user double-taps on home
730 private int mDoubleTapOnHomeBehavior;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800731
Bryce Lee584a4452014-10-21 15:55:55 -0700732 // Allowed theater mode wake actions
733 private boolean mAllowTheaterModeWakeFromKey;
734 private boolean mAllowTheaterModeWakeFromPowerKey;
735 private boolean mAllowTheaterModeWakeFromMotion;
Bryce Lee812d7022014-11-10 13:33:28 -0800736 private boolean mAllowTheaterModeWakeFromMotionWhenNotDreaming;
Bryce Lee584a4452014-10-21 15:55:55 -0700737 private boolean mAllowTheaterModeWakeFromCameraLens;
738 private boolean mAllowTheaterModeWakeFromLidSwitch;
739 private boolean mAllowTheaterModeWakeFromWakeGesture;
740
Bryce Leed3b28402015-03-09 15:49:13 +0000741 // Whether to support long press from power button in non-interactive mode
742 private boolean mSupportLongPressPowerWhenNonInteractive;
743
Bryce Lee55e846d2014-11-04 12:43:44 -0800744 // Whether to go to sleep entering theater mode from power button
745 private boolean mGoToSleepOnButtonPressTheaterMode;
746
Winson Chung9112ec32011-06-27 13:15:32 -0700747 // Screenshot trigger states
Jeff Brownd5bb82d2011-10-12 13:57:59 -0700748 // Time to volume and power must be pressed within this interval of each other.
749 private static final long SCREENSHOT_CHORD_DEBOUNCE_DELAY_MILLIS = 150;
Winson Chung1cea2f32012-10-08 20:42:01 -0700750 // Increase the chord delay when taking a screenshot from the keyguard
751 private static final float KEYGUARD_SCREENSHOT_CHORD_DELAY_MULTIPLIER = 2.5f;
Christopher Tatee90585f2012-03-05 18:56:25 -0800752 private boolean mScreenshotChordEnabled;
Jeff Brown13f00f02014-10-31 14:45:50 -0700753 private boolean mScreenshotChordVolumeDownKeyTriggered;
754 private long mScreenshotChordVolumeDownKeyTime;
755 private boolean mScreenshotChordVolumeDownKeyConsumed;
Phil Weaver106fe732016-11-22 18:18:39 -0800756 private boolean mA11yShortcutChordVolumeUpKeyTriggered;
757 private long mA11yShortcutChordVolumeUpKeyTime;
758 private boolean mA11yShortcutChordVolumeUpKeyConsumed;
759
Jeff Brown13f00f02014-10-31 14:45:50 -0700760 private boolean mScreenshotChordPowerKeyTriggered;
761 private long mScreenshotChordPowerKeyTime;
Winson Chung9112ec32011-06-27 13:15:32 -0700762
Dmitri Plotnikov82e6dfc2017-02-24 18:10:54 -0800763 private static final long BUGREPORT_TV_GESTURE_TIMEOUT_MILLIS = 1000;
764
765 private boolean mBugreportTvKey1Pressed;
766 private boolean mBugreportTvKey2Pressed;
767 private boolean mBugreportTvScheduled;
768
Sujith Ramakrishnan6bed9bd2017-04-26 12:33:37 -0700769 private boolean mAccessibilityTvKey1Pressed;
770 private boolean mAccessibilityTvKey2Pressed;
771 private boolean mAccessibilityTvScheduled;
772
Michael Wrightb854e242013-02-05 17:54:02 -0800773 /* The number of steps between min and max brightness */
774 private static final int BRIGHTNESS_STEPS = 10;
775
Christopher Tate5e08af02012-09-21 17:17:22 -0700776 SettingsObserver mSettingsObserver;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800777 ShortcutManager mShortcutManager;
778 PowerManager.WakeLock mBroadcastWakeLock;
Jeff Brown13f00f02014-10-31 14:45:50 -0700779 PowerManager.WakeLock mPowerKeyWakeLock;
Jeff Brown40013652012-05-16 21:22:36 -0700780 boolean mHavePendingMediaKeyRepeatWithWakeLock;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800781
Craig Mautnerd625ab22013-09-06 13:40:31 -0700782 private int mCurrentUserId;
783
Justin Kohd378ad72013-04-01 12:18:26 -0700784 // Maps global key codes to the components that will handle them.
785 private GlobalKeyManager mGlobalKeyManager;
786
Jeff Brownfd23e3e2012-05-09 13:34:28 -0700787 // Fallback actions by key code.
788 private final SparseArray<KeyCharacterMap.FallbackAction> mFallbackActions =
789 new SparseArray<KeyCharacterMap.FallbackAction>();
Jeff Brown49ed71d2010-12-06 17:13:33 -0800790
Jorim Jaggi76a16232014-08-08 17:00:47 +0200791 private final LogDecelerateInterpolator mLogDecelerateInterpolator
792 = new LogDecelerateInterpolator(100, 0);
793
Jorim Jaggif1cdf952016-04-05 21:41:06 -0700794 private final MutableBoolean mTmpBoolean = new MutableBoolean(false);
Wale Ogunwale6b15ea52016-04-04 07:28:27 -0700795
Jeff Brown70825162012-03-28 17:27:48 -0700796 private static final int MSG_ENABLE_POINTER_LOCATION = 1;
797 private static final int MSG_DISABLE_POINTER_LOCATION = 2;
Jeff Brown40013652012-05-16 21:22:36 -0700798 private static final int MSG_DISPATCH_MEDIA_KEY_WITH_WAKE_LOCK = 3;
799 private static final int MSG_DISPATCH_MEDIA_KEY_REPEAT_WITH_WAKE_LOCK = 4;
Craig Mautner8a0da012014-05-31 15:13:37 -0700800 private static final int MSG_KEYGUARD_DRAWN_COMPLETE = 5;
801 private static final int MSG_KEYGUARD_DRAWN_TIMEOUT = 6;
802 private static final int MSG_WINDOW_MANAGER_DRAWN_COMPLETE = 7;
Craig Mautner84984fa2014-06-19 11:19:20 -0700803 private static final int MSG_DISPATCH_SHOW_RECENTS = 9;
Alan Viverettee34560b22014-07-10 14:50:06 -0700804 private static final int MSG_DISPATCH_SHOW_GLOBAL_ACTIONS = 10;
Craig Mautnera631d492014-08-05 15:16:01 -0700805 private static final int MSG_HIDE_BOOT_MESSAGE = 11;
Michael Wright869a67c2014-08-26 19:33:06 -0700806 private static final int MSG_LAUNCH_VOICE_ASSIST_WITH_WAKE_LOCK = 12;
Jeff Brown13f00f02014-10-31 14:45:50 -0700807 private static final int MSG_POWER_DELAYED_PRESS = 13;
808 private static final int MSG_POWER_LONG_PRESS = 14;
Jeff Brown061ea992015-04-17 19:55:47 -0700809 private static final int MSG_UPDATE_DREAMING_SLEEP_TOKEN = 15;
Jun Mukaid2e7e352015-07-22 17:14:02 -0700810 private static final int MSG_REQUEST_TRANSIENT_BARS = 16;
Winson Chungac52f282017-03-30 14:44:52 -0700811 private static final int MSG_SHOW_PICTURE_IN_PICTURE_MENU = 17;
Anthony Hugh34f09ca2016-03-04 12:03:37 -0800812 private static final int MSG_BACK_LONG_PRESS = 18;
Chong Zhang9f7fb092016-05-20 17:03:08 -0700813 private static final int MSG_DISPOSE_INPUT_CONSUMER = 19;
Anthony Hugh96e9cc52016-07-12 15:17:24 -0700814 private static final int MSG_BACK_DELAYED_PRESS = 20;
Phil Weaver106fe732016-11-22 18:18:39 -0800815 private static final int MSG_ACCESSIBILITY_SHORTCUT = 21;
Dmitri Plotnikov82e6dfc2017-02-24 18:10:54 -0800816 private static final int MSG_BUGREPORT_TV = 22;
Sujith Ramakrishnan6bed9bd2017-04-26 12:33:37 -0700817 private static final int MSG_ACCESSIBILITY_TV = 23;
Felipe Leme5f978802017-06-08 13:01:13 -0700818 private static final int MSG_DISPATCH_BACK_KEY_TO_AUTOFILL = 24;
Philip Quinn4b5b3c62017-07-20 21:07:58 -0700819 private static final int MSG_SYSTEM_KEY_PRESS = 25;
Jun Mukaid2e7e352015-07-22 17:14:02 -0700820
821 private static final int MSG_REQUEST_TRANSIENT_BARS_ARG_STATUS = 0;
822 private static final int MSG_REQUEST_TRANSIENT_BARS_ARG_NAVIGATION = 1;
Jeff Brown70825162012-03-28 17:27:48 -0700823
824 private class PolicyHandler extends Handler {
825 @Override
826 public void handleMessage(Message msg) {
827 switch (msg.what) {
828 case MSG_ENABLE_POINTER_LOCATION:
829 enablePointerLocation();
830 break;
831 case MSG_DISABLE_POINTER_LOCATION:
832 disablePointerLocation();
833 break;
Jeff Brown40013652012-05-16 21:22:36 -0700834 case MSG_DISPATCH_MEDIA_KEY_WITH_WAKE_LOCK:
835 dispatchMediaKeyWithWakeLock((KeyEvent)msg.obj);
836 break;
837 case MSG_DISPATCH_MEDIA_KEY_REPEAT_WITH_WAKE_LOCK:
838 dispatchMediaKeyRepeatWithWakeLock((KeyEvent)msg.obj);
839 break;
Craig Mautner84984fa2014-06-19 11:19:20 -0700840 case MSG_DISPATCH_SHOW_RECENTS:
Jorim Jaggi681fc7b2016-04-14 22:02:39 -0700841 showRecentApps(false, msg.arg1 != 0);
Craig Mautner84984fa2014-06-19 11:19:20 -0700842 break;
Alan Viverettee34560b22014-07-10 14:50:06 -0700843 case MSG_DISPATCH_SHOW_GLOBAL_ACTIONS:
844 showGlobalActionsInternal();
845 break;
Craig Mautner8a0da012014-05-31 15:13:37 -0700846 case MSG_KEYGUARD_DRAWN_COMPLETE:
847 if (DEBUG_WAKEUP) Slog.w(TAG, "Setting mKeyguardDrawComplete");
Jeff Brown36c4db82014-09-19 12:05:31 -0700848 finishKeyguardDrawn();
Craig Mautner8a0da012014-05-31 15:13:37 -0700849 break;
850 case MSG_KEYGUARD_DRAWN_TIMEOUT:
851 Slog.w(TAG, "Keyguard drawn timeout. Setting mKeyguardDrawComplete");
Jeff Brown36c4db82014-09-19 12:05:31 -0700852 finishKeyguardDrawn();
Craig Mautner8a0da012014-05-31 15:13:37 -0700853 break;
854 case MSG_WINDOW_MANAGER_DRAWN_COMPLETE:
855 if (DEBUG_WAKEUP) Slog.w(TAG, "Setting mWindowManagerDrawComplete");
Jeff Brown36c4db82014-09-19 12:05:31 -0700856 finishWindowsDrawn();
Craig Mautner8a0da012014-05-31 15:13:37 -0700857 break;
Craig Mautnera631d492014-08-05 15:16:01 -0700858 case MSG_HIDE_BOOT_MESSAGE:
859 handleHideBootMessage();
860 break;
Michael Wright869a67c2014-08-26 19:33:06 -0700861 case MSG_LAUNCH_VOICE_ASSIST_WITH_WAKE_LOCK:
862 launchVoiceAssistWithWakeLock(msg.arg1 != 0);
863 break;
Jeff Brown13f00f02014-10-31 14:45:50 -0700864 case MSG_POWER_DELAYED_PRESS:
865 powerPress((Long)msg.obj, msg.arg1 != 0, msg.arg2);
866 finishPowerKeyPress();
867 break;
868 case MSG_POWER_LONG_PRESS:
869 powerLongPress();
870 break;
Jeff Brown061ea992015-04-17 19:55:47 -0700871 case MSG_UPDATE_DREAMING_SLEEP_TOKEN:
872 updateDreamingSleepToken(msg.arg1 != 0);
873 break;
Jun Mukaid2e7e352015-07-22 17:14:02 -0700874 case MSG_REQUEST_TRANSIENT_BARS:
875 WindowState targetBar = (msg.arg1 == MSG_REQUEST_TRANSIENT_BARS_ARG_STATUS) ?
876 mStatusBar : mNavigationBar;
877 if (targetBar != null) {
878 requestTransientBars(targetBar);
879 }
880 break;
Winson Chungac52f282017-03-30 14:44:52 -0700881 case MSG_SHOW_PICTURE_IN_PICTURE_MENU:
882 showPictureInPictureMenuInternal();
Jaewan Kimc552b042016-01-18 16:08:45 +0900883 break;
Anthony Hugh34f09ca2016-03-04 12:03:37 -0800884 case MSG_BACK_LONG_PRESS:
885 backLongPress();
Anthony Hugh96e9cc52016-07-12 15:17:24 -0700886 finishBackKeyPress();
Anthony Hugh34f09ca2016-03-04 12:03:37 -0800887 break;
Chong Zhang9f7fb092016-05-20 17:03:08 -0700888 case MSG_DISPOSE_INPUT_CONSUMER:
889 disposeInputConsumer((InputConsumer) msg.obj);
890 break;
Anthony Hugh96e9cc52016-07-12 15:17:24 -0700891 case MSG_BACK_DELAYED_PRESS:
892 backMultiPressAction((Long) msg.obj, msg.arg1);
893 finishBackKeyPress();
894 break;
Phil Weaver106fe732016-11-22 18:18:39 -0800895 case MSG_ACCESSIBILITY_SHORTCUT:
896 accessibilityShortcutActivated();
897 break;
Dmitri Plotnikov82e6dfc2017-02-24 18:10:54 -0800898 case MSG_BUGREPORT_TV:
899 takeBugreport();
900 break;
Sujith Ramakrishnan6bed9bd2017-04-26 12:33:37 -0700901 case MSG_ACCESSIBILITY_TV:
902 if (mAccessibilityShortcutController.isAccessibilityShortcutAvailable(false)) {
903 accessibilityShortcutActivated();
904 }
905 break;
Felipe Leme5f978802017-06-08 13:01:13 -0700906 case MSG_DISPATCH_BACK_KEY_TO_AUTOFILL:
907 mAutofillManagerInternal.onBackKeyPressed();
908 break;
Philip Quinn4b5b3c62017-07-20 21:07:58 -0700909 case MSG_SYSTEM_KEY_PRESS:
910 sendSystemKeyToStatusBar(msg.arg1);
911 break;
Jeff Brown70825162012-03-28 17:27:48 -0700912 }
913 }
914 }
915
Dianne Hackbornad7fa7f2011-01-07 14:06:50 -0800916 private UEventObserver mHDMIObserver = new UEventObserver() {
917 @Override
918 public void onUEvent(UEventObserver.UEvent event) {
919 setHdmiPlugged("1".equals(event.get("SWITCH_STATE")));
920 }
921 };
922
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800923 class SettingsObserver extends ContentObserver {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800924 SettingsObserver(Handler handler) {
925 super(handler);
926 }
David Brownbaf8d092010-03-08 21:52:59 -0800927
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800928 void observe() {
Christopher Tate5e08af02012-09-21 17:17:22 -0700929 // Observe all users' changes
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800930 ContentResolver resolver = mContext.getContentResolver();
931 resolver.registerContentObserver(Settings.System.getUriFor(
Christopher Tate5e08af02012-09-21 17:17:22 -0700932 Settings.System.END_BUTTON_BEHAVIOR), false, this,
933 UserHandle.USER_ALL);
David Brownbaf8d092010-03-08 21:52:59 -0800934 resolver.registerContentObserver(Settings.Secure.getUriFor(
Christopher Tate5e08af02012-09-21 17:17:22 -0700935 Settings.Secure.INCALL_POWER_BUTTON_BEHAVIOR), false, this,
936 UserHandle.USER_ALL);
Jeff Browna20dda42014-05-27 20:57:24 -0700937 resolver.registerContentObserver(Settings.Secure.getUriFor(
Bryce Leedb776ce2016-09-03 15:02:00 -0700938 Settings.Secure.INCALL_BACK_BUTTON_BEHAVIOR), false, this,
939 UserHandle.USER_ALL);
940 resolver.registerContentObserver(Settings.Secure.getUriFor(
Jeff Browna20dda42014-05-27 20:57:24 -0700941 Settings.Secure.WAKE_GESTURE_ENABLED), false, this,
942 UserHandle.USER_ALL);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800943 resolver.registerContentObserver(Settings.System.getUriFor(
Christopher Tate5e08af02012-09-21 17:17:22 -0700944 Settings.System.ACCELEROMETER_ROTATION), false, this,
945 UserHandle.USER_ALL);
Mike Lockwood28569302010-01-28 11:54:40 -0500946 resolver.registerContentObserver(Settings.System.getUriFor(
Christopher Tate5e08af02012-09-21 17:17:22 -0700947 Settings.System.USER_ROTATION), false, this,
948 UserHandle.USER_ALL);
Daniel Sandlerb73617d2010-08-17 00:41:00 -0400949 resolver.registerContentObserver(Settings.System.getUriFor(
Christopher Tate5e08af02012-09-21 17:17:22 -0700950 Settings.System.SCREEN_OFF_TIMEOUT), false, this,
951 UserHandle.USER_ALL);
Dianne Hackbornc777e072010-02-12 13:07:59 -0800952 resolver.registerContentObserver(Settings.System.getUriFor(
Christopher Tate5e08af02012-09-21 17:17:22 -0700953 Settings.System.POINTER_LOCATION), false, this,
954 UserHandle.USER_ALL);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800955 resolver.registerContentObserver(Settings.Secure.getUriFor(
Christopher Tate5e08af02012-09-21 17:17:22 -0700956 Settings.Secure.DEFAULT_INPUT_METHOD), false, this,
957 UserHandle.USER_ALL);
John Spurlockd9b70bd2014-02-06 17:02:44 -0500958 resolver.registerContentObserver(Settings.Secure.getUriFor(
John Spurlockf1a36642013-10-12 17:50:42 -0400959 Settings.Secure.IMMERSIVE_MODE_CONFIRMATIONS), false, this,
Christopher Tate5e08af02012-09-21 17:17:22 -0700960 UserHandle.USER_ALL);
John Spurlockc6d1c602014-01-17 15:22:06 -0500961 resolver.registerContentObserver(Settings.Global.getUriFor(
962 Settings.Global.POLICY_CONTROL), false, this,
963 UserHandle.USER_ALL);
Dianne Hackbornc777e072010-02-12 13:07:59 -0800964 updateSettings();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800965 }
966
967 @Override public void onChange(boolean selfChange) {
Dianne Hackbornc777e072010-02-12 13:07:59 -0800968 updateSettings();
Jeff Brown01a98dd2011-09-20 15:08:29 -0700969 updateRotation(false);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800970 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800971 }
Craig Mautner967212c2013-04-13 21:10:58 -0700972
Jeff Browna20dda42014-05-27 20:57:24 -0700973 class MyWakeGestureListener extends WakeGestureListener {
974 MyWakeGestureListener(Context context, Handler handler) {
975 super(context, handler);
976 }
977
978 @Override
979 public void onWakeUp() {
980 synchronized (mLock) {
981 if (shouldEnableWakeGestureLp()) {
Jeff Browne07b94b2014-06-18 15:56:27 -0700982 performHapticFeedbackLw(null, HapticFeedbackConstants.VIRTUAL_KEY, false);
Dianne Hackborn280a64e2015-07-13 14:48:08 -0700983 wakeUp(SystemClock.uptimeMillis(), mAllowTheaterModeWakeFromWakeGesture,
984 "android.policy:GESTURE");
Jeff Browna20dda42014-05-27 20:57:24 -0700985 }
986 }
987 }
988 }
989
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800990 class MyOrientationListener extends WindowOrientationListener {
Chong Zhang5aaa0b32015-08-28 10:22:36 -0700991 private final Runnable mUpdateRotationRunnable = new Runnable() {
992 @Override
993 public void run() {
Tim Murray1f407642015-10-01 17:07:12 -0700994 // send interaction hint to improve redraw performance
Ruchi Kandoi0d434042016-10-03 09:12:02 -0700995 mPowerManagerInternal.powerHint(PowerHint.INTERACTION, 0);
Chong Zhang5aaa0b32015-08-28 10:22:36 -0700996 updateRotation(false);
997 }
998 };
999
Craig Mautnereee29c42013-01-17 14:44:34 -08001000 MyOrientationListener(Context context, Handler handler) {
1001 super(context, handler);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001002 }
Craig Mautner967212c2013-04-13 21:10:58 -07001003
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001004 @Override
Jeff Brownc0347aa2011-09-23 17:26:09 -07001005 public void onProposedRotationChanged(int rotation) {
Craig Mautnereda67292013-04-28 13:50:14 -07001006 if (localLOGV) Slog.v(TAG, "onProposedRotationChanged, rotation=" + rotation);
Chong Zhang5aaa0b32015-08-28 10:22:36 -07001007 mHandler.post(mUpdateRotationRunnable);
Jeff Brown01a98dd2011-09-20 15:08:29 -07001008 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001009 }
1010 MyOrientationListener mOrientationListener;
1011
Santos Cordonc09d89c2017-04-13 16:12:02 -07001012 final IPersistentVrStateCallbacks mPersistentVrModeListener =
1013 new IPersistentVrStateCallbacks.Stub() {
1014 @Override
1015 public void onPersistentVrStateChanged(boolean enabled) {
1016 mPersistentVrModeEnabled = enabled;
1017 }
1018 };
1019
Jorim Jaggi24bec7c2015-02-04 12:40:14 +01001020 private final StatusBarController mStatusBarController = new StatusBarController();
John Spurlock5b9145b2013-08-20 15:13:47 -04001021
John Spurlock27735a42013-08-14 17:57:38 -04001022 private final BarController mNavigationBarController = new BarController("NavigationBar",
John Spurlock5b9145b2013-08-20 15:13:47 -04001023 View.NAVIGATION_BAR_TRANSIENT,
1024 View.NAVIGATION_BAR_UNHIDE,
John Spurlockbd957402013-10-03 11:38:39 -04001025 View.NAVIGATION_BAR_TRANSLUCENT,
1026 StatusBarManager.WINDOW_NAVIGATION_BAR,
Jorim Jaggi4fa78922015-11-30 17:13:56 -08001027 WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION,
1028 View.NAVIGATION_BAR_TRANSPARENT);
John Spurlock5b9145b2013-08-20 15:13:47 -04001029
Casey Burkhardt048c2bc2016-12-08 16:09:20 -08001030 private final BarController.OnBarVisibilityChangedListener mNavBarVisibilityListener =
1031 new BarController.OnBarVisibilityChangedListener() {
1032 @Override
1033 public void onBarVisibilityChanged(boolean visible) {
Casey Burkhardt469a2082017-06-13 20:12:42 -07001034 mAccessibilityManager.notifyAccessibilityButtonVisibilityChanged(visible);
Casey Burkhardt048c2bc2016-12-08 16:09:20 -08001035 }
1036 };
1037
John Spurlockf1a36642013-10-12 17:50:42 -04001038 private ImmersiveModeConfirmation mImmersiveModeConfirmation;
John Spurlock32beb2c2013-03-11 10:16:47 -04001039
Craig Mautner037aa8d2013-06-07 10:35:44 -07001040 private SystemGesturesPointerEventListener mSystemGestures;
John Spurlock32beb2c2013-03-11 10:16:47 -04001041
Dianne Hackborn42e620c2012-06-24 13:20:51 -07001042 IStatusBarService getStatusBarService() {
1043 synchronized (mServiceAquireLock) {
1044 if (mStatusBarService == null) {
1045 mStatusBarService = IStatusBarService.Stub.asInterface(
1046 ServiceManager.getService("statusbar"));
1047 }
1048 return mStatusBarService;
1049 }
1050 }
1051
Jorim Jaggi86905582016-02-09 21:36:09 -08001052 StatusBarManagerInternal getStatusBarManagerInternal() {
1053 synchronized (mServiceAquireLock) {
1054 if (mStatusBarManagerInternal == null) {
1055 mStatusBarManagerInternal =
1056 LocalServices.getService(StatusBarManagerInternal.class);
1057 }
1058 return mStatusBarManagerInternal;
1059 }
1060 }
1061
Suchi Amalapurapua9e1b162009-03-24 22:24:47 -07001062 /*
1063 * We always let the sensor be switched on by default except when
1064 * the user has explicitly disabled sensor based rotation or when the
1065 * screen is switched off.
1066 */
The Android Open Source Project0727d222009-03-11 12:11:58 -07001067 boolean needSensorRunningLp() {
Jeff Brownbcdfc622014-03-06 19:13:04 -08001068 if (mSupportAutoRotation) {
1069 if (mCurrentAppOrientation == ActivityInfo.SCREEN_ORIENTATION_SENSOR
1070 || mCurrentAppOrientation == ActivityInfo.SCREEN_ORIENTATION_FULL_SENSOR
1071 || mCurrentAppOrientation == ActivityInfo.SCREEN_ORIENTATION_SENSOR_PORTRAIT
1072 || mCurrentAppOrientation == ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE) {
1073 // If the application has explicitly requested to follow the
1074 // orientation, then we need to turn the sensor on.
1075 return true;
1076 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001077 }
Dianne Hackborn867ab6472010-04-29 13:28:56 -07001078 if ((mCarDockEnablesAccelerometer && mDockMode == Intent.EXTRA_DOCK_STATE_CAR) ||
Jeff Brown1a693182011-11-08 14:44:16 -08001079 (mDeskDockEnablesAccelerometer && (mDockMode == Intent.EXTRA_DOCK_STATE_DESK
1080 || mDockMode == Intent.EXTRA_DOCK_STATE_LE_DESK
1081 || mDockMode == Intent.EXTRA_DOCK_STATE_HE_DESK))) {
Mike Lockwoode9867d22009-09-20 01:59:02 -04001082 // enable accelerometer if we are docked in a dock that enables accelerometer
1083 // orientation management,
1084 return true;
1085 }
Jeff Brown207673cd2012-06-05 17:47:11 -07001086 if (mUserRotationMode == USER_ROTATION_LOCKED) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001087 // If the setting for using the sensor by default is enabled, then
1088 // we will always leave it on. Note that the user could go to
1089 // a window that forces an orientation that does not use the
1090 // sensor and in theory we could turn it off... however, when next
1091 // turning it on we won't have a good value for the current
1092 // orientation for a little bit, which can cause orientation
1093 // changes to lag, so we'd like to keep it always on. (It will
1094 // still be turned off when the screen is off.)
Suchi Amalapurapua9e1b162009-03-24 22:24:47 -07001095 return false;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001096 }
Jeff Brownbcdfc622014-03-06 19:13:04 -08001097 return mSupportAutoRotation;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001098 }
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001099
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001100 /*
1101 * Various use cases for invoking this function
1102 * screen turning off, should always disable listeners if already enabled
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001103 * screen turned on and current app has sensor based orientation, enable listeners
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001104 * if not already enabled
1105 * screen turned on and current app does not have sensor orientation, disable listeners if
1106 * already enabled
1107 * screen turning on and current app has sensor based orientation, enable listeners if needed
1108 * screen turning on and current app has nosensor based orientation, do nothing
1109 */
The Android Open Source Project0727d222009-03-11 12:11:58 -07001110 void updateOrientationListenerLp() {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001111 if (!mOrientationListener.canDetectOrientation()) {
1112 // If sensor is turned off or nonexistent for some reason
1113 return;
1114 }
Stefan Kuhne9326dc12015-06-12 09:25:32 -10001115 // Could have been invoked due to screen turning on or off or
1116 // change of the currently visible window's orientation.
Jeff Brown3ee549c2014-09-22 20:14:39 -07001117 if (localLOGV) Slog.v(TAG, "mScreenOnEarly=" + mScreenOnEarly
1118 + ", mAwake=" + mAwake + ", mCurrentAppOrientation=" + mCurrentAppOrientation
Stefan Kuhne9326dc12015-06-12 09:25:32 -10001119 + ", mOrientationSensorEnabled=" + mOrientationSensorEnabled
1120 + ", mKeyguardDrawComplete=" + mKeyguardDrawComplete
1121 + ", mWindowManagerDrawComplete=" + mWindowManagerDrawComplete);
Wale Ogunwalebfa81ad2017-05-24 15:14:42 -07001122 final boolean keyguardGoingAway = mWindowManagerInternal.isKeyguardGoingAway();
1123
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001124 boolean disable = true;
Stefan Kuhne9326dc12015-06-12 09:25:32 -10001125 // Note: We postpone the rotating of the screen until the keyguard as well as the
Wale Ogunwalebfa81ad2017-05-24 15:14:42 -07001126 // window manager have reported a draw complete or the keyguard is going away in dismiss
1127 // mode.
1128 if (mScreenOnEarly && mAwake && ((mKeyguardDrawComplete && mWindowManagerDrawComplete)
1129 || keyguardGoingAway)) {
The Android Open Source Project0727d222009-03-11 12:11:58 -07001130 if (needSensorRunningLp()) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001131 disable = false;
1132 //enable listener if not already enabled
The Android Open Source Project0727d222009-03-11 12:11:58 -07001133 if (!mOrientationSensorEnabled) {
Wale Ogunwalebfa81ad2017-05-24 15:14:42 -07001134 // Don't clear the current sensor orientation if the keyguard is going away in
1135 // dismiss mode. This allows window manager to use the last sensor reading to
1136 // determine the orientation vs. falling back to the last known orientation if
1137 // the sensor reading was cleared which can cause it to relaunch the app that
1138 // will show in the wrong orientation first before correcting leading to app
1139 // launch delays.
1140 mOrientationListener.enable(!keyguardGoingAway /* clearCurrentRotation */);
Craig Mautnereda67292013-04-28 13:50:14 -07001141 if(localLOGV) Slog.v(TAG, "Enabling listeners");
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001142 mOrientationSensorEnabled = true;
1143 }
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001144 }
1145 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001146 //check if sensors need to be disabled
The Android Open Source Project0727d222009-03-11 12:11:58 -07001147 if (disable && mOrientationSensorEnabled) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001148 mOrientationListener.disable();
Craig Mautnereda67292013-04-28 13:50:14 -07001149 if(localLOGV) Slog.v(TAG, "Disabling listeners");
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001150 mOrientationSensorEnabled = false;
1151 }
1152 }
1153
Anthony Hugh96e9cc52016-07-12 15:17:24 -07001154 private void interceptBackKeyDown() {
Nimrod Gileadi580135c2016-10-31 20:42:19 +00001155 MetricsLogger.count(mContext, "key_back_down", 1);
Anthony Hugh96e9cc52016-07-12 15:17:24 -07001156 // Reset back key state for long press
1157 mBackKeyHandled = false;
1158
1159 // Cancel multi-press detection timeout.
1160 if (hasPanicPressOnBackBehavior()) {
1161 if (mBackKeyPressCounter != 0
1162 && mBackKeyPressCounter < PANIC_PRESS_BACK_COUNT) {
1163 mHandler.removeMessages(MSG_BACK_DELAYED_PRESS);
1164 }
1165 }
1166
1167 if (hasLongPressOnBackBehavior()) {
1168 Message msg = mHandler.obtainMessage(MSG_BACK_LONG_PRESS);
1169 msg.setAsynchronous(true);
1170 mHandler.sendMessageDelayed(msg,
1171 ViewConfiguration.get(mContext).getDeviceGlobalActionKeyTimeout());
1172 }
1173 }
1174
1175 // returns true if the key was handled and should not be passed to the user
1176 private boolean interceptBackKeyUp(KeyEvent event) {
1177 // Cache handled state
1178 boolean handled = mBackKeyHandled;
1179
1180 if (hasPanicPressOnBackBehavior()) {
1181 // Check for back key panic press
1182 ++mBackKeyPressCounter;
1183
1184 final long eventTime = event.getDownTime();
1185
1186 if (mBackKeyPressCounter <= PANIC_PRESS_BACK_COUNT) {
1187 // This could be a multi-press. Wait a little bit longer to confirm.
1188 Message msg = mHandler.obtainMessage(MSG_BACK_DELAYED_PRESS,
Bryce Leedb776ce2016-09-03 15:02:00 -07001189 mBackKeyPressCounter, 0, eventTime);
Anthony Hugh96e9cc52016-07-12 15:17:24 -07001190 msg.setAsynchronous(true);
1191 mHandler.sendMessageDelayed(msg, ViewConfiguration.getMultiPressTimeout());
1192 }
1193 }
1194
1195 // Reset back long press state
1196 cancelPendingBackKeyAction();
1197
Bryce Leedb776ce2016-09-03 15:02:00 -07001198 if (mHasFeatureWatch) {
1199 TelecomManager telecomManager = getTelecommService();
1200
1201 if (telecomManager != null) {
1202 if (telecomManager.isRinging()) {
1203 // Pressing back while there's a ringing incoming
1204 // call should silence the ringer.
1205 telecomManager.silenceRinger();
1206
1207 // It should not prevent navigating away
1208 return false;
1209 } else if (
1210 (mIncallBackBehavior & Settings.Secure.INCALL_BACK_BUTTON_BEHAVIOR_HANGUP) != 0
1211 && telecomManager.isInCall()) {
1212 // Otherwise, if "Back button ends call" is enabled,
1213 // the Back button will hang up any current active call.
1214 return telecomManager.endCall();
1215 }
1216 }
1217 }
1218
Felipe Leme5f978802017-06-08 13:01:13 -07001219 if (mAutofillManagerInternal != null && event.getKeyCode() == KeyEvent.KEYCODE_BACK) {
1220 mHandler.sendMessage(mHandler.obtainMessage(MSG_DISPATCH_BACK_KEY_TO_AUTOFILL));
1221 }
1222
Anthony Hugh96e9cc52016-07-12 15:17:24 -07001223 return handled;
1224 }
1225
Jeff Brown13f00f02014-10-31 14:45:50 -07001226 private void interceptPowerKeyDown(KeyEvent event, boolean interactive) {
1227 // Hold a wake lock until the power key is released.
1228 if (!mPowerKeyWakeLock.isHeld()) {
1229 mPowerKeyWakeLock.acquire();
1230 }
1231
1232 // Cancel multi-press detection timeout.
1233 if (mPowerKeyPressCounter != 0) {
1234 mHandler.removeMessages(MSG_POWER_DELAYED_PRESS);
1235 }
1236
1237 // Detect user pressing the power button in panic when an application has
1238 // taken over the whole screen.
1239 boolean panic = mImmersiveModeConfirmation.onPowerKeyDown(interactive,
Adrian Roos7aaa5512016-07-12 15:27:24 -07001240 SystemClock.elapsedRealtime(), isImmersiveMode(mLastSystemUiFlags),
1241 isNavBarEmpty(mLastSystemUiFlags));
Jeff Brown13f00f02014-10-31 14:45:50 -07001242 if (panic) {
Adrian Roosddc8b272015-05-21 16:28:27 -07001243 mHandler.post(mHiddenNavPanic);
Jeff Brown13f00f02014-10-31 14:45:50 -07001244 }
1245
1246 // Latch power key state to detect screenshot chord.
1247 if (interactive && !mScreenshotChordPowerKeyTriggered
1248 && (event.getFlags() & KeyEvent.FLAG_FALLBACK) == 0) {
1249 mScreenshotChordPowerKeyTriggered = true;
1250 mScreenshotChordPowerKeyTime = event.getDownTime();
1251 interceptScreenshotChord();
1252 }
1253
1254 // Stop ringing or end call if configured to do so when power is pressed.
1255 TelecomManager telecomManager = getTelecommService();
1256 boolean hungUp = false;
1257 if (telecomManager != null) {
1258 if (telecomManager.isRinging()) {
1259 // Pressing Power while there's a ringing incoming
1260 // call should silence the ringer.
1261 telecomManager.silenceRinger();
1262 } else if ((mIncallPowerBehavior
1263 & Settings.Secure.INCALL_POWER_BUTTON_BEHAVIOR_HANGUP) != 0
1264 && telecomManager.isInCall() && interactive) {
1265 // Otherwise, if "Power button ends call" is enabled,
1266 // the Power button will hang up any current active call.
1267 hungUp = telecomManager.endCall();
1268 }
1269 }
1270
Adrian Roos5941c982015-09-03 15:59:49 -07001271 GestureLauncherService gestureService = LocalServices.getService(
1272 GestureLauncherService.class);
1273 boolean gesturedServiceIntercepted = false;
1274 if (gestureService != null) {
Jorim Jaggif1cdf952016-04-05 21:41:06 -07001275 gesturedServiceIntercepted = gestureService.interceptPowerKeyDown(event, interactive,
1276 mTmpBoolean);
1277 if (mTmpBoolean.value && mGoingToSleep) {
1278 mCameraGestureTriggeredDuringGoingToSleep = true;
1279 }
Adrian Roos5941c982015-09-03 15:59:49 -07001280 }
1281
Philip Quinnc3a503d2017-07-18 23:23:41 -07001282 // Inform the StatusBar; but do not allow it to consume the event.
Philip Quinn4b5b3c62017-07-20 21:07:58 -07001283 sendSystemKeyToStatusBarAsync(event.getKeyCode());
Philip Quinnc3a503d2017-07-18 23:23:41 -07001284
Jeff Brown13f00f02014-10-31 14:45:50 -07001285 // If the power key has still not yet been handled, then detect short
1286 // press, long press, or multi press and decide what to do.
1287 mPowerKeyHandled = hungUp || mScreenshotChordVolumeDownKeyTriggered
Phil Weaver106fe732016-11-22 18:18:39 -08001288 || mA11yShortcutChordVolumeUpKeyTriggered || gesturedServiceIntercepted;
Jeff Brown13f00f02014-10-31 14:45:50 -07001289 if (!mPowerKeyHandled) {
1290 if (interactive) {
1291 // When interactive, we're already awake.
1292 // Wait for a long press or for the button to be released to decide what to do.
1293 if (hasLongPressOnPowerBehavior()) {
1294 Message msg = mHandler.obtainMessage(MSG_POWER_LONG_PRESS);
1295 msg.setAsynchronous(true);
1296 mHandler.sendMessageDelayed(msg,
1297 ViewConfiguration.get(mContext).getDeviceGlobalActionKeyTimeout());
1298 }
1299 } else {
Bryce Leed9268e32014-11-17 17:40:59 -08001300 wakeUpFromPowerKey(event.getDownTime());
Bryce Leed9268e32014-11-17 17:40:59 -08001301
Bryce Leed3b28402015-03-09 15:49:13 +00001302 if (mSupportLongPressPowerWhenNonInteractive && hasLongPressOnPowerBehavior()) {
1303 Message msg = mHandler.obtainMessage(MSG_POWER_LONG_PRESS);
1304 msg.setAsynchronous(true);
1305 mHandler.sendMessageDelayed(msg,
1306 ViewConfiguration.get(mContext).getDeviceGlobalActionKeyTimeout());
Bryce Leed9268e32014-11-17 17:40:59 -08001307 mBeganFromNonInteractive = true;
Bryce Leed3b28402015-03-09 15:49:13 +00001308 } else {
1309 final int maxCount = getMaxMultiPressPowerCount();
1310
1311 if (maxCount <= 1) {
1312 mPowerKeyHandled = true;
1313 } else {
1314 mBeganFromNonInteractive = true;
1315 }
Jeff Brown13f00f02014-10-31 14:45:50 -07001316 }
1317 }
Jeff Brown4d396052010-10-29 21:50:21 -07001318 }
1319 }
1320
Jeff Brown13f00f02014-10-31 14:45:50 -07001321 private void interceptPowerKeyUp(KeyEvent event, boolean interactive, boolean canceled) {
1322 final boolean handled = canceled || mPowerKeyHandled;
1323 mScreenshotChordPowerKeyTriggered = false;
1324 cancelPendingScreenshotChordAction();
1325 cancelPendingPowerKeyAction();
1326
1327 if (!handled) {
1328 // Figure out how to handle the key now that it has been released.
1329 mPowerKeyPressCounter += 1;
1330
1331 final int maxCount = getMaxMultiPressPowerCount();
1332 final long eventTime = event.getDownTime();
1333 if (mPowerKeyPressCounter < maxCount) {
1334 // This could be a multi-press. Wait a little bit longer to confirm.
1335 // Continue holding the wake lock.
1336 Message msg = mHandler.obtainMessage(MSG_POWER_DELAYED_PRESS,
1337 interactive ? 1 : 0, mPowerKeyPressCounter, eventTime);
1338 msg.setAsynchronous(true);
Alain Vongsouvanh0f63a542017-04-10 17:13:17 -07001339 mHandler.sendMessageDelayed(msg, ViewConfiguration.getMultiPressTimeout());
Jeff Brown13f00f02014-10-31 14:45:50 -07001340 return;
1341 }
1342
1343 // No other actions. Handle it immediately.
1344 powerPress(eventTime, interactive, mPowerKeyPressCounter);
Jeff Brown4d396052010-10-29 21:50:21 -07001345 }
Jeff Brown13f00f02014-10-31 14:45:50 -07001346
1347 // Done. Reset our state.
1348 finishPowerKeyPress();
1349 }
1350
1351 private void finishPowerKeyPress() {
Bryce Leed9268e32014-11-17 17:40:59 -08001352 mBeganFromNonInteractive = false;
Jeff Brown13f00f02014-10-31 14:45:50 -07001353 mPowerKeyPressCounter = 0;
1354 if (mPowerKeyWakeLock.isHeld()) {
1355 mPowerKeyWakeLock.release();
1356 }
Jeff Brownd5bb82d2011-10-12 13:57:59 -07001357 }
1358
Anthony Hugh96e9cc52016-07-12 15:17:24 -07001359 private void finishBackKeyPress() {
1360 mBackKeyPressCounter = 0;
1361 }
1362
Jeff Brownd5bb82d2011-10-12 13:57:59 -07001363 private void cancelPendingPowerKeyAction() {
1364 if (!mPowerKeyHandled) {
Jeff Brown13f00f02014-10-31 14:45:50 -07001365 mPowerKeyHandled = true;
1366 mHandler.removeMessages(MSG_POWER_LONG_PRESS);
Jeff Brownd5bb82d2011-10-12 13:57:59 -07001367 }
Jeff Brown13f00f02014-10-31 14:45:50 -07001368 }
1369
Anthony Hugh34f09ca2016-03-04 12:03:37 -08001370 private void cancelPendingBackKeyAction() {
1371 if (!mBackKeyHandled) {
1372 mBackKeyHandled = true;
1373 mHandler.removeMessages(MSG_BACK_LONG_PRESS);
1374 }
1375 }
1376
Anthony Hugh96e9cc52016-07-12 15:17:24 -07001377 private void backMultiPressAction(long eventTime, int count) {
1378 if (count >= PANIC_PRESS_BACK_COUNT) {
1379 switch (mPanicPressOnBackBehavior) {
1380 case PANIC_PRESS_BACK_NOTHING:
1381 break;
1382 case PANIC_PRESS_BACK_HOME:
1383 launchHomeFromHotKey();
1384 break;
1385 }
1386 }
1387 }
1388
Jeff Brown13f00f02014-10-31 14:45:50 -07001389 private void powerPress(long eventTime, boolean interactive, int count) {
1390 if (mScreenOnEarly && !mScreenOnFully) {
1391 Slog.i(TAG, "Suppressed redundant power key press while "
1392 + "already in the process of turning the screen on.");
1393 return;
Jeff Brownff204712011-10-25 21:27:54 -07001394 }
Jeff Brown13f00f02014-10-31 14:45:50 -07001395
1396 if (count == 2) {
1397 powerMultiPressAction(eventTime, interactive, mDoublePressOnPowerBehavior);
1398 } else if (count == 3) {
1399 powerMultiPressAction(eventTime, interactive, mTriplePressOnPowerBehavior);
Bryce Leed9268e32014-11-17 17:40:59 -08001400 } else if (interactive && !mBeganFromNonInteractive) {
Jeff Brown13f00f02014-10-31 14:45:50 -07001401 switch (mShortPressOnPowerBehavior) {
1402 case SHORT_PRESS_POWER_NOTHING:
1403 break;
1404 case SHORT_PRESS_POWER_GO_TO_SLEEP:
1405 mPowerManager.goToSleep(eventTime,
1406 PowerManager.GO_TO_SLEEP_REASON_POWER_BUTTON, 0);
1407 break;
1408 case SHORT_PRESS_POWER_REALLY_GO_TO_SLEEP:
1409 mPowerManager.goToSleep(eventTime,
1410 PowerManager.GO_TO_SLEEP_REASON_POWER_BUTTON,
1411 PowerManager.GO_TO_SLEEP_FLAG_NO_DOZE);
1412 break;
1413 case SHORT_PRESS_POWER_REALLY_GO_TO_SLEEP_AND_GO_HOME:
1414 mPowerManager.goToSleep(eventTime,
1415 PowerManager.GO_TO_SLEEP_REASON_POWER_BUTTON,
1416 PowerManager.GO_TO_SLEEP_FLAG_NO_DOZE);
1417 launchHomeFromHotKey();
1418 break;
Bryce Lee01b0c5f2015-02-05 18:24:04 -08001419 case SHORT_PRESS_POWER_GO_HOME:
Andrew Zengb4045d32017-03-16 17:25:07 -07001420 shortPressPowerGoHome();
Bryce Lee01b0c5f2015-02-05 18:24:04 -08001421 break;
Yohei Yukawad6475a62017-04-17 10:35:27 -07001422 case SHORT_PRESS_POWER_CLOSE_IME_OR_GO_HOME: {
Yohei Yukawaabbe1ac2017-04-18 09:43:05 -07001423 if (mDismissImeOnBackKeyPressed) {
Yohei Yukawad6475a62017-04-17 10:35:27 -07001424 if (mInputMethodManagerInternal == null) {
1425 mInputMethodManagerInternal =
1426 LocalServices.getService(InputMethodManagerInternal.class);
1427 }
1428 if (mInputMethodManagerInternal != null) {
1429 mInputMethodManagerInternal.hideCurrentInputMethod();
1430 }
1431 } else {
Andrew Zengb4045d32017-03-16 17:25:07 -07001432 shortPressPowerGoHome();
Yohei Yukawad6475a62017-04-17 10:35:27 -07001433 }
1434 break;
1435 }
Jeff Brown13f00f02014-10-31 14:45:50 -07001436 }
1437 }
1438 }
1439
Andrew Zengb4045d32017-03-16 17:25:07 -07001440 private void shortPressPowerGoHome() {
1441 launchHomeFromHotKey(true /* awakenFromDreams */, false /*respectKeyguard*/);
1442 if (isKeyguardShowingAndNotOccluded()) {
1443 // Notify keyguard so it can do any special handling for the power button since the
1444 // device will not power off and only launch home.
1445 mKeyguardDelegate.onShortPowerPressedGoHome();
1446 }
1447 }
1448
Jeff Brown13f00f02014-10-31 14:45:50 -07001449 private void powerMultiPressAction(long eventTime, boolean interactive, int behavior) {
1450 switch (behavior) {
1451 case MULTI_PRESS_POWER_NOTHING:
1452 break;
1453 case MULTI_PRESS_POWER_THEATER_MODE:
Bryce Lee3ae447e2015-06-30 12:31:41 -07001454 if (!isUserSetupComplete()) {
1455 Slog.i(TAG, "Ignoring toggling theater mode - device not setup.");
1456 break;
1457 }
1458
Jeff Brown13f00f02014-10-31 14:45:50 -07001459 if (isTheaterModeEnabled()) {
1460 Slog.i(TAG, "Toggling theater mode off.");
1461 Settings.Global.putInt(mContext.getContentResolver(),
1462 Settings.Global.THEATER_MODE_ON, 0);
1463 if (!interactive) {
1464 wakeUpFromPowerKey(eventTime);
1465 }
1466 } else {
1467 Slog.i(TAG, "Toggling theater mode on.");
1468 Settings.Global.putInt(mContext.getContentResolver(),
1469 Settings.Global.THEATER_MODE_ON, 1);
Bryce Lee55e846d2014-11-04 12:43:44 -08001470
1471 if (mGoToSleepOnButtonPressTheaterMode && interactive) {
Jeff Brown13f00f02014-10-31 14:45:50 -07001472 mPowerManager.goToSleep(eventTime,
1473 PowerManager.GO_TO_SLEEP_REASON_POWER_BUTTON, 0);
1474 }
1475 }
1476 break;
1477 case MULTI_PRESS_POWER_BRIGHTNESS_BOOST:
Jeff Brown7b5be5e2014-11-12 18:45:31 -08001478 Slog.i(TAG, "Starting brightness boost.");
1479 if (!interactive) {
1480 wakeUpFromPowerKey(eventTime);
1481 }
Jeff Brown13f00f02014-10-31 14:45:50 -07001482 mPowerManager.boostScreenBrightness(eventTime);
1483 break;
1484 }
1485 }
1486
1487 private int getMaxMultiPressPowerCount() {
1488 if (mTriplePressOnPowerBehavior != MULTI_PRESS_POWER_NOTHING) {
1489 return 3;
1490 }
1491 if (mDoublePressOnPowerBehavior != MULTI_PRESS_POWER_NOTHING) {
1492 return 2;
1493 }
1494 return 1;
1495 }
1496
1497 private void powerLongPress() {
1498 final int behavior = getResolvedLongPressOnPowerBehavior();
1499 switch (behavior) {
1500 case LONG_PRESS_POWER_NOTHING:
1501 break;
1502 case LONG_PRESS_POWER_GLOBAL_ACTIONS:
1503 mPowerKeyHandled = true;
Phil Weaver106fe732016-11-22 18:18:39 -08001504 performHapticFeedbackLw(null, HapticFeedbackConstants.LONG_PRESS, false);
Jeff Brown13f00f02014-10-31 14:45:50 -07001505 showGlobalActionsInternal();
1506 break;
1507 case LONG_PRESS_POWER_SHUT_OFF:
1508 case LONG_PRESS_POWER_SHUT_OFF_NO_CONFIRM:
1509 mPowerKeyHandled = true;
1510 performHapticFeedbackLw(null, HapticFeedbackConstants.LONG_PRESS, false);
1511 sendCloseSystemWindows(SYSTEM_DIALOG_REASON_GLOBAL_ACTIONS);
1512 mWindowManagerFuncs.shutdown(behavior == LONG_PRESS_POWER_SHUT_OFF);
1513 break;
1514 }
1515 }
1516
Anthony Hugh34f09ca2016-03-04 12:03:37 -08001517 private void backLongPress() {
1518 mBackKeyHandled = true;
1519
1520 switch (mLongPressOnBackBehavior) {
1521 case LONG_PRESS_BACK_NOTHING:
1522 break;
1523 case LONG_PRESS_BACK_GO_TO_VOICE_ASSIST:
Nancy Zheng0d85ee22016-09-29 09:15:56 -07001524 final boolean keyguardActive = mKeyguardDelegate == null
1525 ? false
1526 : mKeyguardDelegate.isShowing();
1527 if (!keyguardActive) {
1528 Intent intent = new Intent(Intent.ACTION_VOICE_ASSIST);
1529 startActivityAsUser(intent, UserHandle.CURRENT_OR_SELF);
1530 }
Anthony Hugh34f09ca2016-03-04 12:03:37 -08001531 break;
1532 }
1533 }
1534
Phil Weaver106fe732016-11-22 18:18:39 -08001535 private void accessibilityShortcutActivated() {
1536 mAccessibilityShortcutController.performAccessibilityShortcut();
1537 }
1538
Chong Zhang9f7fb092016-05-20 17:03:08 -07001539 private void disposeInputConsumer(InputConsumer inputConsumer) {
1540 if (inputConsumer != null) {
1541 inputConsumer.dismiss();
1542 }
1543 }
1544
Nick Vaccarob593a812015-05-15 11:23:05 -07001545 private void sleepPress(long eventTime) {
1546 if (mShortPressOnSleepBehavior == SHORT_PRESS_SLEEP_GO_TO_SLEEP_AND_GO_HOME) {
1547 launchHomeFromHotKey(false /* awakenDreams */, true /*respectKeyguard*/);
1548 }
1549 }
1550
1551 private void sleepRelease(long eventTime) {
Filip Gruszczynskia483a1d2015-03-17 19:06:58 +00001552 switch (mShortPressOnSleepBehavior) {
1553 case SHORT_PRESS_SLEEP_GO_TO_SLEEP:
Filip Gruszczynskia483a1d2015-03-17 19:06:58 +00001554 case SHORT_PRESS_SLEEP_GO_TO_SLEEP_AND_GO_HOME:
Nick Vaccarob593a812015-05-15 11:23:05 -07001555 Slog.i(TAG, "sleepRelease() calling goToSleep(GO_TO_SLEEP_REASON_SLEEP_BUTTON)");
1556 mPowerManager.goToSleep(eventTime,
1557 PowerManager.GO_TO_SLEEP_REASON_SLEEP_BUTTON, 0);
Filip Gruszczynskia483a1d2015-03-17 19:06:58 +00001558 break;
1559 }
1560 }
1561
Jeff Brown13f00f02014-10-31 14:45:50 -07001562 private int getResolvedLongPressOnPowerBehavior() {
1563 if (FactoryTest.isLongPressOnPowerOffEnabled()) {
1564 return LONG_PRESS_POWER_SHUT_OFF_NO_CONFIRM;
1565 }
1566 return mLongPressOnPowerBehavior;
1567 }
1568
1569 private boolean hasLongPressOnPowerBehavior() {
1570 return getResolvedLongPressOnPowerBehavior() != LONG_PRESS_POWER_NOTHING;
Jeff Brownd5bb82d2011-10-12 13:57:59 -07001571 }
1572
Anthony Hugh34f09ca2016-03-04 12:03:37 -08001573 private boolean hasLongPressOnBackBehavior() {
1574 return mLongPressOnBackBehavior != LONG_PRESS_BACK_NOTHING;
1575 }
1576
Anthony Hugh96e9cc52016-07-12 15:17:24 -07001577 private boolean hasPanicPressOnBackBehavior() {
1578 return mPanicPressOnBackBehavior != PANIC_PRESS_BACK_NOTHING;
1579 }
1580
Jeff Brownd5bb82d2011-10-12 13:57:59 -07001581 private void interceptScreenshotChord() {
Christopher Tatee90585f2012-03-05 18:56:25 -08001582 if (mScreenshotChordEnabled
Jeff Brown13f00f02014-10-31 14:45:50 -07001583 && mScreenshotChordVolumeDownKeyTriggered && mScreenshotChordPowerKeyTriggered
Phil Weaver106fe732016-11-22 18:18:39 -08001584 && !mA11yShortcutChordVolumeUpKeyTriggered) {
Jeff Brownd5bb82d2011-10-12 13:57:59 -07001585 final long now = SystemClock.uptimeMillis();
Jeff Brown13f00f02014-10-31 14:45:50 -07001586 if (now <= mScreenshotChordVolumeDownKeyTime + SCREENSHOT_CHORD_DEBOUNCE_DELAY_MILLIS
1587 && now <= mScreenshotChordPowerKeyTime
1588 + SCREENSHOT_CHORD_DEBOUNCE_DELAY_MILLIS) {
1589 mScreenshotChordVolumeDownKeyConsumed = true;
Jeff Brownd5bb82d2011-10-12 13:57:59 -07001590 cancelPendingPowerKeyAction();
Muyuan Li6ca619f2016-03-08 13:30:42 -08001591 mScreenshotRunnable.setScreenshotType(TAKE_SCREENSHOT_FULLSCREEN);
Jeff Sharkey2991fa32012-12-05 18:06:43 -08001592 mHandler.postDelayed(mScreenshotRunnable, getScreenshotChordLongPressDelay());
Jeff Brownd5bb82d2011-10-12 13:57:59 -07001593 }
1594 }
1595 }
1596
Phil Weaver106fe732016-11-22 18:18:39 -08001597 private void interceptAccessibilityShortcutChord() {
Phil Weaverce687c52017-03-15 08:51:52 -07001598 if (mAccessibilityShortcutController.isAccessibilityShortcutAvailable(isKeyguardLocked())
Phil Weaver106fe732016-11-22 18:18:39 -08001599 && mScreenshotChordVolumeDownKeyTriggered && mA11yShortcutChordVolumeUpKeyTriggered
1600 && !mScreenshotChordPowerKeyTriggered) {
1601 final long now = SystemClock.uptimeMillis();
1602 if (now <= mScreenshotChordVolumeDownKeyTime + SCREENSHOT_CHORD_DEBOUNCE_DELAY_MILLIS
1603 && now <= mA11yShortcutChordVolumeUpKeyTime
1604 + SCREENSHOT_CHORD_DEBOUNCE_DELAY_MILLIS) {
1605 mScreenshotChordVolumeDownKeyConsumed = true;
1606 mA11yShortcutChordVolumeUpKeyConsumed = true;
1607 mHandler.sendMessageDelayed(mHandler.obtainMessage(MSG_ACCESSIBILITY_SHORTCUT),
1608 ViewConfiguration.get(mContext).getAccessibilityShortcutKeyTimeout());
1609 }
1610 }
1611 }
1612
Winson Chung1cea2f32012-10-08 20:42:01 -07001613 private long getScreenshotChordLongPressDelay() {
Jim Miller5ecd8112013-01-09 18:50:26 -08001614 if (mKeyguardDelegate.isShowing()) {
Winson Chung1cea2f32012-10-08 20:42:01 -07001615 // Double the time it takes to take a screenshot from the keyguard
1616 return (long) (KEYGUARD_SCREENSHOT_CHORD_DELAY_MULTIPLIER *
Justin Kohfeabd2c2014-05-02 10:02:44 -07001617 ViewConfiguration.get(mContext).getDeviceGlobalActionKeyTimeout());
Winson Chung1cea2f32012-10-08 20:42:01 -07001618 }
Justin Kohfeabd2c2014-05-02 10:02:44 -07001619 return ViewConfiguration.get(mContext).getDeviceGlobalActionKeyTimeout();
Winson Chung1cea2f32012-10-08 20:42:01 -07001620 }
1621
Jeff Brownd5bb82d2011-10-12 13:57:59 -07001622 private void cancelPendingScreenshotChordAction() {
Jeff Sharkey2991fa32012-12-05 18:06:43 -08001623 mHandler.removeCallbacks(mScreenshotRunnable);
Jeff Brown4d396052010-10-29 21:50:21 -07001624 }
1625
Phil Weaver106fe732016-11-22 18:18:39 -08001626 private void cancelPendingAccessibilityShortcutAction() {
1627 mHandler.removeMessages(MSG_ACCESSIBILITY_SHORTCUT);
1628 }
1629
Jeff Brown13f00f02014-10-31 14:45:50 -07001630 private final Runnable mEndCallLongPress = new Runnable() {
Craig Mautnerf1b67412012-09-19 13:18:29 -07001631 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001632 public void run() {
Jeff Brown13f00f02014-10-31 14:45:50 -07001633 mEndCallKeyHandled = true;
Phil Weaver106fe732016-11-22 18:18:39 -08001634 performHapticFeedbackLw(null, HapticFeedbackConstants.LONG_PRESS, false);
Jeff Brown13f00f02014-10-31 14:45:50 -07001635 showGlobalActionsInternal();
Jeff Brownd5bb82d2011-10-12 13:57:59 -07001636 }
1637 };
1638
Muyuan Li6ca619f2016-03-08 13:30:42 -08001639 private class ScreenshotRunnable implements Runnable {
1640 private int mScreenshotType = TAKE_SCREENSHOT_FULLSCREEN;
1641
1642 public void setScreenshotType(int screenshotType) {
1643 mScreenshotType = screenshotType;
1644 }
1645
Craig Mautner0bf6ec92012-12-18 08:33:27 -08001646 @Override
Jeff Brownd5bb82d2011-10-12 13:57:59 -07001647 public void run() {
Muyuan Li6ca619f2016-03-08 13:30:42 -08001648 takeScreenshot(mScreenshotType);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001649 }
Muyuan Li6ca619f2016-03-08 13:30:42 -08001650 }
1651
1652 private final ScreenshotRunnable mScreenshotRunnable = new ScreenshotRunnable();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001653
Alan Viverettee34560b22014-07-10 14:50:06 -07001654 @Override
1655 public void showGlobalActions() {
1656 mHandler.removeMessages(MSG_DISPATCH_SHOW_GLOBAL_ACTIONS);
1657 mHandler.sendEmptyMessage(MSG_DISPATCH_SHOW_GLOBAL_ACTIONS);
1658 }
1659
1660 void showGlobalActionsInternal() {
1661 sendCloseSystemWindows(SYSTEM_DIALOG_REASON_GLOBAL_ACTIONS);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001662 if (mGlobalActions == null) {
Jeff Brown7304c342012-05-11 18:42:42 -07001663 mGlobalActions = new GlobalActions(mContext, mWindowManagerFuncs);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001664 }
Jim Millerab954542014-10-10 18:21:49 -07001665 final boolean keyguardShowing = isKeyguardShowingAndNotOccluded();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001666 mGlobalActions.showDialog(keyguardShowing, isDeviceProvisioned());
1667 if (keyguardShowing) {
1668 // since it took two seconds of long press to bring this up,
1669 // poke the wake lock so they have some time to see the dialog.
Jim Miller25190572013-02-28 17:36:24 -08001670 mPowerManager.userActivity(SystemClock.uptimeMillis(), false);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001671 }
1672 }
1673
1674 boolean isDeviceProvisioned() {
Jeff Brownbf6f6f92012-09-25 15:03:20 -07001675 return Settings.Global.getInt(
1676 mContext.getContentResolver(), Settings.Global.DEVICE_PROVISIONED, 0) != 0;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001677 }
1678
Maurice Lam99c6e072014-04-28 18:24:28 -07001679 boolean isUserSetupComplete() {
Sujith Ramakrishnan0390fff2017-06-08 18:18:12 -07001680 boolean isSetupComplete = Settings.Secure.getIntForUser(mContext.getContentResolver(),
Maurice Lam99c6e072014-04-28 18:24:28 -07001681 Settings.Secure.USER_SETUP_COMPLETE, 0, UserHandle.USER_CURRENT) != 0;
Sujith Ramakrishnan0390fff2017-06-08 18:18:12 -07001682 if (mHasFeatureLeanback) {
1683 isSetupComplete &= isTvUserSetupComplete();
1684 }
1685 return isSetupComplete;
1686 }
1687
1688 private boolean isTvUserSetupComplete() {
1689 return Settings.Secure.getIntForUser(mContext.getContentResolver(),
1690 Settings.Secure.TV_USER_SETUP_COMPLETE, 0, UserHandle.USER_CURRENT) != 0;
Maurice Lam99c6e072014-04-28 18:24:28 -07001691 }
1692
Jeff Brown13f00f02014-10-31 14:45:50 -07001693 private void handleShortPressOnHome() {
Jinsuk Kime601b712015-07-07 08:01:02 +09001694 // Turn on the connected TV and switch HDMI input if we're a HDMI playback device.
Andrii Kulianeb4a7942016-12-21 12:18:05 -08001695 final HdmiControl hdmiControl = getHdmiControl();
1696 if (hdmiControl != null) {
1697 hdmiControl.turnOnTv();
1698 }
Jinsuk Kime601b712015-07-07 08:01:02 +09001699
Jeff Brown13f00f02014-10-31 14:45:50 -07001700 // If there's a dream running then use home to escape the dream
1701 // but don't actually go home.
1702 if (mDreamManagerInternal != null && mDreamManagerInternal.isDreaming()) {
1703 mDreamManagerInternal.stopDream(false /*immediate*/);
1704 return;
1705 }
1706
1707 // Go home!
1708 launchHomeFromHotKey();
1709 }
1710
Jinsuk Kime601b712015-07-07 08:01:02 +09001711 /**
1712 * Creates an accessor to HDMI control service that performs the operation of
1713 * turning on TV (optional) and switching input to us. If HDMI control service
1714 * is not available or we're not a HDMI playback device, the operation is no-op.
Andrii Kulianeb4a7942016-12-21 12:18:05 -08001715 * @return {@link HdmiControl} instance if available, null otherwise.
Jinsuk Kime601b712015-07-07 08:01:02 +09001716 */
1717 private HdmiControl getHdmiControl() {
1718 if (null == mHdmiControl) {
Andrii Kulianeb4a7942016-12-21 12:18:05 -08001719 if (!mContext.getPackageManager().hasSystemFeature(PackageManager.FEATURE_HDMI_CEC)) {
1720 return null;
1721 }
Jinsuk Kime601b712015-07-07 08:01:02 +09001722 HdmiControlManager manager = (HdmiControlManager) mContext.getSystemService(
1723 Context.HDMI_CONTROL_SERVICE);
1724 HdmiPlaybackClient client = null;
1725 if (manager != null) {
1726 client = manager.getPlaybackClient();
1727 }
1728 mHdmiControl = new HdmiControl(client);
1729 }
1730 return mHdmiControl;
1731 }
1732
1733 private static class HdmiControl {
1734 private final HdmiPlaybackClient mClient;
1735
1736 private HdmiControl(HdmiPlaybackClient client) {
1737 mClient = client;
1738 }
1739
1740 public void turnOnTv() {
1741 if (mClient == null) {
1742 return;
1743 }
1744 mClient.oneTouchPlay(new OneTouchPlayCallback() {
1745 @Override
1746 public void onComplete(int result) {
1747 if (result != HdmiControlManager.RESULT_SUCCESS) {
1748 Log.w(TAG, "One touch play failed: " + result);
1749 }
1750 }
1751 });
1752 }
1753 }
1754
Jaewan Kim76b7d0d2016-02-12 19:01:02 +09001755 private void handleLongPressOnHome(int deviceId) {
Jaewan Kim52632e22016-01-14 18:01:52 +09001756 if (mLongPressOnHomeBehavior == LONG_PRESS_HOME_NOTHING) {
1757 return;
1758 }
1759 mHomeConsumed = true;
1760 performHapticFeedbackLw(null, HapticFeedbackConstants.LONG_PRESS, false);
Jaewan Kim52632e22016-01-14 18:01:52 +09001761 switch (mLongPressOnHomeBehavior) {
Sid Soundararajanff662fa2017-03-15 16:24:24 -07001762 case LONG_PRESS_HOME_ALL_APPS:
1763 launchAllAppsAction();
Jaewan Kim52632e22016-01-14 18:01:52 +09001764 break;
1765 case LONG_PRESS_HOME_ASSIST:
Tim Kilbourn0e5f1102015-06-05 16:18:09 -07001766 launchAssistAction(null, deviceId);
Jaewan Kim52632e22016-01-14 18:01:52 +09001767 break;
Jaewan Kim52632e22016-01-14 18:01:52 +09001768 default:
Jaewan Kim76b7d0d2016-02-12 19:01:02 +09001769 Log.w(TAG, "Undefined home long press behavior: " + mLongPressOnHomeBehavior);
Jaewan Kim52632e22016-01-14 18:01:52 +09001770 break;
Jim Millere6ad1a82010-08-20 19:25:39 -07001771 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001772 }
Patrick Dubroyece94522011-02-23 18:35:01 -08001773
Sid Soundararajanff662fa2017-03-15 16:24:24 -07001774 private void launchAllAppsAction() {
1775 Intent intent = new Intent(Intent.ACTION_ALL_APPS);
1776 startActivityAsUser(intent, UserHandle.CURRENT);
1777 }
1778
Jeff Browncaca8812013-05-09 13:34:33 -07001779 private void handleDoubleTapOnHome() {
1780 if (mDoubleTapOnHomeBehavior == DOUBLE_TAP_HOME_RECENT_SYSTEM_UI) {
1781 mHomeConsumed = true;
1782 toggleRecentApps();
1783 }
1784 }
1785
Winson Chungac52f282017-03-30 14:44:52 -07001786 private void showPictureInPictureMenu(KeyEvent event) {
1787 if (DEBUG_INPUT) Log.d(TAG, "showPictureInPictureMenu event=" + event);
1788 mHandler.removeMessages(MSG_SHOW_PICTURE_IN_PICTURE_MENU);
1789 Message msg = mHandler.obtainMessage(MSG_SHOW_PICTURE_IN_PICTURE_MENU);
Jaewan Kimc552b042016-01-18 16:08:45 +09001790 msg.setAsynchronous(true);
1791 msg.sendToTarget();
1792 }
1793
Winson Chungac52f282017-03-30 14:44:52 -07001794 private void showPictureInPictureMenuInternal() {
Jaewan Kimf0fd2182016-04-20 21:17:58 +09001795 StatusBarManagerInternal statusbar = getStatusBarManagerInternal();
1796 if (statusbar != null) {
Winson Chungac52f282017-03-30 14:44:52 -07001797 statusbar.showPictureInPictureMenu();
Jaewan Kimc552b042016-01-18 16:08:45 +09001798 }
Jaewan Kim52632e22016-01-14 18:01:52 +09001799 }
1800
Jeff Browncaca8812013-05-09 13:34:33 -07001801 private final Runnable mHomeDoubleTapTimeoutRunnable = new Runnable() {
1802 @Override
1803 public void run() {
1804 if (mHomeDoubleTapPending) {
1805 mHomeDoubleTapPending = false;
Jeff Brown13f00f02014-10-31 14:45:50 -07001806 handleShortPressOnHome();
Jeff Browncaca8812013-05-09 13:34:33 -07001807 }
1808 }
1809 };
1810
Mark Renoufc1256912015-03-11 14:38:23 -04001811 private boolean isRoundWindow() {
Adam Powell01f280d2015-05-18 16:07:42 -07001812 return mContext.getResources().getConfiguration().isScreenRound();
Mark Renoufc1256912015-03-11 14:38:23 -04001813 }
1814
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001815 /** {@inheritDoc} */
Craig Mautner0bf6ec92012-12-18 08:33:27 -08001816 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001817 public void init(Context context, IWindowManager windowManager,
Jeff Brown96307042012-07-27 15:51:34 -07001818 WindowManagerFuncs windowManagerFuncs) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001819 mContext = context;
1820 mWindowManager = windowManager;
Dianne Hackborndf89e652011-10-06 22:35:11 -07001821 mWindowManagerFuncs = windowManagerFuncs;
Craig Mautner8a0da012014-05-31 15:13:37 -07001822 mWindowManagerInternal = LocalServices.getService(WindowManagerInternal.class);
Jeff Brown061ea992015-04-17 19:55:47 -07001823 mActivityManagerInternal = LocalServices.getService(ActivityManagerInternal.class);
Andrii Kulian112d0562016-03-08 10:44:22 -08001824 mInputManagerInternal = LocalServices.getService(InputManagerInternal.class);
Jose Lima9546b202014-07-02 17:21:51 -07001825 mDreamManagerInternal = LocalServices.getService(DreamManagerInternal.class);
Michael Wrighta4d22d72015-09-16 23:19:26 +01001826 mPowerManagerInternal = LocalServices.getService(PowerManagerInternal.class);
Billy Laucbe540f2015-06-25 01:51:44 +01001827 mAppOpsManager = (AppOpsManager) mContext.getSystemService(Context.APP_OPS_SERVICE);
Wale Ogunwale6b15ea52016-04-04 07:28:27 -07001828 mHasFeatureWatch = mContext.getPackageManager().hasSystemFeature(FEATURE_WATCH);
Dmitri Plotnikov82e6dfc2017-02-24 18:10:54 -08001829 mHasFeatureLeanback = mContext.getPackageManager().hasSystemFeature(FEATURE_LEANBACK);
Phil Weaver106fe732016-11-22 18:18:39 -08001830 mAccessibilityShortcutController =
Phil Weaverce687c52017-03-15 08:51:52 -07001831 new AccessibilityShortcutController(mContext, new Handler(), mCurrentUserId);
Mark Renoufc1256912015-03-11 14:38:23 -04001832 // Init display burn-in protection
1833 boolean burnInProtectionEnabled = context.getResources().getBoolean(
1834 com.android.internal.R.bool.config_enableBurnInProtection);
1835 // Allow a system property to override this. Used by developer settings.
1836 boolean burnInProtectionDevMode =
1837 SystemProperties.getBoolean("persist.debug.force_burn_in", false);
1838 if (burnInProtectionEnabled || burnInProtectionDevMode) {
1839 final int minHorizontal;
1840 final int maxHorizontal;
1841 final int minVertical;
1842 final int maxVertical;
1843 final int maxRadius;
1844 if (burnInProtectionDevMode) {
1845 minHorizontal = -8;
1846 maxHorizontal = 8;
1847 minVertical = -8;
1848 maxVertical = -4;
1849 maxRadius = (isRoundWindow()) ? 6 : -1;
1850 } else {
1851 Resources resources = context.getResources();
1852 minHorizontal = resources.getInteger(
1853 com.android.internal.R.integer.config_burnInProtectionMinHorizontalOffset);
1854 maxHorizontal = resources.getInteger(
1855 com.android.internal.R.integer.config_burnInProtectionMaxHorizontalOffset);
1856 minVertical = resources.getInteger(
1857 com.android.internal.R.integer.config_burnInProtectionMinVerticalOffset);
1858 maxVertical = resources.getInteger(
1859 com.android.internal.R.integer.config_burnInProtectionMaxVerticalOffset);
1860 maxRadius = resources.getInteger(
1861 com.android.internal.R.integer.config_burnInProtectionMaxRadius);
1862 }
1863 mBurnInProtectionHelper = new BurnInProtectionHelper(
1864 context, minHorizontal, maxHorizontal, minVertical, maxVertical, maxRadius);
Filip Gruszczynskicfb31852015-02-25 21:47:12 +00001865 }
Craig Mautner8a0da012014-05-31 15:13:37 -07001866
Jeff Brown70825162012-03-28 17:27:48 -07001867 mHandler = new PolicyHandler();
Jeff Browna20dda42014-05-27 20:57:24 -07001868 mWakeGestureListener = new MyWakeGestureListener(mContext, mHandler);
Craig Mautnereee29c42013-01-17 14:44:34 -08001869 mOrientationListener = new MyOrientationListener(mContext, mHandler);
Jeff Brownc0347aa2011-09-23 17:26:09 -07001870 try {
Andrii Kulian8ee72852017-03-10 10:36:45 -08001871 mOrientationListener.setCurrentRotation(windowManager.getDefaultDisplayRotation());
Jeff Brownc0347aa2011-09-23 17:26:09 -07001872 } catch (RemoteException ex) { }
Christopher Tate5e08af02012-09-21 17:17:22 -07001873 mSettingsObserver = new SettingsObserver(mHandler);
1874 mSettingsObserver.observe();
Svetoslav683914b2015-01-15 14:22:26 -08001875 mShortcutManager = new ShortcutManager(context);
Daniel Sandler6396c722013-04-16 20:19:09 -04001876 mUiMode = context.getResources().getInteger(
1877 com.android.internal.R.integer.config_defaultUiModeType);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001878 mHomeIntent = new Intent(Intent.ACTION_MAIN, null);
1879 mHomeIntent.addCategory(Intent.CATEGORY_HOME);
1880 mHomeIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK
1881 | Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED);
keunyounga7710492015-09-23 11:33:58 -07001882 mEnableCarDockHomeCapture = context.getResources().getBoolean(
1883 com.android.internal.R.bool.config_enableCarDockHomeLaunch);
Dianne Hackborn39c2d712009-09-22 11:41:31 -07001884 mCarDockIntent = new Intent(Intent.ACTION_MAIN, null);
1885 mCarDockIntent.addCategory(Intent.CATEGORY_CAR_DOCK);
1886 mCarDockIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK
1887 | Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED);
1888 mDeskDockIntent = new Intent(Intent.ACTION_MAIN, null);
1889 mDeskDockIntent.addCategory(Intent.CATEGORY_DESK_DOCK);
1890 mDeskDockIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK
1891 | Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED);
Zak Cohendb6ca492017-01-26 14:09:00 -08001892 mVrHeadsetHomeIntent = new Intent(Intent.ACTION_MAIN, null);
1893 mVrHeadsetHomeIntent.addCategory(Intent.CATEGORY_VR_HOME);
1894 mVrHeadsetHomeIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK
1895 | Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED);
Jim Millere6ad1a82010-08-20 19:25:39 -07001896
Jeff Brown96307042012-07-27 15:51:34 -07001897 mPowerManager = (PowerManager)context.getSystemService(Context.POWER_SERVICE);
1898 mBroadcastWakeLock = mPowerManager.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK,
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001899 "PhoneWindowManager.mBroadcastWakeLock");
Jeff Brown13f00f02014-10-31 14:45:50 -07001900 mPowerKeyWakeLock = mPowerManager.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK,
1901 "PhoneWindowManager.mPowerKeyWakeLock");
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001902 mEnableShiftMenuBugReports = "1".equals(SystemProperties.get("ro.debuggable"));
Jeff Brownbcdfc622014-03-06 19:13:04 -08001903 mSupportAutoRotation = mContext.getResources().getBoolean(
1904 com.android.internal.R.bool.config_supportAutoRotation);
Dianne Hackborn2862fff2009-09-15 22:56:29 -07001905 mLidOpenRotation = readRotation(
Mike Lockwood2d1efbd2009-09-16 12:15:53 -04001906 com.android.internal.R.integer.config_lidOpenRotation);
1907 mCarDockRotation = readRotation(
1908 com.android.internal.R.integer.config_carDockRotation);
1909 mDeskDockRotation = readRotation(
1910 com.android.internal.R.integer.config_deskDockRotation);
Jeff Brownc82c89ed2013-04-17 17:18:15 -07001911 mUndockedHdmiRotation = readRotation(
1912 com.android.internal.R.integer.config_undockedHdmiRotation);
Mike Lockwoode9867d22009-09-20 01:59:02 -04001913 mCarDockEnablesAccelerometer = mContext.getResources().getBoolean(
1914 com.android.internal.R.bool.config_carDockEnablesAccelerometer);
1915 mDeskDockEnablesAccelerometer = mContext.getResources().getBoolean(
1916 com.android.internal.R.bool.config_deskDockEnablesAccelerometer);
Dianne Hackborn2862fff2009-09-15 22:56:29 -07001917 mLidKeyboardAccessibility = mContext.getResources().getInteger(
1918 com.android.internal.R.integer.config_lidKeyboardAccessibility);
1919 mLidNavigationAccessibility = mContext.getResources().getInteger(
1920 com.android.internal.R.integer.config_lidNavigationAccessibility);
Edward Savage-Jones7def60d2015-11-13 13:27:03 +01001921 mLidControlsScreenLock = mContext.getResources().getBoolean(
1922 com.android.internal.R.bool.config_lidControlsScreenLock);
Jeff Brownc458ce92012-04-30 14:58:40 -07001923 mLidControlsSleep = mContext.getResources().getBoolean(
1924 com.android.internal.R.bool.config_lidControlsSleep);
Daniel Sandlerdd73ee42013-10-11 22:19:59 -04001925 mTranslucentDecorEnabled = mContext.getResources().getBoolean(
1926 com.android.internal.R.bool.config_enableTranslucentDecor);
Bryce Lee584a4452014-10-21 15:55:55 -07001927
1928 mAllowTheaterModeWakeFromKey = mContext.getResources().getBoolean(
1929 com.android.internal.R.bool.config_allowTheaterModeWakeFromKey);
1930 mAllowTheaterModeWakeFromPowerKey = mAllowTheaterModeWakeFromKey
1931 || mContext.getResources().getBoolean(
1932 com.android.internal.R.bool.config_allowTheaterModeWakeFromPowerKey);
1933 mAllowTheaterModeWakeFromMotion = mContext.getResources().getBoolean(
1934 com.android.internal.R.bool.config_allowTheaterModeWakeFromMotion);
Bryce Lee812d7022014-11-10 13:33:28 -08001935 mAllowTheaterModeWakeFromMotionWhenNotDreaming = mContext.getResources().getBoolean(
1936 com.android.internal.R.bool.config_allowTheaterModeWakeFromMotionWhenNotDreaming);
Bryce Lee584a4452014-10-21 15:55:55 -07001937 mAllowTheaterModeWakeFromCameraLens = mContext.getResources().getBoolean(
1938 com.android.internal.R.bool.config_allowTheaterModeWakeFromCameraLens);
1939 mAllowTheaterModeWakeFromLidSwitch = mContext.getResources().getBoolean(
1940 com.android.internal.R.bool.config_allowTheaterModeWakeFromLidSwitch);
1941 mAllowTheaterModeWakeFromWakeGesture = mContext.getResources().getBoolean(
1942 com.android.internal.R.bool.config_allowTheaterModeWakeFromGesture);
1943
Bryce Lee55e846d2014-11-04 12:43:44 -08001944 mGoToSleepOnButtonPressTheaterMode = mContext.getResources().getBoolean(
1945 com.android.internal.R.bool.config_goToSleepOnButtonPressTheaterMode);
1946
Bryce Leed3b28402015-03-09 15:49:13 +00001947 mSupportLongPressPowerWhenNonInteractive = mContext.getResources().getBoolean(
1948 com.android.internal.R.bool.config_supportLongPressPowerWhenNonInteractive);
1949
Anthony Hugh34f09ca2016-03-04 12:03:37 -08001950 mLongPressOnBackBehavior = mContext.getResources().getInteger(
1951 com.android.internal.R.integer.config_longPressOnBackBehavior);
Anthony Hugh96e9cc52016-07-12 15:17:24 -07001952 mPanicPressOnBackBehavior = mContext.getResources().getInteger(
1953 com.android.internal.R.integer.config_backPanicBehavior);
Anthony Hugh34f09ca2016-03-04 12:03:37 -08001954
Jeff Brown13f00f02014-10-31 14:45:50 -07001955 mShortPressOnPowerBehavior = mContext.getResources().getInteger(
1956 com.android.internal.R.integer.config_shortPressOnPowerBehavior);
1957 mLongPressOnPowerBehavior = mContext.getResources().getInteger(
1958 com.android.internal.R.integer.config_longPressOnPowerBehavior);
1959 mDoublePressOnPowerBehavior = mContext.getResources().getInteger(
1960 com.android.internal.R.integer.config_doublePressOnPowerBehavior);
1961 mTriplePressOnPowerBehavior = mContext.getResources().getInteger(
1962 com.android.internal.R.integer.config_triplePressOnPowerBehavior);
Filip Gruszczynskia483a1d2015-03-17 19:06:58 +00001963 mShortPressOnSleepBehavior = mContext.getResources().getInteger(
1964 com.android.internal.R.integer.config_shortPressOnSleepBehavior);
Jeff Brown13f00f02014-10-31 14:45:50 -07001965
John Spurlock61560172015-02-06 19:46:04 -05001966 mUseTvRouting = AudioSystem.getPlatformType(mContext) == AudioSystem.PLATFORM_TELEVISION;
RoboErik001c59c2015-01-26 15:53:51 -08001967
Karthik Ravi Shankar86ecf342017-04-28 15:35:58 -07001968 mHandleVolumeKeysInWM = mContext.getResources().getBoolean(
1969 com.android.internal.R.bool.config_handleVolumeKeysInWindowManager);
1970
Jeff Brownf71343d2013-05-31 17:59:11 -07001971 readConfigurationDependentBehaviors();
Jeff Browncaca8812013-05-09 13:34:33 -07001972
Svetoslav8e3feb12014-02-24 13:46:47 -08001973 mAccessibilityManager = (AccessibilityManager) context.getSystemService(
1974 Context.ACCESSIBILITY_SERVICE);
1975
Mike Lockwood1753f7f2009-08-24 14:49:07 -07001976 // register for dock events
Dianne Hackborn78968392010-03-04 20:47:56 -08001977 IntentFilter filter = new IntentFilter();
1978 filter.addAction(UiModeManager.ACTION_ENTER_CAR_MODE);
1979 filter.addAction(UiModeManager.ACTION_EXIT_CAR_MODE);
1980 filter.addAction(UiModeManager.ACTION_ENTER_DESK_MODE);
1981 filter.addAction(UiModeManager.ACTION_EXIT_DESK_MODE);
Dianne Hackborn867ab6472010-04-29 13:28:56 -07001982 filter.addAction(Intent.ACTION_DOCK_EVENT);
1983 Intent intent = context.registerReceiver(mDockReceiver, filter);
1984 if (intent != null) {
1985 // Retrieve current sticky dock event broadcast.
1986 mDockMode = intent.getIntExtra(Intent.EXTRA_DOCK_STATE,
1987 Intent.EXTRA_DOCK_STATE_UNDOCKED);
1988 }
Daniel Sandler7e37df52011-11-16 22:08:23 -08001989
Jeff Brown6aaf2952012-10-05 16:01:08 -07001990 // register for dream-related broadcasts
1991 filter = new IntentFilter();
1992 filter.addAction(Intent.ACTION_DREAMING_STARTED);
1993 filter.addAction(Intent.ACTION_DREAMING_STOPPED);
1994 context.registerReceiver(mDreamReceiver, filter);
1995
Christopher Tate5e08af02012-09-21 17:17:22 -07001996 // register for multiuser-relevant broadcasts
1997 filter = new IntentFilter(Intent.ACTION_USER_SWITCHED);
1998 context.registerReceiver(mMultiuserReceiver, filter);
1999
John Spurlock57306e62013-04-22 09:48:49 -04002000 // monitor for system gestures
Craig Mautner037aa8d2013-06-07 10:35:44 -07002001 mSystemGestures = new SystemGesturesPointerEventListener(context,
2002 new SystemGesturesPointerEventListener.Callbacks() {
John Spurlock57306e62013-04-22 09:48:49 -04002003 @Override
2004 public void onSwipeFromTop() {
John Spurlock04db1762013-05-13 12:46:41 -04002005 if (mStatusBar != null) {
John Spurlocke1f366f2013-08-05 12:22:40 -04002006 requestTransientBars(mStatusBar);
John Spurlock04db1762013-05-13 12:46:41 -04002007 }
John Spurlockad3e6cb2013-04-30 08:47:43 -04002008 }
2009 @Override
2010 public void onSwipeFromBottom() {
Adrian Roos85d202b2016-06-02 16:27:47 -07002011 if (mNavigationBar != null && mNavigationBarPosition == NAV_BAR_BOTTOM) {
John Spurlocke1f366f2013-08-05 12:22:40 -04002012 requestTransientBars(mNavigationBar);
John Spurlockad3e6cb2013-04-30 08:47:43 -04002013 }
2014 }
2015 @Override
2016 public void onSwipeFromRight() {
Adrian Roos85d202b2016-06-02 16:27:47 -07002017 if (mNavigationBar != null && mNavigationBarPosition == NAV_BAR_RIGHT) {
2018 requestTransientBars(mNavigationBar);
2019 }
2020 }
2021 @Override
2022 public void onSwipeFromLeft() {
2023 if (mNavigationBar != null && mNavigationBarPosition == NAV_BAR_LEFT) {
John Spurlocke1f366f2013-08-05 12:22:40 -04002024 requestTransientBars(mNavigationBar);
John Spurlockad3e6cb2013-04-30 08:47:43 -04002025 }
2026 }
2027 @Override
Michael Wrighta4d22d72015-09-16 23:19:26 +01002028 public void onFling(int duration) {
2029 if (mPowerManagerInternal != null) {
2030 mPowerManagerInternal.powerHint(
Ruchi Kandoi0d434042016-10-03 09:12:02 -07002031 PowerHint.INTERACTION, duration);
Michael Wrighta4d22d72015-09-16 23:19:26 +01002032 }
2033 }
2034 @Override
John Spurlockad3e6cb2013-04-30 08:47:43 -04002035 public void onDebug() {
John Spurlockd67ec252013-09-05 11:31:54 -04002036 // no-op
John Spurlockad3e6cb2013-04-30 08:47:43 -04002037 }
Adrian Roos3595be42015-03-05 16:31:15 +01002038 @Override
2039 public void onDown() {
2040 mOrientationListener.onTouchStart();
2041 }
2042 @Override
2043 public void onUpOrCancel() {
2044 mOrientationListener.onTouchEnd();
2045 }
Jun Mukaid2e7e352015-07-22 17:14:02 -07002046 @Override
2047 public void onMouseHoverAtTop() {
2048 mHandler.removeMessages(MSG_REQUEST_TRANSIENT_BARS);
2049 Message msg = mHandler.obtainMessage(MSG_REQUEST_TRANSIENT_BARS);
2050 msg.arg1 = MSG_REQUEST_TRANSIENT_BARS_ARG_STATUS;
2051 mHandler.sendMessageDelayed(msg, 500);
2052 }
2053 @Override
2054 public void onMouseHoverAtBottom() {
2055 mHandler.removeMessages(MSG_REQUEST_TRANSIENT_BARS);
2056 Message msg = mHandler.obtainMessage(MSG_REQUEST_TRANSIENT_BARS);
2057 msg.arg1 = MSG_REQUEST_TRANSIENT_BARS_ARG_NAVIGATION;
2058 mHandler.sendMessageDelayed(msg, 500);
2059 }
2060 @Override
2061 public void onMouseLeaveFromEdge() {
2062 mHandler.removeMessages(MSG_REQUEST_TRANSIENT_BARS);
2063 }
John Spurlockad3e6cb2013-04-30 08:47:43 -04002064 });
John Spurlockf1a36642013-10-12 17:50:42 -04002065 mImmersiveModeConfirmation = new ImmersiveModeConfirmation(mContext);
Craig Mautner037aa8d2013-06-07 10:35:44 -07002066 mWindowManagerFuncs.registerPointerEventListener(mSystemGestures);
John Spurlock32beb2c2013-03-11 10:16:47 -04002067
Jeff Brownc2346132012-04-13 01:55:38 -07002068 mVibrator = (Vibrator)context.getSystemService(Context.VIBRATOR_SERVICE);
Dianne Hackbornb1a79802009-09-29 15:18:31 -07002069 mLongPressVibePattern = getLongIntArray(mContext.getResources(),
2070 com.android.internal.R.array.config_longPressVibePattern);
Fabrice Di Megliobd9152f2013-10-01 11:21:31 -07002071 mCalendarDateVibePattern = getLongIntArray(mContext.getResources(),
2072 com.android.internal.R.array.config_calendarDateVibePattern);
Dianne Hackbornb1a79802009-09-29 15:18:31 -07002073 mSafeModeEnabledVibePattern = getLongIntArray(mContext.getResources(),
2074 com.android.internal.R.array.config_safeModeEnabledVibePattern);
Daniel Sandler40427442010-07-16 11:44:52 -04002075
Christopher Tatee90585f2012-03-05 18:56:25 -08002076 mScreenshotChordEnabled = mContext.getResources().getBoolean(
2077 com.android.internal.R.bool.config_enableScreenshotChord);
2078
Justin Kohd378ad72013-04-01 12:18:26 -07002079 mGlobalKeyManager = new GlobalKeyManager(mContext);
2080
Joe Onoratoea495d42011-04-06 11:41:11 -07002081 // Controls rotation and the like.
2082 initializeHdmiState();
Dianne Hackborn40011092011-09-22 13:37:48 -07002083
2084 // Match current screen state.
Craig Mautnera631d492014-08-05 15:16:01 -07002085 if (!mPowerManager.isInteractive()) {
Jeff Brown416c49c2015-05-26 19:50:18 -07002086 startedGoingToSleep(WindowManagerPolicy.OFF_BECAUSE_OF_USER);
2087 finishedGoingToSleep(WindowManagerPolicy.OFF_BECAUSE_OF_USER);
Dianne Hackborn40011092011-09-22 13:37:48 -07002088 }
Jorim Jaggi24bec7c2015-02-04 12:40:14 +01002089
2090 mWindowManagerInternal.registerAppTransitionListener(
2091 mStatusBarController.getAppTransitionListener());
Jorim Jaggife762342016-10-13 14:33:27 +02002092 mWindowManagerInternal.registerAppTransitionListener(new AppTransitionListener() {
2093 @Override
2094 public int onAppTransitionStartingLocked(int transit, IBinder openToken,
2095 IBinder closeToken,
2096 Animation openAnimation, Animation closeAnimation) {
2097 return handleStartTransitionForKeyguardLw(transit, openAnimation);
2098 }
2099
2100 @Override
2101 public void onAppTransitionCancelledLocked(int transit) {
2102 handleStartTransitionForKeyguardLw(transit, null /* transit */);
2103 }
2104 });
Keun-young Park4136d2d2017-05-08 14:51:59 -07002105 mKeyguardDelegate = new KeyguardServiceDelegate(mContext,
2106 new StateCallback() {
2107 @Override
2108 public void onTrustedChanged() {
2109 mWindowManagerFuncs.notifyKeyguardTrustedChanged();
2110 }
2111 });
Mike Lockwood1753f7f2009-08-24 14:49:07 -07002112 }
2113
Jeff Brownf71343d2013-05-31 17:59:11 -07002114 /**
2115 * Read values from config.xml that may be overridden depending on
2116 * the configuration of the device.
2117 * eg. Disable long press on home goes to recents on sw600dp.
2118 */
2119 private void readConfigurationDependentBehaviors() {
Jaewan Kimc552b042016-01-18 16:08:45 +09002120 final Resources res = mContext.getResources();
2121
2122 mLongPressOnHomeBehavior = res.getInteger(
Jeff Brownf71343d2013-05-31 17:59:11 -07002123 com.android.internal.R.integer.config_longPressOnHomeBehavior);
2124 if (mLongPressOnHomeBehavior < LONG_PRESS_HOME_NOTHING ||
Jaewan Kim52632e22016-01-14 18:01:52 +09002125 mLongPressOnHomeBehavior > LAST_LONG_PRESS_HOME_BEHAVIOR) {
Jeff Brownf71343d2013-05-31 17:59:11 -07002126 mLongPressOnHomeBehavior = LONG_PRESS_HOME_NOTHING;
2127 }
2128
Jaewan Kimc552b042016-01-18 16:08:45 +09002129 mDoubleTapOnHomeBehavior = res.getInteger(
Jeff Brownf71343d2013-05-31 17:59:11 -07002130 com.android.internal.R.integer.config_doubleTapOnHomeBehavior);
2131 if (mDoubleTapOnHomeBehavior < DOUBLE_TAP_HOME_NOTHING ||
2132 mDoubleTapOnHomeBehavior > DOUBLE_TAP_HOME_RECENT_SYSTEM_UI) {
2133 mDoubleTapOnHomeBehavior = LONG_PRESS_HOME_NOTHING;
2134 }
Jaewan Kim49117872016-01-19 17:24:08 +09002135
2136 mShortPressWindowBehavior = SHORT_PRESS_WINDOW_NOTHING;
2137 if (mContext.getPackageManager().hasSystemFeature(FEATURE_PICTURE_IN_PICTURE)) {
2138 mShortPressWindowBehavior = SHORT_PRESS_WINDOW_PICTURE_IN_PICTURE;
2139 }
Yorke Lee2e4b7322016-03-02 17:33:06 -08002140
Yorke Lee9b2ffb32016-03-07 20:42:01 -08002141 mNavBarOpacityMode = res.getInteger(
2142 com.android.internal.R.integer.config_navBarOpacityMode);
Jeff Brownf71343d2013-05-31 17:59:11 -07002143 }
2144
Craig Mautner0bf6ec92012-12-18 08:33:27 -08002145 @Override
Dianne Hackborndde331c2012-08-03 14:01:57 -07002146 public void setInitialDisplaySize(Display display, int width, int height, int density) {
Jeff Brownef981a42013-08-07 14:13:37 -07002147 // This method might be called before the policy has been fully initialized
2148 // or for other displays we don't care about.
Andrii Kulian3a507b52016-09-19 18:14:12 -07002149 // TODO(multi-display): Define policy for secondary displays.
Jeff Brownef981a42013-08-07 14:13:37 -07002150 if (mContext == null || display.getDisplayId() != Display.DEFAULT_DISPLAY) {
2151 return;
Dianne Hackbornc652de82013-02-15 16:32:56 -08002152 }
Dianne Hackbornf87d1962012-04-04 12:48:24 -07002153 mDisplay = display;
2154
Craig Mautner46ac6fa2013-08-01 10:06:34 -07002155 final Resources res = mContext.getResources();
Dianne Hackbornf87d1962012-04-04 12:48:24 -07002156 int shortSize, longSize;
Dianne Hackborn9d132642011-04-21 17:26:39 -07002157 if (width > height) {
Dianne Hackborn81e56d52011-05-26 00:55:58 -07002158 shortSize = height;
Dianne Hackbornf87d1962012-04-04 12:48:24 -07002159 longSize = width;
Dianne Hackborn9d132642011-04-21 17:26:39 -07002160 mLandscapeRotation = Surface.ROTATION_0;
2161 mSeascapeRotation = Surface.ROTATION_180;
Craig Mautner46ac6fa2013-08-01 10:06:34 -07002162 if (res.getBoolean(com.android.internal.R.bool.config_reverseDefaultRotation)) {
Dianne Hackborn9d132642011-04-21 17:26:39 -07002163 mPortraitRotation = Surface.ROTATION_90;
2164 mUpsideDownRotation = Surface.ROTATION_270;
2165 } else {
2166 mPortraitRotation = Surface.ROTATION_270;
2167 mUpsideDownRotation = Surface.ROTATION_90;
2168 }
2169 } else {
Dianne Hackborn81e56d52011-05-26 00:55:58 -07002170 shortSize = width;
Dianne Hackbornf87d1962012-04-04 12:48:24 -07002171 longSize = height;
Dianne Hackborn9d132642011-04-21 17:26:39 -07002172 mPortraitRotation = Surface.ROTATION_0;
2173 mUpsideDownRotation = Surface.ROTATION_180;
Craig Mautner46ac6fa2013-08-01 10:06:34 -07002174 if (res.getBoolean(com.android.internal.R.bool.config_reverseDefaultRotation)) {
Dianne Hackborn9d132642011-04-21 17:26:39 -07002175 mLandscapeRotation = Surface.ROTATION_270;
2176 mSeascapeRotation = Surface.ROTATION_90;
2177 } else {
2178 mLandscapeRotation = Surface.ROTATION_90;
2179 mSeascapeRotation = Surface.ROTATION_270;
2180 }
2181 }
Dianne Hackborn81e56d52011-05-26 00:55:58 -07002182
Daniel Sandler4a066c52012-04-20 14:49:13 -04002183 // SystemUI (status bar) layout policy
Dianne Hackborndde331c2012-08-03 14:01:57 -07002184 int shortSizeDp = shortSize * DisplayMetrics.DENSITY_DEFAULT / density;
Craig Mautner46ac6fa2013-08-01 10:06:34 -07002185 int longSizeDp = longSize * DisplayMetrics.DENSITY_DEFAULT / density;
Daniel Sandler4a066c52012-04-20 14:49:13 -04002186
Devin Kimd7b12b42014-05-05 14:34:58 -07002187 // Allow the navigation bar to move on non-square small devices (phones).
2188 mNavigationBarCanMove = width != height && shortSizeDp < 600;
Daniel Sandler36412a72011-08-04 09:35:13 -04002189
Craig Mautner46ac6fa2013-08-01 10:06:34 -07002190 mHasNavigationBar = res.getBoolean(com.android.internal.R.bool.config_showNavigationBar);
Jorim Jaggi11c62e12016-04-05 20:41:21 -07002191
John Spurlock80f00c12013-06-13 11:10:51 -04002192 // Allow a system property to override this. Used by the emulator.
2193 // See also hasNavigationBar().
2194 String navBarOverride = SystemProperties.get("qemu.hw.mainkeys");
2195 if ("1".equals(navBarOverride)) {
Dianne Hackbornf87d1962012-04-04 12:48:24 -07002196 mHasNavigationBar = false;
John Spurlock80f00c12013-06-13 11:10:51 -04002197 } else if ("0".equals(navBarOverride)) {
2198 mHasNavigationBar = true;
Daniel Sandler0c4ccff2011-10-19 16:39:14 -04002199 }
2200
Jeff Brown27f1d672012-10-17 18:32:34 -07002201 // For demo purposes, allow the rotation of the HDMI display to be controlled.
2202 // By default, HDMI locks rotation to landscape.
Erik Gilling9a41ef82011-09-26 19:21:03 -07002203 if ("portrait".equals(SystemProperties.get("persist.demo.hdmirotation"))) {
Jeff Brownc82c89ed2013-04-17 17:18:15 -07002204 mDemoHdmiRotation = mPortraitRotation;
Erik Gilling9a41ef82011-09-26 19:21:03 -07002205 } else {
Jeff Brownc82c89ed2013-04-17 17:18:15 -07002206 mDemoHdmiRotation = mLandscapeRotation;
Erik Gilling9a41ef82011-09-26 19:21:03 -07002207 }
Jeff Brownc82c89ed2013-04-17 17:18:15 -07002208 mDemoHdmiRotationLock = SystemProperties.getBoolean("persist.demo.hdmirotationlock", false);
Craig Mautner46ac6fa2013-08-01 10:06:34 -07002209
Chong Zhangae6119ff2014-11-11 18:54:39 -08002210 // For demo purposes, allow the rotation of the remote display to be controlled.
2211 // By default, remote display locks rotation to landscape.
2212 if ("portrait".equals(SystemProperties.get("persist.demo.remoterotation"))) {
2213 mDemoRotation = mPortraitRotation;
2214 } else {
2215 mDemoRotation = mLandscapeRotation;
2216 }
2217 mDemoRotationLock = SystemProperties.getBoolean(
2218 "persist.demo.rotationlock", false);
2219
Craig Mautner46ac6fa2013-08-01 10:06:34 -07002220 // Only force the default orientation if the screen is xlarge, at least 960dp x 720dp, per
2221 // http://developer.android.com/guide/practices/screens_support.html#range
2222 mForceDefaultOrientation = longSizeDp >= 960 && shortSizeDp >= 720 &&
2223 res.getBoolean(com.android.internal.R.bool.config_forceDefaultOrientation) &&
2224 // For debug purposes the next line turns this feature off with:
2225 // $ adb shell setprop config.override_forced_orient true
2226 // $ adb shell wm size reset
2227 !"true".equals(SystemProperties.get("config.override_forced_orient"));
2228 }
2229
Alan Viverette5a0f4ec2013-10-07 15:10:29 -07002230 /**
2231 * @return whether the navigation bar can be hidden, e.g. the device has a
2232 * navigation bar and touch exploration is not enabled
2233 */
2234 private boolean canHideNavigationBar() {
Alan Viverette817f3cd2015-08-13 11:40:14 -04002235 return mHasNavigationBar;
Alan Viverette5a0f4ec2013-10-07 15:10:29 -07002236 }
2237
Craig Mautner46ac6fa2013-08-01 10:06:34 -07002238 @Override
2239 public boolean isDefaultOrientationForced() {
2240 return mForceDefaultOrientation;
Dianne Hackborn9d132642011-04-21 17:26:39 -07002241 }
2242
Dianne Hackbornc652de82013-02-15 16:32:56 -08002243 @Override
2244 public void setDisplayOverscan(Display display, int left, int top, int right, int bottom) {
Andrii Kulian3a507b52016-09-19 18:14:12 -07002245 // TODO(multi-display): Define policy for secondary displays.
Dianne Hackbornc652de82013-02-15 16:32:56 -08002246 if (display.getDisplayId() == Display.DEFAULT_DISPLAY) {
2247 mOverscanLeft = left;
2248 mOverscanTop = top;
2249 mOverscanRight = right;
2250 mOverscanBottom = bottom;
2251 }
2252 }
2253
Dianne Hackbornc777e072010-02-12 13:07:59 -08002254 public void updateSettings() {
2255 ContentResolver resolver = mContext.getContentResolver();
2256 boolean updateRotation = false;
Dianne Hackbornc777e072010-02-12 13:07:59 -08002257 synchronized (mLock) {
Christopher Tate5e08af02012-09-21 17:17:22 -07002258 mEndcallBehavior = Settings.System.getIntForUser(resolver,
David Brownbaf8d092010-03-08 21:52:59 -08002259 Settings.System.END_BUTTON_BEHAVIOR,
Christopher Tate5e08af02012-09-21 17:17:22 -07002260 Settings.System.END_BUTTON_BEHAVIOR_DEFAULT,
2261 UserHandle.USER_CURRENT);
2262 mIncallPowerBehavior = Settings.Secure.getIntForUser(resolver,
David Brownbaf8d092010-03-08 21:52:59 -08002263 Settings.Secure.INCALL_POWER_BUTTON_BEHAVIOR,
Christopher Tate5e08af02012-09-21 17:17:22 -07002264 Settings.Secure.INCALL_POWER_BUTTON_BEHAVIOR_DEFAULT,
2265 UserHandle.USER_CURRENT);
Bryce Leedb776ce2016-09-03 15:02:00 -07002266 mIncallBackBehavior = Settings.Secure.getIntForUser(resolver,
2267 Settings.Secure.INCALL_BACK_BUTTON_BEHAVIOR,
2268 Settings.Secure.INCALL_BACK_BUTTON_BEHAVIOR_DEFAULT,
2269 UserHandle.USER_CURRENT);
Daniel Sandlerb73617d2010-08-17 00:41:00 -04002270
Jeff Browna20dda42014-05-27 20:57:24 -07002271 // Configure wake gesture.
2272 boolean wakeGestureEnabledSetting = Settings.Secure.getIntForUser(resolver,
2273 Settings.Secure.WAKE_GESTURE_ENABLED, 0,
2274 UserHandle.USER_CURRENT) != 0;
2275 if (mWakeGestureEnabledSetting != wakeGestureEnabledSetting) {
2276 mWakeGestureEnabledSetting = wakeGestureEnabledSetting;
2277 updateWakeGestureListenerLp();
2278 }
2279
Jeff Brown207673cd2012-06-05 17:47:11 -07002280 // Configure rotation lock.
Christopher Tate5e08af02012-09-21 17:17:22 -07002281 int userRotation = Settings.System.getIntForUser(resolver,
2282 Settings.System.USER_ROTATION, Surface.ROTATION_0,
2283 UserHandle.USER_CURRENT);
Jeff Brown207673cd2012-06-05 17:47:11 -07002284 if (mUserRotation != userRotation) {
2285 mUserRotation = userRotation;
2286 updateRotation = true;
2287 }
Christopher Tate5e08af02012-09-21 17:17:22 -07002288 int userRotationMode = Settings.System.getIntForUser(resolver,
2289 Settings.System.ACCELEROMETER_ROTATION, 0, UserHandle.USER_CURRENT) != 0 ?
Jeff Brown207673cd2012-06-05 17:47:11 -07002290 WindowManagerPolicy.USER_ROTATION_FREE :
2291 WindowManagerPolicy.USER_ROTATION_LOCKED;
2292 if (mUserRotationMode != userRotationMode) {
2293 mUserRotationMode = userRotationMode;
2294 updateRotation = true;
Dianne Hackbornc777e072010-02-12 13:07:59 -08002295 updateOrientationListenerLp();
2296 }
Daniel Sandlerb73617d2010-08-17 00:41:00 -04002297
Dianne Hackbornc777e072010-02-12 13:07:59 -08002298 if (mSystemReady) {
Christopher Tate5e08af02012-09-21 17:17:22 -07002299 int pointerLocation = Settings.System.getIntForUser(resolver,
2300 Settings.System.POINTER_LOCATION, 0, UserHandle.USER_CURRENT);
Dianne Hackbornc777e072010-02-12 13:07:59 -08002301 if (mPointerLocationMode != pointerLocation) {
2302 mPointerLocationMode = pointerLocation;
Jeff Brown70825162012-03-28 17:27:48 -07002303 mHandler.sendEmptyMessage(pointerLocation != 0 ?
2304 MSG_ENABLE_POINTER_LOCATION : MSG_DISABLE_POINTER_LOCATION);
Dianne Hackbornc777e072010-02-12 13:07:59 -08002305 }
2306 }
2307 // use screen off timeout setting as the timeout for the lockscreen
Christopher Tate5e08af02012-09-21 17:17:22 -07002308 mLockScreenTimeout = Settings.System.getIntForUser(resolver,
2309 Settings.System.SCREEN_OFF_TIMEOUT, 0, UserHandle.USER_CURRENT);
2310 String imId = Settings.Secure.getStringForUser(resolver,
2311 Settings.Secure.DEFAULT_INPUT_METHOD, UserHandle.USER_CURRENT);
Dianne Hackbornc777e072010-02-12 13:07:59 -08002312 boolean hasSoftInput = imId != null && imId.length() > 0;
2313 if (mHasSoftInput != hasSoftInput) {
2314 mHasSoftInput = hasSoftInput;
2315 updateRotation = true;
2316 }
John Spurlockf1a36642013-10-12 17:50:42 -04002317 if (mImmersiveModeConfirmation != null) {
John Spurlock4355a532014-02-19 09:49:25 -05002318 mImmersiveModeConfirmation.loadSetting(mCurrentUserId);
John Spurlockd67ec252013-09-05 11:31:54 -04002319 }
tiger_huangcc6366d2015-06-29 17:17:30 +08002320 }
2321 synchronized (mWindowManagerFuncs.getWindowManagerLock()) {
John Spurlockc6d1c602014-01-17 15:22:06 -05002322 PolicyControl.reloadFromSetting(mContext);
Dianne Hackbornc777e072010-02-12 13:07:59 -08002323 }
2324 if (updateRotation) {
Jeff Brown01a98dd2011-09-20 15:08:29 -07002325 updateRotation(true);
Dianne Hackbornc777e072010-02-12 13:07:59 -08002326 }
Jeff Brown70825162012-03-28 17:27:48 -07002327 }
2328
Jeff Browna20dda42014-05-27 20:57:24 -07002329 private void updateWakeGestureListenerLp() {
2330 if (shouldEnableWakeGestureLp()) {
2331 mWakeGestureListener.requestWakeUpTrigger();
2332 } else {
2333 mWakeGestureListener.cancelWakeUpTrigger();
2334 }
2335 }
2336
2337 private boolean shouldEnableWakeGestureLp() {
Jeff Brown3ee549c2014-09-22 20:14:39 -07002338 return mWakeGestureEnabledSetting && !mAwake
Jeff Browna20dda42014-05-27 20:57:24 -07002339 && (!mLidControlsSleep || mLidState != LID_CLOSED)
2340 && mWakeGestureListener.isSupported();
2341 }
2342
Jeff Brown70825162012-03-28 17:27:48 -07002343 private void enablePointerLocation() {
2344 if (mPointerLocationView == null) {
2345 mPointerLocationView = new PointerLocationView(mContext);
2346 mPointerLocationView.setPrintCoords(false);
Dianne Hackbornc777e072010-02-12 13:07:59 -08002347 WindowManager.LayoutParams lp = new WindowManager.LayoutParams(
2348 WindowManager.LayoutParams.MATCH_PARENT,
2349 WindowManager.LayoutParams.MATCH_PARENT);
Jeff Brown3b2b3542010-10-15 00:54:27 -07002350 lp.type = WindowManager.LayoutParams.TYPE_SECURE_SYSTEM_OVERLAY;
Jeff Brownbfcb60a2011-09-08 18:51:14 -07002351 lp.flags = WindowManager.LayoutParams.FLAG_FULLSCREEN
2352 | WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE
2353 | WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE
2354 | WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN;
Jeff Brown90fc9052012-10-01 14:44:24 -07002355 if (ActivityManager.isHighEndGfx()) {
2356 lp.flags |= WindowManager.LayoutParams.FLAG_HARDWARE_ACCELERATED;
2357 lp.privateFlags |=
2358 WindowManager.LayoutParams.PRIVATE_FLAG_FORCE_HARDWARE_ACCELERATED;
2359 }
Dianne Hackbornc777e072010-02-12 13:07:59 -08002360 lp.format = PixelFormat.TRANSLUCENT;
2361 lp.setTitle("PointerLocation");
Andrii Kulianfb1bf692017-01-17 11:17:34 -08002362 WindowManager wm = (WindowManager) mContext.getSystemService(WINDOW_SERVICE);
Jeff Browncc4f7db2011-08-30 20:34:48 -07002363 lp.inputFeatures |= WindowManager.LayoutParams.INPUT_FEATURE_NO_INPUT_CHANNEL;
Jeff Brown70825162012-03-28 17:27:48 -07002364 wm.addView(mPointerLocationView, lp);
Michael Wrightc9c487e2013-11-07 18:55:09 -08002365 mWindowManagerFuncs.registerPointerEventListener(mPointerLocationView);
Dianne Hackbornc777e072010-02-12 13:07:59 -08002366 }
Dianne Hackbornc777e072010-02-12 13:07:59 -08002367 }
Jeff Brown70825162012-03-28 17:27:48 -07002368
2369 private void disablePointerLocation() {
Jeff Brown70825162012-03-28 17:27:48 -07002370 if (mPointerLocationView != null) {
Michael Wrightc9c487e2013-11-07 18:55:09 -08002371 mWindowManagerFuncs.unregisterPointerEventListener(mPointerLocationView);
Andrii Kulianfb1bf692017-01-17 11:17:34 -08002372 WindowManager wm = (WindowManager) mContext.getSystemService(WINDOW_SERVICE);
Jeff Brown70825162012-03-28 17:27:48 -07002373 wm.removeView(mPointerLocationView);
2374 mPointerLocationView = null;
2375 }
2376 }
2377
Mike Lockwood2d1efbd2009-09-16 12:15:53 -04002378 private int readRotation(int resID) {
Mike Lockwood1753f7f2009-08-24 14:49:07 -07002379 try {
2380 int rotation = mContext.getResources().getInteger(resID);
2381 switch (rotation) {
2382 case 0:
2383 return Surface.ROTATION_0;
2384 case 90:
2385 return Surface.ROTATION_90;
2386 case 180:
2387 return Surface.ROTATION_180;
2388 case 270:
2389 return Surface.ROTATION_270;
Mike Lockwood1753f7f2009-08-24 14:49:07 -07002390 }
2391 } catch (Resources.NotFoundException e) {
Mike Lockwood2d1efbd2009-09-16 12:15:53 -04002392 // fall through
Mike Lockwood1753f7f2009-08-24 14:49:07 -07002393 }
Mike Lockwood2d1efbd2009-09-16 12:15:53 -04002394 return -1;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002395 }
2396
2397 /** {@inheritDoc} */
Craig Mautner88400d32012-09-30 12:35:45 -07002398 @Override
Dianne Hackbornc2293022013-02-06 23:14:49 -08002399 public int checkAddPermission(WindowManager.LayoutParams attrs, int[] outAppOp) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002400 int type = attrs.type;
Dianne Hackbornc2293022013-02-06 23:14:49 -08002401
2402 outAppOp[0] = AppOpsManager.OP_NONE;
2403
Wale Ogunwale74bf0652015-01-12 10:24:36 -08002404 if (!((type >= FIRST_APPLICATION_WINDOW && type <= LAST_APPLICATION_WINDOW)
2405 || (type >= FIRST_SUB_WINDOW && type <= LAST_SUB_WINDOW)
2406 || (type >= FIRST_SYSTEM_WINDOW && type <= LAST_SYSTEM_WINDOW))) {
2407 return WindowManagerGlobal.ADD_INVALID_TYPE;
2408 }
2409
2410 if (type < FIRST_SYSTEM_WINDOW || type > LAST_SYSTEM_WINDOW) {
2411 // Window manager will make sure these are okay.
Wale Ogunwale5cd907d2017-01-26 14:14:08 -08002412 return ADD_OKAY;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002413 }
Wale Ogunwale5cd907d2017-01-26 14:14:08 -08002414
2415 if (!isSystemAlertWindowType(type)) {
2416 switch (type) {
2417 case TYPE_TOAST:
2418 // Only apps that target older than O SDK can add window without a token, after
2419 // that we require a token so apps cannot add toasts directly as the token is
2420 // added by the notification system.
2421 // Window manager does the checking for this.
2422 outAppOp[0] = OP_TOAST_WINDOW;
2423 return ADD_OKAY;
2424 case TYPE_DREAM:
2425 case TYPE_INPUT_METHOD:
2426 case TYPE_WALLPAPER:
2427 case TYPE_PRESENTATION:
2428 case TYPE_PRIVATE_PRESENTATION:
2429 case TYPE_VOICE_INTERACTION:
2430 case TYPE_ACCESSIBILITY_OVERLAY:
2431 case TYPE_QS_DIALOG:
2432 // The window manager will check these.
2433 return ADD_OKAY;
2434 }
2435 return mContext.checkCallingOrSelfPermission(INTERNAL_SYSTEM_WINDOW)
2436 == PERMISSION_GRANTED ? ADD_OKAY : ADD_PERMISSION_DENIED;
2437 }
2438
2439 // Things get a little more interesting for alert windows...
2440 outAppOp[0] = OP_SYSTEM_ALERT_WINDOW;
2441
2442 final int callingUid = Binder.getCallingUid();
2443 // system processes will be automatically granted privilege to draw
2444 if (UserHandle.getAppId(callingUid) == Process.SYSTEM_UID) {
2445 return ADD_OKAY;
2446 }
2447
2448 ApplicationInfo appInfo;
2449 try {
Tony Mak22295fd2017-03-20 16:17:54 +00002450 appInfo = mContext.getPackageManager().getApplicationInfoAsUser(
2451 attrs.packageName,
2452 0 /* flags */,
Wale Ogunwale5cd907d2017-01-26 14:14:08 -08002453 UserHandle.getUserId(callingUid));
2454 } catch (PackageManager.NameNotFoundException e) {
2455 appInfo = null;
2456 }
2457
2458 if (appInfo == null || (type != TYPE_APPLICATION_OVERLAY && appInfo.targetSdkVersion >= O)) {
2459 /**
2460 * Apps targeting >= {@link Build.VERSION_CODES#O} are required to hold
2461 * {@link android.Manifest.permission#INTERNAL_SYSTEM_WINDOW} (system signature apps)
2462 * permission to add alert windows that aren't
2463 * {@link android.view.WindowManager.LayoutParams#TYPE_APPLICATION_OVERLAY}.
2464 */
Wale Ogunwale5aa86832017-02-28 10:40:27 -08002465 return (mContext.checkCallingOrSelfPermission(INTERNAL_SYSTEM_WINDOW)
2466 == PERMISSION_GRANTED) ? ADD_OKAY : ADD_PERMISSION_DENIED;
Wale Ogunwale5cd907d2017-01-26 14:14:08 -08002467 }
2468
2469 // check if user has enabled this operation. SecurityException will be thrown if this app
2470 // has not been allowed by the user
2471 final int mode = mAppOpsManager.checkOpNoThrow(outAppOp[0], callingUid, attrs.packageName);
2472 switch (mode) {
2473 case AppOpsManager.MODE_ALLOWED:
2474 case AppOpsManager.MODE_IGNORED:
2475 // although we return ADD_OKAY for MODE_IGNORED, the added window will
2476 // actually be hidden in WindowManagerService
2477 return ADD_OKAY;
2478 case AppOpsManager.MODE_ERRORED:
2479 // Don't crash legacy apps
2480 if (appInfo.targetSdkVersion < M) {
2481 return ADD_OKAY;
2482 }
2483 return ADD_PERMISSION_DENIED;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002484 default:
Wale Ogunwale5cd907d2017-01-26 14:14:08 -08002485 // in the default mode, we will make a decision here based on
2486 // checkCallingPermission()
Wale Ogunwale5aa86832017-02-28 10:40:27 -08002487 return (mContext.checkCallingOrSelfPermission(SYSTEM_ALERT_WINDOW)
2488 == PERMISSION_GRANTED) ? ADD_OKAY : ADD_PERMISSION_DENIED;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002489 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002490 }
Craig Mautner88400d32012-09-30 12:35:45 -07002491
2492 @Override
2493 public boolean checkShowToOwnerOnly(WindowManager.LayoutParams attrs) {
2494
2495 // If this switch statement is modified, modify the comment in the declarations of
2496 // the type in {@link WindowManager.LayoutParams} as well.
2497 switch (attrs.type) {
2498 default:
2499 // These are the windows that by default are shown only to the user that created
2500 // them. If this needs to be overridden, set
2501 // {@link WindowManager.LayoutParams.PRIVATE_FLAG_SHOW_FOR_ALL_USERS} in
2502 // {@link WindowManager.LayoutParams}. Note that permission
2503 // {@link android.Manifest.permission.INTERNAL_SYSTEM_WINDOW} is required as well.
2504 if ((attrs.privateFlags & PRIVATE_FLAG_SHOW_FOR_ALL_USERS) == 0) {
2505 return true;
2506 }
2507 break;
2508
2509 // These are the windows that by default are shown to all users. However, to
2510 // protect against spoofing, check permissions below.
2511 case TYPE_APPLICATION_STARTING:
2512 case TYPE_BOOT_PROGRESS:
2513 case TYPE_DISPLAY_OVERLAY:
Selim Cinekf83e8242015-05-19 18:08:14 -07002514 case TYPE_INPUT_CONSUMER:
Craig Mautner88400d32012-09-30 12:35:45 -07002515 case TYPE_KEYGUARD_DIALOG:
2516 case TYPE_MAGNIFICATION_OVERLAY:
2517 case TYPE_NAVIGATION_BAR:
2518 case TYPE_NAVIGATION_BAR_PANEL:
2519 case TYPE_PHONE:
2520 case TYPE_POINTER:
2521 case TYPE_PRIORITY_PHONE:
Craig Mautner88400d32012-09-30 12:35:45 -07002522 case TYPE_SEARCH_BAR:
2523 case TYPE_STATUS_BAR:
2524 case TYPE_STATUS_BAR_PANEL:
2525 case TYPE_STATUS_BAR_SUB_PANEL:
2526 case TYPE_SYSTEM_DIALOG:
Craig Mautner88400d32012-09-30 12:35:45 -07002527 case TYPE_VOLUME_OVERLAY:
Wale Ogunwale5b6714c2016-11-01 20:54:46 -07002528 case TYPE_PRESENTATION:
keunyounga446bf02013-06-21 19:07:57 -07002529 case TYPE_PRIVATE_PRESENTATION:
Filip Gruszczynski466f3212015-09-21 17:57:57 -07002530 case TYPE_DOCK_DIVIDER:
Craig Mautner88400d32012-09-30 12:35:45 -07002531 break;
2532 }
2533
2534 // Check if third party app has set window to system window type.
Wale Ogunwale5cd907d2017-01-26 14:14:08 -08002535 return mContext.checkCallingOrSelfPermission(INTERNAL_SYSTEM_WINDOW) != PERMISSION_GRANTED;
Craig Mautner88400d32012-09-30 12:35:45 -07002536 }
2537
Craig Mautner967212c2013-04-13 21:10:58 -07002538 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002539 public void adjustWindowParamsLw(WindowManager.LayoutParams attrs) {
2540 switch (attrs.type) {
2541 case TYPE_SYSTEM_OVERLAY:
Jeff Brown3b2b3542010-10-15 00:54:27 -07002542 case TYPE_SECURE_SYSTEM_OVERLAY:
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002543 // These types of windows can't receive input events.
2544 attrs.flags |= WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE
2545 | WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE;
Jeff Brownbfcb60a2011-09-08 18:51:14 -07002546 attrs.flags &= ~WindowManager.LayoutParams.FLAG_WATCH_OUTSIDE_TOUCH;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002547 break;
Jorim Jaggi380ecb82014-03-14 17:25:20 +01002548 case TYPE_STATUS_BAR:
2549
2550 // If the Keyguard is in a hidden state (occluded by another window), we force to
2551 // remove the wallpaper and keyguard flag so that any change in-flight after setting
2552 // the keyguard as occluded wouldn't set these flags again.
2553 // See {@link #processKeyguardSetHiddenResultLw}.
Jorim Jaggife762342016-10-13 14:33:27 +02002554 if (mKeyguardOccluded) {
Jorim Jaggi380ecb82014-03-14 17:25:20 +01002555 attrs.flags &= ~WindowManager.LayoutParams.FLAG_SHOW_WALLPAPER;
2556 attrs.privateFlags &= ~WindowManager.LayoutParams.PRIVATE_FLAG_KEYGUARD;
2557 }
2558 break;
Svetoslav Ganovaa076532016-08-01 19:16:43 -07002559
Muyuan Li36ca72c2016-08-06 20:24:06 -07002560 case TYPE_SCREENSHOT:
2561 attrs.flags |= WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE;
2562 break;
Svetoslav Ganovaa076532016-08-01 19:16:43 -07002563
2564 case TYPE_TOAST:
2565 // While apps should use the dedicated toast APIs to add such windows
2566 // it possible legacy apps to add the window directly. Therefore, we
2567 // make windows added directly by the app behave as a toast as much
2568 // as possible in terms of timeout and animation.
2569 if (attrs.hideTimeoutMilliseconds < 0
2570 || attrs.hideTimeoutMilliseconds > TOAST_WINDOW_TIMEOUT) {
2571 attrs.hideTimeoutMilliseconds = TOAST_WINDOW_TIMEOUT;
2572 }
2573 attrs.windowAnimations = com.android.internal.R.style.Animation_Toast;
2574 break;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002575 }
Adrian Roos38502112014-04-09 21:04:11 +02002576
2577 if (attrs.type != TYPE_STATUS_BAR) {
2578 // The status bar is the only window allowed to exhibit keyguard behavior.
2579 attrs.privateFlags &= ~WindowManager.LayoutParams.PRIVATE_FLAG_KEYGUARD;
2580 }
Adrian Roosea562512014-05-05 13:33:03 +02002581
Jorim Jaggi4fa78922015-11-30 17:13:56 -08002582 if (ActivityManager.isHighEndGfx()) {
2583 if ((attrs.flags & FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS) != 0) {
2584 attrs.subtreeSystemUiVisibility |= View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION;
2585 }
Jorim Jaggi8f5701b2016-04-04 18:36:02 -07002586 final boolean forceWindowDrawsStatusBarBackground =
2587 (attrs.privateFlags & PRIVATE_FLAG_FORCE_DRAW_STATUS_BAR_BACKGROUND)
2588 != 0;
Jorim Jaggi4fa78922015-11-30 17:13:56 -08002589 if ((attrs.flags & FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS) != 0
Jorim Jaggi8f5701b2016-04-04 18:36:02 -07002590 || forceWindowDrawsStatusBarBackground
2591 && attrs.height == MATCH_PARENT && attrs.width == MATCH_PARENT) {
Jorim Jaggi4fa78922015-11-30 17:13:56 -08002592 attrs.subtreeSystemUiVisibility |= View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN;
2593 }
Adrian Roosea562512014-05-05 13:33:03 +02002594 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002595 }
RoboErik8a2cfc32014-05-16 11:19:38 -07002596
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002597 void readLidState() {
Jeff Brown2e7760e2012-04-11 15:14:55 -07002598 mLidState = mWindowManagerFuncs.getLidState();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002599 }
RoboErik8a2cfc32014-05-16 11:19:38 -07002600
Michael Wright3818c922014-09-02 13:59:07 -07002601 private void readCameraLensCoverState() {
2602 mCameraLensCoverState = mWindowManagerFuncs.getCameraLensCoverState();
2603 }
2604
Jeff Browndaa37532012-05-01 15:54:03 -07002605 private boolean isHidden(int accessibilityMode) {
2606 switch (accessibilityMode) {
2607 case 1:
2608 return mLidState == LID_CLOSED;
2609 case 2:
2610 return mLidState == LID_OPEN;
2611 default:
2612 return false;
Dianne Hackborn2862fff2009-09-15 22:56:29 -07002613 }
Dianne Hackborn2862fff2009-09-15 22:56:29 -07002614 }
Jeff Brownd04a88c2011-01-16 14:05:47 -08002615
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002616 /** {@inheritDoc} */
Craig Mautner967212c2013-04-13 21:10:58 -07002617 @Override
Jeff Browndaa37532012-05-01 15:54:03 -07002618 public void adjustConfigurationLw(Configuration config, int keyboardPresence,
2619 int navigationPresence) {
2620 mHaveBuiltInKeyboard = (keyboardPresence & PRESENCE_INTERNAL) != 0;
2621
Jeff Brownf71343d2013-05-31 17:59:11 -07002622 readConfigurationDependentBehaviors();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002623 readLidState();
Jeff Brownd04a88c2011-01-16 14:05:47 -08002624
Jeff Browndaa37532012-05-01 15:54:03 -07002625 if (config.keyboard == Configuration.KEYBOARD_NOKEYS
2626 || (keyboardPresence == PRESENCE_INTERNAL
2627 && isHidden(mLidKeyboardAccessibility))) {
Jeff Brownd04a88c2011-01-16 14:05:47 -08002628 config.hardKeyboardHidden = Configuration.HARDKEYBOARDHIDDEN_YES;
Jeff Browndaa37532012-05-01 15:54:03 -07002629 if (!mHasSoftInput) {
2630 config.keyboardHidden = Configuration.KEYBOARDHIDDEN_YES;
2631 }
Jeff Brownd04a88c2011-01-16 14:05:47 -08002632 }
2633
Jeff Browndaa37532012-05-01 15:54:03 -07002634 if (config.navigation == Configuration.NAVIGATION_NONAV
2635 || (navigationPresence == PRESENCE_INTERNAL
2636 && isHidden(mLidNavigationAccessibility))) {
Jeff Brownd04a88c2011-01-16 14:05:47 -08002637 config.navigationHidden = Configuration.NAVIGATIONHIDDEN_YES;
Jeff Brownd04a88c2011-01-16 14:05:47 -08002638 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002639 }
Jeff Brownd04a88c2011-01-16 14:05:47 -08002640
Jorim Jaggi11c62e12016-04-05 20:41:21 -07002641 @Override
2642 public void onConfigurationChanged() {
Andrii Kulian3a507b52016-09-19 18:14:12 -07002643 // TODO(multi-display): Define policy for secondary displays.
Jorim Jaggi11c62e12016-04-05 20:41:21 -07002644 final Resources res = mContext.getResources();
2645
2646 mStatusBarHeight =
2647 res.getDimensionPixelSize(com.android.internal.R.dimen.status_bar_height);
2648
2649 // Height of the navigation bar when presented horizontally at bottom
2650 mNavigationBarHeightForRotationDefault[mPortraitRotation] =
2651 mNavigationBarHeightForRotationDefault[mUpsideDownRotation] =
2652 res.getDimensionPixelSize(com.android.internal.R.dimen.navigation_bar_height);
2653 mNavigationBarHeightForRotationDefault[mLandscapeRotation] =
2654 mNavigationBarHeightForRotationDefault[mSeascapeRotation] = res.getDimensionPixelSize(
2655 com.android.internal.R.dimen.navigation_bar_height_landscape);
2656
2657 // Width of the navigation bar when presented vertically along one side
2658 mNavigationBarWidthForRotationDefault[mPortraitRotation] =
2659 mNavigationBarWidthForRotationDefault[mUpsideDownRotation] =
2660 mNavigationBarWidthForRotationDefault[mLandscapeRotation] =
2661 mNavigationBarWidthForRotationDefault[mSeascapeRotation] =
2662 res.getDimensionPixelSize(com.android.internal.R.dimen.navigation_bar_width);
2663
Justin Paupore01915a12016-09-28 17:41:26 -07002664 if (ALTERNATE_CAR_MODE_NAV_SIZE) {
2665 // Height of the navigation bar when presented horizontally at bottom
2666 mNavigationBarHeightForRotationInCarMode[mPortraitRotation] =
2667 mNavigationBarHeightForRotationInCarMode[mUpsideDownRotation] =
2668 res.getDimensionPixelSize(
2669 com.android.internal.R.dimen.navigation_bar_height_car_mode);
2670 mNavigationBarHeightForRotationInCarMode[mLandscapeRotation] =
2671 mNavigationBarHeightForRotationInCarMode[mSeascapeRotation] = res.getDimensionPixelSize(
2672 com.android.internal.R.dimen.navigation_bar_height_landscape_car_mode);
Jorim Jaggi11c62e12016-04-05 20:41:21 -07002673
Justin Paupore01915a12016-09-28 17:41:26 -07002674 // Width of the navigation bar when presented vertically along one side
2675 mNavigationBarWidthForRotationInCarMode[mPortraitRotation] =
2676 mNavigationBarWidthForRotationInCarMode[mUpsideDownRotation] =
2677 mNavigationBarWidthForRotationInCarMode[mLandscapeRotation] =
2678 mNavigationBarWidthForRotationInCarMode[mSeascapeRotation] =
2679 res.getDimensionPixelSize(
2680 com.android.internal.R.dimen.navigation_bar_width_car_mode);
2681 }
Jorim Jaggi11c62e12016-04-05 20:41:21 -07002682 }
2683
Craig Mautner46ac6fa2013-08-01 10:06:34 -07002684 @Override
Dianne Hackbornabe0da02009-09-18 01:55:39 -07002685 public int getMaxWallpaperLayer() {
Wale Ogunwale5cd907d2017-01-26 14:14:08 -08002686 return getWindowLayerFromTypeLw(TYPE_STATUS_BAR);
Dianne Hackbornabe0da02009-09-18 01:55:39 -07002687 }
2688
Sriram Viswanathan9ebbe6a2015-11-16 17:59:22 -08002689 private int getNavigationBarWidth(int rotation, int uiMode) {
Justin Paupore01915a12016-09-28 17:41:26 -07002690 if (ALTERNATE_CAR_MODE_NAV_SIZE && (uiMode & UI_MODE_TYPE_MASK) == UI_MODE_TYPE_CAR) {
Sriram Viswanathan9ebbe6a2015-11-16 17:59:22 -08002691 return mNavigationBarWidthForRotationInCarMode[rotation];
2692 } else {
2693 return mNavigationBarWidthForRotationDefault[rotation];
2694 }
2695 }
2696
Craig Mautner46ac6fa2013-08-01 10:06:34 -07002697 @Override
Andrii Kuliandb8e1062016-11-15 18:30:27 -08002698 public int getNonDecorDisplayWidth(int fullWidth, int fullHeight, int rotation, int uiMode,
2699 int displayId) {
2700 // TODO(multi-display): Support navigation bar on secondary displays.
2701 if (displayId == Display.DEFAULT_DISPLAY && mHasNavigationBar) {
Dianne Hackborn077ee852012-04-09 16:27:07 -07002702 // For a basic navigation bar, when we are in landscape mode we place
2703 // the navigation bar to the side.
Daniel Sandler4a066c52012-04-20 14:49:13 -04002704 if (mNavigationBarCanMove && fullWidth > fullHeight) {
Sriram Viswanathan9ebbe6a2015-11-16 17:59:22 -08002705 return fullWidth - getNavigationBarWidth(rotation, uiMode);
Dianne Hackborn077ee852012-04-09 16:27:07 -07002706 }
Dianne Hackborn1f903c32011-09-13 19:18:06 -07002707 }
2708 return fullWidth;
Dianne Hackborne2515ee2011-04-27 18:52:56 -04002709 }
2710
Sriram Viswanathan9ebbe6a2015-11-16 17:59:22 -08002711 private int getNavigationBarHeight(int rotation, int uiMode) {
Justin Paupore01915a12016-09-28 17:41:26 -07002712 if (ALTERNATE_CAR_MODE_NAV_SIZE && (uiMode & UI_MODE_TYPE_MASK) == UI_MODE_TYPE_CAR) {
Sriram Viswanathan9ebbe6a2015-11-16 17:59:22 -08002713 return mNavigationBarHeightForRotationInCarMode[rotation];
2714 } else {
2715 return mNavigationBarHeightForRotationDefault[rotation];
2716 }
2717 }
2718
Jose Lima9546b202014-07-02 17:21:51 -07002719 @Override
Andrii Kuliandb8e1062016-11-15 18:30:27 -08002720 public int getNonDecorDisplayHeight(int fullWidth, int fullHeight, int rotation, int uiMode,
2721 int displayId) {
2722 // TODO(multi-display): Support navigation bar on secondary displays.
2723 if (displayId == Display.DEFAULT_DISPLAY && mHasNavigationBar) {
Dianne Hackborn077ee852012-04-09 16:27:07 -07002724 // For a basic navigation bar, when we are in portrait mode we place
2725 // the navigation bar to the bottom.
Daniel Sandler4a066c52012-04-20 14:49:13 -04002726 if (!mNavigationBarCanMove || fullWidth < fullHeight) {
Sriram Viswanathan9ebbe6a2015-11-16 17:59:22 -08002727 return fullHeight - getNavigationBarHeight(rotation, uiMode);
Dianne Hackborn077ee852012-04-09 16:27:07 -07002728 }
2729 }
2730 return fullHeight;
Dianne Hackborn69cb8752011-05-19 18:13:32 -07002731 }
2732
Jose Lima9546b202014-07-02 17:21:51 -07002733 @Override
Andrii Kuliandb8e1062016-11-15 18:30:27 -08002734 public int getConfigDisplayWidth(int fullWidth, int fullHeight, int rotation, int uiMode,
2735 int displayId) {
2736 return getNonDecorDisplayWidth(fullWidth, fullHeight, rotation, uiMode, displayId);
Dianne Hackborn69cb8752011-05-19 18:13:32 -07002737 }
2738
Jose Lima9546b202014-07-02 17:21:51 -07002739 @Override
Andrii Kuliandb8e1062016-11-15 18:30:27 -08002740 public int getConfigDisplayHeight(int fullWidth, int fullHeight, int rotation, int uiMode,
2741 int displayId) {
John Spurlock80f00c12013-06-13 11:10:51 -04002742 // There is a separate status bar at the top of the display. We don't count that as part
2743 // of the fixed decor, since it can hide; however, for purposes of configurations,
Dianne Hackborn077ee852012-04-09 16:27:07 -07002744 // we do want to exclude it since applications can't generally use that part
2745 // of the screen.
Andrii Kuliandb8e1062016-11-15 18:30:27 -08002746 // TODO(multi-display): Support status bars on secondary displays.
2747 if (displayId == Display.DEFAULT_DISPLAY) {
2748 return getNonDecorDisplayHeight(fullWidth, fullHeight, rotation, uiMode, displayId)
2749 - mStatusBarHeight;
2750 }
2751 return fullHeight;
Dianne Hackborne2515ee2011-04-27 18:52:56 -04002752 }
2753
Craig Mautnera3f4bf52012-10-10 20:37:48 -07002754 @Override
Jorim Jaggi0d674622014-05-21 01:34:15 +02002755 public boolean isKeyguardHostWindow(WindowManager.LayoutParams attrs) {
2756 return attrs.type == TYPE_STATUS_BAR;
2757 }
2758
2759 @Override
Jorim Jaggife762342016-10-13 14:33:27 +02002760 public boolean canBeHiddenByKeyguardLw(WindowState win) {
2761 switch (win.getAttrs().type) {
Craig Mautnera3f4bf52012-10-10 20:37:48 -07002762 case TYPE_STATUS_BAR:
2763 case TYPE_NAVIGATION_BAR:
2764 case TYPE_WALLPAPER:
2765 case TYPE_DREAM:
Craig Mautnera3f4bf52012-10-10 20:37:48 -07002766 return false;
2767 default:
Adrian Roos461829d2015-06-03 14:41:18 -07002768 // Hide only windows below the keyguard host window.
Wale Ogunwale5cd907d2017-01-26 14:14:08 -08002769 return getWindowLayerLw(win) < getWindowLayerFromTypeLw(TYPE_STATUS_BAR);
Craig Mautnera3f4bf52012-10-10 20:37:48 -07002770 }
Dianne Hackborn01ad2f42009-09-24 19:24:56 -07002771 }
Craig Mautner8e4df6c2012-05-23 16:57:23 -07002772
Jorim Jaggife762342016-10-13 14:33:27 +02002773 private boolean shouldBeHiddenByKeyguard(WindowState win, WindowState imeTarget) {
2774
2775 // Keyguard visibility of window from activities are determined over activity visibility.
2776 if (win.getAppToken() != null) {
2777 return false;
2778 }
2779
2780 final LayoutParams attrs = win.getAttrs();
2781 final boolean showImeOverKeyguard = imeTarget != null && imeTarget.isVisibleLw() &&
2782 ((imeTarget.getAttrs().flags & FLAG_SHOW_WHEN_LOCKED) != 0
2783 || !canBeHiddenByKeyguardLw(imeTarget));
2784
2785 // Show IME over the keyguard if the target allows it
2786 boolean allowWhenLocked = (win.isInputMethodWindow() || imeTarget == this)
2787 && showImeOverKeyguard;;
2788
2789 if (isKeyguardLocked() && isKeyguardOccluded()) {
2790 // Show SHOW_WHEN_LOCKED windows if Keyguard is occluded.
2791 allowWhenLocked |= (attrs.flags & FLAG_SHOW_WHEN_LOCKED) != 0
2792 // Show error dialogs over apps that are shown on lockscreen
2793 || (attrs.privateFlags & PRIVATE_FLAG_SYSTEM_ERROR) != 0;
2794 }
2795
2796 boolean keyguardLocked = isKeyguardLocked();
2797 boolean hideDockDivider = attrs.type == TYPE_DOCK_DIVIDER
2798 && !mWindowManagerInternal.isStackVisible(DOCKED_STACK_ID);
2799 return (keyguardLocked && !allowWhenLocked && win.getDisplayId() == Display.DEFAULT_DISPLAY)
2800 || hideDockDivider;
Craig Mautner7d7808f2014-09-11 18:02:38 -07002801 }
2802
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002803 /** {@inheritDoc} */
Craig Mautner8e4df6c2012-05-23 16:57:23 -07002804 @Override
Jorim Jaggiba41f4b2016-12-14 17:43:07 -08002805 public StartingSurface addSplashScreen(IBinder appToken, String packageName, int theme,
2806 CompatibilityInfo compatInfo, CharSequence nonLocalizedLabel, int labelRes, int icon,
Andrii Kulianfb1bf692017-01-17 11:17:34 -08002807 int logo, int windowFlags, Configuration overrideConfig, int displayId) {
Jorim Jaggiba41f4b2016-12-14 17:43:07 -08002808 if (!SHOW_SPLASH_SCREENS) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002809 return null;
2810 }
2811 if (packageName == null) {
2812 return null;
2813 }
Craig Mautner8e4df6c2012-05-23 16:57:23 -07002814
Mathias Jeppssond1443e92012-08-24 15:25:32 +02002815 WindowManager wm = null;
2816 View view = null;
2817
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002818 try {
Dianne Hackborn867ab6472010-04-29 13:28:56 -07002819 Context context = mContext;
Jorim Jaggiba41f4b2016-12-14 17:43:07 -08002820 if (DEBUG_SPLASH_SCREEN) Slog.d(TAG, "addSplashScreen " + packageName
Craig Mautner6fbda632012-07-03 09:26:39 -07002821 + ": nonLocalizedLabel=" + nonLocalizedLabel + " theme="
2822 + Integer.toHexString(theme));
Andrii Kulianb047b8b2017-02-08 18:38:26 -08002823
2824 // Obtain proper context to launch on the right display.
2825 final Context displayContext = getDisplayContext(context, displayId);
2826 if (displayContext == null) {
2827 // Can't show splash screen on requested display, so skip showing at all.
2828 return null;
2829 }
2830 context = displayContext;
2831
Dianne Hackborn247fe742011-01-08 17:25:57 -08002832 if (theme != context.getThemeResId() || labelRes != 0) {
Dianne Hackborn867ab6472010-04-29 13:28:56 -07002833 try {
Robert Carr7ad24ba2017-06-20 17:26:06 -07002834 context = context.createPackageContext(packageName, CONTEXT_RESTRICTED);
Dianne Hackborn247fe742011-01-08 17:25:57 -08002835 context.setTheme(theme);
Dianne Hackborn867ab6472010-04-29 13:28:56 -07002836 } catch (PackageManager.NameNotFoundException e) {
2837 // Ignore
2838 }
2839 }
Craig Mautner8e4df6c2012-05-23 16:57:23 -07002840
Andrii Kuliana8a9bc52016-10-14 11:00:13 -07002841 if (overrideConfig != null && !overrideConfig.equals(EMPTY)) {
Jorim Jaggiba41f4b2016-12-14 17:43:07 -08002842 if (DEBUG_SPLASH_SCREEN) Slog.d(TAG, "addSplashScreen: creating context based"
2843 + " on overrideConfig" + overrideConfig + " for splash screen");
Wale Ogunwaledfc18622016-04-16 15:08:48 -07002844 final Context overrideContext = context.createConfigurationContext(overrideConfig);
2845 overrideContext.setTheme(theme);
2846 final TypedArray typedArray = overrideContext.obtainStyledAttributes(
2847 com.android.internal.R.styleable.Window);
2848 final int resId = typedArray.getResourceId(R.styleable.Window_windowBackground, 0);
2849 if (resId != 0 && overrideContext.getDrawable(resId) != null) {
2850 // We want to use the windowBackground for the override context if it is
2851 // available, otherwise we use the default one to make sure a themed starting
2852 // window is displayed for the app.
Jorim Jaggiba41f4b2016-12-14 17:43:07 -08002853 if (DEBUG_SPLASH_SCREEN) Slog.d(TAG, "addSplashScreen: apply overrideConfig"
Wale Ogunwaledfc18622016-04-16 15:08:48 -07002854 + overrideConfig + " to starting window resId=" + resId);
2855 context = overrideContext;
2856 }
Jorim Jaggi7d0d1022017-02-23 15:35:51 +01002857 typedArray.recycle();
Wale Ogunwaledfc18622016-04-16 15:08:48 -07002858 }
2859
2860 final PhoneWindow win = new PhoneWindow(context);
Jorim Jaggia16cc152015-06-01 16:55:05 -07002861 win.setIsStartingWindow(true);
Craig Mautner8e4df6c2012-05-23 16:57:23 -07002862
Phil Weaver155edc62016-06-09 10:24:53 -07002863 CharSequence label = context.getResources().getText(labelRes, null);
2864 // Only change the accessibility title if the label is localized
2865 if (label != null) {
2866 win.setTitle(label, true);
2867 } else {
2868 win.setTitle(nonLocalizedLabel, false);
2869 }
Craig Mautner8e4df6c2012-05-23 16:57:23 -07002870
Dianne Hackborn867ab6472010-04-29 13:28:56 -07002871 win.setType(
2872 WindowManager.LayoutParams.TYPE_APPLICATION_STARTING);
Adrian Roos602c68e2015-04-24 16:03:47 -07002873
2874 synchronized (mWindowManagerFuncs.getWindowManagerLock()) {
2875 // Assumes it's safe to show starting windows of launched apps while
2876 // the keyguard is being hidden. This is okay because starting windows never show
2877 // secret information.
Jorim Jaggife762342016-10-13 14:33:27 +02002878 if (mKeyguardOccluded) {
Adrian Roos602c68e2015-04-24 16:03:47 -07002879 windowFlags |= FLAG_SHOW_WHEN_LOCKED;
2880 }
2881 }
2882
Dianne Hackborn867ab6472010-04-29 13:28:56 -07002883 // Force the window flags: this is a fake window, so it is not really
2884 // touchable or focusable by the user. We also add in the ALT_FOCUSABLE_IM
2885 // flag because we do know that the next window will take input
2886 // focus, so we want to get the IME window up on top of us right away.
2887 win.setFlags(
Dianne Hackborn7eec10e2010-11-12 18:03:47 -08002888 windowFlags|
Dianne Hackborn867ab6472010-04-29 13:28:56 -07002889 WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE|
2890 WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE|
2891 WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM,
Dianne Hackborn7eec10e2010-11-12 18:03:47 -08002892 windowFlags|
Dianne Hackborn867ab6472010-04-29 13:28:56 -07002893 WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE|
2894 WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE|
2895 WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM);
Craig Mautner8e4df6c2012-05-23 16:57:23 -07002896
Adam Powell04fe6eb2013-05-31 14:39:48 -07002897 win.setDefaultIcon(icon);
2898 win.setDefaultLogo(logo);
2899
Dianne Hackborn867ab6472010-04-29 13:28:56 -07002900 win.setLayout(WindowManager.LayoutParams.MATCH_PARENT,
Dianne Hackborn2f0b1752011-05-31 17:59:49 -07002901 WindowManager.LayoutParams.MATCH_PARENT);
Craig Mautner8e4df6c2012-05-23 16:57:23 -07002902
Phil Weaver266ed9a2016-06-08 00:34:40 +00002903 final WindowManager.LayoutParams params = win.getAttributes();
Dianne Hackborn867ab6472010-04-29 13:28:56 -07002904 params.token = appToken;
2905 params.packageName = packageName;
2906 params.windowAnimations = win.getWindowStyle().getResourceId(
2907 com.android.internal.R.styleable.Window_windowAnimationStyle, 0);
John Reck61375a82014-09-18 19:27:48 +00002908 params.privateFlags |=
2909 WindowManager.LayoutParams.PRIVATE_FLAG_FAKE_HARDWARE_ACCELERATED;
Craig Mautner88400d32012-09-30 12:35:45 -07002910 params.privateFlags |= WindowManager.LayoutParams.PRIVATE_FLAG_SHOW_FOR_ALL_USERS;
Adam Lesinski95c42972013-10-02 10:13:27 -07002911
2912 if (!compatInfo.supportsScreen()) {
2913 params.privateFlags |= WindowManager.LayoutParams.PRIVATE_FLAG_COMPATIBLE_WINDOW;
2914 }
2915
Jorim Jaggiba41f4b2016-12-14 17:43:07 -08002916 params.setTitle("Splash Screen " + packageName);
Jorim Jaggi7d0d1022017-02-23 15:35:51 +01002917 addSplashscreenContent(win, context);
2918
Andrii Kulianb047b8b2017-02-08 18:38:26 -08002919 wm = (WindowManager) context.getSystemService(WINDOW_SERVICE);
Mathias Jeppssond1443e92012-08-24 15:25:32 +02002920 view = win.getDecorView();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002921
Jorim Jaggiba41f4b2016-12-14 17:43:07 -08002922 if (DEBUG_SPLASH_SCREEN) Slog.d(TAG, "Adding splash screen window for "
Wale Ogunwaledfc18622016-04-16 15:08:48 -07002923 + packageName + " / " + appToken + ": " + (view.getParent() != null ? view : null));
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002924
2925 wm.addView(view, params);
2926
2927 // Only return the view if it was successfully added to the
2928 // window manager... which we can tell by it having a parent.
Jorim Jaggi02886a82016-12-06 09:10:06 -08002929 return view.getParent() != null ? new SplashScreenSurface(view, appToken) : null;
Jeff Brown98365d72012-08-19 20:30:52 -07002930 } catch (WindowManager.BadTokenException e) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002931 // ignore
Craig Mautner42bf39e2014-02-21 16:46:22 -08002932 Log.w(TAG, appToken + " already running, starting window not displayed. " +
2933 e.getMessage());
Dianne Hackborn867ab6472010-04-29 13:28:56 -07002934 } catch (RuntimeException e) {
2935 // don't crash if something else bad happens, for example a
2936 // failure loading resources because we are loading from an app
2937 // on external storage that has been unmounted.
2938 Log.w(TAG, appToken + " failed creating starting window", e);
Mathias Jeppssond1443e92012-08-24 15:25:32 +02002939 } finally {
2940 if (view != null && view.getParent() == null) {
2941 Log.w(TAG, "view not successfully added to wm, removing view");
2942 wm.removeViewImmediate(view);
2943 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002944 }
2945
2946 return null;
2947 }
2948
Jorim Jaggi7d0d1022017-02-23 15:35:51 +01002949 private void addSplashscreenContent(PhoneWindow win, Context ctx) {
2950 final TypedArray a = ctx.obtainStyledAttributes(R.styleable.Window);
2951 final int resId = a.getResourceId(R.styleable.Window_windowSplashscreenContent, 0);
2952 a.recycle();
2953 if (resId == 0) {
2954 return;
2955 }
2956 final Drawable drawable = ctx.getDrawable(resId);
2957 if (drawable == null) {
2958 return;
2959 }
2960
2961 // We wrap this into a view so the system insets get applied to the drawable.
2962 final View v = new View(ctx);
2963 v.setBackground(drawable);
2964 win.setContentView(v);
2965 }
2966
Andrii Kulianfb1bf692017-01-17 11:17:34 -08002967 /** Obtain proper context for showing splash screen on the provided display. */
2968 private Context getDisplayContext(Context context, int displayId) {
2969 if (displayId == Display.DEFAULT_DISPLAY) {
2970 // The default context fits.
2971 return context;
2972 }
2973
2974 final DisplayManager dm = (DisplayManager) context.getSystemService(DISPLAY_SERVICE);
2975 final Display targetDisplay = dm.getDisplay(displayId);
2976 if (targetDisplay == null) {
2977 // Failed to obtain the non-default display where splash screen should be shown,
2978 // lets not show at all.
2979 return null;
2980 }
2981
2982 return context.createDisplayContext(targetDisplay);
2983 }
2984
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002985 /**
2986 * Preflight adding a window to the system.
RoboErik8a2cfc32014-05-16 11:19:38 -07002987 *
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002988 * Currently enforces that three window types are singletons:
2989 * <ul>
2990 * <li>STATUS_BAR_TYPE</li>
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002991 * <li>KEYGUARD_TYPE</li>
2992 * </ul>
RoboErik8a2cfc32014-05-16 11:19:38 -07002993 *
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002994 * @param win The window to be added
2995 * @param attrs Information about the window to be added
RoboErik8a2cfc32014-05-16 11:19:38 -07002996 *
Jeff Brown98365d72012-08-19 20:30:52 -07002997 * @return If ok, WindowManagerImpl.ADD_OKAY. If too many singletons,
2998 * WindowManagerImpl.ADD_MULTIPLE_SINGLETON
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002999 */
Jose Lima9546b202014-07-02 17:21:51 -07003000 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003001 public int prepareAddWindowLw(WindowState win, WindowManager.LayoutParams attrs) {
3002 switch (attrs.type) {
3003 case TYPE_STATUS_BAR:
Joe Onorato8bc6c512010-06-04 16:21:12 -04003004 mContext.enforceCallingOrSelfPermission(
3005 android.Manifest.permission.STATUS_BAR_SERVICE,
3006 "PhoneWindowManager");
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003007 if (mStatusBar != null) {
Dianne Hackbornf87d1962012-04-04 12:48:24 -07003008 if (mStatusBar.isAlive()) {
Jeff Brown98365d72012-08-19 20:30:52 -07003009 return WindowManagerGlobal.ADD_MULTIPLE_SINGLETON;
Dianne Hackbornf87d1962012-04-04 12:48:24 -07003010 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003011 }
3012 mStatusBar = win;
John Spurlock27735a42013-08-14 17:57:38 -04003013 mStatusBarController.setWindow(win);
Jorim Jaggi9ba2e102017-04-04 12:51:03 +02003014 setKeyguardOccludedLw(mKeyguardOccluded, true /* force */);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003015 break;
Daniel Sandler8956dbb2011-04-22 07:55:02 -04003016 case TYPE_NAVIGATION_BAR:
3017 mContext.enforceCallingOrSelfPermission(
3018 android.Manifest.permission.STATUS_BAR_SERVICE,
3019 "PhoneWindowManager");
Dianne Hackbornf87d1962012-04-04 12:48:24 -07003020 if (mNavigationBar != null) {
3021 if (mNavigationBar.isAlive()) {
Jeff Brown98365d72012-08-19 20:30:52 -07003022 return WindowManagerGlobal.ADD_MULTIPLE_SINGLETON;
Dianne Hackbornf87d1962012-04-04 12:48:24 -07003023 }
3024 }
Daniel Sandler8956dbb2011-04-22 07:55:02 -04003025 mNavigationBar = win;
John Spurlock27735a42013-08-14 17:57:38 -04003026 mNavigationBarController.setWindow(win);
Casey Burkhardt048c2bc2016-12-08 16:09:20 -08003027 mNavigationBarController.setOnBarVisibilityChangedListener(
Casey Burkhardt469a2082017-06-13 20:12:42 -07003028 mNavBarVisibilityListener, true);
Craig Mautnereda67292013-04-28 13:50:14 -07003029 if (DEBUG_LAYOUT) Slog.i(TAG, "NAVIGATION BAR: " + mNavigationBar);
Daniel Sandler8956dbb2011-04-22 07:55:02 -04003030 break;
Jim Millere898ac52012-04-06 17:10:57 -07003031 case TYPE_NAVIGATION_BAR_PANEL:
Dianne Hackborn08743722009-12-21 12:16:51 -08003032 case TYPE_STATUS_BAR_PANEL:
Joe Onorato29fc2c92010-11-24 10:26:50 -08003033 case TYPE_STATUS_BAR_SUB_PANEL:
Jorim Jaggi225d3b52015-04-01 11:18:57 -07003034 case TYPE_VOICE_INTERACTION_STARTING:
Joe Onorato29fc2c92010-11-24 10:26:50 -08003035 mContext.enforceCallingOrSelfPermission(
3036 android.Manifest.permission.STATUS_BAR_SERVICE,
3037 "PhoneWindowManager");
Joe Onorato29fc2c92010-11-24 10:26:50 -08003038 break;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003039 }
Wale Ogunwale5cd907d2017-01-26 14:14:08 -08003040 return ADD_OKAY;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003041 }
3042
3043 /** {@inheritDoc} */
Jose Lima9546b202014-07-02 17:21:51 -07003044 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003045 public void removeWindowLw(WindowState win) {
3046 if (mStatusBar == win) {
3047 mStatusBar = null;
John Spurlock27735a42013-08-14 17:57:38 -04003048 mStatusBarController.setWindow(null);
Jorim Jaggi73294b62016-10-26 18:02:36 -07003049 } else if (mNavigationBar == win) {
Daniel Sandler8956dbb2011-04-22 07:55:02 -04003050 mNavigationBar = null;
John Spurlock27735a42013-08-14 17:57:38 -04003051 mNavigationBarController.setWindow(null);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003052 }
3053 }
3054
3055 static final boolean PRINT_ANIM = false;
RoboErik8a2cfc32014-05-16 11:19:38 -07003056
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003057 /** {@inheritDoc} */
Craig Mautner4b71aa12012-12-27 17:20:01 -08003058 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003059 public int selectAnimationLw(WindowState win, int transit) {
3060 if (PRINT_ANIM) Log.i(TAG, "selectAnimation in " + win
3061 + ": transit=" + transit);
Dianne Hackbornf87d1962012-04-04 12:48:24 -07003062 if (win == mStatusBar) {
Jorim Jaggi67b29d52017-06-09 18:00:00 -07003063 final boolean isKeyguard = (win.getAttrs().privateFlags & PRIVATE_FLAG_KEYGUARD) != 0;
3064 final boolean expanded = win.getAttrs().height == MATCH_PARENT
3065 && win.getAttrs().width == MATCH_PARENT;
3066 if (isKeyguard || expanded) {
3067 return -1;
3068 }
Craig Mautner4b71aa12012-12-27 17:20:01 -08003069 if (transit == TRANSIT_EXIT
3070 || transit == TRANSIT_HIDE) {
Jorim Jaggi67b29d52017-06-09 18:00:00 -07003071 return R.anim.dock_top_exit;
Craig Mautner4b71aa12012-12-27 17:20:01 -08003072 } else if (transit == TRANSIT_ENTER
3073 || transit == TRANSIT_SHOW) {
Jorim Jaggi67b29d52017-06-09 18:00:00 -07003074 return R.anim.dock_top_enter;
Dianne Hackbornf87d1962012-04-04 12:48:24 -07003075 }
3076 } else if (win == mNavigationBar) {
Jorim Jaggi0d210f62015-07-10 14:24:44 -07003077 if (win.getAttrs().windowAnimations != 0) {
3078 return 0;
3079 }
Adrian Roos85d202b2016-06-02 16:27:47 -07003080 // This can be on either the bottom or the right or the left.
3081 if (mNavigationBarPosition == NAV_BAR_BOTTOM) {
Craig Mautner4b71aa12012-12-27 17:20:01 -08003082 if (transit == TRANSIT_EXIT
3083 || transit == TRANSIT_HIDE) {
Jorim Jaggi48832812016-09-06 12:38:23 -07003084 if (isKeyguardShowingAndNotOccluded()) {
3085 return R.anim.dock_bottom_exit_keyguard;
3086 } else {
3087 return R.anim.dock_bottom_exit;
3088 }
Craig Mautner4b71aa12012-12-27 17:20:01 -08003089 } else if (transit == TRANSIT_ENTER
3090 || transit == TRANSIT_SHOW) {
Dianne Hackbornf87d1962012-04-04 12:48:24 -07003091 return R.anim.dock_bottom_enter;
3092 }
Adrian Roos85d202b2016-06-02 16:27:47 -07003093 } else if (mNavigationBarPosition == NAV_BAR_RIGHT) {
Craig Mautner4b71aa12012-12-27 17:20:01 -08003094 if (transit == TRANSIT_EXIT
3095 || transit == TRANSIT_HIDE) {
Dianne Hackbornf87d1962012-04-04 12:48:24 -07003096 return R.anim.dock_right_exit;
Craig Mautner4b71aa12012-12-27 17:20:01 -08003097 } else if (transit == TRANSIT_ENTER
3098 || transit == TRANSIT_SHOW) {
Dianne Hackbornf87d1962012-04-04 12:48:24 -07003099 return R.anim.dock_right_enter;
3100 }
Adrian Roos85d202b2016-06-02 16:27:47 -07003101 } else if (mNavigationBarPosition == NAV_BAR_LEFT) {
3102 if (transit == TRANSIT_EXIT
3103 || transit == TRANSIT_HIDE) {
3104 return R.anim.dock_left_exit;
3105 } else if (transit == TRANSIT_ENTER
3106 || transit == TRANSIT_SHOW) {
3107 return R.anim.dock_left_enter;
3108 }
Dianne Hackbornf87d1962012-04-04 12:48:24 -07003109 }
Filip Gruszczynski57f76f12015-11-04 16:10:54 -08003110 } else if (win.getAttrs().type == TYPE_DOCK_DIVIDER) {
Jorim Jaggi81ba11e2016-02-03 22:04:22 -08003111 return selectDockedDividerAnimationLw(win, transit);
Craig Mautner4b71aa12012-12-27 17:20:01 -08003112 }
3113
3114 if (transit == TRANSIT_PREVIEW_DONE) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003115 if (win.hasAppShownWindows()) {
3116 if (PRINT_ANIM) Log.i(TAG, "**** STARTING EXIT");
3117 return com.android.internal.R.anim.app_starting_exit;
3118 }
Dianne Hackborn7ad44382012-10-18 17:46:00 -07003119 } else if (win.getAttrs().type == TYPE_DREAM && mDreamingLockscreen
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07003120 && transit == TRANSIT_ENTER) {
3121 // Special case: we are animating in a dream, while the keyguard
3122 // is shown. We don't want an animation on the dream, because
3123 // we need it shown immediately with the keyguard animating away
3124 // to reveal it.
3125 return -1;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003126 }
3127
3128 return 0;
3129 }
3130
Jorim Jaggi81ba11e2016-02-03 22:04:22 -08003131 private int selectDockedDividerAnimationLw(WindowState win, int transit) {
3132 int insets = mWindowManagerFuncs.getDockedDividerInsetsLw();
3133
3134 // If the divider is behind the navigation bar, don't animate.
Jorim Jaggi0cb0f722016-03-25 20:49:41 -07003135 final Rect frame = win.getFrameLw();
3136 final boolean behindNavBar = mNavigationBar != null
Adrian Roos85d202b2016-06-02 16:27:47 -07003137 && ((mNavigationBarPosition == NAV_BAR_BOTTOM
Jorim Jaggi0cb0f722016-03-25 20:49:41 -07003138 && frame.top + insets >= mNavigationBar.getFrameLw().top)
Adrian Roos85d202b2016-06-02 16:27:47 -07003139 || (mNavigationBarPosition == NAV_BAR_RIGHT
3140 && frame.left + insets >= mNavigationBar.getFrameLw().left)
3141 || (mNavigationBarPosition == NAV_BAR_LEFT
3142 && frame.right - insets <= mNavigationBar.getFrameLw().right));
Jorim Jaggi0cb0f722016-03-25 20:49:41 -07003143 final boolean landscape = frame.height() > frame.width();
3144 final boolean offscreenLandscape = landscape && (frame.right - insets <= 0
3145 || frame.left + insets >= win.getDisplayFrameLw().right);
3146 final boolean offscreenPortrait = !landscape && (frame.top - insets <= 0
3147 || frame.bottom + insets >= win.getDisplayFrameLw().bottom);
3148 final boolean offscreen = offscreenLandscape || offscreenPortrait;
3149 if (behindNavBar || offscreen) {
Jorim Jaggi81ba11e2016-02-03 22:04:22 -08003150 return 0;
3151 }
3152 if (transit == TRANSIT_ENTER || transit == TRANSIT_SHOW) {
3153 return R.anim.fade_in;
3154 } else if (transit == TRANSIT_EXIT) {
3155 return R.anim.fade_out;
3156 } else {
3157 return 0;
3158 }
3159 }
3160
Craig Mautner3c174372013-02-21 17:54:37 -08003161 @Override
3162 public void selectRotationAnimationLw(int anim[]) {
Adrian Roos7c894802017-07-19 12:25:34 +02003163 // If the screen is off or non-interactive, force a jumpcut.
Adrian Roos3162b8f2017-07-25 15:37:32 +02003164 final boolean forceJumpcut = !mScreenOnFully || !okToAnimate();
Craig Mautner3c174372013-02-21 17:54:37 -08003165 if (PRINT_ANIM) Slog.i(TAG, "selectRotationAnimation mTopFullscreen="
3166 + mTopFullscreenOpaqueWindowState + " rotationAnimation="
3167 + (mTopFullscreenOpaqueWindowState == null ?
Adrian Roos7c894802017-07-19 12:25:34 +02003168 "0" : mTopFullscreenOpaqueWindowState.getAttrs().rotationAnimation)
3169 + " forceJumpcut=" + forceJumpcut);
3170 if (forceJumpcut) {
3171 anim[0] = R.anim.rotation_animation_jump_exit;
3172 anim[1] = R.anim.rotation_animation_enter;
3173 return;
3174 }
Robert Carrfd10cd12016-06-29 16:41:50 -07003175 if (mTopFullscreenOpaqueWindowState != null) {
3176 int animationHint = mTopFullscreenOpaqueWindowState.getRotationAnimationHint();
3177 if (animationHint < 0 && mTopIsFullscreen) {
3178 animationHint = mTopFullscreenOpaqueWindowState.getAttrs().rotationAnimation;
3179 }
3180 switch (animationHint) {
Craig Mautner3c174372013-02-21 17:54:37 -08003181 case ROTATION_ANIMATION_CROSSFADE:
Robert Carr57d9fbd2016-08-15 12:00:35 -07003182 case ROTATION_ANIMATION_SEAMLESS: // Crossfade is fallback for seamless.
Craig Mautner3c174372013-02-21 17:54:37 -08003183 anim[0] = R.anim.rotation_animation_xfade_exit;
3184 anim[1] = R.anim.rotation_animation_enter;
3185 break;
3186 case ROTATION_ANIMATION_JUMPCUT:
3187 anim[0] = R.anim.rotation_animation_jump_exit;
3188 anim[1] = R.anim.rotation_animation_enter;
3189 break;
3190 case ROTATION_ANIMATION_ROTATE:
3191 default:
3192 anim[0] = anim[1] = 0;
3193 break;
3194 }
3195 } else {
3196 anim[0] = anim[1] = 0;
3197 }
3198 }
3199
3200 @Override
3201 public boolean validateRotationAnimationLw(int exitAnimId, int enterAnimId,
3202 boolean forceDefault) {
3203 switch (exitAnimId) {
3204 case R.anim.rotation_animation_xfade_exit:
3205 case R.anim.rotation_animation_jump_exit:
3206 // These are the only cases that matter.
3207 if (forceDefault) {
3208 return false;
3209 }
3210 int anim[] = new int[2];
3211 selectRotationAnimationLw(anim);
3212 return (exitAnimId == anim[0] && enterAnimId == anim[1]);
3213 default:
3214 return true;
3215 }
3216 }
3217
3218 @Override
Jorim Jaggife762342016-10-13 14:33:27 +02003219 public Animation createHiddenByKeyguardExit(boolean onWallpaper,
Jorim Jaggi84a3e7a2014-08-13 17:58:58 +02003220 boolean goingToNotificationShade) {
3221 if (goingToNotificationShade) {
3222 return AnimationUtils.loadAnimation(mContext, R.anim.lock_screen_behind_enter_fade_in);
Craig Mautnerb8340802014-11-04 15:32:57 -08003223 }
Craig Mautner276a6eb2014-11-04 15:32:57 -08003224
3225 AnimationSet set = (AnimationSet) AnimationUtils.loadAnimation(mContext, onWallpaper ?
3226 R.anim.lock_screen_behind_enter_wallpaper :
3227 R.anim.lock_screen_behind_enter);
3228
3229 // TODO: Use XML interpolators when we have log interpolators available in XML.
3230 final List<Animation> animations = set.getAnimations();
3231 for (int i = animations.size() - 1; i >= 0; --i) {
3232 animations.get(i).setInterpolator(mLogDecelerateInterpolator);
3233 }
3234
3235 return set;
Jorim Jaggi76a16232014-08-08 17:00:47 +02003236 }
3237
3238
3239 @Override
Jorim Jaggife762342016-10-13 14:33:27 +02003240 public Animation createKeyguardWallpaperExit(boolean goingToNotificationShade) {
Jorim Jaggi84a3e7a2014-08-13 17:58:58 +02003241 if (goingToNotificationShade) {
3242 return null;
3243 } else {
3244 return AnimationUtils.loadAnimation(mContext, R.anim.lock_screen_wallpaper_exit);
3245 }
Dianne Hackborn01ad2f42009-09-24 19:24:56 -07003246 }
John Spurlockc8b46ca2013-04-08 12:59:26 -04003247
3248 private static void awakenDreams() {
3249 IDreamManager dreamManager = getDreamManager();
3250 if (dreamManager != null) {
3251 try {
3252 dreamManager.awaken();
3253 } catch (RemoteException e) {
3254 // fine, stay asleep then
3255 }
3256 }
3257 }
3258
3259 static IDreamManager getDreamManager() {
3260 return IDreamManager.Stub.asInterface(
3261 ServiceManager.checkService(DreamService.DREAM_SERVICE));
3262 }
3263
Tyler Gunnef9f6f92014-09-12 22:16:17 -07003264 TelecomManager getTelecommService() {
3265 return (TelecomManager) mContext.getSystemService(Context.TELECOM_SERVICE);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003266 }
3267
Jeff Brown4d396052010-10-29 21:50:21 -07003268 static IAudioService getAudioService() {
3269 IAudioService audioService = IAudioService.Stub.asInterface(
3270 ServiceManager.checkService(Context.AUDIO_SERVICE));
3271 if (audioService == null) {
3272 Log.w(TAG, "Unable to find IAudioService interface.");
3273 }
3274 return audioService;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003275 }
3276
3277 boolean keyguardOn() {
Jim Millerab954542014-10-10 18:21:49 -07003278 return isKeyguardShowingAndNotOccluded() || inKeyguardRestrictedKeyInputMode();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003279 }
3280
3281 private static final int[] WINDOW_TYPES_WHERE_HOME_DOESNT_WORK = {
3282 WindowManager.LayoutParams.TYPE_SYSTEM_ALERT,
3283 WindowManager.LayoutParams.TYPE_SYSTEM_ERROR,
3284 };
3285
3286 /** {@inheritDoc} */
Jeff Brown00fa7bd2010-07-02 15:37:36 -07003287 @Override
Jeff Brownd5bb82d2011-10-12 13:57:59 -07003288 public long interceptKeyBeforeDispatching(WindowState win, KeyEvent event, int policyFlags) {
Jeff Brown00fa7bd2010-07-02 15:37:36 -07003289 final boolean keyguardOn = keyguardOn();
Jeff Brown1f245102010-11-18 20:53:46 -08003290 final int keyCode = event.getKeyCode();
3291 final int repeatCount = event.getRepeatCount();
3292 final int metaState = event.getMetaState();
Jeff Brownd5bb82d2011-10-12 13:57:59 -07003293 final int flags = event.getFlags();
Jeff Brown1f245102010-11-18 20:53:46 -08003294 final boolean down = event.getAction() == KeyEvent.ACTION_DOWN;
3295 final boolean canceled = event.isCanceled();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003296
Jeff Brown40013652012-05-16 21:22:36 -07003297 if (DEBUG_INPUT) {
Jeff Brown00fa7bd2010-07-02 15:37:36 -07003298 Log.d(TAG, "interceptKeyTi keyCode=" + keyCode + " down=" + down + " repeatCount="
Jeff Brownfd23e3e2012-05-09 13:34:28 -07003299 + repeatCount + " keyguardOn=" + keyguardOn + " mHomePressed=" + mHomePressed
3300 + " canceled=" + canceled);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003301 }
3302
Jeff Brownd5bb82d2011-10-12 13:57:59 -07003303 // If we think we might have a volume down & power key chord on the way
3304 // but we're not sure, then tell the dispatcher to wait a little while and
3305 // try again later before dispatching.
Christopher Tatee90585f2012-03-05 18:56:25 -08003306 if (mScreenshotChordEnabled && (flags & KeyEvent.FLAG_FALLBACK) == 0) {
Jeff Brown13f00f02014-10-31 14:45:50 -07003307 if (mScreenshotChordVolumeDownKeyTriggered && !mScreenshotChordPowerKeyTriggered) {
Jeff Brownd5bb82d2011-10-12 13:57:59 -07003308 final long now = SystemClock.uptimeMillis();
Jeff Brown13f00f02014-10-31 14:45:50 -07003309 final long timeoutTime = mScreenshotChordVolumeDownKeyTime
3310 + SCREENSHOT_CHORD_DEBOUNCE_DELAY_MILLIS;
Jeff Brownd5bb82d2011-10-12 13:57:59 -07003311 if (now < timeoutTime) {
3312 return timeoutTime - now;
3313 }
3314 }
3315 if (keyCode == KeyEvent.KEYCODE_VOLUME_DOWN
Jeff Brown13f00f02014-10-31 14:45:50 -07003316 && mScreenshotChordVolumeDownKeyConsumed) {
Jeff Brownd5bb82d2011-10-12 13:57:59 -07003317 if (!down) {
Jeff Brown13f00f02014-10-31 14:45:50 -07003318 mScreenshotChordVolumeDownKeyConsumed = false;
Jeff Brownd5bb82d2011-10-12 13:57:59 -07003319 }
3320 return -1;
3321 }
3322 }
3323
Phil Weaver106fe732016-11-22 18:18:39 -08003324 // If an accessibility shortcut might be partially complete, hold off dispatching until we
3325 // know if it is complete or not
Phil Weaverce687c52017-03-15 08:51:52 -07003326 if (mAccessibilityShortcutController.isAccessibilityShortcutAvailable(false)
Phil Weaver106fe732016-11-22 18:18:39 -08003327 && (flags & KeyEvent.FLAG_FALLBACK) == 0) {
3328 if (mScreenshotChordVolumeDownKeyTriggered ^ mA11yShortcutChordVolumeUpKeyTriggered) {
3329 final long now = SystemClock.uptimeMillis();
3330 final long timeoutTime = (mScreenshotChordVolumeDownKeyTriggered
3331 ? mScreenshotChordVolumeDownKeyTime : mA11yShortcutChordVolumeUpKeyTime)
3332 + SCREENSHOT_CHORD_DEBOUNCE_DELAY_MILLIS;
3333 if (now < timeoutTime) {
3334 return timeoutTime - now;
3335 }
3336 }
3337 if (keyCode == KeyEvent.KEYCODE_VOLUME_DOWN && mScreenshotChordVolumeDownKeyConsumed) {
3338 if (!down) {
3339 mScreenshotChordVolumeDownKeyConsumed = false;
3340 }
3341 return -1;
3342 }
3343 if (keyCode == KeyEvent.KEYCODE_VOLUME_UP && mA11yShortcutChordVolumeUpKeyConsumed) {
3344 if (!down) {
3345 mA11yShortcutChordVolumeUpKeyConsumed = false;
3346 }
3347 return -1;
3348 }
3349 }
3350
Michael Wright6a62e552014-06-03 19:19:48 -07003351 // Cancel any pending meta actions if we see any other keys being pressed between the down
3352 // of the meta key and its corresponding up.
Michael Wright251e35d2014-08-22 15:40:27 -07003353 if (mPendingMetaAction && !KeyEvent.isMetaKey(keyCode)) {
Michael Wright6a62e552014-06-03 19:19:48 -07003354 mPendingMetaAction = false;
3355 }
Andrii Kulian112d0562016-03-08 10:44:22 -08003356 // Any key that is not Alt or Meta cancels Caps Lock combo tracking.
3357 if (mPendingCapsLockToggle && !KeyEvent.isMetaKey(keyCode) && !KeyEvent.isAltKey(keyCode)) {
3358 mPendingCapsLockToggle = false;
3359 }
Michael Wright6a62e552014-06-03 19:19:48 -07003360
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003361 // First we always handle the home key here, so applications
3362 // can never break it, although if keyguard is on, we do let
3363 // it handle it, because that gives us the correct 5 second
3364 // timeout.
Jeff Brown00fa7bd2010-07-02 15:37:36 -07003365 if (keyCode == KeyEvent.KEYCODE_HOME) {
Michael Jurka7f2668c2012-03-27 07:49:52 -07003366
Jeff Brown49ed71d2010-12-06 17:13:33 -08003367 // If we have released the home key, and didn't do anything else
3368 // while it was pressed, then it is time to go home!
Michael Jurka7f2668c2012-03-27 07:49:52 -07003369 if (!down) {
Jeff Browncaca8812013-05-09 13:34:33 -07003370 cancelPreloadRecentApps();
3371
Sujith Ramakrishnan6bed9bd2017-04-26 12:33:37 -07003372 if (mHasFeatureLeanback) {
3373 // Clear flags
3374 mAccessibilityTvKey2Pressed = down;
3375 }
3376
Jeff Brown49ed71d2010-12-06 17:13:33 -08003377 mHomePressed = false;
Jeff Browncaca8812013-05-09 13:34:33 -07003378 if (mHomeConsumed) {
3379 mHomeConsumed = false;
Michael Jurka7f2668c2012-03-27 07:49:52 -07003380 return -1;
Jeff Brown49ed71d2010-12-06 17:13:33 -08003381 }
Jeff Browncaca8812013-05-09 13:34:33 -07003382
3383 if (canceled) {
3384 Log.i(TAG, "Ignoring HOME; event canceled.");
3385 return -1;
3386 }
3387
Jeff Browncaca8812013-05-09 13:34:33 -07003388 // Delay handling home if a double-tap is possible.
3389 if (mDoubleTapOnHomeBehavior != DOUBLE_TAP_HOME_NOTHING) {
3390 mHandler.removeCallbacks(mHomeDoubleTapTimeoutRunnable); // just in case
3391 mHomeDoubleTapPending = true;
3392 mHandler.postDelayed(mHomeDoubleTapTimeoutRunnable,
3393 ViewConfiguration.getDoubleTapTimeout());
3394 return -1;
3395 }
3396
Jeff Brown13f00f02014-10-31 14:45:50 -07003397 handleShortPressOnHome();
Jeff Browncaca8812013-05-09 13:34:33 -07003398 return -1;
Jeff Brown49ed71d2010-12-06 17:13:33 -08003399 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003400
3401 // If a system window has focus, then it doesn't make sense
3402 // right now to interact with applications.
3403 WindowManager.LayoutParams attrs = win != null ? win.getAttrs() : null;
3404 if (attrs != null) {
3405 final int type = attrs.type;
Jorim Jaggi73294b62016-10-26 18:02:36 -07003406 if (type == TYPE_KEYGUARD_DIALOG
Jorim Jaggi380ecb82014-03-14 17:25:20 +01003407 || (attrs.privateFlags & PRIVATE_FLAG_KEYGUARD) != 0) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003408 // the "app" is keyguard, so give it the key
Jeff Brownd5bb82d2011-10-12 13:57:59 -07003409 return 0;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003410 }
3411 final int typeCount = WINDOW_TYPES_WHERE_HOME_DOESNT_WORK.length;
3412 for (int i=0; i<typeCount; i++) {
3413 if (type == WINDOW_TYPES_WHERE_HOME_DOESNT_WORK[i]) {
3414 // don't do anything, but also don't pass it to the app
Jeff Brownd5bb82d2011-10-12 13:57:59 -07003415 return -1;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003416 }
3417 }
3418 }
Jeff Browncaca8812013-05-09 13:34:33 -07003419
3420 // Remember that home is pressed and handle special actions.
3421 if (repeatCount == 0) {
3422 mHomePressed = true;
3423 if (mHomeDoubleTapPending) {
3424 mHomeDoubleTapPending = false;
3425 mHandler.removeCallbacks(mHomeDoubleTapTimeoutRunnable);
3426 handleDoubleTapOnHome();
Sid Soundararajanff662fa2017-03-15 16:24:24 -07003427 } else if (mDoubleTapOnHomeBehavior == DOUBLE_TAP_HOME_RECENT_SYSTEM_UI) {
Jeff Browncaca8812013-05-09 13:34:33 -07003428 preloadRecentApps();
Michael Jurka7f2668c2012-03-27 07:49:52 -07003429 }
Jeff Browncaca8812013-05-09 13:34:33 -07003430 } else if ((event.getFlags() & KeyEvent.FLAG_LONG_PRESS) != 0) {
Sujith Ramakrishnan6bed9bd2017-04-26 12:33:37 -07003431 if (mHasFeatureLeanback) {
3432 mAccessibilityTvKey2Pressed = down;
3433 if (interceptAccessibilityGestureTv()) {
3434 return -1;
3435 }
3436 }
3437
Jeff Browncaca8812013-05-09 13:34:33 -07003438 if (!keyguardOn) {
Jaewan Kim76b7d0d2016-02-12 19:01:02 +09003439 handleLongPressOnHome(event.getDeviceId());
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003440 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003441 }
Jeff Brownd5bb82d2011-10-12 13:57:59 -07003442 return -1;
Jeff Brown00fa7bd2010-07-02 15:37:36 -07003443 } else if (keyCode == KeyEvent.KEYCODE_MENU) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003444 // Hijack modified menu keys for debugging features
3445 final int chordBug = KeyEvent.META_SHIFT_ON;
3446
3447 if (down && repeatCount == 0) {
Jeff Brown00fa7bd2010-07-02 15:37:36 -07003448 if (mEnableShiftMenuBugReports && (metaState & chordBug) == chordBug) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003449 Intent intent = new Intent(Intent.ACTION_BUG_REPORT);
Dianne Hackborn5ac72a22012-08-29 18:32:08 -07003450 mContext.sendOrderedBroadcastAsUser(intent, UserHandle.CURRENT,
3451 null, null, null, 0, null, null);
Jeff Brownd5bb82d2011-10-12 13:57:59 -07003452 return -1;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003453 }
3454 }
Jeff Brown00fa7bd2010-07-02 15:37:36 -07003455 } else if (keyCode == KeyEvent.KEYCODE_SEARCH) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003456 if (down) {
3457 if (repeatCount == 0) {
Jeff Brownfd23e3e2012-05-09 13:34:28 -07003458 mSearchKeyShortcutPending = true;
3459 mConsumeSearchKeyUp = false;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003460 }
Jeff Brownfd23e3e2012-05-09 13:34:28 -07003461 } else {
3462 mSearchKeyShortcutPending = false;
3463 if (mConsumeSearchKeyUp) {
3464 mConsumeSearchKeyUp = false;
Jeff Brownd5bb82d2011-10-12 13:57:59 -07003465 return -1;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003466 }
3467 }
Jeff Brownd5bb82d2011-10-12 13:57:59 -07003468 return 0;
Jeff Brown49ed71d2010-12-06 17:13:33 -08003469 } else if (keyCode == KeyEvent.KEYCODE_APP_SWITCH) {
Michael Wrightc9ebea72013-01-16 19:25:02 -08003470 if (!keyguardOn) {
Jeff Browncaca8812013-05-09 13:34:33 -07003471 if (down && repeatCount == 0) {
3472 preloadRecentApps();
3473 } else if (!down) {
3474 toggleRecentApps();
Michael Wrightc9ebea72013-01-16 19:25:02 -08003475 }
Jeff Brown49ed71d2010-12-06 17:13:33 -08003476 }
Jeff Brownd5bb82d2011-10-12 13:57:59 -07003477 return -1;
Jun Mukaid21b3c82015-04-23 14:09:34 -07003478 } else if (keyCode == KeyEvent.KEYCODE_N && event.isMetaPressed()) {
3479 if (down) {
3480 IStatusBarService service = getStatusBarService();
3481 if (service != null) {
3482 try {
3483 service.expandNotificationsPanel();
3484 } catch (RemoteException e) {
3485 // do nothing.
3486 }
3487 }
3488 }
Muyuan Li6ca619f2016-03-08 13:30:42 -08003489 } else if (keyCode == KeyEvent.KEYCODE_S && event.isMetaPressed()
3490 && event.isCtrlPressed()) {
3491 if (down && repeatCount == 0) {
3492 int type = event.isShiftPressed() ? TAKE_SCREENSHOT_SELECTED_REGION
3493 : TAKE_SCREENSHOT_FULLSCREEN;
3494 mScreenshotRunnable.setScreenshotType(type);
3495 mHandler.post(mScreenshotRunnable);
3496 return -1;
3497 }
Clara Bayarrif2debb12015-07-10 14:47:17 +01003498 } else if (keyCode == KeyEvent.KEYCODE_SLASH && event.isMetaPressed()) {
Andrei Stingaceanu002f7122016-03-30 12:22:05 +01003499 if (down && repeatCount == 0 && !isKeyguardLocked()) {
3500 toggleKeyboardShortcutsMenu(event.getDeviceId());
Clara Bayarrif2debb12015-07-10 14:47:17 +01003501 }
Jeff Brownde7a8ea2012-06-13 18:28:57 -07003502 } else if (keyCode == KeyEvent.KEYCODE_ASSIST) {
3503 if (down) {
3504 if (repeatCount == 0) {
3505 mAssistKeyLongPressed = false;
3506 } else if (repeatCount == 1) {
3507 mAssistKeyLongPressed = true;
3508 if (!keyguardOn) {
3509 launchAssistLongPressAction();
3510 }
3511 }
3512 } else {
3513 if (mAssistKeyLongPressed) {
3514 mAssistKeyLongPressed = false;
3515 } else {
3516 if (!keyguardOn) {
Tim Kilbourn0e5f1102015-06-05 16:18:09 -07003517 launchAssistAction(null, event.getDeviceId());
Jeff Brownde7a8ea2012-06-13 18:28:57 -07003518 }
3519 }
3520 }
3521 return -1;
Michael Wrightdc63f7b2014-08-21 19:05:21 -07003522 } else if (keyCode == KeyEvent.KEYCODE_VOICE_ASSIST) {
3523 if (!down) {
3524 Intent voiceIntent;
Michael Wright869a67c2014-08-26 19:33:06 -07003525 if (!keyguardOn) {
Michael Wrightdc63f7b2014-08-21 19:05:21 -07003526 voiceIntent = new Intent(RecognizerIntent.ACTION_WEB_SEARCH);
3527 } else {
Dianne Hackbornb6683c42015-06-18 17:40:33 -07003528 IDeviceIdleController dic = IDeviceIdleController.Stub.asInterface(
3529 ServiceManager.getService(Context.DEVICE_IDLE_CONTROLLER));
3530 if (dic != null) {
3531 try {
3532 dic.exitIdle("voice-search");
3533 } catch (RemoteException e) {
3534 }
3535 }
Michael Wrightdc63f7b2014-08-21 19:05:21 -07003536 voiceIntent = new Intent(RecognizerIntent.ACTION_VOICE_SEARCH_HANDS_FREE);
Michael Wright869a67c2014-08-26 19:33:06 -07003537 voiceIntent.putExtra(RecognizerIntent.EXTRA_SECURE, true);
Michael Wrightdc63f7b2014-08-21 19:05:21 -07003538 }
Bart Sears8b1c27c2015-03-18 23:51:02 +00003539 startActivityAsUser(voiceIntent, UserHandle.CURRENT_OR_SELF);
Michael Wrightdc63f7b2014-08-21 19:05:21 -07003540 }
Jeff Sharkey2991fa32012-12-05 18:06:43 -08003541 } else if (keyCode == KeyEvent.KEYCODE_SYSRQ) {
3542 if (down && repeatCount == 0) {
Muyuan Li6ca619f2016-03-08 13:30:42 -08003543 mScreenshotRunnable.setScreenshotType(TAKE_SCREENSHOT_FULLSCREEN);
Jeff Sharkey2991fa32012-12-05 18:06:43 -08003544 mHandler.post(mScreenshotRunnable);
3545 }
3546 return -1;
Michael Wrightb854e242013-02-05 17:54:02 -08003547 } else if (keyCode == KeyEvent.KEYCODE_BRIGHTNESS_UP
3548 || keyCode == KeyEvent.KEYCODE_BRIGHTNESS_DOWN) {
3549 if (down) {
3550 int direction = keyCode == KeyEvent.KEYCODE_BRIGHTNESS_UP ? 1 : -1;
3551
3552 // Disable autobrightness if it's on
3553 int auto = Settings.System.getIntForUser(
3554 mContext.getContentResolver(),
3555 Settings.System.SCREEN_BRIGHTNESS_MODE,
3556 Settings.System.SCREEN_BRIGHTNESS_MODE_MANUAL,
3557 UserHandle.USER_CURRENT_OR_SELF);
3558 if (auto != 0) {
3559 Settings.System.putIntForUser(mContext.getContentResolver(),
3560 Settings.System.SCREEN_BRIGHTNESS_MODE,
3561 Settings.System.SCREEN_BRIGHTNESS_MODE_MANUAL,
3562 UserHandle.USER_CURRENT_OR_SELF);
3563 }
3564
3565 int min = mPowerManager.getMinimumScreenBrightnessSetting();
3566 int max = mPowerManager.getMaximumScreenBrightnessSetting();
3567 int step = (max - min + BRIGHTNESS_STEPS - 1) / BRIGHTNESS_STEPS * direction;
3568 int brightness = Settings.System.getIntForUser(mContext.getContentResolver(),
3569 Settings.System.SCREEN_BRIGHTNESS,
3570 mPowerManager.getDefaultScreenBrightnessSetting(),
3571 UserHandle.USER_CURRENT_OR_SELF);
3572 brightness += step;
3573 // Make sure we don't go beyond the limits.
3574 brightness = Math.min(max, brightness);
3575 brightness = Math.max(min, brightness);
3576
3577 Settings.System.putIntForUser(mContext.getContentResolver(),
3578 Settings.System.SCREEN_BRIGHTNESS, brightness,
3579 UserHandle.USER_CURRENT_OR_SELF);
Bart Sears8b1c27c2015-03-18 23:51:02 +00003580 startActivityAsUser(new Intent(Intent.ACTION_SHOW_BRIGHTNESS_DIALOG),
Alan Viverette5a399492014-07-14 16:19:38 -07003581 UserHandle.CURRENT_OR_SELF);
Michael Wrightb854e242013-02-05 17:54:02 -08003582 }
3583 return -1;
Jaewan Kim765487f2016-01-12 14:45:42 +09003584 } else if (keyCode == KeyEvent.KEYCODE_VOLUME_UP
3585 || keyCode == KeyEvent.KEYCODE_VOLUME_DOWN
3586 || keyCode == KeyEvent.KEYCODE_VOLUME_MUTE) {
Karthik Ravi Shankar86ecf342017-04-28 15:35:58 -07003587 if (mUseTvRouting || mHandleVolumeKeysInWM) {
3588 // On TVs or when the configuration is enabled, volume keys never
3589 // go to the foreground app.
Jaewan Kim765487f2016-01-12 14:45:42 +09003590 dispatchDirectAudioEvent(event);
3591 return -1;
3592 }
Karthik Ravi Shankar86ecf342017-04-28 15:35:58 -07003593
3594 // If the device is in Vr mode, drop the volume keys and don't
3595 // forward it to the application/dispatch the audio event.
3596 if (mPersistentVrModeEnabled) {
3597 return -1;
3598 }
Evan Rosky516f9e62017-01-23 16:43:52 -08003599 } else if (keyCode == KeyEvent.KEYCODE_TAB && event.isMetaPressed()) {
3600 // Pass through keyboard navigation keys.
3601 return 0;
Dmitri Plotnikov82e6dfc2017-02-24 18:10:54 -08003602 } else if (mHasFeatureLeanback && interceptBugreportGestureTv(keyCode, down)) {
3603 return -1;
Sujith Ramakrishnan6bed9bd2017-04-26 12:33:37 -07003604 } else if (mHasFeatureLeanback && keyCode == KeyEvent.KEYCODE_DPAD_CENTER) {
3605 mAccessibilityTvKey1Pressed = down;
3606 if (interceptAccessibilityGestureTv()) {
3607 return -1;
3608 }
Muyuan Li94ce94e2016-02-24 16:20:54 -08003609 }
3610
Andrii Kulian112d0562016-03-08 10:44:22 -08003611 // Toggle Caps Lock on META-ALT.
3612 boolean actionTriggered = false;
3613 if (KeyEvent.isModifierKey(keyCode)) {
3614 if (!mPendingCapsLockToggle) {
3615 // Start tracking meta state for combo.
3616 mInitialMetaState = mMetaState;
3617 mPendingCapsLockToggle = true;
3618 } else if (event.getAction() == KeyEvent.ACTION_UP) {
3619 int altOnMask = mMetaState & KeyEvent.META_ALT_MASK;
3620 int metaOnMask = mMetaState & KeyEvent.META_META_MASK;
3621
3622 // Check for Caps Lock toggle
3623 if ((metaOnMask != 0) && (altOnMask != 0)) {
3624 // Check if nothing else is pressed
3625 if (mInitialMetaState == (mMetaState ^ (altOnMask | metaOnMask))) {
3626 // Handle Caps Lock Toggle
3627 mInputManagerInternal.toggleCapsLock(event.getDeviceId());
3628 actionTriggered = true;
3629 }
3630 }
3631
3632 // Always stop tracking when key goes up.
3633 mPendingCapsLockToggle = false;
3634 }
3635 }
3636 // Store current meta state to be able to evaluate it later.
3637 mMetaState = metaState;
3638
3639 if (actionTriggered) {
3640 return -1;
3641 }
3642
Muyuan Li94ce94e2016-02-24 16:20:54 -08003643 if (KeyEvent.isMetaKey(keyCode)) {
Michael Wright6a62e552014-06-03 19:19:48 -07003644 if (down) {
3645 mPendingMetaAction = true;
3646 } else if (mPendingMetaAction) {
Tim Kilbourn0e5f1102015-06-05 16:18:09 -07003647 launchAssistAction(Intent.EXTRA_ASSIST_INPUT_HINT_KEYBOARD, event.getDeviceId());
Michael Wright6a62e552014-06-03 19:19:48 -07003648 }
3649 return -1;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003650 }
Jeff Browncaab4d02010-12-09 22:13:41 -08003651
Jeff Brownc1fb48d2010-12-08 16:52:09 -08003652 // Shortcuts are invoked through Search+key, so intercept those here
Jeff Browncaab4d02010-12-09 22:13:41 -08003653 // Any printing key that is chorded with Search should be consumed
3654 // even if no shortcut was invoked. This prevents text from being
3655 // inadvertently inserted when using a keyboard that has built-in macro
3656 // shortcut keys (that emit Search+x) and some of them are not registered.
Jeff Brownfd23e3e2012-05-09 13:34:28 -07003657 if (mSearchKeyShortcutPending) {
Jeff Browncaab4d02010-12-09 22:13:41 -08003658 final KeyCharacterMap kcm = event.getKeyCharacterMap();
3659 if (kcm.isPrintingKey(keyCode)) {
Jeff Brownfd23e3e2012-05-09 13:34:28 -07003660 mConsumeSearchKeyUp = true;
3661 mSearchKeyShortcutPending = false;
Jeff Browncaab4d02010-12-09 22:13:41 -08003662 if (down && repeatCount == 0 && !keyguardOn) {
3663 Intent shortcutIntent = mShortcutManager.getIntent(kcm, keyCode, metaState);
3664 if (shortcutIntent != null) {
3665 shortcutIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
Jeff Brownf0a3cc52011-01-26 18:42:46 -08003666 try {
Bart Sears8b1c27c2015-03-18 23:51:02 +00003667 startActivityAsUser(shortcutIntent, UserHandle.CURRENT);
Andrei Stingaceanu0bf096f2016-04-14 18:11:57 +01003668 dismissKeyboardShortcutsMenu();
Jeff Brownf0a3cc52011-01-26 18:42:46 -08003669 } catch (ActivityNotFoundException ex) {
3670 Slog.w(TAG, "Dropping shortcut key combination because "
3671 + "the activity to which it is registered was not found: "
Jeff Brownfd23e3e2012-05-09 13:34:28 -07003672 + "SEARCH+" + KeyEvent.keyCodeToString(keyCode), ex);
Jeff Brownf0a3cc52011-01-26 18:42:46 -08003673 }
Jeff Browncaab4d02010-12-09 22:13:41 -08003674 } else {
3675 Slog.i(TAG, "Dropping unregistered shortcut key combination: "
Jeff Brownfd23e3e2012-05-09 13:34:28 -07003676 + "SEARCH+" + KeyEvent.keyCodeToString(keyCode));
Jeff Brown49ed71d2010-12-06 17:13:33 -08003677 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003678 }
Jeff Brownd5bb82d2011-10-12 13:57:59 -07003679 return -1;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003680 }
3681 }
3682
Jeff Brown68b909d2011-12-07 16:36:01 -08003683 // Invoke shortcuts using Meta.
Jeff Brown602ab322012-05-16 13:33:47 -07003684 if (down && repeatCount == 0 && !keyguardOn
Jeff Brown68b909d2011-12-07 16:36:01 -08003685 && (metaState & KeyEvent.META_META_ON) != 0) {
3686 final KeyCharacterMap kcm = event.getKeyCharacterMap();
Jeff Brown602ab322012-05-16 13:33:47 -07003687 if (kcm.isPrintingKey(keyCode)) {
3688 Intent shortcutIntent = mShortcutManager.getIntent(kcm, keyCode,
3689 metaState & ~(KeyEvent.META_META_ON
3690 | KeyEvent.META_META_LEFT_ON | KeyEvent.META_META_RIGHT_ON));
3691 if (shortcutIntent != null) {
3692 shortcutIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
3693 try {
Bart Sears8b1c27c2015-03-18 23:51:02 +00003694 startActivityAsUser(shortcutIntent, UserHandle.CURRENT);
Andrei Stingaceanu0bf096f2016-04-14 18:11:57 +01003695 dismissKeyboardShortcutsMenu();
Jeff Brown602ab322012-05-16 13:33:47 -07003696 } catch (ActivityNotFoundException ex) {
3697 Slog.w(TAG, "Dropping shortcut key combination because "
3698 + "the activity to which it is registered was not found: "
3699 + "META+" + KeyEvent.keyCodeToString(keyCode), ex);
3700 }
3701 return -1;
Jeff Brown68b909d2011-12-07 16:36:01 -08003702 }
Jeff Brown68b909d2011-12-07 16:36:01 -08003703 }
3704 }
3705
Jeff Brown6651a632011-11-28 12:59:11 -08003706 // Handle application launch keys.
Jeff Brown602ab322012-05-16 13:33:47 -07003707 if (down && repeatCount == 0 && !keyguardOn) {
Jeff Brown6651a632011-11-28 12:59:11 -08003708 String category = sApplicationLaunchKeyCategories.get(keyCode);
3709 if (category != null) {
Dianne Hackbornf5b86712011-12-05 17:42:41 -08003710 Intent intent = Intent.makeMainSelectorActivity(Intent.ACTION_MAIN, category);
Jeff Brown6651a632011-11-28 12:59:11 -08003711 intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
3712 try {
Bart Sears8b1c27c2015-03-18 23:51:02 +00003713 startActivityAsUser(intent, UserHandle.CURRENT);
Andrei Stingaceanu0bf096f2016-04-14 18:11:57 +01003714 dismissKeyboardShortcutsMenu();
Jeff Brown6651a632011-11-28 12:59:11 -08003715 } catch (ActivityNotFoundException ex) {
3716 Slog.w(TAG, "Dropping application launch key because "
3717 + "the activity to which it is registered was not found: "
3718 + "keyCode=" + keyCode + ", category=" + category, ex);
3719 }
Jeff Brown68b909d2011-12-07 16:36:01 -08003720 return -1;
Jeff Brown6651a632011-11-28 12:59:11 -08003721 }
3722 }
3723
Michael Wright61c46752014-08-21 16:57:33 -07003724 // Display task switcher for ALT-TAB.
Jeff Brown68b909d2011-12-07 16:36:01 -08003725 if (down && repeatCount == 0 && keyCode == KeyEvent.KEYCODE_TAB) {
Michael Wrightd847ad52015-10-24 13:24:15 +01003726 if (mRecentAppsHeldModifiers == 0 && !keyguardOn && isUserSetupComplete()) {
Jeff Brown68b909d2011-12-07 16:36:01 -08003727 final int shiftlessModifiers = event.getModifiers() & ~KeyEvent.META_SHIFT_MASK;
Michael Wright61c46752014-08-21 16:57:33 -07003728 if (KeyEvent.metaStateHasModifiers(shiftlessModifiers, KeyEvent.META_ALT_ON)) {
Winson Chung1e8d71b2014-05-16 17:05:22 -07003729 mRecentAppsHeldModifiers = shiftlessModifiers;
Winson14db3622016-05-09 13:34:07 -07003730 showRecentApps(true, false);
Jeff Brown68b909d2011-12-07 16:36:01 -08003731 return -1;
3732 }
3733 }
Winson Chung1e8d71b2014-05-16 17:05:22 -07003734 } else if (!down && mRecentAppsHeldModifiers != 0
3735 && (metaState & mRecentAppsHeldModifiers) == 0) {
3736 mRecentAppsHeldModifiers = 0;
Winson Chungcdcd4872014-08-05 18:00:13 -07003737 hideRecentApps(true, false);
Jeff Brown68b909d2011-12-07 16:36:01 -08003738 }
3739
Yohei Yukawaae61f712015-12-09 13:00:10 -08003740 // Handle input method switching.
Jeff Browncf39bdf2012-05-18 14:41:19 -07003741 if (down && repeatCount == 0
3742 && (keyCode == KeyEvent.KEYCODE_LANGUAGE_SWITCH
3743 || (keyCode == KeyEvent.KEYCODE_SPACE
Yohei Yukawaae61f712015-12-09 13:00:10 -08003744 && (metaState & KeyEvent.META_META_MASK) != 0))) {
3745 final boolean forwardDirection = (metaState & KeyEvent.META_SHIFT_MASK) == 0;
3746 mWindowManagerFuncs.switchInputMethod(forwardDirection);
Jeff Browncf39bdf2012-05-18 14:41:19 -07003747 return -1;
3748 }
3749 if (mLanguageSwitchKeyPressed && !down
3750 && (keyCode == KeyEvent.KEYCODE_LANGUAGE_SWITCH
3751 || keyCode == KeyEvent.KEYCODE_SPACE)) {
3752 mLanguageSwitchKeyPressed = false;
3753 return -1;
3754 }
3755
Jeff Brown13f00f02014-10-31 14:45:50 -07003756 if (isValidGlobalKey(keyCode)
3757 && mGlobalKeyManager.handleGlobalKey(mContext, keyCode, event)) {
Justin Kohd378ad72013-04-01 12:18:26 -07003758 return -1;
3759 }
3760
Muyuan Li94ce94e2016-02-24 16:20:54 -08003761 if (down) {
Jim Millere4044bb2016-05-10 18:38:25 -07003762 long shortcutCode = keyCode;
Muyuan Li94ce94e2016-02-24 16:20:54 -08003763 if (event.isCtrlPressed()) {
3764 shortcutCode |= ((long) KeyEvent.META_CTRL_ON) << Integer.SIZE;
3765 }
3766
3767 if (event.isAltPressed()) {
3768 shortcutCode |= ((long) KeyEvent.META_ALT_ON) << Integer.SIZE;
3769 }
3770
3771 if (event.isShiftPressed()) {
3772 shortcutCode |= ((long) KeyEvent.META_SHIFT_ON) << Integer.SIZE;
3773 }
3774
3775 if (event.isMetaPressed()) {
3776 shortcutCode |= ((long) KeyEvent.META_META_ON) << Integer.SIZE;
3777 }
3778
3779 IShortcutService shortcutService = mShortcutKeyServices.get(shortcutCode);
3780 if (shortcutService != null) {
3781 try {
Muyuan Lib5dd0492016-04-14 13:22:20 -07003782 if (isUserSetupComplete()) {
3783 shortcutService.notifyShortcutKeyPressed(shortcutCode);
3784 }
Muyuan Li94ce94e2016-02-24 16:20:54 -08003785 } catch (RemoteException e) {
3786 mShortcutKeyServices.delete(shortcutCode);
3787 }
3788 return -1;
3789 }
3790 }
3791
Michael Wright6a62e552014-06-03 19:19:48 -07003792 // Reserve all the META modifier combos for system behavior
Michael Wrightce0c13a2014-07-30 10:49:21 -07003793 if ((metaState & KeyEvent.META_META_ON) != 0) {
Michael Wright6a62e552014-06-03 19:19:48 -07003794 return -1;
3795 }
3796
Jeff Brown68b909d2011-12-07 16:36:01 -08003797 // Let the application handle the key.
Jeff Brownd5bb82d2011-10-12 13:57:59 -07003798 return 0;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003799 }
3800
Dmitri Plotnikov82e6dfc2017-02-24 18:10:54 -08003801 /**
3802 * TV only: recognizes a remote control gesture for capturing a bug report.
3803 */
3804 private boolean interceptBugreportGestureTv(int keyCode, boolean down) {
3805 // The bugreport capture chord is a long press on DPAD CENTER and BACK simultaneously.
3806 if (keyCode == KeyEvent.KEYCODE_DPAD_CENTER) {
3807 mBugreportTvKey1Pressed = down;
3808 } else if (keyCode == KeyEvent.KEYCODE_BACK) {
3809 mBugreportTvKey2Pressed = down;
3810 }
3811
3812 if (mBugreportTvKey1Pressed && mBugreportTvKey2Pressed) {
3813 if (!mBugreportTvScheduled) {
3814 mBugreportTvScheduled = true;
3815 Message msg = Message.obtain(mHandler, MSG_BUGREPORT_TV);
3816 msg.setAsynchronous(true);
3817 mHandler.sendMessageDelayed(msg, BUGREPORT_TV_GESTURE_TIMEOUT_MILLIS);
3818 }
3819 } else if (mBugreportTvScheduled) {
3820 mHandler.removeMessages(MSG_BUGREPORT_TV);
3821 mBugreportTvScheduled = false;
3822 }
3823
3824 return mBugreportTvScheduled;
3825 }
3826
Sujith Ramakrishnan6bed9bd2017-04-26 12:33:37 -07003827 /**
3828 * TV only: recognizes a remote control gesture as Accessibility shortcut.
3829 * Shortcut: Long press (HOME + DPAD_CENTER)
3830 */
3831 private boolean interceptAccessibilityGestureTv() {
3832 if (mAccessibilityTvKey1Pressed && mAccessibilityTvKey2Pressed) {
3833 if (!mAccessibilityTvScheduled) {
3834 mAccessibilityTvScheduled = true;
3835 Message msg = Message.obtain(mHandler, MSG_ACCESSIBILITY_TV);
3836 msg.setAsynchronous(true);
3837 mHandler.sendMessage(msg);
3838 }
3839 } else if (mAccessibilityTvScheduled) {
3840 mHandler.removeMessages(MSG_ACCESSIBILITY_TV);
3841 mAccessibilityTvScheduled = false;
3842 }
3843 return mAccessibilityTvScheduled;
3844 }
3845
Dmitri Plotnikov82e6dfc2017-02-24 18:10:54 -08003846 private void takeBugreport() {
3847 if ("1".equals(SystemProperties.get("ro.debuggable"))
3848 || Settings.Global.getInt(mContext.getContentResolver(),
3849 Settings.Global.DEVELOPMENT_SETTINGS_ENABLED, 0) == 1) {
3850 try {
3851 ActivityManager.getService()
3852 .requestBugReport(ActivityManager.BUGREPORT_OPTION_INTERACTIVE);
3853 } catch (RemoteException e) {
3854 Slog.e(TAG, "Error taking bugreport", e);
3855 }
3856 }
3857 }
3858
Jeff Brown3915bb82010-11-05 15:02:16 -07003859 /** {@inheritDoc} */
3860 @Override
Jeff Brown49ed71d2010-12-06 17:13:33 -08003861 public KeyEvent dispatchUnhandledKey(WindowState win, KeyEvent event, int policyFlags) {
Jeff Brown54875002011-04-06 15:33:01 -07003862 // Note: This method is only called if the initial down was unhandled.
Jeff Brown40013652012-05-16 21:22:36 -07003863 if (DEBUG_INPUT) {
Jeff Brown1f245102010-11-18 20:53:46 -08003864 Slog.d(TAG, "Unhandled key: win=" + win + ", action=" + event.getAction()
3865 + ", flags=" + event.getFlags()
3866 + ", keyCode=" + event.getKeyCode()
3867 + ", scanCode=" + event.getScanCode()
3868 + ", metaState=" + event.getMetaState()
3869 + ", repeatCount=" + event.getRepeatCount()
3870 + ", policyFlags=" + policyFlags);
Jeff Brown3915bb82010-11-05 15:02:16 -07003871 }
Jeff Brown49ed71d2010-12-06 17:13:33 -08003872
Jeff Brownfd23e3e2012-05-09 13:34:28 -07003873 KeyEvent fallbackEvent = null;
Jeff Brown49ed71d2010-12-06 17:13:33 -08003874 if ((event.getFlags() & KeyEvent.FLAG_FALLBACK) == 0) {
3875 final KeyCharacterMap kcm = event.getKeyCharacterMap();
Jeff Brownc1fb48d2010-12-08 16:52:09 -08003876 final int keyCode = event.getKeyCode();
3877 final int metaState = event.getMetaState();
Jeff Brownfd23e3e2012-05-09 13:34:28 -07003878 final boolean initialDown = event.getAction() == KeyEvent.ACTION_DOWN
3879 && event.getRepeatCount() == 0;
Jeff Brown49ed71d2010-12-06 17:13:33 -08003880
Jeff Brown54875002011-04-06 15:33:01 -07003881 // Check for fallback actions specified by the key character map.
Jeff Brownfd23e3e2012-05-09 13:34:28 -07003882 final FallbackAction fallbackAction;
3883 if (initialDown) {
3884 fallbackAction = kcm.getFallbackAction(keyCode, metaState);
3885 } else {
3886 fallbackAction = mFallbackActions.get(keyCode);
3887 }
3888
3889 if (fallbackAction != null) {
Jeff Brown40013652012-05-16 21:22:36 -07003890 if (DEBUG_INPUT) {
Jeff Brownfd23e3e2012-05-09 13:34:28 -07003891 Slog.d(TAG, "Fallback: keyCode=" + fallbackAction.keyCode
3892 + " metaState=" + Integer.toHexString(fallbackAction.metaState));
Jeff Brown49ed71d2010-12-06 17:13:33 -08003893 }
3894
Jeff Brownfd23e3e2012-05-09 13:34:28 -07003895 final int flags = event.getFlags() | KeyEvent.FLAG_FALLBACK;
3896 fallbackEvent = KeyEvent.obtain(
Jeff Brown49ed71d2010-12-06 17:13:33 -08003897 event.getDownTime(), event.getEventTime(),
Jeff Brownfd23e3e2012-05-09 13:34:28 -07003898 event.getAction(), fallbackAction.keyCode,
3899 event.getRepeatCount(), fallbackAction.metaState,
Jeff Brown49ed71d2010-12-06 17:13:33 -08003900 event.getDeviceId(), event.getScanCode(),
3901 flags, event.getSource(), null);
Jeff Brownfd23e3e2012-05-09 13:34:28 -07003902
3903 if (!interceptFallback(win, fallbackEvent, policyFlags)) {
3904 fallbackEvent.recycle();
3905 fallbackEvent = null;
Jeff Brown49ed71d2010-12-06 17:13:33 -08003906 }
Jeff Brownfd23e3e2012-05-09 13:34:28 -07003907
3908 if (initialDown) {
3909 mFallbackActions.put(keyCode, fallbackAction);
3910 } else if (event.getAction() == KeyEvent.ACTION_UP) {
3911 mFallbackActions.remove(keyCode);
3912 fallbackAction.recycle();
3913 }
Jeff Brown49ed71d2010-12-06 17:13:33 -08003914 }
3915 }
3916
Jeff Brown40013652012-05-16 21:22:36 -07003917 if (DEBUG_INPUT) {
Jeff Brownfd23e3e2012-05-09 13:34:28 -07003918 if (fallbackEvent == null) {
3919 Slog.d(TAG, "No fallback.");
3920 } else {
3921 Slog.d(TAG, "Performing fallback: " + fallbackEvent);
3922 }
Jeff Brown49ed71d2010-12-06 17:13:33 -08003923 }
Jeff Brownfd23e3e2012-05-09 13:34:28 -07003924 return fallbackEvent;
Jeff Brown3915bb82010-11-05 15:02:16 -07003925 }
3926
Jeff Brownfd23e3e2012-05-09 13:34:28 -07003927 private boolean interceptFallback(WindowState win, KeyEvent fallbackEvent, int policyFlags) {
Jeff Brown037c33e2014-04-09 00:31:55 -07003928 int actions = interceptKeyBeforeQueueing(fallbackEvent, policyFlags);
Jeff Brownfd23e3e2012-05-09 13:34:28 -07003929 if ((actions & ACTION_PASS_TO_USER) != 0) {
3930 long delayMillis = interceptKeyBeforeDispatching(
3931 win, fallbackEvent, policyFlags);
3932 if (delayMillis == 0) {
3933 return true;
3934 }
3935 }
3936 return false;
Jeff Brown6f2fba42011-02-19 01:08:02 -08003937 }
3938
Jim Millere4044bb2016-05-10 18:38:25 -07003939 @Override
Muyuan Li94ce94e2016-02-24 16:20:54 -08003940 public void registerShortcutKey(long shortcutCode, IShortcutService shortcutService)
3941 throws RemoteException {
3942 synchronized (mLock) {
3943 IShortcutService service = mShortcutKeyServices.get(shortcutCode);
Muyuan Li24d24ac2016-03-03 21:15:02 -08003944 if (service != null && service.asBinder().pingBinder()) {
3945 throw new RemoteException("Key already exists.");
Muyuan Li94ce94e2016-02-24 16:20:54 -08003946 }
3947
3948 mShortcutKeyServices.put(shortcutCode, shortcutService);
3949 }
3950 }
3951
Adrian Roosd88eb262016-08-04 14:50:48 -07003952 @Override
Jorim Jaggife762342016-10-13 14:33:27 +02003953 public void onKeyguardOccludedChangedLw(boolean occluded) {
3954 if (mKeyguardDelegate != null && mKeyguardDelegate.isShowing()) {
3955 mPendingKeyguardOccluded = occluded;
3956 mKeyguardOccludedChanged = true;
3957 } else {
Jorim Jaggi9ba2e102017-04-04 12:51:03 +02003958 setKeyguardOccludedLw(occluded, false /* force */);
Jorim Jaggife762342016-10-13 14:33:27 +02003959 }
3960 }
3961
3962 private int handleStartTransitionForKeyguardLw(int transit, @Nullable Animation anim) {
3963 if (mKeyguardOccludedChanged) {
3964 if (DEBUG_KEYGUARD) Slog.d(TAG, "transition/occluded changed occluded="
3965 + mPendingKeyguardOccluded);
3966 mKeyguardOccludedChanged = false;
Jorim Jaggi9ba2e102017-04-04 12:51:03 +02003967 if (setKeyguardOccludedLw(mPendingKeyguardOccluded, false /* force */)) {
Jorim Jaggife762342016-10-13 14:33:27 +02003968 return FINISH_LAYOUT_REDO_LAYOUT | FINISH_LAYOUT_REDO_WALLPAPER;
3969 }
3970 }
3971 if (AppTransition.isKeyguardGoingAwayTransit(transit)) {
Jorim Jaggi8d786932016-10-26 19:08:36 -07003972 if (DEBUG_KEYGUARD) Slog.d(TAG, "Starting keyguard exit animation");
Jorim Jaggife762342016-10-13 14:33:27 +02003973 final long startTime = anim != null
3974 ? SystemClock.uptimeMillis() + anim.getStartOffset()
3975 : SystemClock.uptimeMillis();
3976 final long duration = anim != null
3977 ? anim.getDuration()
3978 : 0;
3979 startKeyguardExitAnimation(startTime, duration);
3980 }
3981 return 0;
Adrian Roosd88eb262016-08-04 14:50:48 -07003982 }
3983
Jeff Brownde7a8ea2012-06-13 18:28:57 -07003984 private void launchAssistLongPressAction() {
3985 performHapticFeedbackLw(null, HapticFeedbackConstants.LONG_PRESS, false);
3986 sendCloseSystemWindows(SYSTEM_DIALOG_REASON_ASSIST);
3987
3988 // launch the search activity
3989 Intent intent = new Intent(Intent.ACTION_SEARCH_LONG_PRESS);
3990 intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
3991 try {
RoboErik8a2cfc32014-05-16 11:19:38 -07003992 // TODO: This only stops the factory-installed search manager.
Jim Miller45308b12012-06-18 19:23:39 -07003993 // Need to formalize an API to handle others
Jeff Brownde7a8ea2012-06-13 18:28:57 -07003994 SearchManager searchManager = getSearchManager();
3995 if (searchManager != null) {
3996 searchManager.stopSearch();
3997 }
Bart Sears8b1c27c2015-03-18 23:51:02 +00003998 startActivityAsUser(intent, UserHandle.CURRENT);
Jeff Brownde7a8ea2012-06-13 18:28:57 -07003999 } catch (ActivityNotFoundException e) {
4000 Slog.w(TAG, "No activity to handle assist long press action.", e);
4001 }
4002 }
4003
Tim Kilbourn0e5f1102015-06-05 16:18:09 -07004004 private void launchAssistAction(String hint, int deviceId) {
Jeff Brownde7a8ea2012-06-13 18:28:57 -07004005 sendCloseSystemWindows(SYSTEM_DIALOG_REASON_ASSIST);
Maurice Lam39d13812015-07-23 20:49:20 -07004006 if (!isUserSetupComplete()) {
4007 // Disable opening assist window during setup
4008 return;
4009 }
Tim Kilbourn0e5f1102015-06-05 16:18:09 -07004010 Bundle args = null;
4011 if (deviceId > Integer.MIN_VALUE) {
4012 args = new Bundle();
4013 args.putInt(Intent.EXTRA_ASSIST_INPUT_DEVICE_ID, deviceId);
Jeff Brownde7a8ea2012-06-13 18:28:57 -07004014 }
Jorim Jaggi165ce062015-07-06 16:18:11 -07004015 if ((mContext.getResources().getConfiguration().uiMode
4016 & Configuration.UI_MODE_TYPE_MASK) == Configuration.UI_MODE_TYPE_TELEVISION) {
4017 // On TV, use legacy handling until assistants are implemented in the proper way.
4018 ((SearchManager) mContext.getSystemService(Context.SEARCH_SERVICE))
4019 .launchLegacyAssist(hint, UserHandle.myUserId(), args);
4020 } else {
Adrian Roosf2efdd82016-04-15 17:43:18 -07004021 if (hint != null) {
4022 if (args == null) {
4023 args = new Bundle();
Jorim Jaggi165ce062015-07-06 16:18:11 -07004024 }
Adrian Roosf2efdd82016-04-15 17:43:18 -07004025 args.putBoolean(hint, true);
4026 }
4027 StatusBarManagerInternal statusbar = getStatusBarManagerInternal();
4028 if (statusbar != null) {
4029 statusbar.startAssist(args);
Jorim Jaggi165ce062015-07-06 16:18:11 -07004030 }
4031 }
Jeff Brownde7a8ea2012-06-13 18:28:57 -07004032 }
4033
Bart Sears8b1c27c2015-03-18 23:51:02 +00004034 private void startActivityAsUser(Intent intent, UserHandle handle) {
4035 if (isUserSetupComplete()) {
4036 mContext.startActivityAsUser(intent, handle);
4037 } else {
4038 Slog.i(TAG, "Not starting activity because user setup is in progress: " + intent);
4039 }
4040 }
4041
Jeff Brownde7a8ea2012-06-13 18:28:57 -07004042 private SearchManager getSearchManager() {
4043 if (mSearchManager == null) {
4044 mSearchManager = (SearchManager) mContext.getSystemService(Context.SEARCH_SERVICE);
4045 }
4046 return mSearchManager;
4047 }
4048
Jeff Browncaca8812013-05-09 13:34:33 -07004049 private void preloadRecentApps() {
4050 mPreloadedRecentApps = true;
Adrian Roosf2efdd82016-04-15 17:43:18 -07004051 StatusBarManagerInternal statusbar = getStatusBarManagerInternal();
4052 if (statusbar != null) {
4053 statusbar.preloadRecentApps();
Jeff Browncaca8812013-05-09 13:34:33 -07004054 }
4055 }
4056
4057 private void cancelPreloadRecentApps() {
4058 if (mPreloadedRecentApps) {
4059 mPreloadedRecentApps = false;
Adrian Roosf2efdd82016-04-15 17:43:18 -07004060 StatusBarManagerInternal statusbar = getStatusBarManagerInternal();
4061 if (statusbar != null) {
4062 statusbar.cancelPreloadRecentApps();
Jeff Browncaca8812013-05-09 13:34:33 -07004063 }
4064 }
4065 }
4066
4067 private void toggleRecentApps() {
4068 mPreloadedRecentApps = false; // preloading no longer needs to be canceled
Adrian Roosf2efdd82016-04-15 17:43:18 -07004069 StatusBarManagerInternal statusbar = getStatusBarManagerInternal();
4070 if (statusbar != null) {
4071 statusbar.toggleRecentApps();
Winson Chung1e8d71b2014-05-16 17:05:22 -07004072 }
4073 }
4074
Craig Mautner84984fa2014-06-19 11:19:20 -07004075 @Override
Jorim Jaggi681fc7b2016-04-14 22:02:39 -07004076 public void showRecentApps(boolean fromHome) {
Craig Mautner84984fa2014-06-19 11:19:20 -07004077 mHandler.removeMessages(MSG_DISPATCH_SHOW_RECENTS);
Jorim Jaggi681fc7b2016-04-14 22:02:39 -07004078 mHandler.obtainMessage(MSG_DISPATCH_SHOW_RECENTS, fromHome ? 1 : 0, 0).sendToTarget();
Craig Mautner84984fa2014-06-19 11:19:20 -07004079 }
4080
Jorim Jaggi681fc7b2016-04-14 22:02:39 -07004081 private void showRecentApps(boolean triggeredFromAltTab, boolean fromHome) {
Winson Chung1e8d71b2014-05-16 17:05:22 -07004082 mPreloadedRecentApps = false; // preloading no longer needs to be canceled
Adrian Roosf2efdd82016-04-15 17:43:18 -07004083 StatusBarManagerInternal statusbar = getStatusBarManagerInternal();
4084 if (statusbar != null) {
4085 statusbar.showRecentApps(triggeredFromAltTab, fromHome);
Jeff Browncaca8812013-05-09 13:34:33 -07004086 }
4087 }
4088
Clara Bayarri4e850ff2016-03-02 11:12:32 -08004089 private void toggleKeyboardShortcutsMenu(int deviceId) {
Adrian Roosf2efdd82016-04-15 17:43:18 -07004090 StatusBarManagerInternal statusbar = getStatusBarManagerInternal();
4091 if (statusbar != null) {
4092 statusbar.toggleKeyboardShortcutsMenu(deviceId);
Clara Bayarrif2debb12015-07-10 14:47:17 +01004093 }
4094 }
4095
Andrei Stingaceanu0bf096f2016-04-14 18:11:57 +01004096 private void dismissKeyboardShortcutsMenu() {
4097 StatusBarManagerInternal statusbar = getStatusBarManagerInternal();
4098 if (statusbar != null) {
4099 statusbar.dismissKeyboardShortcutsMenu();
4100 }
4101 }
4102
Winson Chungcdcd4872014-08-05 18:00:13 -07004103 private void hideRecentApps(boolean triggeredFromAltTab, boolean triggeredFromHome) {
Winson Chung1e8d71b2014-05-16 17:05:22 -07004104 mPreloadedRecentApps = false; // preloading no longer needs to be canceled
Adrian Roosf2efdd82016-04-15 17:43:18 -07004105 StatusBarManagerInternal statusbar = getStatusBarManagerInternal();
4106 if (statusbar != null) {
4107 statusbar.hideRecentApps(triggeredFromAltTab, triggeredFromHome);
Winson Chung1e8d71b2014-05-16 17:05:22 -07004108 }
4109 }
4110
Filip Gruszczynskia483a1d2015-03-17 19:06:58 +00004111 void launchHomeFromHotKey() {
Bryce Lee662ed802015-04-10 20:11:39 +00004112 launchHomeFromHotKey(true /* awakenFromDreams */, true /*respectKeyguard*/);
Filip Gruszczynskia483a1d2015-03-17 19:06:58 +00004113 }
4114
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004115 /**
4116 * A home key -> launch home action was detected. Take the appropriate action
4117 * given the situation with the keyguard.
4118 */
Bryce Lee662ed802015-04-10 20:11:39 +00004119 void launchHomeFromHotKey(final boolean awakenFromDreams, final boolean respectKeyguard) {
4120 if (respectKeyguard) {
4121 if (isKeyguardShowingAndNotOccluded()) {
4122 // don't launch home if keyguard showing
4123 return;
4124 }
4125
Jorim Jaggife762342016-10-13 14:33:27 +02004126 if (!mKeyguardOccluded && mKeyguardDelegate.isInputRestricted()) {
Bryce Lee662ed802015-04-10 20:11:39 +00004127 // when in keyguard restricted mode, must first verify unlock
4128 // before launching home
4129 mKeyguardDelegate.verifyUnlock(new OnKeyguardExitResult() {
4130 @Override
4131 public void onKeyguardExitResult(boolean success) {
4132 if (success) {
4133 try {
Sudheer Shankadc589ac2016-11-10 15:30:17 -08004134 ActivityManager.getService().stopAppSwitches();
Bryce Lee662ed802015-04-10 20:11:39 +00004135 } catch (RemoteException e) {
4136 }
4137 sendCloseSystemWindows(SYSTEM_DIALOG_REASON_HOME_KEY);
4138 startDockOrHome(true /*fromHomeKey*/, awakenFromDreams);
Dianne Hackborn256dd3b2009-05-19 18:51:21 -07004139 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004140 }
Bryce Lee662ed802015-04-10 20:11:39 +00004141 });
4142 return;
4143 }
4144 }
4145
4146 // no keyguard stuff to worry about, just launch home!
4147 try {
Sudheer Shankadc589ac2016-11-10 15:30:17 -08004148 ActivityManager.getService().stopAppSwitches();
Bryce Lee662ed802015-04-10 20:11:39 +00004149 } catch (RemoteException e) {
4150 }
4151 if (mRecentsVisible) {
4152 // Hide Recents and notify it to launch Home
4153 if (awakenFromDreams) {
4154 awakenDreams();
4155 }
Bryce Lee662ed802015-04-10 20:11:39 +00004156 hideRecentApps(false, true);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004157 } else {
Bryce Lee662ed802015-04-10 20:11:39 +00004158 // Otherwise, just launch Home
4159 sendCloseSystemWindows(SYSTEM_DIALOG_REASON_HOME_KEY);
4160 startDockOrHome(true /*fromHomeKey*/, awakenFromDreams);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004161 }
4162 }
4163
John Spurlock04db1762013-05-13 12:46:41 -04004164 private final Runnable mClearHideNavigationFlag = new Runnable() {
4165 @Override
4166 public void run() {
4167 synchronized (mWindowManagerFuncs.getWindowManagerLock()) {
4168 // Clear flags.
4169 mForceClearedSystemUiFlags &=
4170 ~View.SYSTEM_UI_FLAG_HIDE_NAVIGATION;
4171 }
4172 mWindowManagerFuncs.reevaluateStatusBarVisibility();
Dianne Hackborne26ab702011-10-16 13:21:33 -07004173 }
4174 };
4175
4176 /**
4177 * Input handler used while nav bar is hidden. Captures any touch on the screen,
4178 * to determine when the nav bar should be shown and prevent applications from
4179 * receiving those touches.
4180 */
Jeff Brown32cbc38552011-12-01 14:01:49 -08004181 final class HideNavInputEventReceiver extends InputEventReceiver {
4182 public HideNavInputEventReceiver(InputChannel inputChannel, Looper looper) {
4183 super(inputChannel, looper);
4184 }
4185
Dianne Hackborndf89e652011-10-06 22:35:11 -07004186 @Override
Tarandeep Singhe1cfcf42017-07-10 18:50:00 -07004187 public void onInputEvent(InputEvent event, int displayId) {
Dianne Hackborndf89e652011-10-06 22:35:11 -07004188 boolean handled = false;
4189 try {
Jeff Brown4952dfd2011-11-30 19:23:22 -08004190 if (event instanceof MotionEvent
4191 && (event.getSource() & InputDevice.SOURCE_CLASS_POINTER) != 0) {
4192 final MotionEvent motionEvent = (MotionEvent)event;
4193 if (motionEvent.getAction() == MotionEvent.ACTION_DOWN) {
Dianne Hackborndf89e652011-10-06 22:35:11 -07004194 // When the user taps down, we re-show the nav bar.
4195 boolean changed = false;
John Spurlock04db1762013-05-13 12:46:41 -04004196 synchronized (mWindowManagerFuncs.getWindowManagerLock()) {
Chong Zhang9f7fb092016-05-20 17:03:08 -07004197 if (mInputConsumer == null) {
4198 return;
4199 }
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07004200 // Any user activity always causes us to show the
4201 // navigation controls, if they had been hidden.
4202 // We also clear the low profile and only content
4203 // flags so that tapping on the screen will atomically
4204 // restore all currently hidden screen decorations.
4205 int newVal = mResettingSystemUiFlags |
4206 View.SYSTEM_UI_FLAG_HIDE_NAVIGATION |
4207 View.SYSTEM_UI_FLAG_LOW_PROFILE |
4208 View.SYSTEM_UI_FLAG_FULLSCREEN;
Dianne Hackborne26ab702011-10-16 13:21:33 -07004209 if (mResettingSystemUiFlags != newVal) {
4210 mResettingSystemUiFlags = newVal;
Dianne Hackborndf89e652011-10-06 22:35:11 -07004211 changed = true;
4212 }
Dianne Hackborne26ab702011-10-16 13:21:33 -07004213 // We don't allow the system's nav bar to be hidden
4214 // again for 1 second, to prevent applications from
4215 // spamming us and keeping it from being shown.
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07004216 newVal = mForceClearedSystemUiFlags |
4217 View.SYSTEM_UI_FLAG_HIDE_NAVIGATION;
Dianne Hackborne26ab702011-10-16 13:21:33 -07004218 if (mForceClearedSystemUiFlags != newVal) {
4219 mForceClearedSystemUiFlags = newVal;
4220 changed = true;
John Spurlock04db1762013-05-13 12:46:41 -04004221 mHandler.postDelayed(mClearHideNavigationFlag, 1000);
Dianne Hackborne26ab702011-10-16 13:21:33 -07004222 }
Dianne Hackborndf89e652011-10-06 22:35:11 -07004223 }
4224 if (changed) {
4225 mWindowManagerFuncs.reevaluateStatusBarVisibility();
4226 }
4227 }
4228 }
4229 } finally {
Jeff Brown32cbc38552011-12-01 14:01:49 -08004230 finishInputEvent(event, handled);
Dianne Hackborndf89e652011-10-06 22:35:11 -07004231 }
4232 }
Jeff Brown32cbc38552011-12-01 14:01:49 -08004233 }
Dianne Hackborndf89e652011-10-06 22:35:11 -07004234
4235 @Override
Winsonab216602016-08-09 14:05:20 -07004236 public void setRecentsVisibilityLw(boolean visible) {
4237 mRecentsVisible = visible;
4238 }
4239
4240 @Override
Winson Chungac52f282017-03-30 14:44:52 -07004241 public void setPipVisibilityLw(boolean visible) {
4242 mPictureInPictureVisible = visible;
Winsonab216602016-08-09 14:05:20 -07004243 }
4244
4245 @Override
Dianne Hackborndf89e652011-10-06 22:35:11 -07004246 public int adjustSystemUiVisibilityLw(int visibility) {
John Spurlock5b9145b2013-08-20 15:13:47 -04004247 mStatusBarController.adjustSystemUiVisibilityLw(mLastSystemUiFlags, visibility);
4248 mNavigationBarController.adjustSystemUiVisibilityLw(mLastSystemUiFlags, visibility);
John Spurlock27735a42013-08-14 17:57:38 -04004249
Dianne Hackborndf89e652011-10-06 22:35:11 -07004250 // Reset any bits in mForceClearingStatusBarVisibility that
4251 // are now clear.
Dianne Hackborne26ab702011-10-16 13:21:33 -07004252 mResettingSystemUiFlags &= visibility;
Dianne Hackborndf89e652011-10-06 22:35:11 -07004253 // Clear any bits in the new visibility that are currently being
4254 // force cleared, before reporting it.
Dianne Hackborne26ab702011-10-16 13:21:33 -07004255 return visibility & ~mResettingSystemUiFlags
4256 & ~mForceClearedSystemUiFlags;
Dianne Hackborndf89e652011-10-06 22:35:11 -07004257 }
4258
Craig Mautner69b08182012-09-05 13:07:13 -07004259 @Override
Jorim Jaggi23bf5462016-05-13 15:24:39 -07004260 public boolean getInsetHintLw(WindowManager.LayoutParams attrs, Rect taskBounds,
4261 int displayRotation, int displayWidth, int displayHeight, Rect outContentInsets,
4262 Rect outStableInsets, Rect outOutsets) {
John Spurlockc6d1c602014-01-17 15:22:06 -05004263 final int fl = PolicyControl.getWindowFlags(null, attrs);
John Spurlock1db8b682014-02-18 11:18:59 -05004264 final int sysuiVis = PolicyControl.getSystemUiVisibility(null, attrs);
4265 final int systemUiVisibility = (sysuiVis | attrs.subtreeSystemUiVisibility);
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07004266
Filip Gruszczynski2987f612015-06-30 15:03:30 -07004267 final boolean useOutsets = outOutsets != null && shouldUseOutsets(attrs, fl);
4268 if (useOutsets) {
4269 int outset = ScreenShapeHelper.getWindowOutsetBottomPx(mContext.getResources());
4270 if (outset > 0) {
4271 if (displayRotation == Surface.ROTATION_0) {
4272 outOutsets.bottom += outset;
4273 } else if (displayRotation == Surface.ROTATION_90) {
4274 outOutsets.right += outset;
4275 } else if (displayRotation == Surface.ROTATION_180) {
4276 outOutsets.top += outset;
4277 } else if (displayRotation == Surface.ROTATION_270) {
4278 outOutsets.left += outset;
4279 }
4280 }
4281 }
4282
Dianne Hackborn5b5cc4d2012-05-16 13:15:00 -07004283 if ((fl & (FLAG_LAYOUT_IN_SCREEN | FLAG_LAYOUT_INSET_DECOR))
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004284 == (FLAG_LAYOUT_IN_SCREEN | FLAG_LAYOUT_INSET_DECOR)) {
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07004285 int availRight, availBottom;
Alan Viverette5a0f4ec2013-10-07 15:10:29 -07004286 if (canHideNavigationBar() &&
Dianne Hackborn5b5cc4d2012-05-16 13:15:00 -07004287 (systemUiVisibility & View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION) != 0) {
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07004288 availRight = mUnrestrictedScreenLeft + mUnrestrictedScreenWidth;
4289 availBottom = mUnrestrictedScreenTop + mUnrestrictedScreenHeight;
4290 } else {
4291 availRight = mRestrictedScreenLeft + mRestrictedScreenWidth;
4292 availBottom = mRestrictedScreenTop + mRestrictedScreenHeight;
4293 }
Dianne Hackborn5b5cc4d2012-05-16 13:15:00 -07004294 if ((systemUiVisibility & View.SYSTEM_UI_FLAG_LAYOUT_STABLE) != 0) {
4295 if ((fl & FLAG_FULLSCREEN) != 0) {
Adrian Roos37d7a682014-11-06 18:15:16 +01004296 outContentInsets.set(mStableFullscreenLeft, mStableFullscreenTop,
Dianne Hackborn5b5cc4d2012-05-16 13:15:00 -07004297 availRight - mStableFullscreenRight,
4298 availBottom - mStableFullscreenBottom);
4299 } else {
Adrian Roos37d7a682014-11-06 18:15:16 +01004300 outContentInsets.set(mStableLeft, mStableTop,
Dianne Hackborn5b5cc4d2012-05-16 13:15:00 -07004301 availRight - mStableRight, availBottom - mStableBottom);
4302 }
Dianne Hackbornc652de82013-02-15 16:32:56 -08004303 } else if ((fl & FLAG_FULLSCREEN) != 0 || (fl & FLAG_LAYOUT_IN_OVERSCAN) != 0) {
Adrian Roos37d7a682014-11-06 18:15:16 +01004304 outContentInsets.setEmpty();
Dianne Hackborn5b5cc4d2012-05-16 13:15:00 -07004305 } else if ((systemUiVisibility & (View.SYSTEM_UI_FLAG_FULLSCREEN
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07004306 | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN)) == 0) {
Adrian Roos37d7a682014-11-06 18:15:16 +01004307 outContentInsets.set(mCurLeft, mCurTop,
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07004308 availRight - mCurRight, availBottom - mCurBottom);
4309 } else {
Adrian Roos37d7a682014-11-06 18:15:16 +01004310 outContentInsets.set(mCurLeft, mCurTop,
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07004311 availRight - mCurRight, availBottom - mCurBottom);
4312 }
Adrian Roos37d7a682014-11-06 18:15:16 +01004313
4314 outStableInsets.set(mStableLeft, mStableTop,
4315 availRight - mStableRight, availBottom - mStableBottom);
Jorim Jaggi23bf5462016-05-13 15:24:39 -07004316 if (taskBounds != null) {
4317 calculateRelevantTaskInsets(taskBounds, outContentInsets,
4318 displayWidth, displayHeight);
4319 calculateRelevantTaskInsets(taskBounds, outStableInsets,
4320 displayWidth, displayHeight);
4321 }
Jorim Jaggi0ffd49c2016-02-12 15:04:21 -08004322 return mForceShowSystemBars;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004323 }
Adrian Roos37d7a682014-11-06 18:15:16 +01004324 outContentInsets.setEmpty();
4325 outStableInsets.setEmpty();
Jorim Jaggi0ffd49c2016-02-12 15:04:21 -08004326 return mForceShowSystemBars;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004327 }
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07004328
Jorim Jaggi23bf5462016-05-13 15:24:39 -07004329 /**
4330 * For any given task bounds, the insets relevant for these bounds given the insets relevant
4331 * for the entire display.
4332 */
4333 private void calculateRelevantTaskInsets(Rect taskBounds, Rect inOutInsets, int displayWidth,
4334 int displayHeight) {
4335 mTmpRect.set(0, 0, displayWidth, displayHeight);
4336 mTmpRect.inset(inOutInsets);
4337 mTmpRect.intersect(taskBounds);
4338 int leftInset = mTmpRect.left - taskBounds.left;
4339 int topInset = mTmpRect.top - taskBounds.top;
4340 int rightInset = taskBounds.right - mTmpRect.right;
4341 int bottomInset = taskBounds.bottom - mTmpRect.bottom;
4342 inOutInsets.set(leftInset, topInset, rightInset, bottomInset);
4343 }
4344
Filip Gruszczynski2987f612015-06-30 15:03:30 -07004345 private boolean shouldUseOutsets(WindowManager.LayoutParams attrs, int fl) {
4346 return attrs.type == TYPE_WALLPAPER || (fl & (WindowManager.LayoutParams.FLAG_FULLSCREEN
4347 | WindowManager.LayoutParams.FLAG_LAYOUT_IN_OVERSCAN)) != 0;
4348 }
4349
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004350 /** {@inheritDoc} */
Craig Mautner69b08182012-09-05 13:07:13 -07004351 @Override
4352 public void beginLayoutLw(boolean isDefaultDisplay, int displayWidth, int displayHeight,
Sriram Viswanathan9ebbe6a2015-11-16 17:59:22 -08004353 int displayRotation, int uiMode) {
Filip Gruszczynski2987f612015-06-30 15:03:30 -07004354 mDisplayRotation = displayRotation;
Dianne Hackbornc652de82013-02-15 16:32:56 -08004355 final int overscanLeft, overscanTop, overscanRight, overscanBottom;
4356 if (isDefaultDisplay) {
4357 switch (displayRotation) {
4358 case Surface.ROTATION_90:
4359 overscanLeft = mOverscanTop;
4360 overscanTop = mOverscanRight;
4361 overscanRight = mOverscanBottom;
4362 overscanBottom = mOverscanLeft;
4363 break;
4364 case Surface.ROTATION_180:
4365 overscanLeft = mOverscanRight;
4366 overscanTop = mOverscanBottom;
4367 overscanRight = mOverscanLeft;
4368 overscanBottom = mOverscanTop;
4369 break;
4370 case Surface.ROTATION_270:
4371 overscanLeft = mOverscanBottom;
4372 overscanTop = mOverscanLeft;
4373 overscanRight = mOverscanTop;
4374 overscanBottom = mOverscanRight;
4375 break;
4376 default:
4377 overscanLeft = mOverscanLeft;
4378 overscanTop = mOverscanTop;
4379 overscanRight = mOverscanRight;
4380 overscanBottom = mOverscanBottom;
4381 break;
4382 }
4383 } else {
4384 overscanLeft = 0;
4385 overscanTop = 0;
4386 overscanRight = 0;
4387 overscanBottom = 0;
4388 }
Dianne Hackborn313440842013-02-19 19:22:59 -08004389 mOverscanScreenLeft = mRestrictedOverscanScreenLeft = 0;
4390 mOverscanScreenTop = mRestrictedOverscanScreenTop = 0;
4391 mOverscanScreenWidth = mRestrictedOverscanScreenWidth = displayWidth;
4392 mOverscanScreenHeight = mRestrictedOverscanScreenHeight = displayHeight;
Dianne Hackbornc652de82013-02-15 16:32:56 -08004393 mSystemLeft = 0;
4394 mSystemTop = 0;
4395 mSystemRight = displayWidth;
4396 mSystemBottom = displayHeight;
4397 mUnrestrictedScreenLeft = overscanLeft;
4398 mUnrestrictedScreenTop = overscanTop;
4399 mUnrestrictedScreenWidth = displayWidth - overscanLeft - overscanRight;
4400 mUnrestrictedScreenHeight = displayHeight - overscanTop - overscanBottom;
4401 mRestrictedScreenLeft = mUnrestrictedScreenLeft;
4402 mRestrictedScreenTop = mUnrestrictedScreenTop;
John Spurlockad3e6cb2013-04-30 08:47:43 -04004403 mRestrictedScreenWidth = mSystemGestures.screenWidth = mUnrestrictedScreenWidth;
4404 mRestrictedScreenHeight = mSystemGestures.screenHeight = mUnrestrictedScreenHeight;
Dianne Hackborne30e02f2014-05-27 18:24:45 -07004405 mDockLeft = mContentLeft = mVoiceContentLeft = mStableLeft = mStableFullscreenLeft
Dianne Hackbornc652de82013-02-15 16:32:56 -08004406 = mCurLeft = mUnrestrictedScreenLeft;
Dianne Hackborne30e02f2014-05-27 18:24:45 -07004407 mDockTop = mContentTop = mVoiceContentTop = mStableTop = mStableFullscreenTop
Dianne Hackbornc652de82013-02-15 16:32:56 -08004408 = mCurTop = mUnrestrictedScreenTop;
Dianne Hackborne30e02f2014-05-27 18:24:45 -07004409 mDockRight = mContentRight = mVoiceContentRight = mStableRight = mStableFullscreenRight
Dianne Hackbornc652de82013-02-15 16:32:56 -08004410 = mCurRight = displayWidth - overscanRight;
Dianne Hackborne30e02f2014-05-27 18:24:45 -07004411 mDockBottom = mContentBottom = mVoiceContentBottom = mStableBottom = mStableFullscreenBottom
Dianne Hackbornc652de82013-02-15 16:32:56 -08004412 = mCurBottom = displayHeight - overscanBottom;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004413 mDockLayer = 0x10000000;
Dianne Hackborn5c58de32012-04-28 19:52:37 -07004414 mStatusBarLayer = -1;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004415
Daniel Sandler8956dbb2011-04-22 07:55:02 -04004416 // start with the current dock rect, which will be (0,0,displayWidth,displayHeight)
4417 final Rect pf = mTmpParentFrame;
4418 final Rect df = mTmpDisplayFrame;
Dianne Hackbornc4aad012013-02-22 15:05:25 -08004419 final Rect of = mTmpOverscanFrame;
Daniel Sandler8956dbb2011-04-22 07:55:02 -04004420 final Rect vf = mTmpVisibleFrame;
John Spurlock46646232013-09-30 22:32:42 -04004421 final Rect dcf = mTmpDecorFrame;
Dianne Hackbornc4aad012013-02-22 15:05:25 -08004422 pf.left = df.left = of.left = vf.left = mDockLeft;
4423 pf.top = df.top = of.top = vf.top = mDockTop;
4424 pf.right = df.right = of.right = vf.right = mDockRight;
4425 pf.bottom = df.bottom = of.bottom = vf.bottom = mDockBottom;
John Spurlock46646232013-09-30 22:32:42 -04004426 dcf.setEmpty(); // Decor frame N/A for system bars.
Daniel Sandler8956dbb2011-04-22 07:55:02 -04004427
Craig Mautner69b08182012-09-05 13:07:13 -07004428 if (isDefaultDisplay) {
4429 // For purposes of putting out fake window up to steal focus, we will
4430 // drive nav being hidden only by whether it is requested.
John Spurlocke1f366f2013-08-05 12:22:40 -04004431 final int sysui = mLastSystemUiFlags;
4432 boolean navVisible = (sysui & View.SYSTEM_UI_FLAG_HIDE_NAVIGATION) == 0;
Adrian Roosea562512014-05-05 13:33:03 +02004433 boolean navTranslucent = (sysui
Jorim Jaggi4fa78922015-11-30 17:13:56 -08004434 & (View.NAVIGATION_BAR_TRANSLUCENT | View.NAVIGATION_BAR_TRANSPARENT)) != 0;
John Spurlockf1a36642013-10-12 17:50:42 -04004435 boolean immersive = (sysui & View.SYSTEM_UI_FLAG_IMMERSIVE) != 0;
4436 boolean immersiveSticky = (sysui & View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY) != 0;
4437 boolean navAllowedHidden = immersive || immersiveSticky;
4438 navTranslucent &= !immersiveSticky; // transient trumps translucent
Jorim Jaggife762342016-10-13 14:33:27 +02004439 boolean isKeyguardShowing = isStatusBarKeyguard() && !mKeyguardOccluded;
Adrian Roos4fb3ee32014-08-22 19:29:09 +02004440 if (!isKeyguardShowing) {
4441 navTranslucent &= areTranslucentBarsAllowed();
4442 }
Jaewan Kim33284332016-05-12 18:55:46 +09004443 boolean statusBarExpandedNotKeyguard = !isKeyguardShowing && mStatusBar != null
Adrian Roosdb1bc6b2016-04-14 17:49:43 -07004444 && mStatusBar.getAttrs().height == MATCH_PARENT
4445 && mStatusBar.getAttrs().width == MATCH_PARENT;
Dianne Hackborne26ab702011-10-16 13:21:33 -07004446
Craig Mautner69b08182012-09-05 13:07:13 -07004447 // When the navigation bar isn't visible, we put up a fake
4448 // input window to catch all touch events. This way we can
4449 // detect when the user presses anywhere to bring back the nav
4450 // bar and ensure the application doesn't see the event.
John Spurlockf1a36642013-10-12 17:50:42 -04004451 if (navVisible || navAllowedHidden) {
Selim Cinekf83e8242015-05-19 18:08:14 -07004452 if (mInputConsumer != null) {
Chong Zhang9f7fb092016-05-20 17:03:08 -07004453 mHandler.sendMessage(
4454 mHandler.obtainMessage(MSG_DISPOSE_INPUT_CONSUMER, mInputConsumer));
Selim Cinekf83e8242015-05-19 18:08:14 -07004455 mInputConsumer = null;
Craig Mautner69b08182012-09-05 13:07:13 -07004456 }
Selim Cinekf83e8242015-05-19 18:08:14 -07004457 } else if (mInputConsumer == null) {
Winson41275482016-10-10 15:17:45 -07004458 mInputConsumer = mWindowManagerFuncs.createInputConsumer(mHandler.getLooper(),
4459 INPUT_CONSUMER_NAVIGATION,
4460 (channel, looper) -> new HideNavInputEventReceiver(channel, looper));
Vladislav Kaznacheev19dab2d2017-02-07 10:12:51 -08004461 // As long as mInputConsumer is active, hover events are not dispatched to the app
4462 // and the pointer icon is likely to become stale. Hide it to avoid confusion.
4463 InputManager.getInstance().setPointerIconType(PointerIcon.TYPE_NULL);
Dianne Hackborne26ab702011-10-16 13:21:33 -07004464 }
Dianne Hackborne26ab702011-10-16 13:21:33 -07004465
Craig Mautner69b08182012-09-05 13:07:13 -07004466 // For purposes of positioning and showing the nav bar, if we have
4467 // decided that it can't be hidden (because of the screen aspect ratio),
4468 // then take that into account.
Alan Viverette5a0f4ec2013-10-07 15:10:29 -07004469 navVisible |= !canHideNavigationBar();
Dianne Hackbornf87d1962012-04-04 12:48:24 -07004470
Filip Gruszczynski83dd9552015-09-17 17:50:36 -07004471 boolean updateSysUiVisibility = layoutNavigationBar(displayWidth, displayHeight,
Adrian Roos85d202b2016-06-02 16:27:47 -07004472 displayRotation, uiMode, overscanLeft, overscanRight, overscanBottom, dcf, navVisible, navTranslucent,
Adrian Roosdb1bc6b2016-04-14 17:49:43 -07004473 navAllowedHidden, statusBarExpandedNotKeyguard);
Craig Mautnereda67292013-04-28 13:50:14 -07004474 if (DEBUG_LAYOUT) Slog.i(TAG, String.format("mDock rect: (%d,%d - %d,%d)",
Craig Mautner69b08182012-09-05 13:07:13 -07004475 mDockLeft, mDockTop, mDockRight, mDockBottom));
Filip Gruszczynski83dd9552015-09-17 17:50:36 -07004476 updateSysUiVisibility |= layoutStatusBar(pf, df, of, vf, dcf, sysui, isKeyguardShowing);
John Spurlockad3e6cb2013-04-30 08:47:43 -04004477 if (updateSysUiVisibility) {
4478 updateSystemUiVisibilityLw();
4479 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004480 }
4481 }
4482
Filip Gruszczynski83dd9552015-09-17 17:50:36 -07004483 private boolean layoutStatusBar(Rect pf, Rect df, Rect of, Rect vf, Rect dcf, int sysui,
4484 boolean isKeyguardShowing) {
4485 // decide where the status bar goes ahead of time
4486 if (mStatusBar != null) {
4487 // apply any navigation bar insets
4488 pf.left = df.left = of.left = mUnrestrictedScreenLeft;
4489 pf.top = df.top = of.top = mUnrestrictedScreenTop;
4490 pf.right = df.right = of.right = mUnrestrictedScreenWidth + mUnrestrictedScreenLeft;
4491 pf.bottom = df.bottom = of.bottom = mUnrestrictedScreenHeight
4492 + mUnrestrictedScreenTop;
4493 vf.left = mStableLeft;
4494 vf.top = mStableTop;
4495 vf.right = mStableRight;
4496 vf.bottom = mStableBottom;
4497
4498 mStatusBarLayer = mStatusBar.getSurfaceLayer();
4499
4500 // Let the status bar determine its size.
4501 mStatusBar.computeFrameLw(pf /* parentFrame */, df /* displayFrame */,
4502 vf /* overlayFrame */, vf /* contentFrame */, vf /* visibleFrame */,
4503 dcf /* decorFrame */, vf /* stableFrame */, vf /* outsetFrame */);
4504
4505 // For layout, the status bar is always at the top with our fixed height.
4506 mStableTop = mUnrestrictedScreenTop + mStatusBarHeight;
4507
4508 boolean statusBarTransient = (sysui & View.STATUS_BAR_TRANSIENT) != 0;
4509 boolean statusBarTranslucent = (sysui
Jorim Jaggi4fa78922015-11-30 17:13:56 -08004510 & (View.STATUS_BAR_TRANSLUCENT | View.STATUS_BAR_TRANSPARENT)) != 0;
Filip Gruszczynski83dd9552015-09-17 17:50:36 -07004511 if (!isKeyguardShowing) {
4512 statusBarTranslucent &= areTranslucentBarsAllowed();
4513 }
4514
4515 // If the status bar is hidden, we don't want to cause
4516 // windows behind it to scroll.
4517 if (mStatusBar.isVisibleLw() && !statusBarTransient) {
4518 // Status bar may go away, so the screen area it occupies
4519 // is available to apps but just covering them when the
4520 // status bar is visible.
4521 mDockTop = mUnrestrictedScreenTop + mStatusBarHeight;
4522
4523 mContentTop = mVoiceContentTop = mCurTop = mDockTop;
4524 mContentBottom = mVoiceContentBottom = mCurBottom = mDockBottom;
4525 mContentLeft = mVoiceContentLeft = mCurLeft = mDockLeft;
4526 mContentRight = mVoiceContentRight = mCurRight = mDockRight;
4527
4528 if (DEBUG_LAYOUT) Slog.v(TAG, "Status bar: " +
4529 String.format(
4530 "dock=[%d,%d][%d,%d] content=[%d,%d][%d,%d] cur=[%d,%d][%d,%d]",
4531 mDockLeft, mDockTop, mDockRight, mDockBottom,
4532 mContentLeft, mContentTop, mContentRight, mContentBottom,
4533 mCurLeft, mCurTop, mCurRight, mCurBottom));
4534 }
4535 if (mStatusBar.isVisibleLw() && !mStatusBar.isAnimatingLw()
4536 && !statusBarTransient && !statusBarTranslucent
4537 && !mStatusBarController.wasRecentlyTranslucent()) {
4538 // If the opaque status bar is currently requested to be visible,
4539 // and not in the process of animating on or off, then
4540 // we can tell the app that it is covered by it.
4541 mSystemTop = mUnrestrictedScreenTop + mStatusBarHeight;
4542 }
4543 if (mStatusBarController.checkHiddenLw()) {
4544 return true;
4545 }
4546 }
4547 return false;
4548 }
4549
4550 private boolean layoutNavigationBar(int displayWidth, int displayHeight, int displayRotation,
Adrian Roos85d202b2016-06-02 16:27:47 -07004551 int uiMode, int overscanLeft, int overscanRight, int overscanBottom, Rect dcf,
4552 boolean navVisible, boolean navTranslucent, boolean navAllowedHidden,
Adrian Roosdb1bc6b2016-04-14 17:49:43 -07004553 boolean statusBarExpandedNotKeyguard) {
Filip Gruszczynski83dd9552015-09-17 17:50:36 -07004554 if (mNavigationBar != null) {
4555 boolean transientNavBarShowing = mNavigationBarController.isTransientShowing();
4556 // Force the navigation bar to its appropriate place and
4557 // size. We need to do this directly, instead of relying on
4558 // it to bubble up from the nav bar, because this needs to
4559 // change atomically with screen rotations.
Adrian Roos85d202b2016-06-02 16:27:47 -07004560 mNavigationBarPosition = navigationBarPosition(displayWidth, displayHeight,
4561 displayRotation);
4562 if (mNavigationBarPosition == NAV_BAR_BOTTOM) {
Filip Gruszczynski83dd9552015-09-17 17:50:36 -07004563 // It's a system nav bar or a portrait screen; nav bar goes on bottom.
4564 int top = displayHeight - overscanBottom
Sriram Viswanathan9ebbe6a2015-11-16 17:59:22 -08004565 - getNavigationBarHeight(displayRotation, uiMode);
Filip Gruszczynski83dd9552015-09-17 17:50:36 -07004566 mTmpNavigationFrame.set(0, top, displayWidth, displayHeight - overscanBottom);
4567 mStableBottom = mStableFullscreenBottom = mTmpNavigationFrame.top;
4568 if (transientNavBarShowing) {
4569 mNavigationBarController.setBarShowingLw(true);
4570 } else if (navVisible) {
4571 mNavigationBarController.setBarShowingLw(true);
4572 mDockBottom = mTmpNavigationFrame.top;
4573 mRestrictedScreenHeight = mDockBottom - mRestrictedScreenTop;
4574 mRestrictedOverscanScreenHeight = mDockBottom - mRestrictedOverscanScreenTop;
4575 } else {
Adrian Roosdb1bc6b2016-04-14 17:49:43 -07004576 // We currently want to hide the navigation UI - unless we expanded the status
4577 // bar.
4578 mNavigationBarController.setBarShowingLw(statusBarExpandedNotKeyguard);
Filip Gruszczynski83dd9552015-09-17 17:50:36 -07004579 }
4580 if (navVisible && !navTranslucent && !navAllowedHidden
4581 && !mNavigationBar.isAnimatingLw()
4582 && !mNavigationBarController.wasRecentlyTranslucent()) {
4583 // If the opaque nav bar is currently requested to be visible,
4584 // and not in the process of animating on or off, then
4585 // we can tell the app that it is covered by it.
4586 mSystemBottom = mTmpNavigationFrame.top;
4587 }
Adrian Roos85d202b2016-06-02 16:27:47 -07004588 } else if (mNavigationBarPosition == NAV_BAR_RIGHT) {
Filip Gruszczynski83dd9552015-09-17 17:50:36 -07004589 // Landscape screen; nav bar goes to the right.
4590 int left = displayWidth - overscanRight
Sriram Viswanathan9ebbe6a2015-11-16 17:59:22 -08004591 - getNavigationBarWidth(displayRotation, uiMode);
Filip Gruszczynski83dd9552015-09-17 17:50:36 -07004592 mTmpNavigationFrame.set(left, 0, displayWidth - overscanRight, displayHeight);
4593 mStableRight = mStableFullscreenRight = mTmpNavigationFrame.left;
4594 if (transientNavBarShowing) {
4595 mNavigationBarController.setBarShowingLw(true);
4596 } else if (navVisible) {
4597 mNavigationBarController.setBarShowingLw(true);
4598 mDockRight = mTmpNavigationFrame.left;
4599 mRestrictedScreenWidth = mDockRight - mRestrictedScreenLeft;
4600 mRestrictedOverscanScreenWidth = mDockRight - mRestrictedOverscanScreenLeft;
4601 } else {
Adrian Roosdb1bc6b2016-04-14 17:49:43 -07004602 // We currently want to hide the navigation UI - unless we expanded the status
4603 // bar.
4604 mNavigationBarController.setBarShowingLw(statusBarExpandedNotKeyguard);
Filip Gruszczynski83dd9552015-09-17 17:50:36 -07004605 }
4606 if (navVisible && !navTranslucent && !navAllowedHidden
4607 && !mNavigationBar.isAnimatingLw()
4608 && !mNavigationBarController.wasRecentlyTranslucent()) {
4609 // If the nav bar is currently requested to be visible,
4610 // and not in the process of animating on or off, then
4611 // we can tell the app that it is covered by it.
4612 mSystemRight = mTmpNavigationFrame.left;
4613 }
Adrian Roos85d202b2016-06-02 16:27:47 -07004614 } else if (mNavigationBarPosition == NAV_BAR_LEFT) {
4615 // Seascape screen; nav bar goes to the left.
4616 int right = overscanLeft + getNavigationBarWidth(displayRotation, uiMode);
4617 mTmpNavigationFrame.set(overscanLeft, 0, right, displayHeight);
4618 mStableLeft = mStableFullscreenLeft = mTmpNavigationFrame.right;
4619 if (transientNavBarShowing) {
4620 mNavigationBarController.setBarShowingLw(true);
4621 } else if (navVisible) {
4622 mNavigationBarController.setBarShowingLw(true);
4623 mDockLeft = mTmpNavigationFrame.right;
4624 // TODO: not so sure about those:
4625 mRestrictedScreenLeft = mRestrictedOverscanScreenLeft = mDockLeft;
4626 mRestrictedScreenWidth = mDockRight - mRestrictedScreenLeft;
4627 mRestrictedOverscanScreenWidth = mDockRight - mRestrictedOverscanScreenLeft;
4628 } else {
4629 // We currently want to hide the navigation UI - unless we expanded the status
4630 // bar.
4631 mNavigationBarController.setBarShowingLw(statusBarExpandedNotKeyguard);
4632 }
4633 if (navVisible && !navTranslucent && !navAllowedHidden
4634 && !mNavigationBar.isAnimatingLw()
4635 && !mNavigationBarController.wasRecentlyTranslucent()) {
4636 // If the nav bar is currently requested to be visible,
4637 // and not in the process of animating on or off, then
4638 // we can tell the app that it is covered by it.
4639 mSystemLeft = mTmpNavigationFrame.right;
4640 }
Filip Gruszczynski83dd9552015-09-17 17:50:36 -07004641 }
4642 // Make sure the content and current rectangles are updated to
4643 // account for the restrictions from the navigation bar.
4644 mContentTop = mVoiceContentTop = mCurTop = mDockTop;
4645 mContentBottom = mVoiceContentBottom = mCurBottom = mDockBottom;
4646 mContentLeft = mVoiceContentLeft = mCurLeft = mDockLeft;
4647 mContentRight = mVoiceContentRight = mCurRight = mDockRight;
4648 mStatusBarLayer = mNavigationBar.getSurfaceLayer();
4649 // And compute the final frame.
4650 mNavigationBar.computeFrameLw(mTmpNavigationFrame, mTmpNavigationFrame,
4651 mTmpNavigationFrame, mTmpNavigationFrame, mTmpNavigationFrame, dcf,
4652 mTmpNavigationFrame, mTmpNavigationFrame);
4653 if (DEBUG_LAYOUT) Slog.i(TAG, "mNavigationBar frame: " + mTmpNavigationFrame);
4654 if (mNavigationBarController.checkHiddenLw()) {
4655 return true;
4656 }
4657 }
4658 return false;
4659 }
4660
Adrian Roos85d202b2016-06-02 16:27:47 -07004661 private int navigationBarPosition(int displayWidth, int displayHeight, int displayRotation) {
4662 if (mNavigationBarCanMove && displayWidth > displayHeight) {
4663 if (displayRotation == Surface.ROTATION_270) {
4664 return NAV_BAR_LEFT;
4665 } else {
4666 return NAV_BAR_RIGHT;
4667 }
4668 }
4669 return NAV_BAR_BOTTOM;
Jorim Jaggi737af722015-12-31 10:42:27 +01004670 }
4671
Dianne Hackborn85afd1b2012-05-13 13:31:06 -07004672 /** {@inheritDoc} */
Craig Mautner967212c2013-04-13 21:10:58 -07004673 @Override
John Spurlock46646232013-09-30 22:32:42 -04004674 public int getSystemDecorLayerLw() {
Bryce Lee2ed3e5f2015-04-01 22:09:19 +00004675 if (mStatusBar != null && mStatusBar.isVisibleLw()) {
4676 return mStatusBar.getSurfaceLayer();
4677 }
4678
4679 if (mNavigationBar != null && mNavigationBar.isVisibleLw()) {
4680 return mNavigationBar.getSurfaceLayer();
4681 }
4682
Dianne Hackborn85afd1b2012-05-13 13:31:06 -07004683 return 0;
4684 }
4685
Craig Mautner967212c2013-04-13 21:10:58 -07004686 @Override
4687 public void getContentRectLw(Rect r) {
4688 r.set(mContentLeft, mContentTop, mContentRight, mContentBottom);
4689 }
4690
Dianne Hackbornc4aad012013-02-22 15:05:25 -08004691 void setAttachedWindowFrames(WindowState win, int fl, int adjust, WindowState attached,
4692 boolean insetDecors, Rect pf, Rect df, Rect of, Rect cf, Rect vf) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004693 if (win.getSurfaceLayer() > mDockLayer && attached.getSurfaceLayer() < mDockLayer) {
4694 // Here's a special case: if this attached window is a panel that is
4695 // above the dock window, and the window it is attached to is below
4696 // the dock window, then the frames we computed for the window it is
4697 // attached to can not be used because the dock is effectively part
4698 // of the underlying window and the attached window is floating on top
4699 // of the whole thing. So, we ignore the attached window and explicitly
4700 // compute the frames that would be appropriate without the dock.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08004701 df.left = of.left = cf.left = vf.left = mDockLeft;
4702 df.top = of.top = cf.top = vf.top = mDockTop;
4703 df.right = of.right = cf.right = vf.right = mDockRight;
4704 df.bottom = of.bottom = cf.bottom = vf.bottom = mDockBottom;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004705 } else {
4706 // The effective display frame of the attached window depends on
4707 // whether it is taking care of insetting its content. If not,
4708 // we need to use the parent's content frame so that the entire
4709 // window is positioned within that content. Otherwise we can use
Wale Ogunwale393b1c12014-10-18 16:22:01 -07004710 // the overscan frame and let the attached window take care of
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004711 // positioning its content appropriately.
Dianne Hackborndea3ef72010-10-28 14:24:22 -07004712 if (adjust != SOFT_INPUT_ADJUST_RESIZE) {
Wale Ogunwale393b1c12014-10-18 16:22:01 -07004713 // Set the content frame of the attached window to the parent's decor frame
4714 // (same as content frame when IME isn't present) if specifically requested by
4715 // setting {@link WindowManager.LayoutParams#FLAG_LAYOUT_ATTACHED_IN_DECOR} flag.
4716 // Otherwise, use the overscan frame.
4717 cf.set((fl & FLAG_LAYOUT_ATTACHED_IN_DECOR) != 0
4718 ? attached.getContentFrameLw() : attached.getOverscanFrameLw());
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004719 } else {
4720 // If the window is resizing, then we want to base the content
4721 // frame on our attached content frame to resize... however,
4722 // things can be tricky if the attached window is NOT in resize
4723 // mode, in which case its content frame will be larger.
4724 // Ungh. So to deal with that, make sure the content frame
4725 // we end up using is not covering the IM dock.
4726 cf.set(attached.getContentFrameLw());
Dianne Hackborne30e02f2014-05-27 18:24:45 -07004727 if (attached.isVoiceInteraction()) {
4728 if (cf.left < mVoiceContentLeft) cf.left = mVoiceContentLeft;
4729 if (cf.top < mVoiceContentTop) cf.top = mVoiceContentTop;
4730 if (cf.right > mVoiceContentRight) cf.right = mVoiceContentRight;
4731 if (cf.bottom > mVoiceContentBottom) cf.bottom = mVoiceContentBottom;
4732 } else if (attached.getSurfaceLayer() < mDockLayer) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004733 if (cf.left < mContentLeft) cf.left = mContentLeft;
4734 if (cf.top < mContentTop) cf.top = mContentTop;
4735 if (cf.right > mContentRight) cf.right = mContentRight;
4736 if (cf.bottom > mContentBottom) cf.bottom = mContentBottom;
4737 }
4738 }
4739 df.set(insetDecors ? attached.getDisplayFrameLw() : cf);
Dianne Hackbornc4aad012013-02-22 15:05:25 -08004740 of.set(insetDecors ? attached.getOverscanFrameLw() : cf);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004741 vf.set(attached.getVisibleFrameLw());
4742 }
4743 // The LAYOUT_IN_SCREEN flag is used to determine whether the attached
4744 // window should be positioned relative to its parent or the entire
4745 // screen.
4746 pf.set((fl & FLAG_LAYOUT_IN_SCREEN) == 0
4747 ? attached.getFrameLw() : df);
4748 }
Dianne Hackborn5b5cc4d2012-05-16 13:15:00 -07004749
4750 private void applyStableConstraints(int sysui, int fl, Rect r) {
4751 if ((sysui & View.SYSTEM_UI_FLAG_LAYOUT_STABLE) != 0) {
4752 // If app is requesting a stable layout, don't let the
4753 // content insets go below the stable values.
4754 if ((fl & FLAG_FULLSCREEN) != 0) {
4755 if (r.left < mStableFullscreenLeft) r.left = mStableFullscreenLeft;
4756 if (r.top < mStableFullscreenTop) r.top = mStableFullscreenTop;
4757 if (r.right > mStableFullscreenRight) r.right = mStableFullscreenRight;
4758 if (r.bottom > mStableFullscreenBottom) r.bottom = mStableFullscreenBottom;
4759 } else {
4760 if (r.left < mStableLeft) r.left = mStableLeft;
4761 if (r.top < mStableTop) r.top = mStableTop;
4762 if (r.right > mStableRight) r.right = mStableRight;
4763 if (r.bottom > mStableBottom) r.bottom = mStableBottom;
4764 }
4765 }
4766 }
4767
Jorim Jaggiaa806142015-05-20 18:04:16 -07004768 private boolean canReceiveInput(WindowState win) {
4769 boolean notFocusable =
4770 (win.getAttrs().flags & WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE) != 0;
4771 boolean altFocusableIm =
4772 (win.getAttrs().flags & WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM) != 0;
4773 boolean notFocusableForIm = notFocusable ^ altFocusableIm;
4774 return !notFocusableForIm;
4775 }
4776
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004777 /** {@inheritDoc} */
Craig Mautner69b08182012-09-05 13:07:13 -07004778 @Override
Craig Mautnerc9457fa2014-06-06 14:27:48 -07004779 public void layoutWindowLw(WindowState win, WindowState attached) {
Jorim Jaggiaa806142015-05-20 18:04:16 -07004780 // We've already done the navigation bar and status bar. If the status bar can receive
4781 // input, we need to layout it again to accomodate for the IME window.
4782 if ((win == mStatusBar && !canReceiveInput(win)) || win == mNavigationBar) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004783 return;
4784 }
Jorim Jaggiaa806142015-05-20 18:04:16 -07004785 final WindowManager.LayoutParams attrs = win.getAttrs();
Craig Mautner69b08182012-09-05 13:07:13 -07004786 final boolean isDefaultDisplay = win.isDefaultDisplay();
4787 final boolean needsToOffsetInputMethodTarget = isDefaultDisplay &&
satok1bc0a492012-04-25 22:47:12 +09004788 (win == mLastInputMethodTargetWindow && mLastInputMethodWindow != null);
4789 if (needsToOffsetInputMethodTarget) {
Craig Mautnereda67292013-04-28 13:50:14 -07004790 if (DEBUG_LAYOUT) Slog.i(TAG, "Offset ime target window by the last ime window state");
satok1bc0a492012-04-25 22:47:12 +09004791 offsetInputMethodWindowLw(mLastInputMethodWindow);
4792 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004793
John Spurlockc6d1c602014-01-17 15:22:06 -05004794 final int fl = PolicyControl.getWindowFlags(win, attrs);
Jorim Jaggi8f5701b2016-04-04 18:36:02 -07004795 final int pfl = attrs.privateFlags;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004796 final int sim = attrs.softInputMode;
John Spurlock1db8b682014-02-18 11:18:59 -05004797 final int sysUiFl = PolicyControl.getSystemUiVisibility(win, null);
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07004798
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004799 final Rect pf = mTmpParentFrame;
4800 final Rect df = mTmpDisplayFrame;
Dianne Hackbornc4aad012013-02-22 15:05:25 -08004801 final Rect of = mTmpOverscanFrame;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004802 final Rect cf = mTmpContentFrame;
4803 final Rect vf = mTmpVisibleFrame;
John Spurlock46646232013-09-30 22:32:42 -04004804 final Rect dcf = mTmpDecorFrame;
Adrian Roosfa104232014-06-20 16:10:14 -07004805 final Rect sf = mTmpStableFrame;
Filip Gruszczynski2217f612015-05-26 11:32:08 -07004806 Rect osf = null;
John Spurlock46646232013-09-30 22:32:42 -04004807 dcf.setEmpty();
Craig Mautner69b08182012-09-05 13:07:13 -07004808
4809 final boolean hasNavBar = (isDefaultDisplay && mHasNavigationBar
Daniel Sandler36412a72011-08-04 09:35:13 -04004810 && mNavigationBar != null && mNavigationBar.isVisibleLw());
Daniel Sandler8956dbb2011-04-22 07:55:02 -04004811
Craig Mautnerf683b562012-10-02 11:10:57 -07004812 final int adjust = sim & SOFT_INPUT_MASK_ADJUST;
4813
Adrian Roosfa104232014-06-20 16:10:14 -07004814 if (isDefaultDisplay) {
4815 sf.set(mStableLeft, mStableTop, mStableRight, mStableBottom);
4816 } else {
4817 sf.set(mOverscanLeft, mOverscanTop, mOverscanRight, mOverscanBottom);
4818 }
4819
Craig Mautner69b08182012-09-05 13:07:13 -07004820 if (!isDefaultDisplay) {
4821 if (attached != null) {
4822 // If this window is attached to another, our display
4823 // frame is the same as the one we are attached to.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08004824 setAttachedWindowFrames(win, fl, adjust, attached, true, pf, df, of, cf, vf);
Craig Mautner69b08182012-09-05 13:07:13 -07004825 } else {
4826 // Give the window full screen.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08004827 pf.left = df.left = of.left = cf.left = mOverscanScreenLeft;
4828 pf.top = df.top = of.top = cf.top = mOverscanScreenTop;
4829 pf.right = df.right = of.right = cf.right
Dianne Hackbornc652de82013-02-15 16:32:56 -08004830 = mOverscanScreenLeft + mOverscanScreenWidth;
Dianne Hackbornc4aad012013-02-22 15:05:25 -08004831 pf.bottom = df.bottom = of.bottom = cf.bottom
Dianne Hackbornc652de82013-02-15 16:32:56 -08004832 = mOverscanScreenTop + mOverscanScreenHeight;
Craig Mautner69b08182012-09-05 13:07:13 -07004833 }
Jorim Jaggi225d3b52015-04-01 11:18:57 -07004834 } else if (attrs.type == TYPE_INPUT_METHOD) {
Dianne Hackbornc4aad012013-02-22 15:05:25 -08004835 pf.left = df.left = of.left = cf.left = vf.left = mDockLeft;
4836 pf.top = df.top = of.top = cf.top = vf.top = mDockTop;
4837 pf.right = df.right = of.right = cf.right = vf.right = mDockRight;
John Spurlockc68d5772013-10-08 11:47:58 -04004838 // IM dock windows layout below the nav bar...
John Spurlock57beb3b2013-10-10 10:27:44 -04004839 pf.bottom = df.bottom = of.bottom = mUnrestrictedScreenTop + mUnrestrictedScreenHeight;
John Spurlockc68d5772013-10-08 11:47:58 -04004840 // ...with content insets above the nav bar
4841 cf.bottom = vf.bottom = mStableBottom;
Adrian Roosdd654ea2016-05-27 11:46:10 -07004842 if (mStatusBar != null && mFocusedWindow == mStatusBar && canReceiveInput(mStatusBar)) {
4843 // The status bar forces the navigation bar while it's visible. Make sure the IME
4844 // avoids the navigation bar in that case.
Adrian Roos85d202b2016-06-02 16:27:47 -07004845 if (mNavigationBarPosition == NAV_BAR_RIGHT) {
4846 pf.right = df.right = of.right = cf.right = vf.right = mStableRight;
4847 } else if (mNavigationBarPosition == NAV_BAR_LEFT) {
4848 pf.left = df.left = of.left = cf.left = vf.left = mStableLeft;
4849 }
Adrian Roosdd654ea2016-05-27 11:46:10 -07004850 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004851 // IM dock windows always go to the bottom of the screen.
4852 attrs.gravity = Gravity.BOTTOM;
4853 mDockLayer = win.getSurfaceLayer();
Jorim Jaggi225d3b52015-04-01 11:18:57 -07004854 } else if (attrs.type == TYPE_VOICE_INTERACTION) {
Stefan Kuhne2f280d062015-06-18 07:20:33 -10004855 pf.left = df.left = of.left = mUnrestrictedScreenLeft;
Jorim Jaggi225d3b52015-04-01 11:18:57 -07004856 pf.top = df.top = of.top = mUnrestrictedScreenTop;
Stefan Kuhne2f280d062015-06-18 07:20:33 -10004857 pf.right = df.right = of.right = mUnrestrictedScreenLeft + mUnrestrictedScreenWidth;
4858 pf.bottom = df.bottom = of.bottom = mUnrestrictedScreenTop + mUnrestrictedScreenHeight;
Jorim Jaggi4b74f4d2016-04-27 18:44:08 -07004859 if (adjust != SOFT_INPUT_ADJUST_RESIZE) {
4860 cf.left = mDockLeft;
4861 cf.top = mDockTop;
4862 cf.right = mDockRight;
4863 cf.bottom = mDockBottom;
4864 } else {
4865 cf.left = mContentLeft;
4866 cf.top = mContentTop;
4867 cf.right = mContentRight;
4868 cf.bottom = mContentBottom;
4869 }
4870 if (adjust != SOFT_INPUT_ADJUST_NOTHING) {
4871 vf.left = mCurLeft;
4872 vf.top = mCurTop;
4873 vf.right = mCurRight;
4874 vf.bottom = mCurBottom;
4875 } else {
4876 vf.set(cf);
4877 }
Jorim Jaggi526505d2016-05-24 00:29:19 -07004878 } else if (attrs.type == TYPE_WALLPAPER) {
4879 layoutWallpaper(win, pf, df, of, cf);
Jorim Jaggiaa806142015-05-20 18:04:16 -07004880 } else if (win == mStatusBar) {
Jorim Jaggie0700182014-08-21 01:12:37 +02004881 pf.left = df.left = of.left = mUnrestrictedScreenLeft;
4882 pf.top = df.top = of.top = mUnrestrictedScreenTop;
4883 pf.right = df.right = of.right = mUnrestrictedScreenWidth + mUnrestrictedScreenLeft;
4884 pf.bottom = df.bottom = of.bottom = mUnrestrictedScreenHeight + mUnrestrictedScreenTop;
4885 cf.left = vf.left = mStableLeft;
4886 cf.top = vf.top = mStableTop;
4887 cf.right = vf.right = mStableRight;
4888 vf.bottom = mStableBottom;
Adrian Roosdc5b4532016-01-06 20:49:41 +01004889
4890 if (adjust == SOFT_INPUT_ADJUST_RESIZE) {
4891 cf.bottom = mContentBottom;
4892 } else {
4893 cf.bottom = mDockBottom;
4894 vf.bottom = mContentBottom;
4895 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004896 } else {
John Spurlock46646232013-09-30 22:32:42 -04004897
4898 // Default policy decor for the default display
4899 dcf.left = mSystemLeft;
4900 dcf.top = mSystemTop;
4901 dcf.right = mSystemRight;
4902 dcf.bottom = mSystemBottom;
John Spurlockbd957402013-10-03 11:38:39 -04004903 final boolean inheritTranslucentDecor = (attrs.privateFlags
4904 & WindowManager.LayoutParams.PRIVATE_FLAG_INHERIT_TRANSLUCENT_DECOR) != 0;
John Spurlock65567d42013-10-08 10:08:32 -04004905 final boolean isAppWindow =
4906 attrs.type >= WindowManager.LayoutParams.FIRST_APPLICATION_WINDOW &&
4907 attrs.type <= WindowManager.LayoutParams.LAST_APPLICATION_WINDOW;
4908 final boolean topAtRest =
4909 win == mTopFullscreenOpaqueWindowState && !win.isAnimatingLw();
4910 if (isAppWindow && !inheritTranslucentDecor && !topAtRest) {
John Spurlockbd957402013-10-03 11:38:39 -04004911 if ((sysUiFl & View.SYSTEM_UI_FLAG_FULLSCREEN) == 0
4912 && (fl & WindowManager.LayoutParams.FLAG_FULLSCREEN) == 0
Adrian Roosea562512014-05-05 13:33:03 +02004913 && (fl & WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS) == 0
4914 && (fl & WindowManager.LayoutParams.
Jorim Jaggi4fa78922015-11-30 17:13:56 -08004915 FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS) == 0
Jorim Jaggi8f5701b2016-04-04 18:36:02 -07004916 && (pfl & PRIVATE_FLAG_FORCE_DRAW_STATUS_BAR_BACKGROUND) == 0) {
John Spurlock46646232013-09-30 22:32:42 -04004917 // Ensure policy decor includes status bar
4918 dcf.top = mStableTop;
4919 }
John Spurlockbd957402013-10-03 11:38:39 -04004920 if ((fl & WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION) == 0
Adrian Roosea562512014-05-05 13:33:03 +02004921 && (sysUiFl & View.SYSTEM_UI_FLAG_HIDE_NAVIGATION) == 0
4922 && (fl & WindowManager.LayoutParams.
4923 FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS) == 0) {
John Spurlock46646232013-09-30 22:32:42 -04004924 // Ensure policy decor includes navigation bar
4925 dcf.bottom = mStableBottom;
4926 dcf.right = mStableRight;
4927 }
4928 }
4929
Dianne Hackbornc4aad012013-02-22 15:05:25 -08004930 if ((fl & (FLAG_LAYOUT_IN_SCREEN | FLAG_LAYOUT_INSET_DECOR))
4931 == (FLAG_LAYOUT_IN_SCREEN | FLAG_LAYOUT_INSET_DECOR)) {
RoboErik8a2cfc32014-05-16 11:19:38 -07004932 if (DEBUG_LAYOUT) Slog.v(TAG, "layoutWindowLw(" + attrs.getTitle()
Dianne Hackbornc4aad012013-02-22 15:05:25 -08004933 + "): IN_SCREEN, INSET_DECOR");
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004934 // This is the case for a normal activity window: we want it
4935 // to cover all of the screen space, and it can take care of
4936 // moving its contents to account for screen decorations that
4937 // intrude into that space.
4938 if (attached != null) {
4939 // If this window is attached to another, our display
4940 // frame is the same as the one we are attached to.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08004941 setAttachedWindowFrames(win, fl, adjust, attached, true, pf, df, of, cf, vf);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004942 } else {
Daniel Sandler8956dbb2011-04-22 07:55:02 -04004943 if (attrs.type == TYPE_STATUS_BAR_PANEL
4944 || attrs.type == TYPE_STATUS_BAR_SUB_PANEL) {
Joe Onorato29fc2c92010-11-24 10:26:50 -08004945 // Status bar panels are the only windows who can go on top of
4946 // the status bar. They are protected by the STATUS_BAR_SERVICE
4947 // permission, so they have the same privileges as the status
4948 // bar itself.
Daniel Sandler8956dbb2011-04-22 07:55:02 -04004949 //
Daniel Sandler8e8b4152011-07-21 01:16:43 -04004950 // However, they should still dodge the navigation bar if it exists.
Daniel Sandler8956dbb2011-04-22 07:55:02 -04004951
Dianne Hackbornc4aad012013-02-22 15:05:25 -08004952 pf.left = df.left = of.left = hasNavBar
4953 ? mDockLeft : mUnrestrictedScreenLeft;
4954 pf.top = df.top = of.top = mUnrestrictedScreenTop;
4955 pf.right = df.right = of.right = hasNavBar
4956 ? mRestrictedScreenLeft+mRestrictedScreenWidth
4957 : mUnrestrictedScreenLeft + mUnrestrictedScreenWidth;
4958 pf.bottom = df.bottom = of.bottom = hasNavBar
4959 ? mRestrictedScreenTop+mRestrictedScreenHeight
4960 : mUnrestrictedScreenTop + mUnrestrictedScreenHeight;
Daniel Sandler8956dbb2011-04-22 07:55:02 -04004961
Craig Mautnereda67292013-04-28 13:50:14 -07004962 if (DEBUG_LAYOUT) Slog.v(TAG, String.format(
Daniel Sandler8e8b4152011-07-21 01:16:43 -04004963 "Laying out status bar window: (%d,%d - %d,%d)",
4964 pf.left, pf.top, pf.right, pf.bottom));
John Spurlock46646232013-09-30 22:32:42 -04004965 } else if ((fl & FLAG_LAYOUT_IN_OVERSCAN) != 0
Dianne Hackbornc652de82013-02-15 16:32:56 -08004966 && attrs.type >= WindowManager.LayoutParams.FIRST_APPLICATION_WINDOW
4967 && attrs.type <= WindowManager.LayoutParams.LAST_SUB_WINDOW) {
4968 // Asking to layout into the overscan region, so give it that pure
4969 // unrestricted area.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08004970 pf.left = df.left = of.left = mOverscanScreenLeft;
4971 pf.top = df.top = of.top = mOverscanScreenTop;
4972 pf.right = df.right = of.right = mOverscanScreenLeft + mOverscanScreenWidth;
4973 pf.bottom = df.bottom = of.bottom = mOverscanScreenTop
4974 + mOverscanScreenHeight;
Alan Viverette5a0f4ec2013-10-07 15:10:29 -07004975 } else if (canHideNavigationBar()
Dianne Hackbornf87d1962012-04-04 12:48:24 -07004976 && (sysUiFl & View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION) != 0
Jorim Jaggi380ecb82014-03-14 17:25:20 +01004977 && attrs.type >= WindowManager.LayoutParams.FIRST_APPLICATION_WINDOW
4978 && attrs.type <= WindowManager.LayoutParams.LAST_SUB_WINDOW) {
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07004979 // Asking for layout as if the nav bar is hidden, lets the
Dianne Hackbornc652de82013-02-15 16:32:56 -08004980 // application extend into the unrestricted overscan screen area. We
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07004981 // only do this for application windows to ensure no window that
4982 // can be above the nav bar can do this.
Dianne Hackborn313440842013-02-19 19:22:59 -08004983 pf.left = df.left = mOverscanScreenLeft;
4984 pf.top = df.top = mOverscanScreenTop;
4985 pf.right = df.right = mOverscanScreenLeft + mOverscanScreenWidth;
4986 pf.bottom = df.bottom = mOverscanScreenTop + mOverscanScreenHeight;
Dianne Hackbornc4aad012013-02-22 15:05:25 -08004987 // We need to tell the app about where the frame inside the overscan
4988 // is, so it can inset its content by that amount -- it didn't ask
4989 // to actually extend itself into the overscan region.
4990 of.left = mUnrestrictedScreenLeft;
4991 of.top = mUnrestrictedScreenTop;
4992 of.right = mUnrestrictedScreenLeft + mUnrestrictedScreenWidth;
4993 of.bottom = mUnrestrictedScreenTop + mUnrestrictedScreenHeight;
Joe Onorato29fc2c92010-11-24 10:26:50 -08004994 } else {
Dianne Hackborn313440842013-02-19 19:22:59 -08004995 pf.left = df.left = mRestrictedOverscanScreenLeft;
4996 pf.top = df.top = mRestrictedOverscanScreenTop;
4997 pf.right = df.right = mRestrictedOverscanScreenLeft
4998 + mRestrictedOverscanScreenWidth;
4999 pf.bottom = df.bottom = mRestrictedOverscanScreenTop
5000 + mRestrictedOverscanScreenHeight;
Dianne Hackbornc4aad012013-02-22 15:05:25 -08005001 // We need to tell the app about where the frame inside the overscan
5002 // is, so it can inset its content by that amount -- it didn't ask
5003 // to actually extend itself into the overscan region.
5004 of.left = mUnrestrictedScreenLeft;
5005 of.top = mUnrestrictedScreenTop;
5006 of.right = mUnrestrictedScreenLeft + mUnrestrictedScreenWidth;
5007 of.bottom = mUnrestrictedScreenTop + mUnrestrictedScreenHeight;
Joe Onorato29fc2c92010-11-24 10:26:50 -08005008 }
Craig Mautner69b08182012-09-05 13:07:13 -07005009
John Spurlock46646232013-09-30 22:32:42 -04005010 if ((fl & FLAG_FULLSCREEN) == 0) {
Dianne Hackborne30e02f2014-05-27 18:24:45 -07005011 if (win.isVoiceInteraction()) {
5012 cf.left = mVoiceContentLeft;
5013 cf.top = mVoiceContentTop;
5014 cf.right = mVoiceContentRight;
5015 cf.bottom = mVoiceContentBottom;
Dianne Hackbornc4aad012013-02-22 15:05:25 -08005016 } else {
Dianne Hackborne30e02f2014-05-27 18:24:45 -07005017 if (adjust != SOFT_INPUT_ADJUST_RESIZE) {
5018 cf.left = mDockLeft;
5019 cf.top = mDockTop;
5020 cf.right = mDockRight;
5021 cf.bottom = mDockBottom;
5022 } else {
5023 cf.left = mContentLeft;
5024 cf.top = mContentTop;
5025 cf.right = mContentRight;
5026 cf.bottom = mContentBottom;
5027 }
Dianne Hackbornc4aad012013-02-22 15:05:25 -08005028 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005029 } else {
Dianne Hackbornc4aad012013-02-22 15:05:25 -08005030 // Full screen windows are always given a layout that is as if the
5031 // status bar and other transient decors are gone. This is to avoid
5032 // bad states when moving from a window that is not hding the
5033 // status bar to one that is.
5034 cf.left = mRestrictedScreenLeft;
5035 cf.top = mRestrictedScreenTop;
5036 cf.right = mRestrictedScreenLeft + mRestrictedScreenWidth;
5037 cf.bottom = mRestrictedScreenTop + mRestrictedScreenHeight;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005038 }
Dianne Hackborn5b5cc4d2012-05-16 13:15:00 -07005039 applyStableConstraints(sysUiFl, fl, cf);
Dianne Hackborndea3ef72010-10-28 14:24:22 -07005040 if (adjust != SOFT_INPUT_ADJUST_NOTHING) {
5041 vf.left = mCurLeft;
5042 vf.top = mCurTop;
5043 vf.right = mCurRight;
5044 vf.bottom = mCurBottom;
5045 } else {
5046 vf.set(cf);
5047 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005048 }
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07005049 } else if ((fl & FLAG_LAYOUT_IN_SCREEN) != 0 || (sysUiFl
5050 & (View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
5051 | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION)) != 0) {
Craig Mautnereda67292013-04-28 13:50:14 -07005052 if (DEBUG_LAYOUT) Slog.v(TAG, "layoutWindowLw(" + attrs.getTitle() +
5053 "): IN_SCREEN");
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005054 // A window that has requested to fill the entire screen just
5055 // gets everything, period.
Daniel Sandler8956dbb2011-04-22 07:55:02 -04005056 if (attrs.type == TYPE_STATUS_BAR_PANEL
Lucas Dupinc1cc7592017-05-22 15:56:16 -07005057 || attrs.type == TYPE_STATUS_BAR_SUB_PANEL) {
Dianne Hackbornc4aad012013-02-22 15:05:25 -08005058 pf.left = df.left = of.left = cf.left = hasNavBar
5059 ? mDockLeft : mUnrestrictedScreenLeft;
5060 pf.top = df.top = of.top = cf.top = mUnrestrictedScreenTop;
5061 pf.right = df.right = of.right = cf.right = hasNavBar
Lucas Dupinc1cc7592017-05-22 15:56:16 -07005062 ? mRestrictedScreenLeft + mRestrictedScreenWidth
5063 : mUnrestrictedScreenLeft + mUnrestrictedScreenWidth;
Dianne Hackbornc4aad012013-02-22 15:05:25 -08005064 pf.bottom = df.bottom = of.bottom = cf.bottom = hasNavBar
Lucas Dupinc1cc7592017-05-22 15:56:16 -07005065 ? mRestrictedScreenTop + mRestrictedScreenHeight
5066 : mUnrestrictedScreenTop + mUnrestrictedScreenHeight;
5067 if (DEBUG_LAYOUT) Slog.v(TAG, String.format(
5068 "Laying out IN_SCREEN status bar window: (%d,%d - %d,%d)",
5069 pf.left, pf.top, pf.right, pf.bottom));
5070 } else if (attrs.type == TYPE_VOLUME_OVERLAY) {
5071 // Volume overlay covers everything, including the status and navbar
5072 pf.left = df.left = of.left = cf.left = mUnrestrictedScreenLeft;
5073 pf.top = df.top = of.top = cf.top = mUnrestrictedScreenTop;
5074 pf.right = df.right = of.right = cf.right =
5075 mUnrestrictedScreenLeft + mUnrestrictedScreenWidth;
5076 pf.bottom = df.bottom = of.bottom = cf.bottom =
5077 mUnrestrictedScreenTop + mUnrestrictedScreenHeight;
Craig Mautnereda67292013-04-28 13:50:14 -07005078 if (DEBUG_LAYOUT) Slog.v(TAG, String.format(
Daniel Sandler36412a72011-08-04 09:35:13 -04005079 "Laying out IN_SCREEN status bar window: (%d,%d - %d,%d)",
5080 pf.left, pf.top, pf.right, pf.bottom));
Jim Millere898ac52012-04-06 17:10:57 -07005081 } else if (attrs.type == TYPE_NAVIGATION_BAR
5082 || attrs.type == TYPE_NAVIGATION_BAR_PANEL) {
Daniel Sandler8e8b4152011-07-21 01:16:43 -04005083 // The navigation bar has Real Ultimate Power.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08005084 pf.left = df.left = of.left = mUnrestrictedScreenLeft;
5085 pf.top = df.top = of.top = mUnrestrictedScreenTop;
5086 pf.right = df.right = of.right = mUnrestrictedScreenLeft
5087 + mUnrestrictedScreenWidth;
5088 pf.bottom = df.bottom = of.bottom = mUnrestrictedScreenTop
5089 + mUnrestrictedScreenHeight;
Craig Mautnereda67292013-04-28 13:50:14 -07005090 if (DEBUG_LAYOUT) Slog.v(TAG, String.format(
Daniel Sandler8e8b4152011-07-21 01:16:43 -04005091 "Laying out navigation bar window: (%d,%d - %d,%d)",
5092 pf.left, pf.top, pf.right, pf.bottom));
Dianne Hackborn01011c32012-02-21 13:54:21 -08005093 } else if ((attrs.type == TYPE_SECURE_SYSTEM_OVERLAY
Muyuan Li6ca619f2016-03-08 13:30:42 -08005094 || attrs.type == TYPE_BOOT_PROGRESS
5095 || attrs.type == TYPE_SCREENSHOT)
Jeff Brownbfcb60a2011-09-08 18:51:14 -07005096 && ((fl & FLAG_FULLSCREEN) != 0)) {
Muyuan Li6ca619f2016-03-08 13:30:42 -08005097 // Fullscreen secure system overlays get what they ask for. Screenshot region
5098 // selection overlay should also expand to full screen.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08005099 pf.left = df.left = of.left = cf.left = mOverscanScreenLeft;
5100 pf.top = df.top = of.top = cf.top = mOverscanScreenTop;
5101 pf.right = df.right = of.right = cf.right = mOverscanScreenLeft
5102 + mOverscanScreenWidth;
5103 pf.bottom = df.bottom = of.bottom = cf.bottom = mOverscanScreenTop
5104 + mOverscanScreenHeight;
Craig Mautner165be0c2015-01-27 15:16:58 -08005105 } else if (attrs.type == TYPE_BOOT_PROGRESS) {
Dianne Hackborn01011c32012-02-21 13:54:21 -08005106 // Boot progress screen always covers entire display.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08005107 pf.left = df.left = of.left = cf.left = mOverscanScreenLeft;
5108 pf.top = df.top = of.top = cf.top = mOverscanScreenTop;
5109 pf.right = df.right = of.right = cf.right = mOverscanScreenLeft
5110 + mOverscanScreenWidth;
5111 pf.bottom = df.bottom = of.bottom = cf.bottom = mOverscanScreenTop
5112 + mOverscanScreenHeight;
John Spurlock46646232013-09-30 22:32:42 -04005113 } else if ((fl & FLAG_LAYOUT_IN_OVERSCAN) != 0
Dianne Hackbornc652de82013-02-15 16:32:56 -08005114 && attrs.type >= WindowManager.LayoutParams.FIRST_APPLICATION_WINDOW
5115 && attrs.type <= WindowManager.LayoutParams.LAST_SUB_WINDOW) {
5116 // Asking to layout into the overscan region, so give it that pure
5117 // unrestricted area.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08005118 pf.left = df.left = of.left = cf.left = mOverscanScreenLeft;
5119 pf.top = df.top = of.top = cf.top = mOverscanScreenTop;
5120 pf.right = df.right = of.right = cf.right
Dianne Hackbornc652de82013-02-15 16:32:56 -08005121 = mOverscanScreenLeft + mOverscanScreenWidth;
Dianne Hackbornc4aad012013-02-22 15:05:25 -08005122 pf.bottom = df.bottom = of.bottom = cf.bottom
Dianne Hackbornc652de82013-02-15 16:32:56 -08005123 = mOverscanScreenTop + mOverscanScreenHeight;
Alan Viverette5a0f4ec2013-10-07 15:10:29 -07005124 } else if (canHideNavigationBar()
Dianne Hackbornf87d1962012-04-04 12:48:24 -07005125 && (sysUiFl & View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION) != 0
Craig Mautnerbeac1062014-06-03 14:38:57 -07005126 && (attrs.type == TYPE_STATUS_BAR
5127 || attrs.type == TYPE_TOAST
Jorim Jaggi81fe2d12015-12-21 14:45:18 +01005128 || attrs.type == TYPE_DOCK_DIVIDER
Jorim Jaggi2fdeeab2015-04-01 15:13:03 -07005129 || attrs.type == TYPE_VOICE_INTERACTION_STARTING
John Spurlock34e13d92013-08-10 06:52:28 -04005130 || (attrs.type >= WindowManager.LayoutParams.FIRST_APPLICATION_WINDOW
5131 && attrs.type <= WindowManager.LayoutParams.LAST_SUB_WINDOW))) {
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07005132 // Asking for layout as if the nav bar is hidden, lets the
5133 // application extend into the unrestricted screen area. We
John Spurlock34e13d92013-08-10 06:52:28 -04005134 // only do this for application windows (or toasts) to ensure no window that
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07005135 // can be above the nav bar can do this.
5136 // XXX This assumes that an app asking for this will also
5137 // ask for layout in only content. We can't currently figure out
5138 // what the screen would be if only laying out to hide the nav bar.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08005139 pf.left = df.left = of.left = cf.left = mUnrestrictedScreenLeft;
5140 pf.top = df.top = of.top = cf.top = mUnrestrictedScreenTop;
5141 pf.right = df.right = of.right = cf.right = mUnrestrictedScreenLeft
5142 + mUnrestrictedScreenWidth;
5143 pf.bottom = df.bottom = of.bottom = cf.bottom = mUnrestrictedScreenTop
5144 + mUnrestrictedScreenHeight;
Jorim Jaggi9f6798a2016-02-10 22:16:06 -08005145 } else if ((sysUiFl & View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN) != 0) {
5146 pf.left = df.left = of.left = mRestrictedScreenLeft;
5147 pf.top = df.top = of.top = mRestrictedScreenTop;
5148 pf.right = df.right = of.right = mRestrictedScreenLeft + mRestrictedScreenWidth;
5149 pf.bottom = df.bottom = of.bottom = mRestrictedScreenTop
5150 + mRestrictedScreenHeight;
5151 if (adjust != SOFT_INPUT_ADJUST_RESIZE) {
5152 cf.left = mDockLeft;
5153 cf.top = mDockTop;
5154 cf.right = mDockRight;
5155 cf.bottom = mDockBottom;
5156 } else {
5157 cf.left = mContentLeft;
5158 cf.top = mContentTop;
5159 cf.right = mContentRight;
5160 cf.bottom = mContentBottom;
5161 }
Joe Onorato29fc2c92010-11-24 10:26:50 -08005162 } else {
Dianne Hackbornc4aad012013-02-22 15:05:25 -08005163 pf.left = df.left = of.left = cf.left = mRestrictedScreenLeft;
5164 pf.top = df.top = of.top = cf.top = mRestrictedScreenTop;
5165 pf.right = df.right = of.right = cf.right = mRestrictedScreenLeft
5166 + mRestrictedScreenWidth;
5167 pf.bottom = df.bottom = of.bottom = cf.bottom = mRestrictedScreenTop
5168 + mRestrictedScreenHeight;
Joe Onorato29fc2c92010-11-24 10:26:50 -08005169 }
Craig Mautner69b08182012-09-05 13:07:13 -07005170
Dianne Hackborn5b5cc4d2012-05-16 13:15:00 -07005171 applyStableConstraints(sysUiFl, fl, cf);
Craig Mautner69b08182012-09-05 13:07:13 -07005172
Dianne Hackborndea3ef72010-10-28 14:24:22 -07005173 if (adjust != SOFT_INPUT_ADJUST_NOTHING) {
5174 vf.left = mCurLeft;
5175 vf.top = mCurTop;
5176 vf.right = mCurRight;
5177 vf.bottom = mCurBottom;
5178 } else {
5179 vf.set(cf);
5180 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005181 } else if (attached != null) {
Craig Mautnereda67292013-04-28 13:50:14 -07005182 if (DEBUG_LAYOUT) Slog.v(TAG, "layoutWindowLw(" + attrs.getTitle() +
5183 "): attached to " + attached);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005184 // A child window should be placed inside of the same visible
5185 // frame that its parent had.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08005186 setAttachedWindowFrames(win, fl, adjust, attached, false, pf, df, of, cf, vf);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005187 } else {
Craig Mautnereda67292013-04-28 13:50:14 -07005188 if (DEBUG_LAYOUT) Slog.v(TAG, "layoutWindowLw(" + attrs.getTitle() +
5189 "): normal window");
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005190 // Otherwise, a normal window must be placed inside the content
5191 // of all screen decorations.
John Spurlock67a0f852015-06-15 15:35:47 -04005192 if (attrs.type == TYPE_STATUS_BAR_PANEL || attrs.type == TYPE_VOLUME_OVERLAY) {
5193 // Status bar panels and the volume dialog are the only windows who can go on
5194 // top of the status bar. They are protected by the STATUS_BAR_SERVICE
Dianne Hackborna239c842011-06-01 12:28:20 -07005195 // permission, so they have the same privileges as the status
5196 // bar itself.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08005197 pf.left = df.left = of.left = cf.left = mRestrictedScreenLeft;
5198 pf.top = df.top = of.top = cf.top = mRestrictedScreenTop;
5199 pf.right = df.right = of.right = cf.right = mRestrictedScreenLeft
5200 + mRestrictedScreenWidth;
5201 pf.bottom = df.bottom = of.bottom = cf.bottom = mRestrictedScreenTop
5202 + mRestrictedScreenHeight;
John Spurlock67a0f852015-06-15 15:35:47 -04005203 } else if (attrs.type == TYPE_TOAST || attrs.type == TYPE_SYSTEM_ALERT) {
John Spurlock414c1f02013-12-04 13:47:36 -05005204 // These dialogs are stable to interim decor changes.
John Spurlockbd957402013-10-03 11:38:39 -04005205 pf.left = df.left = of.left = cf.left = mStableLeft;
5206 pf.top = df.top = of.top = cf.top = mStableTop;
5207 pf.right = df.right = of.right = cf.right = mStableRight;
5208 pf.bottom = df.bottom = of.bottom = cf.bottom = mStableBottom;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005209 } else {
Dianne Hackborna239c842011-06-01 12:28:20 -07005210 pf.left = mContentLeft;
5211 pf.top = mContentTop;
5212 pf.right = mContentRight;
5213 pf.bottom = mContentBottom;
Dianne Hackborn20d94742014-05-29 18:35:45 -07005214 if (win.isVoiceInteraction()) {
5215 df.left = of.left = cf.left = mVoiceContentLeft;
5216 df.top = of.top = cf.top = mVoiceContentTop;
5217 df.right = of.right = cf.right = mVoiceContentRight;
5218 df.bottom = of.bottom = cf.bottom = mVoiceContentBottom;
5219 } else if (adjust != SOFT_INPUT_ADJUST_RESIZE) {
Dianne Hackbornc4aad012013-02-22 15:05:25 -08005220 df.left = of.left = cf.left = mDockLeft;
5221 df.top = of.top = cf.top = mDockTop;
5222 df.right = of.right = cf.right = mDockRight;
5223 df.bottom = of.bottom = cf.bottom = mDockBottom;
Dianne Hackborna239c842011-06-01 12:28:20 -07005224 } else {
Dianne Hackbornc4aad012013-02-22 15:05:25 -08005225 df.left = of.left = cf.left = mContentLeft;
5226 df.top = of.top = cf.top = mContentTop;
5227 df.right = of.right = cf.right = mContentRight;
5228 df.bottom = of.bottom = cf.bottom = mContentBottom;
Dianne Hackborna239c842011-06-01 12:28:20 -07005229 }
5230 if (adjust != SOFT_INPUT_ADJUST_NOTHING) {
5231 vf.left = mCurLeft;
5232 vf.top = mCurTop;
5233 vf.right = mCurRight;
5234 vf.bottom = mCurBottom;
5235 } else {
5236 vf.set(cf);
5237 }
Dianne Hackborndea3ef72010-10-28 14:24:22 -07005238 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005239 }
5240 }
Craig Mautner69b08182012-09-05 13:07:13 -07005241
Craig Mautnerb816bed2013-07-23 10:26:17 -07005242 // TYPE_SYSTEM_ERROR is above the NavigationBar so it can't be allowed to extend over it.
Wale Ogunwale9185fb02016-03-11 18:06:14 -08005243 // Also, we don't allow windows in multi-window mode to extend out of the screen.
5244 if ((fl & FLAG_LAYOUT_NO_LIMITS) != 0 && attrs.type != TYPE_SYSTEM_ERROR
Andrii Kulian933076d2016-03-29 17:04:42 -07005245 && !win.isInMultiWindowMode()) {
Dianne Hackborn067e5f62014-09-07 23:14:30 -07005246 df.left = df.top = -10000;
5247 df.right = df.bottom = 10000;
5248 if (attrs.type != TYPE_WALLPAPER) {
5249 of.left = of.top = cf.left = cf.top = vf.left = vf.top = -10000;
5250 of.right = of.bottom = cf.right = cf.bottom = vf.right = vf.bottom = 10000;
5251 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005252 }
5253
Filip Gruszczynski2217f612015-05-26 11:32:08 -07005254 // If the device has a chin (e.g. some watches), a dead area at the bottom of the screen we
5255 // need to provide information to the clients that want to pretend that you can draw there.
Filip Gruszczynskib0c673b2015-06-05 09:43:06 -07005256 // We only want to apply outsets to certain types of windows. For example, we never want to
5257 // apply the outsets to floating dialogs, because they wouldn't make sense there.
Filip Gruszczynski2987f612015-06-30 15:03:30 -07005258 final boolean useOutsets = shouldUseOutsets(attrs, fl);
Filip Gruszczynskib0c673b2015-06-05 09:43:06 -07005259 if (isDefaultDisplay && useOutsets) {
Filip Gruszczynski2217f612015-05-26 11:32:08 -07005260 osf = mTmpOutsetFrame;
5261 osf.set(cf.left, cf.top, cf.right, cf.bottom);
5262 int outset = ScreenShapeHelper.getWindowOutsetBottomPx(mContext.getResources());
5263 if (outset > 0) {
Filip Gruszczynski2987f612015-06-30 15:03:30 -07005264 int rotation = mDisplayRotation;
Filip Gruszczynski2217f612015-05-26 11:32:08 -07005265 if (rotation == Surface.ROTATION_0) {
5266 osf.bottom += outset;
5267 } else if (rotation == Surface.ROTATION_90) {
5268 osf.right += outset;
5269 } else if (rotation == Surface.ROTATION_180) {
5270 osf.top -= outset;
5271 } else if (rotation == Surface.ROTATION_270) {
5272 osf.left -= outset;
5273 }
5274 if (DEBUG_LAYOUT) Slog.v(TAG, "applying bottom outset of " + outset
5275 + " with rotation " + rotation + ", result: " + osf);
5276 }
5277 }
5278
Craig Mautnereda67292013-04-28 13:50:14 -07005279 if (DEBUG_LAYOUT) Slog.v(TAG, "Compute frame " + attrs.getTitle()
The Android Open Source Project11267662009-03-18 17:39:47 -07005280 + ": sim=#" + Integer.toHexString(sim)
RoboErik8a2cfc32014-05-16 11:19:38 -07005281 + " attach=" + attached + " type=" + attrs.type
Daniel Sandler8956dbb2011-04-22 07:55:02 -04005282 + String.format(" flags=0x%08x", fl)
The Android Open Source Project11267662009-03-18 17:39:47 -07005283 + " pf=" + pf.toShortString() + " df=" + df.toShortString()
Dianne Hackbornc4aad012013-02-22 15:05:25 -08005284 + " of=" + of.toShortString()
John Spurlock46646232013-09-30 22:32:42 -04005285 + " cf=" + cf.toShortString() + " vf=" + vf.toShortString()
Adrian Roosfa104232014-06-20 16:10:14 -07005286 + " dcf=" + dcf.toShortString()
Filip Gruszczynski2217f612015-05-26 11:32:08 -07005287 + " sf=" + sf.toShortString()
5288 + " osf=" + (osf == null ? "null" : osf.toShortString()));
Craig Mautner69b08182012-09-05 13:07:13 -07005289
Filip Gruszczynski2217f612015-05-26 11:32:08 -07005290 win.computeFrameLw(pf, df, of, cf, vf, dcf, sf, osf);
Craig Mautner69b08182012-09-05 13:07:13 -07005291
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005292 // Dock windows carve out the bottom of the screen, so normal windows
5293 // can't appear underneath them.
Jorim Jaggib0d27342016-11-01 16:10:42 -07005294 if (attrs.type == TYPE_INPUT_METHOD && win.isVisibleLw()
5295 && !win.getGivenInsetsPendingLw()) {
satok1bc0a492012-04-25 22:47:12 +09005296 setLastInputMethodWindowLw(null, null);
5297 offsetInputMethodWindowLw(win);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005298 }
Jorim Jaggib0d27342016-11-01 16:10:42 -07005299 if (attrs.type == TYPE_VOICE_INTERACTION && win.isVisibleLw()
Dianne Hackborne30e02f2014-05-27 18:24:45 -07005300 && !win.getGivenInsetsPendingLw()) {
5301 offsetVoiceInputWindowLw(win);
5302 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005303 }
5304
Jorim Jaggi526505d2016-05-24 00:29:19 -07005305 private void layoutWallpaper(WindowState win, Rect pf, Rect df, Rect of, Rect cf) {
5306
5307 // The wallpaper also has Real Ultimate Power, but we want to tell
5308 // it about the overscan area.
5309 pf.left = df.left = mOverscanScreenLeft;
5310 pf.top = df.top = mOverscanScreenTop;
5311 pf.right = df.right = mOverscanScreenLeft + mOverscanScreenWidth;
5312 pf.bottom = df.bottom = mOverscanScreenTop + mOverscanScreenHeight;
5313 of.left = cf.left = mUnrestrictedScreenLeft;
5314 of.top = cf.top = mUnrestrictedScreenTop;
5315 of.right = cf.right = mUnrestrictedScreenLeft + mUnrestrictedScreenWidth;
5316 of.bottom = cf.bottom = mUnrestrictedScreenTop + mUnrestrictedScreenHeight;
5317 }
5318
satok1bc0a492012-04-25 22:47:12 +09005319 private void offsetInputMethodWindowLw(WindowState win) {
Craig Mautner4774f6a2015-03-23 11:42:55 -07005320 int top = Math.max(win.getDisplayFrameLw().top, win.getContentFrameLw().top);
satok1bc0a492012-04-25 22:47:12 +09005321 top += win.getGivenContentInsetsLw().top;
5322 if (mContentBottom > top) {
5323 mContentBottom = top;
5324 }
Dianne Hackborne30e02f2014-05-27 18:24:45 -07005325 if (mVoiceContentBottom > top) {
5326 mVoiceContentBottom = top;
5327 }
satok1bc0a492012-04-25 22:47:12 +09005328 top = win.getVisibleFrameLw().top;
5329 top += win.getGivenVisibleInsetsLw().top;
5330 if (mCurBottom > top) {
5331 mCurBottom = top;
5332 }
Craig Mautnereda67292013-04-28 13:50:14 -07005333 if (DEBUG_LAYOUT) Slog.v(TAG, "Input method: mDockBottom="
satok1bc0a492012-04-25 22:47:12 +09005334 + mDockBottom + " mContentBottom="
5335 + mContentBottom + " mCurBottom=" + mCurBottom);
5336 }
5337
Dianne Hackborne30e02f2014-05-27 18:24:45 -07005338 private void offsetVoiceInputWindowLw(WindowState win) {
Craig Mautner4774f6a2015-03-23 11:42:55 -07005339 int top = Math.max(win.getDisplayFrameLw().top, win.getContentFrameLw().top);
Dianne Hackbornae6688b2015-02-11 17:02:41 -08005340 top += win.getGivenContentInsetsLw().top;
5341 if (mVoiceContentBottom > top) {
5342 mVoiceContentBottom = top;
Dianne Hackborne30e02f2014-05-27 18:24:45 -07005343 }
5344 }
5345
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005346 /** {@inheritDoc} */
Craig Mautner61ac6bb2012-02-02 17:29:33 -08005347 @Override
5348 public void finishLayoutLw() {
5349 return;
Dianne Hackborn5f3063e2010-03-10 16:01:58 -08005350 }
5351
5352 /** {@inheritDoc} */
Craig Mautnerad09bcc2012-10-08 13:33:11 -07005353 @Override
Craig Mautner39834192012-09-02 07:47:24 -07005354 public void beginPostLayoutPolicyLw(int displayWidth, int displayHeight) {
Dianne Hackborn5f3063e2010-03-10 16:01:58 -08005355 mTopFullscreenOpaqueWindowState = null;
Adrian Rooscd3884d2015-02-18 17:25:23 +01005356 mTopFullscreenOpaqueOrDimmingWindowState = null;
Jorim Jaggi86905582016-02-09 21:36:09 -08005357 mTopDockedOpaqueWindowState = null;
5358 mTopDockedOpaqueOrDimmingWindowState = null;
Dianne Hackborn5f3063e2010-03-10 16:01:58 -08005359 mForceStatusBar = false;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07005360 mForceStatusBarFromKeyguard = false;
Selim Cinek4a4a2bddc2015-05-07 12:50:19 -07005361 mForceStatusBarTransparent = false;
Dianne Hackborn891d3fb2013-01-09 18:31:37 -08005362 mForcingShowNavBar = false;
5363 mForcingShowNavBarLayer = -1;
RoboErik8a2cfc32014-05-16 11:19:38 -07005364
Dianne Hackborn5f3063e2010-03-10 16:01:58 -08005365 mAllowLockscreenWhenOn = false;
Dianne Hackborn7ad44382012-10-18 17:46:00 -07005366 mShowingDream = false;
Dianne Hackborn5f3063e2010-03-10 16:01:58 -08005367 }
5368
5369 /** {@inheritDoc} */
Craig Mautnerad09bcc2012-10-08 13:33:11 -07005370 @Override
Yohei Yukawad1a09222015-06-30 16:22:05 -07005371 public void applyPostLayoutPolicyLw(WindowState win, WindowManager.LayoutParams attrs,
Jorim Jaggife762342016-10-13 14:33:27 +02005372 WindowState attached, WindowState imeTarget) {
Jorim Jaggi23cc9aa2017-05-23 16:05:35 +02005373 final boolean affectsSystemUi = win.canAffectSystemUiFlags();
5374 if (DEBUG_LAYOUT) Slog.i(TAG, "Win " + win + ": affectsSystemUi=" + affectsSystemUi);
Jorim Jaggife762342016-10-13 14:33:27 +02005375 applyKeyguardPolicyLw(win, imeTarget);
John Spurlockc6d1c602014-01-17 15:22:06 -05005376 final int fl = PolicyControl.getWindowFlags(win, attrs);
Jorim Jaggi23cc9aa2017-05-23 16:05:35 +02005377 if (mTopFullscreenOpaqueWindowState == null && affectsSystemUi
5378 && attrs.type == TYPE_INPUT_METHOD) {
John Spurlock414c1f02013-12-04 13:47:36 -05005379 mForcingShowNavBar = true;
5380 mForcingShowNavBarLayer = win.getSurfaceLayer();
Dianne Hackborn891d3fb2013-01-09 18:31:37 -08005381 }
Selim Cinek4a4a2bddc2015-05-07 12:50:19 -07005382 if (attrs.type == TYPE_STATUS_BAR) {
5383 if ((attrs.privateFlags & PRIVATE_FLAG_KEYGUARD) != 0) {
5384 mForceStatusBarFromKeyguard = true;
5385 }
5386 if ((attrs.privateFlags & PRIVATE_FLAG_FORCE_STATUS_BAR_VISIBLE_TRANSPARENT) != 0) {
5387 mForceStatusBarTransparent = true;
5388 }
Jorim Jaggiafd4a552014-04-08 15:13:05 +02005389 }
Adrian Roos602c68e2015-04-24 16:03:47 -07005390
5391 boolean appWindow = attrs.type >= FIRST_APPLICATION_WINDOW
Jorim Jaggi30d64f32017-04-07 16:33:17 +02005392 && attrs.type < FIRST_SYSTEM_WINDOW;
Jorim Jaggi86905582016-02-09 21:36:09 -08005393 final int stackId = win.getStackId();
Jorim Jaggi23cc9aa2017-05-23 16:05:35 +02005394 if (mTopFullscreenOpaqueWindowState == null && affectsSystemUi) {
John Spurlockc6d1c602014-01-17 15:22:06 -05005395 if ((fl & FLAG_FORCE_NOT_FULLSCREEN) != 0) {
Jorim Jaggife762342016-10-13 14:33:27 +02005396 mForceStatusBar = true;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07005397 }
Dianne Hackborn7ad44382012-10-18 17:46:00 -07005398 if (attrs.type == TYPE_DREAM) {
Jeff Brownc8018eb2012-10-29 21:33:27 -07005399 // If the lockscreen was showing when the dream started then wait
5400 // for the dream to draw before hiding the lockscreen.
5401 if (!mDreamingLockscreen
5402 || (win.isVisibleLw() && win.hasDrawnLw())) {
5403 mShowingDream = true;
Craig Mautnerab55e522014-03-03 13:26:03 -08005404 appWindow = true;
Dianne Hackborn7ad44382012-10-18 17:46:00 -07005405 }
5406 }
Craig Mautnerab55e522014-03-03 13:26:03 -08005407
Yohei Yukawad1a09222015-06-30 16:22:05 -07005408 // For app windows that are not attached, we decide if all windows in the app they
5409 // represent should be hidden or if we should hide the lockscreen. For attached app
5410 // windows we defer the decision to the window it is attached to.
5411 if (appWindow && attached == null) {
Jorim Jaggie6c6ecb2017-07-20 18:09:20 +02005412 if (attrs.isFullscreen() && StackId.normallyFullscreenWindows(stackId)) {
Craig Mautnerab55e522014-03-03 13:26:03 -08005413 if (DEBUG_LAYOUT) Slog.v(TAG, "Fullscreen window: " + win);
5414 mTopFullscreenOpaqueWindowState = win;
Adrian Rooscd3884d2015-02-18 17:25:23 +01005415 if (mTopFullscreenOpaqueOrDimmingWindowState == null) {
5416 mTopFullscreenOpaqueOrDimmingWindowState = win;
5417 }
Craig Mautner00156ec2014-03-06 22:29:02 -08005418 if ((fl & FLAG_ALLOW_LOCK_WHILE_SCREEN_ON) != 0) {
Craig Mautnerab55e522014-03-03 13:26:03 -08005419 mAllowLockscreenWhenOn = true;
5420 }
Dianne Hackborn5f3063e2010-03-10 16:01:58 -08005421 }
Adrian Roos602c68e2015-04-24 16:03:47 -07005422 }
Dianne Hackborn5f3063e2010-03-10 16:01:58 -08005423 }
Jorim Jaggi86905582016-02-09 21:36:09 -08005424
Jorim Jaggi90859bc2016-06-28 16:25:23 -07005425 // Voice interaction overrides both top fullscreen and top docked.
Jorim Jaggi23cc9aa2017-05-23 16:05:35 +02005426 if (affectsSystemUi && win.getAttrs().type == TYPE_VOICE_INTERACTION) {
Jorim Jaggi90859bc2016-06-28 16:25:23 -07005427 if (mTopFullscreenOpaqueWindowState == null) {
5428 mTopFullscreenOpaqueWindowState = win;
5429 if (mTopFullscreenOpaqueOrDimmingWindowState == null) {
5430 mTopFullscreenOpaqueOrDimmingWindowState = win;
5431 }
5432 }
5433 if (mTopDockedOpaqueWindowState == null) {
5434 mTopDockedOpaqueWindowState = win;
5435 if (mTopDockedOpaqueOrDimmingWindowState == null) {
5436 mTopDockedOpaqueOrDimmingWindowState = win;
5437 }
5438 }
5439 }
5440
5441 // Keep track of the window if it's dimming but not necessarily fullscreen.
Jorim Jaggi23cc9aa2017-05-23 16:05:35 +02005442 if (mTopFullscreenOpaqueOrDimmingWindowState == null && affectsSystemUi
Jorim Jaggi86905582016-02-09 21:36:09 -08005443 && win.isDimming() && StackId.normallyFullscreenWindows(stackId)) {
Adrian Rooscd3884d2015-02-18 17:25:23 +01005444 mTopFullscreenOpaqueOrDimmingWindowState = win;
5445 }
Jorim Jaggi86905582016-02-09 21:36:09 -08005446
5447 // We need to keep track of the top "fullscreen" opaque window for the docked stack
5448 // separately, because both the "real fullscreen" opaque window and the one for the docked
5449 // stack can control View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR.
Jorim Jaggi23cc9aa2017-05-23 16:05:35 +02005450 if (mTopDockedOpaqueWindowState == null && affectsSystemUi && appWindow && attached == null
Jorim Jaggie6c6ecb2017-07-20 18:09:20 +02005451 && attrs.isFullscreen() && stackId == DOCKED_STACK_ID) {
Jorim Jaggi86905582016-02-09 21:36:09 -08005452 mTopDockedOpaqueWindowState = win;
5453 if (mTopDockedOpaqueOrDimmingWindowState == null) {
5454 mTopDockedOpaqueOrDimmingWindowState = win;
5455 }
5456 }
5457
5458 // Also keep track of any windows that are dimming but not necessarily fullscreen in the
5459 // docked stack.
Jorim Jaggi23cc9aa2017-05-23 16:05:35 +02005460 if (mTopDockedOpaqueOrDimmingWindowState == null && affectsSystemUi && win.isDimming()
Jorim Jaggi86905582016-02-09 21:36:09 -08005461 && stackId == DOCKED_STACK_ID) {
5462 mTopDockedOpaqueOrDimmingWindowState = win;
5463 }
5464 }
5465
Jorim Jaggife762342016-10-13 14:33:27 +02005466 private void applyKeyguardPolicyLw(WindowState win, WindowState imeTarget) {
5467 if (canBeHiddenByKeyguardLw(win)) {
5468 if (shouldBeHiddenByKeyguard(win, imeTarget)) {
5469 win.hideLw(false /* doAnimation */);
5470 } else {
5471 win.showLw(false /* doAnimation */);
5472 }
5473 }
5474 }
5475
Dianne Hackborn5f3063e2010-03-10 16:01:58 -08005476 /** {@inheritDoc} */
Craig Mautnerad09bcc2012-10-08 13:33:11 -07005477 @Override
Craig Mautner39834192012-09-02 07:47:24 -07005478 public int finishPostLayoutPolicyLw() {
Dianne Hackborn39c2d712009-09-22 11:41:31 -07005479 int changes = 0;
Joe Onorato93056472010-09-10 10:30:46 -04005480 boolean topIsFullscreen = false;
Daniel Sandlere02d8082010-10-08 15:13:22 -04005481
5482 final WindowManager.LayoutParams lp = (mTopFullscreenOpaqueWindowState != null)
5483 ? mTopFullscreenOpaqueWindowState.getAttrs()
5484 : null;
5485
Jeff Brownc8018eb2012-10-29 21:33:27 -07005486 // If we are not currently showing a dream then remember the current
5487 // lockscreen state. We will use this to determine whether the dream
5488 // started while the lockscreen was showing and remember this state
5489 // while the dream is showing.
Dianne Hackborn7ad44382012-10-18 17:46:00 -07005490 if (!mShowingDream) {
Jorim Jaggi8d786932016-10-26 19:08:36 -07005491 mDreamingLockscreen = isKeyguardShowingAndNotOccluded();
Jeff Brown061ea992015-04-17 19:55:47 -07005492 if (mDreamingSleepTokenNeeded) {
5493 mDreamingSleepTokenNeeded = false;
5494 mHandler.obtainMessage(MSG_UPDATE_DREAMING_SLEEP_TOKEN, 0, 1).sendToTarget();
5495 }
5496 } else {
5497 if (!mDreamingSleepTokenNeeded) {
5498 mDreamingSleepTokenNeeded = true;
5499 mHandler.obtainMessage(MSG_UPDATE_DREAMING_SLEEP_TOKEN, 1, 1).sendToTarget();
5500 }
Dianne Hackborn7ad44382012-10-18 17:46:00 -07005501 }
5502
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005503 if (mStatusBar != null) {
Craig Mautnereda67292013-04-28 13:50:14 -07005504 if (DEBUG_LAYOUT) Slog.i(TAG, "force=" + mForceStatusBar
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07005505 + " forcefkg=" + mForceStatusBarFromKeyguard
Dianne Hackbornd70bc2f2009-10-06 23:25:51 -07005506 + " top=" + mTopFullscreenOpaqueWindowState);
Selim Cinek4a4a2bddc2015-05-07 12:50:19 -07005507 boolean shouldBeTransparent = mForceStatusBarTransparent
5508 && !mForceStatusBar
5509 && !mForceStatusBarFromKeyguard;
5510 if (!shouldBeTransparent) {
5511 mStatusBarController.setShowTransparent(false /* transparent */);
5512 } else if (!mStatusBar.isVisibleLw()) {
5513 mStatusBarController.setShowTransparent(true /* transparent */);
5514 }
Adrian Roosdb1bc6b2016-04-14 17:49:43 -07005515
5516 WindowManager.LayoutParams statusBarAttrs = mStatusBar.getAttrs();
5517 boolean statusBarExpanded = statusBarAttrs.height == MATCH_PARENT
5518 && statusBarAttrs.width == MATCH_PARENT;
5519 if (mForceStatusBar || mForceStatusBarFromKeyguard || mForceStatusBarTransparent
5520 || statusBarExpanded) {
Craig Mautnereda67292013-04-28 13:50:14 -07005521 if (DEBUG_LAYOUT) Slog.v(TAG, "Showing status bar: forced");
John Spurlock27735a42013-08-14 17:57:38 -04005522 if (mStatusBarController.setBarShowingLw(true)) {
5523 changes |= FINISH_LAYOUT_REDO_LAYOUT;
5524 }
Craig Mautner81defc72013-10-29 11:10:42 -07005525 // Maintain fullscreen layout until incoming animation is complete.
5526 topIsFullscreen = mTopIsFullscreen && mStatusBar.isAnimatingLw();
John Spurlockf92b6162013-11-11 15:01:16 -05005527 // Transient status bar on the lockscreen is not allowed
Jorim Jaggi2dc47c12017-05-05 17:39:58 +02005528 if ((mForceStatusBarFromKeyguard || statusBarExpanded)
5529 && mStatusBarController.isTransientShowing()) {
John Spurlockf92b6162013-11-11 15:01:16 -05005530 mStatusBarController.updateVisibilityLw(false /*transientAllowed*/,
5531 mLastSystemUiFlags, mLastSystemUiFlags);
5532 }
Adrian Roosdb1bc6b2016-04-14 17:49:43 -07005533 if (statusBarExpanded && mNavigationBar != null) {
5534 if (mNavigationBarController.setBarShowingLw(true)) {
5535 changes |= FINISH_LAYOUT_REDO_LAYOUT;
5536 }
5537 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005538 } else if (mTopFullscreenOpaqueWindowState != null) {
John Spurlockc6d1c602014-01-17 15:22:06 -05005539 final int fl = PolicyControl.getWindowFlags(null, lp);
Joe Onorato93056472010-09-10 10:30:46 -04005540 if (localLOGV) {
Craig Mautnereda67292013-04-28 13:50:14 -07005541 Slog.d(TAG, "frame: " + mTopFullscreenOpaqueWindowState.getFrameLw()
Filip Gruszczynski2a6a2c22015-10-14 12:00:53 -07005542 + " shown position: "
5543 + mTopFullscreenOpaqueWindowState.getShownPositionLw());
Craig Mautnereda67292013-04-28 13:50:14 -07005544 Slog.d(TAG, "attr: " + mTopFullscreenOpaqueWindowState.getAttrs()
John Spurlockc6d1c602014-01-17 15:22:06 -05005545 + " lp.flags=0x" + Integer.toHexString(fl));
Joe Onorato93056472010-09-10 10:30:46 -04005546 }
John Spurlockc6d1c602014-01-17 15:22:06 -05005547 topIsFullscreen = (fl & WindowManager.LayoutParams.FLAG_FULLSCREEN) != 0
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07005548 || (mLastSystemUiFlags & View.SYSTEM_UI_FLAG_FULLSCREEN) != 0;
Joe Onorato93056472010-09-10 10:30:46 -04005549 // The subtle difference between the window for mTopFullscreenOpaqueWindowState
Mark Dolinerd0646dc2014-08-27 16:04:02 -07005550 // and mTopIsFullscreen is that mTopIsFullscreen is set only if the window
Joe Onorato93056472010-09-10 10:30:46 -04005551 // has the FLAG_FULLSCREEN set. Not sure if there is another way that to be the
5552 // case though.
John Spurlock27735a42013-08-14 17:57:38 -04005553 if (mStatusBarController.isTransientShowing()) {
5554 if (mStatusBarController.setBarShowingLw(true)) {
John Spurlock32beb2c2013-03-11 10:16:47 -04005555 changes |= FINISH_LAYOUT_REDO_LAYOUT;
5556 }
Wale Ogunwale6e94a9e2015-10-07 15:35:49 -07005557 } else if (topIsFullscreen
5558 && !mWindowManagerInternal.isStackVisible(FREEFORM_WORKSPACE_STACK_ID)
5559 && !mWindowManagerInternal.isStackVisible(DOCKED_STACK_ID)) {
Craig Mautnereda67292013-04-28 13:50:14 -07005560 if (DEBUG_LAYOUT) Slog.v(TAG, "** HIDING status bar");
John Spurlock27735a42013-08-14 17:57:38 -04005561 if (mStatusBarController.setBarShowingLw(false)) {
Dianne Hackbornf87d1962012-04-04 12:48:24 -07005562 changes |= FINISH_LAYOUT_REDO_LAYOUT;
Craig Mautnereda67292013-04-28 13:50:14 -07005563 } else {
Craig Mautnerc5a6e442013-06-05 17:22:35 -07005564 if (DEBUG_LAYOUT) Slog.v(TAG, "Status bar already hiding");
Daniel Sandler40427442010-07-16 11:44:52 -04005565 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005566 } else {
Craig Mautnereda67292013-04-28 13:50:14 -07005567 if (DEBUG_LAYOUT) Slog.v(TAG, "** SHOWING status bar: top is not fullscreen");
John Spurlock27735a42013-08-14 17:57:38 -04005568 if (mStatusBarController.setBarShowingLw(true)) {
5569 changes |= FINISH_LAYOUT_REDO_LAYOUT;
5570 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005571 }
5572 }
5573 }
Daniel Sandlere02d8082010-10-08 15:13:22 -04005574
Craig Mautner81defc72013-10-29 11:10:42 -07005575 if (mTopIsFullscreen != topIsFullscreen) {
5576 if (!topIsFullscreen) {
5577 // Force another layout when status bar becomes fully shown.
5578 changes |= FINISH_LAYOUT_REDO_LAYOUT;
5579 }
5580 mTopIsFullscreen = topIsFullscreen;
5581 }
Daniel Sandlere02d8082010-10-08 15:13:22 -04005582
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07005583 if ((updateSystemUiVisibilityLw()&SYSTEM_UI_CHANGING_LAYOUT) != 0) {
Dianne Hackborndf89e652011-10-06 22:35:11 -07005584 // If the navigation bar has been hidden or shown, we need to do another
5585 // layout pass to update that window.
5586 changes |= FINISH_LAYOUT_REDO_LAYOUT;
5587 }
Joe Onorato664644d2011-01-23 17:53:23 -08005588
Jorim Jaggi77e10432016-10-26 17:43:56 -07005589 if (mShowingDream != mLastShowingDream) {
5590 mLastShowingDream = mShowingDream;
5591 mWindowManagerFuncs.notifyShowingDreamChanged();
5592 }
5593
Mike Lockwood28569302010-01-28 11:54:40 -05005594 // update since mAllowLockscreenWhenOn might have changed
5595 updateLockScreenTimeout();
Dianne Hackborn39c2d712009-09-22 11:41:31 -07005596 return changes;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005597 }
5598
Jorim Jaggi380ecb82014-03-14 17:25:20 +01005599 /**
Jim Millerab954542014-10-10 18:21:49 -07005600 * Updates the occluded state of the Keyguard.
Jorim Jaggi380ecb82014-03-14 17:25:20 +01005601 *
Jorim Jaggi380ecb82014-03-14 17:25:20 +01005602 * @return Whether the flags have changed and we have to redo the layout.
5603 */
Jorim Jaggi9ba2e102017-04-04 12:51:03 +02005604 private boolean setKeyguardOccludedLw(boolean isOccluded, boolean force) {
Jorim Jaggife762342016-10-13 14:33:27 +02005605 if (DEBUG_KEYGUARD) Slog.d(TAG, "setKeyguardOccluded occluded=" + isOccluded);
Jorim Jaggiec7708a2017-04-10 18:47:36 -07005606 final boolean wasOccluded = mKeyguardOccluded;
5607 final boolean showing = mKeyguardDelegate.isShowing();
5608 final boolean changed = wasOccluded != isOccluded || force;
5609 if (!isOccluded && changed && showing) {
Jim Millerab954542014-10-10 18:21:49 -07005610 mKeyguardOccluded = false;
Jorim Jaggi6626f542016-08-22 13:08:44 -07005611 mKeyguardDelegate.setOccluded(false, true /* animate */);
Jorim Jaggi9ba2e102017-04-04 12:51:03 +02005612 if (mStatusBar != null) {
5613 mStatusBar.getAttrs().privateFlags |= PRIVATE_FLAG_KEYGUARD;
5614 if (!mKeyguardDelegate.hasLockscreenWallpaper()) {
5615 mStatusBar.getAttrs().flags |= FLAG_SHOW_WALLPAPER;
5616 }
Jorim Jaggid11d1a92016-08-16 16:02:32 -07005617 }
Jorim Jaggi380ecb82014-03-14 17:25:20 +01005618 return true;
Jorim Jaggiec7708a2017-04-10 18:47:36 -07005619 } else if (isOccluded && changed && showing) {
Jim Millerab954542014-10-10 18:21:49 -07005620 mKeyguardOccluded = true;
Jorim Jaggi6626f542016-08-22 13:08:44 -07005621 mKeyguardDelegate.setOccluded(true, false /* animate */);
Jorim Jaggi9ba2e102017-04-04 12:51:03 +02005622 if (mStatusBar != null) {
5623 mStatusBar.getAttrs().privateFlags &= ~PRIVATE_FLAG_KEYGUARD;
5624 mStatusBar.getAttrs().flags &= ~FLAG_SHOW_WALLPAPER;
5625 }
Jorim Jaggi380ecb82014-03-14 17:25:20 +01005626 return true;
Jorim Jaggiec7708a2017-04-10 18:47:36 -07005627 } else if (changed) {
Adrian Roos909fe2d2016-10-12 12:03:24 -07005628 mKeyguardOccluded = isOccluded;
5629 mKeyguardDelegate.setOccluded(isOccluded, false /* animate */);
5630 return false;
Jorim Jaggi380ecb82014-03-14 17:25:20 +01005631 } else {
5632 return false;
5633 }
5634 }
5635
5636 private boolean isStatusBarKeyguard() {
5637 return mStatusBar != null
5638 && (mStatusBar.getAttrs().privateFlags & PRIVATE_FLAG_KEYGUARD) != 0;
5639 }
5640
Jose Lima9546b202014-07-02 17:21:51 -07005641 @Override
Dianne Hackborn08743722009-12-21 12:16:51 -08005642 public boolean allowAppAnimationsLw() {
Jorim Jaggife762342016-10-13 14:33:27 +02005643 if (mShowingDream) {
Craig Mautner28816302013-10-10 20:31:00 -07005644 // If keyguard or dreams is currently visible, no reason to animate behind it.
Dianne Hackborn08743722009-12-21 12:16:51 -08005645 return false;
5646 }
Dianne Hackborn08743722009-12-21 12:16:51 -08005647 return true;
5648 }
5649
Jose Lima9546b202014-07-02 17:21:51 -07005650 @Override
Dianne Hackborndf89e652011-10-06 22:35:11 -07005651 public int focusChangedLw(WindowState lastFocus, WindowState newFocus) {
Joe Onorato664644d2011-01-23 17:53:23 -08005652 mFocusedWindow = newFocus;
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07005653 if ((updateSystemUiVisibilityLw()&SYSTEM_UI_CHANGING_LAYOUT) != 0) {
Dianne Hackborndf89e652011-10-06 22:35:11 -07005654 // If the navigation bar has been hidden or shown, we need to do another
5655 // layout pass to update that window.
5656 return FINISH_LAYOUT_REDO_LAYOUT;
5657 }
5658 return 0;
Joe Onorato664644d2011-01-23 17:53:23 -08005659 }
5660
Dianne Hackborn0ecadf72009-03-31 18:00:37 -07005661 /** {@inheritDoc} */
Jose Lima9546b202014-07-02 17:21:51 -07005662 @Override
Jeff Brown46b9ac02010-04-22 18:58:52 -07005663 public void notifyLidSwitchChanged(long whenNanos, boolean lidOpen) {
5664 // lid changed state
Jeff Brownc458ce92012-04-30 14:58:40 -07005665 final int newLidState = lidOpen ? LID_OPEN : LID_CLOSED;
5666 if (newLidState == mLidState) {
5667 return;
5668 }
Jeff Brown01a98dd2011-09-20 15:08:29 -07005669
Jeff Brownc458ce92012-04-30 14:58:40 -07005670 mLidState = newLidState;
5671 applyLidSwitchState();
Jeff Brown01a98dd2011-09-20 15:08:29 -07005672 updateRotation(true);
Jeff Brownc458ce92012-04-30 14:58:40 -07005673
5674 if (lidOpen) {
Dianne Hackborn280a64e2015-07-13 14:48:08 -07005675 wakeUp(SystemClock.uptimeMillis(), mAllowTheaterModeWakeFromLidSwitch,
5676 "android.policy:LID");
Jeff Brownc458ce92012-04-30 14:58:40 -07005677 } else if (!mLidControlsSleep) {
Jeff Brown96307042012-07-27 15:51:34 -07005678 mPowerManager.userActivity(SystemClock.uptimeMillis(), false);
Jeff Brown46b9ac02010-04-22 18:58:52 -07005679 }
5680 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005681
Michael Wright3818c922014-09-02 13:59:07 -07005682 @Override
5683 public void notifyCameraLensCoverSwitchChanged(long whenNanos, boolean lensCovered) {
5684 int lensCoverState = lensCovered ? CAMERA_LENS_COVERED : CAMERA_LENS_UNCOVERED;
5685 if (mCameraLensCoverState == lensCoverState) {
5686 return;
5687 }
5688 if (mCameraLensCoverState == CAMERA_LENS_COVERED &&
5689 lensCoverState == CAMERA_LENS_UNCOVERED) {
5690 Intent intent;
5691 final boolean keyguardActive = mKeyguardDelegate == null ? false :
5692 mKeyguardDelegate.isShowing();
5693 if (keyguardActive) {
5694 intent = new Intent(MediaStore.INTENT_ACTION_STILL_IMAGE_CAMERA_SECURE);
5695 } else {
5696 intent = new Intent(MediaStore.INTENT_ACTION_STILL_IMAGE_CAMERA);
5697 }
Dianne Hackborn280a64e2015-07-13 14:48:08 -07005698 wakeUp(whenNanos / 1000000, mAllowTheaterModeWakeFromCameraLens,
5699 "android.policy:CAMERA_COVER");
Bart Sears8b1c27c2015-03-18 23:51:02 +00005700 startActivityAsUser(intent, UserHandle.CURRENT_OR_SELF);
Michael Wright3818c922014-09-02 13:59:07 -07005701 }
5702 mCameraLensCoverState = lensCoverState;
5703 }
5704
Dianne Hackbornad7fa7f2011-01-07 14:06:50 -08005705 void setHdmiPlugged(boolean plugged) {
5706 if (mHdmiPlugged != plugged) {
5707 mHdmiPlugged = plugged;
Dianne Hackbornf87d1962012-04-04 12:48:24 -07005708 updateRotation(true, true);
Dianne Hackbornad7fa7f2011-01-07 14:06:50 -08005709 Intent intent = new Intent(ACTION_HDMI_PLUGGED);
Joe Onoratodc100302011-01-11 17:07:41 -08005710 intent.addFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY_BEFORE_BOOT);
Dianne Hackbornad7fa7f2011-01-07 14:06:50 -08005711 intent.putExtra(EXTRA_HDMI_PLUGGED_STATE, plugged);
Dianne Hackborn5ac72a22012-08-29 18:32:08 -07005712 mContext.sendStickyBroadcastAsUser(intent, UserHandle.ALL);
Dianne Hackbornad7fa7f2011-01-07 14:06:50 -08005713 }
5714 }
5715
Joe Onoratoea495d42011-04-06 11:41:11 -07005716 void initializeHdmiState() {
Joe Onorato7ba631f2011-05-04 15:28:00 -07005717 boolean plugged = false;
Joe Onoratoea495d42011-04-06 11:41:11 -07005718 // watch for HDMI plug messages if the hdmi switch exists
5719 if (new File("/sys/devices/virtual/switch/hdmi/state").exists()) {
5720 mHDMIObserver.startObserving("DEVPATH=/devices/virtual/switch/hdmi");
5721
Joe Onoratoea495d42011-04-06 11:41:11 -07005722 final String filename = "/sys/class/switch/hdmi/state";
5723 FileReader reader = null;
5724 try {
5725 reader = new FileReader(filename);
5726 char[] buf = new char[15];
5727 int n = reader.read(buf);
5728 if (n > 1) {
5729 plugged = 0 != Integer.parseInt(new String(buf, 0, n-1));
5730 }
5731 } catch (IOException ex) {
5732 Slog.w(TAG, "Couldn't read hdmi state from " + filename + ": " + ex);
5733 } catch (NumberFormatException ex) {
5734 Slog.w(TAG, "Couldn't read hdmi state from " + filename + ": " + ex);
5735 } finally {
5736 if (reader != null) {
5737 try {
5738 reader.close();
5739 } catch (IOException ex) {
5740 }
Joe Onoratodc100302011-01-11 17:07:41 -08005741 }
5742 }
5743 }
Joe Onorato7ba631f2011-05-04 15:28:00 -07005744 // This dance forces the code in setHdmiPlugged to run.
5745 // Always do this so the sticky intent is stuck (to false) if there is no hdmi.
5746 mHdmiPlugged = !plugged;
5747 setHdmiPlugged(!mHdmiPlugged);
Joe Onoratodc100302011-01-11 17:07:41 -08005748 }
5749
Dianne Hackbornc0e3f242011-08-19 14:19:10 -07005750 final Object mScreenshotLock = new Object();
Dianne Hackbornfc8fa632011-08-17 16:20:47 -07005751 ServiceConnection mScreenshotConnection = null;
Dianne Hackbornfc8fa632011-08-17 16:20:47 -07005752
Jeff Brownd5bb82d2011-10-12 13:57:59 -07005753 final Runnable mScreenshotTimeout = new Runnable() {
5754 @Override public void run() {
5755 synchronized (mScreenshotLock) {
5756 if (mScreenshotConnection != null) {
5757 mContext.unbindService(mScreenshotConnection);
5758 mScreenshotConnection = null;
Winson44dbe292016-03-10 14:00:14 -08005759 notifyScreenshotError();
Dianne Hackbornfc8fa632011-08-17 16:20:47 -07005760 }
Winson Chung9112ec32011-06-27 13:15:32 -07005761 }
Jeff Brownd5bb82d2011-10-12 13:57:59 -07005762 }
5763 };
5764
5765 // Assume this is called from the Handler thread.
Muyuan Li6ca619f2016-03-08 13:30:42 -08005766 private void takeScreenshot(final int screenshotType) {
Jeff Brownd5bb82d2011-10-12 13:57:59 -07005767 synchronized (mScreenshotLock) {
5768 if (mScreenshotConnection != null) {
5769 return;
5770 }
Winson44dbe292016-03-10 14:00:14 -08005771 final ComponentName serviceComponent = new ComponentName(SYSUI_PACKAGE,
5772 SYSUI_SCREENSHOT_SERVICE);
5773 final Intent serviceIntent = new Intent();
5774 serviceIntent.setComponent(serviceComponent);
Jeff Brownd5bb82d2011-10-12 13:57:59 -07005775 ServiceConnection conn = new ServiceConnection() {
5776 @Override
5777 public void onServiceConnected(ComponentName name, IBinder service) {
5778 synchronized (mScreenshotLock) {
5779 if (mScreenshotConnection != this) {
5780 return;
5781 }
5782 Messenger messenger = new Messenger(service);
Muyuan Li6ca619f2016-03-08 13:30:42 -08005783 Message msg = Message.obtain(null, screenshotType);
Jeff Brownd5bb82d2011-10-12 13:57:59 -07005784 final ServiceConnection myConn = this;
5785 Handler h = new Handler(mHandler.getLooper()) {
5786 @Override
5787 public void handleMessage(Message msg) {
5788 synchronized (mScreenshotLock) {
5789 if (mScreenshotConnection == myConn) {
5790 mContext.unbindService(mScreenshotConnection);
5791 mScreenshotConnection = null;
5792 mHandler.removeCallbacks(mScreenshotTimeout);
5793 }
5794 }
5795 }
5796 };
5797 msg.replyTo = new Messenger(h);
Winson Chunga63bb842011-10-17 10:26:28 -07005798 msg.arg1 = msg.arg2 = 0;
5799 if (mStatusBar != null && mStatusBar.isVisibleLw())
5800 msg.arg1 = 1;
5801 if (mNavigationBar != null && mNavigationBar.isVisibleLw())
5802 msg.arg2 = 1;
Jeff Brownd5bb82d2011-10-12 13:57:59 -07005803 try {
5804 messenger.send(msg);
5805 } catch (RemoteException e) {
5806 }
5807 }
5808 }
Winson44dbe292016-03-10 14:00:14 -08005809
Jeff Brownd5bb82d2011-10-12 13:57:59 -07005810 @Override
Winson44dbe292016-03-10 14:00:14 -08005811 public void onServiceDisconnected(ComponentName name) {
Geoffrey Pitschb2d6ed32016-08-24 10:37:19 -04005812 synchronized (mScreenshotLock) {
5813 if (mScreenshotConnection != null) {
5814 mContext.unbindService(mScreenshotConnection);
5815 mScreenshotConnection = null;
5816 mHandler.removeCallbacks(mScreenshotTimeout);
5817 notifyScreenshotError();
5818 }
5819 }
Winson44dbe292016-03-10 14:00:14 -08005820 }
Jeff Brownd5bb82d2011-10-12 13:57:59 -07005821 };
Winson44dbe292016-03-10 14:00:14 -08005822 if (mContext.bindServiceAsUser(serviceIntent, conn,
5823 Context.BIND_AUTO_CREATE | Context.BIND_FOREGROUND_SERVICE_WHILE_AWAKE,
5824 UserHandle.CURRENT)) {
Jeff Brownd5bb82d2011-10-12 13:57:59 -07005825 mScreenshotConnection = conn;
5826 mHandler.postDelayed(mScreenshotTimeout, 10000);
5827 }
5828 }
Winson Chung9112ec32011-06-27 13:15:32 -07005829 }
5830
Winson44dbe292016-03-10 14:00:14 -08005831 /**
5832 * Notifies the screenshot service to show an error.
5833 */
5834 private void notifyScreenshotError() {
5835 // If the service process is killed, then ask it to clean up after itself
5836 final ComponentName errorComponent = new ComponentName(SYSUI_PACKAGE,
5837 SYSUI_SCREENSHOT_ERROR_RECEIVER);
Dianne Hackborna8c16932016-05-24 12:58:21 -07005838 Intent errorIntent = new Intent(Intent.ACTION_USER_PRESENT);
Winson44dbe292016-03-10 14:00:14 -08005839 errorIntent.setComponent(errorComponent);
5840 errorIntent.addFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY_BEFORE_BOOT |
5841 Intent.FLAG_RECEIVER_FOREGROUND);
Winson538c2262016-05-19 10:06:18 -07005842 mContext.sendBroadcastAsUser(errorIntent, UserHandle.CURRENT);
Winson44dbe292016-03-10 14:00:14 -08005843 }
5844
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005845 /** {@inheritDoc} */
Jeff Brown00fa7bd2010-07-02 15:37:36 -07005846 @Override
Jeff Brown037c33e2014-04-09 00:31:55 -07005847 public int interceptKeyBeforeQueueing(KeyEvent event, int policyFlags) {
Jeff Brown96307042012-07-27 15:51:34 -07005848 if (!mSystemBooted) {
5849 // If we have not yet booted, don't let key events do anything.
5850 return 0;
5851 }
5852
Jeff Brown037c33e2014-04-09 00:31:55 -07005853 final boolean interactive = (policyFlags & FLAG_INTERACTIVE) != 0;
Jeff Brown1f245102010-11-18 20:53:46 -08005854 final boolean down = event.getAction() == KeyEvent.ACTION_DOWN;
5855 final boolean canceled = event.isCanceled();
5856 final int keyCode = event.getKeyCode();
Jeff Browne20c9e02010-10-11 14:20:19 -07005857
Jeff Brown3122e442010-10-11 23:32:49 -07005858 final boolean isInjected = (policyFlags & WindowManagerPolicy.FLAG_INJECTED) != 0;
Jeff Brown3122e442010-10-11 23:32:49 -07005859
Mike Lockwoodc72b15f2009-11-28 20:58:22 -05005860 // If screen is off then we treat the case where the keyguard is open but hidden
5861 // the same as if it were open and in front.
5862 // This will prevent any keys other than the power button from waking the screen
5863 // when the keyguard is hidden by another activity.
Jim Miller5ecd8112013-01-09 18:50:26 -08005864 final boolean keyguardActive = (mKeyguardDelegate == null ? false :
Jeff Brown037c33e2014-04-09 00:31:55 -07005865 (interactive ?
Jim Millerab954542014-10-10 18:21:49 -07005866 isKeyguardShowingAndNotOccluded() :
Jim Miller5ecd8112013-01-09 18:50:26 -08005867 mKeyguardDelegate.isShowing()));
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005868
Jeff Brown40013652012-05-16 21:22:36 -07005869 if (DEBUG_INPUT) {
Jeff Brown00fa7bd2010-07-02 15:37:36 -07005870 Log.d(TAG, "interceptKeyTq keycode=" + keyCode
Jeff Brown037c33e2014-04-09 00:31:55 -07005871 + " interactive=" + interactive + " keyguardActive=" + keyguardActive
Jeff Brown26875502014-01-30 21:47:47 -08005872 + " policyFlags=" + Integer.toHexString(policyFlags));
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005873 }
5874
Jeff Brown037c33e2014-04-09 00:31:55 -07005875 // Basic policy based on interactive state.
Jeff Brown4d396052010-10-29 21:50:21 -07005876 int result;
Michael Wright337d9d22014-04-22 15:03:48 -07005877 boolean isWakeKey = (policyFlags & WindowManagerPolicy.FLAG_WAKE) != 0
5878 || event.isWakeKey();
Michael Wrightfc01f042014-09-08 14:12:24 -07005879 if (interactive || (isInjected && !isWakeKey)) {
RoboErikde9ba392014-09-26 12:51:01 -07005880 // When the device is interactive or the key is injected pass the
5881 // key to the application.
Jeff Brown4d396052010-10-29 21:50:21 -07005882 result = ACTION_PASS_TO_USER;
Jose Lima9546b202014-07-02 17:21:51 -07005883 isWakeKey = false;
Anthony Hugh4b13ab82016-05-17 13:03:00 -07005884
5885 if (interactive) {
5886 // If the screen is awake, but the button pressed was the one that woke the device
5887 // then don't pass it to the application
5888 if (keyCode == mPendingWakeKey && !down) {
5889 result = 0;
5890 }
5891 // Reset the pending key
5892 mPendingWakeKey = PENDING_KEY_NULL;
5893 }
5894 } else if (!interactive && shouldDispatchInputWhenNonInteractive(event)) {
Michael Wrightfc01f042014-09-08 14:12:24 -07005895 // If we're currently dozing with the screen on and the keyguard showing, pass the key
5896 // to the application but preserve its wake key status to make sure we still move
5897 // from dozing to fully interactive if we would normally go from off to fully
5898 // interactive.
5899 result = ACTION_PASS_TO_USER;
Anthony Hugh4b13ab82016-05-17 13:03:00 -07005900 // Since we're dispatching the input, reset the pending key
5901 mPendingWakeKey = PENDING_KEY_NULL;
Jeff Brown4d396052010-10-29 21:50:21 -07005902 } else {
5903 // When the screen is off and the key is not injected, determine whether
5904 // to wake the device but don't pass the key to the application.
5905 result = 0;
Jeff Brown26875502014-01-30 21:47:47 -08005906 if (isWakeKey && (!down || !isWakeKeyWhenScreenOff(keyCode))) {
5907 isWakeKey = false;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005908 }
Anthony Hugh4b13ab82016-05-17 13:03:00 -07005909 // Cache the wake key on down event so we can also avoid sending the up event to the app
5910 if (isWakeKey && down) {
5911 mPendingWakeKey = keyCode;
5912 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005913 }
5914
Justin Kohd378ad72013-04-01 12:18:26 -07005915 // If the key would be handled globally, just return the result, don't worry about special
5916 // key processing.
Jeff Brown13f00f02014-10-31 14:45:50 -07005917 if (isValidGlobalKey(keyCode)
5918 && mGlobalKeyManager.shouldHandleGlobalKey(keyCode, event)) {
Michael Wright85b1af62014-06-04 14:51:58 -07005919 if (isWakeKey) {
Dianne Hackborn280a64e2015-07-13 14:48:08 -07005920 wakeUp(event.getEventTime(), mAllowTheaterModeWakeFromKey, "android.policy:KEY");
Michael Wright85b1af62014-06-04 14:51:58 -07005921 }
Justin Kohd378ad72013-04-01 12:18:26 -07005922 return result;
5923 }
5924
Jeff Brownbae8e772014-06-12 19:59:45 -07005925 boolean useHapticFeedback = down
5926 && (policyFlags & WindowManagerPolicy.FLAG_VIRTUAL) != 0
5927 && event.getRepeatCount() == 0;
5928
Jeff Brown4d396052010-10-29 21:50:21 -07005929 // Handle special keys.
5930 switch (keyCode) {
Anthony Hugh34f09ca2016-03-04 12:03:37 -08005931 case KeyEvent.KEYCODE_BACK: {
5932 if (down) {
Anthony Hugh96e9cc52016-07-12 15:17:24 -07005933 interceptBackKeyDown();
Anthony Hugh34f09ca2016-03-04 12:03:37 -08005934 } else {
Anthony Hugh96e9cc52016-07-12 15:17:24 -07005935 boolean handled = interceptBackKeyUp(event);
Anthony Hugh34f09ca2016-03-04 12:03:37 -08005936
Anthony Hugh96e9cc52016-07-12 15:17:24 -07005937 // Don't pass back press to app if we've already handled it via long press
Anthony Hugh34f09ca2016-03-04 12:03:37 -08005938 if (handled) {
5939 result &= ~ACTION_PASS_TO_USER;
5940 }
5941 }
5942 break;
5943 }
5944
Jeff Brown4d396052010-10-29 21:50:21 -07005945 case KeyEvent.KEYCODE_VOLUME_DOWN:
Jeff Brownb0418da2010-11-01 15:24:01 -07005946 case KeyEvent.KEYCODE_VOLUME_UP:
5947 case KeyEvent.KEYCODE_VOLUME_MUTE: {
Jeff Brownd5bb82d2011-10-12 13:57:59 -07005948 if (keyCode == KeyEvent.KEYCODE_VOLUME_DOWN) {
5949 if (down) {
Jeff Brown13f00f02014-10-31 14:45:50 -07005950 if (interactive && !mScreenshotChordVolumeDownKeyTriggered
Jeff Brownd5bb82d2011-10-12 13:57:59 -07005951 && (event.getFlags() & KeyEvent.FLAG_FALLBACK) == 0) {
Jeff Brown13f00f02014-10-31 14:45:50 -07005952 mScreenshotChordVolumeDownKeyTriggered = true;
5953 mScreenshotChordVolumeDownKeyTime = event.getDownTime();
5954 mScreenshotChordVolumeDownKeyConsumed = false;
Jeff Brownd5bb82d2011-10-12 13:57:59 -07005955 cancelPendingPowerKeyAction();
5956 interceptScreenshotChord();
Phil Weaverce687c52017-03-15 08:51:52 -07005957 interceptAccessibilityShortcutChord();
Jeff Brownd5bb82d2011-10-12 13:57:59 -07005958 }
5959 } else {
Jeff Brown13f00f02014-10-31 14:45:50 -07005960 mScreenshotChordVolumeDownKeyTriggered = false;
Jeff Brownd5bb82d2011-10-12 13:57:59 -07005961 cancelPendingScreenshotChordAction();
Phil Weaver106fe732016-11-22 18:18:39 -08005962 cancelPendingAccessibilityShortcutAction();
Jeff Brownd5bb82d2011-10-12 13:57:59 -07005963 }
5964 } else if (keyCode == KeyEvent.KEYCODE_VOLUME_UP) {
5965 if (down) {
Phil Weaver106fe732016-11-22 18:18:39 -08005966 if (interactive && !mA11yShortcutChordVolumeUpKeyTriggered
Jeff Brownd5bb82d2011-10-12 13:57:59 -07005967 && (event.getFlags() & KeyEvent.FLAG_FALLBACK) == 0) {
Phil Weaver106fe732016-11-22 18:18:39 -08005968 mA11yShortcutChordVolumeUpKeyTriggered = true;
5969 mA11yShortcutChordVolumeUpKeyTime = event.getDownTime();
5970 mA11yShortcutChordVolumeUpKeyConsumed = false;
Jeff Brownd5bb82d2011-10-12 13:57:59 -07005971 cancelPendingPowerKeyAction();
5972 cancelPendingScreenshotChordAction();
Phil Weaverce687c52017-03-15 08:51:52 -07005973 interceptAccessibilityShortcutChord();
Jeff Brownd5bb82d2011-10-12 13:57:59 -07005974 }
5975 } else {
Phil Weaver106fe732016-11-22 18:18:39 -08005976 mA11yShortcutChordVolumeUpKeyTriggered = false;
Jeff Brownd5bb82d2011-10-12 13:57:59 -07005977 cancelPendingScreenshotChordAction();
Phil Weaver106fe732016-11-22 18:18:39 -08005978 cancelPendingAccessibilityShortcutAction();
Jeff Brownd5bb82d2011-10-12 13:57:59 -07005979 }
5980 }
Jeff Brown4d396052010-10-29 21:50:21 -07005981 if (down) {
Philip Quinn4b5b3c62017-07-20 21:07:58 -07005982 sendSystemKeyToStatusBarAsync(event.getKeyCode());
5983
Tyler Gunnef9f6f92014-09-12 22:16:17 -07005984 TelecomManager telecomManager = getTelecommService();
5985 if (telecomManager != null) {
5986 if (telecomManager.isRinging()) {
Santos Cordon6848f722014-05-21 15:22:12 -07005987 // If an incoming call is ringing, either VOLUME key means
5988 // "silence ringer". We handle these keys here, rather than
5989 // in the InCallScreen, to make sure we'll respond to them
5990 // even if the InCallScreen hasn't come to the foreground yet.
5991 // Look for the DOWN event here, to agree with the "fallback"
5992 // behavior in the InCallScreen.
5993 Log.i(TAG, "interceptKeyBeforeQueueing:"
5994 + " VOLUME key-down while ringing: Silence ringer!");
Jeff Brown4d396052010-10-29 21:50:21 -07005995
Santos Cordon6848f722014-05-21 15:22:12 -07005996 // Silence the ringer. (It's safe to call this
5997 // even if the ringer has already been silenced.)
Tyler Gunnef9f6f92014-09-12 22:16:17 -07005998 telecomManager.silenceRinger();
Jeff Brown4d396052010-10-29 21:50:21 -07005999
Santos Cordon6848f722014-05-21 15:22:12 -07006000 // And *don't* pass this key thru to the current activity
6001 // (which is probably the InCallScreen.)
6002 result &= ~ACTION_PASS_TO_USER;
6003 break;
6004 }
Jeff Brown4d396052010-10-29 21:50:21 -07006005 }
Eric Laurenta9a52582017-05-10 15:16:01 -07006006 int audioMode = AudioManager.MODE_NORMAL;
6007 try {
6008 audioMode = getAudioService().getMode();
6009 } catch (Exception e) {
6010 Log.e(TAG, "Error getting AudioService in interceptKeyBeforeQueueing.", e);
6011 }
6012 boolean isInCall = (telecomManager != null && telecomManager.isInCall()) ||
6013 audioMode == AudioManager.MODE_IN_COMMUNICATION;
6014 if (isInCall && (result & ACTION_PASS_TO_USER) == 0) {
6015 // If we are in call but we decided not to pass the key to
6016 // the application, just pass it to the session service.
6017 MediaSessionLegacyHelper.getHelper(mContext).sendVolumeKeyEvent(
6018 event, AudioManager.USE_DEFAULT_STREAM_TYPE, false);
6019 break;
6020 }
Jaewan Kim765487f2016-01-12 14:45:42 +09006021 }
Karthik Ravi Shankar86ecf342017-04-28 15:35:58 -07006022 if (mUseTvRouting || mHandleVolumeKeysInWM) {
6023 // Defer special key handlings to
Jaewan Kim765487f2016-01-12 14:45:42 +09006024 // {@link interceptKeyBeforeDispatching()}.
6025 result |= ACTION_PASS_TO_USER;
6026 } else if ((result & ACTION_PASS_TO_USER) == 0) {
6027 // If we aren't passing to the user and no one else
6028 // handled it send it to the session manager to
6029 // figure out.
Jaewan Kim50269362016-12-23 11:22:02 +09006030 MediaSessionLegacyHelper.getHelper(mContext).sendVolumeKeyEvent(
David Linf52b6072017-04-21 18:52:18 -07006031 event, AudioManager.USE_DEFAULT_STREAM_TYPE, true);
Jeff Brown4d396052010-10-29 21:50:21 -07006032 }
6033 break;
6034 }
6035
6036 case KeyEvent.KEYCODE_ENDCALL: {
6037 result &= ~ACTION_PASS_TO_USER;
6038 if (down) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -07006039 TelecomManager telecomManager = getTelecommService();
Jeff Brown4d396052010-10-29 21:50:21 -07006040 boolean hungUp = false;
Tyler Gunnef9f6f92014-09-12 22:16:17 -07006041 if (telecomManager != null) {
6042 hungUp = telecomManager.endCall();
Jeff Brown4d396052010-10-29 21:50:21 -07006043 }
Jeff Brown13f00f02014-10-31 14:45:50 -07006044 if (interactive && !hungUp) {
6045 mEndCallKeyHandled = false;
6046 mHandler.postDelayed(mEndCallLongPress,
6047 ViewConfiguration.get(mContext).getDeviceGlobalActionKeyTimeout());
6048 } else {
6049 mEndCallKeyHandled = true;
6050 }
Jeff Brown4d396052010-10-29 21:50:21 -07006051 } else {
Jeff Brown13f00f02014-10-31 14:45:50 -07006052 if (!mEndCallKeyHandled) {
6053 mHandler.removeCallbacks(mEndCallLongPress);
6054 if (!canceled) {
6055 if ((mEndcallBehavior
6056 & Settings.System.END_BUTTON_BEHAVIOR_HOME) != 0) {
6057 if (goHome()) {
6058 break;
6059 }
Dianne Hackborn0041e972009-07-24 17:14:43 -07006060 }
Jeff Brown13f00f02014-10-31 14:45:50 -07006061 if ((mEndcallBehavior
6062 & Settings.System.END_BUTTON_BEHAVIOR_SLEEP) != 0) {
6063 mPowerManager.goToSleep(event.getEventTime(),
6064 PowerManager.GO_TO_SLEEP_REASON_POWER_BUTTON, 0);
6065 isWakeKey = false;
6066 }
Jeff Brown4d396052010-10-29 21:50:21 -07006067 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006068 }
Jeff Brown4d396052010-10-29 21:50:21 -07006069 }
6070 break;
6071 }
6072
6073 case KeyEvent.KEYCODE_POWER: {
Phil Weaver106fe732016-11-22 18:18:39 -08006074 // Any activity on the power button stops the accessibility shortcut
6075 cancelPendingAccessibilityShortcutAction();
Jeff Brown4d396052010-10-29 21:50:21 -07006076 result &= ~ACTION_PASS_TO_USER;
Jeff Brown13f00f02014-10-31 14:45:50 -07006077 isWakeKey = false; // wake-up will be handled separately
Jeff Brown4d396052010-10-29 21:50:21 -07006078 if (down) {
Jeff Brown13f00f02014-10-31 14:45:50 -07006079 interceptPowerKeyDown(event, interactive);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006080 } else {
Jeff Brown13f00f02014-10-31 14:45:50 -07006081 interceptPowerKeyUp(event, interactive, canceled);
Jeff Brown4d396052010-10-29 21:50:21 -07006082 }
6083 break;
6084 }
6085
Jim Miller07e03842016-06-22 15:18:13 -07006086 case KeyEvent.KEYCODE_SYSTEM_NAVIGATION_DOWN:
Jim Millerf4c0a132016-05-17 18:11:52 -07006087 // fall through
Jim Miller07e03842016-06-22 15:18:13 -07006088 case KeyEvent.KEYCODE_SYSTEM_NAVIGATION_UP:
Jim Millerf4c0a132016-05-17 18:11:52 -07006089 // fall through
Jim Miller07e03842016-06-22 15:18:13 -07006090 case KeyEvent.KEYCODE_SYSTEM_NAVIGATION_LEFT:
Jim Millerf4c0a132016-05-17 18:11:52 -07006091 // fall through
Jim Miller07e03842016-06-22 15:18:13 -07006092 case KeyEvent.KEYCODE_SYSTEM_NAVIGATION_RIGHT: {
6093 result &= ~ACTION_PASS_TO_USER;
6094 interceptSystemNavigationKey(event);
Jim Millerf4c0a132016-05-17 18:11:52 -07006095 break;
6096 }
6097
Jeff Brown6212a492014-03-07 13:58:47 -08006098 case KeyEvent.KEYCODE_SLEEP: {
6099 result &= ~ACTION_PASS_TO_USER;
Filip Gruszczynskia483a1d2015-03-17 19:06:58 +00006100 isWakeKey = false;
Jeff Brownbae8e772014-06-12 19:59:45 -07006101 if (!mPowerManager.isInteractive()) {
6102 useHapticFeedback = false; // suppress feedback if already non-interactive
6103 }
Nick Vaccarob593a812015-05-15 11:23:05 -07006104 if (down) {
6105 sleepPress(event.getEventTime());
6106 } else {
6107 sleepRelease(event.getEventTime());
6108 }
Jeff Brown6212a492014-03-07 13:58:47 -08006109 break;
6110 }
6111
Nick Armstrong-Crews56ecfcc2015-09-07 21:46:50 -07006112 case KeyEvent.KEYCODE_SOFT_SLEEP: {
6113 result &= ~ACTION_PASS_TO_USER;
6114 isWakeKey = false;
6115 if (!down) {
6116 mPowerManagerInternal.setUserInactiveOverrideFromWindowManager();
6117 }
6118 break;
6119 }
6120
Jeff Brown6212a492014-03-07 13:58:47 -08006121 case KeyEvent.KEYCODE_WAKEUP: {
6122 result &= ~ACTION_PASS_TO_USER;
Jose Lima9546b202014-07-02 17:21:51 -07006123 isWakeKey = true;
Jeff Brown6212a492014-03-07 13:58:47 -08006124 break;
6125 }
6126
Jeff Brown4d396052010-10-29 21:50:21 -07006127 case KeyEvent.KEYCODE_MEDIA_PLAY:
6128 case KeyEvent.KEYCODE_MEDIA_PAUSE:
6129 case KeyEvent.KEYCODE_MEDIA_PLAY_PAUSE:
Jeff Brown4d396052010-10-29 21:50:21 -07006130 case KeyEvent.KEYCODE_HEADSETHOOK:
6131 case KeyEvent.KEYCODE_MUTE:
6132 case KeyEvent.KEYCODE_MEDIA_STOP:
6133 case KeyEvent.KEYCODE_MEDIA_NEXT:
6134 case KeyEvent.KEYCODE_MEDIA_PREVIOUS:
6135 case KeyEvent.KEYCODE_MEDIA_REWIND:
6136 case KeyEvent.KEYCODE_MEDIA_RECORD:
Jaekyun Seokbfdad8e2013-07-08 13:53:21 +09006137 case KeyEvent.KEYCODE_MEDIA_FAST_FORWARD:
6138 case KeyEvent.KEYCODE_MEDIA_AUDIO_TRACK: {
RoboErikde9ba392014-09-26 12:51:01 -07006139 if (MediaSessionLegacyHelper.getHelper(mContext).isGlobalPriorityActive()) {
6140 // If the global session is active pass all media keys to it
6141 // instead of the active window.
6142 result &= ~ACTION_PASS_TO_USER;
6143 }
Jeff Brown4d396052010-10-29 21:50:21 -07006144 if ((result & ACTION_PASS_TO_USER) == 0) {
6145 // Only do this if we would otherwise not pass it to the user. In that
6146 // case, the PhoneWindow class will do the same thing, except it will
6147 // only do it if the showing app doesn't process the key on its own.
Jeff Brown40013652012-05-16 21:22:36 -07006148 // Note that we need to make a copy of the key event here because the
6149 // original key event will be recycled when we return.
Jeff Brown4d396052010-10-29 21:50:21 -07006150 mBroadcastWakeLock.acquire();
Jeff Brown40013652012-05-16 21:22:36 -07006151 Message msg = mHandler.obtainMessage(MSG_DISPATCH_MEDIA_KEY_WITH_WAKE_LOCK,
6152 new KeyEvent(event));
6153 msg.setAsynchronous(true);
6154 msg.sendToTarget();
Jeff Brown4d396052010-10-29 21:50:21 -07006155 }
6156 break;
Jeff Brown00fa7bd2010-07-02 15:37:36 -07006157 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006158
Jeff Brown4d396052010-10-29 21:50:21 -07006159 case KeyEvent.KEYCODE_CALL: {
6160 if (down) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -07006161 TelecomManager telecomManager = getTelecommService();
6162 if (telecomManager != null) {
6163 if (telecomManager.isRinging()) {
Santos Cordon6848f722014-05-21 15:22:12 -07006164 Log.i(TAG, "interceptKeyBeforeQueueing:"
6165 + " CALL key-down while ringing: Answer the call!");
Tyler Gunnef9f6f92014-09-12 22:16:17 -07006166 telecomManager.acceptRingingCall();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006167
Santos Cordon6848f722014-05-21 15:22:12 -07006168 // And *don't* pass this key thru to the current activity
6169 // (which is presumably the InCallScreen.)
6170 result &= ~ACTION_PASS_TO_USER;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006171 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006172 }
Jeff Brown00fa7bd2010-07-02 15:37:36 -07006173 }
Jeff Brown4d396052010-10-29 21:50:21 -07006174 break;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006175 }
Michael Wright869a67c2014-08-26 19:33:06 -07006176 case KeyEvent.KEYCODE_VOICE_ASSIST: {
6177 // Only do this if we would otherwise not pass it to the user. In that case,
6178 // interceptKeyBeforeDispatching would apply a similar but different policy in
6179 // order to invoke voice assist actions. Note that we need to make a copy of the
6180 // key event here because the original key event will be recycled when we return.
6181 if ((result & ACTION_PASS_TO_USER) == 0 && !down) {
6182 mBroadcastWakeLock.acquire();
6183 Message msg = mHandler.obtainMessage(MSG_LAUNCH_VOICE_ASSIST_WITH_WAKE_LOCK,
6184 keyguardActive ? 1 : 0, 0);
6185 msg.setAsynchronous(true);
6186 msg.sendToTarget();
6187 }
Jaewan Kim49117872016-01-19 17:24:08 +09006188 break;
6189 }
6190 case KeyEvent.KEYCODE_WINDOW: {
6191 if (mShortPressWindowBehavior == SHORT_PRESS_WINDOW_PICTURE_IN_PICTURE) {
Winson Chungac52f282017-03-30 14:44:52 -07006192 if (mPictureInPictureVisible) {
6193 // Consumes the key only if picture-in-picture is visible to show
6194 // picture-in-picture control menu. This gives a chance to the foreground
6195 // activity to customize PIP key behavior.
Jaewan Kimf0fd2182016-04-20 21:17:58 +09006196 if (!down) {
Winson Chungac52f282017-03-30 14:44:52 -07006197 showPictureInPictureMenu(event);
Jaewan Kimf0fd2182016-04-20 21:17:58 +09006198 }
6199 result &= ~ACTION_PASS_TO_USER;
Jaewan Kim49117872016-01-19 17:24:08 +09006200 }
Jaewan Kim49117872016-01-19 17:24:08 +09006201 }
6202 break;
Michael Wright869a67c2014-08-26 19:33:06 -07006203 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006204 }
Jeff Brown26875502014-01-30 21:47:47 -08006205
Jeff Brownbae8e772014-06-12 19:59:45 -07006206 if (useHapticFeedback) {
6207 performHapticFeedbackLw(null, HapticFeedbackConstants.VIRTUAL_KEY, false);
6208 }
6209
Jeff Brown26875502014-01-30 21:47:47 -08006210 if (isWakeKey) {
Dianne Hackborn280a64e2015-07-13 14:48:08 -07006211 wakeUp(event.getEventTime(), mAllowTheaterModeWakeFromKey, "android.policy:KEY");
Jeff Brown26875502014-01-30 21:47:47 -08006212 }
Bryce Lee584a4452014-10-21 15:55:55 -07006213
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006214 return result;
6215 }
6216
Jeff Brown1c2e4942012-11-06 16:32:01 -08006217 /**
Jim Millerf4c0a132016-05-17 18:11:52 -07006218 * Handle statusbar expansion events.
6219 * @param event
6220 */
Jim Miller07e03842016-06-22 15:18:13 -07006221 private void interceptSystemNavigationKey(KeyEvent event) {
Phil Weaver27fcd9c2017-01-20 15:57:24 -08006222 if (event.getAction() == KeyEvent.ACTION_UP) {
6223 if (!mAccessibilityManager.isEnabled()
6224 || !mAccessibilityManager.sendFingerprintGesture(event.getKeyCode())) {
6225 if (areSystemNavigationKeysEnabled()) {
Philip Quinn4b5b3c62017-07-20 21:07:58 -07006226 sendSystemKeyToStatusBarAsync(event.getKeyCode());
Jim Millerf4c0a132016-05-17 18:11:52 -07006227 }
6228 }
6229 }
6230 }
6231
6232 /**
Philip Quinn4b5b3c62017-07-20 21:07:58 -07006233 * Notify the StatusBar that a system key was pressed.
6234 */
6235 private void sendSystemKeyToStatusBar(int keyCode) {
6236 IStatusBarService statusBar = getStatusBarService();
6237 if (statusBar != null) {
6238 try {
6239 statusBar.handleSystemKey(keyCode);
6240 } catch (RemoteException e) {
6241 // Oh well.
6242 }
6243 }
6244 }
6245
6246 /**
6247 * Notify the StatusBar that a system key was pressed without blocking the current thread.
6248 */
6249 private void sendSystemKeyToStatusBarAsync(int keyCode) {
6250 Message message = mHandler.obtainMessage(MSG_SYSTEM_KEY_PRESS, keyCode, 0);
6251 message.setAsynchronous(true);
6252 mHandler.sendMessage(message);
6253 }
6254
6255 /**
Jeff Brown13f00f02014-10-31 14:45:50 -07006256 * Returns true if the key can have global actions attached to it.
6257 * We reserve all power management keys for the system since they require
6258 * very careful handling.
6259 */
6260 private static boolean isValidGlobalKey(int keyCode) {
6261 switch (keyCode) {
6262 case KeyEvent.KEYCODE_POWER:
6263 case KeyEvent.KEYCODE_WAKEUP:
6264 case KeyEvent.KEYCODE_SLEEP:
6265 return false;
6266 default:
6267 return true;
6268 }
6269 }
6270
6271 /**
Jeff Brown1c2e4942012-11-06 16:32:01 -08006272 * When the screen is off we ignore some keys that might otherwise typically
6273 * be considered wake keys. We filter them out here.
6274 *
6275 * {@link KeyEvent#KEYCODE_POWER} is notably absent from this list because it
6276 * is always considered a wake key.
6277 */
6278 private boolean isWakeKeyWhenScreenOff(int keyCode) {
6279 switch (keyCode) {
6280 // ignore volume keys unless docked
6281 case KeyEvent.KEYCODE_VOLUME_UP:
6282 case KeyEvent.KEYCODE_VOLUME_DOWN:
6283 case KeyEvent.KEYCODE_VOLUME_MUTE:
6284 return mDockMode != Intent.EXTRA_DOCK_STATE_UNDOCKED;
6285
6286 // ignore media and camera keys
6287 case KeyEvent.KEYCODE_MUTE:
6288 case KeyEvent.KEYCODE_HEADSETHOOK:
6289 case KeyEvent.KEYCODE_MEDIA_PLAY:
6290 case KeyEvent.KEYCODE_MEDIA_PAUSE:
6291 case KeyEvent.KEYCODE_MEDIA_PLAY_PAUSE:
6292 case KeyEvent.KEYCODE_MEDIA_STOP:
6293 case KeyEvent.KEYCODE_MEDIA_NEXT:
6294 case KeyEvent.KEYCODE_MEDIA_PREVIOUS:
6295 case KeyEvent.KEYCODE_MEDIA_REWIND:
6296 case KeyEvent.KEYCODE_MEDIA_RECORD:
6297 case KeyEvent.KEYCODE_MEDIA_FAST_FORWARD:
Jaekyun Seokbfdad8e2013-07-08 13:53:21 +09006298 case KeyEvent.KEYCODE_MEDIA_AUDIO_TRACK:
Jeff Brown1c2e4942012-11-06 16:32:01 -08006299 case KeyEvent.KEYCODE_CAMERA:
6300 return false;
6301 }
6302 return true;
6303 }
6304
6305
Jeff Brown56194eb2011-03-02 19:23:13 -08006306 /** {@inheritDoc} */
6307 @Override
Michael Wright70af00a2014-09-03 19:30:20 -07006308 public int interceptMotionBeforeQueueingNonInteractive(long whenNanos, int policyFlags) {
6309 if ((policyFlags & FLAG_WAKE) != 0) {
Dianne Hackborn280a64e2015-07-13 14:48:08 -07006310 if (wakeUp(whenNanos / 1000000, mAllowTheaterModeWakeFromMotion,
6311 "android.policy:MOTION")) {
Bryce Lee5c138322014-11-03 08:26:09 -08006312 return 0;
6313 }
Michael Wright70af00a2014-09-03 19:30:20 -07006314 }
Bryce Lee5c138322014-11-03 08:26:09 -08006315
Anthony Hugh4b13ab82016-05-17 13:03:00 -07006316 if (shouldDispatchInputWhenNonInteractive(null)) {
Michael Wright70af00a2014-09-03 19:30:20 -07006317 return ACTION_PASS_TO_USER;
6318 }
Bryce Lee5c138322014-11-03 08:26:09 -08006319
Bryce Lee812d7022014-11-10 13:33:28 -08006320 // If we have not passed the action up and we are in theater mode without dreaming,
6321 // there will be no dream to intercept the touch and wake into ambient. The device should
6322 // wake up in this case.
6323 if (isTheaterModeEnabled() && (policyFlags & FLAG_WAKE) != 0) {
Dianne Hackborn280a64e2015-07-13 14:48:08 -07006324 wakeUp(whenNanos / 1000000, mAllowTheaterModeWakeFromMotionWhenNotDreaming,
6325 "android.policy:MOTION");
Bryce Lee812d7022014-11-10 13:33:28 -08006326 }
6327
Jeff Brown037c33e2014-04-09 00:31:55 -07006328 return 0;
Jeff Brown56194eb2011-03-02 19:23:13 -08006329 }
6330
Anthony Hugh4b13ab82016-05-17 13:03:00 -07006331 private boolean shouldDispatchInputWhenNonInteractive(KeyEvent event) {
Wale Ogunwale6b15ea52016-04-04 07:28:27 -07006332 final boolean displayOff = (mDisplay == null || mDisplay.getState() == Display.STATE_OFF);
6333
6334 if (displayOff && !mHasFeatureWatch) {
6335 return false;
6336 }
6337
6338 // Send events to keyguard while the screen is on and it's showing.
6339 if (isKeyguardShowingAndNotOccluded() && !displayOff) {
Bryce Lee5c138322014-11-03 08:26:09 -08006340 return true;
6341 }
6342
Anthony Hugh4b13ab82016-05-17 13:03:00 -07006343 // Watches handle BACK specially
6344 if (mHasFeatureWatch
6345 && event != null
6346 && (event.getKeyCode() == KeyEvent.KEYCODE_BACK
6347 || event.getKeyCode() == KeyEvent.KEYCODE_STEM_PRIMARY)) {
6348 return false;
6349 }
6350
Bryce Lee5c138322014-11-03 08:26:09 -08006351 // Send events to a dozing dream even if the screen is off since the dream
6352 // is in control of the state of the screen.
6353 IDreamManager dreamManager = getDreamManager();
6354
6355 try {
6356 if (dreamManager != null && dreamManager.isDreaming()) {
6357 return true;
6358 }
6359 } catch (RemoteException e) {
6360 Slog.e(TAG, "RemoteException when checking if dreaming", e);
6361 }
6362
6363 // Otherwise, consume events since the user can't see what is being
6364 // interacted with.
6365 return false;
Michael Wright70af00a2014-09-03 19:30:20 -07006366 }
6367
RoboErik001c59c2015-01-26 15:53:51 -08006368 private void dispatchDirectAudioEvent(KeyEvent event) {
6369 if (event.getAction() != KeyEvent.ACTION_DOWN) {
6370 return;
6371 }
6372 int keyCode = event.getKeyCode();
John Spurlockb94f2d62015-03-17 14:11:57 -04006373 int flags = AudioManager.FLAG_SHOW_UI | AudioManager.FLAG_PLAY_SOUND
6374 | AudioManager.FLAG_FROM_KEY;
RoboErik001c59c2015-01-26 15:53:51 -08006375 String pkgName = mContext.getOpPackageName();
6376 switch (keyCode) {
6377 case KeyEvent.KEYCODE_VOLUME_UP:
6378 try {
John Spurlockee5ad722015-03-03 16:17:21 -05006379 getAudioService().adjustSuggestedStreamVolume(AudioManager.ADJUST_RAISE,
John Spurlock90874332015-03-10 16:00:54 -04006380 AudioManager.USE_DEFAULT_STREAM_TYPE, flags, pkgName, TAG);
Eric Laurenta9a52582017-05-10 15:16:01 -07006381 } catch (Exception e) {
RoboErik001c59c2015-01-26 15:53:51 -08006382 Log.e(TAG, "Error dispatching volume up in dispatchTvAudioEvent.", e);
6383 }
6384 break;
6385 case KeyEvent.KEYCODE_VOLUME_DOWN:
6386 try {
John Spurlockee5ad722015-03-03 16:17:21 -05006387 getAudioService().adjustSuggestedStreamVolume(AudioManager.ADJUST_LOWER,
John Spurlock90874332015-03-10 16:00:54 -04006388 AudioManager.USE_DEFAULT_STREAM_TYPE, flags, pkgName, TAG);
Eric Laurenta9a52582017-05-10 15:16:01 -07006389 } catch (Exception e) {
RoboErik001c59c2015-01-26 15:53:51 -08006390 Log.e(TAG, "Error dispatching volume down in dispatchTvAudioEvent.", e);
6391 }
6392 break;
6393 case KeyEvent.KEYCODE_VOLUME_MUTE:
6394 try {
6395 if (event.getRepeatCount() == 0) {
John Spurlockee5ad722015-03-03 16:17:21 -05006396 getAudioService().adjustSuggestedStreamVolume(
6397 AudioManager.ADJUST_TOGGLE_MUTE,
John Spurlock90874332015-03-10 16:00:54 -04006398 AudioManager.USE_DEFAULT_STREAM_TYPE, flags, pkgName, TAG);
RoboErik001c59c2015-01-26 15:53:51 -08006399 }
Eric Laurenta9a52582017-05-10 15:16:01 -07006400 } catch (Exception e) {
RoboErik001c59c2015-01-26 15:53:51 -08006401 Log.e(TAG, "Error dispatching mute in dispatchTvAudioEvent.", e);
6402 }
6403 break;
6404 }
6405 }
6406
Jeff Brown40013652012-05-16 21:22:36 -07006407 void dispatchMediaKeyWithWakeLock(KeyEvent event) {
6408 if (DEBUG_INPUT) {
6409 Slog.d(TAG, "dispatchMediaKeyWithWakeLock: " + event);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006410 }
6411
Jeff Brown40013652012-05-16 21:22:36 -07006412 if (mHavePendingMediaKeyRepeatWithWakeLock) {
6413 if (DEBUG_INPUT) {
6414 Slog.d(TAG, "dispatchMediaKeyWithWakeLock: canceled repeat");
6415 }
6416
6417 mHandler.removeMessages(MSG_DISPATCH_MEDIA_KEY_REPEAT_WITH_WAKE_LOCK);
6418 mHavePendingMediaKeyRepeatWithWakeLock = false;
6419 mBroadcastWakeLock.release(); // pending repeat was holding onto the wake lock
6420 }
6421
6422 dispatchMediaKeyWithWakeLockToAudioService(event);
6423
6424 if (event.getAction() == KeyEvent.ACTION_DOWN
6425 && event.getRepeatCount() == 0) {
6426 mHavePendingMediaKeyRepeatWithWakeLock = true;
6427
6428 Message msg = mHandler.obtainMessage(
6429 MSG_DISPATCH_MEDIA_KEY_REPEAT_WITH_WAKE_LOCK, event);
6430 msg.setAsynchronous(true);
6431 mHandler.sendMessageDelayed(msg, ViewConfiguration.getKeyRepeatTimeout());
6432 } else {
6433 mBroadcastWakeLock.release();
6434 }
6435 }
6436
6437 void dispatchMediaKeyRepeatWithWakeLock(KeyEvent event) {
6438 mHavePendingMediaKeyRepeatWithWakeLock = false;
6439
6440 KeyEvent repeatEvent = KeyEvent.changeTimeRepeat(event,
6441 SystemClock.uptimeMillis(), 1, event.getFlags() | KeyEvent.FLAG_LONG_PRESS);
6442 if (DEBUG_INPUT) {
6443 Slog.d(TAG, "dispatchMediaKeyRepeatWithWakeLock: " + repeatEvent);
6444 }
6445
6446 dispatchMediaKeyWithWakeLockToAudioService(repeatEvent);
6447 mBroadcastWakeLock.release();
6448 }
6449
6450 void dispatchMediaKeyWithWakeLockToAudioService(KeyEvent event) {
Sudheer Shankafc46e9b2016-10-21 17:55:27 -07006451 if (mActivityManagerInternal.isSystemReady()) {
RoboErik430fc482014-06-12 15:49:20 -07006452 MediaSessionLegacyHelper.getHelper(mContext).sendMediaButtonEvent(event, true);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006453 }
6454 }
6455
Michael Wright869a67c2014-08-26 19:33:06 -07006456 void launchVoiceAssistWithWakeLock(boolean keyguardActive) {
Dianne Hackbornb6683c42015-06-18 17:40:33 -07006457 IDeviceIdleController dic = IDeviceIdleController.Stub.asInterface(
6458 ServiceManager.getService(Context.DEVICE_IDLE_CONTROLLER));
6459 if (dic != null) {
6460 try {
6461 dic.exitIdle("voice-search");
6462 } catch (RemoteException e) {
6463 }
6464 }
Michael Wright869a67c2014-08-26 19:33:06 -07006465 Intent voiceIntent =
6466 new Intent(RecognizerIntent.ACTION_VOICE_SEARCH_HANDS_FREE);
6467 voiceIntent.putExtra(RecognizerIntent.EXTRA_SECURE, keyguardActive);
Bart Sears8b1c27c2015-03-18 23:51:02 +00006468 startActivityAsUser(voiceIntent, UserHandle.CURRENT_OR_SELF);
Michael Wright869a67c2014-08-26 19:33:06 -07006469 mBroadcastWakeLock.release();
6470 }
6471
Mike Lockwood1753f7f2009-08-24 14:49:07 -07006472 BroadcastReceiver mDockReceiver = new BroadcastReceiver() {
Craig Mautnereee29c42013-01-17 14:44:34 -08006473 @Override
Mike Lockwood1753f7f2009-08-24 14:49:07 -07006474 public void onReceive(Context context, Intent intent) {
Dianne Hackborn867ab6472010-04-29 13:28:56 -07006475 if (Intent.ACTION_DOCK_EVENT.equals(intent.getAction())) {
6476 mDockMode = intent.getIntExtra(Intent.EXTRA_DOCK_STATE,
6477 Intent.EXTRA_DOCK_STATE_UNDOCKED);
Daniel Sandler6396c722013-04-16 20:19:09 -04006478 } else {
6479 try {
6480 IUiModeManager uiModeService = IUiModeManager.Stub.asInterface(
6481 ServiceManager.getService(Context.UI_MODE_SERVICE));
6482 mUiMode = uiModeService.getCurrentModeType();
6483 } catch (RemoteException e) {
6484 }
Dianne Hackborn80fa1662009-10-07 14:02:10 -07006485 }
Jeff Brown01a98dd2011-09-20 15:08:29 -07006486 updateRotation(true);
Craig Mautnereee29c42013-01-17 14:44:34 -08006487 synchronized (mLock) {
6488 updateOrientationListenerLp();
6489 }
Mike Lockwood1753f7f2009-08-24 14:49:07 -07006490 }
6491 };
6492
Jeff Brown6aaf2952012-10-05 16:01:08 -07006493 BroadcastReceiver mDreamReceiver = new BroadcastReceiver() {
6494 @Override
6495 public void onReceive(Context context, Intent intent) {
6496 if (Intent.ACTION_DREAMING_STARTED.equals(intent.getAction())) {
Jim Miller5ecd8112013-01-09 18:50:26 -08006497 if (mKeyguardDelegate != null) {
6498 mKeyguardDelegate.onDreamingStarted();
Jeff Brown6aaf2952012-10-05 16:01:08 -07006499 }
6500 } else if (Intent.ACTION_DREAMING_STOPPED.equals(intent.getAction())) {
Jim Miller5ecd8112013-01-09 18:50:26 -08006501 if (mKeyguardDelegate != null) {
6502 mKeyguardDelegate.onDreamingStopped();
Jeff Brown6aaf2952012-10-05 16:01:08 -07006503 }
6504 }
6505 }
6506 };
6507
Christopher Tate5e08af02012-09-21 17:17:22 -07006508 BroadcastReceiver mMultiuserReceiver = new BroadcastReceiver() {
6509 @Override
6510 public void onReceive(Context context, Intent intent) {
6511 if (Intent.ACTION_USER_SWITCHED.equals(intent.getAction())) {
6512 // tickle the settings observer: this first ensures that we're
6513 // observing the relevant settings for the newly-active user,
6514 // and then updates our own bookkeeping based on the now-
6515 // current user.
6516 mSettingsObserver.onChange(false);
John Spurlockce479d82012-11-29 09:52:21 -05006517
6518 // force a re-application of focused window sysui visibility.
6519 // the window may never have been shown for this user
6520 // e.g. the keyguard when going through the new-user setup flow
John Spurlock04db1762013-05-13 12:46:41 -04006521 synchronized (mWindowManagerFuncs.getWindowManagerLock()) {
John Spurlockce479d82012-11-29 09:52:21 -05006522 mLastSystemUiFlags = 0;
6523 updateSystemUiVisibilityLw();
6524 }
Christopher Tate5e08af02012-09-21 17:17:22 -07006525 }
6526 }
6527 };
6528
Adrian Roosddc8b272015-05-21 16:28:27 -07006529 private final Runnable mHiddenNavPanic = new Runnable() {
John Spurlockd9b70bd2014-02-06 17:02:44 -05006530 @Override
6531 public void run() {
Adrian Roosddc8b272015-05-21 16:28:27 -07006532 synchronized (mWindowManagerFuncs.getWindowManagerLock()) {
6533 if (!isUserSetupComplete()) {
6534 // Swipe-up for navigation bar is disabled during setup
6535 return;
6536 }
6537 mPendingPanicGestureUptime = SystemClock.uptimeMillis();
Adrian Roos1f425902016-07-22 10:37:50 -07006538 if (!isNavBarEmpty(mLastSystemUiFlags)) {
6539 mNavigationBarController.showTransient();
6540 }
Adrian Roosddc8b272015-05-21 16:28:27 -07006541 }
John Spurlockd9b70bd2014-02-06 17:02:44 -05006542 }
6543 };
6544
John Spurlocke1f366f2013-08-05 12:22:40 -04006545 private void requestTransientBars(WindowState swipeTarget) {
John Spurlock04db1762013-05-13 12:46:41 -04006546 synchronized (mWindowManagerFuncs.getWindowManagerLock()) {
Maurice Lam99c6e072014-04-28 18:24:28 -07006547 if (!isUserSetupComplete()) {
6548 // Swipe-up for navigation bar is disabled during setup
6549 return;
6550 }
John Spurlock27735a42013-08-14 17:57:38 -04006551 boolean sb = mStatusBarController.checkShowTransientBarLw();
Adrian Roos1f425902016-07-22 10:37:50 -07006552 boolean nb = mNavigationBarController.checkShowTransientBarLw()
6553 && !isNavBarEmpty(mLastSystemUiFlags);
John Spurlockad3e6cb2013-04-30 08:47:43 -04006554 if (sb || nb) {
Adrian Roos62b65e42015-02-25 18:05:34 +01006555 // Don't show status bar when swiping on already visible navigation bar
6556 if (!nb && swipeTarget == mNavigationBar) {
John Spurlocke1f366f2013-08-05 12:22:40 -04006557 if (DEBUG) Slog.d(TAG, "Not showing transient bar, wrong swipe target");
John Spurlockad3e6cb2013-04-30 08:47:43 -04006558 return;
6559 }
John Spurlock27735a42013-08-14 17:57:38 -04006560 if (sb) mStatusBarController.showTransient();
6561 if (nb) mNavigationBarController.showTransient();
John Spurlockf1a36642013-10-12 17:50:42 -04006562 mImmersiveModeConfirmation.confirmCurrentPrompt();
John Spurlockad3e6cb2013-04-30 08:47:43 -04006563 updateSystemUiVisibilityLw();
John Spurlock32beb2c2013-03-11 10:16:47 -04006564 }
John Spurlockad3e6cb2013-04-30 08:47:43 -04006565 }
6566 }
6567
Jeff Brown3ee549c2014-09-22 20:14:39 -07006568 // Called on the PowerManager's Notifier thread.
Jeff Brownc38c9be2012-10-04 13:16:19 -07006569 @Override
Jeff Brown416c49c2015-05-26 19:50:18 -07006570 public void startedGoingToSleep(int why) {
6571 if (DEBUG_WAKEUP) Slog.i(TAG, "Started going to sleep... (why=" + why + ")");
Jorim Jaggif1cdf952016-04-05 21:41:06 -07006572 mCameraGestureTriggeredDuringGoingToSleep = false;
6573 mGoingToSleep = true;
Jorim Jaggid175b6c2015-05-27 15:39:09 -07006574 if (mKeyguardDelegate != null) {
6575 mKeyguardDelegate.onStartedGoingToSleep(why);
6576 }
Jeff Brown416c49c2015-05-26 19:50:18 -07006577 }
6578
6579 // Called on the PowerManager's Notifier thread.
6580 @Override
6581 public void finishedGoingToSleep(int why) {
Dianne Hackborn74489012009-03-24 20:50:09 -07006582 EventLog.writeEvent(70000, 0);
Jeff Brown416c49c2015-05-26 19:50:18 -07006583 if (DEBUG_WAKEUP) Slog.i(TAG, "Finished going to sleep... (why=" + why + ")");
Chris Wren9bb290b2015-06-29 12:02:13 -04006584 MetricsLogger.histogram(mContext, "screen_timeout", mLockScreenTimeout / 1000);
Jeff Brown3ee549c2014-09-22 20:14:39 -07006585
Jorim Jaggif1cdf952016-04-05 21:41:06 -07006586 mGoingToSleep = false;
6587
Jeff Brown3ee549c2014-09-22 20:14:39 -07006588 // We must get this work done here because the power manager will drop
6589 // the wake lock and let the system suspend once this function returns.
The Android Open Source Project0727d222009-03-11 12:11:58 -07006590 synchronized (mLock) {
Jeff Brown3ee549c2014-09-22 20:14:39 -07006591 mAwake = false;
Jeff Browna20dda42014-05-27 20:57:24 -07006592 updateWakeGestureListenerLp();
The Android Open Source Project0727d222009-03-11 12:11:58 -07006593 updateOrientationListenerLp();
Mike Lockwood28569302010-01-28 11:54:40 -05006594 updateLockScreenTimeout();
The Android Open Source Project0727d222009-03-11 12:11:58 -07006595 }
Jeff Brown3ee549c2014-09-22 20:14:39 -07006596 if (mKeyguardDelegate != null) {
Jorim Jaggif1cdf952016-04-05 21:41:06 -07006597 mKeyguardDelegate.onFinishedGoingToSleep(why,
6598 mCameraGestureTriggeredDuringGoingToSleep);
Jeff Brown3ee549c2014-09-22 20:14:39 -07006599 }
Jorim Jaggif1cdf952016-04-05 21:41:06 -07006600 mCameraGestureTriggeredDuringGoingToSleep = false;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006601 }
6602
Jeff Brown3ee549c2014-09-22 20:14:39 -07006603 // Called on the PowerManager's Notifier thread.
Jeff Brownc38c9be2012-10-04 13:16:19 -07006604 @Override
Jeff Brown416c49c2015-05-26 19:50:18 -07006605 public void startedWakingUp() {
Dianne Hackborn74489012009-03-24 20:50:09 -07006606 EventLog.writeEvent(70000, 1);
Jeff Brown416c49c2015-05-26 19:50:18 -07006607 if (DEBUG_WAKEUP) Slog.i(TAG, "Started waking up...");
Craig Mautner8a0da012014-05-31 15:13:37 -07006608
Jeff Brown3ee549c2014-09-22 20:14:39 -07006609 // Since goToSleep performs these functions synchronously, we must
6610 // do the same here. We cannot post this work to a handler because
6611 // that might cause it to become reordered with respect to what
6612 // may happen in a future call to goToSleep.
The Android Open Source Project0727d222009-03-11 12:11:58 -07006613 synchronized (mLock) {
Jeff Brown3ee549c2014-09-22 20:14:39 -07006614 mAwake = true;
Jeff Brown3ee549c2014-09-22 20:14:39 -07006615
Jeff Browna20dda42014-05-27 20:57:24 -07006616 updateWakeGestureListenerLp();
The Android Open Source Project0727d222009-03-11 12:11:58 -07006617 updateOrientationListenerLp();
Mike Lockwood28569302010-01-28 11:54:40 -05006618 updateLockScreenTimeout();
The Android Open Source Project0727d222009-03-11 12:11:58 -07006619 }
Jeff Brownc38c9be2012-10-04 13:16:19 -07006620
Jim Miller5ecd8112013-01-09 18:50:26 -08006621 if (mKeyguardDelegate != null) {
Jorim Jaggi4cfdcf52015-07-09 12:13:59 -07006622 mKeyguardDelegate.onStartedWakingUp();
Jeff Brownc38c9be2012-10-04 13:16:19 -07006623 }
Jeff Brown36c4db82014-09-19 12:05:31 -07006624 }
6625
Jeff Brown416c49c2015-05-26 19:50:18 -07006626 // Called on the PowerManager's Notifier thread.
6627 @Override
6628 public void finishedWakingUp() {
6629 if (DEBUG_WAKEUP) Slog.i(TAG, "Finished waking up...");
Adrian Roos369907f2017-07-14 14:53:39 +02006630
6631 if (mKeyguardDelegate != null) {
6632 mKeyguardDelegate.onFinishedWakingUp();
6633 }
Jeff Brown416c49c2015-05-26 19:50:18 -07006634 }
6635
6636 private void wakeUpFromPowerKey(long eventTime) {
Dianne Hackborn280a64e2015-07-13 14:48:08 -07006637 wakeUp(eventTime, mAllowTheaterModeWakeFromPowerKey, "android.policy:POWER");
Jeff Brown416c49c2015-05-26 19:50:18 -07006638 }
6639
Dianne Hackborn280a64e2015-07-13 14:48:08 -07006640 private boolean wakeUp(long wakeTime, boolean wakeInTheaterMode, String reason) {
Bryce Leed3896842015-06-23 17:06:51 -07006641 final boolean theaterModeEnabled = isTheaterModeEnabled();
6642 if (!wakeInTheaterMode && theaterModeEnabled) {
Jeff Brown416c49c2015-05-26 19:50:18 -07006643 return false;
6644 }
6645
Bryce Leed3896842015-06-23 17:06:51 -07006646 if (theaterModeEnabled) {
6647 Settings.Global.putInt(mContext.getContentResolver(),
6648 Settings.Global.THEATER_MODE_ON, 0);
6649 }
6650
Dianne Hackborn280a64e2015-07-13 14:48:08 -07006651 mPowerManager.wakeUp(wakeTime, reason);
Jeff Brown416c49c2015-05-26 19:50:18 -07006652 return true;
6653 }
6654
Jeff Brown36c4db82014-09-19 12:05:31 -07006655 private void finishKeyguardDrawn() {
Jeff Brown3ee549c2014-09-22 20:14:39 -07006656 synchronized (mLock) {
Jorim Jaggif3255482015-07-24 12:32:42 -07006657 if (!mScreenOnEarly || mKeyguardDrawComplete) {
Stefan Kuhne9326dc12015-06-12 09:25:32 -10006658 return; // We are not awake yet or we have already informed of this event.
Jeff Brown3ee549c2014-09-22 20:14:39 -07006659 }
6660
Jeff Brown36c4db82014-09-19 12:05:31 -07006661 mKeyguardDrawComplete = true;
Jeff Brown3ee549c2014-09-22 20:14:39 -07006662 if (mKeyguardDelegate != null) {
6663 mHandler.removeMessages(MSG_KEYGUARD_DRAWN_TIMEOUT);
6664 }
Jorim Jaggi4cfdcf52015-07-09 12:13:59 -07006665 mWindowManagerDrawComplete = false;
Jeff Brown3ee549c2014-09-22 20:14:39 -07006666 }
6667
Jorim Jaggi4cfdcf52015-07-09 12:13:59 -07006668 // ... eventually calls finishWindowsDrawn which will finalize our screen turn on
6669 // as well as enabling the orientation change logic/sensor.
6670 mWindowManagerInternal.waitForAllWindowsDrawn(mWindowManagerDrawCallback,
6671 WAITING_FOR_DRAWN_TIMEOUT);
Jeff Brown3ee549c2014-09-22 20:14:39 -07006672 }
6673
6674 // Called on the DisplayManager's DisplayPowerController thread.
6675 @Override
6676 public void screenTurnedOff() {
6677 if (DEBUG_WAKEUP) Slog.i(TAG, "Screen turned off...");
6678
Jeff Brown48d1b142015-06-10 16:36:03 -07006679 updateScreenOffSleepToken(true);
Jeff Brown3ee549c2014-09-22 20:14:39 -07006680 synchronized (mLock) {
6681 mScreenOnEarly = false;
6682 mScreenOnFully = false;
Jorim Jaggi95c6dae2015-07-29 15:17:23 -07006683 mKeyguardDrawComplete = false;
Jeff Brown3ee549c2014-09-22 20:14:39 -07006684 mWindowManagerDrawComplete = false;
6685 mScreenOnListener = null;
6686 updateOrientationListenerLp();
Jorim Jaggi0d210f62015-07-10 14:24:44 -07006687
6688 if (mKeyguardDelegate != null) {
6689 mKeyguardDelegate.onScreenTurnedOff();
6690 }
Jeff Brown36c4db82014-09-19 12:05:31 -07006691 }
Ruben Brunkfecb6152016-10-28 20:18:57 -07006692 reportScreenStateToVrManager(false);
Jeff Brown36c4db82014-09-19 12:05:31 -07006693 }
6694
Keun-young Park4136d2d2017-05-08 14:51:59 -07006695 private long getKeyguardDrawnTimeout() {
6696 final boolean bootCompleted =
6697 LocalServices.getService(SystemServiceManager.class).isBootCompleted();
6698 // Set longer timeout if it has not booted yet to prevent showing empty window.
6699 return bootCompleted ? 1000 : 5000;
6700 }
6701
Jeff Brown3ee549c2014-09-22 20:14:39 -07006702 // Called on the DisplayManager's DisplayPowerController thread.
Jeff Brown36c4db82014-09-19 12:05:31 -07006703 @Override
6704 public void screenTurningOn(final ScreenOnListener screenOnListener) {
Jeff Brown36c4db82014-09-19 12:05:31 -07006705 if (DEBUG_WAKEUP) Slog.i(TAG, "Screen turning on...");
Jeff Brown36c4db82014-09-19 12:05:31 -07006706
Jeff Brown48d1b142015-06-10 16:36:03 -07006707 updateScreenOffSleepToken(false);
Jeff Brown3ee549c2014-09-22 20:14:39 -07006708 synchronized (mLock) {
6709 mScreenOnEarly = true;
6710 mScreenOnFully = false;
Jorim Jaggi95c6dae2015-07-29 15:17:23 -07006711 mKeyguardDrawComplete = false;
Jeff Brown3ee549c2014-09-22 20:14:39 -07006712 mWindowManagerDrawComplete = false;
6713 mScreenOnListener = screenOnListener;
Jeff Brown36c4db82014-09-19 12:05:31 -07006714
Jorim Jaggi4cfdcf52015-07-09 12:13:59 -07006715 if (mKeyguardDelegate != null) {
Jorim Jaggia4b51bc2015-08-10 18:20:43 -07006716 mHandler.removeMessages(MSG_KEYGUARD_DRAWN_TIMEOUT);
Keun-young Park4136d2d2017-05-08 14:51:59 -07006717 mHandler.sendEmptyMessageDelayed(MSG_KEYGUARD_DRAWN_TIMEOUT,
6718 getKeyguardDrawnTimeout());
Jorim Jaggi4cfdcf52015-07-09 12:13:59 -07006719 mKeyguardDelegate.onScreenTurningOn(mKeyguardDrawnCallback);
6720 } else {
6721 if (DEBUG_WAKEUP) Slog.d(TAG,
6722 "null mKeyguardDelegate: setting mKeyguardDrawComplete.");
6723 finishKeyguardDrawn();
6724 }
6725 }
Jeff Brown36c4db82014-09-19 12:05:31 -07006726 }
6727
Jorim Jaggi0d210f62015-07-10 14:24:44 -07006728 // Called on the DisplayManager's DisplayPowerController thread.
6729 @Override
6730 public void screenTurnedOn() {
6731 synchronized (mLock) {
6732 if (mKeyguardDelegate != null) {
6733 mKeyguardDelegate.onScreenTurnedOn();
6734 }
6735 }
Ruben Brunkfecb6152016-10-28 20:18:57 -07006736 reportScreenStateToVrManager(true);
6737 }
6738
Jorim Jaggi51304d72017-05-17 17:25:32 +02006739 @Override
6740 public void screenTurningOff(ScreenOffListener screenOffListener) {
6741 mWindowManagerFuncs.screenTurningOff(screenOffListener);
Adrian Roos369907f2017-07-14 14:53:39 +02006742 synchronized (mLock) {
6743 if (mKeyguardDelegate != null) {
6744 mKeyguardDelegate.onScreenTurningOff();
6745 }
6746 }
Jorim Jaggi51304d72017-05-17 17:25:32 +02006747 }
6748
Ruben Brunkfecb6152016-10-28 20:18:57 -07006749 private void reportScreenStateToVrManager(boolean isScreenOn) {
Zak Cohen732aeb02017-01-29 14:19:52 -08006750 if (mVrManagerInternal == null) {
Ruben Brunkfecb6152016-10-28 20:18:57 -07006751 return;
6752 }
Zak Cohen732aeb02017-01-29 14:19:52 -08006753 mVrManagerInternal.onScreenStateChanged(isScreenOn);
6754 }
6755
Jeff Brown36c4db82014-09-19 12:05:31 -07006756 private void finishWindowsDrawn() {
Jeff Brown3ee549c2014-09-22 20:14:39 -07006757 synchronized (mLock) {
6758 if (!mScreenOnEarly || mWindowManagerDrawComplete) {
Stefan Kuhne9326dc12015-06-12 09:25:32 -10006759 return; // Screen is not turned on or we did already handle this case earlier.
Jeff Brown3ee549c2014-09-22 20:14:39 -07006760 }
6761
Jeff Brown36c4db82014-09-19 12:05:31 -07006762 mWindowManagerDrawComplete = true;
Jeff Brown36c4db82014-09-19 12:05:31 -07006763 }
Jeff Brown3ee549c2014-09-22 20:14:39 -07006764
6765 finishScreenTurningOn();
Jeff Brownc38c9be2012-10-04 13:16:19 -07006766 }
6767
Craig Mautner8a0da012014-05-31 15:13:37 -07006768 private void finishScreenTurningOn() {
Stefan Kuhne9326dc12015-06-12 09:25:32 -10006769 synchronized (mLock) {
6770 // We have just finished drawing screen content. Since the orientation listener
6771 // gets only installed when all windows are drawn, we try to install it again.
6772 updateOrientationListenerLp();
6773 }
Jeff Brown3ee549c2014-09-22 20:14:39 -07006774 final ScreenOnListener listener;
6775 final boolean enableScreen;
Jeff Brown36c4db82014-09-19 12:05:31 -07006776 synchronized (mLock) {
Jeff Brown3ee549c2014-09-22 20:14:39 -07006777 if (DEBUG_WAKEUP) Slog.d(TAG,
6778 "finishScreenTurningOn: mAwake=" + mAwake
6779 + ", mScreenOnEarly=" + mScreenOnEarly
6780 + ", mScreenOnFully=" + mScreenOnFully
6781 + ", mKeyguardDrawComplete=" + mKeyguardDrawComplete
6782 + ", mWindowManagerDrawComplete=" + mWindowManagerDrawComplete);
6783
6784 if (mScreenOnFully || !mScreenOnEarly || !mWindowManagerDrawComplete
6785 || (mAwake && !mKeyguardDrawComplete)) {
6786 return; // spurious or not ready yet
Jeff Brown36c4db82014-09-19 12:05:31 -07006787 }
6788
Jeff Brown3ee549c2014-09-22 20:14:39 -07006789 if (DEBUG_WAKEUP) Slog.i(TAG, "Finished screen turning on...");
6790 listener = mScreenOnListener;
Craig Mautner13f6ea72014-06-23 14:57:02 -07006791 mScreenOnListener = null;
Jeff Brown3ee549c2014-09-22 20:14:39 -07006792 mScreenOnFully = true;
6793
6794 // Remember the first time we draw the keyguard so we know when we're done with
6795 // the main part of booting and can enable the screen and hide boot messages.
6796 if (!mKeyguardDrawnOnce && mAwake) {
6797 mKeyguardDrawnOnce = true;
6798 enableScreen = true;
6799 if (mBootMessageNeedsHiding) {
6800 mBootMessageNeedsHiding = false;
6801 hideBootMessages();
6802 }
6803 } else {
6804 enableScreen = false;
6805 }
Jeff Brownc38c9be2012-10-04 13:16:19 -07006806 }
6807
Jeff Brown3ee549c2014-09-22 20:14:39 -07006808 if (listener != null) {
6809 listener.onScreenOn();
6810 }
Jeff Brown4fc45272012-10-10 18:28:14 -07006811
Jeff Brown3ee549c2014-09-22 20:14:39 -07006812 if (enableScreen) {
6813 try {
6814 mWindowManager.enableScreenIfNeeded();
6815 } catch (RemoteException unhandled) {
Jeff Brown36c4db82014-09-19 12:05:31 -07006816 }
Craig Mautnera631d492014-08-05 15:16:01 -07006817 }
6818 }
6819
6820 private void handleHideBootMessage() {
Jeff Brown3ee549c2014-09-22 20:14:39 -07006821 synchronized (mLock) {
6822 if (!mKeyguardDrawnOnce) {
6823 mBootMessageNeedsHiding = true;
6824 return; // keyguard hasn't drawn the first time yet, not done booting
6825 }
Craig Mautnera631d492014-08-05 15:16:01 -07006826 }
Jeff Brown3ee549c2014-09-22 20:14:39 -07006827
6828 if (mBootMsgDialog != null) {
6829 if (DEBUG_WAKEUP) Slog.d(TAG, "handleHideBootMessage: dismissing");
6830 mBootMsgDialog.dismiss();
6831 mBootMsgDialog = null;
Craig Mautnera631d492014-08-05 15:16:01 -07006832 }
Jeff Brownc38c9be2012-10-04 13:16:19 -07006833 }
6834
6835 @Override
Jeff Brown3ee549c2014-09-22 20:14:39 -07006836 public boolean isScreenOn() {
Jorim Jaggi67b29d52017-06-09 18:00:00 -07006837 synchronized (mLock) {
6838 return mScreenOnEarly;
6839 }
Dianne Hackborn08743722009-12-21 12:16:51 -08006840 }
Jeff Brownc38c9be2012-10-04 13:16:19 -07006841
Adrian Roose94c15c2017-05-09 13:17:54 -07006842 @Override
Adrian Roos7c894802017-07-19 12:25:34 +02006843 public boolean okToAnimate() {
6844 return mAwake && !mGoingToSleep;
Adrian Roose94c15c2017-05-09 13:17:54 -07006845 }
6846
Dianne Hackborn08743722009-12-21 12:16:51 -08006847 /** {@inheritDoc} */
Jose Lima9546b202014-07-02 17:21:51 -07006848 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006849 public void enableKeyguard(boolean enabled) {
Jim Miller5ecd8112013-01-09 18:50:26 -08006850 if (mKeyguardDelegate != null) {
6851 mKeyguardDelegate.setKeyguardEnabled(enabled);
Mike Lockwood3a74bd32011-08-12 13:55:22 -07006852 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006853 }
6854
6855 /** {@inheritDoc} */
Jose Lima9546b202014-07-02 17:21:51 -07006856 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006857 public void exitKeyguardSecurely(OnKeyguardExitResult callback) {
Jim Miller5ecd8112013-01-09 18:50:26 -08006858 if (mKeyguardDelegate != null) {
6859 mKeyguardDelegate.verifyUnlock(callback);
Mike Lockwood3a74bd32011-08-12 13:55:22 -07006860 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006861 }
6862
Tony Mak2c0d6dc2016-04-29 16:16:54 +01006863 @Override
6864 public boolean isKeyguardShowingAndNotOccluded() {
Jim Miller5ecd8112013-01-09 18:50:26 -08006865 if (mKeyguardDelegate == null) return false;
Jim Millerab954542014-10-10 18:21:49 -07006866 return mKeyguardDelegate.isShowing() && !mKeyguardOccluded;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006867 }
6868
Jorim Jaggife762342016-10-13 14:33:27 +02006869 @Override
6870 public boolean isKeyguardTrustedLw() {
6871 if (mKeyguardDelegate == null) return false;
6872 return mKeyguardDelegate.isTrusted();
6873 }
6874
Mike Lockwood520d8bc2011-02-18 13:23:13 -05006875 /** {@inheritDoc} */
Jose Lima9546b202014-07-02 17:21:51 -07006876 @Override
Mike Lockwood520d8bc2011-02-18 13:23:13 -05006877 public boolean isKeyguardLocked() {
6878 return keyguardOn();
6879 }
6880
6881 /** {@inheritDoc} */
Jose Lima9546b202014-07-02 17:21:51 -07006882 @Override
Jim Millere4044bb2016-05-10 18:38:25 -07006883 public boolean isKeyguardSecure(int userId) {
Jim Miller5ecd8112013-01-09 18:50:26 -08006884 if (mKeyguardDelegate == null) return false;
Jim Millere4044bb2016-05-10 18:38:25 -07006885 return mKeyguardDelegate.isSecure(userId);
Mike Lockwood520d8bc2011-02-18 13:23:13 -05006886 }
6887
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006888 /** {@inheritDoc} */
Jose Lima9546b202014-07-02 17:21:51 -07006889 @Override
Jorim Jaggife762342016-10-13 14:33:27 +02006890 public boolean isKeyguardOccluded() {
6891 if (mKeyguardDelegate == null) return false;
6892 return mKeyguardOccluded;
Adrian Roos461829d2015-06-03 14:41:18 -07006893 }
6894
6895 /** {@inheritDoc} */
6896 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006897 public boolean inKeyguardRestrictedKeyInputMode() {
Jim Miller5ecd8112013-01-09 18:50:26 -08006898 if (mKeyguardDelegate == null) return false;
6899 return mKeyguardDelegate.isInputRestricted();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006900 }
6901
Jose Lima9546b202014-07-02 17:21:51 -07006902 @Override
Jorim Jaggi241ae102016-11-02 21:57:33 -07006903 public void dismissKeyguardLw(IKeyguardDismissCallback callback) {
RoboErik8a2cfc32014-05-16 11:19:38 -07006904 if (mKeyguardDelegate != null && mKeyguardDelegate.isShowing()) {
Craig Mautnerc0d2d0a2014-10-31 16:25:15 -07006905 if (DEBUG_KEYGUARD) Slog.d(TAG, "PWM.dismissKeyguardLw");
Jorim Jaggi8d786932016-10-26 19:08:36 -07006906
6907 // ask the keyguard to prompt the user to authenticate if necessary
Jorim Jaggi241ae102016-11-02 21:57:33 -07006908 mKeyguardDelegate.dismiss(callback);
6909 } else if (callback != null) {
6910 try {
6911 callback.onDismissError();
6912 } catch (RemoteException e) {
6913 Slog.w(TAG, "Failed to call callback", e);
6914 }
Dianne Hackborn90c52de2011-09-23 12:57:44 -07006915 }
6916 }
6917
Jorim Jaggicff0acb2014-03-31 16:35:15 +02006918 @Override
6919 public boolean isKeyguardDrawnLw() {
6920 synchronized (mLock) {
Jeff Brown3ee549c2014-09-22 20:14:39 -07006921 return mKeyguardDrawnOnce;
Jorim Jaggicff0acb2014-03-31 16:35:15 +02006922 }
6923 }
6924
Jorim Jaggi0d674622014-05-21 01:34:15 +02006925 @Override
Jorim Jaggi77e10432016-10-26 17:43:56 -07006926 public boolean isShowingDreamLw() {
6927 return mShowingDream;
6928 }
6929
6930 @Override
Jorim Jaggie29b2db2014-05-30 23:17:03 +02006931 public void startKeyguardExitAnimation(long startTime, long fadeoutDuration) {
Jorim Jaggi0d674622014-05-21 01:34:15 +02006932 if (mKeyguardDelegate != null) {
Craig Mautnerc0d2d0a2014-10-31 16:25:15 -07006933 if (DEBUG_KEYGUARD) Slog.d(TAG, "PWM.startKeyguardExitAnimation");
Jorim Jaggie29b2db2014-05-30 23:17:03 +02006934 mKeyguardDelegate.startKeyguardExitAnimation(startTime, fadeoutDuration);
Jorim Jaggi0d674622014-05-21 01:34:15 +02006935 }
6936 }
6937
Jorim Jaggi737af722015-12-31 10:42:27 +01006938 @Override
6939 public void getStableInsetsLw(int displayRotation, int displayWidth, int displayHeight,
6940 Rect outInsets) {
6941 outInsets.setEmpty();
Jorim Jaggi82c9dc92016-02-05 15:10:33 -08006942
6943 // Navigation bar and status bar.
6944 getNonDecorInsetsLw(displayRotation, displayWidth, displayHeight, outInsets);
Matthew Ngca4c1a32016-12-13 16:55:09 -08006945 outInsets.top = mStatusBarHeight;
Jorim Jaggi82c9dc92016-02-05 15:10:33 -08006946 }
6947
6948 @Override
6949 public void getNonDecorInsetsLw(int displayRotation, int displayWidth, int displayHeight,
6950 Rect outInsets) {
6951 outInsets.setEmpty();
6952
6953 // Only navigation bar
Matthew Ngca4c1a32016-12-13 16:55:09 -08006954 if (mHasNavigationBar) {
Adrian Roos85d202b2016-06-02 16:27:47 -07006955 int position = navigationBarPosition(displayWidth, displayHeight, displayRotation);
6956 if (position == NAV_BAR_BOTTOM) {
Jorim Jaggi737af722015-12-31 10:42:27 +01006957 outInsets.bottom = getNavigationBarHeight(displayRotation, mUiMode);
Adrian Roos85d202b2016-06-02 16:27:47 -07006958 } else if (position == NAV_BAR_RIGHT) {
Jorim Jaggi737af722015-12-31 10:42:27 +01006959 outInsets.right = getNavigationBarWidth(displayRotation, mUiMode);
Adrian Roos85d202b2016-06-02 16:27:47 -07006960 } else if (position == NAV_BAR_LEFT) {
6961 outInsets.left = getNavigationBarWidth(displayRotation, mUiMode);
Jorim Jaggi737af722015-12-31 10:42:27 +01006962 }
6963 }
6964 }
6965
Jorim Jaggi5060bd82016-02-19 17:12:19 -08006966 @Override
Jorim Jaggi0ffd49c2016-02-12 15:04:21 -08006967 public boolean isNavBarForcedShownLw(WindowState windowState) {
Jorim Jaggie5638a62016-03-25 22:57:01 -07006968 return mForceShowSystemBars;
Jorim Jaggi0ffd49c2016-02-12 15:04:21 -08006969 }
6970
6971 @Override
Andrii Kulian3a1619d2017-07-07 14:38:09 -07006972 public int getNavBarPosition() {
6973 // TODO(multi-display): Support system decor on secondary displays.
6974 return mNavigationBarPosition;
6975 }
6976
6977 @Override
Jorim Jaggi5060bd82016-02-19 17:12:19 -08006978 public boolean isDockSideAllowed(int dockSide) {
6979
6980 // We do not allow all dock sides at which the navigation bar touches the docked stack.
6981 if (!mNavigationBarCanMove) {
6982 return dockSide == DOCKED_TOP || dockSide == DOCKED_LEFT || dockSide == DOCKED_RIGHT;
6983 } else {
6984 return dockSide == DOCKED_TOP || dockSide == DOCKED_LEFT;
6985 }
6986 }
6987
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006988 void sendCloseSystemWindows() {
Jorim Jaggib10e33f2015-02-04 21:57:40 +01006989 PhoneWindow.sendCloseSystemWindows(mContext, null);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006990 }
6991
6992 void sendCloseSystemWindows(String reason) {
Jorim Jaggib10e33f2015-02-04 21:57:40 +01006993 PhoneWindow.sendCloseSystemWindows(mContext, reason);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006994 }
Mitsuru Oshima831d0d92009-06-16 18:27:18 -07006995
Jeff Brown01a98dd2011-09-20 15:08:29 -07006996 @Override
6997 public int rotationForOrientationLw(int orientation, int lastRotation) {
Daniel Sandler2ed6ad62011-02-22 14:54:17 -05006998 if (false) {
6999 Slog.v(TAG, "rotationForOrientationLw(orient="
7000 + orientation + ", last=" + lastRotation
7001 + "); user=" + mUserRotation + " "
7002 + ((mUserRotationMode == WindowManagerPolicy.USER_ROTATION_LOCKED)
7003 ? "USER_ROTATION_LOCKED" : "")
7004 );
7005 }
7006
Craig Mautner46ac6fa2013-08-01 10:06:34 -07007007 if (mForceDefaultOrientation) {
7008 return Surface.ROTATION_0;
7009 }
7010
The Android Open Source Project0727d222009-03-11 12:11:58 -07007011 synchronized (mLock) {
Jeff Brownc0347aa2011-09-23 17:26:09 -07007012 int sensorRotation = mOrientationListener.getProposedRotation(); // may be -1
7013 if (sensorRotation < 0) {
Jeff Brown0f862b42012-09-27 21:11:01 -07007014 sensorRotation = lastRotation;
Jeff Brownc0347aa2011-09-23 17:26:09 -07007015 }
Jeff Brown01a98dd2011-09-20 15:08:29 -07007016
Jeff Browndec6cf42011-11-15 14:08:20 -08007017 final int preferredRotation;
Jeff Brown2e7760e2012-04-11 15:14:55 -07007018 if (mLidState == LID_OPEN && mLidOpenRotation >= 0) {
Jeff Brown01a98dd2011-09-20 15:08:29 -07007019 // Ignore sensor when lid switch is open and rotation is forced.
7020 preferredRotation = mLidOpenRotation;
7021 } else if (mDockMode == Intent.EXTRA_DOCK_STATE_CAR
Jeff Brownc0347aa2011-09-23 17:26:09 -07007022 && (mCarDockEnablesAccelerometer || mCarDockRotation >= 0)) {
Jeff Brown01a98dd2011-09-20 15:08:29 -07007023 // Ignore sensor when in car dock unless explicitly enabled.
7024 // This case can override the behavior of NOSENSOR, and can also
7025 // enable 180 degree rotation while docked.
Jeff Brownc0347aa2011-09-23 17:26:09 -07007026 preferredRotation = mCarDockEnablesAccelerometer
Jeff Brown01a98dd2011-09-20 15:08:29 -07007027 ? sensorRotation : mCarDockRotation;
Jeff Brown1a693182011-11-08 14:44:16 -08007028 } else if ((mDockMode == Intent.EXTRA_DOCK_STATE_DESK
7029 || mDockMode == Intent.EXTRA_DOCK_STATE_LE_DESK
7030 || mDockMode == Intent.EXTRA_DOCK_STATE_HE_DESK)
Jeff Brownc0347aa2011-09-23 17:26:09 -07007031 && (mDeskDockEnablesAccelerometer || mDeskDockRotation >= 0)) {
Jeff Brown01a98dd2011-09-20 15:08:29 -07007032 // Ignore sensor when in desk dock unless explicitly enabled.
7033 // This case can override the behavior of NOSENSOR, and can also
7034 // enable 180 degree rotation while docked.
Jeff Brownc0347aa2011-09-23 17:26:09 -07007035 preferredRotation = mDeskDockEnablesAccelerometer
Jeff Brown01a98dd2011-09-20 15:08:29 -07007036 ? sensorRotation : mDeskDockRotation;
Jeff Brownc82c89ed2013-04-17 17:18:15 -07007037 } else if (mHdmiPlugged && mDemoHdmiRotationLock) {
7038 // Ignore sensor when plugged into HDMI when demo HDMI rotation lock enabled.
Jeff Browneb3e4b92011-12-06 19:54:24 -08007039 // Note that the dock orientation overrides the HDMI orientation.
Jeff Brownc82c89ed2013-04-17 17:18:15 -07007040 preferredRotation = mDemoHdmiRotation;
7041 } else if (mHdmiPlugged && mDockMode == Intent.EXTRA_DOCK_STATE_UNDOCKED
7042 && mUndockedHdmiRotation >= 0) {
7043 // Ignore sensor when plugged into HDMI and an undocked orientation has
7044 // been specified in the configuration (only for legacy devices without
7045 // full multi-display support).
7046 // Note that the dock orientation overrides the HDMI orientation.
7047 preferredRotation = mUndockedHdmiRotation;
Chong Zhangae6119ff2014-11-11 18:54:39 -08007048 } else if (mDemoRotationLock) {
7049 // Ignore sensor when demo rotation lock is enabled.
7050 // Note that the dock orientation and HDMI rotation lock override this.
7051 preferredRotation = mDemoRotation;
Santos Cordon0b5d9692017-07-21 12:08:53 -07007052 } else if (mPersistentVrModeEnabled) {
7053 // While in VR, apps always prefer a portrait rotation. This does not change
7054 // any apps that explicitly set landscape, but does cause sensors be ignored,
7055 // and ignored any orientation lock that the user has set (this conditional
7056 // should remain above the ORIENTATION_LOCKED conditional below).
7057 preferredRotation = mPortraitRotation;
Dianne Hackbornb9ec1ac2013-04-10 17:34:25 -07007058 } else if (orientation == ActivityInfo.SCREEN_ORIENTATION_LOCKED) {
7059 // Application just wants to remain locked in the last rotation.
7060 preferredRotation = lastRotation;
Jeff Brownbcdfc622014-03-06 19:13:04 -08007061 } else if (!mSupportAutoRotation) {
7062 // If we don't support auto-rotation then bail out here and ignore
7063 // the sensor and any rotation lock settings.
7064 preferredRotation = -1;
Jeff Brown207673cd2012-06-05 17:47:11 -07007065 } else if ((mUserRotationMode == WindowManagerPolicy.USER_ROTATION_FREE
Jeff Brown01a98dd2011-09-20 15:08:29 -07007066 && (orientation == ActivityInfo.SCREEN_ORIENTATION_USER
Dianne Hackbornb9ec1ac2013-04-10 17:34:25 -07007067 || orientation == ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED
7068 || orientation == ActivityInfo.SCREEN_ORIENTATION_USER_LANDSCAPE
7069 || orientation == ActivityInfo.SCREEN_ORIENTATION_USER_PORTRAIT
7070 || orientation == ActivityInfo.SCREEN_ORIENTATION_FULL_USER))
Jeff Brown01a98dd2011-09-20 15:08:29 -07007071 || orientation == ActivityInfo.SCREEN_ORIENTATION_SENSOR
7072 || orientation == ActivityInfo.SCREEN_ORIENTATION_FULL_SENSOR
7073 || orientation == ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE
7074 || orientation == ActivityInfo.SCREEN_ORIENTATION_SENSOR_PORTRAIT) {
7075 // Otherwise, use sensor only if requested by the application or enabled
7076 // by default for USER or UNSPECIFIED modes. Does not apply to NOSENSOR.
Jeff Brownd3187e32011-09-21 19:26:44 -07007077 if (mAllowAllRotations < 0) {
7078 // Can't read this during init() because the context doesn't
7079 // have display metrics at that time so we cannot determine
7080 // tablet vs. phone then.
7081 mAllowAllRotations = mContext.getResources().getBoolean(
7082 com.android.internal.R.bool.config_allowAllRotations) ? 1 : 0;
7083 }
Jeff Brown01a98dd2011-09-20 15:08:29 -07007084 if (sensorRotation != Surface.ROTATION_180
Jeff Brownd3187e32011-09-21 19:26:44 -07007085 || mAllowAllRotations == 1
Dianne Hackbornb9ec1ac2013-04-10 17:34:25 -07007086 || orientation == ActivityInfo.SCREEN_ORIENTATION_FULL_SENSOR
7087 || orientation == ActivityInfo.SCREEN_ORIENTATION_FULL_USER) {
Santos Cordon0b5d9692017-07-21 12:08:53 -07007088 preferredRotation = sensorRotation;
Jeff Brown01a98dd2011-09-20 15:08:29 -07007089 } else {
7090 preferredRotation = lastRotation;
7091 }
Jeff Brown207673cd2012-06-05 17:47:11 -07007092 } else if (mUserRotationMode == WindowManagerPolicy.USER_ROTATION_LOCKED
7093 && orientation != ActivityInfo.SCREEN_ORIENTATION_NOSENSOR) {
7094 // Apply rotation lock. Does not apply to NOSENSOR.
7095 // The idea is that the user rotation expresses a weak preference for the direction
7096 // of gravity and as NOSENSOR is never affected by gravity, then neither should
7097 // NOSENSOR be affected by rotation lock (although it will be affected by docks).
Jeff Brown4dfce202011-10-05 12:00:10 -07007098 preferredRotation = mUserRotation;
Jeff Browndec6cf42011-11-15 14:08:20 -08007099 } else {
7100 // No overriding preference.
7101 // We will do exactly what the application asked us to do.
7102 preferredRotation = -1;
Jeff Brown01a98dd2011-09-20 15:08:29 -07007103 }
7104
Dianne Hackborne5439f22010-10-02 16:53:50 -07007105 switch (orientation) {
7106 case ActivityInfo.SCREEN_ORIENTATION_PORTRAIT:
Jeff Browndec6cf42011-11-15 14:08:20 -08007107 // Return portrait unless overridden.
7108 if (isAnyPortrait(preferredRotation)) {
7109 return preferredRotation;
7110 }
Dianne Hackborne5439f22010-10-02 16:53:50 -07007111 return mPortraitRotation;
Dianne Hackborne5439f22010-10-02 16:53:50 -07007112
Jeff Brown01a98dd2011-09-20 15:08:29 -07007113 case ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE:
Jeff Browndec6cf42011-11-15 14:08:20 -08007114 // Return landscape unless overridden.
7115 if (isLandscapeOrSeascape(preferredRotation)) {
7116 return preferredRotation;
7117 }
Jeff Brown01a98dd2011-09-20 15:08:29 -07007118 return mLandscapeRotation;
7119
7120 case ActivityInfo.SCREEN_ORIENTATION_REVERSE_PORTRAIT:
Jeff Browndec6cf42011-11-15 14:08:20 -08007121 // Return reverse portrait unless overridden.
7122 if (isAnyPortrait(preferredRotation)) {
7123 return preferredRotation;
7124 }
Jeff Brown01a98dd2011-09-20 15:08:29 -07007125 return mUpsideDownRotation;
7126
7127 case ActivityInfo.SCREEN_ORIENTATION_REVERSE_LANDSCAPE:
Jeff Browndec6cf42011-11-15 14:08:20 -08007128 // Return seascape unless overridden.
7129 if (isLandscapeOrSeascape(preferredRotation)) {
7130 return preferredRotation;
7131 }
Jeff Brown01a98dd2011-09-20 15:08:29 -07007132 return mSeascapeRotation;
7133
7134 case ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE:
Dianne Hackbornb9ec1ac2013-04-10 17:34:25 -07007135 case ActivityInfo.SCREEN_ORIENTATION_USER_LANDSCAPE:
Jeff Brown01a98dd2011-09-20 15:08:29 -07007136 // Return either landscape rotation.
7137 if (isLandscapeOrSeascape(preferredRotation)) {
7138 return preferredRotation;
7139 }
7140 if (isLandscapeOrSeascape(lastRotation)) {
Jeff Brown4519f072011-01-23 13:16:01 -08007141 return lastRotation;
7142 }
Jeff Brown01a98dd2011-09-20 15:08:29 -07007143 return mLandscapeRotation;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08007144
Jeff Brown01a98dd2011-09-20 15:08:29 -07007145 case ActivityInfo.SCREEN_ORIENTATION_SENSOR_PORTRAIT:
Dianne Hackbornb9ec1ac2013-04-10 17:34:25 -07007146 case ActivityInfo.SCREEN_ORIENTATION_USER_PORTRAIT:
Jeff Brown01a98dd2011-09-20 15:08:29 -07007147 // Return either portrait rotation.
7148 if (isAnyPortrait(preferredRotation)) {
7149 return preferredRotation;
7150 }
7151 if (isAnyPortrait(lastRotation)) {
7152 return lastRotation;
7153 }
7154 return mPortraitRotation;
7155
7156 default:
Jeff Brown4dfce202011-10-05 12:00:10 -07007157 // For USER, UNSPECIFIED, NOSENSOR, SENSOR and FULL_SENSOR,
7158 // just return the preferred orientation we already calculated.
Jeff Brown01a98dd2011-09-20 15:08:29 -07007159 if (preferredRotation >= 0) {
7160 return preferredRotation;
7161 }
Dianne Hackborndacea8c2011-04-21 17:26:39 -07007162 return Surface.ROTATION_0;
Daniel Sandlere7e5ac22011-02-22 16:10:21 -05007163 }
7164 }
Steve Howarda7bfe6a2010-09-23 16:47:49 -07007165 }
7166
Jeff Brown01a98dd2011-09-20 15:08:29 -07007167 @Override
7168 public boolean rotationHasCompatibleMetricsLw(int orientation, int rotation) {
7169 switch (orientation) {
7170 case ActivityInfo.SCREEN_ORIENTATION_PORTRAIT:
7171 case ActivityInfo.SCREEN_ORIENTATION_REVERSE_PORTRAIT:
7172 case ActivityInfo.SCREEN_ORIENTATION_SENSOR_PORTRAIT:
7173 return isAnyPortrait(rotation);
7174
7175 case ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE:
7176 case ActivityInfo.SCREEN_ORIENTATION_REVERSE_LANDSCAPE:
7177 case ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE:
7178 return isLandscapeOrSeascape(rotation);
7179
7180 default:
7181 return true;
7182 }
Steve Howarda7bfe6a2010-09-23 16:47:49 -07007183 }
7184
Jeff Brownc0347aa2011-09-23 17:26:09 -07007185 @Override
7186 public void setRotationLw(int rotation) {
7187 mOrientationListener.setCurrentRotation(rotation);
7188 }
7189
Jeff Brown01a98dd2011-09-20 15:08:29 -07007190 private boolean isLandscapeOrSeascape(int rotation) {
7191 return rotation == mLandscapeRotation || rotation == mSeascapeRotation;
Dianne Hackborne5439f22010-10-02 16:53:50 -07007192 }
7193
Jeff Brown01a98dd2011-09-20 15:08:29 -07007194 private boolean isAnyPortrait(int rotation) {
7195 return rotation == mPortraitRotation || rotation == mUpsideDownRotation;
Dianne Hackborne5439f22010-10-02 16:53:50 -07007196 }
7197
Jose Lima9546b202014-07-02 17:21:51 -07007198 @Override
Svetoslav Ganov80943d82013-01-02 10:25:37 -08007199 public int getUserRotationMode() {
7200 return Settings.System.getIntForUser(mContext.getContentResolver(),
Brett Chabot7e55c402013-05-16 19:38:08 -07007201 Settings.System.ACCELEROMETER_ROTATION, 0, UserHandle.USER_CURRENT) != 0 ?
7202 WindowManagerPolicy.USER_ROTATION_FREE :
7203 WindowManagerPolicy.USER_ROTATION_LOCKED;
Svetoslav Ganov80943d82013-01-02 10:25:37 -08007204 }
Daniel Sandlerb73617d2010-08-17 00:41:00 -04007205
7206 // User rotation: to be used when all else fails in assigning an orientation to the device
Jose Lima9546b202014-07-02 17:21:51 -07007207 @Override
Daniel Sandlerb73617d2010-08-17 00:41:00 -04007208 public void setUserRotationMode(int mode, int rot) {
7209 ContentResolver res = mContext.getContentResolver();
Daniel Sandler2ed6ad62011-02-22 14:54:17 -05007210
7211 // mUserRotationMode and mUserRotation will be assigned by the content observer
Daniel Sandlerb73617d2010-08-17 00:41:00 -04007212 if (mode == WindowManagerPolicy.USER_ROTATION_LOCKED) {
Christopher Tate5e08af02012-09-21 17:17:22 -07007213 Settings.System.putIntForUser(res,
Daniel Sandlerb73617d2010-08-17 00:41:00 -04007214 Settings.System.USER_ROTATION,
Christopher Tate5e08af02012-09-21 17:17:22 -07007215 rot,
7216 UserHandle.USER_CURRENT);
7217 Settings.System.putIntForUser(res,
Daniel Sandler2ed6ad62011-02-22 14:54:17 -05007218 Settings.System.ACCELEROMETER_ROTATION,
Christopher Tate5e08af02012-09-21 17:17:22 -07007219 0,
7220 UserHandle.USER_CURRENT);
Daniel Sandlerb73617d2010-08-17 00:41:00 -04007221 } else {
Christopher Tate5e08af02012-09-21 17:17:22 -07007222 Settings.System.putIntForUser(res,
Daniel Sandlerb73617d2010-08-17 00:41:00 -04007223 Settings.System.ACCELEROMETER_ROTATION,
Christopher Tate5e08af02012-09-21 17:17:22 -07007224 1,
7225 UserHandle.USER_CURRENT);
Daniel Sandlerb73617d2010-08-17 00:41:00 -04007226 }
7227 }
7228
Jose Lima9546b202014-07-02 17:21:51 -07007229 @Override
Jeff Brownac143512012-04-05 18:57:33 -07007230 public void setSafeMode(boolean safeMode) {
7231 mSafeMode = safeMode;
Michael Wright33d6c082017-07-21 16:40:58 +01007232 if (safeMode) {
7233 performHapticFeedbackLw(null, HapticFeedbackConstants.SAFE_MODE_ENABLED, true);
7234 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08007235 }
Craig Mautnereda67292013-04-28 13:50:14 -07007236
Dianne Hackborn181ceb52009-08-27 22:16:40 -07007237 static long[] getLongIntArray(Resources r, int resid) {
7238 int[] ar = r.getIntArray(resid);
7239 if (ar == null) {
7240 return null;
7241 }
7242 long[] out = new long[ar.length];
7243 for (int i=0; i<ar.length; i++) {
7244 out[i] = ar[i];
7245 }
7246 return out;
7247 }
Craig Mautnereda67292013-04-28 13:50:14 -07007248
Keun-young Park4136d2d2017-05-08 14:51:59 -07007249 private void bindKeyguard() {
7250 synchronized (mLock) {
7251 if (mKeyguardBound) {
7252 return;
7253 }
7254 mKeyguardBound = true;
7255 }
7256 mKeyguardDelegate.bindService(mContext);
7257 }
7258
7259 @Override
7260 public void onSystemUiStarted() {
7261 bindKeyguard();
7262 }
7263
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08007264 /** {@inheritDoc} */
Craig Mautnereda67292013-04-28 13:50:14 -07007265 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08007266 public void systemReady() {
Keun-young Park4136d2d2017-05-08 14:51:59 -07007267 // In normal flow, systemReady is called before other system services are ready.
7268 // So it is better not to bind keyguard here.
Mike Lockwooded8902d2013-11-15 11:01:47 -08007269 mKeyguardDelegate.onSystemReady();
7270
Zak Cohen732aeb02017-01-29 14:19:52 -08007271 mVrManagerInternal = LocalServices.getService(VrManagerInternal.class);
Santos Cordonc09d89c2017-04-13 16:12:02 -07007272 if (mVrManagerInternal != null) {
7273 mVrManagerInternal.addPersistentVrModeStateListener(mPersistentVrModeListener);
7274 }
Zak Cohen732aeb02017-01-29 14:19:52 -08007275
Michael Wright3818c922014-09-02 13:59:07 -07007276 readCameraLensCoverState();
Jeff Brown4f5fa282014-06-12 19:19:15 -07007277 updateUiMode();
Dianne Hackbornb1a79802009-09-29 15:18:31 -07007278 synchronized (mLock) {
7279 updateOrientationListenerLp();
Dianne Hackbornc777e072010-02-12 13:07:59 -08007280 mSystemReady = true;
7281 mHandler.post(new Runnable() {
Craig Mautnereda67292013-04-28 13:50:14 -07007282 @Override
Dianne Hackbornc777e072010-02-12 13:07:59 -08007283 public void run() {
7284 updateSettings();
7285 }
7286 });
Keun-young Park4136d2d2017-05-08 14:51:59 -07007287 // If this happens, for whatever reason, systemReady came later than systemBooted.
7288 // And keyguard should be already bound from systemBooted
7289 if (mSystemBooted) {
7290 mKeyguardDelegate.onBootCompleted();
Adrian Roos3542f7d2015-07-13 15:57:53 -07007291 }
7292 }
7293
Michael Wrighta4d22d72015-09-16 23:19:26 +01007294 mSystemGestures.systemReady();
Amith Yamasani02a03812016-04-22 17:32:00 -07007295 mImmersiveModeConfirmation.systemReady();
Felipe Leme5f978802017-06-08 13:01:13 -07007296
7297 mAutofillManagerInternal = LocalServices.getService(AutofillManagerInternal.class);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08007298 }
Dianne Hackborn661cd522011-08-22 00:26:20 -07007299
Dianne Hackbornba24e4d2011-09-01 11:17:06 -07007300 /** {@inheritDoc} */
Jose Lima9546b202014-07-02 17:21:51 -07007301 @Override
Dianne Hackbornba24e4d2011-09-01 11:17:06 -07007302 public void systemBooted() {
Keun-young Park4136d2d2017-05-08 14:51:59 -07007303 bindKeyguard();
Dianne Hackbornba24e4d2011-09-01 11:17:06 -07007304 synchronized (mLock) {
7305 mSystemBooted = true;
Keun-young Park4136d2d2017-05-08 14:51:59 -07007306 if (mSystemReady) {
7307 mKeyguardDelegate.onBootCompleted();
7308 }
Dianne Hackbornba24e4d2011-09-01 11:17:06 -07007309 }
Jeff Brown416c49c2015-05-26 19:50:18 -07007310 startedWakingUp();
Jeff Brown36c4db82014-09-19 12:05:31 -07007311 screenTurningOn(null);
Jorim Jaggic0496072015-08-19 15:14:52 -07007312 screenTurnedOn();
Dianne Hackbornba24e4d2011-09-01 11:17:06 -07007313 }
7314
Keun-young Park4136d2d2017-05-08 14:51:59 -07007315 @Override
7316 public boolean canDismissBootAnimation() {
7317 synchronized (mLock) {
7318 return mKeyguardDrawComplete;
7319 }
7320 }
7321
Dianne Hackborn661cd522011-08-22 00:26:20 -07007322 ProgressDialog mBootMsgDialog = null;
7323
7324 /** {@inheritDoc} */
Jose Lima9546b202014-07-02 17:21:51 -07007325 @Override
Dianne Hackborn661cd522011-08-22 00:26:20 -07007326 public void showBootMessage(final CharSequence msg, final boolean always) {
7327 mHandler.post(new Runnable() {
7328 @Override public void run() {
7329 if (mBootMsgDialog == null) {
Craig Stout4c0cb8a2014-04-04 13:03:10 -07007330 int theme;
Dmitri Plotnikov82e6dfc2017-02-24 18:10:54 -08007331 if (mContext.getPackageManager().hasSystemFeature(FEATURE_LEANBACK)) {
Craig Stout4c0cb8a2014-04-04 13:03:10 -07007332 theme = com.android.internal.R.style.Theme_Leanback_Dialog_Alert;
7333 } else {
7334 theme = 0;
7335 }
Vinod Krishnanfa8fc412014-04-18 14:35:53 -07007336
7337 mBootMsgDialog = new ProgressDialog(mContext, theme) {
Dianne Hackborn295e3c22011-08-25 13:19:08 -07007338 // This dialog will consume all events coming in to
7339 // it, to avoid it trying to do things too early in boot.
7340 @Override public boolean dispatchKeyEvent(KeyEvent event) {
7341 return true;
7342 }
7343 @Override public boolean dispatchKeyShortcutEvent(KeyEvent event) {
7344 return true;
7345 }
7346 @Override public boolean dispatchTouchEvent(MotionEvent ev) {
7347 return true;
7348 }
7349 @Override public boolean dispatchTrackballEvent(MotionEvent ev) {
7350 return true;
7351 }
7352 @Override public boolean dispatchGenericMotionEvent(MotionEvent ev) {
7353 return true;
7354 }
7355 @Override public boolean dispatchPopulateAccessibilityEvent(
7356 AccessibilityEvent event) {
7357 return true;
7358 }
7359 };
Jeff Hao9f60c082014-10-28 18:51:07 -07007360 if (mContext.getPackageManager().isUpgrade()) {
7361 mBootMsgDialog.setTitle(R.string.android_upgrading_title);
7362 } else {
7363 mBootMsgDialog.setTitle(R.string.android_start_title);
7364 }
Dianne Hackborn661cd522011-08-22 00:26:20 -07007365 mBootMsgDialog.setProgressStyle(ProgressDialog.STYLE_SPINNER);
7366 mBootMsgDialog.setIndeterminate(true);
7367 mBootMsgDialog.getWindow().setType(
Dianne Hackborn29aae6f2011-08-18 18:30:09 -07007368 WindowManager.LayoutParams.TYPE_BOOT_PROGRESS);
Dianne Hackborn661cd522011-08-22 00:26:20 -07007369 mBootMsgDialog.getWindow().addFlags(
7370 WindowManager.LayoutParams.FLAG_DIM_BEHIND
7371 | WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN);
7372 mBootMsgDialog.getWindow().setDimAmount(1);
Dianne Hackbornd9efb952011-12-07 14:56:51 -08007373 WindowManager.LayoutParams lp = mBootMsgDialog.getWindow().getAttributes();
7374 lp.screenOrientation = ActivityInfo.SCREEN_ORIENTATION_NOSENSOR;
7375 mBootMsgDialog.getWindow().setAttributes(lp);
Dianne Hackborn661cd522011-08-22 00:26:20 -07007376 mBootMsgDialog.setCancelable(false);
7377 mBootMsgDialog.show();
7378 }
7379 mBootMsgDialog.setMessage(msg);
7380 }
7381 });
7382 }
7383
7384 /** {@inheritDoc} */
Jose Lima9546b202014-07-02 17:21:51 -07007385 @Override
Dianne Hackborn661cd522011-08-22 00:26:20 -07007386 public void hideBootMessages() {
Craig Mautnera631d492014-08-05 15:16:01 -07007387 mHandler.sendEmptyMessage(MSG_HIDE_BOOT_MESSAGE);
Dianne Hackborn661cd522011-08-22 00:26:20 -07007388 }
7389
Mike Lockwood28569302010-01-28 11:54:40 -05007390 /** {@inheritDoc} */
Jose Lima9546b202014-07-02 17:21:51 -07007391 @Override
Mike Lockwood28569302010-01-28 11:54:40 -05007392 public void userActivity() {
Dianne Hackborndf89e652011-10-06 22:35:11 -07007393 // ***************************************
7394 // NOTE NOTE NOTE NOTE NOTE NOTE NOTE NOTE
7395 // ***************************************
7396 // THIS IS CALLED FROM DEEP IN THE POWER MANAGER
7397 // WITH ITS LOCKS HELD.
7398 //
7399 // This code must be VERY careful about the locks
7400 // it acquires.
7401 // In fact, the current code acquires way too many,
7402 // and probably has lurking deadlocks.
7403
Mike Lockwood28569302010-01-28 11:54:40 -05007404 synchronized (mScreenLockTimeout) {
7405 if (mLockScreenTimerActive) {
7406 // reset the timer
7407 mHandler.removeCallbacks(mScreenLockTimeout);
7408 mHandler.postDelayed(mScreenLockTimeout, mLockScreenTimeout);
7409 }
7410 }
Daniel Sandler0601eb72011-04-13 01:01:32 -04007411 }
7412
Adam Cohenf7522022012-10-03 20:03:18 -07007413 class ScreenLockTimeout implements Runnable {
7414 Bundle options;
7415
7416 @Override
Mike Lockwood28569302010-01-28 11:54:40 -05007417 public void run() {
7418 synchronized (this) {
7419 if (localLOGV) Log.v(TAG, "mScreenLockTimeout activating keyguard");
Jim Miller5ecd8112013-01-09 18:50:26 -08007420 if (mKeyguardDelegate != null) {
7421 mKeyguardDelegate.doKeyguardTimeout(options);
Mike Lockwood3a74bd32011-08-12 13:55:22 -07007422 }
Mike Lockwood28569302010-01-28 11:54:40 -05007423 mLockScreenTimerActive = false;
Adam Cohenf7522022012-10-03 20:03:18 -07007424 options = null;
Mike Lockwood28569302010-01-28 11:54:40 -05007425 }
7426 }
Mike Lockwood28569302010-01-28 11:54:40 -05007427
Adam Cohenf7522022012-10-03 20:03:18 -07007428 public void setLockOptions(Bundle options) {
7429 this.options = options;
7430 }
7431 }
7432
7433 ScreenLockTimeout mScreenLockTimeout = new ScreenLockTimeout();
7434
Jose Lima9546b202014-07-02 17:21:51 -07007435 @Override
Adam Cohenf7522022012-10-03 20:03:18 -07007436 public void lockNow(Bundle options) {
Jim Miller93c518e2012-01-17 15:55:31 -08007437 mContext.enforceCallingOrSelfPermission(android.Manifest.permission.DEVICE_POWER, null);
7438 mHandler.removeCallbacks(mScreenLockTimeout);
Adam Cohenf7522022012-10-03 20:03:18 -07007439 if (options != null) {
7440 // In case multiple calls are made to lockNow, we don't wipe out the options
7441 // until the runnable actually executes.
7442 mScreenLockTimeout.setLockOptions(options);
7443 }
Jim Miller93c518e2012-01-17 15:55:31 -08007444 mHandler.post(mScreenLockTimeout);
7445 }
7446
Mike Lockwood28569302010-01-28 11:54:40 -05007447 private void updateLockScreenTimeout() {
7448 synchronized (mScreenLockTimeout) {
Jeff Brown3ee549c2014-09-22 20:14:39 -07007449 boolean enable = (mAllowLockscreenWhenOn && mAwake &&
Jim Millere4044bb2016-05-10 18:38:25 -07007450 mKeyguardDelegate != null && mKeyguardDelegate.isSecure(mCurrentUserId));
Mike Lockwood28569302010-01-28 11:54:40 -05007451 if (mLockScreenTimerActive != enable) {
7452 if (enable) {
7453 if (localLOGV) Log.v(TAG, "setting lockscreen timer");
Jim Miller2967f482016-01-07 15:05:32 -08007454 mHandler.removeCallbacks(mScreenLockTimeout); // remove any pending requests
Mike Lockwood28569302010-01-28 11:54:40 -05007455 mHandler.postDelayed(mScreenLockTimeout, mLockScreenTimeout);
7456 } else {
7457 if (localLOGV) Log.v(TAG, "clearing lockscreen timer");
7458 mHandler.removeCallbacks(mScreenLockTimeout);
7459 }
7460 mLockScreenTimerActive = enable;
7461 }
7462 }
7463 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08007464
Jeff Brown061ea992015-04-17 19:55:47 -07007465 private void updateDreamingSleepToken(boolean acquire) {
7466 if (acquire) {
7467 if (mDreamingSleepToken == null) {
7468 mDreamingSleepToken = mActivityManagerInternal.acquireSleepToken("Dream");
7469 }
7470 } else {
7471 if (mDreamingSleepToken != null) {
7472 mDreamingSleepToken.release();
Jeff Brown48d1b142015-06-10 16:36:03 -07007473 mDreamingSleepToken = null;
7474 }
7475 }
7476 }
7477
7478 private void updateScreenOffSleepToken(boolean acquire) {
7479 if (acquire) {
7480 if (mScreenOffSleepToken == null) {
7481 mScreenOffSleepToken = mActivityManagerInternal.acquireSleepToken("ScreenOff");
7482 }
7483 } else {
7484 if (mScreenOffSleepToken != null) {
7485 mScreenOffSleepToken.release();
7486 mScreenOffSleepToken = null;
Jeff Brown061ea992015-04-17 19:55:47 -07007487 }
7488 }
7489 }
7490
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08007491 /** {@inheritDoc} */
Craig Mautnereda67292013-04-28 13:50:14 -07007492 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08007493 public void enableScreenAfterBoot() {
7494 readLidState();
Jeff Brownc458ce92012-04-30 14:58:40 -07007495 applyLidSwitchState();
Jeff Brown01a98dd2011-09-20 15:08:29 -07007496 updateRotation(true);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08007497 }
Dianne Hackbornf54c8f92009-09-19 14:03:57 -07007498
Jeff Brownc458ce92012-04-30 14:58:40 -07007499 private void applyLidSwitchState() {
Jeff Brownc458ce92012-04-30 14:58:40 -07007500 if (mLidState == LID_CLOSED && mLidControlsSleep) {
Jeff Brown6d8fd272014-05-20 21:24:38 -07007501 mPowerManager.goToSleep(SystemClock.uptimeMillis(),
Jeff Brownc12035c2014-08-13 18:52:25 -07007502 PowerManager.GO_TO_SLEEP_REASON_LID_SWITCH,
Jeff Brown6d8fd272014-05-20 21:24:38 -07007503 PowerManager.GO_TO_SLEEP_FLAG_NO_DOZE);
Edward Savage-Jones7def60d2015-11-13 13:27:03 +01007504 } else if (mLidState == LID_CLOSED && mLidControlsScreenLock) {
7505 mWindowManagerFuncs.lockDeviceNow();
Jeff Brownc458ce92012-04-30 14:58:40 -07007506 }
Jeff Browna20dda42014-05-27 20:57:24 -07007507
7508 synchronized (mLock) {
7509 updateWakeGestureListenerLp();
7510 }
Jeff Brown01a98dd2011-09-20 15:08:29 -07007511 }
7512
Jeff Brown4f5fa282014-06-12 19:19:15 -07007513 void updateUiMode() {
7514 if (mUiModeManager == null) {
7515 mUiModeManager = IUiModeManager.Stub.asInterface(
7516 ServiceManager.getService(Context.UI_MODE_SERVICE));
7517 }
7518 try {
7519 mUiMode = mUiModeManager.getCurrentModeType();
7520 } catch (RemoteException e) {
7521 }
7522 }
7523
Jeff Brown01a98dd2011-09-20 15:08:29 -07007524 void updateRotation(boolean alwaysSendConfiguration) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08007525 try {
7526 //set orientation on WindowManager
Dianne Hackbornf87d1962012-04-04 12:48:24 -07007527 mWindowManager.updateRotation(alwaysSendConfiguration, false);
7528 } catch (RemoteException e) {
7529 // Ignore
7530 }
7531 }
7532
7533 void updateRotation(boolean alwaysSendConfiguration, boolean forceRelayout) {
7534 try {
7535 //set orientation on WindowManager
7536 mWindowManager.updateRotation(alwaysSendConfiguration, forceRelayout);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08007537 } catch (RemoteException e) {
7538 // Ignore
7539 }
7540 }
7541
Daniel Sandler6396c722013-04-16 20:19:09 -04007542 /**
7543 * Return an Intent to launch the currently active dock app as home. Returns
7544 * null if the standard home should be launched, which is the case if any of the following is
7545 * true:
7546 * <ul>
7547 * <li>The device is not in either car mode or desk mode
keunyounga7710492015-09-23 11:33:58 -07007548 * <li>The device is in car mode but mEnableCarDockHomeCapture is false
Daniel Sandler6396c722013-04-16 20:19:09 -04007549 * <li>The device is in desk mode but ENABLE_DESK_DOCK_HOME_CAPTURE is false
7550 * <li>The device is in car mode but there's no CAR_DOCK app with METADATA_DOCK_HOME
7551 * <li>The device is in desk mode but there's no DESK_DOCK app with METADATA_DOCK_HOME
7552 * </ul>
Craig Mautnereda67292013-04-28 13:50:14 -07007553 * @return A dock intent.
Daniel Sandler6396c722013-04-16 20:19:09 -04007554 */
7555 Intent createHomeDockIntent() {
7556 Intent intent = null;
7557
7558 // What home does is based on the mode, not the dock state. That
7559 // is, when in car mode you should be taken to car home regardless
7560 // of whether we are actually in a car dock.
7561 if (mUiMode == Configuration.UI_MODE_TYPE_CAR) {
keunyounga7710492015-09-23 11:33:58 -07007562 if (mEnableCarDockHomeCapture) {
Daniel Sandler6396c722013-04-16 20:19:09 -04007563 intent = mCarDockIntent;
7564 }
7565 } else if (mUiMode == Configuration.UI_MODE_TYPE_DESK) {
7566 if (ENABLE_DESK_DOCK_HOME_CAPTURE) {
7567 intent = mDeskDockIntent;
7568 }
Jeff Brown4f5fa282014-06-12 19:19:15 -07007569 } else if (mUiMode == Configuration.UI_MODE_TYPE_WATCH
7570 && (mDockMode == Intent.EXTRA_DOCK_STATE_DESK
7571 || mDockMode == Intent.EXTRA_DOCK_STATE_HE_DESK
7572 || mDockMode == Intent.EXTRA_DOCK_STATE_LE_DESK)) {
7573 // Always launch dock home from home when watch is docked, if it exists.
7574 intent = mDeskDockIntent;
Zak Cohendb6ca492017-01-26 14:09:00 -08007575 } else if (mUiMode == Configuration.UI_MODE_TYPE_VR_HEADSET) {
7576 if (ENABLE_VR_HEADSET_HOME_CAPTURE) {
7577 intent = mVrHeadsetHomeIntent;
7578 }
Daniel Sandler6396c722013-04-16 20:19:09 -04007579 }
7580
7581 if (intent == null) {
7582 return null;
7583 }
7584
7585 ActivityInfo ai = null;
7586 ResolveInfo info = mContext.getPackageManager().resolveActivityAsUser(
7587 intent,
John Spurlockf56bef12013-07-09 09:51:46 -04007588 PackageManager.MATCH_DEFAULT_ONLY | PackageManager.GET_META_DATA,
Craig Mautnerd625ab22013-09-06 13:40:31 -07007589 mCurrentUserId);
Daniel Sandler6396c722013-04-16 20:19:09 -04007590 if (info != null) {
7591 ai = info.activityInfo;
7592 }
7593 if (ai != null
7594 && ai.metaData != null
7595 && ai.metaData.getBoolean(Intent.METADATA_DOCK_HOME)) {
7596 intent = new Intent(intent);
7597 intent.setClassName(ai.packageName, ai.name);
7598 return intent;
7599 }
7600
7601 return null;
7602 }
7603
Filip Gruszczynskia483a1d2015-03-17 19:06:58 +00007604 void startDockOrHome(boolean fromHomeKey, boolean awakenFromDreams) {
7605 if (awakenFromDreams) {
7606 awakenDreams();
7607 }
Daniel Sandler6396c722013-04-16 20:19:09 -04007608
7609 Intent dock = createHomeDockIntent();
7610 if (dock != null) {
7611 try {
Bryce Lee01b0c5f2015-02-05 18:24:04 -08007612 if (fromHomeKey) {
7613 dock.putExtra(WindowManagerPolicy.EXTRA_FROM_HOME_KEY, fromHomeKey);
7614 }
Bart Sears8b1c27c2015-03-18 23:51:02 +00007615 startActivityAsUser(dock, UserHandle.CURRENT);
Daniel Sandler6396c722013-04-16 20:19:09 -04007616 return;
7617 } catch (ActivityNotFoundException e) {
7618 }
7619 }
7620
Bryce Lee01b0c5f2015-02-05 18:24:04 -08007621 Intent intent;
7622
7623 if (fromHomeKey) {
7624 intent = new Intent(mHomeIntent);
7625 intent.putExtra(WindowManagerPolicy.EXTRA_FROM_HOME_KEY, fromHomeKey);
7626 } else {
7627 intent = mHomeIntent;
7628 }
7629
Bryce Lee9fc0b6f2015-03-19 21:37:45 +00007630 startActivityAsUser(intent, UserHandle.CURRENT);
Dianne Hackborn39c2d712009-09-22 11:41:31 -07007631 }
Craig Mautnereda67292013-04-28 13:50:14 -07007632
Dianne Hackborn39c2d712009-09-22 11:41:31 -07007633 /**
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08007634 * goes to the home screen
7635 * @return whether it did anything
7636 */
7637 boolean goHome() {
Bart Sears8b1c27c2015-03-18 23:51:02 +00007638 if (!isUserSetupComplete()) {
7639 Slog.i(TAG, "Not going home because user setup is in progress.");
7640 return false;
7641 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08007642 if (false) {
7643 // This code always brings home to the front.
Dianne Hackborn256dd3b2009-05-19 18:51:21 -07007644 try {
Sudheer Shankadc589ac2016-11-10 15:30:17 -08007645 ActivityManager.getService().stopAppSwitches();
Dianne Hackborn256dd3b2009-05-19 18:51:21 -07007646 } catch (RemoteException e) {
7647 }
Dianne Hackborn94a679d2009-07-28 17:51:07 -07007648 sendCloseSystemWindows();
Filip Gruszczynskia483a1d2015-03-17 19:06:58 +00007649 startDockOrHome(false /*fromHomeKey*/, true /* awakenFromDreams */);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08007650 } else {
7651 // This code brings home to the front or, if it is already
7652 // at the front, puts the device to sleep.
7653 try {
Wink Savilled2e6a332010-02-12 12:12:06 -08007654 if (SystemProperties.getInt("persist.sys.uts-test-mode", 0) == 1) {
7655 /// Roll back EndcallBehavior as the cupcake design to pass P1 lab entry.
7656 Log.d(TAG, "UTS-TEST-MODE");
7657 } else {
Sudheer Shankadc589ac2016-11-10 15:30:17 -08007658 ActivityManager.getService().stopAppSwitches();
Wink Savilled2e6a332010-02-12 12:12:06 -08007659 sendCloseSystemWindows();
Daniel Sandler6396c722013-04-16 20:19:09 -04007660 Intent dock = createHomeDockIntent();
7661 if (dock != null) {
Sudheer Shankadc589ac2016-11-10 15:30:17 -08007662 int result = ActivityManager.getService()
Daniel Sandler6396c722013-04-16 20:19:09 -04007663 .startActivityAsUser(null, null, dock,
7664 dock.resolveTypeIfNeeded(mContext.getContentResolver()),
7665 null, null, 0,
7666 ActivityManager.START_FLAG_ONLY_IF_NEEDED,
Jeff Hao1b012d32014-08-20 10:35:34 -07007667 null, null, UserHandle.USER_CURRENT);
Daniel Sandler6396c722013-04-16 20:19:09 -04007668 if (result == ActivityManager.START_RETURN_INTENT_TO_CALLER) {
7669 return false;
7670 }
7671 }
Dianne Hackborn39c2d712009-09-22 11:41:31 -07007672 }
Sudheer Shankadc589ac2016-11-10 15:30:17 -08007673 int result = ActivityManager.getService()
Dianne Hackbornf265ea92013-01-31 15:00:51 -08007674 .startActivityAsUser(null, null, mHomeIntent,
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08007675 mHomeIntent.resolveTypeIfNeeded(mContext.getContentResolver()),
Dianne Hackborna4972e92012-03-14 10:38:05 -07007676 null, null, 0,
7677 ActivityManager.START_FLAG_ONLY_IF_NEEDED,
Jeff Hao1b012d32014-08-20 10:35:34 -07007678 null, null, UserHandle.USER_CURRENT);
Dianne Hackborna4972e92012-03-14 10:38:05 -07007679 if (result == ActivityManager.START_RETURN_INTENT_TO_CALLER) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08007680 return false;
7681 }
7682 } catch (RemoteException ex) {
7683 // bummer, the activity manager, which is in this process, is dead
7684 }
7685 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08007686 return true;
7687 }
Craig Mautnereda67292013-04-28 13:50:14 -07007688
7689 @Override
The Android Open Source Project0727d222009-03-11 12:11:58 -07007690 public void setCurrentOrientationLw(int newOrientation) {
7691 synchronized (mLock) {
7692 if (newOrientation != mCurrentAppOrientation) {
7693 mCurrentAppOrientation = newOrientation;
7694 updateOrientationListenerLp();
7695 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08007696 }
7697 }
Amith Yamasanic33cb712010-02-10 15:21:49 -08007698
Bryce Lee584a4452014-10-21 15:55:55 -07007699 private boolean isTheaterModeEnabled() {
7700 return Settings.Global.getInt(mContext.getContentResolver(),
7701 Settings.Global.THEATER_MODE_ON, 0) == 1;
7702 }
7703
Doris Ling628cea42016-06-09 10:35:02 -07007704 private boolean areSystemNavigationKeysEnabled() {
Doris Ling34331b72016-08-09 12:02:28 -07007705 return Settings.Secure.getIntForUser(mContext.getContentResolver(),
Kevin Chyn76096e72017-07-24 14:00:22 -07007706 Settings.Secure.SYSTEM_NAVIGATION_KEYS_ENABLED, 0, UserHandle.USER_CURRENT) == 1;
Doris Ling628cea42016-06-09 10:35:02 -07007707 }
7708
Craig Mautnereda67292013-04-28 13:50:14 -07007709 @Override
The Android Open Source Project0727d222009-03-11 12:11:58 -07007710 public boolean performHapticFeedbackLw(WindowState win, int effectId, boolean always) {
Svetoslav Ganov96179212012-10-10 14:17:45 -07007711 if (!mVibrator.hasVibrator()) {
7712 return false;
7713 }
Christopher Tate5e08af02012-09-21 17:17:22 -07007714 final boolean hapticsDisabled = Settings.System.getIntForUser(mContext.getContentResolver(),
7715 Settings.System.HAPTIC_FEEDBACK_ENABLED, 0, UserHandle.USER_CURRENT) == 0;
Jeff Brown82379ba2014-07-25 19:03:28 -07007716 if (hapticsDisabled && !always) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08007717 return false;
7718 }
Michael Wright71216972017-01-31 18:33:54 +00007719
7720 VibrationEffect effect = getVibrationEffect(effectId);
7721 if (effect == null) {
7722 return false;
7723 }
7724
7725 int owningUid;
7726 String owningPackage;
7727 if (win != null) {
7728 owningUid = win.getOwningUid();
7729 owningPackage = win.getOwningPackage();
7730 } else {
7731 owningUid = android.os.Process.myUid();
7732 owningPackage = mContext.getOpPackageName();
7733 }
7734 mVibrator.vibrate(owningUid, owningPackage, effect, VIBRATION_ATTRIBUTES);
7735 return true;
7736 }
7737
7738 private VibrationEffect getVibrationEffect(int effectId) {
7739 long[] pattern;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08007740 switch (effectId) {
Michael Wright71216972017-01-31 18:33:54 +00007741 case HapticFeedbackConstants.VIRTUAL_KEY:
7742 return VibrationEffect.get(VibrationEffect.EFFECT_CLICK);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08007743 case HapticFeedbackConstants.LONG_PRESS:
Amith Yamasanic33cb712010-02-10 15:21:49 -08007744 pattern = mLongPressVibePattern;
7745 break;
Amith Yamasanic33cb712010-02-10 15:21:49 -08007746 case HapticFeedbackConstants.KEYBOARD_TAP:
Michael Wright71216972017-01-31 18:33:54 +00007747 return VibrationEffect.get(VibrationEffect.EFFECT_CLICK);
Fabrice Di Meglioeeff63a2013-08-05 12:07:24 -07007748 case HapticFeedbackConstants.CLOCK_TICK:
Michael Wright57d94d92017-05-31 14:44:45 +01007749 return VibrationEffect.get(VibrationEffect.EFFECT_TICK);
Fabrice Di Megliobd9152f2013-10-01 11:21:31 -07007750 case HapticFeedbackConstants.CALENDAR_DATE:
7751 pattern = mCalendarDateVibePattern;
7752 break;
Dianne Hackbornb1a79802009-09-29 15:18:31 -07007753 case HapticFeedbackConstants.SAFE_MODE_ENABLED:
Amith Yamasanic33cb712010-02-10 15:21:49 -08007754 pattern = mSafeModeEnabledVibePattern;
7755 break;
Mady Mellore8608912015-06-05 09:02:55 -07007756 case HapticFeedbackConstants.CONTEXT_CLICK:
Michael Wright57d94d92017-05-31 14:44:45 +01007757 return VibrationEffect.get(VibrationEffect.EFFECT_TICK);
Michael Wrighte14b0642017-06-02 19:13:58 +01007758 case HapticFeedbackConstants.VIRTUAL_KEY_RELEASE:
7759 return VibrationEffect.get(VibrationEffect.EFFECT_TICK);
Yohei Yukawada5b4a32017-06-09 12:01:51 -07007760 case HapticFeedbackConstants.TEXT_HANDLE_MOVE:
7761 return VibrationEffect.get(VibrationEffect.EFFECT_TICK);
Amith Yamasanic33cb712010-02-10 15:21:49 -08007762 default:
Michael Wright71216972017-01-31 18:33:54 +00007763 return null;
Dianne Hackbornf265ea92013-01-31 15:00:51 -08007764 }
Erik Wolsheimer017939e2017-05-24 11:18:25 -07007765 if (pattern.length == 0) {
7766 // No vibration
7767 return null;
7768 } else if (pattern.length == 1) {
Amith Yamasanic33cb712010-02-10 15:21:49 -08007769 // One-shot vibration
Michael Wright71216972017-01-31 18:33:54 +00007770 return VibrationEffect.createOneShot(pattern[0], VibrationEffect.DEFAULT_AMPLITUDE);
Amith Yamasanic33cb712010-02-10 15:21:49 -08007771 } else {
7772 // Pattern vibration
Michael Wright71216972017-01-31 18:33:54 +00007773 return VibrationEffect.createWaveform(pattern, -1);
Amith Yamasanic33cb712010-02-10 15:21:49 -08007774 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08007775 }
Jeff Brownc38c9be2012-10-04 13:16:19 -07007776
7777 @Override
7778 public void keepScreenOnStartedLw() {
Daniel Sandler0601eb72011-04-13 01:01:32 -04007779 }
7780
Jeff Brownc38c9be2012-10-04 13:16:19 -07007781 @Override
7782 public void keepScreenOnStoppedLw() {
Jim Millerab954542014-10-10 18:21:49 -07007783 if (isKeyguardShowingAndNotOccluded()) {
Jim Miller25190572013-02-28 17:36:24 -08007784 mPowerManager.userActivity(SystemClock.uptimeMillis(), false);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08007785 }
7786 }
Mike Lockwoodfcb39242009-10-21 23:01:07 -04007787
Dianne Hackborndf89e652011-10-06 22:35:11 -07007788 private int updateSystemUiVisibilityLw() {
Joe Onorato664644d2011-01-23 17:53:23 -08007789 // If there is no window focused, there will be nobody to handle the events
7790 // anyway, so just hang on in whatever state we're in until things settle down.
Adrian Roosdab15162016-09-12 15:08:35 -07007791 WindowState winCandidate = mFocusedWindow != null ? mFocusedWindow
Adrian Roos53f28ec2014-10-29 17:26:12 +01007792 : mTopFullscreenOpaqueWindowState;
Adrian Roosdab15162016-09-12 15:08:35 -07007793 if (winCandidate == null) {
Dianne Hackborndf89e652011-10-06 22:35:11 -07007794 return 0;
7795 }
Adrian Roosdab15162016-09-12 15:08:35 -07007796 if (winCandidate.getAttrs().token == mImmersiveModeConfirmation.getWindowToken()) {
7797 // The immersive mode confirmation should never affect the system bar visibility,
7798 // otherwise it will unhide the navigation bar and hide itself.
7799 winCandidate = isStatusBarKeyguard() ? mStatusBar : mTopFullscreenOpaqueWindowState;
7800 if (winCandidate == null) {
7801 return 0;
7802 }
7803 }
7804 final WindowState win = winCandidate;
Jorim Jaggife762342016-10-13 14:33:27 +02007805 if ((win.getAttrs().privateFlags & PRIVATE_FLAG_KEYGUARD) != 0 && mKeyguardOccluded) {
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07007806 // We are updating at a point where the keyguard has gotten
7807 // focus, but we were last in a state where the top window is
7808 // hiding it. This is probably because the keyguard as been
7809 // shown while the top window was displayed, so we want to ignore
7810 // it here because this is just a very transient change and it
7811 // will quickly lose focus once it correctly gets hidden.
7812 return 0;
7813 }
John Spurlock32beb2c2013-03-11 10:16:47 -04007814
John Spurlock1db8b682014-02-18 11:18:59 -05007815 int tmpVisibility = PolicyControl.getSystemUiVisibility(win, null)
Dianne Hackborne26ab702011-10-16 13:21:33 -07007816 & ~mResettingSystemUiFlags
7817 & ~mForceClearedSystemUiFlags;
John Spurlock79da8332013-09-20 12:04:47 -04007818 if (mForcingShowNavBar && win.getSurfaceLayer() < mForcingShowNavBarLayer) {
John Spurlockc6d1c602014-01-17 15:22:06 -05007819 tmpVisibility &= ~PolicyControl.adjustClearableFlags(win, View.SYSTEM_UI_CLEARABLE_FLAGS);
Dianne Hackborn891d3fb2013-01-09 18:31:37 -08007820 }
Thanh Hai Mai6c009f52015-09-01 16:27:32 -07007821
Jorim Jaggi86905582016-02-09 21:36:09 -08007822 final int fullscreenVisibility = updateLightStatusBarLw(0 /* vis */,
7823 mTopFullscreenOpaqueWindowState, mTopFullscreenOpaqueOrDimmingWindowState);
7824 final int dockedVisibility = updateLightStatusBarLw(0 /* vis */,
7825 mTopDockedOpaqueWindowState, mTopDockedOpaqueOrDimmingWindowState);
7826 mWindowManagerFuncs.getStackBounds(HOME_STACK_ID, mNonDockedStackBounds);
7827 mWindowManagerFuncs.getStackBounds(DOCKED_STACK_ID, mDockedStackBounds);
John Spurlock79da8332013-09-20 12:04:47 -04007828 final int visibility = updateSystemBarsLw(win, mLastSystemUiFlags, tmpVisibility);
John Spurlockad3e6cb2013-04-30 08:47:43 -04007829 final int diff = visibility ^ mLastSystemUiFlags;
Jorim Jaggi86905582016-02-09 21:36:09 -08007830 final int fullscreenDiff = fullscreenVisibility ^ mLastFullscreenStackSysUiFlags;
7831 final int dockedDiff = dockedVisibility ^ mLastDockedStackSysUiFlags;
John Spurlock79da8332013-09-20 12:04:47 -04007832 final boolean needsMenu = win.getNeedsMenuLw(mTopFullscreenOpaqueWindowState);
Jorim Jaggi86905582016-02-09 21:36:09 -08007833 if (diff == 0 && fullscreenDiff == 0 && dockedDiff == 0 && mLastFocusNeedsMenu == needsMenu
7834 && mFocusedApp == win.getAppToken()
7835 && mLastNonDockedStackBounds.equals(mNonDockedStackBounds)
7836 && mLastDockedStackBounds.equals(mDockedStackBounds)) {
Dianne Hackborndf89e652011-10-06 22:35:11 -07007837 return 0;
7838 }
Dianne Hackborne26ab702011-10-16 13:21:33 -07007839 mLastSystemUiFlags = visibility;
Jorim Jaggi86905582016-02-09 21:36:09 -08007840 mLastFullscreenStackSysUiFlags = fullscreenVisibility;
7841 mLastDockedStackSysUiFlags = dockedVisibility;
Dianne Hackborn4eff8d32011-11-10 19:38:40 -08007842 mLastFocusNeedsMenu = needsMenu;
John Spurlock79da8332013-09-20 12:04:47 -04007843 mFocusedApp = win.getAppToken();
Jorim Jaggi86905582016-02-09 21:36:09 -08007844 final Rect fullscreenStackBounds = new Rect(mNonDockedStackBounds);
7845 final Rect dockedStackBounds = new Rect(mDockedStackBounds);
Dianne Hackborndf89e652011-10-06 22:35:11 -07007846 mHandler.post(new Runnable() {
Craig Mautnereda67292013-04-28 13:50:14 -07007847 @Override
Dianne Hackborndf89e652011-10-06 22:35:11 -07007848 public void run() {
Jorim Jaggi86905582016-02-09 21:36:09 -08007849 StatusBarManagerInternal statusbar = getStatusBarManagerInternal();
7850 if (statusbar != null) {
7851 statusbar.setSystemUiVisibility(visibility, fullscreenVisibility,
7852 dockedVisibility, 0xffffffff, fullscreenStackBounds,
7853 dockedStackBounds, win.toString());
7854 statusbar.topAppWindowChanged(needsMenu);
Joe Onorato664644d2011-01-23 17:53:23 -08007855 }
Dianne Hackborndf89e652011-10-06 22:35:11 -07007856 }
7857 });
7858 return diff;
Joe Onorato664644d2011-01-23 17:53:23 -08007859 }
7860
Jorim Jaggi86905582016-02-09 21:36:09 -08007861 private int updateLightStatusBarLw(int vis, WindowState opaque, WindowState opaqueOrDimming) {
Jorim Jaggiff46d4c2017-07-17 16:46:00 +02007862 final boolean onKeyguard = isStatusBarKeyguard() && !mKeyguardOccluded;
7863 final WindowState statusColorWin = onKeyguard ? mStatusBar : opaqueOrDimming;
7864 if (statusColorWin != null && (statusColorWin == opaque || onKeyguard)) {
7865 // If the top fullscreen-or-dimming window is also the top fullscreen, respect
7866 // its light flag.
7867 vis &= ~View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR;
7868 vis |= PolicyControl.getSystemUiVisibility(statusColorWin, null)
7869 & View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR;
7870 } else if (statusColorWin != null && statusColorWin.isDimming()) {
7871 // Otherwise if it's dimming, clear the light flag.
7872 vis &= ~View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR;
Adrian Rooscd3884d2015-02-18 17:25:23 +01007873 }
7874 return vis;
7875 }
7876
Jorim Jaggi40db0292016-06-27 17:58:03 -07007877 private int updateLightNavigationBarLw(int vis, WindowState opaque,
7878 WindowState opaqueOrDimming) {
7879 final WindowState imeWin = mWindowManagerFuncs.getInputMethodWindowLw();
7880
7881 final WindowState navColorWin;
Jorim Jaggiff46d4c2017-07-17 16:46:00 +02007882 if (imeWin != null && imeWin.isVisibleLw() && mNavigationBarPosition == NAV_BAR_BOTTOM) {
Jorim Jaggi40db0292016-06-27 17:58:03 -07007883 navColorWin = imeWin;
7884 } else {
7885 navColorWin = opaqueOrDimming;
7886 }
7887
7888 if (navColorWin != null) {
7889 if (navColorWin == opaque) {
7890 // If the top fullscreen-or-dimming window is also the top fullscreen, respect
7891 // its light flag.
7892 vis &= ~View.SYSTEM_UI_FLAG_LIGHT_NAVIGATION_BAR;
7893 vis |= PolicyControl.getSystemUiVisibility(navColorWin, null)
7894 & View.SYSTEM_UI_FLAG_LIGHT_NAVIGATION_BAR;
7895 } else if (navColorWin.isDimming() || navColorWin == imeWin) {
7896 // Otherwise if it's dimming or it's the IME window, clear the light flag.
7897 vis &= ~View.SYSTEM_UI_FLAG_LIGHT_NAVIGATION_BAR;
7898 }
7899 }
7900 return vis;
7901 }
7902
Jorim Jaggi8f5701b2016-04-04 18:36:02 -07007903 private boolean drawsSystemBarBackground(WindowState win) {
7904 return win == null || (win.getAttrs().flags & FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS) != 0;
7905 }
7906
7907 private boolean forcesDrawStatusBarBackground(WindowState win) {
7908 return win == null || (win.getAttrs().privateFlags
7909 & PRIVATE_FLAG_FORCE_DRAW_STATUS_BAR_BACKGROUND) != 0;
7910 }
7911
John Spurlock79da8332013-09-20 12:04:47 -04007912 private int updateSystemBarsLw(WindowState win, int oldVis, int vis) {
Wale Ogunwale6e94a9e2015-10-07 15:35:49 -07007913 final boolean dockedStackVisible = mWindowManagerInternal.isStackVisible(DOCKED_STACK_ID);
7914 final boolean freeformStackVisible =
7915 mWindowManagerInternal.isStackVisible(FREEFORM_WORKSPACE_STACK_ID);
Jorim Jaggi9511b0f2016-01-29 19:12:44 -08007916 final boolean resizing = mWindowManagerInternal.isDockedDividerResizing();
7917
7918 // We need to force system bars when the docked stack is visible, when the freeform stack
7919 // is visible but also when we are resizing for the transitions when docked stack
7920 // visibility changes.
Jorim Jaggi0ffd49c2016-02-12 15:04:21 -08007921 mForceShowSystemBars = dockedStackVisible || freeformStackVisible || resizing;
Yorke Lee9b2ffb32016-03-07 20:42:01 -08007922 final boolean forceOpaqueStatusBar = mForceShowSystemBars && !mForceStatusBarFromKeyguard;
Wale Ogunwale6e94a9e2015-10-07 15:35:49 -07007923
John Spurlockbd957402013-10-03 11:38:39 -04007924 // apply translucent bar vis flags
Jorim Jaggife762342016-10-13 14:33:27 +02007925 WindowState fullscreenTransWin = isStatusBarKeyguard() && !mKeyguardOccluded
Jorim Jaggi380ecb82014-03-14 17:25:20 +01007926 ? mStatusBar
John Spurlockbd957402013-10-03 11:38:39 -04007927 : mTopFullscreenOpaqueWindowState;
Jorim Jaggi8f5701b2016-04-04 18:36:02 -07007928 vis = mStatusBarController.applyTranslucentFlagLw(fullscreenTransWin, vis, oldVis);
7929 vis = mNavigationBarController.applyTranslucentFlagLw(fullscreenTransWin, vis, oldVis);
7930 final int dockedVis = mStatusBarController.applyTranslucentFlagLw(
7931 mTopDockedOpaqueWindowState, 0, 0);
7932
7933 final boolean fullscreenDrawsStatusBarBackground =
7934 (drawsSystemBarBackground(mTopFullscreenOpaqueWindowState)
7935 && (vis & View.STATUS_BAR_TRANSLUCENT) == 0)
7936 || forcesDrawStatusBarBackground(mTopFullscreenOpaqueWindowState);
7937 final boolean dockedDrawsStatusBarBackground =
7938 (drawsSystemBarBackground(mTopDockedOpaqueWindowState)
7939 && (dockedVis & View.STATUS_BAR_TRANSLUCENT) == 0)
7940 || forcesDrawStatusBarBackground(mTopDockedOpaqueWindowState);
John Spurlockbd957402013-10-03 11:38:39 -04007941
John Spurlock27735a42013-08-14 17:57:38 -04007942 // prevent status bar interaction from clearing certain flags
Selim Cinekf83e8242015-05-19 18:08:14 -07007943 int type = win.getAttrs().type;
7944 boolean statusBarHasFocus = type == TYPE_STATUS_BAR;
John Spurlock08ffcf52014-07-11 10:13:46 -04007945 if (statusBarHasFocus && !isStatusBarKeyguard()) {
John Spurlockad3e6cb2013-04-30 08:47:43 -04007946 int flags = View.SYSTEM_UI_FLAG_FULLSCREEN
7947 | View.SYSTEM_UI_FLAG_HIDE_NAVIGATION
John Spurlockcfc359a2013-09-05 10:42:03 -04007948 | View.SYSTEM_UI_FLAG_IMMERSIVE
Jorim Jaggi73fef8d2015-02-16 17:32:28 +01007949 | View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY
7950 | View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR;
Jorim Jaggife762342016-10-13 14:33:27 +02007951 if (mKeyguardOccluded) {
Jorim Jaggi5cf17872014-03-26 18:31:48 +01007952 flags |= View.STATUS_BAR_TRANSLUCENT | View.NAVIGATION_BAR_TRANSLUCENT;
7953 }
John Spurlockbd957402013-10-03 11:38:39 -04007954 vis = (vis & ~flags) | (oldVis & flags);
John Spurlockad3e6cb2013-04-30 08:47:43 -04007955 }
John Spurlockad3e6cb2013-04-30 08:47:43 -04007956
Jorim Jaggi8f5701b2016-04-04 18:36:02 -07007957 if (fullscreenDrawsStatusBarBackground && dockedDrawsStatusBarBackground) {
7958 vis |= View.STATUS_BAR_TRANSPARENT;
7959 vis &= ~View.STATUS_BAR_TRANSLUCENT;
7960 } else if ((!areTranslucentBarsAllowed() && fullscreenTransWin != mStatusBar)
Yorke Lee9b2ffb32016-03-07 20:42:01 -08007961 || forceOpaqueStatusBar) {
7962 vis &= ~(View.STATUS_BAR_TRANSLUCENT | View.STATUS_BAR_TRANSPARENT);
Alan Viverette5a0f4ec2013-10-07 15:10:29 -07007963 }
7964
Yorke Lee9b2ffb32016-03-07 20:42:01 -08007965 vis = configureNavBarOpacity(vis, dockedStackVisible, freeformStackVisible, resizing);
Yorke Lee2e4b7322016-03-02 17:33:06 -08007966
John Spurlock27735a42013-08-14 17:57:38 -04007967 // update status bar
John Spurlockf1a36642013-10-12 17:50:42 -04007968 boolean immersiveSticky =
7969 (vis & View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY) != 0;
Wale Ogunwale6e94a9e2015-10-07 15:35:49 -07007970 final boolean hideStatusBarWM =
7971 mTopFullscreenOpaqueWindowState != null
7972 && (PolicyControl.getWindowFlags(mTopFullscreenOpaqueWindowState, null)
John Spurlock27735a42013-08-14 17:57:38 -04007973 & WindowManager.LayoutParams.FLAG_FULLSCREEN) != 0;
Wale Ogunwale6e94a9e2015-10-07 15:35:49 -07007974 final boolean hideStatusBarSysui =
John Spurlock27735a42013-08-14 17:57:38 -04007975 (vis & View.SYSTEM_UI_FLAG_FULLSCREEN) != 0;
Wale Ogunwale6e94a9e2015-10-07 15:35:49 -07007976 final boolean hideNavBarSysui =
John Spurlockf1a36642013-10-12 17:50:42 -04007977 (vis & View.SYSTEM_UI_FLAG_HIDE_NAVIGATION) != 0;
John Spurlockad3e6cb2013-04-30 08:47:43 -04007978
Wale Ogunwale6e94a9e2015-10-07 15:35:49 -07007979 final boolean transientStatusBarAllowed = mStatusBar != null
Jorim Jaggi0ffd49c2016-02-12 15:04:21 -08007980 && (statusBarHasFocus || (!mForceShowSystemBars
Wale Ogunwale6e94a9e2015-10-07 15:35:49 -07007981 && (hideStatusBarWM || (hideStatusBarSysui && immersiveSticky))));
John Spurlock27735a42013-08-14 17:57:38 -04007982
Wale Ogunwale6e94a9e2015-10-07 15:35:49 -07007983 final boolean transientNavBarAllowed = mNavigationBar != null
Jorim Jaggi0ffd49c2016-02-12 15:04:21 -08007984 && !mForceShowSystemBars && hideNavBarSysui && immersiveSticky;
John Spurlockf1a36642013-10-12 17:50:42 -04007985
Adrian Roosddc8b272015-05-21 16:28:27 -07007986 final long now = SystemClock.uptimeMillis();
7987 final boolean pendingPanic = mPendingPanicGestureUptime != 0
7988 && now - mPendingPanicGestureUptime <= PANIC_GESTURE_EXPIRATION;
7989 if (pendingPanic && hideNavBarSysui && !isStatusBarKeyguard() && mKeyguardDrawComplete) {
7990 // The user performed the panic gesture recently, we're about to hide the bars,
7991 // we're no longer on the Keyguard and the screen is ready. We can now request the bars.
7992 mPendingPanicGestureUptime = 0;
7993 mStatusBarController.showTransient();
Adrian Roos1f425902016-07-22 10:37:50 -07007994 if (!isNavBarEmpty(vis)) {
7995 mNavigationBarController.showTransient();
7996 }
Adrian Roosddc8b272015-05-21 16:28:27 -07007997 }
7998
Wale Ogunwale6e94a9e2015-10-07 15:35:49 -07007999 final boolean denyTransientStatus = mStatusBarController.isTransientShowRequested()
John Spurlockf1a36642013-10-12 17:50:42 -04008000 && !transientStatusBarAllowed && hideStatusBarSysui;
Wale Ogunwale6e94a9e2015-10-07 15:35:49 -07008001 final boolean denyTransientNav = mNavigationBarController.isTransientShowRequested()
John Spurlockf1a36642013-10-12 17:50:42 -04008002 && !transientNavBarAllowed;
Jorim Jaggi0ffd49c2016-02-12 15:04:21 -08008003 if (denyTransientStatus || denyTransientNav || mForceShowSystemBars) {
John Spurlock27735a42013-08-14 17:57:38 -04008004 // clear the clearable flags instead
John Spurlockf1a36642013-10-12 17:50:42 -04008005 clearClearableFlagsLw();
tiger_huangc58d7562014-10-23 20:24:19 +08008006 vis &= ~View.SYSTEM_UI_CLEARABLE_FLAGS;
John Spurlockad3e6cb2013-04-30 08:47:43 -04008007 }
John Spurlock27735a42013-08-14 17:57:38 -04008008
Selim Cinekf98702e2015-05-20 22:48:40 -07008009 final boolean immersive = (vis & View.SYSTEM_UI_FLAG_IMMERSIVE) != 0;
8010 immersiveSticky = (vis & View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY) != 0;
8011 final boolean navAllowedHidden = immersive || immersiveSticky;
8012
Wale Ogunwale5cd907d2017-01-26 14:14:08 -08008013 if (hideNavBarSysui && !navAllowedHidden
8014 && getWindowLayerLw(win) > getWindowLayerFromTypeLw(TYPE_INPUT_CONSUMER)) {
Selim Cinekf98702e2015-05-20 22:48:40 -07008015 // We can't hide the navbar from this window otherwise the input consumer would not get
8016 // the input events.
8017 vis = (vis & ~View.SYSTEM_UI_FLAG_HIDE_NAVIGATION);
8018 }
8019
John Spurlock27735a42013-08-14 17:57:38 -04008020 vis = mStatusBarController.updateVisibilityLw(transientStatusBarAllowed, oldVis, vis);
8021
8022 // update navigation bar
John Spurlockf1a36642013-10-12 17:50:42 -04008023 boolean oldImmersiveMode = isImmersiveMode(oldVis);
8024 boolean newImmersiveMode = isImmersiveMode(vis);
8025 if (win != null && oldImmersiveMode != newImmersiveMode) {
John Spurlock79da8332013-09-20 12:04:47 -04008026 final String pkg = win.getOwningPackage();
Amith Yamasani02a03812016-04-22 17:32:00 -07008027 mImmersiveModeConfirmation.immersiveModeChangedLw(pkg, newImmersiveMode,
Adrian Roos7aaa5512016-07-12 15:27:24 -07008028 isUserSetupComplete(), isNavBarEmpty(win.getSystemUiVisibility()));
John Spurlock34e13d92013-08-10 06:52:28 -04008029 }
John Spurlock27735a42013-08-14 17:57:38 -04008030
John Spurlockf1a36642013-10-12 17:50:42 -04008031 vis = mNavigationBarController.updateVisibilityLw(transientNavBarAllowed, oldVis, vis);
8032
Jorim Jaggi40db0292016-06-27 17:58:03 -07008033 vis = updateLightNavigationBarLw(vis, mTopFullscreenOpaqueWindowState,
8034 mTopFullscreenOpaqueOrDimmingWindowState);
8035
John Spurlocke1f366f2013-08-05 12:22:40 -04008036 return vis;
John Spurlockad3e6cb2013-04-30 08:47:43 -04008037 }
8038
Yorke Lee9b2ffb32016-03-07 20:42:01 -08008039 /**
8040 * @return the current visibility flags with the nav-bar opacity related flags toggled based
8041 * on the nav bar opacity rules chosen by {@link #mNavBarOpacityMode}.
8042 */
8043 private int configureNavBarOpacity(int visibility, boolean dockedStackVisible,
8044 boolean freeformStackVisible, boolean isDockedDividerResizing) {
8045 if (mNavBarOpacityMode == NAV_BAR_OPAQUE_WHEN_FREEFORM_OR_DOCKED) {
8046 if (dockedStackVisible || freeformStackVisible || isDockedDividerResizing) {
8047 visibility = setNavBarOpaqueFlag(visibility);
8048 }
8049 } else if (mNavBarOpacityMode == NAV_BAR_TRANSLUCENT_WHEN_FREEFORM_OPAQUE_OTHERWISE) {
8050 if (isDockedDividerResizing) {
8051 visibility = setNavBarOpaqueFlag(visibility);
8052 } else if (freeformStackVisible) {
8053 visibility = setNavBarTranslucentFlag(visibility);
8054 } else {
8055 visibility = setNavBarOpaqueFlag(visibility);
8056 }
8057 }
8058
8059 if (!areTranslucentBarsAllowed()) {
8060 visibility &= ~View.NAVIGATION_BAR_TRANSLUCENT;
8061 }
8062 return visibility;
8063 }
8064
8065 private int setNavBarOpaqueFlag(int visibility) {
8066 return visibility &= ~(View.NAVIGATION_BAR_TRANSLUCENT | View.NAVIGATION_BAR_TRANSPARENT);
8067 }
8068
8069 private int setNavBarTranslucentFlag(int visibility) {
8070 visibility &= ~View.NAVIGATION_BAR_TRANSPARENT;
8071 return visibility |= View.NAVIGATION_BAR_TRANSLUCENT;
8072 }
8073
John Spurlockf1a36642013-10-12 17:50:42 -04008074 private void clearClearableFlagsLw() {
8075 int newVal = mResettingSystemUiFlags | View.SYSTEM_UI_CLEARABLE_FLAGS;
8076 if (newVal != mResettingSystemUiFlags) {
8077 mResettingSystemUiFlags = newVal;
8078 mWindowManagerFuncs.reevaluateStatusBarVisibility();
8079 }
8080 }
8081
8082 private boolean isImmersiveMode(int vis) {
8083 final int flags = View.SYSTEM_UI_FLAG_IMMERSIVE | View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY;
John Spurlock34e13d92013-08-10 06:52:28 -04008084 return mNavigationBar != null
8085 && (vis & View.SYSTEM_UI_FLAG_HIDE_NAVIGATION) != 0
Daniel Sandler900ece52013-10-18 15:53:27 -04008086 && (vis & flags) != 0
8087 && canHideNavigationBar();
John Spurlock34e13d92013-08-10 06:52:28 -04008088 }
8089
Adrian Roos7aaa5512016-07-12 15:27:24 -07008090 private static boolean isNavBarEmpty(int systemUiFlags) {
8091 final int disableNavigationBar = (View.STATUS_BAR_DISABLE_HOME
8092 | View.STATUS_BAR_DISABLE_BACK
8093 | View.STATUS_BAR_DISABLE_RECENT);
8094
8095 return (systemUiFlags & disableNavigationBar) == disableNavigationBar;
8096 }
8097
Alan Viverette5a0f4ec2013-10-07 15:10:29 -07008098 /**
Daniel Sandlerdd73ee42013-10-11 22:19:59 -04008099 * @return whether the navigation or status bar can be made translucent
8100 *
8101 * This should return true unless touch exploration is not enabled or
8102 * R.boolean.config_enableTranslucentDecor is false.
Alan Viverette5a0f4ec2013-10-07 15:10:29 -07008103 */
Daniel Sandlerdd73ee42013-10-11 22:19:59 -04008104 private boolean areTranslucentBarsAllowed() {
Alan Viverette817f3cd2015-08-13 11:40:14 -04008105 return mTranslucentDecorEnabled;
Alan Viverette5a0f4ec2013-10-07 15:10:29 -07008106 }
8107
Daniel Sandler0c4ccff2011-10-19 16:39:14 -04008108 // Use this instead of checking config_showNavigationBar so that it can be consistently
8109 // overridden by qemu.hw.mainkeys in the emulator.
Craig Mautnereda67292013-04-28 13:50:14 -07008110 @Override
Daniel Sandler0c4ccff2011-10-19 16:39:14 -04008111 public boolean hasNavigationBar() {
8112 return mHasNavigationBar;
8113 }
8114
satok1bc0a492012-04-25 22:47:12 +09008115 @Override
8116 public void setLastInputMethodWindowLw(WindowState ime, WindowState target) {
8117 mLastInputMethodWindow = ime;
8118 mLastInputMethodTargetWindow = target;
8119 }
8120
Craig Mautnerf1b67412012-09-19 13:18:29 -07008121 @Override
Yohei Yukawad6475a62017-04-17 10:35:27 -07008122 public void setDismissImeOnBackKeyPressed(boolean newValue) {
Yohei Yukawaabbe1ac2017-04-18 09:43:05 -07008123 mDismissImeOnBackKeyPressed = newValue;
Yohei Yukawad6475a62017-04-17 10:35:27 -07008124 }
8125
8126 @Override
Satoshi Kataoka658c7b82013-10-10 17:03:51 +09008127 public int getInputMethodWindowVisibleHeightLw() {
8128 return mDockBottom - mCurBottom;
8129 }
8130
8131 @Override
Craig Mautnerf1b67412012-09-19 13:18:29 -07008132 public void setCurrentUserLw(int newUserId) {
Craig Mautnerd625ab22013-09-06 13:40:31 -07008133 mCurrentUserId = newUserId;
Jim Miller5ecd8112013-01-09 18:50:26 -08008134 if (mKeyguardDelegate != null) {
8135 mKeyguardDelegate.setCurrentUser(newUserId);
Craig Mautnerf1b67412012-09-19 13:18:29 -07008136 }
Phil Weaverce687c52017-03-15 08:51:52 -07008137 if (mAccessibilityShortcutController != null) {
8138 mAccessibilityShortcutController.setCurrentUser(newUserId);
8139 }
Adrian Roosf2efdd82016-04-15 17:43:18 -07008140 StatusBarManagerInternal statusBar = getStatusBarManagerInternal();
Adrian Roos2a629102016-04-15 16:28:03 -07008141 if (statusBar != null) {
Adrian Roosf2efdd82016-04-15 17:43:18 -07008142 statusBar.setCurrentUser(newUserId);
John Spurlock13451a22012-09-28 14:40:41 -04008143 }
Dianne Hackborn2ea9bae2012-11-02 18:43:48 -07008144 setLastInputMethodWindowLw(null, null);
Craig Mautnerf1b67412012-09-19 13:18:29 -07008145 }
8146
8147 @Override
Evan Rosky18396452016-07-27 15:19:37 -07008148 public void setSwitchingUser(boolean switching) {
8149 mKeyguardDelegate.setSwitchingUser(switching);
8150 }
8151
8152 @Override
Svetoslav Ganov545252f2012-12-10 18:29:24 -08008153 public boolean canMagnifyWindow(int windowType) {
8154 switch (windowType) {
8155 case WindowManager.LayoutParams.TYPE_INPUT_METHOD:
8156 case WindowManager.LayoutParams.TYPE_INPUT_METHOD_DIALOG:
8157 case WindowManager.LayoutParams.TYPE_NAVIGATION_BAR:
8158 case WindowManager.LayoutParams.TYPE_MAGNIFICATION_OVERLAY: {
8159 return false;
8160 }
8161 }
8162 return true;
8163 }
8164
8165 @Override
8166 public boolean isTopLevelWindow(int windowType) {
8167 if (windowType >= WindowManager.LayoutParams.FIRST_SUB_WINDOW
8168 && windowType <= WindowManager.LayoutParams.LAST_SUB_WINDOW) {
8169 return (windowType == WindowManager.LayoutParams.TYPE_APPLICATION_ATTACHED_DIALOG);
8170 }
8171 return true;
8172 }
8173
Jim Miller4eeb4f62012-11-08 00:04:29 -08008174 @Override
Robert Carr6da3cc02016-06-16 15:17:07 -07008175 public boolean shouldRotateSeamlessly(int oldRotation, int newRotation) {
8176 // For the upside down rotation we don't rotate seamlessly as the navigation
8177 // bar moves position.
8178 // Note most apps (using orientation:sensor or user as opposed to fullSensor)
8179 // will not enter the reverse portrait orientation, so actually the
8180 // orientation won't change at all.
8181 if (oldRotation == mUpsideDownRotation || newRotation == mUpsideDownRotation) {
8182 return false;
8183 }
Robert Carr0b9ac5a2016-10-26 14:12:14 -07008184 // If the navigation bar can't change sides, then it will
8185 // jump when we change orientations and we don't rotate
8186 // seamlessly.
8187 if (!mNavigationBarCanMove) {
8188 return false;
8189 }
Robert Carr6da3cc02016-06-16 15:17:07 -07008190 int delta = newRotation - oldRotation;
8191 if (delta < 0) delta += 4;
8192 // Likewise we don't rotate seamlessly for 180 degree rotations
Geoffrey Pitschb2d6ed32016-08-24 10:37:19 -04008193 // in this case the surfaces never resize, and our logic to
Robert Carr6da3cc02016-06-16 15:17:07 -07008194 // revert the transformations on size change will fail. We could
8195 // fix this in the future with the "tagged" frames idea.
8196 if (delta == Surface.ROTATION_180) {
8197 return false;
8198 }
8199
Robert Carr57d9fbd2016-08-15 12:00:35 -07008200 final WindowState w = mTopFullscreenOpaqueWindowState;
Robert Carr828ec3dc2016-08-22 13:32:34 -07008201 if (w != mFocusedWindow) {
8202 return false;
8203 }
Robert Carr57d9fbd2016-08-15 12:00:35 -07008204
Robert Carr606f4d52016-06-30 14:36:27 -07008205 // We only enable seamless rotation if the top window has requested
8206 // it and is in the fullscreen opaque state. Seamless rotation
8207 // requires freezing various Surface states and won't work well
8208 // with animations, so we disable it in the animation case for now.
Robert Carr1ccd4252016-08-15 12:05:21 -07008209 if (w != null && !w.isAnimatingLw() &&
Robert Carr57d9fbd2016-08-15 12:00:35 -07008210 ((w.getAttrs().rotationAnimation == ROTATION_ANIMATION_JUMPCUT) ||
8211 (w.getAttrs().rotationAnimation == ROTATION_ANIMATION_SEAMLESS))) {
Robert Carr6da3cc02016-06-16 15:17:07 -07008212 return true;
8213 }
8214 return false;
8215 }
8216
8217 @Override
Jeff Brownd7a04de2012-06-17 14:17:52 -07008218 public void dump(String prefix, PrintWriter pw, String[] args) {
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08008219 pw.print(prefix); pw.print("mSafeMode="); pw.print(mSafeMode);
Dianne Hackbornba24e4d2011-09-01 11:17:06 -07008220 pw.print(" mSystemReady="); pw.print(mSystemReady);
8221 pw.print(" mSystemBooted="); pw.println(mSystemBooted);
Jeff Brown2e7760e2012-04-11 15:14:55 -07008222 pw.print(prefix); pw.print("mLidState="); pw.print(mLidState);
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08008223 pw.print(" mLidOpenRotation="); pw.print(mLidOpenRotation);
Michael Wright3818c922014-09-02 13:59:07 -07008224 pw.print(" mCameraLensCoverState="); pw.print(mCameraLensCoverState);
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08008225 pw.print(" mHdmiPlugged="); pw.println(mHdmiPlugged);
Dianne Hackborne26ab702011-10-16 13:21:33 -07008226 if (mLastSystemUiFlags != 0 || mResettingSystemUiFlags != 0
8227 || mForceClearedSystemUiFlags != 0) {
8228 pw.print(prefix); pw.print("mLastSystemUiFlags=0x");
8229 pw.print(Integer.toHexString(mLastSystemUiFlags));
8230 pw.print(" mResettingSystemUiFlags=0x");
8231 pw.print(Integer.toHexString(mResettingSystemUiFlags));
8232 pw.print(" mForceClearedSystemUiFlags=0x");
8233 pw.println(Integer.toHexString(mForceClearedSystemUiFlags));
Dianne Hackborndf89e652011-10-06 22:35:11 -07008234 }
Dianne Hackborn4eff8d32011-11-10 19:38:40 -08008235 if (mLastFocusNeedsMenu) {
8236 pw.print(prefix); pw.print("mLastFocusNeedsMenu=");
8237 pw.println(mLastFocusNeedsMenu);
8238 }
Jeff Browna20dda42014-05-27 20:57:24 -07008239 pw.print(prefix); pw.print("mWakeGestureEnabledSetting=");
8240 pw.println(mWakeGestureEnabledSetting);
8241
Jeff Brownbcdfc622014-03-06 19:13:04 -08008242 pw.print(prefix); pw.print("mSupportAutoRotation="); pw.println(mSupportAutoRotation);
Daniel Sandler6396c722013-04-16 20:19:09 -04008243 pw.print(prefix); pw.print("mUiMode="); pw.print(mUiMode);
8244 pw.print(" mDockMode="); pw.print(mDockMode);
keunyounga7710492015-09-23 11:33:58 -07008245 pw.print(" mEnableCarDockHomeCapture="); pw.print(mEnableCarDockHomeCapture);
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08008246 pw.print(" mCarDockRotation="); pw.print(mCarDockRotation);
8247 pw.print(" mDeskDockRotation="); pw.println(mDeskDockRotation);
8248 pw.print(prefix); pw.print("mUserRotationMode="); pw.print(mUserRotationMode);
8249 pw.print(" mUserRotation="); pw.print(mUserRotation);
Daniel Sandler2ed6ad62011-02-22 14:54:17 -05008250 pw.print(" mAllowAllRotations="); pw.println(mAllowAllRotations);
Dianne Hackborn6e2281d2012-06-19 17:48:32 -07008251 pw.print(prefix); pw.print("mCurrentAppOrientation="); pw.println(mCurrentAppOrientation);
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08008252 pw.print(prefix); pw.print("mCarDockEnablesAccelerometer=");
8253 pw.print(mCarDockEnablesAccelerometer);
8254 pw.print(" mDeskDockEnablesAccelerometer=");
8255 pw.println(mDeskDockEnablesAccelerometer);
8256 pw.print(prefix); pw.print("mLidKeyboardAccessibility=");
8257 pw.print(mLidKeyboardAccessibility);
8258 pw.print(" mLidNavigationAccessibility="); pw.print(mLidNavigationAccessibility);
Edward Savage-Jones7def60d2015-11-13 13:27:03 +01008259 pw.print(" mLidControlsScreenLock="); pw.println(mLidControlsScreenLock);
Dianne Hackborn6e2281d2012-06-19 17:48:32 -07008260 pw.print(" mLidControlsSleep="); pw.println(mLidControlsSleep);
Jeff Brown6d8fd272014-05-20 21:24:38 -07008261 pw.print(prefix);
Anthony Hugh34f09ca2016-03-04 12:03:37 -08008262 pw.print(" mLongPressOnBackBehavior="); pw.println(mLongPressOnBackBehavior);
8263 pw.print(prefix);
Jeff Brown6d8fd272014-05-20 21:24:38 -07008264 pw.print("mShortPressOnPowerBehavior="); pw.print(mShortPressOnPowerBehavior);
8265 pw.print(" mLongPressOnPowerBehavior="); pw.println(mLongPressOnPowerBehavior);
Jeff Brown13f00f02014-10-31 14:45:50 -07008266 pw.print(prefix);
8267 pw.print("mDoublePressOnPowerBehavior="); pw.print(mDoublePressOnPowerBehavior);
8268 pw.print(" mTriplePressOnPowerBehavior="); pw.println(mTriplePressOnPowerBehavior);
Jeff Brown6d8fd272014-05-20 21:24:38 -07008269 pw.print(prefix); pw.print("mHasSoftInput="); pw.println(mHasSoftInput);
Jeff Brown3ee549c2014-09-22 20:14:39 -07008270 pw.print(prefix); pw.print("mAwake="); pw.println(mAwake);
8271 pw.print(prefix); pw.print("mScreenOnEarly="); pw.print(mScreenOnEarly);
8272 pw.print(" mScreenOnFully="); pw.println(mScreenOnFully);
8273 pw.print(prefix); pw.print("mKeyguardDrawComplete="); pw.print(mKeyguardDrawComplete);
8274 pw.print(" mWindowManagerDrawComplete="); pw.println(mWindowManagerDrawComplete);
8275 pw.print(prefix); pw.print("mOrientationSensorEnabled=");
8276 pw.println(mOrientationSensorEnabled);
Dianne Hackbornc652de82013-02-15 16:32:56 -08008277 pw.print(prefix); pw.print("mOverscanScreen=("); pw.print(mOverscanScreenLeft);
8278 pw.print(","); pw.print(mOverscanScreenTop);
8279 pw.print(") "); pw.print(mOverscanScreenWidth);
8280 pw.print("x"); pw.println(mOverscanScreenHeight);
8281 if (mOverscanLeft != 0 || mOverscanTop != 0
8282 || mOverscanRight != 0 || mOverscanBottom != 0) {
8283 pw.print(prefix); pw.print("mOverscan left="); pw.print(mOverscanLeft);
8284 pw.print(" top="); pw.print(mOverscanTop);
8285 pw.print(" right="); pw.print(mOverscanRight);
8286 pw.print(" bottom="); pw.println(mOverscanBottom);
8287 }
Dianne Hackborn313440842013-02-19 19:22:59 -08008288 pw.print(prefix); pw.print("mRestrictedOverscanScreen=(");
8289 pw.print(mRestrictedOverscanScreenLeft);
8290 pw.print(","); pw.print(mRestrictedOverscanScreenTop);
8291 pw.print(") "); pw.print(mRestrictedOverscanScreenWidth);
8292 pw.print("x"); pw.println(mRestrictedOverscanScreenHeight);
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08008293 pw.print(prefix); pw.print("mUnrestrictedScreen=("); pw.print(mUnrestrictedScreenLeft);
8294 pw.print(","); pw.print(mUnrestrictedScreenTop);
8295 pw.print(") "); pw.print(mUnrestrictedScreenWidth);
8296 pw.print("x"); pw.println(mUnrestrictedScreenHeight);
8297 pw.print(prefix); pw.print("mRestrictedScreen=("); pw.print(mRestrictedScreenLeft);
8298 pw.print(","); pw.print(mRestrictedScreenTop);
8299 pw.print(") "); pw.print(mRestrictedScreenWidth);
8300 pw.print("x"); pw.println(mRestrictedScreenHeight);
Dianne Hackborn5b5cc4d2012-05-16 13:15:00 -07008301 pw.print(prefix); pw.print("mStableFullscreen=("); pw.print(mStableFullscreenLeft);
8302 pw.print(","); pw.print(mStableFullscreenTop);
8303 pw.print(")-("); pw.print(mStableFullscreenRight);
8304 pw.print(","); pw.print(mStableFullscreenBottom); pw.println(")");
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07008305 pw.print(prefix); pw.print("mStable=("); pw.print(mStableLeft);
8306 pw.print(","); pw.print(mStableTop);
8307 pw.print(")-("); pw.print(mStableRight);
8308 pw.print(","); pw.print(mStableBottom); pw.println(")");
Dianne Hackborn5c58de32012-04-28 19:52:37 -07008309 pw.print(prefix); pw.print("mSystem=("); pw.print(mSystemLeft);
8310 pw.print(","); pw.print(mSystemTop);
8311 pw.print(")-("); pw.print(mSystemRight);
8312 pw.print(","); pw.print(mSystemBottom); pw.println(")");
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08008313 pw.print(prefix); pw.print("mCur=("); pw.print(mCurLeft);
8314 pw.print(","); pw.print(mCurTop);
8315 pw.print(")-("); pw.print(mCurRight);
8316 pw.print(","); pw.print(mCurBottom); pw.println(")");
8317 pw.print(prefix); pw.print("mContent=("); pw.print(mContentLeft);
8318 pw.print(","); pw.print(mContentTop);
8319 pw.print(")-("); pw.print(mContentRight);
8320 pw.print(","); pw.print(mContentBottom); pw.println(")");
Dianne Hackborne30e02f2014-05-27 18:24:45 -07008321 pw.print(prefix); pw.print("mVoiceContent=("); pw.print(mVoiceContentLeft);
8322 pw.print(","); pw.print(mVoiceContentTop);
8323 pw.print(")-("); pw.print(mVoiceContentRight);
8324 pw.print(","); pw.print(mVoiceContentBottom); pw.println(")");
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08008325 pw.print(prefix); pw.print("mDock=("); pw.print(mDockLeft);
8326 pw.print(","); pw.print(mDockTop);
8327 pw.print(")-("); pw.print(mDockRight);
8328 pw.print(","); pw.print(mDockBottom); pw.println(")");
Dianne Hackborn5c58de32012-04-28 19:52:37 -07008329 pw.print(prefix); pw.print("mDockLayer="); pw.print(mDockLayer);
8330 pw.print(" mStatusBarLayer="); pw.println(mStatusBarLayer);
Jorim Jaggi8d786932016-10-26 19:08:36 -07008331 pw.print(prefix); pw.print("mShowingDream="); pw.print(mShowingDream);
Jeff Brown061ea992015-04-17 19:55:47 -07008332 pw.print(" mDreamingLockscreen="); pw.print(mDreamingLockscreen);
8333 pw.print(" mDreamingSleepToken="); pw.println(mDreamingSleepToken);
Dianne Hackborn2ea9bae2012-11-02 18:43:48 -07008334 if (mLastInputMethodWindow != null) {
8335 pw.print(prefix); pw.print("mLastInputMethodWindow=");
8336 pw.println(mLastInputMethodWindow);
8337 }
8338 if (mLastInputMethodTargetWindow != null) {
8339 pw.print(prefix); pw.print("mLastInputMethodTargetWindow=");
8340 pw.println(mLastInputMethodTargetWindow);
8341 }
Yohei Yukawad6475a62017-04-17 10:35:27 -07008342 pw.print(prefix); pw.print("mDismissImeOnBackKeyPressed=");
8343 pw.println(mDismissImeOnBackKeyPressed);
Dianne Hackborn2ea9bae2012-11-02 18:43:48 -07008344 if (mStatusBar != null) {
8345 pw.print(prefix); pw.print("mStatusBar=");
Dianne Hackbornae6688b2015-02-11 17:02:41 -08008346 pw.print(mStatusBar); pw.print(" isStatusBarKeyguard=");
8347 pw.println(isStatusBarKeyguard());
Dianne Hackborn2ea9bae2012-11-02 18:43:48 -07008348 }
8349 if (mNavigationBar != null) {
8350 pw.print(prefix); pw.print("mNavigationBar=");
8351 pw.println(mNavigationBar);
8352 }
Dianne Hackborn2ea9bae2012-11-02 18:43:48 -07008353 if (mFocusedWindow != null) {
8354 pw.print(prefix); pw.print("mFocusedWindow=");
8355 pw.println(mFocusedWindow);
8356 }
8357 if (mFocusedApp != null) {
8358 pw.print(prefix); pw.print("mFocusedApp=");
8359 pw.println(mFocusedApp);
8360 }
Dianne Hackborn2ea9bae2012-11-02 18:43:48 -07008361 if (mTopFullscreenOpaqueWindowState != null) {
8362 pw.print(prefix); pw.print("mTopFullscreenOpaqueWindowState=");
8363 pw.println(mTopFullscreenOpaqueWindowState);
8364 }
Adrian Rooscd3884d2015-02-18 17:25:23 +01008365 if (mTopFullscreenOpaqueOrDimmingWindowState != null) {
8366 pw.print(prefix); pw.print("mTopFullscreenOpaqueOrDimmingWindowState=");
8367 pw.println(mTopFullscreenOpaqueOrDimmingWindowState);
8368 }
Dianne Hackborn891d3fb2013-01-09 18:31:37 -08008369 if (mForcingShowNavBar) {
8370 pw.print(prefix); pw.print("mForcingShowNavBar=");
8371 pw.println(mForcingShowNavBar); pw.print( "mForcingShowNavBarLayer=");
8372 pw.println(mForcingShowNavBarLayer);
8373 }
Dianne Hackborn7ad44382012-10-18 17:46:00 -07008374 pw.print(prefix); pw.print("mTopIsFullscreen="); pw.print(mTopIsFullscreen);
Jorim Jaggife762342016-10-13 14:33:27 +02008375 pw.print(" mKeyguardOccluded="); pw.println(mKeyguardOccluded);
Jorim Jaggi8d786932016-10-26 19:08:36 -07008376 pw.print(" mKeyguardOccludedChanged="); pw.println(mKeyguardOccludedChanged);
8377 pw.print(" mPendingKeyguardOccluded="); pw.println(mPendingKeyguardOccluded);
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07008378 pw.print(prefix); pw.print("mForceStatusBar="); pw.print(mForceStatusBar);
8379 pw.print(" mForceStatusBarFromKeyguard=");
8380 pw.println(mForceStatusBarFromKeyguard);
Jorim Jaggife762342016-10-13 14:33:27 +02008381 pw.print(prefix); pw.print("mHomePressed="); pw.println(mHomePressed);
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08008382 pw.print(prefix); pw.print("mAllowLockscreenWhenOn="); pw.print(mAllowLockscreenWhenOn);
8383 pw.print(" mLockScreenTimeout="); pw.print(mLockScreenTimeout);
8384 pw.print(" mLockScreenTimerActive="); pw.println(mLockScreenTimerActive);
8385 pw.print(prefix); pw.print("mEndcallBehavior="); pw.print(mEndcallBehavior);
8386 pw.print(" mIncallPowerBehavior="); pw.print(mIncallPowerBehavior);
Bryce Leedb776ce2016-09-03 15:02:00 -07008387 pw.print(" mIncallBackBehavior="); pw.print(mIncallBackBehavior);
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08008388 pw.print(" mLongPressOnHomeBehavior="); pw.println(mLongPressOnHomeBehavior);
8389 pw.print(prefix); pw.print("mLandscapeRotation="); pw.print(mLandscapeRotation);
8390 pw.print(" mSeascapeRotation="); pw.println(mSeascapeRotation);
8391 pw.print(prefix); pw.print("mPortraitRotation="); pw.print(mPortraitRotation);
8392 pw.print(" mUpsideDownRotation="); pw.println(mUpsideDownRotation);
Jeff Brownc82c89ed2013-04-17 17:18:15 -07008393 pw.print(prefix); pw.print("mDemoHdmiRotation="); pw.print(mDemoHdmiRotation);
8394 pw.print(" mDemoHdmiRotationLock="); pw.println(mDemoHdmiRotationLock);
8395 pw.print(prefix); pw.print("mUndockedHdmiRotation="); pw.println(mUndockedHdmiRotation);
Sujith Ramakrishnan6bed9bd2017-04-26 12:33:37 -07008396 if (mHasFeatureLeanback) {
8397 pw.print(prefix);
8398 pw.print("mAccessibilityTvKey1Pressed="); pw.println(mAccessibilityTvKey1Pressed);
8399 pw.print(prefix);
8400 pw.print("mAccessibilityTvKey2Pressed="); pw.println(mAccessibilityTvKey2Pressed);
8401 pw.print(prefix);
8402 pw.print("mAccessibilityTvScheduled="); pw.println(mAccessibilityTvScheduled);
8403 }
Jeff Brown600f0032014-05-22 17:06:00 -07008404
Tim Kilbournd7c0c2e2014-05-29 16:08:10 -07008405 mGlobalKeyManager.dump(prefix, pw);
John Spurlock27735a42013-08-14 17:57:38 -04008406 mStatusBarController.dump(pw, prefix);
8407 mNavigationBarController.dump(pw, prefix);
John Spurlockc6d1c602014-01-17 15:22:06 -05008408 PolicyControl.dump(prefix, pw);
Jeff Brown600f0032014-05-22 17:06:00 -07008409
Jeff Browna20dda42014-05-27 20:57:24 -07008410 if (mWakeGestureListener != null) {
8411 mWakeGestureListener.dump(pw, prefix);
8412 }
Jeff Brown600f0032014-05-22 17:06:00 -07008413 if (mOrientationListener != null) {
8414 mOrientationListener.dump(pw, prefix);
8415 }
Filip Gruszczynskicfb31852015-02-25 21:47:12 +00008416 if (mBurnInProtectionHelper != null) {
8417 mBurnInProtectionHelper.dump(prefix, pw);
8418 }
Jorim Jaggi84dc08a2015-09-11 17:45:22 -07008419 if (mKeyguardDelegate != null) {
8420 mKeyguardDelegate.dump(prefix, pw);
8421 }
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08008422 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08008423}