blob: 20310611d130a72a91e49dda02a543ff877704d5 [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;
Wale Ogunwale6e94a9e2015-10-07 15:35:49 -070021import static android.view.WindowManager.LayoutParams.*;
22import static android.view.WindowManagerPolicy.WindowManagerFuncs.LID_ABSENT;
23import static android.view.WindowManagerPolicy.WindowManagerFuncs.LID_OPEN;
24import static android.view.WindowManagerPolicy.WindowManagerFuncs.LID_CLOSED;
25import static android.view.WindowManagerPolicy.WindowManagerFuncs.CAMERA_LENS_COVER_ABSENT;
26import static android.view.WindowManagerPolicy.WindowManagerFuncs.CAMERA_LENS_UNCOVERED;
27import static android.view.WindowManagerPolicy.WindowManagerFuncs.CAMERA_LENS_COVERED;
28
Dianne Hackborna4972e92012-03-14 10:38:05 -070029import android.app.ActivityManager;
Jeff Brown061ea992015-04-17 19:55:47 -070030import android.app.ActivityManagerInternal;
31import android.app.ActivityManagerInternal.SleepToken;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -080032import android.app.ActivityManagerNative;
Dianne Hackbornc2293022013-02-06 23:14:49 -080033import android.app.AppOpsManager;
Daniel Sandler6396c722013-04-16 20:19:09 -040034import android.app.IUiModeManager;
Dianne Hackborn661cd522011-08-22 00:26:20 -070035import android.app.ProgressDialog;
Jeff Brownde7a8ea2012-06-13 18:28:57 -070036import android.app.SearchManager;
John Spurlock97642182013-07-29 17:58:39 -040037import android.app.StatusBarManager;
Dianne Hackborn78968392010-03-04 20:47:56 -080038import android.app.UiModeManager;
Dianne Hackborn39c2d712009-09-22 11:41:31 -070039import android.content.ActivityNotFoundException;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -080040import android.content.BroadcastReceiver;
Daniel Sandler0601eb72011-04-13 01:01:32 -040041import android.content.ComponentName;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -080042import android.content.ContentResolver;
43import android.content.Context;
44import android.content.Intent;
Mike Lockwood1753f7f2009-08-24 14:49:07 -070045import android.content.IntentFilter;
Winson Chung9112ec32011-06-27 13:15:32 -070046import android.content.ServiceConnection;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -080047import android.content.pm.ActivityInfo;
48import android.content.pm.PackageManager;
Daniel Sandler6396c722013-04-16 20:19:09 -040049import android.content.pm.ResolveInfo;
Dianne Hackborn2f0b1752011-05-31 17:59:49 -070050import android.content.res.CompatibilityInfo;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -080051import android.content.res.Configuration;
52import android.content.res.Resources;
53import android.database.ContentObserver;
Dianne Hackbornc777e072010-02-12 13:07:59 -080054import android.graphics.PixelFormat;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -080055import android.graphics.Rect;
Jinsuk Kime601b712015-07-07 08:01:02 +090056import android.hardware.hdmi.HdmiControlManager;
57import android.hardware.hdmi.HdmiPlaybackClient;
58import android.hardware.hdmi.HdmiPlaybackClient.OneTouchPlayCallback;
John Spurlock7b414672014-07-18 13:02:39 -040059import android.media.AudioAttributes;
Michael Jurka7a348952012-02-27 13:07:58 -080060import android.media.AudioManager;
John Spurlock61560172015-02-06 19:46:04 -050061import android.media.AudioSystem;
Michael Jurka7a348952012-02-27 13:07:58 -080062import android.media.IAudioService;
Svetoslav Ganov7befb7d2012-09-27 16:49:23 -070063import android.media.Ringtone;
64import android.media.RingtoneManager;
RoboErik8a2cfc32014-05-16 11:19:38 -070065import android.media.session.MediaSessionLegacyHelper;
Billy Laucbe540f2015-06-25 01:51:44 +010066import android.os.Binder;
Dianne Hackborn38e29a62011-09-18 14:43:08 -070067import android.os.Bundle;
Craig Mautner276a6eb2014-11-04 15:32:57 -080068import android.os.Debug;
Jeff Brown9a538ee2012-08-20 14:56:57 -070069import android.os.FactoryTest;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -080070import android.os.Handler;
71import android.os.IBinder;
Dianne Hackbornb6683c42015-06-18 17:40:33 -070072import android.os.IDeviceIdleController;
Jeff Brown32cbc38552011-12-01 14:01:49 -080073import android.os.Looper;
Dianne Hackbornfc8fa632011-08-17 16:20:47 -070074import android.os.Message;
75import android.os.Messenger;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -080076import android.os.PowerManager;
Nick Armstrong-Crews56ecfcc2015-09-07 21:46:50 -070077import android.os.PowerManagerInternal;
Billy Laucbe540f2015-06-25 01:51:44 +010078import android.os.Process;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -080079import android.os.RemoteException;
80import android.os.ServiceManager;
81import android.os.SystemClock;
82import android.os.SystemProperties;
Dianne Hackbornad7fa7f2011-01-07 14:06:50 -080083import android.os.UEventObserver;
Dianne Hackbornf02b60a2012-08-16 10:48:27 -070084import android.os.UserHandle;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -080085import android.os.Vibrator;
Michael Wright3818c922014-09-02 13:59:07 -070086import android.provider.MediaStore;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -080087import android.provider.Settings;
Jose Lima9546b202014-07-02 17:21:51 -070088import android.service.dreams.DreamManagerInternal;
John Spurlockc8b46ca2013-04-08 12:59:26 -040089import android.service.dreams.DreamService;
90import android.service.dreams.IDreamManager;
Michael Wrightdc63f7b2014-08-21 19:05:21 -070091import android.speech.RecognizerIntent;
Tyler Gunnef9f6f92014-09-12 22:16:17 -070092import android.telecom.TelecomManager;
Dianne Hackborn81e56d52011-05-26 00:55:58 -070093import android.util.DisplayMetrics;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -080094import android.util.EventLog;
95import android.util.Log;
Jeff Browna41ca772010-08-11 14:46:32 -070096import android.util.Slog;
Jeff Brown6651a632011-11-28 12:59:11 -080097import android.util.SparseArray;
Dianne Hackbornf87d1962012-04-04 12:48:24 -070098import android.view.Display;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -080099import android.view.Gravity;
100import android.view.HapticFeedbackConstants;
Dianne Hackborne0f085d2011-11-30 18:41:15 -0800101import android.view.IApplicationToken;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800102import android.view.IWindowManager;
Jeff Browna41ca772010-08-11 14:46:32 -0700103import android.view.InputChannel;
Jeff Brown4d396052010-10-29 21:50:21 -0700104import android.view.InputDevice;
Jeff Brown4952dfd2011-11-30 19:23:22 -0800105import android.view.InputEvent;
Jeff Brown32cbc38552011-12-01 14:01:49 -0800106import android.view.InputEventReceiver;
Jeff Brown6b53e8d2010-11-10 16:03:06 -0800107import android.view.KeyCharacterMap;
Craig Mautnerae446592012-12-06 19:05:05 -0800108import android.view.KeyCharacterMap.FallbackAction;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800109import android.view.KeyEvent;
110import android.view.MotionEvent;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800111import android.view.Surface;
112import android.view.View;
113import android.view.ViewConfiguration;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800114import android.view.WindowManager;
Craig Mautnerae446592012-12-06 19:05:05 -0800115import android.view.WindowManagerGlobal;
Craig Mautner8a0da012014-05-31 15:13:37 -0700116import android.view.WindowManagerInternal;
Craig Mautnerae446592012-12-06 19:05:05 -0800117import android.view.WindowManagerPolicy;
Craig Mautnerae446592012-12-06 19:05:05 -0800118import android.view.accessibility.AccessibilityEvent;
Svetoslav8e3feb12014-02-24 13:46:47 -0800119import android.view.accessibility.AccessibilityManager;
Craig Mautnerae446592012-12-06 19:05:05 -0800120import android.view.animation.Animation;
Jorim Jaggi76a16232014-08-08 17:00:47 +0200121import android.view.animation.AnimationSet;
Craig Mautnerae446592012-12-06 19:05:05 -0800122import android.view.animation.AnimationUtils;
Craig Mautnerae446592012-12-06 19:05:05 -0800123import com.android.internal.R;
Jason Monk8f7f3182015-11-18 16:35:14 -0500124import com.android.internal.logging.MetricsLogger;
125import com.android.internal.policy.PhoneWindow;
Craig Mautnerae446592012-12-06 19:05:05 -0800126import com.android.internal.statusbar.IStatusBarService;
Filip Gruszczynski2217f612015-05-26 11:32:08 -0700127import com.android.internal.util.ScreenShapeHelper;
Craig Mautnerae446592012-12-06 19:05:05 -0800128import com.android.internal.widget.PointerLocationView;
Adrian Roos5941c982015-09-03 15:59:49 -0700129import com.android.server.GestureLauncherService;
Craig Mautner8a0da012014-05-31 15:13:37 -0700130import com.android.server.LocalServices;
Jorim Jaggib10e33f2015-02-04 21:57:40 +0100131import com.android.server.policy.keyguard.KeyguardServiceDelegate;
Jorim Jaggi4cfdcf52015-07-09 12:13:59 -0700132import com.android.server.policy.keyguard.KeyguardServiceDelegate.DrawnListener;
Craig Mautnerae446592012-12-06 19:05:05 -0800133
134import java.io.File;
135import java.io.FileReader;
136import java.io.IOException;
137import java.io.PrintWriter;
Craig Mautner2bc789b2014-03-19 19:48:38 -0700138import java.util.HashSet;
Craig Mautner276a6eb2014-11-04 15:32:57 -0800139import java.util.List;
Craig Mautnerae446592012-12-06 19:05:05 -0800140
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800141/**
The Android Open Source Project0727d222009-03-11 12:11:58 -0700142 * WindowManagerPolicy implementation for the Android phone UI. This
143 * introduces a new method suffix, Lp, for an internal lock of the
144 * PhoneWindowManager. This is used to protect some internal state, and
John Spurlock04db1762013-05-13 12:46:41 -0400145 * 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 -0700146 * of both of those when held.
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800147 */
148public class PhoneWindowManager implements WindowManagerPolicy {
149 static final String TAG = "WindowManager";
150 static final boolean DEBUG = false;
Joe Onorato43a17652011-04-06 19:22:23 -0700151 static final boolean localLOGV = false;
Jeff Brown40013652012-05-16 21:22:36 -0700152 static final boolean DEBUG_INPUT = false;
Craig Mautnerc0d2d0a2014-10-31 16:25:15 -0700153 static final boolean DEBUG_KEYGUARD = false;
154 static final boolean DEBUG_LAYOUT = false;
Craig Mautner6fbda632012-07-03 09:26:39 -0700155 static final boolean DEBUG_STARTING_WINDOW = false;
Craig Mautner8a0da012014-05-31 15:13:37 -0700156 static final boolean DEBUG_WAKEUP = false;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800157 static final boolean SHOW_STARTING_ANIMATIONS = true;
158 static final boolean SHOW_PROCESSES_ON_ALT_MENU = false;
Joe Onoratod208e702010-10-08 16:22:43 -0400159
Daniel Sandler6396c722013-04-16 20:19:09 -0400160 // Whether to allow dock apps with METADATA_DOCK_HOME to temporarily take over the Home key.
keunyounga7710492015-09-23 11:33:58 -0700161 // No longer recommended for desk docks;
Daniel Sandler6396c722013-04-16 20:19:09 -0400162 static final boolean ENABLE_DESK_DOCK_HOME_CAPTURE = false;
163
Jeff Brown6d8fd272014-05-20 21:24:38 -0700164 static final int SHORT_PRESS_POWER_NOTHING = 0;
165 static final int SHORT_PRESS_POWER_GO_TO_SLEEP = 1;
166 static final int SHORT_PRESS_POWER_REALLY_GO_TO_SLEEP = 2;
167 static final int SHORT_PRESS_POWER_REALLY_GO_TO_SLEEP_AND_GO_HOME = 3;
Bryce Lee01b0c5f2015-02-05 18:24:04 -0800168 static final int SHORT_PRESS_POWER_GO_HOME = 4;
Jeff Brown6d8fd272014-05-20 21:24:38 -0700169
Joe Onoratod208e702010-10-08 16:22:43 -0400170 static final int LONG_PRESS_POWER_NOTHING = 0;
171 static final int LONG_PRESS_POWER_GLOBAL_ACTIONS = 1;
172 static final int LONG_PRESS_POWER_SHUT_OFF = 2;
Jeff Brown9a538ee2012-08-20 14:56:57 -0700173 static final int LONG_PRESS_POWER_SHUT_OFF_NO_CONFIRM = 3;
Michael Jurka3b1fc472011-06-13 10:54:40 -0700174
Jeff Brown13f00f02014-10-31 14:45:50 -0700175 static final int MULTI_PRESS_POWER_NOTHING = 0;
176 static final int MULTI_PRESS_POWER_THEATER_MODE = 1;
177 static final int MULTI_PRESS_POWER_BRIGHTNESS_BOOST = 2;
178
Michael Jurka3b1fc472011-06-13 10:54:40 -0700179 // These need to match the documentation/constant in
180 // core/res/res/values/config.xml
Joe Onorato46b0d682010-11-22 17:37:27 -0800181 static final int LONG_PRESS_HOME_NOTHING = 0;
Michael Wrightc9ebea72013-01-16 19:25:02 -0800182 static final int LONG_PRESS_HOME_RECENT_SYSTEM_UI = 1;
Jeff Browncaca8812013-05-09 13:34:33 -0700183 static final int LONG_PRESS_HOME_ASSIST = 2;
184
185 static final int DOUBLE_TAP_HOME_NOTHING = 0;
186 static final int DOUBLE_TAP_HOME_RECENT_SYSTEM_UI = 1;
Joe Onorato46b0d682010-11-22 17:37:27 -0800187
Filip Gruszczynskia483a1d2015-03-17 19:06:58 +0000188 static final int SHORT_PRESS_SLEEP_GO_TO_SLEEP = 0;
189 static final int SHORT_PRESS_SLEEP_GO_TO_SLEEP_AND_GO_HOME = 1;
190
Dianne Hackborn5cb8d792009-05-21 17:34:15 -0700191 static final int APPLICATION_MEDIA_SUBLAYER = -2;
192 static final int APPLICATION_MEDIA_OVERLAY_SUBLAYER = -1;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800193 static final int APPLICATION_PANEL_SUBLAYER = 1;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800194 static final int APPLICATION_SUB_PANEL_SUBLAYER = 2;
Wale Ogunwale0a4dc222015-04-14 12:58:42 -0700195 static final int APPLICATION_ABOVE_SUB_PANEL_SUBLAYER = 3;
Craig Mautner88400d32012-09-30 12:35:45 -0700196
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800197 static public final String SYSTEM_DIALOG_REASON_KEY = "reason";
198 static public final String SYSTEM_DIALOG_REASON_GLOBAL_ACTIONS = "globalactions";
199 static public final String SYSTEM_DIALOG_REASON_RECENT_APPS = "recentapps";
Joe Onoratof275f0c2009-11-24 16:11:13 -0500200 static public final String SYSTEM_DIALOG_REASON_HOME_KEY = "homekey";
Jeff Brownde7a8ea2012-06-13 18:28:57 -0700201 static public final String SYSTEM_DIALOG_REASON_ASSIST = "assist";
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800202
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -0700203 /**
204 * These are the system UI flags that, when changing, can cause the layout
205 * of the screen to change.
206 */
207 static final int SYSTEM_UI_CHANGING_LAYOUT =
John Spurlocke1f366f2013-08-05 12:22:40 -0400208 View.SYSTEM_UI_FLAG_HIDE_NAVIGATION
John Spurlock7f4820a2013-10-08 12:54:35 -0400209 | View.SYSTEM_UI_FLAG_FULLSCREEN
210 | View.STATUS_BAR_TRANSLUCENT
Adrian Roosea562512014-05-05 13:33:03 +0200211 | View.NAVIGATION_BAR_TRANSLUCENT
212 | View.SYSTEM_UI_TRANSPARENT;
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -0700213
John Spurlock7b414672014-07-18 13:02:39 -0400214 private static final AudioAttributes VIBRATION_ATTRIBUTES = new AudioAttributes.Builder()
215 .setContentType(AudioAttributes.CONTENT_TYPE_SONIFICATION)
216 .setUsage(AudioAttributes.USAGE_ASSISTANCE_SONIFICATION)
217 .build();
218
Adrian Roosddc8b272015-05-21 16:28:27 -0700219 // The panic gesture may become active only after the keyguard is dismissed and the immersive
220 // app shows again. If that doesn't happen for 30s we drop the gesture.
221 private static final long PANIC_GESTURE_EXPIRATION = 30000;
222
Jim Miller5ecd8112013-01-09 18:50:26 -0800223 /**
224 * Keyguard stuff
225 */
226 private WindowState mKeyguardScrim;
Jorim Jaggi380ecb82014-03-14 17:25:20 +0100227 private boolean mKeyguardHidden;
Jeff Brown3ee549c2014-09-22 20:14:39 -0700228 private boolean mKeyguardDrawnOnce;
Jim Miller5ecd8112013-01-09 18:50:26 -0800229
Jeff Brown6651a632011-11-28 12:59:11 -0800230 /* Table of Application Launch keys. Maps from key codes to intent categories.
231 *
232 * These are special keys that are used to launch particular kinds of applications,
233 * such as a web browser. HID defines nearly a hundred of them in the Consumer (0x0C)
234 * usage page. We don't support quite that many yet...
235 */
236 static SparseArray<String> sApplicationLaunchKeyCategories;
237 static {
238 sApplicationLaunchKeyCategories = new SparseArray<String>();
239 sApplicationLaunchKeyCategories.append(
240 KeyEvent.KEYCODE_EXPLORER, Intent.CATEGORY_APP_BROWSER);
241 sApplicationLaunchKeyCategories.append(
242 KeyEvent.KEYCODE_ENVELOPE, Intent.CATEGORY_APP_EMAIL);
243 sApplicationLaunchKeyCategories.append(
244 KeyEvent.KEYCODE_CONTACTS, Intent.CATEGORY_APP_CONTACTS);
245 sApplicationLaunchKeyCategories.append(
246 KeyEvent.KEYCODE_CALENDAR, Intent.CATEGORY_APP_CALENDAR);
247 sApplicationLaunchKeyCategories.append(
248 KeyEvent.KEYCODE_MUSIC, Intent.CATEGORY_APP_MUSIC);
249 sApplicationLaunchKeyCategories.append(
250 KeyEvent.KEYCODE_CALCULATOR, Intent.CATEGORY_APP_CALCULATOR);
251 }
252
Craig Mautnerc3daedd2014-09-13 11:17:23 -0700253 /** Amount of time (in milliseconds) to wait for windows drawn before powering on. */
Jorim Jaggi0d210f62015-07-10 14:24:44 -0700254 static final int WAITING_FOR_DRAWN_TIMEOUT = 1000;
Craig Mautnerc3daedd2014-09-13 11:17:23 -0700255
Dianne Hackborndf89e652011-10-06 22:35:11 -0700256 /**
257 * Lock protecting internal state. Must not call out into window
258 * manager with lock held. (This lock will be acquired in places
259 * where the window manager is calling in with its own lock held.)
260 */
Craig Mautner0bf6ec92012-12-18 08:33:27 -0800261 private final Object mLock = new Object();
Dianne Hackborndf89e652011-10-06 22:35:11 -0700262
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800263 Context mContext;
264 IWindowManager mWindowManager;
Dianne Hackborndf89e652011-10-06 22:35:11 -0700265 WindowManagerFuncs mWindowManagerFuncs;
Craig Mautner8a0da012014-05-31 15:13:37 -0700266 WindowManagerInternal mWindowManagerInternal;
Jeff Brown96307042012-07-27 15:51:34 -0700267 PowerManager mPowerManager;
Jeff Brown061ea992015-04-17 19:55:47 -0700268 ActivityManagerInternal mActivityManagerInternal;
Jose Lima9546b202014-07-02 17:21:51 -0700269 DreamManagerInternal mDreamManagerInternal;
Michael Wrighta4d22d72015-09-16 23:19:26 +0100270 PowerManagerInternal mPowerManagerInternal;
Joe Onorato93056472010-09-10 10:30:46 -0400271 IStatusBarService mStatusBarService;
Jeff Browncaca8812013-05-09 13:34:33 -0700272 boolean mPreloadedRecentApps;
Dianne Hackborn42e620c2012-06-24 13:20:51 -0700273 final Object mServiceAquireLock = new Object();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800274 Vibrator mVibrator; // Vibrator for giving feedback of orientation changes
Jeff Brownde7a8ea2012-06-13 18:28:57 -0700275 SearchManager mSearchManager;
Svetoslav8e3feb12014-02-24 13:46:47 -0800276 AccessibilityManager mAccessibilityManager;
Filip Gruszczynskicfb31852015-02-25 21:47:12 +0000277 BurnInProtectionHelper mBurnInProtectionHelper;
Billy Laucbe540f2015-06-25 01:51:44 +0100278 AppOpsManager mAppOpsManager;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800279
Dianne Hackborn181ceb52009-08-27 22:16:40 -0700280 // Vibrator pattern for haptic feedback of a long press.
281 long[] mLongPressVibePattern;
Craig Mautner88400d32012-09-30 12:35:45 -0700282
Dianne Hackborn181ceb52009-08-27 22:16:40 -0700283 // Vibrator pattern for haptic feedback of virtual key press.
284 long[] mVirtualKeyVibePattern;
Craig Mautner967212c2013-04-13 21:10:58 -0700285
Amith Yamasanic33cb712010-02-10 15:21:49 -0800286 // Vibrator pattern for a short vibration.
287 long[] mKeyboardTapVibePattern;
288
Fabrice Di Meglioeeff63a2013-08-05 12:07:24 -0700289 // Vibrator pattern for a short vibration when tapping on an hour/minute tick of a Clock.
290 long[] mClockTickVibePattern;
291
Fabrice Di Megliobd9152f2013-10-01 11:21:31 -0700292 // Vibrator pattern for a short vibration when tapping on a day/month/year date of a Calendar.
293 long[] mCalendarDateVibePattern;
294
Dianne Hackbornb1a79802009-09-29 15:18:31 -0700295 // Vibrator pattern for haptic feedback during boot when safe mode is disabled.
296 long[] mSafeModeDisabledVibePattern;
Craig Mautner967212c2013-04-13 21:10:58 -0700297
Dianne Hackbornb1a79802009-09-29 15:18:31 -0700298 // Vibrator pattern for haptic feedback during boot when safe mode is enabled.
299 long[] mSafeModeEnabledVibePattern;
Romain Guy8154cd32010-03-29 14:41:15 -0700300
Mady Mellore8608912015-06-05 09:02:55 -0700301 // Vibrator pattern for haptic feedback of a context click.
302 long[] mContextClickVibePattern;
Mady Mellore82067b2015-04-30 09:58:35 -0700303
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800304 /** If true, hitting shift & menu will broadcast Intent.ACTION_BUG_REPORT */
305 boolean mEnableShiftMenuBugReports = false;
Mike Lockwoodd747dc82011-09-13 16:28:22 -0400306
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800307 boolean mSafeMode;
308 WindowState mStatusBar = null;
Dianne Hackborn69cb8752011-05-19 18:13:32 -0700309 int mStatusBarHeight;
Daniel Sandler8956dbb2011-04-22 07:55:02 -0400310 WindowState mNavigationBar = null;
Daniel Sandler36412a72011-08-04 09:35:13 -0400311 boolean mHasNavigationBar = false;
Dianne Hackbornf87d1962012-04-04 12:48:24 -0700312 boolean mCanHideNavigationBar = false;
Daniel Sandler4a066c52012-04-20 14:49:13 -0400313 boolean mNavigationBarCanMove = false; // can the navigation bar ever move to the side?
314 boolean mNavigationBarOnBottom = true; // is the navigation bar on the bottom *right now*?
315 int[] mNavigationBarHeightForRotation = new int[4];
316 int[] mNavigationBarWidthForRotation = new int[4];
Daniel Sandler8956dbb2011-04-22 07:55:02 -0400317
keunyounga7710492015-09-23 11:33:58 -0700318 // Whether to allow dock apps with METADATA_DOCK_HOME to temporarily take over the Home key.
319 // This is for car dock and this is updated from resource.
320 private boolean mEnableCarDockHomeCapture = true;
321
Craig Mautnera631d492014-08-05 15:16:01 -0700322 boolean mBootMessageNeedsHiding;
Jim Miller5ecd8112013-01-09 18:50:26 -0800323 KeyguardServiceDelegate mKeyguardDelegate;
Craig Mautner13f6ea72014-06-23 14:57:02 -0700324 final Runnable mWindowManagerDrawCallback = new Runnable() {
Craig Mautner8a0da012014-05-31 15:13:37 -0700325 @Override
Craig Mautner13f6ea72014-06-23 14:57:02 -0700326 public void run() {
Craig Mautner8a0da012014-05-31 15:13:37 -0700327 if (DEBUG_WAKEUP) Slog.i(TAG, "All windows ready for display!");
328 mHandler.sendEmptyMessage(MSG_WINDOW_MANAGER_DRAWN_COMPLETE);
329 }
330 };
Jorim Jaggi4cfdcf52015-07-09 12:13:59 -0700331 final DrawnListener mKeyguardDrawnCallback = new DrawnListener() {
Craig Mautner8a0da012014-05-31 15:13:37 -0700332 @Override
Jorim Jaggi4cfdcf52015-07-09 12:13:59 -0700333 public void onDrawn() {
334 if (DEBUG_WAKEUP) Slog.d(TAG, "mKeyguardDelegate.ShowListener.onDrawn.");
Craig Mautner8a0da012014-05-31 15:13:37 -0700335 mHandler.sendEmptyMessage(MSG_KEYGUARD_DRAWN_COMPLETE);
336 }
337 };
338
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800339 GlobalActions mGlobalActions;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800340 Handler mHandler;
satok1bc0a492012-04-25 22:47:12 +0900341 WindowState mLastInputMethodWindow = null;
342 WindowState mLastInputMethodTargetWindow = null;
Jeff Brown4aed78b2011-01-14 17:36:55 -0800343
Jeff Brown13f00f02014-10-31 14:45:50 -0700344 // FIXME This state is shared between the input reader and handler thread.
345 // Technically it's broken and buggy but it has been like this for many years
346 // and we have not yet seen any problems. Someday we'll rewrite this logic
347 // so that only one thread is involved in handling input policy. Unfortunately
348 // it's on a critical path for power management so we can't just post the work to the
349 // handler thread. We'll need to resolve this someday by teaching the input dispatcher
350 // to hold wakelocks during dispatch and eliminating the critical path.
351 volatile boolean mPowerKeyHandled;
Bryce Leed9268e32014-11-17 17:40:59 -0800352 volatile boolean mBeganFromNonInteractive;
Jeff Brown13f00f02014-10-31 14:45:50 -0700353 volatile int mPowerKeyPressCounter;
354 volatile boolean mEndCallKeyHandled;
355
Winson Chungd42a6cf2014-06-03 16:24:04 -0700356 boolean mRecentsVisible;
Winson Chung1e8d71b2014-05-16 17:05:22 -0700357 int mRecentAppsHeldModifiers;
Jeff Browncf39bdf2012-05-18 14:41:19 -0700358 boolean mLanguageSwitchKeyPressed;
Jeff Brown68b909d2011-12-07 16:36:01 -0800359
Jeff Brown2e7760e2012-04-11 15:14:55 -0700360 int mLidState = LID_ABSENT;
Michael Wright3818c922014-09-02 13:59:07 -0700361 int mCameraLensCoverState = CAMERA_LENS_COVER_ABSENT;
Jeff Browndaa37532012-05-01 15:54:03 -0700362 boolean mHaveBuiltInKeyboard;
Jeff Brown4aed78b2011-01-14 17:36:55 -0800363
Dianne Hackbornc777e072010-02-12 13:07:59 -0800364 boolean mSystemReady;
Dianne Hackbornba24e4d2011-09-01 11:17:06 -0700365 boolean mSystemBooted;
Adrian Roos3542f7d2015-07-13 15:57:53 -0700366 private boolean mDeferBindKeyguard;
Dianne Hackbornad7fa7f2011-01-07 14:06:50 -0800367 boolean mHdmiPlugged;
Jinsuk Kime601b712015-07-07 08:01:02 +0900368 HdmiControl mHdmiControl;
Jeff Brown4f5fa282014-06-12 19:19:15 -0700369 IUiModeManager mUiModeManager;
Daniel Sandler6396c722013-04-16 20:19:09 -0400370 int mUiMode;
Dianne Hackborn867ab6472010-04-29 13:28:56 -0700371 int mDockMode = Intent.EXTRA_DOCK_STATE_UNDOCKED;
Mike Lockwood1753f7f2009-08-24 14:49:07 -0700372 int mLidOpenRotation;
Mike Lockwood2d1efbd2009-09-16 12:15:53 -0400373 int mCarDockRotation;
374 int mDeskDockRotation;
Jeff Brownc82c89ed2013-04-17 17:18:15 -0700375 int mUndockedHdmiRotation;
376 int mDemoHdmiRotation;
377 boolean mDemoHdmiRotationLock;
Chong Zhangae6119ff2014-11-11 18:54:39 -0800378 int mDemoRotation;
379 boolean mDemoRotationLock;
Daniel Sandlerb73617d2010-08-17 00:41:00 -0400380
Jeff Browna20dda42014-05-27 20:57:24 -0700381 boolean mWakeGestureEnabledSetting;
382 MyWakeGestureListener mWakeGestureListener;
383
Craig Mautner46ac6fa2013-08-01 10:06:34 -0700384 // Default display does not rotate, apps that require non-default orientation will have to
385 // have the orientation emulated.
386 private boolean mForceDefaultOrientation = false;
387
Daniel Sandlerb73617d2010-08-17 00:41:00 -0400388 int mUserRotationMode = WindowManagerPolicy.USER_ROTATION_FREE;
389 int mUserRotation = Surface.ROTATION_0;
Jeff Brown207673cd2012-06-05 17:47:11 -0700390 boolean mAccelerometerDefault;
Daniel Sandlerb73617d2010-08-17 00:41:00 -0400391
Jeff Brownbcdfc622014-03-06 19:13:04 -0800392 boolean mSupportAutoRotation;
Jeff Brownd3187e32011-09-21 19:26:44 -0700393 int mAllowAllRotations = -1;
Mike Lockwoode9867d22009-09-20 01:59:02 -0400394 boolean mCarDockEnablesAccelerometer;
395 boolean mDeskDockEnablesAccelerometer;
Dianne Hackborn2862fff2009-09-15 22:56:29 -0700396 int mLidKeyboardAccessibility;
397 int mLidNavigationAccessibility;
Jeff Brownc458ce92012-04-30 14:58:40 -0700398 boolean mLidControlsSleep;
Jeff Brown13f00f02014-10-31 14:45:50 -0700399 int mShortPressOnPowerBehavior;
400 int mLongPressOnPowerBehavior;
401 int mDoublePressOnPowerBehavior;
402 int mTriplePressOnPowerBehavior;
Filip Gruszczynskia483a1d2015-03-17 19:06:58 +0000403 int mShortPressOnSleepBehavior;
Jeff Brown3ee549c2014-09-22 20:14:39 -0700404 boolean mAwake;
405 boolean mScreenOnEarly;
406 boolean mScreenOnFully;
407 ScreenOnListener mScreenOnListener;
408 boolean mKeyguardDrawComplete;
409 boolean mWindowManagerDrawComplete;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800410 boolean mOrientationSensorEnabled = false;
411 int mCurrentAppOrientation = ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800412 boolean mHasSoftInput = false;
Daniel Sandlerdd73ee42013-10-11 22:19:59 -0400413 boolean mTranslucentDecorEnabled = true;
RoboErik001c59c2015-01-26 15:53:51 -0800414 boolean mUseTvRouting;
Craig Mautner967212c2013-04-13 21:10:58 -0700415
Jeff Brown70825162012-03-28 17:27:48 -0700416 int mPointerLocationMode = 0; // guarded by mLock
Joe Onorato664644d2011-01-23 17:53:23 -0800417
418 // The last window we were told about in focusChanged.
419 WindowState mFocusedWindow;
Dianne Hackborne0f085d2011-11-30 18:41:15 -0800420 IApplicationToken mFocusedApp;
Joe Onorato664644d2011-01-23 17:53:23 -0800421
Jeff Brown70825162012-03-28 17:27:48 -0700422 PointerLocationView mPointerLocationView;
Jeff Brown32cbc38552011-12-01 14:01:49 -0800423
Dianne Hackbornc652de82013-02-15 16:32:56 -0800424 // The current size of the screen; really; extends into the overscan area of
425 // the screen and doesn't account for any system elements like the status bar.
426 int mOverscanScreenLeft, mOverscanScreenTop;
427 int mOverscanScreenWidth, mOverscanScreenHeight;
428 // The current visible size of the screen; really; (ir)regardless of whether the status
429 // bar can be hidden but not extending into the overscan area.
Joe Onorato29fc2c92010-11-24 10:26:50 -0800430 int mUnrestrictedScreenLeft, mUnrestrictedScreenTop;
431 int mUnrestrictedScreenWidth, mUnrestrictedScreenHeight;
Dianne Hackborn313440842013-02-19 19:22:59 -0800432 // Like mOverscanScreen*, but allowed to move into the overscan region where appropriate.
433 int mRestrictedOverscanScreenLeft, mRestrictedOverscanScreenTop;
434 int mRestrictedOverscanScreenWidth, mRestrictedOverscanScreenHeight;
Dianne Hackborn82de1ae2010-10-28 11:28:39 -0700435 // The current size of the screen; these may be different than (0,0)-(dw,dh)
436 // if the status bar can't be hidden; in that case it effectively carves out
437 // that area of the display from all other windows.
Joe Onorato29fc2c92010-11-24 10:26:50 -0800438 int mRestrictedScreenLeft, mRestrictedScreenTop;
439 int mRestrictedScreenWidth, mRestrictedScreenHeight;
Dianne Hackborn5c58de32012-04-28 19:52:37 -0700440 // During layout, the current screen borders accounting for any currently
441 // visible system UI elements.
442 int mSystemLeft, mSystemTop, mSystemRight, mSystemBottom;
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -0700443 // For applications requesting stable content insets, these are them.
444 int mStableLeft, mStableTop, mStableRight, mStableBottom;
Dianne Hackborn5b5cc4d2012-05-16 13:15:00 -0700445 // For applications requesting stable content insets but have also set the
446 // fullscreen window flag, these are the stable dimensions without the status bar.
447 int mStableFullscreenLeft, mStableFullscreenTop;
448 int mStableFullscreenRight, mStableFullscreenBottom;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800449 // During layout, the current screen borders with all outer decoration
450 // (status bar, input method dock) accounted for.
451 int mCurLeft, mCurTop, mCurRight, mCurBottom;
452 // During layout, the frame in which content should be displayed
453 // to the user, accounting for all screen decoration except for any
454 // space they deem as available for other content. This is usually
455 // the same as mCur*, but may be larger if the screen decor has supplied
456 // content insets.
457 int mContentLeft, mContentTop, mContentRight, mContentBottom;
Dianne Hackborne30e02f2014-05-27 18:24:45 -0700458 // During layout, the frame in which voice content should be displayed
459 // to the user, accounting for all screen decoration except for any
460 // space they deem as available for other content.
461 int mVoiceContentLeft, mVoiceContentTop, mVoiceContentRight, mVoiceContentBottom;
Dianne Hackborn8e11ef02010-11-18 19:47:42 -0800462 // During layout, the current screen borders along which input method
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800463 // windows are placed.
464 int mDockLeft, mDockTop, mDockRight, mDockBottom;
465 // During layout, the layer at which the doc window is placed.
466 int mDockLayer;
Dianne Hackborn5c58de32012-04-28 19:52:37 -0700467 // During layout, this is the layer of the status bar.
468 int mStatusBarLayer;
Dianne Hackborne26ab702011-10-16 13:21:33 -0700469 int mLastSystemUiFlags;
470 // Bits that we are in the process of clearing, so we want to prevent
471 // them from being set by applications until everything has been updated
472 // to have them clear.
473 int mResettingSystemUiFlags = 0;
474 // Bits that we are currently always keeping cleared.
475 int mForceClearedSystemUiFlags = 0;
Dianne Hackborn4eff8d32011-11-10 19:38:40 -0800476 // What we last reported to system UI about whether the compatibility
477 // menu needs to be displayed.
478 boolean mLastFocusNeedsMenu = false;
Adrian Roosddc8b272015-05-21 16:28:27 -0700479 // If nonzero, a panic gesture was performed at that time in uptime millis and is still pending.
480 private long mPendingPanicGestureUptime;
Dianne Hackborndf89e652011-10-06 22:35:11 -0700481
Selim Cinekf83e8242015-05-19 18:08:14 -0700482 InputConsumer mInputConsumer = null;
Dianne Hackborndf89e652011-10-06 22:35:11 -0700483
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800484 static final Rect mTmpParentFrame = new Rect();
485 static final Rect mTmpDisplayFrame = new Rect();
Dianne Hackbornc4aad012013-02-22 15:05:25 -0800486 static final Rect mTmpOverscanFrame = new Rect();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800487 static final Rect mTmpContentFrame = new Rect();
488 static final Rect mTmpVisibleFrame = new Rect();
John Spurlock46646232013-09-30 22:32:42 -0400489 static final Rect mTmpDecorFrame = new Rect();
Adrian Roosfa104232014-06-20 16:10:14 -0700490 static final Rect mTmpStableFrame = new Rect();
Dianne Hackborn1f903c32011-09-13 19:18:06 -0700491 static final Rect mTmpNavigationFrame = new Rect();
Filip Gruszczynski2217f612015-05-26 11:32:08 -0700492 static final Rect mTmpOutsetFrame = new Rect();
Craig Mautner967212c2013-04-13 21:10:58 -0700493
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800494 WindowState mTopFullscreenOpaqueWindowState;
Adrian Rooscd3884d2015-02-18 17:25:23 +0100495 WindowState mTopFullscreenOpaqueOrDimmingWindowState;
Craig Mautner2bc789b2014-03-19 19:48:38 -0700496 HashSet<IApplicationToken> mAppsToBeHidden = new HashSet<IApplicationToken>();
Jorim Jaggic13fcac2014-09-11 17:36:57 +0200497 HashSet<IApplicationToken> mAppsThatDismissKeyguard = new HashSet<IApplicationToken>();
Joe Onorato93056472010-09-10 10:30:46 -0400498 boolean mTopIsFullscreen;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800499 boolean mForceStatusBar;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -0700500 boolean mForceStatusBarFromKeyguard;
Selim Cinek4a4a2bddc2015-05-07 12:50:19 -0700501 private boolean mForceStatusBarTransparent;
Dianne Hackborn39c2d712009-09-22 11:41:31 -0700502 boolean mHideLockScreen;
Dianne Hackborn891d3fb2013-01-09 18:31:37 -0800503 boolean mForcingShowNavBar;
504 int mForcingShowNavBarLayer;
Craig Mautnerad09bcc2012-10-08 13:33:11 -0700505
506 // States of keyguard dismiss.
507 private static final int DISMISS_KEYGUARD_NONE = 0; // Keyguard not being dismissed.
508 private static final int DISMISS_KEYGUARD_START = 1; // Keyguard needs to be dismissed.
509 private static final int DISMISS_KEYGUARD_CONTINUE = 2; // Keyguard has been dismissed.
510 int mDismissKeyguard = DISMISS_KEYGUARD_NONE;
511
512 /** The window that is currently dismissing the keyguard. Dismissing the keyguard must only
513 * be done once per window. */
514 private WindowState mWinDismissingKeyguard;
515
tingna_sunge785ffa2015-05-12 13:23:15 +0800516 /** When window is currently dismissing the keyguard, dismissing the keyguard must handle
517 * the keygaurd secure state change instantly case, e.g. the use case of inserting a PIN
518 * lock SIM card. This variable is used to record the previous keyguard secure state for
519 * monitoring secure state change on window dismissing keyguard. */
520 private boolean mSecureDismissingKeyguard;
521
Craig Mautnerc9457fa2014-06-06 14:27:48 -0700522 /** The window that is currently showing "over" the keyguard. If there is an app window
523 * belonging to another app on top of this the keyguard shows. If there is a fullscreen
524 * app window under this, still dismiss the keyguard but don't show the app underneath. Show
525 * the wallpaper. */
526 private WindowState mWinShowWhenLocked;
527
Dianne Hackborn7ad44382012-10-18 17:46:00 -0700528 boolean mShowingLockscreen;
529 boolean mShowingDream;
530 boolean mDreamingLockscreen;
Jeff Brown061ea992015-04-17 19:55:47 -0700531 boolean mDreamingSleepTokenNeeded;
532 SleepToken mDreamingSleepToken;
Jeff Brown48d1b142015-06-10 16:36:03 -0700533 SleepToken mScreenOffSleepToken;
Jim Millerab954542014-10-10 18:21:49 -0700534 boolean mKeyguardSecure;
535 boolean mKeyguardSecureIncludingHidden;
536 volatile boolean mKeyguardOccluded;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800537 boolean mHomePressed;
Jeff Browncaca8812013-05-09 13:34:33 -0700538 boolean mHomeConsumed;
539 boolean mHomeDoubleTapPending;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800540 Intent mHomeIntent;
Dianne Hackborn39c2d712009-09-22 11:41:31 -0700541 Intent mCarDockIntent;
542 Intent mDeskDockIntent;
Jeff Brownfd23e3e2012-05-09 13:34:28 -0700543 boolean mSearchKeyShortcutPending;
544 boolean mConsumeSearchKeyUp;
Jeff Brownde7a8ea2012-06-13 18:28:57 -0700545 boolean mAssistKeyLongPressed;
Michael Wright6a62e552014-06-03 19:19:48 -0700546 boolean mPendingMetaAction;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800547
Mike Lockwood28569302010-01-28 11:54:40 -0500548 // support for activating the lock screen while the screen is on
549 boolean mAllowLockscreenWhenOn;
550 int mLockScreenTimeout;
551 boolean mLockScreenTimerActive;
552
David Brownbaf8d092010-03-08 21:52:59 -0800553 // Behavior of ENDCALL Button. (See Settings.System.END_BUTTON_BEHAVIOR.)
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800554 int mEndcallBehavior;
David Brownbaf8d092010-03-08 21:52:59 -0800555
556 // Behavior of POWER button while in-call and screen on.
557 // (See Settings.Secure.INCALL_POWER_BUTTON_BEHAVIOR.)
558 int mIncallPowerBehavior;
559
Dianne Hackbornf87d1962012-04-04 12:48:24 -0700560 Display mDisplay;
561
Filip Gruszczynski2987f612015-06-30 15:03:30 -0700562 private int mDisplayRotation;
563
Dianne Hackborn9d132642011-04-21 17:26:39 -0700564 int mLandscapeRotation = 0; // default landscape rotation
565 int mSeascapeRotation = 0; // "other" landscape rotation, 180 degrees from mLandscapeRotation
566 int mPortraitRotation = 0; // default portrait rotation
567 int mUpsideDownRotation = 0; // "other" portrait rotation
Mitsuru Oshima831d0d92009-06-16 18:27:18 -0700568
Dianne Hackbornc652de82013-02-15 16:32:56 -0800569 int mOverscanLeft = 0;
570 int mOverscanTop = 0;
571 int mOverscanRight = 0;
572 int mOverscanBottom = 0;
573
Joe Onorato46b0d682010-11-22 17:37:27 -0800574 // What we do when the user long presses on home
Jeff Browncaca8812013-05-09 13:34:33 -0700575 private int mLongPressOnHomeBehavior;
576
577 // What we do when the user double-taps on home
578 private int mDoubleTapOnHomeBehavior;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800579
Bryce Lee584a4452014-10-21 15:55:55 -0700580 // Allowed theater mode wake actions
581 private boolean mAllowTheaterModeWakeFromKey;
582 private boolean mAllowTheaterModeWakeFromPowerKey;
583 private boolean mAllowTheaterModeWakeFromMotion;
Bryce Lee812d7022014-11-10 13:33:28 -0800584 private boolean mAllowTheaterModeWakeFromMotionWhenNotDreaming;
Bryce Lee584a4452014-10-21 15:55:55 -0700585 private boolean mAllowTheaterModeWakeFromCameraLens;
586 private boolean mAllowTheaterModeWakeFromLidSwitch;
587 private boolean mAllowTheaterModeWakeFromWakeGesture;
588
Bryce Leed3b28402015-03-09 15:49:13 +0000589 // Whether to support long press from power button in non-interactive mode
590 private boolean mSupportLongPressPowerWhenNonInteractive;
591
Bryce Lee55e846d2014-11-04 12:43:44 -0800592 // Whether to go to sleep entering theater mode from power button
593 private boolean mGoToSleepOnButtonPressTheaterMode;
594
Winson Chung9112ec32011-06-27 13:15:32 -0700595 // Screenshot trigger states
Jeff Brownd5bb82d2011-10-12 13:57:59 -0700596 // Time to volume and power must be pressed within this interval of each other.
597 private static final long SCREENSHOT_CHORD_DEBOUNCE_DELAY_MILLIS = 150;
Winson Chung1cea2f32012-10-08 20:42:01 -0700598 // Increase the chord delay when taking a screenshot from the keyguard
599 private static final float KEYGUARD_SCREENSHOT_CHORD_DELAY_MULTIPLIER = 2.5f;
Christopher Tatee90585f2012-03-05 18:56:25 -0800600 private boolean mScreenshotChordEnabled;
Jeff Brown13f00f02014-10-31 14:45:50 -0700601 private boolean mScreenshotChordVolumeDownKeyTriggered;
602 private long mScreenshotChordVolumeDownKeyTime;
603 private boolean mScreenshotChordVolumeDownKeyConsumed;
604 private boolean mScreenshotChordVolumeUpKeyTriggered;
605 private boolean mScreenshotChordPowerKeyTriggered;
606 private long mScreenshotChordPowerKeyTime;
Winson Chung9112ec32011-06-27 13:15:32 -0700607
Michael Wrightb854e242013-02-05 17:54:02 -0800608 /* The number of steps between min and max brightness */
609 private static final int BRIGHTNESS_STEPS = 10;
610
Christopher Tate5e08af02012-09-21 17:17:22 -0700611 SettingsObserver mSettingsObserver;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800612 ShortcutManager mShortcutManager;
613 PowerManager.WakeLock mBroadcastWakeLock;
Jeff Brown13f00f02014-10-31 14:45:50 -0700614 PowerManager.WakeLock mPowerKeyWakeLock;
Jeff Brown40013652012-05-16 21:22:36 -0700615 boolean mHavePendingMediaKeyRepeatWithWakeLock;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800616
Craig Mautnerd625ab22013-09-06 13:40:31 -0700617 private int mCurrentUserId;
618
Justin Kohd378ad72013-04-01 12:18:26 -0700619 // Maps global key codes to the components that will handle them.
620 private GlobalKeyManager mGlobalKeyManager;
621
Jeff Brownfd23e3e2012-05-09 13:34:28 -0700622 // Fallback actions by key code.
623 private final SparseArray<KeyCharacterMap.FallbackAction> mFallbackActions =
624 new SparseArray<KeyCharacterMap.FallbackAction>();
Jeff Brown49ed71d2010-12-06 17:13:33 -0800625
Jorim Jaggi76a16232014-08-08 17:00:47 +0200626 private final LogDecelerateInterpolator mLogDecelerateInterpolator
627 = new LogDecelerateInterpolator(100, 0);
628
Jeff Brown70825162012-03-28 17:27:48 -0700629 private static final int MSG_ENABLE_POINTER_LOCATION = 1;
630 private static final int MSG_DISABLE_POINTER_LOCATION = 2;
Jeff Brown40013652012-05-16 21:22:36 -0700631 private static final int MSG_DISPATCH_MEDIA_KEY_WITH_WAKE_LOCK = 3;
632 private static final int MSG_DISPATCH_MEDIA_KEY_REPEAT_WITH_WAKE_LOCK = 4;
Craig Mautner8a0da012014-05-31 15:13:37 -0700633 private static final int MSG_KEYGUARD_DRAWN_COMPLETE = 5;
634 private static final int MSG_KEYGUARD_DRAWN_TIMEOUT = 6;
635 private static final int MSG_WINDOW_MANAGER_DRAWN_COMPLETE = 7;
Craig Mautner84984fa2014-06-19 11:19:20 -0700636 private static final int MSG_DISPATCH_SHOW_RECENTS = 9;
Alan Viverettee34560b22014-07-10 14:50:06 -0700637 private static final int MSG_DISPATCH_SHOW_GLOBAL_ACTIONS = 10;
Craig Mautnera631d492014-08-05 15:16:01 -0700638 private static final int MSG_HIDE_BOOT_MESSAGE = 11;
Michael Wright869a67c2014-08-26 19:33:06 -0700639 private static final int MSG_LAUNCH_VOICE_ASSIST_WITH_WAKE_LOCK = 12;
Jeff Brown13f00f02014-10-31 14:45:50 -0700640 private static final int MSG_POWER_DELAYED_PRESS = 13;
641 private static final int MSG_POWER_LONG_PRESS = 14;
Jeff Brown061ea992015-04-17 19:55:47 -0700642 private static final int MSG_UPDATE_DREAMING_SLEEP_TOKEN = 15;
Jun Mukaid2e7e352015-07-22 17:14:02 -0700643 private static final int MSG_REQUEST_TRANSIENT_BARS = 16;
644
645 private static final int MSG_REQUEST_TRANSIENT_BARS_ARG_STATUS = 0;
646 private static final int MSG_REQUEST_TRANSIENT_BARS_ARG_NAVIGATION = 1;
Jeff Brown70825162012-03-28 17:27:48 -0700647
648 private class PolicyHandler extends Handler {
649 @Override
650 public void handleMessage(Message msg) {
651 switch (msg.what) {
652 case MSG_ENABLE_POINTER_LOCATION:
653 enablePointerLocation();
654 break;
655 case MSG_DISABLE_POINTER_LOCATION:
656 disablePointerLocation();
657 break;
Jeff Brown40013652012-05-16 21:22:36 -0700658 case MSG_DISPATCH_MEDIA_KEY_WITH_WAKE_LOCK:
659 dispatchMediaKeyWithWakeLock((KeyEvent)msg.obj);
660 break;
661 case MSG_DISPATCH_MEDIA_KEY_REPEAT_WITH_WAKE_LOCK:
662 dispatchMediaKeyRepeatWithWakeLock((KeyEvent)msg.obj);
663 break;
Craig Mautner84984fa2014-06-19 11:19:20 -0700664 case MSG_DISPATCH_SHOW_RECENTS:
665 showRecentApps(false);
666 break;
Alan Viverettee34560b22014-07-10 14:50:06 -0700667 case MSG_DISPATCH_SHOW_GLOBAL_ACTIONS:
668 showGlobalActionsInternal();
669 break;
Craig Mautner8a0da012014-05-31 15:13:37 -0700670 case MSG_KEYGUARD_DRAWN_COMPLETE:
671 if (DEBUG_WAKEUP) Slog.w(TAG, "Setting mKeyguardDrawComplete");
Jeff Brown36c4db82014-09-19 12:05:31 -0700672 finishKeyguardDrawn();
Craig Mautner8a0da012014-05-31 15:13:37 -0700673 break;
674 case MSG_KEYGUARD_DRAWN_TIMEOUT:
675 Slog.w(TAG, "Keyguard drawn timeout. Setting mKeyguardDrawComplete");
Jeff Brown36c4db82014-09-19 12:05:31 -0700676 finishKeyguardDrawn();
Craig Mautner8a0da012014-05-31 15:13:37 -0700677 break;
678 case MSG_WINDOW_MANAGER_DRAWN_COMPLETE:
679 if (DEBUG_WAKEUP) Slog.w(TAG, "Setting mWindowManagerDrawComplete");
Jeff Brown36c4db82014-09-19 12:05:31 -0700680 finishWindowsDrawn();
Craig Mautner8a0da012014-05-31 15:13:37 -0700681 break;
Craig Mautnera631d492014-08-05 15:16:01 -0700682 case MSG_HIDE_BOOT_MESSAGE:
683 handleHideBootMessage();
684 break;
Michael Wright869a67c2014-08-26 19:33:06 -0700685 case MSG_LAUNCH_VOICE_ASSIST_WITH_WAKE_LOCK:
686 launchVoiceAssistWithWakeLock(msg.arg1 != 0);
687 break;
Jeff Brown13f00f02014-10-31 14:45:50 -0700688 case MSG_POWER_DELAYED_PRESS:
689 powerPress((Long)msg.obj, msg.arg1 != 0, msg.arg2);
690 finishPowerKeyPress();
691 break;
692 case MSG_POWER_LONG_PRESS:
693 powerLongPress();
694 break;
Jeff Brown061ea992015-04-17 19:55:47 -0700695 case MSG_UPDATE_DREAMING_SLEEP_TOKEN:
696 updateDreamingSleepToken(msg.arg1 != 0);
697 break;
Jun Mukaid2e7e352015-07-22 17:14:02 -0700698 case MSG_REQUEST_TRANSIENT_BARS:
699 WindowState targetBar = (msg.arg1 == MSG_REQUEST_TRANSIENT_BARS_ARG_STATUS) ?
700 mStatusBar : mNavigationBar;
701 if (targetBar != null) {
702 requestTransientBars(targetBar);
703 }
704 break;
Jeff Brown70825162012-03-28 17:27:48 -0700705 }
706 }
707 }
708
Dianne Hackbornad7fa7f2011-01-07 14:06:50 -0800709 private UEventObserver mHDMIObserver = new UEventObserver() {
710 @Override
711 public void onUEvent(UEventObserver.UEvent event) {
712 setHdmiPlugged("1".equals(event.get("SWITCH_STATE")));
713 }
714 };
715
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800716 class SettingsObserver extends ContentObserver {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800717 SettingsObserver(Handler handler) {
718 super(handler);
719 }
David Brownbaf8d092010-03-08 21:52:59 -0800720
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800721 void observe() {
Christopher Tate5e08af02012-09-21 17:17:22 -0700722 // Observe all users' changes
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800723 ContentResolver resolver = mContext.getContentResolver();
724 resolver.registerContentObserver(Settings.System.getUriFor(
Christopher Tate5e08af02012-09-21 17:17:22 -0700725 Settings.System.END_BUTTON_BEHAVIOR), false, this,
726 UserHandle.USER_ALL);
David Brownbaf8d092010-03-08 21:52:59 -0800727 resolver.registerContentObserver(Settings.Secure.getUriFor(
Christopher Tate5e08af02012-09-21 17:17:22 -0700728 Settings.Secure.INCALL_POWER_BUTTON_BEHAVIOR), false, this,
729 UserHandle.USER_ALL);
Jeff Browna20dda42014-05-27 20:57:24 -0700730 resolver.registerContentObserver(Settings.Secure.getUriFor(
731 Settings.Secure.WAKE_GESTURE_ENABLED), false, this,
732 UserHandle.USER_ALL);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800733 resolver.registerContentObserver(Settings.System.getUriFor(
Christopher Tate5e08af02012-09-21 17:17:22 -0700734 Settings.System.ACCELEROMETER_ROTATION), false, this,
735 UserHandle.USER_ALL);
Mike Lockwood28569302010-01-28 11:54:40 -0500736 resolver.registerContentObserver(Settings.System.getUriFor(
Christopher Tate5e08af02012-09-21 17:17:22 -0700737 Settings.System.USER_ROTATION), false, this,
738 UserHandle.USER_ALL);
Daniel Sandlerb73617d2010-08-17 00:41:00 -0400739 resolver.registerContentObserver(Settings.System.getUriFor(
Christopher Tate5e08af02012-09-21 17:17:22 -0700740 Settings.System.SCREEN_OFF_TIMEOUT), false, this,
741 UserHandle.USER_ALL);
Dianne Hackbornc777e072010-02-12 13:07:59 -0800742 resolver.registerContentObserver(Settings.System.getUriFor(
Christopher Tate5e08af02012-09-21 17:17:22 -0700743 Settings.System.POINTER_LOCATION), false, this,
744 UserHandle.USER_ALL);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800745 resolver.registerContentObserver(Settings.Secure.getUriFor(
Christopher Tate5e08af02012-09-21 17:17:22 -0700746 Settings.Secure.DEFAULT_INPUT_METHOD), false, this,
747 UserHandle.USER_ALL);
John Spurlockd9b70bd2014-02-06 17:02:44 -0500748 resolver.registerContentObserver(Settings.Secure.getUriFor(
John Spurlockf1a36642013-10-12 17:50:42 -0400749 Settings.Secure.IMMERSIVE_MODE_CONFIRMATIONS), false, this,
Christopher Tate5e08af02012-09-21 17:17:22 -0700750 UserHandle.USER_ALL);
John Spurlockc6d1c602014-01-17 15:22:06 -0500751 resolver.registerContentObserver(Settings.Global.getUriFor(
752 Settings.Global.POLICY_CONTROL), false, this,
753 UserHandle.USER_ALL);
Dianne Hackbornc777e072010-02-12 13:07:59 -0800754 updateSettings();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800755 }
756
757 @Override public void onChange(boolean selfChange) {
Dianne Hackbornc777e072010-02-12 13:07:59 -0800758 updateSettings();
Jeff Brown01a98dd2011-09-20 15:08:29 -0700759 updateRotation(false);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800760 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800761 }
Craig Mautner967212c2013-04-13 21:10:58 -0700762
Jeff Browna20dda42014-05-27 20:57:24 -0700763 class MyWakeGestureListener extends WakeGestureListener {
764 MyWakeGestureListener(Context context, Handler handler) {
765 super(context, handler);
766 }
767
768 @Override
769 public void onWakeUp() {
770 synchronized (mLock) {
771 if (shouldEnableWakeGestureLp()) {
Jeff Browne07b94b2014-06-18 15:56:27 -0700772 performHapticFeedbackLw(null, HapticFeedbackConstants.VIRTUAL_KEY, false);
Dianne Hackborn280a64e2015-07-13 14:48:08 -0700773 wakeUp(SystemClock.uptimeMillis(), mAllowTheaterModeWakeFromWakeGesture,
774 "android.policy:GESTURE");
Jeff Browna20dda42014-05-27 20:57:24 -0700775 }
776 }
777 }
778 }
779
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800780 class MyOrientationListener extends WindowOrientationListener {
Chong Zhang5aaa0b32015-08-28 10:22:36 -0700781 private final Runnable mUpdateRotationRunnable = new Runnable() {
782 @Override
783 public void run() {
Tim Murray1f407642015-10-01 17:07:12 -0700784 // send interaction hint to improve redraw performance
785 mPowerManagerInternal.powerHint(PowerManagerInternal.POWER_HINT_INTERACTION, 0);
Chong Zhang5aaa0b32015-08-28 10:22:36 -0700786 updateRotation(false);
787 }
788 };
789
Craig Mautnereee29c42013-01-17 14:44:34 -0800790 MyOrientationListener(Context context, Handler handler) {
791 super(context, handler);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800792 }
Craig Mautner967212c2013-04-13 21:10:58 -0700793
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800794 @Override
Jeff Brownc0347aa2011-09-23 17:26:09 -0700795 public void onProposedRotationChanged(int rotation) {
Craig Mautnereda67292013-04-28 13:50:14 -0700796 if (localLOGV) Slog.v(TAG, "onProposedRotationChanged, rotation=" + rotation);
Chong Zhang5aaa0b32015-08-28 10:22:36 -0700797 mHandler.post(mUpdateRotationRunnable);
Jeff Brown01a98dd2011-09-20 15:08:29 -0700798 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800799 }
800 MyOrientationListener mOrientationListener;
801
Jorim Jaggi24bec7c2015-02-04 12:40:14 +0100802 private final StatusBarController mStatusBarController = new StatusBarController();
John Spurlock5b9145b2013-08-20 15:13:47 -0400803
John Spurlock27735a42013-08-14 17:57:38 -0400804 private final BarController mNavigationBarController = new BarController("NavigationBar",
John Spurlock5b9145b2013-08-20 15:13:47 -0400805 View.NAVIGATION_BAR_TRANSIENT,
806 View.NAVIGATION_BAR_UNHIDE,
John Spurlockbd957402013-10-03 11:38:39 -0400807 View.NAVIGATION_BAR_TRANSLUCENT,
808 StatusBarManager.WINDOW_NAVIGATION_BAR,
809 WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION);
John Spurlock5b9145b2013-08-20 15:13:47 -0400810
John Spurlockf1a36642013-10-12 17:50:42 -0400811 private ImmersiveModeConfirmation mImmersiveModeConfirmation;
John Spurlock32beb2c2013-03-11 10:16:47 -0400812
Craig Mautner037aa8d2013-06-07 10:35:44 -0700813 private SystemGesturesPointerEventListener mSystemGestures;
John Spurlock32beb2c2013-03-11 10:16:47 -0400814
Dianne Hackborn42e620c2012-06-24 13:20:51 -0700815 IStatusBarService getStatusBarService() {
816 synchronized (mServiceAquireLock) {
817 if (mStatusBarService == null) {
818 mStatusBarService = IStatusBarService.Stub.asInterface(
819 ServiceManager.getService("statusbar"));
820 }
821 return mStatusBarService;
822 }
823 }
824
Suchi Amalapurapua9e1b162009-03-24 22:24:47 -0700825 /*
826 * We always let the sensor be switched on by default except when
827 * the user has explicitly disabled sensor based rotation or when the
828 * screen is switched off.
829 */
The Android Open Source Project0727d222009-03-11 12:11:58 -0700830 boolean needSensorRunningLp() {
Jeff Brownbcdfc622014-03-06 19:13:04 -0800831 if (mSupportAutoRotation) {
832 if (mCurrentAppOrientation == ActivityInfo.SCREEN_ORIENTATION_SENSOR
833 || mCurrentAppOrientation == ActivityInfo.SCREEN_ORIENTATION_FULL_SENSOR
834 || mCurrentAppOrientation == ActivityInfo.SCREEN_ORIENTATION_SENSOR_PORTRAIT
835 || mCurrentAppOrientation == ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE) {
836 // If the application has explicitly requested to follow the
837 // orientation, then we need to turn the sensor on.
838 return true;
839 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800840 }
Dianne Hackborn867ab6472010-04-29 13:28:56 -0700841 if ((mCarDockEnablesAccelerometer && mDockMode == Intent.EXTRA_DOCK_STATE_CAR) ||
Jeff Brown1a693182011-11-08 14:44:16 -0800842 (mDeskDockEnablesAccelerometer && (mDockMode == Intent.EXTRA_DOCK_STATE_DESK
843 || mDockMode == Intent.EXTRA_DOCK_STATE_LE_DESK
844 || mDockMode == Intent.EXTRA_DOCK_STATE_HE_DESK))) {
Mike Lockwoode9867d22009-09-20 01:59:02 -0400845 // enable accelerometer if we are docked in a dock that enables accelerometer
846 // orientation management,
847 return true;
848 }
Jeff Brown207673cd2012-06-05 17:47:11 -0700849 if (mUserRotationMode == USER_ROTATION_LOCKED) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800850 // If the setting for using the sensor by default is enabled, then
851 // we will always leave it on. Note that the user could go to
852 // a window that forces an orientation that does not use the
853 // sensor and in theory we could turn it off... however, when next
854 // turning it on we won't have a good value for the current
855 // orientation for a little bit, which can cause orientation
856 // changes to lag, so we'd like to keep it always on. (It will
857 // still be turned off when the screen is off.)
Suchi Amalapurapua9e1b162009-03-24 22:24:47 -0700858 return false;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800859 }
Jeff Brownbcdfc622014-03-06 19:13:04 -0800860 return mSupportAutoRotation;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800861 }
Craig Mautner46ac6fa2013-08-01 10:06:34 -0700862
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800863 /*
864 * Various use cases for invoking this function
865 * screen turning off, should always disable listeners if already enabled
Craig Mautner46ac6fa2013-08-01 10:06:34 -0700866 * screen turned on and current app has sensor based orientation, enable listeners
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800867 * if not already enabled
868 * screen turned on and current app does not have sensor orientation, disable listeners if
869 * already enabled
870 * screen turning on and current app has sensor based orientation, enable listeners if needed
871 * screen turning on and current app has nosensor based orientation, do nothing
872 */
The Android Open Source Project0727d222009-03-11 12:11:58 -0700873 void updateOrientationListenerLp() {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800874 if (!mOrientationListener.canDetectOrientation()) {
875 // If sensor is turned off or nonexistent for some reason
876 return;
877 }
Stefan Kuhne9326dc12015-06-12 09:25:32 -1000878 // Could have been invoked due to screen turning on or off or
879 // change of the currently visible window's orientation.
Jeff Brown3ee549c2014-09-22 20:14:39 -0700880 if (localLOGV) Slog.v(TAG, "mScreenOnEarly=" + mScreenOnEarly
881 + ", mAwake=" + mAwake + ", mCurrentAppOrientation=" + mCurrentAppOrientation
Stefan Kuhne9326dc12015-06-12 09:25:32 -1000882 + ", mOrientationSensorEnabled=" + mOrientationSensorEnabled
883 + ", mKeyguardDrawComplete=" + mKeyguardDrawComplete
884 + ", mWindowManagerDrawComplete=" + mWindowManagerDrawComplete);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800885 boolean disable = true;
Stefan Kuhne9326dc12015-06-12 09:25:32 -1000886 // Note: We postpone the rotating of the screen until the keyguard as well as the
887 // window manager have reported a draw complete.
888 if (mScreenOnEarly && mAwake &&
889 mKeyguardDrawComplete && mWindowManagerDrawComplete) {
The Android Open Source Project0727d222009-03-11 12:11:58 -0700890 if (needSensorRunningLp()) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800891 disable = false;
892 //enable listener if not already enabled
The Android Open Source Project0727d222009-03-11 12:11:58 -0700893 if (!mOrientationSensorEnabled) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800894 mOrientationListener.enable();
Craig Mautnereda67292013-04-28 13:50:14 -0700895 if(localLOGV) Slog.v(TAG, "Enabling listeners");
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800896 mOrientationSensorEnabled = true;
897 }
Craig Mautner46ac6fa2013-08-01 10:06:34 -0700898 }
899 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800900 //check if sensors need to be disabled
The Android Open Source Project0727d222009-03-11 12:11:58 -0700901 if (disable && mOrientationSensorEnabled) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800902 mOrientationListener.disable();
Craig Mautnereda67292013-04-28 13:50:14 -0700903 if(localLOGV) Slog.v(TAG, "Disabling listeners");
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800904 mOrientationSensorEnabled = false;
905 }
906 }
907
Jeff Brown13f00f02014-10-31 14:45:50 -0700908 private void interceptPowerKeyDown(KeyEvent event, boolean interactive) {
909 // Hold a wake lock until the power key is released.
910 if (!mPowerKeyWakeLock.isHeld()) {
911 mPowerKeyWakeLock.acquire();
912 }
913
914 // Cancel multi-press detection timeout.
915 if (mPowerKeyPressCounter != 0) {
916 mHandler.removeMessages(MSG_POWER_DELAYED_PRESS);
917 }
918
919 // Detect user pressing the power button in panic when an application has
920 // taken over the whole screen.
921 boolean panic = mImmersiveModeConfirmation.onPowerKeyDown(interactive,
Craig Mautner0124980e92014-11-30 21:15:34 -0800922 SystemClock.elapsedRealtime(), isImmersiveMode(mLastSystemUiFlags));
Jeff Brown13f00f02014-10-31 14:45:50 -0700923 if (panic) {
Adrian Roosddc8b272015-05-21 16:28:27 -0700924 mHandler.post(mHiddenNavPanic);
Jeff Brown13f00f02014-10-31 14:45:50 -0700925 }
926
927 // Latch power key state to detect screenshot chord.
928 if (interactive && !mScreenshotChordPowerKeyTriggered
929 && (event.getFlags() & KeyEvent.FLAG_FALLBACK) == 0) {
930 mScreenshotChordPowerKeyTriggered = true;
931 mScreenshotChordPowerKeyTime = event.getDownTime();
932 interceptScreenshotChord();
933 }
934
935 // Stop ringing or end call if configured to do so when power is pressed.
936 TelecomManager telecomManager = getTelecommService();
937 boolean hungUp = false;
938 if (telecomManager != null) {
939 if (telecomManager.isRinging()) {
940 // Pressing Power while there's a ringing incoming
941 // call should silence the ringer.
942 telecomManager.silenceRinger();
943 } else if ((mIncallPowerBehavior
944 & Settings.Secure.INCALL_POWER_BUTTON_BEHAVIOR_HANGUP) != 0
945 && telecomManager.isInCall() && interactive) {
946 // Otherwise, if "Power button ends call" is enabled,
947 // the Power button will hang up any current active call.
948 hungUp = telecomManager.endCall();
949 }
950 }
951
Adrian Roos5941c982015-09-03 15:59:49 -0700952 GestureLauncherService gestureService = LocalServices.getService(
953 GestureLauncherService.class);
954 boolean gesturedServiceIntercepted = false;
955 if (gestureService != null) {
956 gesturedServiceIntercepted = gestureService.interceptPowerKeyDown(event, interactive);
957 }
958
Jeff Brown13f00f02014-10-31 14:45:50 -0700959 // If the power key has still not yet been handled, then detect short
960 // press, long press, or multi press and decide what to do.
961 mPowerKeyHandled = hungUp || mScreenshotChordVolumeDownKeyTriggered
Adrian Roos5941c982015-09-03 15:59:49 -0700962 || mScreenshotChordVolumeUpKeyTriggered || gesturedServiceIntercepted;
Jeff Brown13f00f02014-10-31 14:45:50 -0700963 if (!mPowerKeyHandled) {
964 if (interactive) {
965 // When interactive, we're already awake.
966 // Wait for a long press or for the button to be released to decide what to do.
967 if (hasLongPressOnPowerBehavior()) {
968 Message msg = mHandler.obtainMessage(MSG_POWER_LONG_PRESS);
969 msg.setAsynchronous(true);
970 mHandler.sendMessageDelayed(msg,
971 ViewConfiguration.get(mContext).getDeviceGlobalActionKeyTimeout());
972 }
973 } else {
Bryce Leed9268e32014-11-17 17:40:59 -0800974 wakeUpFromPowerKey(event.getDownTime());
Bryce Leed9268e32014-11-17 17:40:59 -0800975
Bryce Leed3b28402015-03-09 15:49:13 +0000976 if (mSupportLongPressPowerWhenNonInteractive && hasLongPressOnPowerBehavior()) {
977 Message msg = mHandler.obtainMessage(MSG_POWER_LONG_PRESS);
978 msg.setAsynchronous(true);
979 mHandler.sendMessageDelayed(msg,
980 ViewConfiguration.get(mContext).getDeviceGlobalActionKeyTimeout());
Bryce Leed9268e32014-11-17 17:40:59 -0800981 mBeganFromNonInteractive = true;
Bryce Leed3b28402015-03-09 15:49:13 +0000982 } else {
983 final int maxCount = getMaxMultiPressPowerCount();
984
985 if (maxCount <= 1) {
986 mPowerKeyHandled = true;
987 } else {
988 mBeganFromNonInteractive = true;
989 }
Jeff Brown13f00f02014-10-31 14:45:50 -0700990 }
991 }
Jeff Brown4d396052010-10-29 21:50:21 -0700992 }
993 }
994
Jeff Brown13f00f02014-10-31 14:45:50 -0700995 private void interceptPowerKeyUp(KeyEvent event, boolean interactive, boolean canceled) {
996 final boolean handled = canceled || mPowerKeyHandled;
997 mScreenshotChordPowerKeyTriggered = false;
998 cancelPendingScreenshotChordAction();
999 cancelPendingPowerKeyAction();
1000
1001 if (!handled) {
1002 // Figure out how to handle the key now that it has been released.
1003 mPowerKeyPressCounter += 1;
1004
1005 final int maxCount = getMaxMultiPressPowerCount();
1006 final long eventTime = event.getDownTime();
1007 if (mPowerKeyPressCounter < maxCount) {
1008 // This could be a multi-press. Wait a little bit longer to confirm.
1009 // Continue holding the wake lock.
1010 Message msg = mHandler.obtainMessage(MSG_POWER_DELAYED_PRESS,
1011 interactive ? 1 : 0, mPowerKeyPressCounter, eventTime);
1012 msg.setAsynchronous(true);
1013 mHandler.sendMessageDelayed(msg, ViewConfiguration.getDoubleTapTimeout());
1014 return;
1015 }
1016
1017 // No other actions. Handle it immediately.
1018 powerPress(eventTime, interactive, mPowerKeyPressCounter);
Jeff Brown4d396052010-10-29 21:50:21 -07001019 }
Jeff Brown13f00f02014-10-31 14:45:50 -07001020
1021 // Done. Reset our state.
1022 finishPowerKeyPress();
1023 }
1024
1025 private void finishPowerKeyPress() {
Bryce Leed9268e32014-11-17 17:40:59 -08001026 mBeganFromNonInteractive = false;
Jeff Brown13f00f02014-10-31 14:45:50 -07001027 mPowerKeyPressCounter = 0;
1028 if (mPowerKeyWakeLock.isHeld()) {
1029 mPowerKeyWakeLock.release();
1030 }
Jeff Brownd5bb82d2011-10-12 13:57:59 -07001031 }
1032
1033 private void cancelPendingPowerKeyAction() {
1034 if (!mPowerKeyHandled) {
Jeff Brown13f00f02014-10-31 14:45:50 -07001035 mPowerKeyHandled = true;
1036 mHandler.removeMessages(MSG_POWER_LONG_PRESS);
Jeff Brownd5bb82d2011-10-12 13:57:59 -07001037 }
Jeff Brown13f00f02014-10-31 14:45:50 -07001038 }
1039
1040 private void powerPress(long eventTime, boolean interactive, int count) {
1041 if (mScreenOnEarly && !mScreenOnFully) {
1042 Slog.i(TAG, "Suppressed redundant power key press while "
1043 + "already in the process of turning the screen on.");
1044 return;
Jeff Brownff204712011-10-25 21:27:54 -07001045 }
Jeff Brown13f00f02014-10-31 14:45:50 -07001046
1047 if (count == 2) {
1048 powerMultiPressAction(eventTime, interactive, mDoublePressOnPowerBehavior);
1049 } else if (count == 3) {
1050 powerMultiPressAction(eventTime, interactive, mTriplePressOnPowerBehavior);
Bryce Leed9268e32014-11-17 17:40:59 -08001051 } else if (interactive && !mBeganFromNonInteractive) {
Jeff Brown13f00f02014-10-31 14:45:50 -07001052 switch (mShortPressOnPowerBehavior) {
1053 case SHORT_PRESS_POWER_NOTHING:
1054 break;
1055 case SHORT_PRESS_POWER_GO_TO_SLEEP:
1056 mPowerManager.goToSleep(eventTime,
1057 PowerManager.GO_TO_SLEEP_REASON_POWER_BUTTON, 0);
1058 break;
1059 case SHORT_PRESS_POWER_REALLY_GO_TO_SLEEP:
1060 mPowerManager.goToSleep(eventTime,
1061 PowerManager.GO_TO_SLEEP_REASON_POWER_BUTTON,
1062 PowerManager.GO_TO_SLEEP_FLAG_NO_DOZE);
1063 break;
1064 case SHORT_PRESS_POWER_REALLY_GO_TO_SLEEP_AND_GO_HOME:
1065 mPowerManager.goToSleep(eventTime,
1066 PowerManager.GO_TO_SLEEP_REASON_POWER_BUTTON,
1067 PowerManager.GO_TO_SLEEP_FLAG_NO_DOZE);
1068 launchHomeFromHotKey();
1069 break;
Bryce Lee01b0c5f2015-02-05 18:24:04 -08001070 case SHORT_PRESS_POWER_GO_HOME:
Bryce Lee662ed802015-04-10 20:11:39 +00001071 launchHomeFromHotKey(true /* awakenFromDreams */, false /*respectKeyguard*/);
Bryce Lee01b0c5f2015-02-05 18:24:04 -08001072 break;
Jeff Brown13f00f02014-10-31 14:45:50 -07001073 }
1074 }
1075 }
1076
1077 private void powerMultiPressAction(long eventTime, boolean interactive, int behavior) {
1078 switch (behavior) {
1079 case MULTI_PRESS_POWER_NOTHING:
1080 break;
1081 case MULTI_PRESS_POWER_THEATER_MODE:
Bryce Lee3ae447e2015-06-30 12:31:41 -07001082 if (!isUserSetupComplete()) {
1083 Slog.i(TAG, "Ignoring toggling theater mode - device not setup.");
1084 break;
1085 }
1086
Jeff Brown13f00f02014-10-31 14:45:50 -07001087 if (isTheaterModeEnabled()) {
1088 Slog.i(TAG, "Toggling theater mode off.");
1089 Settings.Global.putInt(mContext.getContentResolver(),
1090 Settings.Global.THEATER_MODE_ON, 0);
1091 if (!interactive) {
1092 wakeUpFromPowerKey(eventTime);
1093 }
1094 } else {
1095 Slog.i(TAG, "Toggling theater mode on.");
1096 Settings.Global.putInt(mContext.getContentResolver(),
1097 Settings.Global.THEATER_MODE_ON, 1);
Bryce Lee55e846d2014-11-04 12:43:44 -08001098
1099 if (mGoToSleepOnButtonPressTheaterMode && interactive) {
Jeff Brown13f00f02014-10-31 14:45:50 -07001100 mPowerManager.goToSleep(eventTime,
1101 PowerManager.GO_TO_SLEEP_REASON_POWER_BUTTON, 0);
1102 }
1103 }
1104 break;
1105 case MULTI_PRESS_POWER_BRIGHTNESS_BOOST:
Jeff Brown7b5be5e2014-11-12 18:45:31 -08001106 Slog.i(TAG, "Starting brightness boost.");
1107 if (!interactive) {
1108 wakeUpFromPowerKey(eventTime);
1109 }
Jeff Brown13f00f02014-10-31 14:45:50 -07001110 mPowerManager.boostScreenBrightness(eventTime);
1111 break;
1112 }
1113 }
1114
1115 private int getMaxMultiPressPowerCount() {
1116 if (mTriplePressOnPowerBehavior != MULTI_PRESS_POWER_NOTHING) {
1117 return 3;
1118 }
1119 if (mDoublePressOnPowerBehavior != MULTI_PRESS_POWER_NOTHING) {
1120 return 2;
1121 }
1122 return 1;
1123 }
1124
1125 private void powerLongPress() {
1126 final int behavior = getResolvedLongPressOnPowerBehavior();
1127 switch (behavior) {
1128 case LONG_PRESS_POWER_NOTHING:
1129 break;
1130 case LONG_PRESS_POWER_GLOBAL_ACTIONS:
1131 mPowerKeyHandled = true;
1132 if (!performHapticFeedbackLw(null, HapticFeedbackConstants.LONG_PRESS, false)) {
1133 performAuditoryFeedbackForAccessibilityIfNeed();
1134 }
1135 showGlobalActionsInternal();
1136 break;
1137 case LONG_PRESS_POWER_SHUT_OFF:
1138 case LONG_PRESS_POWER_SHUT_OFF_NO_CONFIRM:
1139 mPowerKeyHandled = true;
1140 performHapticFeedbackLw(null, HapticFeedbackConstants.LONG_PRESS, false);
1141 sendCloseSystemWindows(SYSTEM_DIALOG_REASON_GLOBAL_ACTIONS);
1142 mWindowManagerFuncs.shutdown(behavior == LONG_PRESS_POWER_SHUT_OFF);
1143 break;
1144 }
1145 }
1146
Nick Vaccarob593a812015-05-15 11:23:05 -07001147 private void sleepPress(long eventTime) {
1148 if (mShortPressOnSleepBehavior == SHORT_PRESS_SLEEP_GO_TO_SLEEP_AND_GO_HOME) {
1149 launchHomeFromHotKey(false /* awakenDreams */, true /*respectKeyguard*/);
1150 }
1151 }
1152
1153 private void sleepRelease(long eventTime) {
Filip Gruszczynskia483a1d2015-03-17 19:06:58 +00001154 switch (mShortPressOnSleepBehavior) {
1155 case SHORT_PRESS_SLEEP_GO_TO_SLEEP:
Filip Gruszczynskia483a1d2015-03-17 19:06:58 +00001156 case SHORT_PRESS_SLEEP_GO_TO_SLEEP_AND_GO_HOME:
Nick Vaccarob593a812015-05-15 11:23:05 -07001157 Slog.i(TAG, "sleepRelease() calling goToSleep(GO_TO_SLEEP_REASON_SLEEP_BUTTON)");
1158 mPowerManager.goToSleep(eventTime,
1159 PowerManager.GO_TO_SLEEP_REASON_SLEEP_BUTTON, 0);
Filip Gruszczynskia483a1d2015-03-17 19:06:58 +00001160 break;
1161 }
1162 }
1163
Jeff Brown13f00f02014-10-31 14:45:50 -07001164 private int getResolvedLongPressOnPowerBehavior() {
1165 if (FactoryTest.isLongPressOnPowerOffEnabled()) {
1166 return LONG_PRESS_POWER_SHUT_OFF_NO_CONFIRM;
1167 }
1168 return mLongPressOnPowerBehavior;
1169 }
1170
1171 private boolean hasLongPressOnPowerBehavior() {
1172 return getResolvedLongPressOnPowerBehavior() != LONG_PRESS_POWER_NOTHING;
Jeff Brownd5bb82d2011-10-12 13:57:59 -07001173 }
1174
1175 private void interceptScreenshotChord() {
Christopher Tatee90585f2012-03-05 18:56:25 -08001176 if (mScreenshotChordEnabled
Jeff Brown13f00f02014-10-31 14:45:50 -07001177 && mScreenshotChordVolumeDownKeyTriggered && mScreenshotChordPowerKeyTriggered
1178 && !mScreenshotChordVolumeUpKeyTriggered) {
Jeff Brownd5bb82d2011-10-12 13:57:59 -07001179 final long now = SystemClock.uptimeMillis();
Jeff Brown13f00f02014-10-31 14:45:50 -07001180 if (now <= mScreenshotChordVolumeDownKeyTime + SCREENSHOT_CHORD_DEBOUNCE_DELAY_MILLIS
1181 && now <= mScreenshotChordPowerKeyTime
1182 + SCREENSHOT_CHORD_DEBOUNCE_DELAY_MILLIS) {
1183 mScreenshotChordVolumeDownKeyConsumed = true;
Jeff Brownd5bb82d2011-10-12 13:57:59 -07001184 cancelPendingPowerKeyAction();
1185
Jeff Sharkey2991fa32012-12-05 18:06:43 -08001186 mHandler.postDelayed(mScreenshotRunnable, getScreenshotChordLongPressDelay());
Jeff Brownd5bb82d2011-10-12 13:57:59 -07001187 }
1188 }
1189 }
1190
Winson Chung1cea2f32012-10-08 20:42:01 -07001191 private long getScreenshotChordLongPressDelay() {
Jim Miller5ecd8112013-01-09 18:50:26 -08001192 if (mKeyguardDelegate.isShowing()) {
Winson Chung1cea2f32012-10-08 20:42:01 -07001193 // Double the time it takes to take a screenshot from the keyguard
1194 return (long) (KEYGUARD_SCREENSHOT_CHORD_DELAY_MULTIPLIER *
Justin Kohfeabd2c2014-05-02 10:02:44 -07001195 ViewConfiguration.get(mContext).getDeviceGlobalActionKeyTimeout());
Winson Chung1cea2f32012-10-08 20:42:01 -07001196 }
Justin Kohfeabd2c2014-05-02 10:02:44 -07001197 return ViewConfiguration.get(mContext).getDeviceGlobalActionKeyTimeout();
Winson Chung1cea2f32012-10-08 20:42:01 -07001198 }
1199
Jeff Brownd5bb82d2011-10-12 13:57:59 -07001200 private void cancelPendingScreenshotChordAction() {
Jeff Sharkey2991fa32012-12-05 18:06:43 -08001201 mHandler.removeCallbacks(mScreenshotRunnable);
Jeff Brown4d396052010-10-29 21:50:21 -07001202 }
1203
Jeff Brown13f00f02014-10-31 14:45:50 -07001204 private final Runnable mEndCallLongPress = new Runnable() {
Craig Mautnerf1b67412012-09-19 13:18:29 -07001205 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001206 public void run() {
Jeff Brown13f00f02014-10-31 14:45:50 -07001207 mEndCallKeyHandled = true;
1208 if (!performHapticFeedbackLw(null, HapticFeedbackConstants.LONG_PRESS, false)) {
1209 performAuditoryFeedbackForAccessibilityIfNeed();
Joe Onoratod208e702010-10-08 16:22:43 -04001210 }
Jeff Brown13f00f02014-10-31 14:45:50 -07001211 showGlobalActionsInternal();
Jeff Brownd5bb82d2011-10-12 13:57:59 -07001212 }
1213 };
1214
Jeff Sharkey2991fa32012-12-05 18:06:43 -08001215 private final Runnable mScreenshotRunnable = new Runnable() {
Craig Mautner0bf6ec92012-12-18 08:33:27 -08001216 @Override
Jeff Brownd5bb82d2011-10-12 13:57:59 -07001217 public void run() {
1218 takeScreenshot();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001219 }
1220 };
1221
Alan Viverettee34560b22014-07-10 14:50:06 -07001222 @Override
1223 public void showGlobalActions() {
1224 mHandler.removeMessages(MSG_DISPATCH_SHOW_GLOBAL_ACTIONS);
1225 mHandler.sendEmptyMessage(MSG_DISPATCH_SHOW_GLOBAL_ACTIONS);
1226 }
1227
1228 void showGlobalActionsInternal() {
1229 sendCloseSystemWindows(SYSTEM_DIALOG_REASON_GLOBAL_ACTIONS);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001230 if (mGlobalActions == null) {
Jeff Brown7304c342012-05-11 18:42:42 -07001231 mGlobalActions = new GlobalActions(mContext, mWindowManagerFuncs);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001232 }
Jim Millerab954542014-10-10 18:21:49 -07001233 final boolean keyguardShowing = isKeyguardShowingAndNotOccluded();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001234 mGlobalActions.showDialog(keyguardShowing, isDeviceProvisioned());
1235 if (keyguardShowing) {
1236 // since it took two seconds of long press to bring this up,
1237 // poke the wake lock so they have some time to see the dialog.
Jim Miller25190572013-02-28 17:36:24 -08001238 mPowerManager.userActivity(SystemClock.uptimeMillis(), false);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001239 }
1240 }
1241
1242 boolean isDeviceProvisioned() {
Jeff Brownbf6f6f92012-09-25 15:03:20 -07001243 return Settings.Global.getInt(
1244 mContext.getContentResolver(), Settings.Global.DEVICE_PROVISIONED, 0) != 0;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001245 }
1246
Maurice Lam99c6e072014-04-28 18:24:28 -07001247 boolean isUserSetupComplete() {
1248 return Settings.Secure.getIntForUser(mContext.getContentResolver(),
1249 Settings.Secure.USER_SETUP_COMPLETE, 0, UserHandle.USER_CURRENT) != 0;
1250 }
1251
Jeff Brown13f00f02014-10-31 14:45:50 -07001252 private void handleShortPressOnHome() {
Jinsuk Kime601b712015-07-07 08:01:02 +09001253 // Turn on the connected TV and switch HDMI input if we're a HDMI playback device.
1254 getHdmiControl().turnOnTv();
1255
Jeff Brown13f00f02014-10-31 14:45:50 -07001256 // If there's a dream running then use home to escape the dream
1257 // but don't actually go home.
1258 if (mDreamManagerInternal != null && mDreamManagerInternal.isDreaming()) {
1259 mDreamManagerInternal.stopDream(false /*immediate*/);
1260 return;
1261 }
1262
1263 // Go home!
1264 launchHomeFromHotKey();
1265 }
1266
Jinsuk Kime601b712015-07-07 08:01:02 +09001267 /**
1268 * Creates an accessor to HDMI control service that performs the operation of
1269 * turning on TV (optional) and switching input to us. If HDMI control service
1270 * is not available or we're not a HDMI playback device, the operation is no-op.
1271 */
1272 private HdmiControl getHdmiControl() {
1273 if (null == mHdmiControl) {
1274 HdmiControlManager manager = (HdmiControlManager) mContext.getSystemService(
1275 Context.HDMI_CONTROL_SERVICE);
1276 HdmiPlaybackClient client = null;
1277 if (manager != null) {
1278 client = manager.getPlaybackClient();
1279 }
1280 mHdmiControl = new HdmiControl(client);
1281 }
1282 return mHdmiControl;
1283 }
1284
1285 private static class HdmiControl {
1286 private final HdmiPlaybackClient mClient;
1287
1288 private HdmiControl(HdmiPlaybackClient client) {
1289 mClient = client;
1290 }
1291
1292 public void turnOnTv() {
1293 if (mClient == null) {
1294 return;
1295 }
1296 mClient.oneTouchPlay(new OneTouchPlayCallback() {
1297 @Override
1298 public void onComplete(int result) {
1299 if (result != HdmiControlManager.RESULT_SUCCESS) {
1300 Log.w(TAG, "One touch play failed: " + result);
1301 }
1302 }
1303 });
1304 }
1305 }
1306
Tim Kilbourn0e5f1102015-06-05 16:18:09 -07001307 private void handleLongPressOnHome(int deviceId) {
Joe Onorato46b0d682010-11-22 17:37:27 -08001308 if (mLongPressOnHomeBehavior != LONG_PRESS_HOME_NOTHING) {
Jeff Browncaca8812013-05-09 13:34:33 -07001309 mHomeConsumed = true;
Joe Onorato46b0d682010-11-22 17:37:27 -08001310 performHapticFeedbackLw(null, HapticFeedbackConstants.LONG_PRESS, false);
Patrick Dubroyece94522011-02-23 18:35:01 -08001311
Jeff Browncaca8812013-05-09 13:34:33 -07001312 if (mLongPressOnHomeBehavior == LONG_PRESS_HOME_RECENT_SYSTEM_UI) {
1313 toggleRecentApps();
1314 } else if (mLongPressOnHomeBehavior == LONG_PRESS_HOME_ASSIST) {
Tim Kilbourn0e5f1102015-06-05 16:18:09 -07001315 launchAssistAction(null, deviceId);
Jim Millere6ad1a82010-08-20 19:25:39 -07001316 }
1317 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001318 }
Patrick Dubroyece94522011-02-23 18:35:01 -08001319
Jeff Browncaca8812013-05-09 13:34:33 -07001320 private void handleDoubleTapOnHome() {
1321 if (mDoubleTapOnHomeBehavior == DOUBLE_TAP_HOME_RECENT_SYSTEM_UI) {
1322 mHomeConsumed = true;
1323 toggleRecentApps();
1324 }
1325 }
1326
1327 private final Runnable mHomeDoubleTapTimeoutRunnable = new Runnable() {
1328 @Override
1329 public void run() {
1330 if (mHomeDoubleTapPending) {
1331 mHomeDoubleTapPending = false;
Jeff Brown13f00f02014-10-31 14:45:50 -07001332 handleShortPressOnHome();
Jeff Browncaca8812013-05-09 13:34:33 -07001333 }
1334 }
1335 };
1336
Mark Renoufc1256912015-03-11 14:38:23 -04001337 private boolean isRoundWindow() {
Adam Powell01f280d2015-05-18 16:07:42 -07001338 return mContext.getResources().getConfiguration().isScreenRound();
Mark Renoufc1256912015-03-11 14:38:23 -04001339 }
1340
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001341 /** {@inheritDoc} */
Craig Mautner0bf6ec92012-12-18 08:33:27 -08001342 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001343 public void init(Context context, IWindowManager windowManager,
Jeff Brown96307042012-07-27 15:51:34 -07001344 WindowManagerFuncs windowManagerFuncs) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001345 mContext = context;
1346 mWindowManager = windowManager;
Dianne Hackborndf89e652011-10-06 22:35:11 -07001347 mWindowManagerFuncs = windowManagerFuncs;
Craig Mautner8a0da012014-05-31 15:13:37 -07001348 mWindowManagerInternal = LocalServices.getService(WindowManagerInternal.class);
Jeff Brown061ea992015-04-17 19:55:47 -07001349 mActivityManagerInternal = LocalServices.getService(ActivityManagerInternal.class);
Jose Lima9546b202014-07-02 17:21:51 -07001350 mDreamManagerInternal = LocalServices.getService(DreamManagerInternal.class);
Michael Wrighta4d22d72015-09-16 23:19:26 +01001351 mPowerManagerInternal = LocalServices.getService(PowerManagerInternal.class);
Billy Laucbe540f2015-06-25 01:51:44 +01001352 mAppOpsManager = (AppOpsManager) mContext.getSystemService(Context.APP_OPS_SERVICE);
Mark Renoufc1256912015-03-11 14:38:23 -04001353
1354 // Init display burn-in protection
1355 boolean burnInProtectionEnabled = context.getResources().getBoolean(
1356 com.android.internal.R.bool.config_enableBurnInProtection);
1357 // Allow a system property to override this. Used by developer settings.
1358 boolean burnInProtectionDevMode =
1359 SystemProperties.getBoolean("persist.debug.force_burn_in", false);
1360 if (burnInProtectionEnabled || burnInProtectionDevMode) {
1361 final int minHorizontal;
1362 final int maxHorizontal;
1363 final int minVertical;
1364 final int maxVertical;
1365 final int maxRadius;
1366 if (burnInProtectionDevMode) {
1367 minHorizontal = -8;
1368 maxHorizontal = 8;
1369 minVertical = -8;
1370 maxVertical = -4;
1371 maxRadius = (isRoundWindow()) ? 6 : -1;
1372 } else {
1373 Resources resources = context.getResources();
1374 minHorizontal = resources.getInteger(
1375 com.android.internal.R.integer.config_burnInProtectionMinHorizontalOffset);
1376 maxHorizontal = resources.getInteger(
1377 com.android.internal.R.integer.config_burnInProtectionMaxHorizontalOffset);
1378 minVertical = resources.getInteger(
1379 com.android.internal.R.integer.config_burnInProtectionMinVerticalOffset);
1380 maxVertical = resources.getInteger(
1381 com.android.internal.R.integer.config_burnInProtectionMaxVerticalOffset);
1382 maxRadius = resources.getInteger(
1383 com.android.internal.R.integer.config_burnInProtectionMaxRadius);
1384 }
1385 mBurnInProtectionHelper = new BurnInProtectionHelper(
1386 context, minHorizontal, maxHorizontal, minVertical, maxVertical, maxRadius);
Filip Gruszczynskicfb31852015-02-25 21:47:12 +00001387 }
Craig Mautner8a0da012014-05-31 15:13:37 -07001388
Jeff Brown70825162012-03-28 17:27:48 -07001389 mHandler = new PolicyHandler();
Jeff Browna20dda42014-05-27 20:57:24 -07001390 mWakeGestureListener = new MyWakeGestureListener(mContext, mHandler);
Craig Mautnereee29c42013-01-17 14:44:34 -08001391 mOrientationListener = new MyOrientationListener(mContext, mHandler);
Jeff Brownc0347aa2011-09-23 17:26:09 -07001392 try {
1393 mOrientationListener.setCurrentRotation(windowManager.getRotation());
1394 } catch (RemoteException ex) { }
Christopher Tate5e08af02012-09-21 17:17:22 -07001395 mSettingsObserver = new SettingsObserver(mHandler);
1396 mSettingsObserver.observe();
Svetoslav683914b2015-01-15 14:22:26 -08001397 mShortcutManager = new ShortcutManager(context);
Daniel Sandler6396c722013-04-16 20:19:09 -04001398 mUiMode = context.getResources().getInteger(
1399 com.android.internal.R.integer.config_defaultUiModeType);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001400 mHomeIntent = new Intent(Intent.ACTION_MAIN, null);
1401 mHomeIntent.addCategory(Intent.CATEGORY_HOME);
1402 mHomeIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK
1403 | Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED);
keunyounga7710492015-09-23 11:33:58 -07001404 mEnableCarDockHomeCapture = context.getResources().getBoolean(
1405 com.android.internal.R.bool.config_enableCarDockHomeLaunch);
Dianne Hackborn39c2d712009-09-22 11:41:31 -07001406 mCarDockIntent = new Intent(Intent.ACTION_MAIN, null);
1407 mCarDockIntent.addCategory(Intent.CATEGORY_CAR_DOCK);
1408 mCarDockIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK
1409 | Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED);
1410 mDeskDockIntent = new Intent(Intent.ACTION_MAIN, null);
1411 mDeskDockIntent.addCategory(Intent.CATEGORY_DESK_DOCK);
1412 mDeskDockIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK
1413 | Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED);
Jim Millere6ad1a82010-08-20 19:25:39 -07001414
Jeff Brown96307042012-07-27 15:51:34 -07001415 mPowerManager = (PowerManager)context.getSystemService(Context.POWER_SERVICE);
1416 mBroadcastWakeLock = mPowerManager.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK,
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001417 "PhoneWindowManager.mBroadcastWakeLock");
Jeff Brown13f00f02014-10-31 14:45:50 -07001418 mPowerKeyWakeLock = mPowerManager.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK,
1419 "PhoneWindowManager.mPowerKeyWakeLock");
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001420 mEnableShiftMenuBugReports = "1".equals(SystemProperties.get("ro.debuggable"));
Jeff Brownbcdfc622014-03-06 19:13:04 -08001421 mSupportAutoRotation = mContext.getResources().getBoolean(
1422 com.android.internal.R.bool.config_supportAutoRotation);
Dianne Hackborn2862fff2009-09-15 22:56:29 -07001423 mLidOpenRotation = readRotation(
Mike Lockwood2d1efbd2009-09-16 12:15:53 -04001424 com.android.internal.R.integer.config_lidOpenRotation);
1425 mCarDockRotation = readRotation(
1426 com.android.internal.R.integer.config_carDockRotation);
1427 mDeskDockRotation = readRotation(
1428 com.android.internal.R.integer.config_deskDockRotation);
Jeff Brownc82c89ed2013-04-17 17:18:15 -07001429 mUndockedHdmiRotation = readRotation(
1430 com.android.internal.R.integer.config_undockedHdmiRotation);
Mike Lockwoode9867d22009-09-20 01:59:02 -04001431 mCarDockEnablesAccelerometer = mContext.getResources().getBoolean(
1432 com.android.internal.R.bool.config_carDockEnablesAccelerometer);
1433 mDeskDockEnablesAccelerometer = mContext.getResources().getBoolean(
1434 com.android.internal.R.bool.config_deskDockEnablesAccelerometer);
Dianne Hackborn2862fff2009-09-15 22:56:29 -07001435 mLidKeyboardAccessibility = mContext.getResources().getInteger(
1436 com.android.internal.R.integer.config_lidKeyboardAccessibility);
1437 mLidNavigationAccessibility = mContext.getResources().getInteger(
1438 com.android.internal.R.integer.config_lidNavigationAccessibility);
Jeff Brownc458ce92012-04-30 14:58:40 -07001439 mLidControlsSleep = mContext.getResources().getBoolean(
1440 com.android.internal.R.bool.config_lidControlsSleep);
Daniel Sandlerdd73ee42013-10-11 22:19:59 -04001441 mTranslucentDecorEnabled = mContext.getResources().getBoolean(
1442 com.android.internal.R.bool.config_enableTranslucentDecor);
Bryce Lee584a4452014-10-21 15:55:55 -07001443
1444 mAllowTheaterModeWakeFromKey = mContext.getResources().getBoolean(
1445 com.android.internal.R.bool.config_allowTheaterModeWakeFromKey);
1446 mAllowTheaterModeWakeFromPowerKey = mAllowTheaterModeWakeFromKey
1447 || mContext.getResources().getBoolean(
1448 com.android.internal.R.bool.config_allowTheaterModeWakeFromPowerKey);
1449 mAllowTheaterModeWakeFromMotion = mContext.getResources().getBoolean(
1450 com.android.internal.R.bool.config_allowTheaterModeWakeFromMotion);
Bryce Lee812d7022014-11-10 13:33:28 -08001451 mAllowTheaterModeWakeFromMotionWhenNotDreaming = mContext.getResources().getBoolean(
1452 com.android.internal.R.bool.config_allowTheaterModeWakeFromMotionWhenNotDreaming);
Bryce Lee584a4452014-10-21 15:55:55 -07001453 mAllowTheaterModeWakeFromCameraLens = mContext.getResources().getBoolean(
1454 com.android.internal.R.bool.config_allowTheaterModeWakeFromCameraLens);
1455 mAllowTheaterModeWakeFromLidSwitch = mContext.getResources().getBoolean(
1456 com.android.internal.R.bool.config_allowTheaterModeWakeFromLidSwitch);
1457 mAllowTheaterModeWakeFromWakeGesture = mContext.getResources().getBoolean(
1458 com.android.internal.R.bool.config_allowTheaterModeWakeFromGesture);
1459
Bryce Lee55e846d2014-11-04 12:43:44 -08001460 mGoToSleepOnButtonPressTheaterMode = mContext.getResources().getBoolean(
1461 com.android.internal.R.bool.config_goToSleepOnButtonPressTheaterMode);
1462
Bryce Leed3b28402015-03-09 15:49:13 +00001463 mSupportLongPressPowerWhenNonInteractive = mContext.getResources().getBoolean(
1464 com.android.internal.R.bool.config_supportLongPressPowerWhenNonInteractive);
1465
Jeff Brown13f00f02014-10-31 14:45:50 -07001466 mShortPressOnPowerBehavior = mContext.getResources().getInteger(
1467 com.android.internal.R.integer.config_shortPressOnPowerBehavior);
1468 mLongPressOnPowerBehavior = mContext.getResources().getInteger(
1469 com.android.internal.R.integer.config_longPressOnPowerBehavior);
1470 mDoublePressOnPowerBehavior = mContext.getResources().getInteger(
1471 com.android.internal.R.integer.config_doublePressOnPowerBehavior);
1472 mTriplePressOnPowerBehavior = mContext.getResources().getInteger(
1473 com.android.internal.R.integer.config_triplePressOnPowerBehavior);
Filip Gruszczynskia483a1d2015-03-17 19:06:58 +00001474 mShortPressOnSleepBehavior = mContext.getResources().getInteger(
1475 com.android.internal.R.integer.config_shortPressOnSleepBehavior);
Jeff Brown13f00f02014-10-31 14:45:50 -07001476
John Spurlock61560172015-02-06 19:46:04 -05001477 mUseTvRouting = AudioSystem.getPlatformType(mContext) == AudioSystem.PLATFORM_TELEVISION;
RoboErik001c59c2015-01-26 15:53:51 -08001478
Jeff Brownf71343d2013-05-31 17:59:11 -07001479 readConfigurationDependentBehaviors();
Jeff Browncaca8812013-05-09 13:34:33 -07001480
Svetoslav8e3feb12014-02-24 13:46:47 -08001481 mAccessibilityManager = (AccessibilityManager) context.getSystemService(
1482 Context.ACCESSIBILITY_SERVICE);
1483
Mike Lockwood1753f7f2009-08-24 14:49:07 -07001484 // register for dock events
Dianne Hackborn78968392010-03-04 20:47:56 -08001485 IntentFilter filter = new IntentFilter();
1486 filter.addAction(UiModeManager.ACTION_ENTER_CAR_MODE);
1487 filter.addAction(UiModeManager.ACTION_EXIT_CAR_MODE);
1488 filter.addAction(UiModeManager.ACTION_ENTER_DESK_MODE);
1489 filter.addAction(UiModeManager.ACTION_EXIT_DESK_MODE);
Dianne Hackborn867ab6472010-04-29 13:28:56 -07001490 filter.addAction(Intent.ACTION_DOCK_EVENT);
1491 Intent intent = context.registerReceiver(mDockReceiver, filter);
1492 if (intent != null) {
1493 // Retrieve current sticky dock event broadcast.
1494 mDockMode = intent.getIntExtra(Intent.EXTRA_DOCK_STATE,
1495 Intent.EXTRA_DOCK_STATE_UNDOCKED);
1496 }
Daniel Sandler7e37df52011-11-16 22:08:23 -08001497
Jeff Brown6aaf2952012-10-05 16:01:08 -07001498 // register for dream-related broadcasts
1499 filter = new IntentFilter();
1500 filter.addAction(Intent.ACTION_DREAMING_STARTED);
1501 filter.addAction(Intent.ACTION_DREAMING_STOPPED);
1502 context.registerReceiver(mDreamReceiver, filter);
1503
Christopher Tate5e08af02012-09-21 17:17:22 -07001504 // register for multiuser-relevant broadcasts
1505 filter = new IntentFilter(Intent.ACTION_USER_SWITCHED);
1506 context.registerReceiver(mMultiuserReceiver, filter);
1507
John Spurlock57306e62013-04-22 09:48:49 -04001508 // monitor for system gestures
Craig Mautner037aa8d2013-06-07 10:35:44 -07001509 mSystemGestures = new SystemGesturesPointerEventListener(context,
1510 new SystemGesturesPointerEventListener.Callbacks() {
John Spurlock57306e62013-04-22 09:48:49 -04001511 @Override
1512 public void onSwipeFromTop() {
John Spurlock04db1762013-05-13 12:46:41 -04001513 if (mStatusBar != null) {
John Spurlocke1f366f2013-08-05 12:22:40 -04001514 requestTransientBars(mStatusBar);
John Spurlock04db1762013-05-13 12:46:41 -04001515 }
John Spurlockad3e6cb2013-04-30 08:47:43 -04001516 }
1517 @Override
1518 public void onSwipeFromBottom() {
John Spurlock04db1762013-05-13 12:46:41 -04001519 if (mNavigationBar != null && mNavigationBarOnBottom) {
John Spurlocke1f366f2013-08-05 12:22:40 -04001520 requestTransientBars(mNavigationBar);
John Spurlockad3e6cb2013-04-30 08:47:43 -04001521 }
1522 }
1523 @Override
1524 public void onSwipeFromRight() {
John Spurlock04db1762013-05-13 12:46:41 -04001525 if (mNavigationBar != null && !mNavigationBarOnBottom) {
John Spurlocke1f366f2013-08-05 12:22:40 -04001526 requestTransientBars(mNavigationBar);
John Spurlockad3e6cb2013-04-30 08:47:43 -04001527 }
1528 }
1529 @Override
Michael Wrighta4d22d72015-09-16 23:19:26 +01001530 public void onFling(int duration) {
1531 if (mPowerManagerInternal != null) {
1532 mPowerManagerInternal.powerHint(
1533 PowerManagerInternal.POWER_HINT_INTERACTION, duration);
1534 }
1535 }
1536 @Override
John Spurlockad3e6cb2013-04-30 08:47:43 -04001537 public void onDebug() {
John Spurlockd67ec252013-09-05 11:31:54 -04001538 // no-op
John Spurlockad3e6cb2013-04-30 08:47:43 -04001539 }
Adrian Roos3595be42015-03-05 16:31:15 +01001540 @Override
1541 public void onDown() {
1542 mOrientationListener.onTouchStart();
1543 }
1544 @Override
1545 public void onUpOrCancel() {
1546 mOrientationListener.onTouchEnd();
1547 }
Jun Mukaid2e7e352015-07-22 17:14:02 -07001548 @Override
1549 public void onMouseHoverAtTop() {
1550 mHandler.removeMessages(MSG_REQUEST_TRANSIENT_BARS);
1551 Message msg = mHandler.obtainMessage(MSG_REQUEST_TRANSIENT_BARS);
1552 msg.arg1 = MSG_REQUEST_TRANSIENT_BARS_ARG_STATUS;
1553 mHandler.sendMessageDelayed(msg, 500);
1554 }
1555 @Override
1556 public void onMouseHoverAtBottom() {
1557 mHandler.removeMessages(MSG_REQUEST_TRANSIENT_BARS);
1558 Message msg = mHandler.obtainMessage(MSG_REQUEST_TRANSIENT_BARS);
1559 msg.arg1 = MSG_REQUEST_TRANSIENT_BARS_ARG_NAVIGATION;
1560 mHandler.sendMessageDelayed(msg, 500);
1561 }
1562 @Override
1563 public void onMouseLeaveFromEdge() {
1564 mHandler.removeMessages(MSG_REQUEST_TRANSIENT_BARS);
1565 }
John Spurlockad3e6cb2013-04-30 08:47:43 -04001566 });
John Spurlockf1a36642013-10-12 17:50:42 -04001567 mImmersiveModeConfirmation = new ImmersiveModeConfirmation(mContext);
Craig Mautner037aa8d2013-06-07 10:35:44 -07001568 mWindowManagerFuncs.registerPointerEventListener(mSystemGestures);
John Spurlock32beb2c2013-03-11 10:16:47 -04001569
Jeff Brownc2346132012-04-13 01:55:38 -07001570 mVibrator = (Vibrator)context.getSystemService(Context.VIBRATOR_SERVICE);
Dianne Hackbornb1a79802009-09-29 15:18:31 -07001571 mLongPressVibePattern = getLongIntArray(mContext.getResources(),
1572 com.android.internal.R.array.config_longPressVibePattern);
1573 mVirtualKeyVibePattern = getLongIntArray(mContext.getResources(),
1574 com.android.internal.R.array.config_virtualKeyVibePattern);
Amith Yamasanic33cb712010-02-10 15:21:49 -08001575 mKeyboardTapVibePattern = getLongIntArray(mContext.getResources(),
1576 com.android.internal.R.array.config_keyboardTapVibePattern);
Fabrice Di Meglioeeff63a2013-08-05 12:07:24 -07001577 mClockTickVibePattern = getLongIntArray(mContext.getResources(),
1578 com.android.internal.R.array.config_clockTickVibePattern);
Fabrice Di Megliobd9152f2013-10-01 11:21:31 -07001579 mCalendarDateVibePattern = getLongIntArray(mContext.getResources(),
1580 com.android.internal.R.array.config_calendarDateVibePattern);
Dianne Hackbornb1a79802009-09-29 15:18:31 -07001581 mSafeModeDisabledVibePattern = getLongIntArray(mContext.getResources(),
1582 com.android.internal.R.array.config_safeModeDisabledVibePattern);
1583 mSafeModeEnabledVibePattern = getLongIntArray(mContext.getResources(),
1584 com.android.internal.R.array.config_safeModeEnabledVibePattern);
Mady Mellore8608912015-06-05 09:02:55 -07001585 mContextClickVibePattern = getLongIntArray(mContext.getResources(),
1586 com.android.internal.R.array.config_contextClickVibePattern);
Daniel Sandler40427442010-07-16 11:44:52 -04001587
Christopher Tatee90585f2012-03-05 18:56:25 -08001588 mScreenshotChordEnabled = mContext.getResources().getBoolean(
1589 com.android.internal.R.bool.config_enableScreenshotChord);
1590
Justin Kohd378ad72013-04-01 12:18:26 -07001591 mGlobalKeyManager = new GlobalKeyManager(mContext);
1592
Joe Onoratoea495d42011-04-06 11:41:11 -07001593 // Controls rotation and the like.
1594 initializeHdmiState();
Dianne Hackborn40011092011-09-22 13:37:48 -07001595
1596 // Match current screen state.
Craig Mautnera631d492014-08-05 15:16:01 -07001597 if (!mPowerManager.isInteractive()) {
Jeff Brown416c49c2015-05-26 19:50:18 -07001598 startedGoingToSleep(WindowManagerPolicy.OFF_BECAUSE_OF_USER);
1599 finishedGoingToSleep(WindowManagerPolicy.OFF_BECAUSE_OF_USER);
Dianne Hackborn40011092011-09-22 13:37:48 -07001600 }
Jorim Jaggi24bec7c2015-02-04 12:40:14 +01001601
1602 mWindowManagerInternal.registerAppTransitionListener(
1603 mStatusBarController.getAppTransitionListener());
Mike Lockwood1753f7f2009-08-24 14:49:07 -07001604 }
1605
Jeff Brownf71343d2013-05-31 17:59:11 -07001606 /**
1607 * Read values from config.xml that may be overridden depending on
1608 * the configuration of the device.
1609 * eg. Disable long press on home goes to recents on sw600dp.
1610 */
1611 private void readConfigurationDependentBehaviors() {
1612 mLongPressOnHomeBehavior = mContext.getResources().getInteger(
1613 com.android.internal.R.integer.config_longPressOnHomeBehavior);
1614 if (mLongPressOnHomeBehavior < LONG_PRESS_HOME_NOTHING ||
1615 mLongPressOnHomeBehavior > LONG_PRESS_HOME_ASSIST) {
1616 mLongPressOnHomeBehavior = LONG_PRESS_HOME_NOTHING;
1617 }
1618
1619 mDoubleTapOnHomeBehavior = mContext.getResources().getInteger(
1620 com.android.internal.R.integer.config_doubleTapOnHomeBehavior);
1621 if (mDoubleTapOnHomeBehavior < DOUBLE_TAP_HOME_NOTHING ||
1622 mDoubleTapOnHomeBehavior > DOUBLE_TAP_HOME_RECENT_SYSTEM_UI) {
1623 mDoubleTapOnHomeBehavior = LONG_PRESS_HOME_NOTHING;
1624 }
1625 }
1626
Craig Mautner0bf6ec92012-12-18 08:33:27 -08001627 @Override
Dianne Hackborndde331c2012-08-03 14:01:57 -07001628 public void setInitialDisplaySize(Display display, int width, int height, int density) {
Jeff Brownef981a42013-08-07 14:13:37 -07001629 // This method might be called before the policy has been fully initialized
1630 // or for other displays we don't care about.
1631 if (mContext == null || display.getDisplayId() != Display.DEFAULT_DISPLAY) {
1632 return;
Dianne Hackbornc652de82013-02-15 16:32:56 -08001633 }
Dianne Hackbornf87d1962012-04-04 12:48:24 -07001634 mDisplay = display;
1635
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001636 final Resources res = mContext.getResources();
Dianne Hackbornf87d1962012-04-04 12:48:24 -07001637 int shortSize, longSize;
Dianne Hackborn9d132642011-04-21 17:26:39 -07001638 if (width > height) {
Dianne Hackborn81e56d52011-05-26 00:55:58 -07001639 shortSize = height;
Dianne Hackbornf87d1962012-04-04 12:48:24 -07001640 longSize = width;
Dianne Hackborn9d132642011-04-21 17:26:39 -07001641 mLandscapeRotation = Surface.ROTATION_0;
1642 mSeascapeRotation = Surface.ROTATION_180;
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001643 if (res.getBoolean(com.android.internal.R.bool.config_reverseDefaultRotation)) {
Dianne Hackborn9d132642011-04-21 17:26:39 -07001644 mPortraitRotation = Surface.ROTATION_90;
1645 mUpsideDownRotation = Surface.ROTATION_270;
1646 } else {
1647 mPortraitRotation = Surface.ROTATION_270;
1648 mUpsideDownRotation = Surface.ROTATION_90;
1649 }
1650 } else {
Dianne Hackborn81e56d52011-05-26 00:55:58 -07001651 shortSize = width;
Dianne Hackbornf87d1962012-04-04 12:48:24 -07001652 longSize = height;
Dianne Hackborn9d132642011-04-21 17:26:39 -07001653 mPortraitRotation = Surface.ROTATION_0;
1654 mUpsideDownRotation = Surface.ROTATION_180;
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001655 if (res.getBoolean(com.android.internal.R.bool.config_reverseDefaultRotation)) {
Dianne Hackborn9d132642011-04-21 17:26:39 -07001656 mLandscapeRotation = Surface.ROTATION_270;
1657 mSeascapeRotation = Surface.ROTATION_90;
1658 } else {
1659 mLandscapeRotation = Surface.ROTATION_90;
1660 mSeascapeRotation = Surface.ROTATION_270;
1661 }
1662 }
Dianne Hackborn81e56d52011-05-26 00:55:58 -07001663
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001664 mStatusBarHeight =
1665 res.getDimensionPixelSize(com.android.internal.R.dimen.status_bar_height);
Dianne Hackbornf87d1962012-04-04 12:48:24 -07001666
Daniel Sandler9f65c4c2012-04-26 01:35:35 -04001667 // Height of the navigation bar when presented horizontally at bottom
1668 mNavigationBarHeightForRotation[mPortraitRotation] =
1669 mNavigationBarHeightForRotation[mUpsideDownRotation] =
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001670 res.getDimensionPixelSize(com.android.internal.R.dimen.navigation_bar_height);
Daniel Sandler9f65c4c2012-04-26 01:35:35 -04001671 mNavigationBarHeightForRotation[mLandscapeRotation] =
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001672 mNavigationBarHeightForRotation[mSeascapeRotation] = res.getDimensionPixelSize(
1673 com.android.internal.R.dimen.navigation_bar_height_landscape);
Daniel Sandler9f65c4c2012-04-26 01:35:35 -04001674
1675 // Width of the navigation bar when presented vertically along one side
1676 mNavigationBarWidthForRotation[mPortraitRotation] =
1677 mNavigationBarWidthForRotation[mUpsideDownRotation] =
1678 mNavigationBarWidthForRotation[mLandscapeRotation] =
1679 mNavigationBarWidthForRotation[mSeascapeRotation] =
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001680 res.getDimensionPixelSize(com.android.internal.R.dimen.navigation_bar_width);
Daniel Sandler4a066c52012-04-20 14:49:13 -04001681
1682 // SystemUI (status bar) layout policy
Dianne Hackborndde331c2012-08-03 14:01:57 -07001683 int shortSizeDp = shortSize * DisplayMetrics.DENSITY_DEFAULT / density;
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001684 int longSizeDp = longSize * DisplayMetrics.DENSITY_DEFAULT / density;
Daniel Sandler4a066c52012-04-20 14:49:13 -04001685
Devin Kimd7b12b42014-05-05 14:34:58 -07001686 // Allow the navigation bar to move on non-square small devices (phones).
1687 mNavigationBarCanMove = width != height && shortSizeDp < 600;
Daniel Sandler36412a72011-08-04 09:35:13 -04001688
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001689 mHasNavigationBar = res.getBoolean(com.android.internal.R.bool.config_showNavigationBar);
John Spurlock80f00c12013-06-13 11:10:51 -04001690 // Allow a system property to override this. Used by the emulator.
1691 // See also hasNavigationBar().
1692 String navBarOverride = SystemProperties.get("qemu.hw.mainkeys");
1693 if ("1".equals(navBarOverride)) {
Dianne Hackbornf87d1962012-04-04 12:48:24 -07001694 mHasNavigationBar = false;
John Spurlock80f00c12013-06-13 11:10:51 -04001695 } else if ("0".equals(navBarOverride)) {
1696 mHasNavigationBar = true;
Daniel Sandler0c4ccff2011-10-19 16:39:14 -04001697 }
1698
Jeff Brown27f1d672012-10-17 18:32:34 -07001699 // For demo purposes, allow the rotation of the HDMI display to be controlled.
1700 // By default, HDMI locks rotation to landscape.
Erik Gilling9a41ef82011-09-26 19:21:03 -07001701 if ("portrait".equals(SystemProperties.get("persist.demo.hdmirotation"))) {
Jeff Brownc82c89ed2013-04-17 17:18:15 -07001702 mDemoHdmiRotation = mPortraitRotation;
Erik Gilling9a41ef82011-09-26 19:21:03 -07001703 } else {
Jeff Brownc82c89ed2013-04-17 17:18:15 -07001704 mDemoHdmiRotation = mLandscapeRotation;
Erik Gilling9a41ef82011-09-26 19:21:03 -07001705 }
Jeff Brownc82c89ed2013-04-17 17:18:15 -07001706 mDemoHdmiRotationLock = SystemProperties.getBoolean("persist.demo.hdmirotationlock", false);
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001707
Chong Zhangae6119ff2014-11-11 18:54:39 -08001708 // For demo purposes, allow the rotation of the remote display to be controlled.
1709 // By default, remote display locks rotation to landscape.
1710 if ("portrait".equals(SystemProperties.get("persist.demo.remoterotation"))) {
1711 mDemoRotation = mPortraitRotation;
1712 } else {
1713 mDemoRotation = mLandscapeRotation;
1714 }
1715 mDemoRotationLock = SystemProperties.getBoolean(
1716 "persist.demo.rotationlock", false);
1717
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001718 // Only force the default orientation if the screen is xlarge, at least 960dp x 720dp, per
1719 // http://developer.android.com/guide/practices/screens_support.html#range
1720 mForceDefaultOrientation = longSizeDp >= 960 && shortSizeDp >= 720 &&
1721 res.getBoolean(com.android.internal.R.bool.config_forceDefaultOrientation) &&
1722 // For debug purposes the next line turns this feature off with:
1723 // $ adb shell setprop config.override_forced_orient true
1724 // $ adb shell wm size reset
1725 !"true".equals(SystemProperties.get("config.override_forced_orient"));
1726 }
1727
Alan Viverette5a0f4ec2013-10-07 15:10:29 -07001728 /**
1729 * @return whether the navigation bar can be hidden, e.g. the device has a
1730 * navigation bar and touch exploration is not enabled
1731 */
1732 private boolean canHideNavigationBar() {
Alan Viverette817f3cd2015-08-13 11:40:14 -04001733 return mHasNavigationBar;
Alan Viverette5a0f4ec2013-10-07 15:10:29 -07001734 }
1735
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001736 @Override
1737 public boolean isDefaultOrientationForced() {
1738 return mForceDefaultOrientation;
Dianne Hackborn9d132642011-04-21 17:26:39 -07001739 }
1740
Dianne Hackbornc652de82013-02-15 16:32:56 -08001741 @Override
1742 public void setDisplayOverscan(Display display, int left, int top, int right, int bottom) {
1743 if (display.getDisplayId() == Display.DEFAULT_DISPLAY) {
1744 mOverscanLeft = left;
1745 mOverscanTop = top;
1746 mOverscanRight = right;
1747 mOverscanBottom = bottom;
1748 }
1749 }
1750
Dianne Hackbornc777e072010-02-12 13:07:59 -08001751 public void updateSettings() {
1752 ContentResolver resolver = mContext.getContentResolver();
1753 boolean updateRotation = false;
Dianne Hackbornc777e072010-02-12 13:07:59 -08001754 synchronized (mLock) {
Christopher Tate5e08af02012-09-21 17:17:22 -07001755 mEndcallBehavior = Settings.System.getIntForUser(resolver,
David Brownbaf8d092010-03-08 21:52:59 -08001756 Settings.System.END_BUTTON_BEHAVIOR,
Christopher Tate5e08af02012-09-21 17:17:22 -07001757 Settings.System.END_BUTTON_BEHAVIOR_DEFAULT,
1758 UserHandle.USER_CURRENT);
1759 mIncallPowerBehavior = Settings.Secure.getIntForUser(resolver,
David Brownbaf8d092010-03-08 21:52:59 -08001760 Settings.Secure.INCALL_POWER_BUTTON_BEHAVIOR,
Christopher Tate5e08af02012-09-21 17:17:22 -07001761 Settings.Secure.INCALL_POWER_BUTTON_BEHAVIOR_DEFAULT,
1762 UserHandle.USER_CURRENT);
Daniel Sandlerb73617d2010-08-17 00:41:00 -04001763
Jeff Browna20dda42014-05-27 20:57:24 -07001764 // Configure wake gesture.
1765 boolean wakeGestureEnabledSetting = Settings.Secure.getIntForUser(resolver,
1766 Settings.Secure.WAKE_GESTURE_ENABLED, 0,
1767 UserHandle.USER_CURRENT) != 0;
1768 if (mWakeGestureEnabledSetting != wakeGestureEnabledSetting) {
1769 mWakeGestureEnabledSetting = wakeGestureEnabledSetting;
1770 updateWakeGestureListenerLp();
1771 }
1772
Jeff Brown207673cd2012-06-05 17:47:11 -07001773 // Configure rotation lock.
Christopher Tate5e08af02012-09-21 17:17:22 -07001774 int userRotation = Settings.System.getIntForUser(resolver,
1775 Settings.System.USER_ROTATION, Surface.ROTATION_0,
1776 UserHandle.USER_CURRENT);
Jeff Brown207673cd2012-06-05 17:47:11 -07001777 if (mUserRotation != userRotation) {
1778 mUserRotation = userRotation;
1779 updateRotation = true;
1780 }
Christopher Tate5e08af02012-09-21 17:17:22 -07001781 int userRotationMode = Settings.System.getIntForUser(resolver,
1782 Settings.System.ACCELEROMETER_ROTATION, 0, UserHandle.USER_CURRENT) != 0 ?
Jeff Brown207673cd2012-06-05 17:47:11 -07001783 WindowManagerPolicy.USER_ROTATION_FREE :
1784 WindowManagerPolicy.USER_ROTATION_LOCKED;
1785 if (mUserRotationMode != userRotationMode) {
1786 mUserRotationMode = userRotationMode;
1787 updateRotation = true;
Dianne Hackbornc777e072010-02-12 13:07:59 -08001788 updateOrientationListenerLp();
1789 }
Daniel Sandlerb73617d2010-08-17 00:41:00 -04001790
Dianne Hackbornc777e072010-02-12 13:07:59 -08001791 if (mSystemReady) {
Christopher Tate5e08af02012-09-21 17:17:22 -07001792 int pointerLocation = Settings.System.getIntForUser(resolver,
1793 Settings.System.POINTER_LOCATION, 0, UserHandle.USER_CURRENT);
Dianne Hackbornc777e072010-02-12 13:07:59 -08001794 if (mPointerLocationMode != pointerLocation) {
1795 mPointerLocationMode = pointerLocation;
Jeff Brown70825162012-03-28 17:27:48 -07001796 mHandler.sendEmptyMessage(pointerLocation != 0 ?
1797 MSG_ENABLE_POINTER_LOCATION : MSG_DISABLE_POINTER_LOCATION);
Dianne Hackbornc777e072010-02-12 13:07:59 -08001798 }
1799 }
1800 // use screen off timeout setting as the timeout for the lockscreen
Christopher Tate5e08af02012-09-21 17:17:22 -07001801 mLockScreenTimeout = Settings.System.getIntForUser(resolver,
1802 Settings.System.SCREEN_OFF_TIMEOUT, 0, UserHandle.USER_CURRENT);
1803 String imId = Settings.Secure.getStringForUser(resolver,
1804 Settings.Secure.DEFAULT_INPUT_METHOD, UserHandle.USER_CURRENT);
Dianne Hackbornc777e072010-02-12 13:07:59 -08001805 boolean hasSoftInput = imId != null && imId.length() > 0;
1806 if (mHasSoftInput != hasSoftInput) {
1807 mHasSoftInput = hasSoftInput;
1808 updateRotation = true;
1809 }
John Spurlockf1a36642013-10-12 17:50:42 -04001810 if (mImmersiveModeConfirmation != null) {
John Spurlock4355a532014-02-19 09:49:25 -05001811 mImmersiveModeConfirmation.loadSetting(mCurrentUserId);
John Spurlockd67ec252013-09-05 11:31:54 -04001812 }
tiger_huangcc6366d2015-06-29 17:17:30 +08001813 }
1814 synchronized (mWindowManagerFuncs.getWindowManagerLock()) {
John Spurlockc6d1c602014-01-17 15:22:06 -05001815 PolicyControl.reloadFromSetting(mContext);
Dianne Hackbornc777e072010-02-12 13:07:59 -08001816 }
1817 if (updateRotation) {
Jeff Brown01a98dd2011-09-20 15:08:29 -07001818 updateRotation(true);
Dianne Hackbornc777e072010-02-12 13:07:59 -08001819 }
Jeff Brown70825162012-03-28 17:27:48 -07001820 }
1821
Jeff Browna20dda42014-05-27 20:57:24 -07001822 private void updateWakeGestureListenerLp() {
1823 if (shouldEnableWakeGestureLp()) {
1824 mWakeGestureListener.requestWakeUpTrigger();
1825 } else {
1826 mWakeGestureListener.cancelWakeUpTrigger();
1827 }
1828 }
1829
1830 private boolean shouldEnableWakeGestureLp() {
Jeff Brown3ee549c2014-09-22 20:14:39 -07001831 return mWakeGestureEnabledSetting && !mAwake
Jeff Browna20dda42014-05-27 20:57:24 -07001832 && (!mLidControlsSleep || mLidState != LID_CLOSED)
1833 && mWakeGestureListener.isSupported();
1834 }
1835
Jeff Brown70825162012-03-28 17:27:48 -07001836 private void enablePointerLocation() {
1837 if (mPointerLocationView == null) {
1838 mPointerLocationView = new PointerLocationView(mContext);
1839 mPointerLocationView.setPrintCoords(false);
Dianne Hackbornc777e072010-02-12 13:07:59 -08001840 WindowManager.LayoutParams lp = new WindowManager.LayoutParams(
1841 WindowManager.LayoutParams.MATCH_PARENT,
1842 WindowManager.LayoutParams.MATCH_PARENT);
Jeff Brown3b2b3542010-10-15 00:54:27 -07001843 lp.type = WindowManager.LayoutParams.TYPE_SECURE_SYSTEM_OVERLAY;
Jeff Brownbfcb60a2011-09-08 18:51:14 -07001844 lp.flags = WindowManager.LayoutParams.FLAG_FULLSCREEN
1845 | WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE
1846 | WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE
1847 | WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN;
Jeff Brown90fc9052012-10-01 14:44:24 -07001848 if (ActivityManager.isHighEndGfx()) {
1849 lp.flags |= WindowManager.LayoutParams.FLAG_HARDWARE_ACCELERATED;
1850 lp.privateFlags |=
1851 WindowManager.LayoutParams.PRIVATE_FLAG_FORCE_HARDWARE_ACCELERATED;
1852 }
Dianne Hackbornc777e072010-02-12 13:07:59 -08001853 lp.format = PixelFormat.TRANSLUCENT;
1854 lp.setTitle("PointerLocation");
Dianne Hackborn5fd21692011-06-07 14:09:47 -07001855 WindowManager wm = (WindowManager)
Dianne Hackbornc777e072010-02-12 13:07:59 -08001856 mContext.getSystemService(Context.WINDOW_SERVICE);
Jeff Browncc4f7db2011-08-30 20:34:48 -07001857 lp.inputFeatures |= WindowManager.LayoutParams.INPUT_FEATURE_NO_INPUT_CHANNEL;
Jeff Brown70825162012-03-28 17:27:48 -07001858 wm.addView(mPointerLocationView, lp);
Michael Wrightc9c487e2013-11-07 18:55:09 -08001859 mWindowManagerFuncs.registerPointerEventListener(mPointerLocationView);
Dianne Hackbornc777e072010-02-12 13:07:59 -08001860 }
Dianne Hackbornc777e072010-02-12 13:07:59 -08001861 }
Jeff Brown70825162012-03-28 17:27:48 -07001862
1863 private void disablePointerLocation() {
Jeff Brown70825162012-03-28 17:27:48 -07001864 if (mPointerLocationView != null) {
Michael Wrightc9c487e2013-11-07 18:55:09 -08001865 mWindowManagerFuncs.unregisterPointerEventListener(mPointerLocationView);
1866 WindowManager wm = (WindowManager) mContext.getSystemService(Context.WINDOW_SERVICE);
Jeff Brown70825162012-03-28 17:27:48 -07001867 wm.removeView(mPointerLocationView);
1868 mPointerLocationView = null;
1869 }
1870 }
1871
Mike Lockwood2d1efbd2009-09-16 12:15:53 -04001872 private int readRotation(int resID) {
Mike Lockwood1753f7f2009-08-24 14:49:07 -07001873 try {
1874 int rotation = mContext.getResources().getInteger(resID);
1875 switch (rotation) {
1876 case 0:
1877 return Surface.ROTATION_0;
1878 case 90:
1879 return Surface.ROTATION_90;
1880 case 180:
1881 return Surface.ROTATION_180;
1882 case 270:
1883 return Surface.ROTATION_270;
Mike Lockwood1753f7f2009-08-24 14:49:07 -07001884 }
1885 } catch (Resources.NotFoundException e) {
Mike Lockwood2d1efbd2009-09-16 12:15:53 -04001886 // fall through
Mike Lockwood1753f7f2009-08-24 14:49:07 -07001887 }
Mike Lockwood2d1efbd2009-09-16 12:15:53 -04001888 return -1;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001889 }
1890
1891 /** {@inheritDoc} */
Craig Mautner88400d32012-09-30 12:35:45 -07001892 @Override
Dianne Hackbornc2293022013-02-06 23:14:49 -08001893 public int checkAddPermission(WindowManager.LayoutParams attrs, int[] outAppOp) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001894 int type = attrs.type;
Dianne Hackbornc2293022013-02-06 23:14:49 -08001895
1896 outAppOp[0] = AppOpsManager.OP_NONE;
1897
Wale Ogunwale74bf0652015-01-12 10:24:36 -08001898 if (!((type >= FIRST_APPLICATION_WINDOW && type <= LAST_APPLICATION_WINDOW)
1899 || (type >= FIRST_SUB_WINDOW && type <= LAST_SUB_WINDOW)
1900 || (type >= FIRST_SYSTEM_WINDOW && type <= LAST_SYSTEM_WINDOW))) {
1901 return WindowManagerGlobal.ADD_INVALID_TYPE;
1902 }
1903
1904 if (type < FIRST_SYSTEM_WINDOW || type > LAST_SYSTEM_WINDOW) {
1905 // Window manager will make sure these are okay.
Jeff Brown98365d72012-08-19 20:30:52 -07001906 return WindowManagerGlobal.ADD_OKAY;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001907 }
1908 String permission = null;
1909 switch (type) {
1910 case TYPE_TOAST:
1911 // XXX right now the app process has complete control over
1912 // this... should introduce a token to let the system
1913 // monitor/control what they are doing.
Jason Monk1c7c3192014-06-26 12:52:18 -04001914 outAppOp[0] = AppOpsManager.OP_TOAST_WINDOW;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001915 break;
Daniel Sandler7d276c32012-01-30 14:33:52 -05001916 case TYPE_DREAM:
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001917 case TYPE_INPUT_METHOD:
Dianne Hackbornb7cd8b92009-08-08 20:53:03 -07001918 case TYPE_WALLPAPER:
keunyounga446bf02013-06-21 19:07:57 -07001919 case TYPE_PRIVATE_PRESENTATION:
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001920 case TYPE_VOICE_INTERACTION:
Svetoslav3a5c7212014-10-14 09:54:26 -07001921 case TYPE_ACCESSIBILITY_OVERLAY:
Jason Monk8f7f3182015-11-18 16:35:14 -05001922 case TYPE_QS_DIALOG:
Dianne Hackbornb7cd8b92009-08-08 20:53:03 -07001923 // The window manager will check these.
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001924 break;
1925 case TYPE_PHONE:
1926 case TYPE_PRIORITY_PHONE:
1927 case TYPE_SYSTEM_ALERT:
1928 case TYPE_SYSTEM_ERROR:
1929 case TYPE_SYSTEM_OVERLAY:
1930 permission = android.Manifest.permission.SYSTEM_ALERT_WINDOW;
Dianne Hackbornc2293022013-02-06 23:14:49 -08001931 outAppOp[0] = AppOpsManager.OP_SYSTEM_ALERT_WINDOW;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001932 break;
1933 default:
1934 permission = android.Manifest.permission.INTERNAL_SYSTEM_WINDOW;
1935 }
1936 if (permission != null) {
Billy Laucbe540f2015-06-25 01:51:44 +01001937 if (permission == android.Manifest.permission.SYSTEM_ALERT_WINDOW) {
1938 final int callingUid = Binder.getCallingUid();
Billy Lau060275f2015-07-15 22:29:19 +01001939 // system processes will be automatically allowed privilege to draw
Billy Laucbe540f2015-06-25 01:51:44 +01001940 if (callingUid == Process.SYSTEM_UID) {
1941 return WindowManagerGlobal.ADD_OKAY;
1942 }
1943
Billy Lau060275f2015-07-15 22:29:19 +01001944 // check if user has enabled this operation. SecurityException will be thrown if
1945 // this app has not been allowed by the user
Billy Laucbe540f2015-06-25 01:51:44 +01001946 final int mode = mAppOpsManager.checkOp(outAppOp[0], callingUid,
1947 attrs.packageName);
Billy Lau060275f2015-07-15 22:29:19 +01001948 switch (mode) {
1949 case AppOpsManager.MODE_ALLOWED:
1950 case AppOpsManager.MODE_IGNORED:
1951 // although we return ADD_OKAY for MODE_IGNORED, the added window will
1952 // actually be hidden in WindowManagerService
1953 return WindowManagerGlobal.ADD_OKAY;
1954 case AppOpsManager.MODE_ERRORED:
Billy Laucbe540f2015-06-25 01:51:44 +01001955 return WindowManagerGlobal.ADD_PERMISSION_DENIED;
Billy Lau060275f2015-07-15 22:29:19 +01001956 default:
1957 // in the default mode, we will make a decision here based on
1958 // checkCallingPermission()
1959 if (mContext.checkCallingPermission(permission) !=
1960 PackageManager.PERMISSION_GRANTED) {
1961 return WindowManagerGlobal.ADD_PERMISSION_DENIED;
1962 } else {
1963 return WindowManagerGlobal.ADD_OKAY;
1964 }
Billy Laucbe540f2015-06-25 01:51:44 +01001965 }
Billy Laucbe540f2015-06-25 01:51:44 +01001966 }
1967
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001968 if (mContext.checkCallingOrSelfPermission(permission)
1969 != PackageManager.PERMISSION_GRANTED) {
Jeff Brown98365d72012-08-19 20:30:52 -07001970 return WindowManagerGlobal.ADD_PERMISSION_DENIED;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001971 }
1972 }
Jeff Brown98365d72012-08-19 20:30:52 -07001973 return WindowManagerGlobal.ADD_OKAY;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001974 }
Craig Mautner88400d32012-09-30 12:35:45 -07001975
1976 @Override
1977 public boolean checkShowToOwnerOnly(WindowManager.LayoutParams attrs) {
1978
1979 // If this switch statement is modified, modify the comment in the declarations of
1980 // the type in {@link WindowManager.LayoutParams} as well.
1981 switch (attrs.type) {
1982 default:
1983 // These are the windows that by default are shown only to the user that created
1984 // them. If this needs to be overridden, set
1985 // {@link WindowManager.LayoutParams.PRIVATE_FLAG_SHOW_FOR_ALL_USERS} in
1986 // {@link WindowManager.LayoutParams}. Note that permission
1987 // {@link android.Manifest.permission.INTERNAL_SYSTEM_WINDOW} is required as well.
1988 if ((attrs.privateFlags & PRIVATE_FLAG_SHOW_FOR_ALL_USERS) == 0) {
1989 return true;
1990 }
1991 break;
1992
1993 // These are the windows that by default are shown to all users. However, to
1994 // protect against spoofing, check permissions below.
1995 case TYPE_APPLICATION_STARTING:
1996 case TYPE_BOOT_PROGRESS:
1997 case TYPE_DISPLAY_OVERLAY:
Selim Cinekf83e8242015-05-19 18:08:14 -07001998 case TYPE_INPUT_CONSUMER:
Jim Miller5ecd8112013-01-09 18:50:26 -08001999 case TYPE_KEYGUARD_SCRIM:
Craig Mautner88400d32012-09-30 12:35:45 -07002000 case TYPE_KEYGUARD_DIALOG:
2001 case TYPE_MAGNIFICATION_OVERLAY:
2002 case TYPE_NAVIGATION_BAR:
2003 case TYPE_NAVIGATION_BAR_PANEL:
2004 case TYPE_PHONE:
2005 case TYPE_POINTER:
2006 case TYPE_PRIORITY_PHONE:
Craig Mautner88400d32012-09-30 12:35:45 -07002007 case TYPE_SEARCH_BAR:
2008 case TYPE_STATUS_BAR:
2009 case TYPE_STATUS_BAR_PANEL:
2010 case TYPE_STATUS_BAR_SUB_PANEL:
2011 case TYPE_SYSTEM_DIALOG:
Craig Mautner88400d32012-09-30 12:35:45 -07002012 case TYPE_VOLUME_OVERLAY:
keunyounga446bf02013-06-21 19:07:57 -07002013 case TYPE_PRIVATE_PRESENTATION:
Filip Gruszczynski466f3212015-09-21 17:57:57 -07002014 case TYPE_DOCK_DIVIDER:
Craig Mautner88400d32012-09-30 12:35:45 -07002015 break;
2016 }
2017
2018 // Check if third party app has set window to system window type.
2019 return mContext.checkCallingOrSelfPermission(
2020 android.Manifest.permission.INTERNAL_SYSTEM_WINDOW)
2021 != PackageManager.PERMISSION_GRANTED;
2022 }
2023
Craig Mautner967212c2013-04-13 21:10:58 -07002024 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002025 public void adjustWindowParamsLw(WindowManager.LayoutParams attrs) {
2026 switch (attrs.type) {
2027 case TYPE_SYSTEM_OVERLAY:
Jeff Brown3b2b3542010-10-15 00:54:27 -07002028 case TYPE_SECURE_SYSTEM_OVERLAY:
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002029 // These types of windows can't receive input events.
2030 attrs.flags |= WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE
2031 | WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE;
Jeff Brownbfcb60a2011-09-08 18:51:14 -07002032 attrs.flags &= ~WindowManager.LayoutParams.FLAG_WATCH_OUTSIDE_TOUCH;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002033 break;
Jorim Jaggi380ecb82014-03-14 17:25:20 +01002034 case TYPE_STATUS_BAR:
2035
2036 // If the Keyguard is in a hidden state (occluded by another window), we force to
2037 // remove the wallpaper and keyguard flag so that any change in-flight after setting
2038 // the keyguard as occluded wouldn't set these flags again.
2039 // See {@link #processKeyguardSetHiddenResultLw}.
2040 if (mKeyguardHidden) {
2041 attrs.flags &= ~WindowManager.LayoutParams.FLAG_SHOW_WALLPAPER;
2042 attrs.privateFlags &= ~WindowManager.LayoutParams.PRIVATE_FLAG_KEYGUARD;
2043 }
2044 break;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002045 }
Adrian Roos38502112014-04-09 21:04:11 +02002046
2047 if (attrs.type != TYPE_STATUS_BAR) {
2048 // The status bar is the only window allowed to exhibit keyguard behavior.
2049 attrs.privateFlags &= ~WindowManager.LayoutParams.PRIVATE_FLAG_KEYGUARD;
2050 }
Adrian Roosea562512014-05-05 13:33:03 +02002051
2052 if (ActivityManager.isHighEndGfx()
2053 && (attrs.flags & FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS) != 0) {
Adrian Roosf5e9b5c2014-09-10 15:27:41 +02002054 attrs.subtreeSystemUiVisibility |= View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
Adrian Roosea562512014-05-05 13:33:03 +02002055 | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION;
2056 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002057 }
RoboErik8a2cfc32014-05-16 11:19:38 -07002058
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002059 void readLidState() {
Jeff Brown2e7760e2012-04-11 15:14:55 -07002060 mLidState = mWindowManagerFuncs.getLidState();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002061 }
RoboErik8a2cfc32014-05-16 11:19:38 -07002062
Michael Wright3818c922014-09-02 13:59:07 -07002063 private void readCameraLensCoverState() {
2064 mCameraLensCoverState = mWindowManagerFuncs.getCameraLensCoverState();
2065 }
2066
Jeff Browndaa37532012-05-01 15:54:03 -07002067 private boolean isHidden(int accessibilityMode) {
2068 switch (accessibilityMode) {
2069 case 1:
2070 return mLidState == LID_CLOSED;
2071 case 2:
2072 return mLidState == LID_OPEN;
2073 default:
2074 return false;
Dianne Hackborn2862fff2009-09-15 22:56:29 -07002075 }
Dianne Hackborn2862fff2009-09-15 22:56:29 -07002076 }
Jeff Brownd04a88c2011-01-16 14:05:47 -08002077
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002078 /** {@inheritDoc} */
Craig Mautner967212c2013-04-13 21:10:58 -07002079 @Override
Jeff Browndaa37532012-05-01 15:54:03 -07002080 public void adjustConfigurationLw(Configuration config, int keyboardPresence,
2081 int navigationPresence) {
2082 mHaveBuiltInKeyboard = (keyboardPresence & PRESENCE_INTERNAL) != 0;
2083
Jeff Brownf71343d2013-05-31 17:59:11 -07002084 readConfigurationDependentBehaviors();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002085 readLidState();
Jeff Brownc458ce92012-04-30 14:58:40 -07002086 applyLidSwitchState();
Jeff Brownd04a88c2011-01-16 14:05:47 -08002087
Jeff Browndaa37532012-05-01 15:54:03 -07002088 if (config.keyboard == Configuration.KEYBOARD_NOKEYS
2089 || (keyboardPresence == PRESENCE_INTERNAL
2090 && isHidden(mLidKeyboardAccessibility))) {
Jeff Brownd04a88c2011-01-16 14:05:47 -08002091 config.hardKeyboardHidden = Configuration.HARDKEYBOARDHIDDEN_YES;
Jeff Browndaa37532012-05-01 15:54:03 -07002092 if (!mHasSoftInput) {
2093 config.keyboardHidden = Configuration.KEYBOARDHIDDEN_YES;
2094 }
Jeff Brownd04a88c2011-01-16 14:05:47 -08002095 }
2096
Jeff Browndaa37532012-05-01 15:54:03 -07002097 if (config.navigation == Configuration.NAVIGATION_NONAV
2098 || (navigationPresence == PRESENCE_INTERNAL
2099 && isHidden(mLidNavigationAccessibility))) {
Jeff Brownd04a88c2011-01-16 14:05:47 -08002100 config.navigationHidden = Configuration.NAVIGATIONHIDDEN_YES;
Jeff Brownd04a88c2011-01-16 14:05:47 -08002101 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002102 }
Jeff Brownd04a88c2011-01-16 14:05:47 -08002103
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002104 /** {@inheritDoc} */
Craig Mautner967212c2013-04-13 21:10:58 -07002105 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002106 public int windowTypeToLayerLw(int type) {
2107 if (type >= FIRST_APPLICATION_WINDOW && type <= LAST_APPLICATION_WINDOW) {
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07002108 return 2;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002109 }
2110 switch (type) {
keunyounga446bf02013-06-21 19:07:57 -07002111 case TYPE_PRIVATE_PRESENTATION:
2112 return 2;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07002113 case TYPE_WALLPAPER:
2114 // wallpaper is at the bottom, though the window manager may move it.
2115 return 2;
Filip Gruszczynskie95b0ae2015-09-30 10:55:33 -07002116 case TYPE_DOCK_DIVIDER:
2117 return 2;
Jason Monk8f7f3182015-11-18 16:35:14 -05002118 case TYPE_QS_DIALOG:
2119 return 2;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07002120 case TYPE_PHONE:
2121 return 3;
2122 case TYPE_SEARCH_BAR:
Jorim Jaggi225d3b52015-04-01 11:18:57 -07002123 case TYPE_VOICE_INTERACTION_STARTING:
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07002124 return 4;
Dianne Hackborne30e02f2014-05-27 18:24:45 -07002125 case TYPE_VOICE_INTERACTION:
2126 // voice interaction layer is almost immediately above apps.
2127 return 5;
Selim Cinekf83e8242015-05-19 18:08:14 -07002128 case TYPE_INPUT_CONSUMER:
Dianne Hackborne30e02f2014-05-27 18:24:45 -07002129 return 6;
Selim Cinekf83e8242015-05-19 18:08:14 -07002130 case TYPE_SYSTEM_DIALOG:
2131 return 7;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07002132 case TYPE_TOAST:
2133 // toasts and the plugged-in battery thing
Selim Cinekf83e8242015-05-19 18:08:14 -07002134 return 8;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07002135 case TYPE_PRIORITY_PHONE:
2136 // SIM errors and unlock. Not sure if this really should be in a high layer.
Selim Cinekf83e8242015-05-19 18:08:14 -07002137 return 9;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07002138 case TYPE_DREAM:
2139 // used for Dreams (screensavers with TYPE_DREAM windows)
Selim Cinekf83e8242015-05-19 18:08:14 -07002140 return 10;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07002141 case TYPE_SYSTEM_ALERT:
2142 // like the ANR / app crashed dialogs
Selim Cinekf83e8242015-05-19 18:08:14 -07002143 return 11;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07002144 case TYPE_INPUT_METHOD:
2145 // on-screen keyboards and other such input method user interfaces go here.
Selim Cinekf83e8242015-05-19 18:08:14 -07002146 return 12;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07002147 case TYPE_INPUT_METHOD_DIALOG:
2148 // on-screen keyboards and other such input method user interfaces go here.
Selim Cinekf83e8242015-05-19 18:08:14 -07002149 return 13;
Jim Miller5ecd8112013-01-09 18:50:26 -08002150 case TYPE_KEYGUARD_SCRIM:
2151 // the safety window that shows behind keyguard while keyguard is starting
Filip Gruszczynskie95b0ae2015-09-30 10:55:33 -07002152 return 14;
Filip Gruszczynski466f3212015-09-21 17:57:57 -07002153 case TYPE_STATUS_BAR_SUB_PANEL:
Filip Gruszczynskie95b0ae2015-09-30 10:55:33 -07002154 return 15;
Filip Gruszczynski466f3212015-09-21 17:57:57 -07002155 case TYPE_STATUS_BAR:
Filip Gruszczynskie95b0ae2015-09-30 10:55:33 -07002156 return 16;
Filip Gruszczynski466f3212015-09-21 17:57:57 -07002157 case TYPE_STATUS_BAR_PANEL:
Filip Gruszczynskie95b0ae2015-09-30 10:55:33 -07002158 return 17;
Filip Gruszczynski466f3212015-09-21 17:57:57 -07002159 case TYPE_KEYGUARD_DIALOG:
Filip Gruszczynskie95b0ae2015-09-30 10:55:33 -07002160 return 18;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07002161 case TYPE_VOLUME_OVERLAY:
2162 // the on-screen volume indicator and controller shown when the user
2163 // changes the device volume
Filip Gruszczynskie95b0ae2015-09-30 10:55:33 -07002164 return 19;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07002165 case TYPE_SYSTEM_OVERLAY:
2166 // the on-screen volume indicator and controller shown when the user
2167 // changes the device volume
Filip Gruszczynskie95b0ae2015-09-30 10:55:33 -07002168 return 20;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07002169 case TYPE_NAVIGATION_BAR:
2170 // the navigation bar, if available, shows atop most things
Filip Gruszczynskie95b0ae2015-09-30 10:55:33 -07002171 return 21;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07002172 case TYPE_NAVIGATION_BAR_PANEL:
2173 // some panels (e.g. search) need to show on top of the navigation bar
Filip Gruszczynskie95b0ae2015-09-30 10:55:33 -07002174 return 22;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07002175 case TYPE_SYSTEM_ERROR:
2176 // system-level error dialogs
Filip Gruszczynskie95b0ae2015-09-30 10:55:33 -07002177 return 23;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07002178 case TYPE_MAGNIFICATION_OVERLAY:
2179 // used to highlight the magnified portion of a display
Filip Gruszczynskie95b0ae2015-09-30 10:55:33 -07002180 return 24;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07002181 case TYPE_DISPLAY_OVERLAY:
2182 // used to simulate secondary display devices
Filip Gruszczynskie95b0ae2015-09-30 10:55:33 -07002183 return 25;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07002184 case TYPE_DRAG:
2185 // the drag layer: input for drag-and-drop is associated with this window,
2186 // which sits above all other focusable windows
Filip Gruszczynskie95b0ae2015-09-30 10:55:33 -07002187 return 26;
Svetoslav3a5c7212014-10-14 09:54:26 -07002188 case TYPE_ACCESSIBILITY_OVERLAY:
2189 // overlay put by accessibility services to intercept user interaction
Filip Gruszczynskie95b0ae2015-09-30 10:55:33 -07002190 return 27;
Filip Gruszczynski466f3212015-09-21 17:57:57 -07002191 case TYPE_SECURE_SYSTEM_OVERLAY:
Filip Gruszczynskie95b0ae2015-09-30 10:55:33 -07002192 return 28;
Filip Gruszczynski466f3212015-09-21 17:57:57 -07002193 case TYPE_BOOT_PROGRESS:
Filip Gruszczynskie95b0ae2015-09-30 10:55:33 -07002194 return 29;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07002195 case TYPE_POINTER:
2196 // the (mouse) pointer layer
Filip Gruszczynskie95b0ae2015-09-30 10:55:33 -07002197 return 30;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002198 }
2199 Log.e(TAG, "Unknown window type: " + type);
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07002200 return 2;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002201 }
2202
2203 /** {@inheritDoc} */
Craig Mautner46ac6fa2013-08-01 10:06:34 -07002204 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002205 public int subWindowTypeToLayerLw(int type) {
2206 switch (type) {
2207 case TYPE_APPLICATION_PANEL:
2208 case TYPE_APPLICATION_ATTACHED_DIALOG:
2209 return APPLICATION_PANEL_SUBLAYER;
2210 case TYPE_APPLICATION_MEDIA:
2211 return APPLICATION_MEDIA_SUBLAYER;
Dianne Hackborn5cb8d792009-05-21 17:34:15 -07002212 case TYPE_APPLICATION_MEDIA_OVERLAY:
2213 return APPLICATION_MEDIA_OVERLAY_SUBLAYER;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002214 case TYPE_APPLICATION_SUB_PANEL:
2215 return APPLICATION_SUB_PANEL_SUBLAYER;
Wale Ogunwale0a4dc222015-04-14 12:58:42 -07002216 case TYPE_APPLICATION_ABOVE_SUB_PANEL:
2217 return APPLICATION_ABOVE_SUB_PANEL_SUBLAYER;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002218 }
2219 Log.e(TAG, "Unknown sub-window type: " + type);
2220 return 0;
2221 }
2222
Craig Mautner46ac6fa2013-08-01 10:06:34 -07002223 @Override
Dianne Hackbornabe0da02009-09-18 01:55:39 -07002224 public int getMaxWallpaperLayer() {
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07002225 return windowTypeToLayerLw(TYPE_STATUS_BAR);
Dianne Hackbornabe0da02009-09-18 01:55:39 -07002226 }
2227
Craig Mautner46ac6fa2013-08-01 10:06:34 -07002228 @Override
Dianne Hackborn1f903c32011-09-13 19:18:06 -07002229 public int getNonDecorDisplayWidth(int fullWidth, int fullHeight, int rotation) {
Dianne Hackborn077ee852012-04-09 16:27:07 -07002230 if (mHasNavigationBar) {
2231 // For a basic navigation bar, when we are in landscape mode we place
2232 // the navigation bar to the side.
Daniel Sandler4a066c52012-04-20 14:49:13 -04002233 if (mNavigationBarCanMove && fullWidth > fullHeight) {
2234 return fullWidth - mNavigationBarWidthForRotation[rotation];
Dianne Hackborn077ee852012-04-09 16:27:07 -07002235 }
Dianne Hackborn1f903c32011-09-13 19:18:06 -07002236 }
2237 return fullWidth;
Dianne Hackborne2515ee2011-04-27 18:52:56 -04002238 }
2239
Jose Lima9546b202014-07-02 17:21:51 -07002240 @Override
Dianne Hackborn1f903c32011-09-13 19:18:06 -07002241 public int getNonDecorDisplayHeight(int fullWidth, int fullHeight, int rotation) {
Dianne Hackborn077ee852012-04-09 16:27:07 -07002242 if (mHasNavigationBar) {
2243 // For a basic navigation bar, when we are in portrait mode we place
2244 // the navigation bar to the bottom.
Daniel Sandler4a066c52012-04-20 14:49:13 -04002245 if (!mNavigationBarCanMove || fullWidth < fullHeight) {
2246 return fullHeight - mNavigationBarHeightForRotation[rotation];
Dianne Hackborn077ee852012-04-09 16:27:07 -07002247 }
2248 }
2249 return fullHeight;
Dianne Hackborn69cb8752011-05-19 18:13:32 -07002250 }
2251
Jose Lima9546b202014-07-02 17:21:51 -07002252 @Override
Dianne Hackborn1f903c32011-09-13 19:18:06 -07002253 public int getConfigDisplayWidth(int fullWidth, int fullHeight, int rotation) {
2254 return getNonDecorDisplayWidth(fullWidth, fullHeight, rotation);
Dianne Hackborn69cb8752011-05-19 18:13:32 -07002255 }
2256
Jose Lima9546b202014-07-02 17:21:51 -07002257 @Override
Dianne Hackborn1f903c32011-09-13 19:18:06 -07002258 public int getConfigDisplayHeight(int fullWidth, int fullHeight, int rotation) {
John Spurlock80f00c12013-06-13 11:10:51 -04002259 // There is a separate status bar at the top of the display. We don't count that as part
2260 // of the fixed decor, since it can hide; however, for purposes of configurations,
Dianne Hackborn077ee852012-04-09 16:27:07 -07002261 // we do want to exclude it since applications can't generally use that part
2262 // of the screen.
John Spurlock80f00c12013-06-13 11:10:51 -04002263 return getNonDecorDisplayHeight(fullWidth, fullHeight, rotation) - mStatusBarHeight;
Dianne Hackborne2515ee2011-04-27 18:52:56 -04002264 }
2265
Craig Mautnera3f4bf52012-10-10 20:37:48 -07002266 @Override
Craig Mautnerc9457fa2014-06-06 14:27:48 -07002267 public boolean isForceHiding(WindowManager.LayoutParams attrs) {
2268 return (attrs.privateFlags & PRIVATE_FLAG_KEYGUARD) != 0 ||
Jim Millerab954542014-10-10 18:21:49 -07002269 (isKeyguardHostWindow(attrs) &&
2270 (mKeyguardDelegate != null && mKeyguardDelegate.isShowing())) ||
Adrian Roos69e510d2014-07-13 14:57:59 +02002271 (attrs.type == TYPE_KEYGUARD_SCRIM);
Dianne Hackborn01ad2f42009-09-24 19:24:56 -07002272 }
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07002273
Craig Mautnera3f4bf52012-10-10 20:37:48 -07002274 @Override
Jorim Jaggi0d674622014-05-21 01:34:15 +02002275 public boolean isKeyguardHostWindow(WindowManager.LayoutParams attrs) {
2276 return attrs.type == TYPE_STATUS_BAR;
2277 }
2278
2279 @Override
Dianne Hackborn01ad2f42009-09-24 19:24:56 -07002280 public boolean canBeForceHidden(WindowState win, WindowManager.LayoutParams attrs) {
Craig Mautnera3f4bf52012-10-10 20:37:48 -07002281 switch (attrs.type) {
2282 case TYPE_STATUS_BAR:
2283 case TYPE_NAVIGATION_BAR:
2284 case TYPE_WALLPAPER:
2285 case TYPE_DREAM:
Jim Miller5ecd8112013-01-09 18:50:26 -08002286 case TYPE_KEYGUARD_SCRIM:
Filip Gruszczynski466f3212015-09-21 17:57:57 -07002287 case TYPE_DOCK_DIVIDER:
Craig Mautnera3f4bf52012-10-10 20:37:48 -07002288 return false;
2289 default:
Adrian Roos461829d2015-06-03 14:41:18 -07002290 // Hide only windows below the keyguard host window.
2291 return windowTypeToLayerLw(win.getBaseType())
2292 < windowTypeToLayerLw(TYPE_STATUS_BAR);
Craig Mautnera3f4bf52012-10-10 20:37:48 -07002293 }
Dianne Hackborn01ad2f42009-09-24 19:24:56 -07002294 }
Craig Mautner8e4df6c2012-05-23 16:57:23 -07002295
Craig Mautner7d7808f2014-09-11 18:02:38 -07002296 @Override
2297 public WindowState getWinShowWhenLockedLw() {
2298 return mWinShowWhenLocked;
2299 }
2300
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002301 /** {@inheritDoc} */
Craig Mautner8e4df6c2012-05-23 16:57:23 -07002302 @Override
Dianne Hackborn2f0b1752011-05-31 17:59:49 -07002303 public View addStartingWindow(IBinder appToken, String packageName, int theme,
2304 CompatibilityInfo compatInfo, CharSequence nonLocalizedLabel, int labelRes,
Adam Powell04fe6eb2013-05-31 14:39:48 -07002305 int icon, int logo, int windowFlags) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002306 if (!SHOW_STARTING_ANIMATIONS) {
2307 return null;
2308 }
2309 if (packageName == null) {
2310 return null;
2311 }
Craig Mautner8e4df6c2012-05-23 16:57:23 -07002312
Mathias Jeppssond1443e92012-08-24 15:25:32 +02002313 WindowManager wm = null;
2314 View view = null;
2315
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002316 try {
Dianne Hackborn867ab6472010-04-29 13:28:56 -07002317 Context context = mContext;
Craig Mautner6fbda632012-07-03 09:26:39 -07002318 if (DEBUG_STARTING_WINDOW) Slog.d(TAG, "addStartingWindow " + packageName
2319 + ": nonLocalizedLabel=" + nonLocalizedLabel + " theme="
2320 + Integer.toHexString(theme));
Dianne Hackborn247fe742011-01-08 17:25:57 -08002321 if (theme != context.getThemeResId() || labelRes != 0) {
Dianne Hackborn867ab6472010-04-29 13:28:56 -07002322 try {
2323 context = context.createPackageContext(packageName, 0);
Dianne Hackborn247fe742011-01-08 17:25:57 -08002324 context.setTheme(theme);
Dianne Hackborn867ab6472010-04-29 13:28:56 -07002325 } catch (PackageManager.NameNotFoundException e) {
2326 // Ignore
2327 }
2328 }
Craig Mautner8e4df6c2012-05-23 16:57:23 -07002329
Jorim Jaggia16cc152015-06-01 16:55:05 -07002330 PhoneWindow win = new PhoneWindow(context);
2331 win.setIsStartingWindow(true);
Craig Mautner8e4df6c2012-05-23 16:57:23 -07002332
Dianne Hackborn867ab6472010-04-29 13:28:56 -07002333 Resources r = context.getResources();
2334 win.setTitle(r.getText(labelRes, nonLocalizedLabel));
Craig Mautner8e4df6c2012-05-23 16:57:23 -07002335
Dianne Hackborn867ab6472010-04-29 13:28:56 -07002336 win.setType(
2337 WindowManager.LayoutParams.TYPE_APPLICATION_STARTING);
Adrian Roos602c68e2015-04-24 16:03:47 -07002338
2339 synchronized (mWindowManagerFuncs.getWindowManagerLock()) {
2340 // Assumes it's safe to show starting windows of launched apps while
2341 // the keyguard is being hidden. This is okay because starting windows never show
2342 // secret information.
2343 if (mKeyguardHidden) {
2344 windowFlags |= FLAG_SHOW_WHEN_LOCKED;
2345 }
2346 }
2347
Dianne Hackborn867ab6472010-04-29 13:28:56 -07002348 // Force the window flags: this is a fake window, so it is not really
2349 // touchable or focusable by the user. We also add in the ALT_FOCUSABLE_IM
2350 // flag because we do know that the next window will take input
2351 // focus, so we want to get the IME window up on top of us right away.
2352 win.setFlags(
Dianne Hackborn7eec10e2010-11-12 18:03:47 -08002353 windowFlags|
Dianne Hackborn867ab6472010-04-29 13:28:56 -07002354 WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE|
2355 WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE|
2356 WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM,
Dianne Hackborn7eec10e2010-11-12 18:03:47 -08002357 windowFlags|
Dianne Hackborn867ab6472010-04-29 13:28:56 -07002358 WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE|
2359 WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE|
2360 WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM);
Craig Mautner8e4df6c2012-05-23 16:57:23 -07002361
Adam Powell04fe6eb2013-05-31 14:39:48 -07002362 win.setDefaultIcon(icon);
2363 win.setDefaultLogo(logo);
2364
Dianne Hackborn867ab6472010-04-29 13:28:56 -07002365 win.setLayout(WindowManager.LayoutParams.MATCH_PARENT,
Dianne Hackborn2f0b1752011-05-31 17:59:49 -07002366 WindowManager.LayoutParams.MATCH_PARENT);
Craig Mautner8e4df6c2012-05-23 16:57:23 -07002367
Dianne Hackborn867ab6472010-04-29 13:28:56 -07002368 final WindowManager.LayoutParams params = win.getAttributes();
2369 params.token = appToken;
2370 params.packageName = packageName;
2371 params.windowAnimations = win.getWindowStyle().getResourceId(
2372 com.android.internal.R.styleable.Window_windowAnimationStyle, 0);
John Reck61375a82014-09-18 19:27:48 +00002373 params.privateFlags |=
2374 WindowManager.LayoutParams.PRIVATE_FLAG_FAKE_HARDWARE_ACCELERATED;
Craig Mautner88400d32012-09-30 12:35:45 -07002375 params.privateFlags |= WindowManager.LayoutParams.PRIVATE_FLAG_SHOW_FOR_ALL_USERS;
Adam Lesinski95c42972013-10-02 10:13:27 -07002376
2377 if (!compatInfo.supportsScreen()) {
2378 params.privateFlags |= WindowManager.LayoutParams.PRIVATE_FLAG_COMPATIBLE_WINDOW;
2379 }
2380
Dianne Hackborn867ab6472010-04-29 13:28:56 -07002381 params.setTitle("Starting " + packageName);
2382
Mathias Jeppssond1443e92012-08-24 15:25:32 +02002383 wm = (WindowManager)context.getSystemService(Context.WINDOW_SERVICE);
2384 view = win.getDecorView();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002385
Craig Mautner6fbda632012-07-03 09:26:39 -07002386 if (DEBUG_STARTING_WINDOW) Slog.d(
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002387 TAG, "Adding starting window for " + packageName
2388 + " / " + appToken + ": "
2389 + (view.getParent() != null ? view : null));
2390
2391 wm.addView(view, params);
2392
2393 // Only return the view if it was successfully added to the
2394 // window manager... which we can tell by it having a parent.
2395 return view.getParent() != null ? view : null;
Jeff Brown98365d72012-08-19 20:30:52 -07002396 } catch (WindowManager.BadTokenException e) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002397 // ignore
Craig Mautner42bf39e2014-02-21 16:46:22 -08002398 Log.w(TAG, appToken + " already running, starting window not displayed. " +
2399 e.getMessage());
Dianne Hackborn867ab6472010-04-29 13:28:56 -07002400 } catch (RuntimeException e) {
2401 // don't crash if something else bad happens, for example a
2402 // failure loading resources because we are loading from an app
2403 // on external storage that has been unmounted.
2404 Log.w(TAG, appToken + " failed creating starting window", e);
Mathias Jeppssond1443e92012-08-24 15:25:32 +02002405 } finally {
2406 if (view != null && view.getParent() == null) {
2407 Log.w(TAG, "view not successfully added to wm, removing view");
2408 wm.removeViewImmediate(view);
2409 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002410 }
2411
2412 return null;
2413 }
2414
2415 /** {@inheritDoc} */
Jose Lima9546b202014-07-02 17:21:51 -07002416 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002417 public void removeStartingWindow(IBinder appToken, View window) {
Craig Mautner276a6eb2014-11-04 15:32:57 -08002418 if (DEBUG_STARTING_WINDOW) Slog.v(TAG, "Removing starting window for " + appToken + ": "
2419 + window + " Callers=" + Debug.getCallers(4));
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002420
2421 if (window != null) {
Dianne Hackborn5fd21692011-06-07 14:09:47 -07002422 WindowManager wm = (WindowManager)mContext.getSystemService(Context.WINDOW_SERVICE);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002423 wm.removeView(window);
2424 }
2425 }
2426
2427 /**
2428 * Preflight adding a window to the system.
RoboErik8a2cfc32014-05-16 11:19:38 -07002429 *
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002430 * Currently enforces that three window types are singletons:
2431 * <ul>
2432 * <li>STATUS_BAR_TYPE</li>
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002433 * <li>KEYGUARD_TYPE</li>
2434 * </ul>
RoboErik8a2cfc32014-05-16 11:19:38 -07002435 *
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002436 * @param win The window to be added
2437 * @param attrs Information about the window to be added
RoboErik8a2cfc32014-05-16 11:19:38 -07002438 *
Jeff Brown98365d72012-08-19 20:30:52 -07002439 * @return If ok, WindowManagerImpl.ADD_OKAY. If too many singletons,
2440 * WindowManagerImpl.ADD_MULTIPLE_SINGLETON
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002441 */
Jose Lima9546b202014-07-02 17:21:51 -07002442 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002443 public int prepareAddWindowLw(WindowState win, WindowManager.LayoutParams attrs) {
2444 switch (attrs.type) {
2445 case TYPE_STATUS_BAR:
Joe Onorato8bc6c512010-06-04 16:21:12 -04002446 mContext.enforceCallingOrSelfPermission(
2447 android.Manifest.permission.STATUS_BAR_SERVICE,
2448 "PhoneWindowManager");
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002449 if (mStatusBar != null) {
Dianne Hackbornf87d1962012-04-04 12:48:24 -07002450 if (mStatusBar.isAlive()) {
Jeff Brown98365d72012-08-19 20:30:52 -07002451 return WindowManagerGlobal.ADD_MULTIPLE_SINGLETON;
Dianne Hackbornf87d1962012-04-04 12:48:24 -07002452 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002453 }
2454 mStatusBar = win;
John Spurlock27735a42013-08-14 17:57:38 -04002455 mStatusBarController.setWindow(win);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002456 break;
Daniel Sandler8956dbb2011-04-22 07:55:02 -04002457 case TYPE_NAVIGATION_BAR:
2458 mContext.enforceCallingOrSelfPermission(
2459 android.Manifest.permission.STATUS_BAR_SERVICE,
2460 "PhoneWindowManager");
Dianne Hackbornf87d1962012-04-04 12:48:24 -07002461 if (mNavigationBar != null) {
2462 if (mNavigationBar.isAlive()) {
Jeff Brown98365d72012-08-19 20:30:52 -07002463 return WindowManagerGlobal.ADD_MULTIPLE_SINGLETON;
Dianne Hackbornf87d1962012-04-04 12:48:24 -07002464 }
2465 }
Daniel Sandler8956dbb2011-04-22 07:55:02 -04002466 mNavigationBar = win;
John Spurlock27735a42013-08-14 17:57:38 -04002467 mNavigationBarController.setWindow(win);
Craig Mautnereda67292013-04-28 13:50:14 -07002468 if (DEBUG_LAYOUT) Slog.i(TAG, "NAVIGATION BAR: " + mNavigationBar);
Daniel Sandler8956dbb2011-04-22 07:55:02 -04002469 break;
Jim Millere898ac52012-04-06 17:10:57 -07002470 case TYPE_NAVIGATION_BAR_PANEL:
Dianne Hackborn08743722009-12-21 12:16:51 -08002471 case TYPE_STATUS_BAR_PANEL:
Joe Onorato29fc2c92010-11-24 10:26:50 -08002472 case TYPE_STATUS_BAR_SUB_PANEL:
Jorim Jaggi225d3b52015-04-01 11:18:57 -07002473 case TYPE_VOICE_INTERACTION_STARTING:
Joe Onorato29fc2c92010-11-24 10:26:50 -08002474 mContext.enforceCallingOrSelfPermission(
2475 android.Manifest.permission.STATUS_BAR_SERVICE,
2476 "PhoneWindowManager");
Joe Onorato29fc2c92010-11-24 10:26:50 -08002477 break;
Jim Miller5ecd8112013-01-09 18:50:26 -08002478 case TYPE_KEYGUARD_SCRIM:
Jim Miller25190572013-02-28 17:36:24 -08002479 if (mKeyguardScrim != null) {
2480 return WindowManagerGlobal.ADD_MULTIPLE_SINGLETON;
2481 }
Jim Miller5ecd8112013-01-09 18:50:26 -08002482 mKeyguardScrim = win;
2483 break;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002484 }
Jeff Brown98365d72012-08-19 20:30:52 -07002485 return WindowManagerGlobal.ADD_OKAY;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002486 }
2487
2488 /** {@inheritDoc} */
Jose Lima9546b202014-07-02 17:21:51 -07002489 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002490 public void removeWindowLw(WindowState win) {
2491 if (mStatusBar == win) {
2492 mStatusBar = null;
John Spurlock27735a42013-08-14 17:57:38 -04002493 mStatusBarController.setWindow(null);
Jim Millerc0b676d2013-03-22 16:11:08 -07002494 mKeyguardDelegate.showScrim();
Jim Miller5ecd8112013-01-09 18:50:26 -08002495 } else if (mKeyguardScrim == win) {
2496 Log.v(TAG, "Removing keyguard scrim");
2497 mKeyguardScrim = null;
2498 } if (mNavigationBar == win) {
Daniel Sandler8956dbb2011-04-22 07:55:02 -04002499 mNavigationBar = null;
John Spurlock27735a42013-08-14 17:57:38 -04002500 mNavigationBarController.setWindow(null);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002501 }
2502 }
2503
2504 static final boolean PRINT_ANIM = false;
RoboErik8a2cfc32014-05-16 11:19:38 -07002505
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002506 /** {@inheritDoc} */
Craig Mautner4b71aa12012-12-27 17:20:01 -08002507 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002508 public int selectAnimationLw(WindowState win, int transit) {
2509 if (PRINT_ANIM) Log.i(TAG, "selectAnimation in " + win
2510 + ": transit=" + transit);
Dianne Hackbornf87d1962012-04-04 12:48:24 -07002511 if (win == mStatusBar) {
Jorim Jaggi380ecb82014-03-14 17:25:20 +01002512 boolean isKeyguard = (win.getAttrs().privateFlags & PRIVATE_FLAG_KEYGUARD) != 0;
Craig Mautner4b71aa12012-12-27 17:20:01 -08002513 if (transit == TRANSIT_EXIT
2514 || transit == TRANSIT_HIDE) {
Jorim Jaggi380ecb82014-03-14 17:25:20 +01002515 return isKeyguard ? -1 : R.anim.dock_top_exit;
Craig Mautner4b71aa12012-12-27 17:20:01 -08002516 } else if (transit == TRANSIT_ENTER
2517 || transit == TRANSIT_SHOW) {
Jorim Jaggi380ecb82014-03-14 17:25:20 +01002518 return isKeyguard ? -1 : R.anim.dock_top_enter;
Dianne Hackbornf87d1962012-04-04 12:48:24 -07002519 }
2520 } else if (win == mNavigationBar) {
Jorim Jaggi0d210f62015-07-10 14:24:44 -07002521 if (win.getAttrs().windowAnimations != 0) {
2522 return 0;
2523 }
Dianne Hackbornf87d1962012-04-04 12:48:24 -07002524 // This can be on either the bottom or the right.
2525 if (mNavigationBarOnBottom) {
Craig Mautner4b71aa12012-12-27 17:20:01 -08002526 if (transit == TRANSIT_EXIT
2527 || transit == TRANSIT_HIDE) {
Dianne Hackbornf87d1962012-04-04 12:48:24 -07002528 return R.anim.dock_bottom_exit;
Craig Mautner4b71aa12012-12-27 17:20:01 -08002529 } else if (transit == TRANSIT_ENTER
2530 || transit == TRANSIT_SHOW) {
Dianne Hackbornf87d1962012-04-04 12:48:24 -07002531 return R.anim.dock_bottom_enter;
2532 }
2533 } else {
Craig Mautner4b71aa12012-12-27 17:20:01 -08002534 if (transit == TRANSIT_EXIT
2535 || transit == TRANSIT_HIDE) {
Dianne Hackbornf87d1962012-04-04 12:48:24 -07002536 return R.anim.dock_right_exit;
Craig Mautner4b71aa12012-12-27 17:20:01 -08002537 } else if (transit == TRANSIT_ENTER
2538 || transit == TRANSIT_SHOW) {
Dianne Hackbornf87d1962012-04-04 12:48:24 -07002539 return R.anim.dock_right_enter;
2540 }
2541 }
Filip Gruszczynski57f76f12015-11-04 16:10:54 -08002542 } else if (win.getAttrs().type == TYPE_DOCK_DIVIDER) {
Filip Gruszczynski64cdc142015-11-29 21:10:07 -08002543 if (transit == TRANSIT_ENTER || transit == TRANSIT_SHOW) {
Filip Gruszczynski57f76f12015-11-04 16:10:54 -08002544 return R.anim.fade_in;
2545 } else if (transit == TRANSIT_EXIT) {
2546 return R.anim.fade_out;
2547 }
Craig Mautner4b71aa12012-12-27 17:20:01 -08002548 }
2549
2550 if (transit == TRANSIT_PREVIEW_DONE) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002551 if (win.hasAppShownWindows()) {
2552 if (PRINT_ANIM) Log.i(TAG, "**** STARTING EXIT");
2553 return com.android.internal.R.anim.app_starting_exit;
2554 }
Dianne Hackborn7ad44382012-10-18 17:46:00 -07002555 } else if (win.getAttrs().type == TYPE_DREAM && mDreamingLockscreen
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07002556 && transit == TRANSIT_ENTER) {
2557 // Special case: we are animating in a dream, while the keyguard
2558 // is shown. We don't want an animation on the dream, because
2559 // we need it shown immediately with the keyguard animating away
2560 // to reveal it.
2561 return -1;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002562 }
2563
2564 return 0;
2565 }
2566
Craig Mautner3c174372013-02-21 17:54:37 -08002567 @Override
2568 public void selectRotationAnimationLw(int anim[]) {
2569 if (PRINT_ANIM) Slog.i(TAG, "selectRotationAnimation mTopFullscreen="
2570 + mTopFullscreenOpaqueWindowState + " rotationAnimation="
2571 + (mTopFullscreenOpaqueWindowState == null ?
2572 "0" : mTopFullscreenOpaqueWindowState.getAttrs().rotationAnimation));
2573 if (mTopFullscreenOpaqueWindowState != null && mTopIsFullscreen) {
2574 switch (mTopFullscreenOpaqueWindowState.getAttrs().rotationAnimation) {
2575 case ROTATION_ANIMATION_CROSSFADE:
2576 anim[0] = R.anim.rotation_animation_xfade_exit;
2577 anim[1] = R.anim.rotation_animation_enter;
2578 break;
2579 case ROTATION_ANIMATION_JUMPCUT:
2580 anim[0] = R.anim.rotation_animation_jump_exit;
2581 anim[1] = R.anim.rotation_animation_enter;
2582 break;
2583 case ROTATION_ANIMATION_ROTATE:
2584 default:
2585 anim[0] = anim[1] = 0;
2586 break;
2587 }
2588 } else {
2589 anim[0] = anim[1] = 0;
2590 }
2591 }
2592
2593 @Override
2594 public boolean validateRotationAnimationLw(int exitAnimId, int enterAnimId,
2595 boolean forceDefault) {
2596 switch (exitAnimId) {
2597 case R.anim.rotation_animation_xfade_exit:
2598 case R.anim.rotation_animation_jump_exit:
2599 // These are the only cases that matter.
2600 if (forceDefault) {
2601 return false;
2602 }
2603 int anim[] = new int[2];
2604 selectRotationAnimationLw(anim);
2605 return (exitAnimId == anim[0] && enterAnimId == anim[1]);
2606 default:
2607 return true;
2608 }
2609 }
2610
2611 @Override
Jorim Jaggi84a3e7a2014-08-13 17:58:58 +02002612 public Animation createForceHideEnterAnimation(boolean onWallpaper,
2613 boolean goingToNotificationShade) {
2614 if (goingToNotificationShade) {
2615 return AnimationUtils.loadAnimation(mContext, R.anim.lock_screen_behind_enter_fade_in);
Craig Mautnerb8340802014-11-04 15:32:57 -08002616 }
Craig Mautner276a6eb2014-11-04 15:32:57 -08002617
2618 AnimationSet set = (AnimationSet) AnimationUtils.loadAnimation(mContext, onWallpaper ?
2619 R.anim.lock_screen_behind_enter_wallpaper :
2620 R.anim.lock_screen_behind_enter);
2621
2622 // TODO: Use XML interpolators when we have log interpolators available in XML.
2623 final List<Animation> animations = set.getAnimations();
2624 for (int i = animations.size() - 1; i >= 0; --i) {
2625 animations.get(i).setInterpolator(mLogDecelerateInterpolator);
2626 }
2627
2628 return set;
Jorim Jaggi76a16232014-08-08 17:00:47 +02002629 }
2630
2631
2632 @Override
Jorim Jaggi84a3e7a2014-08-13 17:58:58 +02002633 public Animation createForceHideWallpaperExitAnimation(boolean goingToNotificationShade) {
2634 if (goingToNotificationShade) {
2635 return null;
2636 } else {
2637 return AnimationUtils.loadAnimation(mContext, R.anim.lock_screen_wallpaper_exit);
2638 }
Dianne Hackborn01ad2f42009-09-24 19:24:56 -07002639 }
John Spurlockc8b46ca2013-04-08 12:59:26 -04002640
2641 private static void awakenDreams() {
2642 IDreamManager dreamManager = getDreamManager();
2643 if (dreamManager != null) {
2644 try {
2645 dreamManager.awaken();
2646 } catch (RemoteException e) {
2647 // fine, stay asleep then
2648 }
2649 }
2650 }
2651
2652 static IDreamManager getDreamManager() {
2653 return IDreamManager.Stub.asInterface(
2654 ServiceManager.checkService(DreamService.DREAM_SERVICE));
2655 }
2656
Tyler Gunnef9f6f92014-09-12 22:16:17 -07002657 TelecomManager getTelecommService() {
2658 return (TelecomManager) mContext.getSystemService(Context.TELECOM_SERVICE);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002659 }
2660
Jeff Brown4d396052010-10-29 21:50:21 -07002661 static IAudioService getAudioService() {
2662 IAudioService audioService = IAudioService.Stub.asInterface(
2663 ServiceManager.checkService(Context.AUDIO_SERVICE));
2664 if (audioService == null) {
2665 Log.w(TAG, "Unable to find IAudioService interface.");
2666 }
2667 return audioService;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002668 }
2669
2670 boolean keyguardOn() {
Jim Millerab954542014-10-10 18:21:49 -07002671 return isKeyguardShowingAndNotOccluded() || inKeyguardRestrictedKeyInputMode();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002672 }
2673
2674 private static final int[] WINDOW_TYPES_WHERE_HOME_DOESNT_WORK = {
2675 WindowManager.LayoutParams.TYPE_SYSTEM_ALERT,
2676 WindowManager.LayoutParams.TYPE_SYSTEM_ERROR,
2677 };
2678
2679 /** {@inheritDoc} */
Jeff Brown00fa7bd2010-07-02 15:37:36 -07002680 @Override
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002681 public long interceptKeyBeforeDispatching(WindowState win, KeyEvent event, int policyFlags) {
Jeff Brown00fa7bd2010-07-02 15:37:36 -07002682 final boolean keyguardOn = keyguardOn();
Jeff Brown1f245102010-11-18 20:53:46 -08002683 final int keyCode = event.getKeyCode();
2684 final int repeatCount = event.getRepeatCount();
2685 final int metaState = event.getMetaState();
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002686 final int flags = event.getFlags();
Jeff Brown1f245102010-11-18 20:53:46 -08002687 final boolean down = event.getAction() == KeyEvent.ACTION_DOWN;
2688 final boolean canceled = event.isCanceled();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002689
Jeff Brown40013652012-05-16 21:22:36 -07002690 if (DEBUG_INPUT) {
Jeff Brown00fa7bd2010-07-02 15:37:36 -07002691 Log.d(TAG, "interceptKeyTi keyCode=" + keyCode + " down=" + down + " repeatCount="
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002692 + repeatCount + " keyguardOn=" + keyguardOn + " mHomePressed=" + mHomePressed
2693 + " canceled=" + canceled);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002694 }
2695
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002696 // If we think we might have a volume down & power key chord on the way
2697 // but we're not sure, then tell the dispatcher to wait a little while and
2698 // try again later before dispatching.
Christopher Tatee90585f2012-03-05 18:56:25 -08002699 if (mScreenshotChordEnabled && (flags & KeyEvent.FLAG_FALLBACK) == 0) {
Jeff Brown13f00f02014-10-31 14:45:50 -07002700 if (mScreenshotChordVolumeDownKeyTriggered && !mScreenshotChordPowerKeyTriggered) {
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002701 final long now = SystemClock.uptimeMillis();
Jeff Brown13f00f02014-10-31 14:45:50 -07002702 final long timeoutTime = mScreenshotChordVolumeDownKeyTime
2703 + SCREENSHOT_CHORD_DEBOUNCE_DELAY_MILLIS;
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002704 if (now < timeoutTime) {
2705 return timeoutTime - now;
2706 }
2707 }
2708 if (keyCode == KeyEvent.KEYCODE_VOLUME_DOWN
Jeff Brown13f00f02014-10-31 14:45:50 -07002709 && mScreenshotChordVolumeDownKeyConsumed) {
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002710 if (!down) {
Jeff Brown13f00f02014-10-31 14:45:50 -07002711 mScreenshotChordVolumeDownKeyConsumed = false;
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002712 }
2713 return -1;
2714 }
2715 }
2716
Michael Wright6a62e552014-06-03 19:19:48 -07002717 // Cancel any pending meta actions if we see any other keys being pressed between the down
2718 // of the meta key and its corresponding up.
Michael Wright251e35d2014-08-22 15:40:27 -07002719 if (mPendingMetaAction && !KeyEvent.isMetaKey(keyCode)) {
Michael Wright6a62e552014-06-03 19:19:48 -07002720 mPendingMetaAction = false;
2721 }
2722
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002723 // First we always handle the home key here, so applications
2724 // can never break it, although if keyguard is on, we do let
2725 // it handle it, because that gives us the correct 5 second
2726 // timeout.
Jeff Brown00fa7bd2010-07-02 15:37:36 -07002727 if (keyCode == KeyEvent.KEYCODE_HOME) {
Michael Jurka7f2668c2012-03-27 07:49:52 -07002728
Jeff Brown49ed71d2010-12-06 17:13:33 -08002729 // If we have released the home key, and didn't do anything else
2730 // while it was pressed, then it is time to go home!
Michael Jurka7f2668c2012-03-27 07:49:52 -07002731 if (!down) {
Jeff Browncaca8812013-05-09 13:34:33 -07002732 cancelPreloadRecentApps();
2733
Jeff Brown49ed71d2010-12-06 17:13:33 -08002734 mHomePressed = false;
Jeff Browncaca8812013-05-09 13:34:33 -07002735 if (mHomeConsumed) {
2736 mHomeConsumed = false;
Michael Jurka7f2668c2012-03-27 07:49:52 -07002737 return -1;
Jeff Brown49ed71d2010-12-06 17:13:33 -08002738 }
Jeff Browncaca8812013-05-09 13:34:33 -07002739
2740 if (canceled) {
2741 Log.i(TAG, "Ignoring HOME; event canceled.");
2742 return -1;
2743 }
2744
Yorke Lee4f803242014-12-15 23:22:06 +00002745 // If an incoming call is ringing, HOME is totally disabled.
2746 // (The user is already on the InCallUI at this point,
2747 // and his ONLY options are to answer or reject the call.)
2748 TelecomManager telecomManager = getTelecommService();
2749 if (telecomManager != null && telecomManager.isRinging()) {
2750 Log.i(TAG, "Ignoring HOME; there's a ringing incoming call.");
2751 return -1;
2752 }
2753
Jeff Browncaca8812013-05-09 13:34:33 -07002754 // Delay handling home if a double-tap is possible.
2755 if (mDoubleTapOnHomeBehavior != DOUBLE_TAP_HOME_NOTHING) {
2756 mHandler.removeCallbacks(mHomeDoubleTapTimeoutRunnable); // just in case
2757 mHomeDoubleTapPending = true;
2758 mHandler.postDelayed(mHomeDoubleTapTimeoutRunnable,
2759 ViewConfiguration.getDoubleTapTimeout());
2760 return -1;
2761 }
2762
Jeff Brown13f00f02014-10-31 14:45:50 -07002763 handleShortPressOnHome();
Jeff Browncaca8812013-05-09 13:34:33 -07002764 return -1;
Jeff Brown49ed71d2010-12-06 17:13:33 -08002765 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002766
2767 // If a system window has focus, then it doesn't make sense
2768 // right now to interact with applications.
2769 WindowManager.LayoutParams attrs = win != null ? win.getAttrs() : null;
2770 if (attrs != null) {
2771 final int type = attrs.type;
Jorim Jaggi380ecb82014-03-14 17:25:20 +01002772 if (type == WindowManager.LayoutParams.TYPE_KEYGUARD_SCRIM
2773 || type == WindowManager.LayoutParams.TYPE_KEYGUARD_DIALOG
2774 || (attrs.privateFlags & PRIVATE_FLAG_KEYGUARD) != 0) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002775 // the "app" is keyguard, so give it the key
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002776 return 0;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002777 }
2778 final int typeCount = WINDOW_TYPES_WHERE_HOME_DOESNT_WORK.length;
2779 for (int i=0; i<typeCount; i++) {
2780 if (type == WINDOW_TYPES_WHERE_HOME_DOESNT_WORK[i]) {
2781 // don't do anything, but also don't pass it to the app
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002782 return -1;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002783 }
2784 }
2785 }
Jeff Browncaca8812013-05-09 13:34:33 -07002786
2787 // Remember that home is pressed and handle special actions.
2788 if (repeatCount == 0) {
2789 mHomePressed = true;
2790 if (mHomeDoubleTapPending) {
2791 mHomeDoubleTapPending = false;
2792 mHandler.removeCallbacks(mHomeDoubleTapTimeoutRunnable);
2793 handleDoubleTapOnHome();
2794 } else if (mLongPressOnHomeBehavior == LONG_PRESS_HOME_RECENT_SYSTEM_UI
2795 || mDoubleTapOnHomeBehavior == DOUBLE_TAP_HOME_RECENT_SYSTEM_UI) {
2796 preloadRecentApps();
Michael Jurka7f2668c2012-03-27 07:49:52 -07002797 }
Jeff Browncaca8812013-05-09 13:34:33 -07002798 } else if ((event.getFlags() & KeyEvent.FLAG_LONG_PRESS) != 0) {
2799 if (!keyguardOn) {
Tim Kilbourn0e5f1102015-06-05 16:18:09 -07002800 handleLongPressOnHome(event.getDeviceId());
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002801 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002802 }
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002803 return -1;
Jeff Brown00fa7bd2010-07-02 15:37:36 -07002804 } else if (keyCode == KeyEvent.KEYCODE_MENU) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002805 // Hijack modified menu keys for debugging features
2806 final int chordBug = KeyEvent.META_SHIFT_ON;
2807
2808 if (down && repeatCount == 0) {
Jeff Brown00fa7bd2010-07-02 15:37:36 -07002809 if (mEnableShiftMenuBugReports && (metaState & chordBug) == chordBug) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002810 Intent intent = new Intent(Intent.ACTION_BUG_REPORT);
Dianne Hackborn5ac72a22012-08-29 18:32:08 -07002811 mContext.sendOrderedBroadcastAsUser(intent, UserHandle.CURRENT,
2812 null, null, null, 0, null, null);
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002813 return -1;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002814 } else if (SHOW_PROCESSES_ON_ALT_MENU &&
Jeff Brown00fa7bd2010-07-02 15:37:36 -07002815 (metaState & KeyEvent.META_ALT_ON) == KeyEvent.META_ALT_ON) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002816 Intent service = new Intent();
2817 service.setClassName(mContext, "com.android.server.LoadAverageService");
2818 ContentResolver res = mContext.getContentResolver();
Jeff Sharkey8d9a1f62012-10-18 15:38:14 -07002819 boolean shown = Settings.Global.getInt(
2820 res, Settings.Global.SHOW_PROCESSES, 0) != 0;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002821 if (!shown) {
2822 mContext.startService(service);
2823 } else {
2824 mContext.stopService(service);
2825 }
Jeff Sharkey8d9a1f62012-10-18 15:38:14 -07002826 Settings.Global.putInt(
2827 res, Settings.Global.SHOW_PROCESSES, shown ? 0 : 1);
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002828 return -1;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002829 }
2830 }
Jeff Brown00fa7bd2010-07-02 15:37:36 -07002831 } else if (keyCode == KeyEvent.KEYCODE_SEARCH) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002832 if (down) {
2833 if (repeatCount == 0) {
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002834 mSearchKeyShortcutPending = true;
2835 mConsumeSearchKeyUp = false;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002836 }
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002837 } else {
2838 mSearchKeyShortcutPending = false;
2839 if (mConsumeSearchKeyUp) {
2840 mConsumeSearchKeyUp = false;
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002841 return -1;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002842 }
2843 }
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002844 return 0;
Jeff Brown49ed71d2010-12-06 17:13:33 -08002845 } else if (keyCode == KeyEvent.KEYCODE_APP_SWITCH) {
Michael Wrightc9ebea72013-01-16 19:25:02 -08002846 if (!keyguardOn) {
Jeff Browncaca8812013-05-09 13:34:33 -07002847 if (down && repeatCount == 0) {
2848 preloadRecentApps();
2849 } else if (!down) {
2850 toggleRecentApps();
Michael Wrightc9ebea72013-01-16 19:25:02 -08002851 }
Jeff Brown49ed71d2010-12-06 17:13:33 -08002852 }
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002853 return -1;
Jun Mukaid21b3c82015-04-23 14:09:34 -07002854 } else if (keyCode == KeyEvent.KEYCODE_N && event.isMetaPressed()) {
2855 if (down) {
2856 IStatusBarService service = getStatusBarService();
2857 if (service != null) {
2858 try {
2859 service.expandNotificationsPanel();
2860 } catch (RemoteException e) {
2861 // do nothing.
2862 }
2863 }
2864 }
Clara Bayarrif2debb12015-07-10 14:47:17 +01002865 } else if (keyCode == KeyEvent.KEYCODE_SLASH && event.isMetaPressed()) {
2866 if (down) {
2867 if (repeatCount == 0) {
2868 showKeyboardShortcutsMenu();
2869 }
2870 }
Jeff Brownde7a8ea2012-06-13 18:28:57 -07002871 } else if (keyCode == KeyEvent.KEYCODE_ASSIST) {
2872 if (down) {
2873 if (repeatCount == 0) {
2874 mAssistKeyLongPressed = false;
2875 } else if (repeatCount == 1) {
2876 mAssistKeyLongPressed = true;
2877 if (!keyguardOn) {
2878 launchAssistLongPressAction();
2879 }
2880 }
2881 } else {
2882 if (mAssistKeyLongPressed) {
2883 mAssistKeyLongPressed = false;
2884 } else {
2885 if (!keyguardOn) {
Tim Kilbourn0e5f1102015-06-05 16:18:09 -07002886 launchAssistAction(null, event.getDeviceId());
Jeff Brownde7a8ea2012-06-13 18:28:57 -07002887 }
2888 }
2889 }
2890 return -1;
Michael Wrightdc63f7b2014-08-21 19:05:21 -07002891 } else if (keyCode == KeyEvent.KEYCODE_VOICE_ASSIST) {
2892 if (!down) {
2893 Intent voiceIntent;
Michael Wright869a67c2014-08-26 19:33:06 -07002894 if (!keyguardOn) {
Michael Wrightdc63f7b2014-08-21 19:05:21 -07002895 voiceIntent = new Intent(RecognizerIntent.ACTION_WEB_SEARCH);
2896 } else {
Dianne Hackbornb6683c42015-06-18 17:40:33 -07002897 IDeviceIdleController dic = IDeviceIdleController.Stub.asInterface(
2898 ServiceManager.getService(Context.DEVICE_IDLE_CONTROLLER));
2899 if (dic != null) {
2900 try {
2901 dic.exitIdle("voice-search");
2902 } catch (RemoteException e) {
2903 }
2904 }
Michael Wrightdc63f7b2014-08-21 19:05:21 -07002905 voiceIntent = new Intent(RecognizerIntent.ACTION_VOICE_SEARCH_HANDS_FREE);
Michael Wright869a67c2014-08-26 19:33:06 -07002906 voiceIntent.putExtra(RecognizerIntent.EXTRA_SECURE, true);
Michael Wrightdc63f7b2014-08-21 19:05:21 -07002907 }
Bart Sears8b1c27c2015-03-18 23:51:02 +00002908 startActivityAsUser(voiceIntent, UserHandle.CURRENT_OR_SELF);
Michael Wrightdc63f7b2014-08-21 19:05:21 -07002909 }
Jeff Sharkey2991fa32012-12-05 18:06:43 -08002910 } else if (keyCode == KeyEvent.KEYCODE_SYSRQ) {
2911 if (down && repeatCount == 0) {
2912 mHandler.post(mScreenshotRunnable);
2913 }
2914 return -1;
Michael Wrightb854e242013-02-05 17:54:02 -08002915 } else if (keyCode == KeyEvent.KEYCODE_BRIGHTNESS_UP
2916 || keyCode == KeyEvent.KEYCODE_BRIGHTNESS_DOWN) {
2917 if (down) {
2918 int direction = keyCode == KeyEvent.KEYCODE_BRIGHTNESS_UP ? 1 : -1;
2919
2920 // Disable autobrightness if it's on
2921 int auto = Settings.System.getIntForUser(
2922 mContext.getContentResolver(),
2923 Settings.System.SCREEN_BRIGHTNESS_MODE,
2924 Settings.System.SCREEN_BRIGHTNESS_MODE_MANUAL,
2925 UserHandle.USER_CURRENT_OR_SELF);
2926 if (auto != 0) {
2927 Settings.System.putIntForUser(mContext.getContentResolver(),
2928 Settings.System.SCREEN_BRIGHTNESS_MODE,
2929 Settings.System.SCREEN_BRIGHTNESS_MODE_MANUAL,
2930 UserHandle.USER_CURRENT_OR_SELF);
2931 }
2932
2933 int min = mPowerManager.getMinimumScreenBrightnessSetting();
2934 int max = mPowerManager.getMaximumScreenBrightnessSetting();
2935 int step = (max - min + BRIGHTNESS_STEPS - 1) / BRIGHTNESS_STEPS * direction;
2936 int brightness = Settings.System.getIntForUser(mContext.getContentResolver(),
2937 Settings.System.SCREEN_BRIGHTNESS,
2938 mPowerManager.getDefaultScreenBrightnessSetting(),
2939 UserHandle.USER_CURRENT_OR_SELF);
2940 brightness += step;
2941 // Make sure we don't go beyond the limits.
2942 brightness = Math.min(max, brightness);
2943 brightness = Math.max(min, brightness);
2944
2945 Settings.System.putIntForUser(mContext.getContentResolver(),
2946 Settings.System.SCREEN_BRIGHTNESS, brightness,
2947 UserHandle.USER_CURRENT_OR_SELF);
Bart Sears8b1c27c2015-03-18 23:51:02 +00002948 startActivityAsUser(new Intent(Intent.ACTION_SHOW_BRIGHTNESS_DIALOG),
Alan Viverette5a399492014-07-14 16:19:38 -07002949 UserHandle.CURRENT_OR_SELF);
Michael Wrightb854e242013-02-05 17:54:02 -08002950 }
2951 return -1;
Michael Wrightce0c13a2014-07-30 10:49:21 -07002952 } else if (KeyEvent.isMetaKey(keyCode)) {
Michael Wright6a62e552014-06-03 19:19:48 -07002953 if (down) {
2954 mPendingMetaAction = true;
2955 } else if (mPendingMetaAction) {
Tim Kilbourn0e5f1102015-06-05 16:18:09 -07002956 launchAssistAction(Intent.EXTRA_ASSIST_INPUT_HINT_KEYBOARD, event.getDeviceId());
Michael Wright6a62e552014-06-03 19:19:48 -07002957 }
2958 return -1;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002959 }
Jeff Browncaab4d02010-12-09 22:13:41 -08002960
Jeff Brownc1fb48d2010-12-08 16:52:09 -08002961 // Shortcuts are invoked through Search+key, so intercept those here
Jeff Browncaab4d02010-12-09 22:13:41 -08002962 // Any printing key that is chorded with Search should be consumed
2963 // even if no shortcut was invoked. This prevents text from being
2964 // inadvertently inserted when using a keyboard that has built-in macro
2965 // shortcut keys (that emit Search+x) and some of them are not registered.
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002966 if (mSearchKeyShortcutPending) {
Jeff Browncaab4d02010-12-09 22:13:41 -08002967 final KeyCharacterMap kcm = event.getKeyCharacterMap();
2968 if (kcm.isPrintingKey(keyCode)) {
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002969 mConsumeSearchKeyUp = true;
2970 mSearchKeyShortcutPending = false;
Jeff Browncaab4d02010-12-09 22:13:41 -08002971 if (down && repeatCount == 0 && !keyguardOn) {
2972 Intent shortcutIntent = mShortcutManager.getIntent(kcm, keyCode, metaState);
2973 if (shortcutIntent != null) {
2974 shortcutIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
Jeff Brownf0a3cc52011-01-26 18:42:46 -08002975 try {
Bart Sears8b1c27c2015-03-18 23:51:02 +00002976 startActivityAsUser(shortcutIntent, UserHandle.CURRENT);
Jeff Brownf0a3cc52011-01-26 18:42:46 -08002977 } catch (ActivityNotFoundException ex) {
2978 Slog.w(TAG, "Dropping shortcut key combination because "
2979 + "the activity to which it is registered was not found: "
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002980 + "SEARCH+" + KeyEvent.keyCodeToString(keyCode), ex);
Jeff Brownf0a3cc52011-01-26 18:42:46 -08002981 }
Jeff Browncaab4d02010-12-09 22:13:41 -08002982 } else {
2983 Slog.i(TAG, "Dropping unregistered shortcut key combination: "
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002984 + "SEARCH+" + KeyEvent.keyCodeToString(keyCode));
Jeff Brown49ed71d2010-12-06 17:13:33 -08002985 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002986 }
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002987 return -1;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002988 }
2989 }
2990
Jeff Brown68b909d2011-12-07 16:36:01 -08002991 // Invoke shortcuts using Meta.
Jeff Brown602ab322012-05-16 13:33:47 -07002992 if (down && repeatCount == 0 && !keyguardOn
Jeff Brown68b909d2011-12-07 16:36:01 -08002993 && (metaState & KeyEvent.META_META_ON) != 0) {
2994 final KeyCharacterMap kcm = event.getKeyCharacterMap();
Jeff Brown602ab322012-05-16 13:33:47 -07002995 if (kcm.isPrintingKey(keyCode)) {
2996 Intent shortcutIntent = mShortcutManager.getIntent(kcm, keyCode,
2997 metaState & ~(KeyEvent.META_META_ON
2998 | KeyEvent.META_META_LEFT_ON | KeyEvent.META_META_RIGHT_ON));
2999 if (shortcutIntent != null) {
3000 shortcutIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
3001 try {
Bart Sears8b1c27c2015-03-18 23:51:02 +00003002 startActivityAsUser(shortcutIntent, UserHandle.CURRENT);
Jeff Brown602ab322012-05-16 13:33:47 -07003003 } catch (ActivityNotFoundException ex) {
3004 Slog.w(TAG, "Dropping shortcut key combination because "
3005 + "the activity to which it is registered was not found: "
3006 + "META+" + KeyEvent.keyCodeToString(keyCode), ex);
3007 }
3008 return -1;
Jeff Brown68b909d2011-12-07 16:36:01 -08003009 }
Jeff Brown68b909d2011-12-07 16:36:01 -08003010 }
3011 }
3012
Jeff Brown6651a632011-11-28 12:59:11 -08003013 // Handle application launch keys.
Jeff Brown602ab322012-05-16 13:33:47 -07003014 if (down && repeatCount == 0 && !keyguardOn) {
Jeff Brown6651a632011-11-28 12:59:11 -08003015 String category = sApplicationLaunchKeyCategories.get(keyCode);
3016 if (category != null) {
Dianne Hackbornf5b86712011-12-05 17:42:41 -08003017 Intent intent = Intent.makeMainSelectorActivity(Intent.ACTION_MAIN, category);
Jeff Brown6651a632011-11-28 12:59:11 -08003018 intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
3019 try {
Bart Sears8b1c27c2015-03-18 23:51:02 +00003020 startActivityAsUser(intent, UserHandle.CURRENT);
Jeff Brown6651a632011-11-28 12:59:11 -08003021 } catch (ActivityNotFoundException ex) {
3022 Slog.w(TAG, "Dropping application launch key because "
3023 + "the activity to which it is registered was not found: "
3024 + "keyCode=" + keyCode + ", category=" + category, ex);
3025 }
Jeff Brown68b909d2011-12-07 16:36:01 -08003026 return -1;
Jeff Brown6651a632011-11-28 12:59:11 -08003027 }
3028 }
3029
Michael Wright61c46752014-08-21 16:57:33 -07003030 // Display task switcher for ALT-TAB.
Jeff Brown68b909d2011-12-07 16:36:01 -08003031 if (down && repeatCount == 0 && keyCode == KeyEvent.KEYCODE_TAB) {
Michael Wrightd847ad52015-10-24 13:24:15 +01003032 if (mRecentAppsHeldModifiers == 0 && !keyguardOn && isUserSetupComplete()) {
Jeff Brown68b909d2011-12-07 16:36:01 -08003033 final int shiftlessModifiers = event.getModifiers() & ~KeyEvent.META_SHIFT_MASK;
Michael Wright61c46752014-08-21 16:57:33 -07003034 if (KeyEvent.metaStateHasModifiers(shiftlessModifiers, KeyEvent.META_ALT_ON)) {
Winson Chung1e8d71b2014-05-16 17:05:22 -07003035 mRecentAppsHeldModifiers = shiftlessModifiers;
3036 showRecentApps(true);
Jeff Brown68b909d2011-12-07 16:36:01 -08003037 return -1;
3038 }
3039 }
Winson Chung1e8d71b2014-05-16 17:05:22 -07003040 } else if (!down && mRecentAppsHeldModifiers != 0
3041 && (metaState & mRecentAppsHeldModifiers) == 0) {
3042 mRecentAppsHeldModifiers = 0;
Winson Chungcdcd4872014-08-05 18:00:13 -07003043 hideRecentApps(true, false);
Jeff Brown68b909d2011-12-07 16:36:01 -08003044 }
3045
Jeff Browncf39bdf2012-05-18 14:41:19 -07003046 // Handle keyboard language switching.
3047 if (down && repeatCount == 0
3048 && (keyCode == KeyEvent.KEYCODE_LANGUAGE_SWITCH
3049 || (keyCode == KeyEvent.KEYCODE_SPACE
3050 && (metaState & KeyEvent.META_CTRL_MASK) != 0))) {
3051 int direction = (metaState & KeyEvent.META_SHIFT_MASK) != 0 ? -1 : 1;
3052 mWindowManagerFuncs.switchKeyboardLayout(event.getDeviceId(), direction);
3053 return -1;
3054 }
3055 if (mLanguageSwitchKeyPressed && !down
3056 && (keyCode == KeyEvent.KEYCODE_LANGUAGE_SWITCH
3057 || keyCode == KeyEvent.KEYCODE_SPACE)) {
3058 mLanguageSwitchKeyPressed = false;
3059 return -1;
3060 }
3061
Jeff Brown13f00f02014-10-31 14:45:50 -07003062 if (isValidGlobalKey(keyCode)
3063 && mGlobalKeyManager.handleGlobalKey(mContext, keyCode, event)) {
Justin Kohd378ad72013-04-01 12:18:26 -07003064 return -1;
3065 }
3066
Michael Wright6a62e552014-06-03 19:19:48 -07003067 // Reserve all the META modifier combos for system behavior
Michael Wrightce0c13a2014-07-30 10:49:21 -07003068 if ((metaState & KeyEvent.META_META_ON) != 0) {
Michael Wright6a62e552014-06-03 19:19:48 -07003069 return -1;
3070 }
3071
Jeff Brown68b909d2011-12-07 16:36:01 -08003072 // Let the application handle the key.
Jeff Brownd5bb82d2011-10-12 13:57:59 -07003073 return 0;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003074 }
3075
Jeff Brown3915bb82010-11-05 15:02:16 -07003076 /** {@inheritDoc} */
3077 @Override
Jeff Brown49ed71d2010-12-06 17:13:33 -08003078 public KeyEvent dispatchUnhandledKey(WindowState win, KeyEvent event, int policyFlags) {
Jeff Brown54875002011-04-06 15:33:01 -07003079 // Note: This method is only called if the initial down was unhandled.
Jeff Brown40013652012-05-16 21:22:36 -07003080 if (DEBUG_INPUT) {
Jeff Brown1f245102010-11-18 20:53:46 -08003081 Slog.d(TAG, "Unhandled key: win=" + win + ", action=" + event.getAction()
3082 + ", flags=" + event.getFlags()
3083 + ", keyCode=" + event.getKeyCode()
3084 + ", scanCode=" + event.getScanCode()
3085 + ", metaState=" + event.getMetaState()
3086 + ", repeatCount=" + event.getRepeatCount()
3087 + ", policyFlags=" + policyFlags);
Jeff Brown3915bb82010-11-05 15:02:16 -07003088 }
Jeff Brown49ed71d2010-12-06 17:13:33 -08003089
Jeff Brownfd23e3e2012-05-09 13:34:28 -07003090 KeyEvent fallbackEvent = null;
Jeff Brown49ed71d2010-12-06 17:13:33 -08003091 if ((event.getFlags() & KeyEvent.FLAG_FALLBACK) == 0) {
3092 final KeyCharacterMap kcm = event.getKeyCharacterMap();
Jeff Brownc1fb48d2010-12-08 16:52:09 -08003093 final int keyCode = event.getKeyCode();
3094 final int metaState = event.getMetaState();
Jeff Brownfd23e3e2012-05-09 13:34:28 -07003095 final boolean initialDown = event.getAction() == KeyEvent.ACTION_DOWN
3096 && event.getRepeatCount() == 0;
Jeff Brown49ed71d2010-12-06 17:13:33 -08003097
Jeff Brown54875002011-04-06 15:33:01 -07003098 // Check for fallback actions specified by the key character map.
Jeff Brownfd23e3e2012-05-09 13:34:28 -07003099 final FallbackAction fallbackAction;
3100 if (initialDown) {
3101 fallbackAction = kcm.getFallbackAction(keyCode, metaState);
3102 } else {
3103 fallbackAction = mFallbackActions.get(keyCode);
3104 }
3105
3106 if (fallbackAction != null) {
Jeff Brown40013652012-05-16 21:22:36 -07003107 if (DEBUG_INPUT) {
Jeff Brownfd23e3e2012-05-09 13:34:28 -07003108 Slog.d(TAG, "Fallback: keyCode=" + fallbackAction.keyCode
3109 + " metaState=" + Integer.toHexString(fallbackAction.metaState));
Jeff Brown49ed71d2010-12-06 17:13:33 -08003110 }
3111
Jeff Brownfd23e3e2012-05-09 13:34:28 -07003112 final int flags = event.getFlags() | KeyEvent.FLAG_FALLBACK;
3113 fallbackEvent = KeyEvent.obtain(
Jeff Brown49ed71d2010-12-06 17:13:33 -08003114 event.getDownTime(), event.getEventTime(),
Jeff Brownfd23e3e2012-05-09 13:34:28 -07003115 event.getAction(), fallbackAction.keyCode,
3116 event.getRepeatCount(), fallbackAction.metaState,
Jeff Brown49ed71d2010-12-06 17:13:33 -08003117 event.getDeviceId(), event.getScanCode(),
3118 flags, event.getSource(), null);
Jeff Brownfd23e3e2012-05-09 13:34:28 -07003119
3120 if (!interceptFallback(win, fallbackEvent, policyFlags)) {
3121 fallbackEvent.recycle();
3122 fallbackEvent = null;
Jeff Brown49ed71d2010-12-06 17:13:33 -08003123 }
Jeff Brownfd23e3e2012-05-09 13:34:28 -07003124
3125 if (initialDown) {
3126 mFallbackActions.put(keyCode, fallbackAction);
3127 } else if (event.getAction() == KeyEvent.ACTION_UP) {
3128 mFallbackActions.remove(keyCode);
3129 fallbackAction.recycle();
3130 }
Jeff Brown49ed71d2010-12-06 17:13:33 -08003131 }
3132 }
3133
Jeff Brown40013652012-05-16 21:22:36 -07003134 if (DEBUG_INPUT) {
Jeff Brownfd23e3e2012-05-09 13:34:28 -07003135 if (fallbackEvent == null) {
3136 Slog.d(TAG, "No fallback.");
3137 } else {
3138 Slog.d(TAG, "Performing fallback: " + fallbackEvent);
3139 }
Jeff Brown49ed71d2010-12-06 17:13:33 -08003140 }
Jeff Brownfd23e3e2012-05-09 13:34:28 -07003141 return fallbackEvent;
Jeff Brown3915bb82010-11-05 15:02:16 -07003142 }
3143
Jeff Brownfd23e3e2012-05-09 13:34:28 -07003144 private boolean interceptFallback(WindowState win, KeyEvent fallbackEvent, int policyFlags) {
Jeff Brown037c33e2014-04-09 00:31:55 -07003145 int actions = interceptKeyBeforeQueueing(fallbackEvent, policyFlags);
Jeff Brownfd23e3e2012-05-09 13:34:28 -07003146 if ((actions & ACTION_PASS_TO_USER) != 0) {
3147 long delayMillis = interceptKeyBeforeDispatching(
3148 win, fallbackEvent, policyFlags);
3149 if (delayMillis == 0) {
3150 return true;
3151 }
3152 }
3153 return false;
Jeff Brown6f2fba42011-02-19 01:08:02 -08003154 }
3155
Jeff Brownde7a8ea2012-06-13 18:28:57 -07003156 private void launchAssistLongPressAction() {
3157 performHapticFeedbackLw(null, HapticFeedbackConstants.LONG_PRESS, false);
3158 sendCloseSystemWindows(SYSTEM_DIALOG_REASON_ASSIST);
3159
3160 // launch the search activity
3161 Intent intent = new Intent(Intent.ACTION_SEARCH_LONG_PRESS);
3162 intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
3163 try {
RoboErik8a2cfc32014-05-16 11:19:38 -07003164 // TODO: This only stops the factory-installed search manager.
Jim Miller45308b12012-06-18 19:23:39 -07003165 // Need to formalize an API to handle others
Jeff Brownde7a8ea2012-06-13 18:28:57 -07003166 SearchManager searchManager = getSearchManager();
3167 if (searchManager != null) {
3168 searchManager.stopSearch();
3169 }
Bart Sears8b1c27c2015-03-18 23:51:02 +00003170 startActivityAsUser(intent, UserHandle.CURRENT);
Jeff Brownde7a8ea2012-06-13 18:28:57 -07003171 } catch (ActivityNotFoundException e) {
3172 Slog.w(TAG, "No activity to handle assist long press action.", e);
3173 }
3174 }
3175
Tim Kilbourn0e5f1102015-06-05 16:18:09 -07003176 private void launchAssistAction(String hint, int deviceId) {
Jeff Brownde7a8ea2012-06-13 18:28:57 -07003177 sendCloseSystemWindows(SYSTEM_DIALOG_REASON_ASSIST);
Maurice Lam39d13812015-07-23 20:49:20 -07003178 if (!isUserSetupComplete()) {
3179 // Disable opening assist window during setup
3180 return;
3181 }
Tim Kilbourn0e5f1102015-06-05 16:18:09 -07003182 Bundle args = null;
3183 if (deviceId > Integer.MIN_VALUE) {
3184 args = new Bundle();
3185 args.putInt(Intent.EXTRA_ASSIST_INPUT_DEVICE_ID, deviceId);
Jeff Brownde7a8ea2012-06-13 18:28:57 -07003186 }
Jorim Jaggi165ce062015-07-06 16:18:11 -07003187 if ((mContext.getResources().getConfiguration().uiMode
3188 & Configuration.UI_MODE_TYPE_MASK) == Configuration.UI_MODE_TYPE_TELEVISION) {
3189 // On TV, use legacy handling until assistants are implemented in the proper way.
3190 ((SearchManager) mContext.getSystemService(Context.SEARCH_SERVICE))
3191 .launchLegacyAssist(hint, UserHandle.myUserId(), args);
3192 } else {
3193 try {
3194 if (hint != null) {
3195 if (args == null) {
3196 args = new Bundle();
3197 }
3198 args.putBoolean(hint, true);
3199 }
3200 IStatusBarService statusbar = getStatusBarService();
3201 if (statusbar != null) {
3202 statusbar.startAssist(args);
3203 }
3204 } catch (RemoteException e) {
3205 Slog.e(TAG, "RemoteException when starting assist", e);
3206 // re-acquire status bar service next time it is needed.
3207 mStatusBarService = null;
3208 }
3209 }
Jeff Brownde7a8ea2012-06-13 18:28:57 -07003210 }
3211
Bart Sears8b1c27c2015-03-18 23:51:02 +00003212 private void startActivityAsUser(Intent intent, UserHandle handle) {
3213 if (isUserSetupComplete()) {
3214 mContext.startActivityAsUser(intent, handle);
3215 } else {
3216 Slog.i(TAG, "Not starting activity because user setup is in progress: " + intent);
3217 }
3218 }
3219
Jeff Brownde7a8ea2012-06-13 18:28:57 -07003220 private SearchManager getSearchManager() {
3221 if (mSearchManager == null) {
3222 mSearchManager = (SearchManager) mContext.getSystemService(Context.SEARCH_SERVICE);
3223 }
3224 return mSearchManager;
3225 }
3226
Jeff Browncaca8812013-05-09 13:34:33 -07003227 private void preloadRecentApps() {
3228 mPreloadedRecentApps = true;
3229 try {
3230 IStatusBarService statusbar = getStatusBarService();
3231 if (statusbar != null) {
3232 statusbar.preloadRecentApps();
3233 }
3234 } catch (RemoteException e) {
3235 Slog.e(TAG, "RemoteException when preloading recent apps", e);
3236 // re-acquire status bar service next time it is needed.
3237 mStatusBarService = null;
3238 }
3239 }
3240
3241 private void cancelPreloadRecentApps() {
3242 if (mPreloadedRecentApps) {
3243 mPreloadedRecentApps = false;
3244 try {
3245 IStatusBarService statusbar = getStatusBarService();
3246 if (statusbar != null) {
3247 statusbar.cancelPreloadRecentApps();
3248 }
3249 } catch (RemoteException e) {
Winson Chung1e8d71b2014-05-16 17:05:22 -07003250 Slog.e(TAG, "RemoteException when cancelling recent apps preload", e);
Jeff Browncaca8812013-05-09 13:34:33 -07003251 // re-acquire status bar service next time it is needed.
3252 mStatusBarService = null;
3253 }
3254 }
3255 }
3256
3257 private void toggleRecentApps() {
3258 mPreloadedRecentApps = false; // preloading no longer needs to be canceled
Jeff Browncaca8812013-05-09 13:34:33 -07003259 try {
3260 IStatusBarService statusbar = getStatusBarService();
3261 if (statusbar != null) {
3262 statusbar.toggleRecentApps();
3263 }
3264 } catch (RemoteException e) {
Winson Chung1e8d71b2014-05-16 17:05:22 -07003265 Slog.e(TAG, "RemoteException when toggling recent apps", e);
3266 // re-acquire status bar service next time it is needed.
3267 mStatusBarService = null;
3268 }
3269 }
3270
Craig Mautner84984fa2014-06-19 11:19:20 -07003271 @Override
3272 public void showRecentApps() {
3273 mHandler.removeMessages(MSG_DISPATCH_SHOW_RECENTS);
3274 mHandler.sendEmptyMessage(MSG_DISPATCH_SHOW_RECENTS);
3275 }
3276
Winson Chung1e8d71b2014-05-16 17:05:22 -07003277 private void showRecentApps(boolean triggeredFromAltTab) {
3278 mPreloadedRecentApps = false; // preloading no longer needs to be canceled
3279 try {
3280 IStatusBarService statusbar = getStatusBarService();
3281 if (statusbar != null) {
3282 statusbar.showRecentApps(triggeredFromAltTab);
3283 }
3284 } catch (RemoteException e) {
Jeff Browncaca8812013-05-09 13:34:33 -07003285 Slog.e(TAG, "RemoteException when showing recent apps", e);
3286 // re-acquire status bar service next time it is needed.
3287 mStatusBarService = null;
3288 }
3289 }
3290
Clara Bayarrif2debb12015-07-10 14:47:17 +01003291 private void showKeyboardShortcutsMenu() {
3292 try {
3293 IStatusBarService statusbar = getStatusBarService();
3294 if (statusbar != null) {
3295 statusbar.showKeyboardShortcutsMenu();
3296 }
3297 } catch (RemoteException e) {
3298 Slog.e(TAG, "RemoteException when showing keyboard shortcuts menu", e);
3299 }
3300 }
3301
Winson Chungcdcd4872014-08-05 18:00:13 -07003302 private void hideRecentApps(boolean triggeredFromAltTab, boolean triggeredFromHome) {
Winson Chung1e8d71b2014-05-16 17:05:22 -07003303 mPreloadedRecentApps = false; // preloading no longer needs to be canceled
3304 try {
3305 IStatusBarService statusbar = getStatusBarService();
3306 if (statusbar != null) {
Winson Chungcdcd4872014-08-05 18:00:13 -07003307 statusbar.hideRecentApps(triggeredFromAltTab, triggeredFromHome);
Winson Chung1e8d71b2014-05-16 17:05:22 -07003308 }
3309 } catch (RemoteException e) {
3310 Slog.e(TAG, "RemoteException when closing recent apps", e);
3311 // re-acquire status bar service next time it is needed.
3312 mStatusBarService = null;
3313 }
3314 }
3315
Filip Gruszczynskia483a1d2015-03-17 19:06:58 +00003316 void launchHomeFromHotKey() {
Bryce Lee662ed802015-04-10 20:11:39 +00003317 launchHomeFromHotKey(true /* awakenFromDreams */, true /*respectKeyguard*/);
Filip Gruszczynskia483a1d2015-03-17 19:06:58 +00003318 }
3319
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003320 /**
3321 * A home key -> launch home action was detected. Take the appropriate action
3322 * given the situation with the keyguard.
3323 */
Bryce Lee662ed802015-04-10 20:11:39 +00003324 void launchHomeFromHotKey(final boolean awakenFromDreams, final boolean respectKeyguard) {
3325 if (respectKeyguard) {
3326 if (isKeyguardShowingAndNotOccluded()) {
3327 // don't launch home if keyguard showing
3328 return;
3329 }
3330
3331 if (!mHideLockScreen && mKeyguardDelegate.isInputRestricted()) {
3332 // when in keyguard restricted mode, must first verify unlock
3333 // before launching home
3334 mKeyguardDelegate.verifyUnlock(new OnKeyguardExitResult() {
3335 @Override
3336 public void onKeyguardExitResult(boolean success) {
3337 if (success) {
3338 try {
3339 ActivityManagerNative.getDefault().stopAppSwitches();
3340 } catch (RemoteException e) {
3341 }
3342 sendCloseSystemWindows(SYSTEM_DIALOG_REASON_HOME_KEY);
3343 startDockOrHome(true /*fromHomeKey*/, awakenFromDreams);
Dianne Hackborn256dd3b2009-05-19 18:51:21 -07003344 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003345 }
Bryce Lee662ed802015-04-10 20:11:39 +00003346 });
3347 return;
3348 }
3349 }
3350
3351 // no keyguard stuff to worry about, just launch home!
3352 try {
3353 ActivityManagerNative.getDefault().stopAppSwitches();
3354 } catch (RemoteException e) {
3355 }
3356 if (mRecentsVisible) {
3357 // Hide Recents and notify it to launch Home
3358 if (awakenFromDreams) {
3359 awakenDreams();
3360 }
3361 sendCloseSystemWindows(SYSTEM_DIALOG_REASON_HOME_KEY);
3362 hideRecentApps(false, true);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003363 } else {
Bryce Lee662ed802015-04-10 20:11:39 +00003364 // Otherwise, just launch Home
3365 sendCloseSystemWindows(SYSTEM_DIALOG_REASON_HOME_KEY);
3366 startDockOrHome(true /*fromHomeKey*/, awakenFromDreams);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003367 }
3368 }
3369
John Spurlock04db1762013-05-13 12:46:41 -04003370 private final Runnable mClearHideNavigationFlag = new Runnable() {
3371 @Override
3372 public void run() {
3373 synchronized (mWindowManagerFuncs.getWindowManagerLock()) {
3374 // Clear flags.
3375 mForceClearedSystemUiFlags &=
3376 ~View.SYSTEM_UI_FLAG_HIDE_NAVIGATION;
3377 }
3378 mWindowManagerFuncs.reevaluateStatusBarVisibility();
Dianne Hackborne26ab702011-10-16 13:21:33 -07003379 }
3380 };
3381
3382 /**
3383 * Input handler used while nav bar is hidden. Captures any touch on the screen,
3384 * to determine when the nav bar should be shown and prevent applications from
3385 * receiving those touches.
3386 */
Jeff Brown32cbc38552011-12-01 14:01:49 -08003387 final class HideNavInputEventReceiver extends InputEventReceiver {
3388 public HideNavInputEventReceiver(InputChannel inputChannel, Looper looper) {
3389 super(inputChannel, looper);
3390 }
3391
Dianne Hackborndf89e652011-10-06 22:35:11 -07003392 @Override
Jeff Brown32cbc38552011-12-01 14:01:49 -08003393 public void onInputEvent(InputEvent event) {
Dianne Hackborndf89e652011-10-06 22:35:11 -07003394 boolean handled = false;
3395 try {
Jeff Brown4952dfd2011-11-30 19:23:22 -08003396 if (event instanceof MotionEvent
3397 && (event.getSource() & InputDevice.SOURCE_CLASS_POINTER) != 0) {
3398 final MotionEvent motionEvent = (MotionEvent)event;
3399 if (motionEvent.getAction() == MotionEvent.ACTION_DOWN) {
Dianne Hackborndf89e652011-10-06 22:35:11 -07003400 // When the user taps down, we re-show the nav bar.
3401 boolean changed = false;
John Spurlock04db1762013-05-13 12:46:41 -04003402 synchronized (mWindowManagerFuncs.getWindowManagerLock()) {
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07003403 // Any user activity always causes us to show the
3404 // navigation controls, if they had been hidden.
3405 // We also clear the low profile and only content
3406 // flags so that tapping on the screen will atomically
3407 // restore all currently hidden screen decorations.
3408 int newVal = mResettingSystemUiFlags |
3409 View.SYSTEM_UI_FLAG_HIDE_NAVIGATION |
3410 View.SYSTEM_UI_FLAG_LOW_PROFILE |
3411 View.SYSTEM_UI_FLAG_FULLSCREEN;
Dianne Hackborne26ab702011-10-16 13:21:33 -07003412 if (mResettingSystemUiFlags != newVal) {
3413 mResettingSystemUiFlags = newVal;
Dianne Hackborndf89e652011-10-06 22:35:11 -07003414 changed = true;
3415 }
Dianne Hackborne26ab702011-10-16 13:21:33 -07003416 // We don't allow the system's nav bar to be hidden
3417 // again for 1 second, to prevent applications from
3418 // spamming us and keeping it from being shown.
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07003419 newVal = mForceClearedSystemUiFlags |
3420 View.SYSTEM_UI_FLAG_HIDE_NAVIGATION;
Dianne Hackborne26ab702011-10-16 13:21:33 -07003421 if (mForceClearedSystemUiFlags != newVal) {
3422 mForceClearedSystemUiFlags = newVal;
3423 changed = true;
John Spurlock04db1762013-05-13 12:46:41 -04003424 mHandler.postDelayed(mClearHideNavigationFlag, 1000);
Dianne Hackborne26ab702011-10-16 13:21:33 -07003425 }
Dianne Hackborndf89e652011-10-06 22:35:11 -07003426 }
3427 if (changed) {
3428 mWindowManagerFuncs.reevaluateStatusBarVisibility();
3429 }
3430 }
3431 }
3432 } finally {
Jeff Brown32cbc38552011-12-01 14:01:49 -08003433 finishInputEvent(event, handled);
Dianne Hackborndf89e652011-10-06 22:35:11 -07003434 }
3435 }
Jeff Brown32cbc38552011-12-01 14:01:49 -08003436 }
3437 final InputEventReceiver.Factory mHideNavInputEventReceiverFactory =
3438 new InputEventReceiver.Factory() {
3439 @Override
3440 public InputEventReceiver createInputEventReceiver(
3441 InputChannel inputChannel, Looper looper) {
3442 return new HideNavInputEventReceiver(inputChannel, looper);
3443 }
Dianne Hackborndf89e652011-10-06 22:35:11 -07003444 };
3445
3446 @Override
3447 public int adjustSystemUiVisibilityLw(int visibility) {
John Spurlock5b9145b2013-08-20 15:13:47 -04003448 mStatusBarController.adjustSystemUiVisibilityLw(mLastSystemUiFlags, visibility);
3449 mNavigationBarController.adjustSystemUiVisibilityLw(mLastSystemUiFlags, visibility);
Winson Chungd42a6cf2014-06-03 16:24:04 -07003450 mRecentsVisible = (visibility & View.RECENT_APPS_VISIBLE) > 0;
John Spurlock27735a42013-08-14 17:57:38 -04003451
Dianne Hackborndf89e652011-10-06 22:35:11 -07003452 // Reset any bits in mForceClearingStatusBarVisibility that
3453 // are now clear.
Dianne Hackborne26ab702011-10-16 13:21:33 -07003454 mResettingSystemUiFlags &= visibility;
Dianne Hackborndf89e652011-10-06 22:35:11 -07003455 // Clear any bits in the new visibility that are currently being
3456 // force cleared, before reporting it.
Dianne Hackborne26ab702011-10-16 13:21:33 -07003457 return visibility & ~mResettingSystemUiFlags
3458 & ~mForceClearedSystemUiFlags;
Dianne Hackborndf89e652011-10-06 22:35:11 -07003459 }
3460
Craig Mautner69b08182012-09-05 13:07:13 -07003461 @Override
Filip Gruszczynski2987f612015-06-30 15:03:30 -07003462 public void getInsetHintLw(WindowManager.LayoutParams attrs, int displayRotation,
3463 Rect outContentInsets, Rect outStableInsets, Rect outOutsets) {
John Spurlockc6d1c602014-01-17 15:22:06 -05003464 final int fl = PolicyControl.getWindowFlags(null, attrs);
John Spurlock1db8b682014-02-18 11:18:59 -05003465 final int sysuiVis = PolicyControl.getSystemUiVisibility(null, attrs);
3466 final int systemUiVisibility = (sysuiVis | attrs.subtreeSystemUiVisibility);
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07003467
Filip Gruszczynski2987f612015-06-30 15:03:30 -07003468 final boolean useOutsets = outOutsets != null && shouldUseOutsets(attrs, fl);
3469 if (useOutsets) {
3470 int outset = ScreenShapeHelper.getWindowOutsetBottomPx(mContext.getResources());
3471 if (outset > 0) {
3472 if (displayRotation == Surface.ROTATION_0) {
3473 outOutsets.bottom += outset;
3474 } else if (displayRotation == Surface.ROTATION_90) {
3475 outOutsets.right += outset;
3476 } else if (displayRotation == Surface.ROTATION_180) {
3477 outOutsets.top += outset;
3478 } else if (displayRotation == Surface.ROTATION_270) {
3479 outOutsets.left += outset;
3480 }
3481 }
3482 }
3483
Dianne Hackborn5b5cc4d2012-05-16 13:15:00 -07003484 if ((fl & (FLAG_LAYOUT_IN_SCREEN | FLAG_LAYOUT_INSET_DECOR))
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003485 == (FLAG_LAYOUT_IN_SCREEN | FLAG_LAYOUT_INSET_DECOR)) {
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07003486 int availRight, availBottom;
Alan Viverette5a0f4ec2013-10-07 15:10:29 -07003487 if (canHideNavigationBar() &&
Dianne Hackborn5b5cc4d2012-05-16 13:15:00 -07003488 (systemUiVisibility & View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION) != 0) {
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07003489 availRight = mUnrestrictedScreenLeft + mUnrestrictedScreenWidth;
3490 availBottom = mUnrestrictedScreenTop + mUnrestrictedScreenHeight;
3491 } else {
3492 availRight = mRestrictedScreenLeft + mRestrictedScreenWidth;
3493 availBottom = mRestrictedScreenTop + mRestrictedScreenHeight;
3494 }
Dianne Hackborn5b5cc4d2012-05-16 13:15:00 -07003495 if ((systemUiVisibility & View.SYSTEM_UI_FLAG_LAYOUT_STABLE) != 0) {
3496 if ((fl & FLAG_FULLSCREEN) != 0) {
Adrian Roos37d7a682014-11-06 18:15:16 +01003497 outContentInsets.set(mStableFullscreenLeft, mStableFullscreenTop,
Dianne Hackborn5b5cc4d2012-05-16 13:15:00 -07003498 availRight - mStableFullscreenRight,
3499 availBottom - mStableFullscreenBottom);
3500 } else {
Adrian Roos37d7a682014-11-06 18:15:16 +01003501 outContentInsets.set(mStableLeft, mStableTop,
Dianne Hackborn5b5cc4d2012-05-16 13:15:00 -07003502 availRight - mStableRight, availBottom - mStableBottom);
3503 }
Dianne Hackbornc652de82013-02-15 16:32:56 -08003504 } else if ((fl & FLAG_FULLSCREEN) != 0 || (fl & FLAG_LAYOUT_IN_OVERSCAN) != 0) {
Adrian Roos37d7a682014-11-06 18:15:16 +01003505 outContentInsets.setEmpty();
Dianne Hackborn5b5cc4d2012-05-16 13:15:00 -07003506 } else if ((systemUiVisibility & (View.SYSTEM_UI_FLAG_FULLSCREEN
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07003507 | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN)) == 0) {
Adrian Roos37d7a682014-11-06 18:15:16 +01003508 outContentInsets.set(mCurLeft, mCurTop,
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07003509 availRight - mCurRight, availBottom - mCurBottom);
3510 } else {
Adrian Roos37d7a682014-11-06 18:15:16 +01003511 outContentInsets.set(mCurLeft, mCurTop,
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07003512 availRight - mCurRight, availBottom - mCurBottom);
3513 }
Adrian Roos37d7a682014-11-06 18:15:16 +01003514
3515 outStableInsets.set(mStableLeft, mStableTop,
3516 availRight - mStableRight, availBottom - mStableBottom);
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07003517 return;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003518 }
Adrian Roos37d7a682014-11-06 18:15:16 +01003519 outContentInsets.setEmpty();
3520 outStableInsets.setEmpty();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003521 }
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07003522
Filip Gruszczynski2987f612015-06-30 15:03:30 -07003523 private boolean shouldUseOutsets(WindowManager.LayoutParams attrs, int fl) {
3524 return attrs.type == TYPE_WALLPAPER || (fl & (WindowManager.LayoutParams.FLAG_FULLSCREEN
3525 | WindowManager.LayoutParams.FLAG_LAYOUT_IN_OVERSCAN)) != 0;
3526 }
3527
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003528 /** {@inheritDoc} */
Craig Mautner69b08182012-09-05 13:07:13 -07003529 @Override
3530 public void beginLayoutLw(boolean isDefaultDisplay, int displayWidth, int displayHeight,
3531 int displayRotation) {
Filip Gruszczynski2987f612015-06-30 15:03:30 -07003532 mDisplayRotation = displayRotation;
Dianne Hackbornc652de82013-02-15 16:32:56 -08003533 final int overscanLeft, overscanTop, overscanRight, overscanBottom;
3534 if (isDefaultDisplay) {
3535 switch (displayRotation) {
3536 case Surface.ROTATION_90:
3537 overscanLeft = mOverscanTop;
3538 overscanTop = mOverscanRight;
3539 overscanRight = mOverscanBottom;
3540 overscanBottom = mOverscanLeft;
3541 break;
3542 case Surface.ROTATION_180:
3543 overscanLeft = mOverscanRight;
3544 overscanTop = mOverscanBottom;
3545 overscanRight = mOverscanLeft;
3546 overscanBottom = mOverscanTop;
3547 break;
3548 case Surface.ROTATION_270:
3549 overscanLeft = mOverscanBottom;
3550 overscanTop = mOverscanLeft;
3551 overscanRight = mOverscanTop;
3552 overscanBottom = mOverscanRight;
3553 break;
3554 default:
3555 overscanLeft = mOverscanLeft;
3556 overscanTop = mOverscanTop;
3557 overscanRight = mOverscanRight;
3558 overscanBottom = mOverscanBottom;
3559 break;
3560 }
3561 } else {
3562 overscanLeft = 0;
3563 overscanTop = 0;
3564 overscanRight = 0;
3565 overscanBottom = 0;
3566 }
Dianne Hackborn313440842013-02-19 19:22:59 -08003567 mOverscanScreenLeft = mRestrictedOverscanScreenLeft = 0;
3568 mOverscanScreenTop = mRestrictedOverscanScreenTop = 0;
3569 mOverscanScreenWidth = mRestrictedOverscanScreenWidth = displayWidth;
3570 mOverscanScreenHeight = mRestrictedOverscanScreenHeight = displayHeight;
Dianne Hackbornc652de82013-02-15 16:32:56 -08003571 mSystemLeft = 0;
3572 mSystemTop = 0;
3573 mSystemRight = displayWidth;
3574 mSystemBottom = displayHeight;
3575 mUnrestrictedScreenLeft = overscanLeft;
3576 mUnrestrictedScreenTop = overscanTop;
3577 mUnrestrictedScreenWidth = displayWidth - overscanLeft - overscanRight;
3578 mUnrestrictedScreenHeight = displayHeight - overscanTop - overscanBottom;
3579 mRestrictedScreenLeft = mUnrestrictedScreenLeft;
3580 mRestrictedScreenTop = mUnrestrictedScreenTop;
John Spurlockad3e6cb2013-04-30 08:47:43 -04003581 mRestrictedScreenWidth = mSystemGestures.screenWidth = mUnrestrictedScreenWidth;
3582 mRestrictedScreenHeight = mSystemGestures.screenHeight = mUnrestrictedScreenHeight;
Dianne Hackborne30e02f2014-05-27 18:24:45 -07003583 mDockLeft = mContentLeft = mVoiceContentLeft = mStableLeft = mStableFullscreenLeft
Dianne Hackbornc652de82013-02-15 16:32:56 -08003584 = mCurLeft = mUnrestrictedScreenLeft;
Dianne Hackborne30e02f2014-05-27 18:24:45 -07003585 mDockTop = mContentTop = mVoiceContentTop = mStableTop = mStableFullscreenTop
Dianne Hackbornc652de82013-02-15 16:32:56 -08003586 = mCurTop = mUnrestrictedScreenTop;
Dianne Hackborne30e02f2014-05-27 18:24:45 -07003587 mDockRight = mContentRight = mVoiceContentRight = mStableRight = mStableFullscreenRight
Dianne Hackbornc652de82013-02-15 16:32:56 -08003588 = mCurRight = displayWidth - overscanRight;
Dianne Hackborne30e02f2014-05-27 18:24:45 -07003589 mDockBottom = mContentBottom = mVoiceContentBottom = mStableBottom = mStableFullscreenBottom
Dianne Hackbornc652de82013-02-15 16:32:56 -08003590 = mCurBottom = displayHeight - overscanBottom;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003591 mDockLayer = 0x10000000;
Dianne Hackborn5c58de32012-04-28 19:52:37 -07003592 mStatusBarLayer = -1;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003593
Daniel Sandler8956dbb2011-04-22 07:55:02 -04003594 // start with the current dock rect, which will be (0,0,displayWidth,displayHeight)
3595 final Rect pf = mTmpParentFrame;
3596 final Rect df = mTmpDisplayFrame;
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003597 final Rect of = mTmpOverscanFrame;
Daniel Sandler8956dbb2011-04-22 07:55:02 -04003598 final Rect vf = mTmpVisibleFrame;
John Spurlock46646232013-09-30 22:32:42 -04003599 final Rect dcf = mTmpDecorFrame;
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003600 pf.left = df.left = of.left = vf.left = mDockLeft;
3601 pf.top = df.top = of.top = vf.top = mDockTop;
3602 pf.right = df.right = of.right = vf.right = mDockRight;
3603 pf.bottom = df.bottom = of.bottom = vf.bottom = mDockBottom;
John Spurlock46646232013-09-30 22:32:42 -04003604 dcf.setEmpty(); // Decor frame N/A for system bars.
Daniel Sandler8956dbb2011-04-22 07:55:02 -04003605
Craig Mautner69b08182012-09-05 13:07:13 -07003606 if (isDefaultDisplay) {
3607 // For purposes of putting out fake window up to steal focus, we will
3608 // drive nav being hidden only by whether it is requested.
John Spurlocke1f366f2013-08-05 12:22:40 -04003609 final int sysui = mLastSystemUiFlags;
3610 boolean navVisible = (sysui & View.SYSTEM_UI_FLAG_HIDE_NAVIGATION) == 0;
Adrian Roosea562512014-05-05 13:33:03 +02003611 boolean navTranslucent = (sysui
3612 & (View.NAVIGATION_BAR_TRANSLUCENT | View.SYSTEM_UI_TRANSPARENT)) != 0;
John Spurlockf1a36642013-10-12 17:50:42 -04003613 boolean immersive = (sysui & View.SYSTEM_UI_FLAG_IMMERSIVE) != 0;
3614 boolean immersiveSticky = (sysui & View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY) != 0;
3615 boolean navAllowedHidden = immersive || immersiveSticky;
3616 navTranslucent &= !immersiveSticky; // transient trumps translucent
Adrian Roos4fb3ee32014-08-22 19:29:09 +02003617 boolean isKeyguardShowing = isStatusBarKeyguard() && !mHideLockScreen;
3618 if (!isKeyguardShowing) {
3619 navTranslucent &= areTranslucentBarsAllowed();
3620 }
Dianne Hackborne26ab702011-10-16 13:21:33 -07003621
Craig Mautner69b08182012-09-05 13:07:13 -07003622 // When the navigation bar isn't visible, we put up a fake
3623 // input window to catch all touch events. This way we can
3624 // detect when the user presses anywhere to bring back the nav
3625 // bar and ensure the application doesn't see the event.
John Spurlockf1a36642013-10-12 17:50:42 -04003626 if (navVisible || navAllowedHidden) {
Selim Cinekf83e8242015-05-19 18:08:14 -07003627 if (mInputConsumer != null) {
3628 mInputConsumer.dismiss();
3629 mInputConsumer = null;
Craig Mautner69b08182012-09-05 13:07:13 -07003630 }
Selim Cinekf83e8242015-05-19 18:08:14 -07003631 } else if (mInputConsumer == null) {
3632 mInputConsumer = mWindowManagerFuncs.addInputConsumer(mHandler.getLooper(),
3633 mHideNavInputEventReceiverFactory);
Dianne Hackborne26ab702011-10-16 13:21:33 -07003634 }
Dianne Hackborne26ab702011-10-16 13:21:33 -07003635
Craig Mautner69b08182012-09-05 13:07:13 -07003636 // For purposes of positioning and showing the nav bar, if we have
3637 // decided that it can't be hidden (because of the screen aspect ratio),
3638 // then take that into account.
Alan Viverette5a0f4ec2013-10-07 15:10:29 -07003639 navVisible |= !canHideNavigationBar();
Dianne Hackbornf87d1962012-04-04 12:48:24 -07003640
Filip Gruszczynski83dd9552015-09-17 17:50:36 -07003641 boolean updateSysUiVisibility = layoutNavigationBar(displayWidth, displayHeight,
3642 displayRotation, overscanRight, overscanBottom, dcf, navVisible, navTranslucent,
3643 navAllowedHidden);
Craig Mautnereda67292013-04-28 13:50:14 -07003644 if (DEBUG_LAYOUT) Slog.i(TAG, String.format("mDock rect: (%d,%d - %d,%d)",
Craig Mautner69b08182012-09-05 13:07:13 -07003645 mDockLeft, mDockTop, mDockRight, mDockBottom));
Filip Gruszczynski83dd9552015-09-17 17:50:36 -07003646 updateSysUiVisibility |= layoutStatusBar(pf, df, of, vf, dcf, sysui, isKeyguardShowing);
John Spurlockad3e6cb2013-04-30 08:47:43 -04003647 if (updateSysUiVisibility) {
3648 updateSystemUiVisibilityLw();
3649 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003650 }
3651 }
3652
Filip Gruszczynski83dd9552015-09-17 17:50:36 -07003653 private boolean layoutStatusBar(Rect pf, Rect df, Rect of, Rect vf, Rect dcf, int sysui,
3654 boolean isKeyguardShowing) {
3655 // decide where the status bar goes ahead of time
3656 if (mStatusBar != null) {
3657 // apply any navigation bar insets
3658 pf.left = df.left = of.left = mUnrestrictedScreenLeft;
3659 pf.top = df.top = of.top = mUnrestrictedScreenTop;
3660 pf.right = df.right = of.right = mUnrestrictedScreenWidth + mUnrestrictedScreenLeft;
3661 pf.bottom = df.bottom = of.bottom = mUnrestrictedScreenHeight
3662 + mUnrestrictedScreenTop;
3663 vf.left = mStableLeft;
3664 vf.top = mStableTop;
3665 vf.right = mStableRight;
3666 vf.bottom = mStableBottom;
3667
3668 mStatusBarLayer = mStatusBar.getSurfaceLayer();
3669
3670 // Let the status bar determine its size.
3671 mStatusBar.computeFrameLw(pf /* parentFrame */, df /* displayFrame */,
3672 vf /* overlayFrame */, vf /* contentFrame */, vf /* visibleFrame */,
3673 dcf /* decorFrame */, vf /* stableFrame */, vf /* outsetFrame */);
3674
3675 // For layout, the status bar is always at the top with our fixed height.
3676 mStableTop = mUnrestrictedScreenTop + mStatusBarHeight;
3677
3678 boolean statusBarTransient = (sysui & View.STATUS_BAR_TRANSIENT) != 0;
3679 boolean statusBarTranslucent = (sysui
3680 & (View.STATUS_BAR_TRANSLUCENT | View.SYSTEM_UI_TRANSPARENT)) != 0;
3681 if (!isKeyguardShowing) {
3682 statusBarTranslucent &= areTranslucentBarsAllowed();
3683 }
3684
3685 // If the status bar is hidden, we don't want to cause
3686 // windows behind it to scroll.
3687 if (mStatusBar.isVisibleLw() && !statusBarTransient) {
3688 // Status bar may go away, so the screen area it occupies
3689 // is available to apps but just covering them when the
3690 // status bar is visible.
3691 mDockTop = mUnrestrictedScreenTop + mStatusBarHeight;
3692
3693 mContentTop = mVoiceContentTop = mCurTop = mDockTop;
3694 mContentBottom = mVoiceContentBottom = mCurBottom = mDockBottom;
3695 mContentLeft = mVoiceContentLeft = mCurLeft = mDockLeft;
3696 mContentRight = mVoiceContentRight = mCurRight = mDockRight;
3697
3698 if (DEBUG_LAYOUT) Slog.v(TAG, "Status bar: " +
3699 String.format(
3700 "dock=[%d,%d][%d,%d] content=[%d,%d][%d,%d] cur=[%d,%d][%d,%d]",
3701 mDockLeft, mDockTop, mDockRight, mDockBottom,
3702 mContentLeft, mContentTop, mContentRight, mContentBottom,
3703 mCurLeft, mCurTop, mCurRight, mCurBottom));
3704 }
3705 if (mStatusBar.isVisibleLw() && !mStatusBar.isAnimatingLw()
3706 && !statusBarTransient && !statusBarTranslucent
3707 && !mStatusBarController.wasRecentlyTranslucent()) {
3708 // If the opaque status bar is currently requested to be visible,
3709 // and not in the process of animating on or off, then
3710 // we can tell the app that it is covered by it.
3711 mSystemTop = mUnrestrictedScreenTop + mStatusBarHeight;
3712 }
3713 if (mStatusBarController.checkHiddenLw()) {
3714 return true;
3715 }
3716 }
3717 return false;
3718 }
3719
3720 private boolean layoutNavigationBar(int displayWidth, int displayHeight, int displayRotation,
3721 int overscanRight, int overscanBottom, Rect dcf, boolean navVisible,
3722 boolean navTranslucent, boolean navAllowedHidden) {
3723 if (mNavigationBar != null) {
3724 boolean transientNavBarShowing = mNavigationBarController.isTransientShowing();
3725 // Force the navigation bar to its appropriate place and
3726 // size. We need to do this directly, instead of relying on
3727 // it to bubble up from the nav bar, because this needs to
3728 // change atomically with screen rotations.
3729 mNavigationBarOnBottom = (!mNavigationBarCanMove || displayWidth < displayHeight);
3730 if (mNavigationBarOnBottom) {
3731 // It's a system nav bar or a portrait screen; nav bar goes on bottom.
3732 int top = displayHeight - overscanBottom
3733 - mNavigationBarHeightForRotation[displayRotation];
3734 mTmpNavigationFrame.set(0, top, displayWidth, displayHeight - overscanBottom);
3735 mStableBottom = mStableFullscreenBottom = mTmpNavigationFrame.top;
3736 if (transientNavBarShowing) {
3737 mNavigationBarController.setBarShowingLw(true);
3738 } else if (navVisible) {
3739 mNavigationBarController.setBarShowingLw(true);
3740 mDockBottom = mTmpNavigationFrame.top;
3741 mRestrictedScreenHeight = mDockBottom - mRestrictedScreenTop;
3742 mRestrictedOverscanScreenHeight = mDockBottom - mRestrictedOverscanScreenTop;
3743 } else {
3744 // We currently want to hide the navigation UI.
3745 mNavigationBarController.setBarShowingLw(false);
3746 }
3747 if (navVisible && !navTranslucent && !navAllowedHidden
3748 && !mNavigationBar.isAnimatingLw()
3749 && !mNavigationBarController.wasRecentlyTranslucent()) {
3750 // If the opaque nav bar is currently requested to be visible,
3751 // and not in the process of animating on or off, then
3752 // we can tell the app that it is covered by it.
3753 mSystemBottom = mTmpNavigationFrame.top;
3754 }
3755 } else {
3756 // Landscape screen; nav bar goes to the right.
3757 int left = displayWidth - overscanRight
3758 - mNavigationBarWidthForRotation[displayRotation];
3759 mTmpNavigationFrame.set(left, 0, displayWidth - overscanRight, displayHeight);
3760 mStableRight = mStableFullscreenRight = mTmpNavigationFrame.left;
3761 if (transientNavBarShowing) {
3762 mNavigationBarController.setBarShowingLw(true);
3763 } else if (navVisible) {
3764 mNavigationBarController.setBarShowingLw(true);
3765 mDockRight = mTmpNavigationFrame.left;
3766 mRestrictedScreenWidth = mDockRight - mRestrictedScreenLeft;
3767 mRestrictedOverscanScreenWidth = mDockRight - mRestrictedOverscanScreenLeft;
3768 } else {
3769 // We currently want to hide the navigation UI.
3770 mNavigationBarController.setBarShowingLw(false);
3771 }
3772 if (navVisible && !navTranslucent && !navAllowedHidden
3773 && !mNavigationBar.isAnimatingLw()
3774 && !mNavigationBarController.wasRecentlyTranslucent()) {
3775 // If the nav bar is currently requested to be visible,
3776 // and not in the process of animating on or off, then
3777 // we can tell the app that it is covered by it.
3778 mSystemRight = mTmpNavigationFrame.left;
3779 }
3780 }
3781 // Make sure the content and current rectangles are updated to
3782 // account for the restrictions from the navigation bar.
3783 mContentTop = mVoiceContentTop = mCurTop = mDockTop;
3784 mContentBottom = mVoiceContentBottom = mCurBottom = mDockBottom;
3785 mContentLeft = mVoiceContentLeft = mCurLeft = mDockLeft;
3786 mContentRight = mVoiceContentRight = mCurRight = mDockRight;
3787 mStatusBarLayer = mNavigationBar.getSurfaceLayer();
3788 // And compute the final frame.
3789 mNavigationBar.computeFrameLw(mTmpNavigationFrame, mTmpNavigationFrame,
3790 mTmpNavigationFrame, mTmpNavigationFrame, mTmpNavigationFrame, dcf,
3791 mTmpNavigationFrame, mTmpNavigationFrame);
3792 if (DEBUG_LAYOUT) Slog.i(TAG, "mNavigationBar frame: " + mTmpNavigationFrame);
3793 if (mNavigationBarController.checkHiddenLw()) {
3794 return true;
3795 }
3796 }
3797 return false;
3798 }
3799
Dianne Hackborn85afd1b2012-05-13 13:31:06 -07003800 /** {@inheritDoc} */
Craig Mautner967212c2013-04-13 21:10:58 -07003801 @Override
John Spurlock46646232013-09-30 22:32:42 -04003802 public int getSystemDecorLayerLw() {
Bryce Lee2ed3e5f2015-04-01 22:09:19 +00003803 if (mStatusBar != null && mStatusBar.isVisibleLw()) {
3804 return mStatusBar.getSurfaceLayer();
3805 }
3806
3807 if (mNavigationBar != null && mNavigationBar.isVisibleLw()) {
3808 return mNavigationBar.getSurfaceLayer();
3809 }
3810
Dianne Hackborn85afd1b2012-05-13 13:31:06 -07003811 return 0;
3812 }
3813
Craig Mautner967212c2013-04-13 21:10:58 -07003814 @Override
3815 public void getContentRectLw(Rect r) {
3816 r.set(mContentLeft, mContentTop, mContentRight, mContentBottom);
3817 }
3818
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003819 void setAttachedWindowFrames(WindowState win, int fl, int adjust, WindowState attached,
3820 boolean insetDecors, Rect pf, Rect df, Rect of, Rect cf, Rect vf) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003821 if (win.getSurfaceLayer() > mDockLayer && attached.getSurfaceLayer() < mDockLayer) {
3822 // Here's a special case: if this attached window is a panel that is
3823 // above the dock window, and the window it is attached to is below
3824 // the dock window, then the frames we computed for the window it is
3825 // attached to can not be used because the dock is effectively part
3826 // of the underlying window and the attached window is floating on top
3827 // of the whole thing. So, we ignore the attached window and explicitly
3828 // compute the frames that would be appropriate without the dock.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003829 df.left = of.left = cf.left = vf.left = mDockLeft;
3830 df.top = of.top = cf.top = vf.top = mDockTop;
3831 df.right = of.right = cf.right = vf.right = mDockRight;
3832 df.bottom = of.bottom = cf.bottom = vf.bottom = mDockBottom;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003833 } else {
3834 // The effective display frame of the attached window depends on
3835 // whether it is taking care of insetting its content. If not,
3836 // we need to use the parent's content frame so that the entire
3837 // window is positioned within that content. Otherwise we can use
Wale Ogunwale393b1c12014-10-18 16:22:01 -07003838 // the overscan frame and let the attached window take care of
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003839 // positioning its content appropriately.
Dianne Hackborndea3ef72010-10-28 14:24:22 -07003840 if (adjust != SOFT_INPUT_ADJUST_RESIZE) {
Wale Ogunwale393b1c12014-10-18 16:22:01 -07003841 // Set the content frame of the attached window to the parent's decor frame
3842 // (same as content frame when IME isn't present) if specifically requested by
3843 // setting {@link WindowManager.LayoutParams#FLAG_LAYOUT_ATTACHED_IN_DECOR} flag.
3844 // Otherwise, use the overscan frame.
3845 cf.set((fl & FLAG_LAYOUT_ATTACHED_IN_DECOR) != 0
3846 ? attached.getContentFrameLw() : attached.getOverscanFrameLw());
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003847 } else {
3848 // If the window is resizing, then we want to base the content
3849 // frame on our attached content frame to resize... however,
3850 // things can be tricky if the attached window is NOT in resize
3851 // mode, in which case its content frame will be larger.
3852 // Ungh. So to deal with that, make sure the content frame
3853 // we end up using is not covering the IM dock.
3854 cf.set(attached.getContentFrameLw());
Dianne Hackborne30e02f2014-05-27 18:24:45 -07003855 if (attached.isVoiceInteraction()) {
3856 if (cf.left < mVoiceContentLeft) cf.left = mVoiceContentLeft;
3857 if (cf.top < mVoiceContentTop) cf.top = mVoiceContentTop;
3858 if (cf.right > mVoiceContentRight) cf.right = mVoiceContentRight;
3859 if (cf.bottom > mVoiceContentBottom) cf.bottom = mVoiceContentBottom;
3860 } else if (attached.getSurfaceLayer() < mDockLayer) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003861 if (cf.left < mContentLeft) cf.left = mContentLeft;
3862 if (cf.top < mContentTop) cf.top = mContentTop;
3863 if (cf.right > mContentRight) cf.right = mContentRight;
3864 if (cf.bottom > mContentBottom) cf.bottom = mContentBottom;
3865 }
3866 }
3867 df.set(insetDecors ? attached.getDisplayFrameLw() : cf);
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003868 of.set(insetDecors ? attached.getOverscanFrameLw() : cf);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003869 vf.set(attached.getVisibleFrameLw());
3870 }
3871 // The LAYOUT_IN_SCREEN flag is used to determine whether the attached
3872 // window should be positioned relative to its parent or the entire
3873 // screen.
3874 pf.set((fl & FLAG_LAYOUT_IN_SCREEN) == 0
3875 ? attached.getFrameLw() : df);
3876 }
Dianne Hackborn5b5cc4d2012-05-16 13:15:00 -07003877
3878 private void applyStableConstraints(int sysui, int fl, Rect r) {
3879 if ((sysui & View.SYSTEM_UI_FLAG_LAYOUT_STABLE) != 0) {
3880 // If app is requesting a stable layout, don't let the
3881 // content insets go below the stable values.
3882 if ((fl & FLAG_FULLSCREEN) != 0) {
3883 if (r.left < mStableFullscreenLeft) r.left = mStableFullscreenLeft;
3884 if (r.top < mStableFullscreenTop) r.top = mStableFullscreenTop;
3885 if (r.right > mStableFullscreenRight) r.right = mStableFullscreenRight;
3886 if (r.bottom > mStableFullscreenBottom) r.bottom = mStableFullscreenBottom;
3887 } else {
3888 if (r.left < mStableLeft) r.left = mStableLeft;
3889 if (r.top < mStableTop) r.top = mStableTop;
3890 if (r.right > mStableRight) r.right = mStableRight;
3891 if (r.bottom > mStableBottom) r.bottom = mStableBottom;
3892 }
3893 }
3894 }
3895
Jorim Jaggiaa806142015-05-20 18:04:16 -07003896 private boolean canReceiveInput(WindowState win) {
3897 boolean notFocusable =
3898 (win.getAttrs().flags & WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE) != 0;
3899 boolean altFocusableIm =
3900 (win.getAttrs().flags & WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM) != 0;
3901 boolean notFocusableForIm = notFocusable ^ altFocusableIm;
3902 return !notFocusableForIm;
3903 }
3904
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003905 /** {@inheritDoc} */
Craig Mautner69b08182012-09-05 13:07:13 -07003906 @Override
Craig Mautnerc9457fa2014-06-06 14:27:48 -07003907 public void layoutWindowLw(WindowState win, WindowState attached) {
Jorim Jaggiaa806142015-05-20 18:04:16 -07003908 // We've already done the navigation bar and status bar. If the status bar can receive
3909 // input, we need to layout it again to accomodate for the IME window.
3910 if ((win == mStatusBar && !canReceiveInput(win)) || win == mNavigationBar) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003911 return;
3912 }
Jorim Jaggiaa806142015-05-20 18:04:16 -07003913 final WindowManager.LayoutParams attrs = win.getAttrs();
Craig Mautner69b08182012-09-05 13:07:13 -07003914 final boolean isDefaultDisplay = win.isDefaultDisplay();
3915 final boolean needsToOffsetInputMethodTarget = isDefaultDisplay &&
satok1bc0a492012-04-25 22:47:12 +09003916 (win == mLastInputMethodTargetWindow && mLastInputMethodWindow != null);
3917 if (needsToOffsetInputMethodTarget) {
Craig Mautnereda67292013-04-28 13:50:14 -07003918 if (DEBUG_LAYOUT) Slog.i(TAG, "Offset ime target window by the last ime window state");
satok1bc0a492012-04-25 22:47:12 +09003919 offsetInputMethodWindowLw(mLastInputMethodWindow);
3920 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003921
John Spurlockc6d1c602014-01-17 15:22:06 -05003922 final int fl = PolicyControl.getWindowFlags(win, attrs);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003923 final int sim = attrs.softInputMode;
John Spurlock1db8b682014-02-18 11:18:59 -05003924 final int sysUiFl = PolicyControl.getSystemUiVisibility(win, null);
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07003925
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003926 final Rect pf = mTmpParentFrame;
3927 final Rect df = mTmpDisplayFrame;
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003928 final Rect of = mTmpOverscanFrame;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003929 final Rect cf = mTmpContentFrame;
3930 final Rect vf = mTmpVisibleFrame;
John Spurlock46646232013-09-30 22:32:42 -04003931 final Rect dcf = mTmpDecorFrame;
Adrian Roosfa104232014-06-20 16:10:14 -07003932 final Rect sf = mTmpStableFrame;
Filip Gruszczynski2217f612015-05-26 11:32:08 -07003933 Rect osf = null;
John Spurlock46646232013-09-30 22:32:42 -04003934 dcf.setEmpty();
Craig Mautner69b08182012-09-05 13:07:13 -07003935
3936 final boolean hasNavBar = (isDefaultDisplay && mHasNavigationBar
Daniel Sandler36412a72011-08-04 09:35:13 -04003937 && mNavigationBar != null && mNavigationBar.isVisibleLw());
Daniel Sandler8956dbb2011-04-22 07:55:02 -04003938
Craig Mautnerf683b562012-10-02 11:10:57 -07003939 final int adjust = sim & SOFT_INPUT_MASK_ADJUST;
3940
Adrian Roosfa104232014-06-20 16:10:14 -07003941 if (isDefaultDisplay) {
3942 sf.set(mStableLeft, mStableTop, mStableRight, mStableBottom);
3943 } else {
3944 sf.set(mOverscanLeft, mOverscanTop, mOverscanRight, mOverscanBottom);
3945 }
3946
Craig Mautner69b08182012-09-05 13:07:13 -07003947 if (!isDefaultDisplay) {
3948 if (attached != null) {
3949 // If this window is attached to another, our display
3950 // frame is the same as the one we are attached to.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003951 setAttachedWindowFrames(win, fl, adjust, attached, true, pf, df, of, cf, vf);
Craig Mautner69b08182012-09-05 13:07:13 -07003952 } else {
3953 // Give the window full screen.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003954 pf.left = df.left = of.left = cf.left = mOverscanScreenLeft;
3955 pf.top = df.top = of.top = cf.top = mOverscanScreenTop;
3956 pf.right = df.right = of.right = cf.right
Dianne Hackbornc652de82013-02-15 16:32:56 -08003957 = mOverscanScreenLeft + mOverscanScreenWidth;
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003958 pf.bottom = df.bottom = of.bottom = cf.bottom
Dianne Hackbornc652de82013-02-15 16:32:56 -08003959 = mOverscanScreenTop + mOverscanScreenHeight;
Craig Mautner69b08182012-09-05 13:07:13 -07003960 }
Jorim Jaggi225d3b52015-04-01 11:18:57 -07003961 } else if (attrs.type == TYPE_INPUT_METHOD) {
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003962 pf.left = df.left = of.left = cf.left = vf.left = mDockLeft;
3963 pf.top = df.top = of.top = cf.top = vf.top = mDockTop;
3964 pf.right = df.right = of.right = cf.right = vf.right = mDockRight;
John Spurlockc68d5772013-10-08 11:47:58 -04003965 // IM dock windows layout below the nav bar...
John Spurlock57beb3b2013-10-10 10:27:44 -04003966 pf.bottom = df.bottom = of.bottom = mUnrestrictedScreenTop + mUnrestrictedScreenHeight;
John Spurlockc68d5772013-10-08 11:47:58 -04003967 // ...with content insets above the nav bar
3968 cf.bottom = vf.bottom = mStableBottom;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003969 // IM dock windows always go to the bottom of the screen.
3970 attrs.gravity = Gravity.BOTTOM;
3971 mDockLayer = win.getSurfaceLayer();
Jorim Jaggi225d3b52015-04-01 11:18:57 -07003972 } else if (attrs.type == TYPE_VOICE_INTERACTION) {
Stefan Kuhne2f280d062015-06-18 07:20:33 -10003973 pf.left = df.left = of.left = mUnrestrictedScreenLeft;
Jorim Jaggi225d3b52015-04-01 11:18:57 -07003974 pf.top = df.top = of.top = mUnrestrictedScreenTop;
Stefan Kuhne2f280d062015-06-18 07:20:33 -10003975 pf.right = df.right = of.right = mUnrestrictedScreenLeft + mUnrestrictedScreenWidth;
3976 pf.bottom = df.bottom = of.bottom = mUnrestrictedScreenTop + mUnrestrictedScreenHeight;
Jorim Jaggi225d3b52015-04-01 11:18:57 -07003977 cf.bottom = vf.bottom = mStableBottom;
Stefan Kuhne2f280d062015-06-18 07:20:33 -10003978 // Note: In Phone landscape mode, the button bar should also be excluded.
3979 cf.right = vf.right = mStableRight;
3980 cf.left = vf.left = mStableLeft;
Jorim Jaggi225d3b52015-04-01 11:18:57 -07003981 cf.top = vf.top = mStableTop;
Jorim Jaggiaa806142015-05-20 18:04:16 -07003982 } else if (win == mStatusBar) {
Jorim Jaggie0700182014-08-21 01:12:37 +02003983 pf.left = df.left = of.left = mUnrestrictedScreenLeft;
3984 pf.top = df.top = of.top = mUnrestrictedScreenTop;
3985 pf.right = df.right = of.right = mUnrestrictedScreenWidth + mUnrestrictedScreenLeft;
3986 pf.bottom = df.bottom = of.bottom = mUnrestrictedScreenHeight + mUnrestrictedScreenTop;
3987 cf.left = vf.left = mStableLeft;
3988 cf.top = vf.top = mStableTop;
3989 cf.right = vf.right = mStableRight;
3990 vf.bottom = mStableBottom;
3991 cf.bottom = mContentBottom;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003992 } else {
John Spurlock46646232013-09-30 22:32:42 -04003993
3994 // Default policy decor for the default display
3995 dcf.left = mSystemLeft;
3996 dcf.top = mSystemTop;
3997 dcf.right = mSystemRight;
3998 dcf.bottom = mSystemBottom;
John Spurlockbd957402013-10-03 11:38:39 -04003999 final boolean inheritTranslucentDecor = (attrs.privateFlags
4000 & WindowManager.LayoutParams.PRIVATE_FLAG_INHERIT_TRANSLUCENT_DECOR) != 0;
John Spurlock65567d42013-10-08 10:08:32 -04004001 final boolean isAppWindow =
4002 attrs.type >= WindowManager.LayoutParams.FIRST_APPLICATION_WINDOW &&
4003 attrs.type <= WindowManager.LayoutParams.LAST_APPLICATION_WINDOW;
4004 final boolean topAtRest =
4005 win == mTopFullscreenOpaqueWindowState && !win.isAnimatingLw();
4006 if (isAppWindow && !inheritTranslucentDecor && !topAtRest) {
John Spurlockbd957402013-10-03 11:38:39 -04004007 if ((sysUiFl & View.SYSTEM_UI_FLAG_FULLSCREEN) == 0
4008 && (fl & WindowManager.LayoutParams.FLAG_FULLSCREEN) == 0
Adrian Roosea562512014-05-05 13:33:03 +02004009 && (fl & WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS) == 0
4010 && (fl & WindowManager.LayoutParams.
4011 FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS) == 0) {
John Spurlock46646232013-09-30 22:32:42 -04004012 // Ensure policy decor includes status bar
4013 dcf.top = mStableTop;
4014 }
John Spurlockbd957402013-10-03 11:38:39 -04004015 if ((fl & WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION) == 0
Adrian Roosea562512014-05-05 13:33:03 +02004016 && (sysUiFl & View.SYSTEM_UI_FLAG_HIDE_NAVIGATION) == 0
4017 && (fl & WindowManager.LayoutParams.
4018 FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS) == 0) {
John Spurlock46646232013-09-30 22:32:42 -04004019 // Ensure policy decor includes navigation bar
4020 dcf.bottom = mStableBottom;
4021 dcf.right = mStableRight;
4022 }
4023 }
4024
Dianne Hackbornc4aad012013-02-22 15:05:25 -08004025 if ((fl & (FLAG_LAYOUT_IN_SCREEN | FLAG_LAYOUT_INSET_DECOR))
4026 == (FLAG_LAYOUT_IN_SCREEN | FLAG_LAYOUT_INSET_DECOR)) {
RoboErik8a2cfc32014-05-16 11:19:38 -07004027 if (DEBUG_LAYOUT) Slog.v(TAG, "layoutWindowLw(" + attrs.getTitle()
Dianne Hackbornc4aad012013-02-22 15:05:25 -08004028 + "): IN_SCREEN, INSET_DECOR");
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004029 // This is the case for a normal activity window: we want it
4030 // to cover all of the screen space, and it can take care of
4031 // moving its contents to account for screen decorations that
4032 // intrude into that space.
4033 if (attached != null) {
4034 // If this window is attached to another, our display
4035 // frame is the same as the one we are attached to.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08004036 setAttachedWindowFrames(win, fl, adjust, attached, true, pf, df, of, cf, vf);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004037 } else {
Daniel Sandler8956dbb2011-04-22 07:55:02 -04004038 if (attrs.type == TYPE_STATUS_BAR_PANEL
4039 || attrs.type == TYPE_STATUS_BAR_SUB_PANEL) {
Joe Onorato29fc2c92010-11-24 10:26:50 -08004040 // Status bar panels are the only windows who can go on top of
4041 // the status bar. They are protected by the STATUS_BAR_SERVICE
4042 // permission, so they have the same privileges as the status
4043 // bar itself.
Daniel Sandler8956dbb2011-04-22 07:55:02 -04004044 //
Daniel Sandler8e8b4152011-07-21 01:16:43 -04004045 // However, they should still dodge the navigation bar if it exists.
Daniel Sandler8956dbb2011-04-22 07:55:02 -04004046
Dianne Hackbornc4aad012013-02-22 15:05:25 -08004047 pf.left = df.left = of.left = hasNavBar
4048 ? mDockLeft : mUnrestrictedScreenLeft;
4049 pf.top = df.top = of.top = mUnrestrictedScreenTop;
4050 pf.right = df.right = of.right = hasNavBar
4051 ? mRestrictedScreenLeft+mRestrictedScreenWidth
4052 : mUnrestrictedScreenLeft + mUnrestrictedScreenWidth;
4053 pf.bottom = df.bottom = of.bottom = hasNavBar
4054 ? mRestrictedScreenTop+mRestrictedScreenHeight
4055 : mUnrestrictedScreenTop + mUnrestrictedScreenHeight;
Daniel Sandler8956dbb2011-04-22 07:55:02 -04004056
Craig Mautnereda67292013-04-28 13:50:14 -07004057 if (DEBUG_LAYOUT) Slog.v(TAG, String.format(
Daniel Sandler8e8b4152011-07-21 01:16:43 -04004058 "Laying out status bar window: (%d,%d - %d,%d)",
4059 pf.left, pf.top, pf.right, pf.bottom));
John Spurlock46646232013-09-30 22:32:42 -04004060 } else if ((fl & FLAG_LAYOUT_IN_OVERSCAN) != 0
Dianne Hackbornc652de82013-02-15 16:32:56 -08004061 && attrs.type >= WindowManager.LayoutParams.FIRST_APPLICATION_WINDOW
4062 && attrs.type <= WindowManager.LayoutParams.LAST_SUB_WINDOW) {
4063 // Asking to layout into the overscan region, so give it that pure
4064 // unrestricted area.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08004065 pf.left = df.left = of.left = mOverscanScreenLeft;
4066 pf.top = df.top = of.top = mOverscanScreenTop;
4067 pf.right = df.right = of.right = mOverscanScreenLeft + mOverscanScreenWidth;
4068 pf.bottom = df.bottom = of.bottom = mOverscanScreenTop
4069 + mOverscanScreenHeight;
Alan Viverette5a0f4ec2013-10-07 15:10:29 -07004070 } else if (canHideNavigationBar()
Dianne Hackbornf87d1962012-04-04 12:48:24 -07004071 && (sysUiFl & View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION) != 0
Jorim Jaggi380ecb82014-03-14 17:25:20 +01004072 && attrs.type >= WindowManager.LayoutParams.FIRST_APPLICATION_WINDOW
4073 && attrs.type <= WindowManager.LayoutParams.LAST_SUB_WINDOW) {
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07004074 // Asking for layout as if the nav bar is hidden, lets the
Dianne Hackbornc652de82013-02-15 16:32:56 -08004075 // application extend into the unrestricted overscan screen area. We
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07004076 // only do this for application windows to ensure no window that
4077 // can be above the nav bar can do this.
Dianne Hackborn313440842013-02-19 19:22:59 -08004078 pf.left = df.left = mOverscanScreenLeft;
4079 pf.top = df.top = mOverscanScreenTop;
4080 pf.right = df.right = mOverscanScreenLeft + mOverscanScreenWidth;
4081 pf.bottom = df.bottom = mOverscanScreenTop + mOverscanScreenHeight;
Dianne Hackbornc4aad012013-02-22 15:05:25 -08004082 // We need to tell the app about where the frame inside the overscan
4083 // is, so it can inset its content by that amount -- it didn't ask
4084 // to actually extend itself into the overscan region.
4085 of.left = mUnrestrictedScreenLeft;
4086 of.top = mUnrestrictedScreenTop;
4087 of.right = mUnrestrictedScreenLeft + mUnrestrictedScreenWidth;
4088 of.bottom = mUnrestrictedScreenTop + mUnrestrictedScreenHeight;
Joe Onorato29fc2c92010-11-24 10:26:50 -08004089 } else {
Dianne Hackborn313440842013-02-19 19:22:59 -08004090 pf.left = df.left = mRestrictedOverscanScreenLeft;
4091 pf.top = df.top = mRestrictedOverscanScreenTop;
4092 pf.right = df.right = mRestrictedOverscanScreenLeft
4093 + mRestrictedOverscanScreenWidth;
4094 pf.bottom = df.bottom = mRestrictedOverscanScreenTop
4095 + mRestrictedOverscanScreenHeight;
Dianne Hackbornc4aad012013-02-22 15:05:25 -08004096 // We need to tell the app about where the frame inside the overscan
4097 // is, so it can inset its content by that amount -- it didn't ask
4098 // to actually extend itself into the overscan region.
4099 of.left = mUnrestrictedScreenLeft;
4100 of.top = mUnrestrictedScreenTop;
4101 of.right = mUnrestrictedScreenLeft + mUnrestrictedScreenWidth;
4102 of.bottom = mUnrestrictedScreenTop + mUnrestrictedScreenHeight;
Joe Onorato29fc2c92010-11-24 10:26:50 -08004103 }
Craig Mautner69b08182012-09-05 13:07:13 -07004104
John Spurlock46646232013-09-30 22:32:42 -04004105 if ((fl & FLAG_FULLSCREEN) == 0) {
Dianne Hackborne30e02f2014-05-27 18:24:45 -07004106 if (win.isVoiceInteraction()) {
4107 cf.left = mVoiceContentLeft;
4108 cf.top = mVoiceContentTop;
4109 cf.right = mVoiceContentRight;
4110 cf.bottom = mVoiceContentBottom;
Dianne Hackbornc4aad012013-02-22 15:05:25 -08004111 } else {
Dianne Hackborne30e02f2014-05-27 18:24:45 -07004112 if (adjust != SOFT_INPUT_ADJUST_RESIZE) {
4113 cf.left = mDockLeft;
4114 cf.top = mDockTop;
4115 cf.right = mDockRight;
4116 cf.bottom = mDockBottom;
4117 } else {
4118 cf.left = mContentLeft;
4119 cf.top = mContentTop;
4120 cf.right = mContentRight;
4121 cf.bottom = mContentBottom;
4122 }
Dianne Hackbornc4aad012013-02-22 15:05:25 -08004123 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004124 } else {
Dianne Hackbornc4aad012013-02-22 15:05:25 -08004125 // Full screen windows are always given a layout that is as if the
4126 // status bar and other transient decors are gone. This is to avoid
4127 // bad states when moving from a window that is not hding the
4128 // status bar to one that is.
4129 cf.left = mRestrictedScreenLeft;
4130 cf.top = mRestrictedScreenTop;
4131 cf.right = mRestrictedScreenLeft + mRestrictedScreenWidth;
4132 cf.bottom = mRestrictedScreenTop + mRestrictedScreenHeight;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004133 }
Dianne Hackborn5b5cc4d2012-05-16 13:15:00 -07004134 applyStableConstraints(sysUiFl, fl, cf);
Dianne Hackborndea3ef72010-10-28 14:24:22 -07004135 if (adjust != SOFT_INPUT_ADJUST_NOTHING) {
4136 vf.left = mCurLeft;
4137 vf.top = mCurTop;
4138 vf.right = mCurRight;
4139 vf.bottom = mCurBottom;
4140 } else {
4141 vf.set(cf);
4142 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004143 }
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07004144 } else if ((fl & FLAG_LAYOUT_IN_SCREEN) != 0 || (sysUiFl
4145 & (View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
4146 | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION)) != 0) {
Craig Mautnereda67292013-04-28 13:50:14 -07004147 if (DEBUG_LAYOUT) Slog.v(TAG, "layoutWindowLw(" + attrs.getTitle() +
4148 "): IN_SCREEN");
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004149 // A window that has requested to fill the entire screen just
4150 // gets everything, period.
Daniel Sandler8956dbb2011-04-22 07:55:02 -04004151 if (attrs.type == TYPE_STATUS_BAR_PANEL
John Spurlock67a0f852015-06-15 15:35:47 -04004152 || attrs.type == TYPE_STATUS_BAR_SUB_PANEL
4153 || attrs.type == TYPE_VOLUME_OVERLAY) {
Dianne Hackbornc4aad012013-02-22 15:05:25 -08004154 pf.left = df.left = of.left = cf.left = hasNavBar
4155 ? mDockLeft : mUnrestrictedScreenLeft;
4156 pf.top = df.top = of.top = cf.top = mUnrestrictedScreenTop;
4157 pf.right = df.right = of.right = cf.right = hasNavBar
Daniel Sandler8e8b4152011-07-21 01:16:43 -04004158 ? mRestrictedScreenLeft+mRestrictedScreenWidth
Dianne Hackbornc652de82013-02-15 16:32:56 -08004159 : mUnrestrictedScreenLeft + mUnrestrictedScreenWidth;
Dianne Hackbornc4aad012013-02-22 15:05:25 -08004160 pf.bottom = df.bottom = of.bottom = cf.bottom = hasNavBar
Daniel Sandler8e8b4152011-07-21 01:16:43 -04004161 ? mRestrictedScreenTop+mRestrictedScreenHeight
Dianne Hackbornc652de82013-02-15 16:32:56 -08004162 : mUnrestrictedScreenTop + mUnrestrictedScreenHeight;
Craig Mautnereda67292013-04-28 13:50:14 -07004163 if (DEBUG_LAYOUT) Slog.v(TAG, String.format(
Daniel Sandler36412a72011-08-04 09:35:13 -04004164 "Laying out IN_SCREEN status bar window: (%d,%d - %d,%d)",
4165 pf.left, pf.top, pf.right, pf.bottom));
Jim Millere898ac52012-04-06 17:10:57 -07004166 } else if (attrs.type == TYPE_NAVIGATION_BAR
4167 || attrs.type == TYPE_NAVIGATION_BAR_PANEL) {
Daniel Sandler8e8b4152011-07-21 01:16:43 -04004168 // The navigation bar has Real Ultimate Power.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08004169 pf.left = df.left = of.left = mUnrestrictedScreenLeft;
4170 pf.top = df.top = of.top = mUnrestrictedScreenTop;
4171 pf.right = df.right = of.right = mUnrestrictedScreenLeft
4172 + mUnrestrictedScreenWidth;
4173 pf.bottom = df.bottom = of.bottom = mUnrestrictedScreenTop
4174 + mUnrestrictedScreenHeight;
Craig Mautnereda67292013-04-28 13:50:14 -07004175 if (DEBUG_LAYOUT) Slog.v(TAG, String.format(
Daniel Sandler8e8b4152011-07-21 01:16:43 -04004176 "Laying out navigation bar window: (%d,%d - %d,%d)",
4177 pf.left, pf.top, pf.right, pf.bottom));
Dianne Hackborn01011c32012-02-21 13:54:21 -08004178 } else if ((attrs.type == TYPE_SECURE_SYSTEM_OVERLAY
4179 || attrs.type == TYPE_BOOT_PROGRESS)
Jeff Brownbfcb60a2011-09-08 18:51:14 -07004180 && ((fl & FLAG_FULLSCREEN) != 0)) {
4181 // Fullscreen secure system overlays get what they ask for.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08004182 pf.left = df.left = of.left = cf.left = mOverscanScreenLeft;
4183 pf.top = df.top = of.top = cf.top = mOverscanScreenTop;
4184 pf.right = df.right = of.right = cf.right = mOverscanScreenLeft
4185 + mOverscanScreenWidth;
4186 pf.bottom = df.bottom = of.bottom = cf.bottom = mOverscanScreenTop
4187 + mOverscanScreenHeight;
Craig Mautner165be0c2015-01-27 15:16:58 -08004188 } else if (attrs.type == TYPE_BOOT_PROGRESS) {
Dianne Hackborn01011c32012-02-21 13:54:21 -08004189 // Boot progress screen always covers entire display.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08004190 pf.left = df.left = of.left = cf.left = mOverscanScreenLeft;
4191 pf.top = df.top = of.top = cf.top = mOverscanScreenTop;
4192 pf.right = df.right = of.right = cf.right = mOverscanScreenLeft
4193 + mOverscanScreenWidth;
4194 pf.bottom = df.bottom = of.bottom = cf.bottom = mOverscanScreenTop
4195 + mOverscanScreenHeight;
John Spurlockef4adae2013-08-26 17:58:58 -04004196 } else if (attrs.type == TYPE_WALLPAPER) {
Dianne Hackborn067e5f62014-09-07 23:14:30 -07004197 // The wallpaper also has Real Ultimate Power, but we want to tell
4198 // it about the overscan area.
4199 pf.left = df.left = mOverscanScreenLeft;
4200 pf.top = df.top = mOverscanScreenTop;
4201 pf.right = df.right = mOverscanScreenLeft + mOverscanScreenWidth;
4202 pf.bottom = df.bottom = mOverscanScreenTop + mOverscanScreenHeight;
4203 of.left = cf.left = mUnrestrictedScreenLeft;
4204 of.top = cf.top = mUnrestrictedScreenTop;
4205 of.right = cf.right = mUnrestrictedScreenLeft + mUnrestrictedScreenWidth;
4206 of.bottom = cf.bottom = mUnrestrictedScreenTop + mUnrestrictedScreenHeight;
John Spurlock46646232013-09-30 22:32:42 -04004207 } else if ((fl & FLAG_LAYOUT_IN_OVERSCAN) != 0
Dianne Hackbornc652de82013-02-15 16:32:56 -08004208 && attrs.type >= WindowManager.LayoutParams.FIRST_APPLICATION_WINDOW
4209 && attrs.type <= WindowManager.LayoutParams.LAST_SUB_WINDOW) {
4210 // Asking to layout into the overscan region, so give it that pure
4211 // unrestricted area.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08004212 pf.left = df.left = of.left = cf.left = mOverscanScreenLeft;
4213 pf.top = df.top = of.top = cf.top = mOverscanScreenTop;
4214 pf.right = df.right = of.right = cf.right
Dianne Hackbornc652de82013-02-15 16:32:56 -08004215 = mOverscanScreenLeft + mOverscanScreenWidth;
Dianne Hackbornc4aad012013-02-22 15:05:25 -08004216 pf.bottom = df.bottom = of.bottom = cf.bottom
Dianne Hackbornc652de82013-02-15 16:32:56 -08004217 = mOverscanScreenTop + mOverscanScreenHeight;
Alan Viverette5a0f4ec2013-10-07 15:10:29 -07004218 } else if (canHideNavigationBar()
Dianne Hackbornf87d1962012-04-04 12:48:24 -07004219 && (sysUiFl & View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION) != 0
Craig Mautnerbeac1062014-06-03 14:38:57 -07004220 && (attrs.type == TYPE_STATUS_BAR
4221 || attrs.type == TYPE_TOAST
Jorim Jaggi2fdeeab2015-04-01 15:13:03 -07004222 || attrs.type == TYPE_VOICE_INTERACTION_STARTING
John Spurlock34e13d92013-08-10 06:52:28 -04004223 || (attrs.type >= WindowManager.LayoutParams.FIRST_APPLICATION_WINDOW
4224 && attrs.type <= WindowManager.LayoutParams.LAST_SUB_WINDOW))) {
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07004225 // Asking for layout as if the nav bar is hidden, lets the
4226 // application extend into the unrestricted screen area. We
John Spurlock34e13d92013-08-10 06:52:28 -04004227 // only do this for application windows (or toasts) to ensure no window that
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07004228 // can be above the nav bar can do this.
4229 // XXX This assumes that an app asking for this will also
4230 // ask for layout in only content. We can't currently figure out
4231 // what the screen would be if only laying out to hide the nav bar.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08004232 pf.left = df.left = of.left = cf.left = mUnrestrictedScreenLeft;
4233 pf.top = df.top = of.top = cf.top = mUnrestrictedScreenTop;
4234 pf.right = df.right = of.right = cf.right = mUnrestrictedScreenLeft
4235 + mUnrestrictedScreenWidth;
4236 pf.bottom = df.bottom = of.bottom = cf.bottom = mUnrestrictedScreenTop
4237 + mUnrestrictedScreenHeight;
Joe Onorato29fc2c92010-11-24 10:26:50 -08004238 } else {
Dianne Hackbornc4aad012013-02-22 15:05:25 -08004239 pf.left = df.left = of.left = cf.left = mRestrictedScreenLeft;
4240 pf.top = df.top = of.top = cf.top = mRestrictedScreenTop;
4241 pf.right = df.right = of.right = cf.right = mRestrictedScreenLeft
4242 + mRestrictedScreenWidth;
4243 pf.bottom = df.bottom = of.bottom = cf.bottom = mRestrictedScreenTop
4244 + mRestrictedScreenHeight;
Joe Onorato29fc2c92010-11-24 10:26:50 -08004245 }
Craig Mautner69b08182012-09-05 13:07:13 -07004246
Dianne Hackborn5b5cc4d2012-05-16 13:15:00 -07004247 applyStableConstraints(sysUiFl, fl, cf);
Craig Mautner69b08182012-09-05 13:07:13 -07004248
Dianne Hackborndea3ef72010-10-28 14:24:22 -07004249 if (adjust != SOFT_INPUT_ADJUST_NOTHING) {
4250 vf.left = mCurLeft;
4251 vf.top = mCurTop;
4252 vf.right = mCurRight;
4253 vf.bottom = mCurBottom;
4254 } else {
4255 vf.set(cf);
4256 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004257 } else if (attached != null) {
Craig Mautnereda67292013-04-28 13:50:14 -07004258 if (DEBUG_LAYOUT) Slog.v(TAG, "layoutWindowLw(" + attrs.getTitle() +
4259 "): attached to " + attached);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004260 // A child window should be placed inside of the same visible
4261 // frame that its parent had.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08004262 setAttachedWindowFrames(win, fl, adjust, attached, false, pf, df, of, cf, vf);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004263 } else {
Craig Mautnereda67292013-04-28 13:50:14 -07004264 if (DEBUG_LAYOUT) Slog.v(TAG, "layoutWindowLw(" + attrs.getTitle() +
4265 "): normal window");
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004266 // Otherwise, a normal window must be placed inside the content
4267 // of all screen decorations.
John Spurlock67a0f852015-06-15 15:35:47 -04004268 if (attrs.type == TYPE_STATUS_BAR_PANEL || attrs.type == TYPE_VOLUME_OVERLAY) {
4269 // Status bar panels and the volume dialog are the only windows who can go on
4270 // top of the status bar. They are protected by the STATUS_BAR_SERVICE
Dianne Hackborna239c842011-06-01 12:28:20 -07004271 // permission, so they have the same privileges as the status
4272 // bar itself.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08004273 pf.left = df.left = of.left = cf.left = mRestrictedScreenLeft;
4274 pf.top = df.top = of.top = cf.top = mRestrictedScreenTop;
4275 pf.right = df.right = of.right = cf.right = mRestrictedScreenLeft
4276 + mRestrictedScreenWidth;
4277 pf.bottom = df.bottom = of.bottom = cf.bottom = mRestrictedScreenTop
4278 + mRestrictedScreenHeight;
John Spurlock67a0f852015-06-15 15:35:47 -04004279 } else if (attrs.type == TYPE_TOAST || attrs.type == TYPE_SYSTEM_ALERT) {
John Spurlock414c1f02013-12-04 13:47:36 -05004280 // These dialogs are stable to interim decor changes.
John Spurlockbd957402013-10-03 11:38:39 -04004281 pf.left = df.left = of.left = cf.left = mStableLeft;
4282 pf.top = df.top = of.top = cf.top = mStableTop;
4283 pf.right = df.right = of.right = cf.right = mStableRight;
4284 pf.bottom = df.bottom = of.bottom = cf.bottom = mStableBottom;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004285 } else {
Dianne Hackborna239c842011-06-01 12:28:20 -07004286 pf.left = mContentLeft;
4287 pf.top = mContentTop;
4288 pf.right = mContentRight;
4289 pf.bottom = mContentBottom;
Dianne Hackborn20d94742014-05-29 18:35:45 -07004290 if (win.isVoiceInteraction()) {
4291 df.left = of.left = cf.left = mVoiceContentLeft;
4292 df.top = of.top = cf.top = mVoiceContentTop;
4293 df.right = of.right = cf.right = mVoiceContentRight;
4294 df.bottom = of.bottom = cf.bottom = mVoiceContentBottom;
4295 } else if (adjust != SOFT_INPUT_ADJUST_RESIZE) {
Dianne Hackbornc4aad012013-02-22 15:05:25 -08004296 df.left = of.left = cf.left = mDockLeft;
4297 df.top = of.top = cf.top = mDockTop;
4298 df.right = of.right = cf.right = mDockRight;
4299 df.bottom = of.bottom = cf.bottom = mDockBottom;
Dianne Hackborna239c842011-06-01 12:28:20 -07004300 } else {
Dianne Hackbornc4aad012013-02-22 15:05:25 -08004301 df.left = of.left = cf.left = mContentLeft;
4302 df.top = of.top = cf.top = mContentTop;
4303 df.right = of.right = cf.right = mContentRight;
4304 df.bottom = of.bottom = cf.bottom = mContentBottom;
Dianne Hackborna239c842011-06-01 12:28:20 -07004305 }
4306 if (adjust != SOFT_INPUT_ADJUST_NOTHING) {
4307 vf.left = mCurLeft;
4308 vf.top = mCurTop;
4309 vf.right = mCurRight;
4310 vf.bottom = mCurBottom;
4311 } else {
4312 vf.set(cf);
4313 }
Dianne Hackborndea3ef72010-10-28 14:24:22 -07004314 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004315 }
4316 }
Craig Mautner69b08182012-09-05 13:07:13 -07004317
Craig Mautnerb816bed2013-07-23 10:26:17 -07004318 // TYPE_SYSTEM_ERROR is above the NavigationBar so it can't be allowed to extend over it.
4319 if ((fl & FLAG_LAYOUT_NO_LIMITS) != 0 && attrs.type != TYPE_SYSTEM_ERROR) {
Dianne Hackborn067e5f62014-09-07 23:14:30 -07004320 df.left = df.top = -10000;
4321 df.right = df.bottom = 10000;
4322 if (attrs.type != TYPE_WALLPAPER) {
4323 of.left = of.top = cf.left = cf.top = vf.left = vf.top = -10000;
4324 of.right = of.bottom = cf.right = cf.bottom = vf.right = vf.bottom = 10000;
4325 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004326 }
4327
Filip Gruszczynski2217f612015-05-26 11:32:08 -07004328 // If the device has a chin (e.g. some watches), a dead area at the bottom of the screen we
4329 // need to provide information to the clients that want to pretend that you can draw there.
Filip Gruszczynskib0c673b2015-06-05 09:43:06 -07004330 // We only want to apply outsets to certain types of windows. For example, we never want to
4331 // apply the outsets to floating dialogs, because they wouldn't make sense there.
Filip Gruszczynski2987f612015-06-30 15:03:30 -07004332 final boolean useOutsets = shouldUseOutsets(attrs, fl);
Filip Gruszczynskib0c673b2015-06-05 09:43:06 -07004333 if (isDefaultDisplay && useOutsets) {
Filip Gruszczynski2217f612015-05-26 11:32:08 -07004334 osf = mTmpOutsetFrame;
4335 osf.set(cf.left, cf.top, cf.right, cf.bottom);
4336 int outset = ScreenShapeHelper.getWindowOutsetBottomPx(mContext.getResources());
4337 if (outset > 0) {
Filip Gruszczynski2987f612015-06-30 15:03:30 -07004338 int rotation = mDisplayRotation;
Filip Gruszczynski2217f612015-05-26 11:32:08 -07004339 if (rotation == Surface.ROTATION_0) {
4340 osf.bottom += outset;
4341 } else if (rotation == Surface.ROTATION_90) {
4342 osf.right += outset;
4343 } else if (rotation == Surface.ROTATION_180) {
4344 osf.top -= outset;
4345 } else if (rotation == Surface.ROTATION_270) {
4346 osf.left -= outset;
4347 }
4348 if (DEBUG_LAYOUT) Slog.v(TAG, "applying bottom outset of " + outset
4349 + " with rotation " + rotation + ", result: " + osf);
4350 }
4351 }
4352
Craig Mautnereda67292013-04-28 13:50:14 -07004353 if (DEBUG_LAYOUT) Slog.v(TAG, "Compute frame " + attrs.getTitle()
The Android Open Source Project11267662009-03-18 17:39:47 -07004354 + ": sim=#" + Integer.toHexString(sim)
RoboErik8a2cfc32014-05-16 11:19:38 -07004355 + " attach=" + attached + " type=" + attrs.type
Daniel Sandler8956dbb2011-04-22 07:55:02 -04004356 + String.format(" flags=0x%08x", fl)
The Android Open Source Project11267662009-03-18 17:39:47 -07004357 + " pf=" + pf.toShortString() + " df=" + df.toShortString()
Dianne Hackbornc4aad012013-02-22 15:05:25 -08004358 + " of=" + of.toShortString()
John Spurlock46646232013-09-30 22:32:42 -04004359 + " cf=" + cf.toShortString() + " vf=" + vf.toShortString()
Adrian Roosfa104232014-06-20 16:10:14 -07004360 + " dcf=" + dcf.toShortString()
Filip Gruszczynski2217f612015-05-26 11:32:08 -07004361 + " sf=" + sf.toShortString()
4362 + " osf=" + (osf == null ? "null" : osf.toShortString()));
Craig Mautner69b08182012-09-05 13:07:13 -07004363
Filip Gruszczynski2217f612015-05-26 11:32:08 -07004364 win.computeFrameLw(pf, df, of, cf, vf, dcf, sf, osf);
Craig Mautner69b08182012-09-05 13:07:13 -07004365
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004366 // Dock windows carve out the bottom of the screen, so normal windows
4367 // can't appear underneath them.
Craig Mautner8bd206b2012-10-03 10:32:02 -07004368 if (attrs.type == TYPE_INPUT_METHOD && win.isVisibleOrBehindKeyguardLw()
4369 && !win.getGivenInsetsPendingLw()) {
satok1bc0a492012-04-25 22:47:12 +09004370 setLastInputMethodWindowLw(null, null);
4371 offsetInputMethodWindowLw(win);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004372 }
Dianne Hackborne30e02f2014-05-27 18:24:45 -07004373 if (attrs.type == TYPE_VOICE_INTERACTION && win.isVisibleOrBehindKeyguardLw()
4374 && !win.getGivenInsetsPendingLw()) {
4375 offsetVoiceInputWindowLw(win);
4376 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004377 }
4378
satok1bc0a492012-04-25 22:47:12 +09004379 private void offsetInputMethodWindowLw(WindowState win) {
Craig Mautner4774f6a2015-03-23 11:42:55 -07004380 int top = Math.max(win.getDisplayFrameLw().top, win.getContentFrameLw().top);
satok1bc0a492012-04-25 22:47:12 +09004381 top += win.getGivenContentInsetsLw().top;
4382 if (mContentBottom > top) {
4383 mContentBottom = top;
4384 }
Dianne Hackborne30e02f2014-05-27 18:24:45 -07004385 if (mVoiceContentBottom > top) {
4386 mVoiceContentBottom = top;
4387 }
satok1bc0a492012-04-25 22:47:12 +09004388 top = win.getVisibleFrameLw().top;
4389 top += win.getGivenVisibleInsetsLw().top;
4390 if (mCurBottom > top) {
4391 mCurBottom = top;
4392 }
Craig Mautnereda67292013-04-28 13:50:14 -07004393 if (DEBUG_LAYOUT) Slog.v(TAG, "Input method: mDockBottom="
satok1bc0a492012-04-25 22:47:12 +09004394 + mDockBottom + " mContentBottom="
4395 + mContentBottom + " mCurBottom=" + mCurBottom);
4396 }
4397
Dianne Hackborne30e02f2014-05-27 18:24:45 -07004398 private void offsetVoiceInputWindowLw(WindowState win) {
Craig Mautner4774f6a2015-03-23 11:42:55 -07004399 int top = Math.max(win.getDisplayFrameLw().top, win.getContentFrameLw().top);
Dianne Hackbornae6688b2015-02-11 17:02:41 -08004400 top += win.getGivenContentInsetsLw().top;
4401 if (mVoiceContentBottom > top) {
4402 mVoiceContentBottom = top;
Dianne Hackborne30e02f2014-05-27 18:24:45 -07004403 }
4404 }
4405
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004406 /** {@inheritDoc} */
Craig Mautner61ac6bb2012-02-02 17:29:33 -08004407 @Override
4408 public void finishLayoutLw() {
4409 return;
Dianne Hackborn5f3063e2010-03-10 16:01:58 -08004410 }
4411
4412 /** {@inheritDoc} */
Craig Mautnerad09bcc2012-10-08 13:33:11 -07004413 @Override
Craig Mautner39834192012-09-02 07:47:24 -07004414 public void beginPostLayoutPolicyLw(int displayWidth, int displayHeight) {
Dianne Hackborn5f3063e2010-03-10 16:01:58 -08004415 mTopFullscreenOpaqueWindowState = null;
Adrian Rooscd3884d2015-02-18 17:25:23 +01004416 mTopFullscreenOpaqueOrDimmingWindowState = null;
Craig Mautner2bc789b2014-03-19 19:48:38 -07004417 mAppsToBeHidden.clear();
Jorim Jaggic13fcac2014-09-11 17:36:57 +02004418 mAppsThatDismissKeyguard.clear();
Dianne Hackborn5f3063e2010-03-10 16:01:58 -08004419 mForceStatusBar = false;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07004420 mForceStatusBarFromKeyguard = false;
Selim Cinek4a4a2bddc2015-05-07 12:50:19 -07004421 mForceStatusBarTransparent = false;
Dianne Hackborn891d3fb2013-01-09 18:31:37 -08004422 mForcingShowNavBar = false;
4423 mForcingShowNavBarLayer = -1;
RoboErik8a2cfc32014-05-16 11:19:38 -07004424
Dianne Hackborn5f3063e2010-03-10 16:01:58 -08004425 mHideLockScreen = false;
4426 mAllowLockscreenWhenOn = false;
Craig Mautnerad09bcc2012-10-08 13:33:11 -07004427 mDismissKeyguard = DISMISS_KEYGUARD_NONE;
Dianne Hackborn7ad44382012-10-18 17:46:00 -07004428 mShowingLockscreen = false;
4429 mShowingDream = false;
Craig Mautnerc9457fa2014-06-06 14:27:48 -07004430 mWinShowWhenLocked = null;
Jim Millerab954542014-10-10 18:21:49 -07004431 mKeyguardSecure = isKeyguardSecure();
4432 mKeyguardSecureIncludingHidden = mKeyguardSecure
4433 && (mKeyguardDelegate != null && mKeyguardDelegate.isShowing());
Dianne Hackborn5f3063e2010-03-10 16:01:58 -08004434 }
4435
4436 /** {@inheritDoc} */
Craig Mautnerad09bcc2012-10-08 13:33:11 -07004437 @Override
Yohei Yukawad1a09222015-06-30 16:22:05 -07004438 public void applyPostLayoutPolicyLw(WindowState win, WindowManager.LayoutParams attrs,
4439 WindowState attached) {
Dianne Hackbornbc1aa7b2011-09-20 11:20:31 -07004440 if (DEBUG_LAYOUT) Slog.i(TAG, "Win " + win + ": isVisibleOrBehindKeyguardLw="
4441 + win.isVisibleOrBehindKeyguardLw());
John Spurlockc6d1c602014-01-17 15:22:06 -05004442 final int fl = PolicyControl.getWindowFlags(win, attrs);
John Spurlock414c1f02013-12-04 13:47:36 -05004443 if (mTopFullscreenOpaqueWindowState == null
4444 && win.isVisibleLw() && attrs.type == TYPE_INPUT_METHOD) {
4445 mForcingShowNavBar = true;
4446 mForcingShowNavBarLayer = win.getSurfaceLayer();
Dianne Hackborn891d3fb2013-01-09 18:31:37 -08004447 }
Selim Cinek4a4a2bddc2015-05-07 12:50:19 -07004448 if (attrs.type == TYPE_STATUS_BAR) {
4449 if ((attrs.privateFlags & PRIVATE_FLAG_KEYGUARD) != 0) {
4450 mForceStatusBarFromKeyguard = true;
Jorim Jaggie1de9f62015-09-23 14:59:50 -07004451 mShowingLockscreen = true;
Selim Cinek4a4a2bddc2015-05-07 12:50:19 -07004452 }
4453 if ((attrs.privateFlags & PRIVATE_FLAG_FORCE_STATUS_BAR_VISIBLE_TRANSPARENT) != 0) {
4454 mForceStatusBarTransparent = true;
4455 }
Jorim Jaggiafd4a552014-04-08 15:13:05 +02004456 }
Adrian Roos602c68e2015-04-24 16:03:47 -07004457
4458 boolean appWindow = attrs.type >= FIRST_APPLICATION_WINDOW
4459 && attrs.type < FIRST_SYSTEM_WINDOW;
4460 final boolean showWhenLocked = (fl & FLAG_SHOW_WHEN_LOCKED) != 0;
4461 final boolean dismissKeyguard = (fl & FLAG_DISMISS_KEYGUARD) != 0;
4462
Dianne Hackborn5f3063e2010-03-10 16:01:58 -08004463 if (mTopFullscreenOpaqueWindowState == null &&
Dianne Hackborn01b02a72012-01-12 14:05:03 -08004464 win.isVisibleOrBehindKeyguardLw() && !win.isGoneForLayoutLw()) {
John Spurlockc6d1c602014-01-17 15:22:06 -05004465 if ((fl & FLAG_FORCE_NOT_FULLSCREEN) != 0) {
Jorim Jaggi380ecb82014-03-14 17:25:20 +01004466 if ((attrs.privateFlags & PRIVATE_FLAG_KEYGUARD) != 0) {
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07004467 mForceStatusBarFromKeyguard = true;
4468 } else {
4469 mForceStatusBar = true;
4470 }
4471 }
Dianne Hackborn7ad44382012-10-18 17:46:00 -07004472 if (attrs.type == TYPE_DREAM) {
Jeff Brownc8018eb2012-10-29 21:33:27 -07004473 // If the lockscreen was showing when the dream started then wait
4474 // for the dream to draw before hiding the lockscreen.
4475 if (!mDreamingLockscreen
4476 || (win.isVisibleLw() && win.hasDrawnLw())) {
4477 mShowingDream = true;
Craig Mautnerab55e522014-03-03 13:26:03 -08004478 appWindow = true;
Dianne Hackborn7ad44382012-10-18 17:46:00 -07004479 }
4480 }
Craig Mautnerab55e522014-03-03 13:26:03 -08004481
Yohei Yukawad1a09222015-06-30 16:22:05 -07004482 final IApplicationToken appToken = win.getAppToken();
4483
4484 // For app windows that are not attached, we decide if all windows in the app they
4485 // represent should be hidden or if we should hide the lockscreen. For attached app
4486 // windows we defer the decision to the window it is attached to.
4487 if (appWindow && attached == null) {
Jorim Jaggic13fcac2014-09-11 17:36:57 +02004488 if (showWhenLocked) {
Craig Mautnerc9457fa2014-06-06 14:27:48 -07004489 // Remove any previous windows with the same appToken.
Jorim Jaggic13fcac2014-09-11 17:36:57 +02004490 mAppsToBeHidden.remove(appToken);
4491 mAppsThatDismissKeyguard.remove(appToken);
Craig Mautnerca0a1242014-12-02 12:25:14 -08004492 if (mAppsToBeHidden.isEmpty()) {
Craig Mautner192d6042014-12-02 23:24:48 -08004493 if (dismissKeyguard && !mKeyguardSecure) {
4494 mAppsThatDismissKeyguard.add(appToken);
Selim Cinek90b5e072015-08-28 17:05:56 -07004495 } else if (win.isDrawnLw() || win.hasAppShownWindows()) {
Craig Mautnerca0a1242014-12-02 12:25:14 -08004496 mWinShowWhenLocked = win;
4497 mHideLockScreen = true;
4498 mForceStatusBarFromKeyguard = false;
Craig Mautnerca0a1242014-12-02 12:25:14 -08004499 }
Craig Mautnerc9457fa2014-06-06 14:27:48 -07004500 }
Jorim Jaggic13fcac2014-09-11 17:36:57 +02004501 } else if (dismissKeyguard) {
Jim Millerab954542014-10-10 18:21:49 -07004502 if (mKeyguardSecure) {
Jorim Jaggic13fcac2014-09-11 17:36:57 +02004503 mAppsToBeHidden.add(appToken);
4504 } else {
4505 mAppsToBeHidden.remove(appToken);
4506 }
4507 mAppsThatDismissKeyguard.add(appToken);
Craig Mautner2bc789b2014-03-19 19:48:38 -07004508 } else {
Jorim Jaggic13fcac2014-09-11 17:36:57 +02004509 mAppsToBeHidden.add(appToken);
Craig Mautner2bc789b2014-03-19 19:48:38 -07004510 }
Craig Mautnerab55e522014-03-03 13:26:03 -08004511 if (attrs.x == 0 && attrs.y == 0
4512 && attrs.width == WindowManager.LayoutParams.MATCH_PARENT
4513 && attrs.height == WindowManager.LayoutParams.MATCH_PARENT) {
4514 if (DEBUG_LAYOUT) Slog.v(TAG, "Fullscreen window: " + win);
4515 mTopFullscreenOpaqueWindowState = win;
Adrian Rooscd3884d2015-02-18 17:25:23 +01004516 if (mTopFullscreenOpaqueOrDimmingWindowState == null) {
4517 mTopFullscreenOpaqueOrDimmingWindowState = win;
4518 }
Jorim Jaggic13fcac2014-09-11 17:36:57 +02004519 if (!mAppsThatDismissKeyguard.isEmpty() &&
4520 mDismissKeyguard == DISMISS_KEYGUARD_NONE) {
4521 if (DEBUG_LAYOUT) Slog.v(TAG,
4522 "Setting mDismissKeyguard true by win " + win);
tingna_sunge785ffa2015-05-12 13:23:15 +08004523 mDismissKeyguard = (mWinDismissingKeyguard == win
4524 && mSecureDismissingKeyguard == mKeyguardSecure)
4525 ? DISMISS_KEYGUARD_CONTINUE : DISMISS_KEYGUARD_START;
Jorim Jaggic13fcac2014-09-11 17:36:57 +02004526 mWinDismissingKeyguard = win;
tingna_sunge785ffa2015-05-12 13:23:15 +08004527 mSecureDismissingKeyguard = mKeyguardSecure;
Jim Millerab954542014-10-10 18:21:49 -07004528 mForceStatusBarFromKeyguard = mShowingLockscreen && mKeyguardSecure;
Selim Cinek90b5e072015-08-28 17:05:56 -07004529 } else if (mAppsToBeHidden.isEmpty() && showWhenLocked
4530 && (win.isDrawnLw() || win.hasAppShownWindows())) {
Jorim Jaggic13fcac2014-09-11 17:36:57 +02004531 if (DEBUG_LAYOUT) Slog.v(TAG,
4532 "Setting mHideLockScreen to true by win " + win);
4533 mHideLockScreen = true;
4534 mForceStatusBarFromKeyguard = false;
Craig Mautnerab55e522014-03-03 13:26:03 -08004535 }
Craig Mautner00156ec2014-03-06 22:29:02 -08004536 if ((fl & FLAG_ALLOW_LOCK_WHILE_SCREEN_ON) != 0) {
Craig Mautnerab55e522014-03-03 13:26:03 -08004537 mAllowLockscreenWhenOn = true;
4538 }
Dianne Hackborn5f3063e2010-03-10 16:01:58 -08004539 }
Craig Mautnerc9457fa2014-06-06 14:27:48 -07004540
4541 if (mWinShowWhenLocked != null &&
Adrian Roos602c68e2015-04-24 16:03:47 -07004542 mWinShowWhenLocked.getAppToken() != win.getAppToken() &&
4543 (attrs.flags & FLAG_SHOW_WHEN_LOCKED) == 0) {
Craig Mautnerc9457fa2014-06-06 14:27:48 -07004544 win.hideLw(false);
4545 }
Dianne Hackborn5f3063e2010-03-10 16:01:58 -08004546 }
Adrian Roos602c68e2015-04-24 16:03:47 -07004547 } else if (mTopFullscreenOpaqueWindowState == null && mWinShowWhenLocked == null) {
4548 // No TopFullscreenOpaqueWindow is showing, but we found a SHOW_WHEN_LOCKED window
4549 // that is being hidden in an animation - keep the
4550 // keyguard hidden until the new window shows up and
4551 // we know whether to show the keyguard or not.
Adrian Roosb85e1ec2015-05-29 15:23:18 -07004552 if (win.isAnimatingLw() && appWindow && showWhenLocked && mKeyguardHidden) {
Adrian Roos602c68e2015-04-24 16:03:47 -07004553 mHideLockScreen = true;
4554 mWinShowWhenLocked = win;
4555 }
Dianne Hackborn5f3063e2010-03-10 16:01:58 -08004556 }
Adrian Rooscd3884d2015-02-18 17:25:23 +01004557 if (mTopFullscreenOpaqueOrDimmingWindowState == null
4558 && win.isVisibleOrBehindKeyguardLw() && !win.isGoneForLayoutLw()
4559 && win.isDimming()) {
4560 mTopFullscreenOpaqueOrDimmingWindowState = win;
4561 }
Dianne Hackborn5f3063e2010-03-10 16:01:58 -08004562 }
4563
4564 /** {@inheritDoc} */
Craig Mautnerad09bcc2012-10-08 13:33:11 -07004565 @Override
Craig Mautner39834192012-09-02 07:47:24 -07004566 public int finishPostLayoutPolicyLw() {
Craig Mautnerc5e73bf2015-04-21 15:41:26 +00004567 if (mWinShowWhenLocked != null && mTopFullscreenOpaqueWindowState != null &&
4568 mWinShowWhenLocked.getAppToken() != mTopFullscreenOpaqueWindowState.getAppToken()
4569 && isKeyguardLocked()) {
Craig Mautnerc9457fa2014-06-06 14:27:48 -07004570 // A dialog is dismissing the keyguard. Put the wallpaper behind it and hide the
4571 // fullscreen window.
4572 // TODO: Make sure FLAG_SHOW_WALLPAPER is restored when dialog is dismissed. Or not.
4573 mWinShowWhenLocked.getAttrs().flags |= FLAG_SHOW_WALLPAPER;
4574 mTopFullscreenOpaqueWindowState.hideLw(false);
4575 mTopFullscreenOpaqueWindowState = mWinShowWhenLocked;
4576 }
4577
Dianne Hackborn39c2d712009-09-22 11:41:31 -07004578 int changes = 0;
Joe Onorato93056472010-09-10 10:30:46 -04004579 boolean topIsFullscreen = false;
Daniel Sandlere02d8082010-10-08 15:13:22 -04004580
4581 final WindowManager.LayoutParams lp = (mTopFullscreenOpaqueWindowState != null)
4582 ? mTopFullscreenOpaqueWindowState.getAttrs()
4583 : null;
4584
Jeff Brownc8018eb2012-10-29 21:33:27 -07004585 // If we are not currently showing a dream then remember the current
4586 // lockscreen state. We will use this to determine whether the dream
4587 // started while the lockscreen was showing and remember this state
4588 // while the dream is showing.
Dianne Hackborn7ad44382012-10-18 17:46:00 -07004589 if (!mShowingDream) {
4590 mDreamingLockscreen = mShowingLockscreen;
Jeff Brown061ea992015-04-17 19:55:47 -07004591 if (mDreamingSleepTokenNeeded) {
4592 mDreamingSleepTokenNeeded = false;
4593 mHandler.obtainMessage(MSG_UPDATE_DREAMING_SLEEP_TOKEN, 0, 1).sendToTarget();
4594 }
4595 } else {
4596 if (!mDreamingSleepTokenNeeded) {
4597 mDreamingSleepTokenNeeded = true;
4598 mHandler.obtainMessage(MSG_UPDATE_DREAMING_SLEEP_TOKEN, 1, 1).sendToTarget();
4599 }
Dianne Hackborn7ad44382012-10-18 17:46:00 -07004600 }
4601
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004602 if (mStatusBar != null) {
Craig Mautnereda67292013-04-28 13:50:14 -07004603 if (DEBUG_LAYOUT) Slog.i(TAG, "force=" + mForceStatusBar
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07004604 + " forcefkg=" + mForceStatusBarFromKeyguard
Dianne Hackbornd70bc2f2009-10-06 23:25:51 -07004605 + " top=" + mTopFullscreenOpaqueWindowState);
Selim Cinek4a4a2bddc2015-05-07 12:50:19 -07004606 boolean shouldBeTransparent = mForceStatusBarTransparent
4607 && !mForceStatusBar
4608 && !mForceStatusBarFromKeyguard;
4609 if (!shouldBeTransparent) {
4610 mStatusBarController.setShowTransparent(false /* transparent */);
4611 } else if (!mStatusBar.isVisibleLw()) {
4612 mStatusBarController.setShowTransparent(true /* transparent */);
4613 }
4614 if (mForceStatusBar || mForceStatusBarFromKeyguard || mForceStatusBarTransparent) {
Craig Mautnereda67292013-04-28 13:50:14 -07004615 if (DEBUG_LAYOUT) Slog.v(TAG, "Showing status bar: forced");
John Spurlock27735a42013-08-14 17:57:38 -04004616 if (mStatusBarController.setBarShowingLw(true)) {
4617 changes |= FINISH_LAYOUT_REDO_LAYOUT;
4618 }
Craig Mautner81defc72013-10-29 11:10:42 -07004619 // Maintain fullscreen layout until incoming animation is complete.
4620 topIsFullscreen = mTopIsFullscreen && mStatusBar.isAnimatingLw();
John Spurlockf92b6162013-11-11 15:01:16 -05004621 // Transient status bar on the lockscreen is not allowed
4622 if (mForceStatusBarFromKeyguard && mStatusBarController.isTransientShowing()) {
4623 mStatusBarController.updateVisibilityLw(false /*transientAllowed*/,
4624 mLastSystemUiFlags, mLastSystemUiFlags);
4625 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004626 } else if (mTopFullscreenOpaqueWindowState != null) {
John Spurlockc6d1c602014-01-17 15:22:06 -05004627 final int fl = PolicyControl.getWindowFlags(null, lp);
Joe Onorato93056472010-09-10 10:30:46 -04004628 if (localLOGV) {
Craig Mautnereda67292013-04-28 13:50:14 -07004629 Slog.d(TAG, "frame: " + mTopFullscreenOpaqueWindowState.getFrameLw()
Filip Gruszczynski2a6a2c22015-10-14 12:00:53 -07004630 + " shown position: "
4631 + mTopFullscreenOpaqueWindowState.getShownPositionLw());
Craig Mautnereda67292013-04-28 13:50:14 -07004632 Slog.d(TAG, "attr: " + mTopFullscreenOpaqueWindowState.getAttrs()
John Spurlockc6d1c602014-01-17 15:22:06 -05004633 + " lp.flags=0x" + Integer.toHexString(fl));
Joe Onorato93056472010-09-10 10:30:46 -04004634 }
John Spurlockc6d1c602014-01-17 15:22:06 -05004635 topIsFullscreen = (fl & WindowManager.LayoutParams.FLAG_FULLSCREEN) != 0
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07004636 || (mLastSystemUiFlags & View.SYSTEM_UI_FLAG_FULLSCREEN) != 0;
Joe Onorato93056472010-09-10 10:30:46 -04004637 // The subtle difference between the window for mTopFullscreenOpaqueWindowState
Mark Dolinerd0646dc2014-08-27 16:04:02 -07004638 // and mTopIsFullscreen is that mTopIsFullscreen is set only if the window
Joe Onorato93056472010-09-10 10:30:46 -04004639 // has the FLAG_FULLSCREEN set. Not sure if there is another way that to be the
4640 // case though.
John Spurlock27735a42013-08-14 17:57:38 -04004641 if (mStatusBarController.isTransientShowing()) {
4642 if (mStatusBarController.setBarShowingLw(true)) {
John Spurlock32beb2c2013-03-11 10:16:47 -04004643 changes |= FINISH_LAYOUT_REDO_LAYOUT;
4644 }
Wale Ogunwale6e94a9e2015-10-07 15:35:49 -07004645 } else if (topIsFullscreen
4646 && !mWindowManagerInternal.isStackVisible(FREEFORM_WORKSPACE_STACK_ID)
4647 && !mWindowManagerInternal.isStackVisible(DOCKED_STACK_ID)) {
Craig Mautnereda67292013-04-28 13:50:14 -07004648 if (DEBUG_LAYOUT) Slog.v(TAG, "** HIDING status bar");
John Spurlock27735a42013-08-14 17:57:38 -04004649 if (mStatusBarController.setBarShowingLw(false)) {
Dianne Hackbornf87d1962012-04-04 12:48:24 -07004650 changes |= FINISH_LAYOUT_REDO_LAYOUT;
Craig Mautnereda67292013-04-28 13:50:14 -07004651 } else {
Craig Mautnerc5a6e442013-06-05 17:22:35 -07004652 if (DEBUG_LAYOUT) Slog.v(TAG, "Status bar already hiding");
Daniel Sandler40427442010-07-16 11:44:52 -04004653 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004654 } else {
Craig Mautnereda67292013-04-28 13:50:14 -07004655 if (DEBUG_LAYOUT) Slog.v(TAG, "** SHOWING status bar: top is not fullscreen");
John Spurlock27735a42013-08-14 17:57:38 -04004656 if (mStatusBarController.setBarShowingLw(true)) {
4657 changes |= FINISH_LAYOUT_REDO_LAYOUT;
4658 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004659 }
4660 }
4661 }
Daniel Sandlere02d8082010-10-08 15:13:22 -04004662
Craig Mautner81defc72013-10-29 11:10:42 -07004663 if (mTopIsFullscreen != topIsFullscreen) {
4664 if (!topIsFullscreen) {
4665 // Force another layout when status bar becomes fully shown.
4666 changes |= FINISH_LAYOUT_REDO_LAYOUT;
4667 }
4668 mTopIsFullscreen = topIsFullscreen;
4669 }
Daniel Sandlere02d8082010-10-08 15:13:22 -04004670
Craig Mautner39834192012-09-02 07:47:24 -07004671 // Hide the key guard if a visible window explicitly specifies that it wants to be
4672 // displayed when the screen is locked.
Jorim Jaggi5cf17872014-03-26 18:31:48 +01004673 if (mKeyguardDelegate != null && mStatusBar != null) {
4674 if (localLOGV) Slog.v(TAG, "finishPostLayoutPolicyLw: mHideKeyguard="
4675 + mHideLockScreen);
Jim Millerab954542014-10-10 18:21:49 -07004676 if (mDismissKeyguard != DISMISS_KEYGUARD_NONE && !mKeyguardSecure) {
Jorim Jaggi5cf17872014-03-26 18:31:48 +01004677 mKeyguardHidden = true;
Jim Millerab954542014-10-10 18:21:49 -07004678 if (setKeyguardOccludedLw(true)) {
Dianne Hackborn39c2d712009-09-22 11:41:31 -07004679 changes |= FINISH_LAYOUT_REDO_LAYOUT
4680 | FINISH_LAYOUT_REDO_CONFIG
4681 | FINISH_LAYOUT_REDO_WALLPAPER;
4682 }
Jorim Jaggi5cf17872014-03-26 18:31:48 +01004683 if (mKeyguardDelegate.isShowing()) {
4684 mHandler.post(new Runnable() {
4685 @Override
4686 public void run() {
4687 mKeyguardDelegate.keyguardDone(false, false);
4688 }
4689 });
4690 }
4691 } else if (mHideLockScreen) {
4692 mKeyguardHidden = true;
Jorim Jaggi7d85ea92015-05-20 17:20:40 -07004693 mWinDismissingKeyguard = null;
Jim Millerab954542014-10-10 18:21:49 -07004694 if (setKeyguardOccludedLw(true)) {
Jorim Jaggi5cf17872014-03-26 18:31:48 +01004695 changes |= FINISH_LAYOUT_REDO_LAYOUT
4696 | FINISH_LAYOUT_REDO_CONFIG
4697 | FINISH_LAYOUT_REDO_WALLPAPER;
4698 }
4699 } else if (mDismissKeyguard != DISMISS_KEYGUARD_NONE) {
Jorim Jaggi7d85ea92015-05-20 17:20:40 -07004700 mKeyguardHidden = false;
4701 if (setKeyguardOccludedLw(false)) {
4702 changes |= FINISH_LAYOUT_REDO_LAYOUT
4703 | FINISH_LAYOUT_REDO_CONFIG
4704 | FINISH_LAYOUT_REDO_WALLPAPER;
4705 }
Jorim Jaggi5cf17872014-03-26 18:31:48 +01004706 if (mDismissKeyguard == DISMISS_KEYGUARD_START) {
4707 // Only launch the next keyguard unlock window once per window.
Jorim Jaggi5cf17872014-03-26 18:31:48 +01004708 mHandler.post(new Runnable() {
4709 @Override
4710 public void run() {
4711 mKeyguardDelegate.dismiss();
4712 }
4713 });
4714 }
4715 } else {
4716 mWinDismissingKeyguard = null;
tingna_sunge785ffa2015-05-12 13:23:15 +08004717 mSecureDismissingKeyguard = false;
Jorim Jaggi5cf17872014-03-26 18:31:48 +01004718 mKeyguardHidden = false;
Jim Millerab954542014-10-10 18:21:49 -07004719 if (setKeyguardOccludedLw(false)) {
Jorim Jaggi5cf17872014-03-26 18:31:48 +01004720 changes |= FINISH_LAYOUT_REDO_LAYOUT
4721 | FINISH_LAYOUT_REDO_CONFIG
4722 | FINISH_LAYOUT_REDO_WALLPAPER;
4723 }
Suchi Amalapurapu9cdc9032009-05-14 18:01:07 -07004724 }
4725 }
Joe Onorato664644d2011-01-23 17:53:23 -08004726
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07004727 if ((updateSystemUiVisibilityLw()&SYSTEM_UI_CHANGING_LAYOUT) != 0) {
Dianne Hackborndf89e652011-10-06 22:35:11 -07004728 // If the navigation bar has been hidden or shown, we need to do another
4729 // layout pass to update that window.
4730 changes |= FINISH_LAYOUT_REDO_LAYOUT;
4731 }
Joe Onorato664644d2011-01-23 17:53:23 -08004732
Mike Lockwood28569302010-01-28 11:54:40 -05004733 // update since mAllowLockscreenWhenOn might have changed
4734 updateLockScreenTimeout();
Dianne Hackborn39c2d712009-09-22 11:41:31 -07004735 return changes;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004736 }
4737
Jorim Jaggi380ecb82014-03-14 17:25:20 +01004738 /**
Jim Millerab954542014-10-10 18:21:49 -07004739 * Updates the occluded state of the Keyguard.
Jorim Jaggi380ecb82014-03-14 17:25:20 +01004740 *
Jorim Jaggi380ecb82014-03-14 17:25:20 +01004741 * @return Whether the flags have changed and we have to redo the layout.
4742 */
Jim Millerab954542014-10-10 18:21:49 -07004743 private boolean setKeyguardOccludedLw(boolean isOccluded) {
4744 boolean wasOccluded = mKeyguardOccluded;
4745 boolean showing = mKeyguardDelegate.isShowing();
4746 if (wasOccluded && !isOccluded && showing) {
4747 mKeyguardOccluded = false;
4748 mKeyguardDelegate.setOccluded(false);
Jorim Jaggi380ecb82014-03-14 17:25:20 +01004749 mStatusBar.getAttrs().privateFlags |= PRIVATE_FLAG_KEYGUARD;
4750 mStatusBar.getAttrs().flags |= FLAG_SHOW_WALLPAPER;
4751 return true;
Jim Millerab954542014-10-10 18:21:49 -07004752 } else if (!wasOccluded && isOccluded && showing) {
4753 mKeyguardOccluded = true;
4754 mKeyguardDelegate.setOccluded(true);
Jorim Jaggi380ecb82014-03-14 17:25:20 +01004755 mStatusBar.getAttrs().privateFlags &= ~PRIVATE_FLAG_KEYGUARD;
4756 mStatusBar.getAttrs().flags &= ~FLAG_SHOW_WALLPAPER;
4757 return true;
4758 } else {
4759 return false;
4760 }
4761 }
4762
4763 private boolean isStatusBarKeyguard() {
4764 return mStatusBar != null
4765 && (mStatusBar.getAttrs().privateFlags & PRIVATE_FLAG_KEYGUARD) != 0;
4766 }
4767
Jose Lima9546b202014-07-02 17:21:51 -07004768 @Override
Dianne Hackborn08743722009-12-21 12:16:51 -08004769 public boolean allowAppAnimationsLw() {
Jorim Jaggi380ecb82014-03-14 17:25:20 +01004770 if (isStatusBarKeyguard() || mShowingDream) {
Craig Mautner28816302013-10-10 20:31:00 -07004771 // If keyguard or dreams is currently visible, no reason to animate behind it.
Dianne Hackborn08743722009-12-21 12:16:51 -08004772 return false;
4773 }
Dianne Hackborn08743722009-12-21 12:16:51 -08004774 return true;
4775 }
4776
Jose Lima9546b202014-07-02 17:21:51 -07004777 @Override
Dianne Hackborndf89e652011-10-06 22:35:11 -07004778 public int focusChangedLw(WindowState lastFocus, WindowState newFocus) {
Joe Onorato664644d2011-01-23 17:53:23 -08004779 mFocusedWindow = newFocus;
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07004780 if ((updateSystemUiVisibilityLw()&SYSTEM_UI_CHANGING_LAYOUT) != 0) {
Dianne Hackborndf89e652011-10-06 22:35:11 -07004781 // If the navigation bar has been hidden or shown, we need to do another
4782 // layout pass to update that window.
4783 return FINISH_LAYOUT_REDO_LAYOUT;
4784 }
4785 return 0;
Joe Onorato664644d2011-01-23 17:53:23 -08004786 }
4787
Dianne Hackborn0ecadf72009-03-31 18:00:37 -07004788 /** {@inheritDoc} */
Jose Lima9546b202014-07-02 17:21:51 -07004789 @Override
Jeff Brown46b9ac02010-04-22 18:58:52 -07004790 public void notifyLidSwitchChanged(long whenNanos, boolean lidOpen) {
4791 // lid changed state
Jeff Brownc458ce92012-04-30 14:58:40 -07004792 final int newLidState = lidOpen ? LID_OPEN : LID_CLOSED;
4793 if (newLidState == mLidState) {
4794 return;
4795 }
Jeff Brown01a98dd2011-09-20 15:08:29 -07004796
Jeff Brownc458ce92012-04-30 14:58:40 -07004797 mLidState = newLidState;
4798 applyLidSwitchState();
Jeff Brown01a98dd2011-09-20 15:08:29 -07004799 updateRotation(true);
Jeff Brownc458ce92012-04-30 14:58:40 -07004800
4801 if (lidOpen) {
Dianne Hackborn280a64e2015-07-13 14:48:08 -07004802 wakeUp(SystemClock.uptimeMillis(), mAllowTheaterModeWakeFromLidSwitch,
4803 "android.policy:LID");
Jeff Brownc458ce92012-04-30 14:58:40 -07004804 } else if (!mLidControlsSleep) {
Jeff Brown96307042012-07-27 15:51:34 -07004805 mPowerManager.userActivity(SystemClock.uptimeMillis(), false);
Jeff Brown46b9ac02010-04-22 18:58:52 -07004806 }
4807 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004808
Michael Wright3818c922014-09-02 13:59:07 -07004809 @Override
4810 public void notifyCameraLensCoverSwitchChanged(long whenNanos, boolean lensCovered) {
4811 int lensCoverState = lensCovered ? CAMERA_LENS_COVERED : CAMERA_LENS_UNCOVERED;
4812 if (mCameraLensCoverState == lensCoverState) {
4813 return;
4814 }
4815 if (mCameraLensCoverState == CAMERA_LENS_COVERED &&
4816 lensCoverState == CAMERA_LENS_UNCOVERED) {
4817 Intent intent;
4818 final boolean keyguardActive = mKeyguardDelegate == null ? false :
4819 mKeyguardDelegate.isShowing();
4820 if (keyguardActive) {
4821 intent = new Intent(MediaStore.INTENT_ACTION_STILL_IMAGE_CAMERA_SECURE);
4822 } else {
4823 intent = new Intent(MediaStore.INTENT_ACTION_STILL_IMAGE_CAMERA);
4824 }
Dianne Hackborn280a64e2015-07-13 14:48:08 -07004825 wakeUp(whenNanos / 1000000, mAllowTheaterModeWakeFromCameraLens,
4826 "android.policy:CAMERA_COVER");
Bart Sears8b1c27c2015-03-18 23:51:02 +00004827 startActivityAsUser(intent, UserHandle.CURRENT_OR_SELF);
Michael Wright3818c922014-09-02 13:59:07 -07004828 }
4829 mCameraLensCoverState = lensCoverState;
4830 }
4831
Dianne Hackbornad7fa7f2011-01-07 14:06:50 -08004832 void setHdmiPlugged(boolean plugged) {
4833 if (mHdmiPlugged != plugged) {
4834 mHdmiPlugged = plugged;
Dianne Hackbornf87d1962012-04-04 12:48:24 -07004835 updateRotation(true, true);
Dianne Hackbornad7fa7f2011-01-07 14:06:50 -08004836 Intent intent = new Intent(ACTION_HDMI_PLUGGED);
Joe Onoratodc100302011-01-11 17:07:41 -08004837 intent.addFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY_BEFORE_BOOT);
Dianne Hackbornad7fa7f2011-01-07 14:06:50 -08004838 intent.putExtra(EXTRA_HDMI_PLUGGED_STATE, plugged);
Dianne Hackborn5ac72a22012-08-29 18:32:08 -07004839 mContext.sendStickyBroadcastAsUser(intent, UserHandle.ALL);
Dianne Hackbornad7fa7f2011-01-07 14:06:50 -08004840 }
4841 }
4842
Joe Onoratoea495d42011-04-06 11:41:11 -07004843 void initializeHdmiState() {
Joe Onorato7ba631f2011-05-04 15:28:00 -07004844 boolean plugged = false;
Joe Onoratoea495d42011-04-06 11:41:11 -07004845 // watch for HDMI plug messages if the hdmi switch exists
4846 if (new File("/sys/devices/virtual/switch/hdmi/state").exists()) {
4847 mHDMIObserver.startObserving("DEVPATH=/devices/virtual/switch/hdmi");
4848
Joe Onoratoea495d42011-04-06 11:41:11 -07004849 final String filename = "/sys/class/switch/hdmi/state";
4850 FileReader reader = null;
4851 try {
4852 reader = new FileReader(filename);
4853 char[] buf = new char[15];
4854 int n = reader.read(buf);
4855 if (n > 1) {
4856 plugged = 0 != Integer.parseInt(new String(buf, 0, n-1));
4857 }
4858 } catch (IOException ex) {
4859 Slog.w(TAG, "Couldn't read hdmi state from " + filename + ": " + ex);
4860 } catch (NumberFormatException ex) {
4861 Slog.w(TAG, "Couldn't read hdmi state from " + filename + ": " + ex);
4862 } finally {
4863 if (reader != null) {
4864 try {
4865 reader.close();
4866 } catch (IOException ex) {
4867 }
Joe Onoratodc100302011-01-11 17:07:41 -08004868 }
4869 }
4870 }
Joe Onorato7ba631f2011-05-04 15:28:00 -07004871 // This dance forces the code in setHdmiPlugged to run.
4872 // Always do this so the sticky intent is stuck (to false) if there is no hdmi.
4873 mHdmiPlugged = !plugged;
4874 setHdmiPlugged(!mHdmiPlugged);
Joe Onoratodc100302011-01-11 17:07:41 -08004875 }
4876
Dianne Hackbornc0e3f242011-08-19 14:19:10 -07004877 final Object mScreenshotLock = new Object();
Dianne Hackbornfc8fa632011-08-17 16:20:47 -07004878 ServiceConnection mScreenshotConnection = null;
Dianne Hackbornfc8fa632011-08-17 16:20:47 -07004879
Jeff Brownd5bb82d2011-10-12 13:57:59 -07004880 final Runnable mScreenshotTimeout = new Runnable() {
4881 @Override public void run() {
4882 synchronized (mScreenshotLock) {
4883 if (mScreenshotConnection != null) {
4884 mContext.unbindService(mScreenshotConnection);
4885 mScreenshotConnection = null;
Dianne Hackbornfc8fa632011-08-17 16:20:47 -07004886 }
Winson Chung9112ec32011-06-27 13:15:32 -07004887 }
Jeff Brownd5bb82d2011-10-12 13:57:59 -07004888 }
4889 };
4890
4891 // Assume this is called from the Handler thread.
4892 private void takeScreenshot() {
4893 synchronized (mScreenshotLock) {
4894 if (mScreenshotConnection != null) {
4895 return;
4896 }
4897 ComponentName cn = new ComponentName("com.android.systemui",
4898 "com.android.systemui.screenshot.TakeScreenshotService");
4899 Intent intent = new Intent();
4900 intent.setComponent(cn);
4901 ServiceConnection conn = new ServiceConnection() {
4902 @Override
4903 public void onServiceConnected(ComponentName name, IBinder service) {
4904 synchronized (mScreenshotLock) {
4905 if (mScreenshotConnection != this) {
4906 return;
4907 }
4908 Messenger messenger = new Messenger(service);
4909 Message msg = Message.obtain(null, 1);
4910 final ServiceConnection myConn = this;
4911 Handler h = new Handler(mHandler.getLooper()) {
4912 @Override
4913 public void handleMessage(Message msg) {
4914 synchronized (mScreenshotLock) {
4915 if (mScreenshotConnection == myConn) {
4916 mContext.unbindService(mScreenshotConnection);
4917 mScreenshotConnection = null;
4918 mHandler.removeCallbacks(mScreenshotTimeout);
4919 }
4920 }
4921 }
4922 };
4923 msg.replyTo = new Messenger(h);
Winson Chunga63bb842011-10-17 10:26:28 -07004924 msg.arg1 = msg.arg2 = 0;
4925 if (mStatusBar != null && mStatusBar.isVisibleLw())
4926 msg.arg1 = 1;
4927 if (mNavigationBar != null && mNavigationBar.isVisibleLw())
4928 msg.arg2 = 1;
Jeff Brownd5bb82d2011-10-12 13:57:59 -07004929 try {
4930 messenger.send(msg);
4931 } catch (RemoteException e) {
4932 }
4933 }
4934 }
4935 @Override
4936 public void onServiceDisconnected(ComponentName name) {}
4937 };
Amith Yamasani27b89e62013-01-16 12:30:11 -08004938 if (mContext.bindServiceAsUser(
4939 intent, conn, Context.BIND_AUTO_CREATE, UserHandle.CURRENT)) {
Jeff Brownd5bb82d2011-10-12 13:57:59 -07004940 mScreenshotConnection = conn;
4941 mHandler.postDelayed(mScreenshotTimeout, 10000);
4942 }
4943 }
Winson Chung9112ec32011-06-27 13:15:32 -07004944 }
4945
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004946 /** {@inheritDoc} */
Jeff Brown00fa7bd2010-07-02 15:37:36 -07004947 @Override
Jeff Brown037c33e2014-04-09 00:31:55 -07004948 public int interceptKeyBeforeQueueing(KeyEvent event, int policyFlags) {
Jeff Brown96307042012-07-27 15:51:34 -07004949 if (!mSystemBooted) {
4950 // If we have not yet booted, don't let key events do anything.
4951 return 0;
4952 }
4953
Jeff Brown037c33e2014-04-09 00:31:55 -07004954 final boolean interactive = (policyFlags & FLAG_INTERACTIVE) != 0;
Jeff Brown1f245102010-11-18 20:53:46 -08004955 final boolean down = event.getAction() == KeyEvent.ACTION_DOWN;
4956 final boolean canceled = event.isCanceled();
4957 final int keyCode = event.getKeyCode();
Jeff Browne20c9e02010-10-11 14:20:19 -07004958
Jeff Brown3122e442010-10-11 23:32:49 -07004959 final boolean isInjected = (policyFlags & WindowManagerPolicy.FLAG_INJECTED) != 0;
Jeff Brown3122e442010-10-11 23:32:49 -07004960
Mike Lockwoodc72b15f2009-11-28 20:58:22 -05004961 // If screen is off then we treat the case where the keyguard is open but hidden
4962 // the same as if it were open and in front.
4963 // This will prevent any keys other than the power button from waking the screen
4964 // when the keyguard is hidden by another activity.
Jim Miller5ecd8112013-01-09 18:50:26 -08004965 final boolean keyguardActive = (mKeyguardDelegate == null ? false :
Jeff Brown037c33e2014-04-09 00:31:55 -07004966 (interactive ?
Jim Millerab954542014-10-10 18:21:49 -07004967 isKeyguardShowingAndNotOccluded() :
Jim Miller5ecd8112013-01-09 18:50:26 -08004968 mKeyguardDelegate.isShowing()));
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004969
Jeff Brown40013652012-05-16 21:22:36 -07004970 if (DEBUG_INPUT) {
Jeff Brown00fa7bd2010-07-02 15:37:36 -07004971 Log.d(TAG, "interceptKeyTq keycode=" + keyCode
Jeff Brown037c33e2014-04-09 00:31:55 -07004972 + " interactive=" + interactive + " keyguardActive=" + keyguardActive
Jeff Brown26875502014-01-30 21:47:47 -08004973 + " policyFlags=" + Integer.toHexString(policyFlags));
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004974 }
4975
Jeff Brown037c33e2014-04-09 00:31:55 -07004976 // Basic policy based on interactive state.
Jeff Brown4d396052010-10-29 21:50:21 -07004977 int result;
Michael Wright337d9d22014-04-22 15:03:48 -07004978 boolean isWakeKey = (policyFlags & WindowManagerPolicy.FLAG_WAKE) != 0
4979 || event.isWakeKey();
Michael Wrightfc01f042014-09-08 14:12:24 -07004980 if (interactive || (isInjected && !isWakeKey)) {
RoboErikde9ba392014-09-26 12:51:01 -07004981 // When the device is interactive or the key is injected pass the
4982 // key to the application.
Jeff Brown4d396052010-10-29 21:50:21 -07004983 result = ACTION_PASS_TO_USER;
Jose Lima9546b202014-07-02 17:21:51 -07004984 isWakeKey = false;
Michael Wrightfc01f042014-09-08 14:12:24 -07004985 } else if (!interactive && shouldDispatchInputWhenNonInteractive()) {
4986 // If we're currently dozing with the screen on and the keyguard showing, pass the key
4987 // to the application but preserve its wake key status to make sure we still move
4988 // from dozing to fully interactive if we would normally go from off to fully
4989 // interactive.
4990 result = ACTION_PASS_TO_USER;
Jeff Brown4d396052010-10-29 21:50:21 -07004991 } else {
4992 // When the screen is off and the key is not injected, determine whether
4993 // to wake the device but don't pass the key to the application.
4994 result = 0;
Jeff Brown26875502014-01-30 21:47:47 -08004995 if (isWakeKey && (!down || !isWakeKeyWhenScreenOff(keyCode))) {
4996 isWakeKey = false;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004997 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004998 }
4999
Justin Kohd378ad72013-04-01 12:18:26 -07005000 // If the key would be handled globally, just return the result, don't worry about special
5001 // key processing.
Jeff Brown13f00f02014-10-31 14:45:50 -07005002 if (isValidGlobalKey(keyCode)
5003 && mGlobalKeyManager.shouldHandleGlobalKey(keyCode, event)) {
Michael Wright85b1af62014-06-04 14:51:58 -07005004 if (isWakeKey) {
Dianne Hackborn280a64e2015-07-13 14:48:08 -07005005 wakeUp(event.getEventTime(), mAllowTheaterModeWakeFromKey, "android.policy:KEY");
Michael Wright85b1af62014-06-04 14:51:58 -07005006 }
Justin Kohd378ad72013-04-01 12:18:26 -07005007 return result;
5008 }
5009
Jeff Brownbae8e772014-06-12 19:59:45 -07005010 boolean useHapticFeedback = down
5011 && (policyFlags & WindowManagerPolicy.FLAG_VIRTUAL) != 0
5012 && event.getRepeatCount() == 0;
5013
Jeff Brown4d396052010-10-29 21:50:21 -07005014 // Handle special keys.
5015 switch (keyCode) {
5016 case KeyEvent.KEYCODE_VOLUME_DOWN:
Jeff Brownb0418da2010-11-01 15:24:01 -07005017 case KeyEvent.KEYCODE_VOLUME_UP:
5018 case KeyEvent.KEYCODE_VOLUME_MUTE: {
RoboErik001c59c2015-01-26 15:53:51 -08005019 if (mUseTvRouting) {
5020 // On TVs volume keys never go to the foreground app
5021 result &= ~ACTION_PASS_TO_USER;
5022 }
Jeff Brownd5bb82d2011-10-12 13:57:59 -07005023 if (keyCode == KeyEvent.KEYCODE_VOLUME_DOWN) {
5024 if (down) {
Jeff Brown13f00f02014-10-31 14:45:50 -07005025 if (interactive && !mScreenshotChordVolumeDownKeyTriggered
Jeff Brownd5bb82d2011-10-12 13:57:59 -07005026 && (event.getFlags() & KeyEvent.FLAG_FALLBACK) == 0) {
Jeff Brown13f00f02014-10-31 14:45:50 -07005027 mScreenshotChordVolumeDownKeyTriggered = true;
5028 mScreenshotChordVolumeDownKeyTime = event.getDownTime();
5029 mScreenshotChordVolumeDownKeyConsumed = false;
Jeff Brownd5bb82d2011-10-12 13:57:59 -07005030 cancelPendingPowerKeyAction();
5031 interceptScreenshotChord();
5032 }
5033 } else {
Jeff Brown13f00f02014-10-31 14:45:50 -07005034 mScreenshotChordVolumeDownKeyTriggered = false;
Jeff Brownd5bb82d2011-10-12 13:57:59 -07005035 cancelPendingScreenshotChordAction();
5036 }
5037 } else if (keyCode == KeyEvent.KEYCODE_VOLUME_UP) {
5038 if (down) {
Jeff Brown13f00f02014-10-31 14:45:50 -07005039 if (interactive && !mScreenshotChordVolumeUpKeyTriggered
Jeff Brownd5bb82d2011-10-12 13:57:59 -07005040 && (event.getFlags() & KeyEvent.FLAG_FALLBACK) == 0) {
Jeff Brown13f00f02014-10-31 14:45:50 -07005041 mScreenshotChordVolumeUpKeyTriggered = true;
Jeff Brownd5bb82d2011-10-12 13:57:59 -07005042 cancelPendingPowerKeyAction();
5043 cancelPendingScreenshotChordAction();
5044 }
5045 } else {
Jeff Brown13f00f02014-10-31 14:45:50 -07005046 mScreenshotChordVolumeUpKeyTriggered = false;
Jeff Brownd5bb82d2011-10-12 13:57:59 -07005047 cancelPendingScreenshotChordAction();
5048 }
5049 }
Jeff Brown4d396052010-10-29 21:50:21 -07005050 if (down) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -07005051 TelecomManager telecomManager = getTelecommService();
5052 if (telecomManager != null) {
5053 if (telecomManager.isRinging()) {
Santos Cordon6848f722014-05-21 15:22:12 -07005054 // If an incoming call is ringing, either VOLUME key means
5055 // "silence ringer". We handle these keys here, rather than
5056 // in the InCallScreen, to make sure we'll respond to them
5057 // even if the InCallScreen hasn't come to the foreground yet.
5058 // Look for the DOWN event here, to agree with the "fallback"
5059 // behavior in the InCallScreen.
5060 Log.i(TAG, "interceptKeyBeforeQueueing:"
5061 + " VOLUME key-down while ringing: Silence ringer!");
Jeff Brown4d396052010-10-29 21:50:21 -07005062
Santos Cordon6848f722014-05-21 15:22:12 -07005063 // Silence the ringer. (It's safe to call this
5064 // even if the ringer has already been silenced.)
Tyler Gunnef9f6f92014-09-12 22:16:17 -07005065 telecomManager.silenceRinger();
Jeff Brown4d396052010-10-29 21:50:21 -07005066
Santos Cordon6848f722014-05-21 15:22:12 -07005067 // And *don't* pass this key thru to the current activity
5068 // (which is probably the InCallScreen.)
5069 result &= ~ACTION_PASS_TO_USER;
5070 break;
5071 }
Tyler Gunnef9f6f92014-09-12 22:16:17 -07005072 if (telecomManager.isInCall()
Santos Cordon6848f722014-05-21 15:22:12 -07005073 && (result & ACTION_PASS_TO_USER) == 0) {
5074 // If we are in call but we decided not to pass the key to
RoboErik430fc482014-06-12 15:49:20 -07005075 // the application, just pass it to the session service.
5076
5077 MediaSessionLegacyHelper.getHelper(mContext)
RoboErik3c45c292014-07-08 16:47:31 -07005078 .sendVolumeKeyEvent(event, false);
Santos Cordon6848f722014-05-21 15:22:12 -07005079 break;
Jeff Brown4d396052010-10-29 21:50:21 -07005080 }
5081 }
5082
RoboErik430fc482014-06-12 15:49:20 -07005083 if ((result & ACTION_PASS_TO_USER) == 0) {
RoboErik001c59c2015-01-26 15:53:51 -08005084 if (mUseTvRouting) {
5085 dispatchDirectAudioEvent(event);
5086 } else {
5087 // If we aren't passing to the user and no one else
5088 // handled it send it to the session manager to
5089 // figure out.
5090 MediaSessionLegacyHelper.getHelper(mContext)
5091 .sendVolumeKeyEvent(event, true);
5092 }
Jeff Brown4d396052010-10-29 21:50:21 -07005093 break;
5094 }
5095 }
5096 break;
5097 }
5098
5099 case KeyEvent.KEYCODE_ENDCALL: {
5100 result &= ~ACTION_PASS_TO_USER;
5101 if (down) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -07005102 TelecomManager telecomManager = getTelecommService();
Jeff Brown4d396052010-10-29 21:50:21 -07005103 boolean hungUp = false;
Tyler Gunnef9f6f92014-09-12 22:16:17 -07005104 if (telecomManager != null) {
5105 hungUp = telecomManager.endCall();
Jeff Brown4d396052010-10-29 21:50:21 -07005106 }
Jeff Brown13f00f02014-10-31 14:45:50 -07005107 if (interactive && !hungUp) {
5108 mEndCallKeyHandled = false;
5109 mHandler.postDelayed(mEndCallLongPress,
5110 ViewConfiguration.get(mContext).getDeviceGlobalActionKeyTimeout());
5111 } else {
5112 mEndCallKeyHandled = true;
5113 }
Jeff Brown4d396052010-10-29 21:50:21 -07005114 } else {
Jeff Brown13f00f02014-10-31 14:45:50 -07005115 if (!mEndCallKeyHandled) {
5116 mHandler.removeCallbacks(mEndCallLongPress);
5117 if (!canceled) {
5118 if ((mEndcallBehavior
5119 & Settings.System.END_BUTTON_BEHAVIOR_HOME) != 0) {
5120 if (goHome()) {
5121 break;
5122 }
Dianne Hackborn0041e972009-07-24 17:14:43 -07005123 }
Jeff Brown13f00f02014-10-31 14:45:50 -07005124 if ((mEndcallBehavior
5125 & Settings.System.END_BUTTON_BEHAVIOR_SLEEP) != 0) {
5126 mPowerManager.goToSleep(event.getEventTime(),
5127 PowerManager.GO_TO_SLEEP_REASON_POWER_BUTTON, 0);
5128 isWakeKey = false;
5129 }
Jeff Brown4d396052010-10-29 21:50:21 -07005130 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005131 }
Jeff Brown4d396052010-10-29 21:50:21 -07005132 }
5133 break;
5134 }
5135
5136 case KeyEvent.KEYCODE_POWER: {
5137 result &= ~ACTION_PASS_TO_USER;
Jeff Brown13f00f02014-10-31 14:45:50 -07005138 isWakeKey = false; // wake-up will be handled separately
Jeff Brown4d396052010-10-29 21:50:21 -07005139 if (down) {
Jeff Brown13f00f02014-10-31 14:45:50 -07005140 interceptPowerKeyDown(event, interactive);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005141 } else {
Jeff Brown13f00f02014-10-31 14:45:50 -07005142 interceptPowerKeyUp(event, interactive, canceled);
Jeff Brown4d396052010-10-29 21:50:21 -07005143 }
5144 break;
5145 }
5146
Jeff Brown6212a492014-03-07 13:58:47 -08005147 case KeyEvent.KEYCODE_SLEEP: {
5148 result &= ~ACTION_PASS_TO_USER;
Filip Gruszczynskia483a1d2015-03-17 19:06:58 +00005149 isWakeKey = false;
Jeff Brownbae8e772014-06-12 19:59:45 -07005150 if (!mPowerManager.isInteractive()) {
5151 useHapticFeedback = false; // suppress feedback if already non-interactive
5152 }
Nick Vaccarob593a812015-05-15 11:23:05 -07005153 if (down) {
5154 sleepPress(event.getEventTime());
5155 } else {
5156 sleepRelease(event.getEventTime());
5157 }
Jeff Brown6212a492014-03-07 13:58:47 -08005158 break;
5159 }
5160
Nick Armstrong-Crews56ecfcc2015-09-07 21:46:50 -07005161 case KeyEvent.KEYCODE_SOFT_SLEEP: {
5162 result &= ~ACTION_PASS_TO_USER;
5163 isWakeKey = false;
5164 if (!down) {
5165 mPowerManagerInternal.setUserInactiveOverrideFromWindowManager();
5166 }
5167 break;
5168 }
5169
Jeff Brown6212a492014-03-07 13:58:47 -08005170 case KeyEvent.KEYCODE_WAKEUP: {
5171 result &= ~ACTION_PASS_TO_USER;
Jose Lima9546b202014-07-02 17:21:51 -07005172 isWakeKey = true;
Jeff Brown6212a492014-03-07 13:58:47 -08005173 break;
5174 }
5175
Jeff Brown4d396052010-10-29 21:50:21 -07005176 case KeyEvent.KEYCODE_MEDIA_PLAY:
5177 case KeyEvent.KEYCODE_MEDIA_PAUSE:
5178 case KeyEvent.KEYCODE_MEDIA_PLAY_PAUSE:
Jeff Brown4d396052010-10-29 21:50:21 -07005179 case KeyEvent.KEYCODE_HEADSETHOOK:
5180 case KeyEvent.KEYCODE_MUTE:
5181 case KeyEvent.KEYCODE_MEDIA_STOP:
5182 case KeyEvent.KEYCODE_MEDIA_NEXT:
5183 case KeyEvent.KEYCODE_MEDIA_PREVIOUS:
5184 case KeyEvent.KEYCODE_MEDIA_REWIND:
5185 case KeyEvent.KEYCODE_MEDIA_RECORD:
Jaekyun Seokbfdad8e2013-07-08 13:53:21 +09005186 case KeyEvent.KEYCODE_MEDIA_FAST_FORWARD:
5187 case KeyEvent.KEYCODE_MEDIA_AUDIO_TRACK: {
RoboErikde9ba392014-09-26 12:51:01 -07005188 if (MediaSessionLegacyHelper.getHelper(mContext).isGlobalPriorityActive()) {
5189 // If the global session is active pass all media keys to it
5190 // instead of the active window.
5191 result &= ~ACTION_PASS_TO_USER;
5192 }
Jeff Brown4d396052010-10-29 21:50:21 -07005193 if ((result & ACTION_PASS_TO_USER) == 0) {
5194 // Only do this if we would otherwise not pass it to the user. In that
5195 // case, the PhoneWindow class will do the same thing, except it will
5196 // only do it if the showing app doesn't process the key on its own.
Jeff Brown40013652012-05-16 21:22:36 -07005197 // Note that we need to make a copy of the key event here because the
5198 // original key event will be recycled when we return.
Jeff Brown4d396052010-10-29 21:50:21 -07005199 mBroadcastWakeLock.acquire();
Jeff Brown40013652012-05-16 21:22:36 -07005200 Message msg = mHandler.obtainMessage(MSG_DISPATCH_MEDIA_KEY_WITH_WAKE_LOCK,
5201 new KeyEvent(event));
5202 msg.setAsynchronous(true);
5203 msg.sendToTarget();
Jeff Brown4d396052010-10-29 21:50:21 -07005204 }
5205 break;
Jeff Brown00fa7bd2010-07-02 15:37:36 -07005206 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005207
Jeff Brown4d396052010-10-29 21:50:21 -07005208 case KeyEvent.KEYCODE_CALL: {
5209 if (down) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -07005210 TelecomManager telecomManager = getTelecommService();
5211 if (telecomManager != null) {
5212 if (telecomManager.isRinging()) {
Santos Cordon6848f722014-05-21 15:22:12 -07005213 Log.i(TAG, "interceptKeyBeforeQueueing:"
5214 + " CALL key-down while ringing: Answer the call!");
Tyler Gunnef9f6f92014-09-12 22:16:17 -07005215 telecomManager.acceptRingingCall();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005216
Santos Cordon6848f722014-05-21 15:22:12 -07005217 // And *don't* pass this key thru to the current activity
5218 // (which is presumably the InCallScreen.)
5219 result &= ~ACTION_PASS_TO_USER;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005220 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005221 }
Jeff Brown00fa7bd2010-07-02 15:37:36 -07005222 }
Jeff Brown4d396052010-10-29 21:50:21 -07005223 break;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005224 }
Michael Wright869a67c2014-08-26 19:33:06 -07005225 case KeyEvent.KEYCODE_VOICE_ASSIST: {
5226 // Only do this if we would otherwise not pass it to the user. In that case,
5227 // interceptKeyBeforeDispatching would apply a similar but different policy in
5228 // order to invoke voice assist actions. Note that we need to make a copy of the
5229 // key event here because the original key event will be recycled when we return.
5230 if ((result & ACTION_PASS_TO_USER) == 0 && !down) {
5231 mBroadcastWakeLock.acquire();
5232 Message msg = mHandler.obtainMessage(MSG_LAUNCH_VOICE_ASSIST_WITH_WAKE_LOCK,
5233 keyguardActive ? 1 : 0, 0);
5234 msg.setAsynchronous(true);
5235 msg.sendToTarget();
5236 }
5237 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005238 }
Jeff Brown26875502014-01-30 21:47:47 -08005239
Jeff Brownbae8e772014-06-12 19:59:45 -07005240 if (useHapticFeedback) {
5241 performHapticFeedbackLw(null, HapticFeedbackConstants.VIRTUAL_KEY, false);
5242 }
5243
Jeff Brown26875502014-01-30 21:47:47 -08005244 if (isWakeKey) {
Dianne Hackborn280a64e2015-07-13 14:48:08 -07005245 wakeUp(event.getEventTime(), mAllowTheaterModeWakeFromKey, "android.policy:KEY");
Jeff Brown26875502014-01-30 21:47:47 -08005246 }
Bryce Lee584a4452014-10-21 15:55:55 -07005247
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005248 return result;
5249 }
5250
Jeff Brown1c2e4942012-11-06 16:32:01 -08005251 /**
Jeff Brown13f00f02014-10-31 14:45:50 -07005252 * Returns true if the key can have global actions attached to it.
5253 * We reserve all power management keys for the system since they require
5254 * very careful handling.
5255 */
5256 private static boolean isValidGlobalKey(int keyCode) {
5257 switch (keyCode) {
5258 case KeyEvent.KEYCODE_POWER:
5259 case KeyEvent.KEYCODE_WAKEUP:
5260 case KeyEvent.KEYCODE_SLEEP:
5261 return false;
5262 default:
5263 return true;
5264 }
5265 }
5266
5267 /**
Jeff Brown1c2e4942012-11-06 16:32:01 -08005268 * When the screen is off we ignore some keys that might otherwise typically
5269 * be considered wake keys. We filter them out here.
5270 *
5271 * {@link KeyEvent#KEYCODE_POWER} is notably absent from this list because it
5272 * is always considered a wake key.
5273 */
5274 private boolean isWakeKeyWhenScreenOff(int keyCode) {
5275 switch (keyCode) {
5276 // ignore volume keys unless docked
5277 case KeyEvent.KEYCODE_VOLUME_UP:
5278 case KeyEvent.KEYCODE_VOLUME_DOWN:
5279 case KeyEvent.KEYCODE_VOLUME_MUTE:
5280 return mDockMode != Intent.EXTRA_DOCK_STATE_UNDOCKED;
5281
5282 // ignore media and camera keys
5283 case KeyEvent.KEYCODE_MUTE:
5284 case KeyEvent.KEYCODE_HEADSETHOOK:
5285 case KeyEvent.KEYCODE_MEDIA_PLAY:
5286 case KeyEvent.KEYCODE_MEDIA_PAUSE:
5287 case KeyEvent.KEYCODE_MEDIA_PLAY_PAUSE:
5288 case KeyEvent.KEYCODE_MEDIA_STOP:
5289 case KeyEvent.KEYCODE_MEDIA_NEXT:
5290 case KeyEvent.KEYCODE_MEDIA_PREVIOUS:
5291 case KeyEvent.KEYCODE_MEDIA_REWIND:
5292 case KeyEvent.KEYCODE_MEDIA_RECORD:
5293 case KeyEvent.KEYCODE_MEDIA_FAST_FORWARD:
Jaekyun Seokbfdad8e2013-07-08 13:53:21 +09005294 case KeyEvent.KEYCODE_MEDIA_AUDIO_TRACK:
Jeff Brown1c2e4942012-11-06 16:32:01 -08005295 case KeyEvent.KEYCODE_CAMERA:
5296 return false;
5297 }
5298 return true;
5299 }
5300
5301
Jeff Brown56194eb2011-03-02 19:23:13 -08005302 /** {@inheritDoc} */
5303 @Override
Michael Wright70af00a2014-09-03 19:30:20 -07005304 public int interceptMotionBeforeQueueingNonInteractive(long whenNanos, int policyFlags) {
5305 if ((policyFlags & FLAG_WAKE) != 0) {
Dianne Hackborn280a64e2015-07-13 14:48:08 -07005306 if (wakeUp(whenNanos / 1000000, mAllowTheaterModeWakeFromMotion,
5307 "android.policy:MOTION")) {
Bryce Lee5c138322014-11-03 08:26:09 -08005308 return 0;
5309 }
Michael Wright70af00a2014-09-03 19:30:20 -07005310 }
Bryce Lee5c138322014-11-03 08:26:09 -08005311
Michael Wright70af00a2014-09-03 19:30:20 -07005312 if (shouldDispatchInputWhenNonInteractive()) {
5313 return ACTION_PASS_TO_USER;
5314 }
Bryce Lee5c138322014-11-03 08:26:09 -08005315
Bryce Lee812d7022014-11-10 13:33:28 -08005316 // If we have not passed the action up and we are in theater mode without dreaming,
5317 // there will be no dream to intercept the touch and wake into ambient. The device should
5318 // wake up in this case.
5319 if (isTheaterModeEnabled() && (policyFlags & FLAG_WAKE) != 0) {
Dianne Hackborn280a64e2015-07-13 14:48:08 -07005320 wakeUp(whenNanos / 1000000, mAllowTheaterModeWakeFromMotionWhenNotDreaming,
5321 "android.policy:MOTION");
Bryce Lee812d7022014-11-10 13:33:28 -08005322 }
5323
Jeff Brown037c33e2014-04-09 00:31:55 -07005324 return 0;
Jeff Brown56194eb2011-03-02 19:23:13 -08005325 }
5326
Michael Wright70af00a2014-09-03 19:30:20 -07005327 private boolean shouldDispatchInputWhenNonInteractive() {
Joe LaPennaf2b9b2d2015-11-17 22:22:37 +00005328 // Send events to keyguard while the screen is on.
5329 if (isKeyguardShowingAndNotOccluded() && mDisplay != null
5330 && mDisplay.getState() != Display.STATE_OFF) {
Bryce Lee5c138322014-11-03 08:26:09 -08005331 return true;
5332 }
5333
5334 // Send events to a dozing dream even if the screen is off since the dream
5335 // is in control of the state of the screen.
5336 IDreamManager dreamManager = getDreamManager();
5337
5338 try {
5339 if (dreamManager != null && dreamManager.isDreaming()) {
5340 return true;
5341 }
5342 } catch (RemoteException e) {
5343 Slog.e(TAG, "RemoteException when checking if dreaming", e);
5344 }
5345
5346 // Otherwise, consume events since the user can't see what is being
5347 // interacted with.
5348 return false;
Michael Wright70af00a2014-09-03 19:30:20 -07005349 }
5350
RoboErik001c59c2015-01-26 15:53:51 -08005351 private void dispatchDirectAudioEvent(KeyEvent event) {
5352 if (event.getAction() != KeyEvent.ACTION_DOWN) {
5353 return;
5354 }
5355 int keyCode = event.getKeyCode();
John Spurlockb94f2d62015-03-17 14:11:57 -04005356 int flags = AudioManager.FLAG_SHOW_UI | AudioManager.FLAG_PLAY_SOUND
5357 | AudioManager.FLAG_FROM_KEY;
RoboErik001c59c2015-01-26 15:53:51 -08005358 String pkgName = mContext.getOpPackageName();
5359 switch (keyCode) {
5360 case KeyEvent.KEYCODE_VOLUME_UP:
5361 try {
John Spurlockee5ad722015-03-03 16:17:21 -05005362 getAudioService().adjustSuggestedStreamVolume(AudioManager.ADJUST_RAISE,
John Spurlock90874332015-03-10 16:00:54 -04005363 AudioManager.USE_DEFAULT_STREAM_TYPE, flags, pkgName, TAG);
RoboErik001c59c2015-01-26 15:53:51 -08005364 } catch (RemoteException e) {
5365 Log.e(TAG, "Error dispatching volume up in dispatchTvAudioEvent.", e);
5366 }
5367 break;
5368 case KeyEvent.KEYCODE_VOLUME_DOWN:
5369 try {
John Spurlockee5ad722015-03-03 16:17:21 -05005370 getAudioService().adjustSuggestedStreamVolume(AudioManager.ADJUST_LOWER,
John Spurlock90874332015-03-10 16:00:54 -04005371 AudioManager.USE_DEFAULT_STREAM_TYPE, flags, pkgName, TAG);
RoboErik001c59c2015-01-26 15:53:51 -08005372 } catch (RemoteException e) {
5373 Log.e(TAG, "Error dispatching volume down in dispatchTvAudioEvent.", e);
5374 }
5375 break;
5376 case KeyEvent.KEYCODE_VOLUME_MUTE:
5377 try {
5378 if (event.getRepeatCount() == 0) {
John Spurlockee5ad722015-03-03 16:17:21 -05005379 getAudioService().adjustSuggestedStreamVolume(
5380 AudioManager.ADJUST_TOGGLE_MUTE,
John Spurlock90874332015-03-10 16:00:54 -04005381 AudioManager.USE_DEFAULT_STREAM_TYPE, flags, pkgName, TAG);
RoboErik001c59c2015-01-26 15:53:51 -08005382 }
5383 } catch (RemoteException e) {
5384 Log.e(TAG, "Error dispatching mute in dispatchTvAudioEvent.", e);
5385 }
5386 break;
5387 }
5388 }
5389
Jeff Brown40013652012-05-16 21:22:36 -07005390 void dispatchMediaKeyWithWakeLock(KeyEvent event) {
5391 if (DEBUG_INPUT) {
5392 Slog.d(TAG, "dispatchMediaKeyWithWakeLock: " + event);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005393 }
5394
Jeff Brown40013652012-05-16 21:22:36 -07005395 if (mHavePendingMediaKeyRepeatWithWakeLock) {
5396 if (DEBUG_INPUT) {
5397 Slog.d(TAG, "dispatchMediaKeyWithWakeLock: canceled repeat");
5398 }
5399
5400 mHandler.removeMessages(MSG_DISPATCH_MEDIA_KEY_REPEAT_WITH_WAKE_LOCK);
5401 mHavePendingMediaKeyRepeatWithWakeLock = false;
5402 mBroadcastWakeLock.release(); // pending repeat was holding onto the wake lock
5403 }
5404
5405 dispatchMediaKeyWithWakeLockToAudioService(event);
5406
5407 if (event.getAction() == KeyEvent.ACTION_DOWN
5408 && event.getRepeatCount() == 0) {
5409 mHavePendingMediaKeyRepeatWithWakeLock = true;
5410
5411 Message msg = mHandler.obtainMessage(
5412 MSG_DISPATCH_MEDIA_KEY_REPEAT_WITH_WAKE_LOCK, event);
5413 msg.setAsynchronous(true);
5414 mHandler.sendMessageDelayed(msg, ViewConfiguration.getKeyRepeatTimeout());
5415 } else {
5416 mBroadcastWakeLock.release();
5417 }
5418 }
5419
5420 void dispatchMediaKeyRepeatWithWakeLock(KeyEvent event) {
5421 mHavePendingMediaKeyRepeatWithWakeLock = false;
5422
5423 KeyEvent repeatEvent = KeyEvent.changeTimeRepeat(event,
5424 SystemClock.uptimeMillis(), 1, event.getFlags() | KeyEvent.FLAG_LONG_PRESS);
5425 if (DEBUG_INPUT) {
5426 Slog.d(TAG, "dispatchMediaKeyRepeatWithWakeLock: " + repeatEvent);
5427 }
5428
5429 dispatchMediaKeyWithWakeLockToAudioService(repeatEvent);
5430 mBroadcastWakeLock.release();
5431 }
5432
5433 void dispatchMediaKeyWithWakeLockToAudioService(KeyEvent event) {
5434 if (ActivityManagerNative.isSystemReady()) {
RoboErik430fc482014-06-12 15:49:20 -07005435 MediaSessionLegacyHelper.getHelper(mContext).sendMediaButtonEvent(event, true);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005436 }
5437 }
5438
Michael Wright869a67c2014-08-26 19:33:06 -07005439 void launchVoiceAssistWithWakeLock(boolean keyguardActive) {
Dianne Hackbornb6683c42015-06-18 17:40:33 -07005440 IDeviceIdleController dic = IDeviceIdleController.Stub.asInterface(
5441 ServiceManager.getService(Context.DEVICE_IDLE_CONTROLLER));
5442 if (dic != null) {
5443 try {
5444 dic.exitIdle("voice-search");
5445 } catch (RemoteException e) {
5446 }
5447 }
Michael Wright869a67c2014-08-26 19:33:06 -07005448 Intent voiceIntent =
5449 new Intent(RecognizerIntent.ACTION_VOICE_SEARCH_HANDS_FREE);
5450 voiceIntent.putExtra(RecognizerIntent.EXTRA_SECURE, keyguardActive);
Bart Sears8b1c27c2015-03-18 23:51:02 +00005451 startActivityAsUser(voiceIntent, UserHandle.CURRENT_OR_SELF);
Michael Wright869a67c2014-08-26 19:33:06 -07005452 mBroadcastWakeLock.release();
5453 }
5454
Mike Lockwood1753f7f2009-08-24 14:49:07 -07005455 BroadcastReceiver mDockReceiver = new BroadcastReceiver() {
Craig Mautnereee29c42013-01-17 14:44:34 -08005456 @Override
Mike Lockwood1753f7f2009-08-24 14:49:07 -07005457 public void onReceive(Context context, Intent intent) {
Dianne Hackborn867ab6472010-04-29 13:28:56 -07005458 if (Intent.ACTION_DOCK_EVENT.equals(intent.getAction())) {
5459 mDockMode = intent.getIntExtra(Intent.EXTRA_DOCK_STATE,
5460 Intent.EXTRA_DOCK_STATE_UNDOCKED);
Daniel Sandler6396c722013-04-16 20:19:09 -04005461 } else {
5462 try {
5463 IUiModeManager uiModeService = IUiModeManager.Stub.asInterface(
5464 ServiceManager.getService(Context.UI_MODE_SERVICE));
5465 mUiMode = uiModeService.getCurrentModeType();
5466 } catch (RemoteException e) {
5467 }
Dianne Hackborn80fa1662009-10-07 14:02:10 -07005468 }
Jeff Brown01a98dd2011-09-20 15:08:29 -07005469 updateRotation(true);
Craig Mautnereee29c42013-01-17 14:44:34 -08005470 synchronized (mLock) {
5471 updateOrientationListenerLp();
5472 }
Mike Lockwood1753f7f2009-08-24 14:49:07 -07005473 }
5474 };
5475
Jeff Brown6aaf2952012-10-05 16:01:08 -07005476 BroadcastReceiver mDreamReceiver = new BroadcastReceiver() {
5477 @Override
5478 public void onReceive(Context context, Intent intent) {
5479 if (Intent.ACTION_DREAMING_STARTED.equals(intent.getAction())) {
Jim Miller5ecd8112013-01-09 18:50:26 -08005480 if (mKeyguardDelegate != null) {
5481 mKeyguardDelegate.onDreamingStarted();
Jeff Brown6aaf2952012-10-05 16:01:08 -07005482 }
5483 } else if (Intent.ACTION_DREAMING_STOPPED.equals(intent.getAction())) {
Jim Miller5ecd8112013-01-09 18:50:26 -08005484 if (mKeyguardDelegate != null) {
5485 mKeyguardDelegate.onDreamingStopped();
Jeff Brown6aaf2952012-10-05 16:01:08 -07005486 }
5487 }
5488 }
5489 };
5490
Christopher Tate5e08af02012-09-21 17:17:22 -07005491 BroadcastReceiver mMultiuserReceiver = new BroadcastReceiver() {
5492 @Override
5493 public void onReceive(Context context, Intent intent) {
5494 if (Intent.ACTION_USER_SWITCHED.equals(intent.getAction())) {
5495 // tickle the settings observer: this first ensures that we're
5496 // observing the relevant settings for the newly-active user,
5497 // and then updates our own bookkeeping based on the now-
5498 // current user.
5499 mSettingsObserver.onChange(false);
John Spurlockce479d82012-11-29 09:52:21 -05005500
5501 // force a re-application of focused window sysui visibility.
5502 // the window may never have been shown for this user
5503 // e.g. the keyguard when going through the new-user setup flow
John Spurlock04db1762013-05-13 12:46:41 -04005504 synchronized (mWindowManagerFuncs.getWindowManagerLock()) {
John Spurlockce479d82012-11-29 09:52:21 -05005505 mLastSystemUiFlags = 0;
5506 updateSystemUiVisibilityLw();
5507 }
Christopher Tate5e08af02012-09-21 17:17:22 -07005508 }
5509 }
5510 };
5511
Adrian Roosddc8b272015-05-21 16:28:27 -07005512 private final Runnable mHiddenNavPanic = new Runnable() {
John Spurlockd9b70bd2014-02-06 17:02:44 -05005513 @Override
5514 public void run() {
Adrian Roosddc8b272015-05-21 16:28:27 -07005515 synchronized (mWindowManagerFuncs.getWindowManagerLock()) {
5516 if (!isUserSetupComplete()) {
5517 // Swipe-up for navigation bar is disabled during setup
5518 return;
5519 }
5520 mPendingPanicGestureUptime = SystemClock.uptimeMillis();
5521 mNavigationBarController.showTransient();
5522 }
John Spurlockd9b70bd2014-02-06 17:02:44 -05005523 }
5524 };
5525
John Spurlocke1f366f2013-08-05 12:22:40 -04005526 private void requestTransientBars(WindowState swipeTarget) {
John Spurlock04db1762013-05-13 12:46:41 -04005527 synchronized (mWindowManagerFuncs.getWindowManagerLock()) {
Maurice Lam99c6e072014-04-28 18:24:28 -07005528 if (!isUserSetupComplete()) {
5529 // Swipe-up for navigation bar is disabled during setup
5530 return;
5531 }
John Spurlock27735a42013-08-14 17:57:38 -04005532 boolean sb = mStatusBarController.checkShowTransientBarLw();
5533 boolean nb = mNavigationBarController.checkShowTransientBarLw();
John Spurlockad3e6cb2013-04-30 08:47:43 -04005534 if (sb || nb) {
Adrian Roos62b65e42015-02-25 18:05:34 +01005535 // Don't show status bar when swiping on already visible navigation bar
5536 if (!nb && swipeTarget == mNavigationBar) {
John Spurlocke1f366f2013-08-05 12:22:40 -04005537 if (DEBUG) Slog.d(TAG, "Not showing transient bar, wrong swipe target");
John Spurlockad3e6cb2013-04-30 08:47:43 -04005538 return;
5539 }
John Spurlock27735a42013-08-14 17:57:38 -04005540 if (sb) mStatusBarController.showTransient();
5541 if (nb) mNavigationBarController.showTransient();
John Spurlockf1a36642013-10-12 17:50:42 -04005542 mImmersiveModeConfirmation.confirmCurrentPrompt();
John Spurlockad3e6cb2013-04-30 08:47:43 -04005543 updateSystemUiVisibilityLw();
John Spurlock32beb2c2013-03-11 10:16:47 -04005544 }
John Spurlockad3e6cb2013-04-30 08:47:43 -04005545 }
5546 }
5547
Jeff Brown3ee549c2014-09-22 20:14:39 -07005548 // Called on the PowerManager's Notifier thread.
Jeff Brownc38c9be2012-10-04 13:16:19 -07005549 @Override
Jeff Brown416c49c2015-05-26 19:50:18 -07005550 public void startedGoingToSleep(int why) {
5551 if (DEBUG_WAKEUP) Slog.i(TAG, "Started going to sleep... (why=" + why + ")");
Jorim Jaggid175b6c2015-05-27 15:39:09 -07005552 if (mKeyguardDelegate != null) {
5553 mKeyguardDelegate.onStartedGoingToSleep(why);
5554 }
Jeff Brown416c49c2015-05-26 19:50:18 -07005555 }
5556
5557 // Called on the PowerManager's Notifier thread.
5558 @Override
5559 public void finishedGoingToSleep(int why) {
Dianne Hackborn74489012009-03-24 20:50:09 -07005560 EventLog.writeEvent(70000, 0);
Jeff Brown416c49c2015-05-26 19:50:18 -07005561 if (DEBUG_WAKEUP) Slog.i(TAG, "Finished going to sleep... (why=" + why + ")");
Chris Wren9bb290b2015-06-29 12:02:13 -04005562 MetricsLogger.histogram(mContext, "screen_timeout", mLockScreenTimeout / 1000);
Jeff Brown3ee549c2014-09-22 20:14:39 -07005563
5564 // We must get this work done here because the power manager will drop
5565 // the wake lock and let the system suspend once this function returns.
The Android Open Source Project0727d222009-03-11 12:11:58 -07005566 synchronized (mLock) {
Jeff Brown3ee549c2014-09-22 20:14:39 -07005567 mAwake = false;
Jeff Browna20dda42014-05-27 20:57:24 -07005568 updateWakeGestureListenerLp();
The Android Open Source Project0727d222009-03-11 12:11:58 -07005569 updateOrientationListenerLp();
Mike Lockwood28569302010-01-28 11:54:40 -05005570 updateLockScreenTimeout();
The Android Open Source Project0727d222009-03-11 12:11:58 -07005571 }
Jeff Brown3ee549c2014-09-22 20:14:39 -07005572 if (mKeyguardDelegate != null) {
Jorim Jaggid175b6c2015-05-27 15:39:09 -07005573 mKeyguardDelegate.onFinishedGoingToSleep(why);
Jeff Brown3ee549c2014-09-22 20:14:39 -07005574 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005575 }
5576
Jeff Brown3ee549c2014-09-22 20:14:39 -07005577 // Called on the PowerManager's Notifier thread.
Jeff Brownc38c9be2012-10-04 13:16:19 -07005578 @Override
Jeff Brown416c49c2015-05-26 19:50:18 -07005579 public void startedWakingUp() {
Dianne Hackborn74489012009-03-24 20:50:09 -07005580 EventLog.writeEvent(70000, 1);
Jeff Brown416c49c2015-05-26 19:50:18 -07005581 if (DEBUG_WAKEUP) Slog.i(TAG, "Started waking up...");
Craig Mautner8a0da012014-05-31 15:13:37 -07005582
Jeff Brown3ee549c2014-09-22 20:14:39 -07005583 // Since goToSleep performs these functions synchronously, we must
5584 // do the same here. We cannot post this work to a handler because
5585 // that might cause it to become reordered with respect to what
5586 // may happen in a future call to goToSleep.
The Android Open Source Project0727d222009-03-11 12:11:58 -07005587 synchronized (mLock) {
Jeff Brown3ee549c2014-09-22 20:14:39 -07005588 mAwake = true;
Jeff Brown3ee549c2014-09-22 20:14:39 -07005589
Jeff Browna20dda42014-05-27 20:57:24 -07005590 updateWakeGestureListenerLp();
The Android Open Source Project0727d222009-03-11 12:11:58 -07005591 updateOrientationListenerLp();
Mike Lockwood28569302010-01-28 11:54:40 -05005592 updateLockScreenTimeout();
The Android Open Source Project0727d222009-03-11 12:11:58 -07005593 }
Jeff Brownc38c9be2012-10-04 13:16:19 -07005594
Jim Miller5ecd8112013-01-09 18:50:26 -08005595 if (mKeyguardDelegate != null) {
Jorim Jaggi4cfdcf52015-07-09 12:13:59 -07005596 mKeyguardDelegate.onStartedWakingUp();
Jeff Brownc38c9be2012-10-04 13:16:19 -07005597 }
Jeff Brown36c4db82014-09-19 12:05:31 -07005598 }
5599
Jeff Brown416c49c2015-05-26 19:50:18 -07005600 // Called on the PowerManager's Notifier thread.
5601 @Override
5602 public void finishedWakingUp() {
5603 if (DEBUG_WAKEUP) Slog.i(TAG, "Finished waking up...");
5604 }
5605
5606 private void wakeUpFromPowerKey(long eventTime) {
Dianne Hackborn280a64e2015-07-13 14:48:08 -07005607 wakeUp(eventTime, mAllowTheaterModeWakeFromPowerKey, "android.policy:POWER");
Jeff Brown416c49c2015-05-26 19:50:18 -07005608 }
5609
Dianne Hackborn280a64e2015-07-13 14:48:08 -07005610 private boolean wakeUp(long wakeTime, boolean wakeInTheaterMode, String reason) {
Bryce Leed3896842015-06-23 17:06:51 -07005611 final boolean theaterModeEnabled = isTheaterModeEnabled();
5612 if (!wakeInTheaterMode && theaterModeEnabled) {
Jeff Brown416c49c2015-05-26 19:50:18 -07005613 return false;
5614 }
5615
Bryce Leed3896842015-06-23 17:06:51 -07005616 if (theaterModeEnabled) {
5617 Settings.Global.putInt(mContext.getContentResolver(),
5618 Settings.Global.THEATER_MODE_ON, 0);
5619 }
5620
Dianne Hackborn280a64e2015-07-13 14:48:08 -07005621 mPowerManager.wakeUp(wakeTime, reason);
Jeff Brown416c49c2015-05-26 19:50:18 -07005622 return true;
5623 }
5624
Jeff Brown36c4db82014-09-19 12:05:31 -07005625 private void finishKeyguardDrawn() {
Jeff Brown3ee549c2014-09-22 20:14:39 -07005626 synchronized (mLock) {
Jorim Jaggif3255482015-07-24 12:32:42 -07005627 if (!mScreenOnEarly || mKeyguardDrawComplete) {
Stefan Kuhne9326dc12015-06-12 09:25:32 -10005628 return; // We are not awake yet or we have already informed of this event.
Jeff Brown3ee549c2014-09-22 20:14:39 -07005629 }
5630
Jeff Brown36c4db82014-09-19 12:05:31 -07005631 mKeyguardDrawComplete = true;
Jeff Brown3ee549c2014-09-22 20:14:39 -07005632 if (mKeyguardDelegate != null) {
5633 mHandler.removeMessages(MSG_KEYGUARD_DRAWN_TIMEOUT);
5634 }
Jorim Jaggi4cfdcf52015-07-09 12:13:59 -07005635 mWindowManagerDrawComplete = false;
Jeff Brown3ee549c2014-09-22 20:14:39 -07005636 }
5637
Jorim Jaggi4cfdcf52015-07-09 12:13:59 -07005638 // ... eventually calls finishWindowsDrawn which will finalize our screen turn on
5639 // as well as enabling the orientation change logic/sensor.
5640 mWindowManagerInternal.waitForAllWindowsDrawn(mWindowManagerDrawCallback,
5641 WAITING_FOR_DRAWN_TIMEOUT);
Jeff Brown3ee549c2014-09-22 20:14:39 -07005642 }
5643
5644 // Called on the DisplayManager's DisplayPowerController thread.
5645 @Override
5646 public void screenTurnedOff() {
5647 if (DEBUG_WAKEUP) Slog.i(TAG, "Screen turned off...");
5648
Jeff Brown48d1b142015-06-10 16:36:03 -07005649 updateScreenOffSleepToken(true);
Jeff Brown3ee549c2014-09-22 20:14:39 -07005650 synchronized (mLock) {
5651 mScreenOnEarly = false;
5652 mScreenOnFully = false;
Jorim Jaggi95c6dae2015-07-29 15:17:23 -07005653 mKeyguardDrawComplete = false;
Jeff Brown3ee549c2014-09-22 20:14:39 -07005654 mWindowManagerDrawComplete = false;
5655 mScreenOnListener = null;
5656 updateOrientationListenerLp();
Jorim Jaggi0d210f62015-07-10 14:24:44 -07005657
5658 if (mKeyguardDelegate != null) {
5659 mKeyguardDelegate.onScreenTurnedOff();
5660 }
Jeff Brown36c4db82014-09-19 12:05:31 -07005661 }
5662 }
5663
Jeff Brown3ee549c2014-09-22 20:14:39 -07005664 // Called on the DisplayManager's DisplayPowerController thread.
Jeff Brown36c4db82014-09-19 12:05:31 -07005665 @Override
5666 public void screenTurningOn(final ScreenOnListener screenOnListener) {
Jeff Brown36c4db82014-09-19 12:05:31 -07005667 if (DEBUG_WAKEUP) Slog.i(TAG, "Screen turning on...");
Jeff Brown36c4db82014-09-19 12:05:31 -07005668
Jeff Brown48d1b142015-06-10 16:36:03 -07005669 updateScreenOffSleepToken(false);
Jeff Brown3ee549c2014-09-22 20:14:39 -07005670 synchronized (mLock) {
5671 mScreenOnEarly = true;
5672 mScreenOnFully = false;
Jorim Jaggi95c6dae2015-07-29 15:17:23 -07005673 mKeyguardDrawComplete = false;
Jeff Brown3ee549c2014-09-22 20:14:39 -07005674 mWindowManagerDrawComplete = false;
5675 mScreenOnListener = screenOnListener;
Jeff Brown36c4db82014-09-19 12:05:31 -07005676
Jorim Jaggi4cfdcf52015-07-09 12:13:59 -07005677 if (mKeyguardDelegate != null) {
Jorim Jaggia4b51bc2015-08-10 18:20:43 -07005678 mHandler.removeMessages(MSG_KEYGUARD_DRAWN_TIMEOUT);
5679 mHandler.sendEmptyMessageDelayed(MSG_KEYGUARD_DRAWN_TIMEOUT, 1000);
Jorim Jaggi4cfdcf52015-07-09 12:13:59 -07005680 mKeyguardDelegate.onScreenTurningOn(mKeyguardDrawnCallback);
5681 } else {
5682 if (DEBUG_WAKEUP) Slog.d(TAG,
5683 "null mKeyguardDelegate: setting mKeyguardDrawComplete.");
5684 finishKeyguardDrawn();
5685 }
5686 }
Jeff Brown36c4db82014-09-19 12:05:31 -07005687 }
5688
Jorim Jaggi0d210f62015-07-10 14:24:44 -07005689 // Called on the DisplayManager's DisplayPowerController thread.
5690 @Override
5691 public void screenTurnedOn() {
5692 synchronized (mLock) {
5693 if (mKeyguardDelegate != null) {
5694 mKeyguardDelegate.onScreenTurnedOn();
5695 }
5696 }
5697 }
5698
Jeff Brown36c4db82014-09-19 12:05:31 -07005699 private void finishWindowsDrawn() {
Jeff Brown3ee549c2014-09-22 20:14:39 -07005700 synchronized (mLock) {
5701 if (!mScreenOnEarly || mWindowManagerDrawComplete) {
Stefan Kuhne9326dc12015-06-12 09:25:32 -10005702 return; // Screen is not turned on or we did already handle this case earlier.
Jeff Brown3ee549c2014-09-22 20:14:39 -07005703 }
5704
Jeff Brown36c4db82014-09-19 12:05:31 -07005705 mWindowManagerDrawComplete = true;
Jeff Brown36c4db82014-09-19 12:05:31 -07005706 }
Jeff Brown3ee549c2014-09-22 20:14:39 -07005707
5708 finishScreenTurningOn();
Jeff Brownc38c9be2012-10-04 13:16:19 -07005709 }
5710
Craig Mautner8a0da012014-05-31 15:13:37 -07005711 private void finishScreenTurningOn() {
Stefan Kuhne9326dc12015-06-12 09:25:32 -10005712 synchronized (mLock) {
5713 // We have just finished drawing screen content. Since the orientation listener
5714 // gets only installed when all windows are drawn, we try to install it again.
5715 updateOrientationListenerLp();
5716 }
Jeff Brown3ee549c2014-09-22 20:14:39 -07005717 final ScreenOnListener listener;
5718 final boolean enableScreen;
Jeff Brown36c4db82014-09-19 12:05:31 -07005719 synchronized (mLock) {
Jeff Brown3ee549c2014-09-22 20:14:39 -07005720 if (DEBUG_WAKEUP) Slog.d(TAG,
5721 "finishScreenTurningOn: mAwake=" + mAwake
5722 + ", mScreenOnEarly=" + mScreenOnEarly
5723 + ", mScreenOnFully=" + mScreenOnFully
5724 + ", mKeyguardDrawComplete=" + mKeyguardDrawComplete
5725 + ", mWindowManagerDrawComplete=" + mWindowManagerDrawComplete);
5726
5727 if (mScreenOnFully || !mScreenOnEarly || !mWindowManagerDrawComplete
5728 || (mAwake && !mKeyguardDrawComplete)) {
5729 return; // spurious or not ready yet
Jeff Brown36c4db82014-09-19 12:05:31 -07005730 }
5731
Jeff Brown3ee549c2014-09-22 20:14:39 -07005732 if (DEBUG_WAKEUP) Slog.i(TAG, "Finished screen turning on...");
5733 listener = mScreenOnListener;
Craig Mautner13f6ea72014-06-23 14:57:02 -07005734 mScreenOnListener = null;
Jeff Brown3ee549c2014-09-22 20:14:39 -07005735 mScreenOnFully = true;
5736
5737 // Remember the first time we draw the keyguard so we know when we're done with
5738 // the main part of booting and can enable the screen and hide boot messages.
5739 if (!mKeyguardDrawnOnce && mAwake) {
5740 mKeyguardDrawnOnce = true;
5741 enableScreen = true;
5742 if (mBootMessageNeedsHiding) {
5743 mBootMessageNeedsHiding = false;
5744 hideBootMessages();
5745 }
5746 } else {
5747 enableScreen = false;
5748 }
Jeff Brownc38c9be2012-10-04 13:16:19 -07005749 }
5750
Jeff Brown3ee549c2014-09-22 20:14:39 -07005751 if (listener != null) {
5752 listener.onScreenOn();
5753 }
Jeff Brown4fc45272012-10-10 18:28:14 -07005754
Jeff Brown3ee549c2014-09-22 20:14:39 -07005755 if (enableScreen) {
5756 try {
5757 mWindowManager.enableScreenIfNeeded();
5758 } catch (RemoteException unhandled) {
Jeff Brown36c4db82014-09-19 12:05:31 -07005759 }
Craig Mautnera631d492014-08-05 15:16:01 -07005760 }
5761 }
5762
5763 private void handleHideBootMessage() {
Jeff Brown3ee549c2014-09-22 20:14:39 -07005764 synchronized (mLock) {
5765 if (!mKeyguardDrawnOnce) {
5766 mBootMessageNeedsHiding = true;
5767 return; // keyguard hasn't drawn the first time yet, not done booting
5768 }
Craig Mautnera631d492014-08-05 15:16:01 -07005769 }
Jeff Brown3ee549c2014-09-22 20:14:39 -07005770
5771 if (mBootMsgDialog != null) {
5772 if (DEBUG_WAKEUP) Slog.d(TAG, "handleHideBootMessage: dismissing");
5773 mBootMsgDialog.dismiss();
5774 mBootMsgDialog = null;
Craig Mautnera631d492014-08-05 15:16:01 -07005775 }
Jeff Brownc38c9be2012-10-04 13:16:19 -07005776 }
5777
5778 @Override
Jeff Brown3ee549c2014-09-22 20:14:39 -07005779 public boolean isScreenOn() {
5780 return mScreenOnFully;
Dianne Hackborn08743722009-12-21 12:16:51 -08005781 }
Jeff Brownc38c9be2012-10-04 13:16:19 -07005782
Dianne Hackborn08743722009-12-21 12:16:51 -08005783 /** {@inheritDoc} */
Jose Lima9546b202014-07-02 17:21:51 -07005784 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005785 public void enableKeyguard(boolean enabled) {
Jim Miller5ecd8112013-01-09 18:50:26 -08005786 if (mKeyguardDelegate != null) {
5787 mKeyguardDelegate.setKeyguardEnabled(enabled);
Mike Lockwood3a74bd32011-08-12 13:55:22 -07005788 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005789 }
5790
5791 /** {@inheritDoc} */
Jose Lima9546b202014-07-02 17:21:51 -07005792 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005793 public void exitKeyguardSecurely(OnKeyguardExitResult callback) {
Jim Miller5ecd8112013-01-09 18:50:26 -08005794 if (mKeyguardDelegate != null) {
5795 mKeyguardDelegate.verifyUnlock(callback);
Mike Lockwood3a74bd32011-08-12 13:55:22 -07005796 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005797 }
5798
Jim Millerab954542014-10-10 18:21:49 -07005799 private boolean isKeyguardShowingAndNotOccluded() {
Jim Miller5ecd8112013-01-09 18:50:26 -08005800 if (mKeyguardDelegate == null) return false;
Jim Millerab954542014-10-10 18:21:49 -07005801 return mKeyguardDelegate.isShowing() && !mKeyguardOccluded;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005802 }
5803
Mike Lockwood520d8bc2011-02-18 13:23:13 -05005804 /** {@inheritDoc} */
Jose Lima9546b202014-07-02 17:21:51 -07005805 @Override
Mike Lockwood520d8bc2011-02-18 13:23:13 -05005806 public boolean isKeyguardLocked() {
5807 return keyguardOn();
5808 }
5809
5810 /** {@inheritDoc} */
Jose Lima9546b202014-07-02 17:21:51 -07005811 @Override
Mike Lockwood520d8bc2011-02-18 13:23:13 -05005812 public boolean isKeyguardSecure() {
Jim Miller5ecd8112013-01-09 18:50:26 -08005813 if (mKeyguardDelegate == null) return false;
5814 return mKeyguardDelegate.isSecure();
Mike Lockwood520d8bc2011-02-18 13:23:13 -05005815 }
5816
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005817 /** {@inheritDoc} */
Jose Lima9546b202014-07-02 17:21:51 -07005818 @Override
Adrian Roos461829d2015-06-03 14:41:18 -07005819 public boolean isKeyguardShowingOrOccluded() {
5820 return mKeyguardDelegate == null ? false : mKeyguardDelegate.isShowing();
5821 }
5822
5823 /** {@inheritDoc} */
5824 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005825 public boolean inKeyguardRestrictedKeyInputMode() {
Jim Miller5ecd8112013-01-09 18:50:26 -08005826 if (mKeyguardDelegate == null) return false;
5827 return mKeyguardDelegate.isInputRestricted();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005828 }
5829
Jose Lima9546b202014-07-02 17:21:51 -07005830 @Override
Dianne Hackborn90c52de2011-09-23 12:57:44 -07005831 public void dismissKeyguardLw() {
RoboErik8a2cfc32014-05-16 11:19:38 -07005832 if (mKeyguardDelegate != null && mKeyguardDelegate.isShowing()) {
Craig Mautnerc0d2d0a2014-10-31 16:25:15 -07005833 if (DEBUG_KEYGUARD) Slog.d(TAG, "PWM.dismissKeyguardLw");
Daniel Sandler1ce804392012-11-07 15:07:12 -05005834 mHandler.post(new Runnable() {
Jose Lima9546b202014-07-02 17:21:51 -07005835 @Override
Daniel Sandler1ce804392012-11-07 15:07:12 -05005836 public void run() {
Jorim Jaggi8de4311c2014-08-11 22:36:20 +02005837 // ask the keyguard to prompt the user to authenticate if necessary
5838 mKeyguardDelegate.dismiss();
5839 }
5840 });
5841 }
5842 }
5843
5844 public void notifyActivityDrawnForKeyguardLw() {
5845 if (mKeyguardDelegate != null) {
5846 mHandler.post(new Runnable() {
5847 @Override
5848 public void run() {
5849 mKeyguardDelegate.onActivityDrawn();
Daniel Sandler1ce804392012-11-07 15:07:12 -05005850 }
5851 });
Dianne Hackborn90c52de2011-09-23 12:57:44 -07005852 }
5853 }
5854
Jorim Jaggicff0acb2014-03-31 16:35:15 +02005855 @Override
5856 public boolean isKeyguardDrawnLw() {
5857 synchronized (mLock) {
Jeff Brown3ee549c2014-09-22 20:14:39 -07005858 return mKeyguardDrawnOnce;
Jorim Jaggicff0acb2014-03-31 16:35:15 +02005859 }
5860 }
5861
Jorim Jaggi0d674622014-05-21 01:34:15 +02005862 @Override
Jorim Jaggie29b2db2014-05-30 23:17:03 +02005863 public void startKeyguardExitAnimation(long startTime, long fadeoutDuration) {
Jorim Jaggi0d674622014-05-21 01:34:15 +02005864 if (mKeyguardDelegate != null) {
Craig Mautnerc0d2d0a2014-10-31 16:25:15 -07005865 if (DEBUG_KEYGUARD) Slog.d(TAG, "PWM.startKeyguardExitAnimation");
Jorim Jaggie29b2db2014-05-30 23:17:03 +02005866 mKeyguardDelegate.startKeyguardExitAnimation(startTime, fadeoutDuration);
Jorim Jaggi0d674622014-05-21 01:34:15 +02005867 }
5868 }
5869
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005870 void sendCloseSystemWindows() {
Jorim Jaggib10e33f2015-02-04 21:57:40 +01005871 PhoneWindow.sendCloseSystemWindows(mContext, null);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005872 }
5873
5874 void sendCloseSystemWindows(String reason) {
Jorim Jaggib10e33f2015-02-04 21:57:40 +01005875 PhoneWindow.sendCloseSystemWindows(mContext, reason);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005876 }
Mitsuru Oshima831d0d92009-06-16 18:27:18 -07005877
Jeff Brown01a98dd2011-09-20 15:08:29 -07005878 @Override
5879 public int rotationForOrientationLw(int orientation, int lastRotation) {
Daniel Sandler2ed6ad62011-02-22 14:54:17 -05005880 if (false) {
5881 Slog.v(TAG, "rotationForOrientationLw(orient="
5882 + orientation + ", last=" + lastRotation
5883 + "); user=" + mUserRotation + " "
5884 + ((mUserRotationMode == WindowManagerPolicy.USER_ROTATION_LOCKED)
5885 ? "USER_ROTATION_LOCKED" : "")
5886 );
5887 }
5888
Craig Mautner46ac6fa2013-08-01 10:06:34 -07005889 if (mForceDefaultOrientation) {
5890 return Surface.ROTATION_0;
5891 }
5892
The Android Open Source Project0727d222009-03-11 12:11:58 -07005893 synchronized (mLock) {
Jeff Brownc0347aa2011-09-23 17:26:09 -07005894 int sensorRotation = mOrientationListener.getProposedRotation(); // may be -1
5895 if (sensorRotation < 0) {
Jeff Brown0f862b42012-09-27 21:11:01 -07005896 sensorRotation = lastRotation;
Jeff Brownc0347aa2011-09-23 17:26:09 -07005897 }
Jeff Brown01a98dd2011-09-20 15:08:29 -07005898
Jeff Browndec6cf42011-11-15 14:08:20 -08005899 final int preferredRotation;
Jeff Brown2e7760e2012-04-11 15:14:55 -07005900 if (mLidState == LID_OPEN && mLidOpenRotation >= 0) {
Jeff Brown01a98dd2011-09-20 15:08:29 -07005901 // Ignore sensor when lid switch is open and rotation is forced.
5902 preferredRotation = mLidOpenRotation;
5903 } else if (mDockMode == Intent.EXTRA_DOCK_STATE_CAR
Jeff Brownc0347aa2011-09-23 17:26:09 -07005904 && (mCarDockEnablesAccelerometer || mCarDockRotation >= 0)) {
Jeff Brown01a98dd2011-09-20 15:08:29 -07005905 // Ignore sensor when in car dock unless explicitly enabled.
5906 // This case can override the behavior of NOSENSOR, and can also
5907 // enable 180 degree rotation while docked.
Jeff Brownc0347aa2011-09-23 17:26:09 -07005908 preferredRotation = mCarDockEnablesAccelerometer
Jeff Brown01a98dd2011-09-20 15:08:29 -07005909 ? sensorRotation : mCarDockRotation;
Jeff Brown1a693182011-11-08 14:44:16 -08005910 } else if ((mDockMode == Intent.EXTRA_DOCK_STATE_DESK
5911 || mDockMode == Intent.EXTRA_DOCK_STATE_LE_DESK
5912 || mDockMode == Intent.EXTRA_DOCK_STATE_HE_DESK)
Jeff Brownc0347aa2011-09-23 17:26:09 -07005913 && (mDeskDockEnablesAccelerometer || mDeskDockRotation >= 0)) {
Jeff Brown01a98dd2011-09-20 15:08:29 -07005914 // Ignore sensor when in desk dock unless explicitly enabled.
5915 // This case can override the behavior of NOSENSOR, and can also
5916 // enable 180 degree rotation while docked.
Jeff Brownc0347aa2011-09-23 17:26:09 -07005917 preferredRotation = mDeskDockEnablesAccelerometer
Jeff Brown01a98dd2011-09-20 15:08:29 -07005918 ? sensorRotation : mDeskDockRotation;
Jeff Brownc82c89ed2013-04-17 17:18:15 -07005919 } else if (mHdmiPlugged && mDemoHdmiRotationLock) {
5920 // Ignore sensor when plugged into HDMI when demo HDMI rotation lock enabled.
Jeff Browneb3e4b92011-12-06 19:54:24 -08005921 // Note that the dock orientation overrides the HDMI orientation.
Jeff Brownc82c89ed2013-04-17 17:18:15 -07005922 preferredRotation = mDemoHdmiRotation;
5923 } else if (mHdmiPlugged && mDockMode == Intent.EXTRA_DOCK_STATE_UNDOCKED
5924 && mUndockedHdmiRotation >= 0) {
5925 // Ignore sensor when plugged into HDMI and an undocked orientation has
5926 // been specified in the configuration (only for legacy devices without
5927 // full multi-display support).
5928 // Note that the dock orientation overrides the HDMI orientation.
5929 preferredRotation = mUndockedHdmiRotation;
Chong Zhangae6119ff2014-11-11 18:54:39 -08005930 } else if (mDemoRotationLock) {
5931 // Ignore sensor when demo rotation lock is enabled.
5932 // Note that the dock orientation and HDMI rotation lock override this.
5933 preferredRotation = mDemoRotation;
Dianne Hackbornb9ec1ac2013-04-10 17:34:25 -07005934 } else if (orientation == ActivityInfo.SCREEN_ORIENTATION_LOCKED) {
5935 // Application just wants to remain locked in the last rotation.
5936 preferredRotation = lastRotation;
Jeff Brownbcdfc622014-03-06 19:13:04 -08005937 } else if (!mSupportAutoRotation) {
5938 // If we don't support auto-rotation then bail out here and ignore
5939 // the sensor and any rotation lock settings.
5940 preferredRotation = -1;
Jeff Brown207673cd2012-06-05 17:47:11 -07005941 } else if ((mUserRotationMode == WindowManagerPolicy.USER_ROTATION_FREE
Jeff Brown01a98dd2011-09-20 15:08:29 -07005942 && (orientation == ActivityInfo.SCREEN_ORIENTATION_USER
Dianne Hackbornb9ec1ac2013-04-10 17:34:25 -07005943 || orientation == ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED
5944 || orientation == ActivityInfo.SCREEN_ORIENTATION_USER_LANDSCAPE
5945 || orientation == ActivityInfo.SCREEN_ORIENTATION_USER_PORTRAIT
5946 || orientation == ActivityInfo.SCREEN_ORIENTATION_FULL_USER))
Jeff Brown01a98dd2011-09-20 15:08:29 -07005947 || orientation == ActivityInfo.SCREEN_ORIENTATION_SENSOR
5948 || orientation == ActivityInfo.SCREEN_ORIENTATION_FULL_SENSOR
5949 || orientation == ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE
5950 || orientation == ActivityInfo.SCREEN_ORIENTATION_SENSOR_PORTRAIT) {
5951 // Otherwise, use sensor only if requested by the application or enabled
5952 // by default for USER or UNSPECIFIED modes. Does not apply to NOSENSOR.
Jeff Brownd3187e32011-09-21 19:26:44 -07005953 if (mAllowAllRotations < 0) {
5954 // Can't read this during init() because the context doesn't
5955 // have display metrics at that time so we cannot determine
5956 // tablet vs. phone then.
5957 mAllowAllRotations = mContext.getResources().getBoolean(
5958 com.android.internal.R.bool.config_allowAllRotations) ? 1 : 0;
5959 }
Jeff Brown01a98dd2011-09-20 15:08:29 -07005960 if (sensorRotation != Surface.ROTATION_180
Jeff Brownd3187e32011-09-21 19:26:44 -07005961 || mAllowAllRotations == 1
Dianne Hackbornb9ec1ac2013-04-10 17:34:25 -07005962 || orientation == ActivityInfo.SCREEN_ORIENTATION_FULL_SENSOR
5963 || orientation == ActivityInfo.SCREEN_ORIENTATION_FULL_USER) {
Jeff Brown01a98dd2011-09-20 15:08:29 -07005964 preferredRotation = sensorRotation;
5965 } else {
5966 preferredRotation = lastRotation;
5967 }
Jeff Brown207673cd2012-06-05 17:47:11 -07005968 } else if (mUserRotationMode == WindowManagerPolicy.USER_ROTATION_LOCKED
5969 && orientation != ActivityInfo.SCREEN_ORIENTATION_NOSENSOR) {
5970 // Apply rotation lock. Does not apply to NOSENSOR.
5971 // The idea is that the user rotation expresses a weak preference for the direction
5972 // of gravity and as NOSENSOR is never affected by gravity, then neither should
5973 // NOSENSOR be affected by rotation lock (although it will be affected by docks).
Jeff Brown4dfce202011-10-05 12:00:10 -07005974 preferredRotation = mUserRotation;
Jeff Browndec6cf42011-11-15 14:08:20 -08005975 } else {
5976 // No overriding preference.
5977 // We will do exactly what the application asked us to do.
5978 preferredRotation = -1;
Jeff Brown01a98dd2011-09-20 15:08:29 -07005979 }
5980
Dianne Hackborne5439f22010-10-02 16:53:50 -07005981 switch (orientation) {
5982 case ActivityInfo.SCREEN_ORIENTATION_PORTRAIT:
Jeff Browndec6cf42011-11-15 14:08:20 -08005983 // Return portrait unless overridden.
5984 if (isAnyPortrait(preferredRotation)) {
5985 return preferredRotation;
5986 }
Dianne Hackborne5439f22010-10-02 16:53:50 -07005987 return mPortraitRotation;
Dianne Hackborne5439f22010-10-02 16:53:50 -07005988
Jeff Brown01a98dd2011-09-20 15:08:29 -07005989 case ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE:
Jeff Browndec6cf42011-11-15 14:08:20 -08005990 // Return landscape unless overridden.
5991 if (isLandscapeOrSeascape(preferredRotation)) {
5992 return preferredRotation;
5993 }
Jeff Brown01a98dd2011-09-20 15:08:29 -07005994 return mLandscapeRotation;
5995
5996 case ActivityInfo.SCREEN_ORIENTATION_REVERSE_PORTRAIT:
Jeff Browndec6cf42011-11-15 14:08:20 -08005997 // Return reverse portrait unless overridden.
5998 if (isAnyPortrait(preferredRotation)) {
5999 return preferredRotation;
6000 }
Jeff Brown01a98dd2011-09-20 15:08:29 -07006001 return mUpsideDownRotation;
6002
6003 case ActivityInfo.SCREEN_ORIENTATION_REVERSE_LANDSCAPE:
Jeff Browndec6cf42011-11-15 14:08:20 -08006004 // Return seascape unless overridden.
6005 if (isLandscapeOrSeascape(preferredRotation)) {
6006 return preferredRotation;
6007 }
Jeff Brown01a98dd2011-09-20 15:08:29 -07006008 return mSeascapeRotation;
6009
6010 case ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE:
Dianne Hackbornb9ec1ac2013-04-10 17:34:25 -07006011 case ActivityInfo.SCREEN_ORIENTATION_USER_LANDSCAPE:
Jeff Brown01a98dd2011-09-20 15:08:29 -07006012 // Return either landscape rotation.
6013 if (isLandscapeOrSeascape(preferredRotation)) {
6014 return preferredRotation;
6015 }
6016 if (isLandscapeOrSeascape(lastRotation)) {
Jeff Brown4519f072011-01-23 13:16:01 -08006017 return lastRotation;
6018 }
Jeff Brown01a98dd2011-09-20 15:08:29 -07006019 return mLandscapeRotation;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006020
Jeff Brown01a98dd2011-09-20 15:08:29 -07006021 case ActivityInfo.SCREEN_ORIENTATION_SENSOR_PORTRAIT:
Dianne Hackbornb9ec1ac2013-04-10 17:34:25 -07006022 case ActivityInfo.SCREEN_ORIENTATION_USER_PORTRAIT:
Jeff Brown01a98dd2011-09-20 15:08:29 -07006023 // Return either portrait rotation.
6024 if (isAnyPortrait(preferredRotation)) {
6025 return preferredRotation;
6026 }
6027 if (isAnyPortrait(lastRotation)) {
6028 return lastRotation;
6029 }
6030 return mPortraitRotation;
6031
6032 default:
Jeff Brown4dfce202011-10-05 12:00:10 -07006033 // For USER, UNSPECIFIED, NOSENSOR, SENSOR and FULL_SENSOR,
6034 // just return the preferred orientation we already calculated.
Jeff Brown01a98dd2011-09-20 15:08:29 -07006035 if (preferredRotation >= 0) {
6036 return preferredRotation;
6037 }
Dianne Hackborndacea8c2011-04-21 17:26:39 -07006038 return Surface.ROTATION_0;
Daniel Sandlere7e5ac22011-02-22 16:10:21 -05006039 }
6040 }
Steve Howarda7bfe6a2010-09-23 16:47:49 -07006041 }
6042
Jeff Brown01a98dd2011-09-20 15:08:29 -07006043 @Override
6044 public boolean rotationHasCompatibleMetricsLw(int orientation, int rotation) {
6045 switch (orientation) {
6046 case ActivityInfo.SCREEN_ORIENTATION_PORTRAIT:
6047 case ActivityInfo.SCREEN_ORIENTATION_REVERSE_PORTRAIT:
6048 case ActivityInfo.SCREEN_ORIENTATION_SENSOR_PORTRAIT:
6049 return isAnyPortrait(rotation);
6050
6051 case ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE:
6052 case ActivityInfo.SCREEN_ORIENTATION_REVERSE_LANDSCAPE:
6053 case ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE:
6054 return isLandscapeOrSeascape(rotation);
6055
6056 default:
6057 return true;
6058 }
Steve Howarda7bfe6a2010-09-23 16:47:49 -07006059 }
6060
Jeff Brownc0347aa2011-09-23 17:26:09 -07006061 @Override
6062 public void setRotationLw(int rotation) {
6063 mOrientationListener.setCurrentRotation(rotation);
6064 }
6065
Jeff Brown01a98dd2011-09-20 15:08:29 -07006066 private boolean isLandscapeOrSeascape(int rotation) {
6067 return rotation == mLandscapeRotation || rotation == mSeascapeRotation;
Dianne Hackborne5439f22010-10-02 16:53:50 -07006068 }
6069
Jeff Brown01a98dd2011-09-20 15:08:29 -07006070 private boolean isAnyPortrait(int rotation) {
6071 return rotation == mPortraitRotation || rotation == mUpsideDownRotation;
Dianne Hackborne5439f22010-10-02 16:53:50 -07006072 }
6073
Jose Lima9546b202014-07-02 17:21:51 -07006074 @Override
Svetoslav Ganov80943d82013-01-02 10:25:37 -08006075 public int getUserRotationMode() {
6076 return Settings.System.getIntForUser(mContext.getContentResolver(),
Brett Chabot7e55c402013-05-16 19:38:08 -07006077 Settings.System.ACCELEROMETER_ROTATION, 0, UserHandle.USER_CURRENT) != 0 ?
6078 WindowManagerPolicy.USER_ROTATION_FREE :
6079 WindowManagerPolicy.USER_ROTATION_LOCKED;
Svetoslav Ganov80943d82013-01-02 10:25:37 -08006080 }
Daniel Sandlerb73617d2010-08-17 00:41:00 -04006081
6082 // User rotation: to be used when all else fails in assigning an orientation to the device
Jose Lima9546b202014-07-02 17:21:51 -07006083 @Override
Daniel Sandlerb73617d2010-08-17 00:41:00 -04006084 public void setUserRotationMode(int mode, int rot) {
6085 ContentResolver res = mContext.getContentResolver();
Daniel Sandler2ed6ad62011-02-22 14:54:17 -05006086
6087 // mUserRotationMode and mUserRotation will be assigned by the content observer
Daniel Sandlerb73617d2010-08-17 00:41:00 -04006088 if (mode == WindowManagerPolicy.USER_ROTATION_LOCKED) {
Christopher Tate5e08af02012-09-21 17:17:22 -07006089 Settings.System.putIntForUser(res,
Daniel Sandlerb73617d2010-08-17 00:41:00 -04006090 Settings.System.USER_ROTATION,
Christopher Tate5e08af02012-09-21 17:17:22 -07006091 rot,
6092 UserHandle.USER_CURRENT);
6093 Settings.System.putIntForUser(res,
Daniel Sandler2ed6ad62011-02-22 14:54:17 -05006094 Settings.System.ACCELEROMETER_ROTATION,
Christopher Tate5e08af02012-09-21 17:17:22 -07006095 0,
6096 UserHandle.USER_CURRENT);
Daniel Sandlerb73617d2010-08-17 00:41:00 -04006097 } else {
Christopher Tate5e08af02012-09-21 17:17:22 -07006098 Settings.System.putIntForUser(res,
Daniel Sandlerb73617d2010-08-17 00:41:00 -04006099 Settings.System.ACCELEROMETER_ROTATION,
Christopher Tate5e08af02012-09-21 17:17:22 -07006100 1,
6101 UserHandle.USER_CURRENT);
Daniel Sandlerb73617d2010-08-17 00:41:00 -04006102 }
6103 }
6104
Jose Lima9546b202014-07-02 17:21:51 -07006105 @Override
Jeff Brownac143512012-04-05 18:57:33 -07006106 public void setSafeMode(boolean safeMode) {
6107 mSafeMode = safeMode;
6108 performHapticFeedbackLw(null, safeMode
6109 ? HapticFeedbackConstants.SAFE_MODE_ENABLED
6110 : HapticFeedbackConstants.SAFE_MODE_DISABLED, true);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006111 }
Craig Mautnereda67292013-04-28 13:50:14 -07006112
Dianne Hackborn181ceb52009-08-27 22:16:40 -07006113 static long[] getLongIntArray(Resources r, int resid) {
6114 int[] ar = r.getIntArray(resid);
6115 if (ar == null) {
6116 return null;
6117 }
6118 long[] out = new long[ar.length];
6119 for (int i=0; i<ar.length; i++) {
6120 out[i] = ar[i];
6121 }
6122 return out;
6123 }
Craig Mautnereda67292013-04-28 13:50:14 -07006124
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006125 /** {@inheritDoc} */
Craig Mautnereda67292013-04-28 13:50:14 -07006126 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006127 public void systemReady() {
Jim Millerab954542014-10-10 18:21:49 -07006128 mKeyguardDelegate = new KeyguardServiceDelegate(mContext);
Mike Lockwooded8902d2013-11-15 11:01:47 -08006129 mKeyguardDelegate.onSystemReady();
6130
Michael Wright3818c922014-09-02 13:59:07 -07006131 readCameraLensCoverState();
Jeff Brown4f5fa282014-06-12 19:19:15 -07006132 updateUiMode();
Adrian Roos3542f7d2015-07-13 15:57:53 -07006133 boolean bindKeyguardNow;
Dianne Hackbornb1a79802009-09-29 15:18:31 -07006134 synchronized (mLock) {
6135 updateOrientationListenerLp();
Dianne Hackbornc777e072010-02-12 13:07:59 -08006136 mSystemReady = true;
6137 mHandler.post(new Runnable() {
Craig Mautnereda67292013-04-28 13:50:14 -07006138 @Override
Dianne Hackbornc777e072010-02-12 13:07:59 -08006139 public void run() {
6140 updateSettings();
6141 }
6142 });
Adrian Roos3542f7d2015-07-13 15:57:53 -07006143
6144 bindKeyguardNow = mDeferBindKeyguard;
6145 if (bindKeyguardNow) {
6146 // systemBooted ran but wasn't able to bind to the Keyguard, we'll do it now.
6147 mDeferBindKeyguard = false;
6148 }
6149 }
6150
6151 if (bindKeyguardNow) {
6152 mKeyguardDelegate.bindService(mContext);
6153 mKeyguardDelegate.onBootCompleted();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006154 }
Michael Wrighta4d22d72015-09-16 23:19:26 +01006155 mSystemGestures.systemReady();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006156 }
Dianne Hackborn661cd522011-08-22 00:26:20 -07006157
Dianne Hackbornba24e4d2011-09-01 11:17:06 -07006158 /** {@inheritDoc} */
Jose Lima9546b202014-07-02 17:21:51 -07006159 @Override
Dianne Hackbornba24e4d2011-09-01 11:17:06 -07006160 public void systemBooted() {
Adrian Roos3542f7d2015-07-13 15:57:53 -07006161 boolean bindKeyguardNow = false;
6162 synchronized (mLock) {
6163 // Time to bind Keyguard; take care to only bind it once, either here if ready or
6164 // in systemReady if not.
6165 if (mKeyguardDelegate != null) {
6166 bindKeyguardNow = true;
6167 } else {
6168 // Because mKeyguardDelegate is null, we know that the synchronized block in
6169 // systemReady didn't run yet and setting this will actually have an effect.
6170 mDeferBindKeyguard = true;
6171 }
6172 }
6173 if (bindKeyguardNow) {
Jason Monk5eeebf52014-09-26 12:36:51 -04006174 mKeyguardDelegate.bindService(mContext);
Jim Millere5f910a2013-10-16 18:15:46 -07006175 mKeyguardDelegate.onBootCompleted();
6176 }
Dianne Hackbornba24e4d2011-09-01 11:17:06 -07006177 synchronized (mLock) {
6178 mSystemBooted = true;
6179 }
Jeff Brown416c49c2015-05-26 19:50:18 -07006180 startedWakingUp();
Jeff Brown36c4db82014-09-19 12:05:31 -07006181 screenTurningOn(null);
Jorim Jaggic0496072015-08-19 15:14:52 -07006182 screenTurnedOn();
Dianne Hackbornba24e4d2011-09-01 11:17:06 -07006183 }
6184
Dianne Hackborn661cd522011-08-22 00:26:20 -07006185 ProgressDialog mBootMsgDialog = null;
6186
6187 /** {@inheritDoc} */
Jose Lima9546b202014-07-02 17:21:51 -07006188 @Override
Dianne Hackborn661cd522011-08-22 00:26:20 -07006189 public void showBootMessage(final CharSequence msg, final boolean always) {
6190 mHandler.post(new Runnable() {
6191 @Override public void run() {
6192 if (mBootMsgDialog == null) {
Craig Stout4c0cb8a2014-04-04 13:03:10 -07006193 int theme;
6194 if (mContext.getPackageManager().hasSystemFeature(
6195 PackageManager.FEATURE_WATCH)) {
6196 theme = com.android.internal.R.style.Theme_Micro_Dialog_Alert;
6197 } else if (mContext.getPackageManager().hasSystemFeature(
6198 PackageManager.FEATURE_TELEVISION)) {
6199 theme = com.android.internal.R.style.Theme_Leanback_Dialog_Alert;
6200 } else {
6201 theme = 0;
6202 }
Vinod Krishnanfa8fc412014-04-18 14:35:53 -07006203
6204 mBootMsgDialog = new ProgressDialog(mContext, theme) {
Dianne Hackborn295e3c22011-08-25 13:19:08 -07006205 // This dialog will consume all events coming in to
6206 // it, to avoid it trying to do things too early in boot.
6207 @Override public boolean dispatchKeyEvent(KeyEvent event) {
6208 return true;
6209 }
6210 @Override public boolean dispatchKeyShortcutEvent(KeyEvent event) {
6211 return true;
6212 }
6213 @Override public boolean dispatchTouchEvent(MotionEvent ev) {
6214 return true;
6215 }
6216 @Override public boolean dispatchTrackballEvent(MotionEvent ev) {
6217 return true;
6218 }
6219 @Override public boolean dispatchGenericMotionEvent(MotionEvent ev) {
6220 return true;
6221 }
6222 @Override public boolean dispatchPopulateAccessibilityEvent(
6223 AccessibilityEvent event) {
6224 return true;
6225 }
6226 };
Jeff Hao9f60c082014-10-28 18:51:07 -07006227 if (mContext.getPackageManager().isUpgrade()) {
6228 mBootMsgDialog.setTitle(R.string.android_upgrading_title);
6229 } else {
6230 mBootMsgDialog.setTitle(R.string.android_start_title);
6231 }
Dianne Hackborn661cd522011-08-22 00:26:20 -07006232 mBootMsgDialog.setProgressStyle(ProgressDialog.STYLE_SPINNER);
6233 mBootMsgDialog.setIndeterminate(true);
6234 mBootMsgDialog.getWindow().setType(
Dianne Hackborn29aae6f2011-08-18 18:30:09 -07006235 WindowManager.LayoutParams.TYPE_BOOT_PROGRESS);
Dianne Hackborn661cd522011-08-22 00:26:20 -07006236 mBootMsgDialog.getWindow().addFlags(
6237 WindowManager.LayoutParams.FLAG_DIM_BEHIND
6238 | WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN);
6239 mBootMsgDialog.getWindow().setDimAmount(1);
Dianne Hackbornd9efb952011-12-07 14:56:51 -08006240 WindowManager.LayoutParams lp = mBootMsgDialog.getWindow().getAttributes();
6241 lp.screenOrientation = ActivityInfo.SCREEN_ORIENTATION_NOSENSOR;
6242 mBootMsgDialog.getWindow().setAttributes(lp);
Dianne Hackborn661cd522011-08-22 00:26:20 -07006243 mBootMsgDialog.setCancelable(false);
6244 mBootMsgDialog.show();
6245 }
6246 mBootMsgDialog.setMessage(msg);
6247 }
6248 });
6249 }
6250
6251 /** {@inheritDoc} */
Jose Lima9546b202014-07-02 17:21:51 -07006252 @Override
Dianne Hackborn661cd522011-08-22 00:26:20 -07006253 public void hideBootMessages() {
Craig Mautnera631d492014-08-05 15:16:01 -07006254 mHandler.sendEmptyMessage(MSG_HIDE_BOOT_MESSAGE);
Dianne Hackborn661cd522011-08-22 00:26:20 -07006255 }
6256
Mike Lockwood28569302010-01-28 11:54:40 -05006257 /** {@inheritDoc} */
Jose Lima9546b202014-07-02 17:21:51 -07006258 @Override
Mike Lockwood28569302010-01-28 11:54:40 -05006259 public void userActivity() {
Dianne Hackborndf89e652011-10-06 22:35:11 -07006260 // ***************************************
6261 // NOTE NOTE NOTE NOTE NOTE NOTE NOTE NOTE
6262 // ***************************************
6263 // THIS IS CALLED FROM DEEP IN THE POWER MANAGER
6264 // WITH ITS LOCKS HELD.
6265 //
6266 // This code must be VERY careful about the locks
6267 // it acquires.
6268 // In fact, the current code acquires way too many,
6269 // and probably has lurking deadlocks.
6270
Mike Lockwood28569302010-01-28 11:54:40 -05006271 synchronized (mScreenLockTimeout) {
6272 if (mLockScreenTimerActive) {
6273 // reset the timer
6274 mHandler.removeCallbacks(mScreenLockTimeout);
6275 mHandler.postDelayed(mScreenLockTimeout, mLockScreenTimeout);
6276 }
6277 }
Daniel Sandler0601eb72011-04-13 01:01:32 -04006278 }
6279
Adam Cohenf7522022012-10-03 20:03:18 -07006280 class ScreenLockTimeout implements Runnable {
6281 Bundle options;
6282
6283 @Override
Mike Lockwood28569302010-01-28 11:54:40 -05006284 public void run() {
6285 synchronized (this) {
6286 if (localLOGV) Log.v(TAG, "mScreenLockTimeout activating keyguard");
Jim Miller5ecd8112013-01-09 18:50:26 -08006287 if (mKeyguardDelegate != null) {
6288 mKeyguardDelegate.doKeyguardTimeout(options);
Mike Lockwood3a74bd32011-08-12 13:55:22 -07006289 }
Mike Lockwood28569302010-01-28 11:54:40 -05006290 mLockScreenTimerActive = false;
Adam Cohenf7522022012-10-03 20:03:18 -07006291 options = null;
Mike Lockwood28569302010-01-28 11:54:40 -05006292 }
6293 }
Mike Lockwood28569302010-01-28 11:54:40 -05006294
Adam Cohenf7522022012-10-03 20:03:18 -07006295 public void setLockOptions(Bundle options) {
6296 this.options = options;
6297 }
6298 }
6299
6300 ScreenLockTimeout mScreenLockTimeout = new ScreenLockTimeout();
6301
Jose Lima9546b202014-07-02 17:21:51 -07006302 @Override
Adam Cohenf7522022012-10-03 20:03:18 -07006303 public void lockNow(Bundle options) {
Jim Miller93c518e2012-01-17 15:55:31 -08006304 mContext.enforceCallingOrSelfPermission(android.Manifest.permission.DEVICE_POWER, null);
6305 mHandler.removeCallbacks(mScreenLockTimeout);
Adam Cohenf7522022012-10-03 20:03:18 -07006306 if (options != null) {
6307 // In case multiple calls are made to lockNow, we don't wipe out the options
6308 // until the runnable actually executes.
6309 mScreenLockTimeout.setLockOptions(options);
6310 }
Jim Miller93c518e2012-01-17 15:55:31 -08006311 mHandler.post(mScreenLockTimeout);
6312 }
6313
Mike Lockwood28569302010-01-28 11:54:40 -05006314 private void updateLockScreenTimeout() {
6315 synchronized (mScreenLockTimeout) {
Jeff Brown3ee549c2014-09-22 20:14:39 -07006316 boolean enable = (mAllowLockscreenWhenOn && mAwake &&
Jim Miller5ecd8112013-01-09 18:50:26 -08006317 mKeyguardDelegate != null && mKeyguardDelegate.isSecure());
Mike Lockwood28569302010-01-28 11:54:40 -05006318 if (mLockScreenTimerActive != enable) {
6319 if (enable) {
6320 if (localLOGV) Log.v(TAG, "setting lockscreen timer");
6321 mHandler.postDelayed(mScreenLockTimeout, mLockScreenTimeout);
6322 } else {
6323 if (localLOGV) Log.v(TAG, "clearing lockscreen timer");
6324 mHandler.removeCallbacks(mScreenLockTimeout);
6325 }
6326 mLockScreenTimerActive = enable;
6327 }
6328 }
6329 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006330
Jeff Brown061ea992015-04-17 19:55:47 -07006331 private void updateDreamingSleepToken(boolean acquire) {
6332 if (acquire) {
6333 if (mDreamingSleepToken == null) {
6334 mDreamingSleepToken = mActivityManagerInternal.acquireSleepToken("Dream");
6335 }
6336 } else {
6337 if (mDreamingSleepToken != null) {
6338 mDreamingSleepToken.release();
Jeff Brown48d1b142015-06-10 16:36:03 -07006339 mDreamingSleepToken = null;
6340 }
6341 }
6342 }
6343
6344 private void updateScreenOffSleepToken(boolean acquire) {
6345 if (acquire) {
6346 if (mScreenOffSleepToken == null) {
6347 mScreenOffSleepToken = mActivityManagerInternal.acquireSleepToken("ScreenOff");
6348 }
6349 } else {
6350 if (mScreenOffSleepToken != null) {
6351 mScreenOffSleepToken.release();
6352 mScreenOffSleepToken = null;
Jeff Brown061ea992015-04-17 19:55:47 -07006353 }
6354 }
6355 }
6356
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006357 /** {@inheritDoc} */
Craig Mautnereda67292013-04-28 13:50:14 -07006358 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006359 public void enableScreenAfterBoot() {
6360 readLidState();
Jeff Brownc458ce92012-04-30 14:58:40 -07006361 applyLidSwitchState();
Jeff Brown01a98dd2011-09-20 15:08:29 -07006362 updateRotation(true);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006363 }
Dianne Hackbornf54c8f92009-09-19 14:03:57 -07006364
Jeff Brownc458ce92012-04-30 14:58:40 -07006365 private void applyLidSwitchState() {
Jeff Brownc458ce92012-04-30 14:58:40 -07006366 if (mLidState == LID_CLOSED && mLidControlsSleep) {
Jeff Brown6d8fd272014-05-20 21:24:38 -07006367 mPowerManager.goToSleep(SystemClock.uptimeMillis(),
Jeff Brownc12035c2014-08-13 18:52:25 -07006368 PowerManager.GO_TO_SLEEP_REASON_LID_SWITCH,
Jeff Brown6d8fd272014-05-20 21:24:38 -07006369 PowerManager.GO_TO_SLEEP_FLAG_NO_DOZE);
Jeff Brownc458ce92012-04-30 14:58:40 -07006370 }
Jeff Browna20dda42014-05-27 20:57:24 -07006371
6372 synchronized (mLock) {
6373 updateWakeGestureListenerLp();
6374 }
Jeff Brown01a98dd2011-09-20 15:08:29 -07006375 }
6376
Jeff Brown4f5fa282014-06-12 19:19:15 -07006377 void updateUiMode() {
6378 if (mUiModeManager == null) {
6379 mUiModeManager = IUiModeManager.Stub.asInterface(
6380 ServiceManager.getService(Context.UI_MODE_SERVICE));
6381 }
6382 try {
6383 mUiMode = mUiModeManager.getCurrentModeType();
6384 } catch (RemoteException e) {
6385 }
6386 }
6387
Jeff Brown01a98dd2011-09-20 15:08:29 -07006388 void updateRotation(boolean alwaysSendConfiguration) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006389 try {
6390 //set orientation on WindowManager
Dianne Hackbornf87d1962012-04-04 12:48:24 -07006391 mWindowManager.updateRotation(alwaysSendConfiguration, false);
6392 } catch (RemoteException e) {
6393 // Ignore
6394 }
6395 }
6396
6397 void updateRotation(boolean alwaysSendConfiguration, boolean forceRelayout) {
6398 try {
6399 //set orientation on WindowManager
6400 mWindowManager.updateRotation(alwaysSendConfiguration, forceRelayout);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006401 } catch (RemoteException e) {
6402 // Ignore
6403 }
6404 }
6405
Daniel Sandler6396c722013-04-16 20:19:09 -04006406 /**
6407 * Return an Intent to launch the currently active dock app as home. Returns
6408 * null if the standard home should be launched, which is the case if any of the following is
6409 * true:
6410 * <ul>
6411 * <li>The device is not in either car mode or desk mode
keunyounga7710492015-09-23 11:33:58 -07006412 * <li>The device is in car mode but mEnableCarDockHomeCapture is false
Daniel Sandler6396c722013-04-16 20:19:09 -04006413 * <li>The device is in desk mode but ENABLE_DESK_DOCK_HOME_CAPTURE is false
6414 * <li>The device is in car mode but there's no CAR_DOCK app with METADATA_DOCK_HOME
6415 * <li>The device is in desk mode but there's no DESK_DOCK app with METADATA_DOCK_HOME
6416 * </ul>
Craig Mautnereda67292013-04-28 13:50:14 -07006417 * @return A dock intent.
Daniel Sandler6396c722013-04-16 20:19:09 -04006418 */
6419 Intent createHomeDockIntent() {
6420 Intent intent = null;
6421
6422 // What home does is based on the mode, not the dock state. That
6423 // is, when in car mode you should be taken to car home regardless
6424 // of whether we are actually in a car dock.
6425 if (mUiMode == Configuration.UI_MODE_TYPE_CAR) {
keunyounga7710492015-09-23 11:33:58 -07006426 if (mEnableCarDockHomeCapture) {
Daniel Sandler6396c722013-04-16 20:19:09 -04006427 intent = mCarDockIntent;
6428 }
6429 } else if (mUiMode == Configuration.UI_MODE_TYPE_DESK) {
6430 if (ENABLE_DESK_DOCK_HOME_CAPTURE) {
6431 intent = mDeskDockIntent;
6432 }
Jeff Brown4f5fa282014-06-12 19:19:15 -07006433 } else if (mUiMode == Configuration.UI_MODE_TYPE_WATCH
6434 && (mDockMode == Intent.EXTRA_DOCK_STATE_DESK
6435 || mDockMode == Intent.EXTRA_DOCK_STATE_HE_DESK
6436 || mDockMode == Intent.EXTRA_DOCK_STATE_LE_DESK)) {
6437 // Always launch dock home from home when watch is docked, if it exists.
6438 intent = mDeskDockIntent;
Daniel Sandler6396c722013-04-16 20:19:09 -04006439 }
6440
6441 if (intent == null) {
6442 return null;
6443 }
6444
6445 ActivityInfo ai = null;
6446 ResolveInfo info = mContext.getPackageManager().resolveActivityAsUser(
6447 intent,
John Spurlockf56bef12013-07-09 09:51:46 -04006448 PackageManager.MATCH_DEFAULT_ONLY | PackageManager.GET_META_DATA,
Craig Mautnerd625ab22013-09-06 13:40:31 -07006449 mCurrentUserId);
Daniel Sandler6396c722013-04-16 20:19:09 -04006450 if (info != null) {
6451 ai = info.activityInfo;
6452 }
6453 if (ai != null
6454 && ai.metaData != null
6455 && ai.metaData.getBoolean(Intent.METADATA_DOCK_HOME)) {
6456 intent = new Intent(intent);
6457 intent.setClassName(ai.packageName, ai.name);
6458 return intent;
6459 }
6460
6461 return null;
6462 }
6463
Filip Gruszczynskia483a1d2015-03-17 19:06:58 +00006464 void startDockOrHome(boolean fromHomeKey, boolean awakenFromDreams) {
6465 if (awakenFromDreams) {
6466 awakenDreams();
6467 }
Daniel Sandler6396c722013-04-16 20:19:09 -04006468
6469 Intent dock = createHomeDockIntent();
6470 if (dock != null) {
6471 try {
Bryce Lee01b0c5f2015-02-05 18:24:04 -08006472 if (fromHomeKey) {
6473 dock.putExtra(WindowManagerPolicy.EXTRA_FROM_HOME_KEY, fromHomeKey);
6474 }
Bart Sears8b1c27c2015-03-18 23:51:02 +00006475 startActivityAsUser(dock, UserHandle.CURRENT);
Daniel Sandler6396c722013-04-16 20:19:09 -04006476 return;
6477 } catch (ActivityNotFoundException e) {
6478 }
6479 }
6480
Bryce Lee01b0c5f2015-02-05 18:24:04 -08006481 Intent intent;
6482
6483 if (fromHomeKey) {
6484 intent = new Intent(mHomeIntent);
6485 intent.putExtra(WindowManagerPolicy.EXTRA_FROM_HOME_KEY, fromHomeKey);
6486 } else {
6487 intent = mHomeIntent;
6488 }
6489
Bryce Lee9fc0b6f2015-03-19 21:37:45 +00006490 startActivityAsUser(intent, UserHandle.CURRENT);
Dianne Hackborn39c2d712009-09-22 11:41:31 -07006491 }
Craig Mautnereda67292013-04-28 13:50:14 -07006492
Dianne Hackborn39c2d712009-09-22 11:41:31 -07006493 /**
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006494 * goes to the home screen
6495 * @return whether it did anything
6496 */
6497 boolean goHome() {
Bart Sears8b1c27c2015-03-18 23:51:02 +00006498 if (!isUserSetupComplete()) {
6499 Slog.i(TAG, "Not going home because user setup is in progress.");
6500 return false;
6501 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006502 if (false) {
6503 // This code always brings home to the front.
Dianne Hackborn256dd3b2009-05-19 18:51:21 -07006504 try {
6505 ActivityManagerNative.getDefault().stopAppSwitches();
6506 } catch (RemoteException e) {
6507 }
Dianne Hackborn94a679d2009-07-28 17:51:07 -07006508 sendCloseSystemWindows();
Filip Gruszczynskia483a1d2015-03-17 19:06:58 +00006509 startDockOrHome(false /*fromHomeKey*/, true /* awakenFromDreams */);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006510 } else {
6511 // This code brings home to the front or, if it is already
6512 // at the front, puts the device to sleep.
6513 try {
Wink Savilled2e6a332010-02-12 12:12:06 -08006514 if (SystemProperties.getInt("persist.sys.uts-test-mode", 0) == 1) {
6515 /// Roll back EndcallBehavior as the cupcake design to pass P1 lab entry.
6516 Log.d(TAG, "UTS-TEST-MODE");
6517 } else {
6518 ActivityManagerNative.getDefault().stopAppSwitches();
6519 sendCloseSystemWindows();
Daniel Sandler6396c722013-04-16 20:19:09 -04006520 Intent dock = createHomeDockIntent();
6521 if (dock != null) {
6522 int result = ActivityManagerNative.getDefault()
6523 .startActivityAsUser(null, null, dock,
6524 dock.resolveTypeIfNeeded(mContext.getContentResolver()),
6525 null, null, 0,
6526 ActivityManager.START_FLAG_ONLY_IF_NEEDED,
Jeff Hao1b012d32014-08-20 10:35:34 -07006527 null, null, UserHandle.USER_CURRENT);
Daniel Sandler6396c722013-04-16 20:19:09 -04006528 if (result == ActivityManager.START_RETURN_INTENT_TO_CALLER) {
6529 return false;
6530 }
6531 }
Dianne Hackborn39c2d712009-09-22 11:41:31 -07006532 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006533 int result = ActivityManagerNative.getDefault()
Dianne Hackbornf265ea92013-01-31 15:00:51 -08006534 .startActivityAsUser(null, null, mHomeIntent,
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006535 mHomeIntent.resolveTypeIfNeeded(mContext.getContentResolver()),
Dianne Hackborna4972e92012-03-14 10:38:05 -07006536 null, null, 0,
6537 ActivityManager.START_FLAG_ONLY_IF_NEEDED,
Jeff Hao1b012d32014-08-20 10:35:34 -07006538 null, null, UserHandle.USER_CURRENT);
Dianne Hackborna4972e92012-03-14 10:38:05 -07006539 if (result == ActivityManager.START_RETURN_INTENT_TO_CALLER) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006540 return false;
6541 }
6542 } catch (RemoteException ex) {
6543 // bummer, the activity manager, which is in this process, is dead
6544 }
6545 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006546 return true;
6547 }
Craig Mautnereda67292013-04-28 13:50:14 -07006548
6549 @Override
The Android Open Source Project0727d222009-03-11 12:11:58 -07006550 public void setCurrentOrientationLw(int newOrientation) {
6551 synchronized (mLock) {
6552 if (newOrientation != mCurrentAppOrientation) {
6553 mCurrentAppOrientation = newOrientation;
6554 updateOrientationListenerLp();
6555 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006556 }
6557 }
Amith Yamasanic33cb712010-02-10 15:21:49 -08006558
Svetoslav Ganov7befb7d2012-09-27 16:49:23 -07006559 private void performAuditoryFeedbackForAccessibilityIfNeed() {
6560 if (!isGlobalAccessibilityGestureEnabled()) {
6561 return;
6562 }
6563 AudioManager audioManager = (AudioManager) mContext.getSystemService(
6564 Context.AUDIO_SERVICE);
6565 if (audioManager.isSilentMode()) {
6566 return;
6567 }
6568 Ringtone ringTone = RingtoneManager.getRingtone(mContext,
6569 Settings.System.DEFAULT_NOTIFICATION_URI);
6570 ringTone.setStreamType(AudioManager.STREAM_MUSIC);
6571 ringTone.play();
6572 }
Craig Mautnereda67292013-04-28 13:50:14 -07006573
Bryce Lee584a4452014-10-21 15:55:55 -07006574 private boolean isTheaterModeEnabled() {
6575 return Settings.Global.getInt(mContext.getContentResolver(),
6576 Settings.Global.THEATER_MODE_ON, 0) == 1;
6577 }
6578
Svetoslav Ganov7befb7d2012-09-27 16:49:23 -07006579 private boolean isGlobalAccessibilityGestureEnabled() {
6580 return Settings.Global.getInt(mContext.getContentResolver(),
6581 Settings.Global.ENABLE_ACCESSIBILITY_GLOBAL_GESTURE_ENABLED, 0) == 1;
6582 }
6583
Craig Mautnereda67292013-04-28 13:50:14 -07006584 @Override
The Android Open Source Project0727d222009-03-11 12:11:58 -07006585 public boolean performHapticFeedbackLw(WindowState win, int effectId, boolean always) {
Svetoslav Ganov96179212012-10-10 14:17:45 -07006586 if (!mVibrator.hasVibrator()) {
6587 return false;
6588 }
Christopher Tate5e08af02012-09-21 17:17:22 -07006589 final boolean hapticsDisabled = Settings.System.getIntForUser(mContext.getContentResolver(),
6590 Settings.System.HAPTIC_FEEDBACK_ENABLED, 0, UserHandle.USER_CURRENT) == 0;
Jeff Brown82379ba2014-07-25 19:03:28 -07006591 if (hapticsDisabled && !always) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006592 return false;
6593 }
Amith Yamasanic33cb712010-02-10 15:21:49 -08006594 long[] pattern = null;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006595 switch (effectId) {
6596 case HapticFeedbackConstants.LONG_PRESS:
Amith Yamasanic33cb712010-02-10 15:21:49 -08006597 pattern = mLongPressVibePattern;
6598 break;
Dianne Hackbornb1a79802009-09-29 15:18:31 -07006599 case HapticFeedbackConstants.VIRTUAL_KEY:
Amith Yamasanic33cb712010-02-10 15:21:49 -08006600 pattern = mVirtualKeyVibePattern;
6601 break;
6602 case HapticFeedbackConstants.KEYBOARD_TAP:
6603 pattern = mKeyboardTapVibePattern;
6604 break;
Fabrice Di Meglioeeff63a2013-08-05 12:07:24 -07006605 case HapticFeedbackConstants.CLOCK_TICK:
6606 pattern = mClockTickVibePattern;
6607 break;
Fabrice Di Megliobd9152f2013-10-01 11:21:31 -07006608 case HapticFeedbackConstants.CALENDAR_DATE:
6609 pattern = mCalendarDateVibePattern;
6610 break;
Dianne Hackbornb1a79802009-09-29 15:18:31 -07006611 case HapticFeedbackConstants.SAFE_MODE_DISABLED:
Amith Yamasanic33cb712010-02-10 15:21:49 -08006612 pattern = mSafeModeDisabledVibePattern;
6613 break;
Dianne Hackbornb1a79802009-09-29 15:18:31 -07006614 case HapticFeedbackConstants.SAFE_MODE_ENABLED:
Amith Yamasanic33cb712010-02-10 15:21:49 -08006615 pattern = mSafeModeEnabledVibePattern;
6616 break;
Mady Mellore8608912015-06-05 09:02:55 -07006617 case HapticFeedbackConstants.CONTEXT_CLICK:
6618 pattern = mContextClickVibePattern;
Mady Mellore82067b2015-04-30 09:58:35 -07006619 break;
Amith Yamasanic33cb712010-02-10 15:21:49 -08006620 default:
6621 return false;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006622 }
Dianne Hackbornf265ea92013-01-31 15:00:51 -08006623 int owningUid;
6624 String owningPackage;
6625 if (win != null) {
6626 owningUid = win.getOwningUid();
6627 owningPackage = win.getOwningPackage();
6628 } else {
6629 owningUid = android.os.Process.myUid();
Dianne Hackborn95d78532013-09-11 09:51:14 -07006630 owningPackage = mContext.getOpPackageName();
Dianne Hackbornf265ea92013-01-31 15:00:51 -08006631 }
Amith Yamasanic33cb712010-02-10 15:21:49 -08006632 if (pattern.length == 1) {
6633 // One-shot vibration
John Spurlock7b414672014-07-18 13:02:39 -04006634 mVibrator.vibrate(owningUid, owningPackage, pattern[0], VIBRATION_ATTRIBUTES);
Amith Yamasanic33cb712010-02-10 15:21:49 -08006635 } else {
6636 // Pattern vibration
John Spurlock7b414672014-07-18 13:02:39 -04006637 mVibrator.vibrate(owningUid, owningPackage, pattern, -1, VIBRATION_ATTRIBUTES);
Amith Yamasanic33cb712010-02-10 15:21:49 -08006638 }
6639 return true;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006640 }
Jeff Brownc38c9be2012-10-04 13:16:19 -07006641
6642 @Override
6643 public void keepScreenOnStartedLw() {
Daniel Sandler0601eb72011-04-13 01:01:32 -04006644 }
6645
Jeff Brownc38c9be2012-10-04 13:16:19 -07006646 @Override
6647 public void keepScreenOnStoppedLw() {
Jim Millerab954542014-10-10 18:21:49 -07006648 if (isKeyguardShowingAndNotOccluded()) {
Jim Miller25190572013-02-28 17:36:24 -08006649 mPowerManager.userActivity(SystemClock.uptimeMillis(), false);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006650 }
6651 }
Mike Lockwoodfcb39242009-10-21 23:01:07 -04006652
Dianne Hackborndf89e652011-10-06 22:35:11 -07006653 private int updateSystemUiVisibilityLw() {
Joe Onorato664644d2011-01-23 17:53:23 -08006654 // If there is no window focused, there will be nobody to handle the events
6655 // anyway, so just hang on in whatever state we're in until things settle down.
Adrian Roos53f28ec2014-10-29 17:26:12 +01006656 final WindowState win = mFocusedWindow != null ? mFocusedWindow
6657 : mTopFullscreenOpaqueWindowState;
John Spurlock79da8332013-09-20 12:04:47 -04006658 if (win == null) {
Dianne Hackborndf89e652011-10-06 22:35:11 -07006659 return 0;
6660 }
Jorim Jaggi380ecb82014-03-14 17:25:20 +01006661 if ((win.getAttrs().privateFlags & PRIVATE_FLAG_KEYGUARD) != 0 && mHideLockScreen == true) {
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07006662 // We are updating at a point where the keyguard has gotten
6663 // focus, but we were last in a state where the top window is
6664 // hiding it. This is probably because the keyguard as been
6665 // shown while the top window was displayed, so we want to ignore
6666 // it here because this is just a very transient change and it
6667 // will quickly lose focus once it correctly gets hidden.
6668 return 0;
6669 }
John Spurlock32beb2c2013-03-11 10:16:47 -04006670
John Spurlock1db8b682014-02-18 11:18:59 -05006671 int tmpVisibility = PolicyControl.getSystemUiVisibility(win, null)
Dianne Hackborne26ab702011-10-16 13:21:33 -07006672 & ~mResettingSystemUiFlags
6673 & ~mForceClearedSystemUiFlags;
John Spurlock79da8332013-09-20 12:04:47 -04006674 if (mForcingShowNavBar && win.getSurfaceLayer() < mForcingShowNavBarLayer) {
John Spurlockc6d1c602014-01-17 15:22:06 -05006675 tmpVisibility &= ~PolicyControl.adjustClearableFlags(win, View.SYSTEM_UI_CLEARABLE_FLAGS);
Dianne Hackborn891d3fb2013-01-09 18:31:37 -08006676 }
Thanh Hai Mai6c009f52015-09-01 16:27:32 -07006677
6678 if (mUiMode == Configuration.UI_MODE_TYPE_CAR) {
6679 tmpVisibility |= StatusBarManager.DISABLE_RECENT;
6680 }
6681
Adrian Rooscd3884d2015-02-18 17:25:23 +01006682 tmpVisibility = updateLightStatusBarLw(tmpVisibility);
John Spurlock79da8332013-09-20 12:04:47 -04006683 final int visibility = updateSystemBarsLw(win, mLastSystemUiFlags, tmpVisibility);
John Spurlockad3e6cb2013-04-30 08:47:43 -04006684 final int diff = visibility ^ mLastSystemUiFlags;
John Spurlock79da8332013-09-20 12:04:47 -04006685 final boolean needsMenu = win.getNeedsMenuLw(mTopFullscreenOpaqueWindowState);
Dianne Hackborne0f085d2011-11-30 18:41:15 -08006686 if (diff == 0 && mLastFocusNeedsMenu == needsMenu
John Spurlock79da8332013-09-20 12:04:47 -04006687 && mFocusedApp == win.getAppToken()) {
Dianne Hackborndf89e652011-10-06 22:35:11 -07006688 return 0;
6689 }
Dianne Hackborne26ab702011-10-16 13:21:33 -07006690 mLastSystemUiFlags = visibility;
Dianne Hackborn4eff8d32011-11-10 19:38:40 -08006691 mLastFocusNeedsMenu = needsMenu;
John Spurlock79da8332013-09-20 12:04:47 -04006692 mFocusedApp = win.getAppToken();
Dianne Hackborndf89e652011-10-06 22:35:11 -07006693 mHandler.post(new Runnable() {
Craig Mautnereda67292013-04-28 13:50:14 -07006694 @Override
Dianne Hackborndf89e652011-10-06 22:35:11 -07006695 public void run() {
Dianne Hackborn42e620c2012-06-24 13:20:51 -07006696 try {
6697 IStatusBarService statusbar = getStatusBarService();
6698 if (statusbar != null) {
Adrian Roos53f28ec2014-10-29 17:26:12 +01006699 statusbar.setSystemUiVisibility(visibility, 0xffffffff, win.toString());
Dianne Hackborn42e620c2012-06-24 13:20:51 -07006700 statusbar.topAppWindowChanged(needsMenu);
Joe Onorato664644d2011-01-23 17:53:23 -08006701 }
Dianne Hackborn42e620c2012-06-24 13:20:51 -07006702 } catch (RemoteException e) {
6703 // re-acquire status bar service next time it is needed.
6704 mStatusBarService = null;
Joe Onorato664644d2011-01-23 17:53:23 -08006705 }
Dianne Hackborndf89e652011-10-06 22:35:11 -07006706 }
6707 });
6708 return diff;
Joe Onorato664644d2011-01-23 17:53:23 -08006709 }
6710
Adrian Rooscd3884d2015-02-18 17:25:23 +01006711 private int updateLightStatusBarLw(int vis) {
6712 WindowState statusColorWin = isStatusBarKeyguard() && !mHideLockScreen
6713 ? mStatusBar
6714 : mTopFullscreenOpaqueOrDimmingWindowState;
6715
6716 if (statusColorWin != null) {
6717 if (statusColorWin == mTopFullscreenOpaqueWindowState) {
6718 // If the top fullscreen-or-dimming window is also the top fullscreen, respect
6719 // its light flag.
6720 vis &= ~View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR;
6721 vis |= PolicyControl.getSystemUiVisibility(statusColorWin, null)
6722 & View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR;
6723 } else if (statusColorWin != null && statusColorWin.isDimming()) {
6724 // Otherwise if it's dimming, clear the light flag.
6725 vis &= ~View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR;
6726 }
6727 }
6728 return vis;
6729 }
6730
John Spurlock79da8332013-09-20 12:04:47 -04006731 private int updateSystemBarsLw(WindowState win, int oldVis, int vis) {
Wale Ogunwale6e94a9e2015-10-07 15:35:49 -07006732 final boolean dockedStackVisible = mWindowManagerInternal.isStackVisible(DOCKED_STACK_ID);
6733 final boolean freeformStackVisible =
6734 mWindowManagerInternal.isStackVisible(FREEFORM_WORKSPACE_STACK_ID);
6735 final boolean forceShowSystemBars = dockedStackVisible || freeformStackVisible;
6736 // TODO(multi-window): Update to force opaque independently for status bar and nav bar.
6737 // This will require refactoring the code to have separate vis flag for each bar so it can
6738 // be adjusted independently.
6739 final boolean forceOpaqueSystemBars = forceShowSystemBars;
6740
John Spurlockbd957402013-10-03 11:38:39 -04006741 // apply translucent bar vis flags
Jorim Jaggi380ecb82014-03-14 17:25:20 +01006742 WindowState transWin = isStatusBarKeyguard() && !mHideLockScreen
6743 ? mStatusBar
John Spurlockbd957402013-10-03 11:38:39 -04006744 : mTopFullscreenOpaqueWindowState;
6745 vis = mStatusBarController.applyTranslucentFlagLw(transWin, vis, oldVis);
6746 vis = mNavigationBarController.applyTranslucentFlagLw(transWin, vis, oldVis);
6747
John Spurlock27735a42013-08-14 17:57:38 -04006748 // prevent status bar interaction from clearing certain flags
Selim Cinekf83e8242015-05-19 18:08:14 -07006749 int type = win.getAttrs().type;
6750 boolean statusBarHasFocus = type == TYPE_STATUS_BAR;
John Spurlock08ffcf52014-07-11 10:13:46 -04006751 if (statusBarHasFocus && !isStatusBarKeyguard()) {
John Spurlockad3e6cb2013-04-30 08:47:43 -04006752 int flags = View.SYSTEM_UI_FLAG_FULLSCREEN
6753 | View.SYSTEM_UI_FLAG_HIDE_NAVIGATION
John Spurlockcfc359a2013-09-05 10:42:03 -04006754 | View.SYSTEM_UI_FLAG_IMMERSIVE
Jorim Jaggi73fef8d2015-02-16 17:32:28 +01006755 | View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY
6756 | View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR;
John Spurlock08ffcf52014-07-11 10:13:46 -04006757 if (mHideLockScreen) {
Jorim Jaggi5cf17872014-03-26 18:31:48 +01006758 flags |= View.STATUS_BAR_TRANSLUCENT | View.NAVIGATION_BAR_TRANSLUCENT;
6759 }
John Spurlockbd957402013-10-03 11:38:39 -04006760 vis = (vis & ~flags) | (oldVis & flags);
John Spurlockad3e6cb2013-04-30 08:47:43 -04006761 }
John Spurlockad3e6cb2013-04-30 08:47:43 -04006762
Wale Ogunwale6e94a9e2015-10-07 15:35:49 -07006763 if ((!areTranslucentBarsAllowed() && transWin != mStatusBar)
6764 || forceOpaqueSystemBars) {
Adrian Roosea562512014-05-05 13:33:03 +02006765 vis &= ~(View.NAVIGATION_BAR_TRANSLUCENT | View.STATUS_BAR_TRANSLUCENT
6766 | View.SYSTEM_UI_TRANSPARENT);
Alan Viverette5a0f4ec2013-10-07 15:10:29 -07006767 }
6768
John Spurlock27735a42013-08-14 17:57:38 -04006769 // update status bar
John Spurlockf1a36642013-10-12 17:50:42 -04006770 boolean immersiveSticky =
6771 (vis & View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY) != 0;
Wale Ogunwale6e94a9e2015-10-07 15:35:49 -07006772 final boolean hideStatusBarWM =
6773 mTopFullscreenOpaqueWindowState != null
6774 && (PolicyControl.getWindowFlags(mTopFullscreenOpaqueWindowState, null)
John Spurlock27735a42013-08-14 17:57:38 -04006775 & WindowManager.LayoutParams.FLAG_FULLSCREEN) != 0;
Wale Ogunwale6e94a9e2015-10-07 15:35:49 -07006776 final boolean hideStatusBarSysui =
John Spurlock27735a42013-08-14 17:57:38 -04006777 (vis & View.SYSTEM_UI_FLAG_FULLSCREEN) != 0;
Wale Ogunwale6e94a9e2015-10-07 15:35:49 -07006778 final boolean hideNavBarSysui =
John Spurlockf1a36642013-10-12 17:50:42 -04006779 (vis & View.SYSTEM_UI_FLAG_HIDE_NAVIGATION) != 0;
John Spurlockad3e6cb2013-04-30 08:47:43 -04006780
Wale Ogunwale6e94a9e2015-10-07 15:35:49 -07006781 final boolean transientStatusBarAllowed = mStatusBar != null
6782 && (statusBarHasFocus || (!forceShowSystemBars
6783 && (hideStatusBarWM || (hideStatusBarSysui && immersiveSticky))));
John Spurlock27735a42013-08-14 17:57:38 -04006784
Wale Ogunwale6e94a9e2015-10-07 15:35:49 -07006785 final boolean transientNavBarAllowed = mNavigationBar != null
6786 && !forceShowSystemBars && hideNavBarSysui && immersiveSticky;
John Spurlockf1a36642013-10-12 17:50:42 -04006787
Adrian Roosddc8b272015-05-21 16:28:27 -07006788 final long now = SystemClock.uptimeMillis();
6789 final boolean pendingPanic = mPendingPanicGestureUptime != 0
6790 && now - mPendingPanicGestureUptime <= PANIC_GESTURE_EXPIRATION;
6791 if (pendingPanic && hideNavBarSysui && !isStatusBarKeyguard() && mKeyguardDrawComplete) {
6792 // The user performed the panic gesture recently, we're about to hide the bars,
6793 // we're no longer on the Keyguard and the screen is ready. We can now request the bars.
6794 mPendingPanicGestureUptime = 0;
6795 mStatusBarController.showTransient();
6796 mNavigationBarController.showTransient();
6797 }
6798
Wale Ogunwale6e94a9e2015-10-07 15:35:49 -07006799 final boolean denyTransientStatus = mStatusBarController.isTransientShowRequested()
John Spurlockf1a36642013-10-12 17:50:42 -04006800 && !transientStatusBarAllowed && hideStatusBarSysui;
Wale Ogunwale6e94a9e2015-10-07 15:35:49 -07006801 final boolean denyTransientNav = mNavigationBarController.isTransientShowRequested()
John Spurlockf1a36642013-10-12 17:50:42 -04006802 && !transientNavBarAllowed;
Wale Ogunwale6e94a9e2015-10-07 15:35:49 -07006803 if (denyTransientStatus || denyTransientNav || forceShowSystemBars) {
John Spurlock27735a42013-08-14 17:57:38 -04006804 // clear the clearable flags instead
John Spurlockf1a36642013-10-12 17:50:42 -04006805 clearClearableFlagsLw();
tiger_huangc58d7562014-10-23 20:24:19 +08006806 vis &= ~View.SYSTEM_UI_CLEARABLE_FLAGS;
John Spurlockad3e6cb2013-04-30 08:47:43 -04006807 }
John Spurlock27735a42013-08-14 17:57:38 -04006808
Selim Cinekf98702e2015-05-20 22:48:40 -07006809 final boolean immersive = (vis & View.SYSTEM_UI_FLAG_IMMERSIVE) != 0;
6810 immersiveSticky = (vis & View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY) != 0;
6811 final boolean navAllowedHidden = immersive || immersiveSticky;
6812
Selim Cinekd6623612015-05-22 18:56:22 -07006813 if (hideNavBarSysui && !navAllowedHidden && windowTypeToLayerLw(win.getBaseType())
6814 > windowTypeToLayerLw(TYPE_INPUT_CONSUMER)) {
Selim Cinekf98702e2015-05-20 22:48:40 -07006815 // We can't hide the navbar from this window otherwise the input consumer would not get
6816 // the input events.
6817 vis = (vis & ~View.SYSTEM_UI_FLAG_HIDE_NAVIGATION);
6818 }
6819
John Spurlock27735a42013-08-14 17:57:38 -04006820 vis = mStatusBarController.updateVisibilityLw(transientStatusBarAllowed, oldVis, vis);
6821
6822 // update navigation bar
John Spurlockf1a36642013-10-12 17:50:42 -04006823 boolean oldImmersiveMode = isImmersiveMode(oldVis);
6824 boolean newImmersiveMode = isImmersiveMode(vis);
6825 if (win != null && oldImmersiveMode != newImmersiveMode) {
John Spurlock79da8332013-09-20 12:04:47 -04006826 final String pkg = win.getOwningPackage();
Maurice Lam99c6e072014-04-28 18:24:28 -07006827 mImmersiveModeConfirmation.immersiveModeChanged(pkg, newImmersiveMode,
6828 isUserSetupComplete());
John Spurlock34e13d92013-08-10 06:52:28 -04006829 }
John Spurlock27735a42013-08-14 17:57:38 -04006830
John Spurlockf1a36642013-10-12 17:50:42 -04006831 vis = mNavigationBarController.updateVisibilityLw(transientNavBarAllowed, oldVis, vis);
6832
John Spurlocke1f366f2013-08-05 12:22:40 -04006833 return vis;
John Spurlockad3e6cb2013-04-30 08:47:43 -04006834 }
6835
John Spurlockf1a36642013-10-12 17:50:42 -04006836 private void clearClearableFlagsLw() {
6837 int newVal = mResettingSystemUiFlags | View.SYSTEM_UI_CLEARABLE_FLAGS;
6838 if (newVal != mResettingSystemUiFlags) {
6839 mResettingSystemUiFlags = newVal;
6840 mWindowManagerFuncs.reevaluateStatusBarVisibility();
6841 }
6842 }
6843
6844 private boolean isImmersiveMode(int vis) {
6845 final int flags = View.SYSTEM_UI_FLAG_IMMERSIVE | View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY;
John Spurlock34e13d92013-08-10 06:52:28 -04006846 return mNavigationBar != null
6847 && (vis & View.SYSTEM_UI_FLAG_HIDE_NAVIGATION) != 0
Daniel Sandler900ece52013-10-18 15:53:27 -04006848 && (vis & flags) != 0
6849 && canHideNavigationBar();
John Spurlock34e13d92013-08-10 06:52:28 -04006850 }
6851
Alan Viverette5a0f4ec2013-10-07 15:10:29 -07006852 /**
Daniel Sandlerdd73ee42013-10-11 22:19:59 -04006853 * @return whether the navigation or status bar can be made translucent
6854 *
6855 * This should return true unless touch exploration is not enabled or
6856 * R.boolean.config_enableTranslucentDecor is false.
Alan Viverette5a0f4ec2013-10-07 15:10:29 -07006857 */
Daniel Sandlerdd73ee42013-10-11 22:19:59 -04006858 private boolean areTranslucentBarsAllowed() {
Alan Viverette817f3cd2015-08-13 11:40:14 -04006859 return mTranslucentDecorEnabled;
Alan Viverette5a0f4ec2013-10-07 15:10:29 -07006860 }
6861
Daniel Sandler0c4ccff2011-10-19 16:39:14 -04006862 // Use this instead of checking config_showNavigationBar so that it can be consistently
6863 // overridden by qemu.hw.mainkeys in the emulator.
Craig Mautnereda67292013-04-28 13:50:14 -07006864 @Override
Daniel Sandler0c4ccff2011-10-19 16:39:14 -04006865 public boolean hasNavigationBar() {
6866 return mHasNavigationBar;
6867 }
6868
satok1bc0a492012-04-25 22:47:12 +09006869 @Override
6870 public void setLastInputMethodWindowLw(WindowState ime, WindowState target) {
6871 mLastInputMethodWindow = ime;
6872 mLastInputMethodTargetWindow = target;
6873 }
6874
Craig Mautnerf1b67412012-09-19 13:18:29 -07006875 @Override
Satoshi Kataoka658c7b82013-10-10 17:03:51 +09006876 public int getInputMethodWindowVisibleHeightLw() {
6877 return mDockBottom - mCurBottom;
6878 }
6879
6880 @Override
Craig Mautnerf1b67412012-09-19 13:18:29 -07006881 public void setCurrentUserLw(int newUserId) {
Craig Mautnerd625ab22013-09-06 13:40:31 -07006882 mCurrentUserId = newUserId;
Jim Miller5ecd8112013-01-09 18:50:26 -08006883 if (mKeyguardDelegate != null) {
6884 mKeyguardDelegate.setCurrentUser(newUserId);
Craig Mautnerf1b67412012-09-19 13:18:29 -07006885 }
John Spurlock13451a22012-09-28 14:40:41 -04006886 if (mStatusBarService != null) {
6887 try {
6888 mStatusBarService.setCurrentUser(newUserId);
6889 } catch (RemoteException e) {
6890 // oh well
6891 }
6892 }
Dianne Hackborn2ea9bae2012-11-02 18:43:48 -07006893 setLastInputMethodWindowLw(null, null);
Craig Mautnerf1b67412012-09-19 13:18:29 -07006894 }
6895
6896 @Override
Svetoslav Ganov545252f2012-12-10 18:29:24 -08006897 public boolean canMagnifyWindow(int windowType) {
6898 switch (windowType) {
6899 case WindowManager.LayoutParams.TYPE_INPUT_METHOD:
6900 case WindowManager.LayoutParams.TYPE_INPUT_METHOD_DIALOG:
6901 case WindowManager.LayoutParams.TYPE_NAVIGATION_BAR:
6902 case WindowManager.LayoutParams.TYPE_MAGNIFICATION_OVERLAY: {
6903 return false;
6904 }
6905 }
6906 return true;
6907 }
6908
6909 @Override
6910 public boolean isTopLevelWindow(int windowType) {
6911 if (windowType >= WindowManager.LayoutParams.FIRST_SUB_WINDOW
6912 && windowType <= WindowManager.LayoutParams.LAST_SUB_WINDOW) {
6913 return (windowType == WindowManager.LayoutParams.TYPE_APPLICATION_ATTACHED_DIALOG);
6914 }
6915 return true;
6916 }
6917
Jim Miller4eeb4f62012-11-08 00:04:29 -08006918 @Override
Jeff Brownd7a04de2012-06-17 14:17:52 -07006919 public void dump(String prefix, PrintWriter pw, String[] args) {
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08006920 pw.print(prefix); pw.print("mSafeMode="); pw.print(mSafeMode);
Dianne Hackbornba24e4d2011-09-01 11:17:06 -07006921 pw.print(" mSystemReady="); pw.print(mSystemReady);
6922 pw.print(" mSystemBooted="); pw.println(mSystemBooted);
Jeff Brown2e7760e2012-04-11 15:14:55 -07006923 pw.print(prefix); pw.print("mLidState="); pw.print(mLidState);
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08006924 pw.print(" mLidOpenRotation="); pw.print(mLidOpenRotation);
Michael Wright3818c922014-09-02 13:59:07 -07006925 pw.print(" mCameraLensCoverState="); pw.print(mCameraLensCoverState);
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08006926 pw.print(" mHdmiPlugged="); pw.println(mHdmiPlugged);
Dianne Hackborne26ab702011-10-16 13:21:33 -07006927 if (mLastSystemUiFlags != 0 || mResettingSystemUiFlags != 0
6928 || mForceClearedSystemUiFlags != 0) {
6929 pw.print(prefix); pw.print("mLastSystemUiFlags=0x");
6930 pw.print(Integer.toHexString(mLastSystemUiFlags));
6931 pw.print(" mResettingSystemUiFlags=0x");
6932 pw.print(Integer.toHexString(mResettingSystemUiFlags));
6933 pw.print(" mForceClearedSystemUiFlags=0x");
6934 pw.println(Integer.toHexString(mForceClearedSystemUiFlags));
Dianne Hackborndf89e652011-10-06 22:35:11 -07006935 }
Dianne Hackborn4eff8d32011-11-10 19:38:40 -08006936 if (mLastFocusNeedsMenu) {
6937 pw.print(prefix); pw.print("mLastFocusNeedsMenu=");
6938 pw.println(mLastFocusNeedsMenu);
6939 }
Jeff Browna20dda42014-05-27 20:57:24 -07006940 pw.print(prefix); pw.print("mWakeGestureEnabledSetting=");
6941 pw.println(mWakeGestureEnabledSetting);
6942
Jeff Brownbcdfc622014-03-06 19:13:04 -08006943 pw.print(prefix); pw.print("mSupportAutoRotation="); pw.println(mSupportAutoRotation);
Daniel Sandler6396c722013-04-16 20:19:09 -04006944 pw.print(prefix); pw.print("mUiMode="); pw.print(mUiMode);
6945 pw.print(" mDockMode="); pw.print(mDockMode);
keunyounga7710492015-09-23 11:33:58 -07006946 pw.print(" mEnableCarDockHomeCapture="); pw.print(mEnableCarDockHomeCapture);
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08006947 pw.print(" mCarDockRotation="); pw.print(mCarDockRotation);
6948 pw.print(" mDeskDockRotation="); pw.println(mDeskDockRotation);
6949 pw.print(prefix); pw.print("mUserRotationMode="); pw.print(mUserRotationMode);
6950 pw.print(" mUserRotation="); pw.print(mUserRotation);
Daniel Sandler2ed6ad62011-02-22 14:54:17 -05006951 pw.print(" mAllowAllRotations="); pw.println(mAllowAllRotations);
Dianne Hackborn6e2281d2012-06-19 17:48:32 -07006952 pw.print(prefix); pw.print("mCurrentAppOrientation="); pw.println(mCurrentAppOrientation);
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08006953 pw.print(prefix); pw.print("mCarDockEnablesAccelerometer=");
6954 pw.print(mCarDockEnablesAccelerometer);
6955 pw.print(" mDeskDockEnablesAccelerometer=");
6956 pw.println(mDeskDockEnablesAccelerometer);
6957 pw.print(prefix); pw.print("mLidKeyboardAccessibility=");
6958 pw.print(mLidKeyboardAccessibility);
6959 pw.print(" mLidNavigationAccessibility="); pw.print(mLidNavigationAccessibility);
Dianne Hackborn6e2281d2012-06-19 17:48:32 -07006960 pw.print(" mLidControlsSleep="); pw.println(mLidControlsSleep);
Jeff Brown6d8fd272014-05-20 21:24:38 -07006961 pw.print(prefix);
6962 pw.print("mShortPressOnPowerBehavior="); pw.print(mShortPressOnPowerBehavior);
6963 pw.print(" mLongPressOnPowerBehavior="); pw.println(mLongPressOnPowerBehavior);
Jeff Brown13f00f02014-10-31 14:45:50 -07006964 pw.print(prefix);
6965 pw.print("mDoublePressOnPowerBehavior="); pw.print(mDoublePressOnPowerBehavior);
6966 pw.print(" mTriplePressOnPowerBehavior="); pw.println(mTriplePressOnPowerBehavior);
Jeff Brown6d8fd272014-05-20 21:24:38 -07006967 pw.print(prefix); pw.print("mHasSoftInput="); pw.println(mHasSoftInput);
Jeff Brown3ee549c2014-09-22 20:14:39 -07006968 pw.print(prefix); pw.print("mAwake="); pw.println(mAwake);
6969 pw.print(prefix); pw.print("mScreenOnEarly="); pw.print(mScreenOnEarly);
6970 pw.print(" mScreenOnFully="); pw.println(mScreenOnFully);
6971 pw.print(prefix); pw.print("mKeyguardDrawComplete="); pw.print(mKeyguardDrawComplete);
6972 pw.print(" mWindowManagerDrawComplete="); pw.println(mWindowManagerDrawComplete);
6973 pw.print(prefix); pw.print("mOrientationSensorEnabled=");
6974 pw.println(mOrientationSensorEnabled);
Dianne Hackbornc652de82013-02-15 16:32:56 -08006975 pw.print(prefix); pw.print("mOverscanScreen=("); pw.print(mOverscanScreenLeft);
6976 pw.print(","); pw.print(mOverscanScreenTop);
6977 pw.print(") "); pw.print(mOverscanScreenWidth);
6978 pw.print("x"); pw.println(mOverscanScreenHeight);
6979 if (mOverscanLeft != 0 || mOverscanTop != 0
6980 || mOverscanRight != 0 || mOverscanBottom != 0) {
6981 pw.print(prefix); pw.print("mOverscan left="); pw.print(mOverscanLeft);
6982 pw.print(" top="); pw.print(mOverscanTop);
6983 pw.print(" right="); pw.print(mOverscanRight);
6984 pw.print(" bottom="); pw.println(mOverscanBottom);
6985 }
Dianne Hackborn313440842013-02-19 19:22:59 -08006986 pw.print(prefix); pw.print("mRestrictedOverscanScreen=(");
6987 pw.print(mRestrictedOverscanScreenLeft);
6988 pw.print(","); pw.print(mRestrictedOverscanScreenTop);
6989 pw.print(") "); pw.print(mRestrictedOverscanScreenWidth);
6990 pw.print("x"); pw.println(mRestrictedOverscanScreenHeight);
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08006991 pw.print(prefix); pw.print("mUnrestrictedScreen=("); pw.print(mUnrestrictedScreenLeft);
6992 pw.print(","); pw.print(mUnrestrictedScreenTop);
6993 pw.print(") "); pw.print(mUnrestrictedScreenWidth);
6994 pw.print("x"); pw.println(mUnrestrictedScreenHeight);
6995 pw.print(prefix); pw.print("mRestrictedScreen=("); pw.print(mRestrictedScreenLeft);
6996 pw.print(","); pw.print(mRestrictedScreenTop);
6997 pw.print(") "); pw.print(mRestrictedScreenWidth);
6998 pw.print("x"); pw.println(mRestrictedScreenHeight);
Dianne Hackborn5b5cc4d2012-05-16 13:15:00 -07006999 pw.print(prefix); pw.print("mStableFullscreen=("); pw.print(mStableFullscreenLeft);
7000 pw.print(","); pw.print(mStableFullscreenTop);
7001 pw.print(")-("); pw.print(mStableFullscreenRight);
7002 pw.print(","); pw.print(mStableFullscreenBottom); pw.println(")");
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07007003 pw.print(prefix); pw.print("mStable=("); pw.print(mStableLeft);
7004 pw.print(","); pw.print(mStableTop);
7005 pw.print(")-("); pw.print(mStableRight);
7006 pw.print(","); pw.print(mStableBottom); pw.println(")");
Dianne Hackborn5c58de32012-04-28 19:52:37 -07007007 pw.print(prefix); pw.print("mSystem=("); pw.print(mSystemLeft);
7008 pw.print(","); pw.print(mSystemTop);
7009 pw.print(")-("); pw.print(mSystemRight);
7010 pw.print(","); pw.print(mSystemBottom); pw.println(")");
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08007011 pw.print(prefix); pw.print("mCur=("); pw.print(mCurLeft);
7012 pw.print(","); pw.print(mCurTop);
7013 pw.print(")-("); pw.print(mCurRight);
7014 pw.print(","); pw.print(mCurBottom); pw.println(")");
7015 pw.print(prefix); pw.print("mContent=("); pw.print(mContentLeft);
7016 pw.print(","); pw.print(mContentTop);
7017 pw.print(")-("); pw.print(mContentRight);
7018 pw.print(","); pw.print(mContentBottom); pw.println(")");
Dianne Hackborne30e02f2014-05-27 18:24:45 -07007019 pw.print(prefix); pw.print("mVoiceContent=("); pw.print(mVoiceContentLeft);
7020 pw.print(","); pw.print(mVoiceContentTop);
7021 pw.print(")-("); pw.print(mVoiceContentRight);
7022 pw.print(","); pw.print(mVoiceContentBottom); pw.println(")");
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08007023 pw.print(prefix); pw.print("mDock=("); pw.print(mDockLeft);
7024 pw.print(","); pw.print(mDockTop);
7025 pw.print(")-("); pw.print(mDockRight);
7026 pw.print(","); pw.print(mDockBottom); pw.println(")");
Dianne Hackborn5c58de32012-04-28 19:52:37 -07007027 pw.print(prefix); pw.print("mDockLayer="); pw.print(mDockLayer);
7028 pw.print(" mStatusBarLayer="); pw.println(mStatusBarLayer);
Dianne Hackborn7ad44382012-10-18 17:46:00 -07007029 pw.print(prefix); pw.print("mShowingLockscreen="); pw.print(mShowingLockscreen);
7030 pw.print(" mShowingDream="); pw.print(mShowingDream);
Jeff Brown061ea992015-04-17 19:55:47 -07007031 pw.print(" mDreamingLockscreen="); pw.print(mDreamingLockscreen);
7032 pw.print(" mDreamingSleepToken="); pw.println(mDreamingSleepToken);
Dianne Hackborn2ea9bae2012-11-02 18:43:48 -07007033 if (mLastInputMethodWindow != null) {
7034 pw.print(prefix); pw.print("mLastInputMethodWindow=");
7035 pw.println(mLastInputMethodWindow);
7036 }
7037 if (mLastInputMethodTargetWindow != null) {
7038 pw.print(prefix); pw.print("mLastInputMethodTargetWindow=");
7039 pw.println(mLastInputMethodTargetWindow);
7040 }
7041 if (mStatusBar != null) {
7042 pw.print(prefix); pw.print("mStatusBar=");
Dianne Hackbornae6688b2015-02-11 17:02:41 -08007043 pw.print(mStatusBar); pw.print(" isStatusBarKeyguard=");
7044 pw.println(isStatusBarKeyguard());
Dianne Hackborn2ea9bae2012-11-02 18:43:48 -07007045 }
7046 if (mNavigationBar != null) {
7047 pw.print(prefix); pw.print("mNavigationBar=");
7048 pw.println(mNavigationBar);
7049 }
Dianne Hackborn2ea9bae2012-11-02 18:43:48 -07007050 if (mFocusedWindow != null) {
7051 pw.print(prefix); pw.print("mFocusedWindow=");
7052 pw.println(mFocusedWindow);
7053 }
7054 if (mFocusedApp != null) {
7055 pw.print(prefix); pw.print("mFocusedApp=");
7056 pw.println(mFocusedApp);
7057 }
7058 if (mWinDismissingKeyguard != null) {
7059 pw.print(prefix); pw.print("mWinDismissingKeyguard=");
7060 pw.println(mWinDismissingKeyguard);
7061 }
7062 if (mTopFullscreenOpaqueWindowState != null) {
7063 pw.print(prefix); pw.print("mTopFullscreenOpaqueWindowState=");
7064 pw.println(mTopFullscreenOpaqueWindowState);
7065 }
Adrian Rooscd3884d2015-02-18 17:25:23 +01007066 if (mTopFullscreenOpaqueOrDimmingWindowState != null) {
7067 pw.print(prefix); pw.print("mTopFullscreenOpaqueOrDimmingWindowState=");
7068 pw.println(mTopFullscreenOpaqueOrDimmingWindowState);
7069 }
Dianne Hackborn891d3fb2013-01-09 18:31:37 -08007070 if (mForcingShowNavBar) {
7071 pw.print(prefix); pw.print("mForcingShowNavBar=");
7072 pw.println(mForcingShowNavBar); pw.print( "mForcingShowNavBarLayer=");
7073 pw.println(mForcingShowNavBarLayer);
7074 }
Dianne Hackborn7ad44382012-10-18 17:46:00 -07007075 pw.print(prefix); pw.print("mTopIsFullscreen="); pw.print(mTopIsFullscreen);
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08007076 pw.print(" mHideLockScreen="); pw.println(mHideLockScreen);
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07007077 pw.print(prefix); pw.print("mForceStatusBar="); pw.print(mForceStatusBar);
7078 pw.print(" mForceStatusBarFromKeyguard=");
7079 pw.println(mForceStatusBarFromKeyguard);
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08007080 pw.print(prefix); pw.print("mDismissKeyguard="); pw.print(mDismissKeyguard);
Craig Mautnerad09bcc2012-10-08 13:33:11 -07007081 pw.print(" mWinDismissingKeyguard="); pw.print(mWinDismissingKeyguard);
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08007082 pw.print(" mHomePressed="); pw.println(mHomePressed);
7083 pw.print(prefix); pw.print("mAllowLockscreenWhenOn="); pw.print(mAllowLockscreenWhenOn);
7084 pw.print(" mLockScreenTimeout="); pw.print(mLockScreenTimeout);
7085 pw.print(" mLockScreenTimerActive="); pw.println(mLockScreenTimerActive);
7086 pw.print(prefix); pw.print("mEndcallBehavior="); pw.print(mEndcallBehavior);
7087 pw.print(" mIncallPowerBehavior="); pw.print(mIncallPowerBehavior);
7088 pw.print(" mLongPressOnHomeBehavior="); pw.println(mLongPressOnHomeBehavior);
7089 pw.print(prefix); pw.print("mLandscapeRotation="); pw.print(mLandscapeRotation);
7090 pw.print(" mSeascapeRotation="); pw.println(mSeascapeRotation);
7091 pw.print(prefix); pw.print("mPortraitRotation="); pw.print(mPortraitRotation);
7092 pw.print(" mUpsideDownRotation="); pw.println(mUpsideDownRotation);
Jeff Brownc82c89ed2013-04-17 17:18:15 -07007093 pw.print(prefix); pw.print("mDemoHdmiRotation="); pw.print(mDemoHdmiRotation);
7094 pw.print(" mDemoHdmiRotationLock="); pw.println(mDemoHdmiRotationLock);
7095 pw.print(prefix); pw.print("mUndockedHdmiRotation="); pw.println(mUndockedHdmiRotation);
Jeff Brown600f0032014-05-22 17:06:00 -07007096
Tim Kilbournd7c0c2e2014-05-29 16:08:10 -07007097 mGlobalKeyManager.dump(prefix, pw);
John Spurlock27735a42013-08-14 17:57:38 -04007098 mStatusBarController.dump(pw, prefix);
7099 mNavigationBarController.dump(pw, prefix);
John Spurlockc6d1c602014-01-17 15:22:06 -05007100 PolicyControl.dump(prefix, pw);
Jeff Brown600f0032014-05-22 17:06:00 -07007101
Jeff Browna20dda42014-05-27 20:57:24 -07007102 if (mWakeGestureListener != null) {
7103 mWakeGestureListener.dump(pw, prefix);
7104 }
Jeff Brown600f0032014-05-22 17:06:00 -07007105 if (mOrientationListener != null) {
7106 mOrientationListener.dump(pw, prefix);
7107 }
Filip Gruszczynskicfb31852015-02-25 21:47:12 +00007108 if (mBurnInProtectionHelper != null) {
7109 mBurnInProtectionHelper.dump(prefix, pw);
7110 }
Jorim Jaggi84dc08a2015-09-11 17:45:22 -07007111 if (mKeyguardDelegate != null) {
7112 mKeyguardDelegate.dump(prefix, pw);
7113 }
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08007114 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08007115}