blob: 6320413a452a1b054fd1aa18f343ca5122f00ce8 [file] [log] [blame]
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001/*
Jeff Brown37df39a92015-02-25 15:42:31 -08002 * Copyright (C) 2006 The Android Open Source Project
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
Jorim Jaggib10e33f2015-02-04 21:57:40 +010017package com.android.server.policy;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -080018
Wale Ogunwale3797c222015-10-27 14:21:58 -070019import static android.app.ActivityManager.StackId.DOCKED_STACK_ID;
20import static android.app.ActivityManager.StackId.FREEFORM_WORKSPACE_STACK_ID;
Jorim Jaggi86905582016-02-09 21:36:09 -080021import static android.app.ActivityManager.StackId.FULLSCREEN_WORKSPACE_STACK_ID;
22import static android.app.ActivityManager.StackId.HOME_STACK_ID;
Jaewan Kim49117872016-01-19 17:24:08 +090023import static android.content.pm.PackageManager.FEATURE_PICTURE_IN_PICTURE;
24import static android.content.pm.PackageManager.FEATURE_TELEVISION;
25import static android.content.pm.PackageManager.FEATURE_WATCH;
Sriram Viswanathan9ebbe6a2015-11-16 17:59:22 -080026import static android.content.res.Configuration.UI_MODE_TYPE_CAR;
27import static android.content.res.Configuration.UI_MODE_TYPE_MASK;
Jorim Jaggi5060bd82016-02-19 17:12:19 -080028import static android.view.WindowManager.DOCKED_TOP;
29import static android.view.WindowManager.DOCKED_LEFT;
30import static android.view.WindowManager.DOCKED_RIGHT;
Wale Ogunwale6e94a9e2015-10-07 15:35:49 -070031import static android.view.WindowManager.LayoutParams.*;
Jaewan Kim49117872016-01-19 17:24:08 +090032import static android.view.WindowManagerPolicy.WindowManagerFuncs.CAMERA_LENS_COVERED;
Wale Ogunwale6e94a9e2015-10-07 15:35:49 -070033import static android.view.WindowManagerPolicy.WindowManagerFuncs.CAMERA_LENS_COVER_ABSENT;
34import static android.view.WindowManagerPolicy.WindowManagerFuncs.CAMERA_LENS_UNCOVERED;
Jaewan Kim49117872016-01-19 17:24:08 +090035import static android.view.WindowManagerPolicy.WindowManagerFuncs.LID_ABSENT;
36import static android.view.WindowManagerPolicy.WindowManagerFuncs.LID_CLOSED;
37import static android.view.WindowManagerPolicy.WindowManagerFuncs.LID_OPEN;
Wale Ogunwale6e94a9e2015-10-07 15:35:49 -070038
Svet Ganov9cea80cd2016-02-16 11:47:00 -080039import android.Manifest;
Dianne Hackborna4972e92012-03-14 10:38:05 -070040import android.app.ActivityManager;
Jorim Jaggi86905582016-02-09 21:36:09 -080041import android.app.ActivityManager.StackId;
Jeff Brown061ea992015-04-17 19:55:47 -070042import android.app.ActivityManagerInternal;
43import android.app.ActivityManagerInternal.SleepToken;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -080044import android.app.ActivityManagerNative;
Dianne Hackbornc2293022013-02-06 23:14:49 -080045import android.app.AppOpsManager;
Daniel Sandler6396c722013-04-16 20:19:09 -040046import android.app.IUiModeManager;
Dianne Hackborn661cd522011-08-22 00:26:20 -070047import android.app.ProgressDialog;
Jeff Brownde7a8ea2012-06-13 18:28:57 -070048import android.app.SearchManager;
John Spurlock97642182013-07-29 17:58:39 -040049import android.app.StatusBarManager;
Dianne Hackborn78968392010-03-04 20:47:56 -080050import android.app.UiModeManager;
Dianne Hackborn39c2d712009-09-22 11:41:31 -070051import android.content.ActivityNotFoundException;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -080052import android.content.BroadcastReceiver;
Daniel Sandler0601eb72011-04-13 01:01:32 -040053import android.content.ComponentName;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -080054import android.content.ContentResolver;
55import android.content.Context;
56import android.content.Intent;
Mike Lockwood1753f7f2009-08-24 14:49:07 -070057import android.content.IntentFilter;
Winson Chung9112ec32011-06-27 13:15:32 -070058import android.content.ServiceConnection;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -080059import android.content.pm.ActivityInfo;
60import android.content.pm.PackageManager;
Daniel Sandler6396c722013-04-16 20:19:09 -040061import android.content.pm.ResolveInfo;
Dianne Hackborn2f0b1752011-05-31 17:59:49 -070062import android.content.res.CompatibilityInfo;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -080063import android.content.res.Configuration;
64import android.content.res.Resources;
65import android.database.ContentObserver;
Dianne Hackbornc777e072010-02-12 13:07:59 -080066import android.graphics.PixelFormat;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -080067import android.graphics.Rect;
Jinsuk Kime601b712015-07-07 08:01:02 +090068import android.hardware.hdmi.HdmiControlManager;
69import android.hardware.hdmi.HdmiPlaybackClient;
70import android.hardware.hdmi.HdmiPlaybackClient.OneTouchPlayCallback;
John Spurlock7b414672014-07-18 13:02:39 -040071import android.media.AudioAttributes;
Michael Jurka7a348952012-02-27 13:07:58 -080072import android.media.AudioManager;
John Spurlock61560172015-02-06 19:46:04 -050073import android.media.AudioSystem;
Michael Jurka7a348952012-02-27 13:07:58 -080074import android.media.IAudioService;
Svetoslav Ganov7befb7d2012-09-27 16:49:23 -070075import android.media.Ringtone;
76import android.media.RingtoneManager;
RoboErik8a2cfc32014-05-16 11:19:38 -070077import android.media.session.MediaSessionLegacyHelper;
Billy Laucbe540f2015-06-25 01:51:44 +010078import android.os.Binder;
Dianne Hackborn38e29a62011-09-18 14:43:08 -070079import android.os.Bundle;
Craig Mautner276a6eb2014-11-04 15:32:57 -080080import android.os.Debug;
Jeff Brown9a538ee2012-08-20 14:56:57 -070081import android.os.FactoryTest;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -080082import android.os.Handler;
83import android.os.IBinder;
Dianne Hackbornb6683c42015-06-18 17:40:33 -070084import android.os.IDeviceIdleController;
Jeff Brown32cbc38552011-12-01 14:01:49 -080085import android.os.Looper;
Dianne Hackbornfc8fa632011-08-17 16:20:47 -070086import android.os.Message;
87import android.os.Messenger;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -080088import android.os.PowerManager;
Nick Armstrong-Crews56ecfcc2015-09-07 21:46:50 -070089import android.os.PowerManagerInternal;
Billy Laucbe540f2015-06-25 01:51:44 +010090import android.os.Process;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -080091import android.os.RemoteException;
92import android.os.ServiceManager;
93import android.os.SystemClock;
94import android.os.SystemProperties;
Dianne Hackbornad7fa7f2011-01-07 14:06:50 -080095import android.os.UEventObserver;
Dianne Hackbornf02b60a2012-08-16 10:48:27 -070096import android.os.UserHandle;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -080097import android.os.Vibrator;
Michael Wright3818c922014-09-02 13:59:07 -070098import android.provider.MediaStore;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -080099import android.provider.Settings;
Jose Lima9546b202014-07-02 17:21:51 -0700100import android.service.dreams.DreamManagerInternal;
John Spurlockc8b46ca2013-04-08 12:59:26 -0400101import android.service.dreams.DreamService;
102import android.service.dreams.IDreamManager;
Michael Wrightdc63f7b2014-08-21 19:05:21 -0700103import android.speech.RecognizerIntent;
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700104import android.telecom.TelecomManager;
Dianne Hackborn81e56d52011-05-26 00:55:58 -0700105import android.util.DisplayMetrics;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800106import android.util.EventLog;
107import android.util.Log;
Jeff Browna41ca772010-08-11 14:46:32 -0700108import android.util.Slog;
Jeff Brown6651a632011-11-28 12:59:11 -0800109import android.util.SparseArray;
Muyuan Li94ce94e2016-02-24 16:20:54 -0800110import android.util.LongSparseArray;
Dianne Hackbornf87d1962012-04-04 12:48:24 -0700111import android.view.Display;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800112import android.view.Gravity;
113import android.view.HapticFeedbackConstants;
Dianne Hackborne0f085d2011-11-30 18:41:15 -0800114import android.view.IApplicationToken;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800115import android.view.IWindowManager;
Jeff Browna41ca772010-08-11 14:46:32 -0700116import android.view.InputChannel;
Jeff Brown4d396052010-10-29 21:50:21 -0700117import android.view.InputDevice;
Jeff Brown4952dfd2011-11-30 19:23:22 -0800118import android.view.InputEvent;
Jeff Brown32cbc38552011-12-01 14:01:49 -0800119import android.view.InputEventReceiver;
Jeff Brown6b53e8d2010-11-10 16:03:06 -0800120import android.view.KeyCharacterMap;
Craig Mautnerae446592012-12-06 19:05:05 -0800121import android.view.KeyCharacterMap.FallbackAction;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800122import android.view.KeyEvent;
123import android.view.MotionEvent;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800124import android.view.Surface;
125import android.view.View;
126import android.view.ViewConfiguration;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800127import android.view.WindowManager;
Craig Mautnerae446592012-12-06 19:05:05 -0800128import android.view.WindowManagerGlobal;
Craig Mautner8a0da012014-05-31 15:13:37 -0700129import android.view.WindowManagerInternal;
Craig Mautnerae446592012-12-06 19:05:05 -0800130import android.view.WindowManagerPolicy;
Craig Mautnerae446592012-12-06 19:05:05 -0800131import android.view.accessibility.AccessibilityEvent;
Svetoslav8e3feb12014-02-24 13:46:47 -0800132import android.view.accessibility.AccessibilityManager;
Craig Mautnerae446592012-12-06 19:05:05 -0800133import android.view.animation.Animation;
Jorim Jaggi76a16232014-08-08 17:00:47 +0200134import android.view.animation.AnimationSet;
Craig Mautnerae446592012-12-06 19:05:05 -0800135import android.view.animation.AnimationUtils;
Craig Mautnerae446592012-12-06 19:05:05 -0800136import com.android.internal.R;
Jason Monk8f7f3182015-11-18 16:35:14 -0500137import com.android.internal.logging.MetricsLogger;
138import com.android.internal.policy.PhoneWindow;
Muyuan Li94ce94e2016-02-24 16:20:54 -0800139import com.android.internal.policy.IShortcutService;
Craig Mautnerae446592012-12-06 19:05:05 -0800140import com.android.internal.statusbar.IStatusBarService;
Filip Gruszczynski2217f612015-05-26 11:32:08 -0700141import com.android.internal.util.ScreenShapeHelper;
Craig Mautnerae446592012-12-06 19:05:05 -0800142import com.android.internal.widget.PointerLocationView;
Adrian Roos5941c982015-09-03 15:59:49 -0700143import com.android.server.GestureLauncherService;
Craig Mautner8a0da012014-05-31 15:13:37 -0700144import com.android.server.LocalServices;
Jorim Jaggib10e33f2015-02-04 21:57:40 +0100145import com.android.server.policy.keyguard.KeyguardServiceDelegate;
Jorim Jaggi4cfdcf52015-07-09 12:13:59 -0700146import com.android.server.policy.keyguard.KeyguardServiceDelegate.DrawnListener;
Jorim Jaggi86905582016-02-09 21:36:09 -0800147import com.android.server.statusbar.StatusBarManagerInternal;
Craig Mautnerae446592012-12-06 19:05:05 -0800148
149import java.io.File;
150import java.io.FileReader;
151import java.io.IOException;
152import java.io.PrintWriter;
Craig Mautner2bc789b2014-03-19 19:48:38 -0700153import java.util.HashSet;
Craig Mautner276a6eb2014-11-04 15:32:57 -0800154import java.util.List;
Craig Mautnerae446592012-12-06 19:05:05 -0800155
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800156/**
The Android Open Source Project0727d222009-03-11 12:11:58 -0700157 * WindowManagerPolicy implementation for the Android phone UI. This
158 * introduces a new method suffix, Lp, for an internal lock of the
159 * PhoneWindowManager. This is used to protect some internal state, and
John Spurlock04db1762013-05-13 12:46:41 -0400160 * 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 -0700161 * of both of those when held.
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800162 */
163public class PhoneWindowManager implements WindowManagerPolicy {
164 static final String TAG = "WindowManager";
165 static final boolean DEBUG = false;
Joe Onorato43a17652011-04-06 19:22:23 -0700166 static final boolean localLOGV = false;
Jeff Brown40013652012-05-16 21:22:36 -0700167 static final boolean DEBUG_INPUT = false;
Craig Mautnerc0d2d0a2014-10-31 16:25:15 -0700168 static final boolean DEBUG_KEYGUARD = false;
169 static final boolean DEBUG_LAYOUT = false;
Craig Mautner6fbda632012-07-03 09:26:39 -0700170 static final boolean DEBUG_STARTING_WINDOW = false;
Craig Mautner8a0da012014-05-31 15:13:37 -0700171 static final boolean DEBUG_WAKEUP = false;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800172 static final boolean SHOW_STARTING_ANIMATIONS = true;
173 static final boolean SHOW_PROCESSES_ON_ALT_MENU = false;
Joe Onoratod208e702010-10-08 16:22:43 -0400174
Daniel Sandler6396c722013-04-16 20:19:09 -0400175 // Whether to allow dock apps with METADATA_DOCK_HOME to temporarily take over the Home key.
keunyounga7710492015-09-23 11:33:58 -0700176 // No longer recommended for desk docks;
Daniel Sandler6396c722013-04-16 20:19:09 -0400177 static final boolean ENABLE_DESK_DOCK_HOME_CAPTURE = false;
178
Jeff Brown6d8fd272014-05-20 21:24:38 -0700179 static final int SHORT_PRESS_POWER_NOTHING = 0;
180 static final int SHORT_PRESS_POWER_GO_TO_SLEEP = 1;
181 static final int SHORT_PRESS_POWER_REALLY_GO_TO_SLEEP = 2;
182 static final int SHORT_PRESS_POWER_REALLY_GO_TO_SLEEP_AND_GO_HOME = 3;
Bryce Lee01b0c5f2015-02-05 18:24:04 -0800183 static final int SHORT_PRESS_POWER_GO_HOME = 4;
Jeff Brown6d8fd272014-05-20 21:24:38 -0700184
Joe Onoratod208e702010-10-08 16:22:43 -0400185 static final int LONG_PRESS_POWER_NOTHING = 0;
186 static final int LONG_PRESS_POWER_GLOBAL_ACTIONS = 1;
187 static final int LONG_PRESS_POWER_SHUT_OFF = 2;
Jeff Brown9a538ee2012-08-20 14:56:57 -0700188 static final int LONG_PRESS_POWER_SHUT_OFF_NO_CONFIRM = 3;
Michael Jurka3b1fc472011-06-13 10:54:40 -0700189
Jeff Brown13f00f02014-10-31 14:45:50 -0700190 static final int MULTI_PRESS_POWER_NOTHING = 0;
191 static final int MULTI_PRESS_POWER_THEATER_MODE = 1;
192 static final int MULTI_PRESS_POWER_BRIGHTNESS_BOOST = 2;
193
Michael Jurka3b1fc472011-06-13 10:54:40 -0700194 // These need to match the documentation/constant in
195 // core/res/res/values/config.xml
Joe Onorato46b0d682010-11-22 17:37:27 -0800196 static final int LONG_PRESS_HOME_NOTHING = 0;
Michael Wrightc9ebea72013-01-16 19:25:02 -0800197 static final int LONG_PRESS_HOME_RECENT_SYSTEM_UI = 1;
Jeff Browncaca8812013-05-09 13:34:33 -0700198 static final int LONG_PRESS_HOME_ASSIST = 2;
Jaewan Kim76b7d0d2016-02-12 19:01:02 +0900199 static final int LAST_LONG_PRESS_HOME_BEHAVIOR = LONG_PRESS_HOME_ASSIST;
Jeff Browncaca8812013-05-09 13:34:33 -0700200
201 static final int DOUBLE_TAP_HOME_NOTHING = 0;
202 static final int DOUBLE_TAP_HOME_RECENT_SYSTEM_UI = 1;
Joe Onorato46b0d682010-11-22 17:37:27 -0800203
Jaewan Kim49117872016-01-19 17:24:08 +0900204 static final int SHORT_PRESS_WINDOW_NOTHING = 0;
205 static final int SHORT_PRESS_WINDOW_PICTURE_IN_PICTURE = 1;
206
Filip Gruszczynskia483a1d2015-03-17 19:06:58 +0000207 static final int SHORT_PRESS_SLEEP_GO_TO_SLEEP = 0;
208 static final int SHORT_PRESS_SLEEP_GO_TO_SLEEP_AND_GO_HOME = 1;
209
Dianne Hackborn5cb8d792009-05-21 17:34:15 -0700210 static final int APPLICATION_MEDIA_SUBLAYER = -2;
211 static final int APPLICATION_MEDIA_OVERLAY_SUBLAYER = -1;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800212 static final int APPLICATION_PANEL_SUBLAYER = 1;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800213 static final int APPLICATION_SUB_PANEL_SUBLAYER = 2;
Wale Ogunwale0a4dc222015-04-14 12:58:42 -0700214 static final int APPLICATION_ABOVE_SUB_PANEL_SUBLAYER = 3;
Craig Mautner88400d32012-09-30 12:35:45 -0700215
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800216 static public final String SYSTEM_DIALOG_REASON_KEY = "reason";
217 static public final String SYSTEM_DIALOG_REASON_GLOBAL_ACTIONS = "globalactions";
218 static public final String SYSTEM_DIALOG_REASON_RECENT_APPS = "recentapps";
Joe Onoratof275f0c2009-11-24 16:11:13 -0500219 static public final String SYSTEM_DIALOG_REASON_HOME_KEY = "homekey";
Jeff Brownde7a8ea2012-06-13 18:28:57 -0700220 static public final String SYSTEM_DIALOG_REASON_ASSIST = "assist";
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800221
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -0700222 /**
223 * These are the system UI flags that, when changing, can cause the layout
224 * of the screen to change.
225 */
226 static final int SYSTEM_UI_CHANGING_LAYOUT =
John Spurlocke1f366f2013-08-05 12:22:40 -0400227 View.SYSTEM_UI_FLAG_HIDE_NAVIGATION
John Spurlock7f4820a2013-10-08 12:54:35 -0400228 | View.SYSTEM_UI_FLAG_FULLSCREEN
229 | View.STATUS_BAR_TRANSLUCENT
Adrian Roosea562512014-05-05 13:33:03 +0200230 | View.NAVIGATION_BAR_TRANSLUCENT
Jorim Jaggi4fa78922015-11-30 17:13:56 -0800231 | View.STATUS_BAR_TRANSPARENT
232 | View.NAVIGATION_BAR_TRANSPARENT;
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -0700233
John Spurlock7b414672014-07-18 13:02:39 -0400234 private static final AudioAttributes VIBRATION_ATTRIBUTES = new AudioAttributes.Builder()
235 .setContentType(AudioAttributes.CONTENT_TYPE_SONIFICATION)
236 .setUsage(AudioAttributes.USAGE_ASSISTANCE_SONIFICATION)
237 .build();
238
Adrian Roosddc8b272015-05-21 16:28:27 -0700239 // The panic gesture may become active only after the keyguard is dismissed and the immersive
240 // app shows again. If that doesn't happen for 30s we drop the gesture.
241 private static final long PANIC_GESTURE_EXPIRATION = 30000;
242
Jim Miller5ecd8112013-01-09 18:50:26 -0800243 /**
244 * Keyguard stuff
245 */
246 private WindowState mKeyguardScrim;
Jorim Jaggi380ecb82014-03-14 17:25:20 +0100247 private boolean mKeyguardHidden;
Jeff Brown3ee549c2014-09-22 20:14:39 -0700248 private boolean mKeyguardDrawnOnce;
Jim Miller5ecd8112013-01-09 18:50:26 -0800249
Jeff Brown6651a632011-11-28 12:59:11 -0800250 /* Table of Application Launch keys. Maps from key codes to intent categories.
251 *
252 * These are special keys that are used to launch particular kinds of applications,
253 * such as a web browser. HID defines nearly a hundred of them in the Consumer (0x0C)
254 * usage page. We don't support quite that many yet...
255 */
256 static SparseArray<String> sApplicationLaunchKeyCategories;
257 static {
258 sApplicationLaunchKeyCategories = new SparseArray<String>();
259 sApplicationLaunchKeyCategories.append(
260 KeyEvent.KEYCODE_EXPLORER, Intent.CATEGORY_APP_BROWSER);
261 sApplicationLaunchKeyCategories.append(
262 KeyEvent.KEYCODE_ENVELOPE, Intent.CATEGORY_APP_EMAIL);
263 sApplicationLaunchKeyCategories.append(
264 KeyEvent.KEYCODE_CONTACTS, Intent.CATEGORY_APP_CONTACTS);
265 sApplicationLaunchKeyCategories.append(
266 KeyEvent.KEYCODE_CALENDAR, Intent.CATEGORY_APP_CALENDAR);
267 sApplicationLaunchKeyCategories.append(
268 KeyEvent.KEYCODE_MUSIC, Intent.CATEGORY_APP_MUSIC);
269 sApplicationLaunchKeyCategories.append(
270 KeyEvent.KEYCODE_CALCULATOR, Intent.CATEGORY_APP_CALCULATOR);
271 }
272
Craig Mautnerc3daedd2014-09-13 11:17:23 -0700273 /** Amount of time (in milliseconds) to wait for windows drawn before powering on. */
Jorim Jaggi0d210f62015-07-10 14:24:44 -0700274 static final int WAITING_FOR_DRAWN_TIMEOUT = 1000;
Craig Mautnerc3daedd2014-09-13 11:17:23 -0700275
Dianne Hackborndf89e652011-10-06 22:35:11 -0700276 /**
277 * Lock protecting internal state. Must not call out into window
278 * manager with lock held. (This lock will be acquired in places
279 * where the window manager is calling in with its own lock held.)
280 */
Craig Mautner0bf6ec92012-12-18 08:33:27 -0800281 private final Object mLock = new Object();
Dianne Hackborndf89e652011-10-06 22:35:11 -0700282
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800283 Context mContext;
284 IWindowManager mWindowManager;
Dianne Hackborndf89e652011-10-06 22:35:11 -0700285 WindowManagerFuncs mWindowManagerFuncs;
Craig Mautner8a0da012014-05-31 15:13:37 -0700286 WindowManagerInternal mWindowManagerInternal;
Jeff Brown96307042012-07-27 15:51:34 -0700287 PowerManager mPowerManager;
Jeff Brown061ea992015-04-17 19:55:47 -0700288 ActivityManagerInternal mActivityManagerInternal;
Jose Lima9546b202014-07-02 17:21:51 -0700289 DreamManagerInternal mDreamManagerInternal;
Michael Wrighta4d22d72015-09-16 23:19:26 +0100290 PowerManagerInternal mPowerManagerInternal;
Joe Onorato93056472010-09-10 10:30:46 -0400291 IStatusBarService mStatusBarService;
Jorim Jaggi86905582016-02-09 21:36:09 -0800292 StatusBarManagerInternal mStatusBarManagerInternal;
Jeff Browncaca8812013-05-09 13:34:33 -0700293 boolean mPreloadedRecentApps;
Dianne Hackborn42e620c2012-06-24 13:20:51 -0700294 final Object mServiceAquireLock = new Object();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800295 Vibrator mVibrator; // Vibrator for giving feedback of orientation changes
Jeff Brownde7a8ea2012-06-13 18:28:57 -0700296 SearchManager mSearchManager;
Svetoslav8e3feb12014-02-24 13:46:47 -0800297 AccessibilityManager mAccessibilityManager;
Filip Gruszczynskicfb31852015-02-25 21:47:12 +0000298 BurnInProtectionHelper mBurnInProtectionHelper;
Billy Laucbe540f2015-06-25 01:51:44 +0100299 AppOpsManager mAppOpsManager;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800300
Dianne Hackborn181ceb52009-08-27 22:16:40 -0700301 // Vibrator pattern for haptic feedback of a long press.
302 long[] mLongPressVibePattern;
Craig Mautner88400d32012-09-30 12:35:45 -0700303
Dianne Hackborn181ceb52009-08-27 22:16:40 -0700304 // Vibrator pattern for haptic feedback of virtual key press.
305 long[] mVirtualKeyVibePattern;
Craig Mautner967212c2013-04-13 21:10:58 -0700306
Amith Yamasanic33cb712010-02-10 15:21:49 -0800307 // Vibrator pattern for a short vibration.
308 long[] mKeyboardTapVibePattern;
309
Fabrice Di Meglioeeff63a2013-08-05 12:07:24 -0700310 // Vibrator pattern for a short vibration when tapping on an hour/minute tick of a Clock.
311 long[] mClockTickVibePattern;
312
Fabrice Di Megliobd9152f2013-10-01 11:21:31 -0700313 // Vibrator pattern for a short vibration when tapping on a day/month/year date of a Calendar.
314 long[] mCalendarDateVibePattern;
315
Dianne Hackbornb1a79802009-09-29 15:18:31 -0700316 // Vibrator pattern for haptic feedback during boot when safe mode is disabled.
317 long[] mSafeModeDisabledVibePattern;
Craig Mautner967212c2013-04-13 21:10:58 -0700318
Dianne Hackbornb1a79802009-09-29 15:18:31 -0700319 // Vibrator pattern for haptic feedback during boot when safe mode is enabled.
320 long[] mSafeModeEnabledVibePattern;
Romain Guy8154cd32010-03-29 14:41:15 -0700321
Mady Mellore8608912015-06-05 09:02:55 -0700322 // Vibrator pattern for haptic feedback of a context click.
323 long[] mContextClickVibePattern;
Mady Mellore82067b2015-04-30 09:58:35 -0700324
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800325 /** If true, hitting shift & menu will broadcast Intent.ACTION_BUG_REPORT */
326 boolean mEnableShiftMenuBugReports = false;
Mike Lockwoodd747dc82011-09-13 16:28:22 -0400327
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800328 boolean mSafeMode;
329 WindowState mStatusBar = null;
Dianne Hackborn69cb8752011-05-19 18:13:32 -0700330 int mStatusBarHeight;
Daniel Sandler8956dbb2011-04-22 07:55:02 -0400331 WindowState mNavigationBar = null;
Daniel Sandler36412a72011-08-04 09:35:13 -0400332 boolean mHasNavigationBar = false;
Dianne Hackbornf87d1962012-04-04 12:48:24 -0700333 boolean mCanHideNavigationBar = false;
Daniel Sandler4a066c52012-04-20 14:49:13 -0400334 boolean mNavigationBarCanMove = false; // can the navigation bar ever move to the side?
335 boolean mNavigationBarOnBottom = true; // is the navigation bar on the bottom *right now*?
Sriram Viswanathan9ebbe6a2015-11-16 17:59:22 -0800336 int[] mNavigationBarHeightForRotationDefault = new int[4];
337 int[] mNavigationBarWidthForRotationDefault = new int[4];
338 int[] mNavigationBarHeightForRotationInCarMode = new int[4];
339 int[] mNavigationBarWidthForRotationInCarMode = new int[4];
Daniel Sandler8956dbb2011-04-22 07:55:02 -0400340
Muyuan Li94ce94e2016-02-24 16:20:54 -0800341 private LongSparseArray<IShortcutService> mShortcutKeyServices = new LongSparseArray<>();
342
keunyounga7710492015-09-23 11:33:58 -0700343 // Whether to allow dock apps with METADATA_DOCK_HOME to temporarily take over the Home key.
344 // This is for car dock and this is updated from resource.
345 private boolean mEnableCarDockHomeCapture = true;
346
Craig Mautnera631d492014-08-05 15:16:01 -0700347 boolean mBootMessageNeedsHiding;
Jim Miller5ecd8112013-01-09 18:50:26 -0800348 KeyguardServiceDelegate mKeyguardDelegate;
Craig Mautner13f6ea72014-06-23 14:57:02 -0700349 final Runnable mWindowManagerDrawCallback = new Runnable() {
Craig Mautner8a0da012014-05-31 15:13:37 -0700350 @Override
Craig Mautner13f6ea72014-06-23 14:57:02 -0700351 public void run() {
Craig Mautner8a0da012014-05-31 15:13:37 -0700352 if (DEBUG_WAKEUP) Slog.i(TAG, "All windows ready for display!");
353 mHandler.sendEmptyMessage(MSG_WINDOW_MANAGER_DRAWN_COMPLETE);
354 }
355 };
Jorim Jaggi4cfdcf52015-07-09 12:13:59 -0700356 final DrawnListener mKeyguardDrawnCallback = new DrawnListener() {
Craig Mautner8a0da012014-05-31 15:13:37 -0700357 @Override
Jorim Jaggi4cfdcf52015-07-09 12:13:59 -0700358 public void onDrawn() {
359 if (DEBUG_WAKEUP) Slog.d(TAG, "mKeyguardDelegate.ShowListener.onDrawn.");
Craig Mautner8a0da012014-05-31 15:13:37 -0700360 mHandler.sendEmptyMessage(MSG_KEYGUARD_DRAWN_COMPLETE);
361 }
362 };
363
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800364 GlobalActions mGlobalActions;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800365 Handler mHandler;
satok1bc0a492012-04-25 22:47:12 +0900366 WindowState mLastInputMethodWindow = null;
367 WindowState mLastInputMethodTargetWindow = null;
Jeff Brown4aed78b2011-01-14 17:36:55 -0800368
Jeff Brown13f00f02014-10-31 14:45:50 -0700369 // FIXME This state is shared between the input reader and handler thread.
370 // Technically it's broken and buggy but it has been like this for many years
371 // and we have not yet seen any problems. Someday we'll rewrite this logic
372 // so that only one thread is involved in handling input policy. Unfortunately
373 // it's on a critical path for power management so we can't just post the work to the
374 // handler thread. We'll need to resolve this someday by teaching the input dispatcher
375 // to hold wakelocks during dispatch and eliminating the critical path.
376 volatile boolean mPowerKeyHandled;
Bryce Leed9268e32014-11-17 17:40:59 -0800377 volatile boolean mBeganFromNonInteractive;
Jeff Brown13f00f02014-10-31 14:45:50 -0700378 volatile int mPowerKeyPressCounter;
379 volatile boolean mEndCallKeyHandled;
380
Winson Chungd42a6cf2014-06-03 16:24:04 -0700381 boolean mRecentsVisible;
Winson Chung1e8d71b2014-05-16 17:05:22 -0700382 int mRecentAppsHeldModifiers;
Jeff Browncf39bdf2012-05-18 14:41:19 -0700383 boolean mLanguageSwitchKeyPressed;
Jeff Brown68b909d2011-12-07 16:36:01 -0800384
Jeff Brown2e7760e2012-04-11 15:14:55 -0700385 int mLidState = LID_ABSENT;
Michael Wright3818c922014-09-02 13:59:07 -0700386 int mCameraLensCoverState = CAMERA_LENS_COVER_ABSENT;
Jeff Browndaa37532012-05-01 15:54:03 -0700387 boolean mHaveBuiltInKeyboard;
Jeff Brown4aed78b2011-01-14 17:36:55 -0800388
Dianne Hackbornc777e072010-02-12 13:07:59 -0800389 boolean mSystemReady;
Dianne Hackbornba24e4d2011-09-01 11:17:06 -0700390 boolean mSystemBooted;
Adrian Roos3542f7d2015-07-13 15:57:53 -0700391 private boolean mDeferBindKeyguard;
Dianne Hackbornad7fa7f2011-01-07 14:06:50 -0800392 boolean mHdmiPlugged;
Jinsuk Kime601b712015-07-07 08:01:02 +0900393 HdmiControl mHdmiControl;
Jeff Brown4f5fa282014-06-12 19:19:15 -0700394 IUiModeManager mUiModeManager;
Daniel Sandler6396c722013-04-16 20:19:09 -0400395 int mUiMode;
Dianne Hackborn867ab6472010-04-29 13:28:56 -0700396 int mDockMode = Intent.EXTRA_DOCK_STATE_UNDOCKED;
Mike Lockwood1753f7f2009-08-24 14:49:07 -0700397 int mLidOpenRotation;
Mike Lockwood2d1efbd2009-09-16 12:15:53 -0400398 int mCarDockRotation;
399 int mDeskDockRotation;
Jeff Brownc82c89ed2013-04-17 17:18:15 -0700400 int mUndockedHdmiRotation;
401 int mDemoHdmiRotation;
402 boolean mDemoHdmiRotationLock;
Chong Zhangae6119ff2014-11-11 18:54:39 -0800403 int mDemoRotation;
404 boolean mDemoRotationLock;
Daniel Sandlerb73617d2010-08-17 00:41:00 -0400405
Jeff Browna20dda42014-05-27 20:57:24 -0700406 boolean mWakeGestureEnabledSetting;
407 MyWakeGestureListener mWakeGestureListener;
408
Craig Mautner46ac6fa2013-08-01 10:06:34 -0700409 // Default display does not rotate, apps that require non-default orientation will have to
410 // have the orientation emulated.
411 private boolean mForceDefaultOrientation = false;
412
Daniel Sandlerb73617d2010-08-17 00:41:00 -0400413 int mUserRotationMode = WindowManagerPolicy.USER_ROTATION_FREE;
414 int mUserRotation = Surface.ROTATION_0;
Jeff Brown207673cd2012-06-05 17:47:11 -0700415 boolean mAccelerometerDefault;
Daniel Sandlerb73617d2010-08-17 00:41:00 -0400416
Jeff Brownbcdfc622014-03-06 19:13:04 -0800417 boolean mSupportAutoRotation;
Jeff Brownd3187e32011-09-21 19:26:44 -0700418 int mAllowAllRotations = -1;
Mike Lockwoode9867d22009-09-20 01:59:02 -0400419 boolean mCarDockEnablesAccelerometer;
420 boolean mDeskDockEnablesAccelerometer;
Dianne Hackborn2862fff2009-09-15 22:56:29 -0700421 int mLidKeyboardAccessibility;
422 int mLidNavigationAccessibility;
Edward Savage-Jones7def60d2015-11-13 13:27:03 +0100423 boolean mLidControlsScreenLock;
Jeff Brownc458ce92012-04-30 14:58:40 -0700424 boolean mLidControlsSleep;
Jeff Brown13f00f02014-10-31 14:45:50 -0700425 int mShortPressOnPowerBehavior;
426 int mLongPressOnPowerBehavior;
427 int mDoublePressOnPowerBehavior;
428 int mTriplePressOnPowerBehavior;
Filip Gruszczynskia483a1d2015-03-17 19:06:58 +0000429 int mShortPressOnSleepBehavior;
Jaewan Kim49117872016-01-19 17:24:08 +0900430 int mShortPressWindowBehavior;
Jeff Brown3ee549c2014-09-22 20:14:39 -0700431 boolean mAwake;
432 boolean mScreenOnEarly;
433 boolean mScreenOnFully;
434 ScreenOnListener mScreenOnListener;
435 boolean mKeyguardDrawComplete;
436 boolean mWindowManagerDrawComplete;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800437 boolean mOrientationSensorEnabled = false;
438 int mCurrentAppOrientation = ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800439 boolean mHasSoftInput = false;
Daniel Sandlerdd73ee42013-10-11 22:19:59 -0400440 boolean mTranslucentDecorEnabled = true;
RoboErik001c59c2015-01-26 15:53:51 -0800441 boolean mUseTvRouting;
Craig Mautner967212c2013-04-13 21:10:58 -0700442
Jeff Brown70825162012-03-28 17:27:48 -0700443 int mPointerLocationMode = 0; // guarded by mLock
Joe Onorato664644d2011-01-23 17:53:23 -0800444
445 // The last window we were told about in focusChanged.
446 WindowState mFocusedWindow;
Dianne Hackborne0f085d2011-11-30 18:41:15 -0800447 IApplicationToken mFocusedApp;
Joe Onorato664644d2011-01-23 17:53:23 -0800448
Jeff Brown70825162012-03-28 17:27:48 -0700449 PointerLocationView mPointerLocationView;
Jeff Brown32cbc38552011-12-01 14:01:49 -0800450
Dianne Hackbornc652de82013-02-15 16:32:56 -0800451 // The current size of the screen; really; extends into the overscan area of
452 // the screen and doesn't account for any system elements like the status bar.
453 int mOverscanScreenLeft, mOverscanScreenTop;
454 int mOverscanScreenWidth, mOverscanScreenHeight;
455 // The current visible size of the screen; really; (ir)regardless of whether the status
456 // bar can be hidden but not extending into the overscan area.
Joe Onorato29fc2c92010-11-24 10:26:50 -0800457 int mUnrestrictedScreenLeft, mUnrestrictedScreenTop;
458 int mUnrestrictedScreenWidth, mUnrestrictedScreenHeight;
Dianne Hackborn313440842013-02-19 19:22:59 -0800459 // Like mOverscanScreen*, but allowed to move into the overscan region where appropriate.
460 int mRestrictedOverscanScreenLeft, mRestrictedOverscanScreenTop;
461 int mRestrictedOverscanScreenWidth, mRestrictedOverscanScreenHeight;
Dianne Hackborn82de1ae2010-10-28 11:28:39 -0700462 // The current size of the screen; these may be different than (0,0)-(dw,dh)
463 // if the status bar can't be hidden; in that case it effectively carves out
464 // that area of the display from all other windows.
Joe Onorato29fc2c92010-11-24 10:26:50 -0800465 int mRestrictedScreenLeft, mRestrictedScreenTop;
466 int mRestrictedScreenWidth, mRestrictedScreenHeight;
Dianne Hackborn5c58de32012-04-28 19:52:37 -0700467 // During layout, the current screen borders accounting for any currently
468 // visible system UI elements.
469 int mSystemLeft, mSystemTop, mSystemRight, mSystemBottom;
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -0700470 // For applications requesting stable content insets, these are them.
471 int mStableLeft, mStableTop, mStableRight, mStableBottom;
Dianne Hackborn5b5cc4d2012-05-16 13:15:00 -0700472 // For applications requesting stable content insets but have also set the
473 // fullscreen window flag, these are the stable dimensions without the status bar.
474 int mStableFullscreenLeft, mStableFullscreenTop;
475 int mStableFullscreenRight, mStableFullscreenBottom;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800476 // During layout, the current screen borders with all outer decoration
477 // (status bar, input method dock) accounted for.
478 int mCurLeft, mCurTop, mCurRight, mCurBottom;
479 // During layout, the frame in which content should be displayed
480 // to the user, accounting for all screen decoration except for any
481 // space they deem as available for other content. This is usually
482 // the same as mCur*, but may be larger if the screen decor has supplied
483 // content insets.
484 int mContentLeft, mContentTop, mContentRight, mContentBottom;
Dianne Hackborne30e02f2014-05-27 18:24:45 -0700485 // During layout, the frame in which voice content should be displayed
486 // to the user, accounting for all screen decoration except for any
487 // space they deem as available for other content.
488 int mVoiceContentLeft, mVoiceContentTop, mVoiceContentRight, mVoiceContentBottom;
Dianne Hackborn8e11ef02010-11-18 19:47:42 -0800489 // During layout, the current screen borders along which input method
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800490 // windows are placed.
491 int mDockLeft, mDockTop, mDockRight, mDockBottom;
492 // During layout, the layer at which the doc window is placed.
493 int mDockLayer;
Dianne Hackborn5c58de32012-04-28 19:52:37 -0700494 // During layout, this is the layer of the status bar.
495 int mStatusBarLayer;
Dianne Hackborne26ab702011-10-16 13:21:33 -0700496 int mLastSystemUiFlags;
497 // Bits that we are in the process of clearing, so we want to prevent
498 // them from being set by applications until everything has been updated
499 // to have them clear.
500 int mResettingSystemUiFlags = 0;
501 // Bits that we are currently always keeping cleared.
502 int mForceClearedSystemUiFlags = 0;
Jorim Jaggi86905582016-02-09 21:36:09 -0800503 int mLastFullscreenStackSysUiFlags;
504 int mLastDockedStackSysUiFlags;
505 final Rect mNonDockedStackBounds = new Rect();
506 final Rect mDockedStackBounds = new Rect();
507 final Rect mLastNonDockedStackBounds = new Rect();
508 final Rect mLastDockedStackBounds = new Rect();
509
Dianne Hackborn4eff8d32011-11-10 19:38:40 -0800510 // What we last reported to system UI about whether the compatibility
511 // menu needs to be displayed.
512 boolean mLastFocusNeedsMenu = false;
Adrian Roosddc8b272015-05-21 16:28:27 -0700513 // If nonzero, a panic gesture was performed at that time in uptime millis and is still pending.
514 private long mPendingPanicGestureUptime;
Dianne Hackborndf89e652011-10-06 22:35:11 -0700515
Selim Cinekf83e8242015-05-19 18:08:14 -0700516 InputConsumer mInputConsumer = null;
Dianne Hackborndf89e652011-10-06 22:35:11 -0700517
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800518 static final Rect mTmpParentFrame = new Rect();
519 static final Rect mTmpDisplayFrame = new Rect();
Dianne Hackbornc4aad012013-02-22 15:05:25 -0800520 static final Rect mTmpOverscanFrame = new Rect();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800521 static final Rect mTmpContentFrame = new Rect();
522 static final Rect mTmpVisibleFrame = new Rect();
John Spurlock46646232013-09-30 22:32:42 -0400523 static final Rect mTmpDecorFrame = new Rect();
Adrian Roosfa104232014-06-20 16:10:14 -0700524 static final Rect mTmpStableFrame = new Rect();
Dianne Hackborn1f903c32011-09-13 19:18:06 -0700525 static final Rect mTmpNavigationFrame = new Rect();
Filip Gruszczynski2217f612015-05-26 11:32:08 -0700526 static final Rect mTmpOutsetFrame = new Rect();
Craig Mautner967212c2013-04-13 21:10:58 -0700527
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800528 WindowState mTopFullscreenOpaqueWindowState;
Adrian Rooscd3884d2015-02-18 17:25:23 +0100529 WindowState mTopFullscreenOpaqueOrDimmingWindowState;
Jorim Jaggi86905582016-02-09 21:36:09 -0800530 WindowState mTopDockedOpaqueWindowState;
531 WindowState mTopDockedOpaqueOrDimmingWindowState;
Craig Mautner2bc789b2014-03-19 19:48:38 -0700532 HashSet<IApplicationToken> mAppsToBeHidden = new HashSet<IApplicationToken>();
Jorim Jaggic13fcac2014-09-11 17:36:57 +0200533 HashSet<IApplicationToken> mAppsThatDismissKeyguard = new HashSet<IApplicationToken>();
Joe Onorato93056472010-09-10 10:30:46 -0400534 boolean mTopIsFullscreen;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800535 boolean mForceStatusBar;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -0700536 boolean mForceStatusBarFromKeyguard;
Selim Cinek4a4a2bddc2015-05-07 12:50:19 -0700537 private boolean mForceStatusBarTransparent;
Dianne Hackborn39c2d712009-09-22 11:41:31 -0700538 boolean mHideLockScreen;
Dianne Hackborn891d3fb2013-01-09 18:31:37 -0800539 boolean mForcingShowNavBar;
540 int mForcingShowNavBarLayer;
Craig Mautnerad09bcc2012-10-08 13:33:11 -0700541
542 // States of keyguard dismiss.
543 private static final int DISMISS_KEYGUARD_NONE = 0; // Keyguard not being dismissed.
544 private static final int DISMISS_KEYGUARD_START = 1; // Keyguard needs to be dismissed.
545 private static final int DISMISS_KEYGUARD_CONTINUE = 2; // Keyguard has been dismissed.
546 int mDismissKeyguard = DISMISS_KEYGUARD_NONE;
547
548 /** The window that is currently dismissing the keyguard. Dismissing the keyguard must only
549 * be done once per window. */
550 private WindowState mWinDismissingKeyguard;
551
tingna_sunge785ffa2015-05-12 13:23:15 +0800552 /** When window is currently dismissing the keyguard, dismissing the keyguard must handle
553 * the keygaurd secure state change instantly case, e.g. the use case of inserting a PIN
554 * lock SIM card. This variable is used to record the previous keyguard secure state for
555 * monitoring secure state change on window dismissing keyguard. */
556 private boolean mSecureDismissingKeyguard;
557
Craig Mautnerc9457fa2014-06-06 14:27:48 -0700558 /** The window that is currently showing "over" the keyguard. If there is an app window
559 * belonging to another app on top of this the keyguard shows. If there is a fullscreen
560 * app window under this, still dismiss the keyguard but don't show the app underneath. Show
561 * the wallpaper. */
562 private WindowState mWinShowWhenLocked;
563
Dianne Hackborn7ad44382012-10-18 17:46:00 -0700564 boolean mShowingLockscreen;
565 boolean mShowingDream;
566 boolean mDreamingLockscreen;
Jeff Brown061ea992015-04-17 19:55:47 -0700567 boolean mDreamingSleepTokenNeeded;
568 SleepToken mDreamingSleepToken;
Jeff Brown48d1b142015-06-10 16:36:03 -0700569 SleepToken mScreenOffSleepToken;
Jim Millerab954542014-10-10 18:21:49 -0700570 boolean mKeyguardSecure;
571 boolean mKeyguardSecureIncludingHidden;
572 volatile boolean mKeyguardOccluded;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800573 boolean mHomePressed;
Jeff Browncaca8812013-05-09 13:34:33 -0700574 boolean mHomeConsumed;
575 boolean mHomeDoubleTapPending;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800576 Intent mHomeIntent;
Dianne Hackborn39c2d712009-09-22 11:41:31 -0700577 Intent mCarDockIntent;
578 Intent mDeskDockIntent;
Jeff Brownfd23e3e2012-05-09 13:34:28 -0700579 boolean mSearchKeyShortcutPending;
580 boolean mConsumeSearchKeyUp;
Jeff Brownde7a8ea2012-06-13 18:28:57 -0700581 boolean mAssistKeyLongPressed;
Michael Wright6a62e552014-06-03 19:19:48 -0700582 boolean mPendingMetaAction;
Jorim Jaggi0ffd49c2016-02-12 15:04:21 -0800583 boolean mForceShowSystemBars;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800584
Mike Lockwood28569302010-01-28 11:54:40 -0500585 // support for activating the lock screen while the screen is on
586 boolean mAllowLockscreenWhenOn;
587 int mLockScreenTimeout;
588 boolean mLockScreenTimerActive;
589
David Brownbaf8d092010-03-08 21:52:59 -0800590 // Behavior of ENDCALL Button. (See Settings.System.END_BUTTON_BEHAVIOR.)
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800591 int mEndcallBehavior;
David Brownbaf8d092010-03-08 21:52:59 -0800592
593 // Behavior of POWER button while in-call and screen on.
594 // (See Settings.Secure.INCALL_POWER_BUTTON_BEHAVIOR.)
595 int mIncallPowerBehavior;
596
Dianne Hackbornf87d1962012-04-04 12:48:24 -0700597 Display mDisplay;
598
Filip Gruszczynski2987f612015-06-30 15:03:30 -0700599 private int mDisplayRotation;
600
Dianne Hackborn9d132642011-04-21 17:26:39 -0700601 int mLandscapeRotation = 0; // default landscape rotation
602 int mSeascapeRotation = 0; // "other" landscape rotation, 180 degrees from mLandscapeRotation
603 int mPortraitRotation = 0; // default portrait rotation
604 int mUpsideDownRotation = 0; // "other" portrait rotation
Mitsuru Oshima831d0d92009-06-16 18:27:18 -0700605
Dianne Hackbornc652de82013-02-15 16:32:56 -0800606 int mOverscanLeft = 0;
607 int mOverscanTop = 0;
608 int mOverscanRight = 0;
609 int mOverscanBottom = 0;
610
Joe Onorato46b0d682010-11-22 17:37:27 -0800611 // What we do when the user long presses on home
Jeff Browncaca8812013-05-09 13:34:33 -0700612 private int mLongPressOnHomeBehavior;
613
614 // What we do when the user double-taps on home
615 private int mDoubleTapOnHomeBehavior;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800616
Bryce Lee584a4452014-10-21 15:55:55 -0700617 // Allowed theater mode wake actions
618 private boolean mAllowTheaterModeWakeFromKey;
619 private boolean mAllowTheaterModeWakeFromPowerKey;
620 private boolean mAllowTheaterModeWakeFromMotion;
Bryce Lee812d7022014-11-10 13:33:28 -0800621 private boolean mAllowTheaterModeWakeFromMotionWhenNotDreaming;
Bryce Lee584a4452014-10-21 15:55:55 -0700622 private boolean mAllowTheaterModeWakeFromCameraLens;
623 private boolean mAllowTheaterModeWakeFromLidSwitch;
624 private boolean mAllowTheaterModeWakeFromWakeGesture;
625
Bryce Leed3b28402015-03-09 15:49:13 +0000626 // Whether to support long press from power button in non-interactive mode
627 private boolean mSupportLongPressPowerWhenNonInteractive;
628
Bryce Lee55e846d2014-11-04 12:43:44 -0800629 // Whether to go to sleep entering theater mode from power button
630 private boolean mGoToSleepOnButtonPressTheaterMode;
631
Winson Chung9112ec32011-06-27 13:15:32 -0700632 // Screenshot trigger states
Jeff Brownd5bb82d2011-10-12 13:57:59 -0700633 // Time to volume and power must be pressed within this interval of each other.
634 private static final long SCREENSHOT_CHORD_DEBOUNCE_DELAY_MILLIS = 150;
Winson Chung1cea2f32012-10-08 20:42:01 -0700635 // Increase the chord delay when taking a screenshot from the keyguard
636 private static final float KEYGUARD_SCREENSHOT_CHORD_DELAY_MULTIPLIER = 2.5f;
Christopher Tatee90585f2012-03-05 18:56:25 -0800637 private boolean mScreenshotChordEnabled;
Jeff Brown13f00f02014-10-31 14:45:50 -0700638 private boolean mScreenshotChordVolumeDownKeyTriggered;
639 private long mScreenshotChordVolumeDownKeyTime;
640 private boolean mScreenshotChordVolumeDownKeyConsumed;
641 private boolean mScreenshotChordVolumeUpKeyTriggered;
642 private boolean mScreenshotChordPowerKeyTriggered;
643 private long mScreenshotChordPowerKeyTime;
Winson Chung9112ec32011-06-27 13:15:32 -0700644
Michael Wrightb854e242013-02-05 17:54:02 -0800645 /* The number of steps between min and max brightness */
646 private static final int BRIGHTNESS_STEPS = 10;
647
Christopher Tate5e08af02012-09-21 17:17:22 -0700648 SettingsObserver mSettingsObserver;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800649 ShortcutManager mShortcutManager;
650 PowerManager.WakeLock mBroadcastWakeLock;
Jeff Brown13f00f02014-10-31 14:45:50 -0700651 PowerManager.WakeLock mPowerKeyWakeLock;
Jeff Brown40013652012-05-16 21:22:36 -0700652 boolean mHavePendingMediaKeyRepeatWithWakeLock;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800653
Craig Mautnerd625ab22013-09-06 13:40:31 -0700654 private int mCurrentUserId;
655
Justin Kohd378ad72013-04-01 12:18:26 -0700656 // Maps global key codes to the components that will handle them.
657 private GlobalKeyManager mGlobalKeyManager;
658
Jeff Brownfd23e3e2012-05-09 13:34:28 -0700659 // Fallback actions by key code.
660 private final SparseArray<KeyCharacterMap.FallbackAction> mFallbackActions =
661 new SparseArray<KeyCharacterMap.FallbackAction>();
Jeff Brown49ed71d2010-12-06 17:13:33 -0800662
Jorim Jaggi76a16232014-08-08 17:00:47 +0200663 private final LogDecelerateInterpolator mLogDecelerateInterpolator
664 = new LogDecelerateInterpolator(100, 0);
665
Jorim Jaggi4fa78922015-11-30 17:13:56 -0800666 private boolean mForceWindowDrawsStatusBarBackground;
667
Jeff Brown70825162012-03-28 17:27:48 -0700668 private static final int MSG_ENABLE_POINTER_LOCATION = 1;
669 private static final int MSG_DISABLE_POINTER_LOCATION = 2;
Jeff Brown40013652012-05-16 21:22:36 -0700670 private static final int MSG_DISPATCH_MEDIA_KEY_WITH_WAKE_LOCK = 3;
671 private static final int MSG_DISPATCH_MEDIA_KEY_REPEAT_WITH_WAKE_LOCK = 4;
Craig Mautner8a0da012014-05-31 15:13:37 -0700672 private static final int MSG_KEYGUARD_DRAWN_COMPLETE = 5;
673 private static final int MSG_KEYGUARD_DRAWN_TIMEOUT = 6;
674 private static final int MSG_WINDOW_MANAGER_DRAWN_COMPLETE = 7;
Craig Mautner84984fa2014-06-19 11:19:20 -0700675 private static final int MSG_DISPATCH_SHOW_RECENTS = 9;
Alan Viverettee34560b22014-07-10 14:50:06 -0700676 private static final int MSG_DISPATCH_SHOW_GLOBAL_ACTIONS = 10;
Craig Mautnera631d492014-08-05 15:16:01 -0700677 private static final int MSG_HIDE_BOOT_MESSAGE = 11;
Michael Wright869a67c2014-08-26 19:33:06 -0700678 private static final int MSG_LAUNCH_VOICE_ASSIST_WITH_WAKE_LOCK = 12;
Jeff Brown13f00f02014-10-31 14:45:50 -0700679 private static final int MSG_POWER_DELAYED_PRESS = 13;
680 private static final int MSG_POWER_LONG_PRESS = 14;
Jeff Brown061ea992015-04-17 19:55:47 -0700681 private static final int MSG_UPDATE_DREAMING_SLEEP_TOKEN = 15;
Jun Mukaid2e7e352015-07-22 17:14:02 -0700682 private static final int MSG_REQUEST_TRANSIENT_BARS = 16;
Jaewan Kimc552b042016-01-18 16:08:45 +0900683 private static final int MSG_REQUEST_TV_PICTURE_IN_PICTURE = 17;
Jun Mukaid2e7e352015-07-22 17:14:02 -0700684
685 private static final int MSG_REQUEST_TRANSIENT_BARS_ARG_STATUS = 0;
686 private static final int MSG_REQUEST_TRANSIENT_BARS_ARG_NAVIGATION = 1;
Jeff Brown70825162012-03-28 17:27:48 -0700687
688 private class PolicyHandler extends Handler {
689 @Override
690 public void handleMessage(Message msg) {
691 switch (msg.what) {
692 case MSG_ENABLE_POINTER_LOCATION:
693 enablePointerLocation();
694 break;
695 case MSG_DISABLE_POINTER_LOCATION:
696 disablePointerLocation();
697 break;
Jeff Brown40013652012-05-16 21:22:36 -0700698 case MSG_DISPATCH_MEDIA_KEY_WITH_WAKE_LOCK:
699 dispatchMediaKeyWithWakeLock((KeyEvent)msg.obj);
700 break;
701 case MSG_DISPATCH_MEDIA_KEY_REPEAT_WITH_WAKE_LOCK:
702 dispatchMediaKeyRepeatWithWakeLock((KeyEvent)msg.obj);
703 break;
Craig Mautner84984fa2014-06-19 11:19:20 -0700704 case MSG_DISPATCH_SHOW_RECENTS:
705 showRecentApps(false);
706 break;
Alan Viverettee34560b22014-07-10 14:50:06 -0700707 case MSG_DISPATCH_SHOW_GLOBAL_ACTIONS:
708 showGlobalActionsInternal();
709 break;
Craig Mautner8a0da012014-05-31 15:13:37 -0700710 case MSG_KEYGUARD_DRAWN_COMPLETE:
711 if (DEBUG_WAKEUP) Slog.w(TAG, "Setting mKeyguardDrawComplete");
Jeff Brown36c4db82014-09-19 12:05:31 -0700712 finishKeyguardDrawn();
Craig Mautner8a0da012014-05-31 15:13:37 -0700713 break;
714 case MSG_KEYGUARD_DRAWN_TIMEOUT:
715 Slog.w(TAG, "Keyguard drawn timeout. Setting mKeyguardDrawComplete");
Jeff Brown36c4db82014-09-19 12:05:31 -0700716 finishKeyguardDrawn();
Craig Mautner8a0da012014-05-31 15:13:37 -0700717 break;
718 case MSG_WINDOW_MANAGER_DRAWN_COMPLETE:
719 if (DEBUG_WAKEUP) Slog.w(TAG, "Setting mWindowManagerDrawComplete");
Jeff Brown36c4db82014-09-19 12:05:31 -0700720 finishWindowsDrawn();
Craig Mautner8a0da012014-05-31 15:13:37 -0700721 break;
Craig Mautnera631d492014-08-05 15:16:01 -0700722 case MSG_HIDE_BOOT_MESSAGE:
723 handleHideBootMessage();
724 break;
Michael Wright869a67c2014-08-26 19:33:06 -0700725 case MSG_LAUNCH_VOICE_ASSIST_WITH_WAKE_LOCK:
726 launchVoiceAssistWithWakeLock(msg.arg1 != 0);
727 break;
Jeff Brown13f00f02014-10-31 14:45:50 -0700728 case MSG_POWER_DELAYED_PRESS:
729 powerPress((Long)msg.obj, msg.arg1 != 0, msg.arg2);
730 finishPowerKeyPress();
731 break;
732 case MSG_POWER_LONG_PRESS:
733 powerLongPress();
734 break;
Jeff Brown061ea992015-04-17 19:55:47 -0700735 case MSG_UPDATE_DREAMING_SLEEP_TOKEN:
736 updateDreamingSleepToken(msg.arg1 != 0);
737 break;
Jun Mukaid2e7e352015-07-22 17:14:02 -0700738 case MSG_REQUEST_TRANSIENT_BARS:
739 WindowState targetBar = (msg.arg1 == MSG_REQUEST_TRANSIENT_BARS_ARG_STATUS) ?
740 mStatusBar : mNavigationBar;
741 if (targetBar != null) {
742 requestTransientBars(targetBar);
743 }
744 break;
Jaewan Kimc552b042016-01-18 16:08:45 +0900745 case MSG_REQUEST_TV_PICTURE_IN_PICTURE:
746 requestTvPictureInPictureInternal();
747 break;
Jeff Brown70825162012-03-28 17:27:48 -0700748 }
749 }
750 }
751
Dianne Hackbornad7fa7f2011-01-07 14:06:50 -0800752 private UEventObserver mHDMIObserver = new UEventObserver() {
753 @Override
754 public void onUEvent(UEventObserver.UEvent event) {
755 setHdmiPlugged("1".equals(event.get("SWITCH_STATE")));
756 }
757 };
758
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800759 class SettingsObserver extends ContentObserver {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800760 SettingsObserver(Handler handler) {
761 super(handler);
762 }
David Brownbaf8d092010-03-08 21:52:59 -0800763
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800764 void observe() {
Christopher Tate5e08af02012-09-21 17:17:22 -0700765 // Observe all users' changes
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800766 ContentResolver resolver = mContext.getContentResolver();
767 resolver.registerContentObserver(Settings.System.getUriFor(
Christopher Tate5e08af02012-09-21 17:17:22 -0700768 Settings.System.END_BUTTON_BEHAVIOR), false, this,
769 UserHandle.USER_ALL);
David Brownbaf8d092010-03-08 21:52:59 -0800770 resolver.registerContentObserver(Settings.Secure.getUriFor(
Christopher Tate5e08af02012-09-21 17:17:22 -0700771 Settings.Secure.INCALL_POWER_BUTTON_BEHAVIOR), false, this,
772 UserHandle.USER_ALL);
Jeff Browna20dda42014-05-27 20:57:24 -0700773 resolver.registerContentObserver(Settings.Secure.getUriFor(
774 Settings.Secure.WAKE_GESTURE_ENABLED), false, this,
775 UserHandle.USER_ALL);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800776 resolver.registerContentObserver(Settings.System.getUriFor(
Christopher Tate5e08af02012-09-21 17:17:22 -0700777 Settings.System.ACCELEROMETER_ROTATION), false, this,
778 UserHandle.USER_ALL);
Mike Lockwood28569302010-01-28 11:54:40 -0500779 resolver.registerContentObserver(Settings.System.getUriFor(
Christopher Tate5e08af02012-09-21 17:17:22 -0700780 Settings.System.USER_ROTATION), false, this,
781 UserHandle.USER_ALL);
Daniel Sandlerb73617d2010-08-17 00:41:00 -0400782 resolver.registerContentObserver(Settings.System.getUriFor(
Christopher Tate5e08af02012-09-21 17:17:22 -0700783 Settings.System.SCREEN_OFF_TIMEOUT), false, this,
784 UserHandle.USER_ALL);
Dianne Hackbornc777e072010-02-12 13:07:59 -0800785 resolver.registerContentObserver(Settings.System.getUriFor(
Christopher Tate5e08af02012-09-21 17:17:22 -0700786 Settings.System.POINTER_LOCATION), false, this,
787 UserHandle.USER_ALL);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800788 resolver.registerContentObserver(Settings.Secure.getUriFor(
Christopher Tate5e08af02012-09-21 17:17:22 -0700789 Settings.Secure.DEFAULT_INPUT_METHOD), false, this,
790 UserHandle.USER_ALL);
John Spurlockd9b70bd2014-02-06 17:02:44 -0500791 resolver.registerContentObserver(Settings.Secure.getUriFor(
John Spurlockf1a36642013-10-12 17:50:42 -0400792 Settings.Secure.IMMERSIVE_MODE_CONFIRMATIONS), false, this,
Christopher Tate5e08af02012-09-21 17:17:22 -0700793 UserHandle.USER_ALL);
John Spurlockc6d1c602014-01-17 15:22:06 -0500794 resolver.registerContentObserver(Settings.Global.getUriFor(
795 Settings.Global.POLICY_CONTROL), false, this,
796 UserHandle.USER_ALL);
Dianne Hackbornc777e072010-02-12 13:07:59 -0800797 updateSettings();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800798 }
799
800 @Override public void onChange(boolean selfChange) {
Dianne Hackbornc777e072010-02-12 13:07:59 -0800801 updateSettings();
Jeff Brown01a98dd2011-09-20 15:08:29 -0700802 updateRotation(false);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800803 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800804 }
Craig Mautner967212c2013-04-13 21:10:58 -0700805
Jeff Browna20dda42014-05-27 20:57:24 -0700806 class MyWakeGestureListener extends WakeGestureListener {
807 MyWakeGestureListener(Context context, Handler handler) {
808 super(context, handler);
809 }
810
811 @Override
812 public void onWakeUp() {
813 synchronized (mLock) {
814 if (shouldEnableWakeGestureLp()) {
Jeff Browne07b94b2014-06-18 15:56:27 -0700815 performHapticFeedbackLw(null, HapticFeedbackConstants.VIRTUAL_KEY, false);
Dianne Hackborn280a64e2015-07-13 14:48:08 -0700816 wakeUp(SystemClock.uptimeMillis(), mAllowTheaterModeWakeFromWakeGesture,
817 "android.policy:GESTURE");
Jeff Browna20dda42014-05-27 20:57:24 -0700818 }
819 }
820 }
821 }
822
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800823 class MyOrientationListener extends WindowOrientationListener {
Chong Zhang5aaa0b32015-08-28 10:22:36 -0700824 private final Runnable mUpdateRotationRunnable = new Runnable() {
825 @Override
826 public void run() {
Tim Murray1f407642015-10-01 17:07:12 -0700827 // send interaction hint to improve redraw performance
828 mPowerManagerInternal.powerHint(PowerManagerInternal.POWER_HINT_INTERACTION, 0);
Chong Zhang5aaa0b32015-08-28 10:22:36 -0700829 updateRotation(false);
830 }
831 };
832
Craig Mautnereee29c42013-01-17 14:44:34 -0800833 MyOrientationListener(Context context, Handler handler) {
834 super(context, handler);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800835 }
Craig Mautner967212c2013-04-13 21:10:58 -0700836
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800837 @Override
Jeff Brownc0347aa2011-09-23 17:26:09 -0700838 public void onProposedRotationChanged(int rotation) {
Craig Mautnereda67292013-04-28 13:50:14 -0700839 if (localLOGV) Slog.v(TAG, "onProposedRotationChanged, rotation=" + rotation);
Chong Zhang5aaa0b32015-08-28 10:22:36 -0700840 mHandler.post(mUpdateRotationRunnable);
Jeff Brown01a98dd2011-09-20 15:08:29 -0700841 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800842 }
843 MyOrientationListener mOrientationListener;
844
Jorim Jaggi24bec7c2015-02-04 12:40:14 +0100845 private final StatusBarController mStatusBarController = new StatusBarController();
John Spurlock5b9145b2013-08-20 15:13:47 -0400846
John Spurlock27735a42013-08-14 17:57:38 -0400847 private final BarController mNavigationBarController = new BarController("NavigationBar",
John Spurlock5b9145b2013-08-20 15:13:47 -0400848 View.NAVIGATION_BAR_TRANSIENT,
849 View.NAVIGATION_BAR_UNHIDE,
John Spurlockbd957402013-10-03 11:38:39 -0400850 View.NAVIGATION_BAR_TRANSLUCENT,
851 StatusBarManager.WINDOW_NAVIGATION_BAR,
Jorim Jaggi4fa78922015-11-30 17:13:56 -0800852 WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION,
853 View.NAVIGATION_BAR_TRANSPARENT);
John Spurlock5b9145b2013-08-20 15:13:47 -0400854
John Spurlockf1a36642013-10-12 17:50:42 -0400855 private ImmersiveModeConfirmation mImmersiveModeConfirmation;
John Spurlock32beb2c2013-03-11 10:16:47 -0400856
Craig Mautner037aa8d2013-06-07 10:35:44 -0700857 private SystemGesturesPointerEventListener mSystemGestures;
John Spurlock32beb2c2013-03-11 10:16:47 -0400858
Dianne Hackborn42e620c2012-06-24 13:20:51 -0700859 IStatusBarService getStatusBarService() {
860 synchronized (mServiceAquireLock) {
861 if (mStatusBarService == null) {
862 mStatusBarService = IStatusBarService.Stub.asInterface(
863 ServiceManager.getService("statusbar"));
864 }
865 return mStatusBarService;
866 }
867 }
868
Jorim Jaggi86905582016-02-09 21:36:09 -0800869 StatusBarManagerInternal getStatusBarManagerInternal() {
870 synchronized (mServiceAquireLock) {
871 if (mStatusBarManagerInternal == null) {
872 mStatusBarManagerInternal =
873 LocalServices.getService(StatusBarManagerInternal.class);
874 }
875 return mStatusBarManagerInternal;
876 }
877 }
878
Suchi Amalapurapua9e1b162009-03-24 22:24:47 -0700879 /*
880 * We always let the sensor be switched on by default except when
881 * the user has explicitly disabled sensor based rotation or when the
882 * screen is switched off.
883 */
The Android Open Source Project0727d222009-03-11 12:11:58 -0700884 boolean needSensorRunningLp() {
Jeff Brownbcdfc622014-03-06 19:13:04 -0800885 if (mSupportAutoRotation) {
886 if (mCurrentAppOrientation == ActivityInfo.SCREEN_ORIENTATION_SENSOR
887 || mCurrentAppOrientation == ActivityInfo.SCREEN_ORIENTATION_FULL_SENSOR
888 || mCurrentAppOrientation == ActivityInfo.SCREEN_ORIENTATION_SENSOR_PORTRAIT
889 || mCurrentAppOrientation == ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE) {
890 // If the application has explicitly requested to follow the
891 // orientation, then we need to turn the sensor on.
892 return true;
893 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800894 }
Dianne Hackborn867ab6472010-04-29 13:28:56 -0700895 if ((mCarDockEnablesAccelerometer && mDockMode == Intent.EXTRA_DOCK_STATE_CAR) ||
Jeff Brown1a693182011-11-08 14:44:16 -0800896 (mDeskDockEnablesAccelerometer && (mDockMode == Intent.EXTRA_DOCK_STATE_DESK
897 || mDockMode == Intent.EXTRA_DOCK_STATE_LE_DESK
898 || mDockMode == Intent.EXTRA_DOCK_STATE_HE_DESK))) {
Mike Lockwoode9867d22009-09-20 01:59:02 -0400899 // enable accelerometer if we are docked in a dock that enables accelerometer
900 // orientation management,
901 return true;
902 }
Jeff Brown207673cd2012-06-05 17:47:11 -0700903 if (mUserRotationMode == USER_ROTATION_LOCKED) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800904 // If the setting for using the sensor by default is enabled, then
905 // we will always leave it on. Note that the user could go to
906 // a window that forces an orientation that does not use the
907 // sensor and in theory we could turn it off... however, when next
908 // turning it on we won't have a good value for the current
909 // orientation for a little bit, which can cause orientation
910 // changes to lag, so we'd like to keep it always on. (It will
911 // still be turned off when the screen is off.)
Suchi Amalapurapua9e1b162009-03-24 22:24:47 -0700912 return false;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800913 }
Jeff Brownbcdfc622014-03-06 19:13:04 -0800914 return mSupportAutoRotation;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800915 }
Craig Mautner46ac6fa2013-08-01 10:06:34 -0700916
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800917 /*
918 * Various use cases for invoking this function
919 * screen turning off, should always disable listeners if already enabled
Craig Mautner46ac6fa2013-08-01 10:06:34 -0700920 * screen turned on and current app has sensor based orientation, enable listeners
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800921 * if not already enabled
922 * screen turned on and current app does not have sensor orientation, disable listeners if
923 * already enabled
924 * screen turning on and current app has sensor based orientation, enable listeners if needed
925 * screen turning on and current app has nosensor based orientation, do nothing
926 */
The Android Open Source Project0727d222009-03-11 12:11:58 -0700927 void updateOrientationListenerLp() {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800928 if (!mOrientationListener.canDetectOrientation()) {
929 // If sensor is turned off or nonexistent for some reason
930 return;
931 }
Stefan Kuhne9326dc12015-06-12 09:25:32 -1000932 // Could have been invoked due to screen turning on or off or
933 // change of the currently visible window's orientation.
Jeff Brown3ee549c2014-09-22 20:14:39 -0700934 if (localLOGV) Slog.v(TAG, "mScreenOnEarly=" + mScreenOnEarly
935 + ", mAwake=" + mAwake + ", mCurrentAppOrientation=" + mCurrentAppOrientation
Stefan Kuhne9326dc12015-06-12 09:25:32 -1000936 + ", mOrientationSensorEnabled=" + mOrientationSensorEnabled
937 + ", mKeyguardDrawComplete=" + mKeyguardDrawComplete
938 + ", mWindowManagerDrawComplete=" + mWindowManagerDrawComplete);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800939 boolean disable = true;
Stefan Kuhne9326dc12015-06-12 09:25:32 -1000940 // Note: We postpone the rotating of the screen until the keyguard as well as the
941 // window manager have reported a draw complete.
942 if (mScreenOnEarly && mAwake &&
943 mKeyguardDrawComplete && mWindowManagerDrawComplete) {
The Android Open Source Project0727d222009-03-11 12:11:58 -0700944 if (needSensorRunningLp()) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800945 disable = false;
946 //enable listener if not already enabled
The Android Open Source Project0727d222009-03-11 12:11:58 -0700947 if (!mOrientationSensorEnabled) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800948 mOrientationListener.enable();
Craig Mautnereda67292013-04-28 13:50:14 -0700949 if(localLOGV) Slog.v(TAG, "Enabling listeners");
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800950 mOrientationSensorEnabled = true;
951 }
Craig Mautner46ac6fa2013-08-01 10:06:34 -0700952 }
953 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800954 //check if sensors need to be disabled
The Android Open Source Project0727d222009-03-11 12:11:58 -0700955 if (disable && mOrientationSensorEnabled) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800956 mOrientationListener.disable();
Craig Mautnereda67292013-04-28 13:50:14 -0700957 if(localLOGV) Slog.v(TAG, "Disabling listeners");
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800958 mOrientationSensorEnabled = false;
959 }
960 }
961
Jeff Brown13f00f02014-10-31 14:45:50 -0700962 private void interceptPowerKeyDown(KeyEvent event, boolean interactive) {
963 // Hold a wake lock until the power key is released.
964 if (!mPowerKeyWakeLock.isHeld()) {
965 mPowerKeyWakeLock.acquire();
966 }
967
968 // Cancel multi-press detection timeout.
969 if (mPowerKeyPressCounter != 0) {
970 mHandler.removeMessages(MSG_POWER_DELAYED_PRESS);
971 }
972
973 // Detect user pressing the power button in panic when an application has
974 // taken over the whole screen.
975 boolean panic = mImmersiveModeConfirmation.onPowerKeyDown(interactive,
Craig Mautner0124980e92014-11-30 21:15:34 -0800976 SystemClock.elapsedRealtime(), isImmersiveMode(mLastSystemUiFlags));
Jeff Brown13f00f02014-10-31 14:45:50 -0700977 if (panic) {
Adrian Roosddc8b272015-05-21 16:28:27 -0700978 mHandler.post(mHiddenNavPanic);
Jeff Brown13f00f02014-10-31 14:45:50 -0700979 }
980
981 // Latch power key state to detect screenshot chord.
982 if (interactive && !mScreenshotChordPowerKeyTriggered
983 && (event.getFlags() & KeyEvent.FLAG_FALLBACK) == 0) {
984 mScreenshotChordPowerKeyTriggered = true;
985 mScreenshotChordPowerKeyTime = event.getDownTime();
986 interceptScreenshotChord();
987 }
988
989 // Stop ringing or end call if configured to do so when power is pressed.
990 TelecomManager telecomManager = getTelecommService();
991 boolean hungUp = false;
992 if (telecomManager != null) {
993 if (telecomManager.isRinging()) {
994 // Pressing Power while there's a ringing incoming
995 // call should silence the ringer.
996 telecomManager.silenceRinger();
997 } else if ((mIncallPowerBehavior
998 & Settings.Secure.INCALL_POWER_BUTTON_BEHAVIOR_HANGUP) != 0
999 && telecomManager.isInCall() && interactive) {
1000 // Otherwise, if "Power button ends call" is enabled,
1001 // the Power button will hang up any current active call.
1002 hungUp = telecomManager.endCall();
1003 }
1004 }
1005
Adrian Roos5941c982015-09-03 15:59:49 -07001006 GestureLauncherService gestureService = LocalServices.getService(
1007 GestureLauncherService.class);
1008 boolean gesturedServiceIntercepted = false;
1009 if (gestureService != null) {
1010 gesturedServiceIntercepted = gestureService.interceptPowerKeyDown(event, interactive);
1011 }
1012
Jeff Brown13f00f02014-10-31 14:45:50 -07001013 // If the power key has still not yet been handled, then detect short
1014 // press, long press, or multi press and decide what to do.
1015 mPowerKeyHandled = hungUp || mScreenshotChordVolumeDownKeyTriggered
Adrian Roos5941c982015-09-03 15:59:49 -07001016 || mScreenshotChordVolumeUpKeyTriggered || gesturedServiceIntercepted;
Jeff Brown13f00f02014-10-31 14:45:50 -07001017 if (!mPowerKeyHandled) {
1018 if (interactive) {
1019 // When interactive, we're already awake.
1020 // Wait for a long press or for the button to be released to decide what to do.
1021 if (hasLongPressOnPowerBehavior()) {
1022 Message msg = mHandler.obtainMessage(MSG_POWER_LONG_PRESS);
1023 msg.setAsynchronous(true);
1024 mHandler.sendMessageDelayed(msg,
1025 ViewConfiguration.get(mContext).getDeviceGlobalActionKeyTimeout());
1026 }
1027 } else {
Bryce Leed9268e32014-11-17 17:40:59 -08001028 wakeUpFromPowerKey(event.getDownTime());
Bryce Leed9268e32014-11-17 17:40:59 -08001029
Bryce Leed3b28402015-03-09 15:49:13 +00001030 if (mSupportLongPressPowerWhenNonInteractive && hasLongPressOnPowerBehavior()) {
1031 Message msg = mHandler.obtainMessage(MSG_POWER_LONG_PRESS);
1032 msg.setAsynchronous(true);
1033 mHandler.sendMessageDelayed(msg,
1034 ViewConfiguration.get(mContext).getDeviceGlobalActionKeyTimeout());
Bryce Leed9268e32014-11-17 17:40:59 -08001035 mBeganFromNonInteractive = true;
Bryce Leed3b28402015-03-09 15:49:13 +00001036 } else {
1037 final int maxCount = getMaxMultiPressPowerCount();
1038
1039 if (maxCount <= 1) {
1040 mPowerKeyHandled = true;
1041 } else {
1042 mBeganFromNonInteractive = true;
1043 }
Jeff Brown13f00f02014-10-31 14:45:50 -07001044 }
1045 }
Jeff Brown4d396052010-10-29 21:50:21 -07001046 }
1047 }
1048
Jeff Brown13f00f02014-10-31 14:45:50 -07001049 private void interceptPowerKeyUp(KeyEvent event, boolean interactive, boolean canceled) {
1050 final boolean handled = canceled || mPowerKeyHandled;
1051 mScreenshotChordPowerKeyTriggered = false;
1052 cancelPendingScreenshotChordAction();
1053 cancelPendingPowerKeyAction();
1054
1055 if (!handled) {
1056 // Figure out how to handle the key now that it has been released.
1057 mPowerKeyPressCounter += 1;
1058
1059 final int maxCount = getMaxMultiPressPowerCount();
1060 final long eventTime = event.getDownTime();
1061 if (mPowerKeyPressCounter < maxCount) {
1062 // This could be a multi-press. Wait a little bit longer to confirm.
1063 // Continue holding the wake lock.
1064 Message msg = mHandler.obtainMessage(MSG_POWER_DELAYED_PRESS,
1065 interactive ? 1 : 0, mPowerKeyPressCounter, eventTime);
1066 msg.setAsynchronous(true);
1067 mHandler.sendMessageDelayed(msg, ViewConfiguration.getDoubleTapTimeout());
1068 return;
1069 }
1070
1071 // No other actions. Handle it immediately.
1072 powerPress(eventTime, interactive, mPowerKeyPressCounter);
Jeff Brown4d396052010-10-29 21:50:21 -07001073 }
Jeff Brown13f00f02014-10-31 14:45:50 -07001074
1075 // Done. Reset our state.
1076 finishPowerKeyPress();
1077 }
1078
1079 private void finishPowerKeyPress() {
Bryce Leed9268e32014-11-17 17:40:59 -08001080 mBeganFromNonInteractive = false;
Jeff Brown13f00f02014-10-31 14:45:50 -07001081 mPowerKeyPressCounter = 0;
1082 if (mPowerKeyWakeLock.isHeld()) {
1083 mPowerKeyWakeLock.release();
1084 }
Jeff Brownd5bb82d2011-10-12 13:57:59 -07001085 }
1086
1087 private void cancelPendingPowerKeyAction() {
1088 if (!mPowerKeyHandled) {
Jeff Brown13f00f02014-10-31 14:45:50 -07001089 mPowerKeyHandled = true;
1090 mHandler.removeMessages(MSG_POWER_LONG_PRESS);
Jeff Brownd5bb82d2011-10-12 13:57:59 -07001091 }
Jeff Brown13f00f02014-10-31 14:45:50 -07001092 }
1093
1094 private void powerPress(long eventTime, boolean interactive, int count) {
1095 if (mScreenOnEarly && !mScreenOnFully) {
1096 Slog.i(TAG, "Suppressed redundant power key press while "
1097 + "already in the process of turning the screen on.");
1098 return;
Jeff Brownff204712011-10-25 21:27:54 -07001099 }
Jeff Brown13f00f02014-10-31 14:45:50 -07001100
1101 if (count == 2) {
1102 powerMultiPressAction(eventTime, interactive, mDoublePressOnPowerBehavior);
1103 } else if (count == 3) {
1104 powerMultiPressAction(eventTime, interactive, mTriplePressOnPowerBehavior);
Bryce Leed9268e32014-11-17 17:40:59 -08001105 } else if (interactive && !mBeganFromNonInteractive) {
Jeff Brown13f00f02014-10-31 14:45:50 -07001106 switch (mShortPressOnPowerBehavior) {
1107 case SHORT_PRESS_POWER_NOTHING:
1108 break;
1109 case SHORT_PRESS_POWER_GO_TO_SLEEP:
1110 mPowerManager.goToSleep(eventTime,
1111 PowerManager.GO_TO_SLEEP_REASON_POWER_BUTTON, 0);
1112 break;
1113 case SHORT_PRESS_POWER_REALLY_GO_TO_SLEEP:
1114 mPowerManager.goToSleep(eventTime,
1115 PowerManager.GO_TO_SLEEP_REASON_POWER_BUTTON,
1116 PowerManager.GO_TO_SLEEP_FLAG_NO_DOZE);
1117 break;
1118 case SHORT_PRESS_POWER_REALLY_GO_TO_SLEEP_AND_GO_HOME:
1119 mPowerManager.goToSleep(eventTime,
1120 PowerManager.GO_TO_SLEEP_REASON_POWER_BUTTON,
1121 PowerManager.GO_TO_SLEEP_FLAG_NO_DOZE);
1122 launchHomeFromHotKey();
1123 break;
Bryce Lee01b0c5f2015-02-05 18:24:04 -08001124 case SHORT_PRESS_POWER_GO_HOME:
Bryce Lee662ed802015-04-10 20:11:39 +00001125 launchHomeFromHotKey(true /* awakenFromDreams */, false /*respectKeyguard*/);
Bryce Lee01b0c5f2015-02-05 18:24:04 -08001126 break;
Jeff Brown13f00f02014-10-31 14:45:50 -07001127 }
1128 }
1129 }
1130
1131 private void powerMultiPressAction(long eventTime, boolean interactive, int behavior) {
1132 switch (behavior) {
1133 case MULTI_PRESS_POWER_NOTHING:
1134 break;
1135 case MULTI_PRESS_POWER_THEATER_MODE:
Bryce Lee3ae447e2015-06-30 12:31:41 -07001136 if (!isUserSetupComplete()) {
1137 Slog.i(TAG, "Ignoring toggling theater mode - device not setup.");
1138 break;
1139 }
1140
Jeff Brown13f00f02014-10-31 14:45:50 -07001141 if (isTheaterModeEnabled()) {
1142 Slog.i(TAG, "Toggling theater mode off.");
1143 Settings.Global.putInt(mContext.getContentResolver(),
1144 Settings.Global.THEATER_MODE_ON, 0);
1145 if (!interactive) {
1146 wakeUpFromPowerKey(eventTime);
1147 }
1148 } else {
1149 Slog.i(TAG, "Toggling theater mode on.");
1150 Settings.Global.putInt(mContext.getContentResolver(),
1151 Settings.Global.THEATER_MODE_ON, 1);
Bryce Lee55e846d2014-11-04 12:43:44 -08001152
1153 if (mGoToSleepOnButtonPressTheaterMode && interactive) {
Jeff Brown13f00f02014-10-31 14:45:50 -07001154 mPowerManager.goToSleep(eventTime,
1155 PowerManager.GO_TO_SLEEP_REASON_POWER_BUTTON, 0);
1156 }
1157 }
1158 break;
1159 case MULTI_PRESS_POWER_BRIGHTNESS_BOOST:
Jeff Brown7b5be5e2014-11-12 18:45:31 -08001160 Slog.i(TAG, "Starting brightness boost.");
1161 if (!interactive) {
1162 wakeUpFromPowerKey(eventTime);
1163 }
Jeff Brown13f00f02014-10-31 14:45:50 -07001164 mPowerManager.boostScreenBrightness(eventTime);
1165 break;
1166 }
1167 }
1168
1169 private int getMaxMultiPressPowerCount() {
1170 if (mTriplePressOnPowerBehavior != MULTI_PRESS_POWER_NOTHING) {
1171 return 3;
1172 }
1173 if (mDoublePressOnPowerBehavior != MULTI_PRESS_POWER_NOTHING) {
1174 return 2;
1175 }
1176 return 1;
1177 }
1178
1179 private void powerLongPress() {
1180 final int behavior = getResolvedLongPressOnPowerBehavior();
1181 switch (behavior) {
1182 case LONG_PRESS_POWER_NOTHING:
1183 break;
1184 case LONG_PRESS_POWER_GLOBAL_ACTIONS:
1185 mPowerKeyHandled = true;
1186 if (!performHapticFeedbackLw(null, HapticFeedbackConstants.LONG_PRESS, false)) {
1187 performAuditoryFeedbackForAccessibilityIfNeed();
1188 }
1189 showGlobalActionsInternal();
1190 break;
1191 case LONG_PRESS_POWER_SHUT_OFF:
1192 case LONG_PRESS_POWER_SHUT_OFF_NO_CONFIRM:
1193 mPowerKeyHandled = true;
1194 performHapticFeedbackLw(null, HapticFeedbackConstants.LONG_PRESS, false);
1195 sendCloseSystemWindows(SYSTEM_DIALOG_REASON_GLOBAL_ACTIONS);
1196 mWindowManagerFuncs.shutdown(behavior == LONG_PRESS_POWER_SHUT_OFF);
1197 break;
1198 }
1199 }
1200
Nick Vaccarob593a812015-05-15 11:23:05 -07001201 private void sleepPress(long eventTime) {
1202 if (mShortPressOnSleepBehavior == SHORT_PRESS_SLEEP_GO_TO_SLEEP_AND_GO_HOME) {
1203 launchHomeFromHotKey(false /* awakenDreams */, true /*respectKeyguard*/);
1204 }
1205 }
1206
1207 private void sleepRelease(long eventTime) {
Filip Gruszczynskia483a1d2015-03-17 19:06:58 +00001208 switch (mShortPressOnSleepBehavior) {
1209 case SHORT_PRESS_SLEEP_GO_TO_SLEEP:
Filip Gruszczynskia483a1d2015-03-17 19:06:58 +00001210 case SHORT_PRESS_SLEEP_GO_TO_SLEEP_AND_GO_HOME:
Nick Vaccarob593a812015-05-15 11:23:05 -07001211 Slog.i(TAG, "sleepRelease() calling goToSleep(GO_TO_SLEEP_REASON_SLEEP_BUTTON)");
1212 mPowerManager.goToSleep(eventTime,
1213 PowerManager.GO_TO_SLEEP_REASON_SLEEP_BUTTON, 0);
Filip Gruszczynskia483a1d2015-03-17 19:06:58 +00001214 break;
1215 }
1216 }
1217
Jeff Brown13f00f02014-10-31 14:45:50 -07001218 private int getResolvedLongPressOnPowerBehavior() {
1219 if (FactoryTest.isLongPressOnPowerOffEnabled()) {
1220 return LONG_PRESS_POWER_SHUT_OFF_NO_CONFIRM;
1221 }
1222 return mLongPressOnPowerBehavior;
1223 }
1224
1225 private boolean hasLongPressOnPowerBehavior() {
1226 return getResolvedLongPressOnPowerBehavior() != LONG_PRESS_POWER_NOTHING;
Jeff Brownd5bb82d2011-10-12 13:57:59 -07001227 }
1228
1229 private void interceptScreenshotChord() {
Christopher Tatee90585f2012-03-05 18:56:25 -08001230 if (mScreenshotChordEnabled
Jeff Brown13f00f02014-10-31 14:45:50 -07001231 && mScreenshotChordVolumeDownKeyTriggered && mScreenshotChordPowerKeyTriggered
1232 && !mScreenshotChordVolumeUpKeyTriggered) {
Jeff Brownd5bb82d2011-10-12 13:57:59 -07001233 final long now = SystemClock.uptimeMillis();
Jeff Brown13f00f02014-10-31 14:45:50 -07001234 if (now <= mScreenshotChordVolumeDownKeyTime + SCREENSHOT_CHORD_DEBOUNCE_DELAY_MILLIS
1235 && now <= mScreenshotChordPowerKeyTime
1236 + SCREENSHOT_CHORD_DEBOUNCE_DELAY_MILLIS) {
1237 mScreenshotChordVolumeDownKeyConsumed = true;
Jeff Brownd5bb82d2011-10-12 13:57:59 -07001238 cancelPendingPowerKeyAction();
1239
Jeff Sharkey2991fa32012-12-05 18:06:43 -08001240 mHandler.postDelayed(mScreenshotRunnable, getScreenshotChordLongPressDelay());
Jeff Brownd5bb82d2011-10-12 13:57:59 -07001241 }
1242 }
1243 }
1244
Winson Chung1cea2f32012-10-08 20:42:01 -07001245 private long getScreenshotChordLongPressDelay() {
Jim Miller5ecd8112013-01-09 18:50:26 -08001246 if (mKeyguardDelegate.isShowing()) {
Winson Chung1cea2f32012-10-08 20:42:01 -07001247 // Double the time it takes to take a screenshot from the keyguard
1248 return (long) (KEYGUARD_SCREENSHOT_CHORD_DELAY_MULTIPLIER *
Justin Kohfeabd2c2014-05-02 10:02:44 -07001249 ViewConfiguration.get(mContext).getDeviceGlobalActionKeyTimeout());
Winson Chung1cea2f32012-10-08 20:42:01 -07001250 }
Justin Kohfeabd2c2014-05-02 10:02:44 -07001251 return ViewConfiguration.get(mContext).getDeviceGlobalActionKeyTimeout();
Winson Chung1cea2f32012-10-08 20:42:01 -07001252 }
1253
Jeff Brownd5bb82d2011-10-12 13:57:59 -07001254 private void cancelPendingScreenshotChordAction() {
Jeff Sharkey2991fa32012-12-05 18:06:43 -08001255 mHandler.removeCallbacks(mScreenshotRunnable);
Jeff Brown4d396052010-10-29 21:50:21 -07001256 }
1257
Jeff Brown13f00f02014-10-31 14:45:50 -07001258 private final Runnable mEndCallLongPress = new Runnable() {
Craig Mautnerf1b67412012-09-19 13:18:29 -07001259 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001260 public void run() {
Jeff Brown13f00f02014-10-31 14:45:50 -07001261 mEndCallKeyHandled = true;
1262 if (!performHapticFeedbackLw(null, HapticFeedbackConstants.LONG_PRESS, false)) {
1263 performAuditoryFeedbackForAccessibilityIfNeed();
Joe Onoratod208e702010-10-08 16:22:43 -04001264 }
Jeff Brown13f00f02014-10-31 14:45:50 -07001265 showGlobalActionsInternal();
Jeff Brownd5bb82d2011-10-12 13:57:59 -07001266 }
1267 };
1268
Jeff Sharkey2991fa32012-12-05 18:06:43 -08001269 private final Runnable mScreenshotRunnable = new Runnable() {
Craig Mautner0bf6ec92012-12-18 08:33:27 -08001270 @Override
Jeff Brownd5bb82d2011-10-12 13:57:59 -07001271 public void run() {
1272 takeScreenshot();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001273 }
1274 };
1275
Alan Viverettee34560b22014-07-10 14:50:06 -07001276 @Override
1277 public void showGlobalActions() {
1278 mHandler.removeMessages(MSG_DISPATCH_SHOW_GLOBAL_ACTIONS);
1279 mHandler.sendEmptyMessage(MSG_DISPATCH_SHOW_GLOBAL_ACTIONS);
1280 }
1281
1282 void showGlobalActionsInternal() {
1283 sendCloseSystemWindows(SYSTEM_DIALOG_REASON_GLOBAL_ACTIONS);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001284 if (mGlobalActions == null) {
Jeff Brown7304c342012-05-11 18:42:42 -07001285 mGlobalActions = new GlobalActions(mContext, mWindowManagerFuncs);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001286 }
Jim Millerab954542014-10-10 18:21:49 -07001287 final boolean keyguardShowing = isKeyguardShowingAndNotOccluded();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001288 mGlobalActions.showDialog(keyguardShowing, isDeviceProvisioned());
1289 if (keyguardShowing) {
1290 // since it took two seconds of long press to bring this up,
1291 // poke the wake lock so they have some time to see the dialog.
Jim Miller25190572013-02-28 17:36:24 -08001292 mPowerManager.userActivity(SystemClock.uptimeMillis(), false);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001293 }
1294 }
1295
1296 boolean isDeviceProvisioned() {
Jeff Brownbf6f6f92012-09-25 15:03:20 -07001297 return Settings.Global.getInt(
1298 mContext.getContentResolver(), Settings.Global.DEVICE_PROVISIONED, 0) != 0;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001299 }
1300
Maurice Lam99c6e072014-04-28 18:24:28 -07001301 boolean isUserSetupComplete() {
1302 return Settings.Secure.getIntForUser(mContext.getContentResolver(),
1303 Settings.Secure.USER_SETUP_COMPLETE, 0, UserHandle.USER_CURRENT) != 0;
1304 }
1305
Jeff Brown13f00f02014-10-31 14:45:50 -07001306 private void handleShortPressOnHome() {
Jinsuk Kime601b712015-07-07 08:01:02 +09001307 // Turn on the connected TV and switch HDMI input if we're a HDMI playback device.
1308 getHdmiControl().turnOnTv();
1309
Jeff Brown13f00f02014-10-31 14:45:50 -07001310 // If there's a dream running then use home to escape the dream
1311 // but don't actually go home.
1312 if (mDreamManagerInternal != null && mDreamManagerInternal.isDreaming()) {
1313 mDreamManagerInternal.stopDream(false /*immediate*/);
1314 return;
1315 }
1316
1317 // Go home!
1318 launchHomeFromHotKey();
1319 }
1320
Jinsuk Kime601b712015-07-07 08:01:02 +09001321 /**
1322 * Creates an accessor to HDMI control service that performs the operation of
1323 * turning on TV (optional) and switching input to us. If HDMI control service
1324 * is not available or we're not a HDMI playback device, the operation is no-op.
1325 */
1326 private HdmiControl getHdmiControl() {
1327 if (null == mHdmiControl) {
1328 HdmiControlManager manager = (HdmiControlManager) mContext.getSystemService(
1329 Context.HDMI_CONTROL_SERVICE);
1330 HdmiPlaybackClient client = null;
1331 if (manager != null) {
1332 client = manager.getPlaybackClient();
1333 }
1334 mHdmiControl = new HdmiControl(client);
1335 }
1336 return mHdmiControl;
1337 }
1338
1339 private static class HdmiControl {
1340 private final HdmiPlaybackClient mClient;
1341
1342 private HdmiControl(HdmiPlaybackClient client) {
1343 mClient = client;
1344 }
1345
1346 public void turnOnTv() {
1347 if (mClient == null) {
1348 return;
1349 }
1350 mClient.oneTouchPlay(new OneTouchPlayCallback() {
1351 @Override
1352 public void onComplete(int result) {
1353 if (result != HdmiControlManager.RESULT_SUCCESS) {
1354 Log.w(TAG, "One touch play failed: " + result);
1355 }
1356 }
1357 });
1358 }
1359 }
1360
Jaewan Kim76b7d0d2016-02-12 19:01:02 +09001361 private void handleLongPressOnHome(int deviceId) {
Jaewan Kim52632e22016-01-14 18:01:52 +09001362 if (mLongPressOnHomeBehavior == LONG_PRESS_HOME_NOTHING) {
1363 return;
1364 }
1365 mHomeConsumed = true;
1366 performHapticFeedbackLw(null, HapticFeedbackConstants.LONG_PRESS, false);
Patrick Dubroyece94522011-02-23 18:35:01 -08001367
Jaewan Kim52632e22016-01-14 18:01:52 +09001368 switch (mLongPressOnHomeBehavior) {
1369 case LONG_PRESS_HOME_RECENT_SYSTEM_UI:
Jeff Browncaca8812013-05-09 13:34:33 -07001370 toggleRecentApps();
Jaewan Kim52632e22016-01-14 18:01:52 +09001371 break;
1372 case LONG_PRESS_HOME_ASSIST:
Tim Kilbourn0e5f1102015-06-05 16:18:09 -07001373 launchAssistAction(null, deviceId);
Jaewan Kim52632e22016-01-14 18:01:52 +09001374 break;
Jaewan Kim52632e22016-01-14 18:01:52 +09001375 default:
Jaewan Kim76b7d0d2016-02-12 19:01:02 +09001376 Log.w(TAG, "Undefined home long press behavior: " + mLongPressOnHomeBehavior);
Jaewan Kim52632e22016-01-14 18:01:52 +09001377 break;
Jim Millere6ad1a82010-08-20 19:25:39 -07001378 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001379 }
Patrick Dubroyece94522011-02-23 18:35:01 -08001380
Jeff Browncaca8812013-05-09 13:34:33 -07001381 private void handleDoubleTapOnHome() {
1382 if (mDoubleTapOnHomeBehavior == DOUBLE_TAP_HOME_RECENT_SYSTEM_UI) {
1383 mHomeConsumed = true;
1384 toggleRecentApps();
1385 }
1386 }
1387
Jaewan Kimc552b042016-01-18 16:08:45 +09001388 private void requestTvPictureInPicture(KeyEvent event) {
1389 if (DEBUG_INPUT) Log.d(TAG, "requestTvPictureInPicture event=" + event);
1390 mHandler.removeMessages(MSG_REQUEST_TV_PICTURE_IN_PICTURE);
1391 Message msg = mHandler.obtainMessage(MSG_REQUEST_TV_PICTURE_IN_PICTURE);
1392 msg.setAsynchronous(true);
1393 msg.sendToTarget();
1394 }
1395
1396 private void requestTvPictureInPictureInternal() {
1397 try {
1398 IStatusBarService statusbar = getStatusBarService();
1399 if (statusbar != null) {
1400 statusbar.requestTvPictureInPicture();
1401 }
1402 } catch (RemoteException|IllegalArgumentException e) {
1403 Slog.e(TAG, "Cannot handle picture-in-picture key", e);
1404 // re-acquire status bar service next time it is needed.
1405 mStatusBarService = null;
1406 }
Jaewan Kim52632e22016-01-14 18:01:52 +09001407 }
1408
Jeff Browncaca8812013-05-09 13:34:33 -07001409 private final Runnable mHomeDoubleTapTimeoutRunnable = new Runnable() {
1410 @Override
1411 public void run() {
1412 if (mHomeDoubleTapPending) {
1413 mHomeDoubleTapPending = false;
Jeff Brown13f00f02014-10-31 14:45:50 -07001414 handleShortPressOnHome();
Jeff Browncaca8812013-05-09 13:34:33 -07001415 }
1416 }
1417 };
1418
Mark Renoufc1256912015-03-11 14:38:23 -04001419 private boolean isRoundWindow() {
Adam Powell01f280d2015-05-18 16:07:42 -07001420 return mContext.getResources().getConfiguration().isScreenRound();
Mark Renoufc1256912015-03-11 14:38:23 -04001421 }
1422
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001423 /** {@inheritDoc} */
Craig Mautner0bf6ec92012-12-18 08:33:27 -08001424 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001425 public void init(Context context, IWindowManager windowManager,
Jeff Brown96307042012-07-27 15:51:34 -07001426 WindowManagerFuncs windowManagerFuncs) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001427 mContext = context;
1428 mWindowManager = windowManager;
Dianne Hackborndf89e652011-10-06 22:35:11 -07001429 mWindowManagerFuncs = windowManagerFuncs;
Craig Mautner8a0da012014-05-31 15:13:37 -07001430 mWindowManagerInternal = LocalServices.getService(WindowManagerInternal.class);
Jeff Brown061ea992015-04-17 19:55:47 -07001431 mActivityManagerInternal = LocalServices.getService(ActivityManagerInternal.class);
Jose Lima9546b202014-07-02 17:21:51 -07001432 mDreamManagerInternal = LocalServices.getService(DreamManagerInternal.class);
Michael Wrighta4d22d72015-09-16 23:19:26 +01001433 mPowerManagerInternal = LocalServices.getService(PowerManagerInternal.class);
Billy Laucbe540f2015-06-25 01:51:44 +01001434 mAppOpsManager = (AppOpsManager) mContext.getSystemService(Context.APP_OPS_SERVICE);
Mark Renoufc1256912015-03-11 14:38:23 -04001435
1436 // Init display burn-in protection
1437 boolean burnInProtectionEnabled = context.getResources().getBoolean(
1438 com.android.internal.R.bool.config_enableBurnInProtection);
1439 // Allow a system property to override this. Used by developer settings.
1440 boolean burnInProtectionDevMode =
1441 SystemProperties.getBoolean("persist.debug.force_burn_in", false);
1442 if (burnInProtectionEnabled || burnInProtectionDevMode) {
1443 final int minHorizontal;
1444 final int maxHorizontal;
1445 final int minVertical;
1446 final int maxVertical;
1447 final int maxRadius;
1448 if (burnInProtectionDevMode) {
1449 minHorizontal = -8;
1450 maxHorizontal = 8;
1451 minVertical = -8;
1452 maxVertical = -4;
1453 maxRadius = (isRoundWindow()) ? 6 : -1;
1454 } else {
1455 Resources resources = context.getResources();
1456 minHorizontal = resources.getInteger(
1457 com.android.internal.R.integer.config_burnInProtectionMinHorizontalOffset);
1458 maxHorizontal = resources.getInteger(
1459 com.android.internal.R.integer.config_burnInProtectionMaxHorizontalOffset);
1460 minVertical = resources.getInteger(
1461 com.android.internal.R.integer.config_burnInProtectionMinVerticalOffset);
1462 maxVertical = resources.getInteger(
1463 com.android.internal.R.integer.config_burnInProtectionMaxVerticalOffset);
1464 maxRadius = resources.getInteger(
1465 com.android.internal.R.integer.config_burnInProtectionMaxRadius);
1466 }
1467 mBurnInProtectionHelper = new BurnInProtectionHelper(
1468 context, minHorizontal, maxHorizontal, minVertical, maxVertical, maxRadius);
Filip Gruszczynskicfb31852015-02-25 21:47:12 +00001469 }
Craig Mautner8a0da012014-05-31 15:13:37 -07001470
Jeff Brown70825162012-03-28 17:27:48 -07001471 mHandler = new PolicyHandler();
Jeff Browna20dda42014-05-27 20:57:24 -07001472 mWakeGestureListener = new MyWakeGestureListener(mContext, mHandler);
Craig Mautnereee29c42013-01-17 14:44:34 -08001473 mOrientationListener = new MyOrientationListener(mContext, mHandler);
Jeff Brownc0347aa2011-09-23 17:26:09 -07001474 try {
1475 mOrientationListener.setCurrentRotation(windowManager.getRotation());
1476 } catch (RemoteException ex) { }
Christopher Tate5e08af02012-09-21 17:17:22 -07001477 mSettingsObserver = new SettingsObserver(mHandler);
1478 mSettingsObserver.observe();
Svetoslav683914b2015-01-15 14:22:26 -08001479 mShortcutManager = new ShortcutManager(context);
Daniel Sandler6396c722013-04-16 20:19:09 -04001480 mUiMode = context.getResources().getInteger(
1481 com.android.internal.R.integer.config_defaultUiModeType);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001482 mHomeIntent = new Intent(Intent.ACTION_MAIN, null);
1483 mHomeIntent.addCategory(Intent.CATEGORY_HOME);
1484 mHomeIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK
1485 | Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED);
keunyounga7710492015-09-23 11:33:58 -07001486 mEnableCarDockHomeCapture = context.getResources().getBoolean(
1487 com.android.internal.R.bool.config_enableCarDockHomeLaunch);
Dianne Hackborn39c2d712009-09-22 11:41:31 -07001488 mCarDockIntent = new Intent(Intent.ACTION_MAIN, null);
1489 mCarDockIntent.addCategory(Intent.CATEGORY_CAR_DOCK);
1490 mCarDockIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK
1491 | Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED);
1492 mDeskDockIntent = new Intent(Intent.ACTION_MAIN, null);
1493 mDeskDockIntent.addCategory(Intent.CATEGORY_DESK_DOCK);
1494 mDeskDockIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK
1495 | Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED);
Jim Millere6ad1a82010-08-20 19:25:39 -07001496
Jeff Brown96307042012-07-27 15:51:34 -07001497 mPowerManager = (PowerManager)context.getSystemService(Context.POWER_SERVICE);
1498 mBroadcastWakeLock = mPowerManager.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK,
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001499 "PhoneWindowManager.mBroadcastWakeLock");
Jeff Brown13f00f02014-10-31 14:45:50 -07001500 mPowerKeyWakeLock = mPowerManager.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK,
1501 "PhoneWindowManager.mPowerKeyWakeLock");
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001502 mEnableShiftMenuBugReports = "1".equals(SystemProperties.get("ro.debuggable"));
Jeff Brownbcdfc622014-03-06 19:13:04 -08001503 mSupportAutoRotation = mContext.getResources().getBoolean(
1504 com.android.internal.R.bool.config_supportAutoRotation);
Dianne Hackborn2862fff2009-09-15 22:56:29 -07001505 mLidOpenRotation = readRotation(
Mike Lockwood2d1efbd2009-09-16 12:15:53 -04001506 com.android.internal.R.integer.config_lidOpenRotation);
1507 mCarDockRotation = readRotation(
1508 com.android.internal.R.integer.config_carDockRotation);
1509 mDeskDockRotation = readRotation(
1510 com.android.internal.R.integer.config_deskDockRotation);
Jeff Brownc82c89ed2013-04-17 17:18:15 -07001511 mUndockedHdmiRotation = readRotation(
1512 com.android.internal.R.integer.config_undockedHdmiRotation);
Mike Lockwoode9867d22009-09-20 01:59:02 -04001513 mCarDockEnablesAccelerometer = mContext.getResources().getBoolean(
1514 com.android.internal.R.bool.config_carDockEnablesAccelerometer);
1515 mDeskDockEnablesAccelerometer = mContext.getResources().getBoolean(
1516 com.android.internal.R.bool.config_deskDockEnablesAccelerometer);
Dianne Hackborn2862fff2009-09-15 22:56:29 -07001517 mLidKeyboardAccessibility = mContext.getResources().getInteger(
1518 com.android.internal.R.integer.config_lidKeyboardAccessibility);
1519 mLidNavigationAccessibility = mContext.getResources().getInteger(
1520 com.android.internal.R.integer.config_lidNavigationAccessibility);
Edward Savage-Jones7def60d2015-11-13 13:27:03 +01001521 mLidControlsScreenLock = mContext.getResources().getBoolean(
1522 com.android.internal.R.bool.config_lidControlsScreenLock);
Jeff Brownc458ce92012-04-30 14:58:40 -07001523 mLidControlsSleep = mContext.getResources().getBoolean(
1524 com.android.internal.R.bool.config_lidControlsSleep);
Daniel Sandlerdd73ee42013-10-11 22:19:59 -04001525 mTranslucentDecorEnabled = mContext.getResources().getBoolean(
1526 com.android.internal.R.bool.config_enableTranslucentDecor);
Bryce Lee584a4452014-10-21 15:55:55 -07001527
1528 mAllowTheaterModeWakeFromKey = mContext.getResources().getBoolean(
1529 com.android.internal.R.bool.config_allowTheaterModeWakeFromKey);
1530 mAllowTheaterModeWakeFromPowerKey = mAllowTheaterModeWakeFromKey
1531 || mContext.getResources().getBoolean(
1532 com.android.internal.R.bool.config_allowTheaterModeWakeFromPowerKey);
1533 mAllowTheaterModeWakeFromMotion = mContext.getResources().getBoolean(
1534 com.android.internal.R.bool.config_allowTheaterModeWakeFromMotion);
Bryce Lee812d7022014-11-10 13:33:28 -08001535 mAllowTheaterModeWakeFromMotionWhenNotDreaming = mContext.getResources().getBoolean(
1536 com.android.internal.R.bool.config_allowTheaterModeWakeFromMotionWhenNotDreaming);
Bryce Lee584a4452014-10-21 15:55:55 -07001537 mAllowTheaterModeWakeFromCameraLens = mContext.getResources().getBoolean(
1538 com.android.internal.R.bool.config_allowTheaterModeWakeFromCameraLens);
1539 mAllowTheaterModeWakeFromLidSwitch = mContext.getResources().getBoolean(
1540 com.android.internal.R.bool.config_allowTheaterModeWakeFromLidSwitch);
1541 mAllowTheaterModeWakeFromWakeGesture = mContext.getResources().getBoolean(
1542 com.android.internal.R.bool.config_allowTheaterModeWakeFromGesture);
1543
Bryce Lee55e846d2014-11-04 12:43:44 -08001544 mGoToSleepOnButtonPressTheaterMode = mContext.getResources().getBoolean(
1545 com.android.internal.R.bool.config_goToSleepOnButtonPressTheaterMode);
1546
Bryce Leed3b28402015-03-09 15:49:13 +00001547 mSupportLongPressPowerWhenNonInteractive = mContext.getResources().getBoolean(
1548 com.android.internal.R.bool.config_supportLongPressPowerWhenNonInteractive);
1549
Jeff Brown13f00f02014-10-31 14:45:50 -07001550 mShortPressOnPowerBehavior = mContext.getResources().getInteger(
1551 com.android.internal.R.integer.config_shortPressOnPowerBehavior);
1552 mLongPressOnPowerBehavior = mContext.getResources().getInteger(
1553 com.android.internal.R.integer.config_longPressOnPowerBehavior);
1554 mDoublePressOnPowerBehavior = mContext.getResources().getInteger(
1555 com.android.internal.R.integer.config_doublePressOnPowerBehavior);
1556 mTriplePressOnPowerBehavior = mContext.getResources().getInteger(
1557 com.android.internal.R.integer.config_triplePressOnPowerBehavior);
Filip Gruszczynskia483a1d2015-03-17 19:06:58 +00001558 mShortPressOnSleepBehavior = mContext.getResources().getInteger(
1559 com.android.internal.R.integer.config_shortPressOnSleepBehavior);
Jeff Brown13f00f02014-10-31 14:45:50 -07001560
John Spurlock61560172015-02-06 19:46:04 -05001561 mUseTvRouting = AudioSystem.getPlatformType(mContext) == AudioSystem.PLATFORM_TELEVISION;
RoboErik001c59c2015-01-26 15:53:51 -08001562
Jeff Brownf71343d2013-05-31 17:59:11 -07001563 readConfigurationDependentBehaviors();
Jeff Browncaca8812013-05-09 13:34:33 -07001564
Svetoslav8e3feb12014-02-24 13:46:47 -08001565 mAccessibilityManager = (AccessibilityManager) context.getSystemService(
1566 Context.ACCESSIBILITY_SERVICE);
1567
Mike Lockwood1753f7f2009-08-24 14:49:07 -07001568 // register for dock events
Dianne Hackborn78968392010-03-04 20:47:56 -08001569 IntentFilter filter = new IntentFilter();
1570 filter.addAction(UiModeManager.ACTION_ENTER_CAR_MODE);
1571 filter.addAction(UiModeManager.ACTION_EXIT_CAR_MODE);
1572 filter.addAction(UiModeManager.ACTION_ENTER_DESK_MODE);
1573 filter.addAction(UiModeManager.ACTION_EXIT_DESK_MODE);
Dianne Hackborn867ab6472010-04-29 13:28:56 -07001574 filter.addAction(Intent.ACTION_DOCK_EVENT);
1575 Intent intent = context.registerReceiver(mDockReceiver, filter);
1576 if (intent != null) {
1577 // Retrieve current sticky dock event broadcast.
1578 mDockMode = intent.getIntExtra(Intent.EXTRA_DOCK_STATE,
1579 Intent.EXTRA_DOCK_STATE_UNDOCKED);
1580 }
Daniel Sandler7e37df52011-11-16 22:08:23 -08001581
Jeff Brown6aaf2952012-10-05 16:01:08 -07001582 // register for dream-related broadcasts
1583 filter = new IntentFilter();
1584 filter.addAction(Intent.ACTION_DREAMING_STARTED);
1585 filter.addAction(Intent.ACTION_DREAMING_STOPPED);
1586 context.registerReceiver(mDreamReceiver, filter);
1587
Christopher Tate5e08af02012-09-21 17:17:22 -07001588 // register for multiuser-relevant broadcasts
1589 filter = new IntentFilter(Intent.ACTION_USER_SWITCHED);
1590 context.registerReceiver(mMultiuserReceiver, filter);
1591
John Spurlock57306e62013-04-22 09:48:49 -04001592 // monitor for system gestures
Craig Mautner037aa8d2013-06-07 10:35:44 -07001593 mSystemGestures = new SystemGesturesPointerEventListener(context,
1594 new SystemGesturesPointerEventListener.Callbacks() {
John Spurlock57306e62013-04-22 09:48:49 -04001595 @Override
1596 public void onSwipeFromTop() {
John Spurlock04db1762013-05-13 12:46:41 -04001597 if (mStatusBar != null) {
John Spurlocke1f366f2013-08-05 12:22:40 -04001598 requestTransientBars(mStatusBar);
John Spurlock04db1762013-05-13 12:46:41 -04001599 }
John Spurlockad3e6cb2013-04-30 08:47:43 -04001600 }
1601 @Override
1602 public void onSwipeFromBottom() {
John Spurlock04db1762013-05-13 12:46:41 -04001603 if (mNavigationBar != null && mNavigationBarOnBottom) {
John Spurlocke1f366f2013-08-05 12:22:40 -04001604 requestTransientBars(mNavigationBar);
John Spurlockad3e6cb2013-04-30 08:47:43 -04001605 }
1606 }
1607 @Override
1608 public void onSwipeFromRight() {
John Spurlock04db1762013-05-13 12:46:41 -04001609 if (mNavigationBar != null && !mNavigationBarOnBottom) {
John Spurlocke1f366f2013-08-05 12:22:40 -04001610 requestTransientBars(mNavigationBar);
John Spurlockad3e6cb2013-04-30 08:47:43 -04001611 }
1612 }
1613 @Override
Michael Wrighta4d22d72015-09-16 23:19:26 +01001614 public void onFling(int duration) {
1615 if (mPowerManagerInternal != null) {
1616 mPowerManagerInternal.powerHint(
1617 PowerManagerInternal.POWER_HINT_INTERACTION, duration);
1618 }
1619 }
1620 @Override
John Spurlockad3e6cb2013-04-30 08:47:43 -04001621 public void onDebug() {
John Spurlockd67ec252013-09-05 11:31:54 -04001622 // no-op
John Spurlockad3e6cb2013-04-30 08:47:43 -04001623 }
Adrian Roos3595be42015-03-05 16:31:15 +01001624 @Override
1625 public void onDown() {
1626 mOrientationListener.onTouchStart();
1627 }
1628 @Override
1629 public void onUpOrCancel() {
1630 mOrientationListener.onTouchEnd();
1631 }
Jun Mukaid2e7e352015-07-22 17:14:02 -07001632 @Override
1633 public void onMouseHoverAtTop() {
1634 mHandler.removeMessages(MSG_REQUEST_TRANSIENT_BARS);
1635 Message msg = mHandler.obtainMessage(MSG_REQUEST_TRANSIENT_BARS);
1636 msg.arg1 = MSG_REQUEST_TRANSIENT_BARS_ARG_STATUS;
1637 mHandler.sendMessageDelayed(msg, 500);
1638 }
1639 @Override
1640 public void onMouseHoverAtBottom() {
1641 mHandler.removeMessages(MSG_REQUEST_TRANSIENT_BARS);
1642 Message msg = mHandler.obtainMessage(MSG_REQUEST_TRANSIENT_BARS);
1643 msg.arg1 = MSG_REQUEST_TRANSIENT_BARS_ARG_NAVIGATION;
1644 mHandler.sendMessageDelayed(msg, 500);
1645 }
1646 @Override
1647 public void onMouseLeaveFromEdge() {
1648 mHandler.removeMessages(MSG_REQUEST_TRANSIENT_BARS);
1649 }
John Spurlockad3e6cb2013-04-30 08:47:43 -04001650 });
John Spurlockf1a36642013-10-12 17:50:42 -04001651 mImmersiveModeConfirmation = new ImmersiveModeConfirmation(mContext);
Craig Mautner037aa8d2013-06-07 10:35:44 -07001652 mWindowManagerFuncs.registerPointerEventListener(mSystemGestures);
John Spurlock32beb2c2013-03-11 10:16:47 -04001653
Jeff Brownc2346132012-04-13 01:55:38 -07001654 mVibrator = (Vibrator)context.getSystemService(Context.VIBRATOR_SERVICE);
Dianne Hackbornb1a79802009-09-29 15:18:31 -07001655 mLongPressVibePattern = getLongIntArray(mContext.getResources(),
1656 com.android.internal.R.array.config_longPressVibePattern);
1657 mVirtualKeyVibePattern = getLongIntArray(mContext.getResources(),
1658 com.android.internal.R.array.config_virtualKeyVibePattern);
Amith Yamasanic33cb712010-02-10 15:21:49 -08001659 mKeyboardTapVibePattern = getLongIntArray(mContext.getResources(),
1660 com.android.internal.R.array.config_keyboardTapVibePattern);
Fabrice Di Meglioeeff63a2013-08-05 12:07:24 -07001661 mClockTickVibePattern = getLongIntArray(mContext.getResources(),
1662 com.android.internal.R.array.config_clockTickVibePattern);
Fabrice Di Megliobd9152f2013-10-01 11:21:31 -07001663 mCalendarDateVibePattern = getLongIntArray(mContext.getResources(),
1664 com.android.internal.R.array.config_calendarDateVibePattern);
Dianne Hackbornb1a79802009-09-29 15:18:31 -07001665 mSafeModeDisabledVibePattern = getLongIntArray(mContext.getResources(),
1666 com.android.internal.R.array.config_safeModeDisabledVibePattern);
1667 mSafeModeEnabledVibePattern = getLongIntArray(mContext.getResources(),
1668 com.android.internal.R.array.config_safeModeEnabledVibePattern);
Mady Mellore8608912015-06-05 09:02:55 -07001669 mContextClickVibePattern = getLongIntArray(mContext.getResources(),
1670 com.android.internal.R.array.config_contextClickVibePattern);
Daniel Sandler40427442010-07-16 11:44:52 -04001671
Christopher Tatee90585f2012-03-05 18:56:25 -08001672 mScreenshotChordEnabled = mContext.getResources().getBoolean(
1673 com.android.internal.R.bool.config_enableScreenshotChord);
Jorim Jaggi406585a2015-12-21 10:58:56 +01001674 mForceWindowDrawsStatusBarBackground = mContext.getResources().getBoolean(
1675 R.bool.config_forceWindowDrawsStatusBarBackground);
Christopher Tatee90585f2012-03-05 18:56:25 -08001676
Justin Kohd378ad72013-04-01 12:18:26 -07001677 mGlobalKeyManager = new GlobalKeyManager(mContext);
1678
Joe Onoratoea495d42011-04-06 11:41:11 -07001679 // Controls rotation and the like.
1680 initializeHdmiState();
Dianne Hackborn40011092011-09-22 13:37:48 -07001681
1682 // Match current screen state.
Craig Mautnera631d492014-08-05 15:16:01 -07001683 if (!mPowerManager.isInteractive()) {
Jeff Brown416c49c2015-05-26 19:50:18 -07001684 startedGoingToSleep(WindowManagerPolicy.OFF_BECAUSE_OF_USER);
1685 finishedGoingToSleep(WindowManagerPolicy.OFF_BECAUSE_OF_USER);
Dianne Hackborn40011092011-09-22 13:37:48 -07001686 }
Jorim Jaggi24bec7c2015-02-04 12:40:14 +01001687
1688 mWindowManagerInternal.registerAppTransitionListener(
1689 mStatusBarController.getAppTransitionListener());
Mike Lockwood1753f7f2009-08-24 14:49:07 -07001690 }
1691
Jeff Brownf71343d2013-05-31 17:59:11 -07001692 /**
1693 * Read values from config.xml that may be overridden depending on
1694 * the configuration of the device.
1695 * eg. Disable long press on home goes to recents on sw600dp.
1696 */
1697 private void readConfigurationDependentBehaviors() {
Jaewan Kimc552b042016-01-18 16:08:45 +09001698 final Resources res = mContext.getResources();
1699
1700 mLongPressOnHomeBehavior = res.getInteger(
Jeff Brownf71343d2013-05-31 17:59:11 -07001701 com.android.internal.R.integer.config_longPressOnHomeBehavior);
1702 if (mLongPressOnHomeBehavior < LONG_PRESS_HOME_NOTHING ||
Jaewan Kim52632e22016-01-14 18:01:52 +09001703 mLongPressOnHomeBehavior > LAST_LONG_PRESS_HOME_BEHAVIOR) {
Jeff Brownf71343d2013-05-31 17:59:11 -07001704 mLongPressOnHomeBehavior = LONG_PRESS_HOME_NOTHING;
1705 }
1706
Jaewan Kimc552b042016-01-18 16:08:45 +09001707 mDoubleTapOnHomeBehavior = res.getInteger(
Jeff Brownf71343d2013-05-31 17:59:11 -07001708 com.android.internal.R.integer.config_doubleTapOnHomeBehavior);
1709 if (mDoubleTapOnHomeBehavior < DOUBLE_TAP_HOME_NOTHING ||
1710 mDoubleTapOnHomeBehavior > DOUBLE_TAP_HOME_RECENT_SYSTEM_UI) {
1711 mDoubleTapOnHomeBehavior = LONG_PRESS_HOME_NOTHING;
1712 }
Jaewan Kim49117872016-01-19 17:24:08 +09001713
1714 mShortPressWindowBehavior = SHORT_PRESS_WINDOW_NOTHING;
1715 if (mContext.getPackageManager().hasSystemFeature(FEATURE_PICTURE_IN_PICTURE)) {
1716 mShortPressWindowBehavior = SHORT_PRESS_WINDOW_PICTURE_IN_PICTURE;
1717 }
Jeff Brownf71343d2013-05-31 17:59:11 -07001718 }
1719
Craig Mautner0bf6ec92012-12-18 08:33:27 -08001720 @Override
Dianne Hackborndde331c2012-08-03 14:01:57 -07001721 public void setInitialDisplaySize(Display display, int width, int height, int density) {
Jeff Brownef981a42013-08-07 14:13:37 -07001722 // This method might be called before the policy has been fully initialized
1723 // or for other displays we don't care about.
1724 if (mContext == null || display.getDisplayId() != Display.DEFAULT_DISPLAY) {
1725 return;
Dianne Hackbornc652de82013-02-15 16:32:56 -08001726 }
Dianne Hackbornf87d1962012-04-04 12:48:24 -07001727 mDisplay = display;
1728
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001729 final Resources res = mContext.getResources();
Dianne Hackbornf87d1962012-04-04 12:48:24 -07001730 int shortSize, longSize;
Dianne Hackborn9d132642011-04-21 17:26:39 -07001731 if (width > height) {
Dianne Hackborn81e56d52011-05-26 00:55:58 -07001732 shortSize = height;
Dianne Hackbornf87d1962012-04-04 12:48:24 -07001733 longSize = width;
Dianne Hackborn9d132642011-04-21 17:26:39 -07001734 mLandscapeRotation = Surface.ROTATION_0;
1735 mSeascapeRotation = Surface.ROTATION_180;
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001736 if (res.getBoolean(com.android.internal.R.bool.config_reverseDefaultRotation)) {
Dianne Hackborn9d132642011-04-21 17:26:39 -07001737 mPortraitRotation = Surface.ROTATION_90;
1738 mUpsideDownRotation = Surface.ROTATION_270;
1739 } else {
1740 mPortraitRotation = Surface.ROTATION_270;
1741 mUpsideDownRotation = Surface.ROTATION_90;
1742 }
1743 } else {
Dianne Hackborn81e56d52011-05-26 00:55:58 -07001744 shortSize = width;
Dianne Hackbornf87d1962012-04-04 12:48:24 -07001745 longSize = height;
Dianne Hackborn9d132642011-04-21 17:26:39 -07001746 mPortraitRotation = Surface.ROTATION_0;
1747 mUpsideDownRotation = Surface.ROTATION_180;
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001748 if (res.getBoolean(com.android.internal.R.bool.config_reverseDefaultRotation)) {
Dianne Hackborn9d132642011-04-21 17:26:39 -07001749 mLandscapeRotation = Surface.ROTATION_270;
1750 mSeascapeRotation = Surface.ROTATION_90;
1751 } else {
1752 mLandscapeRotation = Surface.ROTATION_90;
1753 mSeascapeRotation = Surface.ROTATION_270;
1754 }
1755 }
Dianne Hackborn81e56d52011-05-26 00:55:58 -07001756
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001757 mStatusBarHeight =
1758 res.getDimensionPixelSize(com.android.internal.R.dimen.status_bar_height);
Dianne Hackbornf87d1962012-04-04 12:48:24 -07001759
Daniel Sandler9f65c4c2012-04-26 01:35:35 -04001760 // Height of the navigation bar when presented horizontally at bottom
Sriram Viswanathan9ebbe6a2015-11-16 17:59:22 -08001761 mNavigationBarHeightForRotationDefault[mPortraitRotation] =
1762 mNavigationBarHeightForRotationDefault[mUpsideDownRotation] =
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001763 res.getDimensionPixelSize(com.android.internal.R.dimen.navigation_bar_height);
Sriram Viswanathan9ebbe6a2015-11-16 17:59:22 -08001764 mNavigationBarHeightForRotationDefault[mLandscapeRotation] =
1765 mNavigationBarHeightForRotationDefault[mSeascapeRotation] = res.getDimensionPixelSize(
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001766 com.android.internal.R.dimen.navigation_bar_height_landscape);
Daniel Sandler9f65c4c2012-04-26 01:35:35 -04001767
1768 // Width of the navigation bar when presented vertically along one side
Sriram Viswanathan9ebbe6a2015-11-16 17:59:22 -08001769 mNavigationBarWidthForRotationDefault[mPortraitRotation] =
1770 mNavigationBarWidthForRotationDefault[mUpsideDownRotation] =
1771 mNavigationBarWidthForRotationDefault[mLandscapeRotation] =
1772 mNavigationBarWidthForRotationDefault[mSeascapeRotation] =
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001773 res.getDimensionPixelSize(com.android.internal.R.dimen.navigation_bar_width);
Daniel Sandler4a066c52012-04-20 14:49:13 -04001774
Sriram Viswanathan9ebbe6a2015-11-16 17:59:22 -08001775 // Height of the navigation bar when presented horizontally at bottom
1776 mNavigationBarHeightForRotationInCarMode[mPortraitRotation] =
1777 mNavigationBarHeightForRotationInCarMode[mUpsideDownRotation] =
1778 res.getDimensionPixelSize(
1779 com.android.internal.R.dimen.navigation_bar_height_car_mode);
1780 mNavigationBarHeightForRotationInCarMode[mLandscapeRotation] =
1781 mNavigationBarHeightForRotationInCarMode[mSeascapeRotation] = res.getDimensionPixelSize(
1782 com.android.internal.R.dimen.navigation_bar_height_landscape_car_mode);
1783
1784 // Width of the navigation bar when presented vertically along one side
1785 mNavigationBarWidthForRotationInCarMode[mPortraitRotation] =
1786 mNavigationBarWidthForRotationInCarMode[mUpsideDownRotation] =
1787 mNavigationBarWidthForRotationInCarMode[mLandscapeRotation] =
1788 mNavigationBarWidthForRotationInCarMode[mSeascapeRotation] =
1789 res.getDimensionPixelSize(
1790 com.android.internal.R.dimen.navigation_bar_width_car_mode);
1791
Daniel Sandler4a066c52012-04-20 14:49:13 -04001792 // SystemUI (status bar) layout policy
Dianne Hackborndde331c2012-08-03 14:01:57 -07001793 int shortSizeDp = shortSize * DisplayMetrics.DENSITY_DEFAULT / density;
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001794 int longSizeDp = longSize * DisplayMetrics.DENSITY_DEFAULT / density;
Daniel Sandler4a066c52012-04-20 14:49:13 -04001795
Devin Kimd7b12b42014-05-05 14:34:58 -07001796 // Allow the navigation bar to move on non-square small devices (phones).
1797 mNavigationBarCanMove = width != height && shortSizeDp < 600;
Daniel Sandler36412a72011-08-04 09:35:13 -04001798
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001799 mHasNavigationBar = res.getBoolean(com.android.internal.R.bool.config_showNavigationBar);
John Spurlock80f00c12013-06-13 11:10:51 -04001800 // Allow a system property to override this. Used by the emulator.
1801 // See also hasNavigationBar().
1802 String navBarOverride = SystemProperties.get("qemu.hw.mainkeys");
1803 if ("1".equals(navBarOverride)) {
Dianne Hackbornf87d1962012-04-04 12:48:24 -07001804 mHasNavigationBar = false;
John Spurlock80f00c12013-06-13 11:10:51 -04001805 } else if ("0".equals(navBarOverride)) {
1806 mHasNavigationBar = true;
Daniel Sandler0c4ccff2011-10-19 16:39:14 -04001807 }
1808
Jeff Brown27f1d672012-10-17 18:32:34 -07001809 // For demo purposes, allow the rotation of the HDMI display to be controlled.
1810 // By default, HDMI locks rotation to landscape.
Erik Gilling9a41ef82011-09-26 19:21:03 -07001811 if ("portrait".equals(SystemProperties.get("persist.demo.hdmirotation"))) {
Jeff Brownc82c89ed2013-04-17 17:18:15 -07001812 mDemoHdmiRotation = mPortraitRotation;
Erik Gilling9a41ef82011-09-26 19:21:03 -07001813 } else {
Jeff Brownc82c89ed2013-04-17 17:18:15 -07001814 mDemoHdmiRotation = mLandscapeRotation;
Erik Gilling9a41ef82011-09-26 19:21:03 -07001815 }
Jeff Brownc82c89ed2013-04-17 17:18:15 -07001816 mDemoHdmiRotationLock = SystemProperties.getBoolean("persist.demo.hdmirotationlock", false);
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001817
Chong Zhangae6119ff2014-11-11 18:54:39 -08001818 // For demo purposes, allow the rotation of the remote display to be controlled.
1819 // By default, remote display locks rotation to landscape.
1820 if ("portrait".equals(SystemProperties.get("persist.demo.remoterotation"))) {
1821 mDemoRotation = mPortraitRotation;
1822 } else {
1823 mDemoRotation = mLandscapeRotation;
1824 }
1825 mDemoRotationLock = SystemProperties.getBoolean(
1826 "persist.demo.rotationlock", false);
1827
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001828 // Only force the default orientation if the screen is xlarge, at least 960dp x 720dp, per
1829 // http://developer.android.com/guide/practices/screens_support.html#range
1830 mForceDefaultOrientation = longSizeDp >= 960 && shortSizeDp >= 720 &&
1831 res.getBoolean(com.android.internal.R.bool.config_forceDefaultOrientation) &&
1832 // For debug purposes the next line turns this feature off with:
1833 // $ adb shell setprop config.override_forced_orient true
1834 // $ adb shell wm size reset
1835 !"true".equals(SystemProperties.get("config.override_forced_orient"));
1836 }
1837
Alan Viverette5a0f4ec2013-10-07 15:10:29 -07001838 /**
1839 * @return whether the navigation bar can be hidden, e.g. the device has a
1840 * navigation bar and touch exploration is not enabled
1841 */
1842 private boolean canHideNavigationBar() {
Alan Viverette817f3cd2015-08-13 11:40:14 -04001843 return mHasNavigationBar;
Alan Viverette5a0f4ec2013-10-07 15:10:29 -07001844 }
1845
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001846 @Override
1847 public boolean isDefaultOrientationForced() {
1848 return mForceDefaultOrientation;
Dianne Hackborn9d132642011-04-21 17:26:39 -07001849 }
1850
Dianne Hackbornc652de82013-02-15 16:32:56 -08001851 @Override
1852 public void setDisplayOverscan(Display display, int left, int top, int right, int bottom) {
1853 if (display.getDisplayId() == Display.DEFAULT_DISPLAY) {
1854 mOverscanLeft = left;
1855 mOverscanTop = top;
1856 mOverscanRight = right;
1857 mOverscanBottom = bottom;
1858 }
1859 }
1860
Dianne Hackbornc777e072010-02-12 13:07:59 -08001861 public void updateSettings() {
1862 ContentResolver resolver = mContext.getContentResolver();
1863 boolean updateRotation = false;
Dianne Hackbornc777e072010-02-12 13:07:59 -08001864 synchronized (mLock) {
Christopher Tate5e08af02012-09-21 17:17:22 -07001865 mEndcallBehavior = Settings.System.getIntForUser(resolver,
David Brownbaf8d092010-03-08 21:52:59 -08001866 Settings.System.END_BUTTON_BEHAVIOR,
Christopher Tate5e08af02012-09-21 17:17:22 -07001867 Settings.System.END_BUTTON_BEHAVIOR_DEFAULT,
1868 UserHandle.USER_CURRENT);
1869 mIncallPowerBehavior = Settings.Secure.getIntForUser(resolver,
David Brownbaf8d092010-03-08 21:52:59 -08001870 Settings.Secure.INCALL_POWER_BUTTON_BEHAVIOR,
Christopher Tate5e08af02012-09-21 17:17:22 -07001871 Settings.Secure.INCALL_POWER_BUTTON_BEHAVIOR_DEFAULT,
1872 UserHandle.USER_CURRENT);
Daniel Sandlerb73617d2010-08-17 00:41:00 -04001873
Jeff Browna20dda42014-05-27 20:57:24 -07001874 // Configure wake gesture.
1875 boolean wakeGestureEnabledSetting = Settings.Secure.getIntForUser(resolver,
1876 Settings.Secure.WAKE_GESTURE_ENABLED, 0,
1877 UserHandle.USER_CURRENT) != 0;
1878 if (mWakeGestureEnabledSetting != wakeGestureEnabledSetting) {
1879 mWakeGestureEnabledSetting = wakeGestureEnabledSetting;
1880 updateWakeGestureListenerLp();
1881 }
1882
Jeff Brown207673cd2012-06-05 17:47:11 -07001883 // Configure rotation lock.
Christopher Tate5e08af02012-09-21 17:17:22 -07001884 int userRotation = Settings.System.getIntForUser(resolver,
1885 Settings.System.USER_ROTATION, Surface.ROTATION_0,
1886 UserHandle.USER_CURRENT);
Jeff Brown207673cd2012-06-05 17:47:11 -07001887 if (mUserRotation != userRotation) {
1888 mUserRotation = userRotation;
1889 updateRotation = true;
1890 }
Christopher Tate5e08af02012-09-21 17:17:22 -07001891 int userRotationMode = Settings.System.getIntForUser(resolver,
1892 Settings.System.ACCELEROMETER_ROTATION, 0, UserHandle.USER_CURRENT) != 0 ?
Jeff Brown207673cd2012-06-05 17:47:11 -07001893 WindowManagerPolicy.USER_ROTATION_FREE :
1894 WindowManagerPolicy.USER_ROTATION_LOCKED;
1895 if (mUserRotationMode != userRotationMode) {
1896 mUserRotationMode = userRotationMode;
1897 updateRotation = true;
Dianne Hackbornc777e072010-02-12 13:07:59 -08001898 updateOrientationListenerLp();
1899 }
Daniel Sandlerb73617d2010-08-17 00:41:00 -04001900
Dianne Hackbornc777e072010-02-12 13:07:59 -08001901 if (mSystemReady) {
Christopher Tate5e08af02012-09-21 17:17:22 -07001902 int pointerLocation = Settings.System.getIntForUser(resolver,
1903 Settings.System.POINTER_LOCATION, 0, UserHandle.USER_CURRENT);
Dianne Hackbornc777e072010-02-12 13:07:59 -08001904 if (mPointerLocationMode != pointerLocation) {
1905 mPointerLocationMode = pointerLocation;
Jeff Brown70825162012-03-28 17:27:48 -07001906 mHandler.sendEmptyMessage(pointerLocation != 0 ?
1907 MSG_ENABLE_POINTER_LOCATION : MSG_DISABLE_POINTER_LOCATION);
Dianne Hackbornc777e072010-02-12 13:07:59 -08001908 }
1909 }
1910 // use screen off timeout setting as the timeout for the lockscreen
Christopher Tate5e08af02012-09-21 17:17:22 -07001911 mLockScreenTimeout = Settings.System.getIntForUser(resolver,
1912 Settings.System.SCREEN_OFF_TIMEOUT, 0, UserHandle.USER_CURRENT);
1913 String imId = Settings.Secure.getStringForUser(resolver,
1914 Settings.Secure.DEFAULT_INPUT_METHOD, UserHandle.USER_CURRENT);
Dianne Hackbornc777e072010-02-12 13:07:59 -08001915 boolean hasSoftInput = imId != null && imId.length() > 0;
1916 if (mHasSoftInput != hasSoftInput) {
1917 mHasSoftInput = hasSoftInput;
1918 updateRotation = true;
1919 }
John Spurlockf1a36642013-10-12 17:50:42 -04001920 if (mImmersiveModeConfirmation != null) {
John Spurlock4355a532014-02-19 09:49:25 -05001921 mImmersiveModeConfirmation.loadSetting(mCurrentUserId);
John Spurlockd67ec252013-09-05 11:31:54 -04001922 }
tiger_huangcc6366d2015-06-29 17:17:30 +08001923 }
1924 synchronized (mWindowManagerFuncs.getWindowManagerLock()) {
John Spurlockc6d1c602014-01-17 15:22:06 -05001925 PolicyControl.reloadFromSetting(mContext);
Dianne Hackbornc777e072010-02-12 13:07:59 -08001926 }
1927 if (updateRotation) {
Jeff Brown01a98dd2011-09-20 15:08:29 -07001928 updateRotation(true);
Dianne Hackbornc777e072010-02-12 13:07:59 -08001929 }
Jeff Brown70825162012-03-28 17:27:48 -07001930 }
1931
Jeff Browna20dda42014-05-27 20:57:24 -07001932 private void updateWakeGestureListenerLp() {
1933 if (shouldEnableWakeGestureLp()) {
1934 mWakeGestureListener.requestWakeUpTrigger();
1935 } else {
1936 mWakeGestureListener.cancelWakeUpTrigger();
1937 }
1938 }
1939
1940 private boolean shouldEnableWakeGestureLp() {
Jeff Brown3ee549c2014-09-22 20:14:39 -07001941 return mWakeGestureEnabledSetting && !mAwake
Jeff Browna20dda42014-05-27 20:57:24 -07001942 && (!mLidControlsSleep || mLidState != LID_CLOSED)
1943 && mWakeGestureListener.isSupported();
1944 }
1945
Jeff Brown70825162012-03-28 17:27:48 -07001946 private void enablePointerLocation() {
1947 if (mPointerLocationView == null) {
1948 mPointerLocationView = new PointerLocationView(mContext);
1949 mPointerLocationView.setPrintCoords(false);
Dianne Hackbornc777e072010-02-12 13:07:59 -08001950 WindowManager.LayoutParams lp = new WindowManager.LayoutParams(
1951 WindowManager.LayoutParams.MATCH_PARENT,
1952 WindowManager.LayoutParams.MATCH_PARENT);
Jeff Brown3b2b3542010-10-15 00:54:27 -07001953 lp.type = WindowManager.LayoutParams.TYPE_SECURE_SYSTEM_OVERLAY;
Jeff Brownbfcb60a2011-09-08 18:51:14 -07001954 lp.flags = WindowManager.LayoutParams.FLAG_FULLSCREEN
1955 | WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE
1956 | WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE
1957 | WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN;
Jeff Brown90fc9052012-10-01 14:44:24 -07001958 if (ActivityManager.isHighEndGfx()) {
1959 lp.flags |= WindowManager.LayoutParams.FLAG_HARDWARE_ACCELERATED;
1960 lp.privateFlags |=
1961 WindowManager.LayoutParams.PRIVATE_FLAG_FORCE_HARDWARE_ACCELERATED;
1962 }
Dianne Hackbornc777e072010-02-12 13:07:59 -08001963 lp.format = PixelFormat.TRANSLUCENT;
1964 lp.setTitle("PointerLocation");
Dianne Hackborn5fd21692011-06-07 14:09:47 -07001965 WindowManager wm = (WindowManager)
Dianne Hackbornc777e072010-02-12 13:07:59 -08001966 mContext.getSystemService(Context.WINDOW_SERVICE);
Jeff Browncc4f7db2011-08-30 20:34:48 -07001967 lp.inputFeatures |= WindowManager.LayoutParams.INPUT_FEATURE_NO_INPUT_CHANNEL;
Jeff Brown70825162012-03-28 17:27:48 -07001968 wm.addView(mPointerLocationView, lp);
Michael Wrightc9c487e2013-11-07 18:55:09 -08001969 mWindowManagerFuncs.registerPointerEventListener(mPointerLocationView);
Dianne Hackbornc777e072010-02-12 13:07:59 -08001970 }
Dianne Hackbornc777e072010-02-12 13:07:59 -08001971 }
Jeff Brown70825162012-03-28 17:27:48 -07001972
1973 private void disablePointerLocation() {
Jeff Brown70825162012-03-28 17:27:48 -07001974 if (mPointerLocationView != null) {
Michael Wrightc9c487e2013-11-07 18:55:09 -08001975 mWindowManagerFuncs.unregisterPointerEventListener(mPointerLocationView);
1976 WindowManager wm = (WindowManager) mContext.getSystemService(Context.WINDOW_SERVICE);
Jeff Brown70825162012-03-28 17:27:48 -07001977 wm.removeView(mPointerLocationView);
1978 mPointerLocationView = null;
1979 }
1980 }
1981
Mike Lockwood2d1efbd2009-09-16 12:15:53 -04001982 private int readRotation(int resID) {
Mike Lockwood1753f7f2009-08-24 14:49:07 -07001983 try {
1984 int rotation = mContext.getResources().getInteger(resID);
1985 switch (rotation) {
1986 case 0:
1987 return Surface.ROTATION_0;
1988 case 90:
1989 return Surface.ROTATION_90;
1990 case 180:
1991 return Surface.ROTATION_180;
1992 case 270:
1993 return Surface.ROTATION_270;
Mike Lockwood1753f7f2009-08-24 14:49:07 -07001994 }
1995 } catch (Resources.NotFoundException e) {
Mike Lockwood2d1efbd2009-09-16 12:15:53 -04001996 // fall through
Mike Lockwood1753f7f2009-08-24 14:49:07 -07001997 }
Mike Lockwood2d1efbd2009-09-16 12:15:53 -04001998 return -1;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001999 }
2000
2001 /** {@inheritDoc} */
Craig Mautner88400d32012-09-30 12:35:45 -07002002 @Override
Dianne Hackbornc2293022013-02-06 23:14:49 -08002003 public int checkAddPermission(WindowManager.LayoutParams attrs, int[] outAppOp) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002004 int type = attrs.type;
Dianne Hackbornc2293022013-02-06 23:14:49 -08002005
2006 outAppOp[0] = AppOpsManager.OP_NONE;
2007
Wale Ogunwale74bf0652015-01-12 10:24:36 -08002008 if (!((type >= FIRST_APPLICATION_WINDOW && type <= LAST_APPLICATION_WINDOW)
2009 || (type >= FIRST_SUB_WINDOW && type <= LAST_SUB_WINDOW)
2010 || (type >= FIRST_SYSTEM_WINDOW && type <= LAST_SYSTEM_WINDOW))) {
2011 return WindowManagerGlobal.ADD_INVALID_TYPE;
2012 }
2013
2014 if (type < FIRST_SYSTEM_WINDOW || type > LAST_SYSTEM_WINDOW) {
2015 // Window manager will make sure these are okay.
Jeff Brown98365d72012-08-19 20:30:52 -07002016 return WindowManagerGlobal.ADD_OKAY;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002017 }
2018 String permission = null;
2019 switch (type) {
2020 case TYPE_TOAST:
2021 // XXX right now the app process has complete control over
2022 // this... should introduce a token to let the system
2023 // monitor/control what they are doing.
Jason Monk1c7c3192014-06-26 12:52:18 -04002024 outAppOp[0] = AppOpsManager.OP_TOAST_WINDOW;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002025 break;
Daniel Sandler7d276c32012-01-30 14:33:52 -05002026 case TYPE_DREAM:
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002027 case TYPE_INPUT_METHOD:
Dianne Hackbornb7cd8b92009-08-08 20:53:03 -07002028 case TYPE_WALLPAPER:
keunyounga446bf02013-06-21 19:07:57 -07002029 case TYPE_PRIVATE_PRESENTATION:
Dianne Hackborne30e02f2014-05-27 18:24:45 -07002030 case TYPE_VOICE_INTERACTION:
Svetoslav3a5c7212014-10-14 09:54:26 -07002031 case TYPE_ACCESSIBILITY_OVERLAY:
Jason Monk8f7f3182015-11-18 16:35:14 -05002032 case TYPE_QS_DIALOG:
Dianne Hackbornb7cd8b92009-08-08 20:53:03 -07002033 // The window manager will check these.
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002034 break;
2035 case TYPE_PHONE:
2036 case TYPE_PRIORITY_PHONE:
2037 case TYPE_SYSTEM_ALERT:
2038 case TYPE_SYSTEM_ERROR:
2039 case TYPE_SYSTEM_OVERLAY:
2040 permission = android.Manifest.permission.SYSTEM_ALERT_WINDOW;
Dianne Hackbornc2293022013-02-06 23:14:49 -08002041 outAppOp[0] = AppOpsManager.OP_SYSTEM_ALERT_WINDOW;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002042 break;
2043 default:
2044 permission = android.Manifest.permission.INTERNAL_SYSTEM_WINDOW;
2045 }
2046 if (permission != null) {
Svet Ganov9cea80cd2016-02-16 11:47:00 -08002047 if (android.Manifest.permission.SYSTEM_ALERT_WINDOW.equals(permission)) {
Billy Laucbe540f2015-06-25 01:51:44 +01002048 final int callingUid = Binder.getCallingUid();
Billy Lau060275f2015-07-15 22:29:19 +01002049 // system processes will be automatically allowed privilege to draw
Billy Laucbe540f2015-06-25 01:51:44 +01002050 if (callingUid == Process.SYSTEM_UID) {
2051 return WindowManagerGlobal.ADD_OKAY;
2052 }
2053
Billy Lau060275f2015-07-15 22:29:19 +01002054 // check if user has enabled this operation. SecurityException will be thrown if
2055 // this app has not been allowed by the user
Billy Laucbe540f2015-06-25 01:51:44 +01002056 final int mode = mAppOpsManager.checkOp(outAppOp[0], callingUid,
2057 attrs.packageName);
Billy Lau060275f2015-07-15 22:29:19 +01002058 switch (mode) {
2059 case AppOpsManager.MODE_ALLOWED:
2060 case AppOpsManager.MODE_IGNORED:
2061 // although we return ADD_OKAY for MODE_IGNORED, the added window will
2062 // actually be hidden in WindowManagerService
2063 return WindowManagerGlobal.ADD_OKAY;
2064 case AppOpsManager.MODE_ERRORED:
Billy Laucbe540f2015-06-25 01:51:44 +01002065 return WindowManagerGlobal.ADD_PERMISSION_DENIED;
Billy Lau060275f2015-07-15 22:29:19 +01002066 default:
2067 // in the default mode, we will make a decision here based on
2068 // checkCallingPermission()
2069 if (mContext.checkCallingPermission(permission) !=
2070 PackageManager.PERMISSION_GRANTED) {
2071 return WindowManagerGlobal.ADD_PERMISSION_DENIED;
2072 } else {
2073 return WindowManagerGlobal.ADD_OKAY;
2074 }
Billy Laucbe540f2015-06-25 01:51:44 +01002075 }
Billy Laucbe540f2015-06-25 01:51:44 +01002076 }
2077
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002078 if (mContext.checkCallingOrSelfPermission(permission)
2079 != PackageManager.PERMISSION_GRANTED) {
Jeff Brown98365d72012-08-19 20:30:52 -07002080 return WindowManagerGlobal.ADD_PERMISSION_DENIED;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002081 }
2082 }
Jeff Brown98365d72012-08-19 20:30:52 -07002083 return WindowManagerGlobal.ADD_OKAY;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002084 }
Craig Mautner88400d32012-09-30 12:35:45 -07002085
2086 @Override
2087 public boolean checkShowToOwnerOnly(WindowManager.LayoutParams attrs) {
2088
2089 // If this switch statement is modified, modify the comment in the declarations of
2090 // the type in {@link WindowManager.LayoutParams} as well.
2091 switch (attrs.type) {
2092 default:
2093 // These are the windows that by default are shown only to the user that created
2094 // them. If this needs to be overridden, set
2095 // {@link WindowManager.LayoutParams.PRIVATE_FLAG_SHOW_FOR_ALL_USERS} in
2096 // {@link WindowManager.LayoutParams}. Note that permission
2097 // {@link android.Manifest.permission.INTERNAL_SYSTEM_WINDOW} is required as well.
2098 if ((attrs.privateFlags & PRIVATE_FLAG_SHOW_FOR_ALL_USERS) == 0) {
2099 return true;
2100 }
2101 break;
2102
2103 // These are the windows that by default are shown to all users. However, to
2104 // protect against spoofing, check permissions below.
2105 case TYPE_APPLICATION_STARTING:
2106 case TYPE_BOOT_PROGRESS:
2107 case TYPE_DISPLAY_OVERLAY:
Selim Cinekf83e8242015-05-19 18:08:14 -07002108 case TYPE_INPUT_CONSUMER:
Jim Miller5ecd8112013-01-09 18:50:26 -08002109 case TYPE_KEYGUARD_SCRIM:
Craig Mautner88400d32012-09-30 12:35:45 -07002110 case TYPE_KEYGUARD_DIALOG:
2111 case TYPE_MAGNIFICATION_OVERLAY:
2112 case TYPE_NAVIGATION_BAR:
2113 case TYPE_NAVIGATION_BAR_PANEL:
2114 case TYPE_PHONE:
2115 case TYPE_POINTER:
2116 case TYPE_PRIORITY_PHONE:
Craig Mautner88400d32012-09-30 12:35:45 -07002117 case TYPE_SEARCH_BAR:
2118 case TYPE_STATUS_BAR:
2119 case TYPE_STATUS_BAR_PANEL:
2120 case TYPE_STATUS_BAR_SUB_PANEL:
2121 case TYPE_SYSTEM_DIALOG:
Craig Mautner88400d32012-09-30 12:35:45 -07002122 case TYPE_VOLUME_OVERLAY:
keunyounga446bf02013-06-21 19:07:57 -07002123 case TYPE_PRIVATE_PRESENTATION:
Filip Gruszczynski466f3212015-09-21 17:57:57 -07002124 case TYPE_DOCK_DIVIDER:
Craig Mautner88400d32012-09-30 12:35:45 -07002125 break;
2126 }
2127
2128 // Check if third party app has set window to system window type.
2129 return mContext.checkCallingOrSelfPermission(
2130 android.Manifest.permission.INTERNAL_SYSTEM_WINDOW)
2131 != PackageManager.PERMISSION_GRANTED;
2132 }
2133
Craig Mautner967212c2013-04-13 21:10:58 -07002134 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002135 public void adjustWindowParamsLw(WindowManager.LayoutParams attrs) {
2136 switch (attrs.type) {
2137 case TYPE_SYSTEM_OVERLAY:
Jeff Brown3b2b3542010-10-15 00:54:27 -07002138 case TYPE_SECURE_SYSTEM_OVERLAY:
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002139 // These types of windows can't receive input events.
2140 attrs.flags |= WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE
2141 | WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE;
Jeff Brownbfcb60a2011-09-08 18:51:14 -07002142 attrs.flags &= ~WindowManager.LayoutParams.FLAG_WATCH_OUTSIDE_TOUCH;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002143 break;
Jorim Jaggi380ecb82014-03-14 17:25:20 +01002144 case TYPE_STATUS_BAR:
2145
2146 // If the Keyguard is in a hidden state (occluded by another window), we force to
2147 // remove the wallpaper and keyguard flag so that any change in-flight after setting
2148 // the keyguard as occluded wouldn't set these flags again.
2149 // See {@link #processKeyguardSetHiddenResultLw}.
2150 if (mKeyguardHidden) {
2151 attrs.flags &= ~WindowManager.LayoutParams.FLAG_SHOW_WALLPAPER;
2152 attrs.privateFlags &= ~WindowManager.LayoutParams.PRIVATE_FLAG_KEYGUARD;
2153 }
2154 break;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002155 }
Adrian Roos38502112014-04-09 21:04:11 +02002156
2157 if (attrs.type != TYPE_STATUS_BAR) {
2158 // The status bar is the only window allowed to exhibit keyguard behavior.
2159 attrs.privateFlags &= ~WindowManager.LayoutParams.PRIVATE_FLAG_KEYGUARD;
2160 }
Adrian Roosea562512014-05-05 13:33:03 +02002161
Jorim Jaggi4fa78922015-11-30 17:13:56 -08002162 if (ActivityManager.isHighEndGfx()) {
2163 if ((attrs.flags & FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS) != 0) {
2164 attrs.subtreeSystemUiVisibility |= View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION;
2165 }
2166 if ((attrs.flags & FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS) != 0
Jorim Jaggi406585a2015-12-21 10:58:56 +01002167 || (mForceWindowDrawsStatusBarBackground
2168 && attrs.height == MATCH_PARENT && attrs.width == MATCH_PARENT)) {
Jorim Jaggi4fa78922015-11-30 17:13:56 -08002169 attrs.subtreeSystemUiVisibility |= View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN;
2170 }
Adrian Roosea562512014-05-05 13:33:03 +02002171 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002172 }
RoboErik8a2cfc32014-05-16 11:19:38 -07002173
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002174 void readLidState() {
Jeff Brown2e7760e2012-04-11 15:14:55 -07002175 mLidState = mWindowManagerFuncs.getLidState();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002176 }
RoboErik8a2cfc32014-05-16 11:19:38 -07002177
Michael Wright3818c922014-09-02 13:59:07 -07002178 private void readCameraLensCoverState() {
2179 mCameraLensCoverState = mWindowManagerFuncs.getCameraLensCoverState();
2180 }
2181
Jeff Browndaa37532012-05-01 15:54:03 -07002182 private boolean isHidden(int accessibilityMode) {
2183 switch (accessibilityMode) {
2184 case 1:
2185 return mLidState == LID_CLOSED;
2186 case 2:
2187 return mLidState == LID_OPEN;
2188 default:
2189 return false;
Dianne Hackborn2862fff2009-09-15 22:56:29 -07002190 }
Dianne Hackborn2862fff2009-09-15 22:56:29 -07002191 }
Jeff Brownd04a88c2011-01-16 14:05:47 -08002192
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002193 /** {@inheritDoc} */
Craig Mautner967212c2013-04-13 21:10:58 -07002194 @Override
Jeff Browndaa37532012-05-01 15:54:03 -07002195 public void adjustConfigurationLw(Configuration config, int keyboardPresence,
2196 int navigationPresence) {
2197 mHaveBuiltInKeyboard = (keyboardPresence & PRESENCE_INTERNAL) != 0;
2198
Jeff Brownf71343d2013-05-31 17:59:11 -07002199 readConfigurationDependentBehaviors();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002200 readLidState();
Jeff Brownc458ce92012-04-30 14:58:40 -07002201 applyLidSwitchState();
Jeff Brownd04a88c2011-01-16 14:05:47 -08002202
Jeff Browndaa37532012-05-01 15:54:03 -07002203 if (config.keyboard == Configuration.KEYBOARD_NOKEYS
2204 || (keyboardPresence == PRESENCE_INTERNAL
2205 && isHidden(mLidKeyboardAccessibility))) {
Jeff Brownd04a88c2011-01-16 14:05:47 -08002206 config.hardKeyboardHidden = Configuration.HARDKEYBOARDHIDDEN_YES;
Jeff Browndaa37532012-05-01 15:54:03 -07002207 if (!mHasSoftInput) {
2208 config.keyboardHidden = Configuration.KEYBOARDHIDDEN_YES;
2209 }
Jeff Brownd04a88c2011-01-16 14:05:47 -08002210 }
2211
Jeff Browndaa37532012-05-01 15:54:03 -07002212 if (config.navigation == Configuration.NAVIGATION_NONAV
2213 || (navigationPresence == PRESENCE_INTERNAL
2214 && isHidden(mLidNavigationAccessibility))) {
Jeff Brownd04a88c2011-01-16 14:05:47 -08002215 config.navigationHidden = Configuration.NAVIGATIONHIDDEN_YES;
Jeff Brownd04a88c2011-01-16 14:05:47 -08002216 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002217 }
Jeff Brownd04a88c2011-01-16 14:05:47 -08002218
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002219 /** {@inheritDoc} */
Craig Mautner967212c2013-04-13 21:10:58 -07002220 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002221 public int windowTypeToLayerLw(int type) {
2222 if (type >= FIRST_APPLICATION_WINDOW && type <= LAST_APPLICATION_WINDOW) {
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07002223 return 2;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002224 }
2225 switch (type) {
keunyounga446bf02013-06-21 19:07:57 -07002226 case TYPE_PRIVATE_PRESENTATION:
2227 return 2;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07002228 case TYPE_WALLPAPER:
2229 // wallpaper is at the bottom, though the window manager may move it.
2230 return 2;
Filip Gruszczynskie95b0ae2015-09-30 10:55:33 -07002231 case TYPE_DOCK_DIVIDER:
2232 return 2;
Jason Monk8f7f3182015-11-18 16:35:14 -05002233 case TYPE_QS_DIALOG:
2234 return 2;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07002235 case TYPE_PHONE:
2236 return 3;
2237 case TYPE_SEARCH_BAR:
Jorim Jaggi225d3b52015-04-01 11:18:57 -07002238 case TYPE_VOICE_INTERACTION_STARTING:
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07002239 return 4;
Dianne Hackborne30e02f2014-05-27 18:24:45 -07002240 case TYPE_VOICE_INTERACTION:
2241 // voice interaction layer is almost immediately above apps.
2242 return 5;
Selim Cinekf83e8242015-05-19 18:08:14 -07002243 case TYPE_INPUT_CONSUMER:
Dianne Hackborne30e02f2014-05-27 18:24:45 -07002244 return 6;
Selim Cinekf83e8242015-05-19 18:08:14 -07002245 case TYPE_SYSTEM_DIALOG:
2246 return 7;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07002247 case TYPE_TOAST:
2248 // toasts and the plugged-in battery thing
Selim Cinekf83e8242015-05-19 18:08:14 -07002249 return 8;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07002250 case TYPE_PRIORITY_PHONE:
2251 // SIM errors and unlock. Not sure if this really should be in a high layer.
Selim Cinekf83e8242015-05-19 18:08:14 -07002252 return 9;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07002253 case TYPE_DREAM:
2254 // used for Dreams (screensavers with TYPE_DREAM windows)
Selim Cinekf83e8242015-05-19 18:08:14 -07002255 return 10;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07002256 case TYPE_SYSTEM_ALERT:
2257 // like the ANR / app crashed dialogs
Selim Cinekf83e8242015-05-19 18:08:14 -07002258 return 11;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07002259 case TYPE_INPUT_METHOD:
2260 // on-screen keyboards and other such input method user interfaces go here.
Selim Cinekf83e8242015-05-19 18:08:14 -07002261 return 12;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07002262 case TYPE_INPUT_METHOD_DIALOG:
2263 // on-screen keyboards and other such input method user interfaces go here.
Selim Cinekf83e8242015-05-19 18:08:14 -07002264 return 13;
Jim Miller5ecd8112013-01-09 18:50:26 -08002265 case TYPE_KEYGUARD_SCRIM:
2266 // the safety window that shows behind keyguard while keyguard is starting
Filip Gruszczynskie95b0ae2015-09-30 10:55:33 -07002267 return 14;
Filip Gruszczynski466f3212015-09-21 17:57:57 -07002268 case TYPE_STATUS_BAR_SUB_PANEL:
Filip Gruszczynskie95b0ae2015-09-30 10:55:33 -07002269 return 15;
Filip Gruszczynski466f3212015-09-21 17:57:57 -07002270 case TYPE_STATUS_BAR:
Filip Gruszczynskie95b0ae2015-09-30 10:55:33 -07002271 return 16;
Filip Gruszczynski466f3212015-09-21 17:57:57 -07002272 case TYPE_STATUS_BAR_PANEL:
Filip Gruszczynskie95b0ae2015-09-30 10:55:33 -07002273 return 17;
Filip Gruszczynski466f3212015-09-21 17:57:57 -07002274 case TYPE_KEYGUARD_DIALOG:
Filip Gruszczynskie95b0ae2015-09-30 10:55:33 -07002275 return 18;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07002276 case TYPE_VOLUME_OVERLAY:
2277 // the on-screen volume indicator and controller shown when the user
2278 // changes the device volume
Filip Gruszczynskie95b0ae2015-09-30 10:55:33 -07002279 return 19;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07002280 case TYPE_SYSTEM_OVERLAY:
2281 // the on-screen volume indicator and controller shown when the user
2282 // changes the device volume
Filip Gruszczynskie95b0ae2015-09-30 10:55:33 -07002283 return 20;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07002284 case TYPE_NAVIGATION_BAR:
2285 // the navigation bar, if available, shows atop most things
Filip Gruszczynskie95b0ae2015-09-30 10:55:33 -07002286 return 21;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07002287 case TYPE_NAVIGATION_BAR_PANEL:
2288 // some panels (e.g. search) need to show on top of the navigation bar
Filip Gruszczynskie95b0ae2015-09-30 10:55:33 -07002289 return 22;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07002290 case TYPE_SYSTEM_ERROR:
2291 // system-level error dialogs
Filip Gruszczynskie95b0ae2015-09-30 10:55:33 -07002292 return 23;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07002293 case TYPE_MAGNIFICATION_OVERLAY:
2294 // used to highlight the magnified portion of a display
Filip Gruszczynskie95b0ae2015-09-30 10:55:33 -07002295 return 24;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07002296 case TYPE_DISPLAY_OVERLAY:
2297 // used to simulate secondary display devices
Filip Gruszczynskie95b0ae2015-09-30 10:55:33 -07002298 return 25;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07002299 case TYPE_DRAG:
2300 // the drag layer: input for drag-and-drop is associated with this window,
2301 // which sits above all other focusable windows
Filip Gruszczynskie95b0ae2015-09-30 10:55:33 -07002302 return 26;
Svetoslav3a5c7212014-10-14 09:54:26 -07002303 case TYPE_ACCESSIBILITY_OVERLAY:
2304 // overlay put by accessibility services to intercept user interaction
Filip Gruszczynskie95b0ae2015-09-30 10:55:33 -07002305 return 27;
Filip Gruszczynski466f3212015-09-21 17:57:57 -07002306 case TYPE_SECURE_SYSTEM_OVERLAY:
Filip Gruszczynskie95b0ae2015-09-30 10:55:33 -07002307 return 28;
Filip Gruszczynski466f3212015-09-21 17:57:57 -07002308 case TYPE_BOOT_PROGRESS:
Filip Gruszczynskie95b0ae2015-09-30 10:55:33 -07002309 return 29;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07002310 case TYPE_POINTER:
2311 // the (mouse) pointer layer
Filip Gruszczynskie95b0ae2015-09-30 10:55:33 -07002312 return 30;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002313 }
2314 Log.e(TAG, "Unknown window type: " + type);
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07002315 return 2;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002316 }
2317
2318 /** {@inheritDoc} */
Craig Mautner46ac6fa2013-08-01 10:06:34 -07002319 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002320 public int subWindowTypeToLayerLw(int type) {
2321 switch (type) {
2322 case TYPE_APPLICATION_PANEL:
2323 case TYPE_APPLICATION_ATTACHED_DIALOG:
2324 return APPLICATION_PANEL_SUBLAYER;
2325 case TYPE_APPLICATION_MEDIA:
2326 return APPLICATION_MEDIA_SUBLAYER;
Dianne Hackborn5cb8d792009-05-21 17:34:15 -07002327 case TYPE_APPLICATION_MEDIA_OVERLAY:
2328 return APPLICATION_MEDIA_OVERLAY_SUBLAYER;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002329 case TYPE_APPLICATION_SUB_PANEL:
2330 return APPLICATION_SUB_PANEL_SUBLAYER;
Wale Ogunwale0a4dc222015-04-14 12:58:42 -07002331 case TYPE_APPLICATION_ABOVE_SUB_PANEL:
2332 return APPLICATION_ABOVE_SUB_PANEL_SUBLAYER;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002333 }
2334 Log.e(TAG, "Unknown sub-window type: " + type);
2335 return 0;
2336 }
2337
Craig Mautner46ac6fa2013-08-01 10:06:34 -07002338 @Override
Dianne Hackbornabe0da02009-09-18 01:55:39 -07002339 public int getMaxWallpaperLayer() {
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07002340 return windowTypeToLayerLw(TYPE_STATUS_BAR);
Dianne Hackbornabe0da02009-09-18 01:55:39 -07002341 }
2342
Sriram Viswanathan9ebbe6a2015-11-16 17:59:22 -08002343 private int getNavigationBarWidth(int rotation, int uiMode) {
2344 if ((uiMode & UI_MODE_TYPE_MASK) == UI_MODE_TYPE_CAR) {
2345 return mNavigationBarWidthForRotationInCarMode[rotation];
2346 } else {
2347 return mNavigationBarWidthForRotationDefault[rotation];
2348 }
2349 }
2350
Craig Mautner46ac6fa2013-08-01 10:06:34 -07002351 @Override
Sriram Viswanathan9ebbe6a2015-11-16 17:59:22 -08002352 public int getNonDecorDisplayWidth(int fullWidth, int fullHeight, int rotation,
2353 int uiMode) {
Dianne Hackborn077ee852012-04-09 16:27:07 -07002354 if (mHasNavigationBar) {
2355 // For a basic navigation bar, when we are in landscape mode we place
2356 // the navigation bar to the side.
Daniel Sandler4a066c52012-04-20 14:49:13 -04002357 if (mNavigationBarCanMove && fullWidth > fullHeight) {
Sriram Viswanathan9ebbe6a2015-11-16 17:59:22 -08002358 return fullWidth - getNavigationBarWidth(rotation, uiMode);
Dianne Hackborn077ee852012-04-09 16:27:07 -07002359 }
Dianne Hackborn1f903c32011-09-13 19:18:06 -07002360 }
2361 return fullWidth;
Dianne Hackborne2515ee2011-04-27 18:52:56 -04002362 }
2363
Sriram Viswanathan9ebbe6a2015-11-16 17:59:22 -08002364 private int getNavigationBarHeight(int rotation, int uiMode) {
2365 if ((uiMode & UI_MODE_TYPE_MASK) == UI_MODE_TYPE_CAR) {
2366 return mNavigationBarHeightForRotationInCarMode[rotation];
2367 } else {
2368 return mNavigationBarHeightForRotationDefault[rotation];
2369 }
2370 }
2371
Jose Lima9546b202014-07-02 17:21:51 -07002372 @Override
Sriram Viswanathan9ebbe6a2015-11-16 17:59:22 -08002373 public int getNonDecorDisplayHeight(int fullWidth, int fullHeight, int rotation,
2374 int uiMode) {
Dianne Hackborn077ee852012-04-09 16:27:07 -07002375 if (mHasNavigationBar) {
2376 // For a basic navigation bar, when we are in portrait mode we place
2377 // the navigation bar to the bottom.
Daniel Sandler4a066c52012-04-20 14:49:13 -04002378 if (!mNavigationBarCanMove || fullWidth < fullHeight) {
Sriram Viswanathan9ebbe6a2015-11-16 17:59:22 -08002379 return fullHeight - getNavigationBarHeight(rotation, uiMode);
Dianne Hackborn077ee852012-04-09 16:27:07 -07002380 }
2381 }
2382 return fullHeight;
Dianne Hackborn69cb8752011-05-19 18:13:32 -07002383 }
2384
Jose Lima9546b202014-07-02 17:21:51 -07002385 @Override
Sriram Viswanathan9ebbe6a2015-11-16 17:59:22 -08002386 public int getConfigDisplayWidth(int fullWidth, int fullHeight, int rotation, int uiMode) {
2387 return getNonDecorDisplayWidth(fullWidth, fullHeight, rotation, uiMode);
Dianne Hackborn69cb8752011-05-19 18:13:32 -07002388 }
2389
Jose Lima9546b202014-07-02 17:21:51 -07002390 @Override
Sriram Viswanathan9ebbe6a2015-11-16 17:59:22 -08002391 public int getConfigDisplayHeight(int fullWidth, int fullHeight, int rotation, int uiMode) {
John Spurlock80f00c12013-06-13 11:10:51 -04002392 // There is a separate status bar at the top of the display. We don't count that as part
2393 // of the fixed decor, since it can hide; however, for purposes of configurations,
Dianne Hackborn077ee852012-04-09 16:27:07 -07002394 // we do want to exclude it since applications can't generally use that part
2395 // of the screen.
Sriram Viswanathan9ebbe6a2015-11-16 17:59:22 -08002396 return getNonDecorDisplayHeight(
2397 fullWidth, fullHeight, rotation, uiMode) - mStatusBarHeight;
Dianne Hackborne2515ee2011-04-27 18:52:56 -04002398 }
2399
Craig Mautnera3f4bf52012-10-10 20:37:48 -07002400 @Override
Craig Mautnerc9457fa2014-06-06 14:27:48 -07002401 public boolean isForceHiding(WindowManager.LayoutParams attrs) {
2402 return (attrs.privateFlags & PRIVATE_FLAG_KEYGUARD) != 0 ||
Jim Millerab954542014-10-10 18:21:49 -07002403 (isKeyguardHostWindow(attrs) &&
2404 (mKeyguardDelegate != null && mKeyguardDelegate.isShowing())) ||
Adrian Roos69e510d2014-07-13 14:57:59 +02002405 (attrs.type == TYPE_KEYGUARD_SCRIM);
Dianne Hackborn01ad2f42009-09-24 19:24:56 -07002406 }
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07002407
Craig Mautnera3f4bf52012-10-10 20:37:48 -07002408 @Override
Jorim Jaggi0d674622014-05-21 01:34:15 +02002409 public boolean isKeyguardHostWindow(WindowManager.LayoutParams attrs) {
2410 return attrs.type == TYPE_STATUS_BAR;
2411 }
2412
2413 @Override
Dianne Hackborn01ad2f42009-09-24 19:24:56 -07002414 public boolean canBeForceHidden(WindowState win, WindowManager.LayoutParams attrs) {
Craig Mautnera3f4bf52012-10-10 20:37:48 -07002415 switch (attrs.type) {
2416 case TYPE_STATUS_BAR:
2417 case TYPE_NAVIGATION_BAR:
2418 case TYPE_WALLPAPER:
2419 case TYPE_DREAM:
Jim Miller5ecd8112013-01-09 18:50:26 -08002420 case TYPE_KEYGUARD_SCRIM:
Craig Mautnera3f4bf52012-10-10 20:37:48 -07002421 return false;
2422 default:
Adrian Roos461829d2015-06-03 14:41:18 -07002423 // Hide only windows below the keyguard host window.
2424 return windowTypeToLayerLw(win.getBaseType())
2425 < windowTypeToLayerLw(TYPE_STATUS_BAR);
Craig Mautnera3f4bf52012-10-10 20:37:48 -07002426 }
Dianne Hackborn01ad2f42009-09-24 19:24:56 -07002427 }
Craig Mautner8e4df6c2012-05-23 16:57:23 -07002428
Craig Mautner7d7808f2014-09-11 18:02:38 -07002429 @Override
2430 public WindowState getWinShowWhenLockedLw() {
2431 return mWinShowWhenLocked;
2432 }
2433
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002434 /** {@inheritDoc} */
Craig Mautner8e4df6c2012-05-23 16:57:23 -07002435 @Override
Dianne Hackborn2f0b1752011-05-31 17:59:49 -07002436 public View addStartingWindow(IBinder appToken, String packageName, int theme,
2437 CompatibilityInfo compatInfo, CharSequence nonLocalizedLabel, int labelRes,
Adam Powell04fe6eb2013-05-31 14:39:48 -07002438 int icon, int logo, int windowFlags) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002439 if (!SHOW_STARTING_ANIMATIONS) {
2440 return null;
2441 }
2442 if (packageName == null) {
2443 return null;
2444 }
Craig Mautner8e4df6c2012-05-23 16:57:23 -07002445
Mathias Jeppssond1443e92012-08-24 15:25:32 +02002446 WindowManager wm = null;
2447 View view = null;
2448
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002449 try {
Dianne Hackborn867ab6472010-04-29 13:28:56 -07002450 Context context = mContext;
Craig Mautner6fbda632012-07-03 09:26:39 -07002451 if (DEBUG_STARTING_WINDOW) Slog.d(TAG, "addStartingWindow " + packageName
2452 + ": nonLocalizedLabel=" + nonLocalizedLabel + " theme="
2453 + Integer.toHexString(theme));
Dianne Hackborn247fe742011-01-08 17:25:57 -08002454 if (theme != context.getThemeResId() || labelRes != 0) {
Dianne Hackborn867ab6472010-04-29 13:28:56 -07002455 try {
2456 context = context.createPackageContext(packageName, 0);
Dianne Hackborn247fe742011-01-08 17:25:57 -08002457 context.setTheme(theme);
Dianne Hackborn867ab6472010-04-29 13:28:56 -07002458 } catch (PackageManager.NameNotFoundException e) {
2459 // Ignore
2460 }
2461 }
Craig Mautner8e4df6c2012-05-23 16:57:23 -07002462
Jorim Jaggia16cc152015-06-01 16:55:05 -07002463 PhoneWindow win = new PhoneWindow(context);
2464 win.setIsStartingWindow(true);
Craig Mautner8e4df6c2012-05-23 16:57:23 -07002465
Dianne Hackborn867ab6472010-04-29 13:28:56 -07002466 Resources r = context.getResources();
2467 win.setTitle(r.getText(labelRes, nonLocalizedLabel));
Craig Mautner8e4df6c2012-05-23 16:57:23 -07002468
Dianne Hackborn867ab6472010-04-29 13:28:56 -07002469 win.setType(
2470 WindowManager.LayoutParams.TYPE_APPLICATION_STARTING);
Adrian Roos602c68e2015-04-24 16:03:47 -07002471
2472 synchronized (mWindowManagerFuncs.getWindowManagerLock()) {
2473 // Assumes it's safe to show starting windows of launched apps while
2474 // the keyguard is being hidden. This is okay because starting windows never show
2475 // secret information.
2476 if (mKeyguardHidden) {
2477 windowFlags |= FLAG_SHOW_WHEN_LOCKED;
2478 }
2479 }
2480
Dianne Hackborn867ab6472010-04-29 13:28:56 -07002481 // Force the window flags: this is a fake window, so it is not really
2482 // touchable or focusable by the user. We also add in the ALT_FOCUSABLE_IM
2483 // flag because we do know that the next window will take input
2484 // focus, so we want to get the IME window up on top of us right away.
2485 win.setFlags(
Dianne Hackborn7eec10e2010-11-12 18:03:47 -08002486 windowFlags|
Dianne Hackborn867ab6472010-04-29 13:28:56 -07002487 WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE|
2488 WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE|
2489 WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM,
Dianne Hackborn7eec10e2010-11-12 18:03:47 -08002490 windowFlags|
Dianne Hackborn867ab6472010-04-29 13:28:56 -07002491 WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE|
2492 WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE|
2493 WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM);
Craig Mautner8e4df6c2012-05-23 16:57:23 -07002494
Adam Powell04fe6eb2013-05-31 14:39:48 -07002495 win.setDefaultIcon(icon);
2496 win.setDefaultLogo(logo);
2497
Dianne Hackborn867ab6472010-04-29 13:28:56 -07002498 win.setLayout(WindowManager.LayoutParams.MATCH_PARENT,
Dianne Hackborn2f0b1752011-05-31 17:59:49 -07002499 WindowManager.LayoutParams.MATCH_PARENT);
Craig Mautner8e4df6c2012-05-23 16:57:23 -07002500
Dianne Hackborn867ab6472010-04-29 13:28:56 -07002501 final WindowManager.LayoutParams params = win.getAttributes();
2502 params.token = appToken;
2503 params.packageName = packageName;
2504 params.windowAnimations = win.getWindowStyle().getResourceId(
2505 com.android.internal.R.styleable.Window_windowAnimationStyle, 0);
John Reck61375a82014-09-18 19:27:48 +00002506 params.privateFlags |=
2507 WindowManager.LayoutParams.PRIVATE_FLAG_FAKE_HARDWARE_ACCELERATED;
Craig Mautner88400d32012-09-30 12:35:45 -07002508 params.privateFlags |= WindowManager.LayoutParams.PRIVATE_FLAG_SHOW_FOR_ALL_USERS;
Adam Lesinski95c42972013-10-02 10:13:27 -07002509
2510 if (!compatInfo.supportsScreen()) {
2511 params.privateFlags |= WindowManager.LayoutParams.PRIVATE_FLAG_COMPATIBLE_WINDOW;
2512 }
2513
Dianne Hackborn867ab6472010-04-29 13:28:56 -07002514 params.setTitle("Starting " + packageName);
2515
Mathias Jeppssond1443e92012-08-24 15:25:32 +02002516 wm = (WindowManager)context.getSystemService(Context.WINDOW_SERVICE);
2517 view = win.getDecorView();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002518
Craig Mautner6fbda632012-07-03 09:26:39 -07002519 if (DEBUG_STARTING_WINDOW) Slog.d(
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002520 TAG, "Adding starting window for " + packageName
2521 + " / " + appToken + ": "
2522 + (view.getParent() != null ? view : null));
2523
2524 wm.addView(view, params);
2525
2526 // Only return the view if it was successfully added to the
2527 // window manager... which we can tell by it having a parent.
2528 return view.getParent() != null ? view : null;
Jeff Brown98365d72012-08-19 20:30:52 -07002529 } catch (WindowManager.BadTokenException e) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002530 // ignore
Craig Mautner42bf39e2014-02-21 16:46:22 -08002531 Log.w(TAG, appToken + " already running, starting window not displayed. " +
2532 e.getMessage());
Dianne Hackborn867ab6472010-04-29 13:28:56 -07002533 } catch (RuntimeException e) {
2534 // don't crash if something else bad happens, for example a
2535 // failure loading resources because we are loading from an app
2536 // on external storage that has been unmounted.
2537 Log.w(TAG, appToken + " failed creating starting window", e);
Mathias Jeppssond1443e92012-08-24 15:25:32 +02002538 } finally {
2539 if (view != null && view.getParent() == null) {
2540 Log.w(TAG, "view not successfully added to wm, removing view");
2541 wm.removeViewImmediate(view);
2542 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002543 }
2544
2545 return null;
2546 }
2547
2548 /** {@inheritDoc} */
Jose Lima9546b202014-07-02 17:21:51 -07002549 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002550 public void removeStartingWindow(IBinder appToken, View window) {
Craig Mautner276a6eb2014-11-04 15:32:57 -08002551 if (DEBUG_STARTING_WINDOW) Slog.v(TAG, "Removing starting window for " + appToken + ": "
2552 + window + " Callers=" + Debug.getCallers(4));
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002553
2554 if (window != null) {
Dianne Hackborn5fd21692011-06-07 14:09:47 -07002555 WindowManager wm = (WindowManager)mContext.getSystemService(Context.WINDOW_SERVICE);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002556 wm.removeView(window);
2557 }
2558 }
2559
2560 /**
2561 * Preflight adding a window to the system.
RoboErik8a2cfc32014-05-16 11:19:38 -07002562 *
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002563 * Currently enforces that three window types are singletons:
2564 * <ul>
2565 * <li>STATUS_BAR_TYPE</li>
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002566 * <li>KEYGUARD_TYPE</li>
2567 * </ul>
RoboErik8a2cfc32014-05-16 11:19:38 -07002568 *
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002569 * @param win The window to be added
2570 * @param attrs Information about the window to be added
RoboErik8a2cfc32014-05-16 11:19:38 -07002571 *
Jeff Brown98365d72012-08-19 20:30:52 -07002572 * @return If ok, WindowManagerImpl.ADD_OKAY. If too many singletons,
2573 * WindowManagerImpl.ADD_MULTIPLE_SINGLETON
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002574 */
Jose Lima9546b202014-07-02 17:21:51 -07002575 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002576 public int prepareAddWindowLw(WindowState win, WindowManager.LayoutParams attrs) {
2577 switch (attrs.type) {
2578 case TYPE_STATUS_BAR:
Joe Onorato8bc6c512010-06-04 16:21:12 -04002579 mContext.enforceCallingOrSelfPermission(
2580 android.Manifest.permission.STATUS_BAR_SERVICE,
2581 "PhoneWindowManager");
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002582 if (mStatusBar != null) {
Dianne Hackbornf87d1962012-04-04 12:48:24 -07002583 if (mStatusBar.isAlive()) {
Jeff Brown98365d72012-08-19 20:30:52 -07002584 return WindowManagerGlobal.ADD_MULTIPLE_SINGLETON;
Dianne Hackbornf87d1962012-04-04 12:48:24 -07002585 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002586 }
2587 mStatusBar = win;
John Spurlock27735a42013-08-14 17:57:38 -04002588 mStatusBarController.setWindow(win);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002589 break;
Daniel Sandler8956dbb2011-04-22 07:55:02 -04002590 case TYPE_NAVIGATION_BAR:
2591 mContext.enforceCallingOrSelfPermission(
2592 android.Manifest.permission.STATUS_BAR_SERVICE,
2593 "PhoneWindowManager");
Dianne Hackbornf87d1962012-04-04 12:48:24 -07002594 if (mNavigationBar != null) {
2595 if (mNavigationBar.isAlive()) {
Jeff Brown98365d72012-08-19 20:30:52 -07002596 return WindowManagerGlobal.ADD_MULTIPLE_SINGLETON;
Dianne Hackbornf87d1962012-04-04 12:48:24 -07002597 }
2598 }
Daniel Sandler8956dbb2011-04-22 07:55:02 -04002599 mNavigationBar = win;
John Spurlock27735a42013-08-14 17:57:38 -04002600 mNavigationBarController.setWindow(win);
Craig Mautnereda67292013-04-28 13:50:14 -07002601 if (DEBUG_LAYOUT) Slog.i(TAG, "NAVIGATION BAR: " + mNavigationBar);
Daniel Sandler8956dbb2011-04-22 07:55:02 -04002602 break;
Jim Millere898ac52012-04-06 17:10:57 -07002603 case TYPE_NAVIGATION_BAR_PANEL:
Dianne Hackborn08743722009-12-21 12:16:51 -08002604 case TYPE_STATUS_BAR_PANEL:
Joe Onorato29fc2c92010-11-24 10:26:50 -08002605 case TYPE_STATUS_BAR_SUB_PANEL:
Jorim Jaggi225d3b52015-04-01 11:18:57 -07002606 case TYPE_VOICE_INTERACTION_STARTING:
Joe Onorato29fc2c92010-11-24 10:26:50 -08002607 mContext.enforceCallingOrSelfPermission(
2608 android.Manifest.permission.STATUS_BAR_SERVICE,
2609 "PhoneWindowManager");
Joe Onorato29fc2c92010-11-24 10:26:50 -08002610 break;
Jim Miller5ecd8112013-01-09 18:50:26 -08002611 case TYPE_KEYGUARD_SCRIM:
Jim Miller25190572013-02-28 17:36:24 -08002612 if (mKeyguardScrim != null) {
2613 return WindowManagerGlobal.ADD_MULTIPLE_SINGLETON;
2614 }
Jim Miller5ecd8112013-01-09 18:50:26 -08002615 mKeyguardScrim = win;
2616 break;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002617 }
Jeff Brown98365d72012-08-19 20:30:52 -07002618 return WindowManagerGlobal.ADD_OKAY;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002619 }
2620
2621 /** {@inheritDoc} */
Jose Lima9546b202014-07-02 17:21:51 -07002622 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002623 public void removeWindowLw(WindowState win) {
2624 if (mStatusBar == win) {
2625 mStatusBar = null;
John Spurlock27735a42013-08-14 17:57:38 -04002626 mStatusBarController.setWindow(null);
Jim Millerc0b676d2013-03-22 16:11:08 -07002627 mKeyguardDelegate.showScrim();
Jim Miller5ecd8112013-01-09 18:50:26 -08002628 } else if (mKeyguardScrim == win) {
2629 Log.v(TAG, "Removing keyguard scrim");
2630 mKeyguardScrim = null;
2631 } if (mNavigationBar == win) {
Daniel Sandler8956dbb2011-04-22 07:55:02 -04002632 mNavigationBar = null;
John Spurlock27735a42013-08-14 17:57:38 -04002633 mNavigationBarController.setWindow(null);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002634 }
2635 }
2636
2637 static final boolean PRINT_ANIM = false;
RoboErik8a2cfc32014-05-16 11:19:38 -07002638
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002639 /** {@inheritDoc} */
Craig Mautner4b71aa12012-12-27 17:20:01 -08002640 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002641 public int selectAnimationLw(WindowState win, int transit) {
2642 if (PRINT_ANIM) Log.i(TAG, "selectAnimation in " + win
2643 + ": transit=" + transit);
Dianne Hackbornf87d1962012-04-04 12:48:24 -07002644 if (win == mStatusBar) {
Jorim Jaggi380ecb82014-03-14 17:25:20 +01002645 boolean isKeyguard = (win.getAttrs().privateFlags & PRIVATE_FLAG_KEYGUARD) != 0;
Craig Mautner4b71aa12012-12-27 17:20:01 -08002646 if (transit == TRANSIT_EXIT
2647 || transit == TRANSIT_HIDE) {
Jorim Jaggi380ecb82014-03-14 17:25:20 +01002648 return isKeyguard ? -1 : R.anim.dock_top_exit;
Craig Mautner4b71aa12012-12-27 17:20:01 -08002649 } else if (transit == TRANSIT_ENTER
2650 || transit == TRANSIT_SHOW) {
Jorim Jaggi380ecb82014-03-14 17:25:20 +01002651 return isKeyguard ? -1 : R.anim.dock_top_enter;
Dianne Hackbornf87d1962012-04-04 12:48:24 -07002652 }
2653 } else if (win == mNavigationBar) {
Jorim Jaggi0d210f62015-07-10 14:24:44 -07002654 if (win.getAttrs().windowAnimations != 0) {
2655 return 0;
2656 }
Dianne Hackbornf87d1962012-04-04 12:48:24 -07002657 // This can be on either the bottom or the right.
2658 if (mNavigationBarOnBottom) {
Craig Mautner4b71aa12012-12-27 17:20:01 -08002659 if (transit == TRANSIT_EXIT
2660 || transit == TRANSIT_HIDE) {
Dianne Hackbornf87d1962012-04-04 12:48:24 -07002661 return R.anim.dock_bottom_exit;
Craig Mautner4b71aa12012-12-27 17:20:01 -08002662 } else if (transit == TRANSIT_ENTER
2663 || transit == TRANSIT_SHOW) {
Dianne Hackbornf87d1962012-04-04 12:48:24 -07002664 return R.anim.dock_bottom_enter;
2665 }
2666 } else {
Craig Mautner4b71aa12012-12-27 17:20:01 -08002667 if (transit == TRANSIT_EXIT
2668 || transit == TRANSIT_HIDE) {
Dianne Hackbornf87d1962012-04-04 12:48:24 -07002669 return R.anim.dock_right_exit;
Craig Mautner4b71aa12012-12-27 17:20:01 -08002670 } else if (transit == TRANSIT_ENTER
2671 || transit == TRANSIT_SHOW) {
Dianne Hackbornf87d1962012-04-04 12:48:24 -07002672 return R.anim.dock_right_enter;
2673 }
2674 }
Filip Gruszczynski57f76f12015-11-04 16:10:54 -08002675 } else if (win.getAttrs().type == TYPE_DOCK_DIVIDER) {
Jorim Jaggi81ba11e2016-02-03 22:04:22 -08002676 return selectDockedDividerAnimationLw(win, transit);
Craig Mautner4b71aa12012-12-27 17:20:01 -08002677 }
2678
2679 if (transit == TRANSIT_PREVIEW_DONE) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002680 if (win.hasAppShownWindows()) {
2681 if (PRINT_ANIM) Log.i(TAG, "**** STARTING EXIT");
2682 return com.android.internal.R.anim.app_starting_exit;
2683 }
Dianne Hackborn7ad44382012-10-18 17:46:00 -07002684 } else if (win.getAttrs().type == TYPE_DREAM && mDreamingLockscreen
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07002685 && transit == TRANSIT_ENTER) {
2686 // Special case: we are animating in a dream, while the keyguard
2687 // is shown. We don't want an animation on the dream, because
2688 // we need it shown immediately with the keyguard animating away
2689 // to reveal it.
2690 return -1;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002691 }
2692
2693 return 0;
2694 }
2695
Jorim Jaggi81ba11e2016-02-03 22:04:22 -08002696 private int selectDockedDividerAnimationLw(WindowState win, int transit) {
2697 int insets = mWindowManagerFuncs.getDockedDividerInsetsLw();
2698
2699 // If the divider is behind the navigation bar, don't animate.
2700 if (mNavigationBar != null
2701 && (win.getFrameLw().top + insets >= mNavigationBar.getFrameLw().top
2702 || win.getFrameLw().left + insets >= mNavigationBar.getFrameLw().left)) {
2703 return 0;
2704 }
2705 if (transit == TRANSIT_ENTER || transit == TRANSIT_SHOW) {
2706 return R.anim.fade_in;
2707 } else if (transit == TRANSIT_EXIT) {
2708 return R.anim.fade_out;
2709 } else {
2710 return 0;
2711 }
2712 }
2713
Craig Mautner3c174372013-02-21 17:54:37 -08002714 @Override
2715 public void selectRotationAnimationLw(int anim[]) {
2716 if (PRINT_ANIM) Slog.i(TAG, "selectRotationAnimation mTopFullscreen="
2717 + mTopFullscreenOpaqueWindowState + " rotationAnimation="
2718 + (mTopFullscreenOpaqueWindowState == null ?
2719 "0" : mTopFullscreenOpaqueWindowState.getAttrs().rotationAnimation));
2720 if (mTopFullscreenOpaqueWindowState != null && mTopIsFullscreen) {
2721 switch (mTopFullscreenOpaqueWindowState.getAttrs().rotationAnimation) {
2722 case ROTATION_ANIMATION_CROSSFADE:
2723 anim[0] = R.anim.rotation_animation_xfade_exit;
2724 anim[1] = R.anim.rotation_animation_enter;
2725 break;
2726 case ROTATION_ANIMATION_JUMPCUT:
2727 anim[0] = R.anim.rotation_animation_jump_exit;
2728 anim[1] = R.anim.rotation_animation_enter;
2729 break;
2730 case ROTATION_ANIMATION_ROTATE:
2731 default:
2732 anim[0] = anim[1] = 0;
2733 break;
2734 }
2735 } else {
2736 anim[0] = anim[1] = 0;
2737 }
2738 }
2739
2740 @Override
2741 public boolean validateRotationAnimationLw(int exitAnimId, int enterAnimId,
2742 boolean forceDefault) {
2743 switch (exitAnimId) {
2744 case R.anim.rotation_animation_xfade_exit:
2745 case R.anim.rotation_animation_jump_exit:
2746 // These are the only cases that matter.
2747 if (forceDefault) {
2748 return false;
2749 }
2750 int anim[] = new int[2];
2751 selectRotationAnimationLw(anim);
2752 return (exitAnimId == anim[0] && enterAnimId == anim[1]);
2753 default:
2754 return true;
2755 }
2756 }
2757
2758 @Override
Jorim Jaggi84a3e7a2014-08-13 17:58:58 +02002759 public Animation createForceHideEnterAnimation(boolean onWallpaper,
2760 boolean goingToNotificationShade) {
2761 if (goingToNotificationShade) {
2762 return AnimationUtils.loadAnimation(mContext, R.anim.lock_screen_behind_enter_fade_in);
Craig Mautnerb8340802014-11-04 15:32:57 -08002763 }
Craig Mautner276a6eb2014-11-04 15:32:57 -08002764
2765 AnimationSet set = (AnimationSet) AnimationUtils.loadAnimation(mContext, onWallpaper ?
2766 R.anim.lock_screen_behind_enter_wallpaper :
2767 R.anim.lock_screen_behind_enter);
2768
2769 // TODO: Use XML interpolators when we have log interpolators available in XML.
2770 final List<Animation> animations = set.getAnimations();
2771 for (int i = animations.size() - 1; i >= 0; --i) {
2772 animations.get(i).setInterpolator(mLogDecelerateInterpolator);
2773 }
2774
2775 return set;
Jorim Jaggi76a16232014-08-08 17:00:47 +02002776 }
2777
2778
2779 @Override
Jorim Jaggi84a3e7a2014-08-13 17:58:58 +02002780 public Animation createForceHideWallpaperExitAnimation(boolean goingToNotificationShade) {
2781 if (goingToNotificationShade) {
2782 return null;
2783 } else {
2784 return AnimationUtils.loadAnimation(mContext, R.anim.lock_screen_wallpaper_exit);
2785 }
Dianne Hackborn01ad2f42009-09-24 19:24:56 -07002786 }
John Spurlockc8b46ca2013-04-08 12:59:26 -04002787
2788 private static void awakenDreams() {
2789 IDreamManager dreamManager = getDreamManager();
2790 if (dreamManager != null) {
2791 try {
2792 dreamManager.awaken();
2793 } catch (RemoteException e) {
2794 // fine, stay asleep then
2795 }
2796 }
2797 }
2798
2799 static IDreamManager getDreamManager() {
2800 return IDreamManager.Stub.asInterface(
2801 ServiceManager.checkService(DreamService.DREAM_SERVICE));
2802 }
2803
Tyler Gunnef9f6f92014-09-12 22:16:17 -07002804 TelecomManager getTelecommService() {
2805 return (TelecomManager) mContext.getSystemService(Context.TELECOM_SERVICE);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002806 }
2807
Jeff Brown4d396052010-10-29 21:50:21 -07002808 static IAudioService getAudioService() {
2809 IAudioService audioService = IAudioService.Stub.asInterface(
2810 ServiceManager.checkService(Context.AUDIO_SERVICE));
2811 if (audioService == null) {
2812 Log.w(TAG, "Unable to find IAudioService interface.");
2813 }
2814 return audioService;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002815 }
2816
2817 boolean keyguardOn() {
Jim Millerab954542014-10-10 18:21:49 -07002818 return isKeyguardShowingAndNotOccluded() || inKeyguardRestrictedKeyInputMode();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002819 }
2820
2821 private static final int[] WINDOW_TYPES_WHERE_HOME_DOESNT_WORK = {
2822 WindowManager.LayoutParams.TYPE_SYSTEM_ALERT,
2823 WindowManager.LayoutParams.TYPE_SYSTEM_ERROR,
2824 };
2825
2826 /** {@inheritDoc} */
Jeff Brown00fa7bd2010-07-02 15:37:36 -07002827 @Override
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002828 public long interceptKeyBeforeDispatching(WindowState win, KeyEvent event, int policyFlags) {
Jeff Brown00fa7bd2010-07-02 15:37:36 -07002829 final boolean keyguardOn = keyguardOn();
Jeff Brown1f245102010-11-18 20:53:46 -08002830 final int keyCode = event.getKeyCode();
2831 final int repeatCount = event.getRepeatCount();
2832 final int metaState = event.getMetaState();
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002833 final int flags = event.getFlags();
Jeff Brown1f245102010-11-18 20:53:46 -08002834 final boolean down = event.getAction() == KeyEvent.ACTION_DOWN;
2835 final boolean canceled = event.isCanceled();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002836
Jeff Brown40013652012-05-16 21:22:36 -07002837 if (DEBUG_INPUT) {
Jeff Brown00fa7bd2010-07-02 15:37:36 -07002838 Log.d(TAG, "interceptKeyTi keyCode=" + keyCode + " down=" + down + " repeatCount="
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002839 + repeatCount + " keyguardOn=" + keyguardOn + " mHomePressed=" + mHomePressed
2840 + " canceled=" + canceled);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002841 }
2842
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002843 // If we think we might have a volume down & power key chord on the way
2844 // but we're not sure, then tell the dispatcher to wait a little while and
2845 // try again later before dispatching.
Christopher Tatee90585f2012-03-05 18:56:25 -08002846 if (mScreenshotChordEnabled && (flags & KeyEvent.FLAG_FALLBACK) == 0) {
Jeff Brown13f00f02014-10-31 14:45:50 -07002847 if (mScreenshotChordVolumeDownKeyTriggered && !mScreenshotChordPowerKeyTriggered) {
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002848 final long now = SystemClock.uptimeMillis();
Jeff Brown13f00f02014-10-31 14:45:50 -07002849 final long timeoutTime = mScreenshotChordVolumeDownKeyTime
2850 + SCREENSHOT_CHORD_DEBOUNCE_DELAY_MILLIS;
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002851 if (now < timeoutTime) {
2852 return timeoutTime - now;
2853 }
2854 }
2855 if (keyCode == KeyEvent.KEYCODE_VOLUME_DOWN
Jeff Brown13f00f02014-10-31 14:45:50 -07002856 && mScreenshotChordVolumeDownKeyConsumed) {
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002857 if (!down) {
Jeff Brown13f00f02014-10-31 14:45:50 -07002858 mScreenshotChordVolumeDownKeyConsumed = false;
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002859 }
2860 return -1;
2861 }
2862 }
2863
Michael Wright6a62e552014-06-03 19:19:48 -07002864 // Cancel any pending meta actions if we see any other keys being pressed between the down
2865 // of the meta key and its corresponding up.
Michael Wright251e35d2014-08-22 15:40:27 -07002866 if (mPendingMetaAction && !KeyEvent.isMetaKey(keyCode)) {
Michael Wright6a62e552014-06-03 19:19:48 -07002867 mPendingMetaAction = false;
2868 }
2869
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002870 // First we always handle the home key here, so applications
2871 // can never break it, although if keyguard is on, we do let
2872 // it handle it, because that gives us the correct 5 second
2873 // timeout.
Jeff Brown00fa7bd2010-07-02 15:37:36 -07002874 if (keyCode == KeyEvent.KEYCODE_HOME) {
Michael Jurka7f2668c2012-03-27 07:49:52 -07002875
Jeff Brown49ed71d2010-12-06 17:13:33 -08002876 // If we have released the home key, and didn't do anything else
2877 // while it was pressed, then it is time to go home!
Michael Jurka7f2668c2012-03-27 07:49:52 -07002878 if (!down) {
Jeff Browncaca8812013-05-09 13:34:33 -07002879 cancelPreloadRecentApps();
2880
Jeff Brown49ed71d2010-12-06 17:13:33 -08002881 mHomePressed = false;
Jeff Browncaca8812013-05-09 13:34:33 -07002882 if (mHomeConsumed) {
2883 mHomeConsumed = false;
Michael Jurka7f2668c2012-03-27 07:49:52 -07002884 return -1;
Jeff Brown49ed71d2010-12-06 17:13:33 -08002885 }
Jeff Browncaca8812013-05-09 13:34:33 -07002886
2887 if (canceled) {
2888 Log.i(TAG, "Ignoring HOME; event canceled.");
2889 return -1;
2890 }
2891
Yorke Lee4f803242014-12-15 23:22:06 +00002892 // If an incoming call is ringing, HOME is totally disabled.
2893 // (The user is already on the InCallUI at this point,
2894 // and his ONLY options are to answer or reject the call.)
2895 TelecomManager telecomManager = getTelecommService();
2896 if (telecomManager != null && telecomManager.isRinging()) {
2897 Log.i(TAG, "Ignoring HOME; there's a ringing incoming call.");
2898 return -1;
2899 }
2900
Jeff Browncaca8812013-05-09 13:34:33 -07002901 // Delay handling home if a double-tap is possible.
2902 if (mDoubleTapOnHomeBehavior != DOUBLE_TAP_HOME_NOTHING) {
2903 mHandler.removeCallbacks(mHomeDoubleTapTimeoutRunnable); // just in case
2904 mHomeDoubleTapPending = true;
2905 mHandler.postDelayed(mHomeDoubleTapTimeoutRunnable,
2906 ViewConfiguration.getDoubleTapTimeout());
2907 return -1;
2908 }
2909
Jeff Brown13f00f02014-10-31 14:45:50 -07002910 handleShortPressOnHome();
Jeff Browncaca8812013-05-09 13:34:33 -07002911 return -1;
Jeff Brown49ed71d2010-12-06 17:13:33 -08002912 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002913
2914 // If a system window has focus, then it doesn't make sense
2915 // right now to interact with applications.
2916 WindowManager.LayoutParams attrs = win != null ? win.getAttrs() : null;
2917 if (attrs != null) {
2918 final int type = attrs.type;
Jorim Jaggi380ecb82014-03-14 17:25:20 +01002919 if (type == WindowManager.LayoutParams.TYPE_KEYGUARD_SCRIM
2920 || type == WindowManager.LayoutParams.TYPE_KEYGUARD_DIALOG
2921 || (attrs.privateFlags & PRIVATE_FLAG_KEYGUARD) != 0) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002922 // the "app" is keyguard, so give it the key
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002923 return 0;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002924 }
2925 final int typeCount = WINDOW_TYPES_WHERE_HOME_DOESNT_WORK.length;
2926 for (int i=0; i<typeCount; i++) {
2927 if (type == WINDOW_TYPES_WHERE_HOME_DOESNT_WORK[i]) {
2928 // don't do anything, but also don't pass it to the app
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002929 return -1;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002930 }
2931 }
2932 }
Jeff Browncaca8812013-05-09 13:34:33 -07002933
2934 // Remember that home is pressed and handle special actions.
2935 if (repeatCount == 0) {
2936 mHomePressed = true;
2937 if (mHomeDoubleTapPending) {
2938 mHomeDoubleTapPending = false;
2939 mHandler.removeCallbacks(mHomeDoubleTapTimeoutRunnable);
2940 handleDoubleTapOnHome();
2941 } else if (mLongPressOnHomeBehavior == LONG_PRESS_HOME_RECENT_SYSTEM_UI
2942 || mDoubleTapOnHomeBehavior == DOUBLE_TAP_HOME_RECENT_SYSTEM_UI) {
2943 preloadRecentApps();
Michael Jurka7f2668c2012-03-27 07:49:52 -07002944 }
Jeff Browncaca8812013-05-09 13:34:33 -07002945 } else if ((event.getFlags() & KeyEvent.FLAG_LONG_PRESS) != 0) {
2946 if (!keyguardOn) {
Jaewan Kim76b7d0d2016-02-12 19:01:02 +09002947 handleLongPressOnHome(event.getDeviceId());
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002948 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002949 }
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002950 return -1;
Jeff Brown00fa7bd2010-07-02 15:37:36 -07002951 } else if (keyCode == KeyEvent.KEYCODE_MENU) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002952 // Hijack modified menu keys for debugging features
2953 final int chordBug = KeyEvent.META_SHIFT_ON;
2954
2955 if (down && repeatCount == 0) {
Jeff Brown00fa7bd2010-07-02 15:37:36 -07002956 if (mEnableShiftMenuBugReports && (metaState & chordBug) == chordBug) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002957 Intent intent = new Intent(Intent.ACTION_BUG_REPORT);
Dianne Hackborn5ac72a22012-08-29 18:32:08 -07002958 mContext.sendOrderedBroadcastAsUser(intent, UserHandle.CURRENT,
2959 null, null, null, 0, null, null);
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002960 return -1;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002961 } else if (SHOW_PROCESSES_ON_ALT_MENU &&
Jeff Brown00fa7bd2010-07-02 15:37:36 -07002962 (metaState & KeyEvent.META_ALT_ON) == KeyEvent.META_ALT_ON) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002963 Intent service = new Intent();
2964 service.setClassName(mContext, "com.android.server.LoadAverageService");
2965 ContentResolver res = mContext.getContentResolver();
Jeff Sharkey8d9a1f62012-10-18 15:38:14 -07002966 boolean shown = Settings.Global.getInt(
2967 res, Settings.Global.SHOW_PROCESSES, 0) != 0;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002968 if (!shown) {
2969 mContext.startService(service);
2970 } else {
2971 mContext.stopService(service);
2972 }
Jeff Sharkey8d9a1f62012-10-18 15:38:14 -07002973 Settings.Global.putInt(
2974 res, Settings.Global.SHOW_PROCESSES, shown ? 0 : 1);
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002975 return -1;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002976 }
2977 }
Jeff Brown00fa7bd2010-07-02 15:37:36 -07002978 } else if (keyCode == KeyEvent.KEYCODE_SEARCH) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002979 if (down) {
2980 if (repeatCount == 0) {
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002981 mSearchKeyShortcutPending = true;
2982 mConsumeSearchKeyUp = false;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002983 }
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002984 } else {
2985 mSearchKeyShortcutPending = false;
2986 if (mConsumeSearchKeyUp) {
2987 mConsumeSearchKeyUp = false;
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002988 return -1;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002989 }
2990 }
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002991 return 0;
Jeff Brown49ed71d2010-12-06 17:13:33 -08002992 } else if (keyCode == KeyEvent.KEYCODE_APP_SWITCH) {
Michael Wrightc9ebea72013-01-16 19:25:02 -08002993 if (!keyguardOn) {
Jeff Browncaca8812013-05-09 13:34:33 -07002994 if (down && repeatCount == 0) {
2995 preloadRecentApps();
2996 } else if (!down) {
2997 toggleRecentApps();
Michael Wrightc9ebea72013-01-16 19:25:02 -08002998 }
Jeff Brown49ed71d2010-12-06 17:13:33 -08002999 }
Jeff Brownd5bb82d2011-10-12 13:57:59 -07003000 return -1;
Jun Mukaid21b3c82015-04-23 14:09:34 -07003001 } else if (keyCode == KeyEvent.KEYCODE_N && event.isMetaPressed()) {
3002 if (down) {
3003 IStatusBarService service = getStatusBarService();
3004 if (service != null) {
3005 try {
3006 service.expandNotificationsPanel();
3007 } catch (RemoteException e) {
3008 // do nothing.
3009 }
3010 }
3011 }
Clara Bayarrif2debb12015-07-10 14:47:17 +01003012 } else if (keyCode == KeyEvent.KEYCODE_SLASH && event.isMetaPressed()) {
3013 if (down) {
3014 if (repeatCount == 0) {
Andrei Stingaceanuc22ab792016-01-07 12:39:38 +00003015 toggleKeyboardShortcutsMenu();
Clara Bayarrif2debb12015-07-10 14:47:17 +01003016 }
3017 }
Jeff Brownde7a8ea2012-06-13 18:28:57 -07003018 } else if (keyCode == KeyEvent.KEYCODE_ASSIST) {
3019 if (down) {
3020 if (repeatCount == 0) {
3021 mAssistKeyLongPressed = false;
3022 } else if (repeatCount == 1) {
3023 mAssistKeyLongPressed = true;
3024 if (!keyguardOn) {
3025 launchAssistLongPressAction();
3026 }
3027 }
3028 } else {
3029 if (mAssistKeyLongPressed) {
3030 mAssistKeyLongPressed = false;
3031 } else {
3032 if (!keyguardOn) {
Tim Kilbourn0e5f1102015-06-05 16:18:09 -07003033 launchAssistAction(null, event.getDeviceId());
Jeff Brownde7a8ea2012-06-13 18:28:57 -07003034 }
3035 }
3036 }
3037 return -1;
Michael Wrightdc63f7b2014-08-21 19:05:21 -07003038 } else if (keyCode == KeyEvent.KEYCODE_VOICE_ASSIST) {
3039 if (!down) {
3040 Intent voiceIntent;
Michael Wright869a67c2014-08-26 19:33:06 -07003041 if (!keyguardOn) {
Michael Wrightdc63f7b2014-08-21 19:05:21 -07003042 voiceIntent = new Intent(RecognizerIntent.ACTION_WEB_SEARCH);
3043 } else {
Dianne Hackbornb6683c42015-06-18 17:40:33 -07003044 IDeviceIdleController dic = IDeviceIdleController.Stub.asInterface(
3045 ServiceManager.getService(Context.DEVICE_IDLE_CONTROLLER));
3046 if (dic != null) {
3047 try {
3048 dic.exitIdle("voice-search");
3049 } catch (RemoteException e) {
3050 }
3051 }
Michael Wrightdc63f7b2014-08-21 19:05:21 -07003052 voiceIntent = new Intent(RecognizerIntent.ACTION_VOICE_SEARCH_HANDS_FREE);
Michael Wright869a67c2014-08-26 19:33:06 -07003053 voiceIntent.putExtra(RecognizerIntent.EXTRA_SECURE, true);
Michael Wrightdc63f7b2014-08-21 19:05:21 -07003054 }
Bart Sears8b1c27c2015-03-18 23:51:02 +00003055 startActivityAsUser(voiceIntent, UserHandle.CURRENT_OR_SELF);
Michael Wrightdc63f7b2014-08-21 19:05:21 -07003056 }
Jeff Sharkey2991fa32012-12-05 18:06:43 -08003057 } else if (keyCode == KeyEvent.KEYCODE_SYSRQ) {
3058 if (down && repeatCount == 0) {
3059 mHandler.post(mScreenshotRunnable);
3060 }
3061 return -1;
Michael Wrightb854e242013-02-05 17:54:02 -08003062 } else if (keyCode == KeyEvent.KEYCODE_BRIGHTNESS_UP
3063 || keyCode == KeyEvent.KEYCODE_BRIGHTNESS_DOWN) {
3064 if (down) {
3065 int direction = keyCode == KeyEvent.KEYCODE_BRIGHTNESS_UP ? 1 : -1;
3066
3067 // Disable autobrightness if it's on
3068 int auto = Settings.System.getIntForUser(
3069 mContext.getContentResolver(),
3070 Settings.System.SCREEN_BRIGHTNESS_MODE,
3071 Settings.System.SCREEN_BRIGHTNESS_MODE_MANUAL,
3072 UserHandle.USER_CURRENT_OR_SELF);
3073 if (auto != 0) {
3074 Settings.System.putIntForUser(mContext.getContentResolver(),
3075 Settings.System.SCREEN_BRIGHTNESS_MODE,
3076 Settings.System.SCREEN_BRIGHTNESS_MODE_MANUAL,
3077 UserHandle.USER_CURRENT_OR_SELF);
3078 }
3079
3080 int min = mPowerManager.getMinimumScreenBrightnessSetting();
3081 int max = mPowerManager.getMaximumScreenBrightnessSetting();
3082 int step = (max - min + BRIGHTNESS_STEPS - 1) / BRIGHTNESS_STEPS * direction;
3083 int brightness = Settings.System.getIntForUser(mContext.getContentResolver(),
3084 Settings.System.SCREEN_BRIGHTNESS,
3085 mPowerManager.getDefaultScreenBrightnessSetting(),
3086 UserHandle.USER_CURRENT_OR_SELF);
3087 brightness += step;
3088 // Make sure we don't go beyond the limits.
3089 brightness = Math.min(max, brightness);
3090 brightness = Math.max(min, brightness);
3091
3092 Settings.System.putIntForUser(mContext.getContentResolver(),
3093 Settings.System.SCREEN_BRIGHTNESS, brightness,
3094 UserHandle.USER_CURRENT_OR_SELF);
Bart Sears8b1c27c2015-03-18 23:51:02 +00003095 startActivityAsUser(new Intent(Intent.ACTION_SHOW_BRIGHTNESS_DIALOG),
Alan Viverette5a399492014-07-14 16:19:38 -07003096 UserHandle.CURRENT_OR_SELF);
Michael Wrightb854e242013-02-05 17:54:02 -08003097 }
3098 return -1;
Jaewan Kim765487f2016-01-12 14:45:42 +09003099 } else if (keyCode == KeyEvent.KEYCODE_VOLUME_UP
3100 || keyCode == KeyEvent.KEYCODE_VOLUME_DOWN
3101 || keyCode == KeyEvent.KEYCODE_VOLUME_MUTE) {
3102 if (mUseTvRouting) {
3103 // On TVs volume keys never go to the foreground app.
3104 dispatchDirectAudioEvent(event);
3105 return -1;
3106 }
Muyuan Li94ce94e2016-02-24 16:20:54 -08003107 }
3108
3109 if (KeyEvent.isMetaKey(keyCode)) {
Michael Wright6a62e552014-06-03 19:19:48 -07003110 if (down) {
3111 mPendingMetaAction = true;
3112 } else if (mPendingMetaAction) {
Tim Kilbourn0e5f1102015-06-05 16:18:09 -07003113 launchAssistAction(Intent.EXTRA_ASSIST_INPUT_HINT_KEYBOARD, event.getDeviceId());
Michael Wright6a62e552014-06-03 19:19:48 -07003114 }
3115 return -1;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003116 }
Jeff Browncaab4d02010-12-09 22:13:41 -08003117
Jeff Brownc1fb48d2010-12-08 16:52:09 -08003118 // Shortcuts are invoked through Search+key, so intercept those here
Jeff Browncaab4d02010-12-09 22:13:41 -08003119 // Any printing key that is chorded with Search should be consumed
3120 // even if no shortcut was invoked. This prevents text from being
3121 // inadvertently inserted when using a keyboard that has built-in macro
3122 // shortcut keys (that emit Search+x) and some of them are not registered.
Jeff Brownfd23e3e2012-05-09 13:34:28 -07003123 if (mSearchKeyShortcutPending) {
Jeff Browncaab4d02010-12-09 22:13:41 -08003124 final KeyCharacterMap kcm = event.getKeyCharacterMap();
3125 if (kcm.isPrintingKey(keyCode)) {
Jeff Brownfd23e3e2012-05-09 13:34:28 -07003126 mConsumeSearchKeyUp = true;
3127 mSearchKeyShortcutPending = false;
Jeff Browncaab4d02010-12-09 22:13:41 -08003128 if (down && repeatCount == 0 && !keyguardOn) {
3129 Intent shortcutIntent = mShortcutManager.getIntent(kcm, keyCode, metaState);
3130 if (shortcutIntent != null) {
3131 shortcutIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
Jeff Brownf0a3cc52011-01-26 18:42:46 -08003132 try {
Bart Sears8b1c27c2015-03-18 23:51:02 +00003133 startActivityAsUser(shortcutIntent, UserHandle.CURRENT);
Jeff Brownf0a3cc52011-01-26 18:42:46 -08003134 } catch (ActivityNotFoundException ex) {
3135 Slog.w(TAG, "Dropping shortcut key combination because "
3136 + "the activity to which it is registered was not found: "
Jeff Brownfd23e3e2012-05-09 13:34:28 -07003137 + "SEARCH+" + KeyEvent.keyCodeToString(keyCode), ex);
Jeff Brownf0a3cc52011-01-26 18:42:46 -08003138 }
Jeff Browncaab4d02010-12-09 22:13:41 -08003139 } else {
3140 Slog.i(TAG, "Dropping unregistered shortcut key combination: "
Jeff Brownfd23e3e2012-05-09 13:34:28 -07003141 + "SEARCH+" + KeyEvent.keyCodeToString(keyCode));
Jeff Brown49ed71d2010-12-06 17:13:33 -08003142 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003143 }
Jeff Brownd5bb82d2011-10-12 13:57:59 -07003144 return -1;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003145 }
3146 }
3147
Jeff Brown68b909d2011-12-07 16:36:01 -08003148 // Invoke shortcuts using Meta.
Jeff Brown602ab322012-05-16 13:33:47 -07003149 if (down && repeatCount == 0 && !keyguardOn
Jeff Brown68b909d2011-12-07 16:36:01 -08003150 && (metaState & KeyEvent.META_META_ON) != 0) {
3151 final KeyCharacterMap kcm = event.getKeyCharacterMap();
Jeff Brown602ab322012-05-16 13:33:47 -07003152 if (kcm.isPrintingKey(keyCode)) {
3153 Intent shortcutIntent = mShortcutManager.getIntent(kcm, keyCode,
3154 metaState & ~(KeyEvent.META_META_ON
3155 | KeyEvent.META_META_LEFT_ON | KeyEvent.META_META_RIGHT_ON));
3156 if (shortcutIntent != null) {
3157 shortcutIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
3158 try {
Bart Sears8b1c27c2015-03-18 23:51:02 +00003159 startActivityAsUser(shortcutIntent, UserHandle.CURRENT);
Jeff Brown602ab322012-05-16 13:33:47 -07003160 } catch (ActivityNotFoundException ex) {
3161 Slog.w(TAG, "Dropping shortcut key combination because "
3162 + "the activity to which it is registered was not found: "
3163 + "META+" + KeyEvent.keyCodeToString(keyCode), ex);
3164 }
3165 return -1;
Jeff Brown68b909d2011-12-07 16:36:01 -08003166 }
Jeff Brown68b909d2011-12-07 16:36:01 -08003167 }
3168 }
3169
Jeff Brown6651a632011-11-28 12:59:11 -08003170 // Handle application launch keys.
Jeff Brown602ab322012-05-16 13:33:47 -07003171 if (down && repeatCount == 0 && !keyguardOn) {
Jeff Brown6651a632011-11-28 12:59:11 -08003172 String category = sApplicationLaunchKeyCategories.get(keyCode);
3173 if (category != null) {
Dianne Hackbornf5b86712011-12-05 17:42:41 -08003174 Intent intent = Intent.makeMainSelectorActivity(Intent.ACTION_MAIN, category);
Jeff Brown6651a632011-11-28 12:59:11 -08003175 intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
3176 try {
Bart Sears8b1c27c2015-03-18 23:51:02 +00003177 startActivityAsUser(intent, UserHandle.CURRENT);
Jeff Brown6651a632011-11-28 12:59:11 -08003178 } catch (ActivityNotFoundException ex) {
3179 Slog.w(TAG, "Dropping application launch key because "
3180 + "the activity to which it is registered was not found: "
3181 + "keyCode=" + keyCode + ", category=" + category, ex);
3182 }
Jeff Brown68b909d2011-12-07 16:36:01 -08003183 return -1;
Jeff Brown6651a632011-11-28 12:59:11 -08003184 }
3185 }
3186
Michael Wright61c46752014-08-21 16:57:33 -07003187 // Display task switcher for ALT-TAB.
Jeff Brown68b909d2011-12-07 16:36:01 -08003188 if (down && repeatCount == 0 && keyCode == KeyEvent.KEYCODE_TAB) {
Michael Wrightd847ad52015-10-24 13:24:15 +01003189 if (mRecentAppsHeldModifiers == 0 && !keyguardOn && isUserSetupComplete()) {
Jeff Brown68b909d2011-12-07 16:36:01 -08003190 final int shiftlessModifiers = event.getModifiers() & ~KeyEvent.META_SHIFT_MASK;
Michael Wright61c46752014-08-21 16:57:33 -07003191 if (KeyEvent.metaStateHasModifiers(shiftlessModifiers, KeyEvent.META_ALT_ON)) {
Winson Chung1e8d71b2014-05-16 17:05:22 -07003192 mRecentAppsHeldModifiers = shiftlessModifiers;
3193 showRecentApps(true);
Jeff Brown68b909d2011-12-07 16:36:01 -08003194 return -1;
3195 }
3196 }
Winson Chung1e8d71b2014-05-16 17:05:22 -07003197 } else if (!down && mRecentAppsHeldModifiers != 0
3198 && (metaState & mRecentAppsHeldModifiers) == 0) {
3199 mRecentAppsHeldModifiers = 0;
Winson Chungcdcd4872014-08-05 18:00:13 -07003200 hideRecentApps(true, false);
Jeff Brown68b909d2011-12-07 16:36:01 -08003201 }
3202
Yohei Yukawaae61f712015-12-09 13:00:10 -08003203 // Handle input method switching.
Jeff Browncf39bdf2012-05-18 14:41:19 -07003204 if (down && repeatCount == 0
3205 && (keyCode == KeyEvent.KEYCODE_LANGUAGE_SWITCH
3206 || (keyCode == KeyEvent.KEYCODE_SPACE
Yohei Yukawaae61f712015-12-09 13:00:10 -08003207 && (metaState & KeyEvent.META_META_MASK) != 0))) {
3208 final boolean forwardDirection = (metaState & KeyEvent.META_SHIFT_MASK) == 0;
3209 mWindowManagerFuncs.switchInputMethod(forwardDirection);
Jeff Browncf39bdf2012-05-18 14:41:19 -07003210 return -1;
3211 }
3212 if (mLanguageSwitchKeyPressed && !down
3213 && (keyCode == KeyEvent.KEYCODE_LANGUAGE_SWITCH
3214 || keyCode == KeyEvent.KEYCODE_SPACE)) {
3215 mLanguageSwitchKeyPressed = false;
3216 return -1;
3217 }
3218
Jeff Brown13f00f02014-10-31 14:45:50 -07003219 if (isValidGlobalKey(keyCode)
3220 && mGlobalKeyManager.handleGlobalKey(mContext, keyCode, event)) {
Justin Kohd378ad72013-04-01 12:18:26 -07003221 return -1;
3222 }
3223
Muyuan Li94ce94e2016-02-24 16:20:54 -08003224 if (down) {
3225 long shortcutCode = (long) keyCode;
3226 if (event.isCtrlPressed()) {
3227 shortcutCode |= ((long) KeyEvent.META_CTRL_ON) << Integer.SIZE;
3228 }
3229
3230 if (event.isAltPressed()) {
3231 shortcutCode |= ((long) KeyEvent.META_ALT_ON) << Integer.SIZE;
3232 }
3233
3234 if (event.isShiftPressed()) {
3235 shortcutCode |= ((long) KeyEvent.META_SHIFT_ON) << Integer.SIZE;
3236 }
3237
3238 if (event.isMetaPressed()) {
3239 shortcutCode |= ((long) KeyEvent.META_META_ON) << Integer.SIZE;
3240 }
3241
3242 IShortcutService shortcutService = mShortcutKeyServices.get(shortcutCode);
3243 if (shortcutService != null) {
3244 try {
3245 shortcutService.notifyShortcutKeyPressed(shortcutCode);
3246 } catch (RemoteException e) {
3247 mShortcutKeyServices.delete(shortcutCode);
3248 }
3249 return -1;
3250 }
3251 }
3252
Michael Wright6a62e552014-06-03 19:19:48 -07003253 // Reserve all the META modifier combos for system behavior
Michael Wrightce0c13a2014-07-30 10:49:21 -07003254 if ((metaState & KeyEvent.META_META_ON) != 0) {
Michael Wright6a62e552014-06-03 19:19:48 -07003255 return -1;
3256 }
3257
Jeff Brown68b909d2011-12-07 16:36:01 -08003258 // Let the application handle the key.
Jeff Brownd5bb82d2011-10-12 13:57:59 -07003259 return 0;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003260 }
3261
Jeff Brown3915bb82010-11-05 15:02:16 -07003262 /** {@inheritDoc} */
3263 @Override
Jeff Brown49ed71d2010-12-06 17:13:33 -08003264 public KeyEvent dispatchUnhandledKey(WindowState win, KeyEvent event, int policyFlags) {
Jeff Brown54875002011-04-06 15:33:01 -07003265 // Note: This method is only called if the initial down was unhandled.
Jeff Brown40013652012-05-16 21:22:36 -07003266 if (DEBUG_INPUT) {
Jeff Brown1f245102010-11-18 20:53:46 -08003267 Slog.d(TAG, "Unhandled key: win=" + win + ", action=" + event.getAction()
3268 + ", flags=" + event.getFlags()
3269 + ", keyCode=" + event.getKeyCode()
3270 + ", scanCode=" + event.getScanCode()
3271 + ", metaState=" + event.getMetaState()
3272 + ", repeatCount=" + event.getRepeatCount()
3273 + ", policyFlags=" + policyFlags);
Jeff Brown3915bb82010-11-05 15:02:16 -07003274 }
Jeff Brown49ed71d2010-12-06 17:13:33 -08003275
Jeff Brownfd23e3e2012-05-09 13:34:28 -07003276 KeyEvent fallbackEvent = null;
Jeff Brown49ed71d2010-12-06 17:13:33 -08003277 if ((event.getFlags() & KeyEvent.FLAG_FALLBACK) == 0) {
3278 final KeyCharacterMap kcm = event.getKeyCharacterMap();
Jeff Brownc1fb48d2010-12-08 16:52:09 -08003279 final int keyCode = event.getKeyCode();
3280 final int metaState = event.getMetaState();
Jeff Brownfd23e3e2012-05-09 13:34:28 -07003281 final boolean initialDown = event.getAction() == KeyEvent.ACTION_DOWN
3282 && event.getRepeatCount() == 0;
Jeff Brown49ed71d2010-12-06 17:13:33 -08003283
Jeff Brown54875002011-04-06 15:33:01 -07003284 // Check for fallback actions specified by the key character map.
Jeff Brownfd23e3e2012-05-09 13:34:28 -07003285 final FallbackAction fallbackAction;
3286 if (initialDown) {
3287 fallbackAction = kcm.getFallbackAction(keyCode, metaState);
3288 } else {
3289 fallbackAction = mFallbackActions.get(keyCode);
3290 }
3291
3292 if (fallbackAction != null) {
Jeff Brown40013652012-05-16 21:22:36 -07003293 if (DEBUG_INPUT) {
Jeff Brownfd23e3e2012-05-09 13:34:28 -07003294 Slog.d(TAG, "Fallback: keyCode=" + fallbackAction.keyCode
3295 + " metaState=" + Integer.toHexString(fallbackAction.metaState));
Jeff Brown49ed71d2010-12-06 17:13:33 -08003296 }
3297
Jeff Brownfd23e3e2012-05-09 13:34:28 -07003298 final int flags = event.getFlags() | KeyEvent.FLAG_FALLBACK;
3299 fallbackEvent = KeyEvent.obtain(
Jeff Brown49ed71d2010-12-06 17:13:33 -08003300 event.getDownTime(), event.getEventTime(),
Jeff Brownfd23e3e2012-05-09 13:34:28 -07003301 event.getAction(), fallbackAction.keyCode,
3302 event.getRepeatCount(), fallbackAction.metaState,
Jeff Brown49ed71d2010-12-06 17:13:33 -08003303 event.getDeviceId(), event.getScanCode(),
3304 flags, event.getSource(), null);
Jeff Brownfd23e3e2012-05-09 13:34:28 -07003305
3306 if (!interceptFallback(win, fallbackEvent, policyFlags)) {
3307 fallbackEvent.recycle();
3308 fallbackEvent = null;
Jeff Brown49ed71d2010-12-06 17:13:33 -08003309 }
Jeff Brownfd23e3e2012-05-09 13:34:28 -07003310
3311 if (initialDown) {
3312 mFallbackActions.put(keyCode, fallbackAction);
3313 } else if (event.getAction() == KeyEvent.ACTION_UP) {
3314 mFallbackActions.remove(keyCode);
3315 fallbackAction.recycle();
3316 }
Jeff Brown49ed71d2010-12-06 17:13:33 -08003317 }
3318 }
3319
Jeff Brown40013652012-05-16 21:22:36 -07003320 if (DEBUG_INPUT) {
Jeff Brownfd23e3e2012-05-09 13:34:28 -07003321 if (fallbackEvent == null) {
3322 Slog.d(TAG, "No fallback.");
3323 } else {
3324 Slog.d(TAG, "Performing fallback: " + fallbackEvent);
3325 }
Jeff Brown49ed71d2010-12-06 17:13:33 -08003326 }
Jeff Brownfd23e3e2012-05-09 13:34:28 -07003327 return fallbackEvent;
Jeff Brown3915bb82010-11-05 15:02:16 -07003328 }
3329
Jeff Brownfd23e3e2012-05-09 13:34:28 -07003330 private boolean interceptFallback(WindowState win, KeyEvent fallbackEvent, int policyFlags) {
Jeff Brown037c33e2014-04-09 00:31:55 -07003331 int actions = interceptKeyBeforeQueueing(fallbackEvent, policyFlags);
Jeff Brownfd23e3e2012-05-09 13:34:28 -07003332 if ((actions & ACTION_PASS_TO_USER) != 0) {
3333 long delayMillis = interceptKeyBeforeDispatching(
3334 win, fallbackEvent, policyFlags);
3335 if (delayMillis == 0) {
3336 return true;
3337 }
3338 }
3339 return false;
Jeff Brown6f2fba42011-02-19 01:08:02 -08003340 }
3341
Muyuan Li94ce94e2016-02-24 16:20:54 -08003342 public void registerShortcutKey(long shortcutCode, IShortcutService shortcutService)
3343 throws RemoteException {
3344 synchronized (mLock) {
3345 IShortcutService service = mShortcutKeyServices.get(shortcutCode);
3346 if (service != null && service.asBinder().isBinderAlive()) {
3347 throw new RemoteException("Key already exists.");
3348 }
3349
3350 mShortcutKeyServices.put(shortcutCode, shortcutService);
3351 }
3352 }
3353
Jeff Brownde7a8ea2012-06-13 18:28:57 -07003354 private void launchAssistLongPressAction() {
3355 performHapticFeedbackLw(null, HapticFeedbackConstants.LONG_PRESS, false);
3356 sendCloseSystemWindows(SYSTEM_DIALOG_REASON_ASSIST);
3357
3358 // launch the search activity
3359 Intent intent = new Intent(Intent.ACTION_SEARCH_LONG_PRESS);
3360 intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
3361 try {
RoboErik8a2cfc32014-05-16 11:19:38 -07003362 // TODO: This only stops the factory-installed search manager.
Jim Miller45308b12012-06-18 19:23:39 -07003363 // Need to formalize an API to handle others
Jeff Brownde7a8ea2012-06-13 18:28:57 -07003364 SearchManager searchManager = getSearchManager();
3365 if (searchManager != null) {
3366 searchManager.stopSearch();
3367 }
Bart Sears8b1c27c2015-03-18 23:51:02 +00003368 startActivityAsUser(intent, UserHandle.CURRENT);
Jeff Brownde7a8ea2012-06-13 18:28:57 -07003369 } catch (ActivityNotFoundException e) {
3370 Slog.w(TAG, "No activity to handle assist long press action.", e);
3371 }
3372 }
3373
Tim Kilbourn0e5f1102015-06-05 16:18:09 -07003374 private void launchAssistAction(String hint, int deviceId) {
Jeff Brownde7a8ea2012-06-13 18:28:57 -07003375 sendCloseSystemWindows(SYSTEM_DIALOG_REASON_ASSIST);
Maurice Lam39d13812015-07-23 20:49:20 -07003376 if (!isUserSetupComplete()) {
3377 // Disable opening assist window during setup
3378 return;
3379 }
Tim Kilbourn0e5f1102015-06-05 16:18:09 -07003380 Bundle args = null;
3381 if (deviceId > Integer.MIN_VALUE) {
3382 args = new Bundle();
3383 args.putInt(Intent.EXTRA_ASSIST_INPUT_DEVICE_ID, deviceId);
Jeff Brownde7a8ea2012-06-13 18:28:57 -07003384 }
Jorim Jaggi165ce062015-07-06 16:18:11 -07003385 if ((mContext.getResources().getConfiguration().uiMode
3386 & Configuration.UI_MODE_TYPE_MASK) == Configuration.UI_MODE_TYPE_TELEVISION) {
3387 // On TV, use legacy handling until assistants are implemented in the proper way.
3388 ((SearchManager) mContext.getSystemService(Context.SEARCH_SERVICE))
3389 .launchLegacyAssist(hint, UserHandle.myUserId(), args);
3390 } else {
3391 try {
3392 if (hint != null) {
3393 if (args == null) {
3394 args = new Bundle();
3395 }
3396 args.putBoolean(hint, true);
3397 }
3398 IStatusBarService statusbar = getStatusBarService();
3399 if (statusbar != null) {
3400 statusbar.startAssist(args);
3401 }
3402 } catch (RemoteException e) {
3403 Slog.e(TAG, "RemoteException when starting assist", e);
3404 // re-acquire status bar service next time it is needed.
3405 mStatusBarService = null;
3406 }
3407 }
Jeff Brownde7a8ea2012-06-13 18:28:57 -07003408 }
3409
Bart Sears8b1c27c2015-03-18 23:51:02 +00003410 private void startActivityAsUser(Intent intent, UserHandle handle) {
3411 if (isUserSetupComplete()) {
3412 mContext.startActivityAsUser(intent, handle);
3413 } else {
3414 Slog.i(TAG, "Not starting activity because user setup is in progress: " + intent);
3415 }
3416 }
3417
Jeff Brownde7a8ea2012-06-13 18:28:57 -07003418 private SearchManager getSearchManager() {
3419 if (mSearchManager == null) {
3420 mSearchManager = (SearchManager) mContext.getSystemService(Context.SEARCH_SERVICE);
3421 }
3422 return mSearchManager;
3423 }
3424
Jeff Browncaca8812013-05-09 13:34:33 -07003425 private void preloadRecentApps() {
3426 mPreloadedRecentApps = true;
3427 try {
3428 IStatusBarService statusbar = getStatusBarService();
3429 if (statusbar != null) {
3430 statusbar.preloadRecentApps();
3431 }
3432 } catch (RemoteException e) {
3433 Slog.e(TAG, "RemoteException when preloading recent apps", e);
3434 // re-acquire status bar service next time it is needed.
3435 mStatusBarService = null;
3436 }
3437 }
3438
3439 private void cancelPreloadRecentApps() {
3440 if (mPreloadedRecentApps) {
3441 mPreloadedRecentApps = false;
3442 try {
3443 IStatusBarService statusbar = getStatusBarService();
3444 if (statusbar != null) {
3445 statusbar.cancelPreloadRecentApps();
3446 }
3447 } catch (RemoteException e) {
Winson Chung1e8d71b2014-05-16 17:05:22 -07003448 Slog.e(TAG, "RemoteException when cancelling recent apps preload", e);
Jeff Browncaca8812013-05-09 13:34:33 -07003449 // re-acquire status bar service next time it is needed.
3450 mStatusBarService = null;
3451 }
3452 }
3453 }
3454
3455 private void toggleRecentApps() {
3456 mPreloadedRecentApps = false; // preloading no longer needs to be canceled
Jeff Browncaca8812013-05-09 13:34:33 -07003457 try {
3458 IStatusBarService statusbar = getStatusBarService();
3459 if (statusbar != null) {
3460 statusbar.toggleRecentApps();
3461 }
3462 } catch (RemoteException e) {
Winson Chung1e8d71b2014-05-16 17:05:22 -07003463 Slog.e(TAG, "RemoteException when toggling recent apps", e);
3464 // re-acquire status bar service next time it is needed.
3465 mStatusBarService = null;
3466 }
3467 }
3468
Craig Mautner84984fa2014-06-19 11:19:20 -07003469 @Override
3470 public void showRecentApps() {
3471 mHandler.removeMessages(MSG_DISPATCH_SHOW_RECENTS);
3472 mHandler.sendEmptyMessage(MSG_DISPATCH_SHOW_RECENTS);
3473 }
3474
Winson Chung1e8d71b2014-05-16 17:05:22 -07003475 private void showRecentApps(boolean triggeredFromAltTab) {
3476 mPreloadedRecentApps = false; // preloading no longer needs to be canceled
3477 try {
3478 IStatusBarService statusbar = getStatusBarService();
3479 if (statusbar != null) {
3480 statusbar.showRecentApps(triggeredFromAltTab);
3481 }
3482 } catch (RemoteException e) {
Jeff Browncaca8812013-05-09 13:34:33 -07003483 Slog.e(TAG, "RemoteException when showing recent apps", e);
3484 // re-acquire status bar service next time it is needed.
3485 mStatusBarService = null;
3486 }
3487 }
3488
Andrei Stingaceanuc22ab792016-01-07 12:39:38 +00003489 private void toggleKeyboardShortcutsMenu() {
Clara Bayarrif2debb12015-07-10 14:47:17 +01003490 try {
3491 IStatusBarService statusbar = getStatusBarService();
3492 if (statusbar != null) {
Andrei Stingaceanuc22ab792016-01-07 12:39:38 +00003493 statusbar.toggleKeyboardShortcutsMenu();
Clara Bayarrif2debb12015-07-10 14:47:17 +01003494 }
3495 } catch (RemoteException e) {
3496 Slog.e(TAG, "RemoteException when showing keyboard shortcuts menu", e);
3497 }
3498 }
3499
Winson Chungcdcd4872014-08-05 18:00:13 -07003500 private void hideRecentApps(boolean triggeredFromAltTab, boolean triggeredFromHome) {
Winson Chung1e8d71b2014-05-16 17:05:22 -07003501 mPreloadedRecentApps = false; // preloading no longer needs to be canceled
3502 try {
3503 IStatusBarService statusbar = getStatusBarService();
3504 if (statusbar != null) {
Winson Chungcdcd4872014-08-05 18:00:13 -07003505 statusbar.hideRecentApps(triggeredFromAltTab, triggeredFromHome);
Winson Chung1e8d71b2014-05-16 17:05:22 -07003506 }
3507 } catch (RemoteException e) {
3508 Slog.e(TAG, "RemoteException when closing recent apps", e);
3509 // re-acquire status bar service next time it is needed.
3510 mStatusBarService = null;
3511 }
3512 }
3513
Filip Gruszczynskia483a1d2015-03-17 19:06:58 +00003514 void launchHomeFromHotKey() {
Bryce Lee662ed802015-04-10 20:11:39 +00003515 launchHomeFromHotKey(true /* awakenFromDreams */, true /*respectKeyguard*/);
Filip Gruszczynskia483a1d2015-03-17 19:06:58 +00003516 }
3517
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003518 /**
3519 * A home key -> launch home action was detected. Take the appropriate action
3520 * given the situation with the keyguard.
3521 */
Bryce Lee662ed802015-04-10 20:11:39 +00003522 void launchHomeFromHotKey(final boolean awakenFromDreams, final boolean respectKeyguard) {
3523 if (respectKeyguard) {
3524 if (isKeyguardShowingAndNotOccluded()) {
3525 // don't launch home if keyguard showing
3526 return;
3527 }
3528
3529 if (!mHideLockScreen && mKeyguardDelegate.isInputRestricted()) {
3530 // when in keyguard restricted mode, must first verify unlock
3531 // before launching home
3532 mKeyguardDelegate.verifyUnlock(new OnKeyguardExitResult() {
3533 @Override
3534 public void onKeyguardExitResult(boolean success) {
3535 if (success) {
3536 try {
3537 ActivityManagerNative.getDefault().stopAppSwitches();
3538 } catch (RemoteException e) {
3539 }
3540 sendCloseSystemWindows(SYSTEM_DIALOG_REASON_HOME_KEY);
3541 startDockOrHome(true /*fromHomeKey*/, awakenFromDreams);
Dianne Hackborn256dd3b2009-05-19 18:51:21 -07003542 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003543 }
Bryce Lee662ed802015-04-10 20:11:39 +00003544 });
3545 return;
3546 }
3547 }
3548
3549 // no keyguard stuff to worry about, just launch home!
3550 try {
3551 ActivityManagerNative.getDefault().stopAppSwitches();
3552 } catch (RemoteException e) {
3553 }
3554 if (mRecentsVisible) {
3555 // Hide Recents and notify it to launch Home
3556 if (awakenFromDreams) {
3557 awakenDreams();
3558 }
Bryce Lee662ed802015-04-10 20:11:39 +00003559 hideRecentApps(false, true);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003560 } else {
Bryce Lee662ed802015-04-10 20:11:39 +00003561 // Otherwise, just launch Home
3562 sendCloseSystemWindows(SYSTEM_DIALOG_REASON_HOME_KEY);
3563 startDockOrHome(true /*fromHomeKey*/, awakenFromDreams);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003564 }
3565 }
3566
John Spurlock04db1762013-05-13 12:46:41 -04003567 private final Runnable mClearHideNavigationFlag = new Runnable() {
3568 @Override
3569 public void run() {
3570 synchronized (mWindowManagerFuncs.getWindowManagerLock()) {
3571 // Clear flags.
3572 mForceClearedSystemUiFlags &=
3573 ~View.SYSTEM_UI_FLAG_HIDE_NAVIGATION;
3574 }
3575 mWindowManagerFuncs.reevaluateStatusBarVisibility();
Dianne Hackborne26ab702011-10-16 13:21:33 -07003576 }
3577 };
3578
3579 /**
3580 * Input handler used while nav bar is hidden. Captures any touch on the screen,
3581 * to determine when the nav bar should be shown and prevent applications from
3582 * receiving those touches.
3583 */
Jeff Brown32cbc38552011-12-01 14:01:49 -08003584 final class HideNavInputEventReceiver extends InputEventReceiver {
3585 public HideNavInputEventReceiver(InputChannel inputChannel, Looper looper) {
3586 super(inputChannel, looper);
3587 }
3588
Dianne Hackborndf89e652011-10-06 22:35:11 -07003589 @Override
Jeff Brown32cbc38552011-12-01 14:01:49 -08003590 public void onInputEvent(InputEvent event) {
Dianne Hackborndf89e652011-10-06 22:35:11 -07003591 boolean handled = false;
3592 try {
Jeff Brown4952dfd2011-11-30 19:23:22 -08003593 if (event instanceof MotionEvent
3594 && (event.getSource() & InputDevice.SOURCE_CLASS_POINTER) != 0) {
3595 final MotionEvent motionEvent = (MotionEvent)event;
3596 if (motionEvent.getAction() == MotionEvent.ACTION_DOWN) {
Dianne Hackborndf89e652011-10-06 22:35:11 -07003597 // When the user taps down, we re-show the nav bar.
3598 boolean changed = false;
John Spurlock04db1762013-05-13 12:46:41 -04003599 synchronized (mWindowManagerFuncs.getWindowManagerLock()) {
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07003600 // Any user activity always causes us to show the
3601 // navigation controls, if they had been hidden.
3602 // We also clear the low profile and only content
3603 // flags so that tapping on the screen will atomically
3604 // restore all currently hidden screen decorations.
3605 int newVal = mResettingSystemUiFlags |
3606 View.SYSTEM_UI_FLAG_HIDE_NAVIGATION |
3607 View.SYSTEM_UI_FLAG_LOW_PROFILE |
3608 View.SYSTEM_UI_FLAG_FULLSCREEN;
Dianne Hackborne26ab702011-10-16 13:21:33 -07003609 if (mResettingSystemUiFlags != newVal) {
3610 mResettingSystemUiFlags = newVal;
Dianne Hackborndf89e652011-10-06 22:35:11 -07003611 changed = true;
3612 }
Dianne Hackborne26ab702011-10-16 13:21:33 -07003613 // We don't allow the system's nav bar to be hidden
3614 // again for 1 second, to prevent applications from
3615 // spamming us and keeping it from being shown.
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07003616 newVal = mForceClearedSystemUiFlags |
3617 View.SYSTEM_UI_FLAG_HIDE_NAVIGATION;
Dianne Hackborne26ab702011-10-16 13:21:33 -07003618 if (mForceClearedSystemUiFlags != newVal) {
3619 mForceClearedSystemUiFlags = newVal;
3620 changed = true;
John Spurlock04db1762013-05-13 12:46:41 -04003621 mHandler.postDelayed(mClearHideNavigationFlag, 1000);
Dianne Hackborne26ab702011-10-16 13:21:33 -07003622 }
Dianne Hackborndf89e652011-10-06 22:35:11 -07003623 }
3624 if (changed) {
3625 mWindowManagerFuncs.reevaluateStatusBarVisibility();
3626 }
3627 }
3628 }
3629 } finally {
Jeff Brown32cbc38552011-12-01 14:01:49 -08003630 finishInputEvent(event, handled);
Dianne Hackborndf89e652011-10-06 22:35:11 -07003631 }
3632 }
Jeff Brown32cbc38552011-12-01 14:01:49 -08003633 }
3634 final InputEventReceiver.Factory mHideNavInputEventReceiverFactory =
3635 new InputEventReceiver.Factory() {
3636 @Override
3637 public InputEventReceiver createInputEventReceiver(
3638 InputChannel inputChannel, Looper looper) {
3639 return new HideNavInputEventReceiver(inputChannel, looper);
3640 }
Dianne Hackborndf89e652011-10-06 22:35:11 -07003641 };
3642
3643 @Override
3644 public int adjustSystemUiVisibilityLw(int visibility) {
John Spurlock5b9145b2013-08-20 15:13:47 -04003645 mStatusBarController.adjustSystemUiVisibilityLw(mLastSystemUiFlags, visibility);
3646 mNavigationBarController.adjustSystemUiVisibilityLw(mLastSystemUiFlags, visibility);
Winson Chungd42a6cf2014-06-03 16:24:04 -07003647 mRecentsVisible = (visibility & View.RECENT_APPS_VISIBLE) > 0;
John Spurlock27735a42013-08-14 17:57:38 -04003648
Dianne Hackborndf89e652011-10-06 22:35:11 -07003649 // Reset any bits in mForceClearingStatusBarVisibility that
3650 // are now clear.
Dianne Hackborne26ab702011-10-16 13:21:33 -07003651 mResettingSystemUiFlags &= visibility;
Dianne Hackborndf89e652011-10-06 22:35:11 -07003652 // Clear any bits in the new visibility that are currently being
3653 // force cleared, before reporting it.
Dianne Hackborne26ab702011-10-16 13:21:33 -07003654 return visibility & ~mResettingSystemUiFlags
3655 & ~mForceClearedSystemUiFlags;
Dianne Hackborndf89e652011-10-06 22:35:11 -07003656 }
3657
Craig Mautner69b08182012-09-05 13:07:13 -07003658 @Override
Jorim Jaggi0ffd49c2016-02-12 15:04:21 -08003659 public boolean getInsetHintLw(WindowManager.LayoutParams attrs, int displayRotation,
Filip Gruszczynski2987f612015-06-30 15:03:30 -07003660 Rect outContentInsets, Rect outStableInsets, Rect outOutsets) {
John Spurlockc6d1c602014-01-17 15:22:06 -05003661 final int fl = PolicyControl.getWindowFlags(null, attrs);
John Spurlock1db8b682014-02-18 11:18:59 -05003662 final int sysuiVis = PolicyControl.getSystemUiVisibility(null, attrs);
3663 final int systemUiVisibility = (sysuiVis | attrs.subtreeSystemUiVisibility);
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07003664
Filip Gruszczynski2987f612015-06-30 15:03:30 -07003665 final boolean useOutsets = outOutsets != null && shouldUseOutsets(attrs, fl);
3666 if (useOutsets) {
3667 int outset = ScreenShapeHelper.getWindowOutsetBottomPx(mContext.getResources());
3668 if (outset > 0) {
3669 if (displayRotation == Surface.ROTATION_0) {
3670 outOutsets.bottom += outset;
3671 } else if (displayRotation == Surface.ROTATION_90) {
3672 outOutsets.right += outset;
3673 } else if (displayRotation == Surface.ROTATION_180) {
3674 outOutsets.top += outset;
3675 } else if (displayRotation == Surface.ROTATION_270) {
3676 outOutsets.left += outset;
3677 }
3678 }
3679 }
3680
Dianne Hackborn5b5cc4d2012-05-16 13:15:00 -07003681 if ((fl & (FLAG_LAYOUT_IN_SCREEN | FLAG_LAYOUT_INSET_DECOR))
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003682 == (FLAG_LAYOUT_IN_SCREEN | FLAG_LAYOUT_INSET_DECOR)) {
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07003683 int availRight, availBottom;
Alan Viverette5a0f4ec2013-10-07 15:10:29 -07003684 if (canHideNavigationBar() &&
Dianne Hackborn5b5cc4d2012-05-16 13:15:00 -07003685 (systemUiVisibility & View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION) != 0) {
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07003686 availRight = mUnrestrictedScreenLeft + mUnrestrictedScreenWidth;
3687 availBottom = mUnrestrictedScreenTop + mUnrestrictedScreenHeight;
3688 } else {
3689 availRight = mRestrictedScreenLeft + mRestrictedScreenWidth;
3690 availBottom = mRestrictedScreenTop + mRestrictedScreenHeight;
3691 }
Dianne Hackborn5b5cc4d2012-05-16 13:15:00 -07003692 if ((systemUiVisibility & View.SYSTEM_UI_FLAG_LAYOUT_STABLE) != 0) {
3693 if ((fl & FLAG_FULLSCREEN) != 0) {
Adrian Roos37d7a682014-11-06 18:15:16 +01003694 outContentInsets.set(mStableFullscreenLeft, mStableFullscreenTop,
Dianne Hackborn5b5cc4d2012-05-16 13:15:00 -07003695 availRight - mStableFullscreenRight,
3696 availBottom - mStableFullscreenBottom);
3697 } else {
Adrian Roos37d7a682014-11-06 18:15:16 +01003698 outContentInsets.set(mStableLeft, mStableTop,
Dianne Hackborn5b5cc4d2012-05-16 13:15:00 -07003699 availRight - mStableRight, availBottom - mStableBottom);
3700 }
Dianne Hackbornc652de82013-02-15 16:32:56 -08003701 } else if ((fl & FLAG_FULLSCREEN) != 0 || (fl & FLAG_LAYOUT_IN_OVERSCAN) != 0) {
Adrian Roos37d7a682014-11-06 18:15:16 +01003702 outContentInsets.setEmpty();
Dianne Hackborn5b5cc4d2012-05-16 13:15:00 -07003703 } else if ((systemUiVisibility & (View.SYSTEM_UI_FLAG_FULLSCREEN
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07003704 | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN)) == 0) {
Adrian Roos37d7a682014-11-06 18:15:16 +01003705 outContentInsets.set(mCurLeft, mCurTop,
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07003706 availRight - mCurRight, availBottom - mCurBottom);
3707 } else {
Adrian Roos37d7a682014-11-06 18:15:16 +01003708 outContentInsets.set(mCurLeft, mCurTop,
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07003709 availRight - mCurRight, availBottom - mCurBottom);
3710 }
Adrian Roos37d7a682014-11-06 18:15:16 +01003711
3712 outStableInsets.set(mStableLeft, mStableTop,
3713 availRight - mStableRight, availBottom - mStableBottom);
Jorim Jaggi0ffd49c2016-02-12 15:04:21 -08003714 return mForceShowSystemBars;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003715 }
Adrian Roos37d7a682014-11-06 18:15:16 +01003716 outContentInsets.setEmpty();
3717 outStableInsets.setEmpty();
Jorim Jaggi0ffd49c2016-02-12 15:04:21 -08003718 return mForceShowSystemBars;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003719 }
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07003720
Filip Gruszczynski2987f612015-06-30 15:03:30 -07003721 private boolean shouldUseOutsets(WindowManager.LayoutParams attrs, int fl) {
3722 return attrs.type == TYPE_WALLPAPER || (fl & (WindowManager.LayoutParams.FLAG_FULLSCREEN
3723 | WindowManager.LayoutParams.FLAG_LAYOUT_IN_OVERSCAN)) != 0;
3724 }
3725
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003726 /** {@inheritDoc} */
Craig Mautner69b08182012-09-05 13:07:13 -07003727 @Override
3728 public void beginLayoutLw(boolean isDefaultDisplay, int displayWidth, int displayHeight,
Sriram Viswanathan9ebbe6a2015-11-16 17:59:22 -08003729 int displayRotation, int uiMode) {
Filip Gruszczynski2987f612015-06-30 15:03:30 -07003730 mDisplayRotation = displayRotation;
Dianne Hackbornc652de82013-02-15 16:32:56 -08003731 final int overscanLeft, overscanTop, overscanRight, overscanBottom;
3732 if (isDefaultDisplay) {
3733 switch (displayRotation) {
3734 case Surface.ROTATION_90:
3735 overscanLeft = mOverscanTop;
3736 overscanTop = mOverscanRight;
3737 overscanRight = mOverscanBottom;
3738 overscanBottom = mOverscanLeft;
3739 break;
3740 case Surface.ROTATION_180:
3741 overscanLeft = mOverscanRight;
3742 overscanTop = mOverscanBottom;
3743 overscanRight = mOverscanLeft;
3744 overscanBottom = mOverscanTop;
3745 break;
3746 case Surface.ROTATION_270:
3747 overscanLeft = mOverscanBottom;
3748 overscanTop = mOverscanLeft;
3749 overscanRight = mOverscanTop;
3750 overscanBottom = mOverscanRight;
3751 break;
3752 default:
3753 overscanLeft = mOverscanLeft;
3754 overscanTop = mOverscanTop;
3755 overscanRight = mOverscanRight;
3756 overscanBottom = mOverscanBottom;
3757 break;
3758 }
3759 } else {
3760 overscanLeft = 0;
3761 overscanTop = 0;
3762 overscanRight = 0;
3763 overscanBottom = 0;
3764 }
Dianne Hackborn313440842013-02-19 19:22:59 -08003765 mOverscanScreenLeft = mRestrictedOverscanScreenLeft = 0;
3766 mOverscanScreenTop = mRestrictedOverscanScreenTop = 0;
3767 mOverscanScreenWidth = mRestrictedOverscanScreenWidth = displayWidth;
3768 mOverscanScreenHeight = mRestrictedOverscanScreenHeight = displayHeight;
Dianne Hackbornc652de82013-02-15 16:32:56 -08003769 mSystemLeft = 0;
3770 mSystemTop = 0;
3771 mSystemRight = displayWidth;
3772 mSystemBottom = displayHeight;
3773 mUnrestrictedScreenLeft = overscanLeft;
3774 mUnrestrictedScreenTop = overscanTop;
3775 mUnrestrictedScreenWidth = displayWidth - overscanLeft - overscanRight;
3776 mUnrestrictedScreenHeight = displayHeight - overscanTop - overscanBottom;
3777 mRestrictedScreenLeft = mUnrestrictedScreenLeft;
3778 mRestrictedScreenTop = mUnrestrictedScreenTop;
John Spurlockad3e6cb2013-04-30 08:47:43 -04003779 mRestrictedScreenWidth = mSystemGestures.screenWidth = mUnrestrictedScreenWidth;
3780 mRestrictedScreenHeight = mSystemGestures.screenHeight = mUnrestrictedScreenHeight;
Dianne Hackborne30e02f2014-05-27 18:24:45 -07003781 mDockLeft = mContentLeft = mVoiceContentLeft = mStableLeft = mStableFullscreenLeft
Dianne Hackbornc652de82013-02-15 16:32:56 -08003782 = mCurLeft = mUnrestrictedScreenLeft;
Dianne Hackborne30e02f2014-05-27 18:24:45 -07003783 mDockTop = mContentTop = mVoiceContentTop = mStableTop = mStableFullscreenTop
Dianne Hackbornc652de82013-02-15 16:32:56 -08003784 = mCurTop = mUnrestrictedScreenTop;
Dianne Hackborne30e02f2014-05-27 18:24:45 -07003785 mDockRight = mContentRight = mVoiceContentRight = mStableRight = mStableFullscreenRight
Dianne Hackbornc652de82013-02-15 16:32:56 -08003786 = mCurRight = displayWidth - overscanRight;
Dianne Hackborne30e02f2014-05-27 18:24:45 -07003787 mDockBottom = mContentBottom = mVoiceContentBottom = mStableBottom = mStableFullscreenBottom
Dianne Hackbornc652de82013-02-15 16:32:56 -08003788 = mCurBottom = displayHeight - overscanBottom;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003789 mDockLayer = 0x10000000;
Dianne Hackborn5c58de32012-04-28 19:52:37 -07003790 mStatusBarLayer = -1;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003791
Daniel Sandler8956dbb2011-04-22 07:55:02 -04003792 // start with the current dock rect, which will be (0,0,displayWidth,displayHeight)
3793 final Rect pf = mTmpParentFrame;
3794 final Rect df = mTmpDisplayFrame;
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003795 final Rect of = mTmpOverscanFrame;
Daniel Sandler8956dbb2011-04-22 07:55:02 -04003796 final Rect vf = mTmpVisibleFrame;
John Spurlock46646232013-09-30 22:32:42 -04003797 final Rect dcf = mTmpDecorFrame;
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003798 pf.left = df.left = of.left = vf.left = mDockLeft;
3799 pf.top = df.top = of.top = vf.top = mDockTop;
3800 pf.right = df.right = of.right = vf.right = mDockRight;
3801 pf.bottom = df.bottom = of.bottom = vf.bottom = mDockBottom;
John Spurlock46646232013-09-30 22:32:42 -04003802 dcf.setEmpty(); // Decor frame N/A for system bars.
Daniel Sandler8956dbb2011-04-22 07:55:02 -04003803
Craig Mautner69b08182012-09-05 13:07:13 -07003804 if (isDefaultDisplay) {
3805 // For purposes of putting out fake window up to steal focus, we will
3806 // drive nav being hidden only by whether it is requested.
John Spurlocke1f366f2013-08-05 12:22:40 -04003807 final int sysui = mLastSystemUiFlags;
3808 boolean navVisible = (sysui & View.SYSTEM_UI_FLAG_HIDE_NAVIGATION) == 0;
Adrian Roosea562512014-05-05 13:33:03 +02003809 boolean navTranslucent = (sysui
Jorim Jaggi4fa78922015-11-30 17:13:56 -08003810 & (View.NAVIGATION_BAR_TRANSLUCENT | View.NAVIGATION_BAR_TRANSPARENT)) != 0;
John Spurlockf1a36642013-10-12 17:50:42 -04003811 boolean immersive = (sysui & View.SYSTEM_UI_FLAG_IMMERSIVE) != 0;
3812 boolean immersiveSticky = (sysui & View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY) != 0;
3813 boolean navAllowedHidden = immersive || immersiveSticky;
3814 navTranslucent &= !immersiveSticky; // transient trumps translucent
Adrian Roos4fb3ee32014-08-22 19:29:09 +02003815 boolean isKeyguardShowing = isStatusBarKeyguard() && !mHideLockScreen;
3816 if (!isKeyguardShowing) {
3817 navTranslucent &= areTranslucentBarsAllowed();
3818 }
Dianne Hackborne26ab702011-10-16 13:21:33 -07003819
Craig Mautner69b08182012-09-05 13:07:13 -07003820 // When the navigation bar isn't visible, we put up a fake
3821 // input window to catch all touch events. This way we can
3822 // detect when the user presses anywhere to bring back the nav
3823 // bar and ensure the application doesn't see the event.
John Spurlockf1a36642013-10-12 17:50:42 -04003824 if (navVisible || navAllowedHidden) {
Selim Cinekf83e8242015-05-19 18:08:14 -07003825 if (mInputConsumer != null) {
3826 mInputConsumer.dismiss();
3827 mInputConsumer = null;
Craig Mautner69b08182012-09-05 13:07:13 -07003828 }
Selim Cinekf83e8242015-05-19 18:08:14 -07003829 } else if (mInputConsumer == null) {
3830 mInputConsumer = mWindowManagerFuncs.addInputConsumer(mHandler.getLooper(),
3831 mHideNavInputEventReceiverFactory);
Dianne Hackborne26ab702011-10-16 13:21:33 -07003832 }
Dianne Hackborne26ab702011-10-16 13:21:33 -07003833
Craig Mautner69b08182012-09-05 13:07:13 -07003834 // For purposes of positioning and showing the nav bar, if we have
3835 // decided that it can't be hidden (because of the screen aspect ratio),
3836 // then take that into account.
Alan Viverette5a0f4ec2013-10-07 15:10:29 -07003837 navVisible |= !canHideNavigationBar();
Dianne Hackbornf87d1962012-04-04 12:48:24 -07003838
Filip Gruszczynski83dd9552015-09-17 17:50:36 -07003839 boolean updateSysUiVisibility = layoutNavigationBar(displayWidth, displayHeight,
Sriram Viswanathan9ebbe6a2015-11-16 17:59:22 -08003840 displayRotation, uiMode, overscanRight, overscanBottom, dcf, navVisible, navTranslucent,
Filip Gruszczynski83dd9552015-09-17 17:50:36 -07003841 navAllowedHidden);
Craig Mautnereda67292013-04-28 13:50:14 -07003842 if (DEBUG_LAYOUT) Slog.i(TAG, String.format("mDock rect: (%d,%d - %d,%d)",
Craig Mautner69b08182012-09-05 13:07:13 -07003843 mDockLeft, mDockTop, mDockRight, mDockBottom));
Filip Gruszczynski83dd9552015-09-17 17:50:36 -07003844 updateSysUiVisibility |= layoutStatusBar(pf, df, of, vf, dcf, sysui, isKeyguardShowing);
John Spurlockad3e6cb2013-04-30 08:47:43 -04003845 if (updateSysUiVisibility) {
3846 updateSystemUiVisibilityLw();
3847 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003848 }
3849 }
3850
Filip Gruszczynski83dd9552015-09-17 17:50:36 -07003851 private boolean layoutStatusBar(Rect pf, Rect df, Rect of, Rect vf, Rect dcf, int sysui,
3852 boolean isKeyguardShowing) {
3853 // decide where the status bar goes ahead of time
3854 if (mStatusBar != null) {
3855 // apply any navigation bar insets
3856 pf.left = df.left = of.left = mUnrestrictedScreenLeft;
3857 pf.top = df.top = of.top = mUnrestrictedScreenTop;
3858 pf.right = df.right = of.right = mUnrestrictedScreenWidth + mUnrestrictedScreenLeft;
3859 pf.bottom = df.bottom = of.bottom = mUnrestrictedScreenHeight
3860 + mUnrestrictedScreenTop;
3861 vf.left = mStableLeft;
3862 vf.top = mStableTop;
3863 vf.right = mStableRight;
3864 vf.bottom = mStableBottom;
3865
3866 mStatusBarLayer = mStatusBar.getSurfaceLayer();
3867
3868 // Let the status bar determine its size.
3869 mStatusBar.computeFrameLw(pf /* parentFrame */, df /* displayFrame */,
3870 vf /* overlayFrame */, vf /* contentFrame */, vf /* visibleFrame */,
3871 dcf /* decorFrame */, vf /* stableFrame */, vf /* outsetFrame */);
3872
3873 // For layout, the status bar is always at the top with our fixed height.
3874 mStableTop = mUnrestrictedScreenTop + mStatusBarHeight;
3875
3876 boolean statusBarTransient = (sysui & View.STATUS_BAR_TRANSIENT) != 0;
3877 boolean statusBarTranslucent = (sysui
Jorim Jaggi4fa78922015-11-30 17:13:56 -08003878 & (View.STATUS_BAR_TRANSLUCENT | View.STATUS_BAR_TRANSPARENT)) != 0;
Filip Gruszczynski83dd9552015-09-17 17:50:36 -07003879 if (!isKeyguardShowing) {
3880 statusBarTranslucent &= areTranslucentBarsAllowed();
3881 }
3882
3883 // If the status bar is hidden, we don't want to cause
3884 // windows behind it to scroll.
3885 if (mStatusBar.isVisibleLw() && !statusBarTransient) {
3886 // Status bar may go away, so the screen area it occupies
3887 // is available to apps but just covering them when the
3888 // status bar is visible.
3889 mDockTop = mUnrestrictedScreenTop + mStatusBarHeight;
3890
3891 mContentTop = mVoiceContentTop = mCurTop = mDockTop;
3892 mContentBottom = mVoiceContentBottom = mCurBottom = mDockBottom;
3893 mContentLeft = mVoiceContentLeft = mCurLeft = mDockLeft;
3894 mContentRight = mVoiceContentRight = mCurRight = mDockRight;
3895
3896 if (DEBUG_LAYOUT) Slog.v(TAG, "Status bar: " +
3897 String.format(
3898 "dock=[%d,%d][%d,%d] content=[%d,%d][%d,%d] cur=[%d,%d][%d,%d]",
3899 mDockLeft, mDockTop, mDockRight, mDockBottom,
3900 mContentLeft, mContentTop, mContentRight, mContentBottom,
3901 mCurLeft, mCurTop, mCurRight, mCurBottom));
3902 }
3903 if (mStatusBar.isVisibleLw() && !mStatusBar.isAnimatingLw()
3904 && !statusBarTransient && !statusBarTranslucent
3905 && !mStatusBarController.wasRecentlyTranslucent()) {
3906 // If the opaque status bar is currently requested to be visible,
3907 // and not in the process of animating on or off, then
3908 // we can tell the app that it is covered by it.
3909 mSystemTop = mUnrestrictedScreenTop + mStatusBarHeight;
3910 }
3911 if (mStatusBarController.checkHiddenLw()) {
3912 return true;
3913 }
3914 }
3915 return false;
3916 }
3917
3918 private boolean layoutNavigationBar(int displayWidth, int displayHeight, int displayRotation,
Sriram Viswanathan9ebbe6a2015-11-16 17:59:22 -08003919 int uiMode, int overscanRight, int overscanBottom, Rect dcf, boolean navVisible,
Filip Gruszczynski83dd9552015-09-17 17:50:36 -07003920 boolean navTranslucent, boolean navAllowedHidden) {
3921 if (mNavigationBar != null) {
3922 boolean transientNavBarShowing = mNavigationBarController.isTransientShowing();
3923 // Force the navigation bar to its appropriate place and
3924 // size. We need to do this directly, instead of relying on
3925 // it to bubble up from the nav bar, because this needs to
3926 // change atomically with screen rotations.
Jorim Jaggi737af722015-12-31 10:42:27 +01003927 mNavigationBarOnBottom = isNavigationBarOnBottom(displayWidth, displayHeight);
Filip Gruszczynski83dd9552015-09-17 17:50:36 -07003928 if (mNavigationBarOnBottom) {
3929 // It's a system nav bar or a portrait screen; nav bar goes on bottom.
3930 int top = displayHeight - overscanBottom
Sriram Viswanathan9ebbe6a2015-11-16 17:59:22 -08003931 - getNavigationBarHeight(displayRotation, uiMode);
Filip Gruszczynski83dd9552015-09-17 17:50:36 -07003932 mTmpNavigationFrame.set(0, top, displayWidth, displayHeight - overscanBottom);
3933 mStableBottom = mStableFullscreenBottom = mTmpNavigationFrame.top;
3934 if (transientNavBarShowing) {
3935 mNavigationBarController.setBarShowingLw(true);
3936 } else if (navVisible) {
3937 mNavigationBarController.setBarShowingLw(true);
3938 mDockBottom = mTmpNavigationFrame.top;
3939 mRestrictedScreenHeight = mDockBottom - mRestrictedScreenTop;
3940 mRestrictedOverscanScreenHeight = mDockBottom - mRestrictedOverscanScreenTop;
3941 } else {
3942 // We currently want to hide the navigation UI.
3943 mNavigationBarController.setBarShowingLw(false);
3944 }
3945 if (navVisible && !navTranslucent && !navAllowedHidden
3946 && !mNavigationBar.isAnimatingLw()
3947 && !mNavigationBarController.wasRecentlyTranslucent()) {
3948 // If the opaque nav bar is currently requested to be visible,
3949 // and not in the process of animating on or off, then
3950 // we can tell the app that it is covered by it.
3951 mSystemBottom = mTmpNavigationFrame.top;
3952 }
3953 } else {
3954 // Landscape screen; nav bar goes to the right.
3955 int left = displayWidth - overscanRight
Sriram Viswanathan9ebbe6a2015-11-16 17:59:22 -08003956 - getNavigationBarWidth(displayRotation, uiMode);
Filip Gruszczynski83dd9552015-09-17 17:50:36 -07003957 mTmpNavigationFrame.set(left, 0, displayWidth - overscanRight, displayHeight);
3958 mStableRight = mStableFullscreenRight = mTmpNavigationFrame.left;
3959 if (transientNavBarShowing) {
3960 mNavigationBarController.setBarShowingLw(true);
3961 } else if (navVisible) {
3962 mNavigationBarController.setBarShowingLw(true);
3963 mDockRight = mTmpNavigationFrame.left;
3964 mRestrictedScreenWidth = mDockRight - mRestrictedScreenLeft;
3965 mRestrictedOverscanScreenWidth = mDockRight - mRestrictedOverscanScreenLeft;
3966 } else {
3967 // We currently want to hide the navigation UI.
3968 mNavigationBarController.setBarShowingLw(false);
3969 }
3970 if (navVisible && !navTranslucent && !navAllowedHidden
3971 && !mNavigationBar.isAnimatingLw()
3972 && !mNavigationBarController.wasRecentlyTranslucent()) {
3973 // If the nav bar is currently requested to be visible,
3974 // and not in the process of animating on or off, then
3975 // we can tell the app that it is covered by it.
3976 mSystemRight = mTmpNavigationFrame.left;
3977 }
3978 }
3979 // Make sure the content and current rectangles are updated to
3980 // account for the restrictions from the navigation bar.
3981 mContentTop = mVoiceContentTop = mCurTop = mDockTop;
3982 mContentBottom = mVoiceContentBottom = mCurBottom = mDockBottom;
3983 mContentLeft = mVoiceContentLeft = mCurLeft = mDockLeft;
3984 mContentRight = mVoiceContentRight = mCurRight = mDockRight;
3985 mStatusBarLayer = mNavigationBar.getSurfaceLayer();
3986 // And compute the final frame.
3987 mNavigationBar.computeFrameLw(mTmpNavigationFrame, mTmpNavigationFrame,
3988 mTmpNavigationFrame, mTmpNavigationFrame, mTmpNavigationFrame, dcf,
3989 mTmpNavigationFrame, mTmpNavigationFrame);
3990 if (DEBUG_LAYOUT) Slog.i(TAG, "mNavigationBar frame: " + mTmpNavigationFrame);
3991 if (mNavigationBarController.checkHiddenLw()) {
3992 return true;
3993 }
3994 }
3995 return false;
3996 }
3997
Jorim Jaggi737af722015-12-31 10:42:27 +01003998 private boolean isNavigationBarOnBottom(int displayWidth, int displayHeight) {
3999 return !mNavigationBarCanMove || displayWidth < displayHeight;
4000 }
4001
Dianne Hackborn85afd1b2012-05-13 13:31:06 -07004002 /** {@inheritDoc} */
Craig Mautner967212c2013-04-13 21:10:58 -07004003 @Override
John Spurlock46646232013-09-30 22:32:42 -04004004 public int getSystemDecorLayerLw() {
Bryce Lee2ed3e5f2015-04-01 22:09:19 +00004005 if (mStatusBar != null && mStatusBar.isVisibleLw()) {
4006 return mStatusBar.getSurfaceLayer();
4007 }
4008
4009 if (mNavigationBar != null && mNavigationBar.isVisibleLw()) {
4010 return mNavigationBar.getSurfaceLayer();
4011 }
4012
Dianne Hackborn85afd1b2012-05-13 13:31:06 -07004013 return 0;
4014 }
4015
Craig Mautner967212c2013-04-13 21:10:58 -07004016 @Override
4017 public void getContentRectLw(Rect r) {
4018 r.set(mContentLeft, mContentTop, mContentRight, mContentBottom);
4019 }
4020
Dianne Hackbornc4aad012013-02-22 15:05:25 -08004021 void setAttachedWindowFrames(WindowState win, int fl, int adjust, WindowState attached,
4022 boolean insetDecors, Rect pf, Rect df, Rect of, Rect cf, Rect vf) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004023 if (win.getSurfaceLayer() > mDockLayer && attached.getSurfaceLayer() < mDockLayer) {
4024 // Here's a special case: if this attached window is a panel that is
4025 // above the dock window, and the window it is attached to is below
4026 // the dock window, then the frames we computed for the window it is
4027 // attached to can not be used because the dock is effectively part
4028 // of the underlying window and the attached window is floating on top
4029 // of the whole thing. So, we ignore the attached window and explicitly
4030 // compute the frames that would be appropriate without the dock.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08004031 df.left = of.left = cf.left = vf.left = mDockLeft;
4032 df.top = of.top = cf.top = vf.top = mDockTop;
4033 df.right = of.right = cf.right = vf.right = mDockRight;
4034 df.bottom = of.bottom = cf.bottom = vf.bottom = mDockBottom;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004035 } else {
4036 // The effective display frame of the attached window depends on
4037 // whether it is taking care of insetting its content. If not,
4038 // we need to use the parent's content frame so that the entire
4039 // window is positioned within that content. Otherwise we can use
Wale Ogunwale393b1c12014-10-18 16:22:01 -07004040 // the overscan frame and let the attached window take care of
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004041 // positioning its content appropriately.
Dianne Hackborndea3ef72010-10-28 14:24:22 -07004042 if (adjust != SOFT_INPUT_ADJUST_RESIZE) {
Wale Ogunwale393b1c12014-10-18 16:22:01 -07004043 // Set the content frame of the attached window to the parent's decor frame
4044 // (same as content frame when IME isn't present) if specifically requested by
4045 // setting {@link WindowManager.LayoutParams#FLAG_LAYOUT_ATTACHED_IN_DECOR} flag.
4046 // Otherwise, use the overscan frame.
4047 cf.set((fl & FLAG_LAYOUT_ATTACHED_IN_DECOR) != 0
4048 ? attached.getContentFrameLw() : attached.getOverscanFrameLw());
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004049 } else {
4050 // If the window is resizing, then we want to base the content
4051 // frame on our attached content frame to resize... however,
4052 // things can be tricky if the attached window is NOT in resize
4053 // mode, in which case its content frame will be larger.
4054 // Ungh. So to deal with that, make sure the content frame
4055 // we end up using is not covering the IM dock.
4056 cf.set(attached.getContentFrameLw());
Dianne Hackborne30e02f2014-05-27 18:24:45 -07004057 if (attached.isVoiceInteraction()) {
4058 if (cf.left < mVoiceContentLeft) cf.left = mVoiceContentLeft;
4059 if (cf.top < mVoiceContentTop) cf.top = mVoiceContentTop;
4060 if (cf.right > mVoiceContentRight) cf.right = mVoiceContentRight;
4061 if (cf.bottom > mVoiceContentBottom) cf.bottom = mVoiceContentBottom;
4062 } else if (attached.getSurfaceLayer() < mDockLayer) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004063 if (cf.left < mContentLeft) cf.left = mContentLeft;
4064 if (cf.top < mContentTop) cf.top = mContentTop;
4065 if (cf.right > mContentRight) cf.right = mContentRight;
4066 if (cf.bottom > mContentBottom) cf.bottom = mContentBottom;
4067 }
4068 }
4069 df.set(insetDecors ? attached.getDisplayFrameLw() : cf);
Dianne Hackbornc4aad012013-02-22 15:05:25 -08004070 of.set(insetDecors ? attached.getOverscanFrameLw() : cf);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004071 vf.set(attached.getVisibleFrameLw());
4072 }
4073 // The LAYOUT_IN_SCREEN flag is used to determine whether the attached
4074 // window should be positioned relative to its parent or the entire
4075 // screen.
4076 pf.set((fl & FLAG_LAYOUT_IN_SCREEN) == 0
4077 ? attached.getFrameLw() : df);
4078 }
Dianne Hackborn5b5cc4d2012-05-16 13:15:00 -07004079
4080 private void applyStableConstraints(int sysui, int fl, Rect r) {
4081 if ((sysui & View.SYSTEM_UI_FLAG_LAYOUT_STABLE) != 0) {
4082 // If app is requesting a stable layout, don't let the
4083 // content insets go below the stable values.
4084 if ((fl & FLAG_FULLSCREEN) != 0) {
4085 if (r.left < mStableFullscreenLeft) r.left = mStableFullscreenLeft;
4086 if (r.top < mStableFullscreenTop) r.top = mStableFullscreenTop;
4087 if (r.right > mStableFullscreenRight) r.right = mStableFullscreenRight;
4088 if (r.bottom > mStableFullscreenBottom) r.bottom = mStableFullscreenBottom;
4089 } else {
4090 if (r.left < mStableLeft) r.left = mStableLeft;
4091 if (r.top < mStableTop) r.top = mStableTop;
4092 if (r.right > mStableRight) r.right = mStableRight;
4093 if (r.bottom > mStableBottom) r.bottom = mStableBottom;
4094 }
4095 }
4096 }
4097
Jorim Jaggiaa806142015-05-20 18:04:16 -07004098 private boolean canReceiveInput(WindowState win) {
4099 boolean notFocusable =
4100 (win.getAttrs().flags & WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE) != 0;
4101 boolean altFocusableIm =
4102 (win.getAttrs().flags & WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM) != 0;
4103 boolean notFocusableForIm = notFocusable ^ altFocusableIm;
4104 return !notFocusableForIm;
4105 }
4106
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004107 /** {@inheritDoc} */
Craig Mautner69b08182012-09-05 13:07:13 -07004108 @Override
Craig Mautnerc9457fa2014-06-06 14:27:48 -07004109 public void layoutWindowLw(WindowState win, WindowState attached) {
Jorim Jaggiaa806142015-05-20 18:04:16 -07004110 // We've already done the navigation bar and status bar. If the status bar can receive
4111 // input, we need to layout it again to accomodate for the IME window.
4112 if ((win == mStatusBar && !canReceiveInput(win)) || win == mNavigationBar) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004113 return;
4114 }
Jorim Jaggiaa806142015-05-20 18:04:16 -07004115 final WindowManager.LayoutParams attrs = win.getAttrs();
Craig Mautner69b08182012-09-05 13:07:13 -07004116 final boolean isDefaultDisplay = win.isDefaultDisplay();
4117 final boolean needsToOffsetInputMethodTarget = isDefaultDisplay &&
satok1bc0a492012-04-25 22:47:12 +09004118 (win == mLastInputMethodTargetWindow && mLastInputMethodWindow != null);
4119 if (needsToOffsetInputMethodTarget) {
Craig Mautnereda67292013-04-28 13:50:14 -07004120 if (DEBUG_LAYOUT) Slog.i(TAG, "Offset ime target window by the last ime window state");
satok1bc0a492012-04-25 22:47:12 +09004121 offsetInputMethodWindowLw(mLastInputMethodWindow);
4122 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004123
John Spurlockc6d1c602014-01-17 15:22:06 -05004124 final int fl = PolicyControl.getWindowFlags(win, attrs);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004125 final int sim = attrs.softInputMode;
John Spurlock1db8b682014-02-18 11:18:59 -05004126 final int sysUiFl = PolicyControl.getSystemUiVisibility(win, null);
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07004127
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004128 final Rect pf = mTmpParentFrame;
4129 final Rect df = mTmpDisplayFrame;
Dianne Hackbornc4aad012013-02-22 15:05:25 -08004130 final Rect of = mTmpOverscanFrame;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004131 final Rect cf = mTmpContentFrame;
4132 final Rect vf = mTmpVisibleFrame;
John Spurlock46646232013-09-30 22:32:42 -04004133 final Rect dcf = mTmpDecorFrame;
Adrian Roosfa104232014-06-20 16:10:14 -07004134 final Rect sf = mTmpStableFrame;
Filip Gruszczynski2217f612015-05-26 11:32:08 -07004135 Rect osf = null;
John Spurlock46646232013-09-30 22:32:42 -04004136 dcf.setEmpty();
Craig Mautner69b08182012-09-05 13:07:13 -07004137
4138 final boolean hasNavBar = (isDefaultDisplay && mHasNavigationBar
Daniel Sandler36412a72011-08-04 09:35:13 -04004139 && mNavigationBar != null && mNavigationBar.isVisibleLw());
Daniel Sandler8956dbb2011-04-22 07:55:02 -04004140
Craig Mautnerf683b562012-10-02 11:10:57 -07004141 final int adjust = sim & SOFT_INPUT_MASK_ADJUST;
4142
Adrian Roosfa104232014-06-20 16:10:14 -07004143 if (isDefaultDisplay) {
4144 sf.set(mStableLeft, mStableTop, mStableRight, mStableBottom);
4145 } else {
4146 sf.set(mOverscanLeft, mOverscanTop, mOverscanRight, mOverscanBottom);
4147 }
4148
Craig Mautner69b08182012-09-05 13:07:13 -07004149 if (!isDefaultDisplay) {
4150 if (attached != null) {
4151 // If this window is attached to another, our display
4152 // frame is the same as the one we are attached to.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08004153 setAttachedWindowFrames(win, fl, adjust, attached, true, pf, df, of, cf, vf);
Craig Mautner69b08182012-09-05 13:07:13 -07004154 } else {
4155 // Give the window full screen.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08004156 pf.left = df.left = of.left = cf.left = mOverscanScreenLeft;
4157 pf.top = df.top = of.top = cf.top = mOverscanScreenTop;
4158 pf.right = df.right = of.right = cf.right
Dianne Hackbornc652de82013-02-15 16:32:56 -08004159 = mOverscanScreenLeft + mOverscanScreenWidth;
Dianne Hackbornc4aad012013-02-22 15:05:25 -08004160 pf.bottom = df.bottom = of.bottom = cf.bottom
Dianne Hackbornc652de82013-02-15 16:32:56 -08004161 = mOverscanScreenTop + mOverscanScreenHeight;
Craig Mautner69b08182012-09-05 13:07:13 -07004162 }
Jorim Jaggi225d3b52015-04-01 11:18:57 -07004163 } else if (attrs.type == TYPE_INPUT_METHOD) {
Dianne Hackbornc4aad012013-02-22 15:05:25 -08004164 pf.left = df.left = of.left = cf.left = vf.left = mDockLeft;
4165 pf.top = df.top = of.top = cf.top = vf.top = mDockTop;
4166 pf.right = df.right = of.right = cf.right = vf.right = mDockRight;
John Spurlockc68d5772013-10-08 11:47:58 -04004167 // IM dock windows layout below the nav bar...
John Spurlock57beb3b2013-10-10 10:27:44 -04004168 pf.bottom = df.bottom = of.bottom = mUnrestrictedScreenTop + mUnrestrictedScreenHeight;
John Spurlockc68d5772013-10-08 11:47:58 -04004169 // ...with content insets above the nav bar
4170 cf.bottom = vf.bottom = mStableBottom;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004171 // IM dock windows always go to the bottom of the screen.
4172 attrs.gravity = Gravity.BOTTOM;
4173 mDockLayer = win.getSurfaceLayer();
Jorim Jaggi225d3b52015-04-01 11:18:57 -07004174 } else if (attrs.type == TYPE_VOICE_INTERACTION) {
Stefan Kuhne2f280d062015-06-18 07:20:33 -10004175 pf.left = df.left = of.left = mUnrestrictedScreenLeft;
Jorim Jaggi225d3b52015-04-01 11:18:57 -07004176 pf.top = df.top = of.top = mUnrestrictedScreenTop;
Stefan Kuhne2f280d062015-06-18 07:20:33 -10004177 pf.right = df.right = of.right = mUnrestrictedScreenLeft + mUnrestrictedScreenWidth;
4178 pf.bottom = df.bottom = of.bottom = mUnrestrictedScreenTop + mUnrestrictedScreenHeight;
Jorim Jaggi225d3b52015-04-01 11:18:57 -07004179 cf.bottom = vf.bottom = mStableBottom;
Stefan Kuhne2f280d062015-06-18 07:20:33 -10004180 // Note: In Phone landscape mode, the button bar should also be excluded.
4181 cf.right = vf.right = mStableRight;
4182 cf.left = vf.left = mStableLeft;
Jorim Jaggi225d3b52015-04-01 11:18:57 -07004183 cf.top = vf.top = mStableTop;
Jorim Jaggiaa806142015-05-20 18:04:16 -07004184 } else if (win == mStatusBar) {
Jorim Jaggie0700182014-08-21 01:12:37 +02004185 pf.left = df.left = of.left = mUnrestrictedScreenLeft;
4186 pf.top = df.top = of.top = mUnrestrictedScreenTop;
4187 pf.right = df.right = of.right = mUnrestrictedScreenWidth + mUnrestrictedScreenLeft;
4188 pf.bottom = df.bottom = of.bottom = mUnrestrictedScreenHeight + mUnrestrictedScreenTop;
4189 cf.left = vf.left = mStableLeft;
4190 cf.top = vf.top = mStableTop;
4191 cf.right = vf.right = mStableRight;
4192 vf.bottom = mStableBottom;
Adrian Roosdc5b4532016-01-06 20:49:41 +01004193
4194 if (adjust == SOFT_INPUT_ADJUST_RESIZE) {
4195 cf.bottom = mContentBottom;
4196 } else {
4197 cf.bottom = mDockBottom;
4198 vf.bottom = mContentBottom;
4199 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004200 } else {
John Spurlock46646232013-09-30 22:32:42 -04004201
4202 // Default policy decor for the default display
4203 dcf.left = mSystemLeft;
4204 dcf.top = mSystemTop;
4205 dcf.right = mSystemRight;
4206 dcf.bottom = mSystemBottom;
John Spurlockbd957402013-10-03 11:38:39 -04004207 final boolean inheritTranslucentDecor = (attrs.privateFlags
4208 & WindowManager.LayoutParams.PRIVATE_FLAG_INHERIT_TRANSLUCENT_DECOR) != 0;
John Spurlock65567d42013-10-08 10:08:32 -04004209 final boolean isAppWindow =
4210 attrs.type >= WindowManager.LayoutParams.FIRST_APPLICATION_WINDOW &&
4211 attrs.type <= WindowManager.LayoutParams.LAST_APPLICATION_WINDOW;
4212 final boolean topAtRest =
4213 win == mTopFullscreenOpaqueWindowState && !win.isAnimatingLw();
4214 if (isAppWindow && !inheritTranslucentDecor && !topAtRest) {
John Spurlockbd957402013-10-03 11:38:39 -04004215 if ((sysUiFl & View.SYSTEM_UI_FLAG_FULLSCREEN) == 0
4216 && (fl & WindowManager.LayoutParams.FLAG_FULLSCREEN) == 0
Adrian Roosea562512014-05-05 13:33:03 +02004217 && (fl & WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS) == 0
4218 && (fl & WindowManager.LayoutParams.
Jorim Jaggi4fa78922015-11-30 17:13:56 -08004219 FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS) == 0
4220 && !mForceWindowDrawsStatusBarBackground) {
John Spurlock46646232013-09-30 22:32:42 -04004221 // Ensure policy decor includes status bar
4222 dcf.top = mStableTop;
4223 }
John Spurlockbd957402013-10-03 11:38:39 -04004224 if ((fl & WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION) == 0
Adrian Roosea562512014-05-05 13:33:03 +02004225 && (sysUiFl & View.SYSTEM_UI_FLAG_HIDE_NAVIGATION) == 0
4226 && (fl & WindowManager.LayoutParams.
4227 FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS) == 0) {
John Spurlock46646232013-09-30 22:32:42 -04004228 // Ensure policy decor includes navigation bar
4229 dcf.bottom = mStableBottom;
4230 dcf.right = mStableRight;
4231 }
4232 }
4233
Dianne Hackbornc4aad012013-02-22 15:05:25 -08004234 if ((fl & (FLAG_LAYOUT_IN_SCREEN | FLAG_LAYOUT_INSET_DECOR))
4235 == (FLAG_LAYOUT_IN_SCREEN | FLAG_LAYOUT_INSET_DECOR)) {
RoboErik8a2cfc32014-05-16 11:19:38 -07004236 if (DEBUG_LAYOUT) Slog.v(TAG, "layoutWindowLw(" + attrs.getTitle()
Dianne Hackbornc4aad012013-02-22 15:05:25 -08004237 + "): IN_SCREEN, INSET_DECOR");
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004238 // This is the case for a normal activity window: we want it
4239 // to cover all of the screen space, and it can take care of
4240 // moving its contents to account for screen decorations that
4241 // intrude into that space.
4242 if (attached != null) {
4243 // If this window is attached to another, our display
4244 // frame is the same as the one we are attached to.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08004245 setAttachedWindowFrames(win, fl, adjust, attached, true, pf, df, of, cf, vf);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004246 } else {
Daniel Sandler8956dbb2011-04-22 07:55:02 -04004247 if (attrs.type == TYPE_STATUS_BAR_PANEL
4248 || attrs.type == TYPE_STATUS_BAR_SUB_PANEL) {
Joe Onorato29fc2c92010-11-24 10:26:50 -08004249 // Status bar panels are the only windows who can go on top of
4250 // the status bar. They are protected by the STATUS_BAR_SERVICE
4251 // permission, so they have the same privileges as the status
4252 // bar itself.
Daniel Sandler8956dbb2011-04-22 07:55:02 -04004253 //
Daniel Sandler8e8b4152011-07-21 01:16:43 -04004254 // However, they should still dodge the navigation bar if it exists.
Daniel Sandler8956dbb2011-04-22 07:55:02 -04004255
Dianne Hackbornc4aad012013-02-22 15:05:25 -08004256 pf.left = df.left = of.left = hasNavBar
4257 ? mDockLeft : mUnrestrictedScreenLeft;
4258 pf.top = df.top = of.top = mUnrestrictedScreenTop;
4259 pf.right = df.right = of.right = hasNavBar
4260 ? mRestrictedScreenLeft+mRestrictedScreenWidth
4261 : mUnrestrictedScreenLeft + mUnrestrictedScreenWidth;
4262 pf.bottom = df.bottom = of.bottom = hasNavBar
4263 ? mRestrictedScreenTop+mRestrictedScreenHeight
4264 : mUnrestrictedScreenTop + mUnrestrictedScreenHeight;
Daniel Sandler8956dbb2011-04-22 07:55:02 -04004265
Craig Mautnereda67292013-04-28 13:50:14 -07004266 if (DEBUG_LAYOUT) Slog.v(TAG, String.format(
Daniel Sandler8e8b4152011-07-21 01:16:43 -04004267 "Laying out status bar window: (%d,%d - %d,%d)",
4268 pf.left, pf.top, pf.right, pf.bottom));
John Spurlock46646232013-09-30 22:32:42 -04004269 } else if ((fl & FLAG_LAYOUT_IN_OVERSCAN) != 0
Dianne Hackbornc652de82013-02-15 16:32:56 -08004270 && attrs.type >= WindowManager.LayoutParams.FIRST_APPLICATION_WINDOW
4271 && attrs.type <= WindowManager.LayoutParams.LAST_SUB_WINDOW) {
4272 // Asking to layout into the overscan region, so give it that pure
4273 // unrestricted area.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08004274 pf.left = df.left = of.left = mOverscanScreenLeft;
4275 pf.top = df.top = of.top = mOverscanScreenTop;
4276 pf.right = df.right = of.right = mOverscanScreenLeft + mOverscanScreenWidth;
4277 pf.bottom = df.bottom = of.bottom = mOverscanScreenTop
4278 + mOverscanScreenHeight;
Alan Viverette5a0f4ec2013-10-07 15:10:29 -07004279 } else if (canHideNavigationBar()
Dianne Hackbornf87d1962012-04-04 12:48:24 -07004280 && (sysUiFl & View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION) != 0
Jorim Jaggi380ecb82014-03-14 17:25:20 +01004281 && attrs.type >= WindowManager.LayoutParams.FIRST_APPLICATION_WINDOW
4282 && attrs.type <= WindowManager.LayoutParams.LAST_SUB_WINDOW) {
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07004283 // Asking for layout as if the nav bar is hidden, lets the
Dianne Hackbornc652de82013-02-15 16:32:56 -08004284 // application extend into the unrestricted overscan screen area. We
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07004285 // only do this for application windows to ensure no window that
4286 // can be above the nav bar can do this.
Dianne Hackborn313440842013-02-19 19:22:59 -08004287 pf.left = df.left = mOverscanScreenLeft;
4288 pf.top = df.top = mOverscanScreenTop;
4289 pf.right = df.right = mOverscanScreenLeft + mOverscanScreenWidth;
4290 pf.bottom = df.bottom = mOverscanScreenTop + mOverscanScreenHeight;
Dianne Hackbornc4aad012013-02-22 15:05:25 -08004291 // We need to tell the app about where the frame inside the overscan
4292 // is, so it can inset its content by that amount -- it didn't ask
4293 // to actually extend itself into the overscan region.
4294 of.left = mUnrestrictedScreenLeft;
4295 of.top = mUnrestrictedScreenTop;
4296 of.right = mUnrestrictedScreenLeft + mUnrestrictedScreenWidth;
4297 of.bottom = mUnrestrictedScreenTop + mUnrestrictedScreenHeight;
Joe Onorato29fc2c92010-11-24 10:26:50 -08004298 } else {
Dianne Hackborn313440842013-02-19 19:22:59 -08004299 pf.left = df.left = mRestrictedOverscanScreenLeft;
4300 pf.top = df.top = mRestrictedOverscanScreenTop;
4301 pf.right = df.right = mRestrictedOverscanScreenLeft
4302 + mRestrictedOverscanScreenWidth;
4303 pf.bottom = df.bottom = mRestrictedOverscanScreenTop
4304 + mRestrictedOverscanScreenHeight;
Dianne Hackbornc4aad012013-02-22 15:05:25 -08004305 // We need to tell the app about where the frame inside the overscan
4306 // is, so it can inset its content by that amount -- it didn't ask
4307 // to actually extend itself into the overscan region.
4308 of.left = mUnrestrictedScreenLeft;
4309 of.top = mUnrestrictedScreenTop;
4310 of.right = mUnrestrictedScreenLeft + mUnrestrictedScreenWidth;
4311 of.bottom = mUnrestrictedScreenTop + mUnrestrictedScreenHeight;
Joe Onorato29fc2c92010-11-24 10:26:50 -08004312 }
Craig Mautner69b08182012-09-05 13:07:13 -07004313
John Spurlock46646232013-09-30 22:32:42 -04004314 if ((fl & FLAG_FULLSCREEN) == 0) {
Dianne Hackborne30e02f2014-05-27 18:24:45 -07004315 if (win.isVoiceInteraction()) {
4316 cf.left = mVoiceContentLeft;
4317 cf.top = mVoiceContentTop;
4318 cf.right = mVoiceContentRight;
4319 cf.bottom = mVoiceContentBottom;
Dianne Hackbornc4aad012013-02-22 15:05:25 -08004320 } else {
Dianne Hackborne30e02f2014-05-27 18:24:45 -07004321 if (adjust != SOFT_INPUT_ADJUST_RESIZE) {
4322 cf.left = mDockLeft;
4323 cf.top = mDockTop;
4324 cf.right = mDockRight;
4325 cf.bottom = mDockBottom;
4326 } else {
4327 cf.left = mContentLeft;
4328 cf.top = mContentTop;
4329 cf.right = mContentRight;
4330 cf.bottom = mContentBottom;
4331 }
Dianne Hackbornc4aad012013-02-22 15:05:25 -08004332 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004333 } else {
Dianne Hackbornc4aad012013-02-22 15:05:25 -08004334 // Full screen windows are always given a layout that is as if the
4335 // status bar and other transient decors are gone. This is to avoid
4336 // bad states when moving from a window that is not hding the
4337 // status bar to one that is.
4338 cf.left = mRestrictedScreenLeft;
4339 cf.top = mRestrictedScreenTop;
4340 cf.right = mRestrictedScreenLeft + mRestrictedScreenWidth;
4341 cf.bottom = mRestrictedScreenTop + mRestrictedScreenHeight;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004342 }
Dianne Hackborn5b5cc4d2012-05-16 13:15:00 -07004343 applyStableConstraints(sysUiFl, fl, cf);
Dianne Hackborndea3ef72010-10-28 14:24:22 -07004344 if (adjust != SOFT_INPUT_ADJUST_NOTHING) {
4345 vf.left = mCurLeft;
4346 vf.top = mCurTop;
4347 vf.right = mCurRight;
4348 vf.bottom = mCurBottom;
4349 } else {
4350 vf.set(cf);
4351 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004352 }
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07004353 } else if ((fl & FLAG_LAYOUT_IN_SCREEN) != 0 || (sysUiFl
4354 & (View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
4355 | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION)) != 0) {
Craig Mautnereda67292013-04-28 13:50:14 -07004356 if (DEBUG_LAYOUT) Slog.v(TAG, "layoutWindowLw(" + attrs.getTitle() +
4357 "): IN_SCREEN");
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004358 // A window that has requested to fill the entire screen just
4359 // gets everything, period.
Daniel Sandler8956dbb2011-04-22 07:55:02 -04004360 if (attrs.type == TYPE_STATUS_BAR_PANEL
John Spurlock67a0f852015-06-15 15:35:47 -04004361 || attrs.type == TYPE_STATUS_BAR_SUB_PANEL
4362 || attrs.type == TYPE_VOLUME_OVERLAY) {
Dianne Hackbornc4aad012013-02-22 15:05:25 -08004363 pf.left = df.left = of.left = cf.left = hasNavBar
4364 ? mDockLeft : mUnrestrictedScreenLeft;
4365 pf.top = df.top = of.top = cf.top = mUnrestrictedScreenTop;
4366 pf.right = df.right = of.right = cf.right = hasNavBar
Daniel Sandler8e8b4152011-07-21 01:16:43 -04004367 ? mRestrictedScreenLeft+mRestrictedScreenWidth
Dianne Hackbornc652de82013-02-15 16:32:56 -08004368 : mUnrestrictedScreenLeft + mUnrestrictedScreenWidth;
Dianne Hackbornc4aad012013-02-22 15:05:25 -08004369 pf.bottom = df.bottom = of.bottom = cf.bottom = hasNavBar
Daniel Sandler8e8b4152011-07-21 01:16:43 -04004370 ? mRestrictedScreenTop+mRestrictedScreenHeight
Dianne Hackbornc652de82013-02-15 16:32:56 -08004371 : mUnrestrictedScreenTop + mUnrestrictedScreenHeight;
Craig Mautnereda67292013-04-28 13:50:14 -07004372 if (DEBUG_LAYOUT) Slog.v(TAG, String.format(
Daniel Sandler36412a72011-08-04 09:35:13 -04004373 "Laying out IN_SCREEN status bar window: (%d,%d - %d,%d)",
4374 pf.left, pf.top, pf.right, pf.bottom));
Jim Millere898ac52012-04-06 17:10:57 -07004375 } else if (attrs.type == TYPE_NAVIGATION_BAR
4376 || attrs.type == TYPE_NAVIGATION_BAR_PANEL) {
Daniel Sandler8e8b4152011-07-21 01:16:43 -04004377 // The navigation bar has Real Ultimate Power.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08004378 pf.left = df.left = of.left = mUnrestrictedScreenLeft;
4379 pf.top = df.top = of.top = mUnrestrictedScreenTop;
4380 pf.right = df.right = of.right = mUnrestrictedScreenLeft
4381 + mUnrestrictedScreenWidth;
4382 pf.bottom = df.bottom = of.bottom = mUnrestrictedScreenTop
4383 + mUnrestrictedScreenHeight;
Craig Mautnereda67292013-04-28 13:50:14 -07004384 if (DEBUG_LAYOUT) Slog.v(TAG, String.format(
Daniel Sandler8e8b4152011-07-21 01:16:43 -04004385 "Laying out navigation bar window: (%d,%d - %d,%d)",
4386 pf.left, pf.top, pf.right, pf.bottom));
Dianne Hackborn01011c32012-02-21 13:54:21 -08004387 } else if ((attrs.type == TYPE_SECURE_SYSTEM_OVERLAY
4388 || attrs.type == TYPE_BOOT_PROGRESS)
Jeff Brownbfcb60a2011-09-08 18:51:14 -07004389 && ((fl & FLAG_FULLSCREEN) != 0)) {
4390 // Fullscreen secure system overlays get what they ask for.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08004391 pf.left = df.left = of.left = cf.left = mOverscanScreenLeft;
4392 pf.top = df.top = of.top = cf.top = mOverscanScreenTop;
4393 pf.right = df.right = of.right = cf.right = mOverscanScreenLeft
4394 + mOverscanScreenWidth;
4395 pf.bottom = df.bottom = of.bottom = cf.bottom = mOverscanScreenTop
4396 + mOverscanScreenHeight;
Craig Mautner165be0c2015-01-27 15:16:58 -08004397 } else if (attrs.type == TYPE_BOOT_PROGRESS) {
Dianne Hackborn01011c32012-02-21 13:54:21 -08004398 // Boot progress screen always covers entire display.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08004399 pf.left = df.left = of.left = cf.left = mOverscanScreenLeft;
4400 pf.top = df.top = of.top = cf.top = mOverscanScreenTop;
4401 pf.right = df.right = of.right = cf.right = mOverscanScreenLeft
4402 + mOverscanScreenWidth;
4403 pf.bottom = df.bottom = of.bottom = cf.bottom = mOverscanScreenTop
4404 + mOverscanScreenHeight;
John Spurlockef4adae2013-08-26 17:58:58 -04004405 } else if (attrs.type == TYPE_WALLPAPER) {
Dianne Hackborn067e5f62014-09-07 23:14:30 -07004406 // The wallpaper also has Real Ultimate Power, but we want to tell
4407 // it about the overscan area.
4408 pf.left = df.left = mOverscanScreenLeft;
4409 pf.top = df.top = mOverscanScreenTop;
4410 pf.right = df.right = mOverscanScreenLeft + mOverscanScreenWidth;
4411 pf.bottom = df.bottom = mOverscanScreenTop + mOverscanScreenHeight;
4412 of.left = cf.left = mUnrestrictedScreenLeft;
4413 of.top = cf.top = mUnrestrictedScreenTop;
4414 of.right = cf.right = mUnrestrictedScreenLeft + mUnrestrictedScreenWidth;
4415 of.bottom = cf.bottom = mUnrestrictedScreenTop + mUnrestrictedScreenHeight;
John Spurlock46646232013-09-30 22:32:42 -04004416 } else if ((fl & FLAG_LAYOUT_IN_OVERSCAN) != 0
Dianne Hackbornc652de82013-02-15 16:32:56 -08004417 && attrs.type >= WindowManager.LayoutParams.FIRST_APPLICATION_WINDOW
4418 && attrs.type <= WindowManager.LayoutParams.LAST_SUB_WINDOW) {
4419 // Asking to layout into the overscan region, so give it that pure
4420 // unrestricted area.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08004421 pf.left = df.left = of.left = cf.left = mOverscanScreenLeft;
4422 pf.top = df.top = of.top = cf.top = mOverscanScreenTop;
4423 pf.right = df.right = of.right = cf.right
Dianne Hackbornc652de82013-02-15 16:32:56 -08004424 = mOverscanScreenLeft + mOverscanScreenWidth;
Dianne Hackbornc4aad012013-02-22 15:05:25 -08004425 pf.bottom = df.bottom = of.bottom = cf.bottom
Dianne Hackbornc652de82013-02-15 16:32:56 -08004426 = mOverscanScreenTop + mOverscanScreenHeight;
Alan Viverette5a0f4ec2013-10-07 15:10:29 -07004427 } else if (canHideNavigationBar()
Dianne Hackbornf87d1962012-04-04 12:48:24 -07004428 && (sysUiFl & View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION) != 0
Craig Mautnerbeac1062014-06-03 14:38:57 -07004429 && (attrs.type == TYPE_STATUS_BAR
4430 || attrs.type == TYPE_TOAST
Jorim Jaggi81fe2d12015-12-21 14:45:18 +01004431 || attrs.type == TYPE_DOCK_DIVIDER
Jorim Jaggi2fdeeab2015-04-01 15:13:03 -07004432 || attrs.type == TYPE_VOICE_INTERACTION_STARTING
John Spurlock34e13d92013-08-10 06:52:28 -04004433 || (attrs.type >= WindowManager.LayoutParams.FIRST_APPLICATION_WINDOW
4434 && attrs.type <= WindowManager.LayoutParams.LAST_SUB_WINDOW))) {
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07004435 // Asking for layout as if the nav bar is hidden, lets the
4436 // application extend into the unrestricted screen area. We
John Spurlock34e13d92013-08-10 06:52:28 -04004437 // only do this for application windows (or toasts) to ensure no window that
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07004438 // can be above the nav bar can do this.
4439 // XXX This assumes that an app asking for this will also
4440 // ask for layout in only content. We can't currently figure out
4441 // what the screen would be if only laying out to hide the nav bar.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08004442 pf.left = df.left = of.left = cf.left = mUnrestrictedScreenLeft;
4443 pf.top = df.top = of.top = cf.top = mUnrestrictedScreenTop;
4444 pf.right = df.right = of.right = cf.right = mUnrestrictedScreenLeft
4445 + mUnrestrictedScreenWidth;
4446 pf.bottom = df.bottom = of.bottom = cf.bottom = mUnrestrictedScreenTop
4447 + mUnrestrictedScreenHeight;
Jorim Jaggi9f6798a2016-02-10 22:16:06 -08004448 } else if ((sysUiFl & View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN) != 0) {
4449 pf.left = df.left = of.left = mRestrictedScreenLeft;
4450 pf.top = df.top = of.top = mRestrictedScreenTop;
4451 pf.right = df.right = of.right = mRestrictedScreenLeft + mRestrictedScreenWidth;
4452 pf.bottom = df.bottom = of.bottom = mRestrictedScreenTop
4453 + mRestrictedScreenHeight;
4454 if (adjust != SOFT_INPUT_ADJUST_RESIZE) {
4455 cf.left = mDockLeft;
4456 cf.top = mDockTop;
4457 cf.right = mDockRight;
4458 cf.bottom = mDockBottom;
4459 } else {
4460 cf.left = mContentLeft;
4461 cf.top = mContentTop;
4462 cf.right = mContentRight;
4463 cf.bottom = mContentBottom;
4464 }
Joe Onorato29fc2c92010-11-24 10:26:50 -08004465 } else {
Dianne Hackbornc4aad012013-02-22 15:05:25 -08004466 pf.left = df.left = of.left = cf.left = mRestrictedScreenLeft;
4467 pf.top = df.top = of.top = cf.top = mRestrictedScreenTop;
4468 pf.right = df.right = of.right = cf.right = mRestrictedScreenLeft
4469 + mRestrictedScreenWidth;
4470 pf.bottom = df.bottom = of.bottom = cf.bottom = mRestrictedScreenTop
4471 + mRestrictedScreenHeight;
Joe Onorato29fc2c92010-11-24 10:26:50 -08004472 }
Craig Mautner69b08182012-09-05 13:07:13 -07004473
Dianne Hackborn5b5cc4d2012-05-16 13:15:00 -07004474 applyStableConstraints(sysUiFl, fl, cf);
Craig Mautner69b08182012-09-05 13:07:13 -07004475
Dianne Hackborndea3ef72010-10-28 14:24:22 -07004476 if (adjust != SOFT_INPUT_ADJUST_NOTHING) {
4477 vf.left = mCurLeft;
4478 vf.top = mCurTop;
4479 vf.right = mCurRight;
4480 vf.bottom = mCurBottom;
4481 } else {
4482 vf.set(cf);
4483 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004484 } else if (attached != null) {
Craig Mautnereda67292013-04-28 13:50:14 -07004485 if (DEBUG_LAYOUT) Slog.v(TAG, "layoutWindowLw(" + attrs.getTitle() +
4486 "): attached to " + attached);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004487 // A child window should be placed inside of the same visible
4488 // frame that its parent had.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08004489 setAttachedWindowFrames(win, fl, adjust, attached, false, pf, df, of, cf, vf);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004490 } else {
Craig Mautnereda67292013-04-28 13:50:14 -07004491 if (DEBUG_LAYOUT) Slog.v(TAG, "layoutWindowLw(" + attrs.getTitle() +
4492 "): normal window");
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004493 // Otherwise, a normal window must be placed inside the content
4494 // of all screen decorations.
John Spurlock67a0f852015-06-15 15:35:47 -04004495 if (attrs.type == TYPE_STATUS_BAR_PANEL || attrs.type == TYPE_VOLUME_OVERLAY) {
4496 // Status bar panels and the volume dialog are the only windows who can go on
4497 // top of the status bar. They are protected by the STATUS_BAR_SERVICE
Dianne Hackborna239c842011-06-01 12:28:20 -07004498 // permission, so they have the same privileges as the status
4499 // bar itself.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08004500 pf.left = df.left = of.left = cf.left = mRestrictedScreenLeft;
4501 pf.top = df.top = of.top = cf.top = mRestrictedScreenTop;
4502 pf.right = df.right = of.right = cf.right = mRestrictedScreenLeft
4503 + mRestrictedScreenWidth;
4504 pf.bottom = df.bottom = of.bottom = cf.bottom = mRestrictedScreenTop
4505 + mRestrictedScreenHeight;
John Spurlock67a0f852015-06-15 15:35:47 -04004506 } else if (attrs.type == TYPE_TOAST || attrs.type == TYPE_SYSTEM_ALERT) {
John Spurlock414c1f02013-12-04 13:47:36 -05004507 // These dialogs are stable to interim decor changes.
John Spurlockbd957402013-10-03 11:38:39 -04004508 pf.left = df.left = of.left = cf.left = mStableLeft;
4509 pf.top = df.top = of.top = cf.top = mStableTop;
4510 pf.right = df.right = of.right = cf.right = mStableRight;
4511 pf.bottom = df.bottom = of.bottom = cf.bottom = mStableBottom;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004512 } else {
Dianne Hackborna239c842011-06-01 12:28:20 -07004513 pf.left = mContentLeft;
4514 pf.top = mContentTop;
4515 pf.right = mContentRight;
4516 pf.bottom = mContentBottom;
Dianne Hackborn20d94742014-05-29 18:35:45 -07004517 if (win.isVoiceInteraction()) {
4518 df.left = of.left = cf.left = mVoiceContentLeft;
4519 df.top = of.top = cf.top = mVoiceContentTop;
4520 df.right = of.right = cf.right = mVoiceContentRight;
4521 df.bottom = of.bottom = cf.bottom = mVoiceContentBottom;
4522 } else if (adjust != SOFT_INPUT_ADJUST_RESIZE) {
Dianne Hackbornc4aad012013-02-22 15:05:25 -08004523 df.left = of.left = cf.left = mDockLeft;
4524 df.top = of.top = cf.top = mDockTop;
4525 df.right = of.right = cf.right = mDockRight;
4526 df.bottom = of.bottom = cf.bottom = mDockBottom;
Dianne Hackborna239c842011-06-01 12:28:20 -07004527 } else {
Dianne Hackbornc4aad012013-02-22 15:05:25 -08004528 df.left = of.left = cf.left = mContentLeft;
4529 df.top = of.top = cf.top = mContentTop;
4530 df.right = of.right = cf.right = mContentRight;
4531 df.bottom = of.bottom = cf.bottom = mContentBottom;
Dianne Hackborna239c842011-06-01 12:28:20 -07004532 }
4533 if (adjust != SOFT_INPUT_ADJUST_NOTHING) {
4534 vf.left = mCurLeft;
4535 vf.top = mCurTop;
4536 vf.right = mCurRight;
4537 vf.bottom = mCurBottom;
4538 } else {
4539 vf.set(cf);
4540 }
Dianne Hackborndea3ef72010-10-28 14:24:22 -07004541 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004542 }
4543 }
Craig Mautner69b08182012-09-05 13:07:13 -07004544
Craig Mautnerb816bed2013-07-23 10:26:17 -07004545 // TYPE_SYSTEM_ERROR is above the NavigationBar so it can't be allowed to extend over it.
4546 if ((fl & FLAG_LAYOUT_NO_LIMITS) != 0 && attrs.type != TYPE_SYSTEM_ERROR) {
Dianne Hackborn067e5f62014-09-07 23:14:30 -07004547 df.left = df.top = -10000;
4548 df.right = df.bottom = 10000;
4549 if (attrs.type != TYPE_WALLPAPER) {
4550 of.left = of.top = cf.left = cf.top = vf.left = vf.top = -10000;
4551 of.right = of.bottom = cf.right = cf.bottom = vf.right = vf.bottom = 10000;
4552 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004553 }
4554
Filip Gruszczynski2217f612015-05-26 11:32:08 -07004555 // If the device has a chin (e.g. some watches), a dead area at the bottom of the screen we
4556 // need to provide information to the clients that want to pretend that you can draw there.
Filip Gruszczynskib0c673b2015-06-05 09:43:06 -07004557 // We only want to apply outsets to certain types of windows. For example, we never want to
4558 // apply the outsets to floating dialogs, because they wouldn't make sense there.
Filip Gruszczynski2987f612015-06-30 15:03:30 -07004559 final boolean useOutsets = shouldUseOutsets(attrs, fl);
Filip Gruszczynskib0c673b2015-06-05 09:43:06 -07004560 if (isDefaultDisplay && useOutsets) {
Filip Gruszczynski2217f612015-05-26 11:32:08 -07004561 osf = mTmpOutsetFrame;
4562 osf.set(cf.left, cf.top, cf.right, cf.bottom);
4563 int outset = ScreenShapeHelper.getWindowOutsetBottomPx(mContext.getResources());
4564 if (outset > 0) {
Filip Gruszczynski2987f612015-06-30 15:03:30 -07004565 int rotation = mDisplayRotation;
Filip Gruszczynski2217f612015-05-26 11:32:08 -07004566 if (rotation == Surface.ROTATION_0) {
4567 osf.bottom += outset;
4568 } else if (rotation == Surface.ROTATION_90) {
4569 osf.right += outset;
4570 } else if (rotation == Surface.ROTATION_180) {
4571 osf.top -= outset;
4572 } else if (rotation == Surface.ROTATION_270) {
4573 osf.left -= outset;
4574 }
4575 if (DEBUG_LAYOUT) Slog.v(TAG, "applying bottom outset of " + outset
4576 + " with rotation " + rotation + ", result: " + osf);
4577 }
4578 }
4579
Craig Mautnereda67292013-04-28 13:50:14 -07004580 if (DEBUG_LAYOUT) Slog.v(TAG, "Compute frame " + attrs.getTitle()
The Android Open Source Project11267662009-03-18 17:39:47 -07004581 + ": sim=#" + Integer.toHexString(sim)
RoboErik8a2cfc32014-05-16 11:19:38 -07004582 + " attach=" + attached + " type=" + attrs.type
Daniel Sandler8956dbb2011-04-22 07:55:02 -04004583 + String.format(" flags=0x%08x", fl)
The Android Open Source Project11267662009-03-18 17:39:47 -07004584 + " pf=" + pf.toShortString() + " df=" + df.toShortString()
Dianne Hackbornc4aad012013-02-22 15:05:25 -08004585 + " of=" + of.toShortString()
John Spurlock46646232013-09-30 22:32:42 -04004586 + " cf=" + cf.toShortString() + " vf=" + vf.toShortString()
Adrian Roosfa104232014-06-20 16:10:14 -07004587 + " dcf=" + dcf.toShortString()
Filip Gruszczynski2217f612015-05-26 11:32:08 -07004588 + " sf=" + sf.toShortString()
4589 + " osf=" + (osf == null ? "null" : osf.toShortString()));
Craig Mautner69b08182012-09-05 13:07:13 -07004590
Filip Gruszczynski2217f612015-05-26 11:32:08 -07004591 win.computeFrameLw(pf, df, of, cf, vf, dcf, sf, osf);
Craig Mautner69b08182012-09-05 13:07:13 -07004592
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004593 // Dock windows carve out the bottom of the screen, so normal windows
4594 // can't appear underneath them.
Craig Mautner8bd206b2012-10-03 10:32:02 -07004595 if (attrs.type == TYPE_INPUT_METHOD && win.isVisibleOrBehindKeyguardLw()
4596 && !win.getGivenInsetsPendingLw()) {
satok1bc0a492012-04-25 22:47:12 +09004597 setLastInputMethodWindowLw(null, null);
4598 offsetInputMethodWindowLw(win);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004599 }
Dianne Hackborne30e02f2014-05-27 18:24:45 -07004600 if (attrs.type == TYPE_VOICE_INTERACTION && win.isVisibleOrBehindKeyguardLw()
4601 && !win.getGivenInsetsPendingLw()) {
4602 offsetVoiceInputWindowLw(win);
4603 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004604 }
4605
satok1bc0a492012-04-25 22:47:12 +09004606 private void offsetInputMethodWindowLw(WindowState win) {
Craig Mautner4774f6a2015-03-23 11:42:55 -07004607 int top = Math.max(win.getDisplayFrameLw().top, win.getContentFrameLw().top);
satok1bc0a492012-04-25 22:47:12 +09004608 top += win.getGivenContentInsetsLw().top;
4609 if (mContentBottom > top) {
4610 mContentBottom = top;
4611 }
Dianne Hackborne30e02f2014-05-27 18:24:45 -07004612 if (mVoiceContentBottom > top) {
4613 mVoiceContentBottom = top;
4614 }
satok1bc0a492012-04-25 22:47:12 +09004615 top = win.getVisibleFrameLw().top;
4616 top += win.getGivenVisibleInsetsLw().top;
4617 if (mCurBottom > top) {
4618 mCurBottom = top;
4619 }
Craig Mautnereda67292013-04-28 13:50:14 -07004620 if (DEBUG_LAYOUT) Slog.v(TAG, "Input method: mDockBottom="
satok1bc0a492012-04-25 22:47:12 +09004621 + mDockBottom + " mContentBottom="
4622 + mContentBottom + " mCurBottom=" + mCurBottom);
4623 }
4624
Dianne Hackborne30e02f2014-05-27 18:24:45 -07004625 private void offsetVoiceInputWindowLw(WindowState win) {
Craig Mautner4774f6a2015-03-23 11:42:55 -07004626 int top = Math.max(win.getDisplayFrameLw().top, win.getContentFrameLw().top);
Dianne Hackbornae6688b2015-02-11 17:02:41 -08004627 top += win.getGivenContentInsetsLw().top;
4628 if (mVoiceContentBottom > top) {
4629 mVoiceContentBottom = top;
Dianne Hackborne30e02f2014-05-27 18:24:45 -07004630 }
4631 }
4632
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004633 /** {@inheritDoc} */
Craig Mautner61ac6bb2012-02-02 17:29:33 -08004634 @Override
4635 public void finishLayoutLw() {
4636 return;
Dianne Hackborn5f3063e2010-03-10 16:01:58 -08004637 }
4638
4639 /** {@inheritDoc} */
Craig Mautnerad09bcc2012-10-08 13:33:11 -07004640 @Override
Craig Mautner39834192012-09-02 07:47:24 -07004641 public void beginPostLayoutPolicyLw(int displayWidth, int displayHeight) {
Dianne Hackborn5f3063e2010-03-10 16:01:58 -08004642 mTopFullscreenOpaqueWindowState = null;
Adrian Rooscd3884d2015-02-18 17:25:23 +01004643 mTopFullscreenOpaqueOrDimmingWindowState = null;
Jorim Jaggi86905582016-02-09 21:36:09 -08004644 mTopDockedOpaqueWindowState = null;
4645 mTopDockedOpaqueOrDimmingWindowState = null;
Craig Mautner2bc789b2014-03-19 19:48:38 -07004646 mAppsToBeHidden.clear();
Jorim Jaggic13fcac2014-09-11 17:36:57 +02004647 mAppsThatDismissKeyguard.clear();
Dianne Hackborn5f3063e2010-03-10 16:01:58 -08004648 mForceStatusBar = false;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07004649 mForceStatusBarFromKeyguard = false;
Selim Cinek4a4a2bddc2015-05-07 12:50:19 -07004650 mForceStatusBarTransparent = false;
Dianne Hackborn891d3fb2013-01-09 18:31:37 -08004651 mForcingShowNavBar = false;
4652 mForcingShowNavBarLayer = -1;
RoboErik8a2cfc32014-05-16 11:19:38 -07004653
Dianne Hackborn5f3063e2010-03-10 16:01:58 -08004654 mHideLockScreen = false;
4655 mAllowLockscreenWhenOn = false;
Craig Mautnerad09bcc2012-10-08 13:33:11 -07004656 mDismissKeyguard = DISMISS_KEYGUARD_NONE;
Dianne Hackborn7ad44382012-10-18 17:46:00 -07004657 mShowingLockscreen = false;
4658 mShowingDream = false;
Craig Mautnerc9457fa2014-06-06 14:27:48 -07004659 mWinShowWhenLocked = null;
Jim Millerab954542014-10-10 18:21:49 -07004660 mKeyguardSecure = isKeyguardSecure();
4661 mKeyguardSecureIncludingHidden = mKeyguardSecure
4662 && (mKeyguardDelegate != null && mKeyguardDelegate.isShowing());
Dianne Hackborn5f3063e2010-03-10 16:01:58 -08004663 }
4664
4665 /** {@inheritDoc} */
Craig Mautnerad09bcc2012-10-08 13:33:11 -07004666 @Override
Yohei Yukawad1a09222015-06-30 16:22:05 -07004667 public void applyPostLayoutPolicyLw(WindowState win, WindowManager.LayoutParams attrs,
4668 WindowState attached) {
Dianne Hackbornbc1aa7b2011-09-20 11:20:31 -07004669 if (DEBUG_LAYOUT) Slog.i(TAG, "Win " + win + ": isVisibleOrBehindKeyguardLw="
4670 + win.isVisibleOrBehindKeyguardLw());
John Spurlockc6d1c602014-01-17 15:22:06 -05004671 final int fl = PolicyControl.getWindowFlags(win, attrs);
John Spurlock414c1f02013-12-04 13:47:36 -05004672 if (mTopFullscreenOpaqueWindowState == null
4673 && win.isVisibleLw() && attrs.type == TYPE_INPUT_METHOD) {
4674 mForcingShowNavBar = true;
4675 mForcingShowNavBarLayer = win.getSurfaceLayer();
Dianne Hackborn891d3fb2013-01-09 18:31:37 -08004676 }
Selim Cinek4a4a2bddc2015-05-07 12:50:19 -07004677 if (attrs.type == TYPE_STATUS_BAR) {
4678 if ((attrs.privateFlags & PRIVATE_FLAG_KEYGUARD) != 0) {
4679 mForceStatusBarFromKeyguard = true;
Jorim Jaggie1de9f62015-09-23 14:59:50 -07004680 mShowingLockscreen = true;
Selim Cinek4a4a2bddc2015-05-07 12:50:19 -07004681 }
4682 if ((attrs.privateFlags & PRIVATE_FLAG_FORCE_STATUS_BAR_VISIBLE_TRANSPARENT) != 0) {
4683 mForceStatusBarTransparent = true;
4684 }
Jorim Jaggiafd4a552014-04-08 15:13:05 +02004685 }
Adrian Roos602c68e2015-04-24 16:03:47 -07004686
4687 boolean appWindow = attrs.type >= FIRST_APPLICATION_WINDOW
4688 && attrs.type < FIRST_SYSTEM_WINDOW;
4689 final boolean showWhenLocked = (fl & FLAG_SHOW_WHEN_LOCKED) != 0;
4690 final boolean dismissKeyguard = (fl & FLAG_DISMISS_KEYGUARD) != 0;
Jorim Jaggi86905582016-02-09 21:36:09 -08004691 final int stackId = win.getStackId();
Dianne Hackborn5f3063e2010-03-10 16:01:58 -08004692 if (mTopFullscreenOpaqueWindowState == null &&
Dianne Hackborn01b02a72012-01-12 14:05:03 -08004693 win.isVisibleOrBehindKeyguardLw() && !win.isGoneForLayoutLw()) {
John Spurlockc6d1c602014-01-17 15:22:06 -05004694 if ((fl & FLAG_FORCE_NOT_FULLSCREEN) != 0) {
Jorim Jaggi380ecb82014-03-14 17:25:20 +01004695 if ((attrs.privateFlags & PRIVATE_FLAG_KEYGUARD) != 0) {
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07004696 mForceStatusBarFromKeyguard = true;
4697 } else {
4698 mForceStatusBar = true;
4699 }
4700 }
Dianne Hackborn7ad44382012-10-18 17:46:00 -07004701 if (attrs.type == TYPE_DREAM) {
Jeff Brownc8018eb2012-10-29 21:33:27 -07004702 // If the lockscreen was showing when the dream started then wait
4703 // for the dream to draw before hiding the lockscreen.
4704 if (!mDreamingLockscreen
4705 || (win.isVisibleLw() && win.hasDrawnLw())) {
4706 mShowingDream = true;
Craig Mautnerab55e522014-03-03 13:26:03 -08004707 appWindow = true;
Dianne Hackborn7ad44382012-10-18 17:46:00 -07004708 }
4709 }
Craig Mautnerab55e522014-03-03 13:26:03 -08004710
Yohei Yukawad1a09222015-06-30 16:22:05 -07004711 final IApplicationToken appToken = win.getAppToken();
4712
4713 // For app windows that are not attached, we decide if all windows in the app they
4714 // represent should be hidden or if we should hide the lockscreen. For attached app
4715 // windows we defer the decision to the window it is attached to.
4716 if (appWindow && attached == null) {
Jorim Jaggic13fcac2014-09-11 17:36:57 +02004717 if (showWhenLocked) {
Craig Mautnerc9457fa2014-06-06 14:27:48 -07004718 // Remove any previous windows with the same appToken.
Jorim Jaggic13fcac2014-09-11 17:36:57 +02004719 mAppsToBeHidden.remove(appToken);
4720 mAppsThatDismissKeyguard.remove(appToken);
Craig Mautnerca0a1242014-12-02 12:25:14 -08004721 if (mAppsToBeHidden.isEmpty()) {
Craig Mautner192d6042014-12-02 23:24:48 -08004722 if (dismissKeyguard && !mKeyguardSecure) {
4723 mAppsThatDismissKeyguard.add(appToken);
Selim Cinek90b5e072015-08-28 17:05:56 -07004724 } else if (win.isDrawnLw() || win.hasAppShownWindows()) {
Craig Mautnerca0a1242014-12-02 12:25:14 -08004725 mWinShowWhenLocked = win;
4726 mHideLockScreen = true;
4727 mForceStatusBarFromKeyguard = false;
Craig Mautnerca0a1242014-12-02 12:25:14 -08004728 }
Craig Mautnerc9457fa2014-06-06 14:27:48 -07004729 }
Jorim Jaggic13fcac2014-09-11 17:36:57 +02004730 } else if (dismissKeyguard) {
Jim Millerab954542014-10-10 18:21:49 -07004731 if (mKeyguardSecure) {
Jorim Jaggic13fcac2014-09-11 17:36:57 +02004732 mAppsToBeHidden.add(appToken);
4733 } else {
4734 mAppsToBeHidden.remove(appToken);
4735 }
4736 mAppsThatDismissKeyguard.add(appToken);
Craig Mautner2bc789b2014-03-19 19:48:38 -07004737 } else {
Jorim Jaggic13fcac2014-09-11 17:36:57 +02004738 mAppsToBeHidden.add(appToken);
Craig Mautner2bc789b2014-03-19 19:48:38 -07004739 }
Jorim Jaggi86905582016-02-09 21:36:09 -08004740 if (isFullscreen(attrs) && StackId.normallyFullscreenWindows(stackId)) {
Craig Mautnerab55e522014-03-03 13:26:03 -08004741 if (DEBUG_LAYOUT) Slog.v(TAG, "Fullscreen window: " + win);
4742 mTopFullscreenOpaqueWindowState = win;
Adrian Rooscd3884d2015-02-18 17:25:23 +01004743 if (mTopFullscreenOpaqueOrDimmingWindowState == null) {
4744 mTopFullscreenOpaqueOrDimmingWindowState = win;
4745 }
Jorim Jaggic13fcac2014-09-11 17:36:57 +02004746 if (!mAppsThatDismissKeyguard.isEmpty() &&
4747 mDismissKeyguard == DISMISS_KEYGUARD_NONE) {
4748 if (DEBUG_LAYOUT) Slog.v(TAG,
4749 "Setting mDismissKeyguard true by win " + win);
tingna_sunge785ffa2015-05-12 13:23:15 +08004750 mDismissKeyguard = (mWinDismissingKeyguard == win
4751 && mSecureDismissingKeyguard == mKeyguardSecure)
4752 ? DISMISS_KEYGUARD_CONTINUE : DISMISS_KEYGUARD_START;
Jorim Jaggic13fcac2014-09-11 17:36:57 +02004753 mWinDismissingKeyguard = win;
tingna_sunge785ffa2015-05-12 13:23:15 +08004754 mSecureDismissingKeyguard = mKeyguardSecure;
Jim Millerab954542014-10-10 18:21:49 -07004755 mForceStatusBarFromKeyguard = mShowingLockscreen && mKeyguardSecure;
Selim Cinek90b5e072015-08-28 17:05:56 -07004756 } else if (mAppsToBeHidden.isEmpty() && showWhenLocked
4757 && (win.isDrawnLw() || win.hasAppShownWindows())) {
Jorim Jaggic13fcac2014-09-11 17:36:57 +02004758 if (DEBUG_LAYOUT) Slog.v(TAG,
4759 "Setting mHideLockScreen to true by win " + win);
4760 mHideLockScreen = true;
4761 mForceStatusBarFromKeyguard = false;
Craig Mautnerab55e522014-03-03 13:26:03 -08004762 }
Craig Mautner00156ec2014-03-06 22:29:02 -08004763 if ((fl & FLAG_ALLOW_LOCK_WHILE_SCREEN_ON) != 0) {
Craig Mautnerab55e522014-03-03 13:26:03 -08004764 mAllowLockscreenWhenOn = true;
4765 }
Dianne Hackborn5f3063e2010-03-10 16:01:58 -08004766 }
Craig Mautnerc9457fa2014-06-06 14:27:48 -07004767
4768 if (mWinShowWhenLocked != null &&
Adrian Roos602c68e2015-04-24 16:03:47 -07004769 mWinShowWhenLocked.getAppToken() != win.getAppToken() &&
4770 (attrs.flags & FLAG_SHOW_WHEN_LOCKED) == 0) {
Craig Mautnerc9457fa2014-06-06 14:27:48 -07004771 win.hideLw(false);
4772 }
Dianne Hackborn5f3063e2010-03-10 16:01:58 -08004773 }
Adrian Roos602c68e2015-04-24 16:03:47 -07004774 } else if (mTopFullscreenOpaqueWindowState == null && mWinShowWhenLocked == null) {
4775 // No TopFullscreenOpaqueWindow is showing, but we found a SHOW_WHEN_LOCKED window
4776 // that is being hidden in an animation - keep the
4777 // keyguard hidden until the new window shows up and
4778 // we know whether to show the keyguard or not.
Adrian Roosb85e1ec2015-05-29 15:23:18 -07004779 if (win.isAnimatingLw() && appWindow && showWhenLocked && mKeyguardHidden) {
Adrian Roos602c68e2015-04-24 16:03:47 -07004780 mHideLockScreen = true;
4781 mWinShowWhenLocked = win;
4782 }
Dianne Hackborn5f3063e2010-03-10 16:01:58 -08004783 }
Jorim Jaggi86905582016-02-09 21:36:09 -08004784
4785 // Keep track of the window if it's dimming but not necessarily fullscreen.
4786 final boolean reallyVisible = win.isVisibleOrBehindKeyguardLw() && !win.isGoneForLayoutLw();
4787 if (mTopFullscreenOpaqueOrDimmingWindowState == null && reallyVisible
4788 && win.isDimming() && StackId.normallyFullscreenWindows(stackId)) {
Adrian Rooscd3884d2015-02-18 17:25:23 +01004789 mTopFullscreenOpaqueOrDimmingWindowState = win;
4790 }
Jorim Jaggi86905582016-02-09 21:36:09 -08004791
4792 // We need to keep track of the top "fullscreen" opaque window for the docked stack
4793 // separately, because both the "real fullscreen" opaque window and the one for the docked
4794 // stack can control View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR.
4795 if (mTopDockedOpaqueWindowState == null && reallyVisible && appWindow && attached == null
4796 && isFullscreen(attrs) && stackId == DOCKED_STACK_ID) {
4797 mTopDockedOpaqueWindowState = win;
4798 if (mTopDockedOpaqueOrDimmingWindowState == null) {
4799 mTopDockedOpaqueOrDimmingWindowState = win;
4800 }
4801 }
4802
4803 // Also keep track of any windows that are dimming but not necessarily fullscreen in the
4804 // docked stack.
4805 if (mTopDockedOpaqueOrDimmingWindowState == null && reallyVisible && win.isDimming()
4806 && stackId == DOCKED_STACK_ID) {
4807 mTopDockedOpaqueOrDimmingWindowState = win;
4808 }
4809 }
4810
4811 private boolean isFullscreen(WindowManager.LayoutParams attrs) {
4812 return attrs.x == 0 && attrs.y == 0
4813 && attrs.width == WindowManager.LayoutParams.MATCH_PARENT
4814 && attrs.height == WindowManager.LayoutParams.MATCH_PARENT;
Dianne Hackborn5f3063e2010-03-10 16:01:58 -08004815 }
4816
4817 /** {@inheritDoc} */
Craig Mautnerad09bcc2012-10-08 13:33:11 -07004818 @Override
Craig Mautner39834192012-09-02 07:47:24 -07004819 public int finishPostLayoutPolicyLw() {
Craig Mautnerc5e73bf2015-04-21 15:41:26 +00004820 if (mWinShowWhenLocked != null && mTopFullscreenOpaqueWindowState != null &&
4821 mWinShowWhenLocked.getAppToken() != mTopFullscreenOpaqueWindowState.getAppToken()
4822 && isKeyguardLocked()) {
Craig Mautnerc9457fa2014-06-06 14:27:48 -07004823 // A dialog is dismissing the keyguard. Put the wallpaper behind it and hide the
4824 // fullscreen window.
4825 // TODO: Make sure FLAG_SHOW_WALLPAPER is restored when dialog is dismissed. Or not.
4826 mWinShowWhenLocked.getAttrs().flags |= FLAG_SHOW_WALLPAPER;
4827 mTopFullscreenOpaqueWindowState.hideLw(false);
4828 mTopFullscreenOpaqueWindowState = mWinShowWhenLocked;
4829 }
4830
Dianne Hackborn39c2d712009-09-22 11:41:31 -07004831 int changes = 0;
Joe Onorato93056472010-09-10 10:30:46 -04004832 boolean topIsFullscreen = false;
Daniel Sandlere02d8082010-10-08 15:13:22 -04004833
4834 final WindowManager.LayoutParams lp = (mTopFullscreenOpaqueWindowState != null)
4835 ? mTopFullscreenOpaqueWindowState.getAttrs()
4836 : null;
4837
Jeff Brownc8018eb2012-10-29 21:33:27 -07004838 // If we are not currently showing a dream then remember the current
4839 // lockscreen state. We will use this to determine whether the dream
4840 // started while the lockscreen was showing and remember this state
4841 // while the dream is showing.
Dianne Hackborn7ad44382012-10-18 17:46:00 -07004842 if (!mShowingDream) {
4843 mDreamingLockscreen = mShowingLockscreen;
Jeff Brown061ea992015-04-17 19:55:47 -07004844 if (mDreamingSleepTokenNeeded) {
4845 mDreamingSleepTokenNeeded = false;
4846 mHandler.obtainMessage(MSG_UPDATE_DREAMING_SLEEP_TOKEN, 0, 1).sendToTarget();
4847 }
4848 } else {
4849 if (!mDreamingSleepTokenNeeded) {
4850 mDreamingSleepTokenNeeded = true;
4851 mHandler.obtainMessage(MSG_UPDATE_DREAMING_SLEEP_TOKEN, 1, 1).sendToTarget();
4852 }
Dianne Hackborn7ad44382012-10-18 17:46:00 -07004853 }
4854
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004855 if (mStatusBar != null) {
Craig Mautnereda67292013-04-28 13:50:14 -07004856 if (DEBUG_LAYOUT) Slog.i(TAG, "force=" + mForceStatusBar
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07004857 + " forcefkg=" + mForceStatusBarFromKeyguard
Dianne Hackbornd70bc2f2009-10-06 23:25:51 -07004858 + " top=" + mTopFullscreenOpaqueWindowState);
Selim Cinek4a4a2bddc2015-05-07 12:50:19 -07004859 boolean shouldBeTransparent = mForceStatusBarTransparent
4860 && !mForceStatusBar
4861 && !mForceStatusBarFromKeyguard;
4862 if (!shouldBeTransparent) {
4863 mStatusBarController.setShowTransparent(false /* transparent */);
4864 } else if (!mStatusBar.isVisibleLw()) {
4865 mStatusBarController.setShowTransparent(true /* transparent */);
4866 }
4867 if (mForceStatusBar || mForceStatusBarFromKeyguard || mForceStatusBarTransparent) {
Craig Mautnereda67292013-04-28 13:50:14 -07004868 if (DEBUG_LAYOUT) Slog.v(TAG, "Showing status bar: forced");
John Spurlock27735a42013-08-14 17:57:38 -04004869 if (mStatusBarController.setBarShowingLw(true)) {
4870 changes |= FINISH_LAYOUT_REDO_LAYOUT;
4871 }
Craig Mautner81defc72013-10-29 11:10:42 -07004872 // Maintain fullscreen layout until incoming animation is complete.
4873 topIsFullscreen = mTopIsFullscreen && mStatusBar.isAnimatingLw();
John Spurlockf92b6162013-11-11 15:01:16 -05004874 // Transient status bar on the lockscreen is not allowed
4875 if (mForceStatusBarFromKeyguard && mStatusBarController.isTransientShowing()) {
4876 mStatusBarController.updateVisibilityLw(false /*transientAllowed*/,
4877 mLastSystemUiFlags, mLastSystemUiFlags);
4878 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004879 } else if (mTopFullscreenOpaqueWindowState != null) {
John Spurlockc6d1c602014-01-17 15:22:06 -05004880 final int fl = PolicyControl.getWindowFlags(null, lp);
Joe Onorato93056472010-09-10 10:30:46 -04004881 if (localLOGV) {
Craig Mautnereda67292013-04-28 13:50:14 -07004882 Slog.d(TAG, "frame: " + mTopFullscreenOpaqueWindowState.getFrameLw()
Filip Gruszczynski2a6a2c22015-10-14 12:00:53 -07004883 + " shown position: "
4884 + mTopFullscreenOpaqueWindowState.getShownPositionLw());
Craig Mautnereda67292013-04-28 13:50:14 -07004885 Slog.d(TAG, "attr: " + mTopFullscreenOpaqueWindowState.getAttrs()
John Spurlockc6d1c602014-01-17 15:22:06 -05004886 + " lp.flags=0x" + Integer.toHexString(fl));
Joe Onorato93056472010-09-10 10:30:46 -04004887 }
John Spurlockc6d1c602014-01-17 15:22:06 -05004888 topIsFullscreen = (fl & WindowManager.LayoutParams.FLAG_FULLSCREEN) != 0
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07004889 || (mLastSystemUiFlags & View.SYSTEM_UI_FLAG_FULLSCREEN) != 0;
Joe Onorato93056472010-09-10 10:30:46 -04004890 // The subtle difference between the window for mTopFullscreenOpaqueWindowState
Mark Dolinerd0646dc2014-08-27 16:04:02 -07004891 // and mTopIsFullscreen is that mTopIsFullscreen is set only if the window
Joe Onorato93056472010-09-10 10:30:46 -04004892 // has the FLAG_FULLSCREEN set. Not sure if there is another way that to be the
4893 // case though.
John Spurlock27735a42013-08-14 17:57:38 -04004894 if (mStatusBarController.isTransientShowing()) {
4895 if (mStatusBarController.setBarShowingLw(true)) {
John Spurlock32beb2c2013-03-11 10:16:47 -04004896 changes |= FINISH_LAYOUT_REDO_LAYOUT;
4897 }
Wale Ogunwale6e94a9e2015-10-07 15:35:49 -07004898 } else if (topIsFullscreen
4899 && !mWindowManagerInternal.isStackVisible(FREEFORM_WORKSPACE_STACK_ID)
4900 && !mWindowManagerInternal.isStackVisible(DOCKED_STACK_ID)) {
Craig Mautnereda67292013-04-28 13:50:14 -07004901 if (DEBUG_LAYOUT) Slog.v(TAG, "** HIDING status bar");
John Spurlock27735a42013-08-14 17:57:38 -04004902 if (mStatusBarController.setBarShowingLw(false)) {
Dianne Hackbornf87d1962012-04-04 12:48:24 -07004903 changes |= FINISH_LAYOUT_REDO_LAYOUT;
Craig Mautnereda67292013-04-28 13:50:14 -07004904 } else {
Craig Mautnerc5a6e442013-06-05 17:22:35 -07004905 if (DEBUG_LAYOUT) Slog.v(TAG, "Status bar already hiding");
Daniel Sandler40427442010-07-16 11:44:52 -04004906 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004907 } else {
Craig Mautnereda67292013-04-28 13:50:14 -07004908 if (DEBUG_LAYOUT) Slog.v(TAG, "** SHOWING status bar: top is not fullscreen");
John Spurlock27735a42013-08-14 17:57:38 -04004909 if (mStatusBarController.setBarShowingLw(true)) {
4910 changes |= FINISH_LAYOUT_REDO_LAYOUT;
4911 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004912 }
4913 }
4914 }
Daniel Sandlere02d8082010-10-08 15:13:22 -04004915
Craig Mautner81defc72013-10-29 11:10:42 -07004916 if (mTopIsFullscreen != topIsFullscreen) {
4917 if (!topIsFullscreen) {
4918 // Force another layout when status bar becomes fully shown.
4919 changes |= FINISH_LAYOUT_REDO_LAYOUT;
4920 }
4921 mTopIsFullscreen = topIsFullscreen;
4922 }
Daniel Sandlere02d8082010-10-08 15:13:22 -04004923
Craig Mautner39834192012-09-02 07:47:24 -07004924 // Hide the key guard if a visible window explicitly specifies that it wants to be
4925 // displayed when the screen is locked.
Jorim Jaggi5cf17872014-03-26 18:31:48 +01004926 if (mKeyguardDelegate != null && mStatusBar != null) {
4927 if (localLOGV) Slog.v(TAG, "finishPostLayoutPolicyLw: mHideKeyguard="
4928 + mHideLockScreen);
Jim Millerab954542014-10-10 18:21:49 -07004929 if (mDismissKeyguard != DISMISS_KEYGUARD_NONE && !mKeyguardSecure) {
Jorim Jaggi5cf17872014-03-26 18:31:48 +01004930 mKeyguardHidden = true;
Jim Millerab954542014-10-10 18:21:49 -07004931 if (setKeyguardOccludedLw(true)) {
Dianne Hackborn39c2d712009-09-22 11:41:31 -07004932 changes |= FINISH_LAYOUT_REDO_LAYOUT
4933 | FINISH_LAYOUT_REDO_CONFIG
4934 | FINISH_LAYOUT_REDO_WALLPAPER;
4935 }
Jorim Jaggi5cf17872014-03-26 18:31:48 +01004936 if (mKeyguardDelegate.isShowing()) {
4937 mHandler.post(new Runnable() {
4938 @Override
4939 public void run() {
4940 mKeyguardDelegate.keyguardDone(false, false);
4941 }
4942 });
4943 }
4944 } else if (mHideLockScreen) {
4945 mKeyguardHidden = true;
Jorim Jaggi7d85ea92015-05-20 17:20:40 -07004946 mWinDismissingKeyguard = null;
Jim Millerab954542014-10-10 18:21:49 -07004947 if (setKeyguardOccludedLw(true)) {
Jorim Jaggi5cf17872014-03-26 18:31:48 +01004948 changes |= FINISH_LAYOUT_REDO_LAYOUT
4949 | FINISH_LAYOUT_REDO_CONFIG
4950 | FINISH_LAYOUT_REDO_WALLPAPER;
4951 }
4952 } else if (mDismissKeyguard != DISMISS_KEYGUARD_NONE) {
Jorim Jaggi7d85ea92015-05-20 17:20:40 -07004953 mKeyguardHidden = false;
4954 if (setKeyguardOccludedLw(false)) {
4955 changes |= FINISH_LAYOUT_REDO_LAYOUT
4956 | FINISH_LAYOUT_REDO_CONFIG
4957 | FINISH_LAYOUT_REDO_WALLPAPER;
4958 }
Jorim Jaggi5cf17872014-03-26 18:31:48 +01004959 if (mDismissKeyguard == DISMISS_KEYGUARD_START) {
4960 // Only launch the next keyguard unlock window once per window.
Jorim Jaggi5cf17872014-03-26 18:31:48 +01004961 mHandler.post(new Runnable() {
4962 @Override
4963 public void run() {
4964 mKeyguardDelegate.dismiss();
4965 }
4966 });
4967 }
4968 } else {
4969 mWinDismissingKeyguard = null;
tingna_sunge785ffa2015-05-12 13:23:15 +08004970 mSecureDismissingKeyguard = false;
Jorim Jaggi5cf17872014-03-26 18:31:48 +01004971 mKeyguardHidden = false;
Jim Millerab954542014-10-10 18:21:49 -07004972 if (setKeyguardOccludedLw(false)) {
Jorim Jaggi5cf17872014-03-26 18:31:48 +01004973 changes |= FINISH_LAYOUT_REDO_LAYOUT
4974 | FINISH_LAYOUT_REDO_CONFIG
4975 | FINISH_LAYOUT_REDO_WALLPAPER;
4976 }
Suchi Amalapurapu9cdc9032009-05-14 18:01:07 -07004977 }
4978 }
Joe Onorato664644d2011-01-23 17:53:23 -08004979
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07004980 if ((updateSystemUiVisibilityLw()&SYSTEM_UI_CHANGING_LAYOUT) != 0) {
Dianne Hackborndf89e652011-10-06 22:35:11 -07004981 // If the navigation bar has been hidden or shown, we need to do another
4982 // layout pass to update that window.
4983 changes |= FINISH_LAYOUT_REDO_LAYOUT;
4984 }
Joe Onorato664644d2011-01-23 17:53:23 -08004985
Mike Lockwood28569302010-01-28 11:54:40 -05004986 // update since mAllowLockscreenWhenOn might have changed
4987 updateLockScreenTimeout();
Dianne Hackborn39c2d712009-09-22 11:41:31 -07004988 return changes;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004989 }
4990
Jorim Jaggi380ecb82014-03-14 17:25:20 +01004991 /**
Jim Millerab954542014-10-10 18:21:49 -07004992 * Updates the occluded state of the Keyguard.
Jorim Jaggi380ecb82014-03-14 17:25:20 +01004993 *
Jorim Jaggi380ecb82014-03-14 17:25:20 +01004994 * @return Whether the flags have changed and we have to redo the layout.
4995 */
Jim Millerab954542014-10-10 18:21:49 -07004996 private boolean setKeyguardOccludedLw(boolean isOccluded) {
4997 boolean wasOccluded = mKeyguardOccluded;
4998 boolean showing = mKeyguardDelegate.isShowing();
4999 if (wasOccluded && !isOccluded && showing) {
5000 mKeyguardOccluded = false;
5001 mKeyguardDelegate.setOccluded(false);
Jorim Jaggi380ecb82014-03-14 17:25:20 +01005002 mStatusBar.getAttrs().privateFlags |= PRIVATE_FLAG_KEYGUARD;
5003 mStatusBar.getAttrs().flags |= FLAG_SHOW_WALLPAPER;
5004 return true;
Jim Millerab954542014-10-10 18:21:49 -07005005 } else if (!wasOccluded && isOccluded && showing) {
5006 mKeyguardOccluded = true;
5007 mKeyguardDelegate.setOccluded(true);
Jorim Jaggi380ecb82014-03-14 17:25:20 +01005008 mStatusBar.getAttrs().privateFlags &= ~PRIVATE_FLAG_KEYGUARD;
5009 mStatusBar.getAttrs().flags &= ~FLAG_SHOW_WALLPAPER;
5010 return true;
5011 } else {
5012 return false;
5013 }
5014 }
5015
5016 private boolean isStatusBarKeyguard() {
5017 return mStatusBar != null
5018 && (mStatusBar.getAttrs().privateFlags & PRIVATE_FLAG_KEYGUARD) != 0;
5019 }
5020
Jose Lima9546b202014-07-02 17:21:51 -07005021 @Override
Dianne Hackborn08743722009-12-21 12:16:51 -08005022 public boolean allowAppAnimationsLw() {
Jorim Jaggi380ecb82014-03-14 17:25:20 +01005023 if (isStatusBarKeyguard() || mShowingDream) {
Craig Mautner28816302013-10-10 20:31:00 -07005024 // If keyguard or dreams is currently visible, no reason to animate behind it.
Dianne Hackborn08743722009-12-21 12:16:51 -08005025 return false;
5026 }
Dianne Hackborn08743722009-12-21 12:16:51 -08005027 return true;
5028 }
5029
Jose Lima9546b202014-07-02 17:21:51 -07005030 @Override
Dianne Hackborndf89e652011-10-06 22:35:11 -07005031 public int focusChangedLw(WindowState lastFocus, WindowState newFocus) {
Joe Onorato664644d2011-01-23 17:53:23 -08005032 mFocusedWindow = newFocus;
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07005033 if ((updateSystemUiVisibilityLw()&SYSTEM_UI_CHANGING_LAYOUT) != 0) {
Dianne Hackborndf89e652011-10-06 22:35:11 -07005034 // If the navigation bar has been hidden or shown, we need to do another
5035 // layout pass to update that window.
5036 return FINISH_LAYOUT_REDO_LAYOUT;
5037 }
5038 return 0;
Joe Onorato664644d2011-01-23 17:53:23 -08005039 }
5040
Dianne Hackborn0ecadf72009-03-31 18:00:37 -07005041 /** {@inheritDoc} */
Jose Lima9546b202014-07-02 17:21:51 -07005042 @Override
Jeff Brown46b9ac02010-04-22 18:58:52 -07005043 public void notifyLidSwitchChanged(long whenNanos, boolean lidOpen) {
5044 // lid changed state
Jeff Brownc458ce92012-04-30 14:58:40 -07005045 final int newLidState = lidOpen ? LID_OPEN : LID_CLOSED;
5046 if (newLidState == mLidState) {
5047 return;
5048 }
Jeff Brown01a98dd2011-09-20 15:08:29 -07005049
Jeff Brownc458ce92012-04-30 14:58:40 -07005050 mLidState = newLidState;
5051 applyLidSwitchState();
Jeff Brown01a98dd2011-09-20 15:08:29 -07005052 updateRotation(true);
Jeff Brownc458ce92012-04-30 14:58:40 -07005053
5054 if (lidOpen) {
Dianne Hackborn280a64e2015-07-13 14:48:08 -07005055 wakeUp(SystemClock.uptimeMillis(), mAllowTheaterModeWakeFromLidSwitch,
5056 "android.policy:LID");
Jeff Brownc458ce92012-04-30 14:58:40 -07005057 } else if (!mLidControlsSleep) {
Jeff Brown96307042012-07-27 15:51:34 -07005058 mPowerManager.userActivity(SystemClock.uptimeMillis(), false);
Jeff Brown46b9ac02010-04-22 18:58:52 -07005059 }
5060 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005061
Michael Wright3818c922014-09-02 13:59:07 -07005062 @Override
5063 public void notifyCameraLensCoverSwitchChanged(long whenNanos, boolean lensCovered) {
5064 int lensCoverState = lensCovered ? CAMERA_LENS_COVERED : CAMERA_LENS_UNCOVERED;
5065 if (mCameraLensCoverState == lensCoverState) {
5066 return;
5067 }
5068 if (mCameraLensCoverState == CAMERA_LENS_COVERED &&
5069 lensCoverState == CAMERA_LENS_UNCOVERED) {
5070 Intent intent;
5071 final boolean keyguardActive = mKeyguardDelegate == null ? false :
5072 mKeyguardDelegate.isShowing();
5073 if (keyguardActive) {
5074 intent = new Intent(MediaStore.INTENT_ACTION_STILL_IMAGE_CAMERA_SECURE);
5075 } else {
5076 intent = new Intent(MediaStore.INTENT_ACTION_STILL_IMAGE_CAMERA);
5077 }
Dianne Hackborn280a64e2015-07-13 14:48:08 -07005078 wakeUp(whenNanos / 1000000, mAllowTheaterModeWakeFromCameraLens,
5079 "android.policy:CAMERA_COVER");
Bart Sears8b1c27c2015-03-18 23:51:02 +00005080 startActivityAsUser(intent, UserHandle.CURRENT_OR_SELF);
Michael Wright3818c922014-09-02 13:59:07 -07005081 }
5082 mCameraLensCoverState = lensCoverState;
5083 }
5084
Dianne Hackbornad7fa7f2011-01-07 14:06:50 -08005085 void setHdmiPlugged(boolean plugged) {
5086 if (mHdmiPlugged != plugged) {
5087 mHdmiPlugged = plugged;
Dianne Hackbornf87d1962012-04-04 12:48:24 -07005088 updateRotation(true, true);
Dianne Hackbornad7fa7f2011-01-07 14:06:50 -08005089 Intent intent = new Intent(ACTION_HDMI_PLUGGED);
Joe Onoratodc100302011-01-11 17:07:41 -08005090 intent.addFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY_BEFORE_BOOT);
Dianne Hackbornad7fa7f2011-01-07 14:06:50 -08005091 intent.putExtra(EXTRA_HDMI_PLUGGED_STATE, plugged);
Dianne Hackborn5ac72a22012-08-29 18:32:08 -07005092 mContext.sendStickyBroadcastAsUser(intent, UserHandle.ALL);
Dianne Hackbornad7fa7f2011-01-07 14:06:50 -08005093 }
5094 }
5095
Joe Onoratoea495d42011-04-06 11:41:11 -07005096 void initializeHdmiState() {
Joe Onorato7ba631f2011-05-04 15:28:00 -07005097 boolean plugged = false;
Joe Onoratoea495d42011-04-06 11:41:11 -07005098 // watch for HDMI plug messages if the hdmi switch exists
5099 if (new File("/sys/devices/virtual/switch/hdmi/state").exists()) {
5100 mHDMIObserver.startObserving("DEVPATH=/devices/virtual/switch/hdmi");
5101
Joe Onoratoea495d42011-04-06 11:41:11 -07005102 final String filename = "/sys/class/switch/hdmi/state";
5103 FileReader reader = null;
5104 try {
5105 reader = new FileReader(filename);
5106 char[] buf = new char[15];
5107 int n = reader.read(buf);
5108 if (n > 1) {
5109 plugged = 0 != Integer.parseInt(new String(buf, 0, n-1));
5110 }
5111 } catch (IOException ex) {
5112 Slog.w(TAG, "Couldn't read hdmi state from " + filename + ": " + ex);
5113 } catch (NumberFormatException ex) {
5114 Slog.w(TAG, "Couldn't read hdmi state from " + filename + ": " + ex);
5115 } finally {
5116 if (reader != null) {
5117 try {
5118 reader.close();
5119 } catch (IOException ex) {
5120 }
Joe Onoratodc100302011-01-11 17:07:41 -08005121 }
5122 }
5123 }
Joe Onorato7ba631f2011-05-04 15:28:00 -07005124 // This dance forces the code in setHdmiPlugged to run.
5125 // Always do this so the sticky intent is stuck (to false) if there is no hdmi.
5126 mHdmiPlugged = !plugged;
5127 setHdmiPlugged(!mHdmiPlugged);
Joe Onoratodc100302011-01-11 17:07:41 -08005128 }
5129
Dianne Hackbornc0e3f242011-08-19 14:19:10 -07005130 final Object mScreenshotLock = new Object();
Dianne Hackbornfc8fa632011-08-17 16:20:47 -07005131 ServiceConnection mScreenshotConnection = null;
Dianne Hackbornfc8fa632011-08-17 16:20:47 -07005132
Jeff Brownd5bb82d2011-10-12 13:57:59 -07005133 final Runnable mScreenshotTimeout = new Runnable() {
5134 @Override public void run() {
5135 synchronized (mScreenshotLock) {
5136 if (mScreenshotConnection != null) {
5137 mContext.unbindService(mScreenshotConnection);
5138 mScreenshotConnection = null;
Dianne Hackbornfc8fa632011-08-17 16:20:47 -07005139 }
Winson Chung9112ec32011-06-27 13:15:32 -07005140 }
Jeff Brownd5bb82d2011-10-12 13:57:59 -07005141 }
5142 };
5143
5144 // Assume this is called from the Handler thread.
5145 private void takeScreenshot() {
5146 synchronized (mScreenshotLock) {
5147 if (mScreenshotConnection != null) {
5148 return;
5149 }
5150 ComponentName cn = new ComponentName("com.android.systemui",
5151 "com.android.systemui.screenshot.TakeScreenshotService");
5152 Intent intent = new Intent();
5153 intent.setComponent(cn);
5154 ServiceConnection conn = new ServiceConnection() {
5155 @Override
5156 public void onServiceConnected(ComponentName name, IBinder service) {
5157 synchronized (mScreenshotLock) {
5158 if (mScreenshotConnection != this) {
5159 return;
5160 }
5161 Messenger messenger = new Messenger(service);
5162 Message msg = Message.obtain(null, 1);
5163 final ServiceConnection myConn = this;
5164 Handler h = new Handler(mHandler.getLooper()) {
5165 @Override
5166 public void handleMessage(Message msg) {
5167 synchronized (mScreenshotLock) {
5168 if (mScreenshotConnection == myConn) {
5169 mContext.unbindService(mScreenshotConnection);
5170 mScreenshotConnection = null;
5171 mHandler.removeCallbacks(mScreenshotTimeout);
5172 }
5173 }
5174 }
5175 };
5176 msg.replyTo = new Messenger(h);
Winson Chunga63bb842011-10-17 10:26:28 -07005177 msg.arg1 = msg.arg2 = 0;
5178 if (mStatusBar != null && mStatusBar.isVisibleLw())
5179 msg.arg1 = 1;
5180 if (mNavigationBar != null && mNavigationBar.isVisibleLw())
5181 msg.arg2 = 1;
Jeff Brownd5bb82d2011-10-12 13:57:59 -07005182 try {
5183 messenger.send(msg);
5184 } catch (RemoteException e) {
5185 }
5186 }
5187 }
5188 @Override
5189 public void onServiceDisconnected(ComponentName name) {}
5190 };
Amith Yamasani27b89e62013-01-16 12:30:11 -08005191 if (mContext.bindServiceAsUser(
5192 intent, conn, Context.BIND_AUTO_CREATE, UserHandle.CURRENT)) {
Jeff Brownd5bb82d2011-10-12 13:57:59 -07005193 mScreenshotConnection = conn;
5194 mHandler.postDelayed(mScreenshotTimeout, 10000);
5195 }
5196 }
Winson Chung9112ec32011-06-27 13:15:32 -07005197 }
5198
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005199 /** {@inheritDoc} */
Jeff Brown00fa7bd2010-07-02 15:37:36 -07005200 @Override
Jeff Brown037c33e2014-04-09 00:31:55 -07005201 public int interceptKeyBeforeQueueing(KeyEvent event, int policyFlags) {
Jeff Brown96307042012-07-27 15:51:34 -07005202 if (!mSystemBooted) {
5203 // If we have not yet booted, don't let key events do anything.
5204 return 0;
5205 }
5206
Jeff Brown037c33e2014-04-09 00:31:55 -07005207 final boolean interactive = (policyFlags & FLAG_INTERACTIVE) != 0;
Jeff Brown1f245102010-11-18 20:53:46 -08005208 final boolean down = event.getAction() == KeyEvent.ACTION_DOWN;
5209 final boolean canceled = event.isCanceled();
5210 final int keyCode = event.getKeyCode();
Jeff Browne20c9e02010-10-11 14:20:19 -07005211
Jeff Brown3122e442010-10-11 23:32:49 -07005212 final boolean isInjected = (policyFlags & WindowManagerPolicy.FLAG_INJECTED) != 0;
Jeff Brown3122e442010-10-11 23:32:49 -07005213
Mike Lockwoodc72b15f2009-11-28 20:58:22 -05005214 // If screen is off then we treat the case where the keyguard is open but hidden
5215 // the same as if it were open and in front.
5216 // This will prevent any keys other than the power button from waking the screen
5217 // when the keyguard is hidden by another activity.
Jim Miller5ecd8112013-01-09 18:50:26 -08005218 final boolean keyguardActive = (mKeyguardDelegate == null ? false :
Jeff Brown037c33e2014-04-09 00:31:55 -07005219 (interactive ?
Jim Millerab954542014-10-10 18:21:49 -07005220 isKeyguardShowingAndNotOccluded() :
Jim Miller5ecd8112013-01-09 18:50:26 -08005221 mKeyguardDelegate.isShowing()));
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005222
Jeff Brown40013652012-05-16 21:22:36 -07005223 if (DEBUG_INPUT) {
Jeff Brown00fa7bd2010-07-02 15:37:36 -07005224 Log.d(TAG, "interceptKeyTq keycode=" + keyCode
Jeff Brown037c33e2014-04-09 00:31:55 -07005225 + " interactive=" + interactive + " keyguardActive=" + keyguardActive
Jeff Brown26875502014-01-30 21:47:47 -08005226 + " policyFlags=" + Integer.toHexString(policyFlags));
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005227 }
5228
Jeff Brown037c33e2014-04-09 00:31:55 -07005229 // Basic policy based on interactive state.
Jeff Brown4d396052010-10-29 21:50:21 -07005230 int result;
Michael Wright337d9d22014-04-22 15:03:48 -07005231 boolean isWakeKey = (policyFlags & WindowManagerPolicy.FLAG_WAKE) != 0
5232 || event.isWakeKey();
Michael Wrightfc01f042014-09-08 14:12:24 -07005233 if (interactive || (isInjected && !isWakeKey)) {
RoboErikde9ba392014-09-26 12:51:01 -07005234 // When the device is interactive or the key is injected pass the
5235 // key to the application.
Jeff Brown4d396052010-10-29 21:50:21 -07005236 result = ACTION_PASS_TO_USER;
Jose Lima9546b202014-07-02 17:21:51 -07005237 isWakeKey = false;
Michael Wrightfc01f042014-09-08 14:12:24 -07005238 } else if (!interactive && shouldDispatchInputWhenNonInteractive()) {
5239 // If we're currently dozing with the screen on and the keyguard showing, pass the key
5240 // to the application but preserve its wake key status to make sure we still move
5241 // from dozing to fully interactive if we would normally go from off to fully
5242 // interactive.
5243 result = ACTION_PASS_TO_USER;
Jeff Brown4d396052010-10-29 21:50:21 -07005244 } else {
5245 // When the screen is off and the key is not injected, determine whether
5246 // to wake the device but don't pass the key to the application.
5247 result = 0;
Jeff Brown26875502014-01-30 21:47:47 -08005248 if (isWakeKey && (!down || !isWakeKeyWhenScreenOff(keyCode))) {
5249 isWakeKey = false;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005250 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005251 }
5252
Justin Kohd378ad72013-04-01 12:18:26 -07005253 // If the key would be handled globally, just return the result, don't worry about special
5254 // key processing.
Jeff Brown13f00f02014-10-31 14:45:50 -07005255 if (isValidGlobalKey(keyCode)
5256 && mGlobalKeyManager.shouldHandleGlobalKey(keyCode, event)) {
Michael Wright85b1af62014-06-04 14:51:58 -07005257 if (isWakeKey) {
Dianne Hackborn280a64e2015-07-13 14:48:08 -07005258 wakeUp(event.getEventTime(), mAllowTheaterModeWakeFromKey, "android.policy:KEY");
Michael Wright85b1af62014-06-04 14:51:58 -07005259 }
Justin Kohd378ad72013-04-01 12:18:26 -07005260 return result;
5261 }
5262
Jeff Brownbae8e772014-06-12 19:59:45 -07005263 boolean useHapticFeedback = down
5264 && (policyFlags & WindowManagerPolicy.FLAG_VIRTUAL) != 0
5265 && event.getRepeatCount() == 0;
5266
Jeff Brown4d396052010-10-29 21:50:21 -07005267 // Handle special keys.
5268 switch (keyCode) {
5269 case KeyEvent.KEYCODE_VOLUME_DOWN:
Jeff Brownb0418da2010-11-01 15:24:01 -07005270 case KeyEvent.KEYCODE_VOLUME_UP:
5271 case KeyEvent.KEYCODE_VOLUME_MUTE: {
Jeff Brownd5bb82d2011-10-12 13:57:59 -07005272 if (keyCode == KeyEvent.KEYCODE_VOLUME_DOWN) {
5273 if (down) {
Jeff Brown13f00f02014-10-31 14:45:50 -07005274 if (interactive && !mScreenshotChordVolumeDownKeyTriggered
Jeff Brownd5bb82d2011-10-12 13:57:59 -07005275 && (event.getFlags() & KeyEvent.FLAG_FALLBACK) == 0) {
Jeff Brown13f00f02014-10-31 14:45:50 -07005276 mScreenshotChordVolumeDownKeyTriggered = true;
5277 mScreenshotChordVolumeDownKeyTime = event.getDownTime();
5278 mScreenshotChordVolumeDownKeyConsumed = false;
Jeff Brownd5bb82d2011-10-12 13:57:59 -07005279 cancelPendingPowerKeyAction();
5280 interceptScreenshotChord();
5281 }
5282 } else {
Jeff Brown13f00f02014-10-31 14:45:50 -07005283 mScreenshotChordVolumeDownKeyTriggered = false;
Jeff Brownd5bb82d2011-10-12 13:57:59 -07005284 cancelPendingScreenshotChordAction();
5285 }
5286 } else if (keyCode == KeyEvent.KEYCODE_VOLUME_UP) {
5287 if (down) {
Jeff Brown13f00f02014-10-31 14:45:50 -07005288 if (interactive && !mScreenshotChordVolumeUpKeyTriggered
Jeff Brownd5bb82d2011-10-12 13:57:59 -07005289 && (event.getFlags() & KeyEvent.FLAG_FALLBACK) == 0) {
Jeff Brown13f00f02014-10-31 14:45:50 -07005290 mScreenshotChordVolumeUpKeyTriggered = true;
Jeff Brownd5bb82d2011-10-12 13:57:59 -07005291 cancelPendingPowerKeyAction();
5292 cancelPendingScreenshotChordAction();
5293 }
5294 } else {
Jeff Brown13f00f02014-10-31 14:45:50 -07005295 mScreenshotChordVolumeUpKeyTriggered = false;
Jeff Brownd5bb82d2011-10-12 13:57:59 -07005296 cancelPendingScreenshotChordAction();
5297 }
5298 }
Jeff Brown4d396052010-10-29 21:50:21 -07005299 if (down) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -07005300 TelecomManager telecomManager = getTelecommService();
5301 if (telecomManager != null) {
5302 if (telecomManager.isRinging()) {
Santos Cordon6848f722014-05-21 15:22:12 -07005303 // If an incoming call is ringing, either VOLUME key means
5304 // "silence ringer". We handle these keys here, rather than
5305 // in the InCallScreen, to make sure we'll respond to them
5306 // even if the InCallScreen hasn't come to the foreground yet.
5307 // Look for the DOWN event here, to agree with the "fallback"
5308 // behavior in the InCallScreen.
5309 Log.i(TAG, "interceptKeyBeforeQueueing:"
5310 + " VOLUME key-down while ringing: Silence ringer!");
Jeff Brown4d396052010-10-29 21:50:21 -07005311
Santos Cordon6848f722014-05-21 15:22:12 -07005312 // Silence the ringer. (It's safe to call this
5313 // even if the ringer has already been silenced.)
Tyler Gunnef9f6f92014-09-12 22:16:17 -07005314 telecomManager.silenceRinger();
Jeff Brown4d396052010-10-29 21:50:21 -07005315
Santos Cordon6848f722014-05-21 15:22:12 -07005316 // And *don't* pass this key thru to the current activity
5317 // (which is probably the InCallScreen.)
5318 result &= ~ACTION_PASS_TO_USER;
5319 break;
5320 }
Tyler Gunnef9f6f92014-09-12 22:16:17 -07005321 if (telecomManager.isInCall()
Santos Cordon6848f722014-05-21 15:22:12 -07005322 && (result & ACTION_PASS_TO_USER) == 0) {
5323 // If we are in call but we decided not to pass the key to
RoboErik430fc482014-06-12 15:49:20 -07005324 // the application, just pass it to the session service.
5325
5326 MediaSessionLegacyHelper.getHelper(mContext)
RoboErik3c45c292014-07-08 16:47:31 -07005327 .sendVolumeKeyEvent(event, false);
Santos Cordon6848f722014-05-21 15:22:12 -07005328 break;
Jeff Brown4d396052010-10-29 21:50:21 -07005329 }
5330 }
Jaewan Kim765487f2016-01-12 14:45:42 +09005331 }
5332 if (mUseTvRouting) {
5333 // On TVs, defer special key handlings to
5334 // {@link interceptKeyBeforeDispatching()}.
5335 result |= ACTION_PASS_TO_USER;
5336 } else if ((result & ACTION_PASS_TO_USER) == 0) {
5337 // If we aren't passing to the user and no one else
5338 // handled it send it to the session manager to
5339 // figure out.
5340 MediaSessionLegacyHelper.getHelper(mContext)
5341 .sendVolumeKeyEvent(event, true);
Jeff Brown4d396052010-10-29 21:50:21 -07005342 }
5343 break;
5344 }
5345
5346 case KeyEvent.KEYCODE_ENDCALL: {
5347 result &= ~ACTION_PASS_TO_USER;
5348 if (down) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -07005349 TelecomManager telecomManager = getTelecommService();
Jeff Brown4d396052010-10-29 21:50:21 -07005350 boolean hungUp = false;
Tyler Gunnef9f6f92014-09-12 22:16:17 -07005351 if (telecomManager != null) {
5352 hungUp = telecomManager.endCall();
Jeff Brown4d396052010-10-29 21:50:21 -07005353 }
Jeff Brown13f00f02014-10-31 14:45:50 -07005354 if (interactive && !hungUp) {
5355 mEndCallKeyHandled = false;
5356 mHandler.postDelayed(mEndCallLongPress,
5357 ViewConfiguration.get(mContext).getDeviceGlobalActionKeyTimeout());
5358 } else {
5359 mEndCallKeyHandled = true;
5360 }
Jeff Brown4d396052010-10-29 21:50:21 -07005361 } else {
Jeff Brown13f00f02014-10-31 14:45:50 -07005362 if (!mEndCallKeyHandled) {
5363 mHandler.removeCallbacks(mEndCallLongPress);
5364 if (!canceled) {
5365 if ((mEndcallBehavior
5366 & Settings.System.END_BUTTON_BEHAVIOR_HOME) != 0) {
5367 if (goHome()) {
5368 break;
5369 }
Dianne Hackborn0041e972009-07-24 17:14:43 -07005370 }
Jeff Brown13f00f02014-10-31 14:45:50 -07005371 if ((mEndcallBehavior
5372 & Settings.System.END_BUTTON_BEHAVIOR_SLEEP) != 0) {
5373 mPowerManager.goToSleep(event.getEventTime(),
5374 PowerManager.GO_TO_SLEEP_REASON_POWER_BUTTON, 0);
5375 isWakeKey = false;
5376 }
Jeff Brown4d396052010-10-29 21:50:21 -07005377 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005378 }
Jeff Brown4d396052010-10-29 21:50:21 -07005379 }
5380 break;
5381 }
5382
5383 case KeyEvent.KEYCODE_POWER: {
5384 result &= ~ACTION_PASS_TO_USER;
Jeff Brown13f00f02014-10-31 14:45:50 -07005385 isWakeKey = false; // wake-up will be handled separately
Jeff Brown4d396052010-10-29 21:50:21 -07005386 if (down) {
Jeff Brown13f00f02014-10-31 14:45:50 -07005387 interceptPowerKeyDown(event, interactive);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005388 } else {
Jeff Brown13f00f02014-10-31 14:45:50 -07005389 interceptPowerKeyUp(event, interactive, canceled);
Jeff Brown4d396052010-10-29 21:50:21 -07005390 }
5391 break;
5392 }
5393
Jeff Brown6212a492014-03-07 13:58:47 -08005394 case KeyEvent.KEYCODE_SLEEP: {
5395 result &= ~ACTION_PASS_TO_USER;
Filip Gruszczynskia483a1d2015-03-17 19:06:58 +00005396 isWakeKey = false;
Jeff Brownbae8e772014-06-12 19:59:45 -07005397 if (!mPowerManager.isInteractive()) {
5398 useHapticFeedback = false; // suppress feedback if already non-interactive
5399 }
Nick Vaccarob593a812015-05-15 11:23:05 -07005400 if (down) {
5401 sleepPress(event.getEventTime());
5402 } else {
5403 sleepRelease(event.getEventTime());
5404 }
Jeff Brown6212a492014-03-07 13:58:47 -08005405 break;
5406 }
5407
Nick Armstrong-Crews56ecfcc2015-09-07 21:46:50 -07005408 case KeyEvent.KEYCODE_SOFT_SLEEP: {
5409 result &= ~ACTION_PASS_TO_USER;
5410 isWakeKey = false;
5411 if (!down) {
5412 mPowerManagerInternal.setUserInactiveOverrideFromWindowManager();
5413 }
5414 break;
5415 }
5416
Jeff Brown6212a492014-03-07 13:58:47 -08005417 case KeyEvent.KEYCODE_WAKEUP: {
5418 result &= ~ACTION_PASS_TO_USER;
Jose Lima9546b202014-07-02 17:21:51 -07005419 isWakeKey = true;
Jeff Brown6212a492014-03-07 13:58:47 -08005420 break;
5421 }
5422
Jeff Brown4d396052010-10-29 21:50:21 -07005423 case KeyEvent.KEYCODE_MEDIA_PLAY:
5424 case KeyEvent.KEYCODE_MEDIA_PAUSE:
5425 case KeyEvent.KEYCODE_MEDIA_PLAY_PAUSE:
Jeff Brown4d396052010-10-29 21:50:21 -07005426 case KeyEvent.KEYCODE_HEADSETHOOK:
5427 case KeyEvent.KEYCODE_MUTE:
5428 case KeyEvent.KEYCODE_MEDIA_STOP:
5429 case KeyEvent.KEYCODE_MEDIA_NEXT:
5430 case KeyEvent.KEYCODE_MEDIA_PREVIOUS:
5431 case KeyEvent.KEYCODE_MEDIA_REWIND:
5432 case KeyEvent.KEYCODE_MEDIA_RECORD:
Jaekyun Seokbfdad8e2013-07-08 13:53:21 +09005433 case KeyEvent.KEYCODE_MEDIA_FAST_FORWARD:
5434 case KeyEvent.KEYCODE_MEDIA_AUDIO_TRACK: {
RoboErikde9ba392014-09-26 12:51:01 -07005435 if (MediaSessionLegacyHelper.getHelper(mContext).isGlobalPriorityActive()) {
5436 // If the global session is active pass all media keys to it
5437 // instead of the active window.
5438 result &= ~ACTION_PASS_TO_USER;
5439 }
Jeff Brown4d396052010-10-29 21:50:21 -07005440 if ((result & ACTION_PASS_TO_USER) == 0) {
5441 // Only do this if we would otherwise not pass it to the user. In that
5442 // case, the PhoneWindow class will do the same thing, except it will
5443 // only do it if the showing app doesn't process the key on its own.
Jeff Brown40013652012-05-16 21:22:36 -07005444 // Note that we need to make a copy of the key event here because the
5445 // original key event will be recycled when we return.
Jeff Brown4d396052010-10-29 21:50:21 -07005446 mBroadcastWakeLock.acquire();
Jeff Brown40013652012-05-16 21:22:36 -07005447 Message msg = mHandler.obtainMessage(MSG_DISPATCH_MEDIA_KEY_WITH_WAKE_LOCK,
5448 new KeyEvent(event));
5449 msg.setAsynchronous(true);
5450 msg.sendToTarget();
Jeff Brown4d396052010-10-29 21:50:21 -07005451 }
5452 break;
Jeff Brown00fa7bd2010-07-02 15:37:36 -07005453 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005454
Jeff Brown4d396052010-10-29 21:50:21 -07005455 case KeyEvent.KEYCODE_CALL: {
5456 if (down) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -07005457 TelecomManager telecomManager = getTelecommService();
5458 if (telecomManager != null) {
5459 if (telecomManager.isRinging()) {
Santos Cordon6848f722014-05-21 15:22:12 -07005460 Log.i(TAG, "interceptKeyBeforeQueueing:"
5461 + " CALL key-down while ringing: Answer the call!");
Tyler Gunnef9f6f92014-09-12 22:16:17 -07005462 telecomManager.acceptRingingCall();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005463
Santos Cordon6848f722014-05-21 15:22:12 -07005464 // And *don't* pass this key thru to the current activity
5465 // (which is presumably the InCallScreen.)
5466 result &= ~ACTION_PASS_TO_USER;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005467 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005468 }
Jeff Brown00fa7bd2010-07-02 15:37:36 -07005469 }
Jeff Brown4d396052010-10-29 21:50:21 -07005470 break;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005471 }
Michael Wright869a67c2014-08-26 19:33:06 -07005472 case KeyEvent.KEYCODE_VOICE_ASSIST: {
5473 // Only do this if we would otherwise not pass it to the user. In that case,
5474 // interceptKeyBeforeDispatching would apply a similar but different policy in
5475 // order to invoke voice assist actions. Note that we need to make a copy of the
5476 // key event here because the original key event will be recycled when we return.
5477 if ((result & ACTION_PASS_TO_USER) == 0 && !down) {
5478 mBroadcastWakeLock.acquire();
5479 Message msg = mHandler.obtainMessage(MSG_LAUNCH_VOICE_ASSIST_WITH_WAKE_LOCK,
5480 keyguardActive ? 1 : 0, 0);
5481 msg.setAsynchronous(true);
5482 msg.sendToTarget();
5483 }
Jaewan Kim49117872016-01-19 17:24:08 +09005484 break;
5485 }
5486 case KeyEvent.KEYCODE_WINDOW: {
5487 if (mShortPressWindowBehavior == SHORT_PRESS_WINDOW_PICTURE_IN_PICTURE) {
5488 if (!down) {
Jaewan Kimc552b042016-01-18 16:08:45 +09005489 requestTvPictureInPicture(event);
Jaewan Kim49117872016-01-19 17:24:08 +09005490 }
5491 result &= ~ACTION_PASS_TO_USER;
5492 }
5493 break;
Michael Wright869a67c2014-08-26 19:33:06 -07005494 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005495 }
Jeff Brown26875502014-01-30 21:47:47 -08005496
Jeff Brownbae8e772014-06-12 19:59:45 -07005497 if (useHapticFeedback) {
5498 performHapticFeedbackLw(null, HapticFeedbackConstants.VIRTUAL_KEY, false);
5499 }
5500
Jeff Brown26875502014-01-30 21:47:47 -08005501 if (isWakeKey) {
Dianne Hackborn280a64e2015-07-13 14:48:08 -07005502 wakeUp(event.getEventTime(), mAllowTheaterModeWakeFromKey, "android.policy:KEY");
Jeff Brown26875502014-01-30 21:47:47 -08005503 }
Bryce Lee584a4452014-10-21 15:55:55 -07005504
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005505 return result;
5506 }
5507
Jeff Brown1c2e4942012-11-06 16:32:01 -08005508 /**
Jeff Brown13f00f02014-10-31 14:45:50 -07005509 * Returns true if the key can have global actions attached to it.
5510 * We reserve all power management keys for the system since they require
5511 * very careful handling.
5512 */
5513 private static boolean isValidGlobalKey(int keyCode) {
5514 switch (keyCode) {
5515 case KeyEvent.KEYCODE_POWER:
5516 case KeyEvent.KEYCODE_WAKEUP:
5517 case KeyEvent.KEYCODE_SLEEP:
5518 return false;
5519 default:
5520 return true;
5521 }
5522 }
5523
5524 /**
Jeff Brown1c2e4942012-11-06 16:32:01 -08005525 * When the screen is off we ignore some keys that might otherwise typically
5526 * be considered wake keys. We filter them out here.
5527 *
5528 * {@link KeyEvent#KEYCODE_POWER} is notably absent from this list because it
5529 * is always considered a wake key.
5530 */
5531 private boolean isWakeKeyWhenScreenOff(int keyCode) {
5532 switch (keyCode) {
5533 // ignore volume keys unless docked
5534 case KeyEvent.KEYCODE_VOLUME_UP:
5535 case KeyEvent.KEYCODE_VOLUME_DOWN:
5536 case KeyEvent.KEYCODE_VOLUME_MUTE:
5537 return mDockMode != Intent.EXTRA_DOCK_STATE_UNDOCKED;
5538
5539 // ignore media and camera keys
5540 case KeyEvent.KEYCODE_MUTE:
5541 case KeyEvent.KEYCODE_HEADSETHOOK:
5542 case KeyEvent.KEYCODE_MEDIA_PLAY:
5543 case KeyEvent.KEYCODE_MEDIA_PAUSE:
5544 case KeyEvent.KEYCODE_MEDIA_PLAY_PAUSE:
5545 case KeyEvent.KEYCODE_MEDIA_STOP:
5546 case KeyEvent.KEYCODE_MEDIA_NEXT:
5547 case KeyEvent.KEYCODE_MEDIA_PREVIOUS:
5548 case KeyEvent.KEYCODE_MEDIA_REWIND:
5549 case KeyEvent.KEYCODE_MEDIA_RECORD:
5550 case KeyEvent.KEYCODE_MEDIA_FAST_FORWARD:
Jaekyun Seokbfdad8e2013-07-08 13:53:21 +09005551 case KeyEvent.KEYCODE_MEDIA_AUDIO_TRACK:
Jeff Brown1c2e4942012-11-06 16:32:01 -08005552 case KeyEvent.KEYCODE_CAMERA:
5553 return false;
5554 }
5555 return true;
5556 }
5557
5558
Jeff Brown56194eb2011-03-02 19:23:13 -08005559 /** {@inheritDoc} */
5560 @Override
Michael Wright70af00a2014-09-03 19:30:20 -07005561 public int interceptMotionBeforeQueueingNonInteractive(long whenNanos, int policyFlags) {
5562 if ((policyFlags & FLAG_WAKE) != 0) {
Dianne Hackborn280a64e2015-07-13 14:48:08 -07005563 if (wakeUp(whenNanos / 1000000, mAllowTheaterModeWakeFromMotion,
5564 "android.policy:MOTION")) {
Bryce Lee5c138322014-11-03 08:26:09 -08005565 return 0;
5566 }
Michael Wright70af00a2014-09-03 19:30:20 -07005567 }
Bryce Lee5c138322014-11-03 08:26:09 -08005568
Michael Wright70af00a2014-09-03 19:30:20 -07005569 if (shouldDispatchInputWhenNonInteractive()) {
5570 return ACTION_PASS_TO_USER;
5571 }
Bryce Lee5c138322014-11-03 08:26:09 -08005572
Bryce Lee812d7022014-11-10 13:33:28 -08005573 // If we have not passed the action up and we are in theater mode without dreaming,
5574 // there will be no dream to intercept the touch and wake into ambient. The device should
5575 // wake up in this case.
5576 if (isTheaterModeEnabled() && (policyFlags & FLAG_WAKE) != 0) {
Dianne Hackborn280a64e2015-07-13 14:48:08 -07005577 wakeUp(whenNanos / 1000000, mAllowTheaterModeWakeFromMotionWhenNotDreaming,
5578 "android.policy:MOTION");
Bryce Lee812d7022014-11-10 13:33:28 -08005579 }
5580
Jeff Brown037c33e2014-04-09 00:31:55 -07005581 return 0;
Jeff Brown56194eb2011-03-02 19:23:13 -08005582 }
5583
Michael Wright70af00a2014-09-03 19:30:20 -07005584 private boolean shouldDispatchInputWhenNonInteractive() {
Joe LaPennaf2b9b2d2015-11-17 22:22:37 +00005585 // Send events to keyguard while the screen is on.
5586 if (isKeyguardShowingAndNotOccluded() && mDisplay != null
5587 && mDisplay.getState() != Display.STATE_OFF) {
Bryce Lee5c138322014-11-03 08:26:09 -08005588 return true;
5589 }
5590
5591 // Send events to a dozing dream even if the screen is off since the dream
5592 // is in control of the state of the screen.
5593 IDreamManager dreamManager = getDreamManager();
5594
5595 try {
5596 if (dreamManager != null && dreamManager.isDreaming()) {
5597 return true;
5598 }
5599 } catch (RemoteException e) {
5600 Slog.e(TAG, "RemoteException when checking if dreaming", e);
5601 }
5602
5603 // Otherwise, consume events since the user can't see what is being
5604 // interacted with.
5605 return false;
Michael Wright70af00a2014-09-03 19:30:20 -07005606 }
5607
RoboErik001c59c2015-01-26 15:53:51 -08005608 private void dispatchDirectAudioEvent(KeyEvent event) {
5609 if (event.getAction() != KeyEvent.ACTION_DOWN) {
5610 return;
5611 }
5612 int keyCode = event.getKeyCode();
John Spurlockb94f2d62015-03-17 14:11:57 -04005613 int flags = AudioManager.FLAG_SHOW_UI | AudioManager.FLAG_PLAY_SOUND
5614 | AudioManager.FLAG_FROM_KEY;
RoboErik001c59c2015-01-26 15:53:51 -08005615 String pkgName = mContext.getOpPackageName();
5616 switch (keyCode) {
5617 case KeyEvent.KEYCODE_VOLUME_UP:
5618 try {
John Spurlockee5ad722015-03-03 16:17:21 -05005619 getAudioService().adjustSuggestedStreamVolume(AudioManager.ADJUST_RAISE,
John Spurlock90874332015-03-10 16:00:54 -04005620 AudioManager.USE_DEFAULT_STREAM_TYPE, flags, pkgName, TAG);
RoboErik001c59c2015-01-26 15:53:51 -08005621 } catch (RemoteException e) {
5622 Log.e(TAG, "Error dispatching volume up in dispatchTvAudioEvent.", e);
5623 }
5624 break;
5625 case KeyEvent.KEYCODE_VOLUME_DOWN:
5626 try {
John Spurlockee5ad722015-03-03 16:17:21 -05005627 getAudioService().adjustSuggestedStreamVolume(AudioManager.ADJUST_LOWER,
John Spurlock90874332015-03-10 16:00:54 -04005628 AudioManager.USE_DEFAULT_STREAM_TYPE, flags, pkgName, TAG);
RoboErik001c59c2015-01-26 15:53:51 -08005629 } catch (RemoteException e) {
5630 Log.e(TAG, "Error dispatching volume down in dispatchTvAudioEvent.", e);
5631 }
5632 break;
5633 case KeyEvent.KEYCODE_VOLUME_MUTE:
5634 try {
5635 if (event.getRepeatCount() == 0) {
John Spurlockee5ad722015-03-03 16:17:21 -05005636 getAudioService().adjustSuggestedStreamVolume(
5637 AudioManager.ADJUST_TOGGLE_MUTE,
John Spurlock90874332015-03-10 16:00:54 -04005638 AudioManager.USE_DEFAULT_STREAM_TYPE, flags, pkgName, TAG);
RoboErik001c59c2015-01-26 15:53:51 -08005639 }
5640 } catch (RemoteException e) {
5641 Log.e(TAG, "Error dispatching mute in dispatchTvAudioEvent.", e);
5642 }
5643 break;
5644 }
5645 }
5646
Jeff Brown40013652012-05-16 21:22:36 -07005647 void dispatchMediaKeyWithWakeLock(KeyEvent event) {
5648 if (DEBUG_INPUT) {
5649 Slog.d(TAG, "dispatchMediaKeyWithWakeLock: " + event);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005650 }
5651
Jeff Brown40013652012-05-16 21:22:36 -07005652 if (mHavePendingMediaKeyRepeatWithWakeLock) {
5653 if (DEBUG_INPUT) {
5654 Slog.d(TAG, "dispatchMediaKeyWithWakeLock: canceled repeat");
5655 }
5656
5657 mHandler.removeMessages(MSG_DISPATCH_MEDIA_KEY_REPEAT_WITH_WAKE_LOCK);
5658 mHavePendingMediaKeyRepeatWithWakeLock = false;
5659 mBroadcastWakeLock.release(); // pending repeat was holding onto the wake lock
5660 }
5661
5662 dispatchMediaKeyWithWakeLockToAudioService(event);
5663
5664 if (event.getAction() == KeyEvent.ACTION_DOWN
5665 && event.getRepeatCount() == 0) {
5666 mHavePendingMediaKeyRepeatWithWakeLock = true;
5667
5668 Message msg = mHandler.obtainMessage(
5669 MSG_DISPATCH_MEDIA_KEY_REPEAT_WITH_WAKE_LOCK, event);
5670 msg.setAsynchronous(true);
5671 mHandler.sendMessageDelayed(msg, ViewConfiguration.getKeyRepeatTimeout());
5672 } else {
5673 mBroadcastWakeLock.release();
5674 }
5675 }
5676
5677 void dispatchMediaKeyRepeatWithWakeLock(KeyEvent event) {
5678 mHavePendingMediaKeyRepeatWithWakeLock = false;
5679
5680 KeyEvent repeatEvent = KeyEvent.changeTimeRepeat(event,
5681 SystemClock.uptimeMillis(), 1, event.getFlags() | KeyEvent.FLAG_LONG_PRESS);
5682 if (DEBUG_INPUT) {
5683 Slog.d(TAG, "dispatchMediaKeyRepeatWithWakeLock: " + repeatEvent);
5684 }
5685
5686 dispatchMediaKeyWithWakeLockToAudioService(repeatEvent);
5687 mBroadcastWakeLock.release();
5688 }
5689
5690 void dispatchMediaKeyWithWakeLockToAudioService(KeyEvent event) {
5691 if (ActivityManagerNative.isSystemReady()) {
RoboErik430fc482014-06-12 15:49:20 -07005692 MediaSessionLegacyHelper.getHelper(mContext).sendMediaButtonEvent(event, true);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005693 }
5694 }
5695
Michael Wright869a67c2014-08-26 19:33:06 -07005696 void launchVoiceAssistWithWakeLock(boolean keyguardActive) {
Dianne Hackbornb6683c42015-06-18 17:40:33 -07005697 IDeviceIdleController dic = IDeviceIdleController.Stub.asInterface(
5698 ServiceManager.getService(Context.DEVICE_IDLE_CONTROLLER));
5699 if (dic != null) {
5700 try {
5701 dic.exitIdle("voice-search");
5702 } catch (RemoteException e) {
5703 }
5704 }
Michael Wright869a67c2014-08-26 19:33:06 -07005705 Intent voiceIntent =
5706 new Intent(RecognizerIntent.ACTION_VOICE_SEARCH_HANDS_FREE);
5707 voiceIntent.putExtra(RecognizerIntent.EXTRA_SECURE, keyguardActive);
Bart Sears8b1c27c2015-03-18 23:51:02 +00005708 startActivityAsUser(voiceIntent, UserHandle.CURRENT_OR_SELF);
Michael Wright869a67c2014-08-26 19:33:06 -07005709 mBroadcastWakeLock.release();
5710 }
5711
Mike Lockwood1753f7f2009-08-24 14:49:07 -07005712 BroadcastReceiver mDockReceiver = new BroadcastReceiver() {
Craig Mautnereee29c42013-01-17 14:44:34 -08005713 @Override
Mike Lockwood1753f7f2009-08-24 14:49:07 -07005714 public void onReceive(Context context, Intent intent) {
Dianne Hackborn867ab6472010-04-29 13:28:56 -07005715 if (Intent.ACTION_DOCK_EVENT.equals(intent.getAction())) {
5716 mDockMode = intent.getIntExtra(Intent.EXTRA_DOCK_STATE,
5717 Intent.EXTRA_DOCK_STATE_UNDOCKED);
Daniel Sandler6396c722013-04-16 20:19:09 -04005718 } else {
5719 try {
5720 IUiModeManager uiModeService = IUiModeManager.Stub.asInterface(
5721 ServiceManager.getService(Context.UI_MODE_SERVICE));
5722 mUiMode = uiModeService.getCurrentModeType();
5723 } catch (RemoteException e) {
5724 }
Dianne Hackborn80fa1662009-10-07 14:02:10 -07005725 }
Jeff Brown01a98dd2011-09-20 15:08:29 -07005726 updateRotation(true);
Craig Mautnereee29c42013-01-17 14:44:34 -08005727 synchronized (mLock) {
5728 updateOrientationListenerLp();
5729 }
Mike Lockwood1753f7f2009-08-24 14:49:07 -07005730 }
5731 };
5732
Jeff Brown6aaf2952012-10-05 16:01:08 -07005733 BroadcastReceiver mDreamReceiver = new BroadcastReceiver() {
5734 @Override
5735 public void onReceive(Context context, Intent intent) {
5736 if (Intent.ACTION_DREAMING_STARTED.equals(intent.getAction())) {
Jim Miller5ecd8112013-01-09 18:50:26 -08005737 if (mKeyguardDelegate != null) {
5738 mKeyguardDelegate.onDreamingStarted();
Jeff Brown6aaf2952012-10-05 16:01:08 -07005739 }
5740 } else if (Intent.ACTION_DREAMING_STOPPED.equals(intent.getAction())) {
Jim Miller5ecd8112013-01-09 18:50:26 -08005741 if (mKeyguardDelegate != null) {
5742 mKeyguardDelegate.onDreamingStopped();
Jeff Brown6aaf2952012-10-05 16:01:08 -07005743 }
5744 }
5745 }
5746 };
5747
Christopher Tate5e08af02012-09-21 17:17:22 -07005748 BroadcastReceiver mMultiuserReceiver = new BroadcastReceiver() {
5749 @Override
5750 public void onReceive(Context context, Intent intent) {
5751 if (Intent.ACTION_USER_SWITCHED.equals(intent.getAction())) {
5752 // tickle the settings observer: this first ensures that we're
5753 // observing the relevant settings for the newly-active user,
5754 // and then updates our own bookkeeping based on the now-
5755 // current user.
5756 mSettingsObserver.onChange(false);
John Spurlockce479d82012-11-29 09:52:21 -05005757
5758 // force a re-application of focused window sysui visibility.
5759 // the window may never have been shown for this user
5760 // e.g. the keyguard when going through the new-user setup flow
John Spurlock04db1762013-05-13 12:46:41 -04005761 synchronized (mWindowManagerFuncs.getWindowManagerLock()) {
John Spurlockce479d82012-11-29 09:52:21 -05005762 mLastSystemUiFlags = 0;
5763 updateSystemUiVisibilityLw();
5764 }
Christopher Tate5e08af02012-09-21 17:17:22 -07005765 }
5766 }
5767 };
5768
Adrian Roosddc8b272015-05-21 16:28:27 -07005769 private final Runnable mHiddenNavPanic = new Runnable() {
John Spurlockd9b70bd2014-02-06 17:02:44 -05005770 @Override
5771 public void run() {
Adrian Roosddc8b272015-05-21 16:28:27 -07005772 synchronized (mWindowManagerFuncs.getWindowManagerLock()) {
5773 if (!isUserSetupComplete()) {
5774 // Swipe-up for navigation bar is disabled during setup
5775 return;
5776 }
5777 mPendingPanicGestureUptime = SystemClock.uptimeMillis();
5778 mNavigationBarController.showTransient();
5779 }
John Spurlockd9b70bd2014-02-06 17:02:44 -05005780 }
5781 };
5782
John Spurlocke1f366f2013-08-05 12:22:40 -04005783 private void requestTransientBars(WindowState swipeTarget) {
John Spurlock04db1762013-05-13 12:46:41 -04005784 synchronized (mWindowManagerFuncs.getWindowManagerLock()) {
Maurice Lam99c6e072014-04-28 18:24:28 -07005785 if (!isUserSetupComplete()) {
5786 // Swipe-up for navigation bar is disabled during setup
5787 return;
5788 }
John Spurlock27735a42013-08-14 17:57:38 -04005789 boolean sb = mStatusBarController.checkShowTransientBarLw();
5790 boolean nb = mNavigationBarController.checkShowTransientBarLw();
John Spurlockad3e6cb2013-04-30 08:47:43 -04005791 if (sb || nb) {
Adrian Roos62b65e42015-02-25 18:05:34 +01005792 // Don't show status bar when swiping on already visible navigation bar
5793 if (!nb && swipeTarget == mNavigationBar) {
John Spurlocke1f366f2013-08-05 12:22:40 -04005794 if (DEBUG) Slog.d(TAG, "Not showing transient bar, wrong swipe target");
John Spurlockad3e6cb2013-04-30 08:47:43 -04005795 return;
5796 }
John Spurlock27735a42013-08-14 17:57:38 -04005797 if (sb) mStatusBarController.showTransient();
5798 if (nb) mNavigationBarController.showTransient();
John Spurlockf1a36642013-10-12 17:50:42 -04005799 mImmersiveModeConfirmation.confirmCurrentPrompt();
John Spurlockad3e6cb2013-04-30 08:47:43 -04005800 updateSystemUiVisibilityLw();
John Spurlock32beb2c2013-03-11 10:16:47 -04005801 }
John Spurlockad3e6cb2013-04-30 08:47:43 -04005802 }
5803 }
5804
Jeff Brown3ee549c2014-09-22 20:14:39 -07005805 // Called on the PowerManager's Notifier thread.
Jeff Brownc38c9be2012-10-04 13:16:19 -07005806 @Override
Jeff Brown416c49c2015-05-26 19:50:18 -07005807 public void startedGoingToSleep(int why) {
5808 if (DEBUG_WAKEUP) Slog.i(TAG, "Started going to sleep... (why=" + why + ")");
Jorim Jaggid175b6c2015-05-27 15:39:09 -07005809 if (mKeyguardDelegate != null) {
5810 mKeyguardDelegate.onStartedGoingToSleep(why);
5811 }
Jeff Brown416c49c2015-05-26 19:50:18 -07005812 }
5813
5814 // Called on the PowerManager's Notifier thread.
5815 @Override
5816 public void finishedGoingToSleep(int why) {
Dianne Hackborn74489012009-03-24 20:50:09 -07005817 EventLog.writeEvent(70000, 0);
Jeff Brown416c49c2015-05-26 19:50:18 -07005818 if (DEBUG_WAKEUP) Slog.i(TAG, "Finished going to sleep... (why=" + why + ")");
Chris Wren9bb290b2015-06-29 12:02:13 -04005819 MetricsLogger.histogram(mContext, "screen_timeout", mLockScreenTimeout / 1000);
Jeff Brown3ee549c2014-09-22 20:14:39 -07005820
5821 // We must get this work done here because the power manager will drop
5822 // the wake lock and let the system suspend once this function returns.
The Android Open Source Project0727d222009-03-11 12:11:58 -07005823 synchronized (mLock) {
Jeff Brown3ee549c2014-09-22 20:14:39 -07005824 mAwake = false;
Jeff Browna20dda42014-05-27 20:57:24 -07005825 updateWakeGestureListenerLp();
The Android Open Source Project0727d222009-03-11 12:11:58 -07005826 updateOrientationListenerLp();
Mike Lockwood28569302010-01-28 11:54:40 -05005827 updateLockScreenTimeout();
The Android Open Source Project0727d222009-03-11 12:11:58 -07005828 }
Jeff Brown3ee549c2014-09-22 20:14:39 -07005829 if (mKeyguardDelegate != null) {
Jorim Jaggid175b6c2015-05-27 15:39:09 -07005830 mKeyguardDelegate.onFinishedGoingToSleep(why);
Jeff Brown3ee549c2014-09-22 20:14:39 -07005831 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005832 }
5833
Jeff Brown3ee549c2014-09-22 20:14:39 -07005834 // Called on the PowerManager's Notifier thread.
Jeff Brownc38c9be2012-10-04 13:16:19 -07005835 @Override
Jeff Brown416c49c2015-05-26 19:50:18 -07005836 public void startedWakingUp() {
Dianne Hackborn74489012009-03-24 20:50:09 -07005837 EventLog.writeEvent(70000, 1);
Jeff Brown416c49c2015-05-26 19:50:18 -07005838 if (DEBUG_WAKEUP) Slog.i(TAG, "Started waking up...");
Craig Mautner8a0da012014-05-31 15:13:37 -07005839
Jeff Brown3ee549c2014-09-22 20:14:39 -07005840 // Since goToSleep performs these functions synchronously, we must
5841 // do the same here. We cannot post this work to a handler because
5842 // that might cause it to become reordered with respect to what
5843 // may happen in a future call to goToSleep.
The Android Open Source Project0727d222009-03-11 12:11:58 -07005844 synchronized (mLock) {
Jeff Brown3ee549c2014-09-22 20:14:39 -07005845 mAwake = true;
Jeff Brown3ee549c2014-09-22 20:14:39 -07005846
Jeff Browna20dda42014-05-27 20:57:24 -07005847 updateWakeGestureListenerLp();
The Android Open Source Project0727d222009-03-11 12:11:58 -07005848 updateOrientationListenerLp();
Mike Lockwood28569302010-01-28 11:54:40 -05005849 updateLockScreenTimeout();
The Android Open Source Project0727d222009-03-11 12:11:58 -07005850 }
Jeff Brownc38c9be2012-10-04 13:16:19 -07005851
Jim Miller5ecd8112013-01-09 18:50:26 -08005852 if (mKeyguardDelegate != null) {
Jorim Jaggi4cfdcf52015-07-09 12:13:59 -07005853 mKeyguardDelegate.onStartedWakingUp();
Jeff Brownc38c9be2012-10-04 13:16:19 -07005854 }
Jeff Brown36c4db82014-09-19 12:05:31 -07005855 }
5856
Jeff Brown416c49c2015-05-26 19:50:18 -07005857 // Called on the PowerManager's Notifier thread.
5858 @Override
5859 public void finishedWakingUp() {
5860 if (DEBUG_WAKEUP) Slog.i(TAG, "Finished waking up...");
5861 }
5862
5863 private void wakeUpFromPowerKey(long eventTime) {
Dianne Hackborn280a64e2015-07-13 14:48:08 -07005864 wakeUp(eventTime, mAllowTheaterModeWakeFromPowerKey, "android.policy:POWER");
Jeff Brown416c49c2015-05-26 19:50:18 -07005865 }
5866
Dianne Hackborn280a64e2015-07-13 14:48:08 -07005867 private boolean wakeUp(long wakeTime, boolean wakeInTheaterMode, String reason) {
Bryce Leed3896842015-06-23 17:06:51 -07005868 final boolean theaterModeEnabled = isTheaterModeEnabled();
5869 if (!wakeInTheaterMode && theaterModeEnabled) {
Jeff Brown416c49c2015-05-26 19:50:18 -07005870 return false;
5871 }
5872
Bryce Leed3896842015-06-23 17:06:51 -07005873 if (theaterModeEnabled) {
5874 Settings.Global.putInt(mContext.getContentResolver(),
5875 Settings.Global.THEATER_MODE_ON, 0);
5876 }
5877
Dianne Hackborn280a64e2015-07-13 14:48:08 -07005878 mPowerManager.wakeUp(wakeTime, reason);
Jeff Brown416c49c2015-05-26 19:50:18 -07005879 return true;
5880 }
5881
Jeff Brown36c4db82014-09-19 12:05:31 -07005882 private void finishKeyguardDrawn() {
Jeff Brown3ee549c2014-09-22 20:14:39 -07005883 synchronized (mLock) {
Jorim Jaggif3255482015-07-24 12:32:42 -07005884 if (!mScreenOnEarly || mKeyguardDrawComplete) {
Stefan Kuhne9326dc12015-06-12 09:25:32 -10005885 return; // We are not awake yet or we have already informed of this event.
Jeff Brown3ee549c2014-09-22 20:14:39 -07005886 }
5887
Jeff Brown36c4db82014-09-19 12:05:31 -07005888 mKeyguardDrawComplete = true;
Jeff Brown3ee549c2014-09-22 20:14:39 -07005889 if (mKeyguardDelegate != null) {
5890 mHandler.removeMessages(MSG_KEYGUARD_DRAWN_TIMEOUT);
5891 }
Jorim Jaggi4cfdcf52015-07-09 12:13:59 -07005892 mWindowManagerDrawComplete = false;
Jeff Brown3ee549c2014-09-22 20:14:39 -07005893 }
5894
Jorim Jaggi4cfdcf52015-07-09 12:13:59 -07005895 // ... eventually calls finishWindowsDrawn which will finalize our screen turn on
5896 // as well as enabling the orientation change logic/sensor.
5897 mWindowManagerInternal.waitForAllWindowsDrawn(mWindowManagerDrawCallback,
5898 WAITING_FOR_DRAWN_TIMEOUT);
Jeff Brown3ee549c2014-09-22 20:14:39 -07005899 }
5900
5901 // Called on the DisplayManager's DisplayPowerController thread.
5902 @Override
5903 public void screenTurnedOff() {
5904 if (DEBUG_WAKEUP) Slog.i(TAG, "Screen turned off...");
5905
Jeff Brown48d1b142015-06-10 16:36:03 -07005906 updateScreenOffSleepToken(true);
Jeff Brown3ee549c2014-09-22 20:14:39 -07005907 synchronized (mLock) {
5908 mScreenOnEarly = false;
5909 mScreenOnFully = false;
Jorim Jaggi95c6dae2015-07-29 15:17:23 -07005910 mKeyguardDrawComplete = false;
Jeff Brown3ee549c2014-09-22 20:14:39 -07005911 mWindowManagerDrawComplete = false;
5912 mScreenOnListener = null;
5913 updateOrientationListenerLp();
Jorim Jaggi0d210f62015-07-10 14:24:44 -07005914
5915 if (mKeyguardDelegate != null) {
5916 mKeyguardDelegate.onScreenTurnedOff();
5917 }
Jeff Brown36c4db82014-09-19 12:05:31 -07005918 }
5919 }
5920
Jeff Brown3ee549c2014-09-22 20:14:39 -07005921 // Called on the DisplayManager's DisplayPowerController thread.
Jeff Brown36c4db82014-09-19 12:05:31 -07005922 @Override
5923 public void screenTurningOn(final ScreenOnListener screenOnListener) {
Jeff Brown36c4db82014-09-19 12:05:31 -07005924 if (DEBUG_WAKEUP) Slog.i(TAG, "Screen turning on...");
Jeff Brown36c4db82014-09-19 12:05:31 -07005925
Jeff Brown48d1b142015-06-10 16:36:03 -07005926 updateScreenOffSleepToken(false);
Jeff Brown3ee549c2014-09-22 20:14:39 -07005927 synchronized (mLock) {
5928 mScreenOnEarly = true;
5929 mScreenOnFully = false;
Jorim Jaggi95c6dae2015-07-29 15:17:23 -07005930 mKeyguardDrawComplete = false;
Jeff Brown3ee549c2014-09-22 20:14:39 -07005931 mWindowManagerDrawComplete = false;
5932 mScreenOnListener = screenOnListener;
Jeff Brown36c4db82014-09-19 12:05:31 -07005933
Jorim Jaggi4cfdcf52015-07-09 12:13:59 -07005934 if (mKeyguardDelegate != null) {
Jorim Jaggia4b51bc2015-08-10 18:20:43 -07005935 mHandler.removeMessages(MSG_KEYGUARD_DRAWN_TIMEOUT);
5936 mHandler.sendEmptyMessageDelayed(MSG_KEYGUARD_DRAWN_TIMEOUT, 1000);
Jorim Jaggi4cfdcf52015-07-09 12:13:59 -07005937 mKeyguardDelegate.onScreenTurningOn(mKeyguardDrawnCallback);
5938 } else {
5939 if (DEBUG_WAKEUP) Slog.d(TAG,
5940 "null mKeyguardDelegate: setting mKeyguardDrawComplete.");
5941 finishKeyguardDrawn();
5942 }
5943 }
Jeff Brown36c4db82014-09-19 12:05:31 -07005944 }
5945
Jorim Jaggi0d210f62015-07-10 14:24:44 -07005946 // Called on the DisplayManager's DisplayPowerController thread.
5947 @Override
5948 public void screenTurnedOn() {
5949 synchronized (mLock) {
5950 if (mKeyguardDelegate != null) {
5951 mKeyguardDelegate.onScreenTurnedOn();
5952 }
5953 }
5954 }
5955
Jeff Brown36c4db82014-09-19 12:05:31 -07005956 private void finishWindowsDrawn() {
Jeff Brown3ee549c2014-09-22 20:14:39 -07005957 synchronized (mLock) {
5958 if (!mScreenOnEarly || mWindowManagerDrawComplete) {
Stefan Kuhne9326dc12015-06-12 09:25:32 -10005959 return; // Screen is not turned on or we did already handle this case earlier.
Jeff Brown3ee549c2014-09-22 20:14:39 -07005960 }
5961
Jeff Brown36c4db82014-09-19 12:05:31 -07005962 mWindowManagerDrawComplete = true;
Jeff Brown36c4db82014-09-19 12:05:31 -07005963 }
Jeff Brown3ee549c2014-09-22 20:14:39 -07005964
5965 finishScreenTurningOn();
Jeff Brownc38c9be2012-10-04 13:16:19 -07005966 }
5967
Craig Mautner8a0da012014-05-31 15:13:37 -07005968 private void finishScreenTurningOn() {
Stefan Kuhne9326dc12015-06-12 09:25:32 -10005969 synchronized (mLock) {
5970 // We have just finished drawing screen content. Since the orientation listener
5971 // gets only installed when all windows are drawn, we try to install it again.
5972 updateOrientationListenerLp();
5973 }
Jeff Brown3ee549c2014-09-22 20:14:39 -07005974 final ScreenOnListener listener;
5975 final boolean enableScreen;
Jeff Brown36c4db82014-09-19 12:05:31 -07005976 synchronized (mLock) {
Jeff Brown3ee549c2014-09-22 20:14:39 -07005977 if (DEBUG_WAKEUP) Slog.d(TAG,
5978 "finishScreenTurningOn: mAwake=" + mAwake
5979 + ", mScreenOnEarly=" + mScreenOnEarly
5980 + ", mScreenOnFully=" + mScreenOnFully
5981 + ", mKeyguardDrawComplete=" + mKeyguardDrawComplete
5982 + ", mWindowManagerDrawComplete=" + mWindowManagerDrawComplete);
5983
5984 if (mScreenOnFully || !mScreenOnEarly || !mWindowManagerDrawComplete
5985 || (mAwake && !mKeyguardDrawComplete)) {
5986 return; // spurious or not ready yet
Jeff Brown36c4db82014-09-19 12:05:31 -07005987 }
5988
Jeff Brown3ee549c2014-09-22 20:14:39 -07005989 if (DEBUG_WAKEUP) Slog.i(TAG, "Finished screen turning on...");
5990 listener = mScreenOnListener;
Craig Mautner13f6ea72014-06-23 14:57:02 -07005991 mScreenOnListener = null;
Jeff Brown3ee549c2014-09-22 20:14:39 -07005992 mScreenOnFully = true;
5993
5994 // Remember the first time we draw the keyguard so we know when we're done with
5995 // the main part of booting and can enable the screen and hide boot messages.
5996 if (!mKeyguardDrawnOnce && mAwake) {
5997 mKeyguardDrawnOnce = true;
5998 enableScreen = true;
5999 if (mBootMessageNeedsHiding) {
6000 mBootMessageNeedsHiding = false;
6001 hideBootMessages();
6002 }
6003 } else {
6004 enableScreen = false;
6005 }
Jeff Brownc38c9be2012-10-04 13:16:19 -07006006 }
6007
Jeff Brown3ee549c2014-09-22 20:14:39 -07006008 if (listener != null) {
6009 listener.onScreenOn();
6010 }
Jeff Brown4fc45272012-10-10 18:28:14 -07006011
Jeff Brown3ee549c2014-09-22 20:14:39 -07006012 if (enableScreen) {
6013 try {
6014 mWindowManager.enableScreenIfNeeded();
6015 } catch (RemoteException unhandled) {
Jeff Brown36c4db82014-09-19 12:05:31 -07006016 }
Craig Mautnera631d492014-08-05 15:16:01 -07006017 }
6018 }
6019
6020 private void handleHideBootMessage() {
Jeff Brown3ee549c2014-09-22 20:14:39 -07006021 synchronized (mLock) {
6022 if (!mKeyguardDrawnOnce) {
6023 mBootMessageNeedsHiding = true;
6024 return; // keyguard hasn't drawn the first time yet, not done booting
6025 }
Craig Mautnera631d492014-08-05 15:16:01 -07006026 }
Jeff Brown3ee549c2014-09-22 20:14:39 -07006027
6028 if (mBootMsgDialog != null) {
6029 if (DEBUG_WAKEUP) Slog.d(TAG, "handleHideBootMessage: dismissing");
6030 mBootMsgDialog.dismiss();
6031 mBootMsgDialog = null;
Craig Mautnera631d492014-08-05 15:16:01 -07006032 }
Jeff Brownc38c9be2012-10-04 13:16:19 -07006033 }
6034
6035 @Override
Jeff Brown3ee549c2014-09-22 20:14:39 -07006036 public boolean isScreenOn() {
6037 return mScreenOnFully;
Dianne Hackborn08743722009-12-21 12:16:51 -08006038 }
Jeff Brownc38c9be2012-10-04 13:16:19 -07006039
Dianne Hackborn08743722009-12-21 12:16:51 -08006040 /** {@inheritDoc} */
Jose Lima9546b202014-07-02 17:21:51 -07006041 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006042 public void enableKeyguard(boolean enabled) {
Jim Miller5ecd8112013-01-09 18:50:26 -08006043 if (mKeyguardDelegate != null) {
6044 mKeyguardDelegate.setKeyguardEnabled(enabled);
Mike Lockwood3a74bd32011-08-12 13:55:22 -07006045 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006046 }
6047
6048 /** {@inheritDoc} */
Jose Lima9546b202014-07-02 17:21:51 -07006049 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006050 public void exitKeyguardSecurely(OnKeyguardExitResult callback) {
Jim Miller5ecd8112013-01-09 18:50:26 -08006051 if (mKeyguardDelegate != null) {
6052 mKeyguardDelegate.verifyUnlock(callback);
Mike Lockwood3a74bd32011-08-12 13:55:22 -07006053 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006054 }
6055
Jim Millerab954542014-10-10 18:21:49 -07006056 private boolean isKeyguardShowingAndNotOccluded() {
Jim Miller5ecd8112013-01-09 18:50:26 -08006057 if (mKeyguardDelegate == null) return false;
Jim Millerab954542014-10-10 18:21:49 -07006058 return mKeyguardDelegate.isShowing() && !mKeyguardOccluded;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006059 }
6060
Mike Lockwood520d8bc2011-02-18 13:23:13 -05006061 /** {@inheritDoc} */
Jose Lima9546b202014-07-02 17:21:51 -07006062 @Override
Mike Lockwood520d8bc2011-02-18 13:23:13 -05006063 public boolean isKeyguardLocked() {
6064 return keyguardOn();
6065 }
6066
6067 /** {@inheritDoc} */
Jose Lima9546b202014-07-02 17:21:51 -07006068 @Override
Mike Lockwood520d8bc2011-02-18 13:23:13 -05006069 public boolean isKeyguardSecure() {
Jim Miller5ecd8112013-01-09 18:50:26 -08006070 if (mKeyguardDelegate == null) return false;
6071 return mKeyguardDelegate.isSecure();
Mike Lockwood520d8bc2011-02-18 13:23:13 -05006072 }
6073
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006074 /** {@inheritDoc} */
Jose Lima9546b202014-07-02 17:21:51 -07006075 @Override
Adrian Roos461829d2015-06-03 14:41:18 -07006076 public boolean isKeyguardShowingOrOccluded() {
6077 return mKeyguardDelegate == null ? false : mKeyguardDelegate.isShowing();
6078 }
6079
6080 /** {@inheritDoc} */
6081 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006082 public boolean inKeyguardRestrictedKeyInputMode() {
Jim Miller5ecd8112013-01-09 18:50:26 -08006083 if (mKeyguardDelegate == null) return false;
6084 return mKeyguardDelegate.isInputRestricted();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006085 }
6086
Jose Lima9546b202014-07-02 17:21:51 -07006087 @Override
Dianne Hackborn90c52de2011-09-23 12:57:44 -07006088 public void dismissKeyguardLw() {
RoboErik8a2cfc32014-05-16 11:19:38 -07006089 if (mKeyguardDelegate != null && mKeyguardDelegate.isShowing()) {
Craig Mautnerc0d2d0a2014-10-31 16:25:15 -07006090 if (DEBUG_KEYGUARD) Slog.d(TAG, "PWM.dismissKeyguardLw");
Daniel Sandler1ce804392012-11-07 15:07:12 -05006091 mHandler.post(new Runnable() {
Jose Lima9546b202014-07-02 17:21:51 -07006092 @Override
Daniel Sandler1ce804392012-11-07 15:07:12 -05006093 public void run() {
Jorim Jaggi8de4311c2014-08-11 22:36:20 +02006094 // ask the keyguard to prompt the user to authenticate if necessary
6095 mKeyguardDelegate.dismiss();
6096 }
6097 });
6098 }
6099 }
6100
6101 public void notifyActivityDrawnForKeyguardLw() {
6102 if (mKeyguardDelegate != null) {
6103 mHandler.post(new Runnable() {
6104 @Override
6105 public void run() {
6106 mKeyguardDelegate.onActivityDrawn();
Daniel Sandler1ce804392012-11-07 15:07:12 -05006107 }
6108 });
Dianne Hackborn90c52de2011-09-23 12:57:44 -07006109 }
6110 }
6111
Jorim Jaggicff0acb2014-03-31 16:35:15 +02006112 @Override
6113 public boolean isKeyguardDrawnLw() {
6114 synchronized (mLock) {
Jeff Brown3ee549c2014-09-22 20:14:39 -07006115 return mKeyguardDrawnOnce;
Jorim Jaggicff0acb2014-03-31 16:35:15 +02006116 }
6117 }
6118
Jorim Jaggi0d674622014-05-21 01:34:15 +02006119 @Override
Jorim Jaggie29b2db2014-05-30 23:17:03 +02006120 public void startKeyguardExitAnimation(long startTime, long fadeoutDuration) {
Jorim Jaggi0d674622014-05-21 01:34:15 +02006121 if (mKeyguardDelegate != null) {
Craig Mautnerc0d2d0a2014-10-31 16:25:15 -07006122 if (DEBUG_KEYGUARD) Slog.d(TAG, "PWM.startKeyguardExitAnimation");
Jorim Jaggie29b2db2014-05-30 23:17:03 +02006123 mKeyguardDelegate.startKeyguardExitAnimation(startTime, fadeoutDuration);
Jorim Jaggi0d674622014-05-21 01:34:15 +02006124 }
6125 }
6126
Jorim Jaggi737af722015-12-31 10:42:27 +01006127 @Override
6128 public void getStableInsetsLw(int displayRotation, int displayWidth, int displayHeight,
6129 Rect outInsets) {
6130 outInsets.setEmpty();
Jorim Jaggi82c9dc92016-02-05 15:10:33 -08006131
6132 // Navigation bar and status bar.
6133 getNonDecorInsetsLw(displayRotation, displayWidth, displayHeight, outInsets);
Jorim Jaggi737af722015-12-31 10:42:27 +01006134 if (mStatusBar != null) {
6135 outInsets.top = mStatusBarHeight;
6136 }
Jorim Jaggi82c9dc92016-02-05 15:10:33 -08006137 }
6138
6139 @Override
6140 public void getNonDecorInsetsLw(int displayRotation, int displayWidth, int displayHeight,
6141 Rect outInsets) {
6142 outInsets.setEmpty();
6143
6144 // Only navigation bar
Jorim Jaggi737af722015-12-31 10:42:27 +01006145 if (mNavigationBar != null) {
6146 if (isNavigationBarOnBottom(displayWidth, displayHeight)) {
6147 outInsets.bottom = getNavigationBarHeight(displayRotation, mUiMode);
6148 } else {
6149 outInsets.right = getNavigationBarWidth(displayRotation, mUiMode);
6150 }
6151 }
6152 }
6153
Jorim Jaggi5060bd82016-02-19 17:12:19 -08006154 @Override
Jorim Jaggi0ffd49c2016-02-12 15:04:21 -08006155 public boolean isNavBarForcedShownLw(WindowState windowState) {
6156 return mForceShowSystemBars
6157 && !windowState.getFrameLw().equals(windowState.getDisplayFrameLw());
6158 }
6159
6160 @Override
Jorim Jaggi5060bd82016-02-19 17:12:19 -08006161 public boolean isDockSideAllowed(int dockSide) {
6162
6163 // We do not allow all dock sides at which the navigation bar touches the docked stack.
6164 if (!mNavigationBarCanMove) {
6165 return dockSide == DOCKED_TOP || dockSide == DOCKED_LEFT || dockSide == DOCKED_RIGHT;
6166 } else {
6167 return dockSide == DOCKED_TOP || dockSide == DOCKED_LEFT;
6168 }
6169 }
6170
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006171 void sendCloseSystemWindows() {
Jorim Jaggib10e33f2015-02-04 21:57:40 +01006172 PhoneWindow.sendCloseSystemWindows(mContext, null);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006173 }
6174
6175 void sendCloseSystemWindows(String reason) {
Jorim Jaggib10e33f2015-02-04 21:57:40 +01006176 PhoneWindow.sendCloseSystemWindows(mContext, reason);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006177 }
Mitsuru Oshima831d0d92009-06-16 18:27:18 -07006178
Jeff Brown01a98dd2011-09-20 15:08:29 -07006179 @Override
6180 public int rotationForOrientationLw(int orientation, int lastRotation) {
Daniel Sandler2ed6ad62011-02-22 14:54:17 -05006181 if (false) {
6182 Slog.v(TAG, "rotationForOrientationLw(orient="
6183 + orientation + ", last=" + lastRotation
6184 + "); user=" + mUserRotation + " "
6185 + ((mUserRotationMode == WindowManagerPolicy.USER_ROTATION_LOCKED)
6186 ? "USER_ROTATION_LOCKED" : "")
6187 );
6188 }
6189
Craig Mautner46ac6fa2013-08-01 10:06:34 -07006190 if (mForceDefaultOrientation) {
6191 return Surface.ROTATION_0;
6192 }
6193
The Android Open Source Project0727d222009-03-11 12:11:58 -07006194 synchronized (mLock) {
Jeff Brownc0347aa2011-09-23 17:26:09 -07006195 int sensorRotation = mOrientationListener.getProposedRotation(); // may be -1
6196 if (sensorRotation < 0) {
Jeff Brown0f862b42012-09-27 21:11:01 -07006197 sensorRotation = lastRotation;
Jeff Brownc0347aa2011-09-23 17:26:09 -07006198 }
Jeff Brown01a98dd2011-09-20 15:08:29 -07006199
Jeff Browndec6cf42011-11-15 14:08:20 -08006200 final int preferredRotation;
Jeff Brown2e7760e2012-04-11 15:14:55 -07006201 if (mLidState == LID_OPEN && mLidOpenRotation >= 0) {
Jeff Brown01a98dd2011-09-20 15:08:29 -07006202 // Ignore sensor when lid switch is open and rotation is forced.
6203 preferredRotation = mLidOpenRotation;
6204 } else if (mDockMode == Intent.EXTRA_DOCK_STATE_CAR
Jeff Brownc0347aa2011-09-23 17:26:09 -07006205 && (mCarDockEnablesAccelerometer || mCarDockRotation >= 0)) {
Jeff Brown01a98dd2011-09-20 15:08:29 -07006206 // Ignore sensor when in car dock unless explicitly enabled.
6207 // This case can override the behavior of NOSENSOR, and can also
6208 // enable 180 degree rotation while docked.
Jeff Brownc0347aa2011-09-23 17:26:09 -07006209 preferredRotation = mCarDockEnablesAccelerometer
Jeff Brown01a98dd2011-09-20 15:08:29 -07006210 ? sensorRotation : mCarDockRotation;
Jeff Brown1a693182011-11-08 14:44:16 -08006211 } else if ((mDockMode == Intent.EXTRA_DOCK_STATE_DESK
6212 || mDockMode == Intent.EXTRA_DOCK_STATE_LE_DESK
6213 || mDockMode == Intent.EXTRA_DOCK_STATE_HE_DESK)
Jeff Brownc0347aa2011-09-23 17:26:09 -07006214 && (mDeskDockEnablesAccelerometer || mDeskDockRotation >= 0)) {
Jeff Brown01a98dd2011-09-20 15:08:29 -07006215 // Ignore sensor when in desk dock unless explicitly enabled.
6216 // This case can override the behavior of NOSENSOR, and can also
6217 // enable 180 degree rotation while docked.
Jeff Brownc0347aa2011-09-23 17:26:09 -07006218 preferredRotation = mDeskDockEnablesAccelerometer
Jeff Brown01a98dd2011-09-20 15:08:29 -07006219 ? sensorRotation : mDeskDockRotation;
Jeff Brownc82c89ed2013-04-17 17:18:15 -07006220 } else if (mHdmiPlugged && mDemoHdmiRotationLock) {
6221 // Ignore sensor when plugged into HDMI when demo HDMI rotation lock enabled.
Jeff Browneb3e4b92011-12-06 19:54:24 -08006222 // Note that the dock orientation overrides the HDMI orientation.
Jeff Brownc82c89ed2013-04-17 17:18:15 -07006223 preferredRotation = mDemoHdmiRotation;
6224 } else if (mHdmiPlugged && mDockMode == Intent.EXTRA_DOCK_STATE_UNDOCKED
6225 && mUndockedHdmiRotation >= 0) {
6226 // Ignore sensor when plugged into HDMI and an undocked orientation has
6227 // been specified in the configuration (only for legacy devices without
6228 // full multi-display support).
6229 // Note that the dock orientation overrides the HDMI orientation.
6230 preferredRotation = mUndockedHdmiRotation;
Chong Zhangae6119ff2014-11-11 18:54:39 -08006231 } else if (mDemoRotationLock) {
6232 // Ignore sensor when demo rotation lock is enabled.
6233 // Note that the dock orientation and HDMI rotation lock override this.
6234 preferredRotation = mDemoRotation;
Dianne Hackbornb9ec1ac2013-04-10 17:34:25 -07006235 } else if (orientation == ActivityInfo.SCREEN_ORIENTATION_LOCKED) {
6236 // Application just wants to remain locked in the last rotation.
6237 preferredRotation = lastRotation;
Jeff Brownbcdfc622014-03-06 19:13:04 -08006238 } else if (!mSupportAutoRotation) {
6239 // If we don't support auto-rotation then bail out here and ignore
6240 // the sensor and any rotation lock settings.
6241 preferredRotation = -1;
Jeff Brown207673cd2012-06-05 17:47:11 -07006242 } else if ((mUserRotationMode == WindowManagerPolicy.USER_ROTATION_FREE
Jeff Brown01a98dd2011-09-20 15:08:29 -07006243 && (orientation == ActivityInfo.SCREEN_ORIENTATION_USER
Dianne Hackbornb9ec1ac2013-04-10 17:34:25 -07006244 || orientation == ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED
6245 || orientation == ActivityInfo.SCREEN_ORIENTATION_USER_LANDSCAPE
6246 || orientation == ActivityInfo.SCREEN_ORIENTATION_USER_PORTRAIT
6247 || orientation == ActivityInfo.SCREEN_ORIENTATION_FULL_USER))
Jeff Brown01a98dd2011-09-20 15:08:29 -07006248 || orientation == ActivityInfo.SCREEN_ORIENTATION_SENSOR
6249 || orientation == ActivityInfo.SCREEN_ORIENTATION_FULL_SENSOR
6250 || orientation == ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE
6251 || orientation == ActivityInfo.SCREEN_ORIENTATION_SENSOR_PORTRAIT) {
6252 // Otherwise, use sensor only if requested by the application or enabled
6253 // by default for USER or UNSPECIFIED modes. Does not apply to NOSENSOR.
Jeff Brownd3187e32011-09-21 19:26:44 -07006254 if (mAllowAllRotations < 0) {
6255 // Can't read this during init() because the context doesn't
6256 // have display metrics at that time so we cannot determine
6257 // tablet vs. phone then.
6258 mAllowAllRotations = mContext.getResources().getBoolean(
6259 com.android.internal.R.bool.config_allowAllRotations) ? 1 : 0;
6260 }
Jeff Brown01a98dd2011-09-20 15:08:29 -07006261 if (sensorRotation != Surface.ROTATION_180
Jeff Brownd3187e32011-09-21 19:26:44 -07006262 || mAllowAllRotations == 1
Dianne Hackbornb9ec1ac2013-04-10 17:34:25 -07006263 || orientation == ActivityInfo.SCREEN_ORIENTATION_FULL_SENSOR
6264 || orientation == ActivityInfo.SCREEN_ORIENTATION_FULL_USER) {
Jeff Brown01a98dd2011-09-20 15:08:29 -07006265 preferredRotation = sensorRotation;
6266 } else {
6267 preferredRotation = lastRotation;
6268 }
Jeff Brown207673cd2012-06-05 17:47:11 -07006269 } else if (mUserRotationMode == WindowManagerPolicy.USER_ROTATION_LOCKED
6270 && orientation != ActivityInfo.SCREEN_ORIENTATION_NOSENSOR) {
6271 // Apply rotation lock. Does not apply to NOSENSOR.
6272 // The idea is that the user rotation expresses a weak preference for the direction
6273 // of gravity and as NOSENSOR is never affected by gravity, then neither should
6274 // NOSENSOR be affected by rotation lock (although it will be affected by docks).
Jeff Brown4dfce202011-10-05 12:00:10 -07006275 preferredRotation = mUserRotation;
Jeff Browndec6cf42011-11-15 14:08:20 -08006276 } else {
6277 // No overriding preference.
6278 // We will do exactly what the application asked us to do.
6279 preferredRotation = -1;
Jeff Brown01a98dd2011-09-20 15:08:29 -07006280 }
6281
Dianne Hackborne5439f22010-10-02 16:53:50 -07006282 switch (orientation) {
6283 case ActivityInfo.SCREEN_ORIENTATION_PORTRAIT:
Jeff Browndec6cf42011-11-15 14:08:20 -08006284 // Return portrait unless overridden.
6285 if (isAnyPortrait(preferredRotation)) {
6286 return preferredRotation;
6287 }
Dianne Hackborne5439f22010-10-02 16:53:50 -07006288 return mPortraitRotation;
Dianne Hackborne5439f22010-10-02 16:53:50 -07006289
Jeff Brown01a98dd2011-09-20 15:08:29 -07006290 case ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE:
Jeff Browndec6cf42011-11-15 14:08:20 -08006291 // Return landscape unless overridden.
6292 if (isLandscapeOrSeascape(preferredRotation)) {
6293 return preferredRotation;
6294 }
Jeff Brown01a98dd2011-09-20 15:08:29 -07006295 return mLandscapeRotation;
6296
6297 case ActivityInfo.SCREEN_ORIENTATION_REVERSE_PORTRAIT:
Jeff Browndec6cf42011-11-15 14:08:20 -08006298 // Return reverse portrait unless overridden.
6299 if (isAnyPortrait(preferredRotation)) {
6300 return preferredRotation;
6301 }
Jeff Brown01a98dd2011-09-20 15:08:29 -07006302 return mUpsideDownRotation;
6303
6304 case ActivityInfo.SCREEN_ORIENTATION_REVERSE_LANDSCAPE:
Jeff Browndec6cf42011-11-15 14:08:20 -08006305 // Return seascape unless overridden.
6306 if (isLandscapeOrSeascape(preferredRotation)) {
6307 return preferredRotation;
6308 }
Jeff Brown01a98dd2011-09-20 15:08:29 -07006309 return mSeascapeRotation;
6310
6311 case ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE:
Dianne Hackbornb9ec1ac2013-04-10 17:34:25 -07006312 case ActivityInfo.SCREEN_ORIENTATION_USER_LANDSCAPE:
Jeff Brown01a98dd2011-09-20 15:08:29 -07006313 // Return either landscape rotation.
6314 if (isLandscapeOrSeascape(preferredRotation)) {
6315 return preferredRotation;
6316 }
6317 if (isLandscapeOrSeascape(lastRotation)) {
Jeff Brown4519f072011-01-23 13:16:01 -08006318 return lastRotation;
6319 }
Jeff Brown01a98dd2011-09-20 15:08:29 -07006320 return mLandscapeRotation;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006321
Jeff Brown01a98dd2011-09-20 15:08:29 -07006322 case ActivityInfo.SCREEN_ORIENTATION_SENSOR_PORTRAIT:
Dianne Hackbornb9ec1ac2013-04-10 17:34:25 -07006323 case ActivityInfo.SCREEN_ORIENTATION_USER_PORTRAIT:
Jeff Brown01a98dd2011-09-20 15:08:29 -07006324 // Return either portrait rotation.
6325 if (isAnyPortrait(preferredRotation)) {
6326 return preferredRotation;
6327 }
6328 if (isAnyPortrait(lastRotation)) {
6329 return lastRotation;
6330 }
6331 return mPortraitRotation;
6332
6333 default:
Jeff Brown4dfce202011-10-05 12:00:10 -07006334 // For USER, UNSPECIFIED, NOSENSOR, SENSOR and FULL_SENSOR,
6335 // just return the preferred orientation we already calculated.
Jeff Brown01a98dd2011-09-20 15:08:29 -07006336 if (preferredRotation >= 0) {
6337 return preferredRotation;
6338 }
Dianne Hackborndacea8c2011-04-21 17:26:39 -07006339 return Surface.ROTATION_0;
Daniel Sandlere7e5ac22011-02-22 16:10:21 -05006340 }
6341 }
Steve Howarda7bfe6a2010-09-23 16:47:49 -07006342 }
6343
Jeff Brown01a98dd2011-09-20 15:08:29 -07006344 @Override
6345 public boolean rotationHasCompatibleMetricsLw(int orientation, int rotation) {
6346 switch (orientation) {
6347 case ActivityInfo.SCREEN_ORIENTATION_PORTRAIT:
6348 case ActivityInfo.SCREEN_ORIENTATION_REVERSE_PORTRAIT:
6349 case ActivityInfo.SCREEN_ORIENTATION_SENSOR_PORTRAIT:
6350 return isAnyPortrait(rotation);
6351
6352 case ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE:
6353 case ActivityInfo.SCREEN_ORIENTATION_REVERSE_LANDSCAPE:
6354 case ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE:
6355 return isLandscapeOrSeascape(rotation);
6356
6357 default:
6358 return true;
6359 }
Steve Howarda7bfe6a2010-09-23 16:47:49 -07006360 }
6361
Jeff Brownc0347aa2011-09-23 17:26:09 -07006362 @Override
6363 public void setRotationLw(int rotation) {
6364 mOrientationListener.setCurrentRotation(rotation);
6365 }
6366
Jeff Brown01a98dd2011-09-20 15:08:29 -07006367 private boolean isLandscapeOrSeascape(int rotation) {
6368 return rotation == mLandscapeRotation || rotation == mSeascapeRotation;
Dianne Hackborne5439f22010-10-02 16:53:50 -07006369 }
6370
Jeff Brown01a98dd2011-09-20 15:08:29 -07006371 private boolean isAnyPortrait(int rotation) {
6372 return rotation == mPortraitRotation || rotation == mUpsideDownRotation;
Dianne Hackborne5439f22010-10-02 16:53:50 -07006373 }
6374
Jose Lima9546b202014-07-02 17:21:51 -07006375 @Override
Svetoslav Ganov80943d82013-01-02 10:25:37 -08006376 public int getUserRotationMode() {
6377 return Settings.System.getIntForUser(mContext.getContentResolver(),
Brett Chabot7e55c402013-05-16 19:38:08 -07006378 Settings.System.ACCELEROMETER_ROTATION, 0, UserHandle.USER_CURRENT) != 0 ?
6379 WindowManagerPolicy.USER_ROTATION_FREE :
6380 WindowManagerPolicy.USER_ROTATION_LOCKED;
Svetoslav Ganov80943d82013-01-02 10:25:37 -08006381 }
Daniel Sandlerb73617d2010-08-17 00:41:00 -04006382
6383 // User rotation: to be used when all else fails in assigning an orientation to the device
Jose Lima9546b202014-07-02 17:21:51 -07006384 @Override
Daniel Sandlerb73617d2010-08-17 00:41:00 -04006385 public void setUserRotationMode(int mode, int rot) {
6386 ContentResolver res = mContext.getContentResolver();
Daniel Sandler2ed6ad62011-02-22 14:54:17 -05006387
6388 // mUserRotationMode and mUserRotation will be assigned by the content observer
Daniel Sandlerb73617d2010-08-17 00:41:00 -04006389 if (mode == WindowManagerPolicy.USER_ROTATION_LOCKED) {
Christopher Tate5e08af02012-09-21 17:17:22 -07006390 Settings.System.putIntForUser(res,
Daniel Sandlerb73617d2010-08-17 00:41:00 -04006391 Settings.System.USER_ROTATION,
Christopher Tate5e08af02012-09-21 17:17:22 -07006392 rot,
6393 UserHandle.USER_CURRENT);
6394 Settings.System.putIntForUser(res,
Daniel Sandler2ed6ad62011-02-22 14:54:17 -05006395 Settings.System.ACCELEROMETER_ROTATION,
Christopher Tate5e08af02012-09-21 17:17:22 -07006396 0,
6397 UserHandle.USER_CURRENT);
Daniel Sandlerb73617d2010-08-17 00:41:00 -04006398 } else {
Christopher Tate5e08af02012-09-21 17:17:22 -07006399 Settings.System.putIntForUser(res,
Daniel Sandlerb73617d2010-08-17 00:41:00 -04006400 Settings.System.ACCELEROMETER_ROTATION,
Christopher Tate5e08af02012-09-21 17:17:22 -07006401 1,
6402 UserHandle.USER_CURRENT);
Daniel Sandlerb73617d2010-08-17 00:41:00 -04006403 }
6404 }
6405
Jose Lima9546b202014-07-02 17:21:51 -07006406 @Override
Jeff Brownac143512012-04-05 18:57:33 -07006407 public void setSafeMode(boolean safeMode) {
6408 mSafeMode = safeMode;
6409 performHapticFeedbackLw(null, safeMode
6410 ? HapticFeedbackConstants.SAFE_MODE_ENABLED
6411 : HapticFeedbackConstants.SAFE_MODE_DISABLED, true);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006412 }
Craig Mautnereda67292013-04-28 13:50:14 -07006413
Dianne Hackborn181ceb52009-08-27 22:16:40 -07006414 static long[] getLongIntArray(Resources r, int resid) {
6415 int[] ar = r.getIntArray(resid);
6416 if (ar == null) {
6417 return null;
6418 }
6419 long[] out = new long[ar.length];
6420 for (int i=0; i<ar.length; i++) {
6421 out[i] = ar[i];
6422 }
6423 return out;
6424 }
Craig Mautnereda67292013-04-28 13:50:14 -07006425
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006426 /** {@inheritDoc} */
Craig Mautnereda67292013-04-28 13:50:14 -07006427 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006428 public void systemReady() {
Jim Millerab954542014-10-10 18:21:49 -07006429 mKeyguardDelegate = new KeyguardServiceDelegate(mContext);
Mike Lockwooded8902d2013-11-15 11:01:47 -08006430 mKeyguardDelegate.onSystemReady();
6431
Michael Wright3818c922014-09-02 13:59:07 -07006432 readCameraLensCoverState();
Jeff Brown4f5fa282014-06-12 19:19:15 -07006433 updateUiMode();
Adrian Roos3542f7d2015-07-13 15:57:53 -07006434 boolean bindKeyguardNow;
Dianne Hackbornb1a79802009-09-29 15:18:31 -07006435 synchronized (mLock) {
6436 updateOrientationListenerLp();
Dianne Hackbornc777e072010-02-12 13:07:59 -08006437 mSystemReady = true;
6438 mHandler.post(new Runnable() {
Craig Mautnereda67292013-04-28 13:50:14 -07006439 @Override
Dianne Hackbornc777e072010-02-12 13:07:59 -08006440 public void run() {
6441 updateSettings();
6442 }
6443 });
Adrian Roos3542f7d2015-07-13 15:57:53 -07006444
6445 bindKeyguardNow = mDeferBindKeyguard;
6446 if (bindKeyguardNow) {
6447 // systemBooted ran but wasn't able to bind to the Keyguard, we'll do it now.
6448 mDeferBindKeyguard = false;
6449 }
6450 }
6451
6452 if (bindKeyguardNow) {
6453 mKeyguardDelegate.bindService(mContext);
6454 mKeyguardDelegate.onBootCompleted();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006455 }
Michael Wrighta4d22d72015-09-16 23:19:26 +01006456 mSystemGestures.systemReady();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006457 }
Dianne Hackborn661cd522011-08-22 00:26:20 -07006458
Dianne Hackbornba24e4d2011-09-01 11:17:06 -07006459 /** {@inheritDoc} */
Jose Lima9546b202014-07-02 17:21:51 -07006460 @Override
Dianne Hackbornba24e4d2011-09-01 11:17:06 -07006461 public void systemBooted() {
Adrian Roos3542f7d2015-07-13 15:57:53 -07006462 boolean bindKeyguardNow = false;
6463 synchronized (mLock) {
6464 // Time to bind Keyguard; take care to only bind it once, either here if ready or
6465 // in systemReady if not.
6466 if (mKeyguardDelegate != null) {
6467 bindKeyguardNow = true;
6468 } else {
6469 // Because mKeyguardDelegate is null, we know that the synchronized block in
6470 // systemReady didn't run yet and setting this will actually have an effect.
6471 mDeferBindKeyguard = true;
6472 }
6473 }
6474 if (bindKeyguardNow) {
Jason Monk5eeebf52014-09-26 12:36:51 -04006475 mKeyguardDelegate.bindService(mContext);
Jim Millere5f910a2013-10-16 18:15:46 -07006476 mKeyguardDelegate.onBootCompleted();
6477 }
Dianne Hackbornba24e4d2011-09-01 11:17:06 -07006478 synchronized (mLock) {
6479 mSystemBooted = true;
6480 }
Jeff Brown416c49c2015-05-26 19:50:18 -07006481 startedWakingUp();
Jeff Brown36c4db82014-09-19 12:05:31 -07006482 screenTurningOn(null);
Jorim Jaggic0496072015-08-19 15:14:52 -07006483 screenTurnedOn();
Dianne Hackbornba24e4d2011-09-01 11:17:06 -07006484 }
6485
Dianne Hackborn661cd522011-08-22 00:26:20 -07006486 ProgressDialog mBootMsgDialog = null;
6487
6488 /** {@inheritDoc} */
Jose Lima9546b202014-07-02 17:21:51 -07006489 @Override
Dianne Hackborn661cd522011-08-22 00:26:20 -07006490 public void showBootMessage(final CharSequence msg, final boolean always) {
6491 mHandler.post(new Runnable() {
6492 @Override public void run() {
6493 if (mBootMsgDialog == null) {
Craig Stout4c0cb8a2014-04-04 13:03:10 -07006494 int theme;
Jaewan Kim49117872016-01-19 17:24:08 +09006495 if (mContext.getPackageManager().hasSystemFeature(FEATURE_WATCH)) {
Craig Stout4c0cb8a2014-04-04 13:03:10 -07006496 theme = com.android.internal.R.style.Theme_Micro_Dialog_Alert;
Jaewan Kim49117872016-01-19 17:24:08 +09006497 } else if (mContext.getPackageManager().hasSystemFeature(FEATURE_TELEVISION)) {
Craig Stout4c0cb8a2014-04-04 13:03:10 -07006498 theme = com.android.internal.R.style.Theme_Leanback_Dialog_Alert;
6499 } else {
6500 theme = 0;
6501 }
Vinod Krishnanfa8fc412014-04-18 14:35:53 -07006502
6503 mBootMsgDialog = new ProgressDialog(mContext, theme) {
Dianne Hackborn295e3c22011-08-25 13:19:08 -07006504 // This dialog will consume all events coming in to
6505 // it, to avoid it trying to do things too early in boot.
6506 @Override public boolean dispatchKeyEvent(KeyEvent event) {
6507 return true;
6508 }
6509 @Override public boolean dispatchKeyShortcutEvent(KeyEvent event) {
6510 return true;
6511 }
6512 @Override public boolean dispatchTouchEvent(MotionEvent ev) {
6513 return true;
6514 }
6515 @Override public boolean dispatchTrackballEvent(MotionEvent ev) {
6516 return true;
6517 }
6518 @Override public boolean dispatchGenericMotionEvent(MotionEvent ev) {
6519 return true;
6520 }
6521 @Override public boolean dispatchPopulateAccessibilityEvent(
6522 AccessibilityEvent event) {
6523 return true;
6524 }
6525 };
Jeff Hao9f60c082014-10-28 18:51:07 -07006526 if (mContext.getPackageManager().isUpgrade()) {
6527 mBootMsgDialog.setTitle(R.string.android_upgrading_title);
6528 } else {
6529 mBootMsgDialog.setTitle(R.string.android_start_title);
6530 }
Dianne Hackborn661cd522011-08-22 00:26:20 -07006531 mBootMsgDialog.setProgressStyle(ProgressDialog.STYLE_SPINNER);
6532 mBootMsgDialog.setIndeterminate(true);
6533 mBootMsgDialog.getWindow().setType(
Dianne Hackborn29aae6f2011-08-18 18:30:09 -07006534 WindowManager.LayoutParams.TYPE_BOOT_PROGRESS);
Dianne Hackborn661cd522011-08-22 00:26:20 -07006535 mBootMsgDialog.getWindow().addFlags(
6536 WindowManager.LayoutParams.FLAG_DIM_BEHIND
6537 | WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN);
6538 mBootMsgDialog.getWindow().setDimAmount(1);
Dianne Hackbornd9efb952011-12-07 14:56:51 -08006539 WindowManager.LayoutParams lp = mBootMsgDialog.getWindow().getAttributes();
6540 lp.screenOrientation = ActivityInfo.SCREEN_ORIENTATION_NOSENSOR;
6541 mBootMsgDialog.getWindow().setAttributes(lp);
Dianne Hackborn661cd522011-08-22 00:26:20 -07006542 mBootMsgDialog.setCancelable(false);
6543 mBootMsgDialog.show();
6544 }
6545 mBootMsgDialog.setMessage(msg);
6546 }
6547 });
6548 }
6549
6550 /** {@inheritDoc} */
Jose Lima9546b202014-07-02 17:21:51 -07006551 @Override
Dianne Hackborn661cd522011-08-22 00:26:20 -07006552 public void hideBootMessages() {
Craig Mautnera631d492014-08-05 15:16:01 -07006553 mHandler.sendEmptyMessage(MSG_HIDE_BOOT_MESSAGE);
Dianne Hackborn661cd522011-08-22 00:26:20 -07006554 }
6555
Mike Lockwood28569302010-01-28 11:54:40 -05006556 /** {@inheritDoc} */
Jose Lima9546b202014-07-02 17:21:51 -07006557 @Override
Mike Lockwood28569302010-01-28 11:54:40 -05006558 public void userActivity() {
Dianne Hackborndf89e652011-10-06 22:35:11 -07006559 // ***************************************
6560 // NOTE NOTE NOTE NOTE NOTE NOTE NOTE NOTE
6561 // ***************************************
6562 // THIS IS CALLED FROM DEEP IN THE POWER MANAGER
6563 // WITH ITS LOCKS HELD.
6564 //
6565 // This code must be VERY careful about the locks
6566 // it acquires.
6567 // In fact, the current code acquires way too many,
6568 // and probably has lurking deadlocks.
6569
Mike Lockwood28569302010-01-28 11:54:40 -05006570 synchronized (mScreenLockTimeout) {
6571 if (mLockScreenTimerActive) {
6572 // reset the timer
6573 mHandler.removeCallbacks(mScreenLockTimeout);
6574 mHandler.postDelayed(mScreenLockTimeout, mLockScreenTimeout);
6575 }
6576 }
Daniel Sandler0601eb72011-04-13 01:01:32 -04006577 }
6578
Adam Cohenf7522022012-10-03 20:03:18 -07006579 class ScreenLockTimeout implements Runnable {
6580 Bundle options;
6581
6582 @Override
Mike Lockwood28569302010-01-28 11:54:40 -05006583 public void run() {
6584 synchronized (this) {
6585 if (localLOGV) Log.v(TAG, "mScreenLockTimeout activating keyguard");
Jim Miller5ecd8112013-01-09 18:50:26 -08006586 if (mKeyguardDelegate != null) {
6587 mKeyguardDelegate.doKeyguardTimeout(options);
Mike Lockwood3a74bd32011-08-12 13:55:22 -07006588 }
Mike Lockwood28569302010-01-28 11:54:40 -05006589 mLockScreenTimerActive = false;
Adam Cohenf7522022012-10-03 20:03:18 -07006590 options = null;
Mike Lockwood28569302010-01-28 11:54:40 -05006591 }
6592 }
Mike Lockwood28569302010-01-28 11:54:40 -05006593
Adam Cohenf7522022012-10-03 20:03:18 -07006594 public void setLockOptions(Bundle options) {
6595 this.options = options;
6596 }
6597 }
6598
6599 ScreenLockTimeout mScreenLockTimeout = new ScreenLockTimeout();
6600
Jose Lima9546b202014-07-02 17:21:51 -07006601 @Override
Adam Cohenf7522022012-10-03 20:03:18 -07006602 public void lockNow(Bundle options) {
Jim Miller93c518e2012-01-17 15:55:31 -08006603 mContext.enforceCallingOrSelfPermission(android.Manifest.permission.DEVICE_POWER, null);
6604 mHandler.removeCallbacks(mScreenLockTimeout);
Adam Cohenf7522022012-10-03 20:03:18 -07006605 if (options != null) {
6606 // In case multiple calls are made to lockNow, we don't wipe out the options
6607 // until the runnable actually executes.
6608 mScreenLockTimeout.setLockOptions(options);
6609 }
Jim Miller93c518e2012-01-17 15:55:31 -08006610 mHandler.post(mScreenLockTimeout);
6611 }
6612
Mike Lockwood28569302010-01-28 11:54:40 -05006613 private void updateLockScreenTimeout() {
6614 synchronized (mScreenLockTimeout) {
Jeff Brown3ee549c2014-09-22 20:14:39 -07006615 boolean enable = (mAllowLockscreenWhenOn && mAwake &&
Jim Miller5ecd8112013-01-09 18:50:26 -08006616 mKeyguardDelegate != null && mKeyguardDelegate.isSecure());
Mike Lockwood28569302010-01-28 11:54:40 -05006617 if (mLockScreenTimerActive != enable) {
6618 if (enable) {
6619 if (localLOGV) Log.v(TAG, "setting lockscreen timer");
Jim Miller2967f482016-01-07 15:05:32 -08006620 mHandler.removeCallbacks(mScreenLockTimeout); // remove any pending requests
Mike Lockwood28569302010-01-28 11:54:40 -05006621 mHandler.postDelayed(mScreenLockTimeout, mLockScreenTimeout);
6622 } else {
6623 if (localLOGV) Log.v(TAG, "clearing lockscreen timer");
6624 mHandler.removeCallbacks(mScreenLockTimeout);
6625 }
6626 mLockScreenTimerActive = enable;
6627 }
6628 }
6629 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006630
Jeff Brown061ea992015-04-17 19:55:47 -07006631 private void updateDreamingSleepToken(boolean acquire) {
6632 if (acquire) {
6633 if (mDreamingSleepToken == null) {
6634 mDreamingSleepToken = mActivityManagerInternal.acquireSleepToken("Dream");
6635 }
6636 } else {
6637 if (mDreamingSleepToken != null) {
6638 mDreamingSleepToken.release();
Jeff Brown48d1b142015-06-10 16:36:03 -07006639 mDreamingSleepToken = null;
6640 }
6641 }
6642 }
6643
6644 private void updateScreenOffSleepToken(boolean acquire) {
6645 if (acquire) {
6646 if (mScreenOffSleepToken == null) {
6647 mScreenOffSleepToken = mActivityManagerInternal.acquireSleepToken("ScreenOff");
6648 }
6649 } else {
6650 if (mScreenOffSleepToken != null) {
6651 mScreenOffSleepToken.release();
6652 mScreenOffSleepToken = null;
Jeff Brown061ea992015-04-17 19:55:47 -07006653 }
6654 }
6655 }
6656
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006657 /** {@inheritDoc} */
Craig Mautnereda67292013-04-28 13:50:14 -07006658 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006659 public void enableScreenAfterBoot() {
6660 readLidState();
Jeff Brownc458ce92012-04-30 14:58:40 -07006661 applyLidSwitchState();
Jeff Brown01a98dd2011-09-20 15:08:29 -07006662 updateRotation(true);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006663 }
Dianne Hackbornf54c8f92009-09-19 14:03:57 -07006664
Jeff Brownc458ce92012-04-30 14:58:40 -07006665 private void applyLidSwitchState() {
Jeff Brownc458ce92012-04-30 14:58:40 -07006666 if (mLidState == LID_CLOSED && mLidControlsSleep) {
Jeff Brown6d8fd272014-05-20 21:24:38 -07006667 mPowerManager.goToSleep(SystemClock.uptimeMillis(),
Jeff Brownc12035c2014-08-13 18:52:25 -07006668 PowerManager.GO_TO_SLEEP_REASON_LID_SWITCH,
Jeff Brown6d8fd272014-05-20 21:24:38 -07006669 PowerManager.GO_TO_SLEEP_FLAG_NO_DOZE);
Edward Savage-Jones7def60d2015-11-13 13:27:03 +01006670 } else if (mLidState == LID_CLOSED && mLidControlsScreenLock) {
6671 mWindowManagerFuncs.lockDeviceNow();
Jeff Brownc458ce92012-04-30 14:58:40 -07006672 }
Jeff Browna20dda42014-05-27 20:57:24 -07006673
6674 synchronized (mLock) {
6675 updateWakeGestureListenerLp();
6676 }
Jeff Brown01a98dd2011-09-20 15:08:29 -07006677 }
6678
Jeff Brown4f5fa282014-06-12 19:19:15 -07006679 void updateUiMode() {
6680 if (mUiModeManager == null) {
6681 mUiModeManager = IUiModeManager.Stub.asInterface(
6682 ServiceManager.getService(Context.UI_MODE_SERVICE));
6683 }
6684 try {
6685 mUiMode = mUiModeManager.getCurrentModeType();
6686 } catch (RemoteException e) {
6687 }
6688 }
6689
Jeff Brown01a98dd2011-09-20 15:08:29 -07006690 void updateRotation(boolean alwaysSendConfiguration) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006691 try {
6692 //set orientation on WindowManager
Dianne Hackbornf87d1962012-04-04 12:48:24 -07006693 mWindowManager.updateRotation(alwaysSendConfiguration, false);
6694 } catch (RemoteException e) {
6695 // Ignore
6696 }
6697 }
6698
6699 void updateRotation(boolean alwaysSendConfiguration, boolean forceRelayout) {
6700 try {
6701 //set orientation on WindowManager
6702 mWindowManager.updateRotation(alwaysSendConfiguration, forceRelayout);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006703 } catch (RemoteException e) {
6704 // Ignore
6705 }
6706 }
6707
Daniel Sandler6396c722013-04-16 20:19:09 -04006708 /**
6709 * Return an Intent to launch the currently active dock app as home. Returns
6710 * null if the standard home should be launched, which is the case if any of the following is
6711 * true:
6712 * <ul>
6713 * <li>The device is not in either car mode or desk mode
keunyounga7710492015-09-23 11:33:58 -07006714 * <li>The device is in car mode but mEnableCarDockHomeCapture is false
Daniel Sandler6396c722013-04-16 20:19:09 -04006715 * <li>The device is in desk mode but ENABLE_DESK_DOCK_HOME_CAPTURE is false
6716 * <li>The device is in car mode but there's no CAR_DOCK app with METADATA_DOCK_HOME
6717 * <li>The device is in desk mode but there's no DESK_DOCK app with METADATA_DOCK_HOME
6718 * </ul>
Craig Mautnereda67292013-04-28 13:50:14 -07006719 * @return A dock intent.
Daniel Sandler6396c722013-04-16 20:19:09 -04006720 */
6721 Intent createHomeDockIntent() {
6722 Intent intent = null;
6723
6724 // What home does is based on the mode, not the dock state. That
6725 // is, when in car mode you should be taken to car home regardless
6726 // of whether we are actually in a car dock.
6727 if (mUiMode == Configuration.UI_MODE_TYPE_CAR) {
keunyounga7710492015-09-23 11:33:58 -07006728 if (mEnableCarDockHomeCapture) {
Daniel Sandler6396c722013-04-16 20:19:09 -04006729 intent = mCarDockIntent;
6730 }
6731 } else if (mUiMode == Configuration.UI_MODE_TYPE_DESK) {
6732 if (ENABLE_DESK_DOCK_HOME_CAPTURE) {
6733 intent = mDeskDockIntent;
6734 }
Jeff Brown4f5fa282014-06-12 19:19:15 -07006735 } else if (mUiMode == Configuration.UI_MODE_TYPE_WATCH
6736 && (mDockMode == Intent.EXTRA_DOCK_STATE_DESK
6737 || mDockMode == Intent.EXTRA_DOCK_STATE_HE_DESK
6738 || mDockMode == Intent.EXTRA_DOCK_STATE_LE_DESK)) {
6739 // Always launch dock home from home when watch is docked, if it exists.
6740 intent = mDeskDockIntent;
Daniel Sandler6396c722013-04-16 20:19:09 -04006741 }
6742
6743 if (intent == null) {
6744 return null;
6745 }
6746
6747 ActivityInfo ai = null;
6748 ResolveInfo info = mContext.getPackageManager().resolveActivityAsUser(
6749 intent,
John Spurlockf56bef12013-07-09 09:51:46 -04006750 PackageManager.MATCH_DEFAULT_ONLY | PackageManager.GET_META_DATA,
Craig Mautnerd625ab22013-09-06 13:40:31 -07006751 mCurrentUserId);
Daniel Sandler6396c722013-04-16 20:19:09 -04006752 if (info != null) {
6753 ai = info.activityInfo;
6754 }
6755 if (ai != null
6756 && ai.metaData != null
6757 && ai.metaData.getBoolean(Intent.METADATA_DOCK_HOME)) {
6758 intent = new Intent(intent);
6759 intent.setClassName(ai.packageName, ai.name);
6760 return intent;
6761 }
6762
6763 return null;
6764 }
6765
Filip Gruszczynskia483a1d2015-03-17 19:06:58 +00006766 void startDockOrHome(boolean fromHomeKey, boolean awakenFromDreams) {
6767 if (awakenFromDreams) {
6768 awakenDreams();
6769 }
Daniel Sandler6396c722013-04-16 20:19:09 -04006770
6771 Intent dock = createHomeDockIntent();
6772 if (dock != null) {
6773 try {
Bryce Lee01b0c5f2015-02-05 18:24:04 -08006774 if (fromHomeKey) {
6775 dock.putExtra(WindowManagerPolicy.EXTRA_FROM_HOME_KEY, fromHomeKey);
6776 }
Bart Sears8b1c27c2015-03-18 23:51:02 +00006777 startActivityAsUser(dock, UserHandle.CURRENT);
Daniel Sandler6396c722013-04-16 20:19:09 -04006778 return;
6779 } catch (ActivityNotFoundException e) {
6780 }
6781 }
6782
Bryce Lee01b0c5f2015-02-05 18:24:04 -08006783 Intent intent;
6784
6785 if (fromHomeKey) {
6786 intent = new Intent(mHomeIntent);
6787 intent.putExtra(WindowManagerPolicy.EXTRA_FROM_HOME_KEY, fromHomeKey);
6788 } else {
6789 intent = mHomeIntent;
6790 }
6791
Bryce Lee9fc0b6f2015-03-19 21:37:45 +00006792 startActivityAsUser(intent, UserHandle.CURRENT);
Dianne Hackborn39c2d712009-09-22 11:41:31 -07006793 }
Craig Mautnereda67292013-04-28 13:50:14 -07006794
Dianne Hackborn39c2d712009-09-22 11:41:31 -07006795 /**
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006796 * goes to the home screen
6797 * @return whether it did anything
6798 */
6799 boolean goHome() {
Bart Sears8b1c27c2015-03-18 23:51:02 +00006800 if (!isUserSetupComplete()) {
6801 Slog.i(TAG, "Not going home because user setup is in progress.");
6802 return false;
6803 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006804 if (false) {
6805 // This code always brings home to the front.
Dianne Hackborn256dd3b2009-05-19 18:51:21 -07006806 try {
6807 ActivityManagerNative.getDefault().stopAppSwitches();
6808 } catch (RemoteException e) {
6809 }
Dianne Hackborn94a679d2009-07-28 17:51:07 -07006810 sendCloseSystemWindows();
Filip Gruszczynskia483a1d2015-03-17 19:06:58 +00006811 startDockOrHome(false /*fromHomeKey*/, true /* awakenFromDreams */);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006812 } else {
6813 // This code brings home to the front or, if it is already
6814 // at the front, puts the device to sleep.
6815 try {
Wink Savilled2e6a332010-02-12 12:12:06 -08006816 if (SystemProperties.getInt("persist.sys.uts-test-mode", 0) == 1) {
6817 /// Roll back EndcallBehavior as the cupcake design to pass P1 lab entry.
6818 Log.d(TAG, "UTS-TEST-MODE");
6819 } else {
6820 ActivityManagerNative.getDefault().stopAppSwitches();
6821 sendCloseSystemWindows();
Daniel Sandler6396c722013-04-16 20:19:09 -04006822 Intent dock = createHomeDockIntent();
6823 if (dock != null) {
6824 int result = ActivityManagerNative.getDefault()
6825 .startActivityAsUser(null, null, dock,
6826 dock.resolveTypeIfNeeded(mContext.getContentResolver()),
6827 null, null, 0,
6828 ActivityManager.START_FLAG_ONLY_IF_NEEDED,
Jeff Hao1b012d32014-08-20 10:35:34 -07006829 null, null, UserHandle.USER_CURRENT);
Daniel Sandler6396c722013-04-16 20:19:09 -04006830 if (result == ActivityManager.START_RETURN_INTENT_TO_CALLER) {
6831 return false;
6832 }
6833 }
Dianne Hackborn39c2d712009-09-22 11:41:31 -07006834 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006835 int result = ActivityManagerNative.getDefault()
Dianne Hackbornf265ea92013-01-31 15:00:51 -08006836 .startActivityAsUser(null, null, mHomeIntent,
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006837 mHomeIntent.resolveTypeIfNeeded(mContext.getContentResolver()),
Dianne Hackborna4972e92012-03-14 10:38:05 -07006838 null, null, 0,
6839 ActivityManager.START_FLAG_ONLY_IF_NEEDED,
Jeff Hao1b012d32014-08-20 10:35:34 -07006840 null, null, UserHandle.USER_CURRENT);
Dianne Hackborna4972e92012-03-14 10:38:05 -07006841 if (result == ActivityManager.START_RETURN_INTENT_TO_CALLER) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006842 return false;
6843 }
6844 } catch (RemoteException ex) {
6845 // bummer, the activity manager, which is in this process, is dead
6846 }
6847 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006848 return true;
6849 }
Craig Mautnereda67292013-04-28 13:50:14 -07006850
6851 @Override
The Android Open Source Project0727d222009-03-11 12:11:58 -07006852 public void setCurrentOrientationLw(int newOrientation) {
6853 synchronized (mLock) {
6854 if (newOrientation != mCurrentAppOrientation) {
6855 mCurrentAppOrientation = newOrientation;
6856 updateOrientationListenerLp();
6857 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006858 }
6859 }
Amith Yamasanic33cb712010-02-10 15:21:49 -08006860
Svetoslav Ganov7befb7d2012-09-27 16:49:23 -07006861 private void performAuditoryFeedbackForAccessibilityIfNeed() {
6862 if (!isGlobalAccessibilityGestureEnabled()) {
6863 return;
6864 }
6865 AudioManager audioManager = (AudioManager) mContext.getSystemService(
6866 Context.AUDIO_SERVICE);
6867 if (audioManager.isSilentMode()) {
6868 return;
6869 }
6870 Ringtone ringTone = RingtoneManager.getRingtone(mContext,
6871 Settings.System.DEFAULT_NOTIFICATION_URI);
6872 ringTone.setStreamType(AudioManager.STREAM_MUSIC);
6873 ringTone.play();
6874 }
Craig Mautnereda67292013-04-28 13:50:14 -07006875
Bryce Lee584a4452014-10-21 15:55:55 -07006876 private boolean isTheaterModeEnabled() {
6877 return Settings.Global.getInt(mContext.getContentResolver(),
6878 Settings.Global.THEATER_MODE_ON, 0) == 1;
6879 }
6880
Svetoslav Ganov7befb7d2012-09-27 16:49:23 -07006881 private boolean isGlobalAccessibilityGestureEnabled() {
6882 return Settings.Global.getInt(mContext.getContentResolver(),
6883 Settings.Global.ENABLE_ACCESSIBILITY_GLOBAL_GESTURE_ENABLED, 0) == 1;
6884 }
6885
Craig Mautnereda67292013-04-28 13:50:14 -07006886 @Override
The Android Open Source Project0727d222009-03-11 12:11:58 -07006887 public boolean performHapticFeedbackLw(WindowState win, int effectId, boolean always) {
Svetoslav Ganov96179212012-10-10 14:17:45 -07006888 if (!mVibrator.hasVibrator()) {
6889 return false;
6890 }
Christopher Tate5e08af02012-09-21 17:17:22 -07006891 final boolean hapticsDisabled = Settings.System.getIntForUser(mContext.getContentResolver(),
6892 Settings.System.HAPTIC_FEEDBACK_ENABLED, 0, UserHandle.USER_CURRENT) == 0;
Jeff Brown82379ba2014-07-25 19:03:28 -07006893 if (hapticsDisabled && !always) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006894 return false;
6895 }
Amith Yamasanic33cb712010-02-10 15:21:49 -08006896 long[] pattern = null;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006897 switch (effectId) {
6898 case HapticFeedbackConstants.LONG_PRESS:
Amith Yamasanic33cb712010-02-10 15:21:49 -08006899 pattern = mLongPressVibePattern;
6900 break;
Dianne Hackbornb1a79802009-09-29 15:18:31 -07006901 case HapticFeedbackConstants.VIRTUAL_KEY:
Amith Yamasanic33cb712010-02-10 15:21:49 -08006902 pattern = mVirtualKeyVibePattern;
6903 break;
6904 case HapticFeedbackConstants.KEYBOARD_TAP:
6905 pattern = mKeyboardTapVibePattern;
6906 break;
Fabrice Di Meglioeeff63a2013-08-05 12:07:24 -07006907 case HapticFeedbackConstants.CLOCK_TICK:
6908 pattern = mClockTickVibePattern;
6909 break;
Fabrice Di Megliobd9152f2013-10-01 11:21:31 -07006910 case HapticFeedbackConstants.CALENDAR_DATE:
6911 pattern = mCalendarDateVibePattern;
6912 break;
Dianne Hackbornb1a79802009-09-29 15:18:31 -07006913 case HapticFeedbackConstants.SAFE_MODE_DISABLED:
Amith Yamasanic33cb712010-02-10 15:21:49 -08006914 pattern = mSafeModeDisabledVibePattern;
6915 break;
Dianne Hackbornb1a79802009-09-29 15:18:31 -07006916 case HapticFeedbackConstants.SAFE_MODE_ENABLED:
Amith Yamasanic33cb712010-02-10 15:21:49 -08006917 pattern = mSafeModeEnabledVibePattern;
6918 break;
Mady Mellore8608912015-06-05 09:02:55 -07006919 case HapticFeedbackConstants.CONTEXT_CLICK:
6920 pattern = mContextClickVibePattern;
Mady Mellore82067b2015-04-30 09:58:35 -07006921 break;
Amith Yamasanic33cb712010-02-10 15:21:49 -08006922 default:
6923 return false;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006924 }
Dianne Hackbornf265ea92013-01-31 15:00:51 -08006925 int owningUid;
6926 String owningPackage;
6927 if (win != null) {
6928 owningUid = win.getOwningUid();
6929 owningPackage = win.getOwningPackage();
6930 } else {
6931 owningUid = android.os.Process.myUid();
Dianne Hackborn95d78532013-09-11 09:51:14 -07006932 owningPackage = mContext.getOpPackageName();
Dianne Hackbornf265ea92013-01-31 15:00:51 -08006933 }
Amith Yamasanic33cb712010-02-10 15:21:49 -08006934 if (pattern.length == 1) {
6935 // One-shot vibration
John Spurlock7b414672014-07-18 13:02:39 -04006936 mVibrator.vibrate(owningUid, owningPackage, pattern[0], VIBRATION_ATTRIBUTES);
Amith Yamasanic33cb712010-02-10 15:21:49 -08006937 } else {
6938 // Pattern vibration
John Spurlock7b414672014-07-18 13:02:39 -04006939 mVibrator.vibrate(owningUid, owningPackage, pattern, -1, VIBRATION_ATTRIBUTES);
Amith Yamasanic33cb712010-02-10 15:21:49 -08006940 }
6941 return true;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006942 }
Jeff Brownc38c9be2012-10-04 13:16:19 -07006943
6944 @Override
6945 public void keepScreenOnStartedLw() {
Daniel Sandler0601eb72011-04-13 01:01:32 -04006946 }
6947
Jeff Brownc38c9be2012-10-04 13:16:19 -07006948 @Override
6949 public void keepScreenOnStoppedLw() {
Jim Millerab954542014-10-10 18:21:49 -07006950 if (isKeyguardShowingAndNotOccluded()) {
Jim Miller25190572013-02-28 17:36:24 -08006951 mPowerManager.userActivity(SystemClock.uptimeMillis(), false);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006952 }
6953 }
Mike Lockwoodfcb39242009-10-21 23:01:07 -04006954
Dianne Hackborndf89e652011-10-06 22:35:11 -07006955 private int updateSystemUiVisibilityLw() {
Joe Onorato664644d2011-01-23 17:53:23 -08006956 // If there is no window focused, there will be nobody to handle the events
6957 // anyway, so just hang on in whatever state we're in until things settle down.
Adrian Roos53f28ec2014-10-29 17:26:12 +01006958 final WindowState win = mFocusedWindow != null ? mFocusedWindow
6959 : mTopFullscreenOpaqueWindowState;
John Spurlock79da8332013-09-20 12:04:47 -04006960 if (win == null) {
Dianne Hackborndf89e652011-10-06 22:35:11 -07006961 return 0;
6962 }
Jorim Jaggi380ecb82014-03-14 17:25:20 +01006963 if ((win.getAttrs().privateFlags & PRIVATE_FLAG_KEYGUARD) != 0 && mHideLockScreen == true) {
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07006964 // We are updating at a point where the keyguard has gotten
6965 // focus, but we were last in a state where the top window is
6966 // hiding it. This is probably because the keyguard as been
6967 // shown while the top window was displayed, so we want to ignore
6968 // it here because this is just a very transient change and it
6969 // will quickly lose focus once it correctly gets hidden.
6970 return 0;
6971 }
John Spurlock32beb2c2013-03-11 10:16:47 -04006972
John Spurlock1db8b682014-02-18 11:18:59 -05006973 int tmpVisibility = PolicyControl.getSystemUiVisibility(win, null)
Dianne Hackborne26ab702011-10-16 13:21:33 -07006974 & ~mResettingSystemUiFlags
6975 & ~mForceClearedSystemUiFlags;
John Spurlock79da8332013-09-20 12:04:47 -04006976 if (mForcingShowNavBar && win.getSurfaceLayer() < mForcingShowNavBarLayer) {
John Spurlockc6d1c602014-01-17 15:22:06 -05006977 tmpVisibility &= ~PolicyControl.adjustClearableFlags(win, View.SYSTEM_UI_CLEARABLE_FLAGS);
Dianne Hackborn891d3fb2013-01-09 18:31:37 -08006978 }
Thanh Hai Mai6c009f52015-09-01 16:27:32 -07006979
6980 if (mUiMode == Configuration.UI_MODE_TYPE_CAR) {
6981 tmpVisibility |= StatusBarManager.DISABLE_RECENT;
6982 }
6983
Jorim Jaggi86905582016-02-09 21:36:09 -08006984 final int fullscreenVisibility = updateLightStatusBarLw(0 /* vis */,
6985 mTopFullscreenOpaqueWindowState, mTopFullscreenOpaqueOrDimmingWindowState);
6986 final int dockedVisibility = updateLightStatusBarLw(0 /* vis */,
6987 mTopDockedOpaqueWindowState, mTopDockedOpaqueOrDimmingWindowState);
6988 mWindowManagerFuncs.getStackBounds(HOME_STACK_ID, mNonDockedStackBounds);
6989 mWindowManagerFuncs.getStackBounds(DOCKED_STACK_ID, mDockedStackBounds);
John Spurlock79da8332013-09-20 12:04:47 -04006990 final int visibility = updateSystemBarsLw(win, mLastSystemUiFlags, tmpVisibility);
John Spurlockad3e6cb2013-04-30 08:47:43 -04006991 final int diff = visibility ^ mLastSystemUiFlags;
Jorim Jaggi86905582016-02-09 21:36:09 -08006992 final int fullscreenDiff = fullscreenVisibility ^ mLastFullscreenStackSysUiFlags;
6993 final int dockedDiff = dockedVisibility ^ mLastDockedStackSysUiFlags;
John Spurlock79da8332013-09-20 12:04:47 -04006994 final boolean needsMenu = win.getNeedsMenuLw(mTopFullscreenOpaqueWindowState);
Jorim Jaggi86905582016-02-09 21:36:09 -08006995 if (diff == 0 && fullscreenDiff == 0 && dockedDiff == 0 && mLastFocusNeedsMenu == needsMenu
6996 && mFocusedApp == win.getAppToken()
6997 && mLastNonDockedStackBounds.equals(mNonDockedStackBounds)
6998 && mLastDockedStackBounds.equals(mDockedStackBounds)) {
Dianne Hackborndf89e652011-10-06 22:35:11 -07006999 return 0;
7000 }
Dianne Hackborne26ab702011-10-16 13:21:33 -07007001 mLastSystemUiFlags = visibility;
Jorim Jaggi86905582016-02-09 21:36:09 -08007002 mLastFullscreenStackSysUiFlags = fullscreenVisibility;
7003 mLastDockedStackSysUiFlags = dockedVisibility;
Dianne Hackborn4eff8d32011-11-10 19:38:40 -08007004 mLastFocusNeedsMenu = needsMenu;
John Spurlock79da8332013-09-20 12:04:47 -04007005 mFocusedApp = win.getAppToken();
Jorim Jaggi86905582016-02-09 21:36:09 -08007006 final Rect fullscreenStackBounds = new Rect(mNonDockedStackBounds);
7007 final Rect dockedStackBounds = new Rect(mDockedStackBounds);
Dianne Hackborndf89e652011-10-06 22:35:11 -07007008 mHandler.post(new Runnable() {
Craig Mautnereda67292013-04-28 13:50:14 -07007009 @Override
Dianne Hackborndf89e652011-10-06 22:35:11 -07007010 public void run() {
Jorim Jaggi86905582016-02-09 21:36:09 -08007011 StatusBarManagerInternal statusbar = getStatusBarManagerInternal();
7012 if (statusbar != null) {
7013 statusbar.setSystemUiVisibility(visibility, fullscreenVisibility,
7014 dockedVisibility, 0xffffffff, fullscreenStackBounds,
7015 dockedStackBounds, win.toString());
7016 statusbar.topAppWindowChanged(needsMenu);
Joe Onorato664644d2011-01-23 17:53:23 -08007017 }
Dianne Hackborndf89e652011-10-06 22:35:11 -07007018 }
7019 });
7020 return diff;
Joe Onorato664644d2011-01-23 17:53:23 -08007021 }
7022
Jorim Jaggi86905582016-02-09 21:36:09 -08007023 private int updateLightStatusBarLw(int vis, WindowState opaque, WindowState opaqueOrDimming) {
Adrian Rooscd3884d2015-02-18 17:25:23 +01007024 WindowState statusColorWin = isStatusBarKeyguard() && !mHideLockScreen
7025 ? mStatusBar
Jorim Jaggi86905582016-02-09 21:36:09 -08007026 : opaqueOrDimming;
Adrian Rooscd3884d2015-02-18 17:25:23 +01007027
7028 if (statusColorWin != null) {
Jorim Jaggi86905582016-02-09 21:36:09 -08007029 if (statusColorWin == opaque) {
Adrian Rooscd3884d2015-02-18 17:25:23 +01007030 // If the top fullscreen-or-dimming window is also the top fullscreen, respect
7031 // its light flag.
7032 vis &= ~View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR;
7033 vis |= PolicyControl.getSystemUiVisibility(statusColorWin, null)
7034 & View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR;
7035 } else if (statusColorWin != null && statusColorWin.isDimming()) {
7036 // Otherwise if it's dimming, clear the light flag.
7037 vis &= ~View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR;
7038 }
7039 }
7040 return vis;
7041 }
7042
John Spurlock79da8332013-09-20 12:04:47 -04007043 private int updateSystemBarsLw(WindowState win, int oldVis, int vis) {
Wale Ogunwale6e94a9e2015-10-07 15:35:49 -07007044 final boolean dockedStackVisible = mWindowManagerInternal.isStackVisible(DOCKED_STACK_ID);
7045 final boolean freeformStackVisible =
7046 mWindowManagerInternal.isStackVisible(FREEFORM_WORKSPACE_STACK_ID);
Jorim Jaggi9511b0f2016-01-29 19:12:44 -08007047 final boolean resizing = mWindowManagerInternal.isDockedDividerResizing();
7048
7049 // We need to force system bars when the docked stack is visible, when the freeform stack
7050 // is visible but also when we are resizing for the transitions when docked stack
7051 // visibility changes.
Jorim Jaggi0ffd49c2016-02-12 15:04:21 -08007052 mForceShowSystemBars = dockedStackVisible || freeformStackVisible || resizing;
7053 final boolean forceOpaqueSystemBars = mForceShowSystemBars && !mForceStatusBarFromKeyguard;
Wale Ogunwale6e94a9e2015-10-07 15:35:49 -07007054
John Spurlockbd957402013-10-03 11:38:39 -04007055 // apply translucent bar vis flags
Jorim Jaggi380ecb82014-03-14 17:25:20 +01007056 WindowState transWin = isStatusBarKeyguard() && !mHideLockScreen
7057 ? mStatusBar
John Spurlockbd957402013-10-03 11:38:39 -04007058 : mTopFullscreenOpaqueWindowState;
7059 vis = mStatusBarController.applyTranslucentFlagLw(transWin, vis, oldVis);
7060 vis = mNavigationBarController.applyTranslucentFlagLw(transWin, vis, oldVis);
7061
John Spurlock27735a42013-08-14 17:57:38 -04007062 // prevent status bar interaction from clearing certain flags
Selim Cinekf83e8242015-05-19 18:08:14 -07007063 int type = win.getAttrs().type;
7064 boolean statusBarHasFocus = type == TYPE_STATUS_BAR;
John Spurlock08ffcf52014-07-11 10:13:46 -04007065 if (statusBarHasFocus && !isStatusBarKeyguard()) {
John Spurlockad3e6cb2013-04-30 08:47:43 -04007066 int flags = View.SYSTEM_UI_FLAG_FULLSCREEN
7067 | View.SYSTEM_UI_FLAG_HIDE_NAVIGATION
John Spurlockcfc359a2013-09-05 10:42:03 -04007068 | View.SYSTEM_UI_FLAG_IMMERSIVE
Jorim Jaggi73fef8d2015-02-16 17:32:28 +01007069 | View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY
7070 | View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR;
John Spurlock08ffcf52014-07-11 10:13:46 -04007071 if (mHideLockScreen) {
Jorim Jaggi5cf17872014-03-26 18:31:48 +01007072 flags |= View.STATUS_BAR_TRANSLUCENT | View.NAVIGATION_BAR_TRANSLUCENT;
7073 }
John Spurlockbd957402013-10-03 11:38:39 -04007074 vis = (vis & ~flags) | (oldVis & flags);
John Spurlockad3e6cb2013-04-30 08:47:43 -04007075 }
John Spurlockad3e6cb2013-04-30 08:47:43 -04007076
Wale Ogunwale6e94a9e2015-10-07 15:35:49 -07007077 if ((!areTranslucentBarsAllowed() && transWin != mStatusBar)
7078 || forceOpaqueSystemBars) {
Adrian Roosea562512014-05-05 13:33:03 +02007079 vis &= ~(View.NAVIGATION_BAR_TRANSLUCENT | View.STATUS_BAR_TRANSLUCENT
7080 | View.SYSTEM_UI_TRANSPARENT);
Alan Viverette5a0f4ec2013-10-07 15:10:29 -07007081 }
7082
Jorim Jaggi4fa78922015-11-30 17:13:56 -08007083 if (mForceWindowDrawsStatusBarBackground) {
7084 vis |= View.STATUS_BAR_TRANSPARENT;
7085 vis &= ~View.STATUS_BAR_TRANSLUCENT;
7086 }
7087
John Spurlock27735a42013-08-14 17:57:38 -04007088 // update status bar
John Spurlockf1a36642013-10-12 17:50:42 -04007089 boolean immersiveSticky =
7090 (vis & View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY) != 0;
Wale Ogunwale6e94a9e2015-10-07 15:35:49 -07007091 final boolean hideStatusBarWM =
7092 mTopFullscreenOpaqueWindowState != null
7093 && (PolicyControl.getWindowFlags(mTopFullscreenOpaqueWindowState, null)
John Spurlock27735a42013-08-14 17:57:38 -04007094 & WindowManager.LayoutParams.FLAG_FULLSCREEN) != 0;
Wale Ogunwale6e94a9e2015-10-07 15:35:49 -07007095 final boolean hideStatusBarSysui =
John Spurlock27735a42013-08-14 17:57:38 -04007096 (vis & View.SYSTEM_UI_FLAG_FULLSCREEN) != 0;
Wale Ogunwale6e94a9e2015-10-07 15:35:49 -07007097 final boolean hideNavBarSysui =
John Spurlockf1a36642013-10-12 17:50:42 -04007098 (vis & View.SYSTEM_UI_FLAG_HIDE_NAVIGATION) != 0;
John Spurlockad3e6cb2013-04-30 08:47:43 -04007099
Wale Ogunwale6e94a9e2015-10-07 15:35:49 -07007100 final boolean transientStatusBarAllowed = mStatusBar != null
Jorim Jaggi0ffd49c2016-02-12 15:04:21 -08007101 && (statusBarHasFocus || (!mForceShowSystemBars
Wale Ogunwale6e94a9e2015-10-07 15:35:49 -07007102 && (hideStatusBarWM || (hideStatusBarSysui && immersiveSticky))));
John Spurlock27735a42013-08-14 17:57:38 -04007103
Wale Ogunwale6e94a9e2015-10-07 15:35:49 -07007104 final boolean transientNavBarAllowed = mNavigationBar != null
Jorim Jaggi0ffd49c2016-02-12 15:04:21 -08007105 && !mForceShowSystemBars && hideNavBarSysui && immersiveSticky;
John Spurlockf1a36642013-10-12 17:50:42 -04007106
Adrian Roosddc8b272015-05-21 16:28:27 -07007107 final long now = SystemClock.uptimeMillis();
7108 final boolean pendingPanic = mPendingPanicGestureUptime != 0
7109 && now - mPendingPanicGestureUptime <= PANIC_GESTURE_EXPIRATION;
7110 if (pendingPanic && hideNavBarSysui && !isStatusBarKeyguard() && mKeyguardDrawComplete) {
7111 // The user performed the panic gesture recently, we're about to hide the bars,
7112 // we're no longer on the Keyguard and the screen is ready. We can now request the bars.
7113 mPendingPanicGestureUptime = 0;
7114 mStatusBarController.showTransient();
7115 mNavigationBarController.showTransient();
7116 }
7117
Wale Ogunwale6e94a9e2015-10-07 15:35:49 -07007118 final boolean denyTransientStatus = mStatusBarController.isTransientShowRequested()
John Spurlockf1a36642013-10-12 17:50:42 -04007119 && !transientStatusBarAllowed && hideStatusBarSysui;
Wale Ogunwale6e94a9e2015-10-07 15:35:49 -07007120 final boolean denyTransientNav = mNavigationBarController.isTransientShowRequested()
John Spurlockf1a36642013-10-12 17:50:42 -04007121 && !transientNavBarAllowed;
Jorim Jaggi0ffd49c2016-02-12 15:04:21 -08007122 if (denyTransientStatus || denyTransientNav || mForceShowSystemBars) {
John Spurlock27735a42013-08-14 17:57:38 -04007123 // clear the clearable flags instead
John Spurlockf1a36642013-10-12 17:50:42 -04007124 clearClearableFlagsLw();
tiger_huangc58d7562014-10-23 20:24:19 +08007125 vis &= ~View.SYSTEM_UI_CLEARABLE_FLAGS;
John Spurlockad3e6cb2013-04-30 08:47:43 -04007126 }
John Spurlock27735a42013-08-14 17:57:38 -04007127
Selim Cinekf98702e2015-05-20 22:48:40 -07007128 final boolean immersive = (vis & View.SYSTEM_UI_FLAG_IMMERSIVE) != 0;
7129 immersiveSticky = (vis & View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY) != 0;
7130 final boolean navAllowedHidden = immersive || immersiveSticky;
7131
Selim Cinekd6623612015-05-22 18:56:22 -07007132 if (hideNavBarSysui && !navAllowedHidden && windowTypeToLayerLw(win.getBaseType())
7133 > windowTypeToLayerLw(TYPE_INPUT_CONSUMER)) {
Selim Cinekf98702e2015-05-20 22:48:40 -07007134 // We can't hide the navbar from this window otherwise the input consumer would not get
7135 // the input events.
7136 vis = (vis & ~View.SYSTEM_UI_FLAG_HIDE_NAVIGATION);
7137 }
7138
John Spurlock27735a42013-08-14 17:57:38 -04007139 vis = mStatusBarController.updateVisibilityLw(transientStatusBarAllowed, oldVis, vis);
7140
7141 // update navigation bar
John Spurlockf1a36642013-10-12 17:50:42 -04007142 boolean oldImmersiveMode = isImmersiveMode(oldVis);
7143 boolean newImmersiveMode = isImmersiveMode(vis);
7144 if (win != null && oldImmersiveMode != newImmersiveMode) {
John Spurlock79da8332013-09-20 12:04:47 -04007145 final String pkg = win.getOwningPackage();
Maurice Lam99c6e072014-04-28 18:24:28 -07007146 mImmersiveModeConfirmation.immersiveModeChanged(pkg, newImmersiveMode,
7147 isUserSetupComplete());
John Spurlock34e13d92013-08-10 06:52:28 -04007148 }
John Spurlock27735a42013-08-14 17:57:38 -04007149
John Spurlockf1a36642013-10-12 17:50:42 -04007150 vis = mNavigationBarController.updateVisibilityLw(transientNavBarAllowed, oldVis, vis);
7151
John Spurlocke1f366f2013-08-05 12:22:40 -04007152 return vis;
John Spurlockad3e6cb2013-04-30 08:47:43 -04007153 }
7154
John Spurlockf1a36642013-10-12 17:50:42 -04007155 private void clearClearableFlagsLw() {
7156 int newVal = mResettingSystemUiFlags | View.SYSTEM_UI_CLEARABLE_FLAGS;
7157 if (newVal != mResettingSystemUiFlags) {
7158 mResettingSystemUiFlags = newVal;
7159 mWindowManagerFuncs.reevaluateStatusBarVisibility();
7160 }
7161 }
7162
7163 private boolean isImmersiveMode(int vis) {
7164 final int flags = View.SYSTEM_UI_FLAG_IMMERSIVE | View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY;
John Spurlock34e13d92013-08-10 06:52:28 -04007165 return mNavigationBar != null
7166 && (vis & View.SYSTEM_UI_FLAG_HIDE_NAVIGATION) != 0
Daniel Sandler900ece52013-10-18 15:53:27 -04007167 && (vis & flags) != 0
7168 && canHideNavigationBar();
John Spurlock34e13d92013-08-10 06:52:28 -04007169 }
7170
Alan Viverette5a0f4ec2013-10-07 15:10:29 -07007171 /**
Daniel Sandlerdd73ee42013-10-11 22:19:59 -04007172 * @return whether the navigation or status bar can be made translucent
7173 *
7174 * This should return true unless touch exploration is not enabled or
7175 * R.boolean.config_enableTranslucentDecor is false.
Alan Viverette5a0f4ec2013-10-07 15:10:29 -07007176 */
Daniel Sandlerdd73ee42013-10-11 22:19:59 -04007177 private boolean areTranslucentBarsAllowed() {
Alan Viverette817f3cd2015-08-13 11:40:14 -04007178 return mTranslucentDecorEnabled;
Alan Viverette5a0f4ec2013-10-07 15:10:29 -07007179 }
7180
Daniel Sandler0c4ccff2011-10-19 16:39:14 -04007181 // Use this instead of checking config_showNavigationBar so that it can be consistently
7182 // overridden by qemu.hw.mainkeys in the emulator.
Craig Mautnereda67292013-04-28 13:50:14 -07007183 @Override
Daniel Sandler0c4ccff2011-10-19 16:39:14 -04007184 public boolean hasNavigationBar() {
7185 return mHasNavigationBar;
7186 }
7187
satok1bc0a492012-04-25 22:47:12 +09007188 @Override
7189 public void setLastInputMethodWindowLw(WindowState ime, WindowState target) {
7190 mLastInputMethodWindow = ime;
7191 mLastInputMethodTargetWindow = target;
7192 }
7193
Craig Mautnerf1b67412012-09-19 13:18:29 -07007194 @Override
Satoshi Kataoka658c7b82013-10-10 17:03:51 +09007195 public int getInputMethodWindowVisibleHeightLw() {
7196 return mDockBottom - mCurBottom;
7197 }
7198
7199 @Override
Craig Mautnerf1b67412012-09-19 13:18:29 -07007200 public void setCurrentUserLw(int newUserId) {
Craig Mautnerd625ab22013-09-06 13:40:31 -07007201 mCurrentUserId = newUserId;
Jim Miller5ecd8112013-01-09 18:50:26 -08007202 if (mKeyguardDelegate != null) {
7203 mKeyguardDelegate.setCurrentUser(newUserId);
Craig Mautnerf1b67412012-09-19 13:18:29 -07007204 }
John Spurlock13451a22012-09-28 14:40:41 -04007205 if (mStatusBarService != null) {
7206 try {
7207 mStatusBarService.setCurrentUser(newUserId);
7208 } catch (RemoteException e) {
7209 // oh well
7210 }
7211 }
Dianne Hackborn2ea9bae2012-11-02 18:43:48 -07007212 setLastInputMethodWindowLw(null, null);
Craig Mautnerf1b67412012-09-19 13:18:29 -07007213 }
7214
7215 @Override
Svetoslav Ganov545252f2012-12-10 18:29:24 -08007216 public boolean canMagnifyWindow(int windowType) {
7217 switch (windowType) {
7218 case WindowManager.LayoutParams.TYPE_INPUT_METHOD:
7219 case WindowManager.LayoutParams.TYPE_INPUT_METHOD_DIALOG:
7220 case WindowManager.LayoutParams.TYPE_NAVIGATION_BAR:
7221 case WindowManager.LayoutParams.TYPE_MAGNIFICATION_OVERLAY: {
7222 return false;
7223 }
7224 }
7225 return true;
7226 }
7227
7228 @Override
7229 public boolean isTopLevelWindow(int windowType) {
7230 if (windowType >= WindowManager.LayoutParams.FIRST_SUB_WINDOW
7231 && windowType <= WindowManager.LayoutParams.LAST_SUB_WINDOW) {
7232 return (windowType == WindowManager.LayoutParams.TYPE_APPLICATION_ATTACHED_DIALOG);
7233 }
7234 return true;
7235 }
7236
Jim Miller4eeb4f62012-11-08 00:04:29 -08007237 @Override
Jeff Brownd7a04de2012-06-17 14:17:52 -07007238 public void dump(String prefix, PrintWriter pw, String[] args) {
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08007239 pw.print(prefix); pw.print("mSafeMode="); pw.print(mSafeMode);
Dianne Hackbornba24e4d2011-09-01 11:17:06 -07007240 pw.print(" mSystemReady="); pw.print(mSystemReady);
7241 pw.print(" mSystemBooted="); pw.println(mSystemBooted);
Jeff Brown2e7760e2012-04-11 15:14:55 -07007242 pw.print(prefix); pw.print("mLidState="); pw.print(mLidState);
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08007243 pw.print(" mLidOpenRotation="); pw.print(mLidOpenRotation);
Michael Wright3818c922014-09-02 13:59:07 -07007244 pw.print(" mCameraLensCoverState="); pw.print(mCameraLensCoverState);
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08007245 pw.print(" mHdmiPlugged="); pw.println(mHdmiPlugged);
Dianne Hackborne26ab702011-10-16 13:21:33 -07007246 if (mLastSystemUiFlags != 0 || mResettingSystemUiFlags != 0
7247 || mForceClearedSystemUiFlags != 0) {
7248 pw.print(prefix); pw.print("mLastSystemUiFlags=0x");
7249 pw.print(Integer.toHexString(mLastSystemUiFlags));
7250 pw.print(" mResettingSystemUiFlags=0x");
7251 pw.print(Integer.toHexString(mResettingSystemUiFlags));
7252 pw.print(" mForceClearedSystemUiFlags=0x");
7253 pw.println(Integer.toHexString(mForceClearedSystemUiFlags));
Dianne Hackborndf89e652011-10-06 22:35:11 -07007254 }
Dianne Hackborn4eff8d32011-11-10 19:38:40 -08007255 if (mLastFocusNeedsMenu) {
7256 pw.print(prefix); pw.print("mLastFocusNeedsMenu=");
7257 pw.println(mLastFocusNeedsMenu);
7258 }
Jeff Browna20dda42014-05-27 20:57:24 -07007259 pw.print(prefix); pw.print("mWakeGestureEnabledSetting=");
7260 pw.println(mWakeGestureEnabledSetting);
7261
Jeff Brownbcdfc622014-03-06 19:13:04 -08007262 pw.print(prefix); pw.print("mSupportAutoRotation="); pw.println(mSupportAutoRotation);
Daniel Sandler6396c722013-04-16 20:19:09 -04007263 pw.print(prefix); pw.print("mUiMode="); pw.print(mUiMode);
7264 pw.print(" mDockMode="); pw.print(mDockMode);
keunyounga7710492015-09-23 11:33:58 -07007265 pw.print(" mEnableCarDockHomeCapture="); pw.print(mEnableCarDockHomeCapture);
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08007266 pw.print(" mCarDockRotation="); pw.print(mCarDockRotation);
7267 pw.print(" mDeskDockRotation="); pw.println(mDeskDockRotation);
7268 pw.print(prefix); pw.print("mUserRotationMode="); pw.print(mUserRotationMode);
7269 pw.print(" mUserRotation="); pw.print(mUserRotation);
Daniel Sandler2ed6ad62011-02-22 14:54:17 -05007270 pw.print(" mAllowAllRotations="); pw.println(mAllowAllRotations);
Dianne Hackborn6e2281d2012-06-19 17:48:32 -07007271 pw.print(prefix); pw.print("mCurrentAppOrientation="); pw.println(mCurrentAppOrientation);
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08007272 pw.print(prefix); pw.print("mCarDockEnablesAccelerometer=");
7273 pw.print(mCarDockEnablesAccelerometer);
7274 pw.print(" mDeskDockEnablesAccelerometer=");
7275 pw.println(mDeskDockEnablesAccelerometer);
7276 pw.print(prefix); pw.print("mLidKeyboardAccessibility=");
7277 pw.print(mLidKeyboardAccessibility);
7278 pw.print(" mLidNavigationAccessibility="); pw.print(mLidNavigationAccessibility);
Edward Savage-Jones7def60d2015-11-13 13:27:03 +01007279 pw.print(" mLidControlsScreenLock="); pw.println(mLidControlsScreenLock);
Dianne Hackborn6e2281d2012-06-19 17:48:32 -07007280 pw.print(" mLidControlsSleep="); pw.println(mLidControlsSleep);
Jeff Brown6d8fd272014-05-20 21:24:38 -07007281 pw.print(prefix);
7282 pw.print("mShortPressOnPowerBehavior="); pw.print(mShortPressOnPowerBehavior);
7283 pw.print(" mLongPressOnPowerBehavior="); pw.println(mLongPressOnPowerBehavior);
Jeff Brown13f00f02014-10-31 14:45:50 -07007284 pw.print(prefix);
7285 pw.print("mDoublePressOnPowerBehavior="); pw.print(mDoublePressOnPowerBehavior);
7286 pw.print(" mTriplePressOnPowerBehavior="); pw.println(mTriplePressOnPowerBehavior);
Jeff Brown6d8fd272014-05-20 21:24:38 -07007287 pw.print(prefix); pw.print("mHasSoftInput="); pw.println(mHasSoftInput);
Jeff Brown3ee549c2014-09-22 20:14:39 -07007288 pw.print(prefix); pw.print("mAwake="); pw.println(mAwake);
7289 pw.print(prefix); pw.print("mScreenOnEarly="); pw.print(mScreenOnEarly);
7290 pw.print(" mScreenOnFully="); pw.println(mScreenOnFully);
7291 pw.print(prefix); pw.print("mKeyguardDrawComplete="); pw.print(mKeyguardDrawComplete);
7292 pw.print(" mWindowManagerDrawComplete="); pw.println(mWindowManagerDrawComplete);
7293 pw.print(prefix); pw.print("mOrientationSensorEnabled=");
7294 pw.println(mOrientationSensorEnabled);
Dianne Hackbornc652de82013-02-15 16:32:56 -08007295 pw.print(prefix); pw.print("mOverscanScreen=("); pw.print(mOverscanScreenLeft);
7296 pw.print(","); pw.print(mOverscanScreenTop);
7297 pw.print(") "); pw.print(mOverscanScreenWidth);
7298 pw.print("x"); pw.println(mOverscanScreenHeight);
7299 if (mOverscanLeft != 0 || mOverscanTop != 0
7300 || mOverscanRight != 0 || mOverscanBottom != 0) {
7301 pw.print(prefix); pw.print("mOverscan left="); pw.print(mOverscanLeft);
7302 pw.print(" top="); pw.print(mOverscanTop);
7303 pw.print(" right="); pw.print(mOverscanRight);
7304 pw.print(" bottom="); pw.println(mOverscanBottom);
7305 }
Dianne Hackborn313440842013-02-19 19:22:59 -08007306 pw.print(prefix); pw.print("mRestrictedOverscanScreen=(");
7307 pw.print(mRestrictedOverscanScreenLeft);
7308 pw.print(","); pw.print(mRestrictedOverscanScreenTop);
7309 pw.print(") "); pw.print(mRestrictedOverscanScreenWidth);
7310 pw.print("x"); pw.println(mRestrictedOverscanScreenHeight);
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08007311 pw.print(prefix); pw.print("mUnrestrictedScreen=("); pw.print(mUnrestrictedScreenLeft);
7312 pw.print(","); pw.print(mUnrestrictedScreenTop);
7313 pw.print(") "); pw.print(mUnrestrictedScreenWidth);
7314 pw.print("x"); pw.println(mUnrestrictedScreenHeight);
7315 pw.print(prefix); pw.print("mRestrictedScreen=("); pw.print(mRestrictedScreenLeft);
7316 pw.print(","); pw.print(mRestrictedScreenTop);
7317 pw.print(") "); pw.print(mRestrictedScreenWidth);
7318 pw.print("x"); pw.println(mRestrictedScreenHeight);
Dianne Hackborn5b5cc4d2012-05-16 13:15:00 -07007319 pw.print(prefix); pw.print("mStableFullscreen=("); pw.print(mStableFullscreenLeft);
7320 pw.print(","); pw.print(mStableFullscreenTop);
7321 pw.print(")-("); pw.print(mStableFullscreenRight);
7322 pw.print(","); pw.print(mStableFullscreenBottom); pw.println(")");
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07007323 pw.print(prefix); pw.print("mStable=("); pw.print(mStableLeft);
7324 pw.print(","); pw.print(mStableTop);
7325 pw.print(")-("); pw.print(mStableRight);
7326 pw.print(","); pw.print(mStableBottom); pw.println(")");
Dianne Hackborn5c58de32012-04-28 19:52:37 -07007327 pw.print(prefix); pw.print("mSystem=("); pw.print(mSystemLeft);
7328 pw.print(","); pw.print(mSystemTop);
7329 pw.print(")-("); pw.print(mSystemRight);
7330 pw.print(","); pw.print(mSystemBottom); pw.println(")");
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08007331 pw.print(prefix); pw.print("mCur=("); pw.print(mCurLeft);
7332 pw.print(","); pw.print(mCurTop);
7333 pw.print(")-("); pw.print(mCurRight);
7334 pw.print(","); pw.print(mCurBottom); pw.println(")");
7335 pw.print(prefix); pw.print("mContent=("); pw.print(mContentLeft);
7336 pw.print(","); pw.print(mContentTop);
7337 pw.print(")-("); pw.print(mContentRight);
7338 pw.print(","); pw.print(mContentBottom); pw.println(")");
Dianne Hackborne30e02f2014-05-27 18:24:45 -07007339 pw.print(prefix); pw.print("mVoiceContent=("); pw.print(mVoiceContentLeft);
7340 pw.print(","); pw.print(mVoiceContentTop);
7341 pw.print(")-("); pw.print(mVoiceContentRight);
7342 pw.print(","); pw.print(mVoiceContentBottom); pw.println(")");
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08007343 pw.print(prefix); pw.print("mDock=("); pw.print(mDockLeft);
7344 pw.print(","); pw.print(mDockTop);
7345 pw.print(")-("); pw.print(mDockRight);
7346 pw.print(","); pw.print(mDockBottom); pw.println(")");
Dianne Hackborn5c58de32012-04-28 19:52:37 -07007347 pw.print(prefix); pw.print("mDockLayer="); pw.print(mDockLayer);
7348 pw.print(" mStatusBarLayer="); pw.println(mStatusBarLayer);
Dianne Hackborn7ad44382012-10-18 17:46:00 -07007349 pw.print(prefix); pw.print("mShowingLockscreen="); pw.print(mShowingLockscreen);
7350 pw.print(" mShowingDream="); pw.print(mShowingDream);
Jeff Brown061ea992015-04-17 19:55:47 -07007351 pw.print(" mDreamingLockscreen="); pw.print(mDreamingLockscreen);
7352 pw.print(" mDreamingSleepToken="); pw.println(mDreamingSleepToken);
Dianne Hackborn2ea9bae2012-11-02 18:43:48 -07007353 if (mLastInputMethodWindow != null) {
7354 pw.print(prefix); pw.print("mLastInputMethodWindow=");
7355 pw.println(mLastInputMethodWindow);
7356 }
7357 if (mLastInputMethodTargetWindow != null) {
7358 pw.print(prefix); pw.print("mLastInputMethodTargetWindow=");
7359 pw.println(mLastInputMethodTargetWindow);
7360 }
7361 if (mStatusBar != null) {
7362 pw.print(prefix); pw.print("mStatusBar=");
Dianne Hackbornae6688b2015-02-11 17:02:41 -08007363 pw.print(mStatusBar); pw.print(" isStatusBarKeyguard=");
7364 pw.println(isStatusBarKeyguard());
Dianne Hackborn2ea9bae2012-11-02 18:43:48 -07007365 }
7366 if (mNavigationBar != null) {
7367 pw.print(prefix); pw.print("mNavigationBar=");
7368 pw.println(mNavigationBar);
7369 }
Dianne Hackborn2ea9bae2012-11-02 18:43:48 -07007370 if (mFocusedWindow != null) {
7371 pw.print(prefix); pw.print("mFocusedWindow=");
7372 pw.println(mFocusedWindow);
7373 }
7374 if (mFocusedApp != null) {
7375 pw.print(prefix); pw.print("mFocusedApp=");
7376 pw.println(mFocusedApp);
7377 }
7378 if (mWinDismissingKeyguard != null) {
7379 pw.print(prefix); pw.print("mWinDismissingKeyguard=");
7380 pw.println(mWinDismissingKeyguard);
7381 }
7382 if (mTopFullscreenOpaqueWindowState != null) {
7383 pw.print(prefix); pw.print("mTopFullscreenOpaqueWindowState=");
7384 pw.println(mTopFullscreenOpaqueWindowState);
7385 }
Adrian Rooscd3884d2015-02-18 17:25:23 +01007386 if (mTopFullscreenOpaqueOrDimmingWindowState != null) {
7387 pw.print(prefix); pw.print("mTopFullscreenOpaqueOrDimmingWindowState=");
7388 pw.println(mTopFullscreenOpaqueOrDimmingWindowState);
7389 }
Dianne Hackborn891d3fb2013-01-09 18:31:37 -08007390 if (mForcingShowNavBar) {
7391 pw.print(prefix); pw.print("mForcingShowNavBar=");
7392 pw.println(mForcingShowNavBar); pw.print( "mForcingShowNavBarLayer=");
7393 pw.println(mForcingShowNavBarLayer);
7394 }
Dianne Hackborn7ad44382012-10-18 17:46:00 -07007395 pw.print(prefix); pw.print("mTopIsFullscreen="); pw.print(mTopIsFullscreen);
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08007396 pw.print(" mHideLockScreen="); pw.println(mHideLockScreen);
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07007397 pw.print(prefix); pw.print("mForceStatusBar="); pw.print(mForceStatusBar);
7398 pw.print(" mForceStatusBarFromKeyguard=");
7399 pw.println(mForceStatusBarFromKeyguard);
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08007400 pw.print(prefix); pw.print("mDismissKeyguard="); pw.print(mDismissKeyguard);
Craig Mautnerad09bcc2012-10-08 13:33:11 -07007401 pw.print(" mWinDismissingKeyguard="); pw.print(mWinDismissingKeyguard);
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08007402 pw.print(" mHomePressed="); pw.println(mHomePressed);
7403 pw.print(prefix); pw.print("mAllowLockscreenWhenOn="); pw.print(mAllowLockscreenWhenOn);
7404 pw.print(" mLockScreenTimeout="); pw.print(mLockScreenTimeout);
7405 pw.print(" mLockScreenTimerActive="); pw.println(mLockScreenTimerActive);
7406 pw.print(prefix); pw.print("mEndcallBehavior="); pw.print(mEndcallBehavior);
7407 pw.print(" mIncallPowerBehavior="); pw.print(mIncallPowerBehavior);
7408 pw.print(" mLongPressOnHomeBehavior="); pw.println(mLongPressOnHomeBehavior);
7409 pw.print(prefix); pw.print("mLandscapeRotation="); pw.print(mLandscapeRotation);
7410 pw.print(" mSeascapeRotation="); pw.println(mSeascapeRotation);
7411 pw.print(prefix); pw.print("mPortraitRotation="); pw.print(mPortraitRotation);
7412 pw.print(" mUpsideDownRotation="); pw.println(mUpsideDownRotation);
Jeff Brownc82c89ed2013-04-17 17:18:15 -07007413 pw.print(prefix); pw.print("mDemoHdmiRotation="); pw.print(mDemoHdmiRotation);
7414 pw.print(" mDemoHdmiRotationLock="); pw.println(mDemoHdmiRotationLock);
7415 pw.print(prefix); pw.print("mUndockedHdmiRotation="); pw.println(mUndockedHdmiRotation);
Jeff Brown600f0032014-05-22 17:06:00 -07007416
Tim Kilbournd7c0c2e2014-05-29 16:08:10 -07007417 mGlobalKeyManager.dump(prefix, pw);
John Spurlock27735a42013-08-14 17:57:38 -04007418 mStatusBarController.dump(pw, prefix);
7419 mNavigationBarController.dump(pw, prefix);
John Spurlockc6d1c602014-01-17 15:22:06 -05007420 PolicyControl.dump(prefix, pw);
Jeff Brown600f0032014-05-22 17:06:00 -07007421
Jeff Browna20dda42014-05-27 20:57:24 -07007422 if (mWakeGestureListener != null) {
7423 mWakeGestureListener.dump(pw, prefix);
7424 }
Jeff Brown600f0032014-05-22 17:06:00 -07007425 if (mOrientationListener != null) {
7426 mOrientationListener.dump(pw, prefix);
7427 }
Filip Gruszczynskicfb31852015-02-25 21:47:12 +00007428 if (mBurnInProtectionHelper != null) {
7429 mBurnInProtectionHelper.dump(prefix, pw);
7430 }
Jorim Jaggi84dc08a2015-09-11 17:45:22 -07007431 if (mKeyguardDelegate != null) {
7432 mKeyguardDelegate.dump(prefix, pw);
7433 }
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08007434 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08007435}