blob: 14d0457e41c102d1b1a6962bb4be76cc3f87c10b [file] [log] [blame]
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001/*
Jeff Brown37df39a92015-02-25 15:42:31 -08002 * Copyright (C) 2006 The Android Open Source Project
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
Jorim Jaggib10e33f2015-02-04 21:57:40 +010017package com.android.server.policy;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -080018
Wale Ogunwale3797c222015-10-27 14:21:58 -070019import static android.app.ActivityManager.StackId.DOCKED_STACK_ID;
20import static android.app.ActivityManager.StackId.FREEFORM_WORKSPACE_STACK_ID;
Jorim Jaggi86905582016-02-09 21:36:09 -080021import static android.app.ActivityManager.StackId.HOME_STACK_ID;
Jaewan Kim49117872016-01-19 17:24:08 +090022import static android.content.pm.PackageManager.FEATURE_PICTURE_IN_PICTURE;
23import static android.content.pm.PackageManager.FEATURE_TELEVISION;
24import static android.content.pm.PackageManager.FEATURE_WATCH;
Sriram Viswanathan9ebbe6a2015-11-16 17:59:22 -080025import static android.content.res.Configuration.UI_MODE_TYPE_CAR;
26import static android.content.res.Configuration.UI_MODE_TYPE_MASK;
Jorim Jaggi5060bd82016-02-19 17:12:19 -080027import static android.view.WindowManager.DOCKED_TOP;
28import static android.view.WindowManager.DOCKED_LEFT;
29import static android.view.WindowManager.DOCKED_RIGHT;
Muyuan Li6ca619f2016-03-08 13:30:42 -080030import static android.view.WindowManager.TAKE_SCREENSHOT_FULLSCREEN;
31import static android.view.WindowManager.TAKE_SCREENSHOT_SELECTED_REGION;
Wale Ogunwale6e94a9e2015-10-07 15:35:49 -070032import static android.view.WindowManager.LayoutParams.*;
Jaewan Kim49117872016-01-19 17:24:08 +090033import static android.view.WindowManagerPolicy.WindowManagerFuncs.CAMERA_LENS_COVERED;
Wale Ogunwale6e94a9e2015-10-07 15:35:49 -070034import static android.view.WindowManagerPolicy.WindowManagerFuncs.CAMERA_LENS_COVER_ABSENT;
35import static android.view.WindowManagerPolicy.WindowManagerFuncs.CAMERA_LENS_UNCOVERED;
Jaewan Kim49117872016-01-19 17:24:08 +090036import static android.view.WindowManagerPolicy.WindowManagerFuncs.LID_ABSENT;
37import static android.view.WindowManagerPolicy.WindowManagerFuncs.LID_CLOSED;
38import static android.view.WindowManagerPolicy.WindowManagerFuncs.LID_OPEN;
Wale Ogunwale6e94a9e2015-10-07 15:35:49 -070039
Dianne Hackborna4972e92012-03-14 10:38:05 -070040import android.app.ActivityManager;
Jorim Jaggi86905582016-02-09 21:36:09 -080041import android.app.ActivityManager.StackId;
Jeff Brown061ea992015-04-17 19:55:47 -070042import android.app.ActivityManagerInternal;
43import android.app.ActivityManagerInternal.SleepToken;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -080044import android.app.ActivityManagerNative;
Dianne Hackbornc2293022013-02-06 23:14:49 -080045import android.app.AppOpsManager;
Daniel Sandler6396c722013-04-16 20:19:09 -040046import android.app.IUiModeManager;
Dianne Hackborn661cd522011-08-22 00:26:20 -070047import android.app.ProgressDialog;
Jeff Brownde7a8ea2012-06-13 18:28:57 -070048import android.app.SearchManager;
John Spurlock97642182013-07-29 17:58:39 -040049import android.app.StatusBarManager;
Dianne Hackborn78968392010-03-04 20:47:56 -080050import android.app.UiModeManager;
Dianne Hackborn39c2d712009-09-22 11:41:31 -070051import android.content.ActivityNotFoundException;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -080052import android.content.BroadcastReceiver;
Daniel Sandler0601eb72011-04-13 01:01:32 -040053import android.content.ComponentName;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -080054import android.content.ContentResolver;
55import android.content.Context;
56import android.content.Intent;
Mike Lockwood1753f7f2009-08-24 14:49:07 -070057import android.content.IntentFilter;
Winson Chung9112ec32011-06-27 13:15:32 -070058import android.content.ServiceConnection;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -080059import android.content.pm.ActivityInfo;
Svet Ganov03f2afc2016-03-04 16:13:03 -080060import android.content.pm.ApplicationInfo;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -080061import android.content.pm.PackageManager;
Daniel Sandler6396c722013-04-16 20:19:09 -040062import android.content.pm.ResolveInfo;
Dianne Hackborn2f0b1752011-05-31 17:59:49 -070063import android.content.res.CompatibilityInfo;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -080064import android.content.res.Configuration;
65import android.content.res.Resources;
66import android.database.ContentObserver;
Dianne Hackbornc777e072010-02-12 13:07:59 -080067import android.graphics.PixelFormat;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -080068import android.graphics.Rect;
Jinsuk Kime601b712015-07-07 08:01:02 +090069import android.hardware.hdmi.HdmiControlManager;
70import android.hardware.hdmi.HdmiPlaybackClient;
71import android.hardware.hdmi.HdmiPlaybackClient.OneTouchPlayCallback;
John Spurlock7b414672014-07-18 13:02:39 -040072import android.media.AudioAttributes;
Michael Jurka7a348952012-02-27 13:07:58 -080073import android.media.AudioManager;
John Spurlock61560172015-02-06 19:46:04 -050074import android.media.AudioSystem;
Michael Jurka7a348952012-02-27 13:07:58 -080075import android.media.IAudioService;
Svetoslav Ganov7befb7d2012-09-27 16:49:23 -070076import android.media.Ringtone;
77import android.media.RingtoneManager;
RoboErik8a2cfc32014-05-16 11:19:38 -070078import android.media.session.MediaSessionLegacyHelper;
Billy Laucbe540f2015-06-25 01:51:44 +010079import android.os.Binder;
Svet Ganov03f2afc2016-03-04 16:13:03 -080080import android.os.Build;
Dianne Hackborn38e29a62011-09-18 14:43:08 -070081import android.os.Bundle;
Craig Mautner276a6eb2014-11-04 15:32:57 -080082import android.os.Debug;
Jeff Brown9a538ee2012-08-20 14:56:57 -070083import android.os.FactoryTest;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -080084import android.os.Handler;
85import android.os.IBinder;
Dianne Hackbornb6683c42015-06-18 17:40:33 -070086import android.os.IDeviceIdleController;
Jeff Brown32cbc38552011-12-01 14:01:49 -080087import android.os.Looper;
Dianne Hackbornfc8fa632011-08-17 16:20:47 -070088import android.os.Message;
89import android.os.Messenger;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -080090import android.os.PowerManager;
Nick Armstrong-Crews56ecfcc2015-09-07 21:46:50 -070091import android.os.PowerManagerInternal;
Billy Laucbe540f2015-06-25 01:51:44 +010092import android.os.Process;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -080093import android.os.RemoteException;
94import android.os.ServiceManager;
95import android.os.SystemClock;
96import android.os.SystemProperties;
Dianne Hackbornad7fa7f2011-01-07 14:06:50 -080097import android.os.UEventObserver;
Dianne Hackbornf02b60a2012-08-16 10:48:27 -070098import android.os.UserHandle;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -080099import android.os.Vibrator;
Michael Wright3818c922014-09-02 13:59:07 -0700100import android.provider.MediaStore;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800101import android.provider.Settings;
Jose Lima9546b202014-07-02 17:21:51 -0700102import android.service.dreams.DreamManagerInternal;
John Spurlockc8b46ca2013-04-08 12:59:26 -0400103import android.service.dreams.DreamService;
104import android.service.dreams.IDreamManager;
Michael Wrightdc63f7b2014-08-21 19:05:21 -0700105import android.speech.RecognizerIntent;
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700106import android.telecom.TelecomManager;
Dianne Hackborn81e56d52011-05-26 00:55:58 -0700107import android.util.DisplayMetrics;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800108import android.util.EventLog;
109import android.util.Log;
Jeff Browna41ca772010-08-11 14:46:32 -0700110import android.util.Slog;
Jeff Brown6651a632011-11-28 12:59:11 -0800111import android.util.SparseArray;
Muyuan Li94ce94e2016-02-24 16:20:54 -0800112import android.util.LongSparseArray;
Dianne Hackbornf87d1962012-04-04 12:48:24 -0700113import android.view.Display;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800114import android.view.Gravity;
115import android.view.HapticFeedbackConstants;
Dianne Hackborne0f085d2011-11-30 18:41:15 -0800116import android.view.IApplicationToken;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800117import android.view.IWindowManager;
Jeff Browna41ca772010-08-11 14:46:32 -0700118import android.view.InputChannel;
Jeff Brown4d396052010-10-29 21:50:21 -0700119import android.view.InputDevice;
Jeff Brown4952dfd2011-11-30 19:23:22 -0800120import android.view.InputEvent;
Jeff Brown32cbc38552011-12-01 14:01:49 -0800121import android.view.InputEventReceiver;
Jeff Brown6b53e8d2010-11-10 16:03:06 -0800122import android.view.KeyCharacterMap;
Craig Mautnerae446592012-12-06 19:05:05 -0800123import android.view.KeyCharacterMap.FallbackAction;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800124import android.view.KeyEvent;
125import android.view.MotionEvent;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800126import android.view.Surface;
127import android.view.View;
128import android.view.ViewConfiguration;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800129import android.view.WindowManager;
Craig Mautnerae446592012-12-06 19:05:05 -0800130import android.view.WindowManagerGlobal;
Craig Mautner8a0da012014-05-31 15:13:37 -0700131import android.view.WindowManagerInternal;
Craig Mautnerae446592012-12-06 19:05:05 -0800132import android.view.WindowManagerPolicy;
Craig Mautnerae446592012-12-06 19:05:05 -0800133import android.view.accessibility.AccessibilityEvent;
Svetoslav8e3feb12014-02-24 13:46:47 -0800134import android.view.accessibility.AccessibilityManager;
Craig Mautnerae446592012-12-06 19:05:05 -0800135import android.view.animation.Animation;
Jorim Jaggi76a16232014-08-08 17:00:47 +0200136import android.view.animation.AnimationSet;
Craig Mautnerae446592012-12-06 19:05:05 -0800137import android.view.animation.AnimationUtils;
Craig Mautnerae446592012-12-06 19:05:05 -0800138import com.android.internal.R;
Jason Monk8f7f3182015-11-18 16:35:14 -0500139import com.android.internal.logging.MetricsLogger;
140import com.android.internal.policy.PhoneWindow;
Muyuan Li94ce94e2016-02-24 16:20:54 -0800141import com.android.internal.policy.IShortcutService;
Craig Mautnerae446592012-12-06 19:05:05 -0800142import com.android.internal.statusbar.IStatusBarService;
Filip Gruszczynski2217f612015-05-26 11:32:08 -0700143import com.android.internal.util.ScreenShapeHelper;
Craig Mautnerae446592012-12-06 19:05:05 -0800144import com.android.internal.widget.PointerLocationView;
Adrian Roos5941c982015-09-03 15:59:49 -0700145import com.android.server.GestureLauncherService;
Craig Mautner8a0da012014-05-31 15:13:37 -0700146import com.android.server.LocalServices;
Jorim Jaggib10e33f2015-02-04 21:57:40 +0100147import com.android.server.policy.keyguard.KeyguardServiceDelegate;
Jorim Jaggi4cfdcf52015-07-09 12:13:59 -0700148import com.android.server.policy.keyguard.KeyguardServiceDelegate.DrawnListener;
Jorim Jaggi86905582016-02-09 21:36:09 -0800149import com.android.server.statusbar.StatusBarManagerInternal;
Craig Mautnerae446592012-12-06 19:05:05 -0800150
151import java.io.File;
152import java.io.FileReader;
153import java.io.IOException;
154import java.io.PrintWriter;
Craig Mautner2bc789b2014-03-19 19:48:38 -0700155import java.util.HashSet;
Craig Mautner276a6eb2014-11-04 15:32:57 -0800156import java.util.List;
Craig Mautnerae446592012-12-06 19:05:05 -0800157
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800158/**
The Android Open Source Project0727d222009-03-11 12:11:58 -0700159 * WindowManagerPolicy implementation for the Android phone UI. This
160 * introduces a new method suffix, Lp, for an internal lock of the
161 * PhoneWindowManager. This is used to protect some internal state, and
John Spurlock04db1762013-05-13 12:46:41 -0400162 * 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 -0700163 * of both of those when held.
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800164 */
165public class PhoneWindowManager implements WindowManagerPolicy {
166 static final String TAG = "WindowManager";
167 static final boolean DEBUG = false;
Joe Onorato43a17652011-04-06 19:22:23 -0700168 static final boolean localLOGV = false;
Jeff Brown40013652012-05-16 21:22:36 -0700169 static final boolean DEBUG_INPUT = false;
Craig Mautnerc0d2d0a2014-10-31 16:25:15 -0700170 static final boolean DEBUG_KEYGUARD = false;
171 static final boolean DEBUG_LAYOUT = false;
Craig Mautner6fbda632012-07-03 09:26:39 -0700172 static final boolean DEBUG_STARTING_WINDOW = false;
Craig Mautner8a0da012014-05-31 15:13:37 -0700173 static final boolean DEBUG_WAKEUP = false;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800174 static final boolean SHOW_STARTING_ANIMATIONS = true;
175 static final boolean SHOW_PROCESSES_ON_ALT_MENU = false;
Joe Onoratod208e702010-10-08 16:22:43 -0400176
Daniel Sandler6396c722013-04-16 20:19:09 -0400177 // Whether to allow dock apps with METADATA_DOCK_HOME to temporarily take over the Home key.
keunyounga7710492015-09-23 11:33:58 -0700178 // No longer recommended for desk docks;
Daniel Sandler6396c722013-04-16 20:19:09 -0400179 static final boolean ENABLE_DESK_DOCK_HOME_CAPTURE = false;
180
Jeff Brown6d8fd272014-05-20 21:24:38 -0700181 static final int SHORT_PRESS_POWER_NOTHING = 0;
182 static final int SHORT_PRESS_POWER_GO_TO_SLEEP = 1;
183 static final int SHORT_PRESS_POWER_REALLY_GO_TO_SLEEP = 2;
184 static final int SHORT_PRESS_POWER_REALLY_GO_TO_SLEEP_AND_GO_HOME = 3;
Bryce Lee01b0c5f2015-02-05 18:24:04 -0800185 static final int SHORT_PRESS_POWER_GO_HOME = 4;
Jeff Brown6d8fd272014-05-20 21:24:38 -0700186
Joe Onoratod208e702010-10-08 16:22:43 -0400187 static final int LONG_PRESS_POWER_NOTHING = 0;
188 static final int LONG_PRESS_POWER_GLOBAL_ACTIONS = 1;
189 static final int LONG_PRESS_POWER_SHUT_OFF = 2;
Jeff Brown9a538ee2012-08-20 14:56:57 -0700190 static final int LONG_PRESS_POWER_SHUT_OFF_NO_CONFIRM = 3;
Michael Jurka3b1fc472011-06-13 10:54:40 -0700191
Anthony Hugh34f09ca2016-03-04 12:03:37 -0800192 static final int LONG_PRESS_BACK_NOTHING = 0;
193 static final int LONG_PRESS_BACK_GO_TO_VOICE_ASSIST = 1;
194
Jeff Brown13f00f02014-10-31 14:45:50 -0700195 static final int MULTI_PRESS_POWER_NOTHING = 0;
196 static final int MULTI_PRESS_POWER_THEATER_MODE = 1;
197 static final int MULTI_PRESS_POWER_BRIGHTNESS_BOOST = 2;
198
Michael Jurka3b1fc472011-06-13 10:54:40 -0700199 // These need to match the documentation/constant in
200 // core/res/res/values/config.xml
Joe Onorato46b0d682010-11-22 17:37:27 -0800201 static final int LONG_PRESS_HOME_NOTHING = 0;
Michael Wrightc9ebea72013-01-16 19:25:02 -0800202 static final int LONG_PRESS_HOME_RECENT_SYSTEM_UI = 1;
Jeff Browncaca8812013-05-09 13:34:33 -0700203 static final int LONG_PRESS_HOME_ASSIST = 2;
Jaewan Kim76b7d0d2016-02-12 19:01:02 +0900204 static final int LAST_LONG_PRESS_HOME_BEHAVIOR = LONG_PRESS_HOME_ASSIST;
Jeff Browncaca8812013-05-09 13:34:33 -0700205
206 static final int DOUBLE_TAP_HOME_NOTHING = 0;
207 static final int DOUBLE_TAP_HOME_RECENT_SYSTEM_UI = 1;
Joe Onorato46b0d682010-11-22 17:37:27 -0800208
Jaewan Kim49117872016-01-19 17:24:08 +0900209 static final int SHORT_PRESS_WINDOW_NOTHING = 0;
210 static final int SHORT_PRESS_WINDOW_PICTURE_IN_PICTURE = 1;
211
Filip Gruszczynskia483a1d2015-03-17 19:06:58 +0000212 static final int SHORT_PRESS_SLEEP_GO_TO_SLEEP = 0;
213 static final int SHORT_PRESS_SLEEP_GO_TO_SLEEP_AND_GO_HOME = 1;
214
Yorke Lee9b2ffb32016-03-07 20:42:01 -0800215 // Controls navigation bar opacity depending on which workspace stacks are currently
216 // visible.
217 // Nav bar is always opaque when either the freeform stack or docked stack is visible.
218 static final int NAV_BAR_OPAQUE_WHEN_FREEFORM_OR_DOCKED = 0;
219 // Nav bar is always translucent when the freeform stack is visible, otherwise always opaque.
220 static final int NAV_BAR_TRANSLUCENT_WHEN_FREEFORM_OPAQUE_OTHERWISE = 1;
221
Dianne Hackborn5cb8d792009-05-21 17:34:15 -0700222 static final int APPLICATION_MEDIA_SUBLAYER = -2;
223 static final int APPLICATION_MEDIA_OVERLAY_SUBLAYER = -1;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800224 static final int APPLICATION_PANEL_SUBLAYER = 1;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800225 static final int APPLICATION_SUB_PANEL_SUBLAYER = 2;
Wale Ogunwale0a4dc222015-04-14 12:58:42 -0700226 static final int APPLICATION_ABOVE_SUB_PANEL_SUBLAYER = 3;
Craig Mautner88400d32012-09-30 12:35:45 -0700227
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800228 static public final String SYSTEM_DIALOG_REASON_KEY = "reason";
229 static public final String SYSTEM_DIALOG_REASON_GLOBAL_ACTIONS = "globalactions";
230 static public final String SYSTEM_DIALOG_REASON_RECENT_APPS = "recentapps";
Joe Onoratof275f0c2009-11-24 16:11:13 -0500231 static public final String SYSTEM_DIALOG_REASON_HOME_KEY = "homekey";
Jeff Brownde7a8ea2012-06-13 18:28:57 -0700232 static public final String SYSTEM_DIALOG_REASON_ASSIST = "assist";
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800233
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -0700234 /**
235 * These are the system UI flags that, when changing, can cause the layout
236 * of the screen to change.
237 */
238 static final int SYSTEM_UI_CHANGING_LAYOUT =
John Spurlocke1f366f2013-08-05 12:22:40 -0400239 View.SYSTEM_UI_FLAG_HIDE_NAVIGATION
John Spurlock7f4820a2013-10-08 12:54:35 -0400240 | View.SYSTEM_UI_FLAG_FULLSCREEN
241 | View.STATUS_BAR_TRANSLUCENT
Adrian Roosea562512014-05-05 13:33:03 +0200242 | View.NAVIGATION_BAR_TRANSLUCENT
Jorim Jaggi4fa78922015-11-30 17:13:56 -0800243 | View.STATUS_BAR_TRANSPARENT
244 | View.NAVIGATION_BAR_TRANSPARENT;
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -0700245
John Spurlock7b414672014-07-18 13:02:39 -0400246 private static final AudioAttributes VIBRATION_ATTRIBUTES = new AudioAttributes.Builder()
247 .setContentType(AudioAttributes.CONTENT_TYPE_SONIFICATION)
248 .setUsage(AudioAttributes.USAGE_ASSISTANCE_SONIFICATION)
249 .build();
250
Adrian Roosddc8b272015-05-21 16:28:27 -0700251 // The panic gesture may become active only after the keyguard is dismissed and the immersive
252 // app shows again. If that doesn't happen for 30s we drop the gesture.
253 private static final long PANIC_GESTURE_EXPIRATION = 30000;
254
Winson44dbe292016-03-10 14:00:14 -0800255 private static final String SYSUI_PACKAGE = "com.android.systemui";
256 private static final String SYSUI_SCREENSHOT_SERVICE =
257 "com.android.systemui.screenshot.TakeScreenshotService";
258 private static final String SYSUI_SCREENSHOT_ERROR_RECEIVER =
259 "com.android.systemui.screenshot.ScreenshotServiceErrorReceiver";
260
Jim Miller5ecd8112013-01-09 18:50:26 -0800261 /**
262 * Keyguard stuff
263 */
264 private WindowState mKeyguardScrim;
Jorim Jaggi380ecb82014-03-14 17:25:20 +0100265 private boolean mKeyguardHidden;
Jeff Brown3ee549c2014-09-22 20:14:39 -0700266 private boolean mKeyguardDrawnOnce;
Jim Miller5ecd8112013-01-09 18:50:26 -0800267
Jeff Brown6651a632011-11-28 12:59:11 -0800268 /* Table of Application Launch keys. Maps from key codes to intent categories.
269 *
270 * These are special keys that are used to launch particular kinds of applications,
271 * such as a web browser. HID defines nearly a hundred of them in the Consumer (0x0C)
272 * usage page. We don't support quite that many yet...
273 */
274 static SparseArray<String> sApplicationLaunchKeyCategories;
275 static {
276 sApplicationLaunchKeyCategories = new SparseArray<String>();
277 sApplicationLaunchKeyCategories.append(
278 KeyEvent.KEYCODE_EXPLORER, Intent.CATEGORY_APP_BROWSER);
279 sApplicationLaunchKeyCategories.append(
280 KeyEvent.KEYCODE_ENVELOPE, Intent.CATEGORY_APP_EMAIL);
281 sApplicationLaunchKeyCategories.append(
282 KeyEvent.KEYCODE_CONTACTS, Intent.CATEGORY_APP_CONTACTS);
283 sApplicationLaunchKeyCategories.append(
284 KeyEvent.KEYCODE_CALENDAR, Intent.CATEGORY_APP_CALENDAR);
285 sApplicationLaunchKeyCategories.append(
286 KeyEvent.KEYCODE_MUSIC, Intent.CATEGORY_APP_MUSIC);
287 sApplicationLaunchKeyCategories.append(
288 KeyEvent.KEYCODE_CALCULATOR, Intent.CATEGORY_APP_CALCULATOR);
289 }
290
Craig Mautnerc3daedd2014-09-13 11:17:23 -0700291 /** Amount of time (in milliseconds) to wait for windows drawn before powering on. */
Jorim Jaggi0d210f62015-07-10 14:24:44 -0700292 static final int WAITING_FOR_DRAWN_TIMEOUT = 1000;
Craig Mautnerc3daedd2014-09-13 11:17:23 -0700293
Dianne Hackborndf89e652011-10-06 22:35:11 -0700294 /**
295 * Lock protecting internal state. Must not call out into window
296 * manager with lock held. (This lock will be acquired in places
297 * where the window manager is calling in with its own lock held.)
298 */
Craig Mautner0bf6ec92012-12-18 08:33:27 -0800299 private final Object mLock = new Object();
Dianne Hackborndf89e652011-10-06 22:35:11 -0700300
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800301 Context mContext;
302 IWindowManager mWindowManager;
Dianne Hackborndf89e652011-10-06 22:35:11 -0700303 WindowManagerFuncs mWindowManagerFuncs;
Craig Mautner8a0da012014-05-31 15:13:37 -0700304 WindowManagerInternal mWindowManagerInternal;
Jeff Brown96307042012-07-27 15:51:34 -0700305 PowerManager mPowerManager;
Jeff Brown061ea992015-04-17 19:55:47 -0700306 ActivityManagerInternal mActivityManagerInternal;
Jose Lima9546b202014-07-02 17:21:51 -0700307 DreamManagerInternal mDreamManagerInternal;
Michael Wrighta4d22d72015-09-16 23:19:26 +0100308 PowerManagerInternal mPowerManagerInternal;
Joe Onorato93056472010-09-10 10:30:46 -0400309 IStatusBarService mStatusBarService;
Jorim Jaggi86905582016-02-09 21:36:09 -0800310 StatusBarManagerInternal mStatusBarManagerInternal;
Jeff Browncaca8812013-05-09 13:34:33 -0700311 boolean mPreloadedRecentApps;
Dianne Hackborn42e620c2012-06-24 13:20:51 -0700312 final Object mServiceAquireLock = new Object();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800313 Vibrator mVibrator; // Vibrator for giving feedback of orientation changes
Jeff Brownde7a8ea2012-06-13 18:28:57 -0700314 SearchManager mSearchManager;
Svetoslav8e3feb12014-02-24 13:46:47 -0800315 AccessibilityManager mAccessibilityManager;
Filip Gruszczynskicfb31852015-02-25 21:47:12 +0000316 BurnInProtectionHelper mBurnInProtectionHelper;
Billy Laucbe540f2015-06-25 01:51:44 +0100317 AppOpsManager mAppOpsManager;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800318
Dianne Hackborn181ceb52009-08-27 22:16:40 -0700319 // Vibrator pattern for haptic feedback of a long press.
320 long[] mLongPressVibePattern;
Craig Mautner88400d32012-09-30 12:35:45 -0700321
Dianne Hackborn181ceb52009-08-27 22:16:40 -0700322 // Vibrator pattern for haptic feedback of virtual key press.
323 long[] mVirtualKeyVibePattern;
Craig Mautner967212c2013-04-13 21:10:58 -0700324
Amith Yamasanic33cb712010-02-10 15:21:49 -0800325 // Vibrator pattern for a short vibration.
326 long[] mKeyboardTapVibePattern;
327
Fabrice Di Meglioeeff63a2013-08-05 12:07:24 -0700328 // Vibrator pattern for a short vibration when tapping on an hour/minute tick of a Clock.
329 long[] mClockTickVibePattern;
330
Fabrice Di Megliobd9152f2013-10-01 11:21:31 -0700331 // Vibrator pattern for a short vibration when tapping on a day/month/year date of a Calendar.
332 long[] mCalendarDateVibePattern;
333
Dianne Hackbornb1a79802009-09-29 15:18:31 -0700334 // Vibrator pattern for haptic feedback during boot when safe mode is disabled.
335 long[] mSafeModeDisabledVibePattern;
Craig Mautner967212c2013-04-13 21:10:58 -0700336
Dianne Hackbornb1a79802009-09-29 15:18:31 -0700337 // Vibrator pattern for haptic feedback during boot when safe mode is enabled.
338 long[] mSafeModeEnabledVibePattern;
Romain Guy8154cd32010-03-29 14:41:15 -0700339
Mady Mellore8608912015-06-05 09:02:55 -0700340 // Vibrator pattern for haptic feedback of a context click.
341 long[] mContextClickVibePattern;
Mady Mellore82067b2015-04-30 09:58:35 -0700342
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800343 /** If true, hitting shift & menu will broadcast Intent.ACTION_BUG_REPORT */
344 boolean mEnableShiftMenuBugReports = false;
Mike Lockwoodd747dc82011-09-13 16:28:22 -0400345
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800346 boolean mSafeMode;
347 WindowState mStatusBar = null;
Dianne Hackborn69cb8752011-05-19 18:13:32 -0700348 int mStatusBarHeight;
Daniel Sandler8956dbb2011-04-22 07:55:02 -0400349 WindowState mNavigationBar = null;
Daniel Sandler36412a72011-08-04 09:35:13 -0400350 boolean mHasNavigationBar = false;
Dianne Hackbornf87d1962012-04-04 12:48:24 -0700351 boolean mCanHideNavigationBar = false;
Daniel Sandler4a066c52012-04-20 14:49:13 -0400352 boolean mNavigationBarCanMove = false; // can the navigation bar ever move to the side?
353 boolean mNavigationBarOnBottom = true; // is the navigation bar on the bottom *right now*?
Sriram Viswanathan9ebbe6a2015-11-16 17:59:22 -0800354 int[] mNavigationBarHeightForRotationDefault = new int[4];
355 int[] mNavigationBarWidthForRotationDefault = new int[4];
356 int[] mNavigationBarHeightForRotationInCarMode = new int[4];
357 int[] mNavigationBarWidthForRotationInCarMode = new int[4];
Daniel Sandler8956dbb2011-04-22 07:55:02 -0400358
Muyuan Li94ce94e2016-02-24 16:20:54 -0800359 private LongSparseArray<IShortcutService> mShortcutKeyServices = new LongSparseArray<>();
360
keunyounga7710492015-09-23 11:33:58 -0700361 // Whether to allow dock apps with METADATA_DOCK_HOME to temporarily take over the Home key.
362 // This is for car dock and this is updated from resource.
363 private boolean mEnableCarDockHomeCapture = true;
364
Craig Mautnera631d492014-08-05 15:16:01 -0700365 boolean mBootMessageNeedsHiding;
Jim Miller5ecd8112013-01-09 18:50:26 -0800366 KeyguardServiceDelegate mKeyguardDelegate;
Craig Mautner13f6ea72014-06-23 14:57:02 -0700367 final Runnable mWindowManagerDrawCallback = new Runnable() {
Craig Mautner8a0da012014-05-31 15:13:37 -0700368 @Override
Craig Mautner13f6ea72014-06-23 14:57:02 -0700369 public void run() {
Craig Mautner8a0da012014-05-31 15:13:37 -0700370 if (DEBUG_WAKEUP) Slog.i(TAG, "All windows ready for display!");
371 mHandler.sendEmptyMessage(MSG_WINDOW_MANAGER_DRAWN_COMPLETE);
372 }
373 };
Jorim Jaggi4cfdcf52015-07-09 12:13:59 -0700374 final DrawnListener mKeyguardDrawnCallback = new DrawnListener() {
Craig Mautner8a0da012014-05-31 15:13:37 -0700375 @Override
Jorim Jaggi4cfdcf52015-07-09 12:13:59 -0700376 public void onDrawn() {
377 if (DEBUG_WAKEUP) Slog.d(TAG, "mKeyguardDelegate.ShowListener.onDrawn.");
Craig Mautner8a0da012014-05-31 15:13:37 -0700378 mHandler.sendEmptyMessage(MSG_KEYGUARD_DRAWN_COMPLETE);
379 }
380 };
381
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800382 GlobalActions mGlobalActions;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800383 Handler mHandler;
satok1bc0a492012-04-25 22:47:12 +0900384 WindowState mLastInputMethodWindow = null;
385 WindowState mLastInputMethodTargetWindow = null;
Jeff Brown4aed78b2011-01-14 17:36:55 -0800386
Jeff Brown13f00f02014-10-31 14:45:50 -0700387 // FIXME This state is shared between the input reader and handler thread.
388 // Technically it's broken and buggy but it has been like this for many years
389 // and we have not yet seen any problems. Someday we'll rewrite this logic
390 // so that only one thread is involved in handling input policy. Unfortunately
391 // it's on a critical path for power management so we can't just post the work to the
392 // handler thread. We'll need to resolve this someday by teaching the input dispatcher
393 // to hold wakelocks during dispatch and eliminating the critical path.
394 volatile boolean mPowerKeyHandled;
Anthony Hugh34f09ca2016-03-04 12:03:37 -0800395 volatile boolean mBackKeyHandled;
Bryce Leed9268e32014-11-17 17:40:59 -0800396 volatile boolean mBeganFromNonInteractive;
Jeff Brown13f00f02014-10-31 14:45:50 -0700397 volatile int mPowerKeyPressCounter;
398 volatile boolean mEndCallKeyHandled;
399
Winson Chungd42a6cf2014-06-03 16:24:04 -0700400 boolean mRecentsVisible;
Winson Chung1e8d71b2014-05-16 17:05:22 -0700401 int mRecentAppsHeldModifiers;
Jeff Browncf39bdf2012-05-18 14:41:19 -0700402 boolean mLanguageSwitchKeyPressed;
Jeff Brown68b909d2011-12-07 16:36:01 -0800403
Jeff Brown2e7760e2012-04-11 15:14:55 -0700404 int mLidState = LID_ABSENT;
Michael Wright3818c922014-09-02 13:59:07 -0700405 int mCameraLensCoverState = CAMERA_LENS_COVER_ABSENT;
Jeff Browndaa37532012-05-01 15:54:03 -0700406 boolean mHaveBuiltInKeyboard;
Jeff Brown4aed78b2011-01-14 17:36:55 -0800407
Dianne Hackbornc777e072010-02-12 13:07:59 -0800408 boolean mSystemReady;
Dianne Hackbornba24e4d2011-09-01 11:17:06 -0700409 boolean mSystemBooted;
Adrian Roos3542f7d2015-07-13 15:57:53 -0700410 private boolean mDeferBindKeyguard;
Dianne Hackbornad7fa7f2011-01-07 14:06:50 -0800411 boolean mHdmiPlugged;
Jinsuk Kime601b712015-07-07 08:01:02 +0900412 HdmiControl mHdmiControl;
Jeff Brown4f5fa282014-06-12 19:19:15 -0700413 IUiModeManager mUiModeManager;
Daniel Sandler6396c722013-04-16 20:19:09 -0400414 int mUiMode;
Dianne Hackborn867ab6472010-04-29 13:28:56 -0700415 int mDockMode = Intent.EXTRA_DOCK_STATE_UNDOCKED;
Mike Lockwood1753f7f2009-08-24 14:49:07 -0700416 int mLidOpenRotation;
Mike Lockwood2d1efbd2009-09-16 12:15:53 -0400417 int mCarDockRotation;
418 int mDeskDockRotation;
Jeff Brownc82c89ed2013-04-17 17:18:15 -0700419 int mUndockedHdmiRotation;
420 int mDemoHdmiRotation;
421 boolean mDemoHdmiRotationLock;
Chong Zhangae6119ff2014-11-11 18:54:39 -0800422 int mDemoRotation;
423 boolean mDemoRotationLock;
Daniel Sandlerb73617d2010-08-17 00:41:00 -0400424
Jeff Browna20dda42014-05-27 20:57:24 -0700425 boolean mWakeGestureEnabledSetting;
426 MyWakeGestureListener mWakeGestureListener;
427
Craig Mautner46ac6fa2013-08-01 10:06:34 -0700428 // Default display does not rotate, apps that require non-default orientation will have to
429 // have the orientation emulated.
430 private boolean mForceDefaultOrientation = false;
431
Daniel Sandlerb73617d2010-08-17 00:41:00 -0400432 int mUserRotationMode = WindowManagerPolicy.USER_ROTATION_FREE;
433 int mUserRotation = Surface.ROTATION_0;
Jeff Brown207673cd2012-06-05 17:47:11 -0700434 boolean mAccelerometerDefault;
Daniel Sandlerb73617d2010-08-17 00:41:00 -0400435
Jeff Brownbcdfc622014-03-06 19:13:04 -0800436 boolean mSupportAutoRotation;
Jeff Brownd3187e32011-09-21 19:26:44 -0700437 int mAllowAllRotations = -1;
Mike Lockwoode9867d22009-09-20 01:59:02 -0400438 boolean mCarDockEnablesAccelerometer;
439 boolean mDeskDockEnablesAccelerometer;
Dianne Hackborn2862fff2009-09-15 22:56:29 -0700440 int mLidKeyboardAccessibility;
441 int mLidNavigationAccessibility;
Edward Savage-Jones7def60d2015-11-13 13:27:03 +0100442 boolean mLidControlsScreenLock;
Jeff Brownc458ce92012-04-30 14:58:40 -0700443 boolean mLidControlsSleep;
Jeff Brown13f00f02014-10-31 14:45:50 -0700444 int mShortPressOnPowerBehavior;
445 int mLongPressOnPowerBehavior;
446 int mDoublePressOnPowerBehavior;
447 int mTriplePressOnPowerBehavior;
Anthony Hugh34f09ca2016-03-04 12:03:37 -0800448 int mLongPressOnBackBehavior;
Filip Gruszczynskia483a1d2015-03-17 19:06:58 +0000449 int mShortPressOnSleepBehavior;
Jaewan Kim49117872016-01-19 17:24:08 +0900450 int mShortPressWindowBehavior;
Jeff Brown3ee549c2014-09-22 20:14:39 -0700451 boolean mAwake;
452 boolean mScreenOnEarly;
453 boolean mScreenOnFully;
454 ScreenOnListener mScreenOnListener;
455 boolean mKeyguardDrawComplete;
456 boolean mWindowManagerDrawComplete;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800457 boolean mOrientationSensorEnabled = false;
458 int mCurrentAppOrientation = ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800459 boolean mHasSoftInput = false;
Daniel Sandlerdd73ee42013-10-11 22:19:59 -0400460 boolean mTranslucentDecorEnabled = true;
RoboErik001c59c2015-01-26 15:53:51 -0800461 boolean mUseTvRouting;
Craig Mautner967212c2013-04-13 21:10:58 -0700462
Jeff Brown70825162012-03-28 17:27:48 -0700463 int mPointerLocationMode = 0; // guarded by mLock
Joe Onorato664644d2011-01-23 17:53:23 -0800464
465 // The last window we were told about in focusChanged.
466 WindowState mFocusedWindow;
Dianne Hackborne0f085d2011-11-30 18:41:15 -0800467 IApplicationToken mFocusedApp;
Joe Onorato664644d2011-01-23 17:53:23 -0800468
Jeff Brown70825162012-03-28 17:27:48 -0700469 PointerLocationView mPointerLocationView;
Jeff Brown32cbc38552011-12-01 14:01:49 -0800470
Dianne Hackbornc652de82013-02-15 16:32:56 -0800471 // The current size of the screen; really; extends into the overscan area of
472 // the screen and doesn't account for any system elements like the status bar.
473 int mOverscanScreenLeft, mOverscanScreenTop;
474 int mOverscanScreenWidth, mOverscanScreenHeight;
475 // The current visible size of the screen; really; (ir)regardless of whether the status
476 // bar can be hidden but not extending into the overscan area.
Joe Onorato29fc2c92010-11-24 10:26:50 -0800477 int mUnrestrictedScreenLeft, mUnrestrictedScreenTop;
478 int mUnrestrictedScreenWidth, mUnrestrictedScreenHeight;
Dianne Hackborn313440842013-02-19 19:22:59 -0800479 // Like mOverscanScreen*, but allowed to move into the overscan region where appropriate.
480 int mRestrictedOverscanScreenLeft, mRestrictedOverscanScreenTop;
481 int mRestrictedOverscanScreenWidth, mRestrictedOverscanScreenHeight;
Dianne Hackborn82de1ae2010-10-28 11:28:39 -0700482 // The current size of the screen; these may be different than (0,0)-(dw,dh)
483 // if the status bar can't be hidden; in that case it effectively carves out
484 // that area of the display from all other windows.
Joe Onorato29fc2c92010-11-24 10:26:50 -0800485 int mRestrictedScreenLeft, mRestrictedScreenTop;
486 int mRestrictedScreenWidth, mRestrictedScreenHeight;
Dianne Hackborn5c58de32012-04-28 19:52:37 -0700487 // During layout, the current screen borders accounting for any currently
488 // visible system UI elements.
489 int mSystemLeft, mSystemTop, mSystemRight, mSystemBottom;
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -0700490 // For applications requesting stable content insets, these are them.
491 int mStableLeft, mStableTop, mStableRight, mStableBottom;
Dianne Hackborn5b5cc4d2012-05-16 13:15:00 -0700492 // For applications requesting stable content insets but have also set the
493 // fullscreen window flag, these are the stable dimensions without the status bar.
494 int mStableFullscreenLeft, mStableFullscreenTop;
495 int mStableFullscreenRight, mStableFullscreenBottom;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800496 // During layout, the current screen borders with all outer decoration
497 // (status bar, input method dock) accounted for.
498 int mCurLeft, mCurTop, mCurRight, mCurBottom;
499 // During layout, the frame in which content should be displayed
500 // to the user, accounting for all screen decoration except for any
501 // space they deem as available for other content. This is usually
502 // the same as mCur*, but may be larger if the screen decor has supplied
503 // content insets.
504 int mContentLeft, mContentTop, mContentRight, mContentBottom;
Dianne Hackborne30e02f2014-05-27 18:24:45 -0700505 // During layout, the frame in which voice content should be displayed
506 // to the user, accounting for all screen decoration except for any
507 // space they deem as available for other content.
508 int mVoiceContentLeft, mVoiceContentTop, mVoiceContentRight, mVoiceContentBottom;
Dianne Hackborn8e11ef02010-11-18 19:47:42 -0800509 // During layout, the current screen borders along which input method
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800510 // windows are placed.
511 int mDockLeft, mDockTop, mDockRight, mDockBottom;
512 // During layout, the layer at which the doc window is placed.
513 int mDockLayer;
Dianne Hackborn5c58de32012-04-28 19:52:37 -0700514 // During layout, this is the layer of the status bar.
515 int mStatusBarLayer;
Dianne Hackborne26ab702011-10-16 13:21:33 -0700516 int mLastSystemUiFlags;
517 // Bits that we are in the process of clearing, so we want to prevent
518 // them from being set by applications until everything has been updated
519 // to have them clear.
520 int mResettingSystemUiFlags = 0;
521 // Bits that we are currently always keeping cleared.
522 int mForceClearedSystemUiFlags = 0;
Jorim Jaggi86905582016-02-09 21:36:09 -0800523 int mLastFullscreenStackSysUiFlags;
524 int mLastDockedStackSysUiFlags;
525 final Rect mNonDockedStackBounds = new Rect();
526 final Rect mDockedStackBounds = new Rect();
527 final Rect mLastNonDockedStackBounds = new Rect();
528 final Rect mLastDockedStackBounds = new Rect();
529
Dianne Hackborn4eff8d32011-11-10 19:38:40 -0800530 // What we last reported to system UI about whether the compatibility
531 // menu needs to be displayed.
532 boolean mLastFocusNeedsMenu = false;
Adrian Roosddc8b272015-05-21 16:28:27 -0700533 // If nonzero, a panic gesture was performed at that time in uptime millis and is still pending.
534 private long mPendingPanicGestureUptime;
Dianne Hackborndf89e652011-10-06 22:35:11 -0700535
Selim Cinekf83e8242015-05-19 18:08:14 -0700536 InputConsumer mInputConsumer = null;
Dianne Hackborndf89e652011-10-06 22:35:11 -0700537
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800538 static final Rect mTmpParentFrame = new Rect();
539 static final Rect mTmpDisplayFrame = new Rect();
Dianne Hackbornc4aad012013-02-22 15:05:25 -0800540 static final Rect mTmpOverscanFrame = new Rect();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800541 static final Rect mTmpContentFrame = new Rect();
542 static final Rect mTmpVisibleFrame = new Rect();
John Spurlock46646232013-09-30 22:32:42 -0400543 static final Rect mTmpDecorFrame = new Rect();
Adrian Roosfa104232014-06-20 16:10:14 -0700544 static final Rect mTmpStableFrame = new Rect();
Dianne Hackborn1f903c32011-09-13 19:18:06 -0700545 static final Rect mTmpNavigationFrame = new Rect();
Filip Gruszczynski2217f612015-05-26 11:32:08 -0700546 static final Rect mTmpOutsetFrame = new Rect();
Craig Mautner967212c2013-04-13 21:10:58 -0700547
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800548 WindowState mTopFullscreenOpaqueWindowState;
Adrian Rooscd3884d2015-02-18 17:25:23 +0100549 WindowState mTopFullscreenOpaqueOrDimmingWindowState;
Jorim Jaggi86905582016-02-09 21:36:09 -0800550 WindowState mTopDockedOpaqueWindowState;
551 WindowState mTopDockedOpaqueOrDimmingWindowState;
Craig Mautner2bc789b2014-03-19 19:48:38 -0700552 HashSet<IApplicationToken> mAppsToBeHidden = new HashSet<IApplicationToken>();
Jorim Jaggic13fcac2014-09-11 17:36:57 +0200553 HashSet<IApplicationToken> mAppsThatDismissKeyguard = new HashSet<IApplicationToken>();
Joe Onorato93056472010-09-10 10:30:46 -0400554 boolean mTopIsFullscreen;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800555 boolean mForceStatusBar;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -0700556 boolean mForceStatusBarFromKeyguard;
Selim Cinek4a4a2bddc2015-05-07 12:50:19 -0700557 private boolean mForceStatusBarTransparent;
Yorke Lee9b2ffb32016-03-07 20:42:01 -0800558 int mNavBarOpacityMode = NAV_BAR_OPAQUE_WHEN_FREEFORM_OR_DOCKED;
Dianne Hackborn39c2d712009-09-22 11:41:31 -0700559 boolean mHideLockScreen;
Dianne Hackborn891d3fb2013-01-09 18:31:37 -0800560 boolean mForcingShowNavBar;
561 int mForcingShowNavBarLayer;
Craig Mautnerad09bcc2012-10-08 13:33:11 -0700562
563 // States of keyguard dismiss.
564 private static final int DISMISS_KEYGUARD_NONE = 0; // Keyguard not being dismissed.
565 private static final int DISMISS_KEYGUARD_START = 1; // Keyguard needs to be dismissed.
566 private static final int DISMISS_KEYGUARD_CONTINUE = 2; // Keyguard has been dismissed.
567 int mDismissKeyguard = DISMISS_KEYGUARD_NONE;
568
569 /** The window that is currently dismissing the keyguard. Dismissing the keyguard must only
570 * be done once per window. */
571 private WindowState mWinDismissingKeyguard;
572
tingna_sunge785ffa2015-05-12 13:23:15 +0800573 /** When window is currently dismissing the keyguard, dismissing the keyguard must handle
574 * the keygaurd secure state change instantly case, e.g. the use case of inserting a PIN
575 * lock SIM card. This variable is used to record the previous keyguard secure state for
576 * monitoring secure state change on window dismissing keyguard. */
577 private boolean mSecureDismissingKeyguard;
578
Craig Mautnerc9457fa2014-06-06 14:27:48 -0700579 /** The window that is currently showing "over" the keyguard. If there is an app window
580 * belonging to another app on top of this the keyguard shows. If there is a fullscreen
581 * app window under this, still dismiss the keyguard but don't show the app underneath. Show
582 * the wallpaper. */
583 private WindowState mWinShowWhenLocked;
584
Dianne Hackborn7ad44382012-10-18 17:46:00 -0700585 boolean mShowingLockscreen;
586 boolean mShowingDream;
587 boolean mDreamingLockscreen;
Jeff Brown061ea992015-04-17 19:55:47 -0700588 boolean mDreamingSleepTokenNeeded;
589 SleepToken mDreamingSleepToken;
Jeff Brown48d1b142015-06-10 16:36:03 -0700590 SleepToken mScreenOffSleepToken;
Jim Millerab954542014-10-10 18:21:49 -0700591 boolean mKeyguardSecure;
592 boolean mKeyguardSecureIncludingHidden;
593 volatile boolean mKeyguardOccluded;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800594 boolean mHomePressed;
Jeff Browncaca8812013-05-09 13:34:33 -0700595 boolean mHomeConsumed;
596 boolean mHomeDoubleTapPending;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800597 Intent mHomeIntent;
Dianne Hackborn39c2d712009-09-22 11:41:31 -0700598 Intent mCarDockIntent;
599 Intent mDeskDockIntent;
Jeff Brownfd23e3e2012-05-09 13:34:28 -0700600 boolean mSearchKeyShortcutPending;
601 boolean mConsumeSearchKeyUp;
Jeff Brownde7a8ea2012-06-13 18:28:57 -0700602 boolean mAssistKeyLongPressed;
Michael Wright6a62e552014-06-03 19:19:48 -0700603 boolean mPendingMetaAction;
Jorim Jaggi0ffd49c2016-02-12 15:04:21 -0800604 boolean mForceShowSystemBars;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800605
Mike Lockwood28569302010-01-28 11:54:40 -0500606 // support for activating the lock screen while the screen is on
607 boolean mAllowLockscreenWhenOn;
608 int mLockScreenTimeout;
609 boolean mLockScreenTimerActive;
610
David Brownbaf8d092010-03-08 21:52:59 -0800611 // Behavior of ENDCALL Button. (See Settings.System.END_BUTTON_BEHAVIOR.)
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800612 int mEndcallBehavior;
David Brownbaf8d092010-03-08 21:52:59 -0800613
614 // Behavior of POWER button while in-call and screen on.
615 // (See Settings.Secure.INCALL_POWER_BUTTON_BEHAVIOR.)
616 int mIncallPowerBehavior;
617
Dianne Hackbornf87d1962012-04-04 12:48:24 -0700618 Display mDisplay;
619
Filip Gruszczynski2987f612015-06-30 15:03:30 -0700620 private int mDisplayRotation;
621
Dianne Hackborn9d132642011-04-21 17:26:39 -0700622 int mLandscapeRotation = 0; // default landscape rotation
623 int mSeascapeRotation = 0; // "other" landscape rotation, 180 degrees from mLandscapeRotation
624 int mPortraitRotation = 0; // default portrait rotation
625 int mUpsideDownRotation = 0; // "other" portrait rotation
Mitsuru Oshima831d0d92009-06-16 18:27:18 -0700626
Dianne Hackbornc652de82013-02-15 16:32:56 -0800627 int mOverscanLeft = 0;
628 int mOverscanTop = 0;
629 int mOverscanRight = 0;
630 int mOverscanBottom = 0;
631
Joe Onorato46b0d682010-11-22 17:37:27 -0800632 // What we do when the user long presses on home
Jeff Browncaca8812013-05-09 13:34:33 -0700633 private int mLongPressOnHomeBehavior;
634
635 // What we do when the user double-taps on home
636 private int mDoubleTapOnHomeBehavior;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800637
Bryce Lee584a4452014-10-21 15:55:55 -0700638 // Allowed theater mode wake actions
639 private boolean mAllowTheaterModeWakeFromKey;
640 private boolean mAllowTheaterModeWakeFromPowerKey;
641 private boolean mAllowTheaterModeWakeFromMotion;
Bryce Lee812d7022014-11-10 13:33:28 -0800642 private boolean mAllowTheaterModeWakeFromMotionWhenNotDreaming;
Bryce Lee584a4452014-10-21 15:55:55 -0700643 private boolean mAllowTheaterModeWakeFromCameraLens;
644 private boolean mAllowTheaterModeWakeFromLidSwitch;
645 private boolean mAllowTheaterModeWakeFromWakeGesture;
646
Bryce Leed3b28402015-03-09 15:49:13 +0000647 // Whether to support long press from power button in non-interactive mode
648 private boolean mSupportLongPressPowerWhenNonInteractive;
649
Bryce Lee55e846d2014-11-04 12:43:44 -0800650 // Whether to go to sleep entering theater mode from power button
651 private boolean mGoToSleepOnButtonPressTheaterMode;
652
Winson Chung9112ec32011-06-27 13:15:32 -0700653 // Screenshot trigger states
Jeff Brownd5bb82d2011-10-12 13:57:59 -0700654 // Time to volume and power must be pressed within this interval of each other.
655 private static final long SCREENSHOT_CHORD_DEBOUNCE_DELAY_MILLIS = 150;
Winson Chung1cea2f32012-10-08 20:42:01 -0700656 // Increase the chord delay when taking a screenshot from the keyguard
657 private static final float KEYGUARD_SCREENSHOT_CHORD_DELAY_MULTIPLIER = 2.5f;
Christopher Tatee90585f2012-03-05 18:56:25 -0800658 private boolean mScreenshotChordEnabled;
Jeff Brown13f00f02014-10-31 14:45:50 -0700659 private boolean mScreenshotChordVolumeDownKeyTriggered;
660 private long mScreenshotChordVolumeDownKeyTime;
661 private boolean mScreenshotChordVolumeDownKeyConsumed;
662 private boolean mScreenshotChordVolumeUpKeyTriggered;
663 private boolean mScreenshotChordPowerKeyTriggered;
664 private long mScreenshotChordPowerKeyTime;
Winson Chung9112ec32011-06-27 13:15:32 -0700665
Michael Wrightb854e242013-02-05 17:54:02 -0800666 /* The number of steps between min and max brightness */
667 private static final int BRIGHTNESS_STEPS = 10;
668
Christopher Tate5e08af02012-09-21 17:17:22 -0700669 SettingsObserver mSettingsObserver;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800670 ShortcutManager mShortcutManager;
671 PowerManager.WakeLock mBroadcastWakeLock;
Jeff Brown13f00f02014-10-31 14:45:50 -0700672 PowerManager.WakeLock mPowerKeyWakeLock;
Jeff Brown40013652012-05-16 21:22:36 -0700673 boolean mHavePendingMediaKeyRepeatWithWakeLock;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800674
Craig Mautnerd625ab22013-09-06 13:40:31 -0700675 private int mCurrentUserId;
676
Justin Kohd378ad72013-04-01 12:18:26 -0700677 // Maps global key codes to the components that will handle them.
678 private GlobalKeyManager mGlobalKeyManager;
679
Jeff Brownfd23e3e2012-05-09 13:34:28 -0700680 // Fallback actions by key code.
681 private final SparseArray<KeyCharacterMap.FallbackAction> mFallbackActions =
682 new SparseArray<KeyCharacterMap.FallbackAction>();
Jeff Brown49ed71d2010-12-06 17:13:33 -0800683
Jorim Jaggi76a16232014-08-08 17:00:47 +0200684 private final LogDecelerateInterpolator mLogDecelerateInterpolator
685 = new LogDecelerateInterpolator(100, 0);
686
Jorim Jaggi4fa78922015-11-30 17:13:56 -0800687 private boolean mForceWindowDrawsStatusBarBackground;
688
Jeff Brown70825162012-03-28 17:27:48 -0700689 private static final int MSG_ENABLE_POINTER_LOCATION = 1;
690 private static final int MSG_DISABLE_POINTER_LOCATION = 2;
Jeff Brown40013652012-05-16 21:22:36 -0700691 private static final int MSG_DISPATCH_MEDIA_KEY_WITH_WAKE_LOCK = 3;
692 private static final int MSG_DISPATCH_MEDIA_KEY_REPEAT_WITH_WAKE_LOCK = 4;
Craig Mautner8a0da012014-05-31 15:13:37 -0700693 private static final int MSG_KEYGUARD_DRAWN_COMPLETE = 5;
694 private static final int MSG_KEYGUARD_DRAWN_TIMEOUT = 6;
695 private static final int MSG_WINDOW_MANAGER_DRAWN_COMPLETE = 7;
Craig Mautner84984fa2014-06-19 11:19:20 -0700696 private static final int MSG_DISPATCH_SHOW_RECENTS = 9;
Alan Viverettee34560b22014-07-10 14:50:06 -0700697 private static final int MSG_DISPATCH_SHOW_GLOBAL_ACTIONS = 10;
Craig Mautnera631d492014-08-05 15:16:01 -0700698 private static final int MSG_HIDE_BOOT_MESSAGE = 11;
Michael Wright869a67c2014-08-26 19:33:06 -0700699 private static final int MSG_LAUNCH_VOICE_ASSIST_WITH_WAKE_LOCK = 12;
Jeff Brown13f00f02014-10-31 14:45:50 -0700700 private static final int MSG_POWER_DELAYED_PRESS = 13;
701 private static final int MSG_POWER_LONG_PRESS = 14;
Jeff Brown061ea992015-04-17 19:55:47 -0700702 private static final int MSG_UPDATE_DREAMING_SLEEP_TOKEN = 15;
Jun Mukaid2e7e352015-07-22 17:14:02 -0700703 private static final int MSG_REQUEST_TRANSIENT_BARS = 16;
Jaewan Kimc552b042016-01-18 16:08:45 +0900704 private static final int MSG_REQUEST_TV_PICTURE_IN_PICTURE = 17;
Anthony Hugh34f09ca2016-03-04 12:03:37 -0800705 private static final int MSG_BACK_LONG_PRESS = 18;
Jun Mukaid2e7e352015-07-22 17:14:02 -0700706
707 private static final int MSG_REQUEST_TRANSIENT_BARS_ARG_STATUS = 0;
708 private static final int MSG_REQUEST_TRANSIENT_BARS_ARG_NAVIGATION = 1;
Jeff Brown70825162012-03-28 17:27:48 -0700709
710 private class PolicyHandler extends Handler {
711 @Override
712 public void handleMessage(Message msg) {
713 switch (msg.what) {
714 case MSG_ENABLE_POINTER_LOCATION:
715 enablePointerLocation();
716 break;
717 case MSG_DISABLE_POINTER_LOCATION:
718 disablePointerLocation();
719 break;
Jeff Brown40013652012-05-16 21:22:36 -0700720 case MSG_DISPATCH_MEDIA_KEY_WITH_WAKE_LOCK:
721 dispatchMediaKeyWithWakeLock((KeyEvent)msg.obj);
722 break;
723 case MSG_DISPATCH_MEDIA_KEY_REPEAT_WITH_WAKE_LOCK:
724 dispatchMediaKeyRepeatWithWakeLock((KeyEvent)msg.obj);
725 break;
Craig Mautner84984fa2014-06-19 11:19:20 -0700726 case MSG_DISPATCH_SHOW_RECENTS:
727 showRecentApps(false);
728 break;
Alan Viverettee34560b22014-07-10 14:50:06 -0700729 case MSG_DISPATCH_SHOW_GLOBAL_ACTIONS:
730 showGlobalActionsInternal();
731 break;
Craig Mautner8a0da012014-05-31 15:13:37 -0700732 case MSG_KEYGUARD_DRAWN_COMPLETE:
733 if (DEBUG_WAKEUP) Slog.w(TAG, "Setting mKeyguardDrawComplete");
Jeff Brown36c4db82014-09-19 12:05:31 -0700734 finishKeyguardDrawn();
Craig Mautner8a0da012014-05-31 15:13:37 -0700735 break;
736 case MSG_KEYGUARD_DRAWN_TIMEOUT:
737 Slog.w(TAG, "Keyguard drawn timeout. Setting mKeyguardDrawComplete");
Jeff Brown36c4db82014-09-19 12:05:31 -0700738 finishKeyguardDrawn();
Craig Mautner8a0da012014-05-31 15:13:37 -0700739 break;
740 case MSG_WINDOW_MANAGER_DRAWN_COMPLETE:
741 if (DEBUG_WAKEUP) Slog.w(TAG, "Setting mWindowManagerDrawComplete");
Jeff Brown36c4db82014-09-19 12:05:31 -0700742 finishWindowsDrawn();
Craig Mautner8a0da012014-05-31 15:13:37 -0700743 break;
Craig Mautnera631d492014-08-05 15:16:01 -0700744 case MSG_HIDE_BOOT_MESSAGE:
745 handleHideBootMessage();
746 break;
Michael Wright869a67c2014-08-26 19:33:06 -0700747 case MSG_LAUNCH_VOICE_ASSIST_WITH_WAKE_LOCK:
748 launchVoiceAssistWithWakeLock(msg.arg1 != 0);
749 break;
Jeff Brown13f00f02014-10-31 14:45:50 -0700750 case MSG_POWER_DELAYED_PRESS:
751 powerPress((Long)msg.obj, msg.arg1 != 0, msg.arg2);
752 finishPowerKeyPress();
753 break;
754 case MSG_POWER_LONG_PRESS:
755 powerLongPress();
756 break;
Jeff Brown061ea992015-04-17 19:55:47 -0700757 case MSG_UPDATE_DREAMING_SLEEP_TOKEN:
758 updateDreamingSleepToken(msg.arg1 != 0);
759 break;
Jun Mukaid2e7e352015-07-22 17:14:02 -0700760 case MSG_REQUEST_TRANSIENT_BARS:
761 WindowState targetBar = (msg.arg1 == MSG_REQUEST_TRANSIENT_BARS_ARG_STATUS) ?
762 mStatusBar : mNavigationBar;
763 if (targetBar != null) {
764 requestTransientBars(targetBar);
765 }
766 break;
Jaewan Kimc552b042016-01-18 16:08:45 +0900767 case MSG_REQUEST_TV_PICTURE_IN_PICTURE:
768 requestTvPictureInPictureInternal();
769 break;
Anthony Hugh34f09ca2016-03-04 12:03:37 -0800770 case MSG_BACK_LONG_PRESS:
771 backLongPress();
772 break;
Jeff Brown70825162012-03-28 17:27:48 -0700773 }
774 }
775 }
776
Dianne Hackbornad7fa7f2011-01-07 14:06:50 -0800777 private UEventObserver mHDMIObserver = new UEventObserver() {
778 @Override
779 public void onUEvent(UEventObserver.UEvent event) {
780 setHdmiPlugged("1".equals(event.get("SWITCH_STATE")));
781 }
782 };
783
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800784 class SettingsObserver extends ContentObserver {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800785 SettingsObserver(Handler handler) {
786 super(handler);
787 }
David Brownbaf8d092010-03-08 21:52:59 -0800788
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800789 void observe() {
Christopher Tate5e08af02012-09-21 17:17:22 -0700790 // Observe all users' changes
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800791 ContentResolver resolver = mContext.getContentResolver();
792 resolver.registerContentObserver(Settings.System.getUriFor(
Christopher Tate5e08af02012-09-21 17:17:22 -0700793 Settings.System.END_BUTTON_BEHAVIOR), false, this,
794 UserHandle.USER_ALL);
David Brownbaf8d092010-03-08 21:52:59 -0800795 resolver.registerContentObserver(Settings.Secure.getUriFor(
Christopher Tate5e08af02012-09-21 17:17:22 -0700796 Settings.Secure.INCALL_POWER_BUTTON_BEHAVIOR), false, this,
797 UserHandle.USER_ALL);
Jeff Browna20dda42014-05-27 20:57:24 -0700798 resolver.registerContentObserver(Settings.Secure.getUriFor(
799 Settings.Secure.WAKE_GESTURE_ENABLED), false, this,
800 UserHandle.USER_ALL);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800801 resolver.registerContentObserver(Settings.System.getUriFor(
Christopher Tate5e08af02012-09-21 17:17:22 -0700802 Settings.System.ACCELEROMETER_ROTATION), false, this,
803 UserHandle.USER_ALL);
Mike Lockwood28569302010-01-28 11:54:40 -0500804 resolver.registerContentObserver(Settings.System.getUriFor(
Christopher Tate5e08af02012-09-21 17:17:22 -0700805 Settings.System.USER_ROTATION), false, this,
806 UserHandle.USER_ALL);
Daniel Sandlerb73617d2010-08-17 00:41:00 -0400807 resolver.registerContentObserver(Settings.System.getUriFor(
Christopher Tate5e08af02012-09-21 17:17:22 -0700808 Settings.System.SCREEN_OFF_TIMEOUT), false, this,
809 UserHandle.USER_ALL);
Dianne Hackbornc777e072010-02-12 13:07:59 -0800810 resolver.registerContentObserver(Settings.System.getUriFor(
Christopher Tate5e08af02012-09-21 17:17:22 -0700811 Settings.System.POINTER_LOCATION), false, this,
812 UserHandle.USER_ALL);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800813 resolver.registerContentObserver(Settings.Secure.getUriFor(
Christopher Tate5e08af02012-09-21 17:17:22 -0700814 Settings.Secure.DEFAULT_INPUT_METHOD), false, this,
815 UserHandle.USER_ALL);
John Spurlockd9b70bd2014-02-06 17:02:44 -0500816 resolver.registerContentObserver(Settings.Secure.getUriFor(
John Spurlockf1a36642013-10-12 17:50:42 -0400817 Settings.Secure.IMMERSIVE_MODE_CONFIRMATIONS), false, this,
Christopher Tate5e08af02012-09-21 17:17:22 -0700818 UserHandle.USER_ALL);
John Spurlockc6d1c602014-01-17 15:22:06 -0500819 resolver.registerContentObserver(Settings.Global.getUriFor(
820 Settings.Global.POLICY_CONTROL), false, this,
821 UserHandle.USER_ALL);
Dianne Hackbornc777e072010-02-12 13:07:59 -0800822 updateSettings();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800823 }
824
825 @Override public void onChange(boolean selfChange) {
Dianne Hackbornc777e072010-02-12 13:07:59 -0800826 updateSettings();
Jeff Brown01a98dd2011-09-20 15:08:29 -0700827 updateRotation(false);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800828 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800829 }
Craig Mautner967212c2013-04-13 21:10:58 -0700830
Jeff Browna20dda42014-05-27 20:57:24 -0700831 class MyWakeGestureListener extends WakeGestureListener {
832 MyWakeGestureListener(Context context, Handler handler) {
833 super(context, handler);
834 }
835
836 @Override
837 public void onWakeUp() {
838 synchronized (mLock) {
839 if (shouldEnableWakeGestureLp()) {
Jeff Browne07b94b2014-06-18 15:56:27 -0700840 performHapticFeedbackLw(null, HapticFeedbackConstants.VIRTUAL_KEY, false);
Dianne Hackborn280a64e2015-07-13 14:48:08 -0700841 wakeUp(SystemClock.uptimeMillis(), mAllowTheaterModeWakeFromWakeGesture,
842 "android.policy:GESTURE");
Jeff Browna20dda42014-05-27 20:57:24 -0700843 }
844 }
845 }
846 }
847
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800848 class MyOrientationListener extends WindowOrientationListener {
Chong Zhang5aaa0b32015-08-28 10:22:36 -0700849 private final Runnable mUpdateRotationRunnable = new Runnable() {
850 @Override
851 public void run() {
Tim Murray1f407642015-10-01 17:07:12 -0700852 // send interaction hint to improve redraw performance
853 mPowerManagerInternal.powerHint(PowerManagerInternal.POWER_HINT_INTERACTION, 0);
Chong Zhang5aaa0b32015-08-28 10:22:36 -0700854 updateRotation(false);
855 }
856 };
857
Craig Mautnereee29c42013-01-17 14:44:34 -0800858 MyOrientationListener(Context context, Handler handler) {
859 super(context, handler);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800860 }
Craig Mautner967212c2013-04-13 21:10:58 -0700861
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800862 @Override
Jeff Brownc0347aa2011-09-23 17:26:09 -0700863 public void onProposedRotationChanged(int rotation) {
Craig Mautnereda67292013-04-28 13:50:14 -0700864 if (localLOGV) Slog.v(TAG, "onProposedRotationChanged, rotation=" + rotation);
Chong Zhang5aaa0b32015-08-28 10:22:36 -0700865 mHandler.post(mUpdateRotationRunnable);
Jeff Brown01a98dd2011-09-20 15:08:29 -0700866 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800867 }
868 MyOrientationListener mOrientationListener;
869
Jorim Jaggi24bec7c2015-02-04 12:40:14 +0100870 private final StatusBarController mStatusBarController = new StatusBarController();
John Spurlock5b9145b2013-08-20 15:13:47 -0400871
John Spurlock27735a42013-08-14 17:57:38 -0400872 private final BarController mNavigationBarController = new BarController("NavigationBar",
John Spurlock5b9145b2013-08-20 15:13:47 -0400873 View.NAVIGATION_BAR_TRANSIENT,
874 View.NAVIGATION_BAR_UNHIDE,
John Spurlockbd957402013-10-03 11:38:39 -0400875 View.NAVIGATION_BAR_TRANSLUCENT,
876 StatusBarManager.WINDOW_NAVIGATION_BAR,
Jorim Jaggi4fa78922015-11-30 17:13:56 -0800877 WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION,
878 View.NAVIGATION_BAR_TRANSPARENT);
John Spurlock5b9145b2013-08-20 15:13:47 -0400879
John Spurlockf1a36642013-10-12 17:50:42 -0400880 private ImmersiveModeConfirmation mImmersiveModeConfirmation;
John Spurlock32beb2c2013-03-11 10:16:47 -0400881
Craig Mautner037aa8d2013-06-07 10:35:44 -0700882 private SystemGesturesPointerEventListener mSystemGestures;
John Spurlock32beb2c2013-03-11 10:16:47 -0400883
Dianne Hackborn42e620c2012-06-24 13:20:51 -0700884 IStatusBarService getStatusBarService() {
885 synchronized (mServiceAquireLock) {
886 if (mStatusBarService == null) {
887 mStatusBarService = IStatusBarService.Stub.asInterface(
888 ServiceManager.getService("statusbar"));
889 }
890 return mStatusBarService;
891 }
892 }
893
Jorim Jaggi86905582016-02-09 21:36:09 -0800894 StatusBarManagerInternal getStatusBarManagerInternal() {
895 synchronized (mServiceAquireLock) {
896 if (mStatusBarManagerInternal == null) {
897 mStatusBarManagerInternal =
898 LocalServices.getService(StatusBarManagerInternal.class);
899 }
900 return mStatusBarManagerInternal;
901 }
902 }
903
Suchi Amalapurapua9e1b162009-03-24 22:24:47 -0700904 /*
905 * We always let the sensor be switched on by default except when
906 * the user has explicitly disabled sensor based rotation or when the
907 * screen is switched off.
908 */
The Android Open Source Project0727d222009-03-11 12:11:58 -0700909 boolean needSensorRunningLp() {
Jeff Brownbcdfc622014-03-06 19:13:04 -0800910 if (mSupportAutoRotation) {
911 if (mCurrentAppOrientation == ActivityInfo.SCREEN_ORIENTATION_SENSOR
912 || mCurrentAppOrientation == ActivityInfo.SCREEN_ORIENTATION_FULL_SENSOR
913 || mCurrentAppOrientation == ActivityInfo.SCREEN_ORIENTATION_SENSOR_PORTRAIT
914 || mCurrentAppOrientation == ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE) {
915 // If the application has explicitly requested to follow the
916 // orientation, then we need to turn the sensor on.
917 return true;
918 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800919 }
Dianne Hackborn867ab6472010-04-29 13:28:56 -0700920 if ((mCarDockEnablesAccelerometer && mDockMode == Intent.EXTRA_DOCK_STATE_CAR) ||
Jeff Brown1a693182011-11-08 14:44:16 -0800921 (mDeskDockEnablesAccelerometer && (mDockMode == Intent.EXTRA_DOCK_STATE_DESK
922 || mDockMode == Intent.EXTRA_DOCK_STATE_LE_DESK
923 || mDockMode == Intent.EXTRA_DOCK_STATE_HE_DESK))) {
Mike Lockwoode9867d22009-09-20 01:59:02 -0400924 // enable accelerometer if we are docked in a dock that enables accelerometer
925 // orientation management,
926 return true;
927 }
Jeff Brown207673cd2012-06-05 17:47:11 -0700928 if (mUserRotationMode == USER_ROTATION_LOCKED) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800929 // If the setting for using the sensor by default is enabled, then
930 // we will always leave it on. Note that the user could go to
931 // a window that forces an orientation that does not use the
932 // sensor and in theory we could turn it off... however, when next
933 // turning it on we won't have a good value for the current
934 // orientation for a little bit, which can cause orientation
935 // changes to lag, so we'd like to keep it always on. (It will
936 // still be turned off when the screen is off.)
Suchi Amalapurapua9e1b162009-03-24 22:24:47 -0700937 return false;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800938 }
Jeff Brownbcdfc622014-03-06 19:13:04 -0800939 return mSupportAutoRotation;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800940 }
Craig Mautner46ac6fa2013-08-01 10:06:34 -0700941
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800942 /*
943 * Various use cases for invoking this function
944 * screen turning off, should always disable listeners if already enabled
Craig Mautner46ac6fa2013-08-01 10:06:34 -0700945 * screen turned on and current app has sensor based orientation, enable listeners
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800946 * if not already enabled
947 * screen turned on and current app does not have sensor orientation, disable listeners if
948 * already enabled
949 * screen turning on and current app has sensor based orientation, enable listeners if needed
950 * screen turning on and current app has nosensor based orientation, do nothing
951 */
The Android Open Source Project0727d222009-03-11 12:11:58 -0700952 void updateOrientationListenerLp() {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800953 if (!mOrientationListener.canDetectOrientation()) {
954 // If sensor is turned off or nonexistent for some reason
955 return;
956 }
Stefan Kuhne9326dc12015-06-12 09:25:32 -1000957 // Could have been invoked due to screen turning on or off or
958 // change of the currently visible window's orientation.
Jeff Brown3ee549c2014-09-22 20:14:39 -0700959 if (localLOGV) Slog.v(TAG, "mScreenOnEarly=" + mScreenOnEarly
960 + ", mAwake=" + mAwake + ", mCurrentAppOrientation=" + mCurrentAppOrientation
Stefan Kuhne9326dc12015-06-12 09:25:32 -1000961 + ", mOrientationSensorEnabled=" + mOrientationSensorEnabled
962 + ", mKeyguardDrawComplete=" + mKeyguardDrawComplete
963 + ", mWindowManagerDrawComplete=" + mWindowManagerDrawComplete);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800964 boolean disable = true;
Stefan Kuhne9326dc12015-06-12 09:25:32 -1000965 // Note: We postpone the rotating of the screen until the keyguard as well as the
966 // window manager have reported a draw complete.
967 if (mScreenOnEarly && mAwake &&
968 mKeyguardDrawComplete && mWindowManagerDrawComplete) {
The Android Open Source Project0727d222009-03-11 12:11:58 -0700969 if (needSensorRunningLp()) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800970 disable = false;
971 //enable listener if not already enabled
The Android Open Source Project0727d222009-03-11 12:11:58 -0700972 if (!mOrientationSensorEnabled) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800973 mOrientationListener.enable();
Craig Mautnereda67292013-04-28 13:50:14 -0700974 if(localLOGV) Slog.v(TAG, "Enabling listeners");
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800975 mOrientationSensorEnabled = true;
976 }
Craig Mautner46ac6fa2013-08-01 10:06:34 -0700977 }
978 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800979 //check if sensors need to be disabled
The Android Open Source Project0727d222009-03-11 12:11:58 -0700980 if (disable && mOrientationSensorEnabled) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800981 mOrientationListener.disable();
Craig Mautnereda67292013-04-28 13:50:14 -0700982 if(localLOGV) Slog.v(TAG, "Disabling listeners");
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800983 mOrientationSensorEnabled = false;
984 }
985 }
986
Jeff Brown13f00f02014-10-31 14:45:50 -0700987 private void interceptPowerKeyDown(KeyEvent event, boolean interactive) {
988 // Hold a wake lock until the power key is released.
989 if (!mPowerKeyWakeLock.isHeld()) {
990 mPowerKeyWakeLock.acquire();
991 }
992
993 // Cancel multi-press detection timeout.
994 if (mPowerKeyPressCounter != 0) {
995 mHandler.removeMessages(MSG_POWER_DELAYED_PRESS);
996 }
997
998 // Detect user pressing the power button in panic when an application has
999 // taken over the whole screen.
1000 boolean panic = mImmersiveModeConfirmation.onPowerKeyDown(interactive,
Craig Mautner0124980e92014-11-30 21:15:34 -08001001 SystemClock.elapsedRealtime(), isImmersiveMode(mLastSystemUiFlags));
Jeff Brown13f00f02014-10-31 14:45:50 -07001002 if (panic) {
Adrian Roosddc8b272015-05-21 16:28:27 -07001003 mHandler.post(mHiddenNavPanic);
Jeff Brown13f00f02014-10-31 14:45:50 -07001004 }
1005
1006 // Latch power key state to detect screenshot chord.
1007 if (interactive && !mScreenshotChordPowerKeyTriggered
1008 && (event.getFlags() & KeyEvent.FLAG_FALLBACK) == 0) {
1009 mScreenshotChordPowerKeyTriggered = true;
1010 mScreenshotChordPowerKeyTime = event.getDownTime();
1011 interceptScreenshotChord();
1012 }
1013
1014 // Stop ringing or end call if configured to do so when power is pressed.
1015 TelecomManager telecomManager = getTelecommService();
1016 boolean hungUp = false;
1017 if (telecomManager != null) {
1018 if (telecomManager.isRinging()) {
1019 // Pressing Power while there's a ringing incoming
1020 // call should silence the ringer.
1021 telecomManager.silenceRinger();
1022 } else if ((mIncallPowerBehavior
1023 & Settings.Secure.INCALL_POWER_BUTTON_BEHAVIOR_HANGUP) != 0
1024 && telecomManager.isInCall() && interactive) {
1025 // Otherwise, if "Power button ends call" is enabled,
1026 // the Power button will hang up any current active call.
1027 hungUp = telecomManager.endCall();
1028 }
1029 }
1030
Adrian Roos5941c982015-09-03 15:59:49 -07001031 GestureLauncherService gestureService = LocalServices.getService(
1032 GestureLauncherService.class);
1033 boolean gesturedServiceIntercepted = false;
1034 if (gestureService != null) {
1035 gesturedServiceIntercepted = gestureService.interceptPowerKeyDown(event, interactive);
1036 }
1037
Jeff Brown13f00f02014-10-31 14:45:50 -07001038 // If the power key has still not yet been handled, then detect short
1039 // press, long press, or multi press and decide what to do.
1040 mPowerKeyHandled = hungUp || mScreenshotChordVolumeDownKeyTriggered
Adrian Roos5941c982015-09-03 15:59:49 -07001041 || mScreenshotChordVolumeUpKeyTriggered || gesturedServiceIntercepted;
Jeff Brown13f00f02014-10-31 14:45:50 -07001042 if (!mPowerKeyHandled) {
1043 if (interactive) {
1044 // When interactive, we're already awake.
1045 // Wait for a long press or for the button to be released to decide what to do.
1046 if (hasLongPressOnPowerBehavior()) {
1047 Message msg = mHandler.obtainMessage(MSG_POWER_LONG_PRESS);
1048 msg.setAsynchronous(true);
1049 mHandler.sendMessageDelayed(msg,
1050 ViewConfiguration.get(mContext).getDeviceGlobalActionKeyTimeout());
1051 }
1052 } else {
Bryce Leed9268e32014-11-17 17:40:59 -08001053 wakeUpFromPowerKey(event.getDownTime());
Bryce Leed9268e32014-11-17 17:40:59 -08001054
Bryce Leed3b28402015-03-09 15:49:13 +00001055 if (mSupportLongPressPowerWhenNonInteractive && hasLongPressOnPowerBehavior()) {
1056 Message msg = mHandler.obtainMessage(MSG_POWER_LONG_PRESS);
1057 msg.setAsynchronous(true);
1058 mHandler.sendMessageDelayed(msg,
1059 ViewConfiguration.get(mContext).getDeviceGlobalActionKeyTimeout());
Bryce Leed9268e32014-11-17 17:40:59 -08001060 mBeganFromNonInteractive = true;
Bryce Leed3b28402015-03-09 15:49:13 +00001061 } else {
1062 final int maxCount = getMaxMultiPressPowerCount();
1063
1064 if (maxCount <= 1) {
1065 mPowerKeyHandled = true;
1066 } else {
1067 mBeganFromNonInteractive = true;
1068 }
Jeff Brown13f00f02014-10-31 14:45:50 -07001069 }
1070 }
Jeff Brown4d396052010-10-29 21:50:21 -07001071 }
1072 }
1073
Jeff Brown13f00f02014-10-31 14:45:50 -07001074 private void interceptPowerKeyUp(KeyEvent event, boolean interactive, boolean canceled) {
1075 final boolean handled = canceled || mPowerKeyHandled;
1076 mScreenshotChordPowerKeyTriggered = false;
1077 cancelPendingScreenshotChordAction();
1078 cancelPendingPowerKeyAction();
1079
1080 if (!handled) {
1081 // Figure out how to handle the key now that it has been released.
1082 mPowerKeyPressCounter += 1;
1083
1084 final int maxCount = getMaxMultiPressPowerCount();
1085 final long eventTime = event.getDownTime();
1086 if (mPowerKeyPressCounter < maxCount) {
1087 // This could be a multi-press. Wait a little bit longer to confirm.
1088 // Continue holding the wake lock.
1089 Message msg = mHandler.obtainMessage(MSG_POWER_DELAYED_PRESS,
1090 interactive ? 1 : 0, mPowerKeyPressCounter, eventTime);
1091 msg.setAsynchronous(true);
1092 mHandler.sendMessageDelayed(msg, ViewConfiguration.getDoubleTapTimeout());
1093 return;
1094 }
1095
1096 // No other actions. Handle it immediately.
1097 powerPress(eventTime, interactive, mPowerKeyPressCounter);
Jeff Brown4d396052010-10-29 21:50:21 -07001098 }
Jeff Brown13f00f02014-10-31 14:45:50 -07001099
1100 // Done. Reset our state.
1101 finishPowerKeyPress();
1102 }
1103
1104 private void finishPowerKeyPress() {
Bryce Leed9268e32014-11-17 17:40:59 -08001105 mBeganFromNonInteractive = false;
Jeff Brown13f00f02014-10-31 14:45:50 -07001106 mPowerKeyPressCounter = 0;
1107 if (mPowerKeyWakeLock.isHeld()) {
1108 mPowerKeyWakeLock.release();
1109 }
Jeff Brownd5bb82d2011-10-12 13:57:59 -07001110 }
1111
1112 private void cancelPendingPowerKeyAction() {
1113 if (!mPowerKeyHandled) {
Jeff Brown13f00f02014-10-31 14:45:50 -07001114 mPowerKeyHandled = true;
1115 mHandler.removeMessages(MSG_POWER_LONG_PRESS);
Jeff Brownd5bb82d2011-10-12 13:57:59 -07001116 }
Jeff Brown13f00f02014-10-31 14:45:50 -07001117 }
1118
Anthony Hugh34f09ca2016-03-04 12:03:37 -08001119 private void cancelPendingBackKeyAction() {
1120 if (!mBackKeyHandled) {
1121 mBackKeyHandled = true;
1122 mHandler.removeMessages(MSG_BACK_LONG_PRESS);
1123 }
1124 }
1125
Jeff Brown13f00f02014-10-31 14:45:50 -07001126 private void powerPress(long eventTime, boolean interactive, int count) {
1127 if (mScreenOnEarly && !mScreenOnFully) {
1128 Slog.i(TAG, "Suppressed redundant power key press while "
1129 + "already in the process of turning the screen on.");
1130 return;
Jeff Brownff204712011-10-25 21:27:54 -07001131 }
Jeff Brown13f00f02014-10-31 14:45:50 -07001132
1133 if (count == 2) {
1134 powerMultiPressAction(eventTime, interactive, mDoublePressOnPowerBehavior);
1135 } else if (count == 3) {
1136 powerMultiPressAction(eventTime, interactive, mTriplePressOnPowerBehavior);
Bryce Leed9268e32014-11-17 17:40:59 -08001137 } else if (interactive && !mBeganFromNonInteractive) {
Jeff Brown13f00f02014-10-31 14:45:50 -07001138 switch (mShortPressOnPowerBehavior) {
1139 case SHORT_PRESS_POWER_NOTHING:
1140 break;
1141 case SHORT_PRESS_POWER_GO_TO_SLEEP:
1142 mPowerManager.goToSleep(eventTime,
1143 PowerManager.GO_TO_SLEEP_REASON_POWER_BUTTON, 0);
1144 break;
1145 case SHORT_PRESS_POWER_REALLY_GO_TO_SLEEP:
1146 mPowerManager.goToSleep(eventTime,
1147 PowerManager.GO_TO_SLEEP_REASON_POWER_BUTTON,
1148 PowerManager.GO_TO_SLEEP_FLAG_NO_DOZE);
1149 break;
1150 case SHORT_PRESS_POWER_REALLY_GO_TO_SLEEP_AND_GO_HOME:
1151 mPowerManager.goToSleep(eventTime,
1152 PowerManager.GO_TO_SLEEP_REASON_POWER_BUTTON,
1153 PowerManager.GO_TO_SLEEP_FLAG_NO_DOZE);
1154 launchHomeFromHotKey();
1155 break;
Bryce Lee01b0c5f2015-02-05 18:24:04 -08001156 case SHORT_PRESS_POWER_GO_HOME:
Bryce Lee662ed802015-04-10 20:11:39 +00001157 launchHomeFromHotKey(true /* awakenFromDreams */, false /*respectKeyguard*/);
Bryce Lee01b0c5f2015-02-05 18:24:04 -08001158 break;
Jeff Brown13f00f02014-10-31 14:45:50 -07001159 }
1160 }
1161 }
1162
1163 private void powerMultiPressAction(long eventTime, boolean interactive, int behavior) {
1164 switch (behavior) {
1165 case MULTI_PRESS_POWER_NOTHING:
1166 break;
1167 case MULTI_PRESS_POWER_THEATER_MODE:
Bryce Lee3ae447e2015-06-30 12:31:41 -07001168 if (!isUserSetupComplete()) {
1169 Slog.i(TAG, "Ignoring toggling theater mode - device not setup.");
1170 break;
1171 }
1172
Jeff Brown13f00f02014-10-31 14:45:50 -07001173 if (isTheaterModeEnabled()) {
1174 Slog.i(TAG, "Toggling theater mode off.");
1175 Settings.Global.putInt(mContext.getContentResolver(),
1176 Settings.Global.THEATER_MODE_ON, 0);
1177 if (!interactive) {
1178 wakeUpFromPowerKey(eventTime);
1179 }
1180 } else {
1181 Slog.i(TAG, "Toggling theater mode on.");
1182 Settings.Global.putInt(mContext.getContentResolver(),
1183 Settings.Global.THEATER_MODE_ON, 1);
Bryce Lee55e846d2014-11-04 12:43:44 -08001184
1185 if (mGoToSleepOnButtonPressTheaterMode && interactive) {
Jeff Brown13f00f02014-10-31 14:45:50 -07001186 mPowerManager.goToSleep(eventTime,
1187 PowerManager.GO_TO_SLEEP_REASON_POWER_BUTTON, 0);
1188 }
1189 }
1190 break;
1191 case MULTI_PRESS_POWER_BRIGHTNESS_BOOST:
Jeff Brown7b5be5e2014-11-12 18:45:31 -08001192 Slog.i(TAG, "Starting brightness boost.");
1193 if (!interactive) {
1194 wakeUpFromPowerKey(eventTime);
1195 }
Jeff Brown13f00f02014-10-31 14:45:50 -07001196 mPowerManager.boostScreenBrightness(eventTime);
1197 break;
1198 }
1199 }
1200
1201 private int getMaxMultiPressPowerCount() {
1202 if (mTriplePressOnPowerBehavior != MULTI_PRESS_POWER_NOTHING) {
1203 return 3;
1204 }
1205 if (mDoublePressOnPowerBehavior != MULTI_PRESS_POWER_NOTHING) {
1206 return 2;
1207 }
1208 return 1;
1209 }
1210
1211 private void powerLongPress() {
1212 final int behavior = getResolvedLongPressOnPowerBehavior();
1213 switch (behavior) {
1214 case LONG_PRESS_POWER_NOTHING:
1215 break;
1216 case LONG_PRESS_POWER_GLOBAL_ACTIONS:
1217 mPowerKeyHandled = true;
1218 if (!performHapticFeedbackLw(null, HapticFeedbackConstants.LONG_PRESS, false)) {
1219 performAuditoryFeedbackForAccessibilityIfNeed();
1220 }
1221 showGlobalActionsInternal();
1222 break;
1223 case LONG_PRESS_POWER_SHUT_OFF:
1224 case LONG_PRESS_POWER_SHUT_OFF_NO_CONFIRM:
1225 mPowerKeyHandled = true;
1226 performHapticFeedbackLw(null, HapticFeedbackConstants.LONG_PRESS, false);
1227 sendCloseSystemWindows(SYSTEM_DIALOG_REASON_GLOBAL_ACTIONS);
1228 mWindowManagerFuncs.shutdown(behavior == LONG_PRESS_POWER_SHUT_OFF);
1229 break;
1230 }
1231 }
1232
Anthony Hugh34f09ca2016-03-04 12:03:37 -08001233 private void backLongPress() {
1234 mBackKeyHandled = true;
1235
1236 switch (mLongPressOnBackBehavior) {
1237 case LONG_PRESS_BACK_NOTHING:
1238 break;
1239 case LONG_PRESS_BACK_GO_TO_VOICE_ASSIST:
1240 Intent intent = new Intent(Intent.ACTION_VOICE_ASSIST);
1241 startActivityAsUser(intent, UserHandle.CURRENT_OR_SELF);
1242 break;
1243 }
1244 }
1245
Nick Vaccarob593a812015-05-15 11:23:05 -07001246 private void sleepPress(long eventTime) {
1247 if (mShortPressOnSleepBehavior == SHORT_PRESS_SLEEP_GO_TO_SLEEP_AND_GO_HOME) {
1248 launchHomeFromHotKey(false /* awakenDreams */, true /*respectKeyguard*/);
1249 }
1250 }
1251
1252 private void sleepRelease(long eventTime) {
Filip Gruszczynskia483a1d2015-03-17 19:06:58 +00001253 switch (mShortPressOnSleepBehavior) {
1254 case SHORT_PRESS_SLEEP_GO_TO_SLEEP:
Filip Gruszczynskia483a1d2015-03-17 19:06:58 +00001255 case SHORT_PRESS_SLEEP_GO_TO_SLEEP_AND_GO_HOME:
Nick Vaccarob593a812015-05-15 11:23:05 -07001256 Slog.i(TAG, "sleepRelease() calling goToSleep(GO_TO_SLEEP_REASON_SLEEP_BUTTON)");
1257 mPowerManager.goToSleep(eventTime,
1258 PowerManager.GO_TO_SLEEP_REASON_SLEEP_BUTTON, 0);
Filip Gruszczynskia483a1d2015-03-17 19:06:58 +00001259 break;
1260 }
1261 }
1262
Jeff Brown13f00f02014-10-31 14:45:50 -07001263 private int getResolvedLongPressOnPowerBehavior() {
1264 if (FactoryTest.isLongPressOnPowerOffEnabled()) {
1265 return LONG_PRESS_POWER_SHUT_OFF_NO_CONFIRM;
1266 }
1267 return mLongPressOnPowerBehavior;
1268 }
1269
1270 private boolean hasLongPressOnPowerBehavior() {
1271 return getResolvedLongPressOnPowerBehavior() != LONG_PRESS_POWER_NOTHING;
Jeff Brownd5bb82d2011-10-12 13:57:59 -07001272 }
1273
Anthony Hugh34f09ca2016-03-04 12:03:37 -08001274 private boolean hasLongPressOnBackBehavior() {
1275 return mLongPressOnBackBehavior != LONG_PRESS_BACK_NOTHING;
1276 }
1277
Jeff Brownd5bb82d2011-10-12 13:57:59 -07001278 private void interceptScreenshotChord() {
Christopher Tatee90585f2012-03-05 18:56:25 -08001279 if (mScreenshotChordEnabled
Jeff Brown13f00f02014-10-31 14:45:50 -07001280 && mScreenshotChordVolumeDownKeyTriggered && mScreenshotChordPowerKeyTriggered
1281 && !mScreenshotChordVolumeUpKeyTriggered) {
Jeff Brownd5bb82d2011-10-12 13:57:59 -07001282 final long now = SystemClock.uptimeMillis();
Jeff Brown13f00f02014-10-31 14:45:50 -07001283 if (now <= mScreenshotChordVolumeDownKeyTime + SCREENSHOT_CHORD_DEBOUNCE_DELAY_MILLIS
1284 && now <= mScreenshotChordPowerKeyTime
1285 + SCREENSHOT_CHORD_DEBOUNCE_DELAY_MILLIS) {
1286 mScreenshotChordVolumeDownKeyConsumed = true;
Jeff Brownd5bb82d2011-10-12 13:57:59 -07001287 cancelPendingPowerKeyAction();
Muyuan Li6ca619f2016-03-08 13:30:42 -08001288 mScreenshotRunnable.setScreenshotType(TAKE_SCREENSHOT_FULLSCREEN);
Jeff Sharkey2991fa32012-12-05 18:06:43 -08001289 mHandler.postDelayed(mScreenshotRunnable, getScreenshotChordLongPressDelay());
Jeff Brownd5bb82d2011-10-12 13:57:59 -07001290 }
1291 }
1292 }
1293
Winson Chung1cea2f32012-10-08 20:42:01 -07001294 private long getScreenshotChordLongPressDelay() {
Jim Miller5ecd8112013-01-09 18:50:26 -08001295 if (mKeyguardDelegate.isShowing()) {
Winson Chung1cea2f32012-10-08 20:42:01 -07001296 // Double the time it takes to take a screenshot from the keyguard
1297 return (long) (KEYGUARD_SCREENSHOT_CHORD_DELAY_MULTIPLIER *
Justin Kohfeabd2c2014-05-02 10:02:44 -07001298 ViewConfiguration.get(mContext).getDeviceGlobalActionKeyTimeout());
Winson Chung1cea2f32012-10-08 20:42:01 -07001299 }
Justin Kohfeabd2c2014-05-02 10:02:44 -07001300 return ViewConfiguration.get(mContext).getDeviceGlobalActionKeyTimeout();
Winson Chung1cea2f32012-10-08 20:42:01 -07001301 }
1302
Jeff Brownd5bb82d2011-10-12 13:57:59 -07001303 private void cancelPendingScreenshotChordAction() {
Jeff Sharkey2991fa32012-12-05 18:06:43 -08001304 mHandler.removeCallbacks(mScreenshotRunnable);
Jeff Brown4d396052010-10-29 21:50:21 -07001305 }
1306
Jeff Brown13f00f02014-10-31 14:45:50 -07001307 private final Runnable mEndCallLongPress = new Runnable() {
Craig Mautnerf1b67412012-09-19 13:18:29 -07001308 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001309 public void run() {
Jeff Brown13f00f02014-10-31 14:45:50 -07001310 mEndCallKeyHandled = true;
1311 if (!performHapticFeedbackLw(null, HapticFeedbackConstants.LONG_PRESS, false)) {
1312 performAuditoryFeedbackForAccessibilityIfNeed();
Joe Onoratod208e702010-10-08 16:22:43 -04001313 }
Jeff Brown13f00f02014-10-31 14:45:50 -07001314 showGlobalActionsInternal();
Jeff Brownd5bb82d2011-10-12 13:57:59 -07001315 }
1316 };
1317
Muyuan Li6ca619f2016-03-08 13:30:42 -08001318 private class ScreenshotRunnable implements Runnable {
1319 private int mScreenshotType = TAKE_SCREENSHOT_FULLSCREEN;
1320
1321 public void setScreenshotType(int screenshotType) {
1322 mScreenshotType = screenshotType;
1323 }
1324
Craig Mautner0bf6ec92012-12-18 08:33:27 -08001325 @Override
Jeff Brownd5bb82d2011-10-12 13:57:59 -07001326 public void run() {
Muyuan Li6ca619f2016-03-08 13:30:42 -08001327 takeScreenshot(mScreenshotType);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001328 }
Muyuan Li6ca619f2016-03-08 13:30:42 -08001329 }
1330
1331 private final ScreenshotRunnable mScreenshotRunnable = new ScreenshotRunnable();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001332
Alan Viverettee34560b22014-07-10 14:50:06 -07001333 @Override
1334 public void showGlobalActions() {
1335 mHandler.removeMessages(MSG_DISPATCH_SHOW_GLOBAL_ACTIONS);
1336 mHandler.sendEmptyMessage(MSG_DISPATCH_SHOW_GLOBAL_ACTIONS);
1337 }
1338
1339 void showGlobalActionsInternal() {
1340 sendCloseSystemWindows(SYSTEM_DIALOG_REASON_GLOBAL_ACTIONS);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001341 if (mGlobalActions == null) {
Jeff Brown7304c342012-05-11 18:42:42 -07001342 mGlobalActions = new GlobalActions(mContext, mWindowManagerFuncs);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001343 }
Jim Millerab954542014-10-10 18:21:49 -07001344 final boolean keyguardShowing = isKeyguardShowingAndNotOccluded();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001345 mGlobalActions.showDialog(keyguardShowing, isDeviceProvisioned());
1346 if (keyguardShowing) {
1347 // since it took two seconds of long press to bring this up,
1348 // poke the wake lock so they have some time to see the dialog.
Jim Miller25190572013-02-28 17:36:24 -08001349 mPowerManager.userActivity(SystemClock.uptimeMillis(), false);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001350 }
1351 }
1352
1353 boolean isDeviceProvisioned() {
Jeff Brownbf6f6f92012-09-25 15:03:20 -07001354 return Settings.Global.getInt(
1355 mContext.getContentResolver(), Settings.Global.DEVICE_PROVISIONED, 0) != 0;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001356 }
1357
Maurice Lam99c6e072014-04-28 18:24:28 -07001358 boolean isUserSetupComplete() {
1359 return Settings.Secure.getIntForUser(mContext.getContentResolver(),
1360 Settings.Secure.USER_SETUP_COMPLETE, 0, UserHandle.USER_CURRENT) != 0;
1361 }
1362
Jeff Brown13f00f02014-10-31 14:45:50 -07001363 private void handleShortPressOnHome() {
Jinsuk Kime601b712015-07-07 08:01:02 +09001364 // Turn on the connected TV and switch HDMI input if we're a HDMI playback device.
1365 getHdmiControl().turnOnTv();
1366
Jeff Brown13f00f02014-10-31 14:45:50 -07001367 // If there's a dream running then use home to escape the dream
1368 // but don't actually go home.
1369 if (mDreamManagerInternal != null && mDreamManagerInternal.isDreaming()) {
1370 mDreamManagerInternal.stopDream(false /*immediate*/);
1371 return;
1372 }
1373
1374 // Go home!
1375 launchHomeFromHotKey();
1376 }
1377
Jinsuk Kime601b712015-07-07 08:01:02 +09001378 /**
1379 * Creates an accessor to HDMI control service that performs the operation of
1380 * turning on TV (optional) and switching input to us. If HDMI control service
1381 * is not available or we're not a HDMI playback device, the operation is no-op.
1382 */
1383 private HdmiControl getHdmiControl() {
1384 if (null == mHdmiControl) {
1385 HdmiControlManager manager = (HdmiControlManager) mContext.getSystemService(
1386 Context.HDMI_CONTROL_SERVICE);
1387 HdmiPlaybackClient client = null;
1388 if (manager != null) {
1389 client = manager.getPlaybackClient();
1390 }
1391 mHdmiControl = new HdmiControl(client);
1392 }
1393 return mHdmiControl;
1394 }
1395
1396 private static class HdmiControl {
1397 private final HdmiPlaybackClient mClient;
1398
1399 private HdmiControl(HdmiPlaybackClient client) {
1400 mClient = client;
1401 }
1402
1403 public void turnOnTv() {
1404 if (mClient == null) {
1405 return;
1406 }
1407 mClient.oneTouchPlay(new OneTouchPlayCallback() {
1408 @Override
1409 public void onComplete(int result) {
1410 if (result != HdmiControlManager.RESULT_SUCCESS) {
1411 Log.w(TAG, "One touch play failed: " + result);
1412 }
1413 }
1414 });
1415 }
1416 }
1417
Jaewan Kim76b7d0d2016-02-12 19:01:02 +09001418 private void handleLongPressOnHome(int deviceId) {
Jaewan Kim52632e22016-01-14 18:01:52 +09001419 if (mLongPressOnHomeBehavior == LONG_PRESS_HOME_NOTHING) {
1420 return;
1421 }
1422 mHomeConsumed = true;
1423 performHapticFeedbackLw(null, HapticFeedbackConstants.LONG_PRESS, false);
Patrick Dubroyece94522011-02-23 18:35:01 -08001424
Jaewan Kim52632e22016-01-14 18:01:52 +09001425 switch (mLongPressOnHomeBehavior) {
1426 case LONG_PRESS_HOME_RECENT_SYSTEM_UI:
Jeff Browncaca8812013-05-09 13:34:33 -07001427 toggleRecentApps();
Jaewan Kim52632e22016-01-14 18:01:52 +09001428 break;
1429 case LONG_PRESS_HOME_ASSIST:
Tim Kilbourn0e5f1102015-06-05 16:18:09 -07001430 launchAssistAction(null, deviceId);
Jaewan Kim52632e22016-01-14 18:01:52 +09001431 break;
Jaewan Kim52632e22016-01-14 18:01:52 +09001432 default:
Jaewan Kim76b7d0d2016-02-12 19:01:02 +09001433 Log.w(TAG, "Undefined home long press behavior: " + mLongPressOnHomeBehavior);
Jaewan Kim52632e22016-01-14 18:01:52 +09001434 break;
Jim Millere6ad1a82010-08-20 19:25:39 -07001435 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001436 }
Patrick Dubroyece94522011-02-23 18:35:01 -08001437
Jeff Browncaca8812013-05-09 13:34:33 -07001438 private void handleDoubleTapOnHome() {
1439 if (mDoubleTapOnHomeBehavior == DOUBLE_TAP_HOME_RECENT_SYSTEM_UI) {
1440 mHomeConsumed = true;
1441 toggleRecentApps();
1442 }
1443 }
1444
Jaewan Kimc552b042016-01-18 16:08:45 +09001445 private void requestTvPictureInPicture(KeyEvent event) {
1446 if (DEBUG_INPUT) Log.d(TAG, "requestTvPictureInPicture event=" + event);
1447 mHandler.removeMessages(MSG_REQUEST_TV_PICTURE_IN_PICTURE);
1448 Message msg = mHandler.obtainMessage(MSG_REQUEST_TV_PICTURE_IN_PICTURE);
1449 msg.setAsynchronous(true);
1450 msg.sendToTarget();
1451 }
1452
1453 private void requestTvPictureInPictureInternal() {
1454 try {
1455 IStatusBarService statusbar = getStatusBarService();
1456 if (statusbar != null) {
1457 statusbar.requestTvPictureInPicture();
1458 }
1459 } catch (RemoteException|IllegalArgumentException e) {
1460 Slog.e(TAG, "Cannot handle picture-in-picture key", e);
1461 // re-acquire status bar service next time it is needed.
1462 mStatusBarService = null;
1463 }
Jaewan Kim52632e22016-01-14 18:01:52 +09001464 }
1465
Jeff Browncaca8812013-05-09 13:34:33 -07001466 private final Runnable mHomeDoubleTapTimeoutRunnable = new Runnable() {
1467 @Override
1468 public void run() {
1469 if (mHomeDoubleTapPending) {
1470 mHomeDoubleTapPending = false;
Jeff Brown13f00f02014-10-31 14:45:50 -07001471 handleShortPressOnHome();
Jeff Browncaca8812013-05-09 13:34:33 -07001472 }
1473 }
1474 };
1475
Mark Renoufc1256912015-03-11 14:38:23 -04001476 private boolean isRoundWindow() {
Adam Powell01f280d2015-05-18 16:07:42 -07001477 return mContext.getResources().getConfiguration().isScreenRound();
Mark Renoufc1256912015-03-11 14:38:23 -04001478 }
1479
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001480 /** {@inheritDoc} */
Craig Mautner0bf6ec92012-12-18 08:33:27 -08001481 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001482 public void init(Context context, IWindowManager windowManager,
Jeff Brown96307042012-07-27 15:51:34 -07001483 WindowManagerFuncs windowManagerFuncs) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001484 mContext = context;
1485 mWindowManager = windowManager;
Dianne Hackborndf89e652011-10-06 22:35:11 -07001486 mWindowManagerFuncs = windowManagerFuncs;
Craig Mautner8a0da012014-05-31 15:13:37 -07001487 mWindowManagerInternal = LocalServices.getService(WindowManagerInternal.class);
Jeff Brown061ea992015-04-17 19:55:47 -07001488 mActivityManagerInternal = LocalServices.getService(ActivityManagerInternal.class);
Jose Lima9546b202014-07-02 17:21:51 -07001489 mDreamManagerInternal = LocalServices.getService(DreamManagerInternal.class);
Michael Wrighta4d22d72015-09-16 23:19:26 +01001490 mPowerManagerInternal = LocalServices.getService(PowerManagerInternal.class);
Billy Laucbe540f2015-06-25 01:51:44 +01001491 mAppOpsManager = (AppOpsManager) mContext.getSystemService(Context.APP_OPS_SERVICE);
Mark Renoufc1256912015-03-11 14:38:23 -04001492
1493 // Init display burn-in protection
1494 boolean burnInProtectionEnabled = context.getResources().getBoolean(
1495 com.android.internal.R.bool.config_enableBurnInProtection);
1496 // Allow a system property to override this. Used by developer settings.
1497 boolean burnInProtectionDevMode =
1498 SystemProperties.getBoolean("persist.debug.force_burn_in", false);
1499 if (burnInProtectionEnabled || burnInProtectionDevMode) {
1500 final int minHorizontal;
1501 final int maxHorizontal;
1502 final int minVertical;
1503 final int maxVertical;
1504 final int maxRadius;
1505 if (burnInProtectionDevMode) {
1506 minHorizontal = -8;
1507 maxHorizontal = 8;
1508 minVertical = -8;
1509 maxVertical = -4;
1510 maxRadius = (isRoundWindow()) ? 6 : -1;
1511 } else {
1512 Resources resources = context.getResources();
1513 minHorizontal = resources.getInteger(
1514 com.android.internal.R.integer.config_burnInProtectionMinHorizontalOffset);
1515 maxHorizontal = resources.getInteger(
1516 com.android.internal.R.integer.config_burnInProtectionMaxHorizontalOffset);
1517 minVertical = resources.getInteger(
1518 com.android.internal.R.integer.config_burnInProtectionMinVerticalOffset);
1519 maxVertical = resources.getInteger(
1520 com.android.internal.R.integer.config_burnInProtectionMaxVerticalOffset);
1521 maxRadius = resources.getInteger(
1522 com.android.internal.R.integer.config_burnInProtectionMaxRadius);
1523 }
1524 mBurnInProtectionHelper = new BurnInProtectionHelper(
1525 context, minHorizontal, maxHorizontal, minVertical, maxVertical, maxRadius);
Filip Gruszczynskicfb31852015-02-25 21:47:12 +00001526 }
Craig Mautner8a0da012014-05-31 15:13:37 -07001527
Jeff Brown70825162012-03-28 17:27:48 -07001528 mHandler = new PolicyHandler();
Jeff Browna20dda42014-05-27 20:57:24 -07001529 mWakeGestureListener = new MyWakeGestureListener(mContext, mHandler);
Craig Mautnereee29c42013-01-17 14:44:34 -08001530 mOrientationListener = new MyOrientationListener(mContext, mHandler);
Jeff Brownc0347aa2011-09-23 17:26:09 -07001531 try {
1532 mOrientationListener.setCurrentRotation(windowManager.getRotation());
1533 } catch (RemoteException ex) { }
Christopher Tate5e08af02012-09-21 17:17:22 -07001534 mSettingsObserver = new SettingsObserver(mHandler);
1535 mSettingsObserver.observe();
Svetoslav683914b2015-01-15 14:22:26 -08001536 mShortcutManager = new ShortcutManager(context);
Daniel Sandler6396c722013-04-16 20:19:09 -04001537 mUiMode = context.getResources().getInteger(
1538 com.android.internal.R.integer.config_defaultUiModeType);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001539 mHomeIntent = new Intent(Intent.ACTION_MAIN, null);
1540 mHomeIntent.addCategory(Intent.CATEGORY_HOME);
1541 mHomeIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK
1542 | Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED);
keunyounga7710492015-09-23 11:33:58 -07001543 mEnableCarDockHomeCapture = context.getResources().getBoolean(
1544 com.android.internal.R.bool.config_enableCarDockHomeLaunch);
Dianne Hackborn39c2d712009-09-22 11:41:31 -07001545 mCarDockIntent = new Intent(Intent.ACTION_MAIN, null);
1546 mCarDockIntent.addCategory(Intent.CATEGORY_CAR_DOCK);
1547 mCarDockIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK
1548 | Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED);
1549 mDeskDockIntent = new Intent(Intent.ACTION_MAIN, null);
1550 mDeskDockIntent.addCategory(Intent.CATEGORY_DESK_DOCK);
1551 mDeskDockIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK
1552 | Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED);
Jim Millere6ad1a82010-08-20 19:25:39 -07001553
Jeff Brown96307042012-07-27 15:51:34 -07001554 mPowerManager = (PowerManager)context.getSystemService(Context.POWER_SERVICE);
1555 mBroadcastWakeLock = mPowerManager.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK,
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001556 "PhoneWindowManager.mBroadcastWakeLock");
Jeff Brown13f00f02014-10-31 14:45:50 -07001557 mPowerKeyWakeLock = mPowerManager.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK,
1558 "PhoneWindowManager.mPowerKeyWakeLock");
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001559 mEnableShiftMenuBugReports = "1".equals(SystemProperties.get("ro.debuggable"));
Jeff Brownbcdfc622014-03-06 19:13:04 -08001560 mSupportAutoRotation = mContext.getResources().getBoolean(
1561 com.android.internal.R.bool.config_supportAutoRotation);
Dianne Hackborn2862fff2009-09-15 22:56:29 -07001562 mLidOpenRotation = readRotation(
Mike Lockwood2d1efbd2009-09-16 12:15:53 -04001563 com.android.internal.R.integer.config_lidOpenRotation);
1564 mCarDockRotation = readRotation(
1565 com.android.internal.R.integer.config_carDockRotation);
1566 mDeskDockRotation = readRotation(
1567 com.android.internal.R.integer.config_deskDockRotation);
Jeff Brownc82c89ed2013-04-17 17:18:15 -07001568 mUndockedHdmiRotation = readRotation(
1569 com.android.internal.R.integer.config_undockedHdmiRotation);
Mike Lockwoode9867d22009-09-20 01:59:02 -04001570 mCarDockEnablesAccelerometer = mContext.getResources().getBoolean(
1571 com.android.internal.R.bool.config_carDockEnablesAccelerometer);
1572 mDeskDockEnablesAccelerometer = mContext.getResources().getBoolean(
1573 com.android.internal.R.bool.config_deskDockEnablesAccelerometer);
Dianne Hackborn2862fff2009-09-15 22:56:29 -07001574 mLidKeyboardAccessibility = mContext.getResources().getInteger(
1575 com.android.internal.R.integer.config_lidKeyboardAccessibility);
1576 mLidNavigationAccessibility = mContext.getResources().getInteger(
1577 com.android.internal.R.integer.config_lidNavigationAccessibility);
Edward Savage-Jones7def60d2015-11-13 13:27:03 +01001578 mLidControlsScreenLock = mContext.getResources().getBoolean(
1579 com.android.internal.R.bool.config_lidControlsScreenLock);
Jeff Brownc458ce92012-04-30 14:58:40 -07001580 mLidControlsSleep = mContext.getResources().getBoolean(
1581 com.android.internal.R.bool.config_lidControlsSleep);
Daniel Sandlerdd73ee42013-10-11 22:19:59 -04001582 mTranslucentDecorEnabled = mContext.getResources().getBoolean(
1583 com.android.internal.R.bool.config_enableTranslucentDecor);
Bryce Lee584a4452014-10-21 15:55:55 -07001584
1585 mAllowTheaterModeWakeFromKey = mContext.getResources().getBoolean(
1586 com.android.internal.R.bool.config_allowTheaterModeWakeFromKey);
1587 mAllowTheaterModeWakeFromPowerKey = mAllowTheaterModeWakeFromKey
1588 || mContext.getResources().getBoolean(
1589 com.android.internal.R.bool.config_allowTheaterModeWakeFromPowerKey);
1590 mAllowTheaterModeWakeFromMotion = mContext.getResources().getBoolean(
1591 com.android.internal.R.bool.config_allowTheaterModeWakeFromMotion);
Bryce Lee812d7022014-11-10 13:33:28 -08001592 mAllowTheaterModeWakeFromMotionWhenNotDreaming = mContext.getResources().getBoolean(
1593 com.android.internal.R.bool.config_allowTheaterModeWakeFromMotionWhenNotDreaming);
Bryce Lee584a4452014-10-21 15:55:55 -07001594 mAllowTheaterModeWakeFromCameraLens = mContext.getResources().getBoolean(
1595 com.android.internal.R.bool.config_allowTheaterModeWakeFromCameraLens);
1596 mAllowTheaterModeWakeFromLidSwitch = mContext.getResources().getBoolean(
1597 com.android.internal.R.bool.config_allowTheaterModeWakeFromLidSwitch);
1598 mAllowTheaterModeWakeFromWakeGesture = mContext.getResources().getBoolean(
1599 com.android.internal.R.bool.config_allowTheaterModeWakeFromGesture);
1600
Bryce Lee55e846d2014-11-04 12:43:44 -08001601 mGoToSleepOnButtonPressTheaterMode = mContext.getResources().getBoolean(
1602 com.android.internal.R.bool.config_goToSleepOnButtonPressTheaterMode);
1603
Bryce Leed3b28402015-03-09 15:49:13 +00001604 mSupportLongPressPowerWhenNonInteractive = mContext.getResources().getBoolean(
1605 com.android.internal.R.bool.config_supportLongPressPowerWhenNonInteractive);
1606
Anthony Hugh34f09ca2016-03-04 12:03:37 -08001607 mLongPressOnBackBehavior = mContext.getResources().getInteger(
1608 com.android.internal.R.integer.config_longPressOnBackBehavior);
1609
Jeff Brown13f00f02014-10-31 14:45:50 -07001610 mShortPressOnPowerBehavior = mContext.getResources().getInteger(
1611 com.android.internal.R.integer.config_shortPressOnPowerBehavior);
1612 mLongPressOnPowerBehavior = mContext.getResources().getInteger(
1613 com.android.internal.R.integer.config_longPressOnPowerBehavior);
1614 mDoublePressOnPowerBehavior = mContext.getResources().getInteger(
1615 com.android.internal.R.integer.config_doublePressOnPowerBehavior);
1616 mTriplePressOnPowerBehavior = mContext.getResources().getInteger(
1617 com.android.internal.R.integer.config_triplePressOnPowerBehavior);
Filip Gruszczynskia483a1d2015-03-17 19:06:58 +00001618 mShortPressOnSleepBehavior = mContext.getResources().getInteger(
1619 com.android.internal.R.integer.config_shortPressOnSleepBehavior);
Jeff Brown13f00f02014-10-31 14:45:50 -07001620
John Spurlock61560172015-02-06 19:46:04 -05001621 mUseTvRouting = AudioSystem.getPlatformType(mContext) == AudioSystem.PLATFORM_TELEVISION;
RoboErik001c59c2015-01-26 15:53:51 -08001622
Jeff Brownf71343d2013-05-31 17:59:11 -07001623 readConfigurationDependentBehaviors();
Jeff Browncaca8812013-05-09 13:34:33 -07001624
Svetoslav8e3feb12014-02-24 13:46:47 -08001625 mAccessibilityManager = (AccessibilityManager) context.getSystemService(
1626 Context.ACCESSIBILITY_SERVICE);
1627
Mike Lockwood1753f7f2009-08-24 14:49:07 -07001628 // register for dock events
Dianne Hackborn78968392010-03-04 20:47:56 -08001629 IntentFilter filter = new IntentFilter();
1630 filter.addAction(UiModeManager.ACTION_ENTER_CAR_MODE);
1631 filter.addAction(UiModeManager.ACTION_EXIT_CAR_MODE);
1632 filter.addAction(UiModeManager.ACTION_ENTER_DESK_MODE);
1633 filter.addAction(UiModeManager.ACTION_EXIT_DESK_MODE);
Dianne Hackborn867ab6472010-04-29 13:28:56 -07001634 filter.addAction(Intent.ACTION_DOCK_EVENT);
1635 Intent intent = context.registerReceiver(mDockReceiver, filter);
1636 if (intent != null) {
1637 // Retrieve current sticky dock event broadcast.
1638 mDockMode = intent.getIntExtra(Intent.EXTRA_DOCK_STATE,
1639 Intent.EXTRA_DOCK_STATE_UNDOCKED);
1640 }
Daniel Sandler7e37df52011-11-16 22:08:23 -08001641
Jeff Brown6aaf2952012-10-05 16:01:08 -07001642 // register for dream-related broadcasts
1643 filter = new IntentFilter();
1644 filter.addAction(Intent.ACTION_DREAMING_STARTED);
1645 filter.addAction(Intent.ACTION_DREAMING_STOPPED);
1646 context.registerReceiver(mDreamReceiver, filter);
1647
Christopher Tate5e08af02012-09-21 17:17:22 -07001648 // register for multiuser-relevant broadcasts
1649 filter = new IntentFilter(Intent.ACTION_USER_SWITCHED);
1650 context.registerReceiver(mMultiuserReceiver, filter);
1651
John Spurlock57306e62013-04-22 09:48:49 -04001652 // monitor for system gestures
Craig Mautner037aa8d2013-06-07 10:35:44 -07001653 mSystemGestures = new SystemGesturesPointerEventListener(context,
1654 new SystemGesturesPointerEventListener.Callbacks() {
John Spurlock57306e62013-04-22 09:48:49 -04001655 @Override
1656 public void onSwipeFromTop() {
John Spurlock04db1762013-05-13 12:46:41 -04001657 if (mStatusBar != null) {
John Spurlocke1f366f2013-08-05 12:22:40 -04001658 requestTransientBars(mStatusBar);
John Spurlock04db1762013-05-13 12:46:41 -04001659 }
John Spurlockad3e6cb2013-04-30 08:47:43 -04001660 }
1661 @Override
1662 public void onSwipeFromBottom() {
John Spurlock04db1762013-05-13 12:46:41 -04001663 if (mNavigationBar != null && mNavigationBarOnBottom) {
John Spurlocke1f366f2013-08-05 12:22:40 -04001664 requestTransientBars(mNavigationBar);
John Spurlockad3e6cb2013-04-30 08:47:43 -04001665 }
1666 }
1667 @Override
1668 public void onSwipeFromRight() {
John Spurlock04db1762013-05-13 12:46:41 -04001669 if (mNavigationBar != null && !mNavigationBarOnBottom) {
John Spurlocke1f366f2013-08-05 12:22:40 -04001670 requestTransientBars(mNavigationBar);
John Spurlockad3e6cb2013-04-30 08:47:43 -04001671 }
1672 }
1673 @Override
Michael Wrighta4d22d72015-09-16 23:19:26 +01001674 public void onFling(int duration) {
1675 if (mPowerManagerInternal != null) {
1676 mPowerManagerInternal.powerHint(
1677 PowerManagerInternal.POWER_HINT_INTERACTION, duration);
1678 }
1679 }
1680 @Override
John Spurlockad3e6cb2013-04-30 08:47:43 -04001681 public void onDebug() {
John Spurlockd67ec252013-09-05 11:31:54 -04001682 // no-op
John Spurlockad3e6cb2013-04-30 08:47:43 -04001683 }
Adrian Roos3595be42015-03-05 16:31:15 +01001684 @Override
1685 public void onDown() {
1686 mOrientationListener.onTouchStart();
1687 }
1688 @Override
1689 public void onUpOrCancel() {
1690 mOrientationListener.onTouchEnd();
1691 }
Jun Mukaid2e7e352015-07-22 17:14:02 -07001692 @Override
1693 public void onMouseHoverAtTop() {
1694 mHandler.removeMessages(MSG_REQUEST_TRANSIENT_BARS);
1695 Message msg = mHandler.obtainMessage(MSG_REQUEST_TRANSIENT_BARS);
1696 msg.arg1 = MSG_REQUEST_TRANSIENT_BARS_ARG_STATUS;
1697 mHandler.sendMessageDelayed(msg, 500);
1698 }
1699 @Override
1700 public void onMouseHoverAtBottom() {
1701 mHandler.removeMessages(MSG_REQUEST_TRANSIENT_BARS);
1702 Message msg = mHandler.obtainMessage(MSG_REQUEST_TRANSIENT_BARS);
1703 msg.arg1 = MSG_REQUEST_TRANSIENT_BARS_ARG_NAVIGATION;
1704 mHandler.sendMessageDelayed(msg, 500);
1705 }
1706 @Override
1707 public void onMouseLeaveFromEdge() {
1708 mHandler.removeMessages(MSG_REQUEST_TRANSIENT_BARS);
1709 }
John Spurlockad3e6cb2013-04-30 08:47:43 -04001710 });
John Spurlockf1a36642013-10-12 17:50:42 -04001711 mImmersiveModeConfirmation = new ImmersiveModeConfirmation(mContext);
Craig Mautner037aa8d2013-06-07 10:35:44 -07001712 mWindowManagerFuncs.registerPointerEventListener(mSystemGestures);
John Spurlock32beb2c2013-03-11 10:16:47 -04001713
Jeff Brownc2346132012-04-13 01:55:38 -07001714 mVibrator = (Vibrator)context.getSystemService(Context.VIBRATOR_SERVICE);
Dianne Hackbornb1a79802009-09-29 15:18:31 -07001715 mLongPressVibePattern = getLongIntArray(mContext.getResources(),
1716 com.android.internal.R.array.config_longPressVibePattern);
1717 mVirtualKeyVibePattern = getLongIntArray(mContext.getResources(),
1718 com.android.internal.R.array.config_virtualKeyVibePattern);
Amith Yamasanic33cb712010-02-10 15:21:49 -08001719 mKeyboardTapVibePattern = getLongIntArray(mContext.getResources(),
1720 com.android.internal.R.array.config_keyboardTapVibePattern);
Fabrice Di Meglioeeff63a2013-08-05 12:07:24 -07001721 mClockTickVibePattern = getLongIntArray(mContext.getResources(),
1722 com.android.internal.R.array.config_clockTickVibePattern);
Fabrice Di Megliobd9152f2013-10-01 11:21:31 -07001723 mCalendarDateVibePattern = getLongIntArray(mContext.getResources(),
1724 com.android.internal.R.array.config_calendarDateVibePattern);
Dianne Hackbornb1a79802009-09-29 15:18:31 -07001725 mSafeModeDisabledVibePattern = getLongIntArray(mContext.getResources(),
1726 com.android.internal.R.array.config_safeModeDisabledVibePattern);
1727 mSafeModeEnabledVibePattern = getLongIntArray(mContext.getResources(),
1728 com.android.internal.R.array.config_safeModeEnabledVibePattern);
Mady Mellore8608912015-06-05 09:02:55 -07001729 mContextClickVibePattern = getLongIntArray(mContext.getResources(),
1730 com.android.internal.R.array.config_contextClickVibePattern);
Daniel Sandler40427442010-07-16 11:44:52 -04001731
Christopher Tatee90585f2012-03-05 18:56:25 -08001732 mScreenshotChordEnabled = mContext.getResources().getBoolean(
1733 com.android.internal.R.bool.config_enableScreenshotChord);
Jorim Jaggi406585a2015-12-21 10:58:56 +01001734 mForceWindowDrawsStatusBarBackground = mContext.getResources().getBoolean(
1735 R.bool.config_forceWindowDrawsStatusBarBackground);
Christopher Tatee90585f2012-03-05 18:56:25 -08001736
Justin Kohd378ad72013-04-01 12:18:26 -07001737 mGlobalKeyManager = new GlobalKeyManager(mContext);
1738
Joe Onoratoea495d42011-04-06 11:41:11 -07001739 // Controls rotation and the like.
1740 initializeHdmiState();
Dianne Hackborn40011092011-09-22 13:37:48 -07001741
1742 // Match current screen state.
Craig Mautnera631d492014-08-05 15:16:01 -07001743 if (!mPowerManager.isInteractive()) {
Jeff Brown416c49c2015-05-26 19:50:18 -07001744 startedGoingToSleep(WindowManagerPolicy.OFF_BECAUSE_OF_USER);
1745 finishedGoingToSleep(WindowManagerPolicy.OFF_BECAUSE_OF_USER);
Dianne Hackborn40011092011-09-22 13:37:48 -07001746 }
Jorim Jaggi24bec7c2015-02-04 12:40:14 +01001747
1748 mWindowManagerInternal.registerAppTransitionListener(
1749 mStatusBarController.getAppTransitionListener());
Mike Lockwood1753f7f2009-08-24 14:49:07 -07001750 }
1751
Jeff Brownf71343d2013-05-31 17:59:11 -07001752 /**
1753 * Read values from config.xml that may be overridden depending on
1754 * the configuration of the device.
1755 * eg. Disable long press on home goes to recents on sw600dp.
1756 */
1757 private void readConfigurationDependentBehaviors() {
Jaewan Kimc552b042016-01-18 16:08:45 +09001758 final Resources res = mContext.getResources();
1759
1760 mLongPressOnHomeBehavior = res.getInteger(
Jeff Brownf71343d2013-05-31 17:59:11 -07001761 com.android.internal.R.integer.config_longPressOnHomeBehavior);
1762 if (mLongPressOnHomeBehavior < LONG_PRESS_HOME_NOTHING ||
Jaewan Kim52632e22016-01-14 18:01:52 +09001763 mLongPressOnHomeBehavior > LAST_LONG_PRESS_HOME_BEHAVIOR) {
Jeff Brownf71343d2013-05-31 17:59:11 -07001764 mLongPressOnHomeBehavior = LONG_PRESS_HOME_NOTHING;
1765 }
1766
Jaewan Kimc552b042016-01-18 16:08:45 +09001767 mDoubleTapOnHomeBehavior = res.getInteger(
Jeff Brownf71343d2013-05-31 17:59:11 -07001768 com.android.internal.R.integer.config_doubleTapOnHomeBehavior);
1769 if (mDoubleTapOnHomeBehavior < DOUBLE_TAP_HOME_NOTHING ||
1770 mDoubleTapOnHomeBehavior > DOUBLE_TAP_HOME_RECENT_SYSTEM_UI) {
1771 mDoubleTapOnHomeBehavior = LONG_PRESS_HOME_NOTHING;
1772 }
Jaewan Kim49117872016-01-19 17:24:08 +09001773
1774 mShortPressWindowBehavior = SHORT_PRESS_WINDOW_NOTHING;
1775 if (mContext.getPackageManager().hasSystemFeature(FEATURE_PICTURE_IN_PICTURE)) {
1776 mShortPressWindowBehavior = SHORT_PRESS_WINDOW_PICTURE_IN_PICTURE;
1777 }
Yorke Lee2e4b7322016-03-02 17:33:06 -08001778
Yorke Lee9b2ffb32016-03-07 20:42:01 -08001779 mNavBarOpacityMode = res.getInteger(
1780 com.android.internal.R.integer.config_navBarOpacityMode);
Jeff Brownf71343d2013-05-31 17:59:11 -07001781 }
1782
Craig Mautner0bf6ec92012-12-18 08:33:27 -08001783 @Override
Dianne Hackborndde331c2012-08-03 14:01:57 -07001784 public void setInitialDisplaySize(Display display, int width, int height, int density) {
Jeff Brownef981a42013-08-07 14:13:37 -07001785 // This method might be called before the policy has been fully initialized
1786 // or for other displays we don't care about.
1787 if (mContext == null || display.getDisplayId() != Display.DEFAULT_DISPLAY) {
1788 return;
Dianne Hackbornc652de82013-02-15 16:32:56 -08001789 }
Dianne Hackbornf87d1962012-04-04 12:48:24 -07001790 mDisplay = display;
1791
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001792 final Resources res = mContext.getResources();
Dianne Hackbornf87d1962012-04-04 12:48:24 -07001793 int shortSize, longSize;
Dianne Hackborn9d132642011-04-21 17:26:39 -07001794 if (width > height) {
Dianne Hackborn81e56d52011-05-26 00:55:58 -07001795 shortSize = height;
Dianne Hackbornf87d1962012-04-04 12:48:24 -07001796 longSize = width;
Dianne Hackborn9d132642011-04-21 17:26:39 -07001797 mLandscapeRotation = Surface.ROTATION_0;
1798 mSeascapeRotation = Surface.ROTATION_180;
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001799 if (res.getBoolean(com.android.internal.R.bool.config_reverseDefaultRotation)) {
Dianne Hackborn9d132642011-04-21 17:26:39 -07001800 mPortraitRotation = Surface.ROTATION_90;
1801 mUpsideDownRotation = Surface.ROTATION_270;
1802 } else {
1803 mPortraitRotation = Surface.ROTATION_270;
1804 mUpsideDownRotation = Surface.ROTATION_90;
1805 }
1806 } else {
Dianne Hackborn81e56d52011-05-26 00:55:58 -07001807 shortSize = width;
Dianne Hackbornf87d1962012-04-04 12:48:24 -07001808 longSize = height;
Dianne Hackborn9d132642011-04-21 17:26:39 -07001809 mPortraitRotation = Surface.ROTATION_0;
1810 mUpsideDownRotation = Surface.ROTATION_180;
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001811 if (res.getBoolean(com.android.internal.R.bool.config_reverseDefaultRotation)) {
Dianne Hackborn9d132642011-04-21 17:26:39 -07001812 mLandscapeRotation = Surface.ROTATION_270;
1813 mSeascapeRotation = Surface.ROTATION_90;
1814 } else {
1815 mLandscapeRotation = Surface.ROTATION_90;
1816 mSeascapeRotation = Surface.ROTATION_270;
1817 }
1818 }
Dianne Hackborn81e56d52011-05-26 00:55:58 -07001819
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001820 mStatusBarHeight =
1821 res.getDimensionPixelSize(com.android.internal.R.dimen.status_bar_height);
Dianne Hackbornf87d1962012-04-04 12:48:24 -07001822
Daniel Sandler9f65c4c2012-04-26 01:35:35 -04001823 // Height of the navigation bar when presented horizontally at bottom
Sriram Viswanathan9ebbe6a2015-11-16 17:59:22 -08001824 mNavigationBarHeightForRotationDefault[mPortraitRotation] =
1825 mNavigationBarHeightForRotationDefault[mUpsideDownRotation] =
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001826 res.getDimensionPixelSize(com.android.internal.R.dimen.navigation_bar_height);
Sriram Viswanathan9ebbe6a2015-11-16 17:59:22 -08001827 mNavigationBarHeightForRotationDefault[mLandscapeRotation] =
1828 mNavigationBarHeightForRotationDefault[mSeascapeRotation] = res.getDimensionPixelSize(
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001829 com.android.internal.R.dimen.navigation_bar_height_landscape);
Daniel Sandler9f65c4c2012-04-26 01:35:35 -04001830
1831 // Width of the navigation bar when presented vertically along one side
Sriram Viswanathan9ebbe6a2015-11-16 17:59:22 -08001832 mNavigationBarWidthForRotationDefault[mPortraitRotation] =
1833 mNavigationBarWidthForRotationDefault[mUpsideDownRotation] =
1834 mNavigationBarWidthForRotationDefault[mLandscapeRotation] =
1835 mNavigationBarWidthForRotationDefault[mSeascapeRotation] =
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001836 res.getDimensionPixelSize(com.android.internal.R.dimen.navigation_bar_width);
Daniel Sandler4a066c52012-04-20 14:49:13 -04001837
Sriram Viswanathan9ebbe6a2015-11-16 17:59:22 -08001838 // Height of the navigation bar when presented horizontally at bottom
1839 mNavigationBarHeightForRotationInCarMode[mPortraitRotation] =
1840 mNavigationBarHeightForRotationInCarMode[mUpsideDownRotation] =
1841 res.getDimensionPixelSize(
1842 com.android.internal.R.dimen.navigation_bar_height_car_mode);
1843 mNavigationBarHeightForRotationInCarMode[mLandscapeRotation] =
1844 mNavigationBarHeightForRotationInCarMode[mSeascapeRotation] = res.getDimensionPixelSize(
1845 com.android.internal.R.dimen.navigation_bar_height_landscape_car_mode);
1846
1847 // Width of the navigation bar when presented vertically along one side
1848 mNavigationBarWidthForRotationInCarMode[mPortraitRotation] =
1849 mNavigationBarWidthForRotationInCarMode[mUpsideDownRotation] =
1850 mNavigationBarWidthForRotationInCarMode[mLandscapeRotation] =
1851 mNavigationBarWidthForRotationInCarMode[mSeascapeRotation] =
1852 res.getDimensionPixelSize(
1853 com.android.internal.R.dimen.navigation_bar_width_car_mode);
1854
Daniel Sandler4a066c52012-04-20 14:49:13 -04001855 // SystemUI (status bar) layout policy
Dianne Hackborndde331c2012-08-03 14:01:57 -07001856 int shortSizeDp = shortSize * DisplayMetrics.DENSITY_DEFAULT / density;
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001857 int longSizeDp = longSize * DisplayMetrics.DENSITY_DEFAULT / density;
Daniel Sandler4a066c52012-04-20 14:49:13 -04001858
Devin Kimd7b12b42014-05-05 14:34:58 -07001859 // Allow the navigation bar to move on non-square small devices (phones).
1860 mNavigationBarCanMove = width != height && shortSizeDp < 600;
Daniel Sandler36412a72011-08-04 09:35:13 -04001861
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001862 mHasNavigationBar = res.getBoolean(com.android.internal.R.bool.config_showNavigationBar);
John Spurlock80f00c12013-06-13 11:10:51 -04001863 // Allow a system property to override this. Used by the emulator.
1864 // See also hasNavigationBar().
1865 String navBarOverride = SystemProperties.get("qemu.hw.mainkeys");
1866 if ("1".equals(navBarOverride)) {
Dianne Hackbornf87d1962012-04-04 12:48:24 -07001867 mHasNavigationBar = false;
John Spurlock80f00c12013-06-13 11:10:51 -04001868 } else if ("0".equals(navBarOverride)) {
1869 mHasNavigationBar = true;
Daniel Sandler0c4ccff2011-10-19 16:39:14 -04001870 }
1871
Jeff Brown27f1d672012-10-17 18:32:34 -07001872 // For demo purposes, allow the rotation of the HDMI display to be controlled.
1873 // By default, HDMI locks rotation to landscape.
Erik Gilling9a41ef82011-09-26 19:21:03 -07001874 if ("portrait".equals(SystemProperties.get("persist.demo.hdmirotation"))) {
Jeff Brownc82c89ed2013-04-17 17:18:15 -07001875 mDemoHdmiRotation = mPortraitRotation;
Erik Gilling9a41ef82011-09-26 19:21:03 -07001876 } else {
Jeff Brownc82c89ed2013-04-17 17:18:15 -07001877 mDemoHdmiRotation = mLandscapeRotation;
Erik Gilling9a41ef82011-09-26 19:21:03 -07001878 }
Jeff Brownc82c89ed2013-04-17 17:18:15 -07001879 mDemoHdmiRotationLock = SystemProperties.getBoolean("persist.demo.hdmirotationlock", false);
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001880
Chong Zhangae6119ff2014-11-11 18:54:39 -08001881 // For demo purposes, allow the rotation of the remote display to be controlled.
1882 // By default, remote display locks rotation to landscape.
1883 if ("portrait".equals(SystemProperties.get("persist.demo.remoterotation"))) {
1884 mDemoRotation = mPortraitRotation;
1885 } else {
1886 mDemoRotation = mLandscapeRotation;
1887 }
1888 mDemoRotationLock = SystemProperties.getBoolean(
1889 "persist.demo.rotationlock", false);
1890
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001891 // Only force the default orientation if the screen is xlarge, at least 960dp x 720dp, per
1892 // http://developer.android.com/guide/practices/screens_support.html#range
1893 mForceDefaultOrientation = longSizeDp >= 960 && shortSizeDp >= 720 &&
1894 res.getBoolean(com.android.internal.R.bool.config_forceDefaultOrientation) &&
1895 // For debug purposes the next line turns this feature off with:
1896 // $ adb shell setprop config.override_forced_orient true
1897 // $ adb shell wm size reset
1898 !"true".equals(SystemProperties.get("config.override_forced_orient"));
1899 }
1900
Alan Viverette5a0f4ec2013-10-07 15:10:29 -07001901 /**
1902 * @return whether the navigation bar can be hidden, e.g. the device has a
1903 * navigation bar and touch exploration is not enabled
1904 */
1905 private boolean canHideNavigationBar() {
Alan Viverette817f3cd2015-08-13 11:40:14 -04001906 return mHasNavigationBar;
Alan Viverette5a0f4ec2013-10-07 15:10:29 -07001907 }
1908
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001909 @Override
1910 public boolean isDefaultOrientationForced() {
1911 return mForceDefaultOrientation;
Dianne Hackborn9d132642011-04-21 17:26:39 -07001912 }
1913
Dianne Hackbornc652de82013-02-15 16:32:56 -08001914 @Override
1915 public void setDisplayOverscan(Display display, int left, int top, int right, int bottom) {
1916 if (display.getDisplayId() == Display.DEFAULT_DISPLAY) {
1917 mOverscanLeft = left;
1918 mOverscanTop = top;
1919 mOverscanRight = right;
1920 mOverscanBottom = bottom;
1921 }
1922 }
1923
Dianne Hackbornc777e072010-02-12 13:07:59 -08001924 public void updateSettings() {
1925 ContentResolver resolver = mContext.getContentResolver();
1926 boolean updateRotation = false;
Dianne Hackbornc777e072010-02-12 13:07:59 -08001927 synchronized (mLock) {
Christopher Tate5e08af02012-09-21 17:17:22 -07001928 mEndcallBehavior = Settings.System.getIntForUser(resolver,
David Brownbaf8d092010-03-08 21:52:59 -08001929 Settings.System.END_BUTTON_BEHAVIOR,
Christopher Tate5e08af02012-09-21 17:17:22 -07001930 Settings.System.END_BUTTON_BEHAVIOR_DEFAULT,
1931 UserHandle.USER_CURRENT);
1932 mIncallPowerBehavior = Settings.Secure.getIntForUser(resolver,
David Brownbaf8d092010-03-08 21:52:59 -08001933 Settings.Secure.INCALL_POWER_BUTTON_BEHAVIOR,
Christopher Tate5e08af02012-09-21 17:17:22 -07001934 Settings.Secure.INCALL_POWER_BUTTON_BEHAVIOR_DEFAULT,
1935 UserHandle.USER_CURRENT);
Daniel Sandlerb73617d2010-08-17 00:41:00 -04001936
Jeff Browna20dda42014-05-27 20:57:24 -07001937 // Configure wake gesture.
1938 boolean wakeGestureEnabledSetting = Settings.Secure.getIntForUser(resolver,
1939 Settings.Secure.WAKE_GESTURE_ENABLED, 0,
1940 UserHandle.USER_CURRENT) != 0;
1941 if (mWakeGestureEnabledSetting != wakeGestureEnabledSetting) {
1942 mWakeGestureEnabledSetting = wakeGestureEnabledSetting;
1943 updateWakeGestureListenerLp();
1944 }
1945
Jeff Brown207673cd2012-06-05 17:47:11 -07001946 // Configure rotation lock.
Christopher Tate5e08af02012-09-21 17:17:22 -07001947 int userRotation = Settings.System.getIntForUser(resolver,
1948 Settings.System.USER_ROTATION, Surface.ROTATION_0,
1949 UserHandle.USER_CURRENT);
Jeff Brown207673cd2012-06-05 17:47:11 -07001950 if (mUserRotation != userRotation) {
1951 mUserRotation = userRotation;
1952 updateRotation = true;
1953 }
Christopher Tate5e08af02012-09-21 17:17:22 -07001954 int userRotationMode = Settings.System.getIntForUser(resolver,
1955 Settings.System.ACCELEROMETER_ROTATION, 0, UserHandle.USER_CURRENT) != 0 ?
Jeff Brown207673cd2012-06-05 17:47:11 -07001956 WindowManagerPolicy.USER_ROTATION_FREE :
1957 WindowManagerPolicy.USER_ROTATION_LOCKED;
1958 if (mUserRotationMode != userRotationMode) {
1959 mUserRotationMode = userRotationMode;
1960 updateRotation = true;
Dianne Hackbornc777e072010-02-12 13:07:59 -08001961 updateOrientationListenerLp();
1962 }
Daniel Sandlerb73617d2010-08-17 00:41:00 -04001963
Dianne Hackbornc777e072010-02-12 13:07:59 -08001964 if (mSystemReady) {
Christopher Tate5e08af02012-09-21 17:17:22 -07001965 int pointerLocation = Settings.System.getIntForUser(resolver,
1966 Settings.System.POINTER_LOCATION, 0, UserHandle.USER_CURRENT);
Dianne Hackbornc777e072010-02-12 13:07:59 -08001967 if (mPointerLocationMode != pointerLocation) {
1968 mPointerLocationMode = pointerLocation;
Jeff Brown70825162012-03-28 17:27:48 -07001969 mHandler.sendEmptyMessage(pointerLocation != 0 ?
1970 MSG_ENABLE_POINTER_LOCATION : MSG_DISABLE_POINTER_LOCATION);
Dianne Hackbornc777e072010-02-12 13:07:59 -08001971 }
1972 }
1973 // use screen off timeout setting as the timeout for the lockscreen
Christopher Tate5e08af02012-09-21 17:17:22 -07001974 mLockScreenTimeout = Settings.System.getIntForUser(resolver,
1975 Settings.System.SCREEN_OFF_TIMEOUT, 0, UserHandle.USER_CURRENT);
1976 String imId = Settings.Secure.getStringForUser(resolver,
1977 Settings.Secure.DEFAULT_INPUT_METHOD, UserHandle.USER_CURRENT);
Dianne Hackbornc777e072010-02-12 13:07:59 -08001978 boolean hasSoftInput = imId != null && imId.length() > 0;
1979 if (mHasSoftInput != hasSoftInput) {
1980 mHasSoftInput = hasSoftInput;
1981 updateRotation = true;
1982 }
John Spurlockf1a36642013-10-12 17:50:42 -04001983 if (mImmersiveModeConfirmation != null) {
John Spurlock4355a532014-02-19 09:49:25 -05001984 mImmersiveModeConfirmation.loadSetting(mCurrentUserId);
John Spurlockd67ec252013-09-05 11:31:54 -04001985 }
tiger_huangcc6366d2015-06-29 17:17:30 +08001986 }
1987 synchronized (mWindowManagerFuncs.getWindowManagerLock()) {
John Spurlockc6d1c602014-01-17 15:22:06 -05001988 PolicyControl.reloadFromSetting(mContext);
Dianne Hackbornc777e072010-02-12 13:07:59 -08001989 }
1990 if (updateRotation) {
Jeff Brown01a98dd2011-09-20 15:08:29 -07001991 updateRotation(true);
Dianne Hackbornc777e072010-02-12 13:07:59 -08001992 }
Jeff Brown70825162012-03-28 17:27:48 -07001993 }
1994
Jeff Browna20dda42014-05-27 20:57:24 -07001995 private void updateWakeGestureListenerLp() {
1996 if (shouldEnableWakeGestureLp()) {
1997 mWakeGestureListener.requestWakeUpTrigger();
1998 } else {
1999 mWakeGestureListener.cancelWakeUpTrigger();
2000 }
2001 }
2002
2003 private boolean shouldEnableWakeGestureLp() {
Jeff Brown3ee549c2014-09-22 20:14:39 -07002004 return mWakeGestureEnabledSetting && !mAwake
Jeff Browna20dda42014-05-27 20:57:24 -07002005 && (!mLidControlsSleep || mLidState != LID_CLOSED)
2006 && mWakeGestureListener.isSupported();
2007 }
2008
Jeff Brown70825162012-03-28 17:27:48 -07002009 private void enablePointerLocation() {
2010 if (mPointerLocationView == null) {
2011 mPointerLocationView = new PointerLocationView(mContext);
2012 mPointerLocationView.setPrintCoords(false);
Dianne Hackbornc777e072010-02-12 13:07:59 -08002013 WindowManager.LayoutParams lp = new WindowManager.LayoutParams(
2014 WindowManager.LayoutParams.MATCH_PARENT,
2015 WindowManager.LayoutParams.MATCH_PARENT);
Jeff Brown3b2b3542010-10-15 00:54:27 -07002016 lp.type = WindowManager.LayoutParams.TYPE_SECURE_SYSTEM_OVERLAY;
Jeff Brownbfcb60a2011-09-08 18:51:14 -07002017 lp.flags = WindowManager.LayoutParams.FLAG_FULLSCREEN
2018 | WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE
2019 | WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE
2020 | WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN;
Jeff Brown90fc9052012-10-01 14:44:24 -07002021 if (ActivityManager.isHighEndGfx()) {
2022 lp.flags |= WindowManager.LayoutParams.FLAG_HARDWARE_ACCELERATED;
2023 lp.privateFlags |=
2024 WindowManager.LayoutParams.PRIVATE_FLAG_FORCE_HARDWARE_ACCELERATED;
2025 }
Dianne Hackbornc777e072010-02-12 13:07:59 -08002026 lp.format = PixelFormat.TRANSLUCENT;
2027 lp.setTitle("PointerLocation");
Dianne Hackborn5fd21692011-06-07 14:09:47 -07002028 WindowManager wm = (WindowManager)
Dianne Hackbornc777e072010-02-12 13:07:59 -08002029 mContext.getSystemService(Context.WINDOW_SERVICE);
Jeff Browncc4f7db2011-08-30 20:34:48 -07002030 lp.inputFeatures |= WindowManager.LayoutParams.INPUT_FEATURE_NO_INPUT_CHANNEL;
Jeff Brown70825162012-03-28 17:27:48 -07002031 wm.addView(mPointerLocationView, lp);
Michael Wrightc9c487e2013-11-07 18:55:09 -08002032 mWindowManagerFuncs.registerPointerEventListener(mPointerLocationView);
Dianne Hackbornc777e072010-02-12 13:07:59 -08002033 }
Dianne Hackbornc777e072010-02-12 13:07:59 -08002034 }
Jeff Brown70825162012-03-28 17:27:48 -07002035
2036 private void disablePointerLocation() {
Jeff Brown70825162012-03-28 17:27:48 -07002037 if (mPointerLocationView != null) {
Michael Wrightc9c487e2013-11-07 18:55:09 -08002038 mWindowManagerFuncs.unregisterPointerEventListener(mPointerLocationView);
2039 WindowManager wm = (WindowManager) mContext.getSystemService(Context.WINDOW_SERVICE);
Jeff Brown70825162012-03-28 17:27:48 -07002040 wm.removeView(mPointerLocationView);
2041 mPointerLocationView = null;
2042 }
2043 }
2044
Mike Lockwood2d1efbd2009-09-16 12:15:53 -04002045 private int readRotation(int resID) {
Mike Lockwood1753f7f2009-08-24 14:49:07 -07002046 try {
2047 int rotation = mContext.getResources().getInteger(resID);
2048 switch (rotation) {
2049 case 0:
2050 return Surface.ROTATION_0;
2051 case 90:
2052 return Surface.ROTATION_90;
2053 case 180:
2054 return Surface.ROTATION_180;
2055 case 270:
2056 return Surface.ROTATION_270;
Mike Lockwood1753f7f2009-08-24 14:49:07 -07002057 }
2058 } catch (Resources.NotFoundException e) {
Mike Lockwood2d1efbd2009-09-16 12:15:53 -04002059 // fall through
Mike Lockwood1753f7f2009-08-24 14:49:07 -07002060 }
Mike Lockwood2d1efbd2009-09-16 12:15:53 -04002061 return -1;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002062 }
2063
2064 /** {@inheritDoc} */
Craig Mautner88400d32012-09-30 12:35:45 -07002065 @Override
Dianne Hackbornc2293022013-02-06 23:14:49 -08002066 public int checkAddPermission(WindowManager.LayoutParams attrs, int[] outAppOp) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002067 int type = attrs.type;
Dianne Hackbornc2293022013-02-06 23:14:49 -08002068
2069 outAppOp[0] = AppOpsManager.OP_NONE;
2070
Wale Ogunwale74bf0652015-01-12 10:24:36 -08002071 if (!((type >= FIRST_APPLICATION_WINDOW && type <= LAST_APPLICATION_WINDOW)
2072 || (type >= FIRST_SUB_WINDOW && type <= LAST_SUB_WINDOW)
2073 || (type >= FIRST_SYSTEM_WINDOW && type <= LAST_SYSTEM_WINDOW))) {
2074 return WindowManagerGlobal.ADD_INVALID_TYPE;
2075 }
2076
2077 if (type < FIRST_SYSTEM_WINDOW || type > LAST_SYSTEM_WINDOW) {
2078 // Window manager will make sure these are okay.
Jeff Brown98365d72012-08-19 20:30:52 -07002079 return WindowManagerGlobal.ADD_OKAY;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002080 }
2081 String permission = null;
2082 switch (type) {
2083 case TYPE_TOAST:
2084 // XXX right now the app process has complete control over
2085 // this... should introduce a token to let the system
2086 // monitor/control what they are doing.
Jason Monk1c7c3192014-06-26 12:52:18 -04002087 outAppOp[0] = AppOpsManager.OP_TOAST_WINDOW;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002088 break;
Daniel Sandler7d276c32012-01-30 14:33:52 -05002089 case TYPE_DREAM:
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002090 case TYPE_INPUT_METHOD:
Dianne Hackbornb7cd8b92009-08-08 20:53:03 -07002091 case TYPE_WALLPAPER:
keunyounga446bf02013-06-21 19:07:57 -07002092 case TYPE_PRIVATE_PRESENTATION:
Dianne Hackborne30e02f2014-05-27 18:24:45 -07002093 case TYPE_VOICE_INTERACTION:
Svetoslav3a5c7212014-10-14 09:54:26 -07002094 case TYPE_ACCESSIBILITY_OVERLAY:
Jason Monk8f7f3182015-11-18 16:35:14 -05002095 case TYPE_QS_DIALOG:
Dianne Hackbornb7cd8b92009-08-08 20:53:03 -07002096 // The window manager will check these.
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002097 break;
2098 case TYPE_PHONE:
2099 case TYPE_PRIORITY_PHONE:
2100 case TYPE_SYSTEM_ALERT:
2101 case TYPE_SYSTEM_ERROR:
2102 case TYPE_SYSTEM_OVERLAY:
2103 permission = android.Manifest.permission.SYSTEM_ALERT_WINDOW;
Dianne Hackbornc2293022013-02-06 23:14:49 -08002104 outAppOp[0] = AppOpsManager.OP_SYSTEM_ALERT_WINDOW;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002105 break;
2106 default:
2107 permission = android.Manifest.permission.INTERNAL_SYSTEM_WINDOW;
2108 }
2109 if (permission != null) {
Svet Ganov9cea80cd2016-02-16 11:47:00 -08002110 if (android.Manifest.permission.SYSTEM_ALERT_WINDOW.equals(permission)) {
Billy Laucbe540f2015-06-25 01:51:44 +01002111 final int callingUid = Binder.getCallingUid();
Billy Lau060275f2015-07-15 22:29:19 +01002112 // system processes will be automatically allowed privilege to draw
Billy Laucbe540f2015-06-25 01:51:44 +01002113 if (callingUid == Process.SYSTEM_UID) {
2114 return WindowManagerGlobal.ADD_OKAY;
2115 }
2116
Billy Lau060275f2015-07-15 22:29:19 +01002117 // check if user has enabled this operation. SecurityException will be thrown if
2118 // this app has not been allowed by the user
Svet Ganov03f2afc2016-03-04 16:13:03 -08002119 final int mode = mAppOpsManager.checkOpNoThrow(outAppOp[0], callingUid,
Billy Laucbe540f2015-06-25 01:51:44 +01002120 attrs.packageName);
Billy Lau060275f2015-07-15 22:29:19 +01002121 switch (mode) {
2122 case AppOpsManager.MODE_ALLOWED:
2123 case AppOpsManager.MODE_IGNORED:
2124 // although we return ADD_OKAY for MODE_IGNORED, the added window will
2125 // actually be hidden in WindowManagerService
2126 return WindowManagerGlobal.ADD_OKAY;
2127 case AppOpsManager.MODE_ERRORED:
Svet Ganov03f2afc2016-03-04 16:13:03 -08002128 try {
2129 ApplicationInfo appInfo = mContext.getPackageManager()
2130 .getApplicationInfo(attrs.packageName,
2131 UserHandle.getUserId(callingUid));
2132 // Don't crash legacy apps
2133 if (appInfo.targetSdkVersion < Build.VERSION_CODES.M) {
2134 return WindowManagerGlobal.ADD_OKAY;
2135 }
2136 } catch (PackageManager.NameNotFoundException e) {
2137 /* ignore */
2138 }
Billy Laucbe540f2015-06-25 01:51:44 +01002139 return WindowManagerGlobal.ADD_PERMISSION_DENIED;
Billy Lau060275f2015-07-15 22:29:19 +01002140 default:
2141 // in the default mode, we will make a decision here based on
2142 // checkCallingPermission()
2143 if (mContext.checkCallingPermission(permission) !=
2144 PackageManager.PERMISSION_GRANTED) {
2145 return WindowManagerGlobal.ADD_PERMISSION_DENIED;
2146 } else {
2147 return WindowManagerGlobal.ADD_OKAY;
2148 }
Billy Laucbe540f2015-06-25 01:51:44 +01002149 }
Billy Laucbe540f2015-06-25 01:51:44 +01002150 }
2151
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002152 if (mContext.checkCallingOrSelfPermission(permission)
2153 != PackageManager.PERMISSION_GRANTED) {
Jeff Brown98365d72012-08-19 20:30:52 -07002154 return WindowManagerGlobal.ADD_PERMISSION_DENIED;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002155 }
2156 }
Jeff Brown98365d72012-08-19 20:30:52 -07002157 return WindowManagerGlobal.ADD_OKAY;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002158 }
Craig Mautner88400d32012-09-30 12:35:45 -07002159
2160 @Override
2161 public boolean checkShowToOwnerOnly(WindowManager.LayoutParams attrs) {
2162
2163 // If this switch statement is modified, modify the comment in the declarations of
2164 // the type in {@link WindowManager.LayoutParams} as well.
2165 switch (attrs.type) {
2166 default:
2167 // These are the windows that by default are shown only to the user that created
2168 // them. If this needs to be overridden, set
2169 // {@link WindowManager.LayoutParams.PRIVATE_FLAG_SHOW_FOR_ALL_USERS} in
2170 // {@link WindowManager.LayoutParams}. Note that permission
2171 // {@link android.Manifest.permission.INTERNAL_SYSTEM_WINDOW} is required as well.
2172 if ((attrs.privateFlags & PRIVATE_FLAG_SHOW_FOR_ALL_USERS) == 0) {
2173 return true;
2174 }
2175 break;
2176
2177 // These are the windows that by default are shown to all users. However, to
2178 // protect against spoofing, check permissions below.
2179 case TYPE_APPLICATION_STARTING:
2180 case TYPE_BOOT_PROGRESS:
2181 case TYPE_DISPLAY_OVERLAY:
Selim Cinekf83e8242015-05-19 18:08:14 -07002182 case TYPE_INPUT_CONSUMER:
Jim Miller5ecd8112013-01-09 18:50:26 -08002183 case TYPE_KEYGUARD_SCRIM:
Craig Mautner88400d32012-09-30 12:35:45 -07002184 case TYPE_KEYGUARD_DIALOG:
2185 case TYPE_MAGNIFICATION_OVERLAY:
2186 case TYPE_NAVIGATION_BAR:
2187 case TYPE_NAVIGATION_BAR_PANEL:
2188 case TYPE_PHONE:
2189 case TYPE_POINTER:
2190 case TYPE_PRIORITY_PHONE:
Craig Mautner88400d32012-09-30 12:35:45 -07002191 case TYPE_SEARCH_BAR:
2192 case TYPE_STATUS_BAR:
2193 case TYPE_STATUS_BAR_PANEL:
2194 case TYPE_STATUS_BAR_SUB_PANEL:
2195 case TYPE_SYSTEM_DIALOG:
Craig Mautner88400d32012-09-30 12:35:45 -07002196 case TYPE_VOLUME_OVERLAY:
keunyounga446bf02013-06-21 19:07:57 -07002197 case TYPE_PRIVATE_PRESENTATION:
Filip Gruszczynski466f3212015-09-21 17:57:57 -07002198 case TYPE_DOCK_DIVIDER:
Craig Mautner88400d32012-09-30 12:35:45 -07002199 break;
2200 }
2201
2202 // Check if third party app has set window to system window type.
2203 return mContext.checkCallingOrSelfPermission(
2204 android.Manifest.permission.INTERNAL_SYSTEM_WINDOW)
2205 != PackageManager.PERMISSION_GRANTED;
2206 }
2207
Craig Mautner967212c2013-04-13 21:10:58 -07002208 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002209 public void adjustWindowParamsLw(WindowManager.LayoutParams attrs) {
2210 switch (attrs.type) {
2211 case TYPE_SYSTEM_OVERLAY:
Jeff Brown3b2b3542010-10-15 00:54:27 -07002212 case TYPE_SECURE_SYSTEM_OVERLAY:
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002213 // These types of windows can't receive input events.
2214 attrs.flags |= WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE
2215 | WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE;
Jeff Brownbfcb60a2011-09-08 18:51:14 -07002216 attrs.flags &= ~WindowManager.LayoutParams.FLAG_WATCH_OUTSIDE_TOUCH;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002217 break;
Jorim Jaggi380ecb82014-03-14 17:25:20 +01002218 case TYPE_STATUS_BAR:
2219
2220 // If the Keyguard is in a hidden state (occluded by another window), we force to
2221 // remove the wallpaper and keyguard flag so that any change in-flight after setting
2222 // the keyguard as occluded wouldn't set these flags again.
2223 // See {@link #processKeyguardSetHiddenResultLw}.
2224 if (mKeyguardHidden) {
2225 attrs.flags &= ~WindowManager.LayoutParams.FLAG_SHOW_WALLPAPER;
2226 attrs.privateFlags &= ~WindowManager.LayoutParams.PRIVATE_FLAG_KEYGUARD;
2227 }
2228 break;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002229 }
Adrian Roos38502112014-04-09 21:04:11 +02002230
2231 if (attrs.type != TYPE_STATUS_BAR) {
2232 // The status bar is the only window allowed to exhibit keyguard behavior.
2233 attrs.privateFlags &= ~WindowManager.LayoutParams.PRIVATE_FLAG_KEYGUARD;
2234 }
Adrian Roosea562512014-05-05 13:33:03 +02002235
Jorim Jaggi4fa78922015-11-30 17:13:56 -08002236 if (ActivityManager.isHighEndGfx()) {
2237 if ((attrs.flags & FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS) != 0) {
2238 attrs.subtreeSystemUiVisibility |= View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION;
2239 }
2240 if ((attrs.flags & FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS) != 0
Jorim Jaggi406585a2015-12-21 10:58:56 +01002241 || (mForceWindowDrawsStatusBarBackground
2242 && attrs.height == MATCH_PARENT && attrs.width == MATCH_PARENT)) {
Jorim Jaggi4fa78922015-11-30 17:13:56 -08002243 attrs.subtreeSystemUiVisibility |= View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN;
2244 }
Adrian Roosea562512014-05-05 13:33:03 +02002245 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002246 }
RoboErik8a2cfc32014-05-16 11:19:38 -07002247
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002248 void readLidState() {
Jeff Brown2e7760e2012-04-11 15:14:55 -07002249 mLidState = mWindowManagerFuncs.getLidState();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002250 }
RoboErik8a2cfc32014-05-16 11:19:38 -07002251
Michael Wright3818c922014-09-02 13:59:07 -07002252 private void readCameraLensCoverState() {
2253 mCameraLensCoverState = mWindowManagerFuncs.getCameraLensCoverState();
2254 }
2255
Jeff Browndaa37532012-05-01 15:54:03 -07002256 private boolean isHidden(int accessibilityMode) {
2257 switch (accessibilityMode) {
2258 case 1:
2259 return mLidState == LID_CLOSED;
2260 case 2:
2261 return mLidState == LID_OPEN;
2262 default:
2263 return false;
Dianne Hackborn2862fff2009-09-15 22:56:29 -07002264 }
Dianne Hackborn2862fff2009-09-15 22:56:29 -07002265 }
Jeff Brownd04a88c2011-01-16 14:05:47 -08002266
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002267 /** {@inheritDoc} */
Craig Mautner967212c2013-04-13 21:10:58 -07002268 @Override
Jeff Browndaa37532012-05-01 15:54:03 -07002269 public void adjustConfigurationLw(Configuration config, int keyboardPresence,
2270 int navigationPresence) {
2271 mHaveBuiltInKeyboard = (keyboardPresence & PRESENCE_INTERNAL) != 0;
2272
Jeff Brownf71343d2013-05-31 17:59:11 -07002273 readConfigurationDependentBehaviors();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002274 readLidState();
Jeff Brownc458ce92012-04-30 14:58:40 -07002275 applyLidSwitchState();
Jeff Brownd04a88c2011-01-16 14:05:47 -08002276
Jeff Browndaa37532012-05-01 15:54:03 -07002277 if (config.keyboard == Configuration.KEYBOARD_NOKEYS
2278 || (keyboardPresence == PRESENCE_INTERNAL
2279 && isHidden(mLidKeyboardAccessibility))) {
Jeff Brownd04a88c2011-01-16 14:05:47 -08002280 config.hardKeyboardHidden = Configuration.HARDKEYBOARDHIDDEN_YES;
Jeff Browndaa37532012-05-01 15:54:03 -07002281 if (!mHasSoftInput) {
2282 config.keyboardHidden = Configuration.KEYBOARDHIDDEN_YES;
2283 }
Jeff Brownd04a88c2011-01-16 14:05:47 -08002284 }
2285
Jeff Browndaa37532012-05-01 15:54:03 -07002286 if (config.navigation == Configuration.NAVIGATION_NONAV
2287 || (navigationPresence == PRESENCE_INTERNAL
2288 && isHidden(mLidNavigationAccessibility))) {
Jeff Brownd04a88c2011-01-16 14:05:47 -08002289 config.navigationHidden = Configuration.NAVIGATIONHIDDEN_YES;
Jeff Brownd04a88c2011-01-16 14:05:47 -08002290 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002291 }
Jeff Brownd04a88c2011-01-16 14:05:47 -08002292
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002293 /** {@inheritDoc} */
Craig Mautner967212c2013-04-13 21:10:58 -07002294 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002295 public int windowTypeToLayerLw(int type) {
2296 if (type >= FIRST_APPLICATION_WINDOW && type <= LAST_APPLICATION_WINDOW) {
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07002297 return 2;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002298 }
2299 switch (type) {
keunyounga446bf02013-06-21 19:07:57 -07002300 case TYPE_PRIVATE_PRESENTATION:
2301 return 2;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07002302 case TYPE_WALLPAPER:
2303 // wallpaper is at the bottom, though the window manager may move it.
2304 return 2;
Filip Gruszczynskie95b0ae2015-09-30 10:55:33 -07002305 case TYPE_DOCK_DIVIDER:
2306 return 2;
Jason Monk8f7f3182015-11-18 16:35:14 -05002307 case TYPE_QS_DIALOG:
2308 return 2;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07002309 case TYPE_PHONE:
2310 return 3;
2311 case TYPE_SEARCH_BAR:
Jorim Jaggi225d3b52015-04-01 11:18:57 -07002312 case TYPE_VOICE_INTERACTION_STARTING:
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07002313 return 4;
Dianne Hackborne30e02f2014-05-27 18:24:45 -07002314 case TYPE_VOICE_INTERACTION:
2315 // voice interaction layer is almost immediately above apps.
2316 return 5;
Selim Cinekf83e8242015-05-19 18:08:14 -07002317 case TYPE_INPUT_CONSUMER:
Dianne Hackborne30e02f2014-05-27 18:24:45 -07002318 return 6;
Selim Cinekf83e8242015-05-19 18:08:14 -07002319 case TYPE_SYSTEM_DIALOG:
2320 return 7;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07002321 case TYPE_TOAST:
2322 // toasts and the plugged-in battery thing
Selim Cinekf83e8242015-05-19 18:08:14 -07002323 return 8;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07002324 case TYPE_PRIORITY_PHONE:
2325 // SIM errors and unlock. Not sure if this really should be in a high layer.
Selim Cinekf83e8242015-05-19 18:08:14 -07002326 return 9;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07002327 case TYPE_DREAM:
2328 // used for Dreams (screensavers with TYPE_DREAM windows)
Selim Cinekf83e8242015-05-19 18:08:14 -07002329 return 10;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07002330 case TYPE_SYSTEM_ALERT:
2331 // like the ANR / app crashed dialogs
Selim Cinekf83e8242015-05-19 18:08:14 -07002332 return 11;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07002333 case TYPE_INPUT_METHOD:
2334 // on-screen keyboards and other such input method user interfaces go here.
Selim Cinekf83e8242015-05-19 18:08:14 -07002335 return 12;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07002336 case TYPE_INPUT_METHOD_DIALOG:
2337 // on-screen keyboards and other such input method user interfaces go here.
Selim Cinekf83e8242015-05-19 18:08:14 -07002338 return 13;
Jim Miller5ecd8112013-01-09 18:50:26 -08002339 case TYPE_KEYGUARD_SCRIM:
2340 // the safety window that shows behind keyguard while keyguard is starting
Filip Gruszczynskie95b0ae2015-09-30 10:55:33 -07002341 return 14;
Filip Gruszczynski466f3212015-09-21 17:57:57 -07002342 case TYPE_STATUS_BAR_SUB_PANEL:
Filip Gruszczynskie95b0ae2015-09-30 10:55:33 -07002343 return 15;
Filip Gruszczynski466f3212015-09-21 17:57:57 -07002344 case TYPE_STATUS_BAR:
Filip Gruszczynskie95b0ae2015-09-30 10:55:33 -07002345 return 16;
Filip Gruszczynski466f3212015-09-21 17:57:57 -07002346 case TYPE_STATUS_BAR_PANEL:
Filip Gruszczynskie95b0ae2015-09-30 10:55:33 -07002347 return 17;
Filip Gruszczynski466f3212015-09-21 17:57:57 -07002348 case TYPE_KEYGUARD_DIALOG:
Filip Gruszczynskie95b0ae2015-09-30 10:55:33 -07002349 return 18;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07002350 case TYPE_VOLUME_OVERLAY:
2351 // the on-screen volume indicator and controller shown when the user
2352 // changes the device volume
Filip Gruszczynskie95b0ae2015-09-30 10:55:33 -07002353 return 19;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07002354 case TYPE_SYSTEM_OVERLAY:
2355 // the on-screen volume indicator and controller shown when the user
2356 // changes the device volume
Filip Gruszczynskie95b0ae2015-09-30 10:55:33 -07002357 return 20;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07002358 case TYPE_NAVIGATION_BAR:
2359 // the navigation bar, if available, shows atop most things
Filip Gruszczynskie95b0ae2015-09-30 10:55:33 -07002360 return 21;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07002361 case TYPE_NAVIGATION_BAR_PANEL:
2362 // some panels (e.g. search) need to show on top of the navigation bar
Filip Gruszczynskie95b0ae2015-09-30 10:55:33 -07002363 return 22;
Muyuan Li6ca619f2016-03-08 13:30:42 -08002364 case TYPE_SCREENSHOT:
2365 // screenshot selection layer shouldn't go above system error, but it should cover
2366 // navigation bars at the very least.
2367 return 23;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07002368 case TYPE_SYSTEM_ERROR:
2369 // system-level error dialogs
Muyuan Li6ca619f2016-03-08 13:30:42 -08002370 return 24;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07002371 case TYPE_MAGNIFICATION_OVERLAY:
2372 // used to highlight the magnified portion of a display
Muyuan Li6ca619f2016-03-08 13:30:42 -08002373 return 25;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07002374 case TYPE_DISPLAY_OVERLAY:
2375 // used to simulate secondary display devices
Muyuan Li6ca619f2016-03-08 13:30:42 -08002376 return 26;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07002377 case TYPE_DRAG:
2378 // the drag layer: input for drag-and-drop is associated with this window,
2379 // which sits above all other focusable windows
Muyuan Li6ca619f2016-03-08 13:30:42 -08002380 return 27;
Svetoslav3a5c7212014-10-14 09:54:26 -07002381 case TYPE_ACCESSIBILITY_OVERLAY:
2382 // overlay put by accessibility services to intercept user interaction
Filip Gruszczynskie95b0ae2015-09-30 10:55:33 -07002383 return 28;
Muyuan Li6ca619f2016-03-08 13:30:42 -08002384 case TYPE_SECURE_SYSTEM_OVERLAY:
Filip Gruszczynskie95b0ae2015-09-30 10:55:33 -07002385 return 29;
Muyuan Li6ca619f2016-03-08 13:30:42 -08002386 case TYPE_BOOT_PROGRESS:
2387 return 30;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07002388 case TYPE_POINTER:
2389 // the (mouse) pointer layer
Muyuan Li6ca619f2016-03-08 13:30:42 -08002390 return 31;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002391 }
2392 Log.e(TAG, "Unknown window type: " + type);
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07002393 return 2;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002394 }
2395
2396 /** {@inheritDoc} */
Craig Mautner46ac6fa2013-08-01 10:06:34 -07002397 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002398 public int subWindowTypeToLayerLw(int type) {
2399 switch (type) {
2400 case TYPE_APPLICATION_PANEL:
2401 case TYPE_APPLICATION_ATTACHED_DIALOG:
2402 return APPLICATION_PANEL_SUBLAYER;
2403 case TYPE_APPLICATION_MEDIA:
2404 return APPLICATION_MEDIA_SUBLAYER;
Dianne Hackborn5cb8d792009-05-21 17:34:15 -07002405 case TYPE_APPLICATION_MEDIA_OVERLAY:
2406 return APPLICATION_MEDIA_OVERLAY_SUBLAYER;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002407 case TYPE_APPLICATION_SUB_PANEL:
2408 return APPLICATION_SUB_PANEL_SUBLAYER;
Wale Ogunwale0a4dc222015-04-14 12:58:42 -07002409 case TYPE_APPLICATION_ABOVE_SUB_PANEL:
2410 return APPLICATION_ABOVE_SUB_PANEL_SUBLAYER;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002411 }
2412 Log.e(TAG, "Unknown sub-window type: " + type);
2413 return 0;
2414 }
2415
Craig Mautner46ac6fa2013-08-01 10:06:34 -07002416 @Override
Dianne Hackbornabe0da02009-09-18 01:55:39 -07002417 public int getMaxWallpaperLayer() {
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07002418 return windowTypeToLayerLw(TYPE_STATUS_BAR);
Dianne Hackbornabe0da02009-09-18 01:55:39 -07002419 }
2420
Sriram Viswanathan9ebbe6a2015-11-16 17:59:22 -08002421 private int getNavigationBarWidth(int rotation, int uiMode) {
2422 if ((uiMode & UI_MODE_TYPE_MASK) == UI_MODE_TYPE_CAR) {
2423 return mNavigationBarWidthForRotationInCarMode[rotation];
2424 } else {
2425 return mNavigationBarWidthForRotationDefault[rotation];
2426 }
2427 }
2428
Craig Mautner46ac6fa2013-08-01 10:06:34 -07002429 @Override
Sriram Viswanathan9ebbe6a2015-11-16 17:59:22 -08002430 public int getNonDecorDisplayWidth(int fullWidth, int fullHeight, int rotation,
2431 int uiMode) {
Dianne Hackborn077ee852012-04-09 16:27:07 -07002432 if (mHasNavigationBar) {
2433 // For a basic navigation bar, when we are in landscape mode we place
2434 // the navigation bar to the side.
Daniel Sandler4a066c52012-04-20 14:49:13 -04002435 if (mNavigationBarCanMove && fullWidth > fullHeight) {
Sriram Viswanathan9ebbe6a2015-11-16 17:59:22 -08002436 return fullWidth - getNavigationBarWidth(rotation, uiMode);
Dianne Hackborn077ee852012-04-09 16:27:07 -07002437 }
Dianne Hackborn1f903c32011-09-13 19:18:06 -07002438 }
2439 return fullWidth;
Dianne Hackborne2515ee2011-04-27 18:52:56 -04002440 }
2441
Sriram Viswanathan9ebbe6a2015-11-16 17:59:22 -08002442 private int getNavigationBarHeight(int rotation, int uiMode) {
2443 if ((uiMode & UI_MODE_TYPE_MASK) == UI_MODE_TYPE_CAR) {
2444 return mNavigationBarHeightForRotationInCarMode[rotation];
2445 } else {
2446 return mNavigationBarHeightForRotationDefault[rotation];
2447 }
2448 }
2449
Jose Lima9546b202014-07-02 17:21:51 -07002450 @Override
Sriram Viswanathan9ebbe6a2015-11-16 17:59:22 -08002451 public int getNonDecorDisplayHeight(int fullWidth, int fullHeight, int rotation,
2452 int uiMode) {
Dianne Hackborn077ee852012-04-09 16:27:07 -07002453 if (mHasNavigationBar) {
2454 // For a basic navigation bar, when we are in portrait mode we place
2455 // the navigation bar to the bottom.
Daniel Sandler4a066c52012-04-20 14:49:13 -04002456 if (!mNavigationBarCanMove || fullWidth < fullHeight) {
Sriram Viswanathan9ebbe6a2015-11-16 17:59:22 -08002457 return fullHeight - getNavigationBarHeight(rotation, uiMode);
Dianne Hackborn077ee852012-04-09 16:27:07 -07002458 }
2459 }
2460 return fullHeight;
Dianne Hackborn69cb8752011-05-19 18:13:32 -07002461 }
2462
Jose Lima9546b202014-07-02 17:21:51 -07002463 @Override
Sriram Viswanathan9ebbe6a2015-11-16 17:59:22 -08002464 public int getConfigDisplayWidth(int fullWidth, int fullHeight, int rotation, int uiMode) {
2465 return getNonDecorDisplayWidth(fullWidth, fullHeight, rotation, uiMode);
Dianne Hackborn69cb8752011-05-19 18:13:32 -07002466 }
2467
Jose Lima9546b202014-07-02 17:21:51 -07002468 @Override
Sriram Viswanathan9ebbe6a2015-11-16 17:59:22 -08002469 public int getConfigDisplayHeight(int fullWidth, int fullHeight, int rotation, int uiMode) {
John Spurlock80f00c12013-06-13 11:10:51 -04002470 // There is a separate status bar at the top of the display. We don't count that as part
2471 // of the fixed decor, since it can hide; however, for purposes of configurations,
Dianne Hackborn077ee852012-04-09 16:27:07 -07002472 // we do want to exclude it since applications can't generally use that part
2473 // of the screen.
Sriram Viswanathan9ebbe6a2015-11-16 17:59:22 -08002474 return getNonDecorDisplayHeight(
2475 fullWidth, fullHeight, rotation, uiMode) - mStatusBarHeight;
Dianne Hackborne2515ee2011-04-27 18:52:56 -04002476 }
2477
Craig Mautnera3f4bf52012-10-10 20:37:48 -07002478 @Override
Craig Mautnerc9457fa2014-06-06 14:27:48 -07002479 public boolean isForceHiding(WindowManager.LayoutParams attrs) {
2480 return (attrs.privateFlags & PRIVATE_FLAG_KEYGUARD) != 0 ||
Jim Millerab954542014-10-10 18:21:49 -07002481 (isKeyguardHostWindow(attrs) &&
2482 (mKeyguardDelegate != null && mKeyguardDelegate.isShowing())) ||
Adrian Roos69e510d2014-07-13 14:57:59 +02002483 (attrs.type == TYPE_KEYGUARD_SCRIM);
Dianne Hackborn01ad2f42009-09-24 19:24:56 -07002484 }
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07002485
Craig Mautnera3f4bf52012-10-10 20:37:48 -07002486 @Override
Jorim Jaggi0d674622014-05-21 01:34:15 +02002487 public boolean isKeyguardHostWindow(WindowManager.LayoutParams attrs) {
2488 return attrs.type == TYPE_STATUS_BAR;
2489 }
2490
2491 @Override
Dianne Hackborn01ad2f42009-09-24 19:24:56 -07002492 public boolean canBeForceHidden(WindowState win, WindowManager.LayoutParams attrs) {
Craig Mautnera3f4bf52012-10-10 20:37:48 -07002493 switch (attrs.type) {
2494 case TYPE_STATUS_BAR:
2495 case TYPE_NAVIGATION_BAR:
2496 case TYPE_WALLPAPER:
2497 case TYPE_DREAM:
Jim Miller5ecd8112013-01-09 18:50:26 -08002498 case TYPE_KEYGUARD_SCRIM:
Craig Mautnera3f4bf52012-10-10 20:37:48 -07002499 return false;
2500 default:
Adrian Roos461829d2015-06-03 14:41:18 -07002501 // Hide only windows below the keyguard host window.
2502 return windowTypeToLayerLw(win.getBaseType())
2503 < windowTypeToLayerLw(TYPE_STATUS_BAR);
Craig Mautnera3f4bf52012-10-10 20:37:48 -07002504 }
Dianne Hackborn01ad2f42009-09-24 19:24:56 -07002505 }
Craig Mautner8e4df6c2012-05-23 16:57:23 -07002506
Craig Mautner7d7808f2014-09-11 18:02:38 -07002507 @Override
2508 public WindowState getWinShowWhenLockedLw() {
2509 return mWinShowWhenLocked;
2510 }
2511
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002512 /** {@inheritDoc} */
Craig Mautner8e4df6c2012-05-23 16:57:23 -07002513 @Override
Dianne Hackborn2f0b1752011-05-31 17:59:49 -07002514 public View addStartingWindow(IBinder appToken, String packageName, int theme,
2515 CompatibilityInfo compatInfo, CharSequence nonLocalizedLabel, int labelRes,
Adam Powell04fe6eb2013-05-31 14:39:48 -07002516 int icon, int logo, int windowFlags) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002517 if (!SHOW_STARTING_ANIMATIONS) {
2518 return null;
2519 }
2520 if (packageName == null) {
2521 return null;
2522 }
Craig Mautner8e4df6c2012-05-23 16:57:23 -07002523
Mathias Jeppssond1443e92012-08-24 15:25:32 +02002524 WindowManager wm = null;
2525 View view = null;
2526
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002527 try {
Dianne Hackborn867ab6472010-04-29 13:28:56 -07002528 Context context = mContext;
Craig Mautner6fbda632012-07-03 09:26:39 -07002529 if (DEBUG_STARTING_WINDOW) Slog.d(TAG, "addStartingWindow " + packageName
2530 + ": nonLocalizedLabel=" + nonLocalizedLabel + " theme="
2531 + Integer.toHexString(theme));
Dianne Hackborn247fe742011-01-08 17:25:57 -08002532 if (theme != context.getThemeResId() || labelRes != 0) {
Dianne Hackborn867ab6472010-04-29 13:28:56 -07002533 try {
2534 context = context.createPackageContext(packageName, 0);
Dianne Hackborn247fe742011-01-08 17:25:57 -08002535 context.setTheme(theme);
Dianne Hackborn867ab6472010-04-29 13:28:56 -07002536 } catch (PackageManager.NameNotFoundException e) {
2537 // Ignore
2538 }
2539 }
Craig Mautner8e4df6c2012-05-23 16:57:23 -07002540
Jorim Jaggia16cc152015-06-01 16:55:05 -07002541 PhoneWindow win = new PhoneWindow(context);
2542 win.setIsStartingWindow(true);
Craig Mautner8e4df6c2012-05-23 16:57:23 -07002543
Dianne Hackborn867ab6472010-04-29 13:28:56 -07002544 Resources r = context.getResources();
2545 win.setTitle(r.getText(labelRes, nonLocalizedLabel));
Craig Mautner8e4df6c2012-05-23 16:57:23 -07002546
Dianne Hackborn867ab6472010-04-29 13:28:56 -07002547 win.setType(
2548 WindowManager.LayoutParams.TYPE_APPLICATION_STARTING);
Adrian Roos602c68e2015-04-24 16:03:47 -07002549
2550 synchronized (mWindowManagerFuncs.getWindowManagerLock()) {
2551 // Assumes it's safe to show starting windows of launched apps while
2552 // the keyguard is being hidden. This is okay because starting windows never show
2553 // secret information.
2554 if (mKeyguardHidden) {
2555 windowFlags |= FLAG_SHOW_WHEN_LOCKED;
2556 }
2557 }
2558
Dianne Hackborn867ab6472010-04-29 13:28:56 -07002559 // Force the window flags: this is a fake window, so it is not really
2560 // touchable or focusable by the user. We also add in the ALT_FOCUSABLE_IM
2561 // flag because we do know that the next window will take input
2562 // focus, so we want to get the IME window up on top of us right away.
2563 win.setFlags(
Dianne Hackborn7eec10e2010-11-12 18:03:47 -08002564 windowFlags|
Dianne Hackborn867ab6472010-04-29 13:28:56 -07002565 WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE|
2566 WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE|
2567 WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM,
Dianne Hackborn7eec10e2010-11-12 18:03:47 -08002568 windowFlags|
Dianne Hackborn867ab6472010-04-29 13:28:56 -07002569 WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE|
2570 WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE|
2571 WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM);
Craig Mautner8e4df6c2012-05-23 16:57:23 -07002572
Adam Powell04fe6eb2013-05-31 14:39:48 -07002573 win.setDefaultIcon(icon);
2574 win.setDefaultLogo(logo);
2575
Dianne Hackborn867ab6472010-04-29 13:28:56 -07002576 win.setLayout(WindowManager.LayoutParams.MATCH_PARENT,
Dianne Hackborn2f0b1752011-05-31 17:59:49 -07002577 WindowManager.LayoutParams.MATCH_PARENT);
Craig Mautner8e4df6c2012-05-23 16:57:23 -07002578
Dianne Hackborn867ab6472010-04-29 13:28:56 -07002579 final WindowManager.LayoutParams params = win.getAttributes();
2580 params.token = appToken;
2581 params.packageName = packageName;
2582 params.windowAnimations = win.getWindowStyle().getResourceId(
2583 com.android.internal.R.styleable.Window_windowAnimationStyle, 0);
John Reck61375a82014-09-18 19:27:48 +00002584 params.privateFlags |=
2585 WindowManager.LayoutParams.PRIVATE_FLAG_FAKE_HARDWARE_ACCELERATED;
Craig Mautner88400d32012-09-30 12:35:45 -07002586 params.privateFlags |= WindowManager.LayoutParams.PRIVATE_FLAG_SHOW_FOR_ALL_USERS;
Adam Lesinski95c42972013-10-02 10:13:27 -07002587
2588 if (!compatInfo.supportsScreen()) {
2589 params.privateFlags |= WindowManager.LayoutParams.PRIVATE_FLAG_COMPATIBLE_WINDOW;
2590 }
2591
Dianne Hackborn867ab6472010-04-29 13:28:56 -07002592 params.setTitle("Starting " + packageName);
2593
Mathias Jeppssond1443e92012-08-24 15:25:32 +02002594 wm = (WindowManager)context.getSystemService(Context.WINDOW_SERVICE);
2595 view = win.getDecorView();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002596
Craig Mautner6fbda632012-07-03 09:26:39 -07002597 if (DEBUG_STARTING_WINDOW) Slog.d(
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002598 TAG, "Adding starting window for " + packageName
2599 + " / " + appToken + ": "
2600 + (view.getParent() != null ? view : null));
2601
2602 wm.addView(view, params);
2603
2604 // Only return the view if it was successfully added to the
2605 // window manager... which we can tell by it having a parent.
2606 return view.getParent() != null ? view : null;
Jeff Brown98365d72012-08-19 20:30:52 -07002607 } catch (WindowManager.BadTokenException e) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002608 // ignore
Craig Mautner42bf39e2014-02-21 16:46:22 -08002609 Log.w(TAG, appToken + " already running, starting window not displayed. " +
2610 e.getMessage());
Dianne Hackborn867ab6472010-04-29 13:28:56 -07002611 } catch (RuntimeException e) {
2612 // don't crash if something else bad happens, for example a
2613 // failure loading resources because we are loading from an app
2614 // on external storage that has been unmounted.
2615 Log.w(TAG, appToken + " failed creating starting window", e);
Mathias Jeppssond1443e92012-08-24 15:25:32 +02002616 } finally {
2617 if (view != null && view.getParent() == null) {
2618 Log.w(TAG, "view not successfully added to wm, removing view");
2619 wm.removeViewImmediate(view);
2620 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002621 }
2622
2623 return null;
2624 }
2625
2626 /** {@inheritDoc} */
Jose Lima9546b202014-07-02 17:21:51 -07002627 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002628 public void removeStartingWindow(IBinder appToken, View window) {
Craig Mautner276a6eb2014-11-04 15:32:57 -08002629 if (DEBUG_STARTING_WINDOW) Slog.v(TAG, "Removing starting window for " + appToken + ": "
2630 + window + " Callers=" + Debug.getCallers(4));
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002631
2632 if (window != null) {
Dianne Hackborn5fd21692011-06-07 14:09:47 -07002633 WindowManager wm = (WindowManager)mContext.getSystemService(Context.WINDOW_SERVICE);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002634 wm.removeView(window);
2635 }
2636 }
2637
2638 /**
2639 * Preflight adding a window to the system.
RoboErik8a2cfc32014-05-16 11:19:38 -07002640 *
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002641 * Currently enforces that three window types are singletons:
2642 * <ul>
2643 * <li>STATUS_BAR_TYPE</li>
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002644 * <li>KEYGUARD_TYPE</li>
2645 * </ul>
RoboErik8a2cfc32014-05-16 11:19:38 -07002646 *
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002647 * @param win The window to be added
2648 * @param attrs Information about the window to be added
RoboErik8a2cfc32014-05-16 11:19:38 -07002649 *
Jeff Brown98365d72012-08-19 20:30:52 -07002650 * @return If ok, WindowManagerImpl.ADD_OKAY. If too many singletons,
2651 * WindowManagerImpl.ADD_MULTIPLE_SINGLETON
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002652 */
Jose Lima9546b202014-07-02 17:21:51 -07002653 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002654 public int prepareAddWindowLw(WindowState win, WindowManager.LayoutParams attrs) {
2655 switch (attrs.type) {
2656 case TYPE_STATUS_BAR:
Joe Onorato8bc6c512010-06-04 16:21:12 -04002657 mContext.enforceCallingOrSelfPermission(
2658 android.Manifest.permission.STATUS_BAR_SERVICE,
2659 "PhoneWindowManager");
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002660 if (mStatusBar != null) {
Dianne Hackbornf87d1962012-04-04 12:48:24 -07002661 if (mStatusBar.isAlive()) {
Jeff Brown98365d72012-08-19 20:30:52 -07002662 return WindowManagerGlobal.ADD_MULTIPLE_SINGLETON;
Dianne Hackbornf87d1962012-04-04 12:48:24 -07002663 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002664 }
2665 mStatusBar = win;
John Spurlock27735a42013-08-14 17:57:38 -04002666 mStatusBarController.setWindow(win);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002667 break;
Daniel Sandler8956dbb2011-04-22 07:55:02 -04002668 case TYPE_NAVIGATION_BAR:
2669 mContext.enforceCallingOrSelfPermission(
2670 android.Manifest.permission.STATUS_BAR_SERVICE,
2671 "PhoneWindowManager");
Dianne Hackbornf87d1962012-04-04 12:48:24 -07002672 if (mNavigationBar != null) {
2673 if (mNavigationBar.isAlive()) {
Jeff Brown98365d72012-08-19 20:30:52 -07002674 return WindowManagerGlobal.ADD_MULTIPLE_SINGLETON;
Dianne Hackbornf87d1962012-04-04 12:48:24 -07002675 }
2676 }
Daniel Sandler8956dbb2011-04-22 07:55:02 -04002677 mNavigationBar = win;
John Spurlock27735a42013-08-14 17:57:38 -04002678 mNavigationBarController.setWindow(win);
Craig Mautnereda67292013-04-28 13:50:14 -07002679 if (DEBUG_LAYOUT) Slog.i(TAG, "NAVIGATION BAR: " + mNavigationBar);
Daniel Sandler8956dbb2011-04-22 07:55:02 -04002680 break;
Jim Millere898ac52012-04-06 17:10:57 -07002681 case TYPE_NAVIGATION_BAR_PANEL:
Dianne Hackborn08743722009-12-21 12:16:51 -08002682 case TYPE_STATUS_BAR_PANEL:
Joe Onorato29fc2c92010-11-24 10:26:50 -08002683 case TYPE_STATUS_BAR_SUB_PANEL:
Jorim Jaggi225d3b52015-04-01 11:18:57 -07002684 case TYPE_VOICE_INTERACTION_STARTING:
Joe Onorato29fc2c92010-11-24 10:26:50 -08002685 mContext.enforceCallingOrSelfPermission(
2686 android.Manifest.permission.STATUS_BAR_SERVICE,
2687 "PhoneWindowManager");
Joe Onorato29fc2c92010-11-24 10:26:50 -08002688 break;
Jim Miller5ecd8112013-01-09 18:50:26 -08002689 case TYPE_KEYGUARD_SCRIM:
Jim Miller25190572013-02-28 17:36:24 -08002690 if (mKeyguardScrim != null) {
2691 return WindowManagerGlobal.ADD_MULTIPLE_SINGLETON;
2692 }
Jim Miller5ecd8112013-01-09 18:50:26 -08002693 mKeyguardScrim = win;
2694 break;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002695 }
Jeff Brown98365d72012-08-19 20:30:52 -07002696 return WindowManagerGlobal.ADD_OKAY;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002697 }
2698
2699 /** {@inheritDoc} */
Jose Lima9546b202014-07-02 17:21:51 -07002700 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002701 public void removeWindowLw(WindowState win) {
2702 if (mStatusBar == win) {
2703 mStatusBar = null;
John Spurlock27735a42013-08-14 17:57:38 -04002704 mStatusBarController.setWindow(null);
Jim Millerc0b676d2013-03-22 16:11:08 -07002705 mKeyguardDelegate.showScrim();
Jim Miller5ecd8112013-01-09 18:50:26 -08002706 } else if (mKeyguardScrim == win) {
2707 Log.v(TAG, "Removing keyguard scrim");
2708 mKeyguardScrim = null;
2709 } if (mNavigationBar == win) {
Daniel Sandler8956dbb2011-04-22 07:55:02 -04002710 mNavigationBar = null;
John Spurlock27735a42013-08-14 17:57:38 -04002711 mNavigationBarController.setWindow(null);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002712 }
2713 }
2714
2715 static final boolean PRINT_ANIM = false;
RoboErik8a2cfc32014-05-16 11:19:38 -07002716
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002717 /** {@inheritDoc} */
Craig Mautner4b71aa12012-12-27 17:20:01 -08002718 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002719 public int selectAnimationLw(WindowState win, int transit) {
2720 if (PRINT_ANIM) Log.i(TAG, "selectAnimation in " + win
2721 + ": transit=" + transit);
Dianne Hackbornf87d1962012-04-04 12:48:24 -07002722 if (win == mStatusBar) {
Jorim Jaggi380ecb82014-03-14 17:25:20 +01002723 boolean isKeyguard = (win.getAttrs().privateFlags & PRIVATE_FLAG_KEYGUARD) != 0;
Craig Mautner4b71aa12012-12-27 17:20:01 -08002724 if (transit == TRANSIT_EXIT
2725 || transit == TRANSIT_HIDE) {
Jorim Jaggi380ecb82014-03-14 17:25:20 +01002726 return isKeyguard ? -1 : R.anim.dock_top_exit;
Craig Mautner4b71aa12012-12-27 17:20:01 -08002727 } else if (transit == TRANSIT_ENTER
2728 || transit == TRANSIT_SHOW) {
Jorim Jaggi380ecb82014-03-14 17:25:20 +01002729 return isKeyguard ? -1 : R.anim.dock_top_enter;
Dianne Hackbornf87d1962012-04-04 12:48:24 -07002730 }
2731 } else if (win == mNavigationBar) {
Jorim Jaggi0d210f62015-07-10 14:24:44 -07002732 if (win.getAttrs().windowAnimations != 0) {
2733 return 0;
2734 }
Dianne Hackbornf87d1962012-04-04 12:48:24 -07002735 // This can be on either the bottom or the right.
2736 if (mNavigationBarOnBottom) {
Craig Mautner4b71aa12012-12-27 17:20:01 -08002737 if (transit == TRANSIT_EXIT
2738 || transit == TRANSIT_HIDE) {
Dianne Hackbornf87d1962012-04-04 12:48:24 -07002739 return R.anim.dock_bottom_exit;
Craig Mautner4b71aa12012-12-27 17:20:01 -08002740 } else if (transit == TRANSIT_ENTER
2741 || transit == TRANSIT_SHOW) {
Dianne Hackbornf87d1962012-04-04 12:48:24 -07002742 return R.anim.dock_bottom_enter;
2743 }
2744 } else {
Craig Mautner4b71aa12012-12-27 17:20:01 -08002745 if (transit == TRANSIT_EXIT
2746 || transit == TRANSIT_HIDE) {
Dianne Hackbornf87d1962012-04-04 12:48:24 -07002747 return R.anim.dock_right_exit;
Craig Mautner4b71aa12012-12-27 17:20:01 -08002748 } else if (transit == TRANSIT_ENTER
2749 || transit == TRANSIT_SHOW) {
Dianne Hackbornf87d1962012-04-04 12:48:24 -07002750 return R.anim.dock_right_enter;
2751 }
2752 }
Filip Gruszczynski57f76f12015-11-04 16:10:54 -08002753 } else if (win.getAttrs().type == TYPE_DOCK_DIVIDER) {
Jorim Jaggi81ba11e2016-02-03 22:04:22 -08002754 return selectDockedDividerAnimationLw(win, transit);
Craig Mautner4b71aa12012-12-27 17:20:01 -08002755 }
2756
2757 if (transit == TRANSIT_PREVIEW_DONE) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002758 if (win.hasAppShownWindows()) {
2759 if (PRINT_ANIM) Log.i(TAG, "**** STARTING EXIT");
2760 return com.android.internal.R.anim.app_starting_exit;
2761 }
Dianne Hackborn7ad44382012-10-18 17:46:00 -07002762 } else if (win.getAttrs().type == TYPE_DREAM && mDreamingLockscreen
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07002763 && transit == TRANSIT_ENTER) {
2764 // Special case: we are animating in a dream, while the keyguard
2765 // is shown. We don't want an animation on the dream, because
2766 // we need it shown immediately with the keyguard animating away
2767 // to reveal it.
2768 return -1;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002769 }
2770
2771 return 0;
2772 }
2773
Jorim Jaggi81ba11e2016-02-03 22:04:22 -08002774 private int selectDockedDividerAnimationLw(WindowState win, int transit) {
2775 int insets = mWindowManagerFuncs.getDockedDividerInsetsLw();
2776
2777 // If the divider is behind the navigation bar, don't animate.
Jorim Jaggi0cb0f722016-03-25 20:49:41 -07002778 final Rect frame = win.getFrameLw();
2779 final boolean behindNavBar = mNavigationBar != null
Jorim Jaggi192086e2016-03-11 17:17:03 +01002780 && ((mNavigationBarOnBottom
Jorim Jaggi0cb0f722016-03-25 20:49:41 -07002781 && frame.top + insets >= mNavigationBar.getFrameLw().top)
Jorim Jaggi192086e2016-03-11 17:17:03 +01002782 || (!mNavigationBarOnBottom
Jorim Jaggi0cb0f722016-03-25 20:49:41 -07002783 && frame.left + insets >= mNavigationBar.getFrameLw().left));
2784 final boolean landscape = frame.height() > frame.width();
2785 final boolean offscreenLandscape = landscape && (frame.right - insets <= 0
2786 || frame.left + insets >= win.getDisplayFrameLw().right);
2787 final boolean offscreenPortrait = !landscape && (frame.top - insets <= 0
2788 || frame.bottom + insets >= win.getDisplayFrameLw().bottom);
2789 final boolean offscreen = offscreenLandscape || offscreenPortrait;
2790 if (behindNavBar || offscreen) {
Jorim Jaggi81ba11e2016-02-03 22:04:22 -08002791 return 0;
2792 }
2793 if (transit == TRANSIT_ENTER || transit == TRANSIT_SHOW) {
2794 return R.anim.fade_in;
2795 } else if (transit == TRANSIT_EXIT) {
2796 return R.anim.fade_out;
2797 } else {
2798 return 0;
2799 }
2800 }
2801
Craig Mautner3c174372013-02-21 17:54:37 -08002802 @Override
2803 public void selectRotationAnimationLw(int anim[]) {
2804 if (PRINT_ANIM) Slog.i(TAG, "selectRotationAnimation mTopFullscreen="
2805 + mTopFullscreenOpaqueWindowState + " rotationAnimation="
2806 + (mTopFullscreenOpaqueWindowState == null ?
2807 "0" : mTopFullscreenOpaqueWindowState.getAttrs().rotationAnimation));
2808 if (mTopFullscreenOpaqueWindowState != null && mTopIsFullscreen) {
2809 switch (mTopFullscreenOpaqueWindowState.getAttrs().rotationAnimation) {
2810 case ROTATION_ANIMATION_CROSSFADE:
2811 anim[0] = R.anim.rotation_animation_xfade_exit;
2812 anim[1] = R.anim.rotation_animation_enter;
2813 break;
2814 case ROTATION_ANIMATION_JUMPCUT:
2815 anim[0] = R.anim.rotation_animation_jump_exit;
2816 anim[1] = R.anim.rotation_animation_enter;
2817 break;
2818 case ROTATION_ANIMATION_ROTATE:
2819 default:
2820 anim[0] = anim[1] = 0;
2821 break;
2822 }
2823 } else {
2824 anim[0] = anim[1] = 0;
2825 }
2826 }
2827
2828 @Override
2829 public boolean validateRotationAnimationLw(int exitAnimId, int enterAnimId,
2830 boolean forceDefault) {
2831 switch (exitAnimId) {
2832 case R.anim.rotation_animation_xfade_exit:
2833 case R.anim.rotation_animation_jump_exit:
2834 // These are the only cases that matter.
2835 if (forceDefault) {
2836 return false;
2837 }
2838 int anim[] = new int[2];
2839 selectRotationAnimationLw(anim);
2840 return (exitAnimId == anim[0] && enterAnimId == anim[1]);
2841 default:
2842 return true;
2843 }
2844 }
2845
2846 @Override
Jorim Jaggi84a3e7a2014-08-13 17:58:58 +02002847 public Animation createForceHideEnterAnimation(boolean onWallpaper,
2848 boolean goingToNotificationShade) {
2849 if (goingToNotificationShade) {
2850 return AnimationUtils.loadAnimation(mContext, R.anim.lock_screen_behind_enter_fade_in);
Craig Mautnerb8340802014-11-04 15:32:57 -08002851 }
Craig Mautner276a6eb2014-11-04 15:32:57 -08002852
2853 AnimationSet set = (AnimationSet) AnimationUtils.loadAnimation(mContext, onWallpaper ?
2854 R.anim.lock_screen_behind_enter_wallpaper :
2855 R.anim.lock_screen_behind_enter);
2856
2857 // TODO: Use XML interpolators when we have log interpolators available in XML.
2858 final List<Animation> animations = set.getAnimations();
2859 for (int i = animations.size() - 1; i >= 0; --i) {
2860 animations.get(i).setInterpolator(mLogDecelerateInterpolator);
2861 }
2862
2863 return set;
Jorim Jaggi76a16232014-08-08 17:00:47 +02002864 }
2865
2866
2867 @Override
Jorim Jaggi84a3e7a2014-08-13 17:58:58 +02002868 public Animation createForceHideWallpaperExitAnimation(boolean goingToNotificationShade) {
2869 if (goingToNotificationShade) {
2870 return null;
2871 } else {
2872 return AnimationUtils.loadAnimation(mContext, R.anim.lock_screen_wallpaper_exit);
2873 }
Dianne Hackborn01ad2f42009-09-24 19:24:56 -07002874 }
John Spurlockc8b46ca2013-04-08 12:59:26 -04002875
2876 private static void awakenDreams() {
2877 IDreamManager dreamManager = getDreamManager();
2878 if (dreamManager != null) {
2879 try {
2880 dreamManager.awaken();
2881 } catch (RemoteException e) {
2882 // fine, stay asleep then
2883 }
2884 }
2885 }
2886
2887 static IDreamManager getDreamManager() {
2888 return IDreamManager.Stub.asInterface(
2889 ServiceManager.checkService(DreamService.DREAM_SERVICE));
2890 }
2891
Tyler Gunnef9f6f92014-09-12 22:16:17 -07002892 TelecomManager getTelecommService() {
2893 return (TelecomManager) mContext.getSystemService(Context.TELECOM_SERVICE);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002894 }
2895
Jeff Brown4d396052010-10-29 21:50:21 -07002896 static IAudioService getAudioService() {
2897 IAudioService audioService = IAudioService.Stub.asInterface(
2898 ServiceManager.checkService(Context.AUDIO_SERVICE));
2899 if (audioService == null) {
2900 Log.w(TAG, "Unable to find IAudioService interface.");
2901 }
2902 return audioService;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002903 }
2904
2905 boolean keyguardOn() {
Jim Millerab954542014-10-10 18:21:49 -07002906 return isKeyguardShowingAndNotOccluded() || inKeyguardRestrictedKeyInputMode();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002907 }
2908
2909 private static final int[] WINDOW_TYPES_WHERE_HOME_DOESNT_WORK = {
2910 WindowManager.LayoutParams.TYPE_SYSTEM_ALERT,
2911 WindowManager.LayoutParams.TYPE_SYSTEM_ERROR,
2912 };
2913
2914 /** {@inheritDoc} */
Jeff Brown00fa7bd2010-07-02 15:37:36 -07002915 @Override
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002916 public long interceptKeyBeforeDispatching(WindowState win, KeyEvent event, int policyFlags) {
Jeff Brown00fa7bd2010-07-02 15:37:36 -07002917 final boolean keyguardOn = keyguardOn();
Jeff Brown1f245102010-11-18 20:53:46 -08002918 final int keyCode = event.getKeyCode();
2919 final int repeatCount = event.getRepeatCount();
2920 final int metaState = event.getMetaState();
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002921 final int flags = event.getFlags();
Jeff Brown1f245102010-11-18 20:53:46 -08002922 final boolean down = event.getAction() == KeyEvent.ACTION_DOWN;
2923 final boolean canceled = event.isCanceled();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002924
Jeff Brown40013652012-05-16 21:22:36 -07002925 if (DEBUG_INPUT) {
Jeff Brown00fa7bd2010-07-02 15:37:36 -07002926 Log.d(TAG, "interceptKeyTi keyCode=" + keyCode + " down=" + down + " repeatCount="
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002927 + repeatCount + " keyguardOn=" + keyguardOn + " mHomePressed=" + mHomePressed
2928 + " canceled=" + canceled);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002929 }
2930
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002931 // If we think we might have a volume down & power key chord on the way
2932 // but we're not sure, then tell the dispatcher to wait a little while and
2933 // try again later before dispatching.
Christopher Tatee90585f2012-03-05 18:56:25 -08002934 if (mScreenshotChordEnabled && (flags & KeyEvent.FLAG_FALLBACK) == 0) {
Jeff Brown13f00f02014-10-31 14:45:50 -07002935 if (mScreenshotChordVolumeDownKeyTriggered && !mScreenshotChordPowerKeyTriggered) {
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002936 final long now = SystemClock.uptimeMillis();
Jeff Brown13f00f02014-10-31 14:45:50 -07002937 final long timeoutTime = mScreenshotChordVolumeDownKeyTime
2938 + SCREENSHOT_CHORD_DEBOUNCE_DELAY_MILLIS;
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002939 if (now < timeoutTime) {
2940 return timeoutTime - now;
2941 }
2942 }
2943 if (keyCode == KeyEvent.KEYCODE_VOLUME_DOWN
Jeff Brown13f00f02014-10-31 14:45:50 -07002944 && mScreenshotChordVolumeDownKeyConsumed) {
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002945 if (!down) {
Jeff Brown13f00f02014-10-31 14:45:50 -07002946 mScreenshotChordVolumeDownKeyConsumed = false;
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002947 }
2948 return -1;
2949 }
2950 }
2951
Michael Wright6a62e552014-06-03 19:19:48 -07002952 // Cancel any pending meta actions if we see any other keys being pressed between the down
2953 // of the meta key and its corresponding up.
Michael Wright251e35d2014-08-22 15:40:27 -07002954 if (mPendingMetaAction && !KeyEvent.isMetaKey(keyCode)) {
Michael Wright6a62e552014-06-03 19:19:48 -07002955 mPendingMetaAction = false;
2956 }
2957
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002958 // First we always handle the home key here, so applications
2959 // can never break it, although if keyguard is on, we do let
2960 // it handle it, because that gives us the correct 5 second
2961 // timeout.
Jeff Brown00fa7bd2010-07-02 15:37:36 -07002962 if (keyCode == KeyEvent.KEYCODE_HOME) {
Michael Jurka7f2668c2012-03-27 07:49:52 -07002963
Jeff Brown49ed71d2010-12-06 17:13:33 -08002964 // If we have released the home key, and didn't do anything else
2965 // while it was pressed, then it is time to go home!
Michael Jurka7f2668c2012-03-27 07:49:52 -07002966 if (!down) {
Jeff Browncaca8812013-05-09 13:34:33 -07002967 cancelPreloadRecentApps();
2968
Jeff Brown49ed71d2010-12-06 17:13:33 -08002969 mHomePressed = false;
Jeff Browncaca8812013-05-09 13:34:33 -07002970 if (mHomeConsumed) {
2971 mHomeConsumed = false;
Michael Jurka7f2668c2012-03-27 07:49:52 -07002972 return -1;
Jeff Brown49ed71d2010-12-06 17:13:33 -08002973 }
Jeff Browncaca8812013-05-09 13:34:33 -07002974
2975 if (canceled) {
2976 Log.i(TAG, "Ignoring HOME; event canceled.");
2977 return -1;
2978 }
2979
Yorke Lee4f803242014-12-15 23:22:06 +00002980 // If an incoming call is ringing, HOME is totally disabled.
2981 // (The user is already on the InCallUI at this point,
2982 // and his ONLY options are to answer or reject the call.)
2983 TelecomManager telecomManager = getTelecommService();
2984 if (telecomManager != null && telecomManager.isRinging()) {
2985 Log.i(TAG, "Ignoring HOME; there's a ringing incoming call.");
2986 return -1;
2987 }
2988
Jeff Browncaca8812013-05-09 13:34:33 -07002989 // Delay handling home if a double-tap is possible.
2990 if (mDoubleTapOnHomeBehavior != DOUBLE_TAP_HOME_NOTHING) {
2991 mHandler.removeCallbacks(mHomeDoubleTapTimeoutRunnable); // just in case
2992 mHomeDoubleTapPending = true;
2993 mHandler.postDelayed(mHomeDoubleTapTimeoutRunnable,
2994 ViewConfiguration.getDoubleTapTimeout());
2995 return -1;
2996 }
2997
Jeff Brown13f00f02014-10-31 14:45:50 -07002998 handleShortPressOnHome();
Jeff Browncaca8812013-05-09 13:34:33 -07002999 return -1;
Jeff Brown49ed71d2010-12-06 17:13:33 -08003000 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003001
3002 // If a system window has focus, then it doesn't make sense
3003 // right now to interact with applications.
3004 WindowManager.LayoutParams attrs = win != null ? win.getAttrs() : null;
3005 if (attrs != null) {
3006 final int type = attrs.type;
Jorim Jaggi380ecb82014-03-14 17:25:20 +01003007 if (type == WindowManager.LayoutParams.TYPE_KEYGUARD_SCRIM
3008 || type == WindowManager.LayoutParams.TYPE_KEYGUARD_DIALOG
3009 || (attrs.privateFlags & PRIVATE_FLAG_KEYGUARD) != 0) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003010 // the "app" is keyguard, so give it the key
Jeff Brownd5bb82d2011-10-12 13:57:59 -07003011 return 0;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003012 }
3013 final int typeCount = WINDOW_TYPES_WHERE_HOME_DOESNT_WORK.length;
3014 for (int i=0; i<typeCount; i++) {
3015 if (type == WINDOW_TYPES_WHERE_HOME_DOESNT_WORK[i]) {
3016 // don't do anything, but also don't pass it to the app
Jeff Brownd5bb82d2011-10-12 13:57:59 -07003017 return -1;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003018 }
3019 }
3020 }
Jeff Browncaca8812013-05-09 13:34:33 -07003021
3022 // Remember that home is pressed and handle special actions.
3023 if (repeatCount == 0) {
3024 mHomePressed = true;
3025 if (mHomeDoubleTapPending) {
3026 mHomeDoubleTapPending = false;
3027 mHandler.removeCallbacks(mHomeDoubleTapTimeoutRunnable);
3028 handleDoubleTapOnHome();
3029 } else if (mLongPressOnHomeBehavior == LONG_PRESS_HOME_RECENT_SYSTEM_UI
3030 || mDoubleTapOnHomeBehavior == DOUBLE_TAP_HOME_RECENT_SYSTEM_UI) {
3031 preloadRecentApps();
Michael Jurka7f2668c2012-03-27 07:49:52 -07003032 }
Jeff Browncaca8812013-05-09 13:34:33 -07003033 } else if ((event.getFlags() & KeyEvent.FLAG_LONG_PRESS) != 0) {
3034 if (!keyguardOn) {
Jaewan Kim76b7d0d2016-02-12 19:01:02 +09003035 handleLongPressOnHome(event.getDeviceId());
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003036 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003037 }
Jeff Brownd5bb82d2011-10-12 13:57:59 -07003038 return -1;
Jeff Brown00fa7bd2010-07-02 15:37:36 -07003039 } else if (keyCode == KeyEvent.KEYCODE_MENU) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003040 // Hijack modified menu keys for debugging features
3041 final int chordBug = KeyEvent.META_SHIFT_ON;
3042
3043 if (down && repeatCount == 0) {
Jeff Brown00fa7bd2010-07-02 15:37:36 -07003044 if (mEnableShiftMenuBugReports && (metaState & chordBug) == chordBug) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003045 Intent intent = new Intent(Intent.ACTION_BUG_REPORT);
Dianne Hackborn5ac72a22012-08-29 18:32:08 -07003046 mContext.sendOrderedBroadcastAsUser(intent, UserHandle.CURRENT,
3047 null, null, null, 0, null, null);
Jeff Brownd5bb82d2011-10-12 13:57:59 -07003048 return -1;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003049 } else if (SHOW_PROCESSES_ON_ALT_MENU &&
Jeff Brown00fa7bd2010-07-02 15:37:36 -07003050 (metaState & KeyEvent.META_ALT_ON) == KeyEvent.META_ALT_ON) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003051 Intent service = new Intent();
3052 service.setClassName(mContext, "com.android.server.LoadAverageService");
3053 ContentResolver res = mContext.getContentResolver();
Jeff Sharkey8d9a1f62012-10-18 15:38:14 -07003054 boolean shown = Settings.Global.getInt(
3055 res, Settings.Global.SHOW_PROCESSES, 0) != 0;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003056 if (!shown) {
3057 mContext.startService(service);
3058 } else {
3059 mContext.stopService(service);
3060 }
Jeff Sharkey8d9a1f62012-10-18 15:38:14 -07003061 Settings.Global.putInt(
3062 res, Settings.Global.SHOW_PROCESSES, shown ? 0 : 1);
Jeff Brownd5bb82d2011-10-12 13:57:59 -07003063 return -1;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003064 }
3065 }
Jeff Brown00fa7bd2010-07-02 15:37:36 -07003066 } else if (keyCode == KeyEvent.KEYCODE_SEARCH) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003067 if (down) {
3068 if (repeatCount == 0) {
Jeff Brownfd23e3e2012-05-09 13:34:28 -07003069 mSearchKeyShortcutPending = true;
3070 mConsumeSearchKeyUp = false;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003071 }
Jeff Brownfd23e3e2012-05-09 13:34:28 -07003072 } else {
3073 mSearchKeyShortcutPending = false;
3074 if (mConsumeSearchKeyUp) {
3075 mConsumeSearchKeyUp = false;
Jeff Brownd5bb82d2011-10-12 13:57:59 -07003076 return -1;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003077 }
3078 }
Jeff Brownd5bb82d2011-10-12 13:57:59 -07003079 return 0;
Jeff Brown49ed71d2010-12-06 17:13:33 -08003080 } else if (keyCode == KeyEvent.KEYCODE_APP_SWITCH) {
Michael Wrightc9ebea72013-01-16 19:25:02 -08003081 if (!keyguardOn) {
Jeff Browncaca8812013-05-09 13:34:33 -07003082 if (down && repeatCount == 0) {
3083 preloadRecentApps();
3084 } else if (!down) {
3085 toggleRecentApps();
Michael Wrightc9ebea72013-01-16 19:25:02 -08003086 }
Jeff Brown49ed71d2010-12-06 17:13:33 -08003087 }
Jeff Brownd5bb82d2011-10-12 13:57:59 -07003088 return -1;
Jun Mukaid21b3c82015-04-23 14:09:34 -07003089 } else if (keyCode == KeyEvent.KEYCODE_N && event.isMetaPressed()) {
3090 if (down) {
3091 IStatusBarService service = getStatusBarService();
3092 if (service != null) {
3093 try {
3094 service.expandNotificationsPanel();
3095 } catch (RemoteException e) {
3096 // do nothing.
3097 }
3098 }
3099 }
Muyuan Li6ca619f2016-03-08 13:30:42 -08003100 } else if (keyCode == KeyEvent.KEYCODE_S && event.isMetaPressed()
3101 && event.isCtrlPressed()) {
3102 if (down && repeatCount == 0) {
3103 int type = event.isShiftPressed() ? TAKE_SCREENSHOT_SELECTED_REGION
3104 : TAKE_SCREENSHOT_FULLSCREEN;
3105 mScreenshotRunnable.setScreenshotType(type);
3106 mHandler.post(mScreenshotRunnable);
3107 return -1;
3108 }
Clara Bayarrif2debb12015-07-10 14:47:17 +01003109 } else if (keyCode == KeyEvent.KEYCODE_SLASH && event.isMetaPressed()) {
Andrei Stingaceanu002f7122016-03-30 12:22:05 +01003110 if (down && repeatCount == 0 && !isKeyguardLocked()) {
3111 toggleKeyboardShortcutsMenu(event.getDeviceId());
Clara Bayarrif2debb12015-07-10 14:47:17 +01003112 }
Jeff Brownde7a8ea2012-06-13 18:28:57 -07003113 } else if (keyCode == KeyEvent.KEYCODE_ASSIST) {
3114 if (down) {
3115 if (repeatCount == 0) {
3116 mAssistKeyLongPressed = false;
3117 } else if (repeatCount == 1) {
3118 mAssistKeyLongPressed = true;
3119 if (!keyguardOn) {
3120 launchAssistLongPressAction();
3121 }
3122 }
3123 } else {
3124 if (mAssistKeyLongPressed) {
3125 mAssistKeyLongPressed = false;
3126 } else {
3127 if (!keyguardOn) {
Tim Kilbourn0e5f1102015-06-05 16:18:09 -07003128 launchAssistAction(null, event.getDeviceId());
Jeff Brownde7a8ea2012-06-13 18:28:57 -07003129 }
3130 }
3131 }
3132 return -1;
Michael Wrightdc63f7b2014-08-21 19:05:21 -07003133 } else if (keyCode == KeyEvent.KEYCODE_VOICE_ASSIST) {
3134 if (!down) {
3135 Intent voiceIntent;
Michael Wright869a67c2014-08-26 19:33:06 -07003136 if (!keyguardOn) {
Michael Wrightdc63f7b2014-08-21 19:05:21 -07003137 voiceIntent = new Intent(RecognizerIntent.ACTION_WEB_SEARCH);
3138 } else {
Dianne Hackbornb6683c42015-06-18 17:40:33 -07003139 IDeviceIdleController dic = IDeviceIdleController.Stub.asInterface(
3140 ServiceManager.getService(Context.DEVICE_IDLE_CONTROLLER));
3141 if (dic != null) {
3142 try {
3143 dic.exitIdle("voice-search");
3144 } catch (RemoteException e) {
3145 }
3146 }
Michael Wrightdc63f7b2014-08-21 19:05:21 -07003147 voiceIntent = new Intent(RecognizerIntent.ACTION_VOICE_SEARCH_HANDS_FREE);
Michael Wright869a67c2014-08-26 19:33:06 -07003148 voiceIntent.putExtra(RecognizerIntent.EXTRA_SECURE, true);
Michael Wrightdc63f7b2014-08-21 19:05:21 -07003149 }
Bart Sears8b1c27c2015-03-18 23:51:02 +00003150 startActivityAsUser(voiceIntent, UserHandle.CURRENT_OR_SELF);
Michael Wrightdc63f7b2014-08-21 19:05:21 -07003151 }
Jeff Sharkey2991fa32012-12-05 18:06:43 -08003152 } else if (keyCode == KeyEvent.KEYCODE_SYSRQ) {
3153 if (down && repeatCount == 0) {
Muyuan Li6ca619f2016-03-08 13:30:42 -08003154 mScreenshotRunnable.setScreenshotType(TAKE_SCREENSHOT_FULLSCREEN);
Jeff Sharkey2991fa32012-12-05 18:06:43 -08003155 mHandler.post(mScreenshotRunnable);
3156 }
3157 return -1;
Michael Wrightb854e242013-02-05 17:54:02 -08003158 } else if (keyCode == KeyEvent.KEYCODE_BRIGHTNESS_UP
3159 || keyCode == KeyEvent.KEYCODE_BRIGHTNESS_DOWN) {
3160 if (down) {
3161 int direction = keyCode == KeyEvent.KEYCODE_BRIGHTNESS_UP ? 1 : -1;
3162
3163 // Disable autobrightness if it's on
3164 int auto = Settings.System.getIntForUser(
3165 mContext.getContentResolver(),
3166 Settings.System.SCREEN_BRIGHTNESS_MODE,
3167 Settings.System.SCREEN_BRIGHTNESS_MODE_MANUAL,
3168 UserHandle.USER_CURRENT_OR_SELF);
3169 if (auto != 0) {
3170 Settings.System.putIntForUser(mContext.getContentResolver(),
3171 Settings.System.SCREEN_BRIGHTNESS_MODE,
3172 Settings.System.SCREEN_BRIGHTNESS_MODE_MANUAL,
3173 UserHandle.USER_CURRENT_OR_SELF);
3174 }
3175
3176 int min = mPowerManager.getMinimumScreenBrightnessSetting();
3177 int max = mPowerManager.getMaximumScreenBrightnessSetting();
3178 int step = (max - min + BRIGHTNESS_STEPS - 1) / BRIGHTNESS_STEPS * direction;
3179 int brightness = Settings.System.getIntForUser(mContext.getContentResolver(),
3180 Settings.System.SCREEN_BRIGHTNESS,
3181 mPowerManager.getDefaultScreenBrightnessSetting(),
3182 UserHandle.USER_CURRENT_OR_SELF);
3183 brightness += step;
3184 // Make sure we don't go beyond the limits.
3185 brightness = Math.min(max, brightness);
3186 brightness = Math.max(min, brightness);
3187
3188 Settings.System.putIntForUser(mContext.getContentResolver(),
3189 Settings.System.SCREEN_BRIGHTNESS, brightness,
3190 UserHandle.USER_CURRENT_OR_SELF);
Bart Sears8b1c27c2015-03-18 23:51:02 +00003191 startActivityAsUser(new Intent(Intent.ACTION_SHOW_BRIGHTNESS_DIALOG),
Alan Viverette5a399492014-07-14 16:19:38 -07003192 UserHandle.CURRENT_OR_SELF);
Michael Wrightb854e242013-02-05 17:54:02 -08003193 }
3194 return -1;
Jaewan Kim765487f2016-01-12 14:45:42 +09003195 } else if (keyCode == KeyEvent.KEYCODE_VOLUME_UP
3196 || keyCode == KeyEvent.KEYCODE_VOLUME_DOWN
3197 || keyCode == KeyEvent.KEYCODE_VOLUME_MUTE) {
3198 if (mUseTvRouting) {
3199 // On TVs volume keys never go to the foreground app.
3200 dispatchDirectAudioEvent(event);
3201 return -1;
3202 }
Muyuan Li94ce94e2016-02-24 16:20:54 -08003203 }
3204
3205 if (KeyEvent.isMetaKey(keyCode)) {
Michael Wright6a62e552014-06-03 19:19:48 -07003206 if (down) {
3207 mPendingMetaAction = true;
3208 } else if (mPendingMetaAction) {
Tim Kilbourn0e5f1102015-06-05 16:18:09 -07003209 launchAssistAction(Intent.EXTRA_ASSIST_INPUT_HINT_KEYBOARD, event.getDeviceId());
Michael Wright6a62e552014-06-03 19:19:48 -07003210 }
3211 return -1;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003212 }
Jeff Browncaab4d02010-12-09 22:13:41 -08003213
Jeff Brownc1fb48d2010-12-08 16:52:09 -08003214 // Shortcuts are invoked through Search+key, so intercept those here
Jeff Browncaab4d02010-12-09 22:13:41 -08003215 // Any printing key that is chorded with Search should be consumed
3216 // even if no shortcut was invoked. This prevents text from being
3217 // inadvertently inserted when using a keyboard that has built-in macro
3218 // shortcut keys (that emit Search+x) and some of them are not registered.
Jeff Brownfd23e3e2012-05-09 13:34:28 -07003219 if (mSearchKeyShortcutPending) {
Jeff Browncaab4d02010-12-09 22:13:41 -08003220 final KeyCharacterMap kcm = event.getKeyCharacterMap();
3221 if (kcm.isPrintingKey(keyCode)) {
Jeff Brownfd23e3e2012-05-09 13:34:28 -07003222 mConsumeSearchKeyUp = true;
3223 mSearchKeyShortcutPending = false;
Jeff Browncaab4d02010-12-09 22:13:41 -08003224 if (down && repeatCount == 0 && !keyguardOn) {
3225 Intent shortcutIntent = mShortcutManager.getIntent(kcm, keyCode, metaState);
3226 if (shortcutIntent != null) {
3227 shortcutIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
Jeff Brownf0a3cc52011-01-26 18:42:46 -08003228 try {
Bart Sears8b1c27c2015-03-18 23:51:02 +00003229 startActivityAsUser(shortcutIntent, UserHandle.CURRENT);
Jeff Brownf0a3cc52011-01-26 18:42:46 -08003230 } catch (ActivityNotFoundException ex) {
3231 Slog.w(TAG, "Dropping shortcut key combination because "
3232 + "the activity to which it is registered was not found: "
Jeff Brownfd23e3e2012-05-09 13:34:28 -07003233 + "SEARCH+" + KeyEvent.keyCodeToString(keyCode), ex);
Jeff Brownf0a3cc52011-01-26 18:42:46 -08003234 }
Jeff Browncaab4d02010-12-09 22:13:41 -08003235 } else {
3236 Slog.i(TAG, "Dropping unregistered shortcut key combination: "
Jeff Brownfd23e3e2012-05-09 13:34:28 -07003237 + "SEARCH+" + KeyEvent.keyCodeToString(keyCode));
Jeff Brown49ed71d2010-12-06 17:13:33 -08003238 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003239 }
Jeff Brownd5bb82d2011-10-12 13:57:59 -07003240 return -1;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003241 }
3242 }
3243
Jeff Brown68b909d2011-12-07 16:36:01 -08003244 // Invoke shortcuts using Meta.
Jeff Brown602ab322012-05-16 13:33:47 -07003245 if (down && repeatCount == 0 && !keyguardOn
Jeff Brown68b909d2011-12-07 16:36:01 -08003246 && (metaState & KeyEvent.META_META_ON) != 0) {
3247 final KeyCharacterMap kcm = event.getKeyCharacterMap();
Jeff Brown602ab322012-05-16 13:33:47 -07003248 if (kcm.isPrintingKey(keyCode)) {
3249 Intent shortcutIntent = mShortcutManager.getIntent(kcm, keyCode,
3250 metaState & ~(KeyEvent.META_META_ON
3251 | KeyEvent.META_META_LEFT_ON | KeyEvent.META_META_RIGHT_ON));
3252 if (shortcutIntent != null) {
3253 shortcutIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
3254 try {
Bart Sears8b1c27c2015-03-18 23:51:02 +00003255 startActivityAsUser(shortcutIntent, UserHandle.CURRENT);
Jeff Brown602ab322012-05-16 13:33:47 -07003256 } catch (ActivityNotFoundException ex) {
3257 Slog.w(TAG, "Dropping shortcut key combination because "
3258 + "the activity to which it is registered was not found: "
3259 + "META+" + KeyEvent.keyCodeToString(keyCode), ex);
3260 }
3261 return -1;
Jeff Brown68b909d2011-12-07 16:36:01 -08003262 }
Jeff Brown68b909d2011-12-07 16:36:01 -08003263 }
3264 }
3265
Jeff Brown6651a632011-11-28 12:59:11 -08003266 // Handle application launch keys.
Jeff Brown602ab322012-05-16 13:33:47 -07003267 if (down && repeatCount == 0 && !keyguardOn) {
Jeff Brown6651a632011-11-28 12:59:11 -08003268 String category = sApplicationLaunchKeyCategories.get(keyCode);
3269 if (category != null) {
Dianne Hackbornf5b86712011-12-05 17:42:41 -08003270 Intent intent = Intent.makeMainSelectorActivity(Intent.ACTION_MAIN, category);
Jeff Brown6651a632011-11-28 12:59:11 -08003271 intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
3272 try {
Bart Sears8b1c27c2015-03-18 23:51:02 +00003273 startActivityAsUser(intent, UserHandle.CURRENT);
Jeff Brown6651a632011-11-28 12:59:11 -08003274 } catch (ActivityNotFoundException ex) {
3275 Slog.w(TAG, "Dropping application launch key because "
3276 + "the activity to which it is registered was not found: "
3277 + "keyCode=" + keyCode + ", category=" + category, ex);
3278 }
Jeff Brown68b909d2011-12-07 16:36:01 -08003279 return -1;
Jeff Brown6651a632011-11-28 12:59:11 -08003280 }
3281 }
3282
Michael Wright61c46752014-08-21 16:57:33 -07003283 // Display task switcher for ALT-TAB.
Jeff Brown68b909d2011-12-07 16:36:01 -08003284 if (down && repeatCount == 0 && keyCode == KeyEvent.KEYCODE_TAB) {
Michael Wrightd847ad52015-10-24 13:24:15 +01003285 if (mRecentAppsHeldModifiers == 0 && !keyguardOn && isUserSetupComplete()) {
Jeff Brown68b909d2011-12-07 16:36:01 -08003286 final int shiftlessModifiers = event.getModifiers() & ~KeyEvent.META_SHIFT_MASK;
Michael Wright61c46752014-08-21 16:57:33 -07003287 if (KeyEvent.metaStateHasModifiers(shiftlessModifiers, KeyEvent.META_ALT_ON)) {
Winson Chung1e8d71b2014-05-16 17:05:22 -07003288 mRecentAppsHeldModifiers = shiftlessModifiers;
3289 showRecentApps(true);
Jeff Brown68b909d2011-12-07 16:36:01 -08003290 return -1;
3291 }
3292 }
Winson Chung1e8d71b2014-05-16 17:05:22 -07003293 } else if (!down && mRecentAppsHeldModifiers != 0
3294 && (metaState & mRecentAppsHeldModifiers) == 0) {
3295 mRecentAppsHeldModifiers = 0;
Winson Chungcdcd4872014-08-05 18:00:13 -07003296 hideRecentApps(true, false);
Jeff Brown68b909d2011-12-07 16:36:01 -08003297 }
3298
Yohei Yukawaae61f712015-12-09 13:00:10 -08003299 // Handle input method switching.
Jeff Browncf39bdf2012-05-18 14:41:19 -07003300 if (down && repeatCount == 0
3301 && (keyCode == KeyEvent.KEYCODE_LANGUAGE_SWITCH
3302 || (keyCode == KeyEvent.KEYCODE_SPACE
Yohei Yukawaae61f712015-12-09 13:00:10 -08003303 && (metaState & KeyEvent.META_META_MASK) != 0))) {
3304 final boolean forwardDirection = (metaState & KeyEvent.META_SHIFT_MASK) == 0;
3305 mWindowManagerFuncs.switchInputMethod(forwardDirection);
Jeff Browncf39bdf2012-05-18 14:41:19 -07003306 return -1;
3307 }
3308 if (mLanguageSwitchKeyPressed && !down
3309 && (keyCode == KeyEvent.KEYCODE_LANGUAGE_SWITCH
3310 || keyCode == KeyEvent.KEYCODE_SPACE)) {
3311 mLanguageSwitchKeyPressed = false;
3312 return -1;
3313 }
3314
Jeff Brown13f00f02014-10-31 14:45:50 -07003315 if (isValidGlobalKey(keyCode)
3316 && mGlobalKeyManager.handleGlobalKey(mContext, keyCode, event)) {
Justin Kohd378ad72013-04-01 12:18:26 -07003317 return -1;
3318 }
3319
Muyuan Li94ce94e2016-02-24 16:20:54 -08003320 if (down) {
3321 long shortcutCode = (long) keyCode;
3322 if (event.isCtrlPressed()) {
3323 shortcutCode |= ((long) KeyEvent.META_CTRL_ON) << Integer.SIZE;
3324 }
3325
3326 if (event.isAltPressed()) {
3327 shortcutCode |= ((long) KeyEvent.META_ALT_ON) << Integer.SIZE;
3328 }
3329
3330 if (event.isShiftPressed()) {
3331 shortcutCode |= ((long) KeyEvent.META_SHIFT_ON) << Integer.SIZE;
3332 }
3333
3334 if (event.isMetaPressed()) {
3335 shortcutCode |= ((long) KeyEvent.META_META_ON) << Integer.SIZE;
3336 }
3337
3338 IShortcutService shortcutService = mShortcutKeyServices.get(shortcutCode);
3339 if (shortcutService != null) {
3340 try {
3341 shortcutService.notifyShortcutKeyPressed(shortcutCode);
3342 } catch (RemoteException e) {
3343 mShortcutKeyServices.delete(shortcutCode);
3344 }
3345 return -1;
3346 }
3347 }
3348
Michael Wright6a62e552014-06-03 19:19:48 -07003349 // Reserve all the META modifier combos for system behavior
Michael Wrightce0c13a2014-07-30 10:49:21 -07003350 if ((metaState & KeyEvent.META_META_ON) != 0) {
Michael Wright6a62e552014-06-03 19:19:48 -07003351 return -1;
3352 }
3353
Jeff Brown68b909d2011-12-07 16:36:01 -08003354 // Let the application handle the key.
Jeff Brownd5bb82d2011-10-12 13:57:59 -07003355 return 0;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003356 }
3357
Jeff Brown3915bb82010-11-05 15:02:16 -07003358 /** {@inheritDoc} */
3359 @Override
Jeff Brown49ed71d2010-12-06 17:13:33 -08003360 public KeyEvent dispatchUnhandledKey(WindowState win, KeyEvent event, int policyFlags) {
Jeff Brown54875002011-04-06 15:33:01 -07003361 // Note: This method is only called if the initial down was unhandled.
Jeff Brown40013652012-05-16 21:22:36 -07003362 if (DEBUG_INPUT) {
Jeff Brown1f245102010-11-18 20:53:46 -08003363 Slog.d(TAG, "Unhandled key: win=" + win + ", action=" + event.getAction()
3364 + ", flags=" + event.getFlags()
3365 + ", keyCode=" + event.getKeyCode()
3366 + ", scanCode=" + event.getScanCode()
3367 + ", metaState=" + event.getMetaState()
3368 + ", repeatCount=" + event.getRepeatCount()
3369 + ", policyFlags=" + policyFlags);
Jeff Brown3915bb82010-11-05 15:02:16 -07003370 }
Jeff Brown49ed71d2010-12-06 17:13:33 -08003371
Jeff Brownfd23e3e2012-05-09 13:34:28 -07003372 KeyEvent fallbackEvent = null;
Jeff Brown49ed71d2010-12-06 17:13:33 -08003373 if ((event.getFlags() & KeyEvent.FLAG_FALLBACK) == 0) {
3374 final KeyCharacterMap kcm = event.getKeyCharacterMap();
Jeff Brownc1fb48d2010-12-08 16:52:09 -08003375 final int keyCode = event.getKeyCode();
3376 final int metaState = event.getMetaState();
Jeff Brownfd23e3e2012-05-09 13:34:28 -07003377 final boolean initialDown = event.getAction() == KeyEvent.ACTION_DOWN
3378 && event.getRepeatCount() == 0;
Jeff Brown49ed71d2010-12-06 17:13:33 -08003379
Jeff Brown54875002011-04-06 15:33:01 -07003380 // Check for fallback actions specified by the key character map.
Jeff Brownfd23e3e2012-05-09 13:34:28 -07003381 final FallbackAction fallbackAction;
3382 if (initialDown) {
3383 fallbackAction = kcm.getFallbackAction(keyCode, metaState);
3384 } else {
3385 fallbackAction = mFallbackActions.get(keyCode);
3386 }
3387
3388 if (fallbackAction != null) {
Jeff Brown40013652012-05-16 21:22:36 -07003389 if (DEBUG_INPUT) {
Jeff Brownfd23e3e2012-05-09 13:34:28 -07003390 Slog.d(TAG, "Fallback: keyCode=" + fallbackAction.keyCode
3391 + " metaState=" + Integer.toHexString(fallbackAction.metaState));
Jeff Brown49ed71d2010-12-06 17:13:33 -08003392 }
3393
Jeff Brownfd23e3e2012-05-09 13:34:28 -07003394 final int flags = event.getFlags() | KeyEvent.FLAG_FALLBACK;
3395 fallbackEvent = KeyEvent.obtain(
Jeff Brown49ed71d2010-12-06 17:13:33 -08003396 event.getDownTime(), event.getEventTime(),
Jeff Brownfd23e3e2012-05-09 13:34:28 -07003397 event.getAction(), fallbackAction.keyCode,
3398 event.getRepeatCount(), fallbackAction.metaState,
Jeff Brown49ed71d2010-12-06 17:13:33 -08003399 event.getDeviceId(), event.getScanCode(),
3400 flags, event.getSource(), null);
Jeff Brownfd23e3e2012-05-09 13:34:28 -07003401
3402 if (!interceptFallback(win, fallbackEvent, policyFlags)) {
3403 fallbackEvent.recycle();
3404 fallbackEvent = null;
Jeff Brown49ed71d2010-12-06 17:13:33 -08003405 }
Jeff Brownfd23e3e2012-05-09 13:34:28 -07003406
3407 if (initialDown) {
3408 mFallbackActions.put(keyCode, fallbackAction);
3409 } else if (event.getAction() == KeyEvent.ACTION_UP) {
3410 mFallbackActions.remove(keyCode);
3411 fallbackAction.recycle();
3412 }
Jeff Brown49ed71d2010-12-06 17:13:33 -08003413 }
3414 }
3415
Jeff Brown40013652012-05-16 21:22:36 -07003416 if (DEBUG_INPUT) {
Jeff Brownfd23e3e2012-05-09 13:34:28 -07003417 if (fallbackEvent == null) {
3418 Slog.d(TAG, "No fallback.");
3419 } else {
3420 Slog.d(TAG, "Performing fallback: " + fallbackEvent);
3421 }
Jeff Brown49ed71d2010-12-06 17:13:33 -08003422 }
Jeff Brownfd23e3e2012-05-09 13:34:28 -07003423 return fallbackEvent;
Jeff Brown3915bb82010-11-05 15:02:16 -07003424 }
3425
Jeff Brownfd23e3e2012-05-09 13:34:28 -07003426 private boolean interceptFallback(WindowState win, KeyEvent fallbackEvent, int policyFlags) {
Jeff Brown037c33e2014-04-09 00:31:55 -07003427 int actions = interceptKeyBeforeQueueing(fallbackEvent, policyFlags);
Jeff Brownfd23e3e2012-05-09 13:34:28 -07003428 if ((actions & ACTION_PASS_TO_USER) != 0) {
3429 long delayMillis = interceptKeyBeforeDispatching(
3430 win, fallbackEvent, policyFlags);
3431 if (delayMillis == 0) {
3432 return true;
3433 }
3434 }
3435 return false;
Jeff Brown6f2fba42011-02-19 01:08:02 -08003436 }
3437
Muyuan Li94ce94e2016-02-24 16:20:54 -08003438 public void registerShortcutKey(long shortcutCode, IShortcutService shortcutService)
3439 throws RemoteException {
3440 synchronized (mLock) {
3441 IShortcutService service = mShortcutKeyServices.get(shortcutCode);
Muyuan Li24d24ac2016-03-03 21:15:02 -08003442 if (service != null && service.asBinder().pingBinder()) {
3443 throw new RemoteException("Key already exists.");
Muyuan Li94ce94e2016-02-24 16:20:54 -08003444 }
3445
3446 mShortcutKeyServices.put(shortcutCode, shortcutService);
3447 }
3448 }
3449
Jeff Brownde7a8ea2012-06-13 18:28:57 -07003450 private void launchAssistLongPressAction() {
3451 performHapticFeedbackLw(null, HapticFeedbackConstants.LONG_PRESS, false);
3452 sendCloseSystemWindows(SYSTEM_DIALOG_REASON_ASSIST);
3453
3454 // launch the search activity
3455 Intent intent = new Intent(Intent.ACTION_SEARCH_LONG_PRESS);
3456 intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
3457 try {
RoboErik8a2cfc32014-05-16 11:19:38 -07003458 // TODO: This only stops the factory-installed search manager.
Jim Miller45308b12012-06-18 19:23:39 -07003459 // Need to formalize an API to handle others
Jeff Brownde7a8ea2012-06-13 18:28:57 -07003460 SearchManager searchManager = getSearchManager();
3461 if (searchManager != null) {
3462 searchManager.stopSearch();
3463 }
Bart Sears8b1c27c2015-03-18 23:51:02 +00003464 startActivityAsUser(intent, UserHandle.CURRENT);
Jeff Brownde7a8ea2012-06-13 18:28:57 -07003465 } catch (ActivityNotFoundException e) {
3466 Slog.w(TAG, "No activity to handle assist long press action.", e);
3467 }
3468 }
3469
Tim Kilbourn0e5f1102015-06-05 16:18:09 -07003470 private void launchAssistAction(String hint, int deviceId) {
Jeff Brownde7a8ea2012-06-13 18:28:57 -07003471 sendCloseSystemWindows(SYSTEM_DIALOG_REASON_ASSIST);
Maurice Lam39d13812015-07-23 20:49:20 -07003472 if (!isUserSetupComplete()) {
3473 // Disable opening assist window during setup
3474 return;
3475 }
Tim Kilbourn0e5f1102015-06-05 16:18:09 -07003476 Bundle args = null;
3477 if (deviceId > Integer.MIN_VALUE) {
3478 args = new Bundle();
3479 args.putInt(Intent.EXTRA_ASSIST_INPUT_DEVICE_ID, deviceId);
Jeff Brownde7a8ea2012-06-13 18:28:57 -07003480 }
Jorim Jaggi165ce062015-07-06 16:18:11 -07003481 if ((mContext.getResources().getConfiguration().uiMode
3482 & Configuration.UI_MODE_TYPE_MASK) == Configuration.UI_MODE_TYPE_TELEVISION) {
3483 // On TV, use legacy handling until assistants are implemented in the proper way.
3484 ((SearchManager) mContext.getSystemService(Context.SEARCH_SERVICE))
3485 .launchLegacyAssist(hint, UserHandle.myUserId(), args);
3486 } else {
3487 try {
3488 if (hint != null) {
3489 if (args == null) {
3490 args = new Bundle();
3491 }
3492 args.putBoolean(hint, true);
3493 }
3494 IStatusBarService statusbar = getStatusBarService();
3495 if (statusbar != null) {
3496 statusbar.startAssist(args);
3497 }
3498 } catch (RemoteException e) {
3499 Slog.e(TAG, "RemoteException when starting assist", e);
3500 // re-acquire status bar service next time it is needed.
3501 mStatusBarService = null;
3502 }
3503 }
Jeff Brownde7a8ea2012-06-13 18:28:57 -07003504 }
3505
Bart Sears8b1c27c2015-03-18 23:51:02 +00003506 private void startActivityAsUser(Intent intent, UserHandle handle) {
3507 if (isUserSetupComplete()) {
3508 mContext.startActivityAsUser(intent, handle);
3509 } else {
3510 Slog.i(TAG, "Not starting activity because user setup is in progress: " + intent);
3511 }
3512 }
3513
Jeff Brownde7a8ea2012-06-13 18:28:57 -07003514 private SearchManager getSearchManager() {
3515 if (mSearchManager == null) {
3516 mSearchManager = (SearchManager) mContext.getSystemService(Context.SEARCH_SERVICE);
3517 }
3518 return mSearchManager;
3519 }
3520
Jeff Browncaca8812013-05-09 13:34:33 -07003521 private void preloadRecentApps() {
3522 mPreloadedRecentApps = true;
3523 try {
3524 IStatusBarService statusbar = getStatusBarService();
3525 if (statusbar != null) {
3526 statusbar.preloadRecentApps();
3527 }
3528 } catch (RemoteException e) {
3529 Slog.e(TAG, "RemoteException when preloading recent apps", e);
3530 // re-acquire status bar service next time it is needed.
3531 mStatusBarService = null;
3532 }
3533 }
3534
3535 private void cancelPreloadRecentApps() {
3536 if (mPreloadedRecentApps) {
3537 mPreloadedRecentApps = false;
3538 try {
3539 IStatusBarService statusbar = getStatusBarService();
3540 if (statusbar != null) {
3541 statusbar.cancelPreloadRecentApps();
3542 }
3543 } catch (RemoteException e) {
Winson Chung1e8d71b2014-05-16 17:05:22 -07003544 Slog.e(TAG, "RemoteException when cancelling recent apps preload", e);
Jeff Browncaca8812013-05-09 13:34:33 -07003545 // re-acquire status bar service next time it is needed.
3546 mStatusBarService = null;
3547 }
3548 }
3549 }
3550
3551 private void toggleRecentApps() {
3552 mPreloadedRecentApps = false; // preloading no longer needs to be canceled
Jeff Browncaca8812013-05-09 13:34:33 -07003553 try {
3554 IStatusBarService statusbar = getStatusBarService();
3555 if (statusbar != null) {
3556 statusbar.toggleRecentApps();
3557 }
3558 } catch (RemoteException e) {
Winson Chung1e8d71b2014-05-16 17:05:22 -07003559 Slog.e(TAG, "RemoteException when toggling recent apps", e);
3560 // re-acquire status bar service next time it is needed.
3561 mStatusBarService = null;
3562 }
3563 }
3564
Craig Mautner84984fa2014-06-19 11:19:20 -07003565 @Override
3566 public void showRecentApps() {
3567 mHandler.removeMessages(MSG_DISPATCH_SHOW_RECENTS);
3568 mHandler.sendEmptyMessage(MSG_DISPATCH_SHOW_RECENTS);
3569 }
3570
Winson Chung1e8d71b2014-05-16 17:05:22 -07003571 private void showRecentApps(boolean triggeredFromAltTab) {
3572 mPreloadedRecentApps = false; // preloading no longer needs to be canceled
3573 try {
3574 IStatusBarService statusbar = getStatusBarService();
3575 if (statusbar != null) {
3576 statusbar.showRecentApps(triggeredFromAltTab);
3577 }
3578 } catch (RemoteException e) {
Jeff Browncaca8812013-05-09 13:34:33 -07003579 Slog.e(TAG, "RemoteException when showing recent apps", e);
3580 // re-acquire status bar service next time it is needed.
3581 mStatusBarService = null;
3582 }
3583 }
3584
Clara Bayarri4e850ff2016-03-02 11:12:32 -08003585 private void toggleKeyboardShortcutsMenu(int deviceId) {
Clara Bayarrif2debb12015-07-10 14:47:17 +01003586 try {
3587 IStatusBarService statusbar = getStatusBarService();
3588 if (statusbar != null) {
Clara Bayarri4e850ff2016-03-02 11:12:32 -08003589 statusbar.toggleKeyboardShortcutsMenu(deviceId);
Clara Bayarrif2debb12015-07-10 14:47:17 +01003590 }
3591 } catch (RemoteException e) {
3592 Slog.e(TAG, "RemoteException when showing keyboard shortcuts menu", e);
3593 }
3594 }
3595
Winson Chungcdcd4872014-08-05 18:00:13 -07003596 private void hideRecentApps(boolean triggeredFromAltTab, boolean triggeredFromHome) {
Winson Chung1e8d71b2014-05-16 17:05:22 -07003597 mPreloadedRecentApps = false; // preloading no longer needs to be canceled
3598 try {
3599 IStatusBarService statusbar = getStatusBarService();
3600 if (statusbar != null) {
Winson Chungcdcd4872014-08-05 18:00:13 -07003601 statusbar.hideRecentApps(triggeredFromAltTab, triggeredFromHome);
Winson Chung1e8d71b2014-05-16 17:05:22 -07003602 }
3603 } catch (RemoteException e) {
3604 Slog.e(TAG, "RemoteException when closing recent apps", e);
3605 // re-acquire status bar service next time it is needed.
3606 mStatusBarService = null;
3607 }
3608 }
3609
Filip Gruszczynskia483a1d2015-03-17 19:06:58 +00003610 void launchHomeFromHotKey() {
Bryce Lee662ed802015-04-10 20:11:39 +00003611 launchHomeFromHotKey(true /* awakenFromDreams */, true /*respectKeyguard*/);
Filip Gruszczynskia483a1d2015-03-17 19:06:58 +00003612 }
3613
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003614 /**
3615 * A home key -> launch home action was detected. Take the appropriate action
3616 * given the situation with the keyguard.
3617 */
Bryce Lee662ed802015-04-10 20:11:39 +00003618 void launchHomeFromHotKey(final boolean awakenFromDreams, final boolean respectKeyguard) {
3619 if (respectKeyguard) {
3620 if (isKeyguardShowingAndNotOccluded()) {
3621 // don't launch home if keyguard showing
3622 return;
3623 }
3624
3625 if (!mHideLockScreen && mKeyguardDelegate.isInputRestricted()) {
3626 // when in keyguard restricted mode, must first verify unlock
3627 // before launching home
3628 mKeyguardDelegate.verifyUnlock(new OnKeyguardExitResult() {
3629 @Override
3630 public void onKeyguardExitResult(boolean success) {
3631 if (success) {
3632 try {
3633 ActivityManagerNative.getDefault().stopAppSwitches();
3634 } catch (RemoteException e) {
3635 }
3636 sendCloseSystemWindows(SYSTEM_DIALOG_REASON_HOME_KEY);
3637 startDockOrHome(true /*fromHomeKey*/, awakenFromDreams);
Dianne Hackborn256dd3b2009-05-19 18:51:21 -07003638 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003639 }
Bryce Lee662ed802015-04-10 20:11:39 +00003640 });
3641 return;
3642 }
3643 }
3644
3645 // no keyguard stuff to worry about, just launch home!
3646 try {
3647 ActivityManagerNative.getDefault().stopAppSwitches();
3648 } catch (RemoteException e) {
3649 }
3650 if (mRecentsVisible) {
3651 // Hide Recents and notify it to launch Home
3652 if (awakenFromDreams) {
3653 awakenDreams();
3654 }
Bryce Lee662ed802015-04-10 20:11:39 +00003655 hideRecentApps(false, true);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003656 } else {
Bryce Lee662ed802015-04-10 20:11:39 +00003657 // Otherwise, just launch Home
3658 sendCloseSystemWindows(SYSTEM_DIALOG_REASON_HOME_KEY);
3659 startDockOrHome(true /*fromHomeKey*/, awakenFromDreams);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003660 }
3661 }
3662
John Spurlock04db1762013-05-13 12:46:41 -04003663 private final Runnable mClearHideNavigationFlag = new Runnable() {
3664 @Override
3665 public void run() {
3666 synchronized (mWindowManagerFuncs.getWindowManagerLock()) {
3667 // Clear flags.
3668 mForceClearedSystemUiFlags &=
3669 ~View.SYSTEM_UI_FLAG_HIDE_NAVIGATION;
3670 }
3671 mWindowManagerFuncs.reevaluateStatusBarVisibility();
Dianne Hackborne26ab702011-10-16 13:21:33 -07003672 }
3673 };
3674
3675 /**
3676 * Input handler used while nav bar is hidden. Captures any touch on the screen,
3677 * to determine when the nav bar should be shown and prevent applications from
3678 * receiving those touches.
3679 */
Jeff Brown32cbc38552011-12-01 14:01:49 -08003680 final class HideNavInputEventReceiver extends InputEventReceiver {
3681 public HideNavInputEventReceiver(InputChannel inputChannel, Looper looper) {
3682 super(inputChannel, looper);
3683 }
3684
Dianne Hackborndf89e652011-10-06 22:35:11 -07003685 @Override
Jeff Brown32cbc38552011-12-01 14:01:49 -08003686 public void onInputEvent(InputEvent event) {
Dianne Hackborndf89e652011-10-06 22:35:11 -07003687 boolean handled = false;
3688 try {
Jeff Brown4952dfd2011-11-30 19:23:22 -08003689 if (event instanceof MotionEvent
3690 && (event.getSource() & InputDevice.SOURCE_CLASS_POINTER) != 0) {
3691 final MotionEvent motionEvent = (MotionEvent)event;
3692 if (motionEvent.getAction() == MotionEvent.ACTION_DOWN) {
Dianne Hackborndf89e652011-10-06 22:35:11 -07003693 // When the user taps down, we re-show the nav bar.
3694 boolean changed = false;
John Spurlock04db1762013-05-13 12:46:41 -04003695 synchronized (mWindowManagerFuncs.getWindowManagerLock()) {
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07003696 // Any user activity always causes us to show the
3697 // navigation controls, if they had been hidden.
3698 // We also clear the low profile and only content
3699 // flags so that tapping on the screen will atomically
3700 // restore all currently hidden screen decorations.
3701 int newVal = mResettingSystemUiFlags |
3702 View.SYSTEM_UI_FLAG_HIDE_NAVIGATION |
3703 View.SYSTEM_UI_FLAG_LOW_PROFILE |
3704 View.SYSTEM_UI_FLAG_FULLSCREEN;
Dianne Hackborne26ab702011-10-16 13:21:33 -07003705 if (mResettingSystemUiFlags != newVal) {
3706 mResettingSystemUiFlags = newVal;
Dianne Hackborndf89e652011-10-06 22:35:11 -07003707 changed = true;
3708 }
Dianne Hackborne26ab702011-10-16 13:21:33 -07003709 // We don't allow the system's nav bar to be hidden
3710 // again for 1 second, to prevent applications from
3711 // spamming us and keeping it from being shown.
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07003712 newVal = mForceClearedSystemUiFlags |
3713 View.SYSTEM_UI_FLAG_HIDE_NAVIGATION;
Dianne Hackborne26ab702011-10-16 13:21:33 -07003714 if (mForceClearedSystemUiFlags != newVal) {
3715 mForceClearedSystemUiFlags = newVal;
3716 changed = true;
John Spurlock04db1762013-05-13 12:46:41 -04003717 mHandler.postDelayed(mClearHideNavigationFlag, 1000);
Dianne Hackborne26ab702011-10-16 13:21:33 -07003718 }
Dianne Hackborndf89e652011-10-06 22:35:11 -07003719 }
3720 if (changed) {
3721 mWindowManagerFuncs.reevaluateStatusBarVisibility();
3722 }
3723 }
3724 }
3725 } finally {
Jeff Brown32cbc38552011-12-01 14:01:49 -08003726 finishInputEvent(event, handled);
Dianne Hackborndf89e652011-10-06 22:35:11 -07003727 }
3728 }
Jeff Brown32cbc38552011-12-01 14:01:49 -08003729 }
3730 final InputEventReceiver.Factory mHideNavInputEventReceiverFactory =
3731 new InputEventReceiver.Factory() {
3732 @Override
3733 public InputEventReceiver createInputEventReceiver(
3734 InputChannel inputChannel, Looper looper) {
3735 return new HideNavInputEventReceiver(inputChannel, looper);
3736 }
Dianne Hackborndf89e652011-10-06 22:35:11 -07003737 };
3738
3739 @Override
3740 public int adjustSystemUiVisibilityLw(int visibility) {
John Spurlock5b9145b2013-08-20 15:13:47 -04003741 mStatusBarController.adjustSystemUiVisibilityLw(mLastSystemUiFlags, visibility);
3742 mNavigationBarController.adjustSystemUiVisibilityLw(mLastSystemUiFlags, visibility);
Winson Chungd42a6cf2014-06-03 16:24:04 -07003743 mRecentsVisible = (visibility & View.RECENT_APPS_VISIBLE) > 0;
John Spurlock27735a42013-08-14 17:57:38 -04003744
Dianne Hackborndf89e652011-10-06 22:35:11 -07003745 // Reset any bits in mForceClearingStatusBarVisibility that
3746 // are now clear.
Dianne Hackborne26ab702011-10-16 13:21:33 -07003747 mResettingSystemUiFlags &= visibility;
Dianne Hackborndf89e652011-10-06 22:35:11 -07003748 // Clear any bits in the new visibility that are currently being
3749 // force cleared, before reporting it.
Dianne Hackborne26ab702011-10-16 13:21:33 -07003750 return visibility & ~mResettingSystemUiFlags
3751 & ~mForceClearedSystemUiFlags;
Dianne Hackborndf89e652011-10-06 22:35:11 -07003752 }
3753
Craig Mautner69b08182012-09-05 13:07:13 -07003754 @Override
Jorim Jaggi0ffd49c2016-02-12 15:04:21 -08003755 public boolean getInsetHintLw(WindowManager.LayoutParams attrs, int displayRotation,
Filip Gruszczynski2987f612015-06-30 15:03:30 -07003756 Rect outContentInsets, Rect outStableInsets, Rect outOutsets) {
John Spurlockc6d1c602014-01-17 15:22:06 -05003757 final int fl = PolicyControl.getWindowFlags(null, attrs);
John Spurlock1db8b682014-02-18 11:18:59 -05003758 final int sysuiVis = PolicyControl.getSystemUiVisibility(null, attrs);
3759 final int systemUiVisibility = (sysuiVis | attrs.subtreeSystemUiVisibility);
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07003760
Filip Gruszczynski2987f612015-06-30 15:03:30 -07003761 final boolean useOutsets = outOutsets != null && shouldUseOutsets(attrs, fl);
3762 if (useOutsets) {
3763 int outset = ScreenShapeHelper.getWindowOutsetBottomPx(mContext.getResources());
3764 if (outset > 0) {
3765 if (displayRotation == Surface.ROTATION_0) {
3766 outOutsets.bottom += outset;
3767 } else if (displayRotation == Surface.ROTATION_90) {
3768 outOutsets.right += outset;
3769 } else if (displayRotation == Surface.ROTATION_180) {
3770 outOutsets.top += outset;
3771 } else if (displayRotation == Surface.ROTATION_270) {
3772 outOutsets.left += outset;
3773 }
3774 }
3775 }
3776
Dianne Hackborn5b5cc4d2012-05-16 13:15:00 -07003777 if ((fl & (FLAG_LAYOUT_IN_SCREEN | FLAG_LAYOUT_INSET_DECOR))
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003778 == (FLAG_LAYOUT_IN_SCREEN | FLAG_LAYOUT_INSET_DECOR)) {
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07003779 int availRight, availBottom;
Alan Viverette5a0f4ec2013-10-07 15:10:29 -07003780 if (canHideNavigationBar() &&
Dianne Hackborn5b5cc4d2012-05-16 13:15:00 -07003781 (systemUiVisibility & View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION) != 0) {
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07003782 availRight = mUnrestrictedScreenLeft + mUnrestrictedScreenWidth;
3783 availBottom = mUnrestrictedScreenTop + mUnrestrictedScreenHeight;
3784 } else {
3785 availRight = mRestrictedScreenLeft + mRestrictedScreenWidth;
3786 availBottom = mRestrictedScreenTop + mRestrictedScreenHeight;
3787 }
Dianne Hackborn5b5cc4d2012-05-16 13:15:00 -07003788 if ((systemUiVisibility & View.SYSTEM_UI_FLAG_LAYOUT_STABLE) != 0) {
3789 if ((fl & FLAG_FULLSCREEN) != 0) {
Adrian Roos37d7a682014-11-06 18:15:16 +01003790 outContentInsets.set(mStableFullscreenLeft, mStableFullscreenTop,
Dianne Hackborn5b5cc4d2012-05-16 13:15:00 -07003791 availRight - mStableFullscreenRight,
3792 availBottom - mStableFullscreenBottom);
3793 } else {
Adrian Roos37d7a682014-11-06 18:15:16 +01003794 outContentInsets.set(mStableLeft, mStableTop,
Dianne Hackborn5b5cc4d2012-05-16 13:15:00 -07003795 availRight - mStableRight, availBottom - mStableBottom);
3796 }
Dianne Hackbornc652de82013-02-15 16:32:56 -08003797 } else if ((fl & FLAG_FULLSCREEN) != 0 || (fl & FLAG_LAYOUT_IN_OVERSCAN) != 0) {
Adrian Roos37d7a682014-11-06 18:15:16 +01003798 outContentInsets.setEmpty();
Dianne Hackborn5b5cc4d2012-05-16 13:15:00 -07003799 } else if ((systemUiVisibility & (View.SYSTEM_UI_FLAG_FULLSCREEN
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07003800 | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN)) == 0) {
Adrian Roos37d7a682014-11-06 18:15:16 +01003801 outContentInsets.set(mCurLeft, mCurTop,
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07003802 availRight - mCurRight, availBottom - mCurBottom);
3803 } else {
Adrian Roos37d7a682014-11-06 18:15:16 +01003804 outContentInsets.set(mCurLeft, mCurTop,
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07003805 availRight - mCurRight, availBottom - mCurBottom);
3806 }
Adrian Roos37d7a682014-11-06 18:15:16 +01003807
3808 outStableInsets.set(mStableLeft, mStableTop,
3809 availRight - mStableRight, availBottom - mStableBottom);
Jorim Jaggi0ffd49c2016-02-12 15:04:21 -08003810 return mForceShowSystemBars;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003811 }
Adrian Roos37d7a682014-11-06 18:15:16 +01003812 outContentInsets.setEmpty();
3813 outStableInsets.setEmpty();
Jorim Jaggi0ffd49c2016-02-12 15:04:21 -08003814 return mForceShowSystemBars;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003815 }
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07003816
Filip Gruszczynski2987f612015-06-30 15:03:30 -07003817 private boolean shouldUseOutsets(WindowManager.LayoutParams attrs, int fl) {
3818 return attrs.type == TYPE_WALLPAPER || (fl & (WindowManager.LayoutParams.FLAG_FULLSCREEN
3819 | WindowManager.LayoutParams.FLAG_LAYOUT_IN_OVERSCAN)) != 0;
3820 }
3821
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003822 /** {@inheritDoc} */
Craig Mautner69b08182012-09-05 13:07:13 -07003823 @Override
3824 public void beginLayoutLw(boolean isDefaultDisplay, int displayWidth, int displayHeight,
Sriram Viswanathan9ebbe6a2015-11-16 17:59:22 -08003825 int displayRotation, int uiMode) {
Filip Gruszczynski2987f612015-06-30 15:03:30 -07003826 mDisplayRotation = displayRotation;
Dianne Hackbornc652de82013-02-15 16:32:56 -08003827 final int overscanLeft, overscanTop, overscanRight, overscanBottom;
3828 if (isDefaultDisplay) {
3829 switch (displayRotation) {
3830 case Surface.ROTATION_90:
3831 overscanLeft = mOverscanTop;
3832 overscanTop = mOverscanRight;
3833 overscanRight = mOverscanBottom;
3834 overscanBottom = mOverscanLeft;
3835 break;
3836 case Surface.ROTATION_180:
3837 overscanLeft = mOverscanRight;
3838 overscanTop = mOverscanBottom;
3839 overscanRight = mOverscanLeft;
3840 overscanBottom = mOverscanTop;
3841 break;
3842 case Surface.ROTATION_270:
3843 overscanLeft = mOverscanBottom;
3844 overscanTop = mOverscanLeft;
3845 overscanRight = mOverscanTop;
3846 overscanBottom = mOverscanRight;
3847 break;
3848 default:
3849 overscanLeft = mOverscanLeft;
3850 overscanTop = mOverscanTop;
3851 overscanRight = mOverscanRight;
3852 overscanBottom = mOverscanBottom;
3853 break;
3854 }
3855 } else {
3856 overscanLeft = 0;
3857 overscanTop = 0;
3858 overscanRight = 0;
3859 overscanBottom = 0;
3860 }
Dianne Hackborn313440842013-02-19 19:22:59 -08003861 mOverscanScreenLeft = mRestrictedOverscanScreenLeft = 0;
3862 mOverscanScreenTop = mRestrictedOverscanScreenTop = 0;
3863 mOverscanScreenWidth = mRestrictedOverscanScreenWidth = displayWidth;
3864 mOverscanScreenHeight = mRestrictedOverscanScreenHeight = displayHeight;
Dianne Hackbornc652de82013-02-15 16:32:56 -08003865 mSystemLeft = 0;
3866 mSystemTop = 0;
3867 mSystemRight = displayWidth;
3868 mSystemBottom = displayHeight;
3869 mUnrestrictedScreenLeft = overscanLeft;
3870 mUnrestrictedScreenTop = overscanTop;
3871 mUnrestrictedScreenWidth = displayWidth - overscanLeft - overscanRight;
3872 mUnrestrictedScreenHeight = displayHeight - overscanTop - overscanBottom;
3873 mRestrictedScreenLeft = mUnrestrictedScreenLeft;
3874 mRestrictedScreenTop = mUnrestrictedScreenTop;
John Spurlockad3e6cb2013-04-30 08:47:43 -04003875 mRestrictedScreenWidth = mSystemGestures.screenWidth = mUnrestrictedScreenWidth;
3876 mRestrictedScreenHeight = mSystemGestures.screenHeight = mUnrestrictedScreenHeight;
Dianne Hackborne30e02f2014-05-27 18:24:45 -07003877 mDockLeft = mContentLeft = mVoiceContentLeft = mStableLeft = mStableFullscreenLeft
Dianne Hackbornc652de82013-02-15 16:32:56 -08003878 = mCurLeft = mUnrestrictedScreenLeft;
Dianne Hackborne30e02f2014-05-27 18:24:45 -07003879 mDockTop = mContentTop = mVoiceContentTop = mStableTop = mStableFullscreenTop
Dianne Hackbornc652de82013-02-15 16:32:56 -08003880 = mCurTop = mUnrestrictedScreenTop;
Dianne Hackborne30e02f2014-05-27 18:24:45 -07003881 mDockRight = mContentRight = mVoiceContentRight = mStableRight = mStableFullscreenRight
Dianne Hackbornc652de82013-02-15 16:32:56 -08003882 = mCurRight = displayWidth - overscanRight;
Dianne Hackborne30e02f2014-05-27 18:24:45 -07003883 mDockBottom = mContentBottom = mVoiceContentBottom = mStableBottom = mStableFullscreenBottom
Dianne Hackbornc652de82013-02-15 16:32:56 -08003884 = mCurBottom = displayHeight - overscanBottom;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003885 mDockLayer = 0x10000000;
Dianne Hackborn5c58de32012-04-28 19:52:37 -07003886 mStatusBarLayer = -1;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003887
Daniel Sandler8956dbb2011-04-22 07:55:02 -04003888 // start with the current dock rect, which will be (0,0,displayWidth,displayHeight)
3889 final Rect pf = mTmpParentFrame;
3890 final Rect df = mTmpDisplayFrame;
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003891 final Rect of = mTmpOverscanFrame;
Daniel Sandler8956dbb2011-04-22 07:55:02 -04003892 final Rect vf = mTmpVisibleFrame;
John Spurlock46646232013-09-30 22:32:42 -04003893 final Rect dcf = mTmpDecorFrame;
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003894 pf.left = df.left = of.left = vf.left = mDockLeft;
3895 pf.top = df.top = of.top = vf.top = mDockTop;
3896 pf.right = df.right = of.right = vf.right = mDockRight;
3897 pf.bottom = df.bottom = of.bottom = vf.bottom = mDockBottom;
John Spurlock46646232013-09-30 22:32:42 -04003898 dcf.setEmpty(); // Decor frame N/A for system bars.
Daniel Sandler8956dbb2011-04-22 07:55:02 -04003899
Craig Mautner69b08182012-09-05 13:07:13 -07003900 if (isDefaultDisplay) {
3901 // For purposes of putting out fake window up to steal focus, we will
3902 // drive nav being hidden only by whether it is requested.
John Spurlocke1f366f2013-08-05 12:22:40 -04003903 final int sysui = mLastSystemUiFlags;
3904 boolean navVisible = (sysui & View.SYSTEM_UI_FLAG_HIDE_NAVIGATION) == 0;
Adrian Roosea562512014-05-05 13:33:03 +02003905 boolean navTranslucent = (sysui
Jorim Jaggi4fa78922015-11-30 17:13:56 -08003906 & (View.NAVIGATION_BAR_TRANSLUCENT | View.NAVIGATION_BAR_TRANSPARENT)) != 0;
John Spurlockf1a36642013-10-12 17:50:42 -04003907 boolean immersive = (sysui & View.SYSTEM_UI_FLAG_IMMERSIVE) != 0;
3908 boolean immersiveSticky = (sysui & View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY) != 0;
3909 boolean navAllowedHidden = immersive || immersiveSticky;
3910 navTranslucent &= !immersiveSticky; // transient trumps translucent
Adrian Roos4fb3ee32014-08-22 19:29:09 +02003911 boolean isKeyguardShowing = isStatusBarKeyguard() && !mHideLockScreen;
3912 if (!isKeyguardShowing) {
3913 navTranslucent &= areTranslucentBarsAllowed();
3914 }
Dianne Hackborne26ab702011-10-16 13:21:33 -07003915
Craig Mautner69b08182012-09-05 13:07:13 -07003916 // When the navigation bar isn't visible, we put up a fake
3917 // input window to catch all touch events. This way we can
3918 // detect when the user presses anywhere to bring back the nav
3919 // bar and ensure the application doesn't see the event.
John Spurlockf1a36642013-10-12 17:50:42 -04003920 if (navVisible || navAllowedHidden) {
Selim Cinekf83e8242015-05-19 18:08:14 -07003921 if (mInputConsumer != null) {
3922 mInputConsumer.dismiss();
3923 mInputConsumer = null;
Craig Mautner69b08182012-09-05 13:07:13 -07003924 }
Selim Cinekf83e8242015-05-19 18:08:14 -07003925 } else if (mInputConsumer == null) {
3926 mInputConsumer = mWindowManagerFuncs.addInputConsumer(mHandler.getLooper(),
3927 mHideNavInputEventReceiverFactory);
Dianne Hackborne26ab702011-10-16 13:21:33 -07003928 }
Dianne Hackborne26ab702011-10-16 13:21:33 -07003929
Craig Mautner69b08182012-09-05 13:07:13 -07003930 // For purposes of positioning and showing the nav bar, if we have
3931 // decided that it can't be hidden (because of the screen aspect ratio),
3932 // then take that into account.
Alan Viverette5a0f4ec2013-10-07 15:10:29 -07003933 navVisible |= !canHideNavigationBar();
Dianne Hackbornf87d1962012-04-04 12:48:24 -07003934
Filip Gruszczynski83dd9552015-09-17 17:50:36 -07003935 boolean updateSysUiVisibility = layoutNavigationBar(displayWidth, displayHeight,
Sriram Viswanathan9ebbe6a2015-11-16 17:59:22 -08003936 displayRotation, uiMode, overscanRight, overscanBottom, dcf, navVisible, navTranslucent,
Filip Gruszczynski83dd9552015-09-17 17:50:36 -07003937 navAllowedHidden);
Craig Mautnereda67292013-04-28 13:50:14 -07003938 if (DEBUG_LAYOUT) Slog.i(TAG, String.format("mDock rect: (%d,%d - %d,%d)",
Craig Mautner69b08182012-09-05 13:07:13 -07003939 mDockLeft, mDockTop, mDockRight, mDockBottom));
Filip Gruszczynski83dd9552015-09-17 17:50:36 -07003940 updateSysUiVisibility |= layoutStatusBar(pf, df, of, vf, dcf, sysui, isKeyguardShowing);
John Spurlockad3e6cb2013-04-30 08:47:43 -04003941 if (updateSysUiVisibility) {
3942 updateSystemUiVisibilityLw();
3943 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003944 }
3945 }
3946
Filip Gruszczynski83dd9552015-09-17 17:50:36 -07003947 private boolean layoutStatusBar(Rect pf, Rect df, Rect of, Rect vf, Rect dcf, int sysui,
3948 boolean isKeyguardShowing) {
3949 // decide where the status bar goes ahead of time
3950 if (mStatusBar != null) {
3951 // apply any navigation bar insets
3952 pf.left = df.left = of.left = mUnrestrictedScreenLeft;
3953 pf.top = df.top = of.top = mUnrestrictedScreenTop;
3954 pf.right = df.right = of.right = mUnrestrictedScreenWidth + mUnrestrictedScreenLeft;
3955 pf.bottom = df.bottom = of.bottom = mUnrestrictedScreenHeight
3956 + mUnrestrictedScreenTop;
3957 vf.left = mStableLeft;
3958 vf.top = mStableTop;
3959 vf.right = mStableRight;
3960 vf.bottom = mStableBottom;
3961
3962 mStatusBarLayer = mStatusBar.getSurfaceLayer();
3963
3964 // Let the status bar determine its size.
3965 mStatusBar.computeFrameLw(pf /* parentFrame */, df /* displayFrame */,
3966 vf /* overlayFrame */, vf /* contentFrame */, vf /* visibleFrame */,
3967 dcf /* decorFrame */, vf /* stableFrame */, vf /* outsetFrame */);
3968
3969 // For layout, the status bar is always at the top with our fixed height.
3970 mStableTop = mUnrestrictedScreenTop + mStatusBarHeight;
3971
3972 boolean statusBarTransient = (sysui & View.STATUS_BAR_TRANSIENT) != 0;
3973 boolean statusBarTranslucent = (sysui
Jorim Jaggi4fa78922015-11-30 17:13:56 -08003974 & (View.STATUS_BAR_TRANSLUCENT | View.STATUS_BAR_TRANSPARENT)) != 0;
Filip Gruszczynski83dd9552015-09-17 17:50:36 -07003975 if (!isKeyguardShowing) {
3976 statusBarTranslucent &= areTranslucentBarsAllowed();
3977 }
3978
3979 // If the status bar is hidden, we don't want to cause
3980 // windows behind it to scroll.
3981 if (mStatusBar.isVisibleLw() && !statusBarTransient) {
3982 // Status bar may go away, so the screen area it occupies
3983 // is available to apps but just covering them when the
3984 // status bar is visible.
3985 mDockTop = mUnrestrictedScreenTop + mStatusBarHeight;
3986
3987 mContentTop = mVoiceContentTop = mCurTop = mDockTop;
3988 mContentBottom = mVoiceContentBottom = mCurBottom = mDockBottom;
3989 mContentLeft = mVoiceContentLeft = mCurLeft = mDockLeft;
3990 mContentRight = mVoiceContentRight = mCurRight = mDockRight;
3991
3992 if (DEBUG_LAYOUT) Slog.v(TAG, "Status bar: " +
3993 String.format(
3994 "dock=[%d,%d][%d,%d] content=[%d,%d][%d,%d] cur=[%d,%d][%d,%d]",
3995 mDockLeft, mDockTop, mDockRight, mDockBottom,
3996 mContentLeft, mContentTop, mContentRight, mContentBottom,
3997 mCurLeft, mCurTop, mCurRight, mCurBottom));
3998 }
3999 if (mStatusBar.isVisibleLw() && !mStatusBar.isAnimatingLw()
4000 && !statusBarTransient && !statusBarTranslucent
4001 && !mStatusBarController.wasRecentlyTranslucent()) {
4002 // If the opaque status bar is currently requested to be visible,
4003 // and not in the process of animating on or off, then
4004 // we can tell the app that it is covered by it.
4005 mSystemTop = mUnrestrictedScreenTop + mStatusBarHeight;
4006 }
4007 if (mStatusBarController.checkHiddenLw()) {
4008 return true;
4009 }
4010 }
4011 return false;
4012 }
4013
4014 private boolean layoutNavigationBar(int displayWidth, int displayHeight, int displayRotation,
Sriram Viswanathan9ebbe6a2015-11-16 17:59:22 -08004015 int uiMode, int overscanRight, int overscanBottom, Rect dcf, boolean navVisible,
Filip Gruszczynski83dd9552015-09-17 17:50:36 -07004016 boolean navTranslucent, boolean navAllowedHidden) {
4017 if (mNavigationBar != null) {
4018 boolean transientNavBarShowing = mNavigationBarController.isTransientShowing();
4019 // Force the navigation bar to its appropriate place and
4020 // size. We need to do this directly, instead of relying on
4021 // it to bubble up from the nav bar, because this needs to
4022 // change atomically with screen rotations.
Jorim Jaggi737af722015-12-31 10:42:27 +01004023 mNavigationBarOnBottom = isNavigationBarOnBottom(displayWidth, displayHeight);
Filip Gruszczynski83dd9552015-09-17 17:50:36 -07004024 if (mNavigationBarOnBottom) {
4025 // It's a system nav bar or a portrait screen; nav bar goes on bottom.
4026 int top = displayHeight - overscanBottom
Sriram Viswanathan9ebbe6a2015-11-16 17:59:22 -08004027 - getNavigationBarHeight(displayRotation, uiMode);
Filip Gruszczynski83dd9552015-09-17 17:50:36 -07004028 mTmpNavigationFrame.set(0, top, displayWidth, displayHeight - overscanBottom);
4029 mStableBottom = mStableFullscreenBottom = mTmpNavigationFrame.top;
4030 if (transientNavBarShowing) {
4031 mNavigationBarController.setBarShowingLw(true);
4032 } else if (navVisible) {
4033 mNavigationBarController.setBarShowingLw(true);
4034 mDockBottom = mTmpNavigationFrame.top;
4035 mRestrictedScreenHeight = mDockBottom - mRestrictedScreenTop;
4036 mRestrictedOverscanScreenHeight = mDockBottom - mRestrictedOverscanScreenTop;
4037 } else {
4038 // We currently want to hide the navigation UI.
4039 mNavigationBarController.setBarShowingLw(false);
4040 }
4041 if (navVisible && !navTranslucent && !navAllowedHidden
4042 && !mNavigationBar.isAnimatingLw()
4043 && !mNavigationBarController.wasRecentlyTranslucent()) {
4044 // If the opaque nav bar is currently requested to be visible,
4045 // and not in the process of animating on or off, then
4046 // we can tell the app that it is covered by it.
4047 mSystemBottom = mTmpNavigationFrame.top;
4048 }
4049 } else {
4050 // Landscape screen; nav bar goes to the right.
4051 int left = displayWidth - overscanRight
Sriram Viswanathan9ebbe6a2015-11-16 17:59:22 -08004052 - getNavigationBarWidth(displayRotation, uiMode);
Filip Gruszczynski83dd9552015-09-17 17:50:36 -07004053 mTmpNavigationFrame.set(left, 0, displayWidth - overscanRight, displayHeight);
4054 mStableRight = mStableFullscreenRight = mTmpNavigationFrame.left;
4055 if (transientNavBarShowing) {
4056 mNavigationBarController.setBarShowingLw(true);
4057 } else if (navVisible) {
4058 mNavigationBarController.setBarShowingLw(true);
4059 mDockRight = mTmpNavigationFrame.left;
4060 mRestrictedScreenWidth = mDockRight - mRestrictedScreenLeft;
4061 mRestrictedOverscanScreenWidth = mDockRight - mRestrictedOverscanScreenLeft;
4062 } else {
4063 // We currently want to hide the navigation UI.
4064 mNavigationBarController.setBarShowingLw(false);
4065 }
4066 if (navVisible && !navTranslucent && !navAllowedHidden
4067 && !mNavigationBar.isAnimatingLw()
4068 && !mNavigationBarController.wasRecentlyTranslucent()) {
4069 // If the nav bar is currently requested to be visible,
4070 // and not in the process of animating on or off, then
4071 // we can tell the app that it is covered by it.
4072 mSystemRight = mTmpNavigationFrame.left;
4073 }
4074 }
4075 // Make sure the content and current rectangles are updated to
4076 // account for the restrictions from the navigation bar.
4077 mContentTop = mVoiceContentTop = mCurTop = mDockTop;
4078 mContentBottom = mVoiceContentBottom = mCurBottom = mDockBottom;
4079 mContentLeft = mVoiceContentLeft = mCurLeft = mDockLeft;
4080 mContentRight = mVoiceContentRight = mCurRight = mDockRight;
4081 mStatusBarLayer = mNavigationBar.getSurfaceLayer();
4082 // And compute the final frame.
4083 mNavigationBar.computeFrameLw(mTmpNavigationFrame, mTmpNavigationFrame,
4084 mTmpNavigationFrame, mTmpNavigationFrame, mTmpNavigationFrame, dcf,
4085 mTmpNavigationFrame, mTmpNavigationFrame);
4086 if (DEBUG_LAYOUT) Slog.i(TAG, "mNavigationBar frame: " + mTmpNavigationFrame);
4087 if (mNavigationBarController.checkHiddenLw()) {
4088 return true;
4089 }
4090 }
4091 return false;
4092 }
4093
Jorim Jaggi737af722015-12-31 10:42:27 +01004094 private boolean isNavigationBarOnBottom(int displayWidth, int displayHeight) {
4095 return !mNavigationBarCanMove || displayWidth < displayHeight;
4096 }
4097
Dianne Hackborn85afd1b2012-05-13 13:31:06 -07004098 /** {@inheritDoc} */
Craig Mautner967212c2013-04-13 21:10:58 -07004099 @Override
John Spurlock46646232013-09-30 22:32:42 -04004100 public int getSystemDecorLayerLw() {
Bryce Lee2ed3e5f2015-04-01 22:09:19 +00004101 if (mStatusBar != null && mStatusBar.isVisibleLw()) {
4102 return mStatusBar.getSurfaceLayer();
4103 }
4104
4105 if (mNavigationBar != null && mNavigationBar.isVisibleLw()) {
4106 return mNavigationBar.getSurfaceLayer();
4107 }
4108
Dianne Hackborn85afd1b2012-05-13 13:31:06 -07004109 return 0;
4110 }
4111
Craig Mautner967212c2013-04-13 21:10:58 -07004112 @Override
4113 public void getContentRectLw(Rect r) {
4114 r.set(mContentLeft, mContentTop, mContentRight, mContentBottom);
4115 }
4116
Dianne Hackbornc4aad012013-02-22 15:05:25 -08004117 void setAttachedWindowFrames(WindowState win, int fl, int adjust, WindowState attached,
4118 boolean insetDecors, Rect pf, Rect df, Rect of, Rect cf, Rect vf) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004119 if (win.getSurfaceLayer() > mDockLayer && attached.getSurfaceLayer() < mDockLayer) {
4120 // Here's a special case: if this attached window is a panel that is
4121 // above the dock window, and the window it is attached to is below
4122 // the dock window, then the frames we computed for the window it is
4123 // attached to can not be used because the dock is effectively part
4124 // of the underlying window and the attached window is floating on top
4125 // of the whole thing. So, we ignore the attached window and explicitly
4126 // compute the frames that would be appropriate without the dock.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08004127 df.left = of.left = cf.left = vf.left = mDockLeft;
4128 df.top = of.top = cf.top = vf.top = mDockTop;
4129 df.right = of.right = cf.right = vf.right = mDockRight;
4130 df.bottom = of.bottom = cf.bottom = vf.bottom = mDockBottom;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004131 } else {
4132 // The effective display frame of the attached window depends on
4133 // whether it is taking care of insetting its content. If not,
4134 // we need to use the parent's content frame so that the entire
4135 // window is positioned within that content. Otherwise we can use
Wale Ogunwale393b1c12014-10-18 16:22:01 -07004136 // the overscan frame and let the attached window take care of
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004137 // positioning its content appropriately.
Dianne Hackborndea3ef72010-10-28 14:24:22 -07004138 if (adjust != SOFT_INPUT_ADJUST_RESIZE) {
Wale Ogunwale393b1c12014-10-18 16:22:01 -07004139 // Set the content frame of the attached window to the parent's decor frame
4140 // (same as content frame when IME isn't present) if specifically requested by
4141 // setting {@link WindowManager.LayoutParams#FLAG_LAYOUT_ATTACHED_IN_DECOR} flag.
4142 // Otherwise, use the overscan frame.
4143 cf.set((fl & FLAG_LAYOUT_ATTACHED_IN_DECOR) != 0
4144 ? attached.getContentFrameLw() : attached.getOverscanFrameLw());
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004145 } else {
4146 // If the window is resizing, then we want to base the content
4147 // frame on our attached content frame to resize... however,
4148 // things can be tricky if the attached window is NOT in resize
4149 // mode, in which case its content frame will be larger.
4150 // Ungh. So to deal with that, make sure the content frame
4151 // we end up using is not covering the IM dock.
4152 cf.set(attached.getContentFrameLw());
Dianne Hackborne30e02f2014-05-27 18:24:45 -07004153 if (attached.isVoiceInteraction()) {
4154 if (cf.left < mVoiceContentLeft) cf.left = mVoiceContentLeft;
4155 if (cf.top < mVoiceContentTop) cf.top = mVoiceContentTop;
4156 if (cf.right > mVoiceContentRight) cf.right = mVoiceContentRight;
4157 if (cf.bottom > mVoiceContentBottom) cf.bottom = mVoiceContentBottom;
4158 } else if (attached.getSurfaceLayer() < mDockLayer) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004159 if (cf.left < mContentLeft) cf.left = mContentLeft;
4160 if (cf.top < mContentTop) cf.top = mContentTop;
4161 if (cf.right > mContentRight) cf.right = mContentRight;
4162 if (cf.bottom > mContentBottom) cf.bottom = mContentBottom;
4163 }
4164 }
4165 df.set(insetDecors ? attached.getDisplayFrameLw() : cf);
Dianne Hackbornc4aad012013-02-22 15:05:25 -08004166 of.set(insetDecors ? attached.getOverscanFrameLw() : cf);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004167 vf.set(attached.getVisibleFrameLw());
4168 }
4169 // The LAYOUT_IN_SCREEN flag is used to determine whether the attached
4170 // window should be positioned relative to its parent or the entire
4171 // screen.
4172 pf.set((fl & FLAG_LAYOUT_IN_SCREEN) == 0
4173 ? attached.getFrameLw() : df);
4174 }
Dianne Hackborn5b5cc4d2012-05-16 13:15:00 -07004175
4176 private void applyStableConstraints(int sysui, int fl, Rect r) {
4177 if ((sysui & View.SYSTEM_UI_FLAG_LAYOUT_STABLE) != 0) {
4178 // If app is requesting a stable layout, don't let the
4179 // content insets go below the stable values.
4180 if ((fl & FLAG_FULLSCREEN) != 0) {
4181 if (r.left < mStableFullscreenLeft) r.left = mStableFullscreenLeft;
4182 if (r.top < mStableFullscreenTop) r.top = mStableFullscreenTop;
4183 if (r.right > mStableFullscreenRight) r.right = mStableFullscreenRight;
4184 if (r.bottom > mStableFullscreenBottom) r.bottom = mStableFullscreenBottom;
4185 } else {
4186 if (r.left < mStableLeft) r.left = mStableLeft;
4187 if (r.top < mStableTop) r.top = mStableTop;
4188 if (r.right > mStableRight) r.right = mStableRight;
4189 if (r.bottom > mStableBottom) r.bottom = mStableBottom;
4190 }
4191 }
4192 }
4193
Jorim Jaggiaa806142015-05-20 18:04:16 -07004194 private boolean canReceiveInput(WindowState win) {
4195 boolean notFocusable =
4196 (win.getAttrs().flags & WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE) != 0;
4197 boolean altFocusableIm =
4198 (win.getAttrs().flags & WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM) != 0;
4199 boolean notFocusableForIm = notFocusable ^ altFocusableIm;
4200 return !notFocusableForIm;
4201 }
4202
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004203 /** {@inheritDoc} */
Craig Mautner69b08182012-09-05 13:07:13 -07004204 @Override
Craig Mautnerc9457fa2014-06-06 14:27:48 -07004205 public void layoutWindowLw(WindowState win, WindowState attached) {
Jorim Jaggiaa806142015-05-20 18:04:16 -07004206 // We've already done the navigation bar and status bar. If the status bar can receive
4207 // input, we need to layout it again to accomodate for the IME window.
4208 if ((win == mStatusBar && !canReceiveInput(win)) || win == mNavigationBar) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004209 return;
4210 }
Jorim Jaggiaa806142015-05-20 18:04:16 -07004211 final WindowManager.LayoutParams attrs = win.getAttrs();
Craig Mautner69b08182012-09-05 13:07:13 -07004212 final boolean isDefaultDisplay = win.isDefaultDisplay();
4213 final boolean needsToOffsetInputMethodTarget = isDefaultDisplay &&
satok1bc0a492012-04-25 22:47:12 +09004214 (win == mLastInputMethodTargetWindow && mLastInputMethodWindow != null);
4215 if (needsToOffsetInputMethodTarget) {
Craig Mautnereda67292013-04-28 13:50:14 -07004216 if (DEBUG_LAYOUT) Slog.i(TAG, "Offset ime target window by the last ime window state");
satok1bc0a492012-04-25 22:47:12 +09004217 offsetInputMethodWindowLw(mLastInputMethodWindow);
4218 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004219
John Spurlockc6d1c602014-01-17 15:22:06 -05004220 final int fl = PolicyControl.getWindowFlags(win, attrs);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004221 final int sim = attrs.softInputMode;
John Spurlock1db8b682014-02-18 11:18:59 -05004222 final int sysUiFl = PolicyControl.getSystemUiVisibility(win, null);
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07004223
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004224 final Rect pf = mTmpParentFrame;
4225 final Rect df = mTmpDisplayFrame;
Dianne Hackbornc4aad012013-02-22 15:05:25 -08004226 final Rect of = mTmpOverscanFrame;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004227 final Rect cf = mTmpContentFrame;
4228 final Rect vf = mTmpVisibleFrame;
John Spurlock46646232013-09-30 22:32:42 -04004229 final Rect dcf = mTmpDecorFrame;
Adrian Roosfa104232014-06-20 16:10:14 -07004230 final Rect sf = mTmpStableFrame;
Filip Gruszczynski2217f612015-05-26 11:32:08 -07004231 Rect osf = null;
John Spurlock46646232013-09-30 22:32:42 -04004232 dcf.setEmpty();
Craig Mautner69b08182012-09-05 13:07:13 -07004233
4234 final boolean hasNavBar = (isDefaultDisplay && mHasNavigationBar
Daniel Sandler36412a72011-08-04 09:35:13 -04004235 && mNavigationBar != null && mNavigationBar.isVisibleLw());
Daniel Sandler8956dbb2011-04-22 07:55:02 -04004236
Craig Mautnerf683b562012-10-02 11:10:57 -07004237 final int adjust = sim & SOFT_INPUT_MASK_ADJUST;
4238
Adrian Roosfa104232014-06-20 16:10:14 -07004239 if (isDefaultDisplay) {
4240 sf.set(mStableLeft, mStableTop, mStableRight, mStableBottom);
4241 } else {
4242 sf.set(mOverscanLeft, mOverscanTop, mOverscanRight, mOverscanBottom);
4243 }
4244
Craig Mautner69b08182012-09-05 13:07:13 -07004245 if (!isDefaultDisplay) {
4246 if (attached != null) {
4247 // If this window is attached to another, our display
4248 // frame is the same as the one we are attached to.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08004249 setAttachedWindowFrames(win, fl, adjust, attached, true, pf, df, of, cf, vf);
Craig Mautner69b08182012-09-05 13:07:13 -07004250 } else {
4251 // Give the window full screen.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08004252 pf.left = df.left = of.left = cf.left = mOverscanScreenLeft;
4253 pf.top = df.top = of.top = cf.top = mOverscanScreenTop;
4254 pf.right = df.right = of.right = cf.right
Dianne Hackbornc652de82013-02-15 16:32:56 -08004255 = mOverscanScreenLeft + mOverscanScreenWidth;
Dianne Hackbornc4aad012013-02-22 15:05:25 -08004256 pf.bottom = df.bottom = of.bottom = cf.bottom
Dianne Hackbornc652de82013-02-15 16:32:56 -08004257 = mOverscanScreenTop + mOverscanScreenHeight;
Craig Mautner69b08182012-09-05 13:07:13 -07004258 }
Jorim Jaggi225d3b52015-04-01 11:18:57 -07004259 } else if (attrs.type == TYPE_INPUT_METHOD) {
Dianne Hackbornc4aad012013-02-22 15:05:25 -08004260 pf.left = df.left = of.left = cf.left = vf.left = mDockLeft;
4261 pf.top = df.top = of.top = cf.top = vf.top = mDockTop;
4262 pf.right = df.right = of.right = cf.right = vf.right = mDockRight;
John Spurlockc68d5772013-10-08 11:47:58 -04004263 // IM dock windows layout below the nav bar...
John Spurlock57beb3b2013-10-10 10:27:44 -04004264 pf.bottom = df.bottom = of.bottom = mUnrestrictedScreenTop + mUnrestrictedScreenHeight;
John Spurlockc68d5772013-10-08 11:47:58 -04004265 // ...with content insets above the nav bar
4266 cf.bottom = vf.bottom = mStableBottom;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004267 // IM dock windows always go to the bottom of the screen.
4268 attrs.gravity = Gravity.BOTTOM;
4269 mDockLayer = win.getSurfaceLayer();
Jorim Jaggi225d3b52015-04-01 11:18:57 -07004270 } else if (attrs.type == TYPE_VOICE_INTERACTION) {
Stefan Kuhne2f280d062015-06-18 07:20:33 -10004271 pf.left = df.left = of.left = mUnrestrictedScreenLeft;
Jorim Jaggi225d3b52015-04-01 11:18:57 -07004272 pf.top = df.top = of.top = mUnrestrictedScreenTop;
Stefan Kuhne2f280d062015-06-18 07:20:33 -10004273 pf.right = df.right = of.right = mUnrestrictedScreenLeft + mUnrestrictedScreenWidth;
4274 pf.bottom = df.bottom = of.bottom = mUnrestrictedScreenTop + mUnrestrictedScreenHeight;
Jorim Jaggi225d3b52015-04-01 11:18:57 -07004275 cf.bottom = vf.bottom = mStableBottom;
Stefan Kuhne2f280d062015-06-18 07:20:33 -10004276 // Note: In Phone landscape mode, the button bar should also be excluded.
4277 cf.right = vf.right = mStableRight;
4278 cf.left = vf.left = mStableLeft;
Jorim Jaggi225d3b52015-04-01 11:18:57 -07004279 cf.top = vf.top = mStableTop;
Jorim Jaggiaa806142015-05-20 18:04:16 -07004280 } else if (win == mStatusBar) {
Jorim Jaggie0700182014-08-21 01:12:37 +02004281 pf.left = df.left = of.left = mUnrestrictedScreenLeft;
4282 pf.top = df.top = of.top = mUnrestrictedScreenTop;
4283 pf.right = df.right = of.right = mUnrestrictedScreenWidth + mUnrestrictedScreenLeft;
4284 pf.bottom = df.bottom = of.bottom = mUnrestrictedScreenHeight + mUnrestrictedScreenTop;
4285 cf.left = vf.left = mStableLeft;
4286 cf.top = vf.top = mStableTop;
4287 cf.right = vf.right = mStableRight;
4288 vf.bottom = mStableBottom;
Adrian Roosdc5b4532016-01-06 20:49:41 +01004289
4290 if (adjust == SOFT_INPUT_ADJUST_RESIZE) {
4291 cf.bottom = mContentBottom;
4292 } else {
4293 cf.bottom = mDockBottom;
4294 vf.bottom = mContentBottom;
4295 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004296 } else {
John Spurlock46646232013-09-30 22:32:42 -04004297
4298 // Default policy decor for the default display
4299 dcf.left = mSystemLeft;
4300 dcf.top = mSystemTop;
4301 dcf.right = mSystemRight;
4302 dcf.bottom = mSystemBottom;
John Spurlockbd957402013-10-03 11:38:39 -04004303 final boolean inheritTranslucentDecor = (attrs.privateFlags
4304 & WindowManager.LayoutParams.PRIVATE_FLAG_INHERIT_TRANSLUCENT_DECOR) != 0;
John Spurlock65567d42013-10-08 10:08:32 -04004305 final boolean isAppWindow =
4306 attrs.type >= WindowManager.LayoutParams.FIRST_APPLICATION_WINDOW &&
4307 attrs.type <= WindowManager.LayoutParams.LAST_APPLICATION_WINDOW;
4308 final boolean topAtRest =
4309 win == mTopFullscreenOpaqueWindowState && !win.isAnimatingLw();
4310 if (isAppWindow && !inheritTranslucentDecor && !topAtRest) {
John Spurlockbd957402013-10-03 11:38:39 -04004311 if ((sysUiFl & View.SYSTEM_UI_FLAG_FULLSCREEN) == 0
4312 && (fl & WindowManager.LayoutParams.FLAG_FULLSCREEN) == 0
Adrian Roosea562512014-05-05 13:33:03 +02004313 && (fl & WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS) == 0
4314 && (fl & WindowManager.LayoutParams.
Jorim Jaggi4fa78922015-11-30 17:13:56 -08004315 FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS) == 0
4316 && !mForceWindowDrawsStatusBarBackground) {
John Spurlock46646232013-09-30 22:32:42 -04004317 // Ensure policy decor includes status bar
4318 dcf.top = mStableTop;
4319 }
John Spurlockbd957402013-10-03 11:38:39 -04004320 if ((fl & WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION) == 0
Adrian Roosea562512014-05-05 13:33:03 +02004321 && (sysUiFl & View.SYSTEM_UI_FLAG_HIDE_NAVIGATION) == 0
4322 && (fl & WindowManager.LayoutParams.
4323 FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS) == 0) {
John Spurlock46646232013-09-30 22:32:42 -04004324 // Ensure policy decor includes navigation bar
4325 dcf.bottom = mStableBottom;
4326 dcf.right = mStableRight;
4327 }
4328 }
4329
Dianne Hackbornc4aad012013-02-22 15:05:25 -08004330 if ((fl & (FLAG_LAYOUT_IN_SCREEN | FLAG_LAYOUT_INSET_DECOR))
4331 == (FLAG_LAYOUT_IN_SCREEN | FLAG_LAYOUT_INSET_DECOR)) {
RoboErik8a2cfc32014-05-16 11:19:38 -07004332 if (DEBUG_LAYOUT) Slog.v(TAG, "layoutWindowLw(" + attrs.getTitle()
Dianne Hackbornc4aad012013-02-22 15:05:25 -08004333 + "): IN_SCREEN, INSET_DECOR");
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004334 // This is the case for a normal activity window: we want it
4335 // to cover all of the screen space, and it can take care of
4336 // moving its contents to account for screen decorations that
4337 // intrude into that space.
4338 if (attached != null) {
4339 // If this window is attached to another, our display
4340 // frame is the same as the one we are attached to.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08004341 setAttachedWindowFrames(win, fl, adjust, attached, true, pf, df, of, cf, vf);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004342 } else {
Daniel Sandler8956dbb2011-04-22 07:55:02 -04004343 if (attrs.type == TYPE_STATUS_BAR_PANEL
4344 || attrs.type == TYPE_STATUS_BAR_SUB_PANEL) {
Joe Onorato29fc2c92010-11-24 10:26:50 -08004345 // Status bar panels are the only windows who can go on top of
4346 // the status bar. They are protected by the STATUS_BAR_SERVICE
4347 // permission, so they have the same privileges as the status
4348 // bar itself.
Daniel Sandler8956dbb2011-04-22 07:55:02 -04004349 //
Daniel Sandler8e8b4152011-07-21 01:16:43 -04004350 // However, they should still dodge the navigation bar if it exists.
Daniel Sandler8956dbb2011-04-22 07:55:02 -04004351
Dianne Hackbornc4aad012013-02-22 15:05:25 -08004352 pf.left = df.left = of.left = hasNavBar
4353 ? mDockLeft : mUnrestrictedScreenLeft;
4354 pf.top = df.top = of.top = mUnrestrictedScreenTop;
4355 pf.right = df.right = of.right = hasNavBar
4356 ? mRestrictedScreenLeft+mRestrictedScreenWidth
4357 : mUnrestrictedScreenLeft + mUnrestrictedScreenWidth;
4358 pf.bottom = df.bottom = of.bottom = hasNavBar
4359 ? mRestrictedScreenTop+mRestrictedScreenHeight
4360 : mUnrestrictedScreenTop + mUnrestrictedScreenHeight;
Daniel Sandler8956dbb2011-04-22 07:55:02 -04004361
Craig Mautnereda67292013-04-28 13:50:14 -07004362 if (DEBUG_LAYOUT) Slog.v(TAG, String.format(
Daniel Sandler8e8b4152011-07-21 01:16:43 -04004363 "Laying out status bar window: (%d,%d - %d,%d)",
4364 pf.left, pf.top, pf.right, pf.bottom));
John Spurlock46646232013-09-30 22:32:42 -04004365 } else if ((fl & FLAG_LAYOUT_IN_OVERSCAN) != 0
Dianne Hackbornc652de82013-02-15 16:32:56 -08004366 && attrs.type >= WindowManager.LayoutParams.FIRST_APPLICATION_WINDOW
4367 && attrs.type <= WindowManager.LayoutParams.LAST_SUB_WINDOW) {
4368 // Asking to layout into the overscan region, so give it that pure
4369 // unrestricted area.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08004370 pf.left = df.left = of.left = mOverscanScreenLeft;
4371 pf.top = df.top = of.top = mOverscanScreenTop;
4372 pf.right = df.right = of.right = mOverscanScreenLeft + mOverscanScreenWidth;
4373 pf.bottom = df.bottom = of.bottom = mOverscanScreenTop
4374 + mOverscanScreenHeight;
Alan Viverette5a0f4ec2013-10-07 15:10:29 -07004375 } else if (canHideNavigationBar()
Dianne Hackbornf87d1962012-04-04 12:48:24 -07004376 && (sysUiFl & View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION) != 0
Jorim Jaggi380ecb82014-03-14 17:25:20 +01004377 && attrs.type >= WindowManager.LayoutParams.FIRST_APPLICATION_WINDOW
4378 && attrs.type <= WindowManager.LayoutParams.LAST_SUB_WINDOW) {
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07004379 // Asking for layout as if the nav bar is hidden, lets the
Dianne Hackbornc652de82013-02-15 16:32:56 -08004380 // application extend into the unrestricted overscan screen area. We
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07004381 // only do this for application windows to ensure no window that
4382 // can be above the nav bar can do this.
Dianne Hackborn313440842013-02-19 19:22:59 -08004383 pf.left = df.left = mOverscanScreenLeft;
4384 pf.top = df.top = mOverscanScreenTop;
4385 pf.right = df.right = mOverscanScreenLeft + mOverscanScreenWidth;
4386 pf.bottom = df.bottom = mOverscanScreenTop + mOverscanScreenHeight;
Dianne Hackbornc4aad012013-02-22 15:05:25 -08004387 // We need to tell the app about where the frame inside the overscan
4388 // is, so it can inset its content by that amount -- it didn't ask
4389 // to actually extend itself into the overscan region.
4390 of.left = mUnrestrictedScreenLeft;
4391 of.top = mUnrestrictedScreenTop;
4392 of.right = mUnrestrictedScreenLeft + mUnrestrictedScreenWidth;
4393 of.bottom = mUnrestrictedScreenTop + mUnrestrictedScreenHeight;
Joe Onorato29fc2c92010-11-24 10:26:50 -08004394 } else {
Dianne Hackborn313440842013-02-19 19:22:59 -08004395 pf.left = df.left = mRestrictedOverscanScreenLeft;
4396 pf.top = df.top = mRestrictedOverscanScreenTop;
4397 pf.right = df.right = mRestrictedOverscanScreenLeft
4398 + mRestrictedOverscanScreenWidth;
4399 pf.bottom = df.bottom = mRestrictedOverscanScreenTop
4400 + mRestrictedOverscanScreenHeight;
Dianne Hackbornc4aad012013-02-22 15:05:25 -08004401 // We need to tell the app about where the frame inside the overscan
4402 // is, so it can inset its content by that amount -- it didn't ask
4403 // to actually extend itself into the overscan region.
4404 of.left = mUnrestrictedScreenLeft;
4405 of.top = mUnrestrictedScreenTop;
4406 of.right = mUnrestrictedScreenLeft + mUnrestrictedScreenWidth;
4407 of.bottom = mUnrestrictedScreenTop + mUnrestrictedScreenHeight;
Joe Onorato29fc2c92010-11-24 10:26:50 -08004408 }
Craig Mautner69b08182012-09-05 13:07:13 -07004409
John Spurlock46646232013-09-30 22:32:42 -04004410 if ((fl & FLAG_FULLSCREEN) == 0) {
Dianne Hackborne30e02f2014-05-27 18:24:45 -07004411 if (win.isVoiceInteraction()) {
4412 cf.left = mVoiceContentLeft;
4413 cf.top = mVoiceContentTop;
4414 cf.right = mVoiceContentRight;
4415 cf.bottom = mVoiceContentBottom;
Dianne Hackbornc4aad012013-02-22 15:05:25 -08004416 } else {
Dianne Hackborne30e02f2014-05-27 18:24:45 -07004417 if (adjust != SOFT_INPUT_ADJUST_RESIZE) {
4418 cf.left = mDockLeft;
4419 cf.top = mDockTop;
4420 cf.right = mDockRight;
4421 cf.bottom = mDockBottom;
4422 } else {
4423 cf.left = mContentLeft;
4424 cf.top = mContentTop;
4425 cf.right = mContentRight;
4426 cf.bottom = mContentBottom;
4427 }
Dianne Hackbornc4aad012013-02-22 15:05:25 -08004428 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004429 } else {
Dianne Hackbornc4aad012013-02-22 15:05:25 -08004430 // Full screen windows are always given a layout that is as if the
4431 // status bar and other transient decors are gone. This is to avoid
4432 // bad states when moving from a window that is not hding the
4433 // status bar to one that is.
4434 cf.left = mRestrictedScreenLeft;
4435 cf.top = mRestrictedScreenTop;
4436 cf.right = mRestrictedScreenLeft + mRestrictedScreenWidth;
4437 cf.bottom = mRestrictedScreenTop + mRestrictedScreenHeight;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004438 }
Dianne Hackborn5b5cc4d2012-05-16 13:15:00 -07004439 applyStableConstraints(sysUiFl, fl, cf);
Dianne Hackborndea3ef72010-10-28 14:24:22 -07004440 if (adjust != SOFT_INPUT_ADJUST_NOTHING) {
4441 vf.left = mCurLeft;
4442 vf.top = mCurTop;
4443 vf.right = mCurRight;
4444 vf.bottom = mCurBottom;
4445 } else {
4446 vf.set(cf);
4447 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004448 }
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07004449 } else if ((fl & FLAG_LAYOUT_IN_SCREEN) != 0 || (sysUiFl
4450 & (View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
4451 | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION)) != 0) {
Craig Mautnereda67292013-04-28 13:50:14 -07004452 if (DEBUG_LAYOUT) Slog.v(TAG, "layoutWindowLw(" + attrs.getTitle() +
4453 "): IN_SCREEN");
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004454 // A window that has requested to fill the entire screen just
4455 // gets everything, period.
Daniel Sandler8956dbb2011-04-22 07:55:02 -04004456 if (attrs.type == TYPE_STATUS_BAR_PANEL
John Spurlock67a0f852015-06-15 15:35:47 -04004457 || attrs.type == TYPE_STATUS_BAR_SUB_PANEL
4458 || attrs.type == TYPE_VOLUME_OVERLAY) {
Dianne Hackbornc4aad012013-02-22 15:05:25 -08004459 pf.left = df.left = of.left = cf.left = hasNavBar
4460 ? mDockLeft : mUnrestrictedScreenLeft;
4461 pf.top = df.top = of.top = cf.top = mUnrestrictedScreenTop;
4462 pf.right = df.right = of.right = cf.right = hasNavBar
Daniel Sandler8e8b4152011-07-21 01:16:43 -04004463 ? mRestrictedScreenLeft+mRestrictedScreenWidth
Dianne Hackbornc652de82013-02-15 16:32:56 -08004464 : mUnrestrictedScreenLeft + mUnrestrictedScreenWidth;
Dianne Hackbornc4aad012013-02-22 15:05:25 -08004465 pf.bottom = df.bottom = of.bottom = cf.bottom = hasNavBar
Daniel Sandler8e8b4152011-07-21 01:16:43 -04004466 ? mRestrictedScreenTop+mRestrictedScreenHeight
Dianne Hackbornc652de82013-02-15 16:32:56 -08004467 : mUnrestrictedScreenTop + mUnrestrictedScreenHeight;
Craig Mautnereda67292013-04-28 13:50:14 -07004468 if (DEBUG_LAYOUT) Slog.v(TAG, String.format(
Daniel Sandler36412a72011-08-04 09:35:13 -04004469 "Laying out IN_SCREEN status bar window: (%d,%d - %d,%d)",
4470 pf.left, pf.top, pf.right, pf.bottom));
Jim Millere898ac52012-04-06 17:10:57 -07004471 } else if (attrs.type == TYPE_NAVIGATION_BAR
4472 || attrs.type == TYPE_NAVIGATION_BAR_PANEL) {
Daniel Sandler8e8b4152011-07-21 01:16:43 -04004473 // The navigation bar has Real Ultimate Power.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08004474 pf.left = df.left = of.left = mUnrestrictedScreenLeft;
4475 pf.top = df.top = of.top = mUnrestrictedScreenTop;
4476 pf.right = df.right = of.right = mUnrestrictedScreenLeft
4477 + mUnrestrictedScreenWidth;
4478 pf.bottom = df.bottom = of.bottom = mUnrestrictedScreenTop
4479 + mUnrestrictedScreenHeight;
Craig Mautnereda67292013-04-28 13:50:14 -07004480 if (DEBUG_LAYOUT) Slog.v(TAG, String.format(
Daniel Sandler8e8b4152011-07-21 01:16:43 -04004481 "Laying out navigation bar window: (%d,%d - %d,%d)",
4482 pf.left, pf.top, pf.right, pf.bottom));
Dianne Hackborn01011c32012-02-21 13:54:21 -08004483 } else if ((attrs.type == TYPE_SECURE_SYSTEM_OVERLAY
Muyuan Li6ca619f2016-03-08 13:30:42 -08004484 || attrs.type == TYPE_BOOT_PROGRESS
4485 || attrs.type == TYPE_SCREENSHOT)
Jeff Brownbfcb60a2011-09-08 18:51:14 -07004486 && ((fl & FLAG_FULLSCREEN) != 0)) {
Muyuan Li6ca619f2016-03-08 13:30:42 -08004487 // Fullscreen secure system overlays get what they ask for. Screenshot region
4488 // selection overlay should also expand to full screen.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08004489 pf.left = df.left = of.left = cf.left = mOverscanScreenLeft;
4490 pf.top = df.top = of.top = cf.top = mOverscanScreenTop;
4491 pf.right = df.right = of.right = cf.right = mOverscanScreenLeft
4492 + mOverscanScreenWidth;
4493 pf.bottom = df.bottom = of.bottom = cf.bottom = mOverscanScreenTop
4494 + mOverscanScreenHeight;
Craig Mautner165be0c2015-01-27 15:16:58 -08004495 } else if (attrs.type == TYPE_BOOT_PROGRESS) {
Dianne Hackborn01011c32012-02-21 13:54:21 -08004496 // Boot progress screen always covers entire display.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08004497 pf.left = df.left = of.left = cf.left = mOverscanScreenLeft;
4498 pf.top = df.top = of.top = cf.top = mOverscanScreenTop;
4499 pf.right = df.right = of.right = cf.right = mOverscanScreenLeft
4500 + mOverscanScreenWidth;
4501 pf.bottom = df.bottom = of.bottom = cf.bottom = mOverscanScreenTop
4502 + mOverscanScreenHeight;
John Spurlockef4adae2013-08-26 17:58:58 -04004503 } else if (attrs.type == TYPE_WALLPAPER) {
Dianne Hackborn067e5f62014-09-07 23:14:30 -07004504 // The wallpaper also has Real Ultimate Power, but we want to tell
4505 // it about the overscan area.
4506 pf.left = df.left = mOverscanScreenLeft;
4507 pf.top = df.top = mOverscanScreenTop;
4508 pf.right = df.right = mOverscanScreenLeft + mOverscanScreenWidth;
4509 pf.bottom = df.bottom = mOverscanScreenTop + mOverscanScreenHeight;
4510 of.left = cf.left = mUnrestrictedScreenLeft;
4511 of.top = cf.top = mUnrestrictedScreenTop;
4512 of.right = cf.right = mUnrestrictedScreenLeft + mUnrestrictedScreenWidth;
4513 of.bottom = cf.bottom = mUnrestrictedScreenTop + mUnrestrictedScreenHeight;
John Spurlock46646232013-09-30 22:32:42 -04004514 } else if ((fl & FLAG_LAYOUT_IN_OVERSCAN) != 0
Dianne Hackbornc652de82013-02-15 16:32:56 -08004515 && attrs.type >= WindowManager.LayoutParams.FIRST_APPLICATION_WINDOW
4516 && attrs.type <= WindowManager.LayoutParams.LAST_SUB_WINDOW) {
4517 // Asking to layout into the overscan region, so give it that pure
4518 // unrestricted area.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08004519 pf.left = df.left = of.left = cf.left = mOverscanScreenLeft;
4520 pf.top = df.top = of.top = cf.top = mOverscanScreenTop;
4521 pf.right = df.right = of.right = cf.right
Dianne Hackbornc652de82013-02-15 16:32:56 -08004522 = mOverscanScreenLeft + mOverscanScreenWidth;
Dianne Hackbornc4aad012013-02-22 15:05:25 -08004523 pf.bottom = df.bottom = of.bottom = cf.bottom
Dianne Hackbornc652de82013-02-15 16:32:56 -08004524 = mOverscanScreenTop + mOverscanScreenHeight;
Alan Viverette5a0f4ec2013-10-07 15:10:29 -07004525 } else if (canHideNavigationBar()
Dianne Hackbornf87d1962012-04-04 12:48:24 -07004526 && (sysUiFl & View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION) != 0
Craig Mautnerbeac1062014-06-03 14:38:57 -07004527 && (attrs.type == TYPE_STATUS_BAR
4528 || attrs.type == TYPE_TOAST
Jorim Jaggi81fe2d12015-12-21 14:45:18 +01004529 || attrs.type == TYPE_DOCK_DIVIDER
Jorim Jaggi2fdeeab2015-04-01 15:13:03 -07004530 || attrs.type == TYPE_VOICE_INTERACTION_STARTING
John Spurlock34e13d92013-08-10 06:52:28 -04004531 || (attrs.type >= WindowManager.LayoutParams.FIRST_APPLICATION_WINDOW
4532 && attrs.type <= WindowManager.LayoutParams.LAST_SUB_WINDOW))) {
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07004533 // Asking for layout as if the nav bar is hidden, lets the
4534 // application extend into the unrestricted screen area. We
John Spurlock34e13d92013-08-10 06:52:28 -04004535 // only do this for application windows (or toasts) to ensure no window that
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07004536 // can be above the nav bar can do this.
4537 // XXX This assumes that an app asking for this will also
4538 // ask for layout in only content. We can't currently figure out
4539 // what the screen would be if only laying out to hide the nav bar.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08004540 pf.left = df.left = of.left = cf.left = mUnrestrictedScreenLeft;
4541 pf.top = df.top = of.top = cf.top = mUnrestrictedScreenTop;
4542 pf.right = df.right = of.right = cf.right = mUnrestrictedScreenLeft
4543 + mUnrestrictedScreenWidth;
4544 pf.bottom = df.bottom = of.bottom = cf.bottom = mUnrestrictedScreenTop
4545 + mUnrestrictedScreenHeight;
Jorim Jaggi9f6798a2016-02-10 22:16:06 -08004546 } else if ((sysUiFl & View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN) != 0) {
4547 pf.left = df.left = of.left = mRestrictedScreenLeft;
4548 pf.top = df.top = of.top = mRestrictedScreenTop;
4549 pf.right = df.right = of.right = mRestrictedScreenLeft + mRestrictedScreenWidth;
4550 pf.bottom = df.bottom = of.bottom = mRestrictedScreenTop
4551 + mRestrictedScreenHeight;
4552 if (adjust != SOFT_INPUT_ADJUST_RESIZE) {
4553 cf.left = mDockLeft;
4554 cf.top = mDockTop;
4555 cf.right = mDockRight;
4556 cf.bottom = mDockBottom;
4557 } else {
4558 cf.left = mContentLeft;
4559 cf.top = mContentTop;
4560 cf.right = mContentRight;
4561 cf.bottom = mContentBottom;
4562 }
Joe Onorato29fc2c92010-11-24 10:26:50 -08004563 } else {
Dianne Hackbornc4aad012013-02-22 15:05:25 -08004564 pf.left = df.left = of.left = cf.left = mRestrictedScreenLeft;
4565 pf.top = df.top = of.top = cf.top = mRestrictedScreenTop;
4566 pf.right = df.right = of.right = cf.right = mRestrictedScreenLeft
4567 + mRestrictedScreenWidth;
4568 pf.bottom = df.bottom = of.bottom = cf.bottom = mRestrictedScreenTop
4569 + mRestrictedScreenHeight;
Joe Onorato29fc2c92010-11-24 10:26:50 -08004570 }
Craig Mautner69b08182012-09-05 13:07:13 -07004571
Dianne Hackborn5b5cc4d2012-05-16 13:15:00 -07004572 applyStableConstraints(sysUiFl, fl, cf);
Craig Mautner69b08182012-09-05 13:07:13 -07004573
Dianne Hackborndea3ef72010-10-28 14:24:22 -07004574 if (adjust != SOFT_INPUT_ADJUST_NOTHING) {
4575 vf.left = mCurLeft;
4576 vf.top = mCurTop;
4577 vf.right = mCurRight;
4578 vf.bottom = mCurBottom;
4579 } else {
4580 vf.set(cf);
4581 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004582 } else if (attached != null) {
Craig Mautnereda67292013-04-28 13:50:14 -07004583 if (DEBUG_LAYOUT) Slog.v(TAG, "layoutWindowLw(" + attrs.getTitle() +
4584 "): attached to " + attached);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004585 // A child window should be placed inside of the same visible
4586 // frame that its parent had.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08004587 setAttachedWindowFrames(win, fl, adjust, attached, false, pf, df, of, cf, vf);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004588 } else {
Craig Mautnereda67292013-04-28 13:50:14 -07004589 if (DEBUG_LAYOUT) Slog.v(TAG, "layoutWindowLw(" + attrs.getTitle() +
4590 "): normal window");
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004591 // Otherwise, a normal window must be placed inside the content
4592 // of all screen decorations.
John Spurlock67a0f852015-06-15 15:35:47 -04004593 if (attrs.type == TYPE_STATUS_BAR_PANEL || attrs.type == TYPE_VOLUME_OVERLAY) {
4594 // Status bar panels and the volume dialog are the only windows who can go on
4595 // top of the status bar. They are protected by the STATUS_BAR_SERVICE
Dianne Hackborna239c842011-06-01 12:28:20 -07004596 // permission, so they have the same privileges as the status
4597 // bar itself.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08004598 pf.left = df.left = of.left = cf.left = mRestrictedScreenLeft;
4599 pf.top = df.top = of.top = cf.top = mRestrictedScreenTop;
4600 pf.right = df.right = of.right = cf.right = mRestrictedScreenLeft
4601 + mRestrictedScreenWidth;
4602 pf.bottom = df.bottom = of.bottom = cf.bottom = mRestrictedScreenTop
4603 + mRestrictedScreenHeight;
John Spurlock67a0f852015-06-15 15:35:47 -04004604 } else if (attrs.type == TYPE_TOAST || attrs.type == TYPE_SYSTEM_ALERT) {
John Spurlock414c1f02013-12-04 13:47:36 -05004605 // These dialogs are stable to interim decor changes.
John Spurlockbd957402013-10-03 11:38:39 -04004606 pf.left = df.left = of.left = cf.left = mStableLeft;
4607 pf.top = df.top = of.top = cf.top = mStableTop;
4608 pf.right = df.right = of.right = cf.right = mStableRight;
4609 pf.bottom = df.bottom = of.bottom = cf.bottom = mStableBottom;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004610 } else {
Dianne Hackborna239c842011-06-01 12:28:20 -07004611 pf.left = mContentLeft;
4612 pf.top = mContentTop;
4613 pf.right = mContentRight;
4614 pf.bottom = mContentBottom;
Dianne Hackborn20d94742014-05-29 18:35:45 -07004615 if (win.isVoiceInteraction()) {
4616 df.left = of.left = cf.left = mVoiceContentLeft;
4617 df.top = of.top = cf.top = mVoiceContentTop;
4618 df.right = of.right = cf.right = mVoiceContentRight;
4619 df.bottom = of.bottom = cf.bottom = mVoiceContentBottom;
4620 } else if (adjust != SOFT_INPUT_ADJUST_RESIZE) {
Dianne Hackbornc4aad012013-02-22 15:05:25 -08004621 df.left = of.left = cf.left = mDockLeft;
4622 df.top = of.top = cf.top = mDockTop;
4623 df.right = of.right = cf.right = mDockRight;
4624 df.bottom = of.bottom = cf.bottom = mDockBottom;
Dianne Hackborna239c842011-06-01 12:28:20 -07004625 } else {
Dianne Hackbornc4aad012013-02-22 15:05:25 -08004626 df.left = of.left = cf.left = mContentLeft;
4627 df.top = of.top = cf.top = mContentTop;
4628 df.right = of.right = cf.right = mContentRight;
4629 df.bottom = of.bottom = cf.bottom = mContentBottom;
Dianne Hackborna239c842011-06-01 12:28:20 -07004630 }
4631 if (adjust != SOFT_INPUT_ADJUST_NOTHING) {
4632 vf.left = mCurLeft;
4633 vf.top = mCurTop;
4634 vf.right = mCurRight;
4635 vf.bottom = mCurBottom;
4636 } else {
4637 vf.set(cf);
4638 }
Dianne Hackborndea3ef72010-10-28 14:24:22 -07004639 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004640 }
4641 }
Craig Mautner69b08182012-09-05 13:07:13 -07004642
Craig Mautnerb816bed2013-07-23 10:26:17 -07004643 // TYPE_SYSTEM_ERROR is above the NavigationBar so it can't be allowed to extend over it.
Wale Ogunwale9185fb02016-03-11 18:06:14 -08004644 // Also, we don't allow windows in multi-window mode to extend out of the screen.
4645 if ((fl & FLAG_LAYOUT_NO_LIMITS) != 0 && attrs.type != TYPE_SYSTEM_ERROR
Andrii Kulian933076d2016-03-29 17:04:42 -07004646 && !win.isInMultiWindowMode()) {
Dianne Hackborn067e5f62014-09-07 23:14:30 -07004647 df.left = df.top = -10000;
4648 df.right = df.bottom = 10000;
4649 if (attrs.type != TYPE_WALLPAPER) {
4650 of.left = of.top = cf.left = cf.top = vf.left = vf.top = -10000;
4651 of.right = of.bottom = cf.right = cf.bottom = vf.right = vf.bottom = 10000;
4652 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004653 }
4654
Filip Gruszczynski2217f612015-05-26 11:32:08 -07004655 // If the device has a chin (e.g. some watches), a dead area at the bottom of the screen we
4656 // need to provide information to the clients that want to pretend that you can draw there.
Filip Gruszczynskib0c673b2015-06-05 09:43:06 -07004657 // We only want to apply outsets to certain types of windows. For example, we never want to
4658 // apply the outsets to floating dialogs, because they wouldn't make sense there.
Filip Gruszczynski2987f612015-06-30 15:03:30 -07004659 final boolean useOutsets = shouldUseOutsets(attrs, fl);
Filip Gruszczynskib0c673b2015-06-05 09:43:06 -07004660 if (isDefaultDisplay && useOutsets) {
Filip Gruszczynski2217f612015-05-26 11:32:08 -07004661 osf = mTmpOutsetFrame;
4662 osf.set(cf.left, cf.top, cf.right, cf.bottom);
4663 int outset = ScreenShapeHelper.getWindowOutsetBottomPx(mContext.getResources());
4664 if (outset > 0) {
Filip Gruszczynski2987f612015-06-30 15:03:30 -07004665 int rotation = mDisplayRotation;
Filip Gruszczynski2217f612015-05-26 11:32:08 -07004666 if (rotation == Surface.ROTATION_0) {
4667 osf.bottom += outset;
4668 } else if (rotation == Surface.ROTATION_90) {
4669 osf.right += outset;
4670 } else if (rotation == Surface.ROTATION_180) {
4671 osf.top -= outset;
4672 } else if (rotation == Surface.ROTATION_270) {
4673 osf.left -= outset;
4674 }
4675 if (DEBUG_LAYOUT) Slog.v(TAG, "applying bottom outset of " + outset
4676 + " with rotation " + rotation + ", result: " + osf);
4677 }
4678 }
4679
Craig Mautnereda67292013-04-28 13:50:14 -07004680 if (DEBUG_LAYOUT) Slog.v(TAG, "Compute frame " + attrs.getTitle()
The Android Open Source Project11267662009-03-18 17:39:47 -07004681 + ": sim=#" + Integer.toHexString(sim)
RoboErik8a2cfc32014-05-16 11:19:38 -07004682 + " attach=" + attached + " type=" + attrs.type
Daniel Sandler8956dbb2011-04-22 07:55:02 -04004683 + String.format(" flags=0x%08x", fl)
The Android Open Source Project11267662009-03-18 17:39:47 -07004684 + " pf=" + pf.toShortString() + " df=" + df.toShortString()
Dianne Hackbornc4aad012013-02-22 15:05:25 -08004685 + " of=" + of.toShortString()
John Spurlock46646232013-09-30 22:32:42 -04004686 + " cf=" + cf.toShortString() + " vf=" + vf.toShortString()
Adrian Roosfa104232014-06-20 16:10:14 -07004687 + " dcf=" + dcf.toShortString()
Filip Gruszczynski2217f612015-05-26 11:32:08 -07004688 + " sf=" + sf.toShortString()
4689 + " osf=" + (osf == null ? "null" : osf.toShortString()));
Craig Mautner69b08182012-09-05 13:07:13 -07004690
Filip Gruszczynski2217f612015-05-26 11:32:08 -07004691 win.computeFrameLw(pf, df, of, cf, vf, dcf, sf, osf);
Craig Mautner69b08182012-09-05 13:07:13 -07004692
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004693 // Dock windows carve out the bottom of the screen, so normal windows
4694 // can't appear underneath them.
Craig Mautner8bd206b2012-10-03 10:32:02 -07004695 if (attrs.type == TYPE_INPUT_METHOD && win.isVisibleOrBehindKeyguardLw()
4696 && !win.getGivenInsetsPendingLw()) {
satok1bc0a492012-04-25 22:47:12 +09004697 setLastInputMethodWindowLw(null, null);
4698 offsetInputMethodWindowLw(win);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004699 }
Dianne Hackborne30e02f2014-05-27 18:24:45 -07004700 if (attrs.type == TYPE_VOICE_INTERACTION && win.isVisibleOrBehindKeyguardLw()
4701 && !win.getGivenInsetsPendingLw()) {
4702 offsetVoiceInputWindowLw(win);
4703 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004704 }
4705
satok1bc0a492012-04-25 22:47:12 +09004706 private void offsetInputMethodWindowLw(WindowState win) {
Craig Mautner4774f6a2015-03-23 11:42:55 -07004707 int top = Math.max(win.getDisplayFrameLw().top, win.getContentFrameLw().top);
satok1bc0a492012-04-25 22:47:12 +09004708 top += win.getGivenContentInsetsLw().top;
4709 if (mContentBottom > top) {
4710 mContentBottom = top;
4711 }
Dianne Hackborne30e02f2014-05-27 18:24:45 -07004712 if (mVoiceContentBottom > top) {
4713 mVoiceContentBottom = top;
4714 }
satok1bc0a492012-04-25 22:47:12 +09004715 top = win.getVisibleFrameLw().top;
4716 top += win.getGivenVisibleInsetsLw().top;
4717 if (mCurBottom > top) {
4718 mCurBottom = top;
4719 }
Craig Mautnereda67292013-04-28 13:50:14 -07004720 if (DEBUG_LAYOUT) Slog.v(TAG, "Input method: mDockBottom="
satok1bc0a492012-04-25 22:47:12 +09004721 + mDockBottom + " mContentBottom="
4722 + mContentBottom + " mCurBottom=" + mCurBottom);
4723 }
4724
Dianne Hackborne30e02f2014-05-27 18:24:45 -07004725 private void offsetVoiceInputWindowLw(WindowState win) {
Craig Mautner4774f6a2015-03-23 11:42:55 -07004726 int top = Math.max(win.getDisplayFrameLw().top, win.getContentFrameLw().top);
Dianne Hackbornae6688b2015-02-11 17:02:41 -08004727 top += win.getGivenContentInsetsLw().top;
4728 if (mVoiceContentBottom > top) {
4729 mVoiceContentBottom = top;
Dianne Hackborne30e02f2014-05-27 18:24:45 -07004730 }
4731 }
4732
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004733 /** {@inheritDoc} */
Craig Mautner61ac6bb2012-02-02 17:29:33 -08004734 @Override
4735 public void finishLayoutLw() {
4736 return;
Dianne Hackborn5f3063e2010-03-10 16:01:58 -08004737 }
4738
4739 /** {@inheritDoc} */
Craig Mautnerad09bcc2012-10-08 13:33:11 -07004740 @Override
Craig Mautner39834192012-09-02 07:47:24 -07004741 public void beginPostLayoutPolicyLw(int displayWidth, int displayHeight) {
Dianne Hackborn5f3063e2010-03-10 16:01:58 -08004742 mTopFullscreenOpaqueWindowState = null;
Adrian Rooscd3884d2015-02-18 17:25:23 +01004743 mTopFullscreenOpaqueOrDimmingWindowState = null;
Jorim Jaggi86905582016-02-09 21:36:09 -08004744 mTopDockedOpaqueWindowState = null;
4745 mTopDockedOpaqueOrDimmingWindowState = null;
Craig Mautner2bc789b2014-03-19 19:48:38 -07004746 mAppsToBeHidden.clear();
Jorim Jaggic13fcac2014-09-11 17:36:57 +02004747 mAppsThatDismissKeyguard.clear();
Dianne Hackborn5f3063e2010-03-10 16:01:58 -08004748 mForceStatusBar = false;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07004749 mForceStatusBarFromKeyguard = false;
Selim Cinek4a4a2bddc2015-05-07 12:50:19 -07004750 mForceStatusBarTransparent = false;
Dianne Hackborn891d3fb2013-01-09 18:31:37 -08004751 mForcingShowNavBar = false;
4752 mForcingShowNavBarLayer = -1;
RoboErik8a2cfc32014-05-16 11:19:38 -07004753
Dianne Hackborn5f3063e2010-03-10 16:01:58 -08004754 mHideLockScreen = false;
4755 mAllowLockscreenWhenOn = false;
Craig Mautnerad09bcc2012-10-08 13:33:11 -07004756 mDismissKeyguard = DISMISS_KEYGUARD_NONE;
Dianne Hackborn7ad44382012-10-18 17:46:00 -07004757 mShowingLockscreen = false;
4758 mShowingDream = false;
Craig Mautnerc9457fa2014-06-06 14:27:48 -07004759 mWinShowWhenLocked = null;
Jim Millerab954542014-10-10 18:21:49 -07004760 mKeyguardSecure = isKeyguardSecure();
4761 mKeyguardSecureIncludingHidden = mKeyguardSecure
4762 && (mKeyguardDelegate != null && mKeyguardDelegate.isShowing());
Dianne Hackborn5f3063e2010-03-10 16:01:58 -08004763 }
4764
4765 /** {@inheritDoc} */
Craig Mautnerad09bcc2012-10-08 13:33:11 -07004766 @Override
Yohei Yukawad1a09222015-06-30 16:22:05 -07004767 public void applyPostLayoutPolicyLw(WindowState win, WindowManager.LayoutParams attrs,
4768 WindowState attached) {
Dianne Hackbornbc1aa7b2011-09-20 11:20:31 -07004769 if (DEBUG_LAYOUT) Slog.i(TAG, "Win " + win + ": isVisibleOrBehindKeyguardLw="
4770 + win.isVisibleOrBehindKeyguardLw());
John Spurlockc6d1c602014-01-17 15:22:06 -05004771 final int fl = PolicyControl.getWindowFlags(win, attrs);
John Spurlock414c1f02013-12-04 13:47:36 -05004772 if (mTopFullscreenOpaqueWindowState == null
4773 && win.isVisibleLw() && attrs.type == TYPE_INPUT_METHOD) {
4774 mForcingShowNavBar = true;
4775 mForcingShowNavBarLayer = win.getSurfaceLayer();
Dianne Hackborn891d3fb2013-01-09 18:31:37 -08004776 }
Selim Cinek4a4a2bddc2015-05-07 12:50:19 -07004777 if (attrs.type == TYPE_STATUS_BAR) {
4778 if ((attrs.privateFlags & PRIVATE_FLAG_KEYGUARD) != 0) {
4779 mForceStatusBarFromKeyguard = true;
Jorim Jaggie1de9f62015-09-23 14:59:50 -07004780 mShowingLockscreen = true;
Selim Cinek4a4a2bddc2015-05-07 12:50:19 -07004781 }
4782 if ((attrs.privateFlags & PRIVATE_FLAG_FORCE_STATUS_BAR_VISIBLE_TRANSPARENT) != 0) {
4783 mForceStatusBarTransparent = true;
4784 }
Jorim Jaggiafd4a552014-04-08 15:13:05 +02004785 }
Adrian Roos602c68e2015-04-24 16:03:47 -07004786
4787 boolean appWindow = attrs.type >= FIRST_APPLICATION_WINDOW
4788 && attrs.type < FIRST_SYSTEM_WINDOW;
4789 final boolean showWhenLocked = (fl & FLAG_SHOW_WHEN_LOCKED) != 0;
4790 final boolean dismissKeyguard = (fl & FLAG_DISMISS_KEYGUARD) != 0;
Jorim Jaggi86905582016-02-09 21:36:09 -08004791 final int stackId = win.getStackId();
Dianne Hackborn5f3063e2010-03-10 16:01:58 -08004792 if (mTopFullscreenOpaqueWindowState == null &&
Dianne Hackborn01b02a72012-01-12 14:05:03 -08004793 win.isVisibleOrBehindKeyguardLw() && !win.isGoneForLayoutLw()) {
John Spurlockc6d1c602014-01-17 15:22:06 -05004794 if ((fl & FLAG_FORCE_NOT_FULLSCREEN) != 0) {
Jorim Jaggi380ecb82014-03-14 17:25:20 +01004795 if ((attrs.privateFlags & PRIVATE_FLAG_KEYGUARD) != 0) {
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07004796 mForceStatusBarFromKeyguard = true;
4797 } else {
4798 mForceStatusBar = true;
4799 }
4800 }
Dianne Hackborn7ad44382012-10-18 17:46:00 -07004801 if (attrs.type == TYPE_DREAM) {
Jeff Brownc8018eb2012-10-29 21:33:27 -07004802 // If the lockscreen was showing when the dream started then wait
4803 // for the dream to draw before hiding the lockscreen.
4804 if (!mDreamingLockscreen
4805 || (win.isVisibleLw() && win.hasDrawnLw())) {
4806 mShowingDream = true;
Craig Mautnerab55e522014-03-03 13:26:03 -08004807 appWindow = true;
Dianne Hackborn7ad44382012-10-18 17:46:00 -07004808 }
4809 }
Craig Mautnerab55e522014-03-03 13:26:03 -08004810
Yohei Yukawad1a09222015-06-30 16:22:05 -07004811 final IApplicationToken appToken = win.getAppToken();
4812
4813 // For app windows that are not attached, we decide if all windows in the app they
4814 // represent should be hidden or if we should hide the lockscreen. For attached app
4815 // windows we defer the decision to the window it is attached to.
4816 if (appWindow && attached == null) {
Jorim Jaggic13fcac2014-09-11 17:36:57 +02004817 if (showWhenLocked) {
Craig Mautnerc9457fa2014-06-06 14:27:48 -07004818 // Remove any previous windows with the same appToken.
Jorim Jaggic13fcac2014-09-11 17:36:57 +02004819 mAppsToBeHidden.remove(appToken);
4820 mAppsThatDismissKeyguard.remove(appToken);
Craig Mautnerca0a1242014-12-02 12:25:14 -08004821 if (mAppsToBeHidden.isEmpty()) {
Craig Mautner192d6042014-12-02 23:24:48 -08004822 if (dismissKeyguard && !mKeyguardSecure) {
4823 mAppsThatDismissKeyguard.add(appToken);
Selim Cinek90b5e072015-08-28 17:05:56 -07004824 } else if (win.isDrawnLw() || win.hasAppShownWindows()) {
Craig Mautnerca0a1242014-12-02 12:25:14 -08004825 mWinShowWhenLocked = win;
4826 mHideLockScreen = true;
4827 mForceStatusBarFromKeyguard = false;
Craig Mautnerca0a1242014-12-02 12:25:14 -08004828 }
Craig Mautnerc9457fa2014-06-06 14:27:48 -07004829 }
Jorim Jaggic13fcac2014-09-11 17:36:57 +02004830 } else if (dismissKeyguard) {
Jim Millerab954542014-10-10 18:21:49 -07004831 if (mKeyguardSecure) {
Jorim Jaggic13fcac2014-09-11 17:36:57 +02004832 mAppsToBeHidden.add(appToken);
4833 } else {
4834 mAppsToBeHidden.remove(appToken);
4835 }
4836 mAppsThatDismissKeyguard.add(appToken);
Craig Mautner2bc789b2014-03-19 19:48:38 -07004837 } else {
Jorim Jaggic13fcac2014-09-11 17:36:57 +02004838 mAppsToBeHidden.add(appToken);
Craig Mautner2bc789b2014-03-19 19:48:38 -07004839 }
Jorim Jaggi86905582016-02-09 21:36:09 -08004840 if (isFullscreen(attrs) && StackId.normallyFullscreenWindows(stackId)) {
Craig Mautnerab55e522014-03-03 13:26:03 -08004841 if (DEBUG_LAYOUT) Slog.v(TAG, "Fullscreen window: " + win);
4842 mTopFullscreenOpaqueWindowState = win;
Adrian Rooscd3884d2015-02-18 17:25:23 +01004843 if (mTopFullscreenOpaqueOrDimmingWindowState == null) {
4844 mTopFullscreenOpaqueOrDimmingWindowState = win;
4845 }
Jorim Jaggic13fcac2014-09-11 17:36:57 +02004846 if (!mAppsThatDismissKeyguard.isEmpty() &&
4847 mDismissKeyguard == DISMISS_KEYGUARD_NONE) {
4848 if (DEBUG_LAYOUT) Slog.v(TAG,
4849 "Setting mDismissKeyguard true by win " + win);
tingna_sunge785ffa2015-05-12 13:23:15 +08004850 mDismissKeyguard = (mWinDismissingKeyguard == win
4851 && mSecureDismissingKeyguard == mKeyguardSecure)
4852 ? DISMISS_KEYGUARD_CONTINUE : DISMISS_KEYGUARD_START;
Jorim Jaggic13fcac2014-09-11 17:36:57 +02004853 mWinDismissingKeyguard = win;
tingna_sunge785ffa2015-05-12 13:23:15 +08004854 mSecureDismissingKeyguard = mKeyguardSecure;
Jim Millerab954542014-10-10 18:21:49 -07004855 mForceStatusBarFromKeyguard = mShowingLockscreen && mKeyguardSecure;
Selim Cinek90b5e072015-08-28 17:05:56 -07004856 } else if (mAppsToBeHidden.isEmpty() && showWhenLocked
4857 && (win.isDrawnLw() || win.hasAppShownWindows())) {
Jorim Jaggic13fcac2014-09-11 17:36:57 +02004858 if (DEBUG_LAYOUT) Slog.v(TAG,
4859 "Setting mHideLockScreen to true by win " + win);
4860 mHideLockScreen = true;
4861 mForceStatusBarFromKeyguard = false;
Craig Mautnerab55e522014-03-03 13:26:03 -08004862 }
Craig Mautner00156ec2014-03-06 22:29:02 -08004863 if ((fl & FLAG_ALLOW_LOCK_WHILE_SCREEN_ON) != 0) {
Craig Mautnerab55e522014-03-03 13:26:03 -08004864 mAllowLockscreenWhenOn = true;
4865 }
Dianne Hackborn5f3063e2010-03-10 16:01:58 -08004866 }
Craig Mautnerc9457fa2014-06-06 14:27:48 -07004867
4868 if (mWinShowWhenLocked != null &&
Adrian Roos602c68e2015-04-24 16:03:47 -07004869 mWinShowWhenLocked.getAppToken() != win.getAppToken() &&
4870 (attrs.flags & FLAG_SHOW_WHEN_LOCKED) == 0) {
Craig Mautnerc9457fa2014-06-06 14:27:48 -07004871 win.hideLw(false);
4872 }
Dianne Hackborn5f3063e2010-03-10 16:01:58 -08004873 }
Adrian Roos602c68e2015-04-24 16:03:47 -07004874 } else if (mTopFullscreenOpaqueWindowState == null && mWinShowWhenLocked == null) {
4875 // No TopFullscreenOpaqueWindow is showing, but we found a SHOW_WHEN_LOCKED window
4876 // that is being hidden in an animation - keep the
4877 // keyguard hidden until the new window shows up and
4878 // we know whether to show the keyguard or not.
Adrian Roosb85e1ec2015-05-29 15:23:18 -07004879 if (win.isAnimatingLw() && appWindow && showWhenLocked && mKeyguardHidden) {
Adrian Roos602c68e2015-04-24 16:03:47 -07004880 mHideLockScreen = true;
4881 mWinShowWhenLocked = win;
4882 }
Dianne Hackborn5f3063e2010-03-10 16:01:58 -08004883 }
Jorim Jaggi86905582016-02-09 21:36:09 -08004884
4885 // Keep track of the window if it's dimming but not necessarily fullscreen.
4886 final boolean reallyVisible = win.isVisibleOrBehindKeyguardLw() && !win.isGoneForLayoutLw();
4887 if (mTopFullscreenOpaqueOrDimmingWindowState == null && reallyVisible
4888 && win.isDimming() && StackId.normallyFullscreenWindows(stackId)) {
Adrian Rooscd3884d2015-02-18 17:25:23 +01004889 mTopFullscreenOpaqueOrDimmingWindowState = win;
4890 }
Jorim Jaggi86905582016-02-09 21:36:09 -08004891
4892 // We need to keep track of the top "fullscreen" opaque window for the docked stack
4893 // separately, because both the "real fullscreen" opaque window and the one for the docked
4894 // stack can control View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR.
4895 if (mTopDockedOpaqueWindowState == null && reallyVisible && appWindow && attached == null
4896 && isFullscreen(attrs) && stackId == DOCKED_STACK_ID) {
4897 mTopDockedOpaqueWindowState = win;
4898 if (mTopDockedOpaqueOrDimmingWindowState == null) {
4899 mTopDockedOpaqueOrDimmingWindowState = win;
4900 }
4901 }
4902
4903 // Also keep track of any windows that are dimming but not necessarily fullscreen in the
4904 // docked stack.
4905 if (mTopDockedOpaqueOrDimmingWindowState == null && reallyVisible && win.isDimming()
4906 && stackId == DOCKED_STACK_ID) {
4907 mTopDockedOpaqueOrDimmingWindowState = win;
4908 }
4909 }
4910
4911 private boolean isFullscreen(WindowManager.LayoutParams attrs) {
4912 return attrs.x == 0 && attrs.y == 0
4913 && attrs.width == WindowManager.LayoutParams.MATCH_PARENT
4914 && attrs.height == WindowManager.LayoutParams.MATCH_PARENT;
Dianne Hackborn5f3063e2010-03-10 16:01:58 -08004915 }
4916
4917 /** {@inheritDoc} */
Craig Mautnerad09bcc2012-10-08 13:33:11 -07004918 @Override
Craig Mautner39834192012-09-02 07:47:24 -07004919 public int finishPostLayoutPolicyLw() {
Craig Mautnerc5e73bf2015-04-21 15:41:26 +00004920 if (mWinShowWhenLocked != null && mTopFullscreenOpaqueWindowState != null &&
4921 mWinShowWhenLocked.getAppToken() != mTopFullscreenOpaqueWindowState.getAppToken()
4922 && isKeyguardLocked()) {
Craig Mautnerc9457fa2014-06-06 14:27:48 -07004923 // A dialog is dismissing the keyguard. Put the wallpaper behind it and hide the
4924 // fullscreen window.
4925 // TODO: Make sure FLAG_SHOW_WALLPAPER is restored when dialog is dismissed. Or not.
4926 mWinShowWhenLocked.getAttrs().flags |= FLAG_SHOW_WALLPAPER;
4927 mTopFullscreenOpaqueWindowState.hideLw(false);
4928 mTopFullscreenOpaqueWindowState = mWinShowWhenLocked;
4929 }
4930
Dianne Hackborn39c2d712009-09-22 11:41:31 -07004931 int changes = 0;
Joe Onorato93056472010-09-10 10:30:46 -04004932 boolean topIsFullscreen = false;
Daniel Sandlere02d8082010-10-08 15:13:22 -04004933
4934 final WindowManager.LayoutParams lp = (mTopFullscreenOpaqueWindowState != null)
4935 ? mTopFullscreenOpaqueWindowState.getAttrs()
4936 : null;
4937
Jeff Brownc8018eb2012-10-29 21:33:27 -07004938 // If we are not currently showing a dream then remember the current
4939 // lockscreen state. We will use this to determine whether the dream
4940 // started while the lockscreen was showing and remember this state
4941 // while the dream is showing.
Dianne Hackborn7ad44382012-10-18 17:46:00 -07004942 if (!mShowingDream) {
4943 mDreamingLockscreen = mShowingLockscreen;
Jeff Brown061ea992015-04-17 19:55:47 -07004944 if (mDreamingSleepTokenNeeded) {
4945 mDreamingSleepTokenNeeded = false;
4946 mHandler.obtainMessage(MSG_UPDATE_DREAMING_SLEEP_TOKEN, 0, 1).sendToTarget();
4947 }
4948 } else {
4949 if (!mDreamingSleepTokenNeeded) {
4950 mDreamingSleepTokenNeeded = true;
4951 mHandler.obtainMessage(MSG_UPDATE_DREAMING_SLEEP_TOKEN, 1, 1).sendToTarget();
4952 }
Dianne Hackborn7ad44382012-10-18 17:46:00 -07004953 }
4954
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004955 if (mStatusBar != null) {
Craig Mautnereda67292013-04-28 13:50:14 -07004956 if (DEBUG_LAYOUT) Slog.i(TAG, "force=" + mForceStatusBar
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07004957 + " forcefkg=" + mForceStatusBarFromKeyguard
Dianne Hackbornd70bc2f2009-10-06 23:25:51 -07004958 + " top=" + mTopFullscreenOpaqueWindowState);
Selim Cinek4a4a2bddc2015-05-07 12:50:19 -07004959 boolean shouldBeTransparent = mForceStatusBarTransparent
4960 && !mForceStatusBar
4961 && !mForceStatusBarFromKeyguard;
4962 if (!shouldBeTransparent) {
4963 mStatusBarController.setShowTransparent(false /* transparent */);
4964 } else if (!mStatusBar.isVisibleLw()) {
4965 mStatusBarController.setShowTransparent(true /* transparent */);
4966 }
4967 if (mForceStatusBar || mForceStatusBarFromKeyguard || mForceStatusBarTransparent) {
Craig Mautnereda67292013-04-28 13:50:14 -07004968 if (DEBUG_LAYOUT) Slog.v(TAG, "Showing status bar: forced");
John Spurlock27735a42013-08-14 17:57:38 -04004969 if (mStatusBarController.setBarShowingLw(true)) {
4970 changes |= FINISH_LAYOUT_REDO_LAYOUT;
4971 }
Craig Mautner81defc72013-10-29 11:10:42 -07004972 // Maintain fullscreen layout until incoming animation is complete.
4973 topIsFullscreen = mTopIsFullscreen && mStatusBar.isAnimatingLw();
John Spurlockf92b6162013-11-11 15:01:16 -05004974 // Transient status bar on the lockscreen is not allowed
4975 if (mForceStatusBarFromKeyguard && mStatusBarController.isTransientShowing()) {
4976 mStatusBarController.updateVisibilityLw(false /*transientAllowed*/,
4977 mLastSystemUiFlags, mLastSystemUiFlags);
4978 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004979 } else if (mTopFullscreenOpaqueWindowState != null) {
John Spurlockc6d1c602014-01-17 15:22:06 -05004980 final int fl = PolicyControl.getWindowFlags(null, lp);
Joe Onorato93056472010-09-10 10:30:46 -04004981 if (localLOGV) {
Craig Mautnereda67292013-04-28 13:50:14 -07004982 Slog.d(TAG, "frame: " + mTopFullscreenOpaqueWindowState.getFrameLw()
Filip Gruszczynski2a6a2c22015-10-14 12:00:53 -07004983 + " shown position: "
4984 + mTopFullscreenOpaqueWindowState.getShownPositionLw());
Craig Mautnereda67292013-04-28 13:50:14 -07004985 Slog.d(TAG, "attr: " + mTopFullscreenOpaqueWindowState.getAttrs()
John Spurlockc6d1c602014-01-17 15:22:06 -05004986 + " lp.flags=0x" + Integer.toHexString(fl));
Joe Onorato93056472010-09-10 10:30:46 -04004987 }
John Spurlockc6d1c602014-01-17 15:22:06 -05004988 topIsFullscreen = (fl & WindowManager.LayoutParams.FLAG_FULLSCREEN) != 0
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07004989 || (mLastSystemUiFlags & View.SYSTEM_UI_FLAG_FULLSCREEN) != 0;
Joe Onorato93056472010-09-10 10:30:46 -04004990 // The subtle difference between the window for mTopFullscreenOpaqueWindowState
Mark Dolinerd0646dc2014-08-27 16:04:02 -07004991 // and mTopIsFullscreen is that mTopIsFullscreen is set only if the window
Joe Onorato93056472010-09-10 10:30:46 -04004992 // has the FLAG_FULLSCREEN set. Not sure if there is another way that to be the
4993 // case though.
John Spurlock27735a42013-08-14 17:57:38 -04004994 if (mStatusBarController.isTransientShowing()) {
4995 if (mStatusBarController.setBarShowingLw(true)) {
John Spurlock32beb2c2013-03-11 10:16:47 -04004996 changes |= FINISH_LAYOUT_REDO_LAYOUT;
4997 }
Wale Ogunwale6e94a9e2015-10-07 15:35:49 -07004998 } else if (topIsFullscreen
4999 && !mWindowManagerInternal.isStackVisible(FREEFORM_WORKSPACE_STACK_ID)
5000 && !mWindowManagerInternal.isStackVisible(DOCKED_STACK_ID)) {
Craig Mautnereda67292013-04-28 13:50:14 -07005001 if (DEBUG_LAYOUT) Slog.v(TAG, "** HIDING status bar");
John Spurlock27735a42013-08-14 17:57:38 -04005002 if (mStatusBarController.setBarShowingLw(false)) {
Dianne Hackbornf87d1962012-04-04 12:48:24 -07005003 changes |= FINISH_LAYOUT_REDO_LAYOUT;
Craig Mautnereda67292013-04-28 13:50:14 -07005004 } else {
Craig Mautnerc5a6e442013-06-05 17:22:35 -07005005 if (DEBUG_LAYOUT) Slog.v(TAG, "Status bar already hiding");
Daniel Sandler40427442010-07-16 11:44:52 -04005006 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005007 } else {
Craig Mautnereda67292013-04-28 13:50:14 -07005008 if (DEBUG_LAYOUT) Slog.v(TAG, "** SHOWING status bar: top is not fullscreen");
John Spurlock27735a42013-08-14 17:57:38 -04005009 if (mStatusBarController.setBarShowingLw(true)) {
5010 changes |= FINISH_LAYOUT_REDO_LAYOUT;
5011 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005012 }
5013 }
5014 }
Daniel Sandlere02d8082010-10-08 15:13:22 -04005015
Craig Mautner81defc72013-10-29 11:10:42 -07005016 if (mTopIsFullscreen != topIsFullscreen) {
5017 if (!topIsFullscreen) {
5018 // Force another layout when status bar becomes fully shown.
5019 changes |= FINISH_LAYOUT_REDO_LAYOUT;
5020 }
5021 mTopIsFullscreen = topIsFullscreen;
5022 }
Daniel Sandlere02d8082010-10-08 15:13:22 -04005023
Craig Mautner39834192012-09-02 07:47:24 -07005024 // Hide the key guard if a visible window explicitly specifies that it wants to be
5025 // displayed when the screen is locked.
Jorim Jaggi5cf17872014-03-26 18:31:48 +01005026 if (mKeyguardDelegate != null && mStatusBar != null) {
5027 if (localLOGV) Slog.v(TAG, "finishPostLayoutPolicyLw: mHideKeyguard="
5028 + mHideLockScreen);
Jim Millerab954542014-10-10 18:21:49 -07005029 if (mDismissKeyguard != DISMISS_KEYGUARD_NONE && !mKeyguardSecure) {
Jorim Jaggi5cf17872014-03-26 18:31:48 +01005030 mKeyguardHidden = true;
Jim Millerab954542014-10-10 18:21:49 -07005031 if (setKeyguardOccludedLw(true)) {
Dianne Hackborn39c2d712009-09-22 11:41:31 -07005032 changes |= FINISH_LAYOUT_REDO_LAYOUT
5033 | FINISH_LAYOUT_REDO_CONFIG
5034 | FINISH_LAYOUT_REDO_WALLPAPER;
5035 }
Jorim Jaggi5cf17872014-03-26 18:31:48 +01005036 if (mKeyguardDelegate.isShowing()) {
5037 mHandler.post(new Runnable() {
5038 @Override
5039 public void run() {
5040 mKeyguardDelegate.keyguardDone(false, false);
5041 }
5042 });
5043 }
5044 } else if (mHideLockScreen) {
5045 mKeyguardHidden = true;
Jorim Jaggi7d85ea92015-05-20 17:20:40 -07005046 mWinDismissingKeyguard = null;
Jim Millerab954542014-10-10 18:21:49 -07005047 if (setKeyguardOccludedLw(true)) {
Jorim Jaggi5cf17872014-03-26 18:31:48 +01005048 changes |= FINISH_LAYOUT_REDO_LAYOUT
5049 | FINISH_LAYOUT_REDO_CONFIG
5050 | FINISH_LAYOUT_REDO_WALLPAPER;
5051 }
5052 } else if (mDismissKeyguard != DISMISS_KEYGUARD_NONE) {
Jorim Jaggi7d85ea92015-05-20 17:20:40 -07005053 mKeyguardHidden = false;
5054 if (setKeyguardOccludedLw(false)) {
5055 changes |= FINISH_LAYOUT_REDO_LAYOUT
5056 | FINISH_LAYOUT_REDO_CONFIG
5057 | FINISH_LAYOUT_REDO_WALLPAPER;
5058 }
Jorim Jaggi5cf17872014-03-26 18:31:48 +01005059 if (mDismissKeyguard == DISMISS_KEYGUARD_START) {
5060 // Only launch the next keyguard unlock window once per window.
Jorim Jaggi5cf17872014-03-26 18:31:48 +01005061 mHandler.post(new Runnable() {
5062 @Override
5063 public void run() {
5064 mKeyguardDelegate.dismiss();
5065 }
5066 });
5067 }
5068 } else {
5069 mWinDismissingKeyguard = null;
tingna_sunge785ffa2015-05-12 13:23:15 +08005070 mSecureDismissingKeyguard = false;
Jorim Jaggi5cf17872014-03-26 18:31:48 +01005071 mKeyguardHidden = false;
Jim Millerab954542014-10-10 18:21:49 -07005072 if (setKeyguardOccludedLw(false)) {
Jorim Jaggi5cf17872014-03-26 18:31:48 +01005073 changes |= FINISH_LAYOUT_REDO_LAYOUT
5074 | FINISH_LAYOUT_REDO_CONFIG
5075 | FINISH_LAYOUT_REDO_WALLPAPER;
5076 }
Suchi Amalapurapu9cdc9032009-05-14 18:01:07 -07005077 }
5078 }
Joe Onorato664644d2011-01-23 17:53:23 -08005079
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07005080 if ((updateSystemUiVisibilityLw()&SYSTEM_UI_CHANGING_LAYOUT) != 0) {
Dianne Hackborndf89e652011-10-06 22:35:11 -07005081 // If the navigation bar has been hidden or shown, we need to do another
5082 // layout pass to update that window.
5083 changes |= FINISH_LAYOUT_REDO_LAYOUT;
5084 }
Joe Onorato664644d2011-01-23 17:53:23 -08005085
Mike Lockwood28569302010-01-28 11:54:40 -05005086 // update since mAllowLockscreenWhenOn might have changed
5087 updateLockScreenTimeout();
Dianne Hackborn39c2d712009-09-22 11:41:31 -07005088 return changes;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005089 }
5090
Jorim Jaggi380ecb82014-03-14 17:25:20 +01005091 /**
Jim Millerab954542014-10-10 18:21:49 -07005092 * Updates the occluded state of the Keyguard.
Jorim Jaggi380ecb82014-03-14 17:25:20 +01005093 *
Jorim Jaggi380ecb82014-03-14 17:25:20 +01005094 * @return Whether the flags have changed and we have to redo the layout.
5095 */
Jim Millerab954542014-10-10 18:21:49 -07005096 private boolean setKeyguardOccludedLw(boolean isOccluded) {
5097 boolean wasOccluded = mKeyguardOccluded;
5098 boolean showing = mKeyguardDelegate.isShowing();
5099 if (wasOccluded && !isOccluded && showing) {
5100 mKeyguardOccluded = false;
5101 mKeyguardDelegate.setOccluded(false);
Jorim Jaggi380ecb82014-03-14 17:25:20 +01005102 mStatusBar.getAttrs().privateFlags |= PRIVATE_FLAG_KEYGUARD;
5103 mStatusBar.getAttrs().flags |= FLAG_SHOW_WALLPAPER;
5104 return true;
Jim Millerab954542014-10-10 18:21:49 -07005105 } else if (!wasOccluded && isOccluded && showing) {
5106 mKeyguardOccluded = true;
5107 mKeyguardDelegate.setOccluded(true);
Jorim Jaggi380ecb82014-03-14 17:25:20 +01005108 mStatusBar.getAttrs().privateFlags &= ~PRIVATE_FLAG_KEYGUARD;
5109 mStatusBar.getAttrs().flags &= ~FLAG_SHOW_WALLPAPER;
5110 return true;
5111 } else {
5112 return false;
5113 }
5114 }
5115
5116 private boolean isStatusBarKeyguard() {
5117 return mStatusBar != null
5118 && (mStatusBar.getAttrs().privateFlags & PRIVATE_FLAG_KEYGUARD) != 0;
5119 }
5120
Jose Lima9546b202014-07-02 17:21:51 -07005121 @Override
Dianne Hackborn08743722009-12-21 12:16:51 -08005122 public boolean allowAppAnimationsLw() {
Jorim Jaggi380ecb82014-03-14 17:25:20 +01005123 if (isStatusBarKeyguard() || mShowingDream) {
Craig Mautner28816302013-10-10 20:31:00 -07005124 // If keyguard or dreams is currently visible, no reason to animate behind it.
Dianne Hackborn08743722009-12-21 12:16:51 -08005125 return false;
5126 }
Dianne Hackborn08743722009-12-21 12:16:51 -08005127 return true;
5128 }
5129
Jose Lima9546b202014-07-02 17:21:51 -07005130 @Override
Dianne Hackborndf89e652011-10-06 22:35:11 -07005131 public int focusChangedLw(WindowState lastFocus, WindowState newFocus) {
Joe Onorato664644d2011-01-23 17:53:23 -08005132 mFocusedWindow = newFocus;
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07005133 if ((updateSystemUiVisibilityLw()&SYSTEM_UI_CHANGING_LAYOUT) != 0) {
Dianne Hackborndf89e652011-10-06 22:35:11 -07005134 // If the navigation bar has been hidden or shown, we need to do another
5135 // layout pass to update that window.
5136 return FINISH_LAYOUT_REDO_LAYOUT;
5137 }
5138 return 0;
Joe Onorato664644d2011-01-23 17:53:23 -08005139 }
5140
Dianne Hackborn0ecadf72009-03-31 18:00:37 -07005141 /** {@inheritDoc} */
Jose Lima9546b202014-07-02 17:21:51 -07005142 @Override
Jeff Brown46b9ac02010-04-22 18:58:52 -07005143 public void notifyLidSwitchChanged(long whenNanos, boolean lidOpen) {
5144 // lid changed state
Jeff Brownc458ce92012-04-30 14:58:40 -07005145 final int newLidState = lidOpen ? LID_OPEN : LID_CLOSED;
5146 if (newLidState == mLidState) {
5147 return;
5148 }
Jeff Brown01a98dd2011-09-20 15:08:29 -07005149
Jeff Brownc458ce92012-04-30 14:58:40 -07005150 mLidState = newLidState;
5151 applyLidSwitchState();
Jeff Brown01a98dd2011-09-20 15:08:29 -07005152 updateRotation(true);
Jeff Brownc458ce92012-04-30 14:58:40 -07005153
5154 if (lidOpen) {
Dianne Hackborn280a64e2015-07-13 14:48:08 -07005155 wakeUp(SystemClock.uptimeMillis(), mAllowTheaterModeWakeFromLidSwitch,
5156 "android.policy:LID");
Jeff Brownc458ce92012-04-30 14:58:40 -07005157 } else if (!mLidControlsSleep) {
Jeff Brown96307042012-07-27 15:51:34 -07005158 mPowerManager.userActivity(SystemClock.uptimeMillis(), false);
Jeff Brown46b9ac02010-04-22 18:58:52 -07005159 }
5160 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005161
Michael Wright3818c922014-09-02 13:59:07 -07005162 @Override
5163 public void notifyCameraLensCoverSwitchChanged(long whenNanos, boolean lensCovered) {
5164 int lensCoverState = lensCovered ? CAMERA_LENS_COVERED : CAMERA_LENS_UNCOVERED;
5165 if (mCameraLensCoverState == lensCoverState) {
5166 return;
5167 }
5168 if (mCameraLensCoverState == CAMERA_LENS_COVERED &&
5169 lensCoverState == CAMERA_LENS_UNCOVERED) {
5170 Intent intent;
5171 final boolean keyguardActive = mKeyguardDelegate == null ? false :
5172 mKeyguardDelegate.isShowing();
5173 if (keyguardActive) {
5174 intent = new Intent(MediaStore.INTENT_ACTION_STILL_IMAGE_CAMERA_SECURE);
5175 } else {
5176 intent = new Intent(MediaStore.INTENT_ACTION_STILL_IMAGE_CAMERA);
5177 }
Dianne Hackborn280a64e2015-07-13 14:48:08 -07005178 wakeUp(whenNanos / 1000000, mAllowTheaterModeWakeFromCameraLens,
5179 "android.policy:CAMERA_COVER");
Bart Sears8b1c27c2015-03-18 23:51:02 +00005180 startActivityAsUser(intent, UserHandle.CURRENT_OR_SELF);
Michael Wright3818c922014-09-02 13:59:07 -07005181 }
5182 mCameraLensCoverState = lensCoverState;
5183 }
5184
Dianne Hackbornad7fa7f2011-01-07 14:06:50 -08005185 void setHdmiPlugged(boolean plugged) {
5186 if (mHdmiPlugged != plugged) {
5187 mHdmiPlugged = plugged;
Dianne Hackbornf87d1962012-04-04 12:48:24 -07005188 updateRotation(true, true);
Dianne Hackbornad7fa7f2011-01-07 14:06:50 -08005189 Intent intent = new Intent(ACTION_HDMI_PLUGGED);
Joe Onoratodc100302011-01-11 17:07:41 -08005190 intent.addFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY_BEFORE_BOOT);
Dianne Hackbornad7fa7f2011-01-07 14:06:50 -08005191 intent.putExtra(EXTRA_HDMI_PLUGGED_STATE, plugged);
Dianne Hackborn5ac72a22012-08-29 18:32:08 -07005192 mContext.sendStickyBroadcastAsUser(intent, UserHandle.ALL);
Dianne Hackbornad7fa7f2011-01-07 14:06:50 -08005193 }
5194 }
5195
Joe Onoratoea495d42011-04-06 11:41:11 -07005196 void initializeHdmiState() {
Joe Onorato7ba631f2011-05-04 15:28:00 -07005197 boolean plugged = false;
Joe Onoratoea495d42011-04-06 11:41:11 -07005198 // watch for HDMI plug messages if the hdmi switch exists
5199 if (new File("/sys/devices/virtual/switch/hdmi/state").exists()) {
5200 mHDMIObserver.startObserving("DEVPATH=/devices/virtual/switch/hdmi");
5201
Joe Onoratoea495d42011-04-06 11:41:11 -07005202 final String filename = "/sys/class/switch/hdmi/state";
5203 FileReader reader = null;
5204 try {
5205 reader = new FileReader(filename);
5206 char[] buf = new char[15];
5207 int n = reader.read(buf);
5208 if (n > 1) {
5209 plugged = 0 != Integer.parseInt(new String(buf, 0, n-1));
5210 }
5211 } catch (IOException ex) {
5212 Slog.w(TAG, "Couldn't read hdmi state from " + filename + ": " + ex);
5213 } catch (NumberFormatException ex) {
5214 Slog.w(TAG, "Couldn't read hdmi state from " + filename + ": " + ex);
5215 } finally {
5216 if (reader != null) {
5217 try {
5218 reader.close();
5219 } catch (IOException ex) {
5220 }
Joe Onoratodc100302011-01-11 17:07:41 -08005221 }
5222 }
5223 }
Joe Onorato7ba631f2011-05-04 15:28:00 -07005224 // This dance forces the code in setHdmiPlugged to run.
5225 // Always do this so the sticky intent is stuck (to false) if there is no hdmi.
5226 mHdmiPlugged = !plugged;
5227 setHdmiPlugged(!mHdmiPlugged);
Joe Onoratodc100302011-01-11 17:07:41 -08005228 }
5229
Dianne Hackbornc0e3f242011-08-19 14:19:10 -07005230 final Object mScreenshotLock = new Object();
Dianne Hackbornfc8fa632011-08-17 16:20:47 -07005231 ServiceConnection mScreenshotConnection = null;
Dianne Hackbornfc8fa632011-08-17 16:20:47 -07005232
Jeff Brownd5bb82d2011-10-12 13:57:59 -07005233 final Runnable mScreenshotTimeout = new Runnable() {
5234 @Override public void run() {
5235 synchronized (mScreenshotLock) {
5236 if (mScreenshotConnection != null) {
5237 mContext.unbindService(mScreenshotConnection);
5238 mScreenshotConnection = null;
Winson44dbe292016-03-10 14:00:14 -08005239 notifyScreenshotError();
Dianne Hackbornfc8fa632011-08-17 16:20:47 -07005240 }
Winson Chung9112ec32011-06-27 13:15:32 -07005241 }
Jeff Brownd5bb82d2011-10-12 13:57:59 -07005242 }
5243 };
5244
5245 // Assume this is called from the Handler thread.
Muyuan Li6ca619f2016-03-08 13:30:42 -08005246 private void takeScreenshot(final int screenshotType) {
Jeff Brownd5bb82d2011-10-12 13:57:59 -07005247 synchronized (mScreenshotLock) {
5248 if (mScreenshotConnection != null) {
5249 return;
5250 }
Winson44dbe292016-03-10 14:00:14 -08005251 final ComponentName serviceComponent = new ComponentName(SYSUI_PACKAGE,
5252 SYSUI_SCREENSHOT_SERVICE);
5253 final Intent serviceIntent = new Intent();
5254 serviceIntent.setComponent(serviceComponent);
Jeff Brownd5bb82d2011-10-12 13:57:59 -07005255 ServiceConnection conn = new ServiceConnection() {
5256 @Override
5257 public void onServiceConnected(ComponentName name, IBinder service) {
5258 synchronized (mScreenshotLock) {
5259 if (mScreenshotConnection != this) {
5260 return;
5261 }
5262 Messenger messenger = new Messenger(service);
Muyuan Li6ca619f2016-03-08 13:30:42 -08005263 Message msg = Message.obtain(null, screenshotType);
Jeff Brownd5bb82d2011-10-12 13:57:59 -07005264 final ServiceConnection myConn = this;
5265 Handler h = new Handler(mHandler.getLooper()) {
5266 @Override
5267 public void handleMessage(Message msg) {
5268 synchronized (mScreenshotLock) {
5269 if (mScreenshotConnection == myConn) {
5270 mContext.unbindService(mScreenshotConnection);
5271 mScreenshotConnection = null;
5272 mHandler.removeCallbacks(mScreenshotTimeout);
5273 }
5274 }
5275 }
5276 };
5277 msg.replyTo = new Messenger(h);
Winson Chunga63bb842011-10-17 10:26:28 -07005278 msg.arg1 = msg.arg2 = 0;
5279 if (mStatusBar != null && mStatusBar.isVisibleLw())
5280 msg.arg1 = 1;
5281 if (mNavigationBar != null && mNavigationBar.isVisibleLw())
5282 msg.arg2 = 1;
Jeff Brownd5bb82d2011-10-12 13:57:59 -07005283 try {
5284 messenger.send(msg);
5285 } catch (RemoteException e) {
5286 }
5287 }
5288 }
Winson44dbe292016-03-10 14:00:14 -08005289
Jeff Brownd5bb82d2011-10-12 13:57:59 -07005290 @Override
Winson44dbe292016-03-10 14:00:14 -08005291 public void onServiceDisconnected(ComponentName name) {
5292 notifyScreenshotError();
5293 }
Jeff Brownd5bb82d2011-10-12 13:57:59 -07005294 };
Winson44dbe292016-03-10 14:00:14 -08005295 if (mContext.bindServiceAsUser(serviceIntent, conn,
5296 Context.BIND_AUTO_CREATE | Context.BIND_FOREGROUND_SERVICE_WHILE_AWAKE,
5297 UserHandle.CURRENT)) {
Jeff Brownd5bb82d2011-10-12 13:57:59 -07005298 mScreenshotConnection = conn;
5299 mHandler.postDelayed(mScreenshotTimeout, 10000);
5300 }
5301 }
Winson Chung9112ec32011-06-27 13:15:32 -07005302 }
5303
Winson44dbe292016-03-10 14:00:14 -08005304 /**
5305 * Notifies the screenshot service to show an error.
5306 */
5307 private void notifyScreenshotError() {
5308 // If the service process is killed, then ask it to clean up after itself
5309 final ComponentName errorComponent = new ComponentName(SYSUI_PACKAGE,
5310 SYSUI_SCREENSHOT_ERROR_RECEIVER);
5311 Intent errorIntent = new Intent();
5312 errorIntent.setComponent(errorComponent);
5313 errorIntent.addFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY_BEFORE_BOOT |
5314 Intent.FLAG_RECEIVER_FOREGROUND);
5315 mContext.sendBroadcastAsUser(errorIntent, UserHandle.ALL);
5316 }
5317
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005318 /** {@inheritDoc} */
Jeff Brown00fa7bd2010-07-02 15:37:36 -07005319 @Override
Jeff Brown037c33e2014-04-09 00:31:55 -07005320 public int interceptKeyBeforeQueueing(KeyEvent event, int policyFlags) {
Jeff Brown96307042012-07-27 15:51:34 -07005321 if (!mSystemBooted) {
5322 // If we have not yet booted, don't let key events do anything.
5323 return 0;
5324 }
5325
Jeff Brown037c33e2014-04-09 00:31:55 -07005326 final boolean interactive = (policyFlags & FLAG_INTERACTIVE) != 0;
Jeff Brown1f245102010-11-18 20:53:46 -08005327 final boolean down = event.getAction() == KeyEvent.ACTION_DOWN;
5328 final boolean canceled = event.isCanceled();
5329 final int keyCode = event.getKeyCode();
Jeff Browne20c9e02010-10-11 14:20:19 -07005330
Jeff Brown3122e442010-10-11 23:32:49 -07005331 final boolean isInjected = (policyFlags & WindowManagerPolicy.FLAG_INJECTED) != 0;
Jeff Brown3122e442010-10-11 23:32:49 -07005332
Mike Lockwoodc72b15f2009-11-28 20:58:22 -05005333 // If screen is off then we treat the case where the keyguard is open but hidden
5334 // the same as if it were open and in front.
5335 // This will prevent any keys other than the power button from waking the screen
5336 // when the keyguard is hidden by another activity.
Jim Miller5ecd8112013-01-09 18:50:26 -08005337 final boolean keyguardActive = (mKeyguardDelegate == null ? false :
Jeff Brown037c33e2014-04-09 00:31:55 -07005338 (interactive ?
Jim Millerab954542014-10-10 18:21:49 -07005339 isKeyguardShowingAndNotOccluded() :
Jim Miller5ecd8112013-01-09 18:50:26 -08005340 mKeyguardDelegate.isShowing()));
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005341
Jeff Brown40013652012-05-16 21:22:36 -07005342 if (DEBUG_INPUT) {
Jeff Brown00fa7bd2010-07-02 15:37:36 -07005343 Log.d(TAG, "interceptKeyTq keycode=" + keyCode
Jeff Brown037c33e2014-04-09 00:31:55 -07005344 + " interactive=" + interactive + " keyguardActive=" + keyguardActive
Jeff Brown26875502014-01-30 21:47:47 -08005345 + " policyFlags=" + Integer.toHexString(policyFlags));
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005346 }
5347
Jeff Brown037c33e2014-04-09 00:31:55 -07005348 // Basic policy based on interactive state.
Jeff Brown4d396052010-10-29 21:50:21 -07005349 int result;
Michael Wright337d9d22014-04-22 15:03:48 -07005350 boolean isWakeKey = (policyFlags & WindowManagerPolicy.FLAG_WAKE) != 0
5351 || event.isWakeKey();
Michael Wrightfc01f042014-09-08 14:12:24 -07005352 if (interactive || (isInjected && !isWakeKey)) {
RoboErikde9ba392014-09-26 12:51:01 -07005353 // When the device is interactive or the key is injected pass the
5354 // key to the application.
Jeff Brown4d396052010-10-29 21:50:21 -07005355 result = ACTION_PASS_TO_USER;
Jose Lima9546b202014-07-02 17:21:51 -07005356 isWakeKey = false;
Michael Wrightfc01f042014-09-08 14:12:24 -07005357 } else if (!interactive && shouldDispatchInputWhenNonInteractive()) {
5358 // If we're currently dozing with the screen on and the keyguard showing, pass the key
5359 // to the application but preserve its wake key status to make sure we still move
5360 // from dozing to fully interactive if we would normally go from off to fully
5361 // interactive.
5362 result = ACTION_PASS_TO_USER;
Jeff Brown4d396052010-10-29 21:50:21 -07005363 } else {
5364 // When the screen is off and the key is not injected, determine whether
5365 // to wake the device but don't pass the key to the application.
5366 result = 0;
Jeff Brown26875502014-01-30 21:47:47 -08005367 if (isWakeKey && (!down || !isWakeKeyWhenScreenOff(keyCode))) {
5368 isWakeKey = false;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005369 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005370 }
5371
Justin Kohd378ad72013-04-01 12:18:26 -07005372 // If the key would be handled globally, just return the result, don't worry about special
5373 // key processing.
Jeff Brown13f00f02014-10-31 14:45:50 -07005374 if (isValidGlobalKey(keyCode)
5375 && mGlobalKeyManager.shouldHandleGlobalKey(keyCode, event)) {
Michael Wright85b1af62014-06-04 14:51:58 -07005376 if (isWakeKey) {
Dianne Hackborn280a64e2015-07-13 14:48:08 -07005377 wakeUp(event.getEventTime(), mAllowTheaterModeWakeFromKey, "android.policy:KEY");
Michael Wright85b1af62014-06-04 14:51:58 -07005378 }
Justin Kohd378ad72013-04-01 12:18:26 -07005379 return result;
5380 }
5381
Jeff Brownbae8e772014-06-12 19:59:45 -07005382 boolean useHapticFeedback = down
5383 && (policyFlags & WindowManagerPolicy.FLAG_VIRTUAL) != 0
5384 && event.getRepeatCount() == 0;
5385
Jeff Brown4d396052010-10-29 21:50:21 -07005386 // Handle special keys.
5387 switch (keyCode) {
Anthony Hugh34f09ca2016-03-04 12:03:37 -08005388 case KeyEvent.KEYCODE_BACK: {
5389 if (down) {
5390 mBackKeyHandled = false;
5391 if (hasLongPressOnBackBehavior()) {
5392 Message msg = mHandler.obtainMessage(MSG_BACK_LONG_PRESS);
5393 msg.setAsynchronous(true);
5394 mHandler.sendMessageDelayed(msg,
5395 ViewConfiguration.get(mContext).getDeviceGlobalActionKeyTimeout());
5396 }
5397 } else {
5398 boolean handled = mBackKeyHandled;
5399
5400 // Reset back key state
5401 cancelPendingBackKeyAction();
5402
5403 // Don't pass back press to app if we've already handled it
5404 if (handled) {
5405 result &= ~ACTION_PASS_TO_USER;
5406 }
5407 }
5408 break;
5409 }
5410
Jeff Brown4d396052010-10-29 21:50:21 -07005411 case KeyEvent.KEYCODE_VOLUME_DOWN:
Jeff Brownb0418da2010-11-01 15:24:01 -07005412 case KeyEvent.KEYCODE_VOLUME_UP:
5413 case KeyEvent.KEYCODE_VOLUME_MUTE: {
Jeff Brownd5bb82d2011-10-12 13:57:59 -07005414 if (keyCode == KeyEvent.KEYCODE_VOLUME_DOWN) {
5415 if (down) {
Jeff Brown13f00f02014-10-31 14:45:50 -07005416 if (interactive && !mScreenshotChordVolumeDownKeyTriggered
Jeff Brownd5bb82d2011-10-12 13:57:59 -07005417 && (event.getFlags() & KeyEvent.FLAG_FALLBACK) == 0) {
Jeff Brown13f00f02014-10-31 14:45:50 -07005418 mScreenshotChordVolumeDownKeyTriggered = true;
5419 mScreenshotChordVolumeDownKeyTime = event.getDownTime();
5420 mScreenshotChordVolumeDownKeyConsumed = false;
Jeff Brownd5bb82d2011-10-12 13:57:59 -07005421 cancelPendingPowerKeyAction();
5422 interceptScreenshotChord();
5423 }
5424 } else {
Jeff Brown13f00f02014-10-31 14:45:50 -07005425 mScreenshotChordVolumeDownKeyTriggered = false;
Jeff Brownd5bb82d2011-10-12 13:57:59 -07005426 cancelPendingScreenshotChordAction();
5427 }
5428 } else if (keyCode == KeyEvent.KEYCODE_VOLUME_UP) {
5429 if (down) {
Jeff Brown13f00f02014-10-31 14:45:50 -07005430 if (interactive && !mScreenshotChordVolumeUpKeyTriggered
Jeff Brownd5bb82d2011-10-12 13:57:59 -07005431 && (event.getFlags() & KeyEvent.FLAG_FALLBACK) == 0) {
Jeff Brown13f00f02014-10-31 14:45:50 -07005432 mScreenshotChordVolumeUpKeyTriggered = true;
Jeff Brownd5bb82d2011-10-12 13:57:59 -07005433 cancelPendingPowerKeyAction();
5434 cancelPendingScreenshotChordAction();
5435 }
5436 } else {
Jeff Brown13f00f02014-10-31 14:45:50 -07005437 mScreenshotChordVolumeUpKeyTriggered = false;
Jeff Brownd5bb82d2011-10-12 13:57:59 -07005438 cancelPendingScreenshotChordAction();
5439 }
5440 }
Jeff Brown4d396052010-10-29 21:50:21 -07005441 if (down) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -07005442 TelecomManager telecomManager = getTelecommService();
5443 if (telecomManager != null) {
5444 if (telecomManager.isRinging()) {
Santos Cordon6848f722014-05-21 15:22:12 -07005445 // If an incoming call is ringing, either VOLUME key means
5446 // "silence ringer". We handle these keys here, rather than
5447 // in the InCallScreen, to make sure we'll respond to them
5448 // even if the InCallScreen hasn't come to the foreground yet.
5449 // Look for the DOWN event here, to agree with the "fallback"
5450 // behavior in the InCallScreen.
5451 Log.i(TAG, "interceptKeyBeforeQueueing:"
5452 + " VOLUME key-down while ringing: Silence ringer!");
Jeff Brown4d396052010-10-29 21:50:21 -07005453
Santos Cordon6848f722014-05-21 15:22:12 -07005454 // Silence the ringer. (It's safe to call this
5455 // even if the ringer has already been silenced.)
Tyler Gunnef9f6f92014-09-12 22:16:17 -07005456 telecomManager.silenceRinger();
Jeff Brown4d396052010-10-29 21:50:21 -07005457
Santos Cordon6848f722014-05-21 15:22:12 -07005458 // And *don't* pass this key thru to the current activity
5459 // (which is probably the InCallScreen.)
5460 result &= ~ACTION_PASS_TO_USER;
5461 break;
5462 }
Tyler Gunnef9f6f92014-09-12 22:16:17 -07005463 if (telecomManager.isInCall()
Santos Cordon6848f722014-05-21 15:22:12 -07005464 && (result & ACTION_PASS_TO_USER) == 0) {
5465 // If we are in call but we decided not to pass the key to
RoboErik430fc482014-06-12 15:49:20 -07005466 // the application, just pass it to the session service.
5467
5468 MediaSessionLegacyHelper.getHelper(mContext)
RoboErik3c45c292014-07-08 16:47:31 -07005469 .sendVolumeKeyEvent(event, false);
Santos Cordon6848f722014-05-21 15:22:12 -07005470 break;
Jeff Brown4d396052010-10-29 21:50:21 -07005471 }
5472 }
Jaewan Kim765487f2016-01-12 14:45:42 +09005473 }
5474 if (mUseTvRouting) {
5475 // On TVs, defer special key handlings to
5476 // {@link interceptKeyBeforeDispatching()}.
5477 result |= ACTION_PASS_TO_USER;
5478 } else if ((result & ACTION_PASS_TO_USER) == 0) {
5479 // If we aren't passing to the user and no one else
5480 // handled it send it to the session manager to
5481 // figure out.
5482 MediaSessionLegacyHelper.getHelper(mContext)
5483 .sendVolumeKeyEvent(event, true);
Jeff Brown4d396052010-10-29 21:50:21 -07005484 }
5485 break;
5486 }
5487
5488 case KeyEvent.KEYCODE_ENDCALL: {
5489 result &= ~ACTION_PASS_TO_USER;
5490 if (down) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -07005491 TelecomManager telecomManager = getTelecommService();
Jeff Brown4d396052010-10-29 21:50:21 -07005492 boolean hungUp = false;
Tyler Gunnef9f6f92014-09-12 22:16:17 -07005493 if (telecomManager != null) {
5494 hungUp = telecomManager.endCall();
Jeff Brown4d396052010-10-29 21:50:21 -07005495 }
Jeff Brown13f00f02014-10-31 14:45:50 -07005496 if (interactive && !hungUp) {
5497 mEndCallKeyHandled = false;
5498 mHandler.postDelayed(mEndCallLongPress,
5499 ViewConfiguration.get(mContext).getDeviceGlobalActionKeyTimeout());
5500 } else {
5501 mEndCallKeyHandled = true;
5502 }
Jeff Brown4d396052010-10-29 21:50:21 -07005503 } else {
Jeff Brown13f00f02014-10-31 14:45:50 -07005504 if (!mEndCallKeyHandled) {
5505 mHandler.removeCallbacks(mEndCallLongPress);
5506 if (!canceled) {
5507 if ((mEndcallBehavior
5508 & Settings.System.END_BUTTON_BEHAVIOR_HOME) != 0) {
5509 if (goHome()) {
5510 break;
5511 }
Dianne Hackborn0041e972009-07-24 17:14:43 -07005512 }
Jeff Brown13f00f02014-10-31 14:45:50 -07005513 if ((mEndcallBehavior
5514 & Settings.System.END_BUTTON_BEHAVIOR_SLEEP) != 0) {
5515 mPowerManager.goToSleep(event.getEventTime(),
5516 PowerManager.GO_TO_SLEEP_REASON_POWER_BUTTON, 0);
5517 isWakeKey = false;
5518 }
Jeff Brown4d396052010-10-29 21:50:21 -07005519 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005520 }
Jeff Brown4d396052010-10-29 21:50:21 -07005521 }
5522 break;
5523 }
5524
5525 case KeyEvent.KEYCODE_POWER: {
5526 result &= ~ACTION_PASS_TO_USER;
Jeff Brown13f00f02014-10-31 14:45:50 -07005527 isWakeKey = false; // wake-up will be handled separately
Jeff Brown4d396052010-10-29 21:50:21 -07005528 if (down) {
Jeff Brown13f00f02014-10-31 14:45:50 -07005529 interceptPowerKeyDown(event, interactive);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005530 } else {
Jeff Brown13f00f02014-10-31 14:45:50 -07005531 interceptPowerKeyUp(event, interactive, canceled);
Jeff Brown4d396052010-10-29 21:50:21 -07005532 }
5533 break;
5534 }
5535
Jeff Brown6212a492014-03-07 13:58:47 -08005536 case KeyEvent.KEYCODE_SLEEP: {
5537 result &= ~ACTION_PASS_TO_USER;
Filip Gruszczynskia483a1d2015-03-17 19:06:58 +00005538 isWakeKey = false;
Jeff Brownbae8e772014-06-12 19:59:45 -07005539 if (!mPowerManager.isInteractive()) {
5540 useHapticFeedback = false; // suppress feedback if already non-interactive
5541 }
Nick Vaccarob593a812015-05-15 11:23:05 -07005542 if (down) {
5543 sleepPress(event.getEventTime());
5544 } else {
5545 sleepRelease(event.getEventTime());
5546 }
Jeff Brown6212a492014-03-07 13:58:47 -08005547 break;
5548 }
5549
Nick Armstrong-Crews56ecfcc2015-09-07 21:46:50 -07005550 case KeyEvent.KEYCODE_SOFT_SLEEP: {
5551 result &= ~ACTION_PASS_TO_USER;
5552 isWakeKey = false;
5553 if (!down) {
5554 mPowerManagerInternal.setUserInactiveOverrideFromWindowManager();
5555 }
5556 break;
5557 }
5558
Jeff Brown6212a492014-03-07 13:58:47 -08005559 case KeyEvent.KEYCODE_WAKEUP: {
5560 result &= ~ACTION_PASS_TO_USER;
Jose Lima9546b202014-07-02 17:21:51 -07005561 isWakeKey = true;
Jeff Brown6212a492014-03-07 13:58:47 -08005562 break;
5563 }
5564
Jeff Brown4d396052010-10-29 21:50:21 -07005565 case KeyEvent.KEYCODE_MEDIA_PLAY:
5566 case KeyEvent.KEYCODE_MEDIA_PAUSE:
5567 case KeyEvent.KEYCODE_MEDIA_PLAY_PAUSE:
Jeff Brown4d396052010-10-29 21:50:21 -07005568 case KeyEvent.KEYCODE_HEADSETHOOK:
5569 case KeyEvent.KEYCODE_MUTE:
5570 case KeyEvent.KEYCODE_MEDIA_STOP:
5571 case KeyEvent.KEYCODE_MEDIA_NEXT:
5572 case KeyEvent.KEYCODE_MEDIA_PREVIOUS:
5573 case KeyEvent.KEYCODE_MEDIA_REWIND:
5574 case KeyEvent.KEYCODE_MEDIA_RECORD:
Jaekyun Seokbfdad8e2013-07-08 13:53:21 +09005575 case KeyEvent.KEYCODE_MEDIA_FAST_FORWARD:
5576 case KeyEvent.KEYCODE_MEDIA_AUDIO_TRACK: {
RoboErikde9ba392014-09-26 12:51:01 -07005577 if (MediaSessionLegacyHelper.getHelper(mContext).isGlobalPriorityActive()) {
5578 // If the global session is active pass all media keys to it
5579 // instead of the active window.
5580 result &= ~ACTION_PASS_TO_USER;
5581 }
Jeff Brown4d396052010-10-29 21:50:21 -07005582 if ((result & ACTION_PASS_TO_USER) == 0) {
5583 // Only do this if we would otherwise not pass it to the user. In that
5584 // case, the PhoneWindow class will do the same thing, except it will
5585 // only do it if the showing app doesn't process the key on its own.
Jeff Brown40013652012-05-16 21:22:36 -07005586 // Note that we need to make a copy of the key event here because the
5587 // original key event will be recycled when we return.
Jeff Brown4d396052010-10-29 21:50:21 -07005588 mBroadcastWakeLock.acquire();
Jeff Brown40013652012-05-16 21:22:36 -07005589 Message msg = mHandler.obtainMessage(MSG_DISPATCH_MEDIA_KEY_WITH_WAKE_LOCK,
5590 new KeyEvent(event));
5591 msg.setAsynchronous(true);
5592 msg.sendToTarget();
Jeff Brown4d396052010-10-29 21:50:21 -07005593 }
5594 break;
Jeff Brown00fa7bd2010-07-02 15:37:36 -07005595 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005596
Jeff Brown4d396052010-10-29 21:50:21 -07005597 case KeyEvent.KEYCODE_CALL: {
5598 if (down) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -07005599 TelecomManager telecomManager = getTelecommService();
5600 if (telecomManager != null) {
5601 if (telecomManager.isRinging()) {
Santos Cordon6848f722014-05-21 15:22:12 -07005602 Log.i(TAG, "interceptKeyBeforeQueueing:"
5603 + " CALL key-down while ringing: Answer the call!");
Tyler Gunnef9f6f92014-09-12 22:16:17 -07005604 telecomManager.acceptRingingCall();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005605
Santos Cordon6848f722014-05-21 15:22:12 -07005606 // And *don't* pass this key thru to the current activity
5607 // (which is presumably the InCallScreen.)
5608 result &= ~ACTION_PASS_TO_USER;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005609 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005610 }
Jeff Brown00fa7bd2010-07-02 15:37:36 -07005611 }
Jeff Brown4d396052010-10-29 21:50:21 -07005612 break;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005613 }
Michael Wright869a67c2014-08-26 19:33:06 -07005614 case KeyEvent.KEYCODE_VOICE_ASSIST: {
5615 // Only do this if we would otherwise not pass it to the user. In that case,
5616 // interceptKeyBeforeDispatching would apply a similar but different policy in
5617 // order to invoke voice assist actions. Note that we need to make a copy of the
5618 // key event here because the original key event will be recycled when we return.
5619 if ((result & ACTION_PASS_TO_USER) == 0 && !down) {
5620 mBroadcastWakeLock.acquire();
5621 Message msg = mHandler.obtainMessage(MSG_LAUNCH_VOICE_ASSIST_WITH_WAKE_LOCK,
5622 keyguardActive ? 1 : 0, 0);
5623 msg.setAsynchronous(true);
5624 msg.sendToTarget();
5625 }
Jaewan Kim49117872016-01-19 17:24:08 +09005626 break;
5627 }
5628 case KeyEvent.KEYCODE_WINDOW: {
5629 if (mShortPressWindowBehavior == SHORT_PRESS_WINDOW_PICTURE_IN_PICTURE) {
5630 if (!down) {
Jaewan Kimc552b042016-01-18 16:08:45 +09005631 requestTvPictureInPicture(event);
Jaewan Kim49117872016-01-19 17:24:08 +09005632 }
5633 result &= ~ACTION_PASS_TO_USER;
5634 }
5635 break;
Michael Wright869a67c2014-08-26 19:33:06 -07005636 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005637 }
Jeff Brown26875502014-01-30 21:47:47 -08005638
Jeff Brownbae8e772014-06-12 19:59:45 -07005639 if (useHapticFeedback) {
5640 performHapticFeedbackLw(null, HapticFeedbackConstants.VIRTUAL_KEY, false);
5641 }
5642
Jeff Brown26875502014-01-30 21:47:47 -08005643 if (isWakeKey) {
Dianne Hackborn280a64e2015-07-13 14:48:08 -07005644 wakeUp(event.getEventTime(), mAllowTheaterModeWakeFromKey, "android.policy:KEY");
Jeff Brown26875502014-01-30 21:47:47 -08005645 }
Bryce Lee584a4452014-10-21 15:55:55 -07005646
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005647 return result;
5648 }
5649
Jeff Brown1c2e4942012-11-06 16:32:01 -08005650 /**
Jeff Brown13f00f02014-10-31 14:45:50 -07005651 * Returns true if the key can have global actions attached to it.
5652 * We reserve all power management keys for the system since they require
5653 * very careful handling.
5654 */
5655 private static boolean isValidGlobalKey(int keyCode) {
5656 switch (keyCode) {
5657 case KeyEvent.KEYCODE_POWER:
5658 case KeyEvent.KEYCODE_WAKEUP:
5659 case KeyEvent.KEYCODE_SLEEP:
5660 return false;
5661 default:
5662 return true;
5663 }
5664 }
5665
5666 /**
Jeff Brown1c2e4942012-11-06 16:32:01 -08005667 * When the screen is off we ignore some keys that might otherwise typically
5668 * be considered wake keys. We filter them out here.
5669 *
5670 * {@link KeyEvent#KEYCODE_POWER} is notably absent from this list because it
5671 * is always considered a wake key.
5672 */
5673 private boolean isWakeKeyWhenScreenOff(int keyCode) {
5674 switch (keyCode) {
5675 // ignore volume keys unless docked
5676 case KeyEvent.KEYCODE_VOLUME_UP:
5677 case KeyEvent.KEYCODE_VOLUME_DOWN:
5678 case KeyEvent.KEYCODE_VOLUME_MUTE:
5679 return mDockMode != Intent.EXTRA_DOCK_STATE_UNDOCKED;
5680
5681 // ignore media and camera keys
5682 case KeyEvent.KEYCODE_MUTE:
5683 case KeyEvent.KEYCODE_HEADSETHOOK:
5684 case KeyEvent.KEYCODE_MEDIA_PLAY:
5685 case KeyEvent.KEYCODE_MEDIA_PAUSE:
5686 case KeyEvent.KEYCODE_MEDIA_PLAY_PAUSE:
5687 case KeyEvent.KEYCODE_MEDIA_STOP:
5688 case KeyEvent.KEYCODE_MEDIA_NEXT:
5689 case KeyEvent.KEYCODE_MEDIA_PREVIOUS:
5690 case KeyEvent.KEYCODE_MEDIA_REWIND:
5691 case KeyEvent.KEYCODE_MEDIA_RECORD:
5692 case KeyEvent.KEYCODE_MEDIA_FAST_FORWARD:
Jaekyun Seokbfdad8e2013-07-08 13:53:21 +09005693 case KeyEvent.KEYCODE_MEDIA_AUDIO_TRACK:
Jeff Brown1c2e4942012-11-06 16:32:01 -08005694 case KeyEvent.KEYCODE_CAMERA:
5695 return false;
5696 }
5697 return true;
5698 }
5699
5700
Jeff Brown56194eb2011-03-02 19:23:13 -08005701 /** {@inheritDoc} */
5702 @Override
Michael Wright70af00a2014-09-03 19:30:20 -07005703 public int interceptMotionBeforeQueueingNonInteractive(long whenNanos, int policyFlags) {
5704 if ((policyFlags & FLAG_WAKE) != 0) {
Dianne Hackborn280a64e2015-07-13 14:48:08 -07005705 if (wakeUp(whenNanos / 1000000, mAllowTheaterModeWakeFromMotion,
5706 "android.policy:MOTION")) {
Bryce Lee5c138322014-11-03 08:26:09 -08005707 return 0;
5708 }
Michael Wright70af00a2014-09-03 19:30:20 -07005709 }
Bryce Lee5c138322014-11-03 08:26:09 -08005710
Michael Wright70af00a2014-09-03 19:30:20 -07005711 if (shouldDispatchInputWhenNonInteractive()) {
5712 return ACTION_PASS_TO_USER;
5713 }
Bryce Lee5c138322014-11-03 08:26:09 -08005714
Bryce Lee812d7022014-11-10 13:33:28 -08005715 // If we have not passed the action up and we are in theater mode without dreaming,
5716 // there will be no dream to intercept the touch and wake into ambient. The device should
5717 // wake up in this case.
5718 if (isTheaterModeEnabled() && (policyFlags & FLAG_WAKE) != 0) {
Dianne Hackborn280a64e2015-07-13 14:48:08 -07005719 wakeUp(whenNanos / 1000000, mAllowTheaterModeWakeFromMotionWhenNotDreaming,
5720 "android.policy:MOTION");
Bryce Lee812d7022014-11-10 13:33:28 -08005721 }
5722
Jeff Brown037c33e2014-04-09 00:31:55 -07005723 return 0;
Jeff Brown56194eb2011-03-02 19:23:13 -08005724 }
5725
Michael Wright70af00a2014-09-03 19:30:20 -07005726 private boolean shouldDispatchInputWhenNonInteractive() {
Joe LaPennaf2b9b2d2015-11-17 22:22:37 +00005727 // Send events to keyguard while the screen is on.
5728 if (isKeyguardShowingAndNotOccluded() && mDisplay != null
5729 && mDisplay.getState() != Display.STATE_OFF) {
Bryce Lee5c138322014-11-03 08:26:09 -08005730 return true;
5731 }
5732
5733 // Send events to a dozing dream even if the screen is off since the dream
5734 // is in control of the state of the screen.
5735 IDreamManager dreamManager = getDreamManager();
5736
5737 try {
5738 if (dreamManager != null && dreamManager.isDreaming()) {
5739 return true;
5740 }
5741 } catch (RemoteException e) {
5742 Slog.e(TAG, "RemoteException when checking if dreaming", e);
5743 }
5744
5745 // Otherwise, consume events since the user can't see what is being
5746 // interacted with.
5747 return false;
Michael Wright70af00a2014-09-03 19:30:20 -07005748 }
5749
RoboErik001c59c2015-01-26 15:53:51 -08005750 private void dispatchDirectAudioEvent(KeyEvent event) {
5751 if (event.getAction() != KeyEvent.ACTION_DOWN) {
5752 return;
5753 }
5754 int keyCode = event.getKeyCode();
John Spurlockb94f2d62015-03-17 14:11:57 -04005755 int flags = AudioManager.FLAG_SHOW_UI | AudioManager.FLAG_PLAY_SOUND
5756 | AudioManager.FLAG_FROM_KEY;
RoboErik001c59c2015-01-26 15:53:51 -08005757 String pkgName = mContext.getOpPackageName();
5758 switch (keyCode) {
5759 case KeyEvent.KEYCODE_VOLUME_UP:
5760 try {
John Spurlockee5ad722015-03-03 16:17:21 -05005761 getAudioService().adjustSuggestedStreamVolume(AudioManager.ADJUST_RAISE,
John Spurlock90874332015-03-10 16:00:54 -04005762 AudioManager.USE_DEFAULT_STREAM_TYPE, flags, pkgName, TAG);
RoboErik001c59c2015-01-26 15:53:51 -08005763 } catch (RemoteException e) {
5764 Log.e(TAG, "Error dispatching volume up in dispatchTvAudioEvent.", e);
5765 }
5766 break;
5767 case KeyEvent.KEYCODE_VOLUME_DOWN:
5768 try {
John Spurlockee5ad722015-03-03 16:17:21 -05005769 getAudioService().adjustSuggestedStreamVolume(AudioManager.ADJUST_LOWER,
John Spurlock90874332015-03-10 16:00:54 -04005770 AudioManager.USE_DEFAULT_STREAM_TYPE, flags, pkgName, TAG);
RoboErik001c59c2015-01-26 15:53:51 -08005771 } catch (RemoteException e) {
5772 Log.e(TAG, "Error dispatching volume down in dispatchTvAudioEvent.", e);
5773 }
5774 break;
5775 case KeyEvent.KEYCODE_VOLUME_MUTE:
5776 try {
5777 if (event.getRepeatCount() == 0) {
John Spurlockee5ad722015-03-03 16:17:21 -05005778 getAudioService().adjustSuggestedStreamVolume(
5779 AudioManager.ADJUST_TOGGLE_MUTE,
John Spurlock90874332015-03-10 16:00:54 -04005780 AudioManager.USE_DEFAULT_STREAM_TYPE, flags, pkgName, TAG);
RoboErik001c59c2015-01-26 15:53:51 -08005781 }
5782 } catch (RemoteException e) {
5783 Log.e(TAG, "Error dispatching mute in dispatchTvAudioEvent.", e);
5784 }
5785 break;
5786 }
5787 }
5788
Jeff Brown40013652012-05-16 21:22:36 -07005789 void dispatchMediaKeyWithWakeLock(KeyEvent event) {
5790 if (DEBUG_INPUT) {
5791 Slog.d(TAG, "dispatchMediaKeyWithWakeLock: " + event);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005792 }
5793
Jeff Brown40013652012-05-16 21:22:36 -07005794 if (mHavePendingMediaKeyRepeatWithWakeLock) {
5795 if (DEBUG_INPUT) {
5796 Slog.d(TAG, "dispatchMediaKeyWithWakeLock: canceled repeat");
5797 }
5798
5799 mHandler.removeMessages(MSG_DISPATCH_MEDIA_KEY_REPEAT_WITH_WAKE_LOCK);
5800 mHavePendingMediaKeyRepeatWithWakeLock = false;
5801 mBroadcastWakeLock.release(); // pending repeat was holding onto the wake lock
5802 }
5803
5804 dispatchMediaKeyWithWakeLockToAudioService(event);
5805
5806 if (event.getAction() == KeyEvent.ACTION_DOWN
5807 && event.getRepeatCount() == 0) {
5808 mHavePendingMediaKeyRepeatWithWakeLock = true;
5809
5810 Message msg = mHandler.obtainMessage(
5811 MSG_DISPATCH_MEDIA_KEY_REPEAT_WITH_WAKE_LOCK, event);
5812 msg.setAsynchronous(true);
5813 mHandler.sendMessageDelayed(msg, ViewConfiguration.getKeyRepeatTimeout());
5814 } else {
5815 mBroadcastWakeLock.release();
5816 }
5817 }
5818
5819 void dispatchMediaKeyRepeatWithWakeLock(KeyEvent event) {
5820 mHavePendingMediaKeyRepeatWithWakeLock = false;
5821
5822 KeyEvent repeatEvent = KeyEvent.changeTimeRepeat(event,
5823 SystemClock.uptimeMillis(), 1, event.getFlags() | KeyEvent.FLAG_LONG_PRESS);
5824 if (DEBUG_INPUT) {
5825 Slog.d(TAG, "dispatchMediaKeyRepeatWithWakeLock: " + repeatEvent);
5826 }
5827
5828 dispatchMediaKeyWithWakeLockToAudioService(repeatEvent);
5829 mBroadcastWakeLock.release();
5830 }
5831
5832 void dispatchMediaKeyWithWakeLockToAudioService(KeyEvent event) {
5833 if (ActivityManagerNative.isSystemReady()) {
RoboErik430fc482014-06-12 15:49:20 -07005834 MediaSessionLegacyHelper.getHelper(mContext).sendMediaButtonEvent(event, true);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005835 }
5836 }
5837
Michael Wright869a67c2014-08-26 19:33:06 -07005838 void launchVoiceAssistWithWakeLock(boolean keyguardActive) {
Dianne Hackbornb6683c42015-06-18 17:40:33 -07005839 IDeviceIdleController dic = IDeviceIdleController.Stub.asInterface(
5840 ServiceManager.getService(Context.DEVICE_IDLE_CONTROLLER));
5841 if (dic != null) {
5842 try {
5843 dic.exitIdle("voice-search");
5844 } catch (RemoteException e) {
5845 }
5846 }
Michael Wright869a67c2014-08-26 19:33:06 -07005847 Intent voiceIntent =
5848 new Intent(RecognizerIntent.ACTION_VOICE_SEARCH_HANDS_FREE);
5849 voiceIntent.putExtra(RecognizerIntent.EXTRA_SECURE, keyguardActive);
Bart Sears8b1c27c2015-03-18 23:51:02 +00005850 startActivityAsUser(voiceIntent, UserHandle.CURRENT_OR_SELF);
Michael Wright869a67c2014-08-26 19:33:06 -07005851 mBroadcastWakeLock.release();
5852 }
5853
Mike Lockwood1753f7f2009-08-24 14:49:07 -07005854 BroadcastReceiver mDockReceiver = new BroadcastReceiver() {
Craig Mautnereee29c42013-01-17 14:44:34 -08005855 @Override
Mike Lockwood1753f7f2009-08-24 14:49:07 -07005856 public void onReceive(Context context, Intent intent) {
Dianne Hackborn867ab6472010-04-29 13:28:56 -07005857 if (Intent.ACTION_DOCK_EVENT.equals(intent.getAction())) {
5858 mDockMode = intent.getIntExtra(Intent.EXTRA_DOCK_STATE,
5859 Intent.EXTRA_DOCK_STATE_UNDOCKED);
Daniel Sandler6396c722013-04-16 20:19:09 -04005860 } else {
5861 try {
5862 IUiModeManager uiModeService = IUiModeManager.Stub.asInterface(
5863 ServiceManager.getService(Context.UI_MODE_SERVICE));
5864 mUiMode = uiModeService.getCurrentModeType();
5865 } catch (RemoteException e) {
5866 }
Dianne Hackborn80fa1662009-10-07 14:02:10 -07005867 }
Jeff Brown01a98dd2011-09-20 15:08:29 -07005868 updateRotation(true);
Craig Mautnereee29c42013-01-17 14:44:34 -08005869 synchronized (mLock) {
5870 updateOrientationListenerLp();
5871 }
Mike Lockwood1753f7f2009-08-24 14:49:07 -07005872 }
5873 };
5874
Jeff Brown6aaf2952012-10-05 16:01:08 -07005875 BroadcastReceiver mDreamReceiver = new BroadcastReceiver() {
5876 @Override
5877 public void onReceive(Context context, Intent intent) {
5878 if (Intent.ACTION_DREAMING_STARTED.equals(intent.getAction())) {
Jim Miller5ecd8112013-01-09 18:50:26 -08005879 if (mKeyguardDelegate != null) {
5880 mKeyguardDelegate.onDreamingStarted();
Jeff Brown6aaf2952012-10-05 16:01:08 -07005881 }
5882 } else if (Intent.ACTION_DREAMING_STOPPED.equals(intent.getAction())) {
Jim Miller5ecd8112013-01-09 18:50:26 -08005883 if (mKeyguardDelegate != null) {
5884 mKeyguardDelegate.onDreamingStopped();
Jeff Brown6aaf2952012-10-05 16:01:08 -07005885 }
5886 }
5887 }
5888 };
5889
Christopher Tate5e08af02012-09-21 17:17:22 -07005890 BroadcastReceiver mMultiuserReceiver = new BroadcastReceiver() {
5891 @Override
5892 public void onReceive(Context context, Intent intent) {
5893 if (Intent.ACTION_USER_SWITCHED.equals(intent.getAction())) {
5894 // tickle the settings observer: this first ensures that we're
5895 // observing the relevant settings for the newly-active user,
5896 // and then updates our own bookkeeping based on the now-
5897 // current user.
5898 mSettingsObserver.onChange(false);
John Spurlockce479d82012-11-29 09:52:21 -05005899
5900 // force a re-application of focused window sysui visibility.
5901 // the window may never have been shown for this user
5902 // e.g. the keyguard when going through the new-user setup flow
John Spurlock04db1762013-05-13 12:46:41 -04005903 synchronized (mWindowManagerFuncs.getWindowManagerLock()) {
John Spurlockce479d82012-11-29 09:52:21 -05005904 mLastSystemUiFlags = 0;
5905 updateSystemUiVisibilityLw();
5906 }
Christopher Tate5e08af02012-09-21 17:17:22 -07005907 }
5908 }
5909 };
5910
Adrian Roosddc8b272015-05-21 16:28:27 -07005911 private final Runnable mHiddenNavPanic = new Runnable() {
John Spurlockd9b70bd2014-02-06 17:02:44 -05005912 @Override
5913 public void run() {
Adrian Roosddc8b272015-05-21 16:28:27 -07005914 synchronized (mWindowManagerFuncs.getWindowManagerLock()) {
5915 if (!isUserSetupComplete()) {
5916 // Swipe-up for navigation bar is disabled during setup
5917 return;
5918 }
5919 mPendingPanicGestureUptime = SystemClock.uptimeMillis();
5920 mNavigationBarController.showTransient();
5921 }
John Spurlockd9b70bd2014-02-06 17:02:44 -05005922 }
5923 };
5924
John Spurlocke1f366f2013-08-05 12:22:40 -04005925 private void requestTransientBars(WindowState swipeTarget) {
John Spurlock04db1762013-05-13 12:46:41 -04005926 synchronized (mWindowManagerFuncs.getWindowManagerLock()) {
Maurice Lam99c6e072014-04-28 18:24:28 -07005927 if (!isUserSetupComplete()) {
5928 // Swipe-up for navigation bar is disabled during setup
5929 return;
5930 }
John Spurlock27735a42013-08-14 17:57:38 -04005931 boolean sb = mStatusBarController.checkShowTransientBarLw();
5932 boolean nb = mNavigationBarController.checkShowTransientBarLw();
John Spurlockad3e6cb2013-04-30 08:47:43 -04005933 if (sb || nb) {
Adrian Roos62b65e42015-02-25 18:05:34 +01005934 // Don't show status bar when swiping on already visible navigation bar
5935 if (!nb && swipeTarget == mNavigationBar) {
John Spurlocke1f366f2013-08-05 12:22:40 -04005936 if (DEBUG) Slog.d(TAG, "Not showing transient bar, wrong swipe target");
John Spurlockad3e6cb2013-04-30 08:47:43 -04005937 return;
5938 }
John Spurlock27735a42013-08-14 17:57:38 -04005939 if (sb) mStatusBarController.showTransient();
5940 if (nb) mNavigationBarController.showTransient();
John Spurlockf1a36642013-10-12 17:50:42 -04005941 mImmersiveModeConfirmation.confirmCurrentPrompt();
John Spurlockad3e6cb2013-04-30 08:47:43 -04005942 updateSystemUiVisibilityLw();
John Spurlock32beb2c2013-03-11 10:16:47 -04005943 }
John Spurlockad3e6cb2013-04-30 08:47:43 -04005944 }
5945 }
5946
Jeff Brown3ee549c2014-09-22 20:14:39 -07005947 // Called on the PowerManager's Notifier thread.
Jeff Brownc38c9be2012-10-04 13:16:19 -07005948 @Override
Jeff Brown416c49c2015-05-26 19:50:18 -07005949 public void startedGoingToSleep(int why) {
5950 if (DEBUG_WAKEUP) Slog.i(TAG, "Started going to sleep... (why=" + why + ")");
Jorim Jaggid175b6c2015-05-27 15:39:09 -07005951 if (mKeyguardDelegate != null) {
5952 mKeyguardDelegate.onStartedGoingToSleep(why);
5953 }
Jeff Brown416c49c2015-05-26 19:50:18 -07005954 }
5955
5956 // Called on the PowerManager's Notifier thread.
5957 @Override
5958 public void finishedGoingToSleep(int why) {
Dianne Hackborn74489012009-03-24 20:50:09 -07005959 EventLog.writeEvent(70000, 0);
Jeff Brown416c49c2015-05-26 19:50:18 -07005960 if (DEBUG_WAKEUP) Slog.i(TAG, "Finished going to sleep... (why=" + why + ")");
Chris Wren9bb290b2015-06-29 12:02:13 -04005961 MetricsLogger.histogram(mContext, "screen_timeout", mLockScreenTimeout / 1000);
Jeff Brown3ee549c2014-09-22 20:14:39 -07005962
5963 // We must get this work done here because the power manager will drop
5964 // the wake lock and let the system suspend once this function returns.
The Android Open Source Project0727d222009-03-11 12:11:58 -07005965 synchronized (mLock) {
Jeff Brown3ee549c2014-09-22 20:14:39 -07005966 mAwake = false;
Jeff Browna20dda42014-05-27 20:57:24 -07005967 updateWakeGestureListenerLp();
The Android Open Source Project0727d222009-03-11 12:11:58 -07005968 updateOrientationListenerLp();
Mike Lockwood28569302010-01-28 11:54:40 -05005969 updateLockScreenTimeout();
The Android Open Source Project0727d222009-03-11 12:11:58 -07005970 }
Jeff Brown3ee549c2014-09-22 20:14:39 -07005971 if (mKeyguardDelegate != null) {
Jorim Jaggid175b6c2015-05-27 15:39:09 -07005972 mKeyguardDelegate.onFinishedGoingToSleep(why);
Jeff Brown3ee549c2014-09-22 20:14:39 -07005973 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005974 }
5975
Jeff Brown3ee549c2014-09-22 20:14:39 -07005976 // Called on the PowerManager's Notifier thread.
Jeff Brownc38c9be2012-10-04 13:16:19 -07005977 @Override
Jeff Brown416c49c2015-05-26 19:50:18 -07005978 public void startedWakingUp() {
Dianne Hackborn74489012009-03-24 20:50:09 -07005979 EventLog.writeEvent(70000, 1);
Jeff Brown416c49c2015-05-26 19:50:18 -07005980 if (DEBUG_WAKEUP) Slog.i(TAG, "Started waking up...");
Craig Mautner8a0da012014-05-31 15:13:37 -07005981
Jeff Brown3ee549c2014-09-22 20:14:39 -07005982 // Since goToSleep performs these functions synchronously, we must
5983 // do the same here. We cannot post this work to a handler because
5984 // that might cause it to become reordered with respect to what
5985 // may happen in a future call to goToSleep.
The Android Open Source Project0727d222009-03-11 12:11:58 -07005986 synchronized (mLock) {
Jeff Brown3ee549c2014-09-22 20:14:39 -07005987 mAwake = true;
Jeff Brown3ee549c2014-09-22 20:14:39 -07005988
Jeff Browna20dda42014-05-27 20:57:24 -07005989 updateWakeGestureListenerLp();
The Android Open Source Project0727d222009-03-11 12:11:58 -07005990 updateOrientationListenerLp();
Mike Lockwood28569302010-01-28 11:54:40 -05005991 updateLockScreenTimeout();
The Android Open Source Project0727d222009-03-11 12:11:58 -07005992 }
Jeff Brownc38c9be2012-10-04 13:16:19 -07005993
Jim Miller5ecd8112013-01-09 18:50:26 -08005994 if (mKeyguardDelegate != null) {
Jorim Jaggi4cfdcf52015-07-09 12:13:59 -07005995 mKeyguardDelegate.onStartedWakingUp();
Jeff Brownc38c9be2012-10-04 13:16:19 -07005996 }
Jeff Brown36c4db82014-09-19 12:05:31 -07005997 }
5998
Jeff Brown416c49c2015-05-26 19:50:18 -07005999 // Called on the PowerManager's Notifier thread.
6000 @Override
6001 public void finishedWakingUp() {
6002 if (DEBUG_WAKEUP) Slog.i(TAG, "Finished waking up...");
6003 }
6004
6005 private void wakeUpFromPowerKey(long eventTime) {
Dianne Hackborn280a64e2015-07-13 14:48:08 -07006006 wakeUp(eventTime, mAllowTheaterModeWakeFromPowerKey, "android.policy:POWER");
Jeff Brown416c49c2015-05-26 19:50:18 -07006007 }
6008
Dianne Hackborn280a64e2015-07-13 14:48:08 -07006009 private boolean wakeUp(long wakeTime, boolean wakeInTheaterMode, String reason) {
Bryce Leed3896842015-06-23 17:06:51 -07006010 final boolean theaterModeEnabled = isTheaterModeEnabled();
6011 if (!wakeInTheaterMode && theaterModeEnabled) {
Jeff Brown416c49c2015-05-26 19:50:18 -07006012 return false;
6013 }
6014
Bryce Leed3896842015-06-23 17:06:51 -07006015 if (theaterModeEnabled) {
6016 Settings.Global.putInt(mContext.getContentResolver(),
6017 Settings.Global.THEATER_MODE_ON, 0);
6018 }
6019
Dianne Hackborn280a64e2015-07-13 14:48:08 -07006020 mPowerManager.wakeUp(wakeTime, reason);
Jeff Brown416c49c2015-05-26 19:50:18 -07006021 return true;
6022 }
6023
Jeff Brown36c4db82014-09-19 12:05:31 -07006024 private void finishKeyguardDrawn() {
Jeff Brown3ee549c2014-09-22 20:14:39 -07006025 synchronized (mLock) {
Jorim Jaggif3255482015-07-24 12:32:42 -07006026 if (!mScreenOnEarly || mKeyguardDrawComplete) {
Stefan Kuhne9326dc12015-06-12 09:25:32 -10006027 return; // We are not awake yet or we have already informed of this event.
Jeff Brown3ee549c2014-09-22 20:14:39 -07006028 }
6029
Jeff Brown36c4db82014-09-19 12:05:31 -07006030 mKeyguardDrawComplete = true;
Jeff Brown3ee549c2014-09-22 20:14:39 -07006031 if (mKeyguardDelegate != null) {
6032 mHandler.removeMessages(MSG_KEYGUARD_DRAWN_TIMEOUT);
6033 }
Jorim Jaggi4cfdcf52015-07-09 12:13:59 -07006034 mWindowManagerDrawComplete = false;
Jeff Brown3ee549c2014-09-22 20:14:39 -07006035 }
6036
Jorim Jaggi4cfdcf52015-07-09 12:13:59 -07006037 // ... eventually calls finishWindowsDrawn which will finalize our screen turn on
6038 // as well as enabling the orientation change logic/sensor.
6039 mWindowManagerInternal.waitForAllWindowsDrawn(mWindowManagerDrawCallback,
6040 WAITING_FOR_DRAWN_TIMEOUT);
Jeff Brown3ee549c2014-09-22 20:14:39 -07006041 }
6042
6043 // Called on the DisplayManager's DisplayPowerController thread.
6044 @Override
6045 public void screenTurnedOff() {
6046 if (DEBUG_WAKEUP) Slog.i(TAG, "Screen turned off...");
6047
Jeff Brown48d1b142015-06-10 16:36:03 -07006048 updateScreenOffSleepToken(true);
Jeff Brown3ee549c2014-09-22 20:14:39 -07006049 synchronized (mLock) {
6050 mScreenOnEarly = false;
6051 mScreenOnFully = false;
Jorim Jaggi95c6dae2015-07-29 15:17:23 -07006052 mKeyguardDrawComplete = false;
Jeff Brown3ee549c2014-09-22 20:14:39 -07006053 mWindowManagerDrawComplete = false;
6054 mScreenOnListener = null;
6055 updateOrientationListenerLp();
Jorim Jaggi0d210f62015-07-10 14:24:44 -07006056
6057 if (mKeyguardDelegate != null) {
6058 mKeyguardDelegate.onScreenTurnedOff();
6059 }
Jeff Brown36c4db82014-09-19 12:05:31 -07006060 }
6061 }
6062
Jeff Brown3ee549c2014-09-22 20:14:39 -07006063 // Called on the DisplayManager's DisplayPowerController thread.
Jeff Brown36c4db82014-09-19 12:05:31 -07006064 @Override
6065 public void screenTurningOn(final ScreenOnListener screenOnListener) {
Jeff Brown36c4db82014-09-19 12:05:31 -07006066 if (DEBUG_WAKEUP) Slog.i(TAG, "Screen turning on...");
Jeff Brown36c4db82014-09-19 12:05:31 -07006067
Jeff Brown48d1b142015-06-10 16:36:03 -07006068 updateScreenOffSleepToken(false);
Jeff Brown3ee549c2014-09-22 20:14:39 -07006069 synchronized (mLock) {
6070 mScreenOnEarly = true;
6071 mScreenOnFully = false;
Jorim Jaggi95c6dae2015-07-29 15:17:23 -07006072 mKeyguardDrawComplete = false;
Jeff Brown3ee549c2014-09-22 20:14:39 -07006073 mWindowManagerDrawComplete = false;
6074 mScreenOnListener = screenOnListener;
Jeff Brown36c4db82014-09-19 12:05:31 -07006075
Jorim Jaggi4cfdcf52015-07-09 12:13:59 -07006076 if (mKeyguardDelegate != null) {
Jorim Jaggia4b51bc2015-08-10 18:20:43 -07006077 mHandler.removeMessages(MSG_KEYGUARD_DRAWN_TIMEOUT);
6078 mHandler.sendEmptyMessageDelayed(MSG_KEYGUARD_DRAWN_TIMEOUT, 1000);
Jorim Jaggi4cfdcf52015-07-09 12:13:59 -07006079 mKeyguardDelegate.onScreenTurningOn(mKeyguardDrawnCallback);
6080 } else {
6081 if (DEBUG_WAKEUP) Slog.d(TAG,
6082 "null mKeyguardDelegate: setting mKeyguardDrawComplete.");
6083 finishKeyguardDrawn();
6084 }
6085 }
Jeff Brown36c4db82014-09-19 12:05:31 -07006086 }
6087
Jorim Jaggi0d210f62015-07-10 14:24:44 -07006088 // Called on the DisplayManager's DisplayPowerController thread.
6089 @Override
6090 public void screenTurnedOn() {
6091 synchronized (mLock) {
6092 if (mKeyguardDelegate != null) {
6093 mKeyguardDelegate.onScreenTurnedOn();
6094 }
6095 }
6096 }
6097
Jeff Brown36c4db82014-09-19 12:05:31 -07006098 private void finishWindowsDrawn() {
Jeff Brown3ee549c2014-09-22 20:14:39 -07006099 synchronized (mLock) {
6100 if (!mScreenOnEarly || mWindowManagerDrawComplete) {
Stefan Kuhne9326dc12015-06-12 09:25:32 -10006101 return; // Screen is not turned on or we did already handle this case earlier.
Jeff Brown3ee549c2014-09-22 20:14:39 -07006102 }
6103
Jeff Brown36c4db82014-09-19 12:05:31 -07006104 mWindowManagerDrawComplete = true;
Jeff Brown36c4db82014-09-19 12:05:31 -07006105 }
Jeff Brown3ee549c2014-09-22 20:14:39 -07006106
6107 finishScreenTurningOn();
Jeff Brownc38c9be2012-10-04 13:16:19 -07006108 }
6109
Craig Mautner8a0da012014-05-31 15:13:37 -07006110 private void finishScreenTurningOn() {
Stefan Kuhne9326dc12015-06-12 09:25:32 -10006111 synchronized (mLock) {
6112 // We have just finished drawing screen content. Since the orientation listener
6113 // gets only installed when all windows are drawn, we try to install it again.
6114 updateOrientationListenerLp();
6115 }
Jeff Brown3ee549c2014-09-22 20:14:39 -07006116 final ScreenOnListener listener;
6117 final boolean enableScreen;
Jeff Brown36c4db82014-09-19 12:05:31 -07006118 synchronized (mLock) {
Jeff Brown3ee549c2014-09-22 20:14:39 -07006119 if (DEBUG_WAKEUP) Slog.d(TAG,
6120 "finishScreenTurningOn: mAwake=" + mAwake
6121 + ", mScreenOnEarly=" + mScreenOnEarly
6122 + ", mScreenOnFully=" + mScreenOnFully
6123 + ", mKeyguardDrawComplete=" + mKeyguardDrawComplete
6124 + ", mWindowManagerDrawComplete=" + mWindowManagerDrawComplete);
6125
6126 if (mScreenOnFully || !mScreenOnEarly || !mWindowManagerDrawComplete
6127 || (mAwake && !mKeyguardDrawComplete)) {
6128 return; // spurious or not ready yet
Jeff Brown36c4db82014-09-19 12:05:31 -07006129 }
6130
Jeff Brown3ee549c2014-09-22 20:14:39 -07006131 if (DEBUG_WAKEUP) Slog.i(TAG, "Finished screen turning on...");
6132 listener = mScreenOnListener;
Craig Mautner13f6ea72014-06-23 14:57:02 -07006133 mScreenOnListener = null;
Jeff Brown3ee549c2014-09-22 20:14:39 -07006134 mScreenOnFully = true;
6135
6136 // Remember the first time we draw the keyguard so we know when we're done with
6137 // the main part of booting and can enable the screen and hide boot messages.
6138 if (!mKeyguardDrawnOnce && mAwake) {
6139 mKeyguardDrawnOnce = true;
6140 enableScreen = true;
6141 if (mBootMessageNeedsHiding) {
6142 mBootMessageNeedsHiding = false;
6143 hideBootMessages();
6144 }
6145 } else {
6146 enableScreen = false;
6147 }
Jeff Brownc38c9be2012-10-04 13:16:19 -07006148 }
6149
Jeff Brown3ee549c2014-09-22 20:14:39 -07006150 if (listener != null) {
6151 listener.onScreenOn();
6152 }
Jeff Brown4fc45272012-10-10 18:28:14 -07006153
Jeff Brown3ee549c2014-09-22 20:14:39 -07006154 if (enableScreen) {
6155 try {
6156 mWindowManager.enableScreenIfNeeded();
6157 } catch (RemoteException unhandled) {
Jeff Brown36c4db82014-09-19 12:05:31 -07006158 }
Craig Mautnera631d492014-08-05 15:16:01 -07006159 }
6160 }
6161
6162 private void handleHideBootMessage() {
Jeff Brown3ee549c2014-09-22 20:14:39 -07006163 synchronized (mLock) {
6164 if (!mKeyguardDrawnOnce) {
6165 mBootMessageNeedsHiding = true;
6166 return; // keyguard hasn't drawn the first time yet, not done booting
6167 }
Craig Mautnera631d492014-08-05 15:16:01 -07006168 }
Jeff Brown3ee549c2014-09-22 20:14:39 -07006169
6170 if (mBootMsgDialog != null) {
6171 if (DEBUG_WAKEUP) Slog.d(TAG, "handleHideBootMessage: dismissing");
6172 mBootMsgDialog.dismiss();
6173 mBootMsgDialog = null;
Craig Mautnera631d492014-08-05 15:16:01 -07006174 }
Jeff Brownc38c9be2012-10-04 13:16:19 -07006175 }
6176
6177 @Override
Jeff Brown3ee549c2014-09-22 20:14:39 -07006178 public boolean isScreenOn() {
6179 return mScreenOnFully;
Dianne Hackborn08743722009-12-21 12:16:51 -08006180 }
Jeff Brownc38c9be2012-10-04 13:16:19 -07006181
Dianne Hackborn08743722009-12-21 12:16:51 -08006182 /** {@inheritDoc} */
Jose Lima9546b202014-07-02 17:21:51 -07006183 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006184 public void enableKeyguard(boolean enabled) {
Jim Miller5ecd8112013-01-09 18:50:26 -08006185 if (mKeyguardDelegate != null) {
6186 mKeyguardDelegate.setKeyguardEnabled(enabled);
Mike Lockwood3a74bd32011-08-12 13:55:22 -07006187 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006188 }
6189
6190 /** {@inheritDoc} */
Jose Lima9546b202014-07-02 17:21:51 -07006191 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006192 public void exitKeyguardSecurely(OnKeyguardExitResult callback) {
Jim Miller5ecd8112013-01-09 18:50:26 -08006193 if (mKeyguardDelegate != null) {
6194 mKeyguardDelegate.verifyUnlock(callback);
Mike Lockwood3a74bd32011-08-12 13:55:22 -07006195 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006196 }
6197
Jim Millerab954542014-10-10 18:21:49 -07006198 private boolean isKeyguardShowingAndNotOccluded() {
Jim Miller5ecd8112013-01-09 18:50:26 -08006199 if (mKeyguardDelegate == null) return false;
Jim Millerab954542014-10-10 18:21:49 -07006200 return mKeyguardDelegate.isShowing() && !mKeyguardOccluded;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006201 }
6202
Mike Lockwood520d8bc2011-02-18 13:23:13 -05006203 /** {@inheritDoc} */
Jose Lima9546b202014-07-02 17:21:51 -07006204 @Override
Mike Lockwood520d8bc2011-02-18 13:23:13 -05006205 public boolean isKeyguardLocked() {
6206 return keyguardOn();
6207 }
6208
6209 /** {@inheritDoc} */
Jose Lima9546b202014-07-02 17:21:51 -07006210 @Override
Mike Lockwood520d8bc2011-02-18 13:23:13 -05006211 public boolean isKeyguardSecure() {
Jim Miller5ecd8112013-01-09 18:50:26 -08006212 if (mKeyguardDelegate == null) return false;
6213 return mKeyguardDelegate.isSecure();
Mike Lockwood520d8bc2011-02-18 13:23:13 -05006214 }
6215
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006216 /** {@inheritDoc} */
Jose Lima9546b202014-07-02 17:21:51 -07006217 @Override
Adrian Roos461829d2015-06-03 14:41:18 -07006218 public boolean isKeyguardShowingOrOccluded() {
6219 return mKeyguardDelegate == null ? false : mKeyguardDelegate.isShowing();
6220 }
6221
6222 /** {@inheritDoc} */
6223 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006224 public boolean inKeyguardRestrictedKeyInputMode() {
Jim Miller5ecd8112013-01-09 18:50:26 -08006225 if (mKeyguardDelegate == null) return false;
6226 return mKeyguardDelegate.isInputRestricted();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006227 }
6228
Jose Lima9546b202014-07-02 17:21:51 -07006229 @Override
Dianne Hackborn90c52de2011-09-23 12:57:44 -07006230 public void dismissKeyguardLw() {
RoboErik8a2cfc32014-05-16 11:19:38 -07006231 if (mKeyguardDelegate != null && mKeyguardDelegate.isShowing()) {
Craig Mautnerc0d2d0a2014-10-31 16:25:15 -07006232 if (DEBUG_KEYGUARD) Slog.d(TAG, "PWM.dismissKeyguardLw");
Daniel Sandler1ce804392012-11-07 15:07:12 -05006233 mHandler.post(new Runnable() {
Jose Lima9546b202014-07-02 17:21:51 -07006234 @Override
Daniel Sandler1ce804392012-11-07 15:07:12 -05006235 public void run() {
Jorim Jaggi8de4311c2014-08-11 22:36:20 +02006236 // ask the keyguard to prompt the user to authenticate if necessary
6237 mKeyguardDelegate.dismiss();
6238 }
6239 });
6240 }
6241 }
6242
6243 public void notifyActivityDrawnForKeyguardLw() {
6244 if (mKeyguardDelegate != null) {
6245 mHandler.post(new Runnable() {
6246 @Override
6247 public void run() {
6248 mKeyguardDelegate.onActivityDrawn();
Daniel Sandler1ce804392012-11-07 15:07:12 -05006249 }
6250 });
Dianne Hackborn90c52de2011-09-23 12:57:44 -07006251 }
6252 }
6253
Jorim Jaggicff0acb2014-03-31 16:35:15 +02006254 @Override
6255 public boolean isKeyguardDrawnLw() {
6256 synchronized (mLock) {
Jeff Brown3ee549c2014-09-22 20:14:39 -07006257 return mKeyguardDrawnOnce;
Jorim Jaggicff0acb2014-03-31 16:35:15 +02006258 }
6259 }
6260
Jorim Jaggi0d674622014-05-21 01:34:15 +02006261 @Override
Jorim Jaggie29b2db2014-05-30 23:17:03 +02006262 public void startKeyguardExitAnimation(long startTime, long fadeoutDuration) {
Jorim Jaggi0d674622014-05-21 01:34:15 +02006263 if (mKeyguardDelegate != null) {
Craig Mautnerc0d2d0a2014-10-31 16:25:15 -07006264 if (DEBUG_KEYGUARD) Slog.d(TAG, "PWM.startKeyguardExitAnimation");
Jorim Jaggie29b2db2014-05-30 23:17:03 +02006265 mKeyguardDelegate.startKeyguardExitAnimation(startTime, fadeoutDuration);
Jorim Jaggi0d674622014-05-21 01:34:15 +02006266 }
6267 }
6268
Jorim Jaggi737af722015-12-31 10:42:27 +01006269 @Override
6270 public void getStableInsetsLw(int displayRotation, int displayWidth, int displayHeight,
6271 Rect outInsets) {
6272 outInsets.setEmpty();
Jorim Jaggi82c9dc92016-02-05 15:10:33 -08006273
6274 // Navigation bar and status bar.
6275 getNonDecorInsetsLw(displayRotation, displayWidth, displayHeight, outInsets);
Jorim Jaggi737af722015-12-31 10:42:27 +01006276 if (mStatusBar != null) {
6277 outInsets.top = mStatusBarHeight;
6278 }
Jorim Jaggi82c9dc92016-02-05 15:10:33 -08006279 }
6280
6281 @Override
6282 public void getNonDecorInsetsLw(int displayRotation, int displayWidth, int displayHeight,
6283 Rect outInsets) {
6284 outInsets.setEmpty();
6285
6286 // Only navigation bar
Jorim Jaggi737af722015-12-31 10:42:27 +01006287 if (mNavigationBar != null) {
6288 if (isNavigationBarOnBottom(displayWidth, displayHeight)) {
6289 outInsets.bottom = getNavigationBarHeight(displayRotation, mUiMode);
6290 } else {
6291 outInsets.right = getNavigationBarWidth(displayRotation, mUiMode);
6292 }
6293 }
6294 }
6295
Jorim Jaggi5060bd82016-02-19 17:12:19 -08006296 @Override
Jorim Jaggi0ffd49c2016-02-12 15:04:21 -08006297 public boolean isNavBarForcedShownLw(WindowState windowState) {
Jorim Jaggie5638a62016-03-25 22:57:01 -07006298 return mForceShowSystemBars;
Jorim Jaggi0ffd49c2016-02-12 15:04:21 -08006299 }
6300
6301 @Override
Jorim Jaggi5060bd82016-02-19 17:12:19 -08006302 public boolean isDockSideAllowed(int dockSide) {
6303
6304 // We do not allow all dock sides at which the navigation bar touches the docked stack.
6305 if (!mNavigationBarCanMove) {
6306 return dockSide == DOCKED_TOP || dockSide == DOCKED_LEFT || dockSide == DOCKED_RIGHT;
6307 } else {
6308 return dockSide == DOCKED_TOP || dockSide == DOCKED_LEFT;
6309 }
6310 }
6311
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006312 void sendCloseSystemWindows() {
Jorim Jaggib10e33f2015-02-04 21:57:40 +01006313 PhoneWindow.sendCloseSystemWindows(mContext, null);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006314 }
6315
6316 void sendCloseSystemWindows(String reason) {
Jorim Jaggib10e33f2015-02-04 21:57:40 +01006317 PhoneWindow.sendCloseSystemWindows(mContext, reason);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006318 }
Mitsuru Oshima831d0d92009-06-16 18:27:18 -07006319
Jeff Brown01a98dd2011-09-20 15:08:29 -07006320 @Override
6321 public int rotationForOrientationLw(int orientation, int lastRotation) {
Daniel Sandler2ed6ad62011-02-22 14:54:17 -05006322 if (false) {
6323 Slog.v(TAG, "rotationForOrientationLw(orient="
6324 + orientation + ", last=" + lastRotation
6325 + "); user=" + mUserRotation + " "
6326 + ((mUserRotationMode == WindowManagerPolicy.USER_ROTATION_LOCKED)
6327 ? "USER_ROTATION_LOCKED" : "")
6328 );
6329 }
6330
Craig Mautner46ac6fa2013-08-01 10:06:34 -07006331 if (mForceDefaultOrientation) {
6332 return Surface.ROTATION_0;
6333 }
6334
The Android Open Source Project0727d222009-03-11 12:11:58 -07006335 synchronized (mLock) {
Jeff Brownc0347aa2011-09-23 17:26:09 -07006336 int sensorRotation = mOrientationListener.getProposedRotation(); // may be -1
6337 if (sensorRotation < 0) {
Jeff Brown0f862b42012-09-27 21:11:01 -07006338 sensorRotation = lastRotation;
Jeff Brownc0347aa2011-09-23 17:26:09 -07006339 }
Jeff Brown01a98dd2011-09-20 15:08:29 -07006340
Jeff Browndec6cf42011-11-15 14:08:20 -08006341 final int preferredRotation;
Jeff Brown2e7760e2012-04-11 15:14:55 -07006342 if (mLidState == LID_OPEN && mLidOpenRotation >= 0) {
Jeff Brown01a98dd2011-09-20 15:08:29 -07006343 // Ignore sensor when lid switch is open and rotation is forced.
6344 preferredRotation = mLidOpenRotation;
6345 } else if (mDockMode == Intent.EXTRA_DOCK_STATE_CAR
Jeff Brownc0347aa2011-09-23 17:26:09 -07006346 && (mCarDockEnablesAccelerometer || mCarDockRotation >= 0)) {
Jeff Brown01a98dd2011-09-20 15:08:29 -07006347 // Ignore sensor when in car dock unless explicitly enabled.
6348 // This case can override the behavior of NOSENSOR, and can also
6349 // enable 180 degree rotation while docked.
Jeff Brownc0347aa2011-09-23 17:26:09 -07006350 preferredRotation = mCarDockEnablesAccelerometer
Jeff Brown01a98dd2011-09-20 15:08:29 -07006351 ? sensorRotation : mCarDockRotation;
Jeff Brown1a693182011-11-08 14:44:16 -08006352 } else if ((mDockMode == Intent.EXTRA_DOCK_STATE_DESK
6353 || mDockMode == Intent.EXTRA_DOCK_STATE_LE_DESK
6354 || mDockMode == Intent.EXTRA_DOCK_STATE_HE_DESK)
Jeff Brownc0347aa2011-09-23 17:26:09 -07006355 && (mDeskDockEnablesAccelerometer || mDeskDockRotation >= 0)) {
Jeff Brown01a98dd2011-09-20 15:08:29 -07006356 // Ignore sensor when in desk dock unless explicitly enabled.
6357 // This case can override the behavior of NOSENSOR, and can also
6358 // enable 180 degree rotation while docked.
Jeff Brownc0347aa2011-09-23 17:26:09 -07006359 preferredRotation = mDeskDockEnablesAccelerometer
Jeff Brown01a98dd2011-09-20 15:08:29 -07006360 ? sensorRotation : mDeskDockRotation;
Jeff Brownc82c89ed2013-04-17 17:18:15 -07006361 } else if (mHdmiPlugged && mDemoHdmiRotationLock) {
6362 // Ignore sensor when plugged into HDMI when demo HDMI rotation lock enabled.
Jeff Browneb3e4b92011-12-06 19:54:24 -08006363 // Note that the dock orientation overrides the HDMI orientation.
Jeff Brownc82c89ed2013-04-17 17:18:15 -07006364 preferredRotation = mDemoHdmiRotation;
6365 } else if (mHdmiPlugged && mDockMode == Intent.EXTRA_DOCK_STATE_UNDOCKED
6366 && mUndockedHdmiRotation >= 0) {
6367 // Ignore sensor when plugged into HDMI and an undocked orientation has
6368 // been specified in the configuration (only for legacy devices without
6369 // full multi-display support).
6370 // Note that the dock orientation overrides the HDMI orientation.
6371 preferredRotation = mUndockedHdmiRotation;
Chong Zhangae6119ff2014-11-11 18:54:39 -08006372 } else if (mDemoRotationLock) {
6373 // Ignore sensor when demo rotation lock is enabled.
6374 // Note that the dock orientation and HDMI rotation lock override this.
6375 preferredRotation = mDemoRotation;
Dianne Hackbornb9ec1ac2013-04-10 17:34:25 -07006376 } else if (orientation == ActivityInfo.SCREEN_ORIENTATION_LOCKED) {
6377 // Application just wants to remain locked in the last rotation.
6378 preferredRotation = lastRotation;
Jeff Brownbcdfc622014-03-06 19:13:04 -08006379 } else if (!mSupportAutoRotation) {
6380 // If we don't support auto-rotation then bail out here and ignore
6381 // the sensor and any rotation lock settings.
6382 preferredRotation = -1;
Jeff Brown207673cd2012-06-05 17:47:11 -07006383 } else if ((mUserRotationMode == WindowManagerPolicy.USER_ROTATION_FREE
Jeff Brown01a98dd2011-09-20 15:08:29 -07006384 && (orientation == ActivityInfo.SCREEN_ORIENTATION_USER
Dianne Hackbornb9ec1ac2013-04-10 17:34:25 -07006385 || orientation == ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED
6386 || orientation == ActivityInfo.SCREEN_ORIENTATION_USER_LANDSCAPE
6387 || orientation == ActivityInfo.SCREEN_ORIENTATION_USER_PORTRAIT
6388 || orientation == ActivityInfo.SCREEN_ORIENTATION_FULL_USER))
Jeff Brown01a98dd2011-09-20 15:08:29 -07006389 || orientation == ActivityInfo.SCREEN_ORIENTATION_SENSOR
6390 || orientation == ActivityInfo.SCREEN_ORIENTATION_FULL_SENSOR
6391 || orientation == ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE
6392 || orientation == ActivityInfo.SCREEN_ORIENTATION_SENSOR_PORTRAIT) {
6393 // Otherwise, use sensor only if requested by the application or enabled
6394 // by default for USER or UNSPECIFIED modes. Does not apply to NOSENSOR.
Jeff Brownd3187e32011-09-21 19:26:44 -07006395 if (mAllowAllRotations < 0) {
6396 // Can't read this during init() because the context doesn't
6397 // have display metrics at that time so we cannot determine
6398 // tablet vs. phone then.
6399 mAllowAllRotations = mContext.getResources().getBoolean(
6400 com.android.internal.R.bool.config_allowAllRotations) ? 1 : 0;
6401 }
Jeff Brown01a98dd2011-09-20 15:08:29 -07006402 if (sensorRotation != Surface.ROTATION_180
Jeff Brownd3187e32011-09-21 19:26:44 -07006403 || mAllowAllRotations == 1
Dianne Hackbornb9ec1ac2013-04-10 17:34:25 -07006404 || orientation == ActivityInfo.SCREEN_ORIENTATION_FULL_SENSOR
6405 || orientation == ActivityInfo.SCREEN_ORIENTATION_FULL_USER) {
Jeff Brown01a98dd2011-09-20 15:08:29 -07006406 preferredRotation = sensorRotation;
6407 } else {
6408 preferredRotation = lastRotation;
6409 }
Jeff Brown207673cd2012-06-05 17:47:11 -07006410 } else if (mUserRotationMode == WindowManagerPolicy.USER_ROTATION_LOCKED
6411 && orientation != ActivityInfo.SCREEN_ORIENTATION_NOSENSOR) {
6412 // Apply rotation lock. Does not apply to NOSENSOR.
6413 // The idea is that the user rotation expresses a weak preference for the direction
6414 // of gravity and as NOSENSOR is never affected by gravity, then neither should
6415 // NOSENSOR be affected by rotation lock (although it will be affected by docks).
Jeff Brown4dfce202011-10-05 12:00:10 -07006416 preferredRotation = mUserRotation;
Jeff Browndec6cf42011-11-15 14:08:20 -08006417 } else {
6418 // No overriding preference.
6419 // We will do exactly what the application asked us to do.
6420 preferredRotation = -1;
Jeff Brown01a98dd2011-09-20 15:08:29 -07006421 }
6422
Dianne Hackborne5439f22010-10-02 16:53:50 -07006423 switch (orientation) {
6424 case ActivityInfo.SCREEN_ORIENTATION_PORTRAIT:
Jeff Browndec6cf42011-11-15 14:08:20 -08006425 // Return portrait unless overridden.
6426 if (isAnyPortrait(preferredRotation)) {
6427 return preferredRotation;
6428 }
Dianne Hackborne5439f22010-10-02 16:53:50 -07006429 return mPortraitRotation;
Dianne Hackborne5439f22010-10-02 16:53:50 -07006430
Jeff Brown01a98dd2011-09-20 15:08:29 -07006431 case ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE:
Jeff Browndec6cf42011-11-15 14:08:20 -08006432 // Return landscape unless overridden.
6433 if (isLandscapeOrSeascape(preferredRotation)) {
6434 return preferredRotation;
6435 }
Jeff Brown01a98dd2011-09-20 15:08:29 -07006436 return mLandscapeRotation;
6437
6438 case ActivityInfo.SCREEN_ORIENTATION_REVERSE_PORTRAIT:
Jeff Browndec6cf42011-11-15 14:08:20 -08006439 // Return reverse portrait unless overridden.
6440 if (isAnyPortrait(preferredRotation)) {
6441 return preferredRotation;
6442 }
Jeff Brown01a98dd2011-09-20 15:08:29 -07006443 return mUpsideDownRotation;
6444
6445 case ActivityInfo.SCREEN_ORIENTATION_REVERSE_LANDSCAPE:
Jeff Browndec6cf42011-11-15 14:08:20 -08006446 // Return seascape unless overridden.
6447 if (isLandscapeOrSeascape(preferredRotation)) {
6448 return preferredRotation;
6449 }
Jeff Brown01a98dd2011-09-20 15:08:29 -07006450 return mSeascapeRotation;
6451
6452 case ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE:
Dianne Hackbornb9ec1ac2013-04-10 17:34:25 -07006453 case ActivityInfo.SCREEN_ORIENTATION_USER_LANDSCAPE:
Jeff Brown01a98dd2011-09-20 15:08:29 -07006454 // Return either landscape rotation.
6455 if (isLandscapeOrSeascape(preferredRotation)) {
6456 return preferredRotation;
6457 }
6458 if (isLandscapeOrSeascape(lastRotation)) {
Jeff Brown4519f072011-01-23 13:16:01 -08006459 return lastRotation;
6460 }
Jeff Brown01a98dd2011-09-20 15:08:29 -07006461 return mLandscapeRotation;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006462
Jeff Brown01a98dd2011-09-20 15:08:29 -07006463 case ActivityInfo.SCREEN_ORIENTATION_SENSOR_PORTRAIT:
Dianne Hackbornb9ec1ac2013-04-10 17:34:25 -07006464 case ActivityInfo.SCREEN_ORIENTATION_USER_PORTRAIT:
Jeff Brown01a98dd2011-09-20 15:08:29 -07006465 // Return either portrait rotation.
6466 if (isAnyPortrait(preferredRotation)) {
6467 return preferredRotation;
6468 }
6469 if (isAnyPortrait(lastRotation)) {
6470 return lastRotation;
6471 }
6472 return mPortraitRotation;
6473
6474 default:
Jeff Brown4dfce202011-10-05 12:00:10 -07006475 // For USER, UNSPECIFIED, NOSENSOR, SENSOR and FULL_SENSOR,
6476 // just return the preferred orientation we already calculated.
Jeff Brown01a98dd2011-09-20 15:08:29 -07006477 if (preferredRotation >= 0) {
6478 return preferredRotation;
6479 }
Dianne Hackborndacea8c2011-04-21 17:26:39 -07006480 return Surface.ROTATION_0;
Daniel Sandlere7e5ac22011-02-22 16:10:21 -05006481 }
6482 }
Steve Howarda7bfe6a2010-09-23 16:47:49 -07006483 }
6484
Jeff Brown01a98dd2011-09-20 15:08:29 -07006485 @Override
6486 public boolean rotationHasCompatibleMetricsLw(int orientation, int rotation) {
6487 switch (orientation) {
6488 case ActivityInfo.SCREEN_ORIENTATION_PORTRAIT:
6489 case ActivityInfo.SCREEN_ORIENTATION_REVERSE_PORTRAIT:
6490 case ActivityInfo.SCREEN_ORIENTATION_SENSOR_PORTRAIT:
6491 return isAnyPortrait(rotation);
6492
6493 case ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE:
6494 case ActivityInfo.SCREEN_ORIENTATION_REVERSE_LANDSCAPE:
6495 case ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE:
6496 return isLandscapeOrSeascape(rotation);
6497
6498 default:
6499 return true;
6500 }
Steve Howarda7bfe6a2010-09-23 16:47:49 -07006501 }
6502
Jeff Brownc0347aa2011-09-23 17:26:09 -07006503 @Override
6504 public void setRotationLw(int rotation) {
6505 mOrientationListener.setCurrentRotation(rotation);
6506 }
6507
Jeff Brown01a98dd2011-09-20 15:08:29 -07006508 private boolean isLandscapeOrSeascape(int rotation) {
6509 return rotation == mLandscapeRotation || rotation == mSeascapeRotation;
Dianne Hackborne5439f22010-10-02 16:53:50 -07006510 }
6511
Jeff Brown01a98dd2011-09-20 15:08:29 -07006512 private boolean isAnyPortrait(int rotation) {
6513 return rotation == mPortraitRotation || rotation == mUpsideDownRotation;
Dianne Hackborne5439f22010-10-02 16:53:50 -07006514 }
6515
Jose Lima9546b202014-07-02 17:21:51 -07006516 @Override
Svetoslav Ganov80943d82013-01-02 10:25:37 -08006517 public int getUserRotationMode() {
6518 return Settings.System.getIntForUser(mContext.getContentResolver(),
Brett Chabot7e55c402013-05-16 19:38:08 -07006519 Settings.System.ACCELEROMETER_ROTATION, 0, UserHandle.USER_CURRENT) != 0 ?
6520 WindowManagerPolicy.USER_ROTATION_FREE :
6521 WindowManagerPolicy.USER_ROTATION_LOCKED;
Svetoslav Ganov80943d82013-01-02 10:25:37 -08006522 }
Daniel Sandlerb73617d2010-08-17 00:41:00 -04006523
6524 // User rotation: to be used when all else fails in assigning an orientation to the device
Jose Lima9546b202014-07-02 17:21:51 -07006525 @Override
Daniel Sandlerb73617d2010-08-17 00:41:00 -04006526 public void setUserRotationMode(int mode, int rot) {
6527 ContentResolver res = mContext.getContentResolver();
Daniel Sandler2ed6ad62011-02-22 14:54:17 -05006528
6529 // mUserRotationMode and mUserRotation will be assigned by the content observer
Daniel Sandlerb73617d2010-08-17 00:41:00 -04006530 if (mode == WindowManagerPolicy.USER_ROTATION_LOCKED) {
Christopher Tate5e08af02012-09-21 17:17:22 -07006531 Settings.System.putIntForUser(res,
Daniel Sandlerb73617d2010-08-17 00:41:00 -04006532 Settings.System.USER_ROTATION,
Christopher Tate5e08af02012-09-21 17:17:22 -07006533 rot,
6534 UserHandle.USER_CURRENT);
6535 Settings.System.putIntForUser(res,
Daniel Sandler2ed6ad62011-02-22 14:54:17 -05006536 Settings.System.ACCELEROMETER_ROTATION,
Christopher Tate5e08af02012-09-21 17:17:22 -07006537 0,
6538 UserHandle.USER_CURRENT);
Daniel Sandlerb73617d2010-08-17 00:41:00 -04006539 } else {
Christopher Tate5e08af02012-09-21 17:17:22 -07006540 Settings.System.putIntForUser(res,
Daniel Sandlerb73617d2010-08-17 00:41:00 -04006541 Settings.System.ACCELEROMETER_ROTATION,
Christopher Tate5e08af02012-09-21 17:17:22 -07006542 1,
6543 UserHandle.USER_CURRENT);
Daniel Sandlerb73617d2010-08-17 00:41:00 -04006544 }
6545 }
6546
Jose Lima9546b202014-07-02 17:21:51 -07006547 @Override
Jeff Brownac143512012-04-05 18:57:33 -07006548 public void setSafeMode(boolean safeMode) {
6549 mSafeMode = safeMode;
6550 performHapticFeedbackLw(null, safeMode
6551 ? HapticFeedbackConstants.SAFE_MODE_ENABLED
6552 : HapticFeedbackConstants.SAFE_MODE_DISABLED, true);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006553 }
Craig Mautnereda67292013-04-28 13:50:14 -07006554
Dianne Hackborn181ceb52009-08-27 22:16:40 -07006555 static long[] getLongIntArray(Resources r, int resid) {
6556 int[] ar = r.getIntArray(resid);
6557 if (ar == null) {
6558 return null;
6559 }
6560 long[] out = new long[ar.length];
6561 for (int i=0; i<ar.length; i++) {
6562 out[i] = ar[i];
6563 }
6564 return out;
6565 }
Craig Mautnereda67292013-04-28 13:50:14 -07006566
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006567 /** {@inheritDoc} */
Craig Mautnereda67292013-04-28 13:50:14 -07006568 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006569 public void systemReady() {
Jim Millerab954542014-10-10 18:21:49 -07006570 mKeyguardDelegate = new KeyguardServiceDelegate(mContext);
Mike Lockwooded8902d2013-11-15 11:01:47 -08006571 mKeyguardDelegate.onSystemReady();
6572
Michael Wright3818c922014-09-02 13:59:07 -07006573 readCameraLensCoverState();
Jeff Brown4f5fa282014-06-12 19:19:15 -07006574 updateUiMode();
Adrian Roos3542f7d2015-07-13 15:57:53 -07006575 boolean bindKeyguardNow;
Dianne Hackbornb1a79802009-09-29 15:18:31 -07006576 synchronized (mLock) {
6577 updateOrientationListenerLp();
Dianne Hackbornc777e072010-02-12 13:07:59 -08006578 mSystemReady = true;
6579 mHandler.post(new Runnable() {
Craig Mautnereda67292013-04-28 13:50:14 -07006580 @Override
Dianne Hackbornc777e072010-02-12 13:07:59 -08006581 public void run() {
6582 updateSettings();
6583 }
6584 });
Adrian Roos3542f7d2015-07-13 15:57:53 -07006585
6586 bindKeyguardNow = mDeferBindKeyguard;
6587 if (bindKeyguardNow) {
6588 // systemBooted ran but wasn't able to bind to the Keyguard, we'll do it now.
6589 mDeferBindKeyguard = false;
6590 }
6591 }
6592
6593 if (bindKeyguardNow) {
6594 mKeyguardDelegate.bindService(mContext);
6595 mKeyguardDelegate.onBootCompleted();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006596 }
Michael Wrighta4d22d72015-09-16 23:19:26 +01006597 mSystemGestures.systemReady();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006598 }
Dianne Hackborn661cd522011-08-22 00:26:20 -07006599
Dianne Hackbornba24e4d2011-09-01 11:17:06 -07006600 /** {@inheritDoc} */
Jose Lima9546b202014-07-02 17:21:51 -07006601 @Override
Dianne Hackbornba24e4d2011-09-01 11:17:06 -07006602 public void systemBooted() {
Adrian Roos3542f7d2015-07-13 15:57:53 -07006603 boolean bindKeyguardNow = false;
6604 synchronized (mLock) {
6605 // Time to bind Keyguard; take care to only bind it once, either here if ready or
6606 // in systemReady if not.
6607 if (mKeyguardDelegate != null) {
6608 bindKeyguardNow = true;
6609 } else {
6610 // Because mKeyguardDelegate is null, we know that the synchronized block in
6611 // systemReady didn't run yet and setting this will actually have an effect.
6612 mDeferBindKeyguard = true;
6613 }
6614 }
6615 if (bindKeyguardNow) {
Jason Monk5eeebf52014-09-26 12:36:51 -04006616 mKeyguardDelegate.bindService(mContext);
Jim Millere5f910a2013-10-16 18:15:46 -07006617 mKeyguardDelegate.onBootCompleted();
6618 }
Dianne Hackbornba24e4d2011-09-01 11:17:06 -07006619 synchronized (mLock) {
6620 mSystemBooted = true;
6621 }
Jeff Brown416c49c2015-05-26 19:50:18 -07006622 startedWakingUp();
Jeff Brown36c4db82014-09-19 12:05:31 -07006623 screenTurningOn(null);
Jorim Jaggic0496072015-08-19 15:14:52 -07006624 screenTurnedOn();
Dianne Hackbornba24e4d2011-09-01 11:17:06 -07006625 }
6626
Dianne Hackborn661cd522011-08-22 00:26:20 -07006627 ProgressDialog mBootMsgDialog = null;
6628
6629 /** {@inheritDoc} */
Jose Lima9546b202014-07-02 17:21:51 -07006630 @Override
Dianne Hackborn661cd522011-08-22 00:26:20 -07006631 public void showBootMessage(final CharSequence msg, final boolean always) {
6632 mHandler.post(new Runnable() {
6633 @Override public void run() {
6634 if (mBootMsgDialog == null) {
Craig Stout4c0cb8a2014-04-04 13:03:10 -07006635 int theme;
Jaewan Kim49117872016-01-19 17:24:08 +09006636 if (mContext.getPackageManager().hasSystemFeature(FEATURE_WATCH)) {
Craig Stout4c0cb8a2014-04-04 13:03:10 -07006637 theme = com.android.internal.R.style.Theme_Micro_Dialog_Alert;
Jaewan Kim49117872016-01-19 17:24:08 +09006638 } else if (mContext.getPackageManager().hasSystemFeature(FEATURE_TELEVISION)) {
Craig Stout4c0cb8a2014-04-04 13:03:10 -07006639 theme = com.android.internal.R.style.Theme_Leanback_Dialog_Alert;
6640 } else {
6641 theme = 0;
6642 }
Vinod Krishnanfa8fc412014-04-18 14:35:53 -07006643
6644 mBootMsgDialog = new ProgressDialog(mContext, theme) {
Dianne Hackborn295e3c22011-08-25 13:19:08 -07006645 // This dialog will consume all events coming in to
6646 // it, to avoid it trying to do things too early in boot.
6647 @Override public boolean dispatchKeyEvent(KeyEvent event) {
6648 return true;
6649 }
6650 @Override public boolean dispatchKeyShortcutEvent(KeyEvent event) {
6651 return true;
6652 }
6653 @Override public boolean dispatchTouchEvent(MotionEvent ev) {
6654 return true;
6655 }
6656 @Override public boolean dispatchTrackballEvent(MotionEvent ev) {
6657 return true;
6658 }
6659 @Override public boolean dispatchGenericMotionEvent(MotionEvent ev) {
6660 return true;
6661 }
6662 @Override public boolean dispatchPopulateAccessibilityEvent(
6663 AccessibilityEvent event) {
6664 return true;
6665 }
6666 };
Jeff Hao9f60c082014-10-28 18:51:07 -07006667 if (mContext.getPackageManager().isUpgrade()) {
6668 mBootMsgDialog.setTitle(R.string.android_upgrading_title);
6669 } else {
6670 mBootMsgDialog.setTitle(R.string.android_start_title);
6671 }
Dianne Hackborn661cd522011-08-22 00:26:20 -07006672 mBootMsgDialog.setProgressStyle(ProgressDialog.STYLE_SPINNER);
6673 mBootMsgDialog.setIndeterminate(true);
6674 mBootMsgDialog.getWindow().setType(
Dianne Hackborn29aae6f2011-08-18 18:30:09 -07006675 WindowManager.LayoutParams.TYPE_BOOT_PROGRESS);
Dianne Hackborn661cd522011-08-22 00:26:20 -07006676 mBootMsgDialog.getWindow().addFlags(
6677 WindowManager.LayoutParams.FLAG_DIM_BEHIND
6678 | WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN);
6679 mBootMsgDialog.getWindow().setDimAmount(1);
Dianne Hackbornd9efb952011-12-07 14:56:51 -08006680 WindowManager.LayoutParams lp = mBootMsgDialog.getWindow().getAttributes();
6681 lp.screenOrientation = ActivityInfo.SCREEN_ORIENTATION_NOSENSOR;
6682 mBootMsgDialog.getWindow().setAttributes(lp);
Dianne Hackborn661cd522011-08-22 00:26:20 -07006683 mBootMsgDialog.setCancelable(false);
6684 mBootMsgDialog.show();
6685 }
6686 mBootMsgDialog.setMessage(msg);
6687 }
6688 });
6689 }
6690
6691 /** {@inheritDoc} */
Jose Lima9546b202014-07-02 17:21:51 -07006692 @Override
Dianne Hackborn661cd522011-08-22 00:26:20 -07006693 public void hideBootMessages() {
Craig Mautnera631d492014-08-05 15:16:01 -07006694 mHandler.sendEmptyMessage(MSG_HIDE_BOOT_MESSAGE);
Dianne Hackborn661cd522011-08-22 00:26:20 -07006695 }
6696
Mike Lockwood28569302010-01-28 11:54:40 -05006697 /** {@inheritDoc} */
Jose Lima9546b202014-07-02 17:21:51 -07006698 @Override
Mike Lockwood28569302010-01-28 11:54:40 -05006699 public void userActivity() {
Dianne Hackborndf89e652011-10-06 22:35:11 -07006700 // ***************************************
6701 // NOTE NOTE NOTE NOTE NOTE NOTE NOTE NOTE
6702 // ***************************************
6703 // THIS IS CALLED FROM DEEP IN THE POWER MANAGER
6704 // WITH ITS LOCKS HELD.
6705 //
6706 // This code must be VERY careful about the locks
6707 // it acquires.
6708 // In fact, the current code acquires way too many,
6709 // and probably has lurking deadlocks.
6710
Mike Lockwood28569302010-01-28 11:54:40 -05006711 synchronized (mScreenLockTimeout) {
6712 if (mLockScreenTimerActive) {
6713 // reset the timer
6714 mHandler.removeCallbacks(mScreenLockTimeout);
6715 mHandler.postDelayed(mScreenLockTimeout, mLockScreenTimeout);
6716 }
6717 }
Daniel Sandler0601eb72011-04-13 01:01:32 -04006718 }
6719
Adam Cohenf7522022012-10-03 20:03:18 -07006720 class ScreenLockTimeout implements Runnable {
6721 Bundle options;
6722
6723 @Override
Mike Lockwood28569302010-01-28 11:54:40 -05006724 public void run() {
6725 synchronized (this) {
6726 if (localLOGV) Log.v(TAG, "mScreenLockTimeout activating keyguard");
Jim Miller5ecd8112013-01-09 18:50:26 -08006727 if (mKeyguardDelegate != null) {
6728 mKeyguardDelegate.doKeyguardTimeout(options);
Mike Lockwood3a74bd32011-08-12 13:55:22 -07006729 }
Mike Lockwood28569302010-01-28 11:54:40 -05006730 mLockScreenTimerActive = false;
Adam Cohenf7522022012-10-03 20:03:18 -07006731 options = null;
Mike Lockwood28569302010-01-28 11:54:40 -05006732 }
6733 }
Mike Lockwood28569302010-01-28 11:54:40 -05006734
Adam Cohenf7522022012-10-03 20:03:18 -07006735 public void setLockOptions(Bundle options) {
6736 this.options = options;
6737 }
6738 }
6739
6740 ScreenLockTimeout mScreenLockTimeout = new ScreenLockTimeout();
6741
Jose Lima9546b202014-07-02 17:21:51 -07006742 @Override
Adam Cohenf7522022012-10-03 20:03:18 -07006743 public void lockNow(Bundle options) {
Jim Miller93c518e2012-01-17 15:55:31 -08006744 mContext.enforceCallingOrSelfPermission(android.Manifest.permission.DEVICE_POWER, null);
6745 mHandler.removeCallbacks(mScreenLockTimeout);
Adam Cohenf7522022012-10-03 20:03:18 -07006746 if (options != null) {
6747 // In case multiple calls are made to lockNow, we don't wipe out the options
6748 // until the runnable actually executes.
6749 mScreenLockTimeout.setLockOptions(options);
6750 }
Jim Miller93c518e2012-01-17 15:55:31 -08006751 mHandler.post(mScreenLockTimeout);
6752 }
6753
Mike Lockwood28569302010-01-28 11:54:40 -05006754 private void updateLockScreenTimeout() {
6755 synchronized (mScreenLockTimeout) {
Jeff Brown3ee549c2014-09-22 20:14:39 -07006756 boolean enable = (mAllowLockscreenWhenOn && mAwake &&
Jim Miller5ecd8112013-01-09 18:50:26 -08006757 mKeyguardDelegate != null && mKeyguardDelegate.isSecure());
Mike Lockwood28569302010-01-28 11:54:40 -05006758 if (mLockScreenTimerActive != enable) {
6759 if (enable) {
6760 if (localLOGV) Log.v(TAG, "setting lockscreen timer");
Jim Miller2967f482016-01-07 15:05:32 -08006761 mHandler.removeCallbacks(mScreenLockTimeout); // remove any pending requests
Mike Lockwood28569302010-01-28 11:54:40 -05006762 mHandler.postDelayed(mScreenLockTimeout, mLockScreenTimeout);
6763 } else {
6764 if (localLOGV) Log.v(TAG, "clearing lockscreen timer");
6765 mHandler.removeCallbacks(mScreenLockTimeout);
6766 }
6767 mLockScreenTimerActive = enable;
6768 }
6769 }
6770 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006771
Jeff Brown061ea992015-04-17 19:55:47 -07006772 private void updateDreamingSleepToken(boolean acquire) {
6773 if (acquire) {
6774 if (mDreamingSleepToken == null) {
6775 mDreamingSleepToken = mActivityManagerInternal.acquireSleepToken("Dream");
6776 }
6777 } else {
6778 if (mDreamingSleepToken != null) {
6779 mDreamingSleepToken.release();
Jeff Brown48d1b142015-06-10 16:36:03 -07006780 mDreamingSleepToken = null;
6781 }
6782 }
6783 }
6784
6785 private void updateScreenOffSleepToken(boolean acquire) {
6786 if (acquire) {
6787 if (mScreenOffSleepToken == null) {
6788 mScreenOffSleepToken = mActivityManagerInternal.acquireSleepToken("ScreenOff");
6789 }
6790 } else {
6791 if (mScreenOffSleepToken != null) {
6792 mScreenOffSleepToken.release();
6793 mScreenOffSleepToken = null;
Jeff Brown061ea992015-04-17 19:55:47 -07006794 }
6795 }
6796 }
6797
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006798 /** {@inheritDoc} */
Craig Mautnereda67292013-04-28 13:50:14 -07006799 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006800 public void enableScreenAfterBoot() {
6801 readLidState();
Jeff Brownc458ce92012-04-30 14:58:40 -07006802 applyLidSwitchState();
Jeff Brown01a98dd2011-09-20 15:08:29 -07006803 updateRotation(true);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006804 }
Dianne Hackbornf54c8f92009-09-19 14:03:57 -07006805
Jeff Brownc458ce92012-04-30 14:58:40 -07006806 private void applyLidSwitchState() {
Jeff Brownc458ce92012-04-30 14:58:40 -07006807 if (mLidState == LID_CLOSED && mLidControlsSleep) {
Jeff Brown6d8fd272014-05-20 21:24:38 -07006808 mPowerManager.goToSleep(SystemClock.uptimeMillis(),
Jeff Brownc12035c2014-08-13 18:52:25 -07006809 PowerManager.GO_TO_SLEEP_REASON_LID_SWITCH,
Jeff Brown6d8fd272014-05-20 21:24:38 -07006810 PowerManager.GO_TO_SLEEP_FLAG_NO_DOZE);
Edward Savage-Jones7def60d2015-11-13 13:27:03 +01006811 } else if (mLidState == LID_CLOSED && mLidControlsScreenLock) {
6812 mWindowManagerFuncs.lockDeviceNow();
Jeff Brownc458ce92012-04-30 14:58:40 -07006813 }
Jeff Browna20dda42014-05-27 20:57:24 -07006814
6815 synchronized (mLock) {
6816 updateWakeGestureListenerLp();
6817 }
Jeff Brown01a98dd2011-09-20 15:08:29 -07006818 }
6819
Jeff Brown4f5fa282014-06-12 19:19:15 -07006820 void updateUiMode() {
6821 if (mUiModeManager == null) {
6822 mUiModeManager = IUiModeManager.Stub.asInterface(
6823 ServiceManager.getService(Context.UI_MODE_SERVICE));
6824 }
6825 try {
6826 mUiMode = mUiModeManager.getCurrentModeType();
6827 } catch (RemoteException e) {
6828 }
6829 }
6830
Jeff Brown01a98dd2011-09-20 15:08:29 -07006831 void updateRotation(boolean alwaysSendConfiguration) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006832 try {
6833 //set orientation on WindowManager
Dianne Hackbornf87d1962012-04-04 12:48:24 -07006834 mWindowManager.updateRotation(alwaysSendConfiguration, false);
6835 } catch (RemoteException e) {
6836 // Ignore
6837 }
6838 }
6839
6840 void updateRotation(boolean alwaysSendConfiguration, boolean forceRelayout) {
6841 try {
6842 //set orientation on WindowManager
6843 mWindowManager.updateRotation(alwaysSendConfiguration, forceRelayout);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006844 } catch (RemoteException e) {
6845 // Ignore
6846 }
6847 }
6848
Daniel Sandler6396c722013-04-16 20:19:09 -04006849 /**
6850 * Return an Intent to launch the currently active dock app as home. Returns
6851 * null if the standard home should be launched, which is the case if any of the following is
6852 * true:
6853 * <ul>
6854 * <li>The device is not in either car mode or desk mode
keunyounga7710492015-09-23 11:33:58 -07006855 * <li>The device is in car mode but mEnableCarDockHomeCapture is false
Daniel Sandler6396c722013-04-16 20:19:09 -04006856 * <li>The device is in desk mode but ENABLE_DESK_DOCK_HOME_CAPTURE is false
6857 * <li>The device is in car mode but there's no CAR_DOCK app with METADATA_DOCK_HOME
6858 * <li>The device is in desk mode but there's no DESK_DOCK app with METADATA_DOCK_HOME
6859 * </ul>
Craig Mautnereda67292013-04-28 13:50:14 -07006860 * @return A dock intent.
Daniel Sandler6396c722013-04-16 20:19:09 -04006861 */
6862 Intent createHomeDockIntent() {
6863 Intent intent = null;
6864
6865 // What home does is based on the mode, not the dock state. That
6866 // is, when in car mode you should be taken to car home regardless
6867 // of whether we are actually in a car dock.
6868 if (mUiMode == Configuration.UI_MODE_TYPE_CAR) {
keunyounga7710492015-09-23 11:33:58 -07006869 if (mEnableCarDockHomeCapture) {
Daniel Sandler6396c722013-04-16 20:19:09 -04006870 intent = mCarDockIntent;
6871 }
6872 } else if (mUiMode == Configuration.UI_MODE_TYPE_DESK) {
6873 if (ENABLE_DESK_DOCK_HOME_CAPTURE) {
6874 intent = mDeskDockIntent;
6875 }
Jeff Brown4f5fa282014-06-12 19:19:15 -07006876 } else if (mUiMode == Configuration.UI_MODE_TYPE_WATCH
6877 && (mDockMode == Intent.EXTRA_DOCK_STATE_DESK
6878 || mDockMode == Intent.EXTRA_DOCK_STATE_HE_DESK
6879 || mDockMode == Intent.EXTRA_DOCK_STATE_LE_DESK)) {
6880 // Always launch dock home from home when watch is docked, if it exists.
6881 intent = mDeskDockIntent;
Daniel Sandler6396c722013-04-16 20:19:09 -04006882 }
6883
6884 if (intent == null) {
6885 return null;
6886 }
6887
6888 ActivityInfo ai = null;
6889 ResolveInfo info = mContext.getPackageManager().resolveActivityAsUser(
6890 intent,
John Spurlockf56bef12013-07-09 09:51:46 -04006891 PackageManager.MATCH_DEFAULT_ONLY | PackageManager.GET_META_DATA,
Craig Mautnerd625ab22013-09-06 13:40:31 -07006892 mCurrentUserId);
Daniel Sandler6396c722013-04-16 20:19:09 -04006893 if (info != null) {
6894 ai = info.activityInfo;
6895 }
6896 if (ai != null
6897 && ai.metaData != null
6898 && ai.metaData.getBoolean(Intent.METADATA_DOCK_HOME)) {
6899 intent = new Intent(intent);
6900 intent.setClassName(ai.packageName, ai.name);
6901 return intent;
6902 }
6903
6904 return null;
6905 }
6906
Filip Gruszczynskia483a1d2015-03-17 19:06:58 +00006907 void startDockOrHome(boolean fromHomeKey, boolean awakenFromDreams) {
6908 if (awakenFromDreams) {
6909 awakenDreams();
6910 }
Daniel Sandler6396c722013-04-16 20:19:09 -04006911
6912 Intent dock = createHomeDockIntent();
6913 if (dock != null) {
6914 try {
Bryce Lee01b0c5f2015-02-05 18:24:04 -08006915 if (fromHomeKey) {
6916 dock.putExtra(WindowManagerPolicy.EXTRA_FROM_HOME_KEY, fromHomeKey);
6917 }
Bart Sears8b1c27c2015-03-18 23:51:02 +00006918 startActivityAsUser(dock, UserHandle.CURRENT);
Daniel Sandler6396c722013-04-16 20:19:09 -04006919 return;
6920 } catch (ActivityNotFoundException e) {
6921 }
6922 }
6923
Bryce Lee01b0c5f2015-02-05 18:24:04 -08006924 Intent intent;
6925
6926 if (fromHomeKey) {
6927 intent = new Intent(mHomeIntent);
6928 intent.putExtra(WindowManagerPolicy.EXTRA_FROM_HOME_KEY, fromHomeKey);
6929 } else {
6930 intent = mHomeIntent;
6931 }
6932
Bryce Lee9fc0b6f2015-03-19 21:37:45 +00006933 startActivityAsUser(intent, UserHandle.CURRENT);
Dianne Hackborn39c2d712009-09-22 11:41:31 -07006934 }
Craig Mautnereda67292013-04-28 13:50:14 -07006935
Dianne Hackborn39c2d712009-09-22 11:41:31 -07006936 /**
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006937 * goes to the home screen
6938 * @return whether it did anything
6939 */
6940 boolean goHome() {
Bart Sears8b1c27c2015-03-18 23:51:02 +00006941 if (!isUserSetupComplete()) {
6942 Slog.i(TAG, "Not going home because user setup is in progress.");
6943 return false;
6944 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006945 if (false) {
6946 // This code always brings home to the front.
Dianne Hackborn256dd3b2009-05-19 18:51:21 -07006947 try {
6948 ActivityManagerNative.getDefault().stopAppSwitches();
6949 } catch (RemoteException e) {
6950 }
Dianne Hackborn94a679d2009-07-28 17:51:07 -07006951 sendCloseSystemWindows();
Filip Gruszczynskia483a1d2015-03-17 19:06:58 +00006952 startDockOrHome(false /*fromHomeKey*/, true /* awakenFromDreams */);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006953 } else {
6954 // This code brings home to the front or, if it is already
6955 // at the front, puts the device to sleep.
6956 try {
Wink Savilled2e6a332010-02-12 12:12:06 -08006957 if (SystemProperties.getInt("persist.sys.uts-test-mode", 0) == 1) {
6958 /// Roll back EndcallBehavior as the cupcake design to pass P1 lab entry.
6959 Log.d(TAG, "UTS-TEST-MODE");
6960 } else {
6961 ActivityManagerNative.getDefault().stopAppSwitches();
6962 sendCloseSystemWindows();
Daniel Sandler6396c722013-04-16 20:19:09 -04006963 Intent dock = createHomeDockIntent();
6964 if (dock != null) {
6965 int result = ActivityManagerNative.getDefault()
6966 .startActivityAsUser(null, null, dock,
6967 dock.resolveTypeIfNeeded(mContext.getContentResolver()),
6968 null, null, 0,
6969 ActivityManager.START_FLAG_ONLY_IF_NEEDED,
Jeff Hao1b012d32014-08-20 10:35:34 -07006970 null, null, UserHandle.USER_CURRENT);
Daniel Sandler6396c722013-04-16 20:19:09 -04006971 if (result == ActivityManager.START_RETURN_INTENT_TO_CALLER) {
6972 return false;
6973 }
6974 }
Dianne Hackborn39c2d712009-09-22 11:41:31 -07006975 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006976 int result = ActivityManagerNative.getDefault()
Dianne Hackbornf265ea92013-01-31 15:00:51 -08006977 .startActivityAsUser(null, null, mHomeIntent,
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006978 mHomeIntent.resolveTypeIfNeeded(mContext.getContentResolver()),
Dianne Hackborna4972e92012-03-14 10:38:05 -07006979 null, null, 0,
6980 ActivityManager.START_FLAG_ONLY_IF_NEEDED,
Jeff Hao1b012d32014-08-20 10:35:34 -07006981 null, null, UserHandle.USER_CURRENT);
Dianne Hackborna4972e92012-03-14 10:38:05 -07006982 if (result == ActivityManager.START_RETURN_INTENT_TO_CALLER) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006983 return false;
6984 }
6985 } catch (RemoteException ex) {
6986 // bummer, the activity manager, which is in this process, is dead
6987 }
6988 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006989 return true;
6990 }
Craig Mautnereda67292013-04-28 13:50:14 -07006991
6992 @Override
The Android Open Source Project0727d222009-03-11 12:11:58 -07006993 public void setCurrentOrientationLw(int newOrientation) {
6994 synchronized (mLock) {
6995 if (newOrientation != mCurrentAppOrientation) {
6996 mCurrentAppOrientation = newOrientation;
6997 updateOrientationListenerLp();
6998 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006999 }
7000 }
Amith Yamasanic33cb712010-02-10 15:21:49 -08007001
Svetoslav Ganov7befb7d2012-09-27 16:49:23 -07007002 private void performAuditoryFeedbackForAccessibilityIfNeed() {
7003 if (!isGlobalAccessibilityGestureEnabled()) {
7004 return;
7005 }
7006 AudioManager audioManager = (AudioManager) mContext.getSystemService(
7007 Context.AUDIO_SERVICE);
7008 if (audioManager.isSilentMode()) {
7009 return;
7010 }
7011 Ringtone ringTone = RingtoneManager.getRingtone(mContext,
7012 Settings.System.DEFAULT_NOTIFICATION_URI);
7013 ringTone.setStreamType(AudioManager.STREAM_MUSIC);
7014 ringTone.play();
7015 }
Craig Mautnereda67292013-04-28 13:50:14 -07007016
Bryce Lee584a4452014-10-21 15:55:55 -07007017 private boolean isTheaterModeEnabled() {
7018 return Settings.Global.getInt(mContext.getContentResolver(),
7019 Settings.Global.THEATER_MODE_ON, 0) == 1;
7020 }
7021
Svetoslav Ganov7befb7d2012-09-27 16:49:23 -07007022 private boolean isGlobalAccessibilityGestureEnabled() {
7023 return Settings.Global.getInt(mContext.getContentResolver(),
7024 Settings.Global.ENABLE_ACCESSIBILITY_GLOBAL_GESTURE_ENABLED, 0) == 1;
7025 }
7026
Craig Mautnereda67292013-04-28 13:50:14 -07007027 @Override
The Android Open Source Project0727d222009-03-11 12:11:58 -07007028 public boolean performHapticFeedbackLw(WindowState win, int effectId, boolean always) {
Svetoslav Ganov96179212012-10-10 14:17:45 -07007029 if (!mVibrator.hasVibrator()) {
7030 return false;
7031 }
Christopher Tate5e08af02012-09-21 17:17:22 -07007032 final boolean hapticsDisabled = Settings.System.getIntForUser(mContext.getContentResolver(),
7033 Settings.System.HAPTIC_FEEDBACK_ENABLED, 0, UserHandle.USER_CURRENT) == 0;
Jeff Brown82379ba2014-07-25 19:03:28 -07007034 if (hapticsDisabled && !always) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08007035 return false;
7036 }
Amith Yamasanic33cb712010-02-10 15:21:49 -08007037 long[] pattern = null;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08007038 switch (effectId) {
7039 case HapticFeedbackConstants.LONG_PRESS:
Amith Yamasanic33cb712010-02-10 15:21:49 -08007040 pattern = mLongPressVibePattern;
7041 break;
Dianne Hackbornb1a79802009-09-29 15:18:31 -07007042 case HapticFeedbackConstants.VIRTUAL_KEY:
Amith Yamasanic33cb712010-02-10 15:21:49 -08007043 pattern = mVirtualKeyVibePattern;
7044 break;
7045 case HapticFeedbackConstants.KEYBOARD_TAP:
7046 pattern = mKeyboardTapVibePattern;
7047 break;
Fabrice Di Meglioeeff63a2013-08-05 12:07:24 -07007048 case HapticFeedbackConstants.CLOCK_TICK:
7049 pattern = mClockTickVibePattern;
7050 break;
Fabrice Di Megliobd9152f2013-10-01 11:21:31 -07007051 case HapticFeedbackConstants.CALENDAR_DATE:
7052 pattern = mCalendarDateVibePattern;
7053 break;
Dianne Hackbornb1a79802009-09-29 15:18:31 -07007054 case HapticFeedbackConstants.SAFE_MODE_DISABLED:
Amith Yamasanic33cb712010-02-10 15:21:49 -08007055 pattern = mSafeModeDisabledVibePattern;
7056 break;
Dianne Hackbornb1a79802009-09-29 15:18:31 -07007057 case HapticFeedbackConstants.SAFE_MODE_ENABLED:
Amith Yamasanic33cb712010-02-10 15:21:49 -08007058 pattern = mSafeModeEnabledVibePattern;
7059 break;
Mady Mellore8608912015-06-05 09:02:55 -07007060 case HapticFeedbackConstants.CONTEXT_CLICK:
7061 pattern = mContextClickVibePattern;
Mady Mellore82067b2015-04-30 09:58:35 -07007062 break;
Amith Yamasanic33cb712010-02-10 15:21:49 -08007063 default:
7064 return false;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08007065 }
Dianne Hackbornf265ea92013-01-31 15:00:51 -08007066 int owningUid;
7067 String owningPackage;
7068 if (win != null) {
7069 owningUid = win.getOwningUid();
7070 owningPackage = win.getOwningPackage();
7071 } else {
7072 owningUid = android.os.Process.myUid();
Dianne Hackborn95d78532013-09-11 09:51:14 -07007073 owningPackage = mContext.getOpPackageName();
Dianne Hackbornf265ea92013-01-31 15:00:51 -08007074 }
Amith Yamasanic33cb712010-02-10 15:21:49 -08007075 if (pattern.length == 1) {
7076 // One-shot vibration
John Spurlock7b414672014-07-18 13:02:39 -04007077 mVibrator.vibrate(owningUid, owningPackage, pattern[0], VIBRATION_ATTRIBUTES);
Amith Yamasanic33cb712010-02-10 15:21:49 -08007078 } else {
7079 // Pattern vibration
John Spurlock7b414672014-07-18 13:02:39 -04007080 mVibrator.vibrate(owningUid, owningPackage, pattern, -1, VIBRATION_ATTRIBUTES);
Amith Yamasanic33cb712010-02-10 15:21:49 -08007081 }
7082 return true;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08007083 }
Jeff Brownc38c9be2012-10-04 13:16:19 -07007084
7085 @Override
7086 public void keepScreenOnStartedLw() {
Daniel Sandler0601eb72011-04-13 01:01:32 -04007087 }
7088
Jeff Brownc38c9be2012-10-04 13:16:19 -07007089 @Override
7090 public void keepScreenOnStoppedLw() {
Jim Millerab954542014-10-10 18:21:49 -07007091 if (isKeyguardShowingAndNotOccluded()) {
Jim Miller25190572013-02-28 17:36:24 -08007092 mPowerManager.userActivity(SystemClock.uptimeMillis(), false);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08007093 }
7094 }
Mike Lockwoodfcb39242009-10-21 23:01:07 -04007095
Dianne Hackborndf89e652011-10-06 22:35:11 -07007096 private int updateSystemUiVisibilityLw() {
Joe Onorato664644d2011-01-23 17:53:23 -08007097 // If there is no window focused, there will be nobody to handle the events
7098 // anyway, so just hang on in whatever state we're in until things settle down.
Adrian Roos53f28ec2014-10-29 17:26:12 +01007099 final WindowState win = mFocusedWindow != null ? mFocusedWindow
7100 : mTopFullscreenOpaqueWindowState;
John Spurlock79da8332013-09-20 12:04:47 -04007101 if (win == null) {
Dianne Hackborndf89e652011-10-06 22:35:11 -07007102 return 0;
7103 }
Jorim Jaggi380ecb82014-03-14 17:25:20 +01007104 if ((win.getAttrs().privateFlags & PRIVATE_FLAG_KEYGUARD) != 0 && mHideLockScreen == true) {
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07007105 // We are updating at a point where the keyguard has gotten
7106 // focus, but we were last in a state where the top window is
7107 // hiding it. This is probably because the keyguard as been
7108 // shown while the top window was displayed, so we want to ignore
7109 // it here because this is just a very transient change and it
7110 // will quickly lose focus once it correctly gets hidden.
7111 return 0;
7112 }
John Spurlock32beb2c2013-03-11 10:16:47 -04007113
John Spurlock1db8b682014-02-18 11:18:59 -05007114 int tmpVisibility = PolicyControl.getSystemUiVisibility(win, null)
Dianne Hackborne26ab702011-10-16 13:21:33 -07007115 & ~mResettingSystemUiFlags
7116 & ~mForceClearedSystemUiFlags;
John Spurlock79da8332013-09-20 12:04:47 -04007117 if (mForcingShowNavBar && win.getSurfaceLayer() < mForcingShowNavBarLayer) {
John Spurlockc6d1c602014-01-17 15:22:06 -05007118 tmpVisibility &= ~PolicyControl.adjustClearableFlags(win, View.SYSTEM_UI_CLEARABLE_FLAGS);
Dianne Hackborn891d3fb2013-01-09 18:31:37 -08007119 }
Thanh Hai Mai6c009f52015-09-01 16:27:32 -07007120
7121 if (mUiMode == Configuration.UI_MODE_TYPE_CAR) {
7122 tmpVisibility |= StatusBarManager.DISABLE_RECENT;
7123 }
7124
Jorim Jaggi86905582016-02-09 21:36:09 -08007125 final int fullscreenVisibility = updateLightStatusBarLw(0 /* vis */,
7126 mTopFullscreenOpaqueWindowState, mTopFullscreenOpaqueOrDimmingWindowState);
7127 final int dockedVisibility = updateLightStatusBarLw(0 /* vis */,
7128 mTopDockedOpaqueWindowState, mTopDockedOpaqueOrDimmingWindowState);
7129 mWindowManagerFuncs.getStackBounds(HOME_STACK_ID, mNonDockedStackBounds);
7130 mWindowManagerFuncs.getStackBounds(DOCKED_STACK_ID, mDockedStackBounds);
John Spurlock79da8332013-09-20 12:04:47 -04007131 final int visibility = updateSystemBarsLw(win, mLastSystemUiFlags, tmpVisibility);
John Spurlockad3e6cb2013-04-30 08:47:43 -04007132 final int diff = visibility ^ mLastSystemUiFlags;
Jorim Jaggi86905582016-02-09 21:36:09 -08007133 final int fullscreenDiff = fullscreenVisibility ^ mLastFullscreenStackSysUiFlags;
7134 final int dockedDiff = dockedVisibility ^ mLastDockedStackSysUiFlags;
John Spurlock79da8332013-09-20 12:04:47 -04007135 final boolean needsMenu = win.getNeedsMenuLw(mTopFullscreenOpaqueWindowState);
Jorim Jaggi86905582016-02-09 21:36:09 -08007136 if (diff == 0 && fullscreenDiff == 0 && dockedDiff == 0 && mLastFocusNeedsMenu == needsMenu
7137 && mFocusedApp == win.getAppToken()
7138 && mLastNonDockedStackBounds.equals(mNonDockedStackBounds)
7139 && mLastDockedStackBounds.equals(mDockedStackBounds)) {
Dianne Hackborndf89e652011-10-06 22:35:11 -07007140 return 0;
7141 }
Dianne Hackborne26ab702011-10-16 13:21:33 -07007142 mLastSystemUiFlags = visibility;
Jorim Jaggi86905582016-02-09 21:36:09 -08007143 mLastFullscreenStackSysUiFlags = fullscreenVisibility;
7144 mLastDockedStackSysUiFlags = dockedVisibility;
Dianne Hackborn4eff8d32011-11-10 19:38:40 -08007145 mLastFocusNeedsMenu = needsMenu;
John Spurlock79da8332013-09-20 12:04:47 -04007146 mFocusedApp = win.getAppToken();
Jorim Jaggi86905582016-02-09 21:36:09 -08007147 final Rect fullscreenStackBounds = new Rect(mNonDockedStackBounds);
7148 final Rect dockedStackBounds = new Rect(mDockedStackBounds);
Dianne Hackborndf89e652011-10-06 22:35:11 -07007149 mHandler.post(new Runnable() {
Craig Mautnereda67292013-04-28 13:50:14 -07007150 @Override
Dianne Hackborndf89e652011-10-06 22:35:11 -07007151 public void run() {
Jorim Jaggi86905582016-02-09 21:36:09 -08007152 StatusBarManagerInternal statusbar = getStatusBarManagerInternal();
7153 if (statusbar != null) {
7154 statusbar.setSystemUiVisibility(visibility, fullscreenVisibility,
7155 dockedVisibility, 0xffffffff, fullscreenStackBounds,
7156 dockedStackBounds, win.toString());
7157 statusbar.topAppWindowChanged(needsMenu);
Joe Onorato664644d2011-01-23 17:53:23 -08007158 }
Dianne Hackborndf89e652011-10-06 22:35:11 -07007159 }
7160 });
7161 return diff;
Joe Onorato664644d2011-01-23 17:53:23 -08007162 }
7163
Jorim Jaggi86905582016-02-09 21:36:09 -08007164 private int updateLightStatusBarLw(int vis, WindowState opaque, WindowState opaqueOrDimming) {
Adrian Rooscd3884d2015-02-18 17:25:23 +01007165 WindowState statusColorWin = isStatusBarKeyguard() && !mHideLockScreen
7166 ? mStatusBar
Jorim Jaggi86905582016-02-09 21:36:09 -08007167 : opaqueOrDimming;
Adrian Rooscd3884d2015-02-18 17:25:23 +01007168
7169 if (statusColorWin != null) {
Jorim Jaggi86905582016-02-09 21:36:09 -08007170 if (statusColorWin == opaque) {
Adrian Rooscd3884d2015-02-18 17:25:23 +01007171 // If the top fullscreen-or-dimming window is also the top fullscreen, respect
7172 // its light flag.
7173 vis &= ~View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR;
7174 vis |= PolicyControl.getSystemUiVisibility(statusColorWin, null)
7175 & View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR;
7176 } else if (statusColorWin != null && statusColorWin.isDimming()) {
7177 // Otherwise if it's dimming, clear the light flag.
7178 vis &= ~View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR;
7179 }
7180 }
7181 return vis;
7182 }
7183
John Spurlock79da8332013-09-20 12:04:47 -04007184 private int updateSystemBarsLw(WindowState win, int oldVis, int vis) {
Wale Ogunwale6e94a9e2015-10-07 15:35:49 -07007185 final boolean dockedStackVisible = mWindowManagerInternal.isStackVisible(DOCKED_STACK_ID);
7186 final boolean freeformStackVisible =
7187 mWindowManagerInternal.isStackVisible(FREEFORM_WORKSPACE_STACK_ID);
Jorim Jaggi9511b0f2016-01-29 19:12:44 -08007188 final boolean resizing = mWindowManagerInternal.isDockedDividerResizing();
7189
7190 // We need to force system bars when the docked stack is visible, when the freeform stack
7191 // is visible but also when we are resizing for the transitions when docked stack
7192 // visibility changes.
Jorim Jaggi0ffd49c2016-02-12 15:04:21 -08007193 mForceShowSystemBars = dockedStackVisible || freeformStackVisible || resizing;
Yorke Lee9b2ffb32016-03-07 20:42:01 -08007194 final boolean forceOpaqueStatusBar = mForceShowSystemBars && !mForceStatusBarFromKeyguard;
Wale Ogunwale6e94a9e2015-10-07 15:35:49 -07007195
John Spurlockbd957402013-10-03 11:38:39 -04007196 // apply translucent bar vis flags
Jorim Jaggi380ecb82014-03-14 17:25:20 +01007197 WindowState transWin = isStatusBarKeyguard() && !mHideLockScreen
7198 ? mStatusBar
John Spurlockbd957402013-10-03 11:38:39 -04007199 : mTopFullscreenOpaqueWindowState;
7200 vis = mStatusBarController.applyTranslucentFlagLw(transWin, vis, oldVis);
7201 vis = mNavigationBarController.applyTranslucentFlagLw(transWin, vis, oldVis);
7202
John Spurlock27735a42013-08-14 17:57:38 -04007203 // prevent status bar interaction from clearing certain flags
Selim Cinekf83e8242015-05-19 18:08:14 -07007204 int type = win.getAttrs().type;
7205 boolean statusBarHasFocus = type == TYPE_STATUS_BAR;
John Spurlock08ffcf52014-07-11 10:13:46 -04007206 if (statusBarHasFocus && !isStatusBarKeyguard()) {
John Spurlockad3e6cb2013-04-30 08:47:43 -04007207 int flags = View.SYSTEM_UI_FLAG_FULLSCREEN
7208 | View.SYSTEM_UI_FLAG_HIDE_NAVIGATION
John Spurlockcfc359a2013-09-05 10:42:03 -04007209 | View.SYSTEM_UI_FLAG_IMMERSIVE
Jorim Jaggi73fef8d2015-02-16 17:32:28 +01007210 | View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY
7211 | View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR;
John Spurlock08ffcf52014-07-11 10:13:46 -04007212 if (mHideLockScreen) {
Jorim Jaggi5cf17872014-03-26 18:31:48 +01007213 flags |= View.STATUS_BAR_TRANSLUCENT | View.NAVIGATION_BAR_TRANSLUCENT;
7214 }
John Spurlockbd957402013-10-03 11:38:39 -04007215 vis = (vis & ~flags) | (oldVis & flags);
John Spurlockad3e6cb2013-04-30 08:47:43 -04007216 }
John Spurlockad3e6cb2013-04-30 08:47:43 -04007217
Wale Ogunwale6e94a9e2015-10-07 15:35:49 -07007218 if ((!areTranslucentBarsAllowed() && transWin != mStatusBar)
Yorke Lee9b2ffb32016-03-07 20:42:01 -08007219 || forceOpaqueStatusBar) {
7220 vis &= ~(View.STATUS_BAR_TRANSLUCENT | View.STATUS_BAR_TRANSPARENT);
Alan Viverette5a0f4ec2013-10-07 15:10:29 -07007221 }
7222
Yorke Lee9b2ffb32016-03-07 20:42:01 -08007223 vis = configureNavBarOpacity(vis, dockedStackVisible, freeformStackVisible, resizing);
Yorke Lee2e4b7322016-03-02 17:33:06 -08007224
Jorim Jaggi4fa78922015-11-30 17:13:56 -08007225 if (mForceWindowDrawsStatusBarBackground) {
7226 vis |= View.STATUS_BAR_TRANSPARENT;
7227 vis &= ~View.STATUS_BAR_TRANSLUCENT;
7228 }
7229
John Spurlock27735a42013-08-14 17:57:38 -04007230 // update status bar
John Spurlockf1a36642013-10-12 17:50:42 -04007231 boolean immersiveSticky =
7232 (vis & View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY) != 0;
Wale Ogunwale6e94a9e2015-10-07 15:35:49 -07007233 final boolean hideStatusBarWM =
7234 mTopFullscreenOpaqueWindowState != null
7235 && (PolicyControl.getWindowFlags(mTopFullscreenOpaqueWindowState, null)
John Spurlock27735a42013-08-14 17:57:38 -04007236 & WindowManager.LayoutParams.FLAG_FULLSCREEN) != 0;
Wale Ogunwale6e94a9e2015-10-07 15:35:49 -07007237 final boolean hideStatusBarSysui =
John Spurlock27735a42013-08-14 17:57:38 -04007238 (vis & View.SYSTEM_UI_FLAG_FULLSCREEN) != 0;
Wale Ogunwale6e94a9e2015-10-07 15:35:49 -07007239 final boolean hideNavBarSysui =
John Spurlockf1a36642013-10-12 17:50:42 -04007240 (vis & View.SYSTEM_UI_FLAG_HIDE_NAVIGATION) != 0;
John Spurlockad3e6cb2013-04-30 08:47:43 -04007241
Wale Ogunwale6e94a9e2015-10-07 15:35:49 -07007242 final boolean transientStatusBarAllowed = mStatusBar != null
Jorim Jaggi0ffd49c2016-02-12 15:04:21 -08007243 && (statusBarHasFocus || (!mForceShowSystemBars
Wale Ogunwale6e94a9e2015-10-07 15:35:49 -07007244 && (hideStatusBarWM || (hideStatusBarSysui && immersiveSticky))));
John Spurlock27735a42013-08-14 17:57:38 -04007245
Wale Ogunwale6e94a9e2015-10-07 15:35:49 -07007246 final boolean transientNavBarAllowed = mNavigationBar != null
Jorim Jaggi0ffd49c2016-02-12 15:04:21 -08007247 && !mForceShowSystemBars && hideNavBarSysui && immersiveSticky;
John Spurlockf1a36642013-10-12 17:50:42 -04007248
Adrian Roosddc8b272015-05-21 16:28:27 -07007249 final long now = SystemClock.uptimeMillis();
7250 final boolean pendingPanic = mPendingPanicGestureUptime != 0
7251 && now - mPendingPanicGestureUptime <= PANIC_GESTURE_EXPIRATION;
7252 if (pendingPanic && hideNavBarSysui && !isStatusBarKeyguard() && mKeyguardDrawComplete) {
7253 // The user performed the panic gesture recently, we're about to hide the bars,
7254 // we're no longer on the Keyguard and the screen is ready. We can now request the bars.
7255 mPendingPanicGestureUptime = 0;
7256 mStatusBarController.showTransient();
7257 mNavigationBarController.showTransient();
7258 }
7259
Wale Ogunwale6e94a9e2015-10-07 15:35:49 -07007260 final boolean denyTransientStatus = mStatusBarController.isTransientShowRequested()
John Spurlockf1a36642013-10-12 17:50:42 -04007261 && !transientStatusBarAllowed && hideStatusBarSysui;
Wale Ogunwale6e94a9e2015-10-07 15:35:49 -07007262 final boolean denyTransientNav = mNavigationBarController.isTransientShowRequested()
John Spurlockf1a36642013-10-12 17:50:42 -04007263 && !transientNavBarAllowed;
Jorim Jaggi0ffd49c2016-02-12 15:04:21 -08007264 if (denyTransientStatus || denyTransientNav || mForceShowSystemBars) {
John Spurlock27735a42013-08-14 17:57:38 -04007265 // clear the clearable flags instead
John Spurlockf1a36642013-10-12 17:50:42 -04007266 clearClearableFlagsLw();
tiger_huangc58d7562014-10-23 20:24:19 +08007267 vis &= ~View.SYSTEM_UI_CLEARABLE_FLAGS;
John Spurlockad3e6cb2013-04-30 08:47:43 -04007268 }
John Spurlock27735a42013-08-14 17:57:38 -04007269
Selim Cinekf98702e2015-05-20 22:48:40 -07007270 final boolean immersive = (vis & View.SYSTEM_UI_FLAG_IMMERSIVE) != 0;
7271 immersiveSticky = (vis & View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY) != 0;
7272 final boolean navAllowedHidden = immersive || immersiveSticky;
7273
Selim Cinekd6623612015-05-22 18:56:22 -07007274 if (hideNavBarSysui && !navAllowedHidden && windowTypeToLayerLw(win.getBaseType())
7275 > windowTypeToLayerLw(TYPE_INPUT_CONSUMER)) {
Selim Cinekf98702e2015-05-20 22:48:40 -07007276 // We can't hide the navbar from this window otherwise the input consumer would not get
7277 // the input events.
7278 vis = (vis & ~View.SYSTEM_UI_FLAG_HIDE_NAVIGATION);
7279 }
7280
John Spurlock27735a42013-08-14 17:57:38 -04007281 vis = mStatusBarController.updateVisibilityLw(transientStatusBarAllowed, oldVis, vis);
7282
7283 // update navigation bar
John Spurlockf1a36642013-10-12 17:50:42 -04007284 boolean oldImmersiveMode = isImmersiveMode(oldVis);
7285 boolean newImmersiveMode = isImmersiveMode(vis);
7286 if (win != null && oldImmersiveMode != newImmersiveMode) {
John Spurlock79da8332013-09-20 12:04:47 -04007287 final String pkg = win.getOwningPackage();
Maurice Lam99c6e072014-04-28 18:24:28 -07007288 mImmersiveModeConfirmation.immersiveModeChanged(pkg, newImmersiveMode,
7289 isUserSetupComplete());
John Spurlock34e13d92013-08-10 06:52:28 -04007290 }
John Spurlock27735a42013-08-14 17:57:38 -04007291
John Spurlockf1a36642013-10-12 17:50:42 -04007292 vis = mNavigationBarController.updateVisibilityLw(transientNavBarAllowed, oldVis, vis);
7293
John Spurlocke1f366f2013-08-05 12:22:40 -04007294 return vis;
John Spurlockad3e6cb2013-04-30 08:47:43 -04007295 }
7296
Yorke Lee9b2ffb32016-03-07 20:42:01 -08007297 /**
7298 * @return the current visibility flags with the nav-bar opacity related flags toggled based
7299 * on the nav bar opacity rules chosen by {@link #mNavBarOpacityMode}.
7300 */
7301 private int configureNavBarOpacity(int visibility, boolean dockedStackVisible,
7302 boolean freeformStackVisible, boolean isDockedDividerResizing) {
7303 if (mNavBarOpacityMode == NAV_BAR_OPAQUE_WHEN_FREEFORM_OR_DOCKED) {
7304 if (dockedStackVisible || freeformStackVisible || isDockedDividerResizing) {
7305 visibility = setNavBarOpaqueFlag(visibility);
7306 }
7307 } else if (mNavBarOpacityMode == NAV_BAR_TRANSLUCENT_WHEN_FREEFORM_OPAQUE_OTHERWISE) {
7308 if (isDockedDividerResizing) {
7309 visibility = setNavBarOpaqueFlag(visibility);
7310 } else if (freeformStackVisible) {
7311 visibility = setNavBarTranslucentFlag(visibility);
7312 } else {
7313 visibility = setNavBarOpaqueFlag(visibility);
7314 }
7315 }
7316
7317 if (!areTranslucentBarsAllowed()) {
7318 visibility &= ~View.NAVIGATION_BAR_TRANSLUCENT;
7319 }
7320 return visibility;
7321 }
7322
7323 private int setNavBarOpaqueFlag(int visibility) {
7324 return visibility &= ~(View.NAVIGATION_BAR_TRANSLUCENT | View.NAVIGATION_BAR_TRANSPARENT);
7325 }
7326
7327 private int setNavBarTranslucentFlag(int visibility) {
7328 visibility &= ~View.NAVIGATION_BAR_TRANSPARENT;
7329 return visibility |= View.NAVIGATION_BAR_TRANSLUCENT;
7330 }
7331
John Spurlockf1a36642013-10-12 17:50:42 -04007332 private void clearClearableFlagsLw() {
7333 int newVal = mResettingSystemUiFlags | View.SYSTEM_UI_CLEARABLE_FLAGS;
7334 if (newVal != mResettingSystemUiFlags) {
7335 mResettingSystemUiFlags = newVal;
7336 mWindowManagerFuncs.reevaluateStatusBarVisibility();
7337 }
7338 }
7339
7340 private boolean isImmersiveMode(int vis) {
7341 final int flags = View.SYSTEM_UI_FLAG_IMMERSIVE | View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY;
John Spurlock34e13d92013-08-10 06:52:28 -04007342 return mNavigationBar != null
7343 && (vis & View.SYSTEM_UI_FLAG_HIDE_NAVIGATION) != 0
Daniel Sandler900ece52013-10-18 15:53:27 -04007344 && (vis & flags) != 0
7345 && canHideNavigationBar();
John Spurlock34e13d92013-08-10 06:52:28 -04007346 }
7347
Alan Viverette5a0f4ec2013-10-07 15:10:29 -07007348 /**
Daniel Sandlerdd73ee42013-10-11 22:19:59 -04007349 * @return whether the navigation or status bar can be made translucent
7350 *
7351 * This should return true unless touch exploration is not enabled or
7352 * R.boolean.config_enableTranslucentDecor is false.
Alan Viverette5a0f4ec2013-10-07 15:10:29 -07007353 */
Daniel Sandlerdd73ee42013-10-11 22:19:59 -04007354 private boolean areTranslucentBarsAllowed() {
Alan Viverette817f3cd2015-08-13 11:40:14 -04007355 return mTranslucentDecorEnabled;
Alan Viverette5a0f4ec2013-10-07 15:10:29 -07007356 }
7357
Daniel Sandler0c4ccff2011-10-19 16:39:14 -04007358 // Use this instead of checking config_showNavigationBar so that it can be consistently
7359 // overridden by qemu.hw.mainkeys in the emulator.
Craig Mautnereda67292013-04-28 13:50:14 -07007360 @Override
Daniel Sandler0c4ccff2011-10-19 16:39:14 -04007361 public boolean hasNavigationBar() {
7362 return mHasNavigationBar;
7363 }
7364
satok1bc0a492012-04-25 22:47:12 +09007365 @Override
7366 public void setLastInputMethodWindowLw(WindowState ime, WindowState target) {
7367 mLastInputMethodWindow = ime;
7368 mLastInputMethodTargetWindow = target;
7369 }
7370
Craig Mautnerf1b67412012-09-19 13:18:29 -07007371 @Override
Satoshi Kataoka658c7b82013-10-10 17:03:51 +09007372 public int getInputMethodWindowVisibleHeightLw() {
7373 return mDockBottom - mCurBottom;
7374 }
7375
7376 @Override
Craig Mautnerf1b67412012-09-19 13:18:29 -07007377 public void setCurrentUserLw(int newUserId) {
Craig Mautnerd625ab22013-09-06 13:40:31 -07007378 mCurrentUserId = newUserId;
Jim Miller5ecd8112013-01-09 18:50:26 -08007379 if (mKeyguardDelegate != null) {
7380 mKeyguardDelegate.setCurrentUser(newUserId);
Craig Mautnerf1b67412012-09-19 13:18:29 -07007381 }
John Spurlock13451a22012-09-28 14:40:41 -04007382 if (mStatusBarService != null) {
7383 try {
7384 mStatusBarService.setCurrentUser(newUserId);
7385 } catch (RemoteException e) {
7386 // oh well
7387 }
7388 }
Dianne Hackborn2ea9bae2012-11-02 18:43:48 -07007389 setLastInputMethodWindowLw(null, null);
Craig Mautnerf1b67412012-09-19 13:18:29 -07007390 }
7391
7392 @Override
Svetoslav Ganov545252f2012-12-10 18:29:24 -08007393 public boolean canMagnifyWindow(int windowType) {
7394 switch (windowType) {
7395 case WindowManager.LayoutParams.TYPE_INPUT_METHOD:
7396 case WindowManager.LayoutParams.TYPE_INPUT_METHOD_DIALOG:
7397 case WindowManager.LayoutParams.TYPE_NAVIGATION_BAR:
7398 case WindowManager.LayoutParams.TYPE_MAGNIFICATION_OVERLAY: {
7399 return false;
7400 }
7401 }
7402 return true;
7403 }
7404
7405 @Override
7406 public boolean isTopLevelWindow(int windowType) {
7407 if (windowType >= WindowManager.LayoutParams.FIRST_SUB_WINDOW
7408 && windowType <= WindowManager.LayoutParams.LAST_SUB_WINDOW) {
7409 return (windowType == WindowManager.LayoutParams.TYPE_APPLICATION_ATTACHED_DIALOG);
7410 }
7411 return true;
7412 }
7413
Jim Miller4eeb4f62012-11-08 00:04:29 -08007414 @Override
Jeff Brownd7a04de2012-06-17 14:17:52 -07007415 public void dump(String prefix, PrintWriter pw, String[] args) {
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08007416 pw.print(prefix); pw.print("mSafeMode="); pw.print(mSafeMode);
Dianne Hackbornba24e4d2011-09-01 11:17:06 -07007417 pw.print(" mSystemReady="); pw.print(mSystemReady);
7418 pw.print(" mSystemBooted="); pw.println(mSystemBooted);
Jeff Brown2e7760e2012-04-11 15:14:55 -07007419 pw.print(prefix); pw.print("mLidState="); pw.print(mLidState);
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08007420 pw.print(" mLidOpenRotation="); pw.print(mLidOpenRotation);
Michael Wright3818c922014-09-02 13:59:07 -07007421 pw.print(" mCameraLensCoverState="); pw.print(mCameraLensCoverState);
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08007422 pw.print(" mHdmiPlugged="); pw.println(mHdmiPlugged);
Dianne Hackborne26ab702011-10-16 13:21:33 -07007423 if (mLastSystemUiFlags != 0 || mResettingSystemUiFlags != 0
7424 || mForceClearedSystemUiFlags != 0) {
7425 pw.print(prefix); pw.print("mLastSystemUiFlags=0x");
7426 pw.print(Integer.toHexString(mLastSystemUiFlags));
7427 pw.print(" mResettingSystemUiFlags=0x");
7428 pw.print(Integer.toHexString(mResettingSystemUiFlags));
7429 pw.print(" mForceClearedSystemUiFlags=0x");
7430 pw.println(Integer.toHexString(mForceClearedSystemUiFlags));
Dianne Hackborndf89e652011-10-06 22:35:11 -07007431 }
Dianne Hackborn4eff8d32011-11-10 19:38:40 -08007432 if (mLastFocusNeedsMenu) {
7433 pw.print(prefix); pw.print("mLastFocusNeedsMenu=");
7434 pw.println(mLastFocusNeedsMenu);
7435 }
Jeff Browna20dda42014-05-27 20:57:24 -07007436 pw.print(prefix); pw.print("mWakeGestureEnabledSetting=");
7437 pw.println(mWakeGestureEnabledSetting);
7438
Jeff Brownbcdfc622014-03-06 19:13:04 -08007439 pw.print(prefix); pw.print("mSupportAutoRotation="); pw.println(mSupportAutoRotation);
Daniel Sandler6396c722013-04-16 20:19:09 -04007440 pw.print(prefix); pw.print("mUiMode="); pw.print(mUiMode);
7441 pw.print(" mDockMode="); pw.print(mDockMode);
keunyounga7710492015-09-23 11:33:58 -07007442 pw.print(" mEnableCarDockHomeCapture="); pw.print(mEnableCarDockHomeCapture);
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08007443 pw.print(" mCarDockRotation="); pw.print(mCarDockRotation);
7444 pw.print(" mDeskDockRotation="); pw.println(mDeskDockRotation);
7445 pw.print(prefix); pw.print("mUserRotationMode="); pw.print(mUserRotationMode);
7446 pw.print(" mUserRotation="); pw.print(mUserRotation);
Daniel Sandler2ed6ad62011-02-22 14:54:17 -05007447 pw.print(" mAllowAllRotations="); pw.println(mAllowAllRotations);
Dianne Hackborn6e2281d2012-06-19 17:48:32 -07007448 pw.print(prefix); pw.print("mCurrentAppOrientation="); pw.println(mCurrentAppOrientation);
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08007449 pw.print(prefix); pw.print("mCarDockEnablesAccelerometer=");
7450 pw.print(mCarDockEnablesAccelerometer);
7451 pw.print(" mDeskDockEnablesAccelerometer=");
7452 pw.println(mDeskDockEnablesAccelerometer);
7453 pw.print(prefix); pw.print("mLidKeyboardAccessibility=");
7454 pw.print(mLidKeyboardAccessibility);
7455 pw.print(" mLidNavigationAccessibility="); pw.print(mLidNavigationAccessibility);
Edward Savage-Jones7def60d2015-11-13 13:27:03 +01007456 pw.print(" mLidControlsScreenLock="); pw.println(mLidControlsScreenLock);
Dianne Hackborn6e2281d2012-06-19 17:48:32 -07007457 pw.print(" mLidControlsSleep="); pw.println(mLidControlsSleep);
Jeff Brown6d8fd272014-05-20 21:24:38 -07007458 pw.print(prefix);
Anthony Hugh34f09ca2016-03-04 12:03:37 -08007459 pw.print(" mLongPressOnBackBehavior="); pw.println(mLongPressOnBackBehavior);
7460 pw.print(prefix);
Jeff Brown6d8fd272014-05-20 21:24:38 -07007461 pw.print("mShortPressOnPowerBehavior="); pw.print(mShortPressOnPowerBehavior);
7462 pw.print(" mLongPressOnPowerBehavior="); pw.println(mLongPressOnPowerBehavior);
Jeff Brown13f00f02014-10-31 14:45:50 -07007463 pw.print(prefix);
7464 pw.print("mDoublePressOnPowerBehavior="); pw.print(mDoublePressOnPowerBehavior);
7465 pw.print(" mTriplePressOnPowerBehavior="); pw.println(mTriplePressOnPowerBehavior);
Jeff Brown6d8fd272014-05-20 21:24:38 -07007466 pw.print(prefix); pw.print("mHasSoftInput="); pw.println(mHasSoftInput);
Jeff Brown3ee549c2014-09-22 20:14:39 -07007467 pw.print(prefix); pw.print("mAwake="); pw.println(mAwake);
7468 pw.print(prefix); pw.print("mScreenOnEarly="); pw.print(mScreenOnEarly);
7469 pw.print(" mScreenOnFully="); pw.println(mScreenOnFully);
7470 pw.print(prefix); pw.print("mKeyguardDrawComplete="); pw.print(mKeyguardDrawComplete);
7471 pw.print(" mWindowManagerDrawComplete="); pw.println(mWindowManagerDrawComplete);
7472 pw.print(prefix); pw.print("mOrientationSensorEnabled=");
7473 pw.println(mOrientationSensorEnabled);
Dianne Hackbornc652de82013-02-15 16:32:56 -08007474 pw.print(prefix); pw.print("mOverscanScreen=("); pw.print(mOverscanScreenLeft);
7475 pw.print(","); pw.print(mOverscanScreenTop);
7476 pw.print(") "); pw.print(mOverscanScreenWidth);
7477 pw.print("x"); pw.println(mOverscanScreenHeight);
7478 if (mOverscanLeft != 0 || mOverscanTop != 0
7479 || mOverscanRight != 0 || mOverscanBottom != 0) {
7480 pw.print(prefix); pw.print("mOverscan left="); pw.print(mOverscanLeft);
7481 pw.print(" top="); pw.print(mOverscanTop);
7482 pw.print(" right="); pw.print(mOverscanRight);
7483 pw.print(" bottom="); pw.println(mOverscanBottom);
7484 }
Dianne Hackborn313440842013-02-19 19:22:59 -08007485 pw.print(prefix); pw.print("mRestrictedOverscanScreen=(");
7486 pw.print(mRestrictedOverscanScreenLeft);
7487 pw.print(","); pw.print(mRestrictedOverscanScreenTop);
7488 pw.print(") "); pw.print(mRestrictedOverscanScreenWidth);
7489 pw.print("x"); pw.println(mRestrictedOverscanScreenHeight);
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08007490 pw.print(prefix); pw.print("mUnrestrictedScreen=("); pw.print(mUnrestrictedScreenLeft);
7491 pw.print(","); pw.print(mUnrestrictedScreenTop);
7492 pw.print(") "); pw.print(mUnrestrictedScreenWidth);
7493 pw.print("x"); pw.println(mUnrestrictedScreenHeight);
7494 pw.print(prefix); pw.print("mRestrictedScreen=("); pw.print(mRestrictedScreenLeft);
7495 pw.print(","); pw.print(mRestrictedScreenTop);
7496 pw.print(") "); pw.print(mRestrictedScreenWidth);
7497 pw.print("x"); pw.println(mRestrictedScreenHeight);
Dianne Hackborn5b5cc4d2012-05-16 13:15:00 -07007498 pw.print(prefix); pw.print("mStableFullscreen=("); pw.print(mStableFullscreenLeft);
7499 pw.print(","); pw.print(mStableFullscreenTop);
7500 pw.print(")-("); pw.print(mStableFullscreenRight);
7501 pw.print(","); pw.print(mStableFullscreenBottom); pw.println(")");
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07007502 pw.print(prefix); pw.print("mStable=("); pw.print(mStableLeft);
7503 pw.print(","); pw.print(mStableTop);
7504 pw.print(")-("); pw.print(mStableRight);
7505 pw.print(","); pw.print(mStableBottom); pw.println(")");
Dianne Hackborn5c58de32012-04-28 19:52:37 -07007506 pw.print(prefix); pw.print("mSystem=("); pw.print(mSystemLeft);
7507 pw.print(","); pw.print(mSystemTop);
7508 pw.print(")-("); pw.print(mSystemRight);
7509 pw.print(","); pw.print(mSystemBottom); pw.println(")");
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08007510 pw.print(prefix); pw.print("mCur=("); pw.print(mCurLeft);
7511 pw.print(","); pw.print(mCurTop);
7512 pw.print(")-("); pw.print(mCurRight);
7513 pw.print(","); pw.print(mCurBottom); pw.println(")");
7514 pw.print(prefix); pw.print("mContent=("); pw.print(mContentLeft);
7515 pw.print(","); pw.print(mContentTop);
7516 pw.print(")-("); pw.print(mContentRight);
7517 pw.print(","); pw.print(mContentBottom); pw.println(")");
Dianne Hackborne30e02f2014-05-27 18:24:45 -07007518 pw.print(prefix); pw.print("mVoiceContent=("); pw.print(mVoiceContentLeft);
7519 pw.print(","); pw.print(mVoiceContentTop);
7520 pw.print(")-("); pw.print(mVoiceContentRight);
7521 pw.print(","); pw.print(mVoiceContentBottom); pw.println(")");
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08007522 pw.print(prefix); pw.print("mDock=("); pw.print(mDockLeft);
7523 pw.print(","); pw.print(mDockTop);
7524 pw.print(")-("); pw.print(mDockRight);
7525 pw.print(","); pw.print(mDockBottom); pw.println(")");
Dianne Hackborn5c58de32012-04-28 19:52:37 -07007526 pw.print(prefix); pw.print("mDockLayer="); pw.print(mDockLayer);
7527 pw.print(" mStatusBarLayer="); pw.println(mStatusBarLayer);
Dianne Hackborn7ad44382012-10-18 17:46:00 -07007528 pw.print(prefix); pw.print("mShowingLockscreen="); pw.print(mShowingLockscreen);
7529 pw.print(" mShowingDream="); pw.print(mShowingDream);
Jeff Brown061ea992015-04-17 19:55:47 -07007530 pw.print(" mDreamingLockscreen="); pw.print(mDreamingLockscreen);
7531 pw.print(" mDreamingSleepToken="); pw.println(mDreamingSleepToken);
Dianne Hackborn2ea9bae2012-11-02 18:43:48 -07007532 if (mLastInputMethodWindow != null) {
7533 pw.print(prefix); pw.print("mLastInputMethodWindow=");
7534 pw.println(mLastInputMethodWindow);
7535 }
7536 if (mLastInputMethodTargetWindow != null) {
7537 pw.print(prefix); pw.print("mLastInputMethodTargetWindow=");
7538 pw.println(mLastInputMethodTargetWindow);
7539 }
7540 if (mStatusBar != null) {
7541 pw.print(prefix); pw.print("mStatusBar=");
Dianne Hackbornae6688b2015-02-11 17:02:41 -08007542 pw.print(mStatusBar); pw.print(" isStatusBarKeyguard=");
7543 pw.println(isStatusBarKeyguard());
Dianne Hackborn2ea9bae2012-11-02 18:43:48 -07007544 }
7545 if (mNavigationBar != null) {
7546 pw.print(prefix); pw.print("mNavigationBar=");
7547 pw.println(mNavigationBar);
7548 }
Dianne Hackborn2ea9bae2012-11-02 18:43:48 -07007549 if (mFocusedWindow != null) {
7550 pw.print(prefix); pw.print("mFocusedWindow=");
7551 pw.println(mFocusedWindow);
7552 }
7553 if (mFocusedApp != null) {
7554 pw.print(prefix); pw.print("mFocusedApp=");
7555 pw.println(mFocusedApp);
7556 }
7557 if (mWinDismissingKeyguard != null) {
7558 pw.print(prefix); pw.print("mWinDismissingKeyguard=");
7559 pw.println(mWinDismissingKeyguard);
7560 }
7561 if (mTopFullscreenOpaqueWindowState != null) {
7562 pw.print(prefix); pw.print("mTopFullscreenOpaqueWindowState=");
7563 pw.println(mTopFullscreenOpaqueWindowState);
7564 }
Adrian Rooscd3884d2015-02-18 17:25:23 +01007565 if (mTopFullscreenOpaqueOrDimmingWindowState != null) {
7566 pw.print(prefix); pw.print("mTopFullscreenOpaqueOrDimmingWindowState=");
7567 pw.println(mTopFullscreenOpaqueOrDimmingWindowState);
7568 }
Dianne Hackborn891d3fb2013-01-09 18:31:37 -08007569 if (mForcingShowNavBar) {
7570 pw.print(prefix); pw.print("mForcingShowNavBar=");
7571 pw.println(mForcingShowNavBar); pw.print( "mForcingShowNavBarLayer=");
7572 pw.println(mForcingShowNavBarLayer);
7573 }
Dianne Hackborn7ad44382012-10-18 17:46:00 -07007574 pw.print(prefix); pw.print("mTopIsFullscreen="); pw.print(mTopIsFullscreen);
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08007575 pw.print(" mHideLockScreen="); pw.println(mHideLockScreen);
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07007576 pw.print(prefix); pw.print("mForceStatusBar="); pw.print(mForceStatusBar);
7577 pw.print(" mForceStatusBarFromKeyguard=");
7578 pw.println(mForceStatusBarFromKeyguard);
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08007579 pw.print(prefix); pw.print("mDismissKeyguard="); pw.print(mDismissKeyguard);
Craig Mautnerad09bcc2012-10-08 13:33:11 -07007580 pw.print(" mWinDismissingKeyguard="); pw.print(mWinDismissingKeyguard);
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08007581 pw.print(" mHomePressed="); pw.println(mHomePressed);
7582 pw.print(prefix); pw.print("mAllowLockscreenWhenOn="); pw.print(mAllowLockscreenWhenOn);
7583 pw.print(" mLockScreenTimeout="); pw.print(mLockScreenTimeout);
7584 pw.print(" mLockScreenTimerActive="); pw.println(mLockScreenTimerActive);
7585 pw.print(prefix); pw.print("mEndcallBehavior="); pw.print(mEndcallBehavior);
7586 pw.print(" mIncallPowerBehavior="); pw.print(mIncallPowerBehavior);
7587 pw.print(" mLongPressOnHomeBehavior="); pw.println(mLongPressOnHomeBehavior);
7588 pw.print(prefix); pw.print("mLandscapeRotation="); pw.print(mLandscapeRotation);
7589 pw.print(" mSeascapeRotation="); pw.println(mSeascapeRotation);
7590 pw.print(prefix); pw.print("mPortraitRotation="); pw.print(mPortraitRotation);
7591 pw.print(" mUpsideDownRotation="); pw.println(mUpsideDownRotation);
Jeff Brownc82c89ed2013-04-17 17:18:15 -07007592 pw.print(prefix); pw.print("mDemoHdmiRotation="); pw.print(mDemoHdmiRotation);
7593 pw.print(" mDemoHdmiRotationLock="); pw.println(mDemoHdmiRotationLock);
7594 pw.print(prefix); pw.print("mUndockedHdmiRotation="); pw.println(mUndockedHdmiRotation);
Jeff Brown600f0032014-05-22 17:06:00 -07007595
Tim Kilbournd7c0c2e2014-05-29 16:08:10 -07007596 mGlobalKeyManager.dump(prefix, pw);
John Spurlock27735a42013-08-14 17:57:38 -04007597 mStatusBarController.dump(pw, prefix);
7598 mNavigationBarController.dump(pw, prefix);
John Spurlockc6d1c602014-01-17 15:22:06 -05007599 PolicyControl.dump(prefix, pw);
Jeff Brown600f0032014-05-22 17:06:00 -07007600
Jeff Browna20dda42014-05-27 20:57:24 -07007601 if (mWakeGestureListener != null) {
7602 mWakeGestureListener.dump(pw, prefix);
7603 }
Jeff Brown600f0032014-05-22 17:06:00 -07007604 if (mOrientationListener != null) {
7605 mOrientationListener.dump(pw, prefix);
7606 }
Filip Gruszczynskicfb31852015-02-25 21:47:12 +00007607 if (mBurnInProtectionHelper != null) {
7608 mBurnInProtectionHelper.dump(prefix, pw);
7609 }
Jorim Jaggi84dc08a2015-09-11 17:45:22 -07007610 if (mKeyguardDelegate != null) {
7611 mKeyguardDelegate.dump(prefix, pw);
7612 }
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08007613 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08007614}