blob: ae78d7c551c11036af7444ab2430f8d81b40e736 [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;
Selim Cinekab55ba52017-08-02 16:45:51 -0700499 volatile boolean mRequestedOrGoingToSleep;
Jaewan Kimf0fd2182016-04-20 21:17:58 +0900500 volatile boolean mRecentsVisible;
Winson Chungac52f282017-03-30 14:44:52 -0700501 volatile boolean mPictureInPictureVisible;
Santos Cordonc09d89c2017-04-13 16:12:02 -0700502 // Written by vr manager thread, only read in this class.
503 volatile private boolean mPersistentVrModeEnabled;
Yohei Yukawaabbe1ac2017-04-18 09:43:05 -0700504 volatile private boolean mDismissImeOnBackKeyPressed;
Jeff Brown13f00f02014-10-31 14:45:50 -0700505
Anthony Hugh4b13ab82016-05-17 13:03:00 -0700506 // Used to hold the last user key used to wake the device. This helps us prevent up events
507 // from being passed to the foregrounded app without a corresponding down event
508 volatile int mPendingWakeKey = PENDING_KEY_NULL;
509
Winson Chung1e8d71b2014-05-16 17:05:22 -0700510 int mRecentAppsHeldModifiers;
Jeff Browncf39bdf2012-05-18 14:41:19 -0700511 boolean mLanguageSwitchKeyPressed;
Jeff Brown68b909d2011-12-07 16:36:01 -0800512
Jeff Brown2e7760e2012-04-11 15:14:55 -0700513 int mLidState = LID_ABSENT;
Michael Wright3818c922014-09-02 13:59:07 -0700514 int mCameraLensCoverState = CAMERA_LENS_COVER_ABSENT;
Jeff Browndaa37532012-05-01 15:54:03 -0700515 boolean mHaveBuiltInKeyboard;
Jeff Brown4aed78b2011-01-14 17:36:55 -0800516
Dianne Hackbornc777e072010-02-12 13:07:59 -0800517 boolean mSystemReady;
Dianne Hackbornba24e4d2011-09-01 11:17:06 -0700518 boolean mSystemBooted;
Dianne Hackbornad7fa7f2011-01-07 14:06:50 -0800519 boolean mHdmiPlugged;
Jinsuk Kime601b712015-07-07 08:01:02 +0900520 HdmiControl mHdmiControl;
Jeff Brown4f5fa282014-06-12 19:19:15 -0700521 IUiModeManager mUiModeManager;
Daniel Sandler6396c722013-04-16 20:19:09 -0400522 int mUiMode;
Dianne Hackborn867ab6472010-04-29 13:28:56 -0700523 int mDockMode = Intent.EXTRA_DOCK_STATE_UNDOCKED;
Mike Lockwood1753f7f2009-08-24 14:49:07 -0700524 int mLidOpenRotation;
Mike Lockwood2d1efbd2009-09-16 12:15:53 -0400525 int mCarDockRotation;
526 int mDeskDockRotation;
Jeff Brownc82c89ed2013-04-17 17:18:15 -0700527 int mUndockedHdmiRotation;
528 int mDemoHdmiRotation;
529 boolean mDemoHdmiRotationLock;
Chong Zhangae6119ff2014-11-11 18:54:39 -0800530 int mDemoRotation;
531 boolean mDemoRotationLock;
Daniel Sandlerb73617d2010-08-17 00:41:00 -0400532
Jeff Browna20dda42014-05-27 20:57:24 -0700533 boolean mWakeGestureEnabledSetting;
534 MyWakeGestureListener mWakeGestureListener;
535
Craig Mautner46ac6fa2013-08-01 10:06:34 -0700536 // Default display does not rotate, apps that require non-default orientation will have to
537 // have the orientation emulated.
538 private boolean mForceDefaultOrientation = false;
539
Daniel Sandlerb73617d2010-08-17 00:41:00 -0400540 int mUserRotationMode = WindowManagerPolicy.USER_ROTATION_FREE;
541 int mUserRotation = Surface.ROTATION_0;
Jeff Brown207673cd2012-06-05 17:47:11 -0700542 boolean mAccelerometerDefault;
Daniel Sandlerb73617d2010-08-17 00:41:00 -0400543
Jeff Brownbcdfc622014-03-06 19:13:04 -0800544 boolean mSupportAutoRotation;
Jeff Brownd3187e32011-09-21 19:26:44 -0700545 int mAllowAllRotations = -1;
Mike Lockwoode9867d22009-09-20 01:59:02 -0400546 boolean mCarDockEnablesAccelerometer;
547 boolean mDeskDockEnablesAccelerometer;
Dianne Hackborn2862fff2009-09-15 22:56:29 -0700548 int mLidKeyboardAccessibility;
549 int mLidNavigationAccessibility;
Edward Savage-Jones7def60d2015-11-13 13:27:03 +0100550 boolean mLidControlsScreenLock;
Jeff Brownc458ce92012-04-30 14:58:40 -0700551 boolean mLidControlsSleep;
Jeff Brown13f00f02014-10-31 14:45:50 -0700552 int mShortPressOnPowerBehavior;
553 int mLongPressOnPowerBehavior;
554 int mDoublePressOnPowerBehavior;
555 int mTriplePressOnPowerBehavior;
Anthony Hugh34f09ca2016-03-04 12:03:37 -0800556 int mLongPressOnBackBehavior;
Anthony Hugh96e9cc52016-07-12 15:17:24 -0700557 int mPanicPressOnBackBehavior;
Filip Gruszczynskia483a1d2015-03-17 19:06:58 +0000558 int mShortPressOnSleepBehavior;
Jaewan Kim49117872016-01-19 17:24:08 +0900559 int mShortPressWindowBehavior;
Adrian Roose94c15c2017-05-09 13:17:54 -0700560 volatile boolean mAwake;
Jeff Brown3ee549c2014-09-22 20:14:39 -0700561 boolean mScreenOnEarly;
562 boolean mScreenOnFully;
563 ScreenOnListener mScreenOnListener;
564 boolean mKeyguardDrawComplete;
565 boolean mWindowManagerDrawComplete;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800566 boolean mOrientationSensorEnabled = false;
567 int mCurrentAppOrientation = ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800568 boolean mHasSoftInput = false;
Daniel Sandlerdd73ee42013-10-11 22:19:59 -0400569 boolean mTranslucentDecorEnabled = true;
RoboErik001c59c2015-01-26 15:53:51 -0800570 boolean mUseTvRouting;
Craig Mautner967212c2013-04-13 21:10:58 -0700571
Karthik Ravi Shankar86ecf342017-04-28 15:35:58 -0700572 private boolean mHandleVolumeKeysInWM;
573
Jeff Brown70825162012-03-28 17:27:48 -0700574 int mPointerLocationMode = 0; // guarded by mLock
Joe Onorato664644d2011-01-23 17:53:23 -0800575
576 // The last window we were told about in focusChanged.
577 WindowState mFocusedWindow;
Dianne Hackborne0f085d2011-11-30 18:41:15 -0800578 IApplicationToken mFocusedApp;
Joe Onorato664644d2011-01-23 17:53:23 -0800579
Jeff Brown70825162012-03-28 17:27:48 -0700580 PointerLocationView mPointerLocationView;
Jeff Brown32cbc38552011-12-01 14:01:49 -0800581
Dianne Hackbornc652de82013-02-15 16:32:56 -0800582 // The current size of the screen; really; extends into the overscan area of
583 // the screen and doesn't account for any system elements like the status bar.
584 int mOverscanScreenLeft, mOverscanScreenTop;
585 int mOverscanScreenWidth, mOverscanScreenHeight;
586 // The current visible size of the screen; really; (ir)regardless of whether the status
587 // bar can be hidden but not extending into the overscan area.
Joe Onorato29fc2c92010-11-24 10:26:50 -0800588 int mUnrestrictedScreenLeft, mUnrestrictedScreenTop;
589 int mUnrestrictedScreenWidth, mUnrestrictedScreenHeight;
Dianne Hackborn313440842013-02-19 19:22:59 -0800590 // Like mOverscanScreen*, but allowed to move into the overscan region where appropriate.
591 int mRestrictedOverscanScreenLeft, mRestrictedOverscanScreenTop;
592 int mRestrictedOverscanScreenWidth, mRestrictedOverscanScreenHeight;
Dianne Hackborn82de1ae2010-10-28 11:28:39 -0700593 // The current size of the screen; these may be different than (0,0)-(dw,dh)
594 // if the status bar can't be hidden; in that case it effectively carves out
595 // that area of the display from all other windows.
Joe Onorato29fc2c92010-11-24 10:26:50 -0800596 int mRestrictedScreenLeft, mRestrictedScreenTop;
597 int mRestrictedScreenWidth, mRestrictedScreenHeight;
Dianne Hackborn5c58de32012-04-28 19:52:37 -0700598 // During layout, the current screen borders accounting for any currently
599 // visible system UI elements.
600 int mSystemLeft, mSystemTop, mSystemRight, mSystemBottom;
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -0700601 // For applications requesting stable content insets, these are them.
602 int mStableLeft, mStableTop, mStableRight, mStableBottom;
Dianne Hackborn5b5cc4d2012-05-16 13:15:00 -0700603 // For applications requesting stable content insets but have also set the
604 // fullscreen window flag, these are the stable dimensions without the status bar.
605 int mStableFullscreenLeft, mStableFullscreenTop;
606 int mStableFullscreenRight, mStableFullscreenBottom;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800607 // During layout, the current screen borders with all outer decoration
608 // (status bar, input method dock) accounted for.
609 int mCurLeft, mCurTop, mCurRight, mCurBottom;
610 // During layout, the frame in which content should be displayed
611 // to the user, accounting for all screen decoration except for any
612 // space they deem as available for other content. This is usually
613 // the same as mCur*, but may be larger if the screen decor has supplied
614 // content insets.
615 int mContentLeft, mContentTop, mContentRight, mContentBottom;
Dianne Hackborne30e02f2014-05-27 18:24:45 -0700616 // During layout, the frame in which voice content should be displayed
617 // to the user, accounting for all screen decoration except for any
618 // space they deem as available for other content.
619 int mVoiceContentLeft, mVoiceContentTop, mVoiceContentRight, mVoiceContentBottom;
Dianne Hackborn8e11ef02010-11-18 19:47:42 -0800620 // During layout, the current screen borders along which input method
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800621 // windows are placed.
622 int mDockLeft, mDockTop, mDockRight, mDockBottom;
623 // During layout, the layer at which the doc window is placed.
624 int mDockLayer;
Dianne Hackborn5c58de32012-04-28 19:52:37 -0700625 // During layout, this is the layer of the status bar.
626 int mStatusBarLayer;
Dianne Hackborne26ab702011-10-16 13:21:33 -0700627 int mLastSystemUiFlags;
628 // Bits that we are in the process of clearing, so we want to prevent
629 // them from being set by applications until everything has been updated
630 // to have them clear.
631 int mResettingSystemUiFlags = 0;
632 // Bits that we are currently always keeping cleared.
633 int mForceClearedSystemUiFlags = 0;
Jorim Jaggi86905582016-02-09 21:36:09 -0800634 int mLastFullscreenStackSysUiFlags;
635 int mLastDockedStackSysUiFlags;
636 final Rect mNonDockedStackBounds = new Rect();
637 final Rect mDockedStackBounds = new Rect();
638 final Rect mLastNonDockedStackBounds = new Rect();
639 final Rect mLastDockedStackBounds = new Rect();
640
Dianne Hackborn4eff8d32011-11-10 19:38:40 -0800641 // What we last reported to system UI about whether the compatibility
642 // menu needs to be displayed.
643 boolean mLastFocusNeedsMenu = false;
Adrian Roosddc8b272015-05-21 16:28:27 -0700644 // If nonzero, a panic gesture was performed at that time in uptime millis and is still pending.
645 private long mPendingPanicGestureUptime;
Dianne Hackborndf89e652011-10-06 22:35:11 -0700646
Selim Cinekf83e8242015-05-19 18:08:14 -0700647 InputConsumer mInputConsumer = null;
Dianne Hackborndf89e652011-10-06 22:35:11 -0700648
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800649 static final Rect mTmpParentFrame = new Rect();
650 static final Rect mTmpDisplayFrame = new Rect();
Dianne Hackbornc4aad012013-02-22 15:05:25 -0800651 static final Rect mTmpOverscanFrame = new Rect();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800652 static final Rect mTmpContentFrame = new Rect();
653 static final Rect mTmpVisibleFrame = new Rect();
John Spurlock46646232013-09-30 22:32:42 -0400654 static final Rect mTmpDecorFrame = new Rect();
Adrian Roosfa104232014-06-20 16:10:14 -0700655 static final Rect mTmpStableFrame = new Rect();
Dianne Hackborn1f903c32011-09-13 19:18:06 -0700656 static final Rect mTmpNavigationFrame = new Rect();
Filip Gruszczynski2217f612015-05-26 11:32:08 -0700657 static final Rect mTmpOutsetFrame = new Rect();
Jorim Jaggi23bf5462016-05-13 15:24:39 -0700658 private static final Rect mTmpRect = new Rect();
Craig Mautner967212c2013-04-13 21:10:58 -0700659
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800660 WindowState mTopFullscreenOpaqueWindowState;
Adrian Rooscd3884d2015-02-18 17:25:23 +0100661 WindowState mTopFullscreenOpaqueOrDimmingWindowState;
Jorim Jaggi86905582016-02-09 21:36:09 -0800662 WindowState mTopDockedOpaqueWindowState;
663 WindowState mTopDockedOpaqueOrDimmingWindowState;
Joe Onorato93056472010-09-10 10:30:46 -0400664 boolean mTopIsFullscreen;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800665 boolean mForceStatusBar;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -0700666 boolean mForceStatusBarFromKeyguard;
Selim Cinek4a4a2bddc2015-05-07 12:50:19 -0700667 private boolean mForceStatusBarTransparent;
Yorke Lee9b2ffb32016-03-07 20:42:01 -0800668 int mNavBarOpacityMode = NAV_BAR_OPAQUE_WHEN_FREEFORM_OR_DOCKED;
Dianne Hackborn891d3fb2013-01-09 18:31:37 -0800669 boolean mForcingShowNavBar;
670 int mForcingShowNavBarLayer;
Craig Mautnerad09bcc2012-10-08 13:33:11 -0700671
Jorim Jaggife762342016-10-13 14:33:27 +0200672 private boolean mPendingKeyguardOccluded;
673 private boolean mKeyguardOccludedChanged;
Craig Mautnerc9457fa2014-06-06 14:27:48 -0700674
Dianne Hackborn7ad44382012-10-18 17:46:00 -0700675 boolean mShowingDream;
Jorim Jaggi77e10432016-10-26 17:43:56 -0700676 private boolean mLastShowingDream;
Dianne Hackborn7ad44382012-10-18 17:46:00 -0700677 boolean mDreamingLockscreen;
Jeff Brown061ea992015-04-17 19:55:47 -0700678 boolean mDreamingSleepTokenNeeded;
679 SleepToken mDreamingSleepToken;
Jeff Brown48d1b142015-06-10 16:36:03 -0700680 SleepToken mScreenOffSleepToken;
Jim Millerab954542014-10-10 18:21:49 -0700681 volatile boolean mKeyguardOccluded;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800682 boolean mHomePressed;
Jeff Browncaca8812013-05-09 13:34:33 -0700683 boolean mHomeConsumed;
684 boolean mHomeDoubleTapPending;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800685 Intent mHomeIntent;
Dianne Hackborn39c2d712009-09-22 11:41:31 -0700686 Intent mCarDockIntent;
687 Intent mDeskDockIntent;
Zak Cohendb6ca492017-01-26 14:09:00 -0800688 Intent mVrHeadsetHomeIntent;
Jeff Brownfd23e3e2012-05-09 13:34:28 -0700689 boolean mSearchKeyShortcutPending;
690 boolean mConsumeSearchKeyUp;
Jeff Brownde7a8ea2012-06-13 18:28:57 -0700691 boolean mAssistKeyLongPressed;
Michael Wright6a62e552014-06-03 19:19:48 -0700692 boolean mPendingMetaAction;
Andrii Kulian112d0562016-03-08 10:44:22 -0800693 boolean mPendingCapsLockToggle;
694 int mMetaState;
695 int mInitialMetaState;
Jorim Jaggi0ffd49c2016-02-12 15:04:21 -0800696 boolean mForceShowSystemBars;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800697
Mike Lockwood28569302010-01-28 11:54:40 -0500698 // support for activating the lock screen while the screen is on
699 boolean mAllowLockscreenWhenOn;
700 int mLockScreenTimeout;
701 boolean mLockScreenTimerActive;
702
David Brownbaf8d092010-03-08 21:52:59 -0800703 // Behavior of ENDCALL Button. (See Settings.System.END_BUTTON_BEHAVIOR.)
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800704 int mEndcallBehavior;
David Brownbaf8d092010-03-08 21:52:59 -0800705
706 // Behavior of POWER button while in-call and screen on.
707 // (See Settings.Secure.INCALL_POWER_BUTTON_BEHAVIOR.)
708 int mIncallPowerBehavior;
709
Bryce Leedb776ce2016-09-03 15:02:00 -0700710 // Behavior of Back button while in-call and screen on
711 int mIncallBackBehavior;
712
Dianne Hackbornf87d1962012-04-04 12:48:24 -0700713 Display mDisplay;
714
Filip Gruszczynski2987f612015-06-30 15:03:30 -0700715 private int mDisplayRotation;
716
Dianne Hackborn9d132642011-04-21 17:26:39 -0700717 int mLandscapeRotation = 0; // default landscape rotation
718 int mSeascapeRotation = 0; // "other" landscape rotation, 180 degrees from mLandscapeRotation
719 int mPortraitRotation = 0; // default portrait rotation
720 int mUpsideDownRotation = 0; // "other" portrait rotation
Mitsuru Oshima831d0d92009-06-16 18:27:18 -0700721
Dianne Hackbornc652de82013-02-15 16:32:56 -0800722 int mOverscanLeft = 0;
723 int mOverscanTop = 0;
724 int mOverscanRight = 0;
725 int mOverscanBottom = 0;
726
Joe Onorato46b0d682010-11-22 17:37:27 -0800727 // What we do when the user long presses on home
Jeff Browncaca8812013-05-09 13:34:33 -0700728 private int mLongPressOnHomeBehavior;
729
730 // What we do when the user double-taps on home
731 private int mDoubleTapOnHomeBehavior;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800732
Bryce Lee584a4452014-10-21 15:55:55 -0700733 // Allowed theater mode wake actions
734 private boolean mAllowTheaterModeWakeFromKey;
735 private boolean mAllowTheaterModeWakeFromPowerKey;
736 private boolean mAllowTheaterModeWakeFromMotion;
Bryce Lee812d7022014-11-10 13:33:28 -0800737 private boolean mAllowTheaterModeWakeFromMotionWhenNotDreaming;
Bryce Lee584a4452014-10-21 15:55:55 -0700738 private boolean mAllowTheaterModeWakeFromCameraLens;
739 private boolean mAllowTheaterModeWakeFromLidSwitch;
740 private boolean mAllowTheaterModeWakeFromWakeGesture;
741
Bryce Leed3b28402015-03-09 15:49:13 +0000742 // Whether to support long press from power button in non-interactive mode
743 private boolean mSupportLongPressPowerWhenNonInteractive;
744
Bryce Lee55e846d2014-11-04 12:43:44 -0800745 // Whether to go to sleep entering theater mode from power button
746 private boolean mGoToSleepOnButtonPressTheaterMode;
747
Winson Chung9112ec32011-06-27 13:15:32 -0700748 // Screenshot trigger states
Jeff Brownd5bb82d2011-10-12 13:57:59 -0700749 // Time to volume and power must be pressed within this interval of each other.
750 private static final long SCREENSHOT_CHORD_DEBOUNCE_DELAY_MILLIS = 150;
Winson Chung1cea2f32012-10-08 20:42:01 -0700751 // Increase the chord delay when taking a screenshot from the keyguard
752 private static final float KEYGUARD_SCREENSHOT_CHORD_DELAY_MULTIPLIER = 2.5f;
Christopher Tatee90585f2012-03-05 18:56:25 -0800753 private boolean mScreenshotChordEnabled;
Jeff Brown13f00f02014-10-31 14:45:50 -0700754 private boolean mScreenshotChordVolumeDownKeyTriggered;
755 private long mScreenshotChordVolumeDownKeyTime;
756 private boolean mScreenshotChordVolumeDownKeyConsumed;
Phil Weaver106fe732016-11-22 18:18:39 -0800757 private boolean mA11yShortcutChordVolumeUpKeyTriggered;
758 private long mA11yShortcutChordVolumeUpKeyTime;
759 private boolean mA11yShortcutChordVolumeUpKeyConsumed;
760
Jeff Brown13f00f02014-10-31 14:45:50 -0700761 private boolean mScreenshotChordPowerKeyTriggered;
762 private long mScreenshotChordPowerKeyTime;
Winson Chung9112ec32011-06-27 13:15:32 -0700763
Dmitri Plotnikov82e6dfc2017-02-24 18:10:54 -0800764 private static final long BUGREPORT_TV_GESTURE_TIMEOUT_MILLIS = 1000;
765
766 private boolean mBugreportTvKey1Pressed;
767 private boolean mBugreportTvKey2Pressed;
768 private boolean mBugreportTvScheduled;
769
Sujith Ramakrishnan6bed9bd2017-04-26 12:33:37 -0700770 private boolean mAccessibilityTvKey1Pressed;
771 private boolean mAccessibilityTvKey2Pressed;
772 private boolean mAccessibilityTvScheduled;
773
Michael Wrightb854e242013-02-05 17:54:02 -0800774 /* The number of steps between min and max brightness */
775 private static final int BRIGHTNESS_STEPS = 10;
776
Christopher Tate5e08af02012-09-21 17:17:22 -0700777 SettingsObserver mSettingsObserver;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800778 ShortcutManager mShortcutManager;
779 PowerManager.WakeLock mBroadcastWakeLock;
Jeff Brown13f00f02014-10-31 14:45:50 -0700780 PowerManager.WakeLock mPowerKeyWakeLock;
Jeff Brown40013652012-05-16 21:22:36 -0700781 boolean mHavePendingMediaKeyRepeatWithWakeLock;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800782
Craig Mautnerd625ab22013-09-06 13:40:31 -0700783 private int mCurrentUserId;
784
Justin Kohd378ad72013-04-01 12:18:26 -0700785 // Maps global key codes to the components that will handle them.
786 private GlobalKeyManager mGlobalKeyManager;
787
Jeff Brownfd23e3e2012-05-09 13:34:28 -0700788 // Fallback actions by key code.
789 private final SparseArray<KeyCharacterMap.FallbackAction> mFallbackActions =
790 new SparseArray<KeyCharacterMap.FallbackAction>();
Jeff Brown49ed71d2010-12-06 17:13:33 -0800791
Jorim Jaggi76a16232014-08-08 17:00:47 +0200792 private final LogDecelerateInterpolator mLogDecelerateInterpolator
793 = new LogDecelerateInterpolator(100, 0);
794
Jorim Jaggif1cdf952016-04-05 21:41:06 -0700795 private final MutableBoolean mTmpBoolean = new MutableBoolean(false);
Wale Ogunwale6b15ea52016-04-04 07:28:27 -0700796
Jeff Brown70825162012-03-28 17:27:48 -0700797 private static final int MSG_ENABLE_POINTER_LOCATION = 1;
798 private static final int MSG_DISABLE_POINTER_LOCATION = 2;
Jeff Brown40013652012-05-16 21:22:36 -0700799 private static final int MSG_DISPATCH_MEDIA_KEY_WITH_WAKE_LOCK = 3;
800 private static final int MSG_DISPATCH_MEDIA_KEY_REPEAT_WITH_WAKE_LOCK = 4;
Craig Mautner8a0da012014-05-31 15:13:37 -0700801 private static final int MSG_KEYGUARD_DRAWN_COMPLETE = 5;
802 private static final int MSG_KEYGUARD_DRAWN_TIMEOUT = 6;
803 private static final int MSG_WINDOW_MANAGER_DRAWN_COMPLETE = 7;
Craig Mautner84984fa2014-06-19 11:19:20 -0700804 private static final int MSG_DISPATCH_SHOW_RECENTS = 9;
Alan Viverettee34560b22014-07-10 14:50:06 -0700805 private static final int MSG_DISPATCH_SHOW_GLOBAL_ACTIONS = 10;
Craig Mautnera631d492014-08-05 15:16:01 -0700806 private static final int MSG_HIDE_BOOT_MESSAGE = 11;
Michael Wright869a67c2014-08-26 19:33:06 -0700807 private static final int MSG_LAUNCH_VOICE_ASSIST_WITH_WAKE_LOCK = 12;
Jeff Brown13f00f02014-10-31 14:45:50 -0700808 private static final int MSG_POWER_DELAYED_PRESS = 13;
809 private static final int MSG_POWER_LONG_PRESS = 14;
Jeff Brown061ea992015-04-17 19:55:47 -0700810 private static final int MSG_UPDATE_DREAMING_SLEEP_TOKEN = 15;
Jun Mukaid2e7e352015-07-22 17:14:02 -0700811 private static final int MSG_REQUEST_TRANSIENT_BARS = 16;
Winson Chungac52f282017-03-30 14:44:52 -0700812 private static final int MSG_SHOW_PICTURE_IN_PICTURE_MENU = 17;
Anthony Hugh34f09ca2016-03-04 12:03:37 -0800813 private static final int MSG_BACK_LONG_PRESS = 18;
Chong Zhang9f7fb092016-05-20 17:03:08 -0700814 private static final int MSG_DISPOSE_INPUT_CONSUMER = 19;
Anthony Hugh96e9cc52016-07-12 15:17:24 -0700815 private static final int MSG_BACK_DELAYED_PRESS = 20;
Phil Weaver106fe732016-11-22 18:18:39 -0800816 private static final int MSG_ACCESSIBILITY_SHORTCUT = 21;
Dmitri Plotnikov82e6dfc2017-02-24 18:10:54 -0800817 private static final int MSG_BUGREPORT_TV = 22;
Sujith Ramakrishnan6bed9bd2017-04-26 12:33:37 -0700818 private static final int MSG_ACCESSIBILITY_TV = 23;
Felipe Leme5f978802017-06-08 13:01:13 -0700819 private static final int MSG_DISPATCH_BACK_KEY_TO_AUTOFILL = 24;
Philip Quinn4b5b3c62017-07-20 21:07:58 -0700820 private static final int MSG_SYSTEM_KEY_PRESS = 25;
Jun Mukaid2e7e352015-07-22 17:14:02 -0700821
822 private static final int MSG_REQUEST_TRANSIENT_BARS_ARG_STATUS = 0;
823 private static final int MSG_REQUEST_TRANSIENT_BARS_ARG_NAVIGATION = 1;
Jeff Brown70825162012-03-28 17:27:48 -0700824
825 private class PolicyHandler extends Handler {
826 @Override
827 public void handleMessage(Message msg) {
828 switch (msg.what) {
829 case MSG_ENABLE_POINTER_LOCATION:
830 enablePointerLocation();
831 break;
832 case MSG_DISABLE_POINTER_LOCATION:
833 disablePointerLocation();
834 break;
Jeff Brown40013652012-05-16 21:22:36 -0700835 case MSG_DISPATCH_MEDIA_KEY_WITH_WAKE_LOCK:
836 dispatchMediaKeyWithWakeLock((KeyEvent)msg.obj);
837 break;
838 case MSG_DISPATCH_MEDIA_KEY_REPEAT_WITH_WAKE_LOCK:
839 dispatchMediaKeyRepeatWithWakeLock((KeyEvent)msg.obj);
840 break;
Craig Mautner84984fa2014-06-19 11:19:20 -0700841 case MSG_DISPATCH_SHOW_RECENTS:
Jorim Jaggi681fc7b2016-04-14 22:02:39 -0700842 showRecentApps(false, msg.arg1 != 0);
Craig Mautner84984fa2014-06-19 11:19:20 -0700843 break;
Alan Viverettee34560b22014-07-10 14:50:06 -0700844 case MSG_DISPATCH_SHOW_GLOBAL_ACTIONS:
845 showGlobalActionsInternal();
846 break;
Craig Mautner8a0da012014-05-31 15:13:37 -0700847 case MSG_KEYGUARD_DRAWN_COMPLETE:
848 if (DEBUG_WAKEUP) Slog.w(TAG, "Setting mKeyguardDrawComplete");
Jeff Brown36c4db82014-09-19 12:05:31 -0700849 finishKeyguardDrawn();
Craig Mautner8a0da012014-05-31 15:13:37 -0700850 break;
851 case MSG_KEYGUARD_DRAWN_TIMEOUT:
852 Slog.w(TAG, "Keyguard drawn timeout. Setting mKeyguardDrawComplete");
Jeff Brown36c4db82014-09-19 12:05:31 -0700853 finishKeyguardDrawn();
Craig Mautner8a0da012014-05-31 15:13:37 -0700854 break;
855 case MSG_WINDOW_MANAGER_DRAWN_COMPLETE:
856 if (DEBUG_WAKEUP) Slog.w(TAG, "Setting mWindowManagerDrawComplete");
Jeff Brown36c4db82014-09-19 12:05:31 -0700857 finishWindowsDrawn();
Craig Mautner8a0da012014-05-31 15:13:37 -0700858 break;
Craig Mautnera631d492014-08-05 15:16:01 -0700859 case MSG_HIDE_BOOT_MESSAGE:
860 handleHideBootMessage();
861 break;
Michael Wright869a67c2014-08-26 19:33:06 -0700862 case MSG_LAUNCH_VOICE_ASSIST_WITH_WAKE_LOCK:
863 launchVoiceAssistWithWakeLock(msg.arg1 != 0);
864 break;
Jeff Brown13f00f02014-10-31 14:45:50 -0700865 case MSG_POWER_DELAYED_PRESS:
866 powerPress((Long)msg.obj, msg.arg1 != 0, msg.arg2);
867 finishPowerKeyPress();
868 break;
869 case MSG_POWER_LONG_PRESS:
870 powerLongPress();
871 break;
Jeff Brown061ea992015-04-17 19:55:47 -0700872 case MSG_UPDATE_DREAMING_SLEEP_TOKEN:
873 updateDreamingSleepToken(msg.arg1 != 0);
874 break;
Jun Mukaid2e7e352015-07-22 17:14:02 -0700875 case MSG_REQUEST_TRANSIENT_BARS:
876 WindowState targetBar = (msg.arg1 == MSG_REQUEST_TRANSIENT_BARS_ARG_STATUS) ?
877 mStatusBar : mNavigationBar;
878 if (targetBar != null) {
879 requestTransientBars(targetBar);
880 }
881 break;
Winson Chungac52f282017-03-30 14:44:52 -0700882 case MSG_SHOW_PICTURE_IN_PICTURE_MENU:
883 showPictureInPictureMenuInternal();
Jaewan Kimc552b042016-01-18 16:08:45 +0900884 break;
Anthony Hugh34f09ca2016-03-04 12:03:37 -0800885 case MSG_BACK_LONG_PRESS:
886 backLongPress();
Anthony Hugh96e9cc52016-07-12 15:17:24 -0700887 finishBackKeyPress();
Anthony Hugh34f09ca2016-03-04 12:03:37 -0800888 break;
Chong Zhang9f7fb092016-05-20 17:03:08 -0700889 case MSG_DISPOSE_INPUT_CONSUMER:
890 disposeInputConsumer((InputConsumer) msg.obj);
891 break;
Anthony Hugh96e9cc52016-07-12 15:17:24 -0700892 case MSG_BACK_DELAYED_PRESS:
893 backMultiPressAction((Long) msg.obj, msg.arg1);
894 finishBackKeyPress();
895 break;
Phil Weaver106fe732016-11-22 18:18:39 -0800896 case MSG_ACCESSIBILITY_SHORTCUT:
897 accessibilityShortcutActivated();
898 break;
Dmitri Plotnikov82e6dfc2017-02-24 18:10:54 -0800899 case MSG_BUGREPORT_TV:
900 takeBugreport();
901 break;
Sujith Ramakrishnan6bed9bd2017-04-26 12:33:37 -0700902 case MSG_ACCESSIBILITY_TV:
903 if (mAccessibilityShortcutController.isAccessibilityShortcutAvailable(false)) {
904 accessibilityShortcutActivated();
905 }
906 break;
Felipe Leme5f978802017-06-08 13:01:13 -0700907 case MSG_DISPATCH_BACK_KEY_TO_AUTOFILL:
908 mAutofillManagerInternal.onBackKeyPressed();
909 break;
Philip Quinn4b5b3c62017-07-20 21:07:58 -0700910 case MSG_SYSTEM_KEY_PRESS:
911 sendSystemKeyToStatusBar(msg.arg1);
912 break;
Jeff Brown70825162012-03-28 17:27:48 -0700913 }
914 }
915 }
916
Dianne Hackbornad7fa7f2011-01-07 14:06:50 -0800917 private UEventObserver mHDMIObserver = new UEventObserver() {
918 @Override
919 public void onUEvent(UEventObserver.UEvent event) {
920 setHdmiPlugged("1".equals(event.get("SWITCH_STATE")));
921 }
922 };
923
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800924 class SettingsObserver extends ContentObserver {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800925 SettingsObserver(Handler handler) {
926 super(handler);
927 }
David Brownbaf8d092010-03-08 21:52:59 -0800928
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800929 void observe() {
Christopher Tate5e08af02012-09-21 17:17:22 -0700930 // Observe all users' changes
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800931 ContentResolver resolver = mContext.getContentResolver();
932 resolver.registerContentObserver(Settings.System.getUriFor(
Christopher Tate5e08af02012-09-21 17:17:22 -0700933 Settings.System.END_BUTTON_BEHAVIOR), false, this,
934 UserHandle.USER_ALL);
David Brownbaf8d092010-03-08 21:52:59 -0800935 resolver.registerContentObserver(Settings.Secure.getUriFor(
Christopher Tate5e08af02012-09-21 17:17:22 -0700936 Settings.Secure.INCALL_POWER_BUTTON_BEHAVIOR), false, this,
937 UserHandle.USER_ALL);
Jeff Browna20dda42014-05-27 20:57:24 -0700938 resolver.registerContentObserver(Settings.Secure.getUriFor(
Bryce Leedb776ce2016-09-03 15:02:00 -0700939 Settings.Secure.INCALL_BACK_BUTTON_BEHAVIOR), false, this,
940 UserHandle.USER_ALL);
941 resolver.registerContentObserver(Settings.Secure.getUriFor(
Jeff Browna20dda42014-05-27 20:57:24 -0700942 Settings.Secure.WAKE_GESTURE_ENABLED), false, this,
943 UserHandle.USER_ALL);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800944 resolver.registerContentObserver(Settings.System.getUriFor(
Christopher Tate5e08af02012-09-21 17:17:22 -0700945 Settings.System.ACCELEROMETER_ROTATION), false, this,
946 UserHandle.USER_ALL);
Mike Lockwood28569302010-01-28 11:54:40 -0500947 resolver.registerContentObserver(Settings.System.getUriFor(
Christopher Tate5e08af02012-09-21 17:17:22 -0700948 Settings.System.USER_ROTATION), false, this,
949 UserHandle.USER_ALL);
Daniel Sandlerb73617d2010-08-17 00:41:00 -0400950 resolver.registerContentObserver(Settings.System.getUriFor(
Christopher Tate5e08af02012-09-21 17:17:22 -0700951 Settings.System.SCREEN_OFF_TIMEOUT), false, this,
952 UserHandle.USER_ALL);
Dianne Hackbornc777e072010-02-12 13:07:59 -0800953 resolver.registerContentObserver(Settings.System.getUriFor(
Christopher Tate5e08af02012-09-21 17:17:22 -0700954 Settings.System.POINTER_LOCATION), false, this,
955 UserHandle.USER_ALL);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800956 resolver.registerContentObserver(Settings.Secure.getUriFor(
Christopher Tate5e08af02012-09-21 17:17:22 -0700957 Settings.Secure.DEFAULT_INPUT_METHOD), false, this,
958 UserHandle.USER_ALL);
John Spurlockd9b70bd2014-02-06 17:02:44 -0500959 resolver.registerContentObserver(Settings.Secure.getUriFor(
John Spurlockf1a36642013-10-12 17:50:42 -0400960 Settings.Secure.IMMERSIVE_MODE_CONFIRMATIONS), false, this,
Christopher Tate5e08af02012-09-21 17:17:22 -0700961 UserHandle.USER_ALL);
John Spurlockc6d1c602014-01-17 15:22:06 -0500962 resolver.registerContentObserver(Settings.Global.getUriFor(
963 Settings.Global.POLICY_CONTROL), false, this,
964 UserHandle.USER_ALL);
Dianne Hackbornc777e072010-02-12 13:07:59 -0800965 updateSettings();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800966 }
967
968 @Override public void onChange(boolean selfChange) {
Dianne Hackbornc777e072010-02-12 13:07:59 -0800969 updateSettings();
Jeff Brown01a98dd2011-09-20 15:08:29 -0700970 updateRotation(false);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800971 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800972 }
Craig Mautner967212c2013-04-13 21:10:58 -0700973
Jeff Browna20dda42014-05-27 20:57:24 -0700974 class MyWakeGestureListener extends WakeGestureListener {
975 MyWakeGestureListener(Context context, Handler handler) {
976 super(context, handler);
977 }
978
979 @Override
980 public void onWakeUp() {
981 synchronized (mLock) {
982 if (shouldEnableWakeGestureLp()) {
Jeff Browne07b94b2014-06-18 15:56:27 -0700983 performHapticFeedbackLw(null, HapticFeedbackConstants.VIRTUAL_KEY, false);
Dianne Hackborn280a64e2015-07-13 14:48:08 -0700984 wakeUp(SystemClock.uptimeMillis(), mAllowTheaterModeWakeFromWakeGesture,
985 "android.policy:GESTURE");
Jeff Browna20dda42014-05-27 20:57:24 -0700986 }
987 }
988 }
989 }
990
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800991 class MyOrientationListener extends WindowOrientationListener {
Chong Zhang5aaa0b32015-08-28 10:22:36 -0700992 private final Runnable mUpdateRotationRunnable = new Runnable() {
993 @Override
994 public void run() {
Tim Murray1f407642015-10-01 17:07:12 -0700995 // send interaction hint to improve redraw performance
Ruchi Kandoi0d434042016-10-03 09:12:02 -0700996 mPowerManagerInternal.powerHint(PowerHint.INTERACTION, 0);
Chong Zhang5aaa0b32015-08-28 10:22:36 -0700997 updateRotation(false);
998 }
999 };
1000
Craig Mautnereee29c42013-01-17 14:44:34 -08001001 MyOrientationListener(Context context, Handler handler) {
1002 super(context, handler);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001003 }
Craig Mautner967212c2013-04-13 21:10:58 -07001004
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001005 @Override
Jeff Brownc0347aa2011-09-23 17:26:09 -07001006 public void onProposedRotationChanged(int rotation) {
Craig Mautnereda67292013-04-28 13:50:14 -07001007 if (localLOGV) Slog.v(TAG, "onProposedRotationChanged, rotation=" + rotation);
Chong Zhang5aaa0b32015-08-28 10:22:36 -07001008 mHandler.post(mUpdateRotationRunnable);
Jeff Brown01a98dd2011-09-20 15:08:29 -07001009 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001010 }
1011 MyOrientationListener mOrientationListener;
1012
Santos Cordonc09d89c2017-04-13 16:12:02 -07001013 final IPersistentVrStateCallbacks mPersistentVrModeListener =
1014 new IPersistentVrStateCallbacks.Stub() {
1015 @Override
1016 public void onPersistentVrStateChanged(boolean enabled) {
1017 mPersistentVrModeEnabled = enabled;
1018 }
1019 };
1020
Jorim Jaggi24bec7c2015-02-04 12:40:14 +01001021 private final StatusBarController mStatusBarController = new StatusBarController();
John Spurlock5b9145b2013-08-20 15:13:47 -04001022
John Spurlock27735a42013-08-14 17:57:38 -04001023 private final BarController mNavigationBarController = new BarController("NavigationBar",
John Spurlock5b9145b2013-08-20 15:13:47 -04001024 View.NAVIGATION_BAR_TRANSIENT,
1025 View.NAVIGATION_BAR_UNHIDE,
John Spurlockbd957402013-10-03 11:38:39 -04001026 View.NAVIGATION_BAR_TRANSLUCENT,
1027 StatusBarManager.WINDOW_NAVIGATION_BAR,
Jorim Jaggi4fa78922015-11-30 17:13:56 -08001028 WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION,
1029 View.NAVIGATION_BAR_TRANSPARENT);
John Spurlock5b9145b2013-08-20 15:13:47 -04001030
Casey Burkhardt048c2bc2016-12-08 16:09:20 -08001031 private final BarController.OnBarVisibilityChangedListener mNavBarVisibilityListener =
1032 new BarController.OnBarVisibilityChangedListener() {
1033 @Override
1034 public void onBarVisibilityChanged(boolean visible) {
Casey Burkhardt469a2082017-06-13 20:12:42 -07001035 mAccessibilityManager.notifyAccessibilityButtonVisibilityChanged(visible);
Casey Burkhardt048c2bc2016-12-08 16:09:20 -08001036 }
1037 };
1038
John Spurlockf1a36642013-10-12 17:50:42 -04001039 private ImmersiveModeConfirmation mImmersiveModeConfirmation;
John Spurlock32beb2c2013-03-11 10:16:47 -04001040
Craig Mautner037aa8d2013-06-07 10:35:44 -07001041 private SystemGesturesPointerEventListener mSystemGestures;
John Spurlock32beb2c2013-03-11 10:16:47 -04001042
Dianne Hackborn42e620c2012-06-24 13:20:51 -07001043 IStatusBarService getStatusBarService() {
1044 synchronized (mServiceAquireLock) {
1045 if (mStatusBarService == null) {
1046 mStatusBarService = IStatusBarService.Stub.asInterface(
1047 ServiceManager.getService("statusbar"));
1048 }
1049 return mStatusBarService;
1050 }
1051 }
1052
Jorim Jaggi86905582016-02-09 21:36:09 -08001053 StatusBarManagerInternal getStatusBarManagerInternal() {
1054 synchronized (mServiceAquireLock) {
1055 if (mStatusBarManagerInternal == null) {
1056 mStatusBarManagerInternal =
1057 LocalServices.getService(StatusBarManagerInternal.class);
1058 }
1059 return mStatusBarManagerInternal;
1060 }
1061 }
1062
Suchi Amalapurapua9e1b162009-03-24 22:24:47 -07001063 /*
1064 * We always let the sensor be switched on by default except when
1065 * the user has explicitly disabled sensor based rotation or when the
1066 * screen is switched off.
1067 */
The Android Open Source Project0727d222009-03-11 12:11:58 -07001068 boolean needSensorRunningLp() {
Jeff Brownbcdfc622014-03-06 19:13:04 -08001069 if (mSupportAutoRotation) {
1070 if (mCurrentAppOrientation == ActivityInfo.SCREEN_ORIENTATION_SENSOR
1071 || mCurrentAppOrientation == ActivityInfo.SCREEN_ORIENTATION_FULL_SENSOR
1072 || mCurrentAppOrientation == ActivityInfo.SCREEN_ORIENTATION_SENSOR_PORTRAIT
1073 || mCurrentAppOrientation == ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE) {
1074 // If the application has explicitly requested to follow the
1075 // orientation, then we need to turn the sensor on.
1076 return true;
1077 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001078 }
Dianne Hackborn867ab6472010-04-29 13:28:56 -07001079 if ((mCarDockEnablesAccelerometer && mDockMode == Intent.EXTRA_DOCK_STATE_CAR) ||
Jeff Brown1a693182011-11-08 14:44:16 -08001080 (mDeskDockEnablesAccelerometer && (mDockMode == Intent.EXTRA_DOCK_STATE_DESK
1081 || mDockMode == Intent.EXTRA_DOCK_STATE_LE_DESK
1082 || mDockMode == Intent.EXTRA_DOCK_STATE_HE_DESK))) {
Mike Lockwoode9867d22009-09-20 01:59:02 -04001083 // enable accelerometer if we are docked in a dock that enables accelerometer
1084 // orientation management,
1085 return true;
1086 }
Jeff Brown207673cd2012-06-05 17:47:11 -07001087 if (mUserRotationMode == USER_ROTATION_LOCKED) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001088 // If the setting for using the sensor by default is enabled, then
1089 // we will always leave it on. Note that the user could go to
1090 // a window that forces an orientation that does not use the
1091 // sensor and in theory we could turn it off... however, when next
1092 // turning it on we won't have a good value for the current
1093 // orientation for a little bit, which can cause orientation
1094 // changes to lag, so we'd like to keep it always on. (It will
1095 // still be turned off when the screen is off.)
Suchi Amalapurapua9e1b162009-03-24 22:24:47 -07001096 return false;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001097 }
Jeff Brownbcdfc622014-03-06 19:13:04 -08001098 return mSupportAutoRotation;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001099 }
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001100
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001101 /*
1102 * Various use cases for invoking this function
1103 * screen turning off, should always disable listeners if already enabled
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001104 * screen turned on and current app has sensor based orientation, enable listeners
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001105 * if not already enabled
1106 * screen turned on and current app does not have sensor orientation, disable listeners if
1107 * already enabled
1108 * screen turning on and current app has sensor based orientation, enable listeners if needed
1109 * screen turning on and current app has nosensor based orientation, do nothing
1110 */
The Android Open Source Project0727d222009-03-11 12:11:58 -07001111 void updateOrientationListenerLp() {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001112 if (!mOrientationListener.canDetectOrientation()) {
1113 // If sensor is turned off or nonexistent for some reason
1114 return;
1115 }
Stefan Kuhne9326dc12015-06-12 09:25:32 -10001116 // Could have been invoked due to screen turning on or off or
1117 // change of the currently visible window's orientation.
Jeff Brown3ee549c2014-09-22 20:14:39 -07001118 if (localLOGV) Slog.v(TAG, "mScreenOnEarly=" + mScreenOnEarly
1119 + ", mAwake=" + mAwake + ", mCurrentAppOrientation=" + mCurrentAppOrientation
Stefan Kuhne9326dc12015-06-12 09:25:32 -10001120 + ", mOrientationSensorEnabled=" + mOrientationSensorEnabled
1121 + ", mKeyguardDrawComplete=" + mKeyguardDrawComplete
1122 + ", mWindowManagerDrawComplete=" + mWindowManagerDrawComplete);
Wale Ogunwalebfa81ad2017-05-24 15:14:42 -07001123 final boolean keyguardGoingAway = mWindowManagerInternal.isKeyguardGoingAway();
1124
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001125 boolean disable = true;
Stefan Kuhne9326dc12015-06-12 09:25:32 -10001126 // Note: We postpone the rotating of the screen until the keyguard as well as the
Wale Ogunwalebfa81ad2017-05-24 15:14:42 -07001127 // window manager have reported a draw complete or the keyguard is going away in dismiss
1128 // mode.
1129 if (mScreenOnEarly && mAwake && ((mKeyguardDrawComplete && mWindowManagerDrawComplete)
1130 || keyguardGoingAway)) {
The Android Open Source Project0727d222009-03-11 12:11:58 -07001131 if (needSensorRunningLp()) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001132 disable = false;
1133 //enable listener if not already enabled
The Android Open Source Project0727d222009-03-11 12:11:58 -07001134 if (!mOrientationSensorEnabled) {
Wale Ogunwalebfa81ad2017-05-24 15:14:42 -07001135 // Don't clear the current sensor orientation if the keyguard is going away in
1136 // dismiss mode. This allows window manager to use the last sensor reading to
1137 // determine the orientation vs. falling back to the last known orientation if
1138 // the sensor reading was cleared which can cause it to relaunch the app that
1139 // will show in the wrong orientation first before correcting leading to app
1140 // launch delays.
1141 mOrientationListener.enable(!keyguardGoingAway /* clearCurrentRotation */);
Craig Mautnereda67292013-04-28 13:50:14 -07001142 if(localLOGV) Slog.v(TAG, "Enabling listeners");
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001143 mOrientationSensorEnabled = true;
1144 }
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001145 }
1146 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001147 //check if sensors need to be disabled
The Android Open Source Project0727d222009-03-11 12:11:58 -07001148 if (disable && mOrientationSensorEnabled) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001149 mOrientationListener.disable();
Craig Mautnereda67292013-04-28 13:50:14 -07001150 if(localLOGV) Slog.v(TAG, "Disabling listeners");
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001151 mOrientationSensorEnabled = false;
1152 }
1153 }
1154
Anthony Hugh96e9cc52016-07-12 15:17:24 -07001155 private void interceptBackKeyDown() {
Nimrod Gileadi580135c2016-10-31 20:42:19 +00001156 MetricsLogger.count(mContext, "key_back_down", 1);
Anthony Hugh96e9cc52016-07-12 15:17:24 -07001157 // Reset back key state for long press
1158 mBackKeyHandled = false;
1159
1160 // Cancel multi-press detection timeout.
1161 if (hasPanicPressOnBackBehavior()) {
1162 if (mBackKeyPressCounter != 0
1163 && mBackKeyPressCounter < PANIC_PRESS_BACK_COUNT) {
1164 mHandler.removeMessages(MSG_BACK_DELAYED_PRESS);
1165 }
1166 }
1167
1168 if (hasLongPressOnBackBehavior()) {
1169 Message msg = mHandler.obtainMessage(MSG_BACK_LONG_PRESS);
1170 msg.setAsynchronous(true);
1171 mHandler.sendMessageDelayed(msg,
1172 ViewConfiguration.get(mContext).getDeviceGlobalActionKeyTimeout());
1173 }
1174 }
1175
1176 // returns true if the key was handled and should not be passed to the user
1177 private boolean interceptBackKeyUp(KeyEvent event) {
1178 // Cache handled state
1179 boolean handled = mBackKeyHandled;
1180
1181 if (hasPanicPressOnBackBehavior()) {
1182 // Check for back key panic press
1183 ++mBackKeyPressCounter;
1184
1185 final long eventTime = event.getDownTime();
1186
1187 if (mBackKeyPressCounter <= PANIC_PRESS_BACK_COUNT) {
1188 // This could be a multi-press. Wait a little bit longer to confirm.
1189 Message msg = mHandler.obtainMessage(MSG_BACK_DELAYED_PRESS,
Bryce Leedb776ce2016-09-03 15:02:00 -07001190 mBackKeyPressCounter, 0, eventTime);
Anthony Hugh96e9cc52016-07-12 15:17:24 -07001191 msg.setAsynchronous(true);
1192 mHandler.sendMessageDelayed(msg, ViewConfiguration.getMultiPressTimeout());
1193 }
1194 }
1195
1196 // Reset back long press state
1197 cancelPendingBackKeyAction();
1198
Bryce Leedb776ce2016-09-03 15:02:00 -07001199 if (mHasFeatureWatch) {
1200 TelecomManager telecomManager = getTelecommService();
1201
1202 if (telecomManager != null) {
1203 if (telecomManager.isRinging()) {
1204 // Pressing back while there's a ringing incoming
1205 // call should silence the ringer.
1206 telecomManager.silenceRinger();
1207
1208 // It should not prevent navigating away
1209 return false;
1210 } else if (
1211 (mIncallBackBehavior & Settings.Secure.INCALL_BACK_BUTTON_BEHAVIOR_HANGUP) != 0
1212 && telecomManager.isInCall()) {
1213 // Otherwise, if "Back button ends call" is enabled,
1214 // the Back button will hang up any current active call.
1215 return telecomManager.endCall();
1216 }
1217 }
1218 }
1219
Felipe Leme5f978802017-06-08 13:01:13 -07001220 if (mAutofillManagerInternal != null && event.getKeyCode() == KeyEvent.KEYCODE_BACK) {
1221 mHandler.sendMessage(mHandler.obtainMessage(MSG_DISPATCH_BACK_KEY_TO_AUTOFILL));
1222 }
1223
Anthony Hugh96e9cc52016-07-12 15:17:24 -07001224 return handled;
1225 }
1226
Jeff Brown13f00f02014-10-31 14:45:50 -07001227 private void interceptPowerKeyDown(KeyEvent event, boolean interactive) {
1228 // Hold a wake lock until the power key is released.
1229 if (!mPowerKeyWakeLock.isHeld()) {
1230 mPowerKeyWakeLock.acquire();
1231 }
1232
1233 // Cancel multi-press detection timeout.
1234 if (mPowerKeyPressCounter != 0) {
1235 mHandler.removeMessages(MSG_POWER_DELAYED_PRESS);
1236 }
1237
1238 // Detect user pressing the power button in panic when an application has
1239 // taken over the whole screen.
1240 boolean panic = mImmersiveModeConfirmation.onPowerKeyDown(interactive,
Adrian Roos7aaa5512016-07-12 15:27:24 -07001241 SystemClock.elapsedRealtime(), isImmersiveMode(mLastSystemUiFlags),
1242 isNavBarEmpty(mLastSystemUiFlags));
Jeff Brown13f00f02014-10-31 14:45:50 -07001243 if (panic) {
Adrian Roosddc8b272015-05-21 16:28:27 -07001244 mHandler.post(mHiddenNavPanic);
Jeff Brown13f00f02014-10-31 14:45:50 -07001245 }
1246
1247 // Latch power key state to detect screenshot chord.
1248 if (interactive && !mScreenshotChordPowerKeyTriggered
1249 && (event.getFlags() & KeyEvent.FLAG_FALLBACK) == 0) {
1250 mScreenshotChordPowerKeyTriggered = true;
1251 mScreenshotChordPowerKeyTime = event.getDownTime();
1252 interceptScreenshotChord();
1253 }
1254
1255 // Stop ringing or end call if configured to do so when power is pressed.
1256 TelecomManager telecomManager = getTelecommService();
1257 boolean hungUp = false;
1258 if (telecomManager != null) {
1259 if (telecomManager.isRinging()) {
1260 // Pressing Power while there's a ringing incoming
1261 // call should silence the ringer.
1262 telecomManager.silenceRinger();
1263 } else if ((mIncallPowerBehavior
1264 & Settings.Secure.INCALL_POWER_BUTTON_BEHAVIOR_HANGUP) != 0
1265 && telecomManager.isInCall() && interactive) {
1266 // Otherwise, if "Power button ends call" is enabled,
1267 // the Power button will hang up any current active call.
1268 hungUp = telecomManager.endCall();
1269 }
1270 }
1271
Adrian Roos5941c982015-09-03 15:59:49 -07001272 GestureLauncherService gestureService = LocalServices.getService(
1273 GestureLauncherService.class);
1274 boolean gesturedServiceIntercepted = false;
1275 if (gestureService != null) {
Jorim Jaggif1cdf952016-04-05 21:41:06 -07001276 gesturedServiceIntercepted = gestureService.interceptPowerKeyDown(event, interactive,
1277 mTmpBoolean);
Selim Cinekab55ba52017-08-02 16:45:51 -07001278 if (mTmpBoolean.value && mRequestedOrGoingToSleep) {
Jorim Jaggif1cdf952016-04-05 21:41:06 -07001279 mCameraGestureTriggeredDuringGoingToSleep = true;
1280 }
Adrian Roos5941c982015-09-03 15:59:49 -07001281 }
1282
Philip Quinnc3a503d2017-07-18 23:23:41 -07001283 // Inform the StatusBar; but do not allow it to consume the event.
Philip Quinn4b5b3c62017-07-20 21:07:58 -07001284 sendSystemKeyToStatusBarAsync(event.getKeyCode());
Philip Quinnc3a503d2017-07-18 23:23:41 -07001285
Jeff Brown13f00f02014-10-31 14:45:50 -07001286 // If the power key has still not yet been handled, then detect short
1287 // press, long press, or multi press and decide what to do.
1288 mPowerKeyHandled = hungUp || mScreenshotChordVolumeDownKeyTriggered
Phil Weaver106fe732016-11-22 18:18:39 -08001289 || mA11yShortcutChordVolumeUpKeyTriggered || gesturedServiceIntercepted;
Jeff Brown13f00f02014-10-31 14:45:50 -07001290 if (!mPowerKeyHandled) {
1291 if (interactive) {
1292 // When interactive, we're already awake.
1293 // Wait for a long press or for the button to be released to decide what to do.
1294 if (hasLongPressOnPowerBehavior()) {
1295 Message msg = mHandler.obtainMessage(MSG_POWER_LONG_PRESS);
1296 msg.setAsynchronous(true);
1297 mHandler.sendMessageDelayed(msg,
1298 ViewConfiguration.get(mContext).getDeviceGlobalActionKeyTimeout());
1299 }
1300 } else {
Bryce Leed9268e32014-11-17 17:40:59 -08001301 wakeUpFromPowerKey(event.getDownTime());
Bryce Leed9268e32014-11-17 17:40:59 -08001302
Bryce Leed3b28402015-03-09 15:49:13 +00001303 if (mSupportLongPressPowerWhenNonInteractive && hasLongPressOnPowerBehavior()) {
1304 Message msg = mHandler.obtainMessage(MSG_POWER_LONG_PRESS);
1305 msg.setAsynchronous(true);
1306 mHandler.sendMessageDelayed(msg,
1307 ViewConfiguration.get(mContext).getDeviceGlobalActionKeyTimeout());
Bryce Leed9268e32014-11-17 17:40:59 -08001308 mBeganFromNonInteractive = true;
Bryce Leed3b28402015-03-09 15:49:13 +00001309 } else {
1310 final int maxCount = getMaxMultiPressPowerCount();
1311
1312 if (maxCount <= 1) {
1313 mPowerKeyHandled = true;
1314 } else {
1315 mBeganFromNonInteractive = true;
1316 }
Jeff Brown13f00f02014-10-31 14:45:50 -07001317 }
1318 }
Jeff Brown4d396052010-10-29 21:50:21 -07001319 }
1320 }
1321
Jeff Brown13f00f02014-10-31 14:45:50 -07001322 private void interceptPowerKeyUp(KeyEvent event, boolean interactive, boolean canceled) {
1323 final boolean handled = canceled || mPowerKeyHandled;
1324 mScreenshotChordPowerKeyTriggered = false;
1325 cancelPendingScreenshotChordAction();
1326 cancelPendingPowerKeyAction();
1327
1328 if (!handled) {
1329 // Figure out how to handle the key now that it has been released.
1330 mPowerKeyPressCounter += 1;
1331
1332 final int maxCount = getMaxMultiPressPowerCount();
1333 final long eventTime = event.getDownTime();
1334 if (mPowerKeyPressCounter < maxCount) {
1335 // This could be a multi-press. Wait a little bit longer to confirm.
1336 // Continue holding the wake lock.
1337 Message msg = mHandler.obtainMessage(MSG_POWER_DELAYED_PRESS,
1338 interactive ? 1 : 0, mPowerKeyPressCounter, eventTime);
1339 msg.setAsynchronous(true);
Alain Vongsouvanh0f63a542017-04-10 17:13:17 -07001340 mHandler.sendMessageDelayed(msg, ViewConfiguration.getMultiPressTimeout());
Jeff Brown13f00f02014-10-31 14:45:50 -07001341 return;
1342 }
1343
1344 // No other actions. Handle it immediately.
1345 powerPress(eventTime, interactive, mPowerKeyPressCounter);
Jeff Brown4d396052010-10-29 21:50:21 -07001346 }
Jeff Brown13f00f02014-10-31 14:45:50 -07001347
1348 // Done. Reset our state.
1349 finishPowerKeyPress();
1350 }
1351
1352 private void finishPowerKeyPress() {
Bryce Leed9268e32014-11-17 17:40:59 -08001353 mBeganFromNonInteractive = false;
Jeff Brown13f00f02014-10-31 14:45:50 -07001354 mPowerKeyPressCounter = 0;
1355 if (mPowerKeyWakeLock.isHeld()) {
1356 mPowerKeyWakeLock.release();
1357 }
Jeff Brownd5bb82d2011-10-12 13:57:59 -07001358 }
1359
Anthony Hugh96e9cc52016-07-12 15:17:24 -07001360 private void finishBackKeyPress() {
1361 mBackKeyPressCounter = 0;
1362 }
1363
Jeff Brownd5bb82d2011-10-12 13:57:59 -07001364 private void cancelPendingPowerKeyAction() {
1365 if (!mPowerKeyHandled) {
Jeff Brown13f00f02014-10-31 14:45:50 -07001366 mPowerKeyHandled = true;
1367 mHandler.removeMessages(MSG_POWER_LONG_PRESS);
Jeff Brownd5bb82d2011-10-12 13:57:59 -07001368 }
Jeff Brown13f00f02014-10-31 14:45:50 -07001369 }
1370
Anthony Hugh34f09ca2016-03-04 12:03:37 -08001371 private void cancelPendingBackKeyAction() {
1372 if (!mBackKeyHandled) {
1373 mBackKeyHandled = true;
1374 mHandler.removeMessages(MSG_BACK_LONG_PRESS);
1375 }
1376 }
1377
Anthony Hugh96e9cc52016-07-12 15:17:24 -07001378 private void backMultiPressAction(long eventTime, int count) {
1379 if (count >= PANIC_PRESS_BACK_COUNT) {
1380 switch (mPanicPressOnBackBehavior) {
1381 case PANIC_PRESS_BACK_NOTHING:
1382 break;
1383 case PANIC_PRESS_BACK_HOME:
1384 launchHomeFromHotKey();
1385 break;
1386 }
1387 }
1388 }
1389
Jeff Brown13f00f02014-10-31 14:45:50 -07001390 private void powerPress(long eventTime, boolean interactive, int count) {
1391 if (mScreenOnEarly && !mScreenOnFully) {
1392 Slog.i(TAG, "Suppressed redundant power key press while "
1393 + "already in the process of turning the screen on.");
1394 return;
Jeff Brownff204712011-10-25 21:27:54 -07001395 }
Jeff Brown13f00f02014-10-31 14:45:50 -07001396
1397 if (count == 2) {
1398 powerMultiPressAction(eventTime, interactive, mDoublePressOnPowerBehavior);
1399 } else if (count == 3) {
1400 powerMultiPressAction(eventTime, interactive, mTriplePressOnPowerBehavior);
Bryce Leed9268e32014-11-17 17:40:59 -08001401 } else if (interactive && !mBeganFromNonInteractive) {
Jeff Brown13f00f02014-10-31 14:45:50 -07001402 switch (mShortPressOnPowerBehavior) {
1403 case SHORT_PRESS_POWER_NOTHING:
1404 break;
1405 case SHORT_PRESS_POWER_GO_TO_SLEEP:
Selim Cinekab55ba52017-08-02 16:45:51 -07001406 goToSleep(eventTime, PowerManager.GO_TO_SLEEP_REASON_POWER_BUTTON, 0);
Jeff Brown13f00f02014-10-31 14:45:50 -07001407 break;
1408 case SHORT_PRESS_POWER_REALLY_GO_TO_SLEEP:
Selim Cinekab55ba52017-08-02 16:45:51 -07001409 goToSleep(eventTime, PowerManager.GO_TO_SLEEP_REASON_POWER_BUTTON,
Jeff Brown13f00f02014-10-31 14:45:50 -07001410 PowerManager.GO_TO_SLEEP_FLAG_NO_DOZE);
1411 break;
1412 case SHORT_PRESS_POWER_REALLY_GO_TO_SLEEP_AND_GO_HOME:
Selim Cinekab55ba52017-08-02 16:45:51 -07001413 goToSleep(eventTime, PowerManager.GO_TO_SLEEP_REASON_POWER_BUTTON,
Jeff Brown13f00f02014-10-31 14:45:50 -07001414 PowerManager.GO_TO_SLEEP_FLAG_NO_DOZE);
1415 launchHomeFromHotKey();
1416 break;
Bryce Lee01b0c5f2015-02-05 18:24:04 -08001417 case SHORT_PRESS_POWER_GO_HOME:
Andrew Zengb4045d32017-03-16 17:25:07 -07001418 shortPressPowerGoHome();
Bryce Lee01b0c5f2015-02-05 18:24:04 -08001419 break;
Yohei Yukawad6475a62017-04-17 10:35:27 -07001420 case SHORT_PRESS_POWER_CLOSE_IME_OR_GO_HOME: {
Yohei Yukawaabbe1ac2017-04-18 09:43:05 -07001421 if (mDismissImeOnBackKeyPressed) {
Yohei Yukawad6475a62017-04-17 10:35:27 -07001422 if (mInputMethodManagerInternal == null) {
1423 mInputMethodManagerInternal =
1424 LocalServices.getService(InputMethodManagerInternal.class);
1425 }
1426 if (mInputMethodManagerInternal != null) {
1427 mInputMethodManagerInternal.hideCurrentInputMethod();
1428 }
1429 } else {
Andrew Zengb4045d32017-03-16 17:25:07 -07001430 shortPressPowerGoHome();
Yohei Yukawad6475a62017-04-17 10:35:27 -07001431 }
1432 break;
1433 }
Jeff Brown13f00f02014-10-31 14:45:50 -07001434 }
1435 }
1436 }
1437
Selim Cinekab55ba52017-08-02 16:45:51 -07001438 private void goToSleep(long eventTime, int reason, int flags) {
1439 mRequestedOrGoingToSleep = true;
1440 mPowerManager.goToSleep(eventTime, reason, flags);
1441 }
1442
Andrew Zengb4045d32017-03-16 17:25:07 -07001443 private void shortPressPowerGoHome() {
1444 launchHomeFromHotKey(true /* awakenFromDreams */, false /*respectKeyguard*/);
1445 if (isKeyguardShowingAndNotOccluded()) {
1446 // Notify keyguard so it can do any special handling for the power button since the
1447 // device will not power off and only launch home.
1448 mKeyguardDelegate.onShortPowerPressedGoHome();
1449 }
1450 }
1451
Jeff Brown13f00f02014-10-31 14:45:50 -07001452 private void powerMultiPressAction(long eventTime, boolean interactive, int behavior) {
1453 switch (behavior) {
1454 case MULTI_PRESS_POWER_NOTHING:
1455 break;
1456 case MULTI_PRESS_POWER_THEATER_MODE:
Bryce Lee3ae447e2015-06-30 12:31:41 -07001457 if (!isUserSetupComplete()) {
1458 Slog.i(TAG, "Ignoring toggling theater mode - device not setup.");
1459 break;
1460 }
1461
Jeff Brown13f00f02014-10-31 14:45:50 -07001462 if (isTheaterModeEnabled()) {
1463 Slog.i(TAG, "Toggling theater mode off.");
1464 Settings.Global.putInt(mContext.getContentResolver(),
1465 Settings.Global.THEATER_MODE_ON, 0);
1466 if (!interactive) {
1467 wakeUpFromPowerKey(eventTime);
1468 }
1469 } else {
1470 Slog.i(TAG, "Toggling theater mode on.");
1471 Settings.Global.putInt(mContext.getContentResolver(),
1472 Settings.Global.THEATER_MODE_ON, 1);
Bryce Lee55e846d2014-11-04 12:43:44 -08001473
1474 if (mGoToSleepOnButtonPressTheaterMode && interactive) {
Selim Cinekab55ba52017-08-02 16:45:51 -07001475 goToSleep(eventTime, PowerManager.GO_TO_SLEEP_REASON_POWER_BUTTON, 0);
Jeff Brown13f00f02014-10-31 14:45:50 -07001476 }
1477 }
1478 break;
1479 case MULTI_PRESS_POWER_BRIGHTNESS_BOOST:
Jeff Brown7b5be5e2014-11-12 18:45:31 -08001480 Slog.i(TAG, "Starting brightness boost.");
1481 if (!interactive) {
1482 wakeUpFromPowerKey(eventTime);
1483 }
Jeff Brown13f00f02014-10-31 14:45:50 -07001484 mPowerManager.boostScreenBrightness(eventTime);
1485 break;
1486 }
1487 }
1488
1489 private int getMaxMultiPressPowerCount() {
1490 if (mTriplePressOnPowerBehavior != MULTI_PRESS_POWER_NOTHING) {
1491 return 3;
1492 }
1493 if (mDoublePressOnPowerBehavior != MULTI_PRESS_POWER_NOTHING) {
1494 return 2;
1495 }
1496 return 1;
1497 }
1498
1499 private void powerLongPress() {
1500 final int behavior = getResolvedLongPressOnPowerBehavior();
1501 switch (behavior) {
1502 case LONG_PRESS_POWER_NOTHING:
1503 break;
1504 case LONG_PRESS_POWER_GLOBAL_ACTIONS:
1505 mPowerKeyHandled = true;
Phil Weaver106fe732016-11-22 18:18:39 -08001506 performHapticFeedbackLw(null, HapticFeedbackConstants.LONG_PRESS, false);
Jeff Brown13f00f02014-10-31 14:45:50 -07001507 showGlobalActionsInternal();
1508 break;
1509 case LONG_PRESS_POWER_SHUT_OFF:
1510 case LONG_PRESS_POWER_SHUT_OFF_NO_CONFIRM:
1511 mPowerKeyHandled = true;
1512 performHapticFeedbackLw(null, HapticFeedbackConstants.LONG_PRESS, false);
1513 sendCloseSystemWindows(SYSTEM_DIALOG_REASON_GLOBAL_ACTIONS);
1514 mWindowManagerFuncs.shutdown(behavior == LONG_PRESS_POWER_SHUT_OFF);
1515 break;
1516 }
1517 }
1518
Anthony Hugh34f09ca2016-03-04 12:03:37 -08001519 private void backLongPress() {
1520 mBackKeyHandled = true;
1521
1522 switch (mLongPressOnBackBehavior) {
1523 case LONG_PRESS_BACK_NOTHING:
1524 break;
1525 case LONG_PRESS_BACK_GO_TO_VOICE_ASSIST:
Nancy Zheng0d85ee22016-09-29 09:15:56 -07001526 final boolean keyguardActive = mKeyguardDelegate == null
1527 ? false
1528 : mKeyguardDelegate.isShowing();
1529 if (!keyguardActive) {
1530 Intent intent = new Intent(Intent.ACTION_VOICE_ASSIST);
1531 startActivityAsUser(intent, UserHandle.CURRENT_OR_SELF);
1532 }
Anthony Hugh34f09ca2016-03-04 12:03:37 -08001533 break;
1534 }
1535 }
1536
Phil Weaver106fe732016-11-22 18:18:39 -08001537 private void accessibilityShortcutActivated() {
1538 mAccessibilityShortcutController.performAccessibilityShortcut();
1539 }
1540
Chong Zhang9f7fb092016-05-20 17:03:08 -07001541 private void disposeInputConsumer(InputConsumer inputConsumer) {
1542 if (inputConsumer != null) {
1543 inputConsumer.dismiss();
1544 }
1545 }
1546
Nick Vaccarob593a812015-05-15 11:23:05 -07001547 private void sleepPress(long eventTime) {
1548 if (mShortPressOnSleepBehavior == SHORT_PRESS_SLEEP_GO_TO_SLEEP_AND_GO_HOME) {
1549 launchHomeFromHotKey(false /* awakenDreams */, true /*respectKeyguard*/);
1550 }
1551 }
1552
1553 private void sleepRelease(long eventTime) {
Filip Gruszczynskia483a1d2015-03-17 19:06:58 +00001554 switch (mShortPressOnSleepBehavior) {
1555 case SHORT_PRESS_SLEEP_GO_TO_SLEEP:
Filip Gruszczynskia483a1d2015-03-17 19:06:58 +00001556 case SHORT_PRESS_SLEEP_GO_TO_SLEEP_AND_GO_HOME:
Nick Vaccarob593a812015-05-15 11:23:05 -07001557 Slog.i(TAG, "sleepRelease() calling goToSleep(GO_TO_SLEEP_REASON_SLEEP_BUTTON)");
Selim Cinekab55ba52017-08-02 16:45:51 -07001558 goToSleep(eventTime, PowerManager.GO_TO_SLEEP_REASON_SLEEP_BUTTON, 0);
Filip Gruszczynskia483a1d2015-03-17 19:06:58 +00001559 break;
1560 }
1561 }
1562
Jeff Brown13f00f02014-10-31 14:45:50 -07001563 private int getResolvedLongPressOnPowerBehavior() {
1564 if (FactoryTest.isLongPressOnPowerOffEnabled()) {
1565 return LONG_PRESS_POWER_SHUT_OFF_NO_CONFIRM;
1566 }
1567 return mLongPressOnPowerBehavior;
1568 }
1569
1570 private boolean hasLongPressOnPowerBehavior() {
1571 return getResolvedLongPressOnPowerBehavior() != LONG_PRESS_POWER_NOTHING;
Jeff Brownd5bb82d2011-10-12 13:57:59 -07001572 }
1573
Anthony Hugh34f09ca2016-03-04 12:03:37 -08001574 private boolean hasLongPressOnBackBehavior() {
1575 return mLongPressOnBackBehavior != LONG_PRESS_BACK_NOTHING;
1576 }
1577
Anthony Hugh96e9cc52016-07-12 15:17:24 -07001578 private boolean hasPanicPressOnBackBehavior() {
1579 return mPanicPressOnBackBehavior != PANIC_PRESS_BACK_NOTHING;
1580 }
1581
Jeff Brownd5bb82d2011-10-12 13:57:59 -07001582 private void interceptScreenshotChord() {
Christopher Tatee90585f2012-03-05 18:56:25 -08001583 if (mScreenshotChordEnabled
Jeff Brown13f00f02014-10-31 14:45:50 -07001584 && mScreenshotChordVolumeDownKeyTriggered && mScreenshotChordPowerKeyTriggered
Phil Weaver106fe732016-11-22 18:18:39 -08001585 && !mA11yShortcutChordVolumeUpKeyTriggered) {
Jeff Brownd5bb82d2011-10-12 13:57:59 -07001586 final long now = SystemClock.uptimeMillis();
Jeff Brown13f00f02014-10-31 14:45:50 -07001587 if (now <= mScreenshotChordVolumeDownKeyTime + SCREENSHOT_CHORD_DEBOUNCE_DELAY_MILLIS
1588 && now <= mScreenshotChordPowerKeyTime
1589 + SCREENSHOT_CHORD_DEBOUNCE_DELAY_MILLIS) {
1590 mScreenshotChordVolumeDownKeyConsumed = true;
Jeff Brownd5bb82d2011-10-12 13:57:59 -07001591 cancelPendingPowerKeyAction();
Muyuan Li6ca619f2016-03-08 13:30:42 -08001592 mScreenshotRunnable.setScreenshotType(TAKE_SCREENSHOT_FULLSCREEN);
Jeff Sharkey2991fa32012-12-05 18:06:43 -08001593 mHandler.postDelayed(mScreenshotRunnable, getScreenshotChordLongPressDelay());
Jeff Brownd5bb82d2011-10-12 13:57:59 -07001594 }
1595 }
1596 }
1597
Phil Weaver106fe732016-11-22 18:18:39 -08001598 private void interceptAccessibilityShortcutChord() {
Phil Weaverce687c52017-03-15 08:51:52 -07001599 if (mAccessibilityShortcutController.isAccessibilityShortcutAvailable(isKeyguardLocked())
Phil Weaver106fe732016-11-22 18:18:39 -08001600 && mScreenshotChordVolumeDownKeyTriggered && mA11yShortcutChordVolumeUpKeyTriggered
1601 && !mScreenshotChordPowerKeyTriggered) {
1602 final long now = SystemClock.uptimeMillis();
1603 if (now <= mScreenshotChordVolumeDownKeyTime + SCREENSHOT_CHORD_DEBOUNCE_DELAY_MILLIS
1604 && now <= mA11yShortcutChordVolumeUpKeyTime
1605 + SCREENSHOT_CHORD_DEBOUNCE_DELAY_MILLIS) {
1606 mScreenshotChordVolumeDownKeyConsumed = true;
1607 mA11yShortcutChordVolumeUpKeyConsumed = true;
1608 mHandler.sendMessageDelayed(mHandler.obtainMessage(MSG_ACCESSIBILITY_SHORTCUT),
1609 ViewConfiguration.get(mContext).getAccessibilityShortcutKeyTimeout());
1610 }
1611 }
1612 }
1613
Winson Chung1cea2f32012-10-08 20:42:01 -07001614 private long getScreenshotChordLongPressDelay() {
Jim Miller5ecd8112013-01-09 18:50:26 -08001615 if (mKeyguardDelegate.isShowing()) {
Winson Chung1cea2f32012-10-08 20:42:01 -07001616 // Double the time it takes to take a screenshot from the keyguard
1617 return (long) (KEYGUARD_SCREENSHOT_CHORD_DELAY_MULTIPLIER *
Justin Kohfeabd2c2014-05-02 10:02:44 -07001618 ViewConfiguration.get(mContext).getDeviceGlobalActionKeyTimeout());
Winson Chung1cea2f32012-10-08 20:42:01 -07001619 }
Justin Kohfeabd2c2014-05-02 10:02:44 -07001620 return ViewConfiguration.get(mContext).getDeviceGlobalActionKeyTimeout();
Winson Chung1cea2f32012-10-08 20:42:01 -07001621 }
1622
Jeff Brownd5bb82d2011-10-12 13:57:59 -07001623 private void cancelPendingScreenshotChordAction() {
Jeff Sharkey2991fa32012-12-05 18:06:43 -08001624 mHandler.removeCallbacks(mScreenshotRunnable);
Jeff Brown4d396052010-10-29 21:50:21 -07001625 }
1626
Phil Weaver106fe732016-11-22 18:18:39 -08001627 private void cancelPendingAccessibilityShortcutAction() {
1628 mHandler.removeMessages(MSG_ACCESSIBILITY_SHORTCUT);
1629 }
1630
Jeff Brown13f00f02014-10-31 14:45:50 -07001631 private final Runnable mEndCallLongPress = new Runnable() {
Craig Mautnerf1b67412012-09-19 13:18:29 -07001632 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001633 public void run() {
Jeff Brown13f00f02014-10-31 14:45:50 -07001634 mEndCallKeyHandled = true;
Phil Weaver106fe732016-11-22 18:18:39 -08001635 performHapticFeedbackLw(null, HapticFeedbackConstants.LONG_PRESS, false);
Jeff Brown13f00f02014-10-31 14:45:50 -07001636 showGlobalActionsInternal();
Jeff Brownd5bb82d2011-10-12 13:57:59 -07001637 }
1638 };
1639
Muyuan Li6ca619f2016-03-08 13:30:42 -08001640 private class ScreenshotRunnable implements Runnable {
1641 private int mScreenshotType = TAKE_SCREENSHOT_FULLSCREEN;
1642
1643 public void setScreenshotType(int screenshotType) {
1644 mScreenshotType = screenshotType;
1645 }
1646
Craig Mautner0bf6ec92012-12-18 08:33:27 -08001647 @Override
Jeff Brownd5bb82d2011-10-12 13:57:59 -07001648 public void run() {
Muyuan Li6ca619f2016-03-08 13:30:42 -08001649 takeScreenshot(mScreenshotType);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001650 }
Muyuan Li6ca619f2016-03-08 13:30:42 -08001651 }
1652
1653 private final ScreenshotRunnable mScreenshotRunnable = new ScreenshotRunnable();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001654
Alan Viverettee34560b22014-07-10 14:50:06 -07001655 @Override
1656 public void showGlobalActions() {
1657 mHandler.removeMessages(MSG_DISPATCH_SHOW_GLOBAL_ACTIONS);
1658 mHandler.sendEmptyMessage(MSG_DISPATCH_SHOW_GLOBAL_ACTIONS);
1659 }
1660
1661 void showGlobalActionsInternal() {
1662 sendCloseSystemWindows(SYSTEM_DIALOG_REASON_GLOBAL_ACTIONS);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001663 if (mGlobalActions == null) {
Jeff Brown7304c342012-05-11 18:42:42 -07001664 mGlobalActions = new GlobalActions(mContext, mWindowManagerFuncs);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001665 }
Jim Millerab954542014-10-10 18:21:49 -07001666 final boolean keyguardShowing = isKeyguardShowingAndNotOccluded();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001667 mGlobalActions.showDialog(keyguardShowing, isDeviceProvisioned());
1668 if (keyguardShowing) {
1669 // since it took two seconds of long press to bring this up,
1670 // poke the wake lock so they have some time to see the dialog.
Jim Miller25190572013-02-28 17:36:24 -08001671 mPowerManager.userActivity(SystemClock.uptimeMillis(), false);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001672 }
1673 }
1674
1675 boolean isDeviceProvisioned() {
Jeff Brownbf6f6f92012-09-25 15:03:20 -07001676 return Settings.Global.getInt(
1677 mContext.getContentResolver(), Settings.Global.DEVICE_PROVISIONED, 0) != 0;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001678 }
1679
Maurice Lam99c6e072014-04-28 18:24:28 -07001680 boolean isUserSetupComplete() {
Sujith Ramakrishnan0390fff2017-06-08 18:18:12 -07001681 boolean isSetupComplete = Settings.Secure.getIntForUser(mContext.getContentResolver(),
Maurice Lam99c6e072014-04-28 18:24:28 -07001682 Settings.Secure.USER_SETUP_COMPLETE, 0, UserHandle.USER_CURRENT) != 0;
Sujith Ramakrishnan0390fff2017-06-08 18:18:12 -07001683 if (mHasFeatureLeanback) {
1684 isSetupComplete &= isTvUserSetupComplete();
1685 }
1686 return isSetupComplete;
1687 }
1688
1689 private boolean isTvUserSetupComplete() {
1690 return Settings.Secure.getIntForUser(mContext.getContentResolver(),
1691 Settings.Secure.TV_USER_SETUP_COMPLETE, 0, UserHandle.USER_CURRENT) != 0;
Maurice Lam99c6e072014-04-28 18:24:28 -07001692 }
1693
Jeff Brown13f00f02014-10-31 14:45:50 -07001694 private void handleShortPressOnHome() {
Jinsuk Kime601b712015-07-07 08:01:02 +09001695 // Turn on the connected TV and switch HDMI input if we're a HDMI playback device.
Andrii Kulianeb4a7942016-12-21 12:18:05 -08001696 final HdmiControl hdmiControl = getHdmiControl();
1697 if (hdmiControl != null) {
1698 hdmiControl.turnOnTv();
1699 }
Jinsuk Kime601b712015-07-07 08:01:02 +09001700
Jeff Brown13f00f02014-10-31 14:45:50 -07001701 // If there's a dream running then use home to escape the dream
1702 // but don't actually go home.
1703 if (mDreamManagerInternal != null && mDreamManagerInternal.isDreaming()) {
1704 mDreamManagerInternal.stopDream(false /*immediate*/);
1705 return;
1706 }
1707
1708 // Go home!
1709 launchHomeFromHotKey();
1710 }
1711
Jinsuk Kime601b712015-07-07 08:01:02 +09001712 /**
1713 * Creates an accessor to HDMI control service that performs the operation of
1714 * turning on TV (optional) and switching input to us. If HDMI control service
1715 * is not available or we're not a HDMI playback device, the operation is no-op.
Andrii Kulianeb4a7942016-12-21 12:18:05 -08001716 * @return {@link HdmiControl} instance if available, null otherwise.
Jinsuk Kime601b712015-07-07 08:01:02 +09001717 */
1718 private HdmiControl getHdmiControl() {
1719 if (null == mHdmiControl) {
Andrii Kulianeb4a7942016-12-21 12:18:05 -08001720 if (!mContext.getPackageManager().hasSystemFeature(PackageManager.FEATURE_HDMI_CEC)) {
1721 return null;
1722 }
Jinsuk Kime601b712015-07-07 08:01:02 +09001723 HdmiControlManager manager = (HdmiControlManager) mContext.getSystemService(
1724 Context.HDMI_CONTROL_SERVICE);
1725 HdmiPlaybackClient client = null;
1726 if (manager != null) {
1727 client = manager.getPlaybackClient();
1728 }
1729 mHdmiControl = new HdmiControl(client);
1730 }
1731 return mHdmiControl;
1732 }
1733
1734 private static class HdmiControl {
1735 private final HdmiPlaybackClient mClient;
1736
1737 private HdmiControl(HdmiPlaybackClient client) {
1738 mClient = client;
1739 }
1740
1741 public void turnOnTv() {
1742 if (mClient == null) {
1743 return;
1744 }
1745 mClient.oneTouchPlay(new OneTouchPlayCallback() {
1746 @Override
1747 public void onComplete(int result) {
1748 if (result != HdmiControlManager.RESULT_SUCCESS) {
1749 Log.w(TAG, "One touch play failed: " + result);
1750 }
1751 }
1752 });
1753 }
1754 }
1755
Jaewan Kim76b7d0d2016-02-12 19:01:02 +09001756 private void handleLongPressOnHome(int deviceId) {
Jaewan Kim52632e22016-01-14 18:01:52 +09001757 if (mLongPressOnHomeBehavior == LONG_PRESS_HOME_NOTHING) {
1758 return;
1759 }
1760 mHomeConsumed = true;
1761 performHapticFeedbackLw(null, HapticFeedbackConstants.LONG_PRESS, false);
Jaewan Kim52632e22016-01-14 18:01:52 +09001762 switch (mLongPressOnHomeBehavior) {
Sid Soundararajanff662fa2017-03-15 16:24:24 -07001763 case LONG_PRESS_HOME_ALL_APPS:
1764 launchAllAppsAction();
Jaewan Kim52632e22016-01-14 18:01:52 +09001765 break;
1766 case LONG_PRESS_HOME_ASSIST:
Tim Kilbourn0e5f1102015-06-05 16:18:09 -07001767 launchAssistAction(null, deviceId);
Jaewan Kim52632e22016-01-14 18:01:52 +09001768 break;
Jaewan Kim52632e22016-01-14 18:01:52 +09001769 default:
Jaewan Kim76b7d0d2016-02-12 19:01:02 +09001770 Log.w(TAG, "Undefined home long press behavior: " + mLongPressOnHomeBehavior);
Jaewan Kim52632e22016-01-14 18:01:52 +09001771 break;
Jim Millere6ad1a82010-08-20 19:25:39 -07001772 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001773 }
Patrick Dubroyece94522011-02-23 18:35:01 -08001774
Sid Soundararajanff662fa2017-03-15 16:24:24 -07001775 private void launchAllAppsAction() {
1776 Intent intent = new Intent(Intent.ACTION_ALL_APPS);
1777 startActivityAsUser(intent, UserHandle.CURRENT);
1778 }
1779
Jeff Browncaca8812013-05-09 13:34:33 -07001780 private void handleDoubleTapOnHome() {
1781 if (mDoubleTapOnHomeBehavior == DOUBLE_TAP_HOME_RECENT_SYSTEM_UI) {
1782 mHomeConsumed = true;
1783 toggleRecentApps();
1784 }
1785 }
1786
Winson Chungac52f282017-03-30 14:44:52 -07001787 private void showPictureInPictureMenu(KeyEvent event) {
1788 if (DEBUG_INPUT) Log.d(TAG, "showPictureInPictureMenu event=" + event);
1789 mHandler.removeMessages(MSG_SHOW_PICTURE_IN_PICTURE_MENU);
1790 Message msg = mHandler.obtainMessage(MSG_SHOW_PICTURE_IN_PICTURE_MENU);
Jaewan Kimc552b042016-01-18 16:08:45 +09001791 msg.setAsynchronous(true);
1792 msg.sendToTarget();
1793 }
1794
Winson Chungac52f282017-03-30 14:44:52 -07001795 private void showPictureInPictureMenuInternal() {
Jaewan Kimf0fd2182016-04-20 21:17:58 +09001796 StatusBarManagerInternal statusbar = getStatusBarManagerInternal();
1797 if (statusbar != null) {
Winson Chungac52f282017-03-30 14:44:52 -07001798 statusbar.showPictureInPictureMenu();
Jaewan Kimc552b042016-01-18 16:08:45 +09001799 }
Jaewan Kim52632e22016-01-14 18:01:52 +09001800 }
1801
Jeff Browncaca8812013-05-09 13:34:33 -07001802 private final Runnable mHomeDoubleTapTimeoutRunnable = new Runnable() {
1803 @Override
1804 public void run() {
1805 if (mHomeDoubleTapPending) {
1806 mHomeDoubleTapPending = false;
Jeff Brown13f00f02014-10-31 14:45:50 -07001807 handleShortPressOnHome();
Jeff Browncaca8812013-05-09 13:34:33 -07001808 }
1809 }
1810 };
1811
Mark Renoufc1256912015-03-11 14:38:23 -04001812 private boolean isRoundWindow() {
Adam Powell01f280d2015-05-18 16:07:42 -07001813 return mContext.getResources().getConfiguration().isScreenRound();
Mark Renoufc1256912015-03-11 14:38:23 -04001814 }
1815
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001816 /** {@inheritDoc} */
Craig Mautner0bf6ec92012-12-18 08:33:27 -08001817 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001818 public void init(Context context, IWindowManager windowManager,
Jeff Brown96307042012-07-27 15:51:34 -07001819 WindowManagerFuncs windowManagerFuncs) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001820 mContext = context;
1821 mWindowManager = windowManager;
Dianne Hackborndf89e652011-10-06 22:35:11 -07001822 mWindowManagerFuncs = windowManagerFuncs;
Craig Mautner8a0da012014-05-31 15:13:37 -07001823 mWindowManagerInternal = LocalServices.getService(WindowManagerInternal.class);
Jeff Brown061ea992015-04-17 19:55:47 -07001824 mActivityManagerInternal = LocalServices.getService(ActivityManagerInternal.class);
Andrii Kulian112d0562016-03-08 10:44:22 -08001825 mInputManagerInternal = LocalServices.getService(InputManagerInternal.class);
Jose Lima9546b202014-07-02 17:21:51 -07001826 mDreamManagerInternal = LocalServices.getService(DreamManagerInternal.class);
Michael Wrighta4d22d72015-09-16 23:19:26 +01001827 mPowerManagerInternal = LocalServices.getService(PowerManagerInternal.class);
Billy Laucbe540f2015-06-25 01:51:44 +01001828 mAppOpsManager = (AppOpsManager) mContext.getSystemService(Context.APP_OPS_SERVICE);
Wale Ogunwale6b15ea52016-04-04 07:28:27 -07001829 mHasFeatureWatch = mContext.getPackageManager().hasSystemFeature(FEATURE_WATCH);
Dmitri Plotnikov82e6dfc2017-02-24 18:10:54 -08001830 mHasFeatureLeanback = mContext.getPackageManager().hasSystemFeature(FEATURE_LEANBACK);
Phil Weaver106fe732016-11-22 18:18:39 -08001831 mAccessibilityShortcutController =
Phil Weaverce687c52017-03-15 08:51:52 -07001832 new AccessibilityShortcutController(mContext, new Handler(), mCurrentUserId);
Mark Renoufc1256912015-03-11 14:38:23 -04001833 // Init display burn-in protection
1834 boolean burnInProtectionEnabled = context.getResources().getBoolean(
1835 com.android.internal.R.bool.config_enableBurnInProtection);
1836 // Allow a system property to override this. Used by developer settings.
1837 boolean burnInProtectionDevMode =
1838 SystemProperties.getBoolean("persist.debug.force_burn_in", false);
1839 if (burnInProtectionEnabled || burnInProtectionDevMode) {
1840 final int minHorizontal;
1841 final int maxHorizontal;
1842 final int minVertical;
1843 final int maxVertical;
1844 final int maxRadius;
1845 if (burnInProtectionDevMode) {
1846 minHorizontal = -8;
1847 maxHorizontal = 8;
1848 minVertical = -8;
1849 maxVertical = -4;
1850 maxRadius = (isRoundWindow()) ? 6 : -1;
1851 } else {
1852 Resources resources = context.getResources();
1853 minHorizontal = resources.getInteger(
1854 com.android.internal.R.integer.config_burnInProtectionMinHorizontalOffset);
1855 maxHorizontal = resources.getInteger(
1856 com.android.internal.R.integer.config_burnInProtectionMaxHorizontalOffset);
1857 minVertical = resources.getInteger(
1858 com.android.internal.R.integer.config_burnInProtectionMinVerticalOffset);
1859 maxVertical = resources.getInteger(
1860 com.android.internal.R.integer.config_burnInProtectionMaxVerticalOffset);
1861 maxRadius = resources.getInteger(
1862 com.android.internal.R.integer.config_burnInProtectionMaxRadius);
1863 }
1864 mBurnInProtectionHelper = new BurnInProtectionHelper(
1865 context, minHorizontal, maxHorizontal, minVertical, maxVertical, maxRadius);
Filip Gruszczynskicfb31852015-02-25 21:47:12 +00001866 }
Craig Mautner8a0da012014-05-31 15:13:37 -07001867
Jeff Brown70825162012-03-28 17:27:48 -07001868 mHandler = new PolicyHandler();
Jeff Browna20dda42014-05-27 20:57:24 -07001869 mWakeGestureListener = new MyWakeGestureListener(mContext, mHandler);
Craig Mautnereee29c42013-01-17 14:44:34 -08001870 mOrientationListener = new MyOrientationListener(mContext, mHandler);
Jeff Brownc0347aa2011-09-23 17:26:09 -07001871 try {
Andrii Kulian8ee72852017-03-10 10:36:45 -08001872 mOrientationListener.setCurrentRotation(windowManager.getDefaultDisplayRotation());
Jeff Brownc0347aa2011-09-23 17:26:09 -07001873 } catch (RemoteException ex) { }
Christopher Tate5e08af02012-09-21 17:17:22 -07001874 mSettingsObserver = new SettingsObserver(mHandler);
1875 mSettingsObserver.observe();
Svetoslav683914b2015-01-15 14:22:26 -08001876 mShortcutManager = new ShortcutManager(context);
Daniel Sandler6396c722013-04-16 20:19:09 -04001877 mUiMode = context.getResources().getInteger(
1878 com.android.internal.R.integer.config_defaultUiModeType);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001879 mHomeIntent = new Intent(Intent.ACTION_MAIN, null);
1880 mHomeIntent.addCategory(Intent.CATEGORY_HOME);
1881 mHomeIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK
1882 | Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED);
keunyounga7710492015-09-23 11:33:58 -07001883 mEnableCarDockHomeCapture = context.getResources().getBoolean(
1884 com.android.internal.R.bool.config_enableCarDockHomeLaunch);
Dianne Hackborn39c2d712009-09-22 11:41:31 -07001885 mCarDockIntent = new Intent(Intent.ACTION_MAIN, null);
1886 mCarDockIntent.addCategory(Intent.CATEGORY_CAR_DOCK);
1887 mCarDockIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK
1888 | Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED);
1889 mDeskDockIntent = new Intent(Intent.ACTION_MAIN, null);
1890 mDeskDockIntent.addCategory(Intent.CATEGORY_DESK_DOCK);
1891 mDeskDockIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK
1892 | Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED);
Zak Cohendb6ca492017-01-26 14:09:00 -08001893 mVrHeadsetHomeIntent = new Intent(Intent.ACTION_MAIN, null);
1894 mVrHeadsetHomeIntent.addCategory(Intent.CATEGORY_VR_HOME);
1895 mVrHeadsetHomeIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK
1896 | Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED);
Jim Millere6ad1a82010-08-20 19:25:39 -07001897
Jeff Brown96307042012-07-27 15:51:34 -07001898 mPowerManager = (PowerManager)context.getSystemService(Context.POWER_SERVICE);
1899 mBroadcastWakeLock = mPowerManager.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK,
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001900 "PhoneWindowManager.mBroadcastWakeLock");
Jeff Brown13f00f02014-10-31 14:45:50 -07001901 mPowerKeyWakeLock = mPowerManager.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK,
1902 "PhoneWindowManager.mPowerKeyWakeLock");
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001903 mEnableShiftMenuBugReports = "1".equals(SystemProperties.get("ro.debuggable"));
Jeff Brownbcdfc622014-03-06 19:13:04 -08001904 mSupportAutoRotation = mContext.getResources().getBoolean(
1905 com.android.internal.R.bool.config_supportAutoRotation);
Dianne Hackborn2862fff2009-09-15 22:56:29 -07001906 mLidOpenRotation = readRotation(
Mike Lockwood2d1efbd2009-09-16 12:15:53 -04001907 com.android.internal.R.integer.config_lidOpenRotation);
1908 mCarDockRotation = readRotation(
1909 com.android.internal.R.integer.config_carDockRotation);
1910 mDeskDockRotation = readRotation(
1911 com.android.internal.R.integer.config_deskDockRotation);
Jeff Brownc82c89ed2013-04-17 17:18:15 -07001912 mUndockedHdmiRotation = readRotation(
1913 com.android.internal.R.integer.config_undockedHdmiRotation);
Mike Lockwoode9867d22009-09-20 01:59:02 -04001914 mCarDockEnablesAccelerometer = mContext.getResources().getBoolean(
1915 com.android.internal.R.bool.config_carDockEnablesAccelerometer);
1916 mDeskDockEnablesAccelerometer = mContext.getResources().getBoolean(
1917 com.android.internal.R.bool.config_deskDockEnablesAccelerometer);
Dianne Hackborn2862fff2009-09-15 22:56:29 -07001918 mLidKeyboardAccessibility = mContext.getResources().getInteger(
1919 com.android.internal.R.integer.config_lidKeyboardAccessibility);
1920 mLidNavigationAccessibility = mContext.getResources().getInteger(
1921 com.android.internal.R.integer.config_lidNavigationAccessibility);
Edward Savage-Jones7def60d2015-11-13 13:27:03 +01001922 mLidControlsScreenLock = mContext.getResources().getBoolean(
1923 com.android.internal.R.bool.config_lidControlsScreenLock);
Jeff Brownc458ce92012-04-30 14:58:40 -07001924 mLidControlsSleep = mContext.getResources().getBoolean(
1925 com.android.internal.R.bool.config_lidControlsSleep);
Daniel Sandlerdd73ee42013-10-11 22:19:59 -04001926 mTranslucentDecorEnabled = mContext.getResources().getBoolean(
1927 com.android.internal.R.bool.config_enableTranslucentDecor);
Bryce Lee584a4452014-10-21 15:55:55 -07001928
1929 mAllowTheaterModeWakeFromKey = mContext.getResources().getBoolean(
1930 com.android.internal.R.bool.config_allowTheaterModeWakeFromKey);
1931 mAllowTheaterModeWakeFromPowerKey = mAllowTheaterModeWakeFromKey
1932 || mContext.getResources().getBoolean(
1933 com.android.internal.R.bool.config_allowTheaterModeWakeFromPowerKey);
1934 mAllowTheaterModeWakeFromMotion = mContext.getResources().getBoolean(
1935 com.android.internal.R.bool.config_allowTheaterModeWakeFromMotion);
Bryce Lee812d7022014-11-10 13:33:28 -08001936 mAllowTheaterModeWakeFromMotionWhenNotDreaming = mContext.getResources().getBoolean(
1937 com.android.internal.R.bool.config_allowTheaterModeWakeFromMotionWhenNotDreaming);
Bryce Lee584a4452014-10-21 15:55:55 -07001938 mAllowTheaterModeWakeFromCameraLens = mContext.getResources().getBoolean(
1939 com.android.internal.R.bool.config_allowTheaterModeWakeFromCameraLens);
1940 mAllowTheaterModeWakeFromLidSwitch = mContext.getResources().getBoolean(
1941 com.android.internal.R.bool.config_allowTheaterModeWakeFromLidSwitch);
1942 mAllowTheaterModeWakeFromWakeGesture = mContext.getResources().getBoolean(
1943 com.android.internal.R.bool.config_allowTheaterModeWakeFromGesture);
1944
Bryce Lee55e846d2014-11-04 12:43:44 -08001945 mGoToSleepOnButtonPressTheaterMode = mContext.getResources().getBoolean(
1946 com.android.internal.R.bool.config_goToSleepOnButtonPressTheaterMode);
1947
Bryce Leed3b28402015-03-09 15:49:13 +00001948 mSupportLongPressPowerWhenNonInteractive = mContext.getResources().getBoolean(
1949 com.android.internal.R.bool.config_supportLongPressPowerWhenNonInteractive);
1950
Anthony Hugh34f09ca2016-03-04 12:03:37 -08001951 mLongPressOnBackBehavior = mContext.getResources().getInteger(
1952 com.android.internal.R.integer.config_longPressOnBackBehavior);
Anthony Hugh96e9cc52016-07-12 15:17:24 -07001953 mPanicPressOnBackBehavior = mContext.getResources().getInteger(
1954 com.android.internal.R.integer.config_backPanicBehavior);
Anthony Hugh34f09ca2016-03-04 12:03:37 -08001955
Jeff Brown13f00f02014-10-31 14:45:50 -07001956 mShortPressOnPowerBehavior = mContext.getResources().getInteger(
1957 com.android.internal.R.integer.config_shortPressOnPowerBehavior);
1958 mLongPressOnPowerBehavior = mContext.getResources().getInteger(
1959 com.android.internal.R.integer.config_longPressOnPowerBehavior);
1960 mDoublePressOnPowerBehavior = mContext.getResources().getInteger(
1961 com.android.internal.R.integer.config_doublePressOnPowerBehavior);
1962 mTriplePressOnPowerBehavior = mContext.getResources().getInteger(
1963 com.android.internal.R.integer.config_triplePressOnPowerBehavior);
Filip Gruszczynskia483a1d2015-03-17 19:06:58 +00001964 mShortPressOnSleepBehavior = mContext.getResources().getInteger(
1965 com.android.internal.R.integer.config_shortPressOnSleepBehavior);
Jeff Brown13f00f02014-10-31 14:45:50 -07001966
John Spurlock61560172015-02-06 19:46:04 -05001967 mUseTvRouting = AudioSystem.getPlatformType(mContext) == AudioSystem.PLATFORM_TELEVISION;
RoboErik001c59c2015-01-26 15:53:51 -08001968
Karthik Ravi Shankar86ecf342017-04-28 15:35:58 -07001969 mHandleVolumeKeysInWM = mContext.getResources().getBoolean(
1970 com.android.internal.R.bool.config_handleVolumeKeysInWindowManager);
1971
Jeff Brownf71343d2013-05-31 17:59:11 -07001972 readConfigurationDependentBehaviors();
Jeff Browncaca8812013-05-09 13:34:33 -07001973
Svetoslav8e3feb12014-02-24 13:46:47 -08001974 mAccessibilityManager = (AccessibilityManager) context.getSystemService(
1975 Context.ACCESSIBILITY_SERVICE);
1976
Mike Lockwood1753f7f2009-08-24 14:49:07 -07001977 // register for dock events
Dianne Hackborn78968392010-03-04 20:47:56 -08001978 IntentFilter filter = new IntentFilter();
1979 filter.addAction(UiModeManager.ACTION_ENTER_CAR_MODE);
1980 filter.addAction(UiModeManager.ACTION_EXIT_CAR_MODE);
1981 filter.addAction(UiModeManager.ACTION_ENTER_DESK_MODE);
1982 filter.addAction(UiModeManager.ACTION_EXIT_DESK_MODE);
Dianne Hackborn867ab6472010-04-29 13:28:56 -07001983 filter.addAction(Intent.ACTION_DOCK_EVENT);
1984 Intent intent = context.registerReceiver(mDockReceiver, filter);
1985 if (intent != null) {
1986 // Retrieve current sticky dock event broadcast.
1987 mDockMode = intent.getIntExtra(Intent.EXTRA_DOCK_STATE,
1988 Intent.EXTRA_DOCK_STATE_UNDOCKED);
1989 }
Daniel Sandler7e37df52011-11-16 22:08:23 -08001990
Jeff Brown6aaf2952012-10-05 16:01:08 -07001991 // register for dream-related broadcasts
1992 filter = new IntentFilter();
1993 filter.addAction(Intent.ACTION_DREAMING_STARTED);
1994 filter.addAction(Intent.ACTION_DREAMING_STOPPED);
1995 context.registerReceiver(mDreamReceiver, filter);
1996
Christopher Tate5e08af02012-09-21 17:17:22 -07001997 // register for multiuser-relevant broadcasts
1998 filter = new IntentFilter(Intent.ACTION_USER_SWITCHED);
1999 context.registerReceiver(mMultiuserReceiver, filter);
2000
John Spurlock57306e62013-04-22 09:48:49 -04002001 // monitor for system gestures
Craig Mautner037aa8d2013-06-07 10:35:44 -07002002 mSystemGestures = new SystemGesturesPointerEventListener(context,
2003 new SystemGesturesPointerEventListener.Callbacks() {
John Spurlock57306e62013-04-22 09:48:49 -04002004 @Override
2005 public void onSwipeFromTop() {
John Spurlock04db1762013-05-13 12:46:41 -04002006 if (mStatusBar != null) {
John Spurlocke1f366f2013-08-05 12:22:40 -04002007 requestTransientBars(mStatusBar);
John Spurlock04db1762013-05-13 12:46:41 -04002008 }
John Spurlockad3e6cb2013-04-30 08:47:43 -04002009 }
2010 @Override
2011 public void onSwipeFromBottom() {
Adrian Roos85d202b2016-06-02 16:27:47 -07002012 if (mNavigationBar != null && mNavigationBarPosition == NAV_BAR_BOTTOM) {
John Spurlocke1f366f2013-08-05 12:22:40 -04002013 requestTransientBars(mNavigationBar);
John Spurlockad3e6cb2013-04-30 08:47:43 -04002014 }
2015 }
2016 @Override
2017 public void onSwipeFromRight() {
Adrian Roos85d202b2016-06-02 16:27:47 -07002018 if (mNavigationBar != null && mNavigationBarPosition == NAV_BAR_RIGHT) {
2019 requestTransientBars(mNavigationBar);
2020 }
2021 }
2022 @Override
2023 public void onSwipeFromLeft() {
2024 if (mNavigationBar != null && mNavigationBarPosition == NAV_BAR_LEFT) {
John Spurlocke1f366f2013-08-05 12:22:40 -04002025 requestTransientBars(mNavigationBar);
John Spurlockad3e6cb2013-04-30 08:47:43 -04002026 }
2027 }
2028 @Override
Michael Wrighta4d22d72015-09-16 23:19:26 +01002029 public void onFling(int duration) {
2030 if (mPowerManagerInternal != null) {
2031 mPowerManagerInternal.powerHint(
Ruchi Kandoi0d434042016-10-03 09:12:02 -07002032 PowerHint.INTERACTION, duration);
Michael Wrighta4d22d72015-09-16 23:19:26 +01002033 }
2034 }
2035 @Override
John Spurlockad3e6cb2013-04-30 08:47:43 -04002036 public void onDebug() {
John Spurlockd67ec252013-09-05 11:31:54 -04002037 // no-op
John Spurlockad3e6cb2013-04-30 08:47:43 -04002038 }
Adrian Roos3595be42015-03-05 16:31:15 +01002039 @Override
2040 public void onDown() {
2041 mOrientationListener.onTouchStart();
2042 }
2043 @Override
2044 public void onUpOrCancel() {
2045 mOrientationListener.onTouchEnd();
2046 }
Jun Mukaid2e7e352015-07-22 17:14:02 -07002047 @Override
2048 public void onMouseHoverAtTop() {
2049 mHandler.removeMessages(MSG_REQUEST_TRANSIENT_BARS);
2050 Message msg = mHandler.obtainMessage(MSG_REQUEST_TRANSIENT_BARS);
2051 msg.arg1 = MSG_REQUEST_TRANSIENT_BARS_ARG_STATUS;
2052 mHandler.sendMessageDelayed(msg, 500);
2053 }
2054 @Override
2055 public void onMouseHoverAtBottom() {
2056 mHandler.removeMessages(MSG_REQUEST_TRANSIENT_BARS);
2057 Message msg = mHandler.obtainMessage(MSG_REQUEST_TRANSIENT_BARS);
2058 msg.arg1 = MSG_REQUEST_TRANSIENT_BARS_ARG_NAVIGATION;
2059 mHandler.sendMessageDelayed(msg, 500);
2060 }
2061 @Override
2062 public void onMouseLeaveFromEdge() {
2063 mHandler.removeMessages(MSG_REQUEST_TRANSIENT_BARS);
2064 }
John Spurlockad3e6cb2013-04-30 08:47:43 -04002065 });
John Spurlockf1a36642013-10-12 17:50:42 -04002066 mImmersiveModeConfirmation = new ImmersiveModeConfirmation(mContext);
Craig Mautner037aa8d2013-06-07 10:35:44 -07002067 mWindowManagerFuncs.registerPointerEventListener(mSystemGestures);
John Spurlock32beb2c2013-03-11 10:16:47 -04002068
Jeff Brownc2346132012-04-13 01:55:38 -07002069 mVibrator = (Vibrator)context.getSystemService(Context.VIBRATOR_SERVICE);
Dianne Hackbornb1a79802009-09-29 15:18:31 -07002070 mLongPressVibePattern = getLongIntArray(mContext.getResources(),
2071 com.android.internal.R.array.config_longPressVibePattern);
Fabrice Di Megliobd9152f2013-10-01 11:21:31 -07002072 mCalendarDateVibePattern = getLongIntArray(mContext.getResources(),
2073 com.android.internal.R.array.config_calendarDateVibePattern);
Dianne Hackbornb1a79802009-09-29 15:18:31 -07002074 mSafeModeEnabledVibePattern = getLongIntArray(mContext.getResources(),
2075 com.android.internal.R.array.config_safeModeEnabledVibePattern);
Daniel Sandler40427442010-07-16 11:44:52 -04002076
Christopher Tatee90585f2012-03-05 18:56:25 -08002077 mScreenshotChordEnabled = mContext.getResources().getBoolean(
2078 com.android.internal.R.bool.config_enableScreenshotChord);
2079
Justin Kohd378ad72013-04-01 12:18:26 -07002080 mGlobalKeyManager = new GlobalKeyManager(mContext);
2081
Joe Onoratoea495d42011-04-06 11:41:11 -07002082 // Controls rotation and the like.
2083 initializeHdmiState();
Dianne Hackborn40011092011-09-22 13:37:48 -07002084
2085 // Match current screen state.
Craig Mautnera631d492014-08-05 15:16:01 -07002086 if (!mPowerManager.isInteractive()) {
Jeff Brown416c49c2015-05-26 19:50:18 -07002087 startedGoingToSleep(WindowManagerPolicy.OFF_BECAUSE_OF_USER);
2088 finishedGoingToSleep(WindowManagerPolicy.OFF_BECAUSE_OF_USER);
Dianne Hackborn40011092011-09-22 13:37:48 -07002089 }
Jorim Jaggi24bec7c2015-02-04 12:40:14 +01002090
2091 mWindowManagerInternal.registerAppTransitionListener(
2092 mStatusBarController.getAppTransitionListener());
Jorim Jaggife762342016-10-13 14:33:27 +02002093 mWindowManagerInternal.registerAppTransitionListener(new AppTransitionListener() {
2094 @Override
2095 public int onAppTransitionStartingLocked(int transit, IBinder openToken,
2096 IBinder closeToken,
2097 Animation openAnimation, Animation closeAnimation) {
2098 return handleStartTransitionForKeyguardLw(transit, openAnimation);
2099 }
2100
2101 @Override
2102 public void onAppTransitionCancelledLocked(int transit) {
2103 handleStartTransitionForKeyguardLw(transit, null /* transit */);
2104 }
2105 });
Keun-young Park4136d2d2017-05-08 14:51:59 -07002106 mKeyguardDelegate = new KeyguardServiceDelegate(mContext,
2107 new StateCallback() {
2108 @Override
2109 public void onTrustedChanged() {
2110 mWindowManagerFuncs.notifyKeyguardTrustedChanged();
2111 }
2112 });
Mike Lockwood1753f7f2009-08-24 14:49:07 -07002113 }
2114
Jeff Brownf71343d2013-05-31 17:59:11 -07002115 /**
2116 * Read values from config.xml that may be overridden depending on
2117 * the configuration of the device.
2118 * eg. Disable long press on home goes to recents on sw600dp.
2119 */
2120 private void readConfigurationDependentBehaviors() {
Jaewan Kimc552b042016-01-18 16:08:45 +09002121 final Resources res = mContext.getResources();
2122
2123 mLongPressOnHomeBehavior = res.getInteger(
Jeff Brownf71343d2013-05-31 17:59:11 -07002124 com.android.internal.R.integer.config_longPressOnHomeBehavior);
2125 if (mLongPressOnHomeBehavior < LONG_PRESS_HOME_NOTHING ||
Jaewan Kim52632e22016-01-14 18:01:52 +09002126 mLongPressOnHomeBehavior > LAST_LONG_PRESS_HOME_BEHAVIOR) {
Jeff Brownf71343d2013-05-31 17:59:11 -07002127 mLongPressOnHomeBehavior = LONG_PRESS_HOME_NOTHING;
2128 }
2129
Jaewan Kimc552b042016-01-18 16:08:45 +09002130 mDoubleTapOnHomeBehavior = res.getInteger(
Jeff Brownf71343d2013-05-31 17:59:11 -07002131 com.android.internal.R.integer.config_doubleTapOnHomeBehavior);
2132 if (mDoubleTapOnHomeBehavior < DOUBLE_TAP_HOME_NOTHING ||
2133 mDoubleTapOnHomeBehavior > DOUBLE_TAP_HOME_RECENT_SYSTEM_UI) {
2134 mDoubleTapOnHomeBehavior = LONG_PRESS_HOME_NOTHING;
2135 }
Jaewan Kim49117872016-01-19 17:24:08 +09002136
2137 mShortPressWindowBehavior = SHORT_PRESS_WINDOW_NOTHING;
2138 if (mContext.getPackageManager().hasSystemFeature(FEATURE_PICTURE_IN_PICTURE)) {
2139 mShortPressWindowBehavior = SHORT_PRESS_WINDOW_PICTURE_IN_PICTURE;
2140 }
Yorke Lee2e4b7322016-03-02 17:33:06 -08002141
Yorke Lee9b2ffb32016-03-07 20:42:01 -08002142 mNavBarOpacityMode = res.getInteger(
2143 com.android.internal.R.integer.config_navBarOpacityMode);
Jeff Brownf71343d2013-05-31 17:59:11 -07002144 }
2145
Craig Mautner0bf6ec92012-12-18 08:33:27 -08002146 @Override
Dianne Hackborndde331c2012-08-03 14:01:57 -07002147 public void setInitialDisplaySize(Display display, int width, int height, int density) {
Jeff Brownef981a42013-08-07 14:13:37 -07002148 // This method might be called before the policy has been fully initialized
2149 // or for other displays we don't care about.
Andrii Kulian3a507b52016-09-19 18:14:12 -07002150 // TODO(multi-display): Define policy for secondary displays.
Jeff Brownef981a42013-08-07 14:13:37 -07002151 if (mContext == null || display.getDisplayId() != Display.DEFAULT_DISPLAY) {
2152 return;
Dianne Hackbornc652de82013-02-15 16:32:56 -08002153 }
Dianne Hackbornf87d1962012-04-04 12:48:24 -07002154 mDisplay = display;
2155
Craig Mautner46ac6fa2013-08-01 10:06:34 -07002156 final Resources res = mContext.getResources();
Dianne Hackbornf87d1962012-04-04 12:48:24 -07002157 int shortSize, longSize;
Dianne Hackborn9d132642011-04-21 17:26:39 -07002158 if (width > height) {
Dianne Hackborn81e56d52011-05-26 00:55:58 -07002159 shortSize = height;
Dianne Hackbornf87d1962012-04-04 12:48:24 -07002160 longSize = width;
Dianne Hackborn9d132642011-04-21 17:26:39 -07002161 mLandscapeRotation = Surface.ROTATION_0;
2162 mSeascapeRotation = Surface.ROTATION_180;
Craig Mautner46ac6fa2013-08-01 10:06:34 -07002163 if (res.getBoolean(com.android.internal.R.bool.config_reverseDefaultRotation)) {
Dianne Hackborn9d132642011-04-21 17:26:39 -07002164 mPortraitRotation = Surface.ROTATION_90;
2165 mUpsideDownRotation = Surface.ROTATION_270;
2166 } else {
2167 mPortraitRotation = Surface.ROTATION_270;
2168 mUpsideDownRotation = Surface.ROTATION_90;
2169 }
2170 } else {
Dianne Hackborn81e56d52011-05-26 00:55:58 -07002171 shortSize = width;
Dianne Hackbornf87d1962012-04-04 12:48:24 -07002172 longSize = height;
Dianne Hackborn9d132642011-04-21 17:26:39 -07002173 mPortraitRotation = Surface.ROTATION_0;
2174 mUpsideDownRotation = Surface.ROTATION_180;
Craig Mautner46ac6fa2013-08-01 10:06:34 -07002175 if (res.getBoolean(com.android.internal.R.bool.config_reverseDefaultRotation)) {
Dianne Hackborn9d132642011-04-21 17:26:39 -07002176 mLandscapeRotation = Surface.ROTATION_270;
2177 mSeascapeRotation = Surface.ROTATION_90;
2178 } else {
2179 mLandscapeRotation = Surface.ROTATION_90;
2180 mSeascapeRotation = Surface.ROTATION_270;
2181 }
2182 }
Dianne Hackborn81e56d52011-05-26 00:55:58 -07002183
Daniel Sandler4a066c52012-04-20 14:49:13 -04002184 // SystemUI (status bar) layout policy
Dianne Hackborndde331c2012-08-03 14:01:57 -07002185 int shortSizeDp = shortSize * DisplayMetrics.DENSITY_DEFAULT / density;
Craig Mautner46ac6fa2013-08-01 10:06:34 -07002186 int longSizeDp = longSize * DisplayMetrics.DENSITY_DEFAULT / density;
Daniel Sandler4a066c52012-04-20 14:49:13 -04002187
Devin Kimd7b12b42014-05-05 14:34:58 -07002188 // Allow the navigation bar to move on non-square small devices (phones).
2189 mNavigationBarCanMove = width != height && shortSizeDp < 600;
Daniel Sandler36412a72011-08-04 09:35:13 -04002190
Craig Mautner46ac6fa2013-08-01 10:06:34 -07002191 mHasNavigationBar = res.getBoolean(com.android.internal.R.bool.config_showNavigationBar);
Jorim Jaggi11c62e12016-04-05 20:41:21 -07002192
John Spurlock80f00c12013-06-13 11:10:51 -04002193 // Allow a system property to override this. Used by the emulator.
2194 // See also hasNavigationBar().
2195 String navBarOverride = SystemProperties.get("qemu.hw.mainkeys");
2196 if ("1".equals(navBarOverride)) {
Dianne Hackbornf87d1962012-04-04 12:48:24 -07002197 mHasNavigationBar = false;
John Spurlock80f00c12013-06-13 11:10:51 -04002198 } else if ("0".equals(navBarOverride)) {
2199 mHasNavigationBar = true;
Daniel Sandler0c4ccff2011-10-19 16:39:14 -04002200 }
2201
Jeff Brown27f1d672012-10-17 18:32:34 -07002202 // For demo purposes, allow the rotation of the HDMI display to be controlled.
2203 // By default, HDMI locks rotation to landscape.
Erik Gilling9a41ef82011-09-26 19:21:03 -07002204 if ("portrait".equals(SystemProperties.get("persist.demo.hdmirotation"))) {
Jeff Brownc82c89ed2013-04-17 17:18:15 -07002205 mDemoHdmiRotation = mPortraitRotation;
Erik Gilling9a41ef82011-09-26 19:21:03 -07002206 } else {
Jeff Brownc82c89ed2013-04-17 17:18:15 -07002207 mDemoHdmiRotation = mLandscapeRotation;
Erik Gilling9a41ef82011-09-26 19:21:03 -07002208 }
Jeff Brownc82c89ed2013-04-17 17:18:15 -07002209 mDemoHdmiRotationLock = SystemProperties.getBoolean("persist.demo.hdmirotationlock", false);
Craig Mautner46ac6fa2013-08-01 10:06:34 -07002210
Chong Zhangae6119ff2014-11-11 18:54:39 -08002211 // For demo purposes, allow the rotation of the remote display to be controlled.
2212 // By default, remote display locks rotation to landscape.
2213 if ("portrait".equals(SystemProperties.get("persist.demo.remoterotation"))) {
2214 mDemoRotation = mPortraitRotation;
2215 } else {
2216 mDemoRotation = mLandscapeRotation;
2217 }
2218 mDemoRotationLock = SystemProperties.getBoolean(
2219 "persist.demo.rotationlock", false);
2220
Craig Mautner46ac6fa2013-08-01 10:06:34 -07002221 // Only force the default orientation if the screen is xlarge, at least 960dp x 720dp, per
2222 // http://developer.android.com/guide/practices/screens_support.html#range
2223 mForceDefaultOrientation = longSizeDp >= 960 && shortSizeDp >= 720 &&
2224 res.getBoolean(com.android.internal.R.bool.config_forceDefaultOrientation) &&
2225 // For debug purposes the next line turns this feature off with:
2226 // $ adb shell setprop config.override_forced_orient true
2227 // $ adb shell wm size reset
2228 !"true".equals(SystemProperties.get("config.override_forced_orient"));
2229 }
2230
Alan Viverette5a0f4ec2013-10-07 15:10:29 -07002231 /**
2232 * @return whether the navigation bar can be hidden, e.g. the device has a
2233 * navigation bar and touch exploration is not enabled
2234 */
2235 private boolean canHideNavigationBar() {
Alan Viverette817f3cd2015-08-13 11:40:14 -04002236 return mHasNavigationBar;
Alan Viverette5a0f4ec2013-10-07 15:10:29 -07002237 }
2238
Craig Mautner46ac6fa2013-08-01 10:06:34 -07002239 @Override
2240 public boolean isDefaultOrientationForced() {
2241 return mForceDefaultOrientation;
Dianne Hackborn9d132642011-04-21 17:26:39 -07002242 }
2243
Dianne Hackbornc652de82013-02-15 16:32:56 -08002244 @Override
2245 public void setDisplayOverscan(Display display, int left, int top, int right, int bottom) {
Andrii Kulian3a507b52016-09-19 18:14:12 -07002246 // TODO(multi-display): Define policy for secondary displays.
Dianne Hackbornc652de82013-02-15 16:32:56 -08002247 if (display.getDisplayId() == Display.DEFAULT_DISPLAY) {
2248 mOverscanLeft = left;
2249 mOverscanTop = top;
2250 mOverscanRight = right;
2251 mOverscanBottom = bottom;
2252 }
2253 }
2254
Dianne Hackbornc777e072010-02-12 13:07:59 -08002255 public void updateSettings() {
2256 ContentResolver resolver = mContext.getContentResolver();
2257 boolean updateRotation = false;
Dianne Hackbornc777e072010-02-12 13:07:59 -08002258 synchronized (mLock) {
Christopher Tate5e08af02012-09-21 17:17:22 -07002259 mEndcallBehavior = Settings.System.getIntForUser(resolver,
David Brownbaf8d092010-03-08 21:52:59 -08002260 Settings.System.END_BUTTON_BEHAVIOR,
Christopher Tate5e08af02012-09-21 17:17:22 -07002261 Settings.System.END_BUTTON_BEHAVIOR_DEFAULT,
2262 UserHandle.USER_CURRENT);
2263 mIncallPowerBehavior = Settings.Secure.getIntForUser(resolver,
David Brownbaf8d092010-03-08 21:52:59 -08002264 Settings.Secure.INCALL_POWER_BUTTON_BEHAVIOR,
Christopher Tate5e08af02012-09-21 17:17:22 -07002265 Settings.Secure.INCALL_POWER_BUTTON_BEHAVIOR_DEFAULT,
2266 UserHandle.USER_CURRENT);
Bryce Leedb776ce2016-09-03 15:02:00 -07002267 mIncallBackBehavior = Settings.Secure.getIntForUser(resolver,
2268 Settings.Secure.INCALL_BACK_BUTTON_BEHAVIOR,
2269 Settings.Secure.INCALL_BACK_BUTTON_BEHAVIOR_DEFAULT,
2270 UserHandle.USER_CURRENT);
Daniel Sandlerb73617d2010-08-17 00:41:00 -04002271
Jeff Browna20dda42014-05-27 20:57:24 -07002272 // Configure wake gesture.
2273 boolean wakeGestureEnabledSetting = Settings.Secure.getIntForUser(resolver,
2274 Settings.Secure.WAKE_GESTURE_ENABLED, 0,
2275 UserHandle.USER_CURRENT) != 0;
2276 if (mWakeGestureEnabledSetting != wakeGestureEnabledSetting) {
2277 mWakeGestureEnabledSetting = wakeGestureEnabledSetting;
2278 updateWakeGestureListenerLp();
2279 }
2280
Jeff Brown207673cd2012-06-05 17:47:11 -07002281 // Configure rotation lock.
Christopher Tate5e08af02012-09-21 17:17:22 -07002282 int userRotation = Settings.System.getIntForUser(resolver,
2283 Settings.System.USER_ROTATION, Surface.ROTATION_0,
2284 UserHandle.USER_CURRENT);
Jeff Brown207673cd2012-06-05 17:47:11 -07002285 if (mUserRotation != userRotation) {
2286 mUserRotation = userRotation;
2287 updateRotation = true;
2288 }
Christopher Tate5e08af02012-09-21 17:17:22 -07002289 int userRotationMode = Settings.System.getIntForUser(resolver,
2290 Settings.System.ACCELEROMETER_ROTATION, 0, UserHandle.USER_CURRENT) != 0 ?
Jeff Brown207673cd2012-06-05 17:47:11 -07002291 WindowManagerPolicy.USER_ROTATION_FREE :
2292 WindowManagerPolicy.USER_ROTATION_LOCKED;
2293 if (mUserRotationMode != userRotationMode) {
2294 mUserRotationMode = userRotationMode;
2295 updateRotation = true;
Dianne Hackbornc777e072010-02-12 13:07:59 -08002296 updateOrientationListenerLp();
2297 }
Daniel Sandlerb73617d2010-08-17 00:41:00 -04002298
Dianne Hackbornc777e072010-02-12 13:07:59 -08002299 if (mSystemReady) {
Christopher Tate5e08af02012-09-21 17:17:22 -07002300 int pointerLocation = Settings.System.getIntForUser(resolver,
2301 Settings.System.POINTER_LOCATION, 0, UserHandle.USER_CURRENT);
Dianne Hackbornc777e072010-02-12 13:07:59 -08002302 if (mPointerLocationMode != pointerLocation) {
2303 mPointerLocationMode = pointerLocation;
Jeff Brown70825162012-03-28 17:27:48 -07002304 mHandler.sendEmptyMessage(pointerLocation != 0 ?
2305 MSG_ENABLE_POINTER_LOCATION : MSG_DISABLE_POINTER_LOCATION);
Dianne Hackbornc777e072010-02-12 13:07:59 -08002306 }
2307 }
2308 // use screen off timeout setting as the timeout for the lockscreen
Christopher Tate5e08af02012-09-21 17:17:22 -07002309 mLockScreenTimeout = Settings.System.getIntForUser(resolver,
2310 Settings.System.SCREEN_OFF_TIMEOUT, 0, UserHandle.USER_CURRENT);
2311 String imId = Settings.Secure.getStringForUser(resolver,
2312 Settings.Secure.DEFAULT_INPUT_METHOD, UserHandle.USER_CURRENT);
Dianne Hackbornc777e072010-02-12 13:07:59 -08002313 boolean hasSoftInput = imId != null && imId.length() > 0;
2314 if (mHasSoftInput != hasSoftInput) {
2315 mHasSoftInput = hasSoftInput;
2316 updateRotation = true;
2317 }
John Spurlockf1a36642013-10-12 17:50:42 -04002318 if (mImmersiveModeConfirmation != null) {
John Spurlock4355a532014-02-19 09:49:25 -05002319 mImmersiveModeConfirmation.loadSetting(mCurrentUserId);
John Spurlockd67ec252013-09-05 11:31:54 -04002320 }
tiger_huangcc6366d2015-06-29 17:17:30 +08002321 }
2322 synchronized (mWindowManagerFuncs.getWindowManagerLock()) {
John Spurlockc6d1c602014-01-17 15:22:06 -05002323 PolicyControl.reloadFromSetting(mContext);
Dianne Hackbornc777e072010-02-12 13:07:59 -08002324 }
2325 if (updateRotation) {
Jeff Brown01a98dd2011-09-20 15:08:29 -07002326 updateRotation(true);
Dianne Hackbornc777e072010-02-12 13:07:59 -08002327 }
Jeff Brown70825162012-03-28 17:27:48 -07002328 }
2329
Jeff Browna20dda42014-05-27 20:57:24 -07002330 private void updateWakeGestureListenerLp() {
2331 if (shouldEnableWakeGestureLp()) {
2332 mWakeGestureListener.requestWakeUpTrigger();
2333 } else {
2334 mWakeGestureListener.cancelWakeUpTrigger();
2335 }
2336 }
2337
2338 private boolean shouldEnableWakeGestureLp() {
Jeff Brown3ee549c2014-09-22 20:14:39 -07002339 return mWakeGestureEnabledSetting && !mAwake
Jeff Browna20dda42014-05-27 20:57:24 -07002340 && (!mLidControlsSleep || mLidState != LID_CLOSED)
2341 && mWakeGestureListener.isSupported();
2342 }
2343
Jeff Brown70825162012-03-28 17:27:48 -07002344 private void enablePointerLocation() {
2345 if (mPointerLocationView == null) {
2346 mPointerLocationView = new PointerLocationView(mContext);
2347 mPointerLocationView.setPrintCoords(false);
Dianne Hackbornc777e072010-02-12 13:07:59 -08002348 WindowManager.LayoutParams lp = new WindowManager.LayoutParams(
2349 WindowManager.LayoutParams.MATCH_PARENT,
2350 WindowManager.LayoutParams.MATCH_PARENT);
Jeff Brown3b2b3542010-10-15 00:54:27 -07002351 lp.type = WindowManager.LayoutParams.TYPE_SECURE_SYSTEM_OVERLAY;
Jeff Brownbfcb60a2011-09-08 18:51:14 -07002352 lp.flags = WindowManager.LayoutParams.FLAG_FULLSCREEN
2353 | WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE
2354 | WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE
2355 | WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN;
Jeff Brown90fc9052012-10-01 14:44:24 -07002356 if (ActivityManager.isHighEndGfx()) {
2357 lp.flags |= WindowManager.LayoutParams.FLAG_HARDWARE_ACCELERATED;
2358 lp.privateFlags |=
2359 WindowManager.LayoutParams.PRIVATE_FLAG_FORCE_HARDWARE_ACCELERATED;
2360 }
Dianne Hackbornc777e072010-02-12 13:07:59 -08002361 lp.format = PixelFormat.TRANSLUCENT;
2362 lp.setTitle("PointerLocation");
Andrii Kulianfb1bf692017-01-17 11:17:34 -08002363 WindowManager wm = (WindowManager) mContext.getSystemService(WINDOW_SERVICE);
Jeff Browncc4f7db2011-08-30 20:34:48 -07002364 lp.inputFeatures |= WindowManager.LayoutParams.INPUT_FEATURE_NO_INPUT_CHANNEL;
Jeff Brown70825162012-03-28 17:27:48 -07002365 wm.addView(mPointerLocationView, lp);
Michael Wrightc9c487e2013-11-07 18:55:09 -08002366 mWindowManagerFuncs.registerPointerEventListener(mPointerLocationView);
Dianne Hackbornc777e072010-02-12 13:07:59 -08002367 }
Dianne Hackbornc777e072010-02-12 13:07:59 -08002368 }
Jeff Brown70825162012-03-28 17:27:48 -07002369
2370 private void disablePointerLocation() {
Jeff Brown70825162012-03-28 17:27:48 -07002371 if (mPointerLocationView != null) {
Michael Wrightc9c487e2013-11-07 18:55:09 -08002372 mWindowManagerFuncs.unregisterPointerEventListener(mPointerLocationView);
Andrii Kulianfb1bf692017-01-17 11:17:34 -08002373 WindowManager wm = (WindowManager) mContext.getSystemService(WINDOW_SERVICE);
Jeff Brown70825162012-03-28 17:27:48 -07002374 wm.removeView(mPointerLocationView);
2375 mPointerLocationView = null;
2376 }
2377 }
2378
Mike Lockwood2d1efbd2009-09-16 12:15:53 -04002379 private int readRotation(int resID) {
Mike Lockwood1753f7f2009-08-24 14:49:07 -07002380 try {
2381 int rotation = mContext.getResources().getInteger(resID);
2382 switch (rotation) {
2383 case 0:
2384 return Surface.ROTATION_0;
2385 case 90:
2386 return Surface.ROTATION_90;
2387 case 180:
2388 return Surface.ROTATION_180;
2389 case 270:
2390 return Surface.ROTATION_270;
Mike Lockwood1753f7f2009-08-24 14:49:07 -07002391 }
2392 } catch (Resources.NotFoundException e) {
Mike Lockwood2d1efbd2009-09-16 12:15:53 -04002393 // fall through
Mike Lockwood1753f7f2009-08-24 14:49:07 -07002394 }
Mike Lockwood2d1efbd2009-09-16 12:15:53 -04002395 return -1;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002396 }
2397
2398 /** {@inheritDoc} */
Craig Mautner88400d32012-09-30 12:35:45 -07002399 @Override
Dianne Hackbornc2293022013-02-06 23:14:49 -08002400 public int checkAddPermission(WindowManager.LayoutParams attrs, int[] outAppOp) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002401 int type = attrs.type;
Dianne Hackbornc2293022013-02-06 23:14:49 -08002402
2403 outAppOp[0] = AppOpsManager.OP_NONE;
2404
Wale Ogunwale74bf0652015-01-12 10:24:36 -08002405 if (!((type >= FIRST_APPLICATION_WINDOW && type <= LAST_APPLICATION_WINDOW)
2406 || (type >= FIRST_SUB_WINDOW && type <= LAST_SUB_WINDOW)
2407 || (type >= FIRST_SYSTEM_WINDOW && type <= LAST_SYSTEM_WINDOW))) {
2408 return WindowManagerGlobal.ADD_INVALID_TYPE;
2409 }
2410
2411 if (type < FIRST_SYSTEM_WINDOW || type > LAST_SYSTEM_WINDOW) {
2412 // Window manager will make sure these are okay.
Wale Ogunwale5cd907d2017-01-26 14:14:08 -08002413 return ADD_OKAY;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002414 }
Wale Ogunwale5cd907d2017-01-26 14:14:08 -08002415
2416 if (!isSystemAlertWindowType(type)) {
2417 switch (type) {
2418 case TYPE_TOAST:
2419 // Only apps that target older than O SDK can add window without a token, after
2420 // that we require a token so apps cannot add toasts directly as the token is
2421 // added by the notification system.
2422 // Window manager does the checking for this.
2423 outAppOp[0] = OP_TOAST_WINDOW;
2424 return ADD_OKAY;
2425 case TYPE_DREAM:
2426 case TYPE_INPUT_METHOD:
2427 case TYPE_WALLPAPER:
2428 case TYPE_PRESENTATION:
2429 case TYPE_PRIVATE_PRESENTATION:
2430 case TYPE_VOICE_INTERACTION:
2431 case TYPE_ACCESSIBILITY_OVERLAY:
2432 case TYPE_QS_DIALOG:
2433 // The window manager will check these.
2434 return ADD_OKAY;
2435 }
2436 return mContext.checkCallingOrSelfPermission(INTERNAL_SYSTEM_WINDOW)
2437 == PERMISSION_GRANTED ? ADD_OKAY : ADD_PERMISSION_DENIED;
2438 }
2439
2440 // Things get a little more interesting for alert windows...
2441 outAppOp[0] = OP_SYSTEM_ALERT_WINDOW;
2442
2443 final int callingUid = Binder.getCallingUid();
2444 // system processes will be automatically granted privilege to draw
2445 if (UserHandle.getAppId(callingUid) == Process.SYSTEM_UID) {
2446 return ADD_OKAY;
2447 }
2448
2449 ApplicationInfo appInfo;
2450 try {
Tony Mak22295fd2017-03-20 16:17:54 +00002451 appInfo = mContext.getPackageManager().getApplicationInfoAsUser(
2452 attrs.packageName,
2453 0 /* flags */,
Wale Ogunwale5cd907d2017-01-26 14:14:08 -08002454 UserHandle.getUserId(callingUid));
2455 } catch (PackageManager.NameNotFoundException e) {
2456 appInfo = null;
2457 }
2458
2459 if (appInfo == null || (type != TYPE_APPLICATION_OVERLAY && appInfo.targetSdkVersion >= O)) {
2460 /**
2461 * Apps targeting >= {@link Build.VERSION_CODES#O} are required to hold
2462 * {@link android.Manifest.permission#INTERNAL_SYSTEM_WINDOW} (system signature apps)
2463 * permission to add alert windows that aren't
2464 * {@link android.view.WindowManager.LayoutParams#TYPE_APPLICATION_OVERLAY}.
2465 */
Wale Ogunwale5aa86832017-02-28 10:40:27 -08002466 return (mContext.checkCallingOrSelfPermission(INTERNAL_SYSTEM_WINDOW)
2467 == PERMISSION_GRANTED) ? ADD_OKAY : ADD_PERMISSION_DENIED;
Wale Ogunwale5cd907d2017-01-26 14:14:08 -08002468 }
2469
2470 // check if user has enabled this operation. SecurityException will be thrown if this app
2471 // has not been allowed by the user
2472 final int mode = mAppOpsManager.checkOpNoThrow(outAppOp[0], callingUid, attrs.packageName);
2473 switch (mode) {
2474 case AppOpsManager.MODE_ALLOWED:
2475 case AppOpsManager.MODE_IGNORED:
2476 // although we return ADD_OKAY for MODE_IGNORED, the added window will
2477 // actually be hidden in WindowManagerService
2478 return ADD_OKAY;
2479 case AppOpsManager.MODE_ERRORED:
2480 // Don't crash legacy apps
2481 if (appInfo.targetSdkVersion < M) {
2482 return ADD_OKAY;
2483 }
2484 return ADD_PERMISSION_DENIED;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002485 default:
Wale Ogunwale5cd907d2017-01-26 14:14:08 -08002486 // in the default mode, we will make a decision here based on
2487 // checkCallingPermission()
Wale Ogunwale5aa86832017-02-28 10:40:27 -08002488 return (mContext.checkCallingOrSelfPermission(SYSTEM_ALERT_WINDOW)
2489 == PERMISSION_GRANTED) ? ADD_OKAY : ADD_PERMISSION_DENIED;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002490 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002491 }
Craig Mautner88400d32012-09-30 12:35:45 -07002492
2493 @Override
2494 public boolean checkShowToOwnerOnly(WindowManager.LayoutParams attrs) {
2495
2496 // If this switch statement is modified, modify the comment in the declarations of
2497 // the type in {@link WindowManager.LayoutParams} as well.
2498 switch (attrs.type) {
2499 default:
2500 // These are the windows that by default are shown only to the user that created
2501 // them. If this needs to be overridden, set
2502 // {@link WindowManager.LayoutParams.PRIVATE_FLAG_SHOW_FOR_ALL_USERS} in
2503 // {@link WindowManager.LayoutParams}. Note that permission
2504 // {@link android.Manifest.permission.INTERNAL_SYSTEM_WINDOW} is required as well.
2505 if ((attrs.privateFlags & PRIVATE_FLAG_SHOW_FOR_ALL_USERS) == 0) {
2506 return true;
2507 }
2508 break;
2509
2510 // These are the windows that by default are shown to all users. However, to
2511 // protect against spoofing, check permissions below.
2512 case TYPE_APPLICATION_STARTING:
2513 case TYPE_BOOT_PROGRESS:
2514 case TYPE_DISPLAY_OVERLAY:
Selim Cinekf83e8242015-05-19 18:08:14 -07002515 case TYPE_INPUT_CONSUMER:
Craig Mautner88400d32012-09-30 12:35:45 -07002516 case TYPE_KEYGUARD_DIALOG:
2517 case TYPE_MAGNIFICATION_OVERLAY:
2518 case TYPE_NAVIGATION_BAR:
2519 case TYPE_NAVIGATION_BAR_PANEL:
2520 case TYPE_PHONE:
2521 case TYPE_POINTER:
2522 case TYPE_PRIORITY_PHONE:
Craig Mautner88400d32012-09-30 12:35:45 -07002523 case TYPE_SEARCH_BAR:
2524 case TYPE_STATUS_BAR:
2525 case TYPE_STATUS_BAR_PANEL:
2526 case TYPE_STATUS_BAR_SUB_PANEL:
2527 case TYPE_SYSTEM_DIALOG:
Craig Mautner88400d32012-09-30 12:35:45 -07002528 case TYPE_VOLUME_OVERLAY:
Wale Ogunwale5b6714c2016-11-01 20:54:46 -07002529 case TYPE_PRESENTATION:
keunyounga446bf02013-06-21 19:07:57 -07002530 case TYPE_PRIVATE_PRESENTATION:
Filip Gruszczynski466f3212015-09-21 17:57:57 -07002531 case TYPE_DOCK_DIVIDER:
Craig Mautner88400d32012-09-30 12:35:45 -07002532 break;
2533 }
2534
2535 // Check if third party app has set window to system window type.
Wale Ogunwale5cd907d2017-01-26 14:14:08 -08002536 return mContext.checkCallingOrSelfPermission(INTERNAL_SYSTEM_WINDOW) != PERMISSION_GRANTED;
Craig Mautner88400d32012-09-30 12:35:45 -07002537 }
2538
Craig Mautner967212c2013-04-13 21:10:58 -07002539 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002540 public void adjustWindowParamsLw(WindowManager.LayoutParams attrs) {
2541 switch (attrs.type) {
2542 case TYPE_SYSTEM_OVERLAY:
Jeff Brown3b2b3542010-10-15 00:54:27 -07002543 case TYPE_SECURE_SYSTEM_OVERLAY:
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002544 // These types of windows can't receive input events.
2545 attrs.flags |= WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE
2546 | WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE;
Jeff Brownbfcb60a2011-09-08 18:51:14 -07002547 attrs.flags &= ~WindowManager.LayoutParams.FLAG_WATCH_OUTSIDE_TOUCH;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002548 break;
Jorim Jaggi380ecb82014-03-14 17:25:20 +01002549 case TYPE_STATUS_BAR:
2550
2551 // If the Keyguard is in a hidden state (occluded by another window), we force to
2552 // remove the wallpaper and keyguard flag so that any change in-flight after setting
2553 // the keyguard as occluded wouldn't set these flags again.
2554 // See {@link #processKeyguardSetHiddenResultLw}.
Jorim Jaggife762342016-10-13 14:33:27 +02002555 if (mKeyguardOccluded) {
Jorim Jaggi380ecb82014-03-14 17:25:20 +01002556 attrs.flags &= ~WindowManager.LayoutParams.FLAG_SHOW_WALLPAPER;
2557 attrs.privateFlags &= ~WindowManager.LayoutParams.PRIVATE_FLAG_KEYGUARD;
2558 }
2559 break;
Svetoslav Ganovaa076532016-08-01 19:16:43 -07002560
Muyuan Li36ca72c2016-08-06 20:24:06 -07002561 case TYPE_SCREENSHOT:
2562 attrs.flags |= WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE;
2563 break;
Svetoslav Ganovaa076532016-08-01 19:16:43 -07002564
2565 case TYPE_TOAST:
2566 // While apps should use the dedicated toast APIs to add such windows
2567 // it possible legacy apps to add the window directly. Therefore, we
2568 // make windows added directly by the app behave as a toast as much
2569 // as possible in terms of timeout and animation.
2570 if (attrs.hideTimeoutMilliseconds < 0
2571 || attrs.hideTimeoutMilliseconds > TOAST_WINDOW_TIMEOUT) {
2572 attrs.hideTimeoutMilliseconds = TOAST_WINDOW_TIMEOUT;
2573 }
2574 attrs.windowAnimations = com.android.internal.R.style.Animation_Toast;
2575 break;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002576 }
Adrian Roos38502112014-04-09 21:04:11 +02002577
2578 if (attrs.type != TYPE_STATUS_BAR) {
2579 // The status bar is the only window allowed to exhibit keyguard behavior.
2580 attrs.privateFlags &= ~WindowManager.LayoutParams.PRIVATE_FLAG_KEYGUARD;
2581 }
Adrian Roosea562512014-05-05 13:33:03 +02002582
Jorim Jaggi4fa78922015-11-30 17:13:56 -08002583 if (ActivityManager.isHighEndGfx()) {
2584 if ((attrs.flags & FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS) != 0) {
2585 attrs.subtreeSystemUiVisibility |= View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION;
2586 }
Jorim Jaggi8f5701b2016-04-04 18:36:02 -07002587 final boolean forceWindowDrawsStatusBarBackground =
2588 (attrs.privateFlags & PRIVATE_FLAG_FORCE_DRAW_STATUS_BAR_BACKGROUND)
2589 != 0;
Jorim Jaggi4fa78922015-11-30 17:13:56 -08002590 if ((attrs.flags & FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS) != 0
Jorim Jaggi8f5701b2016-04-04 18:36:02 -07002591 || forceWindowDrawsStatusBarBackground
2592 && attrs.height == MATCH_PARENT && attrs.width == MATCH_PARENT) {
Jorim Jaggi4fa78922015-11-30 17:13:56 -08002593 attrs.subtreeSystemUiVisibility |= View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN;
2594 }
Adrian Roosea562512014-05-05 13:33:03 +02002595 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002596 }
RoboErik8a2cfc32014-05-16 11:19:38 -07002597
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002598 void readLidState() {
Jeff Brown2e7760e2012-04-11 15:14:55 -07002599 mLidState = mWindowManagerFuncs.getLidState();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002600 }
RoboErik8a2cfc32014-05-16 11:19:38 -07002601
Michael Wright3818c922014-09-02 13:59:07 -07002602 private void readCameraLensCoverState() {
2603 mCameraLensCoverState = mWindowManagerFuncs.getCameraLensCoverState();
2604 }
2605
Jeff Browndaa37532012-05-01 15:54:03 -07002606 private boolean isHidden(int accessibilityMode) {
2607 switch (accessibilityMode) {
2608 case 1:
2609 return mLidState == LID_CLOSED;
2610 case 2:
2611 return mLidState == LID_OPEN;
2612 default:
2613 return false;
Dianne Hackborn2862fff2009-09-15 22:56:29 -07002614 }
Dianne Hackborn2862fff2009-09-15 22:56:29 -07002615 }
Jeff Brownd04a88c2011-01-16 14:05:47 -08002616
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002617 /** {@inheritDoc} */
Craig Mautner967212c2013-04-13 21:10:58 -07002618 @Override
Jeff Browndaa37532012-05-01 15:54:03 -07002619 public void adjustConfigurationLw(Configuration config, int keyboardPresence,
2620 int navigationPresence) {
2621 mHaveBuiltInKeyboard = (keyboardPresence & PRESENCE_INTERNAL) != 0;
2622
Jeff Brownf71343d2013-05-31 17:59:11 -07002623 readConfigurationDependentBehaviors();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002624 readLidState();
Jeff Brownd04a88c2011-01-16 14:05:47 -08002625
Jeff Browndaa37532012-05-01 15:54:03 -07002626 if (config.keyboard == Configuration.KEYBOARD_NOKEYS
2627 || (keyboardPresence == PRESENCE_INTERNAL
2628 && isHidden(mLidKeyboardAccessibility))) {
Jeff Brownd04a88c2011-01-16 14:05:47 -08002629 config.hardKeyboardHidden = Configuration.HARDKEYBOARDHIDDEN_YES;
Jeff Browndaa37532012-05-01 15:54:03 -07002630 if (!mHasSoftInput) {
2631 config.keyboardHidden = Configuration.KEYBOARDHIDDEN_YES;
2632 }
Jeff Brownd04a88c2011-01-16 14:05:47 -08002633 }
2634
Jeff Browndaa37532012-05-01 15:54:03 -07002635 if (config.navigation == Configuration.NAVIGATION_NONAV
2636 || (navigationPresence == PRESENCE_INTERNAL
2637 && isHidden(mLidNavigationAccessibility))) {
Jeff Brownd04a88c2011-01-16 14:05:47 -08002638 config.navigationHidden = Configuration.NAVIGATIONHIDDEN_YES;
Jeff Brownd04a88c2011-01-16 14:05:47 -08002639 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002640 }
Jeff Brownd04a88c2011-01-16 14:05:47 -08002641
Jorim Jaggi11c62e12016-04-05 20:41:21 -07002642 @Override
2643 public void onConfigurationChanged() {
Andrii Kulian3a507b52016-09-19 18:14:12 -07002644 // TODO(multi-display): Define policy for secondary displays.
Jorim Jaggi11c62e12016-04-05 20:41:21 -07002645 final Resources res = mContext.getResources();
2646
2647 mStatusBarHeight =
2648 res.getDimensionPixelSize(com.android.internal.R.dimen.status_bar_height);
2649
2650 // Height of the navigation bar when presented horizontally at bottom
2651 mNavigationBarHeightForRotationDefault[mPortraitRotation] =
2652 mNavigationBarHeightForRotationDefault[mUpsideDownRotation] =
2653 res.getDimensionPixelSize(com.android.internal.R.dimen.navigation_bar_height);
2654 mNavigationBarHeightForRotationDefault[mLandscapeRotation] =
2655 mNavigationBarHeightForRotationDefault[mSeascapeRotation] = res.getDimensionPixelSize(
2656 com.android.internal.R.dimen.navigation_bar_height_landscape);
2657
2658 // Width of the navigation bar when presented vertically along one side
2659 mNavigationBarWidthForRotationDefault[mPortraitRotation] =
2660 mNavigationBarWidthForRotationDefault[mUpsideDownRotation] =
2661 mNavigationBarWidthForRotationDefault[mLandscapeRotation] =
2662 mNavigationBarWidthForRotationDefault[mSeascapeRotation] =
2663 res.getDimensionPixelSize(com.android.internal.R.dimen.navigation_bar_width);
2664
Justin Paupore01915a12016-09-28 17:41:26 -07002665 if (ALTERNATE_CAR_MODE_NAV_SIZE) {
2666 // Height of the navigation bar when presented horizontally at bottom
2667 mNavigationBarHeightForRotationInCarMode[mPortraitRotation] =
2668 mNavigationBarHeightForRotationInCarMode[mUpsideDownRotation] =
2669 res.getDimensionPixelSize(
2670 com.android.internal.R.dimen.navigation_bar_height_car_mode);
2671 mNavigationBarHeightForRotationInCarMode[mLandscapeRotation] =
2672 mNavigationBarHeightForRotationInCarMode[mSeascapeRotation] = res.getDimensionPixelSize(
2673 com.android.internal.R.dimen.navigation_bar_height_landscape_car_mode);
Jorim Jaggi11c62e12016-04-05 20:41:21 -07002674
Justin Paupore01915a12016-09-28 17:41:26 -07002675 // Width of the navigation bar when presented vertically along one side
2676 mNavigationBarWidthForRotationInCarMode[mPortraitRotation] =
2677 mNavigationBarWidthForRotationInCarMode[mUpsideDownRotation] =
2678 mNavigationBarWidthForRotationInCarMode[mLandscapeRotation] =
2679 mNavigationBarWidthForRotationInCarMode[mSeascapeRotation] =
2680 res.getDimensionPixelSize(
2681 com.android.internal.R.dimen.navigation_bar_width_car_mode);
2682 }
Jorim Jaggi11c62e12016-04-05 20:41:21 -07002683 }
2684
Craig Mautner46ac6fa2013-08-01 10:06:34 -07002685 @Override
Dianne Hackbornabe0da02009-09-18 01:55:39 -07002686 public int getMaxWallpaperLayer() {
Wale Ogunwale5cd907d2017-01-26 14:14:08 -08002687 return getWindowLayerFromTypeLw(TYPE_STATUS_BAR);
Dianne Hackbornabe0da02009-09-18 01:55:39 -07002688 }
2689
Sriram Viswanathan9ebbe6a2015-11-16 17:59:22 -08002690 private int getNavigationBarWidth(int rotation, int uiMode) {
Justin Paupore01915a12016-09-28 17:41:26 -07002691 if (ALTERNATE_CAR_MODE_NAV_SIZE && (uiMode & UI_MODE_TYPE_MASK) == UI_MODE_TYPE_CAR) {
Sriram Viswanathan9ebbe6a2015-11-16 17:59:22 -08002692 return mNavigationBarWidthForRotationInCarMode[rotation];
2693 } else {
2694 return mNavigationBarWidthForRotationDefault[rotation];
2695 }
2696 }
2697
Craig Mautner46ac6fa2013-08-01 10:06:34 -07002698 @Override
Andrii Kuliandb8e1062016-11-15 18:30:27 -08002699 public int getNonDecorDisplayWidth(int fullWidth, int fullHeight, int rotation, int uiMode,
2700 int displayId) {
2701 // TODO(multi-display): Support navigation bar on secondary displays.
2702 if (displayId == Display.DEFAULT_DISPLAY && mHasNavigationBar) {
Dianne Hackborn077ee852012-04-09 16:27:07 -07002703 // For a basic navigation bar, when we are in landscape mode we place
2704 // the navigation bar to the side.
Daniel Sandler4a066c52012-04-20 14:49:13 -04002705 if (mNavigationBarCanMove && fullWidth > fullHeight) {
Sriram Viswanathan9ebbe6a2015-11-16 17:59:22 -08002706 return fullWidth - getNavigationBarWidth(rotation, uiMode);
Dianne Hackborn077ee852012-04-09 16:27:07 -07002707 }
Dianne Hackborn1f903c32011-09-13 19:18:06 -07002708 }
2709 return fullWidth;
Dianne Hackborne2515ee2011-04-27 18:52:56 -04002710 }
2711
Sriram Viswanathan9ebbe6a2015-11-16 17:59:22 -08002712 private int getNavigationBarHeight(int rotation, int uiMode) {
Justin Paupore01915a12016-09-28 17:41:26 -07002713 if (ALTERNATE_CAR_MODE_NAV_SIZE && (uiMode & UI_MODE_TYPE_MASK) == UI_MODE_TYPE_CAR) {
Sriram Viswanathan9ebbe6a2015-11-16 17:59:22 -08002714 return mNavigationBarHeightForRotationInCarMode[rotation];
2715 } else {
2716 return mNavigationBarHeightForRotationDefault[rotation];
2717 }
2718 }
2719
Jose Lima9546b202014-07-02 17:21:51 -07002720 @Override
Andrii Kuliandb8e1062016-11-15 18:30:27 -08002721 public int getNonDecorDisplayHeight(int fullWidth, int fullHeight, int rotation, int uiMode,
2722 int displayId) {
2723 // TODO(multi-display): Support navigation bar on secondary displays.
2724 if (displayId == Display.DEFAULT_DISPLAY && mHasNavigationBar) {
Dianne Hackborn077ee852012-04-09 16:27:07 -07002725 // For a basic navigation bar, when we are in portrait mode we place
2726 // the navigation bar to the bottom.
Daniel Sandler4a066c52012-04-20 14:49:13 -04002727 if (!mNavigationBarCanMove || fullWidth < fullHeight) {
Sriram Viswanathan9ebbe6a2015-11-16 17:59:22 -08002728 return fullHeight - getNavigationBarHeight(rotation, uiMode);
Dianne Hackborn077ee852012-04-09 16:27:07 -07002729 }
2730 }
2731 return fullHeight;
Dianne Hackborn69cb8752011-05-19 18:13:32 -07002732 }
2733
Jose Lima9546b202014-07-02 17:21:51 -07002734 @Override
Andrii Kuliandb8e1062016-11-15 18:30:27 -08002735 public int getConfigDisplayWidth(int fullWidth, int fullHeight, int rotation, int uiMode,
2736 int displayId) {
2737 return getNonDecorDisplayWidth(fullWidth, fullHeight, rotation, uiMode, displayId);
Dianne Hackborn69cb8752011-05-19 18:13:32 -07002738 }
2739
Jose Lima9546b202014-07-02 17:21:51 -07002740 @Override
Andrii Kuliandb8e1062016-11-15 18:30:27 -08002741 public int getConfigDisplayHeight(int fullWidth, int fullHeight, int rotation, int uiMode,
2742 int displayId) {
John Spurlock80f00c12013-06-13 11:10:51 -04002743 // There is a separate status bar at the top of the display. We don't count that as part
2744 // of the fixed decor, since it can hide; however, for purposes of configurations,
Dianne Hackborn077ee852012-04-09 16:27:07 -07002745 // we do want to exclude it since applications can't generally use that part
2746 // of the screen.
Andrii Kuliandb8e1062016-11-15 18:30:27 -08002747 // TODO(multi-display): Support status bars on secondary displays.
2748 if (displayId == Display.DEFAULT_DISPLAY) {
2749 return getNonDecorDisplayHeight(fullWidth, fullHeight, rotation, uiMode, displayId)
2750 - mStatusBarHeight;
2751 }
2752 return fullHeight;
Dianne Hackborne2515ee2011-04-27 18:52:56 -04002753 }
2754
Craig Mautnera3f4bf52012-10-10 20:37:48 -07002755 @Override
Jorim Jaggi0d674622014-05-21 01:34:15 +02002756 public boolean isKeyguardHostWindow(WindowManager.LayoutParams attrs) {
2757 return attrs.type == TYPE_STATUS_BAR;
2758 }
2759
2760 @Override
Jorim Jaggife762342016-10-13 14:33:27 +02002761 public boolean canBeHiddenByKeyguardLw(WindowState win) {
2762 switch (win.getAttrs().type) {
Craig Mautnera3f4bf52012-10-10 20:37:48 -07002763 case TYPE_STATUS_BAR:
2764 case TYPE_NAVIGATION_BAR:
2765 case TYPE_WALLPAPER:
2766 case TYPE_DREAM:
Craig Mautnera3f4bf52012-10-10 20:37:48 -07002767 return false;
2768 default:
Adrian Roos461829d2015-06-03 14:41:18 -07002769 // Hide only windows below the keyguard host window.
Wale Ogunwale5cd907d2017-01-26 14:14:08 -08002770 return getWindowLayerLw(win) < getWindowLayerFromTypeLw(TYPE_STATUS_BAR);
Craig Mautnera3f4bf52012-10-10 20:37:48 -07002771 }
Dianne Hackborn01ad2f42009-09-24 19:24:56 -07002772 }
Craig Mautner8e4df6c2012-05-23 16:57:23 -07002773
Jorim Jaggife762342016-10-13 14:33:27 +02002774 private boolean shouldBeHiddenByKeyguard(WindowState win, WindowState imeTarget) {
2775
2776 // Keyguard visibility of window from activities are determined over activity visibility.
2777 if (win.getAppToken() != null) {
2778 return false;
2779 }
2780
2781 final LayoutParams attrs = win.getAttrs();
2782 final boolean showImeOverKeyguard = imeTarget != null && imeTarget.isVisibleLw() &&
2783 ((imeTarget.getAttrs().flags & FLAG_SHOW_WHEN_LOCKED) != 0
2784 || !canBeHiddenByKeyguardLw(imeTarget));
2785
2786 // Show IME over the keyguard if the target allows it
2787 boolean allowWhenLocked = (win.isInputMethodWindow() || imeTarget == this)
2788 && showImeOverKeyguard;;
2789
2790 if (isKeyguardLocked() && isKeyguardOccluded()) {
2791 // Show SHOW_WHEN_LOCKED windows if Keyguard is occluded.
2792 allowWhenLocked |= (attrs.flags & FLAG_SHOW_WHEN_LOCKED) != 0
2793 // Show error dialogs over apps that are shown on lockscreen
2794 || (attrs.privateFlags & PRIVATE_FLAG_SYSTEM_ERROR) != 0;
2795 }
2796
2797 boolean keyguardLocked = isKeyguardLocked();
2798 boolean hideDockDivider = attrs.type == TYPE_DOCK_DIVIDER
2799 && !mWindowManagerInternal.isStackVisible(DOCKED_STACK_ID);
2800 return (keyguardLocked && !allowWhenLocked && win.getDisplayId() == Display.DEFAULT_DISPLAY)
2801 || hideDockDivider;
Craig Mautner7d7808f2014-09-11 18:02:38 -07002802 }
2803
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002804 /** {@inheritDoc} */
Craig Mautner8e4df6c2012-05-23 16:57:23 -07002805 @Override
Jorim Jaggiba41f4b2016-12-14 17:43:07 -08002806 public StartingSurface addSplashScreen(IBinder appToken, String packageName, int theme,
2807 CompatibilityInfo compatInfo, CharSequence nonLocalizedLabel, int labelRes, int icon,
Andrii Kulianfb1bf692017-01-17 11:17:34 -08002808 int logo, int windowFlags, Configuration overrideConfig, int displayId) {
Jorim Jaggiba41f4b2016-12-14 17:43:07 -08002809 if (!SHOW_SPLASH_SCREENS) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002810 return null;
2811 }
2812 if (packageName == null) {
2813 return null;
2814 }
Craig Mautner8e4df6c2012-05-23 16:57:23 -07002815
Mathias Jeppssond1443e92012-08-24 15:25:32 +02002816 WindowManager wm = null;
2817 View view = null;
2818
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002819 try {
Dianne Hackborn867ab6472010-04-29 13:28:56 -07002820 Context context = mContext;
Jorim Jaggiba41f4b2016-12-14 17:43:07 -08002821 if (DEBUG_SPLASH_SCREEN) Slog.d(TAG, "addSplashScreen " + packageName
Craig Mautner6fbda632012-07-03 09:26:39 -07002822 + ": nonLocalizedLabel=" + nonLocalizedLabel + " theme="
2823 + Integer.toHexString(theme));
Andrii Kulianb047b8b2017-02-08 18:38:26 -08002824
2825 // Obtain proper context to launch on the right display.
2826 final Context displayContext = getDisplayContext(context, displayId);
2827 if (displayContext == null) {
2828 // Can't show splash screen on requested display, so skip showing at all.
2829 return null;
2830 }
2831 context = displayContext;
2832
Dianne Hackborn247fe742011-01-08 17:25:57 -08002833 if (theme != context.getThemeResId() || labelRes != 0) {
Dianne Hackborn867ab6472010-04-29 13:28:56 -07002834 try {
Robert Carr7ad24ba2017-06-20 17:26:06 -07002835 context = context.createPackageContext(packageName, CONTEXT_RESTRICTED);
Dianne Hackborn247fe742011-01-08 17:25:57 -08002836 context.setTheme(theme);
Dianne Hackborn867ab6472010-04-29 13:28:56 -07002837 } catch (PackageManager.NameNotFoundException e) {
2838 // Ignore
2839 }
2840 }
Craig Mautner8e4df6c2012-05-23 16:57:23 -07002841
Andrii Kuliana8a9bc52016-10-14 11:00:13 -07002842 if (overrideConfig != null && !overrideConfig.equals(EMPTY)) {
Jorim Jaggiba41f4b2016-12-14 17:43:07 -08002843 if (DEBUG_SPLASH_SCREEN) Slog.d(TAG, "addSplashScreen: creating context based"
2844 + " on overrideConfig" + overrideConfig + " for splash screen");
Wale Ogunwaledfc18622016-04-16 15:08:48 -07002845 final Context overrideContext = context.createConfigurationContext(overrideConfig);
2846 overrideContext.setTheme(theme);
2847 final TypedArray typedArray = overrideContext.obtainStyledAttributes(
2848 com.android.internal.R.styleable.Window);
2849 final int resId = typedArray.getResourceId(R.styleable.Window_windowBackground, 0);
2850 if (resId != 0 && overrideContext.getDrawable(resId) != null) {
2851 // We want to use the windowBackground for the override context if it is
2852 // available, otherwise we use the default one to make sure a themed starting
2853 // window is displayed for the app.
Jorim Jaggiba41f4b2016-12-14 17:43:07 -08002854 if (DEBUG_SPLASH_SCREEN) Slog.d(TAG, "addSplashScreen: apply overrideConfig"
Wale Ogunwaledfc18622016-04-16 15:08:48 -07002855 + overrideConfig + " to starting window resId=" + resId);
2856 context = overrideContext;
2857 }
Jorim Jaggi7d0d1022017-02-23 15:35:51 +01002858 typedArray.recycle();
Wale Ogunwaledfc18622016-04-16 15:08:48 -07002859 }
2860
2861 final PhoneWindow win = new PhoneWindow(context);
Jorim Jaggia16cc152015-06-01 16:55:05 -07002862 win.setIsStartingWindow(true);
Craig Mautner8e4df6c2012-05-23 16:57:23 -07002863
Phil Weaver155edc62016-06-09 10:24:53 -07002864 CharSequence label = context.getResources().getText(labelRes, null);
2865 // Only change the accessibility title if the label is localized
2866 if (label != null) {
2867 win.setTitle(label, true);
2868 } else {
2869 win.setTitle(nonLocalizedLabel, false);
2870 }
Craig Mautner8e4df6c2012-05-23 16:57:23 -07002871
Dianne Hackborn867ab6472010-04-29 13:28:56 -07002872 win.setType(
2873 WindowManager.LayoutParams.TYPE_APPLICATION_STARTING);
Adrian Roos602c68e2015-04-24 16:03:47 -07002874
2875 synchronized (mWindowManagerFuncs.getWindowManagerLock()) {
2876 // Assumes it's safe to show starting windows of launched apps while
2877 // the keyguard is being hidden. This is okay because starting windows never show
2878 // secret information.
Jorim Jaggife762342016-10-13 14:33:27 +02002879 if (mKeyguardOccluded) {
Adrian Roos602c68e2015-04-24 16:03:47 -07002880 windowFlags |= FLAG_SHOW_WHEN_LOCKED;
2881 }
2882 }
2883
Dianne Hackborn867ab6472010-04-29 13:28:56 -07002884 // Force the window flags: this is a fake window, so it is not really
2885 // touchable or focusable by the user. We also add in the ALT_FOCUSABLE_IM
2886 // flag because we do know that the next window will take input
2887 // focus, so we want to get the IME window up on top of us right away.
2888 win.setFlags(
Dianne Hackborn7eec10e2010-11-12 18:03:47 -08002889 windowFlags|
Dianne Hackborn867ab6472010-04-29 13:28:56 -07002890 WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE|
2891 WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE|
2892 WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM,
Dianne Hackborn7eec10e2010-11-12 18:03:47 -08002893 windowFlags|
Dianne Hackborn867ab6472010-04-29 13:28:56 -07002894 WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE|
2895 WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE|
2896 WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM);
Craig Mautner8e4df6c2012-05-23 16:57:23 -07002897
Adam Powell04fe6eb2013-05-31 14:39:48 -07002898 win.setDefaultIcon(icon);
2899 win.setDefaultLogo(logo);
2900
Dianne Hackborn867ab6472010-04-29 13:28:56 -07002901 win.setLayout(WindowManager.LayoutParams.MATCH_PARENT,
Dianne Hackborn2f0b1752011-05-31 17:59:49 -07002902 WindowManager.LayoutParams.MATCH_PARENT);
Craig Mautner8e4df6c2012-05-23 16:57:23 -07002903
Phil Weaver266ed9a2016-06-08 00:34:40 +00002904 final WindowManager.LayoutParams params = win.getAttributes();
Dianne Hackborn867ab6472010-04-29 13:28:56 -07002905 params.token = appToken;
2906 params.packageName = packageName;
2907 params.windowAnimations = win.getWindowStyle().getResourceId(
2908 com.android.internal.R.styleable.Window_windowAnimationStyle, 0);
John Reck61375a82014-09-18 19:27:48 +00002909 params.privateFlags |=
2910 WindowManager.LayoutParams.PRIVATE_FLAG_FAKE_HARDWARE_ACCELERATED;
Craig Mautner88400d32012-09-30 12:35:45 -07002911 params.privateFlags |= WindowManager.LayoutParams.PRIVATE_FLAG_SHOW_FOR_ALL_USERS;
Adam Lesinski95c42972013-10-02 10:13:27 -07002912
2913 if (!compatInfo.supportsScreen()) {
2914 params.privateFlags |= WindowManager.LayoutParams.PRIVATE_FLAG_COMPATIBLE_WINDOW;
2915 }
2916
Jorim Jaggiba41f4b2016-12-14 17:43:07 -08002917 params.setTitle("Splash Screen " + packageName);
Jorim Jaggi7d0d1022017-02-23 15:35:51 +01002918 addSplashscreenContent(win, context);
2919
Andrii Kulianb047b8b2017-02-08 18:38:26 -08002920 wm = (WindowManager) context.getSystemService(WINDOW_SERVICE);
Mathias Jeppssond1443e92012-08-24 15:25:32 +02002921 view = win.getDecorView();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002922
Jorim Jaggiba41f4b2016-12-14 17:43:07 -08002923 if (DEBUG_SPLASH_SCREEN) Slog.d(TAG, "Adding splash screen window for "
Wale Ogunwaledfc18622016-04-16 15:08:48 -07002924 + packageName + " / " + appToken + ": " + (view.getParent() != null ? view : null));
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002925
2926 wm.addView(view, params);
2927
2928 // Only return the view if it was successfully added to the
2929 // window manager... which we can tell by it having a parent.
Jorim Jaggi02886a82016-12-06 09:10:06 -08002930 return view.getParent() != null ? new SplashScreenSurface(view, appToken) : null;
Jeff Brown98365d72012-08-19 20:30:52 -07002931 } catch (WindowManager.BadTokenException e) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002932 // ignore
Craig Mautner42bf39e2014-02-21 16:46:22 -08002933 Log.w(TAG, appToken + " already running, starting window not displayed. " +
2934 e.getMessage());
Dianne Hackborn867ab6472010-04-29 13:28:56 -07002935 } catch (RuntimeException e) {
2936 // don't crash if something else bad happens, for example a
2937 // failure loading resources because we are loading from an app
2938 // on external storage that has been unmounted.
2939 Log.w(TAG, appToken + " failed creating starting window", e);
Mathias Jeppssond1443e92012-08-24 15:25:32 +02002940 } finally {
2941 if (view != null && view.getParent() == null) {
2942 Log.w(TAG, "view not successfully added to wm, removing view");
2943 wm.removeViewImmediate(view);
2944 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002945 }
2946
2947 return null;
2948 }
2949
Jorim Jaggi7d0d1022017-02-23 15:35:51 +01002950 private void addSplashscreenContent(PhoneWindow win, Context ctx) {
2951 final TypedArray a = ctx.obtainStyledAttributes(R.styleable.Window);
2952 final int resId = a.getResourceId(R.styleable.Window_windowSplashscreenContent, 0);
2953 a.recycle();
2954 if (resId == 0) {
2955 return;
2956 }
2957 final Drawable drawable = ctx.getDrawable(resId);
2958 if (drawable == null) {
2959 return;
2960 }
2961
2962 // We wrap this into a view so the system insets get applied to the drawable.
2963 final View v = new View(ctx);
2964 v.setBackground(drawable);
2965 win.setContentView(v);
2966 }
2967
Andrii Kulianfb1bf692017-01-17 11:17:34 -08002968 /** Obtain proper context for showing splash screen on the provided display. */
2969 private Context getDisplayContext(Context context, int displayId) {
2970 if (displayId == Display.DEFAULT_DISPLAY) {
2971 // The default context fits.
2972 return context;
2973 }
2974
2975 final DisplayManager dm = (DisplayManager) context.getSystemService(DISPLAY_SERVICE);
2976 final Display targetDisplay = dm.getDisplay(displayId);
2977 if (targetDisplay == null) {
2978 // Failed to obtain the non-default display where splash screen should be shown,
2979 // lets not show at all.
2980 return null;
2981 }
2982
2983 return context.createDisplayContext(targetDisplay);
2984 }
2985
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002986 /**
2987 * Preflight adding a window to the system.
RoboErik8a2cfc32014-05-16 11:19:38 -07002988 *
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002989 * Currently enforces that three window types are singletons:
2990 * <ul>
2991 * <li>STATUS_BAR_TYPE</li>
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002992 * <li>KEYGUARD_TYPE</li>
2993 * </ul>
RoboErik8a2cfc32014-05-16 11:19:38 -07002994 *
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002995 * @param win The window to be added
2996 * @param attrs Information about the window to be added
RoboErik8a2cfc32014-05-16 11:19:38 -07002997 *
Jeff Brown98365d72012-08-19 20:30:52 -07002998 * @return If ok, WindowManagerImpl.ADD_OKAY. If too many singletons,
2999 * WindowManagerImpl.ADD_MULTIPLE_SINGLETON
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003000 */
Jose Lima9546b202014-07-02 17:21:51 -07003001 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003002 public int prepareAddWindowLw(WindowState win, WindowManager.LayoutParams attrs) {
3003 switch (attrs.type) {
3004 case TYPE_STATUS_BAR:
Joe Onorato8bc6c512010-06-04 16:21:12 -04003005 mContext.enforceCallingOrSelfPermission(
3006 android.Manifest.permission.STATUS_BAR_SERVICE,
3007 "PhoneWindowManager");
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003008 if (mStatusBar != null) {
Dianne Hackbornf87d1962012-04-04 12:48:24 -07003009 if (mStatusBar.isAlive()) {
Jeff Brown98365d72012-08-19 20:30:52 -07003010 return WindowManagerGlobal.ADD_MULTIPLE_SINGLETON;
Dianne Hackbornf87d1962012-04-04 12:48:24 -07003011 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003012 }
3013 mStatusBar = win;
John Spurlock27735a42013-08-14 17:57:38 -04003014 mStatusBarController.setWindow(win);
Jorim Jaggi9ba2e102017-04-04 12:51:03 +02003015 setKeyguardOccludedLw(mKeyguardOccluded, true /* force */);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003016 break;
Daniel Sandler8956dbb2011-04-22 07:55:02 -04003017 case TYPE_NAVIGATION_BAR:
3018 mContext.enforceCallingOrSelfPermission(
3019 android.Manifest.permission.STATUS_BAR_SERVICE,
3020 "PhoneWindowManager");
Dianne Hackbornf87d1962012-04-04 12:48:24 -07003021 if (mNavigationBar != null) {
3022 if (mNavigationBar.isAlive()) {
Jeff Brown98365d72012-08-19 20:30:52 -07003023 return WindowManagerGlobal.ADD_MULTIPLE_SINGLETON;
Dianne Hackbornf87d1962012-04-04 12:48:24 -07003024 }
3025 }
Daniel Sandler8956dbb2011-04-22 07:55:02 -04003026 mNavigationBar = win;
John Spurlock27735a42013-08-14 17:57:38 -04003027 mNavigationBarController.setWindow(win);
Casey Burkhardt048c2bc2016-12-08 16:09:20 -08003028 mNavigationBarController.setOnBarVisibilityChangedListener(
Casey Burkhardt469a2082017-06-13 20:12:42 -07003029 mNavBarVisibilityListener, true);
Craig Mautnereda67292013-04-28 13:50:14 -07003030 if (DEBUG_LAYOUT) Slog.i(TAG, "NAVIGATION BAR: " + mNavigationBar);
Daniel Sandler8956dbb2011-04-22 07:55:02 -04003031 break;
Jim Millere898ac52012-04-06 17:10:57 -07003032 case TYPE_NAVIGATION_BAR_PANEL:
Dianne Hackborn08743722009-12-21 12:16:51 -08003033 case TYPE_STATUS_BAR_PANEL:
Joe Onorato29fc2c92010-11-24 10:26:50 -08003034 case TYPE_STATUS_BAR_SUB_PANEL:
Jorim Jaggi225d3b52015-04-01 11:18:57 -07003035 case TYPE_VOICE_INTERACTION_STARTING:
Joe Onorato29fc2c92010-11-24 10:26:50 -08003036 mContext.enforceCallingOrSelfPermission(
3037 android.Manifest.permission.STATUS_BAR_SERVICE,
3038 "PhoneWindowManager");
Joe Onorato29fc2c92010-11-24 10:26:50 -08003039 break;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003040 }
Wale Ogunwale5cd907d2017-01-26 14:14:08 -08003041 return ADD_OKAY;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003042 }
3043
3044 /** {@inheritDoc} */
Jose Lima9546b202014-07-02 17:21:51 -07003045 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003046 public void removeWindowLw(WindowState win) {
3047 if (mStatusBar == win) {
3048 mStatusBar = null;
John Spurlock27735a42013-08-14 17:57:38 -04003049 mStatusBarController.setWindow(null);
Jorim Jaggi73294b62016-10-26 18:02:36 -07003050 } else if (mNavigationBar == win) {
Daniel Sandler8956dbb2011-04-22 07:55:02 -04003051 mNavigationBar = null;
John Spurlock27735a42013-08-14 17:57:38 -04003052 mNavigationBarController.setWindow(null);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003053 }
3054 }
3055
3056 static final boolean PRINT_ANIM = false;
RoboErik8a2cfc32014-05-16 11:19:38 -07003057
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003058 /** {@inheritDoc} */
Craig Mautner4b71aa12012-12-27 17:20:01 -08003059 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003060 public int selectAnimationLw(WindowState win, int transit) {
3061 if (PRINT_ANIM) Log.i(TAG, "selectAnimation in " + win
3062 + ": transit=" + transit);
Dianne Hackbornf87d1962012-04-04 12:48:24 -07003063 if (win == mStatusBar) {
Jorim Jaggi67b29d52017-06-09 18:00:00 -07003064 final boolean isKeyguard = (win.getAttrs().privateFlags & PRIVATE_FLAG_KEYGUARD) != 0;
3065 final boolean expanded = win.getAttrs().height == MATCH_PARENT
3066 && win.getAttrs().width == MATCH_PARENT;
3067 if (isKeyguard || expanded) {
3068 return -1;
3069 }
Craig Mautner4b71aa12012-12-27 17:20:01 -08003070 if (transit == TRANSIT_EXIT
3071 || transit == TRANSIT_HIDE) {
Jorim Jaggi67b29d52017-06-09 18:00:00 -07003072 return R.anim.dock_top_exit;
Craig Mautner4b71aa12012-12-27 17:20:01 -08003073 } else if (transit == TRANSIT_ENTER
3074 || transit == TRANSIT_SHOW) {
Jorim Jaggi67b29d52017-06-09 18:00:00 -07003075 return R.anim.dock_top_enter;
Dianne Hackbornf87d1962012-04-04 12:48:24 -07003076 }
3077 } else if (win == mNavigationBar) {
Jorim Jaggi0d210f62015-07-10 14:24:44 -07003078 if (win.getAttrs().windowAnimations != 0) {
3079 return 0;
3080 }
Adrian Roos85d202b2016-06-02 16:27:47 -07003081 // This can be on either the bottom or the right or the left.
3082 if (mNavigationBarPosition == NAV_BAR_BOTTOM) {
Craig Mautner4b71aa12012-12-27 17:20:01 -08003083 if (transit == TRANSIT_EXIT
3084 || transit == TRANSIT_HIDE) {
Jorim Jaggi48832812016-09-06 12:38:23 -07003085 if (isKeyguardShowingAndNotOccluded()) {
3086 return R.anim.dock_bottom_exit_keyguard;
3087 } else {
3088 return R.anim.dock_bottom_exit;
3089 }
Craig Mautner4b71aa12012-12-27 17:20:01 -08003090 } else if (transit == TRANSIT_ENTER
3091 || transit == TRANSIT_SHOW) {
Dianne Hackbornf87d1962012-04-04 12:48:24 -07003092 return R.anim.dock_bottom_enter;
3093 }
Adrian Roos85d202b2016-06-02 16:27:47 -07003094 } else if (mNavigationBarPosition == NAV_BAR_RIGHT) {
Craig Mautner4b71aa12012-12-27 17:20:01 -08003095 if (transit == TRANSIT_EXIT
3096 || transit == TRANSIT_HIDE) {
Dianne Hackbornf87d1962012-04-04 12:48:24 -07003097 return R.anim.dock_right_exit;
Craig Mautner4b71aa12012-12-27 17:20:01 -08003098 } else if (transit == TRANSIT_ENTER
3099 || transit == TRANSIT_SHOW) {
Dianne Hackbornf87d1962012-04-04 12:48:24 -07003100 return R.anim.dock_right_enter;
3101 }
Adrian Roos85d202b2016-06-02 16:27:47 -07003102 } else if (mNavigationBarPosition == NAV_BAR_LEFT) {
3103 if (transit == TRANSIT_EXIT
3104 || transit == TRANSIT_HIDE) {
3105 return R.anim.dock_left_exit;
3106 } else if (transit == TRANSIT_ENTER
3107 || transit == TRANSIT_SHOW) {
3108 return R.anim.dock_left_enter;
3109 }
Dianne Hackbornf87d1962012-04-04 12:48:24 -07003110 }
Filip Gruszczynski57f76f12015-11-04 16:10:54 -08003111 } else if (win.getAttrs().type == TYPE_DOCK_DIVIDER) {
Jorim Jaggi81ba11e2016-02-03 22:04:22 -08003112 return selectDockedDividerAnimationLw(win, transit);
Craig Mautner4b71aa12012-12-27 17:20:01 -08003113 }
3114
3115 if (transit == TRANSIT_PREVIEW_DONE) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003116 if (win.hasAppShownWindows()) {
3117 if (PRINT_ANIM) Log.i(TAG, "**** STARTING EXIT");
3118 return com.android.internal.R.anim.app_starting_exit;
3119 }
Dianne Hackborn7ad44382012-10-18 17:46:00 -07003120 } else if (win.getAttrs().type == TYPE_DREAM && mDreamingLockscreen
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07003121 && transit == TRANSIT_ENTER) {
3122 // Special case: we are animating in a dream, while the keyguard
3123 // is shown. We don't want an animation on the dream, because
3124 // we need it shown immediately with the keyguard animating away
3125 // to reveal it.
3126 return -1;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003127 }
3128
3129 return 0;
3130 }
3131
Jorim Jaggi81ba11e2016-02-03 22:04:22 -08003132 private int selectDockedDividerAnimationLw(WindowState win, int transit) {
3133 int insets = mWindowManagerFuncs.getDockedDividerInsetsLw();
3134
3135 // If the divider is behind the navigation bar, don't animate.
Jorim Jaggi0cb0f722016-03-25 20:49:41 -07003136 final Rect frame = win.getFrameLw();
3137 final boolean behindNavBar = mNavigationBar != null
Adrian Roos85d202b2016-06-02 16:27:47 -07003138 && ((mNavigationBarPosition == NAV_BAR_BOTTOM
Jorim Jaggi0cb0f722016-03-25 20:49:41 -07003139 && frame.top + insets >= mNavigationBar.getFrameLw().top)
Adrian Roos85d202b2016-06-02 16:27:47 -07003140 || (mNavigationBarPosition == NAV_BAR_RIGHT
3141 && frame.left + insets >= mNavigationBar.getFrameLw().left)
3142 || (mNavigationBarPosition == NAV_BAR_LEFT
3143 && frame.right - insets <= mNavigationBar.getFrameLw().right));
Jorim Jaggi0cb0f722016-03-25 20:49:41 -07003144 final boolean landscape = frame.height() > frame.width();
3145 final boolean offscreenLandscape = landscape && (frame.right - insets <= 0
3146 || frame.left + insets >= win.getDisplayFrameLw().right);
3147 final boolean offscreenPortrait = !landscape && (frame.top - insets <= 0
3148 || frame.bottom + insets >= win.getDisplayFrameLw().bottom);
3149 final boolean offscreen = offscreenLandscape || offscreenPortrait;
3150 if (behindNavBar || offscreen) {
Jorim Jaggi81ba11e2016-02-03 22:04:22 -08003151 return 0;
3152 }
3153 if (transit == TRANSIT_ENTER || transit == TRANSIT_SHOW) {
3154 return R.anim.fade_in;
3155 } else if (transit == TRANSIT_EXIT) {
3156 return R.anim.fade_out;
3157 } else {
3158 return 0;
3159 }
3160 }
3161
Craig Mautner3c174372013-02-21 17:54:37 -08003162 @Override
3163 public void selectRotationAnimationLw(int anim[]) {
Adrian Roos7c894802017-07-19 12:25:34 +02003164 // If the screen is off or non-interactive, force a jumpcut.
Adrian Roos3162b8f2017-07-25 15:37:32 +02003165 final boolean forceJumpcut = !mScreenOnFully || !okToAnimate();
Craig Mautner3c174372013-02-21 17:54:37 -08003166 if (PRINT_ANIM) Slog.i(TAG, "selectRotationAnimation mTopFullscreen="
3167 + mTopFullscreenOpaqueWindowState + " rotationAnimation="
3168 + (mTopFullscreenOpaqueWindowState == null ?
Adrian Roos7c894802017-07-19 12:25:34 +02003169 "0" : mTopFullscreenOpaqueWindowState.getAttrs().rotationAnimation)
3170 + " forceJumpcut=" + forceJumpcut);
3171 if (forceJumpcut) {
3172 anim[0] = R.anim.rotation_animation_jump_exit;
3173 anim[1] = R.anim.rotation_animation_enter;
3174 return;
3175 }
Robert Carrfd10cd12016-06-29 16:41:50 -07003176 if (mTopFullscreenOpaqueWindowState != null) {
3177 int animationHint = mTopFullscreenOpaqueWindowState.getRotationAnimationHint();
3178 if (animationHint < 0 && mTopIsFullscreen) {
3179 animationHint = mTopFullscreenOpaqueWindowState.getAttrs().rotationAnimation;
3180 }
3181 switch (animationHint) {
Craig Mautner3c174372013-02-21 17:54:37 -08003182 case ROTATION_ANIMATION_CROSSFADE:
Robert Carr57d9fbd2016-08-15 12:00:35 -07003183 case ROTATION_ANIMATION_SEAMLESS: // Crossfade is fallback for seamless.
Craig Mautner3c174372013-02-21 17:54:37 -08003184 anim[0] = R.anim.rotation_animation_xfade_exit;
3185 anim[1] = R.anim.rotation_animation_enter;
3186 break;
3187 case ROTATION_ANIMATION_JUMPCUT:
3188 anim[0] = R.anim.rotation_animation_jump_exit;
3189 anim[1] = R.anim.rotation_animation_enter;
3190 break;
3191 case ROTATION_ANIMATION_ROTATE:
3192 default:
3193 anim[0] = anim[1] = 0;
3194 break;
3195 }
3196 } else {
3197 anim[0] = anim[1] = 0;
3198 }
3199 }
3200
3201 @Override
3202 public boolean validateRotationAnimationLw(int exitAnimId, int enterAnimId,
3203 boolean forceDefault) {
3204 switch (exitAnimId) {
3205 case R.anim.rotation_animation_xfade_exit:
3206 case R.anim.rotation_animation_jump_exit:
3207 // These are the only cases that matter.
3208 if (forceDefault) {
3209 return false;
3210 }
3211 int anim[] = new int[2];
3212 selectRotationAnimationLw(anim);
3213 return (exitAnimId == anim[0] && enterAnimId == anim[1]);
3214 default:
3215 return true;
3216 }
3217 }
3218
3219 @Override
Jorim Jaggife762342016-10-13 14:33:27 +02003220 public Animation createHiddenByKeyguardExit(boolean onWallpaper,
Jorim Jaggi84a3e7a2014-08-13 17:58:58 +02003221 boolean goingToNotificationShade) {
3222 if (goingToNotificationShade) {
3223 return AnimationUtils.loadAnimation(mContext, R.anim.lock_screen_behind_enter_fade_in);
Craig Mautnerb8340802014-11-04 15:32:57 -08003224 }
Craig Mautner276a6eb2014-11-04 15:32:57 -08003225
3226 AnimationSet set = (AnimationSet) AnimationUtils.loadAnimation(mContext, onWallpaper ?
3227 R.anim.lock_screen_behind_enter_wallpaper :
3228 R.anim.lock_screen_behind_enter);
3229
3230 // TODO: Use XML interpolators when we have log interpolators available in XML.
3231 final List<Animation> animations = set.getAnimations();
3232 for (int i = animations.size() - 1; i >= 0; --i) {
3233 animations.get(i).setInterpolator(mLogDecelerateInterpolator);
3234 }
3235
3236 return set;
Jorim Jaggi76a16232014-08-08 17:00:47 +02003237 }
3238
3239
3240 @Override
Jorim Jaggife762342016-10-13 14:33:27 +02003241 public Animation createKeyguardWallpaperExit(boolean goingToNotificationShade) {
Jorim Jaggi84a3e7a2014-08-13 17:58:58 +02003242 if (goingToNotificationShade) {
3243 return null;
3244 } else {
3245 return AnimationUtils.loadAnimation(mContext, R.anim.lock_screen_wallpaper_exit);
3246 }
Dianne Hackborn01ad2f42009-09-24 19:24:56 -07003247 }
John Spurlockc8b46ca2013-04-08 12:59:26 -04003248
3249 private static void awakenDreams() {
3250 IDreamManager dreamManager = getDreamManager();
3251 if (dreamManager != null) {
3252 try {
3253 dreamManager.awaken();
3254 } catch (RemoteException e) {
3255 // fine, stay asleep then
3256 }
3257 }
3258 }
3259
3260 static IDreamManager getDreamManager() {
3261 return IDreamManager.Stub.asInterface(
3262 ServiceManager.checkService(DreamService.DREAM_SERVICE));
3263 }
3264
Tyler Gunnef9f6f92014-09-12 22:16:17 -07003265 TelecomManager getTelecommService() {
3266 return (TelecomManager) mContext.getSystemService(Context.TELECOM_SERVICE);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003267 }
3268
Jeff Brown4d396052010-10-29 21:50:21 -07003269 static IAudioService getAudioService() {
3270 IAudioService audioService = IAudioService.Stub.asInterface(
3271 ServiceManager.checkService(Context.AUDIO_SERVICE));
3272 if (audioService == null) {
3273 Log.w(TAG, "Unable to find IAudioService interface.");
3274 }
3275 return audioService;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003276 }
3277
3278 boolean keyguardOn() {
Jim Millerab954542014-10-10 18:21:49 -07003279 return isKeyguardShowingAndNotOccluded() || inKeyguardRestrictedKeyInputMode();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003280 }
3281
3282 private static final int[] WINDOW_TYPES_WHERE_HOME_DOESNT_WORK = {
3283 WindowManager.LayoutParams.TYPE_SYSTEM_ALERT,
3284 WindowManager.LayoutParams.TYPE_SYSTEM_ERROR,
3285 };
3286
3287 /** {@inheritDoc} */
Jeff Brown00fa7bd2010-07-02 15:37:36 -07003288 @Override
Jeff Brownd5bb82d2011-10-12 13:57:59 -07003289 public long interceptKeyBeforeDispatching(WindowState win, KeyEvent event, int policyFlags) {
Jeff Brown00fa7bd2010-07-02 15:37:36 -07003290 final boolean keyguardOn = keyguardOn();
Jeff Brown1f245102010-11-18 20:53:46 -08003291 final int keyCode = event.getKeyCode();
3292 final int repeatCount = event.getRepeatCount();
3293 final int metaState = event.getMetaState();
Jeff Brownd5bb82d2011-10-12 13:57:59 -07003294 final int flags = event.getFlags();
Jeff Brown1f245102010-11-18 20:53:46 -08003295 final boolean down = event.getAction() == KeyEvent.ACTION_DOWN;
3296 final boolean canceled = event.isCanceled();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003297
Jeff Brown40013652012-05-16 21:22:36 -07003298 if (DEBUG_INPUT) {
Jeff Brown00fa7bd2010-07-02 15:37:36 -07003299 Log.d(TAG, "interceptKeyTi keyCode=" + keyCode + " down=" + down + " repeatCount="
Jeff Brownfd23e3e2012-05-09 13:34:28 -07003300 + repeatCount + " keyguardOn=" + keyguardOn + " mHomePressed=" + mHomePressed
3301 + " canceled=" + canceled);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003302 }
3303
Jeff Brownd5bb82d2011-10-12 13:57:59 -07003304 // If we think we might have a volume down & power key chord on the way
3305 // but we're not sure, then tell the dispatcher to wait a little while and
3306 // try again later before dispatching.
Christopher Tatee90585f2012-03-05 18:56:25 -08003307 if (mScreenshotChordEnabled && (flags & KeyEvent.FLAG_FALLBACK) == 0) {
Jeff Brown13f00f02014-10-31 14:45:50 -07003308 if (mScreenshotChordVolumeDownKeyTriggered && !mScreenshotChordPowerKeyTriggered) {
Jeff Brownd5bb82d2011-10-12 13:57:59 -07003309 final long now = SystemClock.uptimeMillis();
Jeff Brown13f00f02014-10-31 14:45:50 -07003310 final long timeoutTime = mScreenshotChordVolumeDownKeyTime
3311 + SCREENSHOT_CHORD_DEBOUNCE_DELAY_MILLIS;
Jeff Brownd5bb82d2011-10-12 13:57:59 -07003312 if (now < timeoutTime) {
3313 return timeoutTime - now;
3314 }
3315 }
3316 if (keyCode == KeyEvent.KEYCODE_VOLUME_DOWN
Jeff Brown13f00f02014-10-31 14:45:50 -07003317 && mScreenshotChordVolumeDownKeyConsumed) {
Jeff Brownd5bb82d2011-10-12 13:57:59 -07003318 if (!down) {
Jeff Brown13f00f02014-10-31 14:45:50 -07003319 mScreenshotChordVolumeDownKeyConsumed = false;
Jeff Brownd5bb82d2011-10-12 13:57:59 -07003320 }
3321 return -1;
3322 }
3323 }
3324
Phil Weaver106fe732016-11-22 18:18:39 -08003325 // If an accessibility shortcut might be partially complete, hold off dispatching until we
3326 // know if it is complete or not
Phil Weaverce687c52017-03-15 08:51:52 -07003327 if (mAccessibilityShortcutController.isAccessibilityShortcutAvailable(false)
Phil Weaver106fe732016-11-22 18:18:39 -08003328 && (flags & KeyEvent.FLAG_FALLBACK) == 0) {
3329 if (mScreenshotChordVolumeDownKeyTriggered ^ mA11yShortcutChordVolumeUpKeyTriggered) {
3330 final long now = SystemClock.uptimeMillis();
3331 final long timeoutTime = (mScreenshotChordVolumeDownKeyTriggered
3332 ? mScreenshotChordVolumeDownKeyTime : mA11yShortcutChordVolumeUpKeyTime)
3333 + SCREENSHOT_CHORD_DEBOUNCE_DELAY_MILLIS;
3334 if (now < timeoutTime) {
3335 return timeoutTime - now;
3336 }
3337 }
3338 if (keyCode == KeyEvent.KEYCODE_VOLUME_DOWN && mScreenshotChordVolumeDownKeyConsumed) {
3339 if (!down) {
3340 mScreenshotChordVolumeDownKeyConsumed = false;
3341 }
3342 return -1;
3343 }
3344 if (keyCode == KeyEvent.KEYCODE_VOLUME_UP && mA11yShortcutChordVolumeUpKeyConsumed) {
3345 if (!down) {
3346 mA11yShortcutChordVolumeUpKeyConsumed = false;
3347 }
3348 return -1;
3349 }
3350 }
3351
Michael Wright6a62e552014-06-03 19:19:48 -07003352 // Cancel any pending meta actions if we see any other keys being pressed between the down
3353 // of the meta key and its corresponding up.
Michael Wright251e35d2014-08-22 15:40:27 -07003354 if (mPendingMetaAction && !KeyEvent.isMetaKey(keyCode)) {
Michael Wright6a62e552014-06-03 19:19:48 -07003355 mPendingMetaAction = false;
3356 }
Andrii Kulian112d0562016-03-08 10:44:22 -08003357 // Any key that is not Alt or Meta cancels Caps Lock combo tracking.
3358 if (mPendingCapsLockToggle && !KeyEvent.isMetaKey(keyCode) && !KeyEvent.isAltKey(keyCode)) {
3359 mPendingCapsLockToggle = false;
3360 }
Michael Wright6a62e552014-06-03 19:19:48 -07003361
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003362 // First we always handle the home key here, so applications
3363 // can never break it, although if keyguard is on, we do let
3364 // it handle it, because that gives us the correct 5 second
3365 // timeout.
Jeff Brown00fa7bd2010-07-02 15:37:36 -07003366 if (keyCode == KeyEvent.KEYCODE_HOME) {
Michael Jurka7f2668c2012-03-27 07:49:52 -07003367
Jeff Brown49ed71d2010-12-06 17:13:33 -08003368 // If we have released the home key, and didn't do anything else
3369 // while it was pressed, then it is time to go home!
Michael Jurka7f2668c2012-03-27 07:49:52 -07003370 if (!down) {
Jeff Browncaca8812013-05-09 13:34:33 -07003371 cancelPreloadRecentApps();
3372
Sujith Ramakrishnan6bed9bd2017-04-26 12:33:37 -07003373 if (mHasFeatureLeanback) {
3374 // Clear flags
3375 mAccessibilityTvKey2Pressed = down;
3376 }
3377
Jeff Brown49ed71d2010-12-06 17:13:33 -08003378 mHomePressed = false;
Jeff Browncaca8812013-05-09 13:34:33 -07003379 if (mHomeConsumed) {
3380 mHomeConsumed = false;
Michael Jurka7f2668c2012-03-27 07:49:52 -07003381 return -1;
Jeff Brown49ed71d2010-12-06 17:13:33 -08003382 }
Jeff Browncaca8812013-05-09 13:34:33 -07003383
3384 if (canceled) {
3385 Log.i(TAG, "Ignoring HOME; event canceled.");
3386 return -1;
3387 }
3388
Jeff Browncaca8812013-05-09 13:34:33 -07003389 // Delay handling home if a double-tap is possible.
3390 if (mDoubleTapOnHomeBehavior != DOUBLE_TAP_HOME_NOTHING) {
3391 mHandler.removeCallbacks(mHomeDoubleTapTimeoutRunnable); // just in case
3392 mHomeDoubleTapPending = true;
3393 mHandler.postDelayed(mHomeDoubleTapTimeoutRunnable,
3394 ViewConfiguration.getDoubleTapTimeout());
3395 return -1;
3396 }
3397
Jeff Brown13f00f02014-10-31 14:45:50 -07003398 handleShortPressOnHome();
Jeff Browncaca8812013-05-09 13:34:33 -07003399 return -1;
Jeff Brown49ed71d2010-12-06 17:13:33 -08003400 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003401
3402 // If a system window has focus, then it doesn't make sense
3403 // right now to interact with applications.
3404 WindowManager.LayoutParams attrs = win != null ? win.getAttrs() : null;
3405 if (attrs != null) {
3406 final int type = attrs.type;
Jorim Jaggi73294b62016-10-26 18:02:36 -07003407 if (type == TYPE_KEYGUARD_DIALOG
Jorim Jaggi380ecb82014-03-14 17:25:20 +01003408 || (attrs.privateFlags & PRIVATE_FLAG_KEYGUARD) != 0) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003409 // the "app" is keyguard, so give it the key
Jeff Brownd5bb82d2011-10-12 13:57:59 -07003410 return 0;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003411 }
3412 final int typeCount = WINDOW_TYPES_WHERE_HOME_DOESNT_WORK.length;
3413 for (int i=0; i<typeCount; i++) {
3414 if (type == WINDOW_TYPES_WHERE_HOME_DOESNT_WORK[i]) {
3415 // don't do anything, but also don't pass it to the app
Jeff Brownd5bb82d2011-10-12 13:57:59 -07003416 return -1;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003417 }
3418 }
3419 }
Jeff Browncaca8812013-05-09 13:34:33 -07003420
3421 // Remember that home is pressed and handle special actions.
3422 if (repeatCount == 0) {
3423 mHomePressed = true;
3424 if (mHomeDoubleTapPending) {
3425 mHomeDoubleTapPending = false;
3426 mHandler.removeCallbacks(mHomeDoubleTapTimeoutRunnable);
3427 handleDoubleTapOnHome();
Sid Soundararajanff662fa2017-03-15 16:24:24 -07003428 } else if (mDoubleTapOnHomeBehavior == DOUBLE_TAP_HOME_RECENT_SYSTEM_UI) {
Jeff Browncaca8812013-05-09 13:34:33 -07003429 preloadRecentApps();
Michael Jurka7f2668c2012-03-27 07:49:52 -07003430 }
Jeff Browncaca8812013-05-09 13:34:33 -07003431 } else if ((event.getFlags() & KeyEvent.FLAG_LONG_PRESS) != 0) {
Sujith Ramakrishnan6bed9bd2017-04-26 12:33:37 -07003432 if (mHasFeatureLeanback) {
3433 mAccessibilityTvKey2Pressed = down;
3434 if (interceptAccessibilityGestureTv()) {
3435 return -1;
3436 }
3437 }
3438
Jeff Browncaca8812013-05-09 13:34:33 -07003439 if (!keyguardOn) {
Jaewan Kim76b7d0d2016-02-12 19:01:02 +09003440 handleLongPressOnHome(event.getDeviceId());
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003441 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003442 }
Jeff Brownd5bb82d2011-10-12 13:57:59 -07003443 return -1;
Jeff Brown00fa7bd2010-07-02 15:37:36 -07003444 } else if (keyCode == KeyEvent.KEYCODE_MENU) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003445 // Hijack modified menu keys for debugging features
3446 final int chordBug = KeyEvent.META_SHIFT_ON;
3447
3448 if (down && repeatCount == 0) {
Jeff Brown00fa7bd2010-07-02 15:37:36 -07003449 if (mEnableShiftMenuBugReports && (metaState & chordBug) == chordBug) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003450 Intent intent = new Intent(Intent.ACTION_BUG_REPORT);
Dianne Hackborn5ac72a22012-08-29 18:32:08 -07003451 mContext.sendOrderedBroadcastAsUser(intent, UserHandle.CURRENT,
3452 null, null, null, 0, null, null);
Jeff Brownd5bb82d2011-10-12 13:57:59 -07003453 return -1;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003454 }
3455 }
Jeff Brown00fa7bd2010-07-02 15:37:36 -07003456 } else if (keyCode == KeyEvent.KEYCODE_SEARCH) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003457 if (down) {
3458 if (repeatCount == 0) {
Jeff Brownfd23e3e2012-05-09 13:34:28 -07003459 mSearchKeyShortcutPending = true;
3460 mConsumeSearchKeyUp = false;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003461 }
Jeff Brownfd23e3e2012-05-09 13:34:28 -07003462 } else {
3463 mSearchKeyShortcutPending = false;
3464 if (mConsumeSearchKeyUp) {
3465 mConsumeSearchKeyUp = false;
Jeff Brownd5bb82d2011-10-12 13:57:59 -07003466 return -1;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003467 }
3468 }
Jeff Brownd5bb82d2011-10-12 13:57:59 -07003469 return 0;
Jeff Brown49ed71d2010-12-06 17:13:33 -08003470 } else if (keyCode == KeyEvent.KEYCODE_APP_SWITCH) {
Michael Wrightc9ebea72013-01-16 19:25:02 -08003471 if (!keyguardOn) {
Jeff Browncaca8812013-05-09 13:34:33 -07003472 if (down && repeatCount == 0) {
3473 preloadRecentApps();
3474 } else if (!down) {
3475 toggleRecentApps();
Michael Wrightc9ebea72013-01-16 19:25:02 -08003476 }
Jeff Brown49ed71d2010-12-06 17:13:33 -08003477 }
Jeff Brownd5bb82d2011-10-12 13:57:59 -07003478 return -1;
Jun Mukaid21b3c82015-04-23 14:09:34 -07003479 } else if (keyCode == KeyEvent.KEYCODE_N && event.isMetaPressed()) {
3480 if (down) {
3481 IStatusBarService service = getStatusBarService();
3482 if (service != null) {
3483 try {
3484 service.expandNotificationsPanel();
3485 } catch (RemoteException e) {
3486 // do nothing.
3487 }
3488 }
3489 }
Muyuan Li6ca619f2016-03-08 13:30:42 -08003490 } else if (keyCode == KeyEvent.KEYCODE_S && event.isMetaPressed()
3491 && event.isCtrlPressed()) {
3492 if (down && repeatCount == 0) {
3493 int type = event.isShiftPressed() ? TAKE_SCREENSHOT_SELECTED_REGION
3494 : TAKE_SCREENSHOT_FULLSCREEN;
3495 mScreenshotRunnable.setScreenshotType(type);
3496 mHandler.post(mScreenshotRunnable);
3497 return -1;
3498 }
Clara Bayarrif2debb12015-07-10 14:47:17 +01003499 } else if (keyCode == KeyEvent.KEYCODE_SLASH && event.isMetaPressed()) {
Andrei Stingaceanu002f7122016-03-30 12:22:05 +01003500 if (down && repeatCount == 0 && !isKeyguardLocked()) {
3501 toggleKeyboardShortcutsMenu(event.getDeviceId());
Clara Bayarrif2debb12015-07-10 14:47:17 +01003502 }
Jeff Brownde7a8ea2012-06-13 18:28:57 -07003503 } else if (keyCode == KeyEvent.KEYCODE_ASSIST) {
3504 if (down) {
3505 if (repeatCount == 0) {
3506 mAssistKeyLongPressed = false;
3507 } else if (repeatCount == 1) {
3508 mAssistKeyLongPressed = true;
3509 if (!keyguardOn) {
3510 launchAssistLongPressAction();
3511 }
3512 }
3513 } else {
3514 if (mAssistKeyLongPressed) {
3515 mAssistKeyLongPressed = false;
3516 } else {
3517 if (!keyguardOn) {
Tim Kilbourn0e5f1102015-06-05 16:18:09 -07003518 launchAssistAction(null, event.getDeviceId());
Jeff Brownde7a8ea2012-06-13 18:28:57 -07003519 }
3520 }
3521 }
3522 return -1;
Michael Wrightdc63f7b2014-08-21 19:05:21 -07003523 } else if (keyCode == KeyEvent.KEYCODE_VOICE_ASSIST) {
3524 if (!down) {
3525 Intent voiceIntent;
Michael Wright869a67c2014-08-26 19:33:06 -07003526 if (!keyguardOn) {
Michael Wrightdc63f7b2014-08-21 19:05:21 -07003527 voiceIntent = new Intent(RecognizerIntent.ACTION_WEB_SEARCH);
3528 } else {
Dianne Hackbornb6683c42015-06-18 17:40:33 -07003529 IDeviceIdleController dic = IDeviceIdleController.Stub.asInterface(
3530 ServiceManager.getService(Context.DEVICE_IDLE_CONTROLLER));
3531 if (dic != null) {
3532 try {
3533 dic.exitIdle("voice-search");
3534 } catch (RemoteException e) {
3535 }
3536 }
Michael Wrightdc63f7b2014-08-21 19:05:21 -07003537 voiceIntent = new Intent(RecognizerIntent.ACTION_VOICE_SEARCH_HANDS_FREE);
Michael Wright869a67c2014-08-26 19:33:06 -07003538 voiceIntent.putExtra(RecognizerIntent.EXTRA_SECURE, true);
Michael Wrightdc63f7b2014-08-21 19:05:21 -07003539 }
Bart Sears8b1c27c2015-03-18 23:51:02 +00003540 startActivityAsUser(voiceIntent, UserHandle.CURRENT_OR_SELF);
Michael Wrightdc63f7b2014-08-21 19:05:21 -07003541 }
Jeff Sharkey2991fa32012-12-05 18:06:43 -08003542 } else if (keyCode == KeyEvent.KEYCODE_SYSRQ) {
3543 if (down && repeatCount == 0) {
Muyuan Li6ca619f2016-03-08 13:30:42 -08003544 mScreenshotRunnable.setScreenshotType(TAKE_SCREENSHOT_FULLSCREEN);
Jeff Sharkey2991fa32012-12-05 18:06:43 -08003545 mHandler.post(mScreenshotRunnable);
3546 }
3547 return -1;
Michael Wrightb854e242013-02-05 17:54:02 -08003548 } else if (keyCode == KeyEvent.KEYCODE_BRIGHTNESS_UP
3549 || keyCode == KeyEvent.KEYCODE_BRIGHTNESS_DOWN) {
3550 if (down) {
3551 int direction = keyCode == KeyEvent.KEYCODE_BRIGHTNESS_UP ? 1 : -1;
3552
3553 // Disable autobrightness if it's on
3554 int auto = Settings.System.getIntForUser(
3555 mContext.getContentResolver(),
3556 Settings.System.SCREEN_BRIGHTNESS_MODE,
3557 Settings.System.SCREEN_BRIGHTNESS_MODE_MANUAL,
3558 UserHandle.USER_CURRENT_OR_SELF);
3559 if (auto != 0) {
3560 Settings.System.putIntForUser(mContext.getContentResolver(),
3561 Settings.System.SCREEN_BRIGHTNESS_MODE,
3562 Settings.System.SCREEN_BRIGHTNESS_MODE_MANUAL,
3563 UserHandle.USER_CURRENT_OR_SELF);
3564 }
3565
3566 int min = mPowerManager.getMinimumScreenBrightnessSetting();
3567 int max = mPowerManager.getMaximumScreenBrightnessSetting();
3568 int step = (max - min + BRIGHTNESS_STEPS - 1) / BRIGHTNESS_STEPS * direction;
3569 int brightness = Settings.System.getIntForUser(mContext.getContentResolver(),
3570 Settings.System.SCREEN_BRIGHTNESS,
3571 mPowerManager.getDefaultScreenBrightnessSetting(),
3572 UserHandle.USER_CURRENT_OR_SELF);
3573 brightness += step;
3574 // Make sure we don't go beyond the limits.
3575 brightness = Math.min(max, brightness);
3576 brightness = Math.max(min, brightness);
3577
3578 Settings.System.putIntForUser(mContext.getContentResolver(),
3579 Settings.System.SCREEN_BRIGHTNESS, brightness,
3580 UserHandle.USER_CURRENT_OR_SELF);
Bart Sears8b1c27c2015-03-18 23:51:02 +00003581 startActivityAsUser(new Intent(Intent.ACTION_SHOW_BRIGHTNESS_DIALOG),
Alan Viverette5a399492014-07-14 16:19:38 -07003582 UserHandle.CURRENT_OR_SELF);
Michael Wrightb854e242013-02-05 17:54:02 -08003583 }
3584 return -1;
Jaewan Kim765487f2016-01-12 14:45:42 +09003585 } else if (keyCode == KeyEvent.KEYCODE_VOLUME_UP
3586 || keyCode == KeyEvent.KEYCODE_VOLUME_DOWN
3587 || keyCode == KeyEvent.KEYCODE_VOLUME_MUTE) {
Karthik Ravi Shankar86ecf342017-04-28 15:35:58 -07003588 if (mUseTvRouting || mHandleVolumeKeysInWM) {
3589 // On TVs or when the configuration is enabled, volume keys never
3590 // go to the foreground app.
Jaewan Kim765487f2016-01-12 14:45:42 +09003591 dispatchDirectAudioEvent(event);
3592 return -1;
3593 }
Karthik Ravi Shankar86ecf342017-04-28 15:35:58 -07003594
3595 // If the device is in Vr mode, drop the volume keys and don't
3596 // forward it to the application/dispatch the audio event.
3597 if (mPersistentVrModeEnabled) {
3598 return -1;
3599 }
Evan Rosky516f9e62017-01-23 16:43:52 -08003600 } else if (keyCode == KeyEvent.KEYCODE_TAB && event.isMetaPressed()) {
3601 // Pass through keyboard navigation keys.
3602 return 0;
Dmitri Plotnikov82e6dfc2017-02-24 18:10:54 -08003603 } else if (mHasFeatureLeanback && interceptBugreportGestureTv(keyCode, down)) {
3604 return -1;
Sujith Ramakrishnan6bed9bd2017-04-26 12:33:37 -07003605 } else if (mHasFeatureLeanback && keyCode == KeyEvent.KEYCODE_DPAD_CENTER) {
3606 mAccessibilityTvKey1Pressed = down;
3607 if (interceptAccessibilityGestureTv()) {
3608 return -1;
3609 }
Muyuan Li94ce94e2016-02-24 16:20:54 -08003610 }
3611
Andrii Kulian112d0562016-03-08 10:44:22 -08003612 // Toggle Caps Lock on META-ALT.
3613 boolean actionTriggered = false;
3614 if (KeyEvent.isModifierKey(keyCode)) {
3615 if (!mPendingCapsLockToggle) {
3616 // Start tracking meta state for combo.
3617 mInitialMetaState = mMetaState;
3618 mPendingCapsLockToggle = true;
3619 } else if (event.getAction() == KeyEvent.ACTION_UP) {
3620 int altOnMask = mMetaState & KeyEvent.META_ALT_MASK;
3621 int metaOnMask = mMetaState & KeyEvent.META_META_MASK;
3622
3623 // Check for Caps Lock toggle
3624 if ((metaOnMask != 0) && (altOnMask != 0)) {
3625 // Check if nothing else is pressed
3626 if (mInitialMetaState == (mMetaState ^ (altOnMask | metaOnMask))) {
3627 // Handle Caps Lock Toggle
3628 mInputManagerInternal.toggleCapsLock(event.getDeviceId());
3629 actionTriggered = true;
3630 }
3631 }
3632
3633 // Always stop tracking when key goes up.
3634 mPendingCapsLockToggle = false;
3635 }
3636 }
3637 // Store current meta state to be able to evaluate it later.
3638 mMetaState = metaState;
3639
3640 if (actionTriggered) {
3641 return -1;
3642 }
3643
Muyuan Li94ce94e2016-02-24 16:20:54 -08003644 if (KeyEvent.isMetaKey(keyCode)) {
Michael Wright6a62e552014-06-03 19:19:48 -07003645 if (down) {
3646 mPendingMetaAction = true;
3647 } else if (mPendingMetaAction) {
Tim Kilbourn0e5f1102015-06-05 16:18:09 -07003648 launchAssistAction(Intent.EXTRA_ASSIST_INPUT_HINT_KEYBOARD, event.getDeviceId());
Michael Wright6a62e552014-06-03 19:19:48 -07003649 }
3650 return -1;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003651 }
Jeff Browncaab4d02010-12-09 22:13:41 -08003652
Jeff Brownc1fb48d2010-12-08 16:52:09 -08003653 // Shortcuts are invoked through Search+key, so intercept those here
Jeff Browncaab4d02010-12-09 22:13:41 -08003654 // Any printing key that is chorded with Search should be consumed
3655 // even if no shortcut was invoked. This prevents text from being
3656 // inadvertently inserted when using a keyboard that has built-in macro
3657 // shortcut keys (that emit Search+x) and some of them are not registered.
Jeff Brownfd23e3e2012-05-09 13:34:28 -07003658 if (mSearchKeyShortcutPending) {
Jeff Browncaab4d02010-12-09 22:13:41 -08003659 final KeyCharacterMap kcm = event.getKeyCharacterMap();
3660 if (kcm.isPrintingKey(keyCode)) {
Jeff Brownfd23e3e2012-05-09 13:34:28 -07003661 mConsumeSearchKeyUp = true;
3662 mSearchKeyShortcutPending = false;
Jeff Browncaab4d02010-12-09 22:13:41 -08003663 if (down && repeatCount == 0 && !keyguardOn) {
3664 Intent shortcutIntent = mShortcutManager.getIntent(kcm, keyCode, metaState);
3665 if (shortcutIntent != null) {
3666 shortcutIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
Jeff Brownf0a3cc52011-01-26 18:42:46 -08003667 try {
Bart Sears8b1c27c2015-03-18 23:51:02 +00003668 startActivityAsUser(shortcutIntent, UserHandle.CURRENT);
Andrei Stingaceanu0bf096f2016-04-14 18:11:57 +01003669 dismissKeyboardShortcutsMenu();
Jeff Brownf0a3cc52011-01-26 18:42:46 -08003670 } catch (ActivityNotFoundException ex) {
3671 Slog.w(TAG, "Dropping shortcut key combination because "
3672 + "the activity to which it is registered was not found: "
Jeff Brownfd23e3e2012-05-09 13:34:28 -07003673 + "SEARCH+" + KeyEvent.keyCodeToString(keyCode), ex);
Jeff Brownf0a3cc52011-01-26 18:42:46 -08003674 }
Jeff Browncaab4d02010-12-09 22:13:41 -08003675 } else {
3676 Slog.i(TAG, "Dropping unregistered shortcut key combination: "
Jeff Brownfd23e3e2012-05-09 13:34:28 -07003677 + "SEARCH+" + KeyEvent.keyCodeToString(keyCode));
Jeff Brown49ed71d2010-12-06 17:13:33 -08003678 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003679 }
Jeff Brownd5bb82d2011-10-12 13:57:59 -07003680 return -1;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003681 }
3682 }
3683
Jeff Brown68b909d2011-12-07 16:36:01 -08003684 // Invoke shortcuts using Meta.
Jeff Brown602ab322012-05-16 13:33:47 -07003685 if (down && repeatCount == 0 && !keyguardOn
Jeff Brown68b909d2011-12-07 16:36:01 -08003686 && (metaState & KeyEvent.META_META_ON) != 0) {
3687 final KeyCharacterMap kcm = event.getKeyCharacterMap();
Jeff Brown602ab322012-05-16 13:33:47 -07003688 if (kcm.isPrintingKey(keyCode)) {
3689 Intent shortcutIntent = mShortcutManager.getIntent(kcm, keyCode,
3690 metaState & ~(KeyEvent.META_META_ON
3691 | KeyEvent.META_META_LEFT_ON | KeyEvent.META_META_RIGHT_ON));
3692 if (shortcutIntent != null) {
3693 shortcutIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
3694 try {
Bart Sears8b1c27c2015-03-18 23:51:02 +00003695 startActivityAsUser(shortcutIntent, UserHandle.CURRENT);
Andrei Stingaceanu0bf096f2016-04-14 18:11:57 +01003696 dismissKeyboardShortcutsMenu();
Jeff Brown602ab322012-05-16 13:33:47 -07003697 } catch (ActivityNotFoundException ex) {
3698 Slog.w(TAG, "Dropping shortcut key combination because "
3699 + "the activity to which it is registered was not found: "
3700 + "META+" + KeyEvent.keyCodeToString(keyCode), ex);
3701 }
3702 return -1;
Jeff Brown68b909d2011-12-07 16:36:01 -08003703 }
Jeff Brown68b909d2011-12-07 16:36:01 -08003704 }
3705 }
3706
Jeff Brown6651a632011-11-28 12:59:11 -08003707 // Handle application launch keys.
Jeff Brown602ab322012-05-16 13:33:47 -07003708 if (down && repeatCount == 0 && !keyguardOn) {
Jeff Brown6651a632011-11-28 12:59:11 -08003709 String category = sApplicationLaunchKeyCategories.get(keyCode);
3710 if (category != null) {
Dianne Hackbornf5b86712011-12-05 17:42:41 -08003711 Intent intent = Intent.makeMainSelectorActivity(Intent.ACTION_MAIN, category);
Jeff Brown6651a632011-11-28 12:59:11 -08003712 intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
3713 try {
Bart Sears8b1c27c2015-03-18 23:51:02 +00003714 startActivityAsUser(intent, UserHandle.CURRENT);
Andrei Stingaceanu0bf096f2016-04-14 18:11:57 +01003715 dismissKeyboardShortcutsMenu();
Jeff Brown6651a632011-11-28 12:59:11 -08003716 } catch (ActivityNotFoundException ex) {
3717 Slog.w(TAG, "Dropping application launch key because "
3718 + "the activity to which it is registered was not found: "
3719 + "keyCode=" + keyCode + ", category=" + category, ex);
3720 }
Jeff Brown68b909d2011-12-07 16:36:01 -08003721 return -1;
Jeff Brown6651a632011-11-28 12:59:11 -08003722 }
3723 }
3724
Michael Wright61c46752014-08-21 16:57:33 -07003725 // Display task switcher for ALT-TAB.
Jeff Brown68b909d2011-12-07 16:36:01 -08003726 if (down && repeatCount == 0 && keyCode == KeyEvent.KEYCODE_TAB) {
Michael Wrightd847ad52015-10-24 13:24:15 +01003727 if (mRecentAppsHeldModifiers == 0 && !keyguardOn && isUserSetupComplete()) {
Jeff Brown68b909d2011-12-07 16:36:01 -08003728 final int shiftlessModifiers = event.getModifiers() & ~KeyEvent.META_SHIFT_MASK;
Michael Wright61c46752014-08-21 16:57:33 -07003729 if (KeyEvent.metaStateHasModifiers(shiftlessModifiers, KeyEvent.META_ALT_ON)) {
Winson Chung1e8d71b2014-05-16 17:05:22 -07003730 mRecentAppsHeldModifiers = shiftlessModifiers;
Winson14db3622016-05-09 13:34:07 -07003731 showRecentApps(true, false);
Jeff Brown68b909d2011-12-07 16:36:01 -08003732 return -1;
3733 }
3734 }
Winson Chung1e8d71b2014-05-16 17:05:22 -07003735 } else if (!down && mRecentAppsHeldModifiers != 0
3736 && (metaState & mRecentAppsHeldModifiers) == 0) {
3737 mRecentAppsHeldModifiers = 0;
Winson Chungcdcd4872014-08-05 18:00:13 -07003738 hideRecentApps(true, false);
Jeff Brown68b909d2011-12-07 16:36:01 -08003739 }
3740
Yohei Yukawaae61f712015-12-09 13:00:10 -08003741 // Handle input method switching.
Jeff Browncf39bdf2012-05-18 14:41:19 -07003742 if (down && repeatCount == 0
3743 && (keyCode == KeyEvent.KEYCODE_LANGUAGE_SWITCH
3744 || (keyCode == KeyEvent.KEYCODE_SPACE
Yohei Yukawaae61f712015-12-09 13:00:10 -08003745 && (metaState & KeyEvent.META_META_MASK) != 0))) {
3746 final boolean forwardDirection = (metaState & KeyEvent.META_SHIFT_MASK) == 0;
3747 mWindowManagerFuncs.switchInputMethod(forwardDirection);
Jeff Browncf39bdf2012-05-18 14:41:19 -07003748 return -1;
3749 }
3750 if (mLanguageSwitchKeyPressed && !down
3751 && (keyCode == KeyEvent.KEYCODE_LANGUAGE_SWITCH
3752 || keyCode == KeyEvent.KEYCODE_SPACE)) {
3753 mLanguageSwitchKeyPressed = false;
3754 return -1;
3755 }
3756
Jeff Brown13f00f02014-10-31 14:45:50 -07003757 if (isValidGlobalKey(keyCode)
3758 && mGlobalKeyManager.handleGlobalKey(mContext, keyCode, event)) {
Justin Kohd378ad72013-04-01 12:18:26 -07003759 return -1;
3760 }
3761
Muyuan Li94ce94e2016-02-24 16:20:54 -08003762 if (down) {
Jim Millere4044bb2016-05-10 18:38:25 -07003763 long shortcutCode = keyCode;
Muyuan Li94ce94e2016-02-24 16:20:54 -08003764 if (event.isCtrlPressed()) {
3765 shortcutCode |= ((long) KeyEvent.META_CTRL_ON) << Integer.SIZE;
3766 }
3767
3768 if (event.isAltPressed()) {
3769 shortcutCode |= ((long) KeyEvent.META_ALT_ON) << Integer.SIZE;
3770 }
3771
3772 if (event.isShiftPressed()) {
3773 shortcutCode |= ((long) KeyEvent.META_SHIFT_ON) << Integer.SIZE;
3774 }
3775
3776 if (event.isMetaPressed()) {
3777 shortcutCode |= ((long) KeyEvent.META_META_ON) << Integer.SIZE;
3778 }
3779
3780 IShortcutService shortcutService = mShortcutKeyServices.get(shortcutCode);
3781 if (shortcutService != null) {
3782 try {
Muyuan Lib5dd0492016-04-14 13:22:20 -07003783 if (isUserSetupComplete()) {
3784 shortcutService.notifyShortcutKeyPressed(shortcutCode);
3785 }
Muyuan Li94ce94e2016-02-24 16:20:54 -08003786 } catch (RemoteException e) {
3787 mShortcutKeyServices.delete(shortcutCode);
3788 }
3789 return -1;
3790 }
3791 }
3792
Michael Wright6a62e552014-06-03 19:19:48 -07003793 // Reserve all the META modifier combos for system behavior
Michael Wrightce0c13a2014-07-30 10:49:21 -07003794 if ((metaState & KeyEvent.META_META_ON) != 0) {
Michael Wright6a62e552014-06-03 19:19:48 -07003795 return -1;
3796 }
3797
Jeff Brown68b909d2011-12-07 16:36:01 -08003798 // Let the application handle the key.
Jeff Brownd5bb82d2011-10-12 13:57:59 -07003799 return 0;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003800 }
3801
Dmitri Plotnikov82e6dfc2017-02-24 18:10:54 -08003802 /**
3803 * TV only: recognizes a remote control gesture for capturing a bug report.
3804 */
3805 private boolean interceptBugreportGestureTv(int keyCode, boolean down) {
3806 // The bugreport capture chord is a long press on DPAD CENTER and BACK simultaneously.
3807 if (keyCode == KeyEvent.KEYCODE_DPAD_CENTER) {
3808 mBugreportTvKey1Pressed = down;
3809 } else if (keyCode == KeyEvent.KEYCODE_BACK) {
3810 mBugreportTvKey2Pressed = down;
3811 }
3812
3813 if (mBugreportTvKey1Pressed && mBugreportTvKey2Pressed) {
3814 if (!mBugreportTvScheduled) {
3815 mBugreportTvScheduled = true;
3816 Message msg = Message.obtain(mHandler, MSG_BUGREPORT_TV);
3817 msg.setAsynchronous(true);
3818 mHandler.sendMessageDelayed(msg, BUGREPORT_TV_GESTURE_TIMEOUT_MILLIS);
3819 }
3820 } else if (mBugreportTvScheduled) {
3821 mHandler.removeMessages(MSG_BUGREPORT_TV);
3822 mBugreportTvScheduled = false;
3823 }
3824
3825 return mBugreportTvScheduled;
3826 }
3827
Sujith Ramakrishnan6bed9bd2017-04-26 12:33:37 -07003828 /**
3829 * TV only: recognizes a remote control gesture as Accessibility shortcut.
3830 * Shortcut: Long press (HOME + DPAD_CENTER)
3831 */
3832 private boolean interceptAccessibilityGestureTv() {
3833 if (mAccessibilityTvKey1Pressed && mAccessibilityTvKey2Pressed) {
3834 if (!mAccessibilityTvScheduled) {
3835 mAccessibilityTvScheduled = true;
3836 Message msg = Message.obtain(mHandler, MSG_ACCESSIBILITY_TV);
3837 msg.setAsynchronous(true);
3838 mHandler.sendMessage(msg);
3839 }
3840 } else if (mAccessibilityTvScheduled) {
3841 mHandler.removeMessages(MSG_ACCESSIBILITY_TV);
3842 mAccessibilityTvScheduled = false;
3843 }
3844 return mAccessibilityTvScheduled;
3845 }
3846
Dmitri Plotnikov82e6dfc2017-02-24 18:10:54 -08003847 private void takeBugreport() {
3848 if ("1".equals(SystemProperties.get("ro.debuggable"))
3849 || Settings.Global.getInt(mContext.getContentResolver(),
3850 Settings.Global.DEVELOPMENT_SETTINGS_ENABLED, 0) == 1) {
3851 try {
3852 ActivityManager.getService()
3853 .requestBugReport(ActivityManager.BUGREPORT_OPTION_INTERACTIVE);
3854 } catch (RemoteException e) {
3855 Slog.e(TAG, "Error taking bugreport", e);
3856 }
3857 }
3858 }
3859
Jeff Brown3915bb82010-11-05 15:02:16 -07003860 /** {@inheritDoc} */
3861 @Override
Jeff Brown49ed71d2010-12-06 17:13:33 -08003862 public KeyEvent dispatchUnhandledKey(WindowState win, KeyEvent event, int policyFlags) {
Jeff Brown54875002011-04-06 15:33:01 -07003863 // Note: This method is only called if the initial down was unhandled.
Jeff Brown40013652012-05-16 21:22:36 -07003864 if (DEBUG_INPUT) {
Jeff Brown1f245102010-11-18 20:53:46 -08003865 Slog.d(TAG, "Unhandled key: win=" + win + ", action=" + event.getAction()
3866 + ", flags=" + event.getFlags()
3867 + ", keyCode=" + event.getKeyCode()
3868 + ", scanCode=" + event.getScanCode()
3869 + ", metaState=" + event.getMetaState()
3870 + ", repeatCount=" + event.getRepeatCount()
3871 + ", policyFlags=" + policyFlags);
Jeff Brown3915bb82010-11-05 15:02:16 -07003872 }
Jeff Brown49ed71d2010-12-06 17:13:33 -08003873
Jeff Brownfd23e3e2012-05-09 13:34:28 -07003874 KeyEvent fallbackEvent = null;
Jeff Brown49ed71d2010-12-06 17:13:33 -08003875 if ((event.getFlags() & KeyEvent.FLAG_FALLBACK) == 0) {
3876 final KeyCharacterMap kcm = event.getKeyCharacterMap();
Jeff Brownc1fb48d2010-12-08 16:52:09 -08003877 final int keyCode = event.getKeyCode();
3878 final int metaState = event.getMetaState();
Jeff Brownfd23e3e2012-05-09 13:34:28 -07003879 final boolean initialDown = event.getAction() == KeyEvent.ACTION_DOWN
3880 && event.getRepeatCount() == 0;
Jeff Brown49ed71d2010-12-06 17:13:33 -08003881
Jeff Brown54875002011-04-06 15:33:01 -07003882 // Check for fallback actions specified by the key character map.
Jeff Brownfd23e3e2012-05-09 13:34:28 -07003883 final FallbackAction fallbackAction;
3884 if (initialDown) {
3885 fallbackAction = kcm.getFallbackAction(keyCode, metaState);
3886 } else {
3887 fallbackAction = mFallbackActions.get(keyCode);
3888 }
3889
3890 if (fallbackAction != null) {
Jeff Brown40013652012-05-16 21:22:36 -07003891 if (DEBUG_INPUT) {
Jeff Brownfd23e3e2012-05-09 13:34:28 -07003892 Slog.d(TAG, "Fallback: keyCode=" + fallbackAction.keyCode
3893 + " metaState=" + Integer.toHexString(fallbackAction.metaState));
Jeff Brown49ed71d2010-12-06 17:13:33 -08003894 }
3895
Jeff Brownfd23e3e2012-05-09 13:34:28 -07003896 final int flags = event.getFlags() | KeyEvent.FLAG_FALLBACK;
3897 fallbackEvent = KeyEvent.obtain(
Jeff Brown49ed71d2010-12-06 17:13:33 -08003898 event.getDownTime(), event.getEventTime(),
Jeff Brownfd23e3e2012-05-09 13:34:28 -07003899 event.getAction(), fallbackAction.keyCode,
3900 event.getRepeatCount(), fallbackAction.metaState,
Jeff Brown49ed71d2010-12-06 17:13:33 -08003901 event.getDeviceId(), event.getScanCode(),
3902 flags, event.getSource(), null);
Jeff Brownfd23e3e2012-05-09 13:34:28 -07003903
3904 if (!interceptFallback(win, fallbackEvent, policyFlags)) {
3905 fallbackEvent.recycle();
3906 fallbackEvent = null;
Jeff Brown49ed71d2010-12-06 17:13:33 -08003907 }
Jeff Brownfd23e3e2012-05-09 13:34:28 -07003908
3909 if (initialDown) {
3910 mFallbackActions.put(keyCode, fallbackAction);
3911 } else if (event.getAction() == KeyEvent.ACTION_UP) {
3912 mFallbackActions.remove(keyCode);
3913 fallbackAction.recycle();
3914 }
Jeff Brown49ed71d2010-12-06 17:13:33 -08003915 }
3916 }
3917
Jeff Brown40013652012-05-16 21:22:36 -07003918 if (DEBUG_INPUT) {
Jeff Brownfd23e3e2012-05-09 13:34:28 -07003919 if (fallbackEvent == null) {
3920 Slog.d(TAG, "No fallback.");
3921 } else {
3922 Slog.d(TAG, "Performing fallback: " + fallbackEvent);
3923 }
Jeff Brown49ed71d2010-12-06 17:13:33 -08003924 }
Jeff Brownfd23e3e2012-05-09 13:34:28 -07003925 return fallbackEvent;
Jeff Brown3915bb82010-11-05 15:02:16 -07003926 }
3927
Jeff Brownfd23e3e2012-05-09 13:34:28 -07003928 private boolean interceptFallback(WindowState win, KeyEvent fallbackEvent, int policyFlags) {
Jeff Brown037c33e2014-04-09 00:31:55 -07003929 int actions = interceptKeyBeforeQueueing(fallbackEvent, policyFlags);
Jeff Brownfd23e3e2012-05-09 13:34:28 -07003930 if ((actions & ACTION_PASS_TO_USER) != 0) {
3931 long delayMillis = interceptKeyBeforeDispatching(
3932 win, fallbackEvent, policyFlags);
3933 if (delayMillis == 0) {
3934 return true;
3935 }
3936 }
3937 return false;
Jeff Brown6f2fba42011-02-19 01:08:02 -08003938 }
3939
Jim Millere4044bb2016-05-10 18:38:25 -07003940 @Override
Muyuan Li94ce94e2016-02-24 16:20:54 -08003941 public void registerShortcutKey(long shortcutCode, IShortcutService shortcutService)
3942 throws RemoteException {
3943 synchronized (mLock) {
3944 IShortcutService service = mShortcutKeyServices.get(shortcutCode);
Muyuan Li24d24ac2016-03-03 21:15:02 -08003945 if (service != null && service.asBinder().pingBinder()) {
3946 throw new RemoteException("Key already exists.");
Muyuan Li94ce94e2016-02-24 16:20:54 -08003947 }
3948
3949 mShortcutKeyServices.put(shortcutCode, shortcutService);
3950 }
3951 }
3952
Adrian Roosd88eb262016-08-04 14:50:48 -07003953 @Override
Jorim Jaggife762342016-10-13 14:33:27 +02003954 public void onKeyguardOccludedChangedLw(boolean occluded) {
3955 if (mKeyguardDelegate != null && mKeyguardDelegate.isShowing()) {
3956 mPendingKeyguardOccluded = occluded;
3957 mKeyguardOccludedChanged = true;
3958 } else {
Jorim Jaggi9ba2e102017-04-04 12:51:03 +02003959 setKeyguardOccludedLw(occluded, false /* force */);
Jorim Jaggife762342016-10-13 14:33:27 +02003960 }
3961 }
3962
3963 private int handleStartTransitionForKeyguardLw(int transit, @Nullable Animation anim) {
3964 if (mKeyguardOccludedChanged) {
3965 if (DEBUG_KEYGUARD) Slog.d(TAG, "transition/occluded changed occluded="
3966 + mPendingKeyguardOccluded);
3967 mKeyguardOccludedChanged = false;
Jorim Jaggi9ba2e102017-04-04 12:51:03 +02003968 if (setKeyguardOccludedLw(mPendingKeyguardOccluded, false /* force */)) {
Jorim Jaggife762342016-10-13 14:33:27 +02003969 return FINISH_LAYOUT_REDO_LAYOUT | FINISH_LAYOUT_REDO_WALLPAPER;
3970 }
3971 }
3972 if (AppTransition.isKeyguardGoingAwayTransit(transit)) {
Jorim Jaggi8d786932016-10-26 19:08:36 -07003973 if (DEBUG_KEYGUARD) Slog.d(TAG, "Starting keyguard exit animation");
Jorim Jaggife762342016-10-13 14:33:27 +02003974 final long startTime = anim != null
3975 ? SystemClock.uptimeMillis() + anim.getStartOffset()
3976 : SystemClock.uptimeMillis();
3977 final long duration = anim != null
3978 ? anim.getDuration()
3979 : 0;
3980 startKeyguardExitAnimation(startTime, duration);
3981 }
3982 return 0;
Adrian Roosd88eb262016-08-04 14:50:48 -07003983 }
3984
Jeff Brownde7a8ea2012-06-13 18:28:57 -07003985 private void launchAssistLongPressAction() {
3986 performHapticFeedbackLw(null, HapticFeedbackConstants.LONG_PRESS, false);
3987 sendCloseSystemWindows(SYSTEM_DIALOG_REASON_ASSIST);
3988
3989 // launch the search activity
3990 Intent intent = new Intent(Intent.ACTION_SEARCH_LONG_PRESS);
3991 intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
3992 try {
RoboErik8a2cfc32014-05-16 11:19:38 -07003993 // TODO: This only stops the factory-installed search manager.
Jim Miller45308b12012-06-18 19:23:39 -07003994 // Need to formalize an API to handle others
Jeff Brownde7a8ea2012-06-13 18:28:57 -07003995 SearchManager searchManager = getSearchManager();
3996 if (searchManager != null) {
3997 searchManager.stopSearch();
3998 }
Bart Sears8b1c27c2015-03-18 23:51:02 +00003999 startActivityAsUser(intent, UserHandle.CURRENT);
Jeff Brownde7a8ea2012-06-13 18:28:57 -07004000 } catch (ActivityNotFoundException e) {
4001 Slog.w(TAG, "No activity to handle assist long press action.", e);
4002 }
4003 }
4004
Tim Kilbourn0e5f1102015-06-05 16:18:09 -07004005 private void launchAssistAction(String hint, int deviceId) {
Jeff Brownde7a8ea2012-06-13 18:28:57 -07004006 sendCloseSystemWindows(SYSTEM_DIALOG_REASON_ASSIST);
Maurice Lam39d13812015-07-23 20:49:20 -07004007 if (!isUserSetupComplete()) {
4008 // Disable opening assist window during setup
4009 return;
4010 }
Tim Kilbourn0e5f1102015-06-05 16:18:09 -07004011 Bundle args = null;
4012 if (deviceId > Integer.MIN_VALUE) {
4013 args = new Bundle();
4014 args.putInt(Intent.EXTRA_ASSIST_INPUT_DEVICE_ID, deviceId);
Jeff Brownde7a8ea2012-06-13 18:28:57 -07004015 }
Jorim Jaggi165ce062015-07-06 16:18:11 -07004016 if ((mContext.getResources().getConfiguration().uiMode
4017 & Configuration.UI_MODE_TYPE_MASK) == Configuration.UI_MODE_TYPE_TELEVISION) {
4018 // On TV, use legacy handling until assistants are implemented in the proper way.
4019 ((SearchManager) mContext.getSystemService(Context.SEARCH_SERVICE))
4020 .launchLegacyAssist(hint, UserHandle.myUserId(), args);
4021 } else {
Adrian Roosf2efdd82016-04-15 17:43:18 -07004022 if (hint != null) {
4023 if (args == null) {
4024 args = new Bundle();
Jorim Jaggi165ce062015-07-06 16:18:11 -07004025 }
Adrian Roosf2efdd82016-04-15 17:43:18 -07004026 args.putBoolean(hint, true);
4027 }
4028 StatusBarManagerInternal statusbar = getStatusBarManagerInternal();
4029 if (statusbar != null) {
4030 statusbar.startAssist(args);
Jorim Jaggi165ce062015-07-06 16:18:11 -07004031 }
4032 }
Jeff Brownde7a8ea2012-06-13 18:28:57 -07004033 }
4034
Bart Sears8b1c27c2015-03-18 23:51:02 +00004035 private void startActivityAsUser(Intent intent, UserHandle handle) {
4036 if (isUserSetupComplete()) {
4037 mContext.startActivityAsUser(intent, handle);
4038 } else {
4039 Slog.i(TAG, "Not starting activity because user setup is in progress: " + intent);
4040 }
4041 }
4042
Jeff Brownde7a8ea2012-06-13 18:28:57 -07004043 private SearchManager getSearchManager() {
4044 if (mSearchManager == null) {
4045 mSearchManager = (SearchManager) mContext.getSystemService(Context.SEARCH_SERVICE);
4046 }
4047 return mSearchManager;
4048 }
4049
Jeff Browncaca8812013-05-09 13:34:33 -07004050 private void preloadRecentApps() {
4051 mPreloadedRecentApps = true;
Adrian Roosf2efdd82016-04-15 17:43:18 -07004052 StatusBarManagerInternal statusbar = getStatusBarManagerInternal();
4053 if (statusbar != null) {
4054 statusbar.preloadRecentApps();
Jeff Browncaca8812013-05-09 13:34:33 -07004055 }
4056 }
4057
4058 private void cancelPreloadRecentApps() {
4059 if (mPreloadedRecentApps) {
4060 mPreloadedRecentApps = false;
Adrian Roosf2efdd82016-04-15 17:43:18 -07004061 StatusBarManagerInternal statusbar = getStatusBarManagerInternal();
4062 if (statusbar != null) {
4063 statusbar.cancelPreloadRecentApps();
Jeff Browncaca8812013-05-09 13:34:33 -07004064 }
4065 }
4066 }
4067
4068 private void toggleRecentApps() {
4069 mPreloadedRecentApps = false; // preloading no longer needs to be canceled
Adrian Roosf2efdd82016-04-15 17:43:18 -07004070 StatusBarManagerInternal statusbar = getStatusBarManagerInternal();
4071 if (statusbar != null) {
4072 statusbar.toggleRecentApps();
Winson Chung1e8d71b2014-05-16 17:05:22 -07004073 }
4074 }
4075
Craig Mautner84984fa2014-06-19 11:19:20 -07004076 @Override
Jorim Jaggi681fc7b2016-04-14 22:02:39 -07004077 public void showRecentApps(boolean fromHome) {
Craig Mautner84984fa2014-06-19 11:19:20 -07004078 mHandler.removeMessages(MSG_DISPATCH_SHOW_RECENTS);
Jorim Jaggi681fc7b2016-04-14 22:02:39 -07004079 mHandler.obtainMessage(MSG_DISPATCH_SHOW_RECENTS, fromHome ? 1 : 0, 0).sendToTarget();
Craig Mautner84984fa2014-06-19 11:19:20 -07004080 }
4081
Jorim Jaggi681fc7b2016-04-14 22:02:39 -07004082 private void showRecentApps(boolean triggeredFromAltTab, boolean fromHome) {
Winson Chung1e8d71b2014-05-16 17:05:22 -07004083 mPreloadedRecentApps = false; // preloading no longer needs to be canceled
Adrian Roosf2efdd82016-04-15 17:43:18 -07004084 StatusBarManagerInternal statusbar = getStatusBarManagerInternal();
4085 if (statusbar != null) {
4086 statusbar.showRecentApps(triggeredFromAltTab, fromHome);
Jeff Browncaca8812013-05-09 13:34:33 -07004087 }
4088 }
4089
Clara Bayarri4e850ff2016-03-02 11:12:32 -08004090 private void toggleKeyboardShortcutsMenu(int deviceId) {
Adrian Roosf2efdd82016-04-15 17:43:18 -07004091 StatusBarManagerInternal statusbar = getStatusBarManagerInternal();
4092 if (statusbar != null) {
4093 statusbar.toggleKeyboardShortcutsMenu(deviceId);
Clara Bayarrif2debb12015-07-10 14:47:17 +01004094 }
4095 }
4096
Andrei Stingaceanu0bf096f2016-04-14 18:11:57 +01004097 private void dismissKeyboardShortcutsMenu() {
4098 StatusBarManagerInternal statusbar = getStatusBarManagerInternal();
4099 if (statusbar != null) {
4100 statusbar.dismissKeyboardShortcutsMenu();
4101 }
4102 }
4103
Winson Chungcdcd4872014-08-05 18:00:13 -07004104 private void hideRecentApps(boolean triggeredFromAltTab, boolean triggeredFromHome) {
Winson Chung1e8d71b2014-05-16 17:05:22 -07004105 mPreloadedRecentApps = false; // preloading no longer needs to be canceled
Adrian Roosf2efdd82016-04-15 17:43:18 -07004106 StatusBarManagerInternal statusbar = getStatusBarManagerInternal();
4107 if (statusbar != null) {
4108 statusbar.hideRecentApps(triggeredFromAltTab, triggeredFromHome);
Winson Chung1e8d71b2014-05-16 17:05:22 -07004109 }
4110 }
4111
Filip Gruszczynskia483a1d2015-03-17 19:06:58 +00004112 void launchHomeFromHotKey() {
Bryce Lee662ed802015-04-10 20:11:39 +00004113 launchHomeFromHotKey(true /* awakenFromDreams */, true /*respectKeyguard*/);
Filip Gruszczynskia483a1d2015-03-17 19:06:58 +00004114 }
4115
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004116 /**
4117 * A home key -> launch home action was detected. Take the appropriate action
4118 * given the situation with the keyguard.
4119 */
Bryce Lee662ed802015-04-10 20:11:39 +00004120 void launchHomeFromHotKey(final boolean awakenFromDreams, final boolean respectKeyguard) {
4121 if (respectKeyguard) {
4122 if (isKeyguardShowingAndNotOccluded()) {
4123 // don't launch home if keyguard showing
4124 return;
4125 }
4126
Jorim Jaggife762342016-10-13 14:33:27 +02004127 if (!mKeyguardOccluded && mKeyguardDelegate.isInputRestricted()) {
Bryce Lee662ed802015-04-10 20:11:39 +00004128 // when in keyguard restricted mode, must first verify unlock
4129 // before launching home
4130 mKeyguardDelegate.verifyUnlock(new OnKeyguardExitResult() {
4131 @Override
4132 public void onKeyguardExitResult(boolean success) {
4133 if (success) {
4134 try {
Sudheer Shankadc589ac2016-11-10 15:30:17 -08004135 ActivityManager.getService().stopAppSwitches();
Bryce Lee662ed802015-04-10 20:11:39 +00004136 } catch (RemoteException e) {
4137 }
4138 sendCloseSystemWindows(SYSTEM_DIALOG_REASON_HOME_KEY);
4139 startDockOrHome(true /*fromHomeKey*/, awakenFromDreams);
Dianne Hackborn256dd3b2009-05-19 18:51:21 -07004140 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004141 }
Bryce Lee662ed802015-04-10 20:11:39 +00004142 });
4143 return;
4144 }
4145 }
4146
4147 // no keyguard stuff to worry about, just launch home!
4148 try {
Sudheer Shankadc589ac2016-11-10 15:30:17 -08004149 ActivityManager.getService().stopAppSwitches();
Bryce Lee662ed802015-04-10 20:11:39 +00004150 } catch (RemoteException e) {
4151 }
4152 if (mRecentsVisible) {
4153 // Hide Recents and notify it to launch Home
4154 if (awakenFromDreams) {
4155 awakenDreams();
4156 }
Bryce Lee662ed802015-04-10 20:11:39 +00004157 hideRecentApps(false, true);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004158 } else {
Bryce Lee662ed802015-04-10 20:11:39 +00004159 // Otherwise, just launch Home
4160 sendCloseSystemWindows(SYSTEM_DIALOG_REASON_HOME_KEY);
4161 startDockOrHome(true /*fromHomeKey*/, awakenFromDreams);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004162 }
4163 }
4164
John Spurlock04db1762013-05-13 12:46:41 -04004165 private final Runnable mClearHideNavigationFlag = new Runnable() {
4166 @Override
4167 public void run() {
4168 synchronized (mWindowManagerFuncs.getWindowManagerLock()) {
4169 // Clear flags.
4170 mForceClearedSystemUiFlags &=
4171 ~View.SYSTEM_UI_FLAG_HIDE_NAVIGATION;
4172 }
4173 mWindowManagerFuncs.reevaluateStatusBarVisibility();
Dianne Hackborne26ab702011-10-16 13:21:33 -07004174 }
4175 };
4176
4177 /**
4178 * Input handler used while nav bar is hidden. Captures any touch on the screen,
4179 * to determine when the nav bar should be shown and prevent applications from
4180 * receiving those touches.
4181 */
Jeff Brown32cbc38552011-12-01 14:01:49 -08004182 final class HideNavInputEventReceiver extends InputEventReceiver {
4183 public HideNavInputEventReceiver(InputChannel inputChannel, Looper looper) {
4184 super(inputChannel, looper);
4185 }
4186
Dianne Hackborndf89e652011-10-06 22:35:11 -07004187 @Override
Tarandeep Singhe1cfcf42017-07-10 18:50:00 -07004188 public void onInputEvent(InputEvent event, int displayId) {
Dianne Hackborndf89e652011-10-06 22:35:11 -07004189 boolean handled = false;
4190 try {
Jeff Brown4952dfd2011-11-30 19:23:22 -08004191 if (event instanceof MotionEvent
4192 && (event.getSource() & InputDevice.SOURCE_CLASS_POINTER) != 0) {
4193 final MotionEvent motionEvent = (MotionEvent)event;
4194 if (motionEvent.getAction() == MotionEvent.ACTION_DOWN) {
Dianne Hackborndf89e652011-10-06 22:35:11 -07004195 // When the user taps down, we re-show the nav bar.
4196 boolean changed = false;
John Spurlock04db1762013-05-13 12:46:41 -04004197 synchronized (mWindowManagerFuncs.getWindowManagerLock()) {
Chong Zhang9f7fb092016-05-20 17:03:08 -07004198 if (mInputConsumer == null) {
4199 return;
4200 }
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07004201 // Any user activity always causes us to show the
4202 // navigation controls, if they had been hidden.
4203 // We also clear the low profile and only content
4204 // flags so that tapping on the screen will atomically
4205 // restore all currently hidden screen decorations.
4206 int newVal = mResettingSystemUiFlags |
4207 View.SYSTEM_UI_FLAG_HIDE_NAVIGATION |
4208 View.SYSTEM_UI_FLAG_LOW_PROFILE |
4209 View.SYSTEM_UI_FLAG_FULLSCREEN;
Dianne Hackborne26ab702011-10-16 13:21:33 -07004210 if (mResettingSystemUiFlags != newVal) {
4211 mResettingSystemUiFlags = newVal;
Dianne Hackborndf89e652011-10-06 22:35:11 -07004212 changed = true;
4213 }
Dianne Hackborne26ab702011-10-16 13:21:33 -07004214 // We don't allow the system's nav bar to be hidden
4215 // again for 1 second, to prevent applications from
4216 // spamming us and keeping it from being shown.
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07004217 newVal = mForceClearedSystemUiFlags |
4218 View.SYSTEM_UI_FLAG_HIDE_NAVIGATION;
Dianne Hackborne26ab702011-10-16 13:21:33 -07004219 if (mForceClearedSystemUiFlags != newVal) {
4220 mForceClearedSystemUiFlags = newVal;
4221 changed = true;
John Spurlock04db1762013-05-13 12:46:41 -04004222 mHandler.postDelayed(mClearHideNavigationFlag, 1000);
Dianne Hackborne26ab702011-10-16 13:21:33 -07004223 }
Dianne Hackborndf89e652011-10-06 22:35:11 -07004224 }
4225 if (changed) {
4226 mWindowManagerFuncs.reevaluateStatusBarVisibility();
4227 }
4228 }
4229 }
4230 } finally {
Jeff Brown32cbc38552011-12-01 14:01:49 -08004231 finishInputEvent(event, handled);
Dianne Hackborndf89e652011-10-06 22:35:11 -07004232 }
4233 }
Jeff Brown32cbc38552011-12-01 14:01:49 -08004234 }
Dianne Hackborndf89e652011-10-06 22:35:11 -07004235
4236 @Override
Winsonab216602016-08-09 14:05:20 -07004237 public void setRecentsVisibilityLw(boolean visible) {
4238 mRecentsVisible = visible;
4239 }
4240
4241 @Override
Winson Chungac52f282017-03-30 14:44:52 -07004242 public void setPipVisibilityLw(boolean visible) {
4243 mPictureInPictureVisible = visible;
Winsonab216602016-08-09 14:05:20 -07004244 }
4245
4246 @Override
Dianne Hackborndf89e652011-10-06 22:35:11 -07004247 public int adjustSystemUiVisibilityLw(int visibility) {
John Spurlock5b9145b2013-08-20 15:13:47 -04004248 mStatusBarController.adjustSystemUiVisibilityLw(mLastSystemUiFlags, visibility);
4249 mNavigationBarController.adjustSystemUiVisibilityLw(mLastSystemUiFlags, visibility);
John Spurlock27735a42013-08-14 17:57:38 -04004250
Dianne Hackborndf89e652011-10-06 22:35:11 -07004251 // Reset any bits in mForceClearingStatusBarVisibility that
4252 // are now clear.
Dianne Hackborne26ab702011-10-16 13:21:33 -07004253 mResettingSystemUiFlags &= visibility;
Dianne Hackborndf89e652011-10-06 22:35:11 -07004254 // Clear any bits in the new visibility that are currently being
4255 // force cleared, before reporting it.
Dianne Hackborne26ab702011-10-16 13:21:33 -07004256 return visibility & ~mResettingSystemUiFlags
4257 & ~mForceClearedSystemUiFlags;
Dianne Hackborndf89e652011-10-06 22:35:11 -07004258 }
4259
Craig Mautner69b08182012-09-05 13:07:13 -07004260 @Override
Jorim Jaggi23bf5462016-05-13 15:24:39 -07004261 public boolean getInsetHintLw(WindowManager.LayoutParams attrs, Rect taskBounds,
4262 int displayRotation, int displayWidth, int displayHeight, Rect outContentInsets,
4263 Rect outStableInsets, Rect outOutsets) {
John Spurlockc6d1c602014-01-17 15:22:06 -05004264 final int fl = PolicyControl.getWindowFlags(null, attrs);
John Spurlock1db8b682014-02-18 11:18:59 -05004265 final int sysuiVis = PolicyControl.getSystemUiVisibility(null, attrs);
4266 final int systemUiVisibility = (sysuiVis | attrs.subtreeSystemUiVisibility);
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07004267
Filip Gruszczynski2987f612015-06-30 15:03:30 -07004268 final boolean useOutsets = outOutsets != null && shouldUseOutsets(attrs, fl);
4269 if (useOutsets) {
4270 int outset = ScreenShapeHelper.getWindowOutsetBottomPx(mContext.getResources());
4271 if (outset > 0) {
4272 if (displayRotation == Surface.ROTATION_0) {
4273 outOutsets.bottom += outset;
4274 } else if (displayRotation == Surface.ROTATION_90) {
4275 outOutsets.right += outset;
4276 } else if (displayRotation == Surface.ROTATION_180) {
4277 outOutsets.top += outset;
4278 } else if (displayRotation == Surface.ROTATION_270) {
4279 outOutsets.left += outset;
4280 }
4281 }
4282 }
4283
Dianne Hackborn5b5cc4d2012-05-16 13:15:00 -07004284 if ((fl & (FLAG_LAYOUT_IN_SCREEN | FLAG_LAYOUT_INSET_DECOR))
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004285 == (FLAG_LAYOUT_IN_SCREEN | FLAG_LAYOUT_INSET_DECOR)) {
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07004286 int availRight, availBottom;
Alan Viverette5a0f4ec2013-10-07 15:10:29 -07004287 if (canHideNavigationBar() &&
Dianne Hackborn5b5cc4d2012-05-16 13:15:00 -07004288 (systemUiVisibility & View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION) != 0) {
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07004289 availRight = mUnrestrictedScreenLeft + mUnrestrictedScreenWidth;
4290 availBottom = mUnrestrictedScreenTop + mUnrestrictedScreenHeight;
4291 } else {
4292 availRight = mRestrictedScreenLeft + mRestrictedScreenWidth;
4293 availBottom = mRestrictedScreenTop + mRestrictedScreenHeight;
4294 }
Dianne Hackborn5b5cc4d2012-05-16 13:15:00 -07004295 if ((systemUiVisibility & View.SYSTEM_UI_FLAG_LAYOUT_STABLE) != 0) {
4296 if ((fl & FLAG_FULLSCREEN) != 0) {
Adrian Roos37d7a682014-11-06 18:15:16 +01004297 outContentInsets.set(mStableFullscreenLeft, mStableFullscreenTop,
Dianne Hackborn5b5cc4d2012-05-16 13:15:00 -07004298 availRight - mStableFullscreenRight,
4299 availBottom - mStableFullscreenBottom);
4300 } else {
Adrian Roos37d7a682014-11-06 18:15:16 +01004301 outContentInsets.set(mStableLeft, mStableTop,
Dianne Hackborn5b5cc4d2012-05-16 13:15:00 -07004302 availRight - mStableRight, availBottom - mStableBottom);
4303 }
Dianne Hackbornc652de82013-02-15 16:32:56 -08004304 } else if ((fl & FLAG_FULLSCREEN) != 0 || (fl & FLAG_LAYOUT_IN_OVERSCAN) != 0) {
Adrian Roos37d7a682014-11-06 18:15:16 +01004305 outContentInsets.setEmpty();
Dianne Hackborn5b5cc4d2012-05-16 13:15:00 -07004306 } else if ((systemUiVisibility & (View.SYSTEM_UI_FLAG_FULLSCREEN
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07004307 | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN)) == 0) {
Adrian Roos37d7a682014-11-06 18:15:16 +01004308 outContentInsets.set(mCurLeft, mCurTop,
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07004309 availRight - mCurRight, availBottom - mCurBottom);
4310 } else {
Adrian Roos37d7a682014-11-06 18:15:16 +01004311 outContentInsets.set(mCurLeft, mCurTop,
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07004312 availRight - mCurRight, availBottom - mCurBottom);
4313 }
Adrian Roos37d7a682014-11-06 18:15:16 +01004314
4315 outStableInsets.set(mStableLeft, mStableTop,
4316 availRight - mStableRight, availBottom - mStableBottom);
Jorim Jaggi23bf5462016-05-13 15:24:39 -07004317 if (taskBounds != null) {
4318 calculateRelevantTaskInsets(taskBounds, outContentInsets,
4319 displayWidth, displayHeight);
4320 calculateRelevantTaskInsets(taskBounds, outStableInsets,
4321 displayWidth, displayHeight);
4322 }
Jorim Jaggi0ffd49c2016-02-12 15:04:21 -08004323 return mForceShowSystemBars;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004324 }
Adrian Roos37d7a682014-11-06 18:15:16 +01004325 outContentInsets.setEmpty();
4326 outStableInsets.setEmpty();
Jorim Jaggi0ffd49c2016-02-12 15:04:21 -08004327 return mForceShowSystemBars;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004328 }
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07004329
Jorim Jaggi23bf5462016-05-13 15:24:39 -07004330 /**
4331 * For any given task bounds, the insets relevant for these bounds given the insets relevant
4332 * for the entire display.
4333 */
4334 private void calculateRelevantTaskInsets(Rect taskBounds, Rect inOutInsets, int displayWidth,
4335 int displayHeight) {
4336 mTmpRect.set(0, 0, displayWidth, displayHeight);
4337 mTmpRect.inset(inOutInsets);
4338 mTmpRect.intersect(taskBounds);
4339 int leftInset = mTmpRect.left - taskBounds.left;
4340 int topInset = mTmpRect.top - taskBounds.top;
4341 int rightInset = taskBounds.right - mTmpRect.right;
4342 int bottomInset = taskBounds.bottom - mTmpRect.bottom;
4343 inOutInsets.set(leftInset, topInset, rightInset, bottomInset);
4344 }
4345
Filip Gruszczynski2987f612015-06-30 15:03:30 -07004346 private boolean shouldUseOutsets(WindowManager.LayoutParams attrs, int fl) {
4347 return attrs.type == TYPE_WALLPAPER || (fl & (WindowManager.LayoutParams.FLAG_FULLSCREEN
4348 | WindowManager.LayoutParams.FLAG_LAYOUT_IN_OVERSCAN)) != 0;
4349 }
4350
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004351 /** {@inheritDoc} */
Craig Mautner69b08182012-09-05 13:07:13 -07004352 @Override
4353 public void beginLayoutLw(boolean isDefaultDisplay, int displayWidth, int displayHeight,
Sriram Viswanathan9ebbe6a2015-11-16 17:59:22 -08004354 int displayRotation, int uiMode) {
Filip Gruszczynski2987f612015-06-30 15:03:30 -07004355 mDisplayRotation = displayRotation;
Dianne Hackbornc652de82013-02-15 16:32:56 -08004356 final int overscanLeft, overscanTop, overscanRight, overscanBottom;
4357 if (isDefaultDisplay) {
4358 switch (displayRotation) {
4359 case Surface.ROTATION_90:
4360 overscanLeft = mOverscanTop;
4361 overscanTop = mOverscanRight;
4362 overscanRight = mOverscanBottom;
4363 overscanBottom = mOverscanLeft;
4364 break;
4365 case Surface.ROTATION_180:
4366 overscanLeft = mOverscanRight;
4367 overscanTop = mOverscanBottom;
4368 overscanRight = mOverscanLeft;
4369 overscanBottom = mOverscanTop;
4370 break;
4371 case Surface.ROTATION_270:
4372 overscanLeft = mOverscanBottom;
4373 overscanTop = mOverscanLeft;
4374 overscanRight = mOverscanTop;
4375 overscanBottom = mOverscanRight;
4376 break;
4377 default:
4378 overscanLeft = mOverscanLeft;
4379 overscanTop = mOverscanTop;
4380 overscanRight = mOverscanRight;
4381 overscanBottom = mOverscanBottom;
4382 break;
4383 }
4384 } else {
4385 overscanLeft = 0;
4386 overscanTop = 0;
4387 overscanRight = 0;
4388 overscanBottom = 0;
4389 }
Dianne Hackborn313440842013-02-19 19:22:59 -08004390 mOverscanScreenLeft = mRestrictedOverscanScreenLeft = 0;
4391 mOverscanScreenTop = mRestrictedOverscanScreenTop = 0;
4392 mOverscanScreenWidth = mRestrictedOverscanScreenWidth = displayWidth;
4393 mOverscanScreenHeight = mRestrictedOverscanScreenHeight = displayHeight;
Dianne Hackbornc652de82013-02-15 16:32:56 -08004394 mSystemLeft = 0;
4395 mSystemTop = 0;
4396 mSystemRight = displayWidth;
4397 mSystemBottom = displayHeight;
4398 mUnrestrictedScreenLeft = overscanLeft;
4399 mUnrestrictedScreenTop = overscanTop;
4400 mUnrestrictedScreenWidth = displayWidth - overscanLeft - overscanRight;
4401 mUnrestrictedScreenHeight = displayHeight - overscanTop - overscanBottom;
4402 mRestrictedScreenLeft = mUnrestrictedScreenLeft;
4403 mRestrictedScreenTop = mUnrestrictedScreenTop;
John Spurlockad3e6cb2013-04-30 08:47:43 -04004404 mRestrictedScreenWidth = mSystemGestures.screenWidth = mUnrestrictedScreenWidth;
4405 mRestrictedScreenHeight = mSystemGestures.screenHeight = mUnrestrictedScreenHeight;
Dianne Hackborne30e02f2014-05-27 18:24:45 -07004406 mDockLeft = mContentLeft = mVoiceContentLeft = mStableLeft = mStableFullscreenLeft
Dianne Hackbornc652de82013-02-15 16:32:56 -08004407 = mCurLeft = mUnrestrictedScreenLeft;
Dianne Hackborne30e02f2014-05-27 18:24:45 -07004408 mDockTop = mContentTop = mVoiceContentTop = mStableTop = mStableFullscreenTop
Dianne Hackbornc652de82013-02-15 16:32:56 -08004409 = mCurTop = mUnrestrictedScreenTop;
Dianne Hackborne30e02f2014-05-27 18:24:45 -07004410 mDockRight = mContentRight = mVoiceContentRight = mStableRight = mStableFullscreenRight
Dianne Hackbornc652de82013-02-15 16:32:56 -08004411 = mCurRight = displayWidth - overscanRight;
Dianne Hackborne30e02f2014-05-27 18:24:45 -07004412 mDockBottom = mContentBottom = mVoiceContentBottom = mStableBottom = mStableFullscreenBottom
Dianne Hackbornc652de82013-02-15 16:32:56 -08004413 = mCurBottom = displayHeight - overscanBottom;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004414 mDockLayer = 0x10000000;
Dianne Hackborn5c58de32012-04-28 19:52:37 -07004415 mStatusBarLayer = -1;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004416
Daniel Sandler8956dbb2011-04-22 07:55:02 -04004417 // start with the current dock rect, which will be (0,0,displayWidth,displayHeight)
4418 final Rect pf = mTmpParentFrame;
4419 final Rect df = mTmpDisplayFrame;
Dianne Hackbornc4aad012013-02-22 15:05:25 -08004420 final Rect of = mTmpOverscanFrame;
Daniel Sandler8956dbb2011-04-22 07:55:02 -04004421 final Rect vf = mTmpVisibleFrame;
John Spurlock46646232013-09-30 22:32:42 -04004422 final Rect dcf = mTmpDecorFrame;
Dianne Hackbornc4aad012013-02-22 15:05:25 -08004423 pf.left = df.left = of.left = vf.left = mDockLeft;
4424 pf.top = df.top = of.top = vf.top = mDockTop;
4425 pf.right = df.right = of.right = vf.right = mDockRight;
4426 pf.bottom = df.bottom = of.bottom = vf.bottom = mDockBottom;
John Spurlock46646232013-09-30 22:32:42 -04004427 dcf.setEmpty(); // Decor frame N/A for system bars.
Daniel Sandler8956dbb2011-04-22 07:55:02 -04004428
Craig Mautner69b08182012-09-05 13:07:13 -07004429 if (isDefaultDisplay) {
4430 // For purposes of putting out fake window up to steal focus, we will
4431 // drive nav being hidden only by whether it is requested.
John Spurlocke1f366f2013-08-05 12:22:40 -04004432 final int sysui = mLastSystemUiFlags;
4433 boolean navVisible = (sysui & View.SYSTEM_UI_FLAG_HIDE_NAVIGATION) == 0;
Adrian Roosea562512014-05-05 13:33:03 +02004434 boolean navTranslucent = (sysui
Jorim Jaggi4fa78922015-11-30 17:13:56 -08004435 & (View.NAVIGATION_BAR_TRANSLUCENT | View.NAVIGATION_BAR_TRANSPARENT)) != 0;
John Spurlockf1a36642013-10-12 17:50:42 -04004436 boolean immersive = (sysui & View.SYSTEM_UI_FLAG_IMMERSIVE) != 0;
4437 boolean immersiveSticky = (sysui & View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY) != 0;
4438 boolean navAllowedHidden = immersive || immersiveSticky;
4439 navTranslucent &= !immersiveSticky; // transient trumps translucent
Jorim Jaggife762342016-10-13 14:33:27 +02004440 boolean isKeyguardShowing = isStatusBarKeyguard() && !mKeyguardOccluded;
Adrian Roos4fb3ee32014-08-22 19:29:09 +02004441 if (!isKeyguardShowing) {
4442 navTranslucent &= areTranslucentBarsAllowed();
4443 }
Jaewan Kim33284332016-05-12 18:55:46 +09004444 boolean statusBarExpandedNotKeyguard = !isKeyguardShowing && mStatusBar != null
Adrian Roosdb1bc6b2016-04-14 17:49:43 -07004445 && mStatusBar.getAttrs().height == MATCH_PARENT
4446 && mStatusBar.getAttrs().width == MATCH_PARENT;
Dianne Hackborne26ab702011-10-16 13:21:33 -07004447
Craig Mautner69b08182012-09-05 13:07:13 -07004448 // When the navigation bar isn't visible, we put up a fake
4449 // input window to catch all touch events. This way we can
4450 // detect when the user presses anywhere to bring back the nav
4451 // bar and ensure the application doesn't see the event.
John Spurlockf1a36642013-10-12 17:50:42 -04004452 if (navVisible || navAllowedHidden) {
Selim Cinekf83e8242015-05-19 18:08:14 -07004453 if (mInputConsumer != null) {
Chong Zhang9f7fb092016-05-20 17:03:08 -07004454 mHandler.sendMessage(
4455 mHandler.obtainMessage(MSG_DISPOSE_INPUT_CONSUMER, mInputConsumer));
Selim Cinekf83e8242015-05-19 18:08:14 -07004456 mInputConsumer = null;
Craig Mautner69b08182012-09-05 13:07:13 -07004457 }
Selim Cinekf83e8242015-05-19 18:08:14 -07004458 } else if (mInputConsumer == null) {
Winson41275482016-10-10 15:17:45 -07004459 mInputConsumer = mWindowManagerFuncs.createInputConsumer(mHandler.getLooper(),
4460 INPUT_CONSUMER_NAVIGATION,
4461 (channel, looper) -> new HideNavInputEventReceiver(channel, looper));
Vladislav Kaznacheev19dab2d2017-02-07 10:12:51 -08004462 // As long as mInputConsumer is active, hover events are not dispatched to the app
4463 // and the pointer icon is likely to become stale. Hide it to avoid confusion.
4464 InputManager.getInstance().setPointerIconType(PointerIcon.TYPE_NULL);
Dianne Hackborne26ab702011-10-16 13:21:33 -07004465 }
Dianne Hackborne26ab702011-10-16 13:21:33 -07004466
Craig Mautner69b08182012-09-05 13:07:13 -07004467 // For purposes of positioning and showing the nav bar, if we have
4468 // decided that it can't be hidden (because of the screen aspect ratio),
4469 // then take that into account.
Alan Viverette5a0f4ec2013-10-07 15:10:29 -07004470 navVisible |= !canHideNavigationBar();
Dianne Hackbornf87d1962012-04-04 12:48:24 -07004471
Filip Gruszczynski83dd9552015-09-17 17:50:36 -07004472 boolean updateSysUiVisibility = layoutNavigationBar(displayWidth, displayHeight,
Adrian Roos85d202b2016-06-02 16:27:47 -07004473 displayRotation, uiMode, overscanLeft, overscanRight, overscanBottom, dcf, navVisible, navTranslucent,
Adrian Roosdb1bc6b2016-04-14 17:49:43 -07004474 navAllowedHidden, statusBarExpandedNotKeyguard);
Craig Mautnereda67292013-04-28 13:50:14 -07004475 if (DEBUG_LAYOUT) Slog.i(TAG, String.format("mDock rect: (%d,%d - %d,%d)",
Craig Mautner69b08182012-09-05 13:07:13 -07004476 mDockLeft, mDockTop, mDockRight, mDockBottom));
Filip Gruszczynski83dd9552015-09-17 17:50:36 -07004477 updateSysUiVisibility |= layoutStatusBar(pf, df, of, vf, dcf, sysui, isKeyguardShowing);
John Spurlockad3e6cb2013-04-30 08:47:43 -04004478 if (updateSysUiVisibility) {
4479 updateSystemUiVisibilityLw();
4480 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004481 }
4482 }
4483
Filip Gruszczynski83dd9552015-09-17 17:50:36 -07004484 private boolean layoutStatusBar(Rect pf, Rect df, Rect of, Rect vf, Rect dcf, int sysui,
4485 boolean isKeyguardShowing) {
4486 // decide where the status bar goes ahead of time
4487 if (mStatusBar != null) {
4488 // apply any navigation bar insets
4489 pf.left = df.left = of.left = mUnrestrictedScreenLeft;
4490 pf.top = df.top = of.top = mUnrestrictedScreenTop;
4491 pf.right = df.right = of.right = mUnrestrictedScreenWidth + mUnrestrictedScreenLeft;
4492 pf.bottom = df.bottom = of.bottom = mUnrestrictedScreenHeight
4493 + mUnrestrictedScreenTop;
4494 vf.left = mStableLeft;
4495 vf.top = mStableTop;
4496 vf.right = mStableRight;
4497 vf.bottom = mStableBottom;
4498
4499 mStatusBarLayer = mStatusBar.getSurfaceLayer();
4500
4501 // Let the status bar determine its size.
4502 mStatusBar.computeFrameLw(pf /* parentFrame */, df /* displayFrame */,
4503 vf /* overlayFrame */, vf /* contentFrame */, vf /* visibleFrame */,
4504 dcf /* decorFrame */, vf /* stableFrame */, vf /* outsetFrame */);
4505
4506 // For layout, the status bar is always at the top with our fixed height.
4507 mStableTop = mUnrestrictedScreenTop + mStatusBarHeight;
4508
4509 boolean statusBarTransient = (sysui & View.STATUS_BAR_TRANSIENT) != 0;
4510 boolean statusBarTranslucent = (sysui
Jorim Jaggi4fa78922015-11-30 17:13:56 -08004511 & (View.STATUS_BAR_TRANSLUCENT | View.STATUS_BAR_TRANSPARENT)) != 0;
Filip Gruszczynski83dd9552015-09-17 17:50:36 -07004512 if (!isKeyguardShowing) {
4513 statusBarTranslucent &= areTranslucentBarsAllowed();
4514 }
4515
4516 // If the status bar is hidden, we don't want to cause
4517 // windows behind it to scroll.
4518 if (mStatusBar.isVisibleLw() && !statusBarTransient) {
4519 // Status bar may go away, so the screen area it occupies
4520 // is available to apps but just covering them when the
4521 // status bar is visible.
4522 mDockTop = mUnrestrictedScreenTop + mStatusBarHeight;
4523
4524 mContentTop = mVoiceContentTop = mCurTop = mDockTop;
4525 mContentBottom = mVoiceContentBottom = mCurBottom = mDockBottom;
4526 mContentLeft = mVoiceContentLeft = mCurLeft = mDockLeft;
4527 mContentRight = mVoiceContentRight = mCurRight = mDockRight;
4528
4529 if (DEBUG_LAYOUT) Slog.v(TAG, "Status bar: " +
4530 String.format(
4531 "dock=[%d,%d][%d,%d] content=[%d,%d][%d,%d] cur=[%d,%d][%d,%d]",
4532 mDockLeft, mDockTop, mDockRight, mDockBottom,
4533 mContentLeft, mContentTop, mContentRight, mContentBottom,
4534 mCurLeft, mCurTop, mCurRight, mCurBottom));
4535 }
4536 if (mStatusBar.isVisibleLw() && !mStatusBar.isAnimatingLw()
4537 && !statusBarTransient && !statusBarTranslucent
4538 && !mStatusBarController.wasRecentlyTranslucent()) {
4539 // If the opaque status bar is currently requested to be visible,
4540 // and not in the process of animating on or off, then
4541 // we can tell the app that it is covered by it.
4542 mSystemTop = mUnrestrictedScreenTop + mStatusBarHeight;
4543 }
4544 if (mStatusBarController.checkHiddenLw()) {
4545 return true;
4546 }
4547 }
4548 return false;
4549 }
4550
4551 private boolean layoutNavigationBar(int displayWidth, int displayHeight, int displayRotation,
Adrian Roos85d202b2016-06-02 16:27:47 -07004552 int uiMode, int overscanLeft, int overscanRight, int overscanBottom, Rect dcf,
4553 boolean navVisible, boolean navTranslucent, boolean navAllowedHidden,
Adrian Roosdb1bc6b2016-04-14 17:49:43 -07004554 boolean statusBarExpandedNotKeyguard) {
Filip Gruszczynski83dd9552015-09-17 17:50:36 -07004555 if (mNavigationBar != null) {
4556 boolean transientNavBarShowing = mNavigationBarController.isTransientShowing();
4557 // Force the navigation bar to its appropriate place and
4558 // size. We need to do this directly, instead of relying on
4559 // it to bubble up from the nav bar, because this needs to
4560 // change atomically with screen rotations.
Adrian Roos85d202b2016-06-02 16:27:47 -07004561 mNavigationBarPosition = navigationBarPosition(displayWidth, displayHeight,
4562 displayRotation);
4563 if (mNavigationBarPosition == NAV_BAR_BOTTOM) {
Filip Gruszczynski83dd9552015-09-17 17:50:36 -07004564 // It's a system nav bar or a portrait screen; nav bar goes on bottom.
4565 int top = displayHeight - overscanBottom
Sriram Viswanathan9ebbe6a2015-11-16 17:59:22 -08004566 - getNavigationBarHeight(displayRotation, uiMode);
Filip Gruszczynski83dd9552015-09-17 17:50:36 -07004567 mTmpNavigationFrame.set(0, top, displayWidth, displayHeight - overscanBottom);
4568 mStableBottom = mStableFullscreenBottom = mTmpNavigationFrame.top;
4569 if (transientNavBarShowing) {
4570 mNavigationBarController.setBarShowingLw(true);
4571 } else if (navVisible) {
4572 mNavigationBarController.setBarShowingLw(true);
4573 mDockBottom = mTmpNavigationFrame.top;
4574 mRestrictedScreenHeight = mDockBottom - mRestrictedScreenTop;
4575 mRestrictedOverscanScreenHeight = mDockBottom - mRestrictedOverscanScreenTop;
4576 } else {
Adrian Roosdb1bc6b2016-04-14 17:49:43 -07004577 // We currently want to hide the navigation UI - unless we expanded the status
4578 // bar.
4579 mNavigationBarController.setBarShowingLw(statusBarExpandedNotKeyguard);
Filip Gruszczynski83dd9552015-09-17 17:50:36 -07004580 }
4581 if (navVisible && !navTranslucent && !navAllowedHidden
4582 && !mNavigationBar.isAnimatingLw()
4583 && !mNavigationBarController.wasRecentlyTranslucent()) {
4584 // If the opaque nav bar is currently requested to be visible,
4585 // and not in the process of animating on or off, then
4586 // we can tell the app that it is covered by it.
4587 mSystemBottom = mTmpNavigationFrame.top;
4588 }
Adrian Roos85d202b2016-06-02 16:27:47 -07004589 } else if (mNavigationBarPosition == NAV_BAR_RIGHT) {
Filip Gruszczynski83dd9552015-09-17 17:50:36 -07004590 // Landscape screen; nav bar goes to the right.
4591 int left = displayWidth - overscanRight
Sriram Viswanathan9ebbe6a2015-11-16 17:59:22 -08004592 - getNavigationBarWidth(displayRotation, uiMode);
Filip Gruszczynski83dd9552015-09-17 17:50:36 -07004593 mTmpNavigationFrame.set(left, 0, displayWidth - overscanRight, displayHeight);
4594 mStableRight = mStableFullscreenRight = mTmpNavigationFrame.left;
4595 if (transientNavBarShowing) {
4596 mNavigationBarController.setBarShowingLw(true);
4597 } else if (navVisible) {
4598 mNavigationBarController.setBarShowingLw(true);
4599 mDockRight = mTmpNavigationFrame.left;
4600 mRestrictedScreenWidth = mDockRight - mRestrictedScreenLeft;
4601 mRestrictedOverscanScreenWidth = mDockRight - mRestrictedOverscanScreenLeft;
4602 } else {
Adrian Roosdb1bc6b2016-04-14 17:49:43 -07004603 // We currently want to hide the navigation UI - unless we expanded the status
4604 // bar.
4605 mNavigationBarController.setBarShowingLw(statusBarExpandedNotKeyguard);
Filip Gruszczynski83dd9552015-09-17 17:50:36 -07004606 }
4607 if (navVisible && !navTranslucent && !navAllowedHidden
4608 && !mNavigationBar.isAnimatingLw()
4609 && !mNavigationBarController.wasRecentlyTranslucent()) {
4610 // If the nav bar is currently requested to be visible,
4611 // and not in the process of animating on or off, then
4612 // we can tell the app that it is covered by it.
4613 mSystemRight = mTmpNavigationFrame.left;
4614 }
Adrian Roos85d202b2016-06-02 16:27:47 -07004615 } else if (mNavigationBarPosition == NAV_BAR_LEFT) {
4616 // Seascape screen; nav bar goes to the left.
4617 int right = overscanLeft + getNavigationBarWidth(displayRotation, uiMode);
4618 mTmpNavigationFrame.set(overscanLeft, 0, right, displayHeight);
4619 mStableLeft = mStableFullscreenLeft = mTmpNavigationFrame.right;
4620 if (transientNavBarShowing) {
4621 mNavigationBarController.setBarShowingLw(true);
4622 } else if (navVisible) {
4623 mNavigationBarController.setBarShowingLw(true);
4624 mDockLeft = mTmpNavigationFrame.right;
4625 // TODO: not so sure about those:
4626 mRestrictedScreenLeft = mRestrictedOverscanScreenLeft = mDockLeft;
4627 mRestrictedScreenWidth = mDockRight - mRestrictedScreenLeft;
4628 mRestrictedOverscanScreenWidth = mDockRight - mRestrictedOverscanScreenLeft;
4629 } else {
4630 // We currently want to hide the navigation UI - unless we expanded the status
4631 // bar.
4632 mNavigationBarController.setBarShowingLw(statusBarExpandedNotKeyguard);
4633 }
4634 if (navVisible && !navTranslucent && !navAllowedHidden
4635 && !mNavigationBar.isAnimatingLw()
4636 && !mNavigationBarController.wasRecentlyTranslucent()) {
4637 // If the nav bar is currently requested to be visible,
4638 // and not in the process of animating on or off, then
4639 // we can tell the app that it is covered by it.
4640 mSystemLeft = mTmpNavigationFrame.right;
4641 }
Filip Gruszczynski83dd9552015-09-17 17:50:36 -07004642 }
4643 // Make sure the content and current rectangles are updated to
4644 // account for the restrictions from the navigation bar.
4645 mContentTop = mVoiceContentTop = mCurTop = mDockTop;
4646 mContentBottom = mVoiceContentBottom = mCurBottom = mDockBottom;
4647 mContentLeft = mVoiceContentLeft = mCurLeft = mDockLeft;
4648 mContentRight = mVoiceContentRight = mCurRight = mDockRight;
4649 mStatusBarLayer = mNavigationBar.getSurfaceLayer();
4650 // And compute the final frame.
4651 mNavigationBar.computeFrameLw(mTmpNavigationFrame, mTmpNavigationFrame,
4652 mTmpNavigationFrame, mTmpNavigationFrame, mTmpNavigationFrame, dcf,
4653 mTmpNavigationFrame, mTmpNavigationFrame);
4654 if (DEBUG_LAYOUT) Slog.i(TAG, "mNavigationBar frame: " + mTmpNavigationFrame);
4655 if (mNavigationBarController.checkHiddenLw()) {
4656 return true;
4657 }
4658 }
4659 return false;
4660 }
4661
Adrian Roos85d202b2016-06-02 16:27:47 -07004662 private int navigationBarPosition(int displayWidth, int displayHeight, int displayRotation) {
4663 if (mNavigationBarCanMove && displayWidth > displayHeight) {
4664 if (displayRotation == Surface.ROTATION_270) {
4665 return NAV_BAR_LEFT;
4666 } else {
4667 return NAV_BAR_RIGHT;
4668 }
4669 }
4670 return NAV_BAR_BOTTOM;
Jorim Jaggi737af722015-12-31 10:42:27 +01004671 }
4672
Dianne Hackborn85afd1b2012-05-13 13:31:06 -07004673 /** {@inheritDoc} */
Craig Mautner967212c2013-04-13 21:10:58 -07004674 @Override
John Spurlock46646232013-09-30 22:32:42 -04004675 public int getSystemDecorLayerLw() {
Bryce Lee2ed3e5f2015-04-01 22:09:19 +00004676 if (mStatusBar != null && mStatusBar.isVisibleLw()) {
4677 return mStatusBar.getSurfaceLayer();
4678 }
4679
4680 if (mNavigationBar != null && mNavigationBar.isVisibleLw()) {
4681 return mNavigationBar.getSurfaceLayer();
4682 }
4683
Dianne Hackborn85afd1b2012-05-13 13:31:06 -07004684 return 0;
4685 }
4686
Craig Mautner967212c2013-04-13 21:10:58 -07004687 @Override
4688 public void getContentRectLw(Rect r) {
4689 r.set(mContentLeft, mContentTop, mContentRight, mContentBottom);
4690 }
4691
Dianne Hackbornc4aad012013-02-22 15:05:25 -08004692 void setAttachedWindowFrames(WindowState win, int fl, int adjust, WindowState attached,
4693 boolean insetDecors, Rect pf, Rect df, Rect of, Rect cf, Rect vf) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004694 if (win.getSurfaceLayer() > mDockLayer && attached.getSurfaceLayer() < mDockLayer) {
4695 // Here's a special case: if this attached window is a panel that is
4696 // above the dock window, and the window it is attached to is below
4697 // the dock window, then the frames we computed for the window it is
4698 // attached to can not be used because the dock is effectively part
4699 // of the underlying window and the attached window is floating on top
4700 // of the whole thing. So, we ignore the attached window and explicitly
4701 // compute the frames that would be appropriate without the dock.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08004702 df.left = of.left = cf.left = vf.left = mDockLeft;
4703 df.top = of.top = cf.top = vf.top = mDockTop;
4704 df.right = of.right = cf.right = vf.right = mDockRight;
4705 df.bottom = of.bottom = cf.bottom = vf.bottom = mDockBottom;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004706 } else {
4707 // The effective display frame of the attached window depends on
4708 // whether it is taking care of insetting its content. If not,
4709 // we need to use the parent's content frame so that the entire
4710 // window is positioned within that content. Otherwise we can use
Wale Ogunwale393b1c12014-10-18 16:22:01 -07004711 // the overscan frame and let the attached window take care of
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004712 // positioning its content appropriately.
Dianne Hackborndea3ef72010-10-28 14:24:22 -07004713 if (adjust != SOFT_INPUT_ADJUST_RESIZE) {
Wale Ogunwale393b1c12014-10-18 16:22:01 -07004714 // Set the content frame of the attached window to the parent's decor frame
4715 // (same as content frame when IME isn't present) if specifically requested by
4716 // setting {@link WindowManager.LayoutParams#FLAG_LAYOUT_ATTACHED_IN_DECOR} flag.
4717 // Otherwise, use the overscan frame.
4718 cf.set((fl & FLAG_LAYOUT_ATTACHED_IN_DECOR) != 0
4719 ? attached.getContentFrameLw() : attached.getOverscanFrameLw());
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004720 } else {
4721 // If the window is resizing, then we want to base the content
4722 // frame on our attached content frame to resize... however,
4723 // things can be tricky if the attached window is NOT in resize
4724 // mode, in which case its content frame will be larger.
4725 // Ungh. So to deal with that, make sure the content frame
4726 // we end up using is not covering the IM dock.
4727 cf.set(attached.getContentFrameLw());
Dianne Hackborne30e02f2014-05-27 18:24:45 -07004728 if (attached.isVoiceInteraction()) {
4729 if (cf.left < mVoiceContentLeft) cf.left = mVoiceContentLeft;
4730 if (cf.top < mVoiceContentTop) cf.top = mVoiceContentTop;
4731 if (cf.right > mVoiceContentRight) cf.right = mVoiceContentRight;
4732 if (cf.bottom > mVoiceContentBottom) cf.bottom = mVoiceContentBottom;
4733 } else if (attached.getSurfaceLayer() < mDockLayer) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004734 if (cf.left < mContentLeft) cf.left = mContentLeft;
4735 if (cf.top < mContentTop) cf.top = mContentTop;
4736 if (cf.right > mContentRight) cf.right = mContentRight;
4737 if (cf.bottom > mContentBottom) cf.bottom = mContentBottom;
4738 }
4739 }
4740 df.set(insetDecors ? attached.getDisplayFrameLw() : cf);
Dianne Hackbornc4aad012013-02-22 15:05:25 -08004741 of.set(insetDecors ? attached.getOverscanFrameLw() : cf);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004742 vf.set(attached.getVisibleFrameLw());
4743 }
4744 // The LAYOUT_IN_SCREEN flag is used to determine whether the attached
4745 // window should be positioned relative to its parent or the entire
4746 // screen.
4747 pf.set((fl & FLAG_LAYOUT_IN_SCREEN) == 0
4748 ? attached.getFrameLw() : df);
4749 }
Dianne Hackborn5b5cc4d2012-05-16 13:15:00 -07004750
4751 private void applyStableConstraints(int sysui, int fl, Rect r) {
4752 if ((sysui & View.SYSTEM_UI_FLAG_LAYOUT_STABLE) != 0) {
4753 // If app is requesting a stable layout, don't let the
4754 // content insets go below the stable values.
4755 if ((fl & FLAG_FULLSCREEN) != 0) {
4756 if (r.left < mStableFullscreenLeft) r.left = mStableFullscreenLeft;
4757 if (r.top < mStableFullscreenTop) r.top = mStableFullscreenTop;
4758 if (r.right > mStableFullscreenRight) r.right = mStableFullscreenRight;
4759 if (r.bottom > mStableFullscreenBottom) r.bottom = mStableFullscreenBottom;
4760 } else {
4761 if (r.left < mStableLeft) r.left = mStableLeft;
4762 if (r.top < mStableTop) r.top = mStableTop;
4763 if (r.right > mStableRight) r.right = mStableRight;
4764 if (r.bottom > mStableBottom) r.bottom = mStableBottom;
4765 }
4766 }
4767 }
4768
Jorim Jaggiaa806142015-05-20 18:04:16 -07004769 private boolean canReceiveInput(WindowState win) {
4770 boolean notFocusable =
4771 (win.getAttrs().flags & WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE) != 0;
4772 boolean altFocusableIm =
4773 (win.getAttrs().flags & WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM) != 0;
4774 boolean notFocusableForIm = notFocusable ^ altFocusableIm;
4775 return !notFocusableForIm;
4776 }
4777
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004778 /** {@inheritDoc} */
Craig Mautner69b08182012-09-05 13:07:13 -07004779 @Override
Craig Mautnerc9457fa2014-06-06 14:27:48 -07004780 public void layoutWindowLw(WindowState win, WindowState attached) {
Jorim Jaggiaa806142015-05-20 18:04:16 -07004781 // We've already done the navigation bar and status bar. If the status bar can receive
4782 // input, we need to layout it again to accomodate for the IME window.
4783 if ((win == mStatusBar && !canReceiveInput(win)) || win == mNavigationBar) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004784 return;
4785 }
Jorim Jaggiaa806142015-05-20 18:04:16 -07004786 final WindowManager.LayoutParams attrs = win.getAttrs();
Craig Mautner69b08182012-09-05 13:07:13 -07004787 final boolean isDefaultDisplay = win.isDefaultDisplay();
4788 final boolean needsToOffsetInputMethodTarget = isDefaultDisplay &&
satok1bc0a492012-04-25 22:47:12 +09004789 (win == mLastInputMethodTargetWindow && mLastInputMethodWindow != null);
4790 if (needsToOffsetInputMethodTarget) {
Craig Mautnereda67292013-04-28 13:50:14 -07004791 if (DEBUG_LAYOUT) Slog.i(TAG, "Offset ime target window by the last ime window state");
satok1bc0a492012-04-25 22:47:12 +09004792 offsetInputMethodWindowLw(mLastInputMethodWindow);
4793 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004794
John Spurlockc6d1c602014-01-17 15:22:06 -05004795 final int fl = PolicyControl.getWindowFlags(win, attrs);
Jorim Jaggi8f5701b2016-04-04 18:36:02 -07004796 final int pfl = attrs.privateFlags;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004797 final int sim = attrs.softInputMode;
John Spurlock1db8b682014-02-18 11:18:59 -05004798 final int sysUiFl = PolicyControl.getSystemUiVisibility(win, null);
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07004799
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004800 final Rect pf = mTmpParentFrame;
4801 final Rect df = mTmpDisplayFrame;
Dianne Hackbornc4aad012013-02-22 15:05:25 -08004802 final Rect of = mTmpOverscanFrame;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004803 final Rect cf = mTmpContentFrame;
4804 final Rect vf = mTmpVisibleFrame;
John Spurlock46646232013-09-30 22:32:42 -04004805 final Rect dcf = mTmpDecorFrame;
Adrian Roosfa104232014-06-20 16:10:14 -07004806 final Rect sf = mTmpStableFrame;
Filip Gruszczynski2217f612015-05-26 11:32:08 -07004807 Rect osf = null;
John Spurlock46646232013-09-30 22:32:42 -04004808 dcf.setEmpty();
Craig Mautner69b08182012-09-05 13:07:13 -07004809
4810 final boolean hasNavBar = (isDefaultDisplay && mHasNavigationBar
Daniel Sandler36412a72011-08-04 09:35:13 -04004811 && mNavigationBar != null && mNavigationBar.isVisibleLw());
Daniel Sandler8956dbb2011-04-22 07:55:02 -04004812
Craig Mautnerf683b562012-10-02 11:10:57 -07004813 final int adjust = sim & SOFT_INPUT_MASK_ADJUST;
4814
Adrian Roosfa104232014-06-20 16:10:14 -07004815 if (isDefaultDisplay) {
4816 sf.set(mStableLeft, mStableTop, mStableRight, mStableBottom);
4817 } else {
4818 sf.set(mOverscanLeft, mOverscanTop, mOverscanRight, mOverscanBottom);
4819 }
4820
Craig Mautner69b08182012-09-05 13:07:13 -07004821 if (!isDefaultDisplay) {
4822 if (attached != null) {
4823 // If this window is attached to another, our display
4824 // frame is the same as the one we are attached to.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08004825 setAttachedWindowFrames(win, fl, adjust, attached, true, pf, df, of, cf, vf);
Craig Mautner69b08182012-09-05 13:07:13 -07004826 } else {
4827 // Give the window full screen.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08004828 pf.left = df.left = of.left = cf.left = mOverscanScreenLeft;
4829 pf.top = df.top = of.top = cf.top = mOverscanScreenTop;
4830 pf.right = df.right = of.right = cf.right
Dianne Hackbornc652de82013-02-15 16:32:56 -08004831 = mOverscanScreenLeft + mOverscanScreenWidth;
Dianne Hackbornc4aad012013-02-22 15:05:25 -08004832 pf.bottom = df.bottom = of.bottom = cf.bottom
Dianne Hackbornc652de82013-02-15 16:32:56 -08004833 = mOverscanScreenTop + mOverscanScreenHeight;
Craig Mautner69b08182012-09-05 13:07:13 -07004834 }
Jorim Jaggi225d3b52015-04-01 11:18:57 -07004835 } else if (attrs.type == TYPE_INPUT_METHOD) {
Dianne Hackbornc4aad012013-02-22 15:05:25 -08004836 pf.left = df.left = of.left = cf.left = vf.left = mDockLeft;
4837 pf.top = df.top = of.top = cf.top = vf.top = mDockTop;
4838 pf.right = df.right = of.right = cf.right = vf.right = mDockRight;
John Spurlockc68d5772013-10-08 11:47:58 -04004839 // IM dock windows layout below the nav bar...
John Spurlock57beb3b2013-10-10 10:27:44 -04004840 pf.bottom = df.bottom = of.bottom = mUnrestrictedScreenTop + mUnrestrictedScreenHeight;
John Spurlockc68d5772013-10-08 11:47:58 -04004841 // ...with content insets above the nav bar
4842 cf.bottom = vf.bottom = mStableBottom;
Adrian Roosdd654ea2016-05-27 11:46:10 -07004843 if (mStatusBar != null && mFocusedWindow == mStatusBar && canReceiveInput(mStatusBar)) {
4844 // The status bar forces the navigation bar while it's visible. Make sure the IME
4845 // avoids the navigation bar in that case.
Adrian Roos85d202b2016-06-02 16:27:47 -07004846 if (mNavigationBarPosition == NAV_BAR_RIGHT) {
4847 pf.right = df.right = of.right = cf.right = vf.right = mStableRight;
4848 } else if (mNavigationBarPosition == NAV_BAR_LEFT) {
4849 pf.left = df.left = of.left = cf.left = vf.left = mStableLeft;
4850 }
Adrian Roosdd654ea2016-05-27 11:46:10 -07004851 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004852 // IM dock windows always go to the bottom of the screen.
4853 attrs.gravity = Gravity.BOTTOM;
4854 mDockLayer = win.getSurfaceLayer();
Jorim Jaggi225d3b52015-04-01 11:18:57 -07004855 } else if (attrs.type == TYPE_VOICE_INTERACTION) {
Stefan Kuhne2f280d062015-06-18 07:20:33 -10004856 pf.left = df.left = of.left = mUnrestrictedScreenLeft;
Jorim Jaggi225d3b52015-04-01 11:18:57 -07004857 pf.top = df.top = of.top = mUnrestrictedScreenTop;
Stefan Kuhne2f280d062015-06-18 07:20:33 -10004858 pf.right = df.right = of.right = mUnrestrictedScreenLeft + mUnrestrictedScreenWidth;
4859 pf.bottom = df.bottom = of.bottom = mUnrestrictedScreenTop + mUnrestrictedScreenHeight;
Jorim Jaggi4b74f4d2016-04-27 18:44:08 -07004860 if (adjust != SOFT_INPUT_ADJUST_RESIZE) {
4861 cf.left = mDockLeft;
4862 cf.top = mDockTop;
4863 cf.right = mDockRight;
4864 cf.bottom = mDockBottom;
4865 } else {
4866 cf.left = mContentLeft;
4867 cf.top = mContentTop;
4868 cf.right = mContentRight;
4869 cf.bottom = mContentBottom;
4870 }
4871 if (adjust != SOFT_INPUT_ADJUST_NOTHING) {
4872 vf.left = mCurLeft;
4873 vf.top = mCurTop;
4874 vf.right = mCurRight;
4875 vf.bottom = mCurBottom;
4876 } else {
4877 vf.set(cf);
4878 }
Jorim Jaggi526505d2016-05-24 00:29:19 -07004879 } else if (attrs.type == TYPE_WALLPAPER) {
4880 layoutWallpaper(win, pf, df, of, cf);
Jorim Jaggiaa806142015-05-20 18:04:16 -07004881 } else if (win == mStatusBar) {
Jorim Jaggie0700182014-08-21 01:12:37 +02004882 pf.left = df.left = of.left = mUnrestrictedScreenLeft;
4883 pf.top = df.top = of.top = mUnrestrictedScreenTop;
4884 pf.right = df.right = of.right = mUnrestrictedScreenWidth + mUnrestrictedScreenLeft;
4885 pf.bottom = df.bottom = of.bottom = mUnrestrictedScreenHeight + mUnrestrictedScreenTop;
4886 cf.left = vf.left = mStableLeft;
4887 cf.top = vf.top = mStableTop;
4888 cf.right = vf.right = mStableRight;
4889 vf.bottom = mStableBottom;
Adrian Roosdc5b4532016-01-06 20:49:41 +01004890
4891 if (adjust == SOFT_INPUT_ADJUST_RESIZE) {
4892 cf.bottom = mContentBottom;
4893 } else {
4894 cf.bottom = mDockBottom;
4895 vf.bottom = mContentBottom;
4896 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004897 } else {
John Spurlock46646232013-09-30 22:32:42 -04004898
4899 // Default policy decor for the default display
4900 dcf.left = mSystemLeft;
4901 dcf.top = mSystemTop;
4902 dcf.right = mSystemRight;
4903 dcf.bottom = mSystemBottom;
John Spurlockbd957402013-10-03 11:38:39 -04004904 final boolean inheritTranslucentDecor = (attrs.privateFlags
4905 & WindowManager.LayoutParams.PRIVATE_FLAG_INHERIT_TRANSLUCENT_DECOR) != 0;
John Spurlock65567d42013-10-08 10:08:32 -04004906 final boolean isAppWindow =
4907 attrs.type >= WindowManager.LayoutParams.FIRST_APPLICATION_WINDOW &&
4908 attrs.type <= WindowManager.LayoutParams.LAST_APPLICATION_WINDOW;
4909 final boolean topAtRest =
4910 win == mTopFullscreenOpaqueWindowState && !win.isAnimatingLw();
4911 if (isAppWindow && !inheritTranslucentDecor && !topAtRest) {
John Spurlockbd957402013-10-03 11:38:39 -04004912 if ((sysUiFl & View.SYSTEM_UI_FLAG_FULLSCREEN) == 0
4913 && (fl & WindowManager.LayoutParams.FLAG_FULLSCREEN) == 0
Adrian Roosea562512014-05-05 13:33:03 +02004914 && (fl & WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS) == 0
4915 && (fl & WindowManager.LayoutParams.
Jorim Jaggi4fa78922015-11-30 17:13:56 -08004916 FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS) == 0
Jorim Jaggi8f5701b2016-04-04 18:36:02 -07004917 && (pfl & PRIVATE_FLAG_FORCE_DRAW_STATUS_BAR_BACKGROUND) == 0) {
John Spurlock46646232013-09-30 22:32:42 -04004918 // Ensure policy decor includes status bar
4919 dcf.top = mStableTop;
4920 }
John Spurlockbd957402013-10-03 11:38:39 -04004921 if ((fl & WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION) == 0
Adrian Roosea562512014-05-05 13:33:03 +02004922 && (sysUiFl & View.SYSTEM_UI_FLAG_HIDE_NAVIGATION) == 0
4923 && (fl & WindowManager.LayoutParams.
4924 FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS) == 0) {
John Spurlock46646232013-09-30 22:32:42 -04004925 // Ensure policy decor includes navigation bar
4926 dcf.bottom = mStableBottom;
4927 dcf.right = mStableRight;
4928 }
4929 }
4930
Dianne Hackbornc4aad012013-02-22 15:05:25 -08004931 if ((fl & (FLAG_LAYOUT_IN_SCREEN | FLAG_LAYOUT_INSET_DECOR))
4932 == (FLAG_LAYOUT_IN_SCREEN | FLAG_LAYOUT_INSET_DECOR)) {
RoboErik8a2cfc32014-05-16 11:19:38 -07004933 if (DEBUG_LAYOUT) Slog.v(TAG, "layoutWindowLw(" + attrs.getTitle()
Dianne Hackbornc4aad012013-02-22 15:05:25 -08004934 + "): IN_SCREEN, INSET_DECOR");
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004935 // This is the case for a normal activity window: we want it
4936 // to cover all of the screen space, and it can take care of
4937 // moving its contents to account for screen decorations that
4938 // intrude into that space.
4939 if (attached != null) {
4940 // If this window is attached to another, our display
4941 // frame is the same as the one we are attached to.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08004942 setAttachedWindowFrames(win, fl, adjust, attached, true, pf, df, of, cf, vf);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004943 } else {
Daniel Sandler8956dbb2011-04-22 07:55:02 -04004944 if (attrs.type == TYPE_STATUS_BAR_PANEL
4945 || attrs.type == TYPE_STATUS_BAR_SUB_PANEL) {
Joe Onorato29fc2c92010-11-24 10:26:50 -08004946 // Status bar panels are the only windows who can go on top of
4947 // the status bar. They are protected by the STATUS_BAR_SERVICE
4948 // permission, so they have the same privileges as the status
4949 // bar itself.
Daniel Sandler8956dbb2011-04-22 07:55:02 -04004950 //
Daniel Sandler8e8b4152011-07-21 01:16:43 -04004951 // However, they should still dodge the navigation bar if it exists.
Daniel Sandler8956dbb2011-04-22 07:55:02 -04004952
Dianne Hackbornc4aad012013-02-22 15:05:25 -08004953 pf.left = df.left = of.left = hasNavBar
4954 ? mDockLeft : mUnrestrictedScreenLeft;
4955 pf.top = df.top = of.top = mUnrestrictedScreenTop;
4956 pf.right = df.right = of.right = hasNavBar
4957 ? mRestrictedScreenLeft+mRestrictedScreenWidth
4958 : mUnrestrictedScreenLeft + mUnrestrictedScreenWidth;
4959 pf.bottom = df.bottom = of.bottom = hasNavBar
4960 ? mRestrictedScreenTop+mRestrictedScreenHeight
4961 : mUnrestrictedScreenTop + mUnrestrictedScreenHeight;
Daniel Sandler8956dbb2011-04-22 07:55:02 -04004962
Craig Mautnereda67292013-04-28 13:50:14 -07004963 if (DEBUG_LAYOUT) Slog.v(TAG, String.format(
Daniel Sandler8e8b4152011-07-21 01:16:43 -04004964 "Laying out status bar window: (%d,%d - %d,%d)",
4965 pf.left, pf.top, pf.right, pf.bottom));
John Spurlock46646232013-09-30 22:32:42 -04004966 } else if ((fl & FLAG_LAYOUT_IN_OVERSCAN) != 0
Dianne Hackbornc652de82013-02-15 16:32:56 -08004967 && attrs.type >= WindowManager.LayoutParams.FIRST_APPLICATION_WINDOW
4968 && attrs.type <= WindowManager.LayoutParams.LAST_SUB_WINDOW) {
4969 // Asking to layout into the overscan region, so give it that pure
4970 // unrestricted area.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08004971 pf.left = df.left = of.left = mOverscanScreenLeft;
4972 pf.top = df.top = of.top = mOverscanScreenTop;
4973 pf.right = df.right = of.right = mOverscanScreenLeft + mOverscanScreenWidth;
4974 pf.bottom = df.bottom = of.bottom = mOverscanScreenTop
4975 + mOverscanScreenHeight;
Alan Viverette5a0f4ec2013-10-07 15:10:29 -07004976 } else if (canHideNavigationBar()
Dianne Hackbornf87d1962012-04-04 12:48:24 -07004977 && (sysUiFl & View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION) != 0
Jorim Jaggi380ecb82014-03-14 17:25:20 +01004978 && attrs.type >= WindowManager.LayoutParams.FIRST_APPLICATION_WINDOW
4979 && attrs.type <= WindowManager.LayoutParams.LAST_SUB_WINDOW) {
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07004980 // Asking for layout as if the nav bar is hidden, lets the
Dianne Hackbornc652de82013-02-15 16:32:56 -08004981 // application extend into the unrestricted overscan screen area. We
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07004982 // only do this for application windows to ensure no window that
4983 // can be above the nav bar can do this.
Dianne Hackborn313440842013-02-19 19:22:59 -08004984 pf.left = df.left = mOverscanScreenLeft;
4985 pf.top = df.top = mOverscanScreenTop;
4986 pf.right = df.right = mOverscanScreenLeft + mOverscanScreenWidth;
4987 pf.bottom = df.bottom = mOverscanScreenTop + mOverscanScreenHeight;
Dianne Hackbornc4aad012013-02-22 15:05:25 -08004988 // We need to tell the app about where the frame inside the overscan
4989 // is, so it can inset its content by that amount -- it didn't ask
4990 // to actually extend itself into the overscan region.
4991 of.left = mUnrestrictedScreenLeft;
4992 of.top = mUnrestrictedScreenTop;
4993 of.right = mUnrestrictedScreenLeft + mUnrestrictedScreenWidth;
4994 of.bottom = mUnrestrictedScreenTop + mUnrestrictedScreenHeight;
Joe Onorato29fc2c92010-11-24 10:26:50 -08004995 } else {
Dianne Hackborn313440842013-02-19 19:22:59 -08004996 pf.left = df.left = mRestrictedOverscanScreenLeft;
4997 pf.top = df.top = mRestrictedOverscanScreenTop;
4998 pf.right = df.right = mRestrictedOverscanScreenLeft
4999 + mRestrictedOverscanScreenWidth;
5000 pf.bottom = df.bottom = mRestrictedOverscanScreenTop
5001 + mRestrictedOverscanScreenHeight;
Dianne Hackbornc4aad012013-02-22 15:05:25 -08005002 // We need to tell the app about where the frame inside the overscan
5003 // is, so it can inset its content by that amount -- it didn't ask
5004 // to actually extend itself into the overscan region.
5005 of.left = mUnrestrictedScreenLeft;
5006 of.top = mUnrestrictedScreenTop;
5007 of.right = mUnrestrictedScreenLeft + mUnrestrictedScreenWidth;
5008 of.bottom = mUnrestrictedScreenTop + mUnrestrictedScreenHeight;
Joe Onorato29fc2c92010-11-24 10:26:50 -08005009 }
Craig Mautner69b08182012-09-05 13:07:13 -07005010
John Spurlock46646232013-09-30 22:32:42 -04005011 if ((fl & FLAG_FULLSCREEN) == 0) {
Dianne Hackborne30e02f2014-05-27 18:24:45 -07005012 if (win.isVoiceInteraction()) {
5013 cf.left = mVoiceContentLeft;
5014 cf.top = mVoiceContentTop;
5015 cf.right = mVoiceContentRight;
5016 cf.bottom = mVoiceContentBottom;
Dianne Hackbornc4aad012013-02-22 15:05:25 -08005017 } else {
Dianne Hackborne30e02f2014-05-27 18:24:45 -07005018 if (adjust != SOFT_INPUT_ADJUST_RESIZE) {
5019 cf.left = mDockLeft;
5020 cf.top = mDockTop;
5021 cf.right = mDockRight;
5022 cf.bottom = mDockBottom;
5023 } else {
5024 cf.left = mContentLeft;
5025 cf.top = mContentTop;
5026 cf.right = mContentRight;
5027 cf.bottom = mContentBottom;
5028 }
Dianne Hackbornc4aad012013-02-22 15:05:25 -08005029 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005030 } else {
Dianne Hackbornc4aad012013-02-22 15:05:25 -08005031 // Full screen windows are always given a layout that is as if the
5032 // status bar and other transient decors are gone. This is to avoid
5033 // bad states when moving from a window that is not hding the
5034 // status bar to one that is.
5035 cf.left = mRestrictedScreenLeft;
5036 cf.top = mRestrictedScreenTop;
5037 cf.right = mRestrictedScreenLeft + mRestrictedScreenWidth;
5038 cf.bottom = mRestrictedScreenTop + mRestrictedScreenHeight;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005039 }
Dianne Hackborn5b5cc4d2012-05-16 13:15:00 -07005040 applyStableConstraints(sysUiFl, fl, cf);
Dianne Hackborndea3ef72010-10-28 14:24:22 -07005041 if (adjust != SOFT_INPUT_ADJUST_NOTHING) {
5042 vf.left = mCurLeft;
5043 vf.top = mCurTop;
5044 vf.right = mCurRight;
5045 vf.bottom = mCurBottom;
5046 } else {
5047 vf.set(cf);
5048 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005049 }
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07005050 } else if ((fl & FLAG_LAYOUT_IN_SCREEN) != 0 || (sysUiFl
5051 & (View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
5052 | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION)) != 0) {
Craig Mautnereda67292013-04-28 13:50:14 -07005053 if (DEBUG_LAYOUT) Slog.v(TAG, "layoutWindowLw(" + attrs.getTitle() +
5054 "): IN_SCREEN");
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005055 // A window that has requested to fill the entire screen just
5056 // gets everything, period.
Daniel Sandler8956dbb2011-04-22 07:55:02 -04005057 if (attrs.type == TYPE_STATUS_BAR_PANEL
Lucas Dupinc1cc7592017-05-22 15:56:16 -07005058 || attrs.type == TYPE_STATUS_BAR_SUB_PANEL) {
Dianne Hackbornc4aad012013-02-22 15:05:25 -08005059 pf.left = df.left = of.left = cf.left = hasNavBar
5060 ? mDockLeft : mUnrestrictedScreenLeft;
5061 pf.top = df.top = of.top = cf.top = mUnrestrictedScreenTop;
5062 pf.right = df.right = of.right = cf.right = hasNavBar
Lucas Dupinc1cc7592017-05-22 15:56:16 -07005063 ? mRestrictedScreenLeft + mRestrictedScreenWidth
5064 : mUnrestrictedScreenLeft + mUnrestrictedScreenWidth;
Dianne Hackbornc4aad012013-02-22 15:05:25 -08005065 pf.bottom = df.bottom = of.bottom = cf.bottom = hasNavBar
Lucas Dupinc1cc7592017-05-22 15:56:16 -07005066 ? mRestrictedScreenTop + mRestrictedScreenHeight
5067 : mUnrestrictedScreenTop + mUnrestrictedScreenHeight;
5068 if (DEBUG_LAYOUT) Slog.v(TAG, String.format(
5069 "Laying out IN_SCREEN status bar window: (%d,%d - %d,%d)",
5070 pf.left, pf.top, pf.right, pf.bottom));
5071 } else if (attrs.type == TYPE_VOLUME_OVERLAY) {
5072 // Volume overlay covers everything, including the status and navbar
5073 pf.left = df.left = of.left = cf.left = mUnrestrictedScreenLeft;
5074 pf.top = df.top = of.top = cf.top = mUnrestrictedScreenTop;
5075 pf.right = df.right = of.right = cf.right =
5076 mUnrestrictedScreenLeft + mUnrestrictedScreenWidth;
5077 pf.bottom = df.bottom = of.bottom = cf.bottom =
5078 mUnrestrictedScreenTop + mUnrestrictedScreenHeight;
Craig Mautnereda67292013-04-28 13:50:14 -07005079 if (DEBUG_LAYOUT) Slog.v(TAG, String.format(
Daniel Sandler36412a72011-08-04 09:35:13 -04005080 "Laying out IN_SCREEN status bar window: (%d,%d - %d,%d)",
5081 pf.left, pf.top, pf.right, pf.bottom));
Jim Millere898ac52012-04-06 17:10:57 -07005082 } else if (attrs.type == TYPE_NAVIGATION_BAR
5083 || attrs.type == TYPE_NAVIGATION_BAR_PANEL) {
Daniel Sandler8e8b4152011-07-21 01:16:43 -04005084 // The navigation bar has Real Ultimate Power.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08005085 pf.left = df.left = of.left = mUnrestrictedScreenLeft;
5086 pf.top = df.top = of.top = mUnrestrictedScreenTop;
5087 pf.right = df.right = of.right = mUnrestrictedScreenLeft
5088 + mUnrestrictedScreenWidth;
5089 pf.bottom = df.bottom = of.bottom = mUnrestrictedScreenTop
5090 + mUnrestrictedScreenHeight;
Craig Mautnereda67292013-04-28 13:50:14 -07005091 if (DEBUG_LAYOUT) Slog.v(TAG, String.format(
Daniel Sandler8e8b4152011-07-21 01:16:43 -04005092 "Laying out navigation bar window: (%d,%d - %d,%d)",
5093 pf.left, pf.top, pf.right, pf.bottom));
Dianne Hackborn01011c32012-02-21 13:54:21 -08005094 } else if ((attrs.type == TYPE_SECURE_SYSTEM_OVERLAY
Muyuan Li6ca619f2016-03-08 13:30:42 -08005095 || attrs.type == TYPE_BOOT_PROGRESS
5096 || attrs.type == TYPE_SCREENSHOT)
Jeff Brownbfcb60a2011-09-08 18:51:14 -07005097 && ((fl & FLAG_FULLSCREEN) != 0)) {
Muyuan Li6ca619f2016-03-08 13:30:42 -08005098 // Fullscreen secure system overlays get what they ask for. Screenshot region
5099 // selection overlay should also expand to full screen.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08005100 pf.left = df.left = of.left = cf.left = mOverscanScreenLeft;
5101 pf.top = df.top = of.top = cf.top = mOverscanScreenTop;
5102 pf.right = df.right = of.right = cf.right = mOverscanScreenLeft
5103 + mOverscanScreenWidth;
5104 pf.bottom = df.bottom = of.bottom = cf.bottom = mOverscanScreenTop
5105 + mOverscanScreenHeight;
Craig Mautner165be0c2015-01-27 15:16:58 -08005106 } else if (attrs.type == TYPE_BOOT_PROGRESS) {
Dianne Hackborn01011c32012-02-21 13:54:21 -08005107 // Boot progress screen always covers entire display.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08005108 pf.left = df.left = of.left = cf.left = mOverscanScreenLeft;
5109 pf.top = df.top = of.top = cf.top = mOverscanScreenTop;
5110 pf.right = df.right = of.right = cf.right = mOverscanScreenLeft
5111 + mOverscanScreenWidth;
5112 pf.bottom = df.bottom = of.bottom = cf.bottom = mOverscanScreenTop
5113 + mOverscanScreenHeight;
John Spurlock46646232013-09-30 22:32:42 -04005114 } else if ((fl & FLAG_LAYOUT_IN_OVERSCAN) != 0
Dianne Hackbornc652de82013-02-15 16:32:56 -08005115 && attrs.type >= WindowManager.LayoutParams.FIRST_APPLICATION_WINDOW
5116 && attrs.type <= WindowManager.LayoutParams.LAST_SUB_WINDOW) {
5117 // Asking to layout into the overscan region, so give it that pure
5118 // unrestricted area.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08005119 pf.left = df.left = of.left = cf.left = mOverscanScreenLeft;
5120 pf.top = df.top = of.top = cf.top = mOverscanScreenTop;
5121 pf.right = df.right = of.right = cf.right
Dianne Hackbornc652de82013-02-15 16:32:56 -08005122 = mOverscanScreenLeft + mOverscanScreenWidth;
Dianne Hackbornc4aad012013-02-22 15:05:25 -08005123 pf.bottom = df.bottom = of.bottom = cf.bottom
Dianne Hackbornc652de82013-02-15 16:32:56 -08005124 = mOverscanScreenTop + mOverscanScreenHeight;
Alan Viverette5a0f4ec2013-10-07 15:10:29 -07005125 } else if (canHideNavigationBar()
Dianne Hackbornf87d1962012-04-04 12:48:24 -07005126 && (sysUiFl & View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION) != 0
Craig Mautnerbeac1062014-06-03 14:38:57 -07005127 && (attrs.type == TYPE_STATUS_BAR
5128 || attrs.type == TYPE_TOAST
Jorim Jaggi81fe2d12015-12-21 14:45:18 +01005129 || attrs.type == TYPE_DOCK_DIVIDER
Jorim Jaggi2fdeeab2015-04-01 15:13:03 -07005130 || attrs.type == TYPE_VOICE_INTERACTION_STARTING
John Spurlock34e13d92013-08-10 06:52:28 -04005131 || (attrs.type >= WindowManager.LayoutParams.FIRST_APPLICATION_WINDOW
5132 && attrs.type <= WindowManager.LayoutParams.LAST_SUB_WINDOW))) {
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07005133 // Asking for layout as if the nav bar is hidden, lets the
5134 // application extend into the unrestricted screen area. We
John Spurlock34e13d92013-08-10 06:52:28 -04005135 // only do this for application windows (or toasts) to ensure no window that
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07005136 // can be above the nav bar can do this.
5137 // XXX This assumes that an app asking for this will also
5138 // ask for layout in only content. We can't currently figure out
5139 // what the screen would be if only laying out to hide the nav bar.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08005140 pf.left = df.left = of.left = cf.left = mUnrestrictedScreenLeft;
5141 pf.top = df.top = of.top = cf.top = mUnrestrictedScreenTop;
5142 pf.right = df.right = of.right = cf.right = mUnrestrictedScreenLeft
5143 + mUnrestrictedScreenWidth;
5144 pf.bottom = df.bottom = of.bottom = cf.bottom = mUnrestrictedScreenTop
5145 + mUnrestrictedScreenHeight;
Jorim Jaggi9f6798a2016-02-10 22:16:06 -08005146 } else if ((sysUiFl & View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN) != 0) {
5147 pf.left = df.left = of.left = mRestrictedScreenLeft;
5148 pf.top = df.top = of.top = mRestrictedScreenTop;
5149 pf.right = df.right = of.right = mRestrictedScreenLeft + mRestrictedScreenWidth;
5150 pf.bottom = df.bottom = of.bottom = mRestrictedScreenTop
5151 + mRestrictedScreenHeight;
5152 if (adjust != SOFT_INPUT_ADJUST_RESIZE) {
5153 cf.left = mDockLeft;
5154 cf.top = mDockTop;
5155 cf.right = mDockRight;
5156 cf.bottom = mDockBottom;
5157 } else {
5158 cf.left = mContentLeft;
5159 cf.top = mContentTop;
5160 cf.right = mContentRight;
5161 cf.bottom = mContentBottom;
5162 }
Joe Onorato29fc2c92010-11-24 10:26:50 -08005163 } else {
Dianne Hackbornc4aad012013-02-22 15:05:25 -08005164 pf.left = df.left = of.left = cf.left = mRestrictedScreenLeft;
5165 pf.top = df.top = of.top = cf.top = mRestrictedScreenTop;
5166 pf.right = df.right = of.right = cf.right = mRestrictedScreenLeft
5167 + mRestrictedScreenWidth;
5168 pf.bottom = df.bottom = of.bottom = cf.bottom = mRestrictedScreenTop
5169 + mRestrictedScreenHeight;
Joe Onorato29fc2c92010-11-24 10:26:50 -08005170 }
Craig Mautner69b08182012-09-05 13:07:13 -07005171
Dianne Hackborn5b5cc4d2012-05-16 13:15:00 -07005172 applyStableConstraints(sysUiFl, fl, cf);
Craig Mautner69b08182012-09-05 13:07:13 -07005173
Dianne Hackborndea3ef72010-10-28 14:24:22 -07005174 if (adjust != SOFT_INPUT_ADJUST_NOTHING) {
5175 vf.left = mCurLeft;
5176 vf.top = mCurTop;
5177 vf.right = mCurRight;
5178 vf.bottom = mCurBottom;
5179 } else {
5180 vf.set(cf);
5181 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005182 } else if (attached != null) {
Craig Mautnereda67292013-04-28 13:50:14 -07005183 if (DEBUG_LAYOUT) Slog.v(TAG, "layoutWindowLw(" + attrs.getTitle() +
5184 "): attached to " + attached);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005185 // A child window should be placed inside of the same visible
5186 // frame that its parent had.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08005187 setAttachedWindowFrames(win, fl, adjust, attached, false, pf, df, of, cf, vf);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005188 } else {
Craig Mautnereda67292013-04-28 13:50:14 -07005189 if (DEBUG_LAYOUT) Slog.v(TAG, "layoutWindowLw(" + attrs.getTitle() +
5190 "): normal window");
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005191 // Otherwise, a normal window must be placed inside the content
5192 // of all screen decorations.
John Spurlock67a0f852015-06-15 15:35:47 -04005193 if (attrs.type == TYPE_STATUS_BAR_PANEL || attrs.type == TYPE_VOLUME_OVERLAY) {
5194 // Status bar panels and the volume dialog are the only windows who can go on
5195 // top of the status bar. They are protected by the STATUS_BAR_SERVICE
Dianne Hackborna239c842011-06-01 12:28:20 -07005196 // permission, so they have the same privileges as the status
5197 // bar itself.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08005198 pf.left = df.left = of.left = cf.left = mRestrictedScreenLeft;
5199 pf.top = df.top = of.top = cf.top = mRestrictedScreenTop;
5200 pf.right = df.right = of.right = cf.right = mRestrictedScreenLeft
5201 + mRestrictedScreenWidth;
5202 pf.bottom = df.bottom = of.bottom = cf.bottom = mRestrictedScreenTop
5203 + mRestrictedScreenHeight;
John Spurlock67a0f852015-06-15 15:35:47 -04005204 } else if (attrs.type == TYPE_TOAST || attrs.type == TYPE_SYSTEM_ALERT) {
John Spurlock414c1f02013-12-04 13:47:36 -05005205 // These dialogs are stable to interim decor changes.
John Spurlockbd957402013-10-03 11:38:39 -04005206 pf.left = df.left = of.left = cf.left = mStableLeft;
5207 pf.top = df.top = of.top = cf.top = mStableTop;
5208 pf.right = df.right = of.right = cf.right = mStableRight;
5209 pf.bottom = df.bottom = of.bottom = cf.bottom = mStableBottom;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005210 } else {
Dianne Hackborna239c842011-06-01 12:28:20 -07005211 pf.left = mContentLeft;
5212 pf.top = mContentTop;
5213 pf.right = mContentRight;
5214 pf.bottom = mContentBottom;
Dianne Hackborn20d94742014-05-29 18:35:45 -07005215 if (win.isVoiceInteraction()) {
5216 df.left = of.left = cf.left = mVoiceContentLeft;
5217 df.top = of.top = cf.top = mVoiceContentTop;
5218 df.right = of.right = cf.right = mVoiceContentRight;
5219 df.bottom = of.bottom = cf.bottom = mVoiceContentBottom;
5220 } else if (adjust != SOFT_INPUT_ADJUST_RESIZE) {
Dianne Hackbornc4aad012013-02-22 15:05:25 -08005221 df.left = of.left = cf.left = mDockLeft;
5222 df.top = of.top = cf.top = mDockTop;
5223 df.right = of.right = cf.right = mDockRight;
5224 df.bottom = of.bottom = cf.bottom = mDockBottom;
Dianne Hackborna239c842011-06-01 12:28:20 -07005225 } else {
Dianne Hackbornc4aad012013-02-22 15:05:25 -08005226 df.left = of.left = cf.left = mContentLeft;
5227 df.top = of.top = cf.top = mContentTop;
5228 df.right = of.right = cf.right = mContentRight;
5229 df.bottom = of.bottom = cf.bottom = mContentBottom;
Dianne Hackborna239c842011-06-01 12:28:20 -07005230 }
5231 if (adjust != SOFT_INPUT_ADJUST_NOTHING) {
5232 vf.left = mCurLeft;
5233 vf.top = mCurTop;
5234 vf.right = mCurRight;
5235 vf.bottom = mCurBottom;
5236 } else {
5237 vf.set(cf);
5238 }
Dianne Hackborndea3ef72010-10-28 14:24:22 -07005239 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005240 }
5241 }
Craig Mautner69b08182012-09-05 13:07:13 -07005242
Craig Mautnerb816bed2013-07-23 10:26:17 -07005243 // TYPE_SYSTEM_ERROR is above the NavigationBar so it can't be allowed to extend over it.
Wale Ogunwale9185fb02016-03-11 18:06:14 -08005244 // Also, we don't allow windows in multi-window mode to extend out of the screen.
5245 if ((fl & FLAG_LAYOUT_NO_LIMITS) != 0 && attrs.type != TYPE_SYSTEM_ERROR
Andrii Kulian933076d2016-03-29 17:04:42 -07005246 && !win.isInMultiWindowMode()) {
Dianne Hackborn067e5f62014-09-07 23:14:30 -07005247 df.left = df.top = -10000;
5248 df.right = df.bottom = 10000;
5249 if (attrs.type != TYPE_WALLPAPER) {
5250 of.left = of.top = cf.left = cf.top = vf.left = vf.top = -10000;
5251 of.right = of.bottom = cf.right = cf.bottom = vf.right = vf.bottom = 10000;
5252 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005253 }
5254
Filip Gruszczynski2217f612015-05-26 11:32:08 -07005255 // If the device has a chin (e.g. some watches), a dead area at the bottom of the screen we
5256 // need to provide information to the clients that want to pretend that you can draw there.
Filip Gruszczynskib0c673b2015-06-05 09:43:06 -07005257 // We only want to apply outsets to certain types of windows. For example, we never want to
5258 // apply the outsets to floating dialogs, because they wouldn't make sense there.
Filip Gruszczynski2987f612015-06-30 15:03:30 -07005259 final boolean useOutsets = shouldUseOutsets(attrs, fl);
Filip Gruszczynskib0c673b2015-06-05 09:43:06 -07005260 if (isDefaultDisplay && useOutsets) {
Filip Gruszczynski2217f612015-05-26 11:32:08 -07005261 osf = mTmpOutsetFrame;
5262 osf.set(cf.left, cf.top, cf.right, cf.bottom);
5263 int outset = ScreenShapeHelper.getWindowOutsetBottomPx(mContext.getResources());
5264 if (outset > 0) {
Filip Gruszczynski2987f612015-06-30 15:03:30 -07005265 int rotation = mDisplayRotation;
Filip Gruszczynski2217f612015-05-26 11:32:08 -07005266 if (rotation == Surface.ROTATION_0) {
5267 osf.bottom += outset;
5268 } else if (rotation == Surface.ROTATION_90) {
5269 osf.right += outset;
5270 } else if (rotation == Surface.ROTATION_180) {
5271 osf.top -= outset;
5272 } else if (rotation == Surface.ROTATION_270) {
5273 osf.left -= outset;
5274 }
5275 if (DEBUG_LAYOUT) Slog.v(TAG, "applying bottom outset of " + outset
5276 + " with rotation " + rotation + ", result: " + osf);
5277 }
5278 }
5279
Craig Mautnereda67292013-04-28 13:50:14 -07005280 if (DEBUG_LAYOUT) Slog.v(TAG, "Compute frame " + attrs.getTitle()
The Android Open Source Project11267662009-03-18 17:39:47 -07005281 + ": sim=#" + Integer.toHexString(sim)
RoboErik8a2cfc32014-05-16 11:19:38 -07005282 + " attach=" + attached + " type=" + attrs.type
Daniel Sandler8956dbb2011-04-22 07:55:02 -04005283 + String.format(" flags=0x%08x", fl)
The Android Open Source Project11267662009-03-18 17:39:47 -07005284 + " pf=" + pf.toShortString() + " df=" + df.toShortString()
Dianne Hackbornc4aad012013-02-22 15:05:25 -08005285 + " of=" + of.toShortString()
John Spurlock46646232013-09-30 22:32:42 -04005286 + " cf=" + cf.toShortString() + " vf=" + vf.toShortString()
Adrian Roosfa104232014-06-20 16:10:14 -07005287 + " dcf=" + dcf.toShortString()
Filip Gruszczynski2217f612015-05-26 11:32:08 -07005288 + " sf=" + sf.toShortString()
5289 + " osf=" + (osf == null ? "null" : osf.toShortString()));
Craig Mautner69b08182012-09-05 13:07:13 -07005290
Filip Gruszczynski2217f612015-05-26 11:32:08 -07005291 win.computeFrameLw(pf, df, of, cf, vf, dcf, sf, osf);
Craig Mautner69b08182012-09-05 13:07:13 -07005292
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005293 // Dock windows carve out the bottom of the screen, so normal windows
5294 // can't appear underneath them.
Jorim Jaggib0d27342016-11-01 16:10:42 -07005295 if (attrs.type == TYPE_INPUT_METHOD && win.isVisibleLw()
5296 && !win.getGivenInsetsPendingLw()) {
satok1bc0a492012-04-25 22:47:12 +09005297 setLastInputMethodWindowLw(null, null);
5298 offsetInputMethodWindowLw(win);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005299 }
Jorim Jaggib0d27342016-11-01 16:10:42 -07005300 if (attrs.type == TYPE_VOICE_INTERACTION && win.isVisibleLw()
Dianne Hackborne30e02f2014-05-27 18:24:45 -07005301 && !win.getGivenInsetsPendingLw()) {
5302 offsetVoiceInputWindowLw(win);
5303 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005304 }
5305
Jorim Jaggi526505d2016-05-24 00:29:19 -07005306 private void layoutWallpaper(WindowState win, Rect pf, Rect df, Rect of, Rect cf) {
5307
5308 // The wallpaper also has Real Ultimate Power, but we want to tell
5309 // it about the overscan area.
5310 pf.left = df.left = mOverscanScreenLeft;
5311 pf.top = df.top = mOverscanScreenTop;
5312 pf.right = df.right = mOverscanScreenLeft + mOverscanScreenWidth;
5313 pf.bottom = df.bottom = mOverscanScreenTop + mOverscanScreenHeight;
5314 of.left = cf.left = mUnrestrictedScreenLeft;
5315 of.top = cf.top = mUnrestrictedScreenTop;
5316 of.right = cf.right = mUnrestrictedScreenLeft + mUnrestrictedScreenWidth;
5317 of.bottom = cf.bottom = mUnrestrictedScreenTop + mUnrestrictedScreenHeight;
5318 }
5319
satok1bc0a492012-04-25 22:47:12 +09005320 private void offsetInputMethodWindowLw(WindowState win) {
Craig Mautner4774f6a2015-03-23 11:42:55 -07005321 int top = Math.max(win.getDisplayFrameLw().top, win.getContentFrameLw().top);
satok1bc0a492012-04-25 22:47:12 +09005322 top += win.getGivenContentInsetsLw().top;
5323 if (mContentBottom > top) {
5324 mContentBottom = top;
5325 }
Dianne Hackborne30e02f2014-05-27 18:24:45 -07005326 if (mVoiceContentBottom > top) {
5327 mVoiceContentBottom = top;
5328 }
satok1bc0a492012-04-25 22:47:12 +09005329 top = win.getVisibleFrameLw().top;
5330 top += win.getGivenVisibleInsetsLw().top;
5331 if (mCurBottom > top) {
5332 mCurBottom = top;
5333 }
Craig Mautnereda67292013-04-28 13:50:14 -07005334 if (DEBUG_LAYOUT) Slog.v(TAG, "Input method: mDockBottom="
satok1bc0a492012-04-25 22:47:12 +09005335 + mDockBottom + " mContentBottom="
5336 + mContentBottom + " mCurBottom=" + mCurBottom);
5337 }
5338
Dianne Hackborne30e02f2014-05-27 18:24:45 -07005339 private void offsetVoiceInputWindowLw(WindowState win) {
Craig Mautner4774f6a2015-03-23 11:42:55 -07005340 int top = Math.max(win.getDisplayFrameLw().top, win.getContentFrameLw().top);
Dianne Hackbornae6688b2015-02-11 17:02:41 -08005341 top += win.getGivenContentInsetsLw().top;
5342 if (mVoiceContentBottom > top) {
5343 mVoiceContentBottom = top;
Dianne Hackborne30e02f2014-05-27 18:24:45 -07005344 }
5345 }
5346
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005347 /** {@inheritDoc} */
Craig Mautner61ac6bb2012-02-02 17:29:33 -08005348 @Override
5349 public void finishLayoutLw() {
5350 return;
Dianne Hackborn5f3063e2010-03-10 16:01:58 -08005351 }
5352
5353 /** {@inheritDoc} */
Craig Mautnerad09bcc2012-10-08 13:33:11 -07005354 @Override
Craig Mautner39834192012-09-02 07:47:24 -07005355 public void beginPostLayoutPolicyLw(int displayWidth, int displayHeight) {
Dianne Hackborn5f3063e2010-03-10 16:01:58 -08005356 mTopFullscreenOpaqueWindowState = null;
Adrian Rooscd3884d2015-02-18 17:25:23 +01005357 mTopFullscreenOpaqueOrDimmingWindowState = null;
Jorim Jaggi86905582016-02-09 21:36:09 -08005358 mTopDockedOpaqueWindowState = null;
5359 mTopDockedOpaqueOrDimmingWindowState = null;
Dianne Hackborn5f3063e2010-03-10 16:01:58 -08005360 mForceStatusBar = false;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07005361 mForceStatusBarFromKeyguard = false;
Selim Cinek4a4a2bddc2015-05-07 12:50:19 -07005362 mForceStatusBarTransparent = false;
Dianne Hackborn891d3fb2013-01-09 18:31:37 -08005363 mForcingShowNavBar = false;
5364 mForcingShowNavBarLayer = -1;
RoboErik8a2cfc32014-05-16 11:19:38 -07005365
Dianne Hackborn5f3063e2010-03-10 16:01:58 -08005366 mAllowLockscreenWhenOn = false;
Dianne Hackborn7ad44382012-10-18 17:46:00 -07005367 mShowingDream = false;
Dianne Hackborn5f3063e2010-03-10 16:01:58 -08005368 }
5369
5370 /** {@inheritDoc} */
Craig Mautnerad09bcc2012-10-08 13:33:11 -07005371 @Override
Yohei Yukawad1a09222015-06-30 16:22:05 -07005372 public void applyPostLayoutPolicyLw(WindowState win, WindowManager.LayoutParams attrs,
Jorim Jaggife762342016-10-13 14:33:27 +02005373 WindowState attached, WindowState imeTarget) {
Jorim Jaggi23cc9aa2017-05-23 16:05:35 +02005374 final boolean affectsSystemUi = win.canAffectSystemUiFlags();
5375 if (DEBUG_LAYOUT) Slog.i(TAG, "Win " + win + ": affectsSystemUi=" + affectsSystemUi);
Jorim Jaggife762342016-10-13 14:33:27 +02005376 applyKeyguardPolicyLw(win, imeTarget);
John Spurlockc6d1c602014-01-17 15:22:06 -05005377 final int fl = PolicyControl.getWindowFlags(win, attrs);
Jorim Jaggi23cc9aa2017-05-23 16:05:35 +02005378 if (mTopFullscreenOpaqueWindowState == null && affectsSystemUi
5379 && attrs.type == TYPE_INPUT_METHOD) {
John Spurlock414c1f02013-12-04 13:47:36 -05005380 mForcingShowNavBar = true;
5381 mForcingShowNavBarLayer = win.getSurfaceLayer();
Dianne Hackborn891d3fb2013-01-09 18:31:37 -08005382 }
Selim Cinek4a4a2bddc2015-05-07 12:50:19 -07005383 if (attrs.type == TYPE_STATUS_BAR) {
5384 if ((attrs.privateFlags & PRIVATE_FLAG_KEYGUARD) != 0) {
5385 mForceStatusBarFromKeyguard = true;
5386 }
5387 if ((attrs.privateFlags & PRIVATE_FLAG_FORCE_STATUS_BAR_VISIBLE_TRANSPARENT) != 0) {
5388 mForceStatusBarTransparent = true;
5389 }
Jorim Jaggiafd4a552014-04-08 15:13:05 +02005390 }
Adrian Roos602c68e2015-04-24 16:03:47 -07005391
5392 boolean appWindow = attrs.type >= FIRST_APPLICATION_WINDOW
Jorim Jaggi30d64f32017-04-07 16:33:17 +02005393 && attrs.type < FIRST_SYSTEM_WINDOW;
Jorim Jaggi86905582016-02-09 21:36:09 -08005394 final int stackId = win.getStackId();
Jorim Jaggi23cc9aa2017-05-23 16:05:35 +02005395 if (mTopFullscreenOpaqueWindowState == null && affectsSystemUi) {
John Spurlockc6d1c602014-01-17 15:22:06 -05005396 if ((fl & FLAG_FORCE_NOT_FULLSCREEN) != 0) {
Jorim Jaggife762342016-10-13 14:33:27 +02005397 mForceStatusBar = true;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07005398 }
Dianne Hackborn7ad44382012-10-18 17:46:00 -07005399 if (attrs.type == TYPE_DREAM) {
Jeff Brownc8018eb2012-10-29 21:33:27 -07005400 // If the lockscreen was showing when the dream started then wait
5401 // for the dream to draw before hiding the lockscreen.
5402 if (!mDreamingLockscreen
5403 || (win.isVisibleLw() && win.hasDrawnLw())) {
5404 mShowingDream = true;
Craig Mautnerab55e522014-03-03 13:26:03 -08005405 appWindow = true;
Dianne Hackborn7ad44382012-10-18 17:46:00 -07005406 }
5407 }
Craig Mautnerab55e522014-03-03 13:26:03 -08005408
Yohei Yukawad1a09222015-06-30 16:22:05 -07005409 // For app windows that are not attached, we decide if all windows in the app they
5410 // represent should be hidden or if we should hide the lockscreen. For attached app
5411 // windows we defer the decision to the window it is attached to.
5412 if (appWindow && attached == null) {
Jorim Jaggie6c6ecb2017-07-20 18:09:20 +02005413 if (attrs.isFullscreen() && StackId.normallyFullscreenWindows(stackId)) {
Craig Mautnerab55e522014-03-03 13:26:03 -08005414 if (DEBUG_LAYOUT) Slog.v(TAG, "Fullscreen window: " + win);
5415 mTopFullscreenOpaqueWindowState = win;
Adrian Rooscd3884d2015-02-18 17:25:23 +01005416 if (mTopFullscreenOpaqueOrDimmingWindowState == null) {
5417 mTopFullscreenOpaqueOrDimmingWindowState = win;
5418 }
Craig Mautner00156ec2014-03-06 22:29:02 -08005419 if ((fl & FLAG_ALLOW_LOCK_WHILE_SCREEN_ON) != 0) {
Craig Mautnerab55e522014-03-03 13:26:03 -08005420 mAllowLockscreenWhenOn = true;
5421 }
Dianne Hackborn5f3063e2010-03-10 16:01:58 -08005422 }
Adrian Roos602c68e2015-04-24 16:03:47 -07005423 }
Dianne Hackborn5f3063e2010-03-10 16:01:58 -08005424 }
Jorim Jaggi86905582016-02-09 21:36:09 -08005425
Jorim Jaggi90859bc2016-06-28 16:25:23 -07005426 // Voice interaction overrides both top fullscreen and top docked.
Jorim Jaggi23cc9aa2017-05-23 16:05:35 +02005427 if (affectsSystemUi && win.getAttrs().type == TYPE_VOICE_INTERACTION) {
Jorim Jaggi90859bc2016-06-28 16:25:23 -07005428 if (mTopFullscreenOpaqueWindowState == null) {
5429 mTopFullscreenOpaqueWindowState = win;
5430 if (mTopFullscreenOpaqueOrDimmingWindowState == null) {
5431 mTopFullscreenOpaqueOrDimmingWindowState = win;
5432 }
5433 }
5434 if (mTopDockedOpaqueWindowState == null) {
5435 mTopDockedOpaqueWindowState = win;
5436 if (mTopDockedOpaqueOrDimmingWindowState == null) {
5437 mTopDockedOpaqueOrDimmingWindowState = win;
5438 }
5439 }
5440 }
5441
5442 // Keep track of the window if it's dimming but not necessarily fullscreen.
Jorim Jaggi23cc9aa2017-05-23 16:05:35 +02005443 if (mTopFullscreenOpaqueOrDimmingWindowState == null && affectsSystemUi
Jorim Jaggi86905582016-02-09 21:36:09 -08005444 && win.isDimming() && StackId.normallyFullscreenWindows(stackId)) {
Adrian Rooscd3884d2015-02-18 17:25:23 +01005445 mTopFullscreenOpaqueOrDimmingWindowState = win;
5446 }
Jorim Jaggi86905582016-02-09 21:36:09 -08005447
5448 // We need to keep track of the top "fullscreen" opaque window for the docked stack
5449 // separately, because both the "real fullscreen" opaque window and the one for the docked
5450 // stack can control View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR.
Jorim Jaggi23cc9aa2017-05-23 16:05:35 +02005451 if (mTopDockedOpaqueWindowState == null && affectsSystemUi && appWindow && attached == null
Jorim Jaggie6c6ecb2017-07-20 18:09:20 +02005452 && attrs.isFullscreen() && stackId == DOCKED_STACK_ID) {
Jorim Jaggi86905582016-02-09 21:36:09 -08005453 mTopDockedOpaqueWindowState = win;
5454 if (mTopDockedOpaqueOrDimmingWindowState == null) {
5455 mTopDockedOpaqueOrDimmingWindowState = win;
5456 }
5457 }
5458
5459 // Also keep track of any windows that are dimming but not necessarily fullscreen in the
5460 // docked stack.
Jorim Jaggi23cc9aa2017-05-23 16:05:35 +02005461 if (mTopDockedOpaqueOrDimmingWindowState == null && affectsSystemUi && win.isDimming()
Jorim Jaggi86905582016-02-09 21:36:09 -08005462 && stackId == DOCKED_STACK_ID) {
5463 mTopDockedOpaqueOrDimmingWindowState = win;
5464 }
5465 }
5466
Jorim Jaggife762342016-10-13 14:33:27 +02005467 private void applyKeyguardPolicyLw(WindowState win, WindowState imeTarget) {
5468 if (canBeHiddenByKeyguardLw(win)) {
5469 if (shouldBeHiddenByKeyguard(win, imeTarget)) {
5470 win.hideLw(false /* doAnimation */);
5471 } else {
5472 win.showLw(false /* doAnimation */);
5473 }
5474 }
5475 }
5476
Dianne Hackborn5f3063e2010-03-10 16:01:58 -08005477 /** {@inheritDoc} */
Craig Mautnerad09bcc2012-10-08 13:33:11 -07005478 @Override
Craig Mautner39834192012-09-02 07:47:24 -07005479 public int finishPostLayoutPolicyLw() {
Dianne Hackborn39c2d712009-09-22 11:41:31 -07005480 int changes = 0;
Joe Onorato93056472010-09-10 10:30:46 -04005481 boolean topIsFullscreen = false;
Daniel Sandlere02d8082010-10-08 15:13:22 -04005482
5483 final WindowManager.LayoutParams lp = (mTopFullscreenOpaqueWindowState != null)
5484 ? mTopFullscreenOpaqueWindowState.getAttrs()
5485 : null;
5486
Jeff Brownc8018eb2012-10-29 21:33:27 -07005487 // If we are not currently showing a dream then remember the current
5488 // lockscreen state. We will use this to determine whether the dream
5489 // started while the lockscreen was showing and remember this state
5490 // while the dream is showing.
Dianne Hackborn7ad44382012-10-18 17:46:00 -07005491 if (!mShowingDream) {
Jorim Jaggi8d786932016-10-26 19:08:36 -07005492 mDreamingLockscreen = isKeyguardShowingAndNotOccluded();
Jeff Brown061ea992015-04-17 19:55:47 -07005493 if (mDreamingSleepTokenNeeded) {
5494 mDreamingSleepTokenNeeded = false;
5495 mHandler.obtainMessage(MSG_UPDATE_DREAMING_SLEEP_TOKEN, 0, 1).sendToTarget();
5496 }
5497 } else {
5498 if (!mDreamingSleepTokenNeeded) {
5499 mDreamingSleepTokenNeeded = true;
5500 mHandler.obtainMessage(MSG_UPDATE_DREAMING_SLEEP_TOKEN, 1, 1).sendToTarget();
5501 }
Dianne Hackborn7ad44382012-10-18 17:46:00 -07005502 }
5503
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005504 if (mStatusBar != null) {
Craig Mautnereda67292013-04-28 13:50:14 -07005505 if (DEBUG_LAYOUT) Slog.i(TAG, "force=" + mForceStatusBar
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07005506 + " forcefkg=" + mForceStatusBarFromKeyguard
Dianne Hackbornd70bc2f2009-10-06 23:25:51 -07005507 + " top=" + mTopFullscreenOpaqueWindowState);
Selim Cinek4a4a2bddc2015-05-07 12:50:19 -07005508 boolean shouldBeTransparent = mForceStatusBarTransparent
5509 && !mForceStatusBar
5510 && !mForceStatusBarFromKeyguard;
5511 if (!shouldBeTransparent) {
5512 mStatusBarController.setShowTransparent(false /* transparent */);
5513 } else if (!mStatusBar.isVisibleLw()) {
5514 mStatusBarController.setShowTransparent(true /* transparent */);
5515 }
Adrian Roosdb1bc6b2016-04-14 17:49:43 -07005516
5517 WindowManager.LayoutParams statusBarAttrs = mStatusBar.getAttrs();
5518 boolean statusBarExpanded = statusBarAttrs.height == MATCH_PARENT
5519 && statusBarAttrs.width == MATCH_PARENT;
5520 if (mForceStatusBar || mForceStatusBarFromKeyguard || mForceStatusBarTransparent
5521 || statusBarExpanded) {
Craig Mautnereda67292013-04-28 13:50:14 -07005522 if (DEBUG_LAYOUT) Slog.v(TAG, "Showing status bar: forced");
John Spurlock27735a42013-08-14 17:57:38 -04005523 if (mStatusBarController.setBarShowingLw(true)) {
5524 changes |= FINISH_LAYOUT_REDO_LAYOUT;
5525 }
Craig Mautner81defc72013-10-29 11:10:42 -07005526 // Maintain fullscreen layout until incoming animation is complete.
5527 topIsFullscreen = mTopIsFullscreen && mStatusBar.isAnimatingLw();
John Spurlockf92b6162013-11-11 15:01:16 -05005528 // Transient status bar on the lockscreen is not allowed
Jorim Jaggi2dc47c12017-05-05 17:39:58 +02005529 if ((mForceStatusBarFromKeyguard || statusBarExpanded)
5530 && mStatusBarController.isTransientShowing()) {
John Spurlockf92b6162013-11-11 15:01:16 -05005531 mStatusBarController.updateVisibilityLw(false /*transientAllowed*/,
5532 mLastSystemUiFlags, mLastSystemUiFlags);
5533 }
Adrian Roosdb1bc6b2016-04-14 17:49:43 -07005534 if (statusBarExpanded && mNavigationBar != null) {
5535 if (mNavigationBarController.setBarShowingLw(true)) {
5536 changes |= FINISH_LAYOUT_REDO_LAYOUT;
5537 }
5538 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005539 } else if (mTopFullscreenOpaqueWindowState != null) {
John Spurlockc6d1c602014-01-17 15:22:06 -05005540 final int fl = PolicyControl.getWindowFlags(null, lp);
Joe Onorato93056472010-09-10 10:30:46 -04005541 if (localLOGV) {
Craig Mautnereda67292013-04-28 13:50:14 -07005542 Slog.d(TAG, "frame: " + mTopFullscreenOpaqueWindowState.getFrameLw()
Filip Gruszczynski2a6a2c22015-10-14 12:00:53 -07005543 + " shown position: "
5544 + mTopFullscreenOpaqueWindowState.getShownPositionLw());
Craig Mautnereda67292013-04-28 13:50:14 -07005545 Slog.d(TAG, "attr: " + mTopFullscreenOpaqueWindowState.getAttrs()
John Spurlockc6d1c602014-01-17 15:22:06 -05005546 + " lp.flags=0x" + Integer.toHexString(fl));
Joe Onorato93056472010-09-10 10:30:46 -04005547 }
John Spurlockc6d1c602014-01-17 15:22:06 -05005548 topIsFullscreen = (fl & WindowManager.LayoutParams.FLAG_FULLSCREEN) != 0
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07005549 || (mLastSystemUiFlags & View.SYSTEM_UI_FLAG_FULLSCREEN) != 0;
Joe Onorato93056472010-09-10 10:30:46 -04005550 // The subtle difference between the window for mTopFullscreenOpaqueWindowState
Mark Dolinerd0646dc2014-08-27 16:04:02 -07005551 // and mTopIsFullscreen is that mTopIsFullscreen is set only if the window
Joe Onorato93056472010-09-10 10:30:46 -04005552 // has the FLAG_FULLSCREEN set. Not sure if there is another way that to be the
5553 // case though.
John Spurlock27735a42013-08-14 17:57:38 -04005554 if (mStatusBarController.isTransientShowing()) {
5555 if (mStatusBarController.setBarShowingLw(true)) {
John Spurlock32beb2c2013-03-11 10:16:47 -04005556 changes |= FINISH_LAYOUT_REDO_LAYOUT;
5557 }
Wale Ogunwale6e94a9e2015-10-07 15:35:49 -07005558 } else if (topIsFullscreen
5559 && !mWindowManagerInternal.isStackVisible(FREEFORM_WORKSPACE_STACK_ID)
5560 && !mWindowManagerInternal.isStackVisible(DOCKED_STACK_ID)) {
Craig Mautnereda67292013-04-28 13:50:14 -07005561 if (DEBUG_LAYOUT) Slog.v(TAG, "** HIDING status bar");
John Spurlock27735a42013-08-14 17:57:38 -04005562 if (mStatusBarController.setBarShowingLw(false)) {
Dianne Hackbornf87d1962012-04-04 12:48:24 -07005563 changes |= FINISH_LAYOUT_REDO_LAYOUT;
Craig Mautnereda67292013-04-28 13:50:14 -07005564 } else {
Craig Mautnerc5a6e442013-06-05 17:22:35 -07005565 if (DEBUG_LAYOUT) Slog.v(TAG, "Status bar already hiding");
Daniel Sandler40427442010-07-16 11:44:52 -04005566 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005567 } else {
Craig Mautnereda67292013-04-28 13:50:14 -07005568 if (DEBUG_LAYOUT) Slog.v(TAG, "** SHOWING status bar: top is not fullscreen");
John Spurlock27735a42013-08-14 17:57:38 -04005569 if (mStatusBarController.setBarShowingLw(true)) {
5570 changes |= FINISH_LAYOUT_REDO_LAYOUT;
5571 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005572 }
5573 }
5574 }
Daniel Sandlere02d8082010-10-08 15:13:22 -04005575
Craig Mautner81defc72013-10-29 11:10:42 -07005576 if (mTopIsFullscreen != topIsFullscreen) {
5577 if (!topIsFullscreen) {
5578 // Force another layout when status bar becomes fully shown.
5579 changes |= FINISH_LAYOUT_REDO_LAYOUT;
5580 }
5581 mTopIsFullscreen = topIsFullscreen;
5582 }
Daniel Sandlere02d8082010-10-08 15:13:22 -04005583
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07005584 if ((updateSystemUiVisibilityLw()&SYSTEM_UI_CHANGING_LAYOUT) != 0) {
Dianne Hackborndf89e652011-10-06 22:35:11 -07005585 // If the navigation bar has been hidden or shown, we need to do another
5586 // layout pass to update that window.
5587 changes |= FINISH_LAYOUT_REDO_LAYOUT;
5588 }
Joe Onorato664644d2011-01-23 17:53:23 -08005589
Jorim Jaggi77e10432016-10-26 17:43:56 -07005590 if (mShowingDream != mLastShowingDream) {
5591 mLastShowingDream = mShowingDream;
5592 mWindowManagerFuncs.notifyShowingDreamChanged();
5593 }
5594
Mike Lockwood28569302010-01-28 11:54:40 -05005595 // update since mAllowLockscreenWhenOn might have changed
5596 updateLockScreenTimeout();
Dianne Hackborn39c2d712009-09-22 11:41:31 -07005597 return changes;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005598 }
5599
Jorim Jaggi380ecb82014-03-14 17:25:20 +01005600 /**
Jim Millerab954542014-10-10 18:21:49 -07005601 * Updates the occluded state of the Keyguard.
Jorim Jaggi380ecb82014-03-14 17:25:20 +01005602 *
Jorim Jaggi380ecb82014-03-14 17:25:20 +01005603 * @return Whether the flags have changed and we have to redo the layout.
5604 */
Jorim Jaggi9ba2e102017-04-04 12:51:03 +02005605 private boolean setKeyguardOccludedLw(boolean isOccluded, boolean force) {
Jorim Jaggife762342016-10-13 14:33:27 +02005606 if (DEBUG_KEYGUARD) Slog.d(TAG, "setKeyguardOccluded occluded=" + isOccluded);
Jorim Jaggiec7708a2017-04-10 18:47:36 -07005607 final boolean wasOccluded = mKeyguardOccluded;
5608 final boolean showing = mKeyguardDelegate.isShowing();
5609 final boolean changed = wasOccluded != isOccluded || force;
5610 if (!isOccluded && changed && showing) {
Jim Millerab954542014-10-10 18:21:49 -07005611 mKeyguardOccluded = false;
Jorim Jaggi6626f542016-08-22 13:08:44 -07005612 mKeyguardDelegate.setOccluded(false, true /* animate */);
Jorim Jaggi9ba2e102017-04-04 12:51:03 +02005613 if (mStatusBar != null) {
5614 mStatusBar.getAttrs().privateFlags |= PRIVATE_FLAG_KEYGUARD;
5615 if (!mKeyguardDelegate.hasLockscreenWallpaper()) {
5616 mStatusBar.getAttrs().flags |= FLAG_SHOW_WALLPAPER;
5617 }
Jorim Jaggid11d1a92016-08-16 16:02:32 -07005618 }
Jorim Jaggi380ecb82014-03-14 17:25:20 +01005619 return true;
Jorim Jaggiec7708a2017-04-10 18:47:36 -07005620 } else if (isOccluded && changed && showing) {
Jim Millerab954542014-10-10 18:21:49 -07005621 mKeyguardOccluded = true;
Jorim Jaggi6626f542016-08-22 13:08:44 -07005622 mKeyguardDelegate.setOccluded(true, false /* animate */);
Jorim Jaggi9ba2e102017-04-04 12:51:03 +02005623 if (mStatusBar != null) {
5624 mStatusBar.getAttrs().privateFlags &= ~PRIVATE_FLAG_KEYGUARD;
5625 mStatusBar.getAttrs().flags &= ~FLAG_SHOW_WALLPAPER;
5626 }
Jorim Jaggi380ecb82014-03-14 17:25:20 +01005627 return true;
Jorim Jaggiec7708a2017-04-10 18:47:36 -07005628 } else if (changed) {
Adrian Roos909fe2d2016-10-12 12:03:24 -07005629 mKeyguardOccluded = isOccluded;
5630 mKeyguardDelegate.setOccluded(isOccluded, false /* animate */);
5631 return false;
Jorim Jaggi380ecb82014-03-14 17:25:20 +01005632 } else {
5633 return false;
5634 }
5635 }
5636
5637 private boolean isStatusBarKeyguard() {
5638 return mStatusBar != null
5639 && (mStatusBar.getAttrs().privateFlags & PRIVATE_FLAG_KEYGUARD) != 0;
5640 }
5641
Jose Lima9546b202014-07-02 17:21:51 -07005642 @Override
Dianne Hackborn08743722009-12-21 12:16:51 -08005643 public boolean allowAppAnimationsLw() {
Jorim Jaggife762342016-10-13 14:33:27 +02005644 if (mShowingDream) {
Craig Mautner28816302013-10-10 20:31:00 -07005645 // If keyguard or dreams is currently visible, no reason to animate behind it.
Dianne Hackborn08743722009-12-21 12:16:51 -08005646 return false;
5647 }
Dianne Hackborn08743722009-12-21 12:16:51 -08005648 return true;
5649 }
5650
Jose Lima9546b202014-07-02 17:21:51 -07005651 @Override
Dianne Hackborndf89e652011-10-06 22:35:11 -07005652 public int focusChangedLw(WindowState lastFocus, WindowState newFocus) {
Joe Onorato664644d2011-01-23 17:53:23 -08005653 mFocusedWindow = newFocus;
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07005654 if ((updateSystemUiVisibilityLw()&SYSTEM_UI_CHANGING_LAYOUT) != 0) {
Dianne Hackborndf89e652011-10-06 22:35:11 -07005655 // If the navigation bar has been hidden or shown, we need to do another
5656 // layout pass to update that window.
5657 return FINISH_LAYOUT_REDO_LAYOUT;
5658 }
5659 return 0;
Joe Onorato664644d2011-01-23 17:53:23 -08005660 }
5661
Dianne Hackborn0ecadf72009-03-31 18:00:37 -07005662 /** {@inheritDoc} */
Jose Lima9546b202014-07-02 17:21:51 -07005663 @Override
Jeff Brown46b9ac02010-04-22 18:58:52 -07005664 public void notifyLidSwitchChanged(long whenNanos, boolean lidOpen) {
5665 // lid changed state
Jeff Brownc458ce92012-04-30 14:58:40 -07005666 final int newLidState = lidOpen ? LID_OPEN : LID_CLOSED;
5667 if (newLidState == mLidState) {
5668 return;
5669 }
Jeff Brown01a98dd2011-09-20 15:08:29 -07005670
Jeff Brownc458ce92012-04-30 14:58:40 -07005671 mLidState = newLidState;
5672 applyLidSwitchState();
Jeff Brown01a98dd2011-09-20 15:08:29 -07005673 updateRotation(true);
Jeff Brownc458ce92012-04-30 14:58:40 -07005674
5675 if (lidOpen) {
Dianne Hackborn280a64e2015-07-13 14:48:08 -07005676 wakeUp(SystemClock.uptimeMillis(), mAllowTheaterModeWakeFromLidSwitch,
5677 "android.policy:LID");
Jeff Brownc458ce92012-04-30 14:58:40 -07005678 } else if (!mLidControlsSleep) {
Jeff Brown96307042012-07-27 15:51:34 -07005679 mPowerManager.userActivity(SystemClock.uptimeMillis(), false);
Jeff Brown46b9ac02010-04-22 18:58:52 -07005680 }
5681 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005682
Michael Wright3818c922014-09-02 13:59:07 -07005683 @Override
5684 public void notifyCameraLensCoverSwitchChanged(long whenNanos, boolean lensCovered) {
5685 int lensCoverState = lensCovered ? CAMERA_LENS_COVERED : CAMERA_LENS_UNCOVERED;
5686 if (mCameraLensCoverState == lensCoverState) {
5687 return;
5688 }
5689 if (mCameraLensCoverState == CAMERA_LENS_COVERED &&
5690 lensCoverState == CAMERA_LENS_UNCOVERED) {
5691 Intent intent;
5692 final boolean keyguardActive = mKeyguardDelegate == null ? false :
5693 mKeyguardDelegate.isShowing();
5694 if (keyguardActive) {
5695 intent = new Intent(MediaStore.INTENT_ACTION_STILL_IMAGE_CAMERA_SECURE);
5696 } else {
5697 intent = new Intent(MediaStore.INTENT_ACTION_STILL_IMAGE_CAMERA);
5698 }
Dianne Hackborn280a64e2015-07-13 14:48:08 -07005699 wakeUp(whenNanos / 1000000, mAllowTheaterModeWakeFromCameraLens,
5700 "android.policy:CAMERA_COVER");
Bart Sears8b1c27c2015-03-18 23:51:02 +00005701 startActivityAsUser(intent, UserHandle.CURRENT_OR_SELF);
Michael Wright3818c922014-09-02 13:59:07 -07005702 }
5703 mCameraLensCoverState = lensCoverState;
5704 }
5705
Dianne Hackbornad7fa7f2011-01-07 14:06:50 -08005706 void setHdmiPlugged(boolean plugged) {
5707 if (mHdmiPlugged != plugged) {
5708 mHdmiPlugged = plugged;
Dianne Hackbornf87d1962012-04-04 12:48:24 -07005709 updateRotation(true, true);
Dianne Hackbornad7fa7f2011-01-07 14:06:50 -08005710 Intent intent = new Intent(ACTION_HDMI_PLUGGED);
Joe Onoratodc100302011-01-11 17:07:41 -08005711 intent.addFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY_BEFORE_BOOT);
Dianne Hackbornad7fa7f2011-01-07 14:06:50 -08005712 intent.putExtra(EXTRA_HDMI_PLUGGED_STATE, plugged);
Dianne Hackborn5ac72a22012-08-29 18:32:08 -07005713 mContext.sendStickyBroadcastAsUser(intent, UserHandle.ALL);
Dianne Hackbornad7fa7f2011-01-07 14:06:50 -08005714 }
5715 }
5716
Joe Onoratoea495d42011-04-06 11:41:11 -07005717 void initializeHdmiState() {
Joe Onorato7ba631f2011-05-04 15:28:00 -07005718 boolean plugged = false;
Joe Onoratoea495d42011-04-06 11:41:11 -07005719 // watch for HDMI plug messages if the hdmi switch exists
5720 if (new File("/sys/devices/virtual/switch/hdmi/state").exists()) {
5721 mHDMIObserver.startObserving("DEVPATH=/devices/virtual/switch/hdmi");
5722
Joe Onoratoea495d42011-04-06 11:41:11 -07005723 final String filename = "/sys/class/switch/hdmi/state";
5724 FileReader reader = null;
5725 try {
5726 reader = new FileReader(filename);
5727 char[] buf = new char[15];
5728 int n = reader.read(buf);
5729 if (n > 1) {
5730 plugged = 0 != Integer.parseInt(new String(buf, 0, n-1));
5731 }
5732 } catch (IOException ex) {
5733 Slog.w(TAG, "Couldn't read hdmi state from " + filename + ": " + ex);
5734 } catch (NumberFormatException ex) {
5735 Slog.w(TAG, "Couldn't read hdmi state from " + filename + ": " + ex);
5736 } finally {
5737 if (reader != null) {
5738 try {
5739 reader.close();
5740 } catch (IOException ex) {
5741 }
Joe Onoratodc100302011-01-11 17:07:41 -08005742 }
5743 }
5744 }
Joe Onorato7ba631f2011-05-04 15:28:00 -07005745 // This dance forces the code in setHdmiPlugged to run.
5746 // Always do this so the sticky intent is stuck (to false) if there is no hdmi.
5747 mHdmiPlugged = !plugged;
5748 setHdmiPlugged(!mHdmiPlugged);
Joe Onoratodc100302011-01-11 17:07:41 -08005749 }
5750
Dianne Hackbornc0e3f242011-08-19 14:19:10 -07005751 final Object mScreenshotLock = new Object();
Dianne Hackbornfc8fa632011-08-17 16:20:47 -07005752 ServiceConnection mScreenshotConnection = null;
Dianne Hackbornfc8fa632011-08-17 16:20:47 -07005753
Jeff Brownd5bb82d2011-10-12 13:57:59 -07005754 final Runnable mScreenshotTimeout = new Runnable() {
5755 @Override public void run() {
5756 synchronized (mScreenshotLock) {
5757 if (mScreenshotConnection != null) {
5758 mContext.unbindService(mScreenshotConnection);
5759 mScreenshotConnection = null;
Winson44dbe292016-03-10 14:00:14 -08005760 notifyScreenshotError();
Dianne Hackbornfc8fa632011-08-17 16:20:47 -07005761 }
Winson Chung9112ec32011-06-27 13:15:32 -07005762 }
Jeff Brownd5bb82d2011-10-12 13:57:59 -07005763 }
5764 };
5765
5766 // Assume this is called from the Handler thread.
Muyuan Li6ca619f2016-03-08 13:30:42 -08005767 private void takeScreenshot(final int screenshotType) {
Jeff Brownd5bb82d2011-10-12 13:57:59 -07005768 synchronized (mScreenshotLock) {
5769 if (mScreenshotConnection != null) {
5770 return;
5771 }
Winson44dbe292016-03-10 14:00:14 -08005772 final ComponentName serviceComponent = new ComponentName(SYSUI_PACKAGE,
5773 SYSUI_SCREENSHOT_SERVICE);
5774 final Intent serviceIntent = new Intent();
5775 serviceIntent.setComponent(serviceComponent);
Jeff Brownd5bb82d2011-10-12 13:57:59 -07005776 ServiceConnection conn = new ServiceConnection() {
5777 @Override
5778 public void onServiceConnected(ComponentName name, IBinder service) {
5779 synchronized (mScreenshotLock) {
5780 if (mScreenshotConnection != this) {
5781 return;
5782 }
5783 Messenger messenger = new Messenger(service);
Muyuan Li6ca619f2016-03-08 13:30:42 -08005784 Message msg = Message.obtain(null, screenshotType);
Jeff Brownd5bb82d2011-10-12 13:57:59 -07005785 final ServiceConnection myConn = this;
5786 Handler h = new Handler(mHandler.getLooper()) {
5787 @Override
5788 public void handleMessage(Message msg) {
5789 synchronized (mScreenshotLock) {
5790 if (mScreenshotConnection == myConn) {
5791 mContext.unbindService(mScreenshotConnection);
5792 mScreenshotConnection = null;
5793 mHandler.removeCallbacks(mScreenshotTimeout);
5794 }
5795 }
5796 }
5797 };
5798 msg.replyTo = new Messenger(h);
Winson Chunga63bb842011-10-17 10:26:28 -07005799 msg.arg1 = msg.arg2 = 0;
5800 if (mStatusBar != null && mStatusBar.isVisibleLw())
5801 msg.arg1 = 1;
5802 if (mNavigationBar != null && mNavigationBar.isVisibleLw())
5803 msg.arg2 = 1;
Jeff Brownd5bb82d2011-10-12 13:57:59 -07005804 try {
5805 messenger.send(msg);
5806 } catch (RemoteException e) {
5807 }
5808 }
5809 }
Winson44dbe292016-03-10 14:00:14 -08005810
Jeff Brownd5bb82d2011-10-12 13:57:59 -07005811 @Override
Winson44dbe292016-03-10 14:00:14 -08005812 public void onServiceDisconnected(ComponentName name) {
Geoffrey Pitschb2d6ed32016-08-24 10:37:19 -04005813 synchronized (mScreenshotLock) {
5814 if (mScreenshotConnection != null) {
5815 mContext.unbindService(mScreenshotConnection);
5816 mScreenshotConnection = null;
5817 mHandler.removeCallbacks(mScreenshotTimeout);
5818 notifyScreenshotError();
5819 }
5820 }
Winson44dbe292016-03-10 14:00:14 -08005821 }
Jeff Brownd5bb82d2011-10-12 13:57:59 -07005822 };
Winson44dbe292016-03-10 14:00:14 -08005823 if (mContext.bindServiceAsUser(serviceIntent, conn,
5824 Context.BIND_AUTO_CREATE | Context.BIND_FOREGROUND_SERVICE_WHILE_AWAKE,
5825 UserHandle.CURRENT)) {
Jeff Brownd5bb82d2011-10-12 13:57:59 -07005826 mScreenshotConnection = conn;
5827 mHandler.postDelayed(mScreenshotTimeout, 10000);
5828 }
5829 }
Winson Chung9112ec32011-06-27 13:15:32 -07005830 }
5831
Winson44dbe292016-03-10 14:00:14 -08005832 /**
5833 * Notifies the screenshot service to show an error.
5834 */
5835 private void notifyScreenshotError() {
5836 // If the service process is killed, then ask it to clean up after itself
5837 final ComponentName errorComponent = new ComponentName(SYSUI_PACKAGE,
5838 SYSUI_SCREENSHOT_ERROR_RECEIVER);
Dianne Hackborna8c16932016-05-24 12:58:21 -07005839 Intent errorIntent = new Intent(Intent.ACTION_USER_PRESENT);
Winson44dbe292016-03-10 14:00:14 -08005840 errorIntent.setComponent(errorComponent);
5841 errorIntent.addFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY_BEFORE_BOOT |
5842 Intent.FLAG_RECEIVER_FOREGROUND);
Winson538c2262016-05-19 10:06:18 -07005843 mContext.sendBroadcastAsUser(errorIntent, UserHandle.CURRENT);
Winson44dbe292016-03-10 14:00:14 -08005844 }
5845
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005846 /** {@inheritDoc} */
Jeff Brown00fa7bd2010-07-02 15:37:36 -07005847 @Override
Jeff Brown037c33e2014-04-09 00:31:55 -07005848 public int interceptKeyBeforeQueueing(KeyEvent event, int policyFlags) {
Jeff Brown96307042012-07-27 15:51:34 -07005849 if (!mSystemBooted) {
5850 // If we have not yet booted, don't let key events do anything.
5851 return 0;
5852 }
5853
Jeff Brown037c33e2014-04-09 00:31:55 -07005854 final boolean interactive = (policyFlags & FLAG_INTERACTIVE) != 0;
Jeff Brown1f245102010-11-18 20:53:46 -08005855 final boolean down = event.getAction() == KeyEvent.ACTION_DOWN;
5856 final boolean canceled = event.isCanceled();
5857 final int keyCode = event.getKeyCode();
Jeff Browne20c9e02010-10-11 14:20:19 -07005858
Jeff Brown3122e442010-10-11 23:32:49 -07005859 final boolean isInjected = (policyFlags & WindowManagerPolicy.FLAG_INJECTED) != 0;
Jeff Brown3122e442010-10-11 23:32:49 -07005860
Mike Lockwoodc72b15f2009-11-28 20:58:22 -05005861 // If screen is off then we treat the case where the keyguard is open but hidden
5862 // the same as if it were open and in front.
5863 // This will prevent any keys other than the power button from waking the screen
5864 // when the keyguard is hidden by another activity.
Jim Miller5ecd8112013-01-09 18:50:26 -08005865 final boolean keyguardActive = (mKeyguardDelegate == null ? false :
Jeff Brown037c33e2014-04-09 00:31:55 -07005866 (interactive ?
Jim Millerab954542014-10-10 18:21:49 -07005867 isKeyguardShowingAndNotOccluded() :
Jim Miller5ecd8112013-01-09 18:50:26 -08005868 mKeyguardDelegate.isShowing()));
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005869
Jeff Brown40013652012-05-16 21:22:36 -07005870 if (DEBUG_INPUT) {
Jeff Brown00fa7bd2010-07-02 15:37:36 -07005871 Log.d(TAG, "interceptKeyTq keycode=" + keyCode
Jeff Brown037c33e2014-04-09 00:31:55 -07005872 + " interactive=" + interactive + " keyguardActive=" + keyguardActive
Jeff Brown26875502014-01-30 21:47:47 -08005873 + " policyFlags=" + Integer.toHexString(policyFlags));
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005874 }
5875
Jeff Brown037c33e2014-04-09 00:31:55 -07005876 // Basic policy based on interactive state.
Jeff Brown4d396052010-10-29 21:50:21 -07005877 int result;
Michael Wright337d9d22014-04-22 15:03:48 -07005878 boolean isWakeKey = (policyFlags & WindowManagerPolicy.FLAG_WAKE) != 0
5879 || event.isWakeKey();
Michael Wrightfc01f042014-09-08 14:12:24 -07005880 if (interactive || (isInjected && !isWakeKey)) {
RoboErikde9ba392014-09-26 12:51:01 -07005881 // When the device is interactive or the key is injected pass the
5882 // key to the application.
Jeff Brown4d396052010-10-29 21:50:21 -07005883 result = ACTION_PASS_TO_USER;
Jose Lima9546b202014-07-02 17:21:51 -07005884 isWakeKey = false;
Anthony Hugh4b13ab82016-05-17 13:03:00 -07005885
5886 if (interactive) {
5887 // If the screen is awake, but the button pressed was the one that woke the device
5888 // then don't pass it to the application
5889 if (keyCode == mPendingWakeKey && !down) {
5890 result = 0;
5891 }
5892 // Reset the pending key
5893 mPendingWakeKey = PENDING_KEY_NULL;
5894 }
5895 } else if (!interactive && shouldDispatchInputWhenNonInteractive(event)) {
Michael Wrightfc01f042014-09-08 14:12:24 -07005896 // If we're currently dozing with the screen on and the keyguard showing, pass the key
5897 // to the application but preserve its wake key status to make sure we still move
5898 // from dozing to fully interactive if we would normally go from off to fully
5899 // interactive.
5900 result = ACTION_PASS_TO_USER;
Anthony Hugh4b13ab82016-05-17 13:03:00 -07005901 // Since we're dispatching the input, reset the pending key
5902 mPendingWakeKey = PENDING_KEY_NULL;
Jeff Brown4d396052010-10-29 21:50:21 -07005903 } else {
5904 // When the screen is off and the key is not injected, determine whether
5905 // to wake the device but don't pass the key to the application.
5906 result = 0;
Jeff Brown26875502014-01-30 21:47:47 -08005907 if (isWakeKey && (!down || !isWakeKeyWhenScreenOff(keyCode))) {
5908 isWakeKey = false;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005909 }
Anthony Hugh4b13ab82016-05-17 13:03:00 -07005910 // Cache the wake key on down event so we can also avoid sending the up event to the app
5911 if (isWakeKey && down) {
5912 mPendingWakeKey = keyCode;
5913 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005914 }
5915
Justin Kohd378ad72013-04-01 12:18:26 -07005916 // If the key would be handled globally, just return the result, don't worry about special
5917 // key processing.
Jeff Brown13f00f02014-10-31 14:45:50 -07005918 if (isValidGlobalKey(keyCode)
5919 && mGlobalKeyManager.shouldHandleGlobalKey(keyCode, event)) {
Michael Wright85b1af62014-06-04 14:51:58 -07005920 if (isWakeKey) {
Dianne Hackborn280a64e2015-07-13 14:48:08 -07005921 wakeUp(event.getEventTime(), mAllowTheaterModeWakeFromKey, "android.policy:KEY");
Michael Wright85b1af62014-06-04 14:51:58 -07005922 }
Justin Kohd378ad72013-04-01 12:18:26 -07005923 return result;
5924 }
5925
Jeff Brownbae8e772014-06-12 19:59:45 -07005926 boolean useHapticFeedback = down
5927 && (policyFlags & WindowManagerPolicy.FLAG_VIRTUAL) != 0
5928 && event.getRepeatCount() == 0;
5929
Jeff Brown4d396052010-10-29 21:50:21 -07005930 // Handle special keys.
5931 switch (keyCode) {
Anthony Hugh34f09ca2016-03-04 12:03:37 -08005932 case KeyEvent.KEYCODE_BACK: {
5933 if (down) {
Anthony Hugh96e9cc52016-07-12 15:17:24 -07005934 interceptBackKeyDown();
Anthony Hugh34f09ca2016-03-04 12:03:37 -08005935 } else {
Anthony Hugh96e9cc52016-07-12 15:17:24 -07005936 boolean handled = interceptBackKeyUp(event);
Anthony Hugh34f09ca2016-03-04 12:03:37 -08005937
Anthony Hugh96e9cc52016-07-12 15:17:24 -07005938 // Don't pass back press to app if we've already handled it via long press
Anthony Hugh34f09ca2016-03-04 12:03:37 -08005939 if (handled) {
5940 result &= ~ACTION_PASS_TO_USER;
5941 }
5942 }
5943 break;
5944 }
5945
Jeff Brown4d396052010-10-29 21:50:21 -07005946 case KeyEvent.KEYCODE_VOLUME_DOWN:
Jeff Brownb0418da2010-11-01 15:24:01 -07005947 case KeyEvent.KEYCODE_VOLUME_UP:
5948 case KeyEvent.KEYCODE_VOLUME_MUTE: {
Jeff Brownd5bb82d2011-10-12 13:57:59 -07005949 if (keyCode == KeyEvent.KEYCODE_VOLUME_DOWN) {
5950 if (down) {
Jeff Brown13f00f02014-10-31 14:45:50 -07005951 if (interactive && !mScreenshotChordVolumeDownKeyTriggered
Jeff Brownd5bb82d2011-10-12 13:57:59 -07005952 && (event.getFlags() & KeyEvent.FLAG_FALLBACK) == 0) {
Jeff Brown13f00f02014-10-31 14:45:50 -07005953 mScreenshotChordVolumeDownKeyTriggered = true;
5954 mScreenshotChordVolumeDownKeyTime = event.getDownTime();
5955 mScreenshotChordVolumeDownKeyConsumed = false;
Jeff Brownd5bb82d2011-10-12 13:57:59 -07005956 cancelPendingPowerKeyAction();
5957 interceptScreenshotChord();
Phil Weaverce687c52017-03-15 08:51:52 -07005958 interceptAccessibilityShortcutChord();
Jeff Brownd5bb82d2011-10-12 13:57:59 -07005959 }
5960 } else {
Jeff Brown13f00f02014-10-31 14:45:50 -07005961 mScreenshotChordVolumeDownKeyTriggered = false;
Jeff Brownd5bb82d2011-10-12 13:57:59 -07005962 cancelPendingScreenshotChordAction();
Phil Weaver106fe732016-11-22 18:18:39 -08005963 cancelPendingAccessibilityShortcutAction();
Jeff Brownd5bb82d2011-10-12 13:57:59 -07005964 }
5965 } else if (keyCode == KeyEvent.KEYCODE_VOLUME_UP) {
5966 if (down) {
Phil Weaver106fe732016-11-22 18:18:39 -08005967 if (interactive && !mA11yShortcutChordVolumeUpKeyTriggered
Jeff Brownd5bb82d2011-10-12 13:57:59 -07005968 && (event.getFlags() & KeyEvent.FLAG_FALLBACK) == 0) {
Phil Weaver106fe732016-11-22 18:18:39 -08005969 mA11yShortcutChordVolumeUpKeyTriggered = true;
5970 mA11yShortcutChordVolumeUpKeyTime = event.getDownTime();
5971 mA11yShortcutChordVolumeUpKeyConsumed = false;
Jeff Brownd5bb82d2011-10-12 13:57:59 -07005972 cancelPendingPowerKeyAction();
5973 cancelPendingScreenshotChordAction();
Phil Weaverce687c52017-03-15 08:51:52 -07005974 interceptAccessibilityShortcutChord();
Jeff Brownd5bb82d2011-10-12 13:57:59 -07005975 }
5976 } else {
Phil Weaver106fe732016-11-22 18:18:39 -08005977 mA11yShortcutChordVolumeUpKeyTriggered = false;
Jeff Brownd5bb82d2011-10-12 13:57:59 -07005978 cancelPendingScreenshotChordAction();
Phil Weaver106fe732016-11-22 18:18:39 -08005979 cancelPendingAccessibilityShortcutAction();
Jeff Brownd5bb82d2011-10-12 13:57:59 -07005980 }
5981 }
Jeff Brown4d396052010-10-29 21:50:21 -07005982 if (down) {
Philip Quinn4b5b3c62017-07-20 21:07:58 -07005983 sendSystemKeyToStatusBarAsync(event.getKeyCode());
5984
Tyler Gunnef9f6f92014-09-12 22:16:17 -07005985 TelecomManager telecomManager = getTelecommService();
5986 if (telecomManager != null) {
5987 if (telecomManager.isRinging()) {
Santos Cordon6848f722014-05-21 15:22:12 -07005988 // If an incoming call is ringing, either VOLUME key means
5989 // "silence ringer". We handle these keys here, rather than
5990 // in the InCallScreen, to make sure we'll respond to them
5991 // even if the InCallScreen hasn't come to the foreground yet.
5992 // Look for the DOWN event here, to agree with the "fallback"
5993 // behavior in the InCallScreen.
5994 Log.i(TAG, "interceptKeyBeforeQueueing:"
5995 + " VOLUME key-down while ringing: Silence ringer!");
Jeff Brown4d396052010-10-29 21:50:21 -07005996
Santos Cordon6848f722014-05-21 15:22:12 -07005997 // Silence the ringer. (It's safe to call this
5998 // even if the ringer has already been silenced.)
Tyler Gunnef9f6f92014-09-12 22:16:17 -07005999 telecomManager.silenceRinger();
Jeff Brown4d396052010-10-29 21:50:21 -07006000
Santos Cordon6848f722014-05-21 15:22:12 -07006001 // And *don't* pass this key thru to the current activity
6002 // (which is probably the InCallScreen.)
6003 result &= ~ACTION_PASS_TO_USER;
6004 break;
6005 }
Jeff Brown4d396052010-10-29 21:50:21 -07006006 }
Eric Laurenta9a52582017-05-10 15:16:01 -07006007 int audioMode = AudioManager.MODE_NORMAL;
6008 try {
6009 audioMode = getAudioService().getMode();
6010 } catch (Exception e) {
6011 Log.e(TAG, "Error getting AudioService in interceptKeyBeforeQueueing.", e);
6012 }
6013 boolean isInCall = (telecomManager != null && telecomManager.isInCall()) ||
6014 audioMode == AudioManager.MODE_IN_COMMUNICATION;
6015 if (isInCall && (result & ACTION_PASS_TO_USER) == 0) {
6016 // If we are in call but we decided not to pass the key to
6017 // the application, just pass it to the session service.
6018 MediaSessionLegacyHelper.getHelper(mContext).sendVolumeKeyEvent(
6019 event, AudioManager.USE_DEFAULT_STREAM_TYPE, false);
6020 break;
6021 }
Jaewan Kim765487f2016-01-12 14:45:42 +09006022 }
Karthik Ravi Shankar86ecf342017-04-28 15:35:58 -07006023 if (mUseTvRouting || mHandleVolumeKeysInWM) {
6024 // Defer special key handlings to
Jaewan Kim765487f2016-01-12 14:45:42 +09006025 // {@link interceptKeyBeforeDispatching()}.
6026 result |= ACTION_PASS_TO_USER;
6027 } else if ((result & ACTION_PASS_TO_USER) == 0) {
6028 // If we aren't passing to the user and no one else
6029 // handled it send it to the session manager to
6030 // figure out.
Jaewan Kim50269362016-12-23 11:22:02 +09006031 MediaSessionLegacyHelper.getHelper(mContext).sendVolumeKeyEvent(
David Linf52b6072017-04-21 18:52:18 -07006032 event, AudioManager.USE_DEFAULT_STREAM_TYPE, true);
Jeff Brown4d396052010-10-29 21:50:21 -07006033 }
6034 break;
6035 }
6036
6037 case KeyEvent.KEYCODE_ENDCALL: {
6038 result &= ~ACTION_PASS_TO_USER;
6039 if (down) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -07006040 TelecomManager telecomManager = getTelecommService();
Jeff Brown4d396052010-10-29 21:50:21 -07006041 boolean hungUp = false;
Tyler Gunnef9f6f92014-09-12 22:16:17 -07006042 if (telecomManager != null) {
6043 hungUp = telecomManager.endCall();
Jeff Brown4d396052010-10-29 21:50:21 -07006044 }
Jeff Brown13f00f02014-10-31 14:45:50 -07006045 if (interactive && !hungUp) {
6046 mEndCallKeyHandled = false;
6047 mHandler.postDelayed(mEndCallLongPress,
6048 ViewConfiguration.get(mContext).getDeviceGlobalActionKeyTimeout());
6049 } else {
6050 mEndCallKeyHandled = true;
6051 }
Jeff Brown4d396052010-10-29 21:50:21 -07006052 } else {
Jeff Brown13f00f02014-10-31 14:45:50 -07006053 if (!mEndCallKeyHandled) {
6054 mHandler.removeCallbacks(mEndCallLongPress);
6055 if (!canceled) {
6056 if ((mEndcallBehavior
6057 & Settings.System.END_BUTTON_BEHAVIOR_HOME) != 0) {
6058 if (goHome()) {
6059 break;
6060 }
Dianne Hackborn0041e972009-07-24 17:14:43 -07006061 }
Jeff Brown13f00f02014-10-31 14:45:50 -07006062 if ((mEndcallBehavior
6063 & Settings.System.END_BUTTON_BEHAVIOR_SLEEP) != 0) {
Selim Cinekab55ba52017-08-02 16:45:51 -07006064 goToSleep(event.getEventTime(),
Jeff Brown13f00f02014-10-31 14:45:50 -07006065 PowerManager.GO_TO_SLEEP_REASON_POWER_BUTTON, 0);
6066 isWakeKey = false;
6067 }
Jeff Brown4d396052010-10-29 21:50:21 -07006068 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006069 }
Jeff Brown4d396052010-10-29 21:50:21 -07006070 }
6071 break;
6072 }
6073
6074 case KeyEvent.KEYCODE_POWER: {
Phil Weaver106fe732016-11-22 18:18:39 -08006075 // Any activity on the power button stops the accessibility shortcut
6076 cancelPendingAccessibilityShortcutAction();
Jeff Brown4d396052010-10-29 21:50:21 -07006077 result &= ~ACTION_PASS_TO_USER;
Jeff Brown13f00f02014-10-31 14:45:50 -07006078 isWakeKey = false; // wake-up will be handled separately
Jeff Brown4d396052010-10-29 21:50:21 -07006079 if (down) {
Jeff Brown13f00f02014-10-31 14:45:50 -07006080 interceptPowerKeyDown(event, interactive);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006081 } else {
Jeff Brown13f00f02014-10-31 14:45:50 -07006082 interceptPowerKeyUp(event, interactive, canceled);
Jeff Brown4d396052010-10-29 21:50:21 -07006083 }
6084 break;
6085 }
6086
Jim Miller07e03842016-06-22 15:18:13 -07006087 case KeyEvent.KEYCODE_SYSTEM_NAVIGATION_DOWN:
Jim Millerf4c0a132016-05-17 18:11:52 -07006088 // fall through
Jim Miller07e03842016-06-22 15:18:13 -07006089 case KeyEvent.KEYCODE_SYSTEM_NAVIGATION_UP:
Jim Millerf4c0a132016-05-17 18:11:52 -07006090 // fall through
Jim Miller07e03842016-06-22 15:18:13 -07006091 case KeyEvent.KEYCODE_SYSTEM_NAVIGATION_LEFT:
Jim Millerf4c0a132016-05-17 18:11:52 -07006092 // fall through
Jim Miller07e03842016-06-22 15:18:13 -07006093 case KeyEvent.KEYCODE_SYSTEM_NAVIGATION_RIGHT: {
6094 result &= ~ACTION_PASS_TO_USER;
6095 interceptSystemNavigationKey(event);
Jim Millerf4c0a132016-05-17 18:11:52 -07006096 break;
6097 }
6098
Jeff Brown6212a492014-03-07 13:58:47 -08006099 case KeyEvent.KEYCODE_SLEEP: {
6100 result &= ~ACTION_PASS_TO_USER;
Filip Gruszczynskia483a1d2015-03-17 19:06:58 +00006101 isWakeKey = false;
Jeff Brownbae8e772014-06-12 19:59:45 -07006102 if (!mPowerManager.isInteractive()) {
6103 useHapticFeedback = false; // suppress feedback if already non-interactive
6104 }
Nick Vaccarob593a812015-05-15 11:23:05 -07006105 if (down) {
6106 sleepPress(event.getEventTime());
6107 } else {
6108 sleepRelease(event.getEventTime());
6109 }
Jeff Brown6212a492014-03-07 13:58:47 -08006110 break;
6111 }
6112
Nick Armstrong-Crews56ecfcc2015-09-07 21:46:50 -07006113 case KeyEvent.KEYCODE_SOFT_SLEEP: {
6114 result &= ~ACTION_PASS_TO_USER;
6115 isWakeKey = false;
6116 if (!down) {
6117 mPowerManagerInternal.setUserInactiveOverrideFromWindowManager();
6118 }
6119 break;
6120 }
6121
Jeff Brown6212a492014-03-07 13:58:47 -08006122 case KeyEvent.KEYCODE_WAKEUP: {
6123 result &= ~ACTION_PASS_TO_USER;
Jose Lima9546b202014-07-02 17:21:51 -07006124 isWakeKey = true;
Jeff Brown6212a492014-03-07 13:58:47 -08006125 break;
6126 }
6127
Jeff Brown4d396052010-10-29 21:50:21 -07006128 case KeyEvent.KEYCODE_MEDIA_PLAY:
6129 case KeyEvent.KEYCODE_MEDIA_PAUSE:
6130 case KeyEvent.KEYCODE_MEDIA_PLAY_PAUSE:
Jeff Brown4d396052010-10-29 21:50:21 -07006131 case KeyEvent.KEYCODE_HEADSETHOOK:
6132 case KeyEvent.KEYCODE_MUTE:
6133 case KeyEvent.KEYCODE_MEDIA_STOP:
6134 case KeyEvent.KEYCODE_MEDIA_NEXT:
6135 case KeyEvent.KEYCODE_MEDIA_PREVIOUS:
6136 case KeyEvent.KEYCODE_MEDIA_REWIND:
6137 case KeyEvent.KEYCODE_MEDIA_RECORD:
Jaekyun Seokbfdad8e2013-07-08 13:53:21 +09006138 case KeyEvent.KEYCODE_MEDIA_FAST_FORWARD:
6139 case KeyEvent.KEYCODE_MEDIA_AUDIO_TRACK: {
RoboErikde9ba392014-09-26 12:51:01 -07006140 if (MediaSessionLegacyHelper.getHelper(mContext).isGlobalPriorityActive()) {
6141 // If the global session is active pass all media keys to it
6142 // instead of the active window.
6143 result &= ~ACTION_PASS_TO_USER;
6144 }
Jeff Brown4d396052010-10-29 21:50:21 -07006145 if ((result & ACTION_PASS_TO_USER) == 0) {
6146 // Only do this if we would otherwise not pass it to the user. In that
6147 // case, the PhoneWindow class will do the same thing, except it will
6148 // only do it if the showing app doesn't process the key on its own.
Jeff Brown40013652012-05-16 21:22:36 -07006149 // Note that we need to make a copy of the key event here because the
6150 // original key event will be recycled when we return.
Jeff Brown4d396052010-10-29 21:50:21 -07006151 mBroadcastWakeLock.acquire();
Jeff Brown40013652012-05-16 21:22:36 -07006152 Message msg = mHandler.obtainMessage(MSG_DISPATCH_MEDIA_KEY_WITH_WAKE_LOCK,
6153 new KeyEvent(event));
6154 msg.setAsynchronous(true);
6155 msg.sendToTarget();
Jeff Brown4d396052010-10-29 21:50:21 -07006156 }
6157 break;
Jeff Brown00fa7bd2010-07-02 15:37:36 -07006158 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006159
Jeff Brown4d396052010-10-29 21:50:21 -07006160 case KeyEvent.KEYCODE_CALL: {
6161 if (down) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -07006162 TelecomManager telecomManager = getTelecommService();
6163 if (telecomManager != null) {
6164 if (telecomManager.isRinging()) {
Santos Cordon6848f722014-05-21 15:22:12 -07006165 Log.i(TAG, "interceptKeyBeforeQueueing:"
6166 + " CALL key-down while ringing: Answer the call!");
Tyler Gunnef9f6f92014-09-12 22:16:17 -07006167 telecomManager.acceptRingingCall();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006168
Santos Cordon6848f722014-05-21 15:22:12 -07006169 // And *don't* pass this key thru to the current activity
6170 // (which is presumably the InCallScreen.)
6171 result &= ~ACTION_PASS_TO_USER;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006172 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006173 }
Jeff Brown00fa7bd2010-07-02 15:37:36 -07006174 }
Jeff Brown4d396052010-10-29 21:50:21 -07006175 break;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006176 }
Michael Wright869a67c2014-08-26 19:33:06 -07006177 case KeyEvent.KEYCODE_VOICE_ASSIST: {
6178 // Only do this if we would otherwise not pass it to the user. In that case,
6179 // interceptKeyBeforeDispatching would apply a similar but different policy in
6180 // order to invoke voice assist actions. Note that we need to make a copy of the
6181 // key event here because the original key event will be recycled when we return.
6182 if ((result & ACTION_PASS_TO_USER) == 0 && !down) {
6183 mBroadcastWakeLock.acquire();
6184 Message msg = mHandler.obtainMessage(MSG_LAUNCH_VOICE_ASSIST_WITH_WAKE_LOCK,
6185 keyguardActive ? 1 : 0, 0);
6186 msg.setAsynchronous(true);
6187 msg.sendToTarget();
6188 }
Jaewan Kim49117872016-01-19 17:24:08 +09006189 break;
6190 }
6191 case KeyEvent.KEYCODE_WINDOW: {
6192 if (mShortPressWindowBehavior == SHORT_PRESS_WINDOW_PICTURE_IN_PICTURE) {
Winson Chungac52f282017-03-30 14:44:52 -07006193 if (mPictureInPictureVisible) {
6194 // Consumes the key only if picture-in-picture is visible to show
6195 // picture-in-picture control menu. This gives a chance to the foreground
6196 // activity to customize PIP key behavior.
Jaewan Kimf0fd2182016-04-20 21:17:58 +09006197 if (!down) {
Winson Chungac52f282017-03-30 14:44:52 -07006198 showPictureInPictureMenu(event);
Jaewan Kimf0fd2182016-04-20 21:17:58 +09006199 }
6200 result &= ~ACTION_PASS_TO_USER;
Jaewan Kim49117872016-01-19 17:24:08 +09006201 }
Jaewan Kim49117872016-01-19 17:24:08 +09006202 }
6203 break;
Michael Wright869a67c2014-08-26 19:33:06 -07006204 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006205 }
Jeff Brown26875502014-01-30 21:47:47 -08006206
Jeff Brownbae8e772014-06-12 19:59:45 -07006207 if (useHapticFeedback) {
6208 performHapticFeedbackLw(null, HapticFeedbackConstants.VIRTUAL_KEY, false);
6209 }
6210
Jeff Brown26875502014-01-30 21:47:47 -08006211 if (isWakeKey) {
Dianne Hackborn280a64e2015-07-13 14:48:08 -07006212 wakeUp(event.getEventTime(), mAllowTheaterModeWakeFromKey, "android.policy:KEY");
Jeff Brown26875502014-01-30 21:47:47 -08006213 }
Bryce Lee584a4452014-10-21 15:55:55 -07006214
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006215 return result;
6216 }
6217
Jeff Brown1c2e4942012-11-06 16:32:01 -08006218 /**
Jim Millerf4c0a132016-05-17 18:11:52 -07006219 * Handle statusbar expansion events.
6220 * @param event
6221 */
Jim Miller07e03842016-06-22 15:18:13 -07006222 private void interceptSystemNavigationKey(KeyEvent event) {
Phil Weaver27fcd9c2017-01-20 15:57:24 -08006223 if (event.getAction() == KeyEvent.ACTION_UP) {
6224 if (!mAccessibilityManager.isEnabled()
6225 || !mAccessibilityManager.sendFingerprintGesture(event.getKeyCode())) {
6226 if (areSystemNavigationKeysEnabled()) {
Philip Quinn4b5b3c62017-07-20 21:07:58 -07006227 sendSystemKeyToStatusBarAsync(event.getKeyCode());
Jim Millerf4c0a132016-05-17 18:11:52 -07006228 }
6229 }
6230 }
6231 }
6232
6233 /**
Philip Quinn4b5b3c62017-07-20 21:07:58 -07006234 * Notify the StatusBar that a system key was pressed.
6235 */
6236 private void sendSystemKeyToStatusBar(int keyCode) {
6237 IStatusBarService statusBar = getStatusBarService();
6238 if (statusBar != null) {
6239 try {
6240 statusBar.handleSystemKey(keyCode);
6241 } catch (RemoteException e) {
6242 // Oh well.
6243 }
6244 }
6245 }
6246
6247 /**
6248 * Notify the StatusBar that a system key was pressed without blocking the current thread.
6249 */
6250 private void sendSystemKeyToStatusBarAsync(int keyCode) {
6251 Message message = mHandler.obtainMessage(MSG_SYSTEM_KEY_PRESS, keyCode, 0);
6252 message.setAsynchronous(true);
6253 mHandler.sendMessage(message);
6254 }
6255
6256 /**
Jeff Brown13f00f02014-10-31 14:45:50 -07006257 * Returns true if the key can have global actions attached to it.
6258 * We reserve all power management keys for the system since they require
6259 * very careful handling.
6260 */
6261 private static boolean isValidGlobalKey(int keyCode) {
6262 switch (keyCode) {
6263 case KeyEvent.KEYCODE_POWER:
6264 case KeyEvent.KEYCODE_WAKEUP:
6265 case KeyEvent.KEYCODE_SLEEP:
6266 return false;
6267 default:
6268 return true;
6269 }
6270 }
6271
6272 /**
Jeff Brown1c2e4942012-11-06 16:32:01 -08006273 * When the screen is off we ignore some keys that might otherwise typically
6274 * be considered wake keys. We filter them out here.
6275 *
6276 * {@link KeyEvent#KEYCODE_POWER} is notably absent from this list because it
6277 * is always considered a wake key.
6278 */
6279 private boolean isWakeKeyWhenScreenOff(int keyCode) {
6280 switch (keyCode) {
6281 // ignore volume keys unless docked
6282 case KeyEvent.KEYCODE_VOLUME_UP:
6283 case KeyEvent.KEYCODE_VOLUME_DOWN:
6284 case KeyEvent.KEYCODE_VOLUME_MUTE:
6285 return mDockMode != Intent.EXTRA_DOCK_STATE_UNDOCKED;
6286
6287 // ignore media and camera keys
6288 case KeyEvent.KEYCODE_MUTE:
6289 case KeyEvent.KEYCODE_HEADSETHOOK:
6290 case KeyEvent.KEYCODE_MEDIA_PLAY:
6291 case KeyEvent.KEYCODE_MEDIA_PAUSE:
6292 case KeyEvent.KEYCODE_MEDIA_PLAY_PAUSE:
6293 case KeyEvent.KEYCODE_MEDIA_STOP:
6294 case KeyEvent.KEYCODE_MEDIA_NEXT:
6295 case KeyEvent.KEYCODE_MEDIA_PREVIOUS:
6296 case KeyEvent.KEYCODE_MEDIA_REWIND:
6297 case KeyEvent.KEYCODE_MEDIA_RECORD:
6298 case KeyEvent.KEYCODE_MEDIA_FAST_FORWARD:
Jaekyun Seokbfdad8e2013-07-08 13:53:21 +09006299 case KeyEvent.KEYCODE_MEDIA_AUDIO_TRACK:
Jeff Brown1c2e4942012-11-06 16:32:01 -08006300 case KeyEvent.KEYCODE_CAMERA:
6301 return false;
6302 }
6303 return true;
6304 }
6305
6306
Jeff Brown56194eb2011-03-02 19:23:13 -08006307 /** {@inheritDoc} */
6308 @Override
Michael Wright70af00a2014-09-03 19:30:20 -07006309 public int interceptMotionBeforeQueueingNonInteractive(long whenNanos, int policyFlags) {
6310 if ((policyFlags & FLAG_WAKE) != 0) {
Dianne Hackborn280a64e2015-07-13 14:48:08 -07006311 if (wakeUp(whenNanos / 1000000, mAllowTheaterModeWakeFromMotion,
6312 "android.policy:MOTION")) {
Bryce Lee5c138322014-11-03 08:26:09 -08006313 return 0;
6314 }
Michael Wright70af00a2014-09-03 19:30:20 -07006315 }
Bryce Lee5c138322014-11-03 08:26:09 -08006316
Anthony Hugh4b13ab82016-05-17 13:03:00 -07006317 if (shouldDispatchInputWhenNonInteractive(null)) {
Michael Wright70af00a2014-09-03 19:30:20 -07006318 return ACTION_PASS_TO_USER;
6319 }
Bryce Lee5c138322014-11-03 08:26:09 -08006320
Bryce Lee812d7022014-11-10 13:33:28 -08006321 // If we have not passed the action up and we are in theater mode without dreaming,
6322 // there will be no dream to intercept the touch and wake into ambient. The device should
6323 // wake up in this case.
6324 if (isTheaterModeEnabled() && (policyFlags & FLAG_WAKE) != 0) {
Dianne Hackborn280a64e2015-07-13 14:48:08 -07006325 wakeUp(whenNanos / 1000000, mAllowTheaterModeWakeFromMotionWhenNotDreaming,
6326 "android.policy:MOTION");
Bryce Lee812d7022014-11-10 13:33:28 -08006327 }
6328
Jeff Brown037c33e2014-04-09 00:31:55 -07006329 return 0;
Jeff Brown56194eb2011-03-02 19:23:13 -08006330 }
6331
Anthony Hugh4b13ab82016-05-17 13:03:00 -07006332 private boolean shouldDispatchInputWhenNonInteractive(KeyEvent event) {
Wale Ogunwale6b15ea52016-04-04 07:28:27 -07006333 final boolean displayOff = (mDisplay == null || mDisplay.getState() == Display.STATE_OFF);
6334
6335 if (displayOff && !mHasFeatureWatch) {
6336 return false;
6337 }
6338
6339 // Send events to keyguard while the screen is on and it's showing.
6340 if (isKeyguardShowingAndNotOccluded() && !displayOff) {
Bryce Lee5c138322014-11-03 08:26:09 -08006341 return true;
6342 }
6343
Anthony Hugh4b13ab82016-05-17 13:03:00 -07006344 // Watches handle BACK specially
6345 if (mHasFeatureWatch
6346 && event != null
6347 && (event.getKeyCode() == KeyEvent.KEYCODE_BACK
6348 || event.getKeyCode() == KeyEvent.KEYCODE_STEM_PRIMARY)) {
6349 return false;
6350 }
6351
Bryce Lee5c138322014-11-03 08:26:09 -08006352 // Send events to a dozing dream even if the screen is off since the dream
6353 // is in control of the state of the screen.
6354 IDreamManager dreamManager = getDreamManager();
6355
6356 try {
6357 if (dreamManager != null && dreamManager.isDreaming()) {
6358 return true;
6359 }
6360 } catch (RemoteException e) {
6361 Slog.e(TAG, "RemoteException when checking if dreaming", e);
6362 }
6363
6364 // Otherwise, consume events since the user can't see what is being
6365 // interacted with.
6366 return false;
Michael Wright70af00a2014-09-03 19:30:20 -07006367 }
6368
RoboErik001c59c2015-01-26 15:53:51 -08006369 private void dispatchDirectAudioEvent(KeyEvent event) {
6370 if (event.getAction() != KeyEvent.ACTION_DOWN) {
6371 return;
6372 }
6373 int keyCode = event.getKeyCode();
John Spurlockb94f2d62015-03-17 14:11:57 -04006374 int flags = AudioManager.FLAG_SHOW_UI | AudioManager.FLAG_PLAY_SOUND
6375 | AudioManager.FLAG_FROM_KEY;
RoboErik001c59c2015-01-26 15:53:51 -08006376 String pkgName = mContext.getOpPackageName();
6377 switch (keyCode) {
6378 case KeyEvent.KEYCODE_VOLUME_UP:
6379 try {
John Spurlockee5ad722015-03-03 16:17:21 -05006380 getAudioService().adjustSuggestedStreamVolume(AudioManager.ADJUST_RAISE,
John Spurlock90874332015-03-10 16:00:54 -04006381 AudioManager.USE_DEFAULT_STREAM_TYPE, flags, pkgName, TAG);
Eric Laurenta9a52582017-05-10 15:16:01 -07006382 } catch (Exception e) {
RoboErik001c59c2015-01-26 15:53:51 -08006383 Log.e(TAG, "Error dispatching volume up in dispatchTvAudioEvent.", e);
6384 }
6385 break;
6386 case KeyEvent.KEYCODE_VOLUME_DOWN:
6387 try {
John Spurlockee5ad722015-03-03 16:17:21 -05006388 getAudioService().adjustSuggestedStreamVolume(AudioManager.ADJUST_LOWER,
John Spurlock90874332015-03-10 16:00:54 -04006389 AudioManager.USE_DEFAULT_STREAM_TYPE, flags, pkgName, TAG);
Eric Laurenta9a52582017-05-10 15:16:01 -07006390 } catch (Exception e) {
RoboErik001c59c2015-01-26 15:53:51 -08006391 Log.e(TAG, "Error dispatching volume down in dispatchTvAudioEvent.", e);
6392 }
6393 break;
6394 case KeyEvent.KEYCODE_VOLUME_MUTE:
6395 try {
6396 if (event.getRepeatCount() == 0) {
John Spurlockee5ad722015-03-03 16:17:21 -05006397 getAudioService().adjustSuggestedStreamVolume(
6398 AudioManager.ADJUST_TOGGLE_MUTE,
John Spurlock90874332015-03-10 16:00:54 -04006399 AudioManager.USE_DEFAULT_STREAM_TYPE, flags, pkgName, TAG);
RoboErik001c59c2015-01-26 15:53:51 -08006400 }
Eric Laurenta9a52582017-05-10 15:16:01 -07006401 } catch (Exception e) {
RoboErik001c59c2015-01-26 15:53:51 -08006402 Log.e(TAG, "Error dispatching mute in dispatchTvAudioEvent.", e);
6403 }
6404 break;
6405 }
6406 }
6407
Jeff Brown40013652012-05-16 21:22:36 -07006408 void dispatchMediaKeyWithWakeLock(KeyEvent event) {
6409 if (DEBUG_INPUT) {
6410 Slog.d(TAG, "dispatchMediaKeyWithWakeLock: " + event);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006411 }
6412
Jeff Brown40013652012-05-16 21:22:36 -07006413 if (mHavePendingMediaKeyRepeatWithWakeLock) {
6414 if (DEBUG_INPUT) {
6415 Slog.d(TAG, "dispatchMediaKeyWithWakeLock: canceled repeat");
6416 }
6417
6418 mHandler.removeMessages(MSG_DISPATCH_MEDIA_KEY_REPEAT_WITH_WAKE_LOCK);
6419 mHavePendingMediaKeyRepeatWithWakeLock = false;
6420 mBroadcastWakeLock.release(); // pending repeat was holding onto the wake lock
6421 }
6422
6423 dispatchMediaKeyWithWakeLockToAudioService(event);
6424
6425 if (event.getAction() == KeyEvent.ACTION_DOWN
6426 && event.getRepeatCount() == 0) {
6427 mHavePendingMediaKeyRepeatWithWakeLock = true;
6428
6429 Message msg = mHandler.obtainMessage(
6430 MSG_DISPATCH_MEDIA_KEY_REPEAT_WITH_WAKE_LOCK, event);
6431 msg.setAsynchronous(true);
6432 mHandler.sendMessageDelayed(msg, ViewConfiguration.getKeyRepeatTimeout());
6433 } else {
6434 mBroadcastWakeLock.release();
6435 }
6436 }
6437
6438 void dispatchMediaKeyRepeatWithWakeLock(KeyEvent event) {
6439 mHavePendingMediaKeyRepeatWithWakeLock = false;
6440
6441 KeyEvent repeatEvent = KeyEvent.changeTimeRepeat(event,
6442 SystemClock.uptimeMillis(), 1, event.getFlags() | KeyEvent.FLAG_LONG_PRESS);
6443 if (DEBUG_INPUT) {
6444 Slog.d(TAG, "dispatchMediaKeyRepeatWithWakeLock: " + repeatEvent);
6445 }
6446
6447 dispatchMediaKeyWithWakeLockToAudioService(repeatEvent);
6448 mBroadcastWakeLock.release();
6449 }
6450
6451 void dispatchMediaKeyWithWakeLockToAudioService(KeyEvent event) {
Sudheer Shankafc46e9b2016-10-21 17:55:27 -07006452 if (mActivityManagerInternal.isSystemReady()) {
RoboErik430fc482014-06-12 15:49:20 -07006453 MediaSessionLegacyHelper.getHelper(mContext).sendMediaButtonEvent(event, true);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006454 }
6455 }
6456
Michael Wright869a67c2014-08-26 19:33:06 -07006457 void launchVoiceAssistWithWakeLock(boolean keyguardActive) {
Dianne Hackbornb6683c42015-06-18 17:40:33 -07006458 IDeviceIdleController dic = IDeviceIdleController.Stub.asInterface(
6459 ServiceManager.getService(Context.DEVICE_IDLE_CONTROLLER));
6460 if (dic != null) {
6461 try {
6462 dic.exitIdle("voice-search");
6463 } catch (RemoteException e) {
6464 }
6465 }
Michael Wright869a67c2014-08-26 19:33:06 -07006466 Intent voiceIntent =
6467 new Intent(RecognizerIntent.ACTION_VOICE_SEARCH_HANDS_FREE);
6468 voiceIntent.putExtra(RecognizerIntent.EXTRA_SECURE, keyguardActive);
Bart Sears8b1c27c2015-03-18 23:51:02 +00006469 startActivityAsUser(voiceIntent, UserHandle.CURRENT_OR_SELF);
Michael Wright869a67c2014-08-26 19:33:06 -07006470 mBroadcastWakeLock.release();
6471 }
6472
Mike Lockwood1753f7f2009-08-24 14:49:07 -07006473 BroadcastReceiver mDockReceiver = new BroadcastReceiver() {
Craig Mautnereee29c42013-01-17 14:44:34 -08006474 @Override
Mike Lockwood1753f7f2009-08-24 14:49:07 -07006475 public void onReceive(Context context, Intent intent) {
Dianne Hackborn867ab6472010-04-29 13:28:56 -07006476 if (Intent.ACTION_DOCK_EVENT.equals(intent.getAction())) {
6477 mDockMode = intent.getIntExtra(Intent.EXTRA_DOCK_STATE,
6478 Intent.EXTRA_DOCK_STATE_UNDOCKED);
Daniel Sandler6396c722013-04-16 20:19:09 -04006479 } else {
6480 try {
6481 IUiModeManager uiModeService = IUiModeManager.Stub.asInterface(
6482 ServiceManager.getService(Context.UI_MODE_SERVICE));
6483 mUiMode = uiModeService.getCurrentModeType();
6484 } catch (RemoteException e) {
6485 }
Dianne Hackborn80fa1662009-10-07 14:02:10 -07006486 }
Jeff Brown01a98dd2011-09-20 15:08:29 -07006487 updateRotation(true);
Craig Mautnereee29c42013-01-17 14:44:34 -08006488 synchronized (mLock) {
6489 updateOrientationListenerLp();
6490 }
Mike Lockwood1753f7f2009-08-24 14:49:07 -07006491 }
6492 };
6493
Jeff Brown6aaf2952012-10-05 16:01:08 -07006494 BroadcastReceiver mDreamReceiver = new BroadcastReceiver() {
6495 @Override
6496 public void onReceive(Context context, Intent intent) {
6497 if (Intent.ACTION_DREAMING_STARTED.equals(intent.getAction())) {
Jim Miller5ecd8112013-01-09 18:50:26 -08006498 if (mKeyguardDelegate != null) {
6499 mKeyguardDelegate.onDreamingStarted();
Jeff Brown6aaf2952012-10-05 16:01:08 -07006500 }
6501 } else if (Intent.ACTION_DREAMING_STOPPED.equals(intent.getAction())) {
Jim Miller5ecd8112013-01-09 18:50:26 -08006502 if (mKeyguardDelegate != null) {
6503 mKeyguardDelegate.onDreamingStopped();
Jeff Brown6aaf2952012-10-05 16:01:08 -07006504 }
6505 }
6506 }
6507 };
6508
Christopher Tate5e08af02012-09-21 17:17:22 -07006509 BroadcastReceiver mMultiuserReceiver = new BroadcastReceiver() {
6510 @Override
6511 public void onReceive(Context context, Intent intent) {
6512 if (Intent.ACTION_USER_SWITCHED.equals(intent.getAction())) {
6513 // tickle the settings observer: this first ensures that we're
6514 // observing the relevant settings for the newly-active user,
6515 // and then updates our own bookkeeping based on the now-
6516 // current user.
6517 mSettingsObserver.onChange(false);
John Spurlockce479d82012-11-29 09:52:21 -05006518
6519 // force a re-application of focused window sysui visibility.
6520 // the window may never have been shown for this user
6521 // e.g. the keyguard when going through the new-user setup flow
John Spurlock04db1762013-05-13 12:46:41 -04006522 synchronized (mWindowManagerFuncs.getWindowManagerLock()) {
John Spurlockce479d82012-11-29 09:52:21 -05006523 mLastSystemUiFlags = 0;
6524 updateSystemUiVisibilityLw();
6525 }
Christopher Tate5e08af02012-09-21 17:17:22 -07006526 }
6527 }
6528 };
6529
Adrian Roosddc8b272015-05-21 16:28:27 -07006530 private final Runnable mHiddenNavPanic = new Runnable() {
John Spurlockd9b70bd2014-02-06 17:02:44 -05006531 @Override
6532 public void run() {
Adrian Roosddc8b272015-05-21 16:28:27 -07006533 synchronized (mWindowManagerFuncs.getWindowManagerLock()) {
6534 if (!isUserSetupComplete()) {
6535 // Swipe-up for navigation bar is disabled during setup
6536 return;
6537 }
6538 mPendingPanicGestureUptime = SystemClock.uptimeMillis();
Adrian Roos1f425902016-07-22 10:37:50 -07006539 if (!isNavBarEmpty(mLastSystemUiFlags)) {
6540 mNavigationBarController.showTransient();
6541 }
Adrian Roosddc8b272015-05-21 16:28:27 -07006542 }
John Spurlockd9b70bd2014-02-06 17:02:44 -05006543 }
6544 };
6545
John Spurlocke1f366f2013-08-05 12:22:40 -04006546 private void requestTransientBars(WindowState swipeTarget) {
John Spurlock04db1762013-05-13 12:46:41 -04006547 synchronized (mWindowManagerFuncs.getWindowManagerLock()) {
Maurice Lam99c6e072014-04-28 18:24:28 -07006548 if (!isUserSetupComplete()) {
6549 // Swipe-up for navigation bar is disabled during setup
6550 return;
6551 }
John Spurlock27735a42013-08-14 17:57:38 -04006552 boolean sb = mStatusBarController.checkShowTransientBarLw();
Adrian Roos1f425902016-07-22 10:37:50 -07006553 boolean nb = mNavigationBarController.checkShowTransientBarLw()
6554 && !isNavBarEmpty(mLastSystemUiFlags);
John Spurlockad3e6cb2013-04-30 08:47:43 -04006555 if (sb || nb) {
Adrian Roos62b65e42015-02-25 18:05:34 +01006556 // Don't show status bar when swiping on already visible navigation bar
6557 if (!nb && swipeTarget == mNavigationBar) {
John Spurlocke1f366f2013-08-05 12:22:40 -04006558 if (DEBUG) Slog.d(TAG, "Not showing transient bar, wrong swipe target");
John Spurlockad3e6cb2013-04-30 08:47:43 -04006559 return;
6560 }
John Spurlock27735a42013-08-14 17:57:38 -04006561 if (sb) mStatusBarController.showTransient();
6562 if (nb) mNavigationBarController.showTransient();
John Spurlockf1a36642013-10-12 17:50:42 -04006563 mImmersiveModeConfirmation.confirmCurrentPrompt();
John Spurlockad3e6cb2013-04-30 08:47:43 -04006564 updateSystemUiVisibilityLw();
John Spurlock32beb2c2013-03-11 10:16:47 -04006565 }
John Spurlockad3e6cb2013-04-30 08:47:43 -04006566 }
6567 }
6568
Jeff Brown3ee549c2014-09-22 20:14:39 -07006569 // Called on the PowerManager's Notifier thread.
Jeff Brownc38c9be2012-10-04 13:16:19 -07006570 @Override
Jeff Brown416c49c2015-05-26 19:50:18 -07006571 public void startedGoingToSleep(int why) {
6572 if (DEBUG_WAKEUP) Slog.i(TAG, "Started going to sleep... (why=" + why + ")");
Selim Cinekab55ba52017-08-02 16:45:51 -07006573
Jorim Jaggif1cdf952016-04-05 21:41:06 -07006574 mGoingToSleep = true;
Selim Cinekab55ba52017-08-02 16:45:51 -07006575 mRequestedOrGoingToSleep = true;
6576
Jorim Jaggid175b6c2015-05-27 15:39:09 -07006577 if (mKeyguardDelegate != null) {
6578 mKeyguardDelegate.onStartedGoingToSleep(why);
6579 }
Jeff Brown416c49c2015-05-26 19:50:18 -07006580 }
6581
6582 // Called on the PowerManager's Notifier thread.
6583 @Override
6584 public void finishedGoingToSleep(int why) {
Dianne Hackborn74489012009-03-24 20:50:09 -07006585 EventLog.writeEvent(70000, 0);
Jeff Brown416c49c2015-05-26 19:50:18 -07006586 if (DEBUG_WAKEUP) Slog.i(TAG, "Finished going to sleep... (why=" + why + ")");
Chris Wren9bb290b2015-06-29 12:02:13 -04006587 MetricsLogger.histogram(mContext, "screen_timeout", mLockScreenTimeout / 1000);
Jeff Brown3ee549c2014-09-22 20:14:39 -07006588
Jorim Jaggif1cdf952016-04-05 21:41:06 -07006589 mGoingToSleep = false;
Selim Cinekab55ba52017-08-02 16:45:51 -07006590 mRequestedOrGoingToSleep = false;
Jorim Jaggif1cdf952016-04-05 21:41:06 -07006591
Jeff Brown3ee549c2014-09-22 20:14:39 -07006592 // We must get this work done here because the power manager will drop
6593 // the wake lock and let the system suspend once this function returns.
The Android Open Source Project0727d222009-03-11 12:11:58 -07006594 synchronized (mLock) {
Jeff Brown3ee549c2014-09-22 20:14:39 -07006595 mAwake = false;
Jeff Browna20dda42014-05-27 20:57:24 -07006596 updateWakeGestureListenerLp();
The Android Open Source Project0727d222009-03-11 12:11:58 -07006597 updateOrientationListenerLp();
Mike Lockwood28569302010-01-28 11:54:40 -05006598 updateLockScreenTimeout();
The Android Open Source Project0727d222009-03-11 12:11:58 -07006599 }
Jeff Brown3ee549c2014-09-22 20:14:39 -07006600 if (mKeyguardDelegate != null) {
Jorim Jaggif1cdf952016-04-05 21:41:06 -07006601 mKeyguardDelegate.onFinishedGoingToSleep(why,
6602 mCameraGestureTriggeredDuringGoingToSleep);
Jeff Brown3ee549c2014-09-22 20:14:39 -07006603 }
Jorim Jaggif1cdf952016-04-05 21:41:06 -07006604 mCameraGestureTriggeredDuringGoingToSleep = false;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006605 }
6606
Jeff Brown3ee549c2014-09-22 20:14:39 -07006607 // Called on the PowerManager's Notifier thread.
Jeff Brownc38c9be2012-10-04 13:16:19 -07006608 @Override
Jeff Brown416c49c2015-05-26 19:50:18 -07006609 public void startedWakingUp() {
Dianne Hackborn74489012009-03-24 20:50:09 -07006610 EventLog.writeEvent(70000, 1);
Jeff Brown416c49c2015-05-26 19:50:18 -07006611 if (DEBUG_WAKEUP) Slog.i(TAG, "Started waking up...");
Craig Mautner8a0da012014-05-31 15:13:37 -07006612
Jeff Brown3ee549c2014-09-22 20:14:39 -07006613 // Since goToSleep performs these functions synchronously, we must
6614 // do the same here. We cannot post this work to a handler because
6615 // that might cause it to become reordered with respect to what
6616 // may happen in a future call to goToSleep.
The Android Open Source Project0727d222009-03-11 12:11:58 -07006617 synchronized (mLock) {
Jeff Brown3ee549c2014-09-22 20:14:39 -07006618 mAwake = true;
Jeff Brown3ee549c2014-09-22 20:14:39 -07006619
Jeff Browna20dda42014-05-27 20:57:24 -07006620 updateWakeGestureListenerLp();
The Android Open Source Project0727d222009-03-11 12:11:58 -07006621 updateOrientationListenerLp();
Mike Lockwood28569302010-01-28 11:54:40 -05006622 updateLockScreenTimeout();
The Android Open Source Project0727d222009-03-11 12:11:58 -07006623 }
Jeff Brownc38c9be2012-10-04 13:16:19 -07006624
Jim Miller5ecd8112013-01-09 18:50:26 -08006625 if (mKeyguardDelegate != null) {
Jorim Jaggi4cfdcf52015-07-09 12:13:59 -07006626 mKeyguardDelegate.onStartedWakingUp();
Jeff Brownc38c9be2012-10-04 13:16:19 -07006627 }
Jeff Brown36c4db82014-09-19 12:05:31 -07006628 }
6629
Jeff Brown416c49c2015-05-26 19:50:18 -07006630 // Called on the PowerManager's Notifier thread.
6631 @Override
6632 public void finishedWakingUp() {
6633 if (DEBUG_WAKEUP) Slog.i(TAG, "Finished waking up...");
Adrian Roos369907f2017-07-14 14:53:39 +02006634
6635 if (mKeyguardDelegate != null) {
6636 mKeyguardDelegate.onFinishedWakingUp();
6637 }
Jeff Brown416c49c2015-05-26 19:50:18 -07006638 }
6639
6640 private void wakeUpFromPowerKey(long eventTime) {
Dianne Hackborn280a64e2015-07-13 14:48:08 -07006641 wakeUp(eventTime, mAllowTheaterModeWakeFromPowerKey, "android.policy:POWER");
Jeff Brown416c49c2015-05-26 19:50:18 -07006642 }
6643
Dianne Hackborn280a64e2015-07-13 14:48:08 -07006644 private boolean wakeUp(long wakeTime, boolean wakeInTheaterMode, String reason) {
Bryce Leed3896842015-06-23 17:06:51 -07006645 final boolean theaterModeEnabled = isTheaterModeEnabled();
6646 if (!wakeInTheaterMode && theaterModeEnabled) {
Jeff Brown416c49c2015-05-26 19:50:18 -07006647 return false;
6648 }
6649
Bryce Leed3896842015-06-23 17:06:51 -07006650 if (theaterModeEnabled) {
6651 Settings.Global.putInt(mContext.getContentResolver(),
6652 Settings.Global.THEATER_MODE_ON, 0);
6653 }
6654
Dianne Hackborn280a64e2015-07-13 14:48:08 -07006655 mPowerManager.wakeUp(wakeTime, reason);
Jeff Brown416c49c2015-05-26 19:50:18 -07006656 return true;
6657 }
6658
Jeff Brown36c4db82014-09-19 12:05:31 -07006659 private void finishKeyguardDrawn() {
Jeff Brown3ee549c2014-09-22 20:14:39 -07006660 synchronized (mLock) {
Jorim Jaggif3255482015-07-24 12:32:42 -07006661 if (!mScreenOnEarly || mKeyguardDrawComplete) {
Stefan Kuhne9326dc12015-06-12 09:25:32 -10006662 return; // We are not awake yet or we have already informed of this event.
Jeff Brown3ee549c2014-09-22 20:14:39 -07006663 }
6664
Jeff Brown36c4db82014-09-19 12:05:31 -07006665 mKeyguardDrawComplete = true;
Jeff Brown3ee549c2014-09-22 20:14:39 -07006666 if (mKeyguardDelegate != null) {
6667 mHandler.removeMessages(MSG_KEYGUARD_DRAWN_TIMEOUT);
6668 }
Jorim Jaggi4cfdcf52015-07-09 12:13:59 -07006669 mWindowManagerDrawComplete = false;
Jeff Brown3ee549c2014-09-22 20:14:39 -07006670 }
6671
Jorim Jaggi4cfdcf52015-07-09 12:13:59 -07006672 // ... eventually calls finishWindowsDrawn which will finalize our screen turn on
6673 // as well as enabling the orientation change logic/sensor.
6674 mWindowManagerInternal.waitForAllWindowsDrawn(mWindowManagerDrawCallback,
6675 WAITING_FOR_DRAWN_TIMEOUT);
Jeff Brown3ee549c2014-09-22 20:14:39 -07006676 }
6677
6678 // Called on the DisplayManager's DisplayPowerController thread.
6679 @Override
6680 public void screenTurnedOff() {
6681 if (DEBUG_WAKEUP) Slog.i(TAG, "Screen turned off...");
6682
Jeff Brown48d1b142015-06-10 16:36:03 -07006683 updateScreenOffSleepToken(true);
Jeff Brown3ee549c2014-09-22 20:14:39 -07006684 synchronized (mLock) {
6685 mScreenOnEarly = false;
6686 mScreenOnFully = false;
Jorim Jaggi95c6dae2015-07-29 15:17:23 -07006687 mKeyguardDrawComplete = false;
Jeff Brown3ee549c2014-09-22 20:14:39 -07006688 mWindowManagerDrawComplete = false;
6689 mScreenOnListener = null;
6690 updateOrientationListenerLp();
Jorim Jaggi0d210f62015-07-10 14:24:44 -07006691
6692 if (mKeyguardDelegate != null) {
6693 mKeyguardDelegate.onScreenTurnedOff();
6694 }
Jeff Brown36c4db82014-09-19 12:05:31 -07006695 }
Ruben Brunkfecb6152016-10-28 20:18:57 -07006696 reportScreenStateToVrManager(false);
Jeff Brown36c4db82014-09-19 12:05:31 -07006697 }
6698
Keun-young Park4136d2d2017-05-08 14:51:59 -07006699 private long getKeyguardDrawnTimeout() {
6700 final boolean bootCompleted =
6701 LocalServices.getService(SystemServiceManager.class).isBootCompleted();
6702 // Set longer timeout if it has not booted yet to prevent showing empty window.
6703 return bootCompleted ? 1000 : 5000;
6704 }
6705
Jeff Brown3ee549c2014-09-22 20:14:39 -07006706 // Called on the DisplayManager's DisplayPowerController thread.
Jeff Brown36c4db82014-09-19 12:05:31 -07006707 @Override
6708 public void screenTurningOn(final ScreenOnListener screenOnListener) {
Jeff Brown36c4db82014-09-19 12:05:31 -07006709 if (DEBUG_WAKEUP) Slog.i(TAG, "Screen turning on...");
Jeff Brown36c4db82014-09-19 12:05:31 -07006710
Jeff Brown48d1b142015-06-10 16:36:03 -07006711 updateScreenOffSleepToken(false);
Jeff Brown3ee549c2014-09-22 20:14:39 -07006712 synchronized (mLock) {
6713 mScreenOnEarly = true;
6714 mScreenOnFully = false;
Jorim Jaggi95c6dae2015-07-29 15:17:23 -07006715 mKeyguardDrawComplete = false;
Jeff Brown3ee549c2014-09-22 20:14:39 -07006716 mWindowManagerDrawComplete = false;
6717 mScreenOnListener = screenOnListener;
Jeff Brown36c4db82014-09-19 12:05:31 -07006718
Jorim Jaggi4cfdcf52015-07-09 12:13:59 -07006719 if (mKeyguardDelegate != null) {
Jorim Jaggia4b51bc2015-08-10 18:20:43 -07006720 mHandler.removeMessages(MSG_KEYGUARD_DRAWN_TIMEOUT);
Keun-young Park4136d2d2017-05-08 14:51:59 -07006721 mHandler.sendEmptyMessageDelayed(MSG_KEYGUARD_DRAWN_TIMEOUT,
6722 getKeyguardDrawnTimeout());
Jorim Jaggi4cfdcf52015-07-09 12:13:59 -07006723 mKeyguardDelegate.onScreenTurningOn(mKeyguardDrawnCallback);
6724 } else {
6725 if (DEBUG_WAKEUP) Slog.d(TAG,
6726 "null mKeyguardDelegate: setting mKeyguardDrawComplete.");
6727 finishKeyguardDrawn();
6728 }
6729 }
Jeff Brown36c4db82014-09-19 12:05:31 -07006730 }
6731
Jorim Jaggi0d210f62015-07-10 14:24:44 -07006732 // Called on the DisplayManager's DisplayPowerController thread.
6733 @Override
6734 public void screenTurnedOn() {
6735 synchronized (mLock) {
6736 if (mKeyguardDelegate != null) {
6737 mKeyguardDelegate.onScreenTurnedOn();
6738 }
6739 }
Ruben Brunkfecb6152016-10-28 20:18:57 -07006740 reportScreenStateToVrManager(true);
6741 }
6742
Jorim Jaggi51304d72017-05-17 17:25:32 +02006743 @Override
6744 public void screenTurningOff(ScreenOffListener screenOffListener) {
6745 mWindowManagerFuncs.screenTurningOff(screenOffListener);
Adrian Roos369907f2017-07-14 14:53:39 +02006746 synchronized (mLock) {
6747 if (mKeyguardDelegate != null) {
6748 mKeyguardDelegate.onScreenTurningOff();
6749 }
6750 }
Jorim Jaggi51304d72017-05-17 17:25:32 +02006751 }
6752
Ruben Brunkfecb6152016-10-28 20:18:57 -07006753 private void reportScreenStateToVrManager(boolean isScreenOn) {
Zak Cohen732aeb02017-01-29 14:19:52 -08006754 if (mVrManagerInternal == null) {
Ruben Brunkfecb6152016-10-28 20:18:57 -07006755 return;
6756 }
Zak Cohen732aeb02017-01-29 14:19:52 -08006757 mVrManagerInternal.onScreenStateChanged(isScreenOn);
6758 }
6759
Jeff Brown36c4db82014-09-19 12:05:31 -07006760 private void finishWindowsDrawn() {
Jeff Brown3ee549c2014-09-22 20:14:39 -07006761 synchronized (mLock) {
6762 if (!mScreenOnEarly || mWindowManagerDrawComplete) {
Stefan Kuhne9326dc12015-06-12 09:25:32 -10006763 return; // Screen is not turned on or we did already handle this case earlier.
Jeff Brown3ee549c2014-09-22 20:14:39 -07006764 }
6765
Jeff Brown36c4db82014-09-19 12:05:31 -07006766 mWindowManagerDrawComplete = true;
Jeff Brown36c4db82014-09-19 12:05:31 -07006767 }
Jeff Brown3ee549c2014-09-22 20:14:39 -07006768
6769 finishScreenTurningOn();
Jeff Brownc38c9be2012-10-04 13:16:19 -07006770 }
6771
Craig Mautner8a0da012014-05-31 15:13:37 -07006772 private void finishScreenTurningOn() {
Stefan Kuhne9326dc12015-06-12 09:25:32 -10006773 synchronized (mLock) {
6774 // We have just finished drawing screen content. Since the orientation listener
6775 // gets only installed when all windows are drawn, we try to install it again.
6776 updateOrientationListenerLp();
6777 }
Jeff Brown3ee549c2014-09-22 20:14:39 -07006778 final ScreenOnListener listener;
6779 final boolean enableScreen;
Jeff Brown36c4db82014-09-19 12:05:31 -07006780 synchronized (mLock) {
Jeff Brown3ee549c2014-09-22 20:14:39 -07006781 if (DEBUG_WAKEUP) Slog.d(TAG,
6782 "finishScreenTurningOn: mAwake=" + mAwake
6783 + ", mScreenOnEarly=" + mScreenOnEarly
6784 + ", mScreenOnFully=" + mScreenOnFully
6785 + ", mKeyguardDrawComplete=" + mKeyguardDrawComplete
6786 + ", mWindowManagerDrawComplete=" + mWindowManagerDrawComplete);
6787
6788 if (mScreenOnFully || !mScreenOnEarly || !mWindowManagerDrawComplete
6789 || (mAwake && !mKeyguardDrawComplete)) {
6790 return; // spurious or not ready yet
Jeff Brown36c4db82014-09-19 12:05:31 -07006791 }
6792
Jeff Brown3ee549c2014-09-22 20:14:39 -07006793 if (DEBUG_WAKEUP) Slog.i(TAG, "Finished screen turning on...");
6794 listener = mScreenOnListener;
Craig Mautner13f6ea72014-06-23 14:57:02 -07006795 mScreenOnListener = null;
Jeff Brown3ee549c2014-09-22 20:14:39 -07006796 mScreenOnFully = true;
6797
6798 // Remember the first time we draw the keyguard so we know when we're done with
6799 // the main part of booting and can enable the screen and hide boot messages.
6800 if (!mKeyguardDrawnOnce && mAwake) {
6801 mKeyguardDrawnOnce = true;
6802 enableScreen = true;
6803 if (mBootMessageNeedsHiding) {
6804 mBootMessageNeedsHiding = false;
6805 hideBootMessages();
6806 }
6807 } else {
6808 enableScreen = false;
6809 }
Jeff Brownc38c9be2012-10-04 13:16:19 -07006810 }
6811
Jeff Brown3ee549c2014-09-22 20:14:39 -07006812 if (listener != null) {
6813 listener.onScreenOn();
6814 }
Jeff Brown4fc45272012-10-10 18:28:14 -07006815
Jeff Brown3ee549c2014-09-22 20:14:39 -07006816 if (enableScreen) {
6817 try {
6818 mWindowManager.enableScreenIfNeeded();
6819 } catch (RemoteException unhandled) {
Jeff Brown36c4db82014-09-19 12:05:31 -07006820 }
Craig Mautnera631d492014-08-05 15:16:01 -07006821 }
6822 }
6823
6824 private void handleHideBootMessage() {
Jeff Brown3ee549c2014-09-22 20:14:39 -07006825 synchronized (mLock) {
6826 if (!mKeyguardDrawnOnce) {
6827 mBootMessageNeedsHiding = true;
6828 return; // keyguard hasn't drawn the first time yet, not done booting
6829 }
Craig Mautnera631d492014-08-05 15:16:01 -07006830 }
Jeff Brown3ee549c2014-09-22 20:14:39 -07006831
6832 if (mBootMsgDialog != null) {
6833 if (DEBUG_WAKEUP) Slog.d(TAG, "handleHideBootMessage: dismissing");
6834 mBootMsgDialog.dismiss();
6835 mBootMsgDialog = null;
Craig Mautnera631d492014-08-05 15:16:01 -07006836 }
Jeff Brownc38c9be2012-10-04 13:16:19 -07006837 }
6838
6839 @Override
Jeff Brown3ee549c2014-09-22 20:14:39 -07006840 public boolean isScreenOn() {
Jorim Jaggi67b29d52017-06-09 18:00:00 -07006841 synchronized (mLock) {
6842 return mScreenOnEarly;
6843 }
Dianne Hackborn08743722009-12-21 12:16:51 -08006844 }
Jeff Brownc38c9be2012-10-04 13:16:19 -07006845
Adrian Roose94c15c2017-05-09 13:17:54 -07006846 @Override
Adrian Roos7c894802017-07-19 12:25:34 +02006847 public boolean okToAnimate() {
6848 return mAwake && !mGoingToSleep;
Adrian Roose94c15c2017-05-09 13:17:54 -07006849 }
6850
Dianne Hackborn08743722009-12-21 12:16:51 -08006851 /** {@inheritDoc} */
Jose Lima9546b202014-07-02 17:21:51 -07006852 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006853 public void enableKeyguard(boolean enabled) {
Jim Miller5ecd8112013-01-09 18:50:26 -08006854 if (mKeyguardDelegate != null) {
6855 mKeyguardDelegate.setKeyguardEnabled(enabled);
Mike Lockwood3a74bd32011-08-12 13:55:22 -07006856 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006857 }
6858
6859 /** {@inheritDoc} */
Jose Lima9546b202014-07-02 17:21:51 -07006860 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006861 public void exitKeyguardSecurely(OnKeyguardExitResult callback) {
Jim Miller5ecd8112013-01-09 18:50:26 -08006862 if (mKeyguardDelegate != null) {
6863 mKeyguardDelegate.verifyUnlock(callback);
Mike Lockwood3a74bd32011-08-12 13:55:22 -07006864 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006865 }
6866
Tony Mak2c0d6dc2016-04-29 16:16:54 +01006867 @Override
6868 public boolean isKeyguardShowingAndNotOccluded() {
Jim Miller5ecd8112013-01-09 18:50:26 -08006869 if (mKeyguardDelegate == null) return false;
Jim Millerab954542014-10-10 18:21:49 -07006870 return mKeyguardDelegate.isShowing() && !mKeyguardOccluded;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006871 }
6872
Jorim Jaggife762342016-10-13 14:33:27 +02006873 @Override
6874 public boolean isKeyguardTrustedLw() {
6875 if (mKeyguardDelegate == null) return false;
6876 return mKeyguardDelegate.isTrusted();
6877 }
6878
Mike Lockwood520d8bc2011-02-18 13:23:13 -05006879 /** {@inheritDoc} */
Jose Lima9546b202014-07-02 17:21:51 -07006880 @Override
Mike Lockwood520d8bc2011-02-18 13:23:13 -05006881 public boolean isKeyguardLocked() {
6882 return keyguardOn();
6883 }
6884
6885 /** {@inheritDoc} */
Jose Lima9546b202014-07-02 17:21:51 -07006886 @Override
Jim Millere4044bb2016-05-10 18:38:25 -07006887 public boolean isKeyguardSecure(int userId) {
Jim Miller5ecd8112013-01-09 18:50:26 -08006888 if (mKeyguardDelegate == null) return false;
Jim Millere4044bb2016-05-10 18:38:25 -07006889 return mKeyguardDelegate.isSecure(userId);
Mike Lockwood520d8bc2011-02-18 13:23:13 -05006890 }
6891
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006892 /** {@inheritDoc} */
Jose Lima9546b202014-07-02 17:21:51 -07006893 @Override
Jorim Jaggife762342016-10-13 14:33:27 +02006894 public boolean isKeyguardOccluded() {
6895 if (mKeyguardDelegate == null) return false;
6896 return mKeyguardOccluded;
Adrian Roos461829d2015-06-03 14:41:18 -07006897 }
6898
6899 /** {@inheritDoc} */
6900 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006901 public boolean inKeyguardRestrictedKeyInputMode() {
Jim Miller5ecd8112013-01-09 18:50:26 -08006902 if (mKeyguardDelegate == null) return false;
6903 return mKeyguardDelegate.isInputRestricted();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006904 }
6905
Jose Lima9546b202014-07-02 17:21:51 -07006906 @Override
Jorim Jaggi241ae102016-11-02 21:57:33 -07006907 public void dismissKeyguardLw(IKeyguardDismissCallback callback) {
RoboErik8a2cfc32014-05-16 11:19:38 -07006908 if (mKeyguardDelegate != null && mKeyguardDelegate.isShowing()) {
Craig Mautnerc0d2d0a2014-10-31 16:25:15 -07006909 if (DEBUG_KEYGUARD) Slog.d(TAG, "PWM.dismissKeyguardLw");
Jorim Jaggi8d786932016-10-26 19:08:36 -07006910
6911 // ask the keyguard to prompt the user to authenticate if necessary
Jorim Jaggi241ae102016-11-02 21:57:33 -07006912 mKeyguardDelegate.dismiss(callback);
6913 } else if (callback != null) {
6914 try {
6915 callback.onDismissError();
6916 } catch (RemoteException e) {
6917 Slog.w(TAG, "Failed to call callback", e);
6918 }
Dianne Hackborn90c52de2011-09-23 12:57:44 -07006919 }
6920 }
6921
Jorim Jaggicff0acb2014-03-31 16:35:15 +02006922 @Override
6923 public boolean isKeyguardDrawnLw() {
6924 synchronized (mLock) {
Jeff Brown3ee549c2014-09-22 20:14:39 -07006925 return mKeyguardDrawnOnce;
Jorim Jaggicff0acb2014-03-31 16:35:15 +02006926 }
6927 }
6928
Jorim Jaggi0d674622014-05-21 01:34:15 +02006929 @Override
Jorim Jaggi77e10432016-10-26 17:43:56 -07006930 public boolean isShowingDreamLw() {
6931 return mShowingDream;
6932 }
6933
6934 @Override
Jorim Jaggie29b2db2014-05-30 23:17:03 +02006935 public void startKeyguardExitAnimation(long startTime, long fadeoutDuration) {
Jorim Jaggi0d674622014-05-21 01:34:15 +02006936 if (mKeyguardDelegate != null) {
Craig Mautnerc0d2d0a2014-10-31 16:25:15 -07006937 if (DEBUG_KEYGUARD) Slog.d(TAG, "PWM.startKeyguardExitAnimation");
Jorim Jaggie29b2db2014-05-30 23:17:03 +02006938 mKeyguardDelegate.startKeyguardExitAnimation(startTime, fadeoutDuration);
Jorim Jaggi0d674622014-05-21 01:34:15 +02006939 }
6940 }
6941
Jorim Jaggi737af722015-12-31 10:42:27 +01006942 @Override
6943 public void getStableInsetsLw(int displayRotation, int displayWidth, int displayHeight,
6944 Rect outInsets) {
6945 outInsets.setEmpty();
Jorim Jaggi82c9dc92016-02-05 15:10:33 -08006946
6947 // Navigation bar and status bar.
6948 getNonDecorInsetsLw(displayRotation, displayWidth, displayHeight, outInsets);
Matthew Ngca4c1a32016-12-13 16:55:09 -08006949 outInsets.top = mStatusBarHeight;
Jorim Jaggi82c9dc92016-02-05 15:10:33 -08006950 }
6951
6952 @Override
6953 public void getNonDecorInsetsLw(int displayRotation, int displayWidth, int displayHeight,
6954 Rect outInsets) {
6955 outInsets.setEmpty();
6956
6957 // Only navigation bar
Matthew Ngca4c1a32016-12-13 16:55:09 -08006958 if (mHasNavigationBar) {
Adrian Roos85d202b2016-06-02 16:27:47 -07006959 int position = navigationBarPosition(displayWidth, displayHeight, displayRotation);
6960 if (position == NAV_BAR_BOTTOM) {
Jorim Jaggi737af722015-12-31 10:42:27 +01006961 outInsets.bottom = getNavigationBarHeight(displayRotation, mUiMode);
Adrian Roos85d202b2016-06-02 16:27:47 -07006962 } else if (position == NAV_BAR_RIGHT) {
Jorim Jaggi737af722015-12-31 10:42:27 +01006963 outInsets.right = getNavigationBarWidth(displayRotation, mUiMode);
Adrian Roos85d202b2016-06-02 16:27:47 -07006964 } else if (position == NAV_BAR_LEFT) {
6965 outInsets.left = getNavigationBarWidth(displayRotation, mUiMode);
Jorim Jaggi737af722015-12-31 10:42:27 +01006966 }
6967 }
6968 }
6969
Jorim Jaggi5060bd82016-02-19 17:12:19 -08006970 @Override
Jorim Jaggi0ffd49c2016-02-12 15:04:21 -08006971 public boolean isNavBarForcedShownLw(WindowState windowState) {
Jorim Jaggie5638a62016-03-25 22:57:01 -07006972 return mForceShowSystemBars;
Jorim Jaggi0ffd49c2016-02-12 15:04:21 -08006973 }
6974
6975 @Override
Andrii Kulian3a1619d2017-07-07 14:38:09 -07006976 public int getNavBarPosition() {
6977 // TODO(multi-display): Support system decor on secondary displays.
6978 return mNavigationBarPosition;
6979 }
6980
6981 @Override
Jorim Jaggi5060bd82016-02-19 17:12:19 -08006982 public boolean isDockSideAllowed(int dockSide) {
6983
6984 // We do not allow all dock sides at which the navigation bar touches the docked stack.
6985 if (!mNavigationBarCanMove) {
6986 return dockSide == DOCKED_TOP || dockSide == DOCKED_LEFT || dockSide == DOCKED_RIGHT;
6987 } else {
6988 return dockSide == DOCKED_TOP || dockSide == DOCKED_LEFT;
6989 }
6990 }
6991
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006992 void sendCloseSystemWindows() {
Jorim Jaggib10e33f2015-02-04 21:57:40 +01006993 PhoneWindow.sendCloseSystemWindows(mContext, null);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006994 }
6995
6996 void sendCloseSystemWindows(String reason) {
Jorim Jaggib10e33f2015-02-04 21:57:40 +01006997 PhoneWindow.sendCloseSystemWindows(mContext, reason);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006998 }
Mitsuru Oshima831d0d92009-06-16 18:27:18 -07006999
Jeff Brown01a98dd2011-09-20 15:08:29 -07007000 @Override
7001 public int rotationForOrientationLw(int orientation, int lastRotation) {
Daniel Sandler2ed6ad62011-02-22 14:54:17 -05007002 if (false) {
7003 Slog.v(TAG, "rotationForOrientationLw(orient="
7004 + orientation + ", last=" + lastRotation
7005 + "); user=" + mUserRotation + " "
7006 + ((mUserRotationMode == WindowManagerPolicy.USER_ROTATION_LOCKED)
7007 ? "USER_ROTATION_LOCKED" : "")
7008 );
7009 }
7010
Craig Mautner46ac6fa2013-08-01 10:06:34 -07007011 if (mForceDefaultOrientation) {
7012 return Surface.ROTATION_0;
7013 }
7014
The Android Open Source Project0727d222009-03-11 12:11:58 -07007015 synchronized (mLock) {
Jeff Brownc0347aa2011-09-23 17:26:09 -07007016 int sensorRotation = mOrientationListener.getProposedRotation(); // may be -1
7017 if (sensorRotation < 0) {
Jeff Brown0f862b42012-09-27 21:11:01 -07007018 sensorRotation = lastRotation;
Jeff Brownc0347aa2011-09-23 17:26:09 -07007019 }
Jeff Brown01a98dd2011-09-20 15:08:29 -07007020
Jeff Browndec6cf42011-11-15 14:08:20 -08007021 final int preferredRotation;
Jeff Brown2e7760e2012-04-11 15:14:55 -07007022 if (mLidState == LID_OPEN && mLidOpenRotation >= 0) {
Jeff Brown01a98dd2011-09-20 15:08:29 -07007023 // Ignore sensor when lid switch is open and rotation is forced.
7024 preferredRotation = mLidOpenRotation;
7025 } else if (mDockMode == Intent.EXTRA_DOCK_STATE_CAR
Jeff Brownc0347aa2011-09-23 17:26:09 -07007026 && (mCarDockEnablesAccelerometer || mCarDockRotation >= 0)) {
Jeff Brown01a98dd2011-09-20 15:08:29 -07007027 // Ignore sensor when in car dock unless explicitly enabled.
7028 // This case can override the behavior of NOSENSOR, and can also
7029 // enable 180 degree rotation while docked.
Jeff Brownc0347aa2011-09-23 17:26:09 -07007030 preferredRotation = mCarDockEnablesAccelerometer
Jeff Brown01a98dd2011-09-20 15:08:29 -07007031 ? sensorRotation : mCarDockRotation;
Jeff Brown1a693182011-11-08 14:44:16 -08007032 } else if ((mDockMode == Intent.EXTRA_DOCK_STATE_DESK
7033 || mDockMode == Intent.EXTRA_DOCK_STATE_LE_DESK
7034 || mDockMode == Intent.EXTRA_DOCK_STATE_HE_DESK)
Jeff Brownc0347aa2011-09-23 17:26:09 -07007035 && (mDeskDockEnablesAccelerometer || mDeskDockRotation >= 0)) {
Jeff Brown01a98dd2011-09-20 15:08:29 -07007036 // Ignore sensor when in desk dock unless explicitly enabled.
7037 // This case can override the behavior of NOSENSOR, and can also
7038 // enable 180 degree rotation while docked.
Jeff Brownc0347aa2011-09-23 17:26:09 -07007039 preferredRotation = mDeskDockEnablesAccelerometer
Jeff Brown01a98dd2011-09-20 15:08:29 -07007040 ? sensorRotation : mDeskDockRotation;
Jeff Brownc82c89ed2013-04-17 17:18:15 -07007041 } else if (mHdmiPlugged && mDemoHdmiRotationLock) {
7042 // Ignore sensor when plugged into HDMI when demo HDMI rotation lock enabled.
Jeff Browneb3e4b92011-12-06 19:54:24 -08007043 // Note that the dock orientation overrides the HDMI orientation.
Jeff Brownc82c89ed2013-04-17 17:18:15 -07007044 preferredRotation = mDemoHdmiRotation;
7045 } else if (mHdmiPlugged && mDockMode == Intent.EXTRA_DOCK_STATE_UNDOCKED
7046 && mUndockedHdmiRotation >= 0) {
7047 // Ignore sensor when plugged into HDMI and an undocked orientation has
7048 // been specified in the configuration (only for legacy devices without
7049 // full multi-display support).
7050 // Note that the dock orientation overrides the HDMI orientation.
7051 preferredRotation = mUndockedHdmiRotation;
Chong Zhangae6119ff2014-11-11 18:54:39 -08007052 } else if (mDemoRotationLock) {
7053 // Ignore sensor when demo rotation lock is enabled.
7054 // Note that the dock orientation and HDMI rotation lock override this.
7055 preferredRotation = mDemoRotation;
Santos Cordon0b5d9692017-07-21 12:08:53 -07007056 } else if (mPersistentVrModeEnabled) {
7057 // While in VR, apps always prefer a portrait rotation. This does not change
7058 // any apps that explicitly set landscape, but does cause sensors be ignored,
7059 // and ignored any orientation lock that the user has set (this conditional
7060 // should remain above the ORIENTATION_LOCKED conditional below).
7061 preferredRotation = mPortraitRotation;
Dianne Hackbornb9ec1ac2013-04-10 17:34:25 -07007062 } else if (orientation == ActivityInfo.SCREEN_ORIENTATION_LOCKED) {
7063 // Application just wants to remain locked in the last rotation.
7064 preferredRotation = lastRotation;
Jeff Brownbcdfc622014-03-06 19:13:04 -08007065 } else if (!mSupportAutoRotation) {
7066 // If we don't support auto-rotation then bail out here and ignore
7067 // the sensor and any rotation lock settings.
7068 preferredRotation = -1;
Jeff Brown207673cd2012-06-05 17:47:11 -07007069 } else if ((mUserRotationMode == WindowManagerPolicy.USER_ROTATION_FREE
Jeff Brown01a98dd2011-09-20 15:08:29 -07007070 && (orientation == ActivityInfo.SCREEN_ORIENTATION_USER
Dianne Hackbornb9ec1ac2013-04-10 17:34:25 -07007071 || orientation == ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED
7072 || orientation == ActivityInfo.SCREEN_ORIENTATION_USER_LANDSCAPE
7073 || orientation == ActivityInfo.SCREEN_ORIENTATION_USER_PORTRAIT
7074 || orientation == ActivityInfo.SCREEN_ORIENTATION_FULL_USER))
Jeff Brown01a98dd2011-09-20 15:08:29 -07007075 || orientation == ActivityInfo.SCREEN_ORIENTATION_SENSOR
7076 || orientation == ActivityInfo.SCREEN_ORIENTATION_FULL_SENSOR
7077 || orientation == ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE
7078 || orientation == ActivityInfo.SCREEN_ORIENTATION_SENSOR_PORTRAIT) {
7079 // Otherwise, use sensor only if requested by the application or enabled
7080 // by default for USER or UNSPECIFIED modes. Does not apply to NOSENSOR.
Jeff Brownd3187e32011-09-21 19:26:44 -07007081 if (mAllowAllRotations < 0) {
7082 // Can't read this during init() because the context doesn't
7083 // have display metrics at that time so we cannot determine
7084 // tablet vs. phone then.
7085 mAllowAllRotations = mContext.getResources().getBoolean(
7086 com.android.internal.R.bool.config_allowAllRotations) ? 1 : 0;
7087 }
Jeff Brown01a98dd2011-09-20 15:08:29 -07007088 if (sensorRotation != Surface.ROTATION_180
Jeff Brownd3187e32011-09-21 19:26:44 -07007089 || mAllowAllRotations == 1
Dianne Hackbornb9ec1ac2013-04-10 17:34:25 -07007090 || orientation == ActivityInfo.SCREEN_ORIENTATION_FULL_SENSOR
7091 || orientation == ActivityInfo.SCREEN_ORIENTATION_FULL_USER) {
Santos Cordon0b5d9692017-07-21 12:08:53 -07007092 preferredRotation = sensorRotation;
Jeff Brown01a98dd2011-09-20 15:08:29 -07007093 } else {
7094 preferredRotation = lastRotation;
7095 }
Jeff Brown207673cd2012-06-05 17:47:11 -07007096 } else if (mUserRotationMode == WindowManagerPolicy.USER_ROTATION_LOCKED
7097 && orientation != ActivityInfo.SCREEN_ORIENTATION_NOSENSOR) {
7098 // Apply rotation lock. Does not apply to NOSENSOR.
7099 // The idea is that the user rotation expresses a weak preference for the direction
7100 // of gravity and as NOSENSOR is never affected by gravity, then neither should
7101 // NOSENSOR be affected by rotation lock (although it will be affected by docks).
Jeff Brown4dfce202011-10-05 12:00:10 -07007102 preferredRotation = mUserRotation;
Jeff Browndec6cf42011-11-15 14:08:20 -08007103 } else {
7104 // No overriding preference.
7105 // We will do exactly what the application asked us to do.
7106 preferredRotation = -1;
Jeff Brown01a98dd2011-09-20 15:08:29 -07007107 }
7108
Dianne Hackborne5439f22010-10-02 16:53:50 -07007109 switch (orientation) {
7110 case ActivityInfo.SCREEN_ORIENTATION_PORTRAIT:
Jeff Browndec6cf42011-11-15 14:08:20 -08007111 // Return portrait unless overridden.
7112 if (isAnyPortrait(preferredRotation)) {
7113 return preferredRotation;
7114 }
Dianne Hackborne5439f22010-10-02 16:53:50 -07007115 return mPortraitRotation;
Dianne Hackborne5439f22010-10-02 16:53:50 -07007116
Jeff Brown01a98dd2011-09-20 15:08:29 -07007117 case ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE:
Jeff Browndec6cf42011-11-15 14:08:20 -08007118 // Return landscape unless overridden.
7119 if (isLandscapeOrSeascape(preferredRotation)) {
7120 return preferredRotation;
7121 }
Jeff Brown01a98dd2011-09-20 15:08:29 -07007122 return mLandscapeRotation;
7123
7124 case ActivityInfo.SCREEN_ORIENTATION_REVERSE_PORTRAIT:
Jeff Browndec6cf42011-11-15 14:08:20 -08007125 // Return reverse portrait unless overridden.
7126 if (isAnyPortrait(preferredRotation)) {
7127 return preferredRotation;
7128 }
Jeff Brown01a98dd2011-09-20 15:08:29 -07007129 return mUpsideDownRotation;
7130
7131 case ActivityInfo.SCREEN_ORIENTATION_REVERSE_LANDSCAPE:
Jeff Browndec6cf42011-11-15 14:08:20 -08007132 // Return seascape unless overridden.
7133 if (isLandscapeOrSeascape(preferredRotation)) {
7134 return preferredRotation;
7135 }
Jeff Brown01a98dd2011-09-20 15:08:29 -07007136 return mSeascapeRotation;
7137
7138 case ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE:
Dianne Hackbornb9ec1ac2013-04-10 17:34:25 -07007139 case ActivityInfo.SCREEN_ORIENTATION_USER_LANDSCAPE:
Jeff Brown01a98dd2011-09-20 15:08:29 -07007140 // Return either landscape rotation.
7141 if (isLandscapeOrSeascape(preferredRotation)) {
7142 return preferredRotation;
7143 }
7144 if (isLandscapeOrSeascape(lastRotation)) {
Jeff Brown4519f072011-01-23 13:16:01 -08007145 return lastRotation;
7146 }
Jeff Brown01a98dd2011-09-20 15:08:29 -07007147 return mLandscapeRotation;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08007148
Jeff Brown01a98dd2011-09-20 15:08:29 -07007149 case ActivityInfo.SCREEN_ORIENTATION_SENSOR_PORTRAIT:
Dianne Hackbornb9ec1ac2013-04-10 17:34:25 -07007150 case ActivityInfo.SCREEN_ORIENTATION_USER_PORTRAIT:
Jeff Brown01a98dd2011-09-20 15:08:29 -07007151 // Return either portrait rotation.
7152 if (isAnyPortrait(preferredRotation)) {
7153 return preferredRotation;
7154 }
7155 if (isAnyPortrait(lastRotation)) {
7156 return lastRotation;
7157 }
7158 return mPortraitRotation;
7159
7160 default:
Jeff Brown4dfce202011-10-05 12:00:10 -07007161 // For USER, UNSPECIFIED, NOSENSOR, SENSOR and FULL_SENSOR,
7162 // just return the preferred orientation we already calculated.
Jeff Brown01a98dd2011-09-20 15:08:29 -07007163 if (preferredRotation >= 0) {
7164 return preferredRotation;
7165 }
Dianne Hackborndacea8c2011-04-21 17:26:39 -07007166 return Surface.ROTATION_0;
Daniel Sandlere7e5ac22011-02-22 16:10:21 -05007167 }
7168 }
Steve Howarda7bfe6a2010-09-23 16:47:49 -07007169 }
7170
Jeff Brown01a98dd2011-09-20 15:08:29 -07007171 @Override
7172 public boolean rotationHasCompatibleMetricsLw(int orientation, int rotation) {
7173 switch (orientation) {
7174 case ActivityInfo.SCREEN_ORIENTATION_PORTRAIT:
7175 case ActivityInfo.SCREEN_ORIENTATION_REVERSE_PORTRAIT:
7176 case ActivityInfo.SCREEN_ORIENTATION_SENSOR_PORTRAIT:
7177 return isAnyPortrait(rotation);
7178
7179 case ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE:
7180 case ActivityInfo.SCREEN_ORIENTATION_REVERSE_LANDSCAPE:
7181 case ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE:
7182 return isLandscapeOrSeascape(rotation);
7183
7184 default:
7185 return true;
7186 }
Steve Howarda7bfe6a2010-09-23 16:47:49 -07007187 }
7188
Jeff Brownc0347aa2011-09-23 17:26:09 -07007189 @Override
7190 public void setRotationLw(int rotation) {
7191 mOrientationListener.setCurrentRotation(rotation);
7192 }
7193
Jeff Brown01a98dd2011-09-20 15:08:29 -07007194 private boolean isLandscapeOrSeascape(int rotation) {
7195 return rotation == mLandscapeRotation || rotation == mSeascapeRotation;
Dianne Hackborne5439f22010-10-02 16:53:50 -07007196 }
7197
Jeff Brown01a98dd2011-09-20 15:08:29 -07007198 private boolean isAnyPortrait(int rotation) {
7199 return rotation == mPortraitRotation || rotation == mUpsideDownRotation;
Dianne Hackborne5439f22010-10-02 16:53:50 -07007200 }
7201
Jose Lima9546b202014-07-02 17:21:51 -07007202 @Override
Svetoslav Ganov80943d82013-01-02 10:25:37 -08007203 public int getUserRotationMode() {
7204 return Settings.System.getIntForUser(mContext.getContentResolver(),
Brett Chabot7e55c402013-05-16 19:38:08 -07007205 Settings.System.ACCELEROMETER_ROTATION, 0, UserHandle.USER_CURRENT) != 0 ?
7206 WindowManagerPolicy.USER_ROTATION_FREE :
7207 WindowManagerPolicy.USER_ROTATION_LOCKED;
Svetoslav Ganov80943d82013-01-02 10:25:37 -08007208 }
Daniel Sandlerb73617d2010-08-17 00:41:00 -04007209
7210 // User rotation: to be used when all else fails in assigning an orientation to the device
Jose Lima9546b202014-07-02 17:21:51 -07007211 @Override
Daniel Sandlerb73617d2010-08-17 00:41:00 -04007212 public void setUserRotationMode(int mode, int rot) {
7213 ContentResolver res = mContext.getContentResolver();
Daniel Sandler2ed6ad62011-02-22 14:54:17 -05007214
7215 // mUserRotationMode and mUserRotation will be assigned by the content observer
Daniel Sandlerb73617d2010-08-17 00:41:00 -04007216 if (mode == WindowManagerPolicy.USER_ROTATION_LOCKED) {
Christopher Tate5e08af02012-09-21 17:17:22 -07007217 Settings.System.putIntForUser(res,
Daniel Sandlerb73617d2010-08-17 00:41:00 -04007218 Settings.System.USER_ROTATION,
Christopher Tate5e08af02012-09-21 17:17:22 -07007219 rot,
7220 UserHandle.USER_CURRENT);
7221 Settings.System.putIntForUser(res,
Daniel Sandler2ed6ad62011-02-22 14:54:17 -05007222 Settings.System.ACCELEROMETER_ROTATION,
Christopher Tate5e08af02012-09-21 17:17:22 -07007223 0,
7224 UserHandle.USER_CURRENT);
Daniel Sandlerb73617d2010-08-17 00:41:00 -04007225 } else {
Christopher Tate5e08af02012-09-21 17:17:22 -07007226 Settings.System.putIntForUser(res,
Daniel Sandlerb73617d2010-08-17 00:41:00 -04007227 Settings.System.ACCELEROMETER_ROTATION,
Christopher Tate5e08af02012-09-21 17:17:22 -07007228 1,
7229 UserHandle.USER_CURRENT);
Daniel Sandlerb73617d2010-08-17 00:41:00 -04007230 }
7231 }
7232
Jose Lima9546b202014-07-02 17:21:51 -07007233 @Override
Jeff Brownac143512012-04-05 18:57:33 -07007234 public void setSafeMode(boolean safeMode) {
7235 mSafeMode = safeMode;
Michael Wright33d6c082017-07-21 16:40:58 +01007236 if (safeMode) {
7237 performHapticFeedbackLw(null, HapticFeedbackConstants.SAFE_MODE_ENABLED, true);
7238 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08007239 }
Craig Mautnereda67292013-04-28 13:50:14 -07007240
Dianne Hackborn181ceb52009-08-27 22:16:40 -07007241 static long[] getLongIntArray(Resources r, int resid) {
7242 int[] ar = r.getIntArray(resid);
7243 if (ar == null) {
7244 return null;
7245 }
7246 long[] out = new long[ar.length];
7247 for (int i=0; i<ar.length; i++) {
7248 out[i] = ar[i];
7249 }
7250 return out;
7251 }
Craig Mautnereda67292013-04-28 13:50:14 -07007252
Keun-young Park4136d2d2017-05-08 14:51:59 -07007253 private void bindKeyguard() {
7254 synchronized (mLock) {
7255 if (mKeyguardBound) {
7256 return;
7257 }
7258 mKeyguardBound = true;
7259 }
7260 mKeyguardDelegate.bindService(mContext);
7261 }
7262
7263 @Override
7264 public void onSystemUiStarted() {
7265 bindKeyguard();
7266 }
7267
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08007268 /** {@inheritDoc} */
Craig Mautnereda67292013-04-28 13:50:14 -07007269 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08007270 public void systemReady() {
Keun-young Park4136d2d2017-05-08 14:51:59 -07007271 // In normal flow, systemReady is called before other system services are ready.
7272 // So it is better not to bind keyguard here.
Mike Lockwooded8902d2013-11-15 11:01:47 -08007273 mKeyguardDelegate.onSystemReady();
7274
Zak Cohen732aeb02017-01-29 14:19:52 -08007275 mVrManagerInternal = LocalServices.getService(VrManagerInternal.class);
Santos Cordonc09d89c2017-04-13 16:12:02 -07007276 if (mVrManagerInternal != null) {
7277 mVrManagerInternal.addPersistentVrModeStateListener(mPersistentVrModeListener);
7278 }
Zak Cohen732aeb02017-01-29 14:19:52 -08007279
Michael Wright3818c922014-09-02 13:59:07 -07007280 readCameraLensCoverState();
Jeff Brown4f5fa282014-06-12 19:19:15 -07007281 updateUiMode();
Dianne Hackbornb1a79802009-09-29 15:18:31 -07007282 synchronized (mLock) {
7283 updateOrientationListenerLp();
Dianne Hackbornc777e072010-02-12 13:07:59 -08007284 mSystemReady = true;
7285 mHandler.post(new Runnable() {
Craig Mautnereda67292013-04-28 13:50:14 -07007286 @Override
Dianne Hackbornc777e072010-02-12 13:07:59 -08007287 public void run() {
7288 updateSettings();
7289 }
7290 });
Keun-young Park4136d2d2017-05-08 14:51:59 -07007291 // If this happens, for whatever reason, systemReady came later than systemBooted.
7292 // And keyguard should be already bound from systemBooted
7293 if (mSystemBooted) {
7294 mKeyguardDelegate.onBootCompleted();
Adrian Roos3542f7d2015-07-13 15:57:53 -07007295 }
7296 }
7297
Michael Wrighta4d22d72015-09-16 23:19:26 +01007298 mSystemGestures.systemReady();
Amith Yamasani02a03812016-04-22 17:32:00 -07007299 mImmersiveModeConfirmation.systemReady();
Felipe Leme5f978802017-06-08 13:01:13 -07007300
7301 mAutofillManagerInternal = LocalServices.getService(AutofillManagerInternal.class);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08007302 }
Dianne Hackborn661cd522011-08-22 00:26:20 -07007303
Dianne Hackbornba24e4d2011-09-01 11:17:06 -07007304 /** {@inheritDoc} */
Jose Lima9546b202014-07-02 17:21:51 -07007305 @Override
Dianne Hackbornba24e4d2011-09-01 11:17:06 -07007306 public void systemBooted() {
Keun-young Park4136d2d2017-05-08 14:51:59 -07007307 bindKeyguard();
Dianne Hackbornba24e4d2011-09-01 11:17:06 -07007308 synchronized (mLock) {
7309 mSystemBooted = true;
Keun-young Park4136d2d2017-05-08 14:51:59 -07007310 if (mSystemReady) {
7311 mKeyguardDelegate.onBootCompleted();
7312 }
Dianne Hackbornba24e4d2011-09-01 11:17:06 -07007313 }
Jeff Brown416c49c2015-05-26 19:50:18 -07007314 startedWakingUp();
Jeff Brown36c4db82014-09-19 12:05:31 -07007315 screenTurningOn(null);
Jorim Jaggic0496072015-08-19 15:14:52 -07007316 screenTurnedOn();
Dianne Hackbornba24e4d2011-09-01 11:17:06 -07007317 }
7318
Keun-young Park4136d2d2017-05-08 14:51:59 -07007319 @Override
7320 public boolean canDismissBootAnimation() {
7321 synchronized (mLock) {
7322 return mKeyguardDrawComplete;
7323 }
7324 }
7325
Dianne Hackborn661cd522011-08-22 00:26:20 -07007326 ProgressDialog mBootMsgDialog = null;
7327
7328 /** {@inheritDoc} */
Jose Lima9546b202014-07-02 17:21:51 -07007329 @Override
Dianne Hackborn661cd522011-08-22 00:26:20 -07007330 public void showBootMessage(final CharSequence msg, final boolean always) {
7331 mHandler.post(new Runnable() {
7332 @Override public void run() {
7333 if (mBootMsgDialog == null) {
Craig Stout4c0cb8a2014-04-04 13:03:10 -07007334 int theme;
Dmitri Plotnikov82e6dfc2017-02-24 18:10:54 -08007335 if (mContext.getPackageManager().hasSystemFeature(FEATURE_LEANBACK)) {
Craig Stout4c0cb8a2014-04-04 13:03:10 -07007336 theme = com.android.internal.R.style.Theme_Leanback_Dialog_Alert;
7337 } else {
7338 theme = 0;
7339 }
Vinod Krishnanfa8fc412014-04-18 14:35:53 -07007340
7341 mBootMsgDialog = new ProgressDialog(mContext, theme) {
Dianne Hackborn295e3c22011-08-25 13:19:08 -07007342 // This dialog will consume all events coming in to
7343 // it, to avoid it trying to do things too early in boot.
7344 @Override public boolean dispatchKeyEvent(KeyEvent event) {
7345 return true;
7346 }
7347 @Override public boolean dispatchKeyShortcutEvent(KeyEvent event) {
7348 return true;
7349 }
7350 @Override public boolean dispatchTouchEvent(MotionEvent ev) {
7351 return true;
7352 }
7353 @Override public boolean dispatchTrackballEvent(MotionEvent ev) {
7354 return true;
7355 }
7356 @Override public boolean dispatchGenericMotionEvent(MotionEvent ev) {
7357 return true;
7358 }
7359 @Override public boolean dispatchPopulateAccessibilityEvent(
7360 AccessibilityEvent event) {
7361 return true;
7362 }
7363 };
Jeff Hao9f60c082014-10-28 18:51:07 -07007364 if (mContext.getPackageManager().isUpgrade()) {
7365 mBootMsgDialog.setTitle(R.string.android_upgrading_title);
7366 } else {
7367 mBootMsgDialog.setTitle(R.string.android_start_title);
7368 }
Dianne Hackborn661cd522011-08-22 00:26:20 -07007369 mBootMsgDialog.setProgressStyle(ProgressDialog.STYLE_SPINNER);
7370 mBootMsgDialog.setIndeterminate(true);
7371 mBootMsgDialog.getWindow().setType(
Dianne Hackborn29aae6f2011-08-18 18:30:09 -07007372 WindowManager.LayoutParams.TYPE_BOOT_PROGRESS);
Dianne Hackborn661cd522011-08-22 00:26:20 -07007373 mBootMsgDialog.getWindow().addFlags(
7374 WindowManager.LayoutParams.FLAG_DIM_BEHIND
7375 | WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN);
7376 mBootMsgDialog.getWindow().setDimAmount(1);
Dianne Hackbornd9efb952011-12-07 14:56:51 -08007377 WindowManager.LayoutParams lp = mBootMsgDialog.getWindow().getAttributes();
7378 lp.screenOrientation = ActivityInfo.SCREEN_ORIENTATION_NOSENSOR;
7379 mBootMsgDialog.getWindow().setAttributes(lp);
Dianne Hackborn661cd522011-08-22 00:26:20 -07007380 mBootMsgDialog.setCancelable(false);
7381 mBootMsgDialog.show();
7382 }
7383 mBootMsgDialog.setMessage(msg);
7384 }
7385 });
7386 }
7387
7388 /** {@inheritDoc} */
Jose Lima9546b202014-07-02 17:21:51 -07007389 @Override
Dianne Hackborn661cd522011-08-22 00:26:20 -07007390 public void hideBootMessages() {
Craig Mautnera631d492014-08-05 15:16:01 -07007391 mHandler.sendEmptyMessage(MSG_HIDE_BOOT_MESSAGE);
Dianne Hackborn661cd522011-08-22 00:26:20 -07007392 }
7393
Mike Lockwood28569302010-01-28 11:54:40 -05007394 /** {@inheritDoc} */
Jose Lima9546b202014-07-02 17:21:51 -07007395 @Override
Mike Lockwood28569302010-01-28 11:54:40 -05007396 public void userActivity() {
Dianne Hackborndf89e652011-10-06 22:35:11 -07007397 // ***************************************
7398 // NOTE NOTE NOTE NOTE NOTE NOTE NOTE NOTE
7399 // ***************************************
7400 // THIS IS CALLED FROM DEEP IN THE POWER MANAGER
7401 // WITH ITS LOCKS HELD.
7402 //
7403 // This code must be VERY careful about the locks
7404 // it acquires.
7405 // In fact, the current code acquires way too many,
7406 // and probably has lurking deadlocks.
7407
Mike Lockwood28569302010-01-28 11:54:40 -05007408 synchronized (mScreenLockTimeout) {
7409 if (mLockScreenTimerActive) {
7410 // reset the timer
7411 mHandler.removeCallbacks(mScreenLockTimeout);
7412 mHandler.postDelayed(mScreenLockTimeout, mLockScreenTimeout);
7413 }
7414 }
Daniel Sandler0601eb72011-04-13 01:01:32 -04007415 }
7416
Adam Cohenf7522022012-10-03 20:03:18 -07007417 class ScreenLockTimeout implements Runnable {
7418 Bundle options;
7419
7420 @Override
Mike Lockwood28569302010-01-28 11:54:40 -05007421 public void run() {
7422 synchronized (this) {
7423 if (localLOGV) Log.v(TAG, "mScreenLockTimeout activating keyguard");
Jim Miller5ecd8112013-01-09 18:50:26 -08007424 if (mKeyguardDelegate != null) {
7425 mKeyguardDelegate.doKeyguardTimeout(options);
Mike Lockwood3a74bd32011-08-12 13:55:22 -07007426 }
Mike Lockwood28569302010-01-28 11:54:40 -05007427 mLockScreenTimerActive = false;
Adam Cohenf7522022012-10-03 20:03:18 -07007428 options = null;
Mike Lockwood28569302010-01-28 11:54:40 -05007429 }
7430 }
Mike Lockwood28569302010-01-28 11:54:40 -05007431
Adam Cohenf7522022012-10-03 20:03:18 -07007432 public void setLockOptions(Bundle options) {
7433 this.options = options;
7434 }
7435 }
7436
7437 ScreenLockTimeout mScreenLockTimeout = new ScreenLockTimeout();
7438
Jose Lima9546b202014-07-02 17:21:51 -07007439 @Override
Adam Cohenf7522022012-10-03 20:03:18 -07007440 public void lockNow(Bundle options) {
Jim Miller93c518e2012-01-17 15:55:31 -08007441 mContext.enforceCallingOrSelfPermission(android.Manifest.permission.DEVICE_POWER, null);
7442 mHandler.removeCallbacks(mScreenLockTimeout);
Adam Cohenf7522022012-10-03 20:03:18 -07007443 if (options != null) {
7444 // In case multiple calls are made to lockNow, we don't wipe out the options
7445 // until the runnable actually executes.
7446 mScreenLockTimeout.setLockOptions(options);
7447 }
Jim Miller93c518e2012-01-17 15:55:31 -08007448 mHandler.post(mScreenLockTimeout);
7449 }
7450
Mike Lockwood28569302010-01-28 11:54:40 -05007451 private void updateLockScreenTimeout() {
7452 synchronized (mScreenLockTimeout) {
Jeff Brown3ee549c2014-09-22 20:14:39 -07007453 boolean enable = (mAllowLockscreenWhenOn && mAwake &&
Jim Millere4044bb2016-05-10 18:38:25 -07007454 mKeyguardDelegate != null && mKeyguardDelegate.isSecure(mCurrentUserId));
Mike Lockwood28569302010-01-28 11:54:40 -05007455 if (mLockScreenTimerActive != enable) {
7456 if (enable) {
7457 if (localLOGV) Log.v(TAG, "setting lockscreen timer");
Jim Miller2967f482016-01-07 15:05:32 -08007458 mHandler.removeCallbacks(mScreenLockTimeout); // remove any pending requests
Mike Lockwood28569302010-01-28 11:54:40 -05007459 mHandler.postDelayed(mScreenLockTimeout, mLockScreenTimeout);
7460 } else {
7461 if (localLOGV) Log.v(TAG, "clearing lockscreen timer");
7462 mHandler.removeCallbacks(mScreenLockTimeout);
7463 }
7464 mLockScreenTimerActive = enable;
7465 }
7466 }
7467 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08007468
Jeff Brown061ea992015-04-17 19:55:47 -07007469 private void updateDreamingSleepToken(boolean acquire) {
7470 if (acquire) {
7471 if (mDreamingSleepToken == null) {
7472 mDreamingSleepToken = mActivityManagerInternal.acquireSleepToken("Dream");
7473 }
7474 } else {
7475 if (mDreamingSleepToken != null) {
7476 mDreamingSleepToken.release();
Jeff Brown48d1b142015-06-10 16:36:03 -07007477 mDreamingSleepToken = null;
7478 }
7479 }
7480 }
7481
7482 private void updateScreenOffSleepToken(boolean acquire) {
7483 if (acquire) {
7484 if (mScreenOffSleepToken == null) {
7485 mScreenOffSleepToken = mActivityManagerInternal.acquireSleepToken("ScreenOff");
7486 }
7487 } else {
7488 if (mScreenOffSleepToken != null) {
7489 mScreenOffSleepToken.release();
7490 mScreenOffSleepToken = null;
Jeff Brown061ea992015-04-17 19:55:47 -07007491 }
7492 }
7493 }
7494
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08007495 /** {@inheritDoc} */
Craig Mautnereda67292013-04-28 13:50:14 -07007496 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08007497 public void enableScreenAfterBoot() {
7498 readLidState();
Jeff Brownc458ce92012-04-30 14:58:40 -07007499 applyLidSwitchState();
Jeff Brown01a98dd2011-09-20 15:08:29 -07007500 updateRotation(true);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08007501 }
Dianne Hackbornf54c8f92009-09-19 14:03:57 -07007502
Jeff Brownc458ce92012-04-30 14:58:40 -07007503 private void applyLidSwitchState() {
Jeff Brownc458ce92012-04-30 14:58:40 -07007504 if (mLidState == LID_CLOSED && mLidControlsSleep) {
Selim Cinekab55ba52017-08-02 16:45:51 -07007505 goToSleep(SystemClock.uptimeMillis(), PowerManager.GO_TO_SLEEP_REASON_LID_SWITCH,
Jeff Brown6d8fd272014-05-20 21:24:38 -07007506 PowerManager.GO_TO_SLEEP_FLAG_NO_DOZE);
Edward Savage-Jones7def60d2015-11-13 13:27:03 +01007507 } else if (mLidState == LID_CLOSED && mLidControlsScreenLock) {
7508 mWindowManagerFuncs.lockDeviceNow();
Jeff Brownc458ce92012-04-30 14:58:40 -07007509 }
Jeff Browna20dda42014-05-27 20:57:24 -07007510
7511 synchronized (mLock) {
7512 updateWakeGestureListenerLp();
7513 }
Jeff Brown01a98dd2011-09-20 15:08:29 -07007514 }
7515
Jeff Brown4f5fa282014-06-12 19:19:15 -07007516 void updateUiMode() {
7517 if (mUiModeManager == null) {
7518 mUiModeManager = IUiModeManager.Stub.asInterface(
7519 ServiceManager.getService(Context.UI_MODE_SERVICE));
7520 }
7521 try {
7522 mUiMode = mUiModeManager.getCurrentModeType();
7523 } catch (RemoteException e) {
7524 }
7525 }
7526
Jeff Brown01a98dd2011-09-20 15:08:29 -07007527 void updateRotation(boolean alwaysSendConfiguration) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08007528 try {
7529 //set orientation on WindowManager
Dianne Hackbornf87d1962012-04-04 12:48:24 -07007530 mWindowManager.updateRotation(alwaysSendConfiguration, false);
7531 } catch (RemoteException e) {
7532 // Ignore
7533 }
7534 }
7535
7536 void updateRotation(boolean alwaysSendConfiguration, boolean forceRelayout) {
7537 try {
7538 //set orientation on WindowManager
7539 mWindowManager.updateRotation(alwaysSendConfiguration, forceRelayout);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08007540 } catch (RemoteException e) {
7541 // Ignore
7542 }
7543 }
7544
Daniel Sandler6396c722013-04-16 20:19:09 -04007545 /**
7546 * Return an Intent to launch the currently active dock app as home. Returns
7547 * null if the standard home should be launched, which is the case if any of the following is
7548 * true:
7549 * <ul>
7550 * <li>The device is not in either car mode or desk mode
keunyounga7710492015-09-23 11:33:58 -07007551 * <li>The device is in car mode but mEnableCarDockHomeCapture is false
Daniel Sandler6396c722013-04-16 20:19:09 -04007552 * <li>The device is in desk mode but ENABLE_DESK_DOCK_HOME_CAPTURE is false
7553 * <li>The device is in car mode but there's no CAR_DOCK app with METADATA_DOCK_HOME
7554 * <li>The device is in desk mode but there's no DESK_DOCK app with METADATA_DOCK_HOME
7555 * </ul>
Craig Mautnereda67292013-04-28 13:50:14 -07007556 * @return A dock intent.
Daniel Sandler6396c722013-04-16 20:19:09 -04007557 */
7558 Intent createHomeDockIntent() {
7559 Intent intent = null;
7560
7561 // What home does is based on the mode, not the dock state. That
7562 // is, when in car mode you should be taken to car home regardless
7563 // of whether we are actually in a car dock.
7564 if (mUiMode == Configuration.UI_MODE_TYPE_CAR) {
keunyounga7710492015-09-23 11:33:58 -07007565 if (mEnableCarDockHomeCapture) {
Daniel Sandler6396c722013-04-16 20:19:09 -04007566 intent = mCarDockIntent;
7567 }
7568 } else if (mUiMode == Configuration.UI_MODE_TYPE_DESK) {
7569 if (ENABLE_DESK_DOCK_HOME_CAPTURE) {
7570 intent = mDeskDockIntent;
7571 }
Jeff Brown4f5fa282014-06-12 19:19:15 -07007572 } else if (mUiMode == Configuration.UI_MODE_TYPE_WATCH
7573 && (mDockMode == Intent.EXTRA_DOCK_STATE_DESK
7574 || mDockMode == Intent.EXTRA_DOCK_STATE_HE_DESK
7575 || mDockMode == Intent.EXTRA_DOCK_STATE_LE_DESK)) {
7576 // Always launch dock home from home when watch is docked, if it exists.
7577 intent = mDeskDockIntent;
Zak Cohendb6ca492017-01-26 14:09:00 -08007578 } else if (mUiMode == Configuration.UI_MODE_TYPE_VR_HEADSET) {
7579 if (ENABLE_VR_HEADSET_HOME_CAPTURE) {
7580 intent = mVrHeadsetHomeIntent;
7581 }
Daniel Sandler6396c722013-04-16 20:19:09 -04007582 }
7583
7584 if (intent == null) {
7585 return null;
7586 }
7587
7588 ActivityInfo ai = null;
7589 ResolveInfo info = mContext.getPackageManager().resolveActivityAsUser(
7590 intent,
John Spurlockf56bef12013-07-09 09:51:46 -04007591 PackageManager.MATCH_DEFAULT_ONLY | PackageManager.GET_META_DATA,
Craig Mautnerd625ab22013-09-06 13:40:31 -07007592 mCurrentUserId);
Daniel Sandler6396c722013-04-16 20:19:09 -04007593 if (info != null) {
7594 ai = info.activityInfo;
7595 }
7596 if (ai != null
7597 && ai.metaData != null
7598 && ai.metaData.getBoolean(Intent.METADATA_DOCK_HOME)) {
7599 intent = new Intent(intent);
7600 intent.setClassName(ai.packageName, ai.name);
7601 return intent;
7602 }
7603
7604 return null;
7605 }
7606
Filip Gruszczynskia483a1d2015-03-17 19:06:58 +00007607 void startDockOrHome(boolean fromHomeKey, boolean awakenFromDreams) {
7608 if (awakenFromDreams) {
7609 awakenDreams();
7610 }
Daniel Sandler6396c722013-04-16 20:19:09 -04007611
7612 Intent dock = createHomeDockIntent();
7613 if (dock != null) {
7614 try {
Bryce Lee01b0c5f2015-02-05 18:24:04 -08007615 if (fromHomeKey) {
7616 dock.putExtra(WindowManagerPolicy.EXTRA_FROM_HOME_KEY, fromHomeKey);
7617 }
Bart Sears8b1c27c2015-03-18 23:51:02 +00007618 startActivityAsUser(dock, UserHandle.CURRENT);
Daniel Sandler6396c722013-04-16 20:19:09 -04007619 return;
7620 } catch (ActivityNotFoundException e) {
7621 }
7622 }
7623
Bryce Lee01b0c5f2015-02-05 18:24:04 -08007624 Intent intent;
7625
7626 if (fromHomeKey) {
7627 intent = new Intent(mHomeIntent);
7628 intent.putExtra(WindowManagerPolicy.EXTRA_FROM_HOME_KEY, fromHomeKey);
7629 } else {
7630 intent = mHomeIntent;
7631 }
7632
Bryce Lee9fc0b6f2015-03-19 21:37:45 +00007633 startActivityAsUser(intent, UserHandle.CURRENT);
Dianne Hackborn39c2d712009-09-22 11:41:31 -07007634 }
Craig Mautnereda67292013-04-28 13:50:14 -07007635
Dianne Hackborn39c2d712009-09-22 11:41:31 -07007636 /**
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08007637 * goes to the home screen
7638 * @return whether it did anything
7639 */
7640 boolean goHome() {
Bart Sears8b1c27c2015-03-18 23:51:02 +00007641 if (!isUserSetupComplete()) {
7642 Slog.i(TAG, "Not going home because user setup is in progress.");
7643 return false;
7644 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08007645 if (false) {
7646 // This code always brings home to the front.
Dianne Hackborn256dd3b2009-05-19 18:51:21 -07007647 try {
Sudheer Shankadc589ac2016-11-10 15:30:17 -08007648 ActivityManager.getService().stopAppSwitches();
Dianne Hackborn256dd3b2009-05-19 18:51:21 -07007649 } catch (RemoteException e) {
7650 }
Dianne Hackborn94a679d2009-07-28 17:51:07 -07007651 sendCloseSystemWindows();
Filip Gruszczynskia483a1d2015-03-17 19:06:58 +00007652 startDockOrHome(false /*fromHomeKey*/, true /* awakenFromDreams */);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08007653 } else {
7654 // This code brings home to the front or, if it is already
7655 // at the front, puts the device to sleep.
7656 try {
Wink Savilled2e6a332010-02-12 12:12:06 -08007657 if (SystemProperties.getInt("persist.sys.uts-test-mode", 0) == 1) {
7658 /// Roll back EndcallBehavior as the cupcake design to pass P1 lab entry.
7659 Log.d(TAG, "UTS-TEST-MODE");
7660 } else {
Sudheer Shankadc589ac2016-11-10 15:30:17 -08007661 ActivityManager.getService().stopAppSwitches();
Wink Savilled2e6a332010-02-12 12:12:06 -08007662 sendCloseSystemWindows();
Daniel Sandler6396c722013-04-16 20:19:09 -04007663 Intent dock = createHomeDockIntent();
7664 if (dock != null) {
Sudheer Shankadc589ac2016-11-10 15:30:17 -08007665 int result = ActivityManager.getService()
Daniel Sandler6396c722013-04-16 20:19:09 -04007666 .startActivityAsUser(null, null, dock,
7667 dock.resolveTypeIfNeeded(mContext.getContentResolver()),
7668 null, null, 0,
7669 ActivityManager.START_FLAG_ONLY_IF_NEEDED,
Jeff Hao1b012d32014-08-20 10:35:34 -07007670 null, null, UserHandle.USER_CURRENT);
Daniel Sandler6396c722013-04-16 20:19:09 -04007671 if (result == ActivityManager.START_RETURN_INTENT_TO_CALLER) {
7672 return false;
7673 }
7674 }
Dianne Hackborn39c2d712009-09-22 11:41:31 -07007675 }
Sudheer Shankadc589ac2016-11-10 15:30:17 -08007676 int result = ActivityManager.getService()
Dianne Hackbornf265ea92013-01-31 15:00:51 -08007677 .startActivityAsUser(null, null, mHomeIntent,
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08007678 mHomeIntent.resolveTypeIfNeeded(mContext.getContentResolver()),
Dianne Hackborna4972e92012-03-14 10:38:05 -07007679 null, null, 0,
7680 ActivityManager.START_FLAG_ONLY_IF_NEEDED,
Jeff Hao1b012d32014-08-20 10:35:34 -07007681 null, null, UserHandle.USER_CURRENT);
Dianne Hackborna4972e92012-03-14 10:38:05 -07007682 if (result == ActivityManager.START_RETURN_INTENT_TO_CALLER) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08007683 return false;
7684 }
7685 } catch (RemoteException ex) {
7686 // bummer, the activity manager, which is in this process, is dead
7687 }
7688 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08007689 return true;
7690 }
Craig Mautnereda67292013-04-28 13:50:14 -07007691
7692 @Override
The Android Open Source Project0727d222009-03-11 12:11:58 -07007693 public void setCurrentOrientationLw(int newOrientation) {
7694 synchronized (mLock) {
7695 if (newOrientation != mCurrentAppOrientation) {
7696 mCurrentAppOrientation = newOrientation;
7697 updateOrientationListenerLp();
7698 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08007699 }
7700 }
Amith Yamasanic33cb712010-02-10 15:21:49 -08007701
Bryce Lee584a4452014-10-21 15:55:55 -07007702 private boolean isTheaterModeEnabled() {
7703 return Settings.Global.getInt(mContext.getContentResolver(),
7704 Settings.Global.THEATER_MODE_ON, 0) == 1;
7705 }
7706
Doris Ling628cea42016-06-09 10:35:02 -07007707 private boolean areSystemNavigationKeysEnabled() {
Doris Ling34331b72016-08-09 12:02:28 -07007708 return Settings.Secure.getIntForUser(mContext.getContentResolver(),
Kevin Chyn76096e72017-07-24 14:00:22 -07007709 Settings.Secure.SYSTEM_NAVIGATION_KEYS_ENABLED, 0, UserHandle.USER_CURRENT) == 1;
Doris Ling628cea42016-06-09 10:35:02 -07007710 }
7711
Craig Mautnereda67292013-04-28 13:50:14 -07007712 @Override
The Android Open Source Project0727d222009-03-11 12:11:58 -07007713 public boolean performHapticFeedbackLw(WindowState win, int effectId, boolean always) {
Svetoslav Ganov96179212012-10-10 14:17:45 -07007714 if (!mVibrator.hasVibrator()) {
7715 return false;
7716 }
Christopher Tate5e08af02012-09-21 17:17:22 -07007717 final boolean hapticsDisabled = Settings.System.getIntForUser(mContext.getContentResolver(),
7718 Settings.System.HAPTIC_FEEDBACK_ENABLED, 0, UserHandle.USER_CURRENT) == 0;
Jeff Brown82379ba2014-07-25 19:03:28 -07007719 if (hapticsDisabled && !always) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08007720 return false;
7721 }
Michael Wright71216972017-01-31 18:33:54 +00007722
7723 VibrationEffect effect = getVibrationEffect(effectId);
7724 if (effect == null) {
7725 return false;
7726 }
7727
7728 int owningUid;
7729 String owningPackage;
7730 if (win != null) {
7731 owningUid = win.getOwningUid();
7732 owningPackage = win.getOwningPackage();
7733 } else {
7734 owningUid = android.os.Process.myUid();
7735 owningPackage = mContext.getOpPackageName();
7736 }
7737 mVibrator.vibrate(owningUid, owningPackage, effect, VIBRATION_ATTRIBUTES);
7738 return true;
7739 }
7740
7741 private VibrationEffect getVibrationEffect(int effectId) {
7742 long[] pattern;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08007743 switch (effectId) {
Michael Wright71216972017-01-31 18:33:54 +00007744 case HapticFeedbackConstants.VIRTUAL_KEY:
7745 return VibrationEffect.get(VibrationEffect.EFFECT_CLICK);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08007746 case HapticFeedbackConstants.LONG_PRESS:
Amith Yamasanic33cb712010-02-10 15:21:49 -08007747 pattern = mLongPressVibePattern;
7748 break;
Amith Yamasanic33cb712010-02-10 15:21:49 -08007749 case HapticFeedbackConstants.KEYBOARD_TAP:
Michael Wright71216972017-01-31 18:33:54 +00007750 return VibrationEffect.get(VibrationEffect.EFFECT_CLICK);
Fabrice Di Meglioeeff63a2013-08-05 12:07:24 -07007751 case HapticFeedbackConstants.CLOCK_TICK:
Michael Wright57d94d92017-05-31 14:44:45 +01007752 return VibrationEffect.get(VibrationEffect.EFFECT_TICK);
Fabrice Di Megliobd9152f2013-10-01 11:21:31 -07007753 case HapticFeedbackConstants.CALENDAR_DATE:
7754 pattern = mCalendarDateVibePattern;
7755 break;
Dianne Hackbornb1a79802009-09-29 15:18:31 -07007756 case HapticFeedbackConstants.SAFE_MODE_ENABLED:
Amith Yamasanic33cb712010-02-10 15:21:49 -08007757 pattern = mSafeModeEnabledVibePattern;
7758 break;
Mady Mellore8608912015-06-05 09:02:55 -07007759 case HapticFeedbackConstants.CONTEXT_CLICK:
Michael Wright57d94d92017-05-31 14:44:45 +01007760 return VibrationEffect.get(VibrationEffect.EFFECT_TICK);
Michael Wrighte14b0642017-06-02 19:13:58 +01007761 case HapticFeedbackConstants.VIRTUAL_KEY_RELEASE:
7762 return VibrationEffect.get(VibrationEffect.EFFECT_TICK);
Yohei Yukawada5b4a32017-06-09 12:01:51 -07007763 case HapticFeedbackConstants.TEXT_HANDLE_MOVE:
7764 return VibrationEffect.get(VibrationEffect.EFFECT_TICK);
Amith Yamasanic33cb712010-02-10 15:21:49 -08007765 default:
Michael Wright71216972017-01-31 18:33:54 +00007766 return null;
Dianne Hackbornf265ea92013-01-31 15:00:51 -08007767 }
Erik Wolsheimer017939e2017-05-24 11:18:25 -07007768 if (pattern.length == 0) {
7769 // No vibration
7770 return null;
7771 } else if (pattern.length == 1) {
Amith Yamasanic33cb712010-02-10 15:21:49 -08007772 // One-shot vibration
Michael Wright71216972017-01-31 18:33:54 +00007773 return VibrationEffect.createOneShot(pattern[0], VibrationEffect.DEFAULT_AMPLITUDE);
Amith Yamasanic33cb712010-02-10 15:21:49 -08007774 } else {
7775 // Pattern vibration
Michael Wright71216972017-01-31 18:33:54 +00007776 return VibrationEffect.createWaveform(pattern, -1);
Amith Yamasanic33cb712010-02-10 15:21:49 -08007777 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08007778 }
Jeff Brownc38c9be2012-10-04 13:16:19 -07007779
7780 @Override
7781 public void keepScreenOnStartedLw() {
Daniel Sandler0601eb72011-04-13 01:01:32 -04007782 }
7783
Jeff Brownc38c9be2012-10-04 13:16:19 -07007784 @Override
7785 public void keepScreenOnStoppedLw() {
Jim Millerab954542014-10-10 18:21:49 -07007786 if (isKeyguardShowingAndNotOccluded()) {
Jim Miller25190572013-02-28 17:36:24 -08007787 mPowerManager.userActivity(SystemClock.uptimeMillis(), false);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08007788 }
7789 }
Mike Lockwoodfcb39242009-10-21 23:01:07 -04007790
Dianne Hackborndf89e652011-10-06 22:35:11 -07007791 private int updateSystemUiVisibilityLw() {
Joe Onorato664644d2011-01-23 17:53:23 -08007792 // If there is no window focused, there will be nobody to handle the events
7793 // anyway, so just hang on in whatever state we're in until things settle down.
Adrian Roosdab15162016-09-12 15:08:35 -07007794 WindowState winCandidate = mFocusedWindow != null ? mFocusedWindow
Adrian Roos53f28ec2014-10-29 17:26:12 +01007795 : mTopFullscreenOpaqueWindowState;
Adrian Roosdab15162016-09-12 15:08:35 -07007796 if (winCandidate == null) {
Dianne Hackborndf89e652011-10-06 22:35:11 -07007797 return 0;
7798 }
Adrian Roosdab15162016-09-12 15:08:35 -07007799 if (winCandidate.getAttrs().token == mImmersiveModeConfirmation.getWindowToken()) {
7800 // The immersive mode confirmation should never affect the system bar visibility,
7801 // otherwise it will unhide the navigation bar and hide itself.
7802 winCandidate = isStatusBarKeyguard() ? mStatusBar : mTopFullscreenOpaqueWindowState;
7803 if (winCandidate == null) {
7804 return 0;
7805 }
7806 }
7807 final WindowState win = winCandidate;
Jorim Jaggife762342016-10-13 14:33:27 +02007808 if ((win.getAttrs().privateFlags & PRIVATE_FLAG_KEYGUARD) != 0 && mKeyguardOccluded) {
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07007809 // We are updating at a point where the keyguard has gotten
7810 // focus, but we were last in a state where the top window is
7811 // hiding it. This is probably because the keyguard as been
7812 // shown while the top window was displayed, so we want to ignore
7813 // it here because this is just a very transient change and it
7814 // will quickly lose focus once it correctly gets hidden.
7815 return 0;
7816 }
John Spurlock32beb2c2013-03-11 10:16:47 -04007817
John Spurlock1db8b682014-02-18 11:18:59 -05007818 int tmpVisibility = PolicyControl.getSystemUiVisibility(win, null)
Dianne Hackborne26ab702011-10-16 13:21:33 -07007819 & ~mResettingSystemUiFlags
7820 & ~mForceClearedSystemUiFlags;
John Spurlock79da8332013-09-20 12:04:47 -04007821 if (mForcingShowNavBar && win.getSurfaceLayer() < mForcingShowNavBarLayer) {
John Spurlockc6d1c602014-01-17 15:22:06 -05007822 tmpVisibility &= ~PolicyControl.adjustClearableFlags(win, View.SYSTEM_UI_CLEARABLE_FLAGS);
Dianne Hackborn891d3fb2013-01-09 18:31:37 -08007823 }
Thanh Hai Mai6c009f52015-09-01 16:27:32 -07007824
Jorim Jaggi86905582016-02-09 21:36:09 -08007825 final int fullscreenVisibility = updateLightStatusBarLw(0 /* vis */,
7826 mTopFullscreenOpaqueWindowState, mTopFullscreenOpaqueOrDimmingWindowState);
7827 final int dockedVisibility = updateLightStatusBarLw(0 /* vis */,
7828 mTopDockedOpaqueWindowState, mTopDockedOpaqueOrDimmingWindowState);
7829 mWindowManagerFuncs.getStackBounds(HOME_STACK_ID, mNonDockedStackBounds);
7830 mWindowManagerFuncs.getStackBounds(DOCKED_STACK_ID, mDockedStackBounds);
John Spurlock79da8332013-09-20 12:04:47 -04007831 final int visibility = updateSystemBarsLw(win, mLastSystemUiFlags, tmpVisibility);
John Spurlockad3e6cb2013-04-30 08:47:43 -04007832 final int diff = visibility ^ mLastSystemUiFlags;
Jorim Jaggi86905582016-02-09 21:36:09 -08007833 final int fullscreenDiff = fullscreenVisibility ^ mLastFullscreenStackSysUiFlags;
7834 final int dockedDiff = dockedVisibility ^ mLastDockedStackSysUiFlags;
John Spurlock79da8332013-09-20 12:04:47 -04007835 final boolean needsMenu = win.getNeedsMenuLw(mTopFullscreenOpaqueWindowState);
Jorim Jaggi86905582016-02-09 21:36:09 -08007836 if (diff == 0 && fullscreenDiff == 0 && dockedDiff == 0 && mLastFocusNeedsMenu == needsMenu
7837 && mFocusedApp == win.getAppToken()
7838 && mLastNonDockedStackBounds.equals(mNonDockedStackBounds)
7839 && mLastDockedStackBounds.equals(mDockedStackBounds)) {
Dianne Hackborndf89e652011-10-06 22:35:11 -07007840 return 0;
7841 }
Dianne Hackborne26ab702011-10-16 13:21:33 -07007842 mLastSystemUiFlags = visibility;
Jorim Jaggi86905582016-02-09 21:36:09 -08007843 mLastFullscreenStackSysUiFlags = fullscreenVisibility;
7844 mLastDockedStackSysUiFlags = dockedVisibility;
Dianne Hackborn4eff8d32011-11-10 19:38:40 -08007845 mLastFocusNeedsMenu = needsMenu;
John Spurlock79da8332013-09-20 12:04:47 -04007846 mFocusedApp = win.getAppToken();
Jorim Jaggi86905582016-02-09 21:36:09 -08007847 final Rect fullscreenStackBounds = new Rect(mNonDockedStackBounds);
7848 final Rect dockedStackBounds = new Rect(mDockedStackBounds);
Dianne Hackborndf89e652011-10-06 22:35:11 -07007849 mHandler.post(new Runnable() {
Craig Mautnereda67292013-04-28 13:50:14 -07007850 @Override
Dianne Hackborndf89e652011-10-06 22:35:11 -07007851 public void run() {
Jorim Jaggi86905582016-02-09 21:36:09 -08007852 StatusBarManagerInternal statusbar = getStatusBarManagerInternal();
7853 if (statusbar != null) {
7854 statusbar.setSystemUiVisibility(visibility, fullscreenVisibility,
7855 dockedVisibility, 0xffffffff, fullscreenStackBounds,
7856 dockedStackBounds, win.toString());
7857 statusbar.topAppWindowChanged(needsMenu);
Joe Onorato664644d2011-01-23 17:53:23 -08007858 }
Dianne Hackborndf89e652011-10-06 22:35:11 -07007859 }
7860 });
7861 return diff;
Joe Onorato664644d2011-01-23 17:53:23 -08007862 }
7863
Jorim Jaggi86905582016-02-09 21:36:09 -08007864 private int updateLightStatusBarLw(int vis, WindowState opaque, WindowState opaqueOrDimming) {
Jorim Jaggiff46d4c2017-07-17 16:46:00 +02007865 final boolean onKeyguard = isStatusBarKeyguard() && !mKeyguardOccluded;
7866 final WindowState statusColorWin = onKeyguard ? mStatusBar : opaqueOrDimming;
7867 if (statusColorWin != null && (statusColorWin == opaque || onKeyguard)) {
7868 // If the top fullscreen-or-dimming window is also the top fullscreen, respect
7869 // its light flag.
7870 vis &= ~View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR;
7871 vis |= PolicyControl.getSystemUiVisibility(statusColorWin, null)
7872 & View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR;
7873 } else if (statusColorWin != null && statusColorWin.isDimming()) {
7874 // Otherwise if it's dimming, clear the light flag.
7875 vis &= ~View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR;
Adrian Rooscd3884d2015-02-18 17:25:23 +01007876 }
7877 return vis;
7878 }
7879
Jorim Jaggi40db0292016-06-27 17:58:03 -07007880 private int updateLightNavigationBarLw(int vis, WindowState opaque,
7881 WindowState opaqueOrDimming) {
7882 final WindowState imeWin = mWindowManagerFuncs.getInputMethodWindowLw();
7883
7884 final WindowState navColorWin;
Jorim Jaggiff46d4c2017-07-17 16:46:00 +02007885 if (imeWin != null && imeWin.isVisibleLw() && mNavigationBarPosition == NAV_BAR_BOTTOM) {
Jorim Jaggi40db0292016-06-27 17:58:03 -07007886 navColorWin = imeWin;
7887 } else {
7888 navColorWin = opaqueOrDimming;
7889 }
7890
7891 if (navColorWin != null) {
7892 if (navColorWin == opaque) {
7893 // If the top fullscreen-or-dimming window is also the top fullscreen, respect
7894 // its light flag.
7895 vis &= ~View.SYSTEM_UI_FLAG_LIGHT_NAVIGATION_BAR;
7896 vis |= PolicyControl.getSystemUiVisibility(navColorWin, null)
7897 & View.SYSTEM_UI_FLAG_LIGHT_NAVIGATION_BAR;
7898 } else if (navColorWin.isDimming() || navColorWin == imeWin) {
7899 // Otherwise if it's dimming or it's the IME window, clear the light flag.
7900 vis &= ~View.SYSTEM_UI_FLAG_LIGHT_NAVIGATION_BAR;
7901 }
7902 }
7903 return vis;
7904 }
7905
Jorim Jaggi8f5701b2016-04-04 18:36:02 -07007906 private boolean drawsSystemBarBackground(WindowState win) {
7907 return win == null || (win.getAttrs().flags & FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS) != 0;
7908 }
7909
7910 private boolean forcesDrawStatusBarBackground(WindowState win) {
7911 return win == null || (win.getAttrs().privateFlags
7912 & PRIVATE_FLAG_FORCE_DRAW_STATUS_BAR_BACKGROUND) != 0;
7913 }
7914
John Spurlock79da8332013-09-20 12:04:47 -04007915 private int updateSystemBarsLw(WindowState win, int oldVis, int vis) {
Wale Ogunwale6e94a9e2015-10-07 15:35:49 -07007916 final boolean dockedStackVisible = mWindowManagerInternal.isStackVisible(DOCKED_STACK_ID);
7917 final boolean freeformStackVisible =
7918 mWindowManagerInternal.isStackVisible(FREEFORM_WORKSPACE_STACK_ID);
Jorim Jaggi9511b0f2016-01-29 19:12:44 -08007919 final boolean resizing = mWindowManagerInternal.isDockedDividerResizing();
7920
7921 // We need to force system bars when the docked stack is visible, when the freeform stack
7922 // is visible but also when we are resizing for the transitions when docked stack
7923 // visibility changes.
Jorim Jaggi0ffd49c2016-02-12 15:04:21 -08007924 mForceShowSystemBars = dockedStackVisible || freeformStackVisible || resizing;
Yorke Lee9b2ffb32016-03-07 20:42:01 -08007925 final boolean forceOpaqueStatusBar = mForceShowSystemBars && !mForceStatusBarFromKeyguard;
Wale Ogunwale6e94a9e2015-10-07 15:35:49 -07007926
John Spurlockbd957402013-10-03 11:38:39 -04007927 // apply translucent bar vis flags
Jorim Jaggife762342016-10-13 14:33:27 +02007928 WindowState fullscreenTransWin = isStatusBarKeyguard() && !mKeyguardOccluded
Jorim Jaggi380ecb82014-03-14 17:25:20 +01007929 ? mStatusBar
John Spurlockbd957402013-10-03 11:38:39 -04007930 : mTopFullscreenOpaqueWindowState;
Jorim Jaggi8f5701b2016-04-04 18:36:02 -07007931 vis = mStatusBarController.applyTranslucentFlagLw(fullscreenTransWin, vis, oldVis);
7932 vis = mNavigationBarController.applyTranslucentFlagLw(fullscreenTransWin, vis, oldVis);
7933 final int dockedVis = mStatusBarController.applyTranslucentFlagLw(
7934 mTopDockedOpaqueWindowState, 0, 0);
7935
7936 final boolean fullscreenDrawsStatusBarBackground =
7937 (drawsSystemBarBackground(mTopFullscreenOpaqueWindowState)
7938 && (vis & View.STATUS_BAR_TRANSLUCENT) == 0)
7939 || forcesDrawStatusBarBackground(mTopFullscreenOpaqueWindowState);
7940 final boolean dockedDrawsStatusBarBackground =
7941 (drawsSystemBarBackground(mTopDockedOpaqueWindowState)
7942 && (dockedVis & View.STATUS_BAR_TRANSLUCENT) == 0)
7943 || forcesDrawStatusBarBackground(mTopDockedOpaqueWindowState);
John Spurlockbd957402013-10-03 11:38:39 -04007944
John Spurlock27735a42013-08-14 17:57:38 -04007945 // prevent status bar interaction from clearing certain flags
Selim Cinekf83e8242015-05-19 18:08:14 -07007946 int type = win.getAttrs().type;
7947 boolean statusBarHasFocus = type == TYPE_STATUS_BAR;
John Spurlock08ffcf52014-07-11 10:13:46 -04007948 if (statusBarHasFocus && !isStatusBarKeyguard()) {
John Spurlockad3e6cb2013-04-30 08:47:43 -04007949 int flags = View.SYSTEM_UI_FLAG_FULLSCREEN
7950 | View.SYSTEM_UI_FLAG_HIDE_NAVIGATION
John Spurlockcfc359a2013-09-05 10:42:03 -04007951 | View.SYSTEM_UI_FLAG_IMMERSIVE
Jorim Jaggi73fef8d2015-02-16 17:32:28 +01007952 | View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY
7953 | View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR;
Jorim Jaggife762342016-10-13 14:33:27 +02007954 if (mKeyguardOccluded) {
Jorim Jaggi5cf17872014-03-26 18:31:48 +01007955 flags |= View.STATUS_BAR_TRANSLUCENT | View.NAVIGATION_BAR_TRANSLUCENT;
7956 }
John Spurlockbd957402013-10-03 11:38:39 -04007957 vis = (vis & ~flags) | (oldVis & flags);
John Spurlockad3e6cb2013-04-30 08:47:43 -04007958 }
John Spurlockad3e6cb2013-04-30 08:47:43 -04007959
Jorim Jaggi8f5701b2016-04-04 18:36:02 -07007960 if (fullscreenDrawsStatusBarBackground && dockedDrawsStatusBarBackground) {
7961 vis |= View.STATUS_BAR_TRANSPARENT;
7962 vis &= ~View.STATUS_BAR_TRANSLUCENT;
7963 } else if ((!areTranslucentBarsAllowed() && fullscreenTransWin != mStatusBar)
Yorke Lee9b2ffb32016-03-07 20:42:01 -08007964 || forceOpaqueStatusBar) {
7965 vis &= ~(View.STATUS_BAR_TRANSLUCENT | View.STATUS_BAR_TRANSPARENT);
Alan Viverette5a0f4ec2013-10-07 15:10:29 -07007966 }
7967
Yorke Lee9b2ffb32016-03-07 20:42:01 -08007968 vis = configureNavBarOpacity(vis, dockedStackVisible, freeformStackVisible, resizing);
Yorke Lee2e4b7322016-03-02 17:33:06 -08007969
John Spurlock27735a42013-08-14 17:57:38 -04007970 // update status bar
John Spurlockf1a36642013-10-12 17:50:42 -04007971 boolean immersiveSticky =
7972 (vis & View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY) != 0;
Wale Ogunwale6e94a9e2015-10-07 15:35:49 -07007973 final boolean hideStatusBarWM =
7974 mTopFullscreenOpaqueWindowState != null
7975 && (PolicyControl.getWindowFlags(mTopFullscreenOpaqueWindowState, null)
John Spurlock27735a42013-08-14 17:57:38 -04007976 & WindowManager.LayoutParams.FLAG_FULLSCREEN) != 0;
Wale Ogunwale6e94a9e2015-10-07 15:35:49 -07007977 final boolean hideStatusBarSysui =
John Spurlock27735a42013-08-14 17:57:38 -04007978 (vis & View.SYSTEM_UI_FLAG_FULLSCREEN) != 0;
Wale Ogunwale6e94a9e2015-10-07 15:35:49 -07007979 final boolean hideNavBarSysui =
John Spurlockf1a36642013-10-12 17:50:42 -04007980 (vis & View.SYSTEM_UI_FLAG_HIDE_NAVIGATION) != 0;
John Spurlockad3e6cb2013-04-30 08:47:43 -04007981
Wale Ogunwale6e94a9e2015-10-07 15:35:49 -07007982 final boolean transientStatusBarAllowed = mStatusBar != null
Jorim Jaggi0ffd49c2016-02-12 15:04:21 -08007983 && (statusBarHasFocus || (!mForceShowSystemBars
Wale Ogunwale6e94a9e2015-10-07 15:35:49 -07007984 && (hideStatusBarWM || (hideStatusBarSysui && immersiveSticky))));
John Spurlock27735a42013-08-14 17:57:38 -04007985
Wale Ogunwale6e94a9e2015-10-07 15:35:49 -07007986 final boolean transientNavBarAllowed = mNavigationBar != null
Jorim Jaggi0ffd49c2016-02-12 15:04:21 -08007987 && !mForceShowSystemBars && hideNavBarSysui && immersiveSticky;
John Spurlockf1a36642013-10-12 17:50:42 -04007988
Adrian Roosddc8b272015-05-21 16:28:27 -07007989 final long now = SystemClock.uptimeMillis();
7990 final boolean pendingPanic = mPendingPanicGestureUptime != 0
7991 && now - mPendingPanicGestureUptime <= PANIC_GESTURE_EXPIRATION;
7992 if (pendingPanic && hideNavBarSysui && !isStatusBarKeyguard() && mKeyguardDrawComplete) {
7993 // The user performed the panic gesture recently, we're about to hide the bars,
7994 // we're no longer on the Keyguard and the screen is ready. We can now request the bars.
7995 mPendingPanicGestureUptime = 0;
7996 mStatusBarController.showTransient();
Adrian Roos1f425902016-07-22 10:37:50 -07007997 if (!isNavBarEmpty(vis)) {
7998 mNavigationBarController.showTransient();
7999 }
Adrian Roosddc8b272015-05-21 16:28:27 -07008000 }
8001
Wale Ogunwale6e94a9e2015-10-07 15:35:49 -07008002 final boolean denyTransientStatus = mStatusBarController.isTransientShowRequested()
John Spurlockf1a36642013-10-12 17:50:42 -04008003 && !transientStatusBarAllowed && hideStatusBarSysui;
Wale Ogunwale6e94a9e2015-10-07 15:35:49 -07008004 final boolean denyTransientNav = mNavigationBarController.isTransientShowRequested()
John Spurlockf1a36642013-10-12 17:50:42 -04008005 && !transientNavBarAllowed;
Jorim Jaggi0ffd49c2016-02-12 15:04:21 -08008006 if (denyTransientStatus || denyTransientNav || mForceShowSystemBars) {
John Spurlock27735a42013-08-14 17:57:38 -04008007 // clear the clearable flags instead
John Spurlockf1a36642013-10-12 17:50:42 -04008008 clearClearableFlagsLw();
tiger_huangc58d7562014-10-23 20:24:19 +08008009 vis &= ~View.SYSTEM_UI_CLEARABLE_FLAGS;
John Spurlockad3e6cb2013-04-30 08:47:43 -04008010 }
John Spurlock27735a42013-08-14 17:57:38 -04008011
Selim Cinekf98702e2015-05-20 22:48:40 -07008012 final boolean immersive = (vis & View.SYSTEM_UI_FLAG_IMMERSIVE) != 0;
8013 immersiveSticky = (vis & View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY) != 0;
8014 final boolean navAllowedHidden = immersive || immersiveSticky;
8015
Wale Ogunwale5cd907d2017-01-26 14:14:08 -08008016 if (hideNavBarSysui && !navAllowedHidden
8017 && getWindowLayerLw(win) > getWindowLayerFromTypeLw(TYPE_INPUT_CONSUMER)) {
Selim Cinekf98702e2015-05-20 22:48:40 -07008018 // We can't hide the navbar from this window otherwise the input consumer would not get
8019 // the input events.
8020 vis = (vis & ~View.SYSTEM_UI_FLAG_HIDE_NAVIGATION);
8021 }
8022
John Spurlock27735a42013-08-14 17:57:38 -04008023 vis = mStatusBarController.updateVisibilityLw(transientStatusBarAllowed, oldVis, vis);
8024
8025 // update navigation bar
John Spurlockf1a36642013-10-12 17:50:42 -04008026 boolean oldImmersiveMode = isImmersiveMode(oldVis);
8027 boolean newImmersiveMode = isImmersiveMode(vis);
8028 if (win != null && oldImmersiveMode != newImmersiveMode) {
John Spurlock79da8332013-09-20 12:04:47 -04008029 final String pkg = win.getOwningPackage();
Amith Yamasani02a03812016-04-22 17:32:00 -07008030 mImmersiveModeConfirmation.immersiveModeChangedLw(pkg, newImmersiveMode,
Adrian Roos7aaa5512016-07-12 15:27:24 -07008031 isUserSetupComplete(), isNavBarEmpty(win.getSystemUiVisibility()));
John Spurlock34e13d92013-08-10 06:52:28 -04008032 }
John Spurlock27735a42013-08-14 17:57:38 -04008033
John Spurlockf1a36642013-10-12 17:50:42 -04008034 vis = mNavigationBarController.updateVisibilityLw(transientNavBarAllowed, oldVis, vis);
8035
Jorim Jaggi40db0292016-06-27 17:58:03 -07008036 vis = updateLightNavigationBarLw(vis, mTopFullscreenOpaqueWindowState,
8037 mTopFullscreenOpaqueOrDimmingWindowState);
8038
John Spurlocke1f366f2013-08-05 12:22:40 -04008039 return vis;
John Spurlockad3e6cb2013-04-30 08:47:43 -04008040 }
8041
Yorke Lee9b2ffb32016-03-07 20:42:01 -08008042 /**
8043 * @return the current visibility flags with the nav-bar opacity related flags toggled based
8044 * on the nav bar opacity rules chosen by {@link #mNavBarOpacityMode}.
8045 */
8046 private int configureNavBarOpacity(int visibility, boolean dockedStackVisible,
8047 boolean freeformStackVisible, boolean isDockedDividerResizing) {
8048 if (mNavBarOpacityMode == NAV_BAR_OPAQUE_WHEN_FREEFORM_OR_DOCKED) {
8049 if (dockedStackVisible || freeformStackVisible || isDockedDividerResizing) {
8050 visibility = setNavBarOpaqueFlag(visibility);
8051 }
8052 } else if (mNavBarOpacityMode == NAV_BAR_TRANSLUCENT_WHEN_FREEFORM_OPAQUE_OTHERWISE) {
8053 if (isDockedDividerResizing) {
8054 visibility = setNavBarOpaqueFlag(visibility);
8055 } else if (freeformStackVisible) {
8056 visibility = setNavBarTranslucentFlag(visibility);
8057 } else {
8058 visibility = setNavBarOpaqueFlag(visibility);
8059 }
8060 }
8061
8062 if (!areTranslucentBarsAllowed()) {
8063 visibility &= ~View.NAVIGATION_BAR_TRANSLUCENT;
8064 }
8065 return visibility;
8066 }
8067
8068 private int setNavBarOpaqueFlag(int visibility) {
8069 return visibility &= ~(View.NAVIGATION_BAR_TRANSLUCENT | View.NAVIGATION_BAR_TRANSPARENT);
8070 }
8071
8072 private int setNavBarTranslucentFlag(int visibility) {
8073 visibility &= ~View.NAVIGATION_BAR_TRANSPARENT;
8074 return visibility |= View.NAVIGATION_BAR_TRANSLUCENT;
8075 }
8076
John Spurlockf1a36642013-10-12 17:50:42 -04008077 private void clearClearableFlagsLw() {
8078 int newVal = mResettingSystemUiFlags | View.SYSTEM_UI_CLEARABLE_FLAGS;
8079 if (newVal != mResettingSystemUiFlags) {
8080 mResettingSystemUiFlags = newVal;
8081 mWindowManagerFuncs.reevaluateStatusBarVisibility();
8082 }
8083 }
8084
8085 private boolean isImmersiveMode(int vis) {
8086 final int flags = View.SYSTEM_UI_FLAG_IMMERSIVE | View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY;
John Spurlock34e13d92013-08-10 06:52:28 -04008087 return mNavigationBar != null
8088 && (vis & View.SYSTEM_UI_FLAG_HIDE_NAVIGATION) != 0
Daniel Sandler900ece52013-10-18 15:53:27 -04008089 && (vis & flags) != 0
8090 && canHideNavigationBar();
John Spurlock34e13d92013-08-10 06:52:28 -04008091 }
8092
Adrian Roos7aaa5512016-07-12 15:27:24 -07008093 private static boolean isNavBarEmpty(int systemUiFlags) {
8094 final int disableNavigationBar = (View.STATUS_BAR_DISABLE_HOME
8095 | View.STATUS_BAR_DISABLE_BACK
8096 | View.STATUS_BAR_DISABLE_RECENT);
8097
8098 return (systemUiFlags & disableNavigationBar) == disableNavigationBar;
8099 }
8100
Alan Viverette5a0f4ec2013-10-07 15:10:29 -07008101 /**
Daniel Sandlerdd73ee42013-10-11 22:19:59 -04008102 * @return whether the navigation or status bar can be made translucent
8103 *
8104 * This should return true unless touch exploration is not enabled or
8105 * R.boolean.config_enableTranslucentDecor is false.
Alan Viverette5a0f4ec2013-10-07 15:10:29 -07008106 */
Daniel Sandlerdd73ee42013-10-11 22:19:59 -04008107 private boolean areTranslucentBarsAllowed() {
Alan Viverette817f3cd2015-08-13 11:40:14 -04008108 return mTranslucentDecorEnabled;
Alan Viverette5a0f4ec2013-10-07 15:10:29 -07008109 }
8110
Daniel Sandler0c4ccff2011-10-19 16:39:14 -04008111 // Use this instead of checking config_showNavigationBar so that it can be consistently
8112 // overridden by qemu.hw.mainkeys in the emulator.
Craig Mautnereda67292013-04-28 13:50:14 -07008113 @Override
Daniel Sandler0c4ccff2011-10-19 16:39:14 -04008114 public boolean hasNavigationBar() {
8115 return mHasNavigationBar;
8116 }
8117
satok1bc0a492012-04-25 22:47:12 +09008118 @Override
8119 public void setLastInputMethodWindowLw(WindowState ime, WindowState target) {
8120 mLastInputMethodWindow = ime;
8121 mLastInputMethodTargetWindow = target;
8122 }
8123
Craig Mautnerf1b67412012-09-19 13:18:29 -07008124 @Override
Yohei Yukawad6475a62017-04-17 10:35:27 -07008125 public void setDismissImeOnBackKeyPressed(boolean newValue) {
Yohei Yukawaabbe1ac2017-04-18 09:43:05 -07008126 mDismissImeOnBackKeyPressed = newValue;
Yohei Yukawad6475a62017-04-17 10:35:27 -07008127 }
8128
8129 @Override
Satoshi Kataoka658c7b82013-10-10 17:03:51 +09008130 public int getInputMethodWindowVisibleHeightLw() {
8131 return mDockBottom - mCurBottom;
8132 }
8133
8134 @Override
Craig Mautnerf1b67412012-09-19 13:18:29 -07008135 public void setCurrentUserLw(int newUserId) {
Craig Mautnerd625ab22013-09-06 13:40:31 -07008136 mCurrentUserId = newUserId;
Jim Miller5ecd8112013-01-09 18:50:26 -08008137 if (mKeyguardDelegate != null) {
8138 mKeyguardDelegate.setCurrentUser(newUserId);
Craig Mautnerf1b67412012-09-19 13:18:29 -07008139 }
Phil Weaverce687c52017-03-15 08:51:52 -07008140 if (mAccessibilityShortcutController != null) {
8141 mAccessibilityShortcutController.setCurrentUser(newUserId);
8142 }
Adrian Roosf2efdd82016-04-15 17:43:18 -07008143 StatusBarManagerInternal statusBar = getStatusBarManagerInternal();
Adrian Roos2a629102016-04-15 16:28:03 -07008144 if (statusBar != null) {
Adrian Roosf2efdd82016-04-15 17:43:18 -07008145 statusBar.setCurrentUser(newUserId);
John Spurlock13451a22012-09-28 14:40:41 -04008146 }
Dianne Hackborn2ea9bae2012-11-02 18:43:48 -07008147 setLastInputMethodWindowLw(null, null);
Craig Mautnerf1b67412012-09-19 13:18:29 -07008148 }
8149
8150 @Override
Evan Rosky18396452016-07-27 15:19:37 -07008151 public void setSwitchingUser(boolean switching) {
8152 mKeyguardDelegate.setSwitchingUser(switching);
8153 }
8154
8155 @Override
Svetoslav Ganov545252f2012-12-10 18:29:24 -08008156 public boolean canMagnifyWindow(int windowType) {
8157 switch (windowType) {
8158 case WindowManager.LayoutParams.TYPE_INPUT_METHOD:
8159 case WindowManager.LayoutParams.TYPE_INPUT_METHOD_DIALOG:
8160 case WindowManager.LayoutParams.TYPE_NAVIGATION_BAR:
8161 case WindowManager.LayoutParams.TYPE_MAGNIFICATION_OVERLAY: {
8162 return false;
8163 }
8164 }
8165 return true;
8166 }
8167
8168 @Override
8169 public boolean isTopLevelWindow(int windowType) {
8170 if (windowType >= WindowManager.LayoutParams.FIRST_SUB_WINDOW
8171 && windowType <= WindowManager.LayoutParams.LAST_SUB_WINDOW) {
8172 return (windowType == WindowManager.LayoutParams.TYPE_APPLICATION_ATTACHED_DIALOG);
8173 }
8174 return true;
8175 }
8176
Jim Miller4eeb4f62012-11-08 00:04:29 -08008177 @Override
Robert Carr6da3cc02016-06-16 15:17:07 -07008178 public boolean shouldRotateSeamlessly(int oldRotation, int newRotation) {
8179 // For the upside down rotation we don't rotate seamlessly as the navigation
8180 // bar moves position.
8181 // Note most apps (using orientation:sensor or user as opposed to fullSensor)
8182 // will not enter the reverse portrait orientation, so actually the
8183 // orientation won't change at all.
8184 if (oldRotation == mUpsideDownRotation || newRotation == mUpsideDownRotation) {
8185 return false;
8186 }
Robert Carr0b9ac5a2016-10-26 14:12:14 -07008187 // If the navigation bar can't change sides, then it will
8188 // jump when we change orientations and we don't rotate
8189 // seamlessly.
8190 if (!mNavigationBarCanMove) {
8191 return false;
8192 }
Robert Carr6da3cc02016-06-16 15:17:07 -07008193 int delta = newRotation - oldRotation;
8194 if (delta < 0) delta += 4;
8195 // Likewise we don't rotate seamlessly for 180 degree rotations
Geoffrey Pitschb2d6ed32016-08-24 10:37:19 -04008196 // in this case the surfaces never resize, and our logic to
Robert Carr6da3cc02016-06-16 15:17:07 -07008197 // revert the transformations on size change will fail. We could
8198 // fix this in the future with the "tagged" frames idea.
8199 if (delta == Surface.ROTATION_180) {
8200 return false;
8201 }
8202
Robert Carr57d9fbd2016-08-15 12:00:35 -07008203 final WindowState w = mTopFullscreenOpaqueWindowState;
Robert Carr828ec3dc2016-08-22 13:32:34 -07008204 if (w != mFocusedWindow) {
8205 return false;
8206 }
Robert Carr57d9fbd2016-08-15 12:00:35 -07008207
Robert Carr606f4d52016-06-30 14:36:27 -07008208 // We only enable seamless rotation if the top window has requested
8209 // it and is in the fullscreen opaque state. Seamless rotation
8210 // requires freezing various Surface states and won't work well
8211 // with animations, so we disable it in the animation case for now.
Robert Carr1ccd4252016-08-15 12:05:21 -07008212 if (w != null && !w.isAnimatingLw() &&
Robert Carr57d9fbd2016-08-15 12:00:35 -07008213 ((w.getAttrs().rotationAnimation == ROTATION_ANIMATION_JUMPCUT) ||
8214 (w.getAttrs().rotationAnimation == ROTATION_ANIMATION_SEAMLESS))) {
Robert Carr6da3cc02016-06-16 15:17:07 -07008215 return true;
8216 }
8217 return false;
8218 }
8219
8220 @Override
Jeff Brownd7a04de2012-06-17 14:17:52 -07008221 public void dump(String prefix, PrintWriter pw, String[] args) {
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08008222 pw.print(prefix); pw.print("mSafeMode="); pw.print(mSafeMode);
Dianne Hackbornba24e4d2011-09-01 11:17:06 -07008223 pw.print(" mSystemReady="); pw.print(mSystemReady);
8224 pw.print(" mSystemBooted="); pw.println(mSystemBooted);
Jeff Brown2e7760e2012-04-11 15:14:55 -07008225 pw.print(prefix); pw.print("mLidState="); pw.print(mLidState);
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08008226 pw.print(" mLidOpenRotation="); pw.print(mLidOpenRotation);
Michael Wright3818c922014-09-02 13:59:07 -07008227 pw.print(" mCameraLensCoverState="); pw.print(mCameraLensCoverState);
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08008228 pw.print(" mHdmiPlugged="); pw.println(mHdmiPlugged);
Dianne Hackborne26ab702011-10-16 13:21:33 -07008229 if (mLastSystemUiFlags != 0 || mResettingSystemUiFlags != 0
8230 || mForceClearedSystemUiFlags != 0) {
8231 pw.print(prefix); pw.print("mLastSystemUiFlags=0x");
8232 pw.print(Integer.toHexString(mLastSystemUiFlags));
8233 pw.print(" mResettingSystemUiFlags=0x");
8234 pw.print(Integer.toHexString(mResettingSystemUiFlags));
8235 pw.print(" mForceClearedSystemUiFlags=0x");
8236 pw.println(Integer.toHexString(mForceClearedSystemUiFlags));
Dianne Hackborndf89e652011-10-06 22:35:11 -07008237 }
Dianne Hackborn4eff8d32011-11-10 19:38:40 -08008238 if (mLastFocusNeedsMenu) {
8239 pw.print(prefix); pw.print("mLastFocusNeedsMenu=");
8240 pw.println(mLastFocusNeedsMenu);
8241 }
Jeff Browna20dda42014-05-27 20:57:24 -07008242 pw.print(prefix); pw.print("mWakeGestureEnabledSetting=");
8243 pw.println(mWakeGestureEnabledSetting);
8244
Jeff Brownbcdfc622014-03-06 19:13:04 -08008245 pw.print(prefix); pw.print("mSupportAutoRotation="); pw.println(mSupportAutoRotation);
Daniel Sandler6396c722013-04-16 20:19:09 -04008246 pw.print(prefix); pw.print("mUiMode="); pw.print(mUiMode);
8247 pw.print(" mDockMode="); pw.print(mDockMode);
keunyounga7710492015-09-23 11:33:58 -07008248 pw.print(" mEnableCarDockHomeCapture="); pw.print(mEnableCarDockHomeCapture);
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08008249 pw.print(" mCarDockRotation="); pw.print(mCarDockRotation);
8250 pw.print(" mDeskDockRotation="); pw.println(mDeskDockRotation);
8251 pw.print(prefix); pw.print("mUserRotationMode="); pw.print(mUserRotationMode);
8252 pw.print(" mUserRotation="); pw.print(mUserRotation);
Daniel Sandler2ed6ad62011-02-22 14:54:17 -05008253 pw.print(" mAllowAllRotations="); pw.println(mAllowAllRotations);
Dianne Hackborn6e2281d2012-06-19 17:48:32 -07008254 pw.print(prefix); pw.print("mCurrentAppOrientation="); pw.println(mCurrentAppOrientation);
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08008255 pw.print(prefix); pw.print("mCarDockEnablesAccelerometer=");
8256 pw.print(mCarDockEnablesAccelerometer);
8257 pw.print(" mDeskDockEnablesAccelerometer=");
8258 pw.println(mDeskDockEnablesAccelerometer);
8259 pw.print(prefix); pw.print("mLidKeyboardAccessibility=");
8260 pw.print(mLidKeyboardAccessibility);
8261 pw.print(" mLidNavigationAccessibility="); pw.print(mLidNavigationAccessibility);
Edward Savage-Jones7def60d2015-11-13 13:27:03 +01008262 pw.print(" mLidControlsScreenLock="); pw.println(mLidControlsScreenLock);
Dianne Hackborn6e2281d2012-06-19 17:48:32 -07008263 pw.print(" mLidControlsSleep="); pw.println(mLidControlsSleep);
Jeff Brown6d8fd272014-05-20 21:24:38 -07008264 pw.print(prefix);
Anthony Hugh34f09ca2016-03-04 12:03:37 -08008265 pw.print(" mLongPressOnBackBehavior="); pw.println(mLongPressOnBackBehavior);
8266 pw.print(prefix);
Jeff Brown6d8fd272014-05-20 21:24:38 -07008267 pw.print("mShortPressOnPowerBehavior="); pw.print(mShortPressOnPowerBehavior);
8268 pw.print(" mLongPressOnPowerBehavior="); pw.println(mLongPressOnPowerBehavior);
Jeff Brown13f00f02014-10-31 14:45:50 -07008269 pw.print(prefix);
8270 pw.print("mDoublePressOnPowerBehavior="); pw.print(mDoublePressOnPowerBehavior);
8271 pw.print(" mTriplePressOnPowerBehavior="); pw.println(mTriplePressOnPowerBehavior);
Jeff Brown6d8fd272014-05-20 21:24:38 -07008272 pw.print(prefix); pw.print("mHasSoftInput="); pw.println(mHasSoftInput);
Jeff Brown3ee549c2014-09-22 20:14:39 -07008273 pw.print(prefix); pw.print("mAwake="); pw.println(mAwake);
8274 pw.print(prefix); pw.print("mScreenOnEarly="); pw.print(mScreenOnEarly);
8275 pw.print(" mScreenOnFully="); pw.println(mScreenOnFully);
8276 pw.print(prefix); pw.print("mKeyguardDrawComplete="); pw.print(mKeyguardDrawComplete);
8277 pw.print(" mWindowManagerDrawComplete="); pw.println(mWindowManagerDrawComplete);
8278 pw.print(prefix); pw.print("mOrientationSensorEnabled=");
8279 pw.println(mOrientationSensorEnabled);
Dianne Hackbornc652de82013-02-15 16:32:56 -08008280 pw.print(prefix); pw.print("mOverscanScreen=("); pw.print(mOverscanScreenLeft);
8281 pw.print(","); pw.print(mOverscanScreenTop);
8282 pw.print(") "); pw.print(mOverscanScreenWidth);
8283 pw.print("x"); pw.println(mOverscanScreenHeight);
8284 if (mOverscanLeft != 0 || mOverscanTop != 0
8285 || mOverscanRight != 0 || mOverscanBottom != 0) {
8286 pw.print(prefix); pw.print("mOverscan left="); pw.print(mOverscanLeft);
8287 pw.print(" top="); pw.print(mOverscanTop);
8288 pw.print(" right="); pw.print(mOverscanRight);
8289 pw.print(" bottom="); pw.println(mOverscanBottom);
8290 }
Dianne Hackborn313440842013-02-19 19:22:59 -08008291 pw.print(prefix); pw.print("mRestrictedOverscanScreen=(");
8292 pw.print(mRestrictedOverscanScreenLeft);
8293 pw.print(","); pw.print(mRestrictedOverscanScreenTop);
8294 pw.print(") "); pw.print(mRestrictedOverscanScreenWidth);
8295 pw.print("x"); pw.println(mRestrictedOverscanScreenHeight);
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08008296 pw.print(prefix); pw.print("mUnrestrictedScreen=("); pw.print(mUnrestrictedScreenLeft);
8297 pw.print(","); pw.print(mUnrestrictedScreenTop);
8298 pw.print(") "); pw.print(mUnrestrictedScreenWidth);
8299 pw.print("x"); pw.println(mUnrestrictedScreenHeight);
8300 pw.print(prefix); pw.print("mRestrictedScreen=("); pw.print(mRestrictedScreenLeft);
8301 pw.print(","); pw.print(mRestrictedScreenTop);
8302 pw.print(") "); pw.print(mRestrictedScreenWidth);
8303 pw.print("x"); pw.println(mRestrictedScreenHeight);
Dianne Hackborn5b5cc4d2012-05-16 13:15:00 -07008304 pw.print(prefix); pw.print("mStableFullscreen=("); pw.print(mStableFullscreenLeft);
8305 pw.print(","); pw.print(mStableFullscreenTop);
8306 pw.print(")-("); pw.print(mStableFullscreenRight);
8307 pw.print(","); pw.print(mStableFullscreenBottom); pw.println(")");
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07008308 pw.print(prefix); pw.print("mStable=("); pw.print(mStableLeft);
8309 pw.print(","); pw.print(mStableTop);
8310 pw.print(")-("); pw.print(mStableRight);
8311 pw.print(","); pw.print(mStableBottom); pw.println(")");
Dianne Hackborn5c58de32012-04-28 19:52:37 -07008312 pw.print(prefix); pw.print("mSystem=("); pw.print(mSystemLeft);
8313 pw.print(","); pw.print(mSystemTop);
8314 pw.print(")-("); pw.print(mSystemRight);
8315 pw.print(","); pw.print(mSystemBottom); pw.println(")");
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08008316 pw.print(prefix); pw.print("mCur=("); pw.print(mCurLeft);
8317 pw.print(","); pw.print(mCurTop);
8318 pw.print(")-("); pw.print(mCurRight);
8319 pw.print(","); pw.print(mCurBottom); pw.println(")");
8320 pw.print(prefix); pw.print("mContent=("); pw.print(mContentLeft);
8321 pw.print(","); pw.print(mContentTop);
8322 pw.print(")-("); pw.print(mContentRight);
8323 pw.print(","); pw.print(mContentBottom); pw.println(")");
Dianne Hackborne30e02f2014-05-27 18:24:45 -07008324 pw.print(prefix); pw.print("mVoiceContent=("); pw.print(mVoiceContentLeft);
8325 pw.print(","); pw.print(mVoiceContentTop);
8326 pw.print(")-("); pw.print(mVoiceContentRight);
8327 pw.print(","); pw.print(mVoiceContentBottom); pw.println(")");
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08008328 pw.print(prefix); pw.print("mDock=("); pw.print(mDockLeft);
8329 pw.print(","); pw.print(mDockTop);
8330 pw.print(")-("); pw.print(mDockRight);
8331 pw.print(","); pw.print(mDockBottom); pw.println(")");
Dianne Hackborn5c58de32012-04-28 19:52:37 -07008332 pw.print(prefix); pw.print("mDockLayer="); pw.print(mDockLayer);
8333 pw.print(" mStatusBarLayer="); pw.println(mStatusBarLayer);
Jorim Jaggi8d786932016-10-26 19:08:36 -07008334 pw.print(prefix); pw.print("mShowingDream="); pw.print(mShowingDream);
Jeff Brown061ea992015-04-17 19:55:47 -07008335 pw.print(" mDreamingLockscreen="); pw.print(mDreamingLockscreen);
8336 pw.print(" mDreamingSleepToken="); pw.println(mDreamingSleepToken);
Dianne Hackborn2ea9bae2012-11-02 18:43:48 -07008337 if (mLastInputMethodWindow != null) {
8338 pw.print(prefix); pw.print("mLastInputMethodWindow=");
8339 pw.println(mLastInputMethodWindow);
8340 }
8341 if (mLastInputMethodTargetWindow != null) {
8342 pw.print(prefix); pw.print("mLastInputMethodTargetWindow=");
8343 pw.println(mLastInputMethodTargetWindow);
8344 }
Yohei Yukawad6475a62017-04-17 10:35:27 -07008345 pw.print(prefix); pw.print("mDismissImeOnBackKeyPressed=");
8346 pw.println(mDismissImeOnBackKeyPressed);
Dianne Hackborn2ea9bae2012-11-02 18:43:48 -07008347 if (mStatusBar != null) {
8348 pw.print(prefix); pw.print("mStatusBar=");
Dianne Hackbornae6688b2015-02-11 17:02:41 -08008349 pw.print(mStatusBar); pw.print(" isStatusBarKeyguard=");
8350 pw.println(isStatusBarKeyguard());
Dianne Hackborn2ea9bae2012-11-02 18:43:48 -07008351 }
8352 if (mNavigationBar != null) {
8353 pw.print(prefix); pw.print("mNavigationBar=");
8354 pw.println(mNavigationBar);
8355 }
Dianne Hackborn2ea9bae2012-11-02 18:43:48 -07008356 if (mFocusedWindow != null) {
8357 pw.print(prefix); pw.print("mFocusedWindow=");
8358 pw.println(mFocusedWindow);
8359 }
8360 if (mFocusedApp != null) {
8361 pw.print(prefix); pw.print("mFocusedApp=");
8362 pw.println(mFocusedApp);
8363 }
Dianne Hackborn2ea9bae2012-11-02 18:43:48 -07008364 if (mTopFullscreenOpaqueWindowState != null) {
8365 pw.print(prefix); pw.print("mTopFullscreenOpaqueWindowState=");
8366 pw.println(mTopFullscreenOpaqueWindowState);
8367 }
Adrian Rooscd3884d2015-02-18 17:25:23 +01008368 if (mTopFullscreenOpaqueOrDimmingWindowState != null) {
8369 pw.print(prefix); pw.print("mTopFullscreenOpaqueOrDimmingWindowState=");
8370 pw.println(mTopFullscreenOpaqueOrDimmingWindowState);
8371 }
Dianne Hackborn891d3fb2013-01-09 18:31:37 -08008372 if (mForcingShowNavBar) {
8373 pw.print(prefix); pw.print("mForcingShowNavBar=");
8374 pw.println(mForcingShowNavBar); pw.print( "mForcingShowNavBarLayer=");
8375 pw.println(mForcingShowNavBarLayer);
8376 }
Dianne Hackborn7ad44382012-10-18 17:46:00 -07008377 pw.print(prefix); pw.print("mTopIsFullscreen="); pw.print(mTopIsFullscreen);
Jorim Jaggife762342016-10-13 14:33:27 +02008378 pw.print(" mKeyguardOccluded="); pw.println(mKeyguardOccluded);
Jorim Jaggi8d786932016-10-26 19:08:36 -07008379 pw.print(" mKeyguardOccludedChanged="); pw.println(mKeyguardOccludedChanged);
8380 pw.print(" mPendingKeyguardOccluded="); pw.println(mPendingKeyguardOccluded);
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07008381 pw.print(prefix); pw.print("mForceStatusBar="); pw.print(mForceStatusBar);
8382 pw.print(" mForceStatusBarFromKeyguard=");
8383 pw.println(mForceStatusBarFromKeyguard);
Jorim Jaggife762342016-10-13 14:33:27 +02008384 pw.print(prefix); pw.print("mHomePressed="); pw.println(mHomePressed);
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08008385 pw.print(prefix); pw.print("mAllowLockscreenWhenOn="); pw.print(mAllowLockscreenWhenOn);
8386 pw.print(" mLockScreenTimeout="); pw.print(mLockScreenTimeout);
8387 pw.print(" mLockScreenTimerActive="); pw.println(mLockScreenTimerActive);
8388 pw.print(prefix); pw.print("mEndcallBehavior="); pw.print(mEndcallBehavior);
8389 pw.print(" mIncallPowerBehavior="); pw.print(mIncallPowerBehavior);
Bryce Leedb776ce2016-09-03 15:02:00 -07008390 pw.print(" mIncallBackBehavior="); pw.print(mIncallBackBehavior);
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08008391 pw.print(" mLongPressOnHomeBehavior="); pw.println(mLongPressOnHomeBehavior);
8392 pw.print(prefix); pw.print("mLandscapeRotation="); pw.print(mLandscapeRotation);
8393 pw.print(" mSeascapeRotation="); pw.println(mSeascapeRotation);
8394 pw.print(prefix); pw.print("mPortraitRotation="); pw.print(mPortraitRotation);
8395 pw.print(" mUpsideDownRotation="); pw.println(mUpsideDownRotation);
Jeff Brownc82c89ed2013-04-17 17:18:15 -07008396 pw.print(prefix); pw.print("mDemoHdmiRotation="); pw.print(mDemoHdmiRotation);
8397 pw.print(" mDemoHdmiRotationLock="); pw.println(mDemoHdmiRotationLock);
8398 pw.print(prefix); pw.print("mUndockedHdmiRotation="); pw.println(mUndockedHdmiRotation);
Sujith Ramakrishnan6bed9bd2017-04-26 12:33:37 -07008399 if (mHasFeatureLeanback) {
8400 pw.print(prefix);
8401 pw.print("mAccessibilityTvKey1Pressed="); pw.println(mAccessibilityTvKey1Pressed);
8402 pw.print(prefix);
8403 pw.print("mAccessibilityTvKey2Pressed="); pw.println(mAccessibilityTvKey2Pressed);
8404 pw.print(prefix);
8405 pw.print("mAccessibilityTvScheduled="); pw.println(mAccessibilityTvScheduled);
8406 }
Jeff Brown600f0032014-05-22 17:06:00 -07008407
Tim Kilbournd7c0c2e2014-05-29 16:08:10 -07008408 mGlobalKeyManager.dump(prefix, pw);
John Spurlock27735a42013-08-14 17:57:38 -04008409 mStatusBarController.dump(pw, prefix);
8410 mNavigationBarController.dump(pw, prefix);
John Spurlockc6d1c602014-01-17 15:22:06 -05008411 PolicyControl.dump(prefix, pw);
Jeff Brown600f0032014-05-22 17:06:00 -07008412
Jeff Browna20dda42014-05-27 20:57:24 -07008413 if (mWakeGestureListener != null) {
8414 mWakeGestureListener.dump(pw, prefix);
8415 }
Jeff Brown600f0032014-05-22 17:06:00 -07008416 if (mOrientationListener != null) {
8417 mOrientationListener.dump(pw, prefix);
8418 }
Filip Gruszczynskicfb31852015-02-25 21:47:12 +00008419 if (mBurnInProtectionHelper != null) {
8420 mBurnInProtectionHelper.dump(prefix, pw);
8421 }
Jorim Jaggi84dc08a2015-09-11 17:45:22 -07008422 if (mKeyguardDelegate != null) {
8423 mKeyguardDelegate.dump(prefix, pw);
8424 }
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08008425 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08008426}