blob: 764e4d3da00cb66cee729cc4d2e2da9b3dc7d007 [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
Dianne Hackborna4972e92012-03-14 10:38:05 -070019import android.app.ActivityManager;
Jeff Brown061ea992015-04-17 19:55:47 -070020import android.app.ActivityManagerInternal;
21import android.app.ActivityManagerInternal.SleepToken;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -080022import android.app.ActivityManagerNative;
Dianne Hackbornc2293022013-02-06 23:14:49 -080023import android.app.AppOpsManager;
Daniel Sandler6396c722013-04-16 20:19:09 -040024import android.app.IUiModeManager;
Dianne Hackborn661cd522011-08-22 00:26:20 -070025import android.app.ProgressDialog;
Jeff Brownde7a8ea2012-06-13 18:28:57 -070026import android.app.SearchManager;
John Spurlock97642182013-07-29 17:58:39 -040027import android.app.StatusBarManager;
Dianne Hackborn78968392010-03-04 20:47:56 -080028import android.app.UiModeManager;
Dianne Hackborn39c2d712009-09-22 11:41:31 -070029import android.content.ActivityNotFoundException;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -080030import android.content.BroadcastReceiver;
Daniel Sandler0601eb72011-04-13 01:01:32 -040031import android.content.ComponentName;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -080032import android.content.ContentResolver;
33import android.content.Context;
34import android.content.Intent;
Mike Lockwood1753f7f2009-08-24 14:49:07 -070035import android.content.IntentFilter;
Winson Chung9112ec32011-06-27 13:15:32 -070036import android.content.ServiceConnection;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -080037import android.content.pm.ActivityInfo;
38import android.content.pm.PackageManager;
Daniel Sandler6396c722013-04-16 20:19:09 -040039import android.content.pm.ResolveInfo;
Dianne Hackborn2f0b1752011-05-31 17:59:49 -070040import android.content.res.CompatibilityInfo;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -080041import android.content.res.Configuration;
42import android.content.res.Resources;
Craig Mautner8e4df6c2012-05-23 16:57:23 -070043import android.content.res.TypedArray;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -080044import android.database.ContentObserver;
Dianne Hackbornc777e072010-02-12 13:07:59 -080045import android.graphics.PixelFormat;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -080046import android.graphics.Rect;
John Spurlock7b414672014-07-18 13:02:39 -040047import android.media.AudioAttributes;
Michael Jurka7a348952012-02-27 13:07:58 -080048import android.media.AudioManager;
John Spurlock61560172015-02-06 19:46:04 -050049import android.media.AudioSystem;
Michael Jurka7a348952012-02-27 13:07:58 -080050import android.media.IAudioService;
Svetoslav Ganov7befb7d2012-09-27 16:49:23 -070051import android.media.Ringtone;
52import android.media.RingtoneManager;
RoboErik8a2cfc32014-05-16 11:19:38 -070053import android.media.session.MediaSessionLegacyHelper;
Billy Laucbe540f2015-06-25 01:51:44 +010054import android.os.Binder;
Dianne Hackborn38e29a62011-09-18 14:43:08 -070055import android.os.Bundle;
Craig Mautner276a6eb2014-11-04 15:32:57 -080056import android.os.Debug;
Jeff Brown9a538ee2012-08-20 14:56:57 -070057import android.os.FactoryTest;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -080058import android.os.Handler;
59import android.os.IBinder;
Dianne Hackbornb6683c42015-06-18 17:40:33 -070060import android.os.IDeviceIdleController;
Jeff Brown32cbc38552011-12-01 14:01:49 -080061import android.os.Looper;
Dianne Hackbornfc8fa632011-08-17 16:20:47 -070062import android.os.Message;
63import android.os.Messenger;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -080064import android.os.PowerManager;
Billy Laucbe540f2015-06-25 01:51:44 +010065import android.os.Process;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -080066import android.os.RemoteException;
67import android.os.ServiceManager;
68import android.os.SystemClock;
69import android.os.SystemProperties;
Dianne Hackbornad7fa7f2011-01-07 14:06:50 -080070import android.os.UEventObserver;
Dianne Hackbornf02b60a2012-08-16 10:48:27 -070071import android.os.UserHandle;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -080072import android.os.Vibrator;
Michael Wright3818c922014-09-02 13:59:07 -070073import android.provider.MediaStore;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -080074import android.provider.Settings;
Jose Lima9546b202014-07-02 17:21:51 -070075import android.service.dreams.DreamManagerInternal;
John Spurlockc8b46ca2013-04-08 12:59:26 -040076import android.service.dreams.DreamService;
77import android.service.dreams.IDreamManager;
Michael Wrightdc63f7b2014-08-21 19:05:21 -070078import android.speech.RecognizerIntent;
Tyler Gunnef9f6f92014-09-12 22:16:17 -070079import android.telecom.TelecomManager;
Dianne Hackborn81e56d52011-05-26 00:55:58 -070080import android.util.DisplayMetrics;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -080081import android.util.EventLog;
82import android.util.Log;
Jeff Browna41ca772010-08-11 14:46:32 -070083import android.util.Slog;
Jeff Brown6651a632011-11-28 12:59:11 -080084import android.util.SparseArray;
Dianne Hackbornf87d1962012-04-04 12:48:24 -070085import android.view.Display;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -080086import android.view.Gravity;
87import android.view.HapticFeedbackConstants;
Dianne Hackborne0f085d2011-11-30 18:41:15 -080088import android.view.IApplicationToken;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -080089import android.view.IWindowManager;
Jeff Browna41ca772010-08-11 14:46:32 -070090import android.view.InputChannel;
Jeff Brown4d396052010-10-29 21:50:21 -070091import android.view.InputDevice;
Jeff Brown4952dfd2011-11-30 19:23:22 -080092import android.view.InputEvent;
Jeff Brown32cbc38552011-12-01 14:01:49 -080093import android.view.InputEventReceiver;
Jeff Brown6b53e8d2010-11-10 16:03:06 -080094import android.view.KeyCharacterMap;
Craig Mautnerae446592012-12-06 19:05:05 -080095import android.view.KeyCharacterMap.FallbackAction;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -080096import android.view.KeyEvent;
97import android.view.MotionEvent;
Chris Wren9bb290b2015-06-29 12:02:13 -040098
99import com.android.internal.logging.MetricsLogger;
Adam Powell6711f3b2015-05-06 15:57:09 -0700100import com.android.internal.policy.PhoneWindow;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800101import android.view.Surface;
102import android.view.View;
103import android.view.ViewConfiguration;
104import android.view.Window;
105import android.view.WindowManager;
Craig Mautnerae446592012-12-06 19:05:05 -0800106import android.view.WindowManagerGlobal;
Craig Mautner8a0da012014-05-31 15:13:37 -0700107import android.view.WindowManagerInternal;
Craig Mautnerae446592012-12-06 19:05:05 -0800108import android.view.WindowManagerPolicy;
Craig Mautnerae446592012-12-06 19:05:05 -0800109import android.view.accessibility.AccessibilityEvent;
Svetoslav8e3feb12014-02-24 13:46:47 -0800110import android.view.accessibility.AccessibilityManager;
Craig Mautnerae446592012-12-06 19:05:05 -0800111import android.view.animation.Animation;
Jorim Jaggi76a16232014-08-08 17:00:47 +0200112import android.view.animation.AnimationSet;
Craig Mautnerae446592012-12-06 19:05:05 -0800113import android.view.animation.AnimationUtils;
Craig Mautnerae446592012-12-06 19:05:05 -0800114import com.android.internal.R;
Craig Mautnerae446592012-12-06 19:05:05 -0800115import com.android.internal.statusbar.IStatusBarService;
Filip Gruszczynski2217f612015-05-26 11:32:08 -0700116import com.android.internal.util.ScreenShapeHelper;
Craig Mautnerae446592012-12-06 19:05:05 -0800117import com.android.internal.widget.PointerLocationView;
Craig Mautner8a0da012014-05-31 15:13:37 -0700118import com.android.server.LocalServices;
Jorim Jaggib10e33f2015-02-04 21:57:40 +0100119import com.android.server.policy.keyguard.KeyguardServiceDelegate;
120import com.android.server.policy.keyguard.KeyguardServiceDelegate.ShowListener;
Craig Mautnerae446592012-12-06 19:05:05 -0800121
122import java.io.File;
123import java.io.FileReader;
124import java.io.IOException;
125import java.io.PrintWriter;
Craig Mautner2bc789b2014-03-19 19:48:38 -0700126import java.util.HashSet;
Craig Mautner276a6eb2014-11-04 15:32:57 -0800127import java.util.List;
Craig Mautnerae446592012-12-06 19:05:05 -0800128
Dianne Hackbornc652de82013-02-15 16:32:56 -0800129import static android.view.WindowManager.LayoutParams.*;
Jeff Brownac143512012-04-05 18:57:33 -0700130import static android.view.WindowManagerPolicy.WindowManagerFuncs.LID_ABSENT;
131import static android.view.WindowManagerPolicy.WindowManagerFuncs.LID_OPEN;
132import static android.view.WindowManagerPolicy.WindowManagerFuncs.LID_CLOSED;
Michael Wright3818c922014-09-02 13:59:07 -0700133import static android.view.WindowManagerPolicy.WindowManagerFuncs.CAMERA_LENS_COVER_ABSENT;
134import static android.view.WindowManagerPolicy.WindowManagerFuncs.CAMERA_LENS_UNCOVERED;
135import static android.view.WindowManagerPolicy.WindowManagerFuncs.CAMERA_LENS_COVERED;
Dianne Hackborn08743722009-12-21 12:16:51 -0800136
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800137/**
The Android Open Source Project0727d222009-03-11 12:11:58 -0700138 * WindowManagerPolicy implementation for the Android phone UI. This
139 * introduces a new method suffix, Lp, for an internal lock of the
140 * PhoneWindowManager. This is used to protect some internal state, and
John Spurlock04db1762013-05-13 12:46:41 -0400141 * 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 -0700142 * of both of those when held.
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800143 */
144public class PhoneWindowManager implements WindowManagerPolicy {
145 static final String TAG = "WindowManager";
146 static final boolean DEBUG = false;
Joe Onorato43a17652011-04-06 19:22:23 -0700147 static final boolean localLOGV = false;
Jeff Brown40013652012-05-16 21:22:36 -0700148 static final boolean DEBUG_INPUT = false;
Craig Mautnerc0d2d0a2014-10-31 16:25:15 -0700149 static final boolean DEBUG_KEYGUARD = false;
150 static final boolean DEBUG_LAYOUT = false;
Craig Mautner6fbda632012-07-03 09:26:39 -0700151 static final boolean DEBUG_STARTING_WINDOW = false;
Craig Mautner8a0da012014-05-31 15:13:37 -0700152 static final boolean DEBUG_WAKEUP = false;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800153 static final boolean SHOW_STARTING_ANIMATIONS = true;
154 static final boolean SHOW_PROCESSES_ON_ALT_MENU = false;
Joe Onoratod208e702010-10-08 16:22:43 -0400155
Daniel Sandler6396c722013-04-16 20:19:09 -0400156 // Whether to allow dock apps with METADATA_DOCK_HOME to temporarily take over the Home key.
157 // No longer recommended for desk docks; still useful in car docks.
158 static final boolean ENABLE_CAR_DOCK_HOME_CAPTURE = true;
159 static final boolean ENABLE_DESK_DOCK_HOME_CAPTURE = false;
160
Jeff Brown6d8fd272014-05-20 21:24:38 -0700161 static final int SHORT_PRESS_POWER_NOTHING = 0;
162 static final int SHORT_PRESS_POWER_GO_TO_SLEEP = 1;
163 static final int SHORT_PRESS_POWER_REALLY_GO_TO_SLEEP = 2;
164 static final int SHORT_PRESS_POWER_REALLY_GO_TO_SLEEP_AND_GO_HOME = 3;
Bryce Lee01b0c5f2015-02-05 18:24:04 -0800165 static final int SHORT_PRESS_POWER_GO_HOME = 4;
Jeff Brown6d8fd272014-05-20 21:24:38 -0700166
Joe Onoratod208e702010-10-08 16:22:43 -0400167 static final int LONG_PRESS_POWER_NOTHING = 0;
168 static final int LONG_PRESS_POWER_GLOBAL_ACTIONS = 1;
169 static final int LONG_PRESS_POWER_SHUT_OFF = 2;
Jeff Brown9a538ee2012-08-20 14:56:57 -0700170 static final int LONG_PRESS_POWER_SHUT_OFF_NO_CONFIRM = 3;
Michael Jurka3b1fc472011-06-13 10:54:40 -0700171
Jeff Brown13f00f02014-10-31 14:45:50 -0700172 static final int MULTI_PRESS_POWER_NOTHING = 0;
173 static final int MULTI_PRESS_POWER_THEATER_MODE = 1;
174 static final int MULTI_PRESS_POWER_BRIGHTNESS_BOOST = 2;
175
Michael Jurka3b1fc472011-06-13 10:54:40 -0700176 // These need to match the documentation/constant in
177 // core/res/res/values/config.xml
Joe Onorato46b0d682010-11-22 17:37:27 -0800178 static final int LONG_PRESS_HOME_NOTHING = 0;
Michael Wrightc9ebea72013-01-16 19:25:02 -0800179 static final int LONG_PRESS_HOME_RECENT_SYSTEM_UI = 1;
Jeff Browncaca8812013-05-09 13:34:33 -0700180 static final int LONG_PRESS_HOME_ASSIST = 2;
181
182 static final int DOUBLE_TAP_HOME_NOTHING = 0;
183 static final int DOUBLE_TAP_HOME_RECENT_SYSTEM_UI = 1;
Joe Onorato46b0d682010-11-22 17:37:27 -0800184
Filip Gruszczynskia483a1d2015-03-17 19:06:58 +0000185 static final int SHORT_PRESS_SLEEP_GO_TO_SLEEP = 0;
186 static final int SHORT_PRESS_SLEEP_GO_TO_SLEEP_AND_GO_HOME = 1;
187
Dianne Hackborn5cb8d792009-05-21 17:34:15 -0700188 static final int APPLICATION_MEDIA_SUBLAYER = -2;
189 static final int APPLICATION_MEDIA_OVERLAY_SUBLAYER = -1;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800190 static final int APPLICATION_PANEL_SUBLAYER = 1;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800191 static final int APPLICATION_SUB_PANEL_SUBLAYER = 2;
Wale Ogunwale0a4dc222015-04-14 12:58:42 -0700192 static final int APPLICATION_ABOVE_SUB_PANEL_SUBLAYER = 3;
Craig Mautner88400d32012-09-30 12:35:45 -0700193
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800194 static public final String SYSTEM_DIALOG_REASON_KEY = "reason";
195 static public final String SYSTEM_DIALOG_REASON_GLOBAL_ACTIONS = "globalactions";
196 static public final String SYSTEM_DIALOG_REASON_RECENT_APPS = "recentapps";
Joe Onoratof275f0c2009-11-24 16:11:13 -0500197 static public final String SYSTEM_DIALOG_REASON_HOME_KEY = "homekey";
Jeff Brownde7a8ea2012-06-13 18:28:57 -0700198 static public final String SYSTEM_DIALOG_REASON_ASSIST = "assist";
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800199
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -0700200 /**
201 * These are the system UI flags that, when changing, can cause the layout
202 * of the screen to change.
203 */
204 static final int SYSTEM_UI_CHANGING_LAYOUT =
John Spurlocke1f366f2013-08-05 12:22:40 -0400205 View.SYSTEM_UI_FLAG_HIDE_NAVIGATION
John Spurlock7f4820a2013-10-08 12:54:35 -0400206 | View.SYSTEM_UI_FLAG_FULLSCREEN
207 | View.STATUS_BAR_TRANSLUCENT
Adrian Roosea562512014-05-05 13:33:03 +0200208 | View.NAVIGATION_BAR_TRANSLUCENT
209 | View.SYSTEM_UI_TRANSPARENT;
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -0700210
John Spurlock7b414672014-07-18 13:02:39 -0400211 private static final AudioAttributes VIBRATION_ATTRIBUTES = new AudioAttributes.Builder()
212 .setContentType(AudioAttributes.CONTENT_TYPE_SONIFICATION)
213 .setUsage(AudioAttributes.USAGE_ASSISTANCE_SONIFICATION)
214 .build();
215
Adrian Roosddc8b272015-05-21 16:28:27 -0700216 // The panic gesture may become active only after the keyguard is dismissed and the immersive
217 // app shows again. If that doesn't happen for 30s we drop the gesture.
218 private static final long PANIC_GESTURE_EXPIRATION = 30000;
219
Jim Miller5ecd8112013-01-09 18:50:26 -0800220 /**
221 * Keyguard stuff
222 */
223 private WindowState mKeyguardScrim;
Jorim Jaggi380ecb82014-03-14 17:25:20 +0100224 private boolean mKeyguardHidden;
Jeff Brown3ee549c2014-09-22 20:14:39 -0700225 private boolean mKeyguardDrawnOnce;
Jim Miller5ecd8112013-01-09 18:50:26 -0800226
Jeff Brown6651a632011-11-28 12:59:11 -0800227 /* Table of Application Launch keys. Maps from key codes to intent categories.
228 *
229 * These are special keys that are used to launch particular kinds of applications,
230 * such as a web browser. HID defines nearly a hundred of them in the Consumer (0x0C)
231 * usage page. We don't support quite that many yet...
232 */
233 static SparseArray<String> sApplicationLaunchKeyCategories;
234 static {
235 sApplicationLaunchKeyCategories = new SparseArray<String>();
236 sApplicationLaunchKeyCategories.append(
237 KeyEvent.KEYCODE_EXPLORER, Intent.CATEGORY_APP_BROWSER);
238 sApplicationLaunchKeyCategories.append(
239 KeyEvent.KEYCODE_ENVELOPE, Intent.CATEGORY_APP_EMAIL);
240 sApplicationLaunchKeyCategories.append(
241 KeyEvent.KEYCODE_CONTACTS, Intent.CATEGORY_APP_CONTACTS);
242 sApplicationLaunchKeyCategories.append(
243 KeyEvent.KEYCODE_CALENDAR, Intent.CATEGORY_APP_CALENDAR);
244 sApplicationLaunchKeyCategories.append(
245 KeyEvent.KEYCODE_MUSIC, Intent.CATEGORY_APP_MUSIC);
246 sApplicationLaunchKeyCategories.append(
247 KeyEvent.KEYCODE_CALCULATOR, Intent.CATEGORY_APP_CALCULATOR);
248 }
249
Craig Mautnerc3daedd2014-09-13 11:17:23 -0700250 /** Amount of time (in milliseconds) to wait for windows drawn before powering on. */
Stefan Kuhne9326dc12015-06-12 09:25:32 -1000251 static final int WAITING_FOR_DRAWN_TIMEOUT = 500;
Craig Mautnerc3daedd2014-09-13 11:17:23 -0700252
Dianne Hackborndf89e652011-10-06 22:35:11 -0700253 /**
254 * Lock protecting internal state. Must not call out into window
255 * manager with lock held. (This lock will be acquired in places
256 * where the window manager is calling in with its own lock held.)
257 */
Craig Mautner0bf6ec92012-12-18 08:33:27 -0800258 private final Object mLock = new Object();
Dianne Hackborndf89e652011-10-06 22:35:11 -0700259
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800260 Context mContext;
261 IWindowManager mWindowManager;
Dianne Hackborndf89e652011-10-06 22:35:11 -0700262 WindowManagerFuncs mWindowManagerFuncs;
Craig Mautner8a0da012014-05-31 15:13:37 -0700263 WindowManagerInternal mWindowManagerInternal;
Jeff Brown96307042012-07-27 15:51:34 -0700264 PowerManager mPowerManager;
Jeff Brown061ea992015-04-17 19:55:47 -0700265 ActivityManagerInternal mActivityManagerInternal;
Jose Lima9546b202014-07-02 17:21:51 -0700266 DreamManagerInternal mDreamManagerInternal;
Joe Onorato93056472010-09-10 10:30:46 -0400267 IStatusBarService mStatusBarService;
Jeff Browncaca8812013-05-09 13:34:33 -0700268 boolean mPreloadedRecentApps;
Dianne Hackborn42e620c2012-06-24 13:20:51 -0700269 final Object mServiceAquireLock = new Object();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800270 Vibrator mVibrator; // Vibrator for giving feedback of orientation changes
Jeff Brownde7a8ea2012-06-13 18:28:57 -0700271 SearchManager mSearchManager;
Svetoslav8e3feb12014-02-24 13:46:47 -0800272 AccessibilityManager mAccessibilityManager;
Filip Gruszczynskicfb31852015-02-25 21:47:12 +0000273 BurnInProtectionHelper mBurnInProtectionHelper;
Billy Laucbe540f2015-06-25 01:51:44 +0100274 AppOpsManager mAppOpsManager;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800275
Dianne Hackborn181ceb52009-08-27 22:16:40 -0700276 // Vibrator pattern for haptic feedback of a long press.
277 long[] mLongPressVibePattern;
Craig Mautner88400d32012-09-30 12:35:45 -0700278
Dianne Hackborn181ceb52009-08-27 22:16:40 -0700279 // Vibrator pattern for haptic feedback of virtual key press.
280 long[] mVirtualKeyVibePattern;
Craig Mautner967212c2013-04-13 21:10:58 -0700281
Amith Yamasanic33cb712010-02-10 15:21:49 -0800282 // Vibrator pattern for a short vibration.
283 long[] mKeyboardTapVibePattern;
284
Fabrice Di Meglioeeff63a2013-08-05 12:07:24 -0700285 // Vibrator pattern for a short vibration when tapping on an hour/minute tick of a Clock.
286 long[] mClockTickVibePattern;
287
Fabrice Di Megliobd9152f2013-10-01 11:21:31 -0700288 // Vibrator pattern for a short vibration when tapping on a day/month/year date of a Calendar.
289 long[] mCalendarDateVibePattern;
290
Dianne Hackbornb1a79802009-09-29 15:18:31 -0700291 // Vibrator pattern for haptic feedback during boot when safe mode is disabled.
292 long[] mSafeModeDisabledVibePattern;
Craig Mautner967212c2013-04-13 21:10:58 -0700293
Dianne Hackbornb1a79802009-09-29 15:18:31 -0700294 // Vibrator pattern for haptic feedback during boot when safe mode is enabled.
295 long[] mSafeModeEnabledVibePattern;
Romain Guy8154cd32010-03-29 14:41:15 -0700296
Mady Mellore8608912015-06-05 09:02:55 -0700297 // Vibrator pattern for haptic feedback of a context click.
298 long[] mContextClickVibePattern;
Mady Mellore82067b2015-04-30 09:58:35 -0700299
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800300 /** If true, hitting shift & menu will broadcast Intent.ACTION_BUG_REPORT */
301 boolean mEnableShiftMenuBugReports = false;
Mike Lockwoodd747dc82011-09-13 16:28:22 -0400302
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800303 boolean mSafeMode;
304 WindowState mStatusBar = null;
Dianne Hackborn69cb8752011-05-19 18:13:32 -0700305 int mStatusBarHeight;
Daniel Sandler8956dbb2011-04-22 07:55:02 -0400306 WindowState mNavigationBar = null;
Daniel Sandler36412a72011-08-04 09:35:13 -0400307 boolean mHasNavigationBar = false;
Dianne Hackbornf87d1962012-04-04 12:48:24 -0700308 boolean mCanHideNavigationBar = false;
Daniel Sandler4a066c52012-04-20 14:49:13 -0400309 boolean mNavigationBarCanMove = false; // can the navigation bar ever move to the side?
310 boolean mNavigationBarOnBottom = true; // is the navigation bar on the bottom *right now*?
311 int[] mNavigationBarHeightForRotation = new int[4];
312 int[] mNavigationBarWidthForRotation = new int[4];
Daniel Sandler8956dbb2011-04-22 07:55:02 -0400313
Craig Mautnera631d492014-08-05 15:16:01 -0700314 boolean mBootMessageNeedsHiding;
Jim Miller5ecd8112013-01-09 18:50:26 -0800315 KeyguardServiceDelegate mKeyguardDelegate;
Craig Mautner13f6ea72014-06-23 14:57:02 -0700316 final Runnable mWindowManagerDrawCallback = new Runnable() {
Craig Mautner8a0da012014-05-31 15:13:37 -0700317 @Override
Craig Mautner13f6ea72014-06-23 14:57:02 -0700318 public void run() {
Craig Mautner8a0da012014-05-31 15:13:37 -0700319 if (DEBUG_WAKEUP) Slog.i(TAG, "All windows ready for display!");
320 mHandler.sendEmptyMessage(MSG_WINDOW_MANAGER_DRAWN_COMPLETE);
321 }
322 };
323 final ShowListener mKeyguardDelegateCallback = new ShowListener() {
324 @Override
325 public void onShown(IBinder windowToken) {
326 if (DEBUG_WAKEUP) Slog.d(TAG, "mKeyguardDelegate.ShowListener.onShown.");
327 mHandler.sendEmptyMessage(MSG_KEYGUARD_DRAWN_COMPLETE);
328 }
329 };
330
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800331 GlobalActions mGlobalActions;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800332 Handler mHandler;
satok1bc0a492012-04-25 22:47:12 +0900333 WindowState mLastInputMethodWindow = null;
334 WindowState mLastInputMethodTargetWindow = null;
Jeff Brown4aed78b2011-01-14 17:36:55 -0800335
Jeff Brown13f00f02014-10-31 14:45:50 -0700336 // FIXME This state is shared between the input reader and handler thread.
337 // Technically it's broken and buggy but it has been like this for many years
338 // and we have not yet seen any problems. Someday we'll rewrite this logic
339 // so that only one thread is involved in handling input policy. Unfortunately
340 // it's on a critical path for power management so we can't just post the work to the
341 // handler thread. We'll need to resolve this someday by teaching the input dispatcher
342 // to hold wakelocks during dispatch and eliminating the critical path.
343 volatile boolean mPowerKeyHandled;
Bryce Leed9268e32014-11-17 17:40:59 -0800344 volatile boolean mBeganFromNonInteractive;
Jeff Brown13f00f02014-10-31 14:45:50 -0700345 volatile int mPowerKeyPressCounter;
346 volatile boolean mEndCallKeyHandled;
347
Winson Chungd42a6cf2014-06-03 16:24:04 -0700348 boolean mRecentsVisible;
Winson Chung1e8d71b2014-05-16 17:05:22 -0700349 int mRecentAppsHeldModifiers;
Jeff Browncf39bdf2012-05-18 14:41:19 -0700350 boolean mLanguageSwitchKeyPressed;
Jeff Brown68b909d2011-12-07 16:36:01 -0800351
Jeff Brown2e7760e2012-04-11 15:14:55 -0700352 int mLidState = LID_ABSENT;
Michael Wright3818c922014-09-02 13:59:07 -0700353 int mCameraLensCoverState = CAMERA_LENS_COVER_ABSENT;
Jeff Browndaa37532012-05-01 15:54:03 -0700354 boolean mHaveBuiltInKeyboard;
Jeff Brown4aed78b2011-01-14 17:36:55 -0800355
Dianne Hackbornc777e072010-02-12 13:07:59 -0800356 boolean mSystemReady;
Dianne Hackbornba24e4d2011-09-01 11:17:06 -0700357 boolean mSystemBooted;
Dianne Hackbornad7fa7f2011-01-07 14:06:50 -0800358 boolean mHdmiPlugged;
Jeff Brown4f5fa282014-06-12 19:19:15 -0700359 IUiModeManager mUiModeManager;
Daniel Sandler6396c722013-04-16 20:19:09 -0400360 int mUiMode;
Dianne Hackborn867ab6472010-04-29 13:28:56 -0700361 int mDockMode = Intent.EXTRA_DOCK_STATE_UNDOCKED;
Mike Lockwood1753f7f2009-08-24 14:49:07 -0700362 int mLidOpenRotation;
Mike Lockwood2d1efbd2009-09-16 12:15:53 -0400363 int mCarDockRotation;
364 int mDeskDockRotation;
Jeff Brownc82c89ed2013-04-17 17:18:15 -0700365 int mUndockedHdmiRotation;
366 int mDemoHdmiRotation;
367 boolean mDemoHdmiRotationLock;
Chong Zhangae6119ff2014-11-11 18:54:39 -0800368 int mDemoRotation;
369 boolean mDemoRotationLock;
Daniel Sandlerb73617d2010-08-17 00:41:00 -0400370
Jeff Browna20dda42014-05-27 20:57:24 -0700371 boolean mWakeGestureEnabledSetting;
372 MyWakeGestureListener mWakeGestureListener;
373
Craig Mautner46ac6fa2013-08-01 10:06:34 -0700374 // Default display does not rotate, apps that require non-default orientation will have to
375 // have the orientation emulated.
376 private boolean mForceDefaultOrientation = false;
377
Daniel Sandlerb73617d2010-08-17 00:41:00 -0400378 int mUserRotationMode = WindowManagerPolicy.USER_ROTATION_FREE;
379 int mUserRotation = Surface.ROTATION_0;
Jeff Brown207673cd2012-06-05 17:47:11 -0700380 boolean mAccelerometerDefault;
Daniel Sandlerb73617d2010-08-17 00:41:00 -0400381
Jeff Brownbcdfc622014-03-06 19:13:04 -0800382 boolean mSupportAutoRotation;
Jeff Brownd3187e32011-09-21 19:26:44 -0700383 int mAllowAllRotations = -1;
Mike Lockwoode9867d22009-09-20 01:59:02 -0400384 boolean mCarDockEnablesAccelerometer;
385 boolean mDeskDockEnablesAccelerometer;
Dianne Hackborn2862fff2009-09-15 22:56:29 -0700386 int mLidKeyboardAccessibility;
387 int mLidNavigationAccessibility;
Jeff Brownc458ce92012-04-30 14:58:40 -0700388 boolean mLidControlsSleep;
Jeff Brown13f00f02014-10-31 14:45:50 -0700389 int mShortPressOnPowerBehavior;
390 int mLongPressOnPowerBehavior;
391 int mDoublePressOnPowerBehavior;
392 int mTriplePressOnPowerBehavior;
Filip Gruszczynskia483a1d2015-03-17 19:06:58 +0000393 int mShortPressOnSleepBehavior;
Jeff Brown3ee549c2014-09-22 20:14:39 -0700394 boolean mAwake;
395 boolean mScreenOnEarly;
396 boolean mScreenOnFully;
397 ScreenOnListener mScreenOnListener;
398 boolean mKeyguardDrawComplete;
399 boolean mWindowManagerDrawComplete;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800400 boolean mOrientationSensorEnabled = false;
401 int mCurrentAppOrientation = ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800402 boolean mHasSoftInput = false;
Daniel Sandlerdd73ee42013-10-11 22:19:59 -0400403 boolean mTranslucentDecorEnabled = true;
RoboErik001c59c2015-01-26 15:53:51 -0800404 boolean mUseTvRouting;
Craig Mautner967212c2013-04-13 21:10:58 -0700405
Jeff Brown70825162012-03-28 17:27:48 -0700406 int mPointerLocationMode = 0; // guarded by mLock
Joe Onorato664644d2011-01-23 17:53:23 -0800407
408 // The last window we were told about in focusChanged.
409 WindowState mFocusedWindow;
Dianne Hackborne0f085d2011-11-30 18:41:15 -0800410 IApplicationToken mFocusedApp;
Joe Onorato664644d2011-01-23 17:53:23 -0800411
Jeff Brown70825162012-03-28 17:27:48 -0700412 PointerLocationView mPointerLocationView;
Jeff Brown32cbc38552011-12-01 14:01:49 -0800413
Dianne Hackbornc652de82013-02-15 16:32:56 -0800414 // The current size of the screen; really; extends into the overscan area of
415 // the screen and doesn't account for any system elements like the status bar.
416 int mOverscanScreenLeft, mOverscanScreenTop;
417 int mOverscanScreenWidth, mOverscanScreenHeight;
418 // The current visible size of the screen; really; (ir)regardless of whether the status
419 // bar can be hidden but not extending into the overscan area.
Joe Onorato29fc2c92010-11-24 10:26:50 -0800420 int mUnrestrictedScreenLeft, mUnrestrictedScreenTop;
421 int mUnrestrictedScreenWidth, mUnrestrictedScreenHeight;
Dianne Hackborn313440842013-02-19 19:22:59 -0800422 // Like mOverscanScreen*, but allowed to move into the overscan region where appropriate.
423 int mRestrictedOverscanScreenLeft, mRestrictedOverscanScreenTop;
424 int mRestrictedOverscanScreenWidth, mRestrictedOverscanScreenHeight;
Dianne Hackborn82de1ae2010-10-28 11:28:39 -0700425 // The current size of the screen; these may be different than (0,0)-(dw,dh)
426 // if the status bar can't be hidden; in that case it effectively carves out
427 // that area of the display from all other windows.
Joe Onorato29fc2c92010-11-24 10:26:50 -0800428 int mRestrictedScreenLeft, mRestrictedScreenTop;
429 int mRestrictedScreenWidth, mRestrictedScreenHeight;
Dianne Hackborn5c58de32012-04-28 19:52:37 -0700430 // During layout, the current screen borders accounting for any currently
431 // visible system UI elements.
432 int mSystemLeft, mSystemTop, mSystemRight, mSystemBottom;
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -0700433 // For applications requesting stable content insets, these are them.
434 int mStableLeft, mStableTop, mStableRight, mStableBottom;
Dianne Hackborn5b5cc4d2012-05-16 13:15:00 -0700435 // For applications requesting stable content insets but have also set the
436 // fullscreen window flag, these are the stable dimensions without the status bar.
437 int mStableFullscreenLeft, mStableFullscreenTop;
438 int mStableFullscreenRight, mStableFullscreenBottom;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800439 // During layout, the current screen borders with all outer decoration
440 // (status bar, input method dock) accounted for.
441 int mCurLeft, mCurTop, mCurRight, mCurBottom;
442 // During layout, the frame in which content should be displayed
443 // to the user, accounting for all screen decoration except for any
444 // space they deem as available for other content. This is usually
445 // the same as mCur*, but may be larger if the screen decor has supplied
446 // content insets.
447 int mContentLeft, mContentTop, mContentRight, mContentBottom;
Dianne Hackborne30e02f2014-05-27 18:24:45 -0700448 // During layout, the frame in which voice content should be displayed
449 // to the user, accounting for all screen decoration except for any
450 // space they deem as available for other content.
451 int mVoiceContentLeft, mVoiceContentTop, mVoiceContentRight, mVoiceContentBottom;
Dianne Hackborn8e11ef02010-11-18 19:47:42 -0800452 // During layout, the current screen borders along which input method
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800453 // windows are placed.
454 int mDockLeft, mDockTop, mDockRight, mDockBottom;
455 // During layout, the layer at which the doc window is placed.
456 int mDockLayer;
Dianne Hackborn5c58de32012-04-28 19:52:37 -0700457 // During layout, this is the layer of the status bar.
458 int mStatusBarLayer;
Dianne Hackborne26ab702011-10-16 13:21:33 -0700459 int mLastSystemUiFlags;
460 // Bits that we are in the process of clearing, so we want to prevent
461 // them from being set by applications until everything has been updated
462 // to have them clear.
463 int mResettingSystemUiFlags = 0;
464 // Bits that we are currently always keeping cleared.
465 int mForceClearedSystemUiFlags = 0;
Dianne Hackborn4eff8d32011-11-10 19:38:40 -0800466 // What we last reported to system UI about whether the compatibility
467 // menu needs to be displayed.
468 boolean mLastFocusNeedsMenu = false;
Adrian Roosddc8b272015-05-21 16:28:27 -0700469 // If nonzero, a panic gesture was performed at that time in uptime millis and is still pending.
470 private long mPendingPanicGestureUptime;
Dianne Hackborndf89e652011-10-06 22:35:11 -0700471
Selim Cinekf83e8242015-05-19 18:08:14 -0700472 InputConsumer mInputConsumer = null;
Dianne Hackborndf89e652011-10-06 22:35:11 -0700473
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800474 static final Rect mTmpParentFrame = new Rect();
475 static final Rect mTmpDisplayFrame = new Rect();
Dianne Hackbornc4aad012013-02-22 15:05:25 -0800476 static final Rect mTmpOverscanFrame = new Rect();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800477 static final Rect mTmpContentFrame = new Rect();
478 static final Rect mTmpVisibleFrame = new Rect();
John Spurlock46646232013-09-30 22:32:42 -0400479 static final Rect mTmpDecorFrame = new Rect();
Adrian Roosfa104232014-06-20 16:10:14 -0700480 static final Rect mTmpStableFrame = new Rect();
Dianne Hackborn1f903c32011-09-13 19:18:06 -0700481 static final Rect mTmpNavigationFrame = new Rect();
Filip Gruszczynski2217f612015-05-26 11:32:08 -0700482 static final Rect mTmpOutsetFrame = new Rect();
Craig Mautner967212c2013-04-13 21:10:58 -0700483
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800484 WindowState mTopFullscreenOpaqueWindowState;
Adrian Rooscd3884d2015-02-18 17:25:23 +0100485 WindowState mTopFullscreenOpaqueOrDimmingWindowState;
Craig Mautner2bc789b2014-03-19 19:48:38 -0700486 HashSet<IApplicationToken> mAppsToBeHidden = new HashSet<IApplicationToken>();
Jorim Jaggic13fcac2014-09-11 17:36:57 +0200487 HashSet<IApplicationToken> mAppsThatDismissKeyguard = new HashSet<IApplicationToken>();
Joe Onorato93056472010-09-10 10:30:46 -0400488 boolean mTopIsFullscreen;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800489 boolean mForceStatusBar;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -0700490 boolean mForceStatusBarFromKeyguard;
Selim Cinek4a4a2bddc2015-05-07 12:50:19 -0700491 private boolean mForceStatusBarTransparent;
Dianne Hackborn39c2d712009-09-22 11:41:31 -0700492 boolean mHideLockScreen;
Dianne Hackborn891d3fb2013-01-09 18:31:37 -0800493 boolean mForcingShowNavBar;
494 int mForcingShowNavBarLayer;
Craig Mautnerad09bcc2012-10-08 13:33:11 -0700495
496 // States of keyguard dismiss.
497 private static final int DISMISS_KEYGUARD_NONE = 0; // Keyguard not being dismissed.
498 private static final int DISMISS_KEYGUARD_START = 1; // Keyguard needs to be dismissed.
499 private static final int DISMISS_KEYGUARD_CONTINUE = 2; // Keyguard has been dismissed.
500 int mDismissKeyguard = DISMISS_KEYGUARD_NONE;
501
502 /** The window that is currently dismissing the keyguard. Dismissing the keyguard must only
503 * be done once per window. */
504 private WindowState mWinDismissingKeyguard;
505
tingna_sunge785ffa2015-05-12 13:23:15 +0800506 /** When window is currently dismissing the keyguard, dismissing the keyguard must handle
507 * the keygaurd secure state change instantly case, e.g. the use case of inserting a PIN
508 * lock SIM card. This variable is used to record the previous keyguard secure state for
509 * monitoring secure state change on window dismissing keyguard. */
510 private boolean mSecureDismissingKeyguard;
511
Craig Mautnerc9457fa2014-06-06 14:27:48 -0700512 /** The window that is currently showing "over" the keyguard. If there is an app window
513 * belonging to another app on top of this the keyguard shows. If there is a fullscreen
514 * app window under this, still dismiss the keyguard but don't show the app underneath. Show
515 * the wallpaper. */
516 private WindowState mWinShowWhenLocked;
517
Dianne Hackborn7ad44382012-10-18 17:46:00 -0700518 boolean mShowingLockscreen;
519 boolean mShowingDream;
520 boolean mDreamingLockscreen;
Jeff Brown061ea992015-04-17 19:55:47 -0700521 boolean mDreamingSleepTokenNeeded;
522 SleepToken mDreamingSleepToken;
Jeff Brown48d1b142015-06-10 16:36:03 -0700523 SleepToken mScreenOffSleepToken;
Jim Millerab954542014-10-10 18:21:49 -0700524 boolean mKeyguardSecure;
525 boolean mKeyguardSecureIncludingHidden;
526 volatile boolean mKeyguardOccluded;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800527 boolean mHomePressed;
Jeff Browncaca8812013-05-09 13:34:33 -0700528 boolean mHomeConsumed;
529 boolean mHomeDoubleTapPending;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800530 Intent mHomeIntent;
Dianne Hackborn39c2d712009-09-22 11:41:31 -0700531 Intent mCarDockIntent;
532 Intent mDeskDockIntent;
Jeff Brownfd23e3e2012-05-09 13:34:28 -0700533 boolean mSearchKeyShortcutPending;
534 boolean mConsumeSearchKeyUp;
Jeff Brownde7a8ea2012-06-13 18:28:57 -0700535 boolean mAssistKeyLongPressed;
Michael Wright6a62e552014-06-03 19:19:48 -0700536 boolean mPendingMetaAction;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800537
Mike Lockwood28569302010-01-28 11:54:40 -0500538 // support for activating the lock screen while the screen is on
539 boolean mAllowLockscreenWhenOn;
540 int mLockScreenTimeout;
541 boolean mLockScreenTimerActive;
542
David Brownbaf8d092010-03-08 21:52:59 -0800543 // Behavior of ENDCALL Button. (See Settings.System.END_BUTTON_BEHAVIOR.)
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800544 int mEndcallBehavior;
David Brownbaf8d092010-03-08 21:52:59 -0800545
546 // Behavior of POWER button while in-call and screen on.
547 // (See Settings.Secure.INCALL_POWER_BUTTON_BEHAVIOR.)
548 int mIncallPowerBehavior;
549
Dianne Hackbornf87d1962012-04-04 12:48:24 -0700550 Display mDisplay;
551
Dianne Hackborn9d132642011-04-21 17:26:39 -0700552 int mLandscapeRotation = 0; // default landscape rotation
553 int mSeascapeRotation = 0; // "other" landscape rotation, 180 degrees from mLandscapeRotation
554 int mPortraitRotation = 0; // default portrait rotation
555 int mUpsideDownRotation = 0; // "other" portrait rotation
Mitsuru Oshima831d0d92009-06-16 18:27:18 -0700556
Dianne Hackbornc652de82013-02-15 16:32:56 -0800557 int mOverscanLeft = 0;
558 int mOverscanTop = 0;
559 int mOverscanRight = 0;
560 int mOverscanBottom = 0;
561
Joe Onorato46b0d682010-11-22 17:37:27 -0800562 // What we do when the user long presses on home
Jeff Browncaca8812013-05-09 13:34:33 -0700563 private int mLongPressOnHomeBehavior;
564
565 // What we do when the user double-taps on home
566 private int mDoubleTapOnHomeBehavior;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800567
Bryce Lee584a4452014-10-21 15:55:55 -0700568 // Allowed theater mode wake actions
569 private boolean mAllowTheaterModeWakeFromKey;
570 private boolean mAllowTheaterModeWakeFromPowerKey;
571 private boolean mAllowTheaterModeWakeFromMotion;
Bryce Lee812d7022014-11-10 13:33:28 -0800572 private boolean mAllowTheaterModeWakeFromMotionWhenNotDreaming;
Bryce Lee584a4452014-10-21 15:55:55 -0700573 private boolean mAllowTheaterModeWakeFromCameraLens;
574 private boolean mAllowTheaterModeWakeFromLidSwitch;
575 private boolean mAllowTheaterModeWakeFromWakeGesture;
576
Bryce Leed3b28402015-03-09 15:49:13 +0000577 // Whether to support long press from power button in non-interactive mode
578 private boolean mSupportLongPressPowerWhenNonInteractive;
579
Bryce Lee55e846d2014-11-04 12:43:44 -0800580 // Whether to go to sleep entering theater mode from power button
581 private boolean mGoToSleepOnButtonPressTheaterMode;
582
Winson Chung9112ec32011-06-27 13:15:32 -0700583 // Screenshot trigger states
Jeff Brownd5bb82d2011-10-12 13:57:59 -0700584 // Time to volume and power must be pressed within this interval of each other.
585 private static final long SCREENSHOT_CHORD_DEBOUNCE_DELAY_MILLIS = 150;
Winson Chung1cea2f32012-10-08 20:42:01 -0700586 // Increase the chord delay when taking a screenshot from the keyguard
587 private static final float KEYGUARD_SCREENSHOT_CHORD_DELAY_MULTIPLIER = 2.5f;
Christopher Tatee90585f2012-03-05 18:56:25 -0800588 private boolean mScreenshotChordEnabled;
Jeff Brown13f00f02014-10-31 14:45:50 -0700589 private boolean mScreenshotChordVolumeDownKeyTriggered;
590 private long mScreenshotChordVolumeDownKeyTime;
591 private boolean mScreenshotChordVolumeDownKeyConsumed;
592 private boolean mScreenshotChordVolumeUpKeyTriggered;
593 private boolean mScreenshotChordPowerKeyTriggered;
594 private long mScreenshotChordPowerKeyTime;
Winson Chung9112ec32011-06-27 13:15:32 -0700595
Michael Wrightb854e242013-02-05 17:54:02 -0800596 /* The number of steps between min and max brightness */
597 private static final int BRIGHTNESS_STEPS = 10;
598
Christopher Tate5e08af02012-09-21 17:17:22 -0700599 SettingsObserver mSettingsObserver;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800600 ShortcutManager mShortcutManager;
601 PowerManager.WakeLock mBroadcastWakeLock;
Jeff Brown13f00f02014-10-31 14:45:50 -0700602 PowerManager.WakeLock mPowerKeyWakeLock;
Jeff Brown40013652012-05-16 21:22:36 -0700603 boolean mHavePendingMediaKeyRepeatWithWakeLock;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800604
Craig Mautnerd625ab22013-09-06 13:40:31 -0700605 private int mCurrentUserId;
606
Justin Kohd378ad72013-04-01 12:18:26 -0700607 // Maps global key codes to the components that will handle them.
608 private GlobalKeyManager mGlobalKeyManager;
609
Jeff Brownfd23e3e2012-05-09 13:34:28 -0700610 // Fallback actions by key code.
611 private final SparseArray<KeyCharacterMap.FallbackAction> mFallbackActions =
612 new SparseArray<KeyCharacterMap.FallbackAction>();
Jeff Brown49ed71d2010-12-06 17:13:33 -0800613
Jorim Jaggi76a16232014-08-08 17:00:47 +0200614 private final LogDecelerateInterpolator mLogDecelerateInterpolator
615 = new LogDecelerateInterpolator(100, 0);
616
Jeff Brown70825162012-03-28 17:27:48 -0700617 private static final int MSG_ENABLE_POINTER_LOCATION = 1;
618 private static final int MSG_DISABLE_POINTER_LOCATION = 2;
Jeff Brown40013652012-05-16 21:22:36 -0700619 private static final int MSG_DISPATCH_MEDIA_KEY_WITH_WAKE_LOCK = 3;
620 private static final int MSG_DISPATCH_MEDIA_KEY_REPEAT_WITH_WAKE_LOCK = 4;
Craig Mautner8a0da012014-05-31 15:13:37 -0700621 private static final int MSG_KEYGUARD_DRAWN_COMPLETE = 5;
622 private static final int MSG_KEYGUARD_DRAWN_TIMEOUT = 6;
623 private static final int MSG_WINDOW_MANAGER_DRAWN_COMPLETE = 7;
Craig Mautner84984fa2014-06-19 11:19:20 -0700624 private static final int MSG_DISPATCH_SHOW_RECENTS = 9;
Alan Viverettee34560b22014-07-10 14:50:06 -0700625 private static final int MSG_DISPATCH_SHOW_GLOBAL_ACTIONS = 10;
Craig Mautnera631d492014-08-05 15:16:01 -0700626 private static final int MSG_HIDE_BOOT_MESSAGE = 11;
Michael Wright869a67c2014-08-26 19:33:06 -0700627 private static final int MSG_LAUNCH_VOICE_ASSIST_WITH_WAKE_LOCK = 12;
Jeff Brown13f00f02014-10-31 14:45:50 -0700628 private static final int MSG_POWER_DELAYED_PRESS = 13;
629 private static final int MSG_POWER_LONG_PRESS = 14;
Jeff Brown061ea992015-04-17 19:55:47 -0700630 private static final int MSG_UPDATE_DREAMING_SLEEP_TOKEN = 15;
Jeff Brown70825162012-03-28 17:27:48 -0700631
632 private class PolicyHandler extends Handler {
633 @Override
634 public void handleMessage(Message msg) {
635 switch (msg.what) {
636 case MSG_ENABLE_POINTER_LOCATION:
637 enablePointerLocation();
638 break;
639 case MSG_DISABLE_POINTER_LOCATION:
640 disablePointerLocation();
641 break;
Jeff Brown40013652012-05-16 21:22:36 -0700642 case MSG_DISPATCH_MEDIA_KEY_WITH_WAKE_LOCK:
643 dispatchMediaKeyWithWakeLock((KeyEvent)msg.obj);
644 break;
645 case MSG_DISPATCH_MEDIA_KEY_REPEAT_WITH_WAKE_LOCK:
646 dispatchMediaKeyRepeatWithWakeLock((KeyEvent)msg.obj);
647 break;
Craig Mautner84984fa2014-06-19 11:19:20 -0700648 case MSG_DISPATCH_SHOW_RECENTS:
649 showRecentApps(false);
650 break;
Alan Viverettee34560b22014-07-10 14:50:06 -0700651 case MSG_DISPATCH_SHOW_GLOBAL_ACTIONS:
652 showGlobalActionsInternal();
653 break;
Craig Mautner8a0da012014-05-31 15:13:37 -0700654 case MSG_KEYGUARD_DRAWN_COMPLETE:
655 if (DEBUG_WAKEUP) Slog.w(TAG, "Setting mKeyguardDrawComplete");
Jeff Brown36c4db82014-09-19 12:05:31 -0700656 finishKeyguardDrawn();
Craig Mautner8a0da012014-05-31 15:13:37 -0700657 break;
658 case MSG_KEYGUARD_DRAWN_TIMEOUT:
659 Slog.w(TAG, "Keyguard drawn timeout. Setting mKeyguardDrawComplete");
Jeff Brown36c4db82014-09-19 12:05:31 -0700660 finishKeyguardDrawn();
Craig Mautner8a0da012014-05-31 15:13:37 -0700661 break;
662 case MSG_WINDOW_MANAGER_DRAWN_COMPLETE:
663 if (DEBUG_WAKEUP) Slog.w(TAG, "Setting mWindowManagerDrawComplete");
Jeff Brown36c4db82014-09-19 12:05:31 -0700664 finishWindowsDrawn();
Craig Mautner8a0da012014-05-31 15:13:37 -0700665 break;
Craig Mautnera631d492014-08-05 15:16:01 -0700666 case MSG_HIDE_BOOT_MESSAGE:
667 handleHideBootMessage();
668 break;
Michael Wright869a67c2014-08-26 19:33:06 -0700669 case MSG_LAUNCH_VOICE_ASSIST_WITH_WAKE_LOCK:
670 launchVoiceAssistWithWakeLock(msg.arg1 != 0);
671 break;
Jeff Brown13f00f02014-10-31 14:45:50 -0700672 case MSG_POWER_DELAYED_PRESS:
673 powerPress((Long)msg.obj, msg.arg1 != 0, msg.arg2);
674 finishPowerKeyPress();
675 break;
676 case MSG_POWER_LONG_PRESS:
677 powerLongPress();
678 break;
Jeff Brown061ea992015-04-17 19:55:47 -0700679 case MSG_UPDATE_DREAMING_SLEEP_TOKEN:
680 updateDreamingSleepToken(msg.arg1 != 0);
681 break;
Jeff Brown70825162012-03-28 17:27:48 -0700682 }
683 }
684 }
685
Dianne Hackbornad7fa7f2011-01-07 14:06:50 -0800686 private UEventObserver mHDMIObserver = new UEventObserver() {
687 @Override
688 public void onUEvent(UEventObserver.UEvent event) {
689 setHdmiPlugged("1".equals(event.get("SWITCH_STATE")));
690 }
691 };
692
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800693 class SettingsObserver extends ContentObserver {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800694 SettingsObserver(Handler handler) {
695 super(handler);
696 }
David Brownbaf8d092010-03-08 21:52:59 -0800697
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800698 void observe() {
Christopher Tate5e08af02012-09-21 17:17:22 -0700699 // Observe all users' changes
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800700 ContentResolver resolver = mContext.getContentResolver();
701 resolver.registerContentObserver(Settings.System.getUriFor(
Christopher Tate5e08af02012-09-21 17:17:22 -0700702 Settings.System.END_BUTTON_BEHAVIOR), false, this,
703 UserHandle.USER_ALL);
David Brownbaf8d092010-03-08 21:52:59 -0800704 resolver.registerContentObserver(Settings.Secure.getUriFor(
Christopher Tate5e08af02012-09-21 17:17:22 -0700705 Settings.Secure.INCALL_POWER_BUTTON_BEHAVIOR), false, this,
706 UserHandle.USER_ALL);
Jeff Browna20dda42014-05-27 20:57:24 -0700707 resolver.registerContentObserver(Settings.Secure.getUriFor(
708 Settings.Secure.WAKE_GESTURE_ENABLED), false, this,
709 UserHandle.USER_ALL);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800710 resolver.registerContentObserver(Settings.System.getUriFor(
Christopher Tate5e08af02012-09-21 17:17:22 -0700711 Settings.System.ACCELEROMETER_ROTATION), false, this,
712 UserHandle.USER_ALL);
Mike Lockwood28569302010-01-28 11:54:40 -0500713 resolver.registerContentObserver(Settings.System.getUriFor(
Christopher Tate5e08af02012-09-21 17:17:22 -0700714 Settings.System.USER_ROTATION), false, this,
715 UserHandle.USER_ALL);
Daniel Sandlerb73617d2010-08-17 00:41:00 -0400716 resolver.registerContentObserver(Settings.System.getUriFor(
Christopher Tate5e08af02012-09-21 17:17:22 -0700717 Settings.System.SCREEN_OFF_TIMEOUT), false, this,
718 UserHandle.USER_ALL);
Dianne Hackbornc777e072010-02-12 13:07:59 -0800719 resolver.registerContentObserver(Settings.System.getUriFor(
Christopher Tate5e08af02012-09-21 17:17:22 -0700720 Settings.System.POINTER_LOCATION), false, this,
721 UserHandle.USER_ALL);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800722 resolver.registerContentObserver(Settings.Secure.getUriFor(
Christopher Tate5e08af02012-09-21 17:17:22 -0700723 Settings.Secure.DEFAULT_INPUT_METHOD), false, this,
724 UserHandle.USER_ALL);
John Spurlockd9b70bd2014-02-06 17:02:44 -0500725 resolver.registerContentObserver(Settings.Secure.getUriFor(
John Spurlockf1a36642013-10-12 17:50:42 -0400726 Settings.Secure.IMMERSIVE_MODE_CONFIRMATIONS), false, this,
Christopher Tate5e08af02012-09-21 17:17:22 -0700727 UserHandle.USER_ALL);
John Spurlockc6d1c602014-01-17 15:22:06 -0500728 resolver.registerContentObserver(Settings.Global.getUriFor(
729 Settings.Global.POLICY_CONTROL), false, this,
730 UserHandle.USER_ALL);
Dianne Hackbornc777e072010-02-12 13:07:59 -0800731 updateSettings();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800732 }
733
734 @Override public void onChange(boolean selfChange) {
Dianne Hackbornc777e072010-02-12 13:07:59 -0800735 updateSettings();
Jeff Brown01a98dd2011-09-20 15:08:29 -0700736 updateRotation(false);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800737 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800738 }
Craig Mautner967212c2013-04-13 21:10:58 -0700739
Jeff Browna20dda42014-05-27 20:57:24 -0700740 class MyWakeGestureListener extends WakeGestureListener {
741 MyWakeGestureListener(Context context, Handler handler) {
742 super(context, handler);
743 }
744
745 @Override
746 public void onWakeUp() {
747 synchronized (mLock) {
748 if (shouldEnableWakeGestureLp()) {
Jeff Browne07b94b2014-06-18 15:56:27 -0700749 performHapticFeedbackLw(null, HapticFeedbackConstants.VIRTUAL_KEY, false);
Bryce Lee584a4452014-10-21 15:55:55 -0700750 wakeUp(SystemClock.uptimeMillis(), mAllowTheaterModeWakeFromWakeGesture);
Jeff Browna20dda42014-05-27 20:57:24 -0700751 }
752 }
753 }
754 }
755
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800756 class MyOrientationListener extends WindowOrientationListener {
Craig Mautnereee29c42013-01-17 14:44:34 -0800757 MyOrientationListener(Context context, Handler handler) {
758 super(context, handler);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800759 }
Craig Mautner967212c2013-04-13 21:10:58 -0700760
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800761 @Override
Jeff Brownc0347aa2011-09-23 17:26:09 -0700762 public void onProposedRotationChanged(int rotation) {
Craig Mautnereda67292013-04-28 13:50:14 -0700763 if (localLOGV) Slog.v(TAG, "onProposedRotationChanged, rotation=" + rotation);
Jeff Brown01a98dd2011-09-20 15:08:29 -0700764 updateRotation(false);
765 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800766 }
767 MyOrientationListener mOrientationListener;
768
Jorim Jaggi24bec7c2015-02-04 12:40:14 +0100769 private final StatusBarController mStatusBarController = new StatusBarController();
John Spurlock5b9145b2013-08-20 15:13:47 -0400770
John Spurlock27735a42013-08-14 17:57:38 -0400771 private final BarController mNavigationBarController = new BarController("NavigationBar",
John Spurlock5b9145b2013-08-20 15:13:47 -0400772 View.NAVIGATION_BAR_TRANSIENT,
773 View.NAVIGATION_BAR_UNHIDE,
John Spurlockbd957402013-10-03 11:38:39 -0400774 View.NAVIGATION_BAR_TRANSLUCENT,
775 StatusBarManager.WINDOW_NAVIGATION_BAR,
776 WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION);
John Spurlock5b9145b2013-08-20 15:13:47 -0400777
John Spurlockf1a36642013-10-12 17:50:42 -0400778 private ImmersiveModeConfirmation mImmersiveModeConfirmation;
John Spurlock32beb2c2013-03-11 10:16:47 -0400779
Craig Mautner037aa8d2013-06-07 10:35:44 -0700780 private SystemGesturesPointerEventListener mSystemGestures;
John Spurlock32beb2c2013-03-11 10:16:47 -0400781
Dianne Hackborn42e620c2012-06-24 13:20:51 -0700782 IStatusBarService getStatusBarService() {
783 synchronized (mServiceAquireLock) {
784 if (mStatusBarService == null) {
785 mStatusBarService = IStatusBarService.Stub.asInterface(
786 ServiceManager.getService("statusbar"));
787 }
788 return mStatusBarService;
789 }
790 }
791
Suchi Amalapurapua9e1b162009-03-24 22:24:47 -0700792 /*
793 * We always let the sensor be switched on by default except when
794 * the user has explicitly disabled sensor based rotation or when the
795 * screen is switched off.
796 */
The Android Open Source Project0727d222009-03-11 12:11:58 -0700797 boolean needSensorRunningLp() {
Jeff Brownbcdfc622014-03-06 19:13:04 -0800798 if (mSupportAutoRotation) {
799 if (mCurrentAppOrientation == ActivityInfo.SCREEN_ORIENTATION_SENSOR
800 || mCurrentAppOrientation == ActivityInfo.SCREEN_ORIENTATION_FULL_SENSOR
801 || mCurrentAppOrientation == ActivityInfo.SCREEN_ORIENTATION_SENSOR_PORTRAIT
802 || mCurrentAppOrientation == ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE) {
803 // If the application has explicitly requested to follow the
804 // orientation, then we need to turn the sensor on.
805 return true;
806 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800807 }
Dianne Hackborn867ab6472010-04-29 13:28:56 -0700808 if ((mCarDockEnablesAccelerometer && mDockMode == Intent.EXTRA_DOCK_STATE_CAR) ||
Jeff Brown1a693182011-11-08 14:44:16 -0800809 (mDeskDockEnablesAccelerometer && (mDockMode == Intent.EXTRA_DOCK_STATE_DESK
810 || mDockMode == Intent.EXTRA_DOCK_STATE_LE_DESK
811 || mDockMode == Intent.EXTRA_DOCK_STATE_HE_DESK))) {
Mike Lockwoode9867d22009-09-20 01:59:02 -0400812 // enable accelerometer if we are docked in a dock that enables accelerometer
813 // orientation management,
814 return true;
815 }
Jeff Brown207673cd2012-06-05 17:47:11 -0700816 if (mUserRotationMode == USER_ROTATION_LOCKED) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800817 // If the setting for using the sensor by default is enabled, then
818 // we will always leave it on. Note that the user could go to
819 // a window that forces an orientation that does not use the
820 // sensor and in theory we could turn it off... however, when next
821 // turning it on we won't have a good value for the current
822 // orientation for a little bit, which can cause orientation
823 // changes to lag, so we'd like to keep it always on. (It will
824 // still be turned off when the screen is off.)
Suchi Amalapurapua9e1b162009-03-24 22:24:47 -0700825 return false;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800826 }
Jeff Brownbcdfc622014-03-06 19:13:04 -0800827 return mSupportAutoRotation;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800828 }
Craig Mautner46ac6fa2013-08-01 10:06:34 -0700829
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800830 /*
831 * Various use cases for invoking this function
832 * screen turning off, should always disable listeners if already enabled
Craig Mautner46ac6fa2013-08-01 10:06:34 -0700833 * screen turned on and current app has sensor based orientation, enable listeners
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800834 * if not already enabled
835 * screen turned on and current app does not have sensor orientation, disable listeners if
836 * already enabled
837 * screen turning on and current app has sensor based orientation, enable listeners if needed
838 * screen turning on and current app has nosensor based orientation, do nothing
839 */
The Android Open Source Project0727d222009-03-11 12:11:58 -0700840 void updateOrientationListenerLp() {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800841 if (!mOrientationListener.canDetectOrientation()) {
842 // If sensor is turned off or nonexistent for some reason
843 return;
844 }
Stefan Kuhne9326dc12015-06-12 09:25:32 -1000845 // Could have been invoked due to screen turning on or off or
846 // change of the currently visible window's orientation.
Jeff Brown3ee549c2014-09-22 20:14:39 -0700847 if (localLOGV) Slog.v(TAG, "mScreenOnEarly=" + mScreenOnEarly
848 + ", mAwake=" + mAwake + ", mCurrentAppOrientation=" + mCurrentAppOrientation
Stefan Kuhne9326dc12015-06-12 09:25:32 -1000849 + ", mOrientationSensorEnabled=" + mOrientationSensorEnabled
850 + ", mKeyguardDrawComplete=" + mKeyguardDrawComplete
851 + ", mWindowManagerDrawComplete=" + mWindowManagerDrawComplete);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800852 boolean disable = true;
Stefan Kuhne9326dc12015-06-12 09:25:32 -1000853 // Note: We postpone the rotating of the screen until the keyguard as well as the
854 // window manager have reported a draw complete.
855 if (mScreenOnEarly && mAwake &&
856 mKeyguardDrawComplete && mWindowManagerDrawComplete) {
The Android Open Source Project0727d222009-03-11 12:11:58 -0700857 if (needSensorRunningLp()) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800858 disable = false;
859 //enable listener if not already enabled
The Android Open Source Project0727d222009-03-11 12:11:58 -0700860 if (!mOrientationSensorEnabled) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800861 mOrientationListener.enable();
Craig Mautnereda67292013-04-28 13:50:14 -0700862 if(localLOGV) Slog.v(TAG, "Enabling listeners");
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800863 mOrientationSensorEnabled = true;
864 }
Craig Mautner46ac6fa2013-08-01 10:06:34 -0700865 }
866 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800867 //check if sensors need to be disabled
The Android Open Source Project0727d222009-03-11 12:11:58 -0700868 if (disable && mOrientationSensorEnabled) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800869 mOrientationListener.disable();
Craig Mautnereda67292013-04-28 13:50:14 -0700870 if(localLOGV) Slog.v(TAG, "Disabling listeners");
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800871 mOrientationSensorEnabled = false;
872 }
873 }
874
Jeff Brown13f00f02014-10-31 14:45:50 -0700875 private void interceptPowerKeyDown(KeyEvent event, boolean interactive) {
876 // Hold a wake lock until the power key is released.
877 if (!mPowerKeyWakeLock.isHeld()) {
878 mPowerKeyWakeLock.acquire();
879 }
880
881 // Cancel multi-press detection timeout.
882 if (mPowerKeyPressCounter != 0) {
883 mHandler.removeMessages(MSG_POWER_DELAYED_PRESS);
884 }
885
886 // Detect user pressing the power button in panic when an application has
887 // taken over the whole screen.
888 boolean panic = mImmersiveModeConfirmation.onPowerKeyDown(interactive,
Craig Mautner0124980e92014-11-30 21:15:34 -0800889 SystemClock.elapsedRealtime(), isImmersiveMode(mLastSystemUiFlags));
Jeff Brown13f00f02014-10-31 14:45:50 -0700890 if (panic) {
Adrian Roosddc8b272015-05-21 16:28:27 -0700891 mHandler.post(mHiddenNavPanic);
Jeff Brown13f00f02014-10-31 14:45:50 -0700892 }
893
894 // Latch power key state to detect screenshot chord.
895 if (interactive && !mScreenshotChordPowerKeyTriggered
896 && (event.getFlags() & KeyEvent.FLAG_FALLBACK) == 0) {
897 mScreenshotChordPowerKeyTriggered = true;
898 mScreenshotChordPowerKeyTime = event.getDownTime();
899 interceptScreenshotChord();
900 }
901
902 // Stop ringing or end call if configured to do so when power is pressed.
903 TelecomManager telecomManager = getTelecommService();
904 boolean hungUp = false;
905 if (telecomManager != null) {
906 if (telecomManager.isRinging()) {
907 // Pressing Power while there's a ringing incoming
908 // call should silence the ringer.
909 telecomManager.silenceRinger();
910 } else if ((mIncallPowerBehavior
911 & Settings.Secure.INCALL_POWER_BUTTON_BEHAVIOR_HANGUP) != 0
912 && telecomManager.isInCall() && interactive) {
913 // Otherwise, if "Power button ends call" is enabled,
914 // the Power button will hang up any current active call.
915 hungUp = telecomManager.endCall();
916 }
917 }
918
919 // If the power key has still not yet been handled, then detect short
920 // press, long press, or multi press and decide what to do.
921 mPowerKeyHandled = hungUp || mScreenshotChordVolumeDownKeyTriggered
922 || mScreenshotChordVolumeUpKeyTriggered;
923 if (!mPowerKeyHandled) {
924 if (interactive) {
925 // When interactive, we're already awake.
926 // Wait for a long press or for the button to be released to decide what to do.
927 if (hasLongPressOnPowerBehavior()) {
928 Message msg = mHandler.obtainMessage(MSG_POWER_LONG_PRESS);
929 msg.setAsynchronous(true);
930 mHandler.sendMessageDelayed(msg,
931 ViewConfiguration.get(mContext).getDeviceGlobalActionKeyTimeout());
932 }
933 } else {
Bryce Leed9268e32014-11-17 17:40:59 -0800934 wakeUpFromPowerKey(event.getDownTime());
Bryce Leed9268e32014-11-17 17:40:59 -0800935
Bryce Leed3b28402015-03-09 15:49:13 +0000936 if (mSupportLongPressPowerWhenNonInteractive && hasLongPressOnPowerBehavior()) {
937 Message msg = mHandler.obtainMessage(MSG_POWER_LONG_PRESS);
938 msg.setAsynchronous(true);
939 mHandler.sendMessageDelayed(msg,
940 ViewConfiguration.get(mContext).getDeviceGlobalActionKeyTimeout());
Bryce Leed9268e32014-11-17 17:40:59 -0800941 mBeganFromNonInteractive = true;
Bryce Leed3b28402015-03-09 15:49:13 +0000942 } else {
943 final int maxCount = getMaxMultiPressPowerCount();
944
945 if (maxCount <= 1) {
946 mPowerKeyHandled = true;
947 } else {
948 mBeganFromNonInteractive = true;
949 }
Jeff Brown13f00f02014-10-31 14:45:50 -0700950 }
951 }
Jeff Brown4d396052010-10-29 21:50:21 -0700952 }
953 }
954
Jeff Brown13f00f02014-10-31 14:45:50 -0700955 private void interceptPowerKeyUp(KeyEvent event, boolean interactive, boolean canceled) {
956 final boolean handled = canceled || mPowerKeyHandled;
957 mScreenshotChordPowerKeyTriggered = false;
958 cancelPendingScreenshotChordAction();
959 cancelPendingPowerKeyAction();
960
961 if (!handled) {
962 // Figure out how to handle the key now that it has been released.
963 mPowerKeyPressCounter += 1;
964
965 final int maxCount = getMaxMultiPressPowerCount();
966 final long eventTime = event.getDownTime();
967 if (mPowerKeyPressCounter < maxCount) {
968 // This could be a multi-press. Wait a little bit longer to confirm.
969 // Continue holding the wake lock.
970 Message msg = mHandler.obtainMessage(MSG_POWER_DELAYED_PRESS,
971 interactive ? 1 : 0, mPowerKeyPressCounter, eventTime);
972 msg.setAsynchronous(true);
973 mHandler.sendMessageDelayed(msg, ViewConfiguration.getDoubleTapTimeout());
974 return;
975 }
976
977 // No other actions. Handle it immediately.
978 powerPress(eventTime, interactive, mPowerKeyPressCounter);
Jeff Brown4d396052010-10-29 21:50:21 -0700979 }
Jeff Brown13f00f02014-10-31 14:45:50 -0700980
981 // Done. Reset our state.
982 finishPowerKeyPress();
983 }
984
985 private void finishPowerKeyPress() {
Bryce Leed9268e32014-11-17 17:40:59 -0800986 mBeganFromNonInteractive = false;
Jeff Brown13f00f02014-10-31 14:45:50 -0700987 mPowerKeyPressCounter = 0;
988 if (mPowerKeyWakeLock.isHeld()) {
989 mPowerKeyWakeLock.release();
990 }
Jeff Brownd5bb82d2011-10-12 13:57:59 -0700991 }
992
993 private void cancelPendingPowerKeyAction() {
994 if (!mPowerKeyHandled) {
Jeff Brown13f00f02014-10-31 14:45:50 -0700995 mPowerKeyHandled = true;
996 mHandler.removeMessages(MSG_POWER_LONG_PRESS);
Jeff Brownd5bb82d2011-10-12 13:57:59 -0700997 }
Jeff Brown13f00f02014-10-31 14:45:50 -0700998 }
999
1000 private void powerPress(long eventTime, boolean interactive, int count) {
1001 if (mScreenOnEarly && !mScreenOnFully) {
1002 Slog.i(TAG, "Suppressed redundant power key press while "
1003 + "already in the process of turning the screen on.");
1004 return;
Jeff Brownff204712011-10-25 21:27:54 -07001005 }
Jeff Brown13f00f02014-10-31 14:45:50 -07001006
1007 if (count == 2) {
1008 powerMultiPressAction(eventTime, interactive, mDoublePressOnPowerBehavior);
1009 } else if (count == 3) {
1010 powerMultiPressAction(eventTime, interactive, mTriplePressOnPowerBehavior);
Bryce Leed9268e32014-11-17 17:40:59 -08001011 } else if (interactive && !mBeganFromNonInteractive) {
Jeff Brown13f00f02014-10-31 14:45:50 -07001012 switch (mShortPressOnPowerBehavior) {
1013 case SHORT_PRESS_POWER_NOTHING:
1014 break;
1015 case SHORT_PRESS_POWER_GO_TO_SLEEP:
1016 mPowerManager.goToSleep(eventTime,
1017 PowerManager.GO_TO_SLEEP_REASON_POWER_BUTTON, 0);
1018 break;
1019 case SHORT_PRESS_POWER_REALLY_GO_TO_SLEEP:
1020 mPowerManager.goToSleep(eventTime,
1021 PowerManager.GO_TO_SLEEP_REASON_POWER_BUTTON,
1022 PowerManager.GO_TO_SLEEP_FLAG_NO_DOZE);
1023 break;
1024 case SHORT_PRESS_POWER_REALLY_GO_TO_SLEEP_AND_GO_HOME:
1025 mPowerManager.goToSleep(eventTime,
1026 PowerManager.GO_TO_SLEEP_REASON_POWER_BUTTON,
1027 PowerManager.GO_TO_SLEEP_FLAG_NO_DOZE);
1028 launchHomeFromHotKey();
1029 break;
Bryce Lee01b0c5f2015-02-05 18:24:04 -08001030 case SHORT_PRESS_POWER_GO_HOME:
Bryce Lee662ed802015-04-10 20:11:39 +00001031 launchHomeFromHotKey(true /* awakenFromDreams */, false /*respectKeyguard*/);
Bryce Lee01b0c5f2015-02-05 18:24:04 -08001032 break;
Jeff Brown13f00f02014-10-31 14:45:50 -07001033 }
1034 }
1035 }
1036
1037 private void powerMultiPressAction(long eventTime, boolean interactive, int behavior) {
1038 switch (behavior) {
1039 case MULTI_PRESS_POWER_NOTHING:
1040 break;
1041 case MULTI_PRESS_POWER_THEATER_MODE:
Bryce Lee3ae447e2015-06-30 12:31:41 -07001042 if (!isUserSetupComplete()) {
1043 Slog.i(TAG, "Ignoring toggling theater mode - device not setup.");
1044 break;
1045 }
1046
Jeff Brown13f00f02014-10-31 14:45:50 -07001047 if (isTheaterModeEnabled()) {
1048 Slog.i(TAG, "Toggling theater mode off.");
1049 Settings.Global.putInt(mContext.getContentResolver(),
1050 Settings.Global.THEATER_MODE_ON, 0);
1051 if (!interactive) {
1052 wakeUpFromPowerKey(eventTime);
1053 }
1054 } else {
1055 Slog.i(TAG, "Toggling theater mode on.");
1056 Settings.Global.putInt(mContext.getContentResolver(),
1057 Settings.Global.THEATER_MODE_ON, 1);
Bryce Lee55e846d2014-11-04 12:43:44 -08001058
1059 if (mGoToSleepOnButtonPressTheaterMode && interactive) {
Jeff Brown13f00f02014-10-31 14:45:50 -07001060 mPowerManager.goToSleep(eventTime,
1061 PowerManager.GO_TO_SLEEP_REASON_POWER_BUTTON, 0);
1062 }
1063 }
1064 break;
1065 case MULTI_PRESS_POWER_BRIGHTNESS_BOOST:
Jeff Brown7b5be5e2014-11-12 18:45:31 -08001066 Slog.i(TAG, "Starting brightness boost.");
1067 if (!interactive) {
1068 wakeUpFromPowerKey(eventTime);
1069 }
Jeff Brown13f00f02014-10-31 14:45:50 -07001070 mPowerManager.boostScreenBrightness(eventTime);
1071 break;
1072 }
1073 }
1074
1075 private int getMaxMultiPressPowerCount() {
1076 if (mTriplePressOnPowerBehavior != MULTI_PRESS_POWER_NOTHING) {
1077 return 3;
1078 }
1079 if (mDoublePressOnPowerBehavior != MULTI_PRESS_POWER_NOTHING) {
1080 return 2;
1081 }
1082 return 1;
1083 }
1084
1085 private void powerLongPress() {
1086 final int behavior = getResolvedLongPressOnPowerBehavior();
1087 switch (behavior) {
1088 case LONG_PRESS_POWER_NOTHING:
1089 break;
1090 case LONG_PRESS_POWER_GLOBAL_ACTIONS:
1091 mPowerKeyHandled = true;
1092 if (!performHapticFeedbackLw(null, HapticFeedbackConstants.LONG_PRESS, false)) {
1093 performAuditoryFeedbackForAccessibilityIfNeed();
1094 }
1095 showGlobalActionsInternal();
1096 break;
1097 case LONG_PRESS_POWER_SHUT_OFF:
1098 case LONG_PRESS_POWER_SHUT_OFF_NO_CONFIRM:
1099 mPowerKeyHandled = true;
1100 performHapticFeedbackLw(null, HapticFeedbackConstants.LONG_PRESS, false);
1101 sendCloseSystemWindows(SYSTEM_DIALOG_REASON_GLOBAL_ACTIONS);
1102 mWindowManagerFuncs.shutdown(behavior == LONG_PRESS_POWER_SHUT_OFF);
1103 break;
1104 }
1105 }
1106
Nick Vaccarob593a812015-05-15 11:23:05 -07001107 private void sleepPress(long eventTime) {
1108 if (mShortPressOnSleepBehavior == SHORT_PRESS_SLEEP_GO_TO_SLEEP_AND_GO_HOME) {
1109 launchHomeFromHotKey(false /* awakenDreams */, true /*respectKeyguard*/);
1110 }
1111 }
1112
1113 private void sleepRelease(long eventTime) {
Filip Gruszczynskia483a1d2015-03-17 19:06:58 +00001114 switch (mShortPressOnSleepBehavior) {
1115 case SHORT_PRESS_SLEEP_GO_TO_SLEEP:
Filip Gruszczynskia483a1d2015-03-17 19:06:58 +00001116 case SHORT_PRESS_SLEEP_GO_TO_SLEEP_AND_GO_HOME:
Nick Vaccarob593a812015-05-15 11:23:05 -07001117 Slog.i(TAG, "sleepRelease() calling goToSleep(GO_TO_SLEEP_REASON_SLEEP_BUTTON)");
1118 mPowerManager.goToSleep(eventTime,
1119 PowerManager.GO_TO_SLEEP_REASON_SLEEP_BUTTON, 0);
Filip Gruszczynskia483a1d2015-03-17 19:06:58 +00001120 break;
1121 }
1122 }
1123
Jeff Brown13f00f02014-10-31 14:45:50 -07001124 private int getResolvedLongPressOnPowerBehavior() {
1125 if (FactoryTest.isLongPressOnPowerOffEnabled()) {
1126 return LONG_PRESS_POWER_SHUT_OFF_NO_CONFIRM;
1127 }
1128 return mLongPressOnPowerBehavior;
1129 }
1130
1131 private boolean hasLongPressOnPowerBehavior() {
1132 return getResolvedLongPressOnPowerBehavior() != LONG_PRESS_POWER_NOTHING;
Jeff Brownd5bb82d2011-10-12 13:57:59 -07001133 }
1134
1135 private void interceptScreenshotChord() {
Christopher Tatee90585f2012-03-05 18:56:25 -08001136 if (mScreenshotChordEnabled
Jeff Brown13f00f02014-10-31 14:45:50 -07001137 && mScreenshotChordVolumeDownKeyTriggered && mScreenshotChordPowerKeyTriggered
1138 && !mScreenshotChordVolumeUpKeyTriggered) {
Jeff Brownd5bb82d2011-10-12 13:57:59 -07001139 final long now = SystemClock.uptimeMillis();
Jeff Brown13f00f02014-10-31 14:45:50 -07001140 if (now <= mScreenshotChordVolumeDownKeyTime + SCREENSHOT_CHORD_DEBOUNCE_DELAY_MILLIS
1141 && now <= mScreenshotChordPowerKeyTime
1142 + SCREENSHOT_CHORD_DEBOUNCE_DELAY_MILLIS) {
1143 mScreenshotChordVolumeDownKeyConsumed = true;
Jeff Brownd5bb82d2011-10-12 13:57:59 -07001144 cancelPendingPowerKeyAction();
1145
Jeff Sharkey2991fa32012-12-05 18:06:43 -08001146 mHandler.postDelayed(mScreenshotRunnable, getScreenshotChordLongPressDelay());
Jeff Brownd5bb82d2011-10-12 13:57:59 -07001147 }
1148 }
1149 }
1150
Winson Chung1cea2f32012-10-08 20:42:01 -07001151 private long getScreenshotChordLongPressDelay() {
Jim Miller5ecd8112013-01-09 18:50:26 -08001152 if (mKeyguardDelegate.isShowing()) {
Winson Chung1cea2f32012-10-08 20:42:01 -07001153 // Double the time it takes to take a screenshot from the keyguard
1154 return (long) (KEYGUARD_SCREENSHOT_CHORD_DELAY_MULTIPLIER *
Justin Kohfeabd2c2014-05-02 10:02:44 -07001155 ViewConfiguration.get(mContext).getDeviceGlobalActionKeyTimeout());
Winson Chung1cea2f32012-10-08 20:42:01 -07001156 }
Justin Kohfeabd2c2014-05-02 10:02:44 -07001157 return ViewConfiguration.get(mContext).getDeviceGlobalActionKeyTimeout();
Winson Chung1cea2f32012-10-08 20:42:01 -07001158 }
1159
Jeff Brownd5bb82d2011-10-12 13:57:59 -07001160 private void cancelPendingScreenshotChordAction() {
Jeff Sharkey2991fa32012-12-05 18:06:43 -08001161 mHandler.removeCallbacks(mScreenshotRunnable);
Jeff Brown4d396052010-10-29 21:50:21 -07001162 }
1163
Jeff Brown13f00f02014-10-31 14:45:50 -07001164 private final Runnable mEndCallLongPress = new Runnable() {
Craig Mautnerf1b67412012-09-19 13:18:29 -07001165 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001166 public void run() {
Jeff Brown13f00f02014-10-31 14:45:50 -07001167 mEndCallKeyHandled = true;
1168 if (!performHapticFeedbackLw(null, HapticFeedbackConstants.LONG_PRESS, false)) {
1169 performAuditoryFeedbackForAccessibilityIfNeed();
Joe Onoratod208e702010-10-08 16:22:43 -04001170 }
Jeff Brown13f00f02014-10-31 14:45:50 -07001171 showGlobalActionsInternal();
Jeff Brownd5bb82d2011-10-12 13:57:59 -07001172 }
1173 };
1174
Jeff Sharkey2991fa32012-12-05 18:06:43 -08001175 private final Runnable mScreenshotRunnable = new Runnable() {
Craig Mautner0bf6ec92012-12-18 08:33:27 -08001176 @Override
Jeff Brownd5bb82d2011-10-12 13:57:59 -07001177 public void run() {
1178 takeScreenshot();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001179 }
1180 };
1181
Alan Viverettee34560b22014-07-10 14:50:06 -07001182 @Override
1183 public void showGlobalActions() {
1184 mHandler.removeMessages(MSG_DISPATCH_SHOW_GLOBAL_ACTIONS);
1185 mHandler.sendEmptyMessage(MSG_DISPATCH_SHOW_GLOBAL_ACTIONS);
1186 }
1187
1188 void showGlobalActionsInternal() {
1189 sendCloseSystemWindows(SYSTEM_DIALOG_REASON_GLOBAL_ACTIONS);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001190 if (mGlobalActions == null) {
Jeff Brown7304c342012-05-11 18:42:42 -07001191 mGlobalActions = new GlobalActions(mContext, mWindowManagerFuncs);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001192 }
Jim Millerab954542014-10-10 18:21:49 -07001193 final boolean keyguardShowing = isKeyguardShowingAndNotOccluded();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001194 mGlobalActions.showDialog(keyguardShowing, isDeviceProvisioned());
1195 if (keyguardShowing) {
1196 // since it took two seconds of long press to bring this up,
1197 // poke the wake lock so they have some time to see the dialog.
Jim Miller25190572013-02-28 17:36:24 -08001198 mPowerManager.userActivity(SystemClock.uptimeMillis(), false);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001199 }
1200 }
1201
1202 boolean isDeviceProvisioned() {
Jeff Brownbf6f6f92012-09-25 15:03:20 -07001203 return Settings.Global.getInt(
1204 mContext.getContentResolver(), Settings.Global.DEVICE_PROVISIONED, 0) != 0;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001205 }
1206
Maurice Lam99c6e072014-04-28 18:24:28 -07001207 boolean isUserSetupComplete() {
1208 return Settings.Secure.getIntForUser(mContext.getContentResolver(),
1209 Settings.Secure.USER_SETUP_COMPLETE, 0, UserHandle.USER_CURRENT) != 0;
1210 }
1211
Jeff Brown13f00f02014-10-31 14:45:50 -07001212 private void handleShortPressOnHome() {
1213 // If there's a dream running then use home to escape the dream
1214 // but don't actually go home.
1215 if (mDreamManagerInternal != null && mDreamManagerInternal.isDreaming()) {
1216 mDreamManagerInternal.stopDream(false /*immediate*/);
1217 return;
1218 }
1219
1220 // Go home!
1221 launchHomeFromHotKey();
1222 }
1223
Tim Kilbourn0e5f1102015-06-05 16:18:09 -07001224 private void handleLongPressOnHome(int deviceId) {
Joe Onorato46b0d682010-11-22 17:37:27 -08001225 if (mLongPressOnHomeBehavior != LONG_PRESS_HOME_NOTHING) {
Jeff Browncaca8812013-05-09 13:34:33 -07001226 mHomeConsumed = true;
Joe Onorato46b0d682010-11-22 17:37:27 -08001227 performHapticFeedbackLw(null, HapticFeedbackConstants.LONG_PRESS, false);
Patrick Dubroyece94522011-02-23 18:35:01 -08001228
Jeff Browncaca8812013-05-09 13:34:33 -07001229 if (mLongPressOnHomeBehavior == LONG_PRESS_HOME_RECENT_SYSTEM_UI) {
1230 toggleRecentApps();
1231 } else if (mLongPressOnHomeBehavior == LONG_PRESS_HOME_ASSIST) {
Tim Kilbourn0e5f1102015-06-05 16:18:09 -07001232 launchAssistAction(null, deviceId);
Jim Millere6ad1a82010-08-20 19:25:39 -07001233 }
1234 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001235 }
Patrick Dubroyece94522011-02-23 18:35:01 -08001236
Jeff Browncaca8812013-05-09 13:34:33 -07001237 private void handleDoubleTapOnHome() {
1238 if (mDoubleTapOnHomeBehavior == DOUBLE_TAP_HOME_RECENT_SYSTEM_UI) {
1239 mHomeConsumed = true;
1240 toggleRecentApps();
1241 }
1242 }
1243
1244 private final Runnable mHomeDoubleTapTimeoutRunnable = new Runnable() {
1245 @Override
1246 public void run() {
1247 if (mHomeDoubleTapPending) {
1248 mHomeDoubleTapPending = false;
Jeff Brown13f00f02014-10-31 14:45:50 -07001249 handleShortPressOnHome();
Jeff Browncaca8812013-05-09 13:34:33 -07001250 }
1251 }
1252 };
1253
Mark Renoufc1256912015-03-11 14:38:23 -04001254 private boolean isRoundWindow() {
Adam Powell01f280d2015-05-18 16:07:42 -07001255 return mContext.getResources().getConfiguration().isScreenRound();
Mark Renoufc1256912015-03-11 14:38:23 -04001256 }
1257
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001258 /** {@inheritDoc} */
Craig Mautner0bf6ec92012-12-18 08:33:27 -08001259 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001260 public void init(Context context, IWindowManager windowManager,
Jeff Brown96307042012-07-27 15:51:34 -07001261 WindowManagerFuncs windowManagerFuncs) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001262 mContext = context;
1263 mWindowManager = windowManager;
Dianne Hackborndf89e652011-10-06 22:35:11 -07001264 mWindowManagerFuncs = windowManagerFuncs;
Craig Mautner8a0da012014-05-31 15:13:37 -07001265 mWindowManagerInternal = LocalServices.getService(WindowManagerInternal.class);
Jeff Brown061ea992015-04-17 19:55:47 -07001266 mActivityManagerInternal = LocalServices.getService(ActivityManagerInternal.class);
Jose Lima9546b202014-07-02 17:21:51 -07001267 mDreamManagerInternal = LocalServices.getService(DreamManagerInternal.class);
Billy Laucbe540f2015-06-25 01:51:44 +01001268 mAppOpsManager = (AppOpsManager) mContext.getSystemService(Context.APP_OPS_SERVICE);
Mark Renoufc1256912015-03-11 14:38:23 -04001269
1270 // Init display burn-in protection
1271 boolean burnInProtectionEnabled = context.getResources().getBoolean(
1272 com.android.internal.R.bool.config_enableBurnInProtection);
1273 // Allow a system property to override this. Used by developer settings.
1274 boolean burnInProtectionDevMode =
1275 SystemProperties.getBoolean("persist.debug.force_burn_in", false);
1276 if (burnInProtectionEnabled || burnInProtectionDevMode) {
1277 final int minHorizontal;
1278 final int maxHorizontal;
1279 final int minVertical;
1280 final int maxVertical;
1281 final int maxRadius;
1282 if (burnInProtectionDevMode) {
1283 minHorizontal = -8;
1284 maxHorizontal = 8;
1285 minVertical = -8;
1286 maxVertical = -4;
1287 maxRadius = (isRoundWindow()) ? 6 : -1;
1288 } else {
1289 Resources resources = context.getResources();
1290 minHorizontal = resources.getInteger(
1291 com.android.internal.R.integer.config_burnInProtectionMinHorizontalOffset);
1292 maxHorizontal = resources.getInteger(
1293 com.android.internal.R.integer.config_burnInProtectionMaxHorizontalOffset);
1294 minVertical = resources.getInteger(
1295 com.android.internal.R.integer.config_burnInProtectionMinVerticalOffset);
1296 maxVertical = resources.getInteger(
1297 com.android.internal.R.integer.config_burnInProtectionMaxVerticalOffset);
1298 maxRadius = resources.getInteger(
1299 com.android.internal.R.integer.config_burnInProtectionMaxRadius);
1300 }
1301 mBurnInProtectionHelper = new BurnInProtectionHelper(
1302 context, minHorizontal, maxHorizontal, minVertical, maxVertical, maxRadius);
Filip Gruszczynskicfb31852015-02-25 21:47:12 +00001303 }
Craig Mautner8a0da012014-05-31 15:13:37 -07001304
Jeff Brown70825162012-03-28 17:27:48 -07001305 mHandler = new PolicyHandler();
Jeff Browna20dda42014-05-27 20:57:24 -07001306 mWakeGestureListener = new MyWakeGestureListener(mContext, mHandler);
Craig Mautnereee29c42013-01-17 14:44:34 -08001307 mOrientationListener = new MyOrientationListener(mContext, mHandler);
Jeff Brownc0347aa2011-09-23 17:26:09 -07001308 try {
1309 mOrientationListener.setCurrentRotation(windowManager.getRotation());
1310 } catch (RemoteException ex) { }
Christopher Tate5e08af02012-09-21 17:17:22 -07001311 mSettingsObserver = new SettingsObserver(mHandler);
1312 mSettingsObserver.observe();
Svetoslav683914b2015-01-15 14:22:26 -08001313 mShortcutManager = new ShortcutManager(context);
Daniel Sandler6396c722013-04-16 20:19:09 -04001314 mUiMode = context.getResources().getInteger(
1315 com.android.internal.R.integer.config_defaultUiModeType);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001316 mHomeIntent = new Intent(Intent.ACTION_MAIN, null);
1317 mHomeIntent.addCategory(Intent.CATEGORY_HOME);
1318 mHomeIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK
1319 | Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED);
Dianne Hackborn39c2d712009-09-22 11:41:31 -07001320 mCarDockIntent = new Intent(Intent.ACTION_MAIN, null);
1321 mCarDockIntent.addCategory(Intent.CATEGORY_CAR_DOCK);
1322 mCarDockIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK
1323 | Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED);
1324 mDeskDockIntent = new Intent(Intent.ACTION_MAIN, null);
1325 mDeskDockIntent.addCategory(Intent.CATEGORY_DESK_DOCK);
1326 mDeskDockIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK
1327 | Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED);
Jim Millere6ad1a82010-08-20 19:25:39 -07001328
Jeff Brown96307042012-07-27 15:51:34 -07001329 mPowerManager = (PowerManager)context.getSystemService(Context.POWER_SERVICE);
1330 mBroadcastWakeLock = mPowerManager.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK,
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001331 "PhoneWindowManager.mBroadcastWakeLock");
Jeff Brown13f00f02014-10-31 14:45:50 -07001332 mPowerKeyWakeLock = mPowerManager.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK,
1333 "PhoneWindowManager.mPowerKeyWakeLock");
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001334 mEnableShiftMenuBugReports = "1".equals(SystemProperties.get("ro.debuggable"));
Jeff Brownbcdfc622014-03-06 19:13:04 -08001335 mSupportAutoRotation = mContext.getResources().getBoolean(
1336 com.android.internal.R.bool.config_supportAutoRotation);
Dianne Hackborn2862fff2009-09-15 22:56:29 -07001337 mLidOpenRotation = readRotation(
Mike Lockwood2d1efbd2009-09-16 12:15:53 -04001338 com.android.internal.R.integer.config_lidOpenRotation);
1339 mCarDockRotation = readRotation(
1340 com.android.internal.R.integer.config_carDockRotation);
1341 mDeskDockRotation = readRotation(
1342 com.android.internal.R.integer.config_deskDockRotation);
Jeff Brownc82c89ed2013-04-17 17:18:15 -07001343 mUndockedHdmiRotation = readRotation(
1344 com.android.internal.R.integer.config_undockedHdmiRotation);
Mike Lockwoode9867d22009-09-20 01:59:02 -04001345 mCarDockEnablesAccelerometer = mContext.getResources().getBoolean(
1346 com.android.internal.R.bool.config_carDockEnablesAccelerometer);
1347 mDeskDockEnablesAccelerometer = mContext.getResources().getBoolean(
1348 com.android.internal.R.bool.config_deskDockEnablesAccelerometer);
Dianne Hackborn2862fff2009-09-15 22:56:29 -07001349 mLidKeyboardAccessibility = mContext.getResources().getInteger(
1350 com.android.internal.R.integer.config_lidKeyboardAccessibility);
1351 mLidNavigationAccessibility = mContext.getResources().getInteger(
1352 com.android.internal.R.integer.config_lidNavigationAccessibility);
Jeff Brownc458ce92012-04-30 14:58:40 -07001353 mLidControlsSleep = mContext.getResources().getBoolean(
1354 com.android.internal.R.bool.config_lidControlsSleep);
Daniel Sandlerdd73ee42013-10-11 22:19:59 -04001355 mTranslucentDecorEnabled = mContext.getResources().getBoolean(
1356 com.android.internal.R.bool.config_enableTranslucentDecor);
Bryce Lee584a4452014-10-21 15:55:55 -07001357
1358 mAllowTheaterModeWakeFromKey = mContext.getResources().getBoolean(
1359 com.android.internal.R.bool.config_allowTheaterModeWakeFromKey);
1360 mAllowTheaterModeWakeFromPowerKey = mAllowTheaterModeWakeFromKey
1361 || mContext.getResources().getBoolean(
1362 com.android.internal.R.bool.config_allowTheaterModeWakeFromPowerKey);
1363 mAllowTheaterModeWakeFromMotion = mContext.getResources().getBoolean(
1364 com.android.internal.R.bool.config_allowTheaterModeWakeFromMotion);
Bryce Lee812d7022014-11-10 13:33:28 -08001365 mAllowTheaterModeWakeFromMotionWhenNotDreaming = mContext.getResources().getBoolean(
1366 com.android.internal.R.bool.config_allowTheaterModeWakeFromMotionWhenNotDreaming);
Bryce Lee584a4452014-10-21 15:55:55 -07001367 mAllowTheaterModeWakeFromCameraLens = mContext.getResources().getBoolean(
1368 com.android.internal.R.bool.config_allowTheaterModeWakeFromCameraLens);
1369 mAllowTheaterModeWakeFromLidSwitch = mContext.getResources().getBoolean(
1370 com.android.internal.R.bool.config_allowTheaterModeWakeFromLidSwitch);
1371 mAllowTheaterModeWakeFromWakeGesture = mContext.getResources().getBoolean(
1372 com.android.internal.R.bool.config_allowTheaterModeWakeFromGesture);
1373
Bryce Lee55e846d2014-11-04 12:43:44 -08001374 mGoToSleepOnButtonPressTheaterMode = mContext.getResources().getBoolean(
1375 com.android.internal.R.bool.config_goToSleepOnButtonPressTheaterMode);
1376
Bryce Leed3b28402015-03-09 15:49:13 +00001377 mSupportLongPressPowerWhenNonInteractive = mContext.getResources().getBoolean(
1378 com.android.internal.R.bool.config_supportLongPressPowerWhenNonInteractive);
1379
Jeff Brown13f00f02014-10-31 14:45:50 -07001380 mShortPressOnPowerBehavior = mContext.getResources().getInteger(
1381 com.android.internal.R.integer.config_shortPressOnPowerBehavior);
1382 mLongPressOnPowerBehavior = mContext.getResources().getInteger(
1383 com.android.internal.R.integer.config_longPressOnPowerBehavior);
1384 mDoublePressOnPowerBehavior = mContext.getResources().getInteger(
1385 com.android.internal.R.integer.config_doublePressOnPowerBehavior);
1386 mTriplePressOnPowerBehavior = mContext.getResources().getInteger(
1387 com.android.internal.R.integer.config_triplePressOnPowerBehavior);
Filip Gruszczynskia483a1d2015-03-17 19:06:58 +00001388 mShortPressOnSleepBehavior = mContext.getResources().getInteger(
1389 com.android.internal.R.integer.config_shortPressOnSleepBehavior);
Jeff Brown13f00f02014-10-31 14:45:50 -07001390
John Spurlock61560172015-02-06 19:46:04 -05001391 mUseTvRouting = AudioSystem.getPlatformType(mContext) == AudioSystem.PLATFORM_TELEVISION;
RoboErik001c59c2015-01-26 15:53:51 -08001392
Jeff Brownf71343d2013-05-31 17:59:11 -07001393 readConfigurationDependentBehaviors();
Jeff Browncaca8812013-05-09 13:34:33 -07001394
Svetoslav8e3feb12014-02-24 13:46:47 -08001395 mAccessibilityManager = (AccessibilityManager) context.getSystemService(
1396 Context.ACCESSIBILITY_SERVICE);
1397
Mike Lockwood1753f7f2009-08-24 14:49:07 -07001398 // register for dock events
Dianne Hackborn78968392010-03-04 20:47:56 -08001399 IntentFilter filter = new IntentFilter();
1400 filter.addAction(UiModeManager.ACTION_ENTER_CAR_MODE);
1401 filter.addAction(UiModeManager.ACTION_EXIT_CAR_MODE);
1402 filter.addAction(UiModeManager.ACTION_ENTER_DESK_MODE);
1403 filter.addAction(UiModeManager.ACTION_EXIT_DESK_MODE);
Dianne Hackborn867ab6472010-04-29 13:28:56 -07001404 filter.addAction(Intent.ACTION_DOCK_EVENT);
1405 Intent intent = context.registerReceiver(mDockReceiver, filter);
1406 if (intent != null) {
1407 // Retrieve current sticky dock event broadcast.
1408 mDockMode = intent.getIntExtra(Intent.EXTRA_DOCK_STATE,
1409 Intent.EXTRA_DOCK_STATE_UNDOCKED);
1410 }
Daniel Sandler7e37df52011-11-16 22:08:23 -08001411
Jeff Brown6aaf2952012-10-05 16:01:08 -07001412 // register for dream-related broadcasts
1413 filter = new IntentFilter();
1414 filter.addAction(Intent.ACTION_DREAMING_STARTED);
1415 filter.addAction(Intent.ACTION_DREAMING_STOPPED);
1416 context.registerReceiver(mDreamReceiver, filter);
1417
Christopher Tate5e08af02012-09-21 17:17:22 -07001418 // register for multiuser-relevant broadcasts
1419 filter = new IntentFilter(Intent.ACTION_USER_SWITCHED);
1420 context.registerReceiver(mMultiuserReceiver, filter);
1421
John Spurlock57306e62013-04-22 09:48:49 -04001422 // monitor for system gestures
Craig Mautner037aa8d2013-06-07 10:35:44 -07001423 mSystemGestures = new SystemGesturesPointerEventListener(context,
1424 new SystemGesturesPointerEventListener.Callbacks() {
John Spurlock57306e62013-04-22 09:48:49 -04001425 @Override
1426 public void onSwipeFromTop() {
John Spurlock04db1762013-05-13 12:46:41 -04001427 if (mStatusBar != null) {
John Spurlocke1f366f2013-08-05 12:22:40 -04001428 requestTransientBars(mStatusBar);
John Spurlock04db1762013-05-13 12:46:41 -04001429 }
John Spurlockad3e6cb2013-04-30 08:47:43 -04001430 }
1431 @Override
1432 public void onSwipeFromBottom() {
John Spurlock04db1762013-05-13 12:46:41 -04001433 if (mNavigationBar != null && mNavigationBarOnBottom) {
John Spurlocke1f366f2013-08-05 12:22:40 -04001434 requestTransientBars(mNavigationBar);
John Spurlockad3e6cb2013-04-30 08:47:43 -04001435 }
1436 }
1437 @Override
1438 public void onSwipeFromRight() {
John Spurlock04db1762013-05-13 12:46:41 -04001439 if (mNavigationBar != null && !mNavigationBarOnBottom) {
John Spurlocke1f366f2013-08-05 12:22:40 -04001440 requestTransientBars(mNavigationBar);
John Spurlockad3e6cb2013-04-30 08:47:43 -04001441 }
1442 }
1443 @Override
1444 public void onDebug() {
John Spurlockd67ec252013-09-05 11:31:54 -04001445 // no-op
John Spurlockad3e6cb2013-04-30 08:47:43 -04001446 }
Adrian Roos3595be42015-03-05 16:31:15 +01001447 @Override
1448 public void onDown() {
1449 mOrientationListener.onTouchStart();
1450 }
1451 @Override
1452 public void onUpOrCancel() {
1453 mOrientationListener.onTouchEnd();
1454 }
John Spurlockad3e6cb2013-04-30 08:47:43 -04001455 });
John Spurlockf1a36642013-10-12 17:50:42 -04001456 mImmersiveModeConfirmation = new ImmersiveModeConfirmation(mContext);
Craig Mautner037aa8d2013-06-07 10:35:44 -07001457 mWindowManagerFuncs.registerPointerEventListener(mSystemGestures);
John Spurlock32beb2c2013-03-11 10:16:47 -04001458
Jeff Brownc2346132012-04-13 01:55:38 -07001459 mVibrator = (Vibrator)context.getSystemService(Context.VIBRATOR_SERVICE);
Dianne Hackbornb1a79802009-09-29 15:18:31 -07001460 mLongPressVibePattern = getLongIntArray(mContext.getResources(),
1461 com.android.internal.R.array.config_longPressVibePattern);
1462 mVirtualKeyVibePattern = getLongIntArray(mContext.getResources(),
1463 com.android.internal.R.array.config_virtualKeyVibePattern);
Amith Yamasanic33cb712010-02-10 15:21:49 -08001464 mKeyboardTapVibePattern = getLongIntArray(mContext.getResources(),
1465 com.android.internal.R.array.config_keyboardTapVibePattern);
Fabrice Di Meglioeeff63a2013-08-05 12:07:24 -07001466 mClockTickVibePattern = getLongIntArray(mContext.getResources(),
1467 com.android.internal.R.array.config_clockTickVibePattern);
Fabrice Di Megliobd9152f2013-10-01 11:21:31 -07001468 mCalendarDateVibePattern = getLongIntArray(mContext.getResources(),
1469 com.android.internal.R.array.config_calendarDateVibePattern);
Dianne Hackbornb1a79802009-09-29 15:18:31 -07001470 mSafeModeDisabledVibePattern = getLongIntArray(mContext.getResources(),
1471 com.android.internal.R.array.config_safeModeDisabledVibePattern);
1472 mSafeModeEnabledVibePattern = getLongIntArray(mContext.getResources(),
1473 com.android.internal.R.array.config_safeModeEnabledVibePattern);
Mady Mellore8608912015-06-05 09:02:55 -07001474 mContextClickVibePattern = getLongIntArray(mContext.getResources(),
1475 com.android.internal.R.array.config_contextClickVibePattern);
Daniel Sandler40427442010-07-16 11:44:52 -04001476
Christopher Tatee90585f2012-03-05 18:56:25 -08001477 mScreenshotChordEnabled = mContext.getResources().getBoolean(
1478 com.android.internal.R.bool.config_enableScreenshotChord);
1479
Justin Kohd378ad72013-04-01 12:18:26 -07001480 mGlobalKeyManager = new GlobalKeyManager(mContext);
1481
Joe Onoratoea495d42011-04-06 11:41:11 -07001482 // Controls rotation and the like.
1483 initializeHdmiState();
Dianne Hackborn40011092011-09-22 13:37:48 -07001484
1485 // Match current screen state.
Craig Mautnera631d492014-08-05 15:16:01 -07001486 if (!mPowerManager.isInteractive()) {
Jeff Brown416c49c2015-05-26 19:50:18 -07001487 startedGoingToSleep(WindowManagerPolicy.OFF_BECAUSE_OF_USER);
1488 finishedGoingToSleep(WindowManagerPolicy.OFF_BECAUSE_OF_USER);
Dianne Hackborn40011092011-09-22 13:37:48 -07001489 }
Jorim Jaggi24bec7c2015-02-04 12:40:14 +01001490
1491 mWindowManagerInternal.registerAppTransitionListener(
1492 mStatusBarController.getAppTransitionListener());
Mike Lockwood1753f7f2009-08-24 14:49:07 -07001493 }
1494
Jeff Brownf71343d2013-05-31 17:59:11 -07001495 /**
1496 * Read values from config.xml that may be overridden depending on
1497 * the configuration of the device.
1498 * eg. Disable long press on home goes to recents on sw600dp.
1499 */
1500 private void readConfigurationDependentBehaviors() {
1501 mLongPressOnHomeBehavior = mContext.getResources().getInteger(
1502 com.android.internal.R.integer.config_longPressOnHomeBehavior);
1503 if (mLongPressOnHomeBehavior < LONG_PRESS_HOME_NOTHING ||
1504 mLongPressOnHomeBehavior > LONG_PRESS_HOME_ASSIST) {
1505 mLongPressOnHomeBehavior = LONG_PRESS_HOME_NOTHING;
1506 }
1507
1508 mDoubleTapOnHomeBehavior = mContext.getResources().getInteger(
1509 com.android.internal.R.integer.config_doubleTapOnHomeBehavior);
1510 if (mDoubleTapOnHomeBehavior < DOUBLE_TAP_HOME_NOTHING ||
1511 mDoubleTapOnHomeBehavior > DOUBLE_TAP_HOME_RECENT_SYSTEM_UI) {
1512 mDoubleTapOnHomeBehavior = LONG_PRESS_HOME_NOTHING;
1513 }
1514 }
1515
Craig Mautner0bf6ec92012-12-18 08:33:27 -08001516 @Override
Dianne Hackborndde331c2012-08-03 14:01:57 -07001517 public void setInitialDisplaySize(Display display, int width, int height, int density) {
Jeff Brownef981a42013-08-07 14:13:37 -07001518 // This method might be called before the policy has been fully initialized
1519 // or for other displays we don't care about.
1520 if (mContext == null || display.getDisplayId() != Display.DEFAULT_DISPLAY) {
1521 return;
Dianne Hackbornc652de82013-02-15 16:32:56 -08001522 }
Dianne Hackbornf87d1962012-04-04 12:48:24 -07001523 mDisplay = display;
1524
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001525 final Resources res = mContext.getResources();
Dianne Hackbornf87d1962012-04-04 12:48:24 -07001526 int shortSize, longSize;
Dianne Hackborn9d132642011-04-21 17:26:39 -07001527 if (width > height) {
Dianne Hackborn81e56d52011-05-26 00:55:58 -07001528 shortSize = height;
Dianne Hackbornf87d1962012-04-04 12:48:24 -07001529 longSize = width;
Dianne Hackborn9d132642011-04-21 17:26:39 -07001530 mLandscapeRotation = Surface.ROTATION_0;
1531 mSeascapeRotation = Surface.ROTATION_180;
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001532 if (res.getBoolean(com.android.internal.R.bool.config_reverseDefaultRotation)) {
Dianne Hackborn9d132642011-04-21 17:26:39 -07001533 mPortraitRotation = Surface.ROTATION_90;
1534 mUpsideDownRotation = Surface.ROTATION_270;
1535 } else {
1536 mPortraitRotation = Surface.ROTATION_270;
1537 mUpsideDownRotation = Surface.ROTATION_90;
1538 }
1539 } else {
Dianne Hackborn81e56d52011-05-26 00:55:58 -07001540 shortSize = width;
Dianne Hackbornf87d1962012-04-04 12:48:24 -07001541 longSize = height;
Dianne Hackborn9d132642011-04-21 17:26:39 -07001542 mPortraitRotation = Surface.ROTATION_0;
1543 mUpsideDownRotation = Surface.ROTATION_180;
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001544 if (res.getBoolean(com.android.internal.R.bool.config_reverseDefaultRotation)) {
Dianne Hackborn9d132642011-04-21 17:26:39 -07001545 mLandscapeRotation = Surface.ROTATION_270;
1546 mSeascapeRotation = Surface.ROTATION_90;
1547 } else {
1548 mLandscapeRotation = Surface.ROTATION_90;
1549 mSeascapeRotation = Surface.ROTATION_270;
1550 }
1551 }
Dianne Hackborn81e56d52011-05-26 00:55:58 -07001552
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001553 mStatusBarHeight =
1554 res.getDimensionPixelSize(com.android.internal.R.dimen.status_bar_height);
Dianne Hackbornf87d1962012-04-04 12:48:24 -07001555
Daniel Sandler9f65c4c2012-04-26 01:35:35 -04001556 // Height of the navigation bar when presented horizontally at bottom
1557 mNavigationBarHeightForRotation[mPortraitRotation] =
1558 mNavigationBarHeightForRotation[mUpsideDownRotation] =
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001559 res.getDimensionPixelSize(com.android.internal.R.dimen.navigation_bar_height);
Daniel Sandler9f65c4c2012-04-26 01:35:35 -04001560 mNavigationBarHeightForRotation[mLandscapeRotation] =
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001561 mNavigationBarHeightForRotation[mSeascapeRotation] = res.getDimensionPixelSize(
1562 com.android.internal.R.dimen.navigation_bar_height_landscape);
Daniel Sandler9f65c4c2012-04-26 01:35:35 -04001563
1564 // Width of the navigation bar when presented vertically along one side
1565 mNavigationBarWidthForRotation[mPortraitRotation] =
1566 mNavigationBarWidthForRotation[mUpsideDownRotation] =
1567 mNavigationBarWidthForRotation[mLandscapeRotation] =
1568 mNavigationBarWidthForRotation[mSeascapeRotation] =
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001569 res.getDimensionPixelSize(com.android.internal.R.dimen.navigation_bar_width);
Daniel Sandler4a066c52012-04-20 14:49:13 -04001570
1571 // SystemUI (status bar) layout policy
Dianne Hackborndde331c2012-08-03 14:01:57 -07001572 int shortSizeDp = shortSize * DisplayMetrics.DENSITY_DEFAULT / density;
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001573 int longSizeDp = longSize * DisplayMetrics.DENSITY_DEFAULT / density;
Daniel Sandler4a066c52012-04-20 14:49:13 -04001574
Devin Kimd7b12b42014-05-05 14:34:58 -07001575 // Allow the navigation bar to move on non-square small devices (phones).
1576 mNavigationBarCanMove = width != height && shortSizeDp < 600;
Daniel Sandler36412a72011-08-04 09:35:13 -04001577
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001578 mHasNavigationBar = res.getBoolean(com.android.internal.R.bool.config_showNavigationBar);
John Spurlock80f00c12013-06-13 11:10:51 -04001579 // Allow a system property to override this. Used by the emulator.
1580 // See also hasNavigationBar().
1581 String navBarOverride = SystemProperties.get("qemu.hw.mainkeys");
1582 if ("1".equals(navBarOverride)) {
Dianne Hackbornf87d1962012-04-04 12:48:24 -07001583 mHasNavigationBar = false;
John Spurlock80f00c12013-06-13 11:10:51 -04001584 } else if ("0".equals(navBarOverride)) {
1585 mHasNavigationBar = true;
Daniel Sandler0c4ccff2011-10-19 16:39:14 -04001586 }
1587
Jeff Brown27f1d672012-10-17 18:32:34 -07001588 // For demo purposes, allow the rotation of the HDMI display to be controlled.
1589 // By default, HDMI locks rotation to landscape.
Erik Gilling9a41ef82011-09-26 19:21:03 -07001590 if ("portrait".equals(SystemProperties.get("persist.demo.hdmirotation"))) {
Jeff Brownc82c89ed2013-04-17 17:18:15 -07001591 mDemoHdmiRotation = mPortraitRotation;
Erik Gilling9a41ef82011-09-26 19:21:03 -07001592 } else {
Jeff Brownc82c89ed2013-04-17 17:18:15 -07001593 mDemoHdmiRotation = mLandscapeRotation;
Erik Gilling9a41ef82011-09-26 19:21:03 -07001594 }
Jeff Brownc82c89ed2013-04-17 17:18:15 -07001595 mDemoHdmiRotationLock = SystemProperties.getBoolean("persist.demo.hdmirotationlock", false);
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001596
Chong Zhangae6119ff2014-11-11 18:54:39 -08001597 // For demo purposes, allow the rotation of the remote display to be controlled.
1598 // By default, remote display locks rotation to landscape.
1599 if ("portrait".equals(SystemProperties.get("persist.demo.remoterotation"))) {
1600 mDemoRotation = mPortraitRotation;
1601 } else {
1602 mDemoRotation = mLandscapeRotation;
1603 }
1604 mDemoRotationLock = SystemProperties.getBoolean(
1605 "persist.demo.rotationlock", false);
1606
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001607 // Only force the default orientation if the screen is xlarge, at least 960dp x 720dp, per
1608 // http://developer.android.com/guide/practices/screens_support.html#range
1609 mForceDefaultOrientation = longSizeDp >= 960 && shortSizeDp >= 720 &&
1610 res.getBoolean(com.android.internal.R.bool.config_forceDefaultOrientation) &&
1611 // For debug purposes the next line turns this feature off with:
1612 // $ adb shell setprop config.override_forced_orient true
1613 // $ adb shell wm size reset
1614 !"true".equals(SystemProperties.get("config.override_forced_orient"));
1615 }
1616
Alan Viverette5a0f4ec2013-10-07 15:10:29 -07001617 /**
1618 * @return whether the navigation bar can be hidden, e.g. the device has a
1619 * navigation bar and touch exploration is not enabled
1620 */
1621 private boolean canHideNavigationBar() {
Svetoslav8e3feb12014-02-24 13:46:47 -08001622 return mHasNavigationBar
1623 && !mAccessibilityManager.isTouchExplorationEnabled();
Alan Viverette5a0f4ec2013-10-07 15:10:29 -07001624 }
1625
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001626 @Override
1627 public boolean isDefaultOrientationForced() {
1628 return mForceDefaultOrientation;
Dianne Hackborn9d132642011-04-21 17:26:39 -07001629 }
1630
Dianne Hackbornc652de82013-02-15 16:32:56 -08001631 @Override
1632 public void setDisplayOverscan(Display display, int left, int top, int right, int bottom) {
1633 if (display.getDisplayId() == Display.DEFAULT_DISPLAY) {
1634 mOverscanLeft = left;
1635 mOverscanTop = top;
1636 mOverscanRight = right;
1637 mOverscanBottom = bottom;
1638 }
1639 }
1640
Dianne Hackbornc777e072010-02-12 13:07:59 -08001641 public void updateSettings() {
1642 ContentResolver resolver = mContext.getContentResolver();
1643 boolean updateRotation = false;
Dianne Hackbornc777e072010-02-12 13:07:59 -08001644 synchronized (mLock) {
Christopher Tate5e08af02012-09-21 17:17:22 -07001645 mEndcallBehavior = Settings.System.getIntForUser(resolver,
David Brownbaf8d092010-03-08 21:52:59 -08001646 Settings.System.END_BUTTON_BEHAVIOR,
Christopher Tate5e08af02012-09-21 17:17:22 -07001647 Settings.System.END_BUTTON_BEHAVIOR_DEFAULT,
1648 UserHandle.USER_CURRENT);
1649 mIncallPowerBehavior = Settings.Secure.getIntForUser(resolver,
David Brownbaf8d092010-03-08 21:52:59 -08001650 Settings.Secure.INCALL_POWER_BUTTON_BEHAVIOR,
Christopher Tate5e08af02012-09-21 17:17:22 -07001651 Settings.Secure.INCALL_POWER_BUTTON_BEHAVIOR_DEFAULT,
1652 UserHandle.USER_CURRENT);
Daniel Sandlerb73617d2010-08-17 00:41:00 -04001653
Jeff Browna20dda42014-05-27 20:57:24 -07001654 // Configure wake gesture.
1655 boolean wakeGestureEnabledSetting = Settings.Secure.getIntForUser(resolver,
1656 Settings.Secure.WAKE_GESTURE_ENABLED, 0,
1657 UserHandle.USER_CURRENT) != 0;
1658 if (mWakeGestureEnabledSetting != wakeGestureEnabledSetting) {
1659 mWakeGestureEnabledSetting = wakeGestureEnabledSetting;
1660 updateWakeGestureListenerLp();
1661 }
1662
Jeff Brown207673cd2012-06-05 17:47:11 -07001663 // Configure rotation lock.
Christopher Tate5e08af02012-09-21 17:17:22 -07001664 int userRotation = Settings.System.getIntForUser(resolver,
1665 Settings.System.USER_ROTATION, Surface.ROTATION_0,
1666 UserHandle.USER_CURRENT);
Jeff Brown207673cd2012-06-05 17:47:11 -07001667 if (mUserRotation != userRotation) {
1668 mUserRotation = userRotation;
1669 updateRotation = true;
1670 }
Christopher Tate5e08af02012-09-21 17:17:22 -07001671 int userRotationMode = Settings.System.getIntForUser(resolver,
1672 Settings.System.ACCELEROMETER_ROTATION, 0, UserHandle.USER_CURRENT) != 0 ?
Jeff Brown207673cd2012-06-05 17:47:11 -07001673 WindowManagerPolicy.USER_ROTATION_FREE :
1674 WindowManagerPolicy.USER_ROTATION_LOCKED;
1675 if (mUserRotationMode != userRotationMode) {
1676 mUserRotationMode = userRotationMode;
1677 updateRotation = true;
Dianne Hackbornc777e072010-02-12 13:07:59 -08001678 updateOrientationListenerLp();
1679 }
Daniel Sandlerb73617d2010-08-17 00:41:00 -04001680
Dianne Hackbornc777e072010-02-12 13:07:59 -08001681 if (mSystemReady) {
Christopher Tate5e08af02012-09-21 17:17:22 -07001682 int pointerLocation = Settings.System.getIntForUser(resolver,
1683 Settings.System.POINTER_LOCATION, 0, UserHandle.USER_CURRENT);
Dianne Hackbornc777e072010-02-12 13:07:59 -08001684 if (mPointerLocationMode != pointerLocation) {
1685 mPointerLocationMode = pointerLocation;
Jeff Brown70825162012-03-28 17:27:48 -07001686 mHandler.sendEmptyMessage(pointerLocation != 0 ?
1687 MSG_ENABLE_POINTER_LOCATION : MSG_DISABLE_POINTER_LOCATION);
Dianne Hackbornc777e072010-02-12 13:07:59 -08001688 }
1689 }
1690 // use screen off timeout setting as the timeout for the lockscreen
Christopher Tate5e08af02012-09-21 17:17:22 -07001691 mLockScreenTimeout = Settings.System.getIntForUser(resolver,
1692 Settings.System.SCREEN_OFF_TIMEOUT, 0, UserHandle.USER_CURRENT);
1693 String imId = Settings.Secure.getStringForUser(resolver,
1694 Settings.Secure.DEFAULT_INPUT_METHOD, UserHandle.USER_CURRENT);
Dianne Hackbornc777e072010-02-12 13:07:59 -08001695 boolean hasSoftInput = imId != null && imId.length() > 0;
1696 if (mHasSoftInput != hasSoftInput) {
1697 mHasSoftInput = hasSoftInput;
1698 updateRotation = true;
1699 }
John Spurlockf1a36642013-10-12 17:50:42 -04001700 if (mImmersiveModeConfirmation != null) {
John Spurlock4355a532014-02-19 09:49:25 -05001701 mImmersiveModeConfirmation.loadSetting(mCurrentUserId);
John Spurlockd67ec252013-09-05 11:31:54 -04001702 }
tiger_huangcc6366d2015-06-29 17:17:30 +08001703 }
1704 synchronized (mWindowManagerFuncs.getWindowManagerLock()) {
John Spurlockc6d1c602014-01-17 15:22:06 -05001705 PolicyControl.reloadFromSetting(mContext);
Dianne Hackbornc777e072010-02-12 13:07:59 -08001706 }
1707 if (updateRotation) {
Jeff Brown01a98dd2011-09-20 15:08:29 -07001708 updateRotation(true);
Dianne Hackbornc777e072010-02-12 13:07:59 -08001709 }
Jeff Brown70825162012-03-28 17:27:48 -07001710 }
1711
Jeff Browna20dda42014-05-27 20:57:24 -07001712 private void updateWakeGestureListenerLp() {
1713 if (shouldEnableWakeGestureLp()) {
1714 mWakeGestureListener.requestWakeUpTrigger();
1715 } else {
1716 mWakeGestureListener.cancelWakeUpTrigger();
1717 }
1718 }
1719
1720 private boolean shouldEnableWakeGestureLp() {
Jeff Brown3ee549c2014-09-22 20:14:39 -07001721 return mWakeGestureEnabledSetting && !mAwake
Jeff Browna20dda42014-05-27 20:57:24 -07001722 && (!mLidControlsSleep || mLidState != LID_CLOSED)
1723 && mWakeGestureListener.isSupported();
1724 }
1725
Jeff Brown70825162012-03-28 17:27:48 -07001726 private void enablePointerLocation() {
1727 if (mPointerLocationView == null) {
1728 mPointerLocationView = new PointerLocationView(mContext);
1729 mPointerLocationView.setPrintCoords(false);
Dianne Hackbornc777e072010-02-12 13:07:59 -08001730 WindowManager.LayoutParams lp = new WindowManager.LayoutParams(
1731 WindowManager.LayoutParams.MATCH_PARENT,
1732 WindowManager.LayoutParams.MATCH_PARENT);
Jeff Brown3b2b3542010-10-15 00:54:27 -07001733 lp.type = WindowManager.LayoutParams.TYPE_SECURE_SYSTEM_OVERLAY;
Jeff Brownbfcb60a2011-09-08 18:51:14 -07001734 lp.flags = WindowManager.LayoutParams.FLAG_FULLSCREEN
1735 | WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE
1736 | WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE
1737 | WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN;
Jeff Brown90fc9052012-10-01 14:44:24 -07001738 if (ActivityManager.isHighEndGfx()) {
1739 lp.flags |= WindowManager.LayoutParams.FLAG_HARDWARE_ACCELERATED;
1740 lp.privateFlags |=
1741 WindowManager.LayoutParams.PRIVATE_FLAG_FORCE_HARDWARE_ACCELERATED;
1742 }
Dianne Hackbornc777e072010-02-12 13:07:59 -08001743 lp.format = PixelFormat.TRANSLUCENT;
1744 lp.setTitle("PointerLocation");
Dianne Hackborn5fd21692011-06-07 14:09:47 -07001745 WindowManager wm = (WindowManager)
Dianne Hackbornc777e072010-02-12 13:07:59 -08001746 mContext.getSystemService(Context.WINDOW_SERVICE);
Jeff Browncc4f7db2011-08-30 20:34:48 -07001747 lp.inputFeatures |= WindowManager.LayoutParams.INPUT_FEATURE_NO_INPUT_CHANNEL;
Jeff Brown70825162012-03-28 17:27:48 -07001748 wm.addView(mPointerLocationView, lp);
Michael Wrightc9c487e2013-11-07 18:55:09 -08001749 mWindowManagerFuncs.registerPointerEventListener(mPointerLocationView);
Dianne Hackbornc777e072010-02-12 13:07:59 -08001750 }
Dianne Hackbornc777e072010-02-12 13:07:59 -08001751 }
Jeff Brown70825162012-03-28 17:27:48 -07001752
1753 private void disablePointerLocation() {
Jeff Brown70825162012-03-28 17:27:48 -07001754 if (mPointerLocationView != null) {
Michael Wrightc9c487e2013-11-07 18:55:09 -08001755 mWindowManagerFuncs.unregisterPointerEventListener(mPointerLocationView);
1756 WindowManager wm = (WindowManager) mContext.getSystemService(Context.WINDOW_SERVICE);
Jeff Brown70825162012-03-28 17:27:48 -07001757 wm.removeView(mPointerLocationView);
1758 mPointerLocationView = null;
1759 }
1760 }
1761
Mike Lockwood2d1efbd2009-09-16 12:15:53 -04001762 private int readRotation(int resID) {
Mike Lockwood1753f7f2009-08-24 14:49:07 -07001763 try {
1764 int rotation = mContext.getResources().getInteger(resID);
1765 switch (rotation) {
1766 case 0:
1767 return Surface.ROTATION_0;
1768 case 90:
1769 return Surface.ROTATION_90;
1770 case 180:
1771 return Surface.ROTATION_180;
1772 case 270:
1773 return Surface.ROTATION_270;
Mike Lockwood1753f7f2009-08-24 14:49:07 -07001774 }
1775 } catch (Resources.NotFoundException e) {
Mike Lockwood2d1efbd2009-09-16 12:15:53 -04001776 // fall through
Mike Lockwood1753f7f2009-08-24 14:49:07 -07001777 }
Mike Lockwood2d1efbd2009-09-16 12:15:53 -04001778 return -1;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001779 }
1780
1781 /** {@inheritDoc} */
Craig Mautner88400d32012-09-30 12:35:45 -07001782 @Override
Dianne Hackbornc2293022013-02-06 23:14:49 -08001783 public int checkAddPermission(WindowManager.LayoutParams attrs, int[] outAppOp) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001784 int type = attrs.type;
Dianne Hackbornc2293022013-02-06 23:14:49 -08001785
1786 outAppOp[0] = AppOpsManager.OP_NONE;
1787
Wale Ogunwale74bf0652015-01-12 10:24:36 -08001788 if (!((type >= FIRST_APPLICATION_WINDOW && type <= LAST_APPLICATION_WINDOW)
1789 || (type >= FIRST_SUB_WINDOW && type <= LAST_SUB_WINDOW)
1790 || (type >= FIRST_SYSTEM_WINDOW && type <= LAST_SYSTEM_WINDOW))) {
1791 return WindowManagerGlobal.ADD_INVALID_TYPE;
1792 }
1793
1794 if (type < FIRST_SYSTEM_WINDOW || type > LAST_SYSTEM_WINDOW) {
1795 // Window manager will make sure these are okay.
Jeff Brown98365d72012-08-19 20:30:52 -07001796 return WindowManagerGlobal.ADD_OKAY;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001797 }
1798 String permission = null;
1799 switch (type) {
1800 case TYPE_TOAST:
1801 // XXX right now the app process has complete control over
1802 // this... should introduce a token to let the system
1803 // monitor/control what they are doing.
Jason Monk1c7c3192014-06-26 12:52:18 -04001804 outAppOp[0] = AppOpsManager.OP_TOAST_WINDOW;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001805 break;
Daniel Sandler7d276c32012-01-30 14:33:52 -05001806 case TYPE_DREAM:
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001807 case TYPE_INPUT_METHOD:
Dianne Hackbornb7cd8b92009-08-08 20:53:03 -07001808 case TYPE_WALLPAPER:
keunyounga446bf02013-06-21 19:07:57 -07001809 case TYPE_PRIVATE_PRESENTATION:
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001810 case TYPE_VOICE_INTERACTION:
Svetoslav3a5c7212014-10-14 09:54:26 -07001811 case TYPE_ACCESSIBILITY_OVERLAY:
Dianne Hackbornb7cd8b92009-08-08 20:53:03 -07001812 // The window manager will check these.
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001813 break;
1814 case TYPE_PHONE:
1815 case TYPE_PRIORITY_PHONE:
1816 case TYPE_SYSTEM_ALERT:
1817 case TYPE_SYSTEM_ERROR:
1818 case TYPE_SYSTEM_OVERLAY:
1819 permission = android.Manifest.permission.SYSTEM_ALERT_WINDOW;
Dianne Hackbornc2293022013-02-06 23:14:49 -08001820 outAppOp[0] = AppOpsManager.OP_SYSTEM_ALERT_WINDOW;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001821 break;
1822 default:
1823 permission = android.Manifest.permission.INTERNAL_SYSTEM_WINDOW;
1824 }
1825 if (permission != null) {
Billy Laucbe540f2015-06-25 01:51:44 +01001826 if (permission == android.Manifest.permission.SYSTEM_ALERT_WINDOW) {
1827 final int callingUid = Binder.getCallingUid();
1828 // check if this is a system uid first before bothering with
1829 // obtaining package name
1830 if (callingUid == Process.SYSTEM_UID) {
1831 return WindowManagerGlobal.ADD_OKAY;
1832 }
1833
1834 final int mode = mAppOpsManager.checkOp(outAppOp[0], callingUid,
1835 attrs.packageName);
1836 if (mode == AppOpsManager.MODE_DEFAULT) {
1837 if (mContext.checkCallingPermission(permission) !=
1838 PackageManager.PERMISSION_GRANTED) {
1839 return WindowManagerGlobal.ADD_PERMISSION_DENIED;
1840 }
1841 }
1842 return WindowManagerGlobal.ADD_OKAY;
1843 }
1844
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001845 if (mContext.checkCallingOrSelfPermission(permission)
1846 != PackageManager.PERMISSION_GRANTED) {
Jeff Brown98365d72012-08-19 20:30:52 -07001847 return WindowManagerGlobal.ADD_PERMISSION_DENIED;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001848 }
1849 }
Jeff Brown98365d72012-08-19 20:30:52 -07001850 return WindowManagerGlobal.ADD_OKAY;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001851 }
Craig Mautner88400d32012-09-30 12:35:45 -07001852
1853 @Override
1854 public boolean checkShowToOwnerOnly(WindowManager.LayoutParams attrs) {
1855
1856 // If this switch statement is modified, modify the comment in the declarations of
1857 // the type in {@link WindowManager.LayoutParams} as well.
1858 switch (attrs.type) {
1859 default:
1860 // These are the windows that by default are shown only to the user that created
1861 // them. If this needs to be overridden, set
1862 // {@link WindowManager.LayoutParams.PRIVATE_FLAG_SHOW_FOR_ALL_USERS} in
1863 // {@link WindowManager.LayoutParams}. Note that permission
1864 // {@link android.Manifest.permission.INTERNAL_SYSTEM_WINDOW} is required as well.
1865 if ((attrs.privateFlags & PRIVATE_FLAG_SHOW_FOR_ALL_USERS) == 0) {
1866 return true;
1867 }
1868 break;
1869
1870 // These are the windows that by default are shown to all users. However, to
1871 // protect against spoofing, check permissions below.
1872 case TYPE_APPLICATION_STARTING:
1873 case TYPE_BOOT_PROGRESS:
1874 case TYPE_DISPLAY_OVERLAY:
Selim Cinekf83e8242015-05-19 18:08:14 -07001875 case TYPE_INPUT_CONSUMER:
Jim Miller5ecd8112013-01-09 18:50:26 -08001876 case TYPE_KEYGUARD_SCRIM:
Craig Mautner88400d32012-09-30 12:35:45 -07001877 case TYPE_KEYGUARD_DIALOG:
1878 case TYPE_MAGNIFICATION_OVERLAY:
1879 case TYPE_NAVIGATION_BAR:
1880 case TYPE_NAVIGATION_BAR_PANEL:
1881 case TYPE_PHONE:
1882 case TYPE_POINTER:
1883 case TYPE_PRIORITY_PHONE:
Craig Mautner88400d32012-09-30 12:35:45 -07001884 case TYPE_SEARCH_BAR:
1885 case TYPE_STATUS_BAR:
1886 case TYPE_STATUS_BAR_PANEL:
1887 case TYPE_STATUS_BAR_SUB_PANEL:
1888 case TYPE_SYSTEM_DIALOG:
Craig Mautner88400d32012-09-30 12:35:45 -07001889 case TYPE_VOLUME_OVERLAY:
keunyounga446bf02013-06-21 19:07:57 -07001890 case TYPE_PRIVATE_PRESENTATION:
Craig Mautner88400d32012-09-30 12:35:45 -07001891 break;
1892 }
1893
1894 // Check if third party app has set window to system window type.
1895 return mContext.checkCallingOrSelfPermission(
1896 android.Manifest.permission.INTERNAL_SYSTEM_WINDOW)
1897 != PackageManager.PERMISSION_GRANTED;
1898 }
1899
Craig Mautner967212c2013-04-13 21:10:58 -07001900 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001901 public void adjustWindowParamsLw(WindowManager.LayoutParams attrs) {
1902 switch (attrs.type) {
1903 case TYPE_SYSTEM_OVERLAY:
Jeff Brown3b2b3542010-10-15 00:54:27 -07001904 case TYPE_SECURE_SYSTEM_OVERLAY:
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001905 // These types of windows can't receive input events.
1906 attrs.flags |= WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE
1907 | WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE;
Jeff Brownbfcb60a2011-09-08 18:51:14 -07001908 attrs.flags &= ~WindowManager.LayoutParams.FLAG_WATCH_OUTSIDE_TOUCH;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001909 break;
Jorim Jaggi380ecb82014-03-14 17:25:20 +01001910 case TYPE_STATUS_BAR:
1911
1912 // If the Keyguard is in a hidden state (occluded by another window), we force to
1913 // remove the wallpaper and keyguard flag so that any change in-flight after setting
1914 // the keyguard as occluded wouldn't set these flags again.
1915 // See {@link #processKeyguardSetHiddenResultLw}.
1916 if (mKeyguardHidden) {
1917 attrs.flags &= ~WindowManager.LayoutParams.FLAG_SHOW_WALLPAPER;
1918 attrs.privateFlags &= ~WindowManager.LayoutParams.PRIVATE_FLAG_KEYGUARD;
1919 }
1920 break;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001921 }
Adrian Roos38502112014-04-09 21:04:11 +02001922
1923 if (attrs.type != TYPE_STATUS_BAR) {
1924 // The status bar is the only window allowed to exhibit keyguard behavior.
1925 attrs.privateFlags &= ~WindowManager.LayoutParams.PRIVATE_FLAG_KEYGUARD;
1926 }
Adrian Roosea562512014-05-05 13:33:03 +02001927
1928 if (ActivityManager.isHighEndGfx()
1929 && (attrs.flags & FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS) != 0) {
Adrian Roosf5e9b5c2014-09-10 15:27:41 +02001930 attrs.subtreeSystemUiVisibility |= View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
Adrian Roosea562512014-05-05 13:33:03 +02001931 | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION;
1932 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001933 }
RoboErik8a2cfc32014-05-16 11:19:38 -07001934
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001935 void readLidState() {
Jeff Brown2e7760e2012-04-11 15:14:55 -07001936 mLidState = mWindowManagerFuncs.getLidState();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001937 }
RoboErik8a2cfc32014-05-16 11:19:38 -07001938
Michael Wright3818c922014-09-02 13:59:07 -07001939 private void readCameraLensCoverState() {
1940 mCameraLensCoverState = mWindowManagerFuncs.getCameraLensCoverState();
1941 }
1942
Jeff Browndaa37532012-05-01 15:54:03 -07001943 private boolean isHidden(int accessibilityMode) {
1944 switch (accessibilityMode) {
1945 case 1:
1946 return mLidState == LID_CLOSED;
1947 case 2:
1948 return mLidState == LID_OPEN;
1949 default:
1950 return false;
Dianne Hackborn2862fff2009-09-15 22:56:29 -07001951 }
Dianne Hackborn2862fff2009-09-15 22:56:29 -07001952 }
Jeff Brownd04a88c2011-01-16 14:05:47 -08001953
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001954 /** {@inheritDoc} */
Craig Mautner967212c2013-04-13 21:10:58 -07001955 @Override
Jeff Browndaa37532012-05-01 15:54:03 -07001956 public void adjustConfigurationLw(Configuration config, int keyboardPresence,
1957 int navigationPresence) {
1958 mHaveBuiltInKeyboard = (keyboardPresence & PRESENCE_INTERNAL) != 0;
1959
Jeff Brownf71343d2013-05-31 17:59:11 -07001960 readConfigurationDependentBehaviors();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001961 readLidState();
Jeff Brownc458ce92012-04-30 14:58:40 -07001962 applyLidSwitchState();
Jeff Brownd04a88c2011-01-16 14:05:47 -08001963
Jeff Browndaa37532012-05-01 15:54:03 -07001964 if (config.keyboard == Configuration.KEYBOARD_NOKEYS
1965 || (keyboardPresence == PRESENCE_INTERNAL
1966 && isHidden(mLidKeyboardAccessibility))) {
Jeff Brownd04a88c2011-01-16 14:05:47 -08001967 config.hardKeyboardHidden = Configuration.HARDKEYBOARDHIDDEN_YES;
Jeff Browndaa37532012-05-01 15:54:03 -07001968 if (!mHasSoftInput) {
1969 config.keyboardHidden = Configuration.KEYBOARDHIDDEN_YES;
1970 }
Jeff Brownd04a88c2011-01-16 14:05:47 -08001971 }
1972
Jeff Browndaa37532012-05-01 15:54:03 -07001973 if (config.navigation == Configuration.NAVIGATION_NONAV
1974 || (navigationPresence == PRESENCE_INTERNAL
1975 && isHidden(mLidNavigationAccessibility))) {
Jeff Brownd04a88c2011-01-16 14:05:47 -08001976 config.navigationHidden = Configuration.NAVIGATIONHIDDEN_YES;
Jeff Brownd04a88c2011-01-16 14:05:47 -08001977 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001978 }
Jeff Brownd04a88c2011-01-16 14:05:47 -08001979
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001980 /** {@inheritDoc} */
Craig Mautner967212c2013-04-13 21:10:58 -07001981 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001982 public int windowTypeToLayerLw(int type) {
1983 if (type >= FIRST_APPLICATION_WINDOW && type <= LAST_APPLICATION_WINDOW) {
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001984 return 2;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001985 }
1986 switch (type) {
keunyounga446bf02013-06-21 19:07:57 -07001987 case TYPE_PRIVATE_PRESENTATION:
1988 return 2;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001989 case TYPE_WALLPAPER:
1990 // wallpaper is at the bottom, though the window manager may move it.
1991 return 2;
1992 case TYPE_PHONE:
1993 return 3;
1994 case TYPE_SEARCH_BAR:
Jorim Jaggi225d3b52015-04-01 11:18:57 -07001995 case TYPE_VOICE_INTERACTION_STARTING:
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001996 return 4;
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001997 case TYPE_VOICE_INTERACTION:
1998 // voice interaction layer is almost immediately above apps.
1999 return 5;
Selim Cinekf83e8242015-05-19 18:08:14 -07002000 case TYPE_INPUT_CONSUMER:
Dianne Hackborne30e02f2014-05-27 18:24:45 -07002001 return 6;
Selim Cinekf83e8242015-05-19 18:08:14 -07002002 case TYPE_SYSTEM_DIALOG:
2003 return 7;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07002004 case TYPE_TOAST:
2005 // toasts and the plugged-in battery thing
Selim Cinekf83e8242015-05-19 18:08:14 -07002006 return 8;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07002007 case TYPE_PRIORITY_PHONE:
2008 // SIM errors and unlock. Not sure if this really should be in a high layer.
Selim Cinekf83e8242015-05-19 18:08:14 -07002009 return 9;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07002010 case TYPE_DREAM:
2011 // used for Dreams (screensavers with TYPE_DREAM windows)
Selim Cinekf83e8242015-05-19 18:08:14 -07002012 return 10;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07002013 case TYPE_SYSTEM_ALERT:
2014 // like the ANR / app crashed dialogs
Selim Cinekf83e8242015-05-19 18:08:14 -07002015 return 11;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07002016 case TYPE_INPUT_METHOD:
2017 // on-screen keyboards and other such input method user interfaces go here.
Selim Cinekf83e8242015-05-19 18:08:14 -07002018 return 12;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07002019 case TYPE_INPUT_METHOD_DIALOG:
2020 // on-screen keyboards and other such input method user interfaces go here.
Selim Cinekf83e8242015-05-19 18:08:14 -07002021 return 13;
Jim Miller5ecd8112013-01-09 18:50:26 -08002022 case TYPE_KEYGUARD_SCRIM:
2023 // the safety window that shows behind keyguard while keyguard is starting
Jorim Jaggi380ecb82014-03-14 17:25:20 +01002024 return 14;
Selim Cinekf83e8242015-05-19 18:08:14 -07002025 case TYPE_STATUS_BAR_SUB_PANEL:
Jorim Jaggi380ecb82014-03-14 17:25:20 +01002026 return 15;
Selim Cinekf83e8242015-05-19 18:08:14 -07002027 case TYPE_STATUS_BAR:
Jorim Jaggi380ecb82014-03-14 17:25:20 +01002028 return 16;
Selim Cinekf83e8242015-05-19 18:08:14 -07002029 case TYPE_STATUS_BAR_PANEL:
Dianne Hackborne30e02f2014-05-27 18:24:45 -07002030 return 17;
Selim Cinekf83e8242015-05-19 18:08:14 -07002031 case TYPE_KEYGUARD_DIALOG:
2032 return 18;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07002033 case TYPE_VOLUME_OVERLAY:
2034 // the on-screen volume indicator and controller shown when the user
2035 // changes the device volume
Selim Cinekf83e8242015-05-19 18:08:14 -07002036 return 19;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07002037 case TYPE_SYSTEM_OVERLAY:
2038 // the on-screen volume indicator and controller shown when the user
2039 // changes the device volume
Selim Cinekf83e8242015-05-19 18:08:14 -07002040 return 20;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07002041 case TYPE_NAVIGATION_BAR:
2042 // the navigation bar, if available, shows atop most things
Selim Cinekf83e8242015-05-19 18:08:14 -07002043 return 21;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07002044 case TYPE_NAVIGATION_BAR_PANEL:
2045 // some panels (e.g. search) need to show on top of the navigation bar
Selim Cinekf83e8242015-05-19 18:08:14 -07002046 return 22;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07002047 case TYPE_SYSTEM_ERROR:
2048 // system-level error dialogs
Selim Cinekf83e8242015-05-19 18:08:14 -07002049 return 23;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07002050 case TYPE_MAGNIFICATION_OVERLAY:
2051 // used to highlight the magnified portion of a display
Selim Cinekf83e8242015-05-19 18:08:14 -07002052 return 24;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07002053 case TYPE_DISPLAY_OVERLAY:
2054 // used to simulate secondary display devices
Selim Cinekf83e8242015-05-19 18:08:14 -07002055 return 25;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07002056 case TYPE_DRAG:
2057 // the drag layer: input for drag-and-drop is associated with this window,
2058 // which sits above all other focusable windows
Selim Cinekf83e8242015-05-19 18:08:14 -07002059 return 26;
Svetoslav3a5c7212014-10-14 09:54:26 -07002060 case TYPE_ACCESSIBILITY_OVERLAY:
2061 // overlay put by accessibility services to intercept user interaction
Dianne Hackborne30e02f2014-05-27 18:24:45 -07002062 return 27;
Selim Cinekf83e8242015-05-19 18:08:14 -07002063 case TYPE_SECURE_SYSTEM_OVERLAY:
Svetoslav3a5c7212014-10-14 09:54:26 -07002064 return 28;
Selim Cinekf83e8242015-05-19 18:08:14 -07002065 case TYPE_BOOT_PROGRESS:
2066 return 29;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07002067 case TYPE_POINTER:
2068 // the (mouse) pointer layer
Svetoslav3a5c7212014-10-14 09:54:26 -07002069 return 30;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002070 }
2071 Log.e(TAG, "Unknown window type: " + type);
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07002072 return 2;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002073 }
2074
2075 /** {@inheritDoc} */
Craig Mautner46ac6fa2013-08-01 10:06:34 -07002076 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002077 public int subWindowTypeToLayerLw(int type) {
2078 switch (type) {
2079 case TYPE_APPLICATION_PANEL:
2080 case TYPE_APPLICATION_ATTACHED_DIALOG:
2081 return APPLICATION_PANEL_SUBLAYER;
2082 case TYPE_APPLICATION_MEDIA:
2083 return APPLICATION_MEDIA_SUBLAYER;
Dianne Hackborn5cb8d792009-05-21 17:34:15 -07002084 case TYPE_APPLICATION_MEDIA_OVERLAY:
2085 return APPLICATION_MEDIA_OVERLAY_SUBLAYER;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002086 case TYPE_APPLICATION_SUB_PANEL:
2087 return APPLICATION_SUB_PANEL_SUBLAYER;
Wale Ogunwale0a4dc222015-04-14 12:58:42 -07002088 case TYPE_APPLICATION_ABOVE_SUB_PANEL:
2089 return APPLICATION_ABOVE_SUB_PANEL_SUBLAYER;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002090 }
2091 Log.e(TAG, "Unknown sub-window type: " + type);
2092 return 0;
2093 }
2094
Craig Mautner46ac6fa2013-08-01 10:06:34 -07002095 @Override
Dianne Hackbornabe0da02009-09-18 01:55:39 -07002096 public int getMaxWallpaperLayer() {
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07002097 return windowTypeToLayerLw(TYPE_STATUS_BAR);
Dianne Hackbornabe0da02009-09-18 01:55:39 -07002098 }
2099
Craig Mautner46ac6fa2013-08-01 10:06:34 -07002100 @Override
Dianne Hackborn1f903c32011-09-13 19:18:06 -07002101 public int getNonDecorDisplayWidth(int fullWidth, int fullHeight, int rotation) {
Dianne Hackborn077ee852012-04-09 16:27:07 -07002102 if (mHasNavigationBar) {
2103 // For a basic navigation bar, when we are in landscape mode we place
2104 // the navigation bar to the side.
Daniel Sandler4a066c52012-04-20 14:49:13 -04002105 if (mNavigationBarCanMove && fullWidth > fullHeight) {
2106 return fullWidth - mNavigationBarWidthForRotation[rotation];
Dianne Hackborn077ee852012-04-09 16:27:07 -07002107 }
Dianne Hackborn1f903c32011-09-13 19:18:06 -07002108 }
2109 return fullWidth;
Dianne Hackborne2515ee2011-04-27 18:52:56 -04002110 }
2111
Jose Lima9546b202014-07-02 17:21:51 -07002112 @Override
Dianne Hackborn1f903c32011-09-13 19:18:06 -07002113 public int getNonDecorDisplayHeight(int fullWidth, int fullHeight, int rotation) {
Dianne Hackborn077ee852012-04-09 16:27:07 -07002114 if (mHasNavigationBar) {
2115 // For a basic navigation bar, when we are in portrait mode we place
2116 // the navigation bar to the bottom.
Daniel Sandler4a066c52012-04-20 14:49:13 -04002117 if (!mNavigationBarCanMove || fullWidth < fullHeight) {
2118 return fullHeight - mNavigationBarHeightForRotation[rotation];
Dianne Hackborn077ee852012-04-09 16:27:07 -07002119 }
2120 }
2121 return fullHeight;
Dianne Hackborn69cb8752011-05-19 18:13:32 -07002122 }
2123
Jose Lima9546b202014-07-02 17:21:51 -07002124 @Override
Dianne Hackborn1f903c32011-09-13 19:18:06 -07002125 public int getConfigDisplayWidth(int fullWidth, int fullHeight, int rotation) {
2126 return getNonDecorDisplayWidth(fullWidth, fullHeight, rotation);
Dianne Hackborn69cb8752011-05-19 18:13:32 -07002127 }
2128
Jose Lima9546b202014-07-02 17:21:51 -07002129 @Override
Dianne Hackborn1f903c32011-09-13 19:18:06 -07002130 public int getConfigDisplayHeight(int fullWidth, int fullHeight, int rotation) {
John Spurlock80f00c12013-06-13 11:10:51 -04002131 // There is a separate status bar at the top of the display. We don't count that as part
2132 // of the fixed decor, since it can hide; however, for purposes of configurations,
Dianne Hackborn077ee852012-04-09 16:27:07 -07002133 // we do want to exclude it since applications can't generally use that part
2134 // of the screen.
John Spurlock80f00c12013-06-13 11:10:51 -04002135 return getNonDecorDisplayHeight(fullWidth, fullHeight, rotation) - mStatusBarHeight;
Dianne Hackborne2515ee2011-04-27 18:52:56 -04002136 }
2137
Craig Mautnera3f4bf52012-10-10 20:37:48 -07002138 @Override
Craig Mautnerc9457fa2014-06-06 14:27:48 -07002139 public boolean isForceHiding(WindowManager.LayoutParams attrs) {
2140 return (attrs.privateFlags & PRIVATE_FLAG_KEYGUARD) != 0 ||
Jim Millerab954542014-10-10 18:21:49 -07002141 (isKeyguardHostWindow(attrs) &&
2142 (mKeyguardDelegate != null && mKeyguardDelegate.isShowing())) ||
Adrian Roos69e510d2014-07-13 14:57:59 +02002143 (attrs.type == TYPE_KEYGUARD_SCRIM);
Dianne Hackborn01ad2f42009-09-24 19:24:56 -07002144 }
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07002145
Craig Mautnera3f4bf52012-10-10 20:37:48 -07002146 @Override
Jorim Jaggi0d674622014-05-21 01:34:15 +02002147 public boolean isKeyguardHostWindow(WindowManager.LayoutParams attrs) {
2148 return attrs.type == TYPE_STATUS_BAR;
2149 }
2150
2151 @Override
Dianne Hackborn01ad2f42009-09-24 19:24:56 -07002152 public boolean canBeForceHidden(WindowState win, WindowManager.LayoutParams attrs) {
Craig Mautnera3f4bf52012-10-10 20:37:48 -07002153 switch (attrs.type) {
2154 case TYPE_STATUS_BAR:
2155 case TYPE_NAVIGATION_BAR:
2156 case TYPE_WALLPAPER:
2157 case TYPE_DREAM:
Jim Miller5ecd8112013-01-09 18:50:26 -08002158 case TYPE_KEYGUARD_SCRIM:
Craig Mautnera3f4bf52012-10-10 20:37:48 -07002159 return false;
2160 default:
Adrian Roos461829d2015-06-03 14:41:18 -07002161 // Hide only windows below the keyguard host window.
2162 return windowTypeToLayerLw(win.getBaseType())
2163 < windowTypeToLayerLw(TYPE_STATUS_BAR);
Craig Mautnera3f4bf52012-10-10 20:37:48 -07002164 }
Dianne Hackborn01ad2f42009-09-24 19:24:56 -07002165 }
Craig Mautner8e4df6c2012-05-23 16:57:23 -07002166
Craig Mautner7d7808f2014-09-11 18:02:38 -07002167 @Override
2168 public WindowState getWinShowWhenLockedLw() {
2169 return mWinShowWhenLocked;
2170 }
2171
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002172 /** {@inheritDoc} */
Craig Mautner8e4df6c2012-05-23 16:57:23 -07002173 @Override
Dianne Hackborn2f0b1752011-05-31 17:59:49 -07002174 public View addStartingWindow(IBinder appToken, String packageName, int theme,
2175 CompatibilityInfo compatInfo, CharSequence nonLocalizedLabel, int labelRes,
Adam Powell04fe6eb2013-05-31 14:39:48 -07002176 int icon, int logo, int windowFlags) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002177 if (!SHOW_STARTING_ANIMATIONS) {
2178 return null;
2179 }
2180 if (packageName == null) {
2181 return null;
2182 }
Craig Mautner8e4df6c2012-05-23 16:57:23 -07002183
Mathias Jeppssond1443e92012-08-24 15:25:32 +02002184 WindowManager wm = null;
2185 View view = null;
2186
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002187 try {
Dianne Hackborn867ab6472010-04-29 13:28:56 -07002188 Context context = mContext;
Craig Mautner6fbda632012-07-03 09:26:39 -07002189 if (DEBUG_STARTING_WINDOW) Slog.d(TAG, "addStartingWindow " + packageName
2190 + ": nonLocalizedLabel=" + nonLocalizedLabel + " theme="
2191 + Integer.toHexString(theme));
Dianne Hackborn247fe742011-01-08 17:25:57 -08002192 if (theme != context.getThemeResId() || labelRes != 0) {
Dianne Hackborn867ab6472010-04-29 13:28:56 -07002193 try {
2194 context = context.createPackageContext(packageName, 0);
Dianne Hackborn247fe742011-01-08 17:25:57 -08002195 context.setTheme(theme);
Dianne Hackborn867ab6472010-04-29 13:28:56 -07002196 } catch (PackageManager.NameNotFoundException e) {
2197 // Ignore
2198 }
2199 }
Craig Mautner8e4df6c2012-05-23 16:57:23 -07002200
Jorim Jaggia16cc152015-06-01 16:55:05 -07002201 PhoneWindow win = new PhoneWindow(context);
2202 win.setIsStartingWindow(true);
Craig Mautner8e4df6c2012-05-23 16:57:23 -07002203 final TypedArray ta = win.getWindowStyle();
2204 if (ta.getBoolean(
2205 com.android.internal.R.styleable.Window_windowDisablePreview, false)
2206 || ta.getBoolean(
2207 com.android.internal.R.styleable.Window_windowShowWallpaper,false)) {
Dianne Hackborn867ab6472010-04-29 13:28:56 -07002208 return null;
2209 }
Craig Mautner8e4df6c2012-05-23 16:57:23 -07002210
Dianne Hackborn867ab6472010-04-29 13:28:56 -07002211 Resources r = context.getResources();
2212 win.setTitle(r.getText(labelRes, nonLocalizedLabel));
Craig Mautner8e4df6c2012-05-23 16:57:23 -07002213
Dianne Hackborn867ab6472010-04-29 13:28:56 -07002214 win.setType(
2215 WindowManager.LayoutParams.TYPE_APPLICATION_STARTING);
Adrian Roos602c68e2015-04-24 16:03:47 -07002216
2217 synchronized (mWindowManagerFuncs.getWindowManagerLock()) {
2218 // Assumes it's safe to show starting windows of launched apps while
2219 // the keyguard is being hidden. This is okay because starting windows never show
2220 // secret information.
2221 if (mKeyguardHidden) {
2222 windowFlags |= FLAG_SHOW_WHEN_LOCKED;
2223 }
2224 }
2225
Dianne Hackborn867ab6472010-04-29 13:28:56 -07002226 // Force the window flags: this is a fake window, so it is not really
2227 // touchable or focusable by the user. We also add in the ALT_FOCUSABLE_IM
2228 // flag because we do know that the next window will take input
2229 // focus, so we want to get the IME window up on top of us right away.
2230 win.setFlags(
Dianne Hackborn7eec10e2010-11-12 18:03:47 -08002231 windowFlags|
Dianne Hackborn867ab6472010-04-29 13:28:56 -07002232 WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE|
2233 WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE|
2234 WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM,
Dianne Hackborn7eec10e2010-11-12 18:03:47 -08002235 windowFlags|
Dianne Hackborn867ab6472010-04-29 13:28:56 -07002236 WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE|
2237 WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE|
2238 WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM);
Craig Mautner8e4df6c2012-05-23 16:57:23 -07002239
Adam Powell04fe6eb2013-05-31 14:39:48 -07002240 win.setDefaultIcon(icon);
2241 win.setDefaultLogo(logo);
2242
Dianne Hackborn867ab6472010-04-29 13:28:56 -07002243 win.setLayout(WindowManager.LayoutParams.MATCH_PARENT,
Dianne Hackborn2f0b1752011-05-31 17:59:49 -07002244 WindowManager.LayoutParams.MATCH_PARENT);
Craig Mautner8e4df6c2012-05-23 16:57:23 -07002245
Dianne Hackborn867ab6472010-04-29 13:28:56 -07002246 final WindowManager.LayoutParams params = win.getAttributes();
2247 params.token = appToken;
2248 params.packageName = packageName;
2249 params.windowAnimations = win.getWindowStyle().getResourceId(
2250 com.android.internal.R.styleable.Window_windowAnimationStyle, 0);
John Reck61375a82014-09-18 19:27:48 +00002251 params.privateFlags |=
2252 WindowManager.LayoutParams.PRIVATE_FLAG_FAKE_HARDWARE_ACCELERATED;
Craig Mautner88400d32012-09-30 12:35:45 -07002253 params.privateFlags |= WindowManager.LayoutParams.PRIVATE_FLAG_SHOW_FOR_ALL_USERS;
Adam Lesinski95c42972013-10-02 10:13:27 -07002254
2255 if (!compatInfo.supportsScreen()) {
2256 params.privateFlags |= WindowManager.LayoutParams.PRIVATE_FLAG_COMPATIBLE_WINDOW;
2257 }
2258
Dianne Hackborn867ab6472010-04-29 13:28:56 -07002259 params.setTitle("Starting " + packageName);
2260
Mathias Jeppssond1443e92012-08-24 15:25:32 +02002261 wm = (WindowManager)context.getSystemService(Context.WINDOW_SERVICE);
2262 view = win.getDecorView();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002263
2264 if (win.isFloating()) {
2265 // Whoops, there is no way to display an animation/preview
2266 // of such a thing! After all that work... let's skip it.
2267 // (Note that we must do this here because it is in
2268 // getDecorView() where the theme is evaluated... maybe
2269 // we should peek the floating attribute from the theme
2270 // earlier.)
2271 return null;
2272 }
Craig Mautner8e4df6c2012-05-23 16:57:23 -07002273
Craig Mautner6fbda632012-07-03 09:26:39 -07002274 if (DEBUG_STARTING_WINDOW) Slog.d(
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002275 TAG, "Adding starting window for " + packageName
2276 + " / " + appToken + ": "
2277 + (view.getParent() != null ? view : null));
2278
2279 wm.addView(view, params);
2280
2281 // Only return the view if it was successfully added to the
2282 // window manager... which we can tell by it having a parent.
2283 return view.getParent() != null ? view : null;
Jeff Brown98365d72012-08-19 20:30:52 -07002284 } catch (WindowManager.BadTokenException e) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002285 // ignore
Craig Mautner42bf39e2014-02-21 16:46:22 -08002286 Log.w(TAG, appToken + " already running, starting window not displayed. " +
2287 e.getMessage());
Dianne Hackborn867ab6472010-04-29 13:28:56 -07002288 } catch (RuntimeException e) {
2289 // don't crash if something else bad happens, for example a
2290 // failure loading resources because we are loading from an app
2291 // on external storage that has been unmounted.
2292 Log.w(TAG, appToken + " failed creating starting window", e);
Mathias Jeppssond1443e92012-08-24 15:25:32 +02002293 } finally {
2294 if (view != null && view.getParent() == null) {
2295 Log.w(TAG, "view not successfully added to wm, removing view");
2296 wm.removeViewImmediate(view);
2297 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002298 }
2299
2300 return null;
2301 }
2302
2303 /** {@inheritDoc} */
Jose Lima9546b202014-07-02 17:21:51 -07002304 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002305 public void removeStartingWindow(IBinder appToken, View window) {
Craig Mautner276a6eb2014-11-04 15:32:57 -08002306 if (DEBUG_STARTING_WINDOW) Slog.v(TAG, "Removing starting window for " + appToken + ": "
2307 + window + " Callers=" + Debug.getCallers(4));
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002308
2309 if (window != null) {
Dianne Hackborn5fd21692011-06-07 14:09:47 -07002310 WindowManager wm = (WindowManager)mContext.getSystemService(Context.WINDOW_SERVICE);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002311 wm.removeView(window);
2312 }
2313 }
2314
2315 /**
2316 * Preflight adding a window to the system.
RoboErik8a2cfc32014-05-16 11:19:38 -07002317 *
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002318 * Currently enforces that three window types are singletons:
2319 * <ul>
2320 * <li>STATUS_BAR_TYPE</li>
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002321 * <li>KEYGUARD_TYPE</li>
2322 * </ul>
RoboErik8a2cfc32014-05-16 11:19:38 -07002323 *
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002324 * @param win The window to be added
2325 * @param attrs Information about the window to be added
RoboErik8a2cfc32014-05-16 11:19:38 -07002326 *
Jeff Brown98365d72012-08-19 20:30:52 -07002327 * @return If ok, WindowManagerImpl.ADD_OKAY. If too many singletons,
2328 * WindowManagerImpl.ADD_MULTIPLE_SINGLETON
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002329 */
Jose Lima9546b202014-07-02 17:21:51 -07002330 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002331 public int prepareAddWindowLw(WindowState win, WindowManager.LayoutParams attrs) {
2332 switch (attrs.type) {
2333 case TYPE_STATUS_BAR:
Joe Onorato8bc6c512010-06-04 16:21:12 -04002334 mContext.enforceCallingOrSelfPermission(
2335 android.Manifest.permission.STATUS_BAR_SERVICE,
2336 "PhoneWindowManager");
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002337 if (mStatusBar != null) {
Dianne Hackbornf87d1962012-04-04 12:48:24 -07002338 if (mStatusBar.isAlive()) {
Jeff Brown98365d72012-08-19 20:30:52 -07002339 return WindowManagerGlobal.ADD_MULTIPLE_SINGLETON;
Dianne Hackbornf87d1962012-04-04 12:48:24 -07002340 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002341 }
2342 mStatusBar = win;
John Spurlock27735a42013-08-14 17:57:38 -04002343 mStatusBarController.setWindow(win);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002344 break;
Daniel Sandler8956dbb2011-04-22 07:55:02 -04002345 case TYPE_NAVIGATION_BAR:
2346 mContext.enforceCallingOrSelfPermission(
2347 android.Manifest.permission.STATUS_BAR_SERVICE,
2348 "PhoneWindowManager");
Dianne Hackbornf87d1962012-04-04 12:48:24 -07002349 if (mNavigationBar != null) {
2350 if (mNavigationBar.isAlive()) {
Jeff Brown98365d72012-08-19 20:30:52 -07002351 return WindowManagerGlobal.ADD_MULTIPLE_SINGLETON;
Dianne Hackbornf87d1962012-04-04 12:48:24 -07002352 }
2353 }
Daniel Sandler8956dbb2011-04-22 07:55:02 -04002354 mNavigationBar = win;
John Spurlock27735a42013-08-14 17:57:38 -04002355 mNavigationBarController.setWindow(win);
Craig Mautnereda67292013-04-28 13:50:14 -07002356 if (DEBUG_LAYOUT) Slog.i(TAG, "NAVIGATION BAR: " + mNavigationBar);
Daniel Sandler8956dbb2011-04-22 07:55:02 -04002357 break;
Jim Millere898ac52012-04-06 17:10:57 -07002358 case TYPE_NAVIGATION_BAR_PANEL:
Dianne Hackborn08743722009-12-21 12:16:51 -08002359 case TYPE_STATUS_BAR_PANEL:
Joe Onorato29fc2c92010-11-24 10:26:50 -08002360 case TYPE_STATUS_BAR_SUB_PANEL:
Jorim Jaggi225d3b52015-04-01 11:18:57 -07002361 case TYPE_VOICE_INTERACTION_STARTING:
Joe Onorato29fc2c92010-11-24 10:26:50 -08002362 mContext.enforceCallingOrSelfPermission(
2363 android.Manifest.permission.STATUS_BAR_SERVICE,
2364 "PhoneWindowManager");
Joe Onorato29fc2c92010-11-24 10:26:50 -08002365 break;
Jim Miller5ecd8112013-01-09 18:50:26 -08002366 case TYPE_KEYGUARD_SCRIM:
Jim Miller25190572013-02-28 17:36:24 -08002367 if (mKeyguardScrim != null) {
2368 return WindowManagerGlobal.ADD_MULTIPLE_SINGLETON;
2369 }
Jim Miller5ecd8112013-01-09 18:50:26 -08002370 mKeyguardScrim = win;
2371 break;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002372 }
Jeff Brown98365d72012-08-19 20:30:52 -07002373 return WindowManagerGlobal.ADD_OKAY;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002374 }
2375
2376 /** {@inheritDoc} */
Jose Lima9546b202014-07-02 17:21:51 -07002377 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002378 public void removeWindowLw(WindowState win) {
2379 if (mStatusBar == win) {
2380 mStatusBar = null;
John Spurlock27735a42013-08-14 17:57:38 -04002381 mStatusBarController.setWindow(null);
Jim Millerc0b676d2013-03-22 16:11:08 -07002382 mKeyguardDelegate.showScrim();
Jim Miller5ecd8112013-01-09 18:50:26 -08002383 } else if (mKeyguardScrim == win) {
2384 Log.v(TAG, "Removing keyguard scrim");
2385 mKeyguardScrim = null;
2386 } if (mNavigationBar == win) {
Daniel Sandler8956dbb2011-04-22 07:55:02 -04002387 mNavigationBar = null;
John Spurlock27735a42013-08-14 17:57:38 -04002388 mNavigationBarController.setWindow(null);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002389 }
2390 }
2391
2392 static final boolean PRINT_ANIM = false;
RoboErik8a2cfc32014-05-16 11:19:38 -07002393
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002394 /** {@inheritDoc} */
Craig Mautner4b71aa12012-12-27 17:20:01 -08002395 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002396 public int selectAnimationLw(WindowState win, int transit) {
2397 if (PRINT_ANIM) Log.i(TAG, "selectAnimation in " + win
2398 + ": transit=" + transit);
Dianne Hackbornf87d1962012-04-04 12:48:24 -07002399 if (win == mStatusBar) {
Jorim Jaggi380ecb82014-03-14 17:25:20 +01002400 boolean isKeyguard = (win.getAttrs().privateFlags & PRIVATE_FLAG_KEYGUARD) != 0;
Craig Mautner4b71aa12012-12-27 17:20:01 -08002401 if (transit == TRANSIT_EXIT
2402 || transit == TRANSIT_HIDE) {
Jorim Jaggi380ecb82014-03-14 17:25:20 +01002403 return isKeyguard ? -1 : R.anim.dock_top_exit;
Craig Mautner4b71aa12012-12-27 17:20:01 -08002404 } else if (transit == TRANSIT_ENTER
2405 || transit == TRANSIT_SHOW) {
Jorim Jaggi380ecb82014-03-14 17:25:20 +01002406 return isKeyguard ? -1 : R.anim.dock_top_enter;
Dianne Hackbornf87d1962012-04-04 12:48:24 -07002407 }
2408 } else if (win == mNavigationBar) {
2409 // This can be on either the bottom or the right.
2410 if (mNavigationBarOnBottom) {
Craig Mautner4b71aa12012-12-27 17:20:01 -08002411 if (transit == TRANSIT_EXIT
2412 || transit == TRANSIT_HIDE) {
Dianne Hackbornf87d1962012-04-04 12:48:24 -07002413 return R.anim.dock_bottom_exit;
Craig Mautner4b71aa12012-12-27 17:20:01 -08002414 } else if (transit == TRANSIT_ENTER
2415 || transit == TRANSIT_SHOW) {
Dianne Hackbornf87d1962012-04-04 12:48:24 -07002416 return R.anim.dock_bottom_enter;
2417 }
2418 } else {
Craig Mautner4b71aa12012-12-27 17:20:01 -08002419 if (transit == TRANSIT_EXIT
2420 || transit == TRANSIT_HIDE) {
Dianne Hackbornf87d1962012-04-04 12:48:24 -07002421 return R.anim.dock_right_exit;
Craig Mautner4b71aa12012-12-27 17:20:01 -08002422 } else if (transit == TRANSIT_ENTER
2423 || transit == TRANSIT_SHOW) {
Dianne Hackbornf87d1962012-04-04 12:48:24 -07002424 return R.anim.dock_right_enter;
2425 }
2426 }
Craig Mautner4b71aa12012-12-27 17:20:01 -08002427 }
2428
2429 if (transit == TRANSIT_PREVIEW_DONE) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002430 if (win.hasAppShownWindows()) {
2431 if (PRINT_ANIM) Log.i(TAG, "**** STARTING EXIT");
2432 return com.android.internal.R.anim.app_starting_exit;
2433 }
Dianne Hackborn7ad44382012-10-18 17:46:00 -07002434 } else if (win.getAttrs().type == TYPE_DREAM && mDreamingLockscreen
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07002435 && transit == TRANSIT_ENTER) {
2436 // Special case: we are animating in a dream, while the keyguard
2437 // is shown. We don't want an animation on the dream, because
2438 // we need it shown immediately with the keyguard animating away
2439 // to reveal it.
2440 return -1;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002441 }
2442
2443 return 0;
2444 }
2445
Craig Mautner3c174372013-02-21 17:54:37 -08002446 @Override
2447 public void selectRotationAnimationLw(int anim[]) {
2448 if (PRINT_ANIM) Slog.i(TAG, "selectRotationAnimation mTopFullscreen="
2449 + mTopFullscreenOpaqueWindowState + " rotationAnimation="
2450 + (mTopFullscreenOpaqueWindowState == null ?
2451 "0" : mTopFullscreenOpaqueWindowState.getAttrs().rotationAnimation));
2452 if (mTopFullscreenOpaqueWindowState != null && mTopIsFullscreen) {
2453 switch (mTopFullscreenOpaqueWindowState.getAttrs().rotationAnimation) {
2454 case ROTATION_ANIMATION_CROSSFADE:
2455 anim[0] = R.anim.rotation_animation_xfade_exit;
2456 anim[1] = R.anim.rotation_animation_enter;
2457 break;
2458 case ROTATION_ANIMATION_JUMPCUT:
2459 anim[0] = R.anim.rotation_animation_jump_exit;
2460 anim[1] = R.anim.rotation_animation_enter;
2461 break;
2462 case ROTATION_ANIMATION_ROTATE:
2463 default:
2464 anim[0] = anim[1] = 0;
2465 break;
2466 }
2467 } else {
2468 anim[0] = anim[1] = 0;
2469 }
2470 }
2471
2472 @Override
2473 public boolean validateRotationAnimationLw(int exitAnimId, int enterAnimId,
2474 boolean forceDefault) {
2475 switch (exitAnimId) {
2476 case R.anim.rotation_animation_xfade_exit:
2477 case R.anim.rotation_animation_jump_exit:
2478 // These are the only cases that matter.
2479 if (forceDefault) {
2480 return false;
2481 }
2482 int anim[] = new int[2];
2483 selectRotationAnimationLw(anim);
2484 return (exitAnimId == anim[0] && enterAnimId == anim[1]);
2485 default:
2486 return true;
2487 }
2488 }
2489
2490 @Override
Jorim Jaggi84a3e7a2014-08-13 17:58:58 +02002491 public Animation createForceHideEnterAnimation(boolean onWallpaper,
2492 boolean goingToNotificationShade) {
2493 if (goingToNotificationShade) {
2494 return AnimationUtils.loadAnimation(mContext, R.anim.lock_screen_behind_enter_fade_in);
Craig Mautnerb8340802014-11-04 15:32:57 -08002495 }
Craig Mautner276a6eb2014-11-04 15:32:57 -08002496
2497 AnimationSet set = (AnimationSet) AnimationUtils.loadAnimation(mContext, onWallpaper ?
2498 R.anim.lock_screen_behind_enter_wallpaper :
2499 R.anim.lock_screen_behind_enter);
2500
2501 // TODO: Use XML interpolators when we have log interpolators available in XML.
2502 final List<Animation> animations = set.getAnimations();
2503 for (int i = animations.size() - 1; i >= 0; --i) {
2504 animations.get(i).setInterpolator(mLogDecelerateInterpolator);
2505 }
2506
2507 return set;
Jorim Jaggi76a16232014-08-08 17:00:47 +02002508 }
2509
2510
2511 @Override
Jorim Jaggi84a3e7a2014-08-13 17:58:58 +02002512 public Animation createForceHideWallpaperExitAnimation(boolean goingToNotificationShade) {
2513 if (goingToNotificationShade) {
2514 return null;
2515 } else {
2516 return AnimationUtils.loadAnimation(mContext, R.anim.lock_screen_wallpaper_exit);
2517 }
Dianne Hackborn01ad2f42009-09-24 19:24:56 -07002518 }
John Spurlockc8b46ca2013-04-08 12:59:26 -04002519
2520 private static void awakenDreams() {
2521 IDreamManager dreamManager = getDreamManager();
2522 if (dreamManager != null) {
2523 try {
2524 dreamManager.awaken();
2525 } catch (RemoteException e) {
2526 // fine, stay asleep then
2527 }
2528 }
2529 }
2530
2531 static IDreamManager getDreamManager() {
2532 return IDreamManager.Stub.asInterface(
2533 ServiceManager.checkService(DreamService.DREAM_SERVICE));
2534 }
2535
Tyler Gunnef9f6f92014-09-12 22:16:17 -07002536 TelecomManager getTelecommService() {
2537 return (TelecomManager) mContext.getSystemService(Context.TELECOM_SERVICE);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002538 }
2539
Jeff Brown4d396052010-10-29 21:50:21 -07002540 static IAudioService getAudioService() {
2541 IAudioService audioService = IAudioService.Stub.asInterface(
2542 ServiceManager.checkService(Context.AUDIO_SERVICE));
2543 if (audioService == null) {
2544 Log.w(TAG, "Unable to find IAudioService interface.");
2545 }
2546 return audioService;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002547 }
2548
2549 boolean keyguardOn() {
Jim Millerab954542014-10-10 18:21:49 -07002550 return isKeyguardShowingAndNotOccluded() || inKeyguardRestrictedKeyInputMode();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002551 }
2552
2553 private static final int[] WINDOW_TYPES_WHERE_HOME_DOESNT_WORK = {
2554 WindowManager.LayoutParams.TYPE_SYSTEM_ALERT,
2555 WindowManager.LayoutParams.TYPE_SYSTEM_ERROR,
2556 };
2557
2558 /** {@inheritDoc} */
Jeff Brown00fa7bd2010-07-02 15:37:36 -07002559 @Override
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002560 public long interceptKeyBeforeDispatching(WindowState win, KeyEvent event, int policyFlags) {
Jeff Brown00fa7bd2010-07-02 15:37:36 -07002561 final boolean keyguardOn = keyguardOn();
Jeff Brown1f245102010-11-18 20:53:46 -08002562 final int keyCode = event.getKeyCode();
2563 final int repeatCount = event.getRepeatCount();
2564 final int metaState = event.getMetaState();
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002565 final int flags = event.getFlags();
Jeff Brown1f245102010-11-18 20:53:46 -08002566 final boolean down = event.getAction() == KeyEvent.ACTION_DOWN;
2567 final boolean canceled = event.isCanceled();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002568
Jeff Brown40013652012-05-16 21:22:36 -07002569 if (DEBUG_INPUT) {
Jeff Brown00fa7bd2010-07-02 15:37:36 -07002570 Log.d(TAG, "interceptKeyTi keyCode=" + keyCode + " down=" + down + " repeatCount="
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002571 + repeatCount + " keyguardOn=" + keyguardOn + " mHomePressed=" + mHomePressed
2572 + " canceled=" + canceled);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002573 }
2574
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002575 // If we think we might have a volume down & power key chord on the way
2576 // but we're not sure, then tell the dispatcher to wait a little while and
2577 // try again later before dispatching.
Christopher Tatee90585f2012-03-05 18:56:25 -08002578 if (mScreenshotChordEnabled && (flags & KeyEvent.FLAG_FALLBACK) == 0) {
Jeff Brown13f00f02014-10-31 14:45:50 -07002579 if (mScreenshotChordVolumeDownKeyTriggered && !mScreenshotChordPowerKeyTriggered) {
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002580 final long now = SystemClock.uptimeMillis();
Jeff Brown13f00f02014-10-31 14:45:50 -07002581 final long timeoutTime = mScreenshotChordVolumeDownKeyTime
2582 + SCREENSHOT_CHORD_DEBOUNCE_DELAY_MILLIS;
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002583 if (now < timeoutTime) {
2584 return timeoutTime - now;
2585 }
2586 }
2587 if (keyCode == KeyEvent.KEYCODE_VOLUME_DOWN
Jeff Brown13f00f02014-10-31 14:45:50 -07002588 && mScreenshotChordVolumeDownKeyConsumed) {
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002589 if (!down) {
Jeff Brown13f00f02014-10-31 14:45:50 -07002590 mScreenshotChordVolumeDownKeyConsumed = false;
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002591 }
2592 return -1;
2593 }
2594 }
2595
Michael Wright6a62e552014-06-03 19:19:48 -07002596 // Cancel any pending meta actions if we see any other keys being pressed between the down
2597 // of the meta key and its corresponding up.
Michael Wright251e35d2014-08-22 15:40:27 -07002598 if (mPendingMetaAction && !KeyEvent.isMetaKey(keyCode)) {
Michael Wright6a62e552014-06-03 19:19:48 -07002599 mPendingMetaAction = false;
2600 }
2601
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002602 // First we always handle the home key here, so applications
2603 // can never break it, although if keyguard is on, we do let
2604 // it handle it, because that gives us the correct 5 second
2605 // timeout.
Jeff Brown00fa7bd2010-07-02 15:37:36 -07002606 if (keyCode == KeyEvent.KEYCODE_HOME) {
Michael Jurka7f2668c2012-03-27 07:49:52 -07002607
Jeff Brown49ed71d2010-12-06 17:13:33 -08002608 // If we have released the home key, and didn't do anything else
2609 // while it was pressed, then it is time to go home!
Michael Jurka7f2668c2012-03-27 07:49:52 -07002610 if (!down) {
Jeff Browncaca8812013-05-09 13:34:33 -07002611 cancelPreloadRecentApps();
2612
Jeff Brown49ed71d2010-12-06 17:13:33 -08002613 mHomePressed = false;
Jeff Browncaca8812013-05-09 13:34:33 -07002614 if (mHomeConsumed) {
2615 mHomeConsumed = false;
Michael Jurka7f2668c2012-03-27 07:49:52 -07002616 return -1;
Jeff Brown49ed71d2010-12-06 17:13:33 -08002617 }
Jeff Browncaca8812013-05-09 13:34:33 -07002618
2619 if (canceled) {
2620 Log.i(TAG, "Ignoring HOME; event canceled.");
2621 return -1;
2622 }
2623
Yorke Lee4f803242014-12-15 23:22:06 +00002624 // If an incoming call is ringing, HOME is totally disabled.
2625 // (The user is already on the InCallUI at this point,
2626 // and his ONLY options are to answer or reject the call.)
2627 TelecomManager telecomManager = getTelecommService();
2628 if (telecomManager != null && telecomManager.isRinging()) {
2629 Log.i(TAG, "Ignoring HOME; there's a ringing incoming call.");
2630 return -1;
2631 }
2632
Jeff Browncaca8812013-05-09 13:34:33 -07002633 // Delay handling home if a double-tap is possible.
2634 if (mDoubleTapOnHomeBehavior != DOUBLE_TAP_HOME_NOTHING) {
2635 mHandler.removeCallbacks(mHomeDoubleTapTimeoutRunnable); // just in case
2636 mHomeDoubleTapPending = true;
2637 mHandler.postDelayed(mHomeDoubleTapTimeoutRunnable,
2638 ViewConfiguration.getDoubleTapTimeout());
2639 return -1;
2640 }
2641
Jeff Brown13f00f02014-10-31 14:45:50 -07002642 handleShortPressOnHome();
Jeff Browncaca8812013-05-09 13:34:33 -07002643 return -1;
Jeff Brown49ed71d2010-12-06 17:13:33 -08002644 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002645
2646 // If a system window has focus, then it doesn't make sense
2647 // right now to interact with applications.
2648 WindowManager.LayoutParams attrs = win != null ? win.getAttrs() : null;
2649 if (attrs != null) {
2650 final int type = attrs.type;
Jorim Jaggi380ecb82014-03-14 17:25:20 +01002651 if (type == WindowManager.LayoutParams.TYPE_KEYGUARD_SCRIM
2652 || type == WindowManager.LayoutParams.TYPE_KEYGUARD_DIALOG
2653 || (attrs.privateFlags & PRIVATE_FLAG_KEYGUARD) != 0) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002654 // the "app" is keyguard, so give it the key
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002655 return 0;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002656 }
2657 final int typeCount = WINDOW_TYPES_WHERE_HOME_DOESNT_WORK.length;
2658 for (int i=0; i<typeCount; i++) {
2659 if (type == WINDOW_TYPES_WHERE_HOME_DOESNT_WORK[i]) {
2660 // don't do anything, but also don't pass it to the app
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002661 return -1;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002662 }
2663 }
2664 }
Jeff Browncaca8812013-05-09 13:34:33 -07002665
2666 // Remember that home is pressed and handle special actions.
2667 if (repeatCount == 0) {
2668 mHomePressed = true;
2669 if (mHomeDoubleTapPending) {
2670 mHomeDoubleTapPending = false;
2671 mHandler.removeCallbacks(mHomeDoubleTapTimeoutRunnable);
2672 handleDoubleTapOnHome();
2673 } else if (mLongPressOnHomeBehavior == LONG_PRESS_HOME_RECENT_SYSTEM_UI
2674 || mDoubleTapOnHomeBehavior == DOUBLE_TAP_HOME_RECENT_SYSTEM_UI) {
2675 preloadRecentApps();
Michael Jurka7f2668c2012-03-27 07:49:52 -07002676 }
Jeff Browncaca8812013-05-09 13:34:33 -07002677 } else if ((event.getFlags() & KeyEvent.FLAG_LONG_PRESS) != 0) {
2678 if (!keyguardOn) {
Tim Kilbourn0e5f1102015-06-05 16:18:09 -07002679 handleLongPressOnHome(event.getDeviceId());
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002680 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002681 }
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002682 return -1;
Jeff Brown00fa7bd2010-07-02 15:37:36 -07002683 } else if (keyCode == KeyEvent.KEYCODE_MENU) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002684 // Hijack modified menu keys for debugging features
2685 final int chordBug = KeyEvent.META_SHIFT_ON;
2686
2687 if (down && repeatCount == 0) {
Jeff Brown00fa7bd2010-07-02 15:37:36 -07002688 if (mEnableShiftMenuBugReports && (metaState & chordBug) == chordBug) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002689 Intent intent = new Intent(Intent.ACTION_BUG_REPORT);
Dianne Hackborn5ac72a22012-08-29 18:32:08 -07002690 mContext.sendOrderedBroadcastAsUser(intent, UserHandle.CURRENT,
2691 null, null, null, 0, null, null);
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002692 return -1;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002693 } else if (SHOW_PROCESSES_ON_ALT_MENU &&
Jeff Brown00fa7bd2010-07-02 15:37:36 -07002694 (metaState & KeyEvent.META_ALT_ON) == KeyEvent.META_ALT_ON) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002695 Intent service = new Intent();
2696 service.setClassName(mContext, "com.android.server.LoadAverageService");
2697 ContentResolver res = mContext.getContentResolver();
Jeff Sharkey8d9a1f62012-10-18 15:38:14 -07002698 boolean shown = Settings.Global.getInt(
2699 res, Settings.Global.SHOW_PROCESSES, 0) != 0;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002700 if (!shown) {
2701 mContext.startService(service);
2702 } else {
2703 mContext.stopService(service);
2704 }
Jeff Sharkey8d9a1f62012-10-18 15:38:14 -07002705 Settings.Global.putInt(
2706 res, Settings.Global.SHOW_PROCESSES, shown ? 0 : 1);
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002707 return -1;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002708 }
2709 }
Jeff Brown00fa7bd2010-07-02 15:37:36 -07002710 } else if (keyCode == KeyEvent.KEYCODE_SEARCH) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002711 if (down) {
2712 if (repeatCount == 0) {
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002713 mSearchKeyShortcutPending = true;
2714 mConsumeSearchKeyUp = false;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002715 }
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002716 } else {
2717 mSearchKeyShortcutPending = false;
2718 if (mConsumeSearchKeyUp) {
2719 mConsumeSearchKeyUp = false;
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002720 return -1;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002721 }
2722 }
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002723 return 0;
Jeff Brown49ed71d2010-12-06 17:13:33 -08002724 } else if (keyCode == KeyEvent.KEYCODE_APP_SWITCH) {
Michael Wrightc9ebea72013-01-16 19:25:02 -08002725 if (!keyguardOn) {
Jeff Browncaca8812013-05-09 13:34:33 -07002726 if (down && repeatCount == 0) {
2727 preloadRecentApps();
2728 } else if (!down) {
2729 toggleRecentApps();
Michael Wrightc9ebea72013-01-16 19:25:02 -08002730 }
Jeff Brown49ed71d2010-12-06 17:13:33 -08002731 }
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002732 return -1;
Jun Mukaid21b3c82015-04-23 14:09:34 -07002733 } else if (keyCode == KeyEvent.KEYCODE_N && event.isMetaPressed()) {
2734 if (down) {
2735 IStatusBarService service = getStatusBarService();
2736 if (service != null) {
2737 try {
2738 service.expandNotificationsPanel();
2739 } catch (RemoteException e) {
2740 // do nothing.
2741 }
2742 }
2743 }
Jeff Brownde7a8ea2012-06-13 18:28:57 -07002744 } else if (keyCode == KeyEvent.KEYCODE_ASSIST) {
2745 if (down) {
2746 if (repeatCount == 0) {
2747 mAssistKeyLongPressed = false;
2748 } else if (repeatCount == 1) {
2749 mAssistKeyLongPressed = true;
2750 if (!keyguardOn) {
2751 launchAssistLongPressAction();
2752 }
2753 }
2754 } else {
2755 if (mAssistKeyLongPressed) {
2756 mAssistKeyLongPressed = false;
2757 } else {
2758 if (!keyguardOn) {
Tim Kilbourn0e5f1102015-06-05 16:18:09 -07002759 launchAssistAction(null, event.getDeviceId());
Jeff Brownde7a8ea2012-06-13 18:28:57 -07002760 }
2761 }
2762 }
2763 return -1;
Michael Wrightdc63f7b2014-08-21 19:05:21 -07002764 } else if (keyCode == KeyEvent.KEYCODE_VOICE_ASSIST) {
2765 if (!down) {
2766 Intent voiceIntent;
Michael Wright869a67c2014-08-26 19:33:06 -07002767 if (!keyguardOn) {
Michael Wrightdc63f7b2014-08-21 19:05:21 -07002768 voiceIntent = new Intent(RecognizerIntent.ACTION_WEB_SEARCH);
2769 } else {
Dianne Hackbornb6683c42015-06-18 17:40:33 -07002770 IDeviceIdleController dic = IDeviceIdleController.Stub.asInterface(
2771 ServiceManager.getService(Context.DEVICE_IDLE_CONTROLLER));
2772 if (dic != null) {
2773 try {
2774 dic.exitIdle("voice-search");
2775 } catch (RemoteException e) {
2776 }
2777 }
Michael Wrightdc63f7b2014-08-21 19:05:21 -07002778 voiceIntent = new Intent(RecognizerIntent.ACTION_VOICE_SEARCH_HANDS_FREE);
Michael Wright869a67c2014-08-26 19:33:06 -07002779 voiceIntent.putExtra(RecognizerIntent.EXTRA_SECURE, true);
Michael Wrightdc63f7b2014-08-21 19:05:21 -07002780 }
Bart Sears8b1c27c2015-03-18 23:51:02 +00002781 startActivityAsUser(voiceIntent, UserHandle.CURRENT_OR_SELF);
Michael Wrightdc63f7b2014-08-21 19:05:21 -07002782 }
Jeff Sharkey2991fa32012-12-05 18:06:43 -08002783 } else if (keyCode == KeyEvent.KEYCODE_SYSRQ) {
2784 if (down && repeatCount == 0) {
2785 mHandler.post(mScreenshotRunnable);
2786 }
2787 return -1;
Michael Wrightb854e242013-02-05 17:54:02 -08002788 } else if (keyCode == KeyEvent.KEYCODE_BRIGHTNESS_UP
2789 || keyCode == KeyEvent.KEYCODE_BRIGHTNESS_DOWN) {
2790 if (down) {
2791 int direction = keyCode == KeyEvent.KEYCODE_BRIGHTNESS_UP ? 1 : -1;
2792
2793 // Disable autobrightness if it's on
2794 int auto = Settings.System.getIntForUser(
2795 mContext.getContentResolver(),
2796 Settings.System.SCREEN_BRIGHTNESS_MODE,
2797 Settings.System.SCREEN_BRIGHTNESS_MODE_MANUAL,
2798 UserHandle.USER_CURRENT_OR_SELF);
2799 if (auto != 0) {
2800 Settings.System.putIntForUser(mContext.getContentResolver(),
2801 Settings.System.SCREEN_BRIGHTNESS_MODE,
2802 Settings.System.SCREEN_BRIGHTNESS_MODE_MANUAL,
2803 UserHandle.USER_CURRENT_OR_SELF);
2804 }
2805
2806 int min = mPowerManager.getMinimumScreenBrightnessSetting();
2807 int max = mPowerManager.getMaximumScreenBrightnessSetting();
2808 int step = (max - min + BRIGHTNESS_STEPS - 1) / BRIGHTNESS_STEPS * direction;
2809 int brightness = Settings.System.getIntForUser(mContext.getContentResolver(),
2810 Settings.System.SCREEN_BRIGHTNESS,
2811 mPowerManager.getDefaultScreenBrightnessSetting(),
2812 UserHandle.USER_CURRENT_OR_SELF);
2813 brightness += step;
2814 // Make sure we don't go beyond the limits.
2815 brightness = Math.min(max, brightness);
2816 brightness = Math.max(min, brightness);
2817
2818 Settings.System.putIntForUser(mContext.getContentResolver(),
2819 Settings.System.SCREEN_BRIGHTNESS, brightness,
2820 UserHandle.USER_CURRENT_OR_SELF);
Bart Sears8b1c27c2015-03-18 23:51:02 +00002821 startActivityAsUser(new Intent(Intent.ACTION_SHOW_BRIGHTNESS_DIALOG),
Alan Viverette5a399492014-07-14 16:19:38 -07002822 UserHandle.CURRENT_OR_SELF);
Michael Wrightb854e242013-02-05 17:54:02 -08002823 }
2824 return -1;
Michael Wrightce0c13a2014-07-30 10:49:21 -07002825 } else if (KeyEvent.isMetaKey(keyCode)) {
Michael Wright6a62e552014-06-03 19:19:48 -07002826 if (down) {
2827 mPendingMetaAction = true;
2828 } else if (mPendingMetaAction) {
Tim Kilbourn0e5f1102015-06-05 16:18:09 -07002829 launchAssistAction(Intent.EXTRA_ASSIST_INPUT_HINT_KEYBOARD, event.getDeviceId());
Michael Wright6a62e552014-06-03 19:19:48 -07002830 }
2831 return -1;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002832 }
Jeff Browncaab4d02010-12-09 22:13:41 -08002833
Jeff Brownc1fb48d2010-12-08 16:52:09 -08002834 // Shortcuts are invoked through Search+key, so intercept those here
Jeff Browncaab4d02010-12-09 22:13:41 -08002835 // Any printing key that is chorded with Search should be consumed
2836 // even if no shortcut was invoked. This prevents text from being
2837 // inadvertently inserted when using a keyboard that has built-in macro
2838 // shortcut keys (that emit Search+x) and some of them are not registered.
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002839 if (mSearchKeyShortcutPending) {
Jeff Browncaab4d02010-12-09 22:13:41 -08002840 final KeyCharacterMap kcm = event.getKeyCharacterMap();
2841 if (kcm.isPrintingKey(keyCode)) {
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002842 mConsumeSearchKeyUp = true;
2843 mSearchKeyShortcutPending = false;
Jeff Browncaab4d02010-12-09 22:13:41 -08002844 if (down && repeatCount == 0 && !keyguardOn) {
2845 Intent shortcutIntent = mShortcutManager.getIntent(kcm, keyCode, metaState);
2846 if (shortcutIntent != null) {
2847 shortcutIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
Jeff Brownf0a3cc52011-01-26 18:42:46 -08002848 try {
Bart Sears8b1c27c2015-03-18 23:51:02 +00002849 startActivityAsUser(shortcutIntent, UserHandle.CURRENT);
Jeff Brownf0a3cc52011-01-26 18:42:46 -08002850 } catch (ActivityNotFoundException ex) {
2851 Slog.w(TAG, "Dropping shortcut key combination because "
2852 + "the activity to which it is registered was not found: "
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002853 + "SEARCH+" + KeyEvent.keyCodeToString(keyCode), ex);
Jeff Brownf0a3cc52011-01-26 18:42:46 -08002854 }
Jeff Browncaab4d02010-12-09 22:13:41 -08002855 } else {
2856 Slog.i(TAG, "Dropping unregistered shortcut key combination: "
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002857 + "SEARCH+" + KeyEvent.keyCodeToString(keyCode));
Jeff Brown49ed71d2010-12-06 17:13:33 -08002858 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002859 }
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002860 return -1;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002861 }
2862 }
2863
Jeff Brown68b909d2011-12-07 16:36:01 -08002864 // Invoke shortcuts using Meta.
Jeff Brown602ab322012-05-16 13:33:47 -07002865 if (down && repeatCount == 0 && !keyguardOn
Jeff Brown68b909d2011-12-07 16:36:01 -08002866 && (metaState & KeyEvent.META_META_ON) != 0) {
2867 final KeyCharacterMap kcm = event.getKeyCharacterMap();
Jeff Brown602ab322012-05-16 13:33:47 -07002868 if (kcm.isPrintingKey(keyCode)) {
2869 Intent shortcutIntent = mShortcutManager.getIntent(kcm, keyCode,
2870 metaState & ~(KeyEvent.META_META_ON
2871 | KeyEvent.META_META_LEFT_ON | KeyEvent.META_META_RIGHT_ON));
2872 if (shortcutIntent != null) {
2873 shortcutIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
2874 try {
Bart Sears8b1c27c2015-03-18 23:51:02 +00002875 startActivityAsUser(shortcutIntent, UserHandle.CURRENT);
Jeff Brown602ab322012-05-16 13:33:47 -07002876 } catch (ActivityNotFoundException ex) {
2877 Slog.w(TAG, "Dropping shortcut key combination because "
2878 + "the activity to which it is registered was not found: "
2879 + "META+" + KeyEvent.keyCodeToString(keyCode), ex);
2880 }
2881 return -1;
Jeff Brown68b909d2011-12-07 16:36:01 -08002882 }
Jeff Brown68b909d2011-12-07 16:36:01 -08002883 }
2884 }
2885
Jeff Brown6651a632011-11-28 12:59:11 -08002886 // Handle application launch keys.
Jeff Brown602ab322012-05-16 13:33:47 -07002887 if (down && repeatCount == 0 && !keyguardOn) {
Jeff Brown6651a632011-11-28 12:59:11 -08002888 String category = sApplicationLaunchKeyCategories.get(keyCode);
2889 if (category != null) {
Dianne Hackbornf5b86712011-12-05 17:42:41 -08002890 Intent intent = Intent.makeMainSelectorActivity(Intent.ACTION_MAIN, category);
Jeff Brown6651a632011-11-28 12:59:11 -08002891 intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
2892 try {
Bart Sears8b1c27c2015-03-18 23:51:02 +00002893 startActivityAsUser(intent, UserHandle.CURRENT);
Jeff Brown6651a632011-11-28 12:59:11 -08002894 } catch (ActivityNotFoundException ex) {
2895 Slog.w(TAG, "Dropping application launch key because "
2896 + "the activity to which it is registered was not found: "
2897 + "keyCode=" + keyCode + ", category=" + category, ex);
2898 }
Jeff Brown68b909d2011-12-07 16:36:01 -08002899 return -1;
Jeff Brown6651a632011-11-28 12:59:11 -08002900 }
2901 }
2902
Michael Wright61c46752014-08-21 16:57:33 -07002903 // Display task switcher for ALT-TAB.
Jeff Brown68b909d2011-12-07 16:36:01 -08002904 if (down && repeatCount == 0 && keyCode == KeyEvent.KEYCODE_TAB) {
Winson Chung1e8d71b2014-05-16 17:05:22 -07002905 if (mRecentAppsHeldModifiers == 0 && !keyguardOn) {
Jeff Brown68b909d2011-12-07 16:36:01 -08002906 final int shiftlessModifiers = event.getModifiers() & ~KeyEvent.META_SHIFT_MASK;
Michael Wright61c46752014-08-21 16:57:33 -07002907 if (KeyEvent.metaStateHasModifiers(shiftlessModifiers, KeyEvent.META_ALT_ON)) {
Winson Chung1e8d71b2014-05-16 17:05:22 -07002908 mRecentAppsHeldModifiers = shiftlessModifiers;
2909 showRecentApps(true);
Jeff Brown68b909d2011-12-07 16:36:01 -08002910 return -1;
2911 }
2912 }
Winson Chung1e8d71b2014-05-16 17:05:22 -07002913 } else if (!down && mRecentAppsHeldModifiers != 0
2914 && (metaState & mRecentAppsHeldModifiers) == 0) {
2915 mRecentAppsHeldModifiers = 0;
Winson Chungcdcd4872014-08-05 18:00:13 -07002916 hideRecentApps(true, false);
Jeff Brown68b909d2011-12-07 16:36:01 -08002917 }
2918
Jeff Browncf39bdf2012-05-18 14:41:19 -07002919 // Handle keyboard language switching.
2920 if (down && repeatCount == 0
2921 && (keyCode == KeyEvent.KEYCODE_LANGUAGE_SWITCH
2922 || (keyCode == KeyEvent.KEYCODE_SPACE
2923 && (metaState & KeyEvent.META_CTRL_MASK) != 0))) {
2924 int direction = (metaState & KeyEvent.META_SHIFT_MASK) != 0 ? -1 : 1;
2925 mWindowManagerFuncs.switchKeyboardLayout(event.getDeviceId(), direction);
2926 return -1;
2927 }
2928 if (mLanguageSwitchKeyPressed && !down
2929 && (keyCode == KeyEvent.KEYCODE_LANGUAGE_SWITCH
2930 || keyCode == KeyEvent.KEYCODE_SPACE)) {
2931 mLanguageSwitchKeyPressed = false;
2932 return -1;
2933 }
2934
Jeff Brown13f00f02014-10-31 14:45:50 -07002935 if (isValidGlobalKey(keyCode)
2936 && mGlobalKeyManager.handleGlobalKey(mContext, keyCode, event)) {
Justin Kohd378ad72013-04-01 12:18:26 -07002937 return -1;
2938 }
2939
Michael Wright6a62e552014-06-03 19:19:48 -07002940 // Reserve all the META modifier combos for system behavior
Michael Wrightce0c13a2014-07-30 10:49:21 -07002941 if ((metaState & KeyEvent.META_META_ON) != 0) {
Michael Wright6a62e552014-06-03 19:19:48 -07002942 return -1;
2943 }
2944
Jeff Brown68b909d2011-12-07 16:36:01 -08002945 // Let the application handle the key.
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002946 return 0;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002947 }
2948
Jeff Brown3915bb82010-11-05 15:02:16 -07002949 /** {@inheritDoc} */
2950 @Override
Jeff Brown49ed71d2010-12-06 17:13:33 -08002951 public KeyEvent dispatchUnhandledKey(WindowState win, KeyEvent event, int policyFlags) {
Jeff Brown54875002011-04-06 15:33:01 -07002952 // Note: This method is only called if the initial down was unhandled.
Jeff Brown40013652012-05-16 21:22:36 -07002953 if (DEBUG_INPUT) {
Jeff Brown1f245102010-11-18 20:53:46 -08002954 Slog.d(TAG, "Unhandled key: win=" + win + ", action=" + event.getAction()
2955 + ", flags=" + event.getFlags()
2956 + ", keyCode=" + event.getKeyCode()
2957 + ", scanCode=" + event.getScanCode()
2958 + ", metaState=" + event.getMetaState()
2959 + ", repeatCount=" + event.getRepeatCount()
2960 + ", policyFlags=" + policyFlags);
Jeff Brown3915bb82010-11-05 15:02:16 -07002961 }
Jeff Brown49ed71d2010-12-06 17:13:33 -08002962
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002963 KeyEvent fallbackEvent = null;
Jeff Brown49ed71d2010-12-06 17:13:33 -08002964 if ((event.getFlags() & KeyEvent.FLAG_FALLBACK) == 0) {
2965 final KeyCharacterMap kcm = event.getKeyCharacterMap();
Jeff Brownc1fb48d2010-12-08 16:52:09 -08002966 final int keyCode = event.getKeyCode();
2967 final int metaState = event.getMetaState();
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002968 final boolean initialDown = event.getAction() == KeyEvent.ACTION_DOWN
2969 && event.getRepeatCount() == 0;
Jeff Brown49ed71d2010-12-06 17:13:33 -08002970
Jeff Brown54875002011-04-06 15:33:01 -07002971 // Check for fallback actions specified by the key character map.
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002972 final FallbackAction fallbackAction;
2973 if (initialDown) {
2974 fallbackAction = kcm.getFallbackAction(keyCode, metaState);
2975 } else {
2976 fallbackAction = mFallbackActions.get(keyCode);
2977 }
2978
2979 if (fallbackAction != null) {
Jeff Brown40013652012-05-16 21:22:36 -07002980 if (DEBUG_INPUT) {
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002981 Slog.d(TAG, "Fallback: keyCode=" + fallbackAction.keyCode
2982 + " metaState=" + Integer.toHexString(fallbackAction.metaState));
Jeff Brown49ed71d2010-12-06 17:13:33 -08002983 }
2984
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002985 final int flags = event.getFlags() | KeyEvent.FLAG_FALLBACK;
2986 fallbackEvent = KeyEvent.obtain(
Jeff Brown49ed71d2010-12-06 17:13:33 -08002987 event.getDownTime(), event.getEventTime(),
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002988 event.getAction(), fallbackAction.keyCode,
2989 event.getRepeatCount(), fallbackAction.metaState,
Jeff Brown49ed71d2010-12-06 17:13:33 -08002990 event.getDeviceId(), event.getScanCode(),
2991 flags, event.getSource(), null);
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002992
2993 if (!interceptFallback(win, fallbackEvent, policyFlags)) {
2994 fallbackEvent.recycle();
2995 fallbackEvent = null;
Jeff Brown49ed71d2010-12-06 17:13:33 -08002996 }
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002997
2998 if (initialDown) {
2999 mFallbackActions.put(keyCode, fallbackAction);
3000 } else if (event.getAction() == KeyEvent.ACTION_UP) {
3001 mFallbackActions.remove(keyCode);
3002 fallbackAction.recycle();
3003 }
Jeff Brown49ed71d2010-12-06 17:13:33 -08003004 }
3005 }
3006
Jeff Brown40013652012-05-16 21:22:36 -07003007 if (DEBUG_INPUT) {
Jeff Brownfd23e3e2012-05-09 13:34:28 -07003008 if (fallbackEvent == null) {
3009 Slog.d(TAG, "No fallback.");
3010 } else {
3011 Slog.d(TAG, "Performing fallback: " + fallbackEvent);
3012 }
Jeff Brown49ed71d2010-12-06 17:13:33 -08003013 }
Jeff Brownfd23e3e2012-05-09 13:34:28 -07003014 return fallbackEvent;
Jeff Brown3915bb82010-11-05 15:02:16 -07003015 }
3016
Jeff Brownfd23e3e2012-05-09 13:34:28 -07003017 private boolean interceptFallback(WindowState win, KeyEvent fallbackEvent, int policyFlags) {
Jeff Brown037c33e2014-04-09 00:31:55 -07003018 int actions = interceptKeyBeforeQueueing(fallbackEvent, policyFlags);
Jeff Brownfd23e3e2012-05-09 13:34:28 -07003019 if ((actions & ACTION_PASS_TO_USER) != 0) {
3020 long delayMillis = interceptKeyBeforeDispatching(
3021 win, fallbackEvent, policyFlags);
3022 if (delayMillis == 0) {
3023 return true;
3024 }
3025 }
3026 return false;
Jeff Brown6f2fba42011-02-19 01:08:02 -08003027 }
3028
Jeff Brownde7a8ea2012-06-13 18:28:57 -07003029 private void launchAssistLongPressAction() {
3030 performHapticFeedbackLw(null, HapticFeedbackConstants.LONG_PRESS, false);
3031 sendCloseSystemWindows(SYSTEM_DIALOG_REASON_ASSIST);
3032
3033 // launch the search activity
3034 Intent intent = new Intent(Intent.ACTION_SEARCH_LONG_PRESS);
3035 intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
3036 try {
RoboErik8a2cfc32014-05-16 11:19:38 -07003037 // TODO: This only stops the factory-installed search manager.
Jim Miller45308b12012-06-18 19:23:39 -07003038 // Need to formalize an API to handle others
Jeff Brownde7a8ea2012-06-13 18:28:57 -07003039 SearchManager searchManager = getSearchManager();
3040 if (searchManager != null) {
3041 searchManager.stopSearch();
3042 }
Bart Sears8b1c27c2015-03-18 23:51:02 +00003043 startActivityAsUser(intent, UserHandle.CURRENT);
Jeff Brownde7a8ea2012-06-13 18:28:57 -07003044 } catch (ActivityNotFoundException e) {
3045 Slog.w(TAG, "No activity to handle assist long press action.", e);
3046 }
3047 }
3048
3049 private void launchAssistAction() {
Tim Kilbourn0e5f1102015-06-05 16:18:09 -07003050 launchAssistAction(null, Integer.MIN_VALUE);
Michael Wright8ab940a2014-09-01 11:01:27 -07003051 }
3052
3053 private void launchAssistAction(String hint) {
Tim Kilbourn0e5f1102015-06-05 16:18:09 -07003054 launchAssistAction(hint, Integer.MIN_VALUE);
3055 }
3056
3057 private void launchAssistAction(String hint, int deviceId) {
Jeff Brownde7a8ea2012-06-13 18:28:57 -07003058 sendCloseSystemWindows(SYSTEM_DIALOG_REASON_ASSIST);
Tim Kilbourn0e5f1102015-06-05 16:18:09 -07003059 Bundle args = null;
3060 if (deviceId > Integer.MIN_VALUE) {
3061 args = new Bundle();
3062 args.putInt(Intent.EXTRA_ASSIST_INPUT_DEVICE_ID, deviceId);
Jeff Brownde7a8ea2012-06-13 18:28:57 -07003063 }
Tim Kilbourn0e5f1102015-06-05 16:18:09 -07003064 ((SearchManager) mContext.getSystemService(Context.SEARCH_SERVICE))
3065 .launchAssistAction(hint, UserHandle.myUserId(), args);
Jeff Brownde7a8ea2012-06-13 18:28:57 -07003066 }
3067
Bart Sears8b1c27c2015-03-18 23:51:02 +00003068 private void startActivityAsUser(Intent intent, UserHandle handle) {
3069 if (isUserSetupComplete()) {
3070 mContext.startActivityAsUser(intent, handle);
3071 } else {
3072 Slog.i(TAG, "Not starting activity because user setup is in progress: " + intent);
3073 }
3074 }
3075
Jeff Brownde7a8ea2012-06-13 18:28:57 -07003076 private SearchManager getSearchManager() {
3077 if (mSearchManager == null) {
3078 mSearchManager = (SearchManager) mContext.getSystemService(Context.SEARCH_SERVICE);
3079 }
3080 return mSearchManager;
3081 }
3082
Jeff Browncaca8812013-05-09 13:34:33 -07003083 private void preloadRecentApps() {
3084 mPreloadedRecentApps = true;
3085 try {
3086 IStatusBarService statusbar = getStatusBarService();
3087 if (statusbar != null) {
3088 statusbar.preloadRecentApps();
3089 }
3090 } catch (RemoteException e) {
3091 Slog.e(TAG, "RemoteException when preloading recent apps", e);
3092 // re-acquire status bar service next time it is needed.
3093 mStatusBarService = null;
3094 }
3095 }
3096
3097 private void cancelPreloadRecentApps() {
3098 if (mPreloadedRecentApps) {
3099 mPreloadedRecentApps = false;
3100 try {
3101 IStatusBarService statusbar = getStatusBarService();
3102 if (statusbar != null) {
3103 statusbar.cancelPreloadRecentApps();
3104 }
3105 } catch (RemoteException e) {
Winson Chung1e8d71b2014-05-16 17:05:22 -07003106 Slog.e(TAG, "RemoteException when cancelling recent apps preload", e);
Jeff Browncaca8812013-05-09 13:34:33 -07003107 // re-acquire status bar service next time it is needed.
3108 mStatusBarService = null;
3109 }
3110 }
3111 }
3112
3113 private void toggleRecentApps() {
3114 mPreloadedRecentApps = false; // preloading no longer needs to be canceled
Jeff Browncaca8812013-05-09 13:34:33 -07003115 try {
3116 IStatusBarService statusbar = getStatusBarService();
3117 if (statusbar != null) {
3118 statusbar.toggleRecentApps();
3119 }
3120 } catch (RemoteException e) {
Winson Chung1e8d71b2014-05-16 17:05:22 -07003121 Slog.e(TAG, "RemoteException when toggling recent apps", e);
3122 // re-acquire status bar service next time it is needed.
3123 mStatusBarService = null;
3124 }
3125 }
3126
Craig Mautner84984fa2014-06-19 11:19:20 -07003127 @Override
3128 public void showRecentApps() {
3129 mHandler.removeMessages(MSG_DISPATCH_SHOW_RECENTS);
3130 mHandler.sendEmptyMessage(MSG_DISPATCH_SHOW_RECENTS);
3131 }
3132
Winson Chung1e8d71b2014-05-16 17:05:22 -07003133 private void showRecentApps(boolean triggeredFromAltTab) {
3134 mPreloadedRecentApps = false; // preloading no longer needs to be canceled
3135 try {
3136 IStatusBarService statusbar = getStatusBarService();
3137 if (statusbar != null) {
3138 statusbar.showRecentApps(triggeredFromAltTab);
3139 }
3140 } catch (RemoteException e) {
Jeff Browncaca8812013-05-09 13:34:33 -07003141 Slog.e(TAG, "RemoteException when showing recent apps", e);
3142 // re-acquire status bar service next time it is needed.
3143 mStatusBarService = null;
3144 }
3145 }
3146
Winson Chungcdcd4872014-08-05 18:00:13 -07003147 private void hideRecentApps(boolean triggeredFromAltTab, boolean triggeredFromHome) {
Winson Chung1e8d71b2014-05-16 17:05:22 -07003148 mPreloadedRecentApps = false; // preloading no longer needs to be canceled
3149 try {
3150 IStatusBarService statusbar = getStatusBarService();
3151 if (statusbar != null) {
Winson Chungcdcd4872014-08-05 18:00:13 -07003152 statusbar.hideRecentApps(triggeredFromAltTab, triggeredFromHome);
Winson Chung1e8d71b2014-05-16 17:05:22 -07003153 }
3154 } catch (RemoteException e) {
3155 Slog.e(TAG, "RemoteException when closing recent apps", e);
3156 // re-acquire status bar service next time it is needed.
3157 mStatusBarService = null;
3158 }
3159 }
3160
Filip Gruszczynskia483a1d2015-03-17 19:06:58 +00003161 void launchHomeFromHotKey() {
Bryce Lee662ed802015-04-10 20:11:39 +00003162 launchHomeFromHotKey(true /* awakenFromDreams */, true /*respectKeyguard*/);
Filip Gruszczynskia483a1d2015-03-17 19:06:58 +00003163 }
3164
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003165 /**
3166 * A home key -> launch home action was detected. Take the appropriate action
3167 * given the situation with the keyguard.
3168 */
Bryce Lee662ed802015-04-10 20:11:39 +00003169 void launchHomeFromHotKey(final boolean awakenFromDreams, final boolean respectKeyguard) {
3170 if (respectKeyguard) {
3171 if (isKeyguardShowingAndNotOccluded()) {
3172 // don't launch home if keyguard showing
3173 return;
3174 }
3175
3176 if (!mHideLockScreen && mKeyguardDelegate.isInputRestricted()) {
3177 // when in keyguard restricted mode, must first verify unlock
3178 // before launching home
3179 mKeyguardDelegate.verifyUnlock(new OnKeyguardExitResult() {
3180 @Override
3181 public void onKeyguardExitResult(boolean success) {
3182 if (success) {
3183 try {
3184 ActivityManagerNative.getDefault().stopAppSwitches();
3185 } catch (RemoteException e) {
3186 }
3187 sendCloseSystemWindows(SYSTEM_DIALOG_REASON_HOME_KEY);
3188 startDockOrHome(true /*fromHomeKey*/, awakenFromDreams);
Dianne Hackborn256dd3b2009-05-19 18:51:21 -07003189 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003190 }
Bryce Lee662ed802015-04-10 20:11:39 +00003191 });
3192 return;
3193 }
3194 }
3195
3196 // no keyguard stuff to worry about, just launch home!
3197 try {
3198 ActivityManagerNative.getDefault().stopAppSwitches();
3199 } catch (RemoteException e) {
3200 }
3201 if (mRecentsVisible) {
3202 // Hide Recents and notify it to launch Home
3203 if (awakenFromDreams) {
3204 awakenDreams();
3205 }
3206 sendCloseSystemWindows(SYSTEM_DIALOG_REASON_HOME_KEY);
3207 hideRecentApps(false, true);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003208 } else {
Bryce Lee662ed802015-04-10 20:11:39 +00003209 // Otherwise, just launch Home
3210 sendCloseSystemWindows(SYSTEM_DIALOG_REASON_HOME_KEY);
3211 startDockOrHome(true /*fromHomeKey*/, awakenFromDreams);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003212 }
3213 }
3214
John Spurlock04db1762013-05-13 12:46:41 -04003215 private final Runnable mClearHideNavigationFlag = new Runnable() {
3216 @Override
3217 public void run() {
3218 synchronized (mWindowManagerFuncs.getWindowManagerLock()) {
3219 // Clear flags.
3220 mForceClearedSystemUiFlags &=
3221 ~View.SYSTEM_UI_FLAG_HIDE_NAVIGATION;
3222 }
3223 mWindowManagerFuncs.reevaluateStatusBarVisibility();
Dianne Hackborne26ab702011-10-16 13:21:33 -07003224 }
3225 };
3226
3227 /**
3228 * Input handler used while nav bar is hidden. Captures any touch on the screen,
3229 * to determine when the nav bar should be shown and prevent applications from
3230 * receiving those touches.
3231 */
Jeff Brown32cbc38552011-12-01 14:01:49 -08003232 final class HideNavInputEventReceiver extends InputEventReceiver {
3233 public HideNavInputEventReceiver(InputChannel inputChannel, Looper looper) {
3234 super(inputChannel, looper);
3235 }
3236
Dianne Hackborndf89e652011-10-06 22:35:11 -07003237 @Override
Jeff Brown32cbc38552011-12-01 14:01:49 -08003238 public void onInputEvent(InputEvent event) {
Dianne Hackborndf89e652011-10-06 22:35:11 -07003239 boolean handled = false;
3240 try {
Jeff Brown4952dfd2011-11-30 19:23:22 -08003241 if (event instanceof MotionEvent
3242 && (event.getSource() & InputDevice.SOURCE_CLASS_POINTER) != 0) {
3243 final MotionEvent motionEvent = (MotionEvent)event;
3244 if (motionEvent.getAction() == MotionEvent.ACTION_DOWN) {
Dianne Hackborndf89e652011-10-06 22:35:11 -07003245 // When the user taps down, we re-show the nav bar.
3246 boolean changed = false;
John Spurlock04db1762013-05-13 12:46:41 -04003247 synchronized (mWindowManagerFuncs.getWindowManagerLock()) {
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07003248 // Any user activity always causes us to show the
3249 // navigation controls, if they had been hidden.
3250 // We also clear the low profile and only content
3251 // flags so that tapping on the screen will atomically
3252 // restore all currently hidden screen decorations.
3253 int newVal = mResettingSystemUiFlags |
3254 View.SYSTEM_UI_FLAG_HIDE_NAVIGATION |
3255 View.SYSTEM_UI_FLAG_LOW_PROFILE |
3256 View.SYSTEM_UI_FLAG_FULLSCREEN;
Dianne Hackborne26ab702011-10-16 13:21:33 -07003257 if (mResettingSystemUiFlags != newVal) {
3258 mResettingSystemUiFlags = newVal;
Dianne Hackborndf89e652011-10-06 22:35:11 -07003259 changed = true;
3260 }
Dianne Hackborne26ab702011-10-16 13:21:33 -07003261 // We don't allow the system's nav bar to be hidden
3262 // again for 1 second, to prevent applications from
3263 // spamming us and keeping it from being shown.
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07003264 newVal = mForceClearedSystemUiFlags |
3265 View.SYSTEM_UI_FLAG_HIDE_NAVIGATION;
Dianne Hackborne26ab702011-10-16 13:21:33 -07003266 if (mForceClearedSystemUiFlags != newVal) {
3267 mForceClearedSystemUiFlags = newVal;
3268 changed = true;
John Spurlock04db1762013-05-13 12:46:41 -04003269 mHandler.postDelayed(mClearHideNavigationFlag, 1000);
Dianne Hackborne26ab702011-10-16 13:21:33 -07003270 }
Dianne Hackborndf89e652011-10-06 22:35:11 -07003271 }
3272 if (changed) {
3273 mWindowManagerFuncs.reevaluateStatusBarVisibility();
3274 }
3275 }
3276 }
3277 } finally {
Jeff Brown32cbc38552011-12-01 14:01:49 -08003278 finishInputEvent(event, handled);
Dianne Hackborndf89e652011-10-06 22:35:11 -07003279 }
3280 }
Jeff Brown32cbc38552011-12-01 14:01:49 -08003281 }
3282 final InputEventReceiver.Factory mHideNavInputEventReceiverFactory =
3283 new InputEventReceiver.Factory() {
3284 @Override
3285 public InputEventReceiver createInputEventReceiver(
3286 InputChannel inputChannel, Looper looper) {
3287 return new HideNavInputEventReceiver(inputChannel, looper);
3288 }
Dianne Hackborndf89e652011-10-06 22:35:11 -07003289 };
3290
3291 @Override
3292 public int adjustSystemUiVisibilityLw(int visibility) {
John Spurlock5b9145b2013-08-20 15:13:47 -04003293 mStatusBarController.adjustSystemUiVisibilityLw(mLastSystemUiFlags, visibility);
3294 mNavigationBarController.adjustSystemUiVisibilityLw(mLastSystemUiFlags, visibility);
Winson Chungd42a6cf2014-06-03 16:24:04 -07003295 mRecentsVisible = (visibility & View.RECENT_APPS_VISIBLE) > 0;
John Spurlock27735a42013-08-14 17:57:38 -04003296
Dianne Hackborndf89e652011-10-06 22:35:11 -07003297 // Reset any bits in mForceClearingStatusBarVisibility that
3298 // are now clear.
Dianne Hackborne26ab702011-10-16 13:21:33 -07003299 mResettingSystemUiFlags &= visibility;
Dianne Hackborndf89e652011-10-06 22:35:11 -07003300 // Clear any bits in the new visibility that are currently being
3301 // force cleared, before reporting it.
Dianne Hackborne26ab702011-10-16 13:21:33 -07003302 return visibility & ~mResettingSystemUiFlags
3303 & ~mForceClearedSystemUiFlags;
Dianne Hackborndf89e652011-10-06 22:35:11 -07003304 }
3305
Craig Mautner69b08182012-09-05 13:07:13 -07003306 @Override
Adrian Roos37d7a682014-11-06 18:15:16 +01003307 public void getInsetHintLw(WindowManager.LayoutParams attrs, Rect outContentInsets,
3308 Rect outStableInsets) {
John Spurlockc6d1c602014-01-17 15:22:06 -05003309 final int fl = PolicyControl.getWindowFlags(null, attrs);
John Spurlock1db8b682014-02-18 11:18:59 -05003310 final int sysuiVis = PolicyControl.getSystemUiVisibility(null, attrs);
3311 final int systemUiVisibility = (sysuiVis | attrs.subtreeSystemUiVisibility);
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07003312
Dianne Hackborn5b5cc4d2012-05-16 13:15:00 -07003313 if ((fl & (FLAG_LAYOUT_IN_SCREEN | FLAG_LAYOUT_INSET_DECOR))
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003314 == (FLAG_LAYOUT_IN_SCREEN | FLAG_LAYOUT_INSET_DECOR)) {
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07003315 int availRight, availBottom;
Alan Viverette5a0f4ec2013-10-07 15:10:29 -07003316 if (canHideNavigationBar() &&
Dianne Hackborn5b5cc4d2012-05-16 13:15:00 -07003317 (systemUiVisibility & View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION) != 0) {
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07003318 availRight = mUnrestrictedScreenLeft + mUnrestrictedScreenWidth;
3319 availBottom = mUnrestrictedScreenTop + mUnrestrictedScreenHeight;
3320 } else {
3321 availRight = mRestrictedScreenLeft + mRestrictedScreenWidth;
3322 availBottom = mRestrictedScreenTop + mRestrictedScreenHeight;
3323 }
Dianne Hackborn5b5cc4d2012-05-16 13:15:00 -07003324 if ((systemUiVisibility & View.SYSTEM_UI_FLAG_LAYOUT_STABLE) != 0) {
3325 if ((fl & FLAG_FULLSCREEN) != 0) {
Adrian Roos37d7a682014-11-06 18:15:16 +01003326 outContentInsets.set(mStableFullscreenLeft, mStableFullscreenTop,
Dianne Hackborn5b5cc4d2012-05-16 13:15:00 -07003327 availRight - mStableFullscreenRight,
3328 availBottom - mStableFullscreenBottom);
3329 } else {
Adrian Roos37d7a682014-11-06 18:15:16 +01003330 outContentInsets.set(mStableLeft, mStableTop,
Dianne Hackborn5b5cc4d2012-05-16 13:15:00 -07003331 availRight - mStableRight, availBottom - mStableBottom);
3332 }
Dianne Hackbornc652de82013-02-15 16:32:56 -08003333 } else if ((fl & FLAG_FULLSCREEN) != 0 || (fl & FLAG_LAYOUT_IN_OVERSCAN) != 0) {
Adrian Roos37d7a682014-11-06 18:15:16 +01003334 outContentInsets.setEmpty();
Dianne Hackborn5b5cc4d2012-05-16 13:15:00 -07003335 } else if ((systemUiVisibility & (View.SYSTEM_UI_FLAG_FULLSCREEN
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07003336 | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN)) == 0) {
Adrian Roos37d7a682014-11-06 18:15:16 +01003337 outContentInsets.set(mCurLeft, mCurTop,
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07003338 availRight - mCurRight, availBottom - mCurBottom);
3339 } else {
Adrian Roos37d7a682014-11-06 18:15:16 +01003340 outContentInsets.set(mCurLeft, mCurTop,
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07003341 availRight - mCurRight, availBottom - mCurBottom);
3342 }
Adrian Roos37d7a682014-11-06 18:15:16 +01003343
3344 outStableInsets.set(mStableLeft, mStableTop,
3345 availRight - mStableRight, availBottom - mStableBottom);
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07003346 return;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003347 }
Adrian Roos37d7a682014-11-06 18:15:16 +01003348 outContentInsets.setEmpty();
3349 outStableInsets.setEmpty();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003350 }
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07003351
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003352 /** {@inheritDoc} */
Craig Mautner69b08182012-09-05 13:07:13 -07003353 @Override
3354 public void beginLayoutLw(boolean isDefaultDisplay, int displayWidth, int displayHeight,
3355 int displayRotation) {
Dianne Hackbornc652de82013-02-15 16:32:56 -08003356 final int overscanLeft, overscanTop, overscanRight, overscanBottom;
3357 if (isDefaultDisplay) {
3358 switch (displayRotation) {
3359 case Surface.ROTATION_90:
3360 overscanLeft = mOverscanTop;
3361 overscanTop = mOverscanRight;
3362 overscanRight = mOverscanBottom;
3363 overscanBottom = mOverscanLeft;
3364 break;
3365 case Surface.ROTATION_180:
3366 overscanLeft = mOverscanRight;
3367 overscanTop = mOverscanBottom;
3368 overscanRight = mOverscanLeft;
3369 overscanBottom = mOverscanTop;
3370 break;
3371 case Surface.ROTATION_270:
3372 overscanLeft = mOverscanBottom;
3373 overscanTop = mOverscanLeft;
3374 overscanRight = mOverscanTop;
3375 overscanBottom = mOverscanRight;
3376 break;
3377 default:
3378 overscanLeft = mOverscanLeft;
3379 overscanTop = mOverscanTop;
3380 overscanRight = mOverscanRight;
3381 overscanBottom = mOverscanBottom;
3382 break;
3383 }
3384 } else {
3385 overscanLeft = 0;
3386 overscanTop = 0;
3387 overscanRight = 0;
3388 overscanBottom = 0;
3389 }
Dianne Hackborn313440842013-02-19 19:22:59 -08003390 mOverscanScreenLeft = mRestrictedOverscanScreenLeft = 0;
3391 mOverscanScreenTop = mRestrictedOverscanScreenTop = 0;
3392 mOverscanScreenWidth = mRestrictedOverscanScreenWidth = displayWidth;
3393 mOverscanScreenHeight = mRestrictedOverscanScreenHeight = displayHeight;
Dianne Hackbornc652de82013-02-15 16:32:56 -08003394 mSystemLeft = 0;
3395 mSystemTop = 0;
3396 mSystemRight = displayWidth;
3397 mSystemBottom = displayHeight;
3398 mUnrestrictedScreenLeft = overscanLeft;
3399 mUnrestrictedScreenTop = overscanTop;
3400 mUnrestrictedScreenWidth = displayWidth - overscanLeft - overscanRight;
3401 mUnrestrictedScreenHeight = displayHeight - overscanTop - overscanBottom;
3402 mRestrictedScreenLeft = mUnrestrictedScreenLeft;
3403 mRestrictedScreenTop = mUnrestrictedScreenTop;
John Spurlockad3e6cb2013-04-30 08:47:43 -04003404 mRestrictedScreenWidth = mSystemGestures.screenWidth = mUnrestrictedScreenWidth;
3405 mRestrictedScreenHeight = mSystemGestures.screenHeight = mUnrestrictedScreenHeight;
Dianne Hackborne30e02f2014-05-27 18:24:45 -07003406 mDockLeft = mContentLeft = mVoiceContentLeft = mStableLeft = mStableFullscreenLeft
Dianne Hackbornc652de82013-02-15 16:32:56 -08003407 = mCurLeft = mUnrestrictedScreenLeft;
Dianne Hackborne30e02f2014-05-27 18:24:45 -07003408 mDockTop = mContentTop = mVoiceContentTop = mStableTop = mStableFullscreenTop
Dianne Hackbornc652de82013-02-15 16:32:56 -08003409 = mCurTop = mUnrestrictedScreenTop;
Dianne Hackborne30e02f2014-05-27 18:24:45 -07003410 mDockRight = mContentRight = mVoiceContentRight = mStableRight = mStableFullscreenRight
Dianne Hackbornc652de82013-02-15 16:32:56 -08003411 = mCurRight = displayWidth - overscanRight;
Dianne Hackborne30e02f2014-05-27 18:24:45 -07003412 mDockBottom = mContentBottom = mVoiceContentBottom = mStableBottom = mStableFullscreenBottom
Dianne Hackbornc652de82013-02-15 16:32:56 -08003413 = mCurBottom = displayHeight - overscanBottom;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003414 mDockLayer = 0x10000000;
Dianne Hackborn5c58de32012-04-28 19:52:37 -07003415 mStatusBarLayer = -1;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003416
Daniel Sandler8956dbb2011-04-22 07:55:02 -04003417 // start with the current dock rect, which will be (0,0,displayWidth,displayHeight)
3418 final Rect pf = mTmpParentFrame;
3419 final Rect df = mTmpDisplayFrame;
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003420 final Rect of = mTmpOverscanFrame;
Daniel Sandler8956dbb2011-04-22 07:55:02 -04003421 final Rect vf = mTmpVisibleFrame;
John Spurlock46646232013-09-30 22:32:42 -04003422 final Rect dcf = mTmpDecorFrame;
Filip Gruszczynski2217f612015-05-26 11:32:08 -07003423 final Rect osf = mTmpOutsetFrame;
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003424 pf.left = df.left = of.left = vf.left = mDockLeft;
3425 pf.top = df.top = of.top = vf.top = mDockTop;
3426 pf.right = df.right = of.right = vf.right = mDockRight;
3427 pf.bottom = df.bottom = of.bottom = vf.bottom = mDockBottom;
John Spurlock46646232013-09-30 22:32:42 -04003428 dcf.setEmpty(); // Decor frame N/A for system bars.
Daniel Sandler8956dbb2011-04-22 07:55:02 -04003429
Craig Mautner69b08182012-09-05 13:07:13 -07003430 if (isDefaultDisplay) {
3431 // For purposes of putting out fake window up to steal focus, we will
3432 // drive nav being hidden only by whether it is requested.
John Spurlocke1f366f2013-08-05 12:22:40 -04003433 final int sysui = mLastSystemUiFlags;
3434 boolean navVisible = (sysui & View.SYSTEM_UI_FLAG_HIDE_NAVIGATION) == 0;
Adrian Roosea562512014-05-05 13:33:03 +02003435 boolean navTranslucent = (sysui
3436 & (View.NAVIGATION_BAR_TRANSLUCENT | View.SYSTEM_UI_TRANSPARENT)) != 0;
John Spurlockf1a36642013-10-12 17:50:42 -04003437 boolean immersive = (sysui & View.SYSTEM_UI_FLAG_IMMERSIVE) != 0;
3438 boolean immersiveSticky = (sysui & View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY) != 0;
3439 boolean navAllowedHidden = immersive || immersiveSticky;
3440 navTranslucent &= !immersiveSticky; // transient trumps translucent
Adrian Roos4fb3ee32014-08-22 19:29:09 +02003441 boolean isKeyguardShowing = isStatusBarKeyguard() && !mHideLockScreen;
3442 if (!isKeyguardShowing) {
3443 navTranslucent &= areTranslucentBarsAllowed();
3444 }
Dianne Hackborne26ab702011-10-16 13:21:33 -07003445
Craig Mautner69b08182012-09-05 13:07:13 -07003446 // When the navigation bar isn't visible, we put up a fake
3447 // input window to catch all touch events. This way we can
3448 // detect when the user presses anywhere to bring back the nav
3449 // bar and ensure the application doesn't see the event.
John Spurlockf1a36642013-10-12 17:50:42 -04003450 if (navVisible || navAllowedHidden) {
Selim Cinekf83e8242015-05-19 18:08:14 -07003451 if (mInputConsumer != null) {
3452 mInputConsumer.dismiss();
3453 mInputConsumer = null;
Craig Mautner69b08182012-09-05 13:07:13 -07003454 }
Selim Cinekf83e8242015-05-19 18:08:14 -07003455 } else if (mInputConsumer == null) {
3456 mInputConsumer = mWindowManagerFuncs.addInputConsumer(mHandler.getLooper(),
3457 mHideNavInputEventReceiverFactory);
Dianne Hackborne26ab702011-10-16 13:21:33 -07003458 }
Dianne Hackborne26ab702011-10-16 13:21:33 -07003459
Craig Mautner69b08182012-09-05 13:07:13 -07003460 // For purposes of positioning and showing the nav bar, if we have
3461 // decided that it can't be hidden (because of the screen aspect ratio),
3462 // then take that into account.
Alan Viverette5a0f4ec2013-10-07 15:10:29 -07003463 navVisible |= !canHideNavigationBar();
Dianne Hackbornf87d1962012-04-04 12:48:24 -07003464
John Spurlockad3e6cb2013-04-30 08:47:43 -04003465 boolean updateSysUiVisibility = false;
Craig Mautner69b08182012-09-05 13:07:13 -07003466 if (mNavigationBar != null) {
John Spurlock27735a42013-08-14 17:57:38 -04003467 boolean transientNavBarShowing = mNavigationBarController.isTransientShowing();
Craig Mautner69b08182012-09-05 13:07:13 -07003468 // Force the navigation bar to its appropriate place and
3469 // size. We need to do this directly, instead of relying on
3470 // it to bubble up from the nav bar, because this needs to
3471 // change atomically with screen rotations.
3472 mNavigationBarOnBottom = (!mNavigationBarCanMove || displayWidth < displayHeight);
3473 if (mNavigationBarOnBottom) {
3474 // It's a system nav bar or a portrait screen; nav bar goes on bottom.
Dianne Hackbornc652de82013-02-15 16:32:56 -08003475 int top = displayHeight - overscanBottom
3476 - mNavigationBarHeightForRotation[displayRotation];
3477 mTmpNavigationFrame.set(0, top, displayWidth, displayHeight - overscanBottom);
Craig Mautner69b08182012-09-05 13:07:13 -07003478 mStableBottom = mStableFullscreenBottom = mTmpNavigationFrame.top;
John Spurlockf95b89a2013-10-10 22:10:42 -04003479 if (transientNavBarShowing) {
John Spurlock27735a42013-08-14 17:57:38 -04003480 mNavigationBarController.setBarShowingLw(true);
John Spurlockad3e6cb2013-04-30 08:47:43 -04003481 } else if (navVisible) {
John Spurlock27735a42013-08-14 17:57:38 -04003482 mNavigationBarController.setBarShowingLw(true);
Craig Mautner69b08182012-09-05 13:07:13 -07003483 mDockBottom = mTmpNavigationFrame.top;
Dianne Hackborn313440842013-02-19 19:22:59 -08003484 mRestrictedScreenHeight = mDockBottom - mRestrictedScreenTop;
3485 mRestrictedOverscanScreenHeight = mDockBottom - mRestrictedOverscanScreenTop;
Craig Mautner69b08182012-09-05 13:07:13 -07003486 } else {
3487 // We currently want to hide the navigation UI.
John Spurlock27735a42013-08-14 17:57:38 -04003488 mNavigationBarController.setBarShowingLw(false);
Craig Mautner69b08182012-09-05 13:07:13 -07003489 }
John Spurlockc6d1c602014-01-17 15:22:06 -05003490 if (navVisible && !navTranslucent && !navAllowedHidden
3491 && !mNavigationBar.isAnimatingLw()
John Spurlockbd957402013-10-03 11:38:39 -04003492 && !mNavigationBarController.wasRecentlyTranslucent()) {
John Spurlocke1f366f2013-08-05 12:22:40 -04003493 // If the opaque nav bar is currently requested to be visible,
Craig Mautner69b08182012-09-05 13:07:13 -07003494 // and not in the process of animating on or off, then
3495 // we can tell the app that it is covered by it.
3496 mSystemBottom = mTmpNavigationFrame.top;
3497 }
Dianne Hackbornf87d1962012-04-04 12:48:24 -07003498 } else {
Craig Mautner69b08182012-09-05 13:07:13 -07003499 // Landscape screen; nav bar goes to the right.
Dianne Hackbornc652de82013-02-15 16:32:56 -08003500 int left = displayWidth - overscanRight
3501 - mNavigationBarWidthForRotation[displayRotation];
3502 mTmpNavigationFrame.set(left, 0, displayWidth - overscanRight, displayHeight);
Craig Mautner69b08182012-09-05 13:07:13 -07003503 mStableRight = mStableFullscreenRight = mTmpNavigationFrame.left;
John Spurlockf95b89a2013-10-10 22:10:42 -04003504 if (transientNavBarShowing) {
John Spurlock27735a42013-08-14 17:57:38 -04003505 mNavigationBarController.setBarShowingLw(true);
John Spurlockad3e6cb2013-04-30 08:47:43 -04003506 } else if (navVisible) {
John Spurlock27735a42013-08-14 17:57:38 -04003507 mNavigationBarController.setBarShowingLw(true);
Craig Mautner69b08182012-09-05 13:07:13 -07003508 mDockRight = mTmpNavigationFrame.left;
Dianne Hackborn313440842013-02-19 19:22:59 -08003509 mRestrictedScreenWidth = mDockRight - mRestrictedScreenLeft;
3510 mRestrictedOverscanScreenWidth = mDockRight - mRestrictedOverscanScreenLeft;
Craig Mautner69b08182012-09-05 13:07:13 -07003511 } else {
3512 // We currently want to hide the navigation UI.
John Spurlock27735a42013-08-14 17:57:38 -04003513 mNavigationBarController.setBarShowingLw(false);
Craig Mautner69b08182012-09-05 13:07:13 -07003514 }
John Spurlockbd957402013-10-03 11:38:39 -04003515 if (navVisible && !navTranslucent && !mNavigationBar.isAnimatingLw()
3516 && !mNavigationBarController.wasRecentlyTranslucent()) {
Craig Mautner69b08182012-09-05 13:07:13 -07003517 // If the nav bar is currently requested to be visible,
3518 // and not in the process of animating on or off, then
3519 // we can tell the app that it is covered by it.
3520 mSystemRight = mTmpNavigationFrame.left;
3521 }
Dianne Hackbornf87d1962012-04-04 12:48:24 -07003522 }
Craig Mautner69b08182012-09-05 13:07:13 -07003523 // Make sure the content and current rectangles are updated to
3524 // account for the restrictions from the navigation bar.
Dianne Hackborne30e02f2014-05-27 18:24:45 -07003525 mContentTop = mVoiceContentTop = mCurTop = mDockTop;
3526 mContentBottom = mVoiceContentBottom = mCurBottom = mDockBottom;
3527 mContentLeft = mVoiceContentLeft = mCurLeft = mDockLeft;
3528 mContentRight = mVoiceContentRight = mCurRight = mDockRight;
Craig Mautner69b08182012-09-05 13:07:13 -07003529 mStatusBarLayer = mNavigationBar.getSurfaceLayer();
3530 // And compute the final frame.
3531 mNavigationBar.computeFrameLw(mTmpNavigationFrame, mTmpNavigationFrame,
Adrian Roosfa104232014-06-20 16:10:14 -07003532 mTmpNavigationFrame, mTmpNavigationFrame, mTmpNavigationFrame, dcf,
Filip Gruszczynski2217f612015-05-26 11:32:08 -07003533 mTmpNavigationFrame, mTmpNavigationFrame);
Craig Mautnereda67292013-04-28 13:50:14 -07003534 if (DEBUG_LAYOUT) Slog.i(TAG, "mNavigationBar frame: " + mTmpNavigationFrame);
John Spurlock27735a42013-08-14 17:57:38 -04003535 if (mNavigationBarController.checkHiddenLw()) {
John Spurlockad3e6cb2013-04-30 08:47:43 -04003536 updateSysUiVisibility = true;
3537 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003538 }
Craig Mautnereda67292013-04-28 13:50:14 -07003539 if (DEBUG_LAYOUT) Slog.i(TAG, String.format("mDock rect: (%d,%d - %d,%d)",
Craig Mautner69b08182012-09-05 13:07:13 -07003540 mDockLeft, mDockTop, mDockRight, mDockBottom));
3541
3542 // decide where the status bar goes ahead of time
3543 if (mStatusBar != null) {
3544 // apply any navigation bar insets
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003545 pf.left = df.left = of.left = mUnrestrictedScreenLeft;
3546 pf.top = df.top = of.top = mUnrestrictedScreenTop;
3547 pf.right = df.right = of.right = mUnrestrictedScreenWidth + mUnrestrictedScreenLeft;
3548 pf.bottom = df.bottom = of.bottom = mUnrestrictedScreenHeight
3549 + mUnrestrictedScreenTop;
Craig Mautner69b08182012-09-05 13:07:13 -07003550 vf.left = mStableLeft;
3551 vf.top = mStableTop;
3552 vf.right = mStableRight;
3553 vf.bottom = mStableBottom;
3554
3555 mStatusBarLayer = mStatusBar.getSurfaceLayer();
3556
3557 // Let the status bar determine its size.
Filip Gruszczynski2217f612015-05-26 11:32:08 -07003558 mStatusBar.computeFrameLw(pf /* parentFrame */, df /* displayFrame */,
3559 vf /* overlayFrame */, vf /* contentFrame */, vf /* visibleFrame */,
3560 dcf /* decorFrame */, vf /* stableFrame */, vf /* outsetFrame */);
Craig Mautner69b08182012-09-05 13:07:13 -07003561
3562 // For layout, the status bar is always at the top with our fixed height.
3563 mStableTop = mUnrestrictedScreenTop + mStatusBarHeight;
3564
John Spurlocke1f366f2013-08-05 12:22:40 -04003565 boolean statusBarTransient = (sysui & View.STATUS_BAR_TRANSIENT) != 0;
Adrian Roosea562512014-05-05 13:33:03 +02003566 boolean statusBarTranslucent = (sysui
3567 & (View.STATUS_BAR_TRANSLUCENT | View.SYSTEM_UI_TRANSPARENT)) != 0;
Adrian Roos4fb3ee32014-08-22 19:29:09 +02003568 if (!isKeyguardShowing) {
3569 statusBarTranslucent &= areTranslucentBarsAllowed();
3570 }
John Spurlock32beb2c2013-03-11 10:16:47 -04003571
Craig Mautner69b08182012-09-05 13:07:13 -07003572 // If the status bar is hidden, we don't want to cause
3573 // windows behind it to scroll.
John Spurlockeda1f692013-09-16 11:38:44 -04003574 if (mStatusBar.isVisibleLw() && !statusBarTransient) {
Craig Mautner69b08182012-09-05 13:07:13 -07003575 // Status bar may go away, so the screen area it occupies
3576 // is available to apps but just covering them when the
3577 // status bar is visible.
3578 mDockTop = mUnrestrictedScreenTop + mStatusBarHeight;
3579
Dianne Hackborne30e02f2014-05-27 18:24:45 -07003580 mContentTop = mVoiceContentTop = mCurTop = mDockTop;
3581 mContentBottom = mVoiceContentBottom = mCurBottom = mDockBottom;
3582 mContentLeft = mVoiceContentLeft = mCurLeft = mDockLeft;
3583 mContentRight = mVoiceContentRight = mCurRight = mDockRight;
Craig Mautner69b08182012-09-05 13:07:13 -07003584
Craig Mautnereda67292013-04-28 13:50:14 -07003585 if (DEBUG_LAYOUT) Slog.v(TAG, "Status bar: " +
Craig Mautner69b08182012-09-05 13:07:13 -07003586 String.format(
3587 "dock=[%d,%d][%d,%d] content=[%d,%d][%d,%d] cur=[%d,%d][%d,%d]",
3588 mDockLeft, mDockTop, mDockRight, mDockBottom,
3589 mContentLeft, mContentTop, mContentRight, mContentBottom,
3590 mCurLeft, mCurTop, mCurRight, mCurBottom));
3591 }
John Spurlocke1f366f2013-08-05 12:22:40 -04003592 if (mStatusBar.isVisibleLw() && !mStatusBar.isAnimatingLw()
John Spurlockbd957402013-10-03 11:38:39 -04003593 && !statusBarTransient && !statusBarTranslucent
3594 && !mStatusBarController.wasRecentlyTranslucent()) {
John Spurlocke1f366f2013-08-05 12:22:40 -04003595 // If the opaque status bar is currently requested to be visible,
Craig Mautner69b08182012-09-05 13:07:13 -07003596 // and not in the process of animating on or off, then
3597 // we can tell the app that it is covered by it.
3598 mSystemTop = mUnrestrictedScreenTop + mStatusBarHeight;
3599 }
John Spurlock27735a42013-08-14 17:57:38 -04003600 if (mStatusBarController.checkHiddenLw()) {
John Spurlockad3e6cb2013-04-30 08:47:43 -04003601 updateSysUiVisibility = true;
John Spurlock32beb2c2013-03-11 10:16:47 -04003602 }
Dianne Hackborn5c58de32012-04-28 19:52:37 -07003603 }
John Spurlockad3e6cb2013-04-30 08:47:43 -04003604 if (updateSysUiVisibility) {
3605 updateSystemUiVisibilityLw();
3606 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003607 }
3608 }
3609
Dianne Hackborn85afd1b2012-05-13 13:31:06 -07003610 /** {@inheritDoc} */
Craig Mautner967212c2013-04-13 21:10:58 -07003611 @Override
John Spurlock46646232013-09-30 22:32:42 -04003612 public int getSystemDecorLayerLw() {
Bryce Lee2ed3e5f2015-04-01 22:09:19 +00003613 if (mStatusBar != null && mStatusBar.isVisibleLw()) {
3614 return mStatusBar.getSurfaceLayer();
3615 }
3616
3617 if (mNavigationBar != null && mNavigationBar.isVisibleLw()) {
3618 return mNavigationBar.getSurfaceLayer();
3619 }
3620
Dianne Hackborn85afd1b2012-05-13 13:31:06 -07003621 return 0;
3622 }
3623
Craig Mautner967212c2013-04-13 21:10:58 -07003624 @Override
3625 public void getContentRectLw(Rect r) {
3626 r.set(mContentLeft, mContentTop, mContentRight, mContentBottom);
3627 }
3628
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003629 void setAttachedWindowFrames(WindowState win, int fl, int adjust, WindowState attached,
3630 boolean insetDecors, Rect pf, Rect df, Rect of, Rect cf, Rect vf) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003631 if (win.getSurfaceLayer() > mDockLayer && attached.getSurfaceLayer() < mDockLayer) {
3632 // Here's a special case: if this attached window is a panel that is
3633 // above the dock window, and the window it is attached to is below
3634 // the dock window, then the frames we computed for the window it is
3635 // attached to can not be used because the dock is effectively part
3636 // of the underlying window and the attached window is floating on top
3637 // of the whole thing. So, we ignore the attached window and explicitly
3638 // compute the frames that would be appropriate without the dock.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003639 df.left = of.left = cf.left = vf.left = mDockLeft;
3640 df.top = of.top = cf.top = vf.top = mDockTop;
3641 df.right = of.right = cf.right = vf.right = mDockRight;
3642 df.bottom = of.bottom = cf.bottom = vf.bottom = mDockBottom;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003643 } else {
3644 // The effective display frame of the attached window depends on
3645 // whether it is taking care of insetting its content. If not,
3646 // we need to use the parent's content frame so that the entire
3647 // window is positioned within that content. Otherwise we can use
Wale Ogunwale393b1c12014-10-18 16:22:01 -07003648 // the overscan frame and let the attached window take care of
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003649 // positioning its content appropriately.
Dianne Hackborndea3ef72010-10-28 14:24:22 -07003650 if (adjust != SOFT_INPUT_ADJUST_RESIZE) {
Wale Ogunwale393b1c12014-10-18 16:22:01 -07003651 // Set the content frame of the attached window to the parent's decor frame
3652 // (same as content frame when IME isn't present) if specifically requested by
3653 // setting {@link WindowManager.LayoutParams#FLAG_LAYOUT_ATTACHED_IN_DECOR} flag.
3654 // Otherwise, use the overscan frame.
3655 cf.set((fl & FLAG_LAYOUT_ATTACHED_IN_DECOR) != 0
3656 ? attached.getContentFrameLw() : attached.getOverscanFrameLw());
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003657 } else {
3658 // If the window is resizing, then we want to base the content
3659 // frame on our attached content frame to resize... however,
3660 // things can be tricky if the attached window is NOT in resize
3661 // mode, in which case its content frame will be larger.
3662 // Ungh. So to deal with that, make sure the content frame
3663 // we end up using is not covering the IM dock.
3664 cf.set(attached.getContentFrameLw());
Dianne Hackborne30e02f2014-05-27 18:24:45 -07003665 if (attached.isVoiceInteraction()) {
3666 if (cf.left < mVoiceContentLeft) cf.left = mVoiceContentLeft;
3667 if (cf.top < mVoiceContentTop) cf.top = mVoiceContentTop;
3668 if (cf.right > mVoiceContentRight) cf.right = mVoiceContentRight;
3669 if (cf.bottom > mVoiceContentBottom) cf.bottom = mVoiceContentBottom;
3670 } else if (attached.getSurfaceLayer() < mDockLayer) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003671 if (cf.left < mContentLeft) cf.left = mContentLeft;
3672 if (cf.top < mContentTop) cf.top = mContentTop;
3673 if (cf.right > mContentRight) cf.right = mContentRight;
3674 if (cf.bottom > mContentBottom) cf.bottom = mContentBottom;
3675 }
3676 }
3677 df.set(insetDecors ? attached.getDisplayFrameLw() : cf);
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003678 of.set(insetDecors ? attached.getOverscanFrameLw() : cf);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003679 vf.set(attached.getVisibleFrameLw());
3680 }
3681 // The LAYOUT_IN_SCREEN flag is used to determine whether the attached
3682 // window should be positioned relative to its parent or the entire
3683 // screen.
3684 pf.set((fl & FLAG_LAYOUT_IN_SCREEN) == 0
3685 ? attached.getFrameLw() : df);
3686 }
Dianne Hackborn5b5cc4d2012-05-16 13:15:00 -07003687
3688 private void applyStableConstraints(int sysui, int fl, Rect r) {
3689 if ((sysui & View.SYSTEM_UI_FLAG_LAYOUT_STABLE) != 0) {
3690 // If app is requesting a stable layout, don't let the
3691 // content insets go below the stable values.
3692 if ((fl & FLAG_FULLSCREEN) != 0) {
3693 if (r.left < mStableFullscreenLeft) r.left = mStableFullscreenLeft;
3694 if (r.top < mStableFullscreenTop) r.top = mStableFullscreenTop;
3695 if (r.right > mStableFullscreenRight) r.right = mStableFullscreenRight;
3696 if (r.bottom > mStableFullscreenBottom) r.bottom = mStableFullscreenBottom;
3697 } else {
3698 if (r.left < mStableLeft) r.left = mStableLeft;
3699 if (r.top < mStableTop) r.top = mStableTop;
3700 if (r.right > mStableRight) r.right = mStableRight;
3701 if (r.bottom > mStableBottom) r.bottom = mStableBottom;
3702 }
3703 }
3704 }
3705
Jorim Jaggiaa806142015-05-20 18:04:16 -07003706 private boolean canReceiveInput(WindowState win) {
3707 boolean notFocusable =
3708 (win.getAttrs().flags & WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE) != 0;
3709 boolean altFocusableIm =
3710 (win.getAttrs().flags & WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM) != 0;
3711 boolean notFocusableForIm = notFocusable ^ altFocusableIm;
3712 return !notFocusableForIm;
3713 }
3714
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003715 /** {@inheritDoc} */
Craig Mautner69b08182012-09-05 13:07:13 -07003716 @Override
Craig Mautnerc9457fa2014-06-06 14:27:48 -07003717 public void layoutWindowLw(WindowState win, WindowState attached) {
Jorim Jaggiaa806142015-05-20 18:04:16 -07003718 // We've already done the navigation bar and status bar. If the status bar can receive
3719 // input, we need to layout it again to accomodate for the IME window.
3720 if ((win == mStatusBar && !canReceiveInput(win)) || win == mNavigationBar) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003721 return;
3722 }
Jorim Jaggiaa806142015-05-20 18:04:16 -07003723 final WindowManager.LayoutParams attrs = win.getAttrs();
Craig Mautner69b08182012-09-05 13:07:13 -07003724 final boolean isDefaultDisplay = win.isDefaultDisplay();
3725 final boolean needsToOffsetInputMethodTarget = isDefaultDisplay &&
satok1bc0a492012-04-25 22:47:12 +09003726 (win == mLastInputMethodTargetWindow && mLastInputMethodWindow != null);
3727 if (needsToOffsetInputMethodTarget) {
Craig Mautnereda67292013-04-28 13:50:14 -07003728 if (DEBUG_LAYOUT) Slog.i(TAG, "Offset ime target window by the last ime window state");
satok1bc0a492012-04-25 22:47:12 +09003729 offsetInputMethodWindowLw(mLastInputMethodWindow);
3730 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003731
John Spurlockc6d1c602014-01-17 15:22:06 -05003732 final int fl = PolicyControl.getWindowFlags(win, attrs);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003733 final int sim = attrs.softInputMode;
John Spurlock1db8b682014-02-18 11:18:59 -05003734 final int sysUiFl = PolicyControl.getSystemUiVisibility(win, null);
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07003735
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003736 final Rect pf = mTmpParentFrame;
3737 final Rect df = mTmpDisplayFrame;
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003738 final Rect of = mTmpOverscanFrame;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003739 final Rect cf = mTmpContentFrame;
3740 final Rect vf = mTmpVisibleFrame;
John Spurlock46646232013-09-30 22:32:42 -04003741 final Rect dcf = mTmpDecorFrame;
Adrian Roosfa104232014-06-20 16:10:14 -07003742 final Rect sf = mTmpStableFrame;
Filip Gruszczynski2217f612015-05-26 11:32:08 -07003743 Rect osf = null;
John Spurlock46646232013-09-30 22:32:42 -04003744 dcf.setEmpty();
Craig Mautner69b08182012-09-05 13:07:13 -07003745
3746 final boolean hasNavBar = (isDefaultDisplay && mHasNavigationBar
Daniel Sandler36412a72011-08-04 09:35:13 -04003747 && mNavigationBar != null && mNavigationBar.isVisibleLw());
Daniel Sandler8956dbb2011-04-22 07:55:02 -04003748
Craig Mautnerf683b562012-10-02 11:10:57 -07003749 final int adjust = sim & SOFT_INPUT_MASK_ADJUST;
3750
Adrian Roosfa104232014-06-20 16:10:14 -07003751 if (isDefaultDisplay) {
3752 sf.set(mStableLeft, mStableTop, mStableRight, mStableBottom);
3753 } else {
3754 sf.set(mOverscanLeft, mOverscanTop, mOverscanRight, mOverscanBottom);
3755 }
3756
Craig Mautner69b08182012-09-05 13:07:13 -07003757 if (!isDefaultDisplay) {
3758 if (attached != null) {
3759 // If this window is attached to another, our display
3760 // frame is the same as the one we are attached to.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003761 setAttachedWindowFrames(win, fl, adjust, attached, true, pf, df, of, cf, vf);
Craig Mautner69b08182012-09-05 13:07:13 -07003762 } else {
3763 // Give the window full screen.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003764 pf.left = df.left = of.left = cf.left = mOverscanScreenLeft;
3765 pf.top = df.top = of.top = cf.top = mOverscanScreenTop;
3766 pf.right = df.right = of.right = cf.right
Dianne Hackbornc652de82013-02-15 16:32:56 -08003767 = mOverscanScreenLeft + mOverscanScreenWidth;
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003768 pf.bottom = df.bottom = of.bottom = cf.bottom
Dianne Hackbornc652de82013-02-15 16:32:56 -08003769 = mOverscanScreenTop + mOverscanScreenHeight;
Craig Mautner69b08182012-09-05 13:07:13 -07003770 }
Jorim Jaggi225d3b52015-04-01 11:18:57 -07003771 } else if (attrs.type == TYPE_INPUT_METHOD) {
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003772 pf.left = df.left = of.left = cf.left = vf.left = mDockLeft;
3773 pf.top = df.top = of.top = cf.top = vf.top = mDockTop;
3774 pf.right = df.right = of.right = cf.right = vf.right = mDockRight;
John Spurlockc68d5772013-10-08 11:47:58 -04003775 // IM dock windows layout below the nav bar...
John Spurlock57beb3b2013-10-10 10:27:44 -04003776 pf.bottom = df.bottom = of.bottom = mUnrestrictedScreenTop + mUnrestrictedScreenHeight;
John Spurlockc68d5772013-10-08 11:47:58 -04003777 // ...with content insets above the nav bar
3778 cf.bottom = vf.bottom = mStableBottom;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003779 // IM dock windows always go to the bottom of the screen.
3780 attrs.gravity = Gravity.BOTTOM;
3781 mDockLayer = win.getSurfaceLayer();
Jorim Jaggi225d3b52015-04-01 11:18:57 -07003782 } else if (attrs.type == TYPE_VOICE_INTERACTION) {
Stefan Kuhne2f280d062015-06-18 07:20:33 -10003783 pf.left = df.left = of.left = mUnrestrictedScreenLeft;
Jorim Jaggi225d3b52015-04-01 11:18:57 -07003784 pf.top = df.top = of.top = mUnrestrictedScreenTop;
Stefan Kuhne2f280d062015-06-18 07:20:33 -10003785 pf.right = df.right = of.right = mUnrestrictedScreenLeft + mUnrestrictedScreenWidth;
3786 pf.bottom = df.bottom = of.bottom = mUnrestrictedScreenTop + mUnrestrictedScreenHeight;
Jorim Jaggi225d3b52015-04-01 11:18:57 -07003787 cf.bottom = vf.bottom = mStableBottom;
Stefan Kuhne2f280d062015-06-18 07:20:33 -10003788 // Note: In Phone landscape mode, the button bar should also be excluded.
3789 cf.right = vf.right = mStableRight;
3790 cf.left = vf.left = mStableLeft;
Jorim Jaggi225d3b52015-04-01 11:18:57 -07003791 cf.top = vf.top = mStableTop;
Jorim Jaggiaa806142015-05-20 18:04:16 -07003792 } else if (win == mStatusBar) {
Jorim Jaggie0700182014-08-21 01:12:37 +02003793 pf.left = df.left = of.left = mUnrestrictedScreenLeft;
3794 pf.top = df.top = of.top = mUnrestrictedScreenTop;
3795 pf.right = df.right = of.right = mUnrestrictedScreenWidth + mUnrestrictedScreenLeft;
3796 pf.bottom = df.bottom = of.bottom = mUnrestrictedScreenHeight + mUnrestrictedScreenTop;
3797 cf.left = vf.left = mStableLeft;
3798 cf.top = vf.top = mStableTop;
3799 cf.right = vf.right = mStableRight;
3800 vf.bottom = mStableBottom;
3801 cf.bottom = mContentBottom;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003802 } else {
John Spurlock46646232013-09-30 22:32:42 -04003803
3804 // Default policy decor for the default display
3805 dcf.left = mSystemLeft;
3806 dcf.top = mSystemTop;
3807 dcf.right = mSystemRight;
3808 dcf.bottom = mSystemBottom;
John Spurlockbd957402013-10-03 11:38:39 -04003809 final boolean inheritTranslucentDecor = (attrs.privateFlags
3810 & WindowManager.LayoutParams.PRIVATE_FLAG_INHERIT_TRANSLUCENT_DECOR) != 0;
John Spurlock65567d42013-10-08 10:08:32 -04003811 final boolean isAppWindow =
3812 attrs.type >= WindowManager.LayoutParams.FIRST_APPLICATION_WINDOW &&
3813 attrs.type <= WindowManager.LayoutParams.LAST_APPLICATION_WINDOW;
3814 final boolean topAtRest =
3815 win == mTopFullscreenOpaqueWindowState && !win.isAnimatingLw();
3816 if (isAppWindow && !inheritTranslucentDecor && !topAtRest) {
John Spurlockbd957402013-10-03 11:38:39 -04003817 if ((sysUiFl & View.SYSTEM_UI_FLAG_FULLSCREEN) == 0
3818 && (fl & WindowManager.LayoutParams.FLAG_FULLSCREEN) == 0
Adrian Roosea562512014-05-05 13:33:03 +02003819 && (fl & WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS) == 0
3820 && (fl & WindowManager.LayoutParams.
3821 FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS) == 0) {
John Spurlock46646232013-09-30 22:32:42 -04003822 // Ensure policy decor includes status bar
3823 dcf.top = mStableTop;
3824 }
John Spurlockbd957402013-10-03 11:38:39 -04003825 if ((fl & WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION) == 0
Adrian Roosea562512014-05-05 13:33:03 +02003826 && (sysUiFl & View.SYSTEM_UI_FLAG_HIDE_NAVIGATION) == 0
3827 && (fl & WindowManager.LayoutParams.
3828 FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS) == 0) {
John Spurlock46646232013-09-30 22:32:42 -04003829 // Ensure policy decor includes navigation bar
3830 dcf.bottom = mStableBottom;
3831 dcf.right = mStableRight;
3832 }
3833 }
3834
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003835 if ((fl & (FLAG_LAYOUT_IN_SCREEN | FLAG_LAYOUT_INSET_DECOR))
3836 == (FLAG_LAYOUT_IN_SCREEN | FLAG_LAYOUT_INSET_DECOR)) {
RoboErik8a2cfc32014-05-16 11:19:38 -07003837 if (DEBUG_LAYOUT) Slog.v(TAG, "layoutWindowLw(" + attrs.getTitle()
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003838 + "): IN_SCREEN, INSET_DECOR");
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003839 // This is the case for a normal activity window: we want it
3840 // to cover all of the screen space, and it can take care of
3841 // moving its contents to account for screen decorations that
3842 // intrude into that space.
3843 if (attached != null) {
3844 // If this window is attached to another, our display
3845 // frame is the same as the one we are attached to.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003846 setAttachedWindowFrames(win, fl, adjust, attached, true, pf, df, of, cf, vf);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003847 } else {
Daniel Sandler8956dbb2011-04-22 07:55:02 -04003848 if (attrs.type == TYPE_STATUS_BAR_PANEL
3849 || attrs.type == TYPE_STATUS_BAR_SUB_PANEL) {
Joe Onorato29fc2c92010-11-24 10:26:50 -08003850 // Status bar panels are the only windows who can go on top of
3851 // the status bar. They are protected by the STATUS_BAR_SERVICE
3852 // permission, so they have the same privileges as the status
3853 // bar itself.
Daniel Sandler8956dbb2011-04-22 07:55:02 -04003854 //
Daniel Sandler8e8b4152011-07-21 01:16:43 -04003855 // However, they should still dodge the navigation bar if it exists.
Daniel Sandler8956dbb2011-04-22 07:55:02 -04003856
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003857 pf.left = df.left = of.left = hasNavBar
3858 ? mDockLeft : mUnrestrictedScreenLeft;
3859 pf.top = df.top = of.top = mUnrestrictedScreenTop;
3860 pf.right = df.right = of.right = hasNavBar
3861 ? mRestrictedScreenLeft+mRestrictedScreenWidth
3862 : mUnrestrictedScreenLeft + mUnrestrictedScreenWidth;
3863 pf.bottom = df.bottom = of.bottom = hasNavBar
3864 ? mRestrictedScreenTop+mRestrictedScreenHeight
3865 : mUnrestrictedScreenTop + mUnrestrictedScreenHeight;
Daniel Sandler8956dbb2011-04-22 07:55:02 -04003866
Craig Mautnereda67292013-04-28 13:50:14 -07003867 if (DEBUG_LAYOUT) Slog.v(TAG, String.format(
Daniel Sandler8e8b4152011-07-21 01:16:43 -04003868 "Laying out status bar window: (%d,%d - %d,%d)",
3869 pf.left, pf.top, pf.right, pf.bottom));
John Spurlock46646232013-09-30 22:32:42 -04003870 } else if ((fl & FLAG_LAYOUT_IN_OVERSCAN) != 0
Dianne Hackbornc652de82013-02-15 16:32:56 -08003871 && attrs.type >= WindowManager.LayoutParams.FIRST_APPLICATION_WINDOW
3872 && attrs.type <= WindowManager.LayoutParams.LAST_SUB_WINDOW) {
3873 // Asking to layout into the overscan region, so give it that pure
3874 // unrestricted area.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003875 pf.left = df.left = of.left = mOverscanScreenLeft;
3876 pf.top = df.top = of.top = mOverscanScreenTop;
3877 pf.right = df.right = of.right = mOverscanScreenLeft + mOverscanScreenWidth;
3878 pf.bottom = df.bottom = of.bottom = mOverscanScreenTop
3879 + mOverscanScreenHeight;
Alan Viverette5a0f4ec2013-10-07 15:10:29 -07003880 } else if (canHideNavigationBar()
Dianne Hackbornf87d1962012-04-04 12:48:24 -07003881 && (sysUiFl & View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION) != 0
Jorim Jaggi380ecb82014-03-14 17:25:20 +01003882 && attrs.type >= WindowManager.LayoutParams.FIRST_APPLICATION_WINDOW
3883 && attrs.type <= WindowManager.LayoutParams.LAST_SUB_WINDOW) {
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07003884 // Asking for layout as if the nav bar is hidden, lets the
Dianne Hackbornc652de82013-02-15 16:32:56 -08003885 // application extend into the unrestricted overscan screen area. We
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07003886 // only do this for application windows to ensure no window that
3887 // can be above the nav bar can do this.
Dianne Hackborn313440842013-02-19 19:22:59 -08003888 pf.left = df.left = mOverscanScreenLeft;
3889 pf.top = df.top = mOverscanScreenTop;
3890 pf.right = df.right = mOverscanScreenLeft + mOverscanScreenWidth;
3891 pf.bottom = df.bottom = mOverscanScreenTop + mOverscanScreenHeight;
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003892 // We need to tell the app about where the frame inside the overscan
3893 // is, so it can inset its content by that amount -- it didn't ask
3894 // to actually extend itself into the overscan region.
3895 of.left = mUnrestrictedScreenLeft;
3896 of.top = mUnrestrictedScreenTop;
3897 of.right = mUnrestrictedScreenLeft + mUnrestrictedScreenWidth;
3898 of.bottom = mUnrestrictedScreenTop + mUnrestrictedScreenHeight;
Joe Onorato29fc2c92010-11-24 10:26:50 -08003899 } else {
Dianne Hackborn313440842013-02-19 19:22:59 -08003900 pf.left = df.left = mRestrictedOverscanScreenLeft;
3901 pf.top = df.top = mRestrictedOverscanScreenTop;
3902 pf.right = df.right = mRestrictedOverscanScreenLeft
3903 + mRestrictedOverscanScreenWidth;
3904 pf.bottom = df.bottom = mRestrictedOverscanScreenTop
3905 + mRestrictedOverscanScreenHeight;
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003906 // We need to tell the app about where the frame inside the overscan
3907 // is, so it can inset its content by that amount -- it didn't ask
3908 // to actually extend itself into the overscan region.
3909 of.left = mUnrestrictedScreenLeft;
3910 of.top = mUnrestrictedScreenTop;
3911 of.right = mUnrestrictedScreenLeft + mUnrestrictedScreenWidth;
3912 of.bottom = mUnrestrictedScreenTop + mUnrestrictedScreenHeight;
Joe Onorato29fc2c92010-11-24 10:26:50 -08003913 }
Craig Mautner69b08182012-09-05 13:07:13 -07003914
John Spurlock46646232013-09-30 22:32:42 -04003915 if ((fl & FLAG_FULLSCREEN) == 0) {
Dianne Hackborne30e02f2014-05-27 18:24:45 -07003916 if (win.isVoiceInteraction()) {
3917 cf.left = mVoiceContentLeft;
3918 cf.top = mVoiceContentTop;
3919 cf.right = mVoiceContentRight;
3920 cf.bottom = mVoiceContentBottom;
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003921 } else {
Dianne Hackborne30e02f2014-05-27 18:24:45 -07003922 if (adjust != SOFT_INPUT_ADJUST_RESIZE) {
3923 cf.left = mDockLeft;
3924 cf.top = mDockTop;
3925 cf.right = mDockRight;
3926 cf.bottom = mDockBottom;
3927 } else {
3928 cf.left = mContentLeft;
3929 cf.top = mContentTop;
3930 cf.right = mContentRight;
3931 cf.bottom = mContentBottom;
3932 }
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003933 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003934 } else {
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003935 // Full screen windows are always given a layout that is as if the
3936 // status bar and other transient decors are gone. This is to avoid
3937 // bad states when moving from a window that is not hding the
3938 // status bar to one that is.
3939 cf.left = mRestrictedScreenLeft;
3940 cf.top = mRestrictedScreenTop;
3941 cf.right = mRestrictedScreenLeft + mRestrictedScreenWidth;
3942 cf.bottom = mRestrictedScreenTop + mRestrictedScreenHeight;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003943 }
Dianne Hackborn5b5cc4d2012-05-16 13:15:00 -07003944 applyStableConstraints(sysUiFl, fl, cf);
Dianne Hackborndea3ef72010-10-28 14:24:22 -07003945 if (adjust != SOFT_INPUT_ADJUST_NOTHING) {
3946 vf.left = mCurLeft;
3947 vf.top = mCurTop;
3948 vf.right = mCurRight;
3949 vf.bottom = mCurBottom;
3950 } else {
3951 vf.set(cf);
3952 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003953 }
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07003954 } else if ((fl & FLAG_LAYOUT_IN_SCREEN) != 0 || (sysUiFl
3955 & (View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
3956 | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION)) != 0) {
Craig Mautnereda67292013-04-28 13:50:14 -07003957 if (DEBUG_LAYOUT) Slog.v(TAG, "layoutWindowLw(" + attrs.getTitle() +
3958 "): IN_SCREEN");
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003959 // A window that has requested to fill the entire screen just
3960 // gets everything, period.
Daniel Sandler8956dbb2011-04-22 07:55:02 -04003961 if (attrs.type == TYPE_STATUS_BAR_PANEL
John Spurlock67a0f852015-06-15 15:35:47 -04003962 || attrs.type == TYPE_STATUS_BAR_SUB_PANEL
3963 || attrs.type == TYPE_VOLUME_OVERLAY) {
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003964 pf.left = df.left = of.left = cf.left = hasNavBar
3965 ? mDockLeft : mUnrestrictedScreenLeft;
3966 pf.top = df.top = of.top = cf.top = mUnrestrictedScreenTop;
3967 pf.right = df.right = of.right = cf.right = hasNavBar
Daniel Sandler8e8b4152011-07-21 01:16:43 -04003968 ? mRestrictedScreenLeft+mRestrictedScreenWidth
Dianne Hackbornc652de82013-02-15 16:32:56 -08003969 : mUnrestrictedScreenLeft + mUnrestrictedScreenWidth;
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003970 pf.bottom = df.bottom = of.bottom = cf.bottom = hasNavBar
Daniel Sandler8e8b4152011-07-21 01:16:43 -04003971 ? mRestrictedScreenTop+mRestrictedScreenHeight
Dianne Hackbornc652de82013-02-15 16:32:56 -08003972 : mUnrestrictedScreenTop + mUnrestrictedScreenHeight;
Craig Mautnereda67292013-04-28 13:50:14 -07003973 if (DEBUG_LAYOUT) Slog.v(TAG, String.format(
Daniel Sandler36412a72011-08-04 09:35:13 -04003974 "Laying out IN_SCREEN status bar window: (%d,%d - %d,%d)",
3975 pf.left, pf.top, pf.right, pf.bottom));
Jim Millere898ac52012-04-06 17:10:57 -07003976 } else if (attrs.type == TYPE_NAVIGATION_BAR
3977 || attrs.type == TYPE_NAVIGATION_BAR_PANEL) {
Daniel Sandler8e8b4152011-07-21 01:16:43 -04003978 // The navigation bar has Real Ultimate Power.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003979 pf.left = df.left = of.left = mUnrestrictedScreenLeft;
3980 pf.top = df.top = of.top = mUnrestrictedScreenTop;
3981 pf.right = df.right = of.right = mUnrestrictedScreenLeft
3982 + mUnrestrictedScreenWidth;
3983 pf.bottom = df.bottom = of.bottom = mUnrestrictedScreenTop
3984 + mUnrestrictedScreenHeight;
Craig Mautnereda67292013-04-28 13:50:14 -07003985 if (DEBUG_LAYOUT) Slog.v(TAG, String.format(
Daniel Sandler8e8b4152011-07-21 01:16:43 -04003986 "Laying out navigation bar window: (%d,%d - %d,%d)",
3987 pf.left, pf.top, pf.right, pf.bottom));
Dianne Hackborn01011c32012-02-21 13:54:21 -08003988 } else if ((attrs.type == TYPE_SECURE_SYSTEM_OVERLAY
3989 || attrs.type == TYPE_BOOT_PROGRESS)
Jeff Brownbfcb60a2011-09-08 18:51:14 -07003990 && ((fl & FLAG_FULLSCREEN) != 0)) {
3991 // Fullscreen secure system overlays get what they ask for.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003992 pf.left = df.left = of.left = cf.left = mOverscanScreenLeft;
3993 pf.top = df.top = of.top = cf.top = mOverscanScreenTop;
3994 pf.right = df.right = of.right = cf.right = mOverscanScreenLeft
3995 + mOverscanScreenWidth;
3996 pf.bottom = df.bottom = of.bottom = cf.bottom = mOverscanScreenTop
3997 + mOverscanScreenHeight;
Craig Mautner165be0c2015-01-27 15:16:58 -08003998 } else if (attrs.type == TYPE_BOOT_PROGRESS) {
Dianne Hackborn01011c32012-02-21 13:54:21 -08003999 // Boot progress screen always covers entire display.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08004000 pf.left = df.left = of.left = cf.left = mOverscanScreenLeft;
4001 pf.top = df.top = of.top = cf.top = mOverscanScreenTop;
4002 pf.right = df.right = of.right = cf.right = mOverscanScreenLeft
4003 + mOverscanScreenWidth;
4004 pf.bottom = df.bottom = of.bottom = cf.bottom = mOverscanScreenTop
4005 + mOverscanScreenHeight;
John Spurlockef4adae2013-08-26 17:58:58 -04004006 } else if (attrs.type == TYPE_WALLPAPER) {
Dianne Hackborn067e5f62014-09-07 23:14:30 -07004007 // The wallpaper also has Real Ultimate Power, but we want to tell
4008 // it about the overscan area.
4009 pf.left = df.left = mOverscanScreenLeft;
4010 pf.top = df.top = mOverscanScreenTop;
4011 pf.right = df.right = mOverscanScreenLeft + mOverscanScreenWidth;
4012 pf.bottom = df.bottom = mOverscanScreenTop + mOverscanScreenHeight;
4013 of.left = cf.left = mUnrestrictedScreenLeft;
4014 of.top = cf.top = mUnrestrictedScreenTop;
4015 of.right = cf.right = mUnrestrictedScreenLeft + mUnrestrictedScreenWidth;
4016 of.bottom = cf.bottom = mUnrestrictedScreenTop + mUnrestrictedScreenHeight;
John Spurlock46646232013-09-30 22:32:42 -04004017 } else if ((fl & FLAG_LAYOUT_IN_OVERSCAN) != 0
Dianne Hackbornc652de82013-02-15 16:32:56 -08004018 && attrs.type >= WindowManager.LayoutParams.FIRST_APPLICATION_WINDOW
4019 && attrs.type <= WindowManager.LayoutParams.LAST_SUB_WINDOW) {
4020 // Asking to layout into the overscan region, so give it that pure
4021 // unrestricted area.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08004022 pf.left = df.left = of.left = cf.left = mOverscanScreenLeft;
4023 pf.top = df.top = of.top = cf.top = mOverscanScreenTop;
4024 pf.right = df.right = of.right = cf.right
Dianne Hackbornc652de82013-02-15 16:32:56 -08004025 = mOverscanScreenLeft + mOverscanScreenWidth;
Dianne Hackbornc4aad012013-02-22 15:05:25 -08004026 pf.bottom = df.bottom = of.bottom = cf.bottom
Dianne Hackbornc652de82013-02-15 16:32:56 -08004027 = mOverscanScreenTop + mOverscanScreenHeight;
Alan Viverette5a0f4ec2013-10-07 15:10:29 -07004028 } else if (canHideNavigationBar()
Dianne Hackbornf87d1962012-04-04 12:48:24 -07004029 && (sysUiFl & View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION) != 0
Craig Mautnerbeac1062014-06-03 14:38:57 -07004030 && (attrs.type == TYPE_STATUS_BAR
4031 || attrs.type == TYPE_TOAST
Jorim Jaggi2fdeeab2015-04-01 15:13:03 -07004032 || attrs.type == TYPE_VOICE_INTERACTION_STARTING
John Spurlock34e13d92013-08-10 06:52:28 -04004033 || (attrs.type >= WindowManager.LayoutParams.FIRST_APPLICATION_WINDOW
4034 && attrs.type <= WindowManager.LayoutParams.LAST_SUB_WINDOW))) {
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07004035 // Asking for layout as if the nav bar is hidden, lets the
4036 // application extend into the unrestricted screen area. We
John Spurlock34e13d92013-08-10 06:52:28 -04004037 // only do this for application windows (or toasts) to ensure no window that
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07004038 // can be above the nav bar can do this.
4039 // XXX This assumes that an app asking for this will also
4040 // ask for layout in only content. We can't currently figure out
4041 // what the screen would be if only laying out to hide the nav bar.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08004042 pf.left = df.left = of.left = cf.left = mUnrestrictedScreenLeft;
4043 pf.top = df.top = of.top = cf.top = mUnrestrictedScreenTop;
4044 pf.right = df.right = of.right = cf.right = mUnrestrictedScreenLeft
4045 + mUnrestrictedScreenWidth;
4046 pf.bottom = df.bottom = of.bottom = cf.bottom = mUnrestrictedScreenTop
4047 + mUnrestrictedScreenHeight;
Joe Onorato29fc2c92010-11-24 10:26:50 -08004048 } else {
Dianne Hackbornc4aad012013-02-22 15:05:25 -08004049 pf.left = df.left = of.left = cf.left = mRestrictedScreenLeft;
4050 pf.top = df.top = of.top = cf.top = mRestrictedScreenTop;
4051 pf.right = df.right = of.right = cf.right = mRestrictedScreenLeft
4052 + mRestrictedScreenWidth;
4053 pf.bottom = df.bottom = of.bottom = cf.bottom = mRestrictedScreenTop
4054 + mRestrictedScreenHeight;
Joe Onorato29fc2c92010-11-24 10:26:50 -08004055 }
Craig Mautner69b08182012-09-05 13:07:13 -07004056
Dianne Hackborn5b5cc4d2012-05-16 13:15:00 -07004057 applyStableConstraints(sysUiFl, fl, cf);
Craig Mautner69b08182012-09-05 13:07:13 -07004058
Dianne Hackborndea3ef72010-10-28 14:24:22 -07004059 if (adjust != SOFT_INPUT_ADJUST_NOTHING) {
4060 vf.left = mCurLeft;
4061 vf.top = mCurTop;
4062 vf.right = mCurRight;
4063 vf.bottom = mCurBottom;
4064 } else {
4065 vf.set(cf);
4066 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004067 } else if (attached != null) {
Craig Mautnereda67292013-04-28 13:50:14 -07004068 if (DEBUG_LAYOUT) Slog.v(TAG, "layoutWindowLw(" + attrs.getTitle() +
4069 "): attached to " + attached);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004070 // A child window should be placed inside of the same visible
4071 // frame that its parent had.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08004072 setAttachedWindowFrames(win, fl, adjust, attached, false, pf, df, of, cf, vf);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004073 } else {
Craig Mautnereda67292013-04-28 13:50:14 -07004074 if (DEBUG_LAYOUT) Slog.v(TAG, "layoutWindowLw(" + attrs.getTitle() +
4075 "): normal window");
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004076 // Otherwise, a normal window must be placed inside the content
4077 // of all screen decorations.
John Spurlock67a0f852015-06-15 15:35:47 -04004078 if (attrs.type == TYPE_STATUS_BAR_PANEL || attrs.type == TYPE_VOLUME_OVERLAY) {
4079 // Status bar panels and the volume dialog are the only windows who can go on
4080 // top of the status bar. They are protected by the STATUS_BAR_SERVICE
Dianne Hackborna239c842011-06-01 12:28:20 -07004081 // permission, so they have the same privileges as the status
4082 // bar itself.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08004083 pf.left = df.left = of.left = cf.left = mRestrictedScreenLeft;
4084 pf.top = df.top = of.top = cf.top = mRestrictedScreenTop;
4085 pf.right = df.right = of.right = cf.right = mRestrictedScreenLeft
4086 + mRestrictedScreenWidth;
4087 pf.bottom = df.bottom = of.bottom = cf.bottom = mRestrictedScreenTop
4088 + mRestrictedScreenHeight;
John Spurlock67a0f852015-06-15 15:35:47 -04004089 } else if (attrs.type == TYPE_TOAST || attrs.type == TYPE_SYSTEM_ALERT) {
John Spurlock414c1f02013-12-04 13:47:36 -05004090 // These dialogs are stable to interim decor changes.
John Spurlockbd957402013-10-03 11:38:39 -04004091 pf.left = df.left = of.left = cf.left = mStableLeft;
4092 pf.top = df.top = of.top = cf.top = mStableTop;
4093 pf.right = df.right = of.right = cf.right = mStableRight;
4094 pf.bottom = df.bottom = of.bottom = cf.bottom = mStableBottom;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004095 } else {
Dianne Hackborna239c842011-06-01 12:28:20 -07004096 pf.left = mContentLeft;
4097 pf.top = mContentTop;
4098 pf.right = mContentRight;
4099 pf.bottom = mContentBottom;
Dianne Hackborn20d94742014-05-29 18:35:45 -07004100 if (win.isVoiceInteraction()) {
4101 df.left = of.left = cf.left = mVoiceContentLeft;
4102 df.top = of.top = cf.top = mVoiceContentTop;
4103 df.right = of.right = cf.right = mVoiceContentRight;
4104 df.bottom = of.bottom = cf.bottom = mVoiceContentBottom;
4105 } else if (adjust != SOFT_INPUT_ADJUST_RESIZE) {
Dianne Hackbornc4aad012013-02-22 15:05:25 -08004106 df.left = of.left = cf.left = mDockLeft;
4107 df.top = of.top = cf.top = mDockTop;
4108 df.right = of.right = cf.right = mDockRight;
4109 df.bottom = of.bottom = cf.bottom = mDockBottom;
Dianne Hackborna239c842011-06-01 12:28:20 -07004110 } else {
Dianne Hackbornc4aad012013-02-22 15:05:25 -08004111 df.left = of.left = cf.left = mContentLeft;
4112 df.top = of.top = cf.top = mContentTop;
4113 df.right = of.right = cf.right = mContentRight;
4114 df.bottom = of.bottom = cf.bottom = mContentBottom;
Dianne Hackborna239c842011-06-01 12:28:20 -07004115 }
4116 if (adjust != SOFT_INPUT_ADJUST_NOTHING) {
4117 vf.left = mCurLeft;
4118 vf.top = mCurTop;
4119 vf.right = mCurRight;
4120 vf.bottom = mCurBottom;
4121 } else {
4122 vf.set(cf);
4123 }
Dianne Hackborndea3ef72010-10-28 14:24:22 -07004124 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004125 }
4126 }
Craig Mautner69b08182012-09-05 13:07:13 -07004127
Craig Mautnerb816bed2013-07-23 10:26:17 -07004128 // TYPE_SYSTEM_ERROR is above the NavigationBar so it can't be allowed to extend over it.
4129 if ((fl & FLAG_LAYOUT_NO_LIMITS) != 0 && attrs.type != TYPE_SYSTEM_ERROR) {
Dianne Hackborn067e5f62014-09-07 23:14:30 -07004130 df.left = df.top = -10000;
4131 df.right = df.bottom = 10000;
4132 if (attrs.type != TYPE_WALLPAPER) {
4133 of.left = of.top = cf.left = cf.top = vf.left = vf.top = -10000;
4134 of.right = of.bottom = cf.right = cf.bottom = vf.right = vf.bottom = 10000;
4135 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004136 }
4137
Filip Gruszczynski2217f612015-05-26 11:32:08 -07004138 // If the device has a chin (e.g. some watches), a dead area at the bottom of the screen we
4139 // need to provide information to the clients that want to pretend that you can draw there.
Filip Gruszczynskib0c673b2015-06-05 09:43:06 -07004140 // We only want to apply outsets to certain types of windows. For example, we never want to
4141 // apply the outsets to floating dialogs, because they wouldn't make sense there.
4142 final boolean useOutsets = attrs.type == TYPE_WALLPAPER
4143 || (fl & (WindowManager.LayoutParams.FLAG_FULLSCREEN
4144 | WindowManager.LayoutParams.FLAG_LAYOUT_IN_OVERSCAN)) != 0;
4145 if (isDefaultDisplay && useOutsets) {
Filip Gruszczynski2217f612015-05-26 11:32:08 -07004146 osf = mTmpOutsetFrame;
4147 osf.set(cf.left, cf.top, cf.right, cf.bottom);
4148 int outset = ScreenShapeHelper.getWindowOutsetBottomPx(mContext.getResources());
4149 if (outset > 0) {
4150 int rotation = Surface.ROTATION_0;
4151 try {
4152 rotation = mWindowManager.getRotation();
4153 } catch (RemoteException e) {
4154 }
4155 if (rotation == Surface.ROTATION_0) {
4156 osf.bottom += outset;
4157 } else if (rotation == Surface.ROTATION_90) {
4158 osf.right += outset;
4159 } else if (rotation == Surface.ROTATION_180) {
4160 osf.top -= outset;
4161 } else if (rotation == Surface.ROTATION_270) {
4162 osf.left -= outset;
4163 }
4164 if (DEBUG_LAYOUT) Slog.v(TAG, "applying bottom outset of " + outset
4165 + " with rotation " + rotation + ", result: " + osf);
4166 }
4167 }
4168
Craig Mautnereda67292013-04-28 13:50:14 -07004169 if (DEBUG_LAYOUT) Slog.v(TAG, "Compute frame " + attrs.getTitle()
The Android Open Source Project11267662009-03-18 17:39:47 -07004170 + ": sim=#" + Integer.toHexString(sim)
RoboErik8a2cfc32014-05-16 11:19:38 -07004171 + " attach=" + attached + " type=" + attrs.type
Daniel Sandler8956dbb2011-04-22 07:55:02 -04004172 + String.format(" flags=0x%08x", fl)
The Android Open Source Project11267662009-03-18 17:39:47 -07004173 + " pf=" + pf.toShortString() + " df=" + df.toShortString()
Dianne Hackbornc4aad012013-02-22 15:05:25 -08004174 + " of=" + of.toShortString()
John Spurlock46646232013-09-30 22:32:42 -04004175 + " cf=" + cf.toShortString() + " vf=" + vf.toShortString()
Adrian Roosfa104232014-06-20 16:10:14 -07004176 + " dcf=" + dcf.toShortString()
Filip Gruszczynski2217f612015-05-26 11:32:08 -07004177 + " sf=" + sf.toShortString()
4178 + " osf=" + (osf == null ? "null" : osf.toShortString()));
Craig Mautner69b08182012-09-05 13:07:13 -07004179
Filip Gruszczynski2217f612015-05-26 11:32:08 -07004180 win.computeFrameLw(pf, df, of, cf, vf, dcf, sf, osf);
Craig Mautner69b08182012-09-05 13:07:13 -07004181
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004182 // Dock windows carve out the bottom of the screen, so normal windows
4183 // can't appear underneath them.
Craig Mautner8bd206b2012-10-03 10:32:02 -07004184 if (attrs.type == TYPE_INPUT_METHOD && win.isVisibleOrBehindKeyguardLw()
4185 && !win.getGivenInsetsPendingLw()) {
satok1bc0a492012-04-25 22:47:12 +09004186 setLastInputMethodWindowLw(null, null);
4187 offsetInputMethodWindowLw(win);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004188 }
Dianne Hackborne30e02f2014-05-27 18:24:45 -07004189 if (attrs.type == TYPE_VOICE_INTERACTION && win.isVisibleOrBehindKeyguardLw()
4190 && !win.getGivenInsetsPendingLw()) {
4191 offsetVoiceInputWindowLw(win);
4192 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004193 }
4194
satok1bc0a492012-04-25 22:47:12 +09004195 private void offsetInputMethodWindowLw(WindowState win) {
Craig Mautner4774f6a2015-03-23 11:42:55 -07004196 int top = Math.max(win.getDisplayFrameLw().top, win.getContentFrameLw().top);
satok1bc0a492012-04-25 22:47:12 +09004197 top += win.getGivenContentInsetsLw().top;
4198 if (mContentBottom > top) {
4199 mContentBottom = top;
4200 }
Dianne Hackborne30e02f2014-05-27 18:24:45 -07004201 if (mVoiceContentBottom > top) {
4202 mVoiceContentBottom = top;
4203 }
satok1bc0a492012-04-25 22:47:12 +09004204 top = win.getVisibleFrameLw().top;
4205 top += win.getGivenVisibleInsetsLw().top;
4206 if (mCurBottom > top) {
4207 mCurBottom = top;
4208 }
Craig Mautnereda67292013-04-28 13:50:14 -07004209 if (DEBUG_LAYOUT) Slog.v(TAG, "Input method: mDockBottom="
satok1bc0a492012-04-25 22:47:12 +09004210 + mDockBottom + " mContentBottom="
4211 + mContentBottom + " mCurBottom=" + mCurBottom);
4212 }
4213
Dianne Hackborne30e02f2014-05-27 18:24:45 -07004214 private void offsetVoiceInputWindowLw(WindowState win) {
Craig Mautner4774f6a2015-03-23 11:42:55 -07004215 int top = Math.max(win.getDisplayFrameLw().top, win.getContentFrameLw().top);
Dianne Hackbornae6688b2015-02-11 17:02:41 -08004216 top += win.getGivenContentInsetsLw().top;
4217 if (mVoiceContentBottom > top) {
4218 mVoiceContentBottom = top;
Dianne Hackborne30e02f2014-05-27 18:24:45 -07004219 }
4220 }
4221
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004222 /** {@inheritDoc} */
Craig Mautner61ac6bb2012-02-02 17:29:33 -08004223 @Override
4224 public void finishLayoutLw() {
4225 return;
Dianne Hackborn5f3063e2010-03-10 16:01:58 -08004226 }
4227
4228 /** {@inheritDoc} */
Craig Mautnerad09bcc2012-10-08 13:33:11 -07004229 @Override
Craig Mautner39834192012-09-02 07:47:24 -07004230 public void beginPostLayoutPolicyLw(int displayWidth, int displayHeight) {
Dianne Hackborn5f3063e2010-03-10 16:01:58 -08004231 mTopFullscreenOpaqueWindowState = null;
Adrian Rooscd3884d2015-02-18 17:25:23 +01004232 mTopFullscreenOpaqueOrDimmingWindowState = null;
Craig Mautner2bc789b2014-03-19 19:48:38 -07004233 mAppsToBeHidden.clear();
Jorim Jaggic13fcac2014-09-11 17:36:57 +02004234 mAppsThatDismissKeyguard.clear();
Dianne Hackborn5f3063e2010-03-10 16:01:58 -08004235 mForceStatusBar = false;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07004236 mForceStatusBarFromKeyguard = false;
Selim Cinek4a4a2bddc2015-05-07 12:50:19 -07004237 mForceStatusBarTransparent = false;
Dianne Hackborn891d3fb2013-01-09 18:31:37 -08004238 mForcingShowNavBar = false;
4239 mForcingShowNavBarLayer = -1;
RoboErik8a2cfc32014-05-16 11:19:38 -07004240
Dianne Hackborn5f3063e2010-03-10 16:01:58 -08004241 mHideLockScreen = false;
4242 mAllowLockscreenWhenOn = false;
Craig Mautnerad09bcc2012-10-08 13:33:11 -07004243 mDismissKeyguard = DISMISS_KEYGUARD_NONE;
Dianne Hackborn7ad44382012-10-18 17:46:00 -07004244 mShowingLockscreen = false;
4245 mShowingDream = false;
Craig Mautnerc9457fa2014-06-06 14:27:48 -07004246 mWinShowWhenLocked = null;
Jim Millerab954542014-10-10 18:21:49 -07004247 mKeyguardSecure = isKeyguardSecure();
4248 mKeyguardSecureIncludingHidden = mKeyguardSecure
4249 && (mKeyguardDelegate != null && mKeyguardDelegate.isShowing());
Dianne Hackborn5f3063e2010-03-10 16:01:58 -08004250 }
4251
4252 /** {@inheritDoc} */
Craig Mautnerad09bcc2012-10-08 13:33:11 -07004253 @Override
Craig Mautnerc9457fa2014-06-06 14:27:48 -07004254 public void applyPostLayoutPolicyLw(WindowState win, WindowManager.LayoutParams attrs) {
Dianne Hackbornbc1aa7b2011-09-20 11:20:31 -07004255 if (DEBUG_LAYOUT) Slog.i(TAG, "Win " + win + ": isVisibleOrBehindKeyguardLw="
4256 + win.isVisibleOrBehindKeyguardLw());
John Spurlockc6d1c602014-01-17 15:22:06 -05004257 final int fl = PolicyControl.getWindowFlags(win, attrs);
John Spurlock414c1f02013-12-04 13:47:36 -05004258 if (mTopFullscreenOpaqueWindowState == null
4259 && win.isVisibleLw() && attrs.type == TYPE_INPUT_METHOD) {
4260 mForcingShowNavBar = true;
4261 mForcingShowNavBarLayer = win.getSurfaceLayer();
Dianne Hackborn891d3fb2013-01-09 18:31:37 -08004262 }
Selim Cinek4a4a2bddc2015-05-07 12:50:19 -07004263 if (attrs.type == TYPE_STATUS_BAR) {
4264 if ((attrs.privateFlags & PRIVATE_FLAG_KEYGUARD) != 0) {
4265 mForceStatusBarFromKeyguard = true;
4266 }
4267 if ((attrs.privateFlags & PRIVATE_FLAG_FORCE_STATUS_BAR_VISIBLE_TRANSPARENT) != 0) {
4268 mForceStatusBarTransparent = true;
4269 }
Jorim Jaggiafd4a552014-04-08 15:13:05 +02004270 }
Adrian Roos602c68e2015-04-24 16:03:47 -07004271
4272 boolean appWindow = attrs.type >= FIRST_APPLICATION_WINDOW
4273 && attrs.type < FIRST_SYSTEM_WINDOW;
4274 final boolean showWhenLocked = (fl & FLAG_SHOW_WHEN_LOCKED) != 0;
4275 final boolean dismissKeyguard = (fl & FLAG_DISMISS_KEYGUARD) != 0;
4276
Dianne Hackborn5f3063e2010-03-10 16:01:58 -08004277 if (mTopFullscreenOpaqueWindowState == null &&
Dianne Hackborn01b02a72012-01-12 14:05:03 -08004278 win.isVisibleOrBehindKeyguardLw() && !win.isGoneForLayoutLw()) {
John Spurlockc6d1c602014-01-17 15:22:06 -05004279 if ((fl & FLAG_FORCE_NOT_FULLSCREEN) != 0) {
Jorim Jaggi380ecb82014-03-14 17:25:20 +01004280 if ((attrs.privateFlags & PRIVATE_FLAG_KEYGUARD) != 0) {
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07004281 mForceStatusBarFromKeyguard = true;
4282 } else {
4283 mForceStatusBar = true;
4284 }
4285 }
Jorim Jaggi380ecb82014-03-14 17:25:20 +01004286 if ((attrs.privateFlags & PRIVATE_FLAG_KEYGUARD) != 0) {
Dianne Hackborn7ad44382012-10-18 17:46:00 -07004287 mShowingLockscreen = true;
Dianne Hackbornbc1aa7b2011-09-20 11:20:31 -07004288 }
Dianne Hackborn7ad44382012-10-18 17:46:00 -07004289 if (attrs.type == TYPE_DREAM) {
Jeff Brownc8018eb2012-10-29 21:33:27 -07004290 // If the lockscreen was showing when the dream started then wait
4291 // for the dream to draw before hiding the lockscreen.
4292 if (!mDreamingLockscreen
4293 || (win.isVisibleLw() && win.hasDrawnLw())) {
4294 mShowingDream = true;
Craig Mautnerab55e522014-03-03 13:26:03 -08004295 appWindow = true;
Dianne Hackborn7ad44382012-10-18 17:46:00 -07004296 }
4297 }
Craig Mautnerab55e522014-03-03 13:26:03 -08004298
Craig Mautnerab55e522014-03-03 13:26:03 -08004299 if (appWindow) {
Jorim Jaggic13fcac2014-09-11 17:36:57 +02004300 final IApplicationToken appToken = win.getAppToken();
4301 if (showWhenLocked) {
Craig Mautnerc9457fa2014-06-06 14:27:48 -07004302 // Remove any previous windows with the same appToken.
Jorim Jaggic13fcac2014-09-11 17:36:57 +02004303 mAppsToBeHidden.remove(appToken);
4304 mAppsThatDismissKeyguard.remove(appToken);
Craig Mautnerca0a1242014-12-02 12:25:14 -08004305 if (mAppsToBeHidden.isEmpty()) {
Craig Mautner192d6042014-12-02 23:24:48 -08004306 if (dismissKeyguard && !mKeyguardSecure) {
4307 mAppsThatDismissKeyguard.add(appToken);
4308 } else {
Craig Mautnerca0a1242014-12-02 12:25:14 -08004309 mWinShowWhenLocked = win;
4310 mHideLockScreen = true;
4311 mForceStatusBarFromKeyguard = false;
Craig Mautnerca0a1242014-12-02 12:25:14 -08004312 }
Craig Mautnerc9457fa2014-06-06 14:27:48 -07004313 }
Jorim Jaggic13fcac2014-09-11 17:36:57 +02004314 } else if (dismissKeyguard) {
Jim Millerab954542014-10-10 18:21:49 -07004315 if (mKeyguardSecure) {
Jorim Jaggic13fcac2014-09-11 17:36:57 +02004316 mAppsToBeHidden.add(appToken);
4317 } else {
4318 mAppsToBeHidden.remove(appToken);
4319 }
4320 mAppsThatDismissKeyguard.add(appToken);
Craig Mautner2bc789b2014-03-19 19:48:38 -07004321 } else {
Jorim Jaggic13fcac2014-09-11 17:36:57 +02004322 mAppsToBeHidden.add(appToken);
Craig Mautner2bc789b2014-03-19 19:48:38 -07004323 }
Craig Mautnerab55e522014-03-03 13:26:03 -08004324 if (attrs.x == 0 && attrs.y == 0
4325 && attrs.width == WindowManager.LayoutParams.MATCH_PARENT
4326 && attrs.height == WindowManager.LayoutParams.MATCH_PARENT) {
4327 if (DEBUG_LAYOUT) Slog.v(TAG, "Fullscreen window: " + win);
4328 mTopFullscreenOpaqueWindowState = win;
Adrian Rooscd3884d2015-02-18 17:25:23 +01004329 if (mTopFullscreenOpaqueOrDimmingWindowState == null) {
4330 mTopFullscreenOpaqueOrDimmingWindowState = win;
4331 }
Jorim Jaggic13fcac2014-09-11 17:36:57 +02004332 if (!mAppsThatDismissKeyguard.isEmpty() &&
4333 mDismissKeyguard == DISMISS_KEYGUARD_NONE) {
4334 if (DEBUG_LAYOUT) Slog.v(TAG,
4335 "Setting mDismissKeyguard true by win " + win);
tingna_sunge785ffa2015-05-12 13:23:15 +08004336 mDismissKeyguard = (mWinDismissingKeyguard == win
4337 && mSecureDismissingKeyguard == mKeyguardSecure)
4338 ? DISMISS_KEYGUARD_CONTINUE : DISMISS_KEYGUARD_START;
Jorim Jaggic13fcac2014-09-11 17:36:57 +02004339 mWinDismissingKeyguard = win;
tingna_sunge785ffa2015-05-12 13:23:15 +08004340 mSecureDismissingKeyguard = mKeyguardSecure;
Jim Millerab954542014-10-10 18:21:49 -07004341 mForceStatusBarFromKeyguard = mShowingLockscreen && mKeyguardSecure;
Jorim Jaggic13fcac2014-09-11 17:36:57 +02004342 } else if (mAppsToBeHidden.isEmpty() && showWhenLocked) {
4343 if (DEBUG_LAYOUT) Slog.v(TAG,
4344 "Setting mHideLockScreen to true by win " + win);
4345 mHideLockScreen = true;
4346 mForceStatusBarFromKeyguard = false;
Craig Mautnerab55e522014-03-03 13:26:03 -08004347 }
Craig Mautner00156ec2014-03-06 22:29:02 -08004348 if ((fl & FLAG_ALLOW_LOCK_WHILE_SCREEN_ON) != 0) {
Craig Mautnerab55e522014-03-03 13:26:03 -08004349 mAllowLockscreenWhenOn = true;
4350 }
Dianne Hackborn5f3063e2010-03-10 16:01:58 -08004351 }
Craig Mautnerc9457fa2014-06-06 14:27:48 -07004352
4353 if (mWinShowWhenLocked != null &&
Adrian Roos602c68e2015-04-24 16:03:47 -07004354 mWinShowWhenLocked.getAppToken() != win.getAppToken() &&
4355 (attrs.flags & FLAG_SHOW_WHEN_LOCKED) == 0) {
Craig Mautnerc9457fa2014-06-06 14:27:48 -07004356 win.hideLw(false);
4357 }
Dianne Hackborn5f3063e2010-03-10 16:01:58 -08004358 }
Adrian Roos602c68e2015-04-24 16:03:47 -07004359 } else if (mTopFullscreenOpaqueWindowState == null && mWinShowWhenLocked == null) {
4360 // No TopFullscreenOpaqueWindow is showing, but we found a SHOW_WHEN_LOCKED window
4361 // that is being hidden in an animation - keep the
4362 // keyguard hidden until the new window shows up and
4363 // we know whether to show the keyguard or not.
Adrian Roosb85e1ec2015-05-29 15:23:18 -07004364 if (win.isAnimatingLw() && appWindow && showWhenLocked && mKeyguardHidden) {
Adrian Roos602c68e2015-04-24 16:03:47 -07004365 mHideLockScreen = true;
4366 mWinShowWhenLocked = win;
4367 }
Dianne Hackborn5f3063e2010-03-10 16:01:58 -08004368 }
Adrian Rooscd3884d2015-02-18 17:25:23 +01004369 if (mTopFullscreenOpaqueOrDimmingWindowState == null
4370 && win.isVisibleOrBehindKeyguardLw() && !win.isGoneForLayoutLw()
4371 && win.isDimming()) {
4372 mTopFullscreenOpaqueOrDimmingWindowState = win;
4373 }
Dianne Hackborn5f3063e2010-03-10 16:01:58 -08004374 }
4375
4376 /** {@inheritDoc} */
Craig Mautnerad09bcc2012-10-08 13:33:11 -07004377 @Override
Craig Mautner39834192012-09-02 07:47:24 -07004378 public int finishPostLayoutPolicyLw() {
Craig Mautnerc5e73bf2015-04-21 15:41:26 +00004379 if (mWinShowWhenLocked != null && mTopFullscreenOpaqueWindowState != null &&
4380 mWinShowWhenLocked.getAppToken() != mTopFullscreenOpaqueWindowState.getAppToken()
4381 && isKeyguardLocked()) {
Craig Mautnerc9457fa2014-06-06 14:27:48 -07004382 // A dialog is dismissing the keyguard. Put the wallpaper behind it and hide the
4383 // fullscreen window.
4384 // TODO: Make sure FLAG_SHOW_WALLPAPER is restored when dialog is dismissed. Or not.
4385 mWinShowWhenLocked.getAttrs().flags |= FLAG_SHOW_WALLPAPER;
4386 mTopFullscreenOpaqueWindowState.hideLw(false);
4387 mTopFullscreenOpaqueWindowState = mWinShowWhenLocked;
4388 }
4389
Dianne Hackborn39c2d712009-09-22 11:41:31 -07004390 int changes = 0;
Joe Onorato93056472010-09-10 10:30:46 -04004391 boolean topIsFullscreen = false;
Daniel Sandlere02d8082010-10-08 15:13:22 -04004392
4393 final WindowManager.LayoutParams lp = (mTopFullscreenOpaqueWindowState != null)
4394 ? mTopFullscreenOpaqueWindowState.getAttrs()
4395 : null;
4396
Jeff Brownc8018eb2012-10-29 21:33:27 -07004397 // If we are not currently showing a dream then remember the current
4398 // lockscreen state. We will use this to determine whether the dream
4399 // started while the lockscreen was showing and remember this state
4400 // while the dream is showing.
Dianne Hackborn7ad44382012-10-18 17:46:00 -07004401 if (!mShowingDream) {
4402 mDreamingLockscreen = mShowingLockscreen;
Jeff Brown061ea992015-04-17 19:55:47 -07004403 if (mDreamingSleepTokenNeeded) {
4404 mDreamingSleepTokenNeeded = false;
4405 mHandler.obtainMessage(MSG_UPDATE_DREAMING_SLEEP_TOKEN, 0, 1).sendToTarget();
4406 }
4407 } else {
4408 if (!mDreamingSleepTokenNeeded) {
4409 mDreamingSleepTokenNeeded = true;
4410 mHandler.obtainMessage(MSG_UPDATE_DREAMING_SLEEP_TOKEN, 1, 1).sendToTarget();
4411 }
Dianne Hackborn7ad44382012-10-18 17:46:00 -07004412 }
4413
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004414 if (mStatusBar != null) {
Craig Mautnereda67292013-04-28 13:50:14 -07004415 if (DEBUG_LAYOUT) Slog.i(TAG, "force=" + mForceStatusBar
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07004416 + " forcefkg=" + mForceStatusBarFromKeyguard
Dianne Hackbornd70bc2f2009-10-06 23:25:51 -07004417 + " top=" + mTopFullscreenOpaqueWindowState);
Selim Cinek4a4a2bddc2015-05-07 12:50:19 -07004418 boolean shouldBeTransparent = mForceStatusBarTransparent
4419 && !mForceStatusBar
4420 && !mForceStatusBarFromKeyguard;
4421 if (!shouldBeTransparent) {
4422 mStatusBarController.setShowTransparent(false /* transparent */);
4423 } else if (!mStatusBar.isVisibleLw()) {
4424 mStatusBarController.setShowTransparent(true /* transparent */);
4425 }
4426 if (mForceStatusBar || mForceStatusBarFromKeyguard || mForceStatusBarTransparent) {
Craig Mautnereda67292013-04-28 13:50:14 -07004427 if (DEBUG_LAYOUT) Slog.v(TAG, "Showing status bar: forced");
John Spurlock27735a42013-08-14 17:57:38 -04004428 if (mStatusBarController.setBarShowingLw(true)) {
4429 changes |= FINISH_LAYOUT_REDO_LAYOUT;
4430 }
Craig Mautner81defc72013-10-29 11:10:42 -07004431 // Maintain fullscreen layout until incoming animation is complete.
4432 topIsFullscreen = mTopIsFullscreen && mStatusBar.isAnimatingLw();
John Spurlockf92b6162013-11-11 15:01:16 -05004433 // Transient status bar on the lockscreen is not allowed
4434 if (mForceStatusBarFromKeyguard && mStatusBarController.isTransientShowing()) {
4435 mStatusBarController.updateVisibilityLw(false /*transientAllowed*/,
4436 mLastSystemUiFlags, mLastSystemUiFlags);
4437 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004438 } else if (mTopFullscreenOpaqueWindowState != null) {
John Spurlockc6d1c602014-01-17 15:22:06 -05004439 final int fl = PolicyControl.getWindowFlags(null, lp);
Joe Onorato93056472010-09-10 10:30:46 -04004440 if (localLOGV) {
Craig Mautnereda67292013-04-28 13:50:14 -07004441 Slog.d(TAG, "frame: " + mTopFullscreenOpaqueWindowState.getFrameLw()
Joe Onorato93056472010-09-10 10:30:46 -04004442 + " shown frame: " + mTopFullscreenOpaqueWindowState.getShownFrameLw());
Craig Mautnereda67292013-04-28 13:50:14 -07004443 Slog.d(TAG, "attr: " + mTopFullscreenOpaqueWindowState.getAttrs()
John Spurlockc6d1c602014-01-17 15:22:06 -05004444 + " lp.flags=0x" + Integer.toHexString(fl));
Joe Onorato93056472010-09-10 10:30:46 -04004445 }
John Spurlockc6d1c602014-01-17 15:22:06 -05004446 topIsFullscreen = (fl & WindowManager.LayoutParams.FLAG_FULLSCREEN) != 0
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07004447 || (mLastSystemUiFlags & View.SYSTEM_UI_FLAG_FULLSCREEN) != 0;
Joe Onorato93056472010-09-10 10:30:46 -04004448 // The subtle difference between the window for mTopFullscreenOpaqueWindowState
Mark Dolinerd0646dc2014-08-27 16:04:02 -07004449 // and mTopIsFullscreen is that mTopIsFullscreen is set only if the window
Joe Onorato93056472010-09-10 10:30:46 -04004450 // has the FLAG_FULLSCREEN set. Not sure if there is another way that to be the
4451 // case though.
John Spurlock27735a42013-08-14 17:57:38 -04004452 if (mStatusBarController.isTransientShowing()) {
4453 if (mStatusBarController.setBarShowingLw(true)) {
John Spurlock32beb2c2013-03-11 10:16:47 -04004454 changes |= FINISH_LAYOUT_REDO_LAYOUT;
4455 }
4456 } else if (topIsFullscreen) {
Craig Mautnereda67292013-04-28 13:50:14 -07004457 if (DEBUG_LAYOUT) Slog.v(TAG, "** HIDING status bar");
John Spurlock27735a42013-08-14 17:57:38 -04004458 if (mStatusBarController.setBarShowingLw(false)) {
Dianne Hackbornf87d1962012-04-04 12:48:24 -07004459 changes |= FINISH_LAYOUT_REDO_LAYOUT;
Craig Mautnereda67292013-04-28 13:50:14 -07004460 } else {
Craig Mautnerc5a6e442013-06-05 17:22:35 -07004461 if (DEBUG_LAYOUT) Slog.v(TAG, "Status bar already hiding");
Daniel Sandler40427442010-07-16 11:44:52 -04004462 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004463 } else {
Craig Mautnereda67292013-04-28 13:50:14 -07004464 if (DEBUG_LAYOUT) Slog.v(TAG, "** SHOWING status bar: top is not fullscreen");
John Spurlock27735a42013-08-14 17:57:38 -04004465 if (mStatusBarController.setBarShowingLw(true)) {
4466 changes |= FINISH_LAYOUT_REDO_LAYOUT;
4467 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004468 }
4469 }
4470 }
Daniel Sandlere02d8082010-10-08 15:13:22 -04004471
Craig Mautner81defc72013-10-29 11:10:42 -07004472 if (mTopIsFullscreen != topIsFullscreen) {
4473 if (!topIsFullscreen) {
4474 // Force another layout when status bar becomes fully shown.
4475 changes |= FINISH_LAYOUT_REDO_LAYOUT;
4476 }
4477 mTopIsFullscreen = topIsFullscreen;
4478 }
Daniel Sandlere02d8082010-10-08 15:13:22 -04004479
Craig Mautner39834192012-09-02 07:47:24 -07004480 // Hide the key guard if a visible window explicitly specifies that it wants to be
4481 // displayed when the screen is locked.
Jorim Jaggi5cf17872014-03-26 18:31:48 +01004482 if (mKeyguardDelegate != null && mStatusBar != null) {
4483 if (localLOGV) Slog.v(TAG, "finishPostLayoutPolicyLw: mHideKeyguard="
4484 + mHideLockScreen);
Jim Millerab954542014-10-10 18:21:49 -07004485 if (mDismissKeyguard != DISMISS_KEYGUARD_NONE && !mKeyguardSecure) {
Jorim Jaggi5cf17872014-03-26 18:31:48 +01004486 mKeyguardHidden = true;
Jim Millerab954542014-10-10 18:21:49 -07004487 if (setKeyguardOccludedLw(true)) {
Dianne Hackborn39c2d712009-09-22 11:41:31 -07004488 changes |= FINISH_LAYOUT_REDO_LAYOUT
4489 | FINISH_LAYOUT_REDO_CONFIG
4490 | FINISH_LAYOUT_REDO_WALLPAPER;
4491 }
Jorim Jaggi5cf17872014-03-26 18:31:48 +01004492 if (mKeyguardDelegate.isShowing()) {
4493 mHandler.post(new Runnable() {
4494 @Override
4495 public void run() {
4496 mKeyguardDelegate.keyguardDone(false, false);
4497 }
4498 });
4499 }
4500 } else if (mHideLockScreen) {
4501 mKeyguardHidden = true;
Jorim Jaggi7d85ea92015-05-20 17:20:40 -07004502 mWinDismissingKeyguard = null;
Jim Millerab954542014-10-10 18:21:49 -07004503 if (setKeyguardOccludedLw(true)) {
Jorim Jaggi5cf17872014-03-26 18:31:48 +01004504 changes |= FINISH_LAYOUT_REDO_LAYOUT
4505 | FINISH_LAYOUT_REDO_CONFIG
4506 | FINISH_LAYOUT_REDO_WALLPAPER;
4507 }
4508 } else if (mDismissKeyguard != DISMISS_KEYGUARD_NONE) {
Jorim Jaggi7d85ea92015-05-20 17:20:40 -07004509 mKeyguardHidden = false;
4510 if (setKeyguardOccludedLw(false)) {
4511 changes |= FINISH_LAYOUT_REDO_LAYOUT
4512 | FINISH_LAYOUT_REDO_CONFIG
4513 | FINISH_LAYOUT_REDO_WALLPAPER;
4514 }
Jorim Jaggi5cf17872014-03-26 18:31:48 +01004515 if (mDismissKeyguard == DISMISS_KEYGUARD_START) {
4516 // Only launch the next keyguard unlock window once per window.
Jorim Jaggi5cf17872014-03-26 18:31:48 +01004517 mHandler.post(new Runnable() {
4518 @Override
4519 public void run() {
4520 mKeyguardDelegate.dismiss();
4521 }
4522 });
4523 }
4524 } else {
4525 mWinDismissingKeyguard = null;
tingna_sunge785ffa2015-05-12 13:23:15 +08004526 mSecureDismissingKeyguard = false;
Jorim Jaggi5cf17872014-03-26 18:31:48 +01004527 mKeyguardHidden = false;
Jim Millerab954542014-10-10 18:21:49 -07004528 if (setKeyguardOccludedLw(false)) {
Jorim Jaggi5cf17872014-03-26 18:31:48 +01004529 changes |= FINISH_LAYOUT_REDO_LAYOUT
4530 | FINISH_LAYOUT_REDO_CONFIG
4531 | FINISH_LAYOUT_REDO_WALLPAPER;
4532 }
Suchi Amalapurapu9cdc9032009-05-14 18:01:07 -07004533 }
4534 }
Joe Onorato664644d2011-01-23 17:53:23 -08004535
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07004536 if ((updateSystemUiVisibilityLw()&SYSTEM_UI_CHANGING_LAYOUT) != 0) {
Dianne Hackborndf89e652011-10-06 22:35:11 -07004537 // If the navigation bar has been hidden or shown, we need to do another
4538 // layout pass to update that window.
4539 changes |= FINISH_LAYOUT_REDO_LAYOUT;
4540 }
Joe Onorato664644d2011-01-23 17:53:23 -08004541
Mike Lockwood28569302010-01-28 11:54:40 -05004542 // update since mAllowLockscreenWhenOn might have changed
4543 updateLockScreenTimeout();
Dianne Hackborn39c2d712009-09-22 11:41:31 -07004544 return changes;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004545 }
4546
Jorim Jaggi380ecb82014-03-14 17:25:20 +01004547 /**
Jim Millerab954542014-10-10 18:21:49 -07004548 * Updates the occluded state of the Keyguard.
Jorim Jaggi380ecb82014-03-14 17:25:20 +01004549 *
Jorim Jaggi380ecb82014-03-14 17:25:20 +01004550 * @return Whether the flags have changed and we have to redo the layout.
4551 */
Jim Millerab954542014-10-10 18:21:49 -07004552 private boolean setKeyguardOccludedLw(boolean isOccluded) {
4553 boolean wasOccluded = mKeyguardOccluded;
4554 boolean showing = mKeyguardDelegate.isShowing();
4555 if (wasOccluded && !isOccluded && showing) {
4556 mKeyguardOccluded = false;
4557 mKeyguardDelegate.setOccluded(false);
Jorim Jaggi380ecb82014-03-14 17:25:20 +01004558 mStatusBar.getAttrs().privateFlags |= PRIVATE_FLAG_KEYGUARD;
4559 mStatusBar.getAttrs().flags |= FLAG_SHOW_WALLPAPER;
4560 return true;
Jim Millerab954542014-10-10 18:21:49 -07004561 } else if (!wasOccluded && isOccluded && showing) {
4562 mKeyguardOccluded = true;
4563 mKeyguardDelegate.setOccluded(true);
Jorim Jaggi380ecb82014-03-14 17:25:20 +01004564 mStatusBar.getAttrs().privateFlags &= ~PRIVATE_FLAG_KEYGUARD;
4565 mStatusBar.getAttrs().flags &= ~FLAG_SHOW_WALLPAPER;
4566 return true;
4567 } else {
4568 return false;
4569 }
4570 }
4571
4572 private boolean isStatusBarKeyguard() {
4573 return mStatusBar != null
4574 && (mStatusBar.getAttrs().privateFlags & PRIVATE_FLAG_KEYGUARD) != 0;
4575 }
4576
Jose Lima9546b202014-07-02 17:21:51 -07004577 @Override
Dianne Hackborn08743722009-12-21 12:16:51 -08004578 public boolean allowAppAnimationsLw() {
Jorim Jaggi380ecb82014-03-14 17:25:20 +01004579 if (isStatusBarKeyguard() || mShowingDream) {
Craig Mautner28816302013-10-10 20:31:00 -07004580 // If keyguard or dreams is currently visible, no reason to animate behind it.
Dianne Hackborn08743722009-12-21 12:16:51 -08004581 return false;
4582 }
Dianne Hackborn08743722009-12-21 12:16:51 -08004583 return true;
4584 }
4585
Jose Lima9546b202014-07-02 17:21:51 -07004586 @Override
Dianne Hackborndf89e652011-10-06 22:35:11 -07004587 public int focusChangedLw(WindowState lastFocus, WindowState newFocus) {
Joe Onorato664644d2011-01-23 17:53:23 -08004588 mFocusedWindow = newFocus;
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07004589 if ((updateSystemUiVisibilityLw()&SYSTEM_UI_CHANGING_LAYOUT) != 0) {
Dianne Hackborndf89e652011-10-06 22:35:11 -07004590 // If the navigation bar has been hidden or shown, we need to do another
4591 // layout pass to update that window.
4592 return FINISH_LAYOUT_REDO_LAYOUT;
4593 }
4594 return 0;
Joe Onorato664644d2011-01-23 17:53:23 -08004595 }
4596
Dianne Hackborn0ecadf72009-03-31 18:00:37 -07004597 /** {@inheritDoc} */
Jose Lima9546b202014-07-02 17:21:51 -07004598 @Override
Jeff Brown46b9ac02010-04-22 18:58:52 -07004599 public void notifyLidSwitchChanged(long whenNanos, boolean lidOpen) {
4600 // lid changed state
Jeff Brownc458ce92012-04-30 14:58:40 -07004601 final int newLidState = lidOpen ? LID_OPEN : LID_CLOSED;
4602 if (newLidState == mLidState) {
4603 return;
4604 }
Jeff Brown01a98dd2011-09-20 15:08:29 -07004605
Jeff Brownc458ce92012-04-30 14:58:40 -07004606 mLidState = newLidState;
4607 applyLidSwitchState();
Jeff Brown01a98dd2011-09-20 15:08:29 -07004608 updateRotation(true);
Jeff Brownc458ce92012-04-30 14:58:40 -07004609
4610 if (lidOpen) {
Bryce Lee584a4452014-10-21 15:55:55 -07004611 wakeUp(SystemClock.uptimeMillis(), mAllowTheaterModeWakeFromLidSwitch);
Jeff Brownc458ce92012-04-30 14:58:40 -07004612 } else if (!mLidControlsSleep) {
Jeff Brown96307042012-07-27 15:51:34 -07004613 mPowerManager.userActivity(SystemClock.uptimeMillis(), false);
Jeff Brown46b9ac02010-04-22 18:58:52 -07004614 }
4615 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004616
Michael Wright3818c922014-09-02 13:59:07 -07004617 @Override
4618 public void notifyCameraLensCoverSwitchChanged(long whenNanos, boolean lensCovered) {
4619 int lensCoverState = lensCovered ? CAMERA_LENS_COVERED : CAMERA_LENS_UNCOVERED;
4620 if (mCameraLensCoverState == lensCoverState) {
4621 return;
4622 }
4623 if (mCameraLensCoverState == CAMERA_LENS_COVERED &&
4624 lensCoverState == CAMERA_LENS_UNCOVERED) {
4625 Intent intent;
4626 final boolean keyguardActive = mKeyguardDelegate == null ? false :
4627 mKeyguardDelegate.isShowing();
4628 if (keyguardActive) {
4629 intent = new Intent(MediaStore.INTENT_ACTION_STILL_IMAGE_CAMERA_SECURE);
4630 } else {
4631 intent = new Intent(MediaStore.INTENT_ACTION_STILL_IMAGE_CAMERA);
4632 }
Bryce Lee584a4452014-10-21 15:55:55 -07004633 wakeUp(whenNanos / 1000000, mAllowTheaterModeWakeFromCameraLens);
Bart Sears8b1c27c2015-03-18 23:51:02 +00004634 startActivityAsUser(intent, UserHandle.CURRENT_OR_SELF);
Michael Wright3818c922014-09-02 13:59:07 -07004635 }
4636 mCameraLensCoverState = lensCoverState;
4637 }
4638
Dianne Hackbornad7fa7f2011-01-07 14:06:50 -08004639 void setHdmiPlugged(boolean plugged) {
4640 if (mHdmiPlugged != plugged) {
4641 mHdmiPlugged = plugged;
Dianne Hackbornf87d1962012-04-04 12:48:24 -07004642 updateRotation(true, true);
Dianne Hackbornad7fa7f2011-01-07 14:06:50 -08004643 Intent intent = new Intent(ACTION_HDMI_PLUGGED);
Joe Onoratodc100302011-01-11 17:07:41 -08004644 intent.addFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY_BEFORE_BOOT);
Dianne Hackbornad7fa7f2011-01-07 14:06:50 -08004645 intent.putExtra(EXTRA_HDMI_PLUGGED_STATE, plugged);
Dianne Hackborn5ac72a22012-08-29 18:32:08 -07004646 mContext.sendStickyBroadcastAsUser(intent, UserHandle.ALL);
Dianne Hackbornad7fa7f2011-01-07 14:06:50 -08004647 }
4648 }
4649
Joe Onoratoea495d42011-04-06 11:41:11 -07004650 void initializeHdmiState() {
Joe Onorato7ba631f2011-05-04 15:28:00 -07004651 boolean plugged = false;
Joe Onoratoea495d42011-04-06 11:41:11 -07004652 // watch for HDMI plug messages if the hdmi switch exists
4653 if (new File("/sys/devices/virtual/switch/hdmi/state").exists()) {
4654 mHDMIObserver.startObserving("DEVPATH=/devices/virtual/switch/hdmi");
4655
Joe Onoratoea495d42011-04-06 11:41:11 -07004656 final String filename = "/sys/class/switch/hdmi/state";
4657 FileReader reader = null;
4658 try {
4659 reader = new FileReader(filename);
4660 char[] buf = new char[15];
4661 int n = reader.read(buf);
4662 if (n > 1) {
4663 plugged = 0 != Integer.parseInt(new String(buf, 0, n-1));
4664 }
4665 } catch (IOException ex) {
4666 Slog.w(TAG, "Couldn't read hdmi state from " + filename + ": " + ex);
4667 } catch (NumberFormatException ex) {
4668 Slog.w(TAG, "Couldn't read hdmi state from " + filename + ": " + ex);
4669 } finally {
4670 if (reader != null) {
4671 try {
4672 reader.close();
4673 } catch (IOException ex) {
4674 }
Joe Onoratodc100302011-01-11 17:07:41 -08004675 }
4676 }
4677 }
Joe Onorato7ba631f2011-05-04 15:28:00 -07004678 // This dance forces the code in setHdmiPlugged to run.
4679 // Always do this so the sticky intent is stuck (to false) if there is no hdmi.
4680 mHdmiPlugged = !plugged;
4681 setHdmiPlugged(!mHdmiPlugged);
Joe Onoratodc100302011-01-11 17:07:41 -08004682 }
4683
Dianne Hackbornc0e3f242011-08-19 14:19:10 -07004684 final Object mScreenshotLock = new Object();
Dianne Hackbornfc8fa632011-08-17 16:20:47 -07004685 ServiceConnection mScreenshotConnection = null;
Dianne Hackbornfc8fa632011-08-17 16:20:47 -07004686
Jeff Brownd5bb82d2011-10-12 13:57:59 -07004687 final Runnable mScreenshotTimeout = new Runnable() {
4688 @Override public void run() {
4689 synchronized (mScreenshotLock) {
4690 if (mScreenshotConnection != null) {
4691 mContext.unbindService(mScreenshotConnection);
4692 mScreenshotConnection = null;
Dianne Hackbornfc8fa632011-08-17 16:20:47 -07004693 }
Winson Chung9112ec32011-06-27 13:15:32 -07004694 }
Jeff Brownd5bb82d2011-10-12 13:57:59 -07004695 }
4696 };
4697
4698 // Assume this is called from the Handler thread.
4699 private void takeScreenshot() {
4700 synchronized (mScreenshotLock) {
4701 if (mScreenshotConnection != null) {
4702 return;
4703 }
4704 ComponentName cn = new ComponentName("com.android.systemui",
4705 "com.android.systemui.screenshot.TakeScreenshotService");
4706 Intent intent = new Intent();
4707 intent.setComponent(cn);
4708 ServiceConnection conn = new ServiceConnection() {
4709 @Override
4710 public void onServiceConnected(ComponentName name, IBinder service) {
4711 synchronized (mScreenshotLock) {
4712 if (mScreenshotConnection != this) {
4713 return;
4714 }
4715 Messenger messenger = new Messenger(service);
4716 Message msg = Message.obtain(null, 1);
4717 final ServiceConnection myConn = this;
4718 Handler h = new Handler(mHandler.getLooper()) {
4719 @Override
4720 public void handleMessage(Message msg) {
4721 synchronized (mScreenshotLock) {
4722 if (mScreenshotConnection == myConn) {
4723 mContext.unbindService(mScreenshotConnection);
4724 mScreenshotConnection = null;
4725 mHandler.removeCallbacks(mScreenshotTimeout);
4726 }
4727 }
4728 }
4729 };
4730 msg.replyTo = new Messenger(h);
Winson Chunga63bb842011-10-17 10:26:28 -07004731 msg.arg1 = msg.arg2 = 0;
4732 if (mStatusBar != null && mStatusBar.isVisibleLw())
4733 msg.arg1 = 1;
4734 if (mNavigationBar != null && mNavigationBar.isVisibleLw())
4735 msg.arg2 = 1;
Jeff Brownd5bb82d2011-10-12 13:57:59 -07004736 try {
4737 messenger.send(msg);
4738 } catch (RemoteException e) {
4739 }
4740 }
4741 }
4742 @Override
4743 public void onServiceDisconnected(ComponentName name) {}
4744 };
Amith Yamasani27b89e62013-01-16 12:30:11 -08004745 if (mContext.bindServiceAsUser(
4746 intent, conn, Context.BIND_AUTO_CREATE, UserHandle.CURRENT)) {
Jeff Brownd5bb82d2011-10-12 13:57:59 -07004747 mScreenshotConnection = conn;
4748 mHandler.postDelayed(mScreenshotTimeout, 10000);
4749 }
4750 }
Winson Chung9112ec32011-06-27 13:15:32 -07004751 }
4752
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004753 /** {@inheritDoc} */
Jeff Brown00fa7bd2010-07-02 15:37:36 -07004754 @Override
Jeff Brown037c33e2014-04-09 00:31:55 -07004755 public int interceptKeyBeforeQueueing(KeyEvent event, int policyFlags) {
Jeff Brown96307042012-07-27 15:51:34 -07004756 if (!mSystemBooted) {
4757 // If we have not yet booted, don't let key events do anything.
4758 return 0;
4759 }
4760
Jeff Brown037c33e2014-04-09 00:31:55 -07004761 final boolean interactive = (policyFlags & FLAG_INTERACTIVE) != 0;
Jeff Brown1f245102010-11-18 20:53:46 -08004762 final boolean down = event.getAction() == KeyEvent.ACTION_DOWN;
4763 final boolean canceled = event.isCanceled();
4764 final int keyCode = event.getKeyCode();
Jeff Browne20c9e02010-10-11 14:20:19 -07004765
Jeff Brown3122e442010-10-11 23:32:49 -07004766 final boolean isInjected = (policyFlags & WindowManagerPolicy.FLAG_INJECTED) != 0;
Jeff Brown3122e442010-10-11 23:32:49 -07004767
Mike Lockwoodc72b15f2009-11-28 20:58:22 -05004768 // If screen is off then we treat the case where the keyguard is open but hidden
4769 // the same as if it were open and in front.
4770 // This will prevent any keys other than the power button from waking the screen
4771 // when the keyguard is hidden by another activity.
Jim Miller5ecd8112013-01-09 18:50:26 -08004772 final boolean keyguardActive = (mKeyguardDelegate == null ? false :
Jeff Brown037c33e2014-04-09 00:31:55 -07004773 (interactive ?
Jim Millerab954542014-10-10 18:21:49 -07004774 isKeyguardShowingAndNotOccluded() :
Jim Miller5ecd8112013-01-09 18:50:26 -08004775 mKeyguardDelegate.isShowing()));
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004776
Jeff Brown40013652012-05-16 21:22:36 -07004777 if (DEBUG_INPUT) {
Jeff Brown00fa7bd2010-07-02 15:37:36 -07004778 Log.d(TAG, "interceptKeyTq keycode=" + keyCode
Jeff Brown037c33e2014-04-09 00:31:55 -07004779 + " interactive=" + interactive + " keyguardActive=" + keyguardActive
Jeff Brown26875502014-01-30 21:47:47 -08004780 + " policyFlags=" + Integer.toHexString(policyFlags));
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004781 }
4782
Jeff Brown037c33e2014-04-09 00:31:55 -07004783 // Basic policy based on interactive state.
Jeff Brown4d396052010-10-29 21:50:21 -07004784 int result;
Michael Wright337d9d22014-04-22 15:03:48 -07004785 boolean isWakeKey = (policyFlags & WindowManagerPolicy.FLAG_WAKE) != 0
4786 || event.isWakeKey();
Michael Wrightfc01f042014-09-08 14:12:24 -07004787 if (interactive || (isInjected && !isWakeKey)) {
RoboErikde9ba392014-09-26 12:51:01 -07004788 // When the device is interactive or the key is injected pass the
4789 // key to the application.
Jeff Brown4d396052010-10-29 21:50:21 -07004790 result = ACTION_PASS_TO_USER;
Jose Lima9546b202014-07-02 17:21:51 -07004791 isWakeKey = false;
Michael Wrightfc01f042014-09-08 14:12:24 -07004792 } else if (!interactive && shouldDispatchInputWhenNonInteractive()) {
4793 // If we're currently dozing with the screen on and the keyguard showing, pass the key
4794 // to the application but preserve its wake key status to make sure we still move
4795 // from dozing to fully interactive if we would normally go from off to fully
4796 // interactive.
4797 result = ACTION_PASS_TO_USER;
Jeff Brown4d396052010-10-29 21:50:21 -07004798 } else {
4799 // When the screen is off and the key is not injected, determine whether
4800 // to wake the device but don't pass the key to the application.
4801 result = 0;
Jeff Brown26875502014-01-30 21:47:47 -08004802 if (isWakeKey && (!down || !isWakeKeyWhenScreenOff(keyCode))) {
4803 isWakeKey = false;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004804 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004805 }
4806
Justin Kohd378ad72013-04-01 12:18:26 -07004807 // If the key would be handled globally, just return the result, don't worry about special
4808 // key processing.
Jeff Brown13f00f02014-10-31 14:45:50 -07004809 if (isValidGlobalKey(keyCode)
4810 && mGlobalKeyManager.shouldHandleGlobalKey(keyCode, event)) {
Michael Wright85b1af62014-06-04 14:51:58 -07004811 if (isWakeKey) {
Jeff Brown13f00f02014-10-31 14:45:50 -07004812 wakeUp(event.getEventTime(), mAllowTheaterModeWakeFromKey);
Michael Wright85b1af62014-06-04 14:51:58 -07004813 }
Justin Kohd378ad72013-04-01 12:18:26 -07004814 return result;
4815 }
4816
Jeff Brownbae8e772014-06-12 19:59:45 -07004817 boolean useHapticFeedback = down
4818 && (policyFlags & WindowManagerPolicy.FLAG_VIRTUAL) != 0
4819 && event.getRepeatCount() == 0;
4820
Jeff Brown4d396052010-10-29 21:50:21 -07004821 // Handle special keys.
4822 switch (keyCode) {
4823 case KeyEvent.KEYCODE_VOLUME_DOWN:
Jeff Brownb0418da2010-11-01 15:24:01 -07004824 case KeyEvent.KEYCODE_VOLUME_UP:
4825 case KeyEvent.KEYCODE_VOLUME_MUTE: {
RoboErik001c59c2015-01-26 15:53:51 -08004826 if (mUseTvRouting) {
4827 // On TVs volume keys never go to the foreground app
4828 result &= ~ACTION_PASS_TO_USER;
4829 }
Jeff Brownd5bb82d2011-10-12 13:57:59 -07004830 if (keyCode == KeyEvent.KEYCODE_VOLUME_DOWN) {
4831 if (down) {
Jeff Brown13f00f02014-10-31 14:45:50 -07004832 if (interactive && !mScreenshotChordVolumeDownKeyTriggered
Jeff Brownd5bb82d2011-10-12 13:57:59 -07004833 && (event.getFlags() & KeyEvent.FLAG_FALLBACK) == 0) {
Jeff Brown13f00f02014-10-31 14:45:50 -07004834 mScreenshotChordVolumeDownKeyTriggered = true;
4835 mScreenshotChordVolumeDownKeyTime = event.getDownTime();
4836 mScreenshotChordVolumeDownKeyConsumed = false;
Jeff Brownd5bb82d2011-10-12 13:57:59 -07004837 cancelPendingPowerKeyAction();
4838 interceptScreenshotChord();
4839 }
4840 } else {
Jeff Brown13f00f02014-10-31 14:45:50 -07004841 mScreenshotChordVolumeDownKeyTriggered = false;
Jeff Brownd5bb82d2011-10-12 13:57:59 -07004842 cancelPendingScreenshotChordAction();
4843 }
4844 } else if (keyCode == KeyEvent.KEYCODE_VOLUME_UP) {
4845 if (down) {
Jeff Brown13f00f02014-10-31 14:45:50 -07004846 if (interactive && !mScreenshotChordVolumeUpKeyTriggered
Jeff Brownd5bb82d2011-10-12 13:57:59 -07004847 && (event.getFlags() & KeyEvent.FLAG_FALLBACK) == 0) {
Jeff Brown13f00f02014-10-31 14:45:50 -07004848 mScreenshotChordVolumeUpKeyTriggered = true;
Jeff Brownd5bb82d2011-10-12 13:57:59 -07004849 cancelPendingPowerKeyAction();
4850 cancelPendingScreenshotChordAction();
4851 }
4852 } else {
Jeff Brown13f00f02014-10-31 14:45:50 -07004853 mScreenshotChordVolumeUpKeyTriggered = false;
Jeff Brownd5bb82d2011-10-12 13:57:59 -07004854 cancelPendingScreenshotChordAction();
4855 }
4856 }
Jeff Brown4d396052010-10-29 21:50:21 -07004857 if (down) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -07004858 TelecomManager telecomManager = getTelecommService();
4859 if (telecomManager != null) {
4860 if (telecomManager.isRinging()) {
Santos Cordon6848f722014-05-21 15:22:12 -07004861 // If an incoming call is ringing, either VOLUME key means
4862 // "silence ringer". We handle these keys here, rather than
4863 // in the InCallScreen, to make sure we'll respond to them
4864 // even if the InCallScreen hasn't come to the foreground yet.
4865 // Look for the DOWN event here, to agree with the "fallback"
4866 // behavior in the InCallScreen.
4867 Log.i(TAG, "interceptKeyBeforeQueueing:"
4868 + " VOLUME key-down while ringing: Silence ringer!");
Jeff Brown4d396052010-10-29 21:50:21 -07004869
Santos Cordon6848f722014-05-21 15:22:12 -07004870 // Silence the ringer. (It's safe to call this
4871 // even if the ringer has already been silenced.)
Tyler Gunnef9f6f92014-09-12 22:16:17 -07004872 telecomManager.silenceRinger();
Jeff Brown4d396052010-10-29 21:50:21 -07004873
Santos Cordon6848f722014-05-21 15:22:12 -07004874 // And *don't* pass this key thru to the current activity
4875 // (which is probably the InCallScreen.)
4876 result &= ~ACTION_PASS_TO_USER;
4877 break;
4878 }
Tyler Gunnef9f6f92014-09-12 22:16:17 -07004879 if (telecomManager.isInCall()
Santos Cordon6848f722014-05-21 15:22:12 -07004880 && (result & ACTION_PASS_TO_USER) == 0) {
4881 // If we are in call but we decided not to pass the key to
RoboErik430fc482014-06-12 15:49:20 -07004882 // the application, just pass it to the session service.
4883
4884 MediaSessionLegacyHelper.getHelper(mContext)
RoboErik3c45c292014-07-08 16:47:31 -07004885 .sendVolumeKeyEvent(event, false);
Santos Cordon6848f722014-05-21 15:22:12 -07004886 break;
Jeff Brown4d396052010-10-29 21:50:21 -07004887 }
4888 }
4889
RoboErik430fc482014-06-12 15:49:20 -07004890 if ((result & ACTION_PASS_TO_USER) == 0) {
RoboErik001c59c2015-01-26 15:53:51 -08004891 if (mUseTvRouting) {
4892 dispatchDirectAudioEvent(event);
4893 } else {
4894 // If we aren't passing to the user and no one else
4895 // handled it send it to the session manager to
4896 // figure out.
4897 MediaSessionLegacyHelper.getHelper(mContext)
4898 .sendVolumeKeyEvent(event, true);
4899 }
Jeff Brown4d396052010-10-29 21:50:21 -07004900 break;
4901 }
4902 }
4903 break;
4904 }
4905
4906 case KeyEvent.KEYCODE_ENDCALL: {
4907 result &= ~ACTION_PASS_TO_USER;
4908 if (down) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -07004909 TelecomManager telecomManager = getTelecommService();
Jeff Brown4d396052010-10-29 21:50:21 -07004910 boolean hungUp = false;
Tyler Gunnef9f6f92014-09-12 22:16:17 -07004911 if (telecomManager != null) {
4912 hungUp = telecomManager.endCall();
Jeff Brown4d396052010-10-29 21:50:21 -07004913 }
Jeff Brown13f00f02014-10-31 14:45:50 -07004914 if (interactive && !hungUp) {
4915 mEndCallKeyHandled = false;
4916 mHandler.postDelayed(mEndCallLongPress,
4917 ViewConfiguration.get(mContext).getDeviceGlobalActionKeyTimeout());
4918 } else {
4919 mEndCallKeyHandled = true;
4920 }
Jeff Brown4d396052010-10-29 21:50:21 -07004921 } else {
Jeff Brown13f00f02014-10-31 14:45:50 -07004922 if (!mEndCallKeyHandled) {
4923 mHandler.removeCallbacks(mEndCallLongPress);
4924 if (!canceled) {
4925 if ((mEndcallBehavior
4926 & Settings.System.END_BUTTON_BEHAVIOR_HOME) != 0) {
4927 if (goHome()) {
4928 break;
4929 }
Dianne Hackborn0041e972009-07-24 17:14:43 -07004930 }
Jeff Brown13f00f02014-10-31 14:45:50 -07004931 if ((mEndcallBehavior
4932 & Settings.System.END_BUTTON_BEHAVIOR_SLEEP) != 0) {
4933 mPowerManager.goToSleep(event.getEventTime(),
4934 PowerManager.GO_TO_SLEEP_REASON_POWER_BUTTON, 0);
4935 isWakeKey = false;
4936 }
Jeff Brown4d396052010-10-29 21:50:21 -07004937 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004938 }
Jeff Brown4d396052010-10-29 21:50:21 -07004939 }
4940 break;
4941 }
4942
4943 case KeyEvent.KEYCODE_POWER: {
4944 result &= ~ACTION_PASS_TO_USER;
Jeff Brown13f00f02014-10-31 14:45:50 -07004945 isWakeKey = false; // wake-up will be handled separately
Jeff Brown4d396052010-10-29 21:50:21 -07004946 if (down) {
Jeff Brown13f00f02014-10-31 14:45:50 -07004947 interceptPowerKeyDown(event, interactive);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004948 } else {
Jeff Brown13f00f02014-10-31 14:45:50 -07004949 interceptPowerKeyUp(event, interactive, canceled);
Jeff Brown4d396052010-10-29 21:50:21 -07004950 }
4951 break;
4952 }
4953
Jeff Brown6212a492014-03-07 13:58:47 -08004954 case KeyEvent.KEYCODE_SLEEP: {
4955 result &= ~ACTION_PASS_TO_USER;
Filip Gruszczynskia483a1d2015-03-17 19:06:58 +00004956 isWakeKey = false;
Jeff Brownbae8e772014-06-12 19:59:45 -07004957 if (!mPowerManager.isInteractive()) {
4958 useHapticFeedback = false; // suppress feedback if already non-interactive
4959 }
Nick Vaccarob593a812015-05-15 11:23:05 -07004960 if (down) {
4961 sleepPress(event.getEventTime());
4962 } else {
4963 sleepRelease(event.getEventTime());
4964 }
Jeff Brown6212a492014-03-07 13:58:47 -08004965 break;
4966 }
4967
4968 case KeyEvent.KEYCODE_WAKEUP: {
4969 result &= ~ACTION_PASS_TO_USER;
Jose Lima9546b202014-07-02 17:21:51 -07004970 isWakeKey = true;
Jeff Brown6212a492014-03-07 13:58:47 -08004971 break;
4972 }
4973
Jeff Brown4d396052010-10-29 21:50:21 -07004974 case KeyEvent.KEYCODE_MEDIA_PLAY:
4975 case KeyEvent.KEYCODE_MEDIA_PAUSE:
4976 case KeyEvent.KEYCODE_MEDIA_PLAY_PAUSE:
Jeff Brown4d396052010-10-29 21:50:21 -07004977 case KeyEvent.KEYCODE_HEADSETHOOK:
4978 case KeyEvent.KEYCODE_MUTE:
4979 case KeyEvent.KEYCODE_MEDIA_STOP:
4980 case KeyEvent.KEYCODE_MEDIA_NEXT:
4981 case KeyEvent.KEYCODE_MEDIA_PREVIOUS:
4982 case KeyEvent.KEYCODE_MEDIA_REWIND:
4983 case KeyEvent.KEYCODE_MEDIA_RECORD:
Jaekyun Seokbfdad8e2013-07-08 13:53:21 +09004984 case KeyEvent.KEYCODE_MEDIA_FAST_FORWARD:
4985 case KeyEvent.KEYCODE_MEDIA_AUDIO_TRACK: {
RoboErikde9ba392014-09-26 12:51:01 -07004986 if (MediaSessionLegacyHelper.getHelper(mContext).isGlobalPriorityActive()) {
4987 // If the global session is active pass all media keys to it
4988 // instead of the active window.
4989 result &= ~ACTION_PASS_TO_USER;
4990 }
Jeff Brown4d396052010-10-29 21:50:21 -07004991 if ((result & ACTION_PASS_TO_USER) == 0) {
4992 // Only do this if we would otherwise not pass it to the user. In that
4993 // case, the PhoneWindow class will do the same thing, except it will
4994 // only do it if the showing app doesn't process the key on its own.
Jeff Brown40013652012-05-16 21:22:36 -07004995 // Note that we need to make a copy of the key event here because the
4996 // original key event will be recycled when we return.
Jeff Brown4d396052010-10-29 21:50:21 -07004997 mBroadcastWakeLock.acquire();
Jeff Brown40013652012-05-16 21:22:36 -07004998 Message msg = mHandler.obtainMessage(MSG_DISPATCH_MEDIA_KEY_WITH_WAKE_LOCK,
4999 new KeyEvent(event));
5000 msg.setAsynchronous(true);
5001 msg.sendToTarget();
Jeff Brown4d396052010-10-29 21:50:21 -07005002 }
5003 break;
Jeff Brown00fa7bd2010-07-02 15:37:36 -07005004 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005005
Jeff Brown4d396052010-10-29 21:50:21 -07005006 case KeyEvent.KEYCODE_CALL: {
5007 if (down) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -07005008 TelecomManager telecomManager = getTelecommService();
5009 if (telecomManager != null) {
5010 if (telecomManager.isRinging()) {
Santos Cordon6848f722014-05-21 15:22:12 -07005011 Log.i(TAG, "interceptKeyBeforeQueueing:"
5012 + " CALL key-down while ringing: Answer the call!");
Tyler Gunnef9f6f92014-09-12 22:16:17 -07005013 telecomManager.acceptRingingCall();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005014
Santos Cordon6848f722014-05-21 15:22:12 -07005015 // And *don't* pass this key thru to the current activity
5016 // (which is presumably the InCallScreen.)
5017 result &= ~ACTION_PASS_TO_USER;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005018 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005019 }
Jeff Brown00fa7bd2010-07-02 15:37:36 -07005020 }
Jeff Brown4d396052010-10-29 21:50:21 -07005021 break;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005022 }
Michael Wright869a67c2014-08-26 19:33:06 -07005023 case KeyEvent.KEYCODE_VOICE_ASSIST: {
5024 // Only do this if we would otherwise not pass it to the user. In that case,
5025 // interceptKeyBeforeDispatching would apply a similar but different policy in
5026 // order to invoke voice assist actions. Note that we need to make a copy of the
5027 // key event here because the original key event will be recycled when we return.
5028 if ((result & ACTION_PASS_TO_USER) == 0 && !down) {
5029 mBroadcastWakeLock.acquire();
5030 Message msg = mHandler.obtainMessage(MSG_LAUNCH_VOICE_ASSIST_WITH_WAKE_LOCK,
5031 keyguardActive ? 1 : 0, 0);
5032 msg.setAsynchronous(true);
5033 msg.sendToTarget();
5034 }
5035 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005036 }
Jeff Brown26875502014-01-30 21:47:47 -08005037
Jeff Brownbae8e772014-06-12 19:59:45 -07005038 if (useHapticFeedback) {
5039 performHapticFeedbackLw(null, HapticFeedbackConstants.VIRTUAL_KEY, false);
5040 }
5041
Jeff Brown26875502014-01-30 21:47:47 -08005042 if (isWakeKey) {
Jeff Brown13f00f02014-10-31 14:45:50 -07005043 wakeUp(event.getEventTime(), mAllowTheaterModeWakeFromKey);
Jeff Brown26875502014-01-30 21:47:47 -08005044 }
Bryce Lee584a4452014-10-21 15:55:55 -07005045
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005046 return result;
5047 }
5048
Jeff Brown1c2e4942012-11-06 16:32:01 -08005049 /**
Jeff Brown13f00f02014-10-31 14:45:50 -07005050 * Returns true if the key can have global actions attached to it.
5051 * We reserve all power management keys for the system since they require
5052 * very careful handling.
5053 */
5054 private static boolean isValidGlobalKey(int keyCode) {
5055 switch (keyCode) {
5056 case KeyEvent.KEYCODE_POWER:
5057 case KeyEvent.KEYCODE_WAKEUP:
5058 case KeyEvent.KEYCODE_SLEEP:
5059 return false;
5060 default:
5061 return true;
5062 }
5063 }
5064
5065 /**
Jeff Brown1c2e4942012-11-06 16:32:01 -08005066 * When the screen is off we ignore some keys that might otherwise typically
5067 * be considered wake keys. We filter them out here.
5068 *
5069 * {@link KeyEvent#KEYCODE_POWER} is notably absent from this list because it
5070 * is always considered a wake key.
5071 */
5072 private boolean isWakeKeyWhenScreenOff(int keyCode) {
5073 switch (keyCode) {
5074 // ignore volume keys unless docked
5075 case KeyEvent.KEYCODE_VOLUME_UP:
5076 case KeyEvent.KEYCODE_VOLUME_DOWN:
5077 case KeyEvent.KEYCODE_VOLUME_MUTE:
5078 return mDockMode != Intent.EXTRA_DOCK_STATE_UNDOCKED;
5079
5080 // ignore media and camera keys
5081 case KeyEvent.KEYCODE_MUTE:
5082 case KeyEvent.KEYCODE_HEADSETHOOK:
5083 case KeyEvent.KEYCODE_MEDIA_PLAY:
5084 case KeyEvent.KEYCODE_MEDIA_PAUSE:
5085 case KeyEvent.KEYCODE_MEDIA_PLAY_PAUSE:
5086 case KeyEvent.KEYCODE_MEDIA_STOP:
5087 case KeyEvent.KEYCODE_MEDIA_NEXT:
5088 case KeyEvent.KEYCODE_MEDIA_PREVIOUS:
5089 case KeyEvent.KEYCODE_MEDIA_REWIND:
5090 case KeyEvent.KEYCODE_MEDIA_RECORD:
5091 case KeyEvent.KEYCODE_MEDIA_FAST_FORWARD:
Jaekyun Seokbfdad8e2013-07-08 13:53:21 +09005092 case KeyEvent.KEYCODE_MEDIA_AUDIO_TRACK:
Jeff Brown1c2e4942012-11-06 16:32:01 -08005093 case KeyEvent.KEYCODE_CAMERA:
5094 return false;
5095 }
5096 return true;
5097 }
5098
5099
Jeff Brown56194eb2011-03-02 19:23:13 -08005100 /** {@inheritDoc} */
5101 @Override
Michael Wright70af00a2014-09-03 19:30:20 -07005102 public int interceptMotionBeforeQueueingNonInteractive(long whenNanos, int policyFlags) {
5103 if ((policyFlags & FLAG_WAKE) != 0) {
Bryce Lee5c138322014-11-03 08:26:09 -08005104 if (wakeUp(whenNanos / 1000000, mAllowTheaterModeWakeFromMotion)) {
5105 return 0;
5106 }
Michael Wright70af00a2014-09-03 19:30:20 -07005107 }
Bryce Lee5c138322014-11-03 08:26:09 -08005108
Michael Wright70af00a2014-09-03 19:30:20 -07005109 if (shouldDispatchInputWhenNonInteractive()) {
5110 return ACTION_PASS_TO_USER;
5111 }
Bryce Lee5c138322014-11-03 08:26:09 -08005112
Bryce Lee812d7022014-11-10 13:33:28 -08005113 // If we have not passed the action up and we are in theater mode without dreaming,
5114 // there will be no dream to intercept the touch and wake into ambient. The device should
5115 // wake up in this case.
5116 if (isTheaterModeEnabled() && (policyFlags & FLAG_WAKE) != 0) {
5117 wakeUp(whenNanos / 1000000, mAllowTheaterModeWakeFromMotionWhenNotDreaming);
5118 }
5119
Jeff Brown037c33e2014-04-09 00:31:55 -07005120 return 0;
Jeff Brown56194eb2011-03-02 19:23:13 -08005121 }
5122
Michael Wright70af00a2014-09-03 19:30:20 -07005123 private boolean shouldDispatchInputWhenNonInteractive() {
Bryce Lee5c138322014-11-03 08:26:09 -08005124 // Send events to keyguard while the screen is on.
Jim Millerab954542014-10-10 18:21:49 -07005125 if (isKeyguardShowingAndNotOccluded() && mDisplay != null
5126 && mDisplay.getState() != Display.STATE_OFF) {
Bryce Lee5c138322014-11-03 08:26:09 -08005127 return true;
5128 }
5129
5130 // Send events to a dozing dream even if the screen is off since the dream
5131 // is in control of the state of the screen.
5132 IDreamManager dreamManager = getDreamManager();
5133
5134 try {
5135 if (dreamManager != null && dreamManager.isDreaming()) {
5136 return true;
5137 }
5138 } catch (RemoteException e) {
5139 Slog.e(TAG, "RemoteException when checking if dreaming", e);
5140 }
5141
5142 // Otherwise, consume events since the user can't see what is being
5143 // interacted with.
5144 return false;
Michael Wright70af00a2014-09-03 19:30:20 -07005145 }
5146
RoboErik001c59c2015-01-26 15:53:51 -08005147 private void dispatchDirectAudioEvent(KeyEvent event) {
5148 if (event.getAction() != KeyEvent.ACTION_DOWN) {
5149 return;
5150 }
5151 int keyCode = event.getKeyCode();
John Spurlockb94f2d62015-03-17 14:11:57 -04005152 int flags = AudioManager.FLAG_SHOW_UI | AudioManager.FLAG_PLAY_SOUND
5153 | AudioManager.FLAG_FROM_KEY;
RoboErik001c59c2015-01-26 15:53:51 -08005154 String pkgName = mContext.getOpPackageName();
5155 switch (keyCode) {
5156 case KeyEvent.KEYCODE_VOLUME_UP:
5157 try {
John Spurlockee5ad722015-03-03 16:17:21 -05005158 getAudioService().adjustSuggestedStreamVolume(AudioManager.ADJUST_RAISE,
John Spurlock90874332015-03-10 16:00:54 -04005159 AudioManager.USE_DEFAULT_STREAM_TYPE, flags, pkgName, TAG);
RoboErik001c59c2015-01-26 15:53:51 -08005160 } catch (RemoteException e) {
5161 Log.e(TAG, "Error dispatching volume up in dispatchTvAudioEvent.", e);
5162 }
5163 break;
5164 case KeyEvent.KEYCODE_VOLUME_DOWN:
5165 try {
John Spurlockee5ad722015-03-03 16:17:21 -05005166 getAudioService().adjustSuggestedStreamVolume(AudioManager.ADJUST_LOWER,
John Spurlock90874332015-03-10 16:00:54 -04005167 AudioManager.USE_DEFAULT_STREAM_TYPE, flags, pkgName, TAG);
RoboErik001c59c2015-01-26 15:53:51 -08005168 } catch (RemoteException e) {
5169 Log.e(TAG, "Error dispatching volume down in dispatchTvAudioEvent.", e);
5170 }
5171 break;
5172 case KeyEvent.KEYCODE_VOLUME_MUTE:
5173 try {
5174 if (event.getRepeatCount() == 0) {
John Spurlockee5ad722015-03-03 16:17:21 -05005175 getAudioService().adjustSuggestedStreamVolume(
5176 AudioManager.ADJUST_TOGGLE_MUTE,
John Spurlock90874332015-03-10 16:00:54 -04005177 AudioManager.USE_DEFAULT_STREAM_TYPE, flags, pkgName, TAG);
RoboErik001c59c2015-01-26 15:53:51 -08005178 }
5179 } catch (RemoteException e) {
5180 Log.e(TAG, "Error dispatching mute in dispatchTvAudioEvent.", e);
5181 }
5182 break;
5183 }
5184 }
5185
Jeff Brown40013652012-05-16 21:22:36 -07005186 void dispatchMediaKeyWithWakeLock(KeyEvent event) {
5187 if (DEBUG_INPUT) {
5188 Slog.d(TAG, "dispatchMediaKeyWithWakeLock: " + event);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005189 }
5190
Jeff Brown40013652012-05-16 21:22:36 -07005191 if (mHavePendingMediaKeyRepeatWithWakeLock) {
5192 if (DEBUG_INPUT) {
5193 Slog.d(TAG, "dispatchMediaKeyWithWakeLock: canceled repeat");
5194 }
5195
5196 mHandler.removeMessages(MSG_DISPATCH_MEDIA_KEY_REPEAT_WITH_WAKE_LOCK);
5197 mHavePendingMediaKeyRepeatWithWakeLock = false;
5198 mBroadcastWakeLock.release(); // pending repeat was holding onto the wake lock
5199 }
5200
5201 dispatchMediaKeyWithWakeLockToAudioService(event);
5202
5203 if (event.getAction() == KeyEvent.ACTION_DOWN
5204 && event.getRepeatCount() == 0) {
5205 mHavePendingMediaKeyRepeatWithWakeLock = true;
5206
5207 Message msg = mHandler.obtainMessage(
5208 MSG_DISPATCH_MEDIA_KEY_REPEAT_WITH_WAKE_LOCK, event);
5209 msg.setAsynchronous(true);
5210 mHandler.sendMessageDelayed(msg, ViewConfiguration.getKeyRepeatTimeout());
5211 } else {
5212 mBroadcastWakeLock.release();
5213 }
5214 }
5215
5216 void dispatchMediaKeyRepeatWithWakeLock(KeyEvent event) {
5217 mHavePendingMediaKeyRepeatWithWakeLock = false;
5218
5219 KeyEvent repeatEvent = KeyEvent.changeTimeRepeat(event,
5220 SystemClock.uptimeMillis(), 1, event.getFlags() | KeyEvent.FLAG_LONG_PRESS);
5221 if (DEBUG_INPUT) {
5222 Slog.d(TAG, "dispatchMediaKeyRepeatWithWakeLock: " + repeatEvent);
5223 }
5224
5225 dispatchMediaKeyWithWakeLockToAudioService(repeatEvent);
5226 mBroadcastWakeLock.release();
5227 }
5228
5229 void dispatchMediaKeyWithWakeLockToAudioService(KeyEvent event) {
5230 if (ActivityManagerNative.isSystemReady()) {
RoboErik430fc482014-06-12 15:49:20 -07005231 MediaSessionLegacyHelper.getHelper(mContext).sendMediaButtonEvent(event, true);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005232 }
5233 }
5234
Michael Wright869a67c2014-08-26 19:33:06 -07005235 void launchVoiceAssistWithWakeLock(boolean keyguardActive) {
Dianne Hackbornb6683c42015-06-18 17:40:33 -07005236 IDeviceIdleController dic = IDeviceIdleController.Stub.asInterface(
5237 ServiceManager.getService(Context.DEVICE_IDLE_CONTROLLER));
5238 if (dic != null) {
5239 try {
5240 dic.exitIdle("voice-search");
5241 } catch (RemoteException e) {
5242 }
5243 }
Michael Wright869a67c2014-08-26 19:33:06 -07005244 Intent voiceIntent =
5245 new Intent(RecognizerIntent.ACTION_VOICE_SEARCH_HANDS_FREE);
5246 voiceIntent.putExtra(RecognizerIntent.EXTRA_SECURE, keyguardActive);
Bart Sears8b1c27c2015-03-18 23:51:02 +00005247 startActivityAsUser(voiceIntent, UserHandle.CURRENT_OR_SELF);
Michael Wright869a67c2014-08-26 19:33:06 -07005248 mBroadcastWakeLock.release();
5249 }
5250
Mike Lockwood1753f7f2009-08-24 14:49:07 -07005251 BroadcastReceiver mDockReceiver = new BroadcastReceiver() {
Craig Mautnereee29c42013-01-17 14:44:34 -08005252 @Override
Mike Lockwood1753f7f2009-08-24 14:49:07 -07005253 public void onReceive(Context context, Intent intent) {
Dianne Hackborn867ab6472010-04-29 13:28:56 -07005254 if (Intent.ACTION_DOCK_EVENT.equals(intent.getAction())) {
5255 mDockMode = intent.getIntExtra(Intent.EXTRA_DOCK_STATE,
5256 Intent.EXTRA_DOCK_STATE_UNDOCKED);
Daniel Sandler6396c722013-04-16 20:19:09 -04005257 } else {
5258 try {
5259 IUiModeManager uiModeService = IUiModeManager.Stub.asInterface(
5260 ServiceManager.getService(Context.UI_MODE_SERVICE));
5261 mUiMode = uiModeService.getCurrentModeType();
5262 } catch (RemoteException e) {
5263 }
Dianne Hackborn80fa1662009-10-07 14:02:10 -07005264 }
Jeff Brown01a98dd2011-09-20 15:08:29 -07005265 updateRotation(true);
Craig Mautnereee29c42013-01-17 14:44:34 -08005266 synchronized (mLock) {
5267 updateOrientationListenerLp();
5268 }
Mike Lockwood1753f7f2009-08-24 14:49:07 -07005269 }
5270 };
5271
Jeff Brown6aaf2952012-10-05 16:01:08 -07005272 BroadcastReceiver mDreamReceiver = new BroadcastReceiver() {
5273 @Override
5274 public void onReceive(Context context, Intent intent) {
5275 if (Intent.ACTION_DREAMING_STARTED.equals(intent.getAction())) {
Jim Miller5ecd8112013-01-09 18:50:26 -08005276 if (mKeyguardDelegate != null) {
5277 mKeyguardDelegate.onDreamingStarted();
Jeff Brown6aaf2952012-10-05 16:01:08 -07005278 }
5279 } else if (Intent.ACTION_DREAMING_STOPPED.equals(intent.getAction())) {
Jim Miller5ecd8112013-01-09 18:50:26 -08005280 if (mKeyguardDelegate != null) {
5281 mKeyguardDelegate.onDreamingStopped();
Jeff Brown6aaf2952012-10-05 16:01:08 -07005282 }
5283 }
5284 }
5285 };
5286
Christopher Tate5e08af02012-09-21 17:17:22 -07005287 BroadcastReceiver mMultiuserReceiver = new BroadcastReceiver() {
5288 @Override
5289 public void onReceive(Context context, Intent intent) {
5290 if (Intent.ACTION_USER_SWITCHED.equals(intent.getAction())) {
5291 // tickle the settings observer: this first ensures that we're
5292 // observing the relevant settings for the newly-active user,
5293 // and then updates our own bookkeeping based on the now-
5294 // current user.
5295 mSettingsObserver.onChange(false);
John Spurlockce479d82012-11-29 09:52:21 -05005296
5297 // force a re-application of focused window sysui visibility.
5298 // the window may never have been shown for this user
5299 // e.g. the keyguard when going through the new-user setup flow
John Spurlock04db1762013-05-13 12:46:41 -04005300 synchronized (mWindowManagerFuncs.getWindowManagerLock()) {
John Spurlockce479d82012-11-29 09:52:21 -05005301 mLastSystemUiFlags = 0;
5302 updateSystemUiVisibilityLw();
5303 }
Christopher Tate5e08af02012-09-21 17:17:22 -07005304 }
5305 }
5306 };
5307
Adrian Roosddc8b272015-05-21 16:28:27 -07005308 private final Runnable mHiddenNavPanic = new Runnable() {
John Spurlockd9b70bd2014-02-06 17:02:44 -05005309 @Override
5310 public void run() {
Adrian Roosddc8b272015-05-21 16:28:27 -07005311 synchronized (mWindowManagerFuncs.getWindowManagerLock()) {
5312 if (!isUserSetupComplete()) {
5313 // Swipe-up for navigation bar is disabled during setup
5314 return;
5315 }
5316 mPendingPanicGestureUptime = SystemClock.uptimeMillis();
5317 mNavigationBarController.showTransient();
5318 }
John Spurlockd9b70bd2014-02-06 17:02:44 -05005319 }
5320 };
5321
John Spurlocke1f366f2013-08-05 12:22:40 -04005322 private void requestTransientBars(WindowState swipeTarget) {
John Spurlock04db1762013-05-13 12:46:41 -04005323 synchronized (mWindowManagerFuncs.getWindowManagerLock()) {
Maurice Lam99c6e072014-04-28 18:24:28 -07005324 if (!isUserSetupComplete()) {
5325 // Swipe-up for navigation bar is disabled during setup
5326 return;
5327 }
John Spurlock27735a42013-08-14 17:57:38 -04005328 boolean sb = mStatusBarController.checkShowTransientBarLw();
5329 boolean nb = mNavigationBarController.checkShowTransientBarLw();
John Spurlockad3e6cb2013-04-30 08:47:43 -04005330 if (sb || nb) {
Adrian Roos62b65e42015-02-25 18:05:34 +01005331 // Don't show status bar when swiping on already visible navigation bar
5332 if (!nb && swipeTarget == mNavigationBar) {
John Spurlocke1f366f2013-08-05 12:22:40 -04005333 if (DEBUG) Slog.d(TAG, "Not showing transient bar, wrong swipe target");
John Spurlockad3e6cb2013-04-30 08:47:43 -04005334 return;
5335 }
John Spurlock27735a42013-08-14 17:57:38 -04005336 if (sb) mStatusBarController.showTransient();
5337 if (nb) mNavigationBarController.showTransient();
John Spurlockf1a36642013-10-12 17:50:42 -04005338 mImmersiveModeConfirmation.confirmCurrentPrompt();
John Spurlockad3e6cb2013-04-30 08:47:43 -04005339 updateSystemUiVisibilityLw();
John Spurlock32beb2c2013-03-11 10:16:47 -04005340 }
John Spurlockad3e6cb2013-04-30 08:47:43 -04005341 }
5342 }
5343
Jeff Brown3ee549c2014-09-22 20:14:39 -07005344 // Called on the PowerManager's Notifier thread.
Jeff Brownc38c9be2012-10-04 13:16:19 -07005345 @Override
Jeff Brown416c49c2015-05-26 19:50:18 -07005346 public void startedGoingToSleep(int why) {
5347 if (DEBUG_WAKEUP) Slog.i(TAG, "Started going to sleep... (why=" + why + ")");
Jorim Jaggid175b6c2015-05-27 15:39:09 -07005348 if (mKeyguardDelegate != null) {
5349 mKeyguardDelegate.onStartedGoingToSleep(why);
5350 }
Jeff Brown416c49c2015-05-26 19:50:18 -07005351 }
5352
5353 // Called on the PowerManager's Notifier thread.
5354 @Override
5355 public void finishedGoingToSleep(int why) {
Dianne Hackborn74489012009-03-24 20:50:09 -07005356 EventLog.writeEvent(70000, 0);
Jeff Brown416c49c2015-05-26 19:50:18 -07005357 if (DEBUG_WAKEUP) Slog.i(TAG, "Finished going to sleep... (why=" + why + ")");
Chris Wren9bb290b2015-06-29 12:02:13 -04005358 MetricsLogger.histogram(mContext, "screen_timeout", mLockScreenTimeout / 1000);
Jeff Brown3ee549c2014-09-22 20:14:39 -07005359
5360 // We must get this work done here because the power manager will drop
5361 // the wake lock and let the system suspend once this function returns.
The Android Open Source Project0727d222009-03-11 12:11:58 -07005362 synchronized (mLock) {
Jeff Brown3ee549c2014-09-22 20:14:39 -07005363 mAwake = false;
5364 mKeyguardDrawComplete = false;
Jeff Browna20dda42014-05-27 20:57:24 -07005365 updateWakeGestureListenerLp();
The Android Open Source Project0727d222009-03-11 12:11:58 -07005366 updateOrientationListenerLp();
Mike Lockwood28569302010-01-28 11:54:40 -05005367 updateLockScreenTimeout();
The Android Open Source Project0727d222009-03-11 12:11:58 -07005368 }
Jeff Brown3ee549c2014-09-22 20:14:39 -07005369 if (mKeyguardDelegate != null) {
Jorim Jaggid175b6c2015-05-27 15:39:09 -07005370 mKeyguardDelegate.onFinishedGoingToSleep(why);
Jeff Brown3ee549c2014-09-22 20:14:39 -07005371 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005372 }
5373
Jeff Brown3ee549c2014-09-22 20:14:39 -07005374 // Called on the PowerManager's Notifier thread.
Jeff Brownc38c9be2012-10-04 13:16:19 -07005375 @Override
Jeff Brown416c49c2015-05-26 19:50:18 -07005376 public void startedWakingUp() {
Dianne Hackborn74489012009-03-24 20:50:09 -07005377 EventLog.writeEvent(70000, 1);
Jeff Brown416c49c2015-05-26 19:50:18 -07005378 if (DEBUG_WAKEUP) Slog.i(TAG, "Started waking up...");
Craig Mautner8a0da012014-05-31 15:13:37 -07005379
Jeff Brown3ee549c2014-09-22 20:14:39 -07005380 // Since goToSleep performs these functions synchronously, we must
5381 // do the same here. We cannot post this work to a handler because
5382 // that might cause it to become reordered with respect to what
5383 // may happen in a future call to goToSleep.
The Android Open Source Project0727d222009-03-11 12:11:58 -07005384 synchronized (mLock) {
Jeff Brown3ee549c2014-09-22 20:14:39 -07005385 mAwake = true;
5386 mKeyguardDrawComplete = false;
5387 if (mKeyguardDelegate != null) {
5388 mHandler.removeMessages(MSG_KEYGUARD_DRAWN_TIMEOUT);
5389 mHandler.sendEmptyMessageDelayed(MSG_KEYGUARD_DRAWN_TIMEOUT, 1000);
5390 }
5391
Jeff Browna20dda42014-05-27 20:57:24 -07005392 updateWakeGestureListenerLp();
The Android Open Source Project0727d222009-03-11 12:11:58 -07005393 updateOrientationListenerLp();
Mike Lockwood28569302010-01-28 11:54:40 -05005394 updateLockScreenTimeout();
The Android Open Source Project0727d222009-03-11 12:11:58 -07005395 }
Jeff Brownc38c9be2012-10-04 13:16:19 -07005396
Jim Miller5ecd8112013-01-09 18:50:26 -08005397 if (mKeyguardDelegate != null) {
Jorim Jaggid175b6c2015-05-27 15:39:09 -07005398 mKeyguardDelegate.onStartedWakingUp(mKeyguardDelegateCallback);
Jeff Brown36c4db82014-09-19 12:05:31 -07005399 // ... eventually calls finishKeyguardDrawn
Jeff Brownc38c9be2012-10-04 13:16:19 -07005400 } else {
Craig Mautner8a0da012014-05-31 15:13:37 -07005401 if (DEBUG_WAKEUP) Slog.d(TAG, "null mKeyguardDelegate: setting mKeyguardDrawComplete.");
Jeff Brown36c4db82014-09-19 12:05:31 -07005402 finishKeyguardDrawn();
Jeff Brownc38c9be2012-10-04 13:16:19 -07005403 }
Jeff Brown36c4db82014-09-19 12:05:31 -07005404 }
5405
Jeff Brown416c49c2015-05-26 19:50:18 -07005406 // Called on the PowerManager's Notifier thread.
5407 @Override
5408 public void finishedWakingUp() {
5409 if (DEBUG_WAKEUP) Slog.i(TAG, "Finished waking up...");
5410 }
5411
5412 private void wakeUpFromPowerKey(long eventTime) {
5413 wakeUp(eventTime, mAllowTheaterModeWakeFromPowerKey);
5414 }
5415
5416 private boolean wakeUp(long wakeTime, boolean wakeInTheaterMode) {
Bryce Leed3896842015-06-23 17:06:51 -07005417 final boolean theaterModeEnabled = isTheaterModeEnabled();
5418 if (!wakeInTheaterMode && theaterModeEnabled) {
Jeff Brown416c49c2015-05-26 19:50:18 -07005419 return false;
5420 }
5421
Bryce Leed3896842015-06-23 17:06:51 -07005422 if (theaterModeEnabled) {
5423 Settings.Global.putInt(mContext.getContentResolver(),
5424 Settings.Global.THEATER_MODE_ON, 0);
5425 }
5426
Jeff Brown416c49c2015-05-26 19:50:18 -07005427 mPowerManager.wakeUp(wakeTime);
5428 return true;
5429 }
5430
Jeff Brown36c4db82014-09-19 12:05:31 -07005431 private void finishKeyguardDrawn() {
Jeff Brown3ee549c2014-09-22 20:14:39 -07005432 synchronized (mLock) {
5433 if (!mAwake || mKeyguardDrawComplete) {
Stefan Kuhne9326dc12015-06-12 09:25:32 -10005434 return; // We are not awake yet or we have already informed of this event.
Jeff Brown3ee549c2014-09-22 20:14:39 -07005435 }
5436
Jeff Brown36c4db82014-09-19 12:05:31 -07005437 mKeyguardDrawComplete = true;
Jeff Brown3ee549c2014-09-22 20:14:39 -07005438 if (mKeyguardDelegate != null) {
5439 mHandler.removeMessages(MSG_KEYGUARD_DRAWN_TIMEOUT);
5440 }
5441 }
5442
5443 finishScreenTurningOn();
5444 }
5445
5446 // Called on the DisplayManager's DisplayPowerController thread.
5447 @Override
5448 public void screenTurnedOff() {
5449 if (DEBUG_WAKEUP) Slog.i(TAG, "Screen turned off...");
5450
Jeff Brown48d1b142015-06-10 16:36:03 -07005451 updateScreenOffSleepToken(true);
Jeff Brown3ee549c2014-09-22 20:14:39 -07005452 synchronized (mLock) {
5453 mScreenOnEarly = false;
5454 mScreenOnFully = false;
5455 mWindowManagerDrawComplete = false;
5456 mScreenOnListener = null;
5457 updateOrientationListenerLp();
Jeff Brown36c4db82014-09-19 12:05:31 -07005458 }
5459 }
5460
Jeff Brown3ee549c2014-09-22 20:14:39 -07005461 // Called on the DisplayManager's DisplayPowerController thread.
Jeff Brown36c4db82014-09-19 12:05:31 -07005462 @Override
5463 public void screenTurningOn(final ScreenOnListener screenOnListener) {
Jeff Brown36c4db82014-09-19 12:05:31 -07005464 if (DEBUG_WAKEUP) Slog.i(TAG, "Screen turning on...");
Jeff Brown36c4db82014-09-19 12:05:31 -07005465
Jeff Brown48d1b142015-06-10 16:36:03 -07005466 updateScreenOffSleepToken(false);
Jeff Brown3ee549c2014-09-22 20:14:39 -07005467 synchronized (mLock) {
5468 mScreenOnEarly = true;
5469 mScreenOnFully = false;
5470 mWindowManagerDrawComplete = false;
5471 mScreenOnListener = screenOnListener;
Jeff Brown3ee549c2014-09-22 20:14:39 -07005472 }
Jeff Brown36c4db82014-09-19 12:05:31 -07005473
Craig Mautnerc3daedd2014-09-13 11:17:23 -07005474 mWindowManagerInternal.waitForAllWindowsDrawn(mWindowManagerDrawCallback,
5475 WAITING_FOR_DRAWN_TIMEOUT);
Stefan Kuhne9326dc12015-06-12 09:25:32 -10005476 // ... eventually calls finishWindowsDrawn which will finalize our screen turn on
5477 // as well as enabling the orientation change logic/sensor.
Jeff Brown36c4db82014-09-19 12:05:31 -07005478 }
5479
Jeff Brown36c4db82014-09-19 12:05:31 -07005480 private void finishWindowsDrawn() {
Jeff Brown3ee549c2014-09-22 20:14:39 -07005481 synchronized (mLock) {
5482 if (!mScreenOnEarly || mWindowManagerDrawComplete) {
Stefan Kuhne9326dc12015-06-12 09:25:32 -10005483 return; // Screen is not turned on or we did already handle this case earlier.
Jeff Brown3ee549c2014-09-22 20:14:39 -07005484 }
5485
Jeff Brown36c4db82014-09-19 12:05:31 -07005486 mWindowManagerDrawComplete = true;
Jeff Brown36c4db82014-09-19 12:05:31 -07005487 }
Jeff Brown3ee549c2014-09-22 20:14:39 -07005488
5489 finishScreenTurningOn();
Jeff Brownc38c9be2012-10-04 13:16:19 -07005490 }
5491
Craig Mautner8a0da012014-05-31 15:13:37 -07005492 private void finishScreenTurningOn() {
Stefan Kuhne9326dc12015-06-12 09:25:32 -10005493 synchronized (mLock) {
5494 // We have just finished drawing screen content. Since the orientation listener
5495 // gets only installed when all windows are drawn, we try to install it again.
5496 updateOrientationListenerLp();
5497 }
Jeff Brown3ee549c2014-09-22 20:14:39 -07005498 final ScreenOnListener listener;
5499 final boolean enableScreen;
Jeff Brown36c4db82014-09-19 12:05:31 -07005500 synchronized (mLock) {
Jeff Brown3ee549c2014-09-22 20:14:39 -07005501 if (DEBUG_WAKEUP) Slog.d(TAG,
5502 "finishScreenTurningOn: mAwake=" + mAwake
5503 + ", mScreenOnEarly=" + mScreenOnEarly
5504 + ", mScreenOnFully=" + mScreenOnFully
5505 + ", mKeyguardDrawComplete=" + mKeyguardDrawComplete
5506 + ", mWindowManagerDrawComplete=" + mWindowManagerDrawComplete);
5507
5508 if (mScreenOnFully || !mScreenOnEarly || !mWindowManagerDrawComplete
5509 || (mAwake && !mKeyguardDrawComplete)) {
5510 return; // spurious or not ready yet
Jeff Brown36c4db82014-09-19 12:05:31 -07005511 }
5512
Jeff Brown3ee549c2014-09-22 20:14:39 -07005513 if (DEBUG_WAKEUP) Slog.i(TAG, "Finished screen turning on...");
5514 listener = mScreenOnListener;
Craig Mautner13f6ea72014-06-23 14:57:02 -07005515 mScreenOnListener = null;
Jeff Brown3ee549c2014-09-22 20:14:39 -07005516 mScreenOnFully = true;
5517
5518 // Remember the first time we draw the keyguard so we know when we're done with
5519 // the main part of booting and can enable the screen and hide boot messages.
5520 if (!mKeyguardDrawnOnce && mAwake) {
5521 mKeyguardDrawnOnce = true;
5522 enableScreen = true;
5523 if (mBootMessageNeedsHiding) {
5524 mBootMessageNeedsHiding = false;
5525 hideBootMessages();
5526 }
5527 } else {
5528 enableScreen = false;
5529 }
Jeff Brownc38c9be2012-10-04 13:16:19 -07005530 }
5531
Jeff Brown3ee549c2014-09-22 20:14:39 -07005532 if (listener != null) {
5533 listener.onScreenOn();
5534 }
Jeff Brown4fc45272012-10-10 18:28:14 -07005535
Jeff Brown3ee549c2014-09-22 20:14:39 -07005536 if (enableScreen) {
5537 try {
5538 mWindowManager.enableScreenIfNeeded();
5539 } catch (RemoteException unhandled) {
Jeff Brown36c4db82014-09-19 12:05:31 -07005540 }
Craig Mautnera631d492014-08-05 15:16:01 -07005541 }
5542 }
5543
5544 private void handleHideBootMessage() {
Jeff Brown3ee549c2014-09-22 20:14:39 -07005545 synchronized (mLock) {
5546 if (!mKeyguardDrawnOnce) {
5547 mBootMessageNeedsHiding = true;
5548 return; // keyguard hasn't drawn the first time yet, not done booting
5549 }
Craig Mautnera631d492014-08-05 15:16:01 -07005550 }
Jeff Brown3ee549c2014-09-22 20:14:39 -07005551
5552 if (mBootMsgDialog != null) {
5553 if (DEBUG_WAKEUP) Slog.d(TAG, "handleHideBootMessage: dismissing");
5554 mBootMsgDialog.dismiss();
5555 mBootMsgDialog = null;
Craig Mautnera631d492014-08-05 15:16:01 -07005556 }
Jeff Brownc38c9be2012-10-04 13:16:19 -07005557 }
5558
5559 @Override
Jeff Brown3ee549c2014-09-22 20:14:39 -07005560 public boolean isScreenOn() {
5561 return mScreenOnFully;
Dianne Hackborn08743722009-12-21 12:16:51 -08005562 }
Jeff Brownc38c9be2012-10-04 13:16:19 -07005563
Dianne Hackborn08743722009-12-21 12:16:51 -08005564 /** {@inheritDoc} */
Jose Lima9546b202014-07-02 17:21:51 -07005565 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005566 public void enableKeyguard(boolean enabled) {
Jim Miller5ecd8112013-01-09 18:50:26 -08005567 if (mKeyguardDelegate != null) {
5568 mKeyguardDelegate.setKeyguardEnabled(enabled);
Mike Lockwood3a74bd32011-08-12 13:55:22 -07005569 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005570 }
5571
5572 /** {@inheritDoc} */
Jose Lima9546b202014-07-02 17:21:51 -07005573 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005574 public void exitKeyguardSecurely(OnKeyguardExitResult callback) {
Jim Miller5ecd8112013-01-09 18:50:26 -08005575 if (mKeyguardDelegate != null) {
5576 mKeyguardDelegate.verifyUnlock(callback);
Mike Lockwood3a74bd32011-08-12 13:55:22 -07005577 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005578 }
5579
Jim Millerab954542014-10-10 18:21:49 -07005580 private boolean isKeyguardShowingAndNotOccluded() {
Jim Miller5ecd8112013-01-09 18:50:26 -08005581 if (mKeyguardDelegate == null) return false;
Jim Millerab954542014-10-10 18:21:49 -07005582 return mKeyguardDelegate.isShowing() && !mKeyguardOccluded;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005583 }
5584
Mike Lockwood520d8bc2011-02-18 13:23:13 -05005585 /** {@inheritDoc} */
Jose Lima9546b202014-07-02 17:21:51 -07005586 @Override
Mike Lockwood520d8bc2011-02-18 13:23:13 -05005587 public boolean isKeyguardLocked() {
5588 return keyguardOn();
5589 }
5590
5591 /** {@inheritDoc} */
Jose Lima9546b202014-07-02 17:21:51 -07005592 @Override
Mike Lockwood520d8bc2011-02-18 13:23:13 -05005593 public boolean isKeyguardSecure() {
Jim Miller5ecd8112013-01-09 18:50:26 -08005594 if (mKeyguardDelegate == null) return false;
5595 return mKeyguardDelegate.isSecure();
Mike Lockwood520d8bc2011-02-18 13:23:13 -05005596 }
5597
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005598 /** {@inheritDoc} */
Jose Lima9546b202014-07-02 17:21:51 -07005599 @Override
Adrian Roos461829d2015-06-03 14:41:18 -07005600 public boolean isKeyguardShowingOrOccluded() {
5601 return mKeyguardDelegate == null ? false : mKeyguardDelegate.isShowing();
5602 }
5603
5604 /** {@inheritDoc} */
5605 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005606 public boolean inKeyguardRestrictedKeyInputMode() {
Jim Miller5ecd8112013-01-09 18:50:26 -08005607 if (mKeyguardDelegate == null) return false;
5608 return mKeyguardDelegate.isInputRestricted();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005609 }
5610
Jose Lima9546b202014-07-02 17:21:51 -07005611 @Override
Dianne Hackborn90c52de2011-09-23 12:57:44 -07005612 public void dismissKeyguardLw() {
RoboErik8a2cfc32014-05-16 11:19:38 -07005613 if (mKeyguardDelegate != null && mKeyguardDelegate.isShowing()) {
Craig Mautnerc0d2d0a2014-10-31 16:25:15 -07005614 if (DEBUG_KEYGUARD) Slog.d(TAG, "PWM.dismissKeyguardLw");
Daniel Sandler1ce804392012-11-07 15:07:12 -05005615 mHandler.post(new Runnable() {
Jose Lima9546b202014-07-02 17:21:51 -07005616 @Override
Daniel Sandler1ce804392012-11-07 15:07:12 -05005617 public void run() {
Jorim Jaggi8de4311c2014-08-11 22:36:20 +02005618 // ask the keyguard to prompt the user to authenticate if necessary
5619 mKeyguardDelegate.dismiss();
5620 }
5621 });
5622 }
5623 }
5624
5625 public void notifyActivityDrawnForKeyguardLw() {
5626 if (mKeyguardDelegate != null) {
5627 mHandler.post(new Runnable() {
5628 @Override
5629 public void run() {
5630 mKeyguardDelegate.onActivityDrawn();
Daniel Sandler1ce804392012-11-07 15:07:12 -05005631 }
5632 });
Dianne Hackborn90c52de2011-09-23 12:57:44 -07005633 }
5634 }
5635
Jorim Jaggicff0acb2014-03-31 16:35:15 +02005636 @Override
5637 public boolean isKeyguardDrawnLw() {
5638 synchronized (mLock) {
Jeff Brown3ee549c2014-09-22 20:14:39 -07005639 return mKeyguardDrawnOnce;
Jorim Jaggicff0acb2014-03-31 16:35:15 +02005640 }
5641 }
5642
Jorim Jaggi0d674622014-05-21 01:34:15 +02005643 @Override
Jorim Jaggie29b2db2014-05-30 23:17:03 +02005644 public void startKeyguardExitAnimation(long startTime, long fadeoutDuration) {
Jorim Jaggi0d674622014-05-21 01:34:15 +02005645 if (mKeyguardDelegate != null) {
Craig Mautnerc0d2d0a2014-10-31 16:25:15 -07005646 if (DEBUG_KEYGUARD) Slog.d(TAG, "PWM.startKeyguardExitAnimation");
Jorim Jaggie29b2db2014-05-30 23:17:03 +02005647 mKeyguardDelegate.startKeyguardExitAnimation(startTime, fadeoutDuration);
Jorim Jaggi0d674622014-05-21 01:34:15 +02005648 }
5649 }
5650
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005651 void sendCloseSystemWindows() {
Jorim Jaggib10e33f2015-02-04 21:57:40 +01005652 PhoneWindow.sendCloseSystemWindows(mContext, null);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005653 }
5654
5655 void sendCloseSystemWindows(String reason) {
Jorim Jaggib10e33f2015-02-04 21:57:40 +01005656 PhoneWindow.sendCloseSystemWindows(mContext, reason);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005657 }
Mitsuru Oshima831d0d92009-06-16 18:27:18 -07005658
Jeff Brown01a98dd2011-09-20 15:08:29 -07005659 @Override
5660 public int rotationForOrientationLw(int orientation, int lastRotation) {
Daniel Sandler2ed6ad62011-02-22 14:54:17 -05005661 if (false) {
5662 Slog.v(TAG, "rotationForOrientationLw(orient="
5663 + orientation + ", last=" + lastRotation
5664 + "); user=" + mUserRotation + " "
5665 + ((mUserRotationMode == WindowManagerPolicy.USER_ROTATION_LOCKED)
5666 ? "USER_ROTATION_LOCKED" : "")
5667 );
5668 }
5669
Craig Mautner46ac6fa2013-08-01 10:06:34 -07005670 if (mForceDefaultOrientation) {
5671 return Surface.ROTATION_0;
5672 }
5673
The Android Open Source Project0727d222009-03-11 12:11:58 -07005674 synchronized (mLock) {
Jeff Brownc0347aa2011-09-23 17:26:09 -07005675 int sensorRotation = mOrientationListener.getProposedRotation(); // may be -1
5676 if (sensorRotation < 0) {
Jeff Brown0f862b42012-09-27 21:11:01 -07005677 sensorRotation = lastRotation;
Jeff Brownc0347aa2011-09-23 17:26:09 -07005678 }
Jeff Brown01a98dd2011-09-20 15:08:29 -07005679
Jeff Browndec6cf42011-11-15 14:08:20 -08005680 final int preferredRotation;
Jeff Brown2e7760e2012-04-11 15:14:55 -07005681 if (mLidState == LID_OPEN && mLidOpenRotation >= 0) {
Jeff Brown01a98dd2011-09-20 15:08:29 -07005682 // Ignore sensor when lid switch is open and rotation is forced.
5683 preferredRotation = mLidOpenRotation;
5684 } else if (mDockMode == Intent.EXTRA_DOCK_STATE_CAR
Jeff Brownc0347aa2011-09-23 17:26:09 -07005685 && (mCarDockEnablesAccelerometer || mCarDockRotation >= 0)) {
Jeff Brown01a98dd2011-09-20 15:08:29 -07005686 // Ignore sensor when in car dock unless explicitly enabled.
5687 // This case can override the behavior of NOSENSOR, and can also
5688 // enable 180 degree rotation while docked.
Jeff Brownc0347aa2011-09-23 17:26:09 -07005689 preferredRotation = mCarDockEnablesAccelerometer
Jeff Brown01a98dd2011-09-20 15:08:29 -07005690 ? sensorRotation : mCarDockRotation;
Jeff Brown1a693182011-11-08 14:44:16 -08005691 } else if ((mDockMode == Intent.EXTRA_DOCK_STATE_DESK
5692 || mDockMode == Intent.EXTRA_DOCK_STATE_LE_DESK
5693 || mDockMode == Intent.EXTRA_DOCK_STATE_HE_DESK)
Jeff Brownc0347aa2011-09-23 17:26:09 -07005694 && (mDeskDockEnablesAccelerometer || mDeskDockRotation >= 0)) {
Jeff Brown01a98dd2011-09-20 15:08:29 -07005695 // Ignore sensor when in desk dock unless explicitly enabled.
5696 // This case can override the behavior of NOSENSOR, and can also
5697 // enable 180 degree rotation while docked.
Jeff Brownc0347aa2011-09-23 17:26:09 -07005698 preferredRotation = mDeskDockEnablesAccelerometer
Jeff Brown01a98dd2011-09-20 15:08:29 -07005699 ? sensorRotation : mDeskDockRotation;
Jeff Brownc82c89ed2013-04-17 17:18:15 -07005700 } else if (mHdmiPlugged && mDemoHdmiRotationLock) {
5701 // Ignore sensor when plugged into HDMI when demo HDMI rotation lock enabled.
Jeff Browneb3e4b92011-12-06 19:54:24 -08005702 // Note that the dock orientation overrides the HDMI orientation.
Jeff Brownc82c89ed2013-04-17 17:18:15 -07005703 preferredRotation = mDemoHdmiRotation;
5704 } else if (mHdmiPlugged && mDockMode == Intent.EXTRA_DOCK_STATE_UNDOCKED
5705 && mUndockedHdmiRotation >= 0) {
5706 // Ignore sensor when plugged into HDMI and an undocked orientation has
5707 // been specified in the configuration (only for legacy devices without
5708 // full multi-display support).
5709 // Note that the dock orientation overrides the HDMI orientation.
5710 preferredRotation = mUndockedHdmiRotation;
Chong Zhangae6119ff2014-11-11 18:54:39 -08005711 } else if (mDemoRotationLock) {
5712 // Ignore sensor when demo rotation lock is enabled.
5713 // Note that the dock orientation and HDMI rotation lock override this.
5714 preferredRotation = mDemoRotation;
Dianne Hackbornb9ec1ac2013-04-10 17:34:25 -07005715 } else if (orientation == ActivityInfo.SCREEN_ORIENTATION_LOCKED) {
5716 // Application just wants to remain locked in the last rotation.
5717 preferredRotation = lastRotation;
Jeff Brownbcdfc622014-03-06 19:13:04 -08005718 } else if (!mSupportAutoRotation) {
5719 // If we don't support auto-rotation then bail out here and ignore
5720 // the sensor and any rotation lock settings.
5721 preferredRotation = -1;
Jeff Brown207673cd2012-06-05 17:47:11 -07005722 } else if ((mUserRotationMode == WindowManagerPolicy.USER_ROTATION_FREE
Jeff Brown01a98dd2011-09-20 15:08:29 -07005723 && (orientation == ActivityInfo.SCREEN_ORIENTATION_USER
Dianne Hackbornb9ec1ac2013-04-10 17:34:25 -07005724 || orientation == ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED
5725 || orientation == ActivityInfo.SCREEN_ORIENTATION_USER_LANDSCAPE
5726 || orientation == ActivityInfo.SCREEN_ORIENTATION_USER_PORTRAIT
5727 || orientation == ActivityInfo.SCREEN_ORIENTATION_FULL_USER))
Jeff Brown01a98dd2011-09-20 15:08:29 -07005728 || orientation == ActivityInfo.SCREEN_ORIENTATION_SENSOR
5729 || orientation == ActivityInfo.SCREEN_ORIENTATION_FULL_SENSOR
5730 || orientation == ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE
5731 || orientation == ActivityInfo.SCREEN_ORIENTATION_SENSOR_PORTRAIT) {
5732 // Otherwise, use sensor only if requested by the application or enabled
5733 // by default for USER or UNSPECIFIED modes. Does not apply to NOSENSOR.
Jeff Brownd3187e32011-09-21 19:26:44 -07005734 if (mAllowAllRotations < 0) {
5735 // Can't read this during init() because the context doesn't
5736 // have display metrics at that time so we cannot determine
5737 // tablet vs. phone then.
5738 mAllowAllRotations = mContext.getResources().getBoolean(
5739 com.android.internal.R.bool.config_allowAllRotations) ? 1 : 0;
5740 }
Jeff Brown01a98dd2011-09-20 15:08:29 -07005741 if (sensorRotation != Surface.ROTATION_180
Jeff Brownd3187e32011-09-21 19:26:44 -07005742 || mAllowAllRotations == 1
Dianne Hackbornb9ec1ac2013-04-10 17:34:25 -07005743 || orientation == ActivityInfo.SCREEN_ORIENTATION_FULL_SENSOR
5744 || orientation == ActivityInfo.SCREEN_ORIENTATION_FULL_USER) {
Jeff Brown01a98dd2011-09-20 15:08:29 -07005745 preferredRotation = sensorRotation;
5746 } else {
5747 preferredRotation = lastRotation;
5748 }
Jeff Brown207673cd2012-06-05 17:47:11 -07005749 } else if (mUserRotationMode == WindowManagerPolicy.USER_ROTATION_LOCKED
5750 && orientation != ActivityInfo.SCREEN_ORIENTATION_NOSENSOR) {
5751 // Apply rotation lock. Does not apply to NOSENSOR.
5752 // The idea is that the user rotation expresses a weak preference for the direction
5753 // of gravity and as NOSENSOR is never affected by gravity, then neither should
5754 // NOSENSOR be affected by rotation lock (although it will be affected by docks).
Jeff Brown4dfce202011-10-05 12:00:10 -07005755 preferredRotation = mUserRotation;
Jeff Browndec6cf42011-11-15 14:08:20 -08005756 } else {
5757 // No overriding preference.
5758 // We will do exactly what the application asked us to do.
5759 preferredRotation = -1;
Jeff Brown01a98dd2011-09-20 15:08:29 -07005760 }
5761
Dianne Hackborne5439f22010-10-02 16:53:50 -07005762 switch (orientation) {
5763 case ActivityInfo.SCREEN_ORIENTATION_PORTRAIT:
Jeff Browndec6cf42011-11-15 14:08:20 -08005764 // Return portrait unless overridden.
5765 if (isAnyPortrait(preferredRotation)) {
5766 return preferredRotation;
5767 }
Dianne Hackborne5439f22010-10-02 16:53:50 -07005768 return mPortraitRotation;
Dianne Hackborne5439f22010-10-02 16:53:50 -07005769
Jeff Brown01a98dd2011-09-20 15:08:29 -07005770 case ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE:
Jeff Browndec6cf42011-11-15 14:08:20 -08005771 // Return landscape unless overridden.
5772 if (isLandscapeOrSeascape(preferredRotation)) {
5773 return preferredRotation;
5774 }
Jeff Brown01a98dd2011-09-20 15:08:29 -07005775 return mLandscapeRotation;
5776
5777 case ActivityInfo.SCREEN_ORIENTATION_REVERSE_PORTRAIT:
Jeff Browndec6cf42011-11-15 14:08:20 -08005778 // Return reverse portrait unless overridden.
5779 if (isAnyPortrait(preferredRotation)) {
5780 return preferredRotation;
5781 }
Jeff Brown01a98dd2011-09-20 15:08:29 -07005782 return mUpsideDownRotation;
5783
5784 case ActivityInfo.SCREEN_ORIENTATION_REVERSE_LANDSCAPE:
Jeff Browndec6cf42011-11-15 14:08:20 -08005785 // Return seascape unless overridden.
5786 if (isLandscapeOrSeascape(preferredRotation)) {
5787 return preferredRotation;
5788 }
Jeff Brown01a98dd2011-09-20 15:08:29 -07005789 return mSeascapeRotation;
5790
5791 case ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE:
Dianne Hackbornb9ec1ac2013-04-10 17:34:25 -07005792 case ActivityInfo.SCREEN_ORIENTATION_USER_LANDSCAPE:
Jeff Brown01a98dd2011-09-20 15:08:29 -07005793 // Return either landscape rotation.
5794 if (isLandscapeOrSeascape(preferredRotation)) {
5795 return preferredRotation;
5796 }
5797 if (isLandscapeOrSeascape(lastRotation)) {
Jeff Brown4519f072011-01-23 13:16:01 -08005798 return lastRotation;
5799 }
Jeff Brown01a98dd2011-09-20 15:08:29 -07005800 return mLandscapeRotation;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005801
Jeff Brown01a98dd2011-09-20 15:08:29 -07005802 case ActivityInfo.SCREEN_ORIENTATION_SENSOR_PORTRAIT:
Dianne Hackbornb9ec1ac2013-04-10 17:34:25 -07005803 case ActivityInfo.SCREEN_ORIENTATION_USER_PORTRAIT:
Jeff Brown01a98dd2011-09-20 15:08:29 -07005804 // Return either portrait rotation.
5805 if (isAnyPortrait(preferredRotation)) {
5806 return preferredRotation;
5807 }
5808 if (isAnyPortrait(lastRotation)) {
5809 return lastRotation;
5810 }
5811 return mPortraitRotation;
5812
5813 default:
Jeff Brown4dfce202011-10-05 12:00:10 -07005814 // For USER, UNSPECIFIED, NOSENSOR, SENSOR and FULL_SENSOR,
5815 // just return the preferred orientation we already calculated.
Jeff Brown01a98dd2011-09-20 15:08:29 -07005816 if (preferredRotation >= 0) {
5817 return preferredRotation;
5818 }
Dianne Hackborndacea8c2011-04-21 17:26:39 -07005819 return Surface.ROTATION_0;
Daniel Sandlere7e5ac22011-02-22 16:10:21 -05005820 }
5821 }
Steve Howarda7bfe6a2010-09-23 16:47:49 -07005822 }
5823
Jeff Brown01a98dd2011-09-20 15:08:29 -07005824 @Override
5825 public boolean rotationHasCompatibleMetricsLw(int orientation, int rotation) {
5826 switch (orientation) {
5827 case ActivityInfo.SCREEN_ORIENTATION_PORTRAIT:
5828 case ActivityInfo.SCREEN_ORIENTATION_REVERSE_PORTRAIT:
5829 case ActivityInfo.SCREEN_ORIENTATION_SENSOR_PORTRAIT:
5830 return isAnyPortrait(rotation);
5831
5832 case ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE:
5833 case ActivityInfo.SCREEN_ORIENTATION_REVERSE_LANDSCAPE:
5834 case ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE:
5835 return isLandscapeOrSeascape(rotation);
5836
5837 default:
5838 return true;
5839 }
Steve Howarda7bfe6a2010-09-23 16:47:49 -07005840 }
5841
Jeff Brownc0347aa2011-09-23 17:26:09 -07005842 @Override
5843 public void setRotationLw(int rotation) {
5844 mOrientationListener.setCurrentRotation(rotation);
5845 }
5846
Jeff Brown01a98dd2011-09-20 15:08:29 -07005847 private boolean isLandscapeOrSeascape(int rotation) {
5848 return rotation == mLandscapeRotation || rotation == mSeascapeRotation;
Dianne Hackborne5439f22010-10-02 16:53:50 -07005849 }
5850
Jeff Brown01a98dd2011-09-20 15:08:29 -07005851 private boolean isAnyPortrait(int rotation) {
5852 return rotation == mPortraitRotation || rotation == mUpsideDownRotation;
Dianne Hackborne5439f22010-10-02 16:53:50 -07005853 }
5854
Jose Lima9546b202014-07-02 17:21:51 -07005855 @Override
Svetoslav Ganov80943d82013-01-02 10:25:37 -08005856 public int getUserRotationMode() {
5857 return Settings.System.getIntForUser(mContext.getContentResolver(),
Brett Chabot7e55c402013-05-16 19:38:08 -07005858 Settings.System.ACCELEROMETER_ROTATION, 0, UserHandle.USER_CURRENT) != 0 ?
5859 WindowManagerPolicy.USER_ROTATION_FREE :
5860 WindowManagerPolicy.USER_ROTATION_LOCKED;
Svetoslav Ganov80943d82013-01-02 10:25:37 -08005861 }
Daniel Sandlerb73617d2010-08-17 00:41:00 -04005862
5863 // User rotation: to be used when all else fails in assigning an orientation to the device
Jose Lima9546b202014-07-02 17:21:51 -07005864 @Override
Daniel Sandlerb73617d2010-08-17 00:41:00 -04005865 public void setUserRotationMode(int mode, int rot) {
5866 ContentResolver res = mContext.getContentResolver();
Daniel Sandler2ed6ad62011-02-22 14:54:17 -05005867
5868 // mUserRotationMode and mUserRotation will be assigned by the content observer
Daniel Sandlerb73617d2010-08-17 00:41:00 -04005869 if (mode == WindowManagerPolicy.USER_ROTATION_LOCKED) {
Christopher Tate5e08af02012-09-21 17:17:22 -07005870 Settings.System.putIntForUser(res,
Daniel Sandlerb73617d2010-08-17 00:41:00 -04005871 Settings.System.USER_ROTATION,
Christopher Tate5e08af02012-09-21 17:17:22 -07005872 rot,
5873 UserHandle.USER_CURRENT);
5874 Settings.System.putIntForUser(res,
Daniel Sandler2ed6ad62011-02-22 14:54:17 -05005875 Settings.System.ACCELEROMETER_ROTATION,
Christopher Tate5e08af02012-09-21 17:17:22 -07005876 0,
5877 UserHandle.USER_CURRENT);
Daniel Sandlerb73617d2010-08-17 00:41:00 -04005878 } else {
Christopher Tate5e08af02012-09-21 17:17:22 -07005879 Settings.System.putIntForUser(res,
Daniel Sandlerb73617d2010-08-17 00:41:00 -04005880 Settings.System.ACCELEROMETER_ROTATION,
Christopher Tate5e08af02012-09-21 17:17:22 -07005881 1,
5882 UserHandle.USER_CURRENT);
Daniel Sandlerb73617d2010-08-17 00:41:00 -04005883 }
5884 }
5885
Jose Lima9546b202014-07-02 17:21:51 -07005886 @Override
Jeff Brownac143512012-04-05 18:57:33 -07005887 public void setSafeMode(boolean safeMode) {
5888 mSafeMode = safeMode;
5889 performHapticFeedbackLw(null, safeMode
5890 ? HapticFeedbackConstants.SAFE_MODE_ENABLED
5891 : HapticFeedbackConstants.SAFE_MODE_DISABLED, true);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005892 }
Craig Mautnereda67292013-04-28 13:50:14 -07005893
Dianne Hackborn181ceb52009-08-27 22:16:40 -07005894 static long[] getLongIntArray(Resources r, int resid) {
5895 int[] ar = r.getIntArray(resid);
5896 if (ar == null) {
5897 return null;
5898 }
5899 long[] out = new long[ar.length];
5900 for (int i=0; i<ar.length; i++) {
5901 out[i] = ar[i];
5902 }
5903 return out;
5904 }
Craig Mautnereda67292013-04-28 13:50:14 -07005905
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005906 /** {@inheritDoc} */
Craig Mautnereda67292013-04-28 13:50:14 -07005907 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005908 public void systemReady() {
Jim Millerab954542014-10-10 18:21:49 -07005909 mKeyguardDelegate = new KeyguardServiceDelegate(mContext);
Mike Lockwooded8902d2013-11-15 11:01:47 -08005910 mKeyguardDelegate.onSystemReady();
5911
Michael Wright3818c922014-09-02 13:59:07 -07005912 readCameraLensCoverState();
Jeff Brown4f5fa282014-06-12 19:19:15 -07005913 updateUiMode();
Dianne Hackbornb1a79802009-09-29 15:18:31 -07005914 synchronized (mLock) {
5915 updateOrientationListenerLp();
Dianne Hackbornc777e072010-02-12 13:07:59 -08005916 mSystemReady = true;
5917 mHandler.post(new Runnable() {
Craig Mautnereda67292013-04-28 13:50:14 -07005918 @Override
Dianne Hackbornc777e072010-02-12 13:07:59 -08005919 public void run() {
5920 updateSettings();
5921 }
5922 });
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005923 }
5924 }
Dianne Hackborn661cd522011-08-22 00:26:20 -07005925
Dianne Hackbornba24e4d2011-09-01 11:17:06 -07005926 /** {@inheritDoc} */
Jose Lima9546b202014-07-02 17:21:51 -07005927 @Override
Dianne Hackbornba24e4d2011-09-01 11:17:06 -07005928 public void systemBooted() {
Jim Millere5f910a2013-10-16 18:15:46 -07005929 if (mKeyguardDelegate != null) {
Jason Monk5eeebf52014-09-26 12:36:51 -04005930 mKeyguardDelegate.bindService(mContext);
Jim Millere5f910a2013-10-16 18:15:46 -07005931 mKeyguardDelegate.onBootCompleted();
5932 }
Dianne Hackbornba24e4d2011-09-01 11:17:06 -07005933 synchronized (mLock) {
5934 mSystemBooted = true;
5935 }
Jeff Brown416c49c2015-05-26 19:50:18 -07005936 startedWakingUp();
Jeff Brown36c4db82014-09-19 12:05:31 -07005937 screenTurningOn(null);
Dianne Hackbornba24e4d2011-09-01 11:17:06 -07005938 }
5939
Dianne Hackborn661cd522011-08-22 00:26:20 -07005940 ProgressDialog mBootMsgDialog = null;
5941
5942 /** {@inheritDoc} */
Jose Lima9546b202014-07-02 17:21:51 -07005943 @Override
Dianne Hackborn661cd522011-08-22 00:26:20 -07005944 public void showBootMessage(final CharSequence msg, final boolean always) {
5945 mHandler.post(new Runnable() {
5946 @Override public void run() {
5947 if (mBootMsgDialog == null) {
Craig Stout4c0cb8a2014-04-04 13:03:10 -07005948 int theme;
5949 if (mContext.getPackageManager().hasSystemFeature(
5950 PackageManager.FEATURE_WATCH)) {
5951 theme = com.android.internal.R.style.Theme_Micro_Dialog_Alert;
5952 } else if (mContext.getPackageManager().hasSystemFeature(
5953 PackageManager.FEATURE_TELEVISION)) {
5954 theme = com.android.internal.R.style.Theme_Leanback_Dialog_Alert;
5955 } else {
5956 theme = 0;
5957 }
Vinod Krishnanfa8fc412014-04-18 14:35:53 -07005958
5959 mBootMsgDialog = new ProgressDialog(mContext, theme) {
Dianne Hackborn295e3c22011-08-25 13:19:08 -07005960 // This dialog will consume all events coming in to
5961 // it, to avoid it trying to do things too early in boot.
5962 @Override public boolean dispatchKeyEvent(KeyEvent event) {
5963 return true;
5964 }
5965 @Override public boolean dispatchKeyShortcutEvent(KeyEvent event) {
5966 return true;
5967 }
5968 @Override public boolean dispatchTouchEvent(MotionEvent ev) {
5969 return true;
5970 }
5971 @Override public boolean dispatchTrackballEvent(MotionEvent ev) {
5972 return true;
5973 }
5974 @Override public boolean dispatchGenericMotionEvent(MotionEvent ev) {
5975 return true;
5976 }
5977 @Override public boolean dispatchPopulateAccessibilityEvent(
5978 AccessibilityEvent event) {
5979 return true;
5980 }
5981 };
Jeff Hao9f60c082014-10-28 18:51:07 -07005982 if (mContext.getPackageManager().isUpgrade()) {
5983 mBootMsgDialog.setTitle(R.string.android_upgrading_title);
5984 } else {
5985 mBootMsgDialog.setTitle(R.string.android_start_title);
5986 }
Dianne Hackborn661cd522011-08-22 00:26:20 -07005987 mBootMsgDialog.setProgressStyle(ProgressDialog.STYLE_SPINNER);
5988 mBootMsgDialog.setIndeterminate(true);
5989 mBootMsgDialog.getWindow().setType(
Dianne Hackborn29aae6f2011-08-18 18:30:09 -07005990 WindowManager.LayoutParams.TYPE_BOOT_PROGRESS);
Dianne Hackborn661cd522011-08-22 00:26:20 -07005991 mBootMsgDialog.getWindow().addFlags(
5992 WindowManager.LayoutParams.FLAG_DIM_BEHIND
5993 | WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN);
5994 mBootMsgDialog.getWindow().setDimAmount(1);
Dianne Hackbornd9efb952011-12-07 14:56:51 -08005995 WindowManager.LayoutParams lp = mBootMsgDialog.getWindow().getAttributes();
5996 lp.screenOrientation = ActivityInfo.SCREEN_ORIENTATION_NOSENSOR;
5997 mBootMsgDialog.getWindow().setAttributes(lp);
Dianne Hackborn661cd522011-08-22 00:26:20 -07005998 mBootMsgDialog.setCancelable(false);
5999 mBootMsgDialog.show();
6000 }
6001 mBootMsgDialog.setMessage(msg);
6002 }
6003 });
6004 }
6005
6006 /** {@inheritDoc} */
Jose Lima9546b202014-07-02 17:21:51 -07006007 @Override
Dianne Hackborn661cd522011-08-22 00:26:20 -07006008 public void hideBootMessages() {
Craig Mautnera631d492014-08-05 15:16:01 -07006009 mHandler.sendEmptyMessage(MSG_HIDE_BOOT_MESSAGE);
Dianne Hackborn661cd522011-08-22 00:26:20 -07006010 }
6011
Mike Lockwood28569302010-01-28 11:54:40 -05006012 /** {@inheritDoc} */
Jose Lima9546b202014-07-02 17:21:51 -07006013 @Override
Mike Lockwood28569302010-01-28 11:54:40 -05006014 public void userActivity() {
Dianne Hackborndf89e652011-10-06 22:35:11 -07006015 // ***************************************
6016 // NOTE NOTE NOTE NOTE NOTE NOTE NOTE NOTE
6017 // ***************************************
6018 // THIS IS CALLED FROM DEEP IN THE POWER MANAGER
6019 // WITH ITS LOCKS HELD.
6020 //
6021 // This code must be VERY careful about the locks
6022 // it acquires.
6023 // In fact, the current code acquires way too many,
6024 // and probably has lurking deadlocks.
6025
Mike Lockwood28569302010-01-28 11:54:40 -05006026 synchronized (mScreenLockTimeout) {
6027 if (mLockScreenTimerActive) {
6028 // reset the timer
6029 mHandler.removeCallbacks(mScreenLockTimeout);
6030 mHandler.postDelayed(mScreenLockTimeout, mLockScreenTimeout);
6031 }
6032 }
Daniel Sandler0601eb72011-04-13 01:01:32 -04006033 }
6034
Adam Cohenf7522022012-10-03 20:03:18 -07006035 class ScreenLockTimeout implements Runnable {
6036 Bundle options;
6037
6038 @Override
Mike Lockwood28569302010-01-28 11:54:40 -05006039 public void run() {
6040 synchronized (this) {
6041 if (localLOGV) Log.v(TAG, "mScreenLockTimeout activating keyguard");
Jim Miller5ecd8112013-01-09 18:50:26 -08006042 if (mKeyguardDelegate != null) {
6043 mKeyguardDelegate.doKeyguardTimeout(options);
Mike Lockwood3a74bd32011-08-12 13:55:22 -07006044 }
Mike Lockwood28569302010-01-28 11:54:40 -05006045 mLockScreenTimerActive = false;
Adam Cohenf7522022012-10-03 20:03:18 -07006046 options = null;
Mike Lockwood28569302010-01-28 11:54:40 -05006047 }
6048 }
Mike Lockwood28569302010-01-28 11:54:40 -05006049
Adam Cohenf7522022012-10-03 20:03:18 -07006050 public void setLockOptions(Bundle options) {
6051 this.options = options;
6052 }
6053 }
6054
6055 ScreenLockTimeout mScreenLockTimeout = new ScreenLockTimeout();
6056
Jose Lima9546b202014-07-02 17:21:51 -07006057 @Override
Adam Cohenf7522022012-10-03 20:03:18 -07006058 public void lockNow(Bundle options) {
Jim Miller93c518e2012-01-17 15:55:31 -08006059 mContext.enforceCallingOrSelfPermission(android.Manifest.permission.DEVICE_POWER, null);
6060 mHandler.removeCallbacks(mScreenLockTimeout);
Adam Cohenf7522022012-10-03 20:03:18 -07006061 if (options != null) {
6062 // In case multiple calls are made to lockNow, we don't wipe out the options
6063 // until the runnable actually executes.
6064 mScreenLockTimeout.setLockOptions(options);
6065 }
Jim Miller93c518e2012-01-17 15:55:31 -08006066 mHandler.post(mScreenLockTimeout);
6067 }
6068
Mike Lockwood28569302010-01-28 11:54:40 -05006069 private void updateLockScreenTimeout() {
6070 synchronized (mScreenLockTimeout) {
Jeff Brown3ee549c2014-09-22 20:14:39 -07006071 boolean enable = (mAllowLockscreenWhenOn && mAwake &&
Jim Miller5ecd8112013-01-09 18:50:26 -08006072 mKeyguardDelegate != null && mKeyguardDelegate.isSecure());
Mike Lockwood28569302010-01-28 11:54:40 -05006073 if (mLockScreenTimerActive != enable) {
6074 if (enable) {
6075 if (localLOGV) Log.v(TAG, "setting lockscreen timer");
6076 mHandler.postDelayed(mScreenLockTimeout, mLockScreenTimeout);
6077 } else {
6078 if (localLOGV) Log.v(TAG, "clearing lockscreen timer");
6079 mHandler.removeCallbacks(mScreenLockTimeout);
6080 }
6081 mLockScreenTimerActive = enable;
6082 }
6083 }
6084 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006085
Jeff Brown061ea992015-04-17 19:55:47 -07006086 private void updateDreamingSleepToken(boolean acquire) {
6087 if (acquire) {
6088 if (mDreamingSleepToken == null) {
6089 mDreamingSleepToken = mActivityManagerInternal.acquireSleepToken("Dream");
6090 }
6091 } else {
6092 if (mDreamingSleepToken != null) {
6093 mDreamingSleepToken.release();
Jeff Brown48d1b142015-06-10 16:36:03 -07006094 mDreamingSleepToken = null;
6095 }
6096 }
6097 }
6098
6099 private void updateScreenOffSleepToken(boolean acquire) {
6100 if (acquire) {
6101 if (mScreenOffSleepToken == null) {
6102 mScreenOffSleepToken = mActivityManagerInternal.acquireSleepToken("ScreenOff");
6103 }
6104 } else {
6105 if (mScreenOffSleepToken != null) {
6106 mScreenOffSleepToken.release();
6107 mScreenOffSleepToken = null;
Jeff Brown061ea992015-04-17 19:55:47 -07006108 }
6109 }
6110 }
6111
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006112 /** {@inheritDoc} */
Craig Mautnereda67292013-04-28 13:50:14 -07006113 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006114 public void enableScreenAfterBoot() {
6115 readLidState();
Jeff Brownc458ce92012-04-30 14:58:40 -07006116 applyLidSwitchState();
Jeff Brown01a98dd2011-09-20 15:08:29 -07006117 updateRotation(true);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006118 }
Dianne Hackbornf54c8f92009-09-19 14:03:57 -07006119
Jeff Brownc458ce92012-04-30 14:58:40 -07006120 private void applyLidSwitchState() {
Jeff Brownc458ce92012-04-30 14:58:40 -07006121 if (mLidState == LID_CLOSED && mLidControlsSleep) {
Jeff Brown6d8fd272014-05-20 21:24:38 -07006122 mPowerManager.goToSleep(SystemClock.uptimeMillis(),
Jeff Brownc12035c2014-08-13 18:52:25 -07006123 PowerManager.GO_TO_SLEEP_REASON_LID_SWITCH,
Jeff Brown6d8fd272014-05-20 21:24:38 -07006124 PowerManager.GO_TO_SLEEP_FLAG_NO_DOZE);
Jeff Brownc458ce92012-04-30 14:58:40 -07006125 }
Jeff Browna20dda42014-05-27 20:57:24 -07006126
6127 synchronized (mLock) {
6128 updateWakeGestureListenerLp();
6129 }
Jeff Brown01a98dd2011-09-20 15:08:29 -07006130 }
6131
Jeff Brown4f5fa282014-06-12 19:19:15 -07006132 void updateUiMode() {
6133 if (mUiModeManager == null) {
6134 mUiModeManager = IUiModeManager.Stub.asInterface(
6135 ServiceManager.getService(Context.UI_MODE_SERVICE));
6136 }
6137 try {
6138 mUiMode = mUiModeManager.getCurrentModeType();
6139 } catch (RemoteException e) {
6140 }
6141 }
6142
Jeff Brown01a98dd2011-09-20 15:08:29 -07006143 void updateRotation(boolean alwaysSendConfiguration) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006144 try {
6145 //set orientation on WindowManager
Dianne Hackbornf87d1962012-04-04 12:48:24 -07006146 mWindowManager.updateRotation(alwaysSendConfiguration, false);
6147 } catch (RemoteException e) {
6148 // Ignore
6149 }
6150 }
6151
6152 void updateRotation(boolean alwaysSendConfiguration, boolean forceRelayout) {
6153 try {
6154 //set orientation on WindowManager
6155 mWindowManager.updateRotation(alwaysSendConfiguration, forceRelayout);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006156 } catch (RemoteException e) {
6157 // Ignore
6158 }
6159 }
6160
Daniel Sandler6396c722013-04-16 20:19:09 -04006161 /**
6162 * Return an Intent to launch the currently active dock app as home. Returns
6163 * null if the standard home should be launched, which is the case if any of the following is
6164 * true:
6165 * <ul>
6166 * <li>The device is not in either car mode or desk mode
6167 * <li>The device is in car mode but ENABLE_CAR_DOCK_HOME_CAPTURE is false
6168 * <li>The device is in desk mode but ENABLE_DESK_DOCK_HOME_CAPTURE is false
6169 * <li>The device is in car mode but there's no CAR_DOCK app with METADATA_DOCK_HOME
6170 * <li>The device is in desk mode but there's no DESK_DOCK app with METADATA_DOCK_HOME
6171 * </ul>
Craig Mautnereda67292013-04-28 13:50:14 -07006172 * @return A dock intent.
Daniel Sandler6396c722013-04-16 20:19:09 -04006173 */
6174 Intent createHomeDockIntent() {
6175 Intent intent = null;
6176
6177 // What home does is based on the mode, not the dock state. That
6178 // is, when in car mode you should be taken to car home regardless
6179 // of whether we are actually in a car dock.
6180 if (mUiMode == Configuration.UI_MODE_TYPE_CAR) {
6181 if (ENABLE_CAR_DOCK_HOME_CAPTURE) {
6182 intent = mCarDockIntent;
6183 }
6184 } else if (mUiMode == Configuration.UI_MODE_TYPE_DESK) {
6185 if (ENABLE_DESK_DOCK_HOME_CAPTURE) {
6186 intent = mDeskDockIntent;
6187 }
Jeff Brown4f5fa282014-06-12 19:19:15 -07006188 } else if (mUiMode == Configuration.UI_MODE_TYPE_WATCH
6189 && (mDockMode == Intent.EXTRA_DOCK_STATE_DESK
6190 || mDockMode == Intent.EXTRA_DOCK_STATE_HE_DESK
6191 || mDockMode == Intent.EXTRA_DOCK_STATE_LE_DESK)) {
6192 // Always launch dock home from home when watch is docked, if it exists.
6193 intent = mDeskDockIntent;
Daniel Sandler6396c722013-04-16 20:19:09 -04006194 }
6195
6196 if (intent == null) {
6197 return null;
6198 }
6199
6200 ActivityInfo ai = null;
6201 ResolveInfo info = mContext.getPackageManager().resolveActivityAsUser(
6202 intent,
John Spurlockf56bef12013-07-09 09:51:46 -04006203 PackageManager.MATCH_DEFAULT_ONLY | PackageManager.GET_META_DATA,
Craig Mautnerd625ab22013-09-06 13:40:31 -07006204 mCurrentUserId);
Daniel Sandler6396c722013-04-16 20:19:09 -04006205 if (info != null) {
6206 ai = info.activityInfo;
6207 }
6208 if (ai != null
6209 && ai.metaData != null
6210 && ai.metaData.getBoolean(Intent.METADATA_DOCK_HOME)) {
6211 intent = new Intent(intent);
6212 intent.setClassName(ai.packageName, ai.name);
6213 return intent;
6214 }
6215
6216 return null;
6217 }
6218
Filip Gruszczynskia483a1d2015-03-17 19:06:58 +00006219 void startDockOrHome(boolean fromHomeKey, boolean awakenFromDreams) {
6220 if (awakenFromDreams) {
6221 awakenDreams();
6222 }
Daniel Sandler6396c722013-04-16 20:19:09 -04006223
6224 Intent dock = createHomeDockIntent();
6225 if (dock != null) {
6226 try {
Bryce Lee01b0c5f2015-02-05 18:24:04 -08006227 if (fromHomeKey) {
6228 dock.putExtra(WindowManagerPolicy.EXTRA_FROM_HOME_KEY, fromHomeKey);
6229 }
Bart Sears8b1c27c2015-03-18 23:51:02 +00006230 startActivityAsUser(dock, UserHandle.CURRENT);
Daniel Sandler6396c722013-04-16 20:19:09 -04006231 return;
6232 } catch (ActivityNotFoundException e) {
6233 }
6234 }
6235
Bryce Lee01b0c5f2015-02-05 18:24:04 -08006236 Intent intent;
6237
6238 if (fromHomeKey) {
6239 intent = new Intent(mHomeIntent);
6240 intent.putExtra(WindowManagerPolicy.EXTRA_FROM_HOME_KEY, fromHomeKey);
6241 } else {
6242 intent = mHomeIntent;
6243 }
6244
Bryce Lee9fc0b6f2015-03-19 21:37:45 +00006245 startActivityAsUser(intent, UserHandle.CURRENT);
Dianne Hackborn39c2d712009-09-22 11:41:31 -07006246 }
Craig Mautnereda67292013-04-28 13:50:14 -07006247
Dianne Hackborn39c2d712009-09-22 11:41:31 -07006248 /**
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006249 * goes to the home screen
6250 * @return whether it did anything
6251 */
6252 boolean goHome() {
Bart Sears8b1c27c2015-03-18 23:51:02 +00006253 if (!isUserSetupComplete()) {
6254 Slog.i(TAG, "Not going home because user setup is in progress.");
6255 return false;
6256 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006257 if (false) {
6258 // This code always brings home to the front.
Dianne Hackborn256dd3b2009-05-19 18:51:21 -07006259 try {
6260 ActivityManagerNative.getDefault().stopAppSwitches();
6261 } catch (RemoteException e) {
6262 }
Dianne Hackborn94a679d2009-07-28 17:51:07 -07006263 sendCloseSystemWindows();
Filip Gruszczynskia483a1d2015-03-17 19:06:58 +00006264 startDockOrHome(false /*fromHomeKey*/, true /* awakenFromDreams */);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006265 } else {
6266 // This code brings home to the front or, if it is already
6267 // at the front, puts the device to sleep.
6268 try {
Wink Savilled2e6a332010-02-12 12:12:06 -08006269 if (SystemProperties.getInt("persist.sys.uts-test-mode", 0) == 1) {
6270 /// Roll back EndcallBehavior as the cupcake design to pass P1 lab entry.
6271 Log.d(TAG, "UTS-TEST-MODE");
6272 } else {
6273 ActivityManagerNative.getDefault().stopAppSwitches();
6274 sendCloseSystemWindows();
Daniel Sandler6396c722013-04-16 20:19:09 -04006275 Intent dock = createHomeDockIntent();
6276 if (dock != null) {
6277 int result = ActivityManagerNative.getDefault()
6278 .startActivityAsUser(null, null, dock,
6279 dock.resolveTypeIfNeeded(mContext.getContentResolver()),
6280 null, null, 0,
6281 ActivityManager.START_FLAG_ONLY_IF_NEEDED,
Jeff Hao1b012d32014-08-20 10:35:34 -07006282 null, null, UserHandle.USER_CURRENT);
Daniel Sandler6396c722013-04-16 20:19:09 -04006283 if (result == ActivityManager.START_RETURN_INTENT_TO_CALLER) {
6284 return false;
6285 }
6286 }
Dianne Hackborn39c2d712009-09-22 11:41:31 -07006287 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006288 int result = ActivityManagerNative.getDefault()
Dianne Hackbornf265ea92013-01-31 15:00:51 -08006289 .startActivityAsUser(null, null, mHomeIntent,
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006290 mHomeIntent.resolveTypeIfNeeded(mContext.getContentResolver()),
Dianne Hackborna4972e92012-03-14 10:38:05 -07006291 null, null, 0,
6292 ActivityManager.START_FLAG_ONLY_IF_NEEDED,
Jeff Hao1b012d32014-08-20 10:35:34 -07006293 null, null, UserHandle.USER_CURRENT);
Dianne Hackborna4972e92012-03-14 10:38:05 -07006294 if (result == ActivityManager.START_RETURN_INTENT_TO_CALLER) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006295 return false;
6296 }
6297 } catch (RemoteException ex) {
6298 // bummer, the activity manager, which is in this process, is dead
6299 }
6300 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006301 return true;
6302 }
Craig Mautnereda67292013-04-28 13:50:14 -07006303
6304 @Override
The Android Open Source Project0727d222009-03-11 12:11:58 -07006305 public void setCurrentOrientationLw(int newOrientation) {
6306 synchronized (mLock) {
6307 if (newOrientation != mCurrentAppOrientation) {
6308 mCurrentAppOrientation = newOrientation;
6309 updateOrientationListenerLp();
6310 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006311 }
6312 }
Amith Yamasanic33cb712010-02-10 15:21:49 -08006313
Svetoslav Ganov7befb7d2012-09-27 16:49:23 -07006314 private void performAuditoryFeedbackForAccessibilityIfNeed() {
6315 if (!isGlobalAccessibilityGestureEnabled()) {
6316 return;
6317 }
6318 AudioManager audioManager = (AudioManager) mContext.getSystemService(
6319 Context.AUDIO_SERVICE);
6320 if (audioManager.isSilentMode()) {
6321 return;
6322 }
6323 Ringtone ringTone = RingtoneManager.getRingtone(mContext,
6324 Settings.System.DEFAULT_NOTIFICATION_URI);
6325 ringTone.setStreamType(AudioManager.STREAM_MUSIC);
6326 ringTone.play();
6327 }
Craig Mautnereda67292013-04-28 13:50:14 -07006328
Bryce Lee584a4452014-10-21 15:55:55 -07006329 private boolean isTheaterModeEnabled() {
6330 return Settings.Global.getInt(mContext.getContentResolver(),
6331 Settings.Global.THEATER_MODE_ON, 0) == 1;
6332 }
6333
Svetoslav Ganov7befb7d2012-09-27 16:49:23 -07006334 private boolean isGlobalAccessibilityGestureEnabled() {
6335 return Settings.Global.getInt(mContext.getContentResolver(),
6336 Settings.Global.ENABLE_ACCESSIBILITY_GLOBAL_GESTURE_ENABLED, 0) == 1;
6337 }
6338
Craig Mautnereda67292013-04-28 13:50:14 -07006339 @Override
The Android Open Source Project0727d222009-03-11 12:11:58 -07006340 public boolean performHapticFeedbackLw(WindowState win, int effectId, boolean always) {
Svetoslav Ganov96179212012-10-10 14:17:45 -07006341 if (!mVibrator.hasVibrator()) {
6342 return false;
6343 }
Christopher Tate5e08af02012-09-21 17:17:22 -07006344 final boolean hapticsDisabled = Settings.System.getIntForUser(mContext.getContentResolver(),
6345 Settings.System.HAPTIC_FEEDBACK_ENABLED, 0, UserHandle.USER_CURRENT) == 0;
Jeff Brown82379ba2014-07-25 19:03:28 -07006346 if (hapticsDisabled && !always) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006347 return false;
6348 }
Amith Yamasanic33cb712010-02-10 15:21:49 -08006349 long[] pattern = null;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006350 switch (effectId) {
6351 case HapticFeedbackConstants.LONG_PRESS:
Amith Yamasanic33cb712010-02-10 15:21:49 -08006352 pattern = mLongPressVibePattern;
6353 break;
Dianne Hackbornb1a79802009-09-29 15:18:31 -07006354 case HapticFeedbackConstants.VIRTUAL_KEY:
Amith Yamasanic33cb712010-02-10 15:21:49 -08006355 pattern = mVirtualKeyVibePattern;
6356 break;
6357 case HapticFeedbackConstants.KEYBOARD_TAP:
6358 pattern = mKeyboardTapVibePattern;
6359 break;
Fabrice Di Meglioeeff63a2013-08-05 12:07:24 -07006360 case HapticFeedbackConstants.CLOCK_TICK:
6361 pattern = mClockTickVibePattern;
6362 break;
Fabrice Di Megliobd9152f2013-10-01 11:21:31 -07006363 case HapticFeedbackConstants.CALENDAR_DATE:
6364 pattern = mCalendarDateVibePattern;
6365 break;
Dianne Hackbornb1a79802009-09-29 15:18:31 -07006366 case HapticFeedbackConstants.SAFE_MODE_DISABLED:
Amith Yamasanic33cb712010-02-10 15:21:49 -08006367 pattern = mSafeModeDisabledVibePattern;
6368 break;
Dianne Hackbornb1a79802009-09-29 15:18:31 -07006369 case HapticFeedbackConstants.SAFE_MODE_ENABLED:
Amith Yamasanic33cb712010-02-10 15:21:49 -08006370 pattern = mSafeModeEnabledVibePattern;
6371 break;
Mady Mellore8608912015-06-05 09:02:55 -07006372 case HapticFeedbackConstants.CONTEXT_CLICK:
6373 pattern = mContextClickVibePattern;
Mady Mellore82067b2015-04-30 09:58:35 -07006374 break;
Amith Yamasanic33cb712010-02-10 15:21:49 -08006375 default:
6376 return false;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006377 }
Dianne Hackbornf265ea92013-01-31 15:00:51 -08006378 int owningUid;
6379 String owningPackage;
6380 if (win != null) {
6381 owningUid = win.getOwningUid();
6382 owningPackage = win.getOwningPackage();
6383 } else {
6384 owningUid = android.os.Process.myUid();
Dianne Hackborn95d78532013-09-11 09:51:14 -07006385 owningPackage = mContext.getOpPackageName();
Dianne Hackbornf265ea92013-01-31 15:00:51 -08006386 }
Amith Yamasanic33cb712010-02-10 15:21:49 -08006387 if (pattern.length == 1) {
6388 // One-shot vibration
John Spurlock7b414672014-07-18 13:02:39 -04006389 mVibrator.vibrate(owningUid, owningPackage, pattern[0], VIBRATION_ATTRIBUTES);
Amith Yamasanic33cb712010-02-10 15:21:49 -08006390 } else {
6391 // Pattern vibration
John Spurlock7b414672014-07-18 13:02:39 -04006392 mVibrator.vibrate(owningUid, owningPackage, pattern, -1, VIBRATION_ATTRIBUTES);
Amith Yamasanic33cb712010-02-10 15:21:49 -08006393 }
6394 return true;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006395 }
Jeff Brownc38c9be2012-10-04 13:16:19 -07006396
6397 @Override
6398 public void keepScreenOnStartedLw() {
Daniel Sandler0601eb72011-04-13 01:01:32 -04006399 }
6400
Jeff Brownc38c9be2012-10-04 13:16:19 -07006401 @Override
6402 public void keepScreenOnStoppedLw() {
Jim Millerab954542014-10-10 18:21:49 -07006403 if (isKeyguardShowingAndNotOccluded()) {
Jim Miller25190572013-02-28 17:36:24 -08006404 mPowerManager.userActivity(SystemClock.uptimeMillis(), false);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006405 }
6406 }
Mike Lockwoodfcb39242009-10-21 23:01:07 -04006407
Dianne Hackborndf89e652011-10-06 22:35:11 -07006408 private int updateSystemUiVisibilityLw() {
Joe Onorato664644d2011-01-23 17:53:23 -08006409 // If there is no window focused, there will be nobody to handle the events
6410 // anyway, so just hang on in whatever state we're in until things settle down.
Adrian Roos53f28ec2014-10-29 17:26:12 +01006411 final WindowState win = mFocusedWindow != null ? mFocusedWindow
6412 : mTopFullscreenOpaqueWindowState;
John Spurlock79da8332013-09-20 12:04:47 -04006413 if (win == null) {
Dianne Hackborndf89e652011-10-06 22:35:11 -07006414 return 0;
6415 }
Jorim Jaggi380ecb82014-03-14 17:25:20 +01006416 if ((win.getAttrs().privateFlags & PRIVATE_FLAG_KEYGUARD) != 0 && mHideLockScreen == true) {
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07006417 // We are updating at a point where the keyguard has gotten
6418 // focus, but we were last in a state where the top window is
6419 // hiding it. This is probably because the keyguard as been
6420 // shown while the top window was displayed, so we want to ignore
6421 // it here because this is just a very transient change and it
6422 // will quickly lose focus once it correctly gets hidden.
6423 return 0;
6424 }
John Spurlock32beb2c2013-03-11 10:16:47 -04006425
John Spurlock1db8b682014-02-18 11:18:59 -05006426 int tmpVisibility = PolicyControl.getSystemUiVisibility(win, null)
Dianne Hackborne26ab702011-10-16 13:21:33 -07006427 & ~mResettingSystemUiFlags
6428 & ~mForceClearedSystemUiFlags;
John Spurlock79da8332013-09-20 12:04:47 -04006429 if (mForcingShowNavBar && win.getSurfaceLayer() < mForcingShowNavBarLayer) {
John Spurlockc6d1c602014-01-17 15:22:06 -05006430 tmpVisibility &= ~PolicyControl.adjustClearableFlags(win, View.SYSTEM_UI_CLEARABLE_FLAGS);
Dianne Hackborn891d3fb2013-01-09 18:31:37 -08006431 }
Adrian Rooscd3884d2015-02-18 17:25:23 +01006432 tmpVisibility = updateLightStatusBarLw(tmpVisibility);
John Spurlock79da8332013-09-20 12:04:47 -04006433 final int visibility = updateSystemBarsLw(win, mLastSystemUiFlags, tmpVisibility);
John Spurlockad3e6cb2013-04-30 08:47:43 -04006434 final int diff = visibility ^ mLastSystemUiFlags;
John Spurlock79da8332013-09-20 12:04:47 -04006435 final boolean needsMenu = win.getNeedsMenuLw(mTopFullscreenOpaqueWindowState);
Dianne Hackborne0f085d2011-11-30 18:41:15 -08006436 if (diff == 0 && mLastFocusNeedsMenu == needsMenu
John Spurlock79da8332013-09-20 12:04:47 -04006437 && mFocusedApp == win.getAppToken()) {
Dianne Hackborndf89e652011-10-06 22:35:11 -07006438 return 0;
6439 }
Dianne Hackborne26ab702011-10-16 13:21:33 -07006440 mLastSystemUiFlags = visibility;
Dianne Hackborn4eff8d32011-11-10 19:38:40 -08006441 mLastFocusNeedsMenu = needsMenu;
John Spurlock79da8332013-09-20 12:04:47 -04006442 mFocusedApp = win.getAppToken();
Dianne Hackborndf89e652011-10-06 22:35:11 -07006443 mHandler.post(new Runnable() {
Craig Mautnereda67292013-04-28 13:50:14 -07006444 @Override
Dianne Hackborndf89e652011-10-06 22:35:11 -07006445 public void run() {
Dianne Hackborn42e620c2012-06-24 13:20:51 -07006446 try {
6447 IStatusBarService statusbar = getStatusBarService();
6448 if (statusbar != null) {
Adrian Roos53f28ec2014-10-29 17:26:12 +01006449 statusbar.setSystemUiVisibility(visibility, 0xffffffff, win.toString());
Dianne Hackborn42e620c2012-06-24 13:20:51 -07006450 statusbar.topAppWindowChanged(needsMenu);
Joe Onorato664644d2011-01-23 17:53:23 -08006451 }
Dianne Hackborn42e620c2012-06-24 13:20:51 -07006452 } catch (RemoteException e) {
6453 // re-acquire status bar service next time it is needed.
6454 mStatusBarService = null;
Joe Onorato664644d2011-01-23 17:53:23 -08006455 }
Dianne Hackborndf89e652011-10-06 22:35:11 -07006456 }
6457 });
6458 return diff;
Joe Onorato664644d2011-01-23 17:53:23 -08006459 }
6460
Adrian Rooscd3884d2015-02-18 17:25:23 +01006461 private int updateLightStatusBarLw(int vis) {
6462 WindowState statusColorWin = isStatusBarKeyguard() && !mHideLockScreen
6463 ? mStatusBar
6464 : mTopFullscreenOpaqueOrDimmingWindowState;
6465
6466 if (statusColorWin != null) {
6467 if (statusColorWin == mTopFullscreenOpaqueWindowState) {
6468 // If the top fullscreen-or-dimming window is also the top fullscreen, respect
6469 // its light flag.
6470 vis &= ~View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR;
6471 vis |= PolicyControl.getSystemUiVisibility(statusColorWin, null)
6472 & View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR;
6473 } else if (statusColorWin != null && statusColorWin.isDimming()) {
6474 // Otherwise if it's dimming, clear the light flag.
6475 vis &= ~View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR;
6476 }
6477 }
6478 return vis;
6479 }
6480
John Spurlock79da8332013-09-20 12:04:47 -04006481 private int updateSystemBarsLw(WindowState win, int oldVis, int vis) {
John Spurlockbd957402013-10-03 11:38:39 -04006482 // apply translucent bar vis flags
Jorim Jaggi380ecb82014-03-14 17:25:20 +01006483 WindowState transWin = isStatusBarKeyguard() && !mHideLockScreen
6484 ? mStatusBar
John Spurlockbd957402013-10-03 11:38:39 -04006485 : mTopFullscreenOpaqueWindowState;
6486 vis = mStatusBarController.applyTranslucentFlagLw(transWin, vis, oldVis);
6487 vis = mNavigationBarController.applyTranslucentFlagLw(transWin, vis, oldVis);
6488
John Spurlock27735a42013-08-14 17:57:38 -04006489 // prevent status bar interaction from clearing certain flags
Selim Cinekf83e8242015-05-19 18:08:14 -07006490 int type = win.getAttrs().type;
6491 boolean statusBarHasFocus = type == TYPE_STATUS_BAR;
John Spurlock08ffcf52014-07-11 10:13:46 -04006492 if (statusBarHasFocus && !isStatusBarKeyguard()) {
John Spurlockad3e6cb2013-04-30 08:47:43 -04006493 int flags = View.SYSTEM_UI_FLAG_FULLSCREEN
6494 | View.SYSTEM_UI_FLAG_HIDE_NAVIGATION
John Spurlockcfc359a2013-09-05 10:42:03 -04006495 | View.SYSTEM_UI_FLAG_IMMERSIVE
Jorim Jaggi73fef8d2015-02-16 17:32:28 +01006496 | View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY
6497 | View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR;
John Spurlock08ffcf52014-07-11 10:13:46 -04006498 if (mHideLockScreen) {
Jorim Jaggi5cf17872014-03-26 18:31:48 +01006499 flags |= View.STATUS_BAR_TRANSLUCENT | View.NAVIGATION_BAR_TRANSLUCENT;
6500 }
John Spurlockbd957402013-10-03 11:38:39 -04006501 vis = (vis & ~flags) | (oldVis & flags);
John Spurlockad3e6cb2013-04-30 08:47:43 -04006502 }
John Spurlockad3e6cb2013-04-30 08:47:43 -04006503
Adrian Roos4fb3ee32014-08-22 19:29:09 +02006504 if (!areTranslucentBarsAllowed() && transWin != mStatusBar) {
Adrian Roosea562512014-05-05 13:33:03 +02006505 vis &= ~(View.NAVIGATION_BAR_TRANSLUCENT | View.STATUS_BAR_TRANSLUCENT
6506 | View.SYSTEM_UI_TRANSPARENT);
Alan Viverette5a0f4ec2013-10-07 15:10:29 -07006507 }
6508
John Spurlock27735a42013-08-14 17:57:38 -04006509 // update status bar
John Spurlockf1a36642013-10-12 17:50:42 -04006510 boolean immersiveSticky =
6511 (vis & View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY) != 0;
John Spurlock27735a42013-08-14 17:57:38 -04006512 boolean hideStatusBarWM =
John Spurlockbd957402013-10-03 11:38:39 -04006513 mTopFullscreenOpaqueWindowState != null &&
John Spurlockc6d1c602014-01-17 15:22:06 -05006514 (PolicyControl.getWindowFlags(mTopFullscreenOpaqueWindowState, null)
John Spurlock27735a42013-08-14 17:57:38 -04006515 & WindowManager.LayoutParams.FLAG_FULLSCREEN) != 0;
6516 boolean hideStatusBarSysui =
6517 (vis & View.SYSTEM_UI_FLAG_FULLSCREEN) != 0;
John Spurlockf1a36642013-10-12 17:50:42 -04006518 boolean hideNavBarSysui =
6519 (vis & View.SYSTEM_UI_FLAG_HIDE_NAVIGATION) != 0;
John Spurlockad3e6cb2013-04-30 08:47:43 -04006520
John Spurlock27735a42013-08-14 17:57:38 -04006521 boolean transientStatusBarAllowed =
6522 mStatusBar != null && (
6523 hideStatusBarWM
John Spurlockf1a36642013-10-12 17:50:42 -04006524 || (hideStatusBarSysui && immersiveSticky)
John Spurlock27735a42013-08-14 17:57:38 -04006525 || statusBarHasFocus);
6526
John Spurlockf1a36642013-10-12 17:50:42 -04006527 boolean transientNavBarAllowed =
6528 mNavigationBar != null &&
6529 hideNavBarSysui && immersiveSticky;
6530
Adrian Roosddc8b272015-05-21 16:28:27 -07006531 final long now = SystemClock.uptimeMillis();
6532 final boolean pendingPanic = mPendingPanicGestureUptime != 0
6533 && now - mPendingPanicGestureUptime <= PANIC_GESTURE_EXPIRATION;
6534 if (pendingPanic && hideNavBarSysui && !isStatusBarKeyguard() && mKeyguardDrawComplete) {
6535 // The user performed the panic gesture recently, we're about to hide the bars,
6536 // we're no longer on the Keyguard and the screen is ready. We can now request the bars.
6537 mPendingPanicGestureUptime = 0;
6538 mStatusBarController.showTransient();
6539 mNavigationBarController.showTransient();
6540 }
6541
John Spurlockf25706f2013-11-07 18:02:43 -05006542 boolean denyTransientStatus = mStatusBarController.isTransientShowRequested()
John Spurlockf1a36642013-10-12 17:50:42 -04006543 && !transientStatusBarAllowed && hideStatusBarSysui;
John Spurlockf25706f2013-11-07 18:02:43 -05006544 boolean denyTransientNav = mNavigationBarController.isTransientShowRequested()
John Spurlockf1a36642013-10-12 17:50:42 -04006545 && !transientNavBarAllowed;
6546 if (denyTransientStatus || denyTransientNav) {
John Spurlock27735a42013-08-14 17:57:38 -04006547 // clear the clearable flags instead
John Spurlockf1a36642013-10-12 17:50:42 -04006548 clearClearableFlagsLw();
tiger_huangc58d7562014-10-23 20:24:19 +08006549 vis &= ~View.SYSTEM_UI_CLEARABLE_FLAGS;
John Spurlockad3e6cb2013-04-30 08:47:43 -04006550 }
John Spurlock27735a42013-08-14 17:57:38 -04006551
Selim Cinekf98702e2015-05-20 22:48:40 -07006552 final boolean immersive = (vis & View.SYSTEM_UI_FLAG_IMMERSIVE) != 0;
6553 immersiveSticky = (vis & View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY) != 0;
6554 final boolean navAllowedHidden = immersive || immersiveSticky;
6555
Selim Cinekd6623612015-05-22 18:56:22 -07006556 if (hideNavBarSysui && !navAllowedHidden && windowTypeToLayerLw(win.getBaseType())
6557 > windowTypeToLayerLw(TYPE_INPUT_CONSUMER)) {
Selim Cinekf98702e2015-05-20 22:48:40 -07006558 // We can't hide the navbar from this window otherwise the input consumer would not get
6559 // the input events.
6560 vis = (vis & ~View.SYSTEM_UI_FLAG_HIDE_NAVIGATION);
6561 }
6562
John Spurlock27735a42013-08-14 17:57:38 -04006563 vis = mStatusBarController.updateVisibilityLw(transientStatusBarAllowed, oldVis, vis);
6564
6565 // update navigation bar
John Spurlockf1a36642013-10-12 17:50:42 -04006566 boolean oldImmersiveMode = isImmersiveMode(oldVis);
6567 boolean newImmersiveMode = isImmersiveMode(vis);
6568 if (win != null && oldImmersiveMode != newImmersiveMode) {
John Spurlock79da8332013-09-20 12:04:47 -04006569 final String pkg = win.getOwningPackage();
Maurice Lam99c6e072014-04-28 18:24:28 -07006570 mImmersiveModeConfirmation.immersiveModeChanged(pkg, newImmersiveMode,
6571 isUserSetupComplete());
John Spurlock34e13d92013-08-10 06:52:28 -04006572 }
John Spurlock27735a42013-08-14 17:57:38 -04006573
John Spurlockf1a36642013-10-12 17:50:42 -04006574 vis = mNavigationBarController.updateVisibilityLw(transientNavBarAllowed, oldVis, vis);
6575
John Spurlocke1f366f2013-08-05 12:22:40 -04006576 return vis;
John Spurlockad3e6cb2013-04-30 08:47:43 -04006577 }
6578
John Spurlockf1a36642013-10-12 17:50:42 -04006579 private void clearClearableFlagsLw() {
6580 int newVal = mResettingSystemUiFlags | View.SYSTEM_UI_CLEARABLE_FLAGS;
6581 if (newVal != mResettingSystemUiFlags) {
6582 mResettingSystemUiFlags = newVal;
6583 mWindowManagerFuncs.reevaluateStatusBarVisibility();
6584 }
6585 }
6586
6587 private boolean isImmersiveMode(int vis) {
6588 final int flags = View.SYSTEM_UI_FLAG_IMMERSIVE | View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY;
John Spurlock34e13d92013-08-10 06:52:28 -04006589 return mNavigationBar != null
6590 && (vis & View.SYSTEM_UI_FLAG_HIDE_NAVIGATION) != 0
Daniel Sandler900ece52013-10-18 15:53:27 -04006591 && (vis & flags) != 0
6592 && canHideNavigationBar();
John Spurlock34e13d92013-08-10 06:52:28 -04006593 }
6594
Alan Viverette5a0f4ec2013-10-07 15:10:29 -07006595 /**
Daniel Sandlerdd73ee42013-10-11 22:19:59 -04006596 * @return whether the navigation or status bar can be made translucent
6597 *
6598 * This should return true unless touch exploration is not enabled or
6599 * R.boolean.config_enableTranslucentDecor is false.
Alan Viverette5a0f4ec2013-10-07 15:10:29 -07006600 */
Daniel Sandlerdd73ee42013-10-11 22:19:59 -04006601 private boolean areTranslucentBarsAllowed() {
Svetoslav8e3feb12014-02-24 13:46:47 -08006602 return mTranslucentDecorEnabled
6603 && !mAccessibilityManager.isTouchExplorationEnabled();
Alan Viverette5a0f4ec2013-10-07 15:10:29 -07006604 }
6605
Daniel Sandler0c4ccff2011-10-19 16:39:14 -04006606 // Use this instead of checking config_showNavigationBar so that it can be consistently
6607 // overridden by qemu.hw.mainkeys in the emulator.
Craig Mautnereda67292013-04-28 13:50:14 -07006608 @Override
Daniel Sandler0c4ccff2011-10-19 16:39:14 -04006609 public boolean hasNavigationBar() {
6610 return mHasNavigationBar;
6611 }
6612
satok1bc0a492012-04-25 22:47:12 +09006613 @Override
6614 public void setLastInputMethodWindowLw(WindowState ime, WindowState target) {
6615 mLastInputMethodWindow = ime;
6616 mLastInputMethodTargetWindow = target;
6617 }
6618
Craig Mautnerf1b67412012-09-19 13:18:29 -07006619 @Override
Satoshi Kataoka658c7b82013-10-10 17:03:51 +09006620 public int getInputMethodWindowVisibleHeightLw() {
6621 return mDockBottom - mCurBottom;
6622 }
6623
6624 @Override
Craig Mautnerf1b67412012-09-19 13:18:29 -07006625 public void setCurrentUserLw(int newUserId) {
Craig Mautnerd625ab22013-09-06 13:40:31 -07006626 mCurrentUserId = newUserId;
Jim Miller5ecd8112013-01-09 18:50:26 -08006627 if (mKeyguardDelegate != null) {
6628 mKeyguardDelegate.setCurrentUser(newUserId);
Craig Mautnerf1b67412012-09-19 13:18:29 -07006629 }
John Spurlock13451a22012-09-28 14:40:41 -04006630 if (mStatusBarService != null) {
6631 try {
6632 mStatusBarService.setCurrentUser(newUserId);
6633 } catch (RemoteException e) {
6634 // oh well
6635 }
6636 }
Dianne Hackborn2ea9bae2012-11-02 18:43:48 -07006637 setLastInputMethodWindowLw(null, null);
Craig Mautnerf1b67412012-09-19 13:18:29 -07006638 }
6639
6640 @Override
Svetoslav Ganov545252f2012-12-10 18:29:24 -08006641 public boolean canMagnifyWindow(int windowType) {
6642 switch (windowType) {
6643 case WindowManager.LayoutParams.TYPE_INPUT_METHOD:
6644 case WindowManager.LayoutParams.TYPE_INPUT_METHOD_DIALOG:
6645 case WindowManager.LayoutParams.TYPE_NAVIGATION_BAR:
6646 case WindowManager.LayoutParams.TYPE_MAGNIFICATION_OVERLAY: {
6647 return false;
6648 }
6649 }
6650 return true;
6651 }
6652
6653 @Override
6654 public boolean isTopLevelWindow(int windowType) {
6655 if (windowType >= WindowManager.LayoutParams.FIRST_SUB_WINDOW
6656 && windowType <= WindowManager.LayoutParams.LAST_SUB_WINDOW) {
6657 return (windowType == WindowManager.LayoutParams.TYPE_APPLICATION_ATTACHED_DIALOG);
6658 }
6659 return true;
6660 }
6661
Jim Miller4eeb4f62012-11-08 00:04:29 -08006662 @Override
Jeff Brownd7a04de2012-06-17 14:17:52 -07006663 public void dump(String prefix, PrintWriter pw, String[] args) {
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08006664 pw.print(prefix); pw.print("mSafeMode="); pw.print(mSafeMode);
Dianne Hackbornba24e4d2011-09-01 11:17:06 -07006665 pw.print(" mSystemReady="); pw.print(mSystemReady);
6666 pw.print(" mSystemBooted="); pw.println(mSystemBooted);
Jeff Brown2e7760e2012-04-11 15:14:55 -07006667 pw.print(prefix); pw.print("mLidState="); pw.print(mLidState);
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08006668 pw.print(" mLidOpenRotation="); pw.print(mLidOpenRotation);
Michael Wright3818c922014-09-02 13:59:07 -07006669 pw.print(" mCameraLensCoverState="); pw.print(mCameraLensCoverState);
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08006670 pw.print(" mHdmiPlugged="); pw.println(mHdmiPlugged);
Dianne Hackborne26ab702011-10-16 13:21:33 -07006671 if (mLastSystemUiFlags != 0 || mResettingSystemUiFlags != 0
6672 || mForceClearedSystemUiFlags != 0) {
6673 pw.print(prefix); pw.print("mLastSystemUiFlags=0x");
6674 pw.print(Integer.toHexString(mLastSystemUiFlags));
6675 pw.print(" mResettingSystemUiFlags=0x");
6676 pw.print(Integer.toHexString(mResettingSystemUiFlags));
6677 pw.print(" mForceClearedSystemUiFlags=0x");
6678 pw.println(Integer.toHexString(mForceClearedSystemUiFlags));
Dianne Hackborndf89e652011-10-06 22:35:11 -07006679 }
Dianne Hackborn4eff8d32011-11-10 19:38:40 -08006680 if (mLastFocusNeedsMenu) {
6681 pw.print(prefix); pw.print("mLastFocusNeedsMenu=");
6682 pw.println(mLastFocusNeedsMenu);
6683 }
Jeff Browna20dda42014-05-27 20:57:24 -07006684 pw.print(prefix); pw.print("mWakeGestureEnabledSetting=");
6685 pw.println(mWakeGestureEnabledSetting);
6686
Jeff Brownbcdfc622014-03-06 19:13:04 -08006687 pw.print(prefix); pw.print("mSupportAutoRotation="); pw.println(mSupportAutoRotation);
Daniel Sandler6396c722013-04-16 20:19:09 -04006688 pw.print(prefix); pw.print("mUiMode="); pw.print(mUiMode);
6689 pw.print(" mDockMode="); pw.print(mDockMode);
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08006690 pw.print(" mCarDockRotation="); pw.print(mCarDockRotation);
6691 pw.print(" mDeskDockRotation="); pw.println(mDeskDockRotation);
6692 pw.print(prefix); pw.print("mUserRotationMode="); pw.print(mUserRotationMode);
6693 pw.print(" mUserRotation="); pw.print(mUserRotation);
Daniel Sandler2ed6ad62011-02-22 14:54:17 -05006694 pw.print(" mAllowAllRotations="); pw.println(mAllowAllRotations);
Dianne Hackborn6e2281d2012-06-19 17:48:32 -07006695 pw.print(prefix); pw.print("mCurrentAppOrientation="); pw.println(mCurrentAppOrientation);
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08006696 pw.print(prefix); pw.print("mCarDockEnablesAccelerometer=");
6697 pw.print(mCarDockEnablesAccelerometer);
6698 pw.print(" mDeskDockEnablesAccelerometer=");
6699 pw.println(mDeskDockEnablesAccelerometer);
6700 pw.print(prefix); pw.print("mLidKeyboardAccessibility=");
6701 pw.print(mLidKeyboardAccessibility);
6702 pw.print(" mLidNavigationAccessibility="); pw.print(mLidNavigationAccessibility);
Dianne Hackborn6e2281d2012-06-19 17:48:32 -07006703 pw.print(" mLidControlsSleep="); pw.println(mLidControlsSleep);
Jeff Brown6d8fd272014-05-20 21:24:38 -07006704 pw.print(prefix);
6705 pw.print("mShortPressOnPowerBehavior="); pw.print(mShortPressOnPowerBehavior);
6706 pw.print(" mLongPressOnPowerBehavior="); pw.println(mLongPressOnPowerBehavior);
Jeff Brown13f00f02014-10-31 14:45:50 -07006707 pw.print(prefix);
6708 pw.print("mDoublePressOnPowerBehavior="); pw.print(mDoublePressOnPowerBehavior);
6709 pw.print(" mTriplePressOnPowerBehavior="); pw.println(mTriplePressOnPowerBehavior);
Jeff Brown6d8fd272014-05-20 21:24:38 -07006710 pw.print(prefix); pw.print("mHasSoftInput="); pw.println(mHasSoftInput);
Jeff Brown3ee549c2014-09-22 20:14:39 -07006711 pw.print(prefix); pw.print("mAwake="); pw.println(mAwake);
6712 pw.print(prefix); pw.print("mScreenOnEarly="); pw.print(mScreenOnEarly);
6713 pw.print(" mScreenOnFully="); pw.println(mScreenOnFully);
6714 pw.print(prefix); pw.print("mKeyguardDrawComplete="); pw.print(mKeyguardDrawComplete);
6715 pw.print(" mWindowManagerDrawComplete="); pw.println(mWindowManagerDrawComplete);
6716 pw.print(prefix); pw.print("mOrientationSensorEnabled=");
6717 pw.println(mOrientationSensorEnabled);
Dianne Hackbornc652de82013-02-15 16:32:56 -08006718 pw.print(prefix); pw.print("mOverscanScreen=("); pw.print(mOverscanScreenLeft);
6719 pw.print(","); pw.print(mOverscanScreenTop);
6720 pw.print(") "); pw.print(mOverscanScreenWidth);
6721 pw.print("x"); pw.println(mOverscanScreenHeight);
6722 if (mOverscanLeft != 0 || mOverscanTop != 0
6723 || mOverscanRight != 0 || mOverscanBottom != 0) {
6724 pw.print(prefix); pw.print("mOverscan left="); pw.print(mOverscanLeft);
6725 pw.print(" top="); pw.print(mOverscanTop);
6726 pw.print(" right="); pw.print(mOverscanRight);
6727 pw.print(" bottom="); pw.println(mOverscanBottom);
6728 }
Dianne Hackborn313440842013-02-19 19:22:59 -08006729 pw.print(prefix); pw.print("mRestrictedOverscanScreen=(");
6730 pw.print(mRestrictedOverscanScreenLeft);
6731 pw.print(","); pw.print(mRestrictedOverscanScreenTop);
6732 pw.print(") "); pw.print(mRestrictedOverscanScreenWidth);
6733 pw.print("x"); pw.println(mRestrictedOverscanScreenHeight);
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08006734 pw.print(prefix); pw.print("mUnrestrictedScreen=("); pw.print(mUnrestrictedScreenLeft);
6735 pw.print(","); pw.print(mUnrestrictedScreenTop);
6736 pw.print(") "); pw.print(mUnrestrictedScreenWidth);
6737 pw.print("x"); pw.println(mUnrestrictedScreenHeight);
6738 pw.print(prefix); pw.print("mRestrictedScreen=("); pw.print(mRestrictedScreenLeft);
6739 pw.print(","); pw.print(mRestrictedScreenTop);
6740 pw.print(") "); pw.print(mRestrictedScreenWidth);
6741 pw.print("x"); pw.println(mRestrictedScreenHeight);
Dianne Hackborn5b5cc4d2012-05-16 13:15:00 -07006742 pw.print(prefix); pw.print("mStableFullscreen=("); pw.print(mStableFullscreenLeft);
6743 pw.print(","); pw.print(mStableFullscreenTop);
6744 pw.print(")-("); pw.print(mStableFullscreenRight);
6745 pw.print(","); pw.print(mStableFullscreenBottom); pw.println(")");
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07006746 pw.print(prefix); pw.print("mStable=("); pw.print(mStableLeft);
6747 pw.print(","); pw.print(mStableTop);
6748 pw.print(")-("); pw.print(mStableRight);
6749 pw.print(","); pw.print(mStableBottom); pw.println(")");
Dianne Hackborn5c58de32012-04-28 19:52:37 -07006750 pw.print(prefix); pw.print("mSystem=("); pw.print(mSystemLeft);
6751 pw.print(","); pw.print(mSystemTop);
6752 pw.print(")-("); pw.print(mSystemRight);
6753 pw.print(","); pw.print(mSystemBottom); pw.println(")");
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08006754 pw.print(prefix); pw.print("mCur=("); pw.print(mCurLeft);
6755 pw.print(","); pw.print(mCurTop);
6756 pw.print(")-("); pw.print(mCurRight);
6757 pw.print(","); pw.print(mCurBottom); pw.println(")");
6758 pw.print(prefix); pw.print("mContent=("); pw.print(mContentLeft);
6759 pw.print(","); pw.print(mContentTop);
6760 pw.print(")-("); pw.print(mContentRight);
6761 pw.print(","); pw.print(mContentBottom); pw.println(")");
Dianne Hackborne30e02f2014-05-27 18:24:45 -07006762 pw.print(prefix); pw.print("mVoiceContent=("); pw.print(mVoiceContentLeft);
6763 pw.print(","); pw.print(mVoiceContentTop);
6764 pw.print(")-("); pw.print(mVoiceContentRight);
6765 pw.print(","); pw.print(mVoiceContentBottom); pw.println(")");
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08006766 pw.print(prefix); pw.print("mDock=("); pw.print(mDockLeft);
6767 pw.print(","); pw.print(mDockTop);
6768 pw.print(")-("); pw.print(mDockRight);
6769 pw.print(","); pw.print(mDockBottom); pw.println(")");
Dianne Hackborn5c58de32012-04-28 19:52:37 -07006770 pw.print(prefix); pw.print("mDockLayer="); pw.print(mDockLayer);
6771 pw.print(" mStatusBarLayer="); pw.println(mStatusBarLayer);
Dianne Hackborn7ad44382012-10-18 17:46:00 -07006772 pw.print(prefix); pw.print("mShowingLockscreen="); pw.print(mShowingLockscreen);
6773 pw.print(" mShowingDream="); pw.print(mShowingDream);
Jeff Brown061ea992015-04-17 19:55:47 -07006774 pw.print(" mDreamingLockscreen="); pw.print(mDreamingLockscreen);
6775 pw.print(" mDreamingSleepToken="); pw.println(mDreamingSleepToken);
Dianne Hackborn2ea9bae2012-11-02 18:43:48 -07006776 if (mLastInputMethodWindow != null) {
6777 pw.print(prefix); pw.print("mLastInputMethodWindow=");
6778 pw.println(mLastInputMethodWindow);
6779 }
6780 if (mLastInputMethodTargetWindow != null) {
6781 pw.print(prefix); pw.print("mLastInputMethodTargetWindow=");
6782 pw.println(mLastInputMethodTargetWindow);
6783 }
6784 if (mStatusBar != null) {
6785 pw.print(prefix); pw.print("mStatusBar=");
Dianne Hackbornae6688b2015-02-11 17:02:41 -08006786 pw.print(mStatusBar); pw.print(" isStatusBarKeyguard=");
6787 pw.println(isStatusBarKeyguard());
Dianne Hackborn2ea9bae2012-11-02 18:43:48 -07006788 }
6789 if (mNavigationBar != null) {
6790 pw.print(prefix); pw.print("mNavigationBar=");
6791 pw.println(mNavigationBar);
6792 }
Dianne Hackborn2ea9bae2012-11-02 18:43:48 -07006793 if (mFocusedWindow != null) {
6794 pw.print(prefix); pw.print("mFocusedWindow=");
6795 pw.println(mFocusedWindow);
6796 }
6797 if (mFocusedApp != null) {
6798 pw.print(prefix); pw.print("mFocusedApp=");
6799 pw.println(mFocusedApp);
6800 }
6801 if (mWinDismissingKeyguard != null) {
6802 pw.print(prefix); pw.print("mWinDismissingKeyguard=");
6803 pw.println(mWinDismissingKeyguard);
6804 }
6805 if (mTopFullscreenOpaqueWindowState != null) {
6806 pw.print(prefix); pw.print("mTopFullscreenOpaqueWindowState=");
6807 pw.println(mTopFullscreenOpaqueWindowState);
6808 }
Adrian Rooscd3884d2015-02-18 17:25:23 +01006809 if (mTopFullscreenOpaqueOrDimmingWindowState != null) {
6810 pw.print(prefix); pw.print("mTopFullscreenOpaqueOrDimmingWindowState=");
6811 pw.println(mTopFullscreenOpaqueOrDimmingWindowState);
6812 }
Dianne Hackborn891d3fb2013-01-09 18:31:37 -08006813 if (mForcingShowNavBar) {
6814 pw.print(prefix); pw.print("mForcingShowNavBar=");
6815 pw.println(mForcingShowNavBar); pw.print( "mForcingShowNavBarLayer=");
6816 pw.println(mForcingShowNavBarLayer);
6817 }
Dianne Hackborn7ad44382012-10-18 17:46:00 -07006818 pw.print(prefix); pw.print("mTopIsFullscreen="); pw.print(mTopIsFullscreen);
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08006819 pw.print(" mHideLockScreen="); pw.println(mHideLockScreen);
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07006820 pw.print(prefix); pw.print("mForceStatusBar="); pw.print(mForceStatusBar);
6821 pw.print(" mForceStatusBarFromKeyguard=");
6822 pw.println(mForceStatusBarFromKeyguard);
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08006823 pw.print(prefix); pw.print("mDismissKeyguard="); pw.print(mDismissKeyguard);
Craig Mautnerad09bcc2012-10-08 13:33:11 -07006824 pw.print(" mWinDismissingKeyguard="); pw.print(mWinDismissingKeyguard);
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08006825 pw.print(" mHomePressed="); pw.println(mHomePressed);
6826 pw.print(prefix); pw.print("mAllowLockscreenWhenOn="); pw.print(mAllowLockscreenWhenOn);
6827 pw.print(" mLockScreenTimeout="); pw.print(mLockScreenTimeout);
6828 pw.print(" mLockScreenTimerActive="); pw.println(mLockScreenTimerActive);
6829 pw.print(prefix); pw.print("mEndcallBehavior="); pw.print(mEndcallBehavior);
6830 pw.print(" mIncallPowerBehavior="); pw.print(mIncallPowerBehavior);
6831 pw.print(" mLongPressOnHomeBehavior="); pw.println(mLongPressOnHomeBehavior);
6832 pw.print(prefix); pw.print("mLandscapeRotation="); pw.print(mLandscapeRotation);
6833 pw.print(" mSeascapeRotation="); pw.println(mSeascapeRotation);
6834 pw.print(prefix); pw.print("mPortraitRotation="); pw.print(mPortraitRotation);
6835 pw.print(" mUpsideDownRotation="); pw.println(mUpsideDownRotation);
Jeff Brownc82c89ed2013-04-17 17:18:15 -07006836 pw.print(prefix); pw.print("mDemoHdmiRotation="); pw.print(mDemoHdmiRotation);
6837 pw.print(" mDemoHdmiRotationLock="); pw.println(mDemoHdmiRotationLock);
6838 pw.print(prefix); pw.print("mUndockedHdmiRotation="); pw.println(mUndockedHdmiRotation);
Jeff Brown600f0032014-05-22 17:06:00 -07006839
Tim Kilbournd7c0c2e2014-05-29 16:08:10 -07006840 mGlobalKeyManager.dump(prefix, pw);
John Spurlock27735a42013-08-14 17:57:38 -04006841 mStatusBarController.dump(pw, prefix);
6842 mNavigationBarController.dump(pw, prefix);
John Spurlockc6d1c602014-01-17 15:22:06 -05006843 PolicyControl.dump(prefix, pw);
Jeff Brown600f0032014-05-22 17:06:00 -07006844
Jeff Browna20dda42014-05-27 20:57:24 -07006845 if (mWakeGestureListener != null) {
6846 mWakeGestureListener.dump(pw, prefix);
6847 }
Jeff Brown600f0032014-05-22 17:06:00 -07006848 if (mOrientationListener != null) {
6849 mOrientationListener.dump(pw, prefix);
6850 }
Filip Gruszczynskicfb31852015-02-25 21:47:12 +00006851 if (mBurnInProtectionHelper != null) {
6852 mBurnInProtectionHelper.dump(prefix, pw);
6853 }
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08006854 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006855}