blob: 0115a08cefe5568636910edf5b0d7020416407a3 [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.
2780 if (mNavigationBar != null
2781 && (win.getFrameLw().top + insets >= mNavigationBar.getFrameLw().top
2782 || win.getFrameLw().left + insets >= mNavigationBar.getFrameLw().left)) {
2783 return 0;
2784 }
2785 if (transit == TRANSIT_ENTER || transit == TRANSIT_SHOW) {
2786 return R.anim.fade_in;
2787 } else if (transit == TRANSIT_EXIT) {
2788 return R.anim.fade_out;
2789 } else {
2790 return 0;
2791 }
2792 }
2793
Craig Mautner3c174372013-02-21 17:54:37 -08002794 @Override
2795 public void selectRotationAnimationLw(int anim[]) {
2796 if (PRINT_ANIM) Slog.i(TAG, "selectRotationAnimation mTopFullscreen="
2797 + mTopFullscreenOpaqueWindowState + " rotationAnimation="
2798 + (mTopFullscreenOpaqueWindowState == null ?
2799 "0" : mTopFullscreenOpaqueWindowState.getAttrs().rotationAnimation));
2800 if (mTopFullscreenOpaqueWindowState != null && mTopIsFullscreen) {
2801 switch (mTopFullscreenOpaqueWindowState.getAttrs().rotationAnimation) {
2802 case ROTATION_ANIMATION_CROSSFADE:
2803 anim[0] = R.anim.rotation_animation_xfade_exit;
2804 anim[1] = R.anim.rotation_animation_enter;
2805 break;
2806 case ROTATION_ANIMATION_JUMPCUT:
2807 anim[0] = R.anim.rotation_animation_jump_exit;
2808 anim[1] = R.anim.rotation_animation_enter;
2809 break;
2810 case ROTATION_ANIMATION_ROTATE:
2811 default:
2812 anim[0] = anim[1] = 0;
2813 break;
2814 }
2815 } else {
2816 anim[0] = anim[1] = 0;
2817 }
2818 }
2819
2820 @Override
2821 public boolean validateRotationAnimationLw(int exitAnimId, int enterAnimId,
2822 boolean forceDefault) {
2823 switch (exitAnimId) {
2824 case R.anim.rotation_animation_xfade_exit:
2825 case R.anim.rotation_animation_jump_exit:
2826 // These are the only cases that matter.
2827 if (forceDefault) {
2828 return false;
2829 }
2830 int anim[] = new int[2];
2831 selectRotationAnimationLw(anim);
2832 return (exitAnimId == anim[0] && enterAnimId == anim[1]);
2833 default:
2834 return true;
2835 }
2836 }
2837
2838 @Override
Jorim Jaggi84a3e7a2014-08-13 17:58:58 +02002839 public Animation createForceHideEnterAnimation(boolean onWallpaper,
2840 boolean goingToNotificationShade) {
2841 if (goingToNotificationShade) {
2842 return AnimationUtils.loadAnimation(mContext, R.anim.lock_screen_behind_enter_fade_in);
Craig Mautnerb8340802014-11-04 15:32:57 -08002843 }
Craig Mautner276a6eb2014-11-04 15:32:57 -08002844
2845 AnimationSet set = (AnimationSet) AnimationUtils.loadAnimation(mContext, onWallpaper ?
2846 R.anim.lock_screen_behind_enter_wallpaper :
2847 R.anim.lock_screen_behind_enter);
2848
2849 // TODO: Use XML interpolators when we have log interpolators available in XML.
2850 final List<Animation> animations = set.getAnimations();
2851 for (int i = animations.size() - 1; i >= 0; --i) {
2852 animations.get(i).setInterpolator(mLogDecelerateInterpolator);
2853 }
2854
2855 return set;
Jorim Jaggi76a16232014-08-08 17:00:47 +02002856 }
2857
2858
2859 @Override
Jorim Jaggi84a3e7a2014-08-13 17:58:58 +02002860 public Animation createForceHideWallpaperExitAnimation(boolean goingToNotificationShade) {
2861 if (goingToNotificationShade) {
2862 return null;
2863 } else {
2864 return AnimationUtils.loadAnimation(mContext, R.anim.lock_screen_wallpaper_exit);
2865 }
Dianne Hackborn01ad2f42009-09-24 19:24:56 -07002866 }
John Spurlockc8b46ca2013-04-08 12:59:26 -04002867
2868 private static void awakenDreams() {
2869 IDreamManager dreamManager = getDreamManager();
2870 if (dreamManager != null) {
2871 try {
2872 dreamManager.awaken();
2873 } catch (RemoteException e) {
2874 // fine, stay asleep then
2875 }
2876 }
2877 }
2878
2879 static IDreamManager getDreamManager() {
2880 return IDreamManager.Stub.asInterface(
2881 ServiceManager.checkService(DreamService.DREAM_SERVICE));
2882 }
2883
Tyler Gunnef9f6f92014-09-12 22:16:17 -07002884 TelecomManager getTelecommService() {
2885 return (TelecomManager) mContext.getSystemService(Context.TELECOM_SERVICE);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002886 }
2887
Jeff Brown4d396052010-10-29 21:50:21 -07002888 static IAudioService getAudioService() {
2889 IAudioService audioService = IAudioService.Stub.asInterface(
2890 ServiceManager.checkService(Context.AUDIO_SERVICE));
2891 if (audioService == null) {
2892 Log.w(TAG, "Unable to find IAudioService interface.");
2893 }
2894 return audioService;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002895 }
2896
2897 boolean keyguardOn() {
Jim Millerab954542014-10-10 18:21:49 -07002898 return isKeyguardShowingAndNotOccluded() || inKeyguardRestrictedKeyInputMode();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002899 }
2900
2901 private static final int[] WINDOW_TYPES_WHERE_HOME_DOESNT_WORK = {
2902 WindowManager.LayoutParams.TYPE_SYSTEM_ALERT,
2903 WindowManager.LayoutParams.TYPE_SYSTEM_ERROR,
2904 };
2905
2906 /** {@inheritDoc} */
Jeff Brown00fa7bd2010-07-02 15:37:36 -07002907 @Override
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002908 public long interceptKeyBeforeDispatching(WindowState win, KeyEvent event, int policyFlags) {
Jeff Brown00fa7bd2010-07-02 15:37:36 -07002909 final boolean keyguardOn = keyguardOn();
Jeff Brown1f245102010-11-18 20:53:46 -08002910 final int keyCode = event.getKeyCode();
2911 final int repeatCount = event.getRepeatCount();
2912 final int metaState = event.getMetaState();
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002913 final int flags = event.getFlags();
Jeff Brown1f245102010-11-18 20:53:46 -08002914 final boolean down = event.getAction() == KeyEvent.ACTION_DOWN;
2915 final boolean canceled = event.isCanceled();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002916
Jeff Brown40013652012-05-16 21:22:36 -07002917 if (DEBUG_INPUT) {
Jeff Brown00fa7bd2010-07-02 15:37:36 -07002918 Log.d(TAG, "interceptKeyTi keyCode=" + keyCode + " down=" + down + " repeatCount="
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002919 + repeatCount + " keyguardOn=" + keyguardOn + " mHomePressed=" + mHomePressed
2920 + " canceled=" + canceled);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002921 }
2922
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002923 // If we think we might have a volume down & power key chord on the way
2924 // but we're not sure, then tell the dispatcher to wait a little while and
2925 // try again later before dispatching.
Christopher Tatee90585f2012-03-05 18:56:25 -08002926 if (mScreenshotChordEnabled && (flags & KeyEvent.FLAG_FALLBACK) == 0) {
Jeff Brown13f00f02014-10-31 14:45:50 -07002927 if (mScreenshotChordVolumeDownKeyTriggered && !mScreenshotChordPowerKeyTriggered) {
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002928 final long now = SystemClock.uptimeMillis();
Jeff Brown13f00f02014-10-31 14:45:50 -07002929 final long timeoutTime = mScreenshotChordVolumeDownKeyTime
2930 + SCREENSHOT_CHORD_DEBOUNCE_DELAY_MILLIS;
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002931 if (now < timeoutTime) {
2932 return timeoutTime - now;
2933 }
2934 }
2935 if (keyCode == KeyEvent.KEYCODE_VOLUME_DOWN
Jeff Brown13f00f02014-10-31 14:45:50 -07002936 && mScreenshotChordVolumeDownKeyConsumed) {
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002937 if (!down) {
Jeff Brown13f00f02014-10-31 14:45:50 -07002938 mScreenshotChordVolumeDownKeyConsumed = false;
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002939 }
2940 return -1;
2941 }
2942 }
2943
Michael Wright6a62e552014-06-03 19:19:48 -07002944 // Cancel any pending meta actions if we see any other keys being pressed between the down
2945 // of the meta key and its corresponding up.
Michael Wright251e35d2014-08-22 15:40:27 -07002946 if (mPendingMetaAction && !KeyEvent.isMetaKey(keyCode)) {
Michael Wright6a62e552014-06-03 19:19:48 -07002947 mPendingMetaAction = false;
2948 }
2949
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002950 // First we always handle the home key here, so applications
2951 // can never break it, although if keyguard is on, we do let
2952 // it handle it, because that gives us the correct 5 second
2953 // timeout.
Jeff Brown00fa7bd2010-07-02 15:37:36 -07002954 if (keyCode == KeyEvent.KEYCODE_HOME) {
Michael Jurka7f2668c2012-03-27 07:49:52 -07002955
Jeff Brown49ed71d2010-12-06 17:13:33 -08002956 // If we have released the home key, and didn't do anything else
2957 // while it was pressed, then it is time to go home!
Michael Jurka7f2668c2012-03-27 07:49:52 -07002958 if (!down) {
Jeff Browncaca8812013-05-09 13:34:33 -07002959 cancelPreloadRecentApps();
2960
Jeff Brown49ed71d2010-12-06 17:13:33 -08002961 mHomePressed = false;
Jeff Browncaca8812013-05-09 13:34:33 -07002962 if (mHomeConsumed) {
2963 mHomeConsumed = false;
Michael Jurka7f2668c2012-03-27 07:49:52 -07002964 return -1;
Jeff Brown49ed71d2010-12-06 17:13:33 -08002965 }
Jeff Browncaca8812013-05-09 13:34:33 -07002966
2967 if (canceled) {
2968 Log.i(TAG, "Ignoring HOME; event canceled.");
2969 return -1;
2970 }
2971
Yorke Lee4f803242014-12-15 23:22:06 +00002972 // If an incoming call is ringing, HOME is totally disabled.
2973 // (The user is already on the InCallUI at this point,
2974 // and his ONLY options are to answer or reject the call.)
2975 TelecomManager telecomManager = getTelecommService();
2976 if (telecomManager != null && telecomManager.isRinging()) {
2977 Log.i(TAG, "Ignoring HOME; there's a ringing incoming call.");
2978 return -1;
2979 }
2980
Jeff Browncaca8812013-05-09 13:34:33 -07002981 // Delay handling home if a double-tap is possible.
2982 if (mDoubleTapOnHomeBehavior != DOUBLE_TAP_HOME_NOTHING) {
2983 mHandler.removeCallbacks(mHomeDoubleTapTimeoutRunnable); // just in case
2984 mHomeDoubleTapPending = true;
2985 mHandler.postDelayed(mHomeDoubleTapTimeoutRunnable,
2986 ViewConfiguration.getDoubleTapTimeout());
2987 return -1;
2988 }
2989
Jeff Brown13f00f02014-10-31 14:45:50 -07002990 handleShortPressOnHome();
Jeff Browncaca8812013-05-09 13:34:33 -07002991 return -1;
Jeff Brown49ed71d2010-12-06 17:13:33 -08002992 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002993
2994 // If a system window has focus, then it doesn't make sense
2995 // right now to interact with applications.
2996 WindowManager.LayoutParams attrs = win != null ? win.getAttrs() : null;
2997 if (attrs != null) {
2998 final int type = attrs.type;
Jorim Jaggi380ecb82014-03-14 17:25:20 +01002999 if (type == WindowManager.LayoutParams.TYPE_KEYGUARD_SCRIM
3000 || type == WindowManager.LayoutParams.TYPE_KEYGUARD_DIALOG
3001 || (attrs.privateFlags & PRIVATE_FLAG_KEYGUARD) != 0) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003002 // the "app" is keyguard, so give it the key
Jeff Brownd5bb82d2011-10-12 13:57:59 -07003003 return 0;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003004 }
3005 final int typeCount = WINDOW_TYPES_WHERE_HOME_DOESNT_WORK.length;
3006 for (int i=0; i<typeCount; i++) {
3007 if (type == WINDOW_TYPES_WHERE_HOME_DOESNT_WORK[i]) {
3008 // don't do anything, but also don't pass it to the app
Jeff Brownd5bb82d2011-10-12 13:57:59 -07003009 return -1;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003010 }
3011 }
3012 }
Jeff Browncaca8812013-05-09 13:34:33 -07003013
3014 // Remember that home is pressed and handle special actions.
3015 if (repeatCount == 0) {
3016 mHomePressed = true;
3017 if (mHomeDoubleTapPending) {
3018 mHomeDoubleTapPending = false;
3019 mHandler.removeCallbacks(mHomeDoubleTapTimeoutRunnable);
3020 handleDoubleTapOnHome();
3021 } else if (mLongPressOnHomeBehavior == LONG_PRESS_HOME_RECENT_SYSTEM_UI
3022 || mDoubleTapOnHomeBehavior == DOUBLE_TAP_HOME_RECENT_SYSTEM_UI) {
3023 preloadRecentApps();
Michael Jurka7f2668c2012-03-27 07:49:52 -07003024 }
Jeff Browncaca8812013-05-09 13:34:33 -07003025 } else if ((event.getFlags() & KeyEvent.FLAG_LONG_PRESS) != 0) {
3026 if (!keyguardOn) {
Jaewan Kim76b7d0d2016-02-12 19:01:02 +09003027 handleLongPressOnHome(event.getDeviceId());
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003028 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003029 }
Jeff Brownd5bb82d2011-10-12 13:57:59 -07003030 return -1;
Jeff Brown00fa7bd2010-07-02 15:37:36 -07003031 } else if (keyCode == KeyEvent.KEYCODE_MENU) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003032 // Hijack modified menu keys for debugging features
3033 final int chordBug = KeyEvent.META_SHIFT_ON;
3034
3035 if (down && repeatCount == 0) {
Jeff Brown00fa7bd2010-07-02 15:37:36 -07003036 if (mEnableShiftMenuBugReports && (metaState & chordBug) == chordBug) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003037 Intent intent = new Intent(Intent.ACTION_BUG_REPORT);
Dianne Hackborn5ac72a22012-08-29 18:32:08 -07003038 mContext.sendOrderedBroadcastAsUser(intent, UserHandle.CURRENT,
3039 null, null, null, 0, null, null);
Jeff Brownd5bb82d2011-10-12 13:57:59 -07003040 return -1;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003041 } else if (SHOW_PROCESSES_ON_ALT_MENU &&
Jeff Brown00fa7bd2010-07-02 15:37:36 -07003042 (metaState & KeyEvent.META_ALT_ON) == KeyEvent.META_ALT_ON) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003043 Intent service = new Intent();
3044 service.setClassName(mContext, "com.android.server.LoadAverageService");
3045 ContentResolver res = mContext.getContentResolver();
Jeff Sharkey8d9a1f62012-10-18 15:38:14 -07003046 boolean shown = Settings.Global.getInt(
3047 res, Settings.Global.SHOW_PROCESSES, 0) != 0;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003048 if (!shown) {
3049 mContext.startService(service);
3050 } else {
3051 mContext.stopService(service);
3052 }
Jeff Sharkey8d9a1f62012-10-18 15:38:14 -07003053 Settings.Global.putInt(
3054 res, Settings.Global.SHOW_PROCESSES, shown ? 0 : 1);
Jeff Brownd5bb82d2011-10-12 13:57:59 -07003055 return -1;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003056 }
3057 }
Jeff Brown00fa7bd2010-07-02 15:37:36 -07003058 } else if (keyCode == KeyEvent.KEYCODE_SEARCH) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003059 if (down) {
3060 if (repeatCount == 0) {
Jeff Brownfd23e3e2012-05-09 13:34:28 -07003061 mSearchKeyShortcutPending = true;
3062 mConsumeSearchKeyUp = false;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003063 }
Jeff Brownfd23e3e2012-05-09 13:34:28 -07003064 } else {
3065 mSearchKeyShortcutPending = false;
3066 if (mConsumeSearchKeyUp) {
3067 mConsumeSearchKeyUp = false;
Jeff Brownd5bb82d2011-10-12 13:57:59 -07003068 return -1;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003069 }
3070 }
Jeff Brownd5bb82d2011-10-12 13:57:59 -07003071 return 0;
Jeff Brown49ed71d2010-12-06 17:13:33 -08003072 } else if (keyCode == KeyEvent.KEYCODE_APP_SWITCH) {
Michael Wrightc9ebea72013-01-16 19:25:02 -08003073 if (!keyguardOn) {
Jeff Browncaca8812013-05-09 13:34:33 -07003074 if (down && repeatCount == 0) {
3075 preloadRecentApps();
3076 } else if (!down) {
3077 toggleRecentApps();
Michael Wrightc9ebea72013-01-16 19:25:02 -08003078 }
Jeff Brown49ed71d2010-12-06 17:13:33 -08003079 }
Jeff Brownd5bb82d2011-10-12 13:57:59 -07003080 return -1;
Jun Mukaid21b3c82015-04-23 14:09:34 -07003081 } else if (keyCode == KeyEvent.KEYCODE_N && event.isMetaPressed()) {
3082 if (down) {
3083 IStatusBarService service = getStatusBarService();
3084 if (service != null) {
3085 try {
3086 service.expandNotificationsPanel();
3087 } catch (RemoteException e) {
3088 // do nothing.
3089 }
3090 }
3091 }
Muyuan Li6ca619f2016-03-08 13:30:42 -08003092 } else if (keyCode == KeyEvent.KEYCODE_S && event.isMetaPressed()
3093 && event.isCtrlPressed()) {
3094 if (down && repeatCount == 0) {
3095 int type = event.isShiftPressed() ? TAKE_SCREENSHOT_SELECTED_REGION
3096 : TAKE_SCREENSHOT_FULLSCREEN;
3097 mScreenshotRunnable.setScreenshotType(type);
3098 mHandler.post(mScreenshotRunnable);
3099 return -1;
3100 }
Clara Bayarrif2debb12015-07-10 14:47:17 +01003101 } else if (keyCode == KeyEvent.KEYCODE_SLASH && event.isMetaPressed()) {
3102 if (down) {
3103 if (repeatCount == 0) {
Andrei Stingaceanuc22ab792016-01-07 12:39:38 +00003104 toggleKeyboardShortcutsMenu();
Clara Bayarrif2debb12015-07-10 14:47:17 +01003105 }
3106 }
Jeff Brownde7a8ea2012-06-13 18:28:57 -07003107 } else if (keyCode == KeyEvent.KEYCODE_ASSIST) {
3108 if (down) {
3109 if (repeatCount == 0) {
3110 mAssistKeyLongPressed = false;
3111 } else if (repeatCount == 1) {
3112 mAssistKeyLongPressed = true;
3113 if (!keyguardOn) {
3114 launchAssistLongPressAction();
3115 }
3116 }
3117 } else {
3118 if (mAssistKeyLongPressed) {
3119 mAssistKeyLongPressed = false;
3120 } else {
3121 if (!keyguardOn) {
Tim Kilbourn0e5f1102015-06-05 16:18:09 -07003122 launchAssistAction(null, event.getDeviceId());
Jeff Brownde7a8ea2012-06-13 18:28:57 -07003123 }
3124 }
3125 }
3126 return -1;
Michael Wrightdc63f7b2014-08-21 19:05:21 -07003127 } else if (keyCode == KeyEvent.KEYCODE_VOICE_ASSIST) {
3128 if (!down) {
3129 Intent voiceIntent;
Michael Wright869a67c2014-08-26 19:33:06 -07003130 if (!keyguardOn) {
Michael Wrightdc63f7b2014-08-21 19:05:21 -07003131 voiceIntent = new Intent(RecognizerIntent.ACTION_WEB_SEARCH);
3132 } else {
Dianne Hackbornb6683c42015-06-18 17:40:33 -07003133 IDeviceIdleController dic = IDeviceIdleController.Stub.asInterface(
3134 ServiceManager.getService(Context.DEVICE_IDLE_CONTROLLER));
3135 if (dic != null) {
3136 try {
3137 dic.exitIdle("voice-search");
3138 } catch (RemoteException e) {
3139 }
3140 }
Michael Wrightdc63f7b2014-08-21 19:05:21 -07003141 voiceIntent = new Intent(RecognizerIntent.ACTION_VOICE_SEARCH_HANDS_FREE);
Michael Wright869a67c2014-08-26 19:33:06 -07003142 voiceIntent.putExtra(RecognizerIntent.EXTRA_SECURE, true);
Michael Wrightdc63f7b2014-08-21 19:05:21 -07003143 }
Bart Sears8b1c27c2015-03-18 23:51:02 +00003144 startActivityAsUser(voiceIntent, UserHandle.CURRENT_OR_SELF);
Michael Wrightdc63f7b2014-08-21 19:05:21 -07003145 }
Jeff Sharkey2991fa32012-12-05 18:06:43 -08003146 } else if (keyCode == KeyEvent.KEYCODE_SYSRQ) {
3147 if (down && repeatCount == 0) {
Muyuan Li6ca619f2016-03-08 13:30:42 -08003148 mScreenshotRunnable.setScreenshotType(TAKE_SCREENSHOT_FULLSCREEN);
Jeff Sharkey2991fa32012-12-05 18:06:43 -08003149 mHandler.post(mScreenshotRunnable);
3150 }
3151 return -1;
Michael Wrightb854e242013-02-05 17:54:02 -08003152 } else if (keyCode == KeyEvent.KEYCODE_BRIGHTNESS_UP
3153 || keyCode == KeyEvent.KEYCODE_BRIGHTNESS_DOWN) {
3154 if (down) {
3155 int direction = keyCode == KeyEvent.KEYCODE_BRIGHTNESS_UP ? 1 : -1;
3156
3157 // Disable autobrightness if it's on
3158 int auto = Settings.System.getIntForUser(
3159 mContext.getContentResolver(),
3160 Settings.System.SCREEN_BRIGHTNESS_MODE,
3161 Settings.System.SCREEN_BRIGHTNESS_MODE_MANUAL,
3162 UserHandle.USER_CURRENT_OR_SELF);
3163 if (auto != 0) {
3164 Settings.System.putIntForUser(mContext.getContentResolver(),
3165 Settings.System.SCREEN_BRIGHTNESS_MODE,
3166 Settings.System.SCREEN_BRIGHTNESS_MODE_MANUAL,
3167 UserHandle.USER_CURRENT_OR_SELF);
3168 }
3169
3170 int min = mPowerManager.getMinimumScreenBrightnessSetting();
3171 int max = mPowerManager.getMaximumScreenBrightnessSetting();
3172 int step = (max - min + BRIGHTNESS_STEPS - 1) / BRIGHTNESS_STEPS * direction;
3173 int brightness = Settings.System.getIntForUser(mContext.getContentResolver(),
3174 Settings.System.SCREEN_BRIGHTNESS,
3175 mPowerManager.getDefaultScreenBrightnessSetting(),
3176 UserHandle.USER_CURRENT_OR_SELF);
3177 brightness += step;
3178 // Make sure we don't go beyond the limits.
3179 brightness = Math.min(max, brightness);
3180 brightness = Math.max(min, brightness);
3181
3182 Settings.System.putIntForUser(mContext.getContentResolver(),
3183 Settings.System.SCREEN_BRIGHTNESS, brightness,
3184 UserHandle.USER_CURRENT_OR_SELF);
Bart Sears8b1c27c2015-03-18 23:51:02 +00003185 startActivityAsUser(new Intent(Intent.ACTION_SHOW_BRIGHTNESS_DIALOG),
Alan Viverette5a399492014-07-14 16:19:38 -07003186 UserHandle.CURRENT_OR_SELF);
Michael Wrightb854e242013-02-05 17:54:02 -08003187 }
3188 return -1;
Jaewan Kim765487f2016-01-12 14:45:42 +09003189 } else if (keyCode == KeyEvent.KEYCODE_VOLUME_UP
3190 || keyCode == KeyEvent.KEYCODE_VOLUME_DOWN
3191 || keyCode == KeyEvent.KEYCODE_VOLUME_MUTE) {
3192 if (mUseTvRouting) {
3193 // On TVs volume keys never go to the foreground app.
3194 dispatchDirectAudioEvent(event);
3195 return -1;
3196 }
Muyuan Li94ce94e2016-02-24 16:20:54 -08003197 }
3198
3199 if (KeyEvent.isMetaKey(keyCode)) {
Michael Wright6a62e552014-06-03 19:19:48 -07003200 if (down) {
3201 mPendingMetaAction = true;
3202 } else if (mPendingMetaAction) {
Tim Kilbourn0e5f1102015-06-05 16:18:09 -07003203 launchAssistAction(Intent.EXTRA_ASSIST_INPUT_HINT_KEYBOARD, event.getDeviceId());
Michael Wright6a62e552014-06-03 19:19:48 -07003204 }
3205 return -1;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003206 }
Jeff Browncaab4d02010-12-09 22:13:41 -08003207
Jeff Brownc1fb48d2010-12-08 16:52:09 -08003208 // Shortcuts are invoked through Search+key, so intercept those here
Jeff Browncaab4d02010-12-09 22:13:41 -08003209 // Any printing key that is chorded with Search should be consumed
3210 // even if no shortcut was invoked. This prevents text from being
3211 // inadvertently inserted when using a keyboard that has built-in macro
3212 // shortcut keys (that emit Search+x) and some of them are not registered.
Jeff Brownfd23e3e2012-05-09 13:34:28 -07003213 if (mSearchKeyShortcutPending) {
Jeff Browncaab4d02010-12-09 22:13:41 -08003214 final KeyCharacterMap kcm = event.getKeyCharacterMap();
3215 if (kcm.isPrintingKey(keyCode)) {
Jeff Brownfd23e3e2012-05-09 13:34:28 -07003216 mConsumeSearchKeyUp = true;
3217 mSearchKeyShortcutPending = false;
Jeff Browncaab4d02010-12-09 22:13:41 -08003218 if (down && repeatCount == 0 && !keyguardOn) {
3219 Intent shortcutIntent = mShortcutManager.getIntent(kcm, keyCode, metaState);
3220 if (shortcutIntent != null) {
3221 shortcutIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
Jeff Brownf0a3cc52011-01-26 18:42:46 -08003222 try {
Bart Sears8b1c27c2015-03-18 23:51:02 +00003223 startActivityAsUser(shortcutIntent, UserHandle.CURRENT);
Jeff Brownf0a3cc52011-01-26 18:42:46 -08003224 } catch (ActivityNotFoundException ex) {
3225 Slog.w(TAG, "Dropping shortcut key combination because "
3226 + "the activity to which it is registered was not found: "
Jeff Brownfd23e3e2012-05-09 13:34:28 -07003227 + "SEARCH+" + KeyEvent.keyCodeToString(keyCode), ex);
Jeff Brownf0a3cc52011-01-26 18:42:46 -08003228 }
Jeff Browncaab4d02010-12-09 22:13:41 -08003229 } else {
3230 Slog.i(TAG, "Dropping unregistered shortcut key combination: "
Jeff Brownfd23e3e2012-05-09 13:34:28 -07003231 + "SEARCH+" + KeyEvent.keyCodeToString(keyCode));
Jeff Brown49ed71d2010-12-06 17:13:33 -08003232 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003233 }
Jeff Brownd5bb82d2011-10-12 13:57:59 -07003234 return -1;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003235 }
3236 }
3237
Jeff Brown68b909d2011-12-07 16:36:01 -08003238 // Invoke shortcuts using Meta.
Jeff Brown602ab322012-05-16 13:33:47 -07003239 if (down && repeatCount == 0 && !keyguardOn
Jeff Brown68b909d2011-12-07 16:36:01 -08003240 && (metaState & KeyEvent.META_META_ON) != 0) {
3241 final KeyCharacterMap kcm = event.getKeyCharacterMap();
Jeff Brown602ab322012-05-16 13:33:47 -07003242 if (kcm.isPrintingKey(keyCode)) {
3243 Intent shortcutIntent = mShortcutManager.getIntent(kcm, keyCode,
3244 metaState & ~(KeyEvent.META_META_ON
3245 | KeyEvent.META_META_LEFT_ON | KeyEvent.META_META_RIGHT_ON));
3246 if (shortcutIntent != null) {
3247 shortcutIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
3248 try {
Bart Sears8b1c27c2015-03-18 23:51:02 +00003249 startActivityAsUser(shortcutIntent, UserHandle.CURRENT);
Jeff Brown602ab322012-05-16 13:33:47 -07003250 } catch (ActivityNotFoundException ex) {
3251 Slog.w(TAG, "Dropping shortcut key combination because "
3252 + "the activity to which it is registered was not found: "
3253 + "META+" + KeyEvent.keyCodeToString(keyCode), ex);
3254 }
3255 return -1;
Jeff Brown68b909d2011-12-07 16:36:01 -08003256 }
Jeff Brown68b909d2011-12-07 16:36:01 -08003257 }
3258 }
3259
Jeff Brown6651a632011-11-28 12:59:11 -08003260 // Handle application launch keys.
Jeff Brown602ab322012-05-16 13:33:47 -07003261 if (down && repeatCount == 0 && !keyguardOn) {
Jeff Brown6651a632011-11-28 12:59:11 -08003262 String category = sApplicationLaunchKeyCategories.get(keyCode);
3263 if (category != null) {
Dianne Hackbornf5b86712011-12-05 17:42:41 -08003264 Intent intent = Intent.makeMainSelectorActivity(Intent.ACTION_MAIN, category);
Jeff Brown6651a632011-11-28 12:59:11 -08003265 intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
3266 try {
Bart Sears8b1c27c2015-03-18 23:51:02 +00003267 startActivityAsUser(intent, UserHandle.CURRENT);
Jeff Brown6651a632011-11-28 12:59:11 -08003268 } catch (ActivityNotFoundException ex) {
3269 Slog.w(TAG, "Dropping application launch key because "
3270 + "the activity to which it is registered was not found: "
3271 + "keyCode=" + keyCode + ", category=" + category, ex);
3272 }
Jeff Brown68b909d2011-12-07 16:36:01 -08003273 return -1;
Jeff Brown6651a632011-11-28 12:59:11 -08003274 }
3275 }
3276
Michael Wright61c46752014-08-21 16:57:33 -07003277 // Display task switcher for ALT-TAB.
Jeff Brown68b909d2011-12-07 16:36:01 -08003278 if (down && repeatCount == 0 && keyCode == KeyEvent.KEYCODE_TAB) {
Michael Wrightd847ad52015-10-24 13:24:15 +01003279 if (mRecentAppsHeldModifiers == 0 && !keyguardOn && isUserSetupComplete()) {
Jeff Brown68b909d2011-12-07 16:36:01 -08003280 final int shiftlessModifiers = event.getModifiers() & ~KeyEvent.META_SHIFT_MASK;
Michael Wright61c46752014-08-21 16:57:33 -07003281 if (KeyEvent.metaStateHasModifiers(shiftlessModifiers, KeyEvent.META_ALT_ON)) {
Winson Chung1e8d71b2014-05-16 17:05:22 -07003282 mRecentAppsHeldModifiers = shiftlessModifiers;
3283 showRecentApps(true);
Jeff Brown68b909d2011-12-07 16:36:01 -08003284 return -1;
3285 }
3286 }
Winson Chung1e8d71b2014-05-16 17:05:22 -07003287 } else if (!down && mRecentAppsHeldModifiers != 0
3288 && (metaState & mRecentAppsHeldModifiers) == 0) {
3289 mRecentAppsHeldModifiers = 0;
Winson Chungcdcd4872014-08-05 18:00:13 -07003290 hideRecentApps(true, false);
Jeff Brown68b909d2011-12-07 16:36:01 -08003291 }
3292
Yohei Yukawaae61f712015-12-09 13:00:10 -08003293 // Handle input method switching.
Jeff Browncf39bdf2012-05-18 14:41:19 -07003294 if (down && repeatCount == 0
3295 && (keyCode == KeyEvent.KEYCODE_LANGUAGE_SWITCH
3296 || (keyCode == KeyEvent.KEYCODE_SPACE
Yohei Yukawaae61f712015-12-09 13:00:10 -08003297 && (metaState & KeyEvent.META_META_MASK) != 0))) {
3298 final boolean forwardDirection = (metaState & KeyEvent.META_SHIFT_MASK) == 0;
3299 mWindowManagerFuncs.switchInputMethod(forwardDirection);
Jeff Browncf39bdf2012-05-18 14:41:19 -07003300 return -1;
3301 }
3302 if (mLanguageSwitchKeyPressed && !down
3303 && (keyCode == KeyEvent.KEYCODE_LANGUAGE_SWITCH
3304 || keyCode == KeyEvent.KEYCODE_SPACE)) {
3305 mLanguageSwitchKeyPressed = false;
3306 return -1;
3307 }
3308
Jeff Brown13f00f02014-10-31 14:45:50 -07003309 if (isValidGlobalKey(keyCode)
3310 && mGlobalKeyManager.handleGlobalKey(mContext, keyCode, event)) {
Justin Kohd378ad72013-04-01 12:18:26 -07003311 return -1;
3312 }
3313
Muyuan Li94ce94e2016-02-24 16:20:54 -08003314 if (down) {
3315 long shortcutCode = (long) keyCode;
3316 if (event.isCtrlPressed()) {
3317 shortcutCode |= ((long) KeyEvent.META_CTRL_ON) << Integer.SIZE;
3318 }
3319
3320 if (event.isAltPressed()) {
3321 shortcutCode |= ((long) KeyEvent.META_ALT_ON) << Integer.SIZE;
3322 }
3323
3324 if (event.isShiftPressed()) {
3325 shortcutCode |= ((long) KeyEvent.META_SHIFT_ON) << Integer.SIZE;
3326 }
3327
3328 if (event.isMetaPressed()) {
3329 shortcutCode |= ((long) KeyEvent.META_META_ON) << Integer.SIZE;
3330 }
3331
3332 IShortcutService shortcutService = mShortcutKeyServices.get(shortcutCode);
3333 if (shortcutService != null) {
3334 try {
3335 shortcutService.notifyShortcutKeyPressed(shortcutCode);
3336 } catch (RemoteException e) {
3337 mShortcutKeyServices.delete(shortcutCode);
3338 }
3339 return -1;
3340 }
3341 }
3342
Michael Wright6a62e552014-06-03 19:19:48 -07003343 // Reserve all the META modifier combos for system behavior
Michael Wrightce0c13a2014-07-30 10:49:21 -07003344 if ((metaState & KeyEvent.META_META_ON) != 0) {
Michael Wright6a62e552014-06-03 19:19:48 -07003345 return -1;
3346 }
3347
Jeff Brown68b909d2011-12-07 16:36:01 -08003348 // Let the application handle the key.
Jeff Brownd5bb82d2011-10-12 13:57:59 -07003349 return 0;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003350 }
3351
Jeff Brown3915bb82010-11-05 15:02:16 -07003352 /** {@inheritDoc} */
3353 @Override
Jeff Brown49ed71d2010-12-06 17:13:33 -08003354 public KeyEvent dispatchUnhandledKey(WindowState win, KeyEvent event, int policyFlags) {
Jeff Brown54875002011-04-06 15:33:01 -07003355 // Note: This method is only called if the initial down was unhandled.
Jeff Brown40013652012-05-16 21:22:36 -07003356 if (DEBUG_INPUT) {
Jeff Brown1f245102010-11-18 20:53:46 -08003357 Slog.d(TAG, "Unhandled key: win=" + win + ", action=" + event.getAction()
3358 + ", flags=" + event.getFlags()
3359 + ", keyCode=" + event.getKeyCode()
3360 + ", scanCode=" + event.getScanCode()
3361 + ", metaState=" + event.getMetaState()
3362 + ", repeatCount=" + event.getRepeatCount()
3363 + ", policyFlags=" + policyFlags);
Jeff Brown3915bb82010-11-05 15:02:16 -07003364 }
Jeff Brown49ed71d2010-12-06 17:13:33 -08003365
Jeff Brownfd23e3e2012-05-09 13:34:28 -07003366 KeyEvent fallbackEvent = null;
Jeff Brown49ed71d2010-12-06 17:13:33 -08003367 if ((event.getFlags() & KeyEvent.FLAG_FALLBACK) == 0) {
3368 final KeyCharacterMap kcm = event.getKeyCharacterMap();
Jeff Brownc1fb48d2010-12-08 16:52:09 -08003369 final int keyCode = event.getKeyCode();
3370 final int metaState = event.getMetaState();
Jeff Brownfd23e3e2012-05-09 13:34:28 -07003371 final boolean initialDown = event.getAction() == KeyEvent.ACTION_DOWN
3372 && event.getRepeatCount() == 0;
Jeff Brown49ed71d2010-12-06 17:13:33 -08003373
Jeff Brown54875002011-04-06 15:33:01 -07003374 // Check for fallback actions specified by the key character map.
Jeff Brownfd23e3e2012-05-09 13:34:28 -07003375 final FallbackAction fallbackAction;
3376 if (initialDown) {
3377 fallbackAction = kcm.getFallbackAction(keyCode, metaState);
3378 } else {
3379 fallbackAction = mFallbackActions.get(keyCode);
3380 }
3381
3382 if (fallbackAction != null) {
Jeff Brown40013652012-05-16 21:22:36 -07003383 if (DEBUG_INPUT) {
Jeff Brownfd23e3e2012-05-09 13:34:28 -07003384 Slog.d(TAG, "Fallback: keyCode=" + fallbackAction.keyCode
3385 + " metaState=" + Integer.toHexString(fallbackAction.metaState));
Jeff Brown49ed71d2010-12-06 17:13:33 -08003386 }
3387
Jeff Brownfd23e3e2012-05-09 13:34:28 -07003388 final int flags = event.getFlags() | KeyEvent.FLAG_FALLBACK;
3389 fallbackEvent = KeyEvent.obtain(
Jeff Brown49ed71d2010-12-06 17:13:33 -08003390 event.getDownTime(), event.getEventTime(),
Jeff Brownfd23e3e2012-05-09 13:34:28 -07003391 event.getAction(), fallbackAction.keyCode,
3392 event.getRepeatCount(), fallbackAction.metaState,
Jeff Brown49ed71d2010-12-06 17:13:33 -08003393 event.getDeviceId(), event.getScanCode(),
3394 flags, event.getSource(), null);
Jeff Brownfd23e3e2012-05-09 13:34:28 -07003395
3396 if (!interceptFallback(win, fallbackEvent, policyFlags)) {
3397 fallbackEvent.recycle();
3398 fallbackEvent = null;
Jeff Brown49ed71d2010-12-06 17:13:33 -08003399 }
Jeff Brownfd23e3e2012-05-09 13:34:28 -07003400
3401 if (initialDown) {
3402 mFallbackActions.put(keyCode, fallbackAction);
3403 } else if (event.getAction() == KeyEvent.ACTION_UP) {
3404 mFallbackActions.remove(keyCode);
3405 fallbackAction.recycle();
3406 }
Jeff Brown49ed71d2010-12-06 17:13:33 -08003407 }
3408 }
3409
Jeff Brown40013652012-05-16 21:22:36 -07003410 if (DEBUG_INPUT) {
Jeff Brownfd23e3e2012-05-09 13:34:28 -07003411 if (fallbackEvent == null) {
3412 Slog.d(TAG, "No fallback.");
3413 } else {
3414 Slog.d(TAG, "Performing fallback: " + fallbackEvent);
3415 }
Jeff Brown49ed71d2010-12-06 17:13:33 -08003416 }
Jeff Brownfd23e3e2012-05-09 13:34:28 -07003417 return fallbackEvent;
Jeff Brown3915bb82010-11-05 15:02:16 -07003418 }
3419
Jeff Brownfd23e3e2012-05-09 13:34:28 -07003420 private boolean interceptFallback(WindowState win, KeyEvent fallbackEvent, int policyFlags) {
Jeff Brown037c33e2014-04-09 00:31:55 -07003421 int actions = interceptKeyBeforeQueueing(fallbackEvent, policyFlags);
Jeff Brownfd23e3e2012-05-09 13:34:28 -07003422 if ((actions & ACTION_PASS_TO_USER) != 0) {
3423 long delayMillis = interceptKeyBeforeDispatching(
3424 win, fallbackEvent, policyFlags);
3425 if (delayMillis == 0) {
3426 return true;
3427 }
3428 }
3429 return false;
Jeff Brown6f2fba42011-02-19 01:08:02 -08003430 }
3431
Muyuan Li94ce94e2016-02-24 16:20:54 -08003432 public void registerShortcutKey(long shortcutCode, IShortcutService shortcutService)
3433 throws RemoteException {
3434 synchronized (mLock) {
3435 IShortcutService service = mShortcutKeyServices.get(shortcutCode);
Muyuan Li24d24ac2016-03-03 21:15:02 -08003436 if (service != null && service.asBinder().pingBinder()) {
3437 throw new RemoteException("Key already exists.");
Muyuan Li94ce94e2016-02-24 16:20:54 -08003438 }
3439
3440 mShortcutKeyServices.put(shortcutCode, shortcutService);
3441 }
3442 }
3443
Jeff Brownde7a8ea2012-06-13 18:28:57 -07003444 private void launchAssistLongPressAction() {
3445 performHapticFeedbackLw(null, HapticFeedbackConstants.LONG_PRESS, false);
3446 sendCloseSystemWindows(SYSTEM_DIALOG_REASON_ASSIST);
3447
3448 // launch the search activity
3449 Intent intent = new Intent(Intent.ACTION_SEARCH_LONG_PRESS);
3450 intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
3451 try {
RoboErik8a2cfc32014-05-16 11:19:38 -07003452 // TODO: This only stops the factory-installed search manager.
Jim Miller45308b12012-06-18 19:23:39 -07003453 // Need to formalize an API to handle others
Jeff Brownde7a8ea2012-06-13 18:28:57 -07003454 SearchManager searchManager = getSearchManager();
3455 if (searchManager != null) {
3456 searchManager.stopSearch();
3457 }
Bart Sears8b1c27c2015-03-18 23:51:02 +00003458 startActivityAsUser(intent, UserHandle.CURRENT);
Jeff Brownde7a8ea2012-06-13 18:28:57 -07003459 } catch (ActivityNotFoundException e) {
3460 Slog.w(TAG, "No activity to handle assist long press action.", e);
3461 }
3462 }
3463
Tim Kilbourn0e5f1102015-06-05 16:18:09 -07003464 private void launchAssistAction(String hint, int deviceId) {
Jeff Brownde7a8ea2012-06-13 18:28:57 -07003465 sendCloseSystemWindows(SYSTEM_DIALOG_REASON_ASSIST);
Maurice Lam39d13812015-07-23 20:49:20 -07003466 if (!isUserSetupComplete()) {
3467 // Disable opening assist window during setup
3468 return;
3469 }
Tim Kilbourn0e5f1102015-06-05 16:18:09 -07003470 Bundle args = null;
3471 if (deviceId > Integer.MIN_VALUE) {
3472 args = new Bundle();
3473 args.putInt(Intent.EXTRA_ASSIST_INPUT_DEVICE_ID, deviceId);
Jeff Brownde7a8ea2012-06-13 18:28:57 -07003474 }
Jorim Jaggi165ce062015-07-06 16:18:11 -07003475 if ((mContext.getResources().getConfiguration().uiMode
3476 & Configuration.UI_MODE_TYPE_MASK) == Configuration.UI_MODE_TYPE_TELEVISION) {
3477 // On TV, use legacy handling until assistants are implemented in the proper way.
3478 ((SearchManager) mContext.getSystemService(Context.SEARCH_SERVICE))
3479 .launchLegacyAssist(hint, UserHandle.myUserId(), args);
3480 } else {
3481 try {
3482 if (hint != null) {
3483 if (args == null) {
3484 args = new Bundle();
3485 }
3486 args.putBoolean(hint, true);
3487 }
3488 IStatusBarService statusbar = getStatusBarService();
3489 if (statusbar != null) {
3490 statusbar.startAssist(args);
3491 }
3492 } catch (RemoteException e) {
3493 Slog.e(TAG, "RemoteException when starting assist", e);
3494 // re-acquire status bar service next time it is needed.
3495 mStatusBarService = null;
3496 }
3497 }
Jeff Brownde7a8ea2012-06-13 18:28:57 -07003498 }
3499
Bart Sears8b1c27c2015-03-18 23:51:02 +00003500 private void startActivityAsUser(Intent intent, UserHandle handle) {
3501 if (isUserSetupComplete()) {
3502 mContext.startActivityAsUser(intent, handle);
3503 } else {
3504 Slog.i(TAG, "Not starting activity because user setup is in progress: " + intent);
3505 }
3506 }
3507
Jeff Brownde7a8ea2012-06-13 18:28:57 -07003508 private SearchManager getSearchManager() {
3509 if (mSearchManager == null) {
3510 mSearchManager = (SearchManager) mContext.getSystemService(Context.SEARCH_SERVICE);
3511 }
3512 return mSearchManager;
3513 }
3514
Jeff Browncaca8812013-05-09 13:34:33 -07003515 private void preloadRecentApps() {
3516 mPreloadedRecentApps = true;
3517 try {
3518 IStatusBarService statusbar = getStatusBarService();
3519 if (statusbar != null) {
3520 statusbar.preloadRecentApps();
3521 }
3522 } catch (RemoteException e) {
3523 Slog.e(TAG, "RemoteException when preloading recent apps", e);
3524 // re-acquire status bar service next time it is needed.
3525 mStatusBarService = null;
3526 }
3527 }
3528
3529 private void cancelPreloadRecentApps() {
3530 if (mPreloadedRecentApps) {
3531 mPreloadedRecentApps = false;
3532 try {
3533 IStatusBarService statusbar = getStatusBarService();
3534 if (statusbar != null) {
3535 statusbar.cancelPreloadRecentApps();
3536 }
3537 } catch (RemoteException e) {
Winson Chung1e8d71b2014-05-16 17:05:22 -07003538 Slog.e(TAG, "RemoteException when cancelling recent apps preload", e);
Jeff Browncaca8812013-05-09 13:34:33 -07003539 // re-acquire status bar service next time it is needed.
3540 mStatusBarService = null;
3541 }
3542 }
3543 }
3544
3545 private void toggleRecentApps() {
3546 mPreloadedRecentApps = false; // preloading no longer needs to be canceled
Jeff Browncaca8812013-05-09 13:34:33 -07003547 try {
3548 IStatusBarService statusbar = getStatusBarService();
3549 if (statusbar != null) {
3550 statusbar.toggleRecentApps();
3551 }
3552 } catch (RemoteException e) {
Winson Chung1e8d71b2014-05-16 17:05:22 -07003553 Slog.e(TAG, "RemoteException when toggling recent apps", e);
3554 // re-acquire status bar service next time it is needed.
3555 mStatusBarService = null;
3556 }
3557 }
3558
Craig Mautner84984fa2014-06-19 11:19:20 -07003559 @Override
3560 public void showRecentApps() {
3561 mHandler.removeMessages(MSG_DISPATCH_SHOW_RECENTS);
3562 mHandler.sendEmptyMessage(MSG_DISPATCH_SHOW_RECENTS);
3563 }
3564
Winson Chung1e8d71b2014-05-16 17:05:22 -07003565 private void showRecentApps(boolean triggeredFromAltTab) {
3566 mPreloadedRecentApps = false; // preloading no longer needs to be canceled
3567 try {
3568 IStatusBarService statusbar = getStatusBarService();
3569 if (statusbar != null) {
3570 statusbar.showRecentApps(triggeredFromAltTab);
3571 }
3572 } catch (RemoteException e) {
Jeff Browncaca8812013-05-09 13:34:33 -07003573 Slog.e(TAG, "RemoteException when showing recent apps", e);
3574 // re-acquire status bar service next time it is needed.
3575 mStatusBarService = null;
3576 }
3577 }
3578
Andrei Stingaceanuc22ab792016-01-07 12:39:38 +00003579 private void toggleKeyboardShortcutsMenu() {
Clara Bayarrif2debb12015-07-10 14:47:17 +01003580 try {
3581 IStatusBarService statusbar = getStatusBarService();
3582 if (statusbar != null) {
Andrei Stingaceanuc22ab792016-01-07 12:39:38 +00003583 statusbar.toggleKeyboardShortcutsMenu();
Clara Bayarrif2debb12015-07-10 14:47:17 +01003584 }
3585 } catch (RemoteException e) {
3586 Slog.e(TAG, "RemoteException when showing keyboard shortcuts menu", e);
3587 }
3588 }
3589
Winson Chungcdcd4872014-08-05 18:00:13 -07003590 private void hideRecentApps(boolean triggeredFromAltTab, boolean triggeredFromHome) {
Winson Chung1e8d71b2014-05-16 17:05:22 -07003591 mPreloadedRecentApps = false; // preloading no longer needs to be canceled
3592 try {
3593 IStatusBarService statusbar = getStatusBarService();
3594 if (statusbar != null) {
Winson Chungcdcd4872014-08-05 18:00:13 -07003595 statusbar.hideRecentApps(triggeredFromAltTab, triggeredFromHome);
Winson Chung1e8d71b2014-05-16 17:05:22 -07003596 }
3597 } catch (RemoteException e) {
3598 Slog.e(TAG, "RemoteException when closing recent apps", e);
3599 // re-acquire status bar service next time it is needed.
3600 mStatusBarService = null;
3601 }
3602 }
3603
Filip Gruszczynskia483a1d2015-03-17 19:06:58 +00003604 void launchHomeFromHotKey() {
Bryce Lee662ed802015-04-10 20:11:39 +00003605 launchHomeFromHotKey(true /* awakenFromDreams */, true /*respectKeyguard*/);
Filip Gruszczynskia483a1d2015-03-17 19:06:58 +00003606 }
3607
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003608 /**
3609 * A home key -> launch home action was detected. Take the appropriate action
3610 * given the situation with the keyguard.
3611 */
Bryce Lee662ed802015-04-10 20:11:39 +00003612 void launchHomeFromHotKey(final boolean awakenFromDreams, final boolean respectKeyguard) {
3613 if (respectKeyguard) {
3614 if (isKeyguardShowingAndNotOccluded()) {
3615 // don't launch home if keyguard showing
3616 return;
3617 }
3618
3619 if (!mHideLockScreen && mKeyguardDelegate.isInputRestricted()) {
3620 // when in keyguard restricted mode, must first verify unlock
3621 // before launching home
3622 mKeyguardDelegate.verifyUnlock(new OnKeyguardExitResult() {
3623 @Override
3624 public void onKeyguardExitResult(boolean success) {
3625 if (success) {
3626 try {
3627 ActivityManagerNative.getDefault().stopAppSwitches();
3628 } catch (RemoteException e) {
3629 }
3630 sendCloseSystemWindows(SYSTEM_DIALOG_REASON_HOME_KEY);
3631 startDockOrHome(true /*fromHomeKey*/, awakenFromDreams);
Dianne Hackborn256dd3b2009-05-19 18:51:21 -07003632 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003633 }
Bryce Lee662ed802015-04-10 20:11:39 +00003634 });
3635 return;
3636 }
3637 }
3638
3639 // no keyguard stuff to worry about, just launch home!
3640 try {
3641 ActivityManagerNative.getDefault().stopAppSwitches();
3642 } catch (RemoteException e) {
3643 }
3644 if (mRecentsVisible) {
3645 // Hide Recents and notify it to launch Home
3646 if (awakenFromDreams) {
3647 awakenDreams();
3648 }
Bryce Lee662ed802015-04-10 20:11:39 +00003649 hideRecentApps(false, true);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003650 } else {
Bryce Lee662ed802015-04-10 20:11:39 +00003651 // Otherwise, just launch Home
3652 sendCloseSystemWindows(SYSTEM_DIALOG_REASON_HOME_KEY);
3653 startDockOrHome(true /*fromHomeKey*/, awakenFromDreams);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003654 }
3655 }
3656
John Spurlock04db1762013-05-13 12:46:41 -04003657 private final Runnable mClearHideNavigationFlag = new Runnable() {
3658 @Override
3659 public void run() {
3660 synchronized (mWindowManagerFuncs.getWindowManagerLock()) {
3661 // Clear flags.
3662 mForceClearedSystemUiFlags &=
3663 ~View.SYSTEM_UI_FLAG_HIDE_NAVIGATION;
3664 }
3665 mWindowManagerFuncs.reevaluateStatusBarVisibility();
Dianne Hackborne26ab702011-10-16 13:21:33 -07003666 }
3667 };
3668
3669 /**
3670 * Input handler used while nav bar is hidden. Captures any touch on the screen,
3671 * to determine when the nav bar should be shown and prevent applications from
3672 * receiving those touches.
3673 */
Jeff Brown32cbc38552011-12-01 14:01:49 -08003674 final class HideNavInputEventReceiver extends InputEventReceiver {
3675 public HideNavInputEventReceiver(InputChannel inputChannel, Looper looper) {
3676 super(inputChannel, looper);
3677 }
3678
Dianne Hackborndf89e652011-10-06 22:35:11 -07003679 @Override
Jeff Brown32cbc38552011-12-01 14:01:49 -08003680 public void onInputEvent(InputEvent event) {
Dianne Hackborndf89e652011-10-06 22:35:11 -07003681 boolean handled = false;
3682 try {
Jeff Brown4952dfd2011-11-30 19:23:22 -08003683 if (event instanceof MotionEvent
3684 && (event.getSource() & InputDevice.SOURCE_CLASS_POINTER) != 0) {
3685 final MotionEvent motionEvent = (MotionEvent)event;
3686 if (motionEvent.getAction() == MotionEvent.ACTION_DOWN) {
Dianne Hackborndf89e652011-10-06 22:35:11 -07003687 // When the user taps down, we re-show the nav bar.
3688 boolean changed = false;
John Spurlock04db1762013-05-13 12:46:41 -04003689 synchronized (mWindowManagerFuncs.getWindowManagerLock()) {
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07003690 // Any user activity always causes us to show the
3691 // navigation controls, if they had been hidden.
3692 // We also clear the low profile and only content
3693 // flags so that tapping on the screen will atomically
3694 // restore all currently hidden screen decorations.
3695 int newVal = mResettingSystemUiFlags |
3696 View.SYSTEM_UI_FLAG_HIDE_NAVIGATION |
3697 View.SYSTEM_UI_FLAG_LOW_PROFILE |
3698 View.SYSTEM_UI_FLAG_FULLSCREEN;
Dianne Hackborne26ab702011-10-16 13:21:33 -07003699 if (mResettingSystemUiFlags != newVal) {
3700 mResettingSystemUiFlags = newVal;
Dianne Hackborndf89e652011-10-06 22:35:11 -07003701 changed = true;
3702 }
Dianne Hackborne26ab702011-10-16 13:21:33 -07003703 // We don't allow the system's nav bar to be hidden
3704 // again for 1 second, to prevent applications from
3705 // spamming us and keeping it from being shown.
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07003706 newVal = mForceClearedSystemUiFlags |
3707 View.SYSTEM_UI_FLAG_HIDE_NAVIGATION;
Dianne Hackborne26ab702011-10-16 13:21:33 -07003708 if (mForceClearedSystemUiFlags != newVal) {
3709 mForceClearedSystemUiFlags = newVal;
3710 changed = true;
John Spurlock04db1762013-05-13 12:46:41 -04003711 mHandler.postDelayed(mClearHideNavigationFlag, 1000);
Dianne Hackborne26ab702011-10-16 13:21:33 -07003712 }
Dianne Hackborndf89e652011-10-06 22:35:11 -07003713 }
3714 if (changed) {
3715 mWindowManagerFuncs.reevaluateStatusBarVisibility();
3716 }
3717 }
3718 }
3719 } finally {
Jeff Brown32cbc38552011-12-01 14:01:49 -08003720 finishInputEvent(event, handled);
Dianne Hackborndf89e652011-10-06 22:35:11 -07003721 }
3722 }
Jeff Brown32cbc38552011-12-01 14:01:49 -08003723 }
3724 final InputEventReceiver.Factory mHideNavInputEventReceiverFactory =
3725 new InputEventReceiver.Factory() {
3726 @Override
3727 public InputEventReceiver createInputEventReceiver(
3728 InputChannel inputChannel, Looper looper) {
3729 return new HideNavInputEventReceiver(inputChannel, looper);
3730 }
Dianne Hackborndf89e652011-10-06 22:35:11 -07003731 };
3732
3733 @Override
3734 public int adjustSystemUiVisibilityLw(int visibility) {
John Spurlock5b9145b2013-08-20 15:13:47 -04003735 mStatusBarController.adjustSystemUiVisibilityLw(mLastSystemUiFlags, visibility);
3736 mNavigationBarController.adjustSystemUiVisibilityLw(mLastSystemUiFlags, visibility);
Winson Chungd42a6cf2014-06-03 16:24:04 -07003737 mRecentsVisible = (visibility & View.RECENT_APPS_VISIBLE) > 0;
John Spurlock27735a42013-08-14 17:57:38 -04003738
Dianne Hackborndf89e652011-10-06 22:35:11 -07003739 // Reset any bits in mForceClearingStatusBarVisibility that
3740 // are now clear.
Dianne Hackborne26ab702011-10-16 13:21:33 -07003741 mResettingSystemUiFlags &= visibility;
Dianne Hackborndf89e652011-10-06 22:35:11 -07003742 // Clear any bits in the new visibility that are currently being
3743 // force cleared, before reporting it.
Dianne Hackborne26ab702011-10-16 13:21:33 -07003744 return visibility & ~mResettingSystemUiFlags
3745 & ~mForceClearedSystemUiFlags;
Dianne Hackborndf89e652011-10-06 22:35:11 -07003746 }
3747
Craig Mautner69b08182012-09-05 13:07:13 -07003748 @Override
Jorim Jaggi0ffd49c2016-02-12 15:04:21 -08003749 public boolean getInsetHintLw(WindowManager.LayoutParams attrs, int displayRotation,
Filip Gruszczynski2987f612015-06-30 15:03:30 -07003750 Rect outContentInsets, Rect outStableInsets, Rect outOutsets) {
John Spurlockc6d1c602014-01-17 15:22:06 -05003751 final int fl = PolicyControl.getWindowFlags(null, attrs);
John Spurlock1db8b682014-02-18 11:18:59 -05003752 final int sysuiVis = PolicyControl.getSystemUiVisibility(null, attrs);
3753 final int systemUiVisibility = (sysuiVis | attrs.subtreeSystemUiVisibility);
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07003754
Filip Gruszczynski2987f612015-06-30 15:03:30 -07003755 final boolean useOutsets = outOutsets != null && shouldUseOutsets(attrs, fl);
3756 if (useOutsets) {
3757 int outset = ScreenShapeHelper.getWindowOutsetBottomPx(mContext.getResources());
3758 if (outset > 0) {
3759 if (displayRotation == Surface.ROTATION_0) {
3760 outOutsets.bottom += outset;
3761 } else if (displayRotation == Surface.ROTATION_90) {
3762 outOutsets.right += outset;
3763 } else if (displayRotation == Surface.ROTATION_180) {
3764 outOutsets.top += outset;
3765 } else if (displayRotation == Surface.ROTATION_270) {
3766 outOutsets.left += outset;
3767 }
3768 }
3769 }
3770
Dianne Hackborn5b5cc4d2012-05-16 13:15:00 -07003771 if ((fl & (FLAG_LAYOUT_IN_SCREEN | FLAG_LAYOUT_INSET_DECOR))
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003772 == (FLAG_LAYOUT_IN_SCREEN | FLAG_LAYOUT_INSET_DECOR)) {
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07003773 int availRight, availBottom;
Alan Viverette5a0f4ec2013-10-07 15:10:29 -07003774 if (canHideNavigationBar() &&
Dianne Hackborn5b5cc4d2012-05-16 13:15:00 -07003775 (systemUiVisibility & View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION) != 0) {
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07003776 availRight = mUnrestrictedScreenLeft + mUnrestrictedScreenWidth;
3777 availBottom = mUnrestrictedScreenTop + mUnrestrictedScreenHeight;
3778 } else {
3779 availRight = mRestrictedScreenLeft + mRestrictedScreenWidth;
3780 availBottom = mRestrictedScreenTop + mRestrictedScreenHeight;
3781 }
Dianne Hackborn5b5cc4d2012-05-16 13:15:00 -07003782 if ((systemUiVisibility & View.SYSTEM_UI_FLAG_LAYOUT_STABLE) != 0) {
3783 if ((fl & FLAG_FULLSCREEN) != 0) {
Adrian Roos37d7a682014-11-06 18:15:16 +01003784 outContentInsets.set(mStableFullscreenLeft, mStableFullscreenTop,
Dianne Hackborn5b5cc4d2012-05-16 13:15:00 -07003785 availRight - mStableFullscreenRight,
3786 availBottom - mStableFullscreenBottom);
3787 } else {
Adrian Roos37d7a682014-11-06 18:15:16 +01003788 outContentInsets.set(mStableLeft, mStableTop,
Dianne Hackborn5b5cc4d2012-05-16 13:15:00 -07003789 availRight - mStableRight, availBottom - mStableBottom);
3790 }
Dianne Hackbornc652de82013-02-15 16:32:56 -08003791 } else if ((fl & FLAG_FULLSCREEN) != 0 || (fl & FLAG_LAYOUT_IN_OVERSCAN) != 0) {
Adrian Roos37d7a682014-11-06 18:15:16 +01003792 outContentInsets.setEmpty();
Dianne Hackborn5b5cc4d2012-05-16 13:15:00 -07003793 } else if ((systemUiVisibility & (View.SYSTEM_UI_FLAG_FULLSCREEN
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07003794 | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN)) == 0) {
Adrian Roos37d7a682014-11-06 18:15:16 +01003795 outContentInsets.set(mCurLeft, mCurTop,
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07003796 availRight - mCurRight, availBottom - mCurBottom);
3797 } else {
Adrian Roos37d7a682014-11-06 18:15:16 +01003798 outContentInsets.set(mCurLeft, mCurTop,
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07003799 availRight - mCurRight, availBottom - mCurBottom);
3800 }
Adrian Roos37d7a682014-11-06 18:15:16 +01003801
3802 outStableInsets.set(mStableLeft, mStableTop,
3803 availRight - mStableRight, availBottom - mStableBottom);
Jorim Jaggi0ffd49c2016-02-12 15:04:21 -08003804 return mForceShowSystemBars;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003805 }
Adrian Roos37d7a682014-11-06 18:15:16 +01003806 outContentInsets.setEmpty();
3807 outStableInsets.setEmpty();
Jorim Jaggi0ffd49c2016-02-12 15:04:21 -08003808 return mForceShowSystemBars;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003809 }
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07003810
Filip Gruszczynski2987f612015-06-30 15:03:30 -07003811 private boolean shouldUseOutsets(WindowManager.LayoutParams attrs, int fl) {
3812 return attrs.type == TYPE_WALLPAPER || (fl & (WindowManager.LayoutParams.FLAG_FULLSCREEN
3813 | WindowManager.LayoutParams.FLAG_LAYOUT_IN_OVERSCAN)) != 0;
3814 }
3815
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003816 /** {@inheritDoc} */
Craig Mautner69b08182012-09-05 13:07:13 -07003817 @Override
3818 public void beginLayoutLw(boolean isDefaultDisplay, int displayWidth, int displayHeight,
Sriram Viswanathan9ebbe6a2015-11-16 17:59:22 -08003819 int displayRotation, int uiMode) {
Filip Gruszczynski2987f612015-06-30 15:03:30 -07003820 mDisplayRotation = displayRotation;
Dianne Hackbornc652de82013-02-15 16:32:56 -08003821 final int overscanLeft, overscanTop, overscanRight, overscanBottom;
3822 if (isDefaultDisplay) {
3823 switch (displayRotation) {
3824 case Surface.ROTATION_90:
3825 overscanLeft = mOverscanTop;
3826 overscanTop = mOverscanRight;
3827 overscanRight = mOverscanBottom;
3828 overscanBottom = mOverscanLeft;
3829 break;
3830 case Surface.ROTATION_180:
3831 overscanLeft = mOverscanRight;
3832 overscanTop = mOverscanBottom;
3833 overscanRight = mOverscanLeft;
3834 overscanBottom = mOverscanTop;
3835 break;
3836 case Surface.ROTATION_270:
3837 overscanLeft = mOverscanBottom;
3838 overscanTop = mOverscanLeft;
3839 overscanRight = mOverscanTop;
3840 overscanBottom = mOverscanRight;
3841 break;
3842 default:
3843 overscanLeft = mOverscanLeft;
3844 overscanTop = mOverscanTop;
3845 overscanRight = mOverscanRight;
3846 overscanBottom = mOverscanBottom;
3847 break;
3848 }
3849 } else {
3850 overscanLeft = 0;
3851 overscanTop = 0;
3852 overscanRight = 0;
3853 overscanBottom = 0;
3854 }
Dianne Hackborn313440842013-02-19 19:22:59 -08003855 mOverscanScreenLeft = mRestrictedOverscanScreenLeft = 0;
3856 mOverscanScreenTop = mRestrictedOverscanScreenTop = 0;
3857 mOverscanScreenWidth = mRestrictedOverscanScreenWidth = displayWidth;
3858 mOverscanScreenHeight = mRestrictedOverscanScreenHeight = displayHeight;
Dianne Hackbornc652de82013-02-15 16:32:56 -08003859 mSystemLeft = 0;
3860 mSystemTop = 0;
3861 mSystemRight = displayWidth;
3862 mSystemBottom = displayHeight;
3863 mUnrestrictedScreenLeft = overscanLeft;
3864 mUnrestrictedScreenTop = overscanTop;
3865 mUnrestrictedScreenWidth = displayWidth - overscanLeft - overscanRight;
3866 mUnrestrictedScreenHeight = displayHeight - overscanTop - overscanBottom;
3867 mRestrictedScreenLeft = mUnrestrictedScreenLeft;
3868 mRestrictedScreenTop = mUnrestrictedScreenTop;
John Spurlockad3e6cb2013-04-30 08:47:43 -04003869 mRestrictedScreenWidth = mSystemGestures.screenWidth = mUnrestrictedScreenWidth;
3870 mRestrictedScreenHeight = mSystemGestures.screenHeight = mUnrestrictedScreenHeight;
Dianne Hackborne30e02f2014-05-27 18:24:45 -07003871 mDockLeft = mContentLeft = mVoiceContentLeft = mStableLeft = mStableFullscreenLeft
Dianne Hackbornc652de82013-02-15 16:32:56 -08003872 = mCurLeft = mUnrestrictedScreenLeft;
Dianne Hackborne30e02f2014-05-27 18:24:45 -07003873 mDockTop = mContentTop = mVoiceContentTop = mStableTop = mStableFullscreenTop
Dianne Hackbornc652de82013-02-15 16:32:56 -08003874 = mCurTop = mUnrestrictedScreenTop;
Dianne Hackborne30e02f2014-05-27 18:24:45 -07003875 mDockRight = mContentRight = mVoiceContentRight = mStableRight = mStableFullscreenRight
Dianne Hackbornc652de82013-02-15 16:32:56 -08003876 = mCurRight = displayWidth - overscanRight;
Dianne Hackborne30e02f2014-05-27 18:24:45 -07003877 mDockBottom = mContentBottom = mVoiceContentBottom = mStableBottom = mStableFullscreenBottom
Dianne Hackbornc652de82013-02-15 16:32:56 -08003878 = mCurBottom = displayHeight - overscanBottom;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003879 mDockLayer = 0x10000000;
Dianne Hackborn5c58de32012-04-28 19:52:37 -07003880 mStatusBarLayer = -1;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003881
Daniel Sandler8956dbb2011-04-22 07:55:02 -04003882 // start with the current dock rect, which will be (0,0,displayWidth,displayHeight)
3883 final Rect pf = mTmpParentFrame;
3884 final Rect df = mTmpDisplayFrame;
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003885 final Rect of = mTmpOverscanFrame;
Daniel Sandler8956dbb2011-04-22 07:55:02 -04003886 final Rect vf = mTmpVisibleFrame;
John Spurlock46646232013-09-30 22:32:42 -04003887 final Rect dcf = mTmpDecorFrame;
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003888 pf.left = df.left = of.left = vf.left = mDockLeft;
3889 pf.top = df.top = of.top = vf.top = mDockTop;
3890 pf.right = df.right = of.right = vf.right = mDockRight;
3891 pf.bottom = df.bottom = of.bottom = vf.bottom = mDockBottom;
John Spurlock46646232013-09-30 22:32:42 -04003892 dcf.setEmpty(); // Decor frame N/A for system bars.
Daniel Sandler8956dbb2011-04-22 07:55:02 -04003893
Craig Mautner69b08182012-09-05 13:07:13 -07003894 if (isDefaultDisplay) {
3895 // For purposes of putting out fake window up to steal focus, we will
3896 // drive nav being hidden only by whether it is requested.
John Spurlocke1f366f2013-08-05 12:22:40 -04003897 final int sysui = mLastSystemUiFlags;
3898 boolean navVisible = (sysui & View.SYSTEM_UI_FLAG_HIDE_NAVIGATION) == 0;
Adrian Roosea562512014-05-05 13:33:03 +02003899 boolean navTranslucent = (sysui
Jorim Jaggi4fa78922015-11-30 17:13:56 -08003900 & (View.NAVIGATION_BAR_TRANSLUCENT | View.NAVIGATION_BAR_TRANSPARENT)) != 0;
John Spurlockf1a36642013-10-12 17:50:42 -04003901 boolean immersive = (sysui & View.SYSTEM_UI_FLAG_IMMERSIVE) != 0;
3902 boolean immersiveSticky = (sysui & View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY) != 0;
3903 boolean navAllowedHidden = immersive || immersiveSticky;
3904 navTranslucent &= !immersiveSticky; // transient trumps translucent
Adrian Roos4fb3ee32014-08-22 19:29:09 +02003905 boolean isKeyguardShowing = isStatusBarKeyguard() && !mHideLockScreen;
3906 if (!isKeyguardShowing) {
3907 navTranslucent &= areTranslucentBarsAllowed();
3908 }
Dianne Hackborne26ab702011-10-16 13:21:33 -07003909
Craig Mautner69b08182012-09-05 13:07:13 -07003910 // When the navigation bar isn't visible, we put up a fake
3911 // input window to catch all touch events. This way we can
3912 // detect when the user presses anywhere to bring back the nav
3913 // bar and ensure the application doesn't see the event.
John Spurlockf1a36642013-10-12 17:50:42 -04003914 if (navVisible || navAllowedHidden) {
Selim Cinekf83e8242015-05-19 18:08:14 -07003915 if (mInputConsumer != null) {
3916 mInputConsumer.dismiss();
3917 mInputConsumer = null;
Craig Mautner69b08182012-09-05 13:07:13 -07003918 }
Selim Cinekf83e8242015-05-19 18:08:14 -07003919 } else if (mInputConsumer == null) {
3920 mInputConsumer = mWindowManagerFuncs.addInputConsumer(mHandler.getLooper(),
3921 mHideNavInputEventReceiverFactory);
Dianne Hackborne26ab702011-10-16 13:21:33 -07003922 }
Dianne Hackborne26ab702011-10-16 13:21:33 -07003923
Craig Mautner69b08182012-09-05 13:07:13 -07003924 // For purposes of positioning and showing the nav bar, if we have
3925 // decided that it can't be hidden (because of the screen aspect ratio),
3926 // then take that into account.
Alan Viverette5a0f4ec2013-10-07 15:10:29 -07003927 navVisible |= !canHideNavigationBar();
Dianne Hackbornf87d1962012-04-04 12:48:24 -07003928
Filip Gruszczynski83dd9552015-09-17 17:50:36 -07003929 boolean updateSysUiVisibility = layoutNavigationBar(displayWidth, displayHeight,
Sriram Viswanathan9ebbe6a2015-11-16 17:59:22 -08003930 displayRotation, uiMode, overscanRight, overscanBottom, dcf, navVisible, navTranslucent,
Filip Gruszczynski83dd9552015-09-17 17:50:36 -07003931 navAllowedHidden);
Craig Mautnereda67292013-04-28 13:50:14 -07003932 if (DEBUG_LAYOUT) Slog.i(TAG, String.format("mDock rect: (%d,%d - %d,%d)",
Craig Mautner69b08182012-09-05 13:07:13 -07003933 mDockLeft, mDockTop, mDockRight, mDockBottom));
Filip Gruszczynski83dd9552015-09-17 17:50:36 -07003934 updateSysUiVisibility |= layoutStatusBar(pf, df, of, vf, dcf, sysui, isKeyguardShowing);
John Spurlockad3e6cb2013-04-30 08:47:43 -04003935 if (updateSysUiVisibility) {
3936 updateSystemUiVisibilityLw();
3937 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003938 }
3939 }
3940
Filip Gruszczynski83dd9552015-09-17 17:50:36 -07003941 private boolean layoutStatusBar(Rect pf, Rect df, Rect of, Rect vf, Rect dcf, int sysui,
3942 boolean isKeyguardShowing) {
3943 // decide where the status bar goes ahead of time
3944 if (mStatusBar != null) {
3945 // apply any navigation bar insets
3946 pf.left = df.left = of.left = mUnrestrictedScreenLeft;
3947 pf.top = df.top = of.top = mUnrestrictedScreenTop;
3948 pf.right = df.right = of.right = mUnrestrictedScreenWidth + mUnrestrictedScreenLeft;
3949 pf.bottom = df.bottom = of.bottom = mUnrestrictedScreenHeight
3950 + mUnrestrictedScreenTop;
3951 vf.left = mStableLeft;
3952 vf.top = mStableTop;
3953 vf.right = mStableRight;
3954 vf.bottom = mStableBottom;
3955
3956 mStatusBarLayer = mStatusBar.getSurfaceLayer();
3957
3958 // Let the status bar determine its size.
3959 mStatusBar.computeFrameLw(pf /* parentFrame */, df /* displayFrame */,
3960 vf /* overlayFrame */, vf /* contentFrame */, vf /* visibleFrame */,
3961 dcf /* decorFrame */, vf /* stableFrame */, vf /* outsetFrame */);
3962
3963 // For layout, the status bar is always at the top with our fixed height.
3964 mStableTop = mUnrestrictedScreenTop + mStatusBarHeight;
3965
3966 boolean statusBarTransient = (sysui & View.STATUS_BAR_TRANSIENT) != 0;
3967 boolean statusBarTranslucent = (sysui
Jorim Jaggi4fa78922015-11-30 17:13:56 -08003968 & (View.STATUS_BAR_TRANSLUCENT | View.STATUS_BAR_TRANSPARENT)) != 0;
Filip Gruszczynski83dd9552015-09-17 17:50:36 -07003969 if (!isKeyguardShowing) {
3970 statusBarTranslucent &= areTranslucentBarsAllowed();
3971 }
3972
3973 // If the status bar is hidden, we don't want to cause
3974 // windows behind it to scroll.
3975 if (mStatusBar.isVisibleLw() && !statusBarTransient) {
3976 // Status bar may go away, so the screen area it occupies
3977 // is available to apps but just covering them when the
3978 // status bar is visible.
3979 mDockTop = mUnrestrictedScreenTop + mStatusBarHeight;
3980
3981 mContentTop = mVoiceContentTop = mCurTop = mDockTop;
3982 mContentBottom = mVoiceContentBottom = mCurBottom = mDockBottom;
3983 mContentLeft = mVoiceContentLeft = mCurLeft = mDockLeft;
3984 mContentRight = mVoiceContentRight = mCurRight = mDockRight;
3985
3986 if (DEBUG_LAYOUT) Slog.v(TAG, "Status bar: " +
3987 String.format(
3988 "dock=[%d,%d][%d,%d] content=[%d,%d][%d,%d] cur=[%d,%d][%d,%d]",
3989 mDockLeft, mDockTop, mDockRight, mDockBottom,
3990 mContentLeft, mContentTop, mContentRight, mContentBottom,
3991 mCurLeft, mCurTop, mCurRight, mCurBottom));
3992 }
3993 if (mStatusBar.isVisibleLw() && !mStatusBar.isAnimatingLw()
3994 && !statusBarTransient && !statusBarTranslucent
3995 && !mStatusBarController.wasRecentlyTranslucent()) {
3996 // If the opaque status bar is currently requested to be visible,
3997 // and not in the process of animating on or off, then
3998 // we can tell the app that it is covered by it.
3999 mSystemTop = mUnrestrictedScreenTop + mStatusBarHeight;
4000 }
4001 if (mStatusBarController.checkHiddenLw()) {
4002 return true;
4003 }
4004 }
4005 return false;
4006 }
4007
4008 private boolean layoutNavigationBar(int displayWidth, int displayHeight, int displayRotation,
Sriram Viswanathan9ebbe6a2015-11-16 17:59:22 -08004009 int uiMode, int overscanRight, int overscanBottom, Rect dcf, boolean navVisible,
Filip Gruszczynski83dd9552015-09-17 17:50:36 -07004010 boolean navTranslucent, boolean navAllowedHidden) {
4011 if (mNavigationBar != null) {
4012 boolean transientNavBarShowing = mNavigationBarController.isTransientShowing();
4013 // Force the navigation bar to its appropriate place and
4014 // size. We need to do this directly, instead of relying on
4015 // it to bubble up from the nav bar, because this needs to
4016 // change atomically with screen rotations.
Jorim Jaggi737af722015-12-31 10:42:27 +01004017 mNavigationBarOnBottom = isNavigationBarOnBottom(displayWidth, displayHeight);
Filip Gruszczynski83dd9552015-09-17 17:50:36 -07004018 if (mNavigationBarOnBottom) {
4019 // It's a system nav bar or a portrait screen; nav bar goes on bottom.
4020 int top = displayHeight - overscanBottom
Sriram Viswanathan9ebbe6a2015-11-16 17:59:22 -08004021 - getNavigationBarHeight(displayRotation, uiMode);
Filip Gruszczynski83dd9552015-09-17 17:50:36 -07004022 mTmpNavigationFrame.set(0, top, displayWidth, displayHeight - overscanBottom);
4023 mStableBottom = mStableFullscreenBottom = mTmpNavigationFrame.top;
4024 if (transientNavBarShowing) {
4025 mNavigationBarController.setBarShowingLw(true);
4026 } else if (navVisible) {
4027 mNavigationBarController.setBarShowingLw(true);
4028 mDockBottom = mTmpNavigationFrame.top;
4029 mRestrictedScreenHeight = mDockBottom - mRestrictedScreenTop;
4030 mRestrictedOverscanScreenHeight = mDockBottom - mRestrictedOverscanScreenTop;
4031 } else {
4032 // We currently want to hide the navigation UI.
4033 mNavigationBarController.setBarShowingLw(false);
4034 }
4035 if (navVisible && !navTranslucent && !navAllowedHidden
4036 && !mNavigationBar.isAnimatingLw()
4037 && !mNavigationBarController.wasRecentlyTranslucent()) {
4038 // If the opaque nav bar is currently requested to be visible,
4039 // and not in the process of animating on or off, then
4040 // we can tell the app that it is covered by it.
4041 mSystemBottom = mTmpNavigationFrame.top;
4042 }
4043 } else {
4044 // Landscape screen; nav bar goes to the right.
4045 int left = displayWidth - overscanRight
Sriram Viswanathan9ebbe6a2015-11-16 17:59:22 -08004046 - getNavigationBarWidth(displayRotation, uiMode);
Filip Gruszczynski83dd9552015-09-17 17:50:36 -07004047 mTmpNavigationFrame.set(left, 0, displayWidth - overscanRight, displayHeight);
4048 mStableRight = mStableFullscreenRight = mTmpNavigationFrame.left;
4049 if (transientNavBarShowing) {
4050 mNavigationBarController.setBarShowingLw(true);
4051 } else if (navVisible) {
4052 mNavigationBarController.setBarShowingLw(true);
4053 mDockRight = mTmpNavigationFrame.left;
4054 mRestrictedScreenWidth = mDockRight - mRestrictedScreenLeft;
4055 mRestrictedOverscanScreenWidth = mDockRight - mRestrictedOverscanScreenLeft;
4056 } else {
4057 // We currently want to hide the navigation UI.
4058 mNavigationBarController.setBarShowingLw(false);
4059 }
4060 if (navVisible && !navTranslucent && !navAllowedHidden
4061 && !mNavigationBar.isAnimatingLw()
4062 && !mNavigationBarController.wasRecentlyTranslucent()) {
4063 // If the nav bar is currently requested to be visible,
4064 // and not in the process of animating on or off, then
4065 // we can tell the app that it is covered by it.
4066 mSystemRight = mTmpNavigationFrame.left;
4067 }
4068 }
4069 // Make sure the content and current rectangles are updated to
4070 // account for the restrictions from the navigation bar.
4071 mContentTop = mVoiceContentTop = mCurTop = mDockTop;
4072 mContentBottom = mVoiceContentBottom = mCurBottom = mDockBottom;
4073 mContentLeft = mVoiceContentLeft = mCurLeft = mDockLeft;
4074 mContentRight = mVoiceContentRight = mCurRight = mDockRight;
4075 mStatusBarLayer = mNavigationBar.getSurfaceLayer();
4076 // And compute the final frame.
4077 mNavigationBar.computeFrameLw(mTmpNavigationFrame, mTmpNavigationFrame,
4078 mTmpNavigationFrame, mTmpNavigationFrame, mTmpNavigationFrame, dcf,
4079 mTmpNavigationFrame, mTmpNavigationFrame);
4080 if (DEBUG_LAYOUT) Slog.i(TAG, "mNavigationBar frame: " + mTmpNavigationFrame);
4081 if (mNavigationBarController.checkHiddenLw()) {
4082 return true;
4083 }
4084 }
4085 return false;
4086 }
4087
Jorim Jaggi737af722015-12-31 10:42:27 +01004088 private boolean isNavigationBarOnBottom(int displayWidth, int displayHeight) {
4089 return !mNavigationBarCanMove || displayWidth < displayHeight;
4090 }
4091
Dianne Hackborn85afd1b2012-05-13 13:31:06 -07004092 /** {@inheritDoc} */
Craig Mautner967212c2013-04-13 21:10:58 -07004093 @Override
John Spurlock46646232013-09-30 22:32:42 -04004094 public int getSystemDecorLayerLw() {
Bryce Lee2ed3e5f2015-04-01 22:09:19 +00004095 if (mStatusBar != null && mStatusBar.isVisibleLw()) {
4096 return mStatusBar.getSurfaceLayer();
4097 }
4098
4099 if (mNavigationBar != null && mNavigationBar.isVisibleLw()) {
4100 return mNavigationBar.getSurfaceLayer();
4101 }
4102
Dianne Hackborn85afd1b2012-05-13 13:31:06 -07004103 return 0;
4104 }
4105
Craig Mautner967212c2013-04-13 21:10:58 -07004106 @Override
4107 public void getContentRectLw(Rect r) {
4108 r.set(mContentLeft, mContentTop, mContentRight, mContentBottom);
4109 }
4110
Dianne Hackbornc4aad012013-02-22 15:05:25 -08004111 void setAttachedWindowFrames(WindowState win, int fl, int adjust, WindowState attached,
4112 boolean insetDecors, Rect pf, Rect df, Rect of, Rect cf, Rect vf) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004113 if (win.getSurfaceLayer() > mDockLayer && attached.getSurfaceLayer() < mDockLayer) {
4114 // Here's a special case: if this attached window is a panel that is
4115 // above the dock window, and the window it is attached to is below
4116 // the dock window, then the frames we computed for the window it is
4117 // attached to can not be used because the dock is effectively part
4118 // of the underlying window and the attached window is floating on top
4119 // of the whole thing. So, we ignore the attached window and explicitly
4120 // compute the frames that would be appropriate without the dock.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08004121 df.left = of.left = cf.left = vf.left = mDockLeft;
4122 df.top = of.top = cf.top = vf.top = mDockTop;
4123 df.right = of.right = cf.right = vf.right = mDockRight;
4124 df.bottom = of.bottom = cf.bottom = vf.bottom = mDockBottom;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004125 } else {
4126 // The effective display frame of the attached window depends on
4127 // whether it is taking care of insetting its content. If not,
4128 // we need to use the parent's content frame so that the entire
4129 // window is positioned within that content. Otherwise we can use
Wale Ogunwale393b1c12014-10-18 16:22:01 -07004130 // the overscan frame and let the attached window take care of
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004131 // positioning its content appropriately.
Dianne Hackborndea3ef72010-10-28 14:24:22 -07004132 if (adjust != SOFT_INPUT_ADJUST_RESIZE) {
Wale Ogunwale393b1c12014-10-18 16:22:01 -07004133 // Set the content frame of the attached window to the parent's decor frame
4134 // (same as content frame when IME isn't present) if specifically requested by
4135 // setting {@link WindowManager.LayoutParams#FLAG_LAYOUT_ATTACHED_IN_DECOR} flag.
4136 // Otherwise, use the overscan frame.
4137 cf.set((fl & FLAG_LAYOUT_ATTACHED_IN_DECOR) != 0
4138 ? attached.getContentFrameLw() : attached.getOverscanFrameLw());
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004139 } else {
4140 // If the window is resizing, then we want to base the content
4141 // frame on our attached content frame to resize... however,
4142 // things can be tricky if the attached window is NOT in resize
4143 // mode, in which case its content frame will be larger.
4144 // Ungh. So to deal with that, make sure the content frame
4145 // we end up using is not covering the IM dock.
4146 cf.set(attached.getContentFrameLw());
Dianne Hackborne30e02f2014-05-27 18:24:45 -07004147 if (attached.isVoiceInteraction()) {
4148 if (cf.left < mVoiceContentLeft) cf.left = mVoiceContentLeft;
4149 if (cf.top < mVoiceContentTop) cf.top = mVoiceContentTop;
4150 if (cf.right > mVoiceContentRight) cf.right = mVoiceContentRight;
4151 if (cf.bottom > mVoiceContentBottom) cf.bottom = mVoiceContentBottom;
4152 } else if (attached.getSurfaceLayer() < mDockLayer) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004153 if (cf.left < mContentLeft) cf.left = mContentLeft;
4154 if (cf.top < mContentTop) cf.top = mContentTop;
4155 if (cf.right > mContentRight) cf.right = mContentRight;
4156 if (cf.bottom > mContentBottom) cf.bottom = mContentBottom;
4157 }
4158 }
4159 df.set(insetDecors ? attached.getDisplayFrameLw() : cf);
Dianne Hackbornc4aad012013-02-22 15:05:25 -08004160 of.set(insetDecors ? attached.getOverscanFrameLw() : cf);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004161 vf.set(attached.getVisibleFrameLw());
4162 }
4163 // The LAYOUT_IN_SCREEN flag is used to determine whether the attached
4164 // window should be positioned relative to its parent or the entire
4165 // screen.
4166 pf.set((fl & FLAG_LAYOUT_IN_SCREEN) == 0
4167 ? attached.getFrameLw() : df);
4168 }
Dianne Hackborn5b5cc4d2012-05-16 13:15:00 -07004169
4170 private void applyStableConstraints(int sysui, int fl, Rect r) {
4171 if ((sysui & View.SYSTEM_UI_FLAG_LAYOUT_STABLE) != 0) {
4172 // If app is requesting a stable layout, don't let the
4173 // content insets go below the stable values.
4174 if ((fl & FLAG_FULLSCREEN) != 0) {
4175 if (r.left < mStableFullscreenLeft) r.left = mStableFullscreenLeft;
4176 if (r.top < mStableFullscreenTop) r.top = mStableFullscreenTop;
4177 if (r.right > mStableFullscreenRight) r.right = mStableFullscreenRight;
4178 if (r.bottom > mStableFullscreenBottom) r.bottom = mStableFullscreenBottom;
4179 } else {
4180 if (r.left < mStableLeft) r.left = mStableLeft;
4181 if (r.top < mStableTop) r.top = mStableTop;
4182 if (r.right > mStableRight) r.right = mStableRight;
4183 if (r.bottom > mStableBottom) r.bottom = mStableBottom;
4184 }
4185 }
4186 }
4187
Jorim Jaggiaa806142015-05-20 18:04:16 -07004188 private boolean canReceiveInput(WindowState win) {
4189 boolean notFocusable =
4190 (win.getAttrs().flags & WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE) != 0;
4191 boolean altFocusableIm =
4192 (win.getAttrs().flags & WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM) != 0;
4193 boolean notFocusableForIm = notFocusable ^ altFocusableIm;
4194 return !notFocusableForIm;
4195 }
4196
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004197 /** {@inheritDoc} */
Craig Mautner69b08182012-09-05 13:07:13 -07004198 @Override
Craig Mautnerc9457fa2014-06-06 14:27:48 -07004199 public void layoutWindowLw(WindowState win, WindowState attached) {
Jorim Jaggiaa806142015-05-20 18:04:16 -07004200 // We've already done the navigation bar and status bar. If the status bar can receive
4201 // input, we need to layout it again to accomodate for the IME window.
4202 if ((win == mStatusBar && !canReceiveInput(win)) || win == mNavigationBar) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004203 return;
4204 }
Jorim Jaggiaa806142015-05-20 18:04:16 -07004205 final WindowManager.LayoutParams attrs = win.getAttrs();
Craig Mautner69b08182012-09-05 13:07:13 -07004206 final boolean isDefaultDisplay = win.isDefaultDisplay();
4207 final boolean needsToOffsetInputMethodTarget = isDefaultDisplay &&
satok1bc0a492012-04-25 22:47:12 +09004208 (win == mLastInputMethodTargetWindow && mLastInputMethodWindow != null);
4209 if (needsToOffsetInputMethodTarget) {
Craig Mautnereda67292013-04-28 13:50:14 -07004210 if (DEBUG_LAYOUT) Slog.i(TAG, "Offset ime target window by the last ime window state");
satok1bc0a492012-04-25 22:47:12 +09004211 offsetInputMethodWindowLw(mLastInputMethodWindow);
4212 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004213
John Spurlockc6d1c602014-01-17 15:22:06 -05004214 final int fl = PolicyControl.getWindowFlags(win, attrs);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004215 final int sim = attrs.softInputMode;
John Spurlock1db8b682014-02-18 11:18:59 -05004216 final int sysUiFl = PolicyControl.getSystemUiVisibility(win, null);
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07004217
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004218 final Rect pf = mTmpParentFrame;
4219 final Rect df = mTmpDisplayFrame;
Dianne Hackbornc4aad012013-02-22 15:05:25 -08004220 final Rect of = mTmpOverscanFrame;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004221 final Rect cf = mTmpContentFrame;
4222 final Rect vf = mTmpVisibleFrame;
John Spurlock46646232013-09-30 22:32:42 -04004223 final Rect dcf = mTmpDecorFrame;
Adrian Roosfa104232014-06-20 16:10:14 -07004224 final Rect sf = mTmpStableFrame;
Filip Gruszczynski2217f612015-05-26 11:32:08 -07004225 Rect osf = null;
John Spurlock46646232013-09-30 22:32:42 -04004226 dcf.setEmpty();
Craig Mautner69b08182012-09-05 13:07:13 -07004227
4228 final boolean hasNavBar = (isDefaultDisplay && mHasNavigationBar
Daniel Sandler36412a72011-08-04 09:35:13 -04004229 && mNavigationBar != null && mNavigationBar.isVisibleLw());
Daniel Sandler8956dbb2011-04-22 07:55:02 -04004230
Craig Mautnerf683b562012-10-02 11:10:57 -07004231 final int adjust = sim & SOFT_INPUT_MASK_ADJUST;
4232
Adrian Roosfa104232014-06-20 16:10:14 -07004233 if (isDefaultDisplay) {
4234 sf.set(mStableLeft, mStableTop, mStableRight, mStableBottom);
4235 } else {
4236 sf.set(mOverscanLeft, mOverscanTop, mOverscanRight, mOverscanBottom);
4237 }
4238
Craig Mautner69b08182012-09-05 13:07:13 -07004239 if (!isDefaultDisplay) {
4240 if (attached != null) {
4241 // If this window is attached to another, our display
4242 // frame is the same as the one we are attached to.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08004243 setAttachedWindowFrames(win, fl, adjust, attached, true, pf, df, of, cf, vf);
Craig Mautner69b08182012-09-05 13:07:13 -07004244 } else {
4245 // Give the window full screen.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08004246 pf.left = df.left = of.left = cf.left = mOverscanScreenLeft;
4247 pf.top = df.top = of.top = cf.top = mOverscanScreenTop;
4248 pf.right = df.right = of.right = cf.right
Dianne Hackbornc652de82013-02-15 16:32:56 -08004249 = mOverscanScreenLeft + mOverscanScreenWidth;
Dianne Hackbornc4aad012013-02-22 15:05:25 -08004250 pf.bottom = df.bottom = of.bottom = cf.bottom
Dianne Hackbornc652de82013-02-15 16:32:56 -08004251 = mOverscanScreenTop + mOverscanScreenHeight;
Craig Mautner69b08182012-09-05 13:07:13 -07004252 }
Jorim Jaggi225d3b52015-04-01 11:18:57 -07004253 } else if (attrs.type == TYPE_INPUT_METHOD) {
Dianne Hackbornc4aad012013-02-22 15:05:25 -08004254 pf.left = df.left = of.left = cf.left = vf.left = mDockLeft;
4255 pf.top = df.top = of.top = cf.top = vf.top = mDockTop;
4256 pf.right = df.right = of.right = cf.right = vf.right = mDockRight;
John Spurlockc68d5772013-10-08 11:47:58 -04004257 // IM dock windows layout below the nav bar...
John Spurlock57beb3b2013-10-10 10:27:44 -04004258 pf.bottom = df.bottom = of.bottom = mUnrestrictedScreenTop + mUnrestrictedScreenHeight;
John Spurlockc68d5772013-10-08 11:47:58 -04004259 // ...with content insets above the nav bar
4260 cf.bottom = vf.bottom = mStableBottom;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004261 // IM dock windows always go to the bottom of the screen.
4262 attrs.gravity = Gravity.BOTTOM;
4263 mDockLayer = win.getSurfaceLayer();
Jorim Jaggi225d3b52015-04-01 11:18:57 -07004264 } else if (attrs.type == TYPE_VOICE_INTERACTION) {
Stefan Kuhne2f280d062015-06-18 07:20:33 -10004265 pf.left = df.left = of.left = mUnrestrictedScreenLeft;
Jorim Jaggi225d3b52015-04-01 11:18:57 -07004266 pf.top = df.top = of.top = mUnrestrictedScreenTop;
Stefan Kuhne2f280d062015-06-18 07:20:33 -10004267 pf.right = df.right = of.right = mUnrestrictedScreenLeft + mUnrestrictedScreenWidth;
4268 pf.bottom = df.bottom = of.bottom = mUnrestrictedScreenTop + mUnrestrictedScreenHeight;
Jorim Jaggi225d3b52015-04-01 11:18:57 -07004269 cf.bottom = vf.bottom = mStableBottom;
Stefan Kuhne2f280d062015-06-18 07:20:33 -10004270 // Note: In Phone landscape mode, the button bar should also be excluded.
4271 cf.right = vf.right = mStableRight;
4272 cf.left = vf.left = mStableLeft;
Jorim Jaggi225d3b52015-04-01 11:18:57 -07004273 cf.top = vf.top = mStableTop;
Jorim Jaggiaa806142015-05-20 18:04:16 -07004274 } else if (win == mStatusBar) {
Jorim Jaggie0700182014-08-21 01:12:37 +02004275 pf.left = df.left = of.left = mUnrestrictedScreenLeft;
4276 pf.top = df.top = of.top = mUnrestrictedScreenTop;
4277 pf.right = df.right = of.right = mUnrestrictedScreenWidth + mUnrestrictedScreenLeft;
4278 pf.bottom = df.bottom = of.bottom = mUnrestrictedScreenHeight + mUnrestrictedScreenTop;
4279 cf.left = vf.left = mStableLeft;
4280 cf.top = vf.top = mStableTop;
4281 cf.right = vf.right = mStableRight;
4282 vf.bottom = mStableBottom;
Adrian Roosdc5b4532016-01-06 20:49:41 +01004283
4284 if (adjust == SOFT_INPUT_ADJUST_RESIZE) {
4285 cf.bottom = mContentBottom;
4286 } else {
4287 cf.bottom = mDockBottom;
4288 vf.bottom = mContentBottom;
4289 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004290 } else {
John Spurlock46646232013-09-30 22:32:42 -04004291
4292 // Default policy decor for the default display
4293 dcf.left = mSystemLeft;
4294 dcf.top = mSystemTop;
4295 dcf.right = mSystemRight;
4296 dcf.bottom = mSystemBottom;
John Spurlockbd957402013-10-03 11:38:39 -04004297 final boolean inheritTranslucentDecor = (attrs.privateFlags
4298 & WindowManager.LayoutParams.PRIVATE_FLAG_INHERIT_TRANSLUCENT_DECOR) != 0;
John Spurlock65567d42013-10-08 10:08:32 -04004299 final boolean isAppWindow =
4300 attrs.type >= WindowManager.LayoutParams.FIRST_APPLICATION_WINDOW &&
4301 attrs.type <= WindowManager.LayoutParams.LAST_APPLICATION_WINDOW;
4302 final boolean topAtRest =
4303 win == mTopFullscreenOpaqueWindowState && !win.isAnimatingLw();
4304 if (isAppWindow && !inheritTranslucentDecor && !topAtRest) {
John Spurlockbd957402013-10-03 11:38:39 -04004305 if ((sysUiFl & View.SYSTEM_UI_FLAG_FULLSCREEN) == 0
4306 && (fl & WindowManager.LayoutParams.FLAG_FULLSCREEN) == 0
Adrian Roosea562512014-05-05 13:33:03 +02004307 && (fl & WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS) == 0
4308 && (fl & WindowManager.LayoutParams.
Jorim Jaggi4fa78922015-11-30 17:13:56 -08004309 FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS) == 0
4310 && !mForceWindowDrawsStatusBarBackground) {
John Spurlock46646232013-09-30 22:32:42 -04004311 // Ensure policy decor includes status bar
4312 dcf.top = mStableTop;
4313 }
John Spurlockbd957402013-10-03 11:38:39 -04004314 if ((fl & WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION) == 0
Adrian Roosea562512014-05-05 13:33:03 +02004315 && (sysUiFl & View.SYSTEM_UI_FLAG_HIDE_NAVIGATION) == 0
4316 && (fl & WindowManager.LayoutParams.
4317 FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS) == 0) {
John Spurlock46646232013-09-30 22:32:42 -04004318 // Ensure policy decor includes navigation bar
4319 dcf.bottom = mStableBottom;
4320 dcf.right = mStableRight;
4321 }
4322 }
4323
Dianne Hackbornc4aad012013-02-22 15:05:25 -08004324 if ((fl & (FLAG_LAYOUT_IN_SCREEN | FLAG_LAYOUT_INSET_DECOR))
4325 == (FLAG_LAYOUT_IN_SCREEN | FLAG_LAYOUT_INSET_DECOR)) {
RoboErik8a2cfc32014-05-16 11:19:38 -07004326 if (DEBUG_LAYOUT) Slog.v(TAG, "layoutWindowLw(" + attrs.getTitle()
Dianne Hackbornc4aad012013-02-22 15:05:25 -08004327 + "): IN_SCREEN, INSET_DECOR");
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004328 // This is the case for a normal activity window: we want it
4329 // to cover all of the screen space, and it can take care of
4330 // moving its contents to account for screen decorations that
4331 // intrude into that space.
4332 if (attached != null) {
4333 // If this window is attached to another, our display
4334 // frame is the same as the one we are attached to.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08004335 setAttachedWindowFrames(win, fl, adjust, attached, true, pf, df, of, cf, vf);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004336 } else {
Daniel Sandler8956dbb2011-04-22 07:55:02 -04004337 if (attrs.type == TYPE_STATUS_BAR_PANEL
4338 || attrs.type == TYPE_STATUS_BAR_SUB_PANEL) {
Joe Onorato29fc2c92010-11-24 10:26:50 -08004339 // Status bar panels are the only windows who can go on top of
4340 // the status bar. They are protected by the STATUS_BAR_SERVICE
4341 // permission, so they have the same privileges as the status
4342 // bar itself.
Daniel Sandler8956dbb2011-04-22 07:55:02 -04004343 //
Daniel Sandler8e8b4152011-07-21 01:16:43 -04004344 // However, they should still dodge the navigation bar if it exists.
Daniel Sandler8956dbb2011-04-22 07:55:02 -04004345
Dianne Hackbornc4aad012013-02-22 15:05:25 -08004346 pf.left = df.left = of.left = hasNavBar
4347 ? mDockLeft : mUnrestrictedScreenLeft;
4348 pf.top = df.top = of.top = mUnrestrictedScreenTop;
4349 pf.right = df.right = of.right = hasNavBar
4350 ? mRestrictedScreenLeft+mRestrictedScreenWidth
4351 : mUnrestrictedScreenLeft + mUnrestrictedScreenWidth;
4352 pf.bottom = df.bottom = of.bottom = hasNavBar
4353 ? mRestrictedScreenTop+mRestrictedScreenHeight
4354 : mUnrestrictedScreenTop + mUnrestrictedScreenHeight;
Daniel Sandler8956dbb2011-04-22 07:55:02 -04004355
Craig Mautnereda67292013-04-28 13:50:14 -07004356 if (DEBUG_LAYOUT) Slog.v(TAG, String.format(
Daniel Sandler8e8b4152011-07-21 01:16:43 -04004357 "Laying out status bar window: (%d,%d - %d,%d)",
4358 pf.left, pf.top, pf.right, pf.bottom));
John Spurlock46646232013-09-30 22:32:42 -04004359 } else if ((fl & FLAG_LAYOUT_IN_OVERSCAN) != 0
Dianne Hackbornc652de82013-02-15 16:32:56 -08004360 && attrs.type >= WindowManager.LayoutParams.FIRST_APPLICATION_WINDOW
4361 && attrs.type <= WindowManager.LayoutParams.LAST_SUB_WINDOW) {
4362 // Asking to layout into the overscan region, so give it that pure
4363 // unrestricted area.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08004364 pf.left = df.left = of.left = mOverscanScreenLeft;
4365 pf.top = df.top = of.top = mOverscanScreenTop;
4366 pf.right = df.right = of.right = mOverscanScreenLeft + mOverscanScreenWidth;
4367 pf.bottom = df.bottom = of.bottom = mOverscanScreenTop
4368 + mOverscanScreenHeight;
Alan Viverette5a0f4ec2013-10-07 15:10:29 -07004369 } else if (canHideNavigationBar()
Dianne Hackbornf87d1962012-04-04 12:48:24 -07004370 && (sysUiFl & View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION) != 0
Jorim Jaggi380ecb82014-03-14 17:25:20 +01004371 && attrs.type >= WindowManager.LayoutParams.FIRST_APPLICATION_WINDOW
4372 && attrs.type <= WindowManager.LayoutParams.LAST_SUB_WINDOW) {
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07004373 // Asking for layout as if the nav bar is hidden, lets the
Dianne Hackbornc652de82013-02-15 16:32:56 -08004374 // application extend into the unrestricted overscan screen area. We
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07004375 // only do this for application windows to ensure no window that
4376 // can be above the nav bar can do this.
Dianne Hackborn313440842013-02-19 19:22:59 -08004377 pf.left = df.left = mOverscanScreenLeft;
4378 pf.top = df.top = mOverscanScreenTop;
4379 pf.right = df.right = mOverscanScreenLeft + mOverscanScreenWidth;
4380 pf.bottom = df.bottom = mOverscanScreenTop + mOverscanScreenHeight;
Dianne Hackbornc4aad012013-02-22 15:05:25 -08004381 // We need to tell the app about where the frame inside the overscan
4382 // is, so it can inset its content by that amount -- it didn't ask
4383 // to actually extend itself into the overscan region.
4384 of.left = mUnrestrictedScreenLeft;
4385 of.top = mUnrestrictedScreenTop;
4386 of.right = mUnrestrictedScreenLeft + mUnrestrictedScreenWidth;
4387 of.bottom = mUnrestrictedScreenTop + mUnrestrictedScreenHeight;
Joe Onorato29fc2c92010-11-24 10:26:50 -08004388 } else {
Dianne Hackborn313440842013-02-19 19:22:59 -08004389 pf.left = df.left = mRestrictedOverscanScreenLeft;
4390 pf.top = df.top = mRestrictedOverscanScreenTop;
4391 pf.right = df.right = mRestrictedOverscanScreenLeft
4392 + mRestrictedOverscanScreenWidth;
4393 pf.bottom = df.bottom = mRestrictedOverscanScreenTop
4394 + mRestrictedOverscanScreenHeight;
Dianne Hackbornc4aad012013-02-22 15:05:25 -08004395 // We need to tell the app about where the frame inside the overscan
4396 // is, so it can inset its content by that amount -- it didn't ask
4397 // to actually extend itself into the overscan region.
4398 of.left = mUnrestrictedScreenLeft;
4399 of.top = mUnrestrictedScreenTop;
4400 of.right = mUnrestrictedScreenLeft + mUnrestrictedScreenWidth;
4401 of.bottom = mUnrestrictedScreenTop + mUnrestrictedScreenHeight;
Joe Onorato29fc2c92010-11-24 10:26:50 -08004402 }
Craig Mautner69b08182012-09-05 13:07:13 -07004403
John Spurlock46646232013-09-30 22:32:42 -04004404 if ((fl & FLAG_FULLSCREEN) == 0) {
Dianne Hackborne30e02f2014-05-27 18:24:45 -07004405 if (win.isVoiceInteraction()) {
4406 cf.left = mVoiceContentLeft;
4407 cf.top = mVoiceContentTop;
4408 cf.right = mVoiceContentRight;
4409 cf.bottom = mVoiceContentBottom;
Dianne Hackbornc4aad012013-02-22 15:05:25 -08004410 } else {
Dianne Hackborne30e02f2014-05-27 18:24:45 -07004411 if (adjust != SOFT_INPUT_ADJUST_RESIZE) {
4412 cf.left = mDockLeft;
4413 cf.top = mDockTop;
4414 cf.right = mDockRight;
4415 cf.bottom = mDockBottom;
4416 } else {
4417 cf.left = mContentLeft;
4418 cf.top = mContentTop;
4419 cf.right = mContentRight;
4420 cf.bottom = mContentBottom;
4421 }
Dianne Hackbornc4aad012013-02-22 15:05:25 -08004422 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004423 } else {
Dianne Hackbornc4aad012013-02-22 15:05:25 -08004424 // Full screen windows are always given a layout that is as if the
4425 // status bar and other transient decors are gone. This is to avoid
4426 // bad states when moving from a window that is not hding the
4427 // status bar to one that is.
4428 cf.left = mRestrictedScreenLeft;
4429 cf.top = mRestrictedScreenTop;
4430 cf.right = mRestrictedScreenLeft + mRestrictedScreenWidth;
4431 cf.bottom = mRestrictedScreenTop + mRestrictedScreenHeight;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004432 }
Dianne Hackborn5b5cc4d2012-05-16 13:15:00 -07004433 applyStableConstraints(sysUiFl, fl, cf);
Dianne Hackborndea3ef72010-10-28 14:24:22 -07004434 if (adjust != SOFT_INPUT_ADJUST_NOTHING) {
4435 vf.left = mCurLeft;
4436 vf.top = mCurTop;
4437 vf.right = mCurRight;
4438 vf.bottom = mCurBottom;
4439 } else {
4440 vf.set(cf);
4441 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004442 }
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07004443 } else if ((fl & FLAG_LAYOUT_IN_SCREEN) != 0 || (sysUiFl
4444 & (View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
4445 | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION)) != 0) {
Craig Mautnereda67292013-04-28 13:50:14 -07004446 if (DEBUG_LAYOUT) Slog.v(TAG, "layoutWindowLw(" + attrs.getTitle() +
4447 "): IN_SCREEN");
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004448 // A window that has requested to fill the entire screen just
4449 // gets everything, period.
Daniel Sandler8956dbb2011-04-22 07:55:02 -04004450 if (attrs.type == TYPE_STATUS_BAR_PANEL
John Spurlock67a0f852015-06-15 15:35:47 -04004451 || attrs.type == TYPE_STATUS_BAR_SUB_PANEL
4452 || attrs.type == TYPE_VOLUME_OVERLAY) {
Dianne Hackbornc4aad012013-02-22 15:05:25 -08004453 pf.left = df.left = of.left = cf.left = hasNavBar
4454 ? mDockLeft : mUnrestrictedScreenLeft;
4455 pf.top = df.top = of.top = cf.top = mUnrestrictedScreenTop;
4456 pf.right = df.right = of.right = cf.right = hasNavBar
Daniel Sandler8e8b4152011-07-21 01:16:43 -04004457 ? mRestrictedScreenLeft+mRestrictedScreenWidth
Dianne Hackbornc652de82013-02-15 16:32:56 -08004458 : mUnrestrictedScreenLeft + mUnrestrictedScreenWidth;
Dianne Hackbornc4aad012013-02-22 15:05:25 -08004459 pf.bottom = df.bottom = of.bottom = cf.bottom = hasNavBar
Daniel Sandler8e8b4152011-07-21 01:16:43 -04004460 ? mRestrictedScreenTop+mRestrictedScreenHeight
Dianne Hackbornc652de82013-02-15 16:32:56 -08004461 : mUnrestrictedScreenTop + mUnrestrictedScreenHeight;
Craig Mautnereda67292013-04-28 13:50:14 -07004462 if (DEBUG_LAYOUT) Slog.v(TAG, String.format(
Daniel Sandler36412a72011-08-04 09:35:13 -04004463 "Laying out IN_SCREEN status bar window: (%d,%d - %d,%d)",
4464 pf.left, pf.top, pf.right, pf.bottom));
Jim Millere898ac52012-04-06 17:10:57 -07004465 } else if (attrs.type == TYPE_NAVIGATION_BAR
4466 || attrs.type == TYPE_NAVIGATION_BAR_PANEL) {
Daniel Sandler8e8b4152011-07-21 01:16:43 -04004467 // The navigation bar has Real Ultimate Power.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08004468 pf.left = df.left = of.left = mUnrestrictedScreenLeft;
4469 pf.top = df.top = of.top = mUnrestrictedScreenTop;
4470 pf.right = df.right = of.right = mUnrestrictedScreenLeft
4471 + mUnrestrictedScreenWidth;
4472 pf.bottom = df.bottom = of.bottom = mUnrestrictedScreenTop
4473 + mUnrestrictedScreenHeight;
Craig Mautnereda67292013-04-28 13:50:14 -07004474 if (DEBUG_LAYOUT) Slog.v(TAG, String.format(
Daniel Sandler8e8b4152011-07-21 01:16:43 -04004475 "Laying out navigation bar window: (%d,%d - %d,%d)",
4476 pf.left, pf.top, pf.right, pf.bottom));
Dianne Hackborn01011c32012-02-21 13:54:21 -08004477 } else if ((attrs.type == TYPE_SECURE_SYSTEM_OVERLAY
Muyuan Li6ca619f2016-03-08 13:30:42 -08004478 || attrs.type == TYPE_BOOT_PROGRESS
4479 || attrs.type == TYPE_SCREENSHOT)
Jeff Brownbfcb60a2011-09-08 18:51:14 -07004480 && ((fl & FLAG_FULLSCREEN) != 0)) {
Muyuan Li6ca619f2016-03-08 13:30:42 -08004481 // Fullscreen secure system overlays get what they ask for. Screenshot region
4482 // selection overlay should also expand to full screen.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08004483 pf.left = df.left = of.left = cf.left = mOverscanScreenLeft;
4484 pf.top = df.top = of.top = cf.top = mOverscanScreenTop;
4485 pf.right = df.right = of.right = cf.right = mOverscanScreenLeft
4486 + mOverscanScreenWidth;
4487 pf.bottom = df.bottom = of.bottom = cf.bottom = mOverscanScreenTop
4488 + mOverscanScreenHeight;
Craig Mautner165be0c2015-01-27 15:16:58 -08004489 } else if (attrs.type == TYPE_BOOT_PROGRESS) {
Dianne Hackborn01011c32012-02-21 13:54:21 -08004490 // Boot progress screen always covers entire display.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08004491 pf.left = df.left = of.left = cf.left = mOverscanScreenLeft;
4492 pf.top = df.top = of.top = cf.top = mOverscanScreenTop;
4493 pf.right = df.right = of.right = cf.right = mOverscanScreenLeft
4494 + mOverscanScreenWidth;
4495 pf.bottom = df.bottom = of.bottom = cf.bottom = mOverscanScreenTop
4496 + mOverscanScreenHeight;
John Spurlockef4adae2013-08-26 17:58:58 -04004497 } else if (attrs.type == TYPE_WALLPAPER) {
Dianne Hackborn067e5f62014-09-07 23:14:30 -07004498 // The wallpaper also has Real Ultimate Power, but we want to tell
4499 // it about the overscan area.
4500 pf.left = df.left = mOverscanScreenLeft;
4501 pf.top = df.top = mOverscanScreenTop;
4502 pf.right = df.right = mOverscanScreenLeft + mOverscanScreenWidth;
4503 pf.bottom = df.bottom = mOverscanScreenTop + mOverscanScreenHeight;
4504 of.left = cf.left = mUnrestrictedScreenLeft;
4505 of.top = cf.top = mUnrestrictedScreenTop;
4506 of.right = cf.right = mUnrestrictedScreenLeft + mUnrestrictedScreenWidth;
4507 of.bottom = cf.bottom = mUnrestrictedScreenTop + mUnrestrictedScreenHeight;
John Spurlock46646232013-09-30 22:32:42 -04004508 } else if ((fl & FLAG_LAYOUT_IN_OVERSCAN) != 0
Dianne Hackbornc652de82013-02-15 16:32:56 -08004509 && attrs.type >= WindowManager.LayoutParams.FIRST_APPLICATION_WINDOW
4510 && attrs.type <= WindowManager.LayoutParams.LAST_SUB_WINDOW) {
4511 // Asking to layout into the overscan region, so give it that pure
4512 // unrestricted area.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08004513 pf.left = df.left = of.left = cf.left = mOverscanScreenLeft;
4514 pf.top = df.top = of.top = cf.top = mOverscanScreenTop;
4515 pf.right = df.right = of.right = cf.right
Dianne Hackbornc652de82013-02-15 16:32:56 -08004516 = mOverscanScreenLeft + mOverscanScreenWidth;
Dianne Hackbornc4aad012013-02-22 15:05:25 -08004517 pf.bottom = df.bottom = of.bottom = cf.bottom
Dianne Hackbornc652de82013-02-15 16:32:56 -08004518 = mOverscanScreenTop + mOverscanScreenHeight;
Alan Viverette5a0f4ec2013-10-07 15:10:29 -07004519 } else if (canHideNavigationBar()
Dianne Hackbornf87d1962012-04-04 12:48:24 -07004520 && (sysUiFl & View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION) != 0
Craig Mautnerbeac1062014-06-03 14:38:57 -07004521 && (attrs.type == TYPE_STATUS_BAR
4522 || attrs.type == TYPE_TOAST
Jorim Jaggi81fe2d12015-12-21 14:45:18 +01004523 || attrs.type == TYPE_DOCK_DIVIDER
Jorim Jaggi2fdeeab2015-04-01 15:13:03 -07004524 || attrs.type == TYPE_VOICE_INTERACTION_STARTING
John Spurlock34e13d92013-08-10 06:52:28 -04004525 || (attrs.type >= WindowManager.LayoutParams.FIRST_APPLICATION_WINDOW
4526 && attrs.type <= WindowManager.LayoutParams.LAST_SUB_WINDOW))) {
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07004527 // Asking for layout as if the nav bar is hidden, lets the
4528 // application extend into the unrestricted screen area. We
John Spurlock34e13d92013-08-10 06:52:28 -04004529 // only do this for application windows (or toasts) to ensure no window that
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07004530 // can be above the nav bar can do this.
4531 // XXX This assumes that an app asking for this will also
4532 // ask for layout in only content. We can't currently figure out
4533 // what the screen would be if only laying out to hide the nav bar.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08004534 pf.left = df.left = of.left = cf.left = mUnrestrictedScreenLeft;
4535 pf.top = df.top = of.top = cf.top = mUnrestrictedScreenTop;
4536 pf.right = df.right = of.right = cf.right = mUnrestrictedScreenLeft
4537 + mUnrestrictedScreenWidth;
4538 pf.bottom = df.bottom = of.bottom = cf.bottom = mUnrestrictedScreenTop
4539 + mUnrestrictedScreenHeight;
Jorim Jaggi9f6798a2016-02-10 22:16:06 -08004540 } else if ((sysUiFl & View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN) != 0) {
4541 pf.left = df.left = of.left = mRestrictedScreenLeft;
4542 pf.top = df.top = of.top = mRestrictedScreenTop;
4543 pf.right = df.right = of.right = mRestrictedScreenLeft + mRestrictedScreenWidth;
4544 pf.bottom = df.bottom = of.bottom = mRestrictedScreenTop
4545 + mRestrictedScreenHeight;
4546 if (adjust != SOFT_INPUT_ADJUST_RESIZE) {
4547 cf.left = mDockLeft;
4548 cf.top = mDockTop;
4549 cf.right = mDockRight;
4550 cf.bottom = mDockBottom;
4551 } else {
4552 cf.left = mContentLeft;
4553 cf.top = mContentTop;
4554 cf.right = mContentRight;
4555 cf.bottom = mContentBottom;
4556 }
Joe Onorato29fc2c92010-11-24 10:26:50 -08004557 } else {
Dianne Hackbornc4aad012013-02-22 15:05:25 -08004558 pf.left = df.left = of.left = cf.left = mRestrictedScreenLeft;
4559 pf.top = df.top = of.top = cf.top = mRestrictedScreenTop;
4560 pf.right = df.right = of.right = cf.right = mRestrictedScreenLeft
4561 + mRestrictedScreenWidth;
4562 pf.bottom = df.bottom = of.bottom = cf.bottom = mRestrictedScreenTop
4563 + mRestrictedScreenHeight;
Joe Onorato29fc2c92010-11-24 10:26:50 -08004564 }
Craig Mautner69b08182012-09-05 13:07:13 -07004565
Dianne Hackborn5b5cc4d2012-05-16 13:15:00 -07004566 applyStableConstraints(sysUiFl, fl, cf);
Craig Mautner69b08182012-09-05 13:07:13 -07004567
Dianne Hackborndea3ef72010-10-28 14:24:22 -07004568 if (adjust != SOFT_INPUT_ADJUST_NOTHING) {
4569 vf.left = mCurLeft;
4570 vf.top = mCurTop;
4571 vf.right = mCurRight;
4572 vf.bottom = mCurBottom;
4573 } else {
4574 vf.set(cf);
4575 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004576 } else if (attached != null) {
Craig Mautnereda67292013-04-28 13:50:14 -07004577 if (DEBUG_LAYOUT) Slog.v(TAG, "layoutWindowLw(" + attrs.getTitle() +
4578 "): attached to " + attached);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004579 // A child window should be placed inside of the same visible
4580 // frame that its parent had.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08004581 setAttachedWindowFrames(win, fl, adjust, attached, false, pf, df, of, cf, vf);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004582 } else {
Craig Mautnereda67292013-04-28 13:50:14 -07004583 if (DEBUG_LAYOUT) Slog.v(TAG, "layoutWindowLw(" + attrs.getTitle() +
4584 "): normal window");
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004585 // Otherwise, a normal window must be placed inside the content
4586 // of all screen decorations.
John Spurlock67a0f852015-06-15 15:35:47 -04004587 if (attrs.type == TYPE_STATUS_BAR_PANEL || attrs.type == TYPE_VOLUME_OVERLAY) {
4588 // Status bar panels and the volume dialog are the only windows who can go on
4589 // top of the status bar. They are protected by the STATUS_BAR_SERVICE
Dianne Hackborna239c842011-06-01 12:28:20 -07004590 // permission, so they have the same privileges as the status
4591 // bar itself.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08004592 pf.left = df.left = of.left = cf.left = mRestrictedScreenLeft;
4593 pf.top = df.top = of.top = cf.top = mRestrictedScreenTop;
4594 pf.right = df.right = of.right = cf.right = mRestrictedScreenLeft
4595 + mRestrictedScreenWidth;
4596 pf.bottom = df.bottom = of.bottom = cf.bottom = mRestrictedScreenTop
4597 + mRestrictedScreenHeight;
John Spurlock67a0f852015-06-15 15:35:47 -04004598 } else if (attrs.type == TYPE_TOAST || attrs.type == TYPE_SYSTEM_ALERT) {
John Spurlock414c1f02013-12-04 13:47:36 -05004599 // These dialogs are stable to interim decor changes.
John Spurlockbd957402013-10-03 11:38:39 -04004600 pf.left = df.left = of.left = cf.left = mStableLeft;
4601 pf.top = df.top = of.top = cf.top = mStableTop;
4602 pf.right = df.right = of.right = cf.right = mStableRight;
4603 pf.bottom = df.bottom = of.bottom = cf.bottom = mStableBottom;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004604 } else {
Dianne Hackborna239c842011-06-01 12:28:20 -07004605 pf.left = mContentLeft;
4606 pf.top = mContentTop;
4607 pf.right = mContentRight;
4608 pf.bottom = mContentBottom;
Dianne Hackborn20d94742014-05-29 18:35:45 -07004609 if (win.isVoiceInteraction()) {
4610 df.left = of.left = cf.left = mVoiceContentLeft;
4611 df.top = of.top = cf.top = mVoiceContentTop;
4612 df.right = of.right = cf.right = mVoiceContentRight;
4613 df.bottom = of.bottom = cf.bottom = mVoiceContentBottom;
4614 } else if (adjust != SOFT_INPUT_ADJUST_RESIZE) {
Dianne Hackbornc4aad012013-02-22 15:05:25 -08004615 df.left = of.left = cf.left = mDockLeft;
4616 df.top = of.top = cf.top = mDockTop;
4617 df.right = of.right = cf.right = mDockRight;
4618 df.bottom = of.bottom = cf.bottom = mDockBottom;
Dianne Hackborna239c842011-06-01 12:28:20 -07004619 } else {
Dianne Hackbornc4aad012013-02-22 15:05:25 -08004620 df.left = of.left = cf.left = mContentLeft;
4621 df.top = of.top = cf.top = mContentTop;
4622 df.right = of.right = cf.right = mContentRight;
4623 df.bottom = of.bottom = cf.bottom = mContentBottom;
Dianne Hackborna239c842011-06-01 12:28:20 -07004624 }
4625 if (adjust != SOFT_INPUT_ADJUST_NOTHING) {
4626 vf.left = mCurLeft;
4627 vf.top = mCurTop;
4628 vf.right = mCurRight;
4629 vf.bottom = mCurBottom;
4630 } else {
4631 vf.set(cf);
4632 }
Dianne Hackborndea3ef72010-10-28 14:24:22 -07004633 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004634 }
4635 }
Craig Mautner69b08182012-09-05 13:07:13 -07004636
Craig Mautnerb816bed2013-07-23 10:26:17 -07004637 // TYPE_SYSTEM_ERROR is above the NavigationBar so it can't be allowed to extend over it.
Wale Ogunwale9185fb02016-03-11 18:06:14 -08004638 // Also, we don't allow windows in multi-window mode to extend out of the screen.
4639 if ((fl & FLAG_LAYOUT_NO_LIMITS) != 0 && attrs.type != TYPE_SYSTEM_ERROR
4640 && !win.inMultiWindowMode()) {
Dianne Hackborn067e5f62014-09-07 23:14:30 -07004641 df.left = df.top = -10000;
4642 df.right = df.bottom = 10000;
4643 if (attrs.type != TYPE_WALLPAPER) {
4644 of.left = of.top = cf.left = cf.top = vf.left = vf.top = -10000;
4645 of.right = of.bottom = cf.right = cf.bottom = vf.right = vf.bottom = 10000;
4646 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004647 }
4648
Filip Gruszczynski2217f612015-05-26 11:32:08 -07004649 // If the device has a chin (e.g. some watches), a dead area at the bottom of the screen we
4650 // need to provide information to the clients that want to pretend that you can draw there.
Filip Gruszczynskib0c673b2015-06-05 09:43:06 -07004651 // We only want to apply outsets to certain types of windows. For example, we never want to
4652 // apply the outsets to floating dialogs, because they wouldn't make sense there.
Filip Gruszczynski2987f612015-06-30 15:03:30 -07004653 final boolean useOutsets = shouldUseOutsets(attrs, fl);
Filip Gruszczynskib0c673b2015-06-05 09:43:06 -07004654 if (isDefaultDisplay && useOutsets) {
Filip Gruszczynski2217f612015-05-26 11:32:08 -07004655 osf = mTmpOutsetFrame;
4656 osf.set(cf.left, cf.top, cf.right, cf.bottom);
4657 int outset = ScreenShapeHelper.getWindowOutsetBottomPx(mContext.getResources());
4658 if (outset > 0) {
Filip Gruszczynski2987f612015-06-30 15:03:30 -07004659 int rotation = mDisplayRotation;
Filip Gruszczynski2217f612015-05-26 11:32:08 -07004660 if (rotation == Surface.ROTATION_0) {
4661 osf.bottom += outset;
4662 } else if (rotation == Surface.ROTATION_90) {
4663 osf.right += outset;
4664 } else if (rotation == Surface.ROTATION_180) {
4665 osf.top -= outset;
4666 } else if (rotation == Surface.ROTATION_270) {
4667 osf.left -= outset;
4668 }
4669 if (DEBUG_LAYOUT) Slog.v(TAG, "applying bottom outset of " + outset
4670 + " with rotation " + rotation + ", result: " + osf);
4671 }
4672 }
4673
Craig Mautnereda67292013-04-28 13:50:14 -07004674 if (DEBUG_LAYOUT) Slog.v(TAG, "Compute frame " + attrs.getTitle()
The Android Open Source Project11267662009-03-18 17:39:47 -07004675 + ": sim=#" + Integer.toHexString(sim)
RoboErik8a2cfc32014-05-16 11:19:38 -07004676 + " attach=" + attached + " type=" + attrs.type
Daniel Sandler8956dbb2011-04-22 07:55:02 -04004677 + String.format(" flags=0x%08x", fl)
The Android Open Source Project11267662009-03-18 17:39:47 -07004678 + " pf=" + pf.toShortString() + " df=" + df.toShortString()
Dianne Hackbornc4aad012013-02-22 15:05:25 -08004679 + " of=" + of.toShortString()
John Spurlock46646232013-09-30 22:32:42 -04004680 + " cf=" + cf.toShortString() + " vf=" + vf.toShortString()
Adrian Roosfa104232014-06-20 16:10:14 -07004681 + " dcf=" + dcf.toShortString()
Filip Gruszczynski2217f612015-05-26 11:32:08 -07004682 + " sf=" + sf.toShortString()
4683 + " osf=" + (osf == null ? "null" : osf.toShortString()));
Craig Mautner69b08182012-09-05 13:07:13 -07004684
Filip Gruszczynski2217f612015-05-26 11:32:08 -07004685 win.computeFrameLw(pf, df, of, cf, vf, dcf, sf, osf);
Craig Mautner69b08182012-09-05 13:07:13 -07004686
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004687 // Dock windows carve out the bottom of the screen, so normal windows
4688 // can't appear underneath them.
Craig Mautner8bd206b2012-10-03 10:32:02 -07004689 if (attrs.type == TYPE_INPUT_METHOD && win.isVisibleOrBehindKeyguardLw()
4690 && !win.getGivenInsetsPendingLw()) {
satok1bc0a492012-04-25 22:47:12 +09004691 setLastInputMethodWindowLw(null, null);
4692 offsetInputMethodWindowLw(win);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004693 }
Dianne Hackborne30e02f2014-05-27 18:24:45 -07004694 if (attrs.type == TYPE_VOICE_INTERACTION && win.isVisibleOrBehindKeyguardLw()
4695 && !win.getGivenInsetsPendingLw()) {
4696 offsetVoiceInputWindowLw(win);
4697 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004698 }
4699
satok1bc0a492012-04-25 22:47:12 +09004700 private void offsetInputMethodWindowLw(WindowState win) {
Craig Mautner4774f6a2015-03-23 11:42:55 -07004701 int top = Math.max(win.getDisplayFrameLw().top, win.getContentFrameLw().top);
satok1bc0a492012-04-25 22:47:12 +09004702 top += win.getGivenContentInsetsLw().top;
4703 if (mContentBottom > top) {
4704 mContentBottom = top;
4705 }
Dianne Hackborne30e02f2014-05-27 18:24:45 -07004706 if (mVoiceContentBottom > top) {
4707 mVoiceContentBottom = top;
4708 }
satok1bc0a492012-04-25 22:47:12 +09004709 top = win.getVisibleFrameLw().top;
4710 top += win.getGivenVisibleInsetsLw().top;
4711 if (mCurBottom > top) {
4712 mCurBottom = top;
4713 }
Craig Mautnereda67292013-04-28 13:50:14 -07004714 if (DEBUG_LAYOUT) Slog.v(TAG, "Input method: mDockBottom="
satok1bc0a492012-04-25 22:47:12 +09004715 + mDockBottom + " mContentBottom="
4716 + mContentBottom + " mCurBottom=" + mCurBottom);
4717 }
4718
Dianne Hackborne30e02f2014-05-27 18:24:45 -07004719 private void offsetVoiceInputWindowLw(WindowState win) {
Craig Mautner4774f6a2015-03-23 11:42:55 -07004720 int top = Math.max(win.getDisplayFrameLw().top, win.getContentFrameLw().top);
Dianne Hackbornae6688b2015-02-11 17:02:41 -08004721 top += win.getGivenContentInsetsLw().top;
4722 if (mVoiceContentBottom > top) {
4723 mVoiceContentBottom = top;
Dianne Hackborne30e02f2014-05-27 18:24:45 -07004724 }
4725 }
4726
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004727 /** {@inheritDoc} */
Craig Mautner61ac6bb2012-02-02 17:29:33 -08004728 @Override
4729 public void finishLayoutLw() {
4730 return;
Dianne Hackborn5f3063e2010-03-10 16:01:58 -08004731 }
4732
4733 /** {@inheritDoc} */
Craig Mautnerad09bcc2012-10-08 13:33:11 -07004734 @Override
Craig Mautner39834192012-09-02 07:47:24 -07004735 public void beginPostLayoutPolicyLw(int displayWidth, int displayHeight) {
Dianne Hackborn5f3063e2010-03-10 16:01:58 -08004736 mTopFullscreenOpaqueWindowState = null;
Adrian Rooscd3884d2015-02-18 17:25:23 +01004737 mTopFullscreenOpaqueOrDimmingWindowState = null;
Jorim Jaggi86905582016-02-09 21:36:09 -08004738 mTopDockedOpaqueWindowState = null;
4739 mTopDockedOpaqueOrDimmingWindowState = null;
Craig Mautner2bc789b2014-03-19 19:48:38 -07004740 mAppsToBeHidden.clear();
Jorim Jaggic13fcac2014-09-11 17:36:57 +02004741 mAppsThatDismissKeyguard.clear();
Dianne Hackborn5f3063e2010-03-10 16:01:58 -08004742 mForceStatusBar = false;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07004743 mForceStatusBarFromKeyguard = false;
Selim Cinek4a4a2bddc2015-05-07 12:50:19 -07004744 mForceStatusBarTransparent = false;
Dianne Hackborn891d3fb2013-01-09 18:31:37 -08004745 mForcingShowNavBar = false;
4746 mForcingShowNavBarLayer = -1;
RoboErik8a2cfc32014-05-16 11:19:38 -07004747
Dianne Hackborn5f3063e2010-03-10 16:01:58 -08004748 mHideLockScreen = false;
4749 mAllowLockscreenWhenOn = false;
Craig Mautnerad09bcc2012-10-08 13:33:11 -07004750 mDismissKeyguard = DISMISS_KEYGUARD_NONE;
Dianne Hackborn7ad44382012-10-18 17:46:00 -07004751 mShowingLockscreen = false;
4752 mShowingDream = false;
Craig Mautnerc9457fa2014-06-06 14:27:48 -07004753 mWinShowWhenLocked = null;
Jim Millerab954542014-10-10 18:21:49 -07004754 mKeyguardSecure = isKeyguardSecure();
4755 mKeyguardSecureIncludingHidden = mKeyguardSecure
4756 && (mKeyguardDelegate != null && mKeyguardDelegate.isShowing());
Dianne Hackborn5f3063e2010-03-10 16:01:58 -08004757 }
4758
4759 /** {@inheritDoc} */
Craig Mautnerad09bcc2012-10-08 13:33:11 -07004760 @Override
Yohei Yukawad1a09222015-06-30 16:22:05 -07004761 public void applyPostLayoutPolicyLw(WindowState win, WindowManager.LayoutParams attrs,
4762 WindowState attached) {
Dianne Hackbornbc1aa7b2011-09-20 11:20:31 -07004763 if (DEBUG_LAYOUT) Slog.i(TAG, "Win " + win + ": isVisibleOrBehindKeyguardLw="
4764 + win.isVisibleOrBehindKeyguardLw());
John Spurlockc6d1c602014-01-17 15:22:06 -05004765 final int fl = PolicyControl.getWindowFlags(win, attrs);
John Spurlock414c1f02013-12-04 13:47:36 -05004766 if (mTopFullscreenOpaqueWindowState == null
4767 && win.isVisibleLw() && attrs.type == TYPE_INPUT_METHOD) {
4768 mForcingShowNavBar = true;
4769 mForcingShowNavBarLayer = win.getSurfaceLayer();
Dianne Hackborn891d3fb2013-01-09 18:31:37 -08004770 }
Selim Cinek4a4a2bddc2015-05-07 12:50:19 -07004771 if (attrs.type == TYPE_STATUS_BAR) {
4772 if ((attrs.privateFlags & PRIVATE_FLAG_KEYGUARD) != 0) {
4773 mForceStatusBarFromKeyguard = true;
Jorim Jaggie1de9f62015-09-23 14:59:50 -07004774 mShowingLockscreen = true;
Selim Cinek4a4a2bddc2015-05-07 12:50:19 -07004775 }
4776 if ((attrs.privateFlags & PRIVATE_FLAG_FORCE_STATUS_BAR_VISIBLE_TRANSPARENT) != 0) {
4777 mForceStatusBarTransparent = true;
4778 }
Jorim Jaggiafd4a552014-04-08 15:13:05 +02004779 }
Adrian Roos602c68e2015-04-24 16:03:47 -07004780
4781 boolean appWindow = attrs.type >= FIRST_APPLICATION_WINDOW
4782 && attrs.type < FIRST_SYSTEM_WINDOW;
4783 final boolean showWhenLocked = (fl & FLAG_SHOW_WHEN_LOCKED) != 0;
4784 final boolean dismissKeyguard = (fl & FLAG_DISMISS_KEYGUARD) != 0;
Jorim Jaggi86905582016-02-09 21:36:09 -08004785 final int stackId = win.getStackId();
Dianne Hackborn5f3063e2010-03-10 16:01:58 -08004786 if (mTopFullscreenOpaqueWindowState == null &&
Dianne Hackborn01b02a72012-01-12 14:05:03 -08004787 win.isVisibleOrBehindKeyguardLw() && !win.isGoneForLayoutLw()) {
John Spurlockc6d1c602014-01-17 15:22:06 -05004788 if ((fl & FLAG_FORCE_NOT_FULLSCREEN) != 0) {
Jorim Jaggi380ecb82014-03-14 17:25:20 +01004789 if ((attrs.privateFlags & PRIVATE_FLAG_KEYGUARD) != 0) {
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07004790 mForceStatusBarFromKeyguard = true;
4791 } else {
4792 mForceStatusBar = true;
4793 }
4794 }
Dianne Hackborn7ad44382012-10-18 17:46:00 -07004795 if (attrs.type == TYPE_DREAM) {
Jeff Brownc8018eb2012-10-29 21:33:27 -07004796 // If the lockscreen was showing when the dream started then wait
4797 // for the dream to draw before hiding the lockscreen.
4798 if (!mDreamingLockscreen
4799 || (win.isVisibleLw() && win.hasDrawnLw())) {
4800 mShowingDream = true;
Craig Mautnerab55e522014-03-03 13:26:03 -08004801 appWindow = true;
Dianne Hackborn7ad44382012-10-18 17:46:00 -07004802 }
4803 }
Craig Mautnerab55e522014-03-03 13:26:03 -08004804
Yohei Yukawad1a09222015-06-30 16:22:05 -07004805 final IApplicationToken appToken = win.getAppToken();
4806
4807 // For app windows that are not attached, we decide if all windows in the app they
4808 // represent should be hidden or if we should hide the lockscreen. For attached app
4809 // windows we defer the decision to the window it is attached to.
4810 if (appWindow && attached == null) {
Jorim Jaggic13fcac2014-09-11 17:36:57 +02004811 if (showWhenLocked) {
Craig Mautnerc9457fa2014-06-06 14:27:48 -07004812 // Remove any previous windows with the same appToken.
Jorim Jaggic13fcac2014-09-11 17:36:57 +02004813 mAppsToBeHidden.remove(appToken);
4814 mAppsThatDismissKeyguard.remove(appToken);
Craig Mautnerca0a1242014-12-02 12:25:14 -08004815 if (mAppsToBeHidden.isEmpty()) {
Craig Mautner192d6042014-12-02 23:24:48 -08004816 if (dismissKeyguard && !mKeyguardSecure) {
4817 mAppsThatDismissKeyguard.add(appToken);
Selim Cinek90b5e072015-08-28 17:05:56 -07004818 } else if (win.isDrawnLw() || win.hasAppShownWindows()) {
Craig Mautnerca0a1242014-12-02 12:25:14 -08004819 mWinShowWhenLocked = win;
4820 mHideLockScreen = true;
4821 mForceStatusBarFromKeyguard = false;
Craig Mautnerca0a1242014-12-02 12:25:14 -08004822 }
Craig Mautnerc9457fa2014-06-06 14:27:48 -07004823 }
Jorim Jaggic13fcac2014-09-11 17:36:57 +02004824 } else if (dismissKeyguard) {
Jim Millerab954542014-10-10 18:21:49 -07004825 if (mKeyguardSecure) {
Jorim Jaggic13fcac2014-09-11 17:36:57 +02004826 mAppsToBeHidden.add(appToken);
4827 } else {
4828 mAppsToBeHidden.remove(appToken);
4829 }
4830 mAppsThatDismissKeyguard.add(appToken);
Craig Mautner2bc789b2014-03-19 19:48:38 -07004831 } else {
Jorim Jaggic13fcac2014-09-11 17:36:57 +02004832 mAppsToBeHidden.add(appToken);
Craig Mautner2bc789b2014-03-19 19:48:38 -07004833 }
Jorim Jaggi86905582016-02-09 21:36:09 -08004834 if (isFullscreen(attrs) && StackId.normallyFullscreenWindows(stackId)) {
Craig Mautnerab55e522014-03-03 13:26:03 -08004835 if (DEBUG_LAYOUT) Slog.v(TAG, "Fullscreen window: " + win);
4836 mTopFullscreenOpaqueWindowState = win;
Adrian Rooscd3884d2015-02-18 17:25:23 +01004837 if (mTopFullscreenOpaqueOrDimmingWindowState == null) {
4838 mTopFullscreenOpaqueOrDimmingWindowState = win;
4839 }
Jorim Jaggic13fcac2014-09-11 17:36:57 +02004840 if (!mAppsThatDismissKeyguard.isEmpty() &&
4841 mDismissKeyguard == DISMISS_KEYGUARD_NONE) {
4842 if (DEBUG_LAYOUT) Slog.v(TAG,
4843 "Setting mDismissKeyguard true by win " + win);
tingna_sunge785ffa2015-05-12 13:23:15 +08004844 mDismissKeyguard = (mWinDismissingKeyguard == win
4845 && mSecureDismissingKeyguard == mKeyguardSecure)
4846 ? DISMISS_KEYGUARD_CONTINUE : DISMISS_KEYGUARD_START;
Jorim Jaggic13fcac2014-09-11 17:36:57 +02004847 mWinDismissingKeyguard = win;
tingna_sunge785ffa2015-05-12 13:23:15 +08004848 mSecureDismissingKeyguard = mKeyguardSecure;
Jim Millerab954542014-10-10 18:21:49 -07004849 mForceStatusBarFromKeyguard = mShowingLockscreen && mKeyguardSecure;
Selim Cinek90b5e072015-08-28 17:05:56 -07004850 } else if (mAppsToBeHidden.isEmpty() && showWhenLocked
4851 && (win.isDrawnLw() || win.hasAppShownWindows())) {
Jorim Jaggic13fcac2014-09-11 17:36:57 +02004852 if (DEBUG_LAYOUT) Slog.v(TAG,
4853 "Setting mHideLockScreen to true by win " + win);
4854 mHideLockScreen = true;
4855 mForceStatusBarFromKeyguard = false;
Craig Mautnerab55e522014-03-03 13:26:03 -08004856 }
Craig Mautner00156ec2014-03-06 22:29:02 -08004857 if ((fl & FLAG_ALLOW_LOCK_WHILE_SCREEN_ON) != 0) {
Craig Mautnerab55e522014-03-03 13:26:03 -08004858 mAllowLockscreenWhenOn = true;
4859 }
Dianne Hackborn5f3063e2010-03-10 16:01:58 -08004860 }
Craig Mautnerc9457fa2014-06-06 14:27:48 -07004861
4862 if (mWinShowWhenLocked != null &&
Adrian Roos602c68e2015-04-24 16:03:47 -07004863 mWinShowWhenLocked.getAppToken() != win.getAppToken() &&
4864 (attrs.flags & FLAG_SHOW_WHEN_LOCKED) == 0) {
Craig Mautnerc9457fa2014-06-06 14:27:48 -07004865 win.hideLw(false);
4866 }
Dianne Hackborn5f3063e2010-03-10 16:01:58 -08004867 }
Adrian Roos602c68e2015-04-24 16:03:47 -07004868 } else if (mTopFullscreenOpaqueWindowState == null && mWinShowWhenLocked == null) {
4869 // No TopFullscreenOpaqueWindow is showing, but we found a SHOW_WHEN_LOCKED window
4870 // that is being hidden in an animation - keep the
4871 // keyguard hidden until the new window shows up and
4872 // we know whether to show the keyguard or not.
Adrian Roosb85e1ec2015-05-29 15:23:18 -07004873 if (win.isAnimatingLw() && appWindow && showWhenLocked && mKeyguardHidden) {
Adrian Roos602c68e2015-04-24 16:03:47 -07004874 mHideLockScreen = true;
4875 mWinShowWhenLocked = win;
4876 }
Dianne Hackborn5f3063e2010-03-10 16:01:58 -08004877 }
Jorim Jaggi86905582016-02-09 21:36:09 -08004878
4879 // Keep track of the window if it's dimming but not necessarily fullscreen.
4880 final boolean reallyVisible = win.isVisibleOrBehindKeyguardLw() && !win.isGoneForLayoutLw();
4881 if (mTopFullscreenOpaqueOrDimmingWindowState == null && reallyVisible
4882 && win.isDimming() && StackId.normallyFullscreenWindows(stackId)) {
Adrian Rooscd3884d2015-02-18 17:25:23 +01004883 mTopFullscreenOpaqueOrDimmingWindowState = win;
4884 }
Jorim Jaggi86905582016-02-09 21:36:09 -08004885
4886 // We need to keep track of the top "fullscreen" opaque window for the docked stack
4887 // separately, because both the "real fullscreen" opaque window and the one for the docked
4888 // stack can control View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR.
4889 if (mTopDockedOpaqueWindowState == null && reallyVisible && appWindow && attached == null
4890 && isFullscreen(attrs) && stackId == DOCKED_STACK_ID) {
4891 mTopDockedOpaqueWindowState = win;
4892 if (mTopDockedOpaqueOrDimmingWindowState == null) {
4893 mTopDockedOpaqueOrDimmingWindowState = win;
4894 }
4895 }
4896
4897 // Also keep track of any windows that are dimming but not necessarily fullscreen in the
4898 // docked stack.
4899 if (mTopDockedOpaqueOrDimmingWindowState == null && reallyVisible && win.isDimming()
4900 && stackId == DOCKED_STACK_ID) {
4901 mTopDockedOpaqueOrDimmingWindowState = win;
4902 }
4903 }
4904
4905 private boolean isFullscreen(WindowManager.LayoutParams attrs) {
4906 return attrs.x == 0 && attrs.y == 0
4907 && attrs.width == WindowManager.LayoutParams.MATCH_PARENT
4908 && attrs.height == WindowManager.LayoutParams.MATCH_PARENT;
Dianne Hackborn5f3063e2010-03-10 16:01:58 -08004909 }
4910
4911 /** {@inheritDoc} */
Craig Mautnerad09bcc2012-10-08 13:33:11 -07004912 @Override
Craig Mautner39834192012-09-02 07:47:24 -07004913 public int finishPostLayoutPolicyLw() {
Craig Mautnerc5e73bf2015-04-21 15:41:26 +00004914 if (mWinShowWhenLocked != null && mTopFullscreenOpaqueWindowState != null &&
4915 mWinShowWhenLocked.getAppToken() != mTopFullscreenOpaqueWindowState.getAppToken()
4916 && isKeyguardLocked()) {
Craig Mautnerc9457fa2014-06-06 14:27:48 -07004917 // A dialog is dismissing the keyguard. Put the wallpaper behind it and hide the
4918 // fullscreen window.
4919 // TODO: Make sure FLAG_SHOW_WALLPAPER is restored when dialog is dismissed. Or not.
4920 mWinShowWhenLocked.getAttrs().flags |= FLAG_SHOW_WALLPAPER;
4921 mTopFullscreenOpaqueWindowState.hideLw(false);
4922 mTopFullscreenOpaqueWindowState = mWinShowWhenLocked;
4923 }
4924
Dianne Hackborn39c2d712009-09-22 11:41:31 -07004925 int changes = 0;
Joe Onorato93056472010-09-10 10:30:46 -04004926 boolean topIsFullscreen = false;
Daniel Sandlere02d8082010-10-08 15:13:22 -04004927
4928 final WindowManager.LayoutParams lp = (mTopFullscreenOpaqueWindowState != null)
4929 ? mTopFullscreenOpaqueWindowState.getAttrs()
4930 : null;
4931
Jeff Brownc8018eb2012-10-29 21:33:27 -07004932 // If we are not currently showing a dream then remember the current
4933 // lockscreen state. We will use this to determine whether the dream
4934 // started while the lockscreen was showing and remember this state
4935 // while the dream is showing.
Dianne Hackborn7ad44382012-10-18 17:46:00 -07004936 if (!mShowingDream) {
4937 mDreamingLockscreen = mShowingLockscreen;
Jeff Brown061ea992015-04-17 19:55:47 -07004938 if (mDreamingSleepTokenNeeded) {
4939 mDreamingSleepTokenNeeded = false;
4940 mHandler.obtainMessage(MSG_UPDATE_DREAMING_SLEEP_TOKEN, 0, 1).sendToTarget();
4941 }
4942 } else {
4943 if (!mDreamingSleepTokenNeeded) {
4944 mDreamingSleepTokenNeeded = true;
4945 mHandler.obtainMessage(MSG_UPDATE_DREAMING_SLEEP_TOKEN, 1, 1).sendToTarget();
4946 }
Dianne Hackborn7ad44382012-10-18 17:46:00 -07004947 }
4948
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004949 if (mStatusBar != null) {
Craig Mautnereda67292013-04-28 13:50:14 -07004950 if (DEBUG_LAYOUT) Slog.i(TAG, "force=" + mForceStatusBar
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07004951 + " forcefkg=" + mForceStatusBarFromKeyguard
Dianne Hackbornd70bc2f2009-10-06 23:25:51 -07004952 + " top=" + mTopFullscreenOpaqueWindowState);
Selim Cinek4a4a2bddc2015-05-07 12:50:19 -07004953 boolean shouldBeTransparent = mForceStatusBarTransparent
4954 && !mForceStatusBar
4955 && !mForceStatusBarFromKeyguard;
4956 if (!shouldBeTransparent) {
4957 mStatusBarController.setShowTransparent(false /* transparent */);
4958 } else if (!mStatusBar.isVisibleLw()) {
4959 mStatusBarController.setShowTransparent(true /* transparent */);
4960 }
4961 if (mForceStatusBar || mForceStatusBarFromKeyguard || mForceStatusBarTransparent) {
Craig Mautnereda67292013-04-28 13:50:14 -07004962 if (DEBUG_LAYOUT) Slog.v(TAG, "Showing status bar: forced");
John Spurlock27735a42013-08-14 17:57:38 -04004963 if (mStatusBarController.setBarShowingLw(true)) {
4964 changes |= FINISH_LAYOUT_REDO_LAYOUT;
4965 }
Craig Mautner81defc72013-10-29 11:10:42 -07004966 // Maintain fullscreen layout until incoming animation is complete.
4967 topIsFullscreen = mTopIsFullscreen && mStatusBar.isAnimatingLw();
John Spurlockf92b6162013-11-11 15:01:16 -05004968 // Transient status bar on the lockscreen is not allowed
4969 if (mForceStatusBarFromKeyguard && mStatusBarController.isTransientShowing()) {
4970 mStatusBarController.updateVisibilityLw(false /*transientAllowed*/,
4971 mLastSystemUiFlags, mLastSystemUiFlags);
4972 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004973 } else if (mTopFullscreenOpaqueWindowState != null) {
John Spurlockc6d1c602014-01-17 15:22:06 -05004974 final int fl = PolicyControl.getWindowFlags(null, lp);
Joe Onorato93056472010-09-10 10:30:46 -04004975 if (localLOGV) {
Craig Mautnereda67292013-04-28 13:50:14 -07004976 Slog.d(TAG, "frame: " + mTopFullscreenOpaqueWindowState.getFrameLw()
Filip Gruszczynski2a6a2c22015-10-14 12:00:53 -07004977 + " shown position: "
4978 + mTopFullscreenOpaqueWindowState.getShownPositionLw());
Craig Mautnereda67292013-04-28 13:50:14 -07004979 Slog.d(TAG, "attr: " + mTopFullscreenOpaqueWindowState.getAttrs()
John Spurlockc6d1c602014-01-17 15:22:06 -05004980 + " lp.flags=0x" + Integer.toHexString(fl));
Joe Onorato93056472010-09-10 10:30:46 -04004981 }
John Spurlockc6d1c602014-01-17 15:22:06 -05004982 topIsFullscreen = (fl & WindowManager.LayoutParams.FLAG_FULLSCREEN) != 0
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07004983 || (mLastSystemUiFlags & View.SYSTEM_UI_FLAG_FULLSCREEN) != 0;
Joe Onorato93056472010-09-10 10:30:46 -04004984 // The subtle difference between the window for mTopFullscreenOpaqueWindowState
Mark Dolinerd0646dc2014-08-27 16:04:02 -07004985 // and mTopIsFullscreen is that mTopIsFullscreen is set only if the window
Joe Onorato93056472010-09-10 10:30:46 -04004986 // has the FLAG_FULLSCREEN set. Not sure if there is another way that to be the
4987 // case though.
John Spurlock27735a42013-08-14 17:57:38 -04004988 if (mStatusBarController.isTransientShowing()) {
4989 if (mStatusBarController.setBarShowingLw(true)) {
John Spurlock32beb2c2013-03-11 10:16:47 -04004990 changes |= FINISH_LAYOUT_REDO_LAYOUT;
4991 }
Wale Ogunwale6e94a9e2015-10-07 15:35:49 -07004992 } else if (topIsFullscreen
4993 && !mWindowManagerInternal.isStackVisible(FREEFORM_WORKSPACE_STACK_ID)
4994 && !mWindowManagerInternal.isStackVisible(DOCKED_STACK_ID)) {
Craig Mautnereda67292013-04-28 13:50:14 -07004995 if (DEBUG_LAYOUT) Slog.v(TAG, "** HIDING status bar");
John Spurlock27735a42013-08-14 17:57:38 -04004996 if (mStatusBarController.setBarShowingLw(false)) {
Dianne Hackbornf87d1962012-04-04 12:48:24 -07004997 changes |= FINISH_LAYOUT_REDO_LAYOUT;
Craig Mautnereda67292013-04-28 13:50:14 -07004998 } else {
Craig Mautnerc5a6e442013-06-05 17:22:35 -07004999 if (DEBUG_LAYOUT) Slog.v(TAG, "Status bar already hiding");
Daniel Sandler40427442010-07-16 11:44:52 -04005000 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005001 } else {
Craig Mautnereda67292013-04-28 13:50:14 -07005002 if (DEBUG_LAYOUT) Slog.v(TAG, "** SHOWING status bar: top is not fullscreen");
John Spurlock27735a42013-08-14 17:57:38 -04005003 if (mStatusBarController.setBarShowingLw(true)) {
5004 changes |= FINISH_LAYOUT_REDO_LAYOUT;
5005 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005006 }
5007 }
5008 }
Daniel Sandlere02d8082010-10-08 15:13:22 -04005009
Craig Mautner81defc72013-10-29 11:10:42 -07005010 if (mTopIsFullscreen != topIsFullscreen) {
5011 if (!topIsFullscreen) {
5012 // Force another layout when status bar becomes fully shown.
5013 changes |= FINISH_LAYOUT_REDO_LAYOUT;
5014 }
5015 mTopIsFullscreen = topIsFullscreen;
5016 }
Daniel Sandlere02d8082010-10-08 15:13:22 -04005017
Craig Mautner39834192012-09-02 07:47:24 -07005018 // Hide the key guard if a visible window explicitly specifies that it wants to be
5019 // displayed when the screen is locked.
Jorim Jaggi5cf17872014-03-26 18:31:48 +01005020 if (mKeyguardDelegate != null && mStatusBar != null) {
5021 if (localLOGV) Slog.v(TAG, "finishPostLayoutPolicyLw: mHideKeyguard="
5022 + mHideLockScreen);
Jim Millerab954542014-10-10 18:21:49 -07005023 if (mDismissKeyguard != DISMISS_KEYGUARD_NONE && !mKeyguardSecure) {
Jorim Jaggi5cf17872014-03-26 18:31:48 +01005024 mKeyguardHidden = true;
Jim Millerab954542014-10-10 18:21:49 -07005025 if (setKeyguardOccludedLw(true)) {
Dianne Hackborn39c2d712009-09-22 11:41:31 -07005026 changes |= FINISH_LAYOUT_REDO_LAYOUT
5027 | FINISH_LAYOUT_REDO_CONFIG
5028 | FINISH_LAYOUT_REDO_WALLPAPER;
5029 }
Jorim Jaggi5cf17872014-03-26 18:31:48 +01005030 if (mKeyguardDelegate.isShowing()) {
5031 mHandler.post(new Runnable() {
5032 @Override
5033 public void run() {
5034 mKeyguardDelegate.keyguardDone(false, false);
5035 }
5036 });
5037 }
5038 } else if (mHideLockScreen) {
5039 mKeyguardHidden = true;
Jorim Jaggi7d85ea92015-05-20 17:20:40 -07005040 mWinDismissingKeyguard = null;
Jim Millerab954542014-10-10 18:21:49 -07005041 if (setKeyguardOccludedLw(true)) {
Jorim Jaggi5cf17872014-03-26 18:31:48 +01005042 changes |= FINISH_LAYOUT_REDO_LAYOUT
5043 | FINISH_LAYOUT_REDO_CONFIG
5044 | FINISH_LAYOUT_REDO_WALLPAPER;
5045 }
5046 } else if (mDismissKeyguard != DISMISS_KEYGUARD_NONE) {
Jorim Jaggi7d85ea92015-05-20 17:20:40 -07005047 mKeyguardHidden = false;
5048 if (setKeyguardOccludedLw(false)) {
5049 changes |= FINISH_LAYOUT_REDO_LAYOUT
5050 | FINISH_LAYOUT_REDO_CONFIG
5051 | FINISH_LAYOUT_REDO_WALLPAPER;
5052 }
Jorim Jaggi5cf17872014-03-26 18:31:48 +01005053 if (mDismissKeyguard == DISMISS_KEYGUARD_START) {
5054 // Only launch the next keyguard unlock window once per window.
Jorim Jaggi5cf17872014-03-26 18:31:48 +01005055 mHandler.post(new Runnable() {
5056 @Override
5057 public void run() {
5058 mKeyguardDelegate.dismiss();
5059 }
5060 });
5061 }
5062 } else {
5063 mWinDismissingKeyguard = null;
tingna_sunge785ffa2015-05-12 13:23:15 +08005064 mSecureDismissingKeyguard = false;
Jorim Jaggi5cf17872014-03-26 18:31:48 +01005065 mKeyguardHidden = false;
Jim Millerab954542014-10-10 18:21:49 -07005066 if (setKeyguardOccludedLw(false)) {
Jorim Jaggi5cf17872014-03-26 18:31:48 +01005067 changes |= FINISH_LAYOUT_REDO_LAYOUT
5068 | FINISH_LAYOUT_REDO_CONFIG
5069 | FINISH_LAYOUT_REDO_WALLPAPER;
5070 }
Suchi Amalapurapu9cdc9032009-05-14 18:01:07 -07005071 }
5072 }
Joe Onorato664644d2011-01-23 17:53:23 -08005073
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07005074 if ((updateSystemUiVisibilityLw()&SYSTEM_UI_CHANGING_LAYOUT) != 0) {
Dianne Hackborndf89e652011-10-06 22:35:11 -07005075 // If the navigation bar has been hidden or shown, we need to do another
5076 // layout pass to update that window.
5077 changes |= FINISH_LAYOUT_REDO_LAYOUT;
5078 }
Joe Onorato664644d2011-01-23 17:53:23 -08005079
Mike Lockwood28569302010-01-28 11:54:40 -05005080 // update since mAllowLockscreenWhenOn might have changed
5081 updateLockScreenTimeout();
Dianne Hackborn39c2d712009-09-22 11:41:31 -07005082 return changes;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005083 }
5084
Jorim Jaggi380ecb82014-03-14 17:25:20 +01005085 /**
Jim Millerab954542014-10-10 18:21:49 -07005086 * Updates the occluded state of the Keyguard.
Jorim Jaggi380ecb82014-03-14 17:25:20 +01005087 *
Jorim Jaggi380ecb82014-03-14 17:25:20 +01005088 * @return Whether the flags have changed and we have to redo the layout.
5089 */
Jim Millerab954542014-10-10 18:21:49 -07005090 private boolean setKeyguardOccludedLw(boolean isOccluded) {
5091 boolean wasOccluded = mKeyguardOccluded;
5092 boolean showing = mKeyguardDelegate.isShowing();
5093 if (wasOccluded && !isOccluded && showing) {
5094 mKeyguardOccluded = false;
5095 mKeyguardDelegate.setOccluded(false);
Jorim Jaggi380ecb82014-03-14 17:25:20 +01005096 mStatusBar.getAttrs().privateFlags |= PRIVATE_FLAG_KEYGUARD;
5097 mStatusBar.getAttrs().flags |= FLAG_SHOW_WALLPAPER;
5098 return true;
Jim Millerab954542014-10-10 18:21:49 -07005099 } else if (!wasOccluded && isOccluded && showing) {
5100 mKeyguardOccluded = true;
5101 mKeyguardDelegate.setOccluded(true);
Jorim Jaggi380ecb82014-03-14 17:25:20 +01005102 mStatusBar.getAttrs().privateFlags &= ~PRIVATE_FLAG_KEYGUARD;
5103 mStatusBar.getAttrs().flags &= ~FLAG_SHOW_WALLPAPER;
5104 return true;
5105 } else {
5106 return false;
5107 }
5108 }
5109
5110 private boolean isStatusBarKeyguard() {
5111 return mStatusBar != null
5112 && (mStatusBar.getAttrs().privateFlags & PRIVATE_FLAG_KEYGUARD) != 0;
5113 }
5114
Jose Lima9546b202014-07-02 17:21:51 -07005115 @Override
Dianne Hackborn08743722009-12-21 12:16:51 -08005116 public boolean allowAppAnimationsLw() {
Jorim Jaggi380ecb82014-03-14 17:25:20 +01005117 if (isStatusBarKeyguard() || mShowingDream) {
Craig Mautner28816302013-10-10 20:31:00 -07005118 // If keyguard or dreams is currently visible, no reason to animate behind it.
Dianne Hackborn08743722009-12-21 12:16:51 -08005119 return false;
5120 }
Dianne Hackborn08743722009-12-21 12:16:51 -08005121 return true;
5122 }
5123
Jose Lima9546b202014-07-02 17:21:51 -07005124 @Override
Dianne Hackborndf89e652011-10-06 22:35:11 -07005125 public int focusChangedLw(WindowState lastFocus, WindowState newFocus) {
Joe Onorato664644d2011-01-23 17:53:23 -08005126 mFocusedWindow = newFocus;
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07005127 if ((updateSystemUiVisibilityLw()&SYSTEM_UI_CHANGING_LAYOUT) != 0) {
Dianne Hackborndf89e652011-10-06 22:35:11 -07005128 // If the navigation bar has been hidden or shown, we need to do another
5129 // layout pass to update that window.
5130 return FINISH_LAYOUT_REDO_LAYOUT;
5131 }
5132 return 0;
Joe Onorato664644d2011-01-23 17:53:23 -08005133 }
5134
Dianne Hackborn0ecadf72009-03-31 18:00:37 -07005135 /** {@inheritDoc} */
Jose Lima9546b202014-07-02 17:21:51 -07005136 @Override
Jeff Brown46b9ac02010-04-22 18:58:52 -07005137 public void notifyLidSwitchChanged(long whenNanos, boolean lidOpen) {
5138 // lid changed state
Jeff Brownc458ce92012-04-30 14:58:40 -07005139 final int newLidState = lidOpen ? LID_OPEN : LID_CLOSED;
5140 if (newLidState == mLidState) {
5141 return;
5142 }
Jeff Brown01a98dd2011-09-20 15:08:29 -07005143
Jeff Brownc458ce92012-04-30 14:58:40 -07005144 mLidState = newLidState;
5145 applyLidSwitchState();
Jeff Brown01a98dd2011-09-20 15:08:29 -07005146 updateRotation(true);
Jeff Brownc458ce92012-04-30 14:58:40 -07005147
5148 if (lidOpen) {
Dianne Hackborn280a64e2015-07-13 14:48:08 -07005149 wakeUp(SystemClock.uptimeMillis(), mAllowTheaterModeWakeFromLidSwitch,
5150 "android.policy:LID");
Jeff Brownc458ce92012-04-30 14:58:40 -07005151 } else if (!mLidControlsSleep) {
Jeff Brown96307042012-07-27 15:51:34 -07005152 mPowerManager.userActivity(SystemClock.uptimeMillis(), false);
Jeff Brown46b9ac02010-04-22 18:58:52 -07005153 }
5154 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005155
Michael Wright3818c922014-09-02 13:59:07 -07005156 @Override
5157 public void notifyCameraLensCoverSwitchChanged(long whenNanos, boolean lensCovered) {
5158 int lensCoverState = lensCovered ? CAMERA_LENS_COVERED : CAMERA_LENS_UNCOVERED;
5159 if (mCameraLensCoverState == lensCoverState) {
5160 return;
5161 }
5162 if (mCameraLensCoverState == CAMERA_LENS_COVERED &&
5163 lensCoverState == CAMERA_LENS_UNCOVERED) {
5164 Intent intent;
5165 final boolean keyguardActive = mKeyguardDelegate == null ? false :
5166 mKeyguardDelegate.isShowing();
5167 if (keyguardActive) {
5168 intent = new Intent(MediaStore.INTENT_ACTION_STILL_IMAGE_CAMERA_SECURE);
5169 } else {
5170 intent = new Intent(MediaStore.INTENT_ACTION_STILL_IMAGE_CAMERA);
5171 }
Dianne Hackborn280a64e2015-07-13 14:48:08 -07005172 wakeUp(whenNanos / 1000000, mAllowTheaterModeWakeFromCameraLens,
5173 "android.policy:CAMERA_COVER");
Bart Sears8b1c27c2015-03-18 23:51:02 +00005174 startActivityAsUser(intent, UserHandle.CURRENT_OR_SELF);
Michael Wright3818c922014-09-02 13:59:07 -07005175 }
5176 mCameraLensCoverState = lensCoverState;
5177 }
5178
Dianne Hackbornad7fa7f2011-01-07 14:06:50 -08005179 void setHdmiPlugged(boolean plugged) {
5180 if (mHdmiPlugged != plugged) {
5181 mHdmiPlugged = plugged;
Dianne Hackbornf87d1962012-04-04 12:48:24 -07005182 updateRotation(true, true);
Dianne Hackbornad7fa7f2011-01-07 14:06:50 -08005183 Intent intent = new Intent(ACTION_HDMI_PLUGGED);
Joe Onoratodc100302011-01-11 17:07:41 -08005184 intent.addFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY_BEFORE_BOOT);
Dianne Hackbornad7fa7f2011-01-07 14:06:50 -08005185 intent.putExtra(EXTRA_HDMI_PLUGGED_STATE, plugged);
Dianne Hackborn5ac72a22012-08-29 18:32:08 -07005186 mContext.sendStickyBroadcastAsUser(intent, UserHandle.ALL);
Dianne Hackbornad7fa7f2011-01-07 14:06:50 -08005187 }
5188 }
5189
Joe Onoratoea495d42011-04-06 11:41:11 -07005190 void initializeHdmiState() {
Joe Onorato7ba631f2011-05-04 15:28:00 -07005191 boolean plugged = false;
Joe Onoratoea495d42011-04-06 11:41:11 -07005192 // watch for HDMI plug messages if the hdmi switch exists
5193 if (new File("/sys/devices/virtual/switch/hdmi/state").exists()) {
5194 mHDMIObserver.startObserving("DEVPATH=/devices/virtual/switch/hdmi");
5195
Joe Onoratoea495d42011-04-06 11:41:11 -07005196 final String filename = "/sys/class/switch/hdmi/state";
5197 FileReader reader = null;
5198 try {
5199 reader = new FileReader(filename);
5200 char[] buf = new char[15];
5201 int n = reader.read(buf);
5202 if (n > 1) {
5203 plugged = 0 != Integer.parseInt(new String(buf, 0, n-1));
5204 }
5205 } catch (IOException ex) {
5206 Slog.w(TAG, "Couldn't read hdmi state from " + filename + ": " + ex);
5207 } catch (NumberFormatException ex) {
5208 Slog.w(TAG, "Couldn't read hdmi state from " + filename + ": " + ex);
5209 } finally {
5210 if (reader != null) {
5211 try {
5212 reader.close();
5213 } catch (IOException ex) {
5214 }
Joe Onoratodc100302011-01-11 17:07:41 -08005215 }
5216 }
5217 }
Joe Onorato7ba631f2011-05-04 15:28:00 -07005218 // This dance forces the code in setHdmiPlugged to run.
5219 // Always do this so the sticky intent is stuck (to false) if there is no hdmi.
5220 mHdmiPlugged = !plugged;
5221 setHdmiPlugged(!mHdmiPlugged);
Joe Onoratodc100302011-01-11 17:07:41 -08005222 }
5223
Dianne Hackbornc0e3f242011-08-19 14:19:10 -07005224 final Object mScreenshotLock = new Object();
Dianne Hackbornfc8fa632011-08-17 16:20:47 -07005225 ServiceConnection mScreenshotConnection = null;
Dianne Hackbornfc8fa632011-08-17 16:20:47 -07005226
Jeff Brownd5bb82d2011-10-12 13:57:59 -07005227 final Runnable mScreenshotTimeout = new Runnable() {
5228 @Override public void run() {
5229 synchronized (mScreenshotLock) {
5230 if (mScreenshotConnection != null) {
5231 mContext.unbindService(mScreenshotConnection);
5232 mScreenshotConnection = null;
Winson44dbe292016-03-10 14:00:14 -08005233 notifyScreenshotError();
Dianne Hackbornfc8fa632011-08-17 16:20:47 -07005234 }
Winson Chung9112ec32011-06-27 13:15:32 -07005235 }
Jeff Brownd5bb82d2011-10-12 13:57:59 -07005236 }
5237 };
5238
5239 // Assume this is called from the Handler thread.
Muyuan Li6ca619f2016-03-08 13:30:42 -08005240 private void takeScreenshot(final int screenshotType) {
Jeff Brownd5bb82d2011-10-12 13:57:59 -07005241 synchronized (mScreenshotLock) {
5242 if (mScreenshotConnection != null) {
5243 return;
5244 }
Winson44dbe292016-03-10 14:00:14 -08005245 final ComponentName serviceComponent = new ComponentName(SYSUI_PACKAGE,
5246 SYSUI_SCREENSHOT_SERVICE);
5247 final Intent serviceIntent = new Intent();
5248 serviceIntent.setComponent(serviceComponent);
Jeff Brownd5bb82d2011-10-12 13:57:59 -07005249 ServiceConnection conn = new ServiceConnection() {
5250 @Override
5251 public void onServiceConnected(ComponentName name, IBinder service) {
5252 synchronized (mScreenshotLock) {
5253 if (mScreenshotConnection != this) {
5254 return;
5255 }
5256 Messenger messenger = new Messenger(service);
Muyuan Li6ca619f2016-03-08 13:30:42 -08005257 Message msg = Message.obtain(null, screenshotType);
Jeff Brownd5bb82d2011-10-12 13:57:59 -07005258 final ServiceConnection myConn = this;
5259 Handler h = new Handler(mHandler.getLooper()) {
5260 @Override
5261 public void handleMessage(Message msg) {
5262 synchronized (mScreenshotLock) {
5263 if (mScreenshotConnection == myConn) {
5264 mContext.unbindService(mScreenshotConnection);
5265 mScreenshotConnection = null;
5266 mHandler.removeCallbacks(mScreenshotTimeout);
5267 }
5268 }
5269 }
5270 };
5271 msg.replyTo = new Messenger(h);
Winson Chunga63bb842011-10-17 10:26:28 -07005272 msg.arg1 = msg.arg2 = 0;
5273 if (mStatusBar != null && mStatusBar.isVisibleLw())
5274 msg.arg1 = 1;
5275 if (mNavigationBar != null && mNavigationBar.isVisibleLw())
5276 msg.arg2 = 1;
Jeff Brownd5bb82d2011-10-12 13:57:59 -07005277 try {
5278 messenger.send(msg);
5279 } catch (RemoteException e) {
5280 }
5281 }
5282 }
Winson44dbe292016-03-10 14:00:14 -08005283
Jeff Brownd5bb82d2011-10-12 13:57:59 -07005284 @Override
Winson44dbe292016-03-10 14:00:14 -08005285 public void onServiceDisconnected(ComponentName name) {
5286 notifyScreenshotError();
5287 }
Jeff Brownd5bb82d2011-10-12 13:57:59 -07005288 };
Winson44dbe292016-03-10 14:00:14 -08005289 if (mContext.bindServiceAsUser(serviceIntent, conn,
5290 Context.BIND_AUTO_CREATE | Context.BIND_FOREGROUND_SERVICE_WHILE_AWAKE,
5291 UserHandle.CURRENT)) {
Jeff Brownd5bb82d2011-10-12 13:57:59 -07005292 mScreenshotConnection = conn;
5293 mHandler.postDelayed(mScreenshotTimeout, 10000);
5294 }
5295 }
Winson Chung9112ec32011-06-27 13:15:32 -07005296 }
5297
Winson44dbe292016-03-10 14:00:14 -08005298 /**
5299 * Notifies the screenshot service to show an error.
5300 */
5301 private void notifyScreenshotError() {
5302 // If the service process is killed, then ask it to clean up after itself
5303 final ComponentName errorComponent = new ComponentName(SYSUI_PACKAGE,
5304 SYSUI_SCREENSHOT_ERROR_RECEIVER);
5305 Intent errorIntent = new Intent();
5306 errorIntent.setComponent(errorComponent);
5307 errorIntent.addFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY_BEFORE_BOOT |
5308 Intent.FLAG_RECEIVER_FOREGROUND);
5309 mContext.sendBroadcastAsUser(errorIntent, UserHandle.ALL);
5310 }
5311
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005312 /** {@inheritDoc} */
Jeff Brown00fa7bd2010-07-02 15:37:36 -07005313 @Override
Jeff Brown037c33e2014-04-09 00:31:55 -07005314 public int interceptKeyBeforeQueueing(KeyEvent event, int policyFlags) {
Jeff Brown96307042012-07-27 15:51:34 -07005315 if (!mSystemBooted) {
5316 // If we have not yet booted, don't let key events do anything.
5317 return 0;
5318 }
5319
Jeff Brown037c33e2014-04-09 00:31:55 -07005320 final boolean interactive = (policyFlags & FLAG_INTERACTIVE) != 0;
Jeff Brown1f245102010-11-18 20:53:46 -08005321 final boolean down = event.getAction() == KeyEvent.ACTION_DOWN;
5322 final boolean canceled = event.isCanceled();
5323 final int keyCode = event.getKeyCode();
Jeff Browne20c9e02010-10-11 14:20:19 -07005324
Jeff Brown3122e442010-10-11 23:32:49 -07005325 final boolean isInjected = (policyFlags & WindowManagerPolicy.FLAG_INJECTED) != 0;
Jeff Brown3122e442010-10-11 23:32:49 -07005326
Mike Lockwoodc72b15f2009-11-28 20:58:22 -05005327 // If screen is off then we treat the case where the keyguard is open but hidden
5328 // the same as if it were open and in front.
5329 // This will prevent any keys other than the power button from waking the screen
5330 // when the keyguard is hidden by another activity.
Jim Miller5ecd8112013-01-09 18:50:26 -08005331 final boolean keyguardActive = (mKeyguardDelegate == null ? false :
Jeff Brown037c33e2014-04-09 00:31:55 -07005332 (interactive ?
Jim Millerab954542014-10-10 18:21:49 -07005333 isKeyguardShowingAndNotOccluded() :
Jim Miller5ecd8112013-01-09 18:50:26 -08005334 mKeyguardDelegate.isShowing()));
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005335
Jeff Brown40013652012-05-16 21:22:36 -07005336 if (DEBUG_INPUT) {
Jeff Brown00fa7bd2010-07-02 15:37:36 -07005337 Log.d(TAG, "interceptKeyTq keycode=" + keyCode
Jeff Brown037c33e2014-04-09 00:31:55 -07005338 + " interactive=" + interactive + " keyguardActive=" + keyguardActive
Jeff Brown26875502014-01-30 21:47:47 -08005339 + " policyFlags=" + Integer.toHexString(policyFlags));
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005340 }
5341
Jeff Brown037c33e2014-04-09 00:31:55 -07005342 // Basic policy based on interactive state.
Jeff Brown4d396052010-10-29 21:50:21 -07005343 int result;
Michael Wright337d9d22014-04-22 15:03:48 -07005344 boolean isWakeKey = (policyFlags & WindowManagerPolicy.FLAG_WAKE) != 0
5345 || event.isWakeKey();
Michael Wrightfc01f042014-09-08 14:12:24 -07005346 if (interactive || (isInjected && !isWakeKey)) {
RoboErikde9ba392014-09-26 12:51:01 -07005347 // When the device is interactive or the key is injected pass the
5348 // key to the application.
Jeff Brown4d396052010-10-29 21:50:21 -07005349 result = ACTION_PASS_TO_USER;
Jose Lima9546b202014-07-02 17:21:51 -07005350 isWakeKey = false;
Michael Wrightfc01f042014-09-08 14:12:24 -07005351 } else if (!interactive && shouldDispatchInputWhenNonInteractive()) {
5352 // If we're currently dozing with the screen on and the keyguard showing, pass the key
5353 // to the application but preserve its wake key status to make sure we still move
5354 // from dozing to fully interactive if we would normally go from off to fully
5355 // interactive.
5356 result = ACTION_PASS_TO_USER;
Jeff Brown4d396052010-10-29 21:50:21 -07005357 } else {
5358 // When the screen is off and the key is not injected, determine whether
5359 // to wake the device but don't pass the key to the application.
5360 result = 0;
Jeff Brown26875502014-01-30 21:47:47 -08005361 if (isWakeKey && (!down || !isWakeKeyWhenScreenOff(keyCode))) {
5362 isWakeKey = false;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005363 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005364 }
5365
Justin Kohd378ad72013-04-01 12:18:26 -07005366 // If the key would be handled globally, just return the result, don't worry about special
5367 // key processing.
Jeff Brown13f00f02014-10-31 14:45:50 -07005368 if (isValidGlobalKey(keyCode)
5369 && mGlobalKeyManager.shouldHandleGlobalKey(keyCode, event)) {
Michael Wright85b1af62014-06-04 14:51:58 -07005370 if (isWakeKey) {
Dianne Hackborn280a64e2015-07-13 14:48:08 -07005371 wakeUp(event.getEventTime(), mAllowTheaterModeWakeFromKey, "android.policy:KEY");
Michael Wright85b1af62014-06-04 14:51:58 -07005372 }
Justin Kohd378ad72013-04-01 12:18:26 -07005373 return result;
5374 }
5375
Jeff Brownbae8e772014-06-12 19:59:45 -07005376 boolean useHapticFeedback = down
5377 && (policyFlags & WindowManagerPolicy.FLAG_VIRTUAL) != 0
5378 && event.getRepeatCount() == 0;
5379
Jeff Brown4d396052010-10-29 21:50:21 -07005380 // Handle special keys.
5381 switch (keyCode) {
Anthony Hugh34f09ca2016-03-04 12:03:37 -08005382 case KeyEvent.KEYCODE_BACK: {
5383 if (down) {
5384 mBackKeyHandled = false;
5385 if (hasLongPressOnBackBehavior()) {
5386 Message msg = mHandler.obtainMessage(MSG_BACK_LONG_PRESS);
5387 msg.setAsynchronous(true);
5388 mHandler.sendMessageDelayed(msg,
5389 ViewConfiguration.get(mContext).getDeviceGlobalActionKeyTimeout());
5390 }
5391 } else {
5392 boolean handled = mBackKeyHandled;
5393
5394 // Reset back key state
5395 cancelPendingBackKeyAction();
5396
5397 // Don't pass back press to app if we've already handled it
5398 if (handled) {
5399 result &= ~ACTION_PASS_TO_USER;
5400 }
5401 }
5402 break;
5403 }
5404
Jeff Brown4d396052010-10-29 21:50:21 -07005405 case KeyEvent.KEYCODE_VOLUME_DOWN:
Jeff Brownb0418da2010-11-01 15:24:01 -07005406 case KeyEvent.KEYCODE_VOLUME_UP:
5407 case KeyEvent.KEYCODE_VOLUME_MUTE: {
Jeff Brownd5bb82d2011-10-12 13:57:59 -07005408 if (keyCode == KeyEvent.KEYCODE_VOLUME_DOWN) {
5409 if (down) {
Jeff Brown13f00f02014-10-31 14:45:50 -07005410 if (interactive && !mScreenshotChordVolumeDownKeyTriggered
Jeff Brownd5bb82d2011-10-12 13:57:59 -07005411 && (event.getFlags() & KeyEvent.FLAG_FALLBACK) == 0) {
Jeff Brown13f00f02014-10-31 14:45:50 -07005412 mScreenshotChordVolumeDownKeyTriggered = true;
5413 mScreenshotChordVolumeDownKeyTime = event.getDownTime();
5414 mScreenshotChordVolumeDownKeyConsumed = false;
Jeff Brownd5bb82d2011-10-12 13:57:59 -07005415 cancelPendingPowerKeyAction();
5416 interceptScreenshotChord();
5417 }
5418 } else {
Jeff Brown13f00f02014-10-31 14:45:50 -07005419 mScreenshotChordVolumeDownKeyTriggered = false;
Jeff Brownd5bb82d2011-10-12 13:57:59 -07005420 cancelPendingScreenshotChordAction();
5421 }
5422 } else if (keyCode == KeyEvent.KEYCODE_VOLUME_UP) {
5423 if (down) {
Jeff Brown13f00f02014-10-31 14:45:50 -07005424 if (interactive && !mScreenshotChordVolumeUpKeyTriggered
Jeff Brownd5bb82d2011-10-12 13:57:59 -07005425 && (event.getFlags() & KeyEvent.FLAG_FALLBACK) == 0) {
Jeff Brown13f00f02014-10-31 14:45:50 -07005426 mScreenshotChordVolumeUpKeyTriggered = true;
Jeff Brownd5bb82d2011-10-12 13:57:59 -07005427 cancelPendingPowerKeyAction();
5428 cancelPendingScreenshotChordAction();
5429 }
5430 } else {
Jeff Brown13f00f02014-10-31 14:45:50 -07005431 mScreenshotChordVolumeUpKeyTriggered = false;
Jeff Brownd5bb82d2011-10-12 13:57:59 -07005432 cancelPendingScreenshotChordAction();
5433 }
5434 }
Jeff Brown4d396052010-10-29 21:50:21 -07005435 if (down) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -07005436 TelecomManager telecomManager = getTelecommService();
5437 if (telecomManager != null) {
5438 if (telecomManager.isRinging()) {
Santos Cordon6848f722014-05-21 15:22:12 -07005439 // If an incoming call is ringing, either VOLUME key means
5440 // "silence ringer". We handle these keys here, rather than
5441 // in the InCallScreen, to make sure we'll respond to them
5442 // even if the InCallScreen hasn't come to the foreground yet.
5443 // Look for the DOWN event here, to agree with the "fallback"
5444 // behavior in the InCallScreen.
5445 Log.i(TAG, "interceptKeyBeforeQueueing:"
5446 + " VOLUME key-down while ringing: Silence ringer!");
Jeff Brown4d396052010-10-29 21:50:21 -07005447
Santos Cordon6848f722014-05-21 15:22:12 -07005448 // Silence the ringer. (It's safe to call this
5449 // even if the ringer has already been silenced.)
Tyler Gunnef9f6f92014-09-12 22:16:17 -07005450 telecomManager.silenceRinger();
Jeff Brown4d396052010-10-29 21:50:21 -07005451
Santos Cordon6848f722014-05-21 15:22:12 -07005452 // And *don't* pass this key thru to the current activity
5453 // (which is probably the InCallScreen.)
5454 result &= ~ACTION_PASS_TO_USER;
5455 break;
5456 }
Tyler Gunnef9f6f92014-09-12 22:16:17 -07005457 if (telecomManager.isInCall()
Santos Cordon6848f722014-05-21 15:22:12 -07005458 && (result & ACTION_PASS_TO_USER) == 0) {
5459 // If we are in call but we decided not to pass the key to
RoboErik430fc482014-06-12 15:49:20 -07005460 // the application, just pass it to the session service.
5461
5462 MediaSessionLegacyHelper.getHelper(mContext)
RoboErik3c45c292014-07-08 16:47:31 -07005463 .sendVolumeKeyEvent(event, false);
Santos Cordon6848f722014-05-21 15:22:12 -07005464 break;
Jeff Brown4d396052010-10-29 21:50:21 -07005465 }
5466 }
Jaewan Kim765487f2016-01-12 14:45:42 +09005467 }
5468 if (mUseTvRouting) {
5469 // On TVs, defer special key handlings to
5470 // {@link interceptKeyBeforeDispatching()}.
5471 result |= ACTION_PASS_TO_USER;
5472 } else if ((result & ACTION_PASS_TO_USER) == 0) {
5473 // If we aren't passing to the user and no one else
5474 // handled it send it to the session manager to
5475 // figure out.
5476 MediaSessionLegacyHelper.getHelper(mContext)
5477 .sendVolumeKeyEvent(event, true);
Jeff Brown4d396052010-10-29 21:50:21 -07005478 }
5479 break;
5480 }
5481
5482 case KeyEvent.KEYCODE_ENDCALL: {
5483 result &= ~ACTION_PASS_TO_USER;
5484 if (down) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -07005485 TelecomManager telecomManager = getTelecommService();
Jeff Brown4d396052010-10-29 21:50:21 -07005486 boolean hungUp = false;
Tyler Gunnef9f6f92014-09-12 22:16:17 -07005487 if (telecomManager != null) {
5488 hungUp = telecomManager.endCall();
Jeff Brown4d396052010-10-29 21:50:21 -07005489 }
Jeff Brown13f00f02014-10-31 14:45:50 -07005490 if (interactive && !hungUp) {
5491 mEndCallKeyHandled = false;
5492 mHandler.postDelayed(mEndCallLongPress,
5493 ViewConfiguration.get(mContext).getDeviceGlobalActionKeyTimeout());
5494 } else {
5495 mEndCallKeyHandled = true;
5496 }
Jeff Brown4d396052010-10-29 21:50:21 -07005497 } else {
Jeff Brown13f00f02014-10-31 14:45:50 -07005498 if (!mEndCallKeyHandled) {
5499 mHandler.removeCallbacks(mEndCallLongPress);
5500 if (!canceled) {
5501 if ((mEndcallBehavior
5502 & Settings.System.END_BUTTON_BEHAVIOR_HOME) != 0) {
5503 if (goHome()) {
5504 break;
5505 }
Dianne Hackborn0041e972009-07-24 17:14:43 -07005506 }
Jeff Brown13f00f02014-10-31 14:45:50 -07005507 if ((mEndcallBehavior
5508 & Settings.System.END_BUTTON_BEHAVIOR_SLEEP) != 0) {
5509 mPowerManager.goToSleep(event.getEventTime(),
5510 PowerManager.GO_TO_SLEEP_REASON_POWER_BUTTON, 0);
5511 isWakeKey = false;
5512 }
Jeff Brown4d396052010-10-29 21:50:21 -07005513 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005514 }
Jeff Brown4d396052010-10-29 21:50:21 -07005515 }
5516 break;
5517 }
5518
5519 case KeyEvent.KEYCODE_POWER: {
5520 result &= ~ACTION_PASS_TO_USER;
Jeff Brown13f00f02014-10-31 14:45:50 -07005521 isWakeKey = false; // wake-up will be handled separately
Jeff Brown4d396052010-10-29 21:50:21 -07005522 if (down) {
Jeff Brown13f00f02014-10-31 14:45:50 -07005523 interceptPowerKeyDown(event, interactive);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005524 } else {
Jeff Brown13f00f02014-10-31 14:45:50 -07005525 interceptPowerKeyUp(event, interactive, canceled);
Jeff Brown4d396052010-10-29 21:50:21 -07005526 }
5527 break;
5528 }
5529
Jeff Brown6212a492014-03-07 13:58:47 -08005530 case KeyEvent.KEYCODE_SLEEP: {
5531 result &= ~ACTION_PASS_TO_USER;
Filip Gruszczynskia483a1d2015-03-17 19:06:58 +00005532 isWakeKey = false;
Jeff Brownbae8e772014-06-12 19:59:45 -07005533 if (!mPowerManager.isInteractive()) {
5534 useHapticFeedback = false; // suppress feedback if already non-interactive
5535 }
Nick Vaccarob593a812015-05-15 11:23:05 -07005536 if (down) {
5537 sleepPress(event.getEventTime());
5538 } else {
5539 sleepRelease(event.getEventTime());
5540 }
Jeff Brown6212a492014-03-07 13:58:47 -08005541 break;
5542 }
5543
Nick Armstrong-Crews56ecfcc2015-09-07 21:46:50 -07005544 case KeyEvent.KEYCODE_SOFT_SLEEP: {
5545 result &= ~ACTION_PASS_TO_USER;
5546 isWakeKey = false;
5547 if (!down) {
5548 mPowerManagerInternal.setUserInactiveOverrideFromWindowManager();
5549 }
5550 break;
5551 }
5552
Jeff Brown6212a492014-03-07 13:58:47 -08005553 case KeyEvent.KEYCODE_WAKEUP: {
5554 result &= ~ACTION_PASS_TO_USER;
Jose Lima9546b202014-07-02 17:21:51 -07005555 isWakeKey = true;
Jeff Brown6212a492014-03-07 13:58:47 -08005556 break;
5557 }
5558
Jeff Brown4d396052010-10-29 21:50:21 -07005559 case KeyEvent.KEYCODE_MEDIA_PLAY:
5560 case KeyEvent.KEYCODE_MEDIA_PAUSE:
5561 case KeyEvent.KEYCODE_MEDIA_PLAY_PAUSE:
Jeff Brown4d396052010-10-29 21:50:21 -07005562 case KeyEvent.KEYCODE_HEADSETHOOK:
5563 case KeyEvent.KEYCODE_MUTE:
5564 case KeyEvent.KEYCODE_MEDIA_STOP:
5565 case KeyEvent.KEYCODE_MEDIA_NEXT:
5566 case KeyEvent.KEYCODE_MEDIA_PREVIOUS:
5567 case KeyEvent.KEYCODE_MEDIA_REWIND:
5568 case KeyEvent.KEYCODE_MEDIA_RECORD:
Jaekyun Seokbfdad8e2013-07-08 13:53:21 +09005569 case KeyEvent.KEYCODE_MEDIA_FAST_FORWARD:
5570 case KeyEvent.KEYCODE_MEDIA_AUDIO_TRACK: {
RoboErikde9ba392014-09-26 12:51:01 -07005571 if (MediaSessionLegacyHelper.getHelper(mContext).isGlobalPriorityActive()) {
5572 // If the global session is active pass all media keys to it
5573 // instead of the active window.
5574 result &= ~ACTION_PASS_TO_USER;
5575 }
Jeff Brown4d396052010-10-29 21:50:21 -07005576 if ((result & ACTION_PASS_TO_USER) == 0) {
5577 // Only do this if we would otherwise not pass it to the user. In that
5578 // case, the PhoneWindow class will do the same thing, except it will
5579 // only do it if the showing app doesn't process the key on its own.
Jeff Brown40013652012-05-16 21:22:36 -07005580 // Note that we need to make a copy of the key event here because the
5581 // original key event will be recycled when we return.
Jeff Brown4d396052010-10-29 21:50:21 -07005582 mBroadcastWakeLock.acquire();
Jeff Brown40013652012-05-16 21:22:36 -07005583 Message msg = mHandler.obtainMessage(MSG_DISPATCH_MEDIA_KEY_WITH_WAKE_LOCK,
5584 new KeyEvent(event));
5585 msg.setAsynchronous(true);
5586 msg.sendToTarget();
Jeff Brown4d396052010-10-29 21:50:21 -07005587 }
5588 break;
Jeff Brown00fa7bd2010-07-02 15:37:36 -07005589 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005590
Jeff Brown4d396052010-10-29 21:50:21 -07005591 case KeyEvent.KEYCODE_CALL: {
5592 if (down) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -07005593 TelecomManager telecomManager = getTelecommService();
5594 if (telecomManager != null) {
5595 if (telecomManager.isRinging()) {
Santos Cordon6848f722014-05-21 15:22:12 -07005596 Log.i(TAG, "interceptKeyBeforeQueueing:"
5597 + " CALL key-down while ringing: Answer the call!");
Tyler Gunnef9f6f92014-09-12 22:16:17 -07005598 telecomManager.acceptRingingCall();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005599
Santos Cordon6848f722014-05-21 15:22:12 -07005600 // And *don't* pass this key thru to the current activity
5601 // (which is presumably the InCallScreen.)
5602 result &= ~ACTION_PASS_TO_USER;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005603 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005604 }
Jeff Brown00fa7bd2010-07-02 15:37:36 -07005605 }
Jeff Brown4d396052010-10-29 21:50:21 -07005606 break;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005607 }
Michael Wright869a67c2014-08-26 19:33:06 -07005608 case KeyEvent.KEYCODE_VOICE_ASSIST: {
5609 // Only do this if we would otherwise not pass it to the user. In that case,
5610 // interceptKeyBeforeDispatching would apply a similar but different policy in
5611 // order to invoke voice assist actions. Note that we need to make a copy of the
5612 // key event here because the original key event will be recycled when we return.
5613 if ((result & ACTION_PASS_TO_USER) == 0 && !down) {
5614 mBroadcastWakeLock.acquire();
5615 Message msg = mHandler.obtainMessage(MSG_LAUNCH_VOICE_ASSIST_WITH_WAKE_LOCK,
5616 keyguardActive ? 1 : 0, 0);
5617 msg.setAsynchronous(true);
5618 msg.sendToTarget();
5619 }
Jaewan Kim49117872016-01-19 17:24:08 +09005620 break;
5621 }
5622 case KeyEvent.KEYCODE_WINDOW: {
5623 if (mShortPressWindowBehavior == SHORT_PRESS_WINDOW_PICTURE_IN_PICTURE) {
5624 if (!down) {
Jaewan Kimc552b042016-01-18 16:08:45 +09005625 requestTvPictureInPicture(event);
Jaewan Kim49117872016-01-19 17:24:08 +09005626 }
5627 result &= ~ACTION_PASS_TO_USER;
5628 }
5629 break;
Michael Wright869a67c2014-08-26 19:33:06 -07005630 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005631 }
Jeff Brown26875502014-01-30 21:47:47 -08005632
Jeff Brownbae8e772014-06-12 19:59:45 -07005633 if (useHapticFeedback) {
5634 performHapticFeedbackLw(null, HapticFeedbackConstants.VIRTUAL_KEY, false);
5635 }
5636
Jeff Brown26875502014-01-30 21:47:47 -08005637 if (isWakeKey) {
Dianne Hackborn280a64e2015-07-13 14:48:08 -07005638 wakeUp(event.getEventTime(), mAllowTheaterModeWakeFromKey, "android.policy:KEY");
Jeff Brown26875502014-01-30 21:47:47 -08005639 }
Bryce Lee584a4452014-10-21 15:55:55 -07005640
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005641 return result;
5642 }
5643
Jeff Brown1c2e4942012-11-06 16:32:01 -08005644 /**
Jeff Brown13f00f02014-10-31 14:45:50 -07005645 * Returns true if the key can have global actions attached to it.
5646 * We reserve all power management keys for the system since they require
5647 * very careful handling.
5648 */
5649 private static boolean isValidGlobalKey(int keyCode) {
5650 switch (keyCode) {
5651 case KeyEvent.KEYCODE_POWER:
5652 case KeyEvent.KEYCODE_WAKEUP:
5653 case KeyEvent.KEYCODE_SLEEP:
5654 return false;
5655 default:
5656 return true;
5657 }
5658 }
5659
5660 /**
Jeff Brown1c2e4942012-11-06 16:32:01 -08005661 * When the screen is off we ignore some keys that might otherwise typically
5662 * be considered wake keys. We filter them out here.
5663 *
5664 * {@link KeyEvent#KEYCODE_POWER} is notably absent from this list because it
5665 * is always considered a wake key.
5666 */
5667 private boolean isWakeKeyWhenScreenOff(int keyCode) {
5668 switch (keyCode) {
5669 // ignore volume keys unless docked
5670 case KeyEvent.KEYCODE_VOLUME_UP:
5671 case KeyEvent.KEYCODE_VOLUME_DOWN:
5672 case KeyEvent.KEYCODE_VOLUME_MUTE:
5673 return mDockMode != Intent.EXTRA_DOCK_STATE_UNDOCKED;
5674
5675 // ignore media and camera keys
5676 case KeyEvent.KEYCODE_MUTE:
5677 case KeyEvent.KEYCODE_HEADSETHOOK:
5678 case KeyEvent.KEYCODE_MEDIA_PLAY:
5679 case KeyEvent.KEYCODE_MEDIA_PAUSE:
5680 case KeyEvent.KEYCODE_MEDIA_PLAY_PAUSE:
5681 case KeyEvent.KEYCODE_MEDIA_STOP:
5682 case KeyEvent.KEYCODE_MEDIA_NEXT:
5683 case KeyEvent.KEYCODE_MEDIA_PREVIOUS:
5684 case KeyEvent.KEYCODE_MEDIA_REWIND:
5685 case KeyEvent.KEYCODE_MEDIA_RECORD:
5686 case KeyEvent.KEYCODE_MEDIA_FAST_FORWARD:
Jaekyun Seokbfdad8e2013-07-08 13:53:21 +09005687 case KeyEvent.KEYCODE_MEDIA_AUDIO_TRACK:
Jeff Brown1c2e4942012-11-06 16:32:01 -08005688 case KeyEvent.KEYCODE_CAMERA:
5689 return false;
5690 }
5691 return true;
5692 }
5693
5694
Jeff Brown56194eb2011-03-02 19:23:13 -08005695 /** {@inheritDoc} */
5696 @Override
Michael Wright70af00a2014-09-03 19:30:20 -07005697 public int interceptMotionBeforeQueueingNonInteractive(long whenNanos, int policyFlags) {
5698 if ((policyFlags & FLAG_WAKE) != 0) {
Dianne Hackborn280a64e2015-07-13 14:48:08 -07005699 if (wakeUp(whenNanos / 1000000, mAllowTheaterModeWakeFromMotion,
5700 "android.policy:MOTION")) {
Bryce Lee5c138322014-11-03 08:26:09 -08005701 return 0;
5702 }
Michael Wright70af00a2014-09-03 19:30:20 -07005703 }
Bryce Lee5c138322014-11-03 08:26:09 -08005704
Michael Wright70af00a2014-09-03 19:30:20 -07005705 if (shouldDispatchInputWhenNonInteractive()) {
5706 return ACTION_PASS_TO_USER;
5707 }
Bryce Lee5c138322014-11-03 08:26:09 -08005708
Bryce Lee812d7022014-11-10 13:33:28 -08005709 // If we have not passed the action up and we are in theater mode without dreaming,
5710 // there will be no dream to intercept the touch and wake into ambient. The device should
5711 // wake up in this case.
5712 if (isTheaterModeEnabled() && (policyFlags & FLAG_WAKE) != 0) {
Dianne Hackborn280a64e2015-07-13 14:48:08 -07005713 wakeUp(whenNanos / 1000000, mAllowTheaterModeWakeFromMotionWhenNotDreaming,
5714 "android.policy:MOTION");
Bryce Lee812d7022014-11-10 13:33:28 -08005715 }
5716
Jeff Brown037c33e2014-04-09 00:31:55 -07005717 return 0;
Jeff Brown56194eb2011-03-02 19:23:13 -08005718 }
5719
Michael Wright70af00a2014-09-03 19:30:20 -07005720 private boolean shouldDispatchInputWhenNonInteractive() {
Joe LaPennaf2b9b2d2015-11-17 22:22:37 +00005721 // Send events to keyguard while the screen is on.
5722 if (isKeyguardShowingAndNotOccluded() && mDisplay != null
5723 && mDisplay.getState() != Display.STATE_OFF) {
Bryce Lee5c138322014-11-03 08:26:09 -08005724 return true;
5725 }
5726
5727 // Send events to a dozing dream even if the screen is off since the dream
5728 // is in control of the state of the screen.
5729 IDreamManager dreamManager = getDreamManager();
5730
5731 try {
5732 if (dreamManager != null && dreamManager.isDreaming()) {
5733 return true;
5734 }
5735 } catch (RemoteException e) {
5736 Slog.e(TAG, "RemoteException when checking if dreaming", e);
5737 }
5738
5739 // Otherwise, consume events since the user can't see what is being
5740 // interacted with.
5741 return false;
Michael Wright70af00a2014-09-03 19:30:20 -07005742 }
5743
RoboErik001c59c2015-01-26 15:53:51 -08005744 private void dispatchDirectAudioEvent(KeyEvent event) {
5745 if (event.getAction() != KeyEvent.ACTION_DOWN) {
5746 return;
5747 }
5748 int keyCode = event.getKeyCode();
John Spurlockb94f2d62015-03-17 14:11:57 -04005749 int flags = AudioManager.FLAG_SHOW_UI | AudioManager.FLAG_PLAY_SOUND
5750 | AudioManager.FLAG_FROM_KEY;
RoboErik001c59c2015-01-26 15:53:51 -08005751 String pkgName = mContext.getOpPackageName();
5752 switch (keyCode) {
5753 case KeyEvent.KEYCODE_VOLUME_UP:
5754 try {
John Spurlockee5ad722015-03-03 16:17:21 -05005755 getAudioService().adjustSuggestedStreamVolume(AudioManager.ADJUST_RAISE,
John Spurlock90874332015-03-10 16:00:54 -04005756 AudioManager.USE_DEFAULT_STREAM_TYPE, flags, pkgName, TAG);
RoboErik001c59c2015-01-26 15:53:51 -08005757 } catch (RemoteException e) {
5758 Log.e(TAG, "Error dispatching volume up in dispatchTvAudioEvent.", e);
5759 }
5760 break;
5761 case KeyEvent.KEYCODE_VOLUME_DOWN:
5762 try {
John Spurlockee5ad722015-03-03 16:17:21 -05005763 getAudioService().adjustSuggestedStreamVolume(AudioManager.ADJUST_LOWER,
John Spurlock90874332015-03-10 16:00:54 -04005764 AudioManager.USE_DEFAULT_STREAM_TYPE, flags, pkgName, TAG);
RoboErik001c59c2015-01-26 15:53:51 -08005765 } catch (RemoteException e) {
5766 Log.e(TAG, "Error dispatching volume down in dispatchTvAudioEvent.", e);
5767 }
5768 break;
5769 case KeyEvent.KEYCODE_VOLUME_MUTE:
5770 try {
5771 if (event.getRepeatCount() == 0) {
John Spurlockee5ad722015-03-03 16:17:21 -05005772 getAudioService().adjustSuggestedStreamVolume(
5773 AudioManager.ADJUST_TOGGLE_MUTE,
John Spurlock90874332015-03-10 16:00:54 -04005774 AudioManager.USE_DEFAULT_STREAM_TYPE, flags, pkgName, TAG);
RoboErik001c59c2015-01-26 15:53:51 -08005775 }
5776 } catch (RemoteException e) {
5777 Log.e(TAG, "Error dispatching mute in dispatchTvAudioEvent.", e);
5778 }
5779 break;
5780 }
5781 }
5782
Jeff Brown40013652012-05-16 21:22:36 -07005783 void dispatchMediaKeyWithWakeLock(KeyEvent event) {
5784 if (DEBUG_INPUT) {
5785 Slog.d(TAG, "dispatchMediaKeyWithWakeLock: " + event);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005786 }
5787
Jeff Brown40013652012-05-16 21:22:36 -07005788 if (mHavePendingMediaKeyRepeatWithWakeLock) {
5789 if (DEBUG_INPUT) {
5790 Slog.d(TAG, "dispatchMediaKeyWithWakeLock: canceled repeat");
5791 }
5792
5793 mHandler.removeMessages(MSG_DISPATCH_MEDIA_KEY_REPEAT_WITH_WAKE_LOCK);
5794 mHavePendingMediaKeyRepeatWithWakeLock = false;
5795 mBroadcastWakeLock.release(); // pending repeat was holding onto the wake lock
5796 }
5797
5798 dispatchMediaKeyWithWakeLockToAudioService(event);
5799
5800 if (event.getAction() == KeyEvent.ACTION_DOWN
5801 && event.getRepeatCount() == 0) {
5802 mHavePendingMediaKeyRepeatWithWakeLock = true;
5803
5804 Message msg = mHandler.obtainMessage(
5805 MSG_DISPATCH_MEDIA_KEY_REPEAT_WITH_WAKE_LOCK, event);
5806 msg.setAsynchronous(true);
5807 mHandler.sendMessageDelayed(msg, ViewConfiguration.getKeyRepeatTimeout());
5808 } else {
5809 mBroadcastWakeLock.release();
5810 }
5811 }
5812
5813 void dispatchMediaKeyRepeatWithWakeLock(KeyEvent event) {
5814 mHavePendingMediaKeyRepeatWithWakeLock = false;
5815
5816 KeyEvent repeatEvent = KeyEvent.changeTimeRepeat(event,
5817 SystemClock.uptimeMillis(), 1, event.getFlags() | KeyEvent.FLAG_LONG_PRESS);
5818 if (DEBUG_INPUT) {
5819 Slog.d(TAG, "dispatchMediaKeyRepeatWithWakeLock: " + repeatEvent);
5820 }
5821
5822 dispatchMediaKeyWithWakeLockToAudioService(repeatEvent);
5823 mBroadcastWakeLock.release();
5824 }
5825
5826 void dispatchMediaKeyWithWakeLockToAudioService(KeyEvent event) {
5827 if (ActivityManagerNative.isSystemReady()) {
RoboErik430fc482014-06-12 15:49:20 -07005828 MediaSessionLegacyHelper.getHelper(mContext).sendMediaButtonEvent(event, true);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005829 }
5830 }
5831
Michael Wright869a67c2014-08-26 19:33:06 -07005832 void launchVoiceAssistWithWakeLock(boolean keyguardActive) {
Dianne Hackbornb6683c42015-06-18 17:40:33 -07005833 IDeviceIdleController dic = IDeviceIdleController.Stub.asInterface(
5834 ServiceManager.getService(Context.DEVICE_IDLE_CONTROLLER));
5835 if (dic != null) {
5836 try {
5837 dic.exitIdle("voice-search");
5838 } catch (RemoteException e) {
5839 }
5840 }
Michael Wright869a67c2014-08-26 19:33:06 -07005841 Intent voiceIntent =
5842 new Intent(RecognizerIntent.ACTION_VOICE_SEARCH_HANDS_FREE);
5843 voiceIntent.putExtra(RecognizerIntent.EXTRA_SECURE, keyguardActive);
Bart Sears8b1c27c2015-03-18 23:51:02 +00005844 startActivityAsUser(voiceIntent, UserHandle.CURRENT_OR_SELF);
Michael Wright869a67c2014-08-26 19:33:06 -07005845 mBroadcastWakeLock.release();
5846 }
5847
Mike Lockwood1753f7f2009-08-24 14:49:07 -07005848 BroadcastReceiver mDockReceiver = new BroadcastReceiver() {
Craig Mautnereee29c42013-01-17 14:44:34 -08005849 @Override
Mike Lockwood1753f7f2009-08-24 14:49:07 -07005850 public void onReceive(Context context, Intent intent) {
Dianne Hackborn867ab6472010-04-29 13:28:56 -07005851 if (Intent.ACTION_DOCK_EVENT.equals(intent.getAction())) {
5852 mDockMode = intent.getIntExtra(Intent.EXTRA_DOCK_STATE,
5853 Intent.EXTRA_DOCK_STATE_UNDOCKED);
Daniel Sandler6396c722013-04-16 20:19:09 -04005854 } else {
5855 try {
5856 IUiModeManager uiModeService = IUiModeManager.Stub.asInterface(
5857 ServiceManager.getService(Context.UI_MODE_SERVICE));
5858 mUiMode = uiModeService.getCurrentModeType();
5859 } catch (RemoteException e) {
5860 }
Dianne Hackborn80fa1662009-10-07 14:02:10 -07005861 }
Jeff Brown01a98dd2011-09-20 15:08:29 -07005862 updateRotation(true);
Craig Mautnereee29c42013-01-17 14:44:34 -08005863 synchronized (mLock) {
5864 updateOrientationListenerLp();
5865 }
Mike Lockwood1753f7f2009-08-24 14:49:07 -07005866 }
5867 };
5868
Jeff Brown6aaf2952012-10-05 16:01:08 -07005869 BroadcastReceiver mDreamReceiver = new BroadcastReceiver() {
5870 @Override
5871 public void onReceive(Context context, Intent intent) {
5872 if (Intent.ACTION_DREAMING_STARTED.equals(intent.getAction())) {
Jim Miller5ecd8112013-01-09 18:50:26 -08005873 if (mKeyguardDelegate != null) {
5874 mKeyguardDelegate.onDreamingStarted();
Jeff Brown6aaf2952012-10-05 16:01:08 -07005875 }
5876 } else if (Intent.ACTION_DREAMING_STOPPED.equals(intent.getAction())) {
Jim Miller5ecd8112013-01-09 18:50:26 -08005877 if (mKeyguardDelegate != null) {
5878 mKeyguardDelegate.onDreamingStopped();
Jeff Brown6aaf2952012-10-05 16:01:08 -07005879 }
5880 }
5881 }
5882 };
5883
Christopher Tate5e08af02012-09-21 17:17:22 -07005884 BroadcastReceiver mMultiuserReceiver = new BroadcastReceiver() {
5885 @Override
5886 public void onReceive(Context context, Intent intent) {
5887 if (Intent.ACTION_USER_SWITCHED.equals(intent.getAction())) {
5888 // tickle the settings observer: this first ensures that we're
5889 // observing the relevant settings for the newly-active user,
5890 // and then updates our own bookkeeping based on the now-
5891 // current user.
5892 mSettingsObserver.onChange(false);
John Spurlockce479d82012-11-29 09:52:21 -05005893
5894 // force a re-application of focused window sysui visibility.
5895 // the window may never have been shown for this user
5896 // e.g. the keyguard when going through the new-user setup flow
John Spurlock04db1762013-05-13 12:46:41 -04005897 synchronized (mWindowManagerFuncs.getWindowManagerLock()) {
John Spurlockce479d82012-11-29 09:52:21 -05005898 mLastSystemUiFlags = 0;
5899 updateSystemUiVisibilityLw();
5900 }
Christopher Tate5e08af02012-09-21 17:17:22 -07005901 }
5902 }
5903 };
5904
Adrian Roosddc8b272015-05-21 16:28:27 -07005905 private final Runnable mHiddenNavPanic = new Runnable() {
John Spurlockd9b70bd2014-02-06 17:02:44 -05005906 @Override
5907 public void run() {
Adrian Roosddc8b272015-05-21 16:28:27 -07005908 synchronized (mWindowManagerFuncs.getWindowManagerLock()) {
5909 if (!isUserSetupComplete()) {
5910 // Swipe-up for navigation bar is disabled during setup
5911 return;
5912 }
5913 mPendingPanicGestureUptime = SystemClock.uptimeMillis();
5914 mNavigationBarController.showTransient();
5915 }
John Spurlockd9b70bd2014-02-06 17:02:44 -05005916 }
5917 };
5918
John Spurlocke1f366f2013-08-05 12:22:40 -04005919 private void requestTransientBars(WindowState swipeTarget) {
John Spurlock04db1762013-05-13 12:46:41 -04005920 synchronized (mWindowManagerFuncs.getWindowManagerLock()) {
Maurice Lam99c6e072014-04-28 18:24:28 -07005921 if (!isUserSetupComplete()) {
5922 // Swipe-up for navigation bar is disabled during setup
5923 return;
5924 }
John Spurlock27735a42013-08-14 17:57:38 -04005925 boolean sb = mStatusBarController.checkShowTransientBarLw();
5926 boolean nb = mNavigationBarController.checkShowTransientBarLw();
John Spurlockad3e6cb2013-04-30 08:47:43 -04005927 if (sb || nb) {
Adrian Roos62b65e42015-02-25 18:05:34 +01005928 // Don't show status bar when swiping on already visible navigation bar
5929 if (!nb && swipeTarget == mNavigationBar) {
John Spurlocke1f366f2013-08-05 12:22:40 -04005930 if (DEBUG) Slog.d(TAG, "Not showing transient bar, wrong swipe target");
John Spurlockad3e6cb2013-04-30 08:47:43 -04005931 return;
5932 }
John Spurlock27735a42013-08-14 17:57:38 -04005933 if (sb) mStatusBarController.showTransient();
5934 if (nb) mNavigationBarController.showTransient();
John Spurlockf1a36642013-10-12 17:50:42 -04005935 mImmersiveModeConfirmation.confirmCurrentPrompt();
John Spurlockad3e6cb2013-04-30 08:47:43 -04005936 updateSystemUiVisibilityLw();
John Spurlock32beb2c2013-03-11 10:16:47 -04005937 }
John Spurlockad3e6cb2013-04-30 08:47:43 -04005938 }
5939 }
5940
Jeff Brown3ee549c2014-09-22 20:14:39 -07005941 // Called on the PowerManager's Notifier thread.
Jeff Brownc38c9be2012-10-04 13:16:19 -07005942 @Override
Jeff Brown416c49c2015-05-26 19:50:18 -07005943 public void startedGoingToSleep(int why) {
5944 if (DEBUG_WAKEUP) Slog.i(TAG, "Started going to sleep... (why=" + why + ")");
Jorim Jaggid175b6c2015-05-27 15:39:09 -07005945 if (mKeyguardDelegate != null) {
5946 mKeyguardDelegate.onStartedGoingToSleep(why);
5947 }
Jeff Brown416c49c2015-05-26 19:50:18 -07005948 }
5949
5950 // Called on the PowerManager's Notifier thread.
5951 @Override
5952 public void finishedGoingToSleep(int why) {
Dianne Hackborn74489012009-03-24 20:50:09 -07005953 EventLog.writeEvent(70000, 0);
Jeff Brown416c49c2015-05-26 19:50:18 -07005954 if (DEBUG_WAKEUP) Slog.i(TAG, "Finished going to sleep... (why=" + why + ")");
Chris Wren9bb290b2015-06-29 12:02:13 -04005955 MetricsLogger.histogram(mContext, "screen_timeout", mLockScreenTimeout / 1000);
Jeff Brown3ee549c2014-09-22 20:14:39 -07005956
5957 // We must get this work done here because the power manager will drop
5958 // the wake lock and let the system suspend once this function returns.
The Android Open Source Project0727d222009-03-11 12:11:58 -07005959 synchronized (mLock) {
Jeff Brown3ee549c2014-09-22 20:14:39 -07005960 mAwake = false;
Jeff Browna20dda42014-05-27 20:57:24 -07005961 updateWakeGestureListenerLp();
The Android Open Source Project0727d222009-03-11 12:11:58 -07005962 updateOrientationListenerLp();
Mike Lockwood28569302010-01-28 11:54:40 -05005963 updateLockScreenTimeout();
The Android Open Source Project0727d222009-03-11 12:11:58 -07005964 }
Jeff Brown3ee549c2014-09-22 20:14:39 -07005965 if (mKeyguardDelegate != null) {
Jorim Jaggid175b6c2015-05-27 15:39:09 -07005966 mKeyguardDelegate.onFinishedGoingToSleep(why);
Jeff Brown3ee549c2014-09-22 20:14:39 -07005967 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005968 }
5969
Jeff Brown3ee549c2014-09-22 20:14:39 -07005970 // Called on the PowerManager's Notifier thread.
Jeff Brownc38c9be2012-10-04 13:16:19 -07005971 @Override
Jeff Brown416c49c2015-05-26 19:50:18 -07005972 public void startedWakingUp() {
Dianne Hackborn74489012009-03-24 20:50:09 -07005973 EventLog.writeEvent(70000, 1);
Jeff Brown416c49c2015-05-26 19:50:18 -07005974 if (DEBUG_WAKEUP) Slog.i(TAG, "Started waking up...");
Craig Mautner8a0da012014-05-31 15:13:37 -07005975
Jeff Brown3ee549c2014-09-22 20:14:39 -07005976 // Since goToSleep performs these functions synchronously, we must
5977 // do the same here. We cannot post this work to a handler because
5978 // that might cause it to become reordered with respect to what
5979 // may happen in a future call to goToSleep.
The Android Open Source Project0727d222009-03-11 12:11:58 -07005980 synchronized (mLock) {
Jeff Brown3ee549c2014-09-22 20:14:39 -07005981 mAwake = true;
Jeff Brown3ee549c2014-09-22 20:14:39 -07005982
Jeff Browna20dda42014-05-27 20:57:24 -07005983 updateWakeGestureListenerLp();
The Android Open Source Project0727d222009-03-11 12:11:58 -07005984 updateOrientationListenerLp();
Mike Lockwood28569302010-01-28 11:54:40 -05005985 updateLockScreenTimeout();
The Android Open Source Project0727d222009-03-11 12:11:58 -07005986 }
Jeff Brownc38c9be2012-10-04 13:16:19 -07005987
Jim Miller5ecd8112013-01-09 18:50:26 -08005988 if (mKeyguardDelegate != null) {
Jorim Jaggi4cfdcf52015-07-09 12:13:59 -07005989 mKeyguardDelegate.onStartedWakingUp();
Jeff Brownc38c9be2012-10-04 13:16:19 -07005990 }
Jeff Brown36c4db82014-09-19 12:05:31 -07005991 }
5992
Jeff Brown416c49c2015-05-26 19:50:18 -07005993 // Called on the PowerManager's Notifier thread.
5994 @Override
5995 public void finishedWakingUp() {
5996 if (DEBUG_WAKEUP) Slog.i(TAG, "Finished waking up...");
5997 }
5998
5999 private void wakeUpFromPowerKey(long eventTime) {
Dianne Hackborn280a64e2015-07-13 14:48:08 -07006000 wakeUp(eventTime, mAllowTheaterModeWakeFromPowerKey, "android.policy:POWER");
Jeff Brown416c49c2015-05-26 19:50:18 -07006001 }
6002
Dianne Hackborn280a64e2015-07-13 14:48:08 -07006003 private boolean wakeUp(long wakeTime, boolean wakeInTheaterMode, String reason) {
Bryce Leed3896842015-06-23 17:06:51 -07006004 final boolean theaterModeEnabled = isTheaterModeEnabled();
6005 if (!wakeInTheaterMode && theaterModeEnabled) {
Jeff Brown416c49c2015-05-26 19:50:18 -07006006 return false;
6007 }
6008
Bryce Leed3896842015-06-23 17:06:51 -07006009 if (theaterModeEnabled) {
6010 Settings.Global.putInt(mContext.getContentResolver(),
6011 Settings.Global.THEATER_MODE_ON, 0);
6012 }
6013
Dianne Hackborn280a64e2015-07-13 14:48:08 -07006014 mPowerManager.wakeUp(wakeTime, reason);
Jeff Brown416c49c2015-05-26 19:50:18 -07006015 return true;
6016 }
6017
Jeff Brown36c4db82014-09-19 12:05:31 -07006018 private void finishKeyguardDrawn() {
Jeff Brown3ee549c2014-09-22 20:14:39 -07006019 synchronized (mLock) {
Jorim Jaggif3255482015-07-24 12:32:42 -07006020 if (!mScreenOnEarly || mKeyguardDrawComplete) {
Stefan Kuhne9326dc12015-06-12 09:25:32 -10006021 return; // We are not awake yet or we have already informed of this event.
Jeff Brown3ee549c2014-09-22 20:14:39 -07006022 }
6023
Jeff Brown36c4db82014-09-19 12:05:31 -07006024 mKeyguardDrawComplete = true;
Jeff Brown3ee549c2014-09-22 20:14:39 -07006025 if (mKeyguardDelegate != null) {
6026 mHandler.removeMessages(MSG_KEYGUARD_DRAWN_TIMEOUT);
6027 }
Jorim Jaggi4cfdcf52015-07-09 12:13:59 -07006028 mWindowManagerDrawComplete = false;
Jeff Brown3ee549c2014-09-22 20:14:39 -07006029 }
6030
Jorim Jaggi4cfdcf52015-07-09 12:13:59 -07006031 // ... eventually calls finishWindowsDrawn which will finalize our screen turn on
6032 // as well as enabling the orientation change logic/sensor.
6033 mWindowManagerInternal.waitForAllWindowsDrawn(mWindowManagerDrawCallback,
6034 WAITING_FOR_DRAWN_TIMEOUT);
Jeff Brown3ee549c2014-09-22 20:14:39 -07006035 }
6036
6037 // Called on the DisplayManager's DisplayPowerController thread.
6038 @Override
6039 public void screenTurnedOff() {
6040 if (DEBUG_WAKEUP) Slog.i(TAG, "Screen turned off...");
6041
Jeff Brown48d1b142015-06-10 16:36:03 -07006042 updateScreenOffSleepToken(true);
Jeff Brown3ee549c2014-09-22 20:14:39 -07006043 synchronized (mLock) {
6044 mScreenOnEarly = false;
6045 mScreenOnFully = false;
Jorim Jaggi95c6dae2015-07-29 15:17:23 -07006046 mKeyguardDrawComplete = false;
Jeff Brown3ee549c2014-09-22 20:14:39 -07006047 mWindowManagerDrawComplete = false;
6048 mScreenOnListener = null;
6049 updateOrientationListenerLp();
Jorim Jaggi0d210f62015-07-10 14:24:44 -07006050
6051 if (mKeyguardDelegate != null) {
6052 mKeyguardDelegate.onScreenTurnedOff();
6053 }
Jeff Brown36c4db82014-09-19 12:05:31 -07006054 }
6055 }
6056
Jeff Brown3ee549c2014-09-22 20:14:39 -07006057 // Called on the DisplayManager's DisplayPowerController thread.
Jeff Brown36c4db82014-09-19 12:05:31 -07006058 @Override
6059 public void screenTurningOn(final ScreenOnListener screenOnListener) {
Jeff Brown36c4db82014-09-19 12:05:31 -07006060 if (DEBUG_WAKEUP) Slog.i(TAG, "Screen turning on...");
Jeff Brown36c4db82014-09-19 12:05:31 -07006061
Jeff Brown48d1b142015-06-10 16:36:03 -07006062 updateScreenOffSleepToken(false);
Jeff Brown3ee549c2014-09-22 20:14:39 -07006063 synchronized (mLock) {
6064 mScreenOnEarly = true;
6065 mScreenOnFully = false;
Jorim Jaggi95c6dae2015-07-29 15:17:23 -07006066 mKeyguardDrawComplete = false;
Jeff Brown3ee549c2014-09-22 20:14:39 -07006067 mWindowManagerDrawComplete = false;
6068 mScreenOnListener = screenOnListener;
Jeff Brown36c4db82014-09-19 12:05:31 -07006069
Jorim Jaggi4cfdcf52015-07-09 12:13:59 -07006070 if (mKeyguardDelegate != null) {
Jorim Jaggia4b51bc2015-08-10 18:20:43 -07006071 mHandler.removeMessages(MSG_KEYGUARD_DRAWN_TIMEOUT);
6072 mHandler.sendEmptyMessageDelayed(MSG_KEYGUARD_DRAWN_TIMEOUT, 1000);
Jorim Jaggi4cfdcf52015-07-09 12:13:59 -07006073 mKeyguardDelegate.onScreenTurningOn(mKeyguardDrawnCallback);
6074 } else {
6075 if (DEBUG_WAKEUP) Slog.d(TAG,
6076 "null mKeyguardDelegate: setting mKeyguardDrawComplete.");
6077 finishKeyguardDrawn();
6078 }
6079 }
Jeff Brown36c4db82014-09-19 12:05:31 -07006080 }
6081
Jorim Jaggi0d210f62015-07-10 14:24:44 -07006082 // Called on the DisplayManager's DisplayPowerController thread.
6083 @Override
6084 public void screenTurnedOn() {
6085 synchronized (mLock) {
6086 if (mKeyguardDelegate != null) {
6087 mKeyguardDelegate.onScreenTurnedOn();
6088 }
6089 }
6090 }
6091
Jeff Brown36c4db82014-09-19 12:05:31 -07006092 private void finishWindowsDrawn() {
Jeff Brown3ee549c2014-09-22 20:14:39 -07006093 synchronized (mLock) {
6094 if (!mScreenOnEarly || mWindowManagerDrawComplete) {
Stefan Kuhne9326dc12015-06-12 09:25:32 -10006095 return; // Screen is not turned on or we did already handle this case earlier.
Jeff Brown3ee549c2014-09-22 20:14:39 -07006096 }
6097
Jeff Brown36c4db82014-09-19 12:05:31 -07006098 mWindowManagerDrawComplete = true;
Jeff Brown36c4db82014-09-19 12:05:31 -07006099 }
Jeff Brown3ee549c2014-09-22 20:14:39 -07006100
6101 finishScreenTurningOn();
Jeff Brownc38c9be2012-10-04 13:16:19 -07006102 }
6103
Craig Mautner8a0da012014-05-31 15:13:37 -07006104 private void finishScreenTurningOn() {
Stefan Kuhne9326dc12015-06-12 09:25:32 -10006105 synchronized (mLock) {
6106 // We have just finished drawing screen content. Since the orientation listener
6107 // gets only installed when all windows are drawn, we try to install it again.
6108 updateOrientationListenerLp();
6109 }
Jeff Brown3ee549c2014-09-22 20:14:39 -07006110 final ScreenOnListener listener;
6111 final boolean enableScreen;
Jeff Brown36c4db82014-09-19 12:05:31 -07006112 synchronized (mLock) {
Jeff Brown3ee549c2014-09-22 20:14:39 -07006113 if (DEBUG_WAKEUP) Slog.d(TAG,
6114 "finishScreenTurningOn: mAwake=" + mAwake
6115 + ", mScreenOnEarly=" + mScreenOnEarly
6116 + ", mScreenOnFully=" + mScreenOnFully
6117 + ", mKeyguardDrawComplete=" + mKeyguardDrawComplete
6118 + ", mWindowManagerDrawComplete=" + mWindowManagerDrawComplete);
6119
6120 if (mScreenOnFully || !mScreenOnEarly || !mWindowManagerDrawComplete
6121 || (mAwake && !mKeyguardDrawComplete)) {
6122 return; // spurious or not ready yet
Jeff Brown36c4db82014-09-19 12:05:31 -07006123 }
6124
Jeff Brown3ee549c2014-09-22 20:14:39 -07006125 if (DEBUG_WAKEUP) Slog.i(TAG, "Finished screen turning on...");
6126 listener = mScreenOnListener;
Craig Mautner13f6ea72014-06-23 14:57:02 -07006127 mScreenOnListener = null;
Jeff Brown3ee549c2014-09-22 20:14:39 -07006128 mScreenOnFully = true;
6129
6130 // Remember the first time we draw the keyguard so we know when we're done with
6131 // the main part of booting and can enable the screen and hide boot messages.
6132 if (!mKeyguardDrawnOnce && mAwake) {
6133 mKeyguardDrawnOnce = true;
6134 enableScreen = true;
6135 if (mBootMessageNeedsHiding) {
6136 mBootMessageNeedsHiding = false;
6137 hideBootMessages();
6138 }
6139 } else {
6140 enableScreen = false;
6141 }
Jeff Brownc38c9be2012-10-04 13:16:19 -07006142 }
6143
Jeff Brown3ee549c2014-09-22 20:14:39 -07006144 if (listener != null) {
6145 listener.onScreenOn();
6146 }
Jeff Brown4fc45272012-10-10 18:28:14 -07006147
Jeff Brown3ee549c2014-09-22 20:14:39 -07006148 if (enableScreen) {
6149 try {
6150 mWindowManager.enableScreenIfNeeded();
6151 } catch (RemoteException unhandled) {
Jeff Brown36c4db82014-09-19 12:05:31 -07006152 }
Craig Mautnera631d492014-08-05 15:16:01 -07006153 }
6154 }
6155
6156 private void handleHideBootMessage() {
Jeff Brown3ee549c2014-09-22 20:14:39 -07006157 synchronized (mLock) {
6158 if (!mKeyguardDrawnOnce) {
6159 mBootMessageNeedsHiding = true;
6160 return; // keyguard hasn't drawn the first time yet, not done booting
6161 }
Craig Mautnera631d492014-08-05 15:16:01 -07006162 }
Jeff Brown3ee549c2014-09-22 20:14:39 -07006163
6164 if (mBootMsgDialog != null) {
6165 if (DEBUG_WAKEUP) Slog.d(TAG, "handleHideBootMessage: dismissing");
6166 mBootMsgDialog.dismiss();
6167 mBootMsgDialog = null;
Craig Mautnera631d492014-08-05 15:16:01 -07006168 }
Jeff Brownc38c9be2012-10-04 13:16:19 -07006169 }
6170
6171 @Override
Jeff Brown3ee549c2014-09-22 20:14:39 -07006172 public boolean isScreenOn() {
6173 return mScreenOnFully;
Dianne Hackborn08743722009-12-21 12:16:51 -08006174 }
Jeff Brownc38c9be2012-10-04 13:16:19 -07006175
Dianne Hackborn08743722009-12-21 12:16:51 -08006176 /** {@inheritDoc} */
Jose Lima9546b202014-07-02 17:21:51 -07006177 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006178 public void enableKeyguard(boolean enabled) {
Jim Miller5ecd8112013-01-09 18:50:26 -08006179 if (mKeyguardDelegate != null) {
6180 mKeyguardDelegate.setKeyguardEnabled(enabled);
Mike Lockwood3a74bd32011-08-12 13:55:22 -07006181 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006182 }
6183
6184 /** {@inheritDoc} */
Jose Lima9546b202014-07-02 17:21:51 -07006185 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006186 public void exitKeyguardSecurely(OnKeyguardExitResult callback) {
Jim Miller5ecd8112013-01-09 18:50:26 -08006187 if (mKeyguardDelegate != null) {
6188 mKeyguardDelegate.verifyUnlock(callback);
Mike Lockwood3a74bd32011-08-12 13:55:22 -07006189 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006190 }
6191
Jim Millerab954542014-10-10 18:21:49 -07006192 private boolean isKeyguardShowingAndNotOccluded() {
Jim Miller5ecd8112013-01-09 18:50:26 -08006193 if (mKeyguardDelegate == null) return false;
Jim Millerab954542014-10-10 18:21:49 -07006194 return mKeyguardDelegate.isShowing() && !mKeyguardOccluded;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006195 }
6196
Mike Lockwood520d8bc2011-02-18 13:23:13 -05006197 /** {@inheritDoc} */
Jose Lima9546b202014-07-02 17:21:51 -07006198 @Override
Mike Lockwood520d8bc2011-02-18 13:23:13 -05006199 public boolean isKeyguardLocked() {
6200 return keyguardOn();
6201 }
6202
6203 /** {@inheritDoc} */
Jose Lima9546b202014-07-02 17:21:51 -07006204 @Override
Mike Lockwood520d8bc2011-02-18 13:23:13 -05006205 public boolean isKeyguardSecure() {
Jim Miller5ecd8112013-01-09 18:50:26 -08006206 if (mKeyguardDelegate == null) return false;
6207 return mKeyguardDelegate.isSecure();
Mike Lockwood520d8bc2011-02-18 13:23:13 -05006208 }
6209
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006210 /** {@inheritDoc} */
Jose Lima9546b202014-07-02 17:21:51 -07006211 @Override
Adrian Roos461829d2015-06-03 14:41:18 -07006212 public boolean isKeyguardShowingOrOccluded() {
6213 return mKeyguardDelegate == null ? false : mKeyguardDelegate.isShowing();
6214 }
6215
6216 /** {@inheritDoc} */
6217 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006218 public boolean inKeyguardRestrictedKeyInputMode() {
Jim Miller5ecd8112013-01-09 18:50:26 -08006219 if (mKeyguardDelegate == null) return false;
6220 return mKeyguardDelegate.isInputRestricted();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006221 }
6222
Jose Lima9546b202014-07-02 17:21:51 -07006223 @Override
Dianne Hackborn90c52de2011-09-23 12:57:44 -07006224 public void dismissKeyguardLw() {
RoboErik8a2cfc32014-05-16 11:19:38 -07006225 if (mKeyguardDelegate != null && mKeyguardDelegate.isShowing()) {
Craig Mautnerc0d2d0a2014-10-31 16:25:15 -07006226 if (DEBUG_KEYGUARD) Slog.d(TAG, "PWM.dismissKeyguardLw");
Daniel Sandler1ce804392012-11-07 15:07:12 -05006227 mHandler.post(new Runnable() {
Jose Lima9546b202014-07-02 17:21:51 -07006228 @Override
Daniel Sandler1ce804392012-11-07 15:07:12 -05006229 public void run() {
Jorim Jaggi8de4311c2014-08-11 22:36:20 +02006230 // ask the keyguard to prompt the user to authenticate if necessary
6231 mKeyguardDelegate.dismiss();
6232 }
6233 });
6234 }
6235 }
6236
6237 public void notifyActivityDrawnForKeyguardLw() {
6238 if (mKeyguardDelegate != null) {
6239 mHandler.post(new Runnable() {
6240 @Override
6241 public void run() {
6242 mKeyguardDelegate.onActivityDrawn();
Daniel Sandler1ce804392012-11-07 15:07:12 -05006243 }
6244 });
Dianne Hackborn90c52de2011-09-23 12:57:44 -07006245 }
6246 }
6247
Jorim Jaggicff0acb2014-03-31 16:35:15 +02006248 @Override
6249 public boolean isKeyguardDrawnLw() {
6250 synchronized (mLock) {
Jeff Brown3ee549c2014-09-22 20:14:39 -07006251 return mKeyguardDrawnOnce;
Jorim Jaggicff0acb2014-03-31 16:35:15 +02006252 }
6253 }
6254
Jorim Jaggi0d674622014-05-21 01:34:15 +02006255 @Override
Jorim Jaggie29b2db2014-05-30 23:17:03 +02006256 public void startKeyguardExitAnimation(long startTime, long fadeoutDuration) {
Jorim Jaggi0d674622014-05-21 01:34:15 +02006257 if (mKeyguardDelegate != null) {
Craig Mautnerc0d2d0a2014-10-31 16:25:15 -07006258 if (DEBUG_KEYGUARD) Slog.d(TAG, "PWM.startKeyguardExitAnimation");
Jorim Jaggie29b2db2014-05-30 23:17:03 +02006259 mKeyguardDelegate.startKeyguardExitAnimation(startTime, fadeoutDuration);
Jorim Jaggi0d674622014-05-21 01:34:15 +02006260 }
6261 }
6262
Jorim Jaggi737af722015-12-31 10:42:27 +01006263 @Override
6264 public void getStableInsetsLw(int displayRotation, int displayWidth, int displayHeight,
6265 Rect outInsets) {
6266 outInsets.setEmpty();
Jorim Jaggi82c9dc92016-02-05 15:10:33 -08006267
6268 // Navigation bar and status bar.
6269 getNonDecorInsetsLw(displayRotation, displayWidth, displayHeight, outInsets);
Jorim Jaggi737af722015-12-31 10:42:27 +01006270 if (mStatusBar != null) {
6271 outInsets.top = mStatusBarHeight;
6272 }
Jorim Jaggi82c9dc92016-02-05 15:10:33 -08006273 }
6274
6275 @Override
6276 public void getNonDecorInsetsLw(int displayRotation, int displayWidth, int displayHeight,
6277 Rect outInsets) {
6278 outInsets.setEmpty();
6279
6280 // Only navigation bar
Jorim Jaggi737af722015-12-31 10:42:27 +01006281 if (mNavigationBar != null) {
6282 if (isNavigationBarOnBottom(displayWidth, displayHeight)) {
6283 outInsets.bottom = getNavigationBarHeight(displayRotation, mUiMode);
6284 } else {
6285 outInsets.right = getNavigationBarWidth(displayRotation, mUiMode);
6286 }
6287 }
6288 }
6289
Jorim Jaggi5060bd82016-02-19 17:12:19 -08006290 @Override
Jorim Jaggi0ffd49c2016-02-12 15:04:21 -08006291 public boolean isNavBarForcedShownLw(WindowState windowState) {
6292 return mForceShowSystemBars
6293 && !windowState.getFrameLw().equals(windowState.getDisplayFrameLw());
6294 }
6295
6296 @Override
Jorim Jaggi5060bd82016-02-19 17:12:19 -08006297 public boolean isDockSideAllowed(int dockSide) {
6298
6299 // We do not allow all dock sides at which the navigation bar touches the docked stack.
6300 if (!mNavigationBarCanMove) {
6301 return dockSide == DOCKED_TOP || dockSide == DOCKED_LEFT || dockSide == DOCKED_RIGHT;
6302 } else {
6303 return dockSide == DOCKED_TOP || dockSide == DOCKED_LEFT;
6304 }
6305 }
6306
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006307 void sendCloseSystemWindows() {
Jorim Jaggib10e33f2015-02-04 21:57:40 +01006308 PhoneWindow.sendCloseSystemWindows(mContext, null);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006309 }
6310
6311 void sendCloseSystemWindows(String reason) {
Jorim Jaggib10e33f2015-02-04 21:57:40 +01006312 PhoneWindow.sendCloseSystemWindows(mContext, reason);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006313 }
Mitsuru Oshima831d0d92009-06-16 18:27:18 -07006314
Jeff Brown01a98dd2011-09-20 15:08:29 -07006315 @Override
6316 public int rotationForOrientationLw(int orientation, int lastRotation) {
Daniel Sandler2ed6ad62011-02-22 14:54:17 -05006317 if (false) {
6318 Slog.v(TAG, "rotationForOrientationLw(orient="
6319 + orientation + ", last=" + lastRotation
6320 + "); user=" + mUserRotation + " "
6321 + ((mUserRotationMode == WindowManagerPolicy.USER_ROTATION_LOCKED)
6322 ? "USER_ROTATION_LOCKED" : "")
6323 );
6324 }
6325
Craig Mautner46ac6fa2013-08-01 10:06:34 -07006326 if (mForceDefaultOrientation) {
6327 return Surface.ROTATION_0;
6328 }
6329
The Android Open Source Project0727d222009-03-11 12:11:58 -07006330 synchronized (mLock) {
Jeff Brownc0347aa2011-09-23 17:26:09 -07006331 int sensorRotation = mOrientationListener.getProposedRotation(); // may be -1
6332 if (sensorRotation < 0) {
Jeff Brown0f862b42012-09-27 21:11:01 -07006333 sensorRotation = lastRotation;
Jeff Brownc0347aa2011-09-23 17:26:09 -07006334 }
Jeff Brown01a98dd2011-09-20 15:08:29 -07006335
Jeff Browndec6cf42011-11-15 14:08:20 -08006336 final int preferredRotation;
Jeff Brown2e7760e2012-04-11 15:14:55 -07006337 if (mLidState == LID_OPEN && mLidOpenRotation >= 0) {
Jeff Brown01a98dd2011-09-20 15:08:29 -07006338 // Ignore sensor when lid switch is open and rotation is forced.
6339 preferredRotation = mLidOpenRotation;
6340 } else if (mDockMode == Intent.EXTRA_DOCK_STATE_CAR
Jeff Brownc0347aa2011-09-23 17:26:09 -07006341 && (mCarDockEnablesAccelerometer || mCarDockRotation >= 0)) {
Jeff Brown01a98dd2011-09-20 15:08:29 -07006342 // Ignore sensor when in car dock unless explicitly enabled.
6343 // This case can override the behavior of NOSENSOR, and can also
6344 // enable 180 degree rotation while docked.
Jeff Brownc0347aa2011-09-23 17:26:09 -07006345 preferredRotation = mCarDockEnablesAccelerometer
Jeff Brown01a98dd2011-09-20 15:08:29 -07006346 ? sensorRotation : mCarDockRotation;
Jeff Brown1a693182011-11-08 14:44:16 -08006347 } else if ((mDockMode == Intent.EXTRA_DOCK_STATE_DESK
6348 || mDockMode == Intent.EXTRA_DOCK_STATE_LE_DESK
6349 || mDockMode == Intent.EXTRA_DOCK_STATE_HE_DESK)
Jeff Brownc0347aa2011-09-23 17:26:09 -07006350 && (mDeskDockEnablesAccelerometer || mDeskDockRotation >= 0)) {
Jeff Brown01a98dd2011-09-20 15:08:29 -07006351 // Ignore sensor when in desk 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 = mDeskDockEnablesAccelerometer
Jeff Brown01a98dd2011-09-20 15:08:29 -07006355 ? sensorRotation : mDeskDockRotation;
Jeff Brownc82c89ed2013-04-17 17:18:15 -07006356 } else if (mHdmiPlugged && mDemoHdmiRotationLock) {
6357 // Ignore sensor when plugged into HDMI when demo HDMI rotation lock enabled.
Jeff Browneb3e4b92011-12-06 19:54:24 -08006358 // Note that the dock orientation overrides the HDMI orientation.
Jeff Brownc82c89ed2013-04-17 17:18:15 -07006359 preferredRotation = mDemoHdmiRotation;
6360 } else if (mHdmiPlugged && mDockMode == Intent.EXTRA_DOCK_STATE_UNDOCKED
6361 && mUndockedHdmiRotation >= 0) {
6362 // Ignore sensor when plugged into HDMI and an undocked orientation has
6363 // been specified in the configuration (only for legacy devices without
6364 // full multi-display support).
6365 // Note that the dock orientation overrides the HDMI orientation.
6366 preferredRotation = mUndockedHdmiRotation;
Chong Zhangae6119ff2014-11-11 18:54:39 -08006367 } else if (mDemoRotationLock) {
6368 // Ignore sensor when demo rotation lock is enabled.
6369 // Note that the dock orientation and HDMI rotation lock override this.
6370 preferredRotation = mDemoRotation;
Dianne Hackbornb9ec1ac2013-04-10 17:34:25 -07006371 } else if (orientation == ActivityInfo.SCREEN_ORIENTATION_LOCKED) {
6372 // Application just wants to remain locked in the last rotation.
6373 preferredRotation = lastRotation;
Jeff Brownbcdfc622014-03-06 19:13:04 -08006374 } else if (!mSupportAutoRotation) {
6375 // If we don't support auto-rotation then bail out here and ignore
6376 // the sensor and any rotation lock settings.
6377 preferredRotation = -1;
Jeff Brown207673cd2012-06-05 17:47:11 -07006378 } else if ((mUserRotationMode == WindowManagerPolicy.USER_ROTATION_FREE
Jeff Brown01a98dd2011-09-20 15:08:29 -07006379 && (orientation == ActivityInfo.SCREEN_ORIENTATION_USER
Dianne Hackbornb9ec1ac2013-04-10 17:34:25 -07006380 || orientation == ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED
6381 || orientation == ActivityInfo.SCREEN_ORIENTATION_USER_LANDSCAPE
6382 || orientation == ActivityInfo.SCREEN_ORIENTATION_USER_PORTRAIT
6383 || orientation == ActivityInfo.SCREEN_ORIENTATION_FULL_USER))
Jeff Brown01a98dd2011-09-20 15:08:29 -07006384 || orientation == ActivityInfo.SCREEN_ORIENTATION_SENSOR
6385 || orientation == ActivityInfo.SCREEN_ORIENTATION_FULL_SENSOR
6386 || orientation == ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE
6387 || orientation == ActivityInfo.SCREEN_ORIENTATION_SENSOR_PORTRAIT) {
6388 // Otherwise, use sensor only if requested by the application or enabled
6389 // by default for USER or UNSPECIFIED modes. Does not apply to NOSENSOR.
Jeff Brownd3187e32011-09-21 19:26:44 -07006390 if (mAllowAllRotations < 0) {
6391 // Can't read this during init() because the context doesn't
6392 // have display metrics at that time so we cannot determine
6393 // tablet vs. phone then.
6394 mAllowAllRotations = mContext.getResources().getBoolean(
6395 com.android.internal.R.bool.config_allowAllRotations) ? 1 : 0;
6396 }
Jeff Brown01a98dd2011-09-20 15:08:29 -07006397 if (sensorRotation != Surface.ROTATION_180
Jeff Brownd3187e32011-09-21 19:26:44 -07006398 || mAllowAllRotations == 1
Dianne Hackbornb9ec1ac2013-04-10 17:34:25 -07006399 || orientation == ActivityInfo.SCREEN_ORIENTATION_FULL_SENSOR
6400 || orientation == ActivityInfo.SCREEN_ORIENTATION_FULL_USER) {
Jeff Brown01a98dd2011-09-20 15:08:29 -07006401 preferredRotation = sensorRotation;
6402 } else {
6403 preferredRotation = lastRotation;
6404 }
Jeff Brown207673cd2012-06-05 17:47:11 -07006405 } else if (mUserRotationMode == WindowManagerPolicy.USER_ROTATION_LOCKED
6406 && orientation != ActivityInfo.SCREEN_ORIENTATION_NOSENSOR) {
6407 // Apply rotation lock. Does not apply to NOSENSOR.
6408 // The idea is that the user rotation expresses a weak preference for the direction
6409 // of gravity and as NOSENSOR is never affected by gravity, then neither should
6410 // NOSENSOR be affected by rotation lock (although it will be affected by docks).
Jeff Brown4dfce202011-10-05 12:00:10 -07006411 preferredRotation = mUserRotation;
Jeff Browndec6cf42011-11-15 14:08:20 -08006412 } else {
6413 // No overriding preference.
6414 // We will do exactly what the application asked us to do.
6415 preferredRotation = -1;
Jeff Brown01a98dd2011-09-20 15:08:29 -07006416 }
6417
Dianne Hackborne5439f22010-10-02 16:53:50 -07006418 switch (orientation) {
6419 case ActivityInfo.SCREEN_ORIENTATION_PORTRAIT:
Jeff Browndec6cf42011-11-15 14:08:20 -08006420 // Return portrait unless overridden.
6421 if (isAnyPortrait(preferredRotation)) {
6422 return preferredRotation;
6423 }
Dianne Hackborne5439f22010-10-02 16:53:50 -07006424 return mPortraitRotation;
Dianne Hackborne5439f22010-10-02 16:53:50 -07006425
Jeff Brown01a98dd2011-09-20 15:08:29 -07006426 case ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE:
Jeff Browndec6cf42011-11-15 14:08:20 -08006427 // Return landscape unless overridden.
6428 if (isLandscapeOrSeascape(preferredRotation)) {
6429 return preferredRotation;
6430 }
Jeff Brown01a98dd2011-09-20 15:08:29 -07006431 return mLandscapeRotation;
6432
6433 case ActivityInfo.SCREEN_ORIENTATION_REVERSE_PORTRAIT:
Jeff Browndec6cf42011-11-15 14:08:20 -08006434 // Return reverse portrait unless overridden.
6435 if (isAnyPortrait(preferredRotation)) {
6436 return preferredRotation;
6437 }
Jeff Brown01a98dd2011-09-20 15:08:29 -07006438 return mUpsideDownRotation;
6439
6440 case ActivityInfo.SCREEN_ORIENTATION_REVERSE_LANDSCAPE:
Jeff Browndec6cf42011-11-15 14:08:20 -08006441 // Return seascape unless overridden.
6442 if (isLandscapeOrSeascape(preferredRotation)) {
6443 return preferredRotation;
6444 }
Jeff Brown01a98dd2011-09-20 15:08:29 -07006445 return mSeascapeRotation;
6446
6447 case ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE:
Dianne Hackbornb9ec1ac2013-04-10 17:34:25 -07006448 case ActivityInfo.SCREEN_ORIENTATION_USER_LANDSCAPE:
Jeff Brown01a98dd2011-09-20 15:08:29 -07006449 // Return either landscape rotation.
6450 if (isLandscapeOrSeascape(preferredRotation)) {
6451 return preferredRotation;
6452 }
6453 if (isLandscapeOrSeascape(lastRotation)) {
Jeff Brown4519f072011-01-23 13:16:01 -08006454 return lastRotation;
6455 }
Jeff Brown01a98dd2011-09-20 15:08:29 -07006456 return mLandscapeRotation;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006457
Jeff Brown01a98dd2011-09-20 15:08:29 -07006458 case ActivityInfo.SCREEN_ORIENTATION_SENSOR_PORTRAIT:
Dianne Hackbornb9ec1ac2013-04-10 17:34:25 -07006459 case ActivityInfo.SCREEN_ORIENTATION_USER_PORTRAIT:
Jeff Brown01a98dd2011-09-20 15:08:29 -07006460 // Return either portrait rotation.
6461 if (isAnyPortrait(preferredRotation)) {
6462 return preferredRotation;
6463 }
6464 if (isAnyPortrait(lastRotation)) {
6465 return lastRotation;
6466 }
6467 return mPortraitRotation;
6468
6469 default:
Jeff Brown4dfce202011-10-05 12:00:10 -07006470 // For USER, UNSPECIFIED, NOSENSOR, SENSOR and FULL_SENSOR,
6471 // just return the preferred orientation we already calculated.
Jeff Brown01a98dd2011-09-20 15:08:29 -07006472 if (preferredRotation >= 0) {
6473 return preferredRotation;
6474 }
Dianne Hackborndacea8c2011-04-21 17:26:39 -07006475 return Surface.ROTATION_0;
Daniel Sandlere7e5ac22011-02-22 16:10:21 -05006476 }
6477 }
Steve Howarda7bfe6a2010-09-23 16:47:49 -07006478 }
6479
Jeff Brown01a98dd2011-09-20 15:08:29 -07006480 @Override
6481 public boolean rotationHasCompatibleMetricsLw(int orientation, int rotation) {
6482 switch (orientation) {
6483 case ActivityInfo.SCREEN_ORIENTATION_PORTRAIT:
6484 case ActivityInfo.SCREEN_ORIENTATION_REVERSE_PORTRAIT:
6485 case ActivityInfo.SCREEN_ORIENTATION_SENSOR_PORTRAIT:
6486 return isAnyPortrait(rotation);
6487
6488 case ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE:
6489 case ActivityInfo.SCREEN_ORIENTATION_REVERSE_LANDSCAPE:
6490 case ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE:
6491 return isLandscapeOrSeascape(rotation);
6492
6493 default:
6494 return true;
6495 }
Steve Howarda7bfe6a2010-09-23 16:47:49 -07006496 }
6497
Jeff Brownc0347aa2011-09-23 17:26:09 -07006498 @Override
6499 public void setRotationLw(int rotation) {
6500 mOrientationListener.setCurrentRotation(rotation);
6501 }
6502
Jeff Brown01a98dd2011-09-20 15:08:29 -07006503 private boolean isLandscapeOrSeascape(int rotation) {
6504 return rotation == mLandscapeRotation || rotation == mSeascapeRotation;
Dianne Hackborne5439f22010-10-02 16:53:50 -07006505 }
6506
Jeff Brown01a98dd2011-09-20 15:08:29 -07006507 private boolean isAnyPortrait(int rotation) {
6508 return rotation == mPortraitRotation || rotation == mUpsideDownRotation;
Dianne Hackborne5439f22010-10-02 16:53:50 -07006509 }
6510
Jose Lima9546b202014-07-02 17:21:51 -07006511 @Override
Svetoslav Ganov80943d82013-01-02 10:25:37 -08006512 public int getUserRotationMode() {
6513 return Settings.System.getIntForUser(mContext.getContentResolver(),
Brett Chabot7e55c402013-05-16 19:38:08 -07006514 Settings.System.ACCELEROMETER_ROTATION, 0, UserHandle.USER_CURRENT) != 0 ?
6515 WindowManagerPolicy.USER_ROTATION_FREE :
6516 WindowManagerPolicy.USER_ROTATION_LOCKED;
Svetoslav Ganov80943d82013-01-02 10:25:37 -08006517 }
Daniel Sandlerb73617d2010-08-17 00:41:00 -04006518
6519 // User rotation: to be used when all else fails in assigning an orientation to the device
Jose Lima9546b202014-07-02 17:21:51 -07006520 @Override
Daniel Sandlerb73617d2010-08-17 00:41:00 -04006521 public void setUserRotationMode(int mode, int rot) {
6522 ContentResolver res = mContext.getContentResolver();
Daniel Sandler2ed6ad62011-02-22 14:54:17 -05006523
6524 // mUserRotationMode and mUserRotation will be assigned by the content observer
Daniel Sandlerb73617d2010-08-17 00:41:00 -04006525 if (mode == WindowManagerPolicy.USER_ROTATION_LOCKED) {
Christopher Tate5e08af02012-09-21 17:17:22 -07006526 Settings.System.putIntForUser(res,
Daniel Sandlerb73617d2010-08-17 00:41:00 -04006527 Settings.System.USER_ROTATION,
Christopher Tate5e08af02012-09-21 17:17:22 -07006528 rot,
6529 UserHandle.USER_CURRENT);
6530 Settings.System.putIntForUser(res,
Daniel Sandler2ed6ad62011-02-22 14:54:17 -05006531 Settings.System.ACCELEROMETER_ROTATION,
Christopher Tate5e08af02012-09-21 17:17:22 -07006532 0,
6533 UserHandle.USER_CURRENT);
Daniel Sandlerb73617d2010-08-17 00:41:00 -04006534 } else {
Christopher Tate5e08af02012-09-21 17:17:22 -07006535 Settings.System.putIntForUser(res,
Daniel Sandlerb73617d2010-08-17 00:41:00 -04006536 Settings.System.ACCELEROMETER_ROTATION,
Christopher Tate5e08af02012-09-21 17:17:22 -07006537 1,
6538 UserHandle.USER_CURRENT);
Daniel Sandlerb73617d2010-08-17 00:41:00 -04006539 }
6540 }
6541
Jose Lima9546b202014-07-02 17:21:51 -07006542 @Override
Jeff Brownac143512012-04-05 18:57:33 -07006543 public void setSafeMode(boolean safeMode) {
6544 mSafeMode = safeMode;
6545 performHapticFeedbackLw(null, safeMode
6546 ? HapticFeedbackConstants.SAFE_MODE_ENABLED
6547 : HapticFeedbackConstants.SAFE_MODE_DISABLED, true);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006548 }
Craig Mautnereda67292013-04-28 13:50:14 -07006549
Dianne Hackborn181ceb52009-08-27 22:16:40 -07006550 static long[] getLongIntArray(Resources r, int resid) {
6551 int[] ar = r.getIntArray(resid);
6552 if (ar == null) {
6553 return null;
6554 }
6555 long[] out = new long[ar.length];
6556 for (int i=0; i<ar.length; i++) {
6557 out[i] = ar[i];
6558 }
6559 return out;
6560 }
Craig Mautnereda67292013-04-28 13:50:14 -07006561
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006562 /** {@inheritDoc} */
Craig Mautnereda67292013-04-28 13:50:14 -07006563 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006564 public void systemReady() {
Jim Millerab954542014-10-10 18:21:49 -07006565 mKeyguardDelegate = new KeyguardServiceDelegate(mContext);
Mike Lockwooded8902d2013-11-15 11:01:47 -08006566 mKeyguardDelegate.onSystemReady();
6567
Michael Wright3818c922014-09-02 13:59:07 -07006568 readCameraLensCoverState();
Jeff Brown4f5fa282014-06-12 19:19:15 -07006569 updateUiMode();
Adrian Roos3542f7d2015-07-13 15:57:53 -07006570 boolean bindKeyguardNow;
Dianne Hackbornb1a79802009-09-29 15:18:31 -07006571 synchronized (mLock) {
6572 updateOrientationListenerLp();
Dianne Hackbornc777e072010-02-12 13:07:59 -08006573 mSystemReady = true;
6574 mHandler.post(new Runnable() {
Craig Mautnereda67292013-04-28 13:50:14 -07006575 @Override
Dianne Hackbornc777e072010-02-12 13:07:59 -08006576 public void run() {
6577 updateSettings();
6578 }
6579 });
Adrian Roos3542f7d2015-07-13 15:57:53 -07006580
6581 bindKeyguardNow = mDeferBindKeyguard;
6582 if (bindKeyguardNow) {
6583 // systemBooted ran but wasn't able to bind to the Keyguard, we'll do it now.
6584 mDeferBindKeyguard = false;
6585 }
6586 }
6587
6588 if (bindKeyguardNow) {
6589 mKeyguardDelegate.bindService(mContext);
6590 mKeyguardDelegate.onBootCompleted();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006591 }
Michael Wrighta4d22d72015-09-16 23:19:26 +01006592 mSystemGestures.systemReady();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006593 }
Dianne Hackborn661cd522011-08-22 00:26:20 -07006594
Dianne Hackbornba24e4d2011-09-01 11:17:06 -07006595 /** {@inheritDoc} */
Jose Lima9546b202014-07-02 17:21:51 -07006596 @Override
Dianne Hackbornba24e4d2011-09-01 11:17:06 -07006597 public void systemBooted() {
Adrian Roos3542f7d2015-07-13 15:57:53 -07006598 boolean bindKeyguardNow = false;
6599 synchronized (mLock) {
6600 // Time to bind Keyguard; take care to only bind it once, either here if ready or
6601 // in systemReady if not.
6602 if (mKeyguardDelegate != null) {
6603 bindKeyguardNow = true;
6604 } else {
6605 // Because mKeyguardDelegate is null, we know that the synchronized block in
6606 // systemReady didn't run yet and setting this will actually have an effect.
6607 mDeferBindKeyguard = true;
6608 }
6609 }
6610 if (bindKeyguardNow) {
Jason Monk5eeebf52014-09-26 12:36:51 -04006611 mKeyguardDelegate.bindService(mContext);
Jim Millere5f910a2013-10-16 18:15:46 -07006612 mKeyguardDelegate.onBootCompleted();
6613 }
Dianne Hackbornba24e4d2011-09-01 11:17:06 -07006614 synchronized (mLock) {
6615 mSystemBooted = true;
6616 }
Jeff Brown416c49c2015-05-26 19:50:18 -07006617 startedWakingUp();
Jeff Brown36c4db82014-09-19 12:05:31 -07006618 screenTurningOn(null);
Jorim Jaggic0496072015-08-19 15:14:52 -07006619 screenTurnedOn();
Dianne Hackbornba24e4d2011-09-01 11:17:06 -07006620 }
6621
Dianne Hackborn661cd522011-08-22 00:26:20 -07006622 ProgressDialog mBootMsgDialog = null;
6623
6624 /** {@inheritDoc} */
Jose Lima9546b202014-07-02 17:21:51 -07006625 @Override
Dianne Hackborn661cd522011-08-22 00:26:20 -07006626 public void showBootMessage(final CharSequence msg, final boolean always) {
6627 mHandler.post(new Runnable() {
6628 @Override public void run() {
6629 if (mBootMsgDialog == null) {
Craig Stout4c0cb8a2014-04-04 13:03:10 -07006630 int theme;
Jaewan Kim49117872016-01-19 17:24:08 +09006631 if (mContext.getPackageManager().hasSystemFeature(FEATURE_WATCH)) {
Craig Stout4c0cb8a2014-04-04 13:03:10 -07006632 theme = com.android.internal.R.style.Theme_Micro_Dialog_Alert;
Jaewan Kim49117872016-01-19 17:24:08 +09006633 } else if (mContext.getPackageManager().hasSystemFeature(FEATURE_TELEVISION)) {
Craig Stout4c0cb8a2014-04-04 13:03:10 -07006634 theme = com.android.internal.R.style.Theme_Leanback_Dialog_Alert;
6635 } else {
6636 theme = 0;
6637 }
Vinod Krishnanfa8fc412014-04-18 14:35:53 -07006638
6639 mBootMsgDialog = new ProgressDialog(mContext, theme) {
Dianne Hackborn295e3c22011-08-25 13:19:08 -07006640 // This dialog will consume all events coming in to
6641 // it, to avoid it trying to do things too early in boot.
6642 @Override public boolean dispatchKeyEvent(KeyEvent event) {
6643 return true;
6644 }
6645 @Override public boolean dispatchKeyShortcutEvent(KeyEvent event) {
6646 return true;
6647 }
6648 @Override public boolean dispatchTouchEvent(MotionEvent ev) {
6649 return true;
6650 }
6651 @Override public boolean dispatchTrackballEvent(MotionEvent ev) {
6652 return true;
6653 }
6654 @Override public boolean dispatchGenericMotionEvent(MotionEvent ev) {
6655 return true;
6656 }
6657 @Override public boolean dispatchPopulateAccessibilityEvent(
6658 AccessibilityEvent event) {
6659 return true;
6660 }
6661 };
Jeff Hao9f60c082014-10-28 18:51:07 -07006662 if (mContext.getPackageManager().isUpgrade()) {
6663 mBootMsgDialog.setTitle(R.string.android_upgrading_title);
6664 } else {
6665 mBootMsgDialog.setTitle(R.string.android_start_title);
6666 }
Dianne Hackborn661cd522011-08-22 00:26:20 -07006667 mBootMsgDialog.setProgressStyle(ProgressDialog.STYLE_SPINNER);
6668 mBootMsgDialog.setIndeterminate(true);
6669 mBootMsgDialog.getWindow().setType(
Dianne Hackborn29aae6f2011-08-18 18:30:09 -07006670 WindowManager.LayoutParams.TYPE_BOOT_PROGRESS);
Dianne Hackborn661cd522011-08-22 00:26:20 -07006671 mBootMsgDialog.getWindow().addFlags(
6672 WindowManager.LayoutParams.FLAG_DIM_BEHIND
6673 | WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN);
6674 mBootMsgDialog.getWindow().setDimAmount(1);
Dianne Hackbornd9efb952011-12-07 14:56:51 -08006675 WindowManager.LayoutParams lp = mBootMsgDialog.getWindow().getAttributes();
6676 lp.screenOrientation = ActivityInfo.SCREEN_ORIENTATION_NOSENSOR;
6677 mBootMsgDialog.getWindow().setAttributes(lp);
Dianne Hackborn661cd522011-08-22 00:26:20 -07006678 mBootMsgDialog.setCancelable(false);
6679 mBootMsgDialog.show();
6680 }
6681 mBootMsgDialog.setMessage(msg);
6682 }
6683 });
6684 }
6685
6686 /** {@inheritDoc} */
Jose Lima9546b202014-07-02 17:21:51 -07006687 @Override
Dianne Hackborn661cd522011-08-22 00:26:20 -07006688 public void hideBootMessages() {
Craig Mautnera631d492014-08-05 15:16:01 -07006689 mHandler.sendEmptyMessage(MSG_HIDE_BOOT_MESSAGE);
Dianne Hackborn661cd522011-08-22 00:26:20 -07006690 }
6691
Mike Lockwood28569302010-01-28 11:54:40 -05006692 /** {@inheritDoc} */
Jose Lima9546b202014-07-02 17:21:51 -07006693 @Override
Mike Lockwood28569302010-01-28 11:54:40 -05006694 public void userActivity() {
Dianne Hackborndf89e652011-10-06 22:35:11 -07006695 // ***************************************
6696 // NOTE NOTE NOTE NOTE NOTE NOTE NOTE NOTE
6697 // ***************************************
6698 // THIS IS CALLED FROM DEEP IN THE POWER MANAGER
6699 // WITH ITS LOCKS HELD.
6700 //
6701 // This code must be VERY careful about the locks
6702 // it acquires.
6703 // In fact, the current code acquires way too many,
6704 // and probably has lurking deadlocks.
6705
Mike Lockwood28569302010-01-28 11:54:40 -05006706 synchronized (mScreenLockTimeout) {
6707 if (mLockScreenTimerActive) {
6708 // reset the timer
6709 mHandler.removeCallbacks(mScreenLockTimeout);
6710 mHandler.postDelayed(mScreenLockTimeout, mLockScreenTimeout);
6711 }
6712 }
Daniel Sandler0601eb72011-04-13 01:01:32 -04006713 }
6714
Adam Cohenf7522022012-10-03 20:03:18 -07006715 class ScreenLockTimeout implements Runnable {
6716 Bundle options;
6717
6718 @Override
Mike Lockwood28569302010-01-28 11:54:40 -05006719 public void run() {
6720 synchronized (this) {
6721 if (localLOGV) Log.v(TAG, "mScreenLockTimeout activating keyguard");
Jim Miller5ecd8112013-01-09 18:50:26 -08006722 if (mKeyguardDelegate != null) {
6723 mKeyguardDelegate.doKeyguardTimeout(options);
Mike Lockwood3a74bd32011-08-12 13:55:22 -07006724 }
Mike Lockwood28569302010-01-28 11:54:40 -05006725 mLockScreenTimerActive = false;
Adam Cohenf7522022012-10-03 20:03:18 -07006726 options = null;
Mike Lockwood28569302010-01-28 11:54:40 -05006727 }
6728 }
Mike Lockwood28569302010-01-28 11:54:40 -05006729
Adam Cohenf7522022012-10-03 20:03:18 -07006730 public void setLockOptions(Bundle options) {
6731 this.options = options;
6732 }
6733 }
6734
6735 ScreenLockTimeout mScreenLockTimeout = new ScreenLockTimeout();
6736
Jose Lima9546b202014-07-02 17:21:51 -07006737 @Override
Adam Cohenf7522022012-10-03 20:03:18 -07006738 public void lockNow(Bundle options) {
Jim Miller93c518e2012-01-17 15:55:31 -08006739 mContext.enforceCallingOrSelfPermission(android.Manifest.permission.DEVICE_POWER, null);
6740 mHandler.removeCallbacks(mScreenLockTimeout);
Adam Cohenf7522022012-10-03 20:03:18 -07006741 if (options != null) {
6742 // In case multiple calls are made to lockNow, we don't wipe out the options
6743 // until the runnable actually executes.
6744 mScreenLockTimeout.setLockOptions(options);
6745 }
Jim Miller93c518e2012-01-17 15:55:31 -08006746 mHandler.post(mScreenLockTimeout);
6747 }
6748
Mike Lockwood28569302010-01-28 11:54:40 -05006749 private void updateLockScreenTimeout() {
6750 synchronized (mScreenLockTimeout) {
Jeff Brown3ee549c2014-09-22 20:14:39 -07006751 boolean enable = (mAllowLockscreenWhenOn && mAwake &&
Jim Miller5ecd8112013-01-09 18:50:26 -08006752 mKeyguardDelegate != null && mKeyguardDelegate.isSecure());
Mike Lockwood28569302010-01-28 11:54:40 -05006753 if (mLockScreenTimerActive != enable) {
6754 if (enable) {
6755 if (localLOGV) Log.v(TAG, "setting lockscreen timer");
Jim Miller2967f482016-01-07 15:05:32 -08006756 mHandler.removeCallbacks(mScreenLockTimeout); // remove any pending requests
Mike Lockwood28569302010-01-28 11:54:40 -05006757 mHandler.postDelayed(mScreenLockTimeout, mLockScreenTimeout);
6758 } else {
6759 if (localLOGV) Log.v(TAG, "clearing lockscreen timer");
6760 mHandler.removeCallbacks(mScreenLockTimeout);
6761 }
6762 mLockScreenTimerActive = enable;
6763 }
6764 }
6765 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006766
Jeff Brown061ea992015-04-17 19:55:47 -07006767 private void updateDreamingSleepToken(boolean acquire) {
6768 if (acquire) {
6769 if (mDreamingSleepToken == null) {
6770 mDreamingSleepToken = mActivityManagerInternal.acquireSleepToken("Dream");
6771 }
6772 } else {
6773 if (mDreamingSleepToken != null) {
6774 mDreamingSleepToken.release();
Jeff Brown48d1b142015-06-10 16:36:03 -07006775 mDreamingSleepToken = null;
6776 }
6777 }
6778 }
6779
6780 private void updateScreenOffSleepToken(boolean acquire) {
6781 if (acquire) {
6782 if (mScreenOffSleepToken == null) {
6783 mScreenOffSleepToken = mActivityManagerInternal.acquireSleepToken("ScreenOff");
6784 }
6785 } else {
6786 if (mScreenOffSleepToken != null) {
6787 mScreenOffSleepToken.release();
6788 mScreenOffSleepToken = null;
Jeff Brown061ea992015-04-17 19:55:47 -07006789 }
6790 }
6791 }
6792
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006793 /** {@inheritDoc} */
Craig Mautnereda67292013-04-28 13:50:14 -07006794 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006795 public void enableScreenAfterBoot() {
6796 readLidState();
Jeff Brownc458ce92012-04-30 14:58:40 -07006797 applyLidSwitchState();
Jeff Brown01a98dd2011-09-20 15:08:29 -07006798 updateRotation(true);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006799 }
Dianne Hackbornf54c8f92009-09-19 14:03:57 -07006800
Jeff Brownc458ce92012-04-30 14:58:40 -07006801 private void applyLidSwitchState() {
Jeff Brownc458ce92012-04-30 14:58:40 -07006802 if (mLidState == LID_CLOSED && mLidControlsSleep) {
Jeff Brown6d8fd272014-05-20 21:24:38 -07006803 mPowerManager.goToSleep(SystemClock.uptimeMillis(),
Jeff Brownc12035c2014-08-13 18:52:25 -07006804 PowerManager.GO_TO_SLEEP_REASON_LID_SWITCH,
Jeff Brown6d8fd272014-05-20 21:24:38 -07006805 PowerManager.GO_TO_SLEEP_FLAG_NO_DOZE);
Edward Savage-Jones7def60d2015-11-13 13:27:03 +01006806 } else if (mLidState == LID_CLOSED && mLidControlsScreenLock) {
6807 mWindowManagerFuncs.lockDeviceNow();
Jeff Brownc458ce92012-04-30 14:58:40 -07006808 }
Jeff Browna20dda42014-05-27 20:57:24 -07006809
6810 synchronized (mLock) {
6811 updateWakeGestureListenerLp();
6812 }
Jeff Brown01a98dd2011-09-20 15:08:29 -07006813 }
6814
Jeff Brown4f5fa282014-06-12 19:19:15 -07006815 void updateUiMode() {
6816 if (mUiModeManager == null) {
6817 mUiModeManager = IUiModeManager.Stub.asInterface(
6818 ServiceManager.getService(Context.UI_MODE_SERVICE));
6819 }
6820 try {
6821 mUiMode = mUiModeManager.getCurrentModeType();
6822 } catch (RemoteException e) {
6823 }
6824 }
6825
Jeff Brown01a98dd2011-09-20 15:08:29 -07006826 void updateRotation(boolean alwaysSendConfiguration) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006827 try {
6828 //set orientation on WindowManager
Dianne Hackbornf87d1962012-04-04 12:48:24 -07006829 mWindowManager.updateRotation(alwaysSendConfiguration, false);
6830 } catch (RemoteException e) {
6831 // Ignore
6832 }
6833 }
6834
6835 void updateRotation(boolean alwaysSendConfiguration, boolean forceRelayout) {
6836 try {
6837 //set orientation on WindowManager
6838 mWindowManager.updateRotation(alwaysSendConfiguration, forceRelayout);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006839 } catch (RemoteException e) {
6840 // Ignore
6841 }
6842 }
6843
Daniel Sandler6396c722013-04-16 20:19:09 -04006844 /**
6845 * Return an Intent to launch the currently active dock app as home. Returns
6846 * null if the standard home should be launched, which is the case if any of the following is
6847 * true:
6848 * <ul>
6849 * <li>The device is not in either car mode or desk mode
keunyounga7710492015-09-23 11:33:58 -07006850 * <li>The device is in car mode but mEnableCarDockHomeCapture is false
Daniel Sandler6396c722013-04-16 20:19:09 -04006851 * <li>The device is in desk mode but ENABLE_DESK_DOCK_HOME_CAPTURE is false
6852 * <li>The device is in car mode but there's no CAR_DOCK app with METADATA_DOCK_HOME
6853 * <li>The device is in desk mode but there's no DESK_DOCK app with METADATA_DOCK_HOME
6854 * </ul>
Craig Mautnereda67292013-04-28 13:50:14 -07006855 * @return A dock intent.
Daniel Sandler6396c722013-04-16 20:19:09 -04006856 */
6857 Intent createHomeDockIntent() {
6858 Intent intent = null;
6859
6860 // What home does is based on the mode, not the dock state. That
6861 // is, when in car mode you should be taken to car home regardless
6862 // of whether we are actually in a car dock.
6863 if (mUiMode == Configuration.UI_MODE_TYPE_CAR) {
keunyounga7710492015-09-23 11:33:58 -07006864 if (mEnableCarDockHomeCapture) {
Daniel Sandler6396c722013-04-16 20:19:09 -04006865 intent = mCarDockIntent;
6866 }
6867 } else if (mUiMode == Configuration.UI_MODE_TYPE_DESK) {
6868 if (ENABLE_DESK_DOCK_HOME_CAPTURE) {
6869 intent = mDeskDockIntent;
6870 }
Jeff Brown4f5fa282014-06-12 19:19:15 -07006871 } else if (mUiMode == Configuration.UI_MODE_TYPE_WATCH
6872 && (mDockMode == Intent.EXTRA_DOCK_STATE_DESK
6873 || mDockMode == Intent.EXTRA_DOCK_STATE_HE_DESK
6874 || mDockMode == Intent.EXTRA_DOCK_STATE_LE_DESK)) {
6875 // Always launch dock home from home when watch is docked, if it exists.
6876 intent = mDeskDockIntent;
Daniel Sandler6396c722013-04-16 20:19:09 -04006877 }
6878
6879 if (intent == null) {
6880 return null;
6881 }
6882
6883 ActivityInfo ai = null;
6884 ResolveInfo info = mContext.getPackageManager().resolveActivityAsUser(
6885 intent,
John Spurlockf56bef12013-07-09 09:51:46 -04006886 PackageManager.MATCH_DEFAULT_ONLY | PackageManager.GET_META_DATA,
Craig Mautnerd625ab22013-09-06 13:40:31 -07006887 mCurrentUserId);
Daniel Sandler6396c722013-04-16 20:19:09 -04006888 if (info != null) {
6889 ai = info.activityInfo;
6890 }
6891 if (ai != null
6892 && ai.metaData != null
6893 && ai.metaData.getBoolean(Intent.METADATA_DOCK_HOME)) {
6894 intent = new Intent(intent);
6895 intent.setClassName(ai.packageName, ai.name);
6896 return intent;
6897 }
6898
6899 return null;
6900 }
6901
Filip Gruszczynskia483a1d2015-03-17 19:06:58 +00006902 void startDockOrHome(boolean fromHomeKey, boolean awakenFromDreams) {
6903 if (awakenFromDreams) {
6904 awakenDreams();
6905 }
Daniel Sandler6396c722013-04-16 20:19:09 -04006906
6907 Intent dock = createHomeDockIntent();
6908 if (dock != null) {
6909 try {
Bryce Lee01b0c5f2015-02-05 18:24:04 -08006910 if (fromHomeKey) {
6911 dock.putExtra(WindowManagerPolicy.EXTRA_FROM_HOME_KEY, fromHomeKey);
6912 }
Bart Sears8b1c27c2015-03-18 23:51:02 +00006913 startActivityAsUser(dock, UserHandle.CURRENT);
Daniel Sandler6396c722013-04-16 20:19:09 -04006914 return;
6915 } catch (ActivityNotFoundException e) {
6916 }
6917 }
6918
Bryce Lee01b0c5f2015-02-05 18:24:04 -08006919 Intent intent;
6920
6921 if (fromHomeKey) {
6922 intent = new Intent(mHomeIntent);
6923 intent.putExtra(WindowManagerPolicy.EXTRA_FROM_HOME_KEY, fromHomeKey);
6924 } else {
6925 intent = mHomeIntent;
6926 }
6927
Bryce Lee9fc0b6f2015-03-19 21:37:45 +00006928 startActivityAsUser(intent, UserHandle.CURRENT);
Dianne Hackborn39c2d712009-09-22 11:41:31 -07006929 }
Craig Mautnereda67292013-04-28 13:50:14 -07006930
Dianne Hackborn39c2d712009-09-22 11:41:31 -07006931 /**
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006932 * goes to the home screen
6933 * @return whether it did anything
6934 */
6935 boolean goHome() {
Bart Sears8b1c27c2015-03-18 23:51:02 +00006936 if (!isUserSetupComplete()) {
6937 Slog.i(TAG, "Not going home because user setup is in progress.");
6938 return false;
6939 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006940 if (false) {
6941 // This code always brings home to the front.
Dianne Hackborn256dd3b2009-05-19 18:51:21 -07006942 try {
6943 ActivityManagerNative.getDefault().stopAppSwitches();
6944 } catch (RemoteException e) {
6945 }
Dianne Hackborn94a679d2009-07-28 17:51:07 -07006946 sendCloseSystemWindows();
Filip Gruszczynskia483a1d2015-03-17 19:06:58 +00006947 startDockOrHome(false /*fromHomeKey*/, true /* awakenFromDreams */);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006948 } else {
6949 // This code brings home to the front or, if it is already
6950 // at the front, puts the device to sleep.
6951 try {
Wink Savilled2e6a332010-02-12 12:12:06 -08006952 if (SystemProperties.getInt("persist.sys.uts-test-mode", 0) == 1) {
6953 /// Roll back EndcallBehavior as the cupcake design to pass P1 lab entry.
6954 Log.d(TAG, "UTS-TEST-MODE");
6955 } else {
6956 ActivityManagerNative.getDefault().stopAppSwitches();
6957 sendCloseSystemWindows();
Daniel Sandler6396c722013-04-16 20:19:09 -04006958 Intent dock = createHomeDockIntent();
6959 if (dock != null) {
6960 int result = ActivityManagerNative.getDefault()
6961 .startActivityAsUser(null, null, dock,
6962 dock.resolveTypeIfNeeded(mContext.getContentResolver()),
6963 null, null, 0,
6964 ActivityManager.START_FLAG_ONLY_IF_NEEDED,
Jeff Hao1b012d32014-08-20 10:35:34 -07006965 null, null, UserHandle.USER_CURRENT);
Daniel Sandler6396c722013-04-16 20:19:09 -04006966 if (result == ActivityManager.START_RETURN_INTENT_TO_CALLER) {
6967 return false;
6968 }
6969 }
Dianne Hackborn39c2d712009-09-22 11:41:31 -07006970 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006971 int result = ActivityManagerNative.getDefault()
Dianne Hackbornf265ea92013-01-31 15:00:51 -08006972 .startActivityAsUser(null, null, mHomeIntent,
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006973 mHomeIntent.resolveTypeIfNeeded(mContext.getContentResolver()),
Dianne Hackborna4972e92012-03-14 10:38:05 -07006974 null, null, 0,
6975 ActivityManager.START_FLAG_ONLY_IF_NEEDED,
Jeff Hao1b012d32014-08-20 10:35:34 -07006976 null, null, UserHandle.USER_CURRENT);
Dianne Hackborna4972e92012-03-14 10:38:05 -07006977 if (result == ActivityManager.START_RETURN_INTENT_TO_CALLER) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006978 return false;
6979 }
6980 } catch (RemoteException ex) {
6981 // bummer, the activity manager, which is in this process, is dead
6982 }
6983 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006984 return true;
6985 }
Craig Mautnereda67292013-04-28 13:50:14 -07006986
6987 @Override
The Android Open Source Project0727d222009-03-11 12:11:58 -07006988 public void setCurrentOrientationLw(int newOrientation) {
6989 synchronized (mLock) {
6990 if (newOrientation != mCurrentAppOrientation) {
6991 mCurrentAppOrientation = newOrientation;
6992 updateOrientationListenerLp();
6993 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006994 }
6995 }
Amith Yamasanic33cb712010-02-10 15:21:49 -08006996
Svetoslav Ganov7befb7d2012-09-27 16:49:23 -07006997 private void performAuditoryFeedbackForAccessibilityIfNeed() {
6998 if (!isGlobalAccessibilityGestureEnabled()) {
6999 return;
7000 }
7001 AudioManager audioManager = (AudioManager) mContext.getSystemService(
7002 Context.AUDIO_SERVICE);
7003 if (audioManager.isSilentMode()) {
7004 return;
7005 }
7006 Ringtone ringTone = RingtoneManager.getRingtone(mContext,
7007 Settings.System.DEFAULT_NOTIFICATION_URI);
7008 ringTone.setStreamType(AudioManager.STREAM_MUSIC);
7009 ringTone.play();
7010 }
Craig Mautnereda67292013-04-28 13:50:14 -07007011
Bryce Lee584a4452014-10-21 15:55:55 -07007012 private boolean isTheaterModeEnabled() {
7013 return Settings.Global.getInt(mContext.getContentResolver(),
7014 Settings.Global.THEATER_MODE_ON, 0) == 1;
7015 }
7016
Svetoslav Ganov7befb7d2012-09-27 16:49:23 -07007017 private boolean isGlobalAccessibilityGestureEnabled() {
7018 return Settings.Global.getInt(mContext.getContentResolver(),
7019 Settings.Global.ENABLE_ACCESSIBILITY_GLOBAL_GESTURE_ENABLED, 0) == 1;
7020 }
7021
Craig Mautnereda67292013-04-28 13:50:14 -07007022 @Override
The Android Open Source Project0727d222009-03-11 12:11:58 -07007023 public boolean performHapticFeedbackLw(WindowState win, int effectId, boolean always) {
Svetoslav Ganov96179212012-10-10 14:17:45 -07007024 if (!mVibrator.hasVibrator()) {
7025 return false;
7026 }
Christopher Tate5e08af02012-09-21 17:17:22 -07007027 final boolean hapticsDisabled = Settings.System.getIntForUser(mContext.getContentResolver(),
7028 Settings.System.HAPTIC_FEEDBACK_ENABLED, 0, UserHandle.USER_CURRENT) == 0;
Jeff Brown82379ba2014-07-25 19:03:28 -07007029 if (hapticsDisabled && !always) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08007030 return false;
7031 }
Amith Yamasanic33cb712010-02-10 15:21:49 -08007032 long[] pattern = null;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08007033 switch (effectId) {
7034 case HapticFeedbackConstants.LONG_PRESS:
Amith Yamasanic33cb712010-02-10 15:21:49 -08007035 pattern = mLongPressVibePattern;
7036 break;
Dianne Hackbornb1a79802009-09-29 15:18:31 -07007037 case HapticFeedbackConstants.VIRTUAL_KEY:
Amith Yamasanic33cb712010-02-10 15:21:49 -08007038 pattern = mVirtualKeyVibePattern;
7039 break;
7040 case HapticFeedbackConstants.KEYBOARD_TAP:
7041 pattern = mKeyboardTapVibePattern;
7042 break;
Fabrice Di Meglioeeff63a2013-08-05 12:07:24 -07007043 case HapticFeedbackConstants.CLOCK_TICK:
7044 pattern = mClockTickVibePattern;
7045 break;
Fabrice Di Megliobd9152f2013-10-01 11:21:31 -07007046 case HapticFeedbackConstants.CALENDAR_DATE:
7047 pattern = mCalendarDateVibePattern;
7048 break;
Dianne Hackbornb1a79802009-09-29 15:18:31 -07007049 case HapticFeedbackConstants.SAFE_MODE_DISABLED:
Amith Yamasanic33cb712010-02-10 15:21:49 -08007050 pattern = mSafeModeDisabledVibePattern;
7051 break;
Dianne Hackbornb1a79802009-09-29 15:18:31 -07007052 case HapticFeedbackConstants.SAFE_MODE_ENABLED:
Amith Yamasanic33cb712010-02-10 15:21:49 -08007053 pattern = mSafeModeEnabledVibePattern;
7054 break;
Mady Mellore8608912015-06-05 09:02:55 -07007055 case HapticFeedbackConstants.CONTEXT_CLICK:
7056 pattern = mContextClickVibePattern;
Mady Mellore82067b2015-04-30 09:58:35 -07007057 break;
Amith Yamasanic33cb712010-02-10 15:21:49 -08007058 default:
7059 return false;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08007060 }
Dianne Hackbornf265ea92013-01-31 15:00:51 -08007061 int owningUid;
7062 String owningPackage;
7063 if (win != null) {
7064 owningUid = win.getOwningUid();
7065 owningPackage = win.getOwningPackage();
7066 } else {
7067 owningUid = android.os.Process.myUid();
Dianne Hackborn95d78532013-09-11 09:51:14 -07007068 owningPackage = mContext.getOpPackageName();
Dianne Hackbornf265ea92013-01-31 15:00:51 -08007069 }
Amith Yamasanic33cb712010-02-10 15:21:49 -08007070 if (pattern.length == 1) {
7071 // One-shot vibration
John Spurlock7b414672014-07-18 13:02:39 -04007072 mVibrator.vibrate(owningUid, owningPackage, pattern[0], VIBRATION_ATTRIBUTES);
Amith Yamasanic33cb712010-02-10 15:21:49 -08007073 } else {
7074 // Pattern vibration
John Spurlock7b414672014-07-18 13:02:39 -04007075 mVibrator.vibrate(owningUid, owningPackage, pattern, -1, VIBRATION_ATTRIBUTES);
Amith Yamasanic33cb712010-02-10 15:21:49 -08007076 }
7077 return true;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08007078 }
Jeff Brownc38c9be2012-10-04 13:16:19 -07007079
7080 @Override
7081 public void keepScreenOnStartedLw() {
Daniel Sandler0601eb72011-04-13 01:01:32 -04007082 }
7083
Jeff Brownc38c9be2012-10-04 13:16:19 -07007084 @Override
7085 public void keepScreenOnStoppedLw() {
Jim Millerab954542014-10-10 18:21:49 -07007086 if (isKeyguardShowingAndNotOccluded()) {
Jim Miller25190572013-02-28 17:36:24 -08007087 mPowerManager.userActivity(SystemClock.uptimeMillis(), false);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08007088 }
7089 }
Mike Lockwoodfcb39242009-10-21 23:01:07 -04007090
Dianne Hackborndf89e652011-10-06 22:35:11 -07007091 private int updateSystemUiVisibilityLw() {
Joe Onorato664644d2011-01-23 17:53:23 -08007092 // If there is no window focused, there will be nobody to handle the events
7093 // anyway, so just hang on in whatever state we're in until things settle down.
Adrian Roos53f28ec2014-10-29 17:26:12 +01007094 final WindowState win = mFocusedWindow != null ? mFocusedWindow
7095 : mTopFullscreenOpaqueWindowState;
John Spurlock79da8332013-09-20 12:04:47 -04007096 if (win == null) {
Dianne Hackborndf89e652011-10-06 22:35:11 -07007097 return 0;
7098 }
Jorim Jaggi380ecb82014-03-14 17:25:20 +01007099 if ((win.getAttrs().privateFlags & PRIVATE_FLAG_KEYGUARD) != 0 && mHideLockScreen == true) {
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07007100 // We are updating at a point where the keyguard has gotten
7101 // focus, but we were last in a state where the top window is
7102 // hiding it. This is probably because the keyguard as been
7103 // shown while the top window was displayed, so we want to ignore
7104 // it here because this is just a very transient change and it
7105 // will quickly lose focus once it correctly gets hidden.
7106 return 0;
7107 }
John Spurlock32beb2c2013-03-11 10:16:47 -04007108
John Spurlock1db8b682014-02-18 11:18:59 -05007109 int tmpVisibility = PolicyControl.getSystemUiVisibility(win, null)
Dianne Hackborne26ab702011-10-16 13:21:33 -07007110 & ~mResettingSystemUiFlags
7111 & ~mForceClearedSystemUiFlags;
John Spurlock79da8332013-09-20 12:04:47 -04007112 if (mForcingShowNavBar && win.getSurfaceLayer() < mForcingShowNavBarLayer) {
John Spurlockc6d1c602014-01-17 15:22:06 -05007113 tmpVisibility &= ~PolicyControl.adjustClearableFlags(win, View.SYSTEM_UI_CLEARABLE_FLAGS);
Dianne Hackborn891d3fb2013-01-09 18:31:37 -08007114 }
Thanh Hai Mai6c009f52015-09-01 16:27:32 -07007115
7116 if (mUiMode == Configuration.UI_MODE_TYPE_CAR) {
7117 tmpVisibility |= StatusBarManager.DISABLE_RECENT;
7118 }
7119
Jorim Jaggi86905582016-02-09 21:36:09 -08007120 final int fullscreenVisibility = updateLightStatusBarLw(0 /* vis */,
7121 mTopFullscreenOpaqueWindowState, mTopFullscreenOpaqueOrDimmingWindowState);
7122 final int dockedVisibility = updateLightStatusBarLw(0 /* vis */,
7123 mTopDockedOpaqueWindowState, mTopDockedOpaqueOrDimmingWindowState);
7124 mWindowManagerFuncs.getStackBounds(HOME_STACK_ID, mNonDockedStackBounds);
7125 mWindowManagerFuncs.getStackBounds(DOCKED_STACK_ID, mDockedStackBounds);
John Spurlock79da8332013-09-20 12:04:47 -04007126 final int visibility = updateSystemBarsLw(win, mLastSystemUiFlags, tmpVisibility);
John Spurlockad3e6cb2013-04-30 08:47:43 -04007127 final int diff = visibility ^ mLastSystemUiFlags;
Jorim Jaggi86905582016-02-09 21:36:09 -08007128 final int fullscreenDiff = fullscreenVisibility ^ mLastFullscreenStackSysUiFlags;
7129 final int dockedDiff = dockedVisibility ^ mLastDockedStackSysUiFlags;
John Spurlock79da8332013-09-20 12:04:47 -04007130 final boolean needsMenu = win.getNeedsMenuLw(mTopFullscreenOpaqueWindowState);
Jorim Jaggi86905582016-02-09 21:36:09 -08007131 if (diff == 0 && fullscreenDiff == 0 && dockedDiff == 0 && mLastFocusNeedsMenu == needsMenu
7132 && mFocusedApp == win.getAppToken()
7133 && mLastNonDockedStackBounds.equals(mNonDockedStackBounds)
7134 && mLastDockedStackBounds.equals(mDockedStackBounds)) {
Dianne Hackborndf89e652011-10-06 22:35:11 -07007135 return 0;
7136 }
Dianne Hackborne26ab702011-10-16 13:21:33 -07007137 mLastSystemUiFlags = visibility;
Jorim Jaggi86905582016-02-09 21:36:09 -08007138 mLastFullscreenStackSysUiFlags = fullscreenVisibility;
7139 mLastDockedStackSysUiFlags = dockedVisibility;
Dianne Hackborn4eff8d32011-11-10 19:38:40 -08007140 mLastFocusNeedsMenu = needsMenu;
John Spurlock79da8332013-09-20 12:04:47 -04007141 mFocusedApp = win.getAppToken();
Jorim Jaggi86905582016-02-09 21:36:09 -08007142 final Rect fullscreenStackBounds = new Rect(mNonDockedStackBounds);
7143 final Rect dockedStackBounds = new Rect(mDockedStackBounds);
Dianne Hackborndf89e652011-10-06 22:35:11 -07007144 mHandler.post(new Runnable() {
Craig Mautnereda67292013-04-28 13:50:14 -07007145 @Override
Dianne Hackborndf89e652011-10-06 22:35:11 -07007146 public void run() {
Jorim Jaggi86905582016-02-09 21:36:09 -08007147 StatusBarManagerInternal statusbar = getStatusBarManagerInternal();
7148 if (statusbar != null) {
7149 statusbar.setSystemUiVisibility(visibility, fullscreenVisibility,
7150 dockedVisibility, 0xffffffff, fullscreenStackBounds,
7151 dockedStackBounds, win.toString());
7152 statusbar.topAppWindowChanged(needsMenu);
Joe Onorato664644d2011-01-23 17:53:23 -08007153 }
Dianne Hackborndf89e652011-10-06 22:35:11 -07007154 }
7155 });
7156 return diff;
Joe Onorato664644d2011-01-23 17:53:23 -08007157 }
7158
Jorim Jaggi86905582016-02-09 21:36:09 -08007159 private int updateLightStatusBarLw(int vis, WindowState opaque, WindowState opaqueOrDimming) {
Adrian Rooscd3884d2015-02-18 17:25:23 +01007160 WindowState statusColorWin = isStatusBarKeyguard() && !mHideLockScreen
7161 ? mStatusBar
Jorim Jaggi86905582016-02-09 21:36:09 -08007162 : opaqueOrDimming;
Adrian Rooscd3884d2015-02-18 17:25:23 +01007163
7164 if (statusColorWin != null) {
Jorim Jaggi86905582016-02-09 21:36:09 -08007165 if (statusColorWin == opaque) {
Adrian Rooscd3884d2015-02-18 17:25:23 +01007166 // If the top fullscreen-or-dimming window is also the top fullscreen, respect
7167 // its light flag.
7168 vis &= ~View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR;
7169 vis |= PolicyControl.getSystemUiVisibility(statusColorWin, null)
7170 & View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR;
7171 } else if (statusColorWin != null && statusColorWin.isDimming()) {
7172 // Otherwise if it's dimming, clear the light flag.
7173 vis &= ~View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR;
7174 }
7175 }
7176 return vis;
7177 }
7178
John Spurlock79da8332013-09-20 12:04:47 -04007179 private int updateSystemBarsLw(WindowState win, int oldVis, int vis) {
Wale Ogunwale6e94a9e2015-10-07 15:35:49 -07007180 final boolean dockedStackVisible = mWindowManagerInternal.isStackVisible(DOCKED_STACK_ID);
7181 final boolean freeformStackVisible =
7182 mWindowManagerInternal.isStackVisible(FREEFORM_WORKSPACE_STACK_ID);
Jorim Jaggi9511b0f2016-01-29 19:12:44 -08007183 final boolean resizing = mWindowManagerInternal.isDockedDividerResizing();
7184
7185 // We need to force system bars when the docked stack is visible, when the freeform stack
7186 // is visible but also when we are resizing for the transitions when docked stack
7187 // visibility changes.
Jorim Jaggi0ffd49c2016-02-12 15:04:21 -08007188 mForceShowSystemBars = dockedStackVisible || freeformStackVisible || resizing;
Yorke Lee9b2ffb32016-03-07 20:42:01 -08007189 final boolean forceOpaqueStatusBar = mForceShowSystemBars && !mForceStatusBarFromKeyguard;
Wale Ogunwale6e94a9e2015-10-07 15:35:49 -07007190
John Spurlockbd957402013-10-03 11:38:39 -04007191 // apply translucent bar vis flags
Jorim Jaggi380ecb82014-03-14 17:25:20 +01007192 WindowState transWin = isStatusBarKeyguard() && !mHideLockScreen
7193 ? mStatusBar
John Spurlockbd957402013-10-03 11:38:39 -04007194 : mTopFullscreenOpaqueWindowState;
7195 vis = mStatusBarController.applyTranslucentFlagLw(transWin, vis, oldVis);
7196 vis = mNavigationBarController.applyTranslucentFlagLw(transWin, vis, oldVis);
7197
John Spurlock27735a42013-08-14 17:57:38 -04007198 // prevent status bar interaction from clearing certain flags
Selim Cinekf83e8242015-05-19 18:08:14 -07007199 int type = win.getAttrs().type;
7200 boolean statusBarHasFocus = type == TYPE_STATUS_BAR;
John Spurlock08ffcf52014-07-11 10:13:46 -04007201 if (statusBarHasFocus && !isStatusBarKeyguard()) {
John Spurlockad3e6cb2013-04-30 08:47:43 -04007202 int flags = View.SYSTEM_UI_FLAG_FULLSCREEN
7203 | View.SYSTEM_UI_FLAG_HIDE_NAVIGATION
John Spurlockcfc359a2013-09-05 10:42:03 -04007204 | View.SYSTEM_UI_FLAG_IMMERSIVE
Jorim Jaggi73fef8d2015-02-16 17:32:28 +01007205 | View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY
7206 | View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR;
John Spurlock08ffcf52014-07-11 10:13:46 -04007207 if (mHideLockScreen) {
Jorim Jaggi5cf17872014-03-26 18:31:48 +01007208 flags |= View.STATUS_BAR_TRANSLUCENT | View.NAVIGATION_BAR_TRANSLUCENT;
7209 }
John Spurlockbd957402013-10-03 11:38:39 -04007210 vis = (vis & ~flags) | (oldVis & flags);
John Spurlockad3e6cb2013-04-30 08:47:43 -04007211 }
John Spurlockad3e6cb2013-04-30 08:47:43 -04007212
Wale Ogunwale6e94a9e2015-10-07 15:35:49 -07007213 if ((!areTranslucentBarsAllowed() && transWin != mStatusBar)
Yorke Lee9b2ffb32016-03-07 20:42:01 -08007214 || forceOpaqueStatusBar) {
7215 vis &= ~(View.STATUS_BAR_TRANSLUCENT | View.STATUS_BAR_TRANSPARENT);
Alan Viverette5a0f4ec2013-10-07 15:10:29 -07007216 }
7217
Yorke Lee9b2ffb32016-03-07 20:42:01 -08007218 vis = configureNavBarOpacity(vis, dockedStackVisible, freeformStackVisible, resizing);
Yorke Lee2e4b7322016-03-02 17:33:06 -08007219
Jorim Jaggi4fa78922015-11-30 17:13:56 -08007220 if (mForceWindowDrawsStatusBarBackground) {
7221 vis |= View.STATUS_BAR_TRANSPARENT;
7222 vis &= ~View.STATUS_BAR_TRANSLUCENT;
7223 }
7224
John Spurlock27735a42013-08-14 17:57:38 -04007225 // update status bar
John Spurlockf1a36642013-10-12 17:50:42 -04007226 boolean immersiveSticky =
7227 (vis & View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY) != 0;
Wale Ogunwale6e94a9e2015-10-07 15:35:49 -07007228 final boolean hideStatusBarWM =
7229 mTopFullscreenOpaqueWindowState != null
7230 && (PolicyControl.getWindowFlags(mTopFullscreenOpaqueWindowState, null)
John Spurlock27735a42013-08-14 17:57:38 -04007231 & WindowManager.LayoutParams.FLAG_FULLSCREEN) != 0;
Wale Ogunwale6e94a9e2015-10-07 15:35:49 -07007232 final boolean hideStatusBarSysui =
John Spurlock27735a42013-08-14 17:57:38 -04007233 (vis & View.SYSTEM_UI_FLAG_FULLSCREEN) != 0;
Wale Ogunwale6e94a9e2015-10-07 15:35:49 -07007234 final boolean hideNavBarSysui =
John Spurlockf1a36642013-10-12 17:50:42 -04007235 (vis & View.SYSTEM_UI_FLAG_HIDE_NAVIGATION) != 0;
John Spurlockad3e6cb2013-04-30 08:47:43 -04007236
Wale Ogunwale6e94a9e2015-10-07 15:35:49 -07007237 final boolean transientStatusBarAllowed = mStatusBar != null
Jorim Jaggi0ffd49c2016-02-12 15:04:21 -08007238 && (statusBarHasFocus || (!mForceShowSystemBars
Wale Ogunwale6e94a9e2015-10-07 15:35:49 -07007239 && (hideStatusBarWM || (hideStatusBarSysui && immersiveSticky))));
John Spurlock27735a42013-08-14 17:57:38 -04007240
Wale Ogunwale6e94a9e2015-10-07 15:35:49 -07007241 final boolean transientNavBarAllowed = mNavigationBar != null
Jorim Jaggi0ffd49c2016-02-12 15:04:21 -08007242 && !mForceShowSystemBars && hideNavBarSysui && immersiveSticky;
John Spurlockf1a36642013-10-12 17:50:42 -04007243
Adrian Roosddc8b272015-05-21 16:28:27 -07007244 final long now = SystemClock.uptimeMillis();
7245 final boolean pendingPanic = mPendingPanicGestureUptime != 0
7246 && now - mPendingPanicGestureUptime <= PANIC_GESTURE_EXPIRATION;
7247 if (pendingPanic && hideNavBarSysui && !isStatusBarKeyguard() && mKeyguardDrawComplete) {
7248 // The user performed the panic gesture recently, we're about to hide the bars,
7249 // we're no longer on the Keyguard and the screen is ready. We can now request the bars.
7250 mPendingPanicGestureUptime = 0;
7251 mStatusBarController.showTransient();
7252 mNavigationBarController.showTransient();
7253 }
7254
Wale Ogunwale6e94a9e2015-10-07 15:35:49 -07007255 final boolean denyTransientStatus = mStatusBarController.isTransientShowRequested()
John Spurlockf1a36642013-10-12 17:50:42 -04007256 && !transientStatusBarAllowed && hideStatusBarSysui;
Wale Ogunwale6e94a9e2015-10-07 15:35:49 -07007257 final boolean denyTransientNav = mNavigationBarController.isTransientShowRequested()
John Spurlockf1a36642013-10-12 17:50:42 -04007258 && !transientNavBarAllowed;
Jorim Jaggi0ffd49c2016-02-12 15:04:21 -08007259 if (denyTransientStatus || denyTransientNav || mForceShowSystemBars) {
John Spurlock27735a42013-08-14 17:57:38 -04007260 // clear the clearable flags instead
John Spurlockf1a36642013-10-12 17:50:42 -04007261 clearClearableFlagsLw();
tiger_huangc58d7562014-10-23 20:24:19 +08007262 vis &= ~View.SYSTEM_UI_CLEARABLE_FLAGS;
John Spurlockad3e6cb2013-04-30 08:47:43 -04007263 }
John Spurlock27735a42013-08-14 17:57:38 -04007264
Selim Cinekf98702e2015-05-20 22:48:40 -07007265 final boolean immersive = (vis & View.SYSTEM_UI_FLAG_IMMERSIVE) != 0;
7266 immersiveSticky = (vis & View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY) != 0;
7267 final boolean navAllowedHidden = immersive || immersiveSticky;
7268
Selim Cinekd6623612015-05-22 18:56:22 -07007269 if (hideNavBarSysui && !navAllowedHidden && windowTypeToLayerLw(win.getBaseType())
7270 > windowTypeToLayerLw(TYPE_INPUT_CONSUMER)) {
Selim Cinekf98702e2015-05-20 22:48:40 -07007271 // We can't hide the navbar from this window otherwise the input consumer would not get
7272 // the input events.
7273 vis = (vis & ~View.SYSTEM_UI_FLAG_HIDE_NAVIGATION);
7274 }
7275
John Spurlock27735a42013-08-14 17:57:38 -04007276 vis = mStatusBarController.updateVisibilityLw(transientStatusBarAllowed, oldVis, vis);
7277
7278 // update navigation bar
John Spurlockf1a36642013-10-12 17:50:42 -04007279 boolean oldImmersiveMode = isImmersiveMode(oldVis);
7280 boolean newImmersiveMode = isImmersiveMode(vis);
7281 if (win != null && oldImmersiveMode != newImmersiveMode) {
John Spurlock79da8332013-09-20 12:04:47 -04007282 final String pkg = win.getOwningPackage();
Maurice Lam99c6e072014-04-28 18:24:28 -07007283 mImmersiveModeConfirmation.immersiveModeChanged(pkg, newImmersiveMode,
7284 isUserSetupComplete());
John Spurlock34e13d92013-08-10 06:52:28 -04007285 }
John Spurlock27735a42013-08-14 17:57:38 -04007286
John Spurlockf1a36642013-10-12 17:50:42 -04007287 vis = mNavigationBarController.updateVisibilityLw(transientNavBarAllowed, oldVis, vis);
7288
John Spurlocke1f366f2013-08-05 12:22:40 -04007289 return vis;
John Spurlockad3e6cb2013-04-30 08:47:43 -04007290 }
7291
Yorke Lee9b2ffb32016-03-07 20:42:01 -08007292 /**
7293 * @return the current visibility flags with the nav-bar opacity related flags toggled based
7294 * on the nav bar opacity rules chosen by {@link #mNavBarOpacityMode}.
7295 */
7296 private int configureNavBarOpacity(int visibility, boolean dockedStackVisible,
7297 boolean freeformStackVisible, boolean isDockedDividerResizing) {
7298 if (mNavBarOpacityMode == NAV_BAR_OPAQUE_WHEN_FREEFORM_OR_DOCKED) {
7299 if (dockedStackVisible || freeformStackVisible || isDockedDividerResizing) {
7300 visibility = setNavBarOpaqueFlag(visibility);
7301 }
7302 } else if (mNavBarOpacityMode == NAV_BAR_TRANSLUCENT_WHEN_FREEFORM_OPAQUE_OTHERWISE) {
7303 if (isDockedDividerResizing) {
7304 visibility = setNavBarOpaqueFlag(visibility);
7305 } else if (freeformStackVisible) {
7306 visibility = setNavBarTranslucentFlag(visibility);
7307 } else {
7308 visibility = setNavBarOpaqueFlag(visibility);
7309 }
7310 }
7311
7312 if (!areTranslucentBarsAllowed()) {
7313 visibility &= ~View.NAVIGATION_BAR_TRANSLUCENT;
7314 }
7315 return visibility;
7316 }
7317
7318 private int setNavBarOpaqueFlag(int visibility) {
7319 return visibility &= ~(View.NAVIGATION_BAR_TRANSLUCENT | View.NAVIGATION_BAR_TRANSPARENT);
7320 }
7321
7322 private int setNavBarTranslucentFlag(int visibility) {
7323 visibility &= ~View.NAVIGATION_BAR_TRANSPARENT;
7324 return visibility |= View.NAVIGATION_BAR_TRANSLUCENT;
7325 }
7326
John Spurlockf1a36642013-10-12 17:50:42 -04007327 private void clearClearableFlagsLw() {
7328 int newVal = mResettingSystemUiFlags | View.SYSTEM_UI_CLEARABLE_FLAGS;
7329 if (newVal != mResettingSystemUiFlags) {
7330 mResettingSystemUiFlags = newVal;
7331 mWindowManagerFuncs.reevaluateStatusBarVisibility();
7332 }
7333 }
7334
7335 private boolean isImmersiveMode(int vis) {
7336 final int flags = View.SYSTEM_UI_FLAG_IMMERSIVE | View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY;
John Spurlock34e13d92013-08-10 06:52:28 -04007337 return mNavigationBar != null
7338 && (vis & View.SYSTEM_UI_FLAG_HIDE_NAVIGATION) != 0
Daniel Sandler900ece52013-10-18 15:53:27 -04007339 && (vis & flags) != 0
7340 && canHideNavigationBar();
John Spurlock34e13d92013-08-10 06:52:28 -04007341 }
7342
Alan Viverette5a0f4ec2013-10-07 15:10:29 -07007343 /**
Daniel Sandlerdd73ee42013-10-11 22:19:59 -04007344 * @return whether the navigation or status bar can be made translucent
7345 *
7346 * This should return true unless touch exploration is not enabled or
7347 * R.boolean.config_enableTranslucentDecor is false.
Alan Viverette5a0f4ec2013-10-07 15:10:29 -07007348 */
Daniel Sandlerdd73ee42013-10-11 22:19:59 -04007349 private boolean areTranslucentBarsAllowed() {
Alan Viverette817f3cd2015-08-13 11:40:14 -04007350 return mTranslucentDecorEnabled;
Alan Viverette5a0f4ec2013-10-07 15:10:29 -07007351 }
7352
Daniel Sandler0c4ccff2011-10-19 16:39:14 -04007353 // Use this instead of checking config_showNavigationBar so that it can be consistently
7354 // overridden by qemu.hw.mainkeys in the emulator.
Craig Mautnereda67292013-04-28 13:50:14 -07007355 @Override
Daniel Sandler0c4ccff2011-10-19 16:39:14 -04007356 public boolean hasNavigationBar() {
7357 return mHasNavigationBar;
7358 }
7359
satok1bc0a492012-04-25 22:47:12 +09007360 @Override
7361 public void setLastInputMethodWindowLw(WindowState ime, WindowState target) {
7362 mLastInputMethodWindow = ime;
7363 mLastInputMethodTargetWindow = target;
7364 }
7365
Craig Mautnerf1b67412012-09-19 13:18:29 -07007366 @Override
Satoshi Kataoka658c7b82013-10-10 17:03:51 +09007367 public int getInputMethodWindowVisibleHeightLw() {
7368 return mDockBottom - mCurBottom;
7369 }
7370
7371 @Override
Craig Mautnerf1b67412012-09-19 13:18:29 -07007372 public void setCurrentUserLw(int newUserId) {
Craig Mautnerd625ab22013-09-06 13:40:31 -07007373 mCurrentUserId = newUserId;
Jim Miller5ecd8112013-01-09 18:50:26 -08007374 if (mKeyguardDelegate != null) {
7375 mKeyguardDelegate.setCurrentUser(newUserId);
Craig Mautnerf1b67412012-09-19 13:18:29 -07007376 }
John Spurlock13451a22012-09-28 14:40:41 -04007377 if (mStatusBarService != null) {
7378 try {
7379 mStatusBarService.setCurrentUser(newUserId);
7380 } catch (RemoteException e) {
7381 // oh well
7382 }
7383 }
Dianne Hackborn2ea9bae2012-11-02 18:43:48 -07007384 setLastInputMethodWindowLw(null, null);
Craig Mautnerf1b67412012-09-19 13:18:29 -07007385 }
7386
7387 @Override
Svetoslav Ganov545252f2012-12-10 18:29:24 -08007388 public boolean canMagnifyWindow(int windowType) {
7389 switch (windowType) {
7390 case WindowManager.LayoutParams.TYPE_INPUT_METHOD:
7391 case WindowManager.LayoutParams.TYPE_INPUT_METHOD_DIALOG:
7392 case WindowManager.LayoutParams.TYPE_NAVIGATION_BAR:
7393 case WindowManager.LayoutParams.TYPE_MAGNIFICATION_OVERLAY: {
7394 return false;
7395 }
7396 }
7397 return true;
7398 }
7399
7400 @Override
7401 public boolean isTopLevelWindow(int windowType) {
7402 if (windowType >= WindowManager.LayoutParams.FIRST_SUB_WINDOW
7403 && windowType <= WindowManager.LayoutParams.LAST_SUB_WINDOW) {
7404 return (windowType == WindowManager.LayoutParams.TYPE_APPLICATION_ATTACHED_DIALOG);
7405 }
7406 return true;
7407 }
7408
Jim Miller4eeb4f62012-11-08 00:04:29 -08007409 @Override
Jeff Brownd7a04de2012-06-17 14:17:52 -07007410 public void dump(String prefix, PrintWriter pw, String[] args) {
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08007411 pw.print(prefix); pw.print("mSafeMode="); pw.print(mSafeMode);
Dianne Hackbornba24e4d2011-09-01 11:17:06 -07007412 pw.print(" mSystemReady="); pw.print(mSystemReady);
7413 pw.print(" mSystemBooted="); pw.println(mSystemBooted);
Jeff Brown2e7760e2012-04-11 15:14:55 -07007414 pw.print(prefix); pw.print("mLidState="); pw.print(mLidState);
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08007415 pw.print(" mLidOpenRotation="); pw.print(mLidOpenRotation);
Michael Wright3818c922014-09-02 13:59:07 -07007416 pw.print(" mCameraLensCoverState="); pw.print(mCameraLensCoverState);
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08007417 pw.print(" mHdmiPlugged="); pw.println(mHdmiPlugged);
Dianne Hackborne26ab702011-10-16 13:21:33 -07007418 if (mLastSystemUiFlags != 0 || mResettingSystemUiFlags != 0
7419 || mForceClearedSystemUiFlags != 0) {
7420 pw.print(prefix); pw.print("mLastSystemUiFlags=0x");
7421 pw.print(Integer.toHexString(mLastSystemUiFlags));
7422 pw.print(" mResettingSystemUiFlags=0x");
7423 pw.print(Integer.toHexString(mResettingSystemUiFlags));
7424 pw.print(" mForceClearedSystemUiFlags=0x");
7425 pw.println(Integer.toHexString(mForceClearedSystemUiFlags));
Dianne Hackborndf89e652011-10-06 22:35:11 -07007426 }
Dianne Hackborn4eff8d32011-11-10 19:38:40 -08007427 if (mLastFocusNeedsMenu) {
7428 pw.print(prefix); pw.print("mLastFocusNeedsMenu=");
7429 pw.println(mLastFocusNeedsMenu);
7430 }
Jeff Browna20dda42014-05-27 20:57:24 -07007431 pw.print(prefix); pw.print("mWakeGestureEnabledSetting=");
7432 pw.println(mWakeGestureEnabledSetting);
7433
Jeff Brownbcdfc622014-03-06 19:13:04 -08007434 pw.print(prefix); pw.print("mSupportAutoRotation="); pw.println(mSupportAutoRotation);
Daniel Sandler6396c722013-04-16 20:19:09 -04007435 pw.print(prefix); pw.print("mUiMode="); pw.print(mUiMode);
7436 pw.print(" mDockMode="); pw.print(mDockMode);
keunyounga7710492015-09-23 11:33:58 -07007437 pw.print(" mEnableCarDockHomeCapture="); pw.print(mEnableCarDockHomeCapture);
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08007438 pw.print(" mCarDockRotation="); pw.print(mCarDockRotation);
7439 pw.print(" mDeskDockRotation="); pw.println(mDeskDockRotation);
7440 pw.print(prefix); pw.print("mUserRotationMode="); pw.print(mUserRotationMode);
7441 pw.print(" mUserRotation="); pw.print(mUserRotation);
Daniel Sandler2ed6ad62011-02-22 14:54:17 -05007442 pw.print(" mAllowAllRotations="); pw.println(mAllowAllRotations);
Dianne Hackborn6e2281d2012-06-19 17:48:32 -07007443 pw.print(prefix); pw.print("mCurrentAppOrientation="); pw.println(mCurrentAppOrientation);
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08007444 pw.print(prefix); pw.print("mCarDockEnablesAccelerometer=");
7445 pw.print(mCarDockEnablesAccelerometer);
7446 pw.print(" mDeskDockEnablesAccelerometer=");
7447 pw.println(mDeskDockEnablesAccelerometer);
7448 pw.print(prefix); pw.print("mLidKeyboardAccessibility=");
7449 pw.print(mLidKeyboardAccessibility);
7450 pw.print(" mLidNavigationAccessibility="); pw.print(mLidNavigationAccessibility);
Edward Savage-Jones7def60d2015-11-13 13:27:03 +01007451 pw.print(" mLidControlsScreenLock="); pw.println(mLidControlsScreenLock);
Dianne Hackborn6e2281d2012-06-19 17:48:32 -07007452 pw.print(" mLidControlsSleep="); pw.println(mLidControlsSleep);
Jeff Brown6d8fd272014-05-20 21:24:38 -07007453 pw.print(prefix);
Anthony Hugh34f09ca2016-03-04 12:03:37 -08007454 pw.print(" mLongPressOnBackBehavior="); pw.println(mLongPressOnBackBehavior);
7455 pw.print(prefix);
Jeff Brown6d8fd272014-05-20 21:24:38 -07007456 pw.print("mShortPressOnPowerBehavior="); pw.print(mShortPressOnPowerBehavior);
7457 pw.print(" mLongPressOnPowerBehavior="); pw.println(mLongPressOnPowerBehavior);
Jeff Brown13f00f02014-10-31 14:45:50 -07007458 pw.print(prefix);
7459 pw.print("mDoublePressOnPowerBehavior="); pw.print(mDoublePressOnPowerBehavior);
7460 pw.print(" mTriplePressOnPowerBehavior="); pw.println(mTriplePressOnPowerBehavior);
Jeff Brown6d8fd272014-05-20 21:24:38 -07007461 pw.print(prefix); pw.print("mHasSoftInput="); pw.println(mHasSoftInput);
Jeff Brown3ee549c2014-09-22 20:14:39 -07007462 pw.print(prefix); pw.print("mAwake="); pw.println(mAwake);
7463 pw.print(prefix); pw.print("mScreenOnEarly="); pw.print(mScreenOnEarly);
7464 pw.print(" mScreenOnFully="); pw.println(mScreenOnFully);
7465 pw.print(prefix); pw.print("mKeyguardDrawComplete="); pw.print(mKeyguardDrawComplete);
7466 pw.print(" mWindowManagerDrawComplete="); pw.println(mWindowManagerDrawComplete);
7467 pw.print(prefix); pw.print("mOrientationSensorEnabled=");
7468 pw.println(mOrientationSensorEnabled);
Dianne Hackbornc652de82013-02-15 16:32:56 -08007469 pw.print(prefix); pw.print("mOverscanScreen=("); pw.print(mOverscanScreenLeft);
7470 pw.print(","); pw.print(mOverscanScreenTop);
7471 pw.print(") "); pw.print(mOverscanScreenWidth);
7472 pw.print("x"); pw.println(mOverscanScreenHeight);
7473 if (mOverscanLeft != 0 || mOverscanTop != 0
7474 || mOverscanRight != 0 || mOverscanBottom != 0) {
7475 pw.print(prefix); pw.print("mOverscan left="); pw.print(mOverscanLeft);
7476 pw.print(" top="); pw.print(mOverscanTop);
7477 pw.print(" right="); pw.print(mOverscanRight);
7478 pw.print(" bottom="); pw.println(mOverscanBottom);
7479 }
Dianne Hackborn313440842013-02-19 19:22:59 -08007480 pw.print(prefix); pw.print("mRestrictedOverscanScreen=(");
7481 pw.print(mRestrictedOverscanScreenLeft);
7482 pw.print(","); pw.print(mRestrictedOverscanScreenTop);
7483 pw.print(") "); pw.print(mRestrictedOverscanScreenWidth);
7484 pw.print("x"); pw.println(mRestrictedOverscanScreenHeight);
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08007485 pw.print(prefix); pw.print("mUnrestrictedScreen=("); pw.print(mUnrestrictedScreenLeft);
7486 pw.print(","); pw.print(mUnrestrictedScreenTop);
7487 pw.print(") "); pw.print(mUnrestrictedScreenWidth);
7488 pw.print("x"); pw.println(mUnrestrictedScreenHeight);
7489 pw.print(prefix); pw.print("mRestrictedScreen=("); pw.print(mRestrictedScreenLeft);
7490 pw.print(","); pw.print(mRestrictedScreenTop);
7491 pw.print(") "); pw.print(mRestrictedScreenWidth);
7492 pw.print("x"); pw.println(mRestrictedScreenHeight);
Dianne Hackborn5b5cc4d2012-05-16 13:15:00 -07007493 pw.print(prefix); pw.print("mStableFullscreen=("); pw.print(mStableFullscreenLeft);
7494 pw.print(","); pw.print(mStableFullscreenTop);
7495 pw.print(")-("); pw.print(mStableFullscreenRight);
7496 pw.print(","); pw.print(mStableFullscreenBottom); pw.println(")");
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07007497 pw.print(prefix); pw.print("mStable=("); pw.print(mStableLeft);
7498 pw.print(","); pw.print(mStableTop);
7499 pw.print(")-("); pw.print(mStableRight);
7500 pw.print(","); pw.print(mStableBottom); pw.println(")");
Dianne Hackborn5c58de32012-04-28 19:52:37 -07007501 pw.print(prefix); pw.print("mSystem=("); pw.print(mSystemLeft);
7502 pw.print(","); pw.print(mSystemTop);
7503 pw.print(")-("); pw.print(mSystemRight);
7504 pw.print(","); pw.print(mSystemBottom); pw.println(")");
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08007505 pw.print(prefix); pw.print("mCur=("); pw.print(mCurLeft);
7506 pw.print(","); pw.print(mCurTop);
7507 pw.print(")-("); pw.print(mCurRight);
7508 pw.print(","); pw.print(mCurBottom); pw.println(")");
7509 pw.print(prefix); pw.print("mContent=("); pw.print(mContentLeft);
7510 pw.print(","); pw.print(mContentTop);
7511 pw.print(")-("); pw.print(mContentRight);
7512 pw.print(","); pw.print(mContentBottom); pw.println(")");
Dianne Hackborne30e02f2014-05-27 18:24:45 -07007513 pw.print(prefix); pw.print("mVoiceContent=("); pw.print(mVoiceContentLeft);
7514 pw.print(","); pw.print(mVoiceContentTop);
7515 pw.print(")-("); pw.print(mVoiceContentRight);
7516 pw.print(","); pw.print(mVoiceContentBottom); pw.println(")");
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08007517 pw.print(prefix); pw.print("mDock=("); pw.print(mDockLeft);
7518 pw.print(","); pw.print(mDockTop);
7519 pw.print(")-("); pw.print(mDockRight);
7520 pw.print(","); pw.print(mDockBottom); pw.println(")");
Dianne Hackborn5c58de32012-04-28 19:52:37 -07007521 pw.print(prefix); pw.print("mDockLayer="); pw.print(mDockLayer);
7522 pw.print(" mStatusBarLayer="); pw.println(mStatusBarLayer);
Dianne Hackborn7ad44382012-10-18 17:46:00 -07007523 pw.print(prefix); pw.print("mShowingLockscreen="); pw.print(mShowingLockscreen);
7524 pw.print(" mShowingDream="); pw.print(mShowingDream);
Jeff Brown061ea992015-04-17 19:55:47 -07007525 pw.print(" mDreamingLockscreen="); pw.print(mDreamingLockscreen);
7526 pw.print(" mDreamingSleepToken="); pw.println(mDreamingSleepToken);
Dianne Hackborn2ea9bae2012-11-02 18:43:48 -07007527 if (mLastInputMethodWindow != null) {
7528 pw.print(prefix); pw.print("mLastInputMethodWindow=");
7529 pw.println(mLastInputMethodWindow);
7530 }
7531 if (mLastInputMethodTargetWindow != null) {
7532 pw.print(prefix); pw.print("mLastInputMethodTargetWindow=");
7533 pw.println(mLastInputMethodTargetWindow);
7534 }
7535 if (mStatusBar != null) {
7536 pw.print(prefix); pw.print("mStatusBar=");
Dianne Hackbornae6688b2015-02-11 17:02:41 -08007537 pw.print(mStatusBar); pw.print(" isStatusBarKeyguard=");
7538 pw.println(isStatusBarKeyguard());
Dianne Hackborn2ea9bae2012-11-02 18:43:48 -07007539 }
7540 if (mNavigationBar != null) {
7541 pw.print(prefix); pw.print("mNavigationBar=");
7542 pw.println(mNavigationBar);
7543 }
Dianne Hackborn2ea9bae2012-11-02 18:43:48 -07007544 if (mFocusedWindow != null) {
7545 pw.print(prefix); pw.print("mFocusedWindow=");
7546 pw.println(mFocusedWindow);
7547 }
7548 if (mFocusedApp != null) {
7549 pw.print(prefix); pw.print("mFocusedApp=");
7550 pw.println(mFocusedApp);
7551 }
7552 if (mWinDismissingKeyguard != null) {
7553 pw.print(prefix); pw.print("mWinDismissingKeyguard=");
7554 pw.println(mWinDismissingKeyguard);
7555 }
7556 if (mTopFullscreenOpaqueWindowState != null) {
7557 pw.print(prefix); pw.print("mTopFullscreenOpaqueWindowState=");
7558 pw.println(mTopFullscreenOpaqueWindowState);
7559 }
Adrian Rooscd3884d2015-02-18 17:25:23 +01007560 if (mTopFullscreenOpaqueOrDimmingWindowState != null) {
7561 pw.print(prefix); pw.print("mTopFullscreenOpaqueOrDimmingWindowState=");
7562 pw.println(mTopFullscreenOpaqueOrDimmingWindowState);
7563 }
Dianne Hackborn891d3fb2013-01-09 18:31:37 -08007564 if (mForcingShowNavBar) {
7565 pw.print(prefix); pw.print("mForcingShowNavBar=");
7566 pw.println(mForcingShowNavBar); pw.print( "mForcingShowNavBarLayer=");
7567 pw.println(mForcingShowNavBarLayer);
7568 }
Dianne Hackborn7ad44382012-10-18 17:46:00 -07007569 pw.print(prefix); pw.print("mTopIsFullscreen="); pw.print(mTopIsFullscreen);
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08007570 pw.print(" mHideLockScreen="); pw.println(mHideLockScreen);
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07007571 pw.print(prefix); pw.print("mForceStatusBar="); pw.print(mForceStatusBar);
7572 pw.print(" mForceStatusBarFromKeyguard=");
7573 pw.println(mForceStatusBarFromKeyguard);
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08007574 pw.print(prefix); pw.print("mDismissKeyguard="); pw.print(mDismissKeyguard);
Craig Mautnerad09bcc2012-10-08 13:33:11 -07007575 pw.print(" mWinDismissingKeyguard="); pw.print(mWinDismissingKeyguard);
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08007576 pw.print(" mHomePressed="); pw.println(mHomePressed);
7577 pw.print(prefix); pw.print("mAllowLockscreenWhenOn="); pw.print(mAllowLockscreenWhenOn);
7578 pw.print(" mLockScreenTimeout="); pw.print(mLockScreenTimeout);
7579 pw.print(" mLockScreenTimerActive="); pw.println(mLockScreenTimerActive);
7580 pw.print(prefix); pw.print("mEndcallBehavior="); pw.print(mEndcallBehavior);
7581 pw.print(" mIncallPowerBehavior="); pw.print(mIncallPowerBehavior);
7582 pw.print(" mLongPressOnHomeBehavior="); pw.println(mLongPressOnHomeBehavior);
7583 pw.print(prefix); pw.print("mLandscapeRotation="); pw.print(mLandscapeRotation);
7584 pw.print(" mSeascapeRotation="); pw.println(mSeascapeRotation);
7585 pw.print(prefix); pw.print("mPortraitRotation="); pw.print(mPortraitRotation);
7586 pw.print(" mUpsideDownRotation="); pw.println(mUpsideDownRotation);
Jeff Brownc82c89ed2013-04-17 17:18:15 -07007587 pw.print(prefix); pw.print("mDemoHdmiRotation="); pw.print(mDemoHdmiRotation);
7588 pw.print(" mDemoHdmiRotationLock="); pw.println(mDemoHdmiRotationLock);
7589 pw.print(prefix); pw.print("mUndockedHdmiRotation="); pw.println(mUndockedHdmiRotation);
Jeff Brown600f0032014-05-22 17:06:00 -07007590
Tim Kilbournd7c0c2e2014-05-29 16:08:10 -07007591 mGlobalKeyManager.dump(prefix, pw);
John Spurlock27735a42013-08-14 17:57:38 -04007592 mStatusBarController.dump(pw, prefix);
7593 mNavigationBarController.dump(pw, prefix);
John Spurlockc6d1c602014-01-17 15:22:06 -05007594 PolicyControl.dump(prefix, pw);
Jeff Brown600f0032014-05-22 17:06:00 -07007595
Jeff Browna20dda42014-05-27 20:57:24 -07007596 if (mWakeGestureListener != null) {
7597 mWakeGestureListener.dump(pw, prefix);
7598 }
Jeff Brown600f0032014-05-22 17:06:00 -07007599 if (mOrientationListener != null) {
7600 mOrientationListener.dump(pw, prefix);
7601 }
Filip Gruszczynskicfb31852015-02-25 21:47:12 +00007602 if (mBurnInProtectionHelper != null) {
7603 mBurnInProtectionHelper.dump(prefix, pw);
7604 }
Jorim Jaggi84dc08a2015-09-11 17:45:22 -07007605 if (mKeyguardDelegate != null) {
7606 mKeyguardDelegate.dump(prefix, pw);
7607 }
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08007608 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08007609}