blob: f48db05adbd0dd8b613536eed348867f0f869a1f [file] [log] [blame]
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001/*
Jeff Brown37df39a92015-02-25 15:42:31 -08002 * Copyright (C) 2006 The Android Open Source Project
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
Jorim Jaggib10e33f2015-02-04 21:57:40 +010017package com.android.server.policy;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -080018
Wale Ogunwale3797c222015-10-27 14:21:58 -070019import static android.app.ActivityManager.StackId.DOCKED_STACK_ID;
20import static android.app.ActivityManager.StackId.FREEFORM_WORKSPACE_STACK_ID;
Jorim Jaggi86905582016-02-09 21:36:09 -080021import static android.app.ActivityManager.StackId.HOME_STACK_ID;
Jaewan Kim49117872016-01-19 17:24:08 +090022import static android.content.pm.PackageManager.FEATURE_PICTURE_IN_PICTURE;
23import static android.content.pm.PackageManager.FEATURE_TELEVISION;
24import static android.content.pm.PackageManager.FEATURE_WATCH;
Wale Ogunwaledfc18622016-04-16 15:08:48 -070025import static android.content.res.Configuration.EMPTY;
Sriram Viswanathan9ebbe6a2015-11-16 17:59:22 -080026import static android.content.res.Configuration.UI_MODE_TYPE_CAR;
27import static android.content.res.Configuration.UI_MODE_TYPE_MASK;
Jorim Jaggi5060bd82016-02-19 17:12:19 -080028import static android.view.WindowManager.DOCKED_LEFT;
29import static android.view.WindowManager.DOCKED_RIGHT;
Jorim Jaggi73294b62016-10-26 18:02:36 -070030import static android.view.WindowManager.DOCKED_TOP;
Winson41275482016-10-10 15:17:45 -070031import static android.view.WindowManager.INPUT_CONSUMER_NAVIGATION;
Jorim Jaggi73294b62016-10-26 18:02:36 -070032import static android.view.WindowManager.LayoutParams.FIRST_APPLICATION_WINDOW;
33import static android.view.WindowManager.LayoutParams.FIRST_SUB_WINDOW;
34import static android.view.WindowManager.LayoutParams.FIRST_SYSTEM_WINDOW;
35import static android.view.WindowManager.LayoutParams.FLAG_ALLOW_LOCK_WHILE_SCREEN_ON;
36import static android.view.WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS;
37import static android.view.WindowManager.LayoutParams.FLAG_FORCE_NOT_FULLSCREEN;
38import static android.view.WindowManager.LayoutParams.FLAG_FULLSCREEN;
39import static android.view.WindowManager.LayoutParams.FLAG_LAYOUT_ATTACHED_IN_DECOR;
40import static android.view.WindowManager.LayoutParams.FLAG_LAYOUT_INSET_DECOR;
41import static android.view.WindowManager.LayoutParams.FLAG_LAYOUT_IN_OVERSCAN;
42import static android.view.WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN;
43import static android.view.WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS;
44import static android.view.WindowManager.LayoutParams.FLAG_SHOW_WALLPAPER;
45import static android.view.WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED;
46import static android.view.WindowManager.LayoutParams.LAST_APPLICATION_WINDOW;
47import static android.view.WindowManager.LayoutParams.LAST_SUB_WINDOW;
48import static android.view.WindowManager.LayoutParams.LAST_SYSTEM_WINDOW;
49import static android.view.WindowManager.LayoutParams.MATCH_PARENT;
50import static android.view.WindowManager.LayoutParams.PRIVATE_FLAG_FORCE_DRAW_STATUS_BAR_BACKGROUND;
51import static android.view.WindowManager.LayoutParams.PRIVATE_FLAG_FORCE_STATUS_BAR_VISIBLE_TRANSPARENT;
52import static android.view.WindowManager.LayoutParams.PRIVATE_FLAG_KEYGUARD;
53import static android.view.WindowManager.LayoutParams.PRIVATE_FLAG_SHOW_FOR_ALL_USERS;
54import static android.view.WindowManager.LayoutParams.PRIVATE_FLAG_SYSTEM_ERROR;
55import static android.view.WindowManager.LayoutParams.ROTATION_ANIMATION_CROSSFADE;
56import static android.view.WindowManager.LayoutParams.ROTATION_ANIMATION_JUMPCUT;
57import static android.view.WindowManager.LayoutParams.ROTATION_ANIMATION_ROTATE;
58import static android.view.WindowManager.LayoutParams.ROTATION_ANIMATION_SEAMLESS;
59import static android.view.WindowManager.LayoutParams.SOFT_INPUT_ADJUST_NOTHING;
60import static android.view.WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE;
61import static android.view.WindowManager.LayoutParams.SOFT_INPUT_MASK_ADJUST;
62import static android.view.WindowManager.LayoutParams.TYPE_ACCESSIBILITY_OVERLAY;
63import static android.view.WindowManager.LayoutParams.TYPE_APPLICATION_ABOVE_SUB_PANEL;
64import static android.view.WindowManager.LayoutParams.TYPE_APPLICATION_ATTACHED_DIALOG;
65import static android.view.WindowManager.LayoutParams.TYPE_APPLICATION_MEDIA;
66import static android.view.WindowManager.LayoutParams.TYPE_APPLICATION_MEDIA_OVERLAY;
67import static android.view.WindowManager.LayoutParams.TYPE_APPLICATION_PANEL;
68import static android.view.WindowManager.LayoutParams.TYPE_APPLICATION_STARTING;
69import static android.view.WindowManager.LayoutParams.TYPE_APPLICATION_SUB_PANEL;
70import static android.view.WindowManager.LayoutParams.TYPE_BOOT_PROGRESS;
71import static android.view.WindowManager.LayoutParams.TYPE_DISPLAY_OVERLAY;
72import static android.view.WindowManager.LayoutParams.TYPE_DOCK_DIVIDER;
73import static android.view.WindowManager.LayoutParams.TYPE_DRAG;
74import static android.view.WindowManager.LayoutParams.TYPE_DREAM;
75import static android.view.WindowManager.LayoutParams.TYPE_INPUT_CONSUMER;
76import static android.view.WindowManager.LayoutParams.TYPE_INPUT_METHOD;
77import static android.view.WindowManager.LayoutParams.TYPE_INPUT_METHOD_DIALOG;
78import static android.view.WindowManager.LayoutParams.TYPE_KEYGUARD_DIALOG;
79import static android.view.WindowManager.LayoutParams.TYPE_MAGNIFICATION_OVERLAY;
80import static android.view.WindowManager.LayoutParams.TYPE_NAVIGATION_BAR;
81import static android.view.WindowManager.LayoutParams.TYPE_NAVIGATION_BAR_PANEL;
82import static android.view.WindowManager.LayoutParams.TYPE_PHONE;
83import static android.view.WindowManager.LayoutParams.TYPE_POINTER;
Wale Ogunwale5b6714c2016-11-01 20:54:46 -070084import static android.view.WindowManager.LayoutParams.TYPE_PRESENTATION;
Jorim Jaggi73294b62016-10-26 18:02:36 -070085import static android.view.WindowManager.LayoutParams.TYPE_PRIORITY_PHONE;
86import static android.view.WindowManager.LayoutParams.TYPE_PRIVATE_PRESENTATION;
87import static android.view.WindowManager.LayoutParams.TYPE_QS_DIALOG;
88import static android.view.WindowManager.LayoutParams.TYPE_SCREENSHOT;
89import static android.view.WindowManager.LayoutParams.TYPE_SEARCH_BAR;
90import static android.view.WindowManager.LayoutParams.TYPE_SECURE_SYSTEM_OVERLAY;
91import static android.view.WindowManager.LayoutParams.TYPE_STATUS_BAR;
92import static android.view.WindowManager.LayoutParams.TYPE_STATUS_BAR_PANEL;
93import static android.view.WindowManager.LayoutParams.TYPE_STATUS_BAR_SUB_PANEL;
94import static android.view.WindowManager.LayoutParams.TYPE_SYSTEM_ALERT;
95import static android.view.WindowManager.LayoutParams.TYPE_SYSTEM_DIALOG;
96import static android.view.WindowManager.LayoutParams.TYPE_SYSTEM_ERROR;
97import static android.view.WindowManager.LayoutParams.TYPE_SYSTEM_OVERLAY;
98import static android.view.WindowManager.LayoutParams.TYPE_TOAST;
99import static android.view.WindowManager.LayoutParams.TYPE_VOICE_INTERACTION;
100import static android.view.WindowManager.LayoutParams.TYPE_VOICE_INTERACTION_STARTING;
101import static android.view.WindowManager.LayoutParams.TYPE_VOLUME_OVERLAY;
102import static android.view.WindowManager.LayoutParams.TYPE_WALLPAPER;
Muyuan Li6ca619f2016-03-08 13:30:42 -0800103import static android.view.WindowManager.TAKE_SCREENSHOT_FULLSCREEN;
104import static android.view.WindowManager.TAKE_SCREENSHOT_SELECTED_REGION;
Jaewan Kim49117872016-01-19 17:24:08 +0900105import static android.view.WindowManagerPolicy.WindowManagerFuncs.CAMERA_LENS_COVERED;
Wale Ogunwale6e94a9e2015-10-07 15:35:49 -0700106import static android.view.WindowManagerPolicy.WindowManagerFuncs.CAMERA_LENS_COVER_ABSENT;
107import static android.view.WindowManagerPolicy.WindowManagerFuncs.CAMERA_LENS_UNCOVERED;
Jaewan Kim49117872016-01-19 17:24:08 +0900108import static android.view.WindowManagerPolicy.WindowManagerFuncs.LID_ABSENT;
109import static android.view.WindowManagerPolicy.WindowManagerFuncs.LID_CLOSED;
110import static android.view.WindowManagerPolicy.WindowManagerFuncs.LID_OPEN;
Wale Ogunwale6e94a9e2015-10-07 15:35:49 -0700111
Jorim Jaggife762342016-10-13 14:33:27 +0200112import android.annotation.Nullable;
Dianne Hackborna4972e92012-03-14 10:38:05 -0700113import android.app.ActivityManager;
Jorim Jaggi86905582016-02-09 21:36:09 -0800114import android.app.ActivityManager.StackId;
Jeff Brown061ea992015-04-17 19:55:47 -0700115import android.app.ActivityManagerInternal;
116import android.app.ActivityManagerInternal.SleepToken;
Dianne Hackbornc2293022013-02-06 23:14:49 -0800117import android.app.AppOpsManager;
Daniel Sandler6396c722013-04-16 20:19:09 -0400118import android.app.IUiModeManager;
Dianne Hackborn661cd522011-08-22 00:26:20 -0700119import android.app.ProgressDialog;
Jeff Brownde7a8ea2012-06-13 18:28:57 -0700120import android.app.SearchManager;
John Spurlock97642182013-07-29 17:58:39 -0400121import android.app.StatusBarManager;
Dianne Hackborn78968392010-03-04 20:47:56 -0800122import android.app.UiModeManager;
Dianne Hackborn39c2d712009-09-22 11:41:31 -0700123import android.content.ActivityNotFoundException;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800124import android.content.BroadcastReceiver;
Daniel Sandler0601eb72011-04-13 01:01:32 -0400125import android.content.ComponentName;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800126import android.content.ContentResolver;
127import android.content.Context;
128import android.content.Intent;
Mike Lockwood1753f7f2009-08-24 14:49:07 -0700129import android.content.IntentFilter;
Winson Chung9112ec32011-06-27 13:15:32 -0700130import android.content.ServiceConnection;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800131import android.content.pm.ActivityInfo;
Svet Ganov03f2afc2016-03-04 16:13:03 -0800132import android.content.pm.ApplicationInfo;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800133import android.content.pm.PackageManager;
Daniel Sandler6396c722013-04-16 20:19:09 -0400134import android.content.pm.ResolveInfo;
Dianne Hackborn2f0b1752011-05-31 17:59:49 -0700135import android.content.res.CompatibilityInfo;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800136import android.content.res.Configuration;
137import android.content.res.Resources;
Wale Ogunwaledfc18622016-04-16 15:08:48 -0700138import android.content.res.TypedArray;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800139import android.database.ContentObserver;
Dianne Hackbornc777e072010-02-12 13:07:59 -0800140import android.graphics.PixelFormat;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800141import android.graphics.Rect;
Jinsuk Kime601b712015-07-07 08:01:02 +0900142import android.hardware.hdmi.HdmiControlManager;
143import android.hardware.hdmi.HdmiPlaybackClient;
144import android.hardware.hdmi.HdmiPlaybackClient.OneTouchPlayCallback;
Andrii Kulian112d0562016-03-08 10:44:22 -0800145import android.hardware.input.InputManagerInternal;
Ruchi Kandoi0d434042016-10-03 09:12:02 -0700146import android.hardware.power.V1_0.PowerHint;
John Spurlock7b414672014-07-18 13:02:39 -0400147import android.media.AudioAttributes;
Michael Jurka7a348952012-02-27 13:07:58 -0800148import android.media.AudioManager;
John Spurlock61560172015-02-06 19:46:04 -0500149import android.media.AudioSystem;
Michael Jurka7a348952012-02-27 13:07:58 -0800150import android.media.IAudioService;
Svetoslav Ganov7befb7d2012-09-27 16:49:23 -0700151import android.media.Ringtone;
152import android.media.RingtoneManager;
RoboErik8a2cfc32014-05-16 11:19:38 -0700153import android.media.session.MediaSessionLegacyHelper;
Billy Laucbe540f2015-06-25 01:51:44 +0100154import android.os.Binder;
Svet Ganov03f2afc2016-03-04 16:13:03 -0800155import android.os.Build;
Dianne Hackborn38e29a62011-09-18 14:43:08 -0700156import android.os.Bundle;
Craig Mautner276a6eb2014-11-04 15:32:57 -0800157import android.os.Debug;
Jeff Brown9a538ee2012-08-20 14:56:57 -0700158import android.os.FactoryTest;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800159import android.os.Handler;
160import android.os.IBinder;
Dianne Hackbornb6683c42015-06-18 17:40:33 -0700161import android.os.IDeviceIdleController;
Jeff Brown32cbc38552011-12-01 14:01:49 -0800162import android.os.Looper;
Dianne Hackbornfc8fa632011-08-17 16:20:47 -0700163import android.os.Message;
164import android.os.Messenger;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800165import android.os.PowerManager;
Nick Armstrong-Crews56ecfcc2015-09-07 21:46:50 -0700166import android.os.PowerManagerInternal;
Billy Laucbe540f2015-06-25 01:51:44 +0100167import android.os.Process;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800168import android.os.RemoteException;
169import android.os.ServiceManager;
170import android.os.SystemClock;
171import android.os.SystemProperties;
Dianne Hackbornad7fa7f2011-01-07 14:06:50 -0800172import android.os.UEventObserver;
Dianne Hackbornf02b60a2012-08-16 10:48:27 -0700173import android.os.UserHandle;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800174import android.os.Vibrator;
Michael Wright3818c922014-09-02 13:59:07 -0700175import android.provider.MediaStore;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800176import android.provider.Settings;
Jose Lima9546b202014-07-02 17:21:51 -0700177import android.service.dreams.DreamManagerInternal;
John Spurlockc8b46ca2013-04-08 12:59:26 -0400178import android.service.dreams.DreamService;
179import android.service.dreams.IDreamManager;
Michael Wrightdc63f7b2014-08-21 19:05:21 -0700180import android.speech.RecognizerIntent;
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700181import android.telecom.TelecomManager;
Dianne Hackborn81e56d52011-05-26 00:55:58 -0700182import android.util.DisplayMetrics;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800183import android.util.EventLog;
184import android.util.Log;
Jorim Jaggi73294b62016-10-26 18:02:36 -0700185import android.util.LongSparseArray;
Jorim Jaggif1cdf952016-04-05 21:41:06 -0700186import android.util.MutableBoolean;
Jeff Browna41ca772010-08-11 14:46:32 -0700187import android.util.Slog;
Jeff Brown6651a632011-11-28 12:59:11 -0800188import android.util.SparseArray;
Dianne Hackbornf87d1962012-04-04 12:48:24 -0700189import android.view.Display;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800190import android.view.Gravity;
191import android.view.HapticFeedbackConstants;
Dianne Hackborne0f085d2011-11-30 18:41:15 -0800192import android.view.IApplicationToken;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800193import android.view.IWindowManager;
Jeff Browna41ca772010-08-11 14:46:32 -0700194import android.view.InputChannel;
Jeff Brown4d396052010-10-29 21:50:21 -0700195import android.view.InputDevice;
Jeff Brown4952dfd2011-11-30 19:23:22 -0800196import android.view.InputEvent;
Jeff Brown32cbc38552011-12-01 14:01:49 -0800197import android.view.InputEventReceiver;
Jeff Brown6b53e8d2010-11-10 16:03:06 -0800198import android.view.KeyCharacterMap;
Craig Mautnerae446592012-12-06 19:05:05 -0800199import android.view.KeyCharacterMap.FallbackAction;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800200import android.view.KeyEvent;
201import android.view.MotionEvent;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800202import android.view.Surface;
203import android.view.View;
204import android.view.ViewConfiguration;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800205import android.view.WindowManager;
Jorim Jaggife762342016-10-13 14:33:27 +0200206import android.view.WindowManager.LayoutParams;
Craig Mautnerae446592012-12-06 19:05:05 -0800207import android.view.WindowManagerGlobal;
Craig Mautner8a0da012014-05-31 15:13:37 -0700208import android.view.WindowManagerInternal;
Jorim Jaggife762342016-10-13 14:33:27 +0200209import android.view.WindowManagerInternal.AppTransitionListener;
Craig Mautnerae446592012-12-06 19:05:05 -0800210import android.view.WindowManagerPolicy;
Craig Mautnerae446592012-12-06 19:05:05 -0800211import android.view.accessibility.AccessibilityEvent;
Svetoslav8e3feb12014-02-24 13:46:47 -0800212import android.view.accessibility.AccessibilityManager;
Craig Mautnerae446592012-12-06 19:05:05 -0800213import android.view.animation.Animation;
Jorim Jaggi76a16232014-08-08 17:00:47 +0200214import android.view.animation.AnimationSet;
Craig Mautnerae446592012-12-06 19:05:05 -0800215import android.view.animation.AnimationUtils;
Jorim Jaggi73294b62016-10-26 18:02:36 -0700216
Craig Mautnerae446592012-12-06 19:05:05 -0800217import com.android.internal.R;
Jason Monk8f7f3182015-11-18 16:35:14 -0500218import com.android.internal.logging.MetricsLogger;
Jorim Jaggi241ae102016-11-02 21:57:33 -0700219import com.android.internal.policy.IKeyguardDismissCallback;
Muyuan Li94ce94e2016-02-24 16:20:54 -0800220import com.android.internal.policy.IShortcutService;
Jorim Jaggi73294b62016-10-26 18:02:36 -0700221import com.android.internal.policy.PhoneWindow;
Craig Mautnerae446592012-12-06 19:05:05 -0800222import com.android.internal.statusbar.IStatusBarService;
Filip Gruszczynski2217f612015-05-26 11:32:08 -0700223import com.android.internal.util.ScreenShapeHelper;
Craig Mautnerae446592012-12-06 19:05:05 -0800224import com.android.internal.widget.PointerLocationView;
Adrian Roos5941c982015-09-03 15:59:49 -0700225import com.android.server.GestureLauncherService;
Craig Mautner8a0da012014-05-31 15:13:37 -0700226import com.android.server.LocalServices;
Jorim Jaggib10e33f2015-02-04 21:57:40 +0100227import com.android.server.policy.keyguard.KeyguardServiceDelegate;
Jorim Jaggi4cfdcf52015-07-09 12:13:59 -0700228import com.android.server.policy.keyguard.KeyguardServiceDelegate.DrawnListener;
Jorim Jaggie69c9312016-10-31 18:24:38 -0700229import com.android.server.policy.keyguard.KeyguardStateMonitor.StateCallback;
Jorim Jaggi86905582016-02-09 21:36:09 -0800230import com.android.server.statusbar.StatusBarManagerInternal;
Jorim Jaggife762342016-10-13 14:33:27 +0200231import com.android.server.wm.AppTransition;
Craig Mautnerae446592012-12-06 19:05:05 -0800232
233import java.io.File;
234import java.io.FileReader;
235import java.io.IOException;
236import java.io.PrintWriter;
Craig Mautner276a6eb2014-11-04 15:32:57 -0800237import java.util.List;
Craig Mautnerae446592012-12-06 19:05:05 -0800238
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800239/**
The Android Open Source Project0727d222009-03-11 12:11:58 -0700240 * WindowManagerPolicy implementation for the Android phone UI. This
241 * introduces a new method suffix, Lp, for an internal lock of the
242 * PhoneWindowManager. This is used to protect some internal state, and
John Spurlock04db1762013-05-13 12:46:41 -0400243 * 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 -0700244 * of both of those when held.
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800245 */
246public class PhoneWindowManager implements WindowManagerPolicy {
247 static final String TAG = "WindowManager";
248 static final boolean DEBUG = false;
Joe Onorato43a17652011-04-06 19:22:23 -0700249 static final boolean localLOGV = false;
Jeff Brown40013652012-05-16 21:22:36 -0700250 static final boolean DEBUG_INPUT = false;
Craig Mautnerc0d2d0a2014-10-31 16:25:15 -0700251 static final boolean DEBUG_KEYGUARD = false;
252 static final boolean DEBUG_LAYOUT = false;
Craig Mautner6fbda632012-07-03 09:26:39 -0700253 static final boolean DEBUG_STARTING_WINDOW = false;
Craig Mautner8a0da012014-05-31 15:13:37 -0700254 static final boolean DEBUG_WAKEUP = false;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800255 static final boolean SHOW_STARTING_ANIMATIONS = true;
Joe Onoratod208e702010-10-08 16:22:43 -0400256
Daniel Sandler6396c722013-04-16 20:19:09 -0400257 // Whether to allow dock apps with METADATA_DOCK_HOME to temporarily take over the Home key.
keunyounga7710492015-09-23 11:33:58 -0700258 // No longer recommended for desk docks;
Daniel Sandler6396c722013-04-16 20:19:09 -0400259 static final boolean ENABLE_DESK_DOCK_HOME_CAPTURE = false;
260
Justin Paupore01915a12016-09-28 17:41:26 -0700261 static final boolean ALTERNATE_CAR_MODE_NAV_SIZE = false;
262
Jeff Brown6d8fd272014-05-20 21:24:38 -0700263 static final int SHORT_PRESS_POWER_NOTHING = 0;
264 static final int SHORT_PRESS_POWER_GO_TO_SLEEP = 1;
265 static final int SHORT_PRESS_POWER_REALLY_GO_TO_SLEEP = 2;
266 static final int SHORT_PRESS_POWER_REALLY_GO_TO_SLEEP_AND_GO_HOME = 3;
Bryce Lee01b0c5f2015-02-05 18:24:04 -0800267 static final int SHORT_PRESS_POWER_GO_HOME = 4;
Jeff Brown6d8fd272014-05-20 21:24:38 -0700268
Joe Onoratod208e702010-10-08 16:22:43 -0400269 static final int LONG_PRESS_POWER_NOTHING = 0;
270 static final int LONG_PRESS_POWER_GLOBAL_ACTIONS = 1;
271 static final int LONG_PRESS_POWER_SHUT_OFF = 2;
Jeff Brown9a538ee2012-08-20 14:56:57 -0700272 static final int LONG_PRESS_POWER_SHUT_OFF_NO_CONFIRM = 3;
Michael Jurka3b1fc472011-06-13 10:54:40 -0700273
Anthony Hugh34f09ca2016-03-04 12:03:37 -0800274 static final int LONG_PRESS_BACK_NOTHING = 0;
275 static final int LONG_PRESS_BACK_GO_TO_VOICE_ASSIST = 1;
276
Jeff Brown13f00f02014-10-31 14:45:50 -0700277 static final int MULTI_PRESS_POWER_NOTHING = 0;
278 static final int MULTI_PRESS_POWER_THEATER_MODE = 1;
279 static final int MULTI_PRESS_POWER_BRIGHTNESS_BOOST = 2;
280
Anthony Hugh96e9cc52016-07-12 15:17:24 -0700281 // Number of presses needed before we induce panic press behavior on the back button
282 static final int PANIC_PRESS_BACK_COUNT = 4;
283 static final int PANIC_PRESS_BACK_NOTHING = 0;
284 static final int PANIC_PRESS_BACK_HOME = 1;
285
Michael Jurka3b1fc472011-06-13 10:54:40 -0700286 // These need to match the documentation/constant in
287 // core/res/res/values/config.xml
Joe Onorato46b0d682010-11-22 17:37:27 -0800288 static final int LONG_PRESS_HOME_NOTHING = 0;
Michael Wrightc9ebea72013-01-16 19:25:02 -0800289 static final int LONG_PRESS_HOME_RECENT_SYSTEM_UI = 1;
Jeff Browncaca8812013-05-09 13:34:33 -0700290 static final int LONG_PRESS_HOME_ASSIST = 2;
Jaewan Kim76b7d0d2016-02-12 19:01:02 +0900291 static final int LAST_LONG_PRESS_HOME_BEHAVIOR = LONG_PRESS_HOME_ASSIST;
Jeff Browncaca8812013-05-09 13:34:33 -0700292
293 static final int DOUBLE_TAP_HOME_NOTHING = 0;
294 static final int DOUBLE_TAP_HOME_RECENT_SYSTEM_UI = 1;
Joe Onorato46b0d682010-11-22 17:37:27 -0800295
Jaewan Kim49117872016-01-19 17:24:08 +0900296 static final int SHORT_PRESS_WINDOW_NOTHING = 0;
297 static final int SHORT_PRESS_WINDOW_PICTURE_IN_PICTURE = 1;
298
Filip Gruszczynskia483a1d2015-03-17 19:06:58 +0000299 static final int SHORT_PRESS_SLEEP_GO_TO_SLEEP = 0;
300 static final int SHORT_PRESS_SLEEP_GO_TO_SLEEP_AND_GO_HOME = 1;
301
Anthony Hugh4b13ab82016-05-17 13:03:00 -0700302 static final int PENDING_KEY_NULL = -1;
303
Yorke Lee9b2ffb32016-03-07 20:42:01 -0800304 // Controls navigation bar opacity depending on which workspace stacks are currently
305 // visible.
306 // Nav bar is always opaque when either the freeform stack or docked stack is visible.
307 static final int NAV_BAR_OPAQUE_WHEN_FREEFORM_OR_DOCKED = 0;
308 // Nav bar is always translucent when the freeform stack is visible, otherwise always opaque.
309 static final int NAV_BAR_TRANSLUCENT_WHEN_FREEFORM_OPAQUE_OTHERWISE = 1;
310
Dianne Hackborn5cb8d792009-05-21 17:34:15 -0700311 static final int APPLICATION_MEDIA_SUBLAYER = -2;
312 static final int APPLICATION_MEDIA_OVERLAY_SUBLAYER = -1;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800313 static final int APPLICATION_PANEL_SUBLAYER = 1;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800314 static final int APPLICATION_SUB_PANEL_SUBLAYER = 2;
Wale Ogunwale0a4dc222015-04-14 12:58:42 -0700315 static final int APPLICATION_ABOVE_SUB_PANEL_SUBLAYER = 3;
Craig Mautner88400d32012-09-30 12:35:45 -0700316
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800317 static public final String SYSTEM_DIALOG_REASON_KEY = "reason";
318 static public final String SYSTEM_DIALOG_REASON_GLOBAL_ACTIONS = "globalactions";
319 static public final String SYSTEM_DIALOG_REASON_RECENT_APPS = "recentapps";
Joe Onoratof275f0c2009-11-24 16:11:13 -0500320 static public final String SYSTEM_DIALOG_REASON_HOME_KEY = "homekey";
Jeff Brownde7a8ea2012-06-13 18:28:57 -0700321 static public final String SYSTEM_DIALOG_REASON_ASSIST = "assist";
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800322
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -0700323 /**
324 * These are the system UI flags that, when changing, can cause the layout
325 * of the screen to change.
326 */
327 static final int SYSTEM_UI_CHANGING_LAYOUT =
John Spurlocke1f366f2013-08-05 12:22:40 -0400328 View.SYSTEM_UI_FLAG_HIDE_NAVIGATION
John Spurlock7f4820a2013-10-08 12:54:35 -0400329 | View.SYSTEM_UI_FLAG_FULLSCREEN
330 | View.STATUS_BAR_TRANSLUCENT
Adrian Roosea562512014-05-05 13:33:03 +0200331 | View.NAVIGATION_BAR_TRANSLUCENT
Jorim Jaggi4fa78922015-11-30 17:13:56 -0800332 | View.STATUS_BAR_TRANSPARENT
333 | View.NAVIGATION_BAR_TRANSPARENT;
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -0700334
John Spurlock7b414672014-07-18 13:02:39 -0400335 private static final AudioAttributes VIBRATION_ATTRIBUTES = new AudioAttributes.Builder()
336 .setContentType(AudioAttributes.CONTENT_TYPE_SONIFICATION)
337 .setUsage(AudioAttributes.USAGE_ASSISTANCE_SONIFICATION)
338 .build();
339
Adrian Roosddc8b272015-05-21 16:28:27 -0700340 // The panic gesture may become active only after the keyguard is dismissed and the immersive
341 // app shows again. If that doesn't happen for 30s we drop the gesture.
342 private static final long PANIC_GESTURE_EXPIRATION = 30000;
343
Winson44dbe292016-03-10 14:00:14 -0800344 private static final String SYSUI_PACKAGE = "com.android.systemui";
345 private static final String SYSUI_SCREENSHOT_SERVICE =
346 "com.android.systemui.screenshot.TakeScreenshotService";
347 private static final String SYSUI_SCREENSHOT_ERROR_RECEIVER =
348 "com.android.systemui.screenshot.ScreenshotServiceErrorReceiver";
349
Adrian Roos85d202b2016-06-02 16:27:47 -0700350 private static final int NAV_BAR_BOTTOM = 0;
351 private static final int NAV_BAR_RIGHT = 1;
352 private static final int NAV_BAR_LEFT = 2;
353
Jim Miller5ecd8112013-01-09 18:50:26 -0800354 /**
355 * Keyguard stuff
356 */
Jeff Brown3ee549c2014-09-22 20:14:39 -0700357 private boolean mKeyguardDrawnOnce;
Jim Miller5ecd8112013-01-09 18:50:26 -0800358
Jeff Brown6651a632011-11-28 12:59:11 -0800359 /* Table of Application Launch keys. Maps from key codes to intent categories.
360 *
361 * These are special keys that are used to launch particular kinds of applications,
362 * such as a web browser. HID defines nearly a hundred of them in the Consumer (0x0C)
363 * usage page. We don't support quite that many yet...
364 */
365 static SparseArray<String> sApplicationLaunchKeyCategories;
366 static {
367 sApplicationLaunchKeyCategories = new SparseArray<String>();
368 sApplicationLaunchKeyCategories.append(
369 KeyEvent.KEYCODE_EXPLORER, Intent.CATEGORY_APP_BROWSER);
370 sApplicationLaunchKeyCategories.append(
371 KeyEvent.KEYCODE_ENVELOPE, Intent.CATEGORY_APP_EMAIL);
372 sApplicationLaunchKeyCategories.append(
373 KeyEvent.KEYCODE_CONTACTS, Intent.CATEGORY_APP_CONTACTS);
374 sApplicationLaunchKeyCategories.append(
375 KeyEvent.KEYCODE_CALENDAR, Intent.CATEGORY_APP_CALENDAR);
376 sApplicationLaunchKeyCategories.append(
377 KeyEvent.KEYCODE_MUSIC, Intent.CATEGORY_APP_MUSIC);
378 sApplicationLaunchKeyCategories.append(
379 KeyEvent.KEYCODE_CALCULATOR, Intent.CATEGORY_APP_CALCULATOR);
380 }
381
Craig Mautnerc3daedd2014-09-13 11:17:23 -0700382 /** Amount of time (in milliseconds) to wait for windows drawn before powering on. */
Jorim Jaggi0d210f62015-07-10 14:24:44 -0700383 static final int WAITING_FOR_DRAWN_TIMEOUT = 1000;
Craig Mautnerc3daedd2014-09-13 11:17:23 -0700384
Svetoslav Ganovaa076532016-08-01 19:16:43 -0700385 /** Amount of time (in milliseconds) a toast window can be shown. */
386 public static final int TOAST_WINDOW_TIMEOUT = 3500; // 3.5 seconds
387
Dianne Hackborndf89e652011-10-06 22:35:11 -0700388 /**
389 * Lock protecting internal state. Must not call out into window
390 * manager with lock held. (This lock will be acquired in places
391 * where the window manager is calling in with its own lock held.)
392 */
Craig Mautner0bf6ec92012-12-18 08:33:27 -0800393 private final Object mLock = new Object();
Dianne Hackborndf89e652011-10-06 22:35:11 -0700394
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800395 Context mContext;
396 IWindowManager mWindowManager;
Dianne Hackborndf89e652011-10-06 22:35:11 -0700397 WindowManagerFuncs mWindowManagerFuncs;
Craig Mautner8a0da012014-05-31 15:13:37 -0700398 WindowManagerInternal mWindowManagerInternal;
Jeff Brown96307042012-07-27 15:51:34 -0700399 PowerManager mPowerManager;
Jeff Brown061ea992015-04-17 19:55:47 -0700400 ActivityManagerInternal mActivityManagerInternal;
Andrii Kulian112d0562016-03-08 10:44:22 -0800401 InputManagerInternal mInputManagerInternal;
Jose Lima9546b202014-07-02 17:21:51 -0700402 DreamManagerInternal mDreamManagerInternal;
Michael Wrighta4d22d72015-09-16 23:19:26 +0100403 PowerManagerInternal mPowerManagerInternal;
Joe Onorato93056472010-09-10 10:30:46 -0400404 IStatusBarService mStatusBarService;
Jorim Jaggi86905582016-02-09 21:36:09 -0800405 StatusBarManagerInternal mStatusBarManagerInternal;
Jeff Browncaca8812013-05-09 13:34:33 -0700406 boolean mPreloadedRecentApps;
Dianne Hackborn42e620c2012-06-24 13:20:51 -0700407 final Object mServiceAquireLock = new Object();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800408 Vibrator mVibrator; // Vibrator for giving feedback of orientation changes
Jeff Brownde7a8ea2012-06-13 18:28:57 -0700409 SearchManager mSearchManager;
Svetoslav8e3feb12014-02-24 13:46:47 -0800410 AccessibilityManager mAccessibilityManager;
Filip Gruszczynskicfb31852015-02-25 21:47:12 +0000411 BurnInProtectionHelper mBurnInProtectionHelper;
Billy Laucbe540f2015-06-25 01:51:44 +0100412 AppOpsManager mAppOpsManager;
Wale Ogunwale6b15ea52016-04-04 07:28:27 -0700413 private boolean mHasFeatureWatch;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800414
Dianne Hackborn181ceb52009-08-27 22:16:40 -0700415 // Vibrator pattern for haptic feedback of a long press.
416 long[] mLongPressVibePattern;
Craig Mautner88400d32012-09-30 12:35:45 -0700417
Dianne Hackborn181ceb52009-08-27 22:16:40 -0700418 // Vibrator pattern for haptic feedback of virtual key press.
419 long[] mVirtualKeyVibePattern;
Craig Mautner967212c2013-04-13 21:10:58 -0700420
Amith Yamasanic33cb712010-02-10 15:21:49 -0800421 // Vibrator pattern for a short vibration.
422 long[] mKeyboardTapVibePattern;
423
Fabrice Di Meglioeeff63a2013-08-05 12:07:24 -0700424 // Vibrator pattern for a short vibration when tapping on an hour/minute tick of a Clock.
425 long[] mClockTickVibePattern;
426
Fabrice Di Megliobd9152f2013-10-01 11:21:31 -0700427 // Vibrator pattern for a short vibration when tapping on a day/month/year date of a Calendar.
428 long[] mCalendarDateVibePattern;
429
Dianne Hackbornb1a79802009-09-29 15:18:31 -0700430 // Vibrator pattern for haptic feedback during boot when safe mode is disabled.
431 long[] mSafeModeDisabledVibePattern;
Craig Mautner967212c2013-04-13 21:10:58 -0700432
Dianne Hackbornb1a79802009-09-29 15:18:31 -0700433 // Vibrator pattern for haptic feedback during boot when safe mode is enabled.
434 long[] mSafeModeEnabledVibePattern;
Romain Guy8154cd32010-03-29 14:41:15 -0700435
Mady Mellore8608912015-06-05 09:02:55 -0700436 // Vibrator pattern for haptic feedback of a context click.
437 long[] mContextClickVibePattern;
Mady Mellore82067b2015-04-30 09:58:35 -0700438
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800439 /** If true, hitting shift & menu will broadcast Intent.ACTION_BUG_REPORT */
440 boolean mEnableShiftMenuBugReports = false;
Mike Lockwoodd747dc82011-09-13 16:28:22 -0400441
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800442 boolean mSafeMode;
443 WindowState mStatusBar = null;
Dianne Hackborn69cb8752011-05-19 18:13:32 -0700444 int mStatusBarHeight;
Daniel Sandler8956dbb2011-04-22 07:55:02 -0400445 WindowState mNavigationBar = null;
Daniel Sandler36412a72011-08-04 09:35:13 -0400446 boolean mHasNavigationBar = false;
Daniel Sandler4a066c52012-04-20 14:49:13 -0400447 boolean mNavigationBarCanMove = false; // can the navigation bar ever move to the side?
Adrian Roos85d202b2016-06-02 16:27:47 -0700448 int mNavigationBarPosition = NAV_BAR_BOTTOM;
Sriram Viswanathan9ebbe6a2015-11-16 17:59:22 -0800449 int[] mNavigationBarHeightForRotationDefault = new int[4];
450 int[] mNavigationBarWidthForRotationDefault = new int[4];
451 int[] mNavigationBarHeightForRotationInCarMode = new int[4];
452 int[] mNavigationBarWidthForRotationInCarMode = new int[4];
Daniel Sandler8956dbb2011-04-22 07:55:02 -0400453
Muyuan Li94ce94e2016-02-24 16:20:54 -0800454 private LongSparseArray<IShortcutService> mShortcutKeyServices = new LongSparseArray<>();
455
keunyounga7710492015-09-23 11:33:58 -0700456 // Whether to allow dock apps with METADATA_DOCK_HOME to temporarily take over the Home key.
457 // This is for car dock and this is updated from resource.
458 private boolean mEnableCarDockHomeCapture = true;
459
Craig Mautnera631d492014-08-05 15:16:01 -0700460 boolean mBootMessageNeedsHiding;
Jim Miller5ecd8112013-01-09 18:50:26 -0800461 KeyguardServiceDelegate mKeyguardDelegate;
Craig Mautner13f6ea72014-06-23 14:57:02 -0700462 final Runnable mWindowManagerDrawCallback = new Runnable() {
Craig Mautner8a0da012014-05-31 15:13:37 -0700463 @Override
Craig Mautner13f6ea72014-06-23 14:57:02 -0700464 public void run() {
Craig Mautner8a0da012014-05-31 15:13:37 -0700465 if (DEBUG_WAKEUP) Slog.i(TAG, "All windows ready for display!");
466 mHandler.sendEmptyMessage(MSG_WINDOW_MANAGER_DRAWN_COMPLETE);
467 }
468 };
Jorim Jaggi4cfdcf52015-07-09 12:13:59 -0700469 final DrawnListener mKeyguardDrawnCallback = new DrawnListener() {
Craig Mautner8a0da012014-05-31 15:13:37 -0700470 @Override
Jorim Jaggi4cfdcf52015-07-09 12:13:59 -0700471 public void onDrawn() {
472 if (DEBUG_WAKEUP) Slog.d(TAG, "mKeyguardDelegate.ShowListener.onDrawn.");
Craig Mautner8a0da012014-05-31 15:13:37 -0700473 mHandler.sendEmptyMessage(MSG_KEYGUARD_DRAWN_COMPLETE);
474 }
475 };
476
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800477 GlobalActions mGlobalActions;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800478 Handler mHandler;
satok1bc0a492012-04-25 22:47:12 +0900479 WindowState mLastInputMethodWindow = null;
480 WindowState mLastInputMethodTargetWindow = null;
Jeff Brown4aed78b2011-01-14 17:36:55 -0800481
Jeff Brown13f00f02014-10-31 14:45:50 -0700482 // FIXME This state is shared between the input reader and handler thread.
483 // Technically it's broken and buggy but it has been like this for many years
484 // and we have not yet seen any problems. Someday we'll rewrite this logic
485 // so that only one thread is involved in handling input policy. Unfortunately
486 // it's on a critical path for power management so we can't just post the work to the
487 // handler thread. We'll need to resolve this someday by teaching the input dispatcher
488 // to hold wakelocks during dispatch and eliminating the critical path.
489 volatile boolean mPowerKeyHandled;
Anthony Hugh34f09ca2016-03-04 12:03:37 -0800490 volatile boolean mBackKeyHandled;
Bryce Leed9268e32014-11-17 17:40:59 -0800491 volatile boolean mBeganFromNonInteractive;
Jeff Brown13f00f02014-10-31 14:45:50 -0700492 volatile int mPowerKeyPressCounter;
Anthony Hugh96e9cc52016-07-12 15:17:24 -0700493 volatile int mBackKeyPressCounter;
Jeff Brown13f00f02014-10-31 14:45:50 -0700494 volatile boolean mEndCallKeyHandled;
Jorim Jaggif1cdf952016-04-05 21:41:06 -0700495 volatile boolean mCameraGestureTriggeredDuringGoingToSleep;
496 volatile boolean mGoingToSleep;
Jaewan Kimf0fd2182016-04-20 21:17:58 +0900497 volatile boolean mRecentsVisible;
498 volatile boolean mTvPictureInPictureVisible;
Jeff Brown13f00f02014-10-31 14:45:50 -0700499
Anthony Hugh4b13ab82016-05-17 13:03:00 -0700500 // Used to hold the last user key used to wake the device. This helps us prevent up events
501 // from being passed to the foregrounded app without a corresponding down event
502 volatile int mPendingWakeKey = PENDING_KEY_NULL;
503
Winson Chung1e8d71b2014-05-16 17:05:22 -0700504 int mRecentAppsHeldModifiers;
Jeff Browncf39bdf2012-05-18 14:41:19 -0700505 boolean mLanguageSwitchKeyPressed;
Jeff Brown68b909d2011-12-07 16:36:01 -0800506
Jeff Brown2e7760e2012-04-11 15:14:55 -0700507 int mLidState = LID_ABSENT;
Michael Wright3818c922014-09-02 13:59:07 -0700508 int mCameraLensCoverState = CAMERA_LENS_COVER_ABSENT;
Jeff Browndaa37532012-05-01 15:54:03 -0700509 boolean mHaveBuiltInKeyboard;
Jeff Brown4aed78b2011-01-14 17:36:55 -0800510
Dianne Hackbornc777e072010-02-12 13:07:59 -0800511 boolean mSystemReady;
Dianne Hackbornba24e4d2011-09-01 11:17:06 -0700512 boolean mSystemBooted;
Adrian Roos3542f7d2015-07-13 15:57:53 -0700513 private boolean mDeferBindKeyguard;
Dianne Hackbornad7fa7f2011-01-07 14:06:50 -0800514 boolean mHdmiPlugged;
Jinsuk Kime601b712015-07-07 08:01:02 +0900515 HdmiControl mHdmiControl;
Jeff Brown4f5fa282014-06-12 19:19:15 -0700516 IUiModeManager mUiModeManager;
Daniel Sandler6396c722013-04-16 20:19:09 -0400517 int mUiMode;
Dianne Hackborn867ab6472010-04-29 13:28:56 -0700518 int mDockMode = Intent.EXTRA_DOCK_STATE_UNDOCKED;
Mike Lockwood1753f7f2009-08-24 14:49:07 -0700519 int mLidOpenRotation;
Mike Lockwood2d1efbd2009-09-16 12:15:53 -0400520 int mCarDockRotation;
521 int mDeskDockRotation;
Jeff Brownc82c89ed2013-04-17 17:18:15 -0700522 int mUndockedHdmiRotation;
523 int mDemoHdmiRotation;
524 boolean mDemoHdmiRotationLock;
Chong Zhangae6119ff2014-11-11 18:54:39 -0800525 int mDemoRotation;
526 boolean mDemoRotationLock;
Daniel Sandlerb73617d2010-08-17 00:41:00 -0400527
Jeff Browna20dda42014-05-27 20:57:24 -0700528 boolean mWakeGestureEnabledSetting;
529 MyWakeGestureListener mWakeGestureListener;
530
Craig Mautner46ac6fa2013-08-01 10:06:34 -0700531 // Default display does not rotate, apps that require non-default orientation will have to
532 // have the orientation emulated.
533 private boolean mForceDefaultOrientation = false;
534
Daniel Sandlerb73617d2010-08-17 00:41:00 -0400535 int mUserRotationMode = WindowManagerPolicy.USER_ROTATION_FREE;
536 int mUserRotation = Surface.ROTATION_0;
Jeff Brown207673cd2012-06-05 17:47:11 -0700537 boolean mAccelerometerDefault;
Daniel Sandlerb73617d2010-08-17 00:41:00 -0400538
Jeff Brownbcdfc622014-03-06 19:13:04 -0800539 boolean mSupportAutoRotation;
Jeff Brownd3187e32011-09-21 19:26:44 -0700540 int mAllowAllRotations = -1;
Mike Lockwoode9867d22009-09-20 01:59:02 -0400541 boolean mCarDockEnablesAccelerometer;
542 boolean mDeskDockEnablesAccelerometer;
Dianne Hackborn2862fff2009-09-15 22:56:29 -0700543 int mLidKeyboardAccessibility;
544 int mLidNavigationAccessibility;
Edward Savage-Jones7def60d2015-11-13 13:27:03 +0100545 boolean mLidControlsScreenLock;
Jeff Brownc458ce92012-04-30 14:58:40 -0700546 boolean mLidControlsSleep;
Jeff Brown13f00f02014-10-31 14:45:50 -0700547 int mShortPressOnPowerBehavior;
548 int mLongPressOnPowerBehavior;
549 int mDoublePressOnPowerBehavior;
550 int mTriplePressOnPowerBehavior;
Anthony Hugh34f09ca2016-03-04 12:03:37 -0800551 int mLongPressOnBackBehavior;
Anthony Hugh96e9cc52016-07-12 15:17:24 -0700552 int mPanicPressOnBackBehavior;
Filip Gruszczynskia483a1d2015-03-17 19:06:58 +0000553 int mShortPressOnSleepBehavior;
Jaewan Kim49117872016-01-19 17:24:08 +0900554 int mShortPressWindowBehavior;
Jeff Brown3ee549c2014-09-22 20:14:39 -0700555 boolean mAwake;
556 boolean mScreenOnEarly;
557 boolean mScreenOnFully;
558 ScreenOnListener mScreenOnListener;
559 boolean mKeyguardDrawComplete;
560 boolean mWindowManagerDrawComplete;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800561 boolean mOrientationSensorEnabled = false;
562 int mCurrentAppOrientation = ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800563 boolean mHasSoftInput = false;
Daniel Sandlerdd73ee42013-10-11 22:19:59 -0400564 boolean mTranslucentDecorEnabled = true;
RoboErik001c59c2015-01-26 15:53:51 -0800565 boolean mUseTvRouting;
Craig Mautner967212c2013-04-13 21:10:58 -0700566
Jeff Brown70825162012-03-28 17:27:48 -0700567 int mPointerLocationMode = 0; // guarded by mLock
Joe Onorato664644d2011-01-23 17:53:23 -0800568
569 // The last window we were told about in focusChanged.
570 WindowState mFocusedWindow;
Dianne Hackborne0f085d2011-11-30 18:41:15 -0800571 IApplicationToken mFocusedApp;
Joe Onorato664644d2011-01-23 17:53:23 -0800572
Jeff Brown70825162012-03-28 17:27:48 -0700573 PointerLocationView mPointerLocationView;
Jeff Brown32cbc38552011-12-01 14:01:49 -0800574
Dianne Hackbornc652de82013-02-15 16:32:56 -0800575 // The current size of the screen; really; extends into the overscan area of
576 // the screen and doesn't account for any system elements like the status bar.
577 int mOverscanScreenLeft, mOverscanScreenTop;
578 int mOverscanScreenWidth, mOverscanScreenHeight;
579 // The current visible size of the screen; really; (ir)regardless of whether the status
580 // bar can be hidden but not extending into the overscan area.
Joe Onorato29fc2c92010-11-24 10:26:50 -0800581 int mUnrestrictedScreenLeft, mUnrestrictedScreenTop;
582 int mUnrestrictedScreenWidth, mUnrestrictedScreenHeight;
Dianne Hackborn313440842013-02-19 19:22:59 -0800583 // Like mOverscanScreen*, but allowed to move into the overscan region where appropriate.
584 int mRestrictedOverscanScreenLeft, mRestrictedOverscanScreenTop;
585 int mRestrictedOverscanScreenWidth, mRestrictedOverscanScreenHeight;
Dianne Hackborn82de1ae2010-10-28 11:28:39 -0700586 // The current size of the screen; these may be different than (0,0)-(dw,dh)
587 // if the status bar can't be hidden; in that case it effectively carves out
588 // that area of the display from all other windows.
Joe Onorato29fc2c92010-11-24 10:26:50 -0800589 int mRestrictedScreenLeft, mRestrictedScreenTop;
590 int mRestrictedScreenWidth, mRestrictedScreenHeight;
Dianne Hackborn5c58de32012-04-28 19:52:37 -0700591 // During layout, the current screen borders accounting for any currently
592 // visible system UI elements.
593 int mSystemLeft, mSystemTop, mSystemRight, mSystemBottom;
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -0700594 // For applications requesting stable content insets, these are them.
595 int mStableLeft, mStableTop, mStableRight, mStableBottom;
Dianne Hackborn5b5cc4d2012-05-16 13:15:00 -0700596 // For applications requesting stable content insets but have also set the
597 // fullscreen window flag, these are the stable dimensions without the status bar.
598 int mStableFullscreenLeft, mStableFullscreenTop;
599 int mStableFullscreenRight, mStableFullscreenBottom;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800600 // During layout, the current screen borders with all outer decoration
601 // (status bar, input method dock) accounted for.
602 int mCurLeft, mCurTop, mCurRight, mCurBottom;
603 // During layout, the frame in which content should be displayed
604 // to the user, accounting for all screen decoration except for any
605 // space they deem as available for other content. This is usually
606 // the same as mCur*, but may be larger if the screen decor has supplied
607 // content insets.
608 int mContentLeft, mContentTop, mContentRight, mContentBottom;
Dianne Hackborne30e02f2014-05-27 18:24:45 -0700609 // During layout, the frame in which voice content should be displayed
610 // to the user, accounting for all screen decoration except for any
611 // space they deem as available for other content.
612 int mVoiceContentLeft, mVoiceContentTop, mVoiceContentRight, mVoiceContentBottom;
Dianne Hackborn8e11ef02010-11-18 19:47:42 -0800613 // During layout, the current screen borders along which input method
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800614 // windows are placed.
615 int mDockLeft, mDockTop, mDockRight, mDockBottom;
616 // During layout, the layer at which the doc window is placed.
617 int mDockLayer;
Dianne Hackborn5c58de32012-04-28 19:52:37 -0700618 // During layout, this is the layer of the status bar.
619 int mStatusBarLayer;
Dianne Hackborne26ab702011-10-16 13:21:33 -0700620 int mLastSystemUiFlags;
621 // Bits that we are in the process of clearing, so we want to prevent
622 // them from being set by applications until everything has been updated
623 // to have them clear.
624 int mResettingSystemUiFlags = 0;
625 // Bits that we are currently always keeping cleared.
626 int mForceClearedSystemUiFlags = 0;
Jorim Jaggi86905582016-02-09 21:36:09 -0800627 int mLastFullscreenStackSysUiFlags;
628 int mLastDockedStackSysUiFlags;
629 final Rect mNonDockedStackBounds = new Rect();
630 final Rect mDockedStackBounds = new Rect();
631 final Rect mLastNonDockedStackBounds = new Rect();
632 final Rect mLastDockedStackBounds = new Rect();
633
Dianne Hackborn4eff8d32011-11-10 19:38:40 -0800634 // What we last reported to system UI about whether the compatibility
635 // menu needs to be displayed.
636 boolean mLastFocusNeedsMenu = false;
Adrian Roosddc8b272015-05-21 16:28:27 -0700637 // If nonzero, a panic gesture was performed at that time in uptime millis and is still pending.
638 private long mPendingPanicGestureUptime;
Dianne Hackborndf89e652011-10-06 22:35:11 -0700639
Selim Cinekf83e8242015-05-19 18:08:14 -0700640 InputConsumer mInputConsumer = null;
Dianne Hackborndf89e652011-10-06 22:35:11 -0700641
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800642 static final Rect mTmpParentFrame = new Rect();
643 static final Rect mTmpDisplayFrame = new Rect();
Dianne Hackbornc4aad012013-02-22 15:05:25 -0800644 static final Rect mTmpOverscanFrame = new Rect();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800645 static final Rect mTmpContentFrame = new Rect();
646 static final Rect mTmpVisibleFrame = new Rect();
John Spurlock46646232013-09-30 22:32:42 -0400647 static final Rect mTmpDecorFrame = new Rect();
Adrian Roosfa104232014-06-20 16:10:14 -0700648 static final Rect mTmpStableFrame = new Rect();
Dianne Hackborn1f903c32011-09-13 19:18:06 -0700649 static final Rect mTmpNavigationFrame = new Rect();
Filip Gruszczynski2217f612015-05-26 11:32:08 -0700650 static final Rect mTmpOutsetFrame = new Rect();
Jorim Jaggi23bf5462016-05-13 15:24:39 -0700651 private static final Rect mTmpRect = new Rect();
Craig Mautner967212c2013-04-13 21:10:58 -0700652
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800653 WindowState mTopFullscreenOpaqueWindowState;
Adrian Rooscd3884d2015-02-18 17:25:23 +0100654 WindowState mTopFullscreenOpaqueOrDimmingWindowState;
Jorim Jaggi86905582016-02-09 21:36:09 -0800655 WindowState mTopDockedOpaqueWindowState;
656 WindowState mTopDockedOpaqueOrDimmingWindowState;
Joe Onorato93056472010-09-10 10:30:46 -0400657 boolean mTopIsFullscreen;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800658 boolean mForceStatusBar;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -0700659 boolean mForceStatusBarFromKeyguard;
Selim Cinek4a4a2bddc2015-05-07 12:50:19 -0700660 private boolean mForceStatusBarTransparent;
Yorke Lee9b2ffb32016-03-07 20:42:01 -0800661 int mNavBarOpacityMode = NAV_BAR_OPAQUE_WHEN_FREEFORM_OR_DOCKED;
Dianne Hackborn891d3fb2013-01-09 18:31:37 -0800662 boolean mForcingShowNavBar;
663 int mForcingShowNavBarLayer;
Craig Mautnerad09bcc2012-10-08 13:33:11 -0700664
Jorim Jaggife762342016-10-13 14:33:27 +0200665 private boolean mPendingKeyguardOccluded;
666 private boolean mKeyguardOccludedChanged;
Craig Mautnerc9457fa2014-06-06 14:27:48 -0700667
Dianne Hackborn7ad44382012-10-18 17:46:00 -0700668 boolean mShowingDream;
Jorim Jaggi77e10432016-10-26 17:43:56 -0700669 private boolean mLastShowingDream;
Dianne Hackborn7ad44382012-10-18 17:46:00 -0700670 boolean mDreamingLockscreen;
Jeff Brown061ea992015-04-17 19:55:47 -0700671 boolean mDreamingSleepTokenNeeded;
672 SleepToken mDreamingSleepToken;
Jeff Brown48d1b142015-06-10 16:36:03 -0700673 SleepToken mScreenOffSleepToken;
Jim Millerab954542014-10-10 18:21:49 -0700674 volatile boolean mKeyguardOccluded;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800675 boolean mHomePressed;
Jeff Browncaca8812013-05-09 13:34:33 -0700676 boolean mHomeConsumed;
677 boolean mHomeDoubleTapPending;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800678 Intent mHomeIntent;
Dianne Hackborn39c2d712009-09-22 11:41:31 -0700679 Intent mCarDockIntent;
680 Intent mDeskDockIntent;
Jeff Brownfd23e3e2012-05-09 13:34:28 -0700681 boolean mSearchKeyShortcutPending;
682 boolean mConsumeSearchKeyUp;
Jeff Brownde7a8ea2012-06-13 18:28:57 -0700683 boolean mAssistKeyLongPressed;
Michael Wright6a62e552014-06-03 19:19:48 -0700684 boolean mPendingMetaAction;
Andrii Kulian112d0562016-03-08 10:44:22 -0800685 boolean mPendingCapsLockToggle;
686 int mMetaState;
687 int mInitialMetaState;
Jorim Jaggi0ffd49c2016-02-12 15:04:21 -0800688 boolean mForceShowSystemBars;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800689
Mike Lockwood28569302010-01-28 11:54:40 -0500690 // support for activating the lock screen while the screen is on
691 boolean mAllowLockscreenWhenOn;
692 int mLockScreenTimeout;
693 boolean mLockScreenTimerActive;
694
David Brownbaf8d092010-03-08 21:52:59 -0800695 // Behavior of ENDCALL Button. (See Settings.System.END_BUTTON_BEHAVIOR.)
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800696 int mEndcallBehavior;
David Brownbaf8d092010-03-08 21:52:59 -0800697
698 // Behavior of POWER button while in-call and screen on.
699 // (See Settings.Secure.INCALL_POWER_BUTTON_BEHAVIOR.)
700 int mIncallPowerBehavior;
701
Bryce Leedb776ce2016-09-03 15:02:00 -0700702 // Behavior of Back button while in-call and screen on
703 int mIncallBackBehavior;
704
Dianne Hackbornf87d1962012-04-04 12:48:24 -0700705 Display mDisplay;
706
Filip Gruszczynski2987f612015-06-30 15:03:30 -0700707 private int mDisplayRotation;
708
Dianne Hackborn9d132642011-04-21 17:26:39 -0700709 int mLandscapeRotation = 0; // default landscape rotation
710 int mSeascapeRotation = 0; // "other" landscape rotation, 180 degrees from mLandscapeRotation
711 int mPortraitRotation = 0; // default portrait rotation
712 int mUpsideDownRotation = 0; // "other" portrait rotation
Mitsuru Oshima831d0d92009-06-16 18:27:18 -0700713
Dianne Hackbornc652de82013-02-15 16:32:56 -0800714 int mOverscanLeft = 0;
715 int mOverscanTop = 0;
716 int mOverscanRight = 0;
717 int mOverscanBottom = 0;
718
Joe Onorato46b0d682010-11-22 17:37:27 -0800719 // What we do when the user long presses on home
Jeff Browncaca8812013-05-09 13:34:33 -0700720 private int mLongPressOnHomeBehavior;
721
722 // What we do when the user double-taps on home
723 private int mDoubleTapOnHomeBehavior;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800724
Bryce Lee584a4452014-10-21 15:55:55 -0700725 // Allowed theater mode wake actions
726 private boolean mAllowTheaterModeWakeFromKey;
727 private boolean mAllowTheaterModeWakeFromPowerKey;
728 private boolean mAllowTheaterModeWakeFromMotion;
Bryce Lee812d7022014-11-10 13:33:28 -0800729 private boolean mAllowTheaterModeWakeFromMotionWhenNotDreaming;
Bryce Lee584a4452014-10-21 15:55:55 -0700730 private boolean mAllowTheaterModeWakeFromCameraLens;
731 private boolean mAllowTheaterModeWakeFromLidSwitch;
732 private boolean mAllowTheaterModeWakeFromWakeGesture;
733
Bryce Leed3b28402015-03-09 15:49:13 +0000734 // Whether to support long press from power button in non-interactive mode
735 private boolean mSupportLongPressPowerWhenNonInteractive;
736
Bryce Lee55e846d2014-11-04 12:43:44 -0800737 // Whether to go to sleep entering theater mode from power button
738 private boolean mGoToSleepOnButtonPressTheaterMode;
739
Winson Chung9112ec32011-06-27 13:15:32 -0700740 // Screenshot trigger states
Jeff Brownd5bb82d2011-10-12 13:57:59 -0700741 // Time to volume and power must be pressed within this interval of each other.
742 private static final long SCREENSHOT_CHORD_DEBOUNCE_DELAY_MILLIS = 150;
Winson Chung1cea2f32012-10-08 20:42:01 -0700743 // Increase the chord delay when taking a screenshot from the keyguard
744 private static final float KEYGUARD_SCREENSHOT_CHORD_DELAY_MULTIPLIER = 2.5f;
Christopher Tatee90585f2012-03-05 18:56:25 -0800745 private boolean mScreenshotChordEnabled;
Jeff Brown13f00f02014-10-31 14:45:50 -0700746 private boolean mScreenshotChordVolumeDownKeyTriggered;
747 private long mScreenshotChordVolumeDownKeyTime;
748 private boolean mScreenshotChordVolumeDownKeyConsumed;
749 private boolean mScreenshotChordVolumeUpKeyTriggered;
750 private boolean mScreenshotChordPowerKeyTriggered;
751 private long mScreenshotChordPowerKeyTime;
Winson Chung9112ec32011-06-27 13:15:32 -0700752
Michael Wrightb854e242013-02-05 17:54:02 -0800753 /* The number of steps between min and max brightness */
754 private static final int BRIGHTNESS_STEPS = 10;
755
Christopher Tate5e08af02012-09-21 17:17:22 -0700756 SettingsObserver mSettingsObserver;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800757 ShortcutManager mShortcutManager;
758 PowerManager.WakeLock mBroadcastWakeLock;
Jeff Brown13f00f02014-10-31 14:45:50 -0700759 PowerManager.WakeLock mPowerKeyWakeLock;
Jeff Brown40013652012-05-16 21:22:36 -0700760 boolean mHavePendingMediaKeyRepeatWithWakeLock;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800761
Craig Mautnerd625ab22013-09-06 13:40:31 -0700762 private int mCurrentUserId;
763
Justin Kohd378ad72013-04-01 12:18:26 -0700764 // Maps global key codes to the components that will handle them.
765 private GlobalKeyManager mGlobalKeyManager;
766
Jeff Brownfd23e3e2012-05-09 13:34:28 -0700767 // Fallback actions by key code.
768 private final SparseArray<KeyCharacterMap.FallbackAction> mFallbackActions =
769 new SparseArray<KeyCharacterMap.FallbackAction>();
Jeff Brown49ed71d2010-12-06 17:13:33 -0800770
Jorim Jaggi76a16232014-08-08 17:00:47 +0200771 private final LogDecelerateInterpolator mLogDecelerateInterpolator
772 = new LogDecelerateInterpolator(100, 0);
773
Jorim Jaggif1cdf952016-04-05 21:41:06 -0700774 private final MutableBoolean mTmpBoolean = new MutableBoolean(false);
Wale Ogunwale6b15ea52016-04-04 07:28:27 -0700775
Jeff Brown70825162012-03-28 17:27:48 -0700776 private static final int MSG_ENABLE_POINTER_LOCATION = 1;
777 private static final int MSG_DISABLE_POINTER_LOCATION = 2;
Jeff Brown40013652012-05-16 21:22:36 -0700778 private static final int MSG_DISPATCH_MEDIA_KEY_WITH_WAKE_LOCK = 3;
779 private static final int MSG_DISPATCH_MEDIA_KEY_REPEAT_WITH_WAKE_LOCK = 4;
Craig Mautner8a0da012014-05-31 15:13:37 -0700780 private static final int MSG_KEYGUARD_DRAWN_COMPLETE = 5;
781 private static final int MSG_KEYGUARD_DRAWN_TIMEOUT = 6;
782 private static final int MSG_WINDOW_MANAGER_DRAWN_COMPLETE = 7;
Craig Mautner84984fa2014-06-19 11:19:20 -0700783 private static final int MSG_DISPATCH_SHOW_RECENTS = 9;
Alan Viverettee34560b22014-07-10 14:50:06 -0700784 private static final int MSG_DISPATCH_SHOW_GLOBAL_ACTIONS = 10;
Craig Mautnera631d492014-08-05 15:16:01 -0700785 private static final int MSG_HIDE_BOOT_MESSAGE = 11;
Michael Wright869a67c2014-08-26 19:33:06 -0700786 private static final int MSG_LAUNCH_VOICE_ASSIST_WITH_WAKE_LOCK = 12;
Jeff Brown13f00f02014-10-31 14:45:50 -0700787 private static final int MSG_POWER_DELAYED_PRESS = 13;
788 private static final int MSG_POWER_LONG_PRESS = 14;
Jeff Brown061ea992015-04-17 19:55:47 -0700789 private static final int MSG_UPDATE_DREAMING_SLEEP_TOKEN = 15;
Jun Mukaid2e7e352015-07-22 17:14:02 -0700790 private static final int MSG_REQUEST_TRANSIENT_BARS = 16;
Jaewan Kimf0fd2182016-04-20 21:17:58 +0900791 private static final int MSG_SHOW_TV_PICTURE_IN_PICTURE_MENU = 17;
Anthony Hugh34f09ca2016-03-04 12:03:37 -0800792 private static final int MSG_BACK_LONG_PRESS = 18;
Chong Zhang9f7fb092016-05-20 17:03:08 -0700793 private static final int MSG_DISPOSE_INPUT_CONSUMER = 19;
Anthony Hugh96e9cc52016-07-12 15:17:24 -0700794 private static final int MSG_BACK_DELAYED_PRESS = 20;
Jun Mukaid2e7e352015-07-22 17:14:02 -0700795
796 private static final int MSG_REQUEST_TRANSIENT_BARS_ARG_STATUS = 0;
797 private static final int MSG_REQUEST_TRANSIENT_BARS_ARG_NAVIGATION = 1;
Jeff Brown70825162012-03-28 17:27:48 -0700798
799 private class PolicyHandler extends Handler {
800 @Override
801 public void handleMessage(Message msg) {
802 switch (msg.what) {
803 case MSG_ENABLE_POINTER_LOCATION:
804 enablePointerLocation();
805 break;
806 case MSG_DISABLE_POINTER_LOCATION:
807 disablePointerLocation();
808 break;
Jeff Brown40013652012-05-16 21:22:36 -0700809 case MSG_DISPATCH_MEDIA_KEY_WITH_WAKE_LOCK:
810 dispatchMediaKeyWithWakeLock((KeyEvent)msg.obj);
811 break;
812 case MSG_DISPATCH_MEDIA_KEY_REPEAT_WITH_WAKE_LOCK:
813 dispatchMediaKeyRepeatWithWakeLock((KeyEvent)msg.obj);
814 break;
Craig Mautner84984fa2014-06-19 11:19:20 -0700815 case MSG_DISPATCH_SHOW_RECENTS:
Jorim Jaggi681fc7b2016-04-14 22:02:39 -0700816 showRecentApps(false, msg.arg1 != 0);
Craig Mautner84984fa2014-06-19 11:19:20 -0700817 break;
Alan Viverettee34560b22014-07-10 14:50:06 -0700818 case MSG_DISPATCH_SHOW_GLOBAL_ACTIONS:
819 showGlobalActionsInternal();
820 break;
Craig Mautner8a0da012014-05-31 15:13:37 -0700821 case MSG_KEYGUARD_DRAWN_COMPLETE:
822 if (DEBUG_WAKEUP) Slog.w(TAG, "Setting mKeyguardDrawComplete");
Jeff Brown36c4db82014-09-19 12:05:31 -0700823 finishKeyguardDrawn();
Craig Mautner8a0da012014-05-31 15:13:37 -0700824 break;
825 case MSG_KEYGUARD_DRAWN_TIMEOUT:
826 Slog.w(TAG, "Keyguard drawn timeout. Setting mKeyguardDrawComplete");
Jeff Brown36c4db82014-09-19 12:05:31 -0700827 finishKeyguardDrawn();
Craig Mautner8a0da012014-05-31 15:13:37 -0700828 break;
829 case MSG_WINDOW_MANAGER_DRAWN_COMPLETE:
830 if (DEBUG_WAKEUP) Slog.w(TAG, "Setting mWindowManagerDrawComplete");
Jeff Brown36c4db82014-09-19 12:05:31 -0700831 finishWindowsDrawn();
Craig Mautner8a0da012014-05-31 15:13:37 -0700832 break;
Craig Mautnera631d492014-08-05 15:16:01 -0700833 case MSG_HIDE_BOOT_MESSAGE:
834 handleHideBootMessage();
835 break;
Michael Wright869a67c2014-08-26 19:33:06 -0700836 case MSG_LAUNCH_VOICE_ASSIST_WITH_WAKE_LOCK:
837 launchVoiceAssistWithWakeLock(msg.arg1 != 0);
838 break;
Jeff Brown13f00f02014-10-31 14:45:50 -0700839 case MSG_POWER_DELAYED_PRESS:
840 powerPress((Long)msg.obj, msg.arg1 != 0, msg.arg2);
841 finishPowerKeyPress();
842 break;
843 case MSG_POWER_LONG_PRESS:
844 powerLongPress();
845 break;
Jeff Brown061ea992015-04-17 19:55:47 -0700846 case MSG_UPDATE_DREAMING_SLEEP_TOKEN:
847 updateDreamingSleepToken(msg.arg1 != 0);
848 break;
Jun Mukaid2e7e352015-07-22 17:14:02 -0700849 case MSG_REQUEST_TRANSIENT_BARS:
850 WindowState targetBar = (msg.arg1 == MSG_REQUEST_TRANSIENT_BARS_ARG_STATUS) ?
851 mStatusBar : mNavigationBar;
852 if (targetBar != null) {
853 requestTransientBars(targetBar);
854 }
855 break;
Jaewan Kimf0fd2182016-04-20 21:17:58 +0900856 case MSG_SHOW_TV_PICTURE_IN_PICTURE_MENU:
857 showTvPictureInPictureMenuInternal();
Jaewan Kimc552b042016-01-18 16:08:45 +0900858 break;
Anthony Hugh34f09ca2016-03-04 12:03:37 -0800859 case MSG_BACK_LONG_PRESS:
860 backLongPress();
Anthony Hugh96e9cc52016-07-12 15:17:24 -0700861 finishBackKeyPress();
Anthony Hugh34f09ca2016-03-04 12:03:37 -0800862 break;
Chong Zhang9f7fb092016-05-20 17:03:08 -0700863 case MSG_DISPOSE_INPUT_CONSUMER:
864 disposeInputConsumer((InputConsumer) msg.obj);
865 break;
Anthony Hugh96e9cc52016-07-12 15:17:24 -0700866 case MSG_BACK_DELAYED_PRESS:
867 backMultiPressAction((Long) msg.obj, msg.arg1);
868 finishBackKeyPress();
869 break;
Jeff Brown70825162012-03-28 17:27:48 -0700870 }
871 }
872 }
873
Dianne Hackbornad7fa7f2011-01-07 14:06:50 -0800874 private UEventObserver mHDMIObserver = new UEventObserver() {
875 @Override
876 public void onUEvent(UEventObserver.UEvent event) {
877 setHdmiPlugged("1".equals(event.get("SWITCH_STATE")));
878 }
879 };
880
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800881 class SettingsObserver extends ContentObserver {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800882 SettingsObserver(Handler handler) {
883 super(handler);
884 }
David Brownbaf8d092010-03-08 21:52:59 -0800885
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800886 void observe() {
Christopher Tate5e08af02012-09-21 17:17:22 -0700887 // Observe all users' changes
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800888 ContentResolver resolver = mContext.getContentResolver();
889 resolver.registerContentObserver(Settings.System.getUriFor(
Christopher Tate5e08af02012-09-21 17:17:22 -0700890 Settings.System.END_BUTTON_BEHAVIOR), false, this,
891 UserHandle.USER_ALL);
David Brownbaf8d092010-03-08 21:52:59 -0800892 resolver.registerContentObserver(Settings.Secure.getUriFor(
Christopher Tate5e08af02012-09-21 17:17:22 -0700893 Settings.Secure.INCALL_POWER_BUTTON_BEHAVIOR), false, this,
894 UserHandle.USER_ALL);
Jeff Browna20dda42014-05-27 20:57:24 -0700895 resolver.registerContentObserver(Settings.Secure.getUriFor(
Bryce Leedb776ce2016-09-03 15:02:00 -0700896 Settings.Secure.INCALL_BACK_BUTTON_BEHAVIOR), false, this,
897 UserHandle.USER_ALL);
898 resolver.registerContentObserver(Settings.Secure.getUriFor(
Jeff Browna20dda42014-05-27 20:57:24 -0700899 Settings.Secure.WAKE_GESTURE_ENABLED), false, this,
900 UserHandle.USER_ALL);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800901 resolver.registerContentObserver(Settings.System.getUriFor(
Christopher Tate5e08af02012-09-21 17:17:22 -0700902 Settings.System.ACCELEROMETER_ROTATION), false, this,
903 UserHandle.USER_ALL);
Mike Lockwood28569302010-01-28 11:54:40 -0500904 resolver.registerContentObserver(Settings.System.getUriFor(
Christopher Tate5e08af02012-09-21 17:17:22 -0700905 Settings.System.USER_ROTATION), false, this,
906 UserHandle.USER_ALL);
Daniel Sandlerb73617d2010-08-17 00:41:00 -0400907 resolver.registerContentObserver(Settings.System.getUriFor(
Christopher Tate5e08af02012-09-21 17:17:22 -0700908 Settings.System.SCREEN_OFF_TIMEOUT), false, this,
909 UserHandle.USER_ALL);
Dianne Hackbornc777e072010-02-12 13:07:59 -0800910 resolver.registerContentObserver(Settings.System.getUriFor(
Christopher Tate5e08af02012-09-21 17:17:22 -0700911 Settings.System.POINTER_LOCATION), false, this,
912 UserHandle.USER_ALL);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800913 resolver.registerContentObserver(Settings.Secure.getUriFor(
Christopher Tate5e08af02012-09-21 17:17:22 -0700914 Settings.Secure.DEFAULT_INPUT_METHOD), false, this,
915 UserHandle.USER_ALL);
John Spurlockd9b70bd2014-02-06 17:02:44 -0500916 resolver.registerContentObserver(Settings.Secure.getUriFor(
John Spurlockf1a36642013-10-12 17:50:42 -0400917 Settings.Secure.IMMERSIVE_MODE_CONFIRMATIONS), false, this,
Christopher Tate5e08af02012-09-21 17:17:22 -0700918 UserHandle.USER_ALL);
John Spurlockc6d1c602014-01-17 15:22:06 -0500919 resolver.registerContentObserver(Settings.Global.getUriFor(
920 Settings.Global.POLICY_CONTROL), false, this,
921 UserHandle.USER_ALL);
Dianne Hackbornc777e072010-02-12 13:07:59 -0800922 updateSettings();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800923 }
924
925 @Override public void onChange(boolean selfChange) {
Dianne Hackbornc777e072010-02-12 13:07:59 -0800926 updateSettings();
Jeff Brown01a98dd2011-09-20 15:08:29 -0700927 updateRotation(false);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800928 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800929 }
Craig Mautner967212c2013-04-13 21:10:58 -0700930
Jeff Browna20dda42014-05-27 20:57:24 -0700931 class MyWakeGestureListener extends WakeGestureListener {
932 MyWakeGestureListener(Context context, Handler handler) {
933 super(context, handler);
934 }
935
936 @Override
937 public void onWakeUp() {
938 synchronized (mLock) {
939 if (shouldEnableWakeGestureLp()) {
Jeff Browne07b94b2014-06-18 15:56:27 -0700940 performHapticFeedbackLw(null, HapticFeedbackConstants.VIRTUAL_KEY, false);
Dianne Hackborn280a64e2015-07-13 14:48:08 -0700941 wakeUp(SystemClock.uptimeMillis(), mAllowTheaterModeWakeFromWakeGesture,
942 "android.policy:GESTURE");
Jeff Browna20dda42014-05-27 20:57:24 -0700943 }
944 }
945 }
946 }
947
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800948 class MyOrientationListener extends WindowOrientationListener {
Chong Zhang5aaa0b32015-08-28 10:22:36 -0700949 private final Runnable mUpdateRotationRunnable = new Runnable() {
950 @Override
951 public void run() {
Tim Murray1f407642015-10-01 17:07:12 -0700952 // send interaction hint to improve redraw performance
Ruchi Kandoi0d434042016-10-03 09:12:02 -0700953 mPowerManagerInternal.powerHint(PowerHint.INTERACTION, 0);
Chong Zhang5aaa0b32015-08-28 10:22:36 -0700954 updateRotation(false);
955 }
956 };
957
Craig Mautnereee29c42013-01-17 14:44:34 -0800958 MyOrientationListener(Context context, Handler handler) {
959 super(context, handler);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800960 }
Craig Mautner967212c2013-04-13 21:10:58 -0700961
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800962 @Override
Jeff Brownc0347aa2011-09-23 17:26:09 -0700963 public void onProposedRotationChanged(int rotation) {
Craig Mautnereda67292013-04-28 13:50:14 -0700964 if (localLOGV) Slog.v(TAG, "onProposedRotationChanged, rotation=" + rotation);
Chong Zhang5aaa0b32015-08-28 10:22:36 -0700965 mHandler.post(mUpdateRotationRunnable);
Jeff Brown01a98dd2011-09-20 15:08:29 -0700966 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800967 }
968 MyOrientationListener mOrientationListener;
969
Jorim Jaggi24bec7c2015-02-04 12:40:14 +0100970 private final StatusBarController mStatusBarController = new StatusBarController();
John Spurlock5b9145b2013-08-20 15:13:47 -0400971
John Spurlock27735a42013-08-14 17:57:38 -0400972 private final BarController mNavigationBarController = new BarController("NavigationBar",
John Spurlock5b9145b2013-08-20 15:13:47 -0400973 View.NAVIGATION_BAR_TRANSIENT,
974 View.NAVIGATION_BAR_UNHIDE,
John Spurlockbd957402013-10-03 11:38:39 -0400975 View.NAVIGATION_BAR_TRANSLUCENT,
976 StatusBarManager.WINDOW_NAVIGATION_BAR,
Jorim Jaggi4fa78922015-11-30 17:13:56 -0800977 WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION,
978 View.NAVIGATION_BAR_TRANSPARENT);
John Spurlock5b9145b2013-08-20 15:13:47 -0400979
John Spurlockf1a36642013-10-12 17:50:42 -0400980 private ImmersiveModeConfirmation mImmersiveModeConfirmation;
John Spurlock32beb2c2013-03-11 10:16:47 -0400981
Craig Mautner037aa8d2013-06-07 10:35:44 -0700982 private SystemGesturesPointerEventListener mSystemGestures;
John Spurlock32beb2c2013-03-11 10:16:47 -0400983
Dianne Hackborn42e620c2012-06-24 13:20:51 -0700984 IStatusBarService getStatusBarService() {
985 synchronized (mServiceAquireLock) {
986 if (mStatusBarService == null) {
987 mStatusBarService = IStatusBarService.Stub.asInterface(
988 ServiceManager.getService("statusbar"));
989 }
990 return mStatusBarService;
991 }
992 }
993
Jorim Jaggi86905582016-02-09 21:36:09 -0800994 StatusBarManagerInternal getStatusBarManagerInternal() {
995 synchronized (mServiceAquireLock) {
996 if (mStatusBarManagerInternal == null) {
997 mStatusBarManagerInternal =
998 LocalServices.getService(StatusBarManagerInternal.class);
999 }
1000 return mStatusBarManagerInternal;
1001 }
1002 }
1003
Suchi Amalapurapua9e1b162009-03-24 22:24:47 -07001004 /*
1005 * We always let the sensor be switched on by default except when
1006 * the user has explicitly disabled sensor based rotation or when the
1007 * screen is switched off.
1008 */
The Android Open Source Project0727d222009-03-11 12:11:58 -07001009 boolean needSensorRunningLp() {
Jeff Brownbcdfc622014-03-06 19:13:04 -08001010 if (mSupportAutoRotation) {
1011 if (mCurrentAppOrientation == ActivityInfo.SCREEN_ORIENTATION_SENSOR
1012 || mCurrentAppOrientation == ActivityInfo.SCREEN_ORIENTATION_FULL_SENSOR
1013 || mCurrentAppOrientation == ActivityInfo.SCREEN_ORIENTATION_SENSOR_PORTRAIT
1014 || mCurrentAppOrientation == ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE) {
1015 // If the application has explicitly requested to follow the
1016 // orientation, then we need to turn the sensor on.
1017 return true;
1018 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001019 }
Dianne Hackborn867ab6472010-04-29 13:28:56 -07001020 if ((mCarDockEnablesAccelerometer && mDockMode == Intent.EXTRA_DOCK_STATE_CAR) ||
Jeff Brown1a693182011-11-08 14:44:16 -08001021 (mDeskDockEnablesAccelerometer && (mDockMode == Intent.EXTRA_DOCK_STATE_DESK
1022 || mDockMode == Intent.EXTRA_DOCK_STATE_LE_DESK
1023 || mDockMode == Intent.EXTRA_DOCK_STATE_HE_DESK))) {
Mike Lockwoode9867d22009-09-20 01:59:02 -04001024 // enable accelerometer if we are docked in a dock that enables accelerometer
1025 // orientation management,
1026 return true;
1027 }
Jeff Brown207673cd2012-06-05 17:47:11 -07001028 if (mUserRotationMode == USER_ROTATION_LOCKED) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001029 // If the setting for using the sensor by default is enabled, then
1030 // we will always leave it on. Note that the user could go to
1031 // a window that forces an orientation that does not use the
1032 // sensor and in theory we could turn it off... however, when next
1033 // turning it on we won't have a good value for the current
1034 // orientation for a little bit, which can cause orientation
1035 // changes to lag, so we'd like to keep it always on. (It will
1036 // still be turned off when the screen is off.)
Suchi Amalapurapua9e1b162009-03-24 22:24:47 -07001037 return false;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001038 }
Jeff Brownbcdfc622014-03-06 19:13:04 -08001039 return mSupportAutoRotation;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001040 }
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001041
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001042 /*
1043 * Various use cases for invoking this function
1044 * screen turning off, should always disable listeners if already enabled
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001045 * screen turned on and current app has sensor based orientation, enable listeners
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001046 * if not already enabled
1047 * screen turned on and current app does not have sensor orientation, disable listeners if
1048 * already enabled
1049 * screen turning on and current app has sensor based orientation, enable listeners if needed
1050 * screen turning on and current app has nosensor based orientation, do nothing
1051 */
The Android Open Source Project0727d222009-03-11 12:11:58 -07001052 void updateOrientationListenerLp() {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001053 if (!mOrientationListener.canDetectOrientation()) {
1054 // If sensor is turned off or nonexistent for some reason
1055 return;
1056 }
Stefan Kuhne9326dc12015-06-12 09:25:32 -10001057 // Could have been invoked due to screen turning on or off or
1058 // change of the currently visible window's orientation.
Jeff Brown3ee549c2014-09-22 20:14:39 -07001059 if (localLOGV) Slog.v(TAG, "mScreenOnEarly=" + mScreenOnEarly
1060 + ", mAwake=" + mAwake + ", mCurrentAppOrientation=" + mCurrentAppOrientation
Stefan Kuhne9326dc12015-06-12 09:25:32 -10001061 + ", mOrientationSensorEnabled=" + mOrientationSensorEnabled
1062 + ", mKeyguardDrawComplete=" + mKeyguardDrawComplete
1063 + ", mWindowManagerDrawComplete=" + mWindowManagerDrawComplete);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001064 boolean disable = true;
Stefan Kuhne9326dc12015-06-12 09:25:32 -10001065 // Note: We postpone the rotating of the screen until the keyguard as well as the
1066 // window manager have reported a draw complete.
1067 if (mScreenOnEarly && mAwake &&
1068 mKeyguardDrawComplete && mWindowManagerDrawComplete) {
The Android Open Source Project0727d222009-03-11 12:11:58 -07001069 if (needSensorRunningLp()) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001070 disable = false;
1071 //enable listener if not already enabled
The Android Open Source Project0727d222009-03-11 12:11:58 -07001072 if (!mOrientationSensorEnabled) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001073 mOrientationListener.enable();
Craig Mautnereda67292013-04-28 13:50:14 -07001074 if(localLOGV) Slog.v(TAG, "Enabling listeners");
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001075 mOrientationSensorEnabled = true;
1076 }
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001077 }
1078 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001079 //check if sensors need to be disabled
The Android Open Source Project0727d222009-03-11 12:11:58 -07001080 if (disable && mOrientationSensorEnabled) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001081 mOrientationListener.disable();
Craig Mautnereda67292013-04-28 13:50:14 -07001082 if(localLOGV) Slog.v(TAG, "Disabling listeners");
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001083 mOrientationSensorEnabled = false;
1084 }
1085 }
1086
Anthony Hugh96e9cc52016-07-12 15:17:24 -07001087 private void interceptBackKeyDown() {
Nimrod Gileadi580135c2016-10-31 20:42:19 +00001088 MetricsLogger.count(mContext, "key_back_down", 1);
Anthony Hugh96e9cc52016-07-12 15:17:24 -07001089 // Reset back key state for long press
1090 mBackKeyHandled = false;
1091
1092 // Cancel multi-press detection timeout.
1093 if (hasPanicPressOnBackBehavior()) {
1094 if (mBackKeyPressCounter != 0
1095 && mBackKeyPressCounter < PANIC_PRESS_BACK_COUNT) {
1096 mHandler.removeMessages(MSG_BACK_DELAYED_PRESS);
1097 }
1098 }
1099
1100 if (hasLongPressOnBackBehavior()) {
1101 Message msg = mHandler.obtainMessage(MSG_BACK_LONG_PRESS);
1102 msg.setAsynchronous(true);
1103 mHandler.sendMessageDelayed(msg,
1104 ViewConfiguration.get(mContext).getDeviceGlobalActionKeyTimeout());
1105 }
1106 }
1107
1108 // returns true if the key was handled and should not be passed to the user
1109 private boolean interceptBackKeyUp(KeyEvent event) {
1110 // Cache handled state
1111 boolean handled = mBackKeyHandled;
1112
1113 if (hasPanicPressOnBackBehavior()) {
1114 // Check for back key panic press
1115 ++mBackKeyPressCounter;
1116
1117 final long eventTime = event.getDownTime();
1118
1119 if (mBackKeyPressCounter <= PANIC_PRESS_BACK_COUNT) {
1120 // This could be a multi-press. Wait a little bit longer to confirm.
1121 Message msg = mHandler.obtainMessage(MSG_BACK_DELAYED_PRESS,
Bryce Leedb776ce2016-09-03 15:02:00 -07001122 mBackKeyPressCounter, 0, eventTime);
Anthony Hugh96e9cc52016-07-12 15:17:24 -07001123 msg.setAsynchronous(true);
1124 mHandler.sendMessageDelayed(msg, ViewConfiguration.getMultiPressTimeout());
1125 }
1126 }
1127
1128 // Reset back long press state
1129 cancelPendingBackKeyAction();
1130
Bryce Leedb776ce2016-09-03 15:02:00 -07001131 if (mHasFeatureWatch) {
1132 TelecomManager telecomManager = getTelecommService();
1133
1134 if (telecomManager != null) {
1135 if (telecomManager.isRinging()) {
1136 // Pressing back while there's a ringing incoming
1137 // call should silence the ringer.
1138 telecomManager.silenceRinger();
1139
1140 // It should not prevent navigating away
1141 return false;
1142 } else if (
1143 (mIncallBackBehavior & Settings.Secure.INCALL_BACK_BUTTON_BEHAVIOR_HANGUP) != 0
1144 && telecomManager.isInCall()) {
1145 // Otherwise, if "Back button ends call" is enabled,
1146 // the Back button will hang up any current active call.
1147 return telecomManager.endCall();
1148 }
1149 }
1150 }
1151
Anthony Hugh96e9cc52016-07-12 15:17:24 -07001152 return handled;
1153 }
1154
Jeff Brown13f00f02014-10-31 14:45:50 -07001155 private void interceptPowerKeyDown(KeyEvent event, boolean interactive) {
1156 // Hold a wake lock until the power key is released.
1157 if (!mPowerKeyWakeLock.isHeld()) {
1158 mPowerKeyWakeLock.acquire();
1159 }
1160
1161 // Cancel multi-press detection timeout.
1162 if (mPowerKeyPressCounter != 0) {
1163 mHandler.removeMessages(MSG_POWER_DELAYED_PRESS);
1164 }
1165
1166 // Detect user pressing the power button in panic when an application has
1167 // taken over the whole screen.
1168 boolean panic = mImmersiveModeConfirmation.onPowerKeyDown(interactive,
Adrian Roos7aaa5512016-07-12 15:27:24 -07001169 SystemClock.elapsedRealtime(), isImmersiveMode(mLastSystemUiFlags),
1170 isNavBarEmpty(mLastSystemUiFlags));
Jeff Brown13f00f02014-10-31 14:45:50 -07001171 if (panic) {
Adrian Roosddc8b272015-05-21 16:28:27 -07001172 mHandler.post(mHiddenNavPanic);
Jeff Brown13f00f02014-10-31 14:45:50 -07001173 }
1174
1175 // Latch power key state to detect screenshot chord.
1176 if (interactive && !mScreenshotChordPowerKeyTriggered
1177 && (event.getFlags() & KeyEvent.FLAG_FALLBACK) == 0) {
1178 mScreenshotChordPowerKeyTriggered = true;
1179 mScreenshotChordPowerKeyTime = event.getDownTime();
1180 interceptScreenshotChord();
1181 }
1182
1183 // Stop ringing or end call if configured to do so when power is pressed.
1184 TelecomManager telecomManager = getTelecommService();
1185 boolean hungUp = false;
1186 if (telecomManager != null) {
1187 if (telecomManager.isRinging()) {
1188 // Pressing Power while there's a ringing incoming
1189 // call should silence the ringer.
1190 telecomManager.silenceRinger();
1191 } else if ((mIncallPowerBehavior
1192 & Settings.Secure.INCALL_POWER_BUTTON_BEHAVIOR_HANGUP) != 0
1193 && telecomManager.isInCall() && interactive) {
1194 // Otherwise, if "Power button ends call" is enabled,
1195 // the Power button will hang up any current active call.
1196 hungUp = telecomManager.endCall();
1197 }
1198 }
1199
Adrian Roos5941c982015-09-03 15:59:49 -07001200 GestureLauncherService gestureService = LocalServices.getService(
1201 GestureLauncherService.class);
1202 boolean gesturedServiceIntercepted = false;
1203 if (gestureService != null) {
Jorim Jaggif1cdf952016-04-05 21:41:06 -07001204 gesturedServiceIntercepted = gestureService.interceptPowerKeyDown(event, interactive,
1205 mTmpBoolean);
1206 if (mTmpBoolean.value && mGoingToSleep) {
1207 mCameraGestureTriggeredDuringGoingToSleep = true;
1208 }
Adrian Roos5941c982015-09-03 15:59:49 -07001209 }
1210
Jeff Brown13f00f02014-10-31 14:45:50 -07001211 // If the power key has still not yet been handled, then detect short
1212 // press, long press, or multi press and decide what to do.
1213 mPowerKeyHandled = hungUp || mScreenshotChordVolumeDownKeyTriggered
Adrian Roos5941c982015-09-03 15:59:49 -07001214 || mScreenshotChordVolumeUpKeyTriggered || gesturedServiceIntercepted;
Jeff Brown13f00f02014-10-31 14:45:50 -07001215 if (!mPowerKeyHandled) {
1216 if (interactive) {
1217 // When interactive, we're already awake.
1218 // Wait for a long press or for the button to be released to decide what to do.
1219 if (hasLongPressOnPowerBehavior()) {
1220 Message msg = mHandler.obtainMessage(MSG_POWER_LONG_PRESS);
1221 msg.setAsynchronous(true);
1222 mHandler.sendMessageDelayed(msg,
1223 ViewConfiguration.get(mContext).getDeviceGlobalActionKeyTimeout());
1224 }
1225 } else {
Bryce Leed9268e32014-11-17 17:40:59 -08001226 wakeUpFromPowerKey(event.getDownTime());
Bryce Leed9268e32014-11-17 17:40:59 -08001227
Bryce Leed3b28402015-03-09 15:49:13 +00001228 if (mSupportLongPressPowerWhenNonInteractive && hasLongPressOnPowerBehavior()) {
1229 Message msg = mHandler.obtainMessage(MSG_POWER_LONG_PRESS);
1230 msg.setAsynchronous(true);
1231 mHandler.sendMessageDelayed(msg,
1232 ViewConfiguration.get(mContext).getDeviceGlobalActionKeyTimeout());
Bryce Leed9268e32014-11-17 17:40:59 -08001233 mBeganFromNonInteractive = true;
Bryce Leed3b28402015-03-09 15:49:13 +00001234 } else {
1235 final int maxCount = getMaxMultiPressPowerCount();
1236
1237 if (maxCount <= 1) {
1238 mPowerKeyHandled = true;
1239 } else {
1240 mBeganFromNonInteractive = true;
1241 }
Jeff Brown13f00f02014-10-31 14:45:50 -07001242 }
1243 }
Jeff Brown4d396052010-10-29 21:50:21 -07001244 }
1245 }
1246
Jeff Brown13f00f02014-10-31 14:45:50 -07001247 private void interceptPowerKeyUp(KeyEvent event, boolean interactive, boolean canceled) {
1248 final boolean handled = canceled || mPowerKeyHandled;
1249 mScreenshotChordPowerKeyTriggered = false;
1250 cancelPendingScreenshotChordAction();
1251 cancelPendingPowerKeyAction();
1252
1253 if (!handled) {
1254 // Figure out how to handle the key now that it has been released.
1255 mPowerKeyPressCounter += 1;
1256
1257 final int maxCount = getMaxMultiPressPowerCount();
1258 final long eventTime = event.getDownTime();
1259 if (mPowerKeyPressCounter < maxCount) {
1260 // This could be a multi-press. Wait a little bit longer to confirm.
1261 // Continue holding the wake lock.
1262 Message msg = mHandler.obtainMessage(MSG_POWER_DELAYED_PRESS,
1263 interactive ? 1 : 0, mPowerKeyPressCounter, eventTime);
1264 msg.setAsynchronous(true);
1265 mHandler.sendMessageDelayed(msg, ViewConfiguration.getDoubleTapTimeout());
1266 return;
1267 }
1268
1269 // No other actions. Handle it immediately.
1270 powerPress(eventTime, interactive, mPowerKeyPressCounter);
Jeff Brown4d396052010-10-29 21:50:21 -07001271 }
Jeff Brown13f00f02014-10-31 14:45:50 -07001272
1273 // Done. Reset our state.
1274 finishPowerKeyPress();
1275 }
1276
1277 private void finishPowerKeyPress() {
Bryce Leed9268e32014-11-17 17:40:59 -08001278 mBeganFromNonInteractive = false;
Jeff Brown13f00f02014-10-31 14:45:50 -07001279 mPowerKeyPressCounter = 0;
1280 if (mPowerKeyWakeLock.isHeld()) {
1281 mPowerKeyWakeLock.release();
1282 }
Jeff Brownd5bb82d2011-10-12 13:57:59 -07001283 }
1284
Anthony Hugh96e9cc52016-07-12 15:17:24 -07001285 private void finishBackKeyPress() {
1286 mBackKeyPressCounter = 0;
1287 }
1288
Jeff Brownd5bb82d2011-10-12 13:57:59 -07001289 private void cancelPendingPowerKeyAction() {
1290 if (!mPowerKeyHandled) {
Jeff Brown13f00f02014-10-31 14:45:50 -07001291 mPowerKeyHandled = true;
1292 mHandler.removeMessages(MSG_POWER_LONG_PRESS);
Jeff Brownd5bb82d2011-10-12 13:57:59 -07001293 }
Jeff Brown13f00f02014-10-31 14:45:50 -07001294 }
1295
Anthony Hugh34f09ca2016-03-04 12:03:37 -08001296 private void cancelPendingBackKeyAction() {
1297 if (!mBackKeyHandled) {
1298 mBackKeyHandled = true;
1299 mHandler.removeMessages(MSG_BACK_LONG_PRESS);
1300 }
1301 }
1302
Anthony Hugh96e9cc52016-07-12 15:17:24 -07001303 private void backMultiPressAction(long eventTime, int count) {
1304 if (count >= PANIC_PRESS_BACK_COUNT) {
1305 switch (mPanicPressOnBackBehavior) {
1306 case PANIC_PRESS_BACK_NOTHING:
1307 break;
1308 case PANIC_PRESS_BACK_HOME:
1309 launchHomeFromHotKey();
1310 break;
1311 }
1312 }
1313 }
1314
Jeff Brown13f00f02014-10-31 14:45:50 -07001315 private void powerPress(long eventTime, boolean interactive, int count) {
1316 if (mScreenOnEarly && !mScreenOnFully) {
1317 Slog.i(TAG, "Suppressed redundant power key press while "
1318 + "already in the process of turning the screen on.");
1319 return;
Jeff Brownff204712011-10-25 21:27:54 -07001320 }
Jeff Brown13f00f02014-10-31 14:45:50 -07001321
1322 if (count == 2) {
1323 powerMultiPressAction(eventTime, interactive, mDoublePressOnPowerBehavior);
1324 } else if (count == 3) {
1325 powerMultiPressAction(eventTime, interactive, mTriplePressOnPowerBehavior);
Bryce Leed9268e32014-11-17 17:40:59 -08001326 } else if (interactive && !mBeganFromNonInteractive) {
Jeff Brown13f00f02014-10-31 14:45:50 -07001327 switch (mShortPressOnPowerBehavior) {
1328 case SHORT_PRESS_POWER_NOTHING:
1329 break;
1330 case SHORT_PRESS_POWER_GO_TO_SLEEP:
1331 mPowerManager.goToSleep(eventTime,
1332 PowerManager.GO_TO_SLEEP_REASON_POWER_BUTTON, 0);
1333 break;
1334 case SHORT_PRESS_POWER_REALLY_GO_TO_SLEEP:
1335 mPowerManager.goToSleep(eventTime,
1336 PowerManager.GO_TO_SLEEP_REASON_POWER_BUTTON,
1337 PowerManager.GO_TO_SLEEP_FLAG_NO_DOZE);
1338 break;
1339 case SHORT_PRESS_POWER_REALLY_GO_TO_SLEEP_AND_GO_HOME:
1340 mPowerManager.goToSleep(eventTime,
1341 PowerManager.GO_TO_SLEEP_REASON_POWER_BUTTON,
1342 PowerManager.GO_TO_SLEEP_FLAG_NO_DOZE);
1343 launchHomeFromHotKey();
1344 break;
Bryce Lee01b0c5f2015-02-05 18:24:04 -08001345 case SHORT_PRESS_POWER_GO_HOME:
Bryce Lee662ed802015-04-10 20:11:39 +00001346 launchHomeFromHotKey(true /* awakenFromDreams */, false /*respectKeyguard*/);
Bryce Lee01b0c5f2015-02-05 18:24:04 -08001347 break;
Jeff Brown13f00f02014-10-31 14:45:50 -07001348 }
1349 }
1350 }
1351
1352 private void powerMultiPressAction(long eventTime, boolean interactive, int behavior) {
1353 switch (behavior) {
1354 case MULTI_PRESS_POWER_NOTHING:
1355 break;
1356 case MULTI_PRESS_POWER_THEATER_MODE:
Bryce Lee3ae447e2015-06-30 12:31:41 -07001357 if (!isUserSetupComplete()) {
1358 Slog.i(TAG, "Ignoring toggling theater mode - device not setup.");
1359 break;
1360 }
1361
Jeff Brown13f00f02014-10-31 14:45:50 -07001362 if (isTheaterModeEnabled()) {
1363 Slog.i(TAG, "Toggling theater mode off.");
1364 Settings.Global.putInt(mContext.getContentResolver(),
1365 Settings.Global.THEATER_MODE_ON, 0);
1366 if (!interactive) {
1367 wakeUpFromPowerKey(eventTime);
1368 }
1369 } else {
1370 Slog.i(TAG, "Toggling theater mode on.");
1371 Settings.Global.putInt(mContext.getContentResolver(),
1372 Settings.Global.THEATER_MODE_ON, 1);
Bryce Lee55e846d2014-11-04 12:43:44 -08001373
1374 if (mGoToSleepOnButtonPressTheaterMode && interactive) {
Jeff Brown13f00f02014-10-31 14:45:50 -07001375 mPowerManager.goToSleep(eventTime,
1376 PowerManager.GO_TO_SLEEP_REASON_POWER_BUTTON, 0);
1377 }
1378 }
1379 break;
1380 case MULTI_PRESS_POWER_BRIGHTNESS_BOOST:
Jeff Brown7b5be5e2014-11-12 18:45:31 -08001381 Slog.i(TAG, "Starting brightness boost.");
1382 if (!interactive) {
1383 wakeUpFromPowerKey(eventTime);
1384 }
Jeff Brown13f00f02014-10-31 14:45:50 -07001385 mPowerManager.boostScreenBrightness(eventTime);
1386 break;
1387 }
1388 }
1389
1390 private int getMaxMultiPressPowerCount() {
1391 if (mTriplePressOnPowerBehavior != MULTI_PRESS_POWER_NOTHING) {
1392 return 3;
1393 }
1394 if (mDoublePressOnPowerBehavior != MULTI_PRESS_POWER_NOTHING) {
1395 return 2;
1396 }
1397 return 1;
1398 }
1399
1400 private void powerLongPress() {
1401 final int behavior = getResolvedLongPressOnPowerBehavior();
1402 switch (behavior) {
1403 case LONG_PRESS_POWER_NOTHING:
1404 break;
1405 case LONG_PRESS_POWER_GLOBAL_ACTIONS:
1406 mPowerKeyHandled = true;
1407 if (!performHapticFeedbackLw(null, HapticFeedbackConstants.LONG_PRESS, false)) {
1408 performAuditoryFeedbackForAccessibilityIfNeed();
1409 }
1410 showGlobalActionsInternal();
1411 break;
1412 case LONG_PRESS_POWER_SHUT_OFF:
1413 case LONG_PRESS_POWER_SHUT_OFF_NO_CONFIRM:
1414 mPowerKeyHandled = true;
1415 performHapticFeedbackLw(null, HapticFeedbackConstants.LONG_PRESS, false);
1416 sendCloseSystemWindows(SYSTEM_DIALOG_REASON_GLOBAL_ACTIONS);
1417 mWindowManagerFuncs.shutdown(behavior == LONG_PRESS_POWER_SHUT_OFF);
1418 break;
1419 }
1420 }
1421
Anthony Hugh34f09ca2016-03-04 12:03:37 -08001422 private void backLongPress() {
1423 mBackKeyHandled = true;
1424
1425 switch (mLongPressOnBackBehavior) {
1426 case LONG_PRESS_BACK_NOTHING:
1427 break;
1428 case LONG_PRESS_BACK_GO_TO_VOICE_ASSIST:
Nancy Zheng0d85ee22016-09-29 09:15:56 -07001429 final boolean keyguardActive = mKeyguardDelegate == null
1430 ? false
1431 : mKeyguardDelegate.isShowing();
1432 if (!keyguardActive) {
1433 Intent intent = new Intent(Intent.ACTION_VOICE_ASSIST);
1434 startActivityAsUser(intent, UserHandle.CURRENT_OR_SELF);
1435 }
Anthony Hugh34f09ca2016-03-04 12:03:37 -08001436 break;
1437 }
1438 }
1439
Chong Zhang9f7fb092016-05-20 17:03:08 -07001440 private void disposeInputConsumer(InputConsumer inputConsumer) {
1441 if (inputConsumer != null) {
1442 inputConsumer.dismiss();
1443 }
1444 }
1445
Nick Vaccarob593a812015-05-15 11:23:05 -07001446 private void sleepPress(long eventTime) {
1447 if (mShortPressOnSleepBehavior == SHORT_PRESS_SLEEP_GO_TO_SLEEP_AND_GO_HOME) {
1448 launchHomeFromHotKey(false /* awakenDreams */, true /*respectKeyguard*/);
1449 }
1450 }
1451
1452 private void sleepRelease(long eventTime) {
Filip Gruszczynskia483a1d2015-03-17 19:06:58 +00001453 switch (mShortPressOnSleepBehavior) {
1454 case SHORT_PRESS_SLEEP_GO_TO_SLEEP:
Filip Gruszczynskia483a1d2015-03-17 19:06:58 +00001455 case SHORT_PRESS_SLEEP_GO_TO_SLEEP_AND_GO_HOME:
Nick Vaccarob593a812015-05-15 11:23:05 -07001456 Slog.i(TAG, "sleepRelease() calling goToSleep(GO_TO_SLEEP_REASON_SLEEP_BUTTON)");
1457 mPowerManager.goToSleep(eventTime,
1458 PowerManager.GO_TO_SLEEP_REASON_SLEEP_BUTTON, 0);
Filip Gruszczynskia483a1d2015-03-17 19:06:58 +00001459 break;
1460 }
1461 }
1462
Jeff Brown13f00f02014-10-31 14:45:50 -07001463 private int getResolvedLongPressOnPowerBehavior() {
1464 if (FactoryTest.isLongPressOnPowerOffEnabled()) {
1465 return LONG_PRESS_POWER_SHUT_OFF_NO_CONFIRM;
1466 }
1467 return mLongPressOnPowerBehavior;
1468 }
1469
1470 private boolean hasLongPressOnPowerBehavior() {
1471 return getResolvedLongPressOnPowerBehavior() != LONG_PRESS_POWER_NOTHING;
Jeff Brownd5bb82d2011-10-12 13:57:59 -07001472 }
1473
Anthony Hugh34f09ca2016-03-04 12:03:37 -08001474 private boolean hasLongPressOnBackBehavior() {
1475 return mLongPressOnBackBehavior != LONG_PRESS_BACK_NOTHING;
1476 }
1477
Anthony Hugh96e9cc52016-07-12 15:17:24 -07001478 private boolean hasPanicPressOnBackBehavior() {
1479 return mPanicPressOnBackBehavior != PANIC_PRESS_BACK_NOTHING;
1480 }
1481
Jeff Brownd5bb82d2011-10-12 13:57:59 -07001482 private void interceptScreenshotChord() {
Christopher Tatee90585f2012-03-05 18:56:25 -08001483 if (mScreenshotChordEnabled
Jeff Brown13f00f02014-10-31 14:45:50 -07001484 && mScreenshotChordVolumeDownKeyTriggered && mScreenshotChordPowerKeyTriggered
1485 && !mScreenshotChordVolumeUpKeyTriggered) {
Jeff Brownd5bb82d2011-10-12 13:57:59 -07001486 final long now = SystemClock.uptimeMillis();
Jeff Brown13f00f02014-10-31 14:45:50 -07001487 if (now <= mScreenshotChordVolumeDownKeyTime + SCREENSHOT_CHORD_DEBOUNCE_DELAY_MILLIS
1488 && now <= mScreenshotChordPowerKeyTime
1489 + SCREENSHOT_CHORD_DEBOUNCE_DELAY_MILLIS) {
1490 mScreenshotChordVolumeDownKeyConsumed = true;
Jeff Brownd5bb82d2011-10-12 13:57:59 -07001491 cancelPendingPowerKeyAction();
Muyuan Li6ca619f2016-03-08 13:30:42 -08001492 mScreenshotRunnable.setScreenshotType(TAKE_SCREENSHOT_FULLSCREEN);
Jeff Sharkey2991fa32012-12-05 18:06:43 -08001493 mHandler.postDelayed(mScreenshotRunnable, getScreenshotChordLongPressDelay());
Jeff Brownd5bb82d2011-10-12 13:57:59 -07001494 }
1495 }
1496 }
1497
Winson Chung1cea2f32012-10-08 20:42:01 -07001498 private long getScreenshotChordLongPressDelay() {
Jim Miller5ecd8112013-01-09 18:50:26 -08001499 if (mKeyguardDelegate.isShowing()) {
Winson Chung1cea2f32012-10-08 20:42:01 -07001500 // Double the time it takes to take a screenshot from the keyguard
1501 return (long) (KEYGUARD_SCREENSHOT_CHORD_DELAY_MULTIPLIER *
Justin Kohfeabd2c2014-05-02 10:02:44 -07001502 ViewConfiguration.get(mContext).getDeviceGlobalActionKeyTimeout());
Winson Chung1cea2f32012-10-08 20:42:01 -07001503 }
Justin Kohfeabd2c2014-05-02 10:02:44 -07001504 return ViewConfiguration.get(mContext).getDeviceGlobalActionKeyTimeout();
Winson Chung1cea2f32012-10-08 20:42:01 -07001505 }
1506
Jeff Brownd5bb82d2011-10-12 13:57:59 -07001507 private void cancelPendingScreenshotChordAction() {
Jeff Sharkey2991fa32012-12-05 18:06:43 -08001508 mHandler.removeCallbacks(mScreenshotRunnable);
Jeff Brown4d396052010-10-29 21:50:21 -07001509 }
1510
Jeff Brown13f00f02014-10-31 14:45:50 -07001511 private final Runnable mEndCallLongPress = new Runnable() {
Craig Mautnerf1b67412012-09-19 13:18:29 -07001512 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001513 public void run() {
Jeff Brown13f00f02014-10-31 14:45:50 -07001514 mEndCallKeyHandled = true;
1515 if (!performHapticFeedbackLw(null, HapticFeedbackConstants.LONG_PRESS, false)) {
1516 performAuditoryFeedbackForAccessibilityIfNeed();
Joe Onoratod208e702010-10-08 16:22:43 -04001517 }
Jeff Brown13f00f02014-10-31 14:45:50 -07001518 showGlobalActionsInternal();
Jeff Brownd5bb82d2011-10-12 13:57:59 -07001519 }
1520 };
1521
Muyuan Li6ca619f2016-03-08 13:30:42 -08001522 private class ScreenshotRunnable implements Runnable {
1523 private int mScreenshotType = TAKE_SCREENSHOT_FULLSCREEN;
1524
1525 public void setScreenshotType(int screenshotType) {
1526 mScreenshotType = screenshotType;
1527 }
1528
Craig Mautner0bf6ec92012-12-18 08:33:27 -08001529 @Override
Jeff Brownd5bb82d2011-10-12 13:57:59 -07001530 public void run() {
Muyuan Li6ca619f2016-03-08 13:30:42 -08001531 takeScreenshot(mScreenshotType);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001532 }
Muyuan Li6ca619f2016-03-08 13:30:42 -08001533 }
1534
1535 private final ScreenshotRunnable mScreenshotRunnable = new ScreenshotRunnable();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001536
Alan Viverettee34560b22014-07-10 14:50:06 -07001537 @Override
1538 public void showGlobalActions() {
1539 mHandler.removeMessages(MSG_DISPATCH_SHOW_GLOBAL_ACTIONS);
1540 mHandler.sendEmptyMessage(MSG_DISPATCH_SHOW_GLOBAL_ACTIONS);
1541 }
1542
1543 void showGlobalActionsInternal() {
1544 sendCloseSystemWindows(SYSTEM_DIALOG_REASON_GLOBAL_ACTIONS);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001545 if (mGlobalActions == null) {
Jeff Brown7304c342012-05-11 18:42:42 -07001546 mGlobalActions = new GlobalActions(mContext, mWindowManagerFuncs);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001547 }
Jim Millerab954542014-10-10 18:21:49 -07001548 final boolean keyguardShowing = isKeyguardShowingAndNotOccluded();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001549 mGlobalActions.showDialog(keyguardShowing, isDeviceProvisioned());
1550 if (keyguardShowing) {
1551 // since it took two seconds of long press to bring this up,
1552 // poke the wake lock so they have some time to see the dialog.
Jim Miller25190572013-02-28 17:36:24 -08001553 mPowerManager.userActivity(SystemClock.uptimeMillis(), false);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001554 }
1555 }
1556
1557 boolean isDeviceProvisioned() {
Jeff Brownbf6f6f92012-09-25 15:03:20 -07001558 return Settings.Global.getInt(
1559 mContext.getContentResolver(), Settings.Global.DEVICE_PROVISIONED, 0) != 0;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001560 }
1561
Maurice Lam99c6e072014-04-28 18:24:28 -07001562 boolean isUserSetupComplete() {
1563 return Settings.Secure.getIntForUser(mContext.getContentResolver(),
1564 Settings.Secure.USER_SETUP_COMPLETE, 0, UserHandle.USER_CURRENT) != 0;
1565 }
1566
Jeff Brown13f00f02014-10-31 14:45:50 -07001567 private void handleShortPressOnHome() {
Jinsuk Kime601b712015-07-07 08:01:02 +09001568 // Turn on the connected TV and switch HDMI input if we're a HDMI playback device.
1569 getHdmiControl().turnOnTv();
1570
Jeff Brown13f00f02014-10-31 14:45:50 -07001571 // If there's a dream running then use home to escape the dream
1572 // but don't actually go home.
1573 if (mDreamManagerInternal != null && mDreamManagerInternal.isDreaming()) {
1574 mDreamManagerInternal.stopDream(false /*immediate*/);
1575 return;
1576 }
1577
1578 // Go home!
1579 launchHomeFromHotKey();
1580 }
1581
Jinsuk Kime601b712015-07-07 08:01:02 +09001582 /**
1583 * Creates an accessor to HDMI control service that performs the operation of
1584 * turning on TV (optional) and switching input to us. If HDMI control service
1585 * is not available or we're not a HDMI playback device, the operation is no-op.
1586 */
1587 private HdmiControl getHdmiControl() {
1588 if (null == mHdmiControl) {
1589 HdmiControlManager manager = (HdmiControlManager) mContext.getSystemService(
1590 Context.HDMI_CONTROL_SERVICE);
1591 HdmiPlaybackClient client = null;
1592 if (manager != null) {
1593 client = manager.getPlaybackClient();
1594 }
1595 mHdmiControl = new HdmiControl(client);
1596 }
1597 return mHdmiControl;
1598 }
1599
1600 private static class HdmiControl {
1601 private final HdmiPlaybackClient mClient;
1602
1603 private HdmiControl(HdmiPlaybackClient client) {
1604 mClient = client;
1605 }
1606
1607 public void turnOnTv() {
1608 if (mClient == null) {
1609 return;
1610 }
1611 mClient.oneTouchPlay(new OneTouchPlayCallback() {
1612 @Override
1613 public void onComplete(int result) {
1614 if (result != HdmiControlManager.RESULT_SUCCESS) {
1615 Log.w(TAG, "One touch play failed: " + result);
1616 }
1617 }
1618 });
1619 }
1620 }
1621
Jaewan Kim76b7d0d2016-02-12 19:01:02 +09001622 private void handleLongPressOnHome(int deviceId) {
Jaewan Kim52632e22016-01-14 18:01:52 +09001623 if (mLongPressOnHomeBehavior == LONG_PRESS_HOME_NOTHING) {
1624 return;
1625 }
1626 mHomeConsumed = true;
1627 performHapticFeedbackLw(null, HapticFeedbackConstants.LONG_PRESS, false);
Patrick Dubroyece94522011-02-23 18:35:01 -08001628
Jaewan Kim52632e22016-01-14 18:01:52 +09001629 switch (mLongPressOnHomeBehavior) {
1630 case LONG_PRESS_HOME_RECENT_SYSTEM_UI:
Jeff Browncaca8812013-05-09 13:34:33 -07001631 toggleRecentApps();
Jaewan Kim52632e22016-01-14 18:01:52 +09001632 break;
1633 case LONG_PRESS_HOME_ASSIST:
Tim Kilbourn0e5f1102015-06-05 16:18:09 -07001634 launchAssistAction(null, deviceId);
Jaewan Kim52632e22016-01-14 18:01:52 +09001635 break;
Jaewan Kim52632e22016-01-14 18:01:52 +09001636 default:
Jaewan Kim76b7d0d2016-02-12 19:01:02 +09001637 Log.w(TAG, "Undefined home long press behavior: " + mLongPressOnHomeBehavior);
Jaewan Kim52632e22016-01-14 18:01:52 +09001638 break;
Jim Millere6ad1a82010-08-20 19:25:39 -07001639 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001640 }
Patrick Dubroyece94522011-02-23 18:35:01 -08001641
Jeff Browncaca8812013-05-09 13:34:33 -07001642 private void handleDoubleTapOnHome() {
1643 if (mDoubleTapOnHomeBehavior == DOUBLE_TAP_HOME_RECENT_SYSTEM_UI) {
1644 mHomeConsumed = true;
1645 toggleRecentApps();
1646 }
1647 }
1648
Jaewan Kimf0fd2182016-04-20 21:17:58 +09001649 private void showTvPictureInPictureMenu(KeyEvent event) {
1650 if (DEBUG_INPUT) Log.d(TAG, "showTvPictureInPictureMenu event=" + event);
1651 mHandler.removeMessages(MSG_SHOW_TV_PICTURE_IN_PICTURE_MENU);
1652 Message msg = mHandler.obtainMessage(MSG_SHOW_TV_PICTURE_IN_PICTURE_MENU);
Jaewan Kimc552b042016-01-18 16:08:45 +09001653 msg.setAsynchronous(true);
1654 msg.sendToTarget();
1655 }
1656
Jaewan Kimf0fd2182016-04-20 21:17:58 +09001657 private void showTvPictureInPictureMenuInternal() {
1658 StatusBarManagerInternal statusbar = getStatusBarManagerInternal();
1659 if (statusbar != null) {
1660 statusbar.showTvPictureInPictureMenu();
Jaewan Kimc552b042016-01-18 16:08:45 +09001661 }
Jaewan Kim52632e22016-01-14 18:01:52 +09001662 }
1663
Jeff Browncaca8812013-05-09 13:34:33 -07001664 private final Runnable mHomeDoubleTapTimeoutRunnable = new Runnable() {
1665 @Override
1666 public void run() {
1667 if (mHomeDoubleTapPending) {
1668 mHomeDoubleTapPending = false;
Jeff Brown13f00f02014-10-31 14:45:50 -07001669 handleShortPressOnHome();
Jeff Browncaca8812013-05-09 13:34:33 -07001670 }
1671 }
1672 };
1673
Mark Renoufc1256912015-03-11 14:38:23 -04001674 private boolean isRoundWindow() {
Adam Powell01f280d2015-05-18 16:07:42 -07001675 return mContext.getResources().getConfiguration().isScreenRound();
Mark Renoufc1256912015-03-11 14:38:23 -04001676 }
1677
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001678 /** {@inheritDoc} */
Craig Mautner0bf6ec92012-12-18 08:33:27 -08001679 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001680 public void init(Context context, IWindowManager windowManager,
Jeff Brown96307042012-07-27 15:51:34 -07001681 WindowManagerFuncs windowManagerFuncs) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001682 mContext = context;
1683 mWindowManager = windowManager;
Dianne Hackborndf89e652011-10-06 22:35:11 -07001684 mWindowManagerFuncs = windowManagerFuncs;
Craig Mautner8a0da012014-05-31 15:13:37 -07001685 mWindowManagerInternal = LocalServices.getService(WindowManagerInternal.class);
Jeff Brown061ea992015-04-17 19:55:47 -07001686 mActivityManagerInternal = LocalServices.getService(ActivityManagerInternal.class);
Andrii Kulian112d0562016-03-08 10:44:22 -08001687 mInputManagerInternal = LocalServices.getService(InputManagerInternal.class);
Jose Lima9546b202014-07-02 17:21:51 -07001688 mDreamManagerInternal = LocalServices.getService(DreamManagerInternal.class);
Michael Wrighta4d22d72015-09-16 23:19:26 +01001689 mPowerManagerInternal = LocalServices.getService(PowerManagerInternal.class);
Billy Laucbe540f2015-06-25 01:51:44 +01001690 mAppOpsManager = (AppOpsManager) mContext.getSystemService(Context.APP_OPS_SERVICE);
Wale Ogunwale6b15ea52016-04-04 07:28:27 -07001691 mHasFeatureWatch = mContext.getPackageManager().hasSystemFeature(FEATURE_WATCH);
Mark Renoufc1256912015-03-11 14:38:23 -04001692
1693 // Init display burn-in protection
1694 boolean burnInProtectionEnabled = context.getResources().getBoolean(
1695 com.android.internal.R.bool.config_enableBurnInProtection);
1696 // Allow a system property to override this. Used by developer settings.
1697 boolean burnInProtectionDevMode =
1698 SystemProperties.getBoolean("persist.debug.force_burn_in", false);
1699 if (burnInProtectionEnabled || burnInProtectionDevMode) {
1700 final int minHorizontal;
1701 final int maxHorizontal;
1702 final int minVertical;
1703 final int maxVertical;
1704 final int maxRadius;
1705 if (burnInProtectionDevMode) {
1706 minHorizontal = -8;
1707 maxHorizontal = 8;
1708 minVertical = -8;
1709 maxVertical = -4;
1710 maxRadius = (isRoundWindow()) ? 6 : -1;
1711 } else {
1712 Resources resources = context.getResources();
1713 minHorizontal = resources.getInteger(
1714 com.android.internal.R.integer.config_burnInProtectionMinHorizontalOffset);
1715 maxHorizontal = resources.getInteger(
1716 com.android.internal.R.integer.config_burnInProtectionMaxHorizontalOffset);
1717 minVertical = resources.getInteger(
1718 com.android.internal.R.integer.config_burnInProtectionMinVerticalOffset);
1719 maxVertical = resources.getInteger(
1720 com.android.internal.R.integer.config_burnInProtectionMaxVerticalOffset);
1721 maxRadius = resources.getInteger(
1722 com.android.internal.R.integer.config_burnInProtectionMaxRadius);
1723 }
1724 mBurnInProtectionHelper = new BurnInProtectionHelper(
1725 context, minHorizontal, maxHorizontal, minVertical, maxVertical, maxRadius);
Filip Gruszczynskicfb31852015-02-25 21:47:12 +00001726 }
Craig Mautner8a0da012014-05-31 15:13:37 -07001727
Jeff Brown70825162012-03-28 17:27:48 -07001728 mHandler = new PolicyHandler();
Jeff Browna20dda42014-05-27 20:57:24 -07001729 mWakeGestureListener = new MyWakeGestureListener(mContext, mHandler);
Craig Mautnereee29c42013-01-17 14:44:34 -08001730 mOrientationListener = new MyOrientationListener(mContext, mHandler);
Jeff Brownc0347aa2011-09-23 17:26:09 -07001731 try {
1732 mOrientationListener.setCurrentRotation(windowManager.getRotation());
1733 } catch (RemoteException ex) { }
Christopher Tate5e08af02012-09-21 17:17:22 -07001734 mSettingsObserver = new SettingsObserver(mHandler);
1735 mSettingsObserver.observe();
Svetoslav683914b2015-01-15 14:22:26 -08001736 mShortcutManager = new ShortcutManager(context);
Daniel Sandler6396c722013-04-16 20:19:09 -04001737 mUiMode = context.getResources().getInteger(
1738 com.android.internal.R.integer.config_defaultUiModeType);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001739 mHomeIntent = new Intent(Intent.ACTION_MAIN, null);
1740 mHomeIntent.addCategory(Intent.CATEGORY_HOME);
1741 mHomeIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK
1742 | Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED);
keunyounga7710492015-09-23 11:33:58 -07001743 mEnableCarDockHomeCapture = context.getResources().getBoolean(
1744 com.android.internal.R.bool.config_enableCarDockHomeLaunch);
Dianne Hackborn39c2d712009-09-22 11:41:31 -07001745 mCarDockIntent = new Intent(Intent.ACTION_MAIN, null);
1746 mCarDockIntent.addCategory(Intent.CATEGORY_CAR_DOCK);
1747 mCarDockIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK
1748 | Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED);
1749 mDeskDockIntent = new Intent(Intent.ACTION_MAIN, null);
1750 mDeskDockIntent.addCategory(Intent.CATEGORY_DESK_DOCK);
1751 mDeskDockIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK
1752 | Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED);
Jim Millere6ad1a82010-08-20 19:25:39 -07001753
Jeff Brown96307042012-07-27 15:51:34 -07001754 mPowerManager = (PowerManager)context.getSystemService(Context.POWER_SERVICE);
1755 mBroadcastWakeLock = mPowerManager.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK,
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001756 "PhoneWindowManager.mBroadcastWakeLock");
Jeff Brown13f00f02014-10-31 14:45:50 -07001757 mPowerKeyWakeLock = mPowerManager.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK,
1758 "PhoneWindowManager.mPowerKeyWakeLock");
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001759 mEnableShiftMenuBugReports = "1".equals(SystemProperties.get("ro.debuggable"));
Jeff Brownbcdfc622014-03-06 19:13:04 -08001760 mSupportAutoRotation = mContext.getResources().getBoolean(
1761 com.android.internal.R.bool.config_supportAutoRotation);
Dianne Hackborn2862fff2009-09-15 22:56:29 -07001762 mLidOpenRotation = readRotation(
Mike Lockwood2d1efbd2009-09-16 12:15:53 -04001763 com.android.internal.R.integer.config_lidOpenRotation);
1764 mCarDockRotation = readRotation(
1765 com.android.internal.R.integer.config_carDockRotation);
1766 mDeskDockRotation = readRotation(
1767 com.android.internal.R.integer.config_deskDockRotation);
Jeff Brownc82c89ed2013-04-17 17:18:15 -07001768 mUndockedHdmiRotation = readRotation(
1769 com.android.internal.R.integer.config_undockedHdmiRotation);
Mike Lockwoode9867d22009-09-20 01:59:02 -04001770 mCarDockEnablesAccelerometer = mContext.getResources().getBoolean(
1771 com.android.internal.R.bool.config_carDockEnablesAccelerometer);
1772 mDeskDockEnablesAccelerometer = mContext.getResources().getBoolean(
1773 com.android.internal.R.bool.config_deskDockEnablesAccelerometer);
Dianne Hackborn2862fff2009-09-15 22:56:29 -07001774 mLidKeyboardAccessibility = mContext.getResources().getInteger(
1775 com.android.internal.R.integer.config_lidKeyboardAccessibility);
1776 mLidNavigationAccessibility = mContext.getResources().getInteger(
1777 com.android.internal.R.integer.config_lidNavigationAccessibility);
Edward Savage-Jones7def60d2015-11-13 13:27:03 +01001778 mLidControlsScreenLock = mContext.getResources().getBoolean(
1779 com.android.internal.R.bool.config_lidControlsScreenLock);
Jeff Brownc458ce92012-04-30 14:58:40 -07001780 mLidControlsSleep = mContext.getResources().getBoolean(
1781 com.android.internal.R.bool.config_lidControlsSleep);
Daniel Sandlerdd73ee42013-10-11 22:19:59 -04001782 mTranslucentDecorEnabled = mContext.getResources().getBoolean(
1783 com.android.internal.R.bool.config_enableTranslucentDecor);
Bryce Lee584a4452014-10-21 15:55:55 -07001784
1785 mAllowTheaterModeWakeFromKey = mContext.getResources().getBoolean(
1786 com.android.internal.R.bool.config_allowTheaterModeWakeFromKey);
1787 mAllowTheaterModeWakeFromPowerKey = mAllowTheaterModeWakeFromKey
1788 || mContext.getResources().getBoolean(
1789 com.android.internal.R.bool.config_allowTheaterModeWakeFromPowerKey);
1790 mAllowTheaterModeWakeFromMotion = mContext.getResources().getBoolean(
1791 com.android.internal.R.bool.config_allowTheaterModeWakeFromMotion);
Bryce Lee812d7022014-11-10 13:33:28 -08001792 mAllowTheaterModeWakeFromMotionWhenNotDreaming = mContext.getResources().getBoolean(
1793 com.android.internal.R.bool.config_allowTheaterModeWakeFromMotionWhenNotDreaming);
Bryce Lee584a4452014-10-21 15:55:55 -07001794 mAllowTheaterModeWakeFromCameraLens = mContext.getResources().getBoolean(
1795 com.android.internal.R.bool.config_allowTheaterModeWakeFromCameraLens);
1796 mAllowTheaterModeWakeFromLidSwitch = mContext.getResources().getBoolean(
1797 com.android.internal.R.bool.config_allowTheaterModeWakeFromLidSwitch);
1798 mAllowTheaterModeWakeFromWakeGesture = mContext.getResources().getBoolean(
1799 com.android.internal.R.bool.config_allowTheaterModeWakeFromGesture);
1800
Bryce Lee55e846d2014-11-04 12:43:44 -08001801 mGoToSleepOnButtonPressTheaterMode = mContext.getResources().getBoolean(
1802 com.android.internal.R.bool.config_goToSleepOnButtonPressTheaterMode);
1803
Bryce Leed3b28402015-03-09 15:49:13 +00001804 mSupportLongPressPowerWhenNonInteractive = mContext.getResources().getBoolean(
1805 com.android.internal.R.bool.config_supportLongPressPowerWhenNonInteractive);
1806
Anthony Hugh34f09ca2016-03-04 12:03:37 -08001807 mLongPressOnBackBehavior = mContext.getResources().getInteger(
1808 com.android.internal.R.integer.config_longPressOnBackBehavior);
Anthony Hugh96e9cc52016-07-12 15:17:24 -07001809 mPanicPressOnBackBehavior = mContext.getResources().getInteger(
1810 com.android.internal.R.integer.config_backPanicBehavior);
Anthony Hugh34f09ca2016-03-04 12:03:37 -08001811
Jeff Brown13f00f02014-10-31 14:45:50 -07001812 mShortPressOnPowerBehavior = mContext.getResources().getInteger(
1813 com.android.internal.R.integer.config_shortPressOnPowerBehavior);
1814 mLongPressOnPowerBehavior = mContext.getResources().getInteger(
1815 com.android.internal.R.integer.config_longPressOnPowerBehavior);
1816 mDoublePressOnPowerBehavior = mContext.getResources().getInteger(
1817 com.android.internal.R.integer.config_doublePressOnPowerBehavior);
1818 mTriplePressOnPowerBehavior = mContext.getResources().getInteger(
1819 com.android.internal.R.integer.config_triplePressOnPowerBehavior);
Filip Gruszczynskia483a1d2015-03-17 19:06:58 +00001820 mShortPressOnSleepBehavior = mContext.getResources().getInteger(
1821 com.android.internal.R.integer.config_shortPressOnSleepBehavior);
Jeff Brown13f00f02014-10-31 14:45:50 -07001822
John Spurlock61560172015-02-06 19:46:04 -05001823 mUseTvRouting = AudioSystem.getPlatformType(mContext) == AudioSystem.PLATFORM_TELEVISION;
RoboErik001c59c2015-01-26 15:53:51 -08001824
Jeff Brownf71343d2013-05-31 17:59:11 -07001825 readConfigurationDependentBehaviors();
Jeff Browncaca8812013-05-09 13:34:33 -07001826
Svetoslav8e3feb12014-02-24 13:46:47 -08001827 mAccessibilityManager = (AccessibilityManager) context.getSystemService(
1828 Context.ACCESSIBILITY_SERVICE);
1829
Mike Lockwood1753f7f2009-08-24 14:49:07 -07001830 // register for dock events
Dianne Hackborn78968392010-03-04 20:47:56 -08001831 IntentFilter filter = new IntentFilter();
1832 filter.addAction(UiModeManager.ACTION_ENTER_CAR_MODE);
1833 filter.addAction(UiModeManager.ACTION_EXIT_CAR_MODE);
1834 filter.addAction(UiModeManager.ACTION_ENTER_DESK_MODE);
1835 filter.addAction(UiModeManager.ACTION_EXIT_DESK_MODE);
Dianne Hackborn867ab6472010-04-29 13:28:56 -07001836 filter.addAction(Intent.ACTION_DOCK_EVENT);
1837 Intent intent = context.registerReceiver(mDockReceiver, filter);
1838 if (intent != null) {
1839 // Retrieve current sticky dock event broadcast.
1840 mDockMode = intent.getIntExtra(Intent.EXTRA_DOCK_STATE,
1841 Intent.EXTRA_DOCK_STATE_UNDOCKED);
1842 }
Daniel Sandler7e37df52011-11-16 22:08:23 -08001843
Jeff Brown6aaf2952012-10-05 16:01:08 -07001844 // register for dream-related broadcasts
1845 filter = new IntentFilter();
1846 filter.addAction(Intent.ACTION_DREAMING_STARTED);
1847 filter.addAction(Intent.ACTION_DREAMING_STOPPED);
1848 context.registerReceiver(mDreamReceiver, filter);
1849
Christopher Tate5e08af02012-09-21 17:17:22 -07001850 // register for multiuser-relevant broadcasts
1851 filter = new IntentFilter(Intent.ACTION_USER_SWITCHED);
1852 context.registerReceiver(mMultiuserReceiver, filter);
1853
John Spurlock57306e62013-04-22 09:48:49 -04001854 // monitor for system gestures
Craig Mautner037aa8d2013-06-07 10:35:44 -07001855 mSystemGestures = new SystemGesturesPointerEventListener(context,
1856 new SystemGesturesPointerEventListener.Callbacks() {
John Spurlock57306e62013-04-22 09:48:49 -04001857 @Override
1858 public void onSwipeFromTop() {
John Spurlock04db1762013-05-13 12:46:41 -04001859 if (mStatusBar != null) {
John Spurlocke1f366f2013-08-05 12:22:40 -04001860 requestTransientBars(mStatusBar);
John Spurlock04db1762013-05-13 12:46:41 -04001861 }
John Spurlockad3e6cb2013-04-30 08:47:43 -04001862 }
1863 @Override
1864 public void onSwipeFromBottom() {
Adrian Roos85d202b2016-06-02 16:27:47 -07001865 if (mNavigationBar != null && mNavigationBarPosition == NAV_BAR_BOTTOM) {
John Spurlocke1f366f2013-08-05 12:22:40 -04001866 requestTransientBars(mNavigationBar);
John Spurlockad3e6cb2013-04-30 08:47:43 -04001867 }
1868 }
1869 @Override
1870 public void onSwipeFromRight() {
Adrian Roos85d202b2016-06-02 16:27:47 -07001871 if (mNavigationBar != null && mNavigationBarPosition == NAV_BAR_RIGHT) {
1872 requestTransientBars(mNavigationBar);
1873 }
1874 }
1875 @Override
1876 public void onSwipeFromLeft() {
1877 if (mNavigationBar != null && mNavigationBarPosition == NAV_BAR_LEFT) {
John Spurlocke1f366f2013-08-05 12:22:40 -04001878 requestTransientBars(mNavigationBar);
John Spurlockad3e6cb2013-04-30 08:47:43 -04001879 }
1880 }
1881 @Override
Michael Wrighta4d22d72015-09-16 23:19:26 +01001882 public void onFling(int duration) {
1883 if (mPowerManagerInternal != null) {
1884 mPowerManagerInternal.powerHint(
Ruchi Kandoi0d434042016-10-03 09:12:02 -07001885 PowerHint.INTERACTION, duration);
Michael Wrighta4d22d72015-09-16 23:19:26 +01001886 }
1887 }
1888 @Override
John Spurlockad3e6cb2013-04-30 08:47:43 -04001889 public void onDebug() {
John Spurlockd67ec252013-09-05 11:31:54 -04001890 // no-op
John Spurlockad3e6cb2013-04-30 08:47:43 -04001891 }
Adrian Roos3595be42015-03-05 16:31:15 +01001892 @Override
1893 public void onDown() {
1894 mOrientationListener.onTouchStart();
1895 }
1896 @Override
1897 public void onUpOrCancel() {
1898 mOrientationListener.onTouchEnd();
1899 }
Jun Mukaid2e7e352015-07-22 17:14:02 -07001900 @Override
1901 public void onMouseHoverAtTop() {
1902 mHandler.removeMessages(MSG_REQUEST_TRANSIENT_BARS);
1903 Message msg = mHandler.obtainMessage(MSG_REQUEST_TRANSIENT_BARS);
1904 msg.arg1 = MSG_REQUEST_TRANSIENT_BARS_ARG_STATUS;
1905 mHandler.sendMessageDelayed(msg, 500);
1906 }
1907 @Override
1908 public void onMouseHoverAtBottom() {
1909 mHandler.removeMessages(MSG_REQUEST_TRANSIENT_BARS);
1910 Message msg = mHandler.obtainMessage(MSG_REQUEST_TRANSIENT_BARS);
1911 msg.arg1 = MSG_REQUEST_TRANSIENT_BARS_ARG_NAVIGATION;
1912 mHandler.sendMessageDelayed(msg, 500);
1913 }
1914 @Override
1915 public void onMouseLeaveFromEdge() {
1916 mHandler.removeMessages(MSG_REQUEST_TRANSIENT_BARS);
1917 }
John Spurlockad3e6cb2013-04-30 08:47:43 -04001918 });
John Spurlockf1a36642013-10-12 17:50:42 -04001919 mImmersiveModeConfirmation = new ImmersiveModeConfirmation(mContext);
Craig Mautner037aa8d2013-06-07 10:35:44 -07001920 mWindowManagerFuncs.registerPointerEventListener(mSystemGestures);
John Spurlock32beb2c2013-03-11 10:16:47 -04001921
Jeff Brownc2346132012-04-13 01:55:38 -07001922 mVibrator = (Vibrator)context.getSystemService(Context.VIBRATOR_SERVICE);
Dianne Hackbornb1a79802009-09-29 15:18:31 -07001923 mLongPressVibePattern = getLongIntArray(mContext.getResources(),
1924 com.android.internal.R.array.config_longPressVibePattern);
1925 mVirtualKeyVibePattern = getLongIntArray(mContext.getResources(),
1926 com.android.internal.R.array.config_virtualKeyVibePattern);
Amith Yamasanic33cb712010-02-10 15:21:49 -08001927 mKeyboardTapVibePattern = getLongIntArray(mContext.getResources(),
1928 com.android.internal.R.array.config_keyboardTapVibePattern);
Fabrice Di Meglioeeff63a2013-08-05 12:07:24 -07001929 mClockTickVibePattern = getLongIntArray(mContext.getResources(),
1930 com.android.internal.R.array.config_clockTickVibePattern);
Fabrice Di Megliobd9152f2013-10-01 11:21:31 -07001931 mCalendarDateVibePattern = getLongIntArray(mContext.getResources(),
1932 com.android.internal.R.array.config_calendarDateVibePattern);
Dianne Hackbornb1a79802009-09-29 15:18:31 -07001933 mSafeModeDisabledVibePattern = getLongIntArray(mContext.getResources(),
1934 com.android.internal.R.array.config_safeModeDisabledVibePattern);
1935 mSafeModeEnabledVibePattern = getLongIntArray(mContext.getResources(),
1936 com.android.internal.R.array.config_safeModeEnabledVibePattern);
Mady Mellore8608912015-06-05 09:02:55 -07001937 mContextClickVibePattern = getLongIntArray(mContext.getResources(),
1938 com.android.internal.R.array.config_contextClickVibePattern);
Daniel Sandler40427442010-07-16 11:44:52 -04001939
Christopher Tatee90585f2012-03-05 18:56:25 -08001940 mScreenshotChordEnabled = mContext.getResources().getBoolean(
1941 com.android.internal.R.bool.config_enableScreenshotChord);
1942
Justin Kohd378ad72013-04-01 12:18:26 -07001943 mGlobalKeyManager = new GlobalKeyManager(mContext);
1944
Joe Onoratoea495d42011-04-06 11:41:11 -07001945 // Controls rotation and the like.
1946 initializeHdmiState();
Dianne Hackborn40011092011-09-22 13:37:48 -07001947
1948 // Match current screen state.
Craig Mautnera631d492014-08-05 15:16:01 -07001949 if (!mPowerManager.isInteractive()) {
Jeff Brown416c49c2015-05-26 19:50:18 -07001950 startedGoingToSleep(WindowManagerPolicy.OFF_BECAUSE_OF_USER);
1951 finishedGoingToSleep(WindowManagerPolicy.OFF_BECAUSE_OF_USER);
Dianne Hackborn40011092011-09-22 13:37:48 -07001952 }
Jorim Jaggi24bec7c2015-02-04 12:40:14 +01001953
1954 mWindowManagerInternal.registerAppTransitionListener(
1955 mStatusBarController.getAppTransitionListener());
Jorim Jaggife762342016-10-13 14:33:27 +02001956 mWindowManagerInternal.registerAppTransitionListener(new AppTransitionListener() {
1957 @Override
1958 public int onAppTransitionStartingLocked(int transit, IBinder openToken,
1959 IBinder closeToken,
1960 Animation openAnimation, Animation closeAnimation) {
1961 return handleStartTransitionForKeyguardLw(transit, openAnimation);
1962 }
1963
1964 @Override
1965 public void onAppTransitionCancelledLocked(int transit) {
1966 handleStartTransitionForKeyguardLw(transit, null /* transit */);
1967 }
1968 });
Mike Lockwood1753f7f2009-08-24 14:49:07 -07001969 }
1970
Jeff Brownf71343d2013-05-31 17:59:11 -07001971 /**
1972 * Read values from config.xml that may be overridden depending on
1973 * the configuration of the device.
1974 * eg. Disable long press on home goes to recents on sw600dp.
1975 */
1976 private void readConfigurationDependentBehaviors() {
Jaewan Kimc552b042016-01-18 16:08:45 +09001977 final Resources res = mContext.getResources();
1978
1979 mLongPressOnHomeBehavior = res.getInteger(
Jeff Brownf71343d2013-05-31 17:59:11 -07001980 com.android.internal.R.integer.config_longPressOnHomeBehavior);
1981 if (mLongPressOnHomeBehavior < LONG_PRESS_HOME_NOTHING ||
Jaewan Kim52632e22016-01-14 18:01:52 +09001982 mLongPressOnHomeBehavior > LAST_LONG_PRESS_HOME_BEHAVIOR) {
Jeff Brownf71343d2013-05-31 17:59:11 -07001983 mLongPressOnHomeBehavior = LONG_PRESS_HOME_NOTHING;
1984 }
1985
Jaewan Kimc552b042016-01-18 16:08:45 +09001986 mDoubleTapOnHomeBehavior = res.getInteger(
Jeff Brownf71343d2013-05-31 17:59:11 -07001987 com.android.internal.R.integer.config_doubleTapOnHomeBehavior);
1988 if (mDoubleTapOnHomeBehavior < DOUBLE_TAP_HOME_NOTHING ||
1989 mDoubleTapOnHomeBehavior > DOUBLE_TAP_HOME_RECENT_SYSTEM_UI) {
1990 mDoubleTapOnHomeBehavior = LONG_PRESS_HOME_NOTHING;
1991 }
Jaewan Kim49117872016-01-19 17:24:08 +09001992
1993 mShortPressWindowBehavior = SHORT_PRESS_WINDOW_NOTHING;
1994 if (mContext.getPackageManager().hasSystemFeature(FEATURE_PICTURE_IN_PICTURE)) {
1995 mShortPressWindowBehavior = SHORT_PRESS_WINDOW_PICTURE_IN_PICTURE;
1996 }
Yorke Lee2e4b7322016-03-02 17:33:06 -08001997
Yorke Lee9b2ffb32016-03-07 20:42:01 -08001998 mNavBarOpacityMode = res.getInteger(
1999 com.android.internal.R.integer.config_navBarOpacityMode);
Jeff Brownf71343d2013-05-31 17:59:11 -07002000 }
2001
Craig Mautner0bf6ec92012-12-18 08:33:27 -08002002 @Override
Dianne Hackborndde331c2012-08-03 14:01:57 -07002003 public void setInitialDisplaySize(Display display, int width, int height, int density) {
Jeff Brownef981a42013-08-07 14:13:37 -07002004 // This method might be called before the policy has been fully initialized
2005 // or for other displays we don't care about.
Andrii Kulian3a507b52016-09-19 18:14:12 -07002006 // TODO(multi-display): Define policy for secondary displays.
Jeff Brownef981a42013-08-07 14:13:37 -07002007 if (mContext == null || display.getDisplayId() != Display.DEFAULT_DISPLAY) {
2008 return;
Dianne Hackbornc652de82013-02-15 16:32:56 -08002009 }
Dianne Hackbornf87d1962012-04-04 12:48:24 -07002010 mDisplay = display;
2011
Craig Mautner46ac6fa2013-08-01 10:06:34 -07002012 final Resources res = mContext.getResources();
Dianne Hackbornf87d1962012-04-04 12:48:24 -07002013 int shortSize, longSize;
Dianne Hackborn9d132642011-04-21 17:26:39 -07002014 if (width > height) {
Dianne Hackborn81e56d52011-05-26 00:55:58 -07002015 shortSize = height;
Dianne Hackbornf87d1962012-04-04 12:48:24 -07002016 longSize = width;
Dianne Hackborn9d132642011-04-21 17:26:39 -07002017 mLandscapeRotation = Surface.ROTATION_0;
2018 mSeascapeRotation = Surface.ROTATION_180;
Craig Mautner46ac6fa2013-08-01 10:06:34 -07002019 if (res.getBoolean(com.android.internal.R.bool.config_reverseDefaultRotation)) {
Dianne Hackborn9d132642011-04-21 17:26:39 -07002020 mPortraitRotation = Surface.ROTATION_90;
2021 mUpsideDownRotation = Surface.ROTATION_270;
2022 } else {
2023 mPortraitRotation = Surface.ROTATION_270;
2024 mUpsideDownRotation = Surface.ROTATION_90;
2025 }
2026 } else {
Dianne Hackborn81e56d52011-05-26 00:55:58 -07002027 shortSize = width;
Dianne Hackbornf87d1962012-04-04 12:48:24 -07002028 longSize = height;
Dianne Hackborn9d132642011-04-21 17:26:39 -07002029 mPortraitRotation = Surface.ROTATION_0;
2030 mUpsideDownRotation = Surface.ROTATION_180;
Craig Mautner46ac6fa2013-08-01 10:06:34 -07002031 if (res.getBoolean(com.android.internal.R.bool.config_reverseDefaultRotation)) {
Dianne Hackborn9d132642011-04-21 17:26:39 -07002032 mLandscapeRotation = Surface.ROTATION_270;
2033 mSeascapeRotation = Surface.ROTATION_90;
2034 } else {
2035 mLandscapeRotation = Surface.ROTATION_90;
2036 mSeascapeRotation = Surface.ROTATION_270;
2037 }
2038 }
Dianne Hackborn81e56d52011-05-26 00:55:58 -07002039
Daniel Sandler4a066c52012-04-20 14:49:13 -04002040 // SystemUI (status bar) layout policy
Dianne Hackborndde331c2012-08-03 14:01:57 -07002041 int shortSizeDp = shortSize * DisplayMetrics.DENSITY_DEFAULT / density;
Craig Mautner46ac6fa2013-08-01 10:06:34 -07002042 int longSizeDp = longSize * DisplayMetrics.DENSITY_DEFAULT / density;
Daniel Sandler4a066c52012-04-20 14:49:13 -04002043
Devin Kimd7b12b42014-05-05 14:34:58 -07002044 // Allow the navigation bar to move on non-square small devices (phones).
2045 mNavigationBarCanMove = width != height && shortSizeDp < 600;
Daniel Sandler36412a72011-08-04 09:35:13 -04002046
Craig Mautner46ac6fa2013-08-01 10:06:34 -07002047 mHasNavigationBar = res.getBoolean(com.android.internal.R.bool.config_showNavigationBar);
Jorim Jaggi11c62e12016-04-05 20:41:21 -07002048
John Spurlock80f00c12013-06-13 11:10:51 -04002049 // Allow a system property to override this. Used by the emulator.
2050 // See also hasNavigationBar().
2051 String navBarOverride = SystemProperties.get("qemu.hw.mainkeys");
2052 if ("1".equals(navBarOverride)) {
Dianne Hackbornf87d1962012-04-04 12:48:24 -07002053 mHasNavigationBar = false;
John Spurlock80f00c12013-06-13 11:10:51 -04002054 } else if ("0".equals(navBarOverride)) {
2055 mHasNavigationBar = true;
Daniel Sandler0c4ccff2011-10-19 16:39:14 -04002056 }
2057
Jeff Brown27f1d672012-10-17 18:32:34 -07002058 // For demo purposes, allow the rotation of the HDMI display to be controlled.
2059 // By default, HDMI locks rotation to landscape.
Erik Gilling9a41ef82011-09-26 19:21:03 -07002060 if ("portrait".equals(SystemProperties.get("persist.demo.hdmirotation"))) {
Jeff Brownc82c89ed2013-04-17 17:18:15 -07002061 mDemoHdmiRotation = mPortraitRotation;
Erik Gilling9a41ef82011-09-26 19:21:03 -07002062 } else {
Jeff Brownc82c89ed2013-04-17 17:18:15 -07002063 mDemoHdmiRotation = mLandscapeRotation;
Erik Gilling9a41ef82011-09-26 19:21:03 -07002064 }
Jeff Brownc82c89ed2013-04-17 17:18:15 -07002065 mDemoHdmiRotationLock = SystemProperties.getBoolean("persist.demo.hdmirotationlock", false);
Craig Mautner46ac6fa2013-08-01 10:06:34 -07002066
Chong Zhangae6119ff2014-11-11 18:54:39 -08002067 // For demo purposes, allow the rotation of the remote display to be controlled.
2068 // By default, remote display locks rotation to landscape.
2069 if ("portrait".equals(SystemProperties.get("persist.demo.remoterotation"))) {
2070 mDemoRotation = mPortraitRotation;
2071 } else {
2072 mDemoRotation = mLandscapeRotation;
2073 }
2074 mDemoRotationLock = SystemProperties.getBoolean(
2075 "persist.demo.rotationlock", false);
2076
Craig Mautner46ac6fa2013-08-01 10:06:34 -07002077 // Only force the default orientation if the screen is xlarge, at least 960dp x 720dp, per
2078 // http://developer.android.com/guide/practices/screens_support.html#range
2079 mForceDefaultOrientation = longSizeDp >= 960 && shortSizeDp >= 720 &&
2080 res.getBoolean(com.android.internal.R.bool.config_forceDefaultOrientation) &&
2081 // For debug purposes the next line turns this feature off with:
2082 // $ adb shell setprop config.override_forced_orient true
2083 // $ adb shell wm size reset
2084 !"true".equals(SystemProperties.get("config.override_forced_orient"));
2085 }
2086
Alan Viverette5a0f4ec2013-10-07 15:10:29 -07002087 /**
2088 * @return whether the navigation bar can be hidden, e.g. the device has a
2089 * navigation bar and touch exploration is not enabled
2090 */
2091 private boolean canHideNavigationBar() {
Alan Viverette817f3cd2015-08-13 11:40:14 -04002092 return mHasNavigationBar;
Alan Viverette5a0f4ec2013-10-07 15:10:29 -07002093 }
2094
Craig Mautner46ac6fa2013-08-01 10:06:34 -07002095 @Override
2096 public boolean isDefaultOrientationForced() {
2097 return mForceDefaultOrientation;
Dianne Hackborn9d132642011-04-21 17:26:39 -07002098 }
2099
Dianne Hackbornc652de82013-02-15 16:32:56 -08002100 @Override
2101 public void setDisplayOverscan(Display display, int left, int top, int right, int bottom) {
Andrii Kulian3a507b52016-09-19 18:14:12 -07002102 // TODO(multi-display): Define policy for secondary displays.
Dianne Hackbornc652de82013-02-15 16:32:56 -08002103 if (display.getDisplayId() == Display.DEFAULT_DISPLAY) {
2104 mOverscanLeft = left;
2105 mOverscanTop = top;
2106 mOverscanRight = right;
2107 mOverscanBottom = bottom;
2108 }
2109 }
2110
Dianne Hackbornc777e072010-02-12 13:07:59 -08002111 public void updateSettings() {
2112 ContentResolver resolver = mContext.getContentResolver();
2113 boolean updateRotation = false;
Dianne Hackbornc777e072010-02-12 13:07:59 -08002114 synchronized (mLock) {
Christopher Tate5e08af02012-09-21 17:17:22 -07002115 mEndcallBehavior = Settings.System.getIntForUser(resolver,
David Brownbaf8d092010-03-08 21:52:59 -08002116 Settings.System.END_BUTTON_BEHAVIOR,
Christopher Tate5e08af02012-09-21 17:17:22 -07002117 Settings.System.END_BUTTON_BEHAVIOR_DEFAULT,
2118 UserHandle.USER_CURRENT);
2119 mIncallPowerBehavior = Settings.Secure.getIntForUser(resolver,
David Brownbaf8d092010-03-08 21:52:59 -08002120 Settings.Secure.INCALL_POWER_BUTTON_BEHAVIOR,
Christopher Tate5e08af02012-09-21 17:17:22 -07002121 Settings.Secure.INCALL_POWER_BUTTON_BEHAVIOR_DEFAULT,
2122 UserHandle.USER_CURRENT);
Bryce Leedb776ce2016-09-03 15:02:00 -07002123 mIncallBackBehavior = Settings.Secure.getIntForUser(resolver,
2124 Settings.Secure.INCALL_BACK_BUTTON_BEHAVIOR,
2125 Settings.Secure.INCALL_BACK_BUTTON_BEHAVIOR_DEFAULT,
2126 UserHandle.USER_CURRENT);
Daniel Sandlerb73617d2010-08-17 00:41:00 -04002127
Jeff Browna20dda42014-05-27 20:57:24 -07002128 // Configure wake gesture.
2129 boolean wakeGestureEnabledSetting = Settings.Secure.getIntForUser(resolver,
2130 Settings.Secure.WAKE_GESTURE_ENABLED, 0,
2131 UserHandle.USER_CURRENT) != 0;
2132 if (mWakeGestureEnabledSetting != wakeGestureEnabledSetting) {
2133 mWakeGestureEnabledSetting = wakeGestureEnabledSetting;
2134 updateWakeGestureListenerLp();
2135 }
2136
Jeff Brown207673cd2012-06-05 17:47:11 -07002137 // Configure rotation lock.
Christopher Tate5e08af02012-09-21 17:17:22 -07002138 int userRotation = Settings.System.getIntForUser(resolver,
2139 Settings.System.USER_ROTATION, Surface.ROTATION_0,
2140 UserHandle.USER_CURRENT);
Jeff Brown207673cd2012-06-05 17:47:11 -07002141 if (mUserRotation != userRotation) {
2142 mUserRotation = userRotation;
2143 updateRotation = true;
2144 }
Christopher Tate5e08af02012-09-21 17:17:22 -07002145 int userRotationMode = Settings.System.getIntForUser(resolver,
2146 Settings.System.ACCELEROMETER_ROTATION, 0, UserHandle.USER_CURRENT) != 0 ?
Jeff Brown207673cd2012-06-05 17:47:11 -07002147 WindowManagerPolicy.USER_ROTATION_FREE :
2148 WindowManagerPolicy.USER_ROTATION_LOCKED;
2149 if (mUserRotationMode != userRotationMode) {
2150 mUserRotationMode = userRotationMode;
2151 updateRotation = true;
Dianne Hackbornc777e072010-02-12 13:07:59 -08002152 updateOrientationListenerLp();
2153 }
Daniel Sandlerb73617d2010-08-17 00:41:00 -04002154
Dianne Hackbornc777e072010-02-12 13:07:59 -08002155 if (mSystemReady) {
Christopher Tate5e08af02012-09-21 17:17:22 -07002156 int pointerLocation = Settings.System.getIntForUser(resolver,
2157 Settings.System.POINTER_LOCATION, 0, UserHandle.USER_CURRENT);
Dianne Hackbornc777e072010-02-12 13:07:59 -08002158 if (mPointerLocationMode != pointerLocation) {
2159 mPointerLocationMode = pointerLocation;
Jeff Brown70825162012-03-28 17:27:48 -07002160 mHandler.sendEmptyMessage(pointerLocation != 0 ?
2161 MSG_ENABLE_POINTER_LOCATION : MSG_DISABLE_POINTER_LOCATION);
Dianne Hackbornc777e072010-02-12 13:07:59 -08002162 }
2163 }
2164 // use screen off timeout setting as the timeout for the lockscreen
Christopher Tate5e08af02012-09-21 17:17:22 -07002165 mLockScreenTimeout = Settings.System.getIntForUser(resolver,
2166 Settings.System.SCREEN_OFF_TIMEOUT, 0, UserHandle.USER_CURRENT);
2167 String imId = Settings.Secure.getStringForUser(resolver,
2168 Settings.Secure.DEFAULT_INPUT_METHOD, UserHandle.USER_CURRENT);
Dianne Hackbornc777e072010-02-12 13:07:59 -08002169 boolean hasSoftInput = imId != null && imId.length() > 0;
2170 if (mHasSoftInput != hasSoftInput) {
2171 mHasSoftInput = hasSoftInput;
2172 updateRotation = true;
2173 }
John Spurlockf1a36642013-10-12 17:50:42 -04002174 if (mImmersiveModeConfirmation != null) {
John Spurlock4355a532014-02-19 09:49:25 -05002175 mImmersiveModeConfirmation.loadSetting(mCurrentUserId);
John Spurlockd67ec252013-09-05 11:31:54 -04002176 }
tiger_huangcc6366d2015-06-29 17:17:30 +08002177 }
2178 synchronized (mWindowManagerFuncs.getWindowManagerLock()) {
John Spurlockc6d1c602014-01-17 15:22:06 -05002179 PolicyControl.reloadFromSetting(mContext);
Dianne Hackbornc777e072010-02-12 13:07:59 -08002180 }
2181 if (updateRotation) {
Jeff Brown01a98dd2011-09-20 15:08:29 -07002182 updateRotation(true);
Dianne Hackbornc777e072010-02-12 13:07:59 -08002183 }
Jeff Brown70825162012-03-28 17:27:48 -07002184 }
2185
Jeff Browna20dda42014-05-27 20:57:24 -07002186 private void updateWakeGestureListenerLp() {
2187 if (shouldEnableWakeGestureLp()) {
2188 mWakeGestureListener.requestWakeUpTrigger();
2189 } else {
2190 mWakeGestureListener.cancelWakeUpTrigger();
2191 }
2192 }
2193
2194 private boolean shouldEnableWakeGestureLp() {
Jeff Brown3ee549c2014-09-22 20:14:39 -07002195 return mWakeGestureEnabledSetting && !mAwake
Jeff Browna20dda42014-05-27 20:57:24 -07002196 && (!mLidControlsSleep || mLidState != LID_CLOSED)
2197 && mWakeGestureListener.isSupported();
2198 }
2199
Jeff Brown70825162012-03-28 17:27:48 -07002200 private void enablePointerLocation() {
2201 if (mPointerLocationView == null) {
2202 mPointerLocationView = new PointerLocationView(mContext);
2203 mPointerLocationView.setPrintCoords(false);
Dianne Hackbornc777e072010-02-12 13:07:59 -08002204 WindowManager.LayoutParams lp = new WindowManager.LayoutParams(
2205 WindowManager.LayoutParams.MATCH_PARENT,
2206 WindowManager.LayoutParams.MATCH_PARENT);
Jeff Brown3b2b3542010-10-15 00:54:27 -07002207 lp.type = WindowManager.LayoutParams.TYPE_SECURE_SYSTEM_OVERLAY;
Jeff Brownbfcb60a2011-09-08 18:51:14 -07002208 lp.flags = WindowManager.LayoutParams.FLAG_FULLSCREEN
2209 | WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE
2210 | WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE
2211 | WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN;
Jeff Brown90fc9052012-10-01 14:44:24 -07002212 if (ActivityManager.isHighEndGfx()) {
2213 lp.flags |= WindowManager.LayoutParams.FLAG_HARDWARE_ACCELERATED;
2214 lp.privateFlags |=
2215 WindowManager.LayoutParams.PRIVATE_FLAG_FORCE_HARDWARE_ACCELERATED;
2216 }
Dianne Hackbornc777e072010-02-12 13:07:59 -08002217 lp.format = PixelFormat.TRANSLUCENT;
2218 lp.setTitle("PointerLocation");
Dianne Hackborn5fd21692011-06-07 14:09:47 -07002219 WindowManager wm = (WindowManager)
Dianne Hackbornc777e072010-02-12 13:07:59 -08002220 mContext.getSystemService(Context.WINDOW_SERVICE);
Jeff Browncc4f7db2011-08-30 20:34:48 -07002221 lp.inputFeatures |= WindowManager.LayoutParams.INPUT_FEATURE_NO_INPUT_CHANNEL;
Jeff Brown70825162012-03-28 17:27:48 -07002222 wm.addView(mPointerLocationView, lp);
Michael Wrightc9c487e2013-11-07 18:55:09 -08002223 mWindowManagerFuncs.registerPointerEventListener(mPointerLocationView);
Dianne Hackbornc777e072010-02-12 13:07:59 -08002224 }
Dianne Hackbornc777e072010-02-12 13:07:59 -08002225 }
Jeff Brown70825162012-03-28 17:27:48 -07002226
2227 private void disablePointerLocation() {
Jeff Brown70825162012-03-28 17:27:48 -07002228 if (mPointerLocationView != null) {
Michael Wrightc9c487e2013-11-07 18:55:09 -08002229 mWindowManagerFuncs.unregisterPointerEventListener(mPointerLocationView);
2230 WindowManager wm = (WindowManager) mContext.getSystemService(Context.WINDOW_SERVICE);
Jeff Brown70825162012-03-28 17:27:48 -07002231 wm.removeView(mPointerLocationView);
2232 mPointerLocationView = null;
2233 }
2234 }
2235
Mike Lockwood2d1efbd2009-09-16 12:15:53 -04002236 private int readRotation(int resID) {
Mike Lockwood1753f7f2009-08-24 14:49:07 -07002237 try {
2238 int rotation = mContext.getResources().getInteger(resID);
2239 switch (rotation) {
2240 case 0:
2241 return Surface.ROTATION_0;
2242 case 90:
2243 return Surface.ROTATION_90;
2244 case 180:
2245 return Surface.ROTATION_180;
2246 case 270:
2247 return Surface.ROTATION_270;
Mike Lockwood1753f7f2009-08-24 14:49:07 -07002248 }
2249 } catch (Resources.NotFoundException e) {
Mike Lockwood2d1efbd2009-09-16 12:15:53 -04002250 // fall through
Mike Lockwood1753f7f2009-08-24 14:49:07 -07002251 }
Mike Lockwood2d1efbd2009-09-16 12:15:53 -04002252 return -1;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002253 }
2254
2255 /** {@inheritDoc} */
Craig Mautner88400d32012-09-30 12:35:45 -07002256 @Override
Dianne Hackbornc2293022013-02-06 23:14:49 -08002257 public int checkAddPermission(WindowManager.LayoutParams attrs, int[] outAppOp) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002258 int type = attrs.type;
Dianne Hackbornc2293022013-02-06 23:14:49 -08002259
2260 outAppOp[0] = AppOpsManager.OP_NONE;
2261
Wale Ogunwale74bf0652015-01-12 10:24:36 -08002262 if (!((type >= FIRST_APPLICATION_WINDOW && type <= LAST_APPLICATION_WINDOW)
2263 || (type >= FIRST_SUB_WINDOW && type <= LAST_SUB_WINDOW)
2264 || (type >= FIRST_SYSTEM_WINDOW && type <= LAST_SYSTEM_WINDOW))) {
2265 return WindowManagerGlobal.ADD_INVALID_TYPE;
2266 }
2267
2268 if (type < FIRST_SYSTEM_WINDOW || type > LAST_SYSTEM_WINDOW) {
2269 // Window manager will make sure these are okay.
Jeff Brown98365d72012-08-19 20:30:52 -07002270 return WindowManagerGlobal.ADD_OKAY;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002271 }
2272 String permission = null;
2273 switch (type) {
2274 case TYPE_TOAST:
2275 // XXX right now the app process has complete control over
2276 // this... should introduce a token to let the system
2277 // monitor/control what they are doing.
Jason Monk1c7c3192014-06-26 12:52:18 -04002278 outAppOp[0] = AppOpsManager.OP_TOAST_WINDOW;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002279 break;
Daniel Sandler7d276c32012-01-30 14:33:52 -05002280 case TYPE_DREAM:
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002281 case TYPE_INPUT_METHOD:
Dianne Hackbornb7cd8b92009-08-08 20:53:03 -07002282 case TYPE_WALLPAPER:
Wale Ogunwale5b6714c2016-11-01 20:54:46 -07002283 case TYPE_PRESENTATION:
keunyounga446bf02013-06-21 19:07:57 -07002284 case TYPE_PRIVATE_PRESENTATION:
Dianne Hackborne30e02f2014-05-27 18:24:45 -07002285 case TYPE_VOICE_INTERACTION:
Svetoslav3a5c7212014-10-14 09:54:26 -07002286 case TYPE_ACCESSIBILITY_OVERLAY:
Jason Monk8f7f3182015-11-18 16:35:14 -05002287 case TYPE_QS_DIALOG:
Dianne Hackbornb7cd8b92009-08-08 20:53:03 -07002288 // The window manager will check these.
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002289 break;
2290 case TYPE_PHONE:
2291 case TYPE_PRIORITY_PHONE:
2292 case TYPE_SYSTEM_ALERT:
2293 case TYPE_SYSTEM_ERROR:
2294 case TYPE_SYSTEM_OVERLAY:
2295 permission = android.Manifest.permission.SYSTEM_ALERT_WINDOW;
Dianne Hackbornc2293022013-02-06 23:14:49 -08002296 outAppOp[0] = AppOpsManager.OP_SYSTEM_ALERT_WINDOW;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002297 break;
2298 default:
2299 permission = android.Manifest.permission.INTERNAL_SYSTEM_WINDOW;
2300 }
2301 if (permission != null) {
Svet Ganov9cea80cd2016-02-16 11:47:00 -08002302 if (android.Manifest.permission.SYSTEM_ALERT_WINDOW.equals(permission)) {
Billy Laucbe540f2015-06-25 01:51:44 +01002303 final int callingUid = Binder.getCallingUid();
Billy Lau060275f2015-07-15 22:29:19 +01002304 // system processes will be automatically allowed privilege to draw
Billy Laucbe540f2015-06-25 01:51:44 +01002305 if (callingUid == Process.SYSTEM_UID) {
2306 return WindowManagerGlobal.ADD_OKAY;
2307 }
2308
Billy Lau060275f2015-07-15 22:29:19 +01002309 // check if user has enabled this operation. SecurityException will be thrown if
2310 // this app has not been allowed by the user
Svet Ganov03f2afc2016-03-04 16:13:03 -08002311 final int mode = mAppOpsManager.checkOpNoThrow(outAppOp[0], callingUid,
Billy Laucbe540f2015-06-25 01:51:44 +01002312 attrs.packageName);
Billy Lau060275f2015-07-15 22:29:19 +01002313 switch (mode) {
2314 case AppOpsManager.MODE_ALLOWED:
2315 case AppOpsManager.MODE_IGNORED:
2316 // although we return ADD_OKAY for MODE_IGNORED, the added window will
2317 // actually be hidden in WindowManagerService
2318 return WindowManagerGlobal.ADD_OKAY;
2319 case AppOpsManager.MODE_ERRORED:
Svet Ganov03f2afc2016-03-04 16:13:03 -08002320 try {
2321 ApplicationInfo appInfo = mContext.getPackageManager()
2322 .getApplicationInfo(attrs.packageName,
2323 UserHandle.getUserId(callingUid));
2324 // Don't crash legacy apps
2325 if (appInfo.targetSdkVersion < Build.VERSION_CODES.M) {
2326 return WindowManagerGlobal.ADD_OKAY;
2327 }
2328 } catch (PackageManager.NameNotFoundException e) {
2329 /* ignore */
2330 }
Billy Laucbe540f2015-06-25 01:51:44 +01002331 return WindowManagerGlobal.ADD_PERMISSION_DENIED;
Billy Lau060275f2015-07-15 22:29:19 +01002332 default:
2333 // in the default mode, we will make a decision here based on
2334 // checkCallingPermission()
2335 if (mContext.checkCallingPermission(permission) !=
2336 PackageManager.PERMISSION_GRANTED) {
2337 return WindowManagerGlobal.ADD_PERMISSION_DENIED;
2338 } else {
2339 return WindowManagerGlobal.ADD_OKAY;
2340 }
Billy Laucbe540f2015-06-25 01:51:44 +01002341 }
Billy Laucbe540f2015-06-25 01:51:44 +01002342 }
2343
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002344 if (mContext.checkCallingOrSelfPermission(permission)
2345 != PackageManager.PERMISSION_GRANTED) {
Jeff Brown98365d72012-08-19 20:30:52 -07002346 return WindowManagerGlobal.ADD_PERMISSION_DENIED;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002347 }
2348 }
Jeff Brown98365d72012-08-19 20:30:52 -07002349 return WindowManagerGlobal.ADD_OKAY;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002350 }
Craig Mautner88400d32012-09-30 12:35:45 -07002351
2352 @Override
2353 public boolean checkShowToOwnerOnly(WindowManager.LayoutParams attrs) {
2354
2355 // If this switch statement is modified, modify the comment in the declarations of
2356 // the type in {@link WindowManager.LayoutParams} as well.
2357 switch (attrs.type) {
2358 default:
2359 // These are the windows that by default are shown only to the user that created
2360 // them. If this needs to be overridden, set
2361 // {@link WindowManager.LayoutParams.PRIVATE_FLAG_SHOW_FOR_ALL_USERS} in
2362 // {@link WindowManager.LayoutParams}. Note that permission
2363 // {@link android.Manifest.permission.INTERNAL_SYSTEM_WINDOW} is required as well.
2364 if ((attrs.privateFlags & PRIVATE_FLAG_SHOW_FOR_ALL_USERS) == 0) {
2365 return true;
2366 }
2367 break;
2368
2369 // These are the windows that by default are shown to all users. However, to
2370 // protect against spoofing, check permissions below.
2371 case TYPE_APPLICATION_STARTING:
2372 case TYPE_BOOT_PROGRESS:
2373 case TYPE_DISPLAY_OVERLAY:
Selim Cinekf83e8242015-05-19 18:08:14 -07002374 case TYPE_INPUT_CONSUMER:
Craig Mautner88400d32012-09-30 12:35:45 -07002375 case TYPE_KEYGUARD_DIALOG:
2376 case TYPE_MAGNIFICATION_OVERLAY:
2377 case TYPE_NAVIGATION_BAR:
2378 case TYPE_NAVIGATION_BAR_PANEL:
2379 case TYPE_PHONE:
2380 case TYPE_POINTER:
2381 case TYPE_PRIORITY_PHONE:
Craig Mautner88400d32012-09-30 12:35:45 -07002382 case TYPE_SEARCH_BAR:
2383 case TYPE_STATUS_BAR:
2384 case TYPE_STATUS_BAR_PANEL:
2385 case TYPE_STATUS_BAR_SUB_PANEL:
2386 case TYPE_SYSTEM_DIALOG:
Craig Mautner88400d32012-09-30 12:35:45 -07002387 case TYPE_VOLUME_OVERLAY:
Wale Ogunwale5b6714c2016-11-01 20:54:46 -07002388 case TYPE_PRESENTATION:
keunyounga446bf02013-06-21 19:07:57 -07002389 case TYPE_PRIVATE_PRESENTATION:
Filip Gruszczynski466f3212015-09-21 17:57:57 -07002390 case TYPE_DOCK_DIVIDER:
Craig Mautner88400d32012-09-30 12:35:45 -07002391 break;
2392 }
2393
2394 // Check if third party app has set window to system window type.
2395 return mContext.checkCallingOrSelfPermission(
2396 android.Manifest.permission.INTERNAL_SYSTEM_WINDOW)
2397 != PackageManager.PERMISSION_GRANTED;
2398 }
2399
Craig Mautner967212c2013-04-13 21:10:58 -07002400 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002401 public void adjustWindowParamsLw(WindowManager.LayoutParams attrs) {
2402 switch (attrs.type) {
2403 case TYPE_SYSTEM_OVERLAY:
Jeff Brown3b2b3542010-10-15 00:54:27 -07002404 case TYPE_SECURE_SYSTEM_OVERLAY:
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002405 // These types of windows can't receive input events.
2406 attrs.flags |= WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE
2407 | WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE;
Jeff Brownbfcb60a2011-09-08 18:51:14 -07002408 attrs.flags &= ~WindowManager.LayoutParams.FLAG_WATCH_OUTSIDE_TOUCH;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002409 break;
Jorim Jaggi380ecb82014-03-14 17:25:20 +01002410 case TYPE_STATUS_BAR:
2411
2412 // If the Keyguard is in a hidden state (occluded by another window), we force to
2413 // remove the wallpaper and keyguard flag so that any change in-flight after setting
2414 // the keyguard as occluded wouldn't set these flags again.
2415 // See {@link #processKeyguardSetHiddenResultLw}.
Jorim Jaggife762342016-10-13 14:33:27 +02002416 if (mKeyguardOccluded) {
Jorim Jaggi380ecb82014-03-14 17:25:20 +01002417 attrs.flags &= ~WindowManager.LayoutParams.FLAG_SHOW_WALLPAPER;
2418 attrs.privateFlags &= ~WindowManager.LayoutParams.PRIVATE_FLAG_KEYGUARD;
2419 }
2420 break;
Svetoslav Ganovaa076532016-08-01 19:16:43 -07002421
Muyuan Li36ca72c2016-08-06 20:24:06 -07002422 case TYPE_SCREENSHOT:
2423 attrs.flags |= WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE;
2424 break;
Svetoslav Ganovaa076532016-08-01 19:16:43 -07002425
2426 case TYPE_TOAST:
2427 // While apps should use the dedicated toast APIs to add such windows
2428 // it possible legacy apps to add the window directly. Therefore, we
2429 // make windows added directly by the app behave as a toast as much
2430 // as possible in terms of timeout and animation.
2431 if (attrs.hideTimeoutMilliseconds < 0
2432 || attrs.hideTimeoutMilliseconds > TOAST_WINDOW_TIMEOUT) {
2433 attrs.hideTimeoutMilliseconds = TOAST_WINDOW_TIMEOUT;
2434 }
2435 attrs.windowAnimations = com.android.internal.R.style.Animation_Toast;
2436 break;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002437 }
Adrian Roos38502112014-04-09 21:04:11 +02002438
2439 if (attrs.type != TYPE_STATUS_BAR) {
2440 // The status bar is the only window allowed to exhibit keyguard behavior.
2441 attrs.privateFlags &= ~WindowManager.LayoutParams.PRIVATE_FLAG_KEYGUARD;
2442 }
Adrian Roosea562512014-05-05 13:33:03 +02002443
Jorim Jaggi4fa78922015-11-30 17:13:56 -08002444 if (ActivityManager.isHighEndGfx()) {
2445 if ((attrs.flags & FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS) != 0) {
2446 attrs.subtreeSystemUiVisibility |= View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION;
2447 }
Jorim Jaggi8f5701b2016-04-04 18:36:02 -07002448 final boolean forceWindowDrawsStatusBarBackground =
2449 (attrs.privateFlags & PRIVATE_FLAG_FORCE_DRAW_STATUS_BAR_BACKGROUND)
2450 != 0;
Jorim Jaggi4fa78922015-11-30 17:13:56 -08002451 if ((attrs.flags & FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS) != 0
Jorim Jaggi8f5701b2016-04-04 18:36:02 -07002452 || forceWindowDrawsStatusBarBackground
2453 && attrs.height == MATCH_PARENT && attrs.width == MATCH_PARENT) {
Jorim Jaggi4fa78922015-11-30 17:13:56 -08002454 attrs.subtreeSystemUiVisibility |= View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN;
2455 }
Adrian Roosea562512014-05-05 13:33:03 +02002456 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002457 }
RoboErik8a2cfc32014-05-16 11:19:38 -07002458
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002459 void readLidState() {
Jeff Brown2e7760e2012-04-11 15:14:55 -07002460 mLidState = mWindowManagerFuncs.getLidState();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002461 }
RoboErik8a2cfc32014-05-16 11:19:38 -07002462
Michael Wright3818c922014-09-02 13:59:07 -07002463 private void readCameraLensCoverState() {
2464 mCameraLensCoverState = mWindowManagerFuncs.getCameraLensCoverState();
2465 }
2466
Jeff Browndaa37532012-05-01 15:54:03 -07002467 private boolean isHidden(int accessibilityMode) {
2468 switch (accessibilityMode) {
2469 case 1:
2470 return mLidState == LID_CLOSED;
2471 case 2:
2472 return mLidState == LID_OPEN;
2473 default:
2474 return false;
Dianne Hackborn2862fff2009-09-15 22:56:29 -07002475 }
Dianne Hackborn2862fff2009-09-15 22:56:29 -07002476 }
Jeff Brownd04a88c2011-01-16 14:05:47 -08002477
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002478 /** {@inheritDoc} */
Craig Mautner967212c2013-04-13 21:10:58 -07002479 @Override
Jeff Browndaa37532012-05-01 15:54:03 -07002480 public void adjustConfigurationLw(Configuration config, int keyboardPresence,
2481 int navigationPresence) {
2482 mHaveBuiltInKeyboard = (keyboardPresence & PRESENCE_INTERNAL) != 0;
2483
Jeff Brownf71343d2013-05-31 17:59:11 -07002484 readConfigurationDependentBehaviors();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002485 readLidState();
Jeff Brownd04a88c2011-01-16 14:05:47 -08002486
Jeff Browndaa37532012-05-01 15:54:03 -07002487 if (config.keyboard == Configuration.KEYBOARD_NOKEYS
2488 || (keyboardPresence == PRESENCE_INTERNAL
2489 && isHidden(mLidKeyboardAccessibility))) {
Jeff Brownd04a88c2011-01-16 14:05:47 -08002490 config.hardKeyboardHidden = Configuration.HARDKEYBOARDHIDDEN_YES;
Jeff Browndaa37532012-05-01 15:54:03 -07002491 if (!mHasSoftInput) {
2492 config.keyboardHidden = Configuration.KEYBOARDHIDDEN_YES;
2493 }
Jeff Brownd04a88c2011-01-16 14:05:47 -08002494 }
2495
Jeff Browndaa37532012-05-01 15:54:03 -07002496 if (config.navigation == Configuration.NAVIGATION_NONAV
2497 || (navigationPresence == PRESENCE_INTERNAL
2498 && isHidden(mLidNavigationAccessibility))) {
Jeff Brownd04a88c2011-01-16 14:05:47 -08002499 config.navigationHidden = Configuration.NAVIGATIONHIDDEN_YES;
Jeff Brownd04a88c2011-01-16 14:05:47 -08002500 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002501 }
Jeff Brownd04a88c2011-01-16 14:05:47 -08002502
Jorim Jaggi11c62e12016-04-05 20:41:21 -07002503 @Override
2504 public void onConfigurationChanged() {
Andrii Kulian3a507b52016-09-19 18:14:12 -07002505 // TODO(multi-display): Define policy for secondary displays.
Jorim Jaggi11c62e12016-04-05 20:41:21 -07002506 final Resources res = mContext.getResources();
2507
2508 mStatusBarHeight =
2509 res.getDimensionPixelSize(com.android.internal.R.dimen.status_bar_height);
2510
2511 // Height of the navigation bar when presented horizontally at bottom
2512 mNavigationBarHeightForRotationDefault[mPortraitRotation] =
2513 mNavigationBarHeightForRotationDefault[mUpsideDownRotation] =
2514 res.getDimensionPixelSize(com.android.internal.R.dimen.navigation_bar_height);
2515 mNavigationBarHeightForRotationDefault[mLandscapeRotation] =
2516 mNavigationBarHeightForRotationDefault[mSeascapeRotation] = res.getDimensionPixelSize(
2517 com.android.internal.R.dimen.navigation_bar_height_landscape);
2518
2519 // Width of the navigation bar when presented vertically along one side
2520 mNavigationBarWidthForRotationDefault[mPortraitRotation] =
2521 mNavigationBarWidthForRotationDefault[mUpsideDownRotation] =
2522 mNavigationBarWidthForRotationDefault[mLandscapeRotation] =
2523 mNavigationBarWidthForRotationDefault[mSeascapeRotation] =
2524 res.getDimensionPixelSize(com.android.internal.R.dimen.navigation_bar_width);
2525
Justin Paupore01915a12016-09-28 17:41:26 -07002526 if (ALTERNATE_CAR_MODE_NAV_SIZE) {
2527 // Height of the navigation bar when presented horizontally at bottom
2528 mNavigationBarHeightForRotationInCarMode[mPortraitRotation] =
2529 mNavigationBarHeightForRotationInCarMode[mUpsideDownRotation] =
2530 res.getDimensionPixelSize(
2531 com.android.internal.R.dimen.navigation_bar_height_car_mode);
2532 mNavigationBarHeightForRotationInCarMode[mLandscapeRotation] =
2533 mNavigationBarHeightForRotationInCarMode[mSeascapeRotation] = res.getDimensionPixelSize(
2534 com.android.internal.R.dimen.navigation_bar_height_landscape_car_mode);
Jorim Jaggi11c62e12016-04-05 20:41:21 -07002535
Justin Paupore01915a12016-09-28 17:41:26 -07002536 // Width of the navigation bar when presented vertically along one side
2537 mNavigationBarWidthForRotationInCarMode[mPortraitRotation] =
2538 mNavigationBarWidthForRotationInCarMode[mUpsideDownRotation] =
2539 mNavigationBarWidthForRotationInCarMode[mLandscapeRotation] =
2540 mNavigationBarWidthForRotationInCarMode[mSeascapeRotation] =
2541 res.getDimensionPixelSize(
2542 com.android.internal.R.dimen.navigation_bar_width_car_mode);
2543 }
Jorim Jaggi11c62e12016-04-05 20:41:21 -07002544 }
2545
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002546 /** {@inheritDoc} */
Craig Mautner967212c2013-04-13 21:10:58 -07002547 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002548 public int windowTypeToLayerLw(int type) {
2549 if (type >= FIRST_APPLICATION_WINDOW && type <= LAST_APPLICATION_WINDOW) {
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07002550 return 2;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002551 }
2552 switch (type) {
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07002553 case TYPE_WALLPAPER:
2554 // wallpaper is at the bottom, though the window manager may move it.
Wale Ogunwale3a931692016-11-02 16:49:48 -07002555 return 1;
2556 case TYPE_PRESENTATION:
2557 case TYPE_PRIVATE_PRESENTATION:
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07002558 return 2;
Filip Gruszczynskie95b0ae2015-09-30 10:55:33 -07002559 case TYPE_DOCK_DIVIDER:
2560 return 2;
Jason Monk8f7f3182015-11-18 16:35:14 -05002561 case TYPE_QS_DIALOG:
2562 return 2;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07002563 case TYPE_PHONE:
2564 return 3;
2565 case TYPE_SEARCH_BAR:
Jorim Jaggi225d3b52015-04-01 11:18:57 -07002566 case TYPE_VOICE_INTERACTION_STARTING:
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07002567 return 4;
Dianne Hackborne30e02f2014-05-27 18:24:45 -07002568 case TYPE_VOICE_INTERACTION:
2569 // voice interaction layer is almost immediately above apps.
2570 return 5;
Selim Cinekf83e8242015-05-19 18:08:14 -07002571 case TYPE_INPUT_CONSUMER:
Dianne Hackborne30e02f2014-05-27 18:24:45 -07002572 return 6;
Selim Cinekf83e8242015-05-19 18:08:14 -07002573 case TYPE_SYSTEM_DIALOG:
2574 return 7;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07002575 case TYPE_TOAST:
2576 // toasts and the plugged-in battery thing
Selim Cinekf83e8242015-05-19 18:08:14 -07002577 return 8;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07002578 case TYPE_PRIORITY_PHONE:
2579 // SIM errors and unlock. Not sure if this really should be in a high layer.
Selim Cinekf83e8242015-05-19 18:08:14 -07002580 return 9;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07002581 case TYPE_DREAM:
2582 // used for Dreams (screensavers with TYPE_DREAM windows)
Selim Cinekf83e8242015-05-19 18:08:14 -07002583 return 10;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07002584 case TYPE_SYSTEM_ALERT:
2585 // like the ANR / app crashed dialogs
Selim Cinekf83e8242015-05-19 18:08:14 -07002586 return 11;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07002587 case TYPE_INPUT_METHOD:
2588 // on-screen keyboards and other such input method user interfaces go here.
Selim Cinekf83e8242015-05-19 18:08:14 -07002589 return 12;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07002590 case TYPE_INPUT_METHOD_DIALOG:
2591 // on-screen keyboards and other such input method user interfaces go here.
Selim Cinekf83e8242015-05-19 18:08:14 -07002592 return 13;
Filip Gruszczynski466f3212015-09-21 17:57:57 -07002593 case TYPE_STATUS_BAR_SUB_PANEL:
Filip Gruszczynskie95b0ae2015-09-30 10:55:33 -07002594 return 15;
Filip Gruszczynski466f3212015-09-21 17:57:57 -07002595 case TYPE_STATUS_BAR:
Filip Gruszczynskie95b0ae2015-09-30 10:55:33 -07002596 return 16;
Filip Gruszczynski466f3212015-09-21 17:57:57 -07002597 case TYPE_STATUS_BAR_PANEL:
Filip Gruszczynskie95b0ae2015-09-30 10:55:33 -07002598 return 17;
Filip Gruszczynski466f3212015-09-21 17:57:57 -07002599 case TYPE_KEYGUARD_DIALOG:
Filip Gruszczynskie95b0ae2015-09-30 10:55:33 -07002600 return 18;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07002601 case TYPE_VOLUME_OVERLAY:
2602 // the on-screen volume indicator and controller shown when the user
2603 // changes the device volume
Filip Gruszczynskie95b0ae2015-09-30 10:55:33 -07002604 return 19;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07002605 case TYPE_SYSTEM_OVERLAY:
2606 // the on-screen volume indicator and controller shown when the user
2607 // changes the device volume
Filip Gruszczynskie95b0ae2015-09-30 10:55:33 -07002608 return 20;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07002609 case TYPE_NAVIGATION_BAR:
2610 // the navigation bar, if available, shows atop most things
Filip Gruszczynskie95b0ae2015-09-30 10:55:33 -07002611 return 21;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07002612 case TYPE_NAVIGATION_BAR_PANEL:
2613 // some panels (e.g. search) need to show on top of the navigation bar
Filip Gruszczynskie95b0ae2015-09-30 10:55:33 -07002614 return 22;
Muyuan Li6ca619f2016-03-08 13:30:42 -08002615 case TYPE_SCREENSHOT:
2616 // screenshot selection layer shouldn't go above system error, but it should cover
2617 // navigation bars at the very least.
2618 return 23;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07002619 case TYPE_SYSTEM_ERROR:
2620 // system-level error dialogs
Muyuan Li6ca619f2016-03-08 13:30:42 -08002621 return 24;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07002622 case TYPE_MAGNIFICATION_OVERLAY:
2623 // used to highlight the magnified portion of a display
Muyuan Li6ca619f2016-03-08 13:30:42 -08002624 return 25;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07002625 case TYPE_DISPLAY_OVERLAY:
2626 // used to simulate secondary display devices
Muyuan Li6ca619f2016-03-08 13:30:42 -08002627 return 26;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07002628 case TYPE_DRAG:
2629 // the drag layer: input for drag-and-drop is associated with this window,
2630 // which sits above all other focusable windows
Muyuan Li6ca619f2016-03-08 13:30:42 -08002631 return 27;
Svetoslav3a5c7212014-10-14 09:54:26 -07002632 case TYPE_ACCESSIBILITY_OVERLAY:
2633 // overlay put by accessibility services to intercept user interaction
Filip Gruszczynskie95b0ae2015-09-30 10:55:33 -07002634 return 28;
Muyuan Li6ca619f2016-03-08 13:30:42 -08002635 case TYPE_SECURE_SYSTEM_OVERLAY:
Filip Gruszczynskie95b0ae2015-09-30 10:55:33 -07002636 return 29;
Muyuan Li6ca619f2016-03-08 13:30:42 -08002637 case TYPE_BOOT_PROGRESS:
2638 return 30;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07002639 case TYPE_POINTER:
2640 // the (mouse) pointer layer
Muyuan Li6ca619f2016-03-08 13:30:42 -08002641 return 31;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002642 }
2643 Log.e(TAG, "Unknown window type: " + type);
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07002644 return 2;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002645 }
2646
2647 /** {@inheritDoc} */
Craig Mautner46ac6fa2013-08-01 10:06:34 -07002648 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002649 public int subWindowTypeToLayerLw(int type) {
2650 switch (type) {
2651 case TYPE_APPLICATION_PANEL:
2652 case TYPE_APPLICATION_ATTACHED_DIALOG:
2653 return APPLICATION_PANEL_SUBLAYER;
2654 case TYPE_APPLICATION_MEDIA:
2655 return APPLICATION_MEDIA_SUBLAYER;
Dianne Hackborn5cb8d792009-05-21 17:34:15 -07002656 case TYPE_APPLICATION_MEDIA_OVERLAY:
2657 return APPLICATION_MEDIA_OVERLAY_SUBLAYER;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002658 case TYPE_APPLICATION_SUB_PANEL:
2659 return APPLICATION_SUB_PANEL_SUBLAYER;
Wale Ogunwale0a4dc222015-04-14 12:58:42 -07002660 case TYPE_APPLICATION_ABOVE_SUB_PANEL:
2661 return APPLICATION_ABOVE_SUB_PANEL_SUBLAYER;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002662 }
2663 Log.e(TAG, "Unknown sub-window type: " + type);
2664 return 0;
2665 }
2666
Craig Mautner46ac6fa2013-08-01 10:06:34 -07002667 @Override
Dianne Hackbornabe0da02009-09-18 01:55:39 -07002668 public int getMaxWallpaperLayer() {
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07002669 return windowTypeToLayerLw(TYPE_STATUS_BAR);
Dianne Hackbornabe0da02009-09-18 01:55:39 -07002670 }
2671
Sriram Viswanathan9ebbe6a2015-11-16 17:59:22 -08002672 private int getNavigationBarWidth(int rotation, int uiMode) {
Justin Paupore01915a12016-09-28 17:41:26 -07002673 if (ALTERNATE_CAR_MODE_NAV_SIZE && (uiMode & UI_MODE_TYPE_MASK) == UI_MODE_TYPE_CAR) {
Sriram Viswanathan9ebbe6a2015-11-16 17:59:22 -08002674 return mNavigationBarWidthForRotationInCarMode[rotation];
2675 } else {
2676 return mNavigationBarWidthForRotationDefault[rotation];
2677 }
2678 }
2679
Craig Mautner46ac6fa2013-08-01 10:06:34 -07002680 @Override
Andrii Kuliandb8e1062016-11-15 18:30:27 -08002681 public int getNonDecorDisplayWidth(int fullWidth, int fullHeight, int rotation, int uiMode,
2682 int displayId) {
2683 // TODO(multi-display): Support navigation bar on secondary displays.
2684 if (displayId == Display.DEFAULT_DISPLAY && mHasNavigationBar) {
Dianne Hackborn077ee852012-04-09 16:27:07 -07002685 // For a basic navigation bar, when we are in landscape mode we place
2686 // the navigation bar to the side.
Daniel Sandler4a066c52012-04-20 14:49:13 -04002687 if (mNavigationBarCanMove && fullWidth > fullHeight) {
Sriram Viswanathan9ebbe6a2015-11-16 17:59:22 -08002688 return fullWidth - getNavigationBarWidth(rotation, uiMode);
Dianne Hackborn077ee852012-04-09 16:27:07 -07002689 }
Dianne Hackborn1f903c32011-09-13 19:18:06 -07002690 }
2691 return fullWidth;
Dianne Hackborne2515ee2011-04-27 18:52:56 -04002692 }
2693
Sriram Viswanathan9ebbe6a2015-11-16 17:59:22 -08002694 private int getNavigationBarHeight(int rotation, int uiMode) {
Justin Paupore01915a12016-09-28 17:41:26 -07002695 if (ALTERNATE_CAR_MODE_NAV_SIZE && (uiMode & UI_MODE_TYPE_MASK) == UI_MODE_TYPE_CAR) {
Sriram Viswanathan9ebbe6a2015-11-16 17:59:22 -08002696 return mNavigationBarHeightForRotationInCarMode[rotation];
2697 } else {
2698 return mNavigationBarHeightForRotationDefault[rotation];
2699 }
2700 }
2701
Jose Lima9546b202014-07-02 17:21:51 -07002702 @Override
Andrii Kuliandb8e1062016-11-15 18:30:27 -08002703 public int getNonDecorDisplayHeight(int fullWidth, int fullHeight, int rotation, int uiMode,
2704 int displayId) {
2705 // TODO(multi-display): Support navigation bar on secondary displays.
2706 if (displayId == Display.DEFAULT_DISPLAY && mHasNavigationBar) {
Dianne Hackborn077ee852012-04-09 16:27:07 -07002707 // For a basic navigation bar, when we are in portrait mode we place
2708 // the navigation bar to the bottom.
Daniel Sandler4a066c52012-04-20 14:49:13 -04002709 if (!mNavigationBarCanMove || fullWidth < fullHeight) {
Sriram Viswanathan9ebbe6a2015-11-16 17:59:22 -08002710 return fullHeight - getNavigationBarHeight(rotation, uiMode);
Dianne Hackborn077ee852012-04-09 16:27:07 -07002711 }
2712 }
2713 return fullHeight;
Dianne Hackborn69cb8752011-05-19 18:13:32 -07002714 }
2715
Jose Lima9546b202014-07-02 17:21:51 -07002716 @Override
Andrii Kuliandb8e1062016-11-15 18:30:27 -08002717 public int getConfigDisplayWidth(int fullWidth, int fullHeight, int rotation, int uiMode,
2718 int displayId) {
2719 return getNonDecorDisplayWidth(fullWidth, fullHeight, rotation, uiMode, displayId);
Dianne Hackborn69cb8752011-05-19 18:13:32 -07002720 }
2721
Jose Lima9546b202014-07-02 17:21:51 -07002722 @Override
Andrii Kuliandb8e1062016-11-15 18:30:27 -08002723 public int getConfigDisplayHeight(int fullWidth, int fullHeight, int rotation, int uiMode,
2724 int displayId) {
John Spurlock80f00c12013-06-13 11:10:51 -04002725 // There is a separate status bar at the top of the display. We don't count that as part
2726 // of the fixed decor, since it can hide; however, for purposes of configurations,
Dianne Hackborn077ee852012-04-09 16:27:07 -07002727 // we do want to exclude it since applications can't generally use that part
2728 // of the screen.
Andrii Kuliandb8e1062016-11-15 18:30:27 -08002729 // TODO(multi-display): Support status bars on secondary displays.
2730 if (displayId == Display.DEFAULT_DISPLAY) {
2731 return getNonDecorDisplayHeight(fullWidth, fullHeight, rotation, uiMode, displayId)
2732 - mStatusBarHeight;
2733 }
2734 return fullHeight;
Dianne Hackborne2515ee2011-04-27 18:52:56 -04002735 }
2736
Craig Mautnera3f4bf52012-10-10 20:37:48 -07002737 @Override
Jorim Jaggi0d674622014-05-21 01:34:15 +02002738 public boolean isKeyguardHostWindow(WindowManager.LayoutParams attrs) {
2739 return attrs.type == TYPE_STATUS_BAR;
2740 }
2741
2742 @Override
Jorim Jaggife762342016-10-13 14:33:27 +02002743 public boolean canBeHiddenByKeyguardLw(WindowState win) {
2744 switch (win.getAttrs().type) {
Craig Mautnera3f4bf52012-10-10 20:37:48 -07002745 case TYPE_STATUS_BAR:
2746 case TYPE_NAVIGATION_BAR:
2747 case TYPE_WALLPAPER:
2748 case TYPE_DREAM:
Craig Mautnera3f4bf52012-10-10 20:37:48 -07002749 return false;
2750 default:
Adrian Roos461829d2015-06-03 14:41:18 -07002751 // Hide only windows below the keyguard host window.
2752 return windowTypeToLayerLw(win.getBaseType())
2753 < windowTypeToLayerLw(TYPE_STATUS_BAR);
Craig Mautnera3f4bf52012-10-10 20:37:48 -07002754 }
Dianne Hackborn01ad2f42009-09-24 19:24:56 -07002755 }
Craig Mautner8e4df6c2012-05-23 16:57:23 -07002756
Jorim Jaggife762342016-10-13 14:33:27 +02002757 private boolean shouldBeHiddenByKeyguard(WindowState win, WindowState imeTarget) {
2758
2759 // Keyguard visibility of window from activities are determined over activity visibility.
2760 if (win.getAppToken() != null) {
2761 return false;
2762 }
2763
2764 final LayoutParams attrs = win.getAttrs();
2765 final boolean showImeOverKeyguard = imeTarget != null && imeTarget.isVisibleLw() &&
2766 ((imeTarget.getAttrs().flags & FLAG_SHOW_WHEN_LOCKED) != 0
2767 || !canBeHiddenByKeyguardLw(imeTarget));
2768
2769 // Show IME over the keyguard if the target allows it
2770 boolean allowWhenLocked = (win.isInputMethodWindow() || imeTarget == this)
2771 && showImeOverKeyguard;;
2772
2773 if (isKeyguardLocked() && isKeyguardOccluded()) {
2774 // Show SHOW_WHEN_LOCKED windows if Keyguard is occluded.
2775 allowWhenLocked |= (attrs.flags & FLAG_SHOW_WHEN_LOCKED) != 0
2776 // Show error dialogs over apps that are shown on lockscreen
2777 || (attrs.privateFlags & PRIVATE_FLAG_SYSTEM_ERROR) != 0;
2778 }
2779
2780 boolean keyguardLocked = isKeyguardLocked();
2781 boolean hideDockDivider = attrs.type == TYPE_DOCK_DIVIDER
2782 && !mWindowManagerInternal.isStackVisible(DOCKED_STACK_ID);
2783 return (keyguardLocked && !allowWhenLocked && win.getDisplayId() == Display.DEFAULT_DISPLAY)
2784 || hideDockDivider;
Craig Mautner7d7808f2014-09-11 18:02:38 -07002785 }
2786
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002787 /** {@inheritDoc} */
Craig Mautner8e4df6c2012-05-23 16:57:23 -07002788 @Override
Dianne Hackborn2f0b1752011-05-31 17:59:49 -07002789 public View addStartingWindow(IBinder appToken, String packageName, int theme,
2790 CompatibilityInfo compatInfo, CharSequence nonLocalizedLabel, int labelRes,
Wale Ogunwaledfc18622016-04-16 15:08:48 -07002791 int icon, int logo, int windowFlags, Configuration overrideConfig) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002792 if (!SHOW_STARTING_ANIMATIONS) {
2793 return null;
2794 }
2795 if (packageName == null) {
2796 return null;
2797 }
Craig Mautner8e4df6c2012-05-23 16:57:23 -07002798
Mathias Jeppssond1443e92012-08-24 15:25:32 +02002799 WindowManager wm = null;
2800 View view = null;
2801
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002802 try {
Dianne Hackborn867ab6472010-04-29 13:28:56 -07002803 Context context = mContext;
Craig Mautner6fbda632012-07-03 09:26:39 -07002804 if (DEBUG_STARTING_WINDOW) Slog.d(TAG, "addStartingWindow " + packageName
2805 + ": nonLocalizedLabel=" + nonLocalizedLabel + " theme="
2806 + Integer.toHexString(theme));
Dianne Hackborn247fe742011-01-08 17:25:57 -08002807 if (theme != context.getThemeResId() || labelRes != 0) {
Dianne Hackborn867ab6472010-04-29 13:28:56 -07002808 try {
2809 context = context.createPackageContext(packageName, 0);
Dianne Hackborn247fe742011-01-08 17:25:57 -08002810 context.setTheme(theme);
Dianne Hackborn867ab6472010-04-29 13:28:56 -07002811 } catch (PackageManager.NameNotFoundException e) {
2812 // Ignore
2813 }
2814 }
Craig Mautner8e4df6c2012-05-23 16:57:23 -07002815
Andrii Kuliana8a9bc52016-10-14 11:00:13 -07002816 if (overrideConfig != null && !overrideConfig.equals(EMPTY)) {
Wale Ogunwaledfc18622016-04-16 15:08:48 -07002817 if (DEBUG_STARTING_WINDOW) Slog.d(TAG, "addStartingWindow: creating context based"
2818 + " on overrideConfig" + overrideConfig + " for starting window");
2819 final Context overrideContext = context.createConfigurationContext(overrideConfig);
2820 overrideContext.setTheme(theme);
2821 final TypedArray typedArray = overrideContext.obtainStyledAttributes(
2822 com.android.internal.R.styleable.Window);
2823 final int resId = typedArray.getResourceId(R.styleable.Window_windowBackground, 0);
2824 if (resId != 0 && overrideContext.getDrawable(resId) != null) {
2825 // We want to use the windowBackground for the override context if it is
2826 // available, otherwise we use the default one to make sure a themed starting
2827 // window is displayed for the app.
2828 if (DEBUG_STARTING_WINDOW) Slog.d(TAG, "addStartingWindow: apply overrideConfig"
2829 + overrideConfig + " to starting window resId=" + resId);
2830 context = overrideContext;
2831 }
2832 }
2833
2834 final PhoneWindow win = new PhoneWindow(context);
Jorim Jaggia16cc152015-06-01 16:55:05 -07002835 win.setIsStartingWindow(true);
Craig Mautner8e4df6c2012-05-23 16:57:23 -07002836
Phil Weaver155edc62016-06-09 10:24:53 -07002837 CharSequence label = context.getResources().getText(labelRes, null);
2838 // Only change the accessibility title if the label is localized
2839 if (label != null) {
2840 win.setTitle(label, true);
2841 } else {
2842 win.setTitle(nonLocalizedLabel, false);
2843 }
Craig Mautner8e4df6c2012-05-23 16:57:23 -07002844
Dianne Hackborn867ab6472010-04-29 13:28:56 -07002845 win.setType(
2846 WindowManager.LayoutParams.TYPE_APPLICATION_STARTING);
Adrian Roos602c68e2015-04-24 16:03:47 -07002847
2848 synchronized (mWindowManagerFuncs.getWindowManagerLock()) {
2849 // Assumes it's safe to show starting windows of launched apps while
2850 // the keyguard is being hidden. This is okay because starting windows never show
2851 // secret information.
Jorim Jaggife762342016-10-13 14:33:27 +02002852 if (mKeyguardOccluded) {
Adrian Roos602c68e2015-04-24 16:03:47 -07002853 windowFlags |= FLAG_SHOW_WHEN_LOCKED;
2854 }
2855 }
2856
Dianne Hackborn867ab6472010-04-29 13:28:56 -07002857 // Force the window flags: this is a fake window, so it is not really
2858 // touchable or focusable by the user. We also add in the ALT_FOCUSABLE_IM
2859 // flag because we do know that the next window will take input
2860 // focus, so we want to get the IME window up on top of us right away.
2861 win.setFlags(
Dianne Hackborn7eec10e2010-11-12 18:03:47 -08002862 windowFlags|
Dianne Hackborn867ab6472010-04-29 13:28:56 -07002863 WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE|
2864 WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE|
2865 WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM,
Dianne Hackborn7eec10e2010-11-12 18:03:47 -08002866 windowFlags|
Dianne Hackborn867ab6472010-04-29 13:28:56 -07002867 WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE|
2868 WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE|
2869 WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM);
Craig Mautner8e4df6c2012-05-23 16:57:23 -07002870
Adam Powell04fe6eb2013-05-31 14:39:48 -07002871 win.setDefaultIcon(icon);
2872 win.setDefaultLogo(logo);
2873
Dianne Hackborn867ab6472010-04-29 13:28:56 -07002874 win.setLayout(WindowManager.LayoutParams.MATCH_PARENT,
Dianne Hackborn2f0b1752011-05-31 17:59:49 -07002875 WindowManager.LayoutParams.MATCH_PARENT);
Craig Mautner8e4df6c2012-05-23 16:57:23 -07002876
Phil Weaver266ed9a2016-06-08 00:34:40 +00002877 final WindowManager.LayoutParams params = win.getAttributes();
Dianne Hackborn867ab6472010-04-29 13:28:56 -07002878 params.token = appToken;
2879 params.packageName = packageName;
2880 params.windowAnimations = win.getWindowStyle().getResourceId(
2881 com.android.internal.R.styleable.Window_windowAnimationStyle, 0);
John Reck61375a82014-09-18 19:27:48 +00002882 params.privateFlags |=
2883 WindowManager.LayoutParams.PRIVATE_FLAG_FAKE_HARDWARE_ACCELERATED;
Craig Mautner88400d32012-09-30 12:35:45 -07002884 params.privateFlags |= WindowManager.LayoutParams.PRIVATE_FLAG_SHOW_FOR_ALL_USERS;
Adam Lesinski95c42972013-10-02 10:13:27 -07002885
2886 if (!compatInfo.supportsScreen()) {
2887 params.privateFlags |= WindowManager.LayoutParams.PRIVATE_FLAG_COMPATIBLE_WINDOW;
2888 }
2889
Dianne Hackborn867ab6472010-04-29 13:28:56 -07002890 params.setTitle("Starting " + packageName);
2891
Mathias Jeppssond1443e92012-08-24 15:25:32 +02002892 wm = (WindowManager)context.getSystemService(Context.WINDOW_SERVICE);
2893 view = win.getDecorView();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002894
Wale Ogunwaledfc18622016-04-16 15:08:48 -07002895 if (DEBUG_STARTING_WINDOW) Slog.d(TAG, "Adding starting window for "
2896 + packageName + " / " + appToken + ": " + (view.getParent() != null ? view : null));
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002897
2898 wm.addView(view, params);
2899
2900 // Only return the view if it was successfully added to the
2901 // window manager... which we can tell by it having a parent.
2902 return view.getParent() != null ? view : null;
Jeff Brown98365d72012-08-19 20:30:52 -07002903 } catch (WindowManager.BadTokenException e) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002904 // ignore
Craig Mautner42bf39e2014-02-21 16:46:22 -08002905 Log.w(TAG, appToken + " already running, starting window not displayed. " +
2906 e.getMessage());
Dianne Hackborn867ab6472010-04-29 13:28:56 -07002907 } catch (RuntimeException e) {
2908 // don't crash if something else bad happens, for example a
2909 // failure loading resources because we are loading from an app
2910 // on external storage that has been unmounted.
2911 Log.w(TAG, appToken + " failed creating starting window", e);
Mathias Jeppssond1443e92012-08-24 15:25:32 +02002912 } finally {
2913 if (view != null && view.getParent() == null) {
2914 Log.w(TAG, "view not successfully added to wm, removing view");
2915 wm.removeViewImmediate(view);
2916 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002917 }
2918
2919 return null;
2920 }
2921
2922 /** {@inheritDoc} */
Jose Lima9546b202014-07-02 17:21:51 -07002923 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002924 public void removeStartingWindow(IBinder appToken, View window) {
Craig Mautner276a6eb2014-11-04 15:32:57 -08002925 if (DEBUG_STARTING_WINDOW) Slog.v(TAG, "Removing starting window for " + appToken + ": "
2926 + window + " Callers=" + Debug.getCallers(4));
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002927
2928 if (window != null) {
Dianne Hackborn5fd21692011-06-07 14:09:47 -07002929 WindowManager wm = (WindowManager)mContext.getSystemService(Context.WINDOW_SERVICE);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002930 wm.removeView(window);
2931 }
2932 }
2933
2934 /**
2935 * Preflight adding a window to the system.
RoboErik8a2cfc32014-05-16 11:19:38 -07002936 *
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002937 * Currently enforces that three window types are singletons:
2938 * <ul>
2939 * <li>STATUS_BAR_TYPE</li>
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002940 * <li>KEYGUARD_TYPE</li>
2941 * </ul>
RoboErik8a2cfc32014-05-16 11:19:38 -07002942 *
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002943 * @param win The window to be added
2944 * @param attrs Information about the window to be added
RoboErik8a2cfc32014-05-16 11:19:38 -07002945 *
Jeff Brown98365d72012-08-19 20:30:52 -07002946 * @return If ok, WindowManagerImpl.ADD_OKAY. If too many singletons,
2947 * WindowManagerImpl.ADD_MULTIPLE_SINGLETON
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002948 */
Jose Lima9546b202014-07-02 17:21:51 -07002949 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002950 public int prepareAddWindowLw(WindowState win, WindowManager.LayoutParams attrs) {
2951 switch (attrs.type) {
2952 case TYPE_STATUS_BAR:
Joe Onorato8bc6c512010-06-04 16:21:12 -04002953 mContext.enforceCallingOrSelfPermission(
2954 android.Manifest.permission.STATUS_BAR_SERVICE,
2955 "PhoneWindowManager");
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002956 if (mStatusBar != null) {
Dianne Hackbornf87d1962012-04-04 12:48:24 -07002957 if (mStatusBar.isAlive()) {
Jeff Brown98365d72012-08-19 20:30:52 -07002958 return WindowManagerGlobal.ADD_MULTIPLE_SINGLETON;
Dianne Hackbornf87d1962012-04-04 12:48:24 -07002959 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002960 }
2961 mStatusBar = win;
John Spurlock27735a42013-08-14 17:57:38 -04002962 mStatusBarController.setWindow(win);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002963 break;
Daniel Sandler8956dbb2011-04-22 07:55:02 -04002964 case TYPE_NAVIGATION_BAR:
2965 mContext.enforceCallingOrSelfPermission(
2966 android.Manifest.permission.STATUS_BAR_SERVICE,
2967 "PhoneWindowManager");
Dianne Hackbornf87d1962012-04-04 12:48:24 -07002968 if (mNavigationBar != null) {
2969 if (mNavigationBar.isAlive()) {
Jeff Brown98365d72012-08-19 20:30:52 -07002970 return WindowManagerGlobal.ADD_MULTIPLE_SINGLETON;
Dianne Hackbornf87d1962012-04-04 12:48:24 -07002971 }
2972 }
Daniel Sandler8956dbb2011-04-22 07:55:02 -04002973 mNavigationBar = win;
John Spurlock27735a42013-08-14 17:57:38 -04002974 mNavigationBarController.setWindow(win);
Craig Mautnereda67292013-04-28 13:50:14 -07002975 if (DEBUG_LAYOUT) Slog.i(TAG, "NAVIGATION BAR: " + mNavigationBar);
Daniel Sandler8956dbb2011-04-22 07:55:02 -04002976 break;
Jim Millere898ac52012-04-06 17:10:57 -07002977 case TYPE_NAVIGATION_BAR_PANEL:
Dianne Hackborn08743722009-12-21 12:16:51 -08002978 case TYPE_STATUS_BAR_PANEL:
Joe Onorato29fc2c92010-11-24 10:26:50 -08002979 case TYPE_STATUS_BAR_SUB_PANEL:
Jorim Jaggi225d3b52015-04-01 11:18:57 -07002980 case TYPE_VOICE_INTERACTION_STARTING:
Joe Onorato29fc2c92010-11-24 10:26:50 -08002981 mContext.enforceCallingOrSelfPermission(
2982 android.Manifest.permission.STATUS_BAR_SERVICE,
2983 "PhoneWindowManager");
Joe Onorato29fc2c92010-11-24 10:26:50 -08002984 break;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002985 }
Jeff Brown98365d72012-08-19 20:30:52 -07002986 return WindowManagerGlobal.ADD_OKAY;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002987 }
2988
2989 /** {@inheritDoc} */
Jose Lima9546b202014-07-02 17:21:51 -07002990 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002991 public void removeWindowLw(WindowState win) {
2992 if (mStatusBar == win) {
2993 mStatusBar = null;
John Spurlock27735a42013-08-14 17:57:38 -04002994 mStatusBarController.setWindow(null);
Jorim Jaggi73294b62016-10-26 18:02:36 -07002995 } else if (mNavigationBar == win) {
Daniel Sandler8956dbb2011-04-22 07:55:02 -04002996 mNavigationBar = null;
John Spurlock27735a42013-08-14 17:57:38 -04002997 mNavigationBarController.setWindow(null);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002998 }
2999 }
3000
3001 static final boolean PRINT_ANIM = false;
RoboErik8a2cfc32014-05-16 11:19:38 -07003002
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003003 /** {@inheritDoc} */
Craig Mautner4b71aa12012-12-27 17:20:01 -08003004 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003005 public int selectAnimationLw(WindowState win, int transit) {
3006 if (PRINT_ANIM) Log.i(TAG, "selectAnimation in " + win
3007 + ": transit=" + transit);
Dianne Hackbornf87d1962012-04-04 12:48:24 -07003008 if (win == mStatusBar) {
Jorim Jaggi380ecb82014-03-14 17:25:20 +01003009 boolean isKeyguard = (win.getAttrs().privateFlags & PRIVATE_FLAG_KEYGUARD) != 0;
Craig Mautner4b71aa12012-12-27 17:20:01 -08003010 if (transit == TRANSIT_EXIT
3011 || transit == TRANSIT_HIDE) {
Jorim Jaggi380ecb82014-03-14 17:25:20 +01003012 return isKeyguard ? -1 : R.anim.dock_top_exit;
Craig Mautner4b71aa12012-12-27 17:20:01 -08003013 } else if (transit == TRANSIT_ENTER
3014 || transit == TRANSIT_SHOW) {
Jorim Jaggi380ecb82014-03-14 17:25:20 +01003015 return isKeyguard ? -1 : R.anim.dock_top_enter;
Dianne Hackbornf87d1962012-04-04 12:48:24 -07003016 }
3017 } else if (win == mNavigationBar) {
Jorim Jaggi0d210f62015-07-10 14:24:44 -07003018 if (win.getAttrs().windowAnimations != 0) {
3019 return 0;
3020 }
Adrian Roos85d202b2016-06-02 16:27:47 -07003021 // This can be on either the bottom or the right or the left.
3022 if (mNavigationBarPosition == NAV_BAR_BOTTOM) {
Craig Mautner4b71aa12012-12-27 17:20:01 -08003023 if (transit == TRANSIT_EXIT
3024 || transit == TRANSIT_HIDE) {
Jorim Jaggi48832812016-09-06 12:38:23 -07003025 if (isKeyguardShowingAndNotOccluded()) {
3026 return R.anim.dock_bottom_exit_keyguard;
3027 } else {
3028 return R.anim.dock_bottom_exit;
3029 }
Craig Mautner4b71aa12012-12-27 17:20:01 -08003030 } else if (transit == TRANSIT_ENTER
3031 || transit == TRANSIT_SHOW) {
Dianne Hackbornf87d1962012-04-04 12:48:24 -07003032 return R.anim.dock_bottom_enter;
3033 }
Adrian Roos85d202b2016-06-02 16:27:47 -07003034 } else if (mNavigationBarPosition == NAV_BAR_RIGHT) {
Craig Mautner4b71aa12012-12-27 17:20:01 -08003035 if (transit == TRANSIT_EXIT
3036 || transit == TRANSIT_HIDE) {
Dianne Hackbornf87d1962012-04-04 12:48:24 -07003037 return R.anim.dock_right_exit;
Craig Mautner4b71aa12012-12-27 17:20:01 -08003038 } else if (transit == TRANSIT_ENTER
3039 || transit == TRANSIT_SHOW) {
Dianne Hackbornf87d1962012-04-04 12:48:24 -07003040 return R.anim.dock_right_enter;
3041 }
Adrian Roos85d202b2016-06-02 16:27:47 -07003042 } else if (mNavigationBarPosition == NAV_BAR_LEFT) {
3043 if (transit == TRANSIT_EXIT
3044 || transit == TRANSIT_HIDE) {
3045 return R.anim.dock_left_exit;
3046 } else if (transit == TRANSIT_ENTER
3047 || transit == TRANSIT_SHOW) {
3048 return R.anim.dock_left_enter;
3049 }
Dianne Hackbornf87d1962012-04-04 12:48:24 -07003050 }
Filip Gruszczynski57f76f12015-11-04 16:10:54 -08003051 } else if (win.getAttrs().type == TYPE_DOCK_DIVIDER) {
Jorim Jaggi81ba11e2016-02-03 22:04:22 -08003052 return selectDockedDividerAnimationLw(win, transit);
Craig Mautner4b71aa12012-12-27 17:20:01 -08003053 }
3054
3055 if (transit == TRANSIT_PREVIEW_DONE) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003056 if (win.hasAppShownWindows()) {
3057 if (PRINT_ANIM) Log.i(TAG, "**** STARTING EXIT");
3058 return com.android.internal.R.anim.app_starting_exit;
3059 }
Dianne Hackborn7ad44382012-10-18 17:46:00 -07003060 } else if (win.getAttrs().type == TYPE_DREAM && mDreamingLockscreen
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07003061 && transit == TRANSIT_ENTER) {
3062 // Special case: we are animating in a dream, while the keyguard
3063 // is shown. We don't want an animation on the dream, because
3064 // we need it shown immediately with the keyguard animating away
3065 // to reveal it.
3066 return -1;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003067 }
3068
3069 return 0;
3070 }
3071
Jorim Jaggi81ba11e2016-02-03 22:04:22 -08003072 private int selectDockedDividerAnimationLw(WindowState win, int transit) {
3073 int insets = mWindowManagerFuncs.getDockedDividerInsetsLw();
3074
3075 // If the divider is behind the navigation bar, don't animate.
Jorim Jaggi0cb0f722016-03-25 20:49:41 -07003076 final Rect frame = win.getFrameLw();
3077 final boolean behindNavBar = mNavigationBar != null
Adrian Roos85d202b2016-06-02 16:27:47 -07003078 && ((mNavigationBarPosition == NAV_BAR_BOTTOM
Jorim Jaggi0cb0f722016-03-25 20:49:41 -07003079 && frame.top + insets >= mNavigationBar.getFrameLw().top)
Adrian Roos85d202b2016-06-02 16:27:47 -07003080 || (mNavigationBarPosition == NAV_BAR_RIGHT
3081 && frame.left + insets >= mNavigationBar.getFrameLw().left)
3082 || (mNavigationBarPosition == NAV_BAR_LEFT
3083 && frame.right - insets <= mNavigationBar.getFrameLw().right));
Jorim Jaggi0cb0f722016-03-25 20:49:41 -07003084 final boolean landscape = frame.height() > frame.width();
3085 final boolean offscreenLandscape = landscape && (frame.right - insets <= 0
3086 || frame.left + insets >= win.getDisplayFrameLw().right);
3087 final boolean offscreenPortrait = !landscape && (frame.top - insets <= 0
3088 || frame.bottom + insets >= win.getDisplayFrameLw().bottom);
3089 final boolean offscreen = offscreenLandscape || offscreenPortrait;
3090 if (behindNavBar || offscreen) {
Jorim Jaggi81ba11e2016-02-03 22:04:22 -08003091 return 0;
3092 }
3093 if (transit == TRANSIT_ENTER || transit == TRANSIT_SHOW) {
3094 return R.anim.fade_in;
3095 } else if (transit == TRANSIT_EXIT) {
3096 return R.anim.fade_out;
3097 } else {
3098 return 0;
3099 }
3100 }
3101
Craig Mautner3c174372013-02-21 17:54:37 -08003102 @Override
3103 public void selectRotationAnimationLw(int anim[]) {
3104 if (PRINT_ANIM) Slog.i(TAG, "selectRotationAnimation mTopFullscreen="
3105 + mTopFullscreenOpaqueWindowState + " rotationAnimation="
3106 + (mTopFullscreenOpaqueWindowState == null ?
3107 "0" : mTopFullscreenOpaqueWindowState.getAttrs().rotationAnimation));
Robert Carrfd10cd12016-06-29 16:41:50 -07003108 if (mTopFullscreenOpaqueWindowState != null) {
3109 int animationHint = mTopFullscreenOpaqueWindowState.getRotationAnimationHint();
3110 if (animationHint < 0 && mTopIsFullscreen) {
3111 animationHint = mTopFullscreenOpaqueWindowState.getAttrs().rotationAnimation;
3112 }
3113 switch (animationHint) {
Craig Mautner3c174372013-02-21 17:54:37 -08003114 case ROTATION_ANIMATION_CROSSFADE:
Robert Carr57d9fbd2016-08-15 12:00:35 -07003115 case ROTATION_ANIMATION_SEAMLESS: // Crossfade is fallback for seamless.
Craig Mautner3c174372013-02-21 17:54:37 -08003116 anim[0] = R.anim.rotation_animation_xfade_exit;
3117 anim[1] = R.anim.rotation_animation_enter;
3118 break;
3119 case ROTATION_ANIMATION_JUMPCUT:
3120 anim[0] = R.anim.rotation_animation_jump_exit;
3121 anim[1] = R.anim.rotation_animation_enter;
3122 break;
3123 case ROTATION_ANIMATION_ROTATE:
3124 default:
3125 anim[0] = anim[1] = 0;
3126 break;
3127 }
3128 } else {
3129 anim[0] = anim[1] = 0;
3130 }
3131 }
3132
3133 @Override
3134 public boolean validateRotationAnimationLw(int exitAnimId, int enterAnimId,
3135 boolean forceDefault) {
3136 switch (exitAnimId) {
3137 case R.anim.rotation_animation_xfade_exit:
3138 case R.anim.rotation_animation_jump_exit:
3139 // These are the only cases that matter.
3140 if (forceDefault) {
3141 return false;
3142 }
3143 int anim[] = new int[2];
3144 selectRotationAnimationLw(anim);
3145 return (exitAnimId == anim[0] && enterAnimId == anim[1]);
3146 default:
3147 return true;
3148 }
3149 }
3150
3151 @Override
Jorim Jaggife762342016-10-13 14:33:27 +02003152 public Animation createHiddenByKeyguardExit(boolean onWallpaper,
Jorim Jaggi84a3e7a2014-08-13 17:58:58 +02003153 boolean goingToNotificationShade) {
3154 if (goingToNotificationShade) {
3155 return AnimationUtils.loadAnimation(mContext, R.anim.lock_screen_behind_enter_fade_in);
Craig Mautnerb8340802014-11-04 15:32:57 -08003156 }
Craig Mautner276a6eb2014-11-04 15:32:57 -08003157
3158 AnimationSet set = (AnimationSet) AnimationUtils.loadAnimation(mContext, onWallpaper ?
3159 R.anim.lock_screen_behind_enter_wallpaper :
3160 R.anim.lock_screen_behind_enter);
3161
3162 // TODO: Use XML interpolators when we have log interpolators available in XML.
3163 final List<Animation> animations = set.getAnimations();
3164 for (int i = animations.size() - 1; i >= 0; --i) {
3165 animations.get(i).setInterpolator(mLogDecelerateInterpolator);
3166 }
3167
3168 return set;
Jorim Jaggi76a16232014-08-08 17:00:47 +02003169 }
3170
3171
3172 @Override
Jorim Jaggife762342016-10-13 14:33:27 +02003173 public Animation createKeyguardWallpaperExit(boolean goingToNotificationShade) {
Jorim Jaggi84a3e7a2014-08-13 17:58:58 +02003174 if (goingToNotificationShade) {
3175 return null;
3176 } else {
3177 return AnimationUtils.loadAnimation(mContext, R.anim.lock_screen_wallpaper_exit);
3178 }
Dianne Hackborn01ad2f42009-09-24 19:24:56 -07003179 }
John Spurlockc8b46ca2013-04-08 12:59:26 -04003180
3181 private static void awakenDreams() {
3182 IDreamManager dreamManager = getDreamManager();
3183 if (dreamManager != null) {
3184 try {
3185 dreamManager.awaken();
3186 } catch (RemoteException e) {
3187 // fine, stay asleep then
3188 }
3189 }
3190 }
3191
3192 static IDreamManager getDreamManager() {
3193 return IDreamManager.Stub.asInterface(
3194 ServiceManager.checkService(DreamService.DREAM_SERVICE));
3195 }
3196
Tyler Gunnef9f6f92014-09-12 22:16:17 -07003197 TelecomManager getTelecommService() {
3198 return (TelecomManager) mContext.getSystemService(Context.TELECOM_SERVICE);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003199 }
3200
Jeff Brown4d396052010-10-29 21:50:21 -07003201 static IAudioService getAudioService() {
3202 IAudioService audioService = IAudioService.Stub.asInterface(
3203 ServiceManager.checkService(Context.AUDIO_SERVICE));
3204 if (audioService == null) {
3205 Log.w(TAG, "Unable to find IAudioService interface.");
3206 }
3207 return audioService;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003208 }
3209
3210 boolean keyguardOn() {
Jim Millerab954542014-10-10 18:21:49 -07003211 return isKeyguardShowingAndNotOccluded() || inKeyguardRestrictedKeyInputMode();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003212 }
3213
3214 private static final int[] WINDOW_TYPES_WHERE_HOME_DOESNT_WORK = {
3215 WindowManager.LayoutParams.TYPE_SYSTEM_ALERT,
3216 WindowManager.LayoutParams.TYPE_SYSTEM_ERROR,
3217 };
3218
3219 /** {@inheritDoc} */
Jeff Brown00fa7bd2010-07-02 15:37:36 -07003220 @Override
Jeff Brownd5bb82d2011-10-12 13:57:59 -07003221 public long interceptKeyBeforeDispatching(WindowState win, KeyEvent event, int policyFlags) {
Jeff Brown00fa7bd2010-07-02 15:37:36 -07003222 final boolean keyguardOn = keyguardOn();
Jeff Brown1f245102010-11-18 20:53:46 -08003223 final int keyCode = event.getKeyCode();
3224 final int repeatCount = event.getRepeatCount();
3225 final int metaState = event.getMetaState();
Jeff Brownd5bb82d2011-10-12 13:57:59 -07003226 final int flags = event.getFlags();
Jeff Brown1f245102010-11-18 20:53:46 -08003227 final boolean down = event.getAction() == KeyEvent.ACTION_DOWN;
3228 final boolean canceled = event.isCanceled();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003229
Jeff Brown40013652012-05-16 21:22:36 -07003230 if (DEBUG_INPUT) {
Jeff Brown00fa7bd2010-07-02 15:37:36 -07003231 Log.d(TAG, "interceptKeyTi keyCode=" + keyCode + " down=" + down + " repeatCount="
Jeff Brownfd23e3e2012-05-09 13:34:28 -07003232 + repeatCount + " keyguardOn=" + keyguardOn + " mHomePressed=" + mHomePressed
3233 + " canceled=" + canceled);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003234 }
3235
Jeff Brownd5bb82d2011-10-12 13:57:59 -07003236 // If we think we might have a volume down & power key chord on the way
3237 // but we're not sure, then tell the dispatcher to wait a little while and
3238 // try again later before dispatching.
Christopher Tatee90585f2012-03-05 18:56:25 -08003239 if (mScreenshotChordEnabled && (flags & KeyEvent.FLAG_FALLBACK) == 0) {
Jeff Brown13f00f02014-10-31 14:45:50 -07003240 if (mScreenshotChordVolumeDownKeyTriggered && !mScreenshotChordPowerKeyTriggered) {
Jeff Brownd5bb82d2011-10-12 13:57:59 -07003241 final long now = SystemClock.uptimeMillis();
Jeff Brown13f00f02014-10-31 14:45:50 -07003242 final long timeoutTime = mScreenshotChordVolumeDownKeyTime
3243 + SCREENSHOT_CHORD_DEBOUNCE_DELAY_MILLIS;
Jeff Brownd5bb82d2011-10-12 13:57:59 -07003244 if (now < timeoutTime) {
3245 return timeoutTime - now;
3246 }
3247 }
3248 if (keyCode == KeyEvent.KEYCODE_VOLUME_DOWN
Jeff Brown13f00f02014-10-31 14:45:50 -07003249 && mScreenshotChordVolumeDownKeyConsumed) {
Jeff Brownd5bb82d2011-10-12 13:57:59 -07003250 if (!down) {
Jeff Brown13f00f02014-10-31 14:45:50 -07003251 mScreenshotChordVolumeDownKeyConsumed = false;
Jeff Brownd5bb82d2011-10-12 13:57:59 -07003252 }
3253 return -1;
3254 }
3255 }
3256
Michael Wright6a62e552014-06-03 19:19:48 -07003257 // Cancel any pending meta actions if we see any other keys being pressed between the down
3258 // of the meta key and its corresponding up.
Michael Wright251e35d2014-08-22 15:40:27 -07003259 if (mPendingMetaAction && !KeyEvent.isMetaKey(keyCode)) {
Michael Wright6a62e552014-06-03 19:19:48 -07003260 mPendingMetaAction = false;
3261 }
Andrii Kulian112d0562016-03-08 10:44:22 -08003262 // Any key that is not Alt or Meta cancels Caps Lock combo tracking.
3263 if (mPendingCapsLockToggle && !KeyEvent.isMetaKey(keyCode) && !KeyEvent.isAltKey(keyCode)) {
3264 mPendingCapsLockToggle = false;
3265 }
Michael Wright6a62e552014-06-03 19:19:48 -07003266
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003267 // First we always handle the home key here, so applications
3268 // can never break it, although if keyguard is on, we do let
3269 // it handle it, because that gives us the correct 5 second
3270 // timeout.
Jeff Brown00fa7bd2010-07-02 15:37:36 -07003271 if (keyCode == KeyEvent.KEYCODE_HOME) {
Michael Jurka7f2668c2012-03-27 07:49:52 -07003272
Jeff Brown49ed71d2010-12-06 17:13:33 -08003273 // If we have released the home key, and didn't do anything else
3274 // while it was pressed, then it is time to go home!
Michael Jurka7f2668c2012-03-27 07:49:52 -07003275 if (!down) {
Jeff Browncaca8812013-05-09 13:34:33 -07003276 cancelPreloadRecentApps();
3277
Jeff Brown49ed71d2010-12-06 17:13:33 -08003278 mHomePressed = false;
Jeff Browncaca8812013-05-09 13:34:33 -07003279 if (mHomeConsumed) {
3280 mHomeConsumed = false;
Michael Jurka7f2668c2012-03-27 07:49:52 -07003281 return -1;
Jeff Brown49ed71d2010-12-06 17:13:33 -08003282 }
Jeff Browncaca8812013-05-09 13:34:33 -07003283
3284 if (canceled) {
3285 Log.i(TAG, "Ignoring HOME; event canceled.");
3286 return -1;
3287 }
3288
Jeff Browncaca8812013-05-09 13:34:33 -07003289 // Delay handling home if a double-tap is possible.
3290 if (mDoubleTapOnHomeBehavior != DOUBLE_TAP_HOME_NOTHING) {
3291 mHandler.removeCallbacks(mHomeDoubleTapTimeoutRunnable); // just in case
3292 mHomeDoubleTapPending = true;
3293 mHandler.postDelayed(mHomeDoubleTapTimeoutRunnable,
3294 ViewConfiguration.getDoubleTapTimeout());
3295 return -1;
3296 }
3297
Jeff Brown13f00f02014-10-31 14:45:50 -07003298 handleShortPressOnHome();
Jeff Browncaca8812013-05-09 13:34:33 -07003299 return -1;
Jeff Brown49ed71d2010-12-06 17:13:33 -08003300 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003301
3302 // If a system window has focus, then it doesn't make sense
3303 // right now to interact with applications.
3304 WindowManager.LayoutParams attrs = win != null ? win.getAttrs() : null;
3305 if (attrs != null) {
3306 final int type = attrs.type;
Jorim Jaggi73294b62016-10-26 18:02:36 -07003307 if (type == TYPE_KEYGUARD_DIALOG
Jorim Jaggi380ecb82014-03-14 17:25:20 +01003308 || (attrs.privateFlags & PRIVATE_FLAG_KEYGUARD) != 0) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003309 // the "app" is keyguard, so give it the key
Jeff Brownd5bb82d2011-10-12 13:57:59 -07003310 return 0;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003311 }
3312 final int typeCount = WINDOW_TYPES_WHERE_HOME_DOESNT_WORK.length;
3313 for (int i=0; i<typeCount; i++) {
3314 if (type == WINDOW_TYPES_WHERE_HOME_DOESNT_WORK[i]) {
3315 // don't do anything, but also don't pass it to the app
Jeff Brownd5bb82d2011-10-12 13:57:59 -07003316 return -1;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003317 }
3318 }
3319 }
Jeff Browncaca8812013-05-09 13:34:33 -07003320
3321 // Remember that home is pressed and handle special actions.
3322 if (repeatCount == 0) {
3323 mHomePressed = true;
3324 if (mHomeDoubleTapPending) {
3325 mHomeDoubleTapPending = false;
3326 mHandler.removeCallbacks(mHomeDoubleTapTimeoutRunnable);
3327 handleDoubleTapOnHome();
3328 } else if (mLongPressOnHomeBehavior == LONG_PRESS_HOME_RECENT_SYSTEM_UI
3329 || mDoubleTapOnHomeBehavior == DOUBLE_TAP_HOME_RECENT_SYSTEM_UI) {
3330 preloadRecentApps();
Michael Jurka7f2668c2012-03-27 07:49:52 -07003331 }
Jeff Browncaca8812013-05-09 13:34:33 -07003332 } else if ((event.getFlags() & KeyEvent.FLAG_LONG_PRESS) != 0) {
3333 if (!keyguardOn) {
Jaewan Kim76b7d0d2016-02-12 19:01:02 +09003334 handleLongPressOnHome(event.getDeviceId());
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003335 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003336 }
Jeff Brownd5bb82d2011-10-12 13:57:59 -07003337 return -1;
Jeff Brown00fa7bd2010-07-02 15:37:36 -07003338 } else if (keyCode == KeyEvent.KEYCODE_MENU) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003339 // Hijack modified menu keys for debugging features
3340 final int chordBug = KeyEvent.META_SHIFT_ON;
3341
3342 if (down && repeatCount == 0) {
Jeff Brown00fa7bd2010-07-02 15:37:36 -07003343 if (mEnableShiftMenuBugReports && (metaState & chordBug) == chordBug) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003344 Intent intent = new Intent(Intent.ACTION_BUG_REPORT);
Dianne Hackborn5ac72a22012-08-29 18:32:08 -07003345 mContext.sendOrderedBroadcastAsUser(intent, UserHandle.CURRENT,
3346 null, null, null, 0, null, null);
Jeff Brownd5bb82d2011-10-12 13:57:59 -07003347 return -1;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003348 }
3349 }
Jeff Brown00fa7bd2010-07-02 15:37:36 -07003350 } else if (keyCode == KeyEvent.KEYCODE_SEARCH) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003351 if (down) {
3352 if (repeatCount == 0) {
Jeff Brownfd23e3e2012-05-09 13:34:28 -07003353 mSearchKeyShortcutPending = true;
3354 mConsumeSearchKeyUp = false;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003355 }
Jeff Brownfd23e3e2012-05-09 13:34:28 -07003356 } else {
3357 mSearchKeyShortcutPending = false;
3358 if (mConsumeSearchKeyUp) {
3359 mConsumeSearchKeyUp = false;
Jeff Brownd5bb82d2011-10-12 13:57:59 -07003360 return -1;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003361 }
3362 }
Jeff Brownd5bb82d2011-10-12 13:57:59 -07003363 return 0;
Jeff Brown49ed71d2010-12-06 17:13:33 -08003364 } else if (keyCode == KeyEvent.KEYCODE_APP_SWITCH) {
Michael Wrightc9ebea72013-01-16 19:25:02 -08003365 if (!keyguardOn) {
Jeff Browncaca8812013-05-09 13:34:33 -07003366 if (down && repeatCount == 0) {
3367 preloadRecentApps();
3368 } else if (!down) {
3369 toggleRecentApps();
Michael Wrightc9ebea72013-01-16 19:25:02 -08003370 }
Jeff Brown49ed71d2010-12-06 17:13:33 -08003371 }
Jeff Brownd5bb82d2011-10-12 13:57:59 -07003372 return -1;
Jun Mukaid21b3c82015-04-23 14:09:34 -07003373 } else if (keyCode == KeyEvent.KEYCODE_N && event.isMetaPressed()) {
3374 if (down) {
3375 IStatusBarService service = getStatusBarService();
3376 if (service != null) {
3377 try {
3378 service.expandNotificationsPanel();
3379 } catch (RemoteException e) {
3380 // do nothing.
3381 }
3382 }
3383 }
Muyuan Li6ca619f2016-03-08 13:30:42 -08003384 } else if (keyCode == KeyEvent.KEYCODE_S && event.isMetaPressed()
3385 && event.isCtrlPressed()) {
3386 if (down && repeatCount == 0) {
3387 int type = event.isShiftPressed() ? TAKE_SCREENSHOT_SELECTED_REGION
3388 : TAKE_SCREENSHOT_FULLSCREEN;
3389 mScreenshotRunnable.setScreenshotType(type);
3390 mHandler.post(mScreenshotRunnable);
3391 return -1;
3392 }
Clara Bayarrif2debb12015-07-10 14:47:17 +01003393 } else if (keyCode == KeyEvent.KEYCODE_SLASH && event.isMetaPressed()) {
Andrei Stingaceanu002f7122016-03-30 12:22:05 +01003394 if (down && repeatCount == 0 && !isKeyguardLocked()) {
3395 toggleKeyboardShortcutsMenu(event.getDeviceId());
Clara Bayarrif2debb12015-07-10 14:47:17 +01003396 }
Jeff Brownde7a8ea2012-06-13 18:28:57 -07003397 } else if (keyCode == KeyEvent.KEYCODE_ASSIST) {
3398 if (down) {
3399 if (repeatCount == 0) {
3400 mAssistKeyLongPressed = false;
3401 } else if (repeatCount == 1) {
3402 mAssistKeyLongPressed = true;
3403 if (!keyguardOn) {
3404 launchAssistLongPressAction();
3405 }
3406 }
3407 } else {
3408 if (mAssistKeyLongPressed) {
3409 mAssistKeyLongPressed = false;
3410 } else {
3411 if (!keyguardOn) {
Tim Kilbourn0e5f1102015-06-05 16:18:09 -07003412 launchAssistAction(null, event.getDeviceId());
Jeff Brownde7a8ea2012-06-13 18:28:57 -07003413 }
3414 }
3415 }
3416 return -1;
Michael Wrightdc63f7b2014-08-21 19:05:21 -07003417 } else if (keyCode == KeyEvent.KEYCODE_VOICE_ASSIST) {
3418 if (!down) {
3419 Intent voiceIntent;
Michael Wright869a67c2014-08-26 19:33:06 -07003420 if (!keyguardOn) {
Michael Wrightdc63f7b2014-08-21 19:05:21 -07003421 voiceIntent = new Intent(RecognizerIntent.ACTION_WEB_SEARCH);
3422 } else {
Dianne Hackbornb6683c42015-06-18 17:40:33 -07003423 IDeviceIdleController dic = IDeviceIdleController.Stub.asInterface(
3424 ServiceManager.getService(Context.DEVICE_IDLE_CONTROLLER));
3425 if (dic != null) {
3426 try {
3427 dic.exitIdle("voice-search");
3428 } catch (RemoteException e) {
3429 }
3430 }
Michael Wrightdc63f7b2014-08-21 19:05:21 -07003431 voiceIntent = new Intent(RecognizerIntent.ACTION_VOICE_SEARCH_HANDS_FREE);
Michael Wright869a67c2014-08-26 19:33:06 -07003432 voiceIntent.putExtra(RecognizerIntent.EXTRA_SECURE, true);
Michael Wrightdc63f7b2014-08-21 19:05:21 -07003433 }
Bart Sears8b1c27c2015-03-18 23:51:02 +00003434 startActivityAsUser(voiceIntent, UserHandle.CURRENT_OR_SELF);
Michael Wrightdc63f7b2014-08-21 19:05:21 -07003435 }
Jeff Sharkey2991fa32012-12-05 18:06:43 -08003436 } else if (keyCode == KeyEvent.KEYCODE_SYSRQ) {
3437 if (down && repeatCount == 0) {
Muyuan Li6ca619f2016-03-08 13:30:42 -08003438 mScreenshotRunnable.setScreenshotType(TAKE_SCREENSHOT_FULLSCREEN);
Jeff Sharkey2991fa32012-12-05 18:06:43 -08003439 mHandler.post(mScreenshotRunnable);
3440 }
3441 return -1;
Michael Wrightb854e242013-02-05 17:54:02 -08003442 } else if (keyCode == KeyEvent.KEYCODE_BRIGHTNESS_UP
3443 || keyCode == KeyEvent.KEYCODE_BRIGHTNESS_DOWN) {
3444 if (down) {
3445 int direction = keyCode == KeyEvent.KEYCODE_BRIGHTNESS_UP ? 1 : -1;
3446
3447 // Disable autobrightness if it's on
3448 int auto = Settings.System.getIntForUser(
3449 mContext.getContentResolver(),
3450 Settings.System.SCREEN_BRIGHTNESS_MODE,
3451 Settings.System.SCREEN_BRIGHTNESS_MODE_MANUAL,
3452 UserHandle.USER_CURRENT_OR_SELF);
3453 if (auto != 0) {
3454 Settings.System.putIntForUser(mContext.getContentResolver(),
3455 Settings.System.SCREEN_BRIGHTNESS_MODE,
3456 Settings.System.SCREEN_BRIGHTNESS_MODE_MANUAL,
3457 UserHandle.USER_CURRENT_OR_SELF);
3458 }
3459
3460 int min = mPowerManager.getMinimumScreenBrightnessSetting();
3461 int max = mPowerManager.getMaximumScreenBrightnessSetting();
3462 int step = (max - min + BRIGHTNESS_STEPS - 1) / BRIGHTNESS_STEPS * direction;
3463 int brightness = Settings.System.getIntForUser(mContext.getContentResolver(),
3464 Settings.System.SCREEN_BRIGHTNESS,
3465 mPowerManager.getDefaultScreenBrightnessSetting(),
3466 UserHandle.USER_CURRENT_OR_SELF);
3467 brightness += step;
3468 // Make sure we don't go beyond the limits.
3469 brightness = Math.min(max, brightness);
3470 brightness = Math.max(min, brightness);
3471
3472 Settings.System.putIntForUser(mContext.getContentResolver(),
3473 Settings.System.SCREEN_BRIGHTNESS, brightness,
3474 UserHandle.USER_CURRENT_OR_SELF);
Bart Sears8b1c27c2015-03-18 23:51:02 +00003475 startActivityAsUser(new Intent(Intent.ACTION_SHOW_BRIGHTNESS_DIALOG),
Alan Viverette5a399492014-07-14 16:19:38 -07003476 UserHandle.CURRENT_OR_SELF);
Michael Wrightb854e242013-02-05 17:54:02 -08003477 }
3478 return -1;
Jaewan Kim765487f2016-01-12 14:45:42 +09003479 } else if (keyCode == KeyEvent.KEYCODE_VOLUME_UP
3480 || keyCode == KeyEvent.KEYCODE_VOLUME_DOWN
3481 || keyCode == KeyEvent.KEYCODE_VOLUME_MUTE) {
3482 if (mUseTvRouting) {
3483 // On TVs volume keys never go to the foreground app.
3484 dispatchDirectAudioEvent(event);
3485 return -1;
3486 }
Muyuan Li94ce94e2016-02-24 16:20:54 -08003487 }
3488
Andrii Kulian112d0562016-03-08 10:44:22 -08003489 // Toggle Caps Lock on META-ALT.
3490 boolean actionTriggered = false;
3491 if (KeyEvent.isModifierKey(keyCode)) {
3492 if (!mPendingCapsLockToggle) {
3493 // Start tracking meta state for combo.
3494 mInitialMetaState = mMetaState;
3495 mPendingCapsLockToggle = true;
3496 } else if (event.getAction() == KeyEvent.ACTION_UP) {
3497 int altOnMask = mMetaState & KeyEvent.META_ALT_MASK;
3498 int metaOnMask = mMetaState & KeyEvent.META_META_MASK;
3499
3500 // Check for Caps Lock toggle
3501 if ((metaOnMask != 0) && (altOnMask != 0)) {
3502 // Check if nothing else is pressed
3503 if (mInitialMetaState == (mMetaState ^ (altOnMask | metaOnMask))) {
3504 // Handle Caps Lock Toggle
3505 mInputManagerInternal.toggleCapsLock(event.getDeviceId());
3506 actionTriggered = true;
3507 }
3508 }
3509
3510 // Always stop tracking when key goes up.
3511 mPendingCapsLockToggle = false;
3512 }
3513 }
3514 // Store current meta state to be able to evaluate it later.
3515 mMetaState = metaState;
3516
3517 if (actionTriggered) {
3518 return -1;
3519 }
3520
Muyuan Li94ce94e2016-02-24 16:20:54 -08003521 if (KeyEvent.isMetaKey(keyCode)) {
Michael Wright6a62e552014-06-03 19:19:48 -07003522 if (down) {
3523 mPendingMetaAction = true;
3524 } else if (mPendingMetaAction) {
Tim Kilbourn0e5f1102015-06-05 16:18:09 -07003525 launchAssistAction(Intent.EXTRA_ASSIST_INPUT_HINT_KEYBOARD, event.getDeviceId());
Michael Wright6a62e552014-06-03 19:19:48 -07003526 }
3527 return -1;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003528 }
Jeff Browncaab4d02010-12-09 22:13:41 -08003529
Jeff Brownc1fb48d2010-12-08 16:52:09 -08003530 // Shortcuts are invoked through Search+key, so intercept those here
Jeff Browncaab4d02010-12-09 22:13:41 -08003531 // Any printing key that is chorded with Search should be consumed
3532 // even if no shortcut was invoked. This prevents text from being
3533 // inadvertently inserted when using a keyboard that has built-in macro
3534 // shortcut keys (that emit Search+x) and some of them are not registered.
Jeff Brownfd23e3e2012-05-09 13:34:28 -07003535 if (mSearchKeyShortcutPending) {
Jeff Browncaab4d02010-12-09 22:13:41 -08003536 final KeyCharacterMap kcm = event.getKeyCharacterMap();
3537 if (kcm.isPrintingKey(keyCode)) {
Jeff Brownfd23e3e2012-05-09 13:34:28 -07003538 mConsumeSearchKeyUp = true;
3539 mSearchKeyShortcutPending = false;
Jeff Browncaab4d02010-12-09 22:13:41 -08003540 if (down && repeatCount == 0 && !keyguardOn) {
3541 Intent shortcutIntent = mShortcutManager.getIntent(kcm, keyCode, metaState);
3542 if (shortcutIntent != null) {
3543 shortcutIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
Jeff Brownf0a3cc52011-01-26 18:42:46 -08003544 try {
Bart Sears8b1c27c2015-03-18 23:51:02 +00003545 startActivityAsUser(shortcutIntent, UserHandle.CURRENT);
Andrei Stingaceanu0bf096f2016-04-14 18:11:57 +01003546 dismissKeyboardShortcutsMenu();
Jeff Brownf0a3cc52011-01-26 18:42:46 -08003547 } catch (ActivityNotFoundException ex) {
3548 Slog.w(TAG, "Dropping shortcut key combination because "
3549 + "the activity to which it is registered was not found: "
Jeff Brownfd23e3e2012-05-09 13:34:28 -07003550 + "SEARCH+" + KeyEvent.keyCodeToString(keyCode), ex);
Jeff Brownf0a3cc52011-01-26 18:42:46 -08003551 }
Jeff Browncaab4d02010-12-09 22:13:41 -08003552 } else {
3553 Slog.i(TAG, "Dropping unregistered shortcut key combination: "
Jeff Brownfd23e3e2012-05-09 13:34:28 -07003554 + "SEARCH+" + KeyEvent.keyCodeToString(keyCode));
Jeff Brown49ed71d2010-12-06 17:13:33 -08003555 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003556 }
Jeff Brownd5bb82d2011-10-12 13:57:59 -07003557 return -1;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003558 }
3559 }
3560
Jeff Brown68b909d2011-12-07 16:36:01 -08003561 // Invoke shortcuts using Meta.
Jeff Brown602ab322012-05-16 13:33:47 -07003562 if (down && repeatCount == 0 && !keyguardOn
Jeff Brown68b909d2011-12-07 16:36:01 -08003563 && (metaState & KeyEvent.META_META_ON) != 0) {
3564 final KeyCharacterMap kcm = event.getKeyCharacterMap();
Jeff Brown602ab322012-05-16 13:33:47 -07003565 if (kcm.isPrintingKey(keyCode)) {
3566 Intent shortcutIntent = mShortcutManager.getIntent(kcm, keyCode,
3567 metaState & ~(KeyEvent.META_META_ON
3568 | KeyEvent.META_META_LEFT_ON | KeyEvent.META_META_RIGHT_ON));
3569 if (shortcutIntent != null) {
3570 shortcutIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
3571 try {
Bart Sears8b1c27c2015-03-18 23:51:02 +00003572 startActivityAsUser(shortcutIntent, UserHandle.CURRENT);
Andrei Stingaceanu0bf096f2016-04-14 18:11:57 +01003573 dismissKeyboardShortcutsMenu();
Jeff Brown602ab322012-05-16 13:33:47 -07003574 } catch (ActivityNotFoundException ex) {
3575 Slog.w(TAG, "Dropping shortcut key combination because "
3576 + "the activity to which it is registered was not found: "
3577 + "META+" + KeyEvent.keyCodeToString(keyCode), ex);
3578 }
3579 return -1;
Jeff Brown68b909d2011-12-07 16:36:01 -08003580 }
Jeff Brown68b909d2011-12-07 16:36:01 -08003581 }
3582 }
3583
Jeff Brown6651a632011-11-28 12:59:11 -08003584 // Handle application launch keys.
Jeff Brown602ab322012-05-16 13:33:47 -07003585 if (down && repeatCount == 0 && !keyguardOn) {
Jeff Brown6651a632011-11-28 12:59:11 -08003586 String category = sApplicationLaunchKeyCategories.get(keyCode);
3587 if (category != null) {
Dianne Hackbornf5b86712011-12-05 17:42:41 -08003588 Intent intent = Intent.makeMainSelectorActivity(Intent.ACTION_MAIN, category);
Jeff Brown6651a632011-11-28 12:59:11 -08003589 intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
3590 try {
Bart Sears8b1c27c2015-03-18 23:51:02 +00003591 startActivityAsUser(intent, UserHandle.CURRENT);
Andrei Stingaceanu0bf096f2016-04-14 18:11:57 +01003592 dismissKeyboardShortcutsMenu();
Jeff Brown6651a632011-11-28 12:59:11 -08003593 } catch (ActivityNotFoundException ex) {
3594 Slog.w(TAG, "Dropping application launch key because "
3595 + "the activity to which it is registered was not found: "
3596 + "keyCode=" + keyCode + ", category=" + category, ex);
3597 }
Jeff Brown68b909d2011-12-07 16:36:01 -08003598 return -1;
Jeff Brown6651a632011-11-28 12:59:11 -08003599 }
3600 }
3601
Michael Wright61c46752014-08-21 16:57:33 -07003602 // Display task switcher for ALT-TAB.
Jeff Brown68b909d2011-12-07 16:36:01 -08003603 if (down && repeatCount == 0 && keyCode == KeyEvent.KEYCODE_TAB) {
Michael Wrightd847ad52015-10-24 13:24:15 +01003604 if (mRecentAppsHeldModifiers == 0 && !keyguardOn && isUserSetupComplete()) {
Jeff Brown68b909d2011-12-07 16:36:01 -08003605 final int shiftlessModifiers = event.getModifiers() & ~KeyEvent.META_SHIFT_MASK;
Michael Wright61c46752014-08-21 16:57:33 -07003606 if (KeyEvent.metaStateHasModifiers(shiftlessModifiers, KeyEvent.META_ALT_ON)) {
Winson Chung1e8d71b2014-05-16 17:05:22 -07003607 mRecentAppsHeldModifiers = shiftlessModifiers;
Winson14db3622016-05-09 13:34:07 -07003608 showRecentApps(true, false);
Jeff Brown68b909d2011-12-07 16:36:01 -08003609 return -1;
3610 }
3611 }
Winson Chung1e8d71b2014-05-16 17:05:22 -07003612 } else if (!down && mRecentAppsHeldModifiers != 0
3613 && (metaState & mRecentAppsHeldModifiers) == 0) {
3614 mRecentAppsHeldModifiers = 0;
Winson Chungcdcd4872014-08-05 18:00:13 -07003615 hideRecentApps(true, false);
Jeff Brown68b909d2011-12-07 16:36:01 -08003616 }
3617
Yohei Yukawaae61f712015-12-09 13:00:10 -08003618 // Handle input method switching.
Jeff Browncf39bdf2012-05-18 14:41:19 -07003619 if (down && repeatCount == 0
3620 && (keyCode == KeyEvent.KEYCODE_LANGUAGE_SWITCH
3621 || (keyCode == KeyEvent.KEYCODE_SPACE
Yohei Yukawaae61f712015-12-09 13:00:10 -08003622 && (metaState & KeyEvent.META_META_MASK) != 0))) {
3623 final boolean forwardDirection = (metaState & KeyEvent.META_SHIFT_MASK) == 0;
3624 mWindowManagerFuncs.switchInputMethod(forwardDirection);
Jeff Browncf39bdf2012-05-18 14:41:19 -07003625 return -1;
3626 }
3627 if (mLanguageSwitchKeyPressed && !down
3628 && (keyCode == KeyEvent.KEYCODE_LANGUAGE_SWITCH
3629 || keyCode == KeyEvent.KEYCODE_SPACE)) {
3630 mLanguageSwitchKeyPressed = false;
3631 return -1;
3632 }
3633
Jeff Brown13f00f02014-10-31 14:45:50 -07003634 if (isValidGlobalKey(keyCode)
3635 && mGlobalKeyManager.handleGlobalKey(mContext, keyCode, event)) {
Justin Kohd378ad72013-04-01 12:18:26 -07003636 return -1;
3637 }
3638
Muyuan Li94ce94e2016-02-24 16:20:54 -08003639 if (down) {
Jim Millere4044bb2016-05-10 18:38:25 -07003640 long shortcutCode = keyCode;
Muyuan Li94ce94e2016-02-24 16:20:54 -08003641 if (event.isCtrlPressed()) {
3642 shortcutCode |= ((long) KeyEvent.META_CTRL_ON) << Integer.SIZE;
3643 }
3644
3645 if (event.isAltPressed()) {
3646 shortcutCode |= ((long) KeyEvent.META_ALT_ON) << Integer.SIZE;
3647 }
3648
3649 if (event.isShiftPressed()) {
3650 shortcutCode |= ((long) KeyEvent.META_SHIFT_ON) << Integer.SIZE;
3651 }
3652
3653 if (event.isMetaPressed()) {
3654 shortcutCode |= ((long) KeyEvent.META_META_ON) << Integer.SIZE;
3655 }
3656
3657 IShortcutService shortcutService = mShortcutKeyServices.get(shortcutCode);
3658 if (shortcutService != null) {
3659 try {
Muyuan Lib5dd0492016-04-14 13:22:20 -07003660 if (isUserSetupComplete()) {
3661 shortcutService.notifyShortcutKeyPressed(shortcutCode);
3662 }
Muyuan Li94ce94e2016-02-24 16:20:54 -08003663 } catch (RemoteException e) {
3664 mShortcutKeyServices.delete(shortcutCode);
3665 }
3666 return -1;
3667 }
3668 }
3669
Michael Wright6a62e552014-06-03 19:19:48 -07003670 // Reserve all the META modifier combos for system behavior
Michael Wrightce0c13a2014-07-30 10:49:21 -07003671 if ((metaState & KeyEvent.META_META_ON) != 0) {
Michael Wright6a62e552014-06-03 19:19:48 -07003672 return -1;
3673 }
3674
Jeff Brown68b909d2011-12-07 16:36:01 -08003675 // Let the application handle the key.
Jeff Brownd5bb82d2011-10-12 13:57:59 -07003676 return 0;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003677 }
3678
Jeff Brown3915bb82010-11-05 15:02:16 -07003679 /** {@inheritDoc} */
3680 @Override
Jeff Brown49ed71d2010-12-06 17:13:33 -08003681 public KeyEvent dispatchUnhandledKey(WindowState win, KeyEvent event, int policyFlags) {
Jeff Brown54875002011-04-06 15:33:01 -07003682 // Note: This method is only called if the initial down was unhandled.
Jeff Brown40013652012-05-16 21:22:36 -07003683 if (DEBUG_INPUT) {
Jeff Brown1f245102010-11-18 20:53:46 -08003684 Slog.d(TAG, "Unhandled key: win=" + win + ", action=" + event.getAction()
3685 + ", flags=" + event.getFlags()
3686 + ", keyCode=" + event.getKeyCode()
3687 + ", scanCode=" + event.getScanCode()
3688 + ", metaState=" + event.getMetaState()
3689 + ", repeatCount=" + event.getRepeatCount()
3690 + ", policyFlags=" + policyFlags);
Jeff Brown3915bb82010-11-05 15:02:16 -07003691 }
Jeff Brown49ed71d2010-12-06 17:13:33 -08003692
Jeff Brownfd23e3e2012-05-09 13:34:28 -07003693 KeyEvent fallbackEvent = null;
Jeff Brown49ed71d2010-12-06 17:13:33 -08003694 if ((event.getFlags() & KeyEvent.FLAG_FALLBACK) == 0) {
3695 final KeyCharacterMap kcm = event.getKeyCharacterMap();
Jeff Brownc1fb48d2010-12-08 16:52:09 -08003696 final int keyCode = event.getKeyCode();
3697 final int metaState = event.getMetaState();
Jeff Brownfd23e3e2012-05-09 13:34:28 -07003698 final boolean initialDown = event.getAction() == KeyEvent.ACTION_DOWN
3699 && event.getRepeatCount() == 0;
Jeff Brown49ed71d2010-12-06 17:13:33 -08003700
Jeff Brown54875002011-04-06 15:33:01 -07003701 // Check for fallback actions specified by the key character map.
Jeff Brownfd23e3e2012-05-09 13:34:28 -07003702 final FallbackAction fallbackAction;
3703 if (initialDown) {
3704 fallbackAction = kcm.getFallbackAction(keyCode, metaState);
3705 } else {
3706 fallbackAction = mFallbackActions.get(keyCode);
3707 }
3708
3709 if (fallbackAction != null) {
Jeff Brown40013652012-05-16 21:22:36 -07003710 if (DEBUG_INPUT) {
Jeff Brownfd23e3e2012-05-09 13:34:28 -07003711 Slog.d(TAG, "Fallback: keyCode=" + fallbackAction.keyCode
3712 + " metaState=" + Integer.toHexString(fallbackAction.metaState));
Jeff Brown49ed71d2010-12-06 17:13:33 -08003713 }
3714
Jeff Brownfd23e3e2012-05-09 13:34:28 -07003715 final int flags = event.getFlags() | KeyEvent.FLAG_FALLBACK;
3716 fallbackEvent = KeyEvent.obtain(
Jeff Brown49ed71d2010-12-06 17:13:33 -08003717 event.getDownTime(), event.getEventTime(),
Jeff Brownfd23e3e2012-05-09 13:34:28 -07003718 event.getAction(), fallbackAction.keyCode,
3719 event.getRepeatCount(), fallbackAction.metaState,
Jeff Brown49ed71d2010-12-06 17:13:33 -08003720 event.getDeviceId(), event.getScanCode(),
3721 flags, event.getSource(), null);
Jeff Brownfd23e3e2012-05-09 13:34:28 -07003722
3723 if (!interceptFallback(win, fallbackEvent, policyFlags)) {
3724 fallbackEvent.recycle();
3725 fallbackEvent = null;
Jeff Brown49ed71d2010-12-06 17:13:33 -08003726 }
Jeff Brownfd23e3e2012-05-09 13:34:28 -07003727
3728 if (initialDown) {
3729 mFallbackActions.put(keyCode, fallbackAction);
3730 } else if (event.getAction() == KeyEvent.ACTION_UP) {
3731 mFallbackActions.remove(keyCode);
3732 fallbackAction.recycle();
3733 }
Jeff Brown49ed71d2010-12-06 17:13:33 -08003734 }
3735 }
3736
Jeff Brown40013652012-05-16 21:22:36 -07003737 if (DEBUG_INPUT) {
Jeff Brownfd23e3e2012-05-09 13:34:28 -07003738 if (fallbackEvent == null) {
3739 Slog.d(TAG, "No fallback.");
3740 } else {
3741 Slog.d(TAG, "Performing fallback: " + fallbackEvent);
3742 }
Jeff Brown49ed71d2010-12-06 17:13:33 -08003743 }
Jeff Brownfd23e3e2012-05-09 13:34:28 -07003744 return fallbackEvent;
Jeff Brown3915bb82010-11-05 15:02:16 -07003745 }
3746
Jeff Brownfd23e3e2012-05-09 13:34:28 -07003747 private boolean interceptFallback(WindowState win, KeyEvent fallbackEvent, int policyFlags) {
Jeff Brown037c33e2014-04-09 00:31:55 -07003748 int actions = interceptKeyBeforeQueueing(fallbackEvent, policyFlags);
Jeff Brownfd23e3e2012-05-09 13:34:28 -07003749 if ((actions & ACTION_PASS_TO_USER) != 0) {
3750 long delayMillis = interceptKeyBeforeDispatching(
3751 win, fallbackEvent, policyFlags);
3752 if (delayMillis == 0) {
3753 return true;
3754 }
3755 }
3756 return false;
Jeff Brown6f2fba42011-02-19 01:08:02 -08003757 }
3758
Jim Millere4044bb2016-05-10 18:38:25 -07003759 @Override
Muyuan Li94ce94e2016-02-24 16:20:54 -08003760 public void registerShortcutKey(long shortcutCode, IShortcutService shortcutService)
3761 throws RemoteException {
3762 synchronized (mLock) {
3763 IShortcutService service = mShortcutKeyServices.get(shortcutCode);
Muyuan Li24d24ac2016-03-03 21:15:02 -08003764 if (service != null && service.asBinder().pingBinder()) {
3765 throw new RemoteException("Key already exists.");
Muyuan Li94ce94e2016-02-24 16:20:54 -08003766 }
3767
3768 mShortcutKeyServices.put(shortcutCode, shortcutService);
3769 }
3770 }
3771
Adrian Roosd88eb262016-08-04 14:50:48 -07003772 @Override
Jorim Jaggife762342016-10-13 14:33:27 +02003773 public void onKeyguardOccludedChangedLw(boolean occluded) {
3774 if (mKeyguardDelegate != null && mKeyguardDelegate.isShowing()) {
3775 mPendingKeyguardOccluded = occluded;
3776 mKeyguardOccludedChanged = true;
3777 } else {
3778 setKeyguardOccludedLw(occluded);
3779 }
3780 }
3781
3782 private int handleStartTransitionForKeyguardLw(int transit, @Nullable Animation anim) {
3783 if (mKeyguardOccludedChanged) {
3784 if (DEBUG_KEYGUARD) Slog.d(TAG, "transition/occluded changed occluded="
3785 + mPendingKeyguardOccluded);
3786 mKeyguardOccludedChanged = false;
3787 if (setKeyguardOccludedLw(mPendingKeyguardOccluded)) {
3788 return FINISH_LAYOUT_REDO_LAYOUT | FINISH_LAYOUT_REDO_WALLPAPER;
3789 }
3790 }
3791 if (AppTransition.isKeyguardGoingAwayTransit(transit)) {
Jorim Jaggi8d786932016-10-26 19:08:36 -07003792 if (DEBUG_KEYGUARD) Slog.d(TAG, "Starting keyguard exit animation");
Jorim Jaggife762342016-10-13 14:33:27 +02003793 final long startTime = anim != null
3794 ? SystemClock.uptimeMillis() + anim.getStartOffset()
3795 : SystemClock.uptimeMillis();
3796 final long duration = anim != null
3797 ? anim.getDuration()
3798 : 0;
3799 startKeyguardExitAnimation(startTime, duration);
3800 }
3801 return 0;
Adrian Roosd88eb262016-08-04 14:50:48 -07003802 }
3803
Jeff Brownde7a8ea2012-06-13 18:28:57 -07003804 private void launchAssistLongPressAction() {
3805 performHapticFeedbackLw(null, HapticFeedbackConstants.LONG_PRESS, false);
3806 sendCloseSystemWindows(SYSTEM_DIALOG_REASON_ASSIST);
3807
3808 // launch the search activity
3809 Intent intent = new Intent(Intent.ACTION_SEARCH_LONG_PRESS);
3810 intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
3811 try {
RoboErik8a2cfc32014-05-16 11:19:38 -07003812 // TODO: This only stops the factory-installed search manager.
Jim Miller45308b12012-06-18 19:23:39 -07003813 // Need to formalize an API to handle others
Jeff Brownde7a8ea2012-06-13 18:28:57 -07003814 SearchManager searchManager = getSearchManager();
3815 if (searchManager != null) {
3816 searchManager.stopSearch();
3817 }
Bart Sears8b1c27c2015-03-18 23:51:02 +00003818 startActivityAsUser(intent, UserHandle.CURRENT);
Jeff Brownde7a8ea2012-06-13 18:28:57 -07003819 } catch (ActivityNotFoundException e) {
3820 Slog.w(TAG, "No activity to handle assist long press action.", e);
3821 }
3822 }
3823
Tim Kilbourn0e5f1102015-06-05 16:18:09 -07003824 private void launchAssistAction(String hint, int deviceId) {
Jeff Brownde7a8ea2012-06-13 18:28:57 -07003825 sendCloseSystemWindows(SYSTEM_DIALOG_REASON_ASSIST);
Maurice Lam39d13812015-07-23 20:49:20 -07003826 if (!isUserSetupComplete()) {
3827 // Disable opening assist window during setup
3828 return;
3829 }
Tim Kilbourn0e5f1102015-06-05 16:18:09 -07003830 Bundle args = null;
3831 if (deviceId > Integer.MIN_VALUE) {
3832 args = new Bundle();
3833 args.putInt(Intent.EXTRA_ASSIST_INPUT_DEVICE_ID, deviceId);
Jeff Brownde7a8ea2012-06-13 18:28:57 -07003834 }
Jorim Jaggi165ce062015-07-06 16:18:11 -07003835 if ((mContext.getResources().getConfiguration().uiMode
3836 & Configuration.UI_MODE_TYPE_MASK) == Configuration.UI_MODE_TYPE_TELEVISION) {
3837 // On TV, use legacy handling until assistants are implemented in the proper way.
3838 ((SearchManager) mContext.getSystemService(Context.SEARCH_SERVICE))
3839 .launchLegacyAssist(hint, UserHandle.myUserId(), args);
3840 } else {
Adrian Roosf2efdd82016-04-15 17:43:18 -07003841 if (hint != null) {
3842 if (args == null) {
3843 args = new Bundle();
Jorim Jaggi165ce062015-07-06 16:18:11 -07003844 }
Adrian Roosf2efdd82016-04-15 17:43:18 -07003845 args.putBoolean(hint, true);
3846 }
3847 StatusBarManagerInternal statusbar = getStatusBarManagerInternal();
3848 if (statusbar != null) {
3849 statusbar.startAssist(args);
Jorim Jaggi165ce062015-07-06 16:18:11 -07003850 }
3851 }
Jeff Brownde7a8ea2012-06-13 18:28:57 -07003852 }
3853
Bart Sears8b1c27c2015-03-18 23:51:02 +00003854 private void startActivityAsUser(Intent intent, UserHandle handle) {
3855 if (isUserSetupComplete()) {
3856 mContext.startActivityAsUser(intent, handle);
3857 } else {
3858 Slog.i(TAG, "Not starting activity because user setup is in progress: " + intent);
3859 }
3860 }
3861
Jeff Brownde7a8ea2012-06-13 18:28:57 -07003862 private SearchManager getSearchManager() {
3863 if (mSearchManager == null) {
3864 mSearchManager = (SearchManager) mContext.getSystemService(Context.SEARCH_SERVICE);
3865 }
3866 return mSearchManager;
3867 }
3868
Jeff Browncaca8812013-05-09 13:34:33 -07003869 private void preloadRecentApps() {
3870 mPreloadedRecentApps = true;
Adrian Roosf2efdd82016-04-15 17:43:18 -07003871 StatusBarManagerInternal statusbar = getStatusBarManagerInternal();
3872 if (statusbar != null) {
3873 statusbar.preloadRecentApps();
Jeff Browncaca8812013-05-09 13:34:33 -07003874 }
3875 }
3876
3877 private void cancelPreloadRecentApps() {
3878 if (mPreloadedRecentApps) {
3879 mPreloadedRecentApps = false;
Adrian Roosf2efdd82016-04-15 17:43:18 -07003880 StatusBarManagerInternal statusbar = getStatusBarManagerInternal();
3881 if (statusbar != null) {
3882 statusbar.cancelPreloadRecentApps();
Jeff Browncaca8812013-05-09 13:34:33 -07003883 }
3884 }
3885 }
3886
3887 private void toggleRecentApps() {
3888 mPreloadedRecentApps = false; // preloading no longer needs to be canceled
Adrian Roosf2efdd82016-04-15 17:43:18 -07003889 StatusBarManagerInternal statusbar = getStatusBarManagerInternal();
3890 if (statusbar != null) {
3891 statusbar.toggleRecentApps();
Winson Chung1e8d71b2014-05-16 17:05:22 -07003892 }
3893 }
3894
Craig Mautner84984fa2014-06-19 11:19:20 -07003895 @Override
Jorim Jaggi681fc7b2016-04-14 22:02:39 -07003896 public void showRecentApps(boolean fromHome) {
Craig Mautner84984fa2014-06-19 11:19:20 -07003897 mHandler.removeMessages(MSG_DISPATCH_SHOW_RECENTS);
Jorim Jaggi681fc7b2016-04-14 22:02:39 -07003898 mHandler.obtainMessage(MSG_DISPATCH_SHOW_RECENTS, fromHome ? 1 : 0, 0).sendToTarget();
Craig Mautner84984fa2014-06-19 11:19:20 -07003899 }
3900
Jorim Jaggi681fc7b2016-04-14 22:02:39 -07003901 private void showRecentApps(boolean triggeredFromAltTab, boolean fromHome) {
Winson Chung1e8d71b2014-05-16 17:05:22 -07003902 mPreloadedRecentApps = false; // preloading no longer needs to be canceled
Adrian Roosf2efdd82016-04-15 17:43:18 -07003903 StatusBarManagerInternal statusbar = getStatusBarManagerInternal();
3904 if (statusbar != null) {
3905 statusbar.showRecentApps(triggeredFromAltTab, fromHome);
Jeff Browncaca8812013-05-09 13:34:33 -07003906 }
3907 }
3908
Clara Bayarri4e850ff2016-03-02 11:12:32 -08003909 private void toggleKeyboardShortcutsMenu(int deviceId) {
Adrian Roosf2efdd82016-04-15 17:43:18 -07003910 StatusBarManagerInternal statusbar = getStatusBarManagerInternal();
3911 if (statusbar != null) {
3912 statusbar.toggleKeyboardShortcutsMenu(deviceId);
Clara Bayarrif2debb12015-07-10 14:47:17 +01003913 }
3914 }
3915
Andrei Stingaceanu0bf096f2016-04-14 18:11:57 +01003916 private void dismissKeyboardShortcutsMenu() {
3917 StatusBarManagerInternal statusbar = getStatusBarManagerInternal();
3918 if (statusbar != null) {
3919 statusbar.dismissKeyboardShortcutsMenu();
3920 }
3921 }
3922
Winson Chungcdcd4872014-08-05 18:00:13 -07003923 private void hideRecentApps(boolean triggeredFromAltTab, boolean triggeredFromHome) {
Winson Chung1e8d71b2014-05-16 17:05:22 -07003924 mPreloadedRecentApps = false; // preloading no longer needs to be canceled
Adrian Roosf2efdd82016-04-15 17:43:18 -07003925 StatusBarManagerInternal statusbar = getStatusBarManagerInternal();
3926 if (statusbar != null) {
3927 statusbar.hideRecentApps(triggeredFromAltTab, triggeredFromHome);
Winson Chung1e8d71b2014-05-16 17:05:22 -07003928 }
3929 }
3930
Filip Gruszczynskia483a1d2015-03-17 19:06:58 +00003931 void launchHomeFromHotKey() {
Bryce Lee662ed802015-04-10 20:11:39 +00003932 launchHomeFromHotKey(true /* awakenFromDreams */, true /*respectKeyguard*/);
Filip Gruszczynskia483a1d2015-03-17 19:06:58 +00003933 }
3934
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003935 /**
3936 * A home key -> launch home action was detected. Take the appropriate action
3937 * given the situation with the keyguard.
3938 */
Bryce Lee662ed802015-04-10 20:11:39 +00003939 void launchHomeFromHotKey(final boolean awakenFromDreams, final boolean respectKeyguard) {
3940 if (respectKeyguard) {
3941 if (isKeyguardShowingAndNotOccluded()) {
3942 // don't launch home if keyguard showing
3943 return;
3944 }
3945
Jorim Jaggife762342016-10-13 14:33:27 +02003946 if (!mKeyguardOccluded && mKeyguardDelegate.isInputRestricted()) {
Bryce Lee662ed802015-04-10 20:11:39 +00003947 // when in keyguard restricted mode, must first verify unlock
3948 // before launching home
3949 mKeyguardDelegate.verifyUnlock(new OnKeyguardExitResult() {
3950 @Override
3951 public void onKeyguardExitResult(boolean success) {
3952 if (success) {
3953 try {
Sudheer Shankadc589ac2016-11-10 15:30:17 -08003954 ActivityManager.getService().stopAppSwitches();
Bryce Lee662ed802015-04-10 20:11:39 +00003955 } catch (RemoteException e) {
3956 }
3957 sendCloseSystemWindows(SYSTEM_DIALOG_REASON_HOME_KEY);
3958 startDockOrHome(true /*fromHomeKey*/, awakenFromDreams);
Dianne Hackborn256dd3b2009-05-19 18:51:21 -07003959 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003960 }
Bryce Lee662ed802015-04-10 20:11:39 +00003961 });
3962 return;
3963 }
3964 }
3965
3966 // no keyguard stuff to worry about, just launch home!
3967 try {
Sudheer Shankadc589ac2016-11-10 15:30:17 -08003968 ActivityManager.getService().stopAppSwitches();
Bryce Lee662ed802015-04-10 20:11:39 +00003969 } catch (RemoteException e) {
3970 }
3971 if (mRecentsVisible) {
3972 // Hide Recents and notify it to launch Home
3973 if (awakenFromDreams) {
3974 awakenDreams();
3975 }
Bryce Lee662ed802015-04-10 20:11:39 +00003976 hideRecentApps(false, true);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003977 } else {
Bryce Lee662ed802015-04-10 20:11:39 +00003978 // Otherwise, just launch Home
3979 sendCloseSystemWindows(SYSTEM_DIALOG_REASON_HOME_KEY);
3980 startDockOrHome(true /*fromHomeKey*/, awakenFromDreams);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003981 }
3982 }
3983
John Spurlock04db1762013-05-13 12:46:41 -04003984 private final Runnable mClearHideNavigationFlag = new Runnable() {
3985 @Override
3986 public void run() {
3987 synchronized (mWindowManagerFuncs.getWindowManagerLock()) {
3988 // Clear flags.
3989 mForceClearedSystemUiFlags &=
3990 ~View.SYSTEM_UI_FLAG_HIDE_NAVIGATION;
3991 }
3992 mWindowManagerFuncs.reevaluateStatusBarVisibility();
Dianne Hackborne26ab702011-10-16 13:21:33 -07003993 }
3994 };
3995
3996 /**
3997 * Input handler used while nav bar is hidden. Captures any touch on the screen,
3998 * to determine when the nav bar should be shown and prevent applications from
3999 * receiving those touches.
4000 */
Jeff Brown32cbc38552011-12-01 14:01:49 -08004001 final class HideNavInputEventReceiver extends InputEventReceiver {
4002 public HideNavInputEventReceiver(InputChannel inputChannel, Looper looper) {
4003 super(inputChannel, looper);
4004 }
4005
Dianne Hackborndf89e652011-10-06 22:35:11 -07004006 @Override
Jeff Brown32cbc38552011-12-01 14:01:49 -08004007 public void onInputEvent(InputEvent event) {
Dianne Hackborndf89e652011-10-06 22:35:11 -07004008 boolean handled = false;
4009 try {
Jeff Brown4952dfd2011-11-30 19:23:22 -08004010 if (event instanceof MotionEvent
4011 && (event.getSource() & InputDevice.SOURCE_CLASS_POINTER) != 0) {
4012 final MotionEvent motionEvent = (MotionEvent)event;
4013 if (motionEvent.getAction() == MotionEvent.ACTION_DOWN) {
Dianne Hackborndf89e652011-10-06 22:35:11 -07004014 // When the user taps down, we re-show the nav bar.
4015 boolean changed = false;
John Spurlock04db1762013-05-13 12:46:41 -04004016 synchronized (mWindowManagerFuncs.getWindowManagerLock()) {
Chong Zhang9f7fb092016-05-20 17:03:08 -07004017 if (mInputConsumer == null) {
4018 return;
4019 }
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07004020 // Any user activity always causes us to show the
4021 // navigation controls, if they had been hidden.
4022 // We also clear the low profile and only content
4023 // flags so that tapping on the screen will atomically
4024 // restore all currently hidden screen decorations.
4025 int newVal = mResettingSystemUiFlags |
4026 View.SYSTEM_UI_FLAG_HIDE_NAVIGATION |
4027 View.SYSTEM_UI_FLAG_LOW_PROFILE |
4028 View.SYSTEM_UI_FLAG_FULLSCREEN;
Dianne Hackborne26ab702011-10-16 13:21:33 -07004029 if (mResettingSystemUiFlags != newVal) {
4030 mResettingSystemUiFlags = newVal;
Dianne Hackborndf89e652011-10-06 22:35:11 -07004031 changed = true;
4032 }
Dianne Hackborne26ab702011-10-16 13:21:33 -07004033 // We don't allow the system's nav bar to be hidden
4034 // again for 1 second, to prevent applications from
4035 // spamming us and keeping it from being shown.
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07004036 newVal = mForceClearedSystemUiFlags |
4037 View.SYSTEM_UI_FLAG_HIDE_NAVIGATION;
Dianne Hackborne26ab702011-10-16 13:21:33 -07004038 if (mForceClearedSystemUiFlags != newVal) {
4039 mForceClearedSystemUiFlags = newVal;
4040 changed = true;
John Spurlock04db1762013-05-13 12:46:41 -04004041 mHandler.postDelayed(mClearHideNavigationFlag, 1000);
Dianne Hackborne26ab702011-10-16 13:21:33 -07004042 }
Dianne Hackborndf89e652011-10-06 22:35:11 -07004043 }
4044 if (changed) {
4045 mWindowManagerFuncs.reevaluateStatusBarVisibility();
4046 }
4047 }
4048 }
4049 } finally {
Jeff Brown32cbc38552011-12-01 14:01:49 -08004050 finishInputEvent(event, handled);
Dianne Hackborndf89e652011-10-06 22:35:11 -07004051 }
4052 }
Jeff Brown32cbc38552011-12-01 14:01:49 -08004053 }
Dianne Hackborndf89e652011-10-06 22:35:11 -07004054
4055 @Override
Winsonab216602016-08-09 14:05:20 -07004056 public void setRecentsVisibilityLw(boolean visible) {
4057 mRecentsVisible = visible;
4058 }
4059
4060 @Override
4061 public void setTvPipVisibilityLw(boolean visible) {
4062 mTvPictureInPictureVisible = visible;
4063 }
4064
4065 @Override
Dianne Hackborndf89e652011-10-06 22:35:11 -07004066 public int adjustSystemUiVisibilityLw(int visibility) {
John Spurlock5b9145b2013-08-20 15:13:47 -04004067 mStatusBarController.adjustSystemUiVisibilityLw(mLastSystemUiFlags, visibility);
4068 mNavigationBarController.adjustSystemUiVisibilityLw(mLastSystemUiFlags, visibility);
John Spurlock27735a42013-08-14 17:57:38 -04004069
Dianne Hackborndf89e652011-10-06 22:35:11 -07004070 // Reset any bits in mForceClearingStatusBarVisibility that
4071 // are now clear.
Dianne Hackborne26ab702011-10-16 13:21:33 -07004072 mResettingSystemUiFlags &= visibility;
Dianne Hackborndf89e652011-10-06 22:35:11 -07004073 // Clear any bits in the new visibility that are currently being
4074 // force cleared, before reporting it.
Dianne Hackborne26ab702011-10-16 13:21:33 -07004075 return visibility & ~mResettingSystemUiFlags
4076 & ~mForceClearedSystemUiFlags;
Dianne Hackborndf89e652011-10-06 22:35:11 -07004077 }
4078
Craig Mautner69b08182012-09-05 13:07:13 -07004079 @Override
Jorim Jaggi23bf5462016-05-13 15:24:39 -07004080 public boolean getInsetHintLw(WindowManager.LayoutParams attrs, Rect taskBounds,
4081 int displayRotation, int displayWidth, int displayHeight, Rect outContentInsets,
4082 Rect outStableInsets, Rect outOutsets) {
John Spurlockc6d1c602014-01-17 15:22:06 -05004083 final int fl = PolicyControl.getWindowFlags(null, attrs);
John Spurlock1db8b682014-02-18 11:18:59 -05004084 final int sysuiVis = PolicyControl.getSystemUiVisibility(null, attrs);
4085 final int systemUiVisibility = (sysuiVis | attrs.subtreeSystemUiVisibility);
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07004086
Filip Gruszczynski2987f612015-06-30 15:03:30 -07004087 final boolean useOutsets = outOutsets != null && shouldUseOutsets(attrs, fl);
4088 if (useOutsets) {
4089 int outset = ScreenShapeHelper.getWindowOutsetBottomPx(mContext.getResources());
4090 if (outset > 0) {
4091 if (displayRotation == Surface.ROTATION_0) {
4092 outOutsets.bottom += outset;
4093 } else if (displayRotation == Surface.ROTATION_90) {
4094 outOutsets.right += outset;
4095 } else if (displayRotation == Surface.ROTATION_180) {
4096 outOutsets.top += outset;
4097 } else if (displayRotation == Surface.ROTATION_270) {
4098 outOutsets.left += outset;
4099 }
4100 }
4101 }
4102
Dianne Hackborn5b5cc4d2012-05-16 13:15:00 -07004103 if ((fl & (FLAG_LAYOUT_IN_SCREEN | FLAG_LAYOUT_INSET_DECOR))
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004104 == (FLAG_LAYOUT_IN_SCREEN | FLAG_LAYOUT_INSET_DECOR)) {
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07004105 int availRight, availBottom;
Alan Viverette5a0f4ec2013-10-07 15:10:29 -07004106 if (canHideNavigationBar() &&
Dianne Hackborn5b5cc4d2012-05-16 13:15:00 -07004107 (systemUiVisibility & View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION) != 0) {
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07004108 availRight = mUnrestrictedScreenLeft + mUnrestrictedScreenWidth;
4109 availBottom = mUnrestrictedScreenTop + mUnrestrictedScreenHeight;
4110 } else {
4111 availRight = mRestrictedScreenLeft + mRestrictedScreenWidth;
4112 availBottom = mRestrictedScreenTop + mRestrictedScreenHeight;
4113 }
Dianne Hackborn5b5cc4d2012-05-16 13:15:00 -07004114 if ((systemUiVisibility & View.SYSTEM_UI_FLAG_LAYOUT_STABLE) != 0) {
4115 if ((fl & FLAG_FULLSCREEN) != 0) {
Adrian Roos37d7a682014-11-06 18:15:16 +01004116 outContentInsets.set(mStableFullscreenLeft, mStableFullscreenTop,
Dianne Hackborn5b5cc4d2012-05-16 13:15:00 -07004117 availRight - mStableFullscreenRight,
4118 availBottom - mStableFullscreenBottom);
4119 } else {
Adrian Roos37d7a682014-11-06 18:15:16 +01004120 outContentInsets.set(mStableLeft, mStableTop,
Dianne Hackborn5b5cc4d2012-05-16 13:15:00 -07004121 availRight - mStableRight, availBottom - mStableBottom);
4122 }
Dianne Hackbornc652de82013-02-15 16:32:56 -08004123 } else if ((fl & FLAG_FULLSCREEN) != 0 || (fl & FLAG_LAYOUT_IN_OVERSCAN) != 0) {
Adrian Roos37d7a682014-11-06 18:15:16 +01004124 outContentInsets.setEmpty();
Dianne Hackborn5b5cc4d2012-05-16 13:15:00 -07004125 } else if ((systemUiVisibility & (View.SYSTEM_UI_FLAG_FULLSCREEN
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07004126 | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN)) == 0) {
Adrian Roos37d7a682014-11-06 18:15:16 +01004127 outContentInsets.set(mCurLeft, mCurTop,
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07004128 availRight - mCurRight, availBottom - mCurBottom);
4129 } else {
Adrian Roos37d7a682014-11-06 18:15:16 +01004130 outContentInsets.set(mCurLeft, mCurTop,
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07004131 availRight - mCurRight, availBottom - mCurBottom);
4132 }
Adrian Roos37d7a682014-11-06 18:15:16 +01004133
4134 outStableInsets.set(mStableLeft, mStableTop,
4135 availRight - mStableRight, availBottom - mStableBottom);
Jorim Jaggi23bf5462016-05-13 15:24:39 -07004136 if (taskBounds != null) {
4137 calculateRelevantTaskInsets(taskBounds, outContentInsets,
4138 displayWidth, displayHeight);
4139 calculateRelevantTaskInsets(taskBounds, outStableInsets,
4140 displayWidth, displayHeight);
4141 }
Jorim Jaggi0ffd49c2016-02-12 15:04:21 -08004142 return mForceShowSystemBars;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004143 }
Adrian Roos37d7a682014-11-06 18:15:16 +01004144 outContentInsets.setEmpty();
4145 outStableInsets.setEmpty();
Jorim Jaggi0ffd49c2016-02-12 15:04:21 -08004146 return mForceShowSystemBars;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004147 }
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07004148
Jorim Jaggi23bf5462016-05-13 15:24:39 -07004149 /**
4150 * For any given task bounds, the insets relevant for these bounds given the insets relevant
4151 * for the entire display.
4152 */
4153 private void calculateRelevantTaskInsets(Rect taskBounds, Rect inOutInsets, int displayWidth,
4154 int displayHeight) {
4155 mTmpRect.set(0, 0, displayWidth, displayHeight);
4156 mTmpRect.inset(inOutInsets);
4157 mTmpRect.intersect(taskBounds);
4158 int leftInset = mTmpRect.left - taskBounds.left;
4159 int topInset = mTmpRect.top - taskBounds.top;
4160 int rightInset = taskBounds.right - mTmpRect.right;
4161 int bottomInset = taskBounds.bottom - mTmpRect.bottom;
4162 inOutInsets.set(leftInset, topInset, rightInset, bottomInset);
4163 }
4164
Filip Gruszczynski2987f612015-06-30 15:03:30 -07004165 private boolean shouldUseOutsets(WindowManager.LayoutParams attrs, int fl) {
4166 return attrs.type == TYPE_WALLPAPER || (fl & (WindowManager.LayoutParams.FLAG_FULLSCREEN
4167 | WindowManager.LayoutParams.FLAG_LAYOUT_IN_OVERSCAN)) != 0;
4168 }
4169
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004170 /** {@inheritDoc} */
Craig Mautner69b08182012-09-05 13:07:13 -07004171 @Override
4172 public void beginLayoutLw(boolean isDefaultDisplay, int displayWidth, int displayHeight,
Sriram Viswanathan9ebbe6a2015-11-16 17:59:22 -08004173 int displayRotation, int uiMode) {
Filip Gruszczynski2987f612015-06-30 15:03:30 -07004174 mDisplayRotation = displayRotation;
Dianne Hackbornc652de82013-02-15 16:32:56 -08004175 final int overscanLeft, overscanTop, overscanRight, overscanBottom;
4176 if (isDefaultDisplay) {
4177 switch (displayRotation) {
4178 case Surface.ROTATION_90:
4179 overscanLeft = mOverscanTop;
4180 overscanTop = mOverscanRight;
4181 overscanRight = mOverscanBottom;
4182 overscanBottom = mOverscanLeft;
4183 break;
4184 case Surface.ROTATION_180:
4185 overscanLeft = mOverscanRight;
4186 overscanTop = mOverscanBottom;
4187 overscanRight = mOverscanLeft;
4188 overscanBottom = mOverscanTop;
4189 break;
4190 case Surface.ROTATION_270:
4191 overscanLeft = mOverscanBottom;
4192 overscanTop = mOverscanLeft;
4193 overscanRight = mOverscanTop;
4194 overscanBottom = mOverscanRight;
4195 break;
4196 default:
4197 overscanLeft = mOverscanLeft;
4198 overscanTop = mOverscanTop;
4199 overscanRight = mOverscanRight;
4200 overscanBottom = mOverscanBottom;
4201 break;
4202 }
4203 } else {
4204 overscanLeft = 0;
4205 overscanTop = 0;
4206 overscanRight = 0;
4207 overscanBottom = 0;
4208 }
Dianne Hackborn313440842013-02-19 19:22:59 -08004209 mOverscanScreenLeft = mRestrictedOverscanScreenLeft = 0;
4210 mOverscanScreenTop = mRestrictedOverscanScreenTop = 0;
4211 mOverscanScreenWidth = mRestrictedOverscanScreenWidth = displayWidth;
4212 mOverscanScreenHeight = mRestrictedOverscanScreenHeight = displayHeight;
Dianne Hackbornc652de82013-02-15 16:32:56 -08004213 mSystemLeft = 0;
4214 mSystemTop = 0;
4215 mSystemRight = displayWidth;
4216 mSystemBottom = displayHeight;
4217 mUnrestrictedScreenLeft = overscanLeft;
4218 mUnrestrictedScreenTop = overscanTop;
4219 mUnrestrictedScreenWidth = displayWidth - overscanLeft - overscanRight;
4220 mUnrestrictedScreenHeight = displayHeight - overscanTop - overscanBottom;
4221 mRestrictedScreenLeft = mUnrestrictedScreenLeft;
4222 mRestrictedScreenTop = mUnrestrictedScreenTop;
John Spurlockad3e6cb2013-04-30 08:47:43 -04004223 mRestrictedScreenWidth = mSystemGestures.screenWidth = mUnrestrictedScreenWidth;
4224 mRestrictedScreenHeight = mSystemGestures.screenHeight = mUnrestrictedScreenHeight;
Dianne Hackborne30e02f2014-05-27 18:24:45 -07004225 mDockLeft = mContentLeft = mVoiceContentLeft = mStableLeft = mStableFullscreenLeft
Dianne Hackbornc652de82013-02-15 16:32:56 -08004226 = mCurLeft = mUnrestrictedScreenLeft;
Dianne Hackborne30e02f2014-05-27 18:24:45 -07004227 mDockTop = mContentTop = mVoiceContentTop = mStableTop = mStableFullscreenTop
Dianne Hackbornc652de82013-02-15 16:32:56 -08004228 = mCurTop = mUnrestrictedScreenTop;
Dianne Hackborne30e02f2014-05-27 18:24:45 -07004229 mDockRight = mContentRight = mVoiceContentRight = mStableRight = mStableFullscreenRight
Dianne Hackbornc652de82013-02-15 16:32:56 -08004230 = mCurRight = displayWidth - overscanRight;
Dianne Hackborne30e02f2014-05-27 18:24:45 -07004231 mDockBottom = mContentBottom = mVoiceContentBottom = mStableBottom = mStableFullscreenBottom
Dianne Hackbornc652de82013-02-15 16:32:56 -08004232 = mCurBottom = displayHeight - overscanBottom;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004233 mDockLayer = 0x10000000;
Dianne Hackborn5c58de32012-04-28 19:52:37 -07004234 mStatusBarLayer = -1;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004235
Daniel Sandler8956dbb2011-04-22 07:55:02 -04004236 // start with the current dock rect, which will be (0,0,displayWidth,displayHeight)
4237 final Rect pf = mTmpParentFrame;
4238 final Rect df = mTmpDisplayFrame;
Dianne Hackbornc4aad012013-02-22 15:05:25 -08004239 final Rect of = mTmpOverscanFrame;
Daniel Sandler8956dbb2011-04-22 07:55:02 -04004240 final Rect vf = mTmpVisibleFrame;
John Spurlock46646232013-09-30 22:32:42 -04004241 final Rect dcf = mTmpDecorFrame;
Dianne Hackbornc4aad012013-02-22 15:05:25 -08004242 pf.left = df.left = of.left = vf.left = mDockLeft;
4243 pf.top = df.top = of.top = vf.top = mDockTop;
4244 pf.right = df.right = of.right = vf.right = mDockRight;
4245 pf.bottom = df.bottom = of.bottom = vf.bottom = mDockBottom;
John Spurlock46646232013-09-30 22:32:42 -04004246 dcf.setEmpty(); // Decor frame N/A for system bars.
Daniel Sandler8956dbb2011-04-22 07:55:02 -04004247
Craig Mautner69b08182012-09-05 13:07:13 -07004248 if (isDefaultDisplay) {
4249 // For purposes of putting out fake window up to steal focus, we will
4250 // drive nav being hidden only by whether it is requested.
John Spurlocke1f366f2013-08-05 12:22:40 -04004251 final int sysui = mLastSystemUiFlags;
4252 boolean navVisible = (sysui & View.SYSTEM_UI_FLAG_HIDE_NAVIGATION) == 0;
Adrian Roosea562512014-05-05 13:33:03 +02004253 boolean navTranslucent = (sysui
Jorim Jaggi4fa78922015-11-30 17:13:56 -08004254 & (View.NAVIGATION_BAR_TRANSLUCENT | View.NAVIGATION_BAR_TRANSPARENT)) != 0;
John Spurlockf1a36642013-10-12 17:50:42 -04004255 boolean immersive = (sysui & View.SYSTEM_UI_FLAG_IMMERSIVE) != 0;
4256 boolean immersiveSticky = (sysui & View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY) != 0;
4257 boolean navAllowedHidden = immersive || immersiveSticky;
4258 navTranslucent &= !immersiveSticky; // transient trumps translucent
Jorim Jaggife762342016-10-13 14:33:27 +02004259 boolean isKeyguardShowing = isStatusBarKeyguard() && !mKeyguardOccluded;
Adrian Roos4fb3ee32014-08-22 19:29:09 +02004260 if (!isKeyguardShowing) {
4261 navTranslucent &= areTranslucentBarsAllowed();
4262 }
Jaewan Kim33284332016-05-12 18:55:46 +09004263 boolean statusBarExpandedNotKeyguard = !isKeyguardShowing && mStatusBar != null
Adrian Roosdb1bc6b2016-04-14 17:49:43 -07004264 && mStatusBar.getAttrs().height == MATCH_PARENT
4265 && mStatusBar.getAttrs().width == MATCH_PARENT;
Dianne Hackborne26ab702011-10-16 13:21:33 -07004266
Craig Mautner69b08182012-09-05 13:07:13 -07004267 // When the navigation bar isn't visible, we put up a fake
4268 // input window to catch all touch events. This way we can
4269 // detect when the user presses anywhere to bring back the nav
4270 // bar and ensure the application doesn't see the event.
John Spurlockf1a36642013-10-12 17:50:42 -04004271 if (navVisible || navAllowedHidden) {
Selim Cinekf83e8242015-05-19 18:08:14 -07004272 if (mInputConsumer != null) {
Chong Zhang9f7fb092016-05-20 17:03:08 -07004273 mHandler.sendMessage(
4274 mHandler.obtainMessage(MSG_DISPOSE_INPUT_CONSUMER, mInputConsumer));
Selim Cinekf83e8242015-05-19 18:08:14 -07004275 mInputConsumer = null;
Craig Mautner69b08182012-09-05 13:07:13 -07004276 }
Selim Cinekf83e8242015-05-19 18:08:14 -07004277 } else if (mInputConsumer == null) {
Winson41275482016-10-10 15:17:45 -07004278 mInputConsumer = mWindowManagerFuncs.createInputConsumer(mHandler.getLooper(),
4279 INPUT_CONSUMER_NAVIGATION,
4280 (channel, looper) -> new HideNavInputEventReceiver(channel, looper));
Dianne Hackborne26ab702011-10-16 13:21:33 -07004281 }
Dianne Hackborne26ab702011-10-16 13:21:33 -07004282
Craig Mautner69b08182012-09-05 13:07:13 -07004283 // For purposes of positioning and showing the nav bar, if we have
4284 // decided that it can't be hidden (because of the screen aspect ratio),
4285 // then take that into account.
Alan Viverette5a0f4ec2013-10-07 15:10:29 -07004286 navVisible |= !canHideNavigationBar();
Dianne Hackbornf87d1962012-04-04 12:48:24 -07004287
Filip Gruszczynski83dd9552015-09-17 17:50:36 -07004288 boolean updateSysUiVisibility = layoutNavigationBar(displayWidth, displayHeight,
Adrian Roos85d202b2016-06-02 16:27:47 -07004289 displayRotation, uiMode, overscanLeft, overscanRight, overscanBottom, dcf, navVisible, navTranslucent,
Adrian Roosdb1bc6b2016-04-14 17:49:43 -07004290 navAllowedHidden, statusBarExpandedNotKeyguard);
Craig Mautnereda67292013-04-28 13:50:14 -07004291 if (DEBUG_LAYOUT) Slog.i(TAG, String.format("mDock rect: (%d,%d - %d,%d)",
Craig Mautner69b08182012-09-05 13:07:13 -07004292 mDockLeft, mDockTop, mDockRight, mDockBottom));
Filip Gruszczynski83dd9552015-09-17 17:50:36 -07004293 updateSysUiVisibility |= layoutStatusBar(pf, df, of, vf, dcf, sysui, isKeyguardShowing);
John Spurlockad3e6cb2013-04-30 08:47:43 -04004294 if (updateSysUiVisibility) {
4295 updateSystemUiVisibilityLw();
4296 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004297 }
4298 }
4299
Filip Gruszczynski83dd9552015-09-17 17:50:36 -07004300 private boolean layoutStatusBar(Rect pf, Rect df, Rect of, Rect vf, Rect dcf, int sysui,
4301 boolean isKeyguardShowing) {
4302 // decide where the status bar goes ahead of time
4303 if (mStatusBar != null) {
4304 // apply any navigation bar insets
4305 pf.left = df.left = of.left = mUnrestrictedScreenLeft;
4306 pf.top = df.top = of.top = mUnrestrictedScreenTop;
4307 pf.right = df.right = of.right = mUnrestrictedScreenWidth + mUnrestrictedScreenLeft;
4308 pf.bottom = df.bottom = of.bottom = mUnrestrictedScreenHeight
4309 + mUnrestrictedScreenTop;
4310 vf.left = mStableLeft;
4311 vf.top = mStableTop;
4312 vf.right = mStableRight;
4313 vf.bottom = mStableBottom;
4314
4315 mStatusBarLayer = mStatusBar.getSurfaceLayer();
4316
4317 // Let the status bar determine its size.
4318 mStatusBar.computeFrameLw(pf /* parentFrame */, df /* displayFrame */,
4319 vf /* overlayFrame */, vf /* contentFrame */, vf /* visibleFrame */,
4320 dcf /* decorFrame */, vf /* stableFrame */, vf /* outsetFrame */);
4321
4322 // For layout, the status bar is always at the top with our fixed height.
4323 mStableTop = mUnrestrictedScreenTop + mStatusBarHeight;
4324
4325 boolean statusBarTransient = (sysui & View.STATUS_BAR_TRANSIENT) != 0;
4326 boolean statusBarTranslucent = (sysui
Jorim Jaggi4fa78922015-11-30 17:13:56 -08004327 & (View.STATUS_BAR_TRANSLUCENT | View.STATUS_BAR_TRANSPARENT)) != 0;
Filip Gruszczynski83dd9552015-09-17 17:50:36 -07004328 if (!isKeyguardShowing) {
4329 statusBarTranslucent &= areTranslucentBarsAllowed();
4330 }
4331
4332 // If the status bar is hidden, we don't want to cause
4333 // windows behind it to scroll.
4334 if (mStatusBar.isVisibleLw() && !statusBarTransient) {
4335 // Status bar may go away, so the screen area it occupies
4336 // is available to apps but just covering them when the
4337 // status bar is visible.
4338 mDockTop = mUnrestrictedScreenTop + mStatusBarHeight;
4339
4340 mContentTop = mVoiceContentTop = mCurTop = mDockTop;
4341 mContentBottom = mVoiceContentBottom = mCurBottom = mDockBottom;
4342 mContentLeft = mVoiceContentLeft = mCurLeft = mDockLeft;
4343 mContentRight = mVoiceContentRight = mCurRight = mDockRight;
4344
4345 if (DEBUG_LAYOUT) Slog.v(TAG, "Status bar: " +
4346 String.format(
4347 "dock=[%d,%d][%d,%d] content=[%d,%d][%d,%d] cur=[%d,%d][%d,%d]",
4348 mDockLeft, mDockTop, mDockRight, mDockBottom,
4349 mContentLeft, mContentTop, mContentRight, mContentBottom,
4350 mCurLeft, mCurTop, mCurRight, mCurBottom));
4351 }
4352 if (mStatusBar.isVisibleLw() && !mStatusBar.isAnimatingLw()
4353 && !statusBarTransient && !statusBarTranslucent
4354 && !mStatusBarController.wasRecentlyTranslucent()) {
4355 // If the opaque status bar is currently requested to be visible,
4356 // and not in the process of animating on or off, then
4357 // we can tell the app that it is covered by it.
4358 mSystemTop = mUnrestrictedScreenTop + mStatusBarHeight;
4359 }
4360 if (mStatusBarController.checkHiddenLw()) {
4361 return true;
4362 }
4363 }
4364 return false;
4365 }
4366
4367 private boolean layoutNavigationBar(int displayWidth, int displayHeight, int displayRotation,
Adrian Roos85d202b2016-06-02 16:27:47 -07004368 int uiMode, int overscanLeft, int overscanRight, int overscanBottom, Rect dcf,
4369 boolean navVisible, boolean navTranslucent, boolean navAllowedHidden,
Adrian Roosdb1bc6b2016-04-14 17:49:43 -07004370 boolean statusBarExpandedNotKeyguard) {
Filip Gruszczynski83dd9552015-09-17 17:50:36 -07004371 if (mNavigationBar != null) {
4372 boolean transientNavBarShowing = mNavigationBarController.isTransientShowing();
4373 // Force the navigation bar to its appropriate place and
4374 // size. We need to do this directly, instead of relying on
4375 // it to bubble up from the nav bar, because this needs to
4376 // change atomically with screen rotations.
Adrian Roos85d202b2016-06-02 16:27:47 -07004377 mNavigationBarPosition = navigationBarPosition(displayWidth, displayHeight,
4378 displayRotation);
4379 if (mNavigationBarPosition == NAV_BAR_BOTTOM) {
Filip Gruszczynski83dd9552015-09-17 17:50:36 -07004380 // It's a system nav bar or a portrait screen; nav bar goes on bottom.
4381 int top = displayHeight - overscanBottom
Sriram Viswanathan9ebbe6a2015-11-16 17:59:22 -08004382 - getNavigationBarHeight(displayRotation, uiMode);
Filip Gruszczynski83dd9552015-09-17 17:50:36 -07004383 mTmpNavigationFrame.set(0, top, displayWidth, displayHeight - overscanBottom);
4384 mStableBottom = mStableFullscreenBottom = mTmpNavigationFrame.top;
4385 if (transientNavBarShowing) {
4386 mNavigationBarController.setBarShowingLw(true);
4387 } else if (navVisible) {
4388 mNavigationBarController.setBarShowingLw(true);
4389 mDockBottom = mTmpNavigationFrame.top;
4390 mRestrictedScreenHeight = mDockBottom - mRestrictedScreenTop;
4391 mRestrictedOverscanScreenHeight = mDockBottom - mRestrictedOverscanScreenTop;
4392 } else {
Adrian Roosdb1bc6b2016-04-14 17:49:43 -07004393 // We currently want to hide the navigation UI - unless we expanded the status
4394 // bar.
4395 mNavigationBarController.setBarShowingLw(statusBarExpandedNotKeyguard);
Filip Gruszczynski83dd9552015-09-17 17:50:36 -07004396 }
4397 if (navVisible && !navTranslucent && !navAllowedHidden
4398 && !mNavigationBar.isAnimatingLw()
4399 && !mNavigationBarController.wasRecentlyTranslucent()) {
4400 // If the opaque nav bar is currently requested to be visible,
4401 // and not in the process of animating on or off, then
4402 // we can tell the app that it is covered by it.
4403 mSystemBottom = mTmpNavigationFrame.top;
4404 }
Adrian Roos85d202b2016-06-02 16:27:47 -07004405 } else if (mNavigationBarPosition == NAV_BAR_RIGHT) {
Filip Gruszczynski83dd9552015-09-17 17:50:36 -07004406 // Landscape screen; nav bar goes to the right.
4407 int left = displayWidth - overscanRight
Sriram Viswanathan9ebbe6a2015-11-16 17:59:22 -08004408 - getNavigationBarWidth(displayRotation, uiMode);
Filip Gruszczynski83dd9552015-09-17 17:50:36 -07004409 mTmpNavigationFrame.set(left, 0, displayWidth - overscanRight, displayHeight);
4410 mStableRight = mStableFullscreenRight = mTmpNavigationFrame.left;
4411 if (transientNavBarShowing) {
4412 mNavigationBarController.setBarShowingLw(true);
4413 } else if (navVisible) {
4414 mNavigationBarController.setBarShowingLw(true);
4415 mDockRight = mTmpNavigationFrame.left;
4416 mRestrictedScreenWidth = mDockRight - mRestrictedScreenLeft;
4417 mRestrictedOverscanScreenWidth = mDockRight - mRestrictedOverscanScreenLeft;
4418 } else {
Adrian Roosdb1bc6b2016-04-14 17:49:43 -07004419 // We currently want to hide the navigation UI - unless we expanded the status
4420 // bar.
4421 mNavigationBarController.setBarShowingLw(statusBarExpandedNotKeyguard);
Filip Gruszczynski83dd9552015-09-17 17:50:36 -07004422 }
4423 if (navVisible && !navTranslucent && !navAllowedHidden
4424 && !mNavigationBar.isAnimatingLw()
4425 && !mNavigationBarController.wasRecentlyTranslucent()) {
4426 // If the nav bar is currently requested to be visible,
4427 // and not in the process of animating on or off, then
4428 // we can tell the app that it is covered by it.
4429 mSystemRight = mTmpNavigationFrame.left;
4430 }
Adrian Roos85d202b2016-06-02 16:27:47 -07004431 } else if (mNavigationBarPosition == NAV_BAR_LEFT) {
4432 // Seascape screen; nav bar goes to the left.
4433 int right = overscanLeft + getNavigationBarWidth(displayRotation, uiMode);
4434 mTmpNavigationFrame.set(overscanLeft, 0, right, displayHeight);
4435 mStableLeft = mStableFullscreenLeft = mTmpNavigationFrame.right;
4436 if (transientNavBarShowing) {
4437 mNavigationBarController.setBarShowingLw(true);
4438 } else if (navVisible) {
4439 mNavigationBarController.setBarShowingLw(true);
4440 mDockLeft = mTmpNavigationFrame.right;
4441 // TODO: not so sure about those:
4442 mRestrictedScreenLeft = mRestrictedOverscanScreenLeft = mDockLeft;
4443 mRestrictedScreenWidth = mDockRight - mRestrictedScreenLeft;
4444 mRestrictedOverscanScreenWidth = mDockRight - mRestrictedOverscanScreenLeft;
4445 } else {
4446 // We currently want to hide the navigation UI - unless we expanded the status
4447 // bar.
4448 mNavigationBarController.setBarShowingLw(statusBarExpandedNotKeyguard);
4449 }
4450 if (navVisible && !navTranslucent && !navAllowedHidden
4451 && !mNavigationBar.isAnimatingLw()
4452 && !mNavigationBarController.wasRecentlyTranslucent()) {
4453 // If the nav bar is currently requested to be visible,
4454 // and not in the process of animating on or off, then
4455 // we can tell the app that it is covered by it.
4456 mSystemLeft = mTmpNavigationFrame.right;
4457 }
Filip Gruszczynski83dd9552015-09-17 17:50:36 -07004458 }
4459 // Make sure the content and current rectangles are updated to
4460 // account for the restrictions from the navigation bar.
4461 mContentTop = mVoiceContentTop = mCurTop = mDockTop;
4462 mContentBottom = mVoiceContentBottom = mCurBottom = mDockBottom;
4463 mContentLeft = mVoiceContentLeft = mCurLeft = mDockLeft;
4464 mContentRight = mVoiceContentRight = mCurRight = mDockRight;
4465 mStatusBarLayer = mNavigationBar.getSurfaceLayer();
4466 // And compute the final frame.
4467 mNavigationBar.computeFrameLw(mTmpNavigationFrame, mTmpNavigationFrame,
4468 mTmpNavigationFrame, mTmpNavigationFrame, mTmpNavigationFrame, dcf,
4469 mTmpNavigationFrame, mTmpNavigationFrame);
4470 if (DEBUG_LAYOUT) Slog.i(TAG, "mNavigationBar frame: " + mTmpNavigationFrame);
4471 if (mNavigationBarController.checkHiddenLw()) {
4472 return true;
4473 }
4474 }
4475 return false;
4476 }
4477
Adrian Roos85d202b2016-06-02 16:27:47 -07004478 private int navigationBarPosition(int displayWidth, int displayHeight, int displayRotation) {
4479 if (mNavigationBarCanMove && displayWidth > displayHeight) {
4480 if (displayRotation == Surface.ROTATION_270) {
4481 return NAV_BAR_LEFT;
4482 } else {
4483 return NAV_BAR_RIGHT;
4484 }
4485 }
4486 return NAV_BAR_BOTTOM;
Jorim Jaggi737af722015-12-31 10:42:27 +01004487 }
4488
Dianne Hackborn85afd1b2012-05-13 13:31:06 -07004489 /** {@inheritDoc} */
Craig Mautner967212c2013-04-13 21:10:58 -07004490 @Override
John Spurlock46646232013-09-30 22:32:42 -04004491 public int getSystemDecorLayerLw() {
Bryce Lee2ed3e5f2015-04-01 22:09:19 +00004492 if (mStatusBar != null && mStatusBar.isVisibleLw()) {
4493 return mStatusBar.getSurfaceLayer();
4494 }
4495
4496 if (mNavigationBar != null && mNavigationBar.isVisibleLw()) {
4497 return mNavigationBar.getSurfaceLayer();
4498 }
4499
Dianne Hackborn85afd1b2012-05-13 13:31:06 -07004500 return 0;
4501 }
4502
Craig Mautner967212c2013-04-13 21:10:58 -07004503 @Override
4504 public void getContentRectLw(Rect r) {
4505 r.set(mContentLeft, mContentTop, mContentRight, mContentBottom);
4506 }
4507
Dianne Hackbornc4aad012013-02-22 15:05:25 -08004508 void setAttachedWindowFrames(WindowState win, int fl, int adjust, WindowState attached,
4509 boolean insetDecors, Rect pf, Rect df, Rect of, Rect cf, Rect vf) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004510 if (win.getSurfaceLayer() > mDockLayer && attached.getSurfaceLayer() < mDockLayer) {
4511 // Here's a special case: if this attached window is a panel that is
4512 // above the dock window, and the window it is attached to is below
4513 // the dock window, then the frames we computed for the window it is
4514 // attached to can not be used because the dock is effectively part
4515 // of the underlying window and the attached window is floating on top
4516 // of the whole thing. So, we ignore the attached window and explicitly
4517 // compute the frames that would be appropriate without the dock.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08004518 df.left = of.left = cf.left = vf.left = mDockLeft;
4519 df.top = of.top = cf.top = vf.top = mDockTop;
4520 df.right = of.right = cf.right = vf.right = mDockRight;
4521 df.bottom = of.bottom = cf.bottom = vf.bottom = mDockBottom;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004522 } else {
4523 // The effective display frame of the attached window depends on
4524 // whether it is taking care of insetting its content. If not,
4525 // we need to use the parent's content frame so that the entire
4526 // window is positioned within that content. Otherwise we can use
Wale Ogunwale393b1c12014-10-18 16:22:01 -07004527 // the overscan frame and let the attached window take care of
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004528 // positioning its content appropriately.
Dianne Hackborndea3ef72010-10-28 14:24:22 -07004529 if (adjust != SOFT_INPUT_ADJUST_RESIZE) {
Wale Ogunwale393b1c12014-10-18 16:22:01 -07004530 // Set the content frame of the attached window to the parent's decor frame
4531 // (same as content frame when IME isn't present) if specifically requested by
4532 // setting {@link WindowManager.LayoutParams#FLAG_LAYOUT_ATTACHED_IN_DECOR} flag.
4533 // Otherwise, use the overscan frame.
4534 cf.set((fl & FLAG_LAYOUT_ATTACHED_IN_DECOR) != 0
4535 ? attached.getContentFrameLw() : attached.getOverscanFrameLw());
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004536 } else {
4537 // If the window is resizing, then we want to base the content
4538 // frame on our attached content frame to resize... however,
4539 // things can be tricky if the attached window is NOT in resize
4540 // mode, in which case its content frame will be larger.
4541 // Ungh. So to deal with that, make sure the content frame
4542 // we end up using is not covering the IM dock.
4543 cf.set(attached.getContentFrameLw());
Dianne Hackborne30e02f2014-05-27 18:24:45 -07004544 if (attached.isVoiceInteraction()) {
4545 if (cf.left < mVoiceContentLeft) cf.left = mVoiceContentLeft;
4546 if (cf.top < mVoiceContentTop) cf.top = mVoiceContentTop;
4547 if (cf.right > mVoiceContentRight) cf.right = mVoiceContentRight;
4548 if (cf.bottom > mVoiceContentBottom) cf.bottom = mVoiceContentBottom;
4549 } else if (attached.getSurfaceLayer() < mDockLayer) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004550 if (cf.left < mContentLeft) cf.left = mContentLeft;
4551 if (cf.top < mContentTop) cf.top = mContentTop;
4552 if (cf.right > mContentRight) cf.right = mContentRight;
4553 if (cf.bottom > mContentBottom) cf.bottom = mContentBottom;
4554 }
4555 }
4556 df.set(insetDecors ? attached.getDisplayFrameLw() : cf);
Dianne Hackbornc4aad012013-02-22 15:05:25 -08004557 of.set(insetDecors ? attached.getOverscanFrameLw() : cf);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004558 vf.set(attached.getVisibleFrameLw());
4559 }
4560 // The LAYOUT_IN_SCREEN flag is used to determine whether the attached
4561 // window should be positioned relative to its parent or the entire
4562 // screen.
4563 pf.set((fl & FLAG_LAYOUT_IN_SCREEN) == 0
4564 ? attached.getFrameLw() : df);
4565 }
Dianne Hackborn5b5cc4d2012-05-16 13:15:00 -07004566
4567 private void applyStableConstraints(int sysui, int fl, Rect r) {
4568 if ((sysui & View.SYSTEM_UI_FLAG_LAYOUT_STABLE) != 0) {
4569 // If app is requesting a stable layout, don't let the
4570 // content insets go below the stable values.
4571 if ((fl & FLAG_FULLSCREEN) != 0) {
4572 if (r.left < mStableFullscreenLeft) r.left = mStableFullscreenLeft;
4573 if (r.top < mStableFullscreenTop) r.top = mStableFullscreenTop;
4574 if (r.right > mStableFullscreenRight) r.right = mStableFullscreenRight;
4575 if (r.bottom > mStableFullscreenBottom) r.bottom = mStableFullscreenBottom;
4576 } else {
4577 if (r.left < mStableLeft) r.left = mStableLeft;
4578 if (r.top < mStableTop) r.top = mStableTop;
4579 if (r.right > mStableRight) r.right = mStableRight;
4580 if (r.bottom > mStableBottom) r.bottom = mStableBottom;
4581 }
4582 }
4583 }
4584
Jorim Jaggiaa806142015-05-20 18:04:16 -07004585 private boolean canReceiveInput(WindowState win) {
4586 boolean notFocusable =
4587 (win.getAttrs().flags & WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE) != 0;
4588 boolean altFocusableIm =
4589 (win.getAttrs().flags & WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM) != 0;
4590 boolean notFocusableForIm = notFocusable ^ altFocusableIm;
4591 return !notFocusableForIm;
4592 }
4593
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004594 /** {@inheritDoc} */
Craig Mautner69b08182012-09-05 13:07:13 -07004595 @Override
Craig Mautnerc9457fa2014-06-06 14:27:48 -07004596 public void layoutWindowLw(WindowState win, WindowState attached) {
Jorim Jaggiaa806142015-05-20 18:04:16 -07004597 // We've already done the navigation bar and status bar. If the status bar can receive
4598 // input, we need to layout it again to accomodate for the IME window.
4599 if ((win == mStatusBar && !canReceiveInput(win)) || win == mNavigationBar) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004600 return;
4601 }
Jorim Jaggiaa806142015-05-20 18:04:16 -07004602 final WindowManager.LayoutParams attrs = win.getAttrs();
Craig Mautner69b08182012-09-05 13:07:13 -07004603 final boolean isDefaultDisplay = win.isDefaultDisplay();
4604 final boolean needsToOffsetInputMethodTarget = isDefaultDisplay &&
satok1bc0a492012-04-25 22:47:12 +09004605 (win == mLastInputMethodTargetWindow && mLastInputMethodWindow != null);
4606 if (needsToOffsetInputMethodTarget) {
Craig Mautnereda67292013-04-28 13:50:14 -07004607 if (DEBUG_LAYOUT) Slog.i(TAG, "Offset ime target window by the last ime window state");
satok1bc0a492012-04-25 22:47:12 +09004608 offsetInputMethodWindowLw(mLastInputMethodWindow);
4609 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004610
John Spurlockc6d1c602014-01-17 15:22:06 -05004611 final int fl = PolicyControl.getWindowFlags(win, attrs);
Jorim Jaggi8f5701b2016-04-04 18:36:02 -07004612 final int pfl = attrs.privateFlags;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004613 final int sim = attrs.softInputMode;
John Spurlock1db8b682014-02-18 11:18:59 -05004614 final int sysUiFl = PolicyControl.getSystemUiVisibility(win, null);
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07004615
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004616 final Rect pf = mTmpParentFrame;
4617 final Rect df = mTmpDisplayFrame;
Dianne Hackbornc4aad012013-02-22 15:05:25 -08004618 final Rect of = mTmpOverscanFrame;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004619 final Rect cf = mTmpContentFrame;
4620 final Rect vf = mTmpVisibleFrame;
John Spurlock46646232013-09-30 22:32:42 -04004621 final Rect dcf = mTmpDecorFrame;
Adrian Roosfa104232014-06-20 16:10:14 -07004622 final Rect sf = mTmpStableFrame;
Filip Gruszczynski2217f612015-05-26 11:32:08 -07004623 Rect osf = null;
John Spurlock46646232013-09-30 22:32:42 -04004624 dcf.setEmpty();
Craig Mautner69b08182012-09-05 13:07:13 -07004625
4626 final boolean hasNavBar = (isDefaultDisplay && mHasNavigationBar
Daniel Sandler36412a72011-08-04 09:35:13 -04004627 && mNavigationBar != null && mNavigationBar.isVisibleLw());
Daniel Sandler8956dbb2011-04-22 07:55:02 -04004628
Craig Mautnerf683b562012-10-02 11:10:57 -07004629 final int adjust = sim & SOFT_INPUT_MASK_ADJUST;
4630
Adrian Roosfa104232014-06-20 16:10:14 -07004631 if (isDefaultDisplay) {
4632 sf.set(mStableLeft, mStableTop, mStableRight, mStableBottom);
4633 } else {
4634 sf.set(mOverscanLeft, mOverscanTop, mOverscanRight, mOverscanBottom);
4635 }
4636
Craig Mautner69b08182012-09-05 13:07:13 -07004637 if (!isDefaultDisplay) {
4638 if (attached != null) {
4639 // If this window is attached to another, our display
4640 // frame is the same as the one we are attached to.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08004641 setAttachedWindowFrames(win, fl, adjust, attached, true, pf, df, of, cf, vf);
Craig Mautner69b08182012-09-05 13:07:13 -07004642 } else {
4643 // Give the window full screen.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08004644 pf.left = df.left = of.left = cf.left = mOverscanScreenLeft;
4645 pf.top = df.top = of.top = cf.top = mOverscanScreenTop;
4646 pf.right = df.right = of.right = cf.right
Dianne Hackbornc652de82013-02-15 16:32:56 -08004647 = mOverscanScreenLeft + mOverscanScreenWidth;
Dianne Hackbornc4aad012013-02-22 15:05:25 -08004648 pf.bottom = df.bottom = of.bottom = cf.bottom
Dianne Hackbornc652de82013-02-15 16:32:56 -08004649 = mOverscanScreenTop + mOverscanScreenHeight;
Craig Mautner69b08182012-09-05 13:07:13 -07004650 }
Jorim Jaggi225d3b52015-04-01 11:18:57 -07004651 } else if (attrs.type == TYPE_INPUT_METHOD) {
Dianne Hackbornc4aad012013-02-22 15:05:25 -08004652 pf.left = df.left = of.left = cf.left = vf.left = mDockLeft;
4653 pf.top = df.top = of.top = cf.top = vf.top = mDockTop;
4654 pf.right = df.right = of.right = cf.right = vf.right = mDockRight;
John Spurlockc68d5772013-10-08 11:47:58 -04004655 // IM dock windows layout below the nav bar...
John Spurlock57beb3b2013-10-10 10:27:44 -04004656 pf.bottom = df.bottom = of.bottom = mUnrestrictedScreenTop + mUnrestrictedScreenHeight;
John Spurlockc68d5772013-10-08 11:47:58 -04004657 // ...with content insets above the nav bar
4658 cf.bottom = vf.bottom = mStableBottom;
Adrian Roosdd654ea2016-05-27 11:46:10 -07004659 if (mStatusBar != null && mFocusedWindow == mStatusBar && canReceiveInput(mStatusBar)) {
4660 // The status bar forces the navigation bar while it's visible. Make sure the IME
4661 // avoids the navigation bar in that case.
Adrian Roos85d202b2016-06-02 16:27:47 -07004662 if (mNavigationBarPosition == NAV_BAR_RIGHT) {
4663 pf.right = df.right = of.right = cf.right = vf.right = mStableRight;
4664 } else if (mNavigationBarPosition == NAV_BAR_LEFT) {
4665 pf.left = df.left = of.left = cf.left = vf.left = mStableLeft;
4666 }
Adrian Roosdd654ea2016-05-27 11:46:10 -07004667 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004668 // IM dock windows always go to the bottom of the screen.
4669 attrs.gravity = Gravity.BOTTOM;
4670 mDockLayer = win.getSurfaceLayer();
Jorim Jaggi225d3b52015-04-01 11:18:57 -07004671 } else if (attrs.type == TYPE_VOICE_INTERACTION) {
Stefan Kuhne2f280d062015-06-18 07:20:33 -10004672 pf.left = df.left = of.left = mUnrestrictedScreenLeft;
Jorim Jaggi225d3b52015-04-01 11:18:57 -07004673 pf.top = df.top = of.top = mUnrestrictedScreenTop;
Stefan Kuhne2f280d062015-06-18 07:20:33 -10004674 pf.right = df.right = of.right = mUnrestrictedScreenLeft + mUnrestrictedScreenWidth;
4675 pf.bottom = df.bottom = of.bottom = mUnrestrictedScreenTop + mUnrestrictedScreenHeight;
Jorim Jaggi4b74f4d2016-04-27 18:44:08 -07004676 if (adjust != SOFT_INPUT_ADJUST_RESIZE) {
4677 cf.left = mDockLeft;
4678 cf.top = mDockTop;
4679 cf.right = mDockRight;
4680 cf.bottom = mDockBottom;
4681 } else {
4682 cf.left = mContentLeft;
4683 cf.top = mContentTop;
4684 cf.right = mContentRight;
4685 cf.bottom = mContentBottom;
4686 }
4687 if (adjust != SOFT_INPUT_ADJUST_NOTHING) {
4688 vf.left = mCurLeft;
4689 vf.top = mCurTop;
4690 vf.right = mCurRight;
4691 vf.bottom = mCurBottom;
4692 } else {
4693 vf.set(cf);
4694 }
Jorim Jaggi526505d2016-05-24 00:29:19 -07004695 } else if (attrs.type == TYPE_WALLPAPER) {
4696 layoutWallpaper(win, pf, df, of, cf);
Jorim Jaggiaa806142015-05-20 18:04:16 -07004697 } else if (win == mStatusBar) {
Jorim Jaggie0700182014-08-21 01:12:37 +02004698 pf.left = df.left = of.left = mUnrestrictedScreenLeft;
4699 pf.top = df.top = of.top = mUnrestrictedScreenTop;
4700 pf.right = df.right = of.right = mUnrestrictedScreenWidth + mUnrestrictedScreenLeft;
4701 pf.bottom = df.bottom = of.bottom = mUnrestrictedScreenHeight + mUnrestrictedScreenTop;
4702 cf.left = vf.left = mStableLeft;
4703 cf.top = vf.top = mStableTop;
4704 cf.right = vf.right = mStableRight;
4705 vf.bottom = mStableBottom;
Adrian Roosdc5b4532016-01-06 20:49:41 +01004706
4707 if (adjust == SOFT_INPUT_ADJUST_RESIZE) {
4708 cf.bottom = mContentBottom;
4709 } else {
4710 cf.bottom = mDockBottom;
4711 vf.bottom = mContentBottom;
4712 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004713 } else {
John Spurlock46646232013-09-30 22:32:42 -04004714
4715 // Default policy decor for the default display
4716 dcf.left = mSystemLeft;
4717 dcf.top = mSystemTop;
4718 dcf.right = mSystemRight;
4719 dcf.bottom = mSystemBottom;
John Spurlockbd957402013-10-03 11:38:39 -04004720 final boolean inheritTranslucentDecor = (attrs.privateFlags
4721 & WindowManager.LayoutParams.PRIVATE_FLAG_INHERIT_TRANSLUCENT_DECOR) != 0;
John Spurlock65567d42013-10-08 10:08:32 -04004722 final boolean isAppWindow =
4723 attrs.type >= WindowManager.LayoutParams.FIRST_APPLICATION_WINDOW &&
4724 attrs.type <= WindowManager.LayoutParams.LAST_APPLICATION_WINDOW;
4725 final boolean topAtRest =
4726 win == mTopFullscreenOpaqueWindowState && !win.isAnimatingLw();
4727 if (isAppWindow && !inheritTranslucentDecor && !topAtRest) {
John Spurlockbd957402013-10-03 11:38:39 -04004728 if ((sysUiFl & View.SYSTEM_UI_FLAG_FULLSCREEN) == 0
4729 && (fl & WindowManager.LayoutParams.FLAG_FULLSCREEN) == 0
Adrian Roosea562512014-05-05 13:33:03 +02004730 && (fl & WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS) == 0
4731 && (fl & WindowManager.LayoutParams.
Jorim Jaggi4fa78922015-11-30 17:13:56 -08004732 FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS) == 0
Jorim Jaggi8f5701b2016-04-04 18:36:02 -07004733 && (pfl & PRIVATE_FLAG_FORCE_DRAW_STATUS_BAR_BACKGROUND) == 0) {
John Spurlock46646232013-09-30 22:32:42 -04004734 // Ensure policy decor includes status bar
4735 dcf.top = mStableTop;
4736 }
John Spurlockbd957402013-10-03 11:38:39 -04004737 if ((fl & WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION) == 0
Adrian Roosea562512014-05-05 13:33:03 +02004738 && (sysUiFl & View.SYSTEM_UI_FLAG_HIDE_NAVIGATION) == 0
4739 && (fl & WindowManager.LayoutParams.
4740 FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS) == 0) {
John Spurlock46646232013-09-30 22:32:42 -04004741 // Ensure policy decor includes navigation bar
4742 dcf.bottom = mStableBottom;
4743 dcf.right = mStableRight;
4744 }
4745 }
4746
Dianne Hackbornc4aad012013-02-22 15:05:25 -08004747 if ((fl & (FLAG_LAYOUT_IN_SCREEN | FLAG_LAYOUT_INSET_DECOR))
4748 == (FLAG_LAYOUT_IN_SCREEN | FLAG_LAYOUT_INSET_DECOR)) {
RoboErik8a2cfc32014-05-16 11:19:38 -07004749 if (DEBUG_LAYOUT) Slog.v(TAG, "layoutWindowLw(" + attrs.getTitle()
Dianne Hackbornc4aad012013-02-22 15:05:25 -08004750 + "): IN_SCREEN, INSET_DECOR");
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004751 // This is the case for a normal activity window: we want it
4752 // to cover all of the screen space, and it can take care of
4753 // moving its contents to account for screen decorations that
4754 // intrude into that space.
4755 if (attached != null) {
4756 // If this window is attached to another, our display
4757 // frame is the same as the one we are attached to.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08004758 setAttachedWindowFrames(win, fl, adjust, attached, true, pf, df, of, cf, vf);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004759 } else {
Daniel Sandler8956dbb2011-04-22 07:55:02 -04004760 if (attrs.type == TYPE_STATUS_BAR_PANEL
4761 || attrs.type == TYPE_STATUS_BAR_SUB_PANEL) {
Joe Onorato29fc2c92010-11-24 10:26:50 -08004762 // Status bar panels are the only windows who can go on top of
4763 // the status bar. They are protected by the STATUS_BAR_SERVICE
4764 // permission, so they have the same privileges as the status
4765 // bar itself.
Daniel Sandler8956dbb2011-04-22 07:55:02 -04004766 //
Daniel Sandler8e8b4152011-07-21 01:16:43 -04004767 // However, they should still dodge the navigation bar if it exists.
Daniel Sandler8956dbb2011-04-22 07:55:02 -04004768
Dianne Hackbornc4aad012013-02-22 15:05:25 -08004769 pf.left = df.left = of.left = hasNavBar
4770 ? mDockLeft : mUnrestrictedScreenLeft;
4771 pf.top = df.top = of.top = mUnrestrictedScreenTop;
4772 pf.right = df.right = of.right = hasNavBar
4773 ? mRestrictedScreenLeft+mRestrictedScreenWidth
4774 : mUnrestrictedScreenLeft + mUnrestrictedScreenWidth;
4775 pf.bottom = df.bottom = of.bottom = hasNavBar
4776 ? mRestrictedScreenTop+mRestrictedScreenHeight
4777 : mUnrestrictedScreenTop + mUnrestrictedScreenHeight;
Daniel Sandler8956dbb2011-04-22 07:55:02 -04004778
Craig Mautnereda67292013-04-28 13:50:14 -07004779 if (DEBUG_LAYOUT) Slog.v(TAG, String.format(
Daniel Sandler8e8b4152011-07-21 01:16:43 -04004780 "Laying out status bar window: (%d,%d - %d,%d)",
4781 pf.left, pf.top, pf.right, pf.bottom));
John Spurlock46646232013-09-30 22:32:42 -04004782 } else if ((fl & FLAG_LAYOUT_IN_OVERSCAN) != 0
Dianne Hackbornc652de82013-02-15 16:32:56 -08004783 && attrs.type >= WindowManager.LayoutParams.FIRST_APPLICATION_WINDOW
4784 && attrs.type <= WindowManager.LayoutParams.LAST_SUB_WINDOW) {
4785 // Asking to layout into the overscan region, so give it that pure
4786 // unrestricted area.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08004787 pf.left = df.left = of.left = mOverscanScreenLeft;
4788 pf.top = df.top = of.top = mOverscanScreenTop;
4789 pf.right = df.right = of.right = mOverscanScreenLeft + mOverscanScreenWidth;
4790 pf.bottom = df.bottom = of.bottom = mOverscanScreenTop
4791 + mOverscanScreenHeight;
Alan Viverette5a0f4ec2013-10-07 15:10:29 -07004792 } else if (canHideNavigationBar()
Dianne Hackbornf87d1962012-04-04 12:48:24 -07004793 && (sysUiFl & View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION) != 0
Jorim Jaggi380ecb82014-03-14 17:25:20 +01004794 && attrs.type >= WindowManager.LayoutParams.FIRST_APPLICATION_WINDOW
4795 && attrs.type <= WindowManager.LayoutParams.LAST_SUB_WINDOW) {
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07004796 // Asking for layout as if the nav bar is hidden, lets the
Dianne Hackbornc652de82013-02-15 16:32:56 -08004797 // application extend into the unrestricted overscan screen area. We
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07004798 // only do this for application windows to ensure no window that
4799 // can be above the nav bar can do this.
Dianne Hackborn313440842013-02-19 19:22:59 -08004800 pf.left = df.left = mOverscanScreenLeft;
4801 pf.top = df.top = mOverscanScreenTop;
4802 pf.right = df.right = mOverscanScreenLeft + mOverscanScreenWidth;
4803 pf.bottom = df.bottom = mOverscanScreenTop + mOverscanScreenHeight;
Dianne Hackbornc4aad012013-02-22 15:05:25 -08004804 // We need to tell the app about where the frame inside the overscan
4805 // is, so it can inset its content by that amount -- it didn't ask
4806 // to actually extend itself into the overscan region.
4807 of.left = mUnrestrictedScreenLeft;
4808 of.top = mUnrestrictedScreenTop;
4809 of.right = mUnrestrictedScreenLeft + mUnrestrictedScreenWidth;
4810 of.bottom = mUnrestrictedScreenTop + mUnrestrictedScreenHeight;
Joe Onorato29fc2c92010-11-24 10:26:50 -08004811 } else {
Dianne Hackborn313440842013-02-19 19:22:59 -08004812 pf.left = df.left = mRestrictedOverscanScreenLeft;
4813 pf.top = df.top = mRestrictedOverscanScreenTop;
4814 pf.right = df.right = mRestrictedOverscanScreenLeft
4815 + mRestrictedOverscanScreenWidth;
4816 pf.bottom = df.bottom = mRestrictedOverscanScreenTop
4817 + mRestrictedOverscanScreenHeight;
Dianne Hackbornc4aad012013-02-22 15:05:25 -08004818 // We need to tell the app about where the frame inside the overscan
4819 // is, so it can inset its content by that amount -- it didn't ask
4820 // to actually extend itself into the overscan region.
4821 of.left = mUnrestrictedScreenLeft;
4822 of.top = mUnrestrictedScreenTop;
4823 of.right = mUnrestrictedScreenLeft + mUnrestrictedScreenWidth;
4824 of.bottom = mUnrestrictedScreenTop + mUnrestrictedScreenHeight;
Joe Onorato29fc2c92010-11-24 10:26:50 -08004825 }
Craig Mautner69b08182012-09-05 13:07:13 -07004826
John Spurlock46646232013-09-30 22:32:42 -04004827 if ((fl & FLAG_FULLSCREEN) == 0) {
Dianne Hackborne30e02f2014-05-27 18:24:45 -07004828 if (win.isVoiceInteraction()) {
4829 cf.left = mVoiceContentLeft;
4830 cf.top = mVoiceContentTop;
4831 cf.right = mVoiceContentRight;
4832 cf.bottom = mVoiceContentBottom;
Dianne Hackbornc4aad012013-02-22 15:05:25 -08004833 } else {
Dianne Hackborne30e02f2014-05-27 18:24:45 -07004834 if (adjust != SOFT_INPUT_ADJUST_RESIZE) {
4835 cf.left = mDockLeft;
4836 cf.top = mDockTop;
4837 cf.right = mDockRight;
4838 cf.bottom = mDockBottom;
4839 } else {
4840 cf.left = mContentLeft;
4841 cf.top = mContentTop;
4842 cf.right = mContentRight;
4843 cf.bottom = mContentBottom;
4844 }
Dianne Hackbornc4aad012013-02-22 15:05:25 -08004845 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004846 } else {
Dianne Hackbornc4aad012013-02-22 15:05:25 -08004847 // Full screen windows are always given a layout that is as if the
4848 // status bar and other transient decors are gone. This is to avoid
4849 // bad states when moving from a window that is not hding the
4850 // status bar to one that is.
4851 cf.left = mRestrictedScreenLeft;
4852 cf.top = mRestrictedScreenTop;
4853 cf.right = mRestrictedScreenLeft + mRestrictedScreenWidth;
4854 cf.bottom = mRestrictedScreenTop + mRestrictedScreenHeight;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004855 }
Dianne Hackborn5b5cc4d2012-05-16 13:15:00 -07004856 applyStableConstraints(sysUiFl, fl, cf);
Dianne Hackborndea3ef72010-10-28 14:24:22 -07004857 if (adjust != SOFT_INPUT_ADJUST_NOTHING) {
4858 vf.left = mCurLeft;
4859 vf.top = mCurTop;
4860 vf.right = mCurRight;
4861 vf.bottom = mCurBottom;
4862 } else {
4863 vf.set(cf);
4864 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004865 }
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07004866 } else if ((fl & FLAG_LAYOUT_IN_SCREEN) != 0 || (sysUiFl
4867 & (View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
4868 | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION)) != 0) {
Craig Mautnereda67292013-04-28 13:50:14 -07004869 if (DEBUG_LAYOUT) Slog.v(TAG, "layoutWindowLw(" + attrs.getTitle() +
4870 "): IN_SCREEN");
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004871 // A window that has requested to fill the entire screen just
4872 // gets everything, period.
Daniel Sandler8956dbb2011-04-22 07:55:02 -04004873 if (attrs.type == TYPE_STATUS_BAR_PANEL
John Spurlock67a0f852015-06-15 15:35:47 -04004874 || attrs.type == TYPE_STATUS_BAR_SUB_PANEL
4875 || attrs.type == TYPE_VOLUME_OVERLAY) {
Dianne Hackbornc4aad012013-02-22 15:05:25 -08004876 pf.left = df.left = of.left = cf.left = hasNavBar
4877 ? mDockLeft : mUnrestrictedScreenLeft;
4878 pf.top = df.top = of.top = cf.top = mUnrestrictedScreenTop;
4879 pf.right = df.right = of.right = cf.right = hasNavBar
Daniel Sandler8e8b4152011-07-21 01:16:43 -04004880 ? mRestrictedScreenLeft+mRestrictedScreenWidth
Dianne Hackbornc652de82013-02-15 16:32:56 -08004881 : mUnrestrictedScreenLeft + mUnrestrictedScreenWidth;
Dianne Hackbornc4aad012013-02-22 15:05:25 -08004882 pf.bottom = df.bottom = of.bottom = cf.bottom = hasNavBar
Daniel Sandler8e8b4152011-07-21 01:16:43 -04004883 ? mRestrictedScreenTop+mRestrictedScreenHeight
Dianne Hackbornc652de82013-02-15 16:32:56 -08004884 : mUnrestrictedScreenTop + mUnrestrictedScreenHeight;
Craig Mautnereda67292013-04-28 13:50:14 -07004885 if (DEBUG_LAYOUT) Slog.v(TAG, String.format(
Daniel Sandler36412a72011-08-04 09:35:13 -04004886 "Laying out IN_SCREEN status bar window: (%d,%d - %d,%d)",
4887 pf.left, pf.top, pf.right, pf.bottom));
Jim Millere898ac52012-04-06 17:10:57 -07004888 } else if (attrs.type == TYPE_NAVIGATION_BAR
4889 || attrs.type == TYPE_NAVIGATION_BAR_PANEL) {
Daniel Sandler8e8b4152011-07-21 01:16:43 -04004890 // The navigation bar has Real Ultimate Power.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08004891 pf.left = df.left = of.left = mUnrestrictedScreenLeft;
4892 pf.top = df.top = of.top = mUnrestrictedScreenTop;
4893 pf.right = df.right = of.right = mUnrestrictedScreenLeft
4894 + mUnrestrictedScreenWidth;
4895 pf.bottom = df.bottom = of.bottom = mUnrestrictedScreenTop
4896 + mUnrestrictedScreenHeight;
Craig Mautnereda67292013-04-28 13:50:14 -07004897 if (DEBUG_LAYOUT) Slog.v(TAG, String.format(
Daniel Sandler8e8b4152011-07-21 01:16:43 -04004898 "Laying out navigation bar window: (%d,%d - %d,%d)",
4899 pf.left, pf.top, pf.right, pf.bottom));
Dianne Hackborn01011c32012-02-21 13:54:21 -08004900 } else if ((attrs.type == TYPE_SECURE_SYSTEM_OVERLAY
Muyuan Li6ca619f2016-03-08 13:30:42 -08004901 || attrs.type == TYPE_BOOT_PROGRESS
4902 || attrs.type == TYPE_SCREENSHOT)
Jeff Brownbfcb60a2011-09-08 18:51:14 -07004903 && ((fl & FLAG_FULLSCREEN) != 0)) {
Muyuan Li6ca619f2016-03-08 13:30:42 -08004904 // Fullscreen secure system overlays get what they ask for. Screenshot region
4905 // selection overlay should also expand to full screen.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08004906 pf.left = df.left = of.left = cf.left = mOverscanScreenLeft;
4907 pf.top = df.top = of.top = cf.top = mOverscanScreenTop;
4908 pf.right = df.right = of.right = cf.right = mOverscanScreenLeft
4909 + mOverscanScreenWidth;
4910 pf.bottom = df.bottom = of.bottom = cf.bottom = mOverscanScreenTop
4911 + mOverscanScreenHeight;
Craig Mautner165be0c2015-01-27 15:16:58 -08004912 } else if (attrs.type == TYPE_BOOT_PROGRESS) {
Dianne Hackborn01011c32012-02-21 13:54:21 -08004913 // Boot progress screen always covers entire display.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08004914 pf.left = df.left = of.left = cf.left = mOverscanScreenLeft;
4915 pf.top = df.top = of.top = cf.top = mOverscanScreenTop;
4916 pf.right = df.right = of.right = cf.right = mOverscanScreenLeft
4917 + mOverscanScreenWidth;
4918 pf.bottom = df.bottom = of.bottom = cf.bottom = mOverscanScreenTop
4919 + mOverscanScreenHeight;
John Spurlock46646232013-09-30 22:32:42 -04004920 } else if ((fl & FLAG_LAYOUT_IN_OVERSCAN) != 0
Dianne Hackbornc652de82013-02-15 16:32:56 -08004921 && attrs.type >= WindowManager.LayoutParams.FIRST_APPLICATION_WINDOW
4922 && attrs.type <= WindowManager.LayoutParams.LAST_SUB_WINDOW) {
4923 // Asking to layout into the overscan region, so give it that pure
4924 // unrestricted area.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08004925 pf.left = df.left = of.left = cf.left = mOverscanScreenLeft;
4926 pf.top = df.top = of.top = cf.top = mOverscanScreenTop;
4927 pf.right = df.right = of.right = cf.right
Dianne Hackbornc652de82013-02-15 16:32:56 -08004928 = mOverscanScreenLeft + mOverscanScreenWidth;
Dianne Hackbornc4aad012013-02-22 15:05:25 -08004929 pf.bottom = df.bottom = of.bottom = cf.bottom
Dianne Hackbornc652de82013-02-15 16:32:56 -08004930 = mOverscanScreenTop + mOverscanScreenHeight;
Alan Viverette5a0f4ec2013-10-07 15:10:29 -07004931 } else if (canHideNavigationBar()
Dianne Hackbornf87d1962012-04-04 12:48:24 -07004932 && (sysUiFl & View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION) != 0
Craig Mautnerbeac1062014-06-03 14:38:57 -07004933 && (attrs.type == TYPE_STATUS_BAR
4934 || attrs.type == TYPE_TOAST
Jorim Jaggi81fe2d12015-12-21 14:45:18 +01004935 || attrs.type == TYPE_DOCK_DIVIDER
Jorim Jaggi2fdeeab2015-04-01 15:13:03 -07004936 || attrs.type == TYPE_VOICE_INTERACTION_STARTING
John Spurlock34e13d92013-08-10 06:52:28 -04004937 || (attrs.type >= WindowManager.LayoutParams.FIRST_APPLICATION_WINDOW
4938 && attrs.type <= WindowManager.LayoutParams.LAST_SUB_WINDOW))) {
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07004939 // Asking for layout as if the nav bar is hidden, lets the
4940 // application extend into the unrestricted screen area. We
John Spurlock34e13d92013-08-10 06:52:28 -04004941 // only do this for application windows (or toasts) to ensure no window that
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07004942 // can be above the nav bar can do this.
4943 // XXX This assumes that an app asking for this will also
4944 // ask for layout in only content. We can't currently figure out
4945 // what the screen would be if only laying out to hide the nav bar.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08004946 pf.left = df.left = of.left = cf.left = mUnrestrictedScreenLeft;
4947 pf.top = df.top = of.top = cf.top = mUnrestrictedScreenTop;
4948 pf.right = df.right = of.right = cf.right = mUnrestrictedScreenLeft
4949 + mUnrestrictedScreenWidth;
4950 pf.bottom = df.bottom = of.bottom = cf.bottom = mUnrestrictedScreenTop
4951 + mUnrestrictedScreenHeight;
Jorim Jaggi9f6798a2016-02-10 22:16:06 -08004952 } else if ((sysUiFl & View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN) != 0) {
4953 pf.left = df.left = of.left = mRestrictedScreenLeft;
4954 pf.top = df.top = of.top = mRestrictedScreenTop;
4955 pf.right = df.right = of.right = mRestrictedScreenLeft + mRestrictedScreenWidth;
4956 pf.bottom = df.bottom = of.bottom = mRestrictedScreenTop
4957 + mRestrictedScreenHeight;
4958 if (adjust != SOFT_INPUT_ADJUST_RESIZE) {
4959 cf.left = mDockLeft;
4960 cf.top = mDockTop;
4961 cf.right = mDockRight;
4962 cf.bottom = mDockBottom;
4963 } else {
4964 cf.left = mContentLeft;
4965 cf.top = mContentTop;
4966 cf.right = mContentRight;
4967 cf.bottom = mContentBottom;
4968 }
Joe Onorato29fc2c92010-11-24 10:26:50 -08004969 } else {
Dianne Hackbornc4aad012013-02-22 15:05:25 -08004970 pf.left = df.left = of.left = cf.left = mRestrictedScreenLeft;
4971 pf.top = df.top = of.top = cf.top = mRestrictedScreenTop;
4972 pf.right = df.right = of.right = cf.right = mRestrictedScreenLeft
4973 + mRestrictedScreenWidth;
4974 pf.bottom = df.bottom = of.bottom = cf.bottom = mRestrictedScreenTop
4975 + mRestrictedScreenHeight;
Joe Onorato29fc2c92010-11-24 10:26:50 -08004976 }
Craig Mautner69b08182012-09-05 13:07:13 -07004977
Dianne Hackborn5b5cc4d2012-05-16 13:15:00 -07004978 applyStableConstraints(sysUiFl, fl, cf);
Craig Mautner69b08182012-09-05 13:07:13 -07004979
Dianne Hackborndea3ef72010-10-28 14:24:22 -07004980 if (adjust != SOFT_INPUT_ADJUST_NOTHING) {
4981 vf.left = mCurLeft;
4982 vf.top = mCurTop;
4983 vf.right = mCurRight;
4984 vf.bottom = mCurBottom;
4985 } else {
4986 vf.set(cf);
4987 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004988 } else if (attached != null) {
Craig Mautnereda67292013-04-28 13:50:14 -07004989 if (DEBUG_LAYOUT) Slog.v(TAG, "layoutWindowLw(" + attrs.getTitle() +
4990 "): attached to " + attached);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004991 // A child window should be placed inside of the same visible
4992 // frame that its parent had.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08004993 setAttachedWindowFrames(win, fl, adjust, attached, false, pf, df, of, cf, vf);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004994 } else {
Craig Mautnereda67292013-04-28 13:50:14 -07004995 if (DEBUG_LAYOUT) Slog.v(TAG, "layoutWindowLw(" + attrs.getTitle() +
4996 "): normal window");
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004997 // Otherwise, a normal window must be placed inside the content
4998 // of all screen decorations.
John Spurlock67a0f852015-06-15 15:35:47 -04004999 if (attrs.type == TYPE_STATUS_BAR_PANEL || attrs.type == TYPE_VOLUME_OVERLAY) {
5000 // Status bar panels and the volume dialog are the only windows who can go on
5001 // top of the status bar. They are protected by the STATUS_BAR_SERVICE
Dianne Hackborna239c842011-06-01 12:28:20 -07005002 // permission, so they have the same privileges as the status
5003 // bar itself.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08005004 pf.left = df.left = of.left = cf.left = mRestrictedScreenLeft;
5005 pf.top = df.top = of.top = cf.top = mRestrictedScreenTop;
5006 pf.right = df.right = of.right = cf.right = mRestrictedScreenLeft
5007 + mRestrictedScreenWidth;
5008 pf.bottom = df.bottom = of.bottom = cf.bottom = mRestrictedScreenTop
5009 + mRestrictedScreenHeight;
John Spurlock67a0f852015-06-15 15:35:47 -04005010 } else if (attrs.type == TYPE_TOAST || attrs.type == TYPE_SYSTEM_ALERT) {
John Spurlock414c1f02013-12-04 13:47:36 -05005011 // These dialogs are stable to interim decor changes.
John Spurlockbd957402013-10-03 11:38:39 -04005012 pf.left = df.left = of.left = cf.left = mStableLeft;
5013 pf.top = df.top = of.top = cf.top = mStableTop;
5014 pf.right = df.right = of.right = cf.right = mStableRight;
5015 pf.bottom = df.bottom = of.bottom = cf.bottom = mStableBottom;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005016 } else {
Dianne Hackborna239c842011-06-01 12:28:20 -07005017 pf.left = mContentLeft;
5018 pf.top = mContentTop;
5019 pf.right = mContentRight;
5020 pf.bottom = mContentBottom;
Dianne Hackborn20d94742014-05-29 18:35:45 -07005021 if (win.isVoiceInteraction()) {
5022 df.left = of.left = cf.left = mVoiceContentLeft;
5023 df.top = of.top = cf.top = mVoiceContentTop;
5024 df.right = of.right = cf.right = mVoiceContentRight;
5025 df.bottom = of.bottom = cf.bottom = mVoiceContentBottom;
5026 } else if (adjust != SOFT_INPUT_ADJUST_RESIZE) {
Dianne Hackbornc4aad012013-02-22 15:05:25 -08005027 df.left = of.left = cf.left = mDockLeft;
5028 df.top = of.top = cf.top = mDockTop;
5029 df.right = of.right = cf.right = mDockRight;
5030 df.bottom = of.bottom = cf.bottom = mDockBottom;
Dianne Hackborna239c842011-06-01 12:28:20 -07005031 } else {
Dianne Hackbornc4aad012013-02-22 15:05:25 -08005032 df.left = of.left = cf.left = mContentLeft;
5033 df.top = of.top = cf.top = mContentTop;
5034 df.right = of.right = cf.right = mContentRight;
5035 df.bottom = of.bottom = cf.bottom = mContentBottom;
Dianne Hackborna239c842011-06-01 12:28:20 -07005036 }
5037 if (adjust != SOFT_INPUT_ADJUST_NOTHING) {
5038 vf.left = mCurLeft;
5039 vf.top = mCurTop;
5040 vf.right = mCurRight;
5041 vf.bottom = mCurBottom;
5042 } else {
5043 vf.set(cf);
5044 }
Dianne Hackborndea3ef72010-10-28 14:24:22 -07005045 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005046 }
5047 }
Craig Mautner69b08182012-09-05 13:07:13 -07005048
Craig Mautnerb816bed2013-07-23 10:26:17 -07005049 // TYPE_SYSTEM_ERROR is above the NavigationBar so it can't be allowed to extend over it.
Wale Ogunwale9185fb02016-03-11 18:06:14 -08005050 // Also, we don't allow windows in multi-window mode to extend out of the screen.
5051 if ((fl & FLAG_LAYOUT_NO_LIMITS) != 0 && attrs.type != TYPE_SYSTEM_ERROR
Andrii Kulian933076d2016-03-29 17:04:42 -07005052 && !win.isInMultiWindowMode()) {
Dianne Hackborn067e5f62014-09-07 23:14:30 -07005053 df.left = df.top = -10000;
5054 df.right = df.bottom = 10000;
5055 if (attrs.type != TYPE_WALLPAPER) {
5056 of.left = of.top = cf.left = cf.top = vf.left = vf.top = -10000;
5057 of.right = of.bottom = cf.right = cf.bottom = vf.right = vf.bottom = 10000;
5058 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005059 }
5060
Filip Gruszczynski2217f612015-05-26 11:32:08 -07005061 // If the device has a chin (e.g. some watches), a dead area at the bottom of the screen we
5062 // need to provide information to the clients that want to pretend that you can draw there.
Filip Gruszczynskib0c673b2015-06-05 09:43:06 -07005063 // We only want to apply outsets to certain types of windows. For example, we never want to
5064 // apply the outsets to floating dialogs, because they wouldn't make sense there.
Filip Gruszczynski2987f612015-06-30 15:03:30 -07005065 final boolean useOutsets = shouldUseOutsets(attrs, fl);
Filip Gruszczynskib0c673b2015-06-05 09:43:06 -07005066 if (isDefaultDisplay && useOutsets) {
Filip Gruszczynski2217f612015-05-26 11:32:08 -07005067 osf = mTmpOutsetFrame;
5068 osf.set(cf.left, cf.top, cf.right, cf.bottom);
5069 int outset = ScreenShapeHelper.getWindowOutsetBottomPx(mContext.getResources());
5070 if (outset > 0) {
Filip Gruszczynski2987f612015-06-30 15:03:30 -07005071 int rotation = mDisplayRotation;
Filip Gruszczynski2217f612015-05-26 11:32:08 -07005072 if (rotation == Surface.ROTATION_0) {
5073 osf.bottom += outset;
5074 } else if (rotation == Surface.ROTATION_90) {
5075 osf.right += outset;
5076 } else if (rotation == Surface.ROTATION_180) {
5077 osf.top -= outset;
5078 } else if (rotation == Surface.ROTATION_270) {
5079 osf.left -= outset;
5080 }
5081 if (DEBUG_LAYOUT) Slog.v(TAG, "applying bottom outset of " + outset
5082 + " with rotation " + rotation + ", result: " + osf);
5083 }
5084 }
5085
Craig Mautnereda67292013-04-28 13:50:14 -07005086 if (DEBUG_LAYOUT) Slog.v(TAG, "Compute frame " + attrs.getTitle()
The Android Open Source Project11267662009-03-18 17:39:47 -07005087 + ": sim=#" + Integer.toHexString(sim)
RoboErik8a2cfc32014-05-16 11:19:38 -07005088 + " attach=" + attached + " type=" + attrs.type
Daniel Sandler8956dbb2011-04-22 07:55:02 -04005089 + String.format(" flags=0x%08x", fl)
The Android Open Source Project11267662009-03-18 17:39:47 -07005090 + " pf=" + pf.toShortString() + " df=" + df.toShortString()
Dianne Hackbornc4aad012013-02-22 15:05:25 -08005091 + " of=" + of.toShortString()
John Spurlock46646232013-09-30 22:32:42 -04005092 + " cf=" + cf.toShortString() + " vf=" + vf.toShortString()
Adrian Roosfa104232014-06-20 16:10:14 -07005093 + " dcf=" + dcf.toShortString()
Filip Gruszczynski2217f612015-05-26 11:32:08 -07005094 + " sf=" + sf.toShortString()
5095 + " osf=" + (osf == null ? "null" : osf.toShortString()));
Craig Mautner69b08182012-09-05 13:07:13 -07005096
Filip Gruszczynski2217f612015-05-26 11:32:08 -07005097 win.computeFrameLw(pf, df, of, cf, vf, dcf, sf, osf);
Craig Mautner69b08182012-09-05 13:07:13 -07005098
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005099 // Dock windows carve out the bottom of the screen, so normal windows
5100 // can't appear underneath them.
Jorim Jaggib0d27342016-11-01 16:10:42 -07005101 if (attrs.type == TYPE_INPUT_METHOD && win.isVisibleLw()
5102 && !win.getGivenInsetsPendingLw()) {
satok1bc0a492012-04-25 22:47:12 +09005103 setLastInputMethodWindowLw(null, null);
5104 offsetInputMethodWindowLw(win);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005105 }
Jorim Jaggib0d27342016-11-01 16:10:42 -07005106 if (attrs.type == TYPE_VOICE_INTERACTION && win.isVisibleLw()
Dianne Hackborne30e02f2014-05-27 18:24:45 -07005107 && !win.getGivenInsetsPendingLw()) {
5108 offsetVoiceInputWindowLw(win);
5109 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005110 }
5111
Jorim Jaggi526505d2016-05-24 00:29:19 -07005112 private void layoutWallpaper(WindowState win, Rect pf, Rect df, Rect of, Rect cf) {
5113
5114 // The wallpaper also has Real Ultimate Power, but we want to tell
5115 // it about the overscan area.
5116 pf.left = df.left = mOverscanScreenLeft;
5117 pf.top = df.top = mOverscanScreenTop;
5118 pf.right = df.right = mOverscanScreenLeft + mOverscanScreenWidth;
5119 pf.bottom = df.bottom = mOverscanScreenTop + mOverscanScreenHeight;
5120 of.left = cf.left = mUnrestrictedScreenLeft;
5121 of.top = cf.top = mUnrestrictedScreenTop;
5122 of.right = cf.right = mUnrestrictedScreenLeft + mUnrestrictedScreenWidth;
5123 of.bottom = cf.bottom = mUnrestrictedScreenTop + mUnrestrictedScreenHeight;
5124 }
5125
satok1bc0a492012-04-25 22:47:12 +09005126 private void offsetInputMethodWindowLw(WindowState win) {
Craig Mautner4774f6a2015-03-23 11:42:55 -07005127 int top = Math.max(win.getDisplayFrameLw().top, win.getContentFrameLw().top);
satok1bc0a492012-04-25 22:47:12 +09005128 top += win.getGivenContentInsetsLw().top;
5129 if (mContentBottom > top) {
5130 mContentBottom = top;
5131 }
Dianne Hackborne30e02f2014-05-27 18:24:45 -07005132 if (mVoiceContentBottom > top) {
5133 mVoiceContentBottom = top;
5134 }
satok1bc0a492012-04-25 22:47:12 +09005135 top = win.getVisibleFrameLw().top;
5136 top += win.getGivenVisibleInsetsLw().top;
5137 if (mCurBottom > top) {
5138 mCurBottom = top;
5139 }
Craig Mautnereda67292013-04-28 13:50:14 -07005140 if (DEBUG_LAYOUT) Slog.v(TAG, "Input method: mDockBottom="
satok1bc0a492012-04-25 22:47:12 +09005141 + mDockBottom + " mContentBottom="
5142 + mContentBottom + " mCurBottom=" + mCurBottom);
5143 }
5144
Dianne Hackborne30e02f2014-05-27 18:24:45 -07005145 private void offsetVoiceInputWindowLw(WindowState win) {
Craig Mautner4774f6a2015-03-23 11:42:55 -07005146 int top = Math.max(win.getDisplayFrameLw().top, win.getContentFrameLw().top);
Dianne Hackbornae6688b2015-02-11 17:02:41 -08005147 top += win.getGivenContentInsetsLw().top;
5148 if (mVoiceContentBottom > top) {
5149 mVoiceContentBottom = top;
Dianne Hackborne30e02f2014-05-27 18:24:45 -07005150 }
5151 }
5152
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005153 /** {@inheritDoc} */
Craig Mautner61ac6bb2012-02-02 17:29:33 -08005154 @Override
5155 public void finishLayoutLw() {
5156 return;
Dianne Hackborn5f3063e2010-03-10 16:01:58 -08005157 }
5158
5159 /** {@inheritDoc} */
Craig Mautnerad09bcc2012-10-08 13:33:11 -07005160 @Override
Craig Mautner39834192012-09-02 07:47:24 -07005161 public void beginPostLayoutPolicyLw(int displayWidth, int displayHeight) {
Dianne Hackborn5f3063e2010-03-10 16:01:58 -08005162 mTopFullscreenOpaqueWindowState = null;
Adrian Rooscd3884d2015-02-18 17:25:23 +01005163 mTopFullscreenOpaqueOrDimmingWindowState = null;
Jorim Jaggi86905582016-02-09 21:36:09 -08005164 mTopDockedOpaqueWindowState = null;
5165 mTopDockedOpaqueOrDimmingWindowState = null;
Dianne Hackborn5f3063e2010-03-10 16:01:58 -08005166 mForceStatusBar = false;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07005167 mForceStatusBarFromKeyguard = false;
Selim Cinek4a4a2bddc2015-05-07 12:50:19 -07005168 mForceStatusBarTransparent = false;
Dianne Hackborn891d3fb2013-01-09 18:31:37 -08005169 mForcingShowNavBar = false;
5170 mForcingShowNavBarLayer = -1;
RoboErik8a2cfc32014-05-16 11:19:38 -07005171
Dianne Hackborn5f3063e2010-03-10 16:01:58 -08005172 mAllowLockscreenWhenOn = false;
Dianne Hackborn7ad44382012-10-18 17:46:00 -07005173 mShowingDream = false;
Dianne Hackborn5f3063e2010-03-10 16:01:58 -08005174 }
5175
5176 /** {@inheritDoc} */
Craig Mautnerad09bcc2012-10-08 13:33:11 -07005177 @Override
Yohei Yukawad1a09222015-06-30 16:22:05 -07005178 public void applyPostLayoutPolicyLw(WindowState win, WindowManager.LayoutParams attrs,
Jorim Jaggife762342016-10-13 14:33:27 +02005179 WindowState attached, WindowState imeTarget) {
Jorim Jaggib0d27342016-11-01 16:10:42 -07005180 final boolean visible = win.isVisibleLw();
5181 if (DEBUG_LAYOUT) Slog.i(TAG, "Win " + win + ": isVisible=" + visible);
Jorim Jaggife762342016-10-13 14:33:27 +02005182 applyKeyguardPolicyLw(win, imeTarget);
John Spurlockc6d1c602014-01-17 15:22:06 -05005183 final int fl = PolicyControl.getWindowFlags(win, attrs);
Jorim Jaggib0d27342016-11-01 16:10:42 -07005184 if (mTopFullscreenOpaqueWindowState == null && visible && attrs.type == TYPE_INPUT_METHOD) {
John Spurlock414c1f02013-12-04 13:47:36 -05005185 mForcingShowNavBar = true;
5186 mForcingShowNavBarLayer = win.getSurfaceLayer();
Dianne Hackborn891d3fb2013-01-09 18:31:37 -08005187 }
Selim Cinek4a4a2bddc2015-05-07 12:50:19 -07005188 if (attrs.type == TYPE_STATUS_BAR) {
5189 if ((attrs.privateFlags & PRIVATE_FLAG_KEYGUARD) != 0) {
5190 mForceStatusBarFromKeyguard = true;
5191 }
5192 if ((attrs.privateFlags & PRIVATE_FLAG_FORCE_STATUS_BAR_VISIBLE_TRANSPARENT) != 0) {
5193 mForceStatusBarTransparent = true;
5194 }
Jorim Jaggiafd4a552014-04-08 15:13:05 +02005195 }
Adrian Roos602c68e2015-04-24 16:03:47 -07005196
5197 boolean appWindow = attrs.type >= FIRST_APPLICATION_WINDOW
5198 && attrs.type < FIRST_SYSTEM_WINDOW;
Jorim Jaggi86905582016-02-09 21:36:09 -08005199 final int stackId = win.getStackId();
Jorim Jaggib0d27342016-11-01 16:10:42 -07005200 if (mTopFullscreenOpaqueWindowState == null && visible) {
John Spurlockc6d1c602014-01-17 15:22:06 -05005201 if ((fl & FLAG_FORCE_NOT_FULLSCREEN) != 0) {
Jorim Jaggife762342016-10-13 14:33:27 +02005202 mForceStatusBar = true;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07005203 }
Dianne Hackborn7ad44382012-10-18 17:46:00 -07005204 if (attrs.type == TYPE_DREAM) {
Jeff Brownc8018eb2012-10-29 21:33:27 -07005205 // If the lockscreen was showing when the dream started then wait
5206 // for the dream to draw before hiding the lockscreen.
5207 if (!mDreamingLockscreen
5208 || (win.isVisibleLw() && win.hasDrawnLw())) {
5209 mShowingDream = true;
Craig Mautnerab55e522014-03-03 13:26:03 -08005210 appWindow = true;
Dianne Hackborn7ad44382012-10-18 17:46:00 -07005211 }
5212 }
Craig Mautnerab55e522014-03-03 13:26:03 -08005213
Yohei Yukawad1a09222015-06-30 16:22:05 -07005214 // For app windows that are not attached, we decide if all windows in the app they
5215 // represent should be hidden or if we should hide the lockscreen. For attached app
5216 // windows we defer the decision to the window it is attached to.
5217 if (appWindow && attached == null) {
Jorim Jaggi86905582016-02-09 21:36:09 -08005218 if (isFullscreen(attrs) && StackId.normallyFullscreenWindows(stackId)) {
Craig Mautnerab55e522014-03-03 13:26:03 -08005219 if (DEBUG_LAYOUT) Slog.v(TAG, "Fullscreen window: " + win);
5220 mTopFullscreenOpaqueWindowState = win;
Adrian Rooscd3884d2015-02-18 17:25:23 +01005221 if (mTopFullscreenOpaqueOrDimmingWindowState == null) {
5222 mTopFullscreenOpaqueOrDimmingWindowState = win;
5223 }
Craig Mautner00156ec2014-03-06 22:29:02 -08005224 if ((fl & FLAG_ALLOW_LOCK_WHILE_SCREEN_ON) != 0) {
Craig Mautnerab55e522014-03-03 13:26:03 -08005225 mAllowLockscreenWhenOn = true;
5226 }
Dianne Hackborn5f3063e2010-03-10 16:01:58 -08005227 }
Adrian Roos602c68e2015-04-24 16:03:47 -07005228 }
Dianne Hackborn5f3063e2010-03-10 16:01:58 -08005229 }
Jorim Jaggi86905582016-02-09 21:36:09 -08005230
Jorim Jaggi90859bc2016-06-28 16:25:23 -07005231 // Voice interaction overrides both top fullscreen and top docked.
Jorim Jaggib0d27342016-11-01 16:10:42 -07005232 if (visible && win.getAttrs().type == TYPE_VOICE_INTERACTION) {
Jorim Jaggi90859bc2016-06-28 16:25:23 -07005233 if (mTopFullscreenOpaqueWindowState == null) {
5234 mTopFullscreenOpaqueWindowState = win;
5235 if (mTopFullscreenOpaqueOrDimmingWindowState == null) {
5236 mTopFullscreenOpaqueOrDimmingWindowState = win;
5237 }
5238 }
5239 if (mTopDockedOpaqueWindowState == null) {
5240 mTopDockedOpaqueWindowState = win;
5241 if (mTopDockedOpaqueOrDimmingWindowState == null) {
5242 mTopDockedOpaqueOrDimmingWindowState = win;
5243 }
5244 }
5245 }
5246
5247 // Keep track of the window if it's dimming but not necessarily fullscreen.
Jorim Jaggib0d27342016-11-01 16:10:42 -07005248 if (mTopFullscreenOpaqueOrDimmingWindowState == null && visible
Jorim Jaggi86905582016-02-09 21:36:09 -08005249 && win.isDimming() && StackId.normallyFullscreenWindows(stackId)) {
Adrian Rooscd3884d2015-02-18 17:25:23 +01005250 mTopFullscreenOpaqueOrDimmingWindowState = win;
5251 }
Jorim Jaggi86905582016-02-09 21:36:09 -08005252
5253 // We need to keep track of the top "fullscreen" opaque window for the docked stack
5254 // separately, because both the "real fullscreen" opaque window and the one for the docked
5255 // stack can control View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR.
Jorim Jaggib0d27342016-11-01 16:10:42 -07005256 if (mTopDockedOpaqueWindowState == null && visible && appWindow && attached == null
Jorim Jaggi86905582016-02-09 21:36:09 -08005257 && isFullscreen(attrs) && stackId == DOCKED_STACK_ID) {
5258 mTopDockedOpaqueWindowState = win;
5259 if (mTopDockedOpaqueOrDimmingWindowState == null) {
5260 mTopDockedOpaqueOrDimmingWindowState = win;
5261 }
5262 }
5263
5264 // Also keep track of any windows that are dimming but not necessarily fullscreen in the
5265 // docked stack.
Jorim Jaggib0d27342016-11-01 16:10:42 -07005266 if (mTopDockedOpaqueOrDimmingWindowState == null && visible && win.isDimming()
Jorim Jaggi86905582016-02-09 21:36:09 -08005267 && stackId == DOCKED_STACK_ID) {
5268 mTopDockedOpaqueOrDimmingWindowState = win;
5269 }
5270 }
5271
Jorim Jaggife762342016-10-13 14:33:27 +02005272 private void applyKeyguardPolicyLw(WindowState win, WindowState imeTarget) {
5273 if (canBeHiddenByKeyguardLw(win)) {
5274 if (shouldBeHiddenByKeyguard(win, imeTarget)) {
5275 win.hideLw(false /* doAnimation */);
5276 } else {
5277 win.showLw(false /* doAnimation */);
5278 }
5279 }
5280 }
5281
Jorim Jaggi86905582016-02-09 21:36:09 -08005282 private boolean isFullscreen(WindowManager.LayoutParams attrs) {
5283 return attrs.x == 0 && attrs.y == 0
5284 && attrs.width == WindowManager.LayoutParams.MATCH_PARENT
5285 && attrs.height == WindowManager.LayoutParams.MATCH_PARENT;
Dianne Hackborn5f3063e2010-03-10 16:01:58 -08005286 }
5287
5288 /** {@inheritDoc} */
Craig Mautnerad09bcc2012-10-08 13:33:11 -07005289 @Override
Craig Mautner39834192012-09-02 07:47:24 -07005290 public int finishPostLayoutPolicyLw() {
Dianne Hackborn39c2d712009-09-22 11:41:31 -07005291 int changes = 0;
Joe Onorato93056472010-09-10 10:30:46 -04005292 boolean topIsFullscreen = false;
Daniel Sandlere02d8082010-10-08 15:13:22 -04005293
5294 final WindowManager.LayoutParams lp = (mTopFullscreenOpaqueWindowState != null)
5295 ? mTopFullscreenOpaqueWindowState.getAttrs()
5296 : null;
5297
Jeff Brownc8018eb2012-10-29 21:33:27 -07005298 // If we are not currently showing a dream then remember the current
5299 // lockscreen state. We will use this to determine whether the dream
5300 // started while the lockscreen was showing and remember this state
5301 // while the dream is showing.
Dianne Hackborn7ad44382012-10-18 17:46:00 -07005302 if (!mShowingDream) {
Jorim Jaggi8d786932016-10-26 19:08:36 -07005303 mDreamingLockscreen = isKeyguardShowingAndNotOccluded();
Jeff Brown061ea992015-04-17 19:55:47 -07005304 if (mDreamingSleepTokenNeeded) {
5305 mDreamingSleepTokenNeeded = false;
5306 mHandler.obtainMessage(MSG_UPDATE_DREAMING_SLEEP_TOKEN, 0, 1).sendToTarget();
5307 }
5308 } else {
5309 if (!mDreamingSleepTokenNeeded) {
5310 mDreamingSleepTokenNeeded = true;
5311 mHandler.obtainMessage(MSG_UPDATE_DREAMING_SLEEP_TOKEN, 1, 1).sendToTarget();
5312 }
Dianne Hackborn7ad44382012-10-18 17:46:00 -07005313 }
5314
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005315 if (mStatusBar != null) {
Craig Mautnereda67292013-04-28 13:50:14 -07005316 if (DEBUG_LAYOUT) Slog.i(TAG, "force=" + mForceStatusBar
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07005317 + " forcefkg=" + mForceStatusBarFromKeyguard
Dianne Hackbornd70bc2f2009-10-06 23:25:51 -07005318 + " top=" + mTopFullscreenOpaqueWindowState);
Selim Cinek4a4a2bddc2015-05-07 12:50:19 -07005319 boolean shouldBeTransparent = mForceStatusBarTransparent
5320 && !mForceStatusBar
5321 && !mForceStatusBarFromKeyguard;
5322 if (!shouldBeTransparent) {
5323 mStatusBarController.setShowTransparent(false /* transparent */);
5324 } else if (!mStatusBar.isVisibleLw()) {
5325 mStatusBarController.setShowTransparent(true /* transparent */);
5326 }
Adrian Roosdb1bc6b2016-04-14 17:49:43 -07005327
5328 WindowManager.LayoutParams statusBarAttrs = mStatusBar.getAttrs();
5329 boolean statusBarExpanded = statusBarAttrs.height == MATCH_PARENT
5330 && statusBarAttrs.width == MATCH_PARENT;
5331 if (mForceStatusBar || mForceStatusBarFromKeyguard || mForceStatusBarTransparent
5332 || statusBarExpanded) {
Craig Mautnereda67292013-04-28 13:50:14 -07005333 if (DEBUG_LAYOUT) Slog.v(TAG, "Showing status bar: forced");
John Spurlock27735a42013-08-14 17:57:38 -04005334 if (mStatusBarController.setBarShowingLw(true)) {
5335 changes |= FINISH_LAYOUT_REDO_LAYOUT;
5336 }
Craig Mautner81defc72013-10-29 11:10:42 -07005337 // Maintain fullscreen layout until incoming animation is complete.
5338 topIsFullscreen = mTopIsFullscreen && mStatusBar.isAnimatingLw();
John Spurlockf92b6162013-11-11 15:01:16 -05005339 // Transient status bar on the lockscreen is not allowed
5340 if (mForceStatusBarFromKeyguard && mStatusBarController.isTransientShowing()) {
5341 mStatusBarController.updateVisibilityLw(false /*transientAllowed*/,
5342 mLastSystemUiFlags, mLastSystemUiFlags);
5343 }
Adrian Roosdb1bc6b2016-04-14 17:49:43 -07005344 if (statusBarExpanded && mNavigationBar != null) {
5345 if (mNavigationBarController.setBarShowingLw(true)) {
5346 changes |= FINISH_LAYOUT_REDO_LAYOUT;
5347 }
5348 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005349 } else if (mTopFullscreenOpaqueWindowState != null) {
John Spurlockc6d1c602014-01-17 15:22:06 -05005350 final int fl = PolicyControl.getWindowFlags(null, lp);
Joe Onorato93056472010-09-10 10:30:46 -04005351 if (localLOGV) {
Craig Mautnereda67292013-04-28 13:50:14 -07005352 Slog.d(TAG, "frame: " + mTopFullscreenOpaqueWindowState.getFrameLw()
Filip Gruszczynski2a6a2c22015-10-14 12:00:53 -07005353 + " shown position: "
5354 + mTopFullscreenOpaqueWindowState.getShownPositionLw());
Craig Mautnereda67292013-04-28 13:50:14 -07005355 Slog.d(TAG, "attr: " + mTopFullscreenOpaqueWindowState.getAttrs()
John Spurlockc6d1c602014-01-17 15:22:06 -05005356 + " lp.flags=0x" + Integer.toHexString(fl));
Joe Onorato93056472010-09-10 10:30:46 -04005357 }
John Spurlockc6d1c602014-01-17 15:22:06 -05005358 topIsFullscreen = (fl & WindowManager.LayoutParams.FLAG_FULLSCREEN) != 0
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07005359 || (mLastSystemUiFlags & View.SYSTEM_UI_FLAG_FULLSCREEN) != 0;
Joe Onorato93056472010-09-10 10:30:46 -04005360 // The subtle difference between the window for mTopFullscreenOpaqueWindowState
Mark Dolinerd0646dc2014-08-27 16:04:02 -07005361 // and mTopIsFullscreen is that mTopIsFullscreen is set only if the window
Joe Onorato93056472010-09-10 10:30:46 -04005362 // has the FLAG_FULLSCREEN set. Not sure if there is another way that to be the
5363 // case though.
John Spurlock27735a42013-08-14 17:57:38 -04005364 if (mStatusBarController.isTransientShowing()) {
5365 if (mStatusBarController.setBarShowingLw(true)) {
John Spurlock32beb2c2013-03-11 10:16:47 -04005366 changes |= FINISH_LAYOUT_REDO_LAYOUT;
5367 }
Wale Ogunwale6e94a9e2015-10-07 15:35:49 -07005368 } else if (topIsFullscreen
5369 && !mWindowManagerInternal.isStackVisible(FREEFORM_WORKSPACE_STACK_ID)
5370 && !mWindowManagerInternal.isStackVisible(DOCKED_STACK_ID)) {
Craig Mautnereda67292013-04-28 13:50:14 -07005371 if (DEBUG_LAYOUT) Slog.v(TAG, "** HIDING status bar");
John Spurlock27735a42013-08-14 17:57:38 -04005372 if (mStatusBarController.setBarShowingLw(false)) {
Dianne Hackbornf87d1962012-04-04 12:48:24 -07005373 changes |= FINISH_LAYOUT_REDO_LAYOUT;
Craig Mautnereda67292013-04-28 13:50:14 -07005374 } else {
Craig Mautnerc5a6e442013-06-05 17:22:35 -07005375 if (DEBUG_LAYOUT) Slog.v(TAG, "Status bar already hiding");
Daniel Sandler40427442010-07-16 11:44:52 -04005376 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005377 } else {
Craig Mautnereda67292013-04-28 13:50:14 -07005378 if (DEBUG_LAYOUT) Slog.v(TAG, "** SHOWING status bar: top is not fullscreen");
John Spurlock27735a42013-08-14 17:57:38 -04005379 if (mStatusBarController.setBarShowingLw(true)) {
5380 changes |= FINISH_LAYOUT_REDO_LAYOUT;
5381 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005382 }
5383 }
5384 }
Daniel Sandlere02d8082010-10-08 15:13:22 -04005385
Craig Mautner81defc72013-10-29 11:10:42 -07005386 if (mTopIsFullscreen != topIsFullscreen) {
5387 if (!topIsFullscreen) {
5388 // Force another layout when status bar becomes fully shown.
5389 changes |= FINISH_LAYOUT_REDO_LAYOUT;
5390 }
5391 mTopIsFullscreen = topIsFullscreen;
5392 }
Daniel Sandlere02d8082010-10-08 15:13:22 -04005393
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07005394 if ((updateSystemUiVisibilityLw()&SYSTEM_UI_CHANGING_LAYOUT) != 0) {
Dianne Hackborndf89e652011-10-06 22:35:11 -07005395 // If the navigation bar has been hidden or shown, we need to do another
5396 // layout pass to update that window.
5397 changes |= FINISH_LAYOUT_REDO_LAYOUT;
5398 }
Joe Onorato664644d2011-01-23 17:53:23 -08005399
Jorim Jaggi77e10432016-10-26 17:43:56 -07005400 if (mShowingDream != mLastShowingDream) {
5401 mLastShowingDream = mShowingDream;
5402 mWindowManagerFuncs.notifyShowingDreamChanged();
5403 }
5404
Mike Lockwood28569302010-01-28 11:54:40 -05005405 // update since mAllowLockscreenWhenOn might have changed
5406 updateLockScreenTimeout();
Dianne Hackborn39c2d712009-09-22 11:41:31 -07005407 return changes;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005408 }
5409
Jorim Jaggi380ecb82014-03-14 17:25:20 +01005410 /**
Jim Millerab954542014-10-10 18:21:49 -07005411 * Updates the occluded state of the Keyguard.
Jorim Jaggi380ecb82014-03-14 17:25:20 +01005412 *
Jorim Jaggi380ecb82014-03-14 17:25:20 +01005413 * @return Whether the flags have changed and we have to redo the layout.
5414 */
Jim Millerab954542014-10-10 18:21:49 -07005415 private boolean setKeyguardOccludedLw(boolean isOccluded) {
Jorim Jaggife762342016-10-13 14:33:27 +02005416 if (DEBUG_KEYGUARD) Slog.d(TAG, "setKeyguardOccluded occluded=" + isOccluded);
Jim Millerab954542014-10-10 18:21:49 -07005417 boolean wasOccluded = mKeyguardOccluded;
5418 boolean showing = mKeyguardDelegate.isShowing();
5419 if (wasOccluded && !isOccluded && showing) {
5420 mKeyguardOccluded = false;
Jorim Jaggi6626f542016-08-22 13:08:44 -07005421 mKeyguardDelegate.setOccluded(false, true /* animate */);
Jorim Jaggi380ecb82014-03-14 17:25:20 +01005422 mStatusBar.getAttrs().privateFlags |= PRIVATE_FLAG_KEYGUARD;
Jorim Jaggid11d1a92016-08-16 16:02:32 -07005423 if (!mKeyguardDelegate.hasLockscreenWallpaper()) {
5424 mStatusBar.getAttrs().flags |= FLAG_SHOW_WALLPAPER;
5425 }
Jorim Jaggi380ecb82014-03-14 17:25:20 +01005426 return true;
Jim Millerab954542014-10-10 18:21:49 -07005427 } else if (!wasOccluded && isOccluded && showing) {
5428 mKeyguardOccluded = true;
Jorim Jaggi6626f542016-08-22 13:08:44 -07005429 mKeyguardDelegate.setOccluded(true, false /* animate */);
Jorim Jaggi380ecb82014-03-14 17:25:20 +01005430 mStatusBar.getAttrs().privateFlags &= ~PRIVATE_FLAG_KEYGUARD;
5431 mStatusBar.getAttrs().flags &= ~FLAG_SHOW_WALLPAPER;
5432 return true;
Adrian Roos909fe2d2016-10-12 12:03:24 -07005433 } else if (wasOccluded != isOccluded) {
5434 mKeyguardOccluded = isOccluded;
5435 mKeyguardDelegate.setOccluded(isOccluded, false /* animate */);
5436 return false;
Jorim Jaggi380ecb82014-03-14 17:25:20 +01005437 } else {
5438 return false;
5439 }
5440 }
5441
5442 private boolean isStatusBarKeyguard() {
5443 return mStatusBar != null
5444 && (mStatusBar.getAttrs().privateFlags & PRIVATE_FLAG_KEYGUARD) != 0;
5445 }
5446
Jose Lima9546b202014-07-02 17:21:51 -07005447 @Override
Dianne Hackborn08743722009-12-21 12:16:51 -08005448 public boolean allowAppAnimationsLw() {
Jorim Jaggife762342016-10-13 14:33:27 +02005449 if (mShowingDream) {
Craig Mautner28816302013-10-10 20:31:00 -07005450 // If keyguard or dreams is currently visible, no reason to animate behind it.
Dianne Hackborn08743722009-12-21 12:16:51 -08005451 return false;
5452 }
Dianne Hackborn08743722009-12-21 12:16:51 -08005453 return true;
5454 }
5455
Jose Lima9546b202014-07-02 17:21:51 -07005456 @Override
Dianne Hackborndf89e652011-10-06 22:35:11 -07005457 public int focusChangedLw(WindowState lastFocus, WindowState newFocus) {
Joe Onorato664644d2011-01-23 17:53:23 -08005458 mFocusedWindow = newFocus;
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07005459 if ((updateSystemUiVisibilityLw()&SYSTEM_UI_CHANGING_LAYOUT) != 0) {
Dianne Hackborndf89e652011-10-06 22:35:11 -07005460 // If the navigation bar has been hidden or shown, we need to do another
5461 // layout pass to update that window.
5462 return FINISH_LAYOUT_REDO_LAYOUT;
5463 }
5464 return 0;
Joe Onorato664644d2011-01-23 17:53:23 -08005465 }
5466
Dianne Hackborn0ecadf72009-03-31 18:00:37 -07005467 /** {@inheritDoc} */
Jose Lima9546b202014-07-02 17:21:51 -07005468 @Override
Jeff Brown46b9ac02010-04-22 18:58:52 -07005469 public void notifyLidSwitchChanged(long whenNanos, boolean lidOpen) {
5470 // lid changed state
Jeff Brownc458ce92012-04-30 14:58:40 -07005471 final int newLidState = lidOpen ? LID_OPEN : LID_CLOSED;
5472 if (newLidState == mLidState) {
5473 return;
5474 }
Jeff Brown01a98dd2011-09-20 15:08:29 -07005475
Jeff Brownc458ce92012-04-30 14:58:40 -07005476 mLidState = newLidState;
5477 applyLidSwitchState();
Jeff Brown01a98dd2011-09-20 15:08:29 -07005478 updateRotation(true);
Jeff Brownc458ce92012-04-30 14:58:40 -07005479
5480 if (lidOpen) {
Dianne Hackborn280a64e2015-07-13 14:48:08 -07005481 wakeUp(SystemClock.uptimeMillis(), mAllowTheaterModeWakeFromLidSwitch,
5482 "android.policy:LID");
Jeff Brownc458ce92012-04-30 14:58:40 -07005483 } else if (!mLidControlsSleep) {
Jeff Brown96307042012-07-27 15:51:34 -07005484 mPowerManager.userActivity(SystemClock.uptimeMillis(), false);
Jeff Brown46b9ac02010-04-22 18:58:52 -07005485 }
5486 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005487
Michael Wright3818c922014-09-02 13:59:07 -07005488 @Override
5489 public void notifyCameraLensCoverSwitchChanged(long whenNanos, boolean lensCovered) {
5490 int lensCoverState = lensCovered ? CAMERA_LENS_COVERED : CAMERA_LENS_UNCOVERED;
5491 if (mCameraLensCoverState == lensCoverState) {
5492 return;
5493 }
5494 if (mCameraLensCoverState == CAMERA_LENS_COVERED &&
5495 lensCoverState == CAMERA_LENS_UNCOVERED) {
5496 Intent intent;
5497 final boolean keyguardActive = mKeyguardDelegate == null ? false :
5498 mKeyguardDelegate.isShowing();
5499 if (keyguardActive) {
5500 intent = new Intent(MediaStore.INTENT_ACTION_STILL_IMAGE_CAMERA_SECURE);
5501 } else {
5502 intent = new Intent(MediaStore.INTENT_ACTION_STILL_IMAGE_CAMERA);
5503 }
Dianne Hackborn280a64e2015-07-13 14:48:08 -07005504 wakeUp(whenNanos / 1000000, mAllowTheaterModeWakeFromCameraLens,
5505 "android.policy:CAMERA_COVER");
Bart Sears8b1c27c2015-03-18 23:51:02 +00005506 startActivityAsUser(intent, UserHandle.CURRENT_OR_SELF);
Michael Wright3818c922014-09-02 13:59:07 -07005507 }
5508 mCameraLensCoverState = lensCoverState;
5509 }
5510
Dianne Hackbornad7fa7f2011-01-07 14:06:50 -08005511 void setHdmiPlugged(boolean plugged) {
5512 if (mHdmiPlugged != plugged) {
5513 mHdmiPlugged = plugged;
Dianne Hackbornf87d1962012-04-04 12:48:24 -07005514 updateRotation(true, true);
Dianne Hackbornad7fa7f2011-01-07 14:06:50 -08005515 Intent intent = new Intent(ACTION_HDMI_PLUGGED);
Joe Onoratodc100302011-01-11 17:07:41 -08005516 intent.addFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY_BEFORE_BOOT);
Dianne Hackbornad7fa7f2011-01-07 14:06:50 -08005517 intent.putExtra(EXTRA_HDMI_PLUGGED_STATE, plugged);
Dianne Hackborn5ac72a22012-08-29 18:32:08 -07005518 mContext.sendStickyBroadcastAsUser(intent, UserHandle.ALL);
Dianne Hackbornad7fa7f2011-01-07 14:06:50 -08005519 }
5520 }
5521
Joe Onoratoea495d42011-04-06 11:41:11 -07005522 void initializeHdmiState() {
Joe Onorato7ba631f2011-05-04 15:28:00 -07005523 boolean plugged = false;
Joe Onoratoea495d42011-04-06 11:41:11 -07005524 // watch for HDMI plug messages if the hdmi switch exists
5525 if (new File("/sys/devices/virtual/switch/hdmi/state").exists()) {
5526 mHDMIObserver.startObserving("DEVPATH=/devices/virtual/switch/hdmi");
5527
Joe Onoratoea495d42011-04-06 11:41:11 -07005528 final String filename = "/sys/class/switch/hdmi/state";
5529 FileReader reader = null;
5530 try {
5531 reader = new FileReader(filename);
5532 char[] buf = new char[15];
5533 int n = reader.read(buf);
5534 if (n > 1) {
5535 plugged = 0 != Integer.parseInt(new String(buf, 0, n-1));
5536 }
5537 } catch (IOException ex) {
5538 Slog.w(TAG, "Couldn't read hdmi state from " + filename + ": " + ex);
5539 } catch (NumberFormatException ex) {
5540 Slog.w(TAG, "Couldn't read hdmi state from " + filename + ": " + ex);
5541 } finally {
5542 if (reader != null) {
5543 try {
5544 reader.close();
5545 } catch (IOException ex) {
5546 }
Joe Onoratodc100302011-01-11 17:07:41 -08005547 }
5548 }
5549 }
Joe Onorato7ba631f2011-05-04 15:28:00 -07005550 // This dance forces the code in setHdmiPlugged to run.
5551 // Always do this so the sticky intent is stuck (to false) if there is no hdmi.
5552 mHdmiPlugged = !plugged;
5553 setHdmiPlugged(!mHdmiPlugged);
Joe Onoratodc100302011-01-11 17:07:41 -08005554 }
5555
Dianne Hackbornc0e3f242011-08-19 14:19:10 -07005556 final Object mScreenshotLock = new Object();
Dianne Hackbornfc8fa632011-08-17 16:20:47 -07005557 ServiceConnection mScreenshotConnection = null;
Dianne Hackbornfc8fa632011-08-17 16:20:47 -07005558
Jeff Brownd5bb82d2011-10-12 13:57:59 -07005559 final Runnable mScreenshotTimeout = new Runnable() {
5560 @Override public void run() {
5561 synchronized (mScreenshotLock) {
5562 if (mScreenshotConnection != null) {
5563 mContext.unbindService(mScreenshotConnection);
5564 mScreenshotConnection = null;
Winson44dbe292016-03-10 14:00:14 -08005565 notifyScreenshotError();
Dianne Hackbornfc8fa632011-08-17 16:20:47 -07005566 }
Winson Chung9112ec32011-06-27 13:15:32 -07005567 }
Jeff Brownd5bb82d2011-10-12 13:57:59 -07005568 }
5569 };
5570
5571 // Assume this is called from the Handler thread.
Muyuan Li6ca619f2016-03-08 13:30:42 -08005572 private void takeScreenshot(final int screenshotType) {
Jeff Brownd5bb82d2011-10-12 13:57:59 -07005573 synchronized (mScreenshotLock) {
5574 if (mScreenshotConnection != null) {
5575 return;
5576 }
Winson44dbe292016-03-10 14:00:14 -08005577 final ComponentName serviceComponent = new ComponentName(SYSUI_PACKAGE,
5578 SYSUI_SCREENSHOT_SERVICE);
5579 final Intent serviceIntent = new Intent();
5580 serviceIntent.setComponent(serviceComponent);
Jeff Brownd5bb82d2011-10-12 13:57:59 -07005581 ServiceConnection conn = new ServiceConnection() {
5582 @Override
5583 public void onServiceConnected(ComponentName name, IBinder service) {
5584 synchronized (mScreenshotLock) {
5585 if (mScreenshotConnection != this) {
5586 return;
5587 }
5588 Messenger messenger = new Messenger(service);
Muyuan Li6ca619f2016-03-08 13:30:42 -08005589 Message msg = Message.obtain(null, screenshotType);
Jeff Brownd5bb82d2011-10-12 13:57:59 -07005590 final ServiceConnection myConn = this;
5591 Handler h = new Handler(mHandler.getLooper()) {
5592 @Override
5593 public void handleMessage(Message msg) {
5594 synchronized (mScreenshotLock) {
5595 if (mScreenshotConnection == myConn) {
5596 mContext.unbindService(mScreenshotConnection);
5597 mScreenshotConnection = null;
5598 mHandler.removeCallbacks(mScreenshotTimeout);
5599 }
5600 }
5601 }
5602 };
5603 msg.replyTo = new Messenger(h);
Winson Chunga63bb842011-10-17 10:26:28 -07005604 msg.arg1 = msg.arg2 = 0;
5605 if (mStatusBar != null && mStatusBar.isVisibleLw())
5606 msg.arg1 = 1;
5607 if (mNavigationBar != null && mNavigationBar.isVisibleLw())
5608 msg.arg2 = 1;
Jeff Brownd5bb82d2011-10-12 13:57:59 -07005609 try {
5610 messenger.send(msg);
5611 } catch (RemoteException e) {
5612 }
5613 }
5614 }
Winson44dbe292016-03-10 14:00:14 -08005615
Jeff Brownd5bb82d2011-10-12 13:57:59 -07005616 @Override
Winson44dbe292016-03-10 14:00:14 -08005617 public void onServiceDisconnected(ComponentName name) {
Geoffrey Pitschb2d6ed32016-08-24 10:37:19 -04005618 synchronized (mScreenshotLock) {
5619 if (mScreenshotConnection != null) {
5620 mContext.unbindService(mScreenshotConnection);
5621 mScreenshotConnection = null;
5622 mHandler.removeCallbacks(mScreenshotTimeout);
5623 notifyScreenshotError();
5624 }
5625 }
Winson44dbe292016-03-10 14:00:14 -08005626 }
Jeff Brownd5bb82d2011-10-12 13:57:59 -07005627 };
Winson44dbe292016-03-10 14:00:14 -08005628 if (mContext.bindServiceAsUser(serviceIntent, conn,
5629 Context.BIND_AUTO_CREATE | Context.BIND_FOREGROUND_SERVICE_WHILE_AWAKE,
5630 UserHandle.CURRENT)) {
Jeff Brownd5bb82d2011-10-12 13:57:59 -07005631 mScreenshotConnection = conn;
5632 mHandler.postDelayed(mScreenshotTimeout, 10000);
5633 }
5634 }
Winson Chung9112ec32011-06-27 13:15:32 -07005635 }
5636
Winson44dbe292016-03-10 14:00:14 -08005637 /**
5638 * Notifies the screenshot service to show an error.
5639 */
5640 private void notifyScreenshotError() {
5641 // If the service process is killed, then ask it to clean up after itself
5642 final ComponentName errorComponent = new ComponentName(SYSUI_PACKAGE,
5643 SYSUI_SCREENSHOT_ERROR_RECEIVER);
Dianne Hackborna8c16932016-05-24 12:58:21 -07005644 Intent errorIntent = new Intent(Intent.ACTION_USER_PRESENT);
Winson44dbe292016-03-10 14:00:14 -08005645 errorIntent.setComponent(errorComponent);
5646 errorIntent.addFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY_BEFORE_BOOT |
5647 Intent.FLAG_RECEIVER_FOREGROUND);
Winson538c2262016-05-19 10:06:18 -07005648 mContext.sendBroadcastAsUser(errorIntent, UserHandle.CURRENT);
Winson44dbe292016-03-10 14:00:14 -08005649 }
5650
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005651 /** {@inheritDoc} */
Jeff Brown00fa7bd2010-07-02 15:37:36 -07005652 @Override
Jeff Brown037c33e2014-04-09 00:31:55 -07005653 public int interceptKeyBeforeQueueing(KeyEvent event, int policyFlags) {
Jeff Brown96307042012-07-27 15:51:34 -07005654 if (!mSystemBooted) {
5655 // If we have not yet booted, don't let key events do anything.
5656 return 0;
5657 }
5658
Jeff Brown037c33e2014-04-09 00:31:55 -07005659 final boolean interactive = (policyFlags & FLAG_INTERACTIVE) != 0;
Jeff Brown1f245102010-11-18 20:53:46 -08005660 final boolean down = event.getAction() == KeyEvent.ACTION_DOWN;
5661 final boolean canceled = event.isCanceled();
5662 final int keyCode = event.getKeyCode();
Jeff Browne20c9e02010-10-11 14:20:19 -07005663
Jeff Brown3122e442010-10-11 23:32:49 -07005664 final boolean isInjected = (policyFlags & WindowManagerPolicy.FLAG_INJECTED) != 0;
Jeff Brown3122e442010-10-11 23:32:49 -07005665
Mike Lockwoodc72b15f2009-11-28 20:58:22 -05005666 // If screen is off then we treat the case where the keyguard is open but hidden
5667 // the same as if it were open and in front.
5668 // This will prevent any keys other than the power button from waking the screen
5669 // when the keyguard is hidden by another activity.
Jim Miller5ecd8112013-01-09 18:50:26 -08005670 final boolean keyguardActive = (mKeyguardDelegate == null ? false :
Jeff Brown037c33e2014-04-09 00:31:55 -07005671 (interactive ?
Jim Millerab954542014-10-10 18:21:49 -07005672 isKeyguardShowingAndNotOccluded() :
Jim Miller5ecd8112013-01-09 18:50:26 -08005673 mKeyguardDelegate.isShowing()));
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005674
Jeff Brown40013652012-05-16 21:22:36 -07005675 if (DEBUG_INPUT) {
Jeff Brown00fa7bd2010-07-02 15:37:36 -07005676 Log.d(TAG, "interceptKeyTq keycode=" + keyCode
Jeff Brown037c33e2014-04-09 00:31:55 -07005677 + " interactive=" + interactive + " keyguardActive=" + keyguardActive
Jeff Brown26875502014-01-30 21:47:47 -08005678 + " policyFlags=" + Integer.toHexString(policyFlags));
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005679 }
5680
Jeff Brown037c33e2014-04-09 00:31:55 -07005681 // Basic policy based on interactive state.
Jeff Brown4d396052010-10-29 21:50:21 -07005682 int result;
Michael Wright337d9d22014-04-22 15:03:48 -07005683 boolean isWakeKey = (policyFlags & WindowManagerPolicy.FLAG_WAKE) != 0
5684 || event.isWakeKey();
Michael Wrightfc01f042014-09-08 14:12:24 -07005685 if (interactive || (isInjected && !isWakeKey)) {
RoboErikde9ba392014-09-26 12:51:01 -07005686 // When the device is interactive or the key is injected pass the
5687 // key to the application.
Jeff Brown4d396052010-10-29 21:50:21 -07005688 result = ACTION_PASS_TO_USER;
Jose Lima9546b202014-07-02 17:21:51 -07005689 isWakeKey = false;
Anthony Hugh4b13ab82016-05-17 13:03:00 -07005690
5691 if (interactive) {
5692 // If the screen is awake, but the button pressed was the one that woke the device
5693 // then don't pass it to the application
5694 if (keyCode == mPendingWakeKey && !down) {
5695 result = 0;
5696 }
5697 // Reset the pending key
5698 mPendingWakeKey = PENDING_KEY_NULL;
5699 }
5700 } else if (!interactive && shouldDispatchInputWhenNonInteractive(event)) {
Michael Wrightfc01f042014-09-08 14:12:24 -07005701 // If we're currently dozing with the screen on and the keyguard showing, pass the key
5702 // to the application but preserve its wake key status to make sure we still move
5703 // from dozing to fully interactive if we would normally go from off to fully
5704 // interactive.
5705 result = ACTION_PASS_TO_USER;
Anthony Hugh4b13ab82016-05-17 13:03:00 -07005706 // Since we're dispatching the input, reset the pending key
5707 mPendingWakeKey = PENDING_KEY_NULL;
Jeff Brown4d396052010-10-29 21:50:21 -07005708 } else {
5709 // When the screen is off and the key is not injected, determine whether
5710 // to wake the device but don't pass the key to the application.
5711 result = 0;
Jeff Brown26875502014-01-30 21:47:47 -08005712 if (isWakeKey && (!down || !isWakeKeyWhenScreenOff(keyCode))) {
5713 isWakeKey = false;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005714 }
Anthony Hugh4b13ab82016-05-17 13:03:00 -07005715 // Cache the wake key on down event so we can also avoid sending the up event to the app
5716 if (isWakeKey && down) {
5717 mPendingWakeKey = keyCode;
5718 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005719 }
5720
Justin Kohd378ad72013-04-01 12:18:26 -07005721 // If the key would be handled globally, just return the result, don't worry about special
5722 // key processing.
Jeff Brown13f00f02014-10-31 14:45:50 -07005723 if (isValidGlobalKey(keyCode)
5724 && mGlobalKeyManager.shouldHandleGlobalKey(keyCode, event)) {
Michael Wright85b1af62014-06-04 14:51:58 -07005725 if (isWakeKey) {
Dianne Hackborn280a64e2015-07-13 14:48:08 -07005726 wakeUp(event.getEventTime(), mAllowTheaterModeWakeFromKey, "android.policy:KEY");
Michael Wright85b1af62014-06-04 14:51:58 -07005727 }
Justin Kohd378ad72013-04-01 12:18:26 -07005728 return result;
5729 }
5730
Jeff Brownbae8e772014-06-12 19:59:45 -07005731 boolean useHapticFeedback = down
5732 && (policyFlags & WindowManagerPolicy.FLAG_VIRTUAL) != 0
5733 && event.getRepeatCount() == 0;
5734
Jeff Brown4d396052010-10-29 21:50:21 -07005735 // Handle special keys.
5736 switch (keyCode) {
Anthony Hugh34f09ca2016-03-04 12:03:37 -08005737 case KeyEvent.KEYCODE_BACK: {
5738 if (down) {
Anthony Hugh96e9cc52016-07-12 15:17:24 -07005739 interceptBackKeyDown();
Anthony Hugh34f09ca2016-03-04 12:03:37 -08005740 } else {
Anthony Hugh96e9cc52016-07-12 15:17:24 -07005741 boolean handled = interceptBackKeyUp(event);
Anthony Hugh34f09ca2016-03-04 12:03:37 -08005742
Anthony Hugh96e9cc52016-07-12 15:17:24 -07005743 // Don't pass back press to app if we've already handled it via long press
Anthony Hugh34f09ca2016-03-04 12:03:37 -08005744 if (handled) {
5745 result &= ~ACTION_PASS_TO_USER;
5746 }
5747 }
5748 break;
5749 }
5750
Jeff Brown4d396052010-10-29 21:50:21 -07005751 case KeyEvent.KEYCODE_VOLUME_DOWN:
Jeff Brownb0418da2010-11-01 15:24:01 -07005752 case KeyEvent.KEYCODE_VOLUME_UP:
5753 case KeyEvent.KEYCODE_VOLUME_MUTE: {
Jeff Brownd5bb82d2011-10-12 13:57:59 -07005754 if (keyCode == KeyEvent.KEYCODE_VOLUME_DOWN) {
5755 if (down) {
Jeff Brown13f00f02014-10-31 14:45:50 -07005756 if (interactive && !mScreenshotChordVolumeDownKeyTriggered
Jeff Brownd5bb82d2011-10-12 13:57:59 -07005757 && (event.getFlags() & KeyEvent.FLAG_FALLBACK) == 0) {
Jeff Brown13f00f02014-10-31 14:45:50 -07005758 mScreenshotChordVolumeDownKeyTriggered = true;
5759 mScreenshotChordVolumeDownKeyTime = event.getDownTime();
5760 mScreenshotChordVolumeDownKeyConsumed = false;
Jeff Brownd5bb82d2011-10-12 13:57:59 -07005761 cancelPendingPowerKeyAction();
5762 interceptScreenshotChord();
5763 }
5764 } else {
Jeff Brown13f00f02014-10-31 14:45:50 -07005765 mScreenshotChordVolumeDownKeyTriggered = false;
Jeff Brownd5bb82d2011-10-12 13:57:59 -07005766 cancelPendingScreenshotChordAction();
5767 }
5768 } else if (keyCode == KeyEvent.KEYCODE_VOLUME_UP) {
5769 if (down) {
Jeff Brown13f00f02014-10-31 14:45:50 -07005770 if (interactive && !mScreenshotChordVolumeUpKeyTriggered
Jeff Brownd5bb82d2011-10-12 13:57:59 -07005771 && (event.getFlags() & KeyEvent.FLAG_FALLBACK) == 0) {
Jeff Brown13f00f02014-10-31 14:45:50 -07005772 mScreenshotChordVolumeUpKeyTriggered = true;
Jeff Brownd5bb82d2011-10-12 13:57:59 -07005773 cancelPendingPowerKeyAction();
5774 cancelPendingScreenshotChordAction();
5775 }
5776 } else {
Jeff Brown13f00f02014-10-31 14:45:50 -07005777 mScreenshotChordVolumeUpKeyTriggered = false;
Jeff Brownd5bb82d2011-10-12 13:57:59 -07005778 cancelPendingScreenshotChordAction();
5779 }
5780 }
Jeff Brown4d396052010-10-29 21:50:21 -07005781 if (down) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -07005782 TelecomManager telecomManager = getTelecommService();
5783 if (telecomManager != null) {
5784 if (telecomManager.isRinging()) {
Santos Cordon6848f722014-05-21 15:22:12 -07005785 // If an incoming call is ringing, either VOLUME key means
5786 // "silence ringer". We handle these keys here, rather than
5787 // in the InCallScreen, to make sure we'll respond to them
5788 // even if the InCallScreen hasn't come to the foreground yet.
5789 // Look for the DOWN event here, to agree with the "fallback"
5790 // behavior in the InCallScreen.
5791 Log.i(TAG, "interceptKeyBeforeQueueing:"
5792 + " VOLUME key-down while ringing: Silence ringer!");
Jeff Brown4d396052010-10-29 21:50:21 -07005793
Santos Cordon6848f722014-05-21 15:22:12 -07005794 // Silence the ringer. (It's safe to call this
5795 // even if the ringer has already been silenced.)
Tyler Gunnef9f6f92014-09-12 22:16:17 -07005796 telecomManager.silenceRinger();
Jeff Brown4d396052010-10-29 21:50:21 -07005797
Santos Cordon6848f722014-05-21 15:22:12 -07005798 // And *don't* pass this key thru to the current activity
5799 // (which is probably the InCallScreen.)
5800 result &= ~ACTION_PASS_TO_USER;
5801 break;
5802 }
Tyler Gunnef9f6f92014-09-12 22:16:17 -07005803 if (telecomManager.isInCall()
Santos Cordon6848f722014-05-21 15:22:12 -07005804 && (result & ACTION_PASS_TO_USER) == 0) {
5805 // If we are in call but we decided not to pass the key to
RoboErik430fc482014-06-12 15:49:20 -07005806 // the application, just pass it to the session service.
5807
5808 MediaSessionLegacyHelper.getHelper(mContext)
RoboErik3c45c292014-07-08 16:47:31 -07005809 .sendVolumeKeyEvent(event, false);
Santos Cordon6848f722014-05-21 15:22:12 -07005810 break;
Jeff Brown4d396052010-10-29 21:50:21 -07005811 }
5812 }
Jaewan Kim765487f2016-01-12 14:45:42 +09005813 }
5814 if (mUseTvRouting) {
5815 // On TVs, defer special key handlings to
5816 // {@link interceptKeyBeforeDispatching()}.
5817 result |= ACTION_PASS_TO_USER;
5818 } else if ((result & ACTION_PASS_TO_USER) == 0) {
5819 // If we aren't passing to the user and no one else
5820 // handled it send it to the session manager to
5821 // figure out.
5822 MediaSessionLegacyHelper.getHelper(mContext)
5823 .sendVolumeKeyEvent(event, true);
Jeff Brown4d396052010-10-29 21:50:21 -07005824 }
5825 break;
5826 }
5827
5828 case KeyEvent.KEYCODE_ENDCALL: {
5829 result &= ~ACTION_PASS_TO_USER;
5830 if (down) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -07005831 TelecomManager telecomManager = getTelecommService();
Jeff Brown4d396052010-10-29 21:50:21 -07005832 boolean hungUp = false;
Tyler Gunnef9f6f92014-09-12 22:16:17 -07005833 if (telecomManager != null) {
5834 hungUp = telecomManager.endCall();
Jeff Brown4d396052010-10-29 21:50:21 -07005835 }
Jeff Brown13f00f02014-10-31 14:45:50 -07005836 if (interactive && !hungUp) {
5837 mEndCallKeyHandled = false;
5838 mHandler.postDelayed(mEndCallLongPress,
5839 ViewConfiguration.get(mContext).getDeviceGlobalActionKeyTimeout());
5840 } else {
5841 mEndCallKeyHandled = true;
5842 }
Jeff Brown4d396052010-10-29 21:50:21 -07005843 } else {
Jeff Brown13f00f02014-10-31 14:45:50 -07005844 if (!mEndCallKeyHandled) {
5845 mHandler.removeCallbacks(mEndCallLongPress);
5846 if (!canceled) {
5847 if ((mEndcallBehavior
5848 & Settings.System.END_BUTTON_BEHAVIOR_HOME) != 0) {
5849 if (goHome()) {
5850 break;
5851 }
Dianne Hackborn0041e972009-07-24 17:14:43 -07005852 }
Jeff Brown13f00f02014-10-31 14:45:50 -07005853 if ((mEndcallBehavior
5854 & Settings.System.END_BUTTON_BEHAVIOR_SLEEP) != 0) {
5855 mPowerManager.goToSleep(event.getEventTime(),
5856 PowerManager.GO_TO_SLEEP_REASON_POWER_BUTTON, 0);
5857 isWakeKey = false;
5858 }
Jeff Brown4d396052010-10-29 21:50:21 -07005859 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005860 }
Jeff Brown4d396052010-10-29 21:50:21 -07005861 }
5862 break;
5863 }
5864
5865 case KeyEvent.KEYCODE_POWER: {
5866 result &= ~ACTION_PASS_TO_USER;
Jeff Brown13f00f02014-10-31 14:45:50 -07005867 isWakeKey = false; // wake-up will be handled separately
Jeff Brown4d396052010-10-29 21:50:21 -07005868 if (down) {
Jeff Brown13f00f02014-10-31 14:45:50 -07005869 interceptPowerKeyDown(event, interactive);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005870 } else {
Jeff Brown13f00f02014-10-31 14:45:50 -07005871 interceptPowerKeyUp(event, interactive, canceled);
Jeff Brown4d396052010-10-29 21:50:21 -07005872 }
5873 break;
5874 }
5875
Jim Miller07e03842016-06-22 15:18:13 -07005876 case KeyEvent.KEYCODE_SYSTEM_NAVIGATION_DOWN:
Jim Millerf4c0a132016-05-17 18:11:52 -07005877 // fall through
Jim Miller07e03842016-06-22 15:18:13 -07005878 case KeyEvent.KEYCODE_SYSTEM_NAVIGATION_UP:
Jim Millerf4c0a132016-05-17 18:11:52 -07005879 // fall through
Jim Miller07e03842016-06-22 15:18:13 -07005880 case KeyEvent.KEYCODE_SYSTEM_NAVIGATION_LEFT:
Jim Millerf4c0a132016-05-17 18:11:52 -07005881 // fall through
Jim Miller07e03842016-06-22 15:18:13 -07005882 case KeyEvent.KEYCODE_SYSTEM_NAVIGATION_RIGHT: {
5883 result &= ~ACTION_PASS_TO_USER;
5884 interceptSystemNavigationKey(event);
Jim Millerf4c0a132016-05-17 18:11:52 -07005885 break;
5886 }
5887
Jeff Brown6212a492014-03-07 13:58:47 -08005888 case KeyEvent.KEYCODE_SLEEP: {
5889 result &= ~ACTION_PASS_TO_USER;
Filip Gruszczynskia483a1d2015-03-17 19:06:58 +00005890 isWakeKey = false;
Jeff Brownbae8e772014-06-12 19:59:45 -07005891 if (!mPowerManager.isInteractive()) {
5892 useHapticFeedback = false; // suppress feedback if already non-interactive
5893 }
Nick Vaccarob593a812015-05-15 11:23:05 -07005894 if (down) {
5895 sleepPress(event.getEventTime());
5896 } else {
5897 sleepRelease(event.getEventTime());
5898 }
Jeff Brown6212a492014-03-07 13:58:47 -08005899 break;
5900 }
5901
Nick Armstrong-Crews56ecfcc2015-09-07 21:46:50 -07005902 case KeyEvent.KEYCODE_SOFT_SLEEP: {
5903 result &= ~ACTION_PASS_TO_USER;
5904 isWakeKey = false;
5905 if (!down) {
5906 mPowerManagerInternal.setUserInactiveOverrideFromWindowManager();
5907 }
5908 break;
5909 }
5910
Jeff Brown6212a492014-03-07 13:58:47 -08005911 case KeyEvent.KEYCODE_WAKEUP: {
5912 result &= ~ACTION_PASS_TO_USER;
Jose Lima9546b202014-07-02 17:21:51 -07005913 isWakeKey = true;
Jeff Brown6212a492014-03-07 13:58:47 -08005914 break;
5915 }
5916
Jeff Brown4d396052010-10-29 21:50:21 -07005917 case KeyEvent.KEYCODE_MEDIA_PLAY:
5918 case KeyEvent.KEYCODE_MEDIA_PAUSE:
5919 case KeyEvent.KEYCODE_MEDIA_PLAY_PAUSE:
Jeff Brown4d396052010-10-29 21:50:21 -07005920 case KeyEvent.KEYCODE_HEADSETHOOK:
5921 case KeyEvent.KEYCODE_MUTE:
5922 case KeyEvent.KEYCODE_MEDIA_STOP:
5923 case KeyEvent.KEYCODE_MEDIA_NEXT:
5924 case KeyEvent.KEYCODE_MEDIA_PREVIOUS:
5925 case KeyEvent.KEYCODE_MEDIA_REWIND:
5926 case KeyEvent.KEYCODE_MEDIA_RECORD:
Jaekyun Seokbfdad8e2013-07-08 13:53:21 +09005927 case KeyEvent.KEYCODE_MEDIA_FAST_FORWARD:
5928 case KeyEvent.KEYCODE_MEDIA_AUDIO_TRACK: {
RoboErikde9ba392014-09-26 12:51:01 -07005929 if (MediaSessionLegacyHelper.getHelper(mContext).isGlobalPriorityActive()) {
5930 // If the global session is active pass all media keys to it
5931 // instead of the active window.
5932 result &= ~ACTION_PASS_TO_USER;
5933 }
Jeff Brown4d396052010-10-29 21:50:21 -07005934 if ((result & ACTION_PASS_TO_USER) == 0) {
5935 // Only do this if we would otherwise not pass it to the user. In that
5936 // case, the PhoneWindow class will do the same thing, except it will
5937 // only do it if the showing app doesn't process the key on its own.
Jeff Brown40013652012-05-16 21:22:36 -07005938 // Note that we need to make a copy of the key event here because the
5939 // original key event will be recycled when we return.
Jeff Brown4d396052010-10-29 21:50:21 -07005940 mBroadcastWakeLock.acquire();
Jeff Brown40013652012-05-16 21:22:36 -07005941 Message msg = mHandler.obtainMessage(MSG_DISPATCH_MEDIA_KEY_WITH_WAKE_LOCK,
5942 new KeyEvent(event));
5943 msg.setAsynchronous(true);
5944 msg.sendToTarget();
Jeff Brown4d396052010-10-29 21:50:21 -07005945 }
5946 break;
Jeff Brown00fa7bd2010-07-02 15:37:36 -07005947 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005948
Jeff Brown4d396052010-10-29 21:50:21 -07005949 case KeyEvent.KEYCODE_CALL: {
5950 if (down) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -07005951 TelecomManager telecomManager = getTelecommService();
5952 if (telecomManager != null) {
5953 if (telecomManager.isRinging()) {
Santos Cordon6848f722014-05-21 15:22:12 -07005954 Log.i(TAG, "interceptKeyBeforeQueueing:"
5955 + " CALL key-down while ringing: Answer the call!");
Tyler Gunnef9f6f92014-09-12 22:16:17 -07005956 telecomManager.acceptRingingCall();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005957
Santos Cordon6848f722014-05-21 15:22:12 -07005958 // And *don't* pass this key thru to the current activity
5959 // (which is presumably the InCallScreen.)
5960 result &= ~ACTION_PASS_TO_USER;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005961 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005962 }
Jeff Brown00fa7bd2010-07-02 15:37:36 -07005963 }
Jeff Brown4d396052010-10-29 21:50:21 -07005964 break;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005965 }
Michael Wright869a67c2014-08-26 19:33:06 -07005966 case KeyEvent.KEYCODE_VOICE_ASSIST: {
5967 // Only do this if we would otherwise not pass it to the user. In that case,
5968 // interceptKeyBeforeDispatching would apply a similar but different policy in
5969 // order to invoke voice assist actions. Note that we need to make a copy of the
5970 // key event here because the original key event will be recycled when we return.
5971 if ((result & ACTION_PASS_TO_USER) == 0 && !down) {
5972 mBroadcastWakeLock.acquire();
5973 Message msg = mHandler.obtainMessage(MSG_LAUNCH_VOICE_ASSIST_WITH_WAKE_LOCK,
5974 keyguardActive ? 1 : 0, 0);
5975 msg.setAsynchronous(true);
5976 msg.sendToTarget();
5977 }
Jaewan Kim49117872016-01-19 17:24:08 +09005978 break;
5979 }
5980 case KeyEvent.KEYCODE_WINDOW: {
5981 if (mShortPressWindowBehavior == SHORT_PRESS_WINDOW_PICTURE_IN_PICTURE) {
Jaewan Kimf0fd2182016-04-20 21:17:58 +09005982 if (mTvPictureInPictureVisible) {
5983 // Consumes the key only if picture-in-picture is visible
5984 // to show picture-in-picture control menu.
5985 // This gives a chance to the foreground activity
5986 // to customize PIP key behavior.
5987 if (!down) {
5988 showTvPictureInPictureMenu(event);
5989 }
5990 result &= ~ACTION_PASS_TO_USER;
Jaewan Kim49117872016-01-19 17:24:08 +09005991 }
Jaewan Kim49117872016-01-19 17:24:08 +09005992 }
5993 break;
Michael Wright869a67c2014-08-26 19:33:06 -07005994 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005995 }
Jeff Brown26875502014-01-30 21:47:47 -08005996
Jeff Brownbae8e772014-06-12 19:59:45 -07005997 if (useHapticFeedback) {
5998 performHapticFeedbackLw(null, HapticFeedbackConstants.VIRTUAL_KEY, false);
5999 }
6000
Jeff Brown26875502014-01-30 21:47:47 -08006001 if (isWakeKey) {
Dianne Hackborn280a64e2015-07-13 14:48:08 -07006002 wakeUp(event.getEventTime(), mAllowTheaterModeWakeFromKey, "android.policy:KEY");
Jeff Brown26875502014-01-30 21:47:47 -08006003 }
Bryce Lee584a4452014-10-21 15:55:55 -07006004
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006005 return result;
6006 }
6007
Jeff Brown1c2e4942012-11-06 16:32:01 -08006008 /**
Jim Millerf4c0a132016-05-17 18:11:52 -07006009 * Handle statusbar expansion events.
6010 * @param event
6011 */
Jim Miller07e03842016-06-22 15:18:13 -07006012 private void interceptSystemNavigationKey(KeyEvent event) {
Doris Ling628cea42016-06-09 10:35:02 -07006013 if (event.getAction() == KeyEvent.ACTION_UP && areSystemNavigationKeysEnabled()) {
Jim Millerf4c0a132016-05-17 18:11:52 -07006014 IStatusBarService sbar = getStatusBarService();
6015 if (sbar != null) {
6016 try {
Jim Miller07e03842016-06-22 15:18:13 -07006017 sbar.handleSystemNavigationKey(event.getKeyCode());
Jim Millerf4c0a132016-05-17 18:11:52 -07006018 } catch (RemoteException e1) {
6019 // oops, no statusbar. Ignore event.
6020 }
6021 }
6022 }
6023 }
6024
6025 /**
Jeff Brown13f00f02014-10-31 14:45:50 -07006026 * Returns true if the key can have global actions attached to it.
6027 * We reserve all power management keys for the system since they require
6028 * very careful handling.
6029 */
6030 private static boolean isValidGlobalKey(int keyCode) {
6031 switch (keyCode) {
6032 case KeyEvent.KEYCODE_POWER:
6033 case KeyEvent.KEYCODE_WAKEUP:
6034 case KeyEvent.KEYCODE_SLEEP:
6035 return false;
6036 default:
6037 return true;
6038 }
6039 }
6040
6041 /**
Jeff Brown1c2e4942012-11-06 16:32:01 -08006042 * When the screen is off we ignore some keys that might otherwise typically
6043 * be considered wake keys. We filter them out here.
6044 *
6045 * {@link KeyEvent#KEYCODE_POWER} is notably absent from this list because it
6046 * is always considered a wake key.
6047 */
6048 private boolean isWakeKeyWhenScreenOff(int keyCode) {
6049 switch (keyCode) {
6050 // ignore volume keys unless docked
6051 case KeyEvent.KEYCODE_VOLUME_UP:
6052 case KeyEvent.KEYCODE_VOLUME_DOWN:
6053 case KeyEvent.KEYCODE_VOLUME_MUTE:
6054 return mDockMode != Intent.EXTRA_DOCK_STATE_UNDOCKED;
6055
6056 // ignore media and camera keys
6057 case KeyEvent.KEYCODE_MUTE:
6058 case KeyEvent.KEYCODE_HEADSETHOOK:
6059 case KeyEvent.KEYCODE_MEDIA_PLAY:
6060 case KeyEvent.KEYCODE_MEDIA_PAUSE:
6061 case KeyEvent.KEYCODE_MEDIA_PLAY_PAUSE:
6062 case KeyEvent.KEYCODE_MEDIA_STOP:
6063 case KeyEvent.KEYCODE_MEDIA_NEXT:
6064 case KeyEvent.KEYCODE_MEDIA_PREVIOUS:
6065 case KeyEvent.KEYCODE_MEDIA_REWIND:
6066 case KeyEvent.KEYCODE_MEDIA_RECORD:
6067 case KeyEvent.KEYCODE_MEDIA_FAST_FORWARD:
Jaekyun Seokbfdad8e2013-07-08 13:53:21 +09006068 case KeyEvent.KEYCODE_MEDIA_AUDIO_TRACK:
Jeff Brown1c2e4942012-11-06 16:32:01 -08006069 case KeyEvent.KEYCODE_CAMERA:
6070 return false;
6071 }
6072 return true;
6073 }
6074
6075
Jeff Brown56194eb2011-03-02 19:23:13 -08006076 /** {@inheritDoc} */
6077 @Override
Michael Wright70af00a2014-09-03 19:30:20 -07006078 public int interceptMotionBeforeQueueingNonInteractive(long whenNanos, int policyFlags) {
6079 if ((policyFlags & FLAG_WAKE) != 0) {
Dianne Hackborn280a64e2015-07-13 14:48:08 -07006080 if (wakeUp(whenNanos / 1000000, mAllowTheaterModeWakeFromMotion,
6081 "android.policy:MOTION")) {
Bryce Lee5c138322014-11-03 08:26:09 -08006082 return 0;
6083 }
Michael Wright70af00a2014-09-03 19:30:20 -07006084 }
Bryce Lee5c138322014-11-03 08:26:09 -08006085
Anthony Hugh4b13ab82016-05-17 13:03:00 -07006086 if (shouldDispatchInputWhenNonInteractive(null)) {
Michael Wright70af00a2014-09-03 19:30:20 -07006087 return ACTION_PASS_TO_USER;
6088 }
Bryce Lee5c138322014-11-03 08:26:09 -08006089
Bryce Lee812d7022014-11-10 13:33:28 -08006090 // If we have not passed the action up and we are in theater mode without dreaming,
6091 // there will be no dream to intercept the touch and wake into ambient. The device should
6092 // wake up in this case.
6093 if (isTheaterModeEnabled() && (policyFlags & FLAG_WAKE) != 0) {
Dianne Hackborn280a64e2015-07-13 14:48:08 -07006094 wakeUp(whenNanos / 1000000, mAllowTheaterModeWakeFromMotionWhenNotDreaming,
6095 "android.policy:MOTION");
Bryce Lee812d7022014-11-10 13:33:28 -08006096 }
6097
Jeff Brown037c33e2014-04-09 00:31:55 -07006098 return 0;
Jeff Brown56194eb2011-03-02 19:23:13 -08006099 }
6100
Anthony Hugh4b13ab82016-05-17 13:03:00 -07006101 private boolean shouldDispatchInputWhenNonInteractive(KeyEvent event) {
Wale Ogunwale6b15ea52016-04-04 07:28:27 -07006102 final boolean displayOff = (mDisplay == null || mDisplay.getState() == Display.STATE_OFF);
6103
6104 if (displayOff && !mHasFeatureWatch) {
6105 return false;
6106 }
6107
6108 // Send events to keyguard while the screen is on and it's showing.
6109 if (isKeyguardShowingAndNotOccluded() && !displayOff) {
Bryce Lee5c138322014-11-03 08:26:09 -08006110 return true;
6111 }
6112
Anthony Hugh4b13ab82016-05-17 13:03:00 -07006113 // Watches handle BACK specially
6114 if (mHasFeatureWatch
6115 && event != null
6116 && (event.getKeyCode() == KeyEvent.KEYCODE_BACK
6117 || event.getKeyCode() == KeyEvent.KEYCODE_STEM_PRIMARY)) {
6118 return false;
6119 }
6120
Bryce Lee5c138322014-11-03 08:26:09 -08006121 // Send events to a dozing dream even if the screen is off since the dream
6122 // is in control of the state of the screen.
6123 IDreamManager dreamManager = getDreamManager();
6124
6125 try {
6126 if (dreamManager != null && dreamManager.isDreaming()) {
6127 return true;
6128 }
6129 } catch (RemoteException e) {
6130 Slog.e(TAG, "RemoteException when checking if dreaming", e);
6131 }
6132
6133 // Otherwise, consume events since the user can't see what is being
6134 // interacted with.
6135 return false;
Michael Wright70af00a2014-09-03 19:30:20 -07006136 }
6137
RoboErik001c59c2015-01-26 15:53:51 -08006138 private void dispatchDirectAudioEvent(KeyEvent event) {
6139 if (event.getAction() != KeyEvent.ACTION_DOWN) {
6140 return;
6141 }
6142 int keyCode = event.getKeyCode();
John Spurlockb94f2d62015-03-17 14:11:57 -04006143 int flags = AudioManager.FLAG_SHOW_UI | AudioManager.FLAG_PLAY_SOUND
6144 | AudioManager.FLAG_FROM_KEY;
RoboErik001c59c2015-01-26 15:53:51 -08006145 String pkgName = mContext.getOpPackageName();
6146 switch (keyCode) {
6147 case KeyEvent.KEYCODE_VOLUME_UP:
6148 try {
John Spurlockee5ad722015-03-03 16:17:21 -05006149 getAudioService().adjustSuggestedStreamVolume(AudioManager.ADJUST_RAISE,
John Spurlock90874332015-03-10 16:00:54 -04006150 AudioManager.USE_DEFAULT_STREAM_TYPE, flags, pkgName, TAG);
RoboErik001c59c2015-01-26 15:53:51 -08006151 } catch (RemoteException e) {
6152 Log.e(TAG, "Error dispatching volume up in dispatchTvAudioEvent.", e);
6153 }
6154 break;
6155 case KeyEvent.KEYCODE_VOLUME_DOWN:
6156 try {
John Spurlockee5ad722015-03-03 16:17:21 -05006157 getAudioService().adjustSuggestedStreamVolume(AudioManager.ADJUST_LOWER,
John Spurlock90874332015-03-10 16:00:54 -04006158 AudioManager.USE_DEFAULT_STREAM_TYPE, flags, pkgName, TAG);
RoboErik001c59c2015-01-26 15:53:51 -08006159 } catch (RemoteException e) {
6160 Log.e(TAG, "Error dispatching volume down in dispatchTvAudioEvent.", e);
6161 }
6162 break;
6163 case KeyEvent.KEYCODE_VOLUME_MUTE:
6164 try {
6165 if (event.getRepeatCount() == 0) {
John Spurlockee5ad722015-03-03 16:17:21 -05006166 getAudioService().adjustSuggestedStreamVolume(
6167 AudioManager.ADJUST_TOGGLE_MUTE,
John Spurlock90874332015-03-10 16:00:54 -04006168 AudioManager.USE_DEFAULT_STREAM_TYPE, flags, pkgName, TAG);
RoboErik001c59c2015-01-26 15:53:51 -08006169 }
6170 } catch (RemoteException e) {
6171 Log.e(TAG, "Error dispatching mute in dispatchTvAudioEvent.", e);
6172 }
6173 break;
6174 }
6175 }
6176
Jeff Brown40013652012-05-16 21:22:36 -07006177 void dispatchMediaKeyWithWakeLock(KeyEvent event) {
6178 if (DEBUG_INPUT) {
6179 Slog.d(TAG, "dispatchMediaKeyWithWakeLock: " + event);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006180 }
6181
Jeff Brown40013652012-05-16 21:22:36 -07006182 if (mHavePendingMediaKeyRepeatWithWakeLock) {
6183 if (DEBUG_INPUT) {
6184 Slog.d(TAG, "dispatchMediaKeyWithWakeLock: canceled repeat");
6185 }
6186
6187 mHandler.removeMessages(MSG_DISPATCH_MEDIA_KEY_REPEAT_WITH_WAKE_LOCK);
6188 mHavePendingMediaKeyRepeatWithWakeLock = false;
6189 mBroadcastWakeLock.release(); // pending repeat was holding onto the wake lock
6190 }
6191
6192 dispatchMediaKeyWithWakeLockToAudioService(event);
6193
6194 if (event.getAction() == KeyEvent.ACTION_DOWN
6195 && event.getRepeatCount() == 0) {
6196 mHavePendingMediaKeyRepeatWithWakeLock = true;
6197
6198 Message msg = mHandler.obtainMessage(
6199 MSG_DISPATCH_MEDIA_KEY_REPEAT_WITH_WAKE_LOCK, event);
6200 msg.setAsynchronous(true);
6201 mHandler.sendMessageDelayed(msg, ViewConfiguration.getKeyRepeatTimeout());
6202 } else {
6203 mBroadcastWakeLock.release();
6204 }
6205 }
6206
6207 void dispatchMediaKeyRepeatWithWakeLock(KeyEvent event) {
6208 mHavePendingMediaKeyRepeatWithWakeLock = false;
6209
6210 KeyEvent repeatEvent = KeyEvent.changeTimeRepeat(event,
6211 SystemClock.uptimeMillis(), 1, event.getFlags() | KeyEvent.FLAG_LONG_PRESS);
6212 if (DEBUG_INPUT) {
6213 Slog.d(TAG, "dispatchMediaKeyRepeatWithWakeLock: " + repeatEvent);
6214 }
6215
6216 dispatchMediaKeyWithWakeLockToAudioService(repeatEvent);
6217 mBroadcastWakeLock.release();
6218 }
6219
6220 void dispatchMediaKeyWithWakeLockToAudioService(KeyEvent event) {
Sudheer Shankafc46e9b2016-10-21 17:55:27 -07006221 if (mActivityManagerInternal.isSystemReady()) {
RoboErik430fc482014-06-12 15:49:20 -07006222 MediaSessionLegacyHelper.getHelper(mContext).sendMediaButtonEvent(event, true);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006223 }
6224 }
6225
Michael Wright869a67c2014-08-26 19:33:06 -07006226 void launchVoiceAssistWithWakeLock(boolean keyguardActive) {
Dianne Hackbornb6683c42015-06-18 17:40:33 -07006227 IDeviceIdleController dic = IDeviceIdleController.Stub.asInterface(
6228 ServiceManager.getService(Context.DEVICE_IDLE_CONTROLLER));
6229 if (dic != null) {
6230 try {
6231 dic.exitIdle("voice-search");
6232 } catch (RemoteException e) {
6233 }
6234 }
Michael Wright869a67c2014-08-26 19:33:06 -07006235 Intent voiceIntent =
6236 new Intent(RecognizerIntent.ACTION_VOICE_SEARCH_HANDS_FREE);
6237 voiceIntent.putExtra(RecognizerIntent.EXTRA_SECURE, keyguardActive);
Bart Sears8b1c27c2015-03-18 23:51:02 +00006238 startActivityAsUser(voiceIntent, UserHandle.CURRENT_OR_SELF);
Michael Wright869a67c2014-08-26 19:33:06 -07006239 mBroadcastWakeLock.release();
6240 }
6241
Mike Lockwood1753f7f2009-08-24 14:49:07 -07006242 BroadcastReceiver mDockReceiver = new BroadcastReceiver() {
Craig Mautnereee29c42013-01-17 14:44:34 -08006243 @Override
Mike Lockwood1753f7f2009-08-24 14:49:07 -07006244 public void onReceive(Context context, Intent intent) {
Dianne Hackborn867ab6472010-04-29 13:28:56 -07006245 if (Intent.ACTION_DOCK_EVENT.equals(intent.getAction())) {
6246 mDockMode = intent.getIntExtra(Intent.EXTRA_DOCK_STATE,
6247 Intent.EXTRA_DOCK_STATE_UNDOCKED);
Daniel Sandler6396c722013-04-16 20:19:09 -04006248 } else {
6249 try {
6250 IUiModeManager uiModeService = IUiModeManager.Stub.asInterface(
6251 ServiceManager.getService(Context.UI_MODE_SERVICE));
6252 mUiMode = uiModeService.getCurrentModeType();
6253 } catch (RemoteException e) {
6254 }
Dianne Hackborn80fa1662009-10-07 14:02:10 -07006255 }
Jeff Brown01a98dd2011-09-20 15:08:29 -07006256 updateRotation(true);
Craig Mautnereee29c42013-01-17 14:44:34 -08006257 synchronized (mLock) {
6258 updateOrientationListenerLp();
6259 }
Mike Lockwood1753f7f2009-08-24 14:49:07 -07006260 }
6261 };
6262
Jeff Brown6aaf2952012-10-05 16:01:08 -07006263 BroadcastReceiver mDreamReceiver = new BroadcastReceiver() {
6264 @Override
6265 public void onReceive(Context context, Intent intent) {
6266 if (Intent.ACTION_DREAMING_STARTED.equals(intent.getAction())) {
Jim Miller5ecd8112013-01-09 18:50:26 -08006267 if (mKeyguardDelegate != null) {
6268 mKeyguardDelegate.onDreamingStarted();
Jeff Brown6aaf2952012-10-05 16:01:08 -07006269 }
6270 } else if (Intent.ACTION_DREAMING_STOPPED.equals(intent.getAction())) {
Jim Miller5ecd8112013-01-09 18:50:26 -08006271 if (mKeyguardDelegate != null) {
6272 mKeyguardDelegate.onDreamingStopped();
Jeff Brown6aaf2952012-10-05 16:01:08 -07006273 }
6274 }
6275 }
6276 };
6277
Christopher Tate5e08af02012-09-21 17:17:22 -07006278 BroadcastReceiver mMultiuserReceiver = new BroadcastReceiver() {
6279 @Override
6280 public void onReceive(Context context, Intent intent) {
6281 if (Intent.ACTION_USER_SWITCHED.equals(intent.getAction())) {
6282 // tickle the settings observer: this first ensures that we're
6283 // observing the relevant settings for the newly-active user,
6284 // and then updates our own bookkeeping based on the now-
6285 // current user.
6286 mSettingsObserver.onChange(false);
John Spurlockce479d82012-11-29 09:52:21 -05006287
6288 // force a re-application of focused window sysui visibility.
6289 // the window may never have been shown for this user
6290 // e.g. the keyguard when going through the new-user setup flow
John Spurlock04db1762013-05-13 12:46:41 -04006291 synchronized (mWindowManagerFuncs.getWindowManagerLock()) {
John Spurlockce479d82012-11-29 09:52:21 -05006292 mLastSystemUiFlags = 0;
6293 updateSystemUiVisibilityLw();
6294 }
Christopher Tate5e08af02012-09-21 17:17:22 -07006295 }
6296 }
6297 };
6298
Adrian Roosddc8b272015-05-21 16:28:27 -07006299 private final Runnable mHiddenNavPanic = new Runnable() {
John Spurlockd9b70bd2014-02-06 17:02:44 -05006300 @Override
6301 public void run() {
Adrian Roosddc8b272015-05-21 16:28:27 -07006302 synchronized (mWindowManagerFuncs.getWindowManagerLock()) {
6303 if (!isUserSetupComplete()) {
6304 // Swipe-up for navigation bar is disabled during setup
6305 return;
6306 }
6307 mPendingPanicGestureUptime = SystemClock.uptimeMillis();
Adrian Roos1f425902016-07-22 10:37:50 -07006308 if (!isNavBarEmpty(mLastSystemUiFlags)) {
6309 mNavigationBarController.showTransient();
6310 }
Adrian Roosddc8b272015-05-21 16:28:27 -07006311 }
John Spurlockd9b70bd2014-02-06 17:02:44 -05006312 }
6313 };
6314
John Spurlocke1f366f2013-08-05 12:22:40 -04006315 private void requestTransientBars(WindowState swipeTarget) {
John Spurlock04db1762013-05-13 12:46:41 -04006316 synchronized (mWindowManagerFuncs.getWindowManagerLock()) {
Maurice Lam99c6e072014-04-28 18:24:28 -07006317 if (!isUserSetupComplete()) {
6318 // Swipe-up for navigation bar is disabled during setup
6319 return;
6320 }
John Spurlock27735a42013-08-14 17:57:38 -04006321 boolean sb = mStatusBarController.checkShowTransientBarLw();
Adrian Roos1f425902016-07-22 10:37:50 -07006322 boolean nb = mNavigationBarController.checkShowTransientBarLw()
6323 && !isNavBarEmpty(mLastSystemUiFlags);
John Spurlockad3e6cb2013-04-30 08:47:43 -04006324 if (sb || nb) {
Adrian Roos62b65e42015-02-25 18:05:34 +01006325 // Don't show status bar when swiping on already visible navigation bar
6326 if (!nb && swipeTarget == mNavigationBar) {
John Spurlocke1f366f2013-08-05 12:22:40 -04006327 if (DEBUG) Slog.d(TAG, "Not showing transient bar, wrong swipe target");
John Spurlockad3e6cb2013-04-30 08:47:43 -04006328 return;
6329 }
John Spurlock27735a42013-08-14 17:57:38 -04006330 if (sb) mStatusBarController.showTransient();
6331 if (nb) mNavigationBarController.showTransient();
John Spurlockf1a36642013-10-12 17:50:42 -04006332 mImmersiveModeConfirmation.confirmCurrentPrompt();
John Spurlockad3e6cb2013-04-30 08:47:43 -04006333 updateSystemUiVisibilityLw();
John Spurlock32beb2c2013-03-11 10:16:47 -04006334 }
John Spurlockad3e6cb2013-04-30 08:47:43 -04006335 }
6336 }
6337
Jeff Brown3ee549c2014-09-22 20:14:39 -07006338 // Called on the PowerManager's Notifier thread.
Jeff Brownc38c9be2012-10-04 13:16:19 -07006339 @Override
Jeff Brown416c49c2015-05-26 19:50:18 -07006340 public void startedGoingToSleep(int why) {
6341 if (DEBUG_WAKEUP) Slog.i(TAG, "Started going to sleep... (why=" + why + ")");
Jorim Jaggif1cdf952016-04-05 21:41:06 -07006342 mCameraGestureTriggeredDuringGoingToSleep = false;
6343 mGoingToSleep = true;
Jorim Jaggid175b6c2015-05-27 15:39:09 -07006344 if (mKeyguardDelegate != null) {
6345 mKeyguardDelegate.onStartedGoingToSleep(why);
6346 }
Jeff Brown416c49c2015-05-26 19:50:18 -07006347 }
6348
6349 // Called on the PowerManager's Notifier thread.
6350 @Override
6351 public void finishedGoingToSleep(int why) {
Dianne Hackborn74489012009-03-24 20:50:09 -07006352 EventLog.writeEvent(70000, 0);
Jeff Brown416c49c2015-05-26 19:50:18 -07006353 if (DEBUG_WAKEUP) Slog.i(TAG, "Finished going to sleep... (why=" + why + ")");
Chris Wren9bb290b2015-06-29 12:02:13 -04006354 MetricsLogger.histogram(mContext, "screen_timeout", mLockScreenTimeout / 1000);
Jeff Brown3ee549c2014-09-22 20:14:39 -07006355
Jorim Jaggif1cdf952016-04-05 21:41:06 -07006356 mGoingToSleep = false;
6357
Jeff Brown3ee549c2014-09-22 20:14:39 -07006358 // We must get this work done here because the power manager will drop
6359 // the wake lock and let the system suspend once this function returns.
The Android Open Source Project0727d222009-03-11 12:11:58 -07006360 synchronized (mLock) {
Jeff Brown3ee549c2014-09-22 20:14:39 -07006361 mAwake = false;
Jeff Browna20dda42014-05-27 20:57:24 -07006362 updateWakeGestureListenerLp();
The Android Open Source Project0727d222009-03-11 12:11:58 -07006363 updateOrientationListenerLp();
Mike Lockwood28569302010-01-28 11:54:40 -05006364 updateLockScreenTimeout();
The Android Open Source Project0727d222009-03-11 12:11:58 -07006365 }
Jeff Brown3ee549c2014-09-22 20:14:39 -07006366 if (mKeyguardDelegate != null) {
Jorim Jaggif1cdf952016-04-05 21:41:06 -07006367 mKeyguardDelegate.onFinishedGoingToSleep(why,
6368 mCameraGestureTriggeredDuringGoingToSleep);
Jeff Brown3ee549c2014-09-22 20:14:39 -07006369 }
Jorim Jaggif1cdf952016-04-05 21:41:06 -07006370 mCameraGestureTriggeredDuringGoingToSleep = false;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006371 }
6372
Jeff Brown3ee549c2014-09-22 20:14:39 -07006373 // Called on the PowerManager's Notifier thread.
Jeff Brownc38c9be2012-10-04 13:16:19 -07006374 @Override
Jeff Brown416c49c2015-05-26 19:50:18 -07006375 public void startedWakingUp() {
Dianne Hackborn74489012009-03-24 20:50:09 -07006376 EventLog.writeEvent(70000, 1);
Jeff Brown416c49c2015-05-26 19:50:18 -07006377 if (DEBUG_WAKEUP) Slog.i(TAG, "Started waking up...");
Craig Mautner8a0da012014-05-31 15:13:37 -07006378
Jeff Brown3ee549c2014-09-22 20:14:39 -07006379 // Since goToSleep performs these functions synchronously, we must
6380 // do the same here. We cannot post this work to a handler because
6381 // that might cause it to become reordered with respect to what
6382 // may happen in a future call to goToSleep.
The Android Open Source Project0727d222009-03-11 12:11:58 -07006383 synchronized (mLock) {
Jeff Brown3ee549c2014-09-22 20:14:39 -07006384 mAwake = true;
Jeff Brown3ee549c2014-09-22 20:14:39 -07006385
Jeff Browna20dda42014-05-27 20:57:24 -07006386 updateWakeGestureListenerLp();
The Android Open Source Project0727d222009-03-11 12:11:58 -07006387 updateOrientationListenerLp();
Mike Lockwood28569302010-01-28 11:54:40 -05006388 updateLockScreenTimeout();
The Android Open Source Project0727d222009-03-11 12:11:58 -07006389 }
Jeff Brownc38c9be2012-10-04 13:16:19 -07006390
Jim Miller5ecd8112013-01-09 18:50:26 -08006391 if (mKeyguardDelegate != null) {
Jorim Jaggi4cfdcf52015-07-09 12:13:59 -07006392 mKeyguardDelegate.onStartedWakingUp();
Jeff Brownc38c9be2012-10-04 13:16:19 -07006393 }
Jeff Brown36c4db82014-09-19 12:05:31 -07006394 }
6395
Jeff Brown416c49c2015-05-26 19:50:18 -07006396 // Called on the PowerManager's Notifier thread.
6397 @Override
6398 public void finishedWakingUp() {
6399 if (DEBUG_WAKEUP) Slog.i(TAG, "Finished waking up...");
6400 }
6401
6402 private void wakeUpFromPowerKey(long eventTime) {
Dianne Hackborn280a64e2015-07-13 14:48:08 -07006403 wakeUp(eventTime, mAllowTheaterModeWakeFromPowerKey, "android.policy:POWER");
Jeff Brown416c49c2015-05-26 19:50:18 -07006404 }
6405
Dianne Hackborn280a64e2015-07-13 14:48:08 -07006406 private boolean wakeUp(long wakeTime, boolean wakeInTheaterMode, String reason) {
Bryce Leed3896842015-06-23 17:06:51 -07006407 final boolean theaterModeEnabled = isTheaterModeEnabled();
6408 if (!wakeInTheaterMode && theaterModeEnabled) {
Jeff Brown416c49c2015-05-26 19:50:18 -07006409 return false;
6410 }
6411
Bryce Leed3896842015-06-23 17:06:51 -07006412 if (theaterModeEnabled) {
6413 Settings.Global.putInt(mContext.getContentResolver(),
6414 Settings.Global.THEATER_MODE_ON, 0);
6415 }
6416
Dianne Hackborn280a64e2015-07-13 14:48:08 -07006417 mPowerManager.wakeUp(wakeTime, reason);
Jeff Brown416c49c2015-05-26 19:50:18 -07006418 return true;
6419 }
6420
Jeff Brown36c4db82014-09-19 12:05:31 -07006421 private void finishKeyguardDrawn() {
Jeff Brown3ee549c2014-09-22 20:14:39 -07006422 synchronized (mLock) {
Jorim Jaggif3255482015-07-24 12:32:42 -07006423 if (!mScreenOnEarly || mKeyguardDrawComplete) {
Stefan Kuhne9326dc12015-06-12 09:25:32 -10006424 return; // We are not awake yet or we have already informed of this event.
Jeff Brown3ee549c2014-09-22 20:14:39 -07006425 }
6426
Jeff Brown36c4db82014-09-19 12:05:31 -07006427 mKeyguardDrawComplete = true;
Jeff Brown3ee549c2014-09-22 20:14:39 -07006428 if (mKeyguardDelegate != null) {
6429 mHandler.removeMessages(MSG_KEYGUARD_DRAWN_TIMEOUT);
6430 }
Jorim Jaggi4cfdcf52015-07-09 12:13:59 -07006431 mWindowManagerDrawComplete = false;
Jeff Brown3ee549c2014-09-22 20:14:39 -07006432 }
6433
Jorim Jaggi4cfdcf52015-07-09 12:13:59 -07006434 // ... eventually calls finishWindowsDrawn which will finalize our screen turn on
6435 // as well as enabling the orientation change logic/sensor.
6436 mWindowManagerInternal.waitForAllWindowsDrawn(mWindowManagerDrawCallback,
6437 WAITING_FOR_DRAWN_TIMEOUT);
Jeff Brown3ee549c2014-09-22 20:14:39 -07006438 }
6439
6440 // Called on the DisplayManager's DisplayPowerController thread.
6441 @Override
6442 public void screenTurnedOff() {
6443 if (DEBUG_WAKEUP) Slog.i(TAG, "Screen turned off...");
6444
Jeff Brown48d1b142015-06-10 16:36:03 -07006445 updateScreenOffSleepToken(true);
Jeff Brown3ee549c2014-09-22 20:14:39 -07006446 synchronized (mLock) {
6447 mScreenOnEarly = false;
6448 mScreenOnFully = false;
Jorim Jaggi95c6dae2015-07-29 15:17:23 -07006449 mKeyguardDrawComplete = false;
Jeff Brown3ee549c2014-09-22 20:14:39 -07006450 mWindowManagerDrawComplete = false;
6451 mScreenOnListener = null;
6452 updateOrientationListenerLp();
Jorim Jaggi0d210f62015-07-10 14:24:44 -07006453
6454 if (mKeyguardDelegate != null) {
6455 mKeyguardDelegate.onScreenTurnedOff();
6456 }
Jeff Brown36c4db82014-09-19 12:05:31 -07006457 }
6458 }
6459
Jeff Brown3ee549c2014-09-22 20:14:39 -07006460 // Called on the DisplayManager's DisplayPowerController thread.
Jeff Brown36c4db82014-09-19 12:05:31 -07006461 @Override
6462 public void screenTurningOn(final ScreenOnListener screenOnListener) {
Jeff Brown36c4db82014-09-19 12:05:31 -07006463 if (DEBUG_WAKEUP) Slog.i(TAG, "Screen turning on...");
Jeff Brown36c4db82014-09-19 12:05:31 -07006464
Jeff Brown48d1b142015-06-10 16:36:03 -07006465 updateScreenOffSleepToken(false);
Jeff Brown3ee549c2014-09-22 20:14:39 -07006466 synchronized (mLock) {
6467 mScreenOnEarly = true;
6468 mScreenOnFully = false;
Jorim Jaggi95c6dae2015-07-29 15:17:23 -07006469 mKeyguardDrawComplete = false;
Jeff Brown3ee549c2014-09-22 20:14:39 -07006470 mWindowManagerDrawComplete = false;
6471 mScreenOnListener = screenOnListener;
Jeff Brown36c4db82014-09-19 12:05:31 -07006472
Jorim Jaggi4cfdcf52015-07-09 12:13:59 -07006473 if (mKeyguardDelegate != null) {
Jorim Jaggia4b51bc2015-08-10 18:20:43 -07006474 mHandler.removeMessages(MSG_KEYGUARD_DRAWN_TIMEOUT);
6475 mHandler.sendEmptyMessageDelayed(MSG_KEYGUARD_DRAWN_TIMEOUT, 1000);
Jorim Jaggi4cfdcf52015-07-09 12:13:59 -07006476 mKeyguardDelegate.onScreenTurningOn(mKeyguardDrawnCallback);
6477 } else {
6478 if (DEBUG_WAKEUP) Slog.d(TAG,
6479 "null mKeyguardDelegate: setting mKeyguardDrawComplete.");
6480 finishKeyguardDrawn();
6481 }
6482 }
Jeff Brown36c4db82014-09-19 12:05:31 -07006483 }
6484
Jorim Jaggi0d210f62015-07-10 14:24:44 -07006485 // Called on the DisplayManager's DisplayPowerController thread.
6486 @Override
6487 public void screenTurnedOn() {
6488 synchronized (mLock) {
6489 if (mKeyguardDelegate != null) {
6490 mKeyguardDelegate.onScreenTurnedOn();
6491 }
6492 }
6493 }
6494
Jeff Brown36c4db82014-09-19 12:05:31 -07006495 private void finishWindowsDrawn() {
Jeff Brown3ee549c2014-09-22 20:14:39 -07006496 synchronized (mLock) {
6497 if (!mScreenOnEarly || mWindowManagerDrawComplete) {
Stefan Kuhne9326dc12015-06-12 09:25:32 -10006498 return; // Screen is not turned on or we did already handle this case earlier.
Jeff Brown3ee549c2014-09-22 20:14:39 -07006499 }
6500
Jeff Brown36c4db82014-09-19 12:05:31 -07006501 mWindowManagerDrawComplete = true;
Jeff Brown36c4db82014-09-19 12:05:31 -07006502 }
Jeff Brown3ee549c2014-09-22 20:14:39 -07006503
6504 finishScreenTurningOn();
Jeff Brownc38c9be2012-10-04 13:16:19 -07006505 }
6506
Craig Mautner8a0da012014-05-31 15:13:37 -07006507 private void finishScreenTurningOn() {
Stefan Kuhne9326dc12015-06-12 09:25:32 -10006508 synchronized (mLock) {
6509 // We have just finished drawing screen content. Since the orientation listener
6510 // gets only installed when all windows are drawn, we try to install it again.
6511 updateOrientationListenerLp();
6512 }
Jeff Brown3ee549c2014-09-22 20:14:39 -07006513 final ScreenOnListener listener;
6514 final boolean enableScreen;
Jeff Brown36c4db82014-09-19 12:05:31 -07006515 synchronized (mLock) {
Jeff Brown3ee549c2014-09-22 20:14:39 -07006516 if (DEBUG_WAKEUP) Slog.d(TAG,
6517 "finishScreenTurningOn: mAwake=" + mAwake
6518 + ", mScreenOnEarly=" + mScreenOnEarly
6519 + ", mScreenOnFully=" + mScreenOnFully
6520 + ", mKeyguardDrawComplete=" + mKeyguardDrawComplete
6521 + ", mWindowManagerDrawComplete=" + mWindowManagerDrawComplete);
6522
6523 if (mScreenOnFully || !mScreenOnEarly || !mWindowManagerDrawComplete
6524 || (mAwake && !mKeyguardDrawComplete)) {
6525 return; // spurious or not ready yet
Jeff Brown36c4db82014-09-19 12:05:31 -07006526 }
6527
Jeff Brown3ee549c2014-09-22 20:14:39 -07006528 if (DEBUG_WAKEUP) Slog.i(TAG, "Finished screen turning on...");
6529 listener = mScreenOnListener;
Craig Mautner13f6ea72014-06-23 14:57:02 -07006530 mScreenOnListener = null;
Jeff Brown3ee549c2014-09-22 20:14:39 -07006531 mScreenOnFully = true;
6532
6533 // Remember the first time we draw the keyguard so we know when we're done with
6534 // the main part of booting and can enable the screen and hide boot messages.
6535 if (!mKeyguardDrawnOnce && mAwake) {
6536 mKeyguardDrawnOnce = true;
6537 enableScreen = true;
6538 if (mBootMessageNeedsHiding) {
6539 mBootMessageNeedsHiding = false;
6540 hideBootMessages();
6541 }
6542 } else {
6543 enableScreen = false;
6544 }
Jeff Brownc38c9be2012-10-04 13:16:19 -07006545 }
6546
Jeff Brown3ee549c2014-09-22 20:14:39 -07006547 if (listener != null) {
6548 listener.onScreenOn();
6549 }
Jeff Brown4fc45272012-10-10 18:28:14 -07006550
Jeff Brown3ee549c2014-09-22 20:14:39 -07006551 if (enableScreen) {
6552 try {
6553 mWindowManager.enableScreenIfNeeded();
6554 } catch (RemoteException unhandled) {
Jeff Brown36c4db82014-09-19 12:05:31 -07006555 }
Craig Mautnera631d492014-08-05 15:16:01 -07006556 }
6557 }
6558
6559 private void handleHideBootMessage() {
Jeff Brown3ee549c2014-09-22 20:14:39 -07006560 synchronized (mLock) {
6561 if (!mKeyguardDrawnOnce) {
6562 mBootMessageNeedsHiding = true;
6563 return; // keyguard hasn't drawn the first time yet, not done booting
6564 }
Craig Mautnera631d492014-08-05 15:16:01 -07006565 }
Jeff Brown3ee549c2014-09-22 20:14:39 -07006566
6567 if (mBootMsgDialog != null) {
6568 if (DEBUG_WAKEUP) Slog.d(TAG, "handleHideBootMessage: dismissing");
6569 mBootMsgDialog.dismiss();
6570 mBootMsgDialog = null;
Craig Mautnera631d492014-08-05 15:16:01 -07006571 }
Jeff Brownc38c9be2012-10-04 13:16:19 -07006572 }
6573
6574 @Override
Jeff Brown3ee549c2014-09-22 20:14:39 -07006575 public boolean isScreenOn() {
6576 return mScreenOnFully;
Dianne Hackborn08743722009-12-21 12:16:51 -08006577 }
Jeff Brownc38c9be2012-10-04 13:16:19 -07006578
Dianne Hackborn08743722009-12-21 12:16:51 -08006579 /** {@inheritDoc} */
Jose Lima9546b202014-07-02 17:21:51 -07006580 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006581 public void enableKeyguard(boolean enabled) {
Jim Miller5ecd8112013-01-09 18:50:26 -08006582 if (mKeyguardDelegate != null) {
6583 mKeyguardDelegate.setKeyguardEnabled(enabled);
Mike Lockwood3a74bd32011-08-12 13:55:22 -07006584 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006585 }
6586
6587 /** {@inheritDoc} */
Jose Lima9546b202014-07-02 17:21:51 -07006588 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006589 public void exitKeyguardSecurely(OnKeyguardExitResult callback) {
Jim Miller5ecd8112013-01-09 18:50:26 -08006590 if (mKeyguardDelegate != null) {
6591 mKeyguardDelegate.verifyUnlock(callback);
Mike Lockwood3a74bd32011-08-12 13:55:22 -07006592 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006593 }
6594
Tony Mak2c0d6dc2016-04-29 16:16:54 +01006595 @Override
6596 public boolean isKeyguardShowingAndNotOccluded() {
Jim Miller5ecd8112013-01-09 18:50:26 -08006597 if (mKeyguardDelegate == null) return false;
Jim Millerab954542014-10-10 18:21:49 -07006598 return mKeyguardDelegate.isShowing() && !mKeyguardOccluded;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006599 }
6600
Jorim Jaggife762342016-10-13 14:33:27 +02006601 @Override
6602 public boolean isKeyguardTrustedLw() {
6603 if (mKeyguardDelegate == null) return false;
6604 return mKeyguardDelegate.isTrusted();
6605 }
6606
Mike Lockwood520d8bc2011-02-18 13:23:13 -05006607 /** {@inheritDoc} */
Jose Lima9546b202014-07-02 17:21:51 -07006608 @Override
Mike Lockwood520d8bc2011-02-18 13:23:13 -05006609 public boolean isKeyguardLocked() {
6610 return keyguardOn();
6611 }
6612
6613 /** {@inheritDoc} */
Jose Lima9546b202014-07-02 17:21:51 -07006614 @Override
Jim Millere4044bb2016-05-10 18:38:25 -07006615 public boolean isKeyguardSecure(int userId) {
Jim Miller5ecd8112013-01-09 18:50:26 -08006616 if (mKeyguardDelegate == null) return false;
Jim Millere4044bb2016-05-10 18:38:25 -07006617 return mKeyguardDelegate.isSecure(userId);
Mike Lockwood520d8bc2011-02-18 13:23:13 -05006618 }
6619
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006620 /** {@inheritDoc} */
Jose Lima9546b202014-07-02 17:21:51 -07006621 @Override
Jorim Jaggife762342016-10-13 14:33:27 +02006622 public boolean isKeyguardOccluded() {
6623 if (mKeyguardDelegate == null) return false;
6624 return mKeyguardOccluded;
Adrian Roos461829d2015-06-03 14:41:18 -07006625 }
6626
6627 /** {@inheritDoc} */
6628 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006629 public boolean inKeyguardRestrictedKeyInputMode() {
Jim Miller5ecd8112013-01-09 18:50:26 -08006630 if (mKeyguardDelegate == null) return false;
6631 return mKeyguardDelegate.isInputRestricted();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006632 }
6633
Jose Lima9546b202014-07-02 17:21:51 -07006634 @Override
Jorim Jaggi241ae102016-11-02 21:57:33 -07006635 public void dismissKeyguardLw(IKeyguardDismissCallback callback) {
RoboErik8a2cfc32014-05-16 11:19:38 -07006636 if (mKeyguardDelegate != null && mKeyguardDelegate.isShowing()) {
Craig Mautnerc0d2d0a2014-10-31 16:25:15 -07006637 if (DEBUG_KEYGUARD) Slog.d(TAG, "PWM.dismissKeyguardLw");
Jorim Jaggi8d786932016-10-26 19:08:36 -07006638
6639 // ask the keyguard to prompt the user to authenticate if necessary
Jorim Jaggi241ae102016-11-02 21:57:33 -07006640 mKeyguardDelegate.dismiss(callback);
6641 } else if (callback != null) {
6642 try {
6643 callback.onDismissError();
6644 } catch (RemoteException e) {
6645 Slog.w(TAG, "Failed to call callback", e);
6646 }
Dianne Hackborn90c52de2011-09-23 12:57:44 -07006647 }
6648 }
6649
Jorim Jaggicff0acb2014-03-31 16:35:15 +02006650 @Override
6651 public boolean isKeyguardDrawnLw() {
6652 synchronized (mLock) {
Jeff Brown3ee549c2014-09-22 20:14:39 -07006653 return mKeyguardDrawnOnce;
Jorim Jaggicff0acb2014-03-31 16:35:15 +02006654 }
6655 }
6656
Jorim Jaggi0d674622014-05-21 01:34:15 +02006657 @Override
Jorim Jaggi77e10432016-10-26 17:43:56 -07006658 public boolean isShowingDreamLw() {
6659 return mShowingDream;
6660 }
6661
6662 @Override
Jorim Jaggie29b2db2014-05-30 23:17:03 +02006663 public void startKeyguardExitAnimation(long startTime, long fadeoutDuration) {
Jorim Jaggi0d674622014-05-21 01:34:15 +02006664 if (mKeyguardDelegate != null) {
Craig Mautnerc0d2d0a2014-10-31 16:25:15 -07006665 if (DEBUG_KEYGUARD) Slog.d(TAG, "PWM.startKeyguardExitAnimation");
Jorim Jaggie29b2db2014-05-30 23:17:03 +02006666 mKeyguardDelegate.startKeyguardExitAnimation(startTime, fadeoutDuration);
Jorim Jaggi0d674622014-05-21 01:34:15 +02006667 }
6668 }
6669
Jorim Jaggi737af722015-12-31 10:42:27 +01006670 @Override
6671 public void getStableInsetsLw(int displayRotation, int displayWidth, int displayHeight,
6672 Rect outInsets) {
6673 outInsets.setEmpty();
Jorim Jaggi82c9dc92016-02-05 15:10:33 -08006674
6675 // Navigation bar and status bar.
6676 getNonDecorInsetsLw(displayRotation, displayWidth, displayHeight, outInsets);
Jorim Jaggi737af722015-12-31 10:42:27 +01006677 if (mStatusBar != null) {
6678 outInsets.top = mStatusBarHeight;
6679 }
Jorim Jaggi82c9dc92016-02-05 15:10:33 -08006680 }
6681
6682 @Override
6683 public void getNonDecorInsetsLw(int displayRotation, int displayWidth, int displayHeight,
6684 Rect outInsets) {
6685 outInsets.setEmpty();
6686
6687 // Only navigation bar
Jorim Jaggi737af722015-12-31 10:42:27 +01006688 if (mNavigationBar != null) {
Adrian Roos85d202b2016-06-02 16:27:47 -07006689 int position = navigationBarPosition(displayWidth, displayHeight, displayRotation);
6690 if (position == NAV_BAR_BOTTOM) {
Jorim Jaggi737af722015-12-31 10:42:27 +01006691 outInsets.bottom = getNavigationBarHeight(displayRotation, mUiMode);
Adrian Roos85d202b2016-06-02 16:27:47 -07006692 } else if (position == NAV_BAR_RIGHT) {
Jorim Jaggi737af722015-12-31 10:42:27 +01006693 outInsets.right = getNavigationBarWidth(displayRotation, mUiMode);
Adrian Roos85d202b2016-06-02 16:27:47 -07006694 } else if (position == NAV_BAR_LEFT) {
6695 outInsets.left = getNavigationBarWidth(displayRotation, mUiMode);
Jorim Jaggi737af722015-12-31 10:42:27 +01006696 }
6697 }
6698 }
6699
Jorim Jaggi5060bd82016-02-19 17:12:19 -08006700 @Override
Jorim Jaggi0ffd49c2016-02-12 15:04:21 -08006701 public boolean isNavBarForcedShownLw(WindowState windowState) {
Jorim Jaggie5638a62016-03-25 22:57:01 -07006702 return mForceShowSystemBars;
Jorim Jaggi0ffd49c2016-02-12 15:04:21 -08006703 }
6704
6705 @Override
Jorim Jaggi5060bd82016-02-19 17:12:19 -08006706 public boolean isDockSideAllowed(int dockSide) {
6707
6708 // We do not allow all dock sides at which the navigation bar touches the docked stack.
6709 if (!mNavigationBarCanMove) {
6710 return dockSide == DOCKED_TOP || dockSide == DOCKED_LEFT || dockSide == DOCKED_RIGHT;
6711 } else {
6712 return dockSide == DOCKED_TOP || dockSide == DOCKED_LEFT;
6713 }
6714 }
6715
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006716 void sendCloseSystemWindows() {
Jorim Jaggib10e33f2015-02-04 21:57:40 +01006717 PhoneWindow.sendCloseSystemWindows(mContext, null);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006718 }
6719
6720 void sendCloseSystemWindows(String reason) {
Jorim Jaggib10e33f2015-02-04 21:57:40 +01006721 PhoneWindow.sendCloseSystemWindows(mContext, reason);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006722 }
Mitsuru Oshima831d0d92009-06-16 18:27:18 -07006723
Jeff Brown01a98dd2011-09-20 15:08:29 -07006724 @Override
6725 public int rotationForOrientationLw(int orientation, int lastRotation) {
Daniel Sandler2ed6ad62011-02-22 14:54:17 -05006726 if (false) {
6727 Slog.v(TAG, "rotationForOrientationLw(orient="
6728 + orientation + ", last=" + lastRotation
6729 + "); user=" + mUserRotation + " "
6730 + ((mUserRotationMode == WindowManagerPolicy.USER_ROTATION_LOCKED)
6731 ? "USER_ROTATION_LOCKED" : "")
6732 );
6733 }
6734
Craig Mautner46ac6fa2013-08-01 10:06:34 -07006735 if (mForceDefaultOrientation) {
6736 return Surface.ROTATION_0;
6737 }
6738
The Android Open Source Project0727d222009-03-11 12:11:58 -07006739 synchronized (mLock) {
Jeff Brownc0347aa2011-09-23 17:26:09 -07006740 int sensorRotation = mOrientationListener.getProposedRotation(); // may be -1
6741 if (sensorRotation < 0) {
Jeff Brown0f862b42012-09-27 21:11:01 -07006742 sensorRotation = lastRotation;
Jeff Brownc0347aa2011-09-23 17:26:09 -07006743 }
Jeff Brown01a98dd2011-09-20 15:08:29 -07006744
Jeff Browndec6cf42011-11-15 14:08:20 -08006745 final int preferredRotation;
Jeff Brown2e7760e2012-04-11 15:14:55 -07006746 if (mLidState == LID_OPEN && mLidOpenRotation >= 0) {
Jeff Brown01a98dd2011-09-20 15:08:29 -07006747 // Ignore sensor when lid switch is open and rotation is forced.
6748 preferredRotation = mLidOpenRotation;
6749 } else if (mDockMode == Intent.EXTRA_DOCK_STATE_CAR
Jeff Brownc0347aa2011-09-23 17:26:09 -07006750 && (mCarDockEnablesAccelerometer || mCarDockRotation >= 0)) {
Jeff Brown01a98dd2011-09-20 15:08:29 -07006751 // Ignore sensor when in car dock unless explicitly enabled.
6752 // This case can override the behavior of NOSENSOR, and can also
6753 // enable 180 degree rotation while docked.
Jeff Brownc0347aa2011-09-23 17:26:09 -07006754 preferredRotation = mCarDockEnablesAccelerometer
Jeff Brown01a98dd2011-09-20 15:08:29 -07006755 ? sensorRotation : mCarDockRotation;
Jeff Brown1a693182011-11-08 14:44:16 -08006756 } else if ((mDockMode == Intent.EXTRA_DOCK_STATE_DESK
6757 || mDockMode == Intent.EXTRA_DOCK_STATE_LE_DESK
6758 || mDockMode == Intent.EXTRA_DOCK_STATE_HE_DESK)
Jeff Brownc0347aa2011-09-23 17:26:09 -07006759 && (mDeskDockEnablesAccelerometer || mDeskDockRotation >= 0)) {
Jeff Brown01a98dd2011-09-20 15:08:29 -07006760 // Ignore sensor when in desk dock unless explicitly enabled.
6761 // This case can override the behavior of NOSENSOR, and can also
6762 // enable 180 degree rotation while docked.
Jeff Brownc0347aa2011-09-23 17:26:09 -07006763 preferredRotation = mDeskDockEnablesAccelerometer
Jeff Brown01a98dd2011-09-20 15:08:29 -07006764 ? sensorRotation : mDeskDockRotation;
Jeff Brownc82c89ed2013-04-17 17:18:15 -07006765 } else if (mHdmiPlugged && mDemoHdmiRotationLock) {
6766 // Ignore sensor when plugged into HDMI when demo HDMI rotation lock enabled.
Jeff Browneb3e4b92011-12-06 19:54:24 -08006767 // Note that the dock orientation overrides the HDMI orientation.
Jeff Brownc82c89ed2013-04-17 17:18:15 -07006768 preferredRotation = mDemoHdmiRotation;
6769 } else if (mHdmiPlugged && mDockMode == Intent.EXTRA_DOCK_STATE_UNDOCKED
6770 && mUndockedHdmiRotation >= 0) {
6771 // Ignore sensor when plugged into HDMI and an undocked orientation has
6772 // been specified in the configuration (only for legacy devices without
6773 // full multi-display support).
6774 // Note that the dock orientation overrides the HDMI orientation.
6775 preferredRotation = mUndockedHdmiRotation;
Chong Zhangae6119ff2014-11-11 18:54:39 -08006776 } else if (mDemoRotationLock) {
6777 // Ignore sensor when demo rotation lock is enabled.
6778 // Note that the dock orientation and HDMI rotation lock override this.
6779 preferredRotation = mDemoRotation;
Dianne Hackbornb9ec1ac2013-04-10 17:34:25 -07006780 } else if (orientation == ActivityInfo.SCREEN_ORIENTATION_LOCKED) {
6781 // Application just wants to remain locked in the last rotation.
6782 preferredRotation = lastRotation;
Jeff Brownbcdfc622014-03-06 19:13:04 -08006783 } else if (!mSupportAutoRotation) {
6784 // If we don't support auto-rotation then bail out here and ignore
6785 // the sensor and any rotation lock settings.
6786 preferredRotation = -1;
Jeff Brown207673cd2012-06-05 17:47:11 -07006787 } else if ((mUserRotationMode == WindowManagerPolicy.USER_ROTATION_FREE
Jeff Brown01a98dd2011-09-20 15:08:29 -07006788 && (orientation == ActivityInfo.SCREEN_ORIENTATION_USER
Dianne Hackbornb9ec1ac2013-04-10 17:34:25 -07006789 || orientation == ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED
6790 || orientation == ActivityInfo.SCREEN_ORIENTATION_USER_LANDSCAPE
6791 || orientation == ActivityInfo.SCREEN_ORIENTATION_USER_PORTRAIT
6792 || orientation == ActivityInfo.SCREEN_ORIENTATION_FULL_USER))
Jeff Brown01a98dd2011-09-20 15:08:29 -07006793 || orientation == ActivityInfo.SCREEN_ORIENTATION_SENSOR
6794 || orientation == ActivityInfo.SCREEN_ORIENTATION_FULL_SENSOR
6795 || orientation == ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE
6796 || orientation == ActivityInfo.SCREEN_ORIENTATION_SENSOR_PORTRAIT) {
6797 // Otherwise, use sensor only if requested by the application or enabled
6798 // by default for USER or UNSPECIFIED modes. Does not apply to NOSENSOR.
Jeff Brownd3187e32011-09-21 19:26:44 -07006799 if (mAllowAllRotations < 0) {
6800 // Can't read this during init() because the context doesn't
6801 // have display metrics at that time so we cannot determine
6802 // tablet vs. phone then.
6803 mAllowAllRotations = mContext.getResources().getBoolean(
6804 com.android.internal.R.bool.config_allowAllRotations) ? 1 : 0;
6805 }
Jeff Brown01a98dd2011-09-20 15:08:29 -07006806 if (sensorRotation != Surface.ROTATION_180
Jeff Brownd3187e32011-09-21 19:26:44 -07006807 || mAllowAllRotations == 1
Dianne Hackbornb9ec1ac2013-04-10 17:34:25 -07006808 || orientation == ActivityInfo.SCREEN_ORIENTATION_FULL_SENSOR
6809 || orientation == ActivityInfo.SCREEN_ORIENTATION_FULL_USER) {
Jeff Brown01a98dd2011-09-20 15:08:29 -07006810 preferredRotation = sensorRotation;
6811 } else {
6812 preferredRotation = lastRotation;
6813 }
Jeff Brown207673cd2012-06-05 17:47:11 -07006814 } else if (mUserRotationMode == WindowManagerPolicy.USER_ROTATION_LOCKED
6815 && orientation != ActivityInfo.SCREEN_ORIENTATION_NOSENSOR) {
6816 // Apply rotation lock. Does not apply to NOSENSOR.
6817 // The idea is that the user rotation expresses a weak preference for the direction
6818 // of gravity and as NOSENSOR is never affected by gravity, then neither should
6819 // NOSENSOR be affected by rotation lock (although it will be affected by docks).
Jeff Brown4dfce202011-10-05 12:00:10 -07006820 preferredRotation = mUserRotation;
Jeff Browndec6cf42011-11-15 14:08:20 -08006821 } else {
6822 // No overriding preference.
6823 // We will do exactly what the application asked us to do.
6824 preferredRotation = -1;
Jeff Brown01a98dd2011-09-20 15:08:29 -07006825 }
6826
Dianne Hackborne5439f22010-10-02 16:53:50 -07006827 switch (orientation) {
6828 case ActivityInfo.SCREEN_ORIENTATION_PORTRAIT:
Jeff Browndec6cf42011-11-15 14:08:20 -08006829 // Return portrait unless overridden.
6830 if (isAnyPortrait(preferredRotation)) {
6831 return preferredRotation;
6832 }
Dianne Hackborne5439f22010-10-02 16:53:50 -07006833 return mPortraitRotation;
Dianne Hackborne5439f22010-10-02 16:53:50 -07006834
Jeff Brown01a98dd2011-09-20 15:08:29 -07006835 case ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE:
Jeff Browndec6cf42011-11-15 14:08:20 -08006836 // Return landscape unless overridden.
6837 if (isLandscapeOrSeascape(preferredRotation)) {
6838 return preferredRotation;
6839 }
Jeff Brown01a98dd2011-09-20 15:08:29 -07006840 return mLandscapeRotation;
6841
6842 case ActivityInfo.SCREEN_ORIENTATION_REVERSE_PORTRAIT:
Jeff Browndec6cf42011-11-15 14:08:20 -08006843 // Return reverse portrait unless overridden.
6844 if (isAnyPortrait(preferredRotation)) {
6845 return preferredRotation;
6846 }
Jeff Brown01a98dd2011-09-20 15:08:29 -07006847 return mUpsideDownRotation;
6848
6849 case ActivityInfo.SCREEN_ORIENTATION_REVERSE_LANDSCAPE:
Jeff Browndec6cf42011-11-15 14:08:20 -08006850 // Return seascape unless overridden.
6851 if (isLandscapeOrSeascape(preferredRotation)) {
6852 return preferredRotation;
6853 }
Jeff Brown01a98dd2011-09-20 15:08:29 -07006854 return mSeascapeRotation;
6855
6856 case ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE:
Dianne Hackbornb9ec1ac2013-04-10 17:34:25 -07006857 case ActivityInfo.SCREEN_ORIENTATION_USER_LANDSCAPE:
Jeff Brown01a98dd2011-09-20 15:08:29 -07006858 // Return either landscape rotation.
6859 if (isLandscapeOrSeascape(preferredRotation)) {
6860 return preferredRotation;
6861 }
6862 if (isLandscapeOrSeascape(lastRotation)) {
Jeff Brown4519f072011-01-23 13:16:01 -08006863 return lastRotation;
6864 }
Jeff Brown01a98dd2011-09-20 15:08:29 -07006865 return mLandscapeRotation;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006866
Jeff Brown01a98dd2011-09-20 15:08:29 -07006867 case ActivityInfo.SCREEN_ORIENTATION_SENSOR_PORTRAIT:
Dianne Hackbornb9ec1ac2013-04-10 17:34:25 -07006868 case ActivityInfo.SCREEN_ORIENTATION_USER_PORTRAIT:
Jeff Brown01a98dd2011-09-20 15:08:29 -07006869 // Return either portrait rotation.
6870 if (isAnyPortrait(preferredRotation)) {
6871 return preferredRotation;
6872 }
6873 if (isAnyPortrait(lastRotation)) {
6874 return lastRotation;
6875 }
6876 return mPortraitRotation;
6877
6878 default:
Jeff Brown4dfce202011-10-05 12:00:10 -07006879 // For USER, UNSPECIFIED, NOSENSOR, SENSOR and FULL_SENSOR,
6880 // just return the preferred orientation we already calculated.
Jeff Brown01a98dd2011-09-20 15:08:29 -07006881 if (preferredRotation >= 0) {
6882 return preferredRotation;
6883 }
Dianne Hackborndacea8c2011-04-21 17:26:39 -07006884 return Surface.ROTATION_0;
Daniel Sandlere7e5ac22011-02-22 16:10:21 -05006885 }
6886 }
Steve Howarda7bfe6a2010-09-23 16:47:49 -07006887 }
6888
Jeff Brown01a98dd2011-09-20 15:08:29 -07006889 @Override
6890 public boolean rotationHasCompatibleMetricsLw(int orientation, int rotation) {
6891 switch (orientation) {
6892 case ActivityInfo.SCREEN_ORIENTATION_PORTRAIT:
6893 case ActivityInfo.SCREEN_ORIENTATION_REVERSE_PORTRAIT:
6894 case ActivityInfo.SCREEN_ORIENTATION_SENSOR_PORTRAIT:
6895 return isAnyPortrait(rotation);
6896
6897 case ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE:
6898 case ActivityInfo.SCREEN_ORIENTATION_REVERSE_LANDSCAPE:
6899 case ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE:
6900 return isLandscapeOrSeascape(rotation);
6901
6902 default:
6903 return true;
6904 }
Steve Howarda7bfe6a2010-09-23 16:47:49 -07006905 }
6906
Jeff Brownc0347aa2011-09-23 17:26:09 -07006907 @Override
6908 public void setRotationLw(int rotation) {
6909 mOrientationListener.setCurrentRotation(rotation);
6910 }
6911
Jeff Brown01a98dd2011-09-20 15:08:29 -07006912 private boolean isLandscapeOrSeascape(int rotation) {
6913 return rotation == mLandscapeRotation || rotation == mSeascapeRotation;
Dianne Hackborne5439f22010-10-02 16:53:50 -07006914 }
6915
Jeff Brown01a98dd2011-09-20 15:08:29 -07006916 private boolean isAnyPortrait(int rotation) {
6917 return rotation == mPortraitRotation || rotation == mUpsideDownRotation;
Dianne Hackborne5439f22010-10-02 16:53:50 -07006918 }
6919
Jose Lima9546b202014-07-02 17:21:51 -07006920 @Override
Svetoslav Ganov80943d82013-01-02 10:25:37 -08006921 public int getUserRotationMode() {
6922 return Settings.System.getIntForUser(mContext.getContentResolver(),
Brett Chabot7e55c402013-05-16 19:38:08 -07006923 Settings.System.ACCELEROMETER_ROTATION, 0, UserHandle.USER_CURRENT) != 0 ?
6924 WindowManagerPolicy.USER_ROTATION_FREE :
6925 WindowManagerPolicy.USER_ROTATION_LOCKED;
Svetoslav Ganov80943d82013-01-02 10:25:37 -08006926 }
Daniel Sandlerb73617d2010-08-17 00:41:00 -04006927
6928 // User rotation: to be used when all else fails in assigning an orientation to the device
Jose Lima9546b202014-07-02 17:21:51 -07006929 @Override
Daniel Sandlerb73617d2010-08-17 00:41:00 -04006930 public void setUserRotationMode(int mode, int rot) {
6931 ContentResolver res = mContext.getContentResolver();
Daniel Sandler2ed6ad62011-02-22 14:54:17 -05006932
6933 // mUserRotationMode and mUserRotation will be assigned by the content observer
Daniel Sandlerb73617d2010-08-17 00:41:00 -04006934 if (mode == WindowManagerPolicy.USER_ROTATION_LOCKED) {
Christopher Tate5e08af02012-09-21 17:17:22 -07006935 Settings.System.putIntForUser(res,
Daniel Sandlerb73617d2010-08-17 00:41:00 -04006936 Settings.System.USER_ROTATION,
Christopher Tate5e08af02012-09-21 17:17:22 -07006937 rot,
6938 UserHandle.USER_CURRENT);
6939 Settings.System.putIntForUser(res,
Daniel Sandler2ed6ad62011-02-22 14:54:17 -05006940 Settings.System.ACCELEROMETER_ROTATION,
Christopher Tate5e08af02012-09-21 17:17:22 -07006941 0,
6942 UserHandle.USER_CURRENT);
Daniel Sandlerb73617d2010-08-17 00:41:00 -04006943 } else {
Christopher Tate5e08af02012-09-21 17:17:22 -07006944 Settings.System.putIntForUser(res,
Daniel Sandlerb73617d2010-08-17 00:41:00 -04006945 Settings.System.ACCELEROMETER_ROTATION,
Christopher Tate5e08af02012-09-21 17:17:22 -07006946 1,
6947 UserHandle.USER_CURRENT);
Daniel Sandlerb73617d2010-08-17 00:41:00 -04006948 }
6949 }
6950
Jose Lima9546b202014-07-02 17:21:51 -07006951 @Override
Jeff Brownac143512012-04-05 18:57:33 -07006952 public void setSafeMode(boolean safeMode) {
6953 mSafeMode = safeMode;
6954 performHapticFeedbackLw(null, safeMode
6955 ? HapticFeedbackConstants.SAFE_MODE_ENABLED
6956 : HapticFeedbackConstants.SAFE_MODE_DISABLED, true);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006957 }
Craig Mautnereda67292013-04-28 13:50:14 -07006958
Dianne Hackborn181ceb52009-08-27 22:16:40 -07006959 static long[] getLongIntArray(Resources r, int resid) {
6960 int[] ar = r.getIntArray(resid);
6961 if (ar == null) {
6962 return null;
6963 }
6964 long[] out = new long[ar.length];
6965 for (int i=0; i<ar.length; i++) {
6966 out[i] = ar[i];
6967 }
6968 return out;
6969 }
Craig Mautnereda67292013-04-28 13:50:14 -07006970
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006971 /** {@inheritDoc} */
Craig Mautnereda67292013-04-28 13:50:14 -07006972 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006973 public void systemReady() {
Jorim Jaggie69c9312016-10-31 18:24:38 -07006974 mKeyguardDelegate = new KeyguardServiceDelegate(mContext,
6975 new StateCallback() {
6976 @Override
6977 public void onTrustedChanged() {
6978 mWindowManagerFuncs.notifyKeyguardTrustedChanged();
6979 }
6980 });
Mike Lockwooded8902d2013-11-15 11:01:47 -08006981 mKeyguardDelegate.onSystemReady();
6982
Michael Wright3818c922014-09-02 13:59:07 -07006983 readCameraLensCoverState();
Jeff Brown4f5fa282014-06-12 19:19:15 -07006984 updateUiMode();
Adrian Roos3542f7d2015-07-13 15:57:53 -07006985 boolean bindKeyguardNow;
Dianne Hackbornb1a79802009-09-29 15:18:31 -07006986 synchronized (mLock) {
6987 updateOrientationListenerLp();
Dianne Hackbornc777e072010-02-12 13:07:59 -08006988 mSystemReady = true;
6989 mHandler.post(new Runnable() {
Craig Mautnereda67292013-04-28 13:50:14 -07006990 @Override
Dianne Hackbornc777e072010-02-12 13:07:59 -08006991 public void run() {
6992 updateSettings();
6993 }
6994 });
Adrian Roos3542f7d2015-07-13 15:57:53 -07006995
6996 bindKeyguardNow = mDeferBindKeyguard;
6997 if (bindKeyguardNow) {
6998 // systemBooted ran but wasn't able to bind to the Keyguard, we'll do it now.
6999 mDeferBindKeyguard = false;
7000 }
7001 }
7002
7003 if (bindKeyguardNow) {
7004 mKeyguardDelegate.bindService(mContext);
7005 mKeyguardDelegate.onBootCompleted();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08007006 }
Michael Wrighta4d22d72015-09-16 23:19:26 +01007007 mSystemGestures.systemReady();
Amith Yamasani02a03812016-04-22 17:32:00 -07007008 mImmersiveModeConfirmation.systemReady();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08007009 }
Dianne Hackborn661cd522011-08-22 00:26:20 -07007010
Dianne Hackbornba24e4d2011-09-01 11:17:06 -07007011 /** {@inheritDoc} */
Jose Lima9546b202014-07-02 17:21:51 -07007012 @Override
Dianne Hackbornba24e4d2011-09-01 11:17:06 -07007013 public void systemBooted() {
Adrian Roos3542f7d2015-07-13 15:57:53 -07007014 boolean bindKeyguardNow = false;
7015 synchronized (mLock) {
7016 // Time to bind Keyguard; take care to only bind it once, either here if ready or
7017 // in systemReady if not.
7018 if (mKeyguardDelegate != null) {
7019 bindKeyguardNow = true;
7020 } else {
7021 // Because mKeyguardDelegate is null, we know that the synchronized block in
7022 // systemReady didn't run yet and setting this will actually have an effect.
7023 mDeferBindKeyguard = true;
7024 }
7025 }
7026 if (bindKeyguardNow) {
Jason Monk5eeebf52014-09-26 12:36:51 -04007027 mKeyguardDelegate.bindService(mContext);
Jim Millere5f910a2013-10-16 18:15:46 -07007028 mKeyguardDelegate.onBootCompleted();
7029 }
Dianne Hackbornba24e4d2011-09-01 11:17:06 -07007030 synchronized (mLock) {
7031 mSystemBooted = true;
7032 }
Jeff Brown416c49c2015-05-26 19:50:18 -07007033 startedWakingUp();
Jeff Brown36c4db82014-09-19 12:05:31 -07007034 screenTurningOn(null);
Jorim Jaggic0496072015-08-19 15:14:52 -07007035 screenTurnedOn();
Dianne Hackbornba24e4d2011-09-01 11:17:06 -07007036 }
7037
Dianne Hackborn661cd522011-08-22 00:26:20 -07007038 ProgressDialog mBootMsgDialog = null;
7039
7040 /** {@inheritDoc} */
Jose Lima9546b202014-07-02 17:21:51 -07007041 @Override
Dianne Hackborn661cd522011-08-22 00:26:20 -07007042 public void showBootMessage(final CharSequence msg, final boolean always) {
7043 mHandler.post(new Runnable() {
7044 @Override public void run() {
7045 if (mBootMsgDialog == null) {
Craig Stout4c0cb8a2014-04-04 13:03:10 -07007046 int theme;
Michael Kwan5a861672016-06-09 19:44:04 -07007047 if (mContext.getPackageManager().hasSystemFeature(FEATURE_TELEVISION)) {
Craig Stout4c0cb8a2014-04-04 13:03:10 -07007048 theme = com.android.internal.R.style.Theme_Leanback_Dialog_Alert;
7049 } else {
7050 theme = 0;
7051 }
Vinod Krishnanfa8fc412014-04-18 14:35:53 -07007052
7053 mBootMsgDialog = new ProgressDialog(mContext, theme) {
Dianne Hackborn295e3c22011-08-25 13:19:08 -07007054 // This dialog will consume all events coming in to
7055 // it, to avoid it trying to do things too early in boot.
7056 @Override public boolean dispatchKeyEvent(KeyEvent event) {
7057 return true;
7058 }
7059 @Override public boolean dispatchKeyShortcutEvent(KeyEvent event) {
7060 return true;
7061 }
7062 @Override public boolean dispatchTouchEvent(MotionEvent ev) {
7063 return true;
7064 }
7065 @Override public boolean dispatchTrackballEvent(MotionEvent ev) {
7066 return true;
7067 }
7068 @Override public boolean dispatchGenericMotionEvent(MotionEvent ev) {
7069 return true;
7070 }
7071 @Override public boolean dispatchPopulateAccessibilityEvent(
7072 AccessibilityEvent event) {
7073 return true;
7074 }
7075 };
Jeff Hao9f60c082014-10-28 18:51:07 -07007076 if (mContext.getPackageManager().isUpgrade()) {
7077 mBootMsgDialog.setTitle(R.string.android_upgrading_title);
7078 } else {
7079 mBootMsgDialog.setTitle(R.string.android_start_title);
7080 }
Dianne Hackborn661cd522011-08-22 00:26:20 -07007081 mBootMsgDialog.setProgressStyle(ProgressDialog.STYLE_SPINNER);
7082 mBootMsgDialog.setIndeterminate(true);
7083 mBootMsgDialog.getWindow().setType(
Dianne Hackborn29aae6f2011-08-18 18:30:09 -07007084 WindowManager.LayoutParams.TYPE_BOOT_PROGRESS);
Dianne Hackborn661cd522011-08-22 00:26:20 -07007085 mBootMsgDialog.getWindow().addFlags(
7086 WindowManager.LayoutParams.FLAG_DIM_BEHIND
7087 | WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN);
7088 mBootMsgDialog.getWindow().setDimAmount(1);
Dianne Hackbornd9efb952011-12-07 14:56:51 -08007089 WindowManager.LayoutParams lp = mBootMsgDialog.getWindow().getAttributes();
7090 lp.screenOrientation = ActivityInfo.SCREEN_ORIENTATION_NOSENSOR;
7091 mBootMsgDialog.getWindow().setAttributes(lp);
Dianne Hackborn661cd522011-08-22 00:26:20 -07007092 mBootMsgDialog.setCancelable(false);
7093 mBootMsgDialog.show();
7094 }
7095 mBootMsgDialog.setMessage(msg);
7096 }
7097 });
7098 }
7099
7100 /** {@inheritDoc} */
Jose Lima9546b202014-07-02 17:21:51 -07007101 @Override
Dianne Hackborn661cd522011-08-22 00:26:20 -07007102 public void hideBootMessages() {
Craig Mautnera631d492014-08-05 15:16:01 -07007103 mHandler.sendEmptyMessage(MSG_HIDE_BOOT_MESSAGE);
Dianne Hackborn661cd522011-08-22 00:26:20 -07007104 }
7105
Mike Lockwood28569302010-01-28 11:54:40 -05007106 /** {@inheritDoc} */
Jose Lima9546b202014-07-02 17:21:51 -07007107 @Override
Mike Lockwood28569302010-01-28 11:54:40 -05007108 public void userActivity() {
Dianne Hackborndf89e652011-10-06 22:35:11 -07007109 // ***************************************
7110 // NOTE NOTE NOTE NOTE NOTE NOTE NOTE NOTE
7111 // ***************************************
7112 // THIS IS CALLED FROM DEEP IN THE POWER MANAGER
7113 // WITH ITS LOCKS HELD.
7114 //
7115 // This code must be VERY careful about the locks
7116 // it acquires.
7117 // In fact, the current code acquires way too many,
7118 // and probably has lurking deadlocks.
7119
Mike Lockwood28569302010-01-28 11:54:40 -05007120 synchronized (mScreenLockTimeout) {
7121 if (mLockScreenTimerActive) {
7122 // reset the timer
7123 mHandler.removeCallbacks(mScreenLockTimeout);
7124 mHandler.postDelayed(mScreenLockTimeout, mLockScreenTimeout);
7125 }
7126 }
Daniel Sandler0601eb72011-04-13 01:01:32 -04007127 }
7128
Adam Cohenf7522022012-10-03 20:03:18 -07007129 class ScreenLockTimeout implements Runnable {
7130 Bundle options;
7131
7132 @Override
Mike Lockwood28569302010-01-28 11:54:40 -05007133 public void run() {
7134 synchronized (this) {
7135 if (localLOGV) Log.v(TAG, "mScreenLockTimeout activating keyguard");
Jim Miller5ecd8112013-01-09 18:50:26 -08007136 if (mKeyguardDelegate != null) {
7137 mKeyguardDelegate.doKeyguardTimeout(options);
Mike Lockwood3a74bd32011-08-12 13:55:22 -07007138 }
Mike Lockwood28569302010-01-28 11:54:40 -05007139 mLockScreenTimerActive = false;
Adam Cohenf7522022012-10-03 20:03:18 -07007140 options = null;
Mike Lockwood28569302010-01-28 11:54:40 -05007141 }
7142 }
Mike Lockwood28569302010-01-28 11:54:40 -05007143
Adam Cohenf7522022012-10-03 20:03:18 -07007144 public void setLockOptions(Bundle options) {
7145 this.options = options;
7146 }
7147 }
7148
7149 ScreenLockTimeout mScreenLockTimeout = new ScreenLockTimeout();
7150
Jose Lima9546b202014-07-02 17:21:51 -07007151 @Override
Adam Cohenf7522022012-10-03 20:03:18 -07007152 public void lockNow(Bundle options) {
Jim Miller93c518e2012-01-17 15:55:31 -08007153 mContext.enforceCallingOrSelfPermission(android.Manifest.permission.DEVICE_POWER, null);
7154 mHandler.removeCallbacks(mScreenLockTimeout);
Adam Cohenf7522022012-10-03 20:03:18 -07007155 if (options != null) {
7156 // In case multiple calls are made to lockNow, we don't wipe out the options
7157 // until the runnable actually executes.
7158 mScreenLockTimeout.setLockOptions(options);
7159 }
Jim Miller93c518e2012-01-17 15:55:31 -08007160 mHandler.post(mScreenLockTimeout);
7161 }
7162
Mike Lockwood28569302010-01-28 11:54:40 -05007163 private void updateLockScreenTimeout() {
7164 synchronized (mScreenLockTimeout) {
Jeff Brown3ee549c2014-09-22 20:14:39 -07007165 boolean enable = (mAllowLockscreenWhenOn && mAwake &&
Jim Millere4044bb2016-05-10 18:38:25 -07007166 mKeyguardDelegate != null && mKeyguardDelegate.isSecure(mCurrentUserId));
Mike Lockwood28569302010-01-28 11:54:40 -05007167 if (mLockScreenTimerActive != enable) {
7168 if (enable) {
7169 if (localLOGV) Log.v(TAG, "setting lockscreen timer");
Jim Miller2967f482016-01-07 15:05:32 -08007170 mHandler.removeCallbacks(mScreenLockTimeout); // remove any pending requests
Mike Lockwood28569302010-01-28 11:54:40 -05007171 mHandler.postDelayed(mScreenLockTimeout, mLockScreenTimeout);
7172 } else {
7173 if (localLOGV) Log.v(TAG, "clearing lockscreen timer");
7174 mHandler.removeCallbacks(mScreenLockTimeout);
7175 }
7176 mLockScreenTimerActive = enable;
7177 }
7178 }
7179 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08007180
Jeff Brown061ea992015-04-17 19:55:47 -07007181 private void updateDreamingSleepToken(boolean acquire) {
7182 if (acquire) {
7183 if (mDreamingSleepToken == null) {
7184 mDreamingSleepToken = mActivityManagerInternal.acquireSleepToken("Dream");
7185 }
7186 } else {
7187 if (mDreamingSleepToken != null) {
7188 mDreamingSleepToken.release();
Jeff Brown48d1b142015-06-10 16:36:03 -07007189 mDreamingSleepToken = null;
7190 }
7191 }
7192 }
7193
7194 private void updateScreenOffSleepToken(boolean acquire) {
7195 if (acquire) {
7196 if (mScreenOffSleepToken == null) {
7197 mScreenOffSleepToken = mActivityManagerInternal.acquireSleepToken("ScreenOff");
7198 }
7199 } else {
7200 if (mScreenOffSleepToken != null) {
7201 mScreenOffSleepToken.release();
7202 mScreenOffSleepToken = null;
Jeff Brown061ea992015-04-17 19:55:47 -07007203 }
7204 }
7205 }
7206
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08007207 /** {@inheritDoc} */
Craig Mautnereda67292013-04-28 13:50:14 -07007208 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08007209 public void enableScreenAfterBoot() {
7210 readLidState();
Jeff Brownc458ce92012-04-30 14:58:40 -07007211 applyLidSwitchState();
Jeff Brown01a98dd2011-09-20 15:08:29 -07007212 updateRotation(true);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08007213 }
Dianne Hackbornf54c8f92009-09-19 14:03:57 -07007214
Jeff Brownc458ce92012-04-30 14:58:40 -07007215 private void applyLidSwitchState() {
Jeff Brownc458ce92012-04-30 14:58:40 -07007216 if (mLidState == LID_CLOSED && mLidControlsSleep) {
Jeff Brown6d8fd272014-05-20 21:24:38 -07007217 mPowerManager.goToSleep(SystemClock.uptimeMillis(),
Jeff Brownc12035c2014-08-13 18:52:25 -07007218 PowerManager.GO_TO_SLEEP_REASON_LID_SWITCH,
Jeff Brown6d8fd272014-05-20 21:24:38 -07007219 PowerManager.GO_TO_SLEEP_FLAG_NO_DOZE);
Edward Savage-Jones7def60d2015-11-13 13:27:03 +01007220 } else if (mLidState == LID_CLOSED && mLidControlsScreenLock) {
7221 mWindowManagerFuncs.lockDeviceNow();
Jeff Brownc458ce92012-04-30 14:58:40 -07007222 }
Jeff Browna20dda42014-05-27 20:57:24 -07007223
7224 synchronized (mLock) {
7225 updateWakeGestureListenerLp();
7226 }
Jeff Brown01a98dd2011-09-20 15:08:29 -07007227 }
7228
Jeff Brown4f5fa282014-06-12 19:19:15 -07007229 void updateUiMode() {
7230 if (mUiModeManager == null) {
7231 mUiModeManager = IUiModeManager.Stub.asInterface(
7232 ServiceManager.getService(Context.UI_MODE_SERVICE));
7233 }
7234 try {
7235 mUiMode = mUiModeManager.getCurrentModeType();
7236 } catch (RemoteException e) {
7237 }
7238 }
7239
Jeff Brown01a98dd2011-09-20 15:08:29 -07007240 void updateRotation(boolean alwaysSendConfiguration) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08007241 try {
7242 //set orientation on WindowManager
Dianne Hackbornf87d1962012-04-04 12:48:24 -07007243 mWindowManager.updateRotation(alwaysSendConfiguration, false);
7244 } catch (RemoteException e) {
7245 // Ignore
7246 }
7247 }
7248
7249 void updateRotation(boolean alwaysSendConfiguration, boolean forceRelayout) {
7250 try {
7251 //set orientation on WindowManager
7252 mWindowManager.updateRotation(alwaysSendConfiguration, forceRelayout);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08007253 } catch (RemoteException e) {
7254 // Ignore
7255 }
7256 }
7257
Daniel Sandler6396c722013-04-16 20:19:09 -04007258 /**
7259 * Return an Intent to launch the currently active dock app as home. Returns
7260 * null if the standard home should be launched, which is the case if any of the following is
7261 * true:
7262 * <ul>
7263 * <li>The device is not in either car mode or desk mode
keunyounga7710492015-09-23 11:33:58 -07007264 * <li>The device is in car mode but mEnableCarDockHomeCapture is false
Daniel Sandler6396c722013-04-16 20:19:09 -04007265 * <li>The device is in desk mode but ENABLE_DESK_DOCK_HOME_CAPTURE is false
7266 * <li>The device is in car mode but there's no CAR_DOCK app with METADATA_DOCK_HOME
7267 * <li>The device is in desk mode but there's no DESK_DOCK app with METADATA_DOCK_HOME
7268 * </ul>
Craig Mautnereda67292013-04-28 13:50:14 -07007269 * @return A dock intent.
Daniel Sandler6396c722013-04-16 20:19:09 -04007270 */
7271 Intent createHomeDockIntent() {
7272 Intent intent = null;
7273
7274 // What home does is based on the mode, not the dock state. That
7275 // is, when in car mode you should be taken to car home regardless
7276 // of whether we are actually in a car dock.
7277 if (mUiMode == Configuration.UI_MODE_TYPE_CAR) {
keunyounga7710492015-09-23 11:33:58 -07007278 if (mEnableCarDockHomeCapture) {
Daniel Sandler6396c722013-04-16 20:19:09 -04007279 intent = mCarDockIntent;
7280 }
7281 } else if (mUiMode == Configuration.UI_MODE_TYPE_DESK) {
7282 if (ENABLE_DESK_DOCK_HOME_CAPTURE) {
7283 intent = mDeskDockIntent;
7284 }
Jeff Brown4f5fa282014-06-12 19:19:15 -07007285 } else if (mUiMode == Configuration.UI_MODE_TYPE_WATCH
7286 && (mDockMode == Intent.EXTRA_DOCK_STATE_DESK
7287 || mDockMode == Intent.EXTRA_DOCK_STATE_HE_DESK
7288 || mDockMode == Intent.EXTRA_DOCK_STATE_LE_DESK)) {
7289 // Always launch dock home from home when watch is docked, if it exists.
7290 intent = mDeskDockIntent;
Daniel Sandler6396c722013-04-16 20:19:09 -04007291 }
7292
7293 if (intent == null) {
7294 return null;
7295 }
7296
7297 ActivityInfo ai = null;
7298 ResolveInfo info = mContext.getPackageManager().resolveActivityAsUser(
7299 intent,
John Spurlockf56bef12013-07-09 09:51:46 -04007300 PackageManager.MATCH_DEFAULT_ONLY | PackageManager.GET_META_DATA,
Craig Mautnerd625ab22013-09-06 13:40:31 -07007301 mCurrentUserId);
Daniel Sandler6396c722013-04-16 20:19:09 -04007302 if (info != null) {
7303 ai = info.activityInfo;
7304 }
7305 if (ai != null
7306 && ai.metaData != null
7307 && ai.metaData.getBoolean(Intent.METADATA_DOCK_HOME)) {
7308 intent = new Intent(intent);
7309 intent.setClassName(ai.packageName, ai.name);
7310 return intent;
7311 }
7312
7313 return null;
7314 }
7315
Filip Gruszczynskia483a1d2015-03-17 19:06:58 +00007316 void startDockOrHome(boolean fromHomeKey, boolean awakenFromDreams) {
7317 if (awakenFromDreams) {
7318 awakenDreams();
7319 }
Daniel Sandler6396c722013-04-16 20:19:09 -04007320
7321 Intent dock = createHomeDockIntent();
7322 if (dock != null) {
7323 try {
Bryce Lee01b0c5f2015-02-05 18:24:04 -08007324 if (fromHomeKey) {
7325 dock.putExtra(WindowManagerPolicy.EXTRA_FROM_HOME_KEY, fromHomeKey);
7326 }
Bart Sears8b1c27c2015-03-18 23:51:02 +00007327 startActivityAsUser(dock, UserHandle.CURRENT);
Daniel Sandler6396c722013-04-16 20:19:09 -04007328 return;
7329 } catch (ActivityNotFoundException e) {
7330 }
7331 }
7332
Bryce Lee01b0c5f2015-02-05 18:24:04 -08007333 Intent intent;
7334
7335 if (fromHomeKey) {
7336 intent = new Intent(mHomeIntent);
7337 intent.putExtra(WindowManagerPolicy.EXTRA_FROM_HOME_KEY, fromHomeKey);
7338 } else {
7339 intent = mHomeIntent;
7340 }
7341
Bryce Lee9fc0b6f2015-03-19 21:37:45 +00007342 startActivityAsUser(intent, UserHandle.CURRENT);
Dianne Hackborn39c2d712009-09-22 11:41:31 -07007343 }
Craig Mautnereda67292013-04-28 13:50:14 -07007344
Dianne Hackborn39c2d712009-09-22 11:41:31 -07007345 /**
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08007346 * goes to the home screen
7347 * @return whether it did anything
7348 */
7349 boolean goHome() {
Bart Sears8b1c27c2015-03-18 23:51:02 +00007350 if (!isUserSetupComplete()) {
7351 Slog.i(TAG, "Not going home because user setup is in progress.");
7352 return false;
7353 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08007354 if (false) {
7355 // This code always brings home to the front.
Dianne Hackborn256dd3b2009-05-19 18:51:21 -07007356 try {
Sudheer Shankadc589ac2016-11-10 15:30:17 -08007357 ActivityManager.getService().stopAppSwitches();
Dianne Hackborn256dd3b2009-05-19 18:51:21 -07007358 } catch (RemoteException e) {
7359 }
Dianne Hackborn94a679d2009-07-28 17:51:07 -07007360 sendCloseSystemWindows();
Filip Gruszczynskia483a1d2015-03-17 19:06:58 +00007361 startDockOrHome(false /*fromHomeKey*/, true /* awakenFromDreams */);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08007362 } else {
7363 // This code brings home to the front or, if it is already
7364 // at the front, puts the device to sleep.
7365 try {
Wink Savilled2e6a332010-02-12 12:12:06 -08007366 if (SystemProperties.getInt("persist.sys.uts-test-mode", 0) == 1) {
7367 /// Roll back EndcallBehavior as the cupcake design to pass P1 lab entry.
7368 Log.d(TAG, "UTS-TEST-MODE");
7369 } else {
Sudheer Shankadc589ac2016-11-10 15:30:17 -08007370 ActivityManager.getService().stopAppSwitches();
Wink Savilled2e6a332010-02-12 12:12:06 -08007371 sendCloseSystemWindows();
Daniel Sandler6396c722013-04-16 20:19:09 -04007372 Intent dock = createHomeDockIntent();
7373 if (dock != null) {
Sudheer Shankadc589ac2016-11-10 15:30:17 -08007374 int result = ActivityManager.getService()
Daniel Sandler6396c722013-04-16 20:19:09 -04007375 .startActivityAsUser(null, null, dock,
7376 dock.resolveTypeIfNeeded(mContext.getContentResolver()),
7377 null, null, 0,
7378 ActivityManager.START_FLAG_ONLY_IF_NEEDED,
Jeff Hao1b012d32014-08-20 10:35:34 -07007379 null, null, UserHandle.USER_CURRENT);
Daniel Sandler6396c722013-04-16 20:19:09 -04007380 if (result == ActivityManager.START_RETURN_INTENT_TO_CALLER) {
7381 return false;
7382 }
7383 }
Dianne Hackborn39c2d712009-09-22 11:41:31 -07007384 }
Sudheer Shankadc589ac2016-11-10 15:30:17 -08007385 int result = ActivityManager.getService()
Dianne Hackbornf265ea92013-01-31 15:00:51 -08007386 .startActivityAsUser(null, null, mHomeIntent,
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08007387 mHomeIntent.resolveTypeIfNeeded(mContext.getContentResolver()),
Dianne Hackborna4972e92012-03-14 10:38:05 -07007388 null, null, 0,
7389 ActivityManager.START_FLAG_ONLY_IF_NEEDED,
Jeff Hao1b012d32014-08-20 10:35:34 -07007390 null, null, UserHandle.USER_CURRENT);
Dianne Hackborna4972e92012-03-14 10:38:05 -07007391 if (result == ActivityManager.START_RETURN_INTENT_TO_CALLER) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08007392 return false;
7393 }
7394 } catch (RemoteException ex) {
7395 // bummer, the activity manager, which is in this process, is dead
7396 }
7397 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08007398 return true;
7399 }
Craig Mautnereda67292013-04-28 13:50:14 -07007400
7401 @Override
The Android Open Source Project0727d222009-03-11 12:11:58 -07007402 public void setCurrentOrientationLw(int newOrientation) {
7403 synchronized (mLock) {
7404 if (newOrientation != mCurrentAppOrientation) {
7405 mCurrentAppOrientation = newOrientation;
7406 updateOrientationListenerLp();
7407 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08007408 }
7409 }
Amith Yamasanic33cb712010-02-10 15:21:49 -08007410
Svetoslav Ganov7befb7d2012-09-27 16:49:23 -07007411 private void performAuditoryFeedbackForAccessibilityIfNeed() {
7412 if (!isGlobalAccessibilityGestureEnabled()) {
7413 return;
7414 }
7415 AudioManager audioManager = (AudioManager) mContext.getSystemService(
7416 Context.AUDIO_SERVICE);
7417 if (audioManager.isSilentMode()) {
7418 return;
7419 }
7420 Ringtone ringTone = RingtoneManager.getRingtone(mContext,
7421 Settings.System.DEFAULT_NOTIFICATION_URI);
7422 ringTone.setStreamType(AudioManager.STREAM_MUSIC);
7423 ringTone.play();
7424 }
Craig Mautnereda67292013-04-28 13:50:14 -07007425
Bryce Lee584a4452014-10-21 15:55:55 -07007426 private boolean isTheaterModeEnabled() {
7427 return Settings.Global.getInt(mContext.getContentResolver(),
7428 Settings.Global.THEATER_MODE_ON, 0) == 1;
7429 }
7430
Svetoslav Ganov7befb7d2012-09-27 16:49:23 -07007431 private boolean isGlobalAccessibilityGestureEnabled() {
7432 return Settings.Global.getInt(mContext.getContentResolver(),
7433 Settings.Global.ENABLE_ACCESSIBILITY_GLOBAL_GESTURE_ENABLED, 0) == 1;
7434 }
7435
Doris Ling628cea42016-06-09 10:35:02 -07007436 private boolean areSystemNavigationKeysEnabled() {
Doris Ling34331b72016-08-09 12:02:28 -07007437 return Settings.Secure.getIntForUser(mContext.getContentResolver(),
7438 Settings.Secure.SYSTEM_NAVIGATION_KEYS_ENABLED, 0, UserHandle.USER_CURRENT) == 1;
Doris Ling628cea42016-06-09 10:35:02 -07007439 }
7440
Craig Mautnereda67292013-04-28 13:50:14 -07007441 @Override
The Android Open Source Project0727d222009-03-11 12:11:58 -07007442 public boolean performHapticFeedbackLw(WindowState win, int effectId, boolean always) {
Svetoslav Ganov96179212012-10-10 14:17:45 -07007443 if (!mVibrator.hasVibrator()) {
7444 return false;
7445 }
Christopher Tate5e08af02012-09-21 17:17:22 -07007446 final boolean hapticsDisabled = Settings.System.getIntForUser(mContext.getContentResolver(),
7447 Settings.System.HAPTIC_FEEDBACK_ENABLED, 0, UserHandle.USER_CURRENT) == 0;
Jeff Brown82379ba2014-07-25 19:03:28 -07007448 if (hapticsDisabled && !always) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08007449 return false;
7450 }
Amith Yamasanic33cb712010-02-10 15:21:49 -08007451 long[] pattern = null;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08007452 switch (effectId) {
7453 case HapticFeedbackConstants.LONG_PRESS:
Amith Yamasanic33cb712010-02-10 15:21:49 -08007454 pattern = mLongPressVibePattern;
7455 break;
Dianne Hackbornb1a79802009-09-29 15:18:31 -07007456 case HapticFeedbackConstants.VIRTUAL_KEY:
Amith Yamasanic33cb712010-02-10 15:21:49 -08007457 pattern = mVirtualKeyVibePattern;
7458 break;
7459 case HapticFeedbackConstants.KEYBOARD_TAP:
7460 pattern = mKeyboardTapVibePattern;
7461 break;
Fabrice Di Meglioeeff63a2013-08-05 12:07:24 -07007462 case HapticFeedbackConstants.CLOCK_TICK:
7463 pattern = mClockTickVibePattern;
7464 break;
Fabrice Di Megliobd9152f2013-10-01 11:21:31 -07007465 case HapticFeedbackConstants.CALENDAR_DATE:
7466 pattern = mCalendarDateVibePattern;
7467 break;
Dianne Hackbornb1a79802009-09-29 15:18:31 -07007468 case HapticFeedbackConstants.SAFE_MODE_DISABLED:
Amith Yamasanic33cb712010-02-10 15:21:49 -08007469 pattern = mSafeModeDisabledVibePattern;
7470 break;
Dianne Hackbornb1a79802009-09-29 15:18:31 -07007471 case HapticFeedbackConstants.SAFE_MODE_ENABLED:
Amith Yamasanic33cb712010-02-10 15:21:49 -08007472 pattern = mSafeModeEnabledVibePattern;
7473 break;
Mady Mellore8608912015-06-05 09:02:55 -07007474 case HapticFeedbackConstants.CONTEXT_CLICK:
7475 pattern = mContextClickVibePattern;
Mady Mellore82067b2015-04-30 09:58:35 -07007476 break;
Amith Yamasanic33cb712010-02-10 15:21:49 -08007477 default:
7478 return false;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08007479 }
Dianne Hackbornf265ea92013-01-31 15:00:51 -08007480 int owningUid;
7481 String owningPackage;
7482 if (win != null) {
7483 owningUid = win.getOwningUid();
7484 owningPackage = win.getOwningPackage();
7485 } else {
7486 owningUid = android.os.Process.myUid();
Dianne Hackborn95d78532013-09-11 09:51:14 -07007487 owningPackage = mContext.getOpPackageName();
Dianne Hackbornf265ea92013-01-31 15:00:51 -08007488 }
Amith Yamasanic33cb712010-02-10 15:21:49 -08007489 if (pattern.length == 1) {
7490 // One-shot vibration
John Spurlock7b414672014-07-18 13:02:39 -04007491 mVibrator.vibrate(owningUid, owningPackage, pattern[0], VIBRATION_ATTRIBUTES);
Amith Yamasanic33cb712010-02-10 15:21:49 -08007492 } else {
7493 // Pattern vibration
John Spurlock7b414672014-07-18 13:02:39 -04007494 mVibrator.vibrate(owningUid, owningPackage, pattern, -1, VIBRATION_ATTRIBUTES);
Amith Yamasanic33cb712010-02-10 15:21:49 -08007495 }
7496 return true;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08007497 }
Jeff Brownc38c9be2012-10-04 13:16:19 -07007498
7499 @Override
7500 public void keepScreenOnStartedLw() {
Daniel Sandler0601eb72011-04-13 01:01:32 -04007501 }
7502
Jeff Brownc38c9be2012-10-04 13:16:19 -07007503 @Override
7504 public void keepScreenOnStoppedLw() {
Jim Millerab954542014-10-10 18:21:49 -07007505 if (isKeyguardShowingAndNotOccluded()) {
Jim Miller25190572013-02-28 17:36:24 -08007506 mPowerManager.userActivity(SystemClock.uptimeMillis(), false);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08007507 }
7508 }
Mike Lockwoodfcb39242009-10-21 23:01:07 -04007509
Dianne Hackborndf89e652011-10-06 22:35:11 -07007510 private int updateSystemUiVisibilityLw() {
Joe Onorato664644d2011-01-23 17:53:23 -08007511 // If there is no window focused, there will be nobody to handle the events
7512 // anyway, so just hang on in whatever state we're in until things settle down.
Adrian Roosdab15162016-09-12 15:08:35 -07007513 WindowState winCandidate = mFocusedWindow != null ? mFocusedWindow
Adrian Roos53f28ec2014-10-29 17:26:12 +01007514 : mTopFullscreenOpaqueWindowState;
Adrian Roosdab15162016-09-12 15:08:35 -07007515 if (winCandidate == null) {
Dianne Hackborndf89e652011-10-06 22:35:11 -07007516 return 0;
7517 }
Adrian Roosdab15162016-09-12 15:08:35 -07007518 if (winCandidate.getAttrs().token == mImmersiveModeConfirmation.getWindowToken()) {
7519 // The immersive mode confirmation should never affect the system bar visibility,
7520 // otherwise it will unhide the navigation bar and hide itself.
7521 winCandidate = isStatusBarKeyguard() ? mStatusBar : mTopFullscreenOpaqueWindowState;
7522 if (winCandidate == null) {
7523 return 0;
7524 }
7525 }
7526 final WindowState win = winCandidate;
Jorim Jaggife762342016-10-13 14:33:27 +02007527 if ((win.getAttrs().privateFlags & PRIVATE_FLAG_KEYGUARD) != 0 && mKeyguardOccluded) {
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07007528 // We are updating at a point where the keyguard has gotten
7529 // focus, but we were last in a state where the top window is
7530 // hiding it. This is probably because the keyguard as been
7531 // shown while the top window was displayed, so we want to ignore
7532 // it here because this is just a very transient change and it
7533 // will quickly lose focus once it correctly gets hidden.
7534 return 0;
7535 }
John Spurlock32beb2c2013-03-11 10:16:47 -04007536
John Spurlock1db8b682014-02-18 11:18:59 -05007537 int tmpVisibility = PolicyControl.getSystemUiVisibility(win, null)
Dianne Hackborne26ab702011-10-16 13:21:33 -07007538 & ~mResettingSystemUiFlags
7539 & ~mForceClearedSystemUiFlags;
John Spurlock79da8332013-09-20 12:04:47 -04007540 if (mForcingShowNavBar && win.getSurfaceLayer() < mForcingShowNavBarLayer) {
John Spurlockc6d1c602014-01-17 15:22:06 -05007541 tmpVisibility &= ~PolicyControl.adjustClearableFlags(win, View.SYSTEM_UI_CLEARABLE_FLAGS);
Dianne Hackborn891d3fb2013-01-09 18:31:37 -08007542 }
Thanh Hai Mai6c009f52015-09-01 16:27:32 -07007543
Jorim Jaggi86905582016-02-09 21:36:09 -08007544 final int fullscreenVisibility = updateLightStatusBarLw(0 /* vis */,
7545 mTopFullscreenOpaqueWindowState, mTopFullscreenOpaqueOrDimmingWindowState);
7546 final int dockedVisibility = updateLightStatusBarLw(0 /* vis */,
7547 mTopDockedOpaqueWindowState, mTopDockedOpaqueOrDimmingWindowState);
7548 mWindowManagerFuncs.getStackBounds(HOME_STACK_ID, mNonDockedStackBounds);
7549 mWindowManagerFuncs.getStackBounds(DOCKED_STACK_ID, mDockedStackBounds);
John Spurlock79da8332013-09-20 12:04:47 -04007550 final int visibility = updateSystemBarsLw(win, mLastSystemUiFlags, tmpVisibility);
John Spurlockad3e6cb2013-04-30 08:47:43 -04007551 final int diff = visibility ^ mLastSystemUiFlags;
Jorim Jaggi86905582016-02-09 21:36:09 -08007552 final int fullscreenDiff = fullscreenVisibility ^ mLastFullscreenStackSysUiFlags;
7553 final int dockedDiff = dockedVisibility ^ mLastDockedStackSysUiFlags;
John Spurlock79da8332013-09-20 12:04:47 -04007554 final boolean needsMenu = win.getNeedsMenuLw(mTopFullscreenOpaqueWindowState);
Jorim Jaggi86905582016-02-09 21:36:09 -08007555 if (diff == 0 && fullscreenDiff == 0 && dockedDiff == 0 && mLastFocusNeedsMenu == needsMenu
7556 && mFocusedApp == win.getAppToken()
7557 && mLastNonDockedStackBounds.equals(mNonDockedStackBounds)
7558 && mLastDockedStackBounds.equals(mDockedStackBounds)) {
Dianne Hackborndf89e652011-10-06 22:35:11 -07007559 return 0;
7560 }
Dianne Hackborne26ab702011-10-16 13:21:33 -07007561 mLastSystemUiFlags = visibility;
Jorim Jaggi86905582016-02-09 21:36:09 -08007562 mLastFullscreenStackSysUiFlags = fullscreenVisibility;
7563 mLastDockedStackSysUiFlags = dockedVisibility;
Dianne Hackborn4eff8d32011-11-10 19:38:40 -08007564 mLastFocusNeedsMenu = needsMenu;
John Spurlock79da8332013-09-20 12:04:47 -04007565 mFocusedApp = win.getAppToken();
Jorim Jaggi86905582016-02-09 21:36:09 -08007566 final Rect fullscreenStackBounds = new Rect(mNonDockedStackBounds);
7567 final Rect dockedStackBounds = new Rect(mDockedStackBounds);
Dianne Hackborndf89e652011-10-06 22:35:11 -07007568 mHandler.post(new Runnable() {
Craig Mautnereda67292013-04-28 13:50:14 -07007569 @Override
Dianne Hackborndf89e652011-10-06 22:35:11 -07007570 public void run() {
Jorim Jaggi86905582016-02-09 21:36:09 -08007571 StatusBarManagerInternal statusbar = getStatusBarManagerInternal();
7572 if (statusbar != null) {
7573 statusbar.setSystemUiVisibility(visibility, fullscreenVisibility,
7574 dockedVisibility, 0xffffffff, fullscreenStackBounds,
7575 dockedStackBounds, win.toString());
7576 statusbar.topAppWindowChanged(needsMenu);
Joe Onorato664644d2011-01-23 17:53:23 -08007577 }
Dianne Hackborndf89e652011-10-06 22:35:11 -07007578 }
7579 });
7580 return diff;
Joe Onorato664644d2011-01-23 17:53:23 -08007581 }
7582
Jorim Jaggi86905582016-02-09 21:36:09 -08007583 private int updateLightStatusBarLw(int vis, WindowState opaque, WindowState opaqueOrDimming) {
Jorim Jaggife762342016-10-13 14:33:27 +02007584 WindowState statusColorWin = isStatusBarKeyguard() && !mKeyguardOccluded
Adrian Rooscd3884d2015-02-18 17:25:23 +01007585 ? mStatusBar
Jorim Jaggi86905582016-02-09 21:36:09 -08007586 : opaqueOrDimming;
Adrian Rooscd3884d2015-02-18 17:25:23 +01007587
7588 if (statusColorWin != null) {
Jorim Jaggi86905582016-02-09 21:36:09 -08007589 if (statusColorWin == opaque) {
Adrian Rooscd3884d2015-02-18 17:25:23 +01007590 // If the top fullscreen-or-dimming window is also the top fullscreen, respect
7591 // its light flag.
7592 vis &= ~View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR;
7593 vis |= PolicyControl.getSystemUiVisibility(statusColorWin, null)
7594 & View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR;
7595 } else if (statusColorWin != null && statusColorWin.isDimming()) {
7596 // Otherwise if it's dimming, clear the light flag.
7597 vis &= ~View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR;
7598 }
7599 }
7600 return vis;
7601 }
7602
Jorim Jaggi8f5701b2016-04-04 18:36:02 -07007603 private boolean drawsSystemBarBackground(WindowState win) {
7604 return win == null || (win.getAttrs().flags & FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS) != 0;
7605 }
7606
7607 private boolean forcesDrawStatusBarBackground(WindowState win) {
7608 return win == null || (win.getAttrs().privateFlags
7609 & PRIVATE_FLAG_FORCE_DRAW_STATUS_BAR_BACKGROUND) != 0;
7610 }
7611
John Spurlock79da8332013-09-20 12:04:47 -04007612 private int updateSystemBarsLw(WindowState win, int oldVis, int vis) {
Wale Ogunwale6e94a9e2015-10-07 15:35:49 -07007613 final boolean dockedStackVisible = mWindowManagerInternal.isStackVisible(DOCKED_STACK_ID);
7614 final boolean freeformStackVisible =
7615 mWindowManagerInternal.isStackVisible(FREEFORM_WORKSPACE_STACK_ID);
Jorim Jaggi9511b0f2016-01-29 19:12:44 -08007616 final boolean resizing = mWindowManagerInternal.isDockedDividerResizing();
7617
7618 // We need to force system bars when the docked stack is visible, when the freeform stack
7619 // is visible but also when we are resizing for the transitions when docked stack
7620 // visibility changes.
Jorim Jaggi0ffd49c2016-02-12 15:04:21 -08007621 mForceShowSystemBars = dockedStackVisible || freeformStackVisible || resizing;
Yorke Lee9b2ffb32016-03-07 20:42:01 -08007622 final boolean forceOpaqueStatusBar = mForceShowSystemBars && !mForceStatusBarFromKeyguard;
Wale Ogunwale6e94a9e2015-10-07 15:35:49 -07007623
John Spurlockbd957402013-10-03 11:38:39 -04007624 // apply translucent bar vis flags
Jorim Jaggife762342016-10-13 14:33:27 +02007625 WindowState fullscreenTransWin = isStatusBarKeyguard() && !mKeyguardOccluded
Jorim Jaggi380ecb82014-03-14 17:25:20 +01007626 ? mStatusBar
John Spurlockbd957402013-10-03 11:38:39 -04007627 : mTopFullscreenOpaqueWindowState;
Jorim Jaggi8f5701b2016-04-04 18:36:02 -07007628 vis = mStatusBarController.applyTranslucentFlagLw(fullscreenTransWin, vis, oldVis);
7629 vis = mNavigationBarController.applyTranslucentFlagLw(fullscreenTransWin, vis, oldVis);
7630 final int dockedVis = mStatusBarController.applyTranslucentFlagLw(
7631 mTopDockedOpaqueWindowState, 0, 0);
7632
7633 final boolean fullscreenDrawsStatusBarBackground =
7634 (drawsSystemBarBackground(mTopFullscreenOpaqueWindowState)
7635 && (vis & View.STATUS_BAR_TRANSLUCENT) == 0)
7636 || forcesDrawStatusBarBackground(mTopFullscreenOpaqueWindowState);
7637 final boolean dockedDrawsStatusBarBackground =
7638 (drawsSystemBarBackground(mTopDockedOpaqueWindowState)
7639 && (dockedVis & View.STATUS_BAR_TRANSLUCENT) == 0)
7640 || forcesDrawStatusBarBackground(mTopDockedOpaqueWindowState);
John Spurlockbd957402013-10-03 11:38:39 -04007641
John Spurlock27735a42013-08-14 17:57:38 -04007642 // prevent status bar interaction from clearing certain flags
Selim Cinekf83e8242015-05-19 18:08:14 -07007643 int type = win.getAttrs().type;
7644 boolean statusBarHasFocus = type == TYPE_STATUS_BAR;
John Spurlock08ffcf52014-07-11 10:13:46 -04007645 if (statusBarHasFocus && !isStatusBarKeyguard()) {
John Spurlockad3e6cb2013-04-30 08:47:43 -04007646 int flags = View.SYSTEM_UI_FLAG_FULLSCREEN
7647 | View.SYSTEM_UI_FLAG_HIDE_NAVIGATION
John Spurlockcfc359a2013-09-05 10:42:03 -04007648 | View.SYSTEM_UI_FLAG_IMMERSIVE
Jorim Jaggi73fef8d2015-02-16 17:32:28 +01007649 | View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY
7650 | View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR;
Jorim Jaggife762342016-10-13 14:33:27 +02007651 if (mKeyguardOccluded) {
Jorim Jaggi5cf17872014-03-26 18:31:48 +01007652 flags |= View.STATUS_BAR_TRANSLUCENT | View.NAVIGATION_BAR_TRANSLUCENT;
7653 }
John Spurlockbd957402013-10-03 11:38:39 -04007654 vis = (vis & ~flags) | (oldVis & flags);
John Spurlockad3e6cb2013-04-30 08:47:43 -04007655 }
John Spurlockad3e6cb2013-04-30 08:47:43 -04007656
Jorim Jaggi8f5701b2016-04-04 18:36:02 -07007657 if (fullscreenDrawsStatusBarBackground && dockedDrawsStatusBarBackground) {
7658 vis |= View.STATUS_BAR_TRANSPARENT;
7659 vis &= ~View.STATUS_BAR_TRANSLUCENT;
7660 } else if ((!areTranslucentBarsAllowed() && fullscreenTransWin != mStatusBar)
Yorke Lee9b2ffb32016-03-07 20:42:01 -08007661 || forceOpaqueStatusBar) {
7662 vis &= ~(View.STATUS_BAR_TRANSLUCENT | View.STATUS_BAR_TRANSPARENT);
Alan Viverette5a0f4ec2013-10-07 15:10:29 -07007663 }
7664
Yorke Lee9b2ffb32016-03-07 20:42:01 -08007665 vis = configureNavBarOpacity(vis, dockedStackVisible, freeformStackVisible, resizing);
Yorke Lee2e4b7322016-03-02 17:33:06 -08007666
John Spurlock27735a42013-08-14 17:57:38 -04007667 // update status bar
John Spurlockf1a36642013-10-12 17:50:42 -04007668 boolean immersiveSticky =
7669 (vis & View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY) != 0;
Wale Ogunwale6e94a9e2015-10-07 15:35:49 -07007670 final boolean hideStatusBarWM =
7671 mTopFullscreenOpaqueWindowState != null
7672 && (PolicyControl.getWindowFlags(mTopFullscreenOpaqueWindowState, null)
John Spurlock27735a42013-08-14 17:57:38 -04007673 & WindowManager.LayoutParams.FLAG_FULLSCREEN) != 0;
Wale Ogunwale6e94a9e2015-10-07 15:35:49 -07007674 final boolean hideStatusBarSysui =
John Spurlock27735a42013-08-14 17:57:38 -04007675 (vis & View.SYSTEM_UI_FLAG_FULLSCREEN) != 0;
Wale Ogunwale6e94a9e2015-10-07 15:35:49 -07007676 final boolean hideNavBarSysui =
John Spurlockf1a36642013-10-12 17:50:42 -04007677 (vis & View.SYSTEM_UI_FLAG_HIDE_NAVIGATION) != 0;
John Spurlockad3e6cb2013-04-30 08:47:43 -04007678
Wale Ogunwale6e94a9e2015-10-07 15:35:49 -07007679 final boolean transientStatusBarAllowed = mStatusBar != null
Jorim Jaggi0ffd49c2016-02-12 15:04:21 -08007680 && (statusBarHasFocus || (!mForceShowSystemBars
Wale Ogunwale6e94a9e2015-10-07 15:35:49 -07007681 && (hideStatusBarWM || (hideStatusBarSysui && immersiveSticky))));
John Spurlock27735a42013-08-14 17:57:38 -04007682
Wale Ogunwale6e94a9e2015-10-07 15:35:49 -07007683 final boolean transientNavBarAllowed = mNavigationBar != null
Jorim Jaggi0ffd49c2016-02-12 15:04:21 -08007684 && !mForceShowSystemBars && hideNavBarSysui && immersiveSticky;
John Spurlockf1a36642013-10-12 17:50:42 -04007685
Adrian Roosddc8b272015-05-21 16:28:27 -07007686 final long now = SystemClock.uptimeMillis();
7687 final boolean pendingPanic = mPendingPanicGestureUptime != 0
7688 && now - mPendingPanicGestureUptime <= PANIC_GESTURE_EXPIRATION;
7689 if (pendingPanic && hideNavBarSysui && !isStatusBarKeyguard() && mKeyguardDrawComplete) {
7690 // The user performed the panic gesture recently, we're about to hide the bars,
7691 // we're no longer on the Keyguard and the screen is ready. We can now request the bars.
7692 mPendingPanicGestureUptime = 0;
7693 mStatusBarController.showTransient();
Adrian Roos1f425902016-07-22 10:37:50 -07007694 if (!isNavBarEmpty(vis)) {
7695 mNavigationBarController.showTransient();
7696 }
Adrian Roosddc8b272015-05-21 16:28:27 -07007697 }
7698
Wale Ogunwale6e94a9e2015-10-07 15:35:49 -07007699 final boolean denyTransientStatus = mStatusBarController.isTransientShowRequested()
John Spurlockf1a36642013-10-12 17:50:42 -04007700 && !transientStatusBarAllowed && hideStatusBarSysui;
Wale Ogunwale6e94a9e2015-10-07 15:35:49 -07007701 final boolean denyTransientNav = mNavigationBarController.isTransientShowRequested()
John Spurlockf1a36642013-10-12 17:50:42 -04007702 && !transientNavBarAllowed;
Jorim Jaggi0ffd49c2016-02-12 15:04:21 -08007703 if (denyTransientStatus || denyTransientNav || mForceShowSystemBars) {
John Spurlock27735a42013-08-14 17:57:38 -04007704 // clear the clearable flags instead
John Spurlockf1a36642013-10-12 17:50:42 -04007705 clearClearableFlagsLw();
tiger_huangc58d7562014-10-23 20:24:19 +08007706 vis &= ~View.SYSTEM_UI_CLEARABLE_FLAGS;
John Spurlockad3e6cb2013-04-30 08:47:43 -04007707 }
John Spurlock27735a42013-08-14 17:57:38 -04007708
Selim Cinekf98702e2015-05-20 22:48:40 -07007709 final boolean immersive = (vis & View.SYSTEM_UI_FLAG_IMMERSIVE) != 0;
7710 immersiveSticky = (vis & View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY) != 0;
7711 final boolean navAllowedHidden = immersive || immersiveSticky;
7712
Selim Cinekd6623612015-05-22 18:56:22 -07007713 if (hideNavBarSysui && !navAllowedHidden && windowTypeToLayerLw(win.getBaseType())
7714 > windowTypeToLayerLw(TYPE_INPUT_CONSUMER)) {
Selim Cinekf98702e2015-05-20 22:48:40 -07007715 // We can't hide the navbar from this window otherwise the input consumer would not get
7716 // the input events.
7717 vis = (vis & ~View.SYSTEM_UI_FLAG_HIDE_NAVIGATION);
7718 }
7719
John Spurlock27735a42013-08-14 17:57:38 -04007720 vis = mStatusBarController.updateVisibilityLw(transientStatusBarAllowed, oldVis, vis);
7721
7722 // update navigation bar
John Spurlockf1a36642013-10-12 17:50:42 -04007723 boolean oldImmersiveMode = isImmersiveMode(oldVis);
7724 boolean newImmersiveMode = isImmersiveMode(vis);
7725 if (win != null && oldImmersiveMode != newImmersiveMode) {
John Spurlock79da8332013-09-20 12:04:47 -04007726 final String pkg = win.getOwningPackage();
Amith Yamasani02a03812016-04-22 17:32:00 -07007727 mImmersiveModeConfirmation.immersiveModeChangedLw(pkg, newImmersiveMode,
Adrian Roos7aaa5512016-07-12 15:27:24 -07007728 isUserSetupComplete(), isNavBarEmpty(win.getSystemUiVisibility()));
John Spurlock34e13d92013-08-10 06:52:28 -04007729 }
John Spurlock27735a42013-08-14 17:57:38 -04007730
John Spurlockf1a36642013-10-12 17:50:42 -04007731 vis = mNavigationBarController.updateVisibilityLw(transientNavBarAllowed, oldVis, vis);
7732
John Spurlocke1f366f2013-08-05 12:22:40 -04007733 return vis;
John Spurlockad3e6cb2013-04-30 08:47:43 -04007734 }
7735
Yorke Lee9b2ffb32016-03-07 20:42:01 -08007736 /**
7737 * @return the current visibility flags with the nav-bar opacity related flags toggled based
7738 * on the nav bar opacity rules chosen by {@link #mNavBarOpacityMode}.
7739 */
7740 private int configureNavBarOpacity(int visibility, boolean dockedStackVisible,
7741 boolean freeformStackVisible, boolean isDockedDividerResizing) {
7742 if (mNavBarOpacityMode == NAV_BAR_OPAQUE_WHEN_FREEFORM_OR_DOCKED) {
7743 if (dockedStackVisible || freeformStackVisible || isDockedDividerResizing) {
7744 visibility = setNavBarOpaqueFlag(visibility);
7745 }
7746 } else if (mNavBarOpacityMode == NAV_BAR_TRANSLUCENT_WHEN_FREEFORM_OPAQUE_OTHERWISE) {
7747 if (isDockedDividerResizing) {
7748 visibility = setNavBarOpaqueFlag(visibility);
7749 } else if (freeformStackVisible) {
7750 visibility = setNavBarTranslucentFlag(visibility);
7751 } else {
7752 visibility = setNavBarOpaqueFlag(visibility);
7753 }
7754 }
7755
7756 if (!areTranslucentBarsAllowed()) {
7757 visibility &= ~View.NAVIGATION_BAR_TRANSLUCENT;
7758 }
7759 return visibility;
7760 }
7761
7762 private int setNavBarOpaqueFlag(int visibility) {
7763 return visibility &= ~(View.NAVIGATION_BAR_TRANSLUCENT | View.NAVIGATION_BAR_TRANSPARENT);
7764 }
7765
7766 private int setNavBarTranslucentFlag(int visibility) {
7767 visibility &= ~View.NAVIGATION_BAR_TRANSPARENT;
7768 return visibility |= View.NAVIGATION_BAR_TRANSLUCENT;
7769 }
7770
John Spurlockf1a36642013-10-12 17:50:42 -04007771 private void clearClearableFlagsLw() {
7772 int newVal = mResettingSystemUiFlags | View.SYSTEM_UI_CLEARABLE_FLAGS;
7773 if (newVal != mResettingSystemUiFlags) {
7774 mResettingSystemUiFlags = newVal;
7775 mWindowManagerFuncs.reevaluateStatusBarVisibility();
7776 }
7777 }
7778
7779 private boolean isImmersiveMode(int vis) {
7780 final int flags = View.SYSTEM_UI_FLAG_IMMERSIVE | View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY;
John Spurlock34e13d92013-08-10 06:52:28 -04007781 return mNavigationBar != null
7782 && (vis & View.SYSTEM_UI_FLAG_HIDE_NAVIGATION) != 0
Daniel Sandler900ece52013-10-18 15:53:27 -04007783 && (vis & flags) != 0
7784 && canHideNavigationBar();
John Spurlock34e13d92013-08-10 06:52:28 -04007785 }
7786
Adrian Roos7aaa5512016-07-12 15:27:24 -07007787 private static boolean isNavBarEmpty(int systemUiFlags) {
7788 final int disableNavigationBar = (View.STATUS_BAR_DISABLE_HOME
7789 | View.STATUS_BAR_DISABLE_BACK
7790 | View.STATUS_BAR_DISABLE_RECENT);
7791
7792 return (systemUiFlags & disableNavigationBar) == disableNavigationBar;
7793 }
7794
Alan Viverette5a0f4ec2013-10-07 15:10:29 -07007795 /**
Daniel Sandlerdd73ee42013-10-11 22:19:59 -04007796 * @return whether the navigation or status bar can be made translucent
7797 *
7798 * This should return true unless touch exploration is not enabled or
7799 * R.boolean.config_enableTranslucentDecor is false.
Alan Viverette5a0f4ec2013-10-07 15:10:29 -07007800 */
Daniel Sandlerdd73ee42013-10-11 22:19:59 -04007801 private boolean areTranslucentBarsAllowed() {
Alan Viverette817f3cd2015-08-13 11:40:14 -04007802 return mTranslucentDecorEnabled;
Alan Viverette5a0f4ec2013-10-07 15:10:29 -07007803 }
7804
Daniel Sandler0c4ccff2011-10-19 16:39:14 -04007805 // Use this instead of checking config_showNavigationBar so that it can be consistently
7806 // overridden by qemu.hw.mainkeys in the emulator.
Craig Mautnereda67292013-04-28 13:50:14 -07007807 @Override
Daniel Sandler0c4ccff2011-10-19 16:39:14 -04007808 public boolean hasNavigationBar() {
7809 return mHasNavigationBar;
7810 }
7811
satok1bc0a492012-04-25 22:47:12 +09007812 @Override
7813 public void setLastInputMethodWindowLw(WindowState ime, WindowState target) {
7814 mLastInputMethodWindow = ime;
7815 mLastInputMethodTargetWindow = target;
7816 }
7817
Craig Mautnerf1b67412012-09-19 13:18:29 -07007818 @Override
Satoshi Kataoka658c7b82013-10-10 17:03:51 +09007819 public int getInputMethodWindowVisibleHeightLw() {
7820 return mDockBottom - mCurBottom;
7821 }
7822
7823 @Override
Craig Mautnerf1b67412012-09-19 13:18:29 -07007824 public void setCurrentUserLw(int newUserId) {
Craig Mautnerd625ab22013-09-06 13:40:31 -07007825 mCurrentUserId = newUserId;
Jim Miller5ecd8112013-01-09 18:50:26 -08007826 if (mKeyguardDelegate != null) {
7827 mKeyguardDelegate.setCurrentUser(newUserId);
Craig Mautnerf1b67412012-09-19 13:18:29 -07007828 }
Adrian Roosf2efdd82016-04-15 17:43:18 -07007829 StatusBarManagerInternal statusBar = getStatusBarManagerInternal();
Adrian Roos2a629102016-04-15 16:28:03 -07007830 if (statusBar != null) {
Adrian Roosf2efdd82016-04-15 17:43:18 -07007831 statusBar.setCurrentUser(newUserId);
John Spurlock13451a22012-09-28 14:40:41 -04007832 }
Dianne Hackborn2ea9bae2012-11-02 18:43:48 -07007833 setLastInputMethodWindowLw(null, null);
Craig Mautnerf1b67412012-09-19 13:18:29 -07007834 }
7835
7836 @Override
Evan Rosky18396452016-07-27 15:19:37 -07007837 public void setSwitchingUser(boolean switching) {
7838 mKeyguardDelegate.setSwitchingUser(switching);
7839 }
7840
7841 @Override
Svetoslav Ganov545252f2012-12-10 18:29:24 -08007842 public boolean canMagnifyWindow(int windowType) {
7843 switch (windowType) {
7844 case WindowManager.LayoutParams.TYPE_INPUT_METHOD:
7845 case WindowManager.LayoutParams.TYPE_INPUT_METHOD_DIALOG:
7846 case WindowManager.LayoutParams.TYPE_NAVIGATION_BAR:
7847 case WindowManager.LayoutParams.TYPE_MAGNIFICATION_OVERLAY: {
7848 return false;
7849 }
7850 }
7851 return true;
7852 }
7853
7854 @Override
7855 public boolean isTopLevelWindow(int windowType) {
7856 if (windowType >= WindowManager.LayoutParams.FIRST_SUB_WINDOW
7857 && windowType <= WindowManager.LayoutParams.LAST_SUB_WINDOW) {
7858 return (windowType == WindowManager.LayoutParams.TYPE_APPLICATION_ATTACHED_DIALOG);
7859 }
7860 return true;
7861 }
7862
Jim Miller4eeb4f62012-11-08 00:04:29 -08007863 @Override
Robert Carr6da3cc02016-06-16 15:17:07 -07007864 public boolean shouldRotateSeamlessly(int oldRotation, int newRotation) {
7865 // For the upside down rotation we don't rotate seamlessly as the navigation
7866 // bar moves position.
7867 // Note most apps (using orientation:sensor or user as opposed to fullSensor)
7868 // will not enter the reverse portrait orientation, so actually the
7869 // orientation won't change at all.
7870 if (oldRotation == mUpsideDownRotation || newRotation == mUpsideDownRotation) {
7871 return false;
7872 }
Robert Carr0b9ac5a2016-10-26 14:12:14 -07007873 // If the navigation bar can't change sides, then it will
7874 // jump when we change orientations and we don't rotate
7875 // seamlessly.
7876 if (!mNavigationBarCanMove) {
7877 return false;
7878 }
Robert Carr6da3cc02016-06-16 15:17:07 -07007879 int delta = newRotation - oldRotation;
7880 if (delta < 0) delta += 4;
7881 // Likewise we don't rotate seamlessly for 180 degree rotations
Geoffrey Pitschb2d6ed32016-08-24 10:37:19 -04007882 // in this case the surfaces never resize, and our logic to
Robert Carr6da3cc02016-06-16 15:17:07 -07007883 // revert the transformations on size change will fail. We could
7884 // fix this in the future with the "tagged" frames idea.
7885 if (delta == Surface.ROTATION_180) {
7886 return false;
7887 }
7888
Robert Carr57d9fbd2016-08-15 12:00:35 -07007889 final WindowState w = mTopFullscreenOpaqueWindowState;
Robert Carr828ec3dc2016-08-22 13:32:34 -07007890 if (w != mFocusedWindow) {
7891 return false;
7892 }
Robert Carr57d9fbd2016-08-15 12:00:35 -07007893
Robert Carr606f4d52016-06-30 14:36:27 -07007894 // We only enable seamless rotation if the top window has requested
7895 // it and is in the fullscreen opaque state. Seamless rotation
7896 // requires freezing various Surface states and won't work well
7897 // with animations, so we disable it in the animation case for now.
Robert Carr1ccd4252016-08-15 12:05:21 -07007898 if (w != null && !w.isAnimatingLw() &&
Robert Carr57d9fbd2016-08-15 12:00:35 -07007899 ((w.getAttrs().rotationAnimation == ROTATION_ANIMATION_JUMPCUT) ||
7900 (w.getAttrs().rotationAnimation == ROTATION_ANIMATION_SEAMLESS))) {
Robert Carr6da3cc02016-06-16 15:17:07 -07007901 return true;
7902 }
7903 return false;
7904 }
7905
7906 @Override
Jeff Brownd7a04de2012-06-17 14:17:52 -07007907 public void dump(String prefix, PrintWriter pw, String[] args) {
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08007908 pw.print(prefix); pw.print("mSafeMode="); pw.print(mSafeMode);
Dianne Hackbornba24e4d2011-09-01 11:17:06 -07007909 pw.print(" mSystemReady="); pw.print(mSystemReady);
7910 pw.print(" mSystemBooted="); pw.println(mSystemBooted);
Jeff Brown2e7760e2012-04-11 15:14:55 -07007911 pw.print(prefix); pw.print("mLidState="); pw.print(mLidState);
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08007912 pw.print(" mLidOpenRotation="); pw.print(mLidOpenRotation);
Michael Wright3818c922014-09-02 13:59:07 -07007913 pw.print(" mCameraLensCoverState="); pw.print(mCameraLensCoverState);
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08007914 pw.print(" mHdmiPlugged="); pw.println(mHdmiPlugged);
Dianne Hackborne26ab702011-10-16 13:21:33 -07007915 if (mLastSystemUiFlags != 0 || mResettingSystemUiFlags != 0
7916 || mForceClearedSystemUiFlags != 0) {
7917 pw.print(prefix); pw.print("mLastSystemUiFlags=0x");
7918 pw.print(Integer.toHexString(mLastSystemUiFlags));
7919 pw.print(" mResettingSystemUiFlags=0x");
7920 pw.print(Integer.toHexString(mResettingSystemUiFlags));
7921 pw.print(" mForceClearedSystemUiFlags=0x");
7922 pw.println(Integer.toHexString(mForceClearedSystemUiFlags));
Dianne Hackborndf89e652011-10-06 22:35:11 -07007923 }
Dianne Hackborn4eff8d32011-11-10 19:38:40 -08007924 if (mLastFocusNeedsMenu) {
7925 pw.print(prefix); pw.print("mLastFocusNeedsMenu=");
7926 pw.println(mLastFocusNeedsMenu);
7927 }
Jeff Browna20dda42014-05-27 20:57:24 -07007928 pw.print(prefix); pw.print("mWakeGestureEnabledSetting=");
7929 pw.println(mWakeGestureEnabledSetting);
7930
Jeff Brownbcdfc622014-03-06 19:13:04 -08007931 pw.print(prefix); pw.print("mSupportAutoRotation="); pw.println(mSupportAutoRotation);
Daniel Sandler6396c722013-04-16 20:19:09 -04007932 pw.print(prefix); pw.print("mUiMode="); pw.print(mUiMode);
7933 pw.print(" mDockMode="); pw.print(mDockMode);
keunyounga7710492015-09-23 11:33:58 -07007934 pw.print(" mEnableCarDockHomeCapture="); pw.print(mEnableCarDockHomeCapture);
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08007935 pw.print(" mCarDockRotation="); pw.print(mCarDockRotation);
7936 pw.print(" mDeskDockRotation="); pw.println(mDeskDockRotation);
7937 pw.print(prefix); pw.print("mUserRotationMode="); pw.print(mUserRotationMode);
7938 pw.print(" mUserRotation="); pw.print(mUserRotation);
Daniel Sandler2ed6ad62011-02-22 14:54:17 -05007939 pw.print(" mAllowAllRotations="); pw.println(mAllowAllRotations);
Dianne Hackborn6e2281d2012-06-19 17:48:32 -07007940 pw.print(prefix); pw.print("mCurrentAppOrientation="); pw.println(mCurrentAppOrientation);
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08007941 pw.print(prefix); pw.print("mCarDockEnablesAccelerometer=");
7942 pw.print(mCarDockEnablesAccelerometer);
7943 pw.print(" mDeskDockEnablesAccelerometer=");
7944 pw.println(mDeskDockEnablesAccelerometer);
7945 pw.print(prefix); pw.print("mLidKeyboardAccessibility=");
7946 pw.print(mLidKeyboardAccessibility);
7947 pw.print(" mLidNavigationAccessibility="); pw.print(mLidNavigationAccessibility);
Edward Savage-Jones7def60d2015-11-13 13:27:03 +01007948 pw.print(" mLidControlsScreenLock="); pw.println(mLidControlsScreenLock);
Dianne Hackborn6e2281d2012-06-19 17:48:32 -07007949 pw.print(" mLidControlsSleep="); pw.println(mLidControlsSleep);
Jeff Brown6d8fd272014-05-20 21:24:38 -07007950 pw.print(prefix);
Anthony Hugh34f09ca2016-03-04 12:03:37 -08007951 pw.print(" mLongPressOnBackBehavior="); pw.println(mLongPressOnBackBehavior);
7952 pw.print(prefix);
Jeff Brown6d8fd272014-05-20 21:24:38 -07007953 pw.print("mShortPressOnPowerBehavior="); pw.print(mShortPressOnPowerBehavior);
7954 pw.print(" mLongPressOnPowerBehavior="); pw.println(mLongPressOnPowerBehavior);
Jeff Brown13f00f02014-10-31 14:45:50 -07007955 pw.print(prefix);
7956 pw.print("mDoublePressOnPowerBehavior="); pw.print(mDoublePressOnPowerBehavior);
7957 pw.print(" mTriplePressOnPowerBehavior="); pw.println(mTriplePressOnPowerBehavior);
Jeff Brown6d8fd272014-05-20 21:24:38 -07007958 pw.print(prefix); pw.print("mHasSoftInput="); pw.println(mHasSoftInput);
Jeff Brown3ee549c2014-09-22 20:14:39 -07007959 pw.print(prefix); pw.print("mAwake="); pw.println(mAwake);
7960 pw.print(prefix); pw.print("mScreenOnEarly="); pw.print(mScreenOnEarly);
7961 pw.print(" mScreenOnFully="); pw.println(mScreenOnFully);
7962 pw.print(prefix); pw.print("mKeyguardDrawComplete="); pw.print(mKeyguardDrawComplete);
7963 pw.print(" mWindowManagerDrawComplete="); pw.println(mWindowManagerDrawComplete);
7964 pw.print(prefix); pw.print("mOrientationSensorEnabled=");
7965 pw.println(mOrientationSensorEnabled);
Dianne Hackbornc652de82013-02-15 16:32:56 -08007966 pw.print(prefix); pw.print("mOverscanScreen=("); pw.print(mOverscanScreenLeft);
7967 pw.print(","); pw.print(mOverscanScreenTop);
7968 pw.print(") "); pw.print(mOverscanScreenWidth);
7969 pw.print("x"); pw.println(mOverscanScreenHeight);
7970 if (mOverscanLeft != 0 || mOverscanTop != 0
7971 || mOverscanRight != 0 || mOverscanBottom != 0) {
7972 pw.print(prefix); pw.print("mOverscan left="); pw.print(mOverscanLeft);
7973 pw.print(" top="); pw.print(mOverscanTop);
7974 pw.print(" right="); pw.print(mOverscanRight);
7975 pw.print(" bottom="); pw.println(mOverscanBottom);
7976 }
Dianne Hackborn313440842013-02-19 19:22:59 -08007977 pw.print(prefix); pw.print("mRestrictedOverscanScreen=(");
7978 pw.print(mRestrictedOverscanScreenLeft);
7979 pw.print(","); pw.print(mRestrictedOverscanScreenTop);
7980 pw.print(") "); pw.print(mRestrictedOverscanScreenWidth);
7981 pw.print("x"); pw.println(mRestrictedOverscanScreenHeight);
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08007982 pw.print(prefix); pw.print("mUnrestrictedScreen=("); pw.print(mUnrestrictedScreenLeft);
7983 pw.print(","); pw.print(mUnrestrictedScreenTop);
7984 pw.print(") "); pw.print(mUnrestrictedScreenWidth);
7985 pw.print("x"); pw.println(mUnrestrictedScreenHeight);
7986 pw.print(prefix); pw.print("mRestrictedScreen=("); pw.print(mRestrictedScreenLeft);
7987 pw.print(","); pw.print(mRestrictedScreenTop);
7988 pw.print(") "); pw.print(mRestrictedScreenWidth);
7989 pw.print("x"); pw.println(mRestrictedScreenHeight);
Dianne Hackborn5b5cc4d2012-05-16 13:15:00 -07007990 pw.print(prefix); pw.print("mStableFullscreen=("); pw.print(mStableFullscreenLeft);
7991 pw.print(","); pw.print(mStableFullscreenTop);
7992 pw.print(")-("); pw.print(mStableFullscreenRight);
7993 pw.print(","); pw.print(mStableFullscreenBottom); pw.println(")");
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07007994 pw.print(prefix); pw.print("mStable=("); pw.print(mStableLeft);
7995 pw.print(","); pw.print(mStableTop);
7996 pw.print(")-("); pw.print(mStableRight);
7997 pw.print(","); pw.print(mStableBottom); pw.println(")");
Dianne Hackborn5c58de32012-04-28 19:52:37 -07007998 pw.print(prefix); pw.print("mSystem=("); pw.print(mSystemLeft);
7999 pw.print(","); pw.print(mSystemTop);
8000 pw.print(")-("); pw.print(mSystemRight);
8001 pw.print(","); pw.print(mSystemBottom); pw.println(")");
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08008002 pw.print(prefix); pw.print("mCur=("); pw.print(mCurLeft);
8003 pw.print(","); pw.print(mCurTop);
8004 pw.print(")-("); pw.print(mCurRight);
8005 pw.print(","); pw.print(mCurBottom); pw.println(")");
8006 pw.print(prefix); pw.print("mContent=("); pw.print(mContentLeft);
8007 pw.print(","); pw.print(mContentTop);
8008 pw.print(")-("); pw.print(mContentRight);
8009 pw.print(","); pw.print(mContentBottom); pw.println(")");
Dianne Hackborne30e02f2014-05-27 18:24:45 -07008010 pw.print(prefix); pw.print("mVoiceContent=("); pw.print(mVoiceContentLeft);
8011 pw.print(","); pw.print(mVoiceContentTop);
8012 pw.print(")-("); pw.print(mVoiceContentRight);
8013 pw.print(","); pw.print(mVoiceContentBottom); pw.println(")");
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08008014 pw.print(prefix); pw.print("mDock=("); pw.print(mDockLeft);
8015 pw.print(","); pw.print(mDockTop);
8016 pw.print(")-("); pw.print(mDockRight);
8017 pw.print(","); pw.print(mDockBottom); pw.println(")");
Dianne Hackborn5c58de32012-04-28 19:52:37 -07008018 pw.print(prefix); pw.print("mDockLayer="); pw.print(mDockLayer);
8019 pw.print(" mStatusBarLayer="); pw.println(mStatusBarLayer);
Jorim Jaggi8d786932016-10-26 19:08:36 -07008020 pw.print(prefix); pw.print("mShowingDream="); pw.print(mShowingDream);
Jeff Brown061ea992015-04-17 19:55:47 -07008021 pw.print(" mDreamingLockscreen="); pw.print(mDreamingLockscreen);
8022 pw.print(" mDreamingSleepToken="); pw.println(mDreamingSleepToken);
Dianne Hackborn2ea9bae2012-11-02 18:43:48 -07008023 if (mLastInputMethodWindow != null) {
8024 pw.print(prefix); pw.print("mLastInputMethodWindow=");
8025 pw.println(mLastInputMethodWindow);
8026 }
8027 if (mLastInputMethodTargetWindow != null) {
8028 pw.print(prefix); pw.print("mLastInputMethodTargetWindow=");
8029 pw.println(mLastInputMethodTargetWindow);
8030 }
8031 if (mStatusBar != null) {
8032 pw.print(prefix); pw.print("mStatusBar=");
Dianne Hackbornae6688b2015-02-11 17:02:41 -08008033 pw.print(mStatusBar); pw.print(" isStatusBarKeyguard=");
8034 pw.println(isStatusBarKeyguard());
Dianne Hackborn2ea9bae2012-11-02 18:43:48 -07008035 }
8036 if (mNavigationBar != null) {
8037 pw.print(prefix); pw.print("mNavigationBar=");
8038 pw.println(mNavigationBar);
8039 }
Dianne Hackborn2ea9bae2012-11-02 18:43:48 -07008040 if (mFocusedWindow != null) {
8041 pw.print(prefix); pw.print("mFocusedWindow=");
8042 pw.println(mFocusedWindow);
8043 }
8044 if (mFocusedApp != null) {
8045 pw.print(prefix); pw.print("mFocusedApp=");
8046 pw.println(mFocusedApp);
8047 }
Dianne Hackborn2ea9bae2012-11-02 18:43:48 -07008048 if (mTopFullscreenOpaqueWindowState != null) {
8049 pw.print(prefix); pw.print("mTopFullscreenOpaqueWindowState=");
8050 pw.println(mTopFullscreenOpaqueWindowState);
8051 }
Adrian Rooscd3884d2015-02-18 17:25:23 +01008052 if (mTopFullscreenOpaqueOrDimmingWindowState != null) {
8053 pw.print(prefix); pw.print("mTopFullscreenOpaqueOrDimmingWindowState=");
8054 pw.println(mTopFullscreenOpaqueOrDimmingWindowState);
8055 }
Dianne Hackborn891d3fb2013-01-09 18:31:37 -08008056 if (mForcingShowNavBar) {
8057 pw.print(prefix); pw.print("mForcingShowNavBar=");
8058 pw.println(mForcingShowNavBar); pw.print( "mForcingShowNavBarLayer=");
8059 pw.println(mForcingShowNavBarLayer);
8060 }
Dianne Hackborn7ad44382012-10-18 17:46:00 -07008061 pw.print(prefix); pw.print("mTopIsFullscreen="); pw.print(mTopIsFullscreen);
Jorim Jaggife762342016-10-13 14:33:27 +02008062 pw.print(" mKeyguardOccluded="); pw.println(mKeyguardOccluded);
Jorim Jaggi8d786932016-10-26 19:08:36 -07008063 pw.print(" mKeyguardOccludedChanged="); pw.println(mKeyguardOccludedChanged);
8064 pw.print(" mPendingKeyguardOccluded="); pw.println(mPendingKeyguardOccluded);
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07008065 pw.print(prefix); pw.print("mForceStatusBar="); pw.print(mForceStatusBar);
8066 pw.print(" mForceStatusBarFromKeyguard=");
8067 pw.println(mForceStatusBarFromKeyguard);
Jorim Jaggife762342016-10-13 14:33:27 +02008068 pw.print(prefix); pw.print("mHomePressed="); pw.println(mHomePressed);
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08008069 pw.print(prefix); pw.print("mAllowLockscreenWhenOn="); pw.print(mAllowLockscreenWhenOn);
8070 pw.print(" mLockScreenTimeout="); pw.print(mLockScreenTimeout);
8071 pw.print(" mLockScreenTimerActive="); pw.println(mLockScreenTimerActive);
8072 pw.print(prefix); pw.print("mEndcallBehavior="); pw.print(mEndcallBehavior);
8073 pw.print(" mIncallPowerBehavior="); pw.print(mIncallPowerBehavior);
Bryce Leedb776ce2016-09-03 15:02:00 -07008074 pw.print(" mIncallBackBehavior="); pw.print(mIncallBackBehavior);
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08008075 pw.print(" mLongPressOnHomeBehavior="); pw.println(mLongPressOnHomeBehavior);
8076 pw.print(prefix); pw.print("mLandscapeRotation="); pw.print(mLandscapeRotation);
8077 pw.print(" mSeascapeRotation="); pw.println(mSeascapeRotation);
8078 pw.print(prefix); pw.print("mPortraitRotation="); pw.print(mPortraitRotation);
8079 pw.print(" mUpsideDownRotation="); pw.println(mUpsideDownRotation);
Jeff Brownc82c89ed2013-04-17 17:18:15 -07008080 pw.print(prefix); pw.print("mDemoHdmiRotation="); pw.print(mDemoHdmiRotation);
8081 pw.print(" mDemoHdmiRotationLock="); pw.println(mDemoHdmiRotationLock);
8082 pw.print(prefix); pw.print("mUndockedHdmiRotation="); pw.println(mUndockedHdmiRotation);
Jeff Brown600f0032014-05-22 17:06:00 -07008083
Tim Kilbournd7c0c2e2014-05-29 16:08:10 -07008084 mGlobalKeyManager.dump(prefix, pw);
John Spurlock27735a42013-08-14 17:57:38 -04008085 mStatusBarController.dump(pw, prefix);
8086 mNavigationBarController.dump(pw, prefix);
John Spurlockc6d1c602014-01-17 15:22:06 -05008087 PolicyControl.dump(prefix, pw);
Jeff Brown600f0032014-05-22 17:06:00 -07008088
Jeff Browna20dda42014-05-27 20:57:24 -07008089 if (mWakeGestureListener != null) {
8090 mWakeGestureListener.dump(pw, prefix);
8091 }
Jeff Brown600f0032014-05-22 17:06:00 -07008092 if (mOrientationListener != null) {
8093 mOrientationListener.dump(pw, prefix);
8094 }
Filip Gruszczynskicfb31852015-02-25 21:47:12 +00008095 if (mBurnInProtectionHelper != null) {
8096 mBurnInProtectionHelper.dump(prefix, pw);
8097 }
Jorim Jaggi84dc08a2015-09-11 17:45:22 -07008098 if (mKeyguardDelegate != null) {
8099 mKeyguardDelegate.dump(prefix, pw);
8100 }
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08008101 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08008102}