blob: 574faa01a241a7d94a35986967b4e3d50509b263 [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;
Muyuan Li6ca619f2016-03-08 13:30:42 -080031import static android.view.WindowManager.TAKE_SCREENSHOT_FULLSCREEN;
32import static android.view.WindowManager.TAKE_SCREENSHOT_SELECTED_REGION;
Wale Ogunwale6e94a9e2015-10-07 15:35:49 -070033import static android.view.WindowManager.LayoutParams.*;
Jaewan Kim49117872016-01-19 17:24:08 +090034import static android.view.WindowManagerPolicy.WindowManagerFuncs.CAMERA_LENS_COVERED;
Wale Ogunwale6e94a9e2015-10-07 15:35:49 -070035import static android.view.WindowManagerPolicy.WindowManagerFuncs.CAMERA_LENS_COVER_ABSENT;
36import static android.view.WindowManagerPolicy.WindowManagerFuncs.CAMERA_LENS_UNCOVERED;
Jaewan Kim49117872016-01-19 17:24:08 +090037import static android.view.WindowManagerPolicy.WindowManagerFuncs.LID_ABSENT;
38import static android.view.WindowManagerPolicy.WindowManagerFuncs.LID_CLOSED;
39import static android.view.WindowManagerPolicy.WindowManagerFuncs.LID_OPEN;
Wale Ogunwale6e94a9e2015-10-07 15:35:49 -070040
Svet Ganov9cea80cd2016-02-16 11:47:00 -080041import android.Manifest;
Dianne Hackborna4972e92012-03-14 10:38:05 -070042import android.app.ActivityManager;
Jorim Jaggi86905582016-02-09 21:36:09 -080043import android.app.ActivityManager.StackId;
Jeff Brown061ea992015-04-17 19:55:47 -070044import android.app.ActivityManagerInternal;
45import android.app.ActivityManagerInternal.SleepToken;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -080046import android.app.ActivityManagerNative;
Dianne Hackbornc2293022013-02-06 23:14:49 -080047import android.app.AppOpsManager;
Daniel Sandler6396c722013-04-16 20:19:09 -040048import android.app.IUiModeManager;
Dianne Hackborn661cd522011-08-22 00:26:20 -070049import android.app.ProgressDialog;
Jeff Brownde7a8ea2012-06-13 18:28:57 -070050import android.app.SearchManager;
John Spurlock97642182013-07-29 17:58:39 -040051import android.app.StatusBarManager;
Dianne Hackborn78968392010-03-04 20:47:56 -080052import android.app.UiModeManager;
Dianne Hackborn39c2d712009-09-22 11:41:31 -070053import android.content.ActivityNotFoundException;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -080054import android.content.BroadcastReceiver;
Daniel Sandler0601eb72011-04-13 01:01:32 -040055import android.content.ComponentName;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -080056import android.content.ContentResolver;
57import android.content.Context;
58import android.content.Intent;
Mike Lockwood1753f7f2009-08-24 14:49:07 -070059import android.content.IntentFilter;
Winson Chung9112ec32011-06-27 13:15:32 -070060import android.content.ServiceConnection;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -080061import android.content.pm.ActivityInfo;
Svet Ganov03f2afc2016-03-04 16:13:03 -080062import android.content.pm.ApplicationInfo;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -080063import android.content.pm.PackageManager;
Daniel Sandler6396c722013-04-16 20:19:09 -040064import android.content.pm.ResolveInfo;
Dianne Hackborn2f0b1752011-05-31 17:59:49 -070065import android.content.res.CompatibilityInfo;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -080066import android.content.res.Configuration;
67import android.content.res.Resources;
68import android.database.ContentObserver;
Dianne Hackbornc777e072010-02-12 13:07:59 -080069import android.graphics.PixelFormat;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -080070import android.graphics.Rect;
Jinsuk Kime601b712015-07-07 08:01:02 +090071import android.hardware.hdmi.HdmiControlManager;
72import android.hardware.hdmi.HdmiPlaybackClient;
73import android.hardware.hdmi.HdmiPlaybackClient.OneTouchPlayCallback;
John Spurlock7b414672014-07-18 13:02:39 -040074import android.media.AudioAttributes;
Michael Jurka7a348952012-02-27 13:07:58 -080075import android.media.AudioManager;
John Spurlock61560172015-02-06 19:46:04 -050076import android.media.AudioSystem;
Michael Jurka7a348952012-02-27 13:07:58 -080077import android.media.IAudioService;
Svetoslav Ganov7befb7d2012-09-27 16:49:23 -070078import android.media.Ringtone;
79import android.media.RingtoneManager;
RoboErik8a2cfc32014-05-16 11:19:38 -070080import android.media.session.MediaSessionLegacyHelper;
Billy Laucbe540f2015-06-25 01:51:44 +010081import android.os.Binder;
Svet Ganov03f2afc2016-03-04 16:13:03 -080082import android.os.Build;
Dianne Hackborn38e29a62011-09-18 14:43:08 -070083import android.os.Bundle;
Craig Mautner276a6eb2014-11-04 15:32:57 -080084import android.os.Debug;
Jeff Brown9a538ee2012-08-20 14:56:57 -070085import android.os.FactoryTest;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -080086import android.os.Handler;
87import android.os.IBinder;
Dianne Hackbornb6683c42015-06-18 17:40:33 -070088import android.os.IDeviceIdleController;
Jeff Brown32cbc38552011-12-01 14:01:49 -080089import android.os.Looper;
Dianne Hackbornfc8fa632011-08-17 16:20:47 -070090import android.os.Message;
91import android.os.Messenger;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -080092import android.os.PowerManager;
Nick Armstrong-Crews56ecfcc2015-09-07 21:46:50 -070093import android.os.PowerManagerInternal;
Billy Laucbe540f2015-06-25 01:51:44 +010094import android.os.Process;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -080095import android.os.RemoteException;
96import android.os.ServiceManager;
97import android.os.SystemClock;
98import android.os.SystemProperties;
Dianne Hackbornad7fa7f2011-01-07 14:06:50 -080099import android.os.UEventObserver;
Dianne Hackbornf02b60a2012-08-16 10:48:27 -0700100import android.os.UserHandle;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800101import android.os.Vibrator;
Michael Wright3818c922014-09-02 13:59:07 -0700102import android.provider.MediaStore;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800103import android.provider.Settings;
Jose Lima9546b202014-07-02 17:21:51 -0700104import android.service.dreams.DreamManagerInternal;
John Spurlockc8b46ca2013-04-08 12:59:26 -0400105import android.service.dreams.DreamService;
106import android.service.dreams.IDreamManager;
Michael Wrightdc63f7b2014-08-21 19:05:21 -0700107import android.speech.RecognizerIntent;
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700108import android.telecom.TelecomManager;
Dianne Hackborn81e56d52011-05-26 00:55:58 -0700109import android.util.DisplayMetrics;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800110import android.util.EventLog;
111import android.util.Log;
Jeff Browna41ca772010-08-11 14:46:32 -0700112import android.util.Slog;
Jeff Brown6651a632011-11-28 12:59:11 -0800113import android.util.SparseArray;
Muyuan Li94ce94e2016-02-24 16:20:54 -0800114import android.util.LongSparseArray;
Dianne Hackbornf87d1962012-04-04 12:48:24 -0700115import android.view.Display;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800116import android.view.Gravity;
117import android.view.HapticFeedbackConstants;
Dianne Hackborne0f085d2011-11-30 18:41:15 -0800118import android.view.IApplicationToken;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800119import android.view.IWindowManager;
Jeff Browna41ca772010-08-11 14:46:32 -0700120import android.view.InputChannel;
Jeff Brown4d396052010-10-29 21:50:21 -0700121import android.view.InputDevice;
Jeff Brown4952dfd2011-11-30 19:23:22 -0800122import android.view.InputEvent;
Jeff Brown32cbc38552011-12-01 14:01:49 -0800123import android.view.InputEventReceiver;
Jeff Brown6b53e8d2010-11-10 16:03:06 -0800124import android.view.KeyCharacterMap;
Craig Mautnerae446592012-12-06 19:05:05 -0800125import android.view.KeyCharacterMap.FallbackAction;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800126import android.view.KeyEvent;
127import android.view.MotionEvent;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800128import android.view.Surface;
129import android.view.View;
130import android.view.ViewConfiguration;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800131import android.view.WindowManager;
Craig Mautnerae446592012-12-06 19:05:05 -0800132import android.view.WindowManagerGlobal;
Craig Mautner8a0da012014-05-31 15:13:37 -0700133import android.view.WindowManagerInternal;
Craig Mautnerae446592012-12-06 19:05:05 -0800134import android.view.WindowManagerPolicy;
Craig Mautnerae446592012-12-06 19:05:05 -0800135import android.view.accessibility.AccessibilityEvent;
Svetoslav8e3feb12014-02-24 13:46:47 -0800136import android.view.accessibility.AccessibilityManager;
Craig Mautnerae446592012-12-06 19:05:05 -0800137import android.view.animation.Animation;
Jorim Jaggi76a16232014-08-08 17:00:47 +0200138import android.view.animation.AnimationSet;
Craig Mautnerae446592012-12-06 19:05:05 -0800139import android.view.animation.AnimationUtils;
Craig Mautnerae446592012-12-06 19:05:05 -0800140import com.android.internal.R;
Jason Monk8f7f3182015-11-18 16:35:14 -0500141import com.android.internal.logging.MetricsLogger;
142import com.android.internal.policy.PhoneWindow;
Muyuan Li94ce94e2016-02-24 16:20:54 -0800143import com.android.internal.policy.IShortcutService;
Craig Mautnerae446592012-12-06 19:05:05 -0800144import com.android.internal.statusbar.IStatusBarService;
Filip Gruszczynski2217f612015-05-26 11:32:08 -0700145import com.android.internal.util.ScreenShapeHelper;
Craig Mautnerae446592012-12-06 19:05:05 -0800146import com.android.internal.widget.PointerLocationView;
Adrian Roos5941c982015-09-03 15:59:49 -0700147import com.android.server.GestureLauncherService;
Craig Mautner8a0da012014-05-31 15:13:37 -0700148import com.android.server.LocalServices;
Jorim Jaggib10e33f2015-02-04 21:57:40 +0100149import com.android.server.policy.keyguard.KeyguardServiceDelegate;
Jorim Jaggi4cfdcf52015-07-09 12:13:59 -0700150import com.android.server.policy.keyguard.KeyguardServiceDelegate.DrawnListener;
Jorim Jaggi86905582016-02-09 21:36:09 -0800151import com.android.server.statusbar.StatusBarManagerInternal;
Craig Mautnerae446592012-12-06 19:05:05 -0800152
153import java.io.File;
154import java.io.FileReader;
155import java.io.IOException;
156import java.io.PrintWriter;
Craig Mautner2bc789b2014-03-19 19:48:38 -0700157import java.util.HashSet;
Craig Mautner276a6eb2014-11-04 15:32:57 -0800158import java.util.List;
Craig Mautnerae446592012-12-06 19:05:05 -0800159
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800160/**
The Android Open Source Project0727d222009-03-11 12:11:58 -0700161 * WindowManagerPolicy implementation for the Android phone UI. This
162 * introduces a new method suffix, Lp, for an internal lock of the
163 * PhoneWindowManager. This is used to protect some internal state, and
John Spurlock04db1762013-05-13 12:46:41 -0400164 * 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 -0700165 * of both of those when held.
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800166 */
167public class PhoneWindowManager implements WindowManagerPolicy {
168 static final String TAG = "WindowManager";
169 static final boolean DEBUG = false;
Joe Onorato43a17652011-04-06 19:22:23 -0700170 static final boolean localLOGV = false;
Jeff Brown40013652012-05-16 21:22:36 -0700171 static final boolean DEBUG_INPUT = false;
Craig Mautnerc0d2d0a2014-10-31 16:25:15 -0700172 static final boolean DEBUG_KEYGUARD = false;
173 static final boolean DEBUG_LAYOUT = false;
Craig Mautner6fbda632012-07-03 09:26:39 -0700174 static final boolean DEBUG_STARTING_WINDOW = false;
Craig Mautner8a0da012014-05-31 15:13:37 -0700175 static final boolean DEBUG_WAKEUP = false;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800176 static final boolean SHOW_STARTING_ANIMATIONS = true;
177 static final boolean SHOW_PROCESSES_ON_ALT_MENU = false;
Joe Onoratod208e702010-10-08 16:22:43 -0400178
Daniel Sandler6396c722013-04-16 20:19:09 -0400179 // Whether to allow dock apps with METADATA_DOCK_HOME to temporarily take over the Home key.
keunyounga7710492015-09-23 11:33:58 -0700180 // No longer recommended for desk docks;
Daniel Sandler6396c722013-04-16 20:19:09 -0400181 static final boolean ENABLE_DESK_DOCK_HOME_CAPTURE = false;
182
Jeff Brown6d8fd272014-05-20 21:24:38 -0700183 static final int SHORT_PRESS_POWER_NOTHING = 0;
184 static final int SHORT_PRESS_POWER_GO_TO_SLEEP = 1;
185 static final int SHORT_PRESS_POWER_REALLY_GO_TO_SLEEP = 2;
186 static final int SHORT_PRESS_POWER_REALLY_GO_TO_SLEEP_AND_GO_HOME = 3;
Bryce Lee01b0c5f2015-02-05 18:24:04 -0800187 static final int SHORT_PRESS_POWER_GO_HOME = 4;
Jeff Brown6d8fd272014-05-20 21:24:38 -0700188
Joe Onoratod208e702010-10-08 16:22:43 -0400189 static final int LONG_PRESS_POWER_NOTHING = 0;
190 static final int LONG_PRESS_POWER_GLOBAL_ACTIONS = 1;
191 static final int LONG_PRESS_POWER_SHUT_OFF = 2;
Jeff Brown9a538ee2012-08-20 14:56:57 -0700192 static final int LONG_PRESS_POWER_SHUT_OFF_NO_CONFIRM = 3;
Michael Jurka3b1fc472011-06-13 10:54:40 -0700193
Anthony Hugh34f09ca2016-03-04 12:03:37 -0800194 static final int LONG_PRESS_BACK_NOTHING = 0;
195 static final int LONG_PRESS_BACK_GO_TO_VOICE_ASSIST = 1;
196
Jeff Brown13f00f02014-10-31 14:45:50 -0700197 static final int MULTI_PRESS_POWER_NOTHING = 0;
198 static final int MULTI_PRESS_POWER_THEATER_MODE = 1;
199 static final int MULTI_PRESS_POWER_BRIGHTNESS_BOOST = 2;
200
Michael Jurka3b1fc472011-06-13 10:54:40 -0700201 // These need to match the documentation/constant in
202 // core/res/res/values/config.xml
Joe Onorato46b0d682010-11-22 17:37:27 -0800203 static final int LONG_PRESS_HOME_NOTHING = 0;
Michael Wrightc9ebea72013-01-16 19:25:02 -0800204 static final int LONG_PRESS_HOME_RECENT_SYSTEM_UI = 1;
Jeff Browncaca8812013-05-09 13:34:33 -0700205 static final int LONG_PRESS_HOME_ASSIST = 2;
Jaewan Kim76b7d0d2016-02-12 19:01:02 +0900206 static final int LAST_LONG_PRESS_HOME_BEHAVIOR = LONG_PRESS_HOME_ASSIST;
Jeff Browncaca8812013-05-09 13:34:33 -0700207
208 static final int DOUBLE_TAP_HOME_NOTHING = 0;
209 static final int DOUBLE_TAP_HOME_RECENT_SYSTEM_UI = 1;
Joe Onorato46b0d682010-11-22 17:37:27 -0800210
Jaewan Kim49117872016-01-19 17:24:08 +0900211 static final int SHORT_PRESS_WINDOW_NOTHING = 0;
212 static final int SHORT_PRESS_WINDOW_PICTURE_IN_PICTURE = 1;
213
Filip Gruszczynskia483a1d2015-03-17 19:06:58 +0000214 static final int SHORT_PRESS_SLEEP_GO_TO_SLEEP = 0;
215 static final int SHORT_PRESS_SLEEP_GO_TO_SLEEP_AND_GO_HOME = 1;
216
Yorke Lee9b2ffb32016-03-07 20:42:01 -0800217 // Controls navigation bar opacity depending on which workspace stacks are currently
218 // visible.
219 // Nav bar is always opaque when either the freeform stack or docked stack is visible.
220 static final int NAV_BAR_OPAQUE_WHEN_FREEFORM_OR_DOCKED = 0;
221 // Nav bar is always translucent when the freeform stack is visible, otherwise always opaque.
222 static final int NAV_BAR_TRANSLUCENT_WHEN_FREEFORM_OPAQUE_OTHERWISE = 1;
223
Dianne Hackborn5cb8d792009-05-21 17:34:15 -0700224 static final int APPLICATION_MEDIA_SUBLAYER = -2;
225 static final int APPLICATION_MEDIA_OVERLAY_SUBLAYER = -1;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800226 static final int APPLICATION_PANEL_SUBLAYER = 1;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800227 static final int APPLICATION_SUB_PANEL_SUBLAYER = 2;
Wale Ogunwale0a4dc222015-04-14 12:58:42 -0700228 static final int APPLICATION_ABOVE_SUB_PANEL_SUBLAYER = 3;
Craig Mautner88400d32012-09-30 12:35:45 -0700229
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800230 static public final String SYSTEM_DIALOG_REASON_KEY = "reason";
231 static public final String SYSTEM_DIALOG_REASON_GLOBAL_ACTIONS = "globalactions";
232 static public final String SYSTEM_DIALOG_REASON_RECENT_APPS = "recentapps";
Joe Onoratof275f0c2009-11-24 16:11:13 -0500233 static public final String SYSTEM_DIALOG_REASON_HOME_KEY = "homekey";
Jeff Brownde7a8ea2012-06-13 18:28:57 -0700234 static public final String SYSTEM_DIALOG_REASON_ASSIST = "assist";
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800235
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -0700236 /**
237 * These are the system UI flags that, when changing, can cause the layout
238 * of the screen to change.
239 */
240 static final int SYSTEM_UI_CHANGING_LAYOUT =
John Spurlocke1f366f2013-08-05 12:22:40 -0400241 View.SYSTEM_UI_FLAG_HIDE_NAVIGATION
John Spurlock7f4820a2013-10-08 12:54:35 -0400242 | View.SYSTEM_UI_FLAG_FULLSCREEN
243 | View.STATUS_BAR_TRANSLUCENT
Adrian Roosea562512014-05-05 13:33:03 +0200244 | View.NAVIGATION_BAR_TRANSLUCENT
Jorim Jaggi4fa78922015-11-30 17:13:56 -0800245 | View.STATUS_BAR_TRANSPARENT
246 | View.NAVIGATION_BAR_TRANSPARENT;
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -0700247
John Spurlock7b414672014-07-18 13:02:39 -0400248 private static final AudioAttributes VIBRATION_ATTRIBUTES = new AudioAttributes.Builder()
249 .setContentType(AudioAttributes.CONTENT_TYPE_SONIFICATION)
250 .setUsage(AudioAttributes.USAGE_ASSISTANCE_SONIFICATION)
251 .build();
252
Adrian Roosddc8b272015-05-21 16:28:27 -0700253 // The panic gesture may become active only after the keyguard is dismissed and the immersive
254 // app shows again. If that doesn't happen for 30s we drop the gesture.
255 private static final long PANIC_GESTURE_EXPIRATION = 30000;
256
Winson44dbe292016-03-10 14:00:14 -0800257 private static final String SYSUI_PACKAGE = "com.android.systemui";
258 private static final String SYSUI_SCREENSHOT_SERVICE =
259 "com.android.systemui.screenshot.TakeScreenshotService";
260 private static final String SYSUI_SCREENSHOT_ERROR_RECEIVER =
261 "com.android.systemui.screenshot.ScreenshotServiceErrorReceiver";
262
Jim Miller5ecd8112013-01-09 18:50:26 -0800263 /**
264 * Keyguard stuff
265 */
266 private WindowState mKeyguardScrim;
Jorim Jaggi380ecb82014-03-14 17:25:20 +0100267 private boolean mKeyguardHidden;
Jeff Brown3ee549c2014-09-22 20:14:39 -0700268 private boolean mKeyguardDrawnOnce;
Jim Miller5ecd8112013-01-09 18:50:26 -0800269
Jeff Brown6651a632011-11-28 12:59:11 -0800270 /* Table of Application Launch keys. Maps from key codes to intent categories.
271 *
272 * These are special keys that are used to launch particular kinds of applications,
273 * such as a web browser. HID defines nearly a hundred of them in the Consumer (0x0C)
274 * usage page. We don't support quite that many yet...
275 */
276 static SparseArray<String> sApplicationLaunchKeyCategories;
277 static {
278 sApplicationLaunchKeyCategories = new SparseArray<String>();
279 sApplicationLaunchKeyCategories.append(
280 KeyEvent.KEYCODE_EXPLORER, Intent.CATEGORY_APP_BROWSER);
281 sApplicationLaunchKeyCategories.append(
282 KeyEvent.KEYCODE_ENVELOPE, Intent.CATEGORY_APP_EMAIL);
283 sApplicationLaunchKeyCategories.append(
284 KeyEvent.KEYCODE_CONTACTS, Intent.CATEGORY_APP_CONTACTS);
285 sApplicationLaunchKeyCategories.append(
286 KeyEvent.KEYCODE_CALENDAR, Intent.CATEGORY_APP_CALENDAR);
287 sApplicationLaunchKeyCategories.append(
288 KeyEvent.KEYCODE_MUSIC, Intent.CATEGORY_APP_MUSIC);
289 sApplicationLaunchKeyCategories.append(
290 KeyEvent.KEYCODE_CALCULATOR, Intent.CATEGORY_APP_CALCULATOR);
291 }
292
Craig Mautnerc3daedd2014-09-13 11:17:23 -0700293 /** Amount of time (in milliseconds) to wait for windows drawn before powering on. */
Jorim Jaggi0d210f62015-07-10 14:24:44 -0700294 static final int WAITING_FOR_DRAWN_TIMEOUT = 1000;
Craig Mautnerc3daedd2014-09-13 11:17:23 -0700295
Dianne Hackborndf89e652011-10-06 22:35:11 -0700296 /**
297 * Lock protecting internal state. Must not call out into window
298 * manager with lock held. (This lock will be acquired in places
299 * where the window manager is calling in with its own lock held.)
300 */
Craig Mautner0bf6ec92012-12-18 08:33:27 -0800301 private final Object mLock = new Object();
Dianne Hackborndf89e652011-10-06 22:35:11 -0700302
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800303 Context mContext;
304 IWindowManager mWindowManager;
Dianne Hackborndf89e652011-10-06 22:35:11 -0700305 WindowManagerFuncs mWindowManagerFuncs;
Craig Mautner8a0da012014-05-31 15:13:37 -0700306 WindowManagerInternal mWindowManagerInternal;
Jeff Brown96307042012-07-27 15:51:34 -0700307 PowerManager mPowerManager;
Jeff Brown061ea992015-04-17 19:55:47 -0700308 ActivityManagerInternal mActivityManagerInternal;
Jose Lima9546b202014-07-02 17:21:51 -0700309 DreamManagerInternal mDreamManagerInternal;
Michael Wrighta4d22d72015-09-16 23:19:26 +0100310 PowerManagerInternal mPowerManagerInternal;
Joe Onorato93056472010-09-10 10:30:46 -0400311 IStatusBarService mStatusBarService;
Jorim Jaggi86905582016-02-09 21:36:09 -0800312 StatusBarManagerInternal mStatusBarManagerInternal;
Jeff Browncaca8812013-05-09 13:34:33 -0700313 boolean mPreloadedRecentApps;
Dianne Hackborn42e620c2012-06-24 13:20:51 -0700314 final Object mServiceAquireLock = new Object();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800315 Vibrator mVibrator; // Vibrator for giving feedback of orientation changes
Jeff Brownde7a8ea2012-06-13 18:28:57 -0700316 SearchManager mSearchManager;
Svetoslav8e3feb12014-02-24 13:46:47 -0800317 AccessibilityManager mAccessibilityManager;
Filip Gruszczynskicfb31852015-02-25 21:47:12 +0000318 BurnInProtectionHelper mBurnInProtectionHelper;
Billy Laucbe540f2015-06-25 01:51:44 +0100319 AppOpsManager mAppOpsManager;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800320
Dianne Hackborn181ceb52009-08-27 22:16:40 -0700321 // Vibrator pattern for haptic feedback of a long press.
322 long[] mLongPressVibePattern;
Craig Mautner88400d32012-09-30 12:35:45 -0700323
Dianne Hackborn181ceb52009-08-27 22:16:40 -0700324 // Vibrator pattern for haptic feedback of virtual key press.
325 long[] mVirtualKeyVibePattern;
Craig Mautner967212c2013-04-13 21:10:58 -0700326
Amith Yamasanic33cb712010-02-10 15:21:49 -0800327 // Vibrator pattern for a short vibration.
328 long[] mKeyboardTapVibePattern;
329
Fabrice Di Meglioeeff63a2013-08-05 12:07:24 -0700330 // Vibrator pattern for a short vibration when tapping on an hour/minute tick of a Clock.
331 long[] mClockTickVibePattern;
332
Fabrice Di Megliobd9152f2013-10-01 11:21:31 -0700333 // Vibrator pattern for a short vibration when tapping on a day/month/year date of a Calendar.
334 long[] mCalendarDateVibePattern;
335
Dianne Hackbornb1a79802009-09-29 15:18:31 -0700336 // Vibrator pattern for haptic feedback during boot when safe mode is disabled.
337 long[] mSafeModeDisabledVibePattern;
Craig Mautner967212c2013-04-13 21:10:58 -0700338
Dianne Hackbornb1a79802009-09-29 15:18:31 -0700339 // Vibrator pattern for haptic feedback during boot when safe mode is enabled.
340 long[] mSafeModeEnabledVibePattern;
Romain Guy8154cd32010-03-29 14:41:15 -0700341
Mady Mellore8608912015-06-05 09:02:55 -0700342 // Vibrator pattern for haptic feedback of a context click.
343 long[] mContextClickVibePattern;
Mady Mellore82067b2015-04-30 09:58:35 -0700344
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800345 /** If true, hitting shift & menu will broadcast Intent.ACTION_BUG_REPORT */
346 boolean mEnableShiftMenuBugReports = false;
Mike Lockwoodd747dc82011-09-13 16:28:22 -0400347
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800348 boolean mSafeMode;
349 WindowState mStatusBar = null;
Dianne Hackborn69cb8752011-05-19 18:13:32 -0700350 int mStatusBarHeight;
Daniel Sandler8956dbb2011-04-22 07:55:02 -0400351 WindowState mNavigationBar = null;
Daniel Sandler36412a72011-08-04 09:35:13 -0400352 boolean mHasNavigationBar = false;
Dianne Hackbornf87d1962012-04-04 12:48:24 -0700353 boolean mCanHideNavigationBar = false;
Daniel Sandler4a066c52012-04-20 14:49:13 -0400354 boolean mNavigationBarCanMove = false; // can the navigation bar ever move to the side?
355 boolean mNavigationBarOnBottom = true; // is the navigation bar on the bottom *right now*?
Sriram Viswanathan9ebbe6a2015-11-16 17:59:22 -0800356 int[] mNavigationBarHeightForRotationDefault = new int[4];
357 int[] mNavigationBarWidthForRotationDefault = new int[4];
358 int[] mNavigationBarHeightForRotationInCarMode = new int[4];
359 int[] mNavigationBarWidthForRotationInCarMode = new int[4];
Daniel Sandler8956dbb2011-04-22 07:55:02 -0400360
Muyuan Li94ce94e2016-02-24 16:20:54 -0800361 private LongSparseArray<IShortcutService> mShortcutKeyServices = new LongSparseArray<>();
362
keunyounga7710492015-09-23 11:33:58 -0700363 // Whether to allow dock apps with METADATA_DOCK_HOME to temporarily take over the Home key.
364 // This is for car dock and this is updated from resource.
365 private boolean mEnableCarDockHomeCapture = true;
366
Craig Mautnera631d492014-08-05 15:16:01 -0700367 boolean mBootMessageNeedsHiding;
Jim Miller5ecd8112013-01-09 18:50:26 -0800368 KeyguardServiceDelegate mKeyguardDelegate;
Craig Mautner13f6ea72014-06-23 14:57:02 -0700369 final Runnable mWindowManagerDrawCallback = new Runnable() {
Craig Mautner8a0da012014-05-31 15:13:37 -0700370 @Override
Craig Mautner13f6ea72014-06-23 14:57:02 -0700371 public void run() {
Craig Mautner8a0da012014-05-31 15:13:37 -0700372 if (DEBUG_WAKEUP) Slog.i(TAG, "All windows ready for display!");
373 mHandler.sendEmptyMessage(MSG_WINDOW_MANAGER_DRAWN_COMPLETE);
374 }
375 };
Jorim Jaggi4cfdcf52015-07-09 12:13:59 -0700376 final DrawnListener mKeyguardDrawnCallback = new DrawnListener() {
Craig Mautner8a0da012014-05-31 15:13:37 -0700377 @Override
Jorim Jaggi4cfdcf52015-07-09 12:13:59 -0700378 public void onDrawn() {
379 if (DEBUG_WAKEUP) Slog.d(TAG, "mKeyguardDelegate.ShowListener.onDrawn.");
Craig Mautner8a0da012014-05-31 15:13:37 -0700380 mHandler.sendEmptyMessage(MSG_KEYGUARD_DRAWN_COMPLETE);
381 }
382 };
383
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800384 GlobalActions mGlobalActions;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800385 Handler mHandler;
satok1bc0a492012-04-25 22:47:12 +0900386 WindowState mLastInputMethodWindow = null;
387 WindowState mLastInputMethodTargetWindow = null;
Jeff Brown4aed78b2011-01-14 17:36:55 -0800388
Jeff Brown13f00f02014-10-31 14:45:50 -0700389 // FIXME This state is shared between the input reader and handler thread.
390 // Technically it's broken and buggy but it has been like this for many years
391 // and we have not yet seen any problems. Someday we'll rewrite this logic
392 // so that only one thread is involved in handling input policy. Unfortunately
393 // it's on a critical path for power management so we can't just post the work to the
394 // handler thread. We'll need to resolve this someday by teaching the input dispatcher
395 // to hold wakelocks during dispatch and eliminating the critical path.
396 volatile boolean mPowerKeyHandled;
Anthony Hugh34f09ca2016-03-04 12:03:37 -0800397 volatile boolean mBackKeyHandled;
Bryce Leed9268e32014-11-17 17:40:59 -0800398 volatile boolean mBeganFromNonInteractive;
Jeff Brown13f00f02014-10-31 14:45:50 -0700399 volatile int mPowerKeyPressCounter;
400 volatile boolean mEndCallKeyHandled;
401
Winson Chungd42a6cf2014-06-03 16:24:04 -0700402 boolean mRecentsVisible;
Winson Chung1e8d71b2014-05-16 17:05:22 -0700403 int mRecentAppsHeldModifiers;
Jeff Browncf39bdf2012-05-18 14:41:19 -0700404 boolean mLanguageSwitchKeyPressed;
Jeff Brown68b909d2011-12-07 16:36:01 -0800405
Jeff Brown2e7760e2012-04-11 15:14:55 -0700406 int mLidState = LID_ABSENT;
Michael Wright3818c922014-09-02 13:59:07 -0700407 int mCameraLensCoverState = CAMERA_LENS_COVER_ABSENT;
Jeff Browndaa37532012-05-01 15:54:03 -0700408 boolean mHaveBuiltInKeyboard;
Jeff Brown4aed78b2011-01-14 17:36:55 -0800409
Dianne Hackbornc777e072010-02-12 13:07:59 -0800410 boolean mSystemReady;
Dianne Hackbornba24e4d2011-09-01 11:17:06 -0700411 boolean mSystemBooted;
Adrian Roos3542f7d2015-07-13 15:57:53 -0700412 private boolean mDeferBindKeyguard;
Dianne Hackbornad7fa7f2011-01-07 14:06:50 -0800413 boolean mHdmiPlugged;
Jinsuk Kime601b712015-07-07 08:01:02 +0900414 HdmiControl mHdmiControl;
Jeff Brown4f5fa282014-06-12 19:19:15 -0700415 IUiModeManager mUiModeManager;
Daniel Sandler6396c722013-04-16 20:19:09 -0400416 int mUiMode;
Dianne Hackborn867ab6472010-04-29 13:28:56 -0700417 int mDockMode = Intent.EXTRA_DOCK_STATE_UNDOCKED;
Mike Lockwood1753f7f2009-08-24 14:49:07 -0700418 int mLidOpenRotation;
Mike Lockwood2d1efbd2009-09-16 12:15:53 -0400419 int mCarDockRotation;
420 int mDeskDockRotation;
Jeff Brownc82c89ed2013-04-17 17:18:15 -0700421 int mUndockedHdmiRotation;
422 int mDemoHdmiRotation;
423 boolean mDemoHdmiRotationLock;
Chong Zhangae6119ff2014-11-11 18:54:39 -0800424 int mDemoRotation;
425 boolean mDemoRotationLock;
Daniel Sandlerb73617d2010-08-17 00:41:00 -0400426
Jeff Browna20dda42014-05-27 20:57:24 -0700427 boolean mWakeGestureEnabledSetting;
428 MyWakeGestureListener mWakeGestureListener;
429
Craig Mautner46ac6fa2013-08-01 10:06:34 -0700430 // Default display does not rotate, apps that require non-default orientation will have to
431 // have the orientation emulated.
432 private boolean mForceDefaultOrientation = false;
433
Daniel Sandlerb73617d2010-08-17 00:41:00 -0400434 int mUserRotationMode = WindowManagerPolicy.USER_ROTATION_FREE;
435 int mUserRotation = Surface.ROTATION_0;
Jeff Brown207673cd2012-06-05 17:47:11 -0700436 boolean mAccelerometerDefault;
Daniel Sandlerb73617d2010-08-17 00:41:00 -0400437
Jeff Brownbcdfc622014-03-06 19:13:04 -0800438 boolean mSupportAutoRotation;
Jeff Brownd3187e32011-09-21 19:26:44 -0700439 int mAllowAllRotations = -1;
Mike Lockwoode9867d22009-09-20 01:59:02 -0400440 boolean mCarDockEnablesAccelerometer;
441 boolean mDeskDockEnablesAccelerometer;
Dianne Hackborn2862fff2009-09-15 22:56:29 -0700442 int mLidKeyboardAccessibility;
443 int mLidNavigationAccessibility;
Edward Savage-Jones7def60d2015-11-13 13:27:03 +0100444 boolean mLidControlsScreenLock;
Jeff Brownc458ce92012-04-30 14:58:40 -0700445 boolean mLidControlsSleep;
Jeff Brown13f00f02014-10-31 14:45:50 -0700446 int mShortPressOnPowerBehavior;
447 int mLongPressOnPowerBehavior;
448 int mDoublePressOnPowerBehavior;
449 int mTriplePressOnPowerBehavior;
Anthony Hugh34f09ca2016-03-04 12:03:37 -0800450 int mLongPressOnBackBehavior;
Filip Gruszczynskia483a1d2015-03-17 19:06:58 +0000451 int mShortPressOnSleepBehavior;
Jaewan Kim49117872016-01-19 17:24:08 +0900452 int mShortPressWindowBehavior;
Jeff Brown3ee549c2014-09-22 20:14:39 -0700453 boolean mAwake;
454 boolean mScreenOnEarly;
455 boolean mScreenOnFully;
456 ScreenOnListener mScreenOnListener;
457 boolean mKeyguardDrawComplete;
458 boolean mWindowManagerDrawComplete;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800459 boolean mOrientationSensorEnabled = false;
460 int mCurrentAppOrientation = ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800461 boolean mHasSoftInput = false;
Daniel Sandlerdd73ee42013-10-11 22:19:59 -0400462 boolean mTranslucentDecorEnabled = true;
RoboErik001c59c2015-01-26 15:53:51 -0800463 boolean mUseTvRouting;
Craig Mautner967212c2013-04-13 21:10:58 -0700464
Jeff Brown70825162012-03-28 17:27:48 -0700465 int mPointerLocationMode = 0; // guarded by mLock
Joe Onorato664644d2011-01-23 17:53:23 -0800466
467 // The last window we were told about in focusChanged.
468 WindowState mFocusedWindow;
Dianne Hackborne0f085d2011-11-30 18:41:15 -0800469 IApplicationToken mFocusedApp;
Joe Onorato664644d2011-01-23 17:53:23 -0800470
Jeff Brown70825162012-03-28 17:27:48 -0700471 PointerLocationView mPointerLocationView;
Jeff Brown32cbc38552011-12-01 14:01:49 -0800472
Dianne Hackbornc652de82013-02-15 16:32:56 -0800473 // The current size of the screen; really; extends into the overscan area of
474 // the screen and doesn't account for any system elements like the status bar.
475 int mOverscanScreenLeft, mOverscanScreenTop;
476 int mOverscanScreenWidth, mOverscanScreenHeight;
477 // The current visible size of the screen; really; (ir)regardless of whether the status
478 // bar can be hidden but not extending into the overscan area.
Joe Onorato29fc2c92010-11-24 10:26:50 -0800479 int mUnrestrictedScreenLeft, mUnrestrictedScreenTop;
480 int mUnrestrictedScreenWidth, mUnrestrictedScreenHeight;
Dianne Hackborn313440842013-02-19 19:22:59 -0800481 // Like mOverscanScreen*, but allowed to move into the overscan region where appropriate.
482 int mRestrictedOverscanScreenLeft, mRestrictedOverscanScreenTop;
483 int mRestrictedOverscanScreenWidth, mRestrictedOverscanScreenHeight;
Dianne Hackborn82de1ae2010-10-28 11:28:39 -0700484 // The current size of the screen; these may be different than (0,0)-(dw,dh)
485 // if the status bar can't be hidden; in that case it effectively carves out
486 // that area of the display from all other windows.
Joe Onorato29fc2c92010-11-24 10:26:50 -0800487 int mRestrictedScreenLeft, mRestrictedScreenTop;
488 int mRestrictedScreenWidth, mRestrictedScreenHeight;
Dianne Hackborn5c58de32012-04-28 19:52:37 -0700489 // During layout, the current screen borders accounting for any currently
490 // visible system UI elements.
491 int mSystemLeft, mSystemTop, mSystemRight, mSystemBottom;
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -0700492 // For applications requesting stable content insets, these are them.
493 int mStableLeft, mStableTop, mStableRight, mStableBottom;
Dianne Hackborn5b5cc4d2012-05-16 13:15:00 -0700494 // For applications requesting stable content insets but have also set the
495 // fullscreen window flag, these are the stable dimensions without the status bar.
496 int mStableFullscreenLeft, mStableFullscreenTop;
497 int mStableFullscreenRight, mStableFullscreenBottom;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800498 // During layout, the current screen borders with all outer decoration
499 // (status bar, input method dock) accounted for.
500 int mCurLeft, mCurTop, mCurRight, mCurBottom;
501 // During layout, the frame in which content should be displayed
502 // to the user, accounting for all screen decoration except for any
503 // space they deem as available for other content. This is usually
504 // the same as mCur*, but may be larger if the screen decor has supplied
505 // content insets.
506 int mContentLeft, mContentTop, mContentRight, mContentBottom;
Dianne Hackborne30e02f2014-05-27 18:24:45 -0700507 // During layout, the frame in which voice content should be displayed
508 // to the user, accounting for all screen decoration except for any
509 // space they deem as available for other content.
510 int mVoiceContentLeft, mVoiceContentTop, mVoiceContentRight, mVoiceContentBottom;
Dianne Hackborn8e11ef02010-11-18 19:47:42 -0800511 // During layout, the current screen borders along which input method
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800512 // windows are placed.
513 int mDockLeft, mDockTop, mDockRight, mDockBottom;
514 // During layout, the layer at which the doc window is placed.
515 int mDockLayer;
Dianne Hackborn5c58de32012-04-28 19:52:37 -0700516 // During layout, this is the layer of the status bar.
517 int mStatusBarLayer;
Dianne Hackborne26ab702011-10-16 13:21:33 -0700518 int mLastSystemUiFlags;
519 // Bits that we are in the process of clearing, so we want to prevent
520 // them from being set by applications until everything has been updated
521 // to have them clear.
522 int mResettingSystemUiFlags = 0;
523 // Bits that we are currently always keeping cleared.
524 int mForceClearedSystemUiFlags = 0;
Jorim Jaggi86905582016-02-09 21:36:09 -0800525 int mLastFullscreenStackSysUiFlags;
526 int mLastDockedStackSysUiFlags;
527 final Rect mNonDockedStackBounds = new Rect();
528 final Rect mDockedStackBounds = new Rect();
529 final Rect mLastNonDockedStackBounds = new Rect();
530 final Rect mLastDockedStackBounds = new Rect();
531
Dianne Hackborn4eff8d32011-11-10 19:38:40 -0800532 // What we last reported to system UI about whether the compatibility
533 // menu needs to be displayed.
534 boolean mLastFocusNeedsMenu = false;
Adrian Roosddc8b272015-05-21 16:28:27 -0700535 // If nonzero, a panic gesture was performed at that time in uptime millis and is still pending.
536 private long mPendingPanicGestureUptime;
Dianne Hackborndf89e652011-10-06 22:35:11 -0700537
Selim Cinekf83e8242015-05-19 18:08:14 -0700538 InputConsumer mInputConsumer = null;
Dianne Hackborndf89e652011-10-06 22:35:11 -0700539
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800540 static final Rect mTmpParentFrame = new Rect();
541 static final Rect mTmpDisplayFrame = new Rect();
Dianne Hackbornc4aad012013-02-22 15:05:25 -0800542 static final Rect mTmpOverscanFrame = new Rect();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800543 static final Rect mTmpContentFrame = new Rect();
544 static final Rect mTmpVisibleFrame = new Rect();
John Spurlock46646232013-09-30 22:32:42 -0400545 static final Rect mTmpDecorFrame = new Rect();
Adrian Roosfa104232014-06-20 16:10:14 -0700546 static final Rect mTmpStableFrame = new Rect();
Dianne Hackborn1f903c32011-09-13 19:18:06 -0700547 static final Rect mTmpNavigationFrame = new Rect();
Filip Gruszczynski2217f612015-05-26 11:32:08 -0700548 static final Rect mTmpOutsetFrame = new Rect();
Craig Mautner967212c2013-04-13 21:10:58 -0700549
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800550 WindowState mTopFullscreenOpaqueWindowState;
Adrian Rooscd3884d2015-02-18 17:25:23 +0100551 WindowState mTopFullscreenOpaqueOrDimmingWindowState;
Jorim Jaggi86905582016-02-09 21:36:09 -0800552 WindowState mTopDockedOpaqueWindowState;
553 WindowState mTopDockedOpaqueOrDimmingWindowState;
Craig Mautner2bc789b2014-03-19 19:48:38 -0700554 HashSet<IApplicationToken> mAppsToBeHidden = new HashSet<IApplicationToken>();
Jorim Jaggic13fcac2014-09-11 17:36:57 +0200555 HashSet<IApplicationToken> mAppsThatDismissKeyguard = new HashSet<IApplicationToken>();
Joe Onorato93056472010-09-10 10:30:46 -0400556 boolean mTopIsFullscreen;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800557 boolean mForceStatusBar;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -0700558 boolean mForceStatusBarFromKeyguard;
Selim Cinek4a4a2bddc2015-05-07 12:50:19 -0700559 private boolean mForceStatusBarTransparent;
Yorke Lee9b2ffb32016-03-07 20:42:01 -0800560 int mNavBarOpacityMode = NAV_BAR_OPAQUE_WHEN_FREEFORM_OR_DOCKED;
Dianne Hackborn39c2d712009-09-22 11:41:31 -0700561 boolean mHideLockScreen;
Dianne Hackborn891d3fb2013-01-09 18:31:37 -0800562 boolean mForcingShowNavBar;
563 int mForcingShowNavBarLayer;
Craig Mautnerad09bcc2012-10-08 13:33:11 -0700564
565 // States of keyguard dismiss.
566 private static final int DISMISS_KEYGUARD_NONE = 0; // Keyguard not being dismissed.
567 private static final int DISMISS_KEYGUARD_START = 1; // Keyguard needs to be dismissed.
568 private static final int DISMISS_KEYGUARD_CONTINUE = 2; // Keyguard has been dismissed.
569 int mDismissKeyguard = DISMISS_KEYGUARD_NONE;
570
571 /** The window that is currently dismissing the keyguard. Dismissing the keyguard must only
572 * be done once per window. */
573 private WindowState mWinDismissingKeyguard;
574
tingna_sunge785ffa2015-05-12 13:23:15 +0800575 /** When window is currently dismissing the keyguard, dismissing the keyguard must handle
576 * the keygaurd secure state change instantly case, e.g. the use case of inserting a PIN
577 * lock SIM card. This variable is used to record the previous keyguard secure state for
578 * monitoring secure state change on window dismissing keyguard. */
579 private boolean mSecureDismissingKeyguard;
580
Craig Mautnerc9457fa2014-06-06 14:27:48 -0700581 /** The window that is currently showing "over" the keyguard. If there is an app window
582 * belonging to another app on top of this the keyguard shows. If there is a fullscreen
583 * app window under this, still dismiss the keyguard but don't show the app underneath. Show
584 * the wallpaper. */
585 private WindowState mWinShowWhenLocked;
586
Dianne Hackborn7ad44382012-10-18 17:46:00 -0700587 boolean mShowingLockscreen;
588 boolean mShowingDream;
589 boolean mDreamingLockscreen;
Jeff Brown061ea992015-04-17 19:55:47 -0700590 boolean mDreamingSleepTokenNeeded;
591 SleepToken mDreamingSleepToken;
Jeff Brown48d1b142015-06-10 16:36:03 -0700592 SleepToken mScreenOffSleepToken;
Jim Millerab954542014-10-10 18:21:49 -0700593 boolean mKeyguardSecure;
594 boolean mKeyguardSecureIncludingHidden;
595 volatile boolean mKeyguardOccluded;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800596 boolean mHomePressed;
Jeff Browncaca8812013-05-09 13:34:33 -0700597 boolean mHomeConsumed;
598 boolean mHomeDoubleTapPending;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800599 Intent mHomeIntent;
Dianne Hackborn39c2d712009-09-22 11:41:31 -0700600 Intent mCarDockIntent;
601 Intent mDeskDockIntent;
Jeff Brownfd23e3e2012-05-09 13:34:28 -0700602 boolean mSearchKeyShortcutPending;
603 boolean mConsumeSearchKeyUp;
Jeff Brownde7a8ea2012-06-13 18:28:57 -0700604 boolean mAssistKeyLongPressed;
Michael Wright6a62e552014-06-03 19:19:48 -0700605 boolean mPendingMetaAction;
Jorim Jaggi0ffd49c2016-02-12 15:04:21 -0800606 boolean mForceShowSystemBars;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800607
Mike Lockwood28569302010-01-28 11:54:40 -0500608 // support for activating the lock screen while the screen is on
609 boolean mAllowLockscreenWhenOn;
610 int mLockScreenTimeout;
611 boolean mLockScreenTimerActive;
612
David Brownbaf8d092010-03-08 21:52:59 -0800613 // Behavior of ENDCALL Button. (See Settings.System.END_BUTTON_BEHAVIOR.)
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800614 int mEndcallBehavior;
David Brownbaf8d092010-03-08 21:52:59 -0800615
616 // Behavior of POWER button while in-call and screen on.
617 // (See Settings.Secure.INCALL_POWER_BUTTON_BEHAVIOR.)
618 int mIncallPowerBehavior;
619
Dianne Hackbornf87d1962012-04-04 12:48:24 -0700620 Display mDisplay;
621
Filip Gruszczynski2987f612015-06-30 15:03:30 -0700622 private int mDisplayRotation;
623
Dianne Hackborn9d132642011-04-21 17:26:39 -0700624 int mLandscapeRotation = 0; // default landscape rotation
625 int mSeascapeRotation = 0; // "other" landscape rotation, 180 degrees from mLandscapeRotation
626 int mPortraitRotation = 0; // default portrait rotation
627 int mUpsideDownRotation = 0; // "other" portrait rotation
Mitsuru Oshima831d0d92009-06-16 18:27:18 -0700628
Dianne Hackbornc652de82013-02-15 16:32:56 -0800629 int mOverscanLeft = 0;
630 int mOverscanTop = 0;
631 int mOverscanRight = 0;
632 int mOverscanBottom = 0;
633
Joe Onorato46b0d682010-11-22 17:37:27 -0800634 // What we do when the user long presses on home
Jeff Browncaca8812013-05-09 13:34:33 -0700635 private int mLongPressOnHomeBehavior;
636
637 // What we do when the user double-taps on home
638 private int mDoubleTapOnHomeBehavior;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800639
Bryce Lee584a4452014-10-21 15:55:55 -0700640 // Allowed theater mode wake actions
641 private boolean mAllowTheaterModeWakeFromKey;
642 private boolean mAllowTheaterModeWakeFromPowerKey;
643 private boolean mAllowTheaterModeWakeFromMotion;
Bryce Lee812d7022014-11-10 13:33:28 -0800644 private boolean mAllowTheaterModeWakeFromMotionWhenNotDreaming;
Bryce Lee584a4452014-10-21 15:55:55 -0700645 private boolean mAllowTheaterModeWakeFromCameraLens;
646 private boolean mAllowTheaterModeWakeFromLidSwitch;
647 private boolean mAllowTheaterModeWakeFromWakeGesture;
648
Bryce Leed3b28402015-03-09 15:49:13 +0000649 // Whether to support long press from power button in non-interactive mode
650 private boolean mSupportLongPressPowerWhenNonInteractive;
651
Bryce Lee55e846d2014-11-04 12:43:44 -0800652 // Whether to go to sleep entering theater mode from power button
653 private boolean mGoToSleepOnButtonPressTheaterMode;
654
Winson Chung9112ec32011-06-27 13:15:32 -0700655 // Screenshot trigger states
Jeff Brownd5bb82d2011-10-12 13:57:59 -0700656 // Time to volume and power must be pressed within this interval of each other.
657 private static final long SCREENSHOT_CHORD_DEBOUNCE_DELAY_MILLIS = 150;
Winson Chung1cea2f32012-10-08 20:42:01 -0700658 // Increase the chord delay when taking a screenshot from the keyguard
659 private static final float KEYGUARD_SCREENSHOT_CHORD_DELAY_MULTIPLIER = 2.5f;
Christopher Tatee90585f2012-03-05 18:56:25 -0800660 private boolean mScreenshotChordEnabled;
Jeff Brown13f00f02014-10-31 14:45:50 -0700661 private boolean mScreenshotChordVolumeDownKeyTriggered;
662 private long mScreenshotChordVolumeDownKeyTime;
663 private boolean mScreenshotChordVolumeDownKeyConsumed;
664 private boolean mScreenshotChordVolumeUpKeyTriggered;
665 private boolean mScreenshotChordPowerKeyTriggered;
666 private long mScreenshotChordPowerKeyTime;
Winson Chung9112ec32011-06-27 13:15:32 -0700667
Michael Wrightb854e242013-02-05 17:54:02 -0800668 /* The number of steps between min and max brightness */
669 private static final int BRIGHTNESS_STEPS = 10;
670
Christopher Tate5e08af02012-09-21 17:17:22 -0700671 SettingsObserver mSettingsObserver;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800672 ShortcutManager mShortcutManager;
673 PowerManager.WakeLock mBroadcastWakeLock;
Jeff Brown13f00f02014-10-31 14:45:50 -0700674 PowerManager.WakeLock mPowerKeyWakeLock;
Jeff Brown40013652012-05-16 21:22:36 -0700675 boolean mHavePendingMediaKeyRepeatWithWakeLock;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800676
Craig Mautnerd625ab22013-09-06 13:40:31 -0700677 private int mCurrentUserId;
678
Justin Kohd378ad72013-04-01 12:18:26 -0700679 // Maps global key codes to the components that will handle them.
680 private GlobalKeyManager mGlobalKeyManager;
681
Jeff Brownfd23e3e2012-05-09 13:34:28 -0700682 // Fallback actions by key code.
683 private final SparseArray<KeyCharacterMap.FallbackAction> mFallbackActions =
684 new SparseArray<KeyCharacterMap.FallbackAction>();
Jeff Brown49ed71d2010-12-06 17:13:33 -0800685
Jorim Jaggi76a16232014-08-08 17:00:47 +0200686 private final LogDecelerateInterpolator mLogDecelerateInterpolator
687 = new LogDecelerateInterpolator(100, 0);
688
Jorim Jaggi4fa78922015-11-30 17:13:56 -0800689 private boolean mForceWindowDrawsStatusBarBackground;
690
Jeff Brown70825162012-03-28 17:27:48 -0700691 private static final int MSG_ENABLE_POINTER_LOCATION = 1;
692 private static final int MSG_DISABLE_POINTER_LOCATION = 2;
Jeff Brown40013652012-05-16 21:22:36 -0700693 private static final int MSG_DISPATCH_MEDIA_KEY_WITH_WAKE_LOCK = 3;
694 private static final int MSG_DISPATCH_MEDIA_KEY_REPEAT_WITH_WAKE_LOCK = 4;
Craig Mautner8a0da012014-05-31 15:13:37 -0700695 private static final int MSG_KEYGUARD_DRAWN_COMPLETE = 5;
696 private static final int MSG_KEYGUARD_DRAWN_TIMEOUT = 6;
697 private static final int MSG_WINDOW_MANAGER_DRAWN_COMPLETE = 7;
Craig Mautner84984fa2014-06-19 11:19:20 -0700698 private static final int MSG_DISPATCH_SHOW_RECENTS = 9;
Alan Viverettee34560b22014-07-10 14:50:06 -0700699 private static final int MSG_DISPATCH_SHOW_GLOBAL_ACTIONS = 10;
Craig Mautnera631d492014-08-05 15:16:01 -0700700 private static final int MSG_HIDE_BOOT_MESSAGE = 11;
Michael Wright869a67c2014-08-26 19:33:06 -0700701 private static final int MSG_LAUNCH_VOICE_ASSIST_WITH_WAKE_LOCK = 12;
Jeff Brown13f00f02014-10-31 14:45:50 -0700702 private static final int MSG_POWER_DELAYED_PRESS = 13;
703 private static final int MSG_POWER_LONG_PRESS = 14;
Jeff Brown061ea992015-04-17 19:55:47 -0700704 private static final int MSG_UPDATE_DREAMING_SLEEP_TOKEN = 15;
Jun Mukaid2e7e352015-07-22 17:14:02 -0700705 private static final int MSG_REQUEST_TRANSIENT_BARS = 16;
Jaewan Kimc552b042016-01-18 16:08:45 +0900706 private static final int MSG_REQUEST_TV_PICTURE_IN_PICTURE = 17;
Anthony Hugh34f09ca2016-03-04 12:03:37 -0800707 private static final int MSG_BACK_LONG_PRESS = 18;
Jun Mukaid2e7e352015-07-22 17:14:02 -0700708
709 private static final int MSG_REQUEST_TRANSIENT_BARS_ARG_STATUS = 0;
710 private static final int MSG_REQUEST_TRANSIENT_BARS_ARG_NAVIGATION = 1;
Jeff Brown70825162012-03-28 17:27:48 -0700711
712 private class PolicyHandler extends Handler {
713 @Override
714 public void handleMessage(Message msg) {
715 switch (msg.what) {
716 case MSG_ENABLE_POINTER_LOCATION:
717 enablePointerLocation();
718 break;
719 case MSG_DISABLE_POINTER_LOCATION:
720 disablePointerLocation();
721 break;
Jeff Brown40013652012-05-16 21:22:36 -0700722 case MSG_DISPATCH_MEDIA_KEY_WITH_WAKE_LOCK:
723 dispatchMediaKeyWithWakeLock((KeyEvent)msg.obj);
724 break;
725 case MSG_DISPATCH_MEDIA_KEY_REPEAT_WITH_WAKE_LOCK:
726 dispatchMediaKeyRepeatWithWakeLock((KeyEvent)msg.obj);
727 break;
Craig Mautner84984fa2014-06-19 11:19:20 -0700728 case MSG_DISPATCH_SHOW_RECENTS:
729 showRecentApps(false);
730 break;
Alan Viverettee34560b22014-07-10 14:50:06 -0700731 case MSG_DISPATCH_SHOW_GLOBAL_ACTIONS:
732 showGlobalActionsInternal();
733 break;
Craig Mautner8a0da012014-05-31 15:13:37 -0700734 case MSG_KEYGUARD_DRAWN_COMPLETE:
735 if (DEBUG_WAKEUP) Slog.w(TAG, "Setting mKeyguardDrawComplete");
Jeff Brown36c4db82014-09-19 12:05:31 -0700736 finishKeyguardDrawn();
Craig Mautner8a0da012014-05-31 15:13:37 -0700737 break;
738 case MSG_KEYGUARD_DRAWN_TIMEOUT:
739 Slog.w(TAG, "Keyguard drawn timeout. Setting mKeyguardDrawComplete");
Jeff Brown36c4db82014-09-19 12:05:31 -0700740 finishKeyguardDrawn();
Craig Mautner8a0da012014-05-31 15:13:37 -0700741 break;
742 case MSG_WINDOW_MANAGER_DRAWN_COMPLETE:
743 if (DEBUG_WAKEUP) Slog.w(TAG, "Setting mWindowManagerDrawComplete");
Jeff Brown36c4db82014-09-19 12:05:31 -0700744 finishWindowsDrawn();
Craig Mautner8a0da012014-05-31 15:13:37 -0700745 break;
Craig Mautnera631d492014-08-05 15:16:01 -0700746 case MSG_HIDE_BOOT_MESSAGE:
747 handleHideBootMessage();
748 break;
Michael Wright869a67c2014-08-26 19:33:06 -0700749 case MSG_LAUNCH_VOICE_ASSIST_WITH_WAKE_LOCK:
750 launchVoiceAssistWithWakeLock(msg.arg1 != 0);
751 break;
Jeff Brown13f00f02014-10-31 14:45:50 -0700752 case MSG_POWER_DELAYED_PRESS:
753 powerPress((Long)msg.obj, msg.arg1 != 0, msg.arg2);
754 finishPowerKeyPress();
755 break;
756 case MSG_POWER_LONG_PRESS:
757 powerLongPress();
758 break;
Jeff Brown061ea992015-04-17 19:55:47 -0700759 case MSG_UPDATE_DREAMING_SLEEP_TOKEN:
760 updateDreamingSleepToken(msg.arg1 != 0);
761 break;
Jun Mukaid2e7e352015-07-22 17:14:02 -0700762 case MSG_REQUEST_TRANSIENT_BARS:
763 WindowState targetBar = (msg.arg1 == MSG_REQUEST_TRANSIENT_BARS_ARG_STATUS) ?
764 mStatusBar : mNavigationBar;
765 if (targetBar != null) {
766 requestTransientBars(targetBar);
767 }
768 break;
Jaewan Kimc552b042016-01-18 16:08:45 +0900769 case MSG_REQUEST_TV_PICTURE_IN_PICTURE:
770 requestTvPictureInPictureInternal();
771 break;
Anthony Hugh34f09ca2016-03-04 12:03:37 -0800772 case MSG_BACK_LONG_PRESS:
773 backLongPress();
774 break;
Jeff Brown70825162012-03-28 17:27:48 -0700775 }
776 }
777 }
778
Dianne Hackbornad7fa7f2011-01-07 14:06:50 -0800779 private UEventObserver mHDMIObserver = new UEventObserver() {
780 @Override
781 public void onUEvent(UEventObserver.UEvent event) {
782 setHdmiPlugged("1".equals(event.get("SWITCH_STATE")));
783 }
784 };
785
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800786 class SettingsObserver extends ContentObserver {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800787 SettingsObserver(Handler handler) {
788 super(handler);
789 }
David Brownbaf8d092010-03-08 21:52:59 -0800790
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800791 void observe() {
Christopher Tate5e08af02012-09-21 17:17:22 -0700792 // Observe all users' changes
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800793 ContentResolver resolver = mContext.getContentResolver();
794 resolver.registerContentObserver(Settings.System.getUriFor(
Christopher Tate5e08af02012-09-21 17:17:22 -0700795 Settings.System.END_BUTTON_BEHAVIOR), false, this,
796 UserHandle.USER_ALL);
David Brownbaf8d092010-03-08 21:52:59 -0800797 resolver.registerContentObserver(Settings.Secure.getUriFor(
Christopher Tate5e08af02012-09-21 17:17:22 -0700798 Settings.Secure.INCALL_POWER_BUTTON_BEHAVIOR), false, this,
799 UserHandle.USER_ALL);
Jeff Browna20dda42014-05-27 20:57:24 -0700800 resolver.registerContentObserver(Settings.Secure.getUriFor(
801 Settings.Secure.WAKE_GESTURE_ENABLED), false, this,
802 UserHandle.USER_ALL);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800803 resolver.registerContentObserver(Settings.System.getUriFor(
Christopher Tate5e08af02012-09-21 17:17:22 -0700804 Settings.System.ACCELEROMETER_ROTATION), false, this,
805 UserHandle.USER_ALL);
Mike Lockwood28569302010-01-28 11:54:40 -0500806 resolver.registerContentObserver(Settings.System.getUriFor(
Christopher Tate5e08af02012-09-21 17:17:22 -0700807 Settings.System.USER_ROTATION), false, this,
808 UserHandle.USER_ALL);
Daniel Sandlerb73617d2010-08-17 00:41:00 -0400809 resolver.registerContentObserver(Settings.System.getUriFor(
Christopher Tate5e08af02012-09-21 17:17:22 -0700810 Settings.System.SCREEN_OFF_TIMEOUT), false, this,
811 UserHandle.USER_ALL);
Dianne Hackbornc777e072010-02-12 13:07:59 -0800812 resolver.registerContentObserver(Settings.System.getUriFor(
Christopher Tate5e08af02012-09-21 17:17:22 -0700813 Settings.System.POINTER_LOCATION), false, this,
814 UserHandle.USER_ALL);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800815 resolver.registerContentObserver(Settings.Secure.getUriFor(
Christopher Tate5e08af02012-09-21 17:17:22 -0700816 Settings.Secure.DEFAULT_INPUT_METHOD), false, this,
817 UserHandle.USER_ALL);
John Spurlockd9b70bd2014-02-06 17:02:44 -0500818 resolver.registerContentObserver(Settings.Secure.getUriFor(
John Spurlockf1a36642013-10-12 17:50:42 -0400819 Settings.Secure.IMMERSIVE_MODE_CONFIRMATIONS), false, this,
Christopher Tate5e08af02012-09-21 17:17:22 -0700820 UserHandle.USER_ALL);
John Spurlockc6d1c602014-01-17 15:22:06 -0500821 resolver.registerContentObserver(Settings.Global.getUriFor(
822 Settings.Global.POLICY_CONTROL), false, this,
823 UserHandle.USER_ALL);
Dianne Hackbornc777e072010-02-12 13:07:59 -0800824 updateSettings();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800825 }
826
827 @Override public void onChange(boolean selfChange) {
Dianne Hackbornc777e072010-02-12 13:07:59 -0800828 updateSettings();
Jeff Brown01a98dd2011-09-20 15:08:29 -0700829 updateRotation(false);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800830 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800831 }
Craig Mautner967212c2013-04-13 21:10:58 -0700832
Jeff Browna20dda42014-05-27 20:57:24 -0700833 class MyWakeGestureListener extends WakeGestureListener {
834 MyWakeGestureListener(Context context, Handler handler) {
835 super(context, handler);
836 }
837
838 @Override
839 public void onWakeUp() {
840 synchronized (mLock) {
841 if (shouldEnableWakeGestureLp()) {
Jeff Browne07b94b2014-06-18 15:56:27 -0700842 performHapticFeedbackLw(null, HapticFeedbackConstants.VIRTUAL_KEY, false);
Dianne Hackborn280a64e2015-07-13 14:48:08 -0700843 wakeUp(SystemClock.uptimeMillis(), mAllowTheaterModeWakeFromWakeGesture,
844 "android.policy:GESTURE");
Jeff Browna20dda42014-05-27 20:57:24 -0700845 }
846 }
847 }
848 }
849
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800850 class MyOrientationListener extends WindowOrientationListener {
Chong Zhang5aaa0b32015-08-28 10:22:36 -0700851 private final Runnable mUpdateRotationRunnable = new Runnable() {
852 @Override
853 public void run() {
Tim Murray1f407642015-10-01 17:07:12 -0700854 // send interaction hint to improve redraw performance
855 mPowerManagerInternal.powerHint(PowerManagerInternal.POWER_HINT_INTERACTION, 0);
Chong Zhang5aaa0b32015-08-28 10:22:36 -0700856 updateRotation(false);
857 }
858 };
859
Craig Mautnereee29c42013-01-17 14:44:34 -0800860 MyOrientationListener(Context context, Handler handler) {
861 super(context, handler);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800862 }
Craig Mautner967212c2013-04-13 21:10:58 -0700863
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800864 @Override
Jeff Brownc0347aa2011-09-23 17:26:09 -0700865 public void onProposedRotationChanged(int rotation) {
Craig Mautnereda67292013-04-28 13:50:14 -0700866 if (localLOGV) Slog.v(TAG, "onProposedRotationChanged, rotation=" + rotation);
Chong Zhang5aaa0b32015-08-28 10:22:36 -0700867 mHandler.post(mUpdateRotationRunnable);
Jeff Brown01a98dd2011-09-20 15:08:29 -0700868 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800869 }
870 MyOrientationListener mOrientationListener;
871
Jorim Jaggi24bec7c2015-02-04 12:40:14 +0100872 private final StatusBarController mStatusBarController = new StatusBarController();
John Spurlock5b9145b2013-08-20 15:13:47 -0400873
John Spurlock27735a42013-08-14 17:57:38 -0400874 private final BarController mNavigationBarController = new BarController("NavigationBar",
John Spurlock5b9145b2013-08-20 15:13:47 -0400875 View.NAVIGATION_BAR_TRANSIENT,
876 View.NAVIGATION_BAR_UNHIDE,
John Spurlockbd957402013-10-03 11:38:39 -0400877 View.NAVIGATION_BAR_TRANSLUCENT,
878 StatusBarManager.WINDOW_NAVIGATION_BAR,
Jorim Jaggi4fa78922015-11-30 17:13:56 -0800879 WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION,
880 View.NAVIGATION_BAR_TRANSPARENT);
John Spurlock5b9145b2013-08-20 15:13:47 -0400881
John Spurlockf1a36642013-10-12 17:50:42 -0400882 private ImmersiveModeConfirmation mImmersiveModeConfirmation;
John Spurlock32beb2c2013-03-11 10:16:47 -0400883
Craig Mautner037aa8d2013-06-07 10:35:44 -0700884 private SystemGesturesPointerEventListener mSystemGestures;
John Spurlock32beb2c2013-03-11 10:16:47 -0400885
Dianne Hackborn42e620c2012-06-24 13:20:51 -0700886 IStatusBarService getStatusBarService() {
887 synchronized (mServiceAquireLock) {
888 if (mStatusBarService == null) {
889 mStatusBarService = IStatusBarService.Stub.asInterface(
890 ServiceManager.getService("statusbar"));
891 }
892 return mStatusBarService;
893 }
894 }
895
Jorim Jaggi86905582016-02-09 21:36:09 -0800896 StatusBarManagerInternal getStatusBarManagerInternal() {
897 synchronized (mServiceAquireLock) {
898 if (mStatusBarManagerInternal == null) {
899 mStatusBarManagerInternal =
900 LocalServices.getService(StatusBarManagerInternal.class);
901 }
902 return mStatusBarManagerInternal;
903 }
904 }
905
Suchi Amalapurapua9e1b162009-03-24 22:24:47 -0700906 /*
907 * We always let the sensor be switched on by default except when
908 * the user has explicitly disabled sensor based rotation or when the
909 * screen is switched off.
910 */
The Android Open Source Project0727d222009-03-11 12:11:58 -0700911 boolean needSensorRunningLp() {
Jeff Brownbcdfc622014-03-06 19:13:04 -0800912 if (mSupportAutoRotation) {
913 if (mCurrentAppOrientation == ActivityInfo.SCREEN_ORIENTATION_SENSOR
914 || mCurrentAppOrientation == ActivityInfo.SCREEN_ORIENTATION_FULL_SENSOR
915 || mCurrentAppOrientation == ActivityInfo.SCREEN_ORIENTATION_SENSOR_PORTRAIT
916 || mCurrentAppOrientation == ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE) {
917 // If the application has explicitly requested to follow the
918 // orientation, then we need to turn the sensor on.
919 return true;
920 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800921 }
Dianne Hackborn867ab6472010-04-29 13:28:56 -0700922 if ((mCarDockEnablesAccelerometer && mDockMode == Intent.EXTRA_DOCK_STATE_CAR) ||
Jeff Brown1a693182011-11-08 14:44:16 -0800923 (mDeskDockEnablesAccelerometer && (mDockMode == Intent.EXTRA_DOCK_STATE_DESK
924 || mDockMode == Intent.EXTRA_DOCK_STATE_LE_DESK
925 || mDockMode == Intent.EXTRA_DOCK_STATE_HE_DESK))) {
Mike Lockwoode9867d22009-09-20 01:59:02 -0400926 // enable accelerometer if we are docked in a dock that enables accelerometer
927 // orientation management,
928 return true;
929 }
Jeff Brown207673cd2012-06-05 17:47:11 -0700930 if (mUserRotationMode == USER_ROTATION_LOCKED) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800931 // If the setting for using the sensor by default is enabled, then
932 // we will always leave it on. Note that the user could go to
933 // a window that forces an orientation that does not use the
934 // sensor and in theory we could turn it off... however, when next
935 // turning it on we won't have a good value for the current
936 // orientation for a little bit, which can cause orientation
937 // changes to lag, so we'd like to keep it always on. (It will
938 // still be turned off when the screen is off.)
Suchi Amalapurapua9e1b162009-03-24 22:24:47 -0700939 return false;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800940 }
Jeff Brownbcdfc622014-03-06 19:13:04 -0800941 return mSupportAutoRotation;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800942 }
Craig Mautner46ac6fa2013-08-01 10:06:34 -0700943
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800944 /*
945 * Various use cases for invoking this function
946 * screen turning off, should always disable listeners if already enabled
Craig Mautner46ac6fa2013-08-01 10:06:34 -0700947 * screen turned on and current app has sensor based orientation, enable listeners
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800948 * if not already enabled
949 * screen turned on and current app does not have sensor orientation, disable listeners if
950 * already enabled
951 * screen turning on and current app has sensor based orientation, enable listeners if needed
952 * screen turning on and current app has nosensor based orientation, do nothing
953 */
The Android Open Source Project0727d222009-03-11 12:11:58 -0700954 void updateOrientationListenerLp() {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800955 if (!mOrientationListener.canDetectOrientation()) {
956 // If sensor is turned off or nonexistent for some reason
957 return;
958 }
Stefan Kuhne9326dc12015-06-12 09:25:32 -1000959 // Could have been invoked due to screen turning on or off or
960 // change of the currently visible window's orientation.
Jeff Brown3ee549c2014-09-22 20:14:39 -0700961 if (localLOGV) Slog.v(TAG, "mScreenOnEarly=" + mScreenOnEarly
962 + ", mAwake=" + mAwake + ", mCurrentAppOrientation=" + mCurrentAppOrientation
Stefan Kuhne9326dc12015-06-12 09:25:32 -1000963 + ", mOrientationSensorEnabled=" + mOrientationSensorEnabled
964 + ", mKeyguardDrawComplete=" + mKeyguardDrawComplete
965 + ", mWindowManagerDrawComplete=" + mWindowManagerDrawComplete);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800966 boolean disable = true;
Stefan Kuhne9326dc12015-06-12 09:25:32 -1000967 // Note: We postpone the rotating of the screen until the keyguard as well as the
968 // window manager have reported a draw complete.
969 if (mScreenOnEarly && mAwake &&
970 mKeyguardDrawComplete && mWindowManagerDrawComplete) {
The Android Open Source Project0727d222009-03-11 12:11:58 -0700971 if (needSensorRunningLp()) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800972 disable = false;
973 //enable listener if not already enabled
The Android Open Source Project0727d222009-03-11 12:11:58 -0700974 if (!mOrientationSensorEnabled) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800975 mOrientationListener.enable();
Craig Mautnereda67292013-04-28 13:50:14 -0700976 if(localLOGV) Slog.v(TAG, "Enabling listeners");
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800977 mOrientationSensorEnabled = true;
978 }
Craig Mautner46ac6fa2013-08-01 10:06:34 -0700979 }
980 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800981 //check if sensors need to be disabled
The Android Open Source Project0727d222009-03-11 12:11:58 -0700982 if (disable && mOrientationSensorEnabled) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800983 mOrientationListener.disable();
Craig Mautnereda67292013-04-28 13:50:14 -0700984 if(localLOGV) Slog.v(TAG, "Disabling listeners");
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800985 mOrientationSensorEnabled = false;
986 }
987 }
988
Jeff Brown13f00f02014-10-31 14:45:50 -0700989 private void interceptPowerKeyDown(KeyEvent event, boolean interactive) {
990 // Hold a wake lock until the power key is released.
991 if (!mPowerKeyWakeLock.isHeld()) {
992 mPowerKeyWakeLock.acquire();
993 }
994
995 // Cancel multi-press detection timeout.
996 if (mPowerKeyPressCounter != 0) {
997 mHandler.removeMessages(MSG_POWER_DELAYED_PRESS);
998 }
999
1000 // Detect user pressing the power button in panic when an application has
1001 // taken over the whole screen.
1002 boolean panic = mImmersiveModeConfirmation.onPowerKeyDown(interactive,
Craig Mautner0124980e92014-11-30 21:15:34 -08001003 SystemClock.elapsedRealtime(), isImmersiveMode(mLastSystemUiFlags));
Jeff Brown13f00f02014-10-31 14:45:50 -07001004 if (panic) {
Adrian Roosddc8b272015-05-21 16:28:27 -07001005 mHandler.post(mHiddenNavPanic);
Jeff Brown13f00f02014-10-31 14:45:50 -07001006 }
1007
1008 // Latch power key state to detect screenshot chord.
1009 if (interactive && !mScreenshotChordPowerKeyTriggered
1010 && (event.getFlags() & KeyEvent.FLAG_FALLBACK) == 0) {
1011 mScreenshotChordPowerKeyTriggered = true;
1012 mScreenshotChordPowerKeyTime = event.getDownTime();
1013 interceptScreenshotChord();
1014 }
1015
1016 // Stop ringing or end call if configured to do so when power is pressed.
1017 TelecomManager telecomManager = getTelecommService();
1018 boolean hungUp = false;
1019 if (telecomManager != null) {
1020 if (telecomManager.isRinging()) {
1021 // Pressing Power while there's a ringing incoming
1022 // call should silence the ringer.
1023 telecomManager.silenceRinger();
1024 } else if ((mIncallPowerBehavior
1025 & Settings.Secure.INCALL_POWER_BUTTON_BEHAVIOR_HANGUP) != 0
1026 && telecomManager.isInCall() && interactive) {
1027 // Otherwise, if "Power button ends call" is enabled,
1028 // the Power button will hang up any current active call.
1029 hungUp = telecomManager.endCall();
1030 }
1031 }
1032
Adrian Roos5941c982015-09-03 15:59:49 -07001033 GestureLauncherService gestureService = LocalServices.getService(
1034 GestureLauncherService.class);
1035 boolean gesturedServiceIntercepted = false;
1036 if (gestureService != null) {
1037 gesturedServiceIntercepted = gestureService.interceptPowerKeyDown(event, interactive);
1038 }
1039
Jeff Brown13f00f02014-10-31 14:45:50 -07001040 // If the power key has still not yet been handled, then detect short
1041 // press, long press, or multi press and decide what to do.
1042 mPowerKeyHandled = hungUp || mScreenshotChordVolumeDownKeyTriggered
Adrian Roos5941c982015-09-03 15:59:49 -07001043 || mScreenshotChordVolumeUpKeyTriggered || gesturedServiceIntercepted;
Jeff Brown13f00f02014-10-31 14:45:50 -07001044 if (!mPowerKeyHandled) {
1045 if (interactive) {
1046 // When interactive, we're already awake.
1047 // Wait for a long press or for the button to be released to decide what to do.
1048 if (hasLongPressOnPowerBehavior()) {
1049 Message msg = mHandler.obtainMessage(MSG_POWER_LONG_PRESS);
1050 msg.setAsynchronous(true);
1051 mHandler.sendMessageDelayed(msg,
1052 ViewConfiguration.get(mContext).getDeviceGlobalActionKeyTimeout());
1053 }
1054 } else {
Bryce Leed9268e32014-11-17 17:40:59 -08001055 wakeUpFromPowerKey(event.getDownTime());
Bryce Leed9268e32014-11-17 17:40:59 -08001056
Bryce Leed3b28402015-03-09 15:49:13 +00001057 if (mSupportLongPressPowerWhenNonInteractive && hasLongPressOnPowerBehavior()) {
1058 Message msg = mHandler.obtainMessage(MSG_POWER_LONG_PRESS);
1059 msg.setAsynchronous(true);
1060 mHandler.sendMessageDelayed(msg,
1061 ViewConfiguration.get(mContext).getDeviceGlobalActionKeyTimeout());
Bryce Leed9268e32014-11-17 17:40:59 -08001062 mBeganFromNonInteractive = true;
Bryce Leed3b28402015-03-09 15:49:13 +00001063 } else {
1064 final int maxCount = getMaxMultiPressPowerCount();
1065
1066 if (maxCount <= 1) {
1067 mPowerKeyHandled = true;
1068 } else {
1069 mBeganFromNonInteractive = true;
1070 }
Jeff Brown13f00f02014-10-31 14:45:50 -07001071 }
1072 }
Jeff Brown4d396052010-10-29 21:50:21 -07001073 }
1074 }
1075
Jeff Brown13f00f02014-10-31 14:45:50 -07001076 private void interceptPowerKeyUp(KeyEvent event, boolean interactive, boolean canceled) {
1077 final boolean handled = canceled || mPowerKeyHandled;
1078 mScreenshotChordPowerKeyTriggered = false;
1079 cancelPendingScreenshotChordAction();
1080 cancelPendingPowerKeyAction();
1081
1082 if (!handled) {
1083 // Figure out how to handle the key now that it has been released.
1084 mPowerKeyPressCounter += 1;
1085
1086 final int maxCount = getMaxMultiPressPowerCount();
1087 final long eventTime = event.getDownTime();
1088 if (mPowerKeyPressCounter < maxCount) {
1089 // This could be a multi-press. Wait a little bit longer to confirm.
1090 // Continue holding the wake lock.
1091 Message msg = mHandler.obtainMessage(MSG_POWER_DELAYED_PRESS,
1092 interactive ? 1 : 0, mPowerKeyPressCounter, eventTime);
1093 msg.setAsynchronous(true);
1094 mHandler.sendMessageDelayed(msg, ViewConfiguration.getDoubleTapTimeout());
1095 return;
1096 }
1097
1098 // No other actions. Handle it immediately.
1099 powerPress(eventTime, interactive, mPowerKeyPressCounter);
Jeff Brown4d396052010-10-29 21:50:21 -07001100 }
Jeff Brown13f00f02014-10-31 14:45:50 -07001101
1102 // Done. Reset our state.
1103 finishPowerKeyPress();
1104 }
1105
1106 private void finishPowerKeyPress() {
Bryce Leed9268e32014-11-17 17:40:59 -08001107 mBeganFromNonInteractive = false;
Jeff Brown13f00f02014-10-31 14:45:50 -07001108 mPowerKeyPressCounter = 0;
1109 if (mPowerKeyWakeLock.isHeld()) {
1110 mPowerKeyWakeLock.release();
1111 }
Jeff Brownd5bb82d2011-10-12 13:57:59 -07001112 }
1113
1114 private void cancelPendingPowerKeyAction() {
1115 if (!mPowerKeyHandled) {
Jeff Brown13f00f02014-10-31 14:45:50 -07001116 mPowerKeyHandled = true;
1117 mHandler.removeMessages(MSG_POWER_LONG_PRESS);
Jeff Brownd5bb82d2011-10-12 13:57:59 -07001118 }
Jeff Brown13f00f02014-10-31 14:45:50 -07001119 }
1120
Anthony Hugh34f09ca2016-03-04 12:03:37 -08001121 private void cancelPendingBackKeyAction() {
1122 if (!mBackKeyHandled) {
1123 mBackKeyHandled = true;
1124 mHandler.removeMessages(MSG_BACK_LONG_PRESS);
1125 }
1126 }
1127
Jeff Brown13f00f02014-10-31 14:45:50 -07001128 private void powerPress(long eventTime, boolean interactive, int count) {
1129 if (mScreenOnEarly && !mScreenOnFully) {
1130 Slog.i(TAG, "Suppressed redundant power key press while "
1131 + "already in the process of turning the screen on.");
1132 return;
Jeff Brownff204712011-10-25 21:27:54 -07001133 }
Jeff Brown13f00f02014-10-31 14:45:50 -07001134
1135 if (count == 2) {
1136 powerMultiPressAction(eventTime, interactive, mDoublePressOnPowerBehavior);
1137 } else if (count == 3) {
1138 powerMultiPressAction(eventTime, interactive, mTriplePressOnPowerBehavior);
Bryce Leed9268e32014-11-17 17:40:59 -08001139 } else if (interactive && !mBeganFromNonInteractive) {
Jeff Brown13f00f02014-10-31 14:45:50 -07001140 switch (mShortPressOnPowerBehavior) {
1141 case SHORT_PRESS_POWER_NOTHING:
1142 break;
1143 case SHORT_PRESS_POWER_GO_TO_SLEEP:
1144 mPowerManager.goToSleep(eventTime,
1145 PowerManager.GO_TO_SLEEP_REASON_POWER_BUTTON, 0);
1146 break;
1147 case SHORT_PRESS_POWER_REALLY_GO_TO_SLEEP:
1148 mPowerManager.goToSleep(eventTime,
1149 PowerManager.GO_TO_SLEEP_REASON_POWER_BUTTON,
1150 PowerManager.GO_TO_SLEEP_FLAG_NO_DOZE);
1151 break;
1152 case SHORT_PRESS_POWER_REALLY_GO_TO_SLEEP_AND_GO_HOME:
1153 mPowerManager.goToSleep(eventTime,
1154 PowerManager.GO_TO_SLEEP_REASON_POWER_BUTTON,
1155 PowerManager.GO_TO_SLEEP_FLAG_NO_DOZE);
1156 launchHomeFromHotKey();
1157 break;
Bryce Lee01b0c5f2015-02-05 18:24:04 -08001158 case SHORT_PRESS_POWER_GO_HOME:
Bryce Lee662ed802015-04-10 20:11:39 +00001159 launchHomeFromHotKey(true /* awakenFromDreams */, false /*respectKeyguard*/);
Bryce Lee01b0c5f2015-02-05 18:24:04 -08001160 break;
Jeff Brown13f00f02014-10-31 14:45:50 -07001161 }
1162 }
1163 }
1164
1165 private void powerMultiPressAction(long eventTime, boolean interactive, int behavior) {
1166 switch (behavior) {
1167 case MULTI_PRESS_POWER_NOTHING:
1168 break;
1169 case MULTI_PRESS_POWER_THEATER_MODE:
Bryce Lee3ae447e2015-06-30 12:31:41 -07001170 if (!isUserSetupComplete()) {
1171 Slog.i(TAG, "Ignoring toggling theater mode - device not setup.");
1172 break;
1173 }
1174
Jeff Brown13f00f02014-10-31 14:45:50 -07001175 if (isTheaterModeEnabled()) {
1176 Slog.i(TAG, "Toggling theater mode off.");
1177 Settings.Global.putInt(mContext.getContentResolver(),
1178 Settings.Global.THEATER_MODE_ON, 0);
1179 if (!interactive) {
1180 wakeUpFromPowerKey(eventTime);
1181 }
1182 } else {
1183 Slog.i(TAG, "Toggling theater mode on.");
1184 Settings.Global.putInt(mContext.getContentResolver(),
1185 Settings.Global.THEATER_MODE_ON, 1);
Bryce Lee55e846d2014-11-04 12:43:44 -08001186
1187 if (mGoToSleepOnButtonPressTheaterMode && interactive) {
Jeff Brown13f00f02014-10-31 14:45:50 -07001188 mPowerManager.goToSleep(eventTime,
1189 PowerManager.GO_TO_SLEEP_REASON_POWER_BUTTON, 0);
1190 }
1191 }
1192 break;
1193 case MULTI_PRESS_POWER_BRIGHTNESS_BOOST:
Jeff Brown7b5be5e2014-11-12 18:45:31 -08001194 Slog.i(TAG, "Starting brightness boost.");
1195 if (!interactive) {
1196 wakeUpFromPowerKey(eventTime);
1197 }
Jeff Brown13f00f02014-10-31 14:45:50 -07001198 mPowerManager.boostScreenBrightness(eventTime);
1199 break;
1200 }
1201 }
1202
1203 private int getMaxMultiPressPowerCount() {
1204 if (mTriplePressOnPowerBehavior != MULTI_PRESS_POWER_NOTHING) {
1205 return 3;
1206 }
1207 if (mDoublePressOnPowerBehavior != MULTI_PRESS_POWER_NOTHING) {
1208 return 2;
1209 }
1210 return 1;
1211 }
1212
1213 private void powerLongPress() {
1214 final int behavior = getResolvedLongPressOnPowerBehavior();
1215 switch (behavior) {
1216 case LONG_PRESS_POWER_NOTHING:
1217 break;
1218 case LONG_PRESS_POWER_GLOBAL_ACTIONS:
1219 mPowerKeyHandled = true;
1220 if (!performHapticFeedbackLw(null, HapticFeedbackConstants.LONG_PRESS, false)) {
1221 performAuditoryFeedbackForAccessibilityIfNeed();
1222 }
1223 showGlobalActionsInternal();
1224 break;
1225 case LONG_PRESS_POWER_SHUT_OFF:
1226 case LONG_PRESS_POWER_SHUT_OFF_NO_CONFIRM:
1227 mPowerKeyHandled = true;
1228 performHapticFeedbackLw(null, HapticFeedbackConstants.LONG_PRESS, false);
1229 sendCloseSystemWindows(SYSTEM_DIALOG_REASON_GLOBAL_ACTIONS);
1230 mWindowManagerFuncs.shutdown(behavior == LONG_PRESS_POWER_SHUT_OFF);
1231 break;
1232 }
1233 }
1234
Anthony Hugh34f09ca2016-03-04 12:03:37 -08001235 private void backLongPress() {
1236 mBackKeyHandled = true;
1237
1238 switch (mLongPressOnBackBehavior) {
1239 case LONG_PRESS_BACK_NOTHING:
1240 break;
1241 case LONG_PRESS_BACK_GO_TO_VOICE_ASSIST:
1242 Intent intent = new Intent(Intent.ACTION_VOICE_ASSIST);
1243 startActivityAsUser(intent, UserHandle.CURRENT_OR_SELF);
1244 break;
1245 }
1246 }
1247
Nick Vaccarob593a812015-05-15 11:23:05 -07001248 private void sleepPress(long eventTime) {
1249 if (mShortPressOnSleepBehavior == SHORT_PRESS_SLEEP_GO_TO_SLEEP_AND_GO_HOME) {
1250 launchHomeFromHotKey(false /* awakenDreams */, true /*respectKeyguard*/);
1251 }
1252 }
1253
1254 private void sleepRelease(long eventTime) {
Filip Gruszczynskia483a1d2015-03-17 19:06:58 +00001255 switch (mShortPressOnSleepBehavior) {
1256 case SHORT_PRESS_SLEEP_GO_TO_SLEEP:
Filip Gruszczynskia483a1d2015-03-17 19:06:58 +00001257 case SHORT_PRESS_SLEEP_GO_TO_SLEEP_AND_GO_HOME:
Nick Vaccarob593a812015-05-15 11:23:05 -07001258 Slog.i(TAG, "sleepRelease() calling goToSleep(GO_TO_SLEEP_REASON_SLEEP_BUTTON)");
1259 mPowerManager.goToSleep(eventTime,
1260 PowerManager.GO_TO_SLEEP_REASON_SLEEP_BUTTON, 0);
Filip Gruszczynskia483a1d2015-03-17 19:06:58 +00001261 break;
1262 }
1263 }
1264
Jeff Brown13f00f02014-10-31 14:45:50 -07001265 private int getResolvedLongPressOnPowerBehavior() {
1266 if (FactoryTest.isLongPressOnPowerOffEnabled()) {
1267 return LONG_PRESS_POWER_SHUT_OFF_NO_CONFIRM;
1268 }
1269 return mLongPressOnPowerBehavior;
1270 }
1271
1272 private boolean hasLongPressOnPowerBehavior() {
1273 return getResolvedLongPressOnPowerBehavior() != LONG_PRESS_POWER_NOTHING;
Jeff Brownd5bb82d2011-10-12 13:57:59 -07001274 }
1275
Anthony Hugh34f09ca2016-03-04 12:03:37 -08001276 private boolean hasLongPressOnBackBehavior() {
1277 return mLongPressOnBackBehavior != LONG_PRESS_BACK_NOTHING;
1278 }
1279
Jeff Brownd5bb82d2011-10-12 13:57:59 -07001280 private void interceptScreenshotChord() {
Christopher Tatee90585f2012-03-05 18:56:25 -08001281 if (mScreenshotChordEnabled
Jeff Brown13f00f02014-10-31 14:45:50 -07001282 && mScreenshotChordVolumeDownKeyTriggered && mScreenshotChordPowerKeyTriggered
1283 && !mScreenshotChordVolumeUpKeyTriggered) {
Jeff Brownd5bb82d2011-10-12 13:57:59 -07001284 final long now = SystemClock.uptimeMillis();
Jeff Brown13f00f02014-10-31 14:45:50 -07001285 if (now <= mScreenshotChordVolumeDownKeyTime + SCREENSHOT_CHORD_DEBOUNCE_DELAY_MILLIS
1286 && now <= mScreenshotChordPowerKeyTime
1287 + SCREENSHOT_CHORD_DEBOUNCE_DELAY_MILLIS) {
1288 mScreenshotChordVolumeDownKeyConsumed = true;
Jeff Brownd5bb82d2011-10-12 13:57:59 -07001289 cancelPendingPowerKeyAction();
Muyuan Li6ca619f2016-03-08 13:30:42 -08001290 mScreenshotRunnable.setScreenshotType(TAKE_SCREENSHOT_FULLSCREEN);
Jeff Sharkey2991fa32012-12-05 18:06:43 -08001291 mHandler.postDelayed(mScreenshotRunnable, getScreenshotChordLongPressDelay());
Jeff Brownd5bb82d2011-10-12 13:57:59 -07001292 }
1293 }
1294 }
1295
Winson Chung1cea2f32012-10-08 20:42:01 -07001296 private long getScreenshotChordLongPressDelay() {
Jim Miller5ecd8112013-01-09 18:50:26 -08001297 if (mKeyguardDelegate.isShowing()) {
Winson Chung1cea2f32012-10-08 20:42:01 -07001298 // Double the time it takes to take a screenshot from the keyguard
1299 return (long) (KEYGUARD_SCREENSHOT_CHORD_DELAY_MULTIPLIER *
Justin Kohfeabd2c2014-05-02 10:02:44 -07001300 ViewConfiguration.get(mContext).getDeviceGlobalActionKeyTimeout());
Winson Chung1cea2f32012-10-08 20:42:01 -07001301 }
Justin Kohfeabd2c2014-05-02 10:02:44 -07001302 return ViewConfiguration.get(mContext).getDeviceGlobalActionKeyTimeout();
Winson Chung1cea2f32012-10-08 20:42:01 -07001303 }
1304
Jeff Brownd5bb82d2011-10-12 13:57:59 -07001305 private void cancelPendingScreenshotChordAction() {
Jeff Sharkey2991fa32012-12-05 18:06:43 -08001306 mHandler.removeCallbacks(mScreenshotRunnable);
Jeff Brown4d396052010-10-29 21:50:21 -07001307 }
1308
Jeff Brown13f00f02014-10-31 14:45:50 -07001309 private final Runnable mEndCallLongPress = new Runnable() {
Craig Mautnerf1b67412012-09-19 13:18:29 -07001310 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001311 public void run() {
Jeff Brown13f00f02014-10-31 14:45:50 -07001312 mEndCallKeyHandled = true;
1313 if (!performHapticFeedbackLw(null, HapticFeedbackConstants.LONG_PRESS, false)) {
1314 performAuditoryFeedbackForAccessibilityIfNeed();
Joe Onoratod208e702010-10-08 16:22:43 -04001315 }
Jeff Brown13f00f02014-10-31 14:45:50 -07001316 showGlobalActionsInternal();
Jeff Brownd5bb82d2011-10-12 13:57:59 -07001317 }
1318 };
1319
Muyuan Li6ca619f2016-03-08 13:30:42 -08001320 private class ScreenshotRunnable implements Runnable {
1321 private int mScreenshotType = TAKE_SCREENSHOT_FULLSCREEN;
1322
1323 public void setScreenshotType(int screenshotType) {
1324 mScreenshotType = screenshotType;
1325 }
1326
Craig Mautner0bf6ec92012-12-18 08:33:27 -08001327 @Override
Jeff Brownd5bb82d2011-10-12 13:57:59 -07001328 public void run() {
Muyuan Li6ca619f2016-03-08 13:30:42 -08001329 takeScreenshot(mScreenshotType);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001330 }
Muyuan Li6ca619f2016-03-08 13:30:42 -08001331 }
1332
1333 private final ScreenshotRunnable mScreenshotRunnable = new ScreenshotRunnable();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001334
Alan Viverettee34560b22014-07-10 14:50:06 -07001335 @Override
1336 public void showGlobalActions() {
1337 mHandler.removeMessages(MSG_DISPATCH_SHOW_GLOBAL_ACTIONS);
1338 mHandler.sendEmptyMessage(MSG_DISPATCH_SHOW_GLOBAL_ACTIONS);
1339 }
1340
1341 void showGlobalActionsInternal() {
1342 sendCloseSystemWindows(SYSTEM_DIALOG_REASON_GLOBAL_ACTIONS);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001343 if (mGlobalActions == null) {
Jeff Brown7304c342012-05-11 18:42:42 -07001344 mGlobalActions = new GlobalActions(mContext, mWindowManagerFuncs);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001345 }
Jim Millerab954542014-10-10 18:21:49 -07001346 final boolean keyguardShowing = isKeyguardShowingAndNotOccluded();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001347 mGlobalActions.showDialog(keyguardShowing, isDeviceProvisioned());
1348 if (keyguardShowing) {
1349 // since it took two seconds of long press to bring this up,
1350 // poke the wake lock so they have some time to see the dialog.
Jim Miller25190572013-02-28 17:36:24 -08001351 mPowerManager.userActivity(SystemClock.uptimeMillis(), false);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001352 }
1353 }
1354
1355 boolean isDeviceProvisioned() {
Jeff Brownbf6f6f92012-09-25 15:03:20 -07001356 return Settings.Global.getInt(
1357 mContext.getContentResolver(), Settings.Global.DEVICE_PROVISIONED, 0) != 0;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001358 }
1359
Maurice Lam99c6e072014-04-28 18:24:28 -07001360 boolean isUserSetupComplete() {
1361 return Settings.Secure.getIntForUser(mContext.getContentResolver(),
1362 Settings.Secure.USER_SETUP_COMPLETE, 0, UserHandle.USER_CURRENT) != 0;
1363 }
1364
Jeff Brown13f00f02014-10-31 14:45:50 -07001365 private void handleShortPressOnHome() {
Jinsuk Kime601b712015-07-07 08:01:02 +09001366 // Turn on the connected TV and switch HDMI input if we're a HDMI playback device.
1367 getHdmiControl().turnOnTv();
1368
Jeff Brown13f00f02014-10-31 14:45:50 -07001369 // If there's a dream running then use home to escape the dream
1370 // but don't actually go home.
1371 if (mDreamManagerInternal != null && mDreamManagerInternal.isDreaming()) {
1372 mDreamManagerInternal.stopDream(false /*immediate*/);
1373 return;
1374 }
1375
1376 // Go home!
1377 launchHomeFromHotKey();
1378 }
1379
Jinsuk Kime601b712015-07-07 08:01:02 +09001380 /**
1381 * Creates an accessor to HDMI control service that performs the operation of
1382 * turning on TV (optional) and switching input to us. If HDMI control service
1383 * is not available or we're not a HDMI playback device, the operation is no-op.
1384 */
1385 private HdmiControl getHdmiControl() {
1386 if (null == mHdmiControl) {
1387 HdmiControlManager manager = (HdmiControlManager) mContext.getSystemService(
1388 Context.HDMI_CONTROL_SERVICE);
1389 HdmiPlaybackClient client = null;
1390 if (manager != null) {
1391 client = manager.getPlaybackClient();
1392 }
1393 mHdmiControl = new HdmiControl(client);
1394 }
1395 return mHdmiControl;
1396 }
1397
1398 private static class HdmiControl {
1399 private final HdmiPlaybackClient mClient;
1400
1401 private HdmiControl(HdmiPlaybackClient client) {
1402 mClient = client;
1403 }
1404
1405 public void turnOnTv() {
1406 if (mClient == null) {
1407 return;
1408 }
1409 mClient.oneTouchPlay(new OneTouchPlayCallback() {
1410 @Override
1411 public void onComplete(int result) {
1412 if (result != HdmiControlManager.RESULT_SUCCESS) {
1413 Log.w(TAG, "One touch play failed: " + result);
1414 }
1415 }
1416 });
1417 }
1418 }
1419
Jaewan Kim76b7d0d2016-02-12 19:01:02 +09001420 private void handleLongPressOnHome(int deviceId) {
Jaewan Kim52632e22016-01-14 18:01:52 +09001421 if (mLongPressOnHomeBehavior == LONG_PRESS_HOME_NOTHING) {
1422 return;
1423 }
1424 mHomeConsumed = true;
1425 performHapticFeedbackLw(null, HapticFeedbackConstants.LONG_PRESS, false);
Patrick Dubroyece94522011-02-23 18:35:01 -08001426
Jaewan Kim52632e22016-01-14 18:01:52 +09001427 switch (mLongPressOnHomeBehavior) {
1428 case LONG_PRESS_HOME_RECENT_SYSTEM_UI:
Jeff Browncaca8812013-05-09 13:34:33 -07001429 toggleRecentApps();
Jaewan Kim52632e22016-01-14 18:01:52 +09001430 break;
1431 case LONG_PRESS_HOME_ASSIST:
Tim Kilbourn0e5f1102015-06-05 16:18:09 -07001432 launchAssistAction(null, deviceId);
Jaewan Kim52632e22016-01-14 18:01:52 +09001433 break;
Jaewan Kim52632e22016-01-14 18:01:52 +09001434 default:
Jaewan Kim76b7d0d2016-02-12 19:01:02 +09001435 Log.w(TAG, "Undefined home long press behavior: " + mLongPressOnHomeBehavior);
Jaewan Kim52632e22016-01-14 18:01:52 +09001436 break;
Jim Millere6ad1a82010-08-20 19:25:39 -07001437 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001438 }
Patrick Dubroyece94522011-02-23 18:35:01 -08001439
Jeff Browncaca8812013-05-09 13:34:33 -07001440 private void handleDoubleTapOnHome() {
1441 if (mDoubleTapOnHomeBehavior == DOUBLE_TAP_HOME_RECENT_SYSTEM_UI) {
1442 mHomeConsumed = true;
1443 toggleRecentApps();
1444 }
1445 }
1446
Jaewan Kimc552b042016-01-18 16:08:45 +09001447 private void requestTvPictureInPicture(KeyEvent event) {
1448 if (DEBUG_INPUT) Log.d(TAG, "requestTvPictureInPicture event=" + event);
1449 mHandler.removeMessages(MSG_REQUEST_TV_PICTURE_IN_PICTURE);
1450 Message msg = mHandler.obtainMessage(MSG_REQUEST_TV_PICTURE_IN_PICTURE);
1451 msg.setAsynchronous(true);
1452 msg.sendToTarget();
1453 }
1454
1455 private void requestTvPictureInPictureInternal() {
1456 try {
1457 IStatusBarService statusbar = getStatusBarService();
1458 if (statusbar != null) {
1459 statusbar.requestTvPictureInPicture();
1460 }
1461 } catch (RemoteException|IllegalArgumentException e) {
1462 Slog.e(TAG, "Cannot handle picture-in-picture key", e);
1463 // re-acquire status bar service next time it is needed.
1464 mStatusBarService = null;
1465 }
Jaewan Kim52632e22016-01-14 18:01:52 +09001466 }
1467
Jeff Browncaca8812013-05-09 13:34:33 -07001468 private final Runnable mHomeDoubleTapTimeoutRunnable = new Runnable() {
1469 @Override
1470 public void run() {
1471 if (mHomeDoubleTapPending) {
1472 mHomeDoubleTapPending = false;
Jeff Brown13f00f02014-10-31 14:45:50 -07001473 handleShortPressOnHome();
Jeff Browncaca8812013-05-09 13:34:33 -07001474 }
1475 }
1476 };
1477
Mark Renoufc1256912015-03-11 14:38:23 -04001478 private boolean isRoundWindow() {
Adam Powell01f280d2015-05-18 16:07:42 -07001479 return mContext.getResources().getConfiguration().isScreenRound();
Mark Renoufc1256912015-03-11 14:38:23 -04001480 }
1481
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001482 /** {@inheritDoc} */
Craig Mautner0bf6ec92012-12-18 08:33:27 -08001483 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001484 public void init(Context context, IWindowManager windowManager,
Jeff Brown96307042012-07-27 15:51:34 -07001485 WindowManagerFuncs windowManagerFuncs) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001486 mContext = context;
1487 mWindowManager = windowManager;
Dianne Hackborndf89e652011-10-06 22:35:11 -07001488 mWindowManagerFuncs = windowManagerFuncs;
Craig Mautner8a0da012014-05-31 15:13:37 -07001489 mWindowManagerInternal = LocalServices.getService(WindowManagerInternal.class);
Jeff Brown061ea992015-04-17 19:55:47 -07001490 mActivityManagerInternal = LocalServices.getService(ActivityManagerInternal.class);
Jose Lima9546b202014-07-02 17:21:51 -07001491 mDreamManagerInternal = LocalServices.getService(DreamManagerInternal.class);
Michael Wrighta4d22d72015-09-16 23:19:26 +01001492 mPowerManagerInternal = LocalServices.getService(PowerManagerInternal.class);
Billy Laucbe540f2015-06-25 01:51:44 +01001493 mAppOpsManager = (AppOpsManager) mContext.getSystemService(Context.APP_OPS_SERVICE);
Mark Renoufc1256912015-03-11 14:38:23 -04001494
1495 // Init display burn-in protection
1496 boolean burnInProtectionEnabled = context.getResources().getBoolean(
1497 com.android.internal.R.bool.config_enableBurnInProtection);
1498 // Allow a system property to override this. Used by developer settings.
1499 boolean burnInProtectionDevMode =
1500 SystemProperties.getBoolean("persist.debug.force_burn_in", false);
1501 if (burnInProtectionEnabled || burnInProtectionDevMode) {
1502 final int minHorizontal;
1503 final int maxHorizontal;
1504 final int minVertical;
1505 final int maxVertical;
1506 final int maxRadius;
1507 if (burnInProtectionDevMode) {
1508 minHorizontal = -8;
1509 maxHorizontal = 8;
1510 minVertical = -8;
1511 maxVertical = -4;
1512 maxRadius = (isRoundWindow()) ? 6 : -1;
1513 } else {
1514 Resources resources = context.getResources();
1515 minHorizontal = resources.getInteger(
1516 com.android.internal.R.integer.config_burnInProtectionMinHorizontalOffset);
1517 maxHorizontal = resources.getInteger(
1518 com.android.internal.R.integer.config_burnInProtectionMaxHorizontalOffset);
1519 minVertical = resources.getInteger(
1520 com.android.internal.R.integer.config_burnInProtectionMinVerticalOffset);
1521 maxVertical = resources.getInteger(
1522 com.android.internal.R.integer.config_burnInProtectionMaxVerticalOffset);
1523 maxRadius = resources.getInteger(
1524 com.android.internal.R.integer.config_burnInProtectionMaxRadius);
1525 }
1526 mBurnInProtectionHelper = new BurnInProtectionHelper(
1527 context, minHorizontal, maxHorizontal, minVertical, maxVertical, maxRadius);
Filip Gruszczynskicfb31852015-02-25 21:47:12 +00001528 }
Craig Mautner8a0da012014-05-31 15:13:37 -07001529
Jeff Brown70825162012-03-28 17:27:48 -07001530 mHandler = new PolicyHandler();
Jeff Browna20dda42014-05-27 20:57:24 -07001531 mWakeGestureListener = new MyWakeGestureListener(mContext, mHandler);
Craig Mautnereee29c42013-01-17 14:44:34 -08001532 mOrientationListener = new MyOrientationListener(mContext, mHandler);
Jeff Brownc0347aa2011-09-23 17:26:09 -07001533 try {
1534 mOrientationListener.setCurrentRotation(windowManager.getRotation());
1535 } catch (RemoteException ex) { }
Christopher Tate5e08af02012-09-21 17:17:22 -07001536 mSettingsObserver = new SettingsObserver(mHandler);
1537 mSettingsObserver.observe();
Svetoslav683914b2015-01-15 14:22:26 -08001538 mShortcutManager = new ShortcutManager(context);
Daniel Sandler6396c722013-04-16 20:19:09 -04001539 mUiMode = context.getResources().getInteger(
1540 com.android.internal.R.integer.config_defaultUiModeType);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001541 mHomeIntent = new Intent(Intent.ACTION_MAIN, null);
1542 mHomeIntent.addCategory(Intent.CATEGORY_HOME);
1543 mHomeIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK
1544 | Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED);
keunyounga7710492015-09-23 11:33:58 -07001545 mEnableCarDockHomeCapture = context.getResources().getBoolean(
1546 com.android.internal.R.bool.config_enableCarDockHomeLaunch);
Dianne Hackborn39c2d712009-09-22 11:41:31 -07001547 mCarDockIntent = new Intent(Intent.ACTION_MAIN, null);
1548 mCarDockIntent.addCategory(Intent.CATEGORY_CAR_DOCK);
1549 mCarDockIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK
1550 | Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED);
1551 mDeskDockIntent = new Intent(Intent.ACTION_MAIN, null);
1552 mDeskDockIntent.addCategory(Intent.CATEGORY_DESK_DOCK);
1553 mDeskDockIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK
1554 | Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED);
Jim Millere6ad1a82010-08-20 19:25:39 -07001555
Jeff Brown96307042012-07-27 15:51:34 -07001556 mPowerManager = (PowerManager)context.getSystemService(Context.POWER_SERVICE);
1557 mBroadcastWakeLock = mPowerManager.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK,
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001558 "PhoneWindowManager.mBroadcastWakeLock");
Jeff Brown13f00f02014-10-31 14:45:50 -07001559 mPowerKeyWakeLock = mPowerManager.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK,
1560 "PhoneWindowManager.mPowerKeyWakeLock");
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001561 mEnableShiftMenuBugReports = "1".equals(SystemProperties.get("ro.debuggable"));
Jeff Brownbcdfc622014-03-06 19:13:04 -08001562 mSupportAutoRotation = mContext.getResources().getBoolean(
1563 com.android.internal.R.bool.config_supportAutoRotation);
Dianne Hackborn2862fff2009-09-15 22:56:29 -07001564 mLidOpenRotation = readRotation(
Mike Lockwood2d1efbd2009-09-16 12:15:53 -04001565 com.android.internal.R.integer.config_lidOpenRotation);
1566 mCarDockRotation = readRotation(
1567 com.android.internal.R.integer.config_carDockRotation);
1568 mDeskDockRotation = readRotation(
1569 com.android.internal.R.integer.config_deskDockRotation);
Jeff Brownc82c89ed2013-04-17 17:18:15 -07001570 mUndockedHdmiRotation = readRotation(
1571 com.android.internal.R.integer.config_undockedHdmiRotation);
Mike Lockwoode9867d22009-09-20 01:59:02 -04001572 mCarDockEnablesAccelerometer = mContext.getResources().getBoolean(
1573 com.android.internal.R.bool.config_carDockEnablesAccelerometer);
1574 mDeskDockEnablesAccelerometer = mContext.getResources().getBoolean(
1575 com.android.internal.R.bool.config_deskDockEnablesAccelerometer);
Dianne Hackborn2862fff2009-09-15 22:56:29 -07001576 mLidKeyboardAccessibility = mContext.getResources().getInteger(
1577 com.android.internal.R.integer.config_lidKeyboardAccessibility);
1578 mLidNavigationAccessibility = mContext.getResources().getInteger(
1579 com.android.internal.R.integer.config_lidNavigationAccessibility);
Edward Savage-Jones7def60d2015-11-13 13:27:03 +01001580 mLidControlsScreenLock = mContext.getResources().getBoolean(
1581 com.android.internal.R.bool.config_lidControlsScreenLock);
Jeff Brownc458ce92012-04-30 14:58:40 -07001582 mLidControlsSleep = mContext.getResources().getBoolean(
1583 com.android.internal.R.bool.config_lidControlsSleep);
Daniel Sandlerdd73ee42013-10-11 22:19:59 -04001584 mTranslucentDecorEnabled = mContext.getResources().getBoolean(
1585 com.android.internal.R.bool.config_enableTranslucentDecor);
Bryce Lee584a4452014-10-21 15:55:55 -07001586
1587 mAllowTheaterModeWakeFromKey = mContext.getResources().getBoolean(
1588 com.android.internal.R.bool.config_allowTheaterModeWakeFromKey);
1589 mAllowTheaterModeWakeFromPowerKey = mAllowTheaterModeWakeFromKey
1590 || mContext.getResources().getBoolean(
1591 com.android.internal.R.bool.config_allowTheaterModeWakeFromPowerKey);
1592 mAllowTheaterModeWakeFromMotion = mContext.getResources().getBoolean(
1593 com.android.internal.R.bool.config_allowTheaterModeWakeFromMotion);
Bryce Lee812d7022014-11-10 13:33:28 -08001594 mAllowTheaterModeWakeFromMotionWhenNotDreaming = mContext.getResources().getBoolean(
1595 com.android.internal.R.bool.config_allowTheaterModeWakeFromMotionWhenNotDreaming);
Bryce Lee584a4452014-10-21 15:55:55 -07001596 mAllowTheaterModeWakeFromCameraLens = mContext.getResources().getBoolean(
1597 com.android.internal.R.bool.config_allowTheaterModeWakeFromCameraLens);
1598 mAllowTheaterModeWakeFromLidSwitch = mContext.getResources().getBoolean(
1599 com.android.internal.R.bool.config_allowTheaterModeWakeFromLidSwitch);
1600 mAllowTheaterModeWakeFromWakeGesture = mContext.getResources().getBoolean(
1601 com.android.internal.R.bool.config_allowTheaterModeWakeFromGesture);
1602
Bryce Lee55e846d2014-11-04 12:43:44 -08001603 mGoToSleepOnButtonPressTheaterMode = mContext.getResources().getBoolean(
1604 com.android.internal.R.bool.config_goToSleepOnButtonPressTheaterMode);
1605
Bryce Leed3b28402015-03-09 15:49:13 +00001606 mSupportLongPressPowerWhenNonInteractive = mContext.getResources().getBoolean(
1607 com.android.internal.R.bool.config_supportLongPressPowerWhenNonInteractive);
1608
Anthony Hugh34f09ca2016-03-04 12:03:37 -08001609 mLongPressOnBackBehavior = mContext.getResources().getInteger(
1610 com.android.internal.R.integer.config_longPressOnBackBehavior);
1611
Jeff Brown13f00f02014-10-31 14:45:50 -07001612 mShortPressOnPowerBehavior = mContext.getResources().getInteger(
1613 com.android.internal.R.integer.config_shortPressOnPowerBehavior);
1614 mLongPressOnPowerBehavior = mContext.getResources().getInteger(
1615 com.android.internal.R.integer.config_longPressOnPowerBehavior);
1616 mDoublePressOnPowerBehavior = mContext.getResources().getInteger(
1617 com.android.internal.R.integer.config_doublePressOnPowerBehavior);
1618 mTriplePressOnPowerBehavior = mContext.getResources().getInteger(
1619 com.android.internal.R.integer.config_triplePressOnPowerBehavior);
Filip Gruszczynskia483a1d2015-03-17 19:06:58 +00001620 mShortPressOnSleepBehavior = mContext.getResources().getInteger(
1621 com.android.internal.R.integer.config_shortPressOnSleepBehavior);
Jeff Brown13f00f02014-10-31 14:45:50 -07001622
John Spurlock61560172015-02-06 19:46:04 -05001623 mUseTvRouting = AudioSystem.getPlatformType(mContext) == AudioSystem.PLATFORM_TELEVISION;
RoboErik001c59c2015-01-26 15:53:51 -08001624
Jeff Brownf71343d2013-05-31 17:59:11 -07001625 readConfigurationDependentBehaviors();
Jeff Browncaca8812013-05-09 13:34:33 -07001626
Svetoslav8e3feb12014-02-24 13:46:47 -08001627 mAccessibilityManager = (AccessibilityManager) context.getSystemService(
1628 Context.ACCESSIBILITY_SERVICE);
1629
Mike Lockwood1753f7f2009-08-24 14:49:07 -07001630 // register for dock events
Dianne Hackborn78968392010-03-04 20:47:56 -08001631 IntentFilter filter = new IntentFilter();
1632 filter.addAction(UiModeManager.ACTION_ENTER_CAR_MODE);
1633 filter.addAction(UiModeManager.ACTION_EXIT_CAR_MODE);
1634 filter.addAction(UiModeManager.ACTION_ENTER_DESK_MODE);
1635 filter.addAction(UiModeManager.ACTION_EXIT_DESK_MODE);
Dianne Hackborn867ab6472010-04-29 13:28:56 -07001636 filter.addAction(Intent.ACTION_DOCK_EVENT);
1637 Intent intent = context.registerReceiver(mDockReceiver, filter);
1638 if (intent != null) {
1639 // Retrieve current sticky dock event broadcast.
1640 mDockMode = intent.getIntExtra(Intent.EXTRA_DOCK_STATE,
1641 Intent.EXTRA_DOCK_STATE_UNDOCKED);
1642 }
Daniel Sandler7e37df52011-11-16 22:08:23 -08001643
Jeff Brown6aaf2952012-10-05 16:01:08 -07001644 // register for dream-related broadcasts
1645 filter = new IntentFilter();
1646 filter.addAction(Intent.ACTION_DREAMING_STARTED);
1647 filter.addAction(Intent.ACTION_DREAMING_STOPPED);
1648 context.registerReceiver(mDreamReceiver, filter);
1649
Christopher Tate5e08af02012-09-21 17:17:22 -07001650 // register for multiuser-relevant broadcasts
1651 filter = new IntentFilter(Intent.ACTION_USER_SWITCHED);
1652 context.registerReceiver(mMultiuserReceiver, filter);
1653
John Spurlock57306e62013-04-22 09:48:49 -04001654 // monitor for system gestures
Craig Mautner037aa8d2013-06-07 10:35:44 -07001655 mSystemGestures = new SystemGesturesPointerEventListener(context,
1656 new SystemGesturesPointerEventListener.Callbacks() {
John Spurlock57306e62013-04-22 09:48:49 -04001657 @Override
1658 public void onSwipeFromTop() {
John Spurlock04db1762013-05-13 12:46:41 -04001659 if (mStatusBar != null) {
John Spurlocke1f366f2013-08-05 12:22:40 -04001660 requestTransientBars(mStatusBar);
John Spurlock04db1762013-05-13 12:46:41 -04001661 }
John Spurlockad3e6cb2013-04-30 08:47:43 -04001662 }
1663 @Override
1664 public void onSwipeFromBottom() {
John Spurlock04db1762013-05-13 12:46:41 -04001665 if (mNavigationBar != null && mNavigationBarOnBottom) {
John Spurlocke1f366f2013-08-05 12:22:40 -04001666 requestTransientBars(mNavigationBar);
John Spurlockad3e6cb2013-04-30 08:47:43 -04001667 }
1668 }
1669 @Override
1670 public void onSwipeFromRight() {
John Spurlock04db1762013-05-13 12:46:41 -04001671 if (mNavigationBar != null && !mNavigationBarOnBottom) {
John Spurlocke1f366f2013-08-05 12:22:40 -04001672 requestTransientBars(mNavigationBar);
John Spurlockad3e6cb2013-04-30 08:47:43 -04001673 }
1674 }
1675 @Override
Michael Wrighta4d22d72015-09-16 23:19:26 +01001676 public void onFling(int duration) {
1677 if (mPowerManagerInternal != null) {
1678 mPowerManagerInternal.powerHint(
1679 PowerManagerInternal.POWER_HINT_INTERACTION, duration);
1680 }
1681 }
1682 @Override
John Spurlockad3e6cb2013-04-30 08:47:43 -04001683 public void onDebug() {
John Spurlockd67ec252013-09-05 11:31:54 -04001684 // no-op
John Spurlockad3e6cb2013-04-30 08:47:43 -04001685 }
Adrian Roos3595be42015-03-05 16:31:15 +01001686 @Override
1687 public void onDown() {
1688 mOrientationListener.onTouchStart();
1689 }
1690 @Override
1691 public void onUpOrCancel() {
1692 mOrientationListener.onTouchEnd();
1693 }
Jun Mukaid2e7e352015-07-22 17:14:02 -07001694 @Override
1695 public void onMouseHoverAtTop() {
1696 mHandler.removeMessages(MSG_REQUEST_TRANSIENT_BARS);
1697 Message msg = mHandler.obtainMessage(MSG_REQUEST_TRANSIENT_BARS);
1698 msg.arg1 = MSG_REQUEST_TRANSIENT_BARS_ARG_STATUS;
1699 mHandler.sendMessageDelayed(msg, 500);
1700 }
1701 @Override
1702 public void onMouseHoverAtBottom() {
1703 mHandler.removeMessages(MSG_REQUEST_TRANSIENT_BARS);
1704 Message msg = mHandler.obtainMessage(MSG_REQUEST_TRANSIENT_BARS);
1705 msg.arg1 = MSG_REQUEST_TRANSIENT_BARS_ARG_NAVIGATION;
1706 mHandler.sendMessageDelayed(msg, 500);
1707 }
1708 @Override
1709 public void onMouseLeaveFromEdge() {
1710 mHandler.removeMessages(MSG_REQUEST_TRANSIENT_BARS);
1711 }
John Spurlockad3e6cb2013-04-30 08:47:43 -04001712 });
John Spurlockf1a36642013-10-12 17:50:42 -04001713 mImmersiveModeConfirmation = new ImmersiveModeConfirmation(mContext);
Craig Mautner037aa8d2013-06-07 10:35:44 -07001714 mWindowManagerFuncs.registerPointerEventListener(mSystemGestures);
John Spurlock32beb2c2013-03-11 10:16:47 -04001715
Jeff Brownc2346132012-04-13 01:55:38 -07001716 mVibrator = (Vibrator)context.getSystemService(Context.VIBRATOR_SERVICE);
Dianne Hackbornb1a79802009-09-29 15:18:31 -07001717 mLongPressVibePattern = getLongIntArray(mContext.getResources(),
1718 com.android.internal.R.array.config_longPressVibePattern);
1719 mVirtualKeyVibePattern = getLongIntArray(mContext.getResources(),
1720 com.android.internal.R.array.config_virtualKeyVibePattern);
Amith Yamasanic33cb712010-02-10 15:21:49 -08001721 mKeyboardTapVibePattern = getLongIntArray(mContext.getResources(),
1722 com.android.internal.R.array.config_keyboardTapVibePattern);
Fabrice Di Meglioeeff63a2013-08-05 12:07:24 -07001723 mClockTickVibePattern = getLongIntArray(mContext.getResources(),
1724 com.android.internal.R.array.config_clockTickVibePattern);
Fabrice Di Megliobd9152f2013-10-01 11:21:31 -07001725 mCalendarDateVibePattern = getLongIntArray(mContext.getResources(),
1726 com.android.internal.R.array.config_calendarDateVibePattern);
Dianne Hackbornb1a79802009-09-29 15:18:31 -07001727 mSafeModeDisabledVibePattern = getLongIntArray(mContext.getResources(),
1728 com.android.internal.R.array.config_safeModeDisabledVibePattern);
1729 mSafeModeEnabledVibePattern = getLongIntArray(mContext.getResources(),
1730 com.android.internal.R.array.config_safeModeEnabledVibePattern);
Mady Mellore8608912015-06-05 09:02:55 -07001731 mContextClickVibePattern = getLongIntArray(mContext.getResources(),
1732 com.android.internal.R.array.config_contextClickVibePattern);
Daniel Sandler40427442010-07-16 11:44:52 -04001733
Christopher Tatee90585f2012-03-05 18:56:25 -08001734 mScreenshotChordEnabled = mContext.getResources().getBoolean(
1735 com.android.internal.R.bool.config_enableScreenshotChord);
Jorim Jaggi406585a2015-12-21 10:58:56 +01001736 mForceWindowDrawsStatusBarBackground = mContext.getResources().getBoolean(
1737 R.bool.config_forceWindowDrawsStatusBarBackground);
Christopher Tatee90585f2012-03-05 18:56:25 -08001738
Justin Kohd378ad72013-04-01 12:18:26 -07001739 mGlobalKeyManager = new GlobalKeyManager(mContext);
1740
Joe Onoratoea495d42011-04-06 11:41:11 -07001741 // Controls rotation and the like.
1742 initializeHdmiState();
Dianne Hackborn40011092011-09-22 13:37:48 -07001743
1744 // Match current screen state.
Craig Mautnera631d492014-08-05 15:16:01 -07001745 if (!mPowerManager.isInteractive()) {
Jeff Brown416c49c2015-05-26 19:50:18 -07001746 startedGoingToSleep(WindowManagerPolicy.OFF_BECAUSE_OF_USER);
1747 finishedGoingToSleep(WindowManagerPolicy.OFF_BECAUSE_OF_USER);
Dianne Hackborn40011092011-09-22 13:37:48 -07001748 }
Jorim Jaggi24bec7c2015-02-04 12:40:14 +01001749
1750 mWindowManagerInternal.registerAppTransitionListener(
1751 mStatusBarController.getAppTransitionListener());
Mike Lockwood1753f7f2009-08-24 14:49:07 -07001752 }
1753
Jeff Brownf71343d2013-05-31 17:59:11 -07001754 /**
1755 * Read values from config.xml that may be overridden depending on
1756 * the configuration of the device.
1757 * eg. Disable long press on home goes to recents on sw600dp.
1758 */
1759 private void readConfigurationDependentBehaviors() {
Jaewan Kimc552b042016-01-18 16:08:45 +09001760 final Resources res = mContext.getResources();
1761
1762 mLongPressOnHomeBehavior = res.getInteger(
Jeff Brownf71343d2013-05-31 17:59:11 -07001763 com.android.internal.R.integer.config_longPressOnHomeBehavior);
1764 if (mLongPressOnHomeBehavior < LONG_PRESS_HOME_NOTHING ||
Jaewan Kim52632e22016-01-14 18:01:52 +09001765 mLongPressOnHomeBehavior > LAST_LONG_PRESS_HOME_BEHAVIOR) {
Jeff Brownf71343d2013-05-31 17:59:11 -07001766 mLongPressOnHomeBehavior = LONG_PRESS_HOME_NOTHING;
1767 }
1768
Jaewan Kimc552b042016-01-18 16:08:45 +09001769 mDoubleTapOnHomeBehavior = res.getInteger(
Jeff Brownf71343d2013-05-31 17:59:11 -07001770 com.android.internal.R.integer.config_doubleTapOnHomeBehavior);
1771 if (mDoubleTapOnHomeBehavior < DOUBLE_TAP_HOME_NOTHING ||
1772 mDoubleTapOnHomeBehavior > DOUBLE_TAP_HOME_RECENT_SYSTEM_UI) {
1773 mDoubleTapOnHomeBehavior = LONG_PRESS_HOME_NOTHING;
1774 }
Jaewan Kim49117872016-01-19 17:24:08 +09001775
1776 mShortPressWindowBehavior = SHORT_PRESS_WINDOW_NOTHING;
1777 if (mContext.getPackageManager().hasSystemFeature(FEATURE_PICTURE_IN_PICTURE)) {
1778 mShortPressWindowBehavior = SHORT_PRESS_WINDOW_PICTURE_IN_PICTURE;
1779 }
Yorke Lee2e4b7322016-03-02 17:33:06 -08001780
Yorke Lee9b2ffb32016-03-07 20:42:01 -08001781 mNavBarOpacityMode = res.getInteger(
1782 com.android.internal.R.integer.config_navBarOpacityMode);
Jeff Brownf71343d2013-05-31 17:59:11 -07001783 }
1784
Craig Mautner0bf6ec92012-12-18 08:33:27 -08001785 @Override
Dianne Hackborndde331c2012-08-03 14:01:57 -07001786 public void setInitialDisplaySize(Display display, int width, int height, int density) {
Jeff Brownef981a42013-08-07 14:13:37 -07001787 // This method might be called before the policy has been fully initialized
1788 // or for other displays we don't care about.
1789 if (mContext == null || display.getDisplayId() != Display.DEFAULT_DISPLAY) {
1790 return;
Dianne Hackbornc652de82013-02-15 16:32:56 -08001791 }
Dianne Hackbornf87d1962012-04-04 12:48:24 -07001792 mDisplay = display;
1793
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001794 final Resources res = mContext.getResources();
Dianne Hackbornf87d1962012-04-04 12:48:24 -07001795 int shortSize, longSize;
Dianne Hackborn9d132642011-04-21 17:26:39 -07001796 if (width > height) {
Dianne Hackborn81e56d52011-05-26 00:55:58 -07001797 shortSize = height;
Dianne Hackbornf87d1962012-04-04 12:48:24 -07001798 longSize = width;
Dianne Hackborn9d132642011-04-21 17:26:39 -07001799 mLandscapeRotation = Surface.ROTATION_0;
1800 mSeascapeRotation = Surface.ROTATION_180;
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001801 if (res.getBoolean(com.android.internal.R.bool.config_reverseDefaultRotation)) {
Dianne Hackborn9d132642011-04-21 17:26:39 -07001802 mPortraitRotation = Surface.ROTATION_90;
1803 mUpsideDownRotation = Surface.ROTATION_270;
1804 } else {
1805 mPortraitRotation = Surface.ROTATION_270;
1806 mUpsideDownRotation = Surface.ROTATION_90;
1807 }
1808 } else {
Dianne Hackborn81e56d52011-05-26 00:55:58 -07001809 shortSize = width;
Dianne Hackbornf87d1962012-04-04 12:48:24 -07001810 longSize = height;
Dianne Hackborn9d132642011-04-21 17:26:39 -07001811 mPortraitRotation = Surface.ROTATION_0;
1812 mUpsideDownRotation = Surface.ROTATION_180;
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001813 if (res.getBoolean(com.android.internal.R.bool.config_reverseDefaultRotation)) {
Dianne Hackborn9d132642011-04-21 17:26:39 -07001814 mLandscapeRotation = Surface.ROTATION_270;
1815 mSeascapeRotation = Surface.ROTATION_90;
1816 } else {
1817 mLandscapeRotation = Surface.ROTATION_90;
1818 mSeascapeRotation = Surface.ROTATION_270;
1819 }
1820 }
Dianne Hackborn81e56d52011-05-26 00:55:58 -07001821
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001822 mStatusBarHeight =
1823 res.getDimensionPixelSize(com.android.internal.R.dimen.status_bar_height);
Dianne Hackbornf87d1962012-04-04 12:48:24 -07001824
Daniel Sandler9f65c4c2012-04-26 01:35:35 -04001825 // Height of the navigation bar when presented horizontally at bottom
Sriram Viswanathan9ebbe6a2015-11-16 17:59:22 -08001826 mNavigationBarHeightForRotationDefault[mPortraitRotation] =
1827 mNavigationBarHeightForRotationDefault[mUpsideDownRotation] =
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001828 res.getDimensionPixelSize(com.android.internal.R.dimen.navigation_bar_height);
Sriram Viswanathan9ebbe6a2015-11-16 17:59:22 -08001829 mNavigationBarHeightForRotationDefault[mLandscapeRotation] =
1830 mNavigationBarHeightForRotationDefault[mSeascapeRotation] = res.getDimensionPixelSize(
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001831 com.android.internal.R.dimen.navigation_bar_height_landscape);
Daniel Sandler9f65c4c2012-04-26 01:35:35 -04001832
1833 // Width of the navigation bar when presented vertically along one side
Sriram Viswanathan9ebbe6a2015-11-16 17:59:22 -08001834 mNavigationBarWidthForRotationDefault[mPortraitRotation] =
1835 mNavigationBarWidthForRotationDefault[mUpsideDownRotation] =
1836 mNavigationBarWidthForRotationDefault[mLandscapeRotation] =
1837 mNavigationBarWidthForRotationDefault[mSeascapeRotation] =
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001838 res.getDimensionPixelSize(com.android.internal.R.dimen.navigation_bar_width);
Daniel Sandler4a066c52012-04-20 14:49:13 -04001839
Sriram Viswanathan9ebbe6a2015-11-16 17:59:22 -08001840 // Height of the navigation bar when presented horizontally at bottom
1841 mNavigationBarHeightForRotationInCarMode[mPortraitRotation] =
1842 mNavigationBarHeightForRotationInCarMode[mUpsideDownRotation] =
1843 res.getDimensionPixelSize(
1844 com.android.internal.R.dimen.navigation_bar_height_car_mode);
1845 mNavigationBarHeightForRotationInCarMode[mLandscapeRotation] =
1846 mNavigationBarHeightForRotationInCarMode[mSeascapeRotation] = res.getDimensionPixelSize(
1847 com.android.internal.R.dimen.navigation_bar_height_landscape_car_mode);
1848
1849 // Width of the navigation bar when presented vertically along one side
1850 mNavigationBarWidthForRotationInCarMode[mPortraitRotation] =
1851 mNavigationBarWidthForRotationInCarMode[mUpsideDownRotation] =
1852 mNavigationBarWidthForRotationInCarMode[mLandscapeRotation] =
1853 mNavigationBarWidthForRotationInCarMode[mSeascapeRotation] =
1854 res.getDimensionPixelSize(
1855 com.android.internal.R.dimen.navigation_bar_width_car_mode);
1856
Daniel Sandler4a066c52012-04-20 14:49:13 -04001857 // SystemUI (status bar) layout policy
Dianne Hackborndde331c2012-08-03 14:01:57 -07001858 int shortSizeDp = shortSize * DisplayMetrics.DENSITY_DEFAULT / density;
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001859 int longSizeDp = longSize * DisplayMetrics.DENSITY_DEFAULT / density;
Daniel Sandler4a066c52012-04-20 14:49:13 -04001860
Devin Kimd7b12b42014-05-05 14:34:58 -07001861 // Allow the navigation bar to move on non-square small devices (phones).
1862 mNavigationBarCanMove = width != height && shortSizeDp < 600;
Daniel Sandler36412a72011-08-04 09:35:13 -04001863
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001864 mHasNavigationBar = res.getBoolean(com.android.internal.R.bool.config_showNavigationBar);
John Spurlock80f00c12013-06-13 11:10:51 -04001865 // Allow a system property to override this. Used by the emulator.
1866 // See also hasNavigationBar().
1867 String navBarOverride = SystemProperties.get("qemu.hw.mainkeys");
1868 if ("1".equals(navBarOverride)) {
Dianne Hackbornf87d1962012-04-04 12:48:24 -07001869 mHasNavigationBar = false;
John Spurlock80f00c12013-06-13 11:10:51 -04001870 } else if ("0".equals(navBarOverride)) {
1871 mHasNavigationBar = true;
Daniel Sandler0c4ccff2011-10-19 16:39:14 -04001872 }
1873
Jeff Brown27f1d672012-10-17 18:32:34 -07001874 // For demo purposes, allow the rotation of the HDMI display to be controlled.
1875 // By default, HDMI locks rotation to landscape.
Erik Gilling9a41ef82011-09-26 19:21:03 -07001876 if ("portrait".equals(SystemProperties.get("persist.demo.hdmirotation"))) {
Jeff Brownc82c89ed2013-04-17 17:18:15 -07001877 mDemoHdmiRotation = mPortraitRotation;
Erik Gilling9a41ef82011-09-26 19:21:03 -07001878 } else {
Jeff Brownc82c89ed2013-04-17 17:18:15 -07001879 mDemoHdmiRotation = mLandscapeRotation;
Erik Gilling9a41ef82011-09-26 19:21:03 -07001880 }
Jeff Brownc82c89ed2013-04-17 17:18:15 -07001881 mDemoHdmiRotationLock = SystemProperties.getBoolean("persist.demo.hdmirotationlock", false);
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001882
Chong Zhangae6119ff2014-11-11 18:54:39 -08001883 // For demo purposes, allow the rotation of the remote display to be controlled.
1884 // By default, remote display locks rotation to landscape.
1885 if ("portrait".equals(SystemProperties.get("persist.demo.remoterotation"))) {
1886 mDemoRotation = mPortraitRotation;
1887 } else {
1888 mDemoRotation = mLandscapeRotation;
1889 }
1890 mDemoRotationLock = SystemProperties.getBoolean(
1891 "persist.demo.rotationlock", false);
1892
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001893 // Only force the default orientation if the screen is xlarge, at least 960dp x 720dp, per
1894 // http://developer.android.com/guide/practices/screens_support.html#range
1895 mForceDefaultOrientation = longSizeDp >= 960 && shortSizeDp >= 720 &&
1896 res.getBoolean(com.android.internal.R.bool.config_forceDefaultOrientation) &&
1897 // For debug purposes the next line turns this feature off with:
1898 // $ adb shell setprop config.override_forced_orient true
1899 // $ adb shell wm size reset
1900 !"true".equals(SystemProperties.get("config.override_forced_orient"));
1901 }
1902
Alan Viverette5a0f4ec2013-10-07 15:10:29 -07001903 /**
1904 * @return whether the navigation bar can be hidden, e.g. the device has a
1905 * navigation bar and touch exploration is not enabled
1906 */
1907 private boolean canHideNavigationBar() {
Alan Viverette817f3cd2015-08-13 11:40:14 -04001908 return mHasNavigationBar;
Alan Viverette5a0f4ec2013-10-07 15:10:29 -07001909 }
1910
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001911 @Override
1912 public boolean isDefaultOrientationForced() {
1913 return mForceDefaultOrientation;
Dianne Hackborn9d132642011-04-21 17:26:39 -07001914 }
1915
Dianne Hackbornc652de82013-02-15 16:32:56 -08001916 @Override
1917 public void setDisplayOverscan(Display display, int left, int top, int right, int bottom) {
1918 if (display.getDisplayId() == Display.DEFAULT_DISPLAY) {
1919 mOverscanLeft = left;
1920 mOverscanTop = top;
1921 mOverscanRight = right;
1922 mOverscanBottom = bottom;
1923 }
1924 }
1925
Dianne Hackbornc777e072010-02-12 13:07:59 -08001926 public void updateSettings() {
1927 ContentResolver resolver = mContext.getContentResolver();
1928 boolean updateRotation = false;
Dianne Hackbornc777e072010-02-12 13:07:59 -08001929 synchronized (mLock) {
Christopher Tate5e08af02012-09-21 17:17:22 -07001930 mEndcallBehavior = Settings.System.getIntForUser(resolver,
David Brownbaf8d092010-03-08 21:52:59 -08001931 Settings.System.END_BUTTON_BEHAVIOR,
Christopher Tate5e08af02012-09-21 17:17:22 -07001932 Settings.System.END_BUTTON_BEHAVIOR_DEFAULT,
1933 UserHandle.USER_CURRENT);
1934 mIncallPowerBehavior = Settings.Secure.getIntForUser(resolver,
David Brownbaf8d092010-03-08 21:52:59 -08001935 Settings.Secure.INCALL_POWER_BUTTON_BEHAVIOR,
Christopher Tate5e08af02012-09-21 17:17:22 -07001936 Settings.Secure.INCALL_POWER_BUTTON_BEHAVIOR_DEFAULT,
1937 UserHandle.USER_CURRENT);
Daniel Sandlerb73617d2010-08-17 00:41:00 -04001938
Jeff Browna20dda42014-05-27 20:57:24 -07001939 // Configure wake gesture.
1940 boolean wakeGestureEnabledSetting = Settings.Secure.getIntForUser(resolver,
1941 Settings.Secure.WAKE_GESTURE_ENABLED, 0,
1942 UserHandle.USER_CURRENT) != 0;
1943 if (mWakeGestureEnabledSetting != wakeGestureEnabledSetting) {
1944 mWakeGestureEnabledSetting = wakeGestureEnabledSetting;
1945 updateWakeGestureListenerLp();
1946 }
1947
Jeff Brown207673cd2012-06-05 17:47:11 -07001948 // Configure rotation lock.
Christopher Tate5e08af02012-09-21 17:17:22 -07001949 int userRotation = Settings.System.getIntForUser(resolver,
1950 Settings.System.USER_ROTATION, Surface.ROTATION_0,
1951 UserHandle.USER_CURRENT);
Jeff Brown207673cd2012-06-05 17:47:11 -07001952 if (mUserRotation != userRotation) {
1953 mUserRotation = userRotation;
1954 updateRotation = true;
1955 }
Christopher Tate5e08af02012-09-21 17:17:22 -07001956 int userRotationMode = Settings.System.getIntForUser(resolver,
1957 Settings.System.ACCELEROMETER_ROTATION, 0, UserHandle.USER_CURRENT) != 0 ?
Jeff Brown207673cd2012-06-05 17:47:11 -07001958 WindowManagerPolicy.USER_ROTATION_FREE :
1959 WindowManagerPolicy.USER_ROTATION_LOCKED;
1960 if (mUserRotationMode != userRotationMode) {
1961 mUserRotationMode = userRotationMode;
1962 updateRotation = true;
Dianne Hackbornc777e072010-02-12 13:07:59 -08001963 updateOrientationListenerLp();
1964 }
Daniel Sandlerb73617d2010-08-17 00:41:00 -04001965
Dianne Hackbornc777e072010-02-12 13:07:59 -08001966 if (mSystemReady) {
Christopher Tate5e08af02012-09-21 17:17:22 -07001967 int pointerLocation = Settings.System.getIntForUser(resolver,
1968 Settings.System.POINTER_LOCATION, 0, UserHandle.USER_CURRENT);
Dianne Hackbornc777e072010-02-12 13:07:59 -08001969 if (mPointerLocationMode != pointerLocation) {
1970 mPointerLocationMode = pointerLocation;
Jeff Brown70825162012-03-28 17:27:48 -07001971 mHandler.sendEmptyMessage(pointerLocation != 0 ?
1972 MSG_ENABLE_POINTER_LOCATION : MSG_DISABLE_POINTER_LOCATION);
Dianne Hackbornc777e072010-02-12 13:07:59 -08001973 }
1974 }
1975 // use screen off timeout setting as the timeout for the lockscreen
Christopher Tate5e08af02012-09-21 17:17:22 -07001976 mLockScreenTimeout = Settings.System.getIntForUser(resolver,
1977 Settings.System.SCREEN_OFF_TIMEOUT, 0, UserHandle.USER_CURRENT);
1978 String imId = Settings.Secure.getStringForUser(resolver,
1979 Settings.Secure.DEFAULT_INPUT_METHOD, UserHandle.USER_CURRENT);
Dianne Hackbornc777e072010-02-12 13:07:59 -08001980 boolean hasSoftInput = imId != null && imId.length() > 0;
1981 if (mHasSoftInput != hasSoftInput) {
1982 mHasSoftInput = hasSoftInput;
1983 updateRotation = true;
1984 }
John Spurlockf1a36642013-10-12 17:50:42 -04001985 if (mImmersiveModeConfirmation != null) {
John Spurlock4355a532014-02-19 09:49:25 -05001986 mImmersiveModeConfirmation.loadSetting(mCurrentUserId);
John Spurlockd67ec252013-09-05 11:31:54 -04001987 }
tiger_huangcc6366d2015-06-29 17:17:30 +08001988 }
1989 synchronized (mWindowManagerFuncs.getWindowManagerLock()) {
John Spurlockc6d1c602014-01-17 15:22:06 -05001990 PolicyControl.reloadFromSetting(mContext);
Dianne Hackbornc777e072010-02-12 13:07:59 -08001991 }
1992 if (updateRotation) {
Jeff Brown01a98dd2011-09-20 15:08:29 -07001993 updateRotation(true);
Dianne Hackbornc777e072010-02-12 13:07:59 -08001994 }
Jeff Brown70825162012-03-28 17:27:48 -07001995 }
1996
Jeff Browna20dda42014-05-27 20:57:24 -07001997 private void updateWakeGestureListenerLp() {
1998 if (shouldEnableWakeGestureLp()) {
1999 mWakeGestureListener.requestWakeUpTrigger();
2000 } else {
2001 mWakeGestureListener.cancelWakeUpTrigger();
2002 }
2003 }
2004
2005 private boolean shouldEnableWakeGestureLp() {
Jeff Brown3ee549c2014-09-22 20:14:39 -07002006 return mWakeGestureEnabledSetting && !mAwake
Jeff Browna20dda42014-05-27 20:57:24 -07002007 && (!mLidControlsSleep || mLidState != LID_CLOSED)
2008 && mWakeGestureListener.isSupported();
2009 }
2010
Jeff Brown70825162012-03-28 17:27:48 -07002011 private void enablePointerLocation() {
2012 if (mPointerLocationView == null) {
2013 mPointerLocationView = new PointerLocationView(mContext);
2014 mPointerLocationView.setPrintCoords(false);
Dianne Hackbornc777e072010-02-12 13:07:59 -08002015 WindowManager.LayoutParams lp = new WindowManager.LayoutParams(
2016 WindowManager.LayoutParams.MATCH_PARENT,
2017 WindowManager.LayoutParams.MATCH_PARENT);
Jeff Brown3b2b3542010-10-15 00:54:27 -07002018 lp.type = WindowManager.LayoutParams.TYPE_SECURE_SYSTEM_OVERLAY;
Jeff Brownbfcb60a2011-09-08 18:51:14 -07002019 lp.flags = WindowManager.LayoutParams.FLAG_FULLSCREEN
2020 | WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE
2021 | WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE
2022 | WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN;
Jeff Brown90fc9052012-10-01 14:44:24 -07002023 if (ActivityManager.isHighEndGfx()) {
2024 lp.flags |= WindowManager.LayoutParams.FLAG_HARDWARE_ACCELERATED;
2025 lp.privateFlags |=
2026 WindowManager.LayoutParams.PRIVATE_FLAG_FORCE_HARDWARE_ACCELERATED;
2027 }
Dianne Hackbornc777e072010-02-12 13:07:59 -08002028 lp.format = PixelFormat.TRANSLUCENT;
2029 lp.setTitle("PointerLocation");
Dianne Hackborn5fd21692011-06-07 14:09:47 -07002030 WindowManager wm = (WindowManager)
Dianne Hackbornc777e072010-02-12 13:07:59 -08002031 mContext.getSystemService(Context.WINDOW_SERVICE);
Jeff Browncc4f7db2011-08-30 20:34:48 -07002032 lp.inputFeatures |= WindowManager.LayoutParams.INPUT_FEATURE_NO_INPUT_CHANNEL;
Jeff Brown70825162012-03-28 17:27:48 -07002033 wm.addView(mPointerLocationView, lp);
Michael Wrightc9c487e2013-11-07 18:55:09 -08002034 mWindowManagerFuncs.registerPointerEventListener(mPointerLocationView);
Dianne Hackbornc777e072010-02-12 13:07:59 -08002035 }
Dianne Hackbornc777e072010-02-12 13:07:59 -08002036 }
Jeff Brown70825162012-03-28 17:27:48 -07002037
2038 private void disablePointerLocation() {
Jeff Brown70825162012-03-28 17:27:48 -07002039 if (mPointerLocationView != null) {
Michael Wrightc9c487e2013-11-07 18:55:09 -08002040 mWindowManagerFuncs.unregisterPointerEventListener(mPointerLocationView);
2041 WindowManager wm = (WindowManager) mContext.getSystemService(Context.WINDOW_SERVICE);
Jeff Brown70825162012-03-28 17:27:48 -07002042 wm.removeView(mPointerLocationView);
2043 mPointerLocationView = null;
2044 }
2045 }
2046
Mike Lockwood2d1efbd2009-09-16 12:15:53 -04002047 private int readRotation(int resID) {
Mike Lockwood1753f7f2009-08-24 14:49:07 -07002048 try {
2049 int rotation = mContext.getResources().getInteger(resID);
2050 switch (rotation) {
2051 case 0:
2052 return Surface.ROTATION_0;
2053 case 90:
2054 return Surface.ROTATION_90;
2055 case 180:
2056 return Surface.ROTATION_180;
2057 case 270:
2058 return Surface.ROTATION_270;
Mike Lockwood1753f7f2009-08-24 14:49:07 -07002059 }
2060 } catch (Resources.NotFoundException e) {
Mike Lockwood2d1efbd2009-09-16 12:15:53 -04002061 // fall through
Mike Lockwood1753f7f2009-08-24 14:49:07 -07002062 }
Mike Lockwood2d1efbd2009-09-16 12:15:53 -04002063 return -1;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002064 }
2065
2066 /** {@inheritDoc} */
Craig Mautner88400d32012-09-30 12:35:45 -07002067 @Override
Dianne Hackbornc2293022013-02-06 23:14:49 -08002068 public int checkAddPermission(WindowManager.LayoutParams attrs, int[] outAppOp) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002069 int type = attrs.type;
Dianne Hackbornc2293022013-02-06 23:14:49 -08002070
2071 outAppOp[0] = AppOpsManager.OP_NONE;
2072
Wale Ogunwale74bf0652015-01-12 10:24:36 -08002073 if (!((type >= FIRST_APPLICATION_WINDOW && type <= LAST_APPLICATION_WINDOW)
2074 || (type >= FIRST_SUB_WINDOW && type <= LAST_SUB_WINDOW)
2075 || (type >= FIRST_SYSTEM_WINDOW && type <= LAST_SYSTEM_WINDOW))) {
2076 return WindowManagerGlobal.ADD_INVALID_TYPE;
2077 }
2078
2079 if (type < FIRST_SYSTEM_WINDOW || type > LAST_SYSTEM_WINDOW) {
2080 // Window manager will make sure these are okay.
Jeff Brown98365d72012-08-19 20:30:52 -07002081 return WindowManagerGlobal.ADD_OKAY;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002082 }
2083 String permission = null;
2084 switch (type) {
2085 case TYPE_TOAST:
2086 // XXX right now the app process has complete control over
2087 // this... should introduce a token to let the system
2088 // monitor/control what they are doing.
Jason Monk1c7c3192014-06-26 12:52:18 -04002089 outAppOp[0] = AppOpsManager.OP_TOAST_WINDOW;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002090 break;
Daniel Sandler7d276c32012-01-30 14:33:52 -05002091 case TYPE_DREAM:
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002092 case TYPE_INPUT_METHOD:
Dianne Hackbornb7cd8b92009-08-08 20:53:03 -07002093 case TYPE_WALLPAPER:
keunyounga446bf02013-06-21 19:07:57 -07002094 case TYPE_PRIVATE_PRESENTATION:
Dianne Hackborne30e02f2014-05-27 18:24:45 -07002095 case TYPE_VOICE_INTERACTION:
Svetoslav3a5c7212014-10-14 09:54:26 -07002096 case TYPE_ACCESSIBILITY_OVERLAY:
Jason Monk8f7f3182015-11-18 16:35:14 -05002097 case TYPE_QS_DIALOG:
Dianne Hackbornb7cd8b92009-08-08 20:53:03 -07002098 // The window manager will check these.
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002099 break;
2100 case TYPE_PHONE:
2101 case TYPE_PRIORITY_PHONE:
2102 case TYPE_SYSTEM_ALERT:
2103 case TYPE_SYSTEM_ERROR:
2104 case TYPE_SYSTEM_OVERLAY:
2105 permission = android.Manifest.permission.SYSTEM_ALERT_WINDOW;
Dianne Hackbornc2293022013-02-06 23:14:49 -08002106 outAppOp[0] = AppOpsManager.OP_SYSTEM_ALERT_WINDOW;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002107 break;
2108 default:
2109 permission = android.Manifest.permission.INTERNAL_SYSTEM_WINDOW;
2110 }
2111 if (permission != null) {
Svet Ganov9cea80cd2016-02-16 11:47:00 -08002112 if (android.Manifest.permission.SYSTEM_ALERT_WINDOW.equals(permission)) {
Billy Laucbe540f2015-06-25 01:51:44 +01002113 final int callingUid = Binder.getCallingUid();
Billy Lau060275f2015-07-15 22:29:19 +01002114 // system processes will be automatically allowed privilege to draw
Billy Laucbe540f2015-06-25 01:51:44 +01002115 if (callingUid == Process.SYSTEM_UID) {
2116 return WindowManagerGlobal.ADD_OKAY;
2117 }
2118
Billy Lau060275f2015-07-15 22:29:19 +01002119 // check if user has enabled this operation. SecurityException will be thrown if
2120 // this app has not been allowed by the user
Svet Ganov03f2afc2016-03-04 16:13:03 -08002121 final int mode = mAppOpsManager.checkOpNoThrow(outAppOp[0], callingUid,
Billy Laucbe540f2015-06-25 01:51:44 +01002122 attrs.packageName);
Billy Lau060275f2015-07-15 22:29:19 +01002123 switch (mode) {
2124 case AppOpsManager.MODE_ALLOWED:
2125 case AppOpsManager.MODE_IGNORED:
2126 // although we return ADD_OKAY for MODE_IGNORED, the added window will
2127 // actually be hidden in WindowManagerService
2128 return WindowManagerGlobal.ADD_OKAY;
2129 case AppOpsManager.MODE_ERRORED:
Svet Ganov03f2afc2016-03-04 16:13:03 -08002130 try {
2131 ApplicationInfo appInfo = mContext.getPackageManager()
2132 .getApplicationInfo(attrs.packageName,
2133 UserHandle.getUserId(callingUid));
2134 // Don't crash legacy apps
2135 if (appInfo.targetSdkVersion < Build.VERSION_CODES.M) {
2136 return WindowManagerGlobal.ADD_OKAY;
2137 }
2138 } catch (PackageManager.NameNotFoundException e) {
2139 /* ignore */
2140 }
Billy Laucbe540f2015-06-25 01:51:44 +01002141 return WindowManagerGlobal.ADD_PERMISSION_DENIED;
Billy Lau060275f2015-07-15 22:29:19 +01002142 default:
2143 // in the default mode, we will make a decision here based on
2144 // checkCallingPermission()
2145 if (mContext.checkCallingPermission(permission) !=
2146 PackageManager.PERMISSION_GRANTED) {
2147 return WindowManagerGlobal.ADD_PERMISSION_DENIED;
2148 } else {
2149 return WindowManagerGlobal.ADD_OKAY;
2150 }
Billy Laucbe540f2015-06-25 01:51:44 +01002151 }
Billy Laucbe540f2015-06-25 01:51:44 +01002152 }
2153
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002154 if (mContext.checkCallingOrSelfPermission(permission)
2155 != PackageManager.PERMISSION_GRANTED) {
Jeff Brown98365d72012-08-19 20:30:52 -07002156 return WindowManagerGlobal.ADD_PERMISSION_DENIED;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002157 }
2158 }
Jeff Brown98365d72012-08-19 20:30:52 -07002159 return WindowManagerGlobal.ADD_OKAY;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002160 }
Craig Mautner88400d32012-09-30 12:35:45 -07002161
2162 @Override
2163 public boolean checkShowToOwnerOnly(WindowManager.LayoutParams attrs) {
2164
2165 // If this switch statement is modified, modify the comment in the declarations of
2166 // the type in {@link WindowManager.LayoutParams} as well.
2167 switch (attrs.type) {
2168 default:
2169 // These are the windows that by default are shown only to the user that created
2170 // them. If this needs to be overridden, set
2171 // {@link WindowManager.LayoutParams.PRIVATE_FLAG_SHOW_FOR_ALL_USERS} in
2172 // {@link WindowManager.LayoutParams}. Note that permission
2173 // {@link android.Manifest.permission.INTERNAL_SYSTEM_WINDOW} is required as well.
2174 if ((attrs.privateFlags & PRIVATE_FLAG_SHOW_FOR_ALL_USERS) == 0) {
2175 return true;
2176 }
2177 break;
2178
2179 // These are the windows that by default are shown to all users. However, to
2180 // protect against spoofing, check permissions below.
2181 case TYPE_APPLICATION_STARTING:
2182 case TYPE_BOOT_PROGRESS:
2183 case TYPE_DISPLAY_OVERLAY:
Selim Cinekf83e8242015-05-19 18:08:14 -07002184 case TYPE_INPUT_CONSUMER:
Jim Miller5ecd8112013-01-09 18:50:26 -08002185 case TYPE_KEYGUARD_SCRIM:
Craig Mautner88400d32012-09-30 12:35:45 -07002186 case TYPE_KEYGUARD_DIALOG:
2187 case TYPE_MAGNIFICATION_OVERLAY:
2188 case TYPE_NAVIGATION_BAR:
2189 case TYPE_NAVIGATION_BAR_PANEL:
2190 case TYPE_PHONE:
2191 case TYPE_POINTER:
2192 case TYPE_PRIORITY_PHONE:
Craig Mautner88400d32012-09-30 12:35:45 -07002193 case TYPE_SEARCH_BAR:
2194 case TYPE_STATUS_BAR:
2195 case TYPE_STATUS_BAR_PANEL:
2196 case TYPE_STATUS_BAR_SUB_PANEL:
2197 case TYPE_SYSTEM_DIALOG:
Craig Mautner88400d32012-09-30 12:35:45 -07002198 case TYPE_VOLUME_OVERLAY:
keunyounga446bf02013-06-21 19:07:57 -07002199 case TYPE_PRIVATE_PRESENTATION:
Filip Gruszczynski466f3212015-09-21 17:57:57 -07002200 case TYPE_DOCK_DIVIDER:
Craig Mautner88400d32012-09-30 12:35:45 -07002201 break;
2202 }
2203
2204 // Check if third party app has set window to system window type.
2205 return mContext.checkCallingOrSelfPermission(
2206 android.Manifest.permission.INTERNAL_SYSTEM_WINDOW)
2207 != PackageManager.PERMISSION_GRANTED;
2208 }
2209
Craig Mautner967212c2013-04-13 21:10:58 -07002210 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002211 public void adjustWindowParamsLw(WindowManager.LayoutParams attrs) {
2212 switch (attrs.type) {
2213 case TYPE_SYSTEM_OVERLAY:
Jeff Brown3b2b3542010-10-15 00:54:27 -07002214 case TYPE_SECURE_SYSTEM_OVERLAY:
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002215 // These types of windows can't receive input events.
2216 attrs.flags |= WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE
2217 | WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE;
Jeff Brownbfcb60a2011-09-08 18:51:14 -07002218 attrs.flags &= ~WindowManager.LayoutParams.FLAG_WATCH_OUTSIDE_TOUCH;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002219 break;
Jorim Jaggi380ecb82014-03-14 17:25:20 +01002220 case TYPE_STATUS_BAR:
2221
2222 // If the Keyguard is in a hidden state (occluded by another window), we force to
2223 // remove the wallpaper and keyguard flag so that any change in-flight after setting
2224 // the keyguard as occluded wouldn't set these flags again.
2225 // See {@link #processKeyguardSetHiddenResultLw}.
2226 if (mKeyguardHidden) {
2227 attrs.flags &= ~WindowManager.LayoutParams.FLAG_SHOW_WALLPAPER;
2228 attrs.privateFlags &= ~WindowManager.LayoutParams.PRIVATE_FLAG_KEYGUARD;
2229 }
2230 break;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002231 }
Adrian Roos38502112014-04-09 21:04:11 +02002232
2233 if (attrs.type != TYPE_STATUS_BAR) {
2234 // The status bar is the only window allowed to exhibit keyguard behavior.
2235 attrs.privateFlags &= ~WindowManager.LayoutParams.PRIVATE_FLAG_KEYGUARD;
2236 }
Adrian Roosea562512014-05-05 13:33:03 +02002237
Jorim Jaggi4fa78922015-11-30 17:13:56 -08002238 if (ActivityManager.isHighEndGfx()) {
2239 if ((attrs.flags & FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS) != 0) {
2240 attrs.subtreeSystemUiVisibility |= View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION;
2241 }
2242 if ((attrs.flags & FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS) != 0
Jorim Jaggi406585a2015-12-21 10:58:56 +01002243 || (mForceWindowDrawsStatusBarBackground
2244 && attrs.height == MATCH_PARENT && attrs.width == MATCH_PARENT)) {
Jorim Jaggi4fa78922015-11-30 17:13:56 -08002245 attrs.subtreeSystemUiVisibility |= View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN;
2246 }
Adrian Roosea562512014-05-05 13:33:03 +02002247 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002248 }
RoboErik8a2cfc32014-05-16 11:19:38 -07002249
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002250 void readLidState() {
Jeff Brown2e7760e2012-04-11 15:14:55 -07002251 mLidState = mWindowManagerFuncs.getLidState();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002252 }
RoboErik8a2cfc32014-05-16 11:19:38 -07002253
Michael Wright3818c922014-09-02 13:59:07 -07002254 private void readCameraLensCoverState() {
2255 mCameraLensCoverState = mWindowManagerFuncs.getCameraLensCoverState();
2256 }
2257
Jeff Browndaa37532012-05-01 15:54:03 -07002258 private boolean isHidden(int accessibilityMode) {
2259 switch (accessibilityMode) {
2260 case 1:
2261 return mLidState == LID_CLOSED;
2262 case 2:
2263 return mLidState == LID_OPEN;
2264 default:
2265 return false;
Dianne Hackborn2862fff2009-09-15 22:56:29 -07002266 }
Dianne Hackborn2862fff2009-09-15 22:56:29 -07002267 }
Jeff Brownd04a88c2011-01-16 14:05:47 -08002268
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002269 /** {@inheritDoc} */
Craig Mautner967212c2013-04-13 21:10:58 -07002270 @Override
Jeff Browndaa37532012-05-01 15:54:03 -07002271 public void adjustConfigurationLw(Configuration config, int keyboardPresence,
2272 int navigationPresence) {
2273 mHaveBuiltInKeyboard = (keyboardPresence & PRESENCE_INTERNAL) != 0;
2274
Jeff Brownf71343d2013-05-31 17:59:11 -07002275 readConfigurationDependentBehaviors();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002276 readLidState();
Jeff Brownc458ce92012-04-30 14:58:40 -07002277 applyLidSwitchState();
Jeff Brownd04a88c2011-01-16 14:05:47 -08002278
Jeff Browndaa37532012-05-01 15:54:03 -07002279 if (config.keyboard == Configuration.KEYBOARD_NOKEYS
2280 || (keyboardPresence == PRESENCE_INTERNAL
2281 && isHidden(mLidKeyboardAccessibility))) {
Jeff Brownd04a88c2011-01-16 14:05:47 -08002282 config.hardKeyboardHidden = Configuration.HARDKEYBOARDHIDDEN_YES;
Jeff Browndaa37532012-05-01 15:54:03 -07002283 if (!mHasSoftInput) {
2284 config.keyboardHidden = Configuration.KEYBOARDHIDDEN_YES;
2285 }
Jeff Brownd04a88c2011-01-16 14:05:47 -08002286 }
2287
Jeff Browndaa37532012-05-01 15:54:03 -07002288 if (config.navigation == Configuration.NAVIGATION_NONAV
2289 || (navigationPresence == PRESENCE_INTERNAL
2290 && isHidden(mLidNavigationAccessibility))) {
Jeff Brownd04a88c2011-01-16 14:05:47 -08002291 config.navigationHidden = Configuration.NAVIGATIONHIDDEN_YES;
Jeff Brownd04a88c2011-01-16 14:05:47 -08002292 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002293 }
Jeff Brownd04a88c2011-01-16 14:05:47 -08002294
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002295 /** {@inheritDoc} */
Craig Mautner967212c2013-04-13 21:10:58 -07002296 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002297 public int windowTypeToLayerLw(int type) {
2298 if (type >= FIRST_APPLICATION_WINDOW && type <= LAST_APPLICATION_WINDOW) {
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07002299 return 2;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002300 }
2301 switch (type) {
keunyounga446bf02013-06-21 19:07:57 -07002302 case TYPE_PRIVATE_PRESENTATION:
2303 return 2;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07002304 case TYPE_WALLPAPER:
2305 // wallpaper is at the bottom, though the window manager may move it.
2306 return 2;
Filip Gruszczynskie95b0ae2015-09-30 10:55:33 -07002307 case TYPE_DOCK_DIVIDER:
2308 return 2;
Jason Monk8f7f3182015-11-18 16:35:14 -05002309 case TYPE_QS_DIALOG:
2310 return 2;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07002311 case TYPE_PHONE:
2312 return 3;
2313 case TYPE_SEARCH_BAR:
Jorim Jaggi225d3b52015-04-01 11:18:57 -07002314 case TYPE_VOICE_INTERACTION_STARTING:
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07002315 return 4;
Dianne Hackborne30e02f2014-05-27 18:24:45 -07002316 case TYPE_VOICE_INTERACTION:
2317 // voice interaction layer is almost immediately above apps.
2318 return 5;
Selim Cinekf83e8242015-05-19 18:08:14 -07002319 case TYPE_INPUT_CONSUMER:
Dianne Hackborne30e02f2014-05-27 18:24:45 -07002320 return 6;
Selim Cinekf83e8242015-05-19 18:08:14 -07002321 case TYPE_SYSTEM_DIALOG:
2322 return 7;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07002323 case TYPE_TOAST:
2324 // toasts and the plugged-in battery thing
Selim Cinekf83e8242015-05-19 18:08:14 -07002325 return 8;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07002326 case TYPE_PRIORITY_PHONE:
2327 // SIM errors and unlock. Not sure if this really should be in a high layer.
Selim Cinekf83e8242015-05-19 18:08:14 -07002328 return 9;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07002329 case TYPE_DREAM:
2330 // used for Dreams (screensavers with TYPE_DREAM windows)
Selim Cinekf83e8242015-05-19 18:08:14 -07002331 return 10;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07002332 case TYPE_SYSTEM_ALERT:
2333 // like the ANR / app crashed dialogs
Selim Cinekf83e8242015-05-19 18:08:14 -07002334 return 11;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07002335 case TYPE_INPUT_METHOD:
2336 // on-screen keyboards and other such input method user interfaces go here.
Selim Cinekf83e8242015-05-19 18:08:14 -07002337 return 12;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07002338 case TYPE_INPUT_METHOD_DIALOG:
2339 // on-screen keyboards and other such input method user interfaces go here.
Selim Cinekf83e8242015-05-19 18:08:14 -07002340 return 13;
Jim Miller5ecd8112013-01-09 18:50:26 -08002341 case TYPE_KEYGUARD_SCRIM:
2342 // the safety window that shows behind keyguard while keyguard is starting
Filip Gruszczynskie95b0ae2015-09-30 10:55:33 -07002343 return 14;
Filip Gruszczynski466f3212015-09-21 17:57:57 -07002344 case TYPE_STATUS_BAR_SUB_PANEL:
Filip Gruszczynskie95b0ae2015-09-30 10:55:33 -07002345 return 15;
Filip Gruszczynski466f3212015-09-21 17:57:57 -07002346 case TYPE_STATUS_BAR:
Filip Gruszczynskie95b0ae2015-09-30 10:55:33 -07002347 return 16;
Filip Gruszczynski466f3212015-09-21 17:57:57 -07002348 case TYPE_STATUS_BAR_PANEL:
Filip Gruszczynskie95b0ae2015-09-30 10:55:33 -07002349 return 17;
Filip Gruszczynski466f3212015-09-21 17:57:57 -07002350 case TYPE_KEYGUARD_DIALOG:
Filip Gruszczynskie95b0ae2015-09-30 10:55:33 -07002351 return 18;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07002352 case TYPE_VOLUME_OVERLAY:
2353 // the on-screen volume indicator and controller shown when the user
2354 // changes the device volume
Filip Gruszczynskie95b0ae2015-09-30 10:55:33 -07002355 return 19;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07002356 case TYPE_SYSTEM_OVERLAY:
2357 // the on-screen volume indicator and controller shown when the user
2358 // changes the device volume
Filip Gruszczynskie95b0ae2015-09-30 10:55:33 -07002359 return 20;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07002360 case TYPE_NAVIGATION_BAR:
2361 // the navigation bar, if available, shows atop most things
Filip Gruszczynskie95b0ae2015-09-30 10:55:33 -07002362 return 21;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07002363 case TYPE_NAVIGATION_BAR_PANEL:
2364 // some panels (e.g. search) need to show on top of the navigation bar
Filip Gruszczynskie95b0ae2015-09-30 10:55:33 -07002365 return 22;
Muyuan Li6ca619f2016-03-08 13:30:42 -08002366 case TYPE_SCREENSHOT:
2367 // screenshot selection layer shouldn't go above system error, but it should cover
2368 // navigation bars at the very least.
2369 return 23;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07002370 case TYPE_SYSTEM_ERROR:
2371 // system-level error dialogs
Muyuan Li6ca619f2016-03-08 13:30:42 -08002372 return 24;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07002373 case TYPE_MAGNIFICATION_OVERLAY:
2374 // used to highlight the magnified portion of a display
Muyuan Li6ca619f2016-03-08 13:30:42 -08002375 return 25;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07002376 case TYPE_DISPLAY_OVERLAY:
2377 // used to simulate secondary display devices
Muyuan Li6ca619f2016-03-08 13:30:42 -08002378 return 26;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07002379 case TYPE_DRAG:
2380 // the drag layer: input for drag-and-drop is associated with this window,
2381 // which sits above all other focusable windows
Muyuan Li6ca619f2016-03-08 13:30:42 -08002382 return 27;
Svetoslav3a5c7212014-10-14 09:54:26 -07002383 case TYPE_ACCESSIBILITY_OVERLAY:
2384 // overlay put by accessibility services to intercept user interaction
Filip Gruszczynskie95b0ae2015-09-30 10:55:33 -07002385 return 28;
Muyuan Li6ca619f2016-03-08 13:30:42 -08002386 case TYPE_SECURE_SYSTEM_OVERLAY:
Filip Gruszczynskie95b0ae2015-09-30 10:55:33 -07002387 return 29;
Muyuan Li6ca619f2016-03-08 13:30:42 -08002388 case TYPE_BOOT_PROGRESS:
2389 return 30;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07002390 case TYPE_POINTER:
2391 // the (mouse) pointer layer
Muyuan Li6ca619f2016-03-08 13:30:42 -08002392 return 31;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002393 }
2394 Log.e(TAG, "Unknown window type: " + type);
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07002395 return 2;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002396 }
2397
2398 /** {@inheritDoc} */
Craig Mautner46ac6fa2013-08-01 10:06:34 -07002399 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002400 public int subWindowTypeToLayerLw(int type) {
2401 switch (type) {
2402 case TYPE_APPLICATION_PANEL:
2403 case TYPE_APPLICATION_ATTACHED_DIALOG:
2404 return APPLICATION_PANEL_SUBLAYER;
2405 case TYPE_APPLICATION_MEDIA:
2406 return APPLICATION_MEDIA_SUBLAYER;
Dianne Hackborn5cb8d792009-05-21 17:34:15 -07002407 case TYPE_APPLICATION_MEDIA_OVERLAY:
2408 return APPLICATION_MEDIA_OVERLAY_SUBLAYER;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002409 case TYPE_APPLICATION_SUB_PANEL:
2410 return APPLICATION_SUB_PANEL_SUBLAYER;
Wale Ogunwale0a4dc222015-04-14 12:58:42 -07002411 case TYPE_APPLICATION_ABOVE_SUB_PANEL:
2412 return APPLICATION_ABOVE_SUB_PANEL_SUBLAYER;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002413 }
2414 Log.e(TAG, "Unknown sub-window type: " + type);
2415 return 0;
2416 }
2417
Craig Mautner46ac6fa2013-08-01 10:06:34 -07002418 @Override
Dianne Hackbornabe0da02009-09-18 01:55:39 -07002419 public int getMaxWallpaperLayer() {
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07002420 return windowTypeToLayerLw(TYPE_STATUS_BAR);
Dianne Hackbornabe0da02009-09-18 01:55:39 -07002421 }
2422
Sriram Viswanathan9ebbe6a2015-11-16 17:59:22 -08002423 private int getNavigationBarWidth(int rotation, int uiMode) {
2424 if ((uiMode & UI_MODE_TYPE_MASK) == UI_MODE_TYPE_CAR) {
2425 return mNavigationBarWidthForRotationInCarMode[rotation];
2426 } else {
2427 return mNavigationBarWidthForRotationDefault[rotation];
2428 }
2429 }
2430
Craig Mautner46ac6fa2013-08-01 10:06:34 -07002431 @Override
Sriram Viswanathan9ebbe6a2015-11-16 17:59:22 -08002432 public int getNonDecorDisplayWidth(int fullWidth, int fullHeight, int rotation,
2433 int uiMode) {
Dianne Hackborn077ee852012-04-09 16:27:07 -07002434 if (mHasNavigationBar) {
2435 // For a basic navigation bar, when we are in landscape mode we place
2436 // the navigation bar to the side.
Daniel Sandler4a066c52012-04-20 14:49:13 -04002437 if (mNavigationBarCanMove && fullWidth > fullHeight) {
Sriram Viswanathan9ebbe6a2015-11-16 17:59:22 -08002438 return fullWidth - getNavigationBarWidth(rotation, uiMode);
Dianne Hackborn077ee852012-04-09 16:27:07 -07002439 }
Dianne Hackborn1f903c32011-09-13 19:18:06 -07002440 }
2441 return fullWidth;
Dianne Hackborne2515ee2011-04-27 18:52:56 -04002442 }
2443
Sriram Viswanathan9ebbe6a2015-11-16 17:59:22 -08002444 private int getNavigationBarHeight(int rotation, int uiMode) {
2445 if ((uiMode & UI_MODE_TYPE_MASK) == UI_MODE_TYPE_CAR) {
2446 return mNavigationBarHeightForRotationInCarMode[rotation];
2447 } else {
2448 return mNavigationBarHeightForRotationDefault[rotation];
2449 }
2450 }
2451
Jose Lima9546b202014-07-02 17:21:51 -07002452 @Override
Sriram Viswanathan9ebbe6a2015-11-16 17:59:22 -08002453 public int getNonDecorDisplayHeight(int fullWidth, int fullHeight, int rotation,
2454 int uiMode) {
Dianne Hackborn077ee852012-04-09 16:27:07 -07002455 if (mHasNavigationBar) {
2456 // For a basic navigation bar, when we are in portrait mode we place
2457 // the navigation bar to the bottom.
Daniel Sandler4a066c52012-04-20 14:49:13 -04002458 if (!mNavigationBarCanMove || fullWidth < fullHeight) {
Sriram Viswanathan9ebbe6a2015-11-16 17:59:22 -08002459 return fullHeight - getNavigationBarHeight(rotation, uiMode);
Dianne Hackborn077ee852012-04-09 16:27:07 -07002460 }
2461 }
2462 return fullHeight;
Dianne Hackborn69cb8752011-05-19 18:13:32 -07002463 }
2464
Jose Lima9546b202014-07-02 17:21:51 -07002465 @Override
Sriram Viswanathan9ebbe6a2015-11-16 17:59:22 -08002466 public int getConfigDisplayWidth(int fullWidth, int fullHeight, int rotation, int uiMode) {
2467 return getNonDecorDisplayWidth(fullWidth, fullHeight, rotation, uiMode);
Dianne Hackborn69cb8752011-05-19 18:13:32 -07002468 }
2469
Jose Lima9546b202014-07-02 17:21:51 -07002470 @Override
Sriram Viswanathan9ebbe6a2015-11-16 17:59:22 -08002471 public int getConfigDisplayHeight(int fullWidth, int fullHeight, int rotation, int uiMode) {
John Spurlock80f00c12013-06-13 11:10:51 -04002472 // There is a separate status bar at the top of the display. We don't count that as part
2473 // of the fixed decor, since it can hide; however, for purposes of configurations,
Dianne Hackborn077ee852012-04-09 16:27:07 -07002474 // we do want to exclude it since applications can't generally use that part
2475 // of the screen.
Sriram Viswanathan9ebbe6a2015-11-16 17:59:22 -08002476 return getNonDecorDisplayHeight(
2477 fullWidth, fullHeight, rotation, uiMode) - mStatusBarHeight;
Dianne Hackborne2515ee2011-04-27 18:52:56 -04002478 }
2479
Craig Mautnera3f4bf52012-10-10 20:37:48 -07002480 @Override
Craig Mautnerc9457fa2014-06-06 14:27:48 -07002481 public boolean isForceHiding(WindowManager.LayoutParams attrs) {
2482 return (attrs.privateFlags & PRIVATE_FLAG_KEYGUARD) != 0 ||
Jim Millerab954542014-10-10 18:21:49 -07002483 (isKeyguardHostWindow(attrs) &&
2484 (mKeyguardDelegate != null && mKeyguardDelegate.isShowing())) ||
Adrian Roos69e510d2014-07-13 14:57:59 +02002485 (attrs.type == TYPE_KEYGUARD_SCRIM);
Dianne Hackborn01ad2f42009-09-24 19:24:56 -07002486 }
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07002487
Craig Mautnera3f4bf52012-10-10 20:37:48 -07002488 @Override
Jorim Jaggi0d674622014-05-21 01:34:15 +02002489 public boolean isKeyguardHostWindow(WindowManager.LayoutParams attrs) {
2490 return attrs.type == TYPE_STATUS_BAR;
2491 }
2492
2493 @Override
Dianne Hackborn01ad2f42009-09-24 19:24:56 -07002494 public boolean canBeForceHidden(WindowState win, WindowManager.LayoutParams attrs) {
Craig Mautnera3f4bf52012-10-10 20:37:48 -07002495 switch (attrs.type) {
2496 case TYPE_STATUS_BAR:
2497 case TYPE_NAVIGATION_BAR:
2498 case TYPE_WALLPAPER:
2499 case TYPE_DREAM:
Jim Miller5ecd8112013-01-09 18:50:26 -08002500 case TYPE_KEYGUARD_SCRIM:
Craig Mautnera3f4bf52012-10-10 20:37:48 -07002501 return false;
2502 default:
Adrian Roos461829d2015-06-03 14:41:18 -07002503 // Hide only windows below the keyguard host window.
2504 return windowTypeToLayerLw(win.getBaseType())
2505 < windowTypeToLayerLw(TYPE_STATUS_BAR);
Craig Mautnera3f4bf52012-10-10 20:37:48 -07002506 }
Dianne Hackborn01ad2f42009-09-24 19:24:56 -07002507 }
Craig Mautner8e4df6c2012-05-23 16:57:23 -07002508
Craig Mautner7d7808f2014-09-11 18:02:38 -07002509 @Override
2510 public WindowState getWinShowWhenLockedLw() {
2511 return mWinShowWhenLocked;
2512 }
2513
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002514 /** {@inheritDoc} */
Craig Mautner8e4df6c2012-05-23 16:57:23 -07002515 @Override
Dianne Hackborn2f0b1752011-05-31 17:59:49 -07002516 public View addStartingWindow(IBinder appToken, String packageName, int theme,
2517 CompatibilityInfo compatInfo, CharSequence nonLocalizedLabel, int labelRes,
Adam Powell04fe6eb2013-05-31 14:39:48 -07002518 int icon, int logo, int windowFlags) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002519 if (!SHOW_STARTING_ANIMATIONS) {
2520 return null;
2521 }
2522 if (packageName == null) {
2523 return null;
2524 }
Craig Mautner8e4df6c2012-05-23 16:57:23 -07002525
Mathias Jeppssond1443e92012-08-24 15:25:32 +02002526 WindowManager wm = null;
2527 View view = null;
2528
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002529 try {
Dianne Hackborn867ab6472010-04-29 13:28:56 -07002530 Context context = mContext;
Craig Mautner6fbda632012-07-03 09:26:39 -07002531 if (DEBUG_STARTING_WINDOW) Slog.d(TAG, "addStartingWindow " + packageName
2532 + ": nonLocalizedLabel=" + nonLocalizedLabel + " theme="
2533 + Integer.toHexString(theme));
Dianne Hackborn247fe742011-01-08 17:25:57 -08002534 if (theme != context.getThemeResId() || labelRes != 0) {
Dianne Hackborn867ab6472010-04-29 13:28:56 -07002535 try {
2536 context = context.createPackageContext(packageName, 0);
Dianne Hackborn247fe742011-01-08 17:25:57 -08002537 context.setTheme(theme);
Dianne Hackborn867ab6472010-04-29 13:28:56 -07002538 } catch (PackageManager.NameNotFoundException e) {
2539 // Ignore
2540 }
2541 }
Craig Mautner8e4df6c2012-05-23 16:57:23 -07002542
Jorim Jaggia16cc152015-06-01 16:55:05 -07002543 PhoneWindow win = new PhoneWindow(context);
2544 win.setIsStartingWindow(true);
Craig Mautner8e4df6c2012-05-23 16:57:23 -07002545
Dianne Hackborn867ab6472010-04-29 13:28:56 -07002546 Resources r = context.getResources();
2547 win.setTitle(r.getText(labelRes, nonLocalizedLabel));
Craig Mautner8e4df6c2012-05-23 16:57:23 -07002548
Dianne Hackborn867ab6472010-04-29 13:28:56 -07002549 win.setType(
2550 WindowManager.LayoutParams.TYPE_APPLICATION_STARTING);
Adrian Roos602c68e2015-04-24 16:03:47 -07002551
2552 synchronized (mWindowManagerFuncs.getWindowManagerLock()) {
2553 // Assumes it's safe to show starting windows of launched apps while
2554 // the keyguard is being hidden. This is okay because starting windows never show
2555 // secret information.
2556 if (mKeyguardHidden) {
2557 windowFlags |= FLAG_SHOW_WHEN_LOCKED;
2558 }
2559 }
2560
Dianne Hackborn867ab6472010-04-29 13:28:56 -07002561 // Force the window flags: this is a fake window, so it is not really
2562 // touchable or focusable by the user. We also add in the ALT_FOCUSABLE_IM
2563 // flag because we do know that the next window will take input
2564 // focus, so we want to get the IME window up on top of us right away.
2565 win.setFlags(
Dianne Hackborn7eec10e2010-11-12 18:03:47 -08002566 windowFlags|
Dianne Hackborn867ab6472010-04-29 13:28:56 -07002567 WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE|
2568 WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE|
2569 WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM,
Dianne Hackborn7eec10e2010-11-12 18:03:47 -08002570 windowFlags|
Dianne Hackborn867ab6472010-04-29 13:28:56 -07002571 WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE|
2572 WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE|
2573 WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM);
Craig Mautner8e4df6c2012-05-23 16:57:23 -07002574
Adam Powell04fe6eb2013-05-31 14:39:48 -07002575 win.setDefaultIcon(icon);
2576 win.setDefaultLogo(logo);
2577
Dianne Hackborn867ab6472010-04-29 13:28:56 -07002578 win.setLayout(WindowManager.LayoutParams.MATCH_PARENT,
Dianne Hackborn2f0b1752011-05-31 17:59:49 -07002579 WindowManager.LayoutParams.MATCH_PARENT);
Craig Mautner8e4df6c2012-05-23 16:57:23 -07002580
Dianne Hackborn867ab6472010-04-29 13:28:56 -07002581 final WindowManager.LayoutParams params = win.getAttributes();
2582 params.token = appToken;
2583 params.packageName = packageName;
2584 params.windowAnimations = win.getWindowStyle().getResourceId(
2585 com.android.internal.R.styleable.Window_windowAnimationStyle, 0);
John Reck61375a82014-09-18 19:27:48 +00002586 params.privateFlags |=
2587 WindowManager.LayoutParams.PRIVATE_FLAG_FAKE_HARDWARE_ACCELERATED;
Craig Mautner88400d32012-09-30 12:35:45 -07002588 params.privateFlags |= WindowManager.LayoutParams.PRIVATE_FLAG_SHOW_FOR_ALL_USERS;
Adam Lesinski95c42972013-10-02 10:13:27 -07002589
2590 if (!compatInfo.supportsScreen()) {
2591 params.privateFlags |= WindowManager.LayoutParams.PRIVATE_FLAG_COMPATIBLE_WINDOW;
2592 }
2593
Dianne Hackborn867ab6472010-04-29 13:28:56 -07002594 params.setTitle("Starting " + packageName);
2595
Mathias Jeppssond1443e92012-08-24 15:25:32 +02002596 wm = (WindowManager)context.getSystemService(Context.WINDOW_SERVICE);
2597 view = win.getDecorView();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002598
Craig Mautner6fbda632012-07-03 09:26:39 -07002599 if (DEBUG_STARTING_WINDOW) Slog.d(
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002600 TAG, "Adding starting window for " + packageName
2601 + " / " + appToken + ": "
2602 + (view.getParent() != null ? view : null));
2603
2604 wm.addView(view, params);
2605
2606 // Only return the view if it was successfully added to the
2607 // window manager... which we can tell by it having a parent.
2608 return view.getParent() != null ? view : null;
Jeff Brown98365d72012-08-19 20:30:52 -07002609 } catch (WindowManager.BadTokenException e) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002610 // ignore
Craig Mautner42bf39e2014-02-21 16:46:22 -08002611 Log.w(TAG, appToken + " already running, starting window not displayed. " +
2612 e.getMessage());
Dianne Hackborn867ab6472010-04-29 13:28:56 -07002613 } catch (RuntimeException e) {
2614 // don't crash if something else bad happens, for example a
2615 // failure loading resources because we are loading from an app
2616 // on external storage that has been unmounted.
2617 Log.w(TAG, appToken + " failed creating starting window", e);
Mathias Jeppssond1443e92012-08-24 15:25:32 +02002618 } finally {
2619 if (view != null && view.getParent() == null) {
2620 Log.w(TAG, "view not successfully added to wm, removing view");
2621 wm.removeViewImmediate(view);
2622 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002623 }
2624
2625 return null;
2626 }
2627
2628 /** {@inheritDoc} */
Jose Lima9546b202014-07-02 17:21:51 -07002629 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002630 public void removeStartingWindow(IBinder appToken, View window) {
Craig Mautner276a6eb2014-11-04 15:32:57 -08002631 if (DEBUG_STARTING_WINDOW) Slog.v(TAG, "Removing starting window for " + appToken + ": "
2632 + window + " Callers=" + Debug.getCallers(4));
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002633
2634 if (window != null) {
Dianne Hackborn5fd21692011-06-07 14:09:47 -07002635 WindowManager wm = (WindowManager)mContext.getSystemService(Context.WINDOW_SERVICE);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002636 wm.removeView(window);
2637 }
2638 }
2639
2640 /**
2641 * Preflight adding a window to the system.
RoboErik8a2cfc32014-05-16 11:19:38 -07002642 *
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002643 * Currently enforces that three window types are singletons:
2644 * <ul>
2645 * <li>STATUS_BAR_TYPE</li>
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002646 * <li>KEYGUARD_TYPE</li>
2647 * </ul>
RoboErik8a2cfc32014-05-16 11:19:38 -07002648 *
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002649 * @param win The window to be added
2650 * @param attrs Information about the window to be added
RoboErik8a2cfc32014-05-16 11:19:38 -07002651 *
Jeff Brown98365d72012-08-19 20:30:52 -07002652 * @return If ok, WindowManagerImpl.ADD_OKAY. If too many singletons,
2653 * WindowManagerImpl.ADD_MULTIPLE_SINGLETON
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002654 */
Jose Lima9546b202014-07-02 17:21:51 -07002655 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002656 public int prepareAddWindowLw(WindowState win, WindowManager.LayoutParams attrs) {
2657 switch (attrs.type) {
2658 case TYPE_STATUS_BAR:
Joe Onorato8bc6c512010-06-04 16:21:12 -04002659 mContext.enforceCallingOrSelfPermission(
2660 android.Manifest.permission.STATUS_BAR_SERVICE,
2661 "PhoneWindowManager");
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002662 if (mStatusBar != null) {
Dianne Hackbornf87d1962012-04-04 12:48:24 -07002663 if (mStatusBar.isAlive()) {
Jeff Brown98365d72012-08-19 20:30:52 -07002664 return WindowManagerGlobal.ADD_MULTIPLE_SINGLETON;
Dianne Hackbornf87d1962012-04-04 12:48:24 -07002665 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002666 }
2667 mStatusBar = win;
John Spurlock27735a42013-08-14 17:57:38 -04002668 mStatusBarController.setWindow(win);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002669 break;
Daniel Sandler8956dbb2011-04-22 07:55:02 -04002670 case TYPE_NAVIGATION_BAR:
2671 mContext.enforceCallingOrSelfPermission(
2672 android.Manifest.permission.STATUS_BAR_SERVICE,
2673 "PhoneWindowManager");
Dianne Hackbornf87d1962012-04-04 12:48:24 -07002674 if (mNavigationBar != null) {
2675 if (mNavigationBar.isAlive()) {
Jeff Brown98365d72012-08-19 20:30:52 -07002676 return WindowManagerGlobal.ADD_MULTIPLE_SINGLETON;
Dianne Hackbornf87d1962012-04-04 12:48:24 -07002677 }
2678 }
Daniel Sandler8956dbb2011-04-22 07:55:02 -04002679 mNavigationBar = win;
John Spurlock27735a42013-08-14 17:57:38 -04002680 mNavigationBarController.setWindow(win);
Craig Mautnereda67292013-04-28 13:50:14 -07002681 if (DEBUG_LAYOUT) Slog.i(TAG, "NAVIGATION BAR: " + mNavigationBar);
Daniel Sandler8956dbb2011-04-22 07:55:02 -04002682 break;
Jim Millere898ac52012-04-06 17:10:57 -07002683 case TYPE_NAVIGATION_BAR_PANEL:
Dianne Hackborn08743722009-12-21 12:16:51 -08002684 case TYPE_STATUS_BAR_PANEL:
Joe Onorato29fc2c92010-11-24 10:26:50 -08002685 case TYPE_STATUS_BAR_SUB_PANEL:
Jorim Jaggi225d3b52015-04-01 11:18:57 -07002686 case TYPE_VOICE_INTERACTION_STARTING:
Joe Onorato29fc2c92010-11-24 10:26:50 -08002687 mContext.enforceCallingOrSelfPermission(
2688 android.Manifest.permission.STATUS_BAR_SERVICE,
2689 "PhoneWindowManager");
Joe Onorato29fc2c92010-11-24 10:26:50 -08002690 break;
Jim Miller5ecd8112013-01-09 18:50:26 -08002691 case TYPE_KEYGUARD_SCRIM:
Jim Miller25190572013-02-28 17:36:24 -08002692 if (mKeyguardScrim != null) {
2693 return WindowManagerGlobal.ADD_MULTIPLE_SINGLETON;
2694 }
Jim Miller5ecd8112013-01-09 18:50:26 -08002695 mKeyguardScrim = win;
2696 break;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002697 }
Jeff Brown98365d72012-08-19 20:30:52 -07002698 return WindowManagerGlobal.ADD_OKAY;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002699 }
2700
2701 /** {@inheritDoc} */
Jose Lima9546b202014-07-02 17:21:51 -07002702 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002703 public void removeWindowLw(WindowState win) {
2704 if (mStatusBar == win) {
2705 mStatusBar = null;
John Spurlock27735a42013-08-14 17:57:38 -04002706 mStatusBarController.setWindow(null);
Jim Millerc0b676d2013-03-22 16:11:08 -07002707 mKeyguardDelegate.showScrim();
Jim Miller5ecd8112013-01-09 18:50:26 -08002708 } else if (mKeyguardScrim == win) {
2709 Log.v(TAG, "Removing keyguard scrim");
2710 mKeyguardScrim = null;
2711 } if (mNavigationBar == win) {
Daniel Sandler8956dbb2011-04-22 07:55:02 -04002712 mNavigationBar = null;
John Spurlock27735a42013-08-14 17:57:38 -04002713 mNavigationBarController.setWindow(null);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002714 }
2715 }
2716
2717 static final boolean PRINT_ANIM = false;
RoboErik8a2cfc32014-05-16 11:19:38 -07002718
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002719 /** {@inheritDoc} */
Craig Mautner4b71aa12012-12-27 17:20:01 -08002720 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002721 public int selectAnimationLw(WindowState win, int transit) {
2722 if (PRINT_ANIM) Log.i(TAG, "selectAnimation in " + win
2723 + ": transit=" + transit);
Dianne Hackbornf87d1962012-04-04 12:48:24 -07002724 if (win == mStatusBar) {
Jorim Jaggi380ecb82014-03-14 17:25:20 +01002725 boolean isKeyguard = (win.getAttrs().privateFlags & PRIVATE_FLAG_KEYGUARD) != 0;
Craig Mautner4b71aa12012-12-27 17:20:01 -08002726 if (transit == TRANSIT_EXIT
2727 || transit == TRANSIT_HIDE) {
Jorim Jaggi380ecb82014-03-14 17:25:20 +01002728 return isKeyguard ? -1 : R.anim.dock_top_exit;
Craig Mautner4b71aa12012-12-27 17:20:01 -08002729 } else if (transit == TRANSIT_ENTER
2730 || transit == TRANSIT_SHOW) {
Jorim Jaggi380ecb82014-03-14 17:25:20 +01002731 return isKeyguard ? -1 : R.anim.dock_top_enter;
Dianne Hackbornf87d1962012-04-04 12:48:24 -07002732 }
2733 } else if (win == mNavigationBar) {
Jorim Jaggi0d210f62015-07-10 14:24:44 -07002734 if (win.getAttrs().windowAnimations != 0) {
2735 return 0;
2736 }
Dianne Hackbornf87d1962012-04-04 12:48:24 -07002737 // This can be on either the bottom or the right.
2738 if (mNavigationBarOnBottom) {
Craig Mautner4b71aa12012-12-27 17:20:01 -08002739 if (transit == TRANSIT_EXIT
2740 || transit == TRANSIT_HIDE) {
Dianne Hackbornf87d1962012-04-04 12:48:24 -07002741 return R.anim.dock_bottom_exit;
Craig Mautner4b71aa12012-12-27 17:20:01 -08002742 } else if (transit == TRANSIT_ENTER
2743 || transit == TRANSIT_SHOW) {
Dianne Hackbornf87d1962012-04-04 12:48:24 -07002744 return R.anim.dock_bottom_enter;
2745 }
2746 } else {
Craig Mautner4b71aa12012-12-27 17:20:01 -08002747 if (transit == TRANSIT_EXIT
2748 || transit == TRANSIT_HIDE) {
Dianne Hackbornf87d1962012-04-04 12:48:24 -07002749 return R.anim.dock_right_exit;
Craig Mautner4b71aa12012-12-27 17:20:01 -08002750 } else if (transit == TRANSIT_ENTER
2751 || transit == TRANSIT_SHOW) {
Dianne Hackbornf87d1962012-04-04 12:48:24 -07002752 return R.anim.dock_right_enter;
2753 }
2754 }
Filip Gruszczynski57f76f12015-11-04 16:10:54 -08002755 } else if (win.getAttrs().type == TYPE_DOCK_DIVIDER) {
Jorim Jaggi81ba11e2016-02-03 22:04:22 -08002756 return selectDockedDividerAnimationLw(win, transit);
Craig Mautner4b71aa12012-12-27 17:20:01 -08002757 }
2758
2759 if (transit == TRANSIT_PREVIEW_DONE) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002760 if (win.hasAppShownWindows()) {
2761 if (PRINT_ANIM) Log.i(TAG, "**** STARTING EXIT");
2762 return com.android.internal.R.anim.app_starting_exit;
2763 }
Dianne Hackborn7ad44382012-10-18 17:46:00 -07002764 } else if (win.getAttrs().type == TYPE_DREAM && mDreamingLockscreen
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07002765 && transit == TRANSIT_ENTER) {
2766 // Special case: we are animating in a dream, while the keyguard
2767 // is shown. We don't want an animation on the dream, because
2768 // we need it shown immediately with the keyguard animating away
2769 // to reveal it.
2770 return -1;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002771 }
2772
2773 return 0;
2774 }
2775
Jorim Jaggi81ba11e2016-02-03 22:04:22 -08002776 private int selectDockedDividerAnimationLw(WindowState win, int transit) {
2777 int insets = mWindowManagerFuncs.getDockedDividerInsetsLw();
2778
2779 // If the divider is behind the navigation bar, don't animate.
Jorim Jaggi0cb0f722016-03-25 20:49:41 -07002780 final Rect frame = win.getFrameLw();
2781 final boolean behindNavBar = mNavigationBar != null
Jorim Jaggi192086e2016-03-11 17:17:03 +01002782 && ((mNavigationBarOnBottom
Jorim Jaggi0cb0f722016-03-25 20:49:41 -07002783 && frame.top + insets >= mNavigationBar.getFrameLw().top)
Jorim Jaggi192086e2016-03-11 17:17:03 +01002784 || (!mNavigationBarOnBottom
Jorim Jaggi0cb0f722016-03-25 20:49:41 -07002785 && frame.left + insets >= mNavigationBar.getFrameLw().left));
2786 final boolean landscape = frame.height() > frame.width();
2787 final boolean offscreenLandscape = landscape && (frame.right - insets <= 0
2788 || frame.left + insets >= win.getDisplayFrameLw().right);
2789 final boolean offscreenPortrait = !landscape && (frame.top - insets <= 0
2790 || frame.bottom + insets >= win.getDisplayFrameLw().bottom);
2791 final boolean offscreen = offscreenLandscape || offscreenPortrait;
2792 if (behindNavBar || offscreen) {
Jorim Jaggi81ba11e2016-02-03 22:04:22 -08002793 return 0;
2794 }
2795 if (transit == TRANSIT_ENTER || transit == TRANSIT_SHOW) {
2796 return R.anim.fade_in;
2797 } else if (transit == TRANSIT_EXIT) {
2798 return R.anim.fade_out;
2799 } else {
2800 return 0;
2801 }
2802 }
2803
Craig Mautner3c174372013-02-21 17:54:37 -08002804 @Override
2805 public void selectRotationAnimationLw(int anim[]) {
2806 if (PRINT_ANIM) Slog.i(TAG, "selectRotationAnimation mTopFullscreen="
2807 + mTopFullscreenOpaqueWindowState + " rotationAnimation="
2808 + (mTopFullscreenOpaqueWindowState == null ?
2809 "0" : mTopFullscreenOpaqueWindowState.getAttrs().rotationAnimation));
2810 if (mTopFullscreenOpaqueWindowState != null && mTopIsFullscreen) {
2811 switch (mTopFullscreenOpaqueWindowState.getAttrs().rotationAnimation) {
2812 case ROTATION_ANIMATION_CROSSFADE:
2813 anim[0] = R.anim.rotation_animation_xfade_exit;
2814 anim[1] = R.anim.rotation_animation_enter;
2815 break;
2816 case ROTATION_ANIMATION_JUMPCUT:
2817 anim[0] = R.anim.rotation_animation_jump_exit;
2818 anim[1] = R.anim.rotation_animation_enter;
2819 break;
2820 case ROTATION_ANIMATION_ROTATE:
2821 default:
2822 anim[0] = anim[1] = 0;
2823 break;
2824 }
2825 } else {
2826 anim[0] = anim[1] = 0;
2827 }
2828 }
2829
2830 @Override
2831 public boolean validateRotationAnimationLw(int exitAnimId, int enterAnimId,
2832 boolean forceDefault) {
2833 switch (exitAnimId) {
2834 case R.anim.rotation_animation_xfade_exit:
2835 case R.anim.rotation_animation_jump_exit:
2836 // These are the only cases that matter.
2837 if (forceDefault) {
2838 return false;
2839 }
2840 int anim[] = new int[2];
2841 selectRotationAnimationLw(anim);
2842 return (exitAnimId == anim[0] && enterAnimId == anim[1]);
2843 default:
2844 return true;
2845 }
2846 }
2847
2848 @Override
Jorim Jaggi84a3e7a2014-08-13 17:58:58 +02002849 public Animation createForceHideEnterAnimation(boolean onWallpaper,
2850 boolean goingToNotificationShade) {
2851 if (goingToNotificationShade) {
2852 return AnimationUtils.loadAnimation(mContext, R.anim.lock_screen_behind_enter_fade_in);
Craig Mautnerb8340802014-11-04 15:32:57 -08002853 }
Craig Mautner276a6eb2014-11-04 15:32:57 -08002854
2855 AnimationSet set = (AnimationSet) AnimationUtils.loadAnimation(mContext, onWallpaper ?
2856 R.anim.lock_screen_behind_enter_wallpaper :
2857 R.anim.lock_screen_behind_enter);
2858
2859 // TODO: Use XML interpolators when we have log interpolators available in XML.
2860 final List<Animation> animations = set.getAnimations();
2861 for (int i = animations.size() - 1; i >= 0; --i) {
2862 animations.get(i).setInterpolator(mLogDecelerateInterpolator);
2863 }
2864
2865 return set;
Jorim Jaggi76a16232014-08-08 17:00:47 +02002866 }
2867
2868
2869 @Override
Jorim Jaggi84a3e7a2014-08-13 17:58:58 +02002870 public Animation createForceHideWallpaperExitAnimation(boolean goingToNotificationShade) {
2871 if (goingToNotificationShade) {
2872 return null;
2873 } else {
2874 return AnimationUtils.loadAnimation(mContext, R.anim.lock_screen_wallpaper_exit);
2875 }
Dianne Hackborn01ad2f42009-09-24 19:24:56 -07002876 }
John Spurlockc8b46ca2013-04-08 12:59:26 -04002877
2878 private static void awakenDreams() {
2879 IDreamManager dreamManager = getDreamManager();
2880 if (dreamManager != null) {
2881 try {
2882 dreamManager.awaken();
2883 } catch (RemoteException e) {
2884 // fine, stay asleep then
2885 }
2886 }
2887 }
2888
2889 static IDreamManager getDreamManager() {
2890 return IDreamManager.Stub.asInterface(
2891 ServiceManager.checkService(DreamService.DREAM_SERVICE));
2892 }
2893
Tyler Gunnef9f6f92014-09-12 22:16:17 -07002894 TelecomManager getTelecommService() {
2895 return (TelecomManager) mContext.getSystemService(Context.TELECOM_SERVICE);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002896 }
2897
Jeff Brown4d396052010-10-29 21:50:21 -07002898 static IAudioService getAudioService() {
2899 IAudioService audioService = IAudioService.Stub.asInterface(
2900 ServiceManager.checkService(Context.AUDIO_SERVICE));
2901 if (audioService == null) {
2902 Log.w(TAG, "Unable to find IAudioService interface.");
2903 }
2904 return audioService;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002905 }
2906
2907 boolean keyguardOn() {
Jim Millerab954542014-10-10 18:21:49 -07002908 return isKeyguardShowingAndNotOccluded() || inKeyguardRestrictedKeyInputMode();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002909 }
2910
2911 private static final int[] WINDOW_TYPES_WHERE_HOME_DOESNT_WORK = {
2912 WindowManager.LayoutParams.TYPE_SYSTEM_ALERT,
2913 WindowManager.LayoutParams.TYPE_SYSTEM_ERROR,
2914 };
2915
2916 /** {@inheritDoc} */
Jeff Brown00fa7bd2010-07-02 15:37:36 -07002917 @Override
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002918 public long interceptKeyBeforeDispatching(WindowState win, KeyEvent event, int policyFlags) {
Jeff Brown00fa7bd2010-07-02 15:37:36 -07002919 final boolean keyguardOn = keyguardOn();
Jeff Brown1f245102010-11-18 20:53:46 -08002920 final int keyCode = event.getKeyCode();
2921 final int repeatCount = event.getRepeatCount();
2922 final int metaState = event.getMetaState();
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002923 final int flags = event.getFlags();
Jeff Brown1f245102010-11-18 20:53:46 -08002924 final boolean down = event.getAction() == KeyEvent.ACTION_DOWN;
2925 final boolean canceled = event.isCanceled();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002926
Jeff Brown40013652012-05-16 21:22:36 -07002927 if (DEBUG_INPUT) {
Jeff Brown00fa7bd2010-07-02 15:37:36 -07002928 Log.d(TAG, "interceptKeyTi keyCode=" + keyCode + " down=" + down + " repeatCount="
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002929 + repeatCount + " keyguardOn=" + keyguardOn + " mHomePressed=" + mHomePressed
2930 + " canceled=" + canceled);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002931 }
2932
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002933 // If we think we might have a volume down & power key chord on the way
2934 // but we're not sure, then tell the dispatcher to wait a little while and
2935 // try again later before dispatching.
Christopher Tatee90585f2012-03-05 18:56:25 -08002936 if (mScreenshotChordEnabled && (flags & KeyEvent.FLAG_FALLBACK) == 0) {
Jeff Brown13f00f02014-10-31 14:45:50 -07002937 if (mScreenshotChordVolumeDownKeyTriggered && !mScreenshotChordPowerKeyTriggered) {
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002938 final long now = SystemClock.uptimeMillis();
Jeff Brown13f00f02014-10-31 14:45:50 -07002939 final long timeoutTime = mScreenshotChordVolumeDownKeyTime
2940 + SCREENSHOT_CHORD_DEBOUNCE_DELAY_MILLIS;
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002941 if (now < timeoutTime) {
2942 return timeoutTime - now;
2943 }
2944 }
2945 if (keyCode == KeyEvent.KEYCODE_VOLUME_DOWN
Jeff Brown13f00f02014-10-31 14:45:50 -07002946 && mScreenshotChordVolumeDownKeyConsumed) {
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002947 if (!down) {
Jeff Brown13f00f02014-10-31 14:45:50 -07002948 mScreenshotChordVolumeDownKeyConsumed = false;
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002949 }
2950 return -1;
2951 }
2952 }
2953
Michael Wright6a62e552014-06-03 19:19:48 -07002954 // Cancel any pending meta actions if we see any other keys being pressed between the down
2955 // of the meta key and its corresponding up.
Michael Wright251e35d2014-08-22 15:40:27 -07002956 if (mPendingMetaAction && !KeyEvent.isMetaKey(keyCode)) {
Michael Wright6a62e552014-06-03 19:19:48 -07002957 mPendingMetaAction = false;
2958 }
2959
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002960 // First we always handle the home key here, so applications
2961 // can never break it, although if keyguard is on, we do let
2962 // it handle it, because that gives us the correct 5 second
2963 // timeout.
Jeff Brown00fa7bd2010-07-02 15:37:36 -07002964 if (keyCode == KeyEvent.KEYCODE_HOME) {
Michael Jurka7f2668c2012-03-27 07:49:52 -07002965
Jeff Brown49ed71d2010-12-06 17:13:33 -08002966 // If we have released the home key, and didn't do anything else
2967 // while it was pressed, then it is time to go home!
Michael Jurka7f2668c2012-03-27 07:49:52 -07002968 if (!down) {
Jeff Browncaca8812013-05-09 13:34:33 -07002969 cancelPreloadRecentApps();
2970
Jeff Brown49ed71d2010-12-06 17:13:33 -08002971 mHomePressed = false;
Jeff Browncaca8812013-05-09 13:34:33 -07002972 if (mHomeConsumed) {
2973 mHomeConsumed = false;
Michael Jurka7f2668c2012-03-27 07:49:52 -07002974 return -1;
Jeff Brown49ed71d2010-12-06 17:13:33 -08002975 }
Jeff Browncaca8812013-05-09 13:34:33 -07002976
2977 if (canceled) {
2978 Log.i(TAG, "Ignoring HOME; event canceled.");
2979 return -1;
2980 }
2981
Yorke Lee4f803242014-12-15 23:22:06 +00002982 // If an incoming call is ringing, HOME is totally disabled.
2983 // (The user is already on the InCallUI at this point,
2984 // and his ONLY options are to answer or reject the call.)
2985 TelecomManager telecomManager = getTelecommService();
2986 if (telecomManager != null && telecomManager.isRinging()) {
2987 Log.i(TAG, "Ignoring HOME; there's a ringing incoming call.");
2988 return -1;
2989 }
2990
Jeff Browncaca8812013-05-09 13:34:33 -07002991 // Delay handling home if a double-tap is possible.
2992 if (mDoubleTapOnHomeBehavior != DOUBLE_TAP_HOME_NOTHING) {
2993 mHandler.removeCallbacks(mHomeDoubleTapTimeoutRunnable); // just in case
2994 mHomeDoubleTapPending = true;
2995 mHandler.postDelayed(mHomeDoubleTapTimeoutRunnable,
2996 ViewConfiguration.getDoubleTapTimeout());
2997 return -1;
2998 }
2999
Jeff Brown13f00f02014-10-31 14:45:50 -07003000 handleShortPressOnHome();
Jeff Browncaca8812013-05-09 13:34:33 -07003001 return -1;
Jeff Brown49ed71d2010-12-06 17:13:33 -08003002 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003003
3004 // If a system window has focus, then it doesn't make sense
3005 // right now to interact with applications.
3006 WindowManager.LayoutParams attrs = win != null ? win.getAttrs() : null;
3007 if (attrs != null) {
3008 final int type = attrs.type;
Jorim Jaggi380ecb82014-03-14 17:25:20 +01003009 if (type == WindowManager.LayoutParams.TYPE_KEYGUARD_SCRIM
3010 || type == WindowManager.LayoutParams.TYPE_KEYGUARD_DIALOG
3011 || (attrs.privateFlags & PRIVATE_FLAG_KEYGUARD) != 0) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003012 // the "app" is keyguard, so give it the key
Jeff Brownd5bb82d2011-10-12 13:57:59 -07003013 return 0;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003014 }
3015 final int typeCount = WINDOW_TYPES_WHERE_HOME_DOESNT_WORK.length;
3016 for (int i=0; i<typeCount; i++) {
3017 if (type == WINDOW_TYPES_WHERE_HOME_DOESNT_WORK[i]) {
3018 // don't do anything, but also don't pass it to the app
Jeff Brownd5bb82d2011-10-12 13:57:59 -07003019 return -1;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003020 }
3021 }
3022 }
Jeff Browncaca8812013-05-09 13:34:33 -07003023
3024 // Remember that home is pressed and handle special actions.
3025 if (repeatCount == 0) {
3026 mHomePressed = true;
3027 if (mHomeDoubleTapPending) {
3028 mHomeDoubleTapPending = false;
3029 mHandler.removeCallbacks(mHomeDoubleTapTimeoutRunnable);
3030 handleDoubleTapOnHome();
3031 } else if (mLongPressOnHomeBehavior == LONG_PRESS_HOME_RECENT_SYSTEM_UI
3032 || mDoubleTapOnHomeBehavior == DOUBLE_TAP_HOME_RECENT_SYSTEM_UI) {
3033 preloadRecentApps();
Michael Jurka7f2668c2012-03-27 07:49:52 -07003034 }
Jeff Browncaca8812013-05-09 13:34:33 -07003035 } else if ((event.getFlags() & KeyEvent.FLAG_LONG_PRESS) != 0) {
3036 if (!keyguardOn) {
Jaewan Kim76b7d0d2016-02-12 19:01:02 +09003037 handleLongPressOnHome(event.getDeviceId());
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003038 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003039 }
Jeff Brownd5bb82d2011-10-12 13:57:59 -07003040 return -1;
Jeff Brown00fa7bd2010-07-02 15:37:36 -07003041 } else if (keyCode == KeyEvent.KEYCODE_MENU) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003042 // Hijack modified menu keys for debugging features
3043 final int chordBug = KeyEvent.META_SHIFT_ON;
3044
3045 if (down && repeatCount == 0) {
Jeff Brown00fa7bd2010-07-02 15:37:36 -07003046 if (mEnableShiftMenuBugReports && (metaState & chordBug) == chordBug) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003047 Intent intent = new Intent(Intent.ACTION_BUG_REPORT);
Dianne Hackborn5ac72a22012-08-29 18:32:08 -07003048 mContext.sendOrderedBroadcastAsUser(intent, UserHandle.CURRENT,
3049 null, null, null, 0, null, null);
Jeff Brownd5bb82d2011-10-12 13:57:59 -07003050 return -1;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003051 } else if (SHOW_PROCESSES_ON_ALT_MENU &&
Jeff Brown00fa7bd2010-07-02 15:37:36 -07003052 (metaState & KeyEvent.META_ALT_ON) == KeyEvent.META_ALT_ON) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003053 Intent service = new Intent();
3054 service.setClassName(mContext, "com.android.server.LoadAverageService");
3055 ContentResolver res = mContext.getContentResolver();
Jeff Sharkey8d9a1f62012-10-18 15:38:14 -07003056 boolean shown = Settings.Global.getInt(
3057 res, Settings.Global.SHOW_PROCESSES, 0) != 0;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003058 if (!shown) {
3059 mContext.startService(service);
3060 } else {
3061 mContext.stopService(service);
3062 }
Jeff Sharkey8d9a1f62012-10-18 15:38:14 -07003063 Settings.Global.putInt(
3064 res, Settings.Global.SHOW_PROCESSES, shown ? 0 : 1);
Jeff Brownd5bb82d2011-10-12 13:57:59 -07003065 return -1;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003066 }
3067 }
Jeff Brown00fa7bd2010-07-02 15:37:36 -07003068 } else if (keyCode == KeyEvent.KEYCODE_SEARCH) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003069 if (down) {
3070 if (repeatCount == 0) {
Jeff Brownfd23e3e2012-05-09 13:34:28 -07003071 mSearchKeyShortcutPending = true;
3072 mConsumeSearchKeyUp = false;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003073 }
Jeff Brownfd23e3e2012-05-09 13:34:28 -07003074 } else {
3075 mSearchKeyShortcutPending = false;
3076 if (mConsumeSearchKeyUp) {
3077 mConsumeSearchKeyUp = false;
Jeff Brownd5bb82d2011-10-12 13:57:59 -07003078 return -1;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003079 }
3080 }
Jeff Brownd5bb82d2011-10-12 13:57:59 -07003081 return 0;
Jeff Brown49ed71d2010-12-06 17:13:33 -08003082 } else if (keyCode == KeyEvent.KEYCODE_APP_SWITCH) {
Michael Wrightc9ebea72013-01-16 19:25:02 -08003083 if (!keyguardOn) {
Jeff Browncaca8812013-05-09 13:34:33 -07003084 if (down && repeatCount == 0) {
3085 preloadRecentApps();
3086 } else if (!down) {
3087 toggleRecentApps();
Michael Wrightc9ebea72013-01-16 19:25:02 -08003088 }
Jeff Brown49ed71d2010-12-06 17:13:33 -08003089 }
Jeff Brownd5bb82d2011-10-12 13:57:59 -07003090 return -1;
Jun Mukaid21b3c82015-04-23 14:09:34 -07003091 } else if (keyCode == KeyEvent.KEYCODE_N && event.isMetaPressed()) {
3092 if (down) {
3093 IStatusBarService service = getStatusBarService();
3094 if (service != null) {
3095 try {
3096 service.expandNotificationsPanel();
3097 } catch (RemoteException e) {
3098 // do nothing.
3099 }
3100 }
3101 }
Muyuan Li6ca619f2016-03-08 13:30:42 -08003102 } else if (keyCode == KeyEvent.KEYCODE_S && event.isMetaPressed()
3103 && event.isCtrlPressed()) {
3104 if (down && repeatCount == 0) {
3105 int type = event.isShiftPressed() ? TAKE_SCREENSHOT_SELECTED_REGION
3106 : TAKE_SCREENSHOT_FULLSCREEN;
3107 mScreenshotRunnable.setScreenshotType(type);
3108 mHandler.post(mScreenshotRunnable);
3109 return -1;
3110 }
Clara Bayarrif2debb12015-07-10 14:47:17 +01003111 } else if (keyCode == KeyEvent.KEYCODE_SLASH && event.isMetaPressed()) {
3112 if (down) {
3113 if (repeatCount == 0) {
Clara Bayarri4e850ff2016-03-02 11:12:32 -08003114 toggleKeyboardShortcutsMenu(event.getDeviceId());
Clara Bayarrif2debb12015-07-10 14:47:17 +01003115 }
3116 }
Jeff Brownde7a8ea2012-06-13 18:28:57 -07003117 } else if (keyCode == KeyEvent.KEYCODE_ASSIST) {
3118 if (down) {
3119 if (repeatCount == 0) {
3120 mAssistKeyLongPressed = false;
3121 } else if (repeatCount == 1) {
3122 mAssistKeyLongPressed = true;
3123 if (!keyguardOn) {
3124 launchAssistLongPressAction();
3125 }
3126 }
3127 } else {
3128 if (mAssistKeyLongPressed) {
3129 mAssistKeyLongPressed = false;
3130 } else {
3131 if (!keyguardOn) {
Tim Kilbourn0e5f1102015-06-05 16:18:09 -07003132 launchAssistAction(null, event.getDeviceId());
Jeff Brownde7a8ea2012-06-13 18:28:57 -07003133 }
3134 }
3135 }
3136 return -1;
Michael Wrightdc63f7b2014-08-21 19:05:21 -07003137 } else if (keyCode == KeyEvent.KEYCODE_VOICE_ASSIST) {
3138 if (!down) {
3139 Intent voiceIntent;
Michael Wright869a67c2014-08-26 19:33:06 -07003140 if (!keyguardOn) {
Michael Wrightdc63f7b2014-08-21 19:05:21 -07003141 voiceIntent = new Intent(RecognizerIntent.ACTION_WEB_SEARCH);
3142 } else {
Dianne Hackbornb6683c42015-06-18 17:40:33 -07003143 IDeviceIdleController dic = IDeviceIdleController.Stub.asInterface(
3144 ServiceManager.getService(Context.DEVICE_IDLE_CONTROLLER));
3145 if (dic != null) {
3146 try {
3147 dic.exitIdle("voice-search");
3148 } catch (RemoteException e) {
3149 }
3150 }
Michael Wrightdc63f7b2014-08-21 19:05:21 -07003151 voiceIntent = new Intent(RecognizerIntent.ACTION_VOICE_SEARCH_HANDS_FREE);
Michael Wright869a67c2014-08-26 19:33:06 -07003152 voiceIntent.putExtra(RecognizerIntent.EXTRA_SECURE, true);
Michael Wrightdc63f7b2014-08-21 19:05:21 -07003153 }
Bart Sears8b1c27c2015-03-18 23:51:02 +00003154 startActivityAsUser(voiceIntent, UserHandle.CURRENT_OR_SELF);
Michael Wrightdc63f7b2014-08-21 19:05:21 -07003155 }
Jeff Sharkey2991fa32012-12-05 18:06:43 -08003156 } else if (keyCode == KeyEvent.KEYCODE_SYSRQ) {
3157 if (down && repeatCount == 0) {
Muyuan Li6ca619f2016-03-08 13:30:42 -08003158 mScreenshotRunnable.setScreenshotType(TAKE_SCREENSHOT_FULLSCREEN);
Jeff Sharkey2991fa32012-12-05 18:06:43 -08003159 mHandler.post(mScreenshotRunnable);
3160 }
3161 return -1;
Michael Wrightb854e242013-02-05 17:54:02 -08003162 } else if (keyCode == KeyEvent.KEYCODE_BRIGHTNESS_UP
3163 || keyCode == KeyEvent.KEYCODE_BRIGHTNESS_DOWN) {
3164 if (down) {
3165 int direction = keyCode == KeyEvent.KEYCODE_BRIGHTNESS_UP ? 1 : -1;
3166
3167 // Disable autobrightness if it's on
3168 int auto = Settings.System.getIntForUser(
3169 mContext.getContentResolver(),
3170 Settings.System.SCREEN_BRIGHTNESS_MODE,
3171 Settings.System.SCREEN_BRIGHTNESS_MODE_MANUAL,
3172 UserHandle.USER_CURRENT_OR_SELF);
3173 if (auto != 0) {
3174 Settings.System.putIntForUser(mContext.getContentResolver(),
3175 Settings.System.SCREEN_BRIGHTNESS_MODE,
3176 Settings.System.SCREEN_BRIGHTNESS_MODE_MANUAL,
3177 UserHandle.USER_CURRENT_OR_SELF);
3178 }
3179
3180 int min = mPowerManager.getMinimumScreenBrightnessSetting();
3181 int max = mPowerManager.getMaximumScreenBrightnessSetting();
3182 int step = (max - min + BRIGHTNESS_STEPS - 1) / BRIGHTNESS_STEPS * direction;
3183 int brightness = Settings.System.getIntForUser(mContext.getContentResolver(),
3184 Settings.System.SCREEN_BRIGHTNESS,
3185 mPowerManager.getDefaultScreenBrightnessSetting(),
3186 UserHandle.USER_CURRENT_OR_SELF);
3187 brightness += step;
3188 // Make sure we don't go beyond the limits.
3189 brightness = Math.min(max, brightness);
3190 brightness = Math.max(min, brightness);
3191
3192 Settings.System.putIntForUser(mContext.getContentResolver(),
3193 Settings.System.SCREEN_BRIGHTNESS, brightness,
3194 UserHandle.USER_CURRENT_OR_SELF);
Bart Sears8b1c27c2015-03-18 23:51:02 +00003195 startActivityAsUser(new Intent(Intent.ACTION_SHOW_BRIGHTNESS_DIALOG),
Alan Viverette5a399492014-07-14 16:19:38 -07003196 UserHandle.CURRENT_OR_SELF);
Michael Wrightb854e242013-02-05 17:54:02 -08003197 }
3198 return -1;
Jaewan Kim765487f2016-01-12 14:45:42 +09003199 } else if (keyCode == KeyEvent.KEYCODE_VOLUME_UP
3200 || keyCode == KeyEvent.KEYCODE_VOLUME_DOWN
3201 || keyCode == KeyEvent.KEYCODE_VOLUME_MUTE) {
3202 if (mUseTvRouting) {
3203 // On TVs volume keys never go to the foreground app.
3204 dispatchDirectAudioEvent(event);
3205 return -1;
3206 }
Muyuan Li94ce94e2016-02-24 16:20:54 -08003207 }
3208
3209 if (KeyEvent.isMetaKey(keyCode)) {
Michael Wright6a62e552014-06-03 19:19:48 -07003210 if (down) {
3211 mPendingMetaAction = true;
3212 } else if (mPendingMetaAction) {
Tim Kilbourn0e5f1102015-06-05 16:18:09 -07003213 launchAssistAction(Intent.EXTRA_ASSIST_INPUT_HINT_KEYBOARD, event.getDeviceId());
Michael Wright6a62e552014-06-03 19:19:48 -07003214 }
3215 return -1;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003216 }
Jeff Browncaab4d02010-12-09 22:13:41 -08003217
Jeff Brownc1fb48d2010-12-08 16:52:09 -08003218 // Shortcuts are invoked through Search+key, so intercept those here
Jeff Browncaab4d02010-12-09 22:13:41 -08003219 // Any printing key that is chorded with Search should be consumed
3220 // even if no shortcut was invoked. This prevents text from being
3221 // inadvertently inserted when using a keyboard that has built-in macro
3222 // shortcut keys (that emit Search+x) and some of them are not registered.
Jeff Brownfd23e3e2012-05-09 13:34:28 -07003223 if (mSearchKeyShortcutPending) {
Jeff Browncaab4d02010-12-09 22:13:41 -08003224 final KeyCharacterMap kcm = event.getKeyCharacterMap();
3225 if (kcm.isPrintingKey(keyCode)) {
Jeff Brownfd23e3e2012-05-09 13:34:28 -07003226 mConsumeSearchKeyUp = true;
3227 mSearchKeyShortcutPending = false;
Jeff Browncaab4d02010-12-09 22:13:41 -08003228 if (down && repeatCount == 0 && !keyguardOn) {
3229 Intent shortcutIntent = mShortcutManager.getIntent(kcm, keyCode, metaState);
3230 if (shortcutIntent != null) {
3231 shortcutIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
Jeff Brownf0a3cc52011-01-26 18:42:46 -08003232 try {
Bart Sears8b1c27c2015-03-18 23:51:02 +00003233 startActivityAsUser(shortcutIntent, UserHandle.CURRENT);
Jeff Brownf0a3cc52011-01-26 18:42:46 -08003234 } catch (ActivityNotFoundException ex) {
3235 Slog.w(TAG, "Dropping shortcut key combination because "
3236 + "the activity to which it is registered was not found: "
Jeff Brownfd23e3e2012-05-09 13:34:28 -07003237 + "SEARCH+" + KeyEvent.keyCodeToString(keyCode), ex);
Jeff Brownf0a3cc52011-01-26 18:42:46 -08003238 }
Jeff Browncaab4d02010-12-09 22:13:41 -08003239 } else {
3240 Slog.i(TAG, "Dropping unregistered shortcut key combination: "
Jeff Brownfd23e3e2012-05-09 13:34:28 -07003241 + "SEARCH+" + KeyEvent.keyCodeToString(keyCode));
Jeff Brown49ed71d2010-12-06 17:13:33 -08003242 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003243 }
Jeff Brownd5bb82d2011-10-12 13:57:59 -07003244 return -1;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003245 }
3246 }
3247
Jeff Brown68b909d2011-12-07 16:36:01 -08003248 // Invoke shortcuts using Meta.
Jeff Brown602ab322012-05-16 13:33:47 -07003249 if (down && repeatCount == 0 && !keyguardOn
Jeff Brown68b909d2011-12-07 16:36:01 -08003250 && (metaState & KeyEvent.META_META_ON) != 0) {
3251 final KeyCharacterMap kcm = event.getKeyCharacterMap();
Jeff Brown602ab322012-05-16 13:33:47 -07003252 if (kcm.isPrintingKey(keyCode)) {
3253 Intent shortcutIntent = mShortcutManager.getIntent(kcm, keyCode,
3254 metaState & ~(KeyEvent.META_META_ON
3255 | KeyEvent.META_META_LEFT_ON | KeyEvent.META_META_RIGHT_ON));
3256 if (shortcutIntent != null) {
3257 shortcutIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
3258 try {
Bart Sears8b1c27c2015-03-18 23:51:02 +00003259 startActivityAsUser(shortcutIntent, UserHandle.CURRENT);
Jeff Brown602ab322012-05-16 13:33:47 -07003260 } catch (ActivityNotFoundException ex) {
3261 Slog.w(TAG, "Dropping shortcut key combination because "
3262 + "the activity to which it is registered was not found: "
3263 + "META+" + KeyEvent.keyCodeToString(keyCode), ex);
3264 }
3265 return -1;
Jeff Brown68b909d2011-12-07 16:36:01 -08003266 }
Jeff Brown68b909d2011-12-07 16:36:01 -08003267 }
3268 }
3269
Jeff Brown6651a632011-11-28 12:59:11 -08003270 // Handle application launch keys.
Jeff Brown602ab322012-05-16 13:33:47 -07003271 if (down && repeatCount == 0 && !keyguardOn) {
Jeff Brown6651a632011-11-28 12:59:11 -08003272 String category = sApplicationLaunchKeyCategories.get(keyCode);
3273 if (category != null) {
Dianne Hackbornf5b86712011-12-05 17:42:41 -08003274 Intent intent = Intent.makeMainSelectorActivity(Intent.ACTION_MAIN, category);
Jeff Brown6651a632011-11-28 12:59:11 -08003275 intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
3276 try {
Bart Sears8b1c27c2015-03-18 23:51:02 +00003277 startActivityAsUser(intent, UserHandle.CURRENT);
Jeff Brown6651a632011-11-28 12:59:11 -08003278 } catch (ActivityNotFoundException ex) {
3279 Slog.w(TAG, "Dropping application launch key because "
3280 + "the activity to which it is registered was not found: "
3281 + "keyCode=" + keyCode + ", category=" + category, ex);
3282 }
Jeff Brown68b909d2011-12-07 16:36:01 -08003283 return -1;
Jeff Brown6651a632011-11-28 12:59:11 -08003284 }
3285 }
3286
Michael Wright61c46752014-08-21 16:57:33 -07003287 // Display task switcher for ALT-TAB.
Jeff Brown68b909d2011-12-07 16:36:01 -08003288 if (down && repeatCount == 0 && keyCode == KeyEvent.KEYCODE_TAB) {
Michael Wrightd847ad52015-10-24 13:24:15 +01003289 if (mRecentAppsHeldModifiers == 0 && !keyguardOn && isUserSetupComplete()) {
Jeff Brown68b909d2011-12-07 16:36:01 -08003290 final int shiftlessModifiers = event.getModifiers() & ~KeyEvent.META_SHIFT_MASK;
Michael Wright61c46752014-08-21 16:57:33 -07003291 if (KeyEvent.metaStateHasModifiers(shiftlessModifiers, KeyEvent.META_ALT_ON)) {
Winson Chung1e8d71b2014-05-16 17:05:22 -07003292 mRecentAppsHeldModifiers = shiftlessModifiers;
3293 showRecentApps(true);
Jeff Brown68b909d2011-12-07 16:36:01 -08003294 return -1;
3295 }
3296 }
Winson Chung1e8d71b2014-05-16 17:05:22 -07003297 } else if (!down && mRecentAppsHeldModifiers != 0
3298 && (metaState & mRecentAppsHeldModifiers) == 0) {
3299 mRecentAppsHeldModifiers = 0;
Winson Chungcdcd4872014-08-05 18:00:13 -07003300 hideRecentApps(true, false);
Jeff Brown68b909d2011-12-07 16:36:01 -08003301 }
3302
Yohei Yukawaae61f712015-12-09 13:00:10 -08003303 // Handle input method switching.
Jeff Browncf39bdf2012-05-18 14:41:19 -07003304 if (down && repeatCount == 0
3305 && (keyCode == KeyEvent.KEYCODE_LANGUAGE_SWITCH
3306 || (keyCode == KeyEvent.KEYCODE_SPACE
Yohei Yukawaae61f712015-12-09 13:00:10 -08003307 && (metaState & KeyEvent.META_META_MASK) != 0))) {
3308 final boolean forwardDirection = (metaState & KeyEvent.META_SHIFT_MASK) == 0;
3309 mWindowManagerFuncs.switchInputMethod(forwardDirection);
Jeff Browncf39bdf2012-05-18 14:41:19 -07003310 return -1;
3311 }
3312 if (mLanguageSwitchKeyPressed && !down
3313 && (keyCode == KeyEvent.KEYCODE_LANGUAGE_SWITCH
3314 || keyCode == KeyEvent.KEYCODE_SPACE)) {
3315 mLanguageSwitchKeyPressed = false;
3316 return -1;
3317 }
3318
Jeff Brown13f00f02014-10-31 14:45:50 -07003319 if (isValidGlobalKey(keyCode)
3320 && mGlobalKeyManager.handleGlobalKey(mContext, keyCode, event)) {
Justin Kohd378ad72013-04-01 12:18:26 -07003321 return -1;
3322 }
3323
Muyuan Li94ce94e2016-02-24 16:20:54 -08003324 if (down) {
3325 long shortcutCode = (long) keyCode;
3326 if (event.isCtrlPressed()) {
3327 shortcutCode |= ((long) KeyEvent.META_CTRL_ON) << Integer.SIZE;
3328 }
3329
3330 if (event.isAltPressed()) {
3331 shortcutCode |= ((long) KeyEvent.META_ALT_ON) << Integer.SIZE;
3332 }
3333
3334 if (event.isShiftPressed()) {
3335 shortcutCode |= ((long) KeyEvent.META_SHIFT_ON) << Integer.SIZE;
3336 }
3337
3338 if (event.isMetaPressed()) {
3339 shortcutCode |= ((long) KeyEvent.META_META_ON) << Integer.SIZE;
3340 }
3341
3342 IShortcutService shortcutService = mShortcutKeyServices.get(shortcutCode);
3343 if (shortcutService != null) {
3344 try {
3345 shortcutService.notifyShortcutKeyPressed(shortcutCode);
3346 } catch (RemoteException e) {
3347 mShortcutKeyServices.delete(shortcutCode);
3348 }
3349 return -1;
3350 }
3351 }
3352
Michael Wright6a62e552014-06-03 19:19:48 -07003353 // Reserve all the META modifier combos for system behavior
Michael Wrightce0c13a2014-07-30 10:49:21 -07003354 if ((metaState & KeyEvent.META_META_ON) != 0) {
Michael Wright6a62e552014-06-03 19:19:48 -07003355 return -1;
3356 }
3357
Jeff Brown68b909d2011-12-07 16:36:01 -08003358 // Let the application handle the key.
Jeff Brownd5bb82d2011-10-12 13:57:59 -07003359 return 0;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003360 }
3361
Jeff Brown3915bb82010-11-05 15:02:16 -07003362 /** {@inheritDoc} */
3363 @Override
Jeff Brown49ed71d2010-12-06 17:13:33 -08003364 public KeyEvent dispatchUnhandledKey(WindowState win, KeyEvent event, int policyFlags) {
Jeff Brown54875002011-04-06 15:33:01 -07003365 // Note: This method is only called if the initial down was unhandled.
Jeff Brown40013652012-05-16 21:22:36 -07003366 if (DEBUG_INPUT) {
Jeff Brown1f245102010-11-18 20:53:46 -08003367 Slog.d(TAG, "Unhandled key: win=" + win + ", action=" + event.getAction()
3368 + ", flags=" + event.getFlags()
3369 + ", keyCode=" + event.getKeyCode()
3370 + ", scanCode=" + event.getScanCode()
3371 + ", metaState=" + event.getMetaState()
3372 + ", repeatCount=" + event.getRepeatCount()
3373 + ", policyFlags=" + policyFlags);
Jeff Brown3915bb82010-11-05 15:02:16 -07003374 }
Jeff Brown49ed71d2010-12-06 17:13:33 -08003375
Jeff Brownfd23e3e2012-05-09 13:34:28 -07003376 KeyEvent fallbackEvent = null;
Jeff Brown49ed71d2010-12-06 17:13:33 -08003377 if ((event.getFlags() & KeyEvent.FLAG_FALLBACK) == 0) {
3378 final KeyCharacterMap kcm = event.getKeyCharacterMap();
Jeff Brownc1fb48d2010-12-08 16:52:09 -08003379 final int keyCode = event.getKeyCode();
3380 final int metaState = event.getMetaState();
Jeff Brownfd23e3e2012-05-09 13:34:28 -07003381 final boolean initialDown = event.getAction() == KeyEvent.ACTION_DOWN
3382 && event.getRepeatCount() == 0;
Jeff Brown49ed71d2010-12-06 17:13:33 -08003383
Jeff Brown54875002011-04-06 15:33:01 -07003384 // Check for fallback actions specified by the key character map.
Jeff Brownfd23e3e2012-05-09 13:34:28 -07003385 final FallbackAction fallbackAction;
3386 if (initialDown) {
3387 fallbackAction = kcm.getFallbackAction(keyCode, metaState);
3388 } else {
3389 fallbackAction = mFallbackActions.get(keyCode);
3390 }
3391
3392 if (fallbackAction != null) {
Jeff Brown40013652012-05-16 21:22:36 -07003393 if (DEBUG_INPUT) {
Jeff Brownfd23e3e2012-05-09 13:34:28 -07003394 Slog.d(TAG, "Fallback: keyCode=" + fallbackAction.keyCode
3395 + " metaState=" + Integer.toHexString(fallbackAction.metaState));
Jeff Brown49ed71d2010-12-06 17:13:33 -08003396 }
3397
Jeff Brownfd23e3e2012-05-09 13:34:28 -07003398 final int flags = event.getFlags() | KeyEvent.FLAG_FALLBACK;
3399 fallbackEvent = KeyEvent.obtain(
Jeff Brown49ed71d2010-12-06 17:13:33 -08003400 event.getDownTime(), event.getEventTime(),
Jeff Brownfd23e3e2012-05-09 13:34:28 -07003401 event.getAction(), fallbackAction.keyCode,
3402 event.getRepeatCount(), fallbackAction.metaState,
Jeff Brown49ed71d2010-12-06 17:13:33 -08003403 event.getDeviceId(), event.getScanCode(),
3404 flags, event.getSource(), null);
Jeff Brownfd23e3e2012-05-09 13:34:28 -07003405
3406 if (!interceptFallback(win, fallbackEvent, policyFlags)) {
3407 fallbackEvent.recycle();
3408 fallbackEvent = null;
Jeff Brown49ed71d2010-12-06 17:13:33 -08003409 }
Jeff Brownfd23e3e2012-05-09 13:34:28 -07003410
3411 if (initialDown) {
3412 mFallbackActions.put(keyCode, fallbackAction);
3413 } else if (event.getAction() == KeyEvent.ACTION_UP) {
3414 mFallbackActions.remove(keyCode);
3415 fallbackAction.recycle();
3416 }
Jeff Brown49ed71d2010-12-06 17:13:33 -08003417 }
3418 }
3419
Jeff Brown40013652012-05-16 21:22:36 -07003420 if (DEBUG_INPUT) {
Jeff Brownfd23e3e2012-05-09 13:34:28 -07003421 if (fallbackEvent == null) {
3422 Slog.d(TAG, "No fallback.");
3423 } else {
3424 Slog.d(TAG, "Performing fallback: " + fallbackEvent);
3425 }
Jeff Brown49ed71d2010-12-06 17:13:33 -08003426 }
Jeff Brownfd23e3e2012-05-09 13:34:28 -07003427 return fallbackEvent;
Jeff Brown3915bb82010-11-05 15:02:16 -07003428 }
3429
Jeff Brownfd23e3e2012-05-09 13:34:28 -07003430 private boolean interceptFallback(WindowState win, KeyEvent fallbackEvent, int policyFlags) {
Jeff Brown037c33e2014-04-09 00:31:55 -07003431 int actions = interceptKeyBeforeQueueing(fallbackEvent, policyFlags);
Jeff Brownfd23e3e2012-05-09 13:34:28 -07003432 if ((actions & ACTION_PASS_TO_USER) != 0) {
3433 long delayMillis = interceptKeyBeforeDispatching(
3434 win, fallbackEvent, policyFlags);
3435 if (delayMillis == 0) {
3436 return true;
3437 }
3438 }
3439 return false;
Jeff Brown6f2fba42011-02-19 01:08:02 -08003440 }
3441
Muyuan Li94ce94e2016-02-24 16:20:54 -08003442 public void registerShortcutKey(long shortcutCode, IShortcutService shortcutService)
3443 throws RemoteException {
3444 synchronized (mLock) {
3445 IShortcutService service = mShortcutKeyServices.get(shortcutCode);
Muyuan Li24d24ac2016-03-03 21:15:02 -08003446 if (service != null && service.asBinder().pingBinder()) {
3447 throw new RemoteException("Key already exists.");
Muyuan Li94ce94e2016-02-24 16:20:54 -08003448 }
3449
3450 mShortcutKeyServices.put(shortcutCode, shortcutService);
3451 }
3452 }
3453
Jeff Brownde7a8ea2012-06-13 18:28:57 -07003454 private void launchAssistLongPressAction() {
3455 performHapticFeedbackLw(null, HapticFeedbackConstants.LONG_PRESS, false);
3456 sendCloseSystemWindows(SYSTEM_DIALOG_REASON_ASSIST);
3457
3458 // launch the search activity
3459 Intent intent = new Intent(Intent.ACTION_SEARCH_LONG_PRESS);
3460 intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
3461 try {
RoboErik8a2cfc32014-05-16 11:19:38 -07003462 // TODO: This only stops the factory-installed search manager.
Jim Miller45308b12012-06-18 19:23:39 -07003463 // Need to formalize an API to handle others
Jeff Brownde7a8ea2012-06-13 18:28:57 -07003464 SearchManager searchManager = getSearchManager();
3465 if (searchManager != null) {
3466 searchManager.stopSearch();
3467 }
Bart Sears8b1c27c2015-03-18 23:51:02 +00003468 startActivityAsUser(intent, UserHandle.CURRENT);
Jeff Brownde7a8ea2012-06-13 18:28:57 -07003469 } catch (ActivityNotFoundException e) {
3470 Slog.w(TAG, "No activity to handle assist long press action.", e);
3471 }
3472 }
3473
Tim Kilbourn0e5f1102015-06-05 16:18:09 -07003474 private void launchAssistAction(String hint, int deviceId) {
Jeff Brownde7a8ea2012-06-13 18:28:57 -07003475 sendCloseSystemWindows(SYSTEM_DIALOG_REASON_ASSIST);
Maurice Lam39d13812015-07-23 20:49:20 -07003476 if (!isUserSetupComplete()) {
3477 // Disable opening assist window during setup
3478 return;
3479 }
Tim Kilbourn0e5f1102015-06-05 16:18:09 -07003480 Bundle args = null;
3481 if (deviceId > Integer.MIN_VALUE) {
3482 args = new Bundle();
3483 args.putInt(Intent.EXTRA_ASSIST_INPUT_DEVICE_ID, deviceId);
Jeff Brownde7a8ea2012-06-13 18:28:57 -07003484 }
Jorim Jaggi165ce062015-07-06 16:18:11 -07003485 if ((mContext.getResources().getConfiguration().uiMode
3486 & Configuration.UI_MODE_TYPE_MASK) == Configuration.UI_MODE_TYPE_TELEVISION) {
3487 // On TV, use legacy handling until assistants are implemented in the proper way.
3488 ((SearchManager) mContext.getSystemService(Context.SEARCH_SERVICE))
3489 .launchLegacyAssist(hint, UserHandle.myUserId(), args);
3490 } else {
3491 try {
3492 if (hint != null) {
3493 if (args == null) {
3494 args = new Bundle();
3495 }
3496 args.putBoolean(hint, true);
3497 }
3498 IStatusBarService statusbar = getStatusBarService();
3499 if (statusbar != null) {
3500 statusbar.startAssist(args);
3501 }
3502 } catch (RemoteException e) {
3503 Slog.e(TAG, "RemoteException when starting assist", e);
3504 // re-acquire status bar service next time it is needed.
3505 mStatusBarService = null;
3506 }
3507 }
Jeff Brownde7a8ea2012-06-13 18:28:57 -07003508 }
3509
Bart Sears8b1c27c2015-03-18 23:51:02 +00003510 private void startActivityAsUser(Intent intent, UserHandle handle) {
3511 if (isUserSetupComplete()) {
3512 mContext.startActivityAsUser(intent, handle);
3513 } else {
3514 Slog.i(TAG, "Not starting activity because user setup is in progress: " + intent);
3515 }
3516 }
3517
Jeff Brownde7a8ea2012-06-13 18:28:57 -07003518 private SearchManager getSearchManager() {
3519 if (mSearchManager == null) {
3520 mSearchManager = (SearchManager) mContext.getSystemService(Context.SEARCH_SERVICE);
3521 }
3522 return mSearchManager;
3523 }
3524
Jeff Browncaca8812013-05-09 13:34:33 -07003525 private void preloadRecentApps() {
3526 mPreloadedRecentApps = true;
3527 try {
3528 IStatusBarService statusbar = getStatusBarService();
3529 if (statusbar != null) {
3530 statusbar.preloadRecentApps();
3531 }
3532 } catch (RemoteException e) {
3533 Slog.e(TAG, "RemoteException when preloading recent apps", e);
3534 // re-acquire status bar service next time it is needed.
3535 mStatusBarService = null;
3536 }
3537 }
3538
3539 private void cancelPreloadRecentApps() {
3540 if (mPreloadedRecentApps) {
3541 mPreloadedRecentApps = false;
3542 try {
3543 IStatusBarService statusbar = getStatusBarService();
3544 if (statusbar != null) {
3545 statusbar.cancelPreloadRecentApps();
3546 }
3547 } catch (RemoteException e) {
Winson Chung1e8d71b2014-05-16 17:05:22 -07003548 Slog.e(TAG, "RemoteException when cancelling recent apps preload", e);
Jeff Browncaca8812013-05-09 13:34:33 -07003549 // re-acquire status bar service next time it is needed.
3550 mStatusBarService = null;
3551 }
3552 }
3553 }
3554
3555 private void toggleRecentApps() {
3556 mPreloadedRecentApps = false; // preloading no longer needs to be canceled
Jeff Browncaca8812013-05-09 13:34:33 -07003557 try {
3558 IStatusBarService statusbar = getStatusBarService();
3559 if (statusbar != null) {
3560 statusbar.toggleRecentApps();
3561 }
3562 } catch (RemoteException e) {
Winson Chung1e8d71b2014-05-16 17:05:22 -07003563 Slog.e(TAG, "RemoteException when toggling recent apps", e);
3564 // re-acquire status bar service next time it is needed.
3565 mStatusBarService = null;
3566 }
3567 }
3568
Craig Mautner84984fa2014-06-19 11:19:20 -07003569 @Override
3570 public void showRecentApps() {
3571 mHandler.removeMessages(MSG_DISPATCH_SHOW_RECENTS);
3572 mHandler.sendEmptyMessage(MSG_DISPATCH_SHOW_RECENTS);
3573 }
3574
Winson Chung1e8d71b2014-05-16 17:05:22 -07003575 private void showRecentApps(boolean triggeredFromAltTab) {
3576 mPreloadedRecentApps = false; // preloading no longer needs to be canceled
3577 try {
3578 IStatusBarService statusbar = getStatusBarService();
3579 if (statusbar != null) {
3580 statusbar.showRecentApps(triggeredFromAltTab);
3581 }
3582 } catch (RemoteException e) {
Jeff Browncaca8812013-05-09 13:34:33 -07003583 Slog.e(TAG, "RemoteException when showing recent apps", e);
3584 // re-acquire status bar service next time it is needed.
3585 mStatusBarService = null;
3586 }
3587 }
3588
Clara Bayarri4e850ff2016-03-02 11:12:32 -08003589 private void toggleKeyboardShortcutsMenu(int deviceId) {
Clara Bayarrif2debb12015-07-10 14:47:17 +01003590 try {
3591 IStatusBarService statusbar = getStatusBarService();
3592 if (statusbar != null) {
Clara Bayarri4e850ff2016-03-02 11:12:32 -08003593 statusbar.toggleKeyboardShortcutsMenu(deviceId);
Clara Bayarrif2debb12015-07-10 14:47:17 +01003594 }
3595 } catch (RemoteException e) {
3596 Slog.e(TAG, "RemoteException when showing keyboard shortcuts menu", e);
3597 }
3598 }
3599
Winson Chungcdcd4872014-08-05 18:00:13 -07003600 private void hideRecentApps(boolean triggeredFromAltTab, boolean triggeredFromHome) {
Winson Chung1e8d71b2014-05-16 17:05:22 -07003601 mPreloadedRecentApps = false; // preloading no longer needs to be canceled
3602 try {
3603 IStatusBarService statusbar = getStatusBarService();
3604 if (statusbar != null) {
Winson Chungcdcd4872014-08-05 18:00:13 -07003605 statusbar.hideRecentApps(triggeredFromAltTab, triggeredFromHome);
Winson Chung1e8d71b2014-05-16 17:05:22 -07003606 }
3607 } catch (RemoteException e) {
3608 Slog.e(TAG, "RemoteException when closing recent apps", e);
3609 // re-acquire status bar service next time it is needed.
3610 mStatusBarService = null;
3611 }
3612 }
3613
Filip Gruszczynskia483a1d2015-03-17 19:06:58 +00003614 void launchHomeFromHotKey() {
Bryce Lee662ed802015-04-10 20:11:39 +00003615 launchHomeFromHotKey(true /* awakenFromDreams */, true /*respectKeyguard*/);
Filip Gruszczynskia483a1d2015-03-17 19:06:58 +00003616 }
3617
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003618 /**
3619 * A home key -> launch home action was detected. Take the appropriate action
3620 * given the situation with the keyguard.
3621 */
Bryce Lee662ed802015-04-10 20:11:39 +00003622 void launchHomeFromHotKey(final boolean awakenFromDreams, final boolean respectKeyguard) {
3623 if (respectKeyguard) {
3624 if (isKeyguardShowingAndNotOccluded()) {
3625 // don't launch home if keyguard showing
3626 return;
3627 }
3628
3629 if (!mHideLockScreen && mKeyguardDelegate.isInputRestricted()) {
3630 // when in keyguard restricted mode, must first verify unlock
3631 // before launching home
3632 mKeyguardDelegate.verifyUnlock(new OnKeyguardExitResult() {
3633 @Override
3634 public void onKeyguardExitResult(boolean success) {
3635 if (success) {
3636 try {
3637 ActivityManagerNative.getDefault().stopAppSwitches();
3638 } catch (RemoteException e) {
3639 }
3640 sendCloseSystemWindows(SYSTEM_DIALOG_REASON_HOME_KEY);
3641 startDockOrHome(true /*fromHomeKey*/, awakenFromDreams);
Dianne Hackborn256dd3b2009-05-19 18:51:21 -07003642 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003643 }
Bryce Lee662ed802015-04-10 20:11:39 +00003644 });
3645 return;
3646 }
3647 }
3648
3649 // no keyguard stuff to worry about, just launch home!
3650 try {
3651 ActivityManagerNative.getDefault().stopAppSwitches();
3652 } catch (RemoteException e) {
3653 }
3654 if (mRecentsVisible) {
3655 // Hide Recents and notify it to launch Home
3656 if (awakenFromDreams) {
3657 awakenDreams();
3658 }
Bryce Lee662ed802015-04-10 20:11:39 +00003659 hideRecentApps(false, true);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003660 } else {
Bryce Lee662ed802015-04-10 20:11:39 +00003661 // Otherwise, just launch Home
3662 sendCloseSystemWindows(SYSTEM_DIALOG_REASON_HOME_KEY);
3663 startDockOrHome(true /*fromHomeKey*/, awakenFromDreams);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003664 }
3665 }
3666
John Spurlock04db1762013-05-13 12:46:41 -04003667 private final Runnable mClearHideNavigationFlag = new Runnable() {
3668 @Override
3669 public void run() {
3670 synchronized (mWindowManagerFuncs.getWindowManagerLock()) {
3671 // Clear flags.
3672 mForceClearedSystemUiFlags &=
3673 ~View.SYSTEM_UI_FLAG_HIDE_NAVIGATION;
3674 }
3675 mWindowManagerFuncs.reevaluateStatusBarVisibility();
Dianne Hackborne26ab702011-10-16 13:21:33 -07003676 }
3677 };
3678
3679 /**
3680 * Input handler used while nav bar is hidden. Captures any touch on the screen,
3681 * to determine when the nav bar should be shown and prevent applications from
3682 * receiving those touches.
3683 */
Jeff Brown32cbc38552011-12-01 14:01:49 -08003684 final class HideNavInputEventReceiver extends InputEventReceiver {
3685 public HideNavInputEventReceiver(InputChannel inputChannel, Looper looper) {
3686 super(inputChannel, looper);
3687 }
3688
Dianne Hackborndf89e652011-10-06 22:35:11 -07003689 @Override
Jeff Brown32cbc38552011-12-01 14:01:49 -08003690 public void onInputEvent(InputEvent event) {
Dianne Hackborndf89e652011-10-06 22:35:11 -07003691 boolean handled = false;
3692 try {
Jeff Brown4952dfd2011-11-30 19:23:22 -08003693 if (event instanceof MotionEvent
3694 && (event.getSource() & InputDevice.SOURCE_CLASS_POINTER) != 0) {
3695 final MotionEvent motionEvent = (MotionEvent)event;
3696 if (motionEvent.getAction() == MotionEvent.ACTION_DOWN) {
Dianne Hackborndf89e652011-10-06 22:35:11 -07003697 // When the user taps down, we re-show the nav bar.
3698 boolean changed = false;
John Spurlock04db1762013-05-13 12:46:41 -04003699 synchronized (mWindowManagerFuncs.getWindowManagerLock()) {
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07003700 // Any user activity always causes us to show the
3701 // navigation controls, if they had been hidden.
3702 // We also clear the low profile and only content
3703 // flags so that tapping on the screen will atomically
3704 // restore all currently hidden screen decorations.
3705 int newVal = mResettingSystemUiFlags |
3706 View.SYSTEM_UI_FLAG_HIDE_NAVIGATION |
3707 View.SYSTEM_UI_FLAG_LOW_PROFILE |
3708 View.SYSTEM_UI_FLAG_FULLSCREEN;
Dianne Hackborne26ab702011-10-16 13:21:33 -07003709 if (mResettingSystemUiFlags != newVal) {
3710 mResettingSystemUiFlags = newVal;
Dianne Hackborndf89e652011-10-06 22:35:11 -07003711 changed = true;
3712 }
Dianne Hackborne26ab702011-10-16 13:21:33 -07003713 // We don't allow the system's nav bar to be hidden
3714 // again for 1 second, to prevent applications from
3715 // spamming us and keeping it from being shown.
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07003716 newVal = mForceClearedSystemUiFlags |
3717 View.SYSTEM_UI_FLAG_HIDE_NAVIGATION;
Dianne Hackborne26ab702011-10-16 13:21:33 -07003718 if (mForceClearedSystemUiFlags != newVal) {
3719 mForceClearedSystemUiFlags = newVal;
3720 changed = true;
John Spurlock04db1762013-05-13 12:46:41 -04003721 mHandler.postDelayed(mClearHideNavigationFlag, 1000);
Dianne Hackborne26ab702011-10-16 13:21:33 -07003722 }
Dianne Hackborndf89e652011-10-06 22:35:11 -07003723 }
3724 if (changed) {
3725 mWindowManagerFuncs.reevaluateStatusBarVisibility();
3726 }
3727 }
3728 }
3729 } finally {
Jeff Brown32cbc38552011-12-01 14:01:49 -08003730 finishInputEvent(event, handled);
Dianne Hackborndf89e652011-10-06 22:35:11 -07003731 }
3732 }
Jeff Brown32cbc38552011-12-01 14:01:49 -08003733 }
3734 final InputEventReceiver.Factory mHideNavInputEventReceiverFactory =
3735 new InputEventReceiver.Factory() {
3736 @Override
3737 public InputEventReceiver createInputEventReceiver(
3738 InputChannel inputChannel, Looper looper) {
3739 return new HideNavInputEventReceiver(inputChannel, looper);
3740 }
Dianne Hackborndf89e652011-10-06 22:35:11 -07003741 };
3742
3743 @Override
3744 public int adjustSystemUiVisibilityLw(int visibility) {
John Spurlock5b9145b2013-08-20 15:13:47 -04003745 mStatusBarController.adjustSystemUiVisibilityLw(mLastSystemUiFlags, visibility);
3746 mNavigationBarController.adjustSystemUiVisibilityLw(mLastSystemUiFlags, visibility);
Winson Chungd42a6cf2014-06-03 16:24:04 -07003747 mRecentsVisible = (visibility & View.RECENT_APPS_VISIBLE) > 0;
John Spurlock27735a42013-08-14 17:57:38 -04003748
Dianne Hackborndf89e652011-10-06 22:35:11 -07003749 // Reset any bits in mForceClearingStatusBarVisibility that
3750 // are now clear.
Dianne Hackborne26ab702011-10-16 13:21:33 -07003751 mResettingSystemUiFlags &= visibility;
Dianne Hackborndf89e652011-10-06 22:35:11 -07003752 // Clear any bits in the new visibility that are currently being
3753 // force cleared, before reporting it.
Dianne Hackborne26ab702011-10-16 13:21:33 -07003754 return visibility & ~mResettingSystemUiFlags
3755 & ~mForceClearedSystemUiFlags;
Dianne Hackborndf89e652011-10-06 22:35:11 -07003756 }
3757
Craig Mautner69b08182012-09-05 13:07:13 -07003758 @Override
Jorim Jaggi0ffd49c2016-02-12 15:04:21 -08003759 public boolean getInsetHintLw(WindowManager.LayoutParams attrs, int displayRotation,
Filip Gruszczynski2987f612015-06-30 15:03:30 -07003760 Rect outContentInsets, Rect outStableInsets, Rect outOutsets) {
John Spurlockc6d1c602014-01-17 15:22:06 -05003761 final int fl = PolicyControl.getWindowFlags(null, attrs);
John Spurlock1db8b682014-02-18 11:18:59 -05003762 final int sysuiVis = PolicyControl.getSystemUiVisibility(null, attrs);
3763 final int systemUiVisibility = (sysuiVis | attrs.subtreeSystemUiVisibility);
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07003764
Filip Gruszczynski2987f612015-06-30 15:03:30 -07003765 final boolean useOutsets = outOutsets != null && shouldUseOutsets(attrs, fl);
3766 if (useOutsets) {
3767 int outset = ScreenShapeHelper.getWindowOutsetBottomPx(mContext.getResources());
3768 if (outset > 0) {
3769 if (displayRotation == Surface.ROTATION_0) {
3770 outOutsets.bottom += outset;
3771 } else if (displayRotation == Surface.ROTATION_90) {
3772 outOutsets.right += outset;
3773 } else if (displayRotation == Surface.ROTATION_180) {
3774 outOutsets.top += outset;
3775 } else if (displayRotation == Surface.ROTATION_270) {
3776 outOutsets.left += outset;
3777 }
3778 }
3779 }
3780
Dianne Hackborn5b5cc4d2012-05-16 13:15:00 -07003781 if ((fl & (FLAG_LAYOUT_IN_SCREEN | FLAG_LAYOUT_INSET_DECOR))
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003782 == (FLAG_LAYOUT_IN_SCREEN | FLAG_LAYOUT_INSET_DECOR)) {
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07003783 int availRight, availBottom;
Alan Viverette5a0f4ec2013-10-07 15:10:29 -07003784 if (canHideNavigationBar() &&
Dianne Hackborn5b5cc4d2012-05-16 13:15:00 -07003785 (systemUiVisibility & View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION) != 0) {
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07003786 availRight = mUnrestrictedScreenLeft + mUnrestrictedScreenWidth;
3787 availBottom = mUnrestrictedScreenTop + mUnrestrictedScreenHeight;
3788 } else {
3789 availRight = mRestrictedScreenLeft + mRestrictedScreenWidth;
3790 availBottom = mRestrictedScreenTop + mRestrictedScreenHeight;
3791 }
Dianne Hackborn5b5cc4d2012-05-16 13:15:00 -07003792 if ((systemUiVisibility & View.SYSTEM_UI_FLAG_LAYOUT_STABLE) != 0) {
3793 if ((fl & FLAG_FULLSCREEN) != 0) {
Adrian Roos37d7a682014-11-06 18:15:16 +01003794 outContentInsets.set(mStableFullscreenLeft, mStableFullscreenTop,
Dianne Hackborn5b5cc4d2012-05-16 13:15:00 -07003795 availRight - mStableFullscreenRight,
3796 availBottom - mStableFullscreenBottom);
3797 } else {
Adrian Roos37d7a682014-11-06 18:15:16 +01003798 outContentInsets.set(mStableLeft, mStableTop,
Dianne Hackborn5b5cc4d2012-05-16 13:15:00 -07003799 availRight - mStableRight, availBottom - mStableBottom);
3800 }
Dianne Hackbornc652de82013-02-15 16:32:56 -08003801 } else if ((fl & FLAG_FULLSCREEN) != 0 || (fl & FLAG_LAYOUT_IN_OVERSCAN) != 0) {
Adrian Roos37d7a682014-11-06 18:15:16 +01003802 outContentInsets.setEmpty();
Dianne Hackborn5b5cc4d2012-05-16 13:15:00 -07003803 } else if ((systemUiVisibility & (View.SYSTEM_UI_FLAG_FULLSCREEN
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07003804 | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN)) == 0) {
Adrian Roos37d7a682014-11-06 18:15:16 +01003805 outContentInsets.set(mCurLeft, mCurTop,
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07003806 availRight - mCurRight, availBottom - mCurBottom);
3807 } else {
Adrian Roos37d7a682014-11-06 18:15:16 +01003808 outContentInsets.set(mCurLeft, mCurTop,
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07003809 availRight - mCurRight, availBottom - mCurBottom);
3810 }
Adrian Roos37d7a682014-11-06 18:15:16 +01003811
3812 outStableInsets.set(mStableLeft, mStableTop,
3813 availRight - mStableRight, availBottom - mStableBottom);
Jorim Jaggi0ffd49c2016-02-12 15:04:21 -08003814 return mForceShowSystemBars;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003815 }
Adrian Roos37d7a682014-11-06 18:15:16 +01003816 outContentInsets.setEmpty();
3817 outStableInsets.setEmpty();
Jorim Jaggi0ffd49c2016-02-12 15:04:21 -08003818 return mForceShowSystemBars;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003819 }
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07003820
Filip Gruszczynski2987f612015-06-30 15:03:30 -07003821 private boolean shouldUseOutsets(WindowManager.LayoutParams attrs, int fl) {
3822 return attrs.type == TYPE_WALLPAPER || (fl & (WindowManager.LayoutParams.FLAG_FULLSCREEN
3823 | WindowManager.LayoutParams.FLAG_LAYOUT_IN_OVERSCAN)) != 0;
3824 }
3825
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003826 /** {@inheritDoc} */
Craig Mautner69b08182012-09-05 13:07:13 -07003827 @Override
3828 public void beginLayoutLw(boolean isDefaultDisplay, int displayWidth, int displayHeight,
Sriram Viswanathan9ebbe6a2015-11-16 17:59:22 -08003829 int displayRotation, int uiMode) {
Filip Gruszczynski2987f612015-06-30 15:03:30 -07003830 mDisplayRotation = displayRotation;
Dianne Hackbornc652de82013-02-15 16:32:56 -08003831 final int overscanLeft, overscanTop, overscanRight, overscanBottom;
3832 if (isDefaultDisplay) {
3833 switch (displayRotation) {
3834 case Surface.ROTATION_90:
3835 overscanLeft = mOverscanTop;
3836 overscanTop = mOverscanRight;
3837 overscanRight = mOverscanBottom;
3838 overscanBottom = mOverscanLeft;
3839 break;
3840 case Surface.ROTATION_180:
3841 overscanLeft = mOverscanRight;
3842 overscanTop = mOverscanBottom;
3843 overscanRight = mOverscanLeft;
3844 overscanBottom = mOverscanTop;
3845 break;
3846 case Surface.ROTATION_270:
3847 overscanLeft = mOverscanBottom;
3848 overscanTop = mOverscanLeft;
3849 overscanRight = mOverscanTop;
3850 overscanBottom = mOverscanRight;
3851 break;
3852 default:
3853 overscanLeft = mOverscanLeft;
3854 overscanTop = mOverscanTop;
3855 overscanRight = mOverscanRight;
3856 overscanBottom = mOverscanBottom;
3857 break;
3858 }
3859 } else {
3860 overscanLeft = 0;
3861 overscanTop = 0;
3862 overscanRight = 0;
3863 overscanBottom = 0;
3864 }
Dianne Hackborn313440842013-02-19 19:22:59 -08003865 mOverscanScreenLeft = mRestrictedOverscanScreenLeft = 0;
3866 mOverscanScreenTop = mRestrictedOverscanScreenTop = 0;
3867 mOverscanScreenWidth = mRestrictedOverscanScreenWidth = displayWidth;
3868 mOverscanScreenHeight = mRestrictedOverscanScreenHeight = displayHeight;
Dianne Hackbornc652de82013-02-15 16:32:56 -08003869 mSystemLeft = 0;
3870 mSystemTop = 0;
3871 mSystemRight = displayWidth;
3872 mSystemBottom = displayHeight;
3873 mUnrestrictedScreenLeft = overscanLeft;
3874 mUnrestrictedScreenTop = overscanTop;
3875 mUnrestrictedScreenWidth = displayWidth - overscanLeft - overscanRight;
3876 mUnrestrictedScreenHeight = displayHeight - overscanTop - overscanBottom;
3877 mRestrictedScreenLeft = mUnrestrictedScreenLeft;
3878 mRestrictedScreenTop = mUnrestrictedScreenTop;
John Spurlockad3e6cb2013-04-30 08:47:43 -04003879 mRestrictedScreenWidth = mSystemGestures.screenWidth = mUnrestrictedScreenWidth;
3880 mRestrictedScreenHeight = mSystemGestures.screenHeight = mUnrestrictedScreenHeight;
Dianne Hackborne30e02f2014-05-27 18:24:45 -07003881 mDockLeft = mContentLeft = mVoiceContentLeft = mStableLeft = mStableFullscreenLeft
Dianne Hackbornc652de82013-02-15 16:32:56 -08003882 = mCurLeft = mUnrestrictedScreenLeft;
Dianne Hackborne30e02f2014-05-27 18:24:45 -07003883 mDockTop = mContentTop = mVoiceContentTop = mStableTop = mStableFullscreenTop
Dianne Hackbornc652de82013-02-15 16:32:56 -08003884 = mCurTop = mUnrestrictedScreenTop;
Dianne Hackborne30e02f2014-05-27 18:24:45 -07003885 mDockRight = mContentRight = mVoiceContentRight = mStableRight = mStableFullscreenRight
Dianne Hackbornc652de82013-02-15 16:32:56 -08003886 = mCurRight = displayWidth - overscanRight;
Dianne Hackborne30e02f2014-05-27 18:24:45 -07003887 mDockBottom = mContentBottom = mVoiceContentBottom = mStableBottom = mStableFullscreenBottom
Dianne Hackbornc652de82013-02-15 16:32:56 -08003888 = mCurBottom = displayHeight - overscanBottom;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003889 mDockLayer = 0x10000000;
Dianne Hackborn5c58de32012-04-28 19:52:37 -07003890 mStatusBarLayer = -1;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003891
Daniel Sandler8956dbb2011-04-22 07:55:02 -04003892 // start with the current dock rect, which will be (0,0,displayWidth,displayHeight)
3893 final Rect pf = mTmpParentFrame;
3894 final Rect df = mTmpDisplayFrame;
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003895 final Rect of = mTmpOverscanFrame;
Daniel Sandler8956dbb2011-04-22 07:55:02 -04003896 final Rect vf = mTmpVisibleFrame;
John Spurlock46646232013-09-30 22:32:42 -04003897 final Rect dcf = mTmpDecorFrame;
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003898 pf.left = df.left = of.left = vf.left = mDockLeft;
3899 pf.top = df.top = of.top = vf.top = mDockTop;
3900 pf.right = df.right = of.right = vf.right = mDockRight;
3901 pf.bottom = df.bottom = of.bottom = vf.bottom = mDockBottom;
John Spurlock46646232013-09-30 22:32:42 -04003902 dcf.setEmpty(); // Decor frame N/A for system bars.
Daniel Sandler8956dbb2011-04-22 07:55:02 -04003903
Craig Mautner69b08182012-09-05 13:07:13 -07003904 if (isDefaultDisplay) {
3905 // For purposes of putting out fake window up to steal focus, we will
3906 // drive nav being hidden only by whether it is requested.
John Spurlocke1f366f2013-08-05 12:22:40 -04003907 final int sysui = mLastSystemUiFlags;
3908 boolean navVisible = (sysui & View.SYSTEM_UI_FLAG_HIDE_NAVIGATION) == 0;
Adrian Roosea562512014-05-05 13:33:03 +02003909 boolean navTranslucent = (sysui
Jorim Jaggi4fa78922015-11-30 17:13:56 -08003910 & (View.NAVIGATION_BAR_TRANSLUCENT | View.NAVIGATION_BAR_TRANSPARENT)) != 0;
John Spurlockf1a36642013-10-12 17:50:42 -04003911 boolean immersive = (sysui & View.SYSTEM_UI_FLAG_IMMERSIVE) != 0;
3912 boolean immersiveSticky = (sysui & View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY) != 0;
3913 boolean navAllowedHidden = immersive || immersiveSticky;
3914 navTranslucent &= !immersiveSticky; // transient trumps translucent
Adrian Roos4fb3ee32014-08-22 19:29:09 +02003915 boolean isKeyguardShowing = isStatusBarKeyguard() && !mHideLockScreen;
3916 if (!isKeyguardShowing) {
3917 navTranslucent &= areTranslucentBarsAllowed();
3918 }
Dianne Hackborne26ab702011-10-16 13:21:33 -07003919
Craig Mautner69b08182012-09-05 13:07:13 -07003920 // When the navigation bar isn't visible, we put up a fake
3921 // input window to catch all touch events. This way we can
3922 // detect when the user presses anywhere to bring back the nav
3923 // bar and ensure the application doesn't see the event.
John Spurlockf1a36642013-10-12 17:50:42 -04003924 if (navVisible || navAllowedHidden) {
Selim Cinekf83e8242015-05-19 18:08:14 -07003925 if (mInputConsumer != null) {
3926 mInputConsumer.dismiss();
3927 mInputConsumer = null;
Craig Mautner69b08182012-09-05 13:07:13 -07003928 }
Selim Cinekf83e8242015-05-19 18:08:14 -07003929 } else if (mInputConsumer == null) {
3930 mInputConsumer = mWindowManagerFuncs.addInputConsumer(mHandler.getLooper(),
3931 mHideNavInputEventReceiverFactory);
Dianne Hackborne26ab702011-10-16 13:21:33 -07003932 }
Dianne Hackborne26ab702011-10-16 13:21:33 -07003933
Craig Mautner69b08182012-09-05 13:07:13 -07003934 // For purposes of positioning and showing the nav bar, if we have
3935 // decided that it can't be hidden (because of the screen aspect ratio),
3936 // then take that into account.
Alan Viverette5a0f4ec2013-10-07 15:10:29 -07003937 navVisible |= !canHideNavigationBar();
Dianne Hackbornf87d1962012-04-04 12:48:24 -07003938
Filip Gruszczynski83dd9552015-09-17 17:50:36 -07003939 boolean updateSysUiVisibility = layoutNavigationBar(displayWidth, displayHeight,
Sriram Viswanathan9ebbe6a2015-11-16 17:59:22 -08003940 displayRotation, uiMode, overscanRight, overscanBottom, dcf, navVisible, navTranslucent,
Filip Gruszczynski83dd9552015-09-17 17:50:36 -07003941 navAllowedHidden);
Craig Mautnereda67292013-04-28 13:50:14 -07003942 if (DEBUG_LAYOUT) Slog.i(TAG, String.format("mDock rect: (%d,%d - %d,%d)",
Craig Mautner69b08182012-09-05 13:07:13 -07003943 mDockLeft, mDockTop, mDockRight, mDockBottom));
Filip Gruszczynski83dd9552015-09-17 17:50:36 -07003944 updateSysUiVisibility |= layoutStatusBar(pf, df, of, vf, dcf, sysui, isKeyguardShowing);
John Spurlockad3e6cb2013-04-30 08:47:43 -04003945 if (updateSysUiVisibility) {
3946 updateSystemUiVisibilityLw();
3947 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003948 }
3949 }
3950
Filip Gruszczynski83dd9552015-09-17 17:50:36 -07003951 private boolean layoutStatusBar(Rect pf, Rect df, Rect of, Rect vf, Rect dcf, int sysui,
3952 boolean isKeyguardShowing) {
3953 // decide where the status bar goes ahead of time
3954 if (mStatusBar != null) {
3955 // apply any navigation bar insets
3956 pf.left = df.left = of.left = mUnrestrictedScreenLeft;
3957 pf.top = df.top = of.top = mUnrestrictedScreenTop;
3958 pf.right = df.right = of.right = mUnrestrictedScreenWidth + mUnrestrictedScreenLeft;
3959 pf.bottom = df.bottom = of.bottom = mUnrestrictedScreenHeight
3960 + mUnrestrictedScreenTop;
3961 vf.left = mStableLeft;
3962 vf.top = mStableTop;
3963 vf.right = mStableRight;
3964 vf.bottom = mStableBottom;
3965
3966 mStatusBarLayer = mStatusBar.getSurfaceLayer();
3967
3968 // Let the status bar determine its size.
3969 mStatusBar.computeFrameLw(pf /* parentFrame */, df /* displayFrame */,
3970 vf /* overlayFrame */, vf /* contentFrame */, vf /* visibleFrame */,
3971 dcf /* decorFrame */, vf /* stableFrame */, vf /* outsetFrame */);
3972
3973 // For layout, the status bar is always at the top with our fixed height.
3974 mStableTop = mUnrestrictedScreenTop + mStatusBarHeight;
3975
3976 boolean statusBarTransient = (sysui & View.STATUS_BAR_TRANSIENT) != 0;
3977 boolean statusBarTranslucent = (sysui
Jorim Jaggi4fa78922015-11-30 17:13:56 -08003978 & (View.STATUS_BAR_TRANSLUCENT | View.STATUS_BAR_TRANSPARENT)) != 0;
Filip Gruszczynski83dd9552015-09-17 17:50:36 -07003979 if (!isKeyguardShowing) {
3980 statusBarTranslucent &= areTranslucentBarsAllowed();
3981 }
3982
3983 // If the status bar is hidden, we don't want to cause
3984 // windows behind it to scroll.
3985 if (mStatusBar.isVisibleLw() && !statusBarTransient) {
3986 // Status bar may go away, so the screen area it occupies
3987 // is available to apps but just covering them when the
3988 // status bar is visible.
3989 mDockTop = mUnrestrictedScreenTop + mStatusBarHeight;
3990
3991 mContentTop = mVoiceContentTop = mCurTop = mDockTop;
3992 mContentBottom = mVoiceContentBottom = mCurBottom = mDockBottom;
3993 mContentLeft = mVoiceContentLeft = mCurLeft = mDockLeft;
3994 mContentRight = mVoiceContentRight = mCurRight = mDockRight;
3995
3996 if (DEBUG_LAYOUT) Slog.v(TAG, "Status bar: " +
3997 String.format(
3998 "dock=[%d,%d][%d,%d] content=[%d,%d][%d,%d] cur=[%d,%d][%d,%d]",
3999 mDockLeft, mDockTop, mDockRight, mDockBottom,
4000 mContentLeft, mContentTop, mContentRight, mContentBottom,
4001 mCurLeft, mCurTop, mCurRight, mCurBottom));
4002 }
4003 if (mStatusBar.isVisibleLw() && !mStatusBar.isAnimatingLw()
4004 && !statusBarTransient && !statusBarTranslucent
4005 && !mStatusBarController.wasRecentlyTranslucent()) {
4006 // If the opaque status bar is currently requested to be visible,
4007 // and not in the process of animating on or off, then
4008 // we can tell the app that it is covered by it.
4009 mSystemTop = mUnrestrictedScreenTop + mStatusBarHeight;
4010 }
4011 if (mStatusBarController.checkHiddenLw()) {
4012 return true;
4013 }
4014 }
4015 return false;
4016 }
4017
4018 private boolean layoutNavigationBar(int displayWidth, int displayHeight, int displayRotation,
Sriram Viswanathan9ebbe6a2015-11-16 17:59:22 -08004019 int uiMode, int overscanRight, int overscanBottom, Rect dcf, boolean navVisible,
Filip Gruszczynski83dd9552015-09-17 17:50:36 -07004020 boolean navTranslucent, boolean navAllowedHidden) {
4021 if (mNavigationBar != null) {
4022 boolean transientNavBarShowing = mNavigationBarController.isTransientShowing();
4023 // Force the navigation bar to its appropriate place and
4024 // size. We need to do this directly, instead of relying on
4025 // it to bubble up from the nav bar, because this needs to
4026 // change atomically with screen rotations.
Jorim Jaggi737af722015-12-31 10:42:27 +01004027 mNavigationBarOnBottom = isNavigationBarOnBottom(displayWidth, displayHeight);
Filip Gruszczynski83dd9552015-09-17 17:50:36 -07004028 if (mNavigationBarOnBottom) {
4029 // It's a system nav bar or a portrait screen; nav bar goes on bottom.
4030 int top = displayHeight - overscanBottom
Sriram Viswanathan9ebbe6a2015-11-16 17:59:22 -08004031 - getNavigationBarHeight(displayRotation, uiMode);
Filip Gruszczynski83dd9552015-09-17 17:50:36 -07004032 mTmpNavigationFrame.set(0, top, displayWidth, displayHeight - overscanBottom);
4033 mStableBottom = mStableFullscreenBottom = mTmpNavigationFrame.top;
4034 if (transientNavBarShowing) {
4035 mNavigationBarController.setBarShowingLw(true);
4036 } else if (navVisible) {
4037 mNavigationBarController.setBarShowingLw(true);
4038 mDockBottom = mTmpNavigationFrame.top;
4039 mRestrictedScreenHeight = mDockBottom - mRestrictedScreenTop;
4040 mRestrictedOverscanScreenHeight = mDockBottom - mRestrictedOverscanScreenTop;
4041 } else {
4042 // We currently want to hide the navigation UI.
4043 mNavigationBarController.setBarShowingLw(false);
4044 }
4045 if (navVisible && !navTranslucent && !navAllowedHidden
4046 && !mNavigationBar.isAnimatingLw()
4047 && !mNavigationBarController.wasRecentlyTranslucent()) {
4048 // If the opaque nav bar is currently requested to be visible,
4049 // and not in the process of animating on or off, then
4050 // we can tell the app that it is covered by it.
4051 mSystemBottom = mTmpNavigationFrame.top;
4052 }
4053 } else {
4054 // Landscape screen; nav bar goes to the right.
4055 int left = displayWidth - overscanRight
Sriram Viswanathan9ebbe6a2015-11-16 17:59:22 -08004056 - getNavigationBarWidth(displayRotation, uiMode);
Filip Gruszczynski83dd9552015-09-17 17:50:36 -07004057 mTmpNavigationFrame.set(left, 0, displayWidth - overscanRight, displayHeight);
4058 mStableRight = mStableFullscreenRight = mTmpNavigationFrame.left;
4059 if (transientNavBarShowing) {
4060 mNavigationBarController.setBarShowingLw(true);
4061 } else if (navVisible) {
4062 mNavigationBarController.setBarShowingLw(true);
4063 mDockRight = mTmpNavigationFrame.left;
4064 mRestrictedScreenWidth = mDockRight - mRestrictedScreenLeft;
4065 mRestrictedOverscanScreenWidth = mDockRight - mRestrictedOverscanScreenLeft;
4066 } else {
4067 // We currently want to hide the navigation UI.
4068 mNavigationBarController.setBarShowingLw(false);
4069 }
4070 if (navVisible && !navTranslucent && !navAllowedHidden
4071 && !mNavigationBar.isAnimatingLw()
4072 && !mNavigationBarController.wasRecentlyTranslucent()) {
4073 // If the nav bar is currently requested to be visible,
4074 // and not in the process of animating on or off, then
4075 // we can tell the app that it is covered by it.
4076 mSystemRight = mTmpNavigationFrame.left;
4077 }
4078 }
4079 // Make sure the content and current rectangles are updated to
4080 // account for the restrictions from the navigation bar.
4081 mContentTop = mVoiceContentTop = mCurTop = mDockTop;
4082 mContentBottom = mVoiceContentBottom = mCurBottom = mDockBottom;
4083 mContentLeft = mVoiceContentLeft = mCurLeft = mDockLeft;
4084 mContentRight = mVoiceContentRight = mCurRight = mDockRight;
4085 mStatusBarLayer = mNavigationBar.getSurfaceLayer();
4086 // And compute the final frame.
4087 mNavigationBar.computeFrameLw(mTmpNavigationFrame, mTmpNavigationFrame,
4088 mTmpNavigationFrame, mTmpNavigationFrame, mTmpNavigationFrame, dcf,
4089 mTmpNavigationFrame, mTmpNavigationFrame);
4090 if (DEBUG_LAYOUT) Slog.i(TAG, "mNavigationBar frame: " + mTmpNavigationFrame);
4091 if (mNavigationBarController.checkHiddenLw()) {
4092 return true;
4093 }
4094 }
4095 return false;
4096 }
4097
Jorim Jaggi737af722015-12-31 10:42:27 +01004098 private boolean isNavigationBarOnBottom(int displayWidth, int displayHeight) {
4099 return !mNavigationBarCanMove || displayWidth < displayHeight;
4100 }
4101
Dianne Hackborn85afd1b2012-05-13 13:31:06 -07004102 /** {@inheritDoc} */
Craig Mautner967212c2013-04-13 21:10:58 -07004103 @Override
John Spurlock46646232013-09-30 22:32:42 -04004104 public int getSystemDecorLayerLw() {
Bryce Lee2ed3e5f2015-04-01 22:09:19 +00004105 if (mStatusBar != null && mStatusBar.isVisibleLw()) {
4106 return mStatusBar.getSurfaceLayer();
4107 }
4108
4109 if (mNavigationBar != null && mNavigationBar.isVisibleLw()) {
4110 return mNavigationBar.getSurfaceLayer();
4111 }
4112
Dianne Hackborn85afd1b2012-05-13 13:31:06 -07004113 return 0;
4114 }
4115
Craig Mautner967212c2013-04-13 21:10:58 -07004116 @Override
4117 public void getContentRectLw(Rect r) {
4118 r.set(mContentLeft, mContentTop, mContentRight, mContentBottom);
4119 }
4120
Dianne Hackbornc4aad012013-02-22 15:05:25 -08004121 void setAttachedWindowFrames(WindowState win, int fl, int adjust, WindowState attached,
4122 boolean insetDecors, Rect pf, Rect df, Rect of, Rect cf, Rect vf) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004123 if (win.getSurfaceLayer() > mDockLayer && attached.getSurfaceLayer() < mDockLayer) {
4124 // Here's a special case: if this attached window is a panel that is
4125 // above the dock window, and the window it is attached to is below
4126 // the dock window, then the frames we computed for the window it is
4127 // attached to can not be used because the dock is effectively part
4128 // of the underlying window and the attached window is floating on top
4129 // of the whole thing. So, we ignore the attached window and explicitly
4130 // compute the frames that would be appropriate without the dock.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08004131 df.left = of.left = cf.left = vf.left = mDockLeft;
4132 df.top = of.top = cf.top = vf.top = mDockTop;
4133 df.right = of.right = cf.right = vf.right = mDockRight;
4134 df.bottom = of.bottom = cf.bottom = vf.bottom = mDockBottom;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004135 } else {
4136 // The effective display frame of the attached window depends on
4137 // whether it is taking care of insetting its content. If not,
4138 // we need to use the parent's content frame so that the entire
4139 // window is positioned within that content. Otherwise we can use
Wale Ogunwale393b1c12014-10-18 16:22:01 -07004140 // the overscan frame and let the attached window take care of
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004141 // positioning its content appropriately.
Dianne Hackborndea3ef72010-10-28 14:24:22 -07004142 if (adjust != SOFT_INPUT_ADJUST_RESIZE) {
Wale Ogunwale393b1c12014-10-18 16:22:01 -07004143 // Set the content frame of the attached window to the parent's decor frame
4144 // (same as content frame when IME isn't present) if specifically requested by
4145 // setting {@link WindowManager.LayoutParams#FLAG_LAYOUT_ATTACHED_IN_DECOR} flag.
4146 // Otherwise, use the overscan frame.
4147 cf.set((fl & FLAG_LAYOUT_ATTACHED_IN_DECOR) != 0
4148 ? attached.getContentFrameLw() : attached.getOverscanFrameLw());
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004149 } else {
4150 // If the window is resizing, then we want to base the content
4151 // frame on our attached content frame to resize... however,
4152 // things can be tricky if the attached window is NOT in resize
4153 // mode, in which case its content frame will be larger.
4154 // Ungh. So to deal with that, make sure the content frame
4155 // we end up using is not covering the IM dock.
4156 cf.set(attached.getContentFrameLw());
Dianne Hackborne30e02f2014-05-27 18:24:45 -07004157 if (attached.isVoiceInteraction()) {
4158 if (cf.left < mVoiceContentLeft) cf.left = mVoiceContentLeft;
4159 if (cf.top < mVoiceContentTop) cf.top = mVoiceContentTop;
4160 if (cf.right > mVoiceContentRight) cf.right = mVoiceContentRight;
4161 if (cf.bottom > mVoiceContentBottom) cf.bottom = mVoiceContentBottom;
4162 } else if (attached.getSurfaceLayer() < mDockLayer) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004163 if (cf.left < mContentLeft) cf.left = mContentLeft;
4164 if (cf.top < mContentTop) cf.top = mContentTop;
4165 if (cf.right > mContentRight) cf.right = mContentRight;
4166 if (cf.bottom > mContentBottom) cf.bottom = mContentBottom;
4167 }
4168 }
4169 df.set(insetDecors ? attached.getDisplayFrameLw() : cf);
Dianne Hackbornc4aad012013-02-22 15:05:25 -08004170 of.set(insetDecors ? attached.getOverscanFrameLw() : cf);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004171 vf.set(attached.getVisibleFrameLw());
4172 }
4173 // The LAYOUT_IN_SCREEN flag is used to determine whether the attached
4174 // window should be positioned relative to its parent or the entire
4175 // screen.
4176 pf.set((fl & FLAG_LAYOUT_IN_SCREEN) == 0
4177 ? attached.getFrameLw() : df);
4178 }
Dianne Hackborn5b5cc4d2012-05-16 13:15:00 -07004179
4180 private void applyStableConstraints(int sysui, int fl, Rect r) {
4181 if ((sysui & View.SYSTEM_UI_FLAG_LAYOUT_STABLE) != 0) {
4182 // If app is requesting a stable layout, don't let the
4183 // content insets go below the stable values.
4184 if ((fl & FLAG_FULLSCREEN) != 0) {
4185 if (r.left < mStableFullscreenLeft) r.left = mStableFullscreenLeft;
4186 if (r.top < mStableFullscreenTop) r.top = mStableFullscreenTop;
4187 if (r.right > mStableFullscreenRight) r.right = mStableFullscreenRight;
4188 if (r.bottom > mStableFullscreenBottom) r.bottom = mStableFullscreenBottom;
4189 } else {
4190 if (r.left < mStableLeft) r.left = mStableLeft;
4191 if (r.top < mStableTop) r.top = mStableTop;
4192 if (r.right > mStableRight) r.right = mStableRight;
4193 if (r.bottom > mStableBottom) r.bottom = mStableBottom;
4194 }
4195 }
4196 }
4197
Jorim Jaggiaa806142015-05-20 18:04:16 -07004198 private boolean canReceiveInput(WindowState win) {
4199 boolean notFocusable =
4200 (win.getAttrs().flags & WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE) != 0;
4201 boolean altFocusableIm =
4202 (win.getAttrs().flags & WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM) != 0;
4203 boolean notFocusableForIm = notFocusable ^ altFocusableIm;
4204 return !notFocusableForIm;
4205 }
4206
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004207 /** {@inheritDoc} */
Craig Mautner69b08182012-09-05 13:07:13 -07004208 @Override
Craig Mautnerc9457fa2014-06-06 14:27:48 -07004209 public void layoutWindowLw(WindowState win, WindowState attached) {
Jorim Jaggiaa806142015-05-20 18:04:16 -07004210 // We've already done the navigation bar and status bar. If the status bar can receive
4211 // input, we need to layout it again to accomodate for the IME window.
4212 if ((win == mStatusBar && !canReceiveInput(win)) || win == mNavigationBar) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004213 return;
4214 }
Jorim Jaggiaa806142015-05-20 18:04:16 -07004215 final WindowManager.LayoutParams attrs = win.getAttrs();
Craig Mautner69b08182012-09-05 13:07:13 -07004216 final boolean isDefaultDisplay = win.isDefaultDisplay();
4217 final boolean needsToOffsetInputMethodTarget = isDefaultDisplay &&
satok1bc0a492012-04-25 22:47:12 +09004218 (win == mLastInputMethodTargetWindow && mLastInputMethodWindow != null);
4219 if (needsToOffsetInputMethodTarget) {
Craig Mautnereda67292013-04-28 13:50:14 -07004220 if (DEBUG_LAYOUT) Slog.i(TAG, "Offset ime target window by the last ime window state");
satok1bc0a492012-04-25 22:47:12 +09004221 offsetInputMethodWindowLw(mLastInputMethodWindow);
4222 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004223
John Spurlockc6d1c602014-01-17 15:22:06 -05004224 final int fl = PolicyControl.getWindowFlags(win, attrs);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004225 final int sim = attrs.softInputMode;
John Spurlock1db8b682014-02-18 11:18:59 -05004226 final int sysUiFl = PolicyControl.getSystemUiVisibility(win, null);
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07004227
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004228 final Rect pf = mTmpParentFrame;
4229 final Rect df = mTmpDisplayFrame;
Dianne Hackbornc4aad012013-02-22 15:05:25 -08004230 final Rect of = mTmpOverscanFrame;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004231 final Rect cf = mTmpContentFrame;
4232 final Rect vf = mTmpVisibleFrame;
John Spurlock46646232013-09-30 22:32:42 -04004233 final Rect dcf = mTmpDecorFrame;
Adrian Roosfa104232014-06-20 16:10:14 -07004234 final Rect sf = mTmpStableFrame;
Filip Gruszczynski2217f612015-05-26 11:32:08 -07004235 Rect osf = null;
John Spurlock46646232013-09-30 22:32:42 -04004236 dcf.setEmpty();
Craig Mautner69b08182012-09-05 13:07:13 -07004237
4238 final boolean hasNavBar = (isDefaultDisplay && mHasNavigationBar
Daniel Sandler36412a72011-08-04 09:35:13 -04004239 && mNavigationBar != null && mNavigationBar.isVisibleLw());
Daniel Sandler8956dbb2011-04-22 07:55:02 -04004240
Craig Mautnerf683b562012-10-02 11:10:57 -07004241 final int adjust = sim & SOFT_INPUT_MASK_ADJUST;
4242
Adrian Roosfa104232014-06-20 16:10:14 -07004243 if (isDefaultDisplay) {
4244 sf.set(mStableLeft, mStableTop, mStableRight, mStableBottom);
4245 } else {
4246 sf.set(mOverscanLeft, mOverscanTop, mOverscanRight, mOverscanBottom);
4247 }
4248
Craig Mautner69b08182012-09-05 13:07:13 -07004249 if (!isDefaultDisplay) {
4250 if (attached != null) {
4251 // If this window is attached to another, our display
4252 // frame is the same as the one we are attached to.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08004253 setAttachedWindowFrames(win, fl, adjust, attached, true, pf, df, of, cf, vf);
Craig Mautner69b08182012-09-05 13:07:13 -07004254 } else {
4255 // Give the window full screen.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08004256 pf.left = df.left = of.left = cf.left = mOverscanScreenLeft;
4257 pf.top = df.top = of.top = cf.top = mOverscanScreenTop;
4258 pf.right = df.right = of.right = cf.right
Dianne Hackbornc652de82013-02-15 16:32:56 -08004259 = mOverscanScreenLeft + mOverscanScreenWidth;
Dianne Hackbornc4aad012013-02-22 15:05:25 -08004260 pf.bottom = df.bottom = of.bottom = cf.bottom
Dianne Hackbornc652de82013-02-15 16:32:56 -08004261 = mOverscanScreenTop + mOverscanScreenHeight;
Craig Mautner69b08182012-09-05 13:07:13 -07004262 }
Jorim Jaggi225d3b52015-04-01 11:18:57 -07004263 } else if (attrs.type == TYPE_INPUT_METHOD) {
Dianne Hackbornc4aad012013-02-22 15:05:25 -08004264 pf.left = df.left = of.left = cf.left = vf.left = mDockLeft;
4265 pf.top = df.top = of.top = cf.top = vf.top = mDockTop;
4266 pf.right = df.right = of.right = cf.right = vf.right = mDockRight;
John Spurlockc68d5772013-10-08 11:47:58 -04004267 // IM dock windows layout below the nav bar...
John Spurlock57beb3b2013-10-10 10:27:44 -04004268 pf.bottom = df.bottom = of.bottom = mUnrestrictedScreenTop + mUnrestrictedScreenHeight;
John Spurlockc68d5772013-10-08 11:47:58 -04004269 // ...with content insets above the nav bar
4270 cf.bottom = vf.bottom = mStableBottom;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004271 // IM dock windows always go to the bottom of the screen.
4272 attrs.gravity = Gravity.BOTTOM;
4273 mDockLayer = win.getSurfaceLayer();
Jorim Jaggi225d3b52015-04-01 11:18:57 -07004274 } else if (attrs.type == TYPE_VOICE_INTERACTION) {
Stefan Kuhne2f280d062015-06-18 07:20:33 -10004275 pf.left = df.left = of.left = mUnrestrictedScreenLeft;
Jorim Jaggi225d3b52015-04-01 11:18:57 -07004276 pf.top = df.top = of.top = mUnrestrictedScreenTop;
Stefan Kuhne2f280d062015-06-18 07:20:33 -10004277 pf.right = df.right = of.right = mUnrestrictedScreenLeft + mUnrestrictedScreenWidth;
4278 pf.bottom = df.bottom = of.bottom = mUnrestrictedScreenTop + mUnrestrictedScreenHeight;
Jorim Jaggi225d3b52015-04-01 11:18:57 -07004279 cf.bottom = vf.bottom = mStableBottom;
Stefan Kuhne2f280d062015-06-18 07:20:33 -10004280 // Note: In Phone landscape mode, the button bar should also be excluded.
4281 cf.right = vf.right = mStableRight;
4282 cf.left = vf.left = mStableLeft;
Jorim Jaggi225d3b52015-04-01 11:18:57 -07004283 cf.top = vf.top = mStableTop;
Jorim Jaggiaa806142015-05-20 18:04:16 -07004284 } else if (win == mStatusBar) {
Jorim Jaggie0700182014-08-21 01:12:37 +02004285 pf.left = df.left = of.left = mUnrestrictedScreenLeft;
4286 pf.top = df.top = of.top = mUnrestrictedScreenTop;
4287 pf.right = df.right = of.right = mUnrestrictedScreenWidth + mUnrestrictedScreenLeft;
4288 pf.bottom = df.bottom = of.bottom = mUnrestrictedScreenHeight + mUnrestrictedScreenTop;
4289 cf.left = vf.left = mStableLeft;
4290 cf.top = vf.top = mStableTop;
4291 cf.right = vf.right = mStableRight;
4292 vf.bottom = mStableBottom;
Adrian Roosdc5b4532016-01-06 20:49:41 +01004293
4294 if (adjust == SOFT_INPUT_ADJUST_RESIZE) {
4295 cf.bottom = mContentBottom;
4296 } else {
4297 cf.bottom = mDockBottom;
4298 vf.bottom = mContentBottom;
4299 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004300 } else {
John Spurlock46646232013-09-30 22:32:42 -04004301
4302 // Default policy decor for the default display
4303 dcf.left = mSystemLeft;
4304 dcf.top = mSystemTop;
4305 dcf.right = mSystemRight;
4306 dcf.bottom = mSystemBottom;
John Spurlockbd957402013-10-03 11:38:39 -04004307 final boolean inheritTranslucentDecor = (attrs.privateFlags
4308 & WindowManager.LayoutParams.PRIVATE_FLAG_INHERIT_TRANSLUCENT_DECOR) != 0;
John Spurlock65567d42013-10-08 10:08:32 -04004309 final boolean isAppWindow =
4310 attrs.type >= WindowManager.LayoutParams.FIRST_APPLICATION_WINDOW &&
4311 attrs.type <= WindowManager.LayoutParams.LAST_APPLICATION_WINDOW;
4312 final boolean topAtRest =
4313 win == mTopFullscreenOpaqueWindowState && !win.isAnimatingLw();
4314 if (isAppWindow && !inheritTranslucentDecor && !topAtRest) {
John Spurlockbd957402013-10-03 11:38:39 -04004315 if ((sysUiFl & View.SYSTEM_UI_FLAG_FULLSCREEN) == 0
4316 && (fl & WindowManager.LayoutParams.FLAG_FULLSCREEN) == 0
Adrian Roosea562512014-05-05 13:33:03 +02004317 && (fl & WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS) == 0
4318 && (fl & WindowManager.LayoutParams.
Jorim Jaggi4fa78922015-11-30 17:13:56 -08004319 FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS) == 0
4320 && !mForceWindowDrawsStatusBarBackground) {
John Spurlock46646232013-09-30 22:32:42 -04004321 // Ensure policy decor includes status bar
4322 dcf.top = mStableTop;
4323 }
John Spurlockbd957402013-10-03 11:38:39 -04004324 if ((fl & WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION) == 0
Adrian Roosea562512014-05-05 13:33:03 +02004325 && (sysUiFl & View.SYSTEM_UI_FLAG_HIDE_NAVIGATION) == 0
4326 && (fl & WindowManager.LayoutParams.
4327 FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS) == 0) {
John Spurlock46646232013-09-30 22:32:42 -04004328 // Ensure policy decor includes navigation bar
4329 dcf.bottom = mStableBottom;
4330 dcf.right = mStableRight;
4331 }
4332 }
4333
Dianne Hackbornc4aad012013-02-22 15:05:25 -08004334 if ((fl & (FLAG_LAYOUT_IN_SCREEN | FLAG_LAYOUT_INSET_DECOR))
4335 == (FLAG_LAYOUT_IN_SCREEN | FLAG_LAYOUT_INSET_DECOR)) {
RoboErik8a2cfc32014-05-16 11:19:38 -07004336 if (DEBUG_LAYOUT) Slog.v(TAG, "layoutWindowLw(" + attrs.getTitle()
Dianne Hackbornc4aad012013-02-22 15:05:25 -08004337 + "): IN_SCREEN, INSET_DECOR");
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004338 // This is the case for a normal activity window: we want it
4339 // to cover all of the screen space, and it can take care of
4340 // moving its contents to account for screen decorations that
4341 // intrude into that space.
4342 if (attached != null) {
4343 // If this window is attached to another, our display
4344 // frame is the same as the one we are attached to.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08004345 setAttachedWindowFrames(win, fl, adjust, attached, true, pf, df, of, cf, vf);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004346 } else {
Daniel Sandler8956dbb2011-04-22 07:55:02 -04004347 if (attrs.type == TYPE_STATUS_BAR_PANEL
4348 || attrs.type == TYPE_STATUS_BAR_SUB_PANEL) {
Joe Onorato29fc2c92010-11-24 10:26:50 -08004349 // Status bar panels are the only windows who can go on top of
4350 // the status bar. They are protected by the STATUS_BAR_SERVICE
4351 // permission, so they have the same privileges as the status
4352 // bar itself.
Daniel Sandler8956dbb2011-04-22 07:55:02 -04004353 //
Daniel Sandler8e8b4152011-07-21 01:16:43 -04004354 // However, they should still dodge the navigation bar if it exists.
Daniel Sandler8956dbb2011-04-22 07:55:02 -04004355
Dianne Hackbornc4aad012013-02-22 15:05:25 -08004356 pf.left = df.left = of.left = hasNavBar
4357 ? mDockLeft : mUnrestrictedScreenLeft;
4358 pf.top = df.top = of.top = mUnrestrictedScreenTop;
4359 pf.right = df.right = of.right = hasNavBar
4360 ? mRestrictedScreenLeft+mRestrictedScreenWidth
4361 : mUnrestrictedScreenLeft + mUnrestrictedScreenWidth;
4362 pf.bottom = df.bottom = of.bottom = hasNavBar
4363 ? mRestrictedScreenTop+mRestrictedScreenHeight
4364 : mUnrestrictedScreenTop + mUnrestrictedScreenHeight;
Daniel Sandler8956dbb2011-04-22 07:55:02 -04004365
Craig Mautnereda67292013-04-28 13:50:14 -07004366 if (DEBUG_LAYOUT) Slog.v(TAG, String.format(
Daniel Sandler8e8b4152011-07-21 01:16:43 -04004367 "Laying out status bar window: (%d,%d - %d,%d)",
4368 pf.left, pf.top, pf.right, pf.bottom));
John Spurlock46646232013-09-30 22:32:42 -04004369 } else if ((fl & FLAG_LAYOUT_IN_OVERSCAN) != 0
Dianne Hackbornc652de82013-02-15 16:32:56 -08004370 && attrs.type >= WindowManager.LayoutParams.FIRST_APPLICATION_WINDOW
4371 && attrs.type <= WindowManager.LayoutParams.LAST_SUB_WINDOW) {
4372 // Asking to layout into the overscan region, so give it that pure
4373 // unrestricted area.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08004374 pf.left = df.left = of.left = mOverscanScreenLeft;
4375 pf.top = df.top = of.top = mOverscanScreenTop;
4376 pf.right = df.right = of.right = mOverscanScreenLeft + mOverscanScreenWidth;
4377 pf.bottom = df.bottom = of.bottom = mOverscanScreenTop
4378 + mOverscanScreenHeight;
Alan Viverette5a0f4ec2013-10-07 15:10:29 -07004379 } else if (canHideNavigationBar()
Dianne Hackbornf87d1962012-04-04 12:48:24 -07004380 && (sysUiFl & View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION) != 0
Jorim Jaggi380ecb82014-03-14 17:25:20 +01004381 && attrs.type >= WindowManager.LayoutParams.FIRST_APPLICATION_WINDOW
4382 && attrs.type <= WindowManager.LayoutParams.LAST_SUB_WINDOW) {
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07004383 // Asking for layout as if the nav bar is hidden, lets the
Dianne Hackbornc652de82013-02-15 16:32:56 -08004384 // application extend into the unrestricted overscan screen area. We
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07004385 // only do this for application windows to ensure no window that
4386 // can be above the nav bar can do this.
Dianne Hackborn313440842013-02-19 19:22:59 -08004387 pf.left = df.left = mOverscanScreenLeft;
4388 pf.top = df.top = mOverscanScreenTop;
4389 pf.right = df.right = mOverscanScreenLeft + mOverscanScreenWidth;
4390 pf.bottom = df.bottom = mOverscanScreenTop + mOverscanScreenHeight;
Dianne Hackbornc4aad012013-02-22 15:05:25 -08004391 // We need to tell the app about where the frame inside the overscan
4392 // is, so it can inset its content by that amount -- it didn't ask
4393 // to actually extend itself into the overscan region.
4394 of.left = mUnrestrictedScreenLeft;
4395 of.top = mUnrestrictedScreenTop;
4396 of.right = mUnrestrictedScreenLeft + mUnrestrictedScreenWidth;
4397 of.bottom = mUnrestrictedScreenTop + mUnrestrictedScreenHeight;
Joe Onorato29fc2c92010-11-24 10:26:50 -08004398 } else {
Dianne Hackborn313440842013-02-19 19:22:59 -08004399 pf.left = df.left = mRestrictedOverscanScreenLeft;
4400 pf.top = df.top = mRestrictedOverscanScreenTop;
4401 pf.right = df.right = mRestrictedOverscanScreenLeft
4402 + mRestrictedOverscanScreenWidth;
4403 pf.bottom = df.bottom = mRestrictedOverscanScreenTop
4404 + mRestrictedOverscanScreenHeight;
Dianne Hackbornc4aad012013-02-22 15:05:25 -08004405 // We need to tell the app about where the frame inside the overscan
4406 // is, so it can inset its content by that amount -- it didn't ask
4407 // to actually extend itself into the overscan region.
4408 of.left = mUnrestrictedScreenLeft;
4409 of.top = mUnrestrictedScreenTop;
4410 of.right = mUnrestrictedScreenLeft + mUnrestrictedScreenWidth;
4411 of.bottom = mUnrestrictedScreenTop + mUnrestrictedScreenHeight;
Joe Onorato29fc2c92010-11-24 10:26:50 -08004412 }
Craig Mautner69b08182012-09-05 13:07:13 -07004413
John Spurlock46646232013-09-30 22:32:42 -04004414 if ((fl & FLAG_FULLSCREEN) == 0) {
Dianne Hackborne30e02f2014-05-27 18:24:45 -07004415 if (win.isVoiceInteraction()) {
4416 cf.left = mVoiceContentLeft;
4417 cf.top = mVoiceContentTop;
4418 cf.right = mVoiceContentRight;
4419 cf.bottom = mVoiceContentBottom;
Dianne Hackbornc4aad012013-02-22 15:05:25 -08004420 } else {
Dianne Hackborne30e02f2014-05-27 18:24:45 -07004421 if (adjust != SOFT_INPUT_ADJUST_RESIZE) {
4422 cf.left = mDockLeft;
4423 cf.top = mDockTop;
4424 cf.right = mDockRight;
4425 cf.bottom = mDockBottom;
4426 } else {
4427 cf.left = mContentLeft;
4428 cf.top = mContentTop;
4429 cf.right = mContentRight;
4430 cf.bottom = mContentBottom;
4431 }
Dianne Hackbornc4aad012013-02-22 15:05:25 -08004432 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004433 } else {
Dianne Hackbornc4aad012013-02-22 15:05:25 -08004434 // Full screen windows are always given a layout that is as if the
4435 // status bar and other transient decors are gone. This is to avoid
4436 // bad states when moving from a window that is not hding the
4437 // status bar to one that is.
4438 cf.left = mRestrictedScreenLeft;
4439 cf.top = mRestrictedScreenTop;
4440 cf.right = mRestrictedScreenLeft + mRestrictedScreenWidth;
4441 cf.bottom = mRestrictedScreenTop + mRestrictedScreenHeight;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004442 }
Dianne Hackborn5b5cc4d2012-05-16 13:15:00 -07004443 applyStableConstraints(sysUiFl, fl, cf);
Dianne Hackborndea3ef72010-10-28 14:24:22 -07004444 if (adjust != SOFT_INPUT_ADJUST_NOTHING) {
4445 vf.left = mCurLeft;
4446 vf.top = mCurTop;
4447 vf.right = mCurRight;
4448 vf.bottom = mCurBottom;
4449 } else {
4450 vf.set(cf);
4451 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004452 }
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07004453 } else if ((fl & FLAG_LAYOUT_IN_SCREEN) != 0 || (sysUiFl
4454 & (View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
4455 | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION)) != 0) {
Craig Mautnereda67292013-04-28 13:50:14 -07004456 if (DEBUG_LAYOUT) Slog.v(TAG, "layoutWindowLw(" + attrs.getTitle() +
4457 "): IN_SCREEN");
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004458 // A window that has requested to fill the entire screen just
4459 // gets everything, period.
Daniel Sandler8956dbb2011-04-22 07:55:02 -04004460 if (attrs.type == TYPE_STATUS_BAR_PANEL
John Spurlock67a0f852015-06-15 15:35:47 -04004461 || attrs.type == TYPE_STATUS_BAR_SUB_PANEL
4462 || attrs.type == TYPE_VOLUME_OVERLAY) {
Dianne Hackbornc4aad012013-02-22 15:05:25 -08004463 pf.left = df.left = of.left = cf.left = hasNavBar
4464 ? mDockLeft : mUnrestrictedScreenLeft;
4465 pf.top = df.top = of.top = cf.top = mUnrestrictedScreenTop;
4466 pf.right = df.right = of.right = cf.right = hasNavBar
Daniel Sandler8e8b4152011-07-21 01:16:43 -04004467 ? mRestrictedScreenLeft+mRestrictedScreenWidth
Dianne Hackbornc652de82013-02-15 16:32:56 -08004468 : mUnrestrictedScreenLeft + mUnrestrictedScreenWidth;
Dianne Hackbornc4aad012013-02-22 15:05:25 -08004469 pf.bottom = df.bottom = of.bottom = cf.bottom = hasNavBar
Daniel Sandler8e8b4152011-07-21 01:16:43 -04004470 ? mRestrictedScreenTop+mRestrictedScreenHeight
Dianne Hackbornc652de82013-02-15 16:32:56 -08004471 : mUnrestrictedScreenTop + mUnrestrictedScreenHeight;
Craig Mautnereda67292013-04-28 13:50:14 -07004472 if (DEBUG_LAYOUT) Slog.v(TAG, String.format(
Daniel Sandler36412a72011-08-04 09:35:13 -04004473 "Laying out IN_SCREEN status bar window: (%d,%d - %d,%d)",
4474 pf.left, pf.top, pf.right, pf.bottom));
Jim Millere898ac52012-04-06 17:10:57 -07004475 } else if (attrs.type == TYPE_NAVIGATION_BAR
4476 || attrs.type == TYPE_NAVIGATION_BAR_PANEL) {
Daniel Sandler8e8b4152011-07-21 01:16:43 -04004477 // The navigation bar has Real Ultimate Power.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08004478 pf.left = df.left = of.left = mUnrestrictedScreenLeft;
4479 pf.top = df.top = of.top = mUnrestrictedScreenTop;
4480 pf.right = df.right = of.right = mUnrestrictedScreenLeft
4481 + mUnrestrictedScreenWidth;
4482 pf.bottom = df.bottom = of.bottom = mUnrestrictedScreenTop
4483 + mUnrestrictedScreenHeight;
Craig Mautnereda67292013-04-28 13:50:14 -07004484 if (DEBUG_LAYOUT) Slog.v(TAG, String.format(
Daniel Sandler8e8b4152011-07-21 01:16:43 -04004485 "Laying out navigation bar window: (%d,%d - %d,%d)",
4486 pf.left, pf.top, pf.right, pf.bottom));
Dianne Hackborn01011c32012-02-21 13:54:21 -08004487 } else if ((attrs.type == TYPE_SECURE_SYSTEM_OVERLAY
Muyuan Li6ca619f2016-03-08 13:30:42 -08004488 || attrs.type == TYPE_BOOT_PROGRESS
4489 || attrs.type == TYPE_SCREENSHOT)
Jeff Brownbfcb60a2011-09-08 18:51:14 -07004490 && ((fl & FLAG_FULLSCREEN) != 0)) {
Muyuan Li6ca619f2016-03-08 13:30:42 -08004491 // Fullscreen secure system overlays get what they ask for. Screenshot region
4492 // selection overlay should also expand to full screen.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08004493 pf.left = df.left = of.left = cf.left = mOverscanScreenLeft;
4494 pf.top = df.top = of.top = cf.top = mOverscanScreenTop;
4495 pf.right = df.right = of.right = cf.right = mOverscanScreenLeft
4496 + mOverscanScreenWidth;
4497 pf.bottom = df.bottom = of.bottom = cf.bottom = mOverscanScreenTop
4498 + mOverscanScreenHeight;
Craig Mautner165be0c2015-01-27 15:16:58 -08004499 } else if (attrs.type == TYPE_BOOT_PROGRESS) {
Dianne Hackborn01011c32012-02-21 13:54:21 -08004500 // Boot progress screen always covers entire display.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08004501 pf.left = df.left = of.left = cf.left = mOverscanScreenLeft;
4502 pf.top = df.top = of.top = cf.top = mOverscanScreenTop;
4503 pf.right = df.right = of.right = cf.right = mOverscanScreenLeft
4504 + mOverscanScreenWidth;
4505 pf.bottom = df.bottom = of.bottom = cf.bottom = mOverscanScreenTop
4506 + mOverscanScreenHeight;
John Spurlockef4adae2013-08-26 17:58:58 -04004507 } else if (attrs.type == TYPE_WALLPAPER) {
Dianne Hackborn067e5f62014-09-07 23:14:30 -07004508 // The wallpaper also has Real Ultimate Power, but we want to tell
4509 // it about the overscan area.
4510 pf.left = df.left = mOverscanScreenLeft;
4511 pf.top = df.top = mOverscanScreenTop;
4512 pf.right = df.right = mOverscanScreenLeft + mOverscanScreenWidth;
4513 pf.bottom = df.bottom = mOverscanScreenTop + mOverscanScreenHeight;
4514 of.left = cf.left = mUnrestrictedScreenLeft;
4515 of.top = cf.top = mUnrestrictedScreenTop;
4516 of.right = cf.right = mUnrestrictedScreenLeft + mUnrestrictedScreenWidth;
4517 of.bottom = cf.bottom = mUnrestrictedScreenTop + mUnrestrictedScreenHeight;
John Spurlock46646232013-09-30 22:32:42 -04004518 } else if ((fl & FLAG_LAYOUT_IN_OVERSCAN) != 0
Dianne Hackbornc652de82013-02-15 16:32:56 -08004519 && attrs.type >= WindowManager.LayoutParams.FIRST_APPLICATION_WINDOW
4520 && attrs.type <= WindowManager.LayoutParams.LAST_SUB_WINDOW) {
4521 // Asking to layout into the overscan region, so give it that pure
4522 // unrestricted area.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08004523 pf.left = df.left = of.left = cf.left = mOverscanScreenLeft;
4524 pf.top = df.top = of.top = cf.top = mOverscanScreenTop;
4525 pf.right = df.right = of.right = cf.right
Dianne Hackbornc652de82013-02-15 16:32:56 -08004526 = mOverscanScreenLeft + mOverscanScreenWidth;
Dianne Hackbornc4aad012013-02-22 15:05:25 -08004527 pf.bottom = df.bottom = of.bottom = cf.bottom
Dianne Hackbornc652de82013-02-15 16:32:56 -08004528 = mOverscanScreenTop + mOverscanScreenHeight;
Alan Viverette5a0f4ec2013-10-07 15:10:29 -07004529 } else if (canHideNavigationBar()
Dianne Hackbornf87d1962012-04-04 12:48:24 -07004530 && (sysUiFl & View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION) != 0
Craig Mautnerbeac1062014-06-03 14:38:57 -07004531 && (attrs.type == TYPE_STATUS_BAR
4532 || attrs.type == TYPE_TOAST
Jorim Jaggi81fe2d12015-12-21 14:45:18 +01004533 || attrs.type == TYPE_DOCK_DIVIDER
Jorim Jaggi2fdeeab2015-04-01 15:13:03 -07004534 || attrs.type == TYPE_VOICE_INTERACTION_STARTING
John Spurlock34e13d92013-08-10 06:52:28 -04004535 || (attrs.type >= WindowManager.LayoutParams.FIRST_APPLICATION_WINDOW
4536 && attrs.type <= WindowManager.LayoutParams.LAST_SUB_WINDOW))) {
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07004537 // Asking for layout as if the nav bar is hidden, lets the
4538 // application extend into the unrestricted screen area. We
John Spurlock34e13d92013-08-10 06:52:28 -04004539 // only do this for application windows (or toasts) to ensure no window that
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07004540 // can be above the nav bar can do this.
4541 // XXX This assumes that an app asking for this will also
4542 // ask for layout in only content. We can't currently figure out
4543 // what the screen would be if only laying out to hide the nav bar.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08004544 pf.left = df.left = of.left = cf.left = mUnrestrictedScreenLeft;
4545 pf.top = df.top = of.top = cf.top = mUnrestrictedScreenTop;
4546 pf.right = df.right = of.right = cf.right = mUnrestrictedScreenLeft
4547 + mUnrestrictedScreenWidth;
4548 pf.bottom = df.bottom = of.bottom = cf.bottom = mUnrestrictedScreenTop
4549 + mUnrestrictedScreenHeight;
Jorim Jaggi9f6798a2016-02-10 22:16:06 -08004550 } else if ((sysUiFl & View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN) != 0) {
4551 pf.left = df.left = of.left = mRestrictedScreenLeft;
4552 pf.top = df.top = of.top = mRestrictedScreenTop;
4553 pf.right = df.right = of.right = mRestrictedScreenLeft + mRestrictedScreenWidth;
4554 pf.bottom = df.bottom = of.bottom = mRestrictedScreenTop
4555 + mRestrictedScreenHeight;
4556 if (adjust != SOFT_INPUT_ADJUST_RESIZE) {
4557 cf.left = mDockLeft;
4558 cf.top = mDockTop;
4559 cf.right = mDockRight;
4560 cf.bottom = mDockBottom;
4561 } else {
4562 cf.left = mContentLeft;
4563 cf.top = mContentTop;
4564 cf.right = mContentRight;
4565 cf.bottom = mContentBottom;
4566 }
Joe Onorato29fc2c92010-11-24 10:26:50 -08004567 } else {
Dianne Hackbornc4aad012013-02-22 15:05:25 -08004568 pf.left = df.left = of.left = cf.left = mRestrictedScreenLeft;
4569 pf.top = df.top = of.top = cf.top = mRestrictedScreenTop;
4570 pf.right = df.right = of.right = cf.right = mRestrictedScreenLeft
4571 + mRestrictedScreenWidth;
4572 pf.bottom = df.bottom = of.bottom = cf.bottom = mRestrictedScreenTop
4573 + mRestrictedScreenHeight;
Joe Onorato29fc2c92010-11-24 10:26:50 -08004574 }
Craig Mautner69b08182012-09-05 13:07:13 -07004575
Dianne Hackborn5b5cc4d2012-05-16 13:15:00 -07004576 applyStableConstraints(sysUiFl, fl, cf);
Craig Mautner69b08182012-09-05 13:07:13 -07004577
Dianne Hackborndea3ef72010-10-28 14:24:22 -07004578 if (adjust != SOFT_INPUT_ADJUST_NOTHING) {
4579 vf.left = mCurLeft;
4580 vf.top = mCurTop;
4581 vf.right = mCurRight;
4582 vf.bottom = mCurBottom;
4583 } else {
4584 vf.set(cf);
4585 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004586 } else if (attached != null) {
Craig Mautnereda67292013-04-28 13:50:14 -07004587 if (DEBUG_LAYOUT) Slog.v(TAG, "layoutWindowLw(" + attrs.getTitle() +
4588 "): attached to " + attached);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004589 // A child window should be placed inside of the same visible
4590 // frame that its parent had.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08004591 setAttachedWindowFrames(win, fl, adjust, attached, false, pf, df, of, cf, vf);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004592 } else {
Craig Mautnereda67292013-04-28 13:50:14 -07004593 if (DEBUG_LAYOUT) Slog.v(TAG, "layoutWindowLw(" + attrs.getTitle() +
4594 "): normal window");
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004595 // Otherwise, a normal window must be placed inside the content
4596 // of all screen decorations.
John Spurlock67a0f852015-06-15 15:35:47 -04004597 if (attrs.type == TYPE_STATUS_BAR_PANEL || attrs.type == TYPE_VOLUME_OVERLAY) {
4598 // Status bar panels and the volume dialog are the only windows who can go on
4599 // top of the status bar. They are protected by the STATUS_BAR_SERVICE
Dianne Hackborna239c842011-06-01 12:28:20 -07004600 // permission, so they have the same privileges as the status
4601 // bar itself.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08004602 pf.left = df.left = of.left = cf.left = mRestrictedScreenLeft;
4603 pf.top = df.top = of.top = cf.top = mRestrictedScreenTop;
4604 pf.right = df.right = of.right = cf.right = mRestrictedScreenLeft
4605 + mRestrictedScreenWidth;
4606 pf.bottom = df.bottom = of.bottom = cf.bottom = mRestrictedScreenTop
4607 + mRestrictedScreenHeight;
John Spurlock67a0f852015-06-15 15:35:47 -04004608 } else if (attrs.type == TYPE_TOAST || attrs.type == TYPE_SYSTEM_ALERT) {
John Spurlock414c1f02013-12-04 13:47:36 -05004609 // These dialogs are stable to interim decor changes.
John Spurlockbd957402013-10-03 11:38:39 -04004610 pf.left = df.left = of.left = cf.left = mStableLeft;
4611 pf.top = df.top = of.top = cf.top = mStableTop;
4612 pf.right = df.right = of.right = cf.right = mStableRight;
4613 pf.bottom = df.bottom = of.bottom = cf.bottom = mStableBottom;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004614 } else {
Dianne Hackborna239c842011-06-01 12:28:20 -07004615 pf.left = mContentLeft;
4616 pf.top = mContentTop;
4617 pf.right = mContentRight;
4618 pf.bottom = mContentBottom;
Dianne Hackborn20d94742014-05-29 18:35:45 -07004619 if (win.isVoiceInteraction()) {
4620 df.left = of.left = cf.left = mVoiceContentLeft;
4621 df.top = of.top = cf.top = mVoiceContentTop;
4622 df.right = of.right = cf.right = mVoiceContentRight;
4623 df.bottom = of.bottom = cf.bottom = mVoiceContentBottom;
4624 } else if (adjust != SOFT_INPUT_ADJUST_RESIZE) {
Dianne Hackbornc4aad012013-02-22 15:05:25 -08004625 df.left = of.left = cf.left = mDockLeft;
4626 df.top = of.top = cf.top = mDockTop;
4627 df.right = of.right = cf.right = mDockRight;
4628 df.bottom = of.bottom = cf.bottom = mDockBottom;
Dianne Hackborna239c842011-06-01 12:28:20 -07004629 } else {
Dianne Hackbornc4aad012013-02-22 15:05:25 -08004630 df.left = of.left = cf.left = mContentLeft;
4631 df.top = of.top = cf.top = mContentTop;
4632 df.right = of.right = cf.right = mContentRight;
4633 df.bottom = of.bottom = cf.bottom = mContentBottom;
Dianne Hackborna239c842011-06-01 12:28:20 -07004634 }
4635 if (adjust != SOFT_INPUT_ADJUST_NOTHING) {
4636 vf.left = mCurLeft;
4637 vf.top = mCurTop;
4638 vf.right = mCurRight;
4639 vf.bottom = mCurBottom;
4640 } else {
4641 vf.set(cf);
4642 }
Dianne Hackborndea3ef72010-10-28 14:24:22 -07004643 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004644 }
4645 }
Craig Mautner69b08182012-09-05 13:07:13 -07004646
Craig Mautnerb816bed2013-07-23 10:26:17 -07004647 // TYPE_SYSTEM_ERROR is above the NavigationBar so it can't be allowed to extend over it.
Wale Ogunwale9185fb02016-03-11 18:06:14 -08004648 // Also, we don't allow windows in multi-window mode to extend out of the screen.
4649 if ((fl & FLAG_LAYOUT_NO_LIMITS) != 0 && attrs.type != TYPE_SYSTEM_ERROR
4650 && !win.inMultiWindowMode()) {
Dianne Hackborn067e5f62014-09-07 23:14:30 -07004651 df.left = df.top = -10000;
4652 df.right = df.bottom = 10000;
4653 if (attrs.type != TYPE_WALLPAPER) {
4654 of.left = of.top = cf.left = cf.top = vf.left = vf.top = -10000;
4655 of.right = of.bottom = cf.right = cf.bottom = vf.right = vf.bottom = 10000;
4656 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004657 }
4658
Filip Gruszczynski2217f612015-05-26 11:32:08 -07004659 // If the device has a chin (e.g. some watches), a dead area at the bottom of the screen we
4660 // need to provide information to the clients that want to pretend that you can draw there.
Filip Gruszczynskib0c673b2015-06-05 09:43:06 -07004661 // We only want to apply outsets to certain types of windows. For example, we never want to
4662 // apply the outsets to floating dialogs, because they wouldn't make sense there.
Filip Gruszczynski2987f612015-06-30 15:03:30 -07004663 final boolean useOutsets = shouldUseOutsets(attrs, fl);
Filip Gruszczynskib0c673b2015-06-05 09:43:06 -07004664 if (isDefaultDisplay && useOutsets) {
Filip Gruszczynski2217f612015-05-26 11:32:08 -07004665 osf = mTmpOutsetFrame;
4666 osf.set(cf.left, cf.top, cf.right, cf.bottom);
4667 int outset = ScreenShapeHelper.getWindowOutsetBottomPx(mContext.getResources());
4668 if (outset > 0) {
Filip Gruszczynski2987f612015-06-30 15:03:30 -07004669 int rotation = mDisplayRotation;
Filip Gruszczynski2217f612015-05-26 11:32:08 -07004670 if (rotation == Surface.ROTATION_0) {
4671 osf.bottom += outset;
4672 } else if (rotation == Surface.ROTATION_90) {
4673 osf.right += outset;
4674 } else if (rotation == Surface.ROTATION_180) {
4675 osf.top -= outset;
4676 } else if (rotation == Surface.ROTATION_270) {
4677 osf.left -= outset;
4678 }
4679 if (DEBUG_LAYOUT) Slog.v(TAG, "applying bottom outset of " + outset
4680 + " with rotation " + rotation + ", result: " + osf);
4681 }
4682 }
4683
Craig Mautnereda67292013-04-28 13:50:14 -07004684 if (DEBUG_LAYOUT) Slog.v(TAG, "Compute frame " + attrs.getTitle()
The Android Open Source Project11267662009-03-18 17:39:47 -07004685 + ": sim=#" + Integer.toHexString(sim)
RoboErik8a2cfc32014-05-16 11:19:38 -07004686 + " attach=" + attached + " type=" + attrs.type
Daniel Sandler8956dbb2011-04-22 07:55:02 -04004687 + String.format(" flags=0x%08x", fl)
The Android Open Source Project11267662009-03-18 17:39:47 -07004688 + " pf=" + pf.toShortString() + " df=" + df.toShortString()
Dianne Hackbornc4aad012013-02-22 15:05:25 -08004689 + " of=" + of.toShortString()
John Spurlock46646232013-09-30 22:32:42 -04004690 + " cf=" + cf.toShortString() + " vf=" + vf.toShortString()
Adrian Roosfa104232014-06-20 16:10:14 -07004691 + " dcf=" + dcf.toShortString()
Filip Gruszczynski2217f612015-05-26 11:32:08 -07004692 + " sf=" + sf.toShortString()
4693 + " osf=" + (osf == null ? "null" : osf.toShortString()));
Craig Mautner69b08182012-09-05 13:07:13 -07004694
Filip Gruszczynski2217f612015-05-26 11:32:08 -07004695 win.computeFrameLw(pf, df, of, cf, vf, dcf, sf, osf);
Craig Mautner69b08182012-09-05 13:07:13 -07004696
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004697 // Dock windows carve out the bottom of the screen, so normal windows
4698 // can't appear underneath them.
Craig Mautner8bd206b2012-10-03 10:32:02 -07004699 if (attrs.type == TYPE_INPUT_METHOD && win.isVisibleOrBehindKeyguardLw()
4700 && !win.getGivenInsetsPendingLw()) {
satok1bc0a492012-04-25 22:47:12 +09004701 setLastInputMethodWindowLw(null, null);
4702 offsetInputMethodWindowLw(win);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004703 }
Dianne Hackborne30e02f2014-05-27 18:24:45 -07004704 if (attrs.type == TYPE_VOICE_INTERACTION && win.isVisibleOrBehindKeyguardLw()
4705 && !win.getGivenInsetsPendingLw()) {
4706 offsetVoiceInputWindowLw(win);
4707 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004708 }
4709
satok1bc0a492012-04-25 22:47:12 +09004710 private void offsetInputMethodWindowLw(WindowState win) {
Craig Mautner4774f6a2015-03-23 11:42:55 -07004711 int top = Math.max(win.getDisplayFrameLw().top, win.getContentFrameLw().top);
satok1bc0a492012-04-25 22:47:12 +09004712 top += win.getGivenContentInsetsLw().top;
4713 if (mContentBottom > top) {
4714 mContentBottom = top;
4715 }
Dianne Hackborne30e02f2014-05-27 18:24:45 -07004716 if (mVoiceContentBottom > top) {
4717 mVoiceContentBottom = top;
4718 }
satok1bc0a492012-04-25 22:47:12 +09004719 top = win.getVisibleFrameLw().top;
4720 top += win.getGivenVisibleInsetsLw().top;
4721 if (mCurBottom > top) {
4722 mCurBottom = top;
4723 }
Craig Mautnereda67292013-04-28 13:50:14 -07004724 if (DEBUG_LAYOUT) Slog.v(TAG, "Input method: mDockBottom="
satok1bc0a492012-04-25 22:47:12 +09004725 + mDockBottom + " mContentBottom="
4726 + mContentBottom + " mCurBottom=" + mCurBottom);
4727 }
4728
Dianne Hackborne30e02f2014-05-27 18:24:45 -07004729 private void offsetVoiceInputWindowLw(WindowState win) {
Craig Mautner4774f6a2015-03-23 11:42:55 -07004730 int top = Math.max(win.getDisplayFrameLw().top, win.getContentFrameLw().top);
Dianne Hackbornae6688b2015-02-11 17:02:41 -08004731 top += win.getGivenContentInsetsLw().top;
4732 if (mVoiceContentBottom > top) {
4733 mVoiceContentBottom = top;
Dianne Hackborne30e02f2014-05-27 18:24:45 -07004734 }
4735 }
4736
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004737 /** {@inheritDoc} */
Craig Mautner61ac6bb2012-02-02 17:29:33 -08004738 @Override
4739 public void finishLayoutLw() {
4740 return;
Dianne Hackborn5f3063e2010-03-10 16:01:58 -08004741 }
4742
4743 /** {@inheritDoc} */
Craig Mautnerad09bcc2012-10-08 13:33:11 -07004744 @Override
Craig Mautner39834192012-09-02 07:47:24 -07004745 public void beginPostLayoutPolicyLw(int displayWidth, int displayHeight) {
Dianne Hackborn5f3063e2010-03-10 16:01:58 -08004746 mTopFullscreenOpaqueWindowState = null;
Adrian Rooscd3884d2015-02-18 17:25:23 +01004747 mTopFullscreenOpaqueOrDimmingWindowState = null;
Jorim Jaggi86905582016-02-09 21:36:09 -08004748 mTopDockedOpaqueWindowState = null;
4749 mTopDockedOpaqueOrDimmingWindowState = null;
Craig Mautner2bc789b2014-03-19 19:48:38 -07004750 mAppsToBeHidden.clear();
Jorim Jaggic13fcac2014-09-11 17:36:57 +02004751 mAppsThatDismissKeyguard.clear();
Dianne Hackborn5f3063e2010-03-10 16:01:58 -08004752 mForceStatusBar = false;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07004753 mForceStatusBarFromKeyguard = false;
Selim Cinek4a4a2bddc2015-05-07 12:50:19 -07004754 mForceStatusBarTransparent = false;
Dianne Hackborn891d3fb2013-01-09 18:31:37 -08004755 mForcingShowNavBar = false;
4756 mForcingShowNavBarLayer = -1;
RoboErik8a2cfc32014-05-16 11:19:38 -07004757
Dianne Hackborn5f3063e2010-03-10 16:01:58 -08004758 mHideLockScreen = false;
4759 mAllowLockscreenWhenOn = false;
Craig Mautnerad09bcc2012-10-08 13:33:11 -07004760 mDismissKeyguard = DISMISS_KEYGUARD_NONE;
Dianne Hackborn7ad44382012-10-18 17:46:00 -07004761 mShowingLockscreen = false;
4762 mShowingDream = false;
Craig Mautnerc9457fa2014-06-06 14:27:48 -07004763 mWinShowWhenLocked = null;
Jim Millerab954542014-10-10 18:21:49 -07004764 mKeyguardSecure = isKeyguardSecure();
4765 mKeyguardSecureIncludingHidden = mKeyguardSecure
4766 && (mKeyguardDelegate != null && mKeyguardDelegate.isShowing());
Dianne Hackborn5f3063e2010-03-10 16:01:58 -08004767 }
4768
4769 /** {@inheritDoc} */
Craig Mautnerad09bcc2012-10-08 13:33:11 -07004770 @Override
Yohei Yukawad1a09222015-06-30 16:22:05 -07004771 public void applyPostLayoutPolicyLw(WindowState win, WindowManager.LayoutParams attrs,
4772 WindowState attached) {
Dianne Hackbornbc1aa7b2011-09-20 11:20:31 -07004773 if (DEBUG_LAYOUT) Slog.i(TAG, "Win " + win + ": isVisibleOrBehindKeyguardLw="
4774 + win.isVisibleOrBehindKeyguardLw());
John Spurlockc6d1c602014-01-17 15:22:06 -05004775 final int fl = PolicyControl.getWindowFlags(win, attrs);
John Spurlock414c1f02013-12-04 13:47:36 -05004776 if (mTopFullscreenOpaqueWindowState == null
4777 && win.isVisibleLw() && attrs.type == TYPE_INPUT_METHOD) {
4778 mForcingShowNavBar = true;
4779 mForcingShowNavBarLayer = win.getSurfaceLayer();
Dianne Hackborn891d3fb2013-01-09 18:31:37 -08004780 }
Selim Cinek4a4a2bddc2015-05-07 12:50:19 -07004781 if (attrs.type == TYPE_STATUS_BAR) {
4782 if ((attrs.privateFlags & PRIVATE_FLAG_KEYGUARD) != 0) {
4783 mForceStatusBarFromKeyguard = true;
Jorim Jaggie1de9f62015-09-23 14:59:50 -07004784 mShowingLockscreen = true;
Selim Cinek4a4a2bddc2015-05-07 12:50:19 -07004785 }
4786 if ((attrs.privateFlags & PRIVATE_FLAG_FORCE_STATUS_BAR_VISIBLE_TRANSPARENT) != 0) {
4787 mForceStatusBarTransparent = true;
4788 }
Jorim Jaggiafd4a552014-04-08 15:13:05 +02004789 }
Adrian Roos602c68e2015-04-24 16:03:47 -07004790
4791 boolean appWindow = attrs.type >= FIRST_APPLICATION_WINDOW
4792 && attrs.type < FIRST_SYSTEM_WINDOW;
4793 final boolean showWhenLocked = (fl & FLAG_SHOW_WHEN_LOCKED) != 0;
4794 final boolean dismissKeyguard = (fl & FLAG_DISMISS_KEYGUARD) != 0;
Jorim Jaggi86905582016-02-09 21:36:09 -08004795 final int stackId = win.getStackId();
Dianne Hackborn5f3063e2010-03-10 16:01:58 -08004796 if (mTopFullscreenOpaqueWindowState == null &&
Dianne Hackborn01b02a72012-01-12 14:05:03 -08004797 win.isVisibleOrBehindKeyguardLw() && !win.isGoneForLayoutLw()) {
John Spurlockc6d1c602014-01-17 15:22:06 -05004798 if ((fl & FLAG_FORCE_NOT_FULLSCREEN) != 0) {
Jorim Jaggi380ecb82014-03-14 17:25:20 +01004799 if ((attrs.privateFlags & PRIVATE_FLAG_KEYGUARD) != 0) {
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07004800 mForceStatusBarFromKeyguard = true;
4801 } else {
4802 mForceStatusBar = true;
4803 }
4804 }
Dianne Hackborn7ad44382012-10-18 17:46:00 -07004805 if (attrs.type == TYPE_DREAM) {
Jeff Brownc8018eb2012-10-29 21:33:27 -07004806 // If the lockscreen was showing when the dream started then wait
4807 // for the dream to draw before hiding the lockscreen.
4808 if (!mDreamingLockscreen
4809 || (win.isVisibleLw() && win.hasDrawnLw())) {
4810 mShowingDream = true;
Craig Mautnerab55e522014-03-03 13:26:03 -08004811 appWindow = true;
Dianne Hackborn7ad44382012-10-18 17:46:00 -07004812 }
4813 }
Craig Mautnerab55e522014-03-03 13:26:03 -08004814
Yohei Yukawad1a09222015-06-30 16:22:05 -07004815 final IApplicationToken appToken = win.getAppToken();
4816
4817 // For app windows that are not attached, we decide if all windows in the app they
4818 // represent should be hidden or if we should hide the lockscreen. For attached app
4819 // windows we defer the decision to the window it is attached to.
4820 if (appWindow && attached == null) {
Jorim Jaggic13fcac2014-09-11 17:36:57 +02004821 if (showWhenLocked) {
Craig Mautnerc9457fa2014-06-06 14:27:48 -07004822 // Remove any previous windows with the same appToken.
Jorim Jaggic13fcac2014-09-11 17:36:57 +02004823 mAppsToBeHidden.remove(appToken);
4824 mAppsThatDismissKeyguard.remove(appToken);
Craig Mautnerca0a1242014-12-02 12:25:14 -08004825 if (mAppsToBeHidden.isEmpty()) {
Craig Mautner192d6042014-12-02 23:24:48 -08004826 if (dismissKeyguard && !mKeyguardSecure) {
4827 mAppsThatDismissKeyguard.add(appToken);
Selim Cinek90b5e072015-08-28 17:05:56 -07004828 } else if (win.isDrawnLw() || win.hasAppShownWindows()) {
Craig Mautnerca0a1242014-12-02 12:25:14 -08004829 mWinShowWhenLocked = win;
4830 mHideLockScreen = true;
4831 mForceStatusBarFromKeyguard = false;
Craig Mautnerca0a1242014-12-02 12:25:14 -08004832 }
Craig Mautnerc9457fa2014-06-06 14:27:48 -07004833 }
Jorim Jaggic13fcac2014-09-11 17:36:57 +02004834 } else if (dismissKeyguard) {
Jim Millerab954542014-10-10 18:21:49 -07004835 if (mKeyguardSecure) {
Jorim Jaggic13fcac2014-09-11 17:36:57 +02004836 mAppsToBeHidden.add(appToken);
4837 } else {
4838 mAppsToBeHidden.remove(appToken);
4839 }
4840 mAppsThatDismissKeyguard.add(appToken);
Craig Mautner2bc789b2014-03-19 19:48:38 -07004841 } else {
Jorim Jaggic13fcac2014-09-11 17:36:57 +02004842 mAppsToBeHidden.add(appToken);
Craig Mautner2bc789b2014-03-19 19:48:38 -07004843 }
Jorim Jaggi86905582016-02-09 21:36:09 -08004844 if (isFullscreen(attrs) && StackId.normallyFullscreenWindows(stackId)) {
Craig Mautnerab55e522014-03-03 13:26:03 -08004845 if (DEBUG_LAYOUT) Slog.v(TAG, "Fullscreen window: " + win);
4846 mTopFullscreenOpaqueWindowState = win;
Adrian Rooscd3884d2015-02-18 17:25:23 +01004847 if (mTopFullscreenOpaqueOrDimmingWindowState == null) {
4848 mTopFullscreenOpaqueOrDimmingWindowState = win;
4849 }
Jorim Jaggic13fcac2014-09-11 17:36:57 +02004850 if (!mAppsThatDismissKeyguard.isEmpty() &&
4851 mDismissKeyguard == DISMISS_KEYGUARD_NONE) {
4852 if (DEBUG_LAYOUT) Slog.v(TAG,
4853 "Setting mDismissKeyguard true by win " + win);
tingna_sunge785ffa2015-05-12 13:23:15 +08004854 mDismissKeyguard = (mWinDismissingKeyguard == win
4855 && mSecureDismissingKeyguard == mKeyguardSecure)
4856 ? DISMISS_KEYGUARD_CONTINUE : DISMISS_KEYGUARD_START;
Jorim Jaggic13fcac2014-09-11 17:36:57 +02004857 mWinDismissingKeyguard = win;
tingna_sunge785ffa2015-05-12 13:23:15 +08004858 mSecureDismissingKeyguard = mKeyguardSecure;
Jim Millerab954542014-10-10 18:21:49 -07004859 mForceStatusBarFromKeyguard = mShowingLockscreen && mKeyguardSecure;
Selim Cinek90b5e072015-08-28 17:05:56 -07004860 } else if (mAppsToBeHidden.isEmpty() && showWhenLocked
4861 && (win.isDrawnLw() || win.hasAppShownWindows())) {
Jorim Jaggic13fcac2014-09-11 17:36:57 +02004862 if (DEBUG_LAYOUT) Slog.v(TAG,
4863 "Setting mHideLockScreen to true by win " + win);
4864 mHideLockScreen = true;
4865 mForceStatusBarFromKeyguard = false;
Craig Mautnerab55e522014-03-03 13:26:03 -08004866 }
Craig Mautner00156ec2014-03-06 22:29:02 -08004867 if ((fl & FLAG_ALLOW_LOCK_WHILE_SCREEN_ON) != 0) {
Craig Mautnerab55e522014-03-03 13:26:03 -08004868 mAllowLockscreenWhenOn = true;
4869 }
Dianne Hackborn5f3063e2010-03-10 16:01:58 -08004870 }
Craig Mautnerc9457fa2014-06-06 14:27:48 -07004871
4872 if (mWinShowWhenLocked != null &&
Adrian Roos602c68e2015-04-24 16:03:47 -07004873 mWinShowWhenLocked.getAppToken() != win.getAppToken() &&
4874 (attrs.flags & FLAG_SHOW_WHEN_LOCKED) == 0) {
Craig Mautnerc9457fa2014-06-06 14:27:48 -07004875 win.hideLw(false);
4876 }
Dianne Hackborn5f3063e2010-03-10 16:01:58 -08004877 }
Adrian Roos602c68e2015-04-24 16:03:47 -07004878 } else if (mTopFullscreenOpaqueWindowState == null && mWinShowWhenLocked == null) {
4879 // No TopFullscreenOpaqueWindow is showing, but we found a SHOW_WHEN_LOCKED window
4880 // that is being hidden in an animation - keep the
4881 // keyguard hidden until the new window shows up and
4882 // we know whether to show the keyguard or not.
Adrian Roosb85e1ec2015-05-29 15:23:18 -07004883 if (win.isAnimatingLw() && appWindow && showWhenLocked && mKeyguardHidden) {
Adrian Roos602c68e2015-04-24 16:03:47 -07004884 mHideLockScreen = true;
4885 mWinShowWhenLocked = win;
4886 }
Dianne Hackborn5f3063e2010-03-10 16:01:58 -08004887 }
Jorim Jaggi86905582016-02-09 21:36:09 -08004888
4889 // Keep track of the window if it's dimming but not necessarily fullscreen.
4890 final boolean reallyVisible = win.isVisibleOrBehindKeyguardLw() && !win.isGoneForLayoutLw();
4891 if (mTopFullscreenOpaqueOrDimmingWindowState == null && reallyVisible
4892 && win.isDimming() && StackId.normallyFullscreenWindows(stackId)) {
Adrian Rooscd3884d2015-02-18 17:25:23 +01004893 mTopFullscreenOpaqueOrDimmingWindowState = win;
4894 }
Jorim Jaggi86905582016-02-09 21:36:09 -08004895
4896 // We need to keep track of the top "fullscreen" opaque window for the docked stack
4897 // separately, because both the "real fullscreen" opaque window and the one for the docked
4898 // stack can control View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR.
4899 if (mTopDockedOpaqueWindowState == null && reallyVisible && appWindow && attached == null
4900 && isFullscreen(attrs) && stackId == DOCKED_STACK_ID) {
4901 mTopDockedOpaqueWindowState = win;
4902 if (mTopDockedOpaqueOrDimmingWindowState == null) {
4903 mTopDockedOpaqueOrDimmingWindowState = win;
4904 }
4905 }
4906
4907 // Also keep track of any windows that are dimming but not necessarily fullscreen in the
4908 // docked stack.
4909 if (mTopDockedOpaqueOrDimmingWindowState == null && reallyVisible && win.isDimming()
4910 && stackId == DOCKED_STACK_ID) {
4911 mTopDockedOpaqueOrDimmingWindowState = win;
4912 }
4913 }
4914
4915 private boolean isFullscreen(WindowManager.LayoutParams attrs) {
4916 return attrs.x == 0 && attrs.y == 0
4917 && attrs.width == WindowManager.LayoutParams.MATCH_PARENT
4918 && attrs.height == WindowManager.LayoutParams.MATCH_PARENT;
Dianne Hackborn5f3063e2010-03-10 16:01:58 -08004919 }
4920
4921 /** {@inheritDoc} */
Craig Mautnerad09bcc2012-10-08 13:33:11 -07004922 @Override
Craig Mautner39834192012-09-02 07:47:24 -07004923 public int finishPostLayoutPolicyLw() {
Craig Mautnerc5e73bf2015-04-21 15:41:26 +00004924 if (mWinShowWhenLocked != null && mTopFullscreenOpaqueWindowState != null &&
4925 mWinShowWhenLocked.getAppToken() != mTopFullscreenOpaqueWindowState.getAppToken()
4926 && isKeyguardLocked()) {
Craig Mautnerc9457fa2014-06-06 14:27:48 -07004927 // A dialog is dismissing the keyguard. Put the wallpaper behind it and hide the
4928 // fullscreen window.
4929 // TODO: Make sure FLAG_SHOW_WALLPAPER is restored when dialog is dismissed. Or not.
4930 mWinShowWhenLocked.getAttrs().flags |= FLAG_SHOW_WALLPAPER;
4931 mTopFullscreenOpaqueWindowState.hideLw(false);
4932 mTopFullscreenOpaqueWindowState = mWinShowWhenLocked;
4933 }
4934
Dianne Hackborn39c2d712009-09-22 11:41:31 -07004935 int changes = 0;
Joe Onorato93056472010-09-10 10:30:46 -04004936 boolean topIsFullscreen = false;
Daniel Sandlere02d8082010-10-08 15:13:22 -04004937
4938 final WindowManager.LayoutParams lp = (mTopFullscreenOpaqueWindowState != null)
4939 ? mTopFullscreenOpaqueWindowState.getAttrs()
4940 : null;
4941
Jeff Brownc8018eb2012-10-29 21:33:27 -07004942 // If we are not currently showing a dream then remember the current
4943 // lockscreen state. We will use this to determine whether the dream
4944 // started while the lockscreen was showing and remember this state
4945 // while the dream is showing.
Dianne Hackborn7ad44382012-10-18 17:46:00 -07004946 if (!mShowingDream) {
4947 mDreamingLockscreen = mShowingLockscreen;
Jeff Brown061ea992015-04-17 19:55:47 -07004948 if (mDreamingSleepTokenNeeded) {
4949 mDreamingSleepTokenNeeded = false;
4950 mHandler.obtainMessage(MSG_UPDATE_DREAMING_SLEEP_TOKEN, 0, 1).sendToTarget();
4951 }
4952 } else {
4953 if (!mDreamingSleepTokenNeeded) {
4954 mDreamingSleepTokenNeeded = true;
4955 mHandler.obtainMessage(MSG_UPDATE_DREAMING_SLEEP_TOKEN, 1, 1).sendToTarget();
4956 }
Dianne Hackborn7ad44382012-10-18 17:46:00 -07004957 }
4958
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004959 if (mStatusBar != null) {
Craig Mautnereda67292013-04-28 13:50:14 -07004960 if (DEBUG_LAYOUT) Slog.i(TAG, "force=" + mForceStatusBar
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07004961 + " forcefkg=" + mForceStatusBarFromKeyguard
Dianne Hackbornd70bc2f2009-10-06 23:25:51 -07004962 + " top=" + mTopFullscreenOpaqueWindowState);
Selim Cinek4a4a2bddc2015-05-07 12:50:19 -07004963 boolean shouldBeTransparent = mForceStatusBarTransparent
4964 && !mForceStatusBar
4965 && !mForceStatusBarFromKeyguard;
4966 if (!shouldBeTransparent) {
4967 mStatusBarController.setShowTransparent(false /* transparent */);
4968 } else if (!mStatusBar.isVisibleLw()) {
4969 mStatusBarController.setShowTransparent(true /* transparent */);
4970 }
4971 if (mForceStatusBar || mForceStatusBarFromKeyguard || mForceStatusBarTransparent) {
Craig Mautnereda67292013-04-28 13:50:14 -07004972 if (DEBUG_LAYOUT) Slog.v(TAG, "Showing status bar: forced");
John Spurlock27735a42013-08-14 17:57:38 -04004973 if (mStatusBarController.setBarShowingLw(true)) {
4974 changes |= FINISH_LAYOUT_REDO_LAYOUT;
4975 }
Craig Mautner81defc72013-10-29 11:10:42 -07004976 // Maintain fullscreen layout until incoming animation is complete.
4977 topIsFullscreen = mTopIsFullscreen && mStatusBar.isAnimatingLw();
John Spurlockf92b6162013-11-11 15:01:16 -05004978 // Transient status bar on the lockscreen is not allowed
4979 if (mForceStatusBarFromKeyguard && mStatusBarController.isTransientShowing()) {
4980 mStatusBarController.updateVisibilityLw(false /*transientAllowed*/,
4981 mLastSystemUiFlags, mLastSystemUiFlags);
4982 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004983 } else if (mTopFullscreenOpaqueWindowState != null) {
John Spurlockc6d1c602014-01-17 15:22:06 -05004984 final int fl = PolicyControl.getWindowFlags(null, lp);
Joe Onorato93056472010-09-10 10:30:46 -04004985 if (localLOGV) {
Craig Mautnereda67292013-04-28 13:50:14 -07004986 Slog.d(TAG, "frame: " + mTopFullscreenOpaqueWindowState.getFrameLw()
Filip Gruszczynski2a6a2c22015-10-14 12:00:53 -07004987 + " shown position: "
4988 + mTopFullscreenOpaqueWindowState.getShownPositionLw());
Craig Mautnereda67292013-04-28 13:50:14 -07004989 Slog.d(TAG, "attr: " + mTopFullscreenOpaqueWindowState.getAttrs()
John Spurlockc6d1c602014-01-17 15:22:06 -05004990 + " lp.flags=0x" + Integer.toHexString(fl));
Joe Onorato93056472010-09-10 10:30:46 -04004991 }
John Spurlockc6d1c602014-01-17 15:22:06 -05004992 topIsFullscreen = (fl & WindowManager.LayoutParams.FLAG_FULLSCREEN) != 0
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07004993 || (mLastSystemUiFlags & View.SYSTEM_UI_FLAG_FULLSCREEN) != 0;
Joe Onorato93056472010-09-10 10:30:46 -04004994 // The subtle difference between the window for mTopFullscreenOpaqueWindowState
Mark Dolinerd0646dc2014-08-27 16:04:02 -07004995 // and mTopIsFullscreen is that mTopIsFullscreen is set only if the window
Joe Onorato93056472010-09-10 10:30:46 -04004996 // has the FLAG_FULLSCREEN set. Not sure if there is another way that to be the
4997 // case though.
John Spurlock27735a42013-08-14 17:57:38 -04004998 if (mStatusBarController.isTransientShowing()) {
4999 if (mStatusBarController.setBarShowingLw(true)) {
John Spurlock32beb2c2013-03-11 10:16:47 -04005000 changes |= FINISH_LAYOUT_REDO_LAYOUT;
5001 }
Wale Ogunwale6e94a9e2015-10-07 15:35:49 -07005002 } else if (topIsFullscreen
5003 && !mWindowManagerInternal.isStackVisible(FREEFORM_WORKSPACE_STACK_ID)
5004 && !mWindowManagerInternal.isStackVisible(DOCKED_STACK_ID)) {
Craig Mautnereda67292013-04-28 13:50:14 -07005005 if (DEBUG_LAYOUT) Slog.v(TAG, "** HIDING status bar");
John Spurlock27735a42013-08-14 17:57:38 -04005006 if (mStatusBarController.setBarShowingLw(false)) {
Dianne Hackbornf87d1962012-04-04 12:48:24 -07005007 changes |= FINISH_LAYOUT_REDO_LAYOUT;
Craig Mautnereda67292013-04-28 13:50:14 -07005008 } else {
Craig Mautnerc5a6e442013-06-05 17:22:35 -07005009 if (DEBUG_LAYOUT) Slog.v(TAG, "Status bar already hiding");
Daniel Sandler40427442010-07-16 11:44:52 -04005010 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005011 } else {
Craig Mautnereda67292013-04-28 13:50:14 -07005012 if (DEBUG_LAYOUT) Slog.v(TAG, "** SHOWING status bar: top is not fullscreen");
John Spurlock27735a42013-08-14 17:57:38 -04005013 if (mStatusBarController.setBarShowingLw(true)) {
5014 changes |= FINISH_LAYOUT_REDO_LAYOUT;
5015 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005016 }
5017 }
5018 }
Daniel Sandlere02d8082010-10-08 15:13:22 -04005019
Craig Mautner81defc72013-10-29 11:10:42 -07005020 if (mTopIsFullscreen != topIsFullscreen) {
5021 if (!topIsFullscreen) {
5022 // Force another layout when status bar becomes fully shown.
5023 changes |= FINISH_LAYOUT_REDO_LAYOUT;
5024 }
5025 mTopIsFullscreen = topIsFullscreen;
5026 }
Daniel Sandlere02d8082010-10-08 15:13:22 -04005027
Craig Mautner39834192012-09-02 07:47:24 -07005028 // Hide the key guard if a visible window explicitly specifies that it wants to be
5029 // displayed when the screen is locked.
Jorim Jaggi5cf17872014-03-26 18:31:48 +01005030 if (mKeyguardDelegate != null && mStatusBar != null) {
5031 if (localLOGV) Slog.v(TAG, "finishPostLayoutPolicyLw: mHideKeyguard="
5032 + mHideLockScreen);
Jim Millerab954542014-10-10 18:21:49 -07005033 if (mDismissKeyguard != DISMISS_KEYGUARD_NONE && !mKeyguardSecure) {
Jorim Jaggi5cf17872014-03-26 18:31:48 +01005034 mKeyguardHidden = true;
Jim Millerab954542014-10-10 18:21:49 -07005035 if (setKeyguardOccludedLw(true)) {
Dianne Hackborn39c2d712009-09-22 11:41:31 -07005036 changes |= FINISH_LAYOUT_REDO_LAYOUT
5037 | FINISH_LAYOUT_REDO_CONFIG
5038 | FINISH_LAYOUT_REDO_WALLPAPER;
5039 }
Jorim Jaggi5cf17872014-03-26 18:31:48 +01005040 if (mKeyguardDelegate.isShowing()) {
5041 mHandler.post(new Runnable() {
5042 @Override
5043 public void run() {
5044 mKeyguardDelegate.keyguardDone(false, false);
5045 }
5046 });
5047 }
5048 } else if (mHideLockScreen) {
5049 mKeyguardHidden = true;
Jorim Jaggi7d85ea92015-05-20 17:20:40 -07005050 mWinDismissingKeyguard = null;
Jim Millerab954542014-10-10 18:21:49 -07005051 if (setKeyguardOccludedLw(true)) {
Jorim Jaggi5cf17872014-03-26 18:31:48 +01005052 changes |= FINISH_LAYOUT_REDO_LAYOUT
5053 | FINISH_LAYOUT_REDO_CONFIG
5054 | FINISH_LAYOUT_REDO_WALLPAPER;
5055 }
5056 } else if (mDismissKeyguard != DISMISS_KEYGUARD_NONE) {
Jorim Jaggi7d85ea92015-05-20 17:20:40 -07005057 mKeyguardHidden = false;
5058 if (setKeyguardOccludedLw(false)) {
5059 changes |= FINISH_LAYOUT_REDO_LAYOUT
5060 | FINISH_LAYOUT_REDO_CONFIG
5061 | FINISH_LAYOUT_REDO_WALLPAPER;
5062 }
Jorim Jaggi5cf17872014-03-26 18:31:48 +01005063 if (mDismissKeyguard == DISMISS_KEYGUARD_START) {
5064 // Only launch the next keyguard unlock window once per window.
Jorim Jaggi5cf17872014-03-26 18:31:48 +01005065 mHandler.post(new Runnable() {
5066 @Override
5067 public void run() {
5068 mKeyguardDelegate.dismiss();
5069 }
5070 });
5071 }
5072 } else {
5073 mWinDismissingKeyguard = null;
tingna_sunge785ffa2015-05-12 13:23:15 +08005074 mSecureDismissingKeyguard = false;
Jorim Jaggi5cf17872014-03-26 18:31:48 +01005075 mKeyguardHidden = false;
Jim Millerab954542014-10-10 18:21:49 -07005076 if (setKeyguardOccludedLw(false)) {
Jorim Jaggi5cf17872014-03-26 18:31:48 +01005077 changes |= FINISH_LAYOUT_REDO_LAYOUT
5078 | FINISH_LAYOUT_REDO_CONFIG
5079 | FINISH_LAYOUT_REDO_WALLPAPER;
5080 }
Suchi Amalapurapu9cdc9032009-05-14 18:01:07 -07005081 }
5082 }
Joe Onorato664644d2011-01-23 17:53:23 -08005083
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07005084 if ((updateSystemUiVisibilityLw()&SYSTEM_UI_CHANGING_LAYOUT) != 0) {
Dianne Hackborndf89e652011-10-06 22:35:11 -07005085 // If the navigation bar has been hidden or shown, we need to do another
5086 // layout pass to update that window.
5087 changes |= FINISH_LAYOUT_REDO_LAYOUT;
5088 }
Joe Onorato664644d2011-01-23 17:53:23 -08005089
Mike Lockwood28569302010-01-28 11:54:40 -05005090 // update since mAllowLockscreenWhenOn might have changed
5091 updateLockScreenTimeout();
Dianne Hackborn39c2d712009-09-22 11:41:31 -07005092 return changes;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005093 }
5094
Jorim Jaggi380ecb82014-03-14 17:25:20 +01005095 /**
Jim Millerab954542014-10-10 18:21:49 -07005096 * Updates the occluded state of the Keyguard.
Jorim Jaggi380ecb82014-03-14 17:25:20 +01005097 *
Jorim Jaggi380ecb82014-03-14 17:25:20 +01005098 * @return Whether the flags have changed and we have to redo the layout.
5099 */
Jim Millerab954542014-10-10 18:21:49 -07005100 private boolean setKeyguardOccludedLw(boolean isOccluded) {
5101 boolean wasOccluded = mKeyguardOccluded;
5102 boolean showing = mKeyguardDelegate.isShowing();
5103 if (wasOccluded && !isOccluded && showing) {
5104 mKeyguardOccluded = false;
5105 mKeyguardDelegate.setOccluded(false);
Jorim Jaggi380ecb82014-03-14 17:25:20 +01005106 mStatusBar.getAttrs().privateFlags |= PRIVATE_FLAG_KEYGUARD;
5107 mStatusBar.getAttrs().flags |= FLAG_SHOW_WALLPAPER;
5108 return true;
Jim Millerab954542014-10-10 18:21:49 -07005109 } else if (!wasOccluded && isOccluded && showing) {
5110 mKeyguardOccluded = true;
5111 mKeyguardDelegate.setOccluded(true);
Jorim Jaggi380ecb82014-03-14 17:25:20 +01005112 mStatusBar.getAttrs().privateFlags &= ~PRIVATE_FLAG_KEYGUARD;
5113 mStatusBar.getAttrs().flags &= ~FLAG_SHOW_WALLPAPER;
5114 return true;
5115 } else {
5116 return false;
5117 }
5118 }
5119
5120 private boolean isStatusBarKeyguard() {
5121 return mStatusBar != null
5122 && (mStatusBar.getAttrs().privateFlags & PRIVATE_FLAG_KEYGUARD) != 0;
5123 }
5124
Jose Lima9546b202014-07-02 17:21:51 -07005125 @Override
Dianne Hackborn08743722009-12-21 12:16:51 -08005126 public boolean allowAppAnimationsLw() {
Jorim Jaggi380ecb82014-03-14 17:25:20 +01005127 if (isStatusBarKeyguard() || mShowingDream) {
Craig Mautner28816302013-10-10 20:31:00 -07005128 // If keyguard or dreams is currently visible, no reason to animate behind it.
Dianne Hackborn08743722009-12-21 12:16:51 -08005129 return false;
5130 }
Dianne Hackborn08743722009-12-21 12:16:51 -08005131 return true;
5132 }
5133
Jose Lima9546b202014-07-02 17:21:51 -07005134 @Override
Dianne Hackborndf89e652011-10-06 22:35:11 -07005135 public int focusChangedLw(WindowState lastFocus, WindowState newFocus) {
Joe Onorato664644d2011-01-23 17:53:23 -08005136 mFocusedWindow = newFocus;
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07005137 if ((updateSystemUiVisibilityLw()&SYSTEM_UI_CHANGING_LAYOUT) != 0) {
Dianne Hackborndf89e652011-10-06 22:35:11 -07005138 // If the navigation bar has been hidden or shown, we need to do another
5139 // layout pass to update that window.
5140 return FINISH_LAYOUT_REDO_LAYOUT;
5141 }
5142 return 0;
Joe Onorato664644d2011-01-23 17:53:23 -08005143 }
5144
Dianne Hackborn0ecadf72009-03-31 18:00:37 -07005145 /** {@inheritDoc} */
Jose Lima9546b202014-07-02 17:21:51 -07005146 @Override
Jeff Brown46b9ac02010-04-22 18:58:52 -07005147 public void notifyLidSwitchChanged(long whenNanos, boolean lidOpen) {
5148 // lid changed state
Jeff Brownc458ce92012-04-30 14:58:40 -07005149 final int newLidState = lidOpen ? LID_OPEN : LID_CLOSED;
5150 if (newLidState == mLidState) {
5151 return;
5152 }
Jeff Brown01a98dd2011-09-20 15:08:29 -07005153
Jeff Brownc458ce92012-04-30 14:58:40 -07005154 mLidState = newLidState;
5155 applyLidSwitchState();
Jeff Brown01a98dd2011-09-20 15:08:29 -07005156 updateRotation(true);
Jeff Brownc458ce92012-04-30 14:58:40 -07005157
5158 if (lidOpen) {
Dianne Hackborn280a64e2015-07-13 14:48:08 -07005159 wakeUp(SystemClock.uptimeMillis(), mAllowTheaterModeWakeFromLidSwitch,
5160 "android.policy:LID");
Jeff Brownc458ce92012-04-30 14:58:40 -07005161 } else if (!mLidControlsSleep) {
Jeff Brown96307042012-07-27 15:51:34 -07005162 mPowerManager.userActivity(SystemClock.uptimeMillis(), false);
Jeff Brown46b9ac02010-04-22 18:58:52 -07005163 }
5164 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005165
Michael Wright3818c922014-09-02 13:59:07 -07005166 @Override
5167 public void notifyCameraLensCoverSwitchChanged(long whenNanos, boolean lensCovered) {
5168 int lensCoverState = lensCovered ? CAMERA_LENS_COVERED : CAMERA_LENS_UNCOVERED;
5169 if (mCameraLensCoverState == lensCoverState) {
5170 return;
5171 }
5172 if (mCameraLensCoverState == CAMERA_LENS_COVERED &&
5173 lensCoverState == CAMERA_LENS_UNCOVERED) {
5174 Intent intent;
5175 final boolean keyguardActive = mKeyguardDelegate == null ? false :
5176 mKeyguardDelegate.isShowing();
5177 if (keyguardActive) {
5178 intent = new Intent(MediaStore.INTENT_ACTION_STILL_IMAGE_CAMERA_SECURE);
5179 } else {
5180 intent = new Intent(MediaStore.INTENT_ACTION_STILL_IMAGE_CAMERA);
5181 }
Dianne Hackborn280a64e2015-07-13 14:48:08 -07005182 wakeUp(whenNanos / 1000000, mAllowTheaterModeWakeFromCameraLens,
5183 "android.policy:CAMERA_COVER");
Bart Sears8b1c27c2015-03-18 23:51:02 +00005184 startActivityAsUser(intent, UserHandle.CURRENT_OR_SELF);
Michael Wright3818c922014-09-02 13:59:07 -07005185 }
5186 mCameraLensCoverState = lensCoverState;
5187 }
5188
Dianne Hackbornad7fa7f2011-01-07 14:06:50 -08005189 void setHdmiPlugged(boolean plugged) {
5190 if (mHdmiPlugged != plugged) {
5191 mHdmiPlugged = plugged;
Dianne Hackbornf87d1962012-04-04 12:48:24 -07005192 updateRotation(true, true);
Dianne Hackbornad7fa7f2011-01-07 14:06:50 -08005193 Intent intent = new Intent(ACTION_HDMI_PLUGGED);
Joe Onoratodc100302011-01-11 17:07:41 -08005194 intent.addFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY_BEFORE_BOOT);
Dianne Hackbornad7fa7f2011-01-07 14:06:50 -08005195 intent.putExtra(EXTRA_HDMI_PLUGGED_STATE, plugged);
Dianne Hackborn5ac72a22012-08-29 18:32:08 -07005196 mContext.sendStickyBroadcastAsUser(intent, UserHandle.ALL);
Dianne Hackbornad7fa7f2011-01-07 14:06:50 -08005197 }
5198 }
5199
Joe Onoratoea495d42011-04-06 11:41:11 -07005200 void initializeHdmiState() {
Joe Onorato7ba631f2011-05-04 15:28:00 -07005201 boolean plugged = false;
Joe Onoratoea495d42011-04-06 11:41:11 -07005202 // watch for HDMI plug messages if the hdmi switch exists
5203 if (new File("/sys/devices/virtual/switch/hdmi/state").exists()) {
5204 mHDMIObserver.startObserving("DEVPATH=/devices/virtual/switch/hdmi");
5205
Joe Onoratoea495d42011-04-06 11:41:11 -07005206 final String filename = "/sys/class/switch/hdmi/state";
5207 FileReader reader = null;
5208 try {
5209 reader = new FileReader(filename);
5210 char[] buf = new char[15];
5211 int n = reader.read(buf);
5212 if (n > 1) {
5213 plugged = 0 != Integer.parseInt(new String(buf, 0, n-1));
5214 }
5215 } catch (IOException ex) {
5216 Slog.w(TAG, "Couldn't read hdmi state from " + filename + ": " + ex);
5217 } catch (NumberFormatException ex) {
5218 Slog.w(TAG, "Couldn't read hdmi state from " + filename + ": " + ex);
5219 } finally {
5220 if (reader != null) {
5221 try {
5222 reader.close();
5223 } catch (IOException ex) {
5224 }
Joe Onoratodc100302011-01-11 17:07:41 -08005225 }
5226 }
5227 }
Joe Onorato7ba631f2011-05-04 15:28:00 -07005228 // This dance forces the code in setHdmiPlugged to run.
5229 // Always do this so the sticky intent is stuck (to false) if there is no hdmi.
5230 mHdmiPlugged = !plugged;
5231 setHdmiPlugged(!mHdmiPlugged);
Joe Onoratodc100302011-01-11 17:07:41 -08005232 }
5233
Dianne Hackbornc0e3f242011-08-19 14:19:10 -07005234 final Object mScreenshotLock = new Object();
Dianne Hackbornfc8fa632011-08-17 16:20:47 -07005235 ServiceConnection mScreenshotConnection = null;
Dianne Hackbornfc8fa632011-08-17 16:20:47 -07005236
Jeff Brownd5bb82d2011-10-12 13:57:59 -07005237 final Runnable mScreenshotTimeout = new Runnable() {
5238 @Override public void run() {
5239 synchronized (mScreenshotLock) {
5240 if (mScreenshotConnection != null) {
5241 mContext.unbindService(mScreenshotConnection);
5242 mScreenshotConnection = null;
Winson44dbe292016-03-10 14:00:14 -08005243 notifyScreenshotError();
Dianne Hackbornfc8fa632011-08-17 16:20:47 -07005244 }
Winson Chung9112ec32011-06-27 13:15:32 -07005245 }
Jeff Brownd5bb82d2011-10-12 13:57:59 -07005246 }
5247 };
5248
5249 // Assume this is called from the Handler thread.
Muyuan Li6ca619f2016-03-08 13:30:42 -08005250 private void takeScreenshot(final int screenshotType) {
Jeff Brownd5bb82d2011-10-12 13:57:59 -07005251 synchronized (mScreenshotLock) {
5252 if (mScreenshotConnection != null) {
5253 return;
5254 }
Winson44dbe292016-03-10 14:00:14 -08005255 final ComponentName serviceComponent = new ComponentName(SYSUI_PACKAGE,
5256 SYSUI_SCREENSHOT_SERVICE);
5257 final Intent serviceIntent = new Intent();
5258 serviceIntent.setComponent(serviceComponent);
Jeff Brownd5bb82d2011-10-12 13:57:59 -07005259 ServiceConnection conn = new ServiceConnection() {
5260 @Override
5261 public void onServiceConnected(ComponentName name, IBinder service) {
5262 synchronized (mScreenshotLock) {
5263 if (mScreenshotConnection != this) {
5264 return;
5265 }
5266 Messenger messenger = new Messenger(service);
Muyuan Li6ca619f2016-03-08 13:30:42 -08005267 Message msg = Message.obtain(null, screenshotType);
Jeff Brownd5bb82d2011-10-12 13:57:59 -07005268 final ServiceConnection myConn = this;
5269 Handler h = new Handler(mHandler.getLooper()) {
5270 @Override
5271 public void handleMessage(Message msg) {
5272 synchronized (mScreenshotLock) {
5273 if (mScreenshotConnection == myConn) {
5274 mContext.unbindService(mScreenshotConnection);
5275 mScreenshotConnection = null;
5276 mHandler.removeCallbacks(mScreenshotTimeout);
5277 }
5278 }
5279 }
5280 };
5281 msg.replyTo = new Messenger(h);
Winson Chunga63bb842011-10-17 10:26:28 -07005282 msg.arg1 = msg.arg2 = 0;
5283 if (mStatusBar != null && mStatusBar.isVisibleLw())
5284 msg.arg1 = 1;
5285 if (mNavigationBar != null && mNavigationBar.isVisibleLw())
5286 msg.arg2 = 1;
Jeff Brownd5bb82d2011-10-12 13:57:59 -07005287 try {
5288 messenger.send(msg);
5289 } catch (RemoteException e) {
5290 }
5291 }
5292 }
Winson44dbe292016-03-10 14:00:14 -08005293
Jeff Brownd5bb82d2011-10-12 13:57:59 -07005294 @Override
Winson44dbe292016-03-10 14:00:14 -08005295 public void onServiceDisconnected(ComponentName name) {
5296 notifyScreenshotError();
5297 }
Jeff Brownd5bb82d2011-10-12 13:57:59 -07005298 };
Winson44dbe292016-03-10 14:00:14 -08005299 if (mContext.bindServiceAsUser(serviceIntent, conn,
5300 Context.BIND_AUTO_CREATE | Context.BIND_FOREGROUND_SERVICE_WHILE_AWAKE,
5301 UserHandle.CURRENT)) {
Jeff Brownd5bb82d2011-10-12 13:57:59 -07005302 mScreenshotConnection = conn;
5303 mHandler.postDelayed(mScreenshotTimeout, 10000);
5304 }
5305 }
Winson Chung9112ec32011-06-27 13:15:32 -07005306 }
5307
Winson44dbe292016-03-10 14:00:14 -08005308 /**
5309 * Notifies the screenshot service to show an error.
5310 */
5311 private void notifyScreenshotError() {
5312 // If the service process is killed, then ask it to clean up after itself
5313 final ComponentName errorComponent = new ComponentName(SYSUI_PACKAGE,
5314 SYSUI_SCREENSHOT_ERROR_RECEIVER);
5315 Intent errorIntent = new Intent();
5316 errorIntent.setComponent(errorComponent);
5317 errorIntent.addFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY_BEFORE_BOOT |
5318 Intent.FLAG_RECEIVER_FOREGROUND);
5319 mContext.sendBroadcastAsUser(errorIntent, UserHandle.ALL);
5320 }
5321
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005322 /** {@inheritDoc} */
Jeff Brown00fa7bd2010-07-02 15:37:36 -07005323 @Override
Jeff Brown037c33e2014-04-09 00:31:55 -07005324 public int interceptKeyBeforeQueueing(KeyEvent event, int policyFlags) {
Jeff Brown96307042012-07-27 15:51:34 -07005325 if (!mSystemBooted) {
5326 // If we have not yet booted, don't let key events do anything.
5327 return 0;
5328 }
5329
Jeff Brown037c33e2014-04-09 00:31:55 -07005330 final boolean interactive = (policyFlags & FLAG_INTERACTIVE) != 0;
Jeff Brown1f245102010-11-18 20:53:46 -08005331 final boolean down = event.getAction() == KeyEvent.ACTION_DOWN;
5332 final boolean canceled = event.isCanceled();
5333 final int keyCode = event.getKeyCode();
Jeff Browne20c9e02010-10-11 14:20:19 -07005334
Jeff Brown3122e442010-10-11 23:32:49 -07005335 final boolean isInjected = (policyFlags & WindowManagerPolicy.FLAG_INJECTED) != 0;
Jeff Brown3122e442010-10-11 23:32:49 -07005336
Mike Lockwoodc72b15f2009-11-28 20:58:22 -05005337 // If screen is off then we treat the case where the keyguard is open but hidden
5338 // the same as if it were open and in front.
5339 // This will prevent any keys other than the power button from waking the screen
5340 // when the keyguard is hidden by another activity.
Jim Miller5ecd8112013-01-09 18:50:26 -08005341 final boolean keyguardActive = (mKeyguardDelegate == null ? false :
Jeff Brown037c33e2014-04-09 00:31:55 -07005342 (interactive ?
Jim Millerab954542014-10-10 18:21:49 -07005343 isKeyguardShowingAndNotOccluded() :
Jim Miller5ecd8112013-01-09 18:50:26 -08005344 mKeyguardDelegate.isShowing()));
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005345
Jeff Brown40013652012-05-16 21:22:36 -07005346 if (DEBUG_INPUT) {
Jeff Brown00fa7bd2010-07-02 15:37:36 -07005347 Log.d(TAG, "interceptKeyTq keycode=" + keyCode
Jeff Brown037c33e2014-04-09 00:31:55 -07005348 + " interactive=" + interactive + " keyguardActive=" + keyguardActive
Jeff Brown26875502014-01-30 21:47:47 -08005349 + " policyFlags=" + Integer.toHexString(policyFlags));
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005350 }
5351
Jeff Brown037c33e2014-04-09 00:31:55 -07005352 // Basic policy based on interactive state.
Jeff Brown4d396052010-10-29 21:50:21 -07005353 int result;
Michael Wright337d9d22014-04-22 15:03:48 -07005354 boolean isWakeKey = (policyFlags & WindowManagerPolicy.FLAG_WAKE) != 0
5355 || event.isWakeKey();
Michael Wrightfc01f042014-09-08 14:12:24 -07005356 if (interactive || (isInjected && !isWakeKey)) {
RoboErikde9ba392014-09-26 12:51:01 -07005357 // When the device is interactive or the key is injected pass the
5358 // key to the application.
Jeff Brown4d396052010-10-29 21:50:21 -07005359 result = ACTION_PASS_TO_USER;
Jose Lima9546b202014-07-02 17:21:51 -07005360 isWakeKey = false;
Michael Wrightfc01f042014-09-08 14:12:24 -07005361 } else if (!interactive && shouldDispatchInputWhenNonInteractive()) {
5362 // If we're currently dozing with the screen on and the keyguard showing, pass the key
5363 // to the application but preserve its wake key status to make sure we still move
5364 // from dozing to fully interactive if we would normally go from off to fully
5365 // interactive.
5366 result = ACTION_PASS_TO_USER;
Jeff Brown4d396052010-10-29 21:50:21 -07005367 } else {
5368 // When the screen is off and the key is not injected, determine whether
5369 // to wake the device but don't pass the key to the application.
5370 result = 0;
Jeff Brown26875502014-01-30 21:47:47 -08005371 if (isWakeKey && (!down || !isWakeKeyWhenScreenOff(keyCode))) {
5372 isWakeKey = false;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005373 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005374 }
5375
Justin Kohd378ad72013-04-01 12:18:26 -07005376 // If the key would be handled globally, just return the result, don't worry about special
5377 // key processing.
Jeff Brown13f00f02014-10-31 14:45:50 -07005378 if (isValidGlobalKey(keyCode)
5379 && mGlobalKeyManager.shouldHandleGlobalKey(keyCode, event)) {
Michael Wright85b1af62014-06-04 14:51:58 -07005380 if (isWakeKey) {
Dianne Hackborn280a64e2015-07-13 14:48:08 -07005381 wakeUp(event.getEventTime(), mAllowTheaterModeWakeFromKey, "android.policy:KEY");
Michael Wright85b1af62014-06-04 14:51:58 -07005382 }
Justin Kohd378ad72013-04-01 12:18:26 -07005383 return result;
5384 }
5385
Jeff Brownbae8e772014-06-12 19:59:45 -07005386 boolean useHapticFeedback = down
5387 && (policyFlags & WindowManagerPolicy.FLAG_VIRTUAL) != 0
5388 && event.getRepeatCount() == 0;
5389
Jeff Brown4d396052010-10-29 21:50:21 -07005390 // Handle special keys.
5391 switch (keyCode) {
Anthony Hugh34f09ca2016-03-04 12:03:37 -08005392 case KeyEvent.KEYCODE_BACK: {
5393 if (down) {
5394 mBackKeyHandled = false;
5395 if (hasLongPressOnBackBehavior()) {
5396 Message msg = mHandler.obtainMessage(MSG_BACK_LONG_PRESS);
5397 msg.setAsynchronous(true);
5398 mHandler.sendMessageDelayed(msg,
5399 ViewConfiguration.get(mContext).getDeviceGlobalActionKeyTimeout());
5400 }
5401 } else {
5402 boolean handled = mBackKeyHandled;
5403
5404 // Reset back key state
5405 cancelPendingBackKeyAction();
5406
5407 // Don't pass back press to app if we've already handled it
5408 if (handled) {
5409 result &= ~ACTION_PASS_TO_USER;
5410 }
5411 }
5412 break;
5413 }
5414
Jeff Brown4d396052010-10-29 21:50:21 -07005415 case KeyEvent.KEYCODE_VOLUME_DOWN:
Jeff Brownb0418da2010-11-01 15:24:01 -07005416 case KeyEvent.KEYCODE_VOLUME_UP:
5417 case KeyEvent.KEYCODE_VOLUME_MUTE: {
Jeff Brownd5bb82d2011-10-12 13:57:59 -07005418 if (keyCode == KeyEvent.KEYCODE_VOLUME_DOWN) {
5419 if (down) {
Jeff Brown13f00f02014-10-31 14:45:50 -07005420 if (interactive && !mScreenshotChordVolumeDownKeyTriggered
Jeff Brownd5bb82d2011-10-12 13:57:59 -07005421 && (event.getFlags() & KeyEvent.FLAG_FALLBACK) == 0) {
Jeff Brown13f00f02014-10-31 14:45:50 -07005422 mScreenshotChordVolumeDownKeyTriggered = true;
5423 mScreenshotChordVolumeDownKeyTime = event.getDownTime();
5424 mScreenshotChordVolumeDownKeyConsumed = false;
Jeff Brownd5bb82d2011-10-12 13:57:59 -07005425 cancelPendingPowerKeyAction();
5426 interceptScreenshotChord();
5427 }
5428 } else {
Jeff Brown13f00f02014-10-31 14:45:50 -07005429 mScreenshotChordVolumeDownKeyTriggered = false;
Jeff Brownd5bb82d2011-10-12 13:57:59 -07005430 cancelPendingScreenshotChordAction();
5431 }
5432 } else if (keyCode == KeyEvent.KEYCODE_VOLUME_UP) {
5433 if (down) {
Jeff Brown13f00f02014-10-31 14:45:50 -07005434 if (interactive && !mScreenshotChordVolumeUpKeyTriggered
Jeff Brownd5bb82d2011-10-12 13:57:59 -07005435 && (event.getFlags() & KeyEvent.FLAG_FALLBACK) == 0) {
Jeff Brown13f00f02014-10-31 14:45:50 -07005436 mScreenshotChordVolumeUpKeyTriggered = true;
Jeff Brownd5bb82d2011-10-12 13:57:59 -07005437 cancelPendingPowerKeyAction();
5438 cancelPendingScreenshotChordAction();
5439 }
5440 } else {
Jeff Brown13f00f02014-10-31 14:45:50 -07005441 mScreenshotChordVolumeUpKeyTriggered = false;
Jeff Brownd5bb82d2011-10-12 13:57:59 -07005442 cancelPendingScreenshotChordAction();
5443 }
5444 }
Jeff Brown4d396052010-10-29 21:50:21 -07005445 if (down) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -07005446 TelecomManager telecomManager = getTelecommService();
5447 if (telecomManager != null) {
5448 if (telecomManager.isRinging()) {
Santos Cordon6848f722014-05-21 15:22:12 -07005449 // If an incoming call is ringing, either VOLUME key means
5450 // "silence ringer". We handle these keys here, rather than
5451 // in the InCallScreen, to make sure we'll respond to them
5452 // even if the InCallScreen hasn't come to the foreground yet.
5453 // Look for the DOWN event here, to agree with the "fallback"
5454 // behavior in the InCallScreen.
5455 Log.i(TAG, "interceptKeyBeforeQueueing:"
5456 + " VOLUME key-down while ringing: Silence ringer!");
Jeff Brown4d396052010-10-29 21:50:21 -07005457
Santos Cordon6848f722014-05-21 15:22:12 -07005458 // Silence the ringer. (It's safe to call this
5459 // even if the ringer has already been silenced.)
Tyler Gunnef9f6f92014-09-12 22:16:17 -07005460 telecomManager.silenceRinger();
Jeff Brown4d396052010-10-29 21:50:21 -07005461
Santos Cordon6848f722014-05-21 15:22:12 -07005462 // And *don't* pass this key thru to the current activity
5463 // (which is probably the InCallScreen.)
5464 result &= ~ACTION_PASS_TO_USER;
5465 break;
5466 }
Tyler Gunnef9f6f92014-09-12 22:16:17 -07005467 if (telecomManager.isInCall()
Santos Cordon6848f722014-05-21 15:22:12 -07005468 && (result & ACTION_PASS_TO_USER) == 0) {
5469 // If we are in call but we decided not to pass the key to
RoboErik430fc482014-06-12 15:49:20 -07005470 // the application, just pass it to the session service.
5471
5472 MediaSessionLegacyHelper.getHelper(mContext)
RoboErik3c45c292014-07-08 16:47:31 -07005473 .sendVolumeKeyEvent(event, false);
Santos Cordon6848f722014-05-21 15:22:12 -07005474 break;
Jeff Brown4d396052010-10-29 21:50:21 -07005475 }
5476 }
Jaewan Kim765487f2016-01-12 14:45:42 +09005477 }
5478 if (mUseTvRouting) {
5479 // On TVs, defer special key handlings to
5480 // {@link interceptKeyBeforeDispatching()}.
5481 result |= ACTION_PASS_TO_USER;
5482 } else if ((result & ACTION_PASS_TO_USER) == 0) {
5483 // If we aren't passing to the user and no one else
5484 // handled it send it to the session manager to
5485 // figure out.
5486 MediaSessionLegacyHelper.getHelper(mContext)
5487 .sendVolumeKeyEvent(event, true);
Jeff Brown4d396052010-10-29 21:50:21 -07005488 }
5489 break;
5490 }
5491
5492 case KeyEvent.KEYCODE_ENDCALL: {
5493 result &= ~ACTION_PASS_TO_USER;
5494 if (down) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -07005495 TelecomManager telecomManager = getTelecommService();
Jeff Brown4d396052010-10-29 21:50:21 -07005496 boolean hungUp = false;
Tyler Gunnef9f6f92014-09-12 22:16:17 -07005497 if (telecomManager != null) {
5498 hungUp = telecomManager.endCall();
Jeff Brown4d396052010-10-29 21:50:21 -07005499 }
Jeff Brown13f00f02014-10-31 14:45:50 -07005500 if (interactive && !hungUp) {
5501 mEndCallKeyHandled = false;
5502 mHandler.postDelayed(mEndCallLongPress,
5503 ViewConfiguration.get(mContext).getDeviceGlobalActionKeyTimeout());
5504 } else {
5505 mEndCallKeyHandled = true;
5506 }
Jeff Brown4d396052010-10-29 21:50:21 -07005507 } else {
Jeff Brown13f00f02014-10-31 14:45:50 -07005508 if (!mEndCallKeyHandled) {
5509 mHandler.removeCallbacks(mEndCallLongPress);
5510 if (!canceled) {
5511 if ((mEndcallBehavior
5512 & Settings.System.END_BUTTON_BEHAVIOR_HOME) != 0) {
5513 if (goHome()) {
5514 break;
5515 }
Dianne Hackborn0041e972009-07-24 17:14:43 -07005516 }
Jeff Brown13f00f02014-10-31 14:45:50 -07005517 if ((mEndcallBehavior
5518 & Settings.System.END_BUTTON_BEHAVIOR_SLEEP) != 0) {
5519 mPowerManager.goToSleep(event.getEventTime(),
5520 PowerManager.GO_TO_SLEEP_REASON_POWER_BUTTON, 0);
5521 isWakeKey = false;
5522 }
Jeff Brown4d396052010-10-29 21:50:21 -07005523 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005524 }
Jeff Brown4d396052010-10-29 21:50:21 -07005525 }
5526 break;
5527 }
5528
5529 case KeyEvent.KEYCODE_POWER: {
5530 result &= ~ACTION_PASS_TO_USER;
Jeff Brown13f00f02014-10-31 14:45:50 -07005531 isWakeKey = false; // wake-up will be handled separately
Jeff Brown4d396052010-10-29 21:50:21 -07005532 if (down) {
Jeff Brown13f00f02014-10-31 14:45:50 -07005533 interceptPowerKeyDown(event, interactive);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005534 } else {
Jeff Brown13f00f02014-10-31 14:45:50 -07005535 interceptPowerKeyUp(event, interactive, canceled);
Jeff Brown4d396052010-10-29 21:50:21 -07005536 }
5537 break;
5538 }
5539
Jeff Brown6212a492014-03-07 13:58:47 -08005540 case KeyEvent.KEYCODE_SLEEP: {
5541 result &= ~ACTION_PASS_TO_USER;
Filip Gruszczynskia483a1d2015-03-17 19:06:58 +00005542 isWakeKey = false;
Jeff Brownbae8e772014-06-12 19:59:45 -07005543 if (!mPowerManager.isInteractive()) {
5544 useHapticFeedback = false; // suppress feedback if already non-interactive
5545 }
Nick Vaccarob593a812015-05-15 11:23:05 -07005546 if (down) {
5547 sleepPress(event.getEventTime());
5548 } else {
5549 sleepRelease(event.getEventTime());
5550 }
Jeff Brown6212a492014-03-07 13:58:47 -08005551 break;
5552 }
5553
Nick Armstrong-Crews56ecfcc2015-09-07 21:46:50 -07005554 case KeyEvent.KEYCODE_SOFT_SLEEP: {
5555 result &= ~ACTION_PASS_TO_USER;
5556 isWakeKey = false;
5557 if (!down) {
5558 mPowerManagerInternal.setUserInactiveOverrideFromWindowManager();
5559 }
5560 break;
5561 }
5562
Jeff Brown6212a492014-03-07 13:58:47 -08005563 case KeyEvent.KEYCODE_WAKEUP: {
5564 result &= ~ACTION_PASS_TO_USER;
Jose Lima9546b202014-07-02 17:21:51 -07005565 isWakeKey = true;
Jeff Brown6212a492014-03-07 13:58:47 -08005566 break;
5567 }
5568
Jeff Brown4d396052010-10-29 21:50:21 -07005569 case KeyEvent.KEYCODE_MEDIA_PLAY:
5570 case KeyEvent.KEYCODE_MEDIA_PAUSE:
5571 case KeyEvent.KEYCODE_MEDIA_PLAY_PAUSE:
Jeff Brown4d396052010-10-29 21:50:21 -07005572 case KeyEvent.KEYCODE_HEADSETHOOK:
5573 case KeyEvent.KEYCODE_MUTE:
5574 case KeyEvent.KEYCODE_MEDIA_STOP:
5575 case KeyEvent.KEYCODE_MEDIA_NEXT:
5576 case KeyEvent.KEYCODE_MEDIA_PREVIOUS:
5577 case KeyEvent.KEYCODE_MEDIA_REWIND:
5578 case KeyEvent.KEYCODE_MEDIA_RECORD:
Jaekyun Seokbfdad8e2013-07-08 13:53:21 +09005579 case KeyEvent.KEYCODE_MEDIA_FAST_FORWARD:
5580 case KeyEvent.KEYCODE_MEDIA_AUDIO_TRACK: {
RoboErikde9ba392014-09-26 12:51:01 -07005581 if (MediaSessionLegacyHelper.getHelper(mContext).isGlobalPriorityActive()) {
5582 // If the global session is active pass all media keys to it
5583 // instead of the active window.
5584 result &= ~ACTION_PASS_TO_USER;
5585 }
Jeff Brown4d396052010-10-29 21:50:21 -07005586 if ((result & ACTION_PASS_TO_USER) == 0) {
5587 // Only do this if we would otherwise not pass it to the user. In that
5588 // case, the PhoneWindow class will do the same thing, except it will
5589 // only do it if the showing app doesn't process the key on its own.
Jeff Brown40013652012-05-16 21:22:36 -07005590 // Note that we need to make a copy of the key event here because the
5591 // original key event will be recycled when we return.
Jeff Brown4d396052010-10-29 21:50:21 -07005592 mBroadcastWakeLock.acquire();
Jeff Brown40013652012-05-16 21:22:36 -07005593 Message msg = mHandler.obtainMessage(MSG_DISPATCH_MEDIA_KEY_WITH_WAKE_LOCK,
5594 new KeyEvent(event));
5595 msg.setAsynchronous(true);
5596 msg.sendToTarget();
Jeff Brown4d396052010-10-29 21:50:21 -07005597 }
5598 break;
Jeff Brown00fa7bd2010-07-02 15:37:36 -07005599 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005600
Jeff Brown4d396052010-10-29 21:50:21 -07005601 case KeyEvent.KEYCODE_CALL: {
5602 if (down) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -07005603 TelecomManager telecomManager = getTelecommService();
5604 if (telecomManager != null) {
5605 if (telecomManager.isRinging()) {
Santos Cordon6848f722014-05-21 15:22:12 -07005606 Log.i(TAG, "interceptKeyBeforeQueueing:"
5607 + " CALL key-down while ringing: Answer the call!");
Tyler Gunnef9f6f92014-09-12 22:16:17 -07005608 telecomManager.acceptRingingCall();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005609
Santos Cordon6848f722014-05-21 15:22:12 -07005610 // And *don't* pass this key thru to the current activity
5611 // (which is presumably the InCallScreen.)
5612 result &= ~ACTION_PASS_TO_USER;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005613 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005614 }
Jeff Brown00fa7bd2010-07-02 15:37:36 -07005615 }
Jeff Brown4d396052010-10-29 21:50:21 -07005616 break;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005617 }
Michael Wright869a67c2014-08-26 19:33:06 -07005618 case KeyEvent.KEYCODE_VOICE_ASSIST: {
5619 // Only do this if we would otherwise not pass it to the user. In that case,
5620 // interceptKeyBeforeDispatching would apply a similar but different policy in
5621 // order to invoke voice assist actions. Note that we need to make a copy of the
5622 // key event here because the original key event will be recycled when we return.
5623 if ((result & ACTION_PASS_TO_USER) == 0 && !down) {
5624 mBroadcastWakeLock.acquire();
5625 Message msg = mHandler.obtainMessage(MSG_LAUNCH_VOICE_ASSIST_WITH_WAKE_LOCK,
5626 keyguardActive ? 1 : 0, 0);
5627 msg.setAsynchronous(true);
5628 msg.sendToTarget();
5629 }
Jaewan Kim49117872016-01-19 17:24:08 +09005630 break;
5631 }
5632 case KeyEvent.KEYCODE_WINDOW: {
5633 if (mShortPressWindowBehavior == SHORT_PRESS_WINDOW_PICTURE_IN_PICTURE) {
5634 if (!down) {
Jaewan Kimc552b042016-01-18 16:08:45 +09005635 requestTvPictureInPicture(event);
Jaewan Kim49117872016-01-19 17:24:08 +09005636 }
5637 result &= ~ACTION_PASS_TO_USER;
5638 }
5639 break;
Michael Wright869a67c2014-08-26 19:33:06 -07005640 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005641 }
Jeff Brown26875502014-01-30 21:47:47 -08005642
Jeff Brownbae8e772014-06-12 19:59:45 -07005643 if (useHapticFeedback) {
5644 performHapticFeedbackLw(null, HapticFeedbackConstants.VIRTUAL_KEY, false);
5645 }
5646
Jeff Brown26875502014-01-30 21:47:47 -08005647 if (isWakeKey) {
Dianne Hackborn280a64e2015-07-13 14:48:08 -07005648 wakeUp(event.getEventTime(), mAllowTheaterModeWakeFromKey, "android.policy:KEY");
Jeff Brown26875502014-01-30 21:47:47 -08005649 }
Bryce Lee584a4452014-10-21 15:55:55 -07005650
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005651 return result;
5652 }
5653
Jeff Brown1c2e4942012-11-06 16:32:01 -08005654 /**
Jeff Brown13f00f02014-10-31 14:45:50 -07005655 * Returns true if the key can have global actions attached to it.
5656 * We reserve all power management keys for the system since they require
5657 * very careful handling.
5658 */
5659 private static boolean isValidGlobalKey(int keyCode) {
5660 switch (keyCode) {
5661 case KeyEvent.KEYCODE_POWER:
5662 case KeyEvent.KEYCODE_WAKEUP:
5663 case KeyEvent.KEYCODE_SLEEP:
5664 return false;
5665 default:
5666 return true;
5667 }
5668 }
5669
5670 /**
Jeff Brown1c2e4942012-11-06 16:32:01 -08005671 * When the screen is off we ignore some keys that might otherwise typically
5672 * be considered wake keys. We filter them out here.
5673 *
5674 * {@link KeyEvent#KEYCODE_POWER} is notably absent from this list because it
5675 * is always considered a wake key.
5676 */
5677 private boolean isWakeKeyWhenScreenOff(int keyCode) {
5678 switch (keyCode) {
5679 // ignore volume keys unless docked
5680 case KeyEvent.KEYCODE_VOLUME_UP:
5681 case KeyEvent.KEYCODE_VOLUME_DOWN:
5682 case KeyEvent.KEYCODE_VOLUME_MUTE:
5683 return mDockMode != Intent.EXTRA_DOCK_STATE_UNDOCKED;
5684
5685 // ignore media and camera keys
5686 case KeyEvent.KEYCODE_MUTE:
5687 case KeyEvent.KEYCODE_HEADSETHOOK:
5688 case KeyEvent.KEYCODE_MEDIA_PLAY:
5689 case KeyEvent.KEYCODE_MEDIA_PAUSE:
5690 case KeyEvent.KEYCODE_MEDIA_PLAY_PAUSE:
5691 case KeyEvent.KEYCODE_MEDIA_STOP:
5692 case KeyEvent.KEYCODE_MEDIA_NEXT:
5693 case KeyEvent.KEYCODE_MEDIA_PREVIOUS:
5694 case KeyEvent.KEYCODE_MEDIA_REWIND:
5695 case KeyEvent.KEYCODE_MEDIA_RECORD:
5696 case KeyEvent.KEYCODE_MEDIA_FAST_FORWARD:
Jaekyun Seokbfdad8e2013-07-08 13:53:21 +09005697 case KeyEvent.KEYCODE_MEDIA_AUDIO_TRACK:
Jeff Brown1c2e4942012-11-06 16:32:01 -08005698 case KeyEvent.KEYCODE_CAMERA:
5699 return false;
5700 }
5701 return true;
5702 }
5703
5704
Jeff Brown56194eb2011-03-02 19:23:13 -08005705 /** {@inheritDoc} */
5706 @Override
Michael Wright70af00a2014-09-03 19:30:20 -07005707 public int interceptMotionBeforeQueueingNonInteractive(long whenNanos, int policyFlags) {
5708 if ((policyFlags & FLAG_WAKE) != 0) {
Dianne Hackborn280a64e2015-07-13 14:48:08 -07005709 if (wakeUp(whenNanos / 1000000, mAllowTheaterModeWakeFromMotion,
5710 "android.policy:MOTION")) {
Bryce Lee5c138322014-11-03 08:26:09 -08005711 return 0;
5712 }
Michael Wright70af00a2014-09-03 19:30:20 -07005713 }
Bryce Lee5c138322014-11-03 08:26:09 -08005714
Michael Wright70af00a2014-09-03 19:30:20 -07005715 if (shouldDispatchInputWhenNonInteractive()) {
5716 return ACTION_PASS_TO_USER;
5717 }
Bryce Lee5c138322014-11-03 08:26:09 -08005718
Bryce Lee812d7022014-11-10 13:33:28 -08005719 // If we have not passed the action up and we are in theater mode without dreaming,
5720 // there will be no dream to intercept the touch and wake into ambient. The device should
5721 // wake up in this case.
5722 if (isTheaterModeEnabled() && (policyFlags & FLAG_WAKE) != 0) {
Dianne Hackborn280a64e2015-07-13 14:48:08 -07005723 wakeUp(whenNanos / 1000000, mAllowTheaterModeWakeFromMotionWhenNotDreaming,
5724 "android.policy:MOTION");
Bryce Lee812d7022014-11-10 13:33:28 -08005725 }
5726
Jeff Brown037c33e2014-04-09 00:31:55 -07005727 return 0;
Jeff Brown56194eb2011-03-02 19:23:13 -08005728 }
5729
Michael Wright70af00a2014-09-03 19:30:20 -07005730 private boolean shouldDispatchInputWhenNonInteractive() {
Joe LaPennaf2b9b2d2015-11-17 22:22:37 +00005731 // Send events to keyguard while the screen is on.
5732 if (isKeyguardShowingAndNotOccluded() && mDisplay != null
5733 && mDisplay.getState() != Display.STATE_OFF) {
Bryce Lee5c138322014-11-03 08:26:09 -08005734 return true;
5735 }
5736
5737 // Send events to a dozing dream even if the screen is off since the dream
5738 // is in control of the state of the screen.
5739 IDreamManager dreamManager = getDreamManager();
5740
5741 try {
5742 if (dreamManager != null && dreamManager.isDreaming()) {
5743 return true;
5744 }
5745 } catch (RemoteException e) {
5746 Slog.e(TAG, "RemoteException when checking if dreaming", e);
5747 }
5748
5749 // Otherwise, consume events since the user can't see what is being
5750 // interacted with.
5751 return false;
Michael Wright70af00a2014-09-03 19:30:20 -07005752 }
5753
RoboErik001c59c2015-01-26 15:53:51 -08005754 private void dispatchDirectAudioEvent(KeyEvent event) {
5755 if (event.getAction() != KeyEvent.ACTION_DOWN) {
5756 return;
5757 }
5758 int keyCode = event.getKeyCode();
John Spurlockb94f2d62015-03-17 14:11:57 -04005759 int flags = AudioManager.FLAG_SHOW_UI | AudioManager.FLAG_PLAY_SOUND
5760 | AudioManager.FLAG_FROM_KEY;
RoboErik001c59c2015-01-26 15:53:51 -08005761 String pkgName = mContext.getOpPackageName();
5762 switch (keyCode) {
5763 case KeyEvent.KEYCODE_VOLUME_UP:
5764 try {
John Spurlockee5ad722015-03-03 16:17:21 -05005765 getAudioService().adjustSuggestedStreamVolume(AudioManager.ADJUST_RAISE,
John Spurlock90874332015-03-10 16:00:54 -04005766 AudioManager.USE_DEFAULT_STREAM_TYPE, flags, pkgName, TAG);
RoboErik001c59c2015-01-26 15:53:51 -08005767 } catch (RemoteException e) {
5768 Log.e(TAG, "Error dispatching volume up in dispatchTvAudioEvent.", e);
5769 }
5770 break;
5771 case KeyEvent.KEYCODE_VOLUME_DOWN:
5772 try {
John Spurlockee5ad722015-03-03 16:17:21 -05005773 getAudioService().adjustSuggestedStreamVolume(AudioManager.ADJUST_LOWER,
John Spurlock90874332015-03-10 16:00:54 -04005774 AudioManager.USE_DEFAULT_STREAM_TYPE, flags, pkgName, TAG);
RoboErik001c59c2015-01-26 15:53:51 -08005775 } catch (RemoteException e) {
5776 Log.e(TAG, "Error dispatching volume down in dispatchTvAudioEvent.", e);
5777 }
5778 break;
5779 case KeyEvent.KEYCODE_VOLUME_MUTE:
5780 try {
5781 if (event.getRepeatCount() == 0) {
John Spurlockee5ad722015-03-03 16:17:21 -05005782 getAudioService().adjustSuggestedStreamVolume(
5783 AudioManager.ADJUST_TOGGLE_MUTE,
John Spurlock90874332015-03-10 16:00:54 -04005784 AudioManager.USE_DEFAULT_STREAM_TYPE, flags, pkgName, TAG);
RoboErik001c59c2015-01-26 15:53:51 -08005785 }
5786 } catch (RemoteException e) {
5787 Log.e(TAG, "Error dispatching mute in dispatchTvAudioEvent.", e);
5788 }
5789 break;
5790 }
5791 }
5792
Jeff Brown40013652012-05-16 21:22:36 -07005793 void dispatchMediaKeyWithWakeLock(KeyEvent event) {
5794 if (DEBUG_INPUT) {
5795 Slog.d(TAG, "dispatchMediaKeyWithWakeLock: " + event);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005796 }
5797
Jeff Brown40013652012-05-16 21:22:36 -07005798 if (mHavePendingMediaKeyRepeatWithWakeLock) {
5799 if (DEBUG_INPUT) {
5800 Slog.d(TAG, "dispatchMediaKeyWithWakeLock: canceled repeat");
5801 }
5802
5803 mHandler.removeMessages(MSG_DISPATCH_MEDIA_KEY_REPEAT_WITH_WAKE_LOCK);
5804 mHavePendingMediaKeyRepeatWithWakeLock = false;
5805 mBroadcastWakeLock.release(); // pending repeat was holding onto the wake lock
5806 }
5807
5808 dispatchMediaKeyWithWakeLockToAudioService(event);
5809
5810 if (event.getAction() == KeyEvent.ACTION_DOWN
5811 && event.getRepeatCount() == 0) {
5812 mHavePendingMediaKeyRepeatWithWakeLock = true;
5813
5814 Message msg = mHandler.obtainMessage(
5815 MSG_DISPATCH_MEDIA_KEY_REPEAT_WITH_WAKE_LOCK, event);
5816 msg.setAsynchronous(true);
5817 mHandler.sendMessageDelayed(msg, ViewConfiguration.getKeyRepeatTimeout());
5818 } else {
5819 mBroadcastWakeLock.release();
5820 }
5821 }
5822
5823 void dispatchMediaKeyRepeatWithWakeLock(KeyEvent event) {
5824 mHavePendingMediaKeyRepeatWithWakeLock = false;
5825
5826 KeyEvent repeatEvent = KeyEvent.changeTimeRepeat(event,
5827 SystemClock.uptimeMillis(), 1, event.getFlags() | KeyEvent.FLAG_LONG_PRESS);
5828 if (DEBUG_INPUT) {
5829 Slog.d(TAG, "dispatchMediaKeyRepeatWithWakeLock: " + repeatEvent);
5830 }
5831
5832 dispatchMediaKeyWithWakeLockToAudioService(repeatEvent);
5833 mBroadcastWakeLock.release();
5834 }
5835
5836 void dispatchMediaKeyWithWakeLockToAudioService(KeyEvent event) {
5837 if (ActivityManagerNative.isSystemReady()) {
RoboErik430fc482014-06-12 15:49:20 -07005838 MediaSessionLegacyHelper.getHelper(mContext).sendMediaButtonEvent(event, true);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005839 }
5840 }
5841
Michael Wright869a67c2014-08-26 19:33:06 -07005842 void launchVoiceAssistWithWakeLock(boolean keyguardActive) {
Dianne Hackbornb6683c42015-06-18 17:40:33 -07005843 IDeviceIdleController dic = IDeviceIdleController.Stub.asInterface(
5844 ServiceManager.getService(Context.DEVICE_IDLE_CONTROLLER));
5845 if (dic != null) {
5846 try {
5847 dic.exitIdle("voice-search");
5848 } catch (RemoteException e) {
5849 }
5850 }
Michael Wright869a67c2014-08-26 19:33:06 -07005851 Intent voiceIntent =
5852 new Intent(RecognizerIntent.ACTION_VOICE_SEARCH_HANDS_FREE);
5853 voiceIntent.putExtra(RecognizerIntent.EXTRA_SECURE, keyguardActive);
Bart Sears8b1c27c2015-03-18 23:51:02 +00005854 startActivityAsUser(voiceIntent, UserHandle.CURRENT_OR_SELF);
Michael Wright869a67c2014-08-26 19:33:06 -07005855 mBroadcastWakeLock.release();
5856 }
5857
Mike Lockwood1753f7f2009-08-24 14:49:07 -07005858 BroadcastReceiver mDockReceiver = new BroadcastReceiver() {
Craig Mautnereee29c42013-01-17 14:44:34 -08005859 @Override
Mike Lockwood1753f7f2009-08-24 14:49:07 -07005860 public void onReceive(Context context, Intent intent) {
Dianne Hackborn867ab6472010-04-29 13:28:56 -07005861 if (Intent.ACTION_DOCK_EVENT.equals(intent.getAction())) {
5862 mDockMode = intent.getIntExtra(Intent.EXTRA_DOCK_STATE,
5863 Intent.EXTRA_DOCK_STATE_UNDOCKED);
Daniel Sandler6396c722013-04-16 20:19:09 -04005864 } else {
5865 try {
5866 IUiModeManager uiModeService = IUiModeManager.Stub.asInterface(
5867 ServiceManager.getService(Context.UI_MODE_SERVICE));
5868 mUiMode = uiModeService.getCurrentModeType();
5869 } catch (RemoteException e) {
5870 }
Dianne Hackborn80fa1662009-10-07 14:02:10 -07005871 }
Jeff Brown01a98dd2011-09-20 15:08:29 -07005872 updateRotation(true);
Craig Mautnereee29c42013-01-17 14:44:34 -08005873 synchronized (mLock) {
5874 updateOrientationListenerLp();
5875 }
Mike Lockwood1753f7f2009-08-24 14:49:07 -07005876 }
5877 };
5878
Jeff Brown6aaf2952012-10-05 16:01:08 -07005879 BroadcastReceiver mDreamReceiver = new BroadcastReceiver() {
5880 @Override
5881 public void onReceive(Context context, Intent intent) {
5882 if (Intent.ACTION_DREAMING_STARTED.equals(intent.getAction())) {
Jim Miller5ecd8112013-01-09 18:50:26 -08005883 if (mKeyguardDelegate != null) {
5884 mKeyguardDelegate.onDreamingStarted();
Jeff Brown6aaf2952012-10-05 16:01:08 -07005885 }
5886 } else if (Intent.ACTION_DREAMING_STOPPED.equals(intent.getAction())) {
Jim Miller5ecd8112013-01-09 18:50:26 -08005887 if (mKeyguardDelegate != null) {
5888 mKeyguardDelegate.onDreamingStopped();
Jeff Brown6aaf2952012-10-05 16:01:08 -07005889 }
5890 }
5891 }
5892 };
5893
Christopher Tate5e08af02012-09-21 17:17:22 -07005894 BroadcastReceiver mMultiuserReceiver = new BroadcastReceiver() {
5895 @Override
5896 public void onReceive(Context context, Intent intent) {
5897 if (Intent.ACTION_USER_SWITCHED.equals(intent.getAction())) {
5898 // tickle the settings observer: this first ensures that we're
5899 // observing the relevant settings for the newly-active user,
5900 // and then updates our own bookkeeping based on the now-
5901 // current user.
5902 mSettingsObserver.onChange(false);
John Spurlockce479d82012-11-29 09:52:21 -05005903
5904 // force a re-application of focused window sysui visibility.
5905 // the window may never have been shown for this user
5906 // e.g. the keyguard when going through the new-user setup flow
John Spurlock04db1762013-05-13 12:46:41 -04005907 synchronized (mWindowManagerFuncs.getWindowManagerLock()) {
John Spurlockce479d82012-11-29 09:52:21 -05005908 mLastSystemUiFlags = 0;
5909 updateSystemUiVisibilityLw();
5910 }
Christopher Tate5e08af02012-09-21 17:17:22 -07005911 }
5912 }
5913 };
5914
Adrian Roosddc8b272015-05-21 16:28:27 -07005915 private final Runnable mHiddenNavPanic = new Runnable() {
John Spurlockd9b70bd2014-02-06 17:02:44 -05005916 @Override
5917 public void run() {
Adrian Roosddc8b272015-05-21 16:28:27 -07005918 synchronized (mWindowManagerFuncs.getWindowManagerLock()) {
5919 if (!isUserSetupComplete()) {
5920 // Swipe-up for navigation bar is disabled during setup
5921 return;
5922 }
5923 mPendingPanicGestureUptime = SystemClock.uptimeMillis();
5924 mNavigationBarController.showTransient();
5925 }
John Spurlockd9b70bd2014-02-06 17:02:44 -05005926 }
5927 };
5928
John Spurlocke1f366f2013-08-05 12:22:40 -04005929 private void requestTransientBars(WindowState swipeTarget) {
John Spurlock04db1762013-05-13 12:46:41 -04005930 synchronized (mWindowManagerFuncs.getWindowManagerLock()) {
Maurice Lam99c6e072014-04-28 18:24:28 -07005931 if (!isUserSetupComplete()) {
5932 // Swipe-up for navigation bar is disabled during setup
5933 return;
5934 }
John Spurlock27735a42013-08-14 17:57:38 -04005935 boolean sb = mStatusBarController.checkShowTransientBarLw();
5936 boolean nb = mNavigationBarController.checkShowTransientBarLw();
John Spurlockad3e6cb2013-04-30 08:47:43 -04005937 if (sb || nb) {
Adrian Roos62b65e42015-02-25 18:05:34 +01005938 // Don't show status bar when swiping on already visible navigation bar
5939 if (!nb && swipeTarget == mNavigationBar) {
John Spurlocke1f366f2013-08-05 12:22:40 -04005940 if (DEBUG) Slog.d(TAG, "Not showing transient bar, wrong swipe target");
John Spurlockad3e6cb2013-04-30 08:47:43 -04005941 return;
5942 }
John Spurlock27735a42013-08-14 17:57:38 -04005943 if (sb) mStatusBarController.showTransient();
5944 if (nb) mNavigationBarController.showTransient();
John Spurlockf1a36642013-10-12 17:50:42 -04005945 mImmersiveModeConfirmation.confirmCurrentPrompt();
John Spurlockad3e6cb2013-04-30 08:47:43 -04005946 updateSystemUiVisibilityLw();
John Spurlock32beb2c2013-03-11 10:16:47 -04005947 }
John Spurlockad3e6cb2013-04-30 08:47:43 -04005948 }
5949 }
5950
Jeff Brown3ee549c2014-09-22 20:14:39 -07005951 // Called on the PowerManager's Notifier thread.
Jeff Brownc38c9be2012-10-04 13:16:19 -07005952 @Override
Jeff Brown416c49c2015-05-26 19:50:18 -07005953 public void startedGoingToSleep(int why) {
5954 if (DEBUG_WAKEUP) Slog.i(TAG, "Started going to sleep... (why=" + why + ")");
Jorim Jaggid175b6c2015-05-27 15:39:09 -07005955 if (mKeyguardDelegate != null) {
5956 mKeyguardDelegate.onStartedGoingToSleep(why);
5957 }
Jeff Brown416c49c2015-05-26 19:50:18 -07005958 }
5959
5960 // Called on the PowerManager's Notifier thread.
5961 @Override
5962 public void finishedGoingToSleep(int why) {
Dianne Hackborn74489012009-03-24 20:50:09 -07005963 EventLog.writeEvent(70000, 0);
Jeff Brown416c49c2015-05-26 19:50:18 -07005964 if (DEBUG_WAKEUP) Slog.i(TAG, "Finished going to sleep... (why=" + why + ")");
Chris Wren9bb290b2015-06-29 12:02:13 -04005965 MetricsLogger.histogram(mContext, "screen_timeout", mLockScreenTimeout / 1000);
Jeff Brown3ee549c2014-09-22 20:14:39 -07005966
5967 // We must get this work done here because the power manager will drop
5968 // the wake lock and let the system suspend once this function returns.
The Android Open Source Project0727d222009-03-11 12:11:58 -07005969 synchronized (mLock) {
Jeff Brown3ee549c2014-09-22 20:14:39 -07005970 mAwake = false;
Jeff Browna20dda42014-05-27 20:57:24 -07005971 updateWakeGestureListenerLp();
The Android Open Source Project0727d222009-03-11 12:11:58 -07005972 updateOrientationListenerLp();
Mike Lockwood28569302010-01-28 11:54:40 -05005973 updateLockScreenTimeout();
The Android Open Source Project0727d222009-03-11 12:11:58 -07005974 }
Jeff Brown3ee549c2014-09-22 20:14:39 -07005975 if (mKeyguardDelegate != null) {
Jorim Jaggid175b6c2015-05-27 15:39:09 -07005976 mKeyguardDelegate.onFinishedGoingToSleep(why);
Jeff Brown3ee549c2014-09-22 20:14:39 -07005977 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005978 }
5979
Jeff Brown3ee549c2014-09-22 20:14:39 -07005980 // Called on the PowerManager's Notifier thread.
Jeff Brownc38c9be2012-10-04 13:16:19 -07005981 @Override
Jeff Brown416c49c2015-05-26 19:50:18 -07005982 public void startedWakingUp() {
Dianne Hackborn74489012009-03-24 20:50:09 -07005983 EventLog.writeEvent(70000, 1);
Jeff Brown416c49c2015-05-26 19:50:18 -07005984 if (DEBUG_WAKEUP) Slog.i(TAG, "Started waking up...");
Craig Mautner8a0da012014-05-31 15:13:37 -07005985
Jeff Brown3ee549c2014-09-22 20:14:39 -07005986 // Since goToSleep performs these functions synchronously, we must
5987 // do the same here. We cannot post this work to a handler because
5988 // that might cause it to become reordered with respect to what
5989 // may happen in a future call to goToSleep.
The Android Open Source Project0727d222009-03-11 12:11:58 -07005990 synchronized (mLock) {
Jeff Brown3ee549c2014-09-22 20:14:39 -07005991 mAwake = true;
Jeff Brown3ee549c2014-09-22 20:14:39 -07005992
Jeff Browna20dda42014-05-27 20:57:24 -07005993 updateWakeGestureListenerLp();
The Android Open Source Project0727d222009-03-11 12:11:58 -07005994 updateOrientationListenerLp();
Mike Lockwood28569302010-01-28 11:54:40 -05005995 updateLockScreenTimeout();
The Android Open Source Project0727d222009-03-11 12:11:58 -07005996 }
Jeff Brownc38c9be2012-10-04 13:16:19 -07005997
Jim Miller5ecd8112013-01-09 18:50:26 -08005998 if (mKeyguardDelegate != null) {
Jorim Jaggi4cfdcf52015-07-09 12:13:59 -07005999 mKeyguardDelegate.onStartedWakingUp();
Jeff Brownc38c9be2012-10-04 13:16:19 -07006000 }
Jeff Brown36c4db82014-09-19 12:05:31 -07006001 }
6002
Jeff Brown416c49c2015-05-26 19:50:18 -07006003 // Called on the PowerManager's Notifier thread.
6004 @Override
6005 public void finishedWakingUp() {
6006 if (DEBUG_WAKEUP) Slog.i(TAG, "Finished waking up...");
6007 }
6008
6009 private void wakeUpFromPowerKey(long eventTime) {
Dianne Hackborn280a64e2015-07-13 14:48:08 -07006010 wakeUp(eventTime, mAllowTheaterModeWakeFromPowerKey, "android.policy:POWER");
Jeff Brown416c49c2015-05-26 19:50:18 -07006011 }
6012
Dianne Hackborn280a64e2015-07-13 14:48:08 -07006013 private boolean wakeUp(long wakeTime, boolean wakeInTheaterMode, String reason) {
Bryce Leed3896842015-06-23 17:06:51 -07006014 final boolean theaterModeEnabled = isTheaterModeEnabled();
6015 if (!wakeInTheaterMode && theaterModeEnabled) {
Jeff Brown416c49c2015-05-26 19:50:18 -07006016 return false;
6017 }
6018
Bryce Leed3896842015-06-23 17:06:51 -07006019 if (theaterModeEnabled) {
6020 Settings.Global.putInt(mContext.getContentResolver(),
6021 Settings.Global.THEATER_MODE_ON, 0);
6022 }
6023
Dianne Hackborn280a64e2015-07-13 14:48:08 -07006024 mPowerManager.wakeUp(wakeTime, reason);
Jeff Brown416c49c2015-05-26 19:50:18 -07006025 return true;
6026 }
6027
Jeff Brown36c4db82014-09-19 12:05:31 -07006028 private void finishKeyguardDrawn() {
Jeff Brown3ee549c2014-09-22 20:14:39 -07006029 synchronized (mLock) {
Jorim Jaggif3255482015-07-24 12:32:42 -07006030 if (!mScreenOnEarly || mKeyguardDrawComplete) {
Stefan Kuhne9326dc12015-06-12 09:25:32 -10006031 return; // We are not awake yet or we have already informed of this event.
Jeff Brown3ee549c2014-09-22 20:14:39 -07006032 }
6033
Jeff Brown36c4db82014-09-19 12:05:31 -07006034 mKeyguardDrawComplete = true;
Jeff Brown3ee549c2014-09-22 20:14:39 -07006035 if (mKeyguardDelegate != null) {
6036 mHandler.removeMessages(MSG_KEYGUARD_DRAWN_TIMEOUT);
6037 }
Jorim Jaggi4cfdcf52015-07-09 12:13:59 -07006038 mWindowManagerDrawComplete = false;
Jeff Brown3ee549c2014-09-22 20:14:39 -07006039 }
6040
Jorim Jaggi4cfdcf52015-07-09 12:13:59 -07006041 // ... eventually calls finishWindowsDrawn which will finalize our screen turn on
6042 // as well as enabling the orientation change logic/sensor.
6043 mWindowManagerInternal.waitForAllWindowsDrawn(mWindowManagerDrawCallback,
6044 WAITING_FOR_DRAWN_TIMEOUT);
Jeff Brown3ee549c2014-09-22 20:14:39 -07006045 }
6046
6047 // Called on the DisplayManager's DisplayPowerController thread.
6048 @Override
6049 public void screenTurnedOff() {
6050 if (DEBUG_WAKEUP) Slog.i(TAG, "Screen turned off...");
6051
Jeff Brown48d1b142015-06-10 16:36:03 -07006052 updateScreenOffSleepToken(true);
Jeff Brown3ee549c2014-09-22 20:14:39 -07006053 synchronized (mLock) {
6054 mScreenOnEarly = false;
6055 mScreenOnFully = false;
Jorim Jaggi95c6dae2015-07-29 15:17:23 -07006056 mKeyguardDrawComplete = false;
Jeff Brown3ee549c2014-09-22 20:14:39 -07006057 mWindowManagerDrawComplete = false;
6058 mScreenOnListener = null;
6059 updateOrientationListenerLp();
Jorim Jaggi0d210f62015-07-10 14:24:44 -07006060
6061 if (mKeyguardDelegate != null) {
6062 mKeyguardDelegate.onScreenTurnedOff();
6063 }
Jeff Brown36c4db82014-09-19 12:05:31 -07006064 }
6065 }
6066
Jeff Brown3ee549c2014-09-22 20:14:39 -07006067 // Called on the DisplayManager's DisplayPowerController thread.
Jeff Brown36c4db82014-09-19 12:05:31 -07006068 @Override
6069 public void screenTurningOn(final ScreenOnListener screenOnListener) {
Jeff Brown36c4db82014-09-19 12:05:31 -07006070 if (DEBUG_WAKEUP) Slog.i(TAG, "Screen turning on...");
Jeff Brown36c4db82014-09-19 12:05:31 -07006071
Jeff Brown48d1b142015-06-10 16:36:03 -07006072 updateScreenOffSleepToken(false);
Jeff Brown3ee549c2014-09-22 20:14:39 -07006073 synchronized (mLock) {
6074 mScreenOnEarly = true;
6075 mScreenOnFully = false;
Jorim Jaggi95c6dae2015-07-29 15:17:23 -07006076 mKeyguardDrawComplete = false;
Jeff Brown3ee549c2014-09-22 20:14:39 -07006077 mWindowManagerDrawComplete = false;
6078 mScreenOnListener = screenOnListener;
Jeff Brown36c4db82014-09-19 12:05:31 -07006079
Jorim Jaggi4cfdcf52015-07-09 12:13:59 -07006080 if (mKeyguardDelegate != null) {
Jorim Jaggia4b51bc2015-08-10 18:20:43 -07006081 mHandler.removeMessages(MSG_KEYGUARD_DRAWN_TIMEOUT);
6082 mHandler.sendEmptyMessageDelayed(MSG_KEYGUARD_DRAWN_TIMEOUT, 1000);
Jorim Jaggi4cfdcf52015-07-09 12:13:59 -07006083 mKeyguardDelegate.onScreenTurningOn(mKeyguardDrawnCallback);
6084 } else {
6085 if (DEBUG_WAKEUP) Slog.d(TAG,
6086 "null mKeyguardDelegate: setting mKeyguardDrawComplete.");
6087 finishKeyguardDrawn();
6088 }
6089 }
Jeff Brown36c4db82014-09-19 12:05:31 -07006090 }
6091
Jorim Jaggi0d210f62015-07-10 14:24:44 -07006092 // Called on the DisplayManager's DisplayPowerController thread.
6093 @Override
6094 public void screenTurnedOn() {
6095 synchronized (mLock) {
6096 if (mKeyguardDelegate != null) {
6097 mKeyguardDelegate.onScreenTurnedOn();
6098 }
6099 }
6100 }
6101
Jeff Brown36c4db82014-09-19 12:05:31 -07006102 private void finishWindowsDrawn() {
Jeff Brown3ee549c2014-09-22 20:14:39 -07006103 synchronized (mLock) {
6104 if (!mScreenOnEarly || mWindowManagerDrawComplete) {
Stefan Kuhne9326dc12015-06-12 09:25:32 -10006105 return; // Screen is not turned on or we did already handle this case earlier.
Jeff Brown3ee549c2014-09-22 20:14:39 -07006106 }
6107
Jeff Brown36c4db82014-09-19 12:05:31 -07006108 mWindowManagerDrawComplete = true;
Jeff Brown36c4db82014-09-19 12:05:31 -07006109 }
Jeff Brown3ee549c2014-09-22 20:14:39 -07006110
6111 finishScreenTurningOn();
Jeff Brownc38c9be2012-10-04 13:16:19 -07006112 }
6113
Craig Mautner8a0da012014-05-31 15:13:37 -07006114 private void finishScreenTurningOn() {
Stefan Kuhne9326dc12015-06-12 09:25:32 -10006115 synchronized (mLock) {
6116 // We have just finished drawing screen content. Since the orientation listener
6117 // gets only installed when all windows are drawn, we try to install it again.
6118 updateOrientationListenerLp();
6119 }
Jeff Brown3ee549c2014-09-22 20:14:39 -07006120 final ScreenOnListener listener;
6121 final boolean enableScreen;
Jeff Brown36c4db82014-09-19 12:05:31 -07006122 synchronized (mLock) {
Jeff Brown3ee549c2014-09-22 20:14:39 -07006123 if (DEBUG_WAKEUP) Slog.d(TAG,
6124 "finishScreenTurningOn: mAwake=" + mAwake
6125 + ", mScreenOnEarly=" + mScreenOnEarly
6126 + ", mScreenOnFully=" + mScreenOnFully
6127 + ", mKeyguardDrawComplete=" + mKeyguardDrawComplete
6128 + ", mWindowManagerDrawComplete=" + mWindowManagerDrawComplete);
6129
6130 if (mScreenOnFully || !mScreenOnEarly || !mWindowManagerDrawComplete
6131 || (mAwake && !mKeyguardDrawComplete)) {
6132 return; // spurious or not ready yet
Jeff Brown36c4db82014-09-19 12:05:31 -07006133 }
6134
Jeff Brown3ee549c2014-09-22 20:14:39 -07006135 if (DEBUG_WAKEUP) Slog.i(TAG, "Finished screen turning on...");
6136 listener = mScreenOnListener;
Craig Mautner13f6ea72014-06-23 14:57:02 -07006137 mScreenOnListener = null;
Jeff Brown3ee549c2014-09-22 20:14:39 -07006138 mScreenOnFully = true;
6139
6140 // Remember the first time we draw the keyguard so we know when we're done with
6141 // the main part of booting and can enable the screen and hide boot messages.
6142 if (!mKeyguardDrawnOnce && mAwake) {
6143 mKeyguardDrawnOnce = true;
6144 enableScreen = true;
6145 if (mBootMessageNeedsHiding) {
6146 mBootMessageNeedsHiding = false;
6147 hideBootMessages();
6148 }
6149 } else {
6150 enableScreen = false;
6151 }
Jeff Brownc38c9be2012-10-04 13:16:19 -07006152 }
6153
Jeff Brown3ee549c2014-09-22 20:14:39 -07006154 if (listener != null) {
6155 listener.onScreenOn();
6156 }
Jeff Brown4fc45272012-10-10 18:28:14 -07006157
Jeff Brown3ee549c2014-09-22 20:14:39 -07006158 if (enableScreen) {
6159 try {
6160 mWindowManager.enableScreenIfNeeded();
6161 } catch (RemoteException unhandled) {
Jeff Brown36c4db82014-09-19 12:05:31 -07006162 }
Craig Mautnera631d492014-08-05 15:16:01 -07006163 }
6164 }
6165
6166 private void handleHideBootMessage() {
Jeff Brown3ee549c2014-09-22 20:14:39 -07006167 synchronized (mLock) {
6168 if (!mKeyguardDrawnOnce) {
6169 mBootMessageNeedsHiding = true;
6170 return; // keyguard hasn't drawn the first time yet, not done booting
6171 }
Craig Mautnera631d492014-08-05 15:16:01 -07006172 }
Jeff Brown3ee549c2014-09-22 20:14:39 -07006173
6174 if (mBootMsgDialog != null) {
6175 if (DEBUG_WAKEUP) Slog.d(TAG, "handleHideBootMessage: dismissing");
6176 mBootMsgDialog.dismiss();
6177 mBootMsgDialog = null;
Craig Mautnera631d492014-08-05 15:16:01 -07006178 }
Jeff Brownc38c9be2012-10-04 13:16:19 -07006179 }
6180
6181 @Override
Jeff Brown3ee549c2014-09-22 20:14:39 -07006182 public boolean isScreenOn() {
6183 return mScreenOnFully;
Dianne Hackborn08743722009-12-21 12:16:51 -08006184 }
Jeff Brownc38c9be2012-10-04 13:16:19 -07006185
Dianne Hackborn08743722009-12-21 12:16:51 -08006186 /** {@inheritDoc} */
Jose Lima9546b202014-07-02 17:21:51 -07006187 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006188 public void enableKeyguard(boolean enabled) {
Jim Miller5ecd8112013-01-09 18:50:26 -08006189 if (mKeyguardDelegate != null) {
6190 mKeyguardDelegate.setKeyguardEnabled(enabled);
Mike Lockwood3a74bd32011-08-12 13:55:22 -07006191 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006192 }
6193
6194 /** {@inheritDoc} */
Jose Lima9546b202014-07-02 17:21:51 -07006195 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006196 public void exitKeyguardSecurely(OnKeyguardExitResult callback) {
Jim Miller5ecd8112013-01-09 18:50:26 -08006197 if (mKeyguardDelegate != null) {
6198 mKeyguardDelegate.verifyUnlock(callback);
Mike Lockwood3a74bd32011-08-12 13:55:22 -07006199 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006200 }
6201
Jim Millerab954542014-10-10 18:21:49 -07006202 private boolean isKeyguardShowingAndNotOccluded() {
Jim Miller5ecd8112013-01-09 18:50:26 -08006203 if (mKeyguardDelegate == null) return false;
Jim Millerab954542014-10-10 18:21:49 -07006204 return mKeyguardDelegate.isShowing() && !mKeyguardOccluded;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006205 }
6206
Mike Lockwood520d8bc2011-02-18 13:23:13 -05006207 /** {@inheritDoc} */
Jose Lima9546b202014-07-02 17:21:51 -07006208 @Override
Mike Lockwood520d8bc2011-02-18 13:23:13 -05006209 public boolean isKeyguardLocked() {
6210 return keyguardOn();
6211 }
6212
6213 /** {@inheritDoc} */
Jose Lima9546b202014-07-02 17:21:51 -07006214 @Override
Mike Lockwood520d8bc2011-02-18 13:23:13 -05006215 public boolean isKeyguardSecure() {
Jim Miller5ecd8112013-01-09 18:50:26 -08006216 if (mKeyguardDelegate == null) return false;
6217 return mKeyguardDelegate.isSecure();
Mike Lockwood520d8bc2011-02-18 13:23:13 -05006218 }
6219
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006220 /** {@inheritDoc} */
Jose Lima9546b202014-07-02 17:21:51 -07006221 @Override
Adrian Roos461829d2015-06-03 14:41:18 -07006222 public boolean isKeyguardShowingOrOccluded() {
6223 return mKeyguardDelegate == null ? false : mKeyguardDelegate.isShowing();
6224 }
6225
6226 /** {@inheritDoc} */
6227 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006228 public boolean inKeyguardRestrictedKeyInputMode() {
Jim Miller5ecd8112013-01-09 18:50:26 -08006229 if (mKeyguardDelegate == null) return false;
6230 return mKeyguardDelegate.isInputRestricted();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006231 }
6232
Jose Lima9546b202014-07-02 17:21:51 -07006233 @Override
Dianne Hackborn90c52de2011-09-23 12:57:44 -07006234 public void dismissKeyguardLw() {
RoboErik8a2cfc32014-05-16 11:19:38 -07006235 if (mKeyguardDelegate != null && mKeyguardDelegate.isShowing()) {
Craig Mautnerc0d2d0a2014-10-31 16:25:15 -07006236 if (DEBUG_KEYGUARD) Slog.d(TAG, "PWM.dismissKeyguardLw");
Daniel Sandler1ce804392012-11-07 15:07:12 -05006237 mHandler.post(new Runnable() {
Jose Lima9546b202014-07-02 17:21:51 -07006238 @Override
Daniel Sandler1ce804392012-11-07 15:07:12 -05006239 public void run() {
Jorim Jaggi8de4311c2014-08-11 22:36:20 +02006240 // ask the keyguard to prompt the user to authenticate if necessary
6241 mKeyguardDelegate.dismiss();
6242 }
6243 });
6244 }
6245 }
6246
6247 public void notifyActivityDrawnForKeyguardLw() {
6248 if (mKeyguardDelegate != null) {
6249 mHandler.post(new Runnable() {
6250 @Override
6251 public void run() {
6252 mKeyguardDelegate.onActivityDrawn();
Daniel Sandler1ce804392012-11-07 15:07:12 -05006253 }
6254 });
Dianne Hackborn90c52de2011-09-23 12:57:44 -07006255 }
6256 }
6257
Jorim Jaggicff0acb2014-03-31 16:35:15 +02006258 @Override
6259 public boolean isKeyguardDrawnLw() {
6260 synchronized (mLock) {
Jeff Brown3ee549c2014-09-22 20:14:39 -07006261 return mKeyguardDrawnOnce;
Jorim Jaggicff0acb2014-03-31 16:35:15 +02006262 }
6263 }
6264
Jorim Jaggi0d674622014-05-21 01:34:15 +02006265 @Override
Jorim Jaggie29b2db2014-05-30 23:17:03 +02006266 public void startKeyguardExitAnimation(long startTime, long fadeoutDuration) {
Jorim Jaggi0d674622014-05-21 01:34:15 +02006267 if (mKeyguardDelegate != null) {
Craig Mautnerc0d2d0a2014-10-31 16:25:15 -07006268 if (DEBUG_KEYGUARD) Slog.d(TAG, "PWM.startKeyguardExitAnimation");
Jorim Jaggie29b2db2014-05-30 23:17:03 +02006269 mKeyguardDelegate.startKeyguardExitAnimation(startTime, fadeoutDuration);
Jorim Jaggi0d674622014-05-21 01:34:15 +02006270 }
6271 }
6272
Jorim Jaggi737af722015-12-31 10:42:27 +01006273 @Override
6274 public void getStableInsetsLw(int displayRotation, int displayWidth, int displayHeight,
6275 Rect outInsets) {
6276 outInsets.setEmpty();
Jorim Jaggi82c9dc92016-02-05 15:10:33 -08006277
6278 // Navigation bar and status bar.
6279 getNonDecorInsetsLw(displayRotation, displayWidth, displayHeight, outInsets);
Jorim Jaggi737af722015-12-31 10:42:27 +01006280 if (mStatusBar != null) {
6281 outInsets.top = mStatusBarHeight;
6282 }
Jorim Jaggi82c9dc92016-02-05 15:10:33 -08006283 }
6284
6285 @Override
6286 public void getNonDecorInsetsLw(int displayRotation, int displayWidth, int displayHeight,
6287 Rect outInsets) {
6288 outInsets.setEmpty();
6289
6290 // Only navigation bar
Jorim Jaggi737af722015-12-31 10:42:27 +01006291 if (mNavigationBar != null) {
6292 if (isNavigationBarOnBottom(displayWidth, displayHeight)) {
6293 outInsets.bottom = getNavigationBarHeight(displayRotation, mUiMode);
6294 } else {
6295 outInsets.right = getNavigationBarWidth(displayRotation, mUiMode);
6296 }
6297 }
6298 }
6299
Jorim Jaggi5060bd82016-02-19 17:12:19 -08006300 @Override
Jorim Jaggi0ffd49c2016-02-12 15:04:21 -08006301 public boolean isNavBarForcedShownLw(WindowState windowState) {
Jorim Jaggie5638a62016-03-25 22:57:01 -07006302 return mForceShowSystemBars;
Jorim Jaggi0ffd49c2016-02-12 15:04:21 -08006303 }
6304
6305 @Override
Jorim Jaggi5060bd82016-02-19 17:12:19 -08006306 public boolean isDockSideAllowed(int dockSide) {
6307
6308 // We do not allow all dock sides at which the navigation bar touches the docked stack.
6309 if (!mNavigationBarCanMove) {
6310 return dockSide == DOCKED_TOP || dockSide == DOCKED_LEFT || dockSide == DOCKED_RIGHT;
6311 } else {
6312 return dockSide == DOCKED_TOP || dockSide == DOCKED_LEFT;
6313 }
6314 }
6315
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006316 void sendCloseSystemWindows() {
Jorim Jaggib10e33f2015-02-04 21:57:40 +01006317 PhoneWindow.sendCloseSystemWindows(mContext, null);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006318 }
6319
6320 void sendCloseSystemWindows(String reason) {
Jorim Jaggib10e33f2015-02-04 21:57:40 +01006321 PhoneWindow.sendCloseSystemWindows(mContext, reason);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006322 }
Mitsuru Oshima831d0d92009-06-16 18:27:18 -07006323
Jeff Brown01a98dd2011-09-20 15:08:29 -07006324 @Override
6325 public int rotationForOrientationLw(int orientation, int lastRotation) {
Daniel Sandler2ed6ad62011-02-22 14:54:17 -05006326 if (false) {
6327 Slog.v(TAG, "rotationForOrientationLw(orient="
6328 + orientation + ", last=" + lastRotation
6329 + "); user=" + mUserRotation + " "
6330 + ((mUserRotationMode == WindowManagerPolicy.USER_ROTATION_LOCKED)
6331 ? "USER_ROTATION_LOCKED" : "")
6332 );
6333 }
6334
Craig Mautner46ac6fa2013-08-01 10:06:34 -07006335 if (mForceDefaultOrientation) {
6336 return Surface.ROTATION_0;
6337 }
6338
The Android Open Source Project0727d222009-03-11 12:11:58 -07006339 synchronized (mLock) {
Jeff Brownc0347aa2011-09-23 17:26:09 -07006340 int sensorRotation = mOrientationListener.getProposedRotation(); // may be -1
6341 if (sensorRotation < 0) {
Jeff Brown0f862b42012-09-27 21:11:01 -07006342 sensorRotation = lastRotation;
Jeff Brownc0347aa2011-09-23 17:26:09 -07006343 }
Jeff Brown01a98dd2011-09-20 15:08:29 -07006344
Jeff Browndec6cf42011-11-15 14:08:20 -08006345 final int preferredRotation;
Jeff Brown2e7760e2012-04-11 15:14:55 -07006346 if (mLidState == LID_OPEN && mLidOpenRotation >= 0) {
Jeff Brown01a98dd2011-09-20 15:08:29 -07006347 // Ignore sensor when lid switch is open and rotation is forced.
6348 preferredRotation = mLidOpenRotation;
6349 } else if (mDockMode == Intent.EXTRA_DOCK_STATE_CAR
Jeff Brownc0347aa2011-09-23 17:26:09 -07006350 && (mCarDockEnablesAccelerometer || mCarDockRotation >= 0)) {
Jeff Brown01a98dd2011-09-20 15:08:29 -07006351 // Ignore sensor when in car dock unless explicitly enabled.
6352 // This case can override the behavior of NOSENSOR, and can also
6353 // enable 180 degree rotation while docked.
Jeff Brownc0347aa2011-09-23 17:26:09 -07006354 preferredRotation = mCarDockEnablesAccelerometer
Jeff Brown01a98dd2011-09-20 15:08:29 -07006355 ? sensorRotation : mCarDockRotation;
Jeff Brown1a693182011-11-08 14:44:16 -08006356 } else if ((mDockMode == Intent.EXTRA_DOCK_STATE_DESK
6357 || mDockMode == Intent.EXTRA_DOCK_STATE_LE_DESK
6358 || mDockMode == Intent.EXTRA_DOCK_STATE_HE_DESK)
Jeff Brownc0347aa2011-09-23 17:26:09 -07006359 && (mDeskDockEnablesAccelerometer || mDeskDockRotation >= 0)) {
Jeff Brown01a98dd2011-09-20 15:08:29 -07006360 // Ignore sensor when in desk dock unless explicitly enabled.
6361 // This case can override the behavior of NOSENSOR, and can also
6362 // enable 180 degree rotation while docked.
Jeff Brownc0347aa2011-09-23 17:26:09 -07006363 preferredRotation = mDeskDockEnablesAccelerometer
Jeff Brown01a98dd2011-09-20 15:08:29 -07006364 ? sensorRotation : mDeskDockRotation;
Jeff Brownc82c89ed2013-04-17 17:18:15 -07006365 } else if (mHdmiPlugged && mDemoHdmiRotationLock) {
6366 // Ignore sensor when plugged into HDMI when demo HDMI rotation lock enabled.
Jeff Browneb3e4b92011-12-06 19:54:24 -08006367 // Note that the dock orientation overrides the HDMI orientation.
Jeff Brownc82c89ed2013-04-17 17:18:15 -07006368 preferredRotation = mDemoHdmiRotation;
6369 } else if (mHdmiPlugged && mDockMode == Intent.EXTRA_DOCK_STATE_UNDOCKED
6370 && mUndockedHdmiRotation >= 0) {
6371 // Ignore sensor when plugged into HDMI and an undocked orientation has
6372 // been specified in the configuration (only for legacy devices without
6373 // full multi-display support).
6374 // Note that the dock orientation overrides the HDMI orientation.
6375 preferredRotation = mUndockedHdmiRotation;
Chong Zhangae6119ff2014-11-11 18:54:39 -08006376 } else if (mDemoRotationLock) {
6377 // Ignore sensor when demo rotation lock is enabled.
6378 // Note that the dock orientation and HDMI rotation lock override this.
6379 preferredRotation = mDemoRotation;
Dianne Hackbornb9ec1ac2013-04-10 17:34:25 -07006380 } else if (orientation == ActivityInfo.SCREEN_ORIENTATION_LOCKED) {
6381 // Application just wants to remain locked in the last rotation.
6382 preferredRotation = lastRotation;
Jeff Brownbcdfc622014-03-06 19:13:04 -08006383 } else if (!mSupportAutoRotation) {
6384 // If we don't support auto-rotation then bail out here and ignore
6385 // the sensor and any rotation lock settings.
6386 preferredRotation = -1;
Jeff Brown207673cd2012-06-05 17:47:11 -07006387 } else if ((mUserRotationMode == WindowManagerPolicy.USER_ROTATION_FREE
Jeff Brown01a98dd2011-09-20 15:08:29 -07006388 && (orientation == ActivityInfo.SCREEN_ORIENTATION_USER
Dianne Hackbornb9ec1ac2013-04-10 17:34:25 -07006389 || orientation == ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED
6390 || orientation == ActivityInfo.SCREEN_ORIENTATION_USER_LANDSCAPE
6391 || orientation == ActivityInfo.SCREEN_ORIENTATION_USER_PORTRAIT
6392 || orientation == ActivityInfo.SCREEN_ORIENTATION_FULL_USER))
Jeff Brown01a98dd2011-09-20 15:08:29 -07006393 || orientation == ActivityInfo.SCREEN_ORIENTATION_SENSOR
6394 || orientation == ActivityInfo.SCREEN_ORIENTATION_FULL_SENSOR
6395 || orientation == ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE
6396 || orientation == ActivityInfo.SCREEN_ORIENTATION_SENSOR_PORTRAIT) {
6397 // Otherwise, use sensor only if requested by the application or enabled
6398 // by default for USER or UNSPECIFIED modes. Does not apply to NOSENSOR.
Jeff Brownd3187e32011-09-21 19:26:44 -07006399 if (mAllowAllRotations < 0) {
6400 // Can't read this during init() because the context doesn't
6401 // have display metrics at that time so we cannot determine
6402 // tablet vs. phone then.
6403 mAllowAllRotations = mContext.getResources().getBoolean(
6404 com.android.internal.R.bool.config_allowAllRotations) ? 1 : 0;
6405 }
Jeff Brown01a98dd2011-09-20 15:08:29 -07006406 if (sensorRotation != Surface.ROTATION_180
Jeff Brownd3187e32011-09-21 19:26:44 -07006407 || mAllowAllRotations == 1
Dianne Hackbornb9ec1ac2013-04-10 17:34:25 -07006408 || orientation == ActivityInfo.SCREEN_ORIENTATION_FULL_SENSOR
6409 || orientation == ActivityInfo.SCREEN_ORIENTATION_FULL_USER) {
Jeff Brown01a98dd2011-09-20 15:08:29 -07006410 preferredRotation = sensorRotation;
6411 } else {
6412 preferredRotation = lastRotation;
6413 }
Jeff Brown207673cd2012-06-05 17:47:11 -07006414 } else if (mUserRotationMode == WindowManagerPolicy.USER_ROTATION_LOCKED
6415 && orientation != ActivityInfo.SCREEN_ORIENTATION_NOSENSOR) {
6416 // Apply rotation lock. Does not apply to NOSENSOR.
6417 // The idea is that the user rotation expresses a weak preference for the direction
6418 // of gravity and as NOSENSOR is never affected by gravity, then neither should
6419 // NOSENSOR be affected by rotation lock (although it will be affected by docks).
Jeff Brown4dfce202011-10-05 12:00:10 -07006420 preferredRotation = mUserRotation;
Jeff Browndec6cf42011-11-15 14:08:20 -08006421 } else {
6422 // No overriding preference.
6423 // We will do exactly what the application asked us to do.
6424 preferredRotation = -1;
Jeff Brown01a98dd2011-09-20 15:08:29 -07006425 }
6426
Dianne Hackborne5439f22010-10-02 16:53:50 -07006427 switch (orientation) {
6428 case ActivityInfo.SCREEN_ORIENTATION_PORTRAIT:
Jeff Browndec6cf42011-11-15 14:08:20 -08006429 // Return portrait unless overridden.
6430 if (isAnyPortrait(preferredRotation)) {
6431 return preferredRotation;
6432 }
Dianne Hackborne5439f22010-10-02 16:53:50 -07006433 return mPortraitRotation;
Dianne Hackborne5439f22010-10-02 16:53:50 -07006434
Jeff Brown01a98dd2011-09-20 15:08:29 -07006435 case ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE:
Jeff Browndec6cf42011-11-15 14:08:20 -08006436 // Return landscape unless overridden.
6437 if (isLandscapeOrSeascape(preferredRotation)) {
6438 return preferredRotation;
6439 }
Jeff Brown01a98dd2011-09-20 15:08:29 -07006440 return mLandscapeRotation;
6441
6442 case ActivityInfo.SCREEN_ORIENTATION_REVERSE_PORTRAIT:
Jeff Browndec6cf42011-11-15 14:08:20 -08006443 // Return reverse portrait unless overridden.
6444 if (isAnyPortrait(preferredRotation)) {
6445 return preferredRotation;
6446 }
Jeff Brown01a98dd2011-09-20 15:08:29 -07006447 return mUpsideDownRotation;
6448
6449 case ActivityInfo.SCREEN_ORIENTATION_REVERSE_LANDSCAPE:
Jeff Browndec6cf42011-11-15 14:08:20 -08006450 // Return seascape unless overridden.
6451 if (isLandscapeOrSeascape(preferredRotation)) {
6452 return preferredRotation;
6453 }
Jeff Brown01a98dd2011-09-20 15:08:29 -07006454 return mSeascapeRotation;
6455
6456 case ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE:
Dianne Hackbornb9ec1ac2013-04-10 17:34:25 -07006457 case ActivityInfo.SCREEN_ORIENTATION_USER_LANDSCAPE:
Jeff Brown01a98dd2011-09-20 15:08:29 -07006458 // Return either landscape rotation.
6459 if (isLandscapeOrSeascape(preferredRotation)) {
6460 return preferredRotation;
6461 }
6462 if (isLandscapeOrSeascape(lastRotation)) {
Jeff Brown4519f072011-01-23 13:16:01 -08006463 return lastRotation;
6464 }
Jeff Brown01a98dd2011-09-20 15:08:29 -07006465 return mLandscapeRotation;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006466
Jeff Brown01a98dd2011-09-20 15:08:29 -07006467 case ActivityInfo.SCREEN_ORIENTATION_SENSOR_PORTRAIT:
Dianne Hackbornb9ec1ac2013-04-10 17:34:25 -07006468 case ActivityInfo.SCREEN_ORIENTATION_USER_PORTRAIT:
Jeff Brown01a98dd2011-09-20 15:08:29 -07006469 // Return either portrait rotation.
6470 if (isAnyPortrait(preferredRotation)) {
6471 return preferredRotation;
6472 }
6473 if (isAnyPortrait(lastRotation)) {
6474 return lastRotation;
6475 }
6476 return mPortraitRotation;
6477
6478 default:
Jeff Brown4dfce202011-10-05 12:00:10 -07006479 // For USER, UNSPECIFIED, NOSENSOR, SENSOR and FULL_SENSOR,
6480 // just return the preferred orientation we already calculated.
Jeff Brown01a98dd2011-09-20 15:08:29 -07006481 if (preferredRotation >= 0) {
6482 return preferredRotation;
6483 }
Dianne Hackborndacea8c2011-04-21 17:26:39 -07006484 return Surface.ROTATION_0;
Daniel Sandlere7e5ac22011-02-22 16:10:21 -05006485 }
6486 }
Steve Howarda7bfe6a2010-09-23 16:47:49 -07006487 }
6488
Jeff Brown01a98dd2011-09-20 15:08:29 -07006489 @Override
6490 public boolean rotationHasCompatibleMetricsLw(int orientation, int rotation) {
6491 switch (orientation) {
6492 case ActivityInfo.SCREEN_ORIENTATION_PORTRAIT:
6493 case ActivityInfo.SCREEN_ORIENTATION_REVERSE_PORTRAIT:
6494 case ActivityInfo.SCREEN_ORIENTATION_SENSOR_PORTRAIT:
6495 return isAnyPortrait(rotation);
6496
6497 case ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE:
6498 case ActivityInfo.SCREEN_ORIENTATION_REVERSE_LANDSCAPE:
6499 case ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE:
6500 return isLandscapeOrSeascape(rotation);
6501
6502 default:
6503 return true;
6504 }
Steve Howarda7bfe6a2010-09-23 16:47:49 -07006505 }
6506
Jeff Brownc0347aa2011-09-23 17:26:09 -07006507 @Override
6508 public void setRotationLw(int rotation) {
6509 mOrientationListener.setCurrentRotation(rotation);
6510 }
6511
Jeff Brown01a98dd2011-09-20 15:08:29 -07006512 private boolean isLandscapeOrSeascape(int rotation) {
6513 return rotation == mLandscapeRotation || rotation == mSeascapeRotation;
Dianne Hackborne5439f22010-10-02 16:53:50 -07006514 }
6515
Jeff Brown01a98dd2011-09-20 15:08:29 -07006516 private boolean isAnyPortrait(int rotation) {
6517 return rotation == mPortraitRotation || rotation == mUpsideDownRotation;
Dianne Hackborne5439f22010-10-02 16:53:50 -07006518 }
6519
Jose Lima9546b202014-07-02 17:21:51 -07006520 @Override
Svetoslav Ganov80943d82013-01-02 10:25:37 -08006521 public int getUserRotationMode() {
6522 return Settings.System.getIntForUser(mContext.getContentResolver(),
Brett Chabot7e55c402013-05-16 19:38:08 -07006523 Settings.System.ACCELEROMETER_ROTATION, 0, UserHandle.USER_CURRENT) != 0 ?
6524 WindowManagerPolicy.USER_ROTATION_FREE :
6525 WindowManagerPolicy.USER_ROTATION_LOCKED;
Svetoslav Ganov80943d82013-01-02 10:25:37 -08006526 }
Daniel Sandlerb73617d2010-08-17 00:41:00 -04006527
6528 // User rotation: to be used when all else fails in assigning an orientation to the device
Jose Lima9546b202014-07-02 17:21:51 -07006529 @Override
Daniel Sandlerb73617d2010-08-17 00:41:00 -04006530 public void setUserRotationMode(int mode, int rot) {
6531 ContentResolver res = mContext.getContentResolver();
Daniel Sandler2ed6ad62011-02-22 14:54:17 -05006532
6533 // mUserRotationMode and mUserRotation will be assigned by the content observer
Daniel Sandlerb73617d2010-08-17 00:41:00 -04006534 if (mode == WindowManagerPolicy.USER_ROTATION_LOCKED) {
Christopher Tate5e08af02012-09-21 17:17:22 -07006535 Settings.System.putIntForUser(res,
Daniel Sandlerb73617d2010-08-17 00:41:00 -04006536 Settings.System.USER_ROTATION,
Christopher Tate5e08af02012-09-21 17:17:22 -07006537 rot,
6538 UserHandle.USER_CURRENT);
6539 Settings.System.putIntForUser(res,
Daniel Sandler2ed6ad62011-02-22 14:54:17 -05006540 Settings.System.ACCELEROMETER_ROTATION,
Christopher Tate5e08af02012-09-21 17:17:22 -07006541 0,
6542 UserHandle.USER_CURRENT);
Daniel Sandlerb73617d2010-08-17 00:41:00 -04006543 } else {
Christopher Tate5e08af02012-09-21 17:17:22 -07006544 Settings.System.putIntForUser(res,
Daniel Sandlerb73617d2010-08-17 00:41:00 -04006545 Settings.System.ACCELEROMETER_ROTATION,
Christopher Tate5e08af02012-09-21 17:17:22 -07006546 1,
6547 UserHandle.USER_CURRENT);
Daniel Sandlerb73617d2010-08-17 00:41:00 -04006548 }
6549 }
6550
Jose Lima9546b202014-07-02 17:21:51 -07006551 @Override
Jeff Brownac143512012-04-05 18:57:33 -07006552 public void setSafeMode(boolean safeMode) {
6553 mSafeMode = safeMode;
6554 performHapticFeedbackLw(null, safeMode
6555 ? HapticFeedbackConstants.SAFE_MODE_ENABLED
6556 : HapticFeedbackConstants.SAFE_MODE_DISABLED, true);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006557 }
Craig Mautnereda67292013-04-28 13:50:14 -07006558
Dianne Hackborn181ceb52009-08-27 22:16:40 -07006559 static long[] getLongIntArray(Resources r, int resid) {
6560 int[] ar = r.getIntArray(resid);
6561 if (ar == null) {
6562 return null;
6563 }
6564 long[] out = new long[ar.length];
6565 for (int i=0; i<ar.length; i++) {
6566 out[i] = ar[i];
6567 }
6568 return out;
6569 }
Craig Mautnereda67292013-04-28 13:50:14 -07006570
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006571 /** {@inheritDoc} */
Craig Mautnereda67292013-04-28 13:50:14 -07006572 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006573 public void systemReady() {
Jim Millerab954542014-10-10 18:21:49 -07006574 mKeyguardDelegate = new KeyguardServiceDelegate(mContext);
Mike Lockwooded8902d2013-11-15 11:01:47 -08006575 mKeyguardDelegate.onSystemReady();
6576
Michael Wright3818c922014-09-02 13:59:07 -07006577 readCameraLensCoverState();
Jeff Brown4f5fa282014-06-12 19:19:15 -07006578 updateUiMode();
Adrian Roos3542f7d2015-07-13 15:57:53 -07006579 boolean bindKeyguardNow;
Dianne Hackbornb1a79802009-09-29 15:18:31 -07006580 synchronized (mLock) {
6581 updateOrientationListenerLp();
Dianne Hackbornc777e072010-02-12 13:07:59 -08006582 mSystemReady = true;
6583 mHandler.post(new Runnable() {
Craig Mautnereda67292013-04-28 13:50:14 -07006584 @Override
Dianne Hackbornc777e072010-02-12 13:07:59 -08006585 public void run() {
6586 updateSettings();
6587 }
6588 });
Adrian Roos3542f7d2015-07-13 15:57:53 -07006589
6590 bindKeyguardNow = mDeferBindKeyguard;
6591 if (bindKeyguardNow) {
6592 // systemBooted ran but wasn't able to bind to the Keyguard, we'll do it now.
6593 mDeferBindKeyguard = false;
6594 }
6595 }
6596
6597 if (bindKeyguardNow) {
6598 mKeyguardDelegate.bindService(mContext);
6599 mKeyguardDelegate.onBootCompleted();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006600 }
Michael Wrighta4d22d72015-09-16 23:19:26 +01006601 mSystemGestures.systemReady();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006602 }
Dianne Hackborn661cd522011-08-22 00:26:20 -07006603
Dianne Hackbornba24e4d2011-09-01 11:17:06 -07006604 /** {@inheritDoc} */
Jose Lima9546b202014-07-02 17:21:51 -07006605 @Override
Dianne Hackbornba24e4d2011-09-01 11:17:06 -07006606 public void systemBooted() {
Adrian Roos3542f7d2015-07-13 15:57:53 -07006607 boolean bindKeyguardNow = false;
6608 synchronized (mLock) {
6609 // Time to bind Keyguard; take care to only bind it once, either here if ready or
6610 // in systemReady if not.
6611 if (mKeyguardDelegate != null) {
6612 bindKeyguardNow = true;
6613 } else {
6614 // Because mKeyguardDelegate is null, we know that the synchronized block in
6615 // systemReady didn't run yet and setting this will actually have an effect.
6616 mDeferBindKeyguard = true;
6617 }
6618 }
6619 if (bindKeyguardNow) {
Jason Monk5eeebf52014-09-26 12:36:51 -04006620 mKeyguardDelegate.bindService(mContext);
Jim Millere5f910a2013-10-16 18:15:46 -07006621 mKeyguardDelegate.onBootCompleted();
6622 }
Dianne Hackbornba24e4d2011-09-01 11:17:06 -07006623 synchronized (mLock) {
6624 mSystemBooted = true;
6625 }
Jeff Brown416c49c2015-05-26 19:50:18 -07006626 startedWakingUp();
Jeff Brown36c4db82014-09-19 12:05:31 -07006627 screenTurningOn(null);
Jorim Jaggic0496072015-08-19 15:14:52 -07006628 screenTurnedOn();
Dianne Hackbornba24e4d2011-09-01 11:17:06 -07006629 }
6630
Dianne Hackborn661cd522011-08-22 00:26:20 -07006631 ProgressDialog mBootMsgDialog = null;
6632
6633 /** {@inheritDoc} */
Jose Lima9546b202014-07-02 17:21:51 -07006634 @Override
Dianne Hackborn661cd522011-08-22 00:26:20 -07006635 public void showBootMessage(final CharSequence msg, final boolean always) {
6636 mHandler.post(new Runnable() {
6637 @Override public void run() {
6638 if (mBootMsgDialog == null) {
Craig Stout4c0cb8a2014-04-04 13:03:10 -07006639 int theme;
Jaewan Kim49117872016-01-19 17:24:08 +09006640 if (mContext.getPackageManager().hasSystemFeature(FEATURE_WATCH)) {
Craig Stout4c0cb8a2014-04-04 13:03:10 -07006641 theme = com.android.internal.R.style.Theme_Micro_Dialog_Alert;
Jaewan Kim49117872016-01-19 17:24:08 +09006642 } else if (mContext.getPackageManager().hasSystemFeature(FEATURE_TELEVISION)) {
Craig Stout4c0cb8a2014-04-04 13:03:10 -07006643 theme = com.android.internal.R.style.Theme_Leanback_Dialog_Alert;
6644 } else {
6645 theme = 0;
6646 }
Vinod Krishnanfa8fc412014-04-18 14:35:53 -07006647
6648 mBootMsgDialog = new ProgressDialog(mContext, theme) {
Dianne Hackborn295e3c22011-08-25 13:19:08 -07006649 // This dialog will consume all events coming in to
6650 // it, to avoid it trying to do things too early in boot.
6651 @Override public boolean dispatchKeyEvent(KeyEvent event) {
6652 return true;
6653 }
6654 @Override public boolean dispatchKeyShortcutEvent(KeyEvent event) {
6655 return true;
6656 }
6657 @Override public boolean dispatchTouchEvent(MotionEvent ev) {
6658 return true;
6659 }
6660 @Override public boolean dispatchTrackballEvent(MotionEvent ev) {
6661 return true;
6662 }
6663 @Override public boolean dispatchGenericMotionEvent(MotionEvent ev) {
6664 return true;
6665 }
6666 @Override public boolean dispatchPopulateAccessibilityEvent(
6667 AccessibilityEvent event) {
6668 return true;
6669 }
6670 };
Jeff Hao9f60c082014-10-28 18:51:07 -07006671 if (mContext.getPackageManager().isUpgrade()) {
6672 mBootMsgDialog.setTitle(R.string.android_upgrading_title);
6673 } else {
6674 mBootMsgDialog.setTitle(R.string.android_start_title);
6675 }
Dianne Hackborn661cd522011-08-22 00:26:20 -07006676 mBootMsgDialog.setProgressStyle(ProgressDialog.STYLE_SPINNER);
6677 mBootMsgDialog.setIndeterminate(true);
6678 mBootMsgDialog.getWindow().setType(
Dianne Hackborn29aae6f2011-08-18 18:30:09 -07006679 WindowManager.LayoutParams.TYPE_BOOT_PROGRESS);
Dianne Hackborn661cd522011-08-22 00:26:20 -07006680 mBootMsgDialog.getWindow().addFlags(
6681 WindowManager.LayoutParams.FLAG_DIM_BEHIND
6682 | WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN);
6683 mBootMsgDialog.getWindow().setDimAmount(1);
Dianne Hackbornd9efb952011-12-07 14:56:51 -08006684 WindowManager.LayoutParams lp = mBootMsgDialog.getWindow().getAttributes();
6685 lp.screenOrientation = ActivityInfo.SCREEN_ORIENTATION_NOSENSOR;
6686 mBootMsgDialog.getWindow().setAttributes(lp);
Dianne Hackborn661cd522011-08-22 00:26:20 -07006687 mBootMsgDialog.setCancelable(false);
6688 mBootMsgDialog.show();
6689 }
6690 mBootMsgDialog.setMessage(msg);
6691 }
6692 });
6693 }
6694
6695 /** {@inheritDoc} */
Jose Lima9546b202014-07-02 17:21:51 -07006696 @Override
Dianne Hackborn661cd522011-08-22 00:26:20 -07006697 public void hideBootMessages() {
Craig Mautnera631d492014-08-05 15:16:01 -07006698 mHandler.sendEmptyMessage(MSG_HIDE_BOOT_MESSAGE);
Dianne Hackborn661cd522011-08-22 00:26:20 -07006699 }
6700
Mike Lockwood28569302010-01-28 11:54:40 -05006701 /** {@inheritDoc} */
Jose Lima9546b202014-07-02 17:21:51 -07006702 @Override
Mike Lockwood28569302010-01-28 11:54:40 -05006703 public void userActivity() {
Dianne Hackborndf89e652011-10-06 22:35:11 -07006704 // ***************************************
6705 // NOTE NOTE NOTE NOTE NOTE NOTE NOTE NOTE
6706 // ***************************************
6707 // THIS IS CALLED FROM DEEP IN THE POWER MANAGER
6708 // WITH ITS LOCKS HELD.
6709 //
6710 // This code must be VERY careful about the locks
6711 // it acquires.
6712 // In fact, the current code acquires way too many,
6713 // and probably has lurking deadlocks.
6714
Mike Lockwood28569302010-01-28 11:54:40 -05006715 synchronized (mScreenLockTimeout) {
6716 if (mLockScreenTimerActive) {
6717 // reset the timer
6718 mHandler.removeCallbacks(mScreenLockTimeout);
6719 mHandler.postDelayed(mScreenLockTimeout, mLockScreenTimeout);
6720 }
6721 }
Daniel Sandler0601eb72011-04-13 01:01:32 -04006722 }
6723
Adam Cohenf7522022012-10-03 20:03:18 -07006724 class ScreenLockTimeout implements Runnable {
6725 Bundle options;
6726
6727 @Override
Mike Lockwood28569302010-01-28 11:54:40 -05006728 public void run() {
6729 synchronized (this) {
6730 if (localLOGV) Log.v(TAG, "mScreenLockTimeout activating keyguard");
Jim Miller5ecd8112013-01-09 18:50:26 -08006731 if (mKeyguardDelegate != null) {
6732 mKeyguardDelegate.doKeyguardTimeout(options);
Mike Lockwood3a74bd32011-08-12 13:55:22 -07006733 }
Mike Lockwood28569302010-01-28 11:54:40 -05006734 mLockScreenTimerActive = false;
Adam Cohenf7522022012-10-03 20:03:18 -07006735 options = null;
Mike Lockwood28569302010-01-28 11:54:40 -05006736 }
6737 }
Mike Lockwood28569302010-01-28 11:54:40 -05006738
Adam Cohenf7522022012-10-03 20:03:18 -07006739 public void setLockOptions(Bundle options) {
6740 this.options = options;
6741 }
6742 }
6743
6744 ScreenLockTimeout mScreenLockTimeout = new ScreenLockTimeout();
6745
Jose Lima9546b202014-07-02 17:21:51 -07006746 @Override
Adam Cohenf7522022012-10-03 20:03:18 -07006747 public void lockNow(Bundle options) {
Jim Miller93c518e2012-01-17 15:55:31 -08006748 mContext.enforceCallingOrSelfPermission(android.Manifest.permission.DEVICE_POWER, null);
6749 mHandler.removeCallbacks(mScreenLockTimeout);
Adam Cohenf7522022012-10-03 20:03:18 -07006750 if (options != null) {
6751 // In case multiple calls are made to lockNow, we don't wipe out the options
6752 // until the runnable actually executes.
6753 mScreenLockTimeout.setLockOptions(options);
6754 }
Jim Miller93c518e2012-01-17 15:55:31 -08006755 mHandler.post(mScreenLockTimeout);
6756 }
6757
Mike Lockwood28569302010-01-28 11:54:40 -05006758 private void updateLockScreenTimeout() {
6759 synchronized (mScreenLockTimeout) {
Jeff Brown3ee549c2014-09-22 20:14:39 -07006760 boolean enable = (mAllowLockscreenWhenOn && mAwake &&
Jim Miller5ecd8112013-01-09 18:50:26 -08006761 mKeyguardDelegate != null && mKeyguardDelegate.isSecure());
Mike Lockwood28569302010-01-28 11:54:40 -05006762 if (mLockScreenTimerActive != enable) {
6763 if (enable) {
6764 if (localLOGV) Log.v(TAG, "setting lockscreen timer");
Jim Miller2967f482016-01-07 15:05:32 -08006765 mHandler.removeCallbacks(mScreenLockTimeout); // remove any pending requests
Mike Lockwood28569302010-01-28 11:54:40 -05006766 mHandler.postDelayed(mScreenLockTimeout, mLockScreenTimeout);
6767 } else {
6768 if (localLOGV) Log.v(TAG, "clearing lockscreen timer");
6769 mHandler.removeCallbacks(mScreenLockTimeout);
6770 }
6771 mLockScreenTimerActive = enable;
6772 }
6773 }
6774 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006775
Jeff Brown061ea992015-04-17 19:55:47 -07006776 private void updateDreamingSleepToken(boolean acquire) {
6777 if (acquire) {
6778 if (mDreamingSleepToken == null) {
6779 mDreamingSleepToken = mActivityManagerInternal.acquireSleepToken("Dream");
6780 }
6781 } else {
6782 if (mDreamingSleepToken != null) {
6783 mDreamingSleepToken.release();
Jeff Brown48d1b142015-06-10 16:36:03 -07006784 mDreamingSleepToken = null;
6785 }
6786 }
6787 }
6788
6789 private void updateScreenOffSleepToken(boolean acquire) {
6790 if (acquire) {
6791 if (mScreenOffSleepToken == null) {
6792 mScreenOffSleepToken = mActivityManagerInternal.acquireSleepToken("ScreenOff");
6793 }
6794 } else {
6795 if (mScreenOffSleepToken != null) {
6796 mScreenOffSleepToken.release();
6797 mScreenOffSleepToken = null;
Jeff Brown061ea992015-04-17 19:55:47 -07006798 }
6799 }
6800 }
6801
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006802 /** {@inheritDoc} */
Craig Mautnereda67292013-04-28 13:50:14 -07006803 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006804 public void enableScreenAfterBoot() {
6805 readLidState();
Jeff Brownc458ce92012-04-30 14:58:40 -07006806 applyLidSwitchState();
Jeff Brown01a98dd2011-09-20 15:08:29 -07006807 updateRotation(true);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006808 }
Dianne Hackbornf54c8f92009-09-19 14:03:57 -07006809
Jeff Brownc458ce92012-04-30 14:58:40 -07006810 private void applyLidSwitchState() {
Jeff Brownc458ce92012-04-30 14:58:40 -07006811 if (mLidState == LID_CLOSED && mLidControlsSleep) {
Jeff Brown6d8fd272014-05-20 21:24:38 -07006812 mPowerManager.goToSleep(SystemClock.uptimeMillis(),
Jeff Brownc12035c2014-08-13 18:52:25 -07006813 PowerManager.GO_TO_SLEEP_REASON_LID_SWITCH,
Jeff Brown6d8fd272014-05-20 21:24:38 -07006814 PowerManager.GO_TO_SLEEP_FLAG_NO_DOZE);
Edward Savage-Jones7def60d2015-11-13 13:27:03 +01006815 } else if (mLidState == LID_CLOSED && mLidControlsScreenLock) {
6816 mWindowManagerFuncs.lockDeviceNow();
Jeff Brownc458ce92012-04-30 14:58:40 -07006817 }
Jeff Browna20dda42014-05-27 20:57:24 -07006818
6819 synchronized (mLock) {
6820 updateWakeGestureListenerLp();
6821 }
Jeff Brown01a98dd2011-09-20 15:08:29 -07006822 }
6823
Jeff Brown4f5fa282014-06-12 19:19:15 -07006824 void updateUiMode() {
6825 if (mUiModeManager == null) {
6826 mUiModeManager = IUiModeManager.Stub.asInterface(
6827 ServiceManager.getService(Context.UI_MODE_SERVICE));
6828 }
6829 try {
6830 mUiMode = mUiModeManager.getCurrentModeType();
6831 } catch (RemoteException e) {
6832 }
6833 }
6834
Jeff Brown01a98dd2011-09-20 15:08:29 -07006835 void updateRotation(boolean alwaysSendConfiguration) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006836 try {
6837 //set orientation on WindowManager
Dianne Hackbornf87d1962012-04-04 12:48:24 -07006838 mWindowManager.updateRotation(alwaysSendConfiguration, false);
6839 } catch (RemoteException e) {
6840 // Ignore
6841 }
6842 }
6843
6844 void updateRotation(boolean alwaysSendConfiguration, boolean forceRelayout) {
6845 try {
6846 //set orientation on WindowManager
6847 mWindowManager.updateRotation(alwaysSendConfiguration, forceRelayout);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006848 } catch (RemoteException e) {
6849 // Ignore
6850 }
6851 }
6852
Daniel Sandler6396c722013-04-16 20:19:09 -04006853 /**
6854 * Return an Intent to launch the currently active dock app as home. Returns
6855 * null if the standard home should be launched, which is the case if any of the following is
6856 * true:
6857 * <ul>
6858 * <li>The device is not in either car mode or desk mode
keunyounga7710492015-09-23 11:33:58 -07006859 * <li>The device is in car mode but mEnableCarDockHomeCapture is false
Daniel Sandler6396c722013-04-16 20:19:09 -04006860 * <li>The device is in desk mode but ENABLE_DESK_DOCK_HOME_CAPTURE is false
6861 * <li>The device is in car mode but there's no CAR_DOCK app with METADATA_DOCK_HOME
6862 * <li>The device is in desk mode but there's no DESK_DOCK app with METADATA_DOCK_HOME
6863 * </ul>
Craig Mautnereda67292013-04-28 13:50:14 -07006864 * @return A dock intent.
Daniel Sandler6396c722013-04-16 20:19:09 -04006865 */
6866 Intent createHomeDockIntent() {
6867 Intent intent = null;
6868
6869 // What home does is based on the mode, not the dock state. That
6870 // is, when in car mode you should be taken to car home regardless
6871 // of whether we are actually in a car dock.
6872 if (mUiMode == Configuration.UI_MODE_TYPE_CAR) {
keunyounga7710492015-09-23 11:33:58 -07006873 if (mEnableCarDockHomeCapture) {
Daniel Sandler6396c722013-04-16 20:19:09 -04006874 intent = mCarDockIntent;
6875 }
6876 } else if (mUiMode == Configuration.UI_MODE_TYPE_DESK) {
6877 if (ENABLE_DESK_DOCK_HOME_CAPTURE) {
6878 intent = mDeskDockIntent;
6879 }
Jeff Brown4f5fa282014-06-12 19:19:15 -07006880 } else if (mUiMode == Configuration.UI_MODE_TYPE_WATCH
6881 && (mDockMode == Intent.EXTRA_DOCK_STATE_DESK
6882 || mDockMode == Intent.EXTRA_DOCK_STATE_HE_DESK
6883 || mDockMode == Intent.EXTRA_DOCK_STATE_LE_DESK)) {
6884 // Always launch dock home from home when watch is docked, if it exists.
6885 intent = mDeskDockIntent;
Daniel Sandler6396c722013-04-16 20:19:09 -04006886 }
6887
6888 if (intent == null) {
6889 return null;
6890 }
6891
6892 ActivityInfo ai = null;
6893 ResolveInfo info = mContext.getPackageManager().resolveActivityAsUser(
6894 intent,
John Spurlockf56bef12013-07-09 09:51:46 -04006895 PackageManager.MATCH_DEFAULT_ONLY | PackageManager.GET_META_DATA,
Craig Mautnerd625ab22013-09-06 13:40:31 -07006896 mCurrentUserId);
Daniel Sandler6396c722013-04-16 20:19:09 -04006897 if (info != null) {
6898 ai = info.activityInfo;
6899 }
6900 if (ai != null
6901 && ai.metaData != null
6902 && ai.metaData.getBoolean(Intent.METADATA_DOCK_HOME)) {
6903 intent = new Intent(intent);
6904 intent.setClassName(ai.packageName, ai.name);
6905 return intent;
6906 }
6907
6908 return null;
6909 }
6910
Filip Gruszczynskia483a1d2015-03-17 19:06:58 +00006911 void startDockOrHome(boolean fromHomeKey, boolean awakenFromDreams) {
6912 if (awakenFromDreams) {
6913 awakenDreams();
6914 }
Daniel Sandler6396c722013-04-16 20:19:09 -04006915
6916 Intent dock = createHomeDockIntent();
6917 if (dock != null) {
6918 try {
Bryce Lee01b0c5f2015-02-05 18:24:04 -08006919 if (fromHomeKey) {
6920 dock.putExtra(WindowManagerPolicy.EXTRA_FROM_HOME_KEY, fromHomeKey);
6921 }
Bart Sears8b1c27c2015-03-18 23:51:02 +00006922 startActivityAsUser(dock, UserHandle.CURRENT);
Daniel Sandler6396c722013-04-16 20:19:09 -04006923 return;
6924 } catch (ActivityNotFoundException e) {
6925 }
6926 }
6927
Bryce Lee01b0c5f2015-02-05 18:24:04 -08006928 Intent intent;
6929
6930 if (fromHomeKey) {
6931 intent = new Intent(mHomeIntent);
6932 intent.putExtra(WindowManagerPolicy.EXTRA_FROM_HOME_KEY, fromHomeKey);
6933 } else {
6934 intent = mHomeIntent;
6935 }
6936
Bryce Lee9fc0b6f2015-03-19 21:37:45 +00006937 startActivityAsUser(intent, UserHandle.CURRENT);
Dianne Hackborn39c2d712009-09-22 11:41:31 -07006938 }
Craig Mautnereda67292013-04-28 13:50:14 -07006939
Dianne Hackborn39c2d712009-09-22 11:41:31 -07006940 /**
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006941 * goes to the home screen
6942 * @return whether it did anything
6943 */
6944 boolean goHome() {
Bart Sears8b1c27c2015-03-18 23:51:02 +00006945 if (!isUserSetupComplete()) {
6946 Slog.i(TAG, "Not going home because user setup is in progress.");
6947 return false;
6948 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006949 if (false) {
6950 // This code always brings home to the front.
Dianne Hackborn256dd3b2009-05-19 18:51:21 -07006951 try {
6952 ActivityManagerNative.getDefault().stopAppSwitches();
6953 } catch (RemoteException e) {
6954 }
Dianne Hackborn94a679d2009-07-28 17:51:07 -07006955 sendCloseSystemWindows();
Filip Gruszczynskia483a1d2015-03-17 19:06:58 +00006956 startDockOrHome(false /*fromHomeKey*/, true /* awakenFromDreams */);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006957 } else {
6958 // This code brings home to the front or, if it is already
6959 // at the front, puts the device to sleep.
6960 try {
Wink Savilled2e6a332010-02-12 12:12:06 -08006961 if (SystemProperties.getInt("persist.sys.uts-test-mode", 0) == 1) {
6962 /// Roll back EndcallBehavior as the cupcake design to pass P1 lab entry.
6963 Log.d(TAG, "UTS-TEST-MODE");
6964 } else {
6965 ActivityManagerNative.getDefault().stopAppSwitches();
6966 sendCloseSystemWindows();
Daniel Sandler6396c722013-04-16 20:19:09 -04006967 Intent dock = createHomeDockIntent();
6968 if (dock != null) {
6969 int result = ActivityManagerNative.getDefault()
6970 .startActivityAsUser(null, null, dock,
6971 dock.resolveTypeIfNeeded(mContext.getContentResolver()),
6972 null, null, 0,
6973 ActivityManager.START_FLAG_ONLY_IF_NEEDED,
Jeff Hao1b012d32014-08-20 10:35:34 -07006974 null, null, UserHandle.USER_CURRENT);
Daniel Sandler6396c722013-04-16 20:19:09 -04006975 if (result == ActivityManager.START_RETURN_INTENT_TO_CALLER) {
6976 return false;
6977 }
6978 }
Dianne Hackborn39c2d712009-09-22 11:41:31 -07006979 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006980 int result = ActivityManagerNative.getDefault()
Dianne Hackbornf265ea92013-01-31 15:00:51 -08006981 .startActivityAsUser(null, null, mHomeIntent,
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006982 mHomeIntent.resolveTypeIfNeeded(mContext.getContentResolver()),
Dianne Hackborna4972e92012-03-14 10:38:05 -07006983 null, null, 0,
6984 ActivityManager.START_FLAG_ONLY_IF_NEEDED,
Jeff Hao1b012d32014-08-20 10:35:34 -07006985 null, null, UserHandle.USER_CURRENT);
Dianne Hackborna4972e92012-03-14 10:38:05 -07006986 if (result == ActivityManager.START_RETURN_INTENT_TO_CALLER) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006987 return false;
6988 }
6989 } catch (RemoteException ex) {
6990 // bummer, the activity manager, which is in this process, is dead
6991 }
6992 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006993 return true;
6994 }
Craig Mautnereda67292013-04-28 13:50:14 -07006995
6996 @Override
The Android Open Source Project0727d222009-03-11 12:11:58 -07006997 public void setCurrentOrientationLw(int newOrientation) {
6998 synchronized (mLock) {
6999 if (newOrientation != mCurrentAppOrientation) {
7000 mCurrentAppOrientation = newOrientation;
7001 updateOrientationListenerLp();
7002 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08007003 }
7004 }
Amith Yamasanic33cb712010-02-10 15:21:49 -08007005
Svetoslav Ganov7befb7d2012-09-27 16:49:23 -07007006 private void performAuditoryFeedbackForAccessibilityIfNeed() {
7007 if (!isGlobalAccessibilityGestureEnabled()) {
7008 return;
7009 }
7010 AudioManager audioManager = (AudioManager) mContext.getSystemService(
7011 Context.AUDIO_SERVICE);
7012 if (audioManager.isSilentMode()) {
7013 return;
7014 }
7015 Ringtone ringTone = RingtoneManager.getRingtone(mContext,
7016 Settings.System.DEFAULT_NOTIFICATION_URI);
7017 ringTone.setStreamType(AudioManager.STREAM_MUSIC);
7018 ringTone.play();
7019 }
Craig Mautnereda67292013-04-28 13:50:14 -07007020
Bryce Lee584a4452014-10-21 15:55:55 -07007021 private boolean isTheaterModeEnabled() {
7022 return Settings.Global.getInt(mContext.getContentResolver(),
7023 Settings.Global.THEATER_MODE_ON, 0) == 1;
7024 }
7025
Svetoslav Ganov7befb7d2012-09-27 16:49:23 -07007026 private boolean isGlobalAccessibilityGestureEnabled() {
7027 return Settings.Global.getInt(mContext.getContentResolver(),
7028 Settings.Global.ENABLE_ACCESSIBILITY_GLOBAL_GESTURE_ENABLED, 0) == 1;
7029 }
7030
Craig Mautnereda67292013-04-28 13:50:14 -07007031 @Override
The Android Open Source Project0727d222009-03-11 12:11:58 -07007032 public boolean performHapticFeedbackLw(WindowState win, int effectId, boolean always) {
Svetoslav Ganov96179212012-10-10 14:17:45 -07007033 if (!mVibrator.hasVibrator()) {
7034 return false;
7035 }
Christopher Tate5e08af02012-09-21 17:17:22 -07007036 final boolean hapticsDisabled = Settings.System.getIntForUser(mContext.getContentResolver(),
7037 Settings.System.HAPTIC_FEEDBACK_ENABLED, 0, UserHandle.USER_CURRENT) == 0;
Jeff Brown82379ba2014-07-25 19:03:28 -07007038 if (hapticsDisabled && !always) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08007039 return false;
7040 }
Amith Yamasanic33cb712010-02-10 15:21:49 -08007041 long[] pattern = null;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08007042 switch (effectId) {
7043 case HapticFeedbackConstants.LONG_PRESS:
Amith Yamasanic33cb712010-02-10 15:21:49 -08007044 pattern = mLongPressVibePattern;
7045 break;
Dianne Hackbornb1a79802009-09-29 15:18:31 -07007046 case HapticFeedbackConstants.VIRTUAL_KEY:
Amith Yamasanic33cb712010-02-10 15:21:49 -08007047 pattern = mVirtualKeyVibePattern;
7048 break;
7049 case HapticFeedbackConstants.KEYBOARD_TAP:
7050 pattern = mKeyboardTapVibePattern;
7051 break;
Fabrice Di Meglioeeff63a2013-08-05 12:07:24 -07007052 case HapticFeedbackConstants.CLOCK_TICK:
7053 pattern = mClockTickVibePattern;
7054 break;
Fabrice Di Megliobd9152f2013-10-01 11:21:31 -07007055 case HapticFeedbackConstants.CALENDAR_DATE:
7056 pattern = mCalendarDateVibePattern;
7057 break;
Dianne Hackbornb1a79802009-09-29 15:18:31 -07007058 case HapticFeedbackConstants.SAFE_MODE_DISABLED:
Amith Yamasanic33cb712010-02-10 15:21:49 -08007059 pattern = mSafeModeDisabledVibePattern;
7060 break;
Dianne Hackbornb1a79802009-09-29 15:18:31 -07007061 case HapticFeedbackConstants.SAFE_MODE_ENABLED:
Amith Yamasanic33cb712010-02-10 15:21:49 -08007062 pattern = mSafeModeEnabledVibePattern;
7063 break;
Mady Mellore8608912015-06-05 09:02:55 -07007064 case HapticFeedbackConstants.CONTEXT_CLICK:
7065 pattern = mContextClickVibePattern;
Mady Mellore82067b2015-04-30 09:58:35 -07007066 break;
Amith Yamasanic33cb712010-02-10 15:21:49 -08007067 default:
7068 return false;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08007069 }
Dianne Hackbornf265ea92013-01-31 15:00:51 -08007070 int owningUid;
7071 String owningPackage;
7072 if (win != null) {
7073 owningUid = win.getOwningUid();
7074 owningPackage = win.getOwningPackage();
7075 } else {
7076 owningUid = android.os.Process.myUid();
Dianne Hackborn95d78532013-09-11 09:51:14 -07007077 owningPackage = mContext.getOpPackageName();
Dianne Hackbornf265ea92013-01-31 15:00:51 -08007078 }
Amith Yamasanic33cb712010-02-10 15:21:49 -08007079 if (pattern.length == 1) {
7080 // One-shot vibration
John Spurlock7b414672014-07-18 13:02:39 -04007081 mVibrator.vibrate(owningUid, owningPackage, pattern[0], VIBRATION_ATTRIBUTES);
Amith Yamasanic33cb712010-02-10 15:21:49 -08007082 } else {
7083 // Pattern vibration
John Spurlock7b414672014-07-18 13:02:39 -04007084 mVibrator.vibrate(owningUid, owningPackage, pattern, -1, VIBRATION_ATTRIBUTES);
Amith Yamasanic33cb712010-02-10 15:21:49 -08007085 }
7086 return true;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08007087 }
Jeff Brownc38c9be2012-10-04 13:16:19 -07007088
7089 @Override
7090 public void keepScreenOnStartedLw() {
Daniel Sandler0601eb72011-04-13 01:01:32 -04007091 }
7092
Jeff Brownc38c9be2012-10-04 13:16:19 -07007093 @Override
7094 public void keepScreenOnStoppedLw() {
Jim Millerab954542014-10-10 18:21:49 -07007095 if (isKeyguardShowingAndNotOccluded()) {
Jim Miller25190572013-02-28 17:36:24 -08007096 mPowerManager.userActivity(SystemClock.uptimeMillis(), false);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08007097 }
7098 }
Mike Lockwoodfcb39242009-10-21 23:01:07 -04007099
Dianne Hackborndf89e652011-10-06 22:35:11 -07007100 private int updateSystemUiVisibilityLw() {
Joe Onorato664644d2011-01-23 17:53:23 -08007101 // If there is no window focused, there will be nobody to handle the events
7102 // anyway, so just hang on in whatever state we're in until things settle down.
Adrian Roos53f28ec2014-10-29 17:26:12 +01007103 final WindowState win = mFocusedWindow != null ? mFocusedWindow
7104 : mTopFullscreenOpaqueWindowState;
John Spurlock79da8332013-09-20 12:04:47 -04007105 if (win == null) {
Dianne Hackborndf89e652011-10-06 22:35:11 -07007106 return 0;
7107 }
Jorim Jaggi380ecb82014-03-14 17:25:20 +01007108 if ((win.getAttrs().privateFlags & PRIVATE_FLAG_KEYGUARD) != 0 && mHideLockScreen == true) {
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07007109 // We are updating at a point where the keyguard has gotten
7110 // focus, but we were last in a state where the top window is
7111 // hiding it. This is probably because the keyguard as been
7112 // shown while the top window was displayed, so we want to ignore
7113 // it here because this is just a very transient change and it
7114 // will quickly lose focus once it correctly gets hidden.
7115 return 0;
7116 }
John Spurlock32beb2c2013-03-11 10:16:47 -04007117
John Spurlock1db8b682014-02-18 11:18:59 -05007118 int tmpVisibility = PolicyControl.getSystemUiVisibility(win, null)
Dianne Hackborne26ab702011-10-16 13:21:33 -07007119 & ~mResettingSystemUiFlags
7120 & ~mForceClearedSystemUiFlags;
John Spurlock79da8332013-09-20 12:04:47 -04007121 if (mForcingShowNavBar && win.getSurfaceLayer() < mForcingShowNavBarLayer) {
John Spurlockc6d1c602014-01-17 15:22:06 -05007122 tmpVisibility &= ~PolicyControl.adjustClearableFlags(win, View.SYSTEM_UI_CLEARABLE_FLAGS);
Dianne Hackborn891d3fb2013-01-09 18:31:37 -08007123 }
Thanh Hai Mai6c009f52015-09-01 16:27:32 -07007124
7125 if (mUiMode == Configuration.UI_MODE_TYPE_CAR) {
7126 tmpVisibility |= StatusBarManager.DISABLE_RECENT;
7127 }
7128
Jorim Jaggi86905582016-02-09 21:36:09 -08007129 final int fullscreenVisibility = updateLightStatusBarLw(0 /* vis */,
7130 mTopFullscreenOpaqueWindowState, mTopFullscreenOpaqueOrDimmingWindowState);
7131 final int dockedVisibility = updateLightStatusBarLw(0 /* vis */,
7132 mTopDockedOpaqueWindowState, mTopDockedOpaqueOrDimmingWindowState);
7133 mWindowManagerFuncs.getStackBounds(HOME_STACK_ID, mNonDockedStackBounds);
7134 mWindowManagerFuncs.getStackBounds(DOCKED_STACK_ID, mDockedStackBounds);
John Spurlock79da8332013-09-20 12:04:47 -04007135 final int visibility = updateSystemBarsLw(win, mLastSystemUiFlags, tmpVisibility);
John Spurlockad3e6cb2013-04-30 08:47:43 -04007136 final int diff = visibility ^ mLastSystemUiFlags;
Jorim Jaggi86905582016-02-09 21:36:09 -08007137 final int fullscreenDiff = fullscreenVisibility ^ mLastFullscreenStackSysUiFlags;
7138 final int dockedDiff = dockedVisibility ^ mLastDockedStackSysUiFlags;
John Spurlock79da8332013-09-20 12:04:47 -04007139 final boolean needsMenu = win.getNeedsMenuLw(mTopFullscreenOpaqueWindowState);
Jorim Jaggi86905582016-02-09 21:36:09 -08007140 if (diff == 0 && fullscreenDiff == 0 && dockedDiff == 0 && mLastFocusNeedsMenu == needsMenu
7141 && mFocusedApp == win.getAppToken()
7142 && mLastNonDockedStackBounds.equals(mNonDockedStackBounds)
7143 && mLastDockedStackBounds.equals(mDockedStackBounds)) {
Dianne Hackborndf89e652011-10-06 22:35:11 -07007144 return 0;
7145 }
Dianne Hackborne26ab702011-10-16 13:21:33 -07007146 mLastSystemUiFlags = visibility;
Jorim Jaggi86905582016-02-09 21:36:09 -08007147 mLastFullscreenStackSysUiFlags = fullscreenVisibility;
7148 mLastDockedStackSysUiFlags = dockedVisibility;
Dianne Hackborn4eff8d32011-11-10 19:38:40 -08007149 mLastFocusNeedsMenu = needsMenu;
John Spurlock79da8332013-09-20 12:04:47 -04007150 mFocusedApp = win.getAppToken();
Jorim Jaggi86905582016-02-09 21:36:09 -08007151 final Rect fullscreenStackBounds = new Rect(mNonDockedStackBounds);
7152 final Rect dockedStackBounds = new Rect(mDockedStackBounds);
Dianne Hackborndf89e652011-10-06 22:35:11 -07007153 mHandler.post(new Runnable() {
Craig Mautnereda67292013-04-28 13:50:14 -07007154 @Override
Dianne Hackborndf89e652011-10-06 22:35:11 -07007155 public void run() {
Jorim Jaggi86905582016-02-09 21:36:09 -08007156 StatusBarManagerInternal statusbar = getStatusBarManagerInternal();
7157 if (statusbar != null) {
7158 statusbar.setSystemUiVisibility(visibility, fullscreenVisibility,
7159 dockedVisibility, 0xffffffff, fullscreenStackBounds,
7160 dockedStackBounds, win.toString());
7161 statusbar.topAppWindowChanged(needsMenu);
Joe Onorato664644d2011-01-23 17:53:23 -08007162 }
Dianne Hackborndf89e652011-10-06 22:35:11 -07007163 }
7164 });
7165 return diff;
Joe Onorato664644d2011-01-23 17:53:23 -08007166 }
7167
Jorim Jaggi86905582016-02-09 21:36:09 -08007168 private int updateLightStatusBarLw(int vis, WindowState opaque, WindowState opaqueOrDimming) {
Adrian Rooscd3884d2015-02-18 17:25:23 +01007169 WindowState statusColorWin = isStatusBarKeyguard() && !mHideLockScreen
7170 ? mStatusBar
Jorim Jaggi86905582016-02-09 21:36:09 -08007171 : opaqueOrDimming;
Adrian Rooscd3884d2015-02-18 17:25:23 +01007172
7173 if (statusColorWin != null) {
Jorim Jaggi86905582016-02-09 21:36:09 -08007174 if (statusColorWin == opaque) {
Adrian Rooscd3884d2015-02-18 17:25:23 +01007175 // If the top fullscreen-or-dimming window is also the top fullscreen, respect
7176 // its light flag.
7177 vis &= ~View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR;
7178 vis |= PolicyControl.getSystemUiVisibility(statusColorWin, null)
7179 & View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR;
7180 } else if (statusColorWin != null && statusColorWin.isDimming()) {
7181 // Otherwise if it's dimming, clear the light flag.
7182 vis &= ~View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR;
7183 }
7184 }
7185 return vis;
7186 }
7187
John Spurlock79da8332013-09-20 12:04:47 -04007188 private int updateSystemBarsLw(WindowState win, int oldVis, int vis) {
Wale Ogunwale6e94a9e2015-10-07 15:35:49 -07007189 final boolean dockedStackVisible = mWindowManagerInternal.isStackVisible(DOCKED_STACK_ID);
7190 final boolean freeformStackVisible =
7191 mWindowManagerInternal.isStackVisible(FREEFORM_WORKSPACE_STACK_ID);
Jorim Jaggi9511b0f2016-01-29 19:12:44 -08007192 final boolean resizing = mWindowManagerInternal.isDockedDividerResizing();
7193
7194 // We need to force system bars when the docked stack is visible, when the freeform stack
7195 // is visible but also when we are resizing for the transitions when docked stack
7196 // visibility changes.
Jorim Jaggi0ffd49c2016-02-12 15:04:21 -08007197 mForceShowSystemBars = dockedStackVisible || freeformStackVisible || resizing;
Yorke Lee9b2ffb32016-03-07 20:42:01 -08007198 final boolean forceOpaqueStatusBar = mForceShowSystemBars && !mForceStatusBarFromKeyguard;
Wale Ogunwale6e94a9e2015-10-07 15:35:49 -07007199
John Spurlockbd957402013-10-03 11:38:39 -04007200 // apply translucent bar vis flags
Jorim Jaggi380ecb82014-03-14 17:25:20 +01007201 WindowState transWin = isStatusBarKeyguard() && !mHideLockScreen
7202 ? mStatusBar
John Spurlockbd957402013-10-03 11:38:39 -04007203 : mTopFullscreenOpaqueWindowState;
7204 vis = mStatusBarController.applyTranslucentFlagLw(transWin, vis, oldVis);
7205 vis = mNavigationBarController.applyTranslucentFlagLw(transWin, vis, oldVis);
7206
John Spurlock27735a42013-08-14 17:57:38 -04007207 // prevent status bar interaction from clearing certain flags
Selim Cinekf83e8242015-05-19 18:08:14 -07007208 int type = win.getAttrs().type;
7209 boolean statusBarHasFocus = type == TYPE_STATUS_BAR;
John Spurlock08ffcf52014-07-11 10:13:46 -04007210 if (statusBarHasFocus && !isStatusBarKeyguard()) {
John Spurlockad3e6cb2013-04-30 08:47:43 -04007211 int flags = View.SYSTEM_UI_FLAG_FULLSCREEN
7212 | View.SYSTEM_UI_FLAG_HIDE_NAVIGATION
John Spurlockcfc359a2013-09-05 10:42:03 -04007213 | View.SYSTEM_UI_FLAG_IMMERSIVE
Jorim Jaggi73fef8d2015-02-16 17:32:28 +01007214 | View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY
7215 | View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR;
John Spurlock08ffcf52014-07-11 10:13:46 -04007216 if (mHideLockScreen) {
Jorim Jaggi5cf17872014-03-26 18:31:48 +01007217 flags |= View.STATUS_BAR_TRANSLUCENT | View.NAVIGATION_BAR_TRANSLUCENT;
7218 }
John Spurlockbd957402013-10-03 11:38:39 -04007219 vis = (vis & ~flags) | (oldVis & flags);
John Spurlockad3e6cb2013-04-30 08:47:43 -04007220 }
John Spurlockad3e6cb2013-04-30 08:47:43 -04007221
Wale Ogunwale6e94a9e2015-10-07 15:35:49 -07007222 if ((!areTranslucentBarsAllowed() && transWin != mStatusBar)
Yorke Lee9b2ffb32016-03-07 20:42:01 -08007223 || forceOpaqueStatusBar) {
7224 vis &= ~(View.STATUS_BAR_TRANSLUCENT | View.STATUS_BAR_TRANSPARENT);
Alan Viverette5a0f4ec2013-10-07 15:10:29 -07007225 }
7226
Yorke Lee9b2ffb32016-03-07 20:42:01 -08007227 vis = configureNavBarOpacity(vis, dockedStackVisible, freeformStackVisible, resizing);
Yorke Lee2e4b7322016-03-02 17:33:06 -08007228
Jorim Jaggi4fa78922015-11-30 17:13:56 -08007229 if (mForceWindowDrawsStatusBarBackground) {
7230 vis |= View.STATUS_BAR_TRANSPARENT;
7231 vis &= ~View.STATUS_BAR_TRANSLUCENT;
7232 }
7233
John Spurlock27735a42013-08-14 17:57:38 -04007234 // update status bar
John Spurlockf1a36642013-10-12 17:50:42 -04007235 boolean immersiveSticky =
7236 (vis & View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY) != 0;
Wale Ogunwale6e94a9e2015-10-07 15:35:49 -07007237 final boolean hideStatusBarWM =
7238 mTopFullscreenOpaqueWindowState != null
7239 && (PolicyControl.getWindowFlags(mTopFullscreenOpaqueWindowState, null)
John Spurlock27735a42013-08-14 17:57:38 -04007240 & WindowManager.LayoutParams.FLAG_FULLSCREEN) != 0;
Wale Ogunwale6e94a9e2015-10-07 15:35:49 -07007241 final boolean hideStatusBarSysui =
John Spurlock27735a42013-08-14 17:57:38 -04007242 (vis & View.SYSTEM_UI_FLAG_FULLSCREEN) != 0;
Wale Ogunwale6e94a9e2015-10-07 15:35:49 -07007243 final boolean hideNavBarSysui =
John Spurlockf1a36642013-10-12 17:50:42 -04007244 (vis & View.SYSTEM_UI_FLAG_HIDE_NAVIGATION) != 0;
John Spurlockad3e6cb2013-04-30 08:47:43 -04007245
Wale Ogunwale6e94a9e2015-10-07 15:35:49 -07007246 final boolean transientStatusBarAllowed = mStatusBar != null
Jorim Jaggi0ffd49c2016-02-12 15:04:21 -08007247 && (statusBarHasFocus || (!mForceShowSystemBars
Wale Ogunwale6e94a9e2015-10-07 15:35:49 -07007248 && (hideStatusBarWM || (hideStatusBarSysui && immersiveSticky))));
John Spurlock27735a42013-08-14 17:57:38 -04007249
Wale Ogunwale6e94a9e2015-10-07 15:35:49 -07007250 final boolean transientNavBarAllowed = mNavigationBar != null
Jorim Jaggi0ffd49c2016-02-12 15:04:21 -08007251 && !mForceShowSystemBars && hideNavBarSysui && immersiveSticky;
John Spurlockf1a36642013-10-12 17:50:42 -04007252
Adrian Roosddc8b272015-05-21 16:28:27 -07007253 final long now = SystemClock.uptimeMillis();
7254 final boolean pendingPanic = mPendingPanicGestureUptime != 0
7255 && now - mPendingPanicGestureUptime <= PANIC_GESTURE_EXPIRATION;
7256 if (pendingPanic && hideNavBarSysui && !isStatusBarKeyguard() && mKeyguardDrawComplete) {
7257 // The user performed the panic gesture recently, we're about to hide the bars,
7258 // we're no longer on the Keyguard and the screen is ready. We can now request the bars.
7259 mPendingPanicGestureUptime = 0;
7260 mStatusBarController.showTransient();
7261 mNavigationBarController.showTransient();
7262 }
7263
Wale Ogunwale6e94a9e2015-10-07 15:35:49 -07007264 final boolean denyTransientStatus = mStatusBarController.isTransientShowRequested()
John Spurlockf1a36642013-10-12 17:50:42 -04007265 && !transientStatusBarAllowed && hideStatusBarSysui;
Wale Ogunwale6e94a9e2015-10-07 15:35:49 -07007266 final boolean denyTransientNav = mNavigationBarController.isTransientShowRequested()
John Spurlockf1a36642013-10-12 17:50:42 -04007267 && !transientNavBarAllowed;
Jorim Jaggi0ffd49c2016-02-12 15:04:21 -08007268 if (denyTransientStatus || denyTransientNav || mForceShowSystemBars) {
John Spurlock27735a42013-08-14 17:57:38 -04007269 // clear the clearable flags instead
John Spurlockf1a36642013-10-12 17:50:42 -04007270 clearClearableFlagsLw();
tiger_huangc58d7562014-10-23 20:24:19 +08007271 vis &= ~View.SYSTEM_UI_CLEARABLE_FLAGS;
John Spurlockad3e6cb2013-04-30 08:47:43 -04007272 }
John Spurlock27735a42013-08-14 17:57:38 -04007273
Selim Cinekf98702e2015-05-20 22:48:40 -07007274 final boolean immersive = (vis & View.SYSTEM_UI_FLAG_IMMERSIVE) != 0;
7275 immersiveSticky = (vis & View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY) != 0;
7276 final boolean navAllowedHidden = immersive || immersiveSticky;
7277
Selim Cinekd6623612015-05-22 18:56:22 -07007278 if (hideNavBarSysui && !navAllowedHidden && windowTypeToLayerLw(win.getBaseType())
7279 > windowTypeToLayerLw(TYPE_INPUT_CONSUMER)) {
Selim Cinekf98702e2015-05-20 22:48:40 -07007280 // We can't hide the navbar from this window otherwise the input consumer would not get
7281 // the input events.
7282 vis = (vis & ~View.SYSTEM_UI_FLAG_HIDE_NAVIGATION);
7283 }
7284
John Spurlock27735a42013-08-14 17:57:38 -04007285 vis = mStatusBarController.updateVisibilityLw(transientStatusBarAllowed, oldVis, vis);
7286
7287 // update navigation bar
John Spurlockf1a36642013-10-12 17:50:42 -04007288 boolean oldImmersiveMode = isImmersiveMode(oldVis);
7289 boolean newImmersiveMode = isImmersiveMode(vis);
7290 if (win != null && oldImmersiveMode != newImmersiveMode) {
John Spurlock79da8332013-09-20 12:04:47 -04007291 final String pkg = win.getOwningPackage();
Maurice Lam99c6e072014-04-28 18:24:28 -07007292 mImmersiveModeConfirmation.immersiveModeChanged(pkg, newImmersiveMode,
7293 isUserSetupComplete());
John Spurlock34e13d92013-08-10 06:52:28 -04007294 }
John Spurlock27735a42013-08-14 17:57:38 -04007295
John Spurlockf1a36642013-10-12 17:50:42 -04007296 vis = mNavigationBarController.updateVisibilityLw(transientNavBarAllowed, oldVis, vis);
7297
John Spurlocke1f366f2013-08-05 12:22:40 -04007298 return vis;
John Spurlockad3e6cb2013-04-30 08:47:43 -04007299 }
7300
Yorke Lee9b2ffb32016-03-07 20:42:01 -08007301 /**
7302 * @return the current visibility flags with the nav-bar opacity related flags toggled based
7303 * on the nav bar opacity rules chosen by {@link #mNavBarOpacityMode}.
7304 */
7305 private int configureNavBarOpacity(int visibility, boolean dockedStackVisible,
7306 boolean freeformStackVisible, boolean isDockedDividerResizing) {
7307 if (mNavBarOpacityMode == NAV_BAR_OPAQUE_WHEN_FREEFORM_OR_DOCKED) {
7308 if (dockedStackVisible || freeformStackVisible || isDockedDividerResizing) {
7309 visibility = setNavBarOpaqueFlag(visibility);
7310 }
7311 } else if (mNavBarOpacityMode == NAV_BAR_TRANSLUCENT_WHEN_FREEFORM_OPAQUE_OTHERWISE) {
7312 if (isDockedDividerResizing) {
7313 visibility = setNavBarOpaqueFlag(visibility);
7314 } else if (freeformStackVisible) {
7315 visibility = setNavBarTranslucentFlag(visibility);
7316 } else {
7317 visibility = setNavBarOpaqueFlag(visibility);
7318 }
7319 }
7320
7321 if (!areTranslucentBarsAllowed()) {
7322 visibility &= ~View.NAVIGATION_BAR_TRANSLUCENT;
7323 }
7324 return visibility;
7325 }
7326
7327 private int setNavBarOpaqueFlag(int visibility) {
7328 return visibility &= ~(View.NAVIGATION_BAR_TRANSLUCENT | View.NAVIGATION_BAR_TRANSPARENT);
7329 }
7330
7331 private int setNavBarTranslucentFlag(int visibility) {
7332 visibility &= ~View.NAVIGATION_BAR_TRANSPARENT;
7333 return visibility |= View.NAVIGATION_BAR_TRANSLUCENT;
7334 }
7335
John Spurlockf1a36642013-10-12 17:50:42 -04007336 private void clearClearableFlagsLw() {
7337 int newVal = mResettingSystemUiFlags | View.SYSTEM_UI_CLEARABLE_FLAGS;
7338 if (newVal != mResettingSystemUiFlags) {
7339 mResettingSystemUiFlags = newVal;
7340 mWindowManagerFuncs.reevaluateStatusBarVisibility();
7341 }
7342 }
7343
7344 private boolean isImmersiveMode(int vis) {
7345 final int flags = View.SYSTEM_UI_FLAG_IMMERSIVE | View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY;
John Spurlock34e13d92013-08-10 06:52:28 -04007346 return mNavigationBar != null
7347 && (vis & View.SYSTEM_UI_FLAG_HIDE_NAVIGATION) != 0
Daniel Sandler900ece52013-10-18 15:53:27 -04007348 && (vis & flags) != 0
7349 && canHideNavigationBar();
John Spurlock34e13d92013-08-10 06:52:28 -04007350 }
7351
Alan Viverette5a0f4ec2013-10-07 15:10:29 -07007352 /**
Daniel Sandlerdd73ee42013-10-11 22:19:59 -04007353 * @return whether the navigation or status bar can be made translucent
7354 *
7355 * This should return true unless touch exploration is not enabled or
7356 * R.boolean.config_enableTranslucentDecor is false.
Alan Viverette5a0f4ec2013-10-07 15:10:29 -07007357 */
Daniel Sandlerdd73ee42013-10-11 22:19:59 -04007358 private boolean areTranslucentBarsAllowed() {
Alan Viverette817f3cd2015-08-13 11:40:14 -04007359 return mTranslucentDecorEnabled;
Alan Viverette5a0f4ec2013-10-07 15:10:29 -07007360 }
7361
Daniel Sandler0c4ccff2011-10-19 16:39:14 -04007362 // Use this instead of checking config_showNavigationBar so that it can be consistently
7363 // overridden by qemu.hw.mainkeys in the emulator.
Craig Mautnereda67292013-04-28 13:50:14 -07007364 @Override
Daniel Sandler0c4ccff2011-10-19 16:39:14 -04007365 public boolean hasNavigationBar() {
7366 return mHasNavigationBar;
7367 }
7368
satok1bc0a492012-04-25 22:47:12 +09007369 @Override
7370 public void setLastInputMethodWindowLw(WindowState ime, WindowState target) {
7371 mLastInputMethodWindow = ime;
7372 mLastInputMethodTargetWindow = target;
7373 }
7374
Craig Mautnerf1b67412012-09-19 13:18:29 -07007375 @Override
Satoshi Kataoka658c7b82013-10-10 17:03:51 +09007376 public int getInputMethodWindowVisibleHeightLw() {
7377 return mDockBottom - mCurBottom;
7378 }
7379
7380 @Override
Craig Mautnerf1b67412012-09-19 13:18:29 -07007381 public void setCurrentUserLw(int newUserId) {
Craig Mautnerd625ab22013-09-06 13:40:31 -07007382 mCurrentUserId = newUserId;
Jim Miller5ecd8112013-01-09 18:50:26 -08007383 if (mKeyguardDelegate != null) {
7384 mKeyguardDelegate.setCurrentUser(newUserId);
Craig Mautnerf1b67412012-09-19 13:18:29 -07007385 }
John Spurlock13451a22012-09-28 14:40:41 -04007386 if (mStatusBarService != null) {
7387 try {
7388 mStatusBarService.setCurrentUser(newUserId);
7389 } catch (RemoteException e) {
7390 // oh well
7391 }
7392 }
Dianne Hackborn2ea9bae2012-11-02 18:43:48 -07007393 setLastInputMethodWindowLw(null, null);
Craig Mautnerf1b67412012-09-19 13:18:29 -07007394 }
7395
7396 @Override
Svetoslav Ganov545252f2012-12-10 18:29:24 -08007397 public boolean canMagnifyWindow(int windowType) {
7398 switch (windowType) {
7399 case WindowManager.LayoutParams.TYPE_INPUT_METHOD:
7400 case WindowManager.LayoutParams.TYPE_INPUT_METHOD_DIALOG:
7401 case WindowManager.LayoutParams.TYPE_NAVIGATION_BAR:
7402 case WindowManager.LayoutParams.TYPE_MAGNIFICATION_OVERLAY: {
7403 return false;
7404 }
7405 }
7406 return true;
7407 }
7408
7409 @Override
7410 public boolean isTopLevelWindow(int windowType) {
7411 if (windowType >= WindowManager.LayoutParams.FIRST_SUB_WINDOW
7412 && windowType <= WindowManager.LayoutParams.LAST_SUB_WINDOW) {
7413 return (windowType == WindowManager.LayoutParams.TYPE_APPLICATION_ATTACHED_DIALOG);
7414 }
7415 return true;
7416 }
7417
Jim Miller4eeb4f62012-11-08 00:04:29 -08007418 @Override
Jeff Brownd7a04de2012-06-17 14:17:52 -07007419 public void dump(String prefix, PrintWriter pw, String[] args) {
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08007420 pw.print(prefix); pw.print("mSafeMode="); pw.print(mSafeMode);
Dianne Hackbornba24e4d2011-09-01 11:17:06 -07007421 pw.print(" mSystemReady="); pw.print(mSystemReady);
7422 pw.print(" mSystemBooted="); pw.println(mSystemBooted);
Jeff Brown2e7760e2012-04-11 15:14:55 -07007423 pw.print(prefix); pw.print("mLidState="); pw.print(mLidState);
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08007424 pw.print(" mLidOpenRotation="); pw.print(mLidOpenRotation);
Michael Wright3818c922014-09-02 13:59:07 -07007425 pw.print(" mCameraLensCoverState="); pw.print(mCameraLensCoverState);
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08007426 pw.print(" mHdmiPlugged="); pw.println(mHdmiPlugged);
Dianne Hackborne26ab702011-10-16 13:21:33 -07007427 if (mLastSystemUiFlags != 0 || mResettingSystemUiFlags != 0
7428 || mForceClearedSystemUiFlags != 0) {
7429 pw.print(prefix); pw.print("mLastSystemUiFlags=0x");
7430 pw.print(Integer.toHexString(mLastSystemUiFlags));
7431 pw.print(" mResettingSystemUiFlags=0x");
7432 pw.print(Integer.toHexString(mResettingSystemUiFlags));
7433 pw.print(" mForceClearedSystemUiFlags=0x");
7434 pw.println(Integer.toHexString(mForceClearedSystemUiFlags));
Dianne Hackborndf89e652011-10-06 22:35:11 -07007435 }
Dianne Hackborn4eff8d32011-11-10 19:38:40 -08007436 if (mLastFocusNeedsMenu) {
7437 pw.print(prefix); pw.print("mLastFocusNeedsMenu=");
7438 pw.println(mLastFocusNeedsMenu);
7439 }
Jeff Browna20dda42014-05-27 20:57:24 -07007440 pw.print(prefix); pw.print("mWakeGestureEnabledSetting=");
7441 pw.println(mWakeGestureEnabledSetting);
7442
Jeff Brownbcdfc622014-03-06 19:13:04 -08007443 pw.print(prefix); pw.print("mSupportAutoRotation="); pw.println(mSupportAutoRotation);
Daniel Sandler6396c722013-04-16 20:19:09 -04007444 pw.print(prefix); pw.print("mUiMode="); pw.print(mUiMode);
7445 pw.print(" mDockMode="); pw.print(mDockMode);
keunyounga7710492015-09-23 11:33:58 -07007446 pw.print(" mEnableCarDockHomeCapture="); pw.print(mEnableCarDockHomeCapture);
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08007447 pw.print(" mCarDockRotation="); pw.print(mCarDockRotation);
7448 pw.print(" mDeskDockRotation="); pw.println(mDeskDockRotation);
7449 pw.print(prefix); pw.print("mUserRotationMode="); pw.print(mUserRotationMode);
7450 pw.print(" mUserRotation="); pw.print(mUserRotation);
Daniel Sandler2ed6ad62011-02-22 14:54:17 -05007451 pw.print(" mAllowAllRotations="); pw.println(mAllowAllRotations);
Dianne Hackborn6e2281d2012-06-19 17:48:32 -07007452 pw.print(prefix); pw.print("mCurrentAppOrientation="); pw.println(mCurrentAppOrientation);
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08007453 pw.print(prefix); pw.print("mCarDockEnablesAccelerometer=");
7454 pw.print(mCarDockEnablesAccelerometer);
7455 pw.print(" mDeskDockEnablesAccelerometer=");
7456 pw.println(mDeskDockEnablesAccelerometer);
7457 pw.print(prefix); pw.print("mLidKeyboardAccessibility=");
7458 pw.print(mLidKeyboardAccessibility);
7459 pw.print(" mLidNavigationAccessibility="); pw.print(mLidNavigationAccessibility);
Edward Savage-Jones7def60d2015-11-13 13:27:03 +01007460 pw.print(" mLidControlsScreenLock="); pw.println(mLidControlsScreenLock);
Dianne Hackborn6e2281d2012-06-19 17:48:32 -07007461 pw.print(" mLidControlsSleep="); pw.println(mLidControlsSleep);
Jeff Brown6d8fd272014-05-20 21:24:38 -07007462 pw.print(prefix);
Anthony Hugh34f09ca2016-03-04 12:03:37 -08007463 pw.print(" mLongPressOnBackBehavior="); pw.println(mLongPressOnBackBehavior);
7464 pw.print(prefix);
Jeff Brown6d8fd272014-05-20 21:24:38 -07007465 pw.print("mShortPressOnPowerBehavior="); pw.print(mShortPressOnPowerBehavior);
7466 pw.print(" mLongPressOnPowerBehavior="); pw.println(mLongPressOnPowerBehavior);
Jeff Brown13f00f02014-10-31 14:45:50 -07007467 pw.print(prefix);
7468 pw.print("mDoublePressOnPowerBehavior="); pw.print(mDoublePressOnPowerBehavior);
7469 pw.print(" mTriplePressOnPowerBehavior="); pw.println(mTriplePressOnPowerBehavior);
Jeff Brown6d8fd272014-05-20 21:24:38 -07007470 pw.print(prefix); pw.print("mHasSoftInput="); pw.println(mHasSoftInput);
Jeff Brown3ee549c2014-09-22 20:14:39 -07007471 pw.print(prefix); pw.print("mAwake="); pw.println(mAwake);
7472 pw.print(prefix); pw.print("mScreenOnEarly="); pw.print(mScreenOnEarly);
7473 pw.print(" mScreenOnFully="); pw.println(mScreenOnFully);
7474 pw.print(prefix); pw.print("mKeyguardDrawComplete="); pw.print(mKeyguardDrawComplete);
7475 pw.print(" mWindowManagerDrawComplete="); pw.println(mWindowManagerDrawComplete);
7476 pw.print(prefix); pw.print("mOrientationSensorEnabled=");
7477 pw.println(mOrientationSensorEnabled);
Dianne Hackbornc652de82013-02-15 16:32:56 -08007478 pw.print(prefix); pw.print("mOverscanScreen=("); pw.print(mOverscanScreenLeft);
7479 pw.print(","); pw.print(mOverscanScreenTop);
7480 pw.print(") "); pw.print(mOverscanScreenWidth);
7481 pw.print("x"); pw.println(mOverscanScreenHeight);
7482 if (mOverscanLeft != 0 || mOverscanTop != 0
7483 || mOverscanRight != 0 || mOverscanBottom != 0) {
7484 pw.print(prefix); pw.print("mOverscan left="); pw.print(mOverscanLeft);
7485 pw.print(" top="); pw.print(mOverscanTop);
7486 pw.print(" right="); pw.print(mOverscanRight);
7487 pw.print(" bottom="); pw.println(mOverscanBottom);
7488 }
Dianne Hackborn313440842013-02-19 19:22:59 -08007489 pw.print(prefix); pw.print("mRestrictedOverscanScreen=(");
7490 pw.print(mRestrictedOverscanScreenLeft);
7491 pw.print(","); pw.print(mRestrictedOverscanScreenTop);
7492 pw.print(") "); pw.print(mRestrictedOverscanScreenWidth);
7493 pw.print("x"); pw.println(mRestrictedOverscanScreenHeight);
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08007494 pw.print(prefix); pw.print("mUnrestrictedScreen=("); pw.print(mUnrestrictedScreenLeft);
7495 pw.print(","); pw.print(mUnrestrictedScreenTop);
7496 pw.print(") "); pw.print(mUnrestrictedScreenWidth);
7497 pw.print("x"); pw.println(mUnrestrictedScreenHeight);
7498 pw.print(prefix); pw.print("mRestrictedScreen=("); pw.print(mRestrictedScreenLeft);
7499 pw.print(","); pw.print(mRestrictedScreenTop);
7500 pw.print(") "); pw.print(mRestrictedScreenWidth);
7501 pw.print("x"); pw.println(mRestrictedScreenHeight);
Dianne Hackborn5b5cc4d2012-05-16 13:15:00 -07007502 pw.print(prefix); pw.print("mStableFullscreen=("); pw.print(mStableFullscreenLeft);
7503 pw.print(","); pw.print(mStableFullscreenTop);
7504 pw.print(")-("); pw.print(mStableFullscreenRight);
7505 pw.print(","); pw.print(mStableFullscreenBottom); pw.println(")");
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07007506 pw.print(prefix); pw.print("mStable=("); pw.print(mStableLeft);
7507 pw.print(","); pw.print(mStableTop);
7508 pw.print(")-("); pw.print(mStableRight);
7509 pw.print(","); pw.print(mStableBottom); pw.println(")");
Dianne Hackborn5c58de32012-04-28 19:52:37 -07007510 pw.print(prefix); pw.print("mSystem=("); pw.print(mSystemLeft);
7511 pw.print(","); pw.print(mSystemTop);
7512 pw.print(")-("); pw.print(mSystemRight);
7513 pw.print(","); pw.print(mSystemBottom); pw.println(")");
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08007514 pw.print(prefix); pw.print("mCur=("); pw.print(mCurLeft);
7515 pw.print(","); pw.print(mCurTop);
7516 pw.print(")-("); pw.print(mCurRight);
7517 pw.print(","); pw.print(mCurBottom); pw.println(")");
7518 pw.print(prefix); pw.print("mContent=("); pw.print(mContentLeft);
7519 pw.print(","); pw.print(mContentTop);
7520 pw.print(")-("); pw.print(mContentRight);
7521 pw.print(","); pw.print(mContentBottom); pw.println(")");
Dianne Hackborne30e02f2014-05-27 18:24:45 -07007522 pw.print(prefix); pw.print("mVoiceContent=("); pw.print(mVoiceContentLeft);
7523 pw.print(","); pw.print(mVoiceContentTop);
7524 pw.print(")-("); pw.print(mVoiceContentRight);
7525 pw.print(","); pw.print(mVoiceContentBottom); pw.println(")");
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08007526 pw.print(prefix); pw.print("mDock=("); pw.print(mDockLeft);
7527 pw.print(","); pw.print(mDockTop);
7528 pw.print(")-("); pw.print(mDockRight);
7529 pw.print(","); pw.print(mDockBottom); pw.println(")");
Dianne Hackborn5c58de32012-04-28 19:52:37 -07007530 pw.print(prefix); pw.print("mDockLayer="); pw.print(mDockLayer);
7531 pw.print(" mStatusBarLayer="); pw.println(mStatusBarLayer);
Dianne Hackborn7ad44382012-10-18 17:46:00 -07007532 pw.print(prefix); pw.print("mShowingLockscreen="); pw.print(mShowingLockscreen);
7533 pw.print(" mShowingDream="); pw.print(mShowingDream);
Jeff Brown061ea992015-04-17 19:55:47 -07007534 pw.print(" mDreamingLockscreen="); pw.print(mDreamingLockscreen);
7535 pw.print(" mDreamingSleepToken="); pw.println(mDreamingSleepToken);
Dianne Hackborn2ea9bae2012-11-02 18:43:48 -07007536 if (mLastInputMethodWindow != null) {
7537 pw.print(prefix); pw.print("mLastInputMethodWindow=");
7538 pw.println(mLastInputMethodWindow);
7539 }
7540 if (mLastInputMethodTargetWindow != null) {
7541 pw.print(prefix); pw.print("mLastInputMethodTargetWindow=");
7542 pw.println(mLastInputMethodTargetWindow);
7543 }
7544 if (mStatusBar != null) {
7545 pw.print(prefix); pw.print("mStatusBar=");
Dianne Hackbornae6688b2015-02-11 17:02:41 -08007546 pw.print(mStatusBar); pw.print(" isStatusBarKeyguard=");
7547 pw.println(isStatusBarKeyguard());
Dianne Hackborn2ea9bae2012-11-02 18:43:48 -07007548 }
7549 if (mNavigationBar != null) {
7550 pw.print(prefix); pw.print("mNavigationBar=");
7551 pw.println(mNavigationBar);
7552 }
Dianne Hackborn2ea9bae2012-11-02 18:43:48 -07007553 if (mFocusedWindow != null) {
7554 pw.print(prefix); pw.print("mFocusedWindow=");
7555 pw.println(mFocusedWindow);
7556 }
7557 if (mFocusedApp != null) {
7558 pw.print(prefix); pw.print("mFocusedApp=");
7559 pw.println(mFocusedApp);
7560 }
7561 if (mWinDismissingKeyguard != null) {
7562 pw.print(prefix); pw.print("mWinDismissingKeyguard=");
7563 pw.println(mWinDismissingKeyguard);
7564 }
7565 if (mTopFullscreenOpaqueWindowState != null) {
7566 pw.print(prefix); pw.print("mTopFullscreenOpaqueWindowState=");
7567 pw.println(mTopFullscreenOpaqueWindowState);
7568 }
Adrian Rooscd3884d2015-02-18 17:25:23 +01007569 if (mTopFullscreenOpaqueOrDimmingWindowState != null) {
7570 pw.print(prefix); pw.print("mTopFullscreenOpaqueOrDimmingWindowState=");
7571 pw.println(mTopFullscreenOpaqueOrDimmingWindowState);
7572 }
Dianne Hackborn891d3fb2013-01-09 18:31:37 -08007573 if (mForcingShowNavBar) {
7574 pw.print(prefix); pw.print("mForcingShowNavBar=");
7575 pw.println(mForcingShowNavBar); pw.print( "mForcingShowNavBarLayer=");
7576 pw.println(mForcingShowNavBarLayer);
7577 }
Dianne Hackborn7ad44382012-10-18 17:46:00 -07007578 pw.print(prefix); pw.print("mTopIsFullscreen="); pw.print(mTopIsFullscreen);
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08007579 pw.print(" mHideLockScreen="); pw.println(mHideLockScreen);
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07007580 pw.print(prefix); pw.print("mForceStatusBar="); pw.print(mForceStatusBar);
7581 pw.print(" mForceStatusBarFromKeyguard=");
7582 pw.println(mForceStatusBarFromKeyguard);
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08007583 pw.print(prefix); pw.print("mDismissKeyguard="); pw.print(mDismissKeyguard);
Craig Mautnerad09bcc2012-10-08 13:33:11 -07007584 pw.print(" mWinDismissingKeyguard="); pw.print(mWinDismissingKeyguard);
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08007585 pw.print(" mHomePressed="); pw.println(mHomePressed);
7586 pw.print(prefix); pw.print("mAllowLockscreenWhenOn="); pw.print(mAllowLockscreenWhenOn);
7587 pw.print(" mLockScreenTimeout="); pw.print(mLockScreenTimeout);
7588 pw.print(" mLockScreenTimerActive="); pw.println(mLockScreenTimerActive);
7589 pw.print(prefix); pw.print("mEndcallBehavior="); pw.print(mEndcallBehavior);
7590 pw.print(" mIncallPowerBehavior="); pw.print(mIncallPowerBehavior);
7591 pw.print(" mLongPressOnHomeBehavior="); pw.println(mLongPressOnHomeBehavior);
7592 pw.print(prefix); pw.print("mLandscapeRotation="); pw.print(mLandscapeRotation);
7593 pw.print(" mSeascapeRotation="); pw.println(mSeascapeRotation);
7594 pw.print(prefix); pw.print("mPortraitRotation="); pw.print(mPortraitRotation);
7595 pw.print(" mUpsideDownRotation="); pw.println(mUpsideDownRotation);
Jeff Brownc82c89ed2013-04-17 17:18:15 -07007596 pw.print(prefix); pw.print("mDemoHdmiRotation="); pw.print(mDemoHdmiRotation);
7597 pw.print(" mDemoHdmiRotationLock="); pw.println(mDemoHdmiRotationLock);
7598 pw.print(prefix); pw.print("mUndockedHdmiRotation="); pw.println(mUndockedHdmiRotation);
Jeff Brown600f0032014-05-22 17:06:00 -07007599
Tim Kilbournd7c0c2e2014-05-29 16:08:10 -07007600 mGlobalKeyManager.dump(prefix, pw);
John Spurlock27735a42013-08-14 17:57:38 -04007601 mStatusBarController.dump(pw, prefix);
7602 mNavigationBarController.dump(pw, prefix);
John Spurlockc6d1c602014-01-17 15:22:06 -05007603 PolicyControl.dump(prefix, pw);
Jeff Brown600f0032014-05-22 17:06:00 -07007604
Jeff Browna20dda42014-05-27 20:57:24 -07007605 if (mWakeGestureListener != null) {
7606 mWakeGestureListener.dump(pw, prefix);
7607 }
Jeff Brown600f0032014-05-22 17:06:00 -07007608 if (mOrientationListener != null) {
7609 mOrientationListener.dump(pw, prefix);
7610 }
Filip Gruszczynskicfb31852015-02-25 21:47:12 +00007611 if (mBurnInProtectionHelper != null) {
7612 mBurnInProtectionHelper.dump(prefix, pw);
7613 }
Jorim Jaggi84dc08a2015-09-11 17:45:22 -07007614 if (mKeyguardDelegate != null) {
7615 mKeyguardDelegate.dump(prefix, pw);
7616 }
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08007617 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08007618}