blob: b77a25349070da8b9f617038cc2b823b6ebe436a [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:
1042 if (isTheaterModeEnabled()) {
1043 Slog.i(TAG, "Toggling theater mode off.");
1044 Settings.Global.putInt(mContext.getContentResolver(),
1045 Settings.Global.THEATER_MODE_ON, 0);
1046 if (!interactive) {
1047 wakeUpFromPowerKey(eventTime);
1048 }
1049 } else {
1050 Slog.i(TAG, "Toggling theater mode on.");
1051 Settings.Global.putInt(mContext.getContentResolver(),
1052 Settings.Global.THEATER_MODE_ON, 1);
Bryce Lee55e846d2014-11-04 12:43:44 -08001053
1054 if (mGoToSleepOnButtonPressTheaterMode && interactive) {
Jeff Brown13f00f02014-10-31 14:45:50 -07001055 mPowerManager.goToSleep(eventTime,
1056 PowerManager.GO_TO_SLEEP_REASON_POWER_BUTTON, 0);
1057 }
1058 }
1059 break;
1060 case MULTI_PRESS_POWER_BRIGHTNESS_BOOST:
Jeff Brown7b5be5e2014-11-12 18:45:31 -08001061 Slog.i(TAG, "Starting brightness boost.");
1062 if (!interactive) {
1063 wakeUpFromPowerKey(eventTime);
1064 }
Jeff Brown13f00f02014-10-31 14:45:50 -07001065 mPowerManager.boostScreenBrightness(eventTime);
1066 break;
1067 }
1068 }
1069
1070 private int getMaxMultiPressPowerCount() {
1071 if (mTriplePressOnPowerBehavior != MULTI_PRESS_POWER_NOTHING) {
1072 return 3;
1073 }
1074 if (mDoublePressOnPowerBehavior != MULTI_PRESS_POWER_NOTHING) {
1075 return 2;
1076 }
1077 return 1;
1078 }
1079
1080 private void powerLongPress() {
1081 final int behavior = getResolvedLongPressOnPowerBehavior();
1082 switch (behavior) {
1083 case LONG_PRESS_POWER_NOTHING:
1084 break;
1085 case LONG_PRESS_POWER_GLOBAL_ACTIONS:
1086 mPowerKeyHandled = true;
1087 if (!performHapticFeedbackLw(null, HapticFeedbackConstants.LONG_PRESS, false)) {
1088 performAuditoryFeedbackForAccessibilityIfNeed();
1089 }
1090 showGlobalActionsInternal();
1091 break;
1092 case LONG_PRESS_POWER_SHUT_OFF:
1093 case LONG_PRESS_POWER_SHUT_OFF_NO_CONFIRM:
1094 mPowerKeyHandled = true;
1095 performHapticFeedbackLw(null, HapticFeedbackConstants.LONG_PRESS, false);
1096 sendCloseSystemWindows(SYSTEM_DIALOG_REASON_GLOBAL_ACTIONS);
1097 mWindowManagerFuncs.shutdown(behavior == LONG_PRESS_POWER_SHUT_OFF);
1098 break;
1099 }
1100 }
1101
Nick Vaccarob593a812015-05-15 11:23:05 -07001102 private void sleepPress(long eventTime) {
1103 if (mShortPressOnSleepBehavior == SHORT_PRESS_SLEEP_GO_TO_SLEEP_AND_GO_HOME) {
1104 launchHomeFromHotKey(false /* awakenDreams */, true /*respectKeyguard*/);
1105 }
1106 }
1107
1108 private void sleepRelease(long eventTime) {
Filip Gruszczynskia483a1d2015-03-17 19:06:58 +00001109 switch (mShortPressOnSleepBehavior) {
1110 case SHORT_PRESS_SLEEP_GO_TO_SLEEP:
Filip Gruszczynskia483a1d2015-03-17 19:06:58 +00001111 case SHORT_PRESS_SLEEP_GO_TO_SLEEP_AND_GO_HOME:
Nick Vaccarob593a812015-05-15 11:23:05 -07001112 Slog.i(TAG, "sleepRelease() calling goToSleep(GO_TO_SLEEP_REASON_SLEEP_BUTTON)");
1113 mPowerManager.goToSleep(eventTime,
1114 PowerManager.GO_TO_SLEEP_REASON_SLEEP_BUTTON, 0);
Filip Gruszczynskia483a1d2015-03-17 19:06:58 +00001115 break;
1116 }
1117 }
1118
Jeff Brown13f00f02014-10-31 14:45:50 -07001119 private int getResolvedLongPressOnPowerBehavior() {
1120 if (FactoryTest.isLongPressOnPowerOffEnabled()) {
1121 return LONG_PRESS_POWER_SHUT_OFF_NO_CONFIRM;
1122 }
1123 return mLongPressOnPowerBehavior;
1124 }
1125
1126 private boolean hasLongPressOnPowerBehavior() {
1127 return getResolvedLongPressOnPowerBehavior() != LONG_PRESS_POWER_NOTHING;
Jeff Brownd5bb82d2011-10-12 13:57:59 -07001128 }
1129
1130 private void interceptScreenshotChord() {
Christopher Tatee90585f2012-03-05 18:56:25 -08001131 if (mScreenshotChordEnabled
Jeff Brown13f00f02014-10-31 14:45:50 -07001132 && mScreenshotChordVolumeDownKeyTriggered && mScreenshotChordPowerKeyTriggered
1133 && !mScreenshotChordVolumeUpKeyTriggered) {
Jeff Brownd5bb82d2011-10-12 13:57:59 -07001134 final long now = SystemClock.uptimeMillis();
Jeff Brown13f00f02014-10-31 14:45:50 -07001135 if (now <= mScreenshotChordVolumeDownKeyTime + SCREENSHOT_CHORD_DEBOUNCE_DELAY_MILLIS
1136 && now <= mScreenshotChordPowerKeyTime
1137 + SCREENSHOT_CHORD_DEBOUNCE_DELAY_MILLIS) {
1138 mScreenshotChordVolumeDownKeyConsumed = true;
Jeff Brownd5bb82d2011-10-12 13:57:59 -07001139 cancelPendingPowerKeyAction();
1140
Jeff Sharkey2991fa32012-12-05 18:06:43 -08001141 mHandler.postDelayed(mScreenshotRunnable, getScreenshotChordLongPressDelay());
Jeff Brownd5bb82d2011-10-12 13:57:59 -07001142 }
1143 }
1144 }
1145
Winson Chung1cea2f32012-10-08 20:42:01 -07001146 private long getScreenshotChordLongPressDelay() {
Jim Miller5ecd8112013-01-09 18:50:26 -08001147 if (mKeyguardDelegate.isShowing()) {
Winson Chung1cea2f32012-10-08 20:42:01 -07001148 // Double the time it takes to take a screenshot from the keyguard
1149 return (long) (KEYGUARD_SCREENSHOT_CHORD_DELAY_MULTIPLIER *
Justin Kohfeabd2c2014-05-02 10:02:44 -07001150 ViewConfiguration.get(mContext).getDeviceGlobalActionKeyTimeout());
Winson Chung1cea2f32012-10-08 20:42:01 -07001151 }
Justin Kohfeabd2c2014-05-02 10:02:44 -07001152 return ViewConfiguration.get(mContext).getDeviceGlobalActionKeyTimeout();
Winson Chung1cea2f32012-10-08 20:42:01 -07001153 }
1154
Jeff Brownd5bb82d2011-10-12 13:57:59 -07001155 private void cancelPendingScreenshotChordAction() {
Jeff Sharkey2991fa32012-12-05 18:06:43 -08001156 mHandler.removeCallbacks(mScreenshotRunnable);
Jeff Brown4d396052010-10-29 21:50:21 -07001157 }
1158
Jeff Brown13f00f02014-10-31 14:45:50 -07001159 private final Runnable mEndCallLongPress = new Runnable() {
Craig Mautnerf1b67412012-09-19 13:18:29 -07001160 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001161 public void run() {
Jeff Brown13f00f02014-10-31 14:45:50 -07001162 mEndCallKeyHandled = true;
1163 if (!performHapticFeedbackLw(null, HapticFeedbackConstants.LONG_PRESS, false)) {
1164 performAuditoryFeedbackForAccessibilityIfNeed();
Joe Onoratod208e702010-10-08 16:22:43 -04001165 }
Jeff Brown13f00f02014-10-31 14:45:50 -07001166 showGlobalActionsInternal();
Jeff Brownd5bb82d2011-10-12 13:57:59 -07001167 }
1168 };
1169
Jeff Sharkey2991fa32012-12-05 18:06:43 -08001170 private final Runnable mScreenshotRunnable = new Runnable() {
Craig Mautner0bf6ec92012-12-18 08:33:27 -08001171 @Override
Jeff Brownd5bb82d2011-10-12 13:57:59 -07001172 public void run() {
1173 takeScreenshot();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001174 }
1175 };
1176
Alan Viverettee34560b22014-07-10 14:50:06 -07001177 @Override
1178 public void showGlobalActions() {
1179 mHandler.removeMessages(MSG_DISPATCH_SHOW_GLOBAL_ACTIONS);
1180 mHandler.sendEmptyMessage(MSG_DISPATCH_SHOW_GLOBAL_ACTIONS);
1181 }
1182
1183 void showGlobalActionsInternal() {
1184 sendCloseSystemWindows(SYSTEM_DIALOG_REASON_GLOBAL_ACTIONS);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001185 if (mGlobalActions == null) {
Jeff Brown7304c342012-05-11 18:42:42 -07001186 mGlobalActions = new GlobalActions(mContext, mWindowManagerFuncs);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001187 }
Jim Millerab954542014-10-10 18:21:49 -07001188 final boolean keyguardShowing = isKeyguardShowingAndNotOccluded();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001189 mGlobalActions.showDialog(keyguardShowing, isDeviceProvisioned());
1190 if (keyguardShowing) {
1191 // since it took two seconds of long press to bring this up,
1192 // poke the wake lock so they have some time to see the dialog.
Jim Miller25190572013-02-28 17:36:24 -08001193 mPowerManager.userActivity(SystemClock.uptimeMillis(), false);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001194 }
1195 }
1196
1197 boolean isDeviceProvisioned() {
Jeff Brownbf6f6f92012-09-25 15:03:20 -07001198 return Settings.Global.getInt(
1199 mContext.getContentResolver(), Settings.Global.DEVICE_PROVISIONED, 0) != 0;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001200 }
1201
Maurice Lam99c6e072014-04-28 18:24:28 -07001202 boolean isUserSetupComplete() {
1203 return Settings.Secure.getIntForUser(mContext.getContentResolver(),
1204 Settings.Secure.USER_SETUP_COMPLETE, 0, UserHandle.USER_CURRENT) != 0;
1205 }
1206
Jeff Brown13f00f02014-10-31 14:45:50 -07001207 private void handleShortPressOnHome() {
1208 // If there's a dream running then use home to escape the dream
1209 // but don't actually go home.
1210 if (mDreamManagerInternal != null && mDreamManagerInternal.isDreaming()) {
1211 mDreamManagerInternal.stopDream(false /*immediate*/);
1212 return;
1213 }
1214
1215 // Go home!
1216 launchHomeFromHotKey();
1217 }
1218
Tim Kilbourn0e5f1102015-06-05 16:18:09 -07001219 private void handleLongPressOnHome(int deviceId) {
Joe Onorato46b0d682010-11-22 17:37:27 -08001220 if (mLongPressOnHomeBehavior != LONG_PRESS_HOME_NOTHING) {
Jeff Browncaca8812013-05-09 13:34:33 -07001221 mHomeConsumed = true;
Joe Onorato46b0d682010-11-22 17:37:27 -08001222 performHapticFeedbackLw(null, HapticFeedbackConstants.LONG_PRESS, false);
Patrick Dubroyece94522011-02-23 18:35:01 -08001223
Jeff Browncaca8812013-05-09 13:34:33 -07001224 if (mLongPressOnHomeBehavior == LONG_PRESS_HOME_RECENT_SYSTEM_UI) {
1225 toggleRecentApps();
1226 } else if (mLongPressOnHomeBehavior == LONG_PRESS_HOME_ASSIST) {
Tim Kilbourn0e5f1102015-06-05 16:18:09 -07001227 launchAssistAction(null, deviceId);
Jim Millere6ad1a82010-08-20 19:25:39 -07001228 }
1229 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001230 }
Patrick Dubroyece94522011-02-23 18:35:01 -08001231
Jeff Browncaca8812013-05-09 13:34:33 -07001232 private void handleDoubleTapOnHome() {
1233 if (mDoubleTapOnHomeBehavior == DOUBLE_TAP_HOME_RECENT_SYSTEM_UI) {
1234 mHomeConsumed = true;
1235 toggleRecentApps();
1236 }
1237 }
1238
1239 private final Runnable mHomeDoubleTapTimeoutRunnable = new Runnable() {
1240 @Override
1241 public void run() {
1242 if (mHomeDoubleTapPending) {
1243 mHomeDoubleTapPending = false;
Jeff Brown13f00f02014-10-31 14:45:50 -07001244 handleShortPressOnHome();
Jeff Browncaca8812013-05-09 13:34:33 -07001245 }
1246 }
1247 };
1248
Mark Renoufc1256912015-03-11 14:38:23 -04001249 private boolean isRoundWindow() {
Adam Powell01f280d2015-05-18 16:07:42 -07001250 return mContext.getResources().getConfiguration().isScreenRound();
Mark Renoufc1256912015-03-11 14:38:23 -04001251 }
1252
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001253 /** {@inheritDoc} */
Craig Mautner0bf6ec92012-12-18 08:33:27 -08001254 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001255 public void init(Context context, IWindowManager windowManager,
Jeff Brown96307042012-07-27 15:51:34 -07001256 WindowManagerFuncs windowManagerFuncs) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001257 mContext = context;
1258 mWindowManager = windowManager;
Dianne Hackborndf89e652011-10-06 22:35:11 -07001259 mWindowManagerFuncs = windowManagerFuncs;
Craig Mautner8a0da012014-05-31 15:13:37 -07001260 mWindowManagerInternal = LocalServices.getService(WindowManagerInternal.class);
Jeff Brown061ea992015-04-17 19:55:47 -07001261 mActivityManagerInternal = LocalServices.getService(ActivityManagerInternal.class);
Jose Lima9546b202014-07-02 17:21:51 -07001262 mDreamManagerInternal = LocalServices.getService(DreamManagerInternal.class);
Billy Laucbe540f2015-06-25 01:51:44 +01001263 mAppOpsManager = (AppOpsManager) mContext.getSystemService(Context.APP_OPS_SERVICE);
Mark Renoufc1256912015-03-11 14:38:23 -04001264
1265 // Init display burn-in protection
1266 boolean burnInProtectionEnabled = context.getResources().getBoolean(
1267 com.android.internal.R.bool.config_enableBurnInProtection);
1268 // Allow a system property to override this. Used by developer settings.
1269 boolean burnInProtectionDevMode =
1270 SystemProperties.getBoolean("persist.debug.force_burn_in", false);
1271 if (burnInProtectionEnabled || burnInProtectionDevMode) {
1272 final int minHorizontal;
1273 final int maxHorizontal;
1274 final int minVertical;
1275 final int maxVertical;
1276 final int maxRadius;
1277 if (burnInProtectionDevMode) {
1278 minHorizontal = -8;
1279 maxHorizontal = 8;
1280 minVertical = -8;
1281 maxVertical = -4;
1282 maxRadius = (isRoundWindow()) ? 6 : -1;
1283 } else {
1284 Resources resources = context.getResources();
1285 minHorizontal = resources.getInteger(
1286 com.android.internal.R.integer.config_burnInProtectionMinHorizontalOffset);
1287 maxHorizontal = resources.getInteger(
1288 com.android.internal.R.integer.config_burnInProtectionMaxHorizontalOffset);
1289 minVertical = resources.getInteger(
1290 com.android.internal.R.integer.config_burnInProtectionMinVerticalOffset);
1291 maxVertical = resources.getInteger(
1292 com.android.internal.R.integer.config_burnInProtectionMaxVerticalOffset);
1293 maxRadius = resources.getInteger(
1294 com.android.internal.R.integer.config_burnInProtectionMaxRadius);
1295 }
1296 mBurnInProtectionHelper = new BurnInProtectionHelper(
1297 context, minHorizontal, maxHorizontal, minVertical, maxVertical, maxRadius);
Filip Gruszczynskicfb31852015-02-25 21:47:12 +00001298 }
Craig Mautner8a0da012014-05-31 15:13:37 -07001299
Jeff Brown70825162012-03-28 17:27:48 -07001300 mHandler = new PolicyHandler();
Jeff Browna20dda42014-05-27 20:57:24 -07001301 mWakeGestureListener = new MyWakeGestureListener(mContext, mHandler);
Craig Mautnereee29c42013-01-17 14:44:34 -08001302 mOrientationListener = new MyOrientationListener(mContext, mHandler);
Jeff Brownc0347aa2011-09-23 17:26:09 -07001303 try {
1304 mOrientationListener.setCurrentRotation(windowManager.getRotation());
1305 } catch (RemoteException ex) { }
Christopher Tate5e08af02012-09-21 17:17:22 -07001306 mSettingsObserver = new SettingsObserver(mHandler);
1307 mSettingsObserver.observe();
Svetoslav683914b2015-01-15 14:22:26 -08001308 mShortcutManager = new ShortcutManager(context);
Daniel Sandler6396c722013-04-16 20:19:09 -04001309 mUiMode = context.getResources().getInteger(
1310 com.android.internal.R.integer.config_defaultUiModeType);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001311 mHomeIntent = new Intent(Intent.ACTION_MAIN, null);
1312 mHomeIntent.addCategory(Intent.CATEGORY_HOME);
1313 mHomeIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK
1314 | Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED);
Dianne Hackborn39c2d712009-09-22 11:41:31 -07001315 mCarDockIntent = new Intent(Intent.ACTION_MAIN, null);
1316 mCarDockIntent.addCategory(Intent.CATEGORY_CAR_DOCK);
1317 mCarDockIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK
1318 | Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED);
1319 mDeskDockIntent = new Intent(Intent.ACTION_MAIN, null);
1320 mDeskDockIntent.addCategory(Intent.CATEGORY_DESK_DOCK);
1321 mDeskDockIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK
1322 | Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED);
Jim Millere6ad1a82010-08-20 19:25:39 -07001323
Jeff Brown96307042012-07-27 15:51:34 -07001324 mPowerManager = (PowerManager)context.getSystemService(Context.POWER_SERVICE);
1325 mBroadcastWakeLock = mPowerManager.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK,
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001326 "PhoneWindowManager.mBroadcastWakeLock");
Jeff Brown13f00f02014-10-31 14:45:50 -07001327 mPowerKeyWakeLock = mPowerManager.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK,
1328 "PhoneWindowManager.mPowerKeyWakeLock");
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001329 mEnableShiftMenuBugReports = "1".equals(SystemProperties.get("ro.debuggable"));
Jeff Brownbcdfc622014-03-06 19:13:04 -08001330 mSupportAutoRotation = mContext.getResources().getBoolean(
1331 com.android.internal.R.bool.config_supportAutoRotation);
Dianne Hackborn2862fff2009-09-15 22:56:29 -07001332 mLidOpenRotation = readRotation(
Mike Lockwood2d1efbd2009-09-16 12:15:53 -04001333 com.android.internal.R.integer.config_lidOpenRotation);
1334 mCarDockRotation = readRotation(
1335 com.android.internal.R.integer.config_carDockRotation);
1336 mDeskDockRotation = readRotation(
1337 com.android.internal.R.integer.config_deskDockRotation);
Jeff Brownc82c89ed2013-04-17 17:18:15 -07001338 mUndockedHdmiRotation = readRotation(
1339 com.android.internal.R.integer.config_undockedHdmiRotation);
Mike Lockwoode9867d22009-09-20 01:59:02 -04001340 mCarDockEnablesAccelerometer = mContext.getResources().getBoolean(
1341 com.android.internal.R.bool.config_carDockEnablesAccelerometer);
1342 mDeskDockEnablesAccelerometer = mContext.getResources().getBoolean(
1343 com.android.internal.R.bool.config_deskDockEnablesAccelerometer);
Dianne Hackborn2862fff2009-09-15 22:56:29 -07001344 mLidKeyboardAccessibility = mContext.getResources().getInteger(
1345 com.android.internal.R.integer.config_lidKeyboardAccessibility);
1346 mLidNavigationAccessibility = mContext.getResources().getInteger(
1347 com.android.internal.R.integer.config_lidNavigationAccessibility);
Jeff Brownc458ce92012-04-30 14:58:40 -07001348 mLidControlsSleep = mContext.getResources().getBoolean(
1349 com.android.internal.R.bool.config_lidControlsSleep);
Daniel Sandlerdd73ee42013-10-11 22:19:59 -04001350 mTranslucentDecorEnabled = mContext.getResources().getBoolean(
1351 com.android.internal.R.bool.config_enableTranslucentDecor);
Bryce Lee584a4452014-10-21 15:55:55 -07001352
1353 mAllowTheaterModeWakeFromKey = mContext.getResources().getBoolean(
1354 com.android.internal.R.bool.config_allowTheaterModeWakeFromKey);
1355 mAllowTheaterModeWakeFromPowerKey = mAllowTheaterModeWakeFromKey
1356 || mContext.getResources().getBoolean(
1357 com.android.internal.R.bool.config_allowTheaterModeWakeFromPowerKey);
1358 mAllowTheaterModeWakeFromMotion = mContext.getResources().getBoolean(
1359 com.android.internal.R.bool.config_allowTheaterModeWakeFromMotion);
Bryce Lee812d7022014-11-10 13:33:28 -08001360 mAllowTheaterModeWakeFromMotionWhenNotDreaming = mContext.getResources().getBoolean(
1361 com.android.internal.R.bool.config_allowTheaterModeWakeFromMotionWhenNotDreaming);
Bryce Lee584a4452014-10-21 15:55:55 -07001362 mAllowTheaterModeWakeFromCameraLens = mContext.getResources().getBoolean(
1363 com.android.internal.R.bool.config_allowTheaterModeWakeFromCameraLens);
1364 mAllowTheaterModeWakeFromLidSwitch = mContext.getResources().getBoolean(
1365 com.android.internal.R.bool.config_allowTheaterModeWakeFromLidSwitch);
1366 mAllowTheaterModeWakeFromWakeGesture = mContext.getResources().getBoolean(
1367 com.android.internal.R.bool.config_allowTheaterModeWakeFromGesture);
1368
Bryce Lee55e846d2014-11-04 12:43:44 -08001369 mGoToSleepOnButtonPressTheaterMode = mContext.getResources().getBoolean(
1370 com.android.internal.R.bool.config_goToSleepOnButtonPressTheaterMode);
1371
Bryce Leed3b28402015-03-09 15:49:13 +00001372 mSupportLongPressPowerWhenNonInteractive = mContext.getResources().getBoolean(
1373 com.android.internal.R.bool.config_supportLongPressPowerWhenNonInteractive);
1374
Jeff Brown13f00f02014-10-31 14:45:50 -07001375 mShortPressOnPowerBehavior = mContext.getResources().getInteger(
1376 com.android.internal.R.integer.config_shortPressOnPowerBehavior);
1377 mLongPressOnPowerBehavior = mContext.getResources().getInteger(
1378 com.android.internal.R.integer.config_longPressOnPowerBehavior);
1379 mDoublePressOnPowerBehavior = mContext.getResources().getInteger(
1380 com.android.internal.R.integer.config_doublePressOnPowerBehavior);
1381 mTriplePressOnPowerBehavior = mContext.getResources().getInteger(
1382 com.android.internal.R.integer.config_triplePressOnPowerBehavior);
Filip Gruszczynskia483a1d2015-03-17 19:06:58 +00001383 mShortPressOnSleepBehavior = mContext.getResources().getInteger(
1384 com.android.internal.R.integer.config_shortPressOnSleepBehavior);
Jeff Brown13f00f02014-10-31 14:45:50 -07001385
John Spurlock61560172015-02-06 19:46:04 -05001386 mUseTvRouting = AudioSystem.getPlatformType(mContext) == AudioSystem.PLATFORM_TELEVISION;
RoboErik001c59c2015-01-26 15:53:51 -08001387
Jeff Brownf71343d2013-05-31 17:59:11 -07001388 readConfigurationDependentBehaviors();
Jeff Browncaca8812013-05-09 13:34:33 -07001389
Svetoslav8e3feb12014-02-24 13:46:47 -08001390 mAccessibilityManager = (AccessibilityManager) context.getSystemService(
1391 Context.ACCESSIBILITY_SERVICE);
1392
Mike Lockwood1753f7f2009-08-24 14:49:07 -07001393 // register for dock events
Dianne Hackborn78968392010-03-04 20:47:56 -08001394 IntentFilter filter = new IntentFilter();
1395 filter.addAction(UiModeManager.ACTION_ENTER_CAR_MODE);
1396 filter.addAction(UiModeManager.ACTION_EXIT_CAR_MODE);
1397 filter.addAction(UiModeManager.ACTION_ENTER_DESK_MODE);
1398 filter.addAction(UiModeManager.ACTION_EXIT_DESK_MODE);
Dianne Hackborn867ab6472010-04-29 13:28:56 -07001399 filter.addAction(Intent.ACTION_DOCK_EVENT);
1400 Intent intent = context.registerReceiver(mDockReceiver, filter);
1401 if (intent != null) {
1402 // Retrieve current sticky dock event broadcast.
1403 mDockMode = intent.getIntExtra(Intent.EXTRA_DOCK_STATE,
1404 Intent.EXTRA_DOCK_STATE_UNDOCKED);
1405 }
Daniel Sandler7e37df52011-11-16 22:08:23 -08001406
Jeff Brown6aaf2952012-10-05 16:01:08 -07001407 // register for dream-related broadcasts
1408 filter = new IntentFilter();
1409 filter.addAction(Intent.ACTION_DREAMING_STARTED);
1410 filter.addAction(Intent.ACTION_DREAMING_STOPPED);
1411 context.registerReceiver(mDreamReceiver, filter);
1412
Christopher Tate5e08af02012-09-21 17:17:22 -07001413 // register for multiuser-relevant broadcasts
1414 filter = new IntentFilter(Intent.ACTION_USER_SWITCHED);
1415 context.registerReceiver(mMultiuserReceiver, filter);
1416
John Spurlock57306e62013-04-22 09:48:49 -04001417 // monitor for system gestures
Craig Mautner037aa8d2013-06-07 10:35:44 -07001418 mSystemGestures = new SystemGesturesPointerEventListener(context,
1419 new SystemGesturesPointerEventListener.Callbacks() {
John Spurlock57306e62013-04-22 09:48:49 -04001420 @Override
1421 public void onSwipeFromTop() {
John Spurlock04db1762013-05-13 12:46:41 -04001422 if (mStatusBar != null) {
John Spurlocke1f366f2013-08-05 12:22:40 -04001423 requestTransientBars(mStatusBar);
John Spurlock04db1762013-05-13 12:46:41 -04001424 }
John Spurlockad3e6cb2013-04-30 08:47:43 -04001425 }
1426 @Override
1427 public void onSwipeFromBottom() {
John Spurlock04db1762013-05-13 12:46:41 -04001428 if (mNavigationBar != null && mNavigationBarOnBottom) {
John Spurlocke1f366f2013-08-05 12:22:40 -04001429 requestTransientBars(mNavigationBar);
John Spurlockad3e6cb2013-04-30 08:47:43 -04001430 }
1431 }
1432 @Override
1433 public void onSwipeFromRight() {
John Spurlock04db1762013-05-13 12:46:41 -04001434 if (mNavigationBar != null && !mNavigationBarOnBottom) {
John Spurlocke1f366f2013-08-05 12:22:40 -04001435 requestTransientBars(mNavigationBar);
John Spurlockad3e6cb2013-04-30 08:47:43 -04001436 }
1437 }
1438 @Override
1439 public void onDebug() {
John Spurlockd67ec252013-09-05 11:31:54 -04001440 // no-op
John Spurlockad3e6cb2013-04-30 08:47:43 -04001441 }
Adrian Roos3595be42015-03-05 16:31:15 +01001442 @Override
1443 public void onDown() {
1444 mOrientationListener.onTouchStart();
1445 }
1446 @Override
1447 public void onUpOrCancel() {
1448 mOrientationListener.onTouchEnd();
1449 }
John Spurlockad3e6cb2013-04-30 08:47:43 -04001450 });
John Spurlockf1a36642013-10-12 17:50:42 -04001451 mImmersiveModeConfirmation = new ImmersiveModeConfirmation(mContext);
Craig Mautner037aa8d2013-06-07 10:35:44 -07001452 mWindowManagerFuncs.registerPointerEventListener(mSystemGestures);
John Spurlock32beb2c2013-03-11 10:16:47 -04001453
Jeff Brownc2346132012-04-13 01:55:38 -07001454 mVibrator = (Vibrator)context.getSystemService(Context.VIBRATOR_SERVICE);
Dianne Hackbornb1a79802009-09-29 15:18:31 -07001455 mLongPressVibePattern = getLongIntArray(mContext.getResources(),
1456 com.android.internal.R.array.config_longPressVibePattern);
1457 mVirtualKeyVibePattern = getLongIntArray(mContext.getResources(),
1458 com.android.internal.R.array.config_virtualKeyVibePattern);
Amith Yamasanic33cb712010-02-10 15:21:49 -08001459 mKeyboardTapVibePattern = getLongIntArray(mContext.getResources(),
1460 com.android.internal.R.array.config_keyboardTapVibePattern);
Fabrice Di Meglioeeff63a2013-08-05 12:07:24 -07001461 mClockTickVibePattern = getLongIntArray(mContext.getResources(),
1462 com.android.internal.R.array.config_clockTickVibePattern);
Fabrice Di Megliobd9152f2013-10-01 11:21:31 -07001463 mCalendarDateVibePattern = getLongIntArray(mContext.getResources(),
1464 com.android.internal.R.array.config_calendarDateVibePattern);
Dianne Hackbornb1a79802009-09-29 15:18:31 -07001465 mSafeModeDisabledVibePattern = getLongIntArray(mContext.getResources(),
1466 com.android.internal.R.array.config_safeModeDisabledVibePattern);
1467 mSafeModeEnabledVibePattern = getLongIntArray(mContext.getResources(),
1468 com.android.internal.R.array.config_safeModeEnabledVibePattern);
Mady Mellore8608912015-06-05 09:02:55 -07001469 mContextClickVibePattern = getLongIntArray(mContext.getResources(),
1470 com.android.internal.R.array.config_contextClickVibePattern);
Daniel Sandler40427442010-07-16 11:44:52 -04001471
Christopher Tatee90585f2012-03-05 18:56:25 -08001472 mScreenshotChordEnabled = mContext.getResources().getBoolean(
1473 com.android.internal.R.bool.config_enableScreenshotChord);
1474
Justin Kohd378ad72013-04-01 12:18:26 -07001475 mGlobalKeyManager = new GlobalKeyManager(mContext);
1476
Joe Onoratoea495d42011-04-06 11:41:11 -07001477 // Controls rotation and the like.
1478 initializeHdmiState();
Dianne Hackborn40011092011-09-22 13:37:48 -07001479
1480 // Match current screen state.
Craig Mautnera631d492014-08-05 15:16:01 -07001481 if (!mPowerManager.isInteractive()) {
Jeff Brown416c49c2015-05-26 19:50:18 -07001482 startedGoingToSleep(WindowManagerPolicy.OFF_BECAUSE_OF_USER);
1483 finishedGoingToSleep(WindowManagerPolicy.OFF_BECAUSE_OF_USER);
Dianne Hackborn40011092011-09-22 13:37:48 -07001484 }
Jorim Jaggi24bec7c2015-02-04 12:40:14 +01001485
1486 mWindowManagerInternal.registerAppTransitionListener(
1487 mStatusBarController.getAppTransitionListener());
Mike Lockwood1753f7f2009-08-24 14:49:07 -07001488 }
1489
Jeff Brownf71343d2013-05-31 17:59:11 -07001490 /**
1491 * Read values from config.xml that may be overridden depending on
1492 * the configuration of the device.
1493 * eg. Disable long press on home goes to recents on sw600dp.
1494 */
1495 private void readConfigurationDependentBehaviors() {
1496 mLongPressOnHomeBehavior = mContext.getResources().getInteger(
1497 com.android.internal.R.integer.config_longPressOnHomeBehavior);
1498 if (mLongPressOnHomeBehavior < LONG_PRESS_HOME_NOTHING ||
1499 mLongPressOnHomeBehavior > LONG_PRESS_HOME_ASSIST) {
1500 mLongPressOnHomeBehavior = LONG_PRESS_HOME_NOTHING;
1501 }
1502
1503 mDoubleTapOnHomeBehavior = mContext.getResources().getInteger(
1504 com.android.internal.R.integer.config_doubleTapOnHomeBehavior);
1505 if (mDoubleTapOnHomeBehavior < DOUBLE_TAP_HOME_NOTHING ||
1506 mDoubleTapOnHomeBehavior > DOUBLE_TAP_HOME_RECENT_SYSTEM_UI) {
1507 mDoubleTapOnHomeBehavior = LONG_PRESS_HOME_NOTHING;
1508 }
1509 }
1510
Craig Mautner0bf6ec92012-12-18 08:33:27 -08001511 @Override
Dianne Hackborndde331c2012-08-03 14:01:57 -07001512 public void setInitialDisplaySize(Display display, int width, int height, int density) {
Jeff Brownef981a42013-08-07 14:13:37 -07001513 // This method might be called before the policy has been fully initialized
1514 // or for other displays we don't care about.
1515 if (mContext == null || display.getDisplayId() != Display.DEFAULT_DISPLAY) {
1516 return;
Dianne Hackbornc652de82013-02-15 16:32:56 -08001517 }
Dianne Hackbornf87d1962012-04-04 12:48:24 -07001518 mDisplay = display;
1519
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001520 final Resources res = mContext.getResources();
Dianne Hackbornf87d1962012-04-04 12:48:24 -07001521 int shortSize, longSize;
Dianne Hackborn9d132642011-04-21 17:26:39 -07001522 if (width > height) {
Dianne Hackborn81e56d52011-05-26 00:55:58 -07001523 shortSize = height;
Dianne Hackbornf87d1962012-04-04 12:48:24 -07001524 longSize = width;
Dianne Hackborn9d132642011-04-21 17:26:39 -07001525 mLandscapeRotation = Surface.ROTATION_0;
1526 mSeascapeRotation = Surface.ROTATION_180;
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001527 if (res.getBoolean(com.android.internal.R.bool.config_reverseDefaultRotation)) {
Dianne Hackborn9d132642011-04-21 17:26:39 -07001528 mPortraitRotation = Surface.ROTATION_90;
1529 mUpsideDownRotation = Surface.ROTATION_270;
1530 } else {
1531 mPortraitRotation = Surface.ROTATION_270;
1532 mUpsideDownRotation = Surface.ROTATION_90;
1533 }
1534 } else {
Dianne Hackborn81e56d52011-05-26 00:55:58 -07001535 shortSize = width;
Dianne Hackbornf87d1962012-04-04 12:48:24 -07001536 longSize = height;
Dianne Hackborn9d132642011-04-21 17:26:39 -07001537 mPortraitRotation = Surface.ROTATION_0;
1538 mUpsideDownRotation = Surface.ROTATION_180;
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001539 if (res.getBoolean(com.android.internal.R.bool.config_reverseDefaultRotation)) {
Dianne Hackborn9d132642011-04-21 17:26:39 -07001540 mLandscapeRotation = Surface.ROTATION_270;
1541 mSeascapeRotation = Surface.ROTATION_90;
1542 } else {
1543 mLandscapeRotation = Surface.ROTATION_90;
1544 mSeascapeRotation = Surface.ROTATION_270;
1545 }
1546 }
Dianne Hackborn81e56d52011-05-26 00:55:58 -07001547
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001548 mStatusBarHeight =
1549 res.getDimensionPixelSize(com.android.internal.R.dimen.status_bar_height);
Dianne Hackbornf87d1962012-04-04 12:48:24 -07001550
Daniel Sandler9f65c4c2012-04-26 01:35:35 -04001551 // Height of the navigation bar when presented horizontally at bottom
1552 mNavigationBarHeightForRotation[mPortraitRotation] =
1553 mNavigationBarHeightForRotation[mUpsideDownRotation] =
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001554 res.getDimensionPixelSize(com.android.internal.R.dimen.navigation_bar_height);
Daniel Sandler9f65c4c2012-04-26 01:35:35 -04001555 mNavigationBarHeightForRotation[mLandscapeRotation] =
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001556 mNavigationBarHeightForRotation[mSeascapeRotation] = res.getDimensionPixelSize(
1557 com.android.internal.R.dimen.navigation_bar_height_landscape);
Daniel Sandler9f65c4c2012-04-26 01:35:35 -04001558
1559 // Width of the navigation bar when presented vertically along one side
1560 mNavigationBarWidthForRotation[mPortraitRotation] =
1561 mNavigationBarWidthForRotation[mUpsideDownRotation] =
1562 mNavigationBarWidthForRotation[mLandscapeRotation] =
1563 mNavigationBarWidthForRotation[mSeascapeRotation] =
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001564 res.getDimensionPixelSize(com.android.internal.R.dimen.navigation_bar_width);
Daniel Sandler4a066c52012-04-20 14:49:13 -04001565
1566 // SystemUI (status bar) layout policy
Dianne Hackborndde331c2012-08-03 14:01:57 -07001567 int shortSizeDp = shortSize * DisplayMetrics.DENSITY_DEFAULT / density;
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001568 int longSizeDp = longSize * DisplayMetrics.DENSITY_DEFAULT / density;
Daniel Sandler4a066c52012-04-20 14:49:13 -04001569
Devin Kimd7b12b42014-05-05 14:34:58 -07001570 // Allow the navigation bar to move on non-square small devices (phones).
1571 mNavigationBarCanMove = width != height && shortSizeDp < 600;
Daniel Sandler36412a72011-08-04 09:35:13 -04001572
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001573 mHasNavigationBar = res.getBoolean(com.android.internal.R.bool.config_showNavigationBar);
John Spurlock80f00c12013-06-13 11:10:51 -04001574 // Allow a system property to override this. Used by the emulator.
1575 // See also hasNavigationBar().
1576 String navBarOverride = SystemProperties.get("qemu.hw.mainkeys");
1577 if ("1".equals(navBarOverride)) {
Dianne Hackbornf87d1962012-04-04 12:48:24 -07001578 mHasNavigationBar = false;
John Spurlock80f00c12013-06-13 11:10:51 -04001579 } else if ("0".equals(navBarOverride)) {
1580 mHasNavigationBar = true;
Daniel Sandler0c4ccff2011-10-19 16:39:14 -04001581 }
1582
Jeff Brown27f1d672012-10-17 18:32:34 -07001583 // For demo purposes, allow the rotation of the HDMI display to be controlled.
1584 // By default, HDMI locks rotation to landscape.
Erik Gilling9a41ef82011-09-26 19:21:03 -07001585 if ("portrait".equals(SystemProperties.get("persist.demo.hdmirotation"))) {
Jeff Brownc82c89ed2013-04-17 17:18:15 -07001586 mDemoHdmiRotation = mPortraitRotation;
Erik Gilling9a41ef82011-09-26 19:21:03 -07001587 } else {
Jeff Brownc82c89ed2013-04-17 17:18:15 -07001588 mDemoHdmiRotation = mLandscapeRotation;
Erik Gilling9a41ef82011-09-26 19:21:03 -07001589 }
Jeff Brownc82c89ed2013-04-17 17:18:15 -07001590 mDemoHdmiRotationLock = SystemProperties.getBoolean("persist.demo.hdmirotationlock", false);
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001591
Chong Zhangae6119ff2014-11-11 18:54:39 -08001592 // For demo purposes, allow the rotation of the remote display to be controlled.
1593 // By default, remote display locks rotation to landscape.
1594 if ("portrait".equals(SystemProperties.get("persist.demo.remoterotation"))) {
1595 mDemoRotation = mPortraitRotation;
1596 } else {
1597 mDemoRotation = mLandscapeRotation;
1598 }
1599 mDemoRotationLock = SystemProperties.getBoolean(
1600 "persist.demo.rotationlock", false);
1601
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001602 // Only force the default orientation if the screen is xlarge, at least 960dp x 720dp, per
1603 // http://developer.android.com/guide/practices/screens_support.html#range
1604 mForceDefaultOrientation = longSizeDp >= 960 && shortSizeDp >= 720 &&
1605 res.getBoolean(com.android.internal.R.bool.config_forceDefaultOrientation) &&
1606 // For debug purposes the next line turns this feature off with:
1607 // $ adb shell setprop config.override_forced_orient true
1608 // $ adb shell wm size reset
1609 !"true".equals(SystemProperties.get("config.override_forced_orient"));
1610 }
1611
Alan Viverette5a0f4ec2013-10-07 15:10:29 -07001612 /**
1613 * @return whether the navigation bar can be hidden, e.g. the device has a
1614 * navigation bar and touch exploration is not enabled
1615 */
1616 private boolean canHideNavigationBar() {
Svetoslav8e3feb12014-02-24 13:46:47 -08001617 return mHasNavigationBar
1618 && !mAccessibilityManager.isTouchExplorationEnabled();
Alan Viverette5a0f4ec2013-10-07 15:10:29 -07001619 }
1620
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001621 @Override
1622 public boolean isDefaultOrientationForced() {
1623 return mForceDefaultOrientation;
Dianne Hackborn9d132642011-04-21 17:26:39 -07001624 }
1625
Dianne Hackbornc652de82013-02-15 16:32:56 -08001626 @Override
1627 public void setDisplayOverscan(Display display, int left, int top, int right, int bottom) {
1628 if (display.getDisplayId() == Display.DEFAULT_DISPLAY) {
1629 mOverscanLeft = left;
1630 mOverscanTop = top;
1631 mOverscanRight = right;
1632 mOverscanBottom = bottom;
1633 }
1634 }
1635
Dianne Hackbornc777e072010-02-12 13:07:59 -08001636 public void updateSettings() {
1637 ContentResolver resolver = mContext.getContentResolver();
1638 boolean updateRotation = false;
Dianne Hackbornc777e072010-02-12 13:07:59 -08001639 synchronized (mLock) {
Christopher Tate5e08af02012-09-21 17:17:22 -07001640 mEndcallBehavior = Settings.System.getIntForUser(resolver,
David Brownbaf8d092010-03-08 21:52:59 -08001641 Settings.System.END_BUTTON_BEHAVIOR,
Christopher Tate5e08af02012-09-21 17:17:22 -07001642 Settings.System.END_BUTTON_BEHAVIOR_DEFAULT,
1643 UserHandle.USER_CURRENT);
1644 mIncallPowerBehavior = Settings.Secure.getIntForUser(resolver,
David Brownbaf8d092010-03-08 21:52:59 -08001645 Settings.Secure.INCALL_POWER_BUTTON_BEHAVIOR,
Christopher Tate5e08af02012-09-21 17:17:22 -07001646 Settings.Secure.INCALL_POWER_BUTTON_BEHAVIOR_DEFAULT,
1647 UserHandle.USER_CURRENT);
Daniel Sandlerb73617d2010-08-17 00:41:00 -04001648
Jeff Browna20dda42014-05-27 20:57:24 -07001649 // Configure wake gesture.
1650 boolean wakeGestureEnabledSetting = Settings.Secure.getIntForUser(resolver,
1651 Settings.Secure.WAKE_GESTURE_ENABLED, 0,
1652 UserHandle.USER_CURRENT) != 0;
1653 if (mWakeGestureEnabledSetting != wakeGestureEnabledSetting) {
1654 mWakeGestureEnabledSetting = wakeGestureEnabledSetting;
1655 updateWakeGestureListenerLp();
1656 }
1657
Jeff Brown207673cd2012-06-05 17:47:11 -07001658 // Configure rotation lock.
Christopher Tate5e08af02012-09-21 17:17:22 -07001659 int userRotation = Settings.System.getIntForUser(resolver,
1660 Settings.System.USER_ROTATION, Surface.ROTATION_0,
1661 UserHandle.USER_CURRENT);
Jeff Brown207673cd2012-06-05 17:47:11 -07001662 if (mUserRotation != userRotation) {
1663 mUserRotation = userRotation;
1664 updateRotation = true;
1665 }
Christopher Tate5e08af02012-09-21 17:17:22 -07001666 int userRotationMode = Settings.System.getIntForUser(resolver,
1667 Settings.System.ACCELEROMETER_ROTATION, 0, UserHandle.USER_CURRENT) != 0 ?
Jeff Brown207673cd2012-06-05 17:47:11 -07001668 WindowManagerPolicy.USER_ROTATION_FREE :
1669 WindowManagerPolicy.USER_ROTATION_LOCKED;
1670 if (mUserRotationMode != userRotationMode) {
1671 mUserRotationMode = userRotationMode;
1672 updateRotation = true;
Dianne Hackbornc777e072010-02-12 13:07:59 -08001673 updateOrientationListenerLp();
1674 }
Daniel Sandlerb73617d2010-08-17 00:41:00 -04001675
Dianne Hackbornc777e072010-02-12 13:07:59 -08001676 if (mSystemReady) {
Christopher Tate5e08af02012-09-21 17:17:22 -07001677 int pointerLocation = Settings.System.getIntForUser(resolver,
1678 Settings.System.POINTER_LOCATION, 0, UserHandle.USER_CURRENT);
Dianne Hackbornc777e072010-02-12 13:07:59 -08001679 if (mPointerLocationMode != pointerLocation) {
1680 mPointerLocationMode = pointerLocation;
Jeff Brown70825162012-03-28 17:27:48 -07001681 mHandler.sendEmptyMessage(pointerLocation != 0 ?
1682 MSG_ENABLE_POINTER_LOCATION : MSG_DISABLE_POINTER_LOCATION);
Dianne Hackbornc777e072010-02-12 13:07:59 -08001683 }
1684 }
1685 // use screen off timeout setting as the timeout for the lockscreen
Christopher Tate5e08af02012-09-21 17:17:22 -07001686 mLockScreenTimeout = Settings.System.getIntForUser(resolver,
1687 Settings.System.SCREEN_OFF_TIMEOUT, 0, UserHandle.USER_CURRENT);
1688 String imId = Settings.Secure.getStringForUser(resolver,
1689 Settings.Secure.DEFAULT_INPUT_METHOD, UserHandle.USER_CURRENT);
Dianne Hackbornc777e072010-02-12 13:07:59 -08001690 boolean hasSoftInput = imId != null && imId.length() > 0;
1691 if (mHasSoftInput != hasSoftInput) {
1692 mHasSoftInput = hasSoftInput;
1693 updateRotation = true;
1694 }
John Spurlockf1a36642013-10-12 17:50:42 -04001695 if (mImmersiveModeConfirmation != null) {
John Spurlock4355a532014-02-19 09:49:25 -05001696 mImmersiveModeConfirmation.loadSetting(mCurrentUserId);
John Spurlockd67ec252013-09-05 11:31:54 -04001697 }
tiger_huangcc6366d2015-06-29 17:17:30 +08001698 }
1699 synchronized (mWindowManagerFuncs.getWindowManagerLock()) {
John Spurlockc6d1c602014-01-17 15:22:06 -05001700 PolicyControl.reloadFromSetting(mContext);
Dianne Hackbornc777e072010-02-12 13:07:59 -08001701 }
1702 if (updateRotation) {
Jeff Brown01a98dd2011-09-20 15:08:29 -07001703 updateRotation(true);
Dianne Hackbornc777e072010-02-12 13:07:59 -08001704 }
Jeff Brown70825162012-03-28 17:27:48 -07001705 }
1706
Jeff Browna20dda42014-05-27 20:57:24 -07001707 private void updateWakeGestureListenerLp() {
1708 if (shouldEnableWakeGestureLp()) {
1709 mWakeGestureListener.requestWakeUpTrigger();
1710 } else {
1711 mWakeGestureListener.cancelWakeUpTrigger();
1712 }
1713 }
1714
1715 private boolean shouldEnableWakeGestureLp() {
Jeff Brown3ee549c2014-09-22 20:14:39 -07001716 return mWakeGestureEnabledSetting && !mAwake
Jeff Browna20dda42014-05-27 20:57:24 -07001717 && (!mLidControlsSleep || mLidState != LID_CLOSED)
1718 && mWakeGestureListener.isSupported();
1719 }
1720
Jeff Brown70825162012-03-28 17:27:48 -07001721 private void enablePointerLocation() {
1722 if (mPointerLocationView == null) {
1723 mPointerLocationView = new PointerLocationView(mContext);
1724 mPointerLocationView.setPrintCoords(false);
Dianne Hackbornc777e072010-02-12 13:07:59 -08001725 WindowManager.LayoutParams lp = new WindowManager.LayoutParams(
1726 WindowManager.LayoutParams.MATCH_PARENT,
1727 WindowManager.LayoutParams.MATCH_PARENT);
Jeff Brown3b2b3542010-10-15 00:54:27 -07001728 lp.type = WindowManager.LayoutParams.TYPE_SECURE_SYSTEM_OVERLAY;
Jeff Brownbfcb60a2011-09-08 18:51:14 -07001729 lp.flags = WindowManager.LayoutParams.FLAG_FULLSCREEN
1730 | WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE
1731 | WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE
1732 | WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN;
Jeff Brown90fc9052012-10-01 14:44:24 -07001733 if (ActivityManager.isHighEndGfx()) {
1734 lp.flags |= WindowManager.LayoutParams.FLAG_HARDWARE_ACCELERATED;
1735 lp.privateFlags |=
1736 WindowManager.LayoutParams.PRIVATE_FLAG_FORCE_HARDWARE_ACCELERATED;
1737 }
Dianne Hackbornc777e072010-02-12 13:07:59 -08001738 lp.format = PixelFormat.TRANSLUCENT;
1739 lp.setTitle("PointerLocation");
Dianne Hackborn5fd21692011-06-07 14:09:47 -07001740 WindowManager wm = (WindowManager)
Dianne Hackbornc777e072010-02-12 13:07:59 -08001741 mContext.getSystemService(Context.WINDOW_SERVICE);
Jeff Browncc4f7db2011-08-30 20:34:48 -07001742 lp.inputFeatures |= WindowManager.LayoutParams.INPUT_FEATURE_NO_INPUT_CHANNEL;
Jeff Brown70825162012-03-28 17:27:48 -07001743 wm.addView(mPointerLocationView, lp);
Michael Wrightc9c487e2013-11-07 18:55:09 -08001744 mWindowManagerFuncs.registerPointerEventListener(mPointerLocationView);
Dianne Hackbornc777e072010-02-12 13:07:59 -08001745 }
Dianne Hackbornc777e072010-02-12 13:07:59 -08001746 }
Jeff Brown70825162012-03-28 17:27:48 -07001747
1748 private void disablePointerLocation() {
Jeff Brown70825162012-03-28 17:27:48 -07001749 if (mPointerLocationView != null) {
Michael Wrightc9c487e2013-11-07 18:55:09 -08001750 mWindowManagerFuncs.unregisterPointerEventListener(mPointerLocationView);
1751 WindowManager wm = (WindowManager) mContext.getSystemService(Context.WINDOW_SERVICE);
Jeff Brown70825162012-03-28 17:27:48 -07001752 wm.removeView(mPointerLocationView);
1753 mPointerLocationView = null;
1754 }
1755 }
1756
Mike Lockwood2d1efbd2009-09-16 12:15:53 -04001757 private int readRotation(int resID) {
Mike Lockwood1753f7f2009-08-24 14:49:07 -07001758 try {
1759 int rotation = mContext.getResources().getInteger(resID);
1760 switch (rotation) {
1761 case 0:
1762 return Surface.ROTATION_0;
1763 case 90:
1764 return Surface.ROTATION_90;
1765 case 180:
1766 return Surface.ROTATION_180;
1767 case 270:
1768 return Surface.ROTATION_270;
Mike Lockwood1753f7f2009-08-24 14:49:07 -07001769 }
1770 } catch (Resources.NotFoundException e) {
Mike Lockwood2d1efbd2009-09-16 12:15:53 -04001771 // fall through
Mike Lockwood1753f7f2009-08-24 14:49:07 -07001772 }
Mike Lockwood2d1efbd2009-09-16 12:15:53 -04001773 return -1;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001774 }
1775
1776 /** {@inheritDoc} */
Craig Mautner88400d32012-09-30 12:35:45 -07001777 @Override
Dianne Hackbornc2293022013-02-06 23:14:49 -08001778 public int checkAddPermission(WindowManager.LayoutParams attrs, int[] outAppOp) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001779 int type = attrs.type;
Dianne Hackbornc2293022013-02-06 23:14:49 -08001780
1781 outAppOp[0] = AppOpsManager.OP_NONE;
1782
Wale Ogunwale74bf0652015-01-12 10:24:36 -08001783 if (!((type >= FIRST_APPLICATION_WINDOW && type <= LAST_APPLICATION_WINDOW)
1784 || (type >= FIRST_SUB_WINDOW && type <= LAST_SUB_WINDOW)
1785 || (type >= FIRST_SYSTEM_WINDOW && type <= LAST_SYSTEM_WINDOW))) {
1786 return WindowManagerGlobal.ADD_INVALID_TYPE;
1787 }
1788
1789 if (type < FIRST_SYSTEM_WINDOW || type > LAST_SYSTEM_WINDOW) {
1790 // Window manager will make sure these are okay.
Jeff Brown98365d72012-08-19 20:30:52 -07001791 return WindowManagerGlobal.ADD_OKAY;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001792 }
1793 String permission = null;
1794 switch (type) {
1795 case TYPE_TOAST:
1796 // XXX right now the app process has complete control over
1797 // this... should introduce a token to let the system
1798 // monitor/control what they are doing.
Jason Monk1c7c3192014-06-26 12:52:18 -04001799 outAppOp[0] = AppOpsManager.OP_TOAST_WINDOW;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001800 break;
Daniel Sandler7d276c32012-01-30 14:33:52 -05001801 case TYPE_DREAM:
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001802 case TYPE_INPUT_METHOD:
Dianne Hackbornb7cd8b92009-08-08 20:53:03 -07001803 case TYPE_WALLPAPER:
keunyounga446bf02013-06-21 19:07:57 -07001804 case TYPE_PRIVATE_PRESENTATION:
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001805 case TYPE_VOICE_INTERACTION:
Svetoslav3a5c7212014-10-14 09:54:26 -07001806 case TYPE_ACCESSIBILITY_OVERLAY:
Dianne Hackbornb7cd8b92009-08-08 20:53:03 -07001807 // The window manager will check these.
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001808 break;
1809 case TYPE_PHONE:
1810 case TYPE_PRIORITY_PHONE:
1811 case TYPE_SYSTEM_ALERT:
1812 case TYPE_SYSTEM_ERROR:
1813 case TYPE_SYSTEM_OVERLAY:
1814 permission = android.Manifest.permission.SYSTEM_ALERT_WINDOW;
Dianne Hackbornc2293022013-02-06 23:14:49 -08001815 outAppOp[0] = AppOpsManager.OP_SYSTEM_ALERT_WINDOW;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001816 break;
1817 default:
1818 permission = android.Manifest.permission.INTERNAL_SYSTEM_WINDOW;
1819 }
1820 if (permission != null) {
Billy Laucbe540f2015-06-25 01:51:44 +01001821 if (permission == android.Manifest.permission.SYSTEM_ALERT_WINDOW) {
1822 final int callingUid = Binder.getCallingUid();
1823 // check if this is a system uid first before bothering with
1824 // obtaining package name
1825 if (callingUid == Process.SYSTEM_UID) {
1826 return WindowManagerGlobal.ADD_OKAY;
1827 }
1828
1829 final int mode = mAppOpsManager.checkOp(outAppOp[0], callingUid,
1830 attrs.packageName);
1831 if (mode == AppOpsManager.MODE_DEFAULT) {
1832 if (mContext.checkCallingPermission(permission) !=
1833 PackageManager.PERMISSION_GRANTED) {
1834 return WindowManagerGlobal.ADD_PERMISSION_DENIED;
1835 }
1836 }
1837 return WindowManagerGlobal.ADD_OKAY;
1838 }
1839
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001840 if (mContext.checkCallingOrSelfPermission(permission)
1841 != PackageManager.PERMISSION_GRANTED) {
Jeff Brown98365d72012-08-19 20:30:52 -07001842 return WindowManagerGlobal.ADD_PERMISSION_DENIED;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001843 }
1844 }
Jeff Brown98365d72012-08-19 20:30:52 -07001845 return WindowManagerGlobal.ADD_OKAY;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001846 }
Craig Mautner88400d32012-09-30 12:35:45 -07001847
1848 @Override
1849 public boolean checkShowToOwnerOnly(WindowManager.LayoutParams attrs) {
1850
1851 // If this switch statement is modified, modify the comment in the declarations of
1852 // the type in {@link WindowManager.LayoutParams} as well.
1853 switch (attrs.type) {
1854 default:
1855 // These are the windows that by default are shown only to the user that created
1856 // them. If this needs to be overridden, set
1857 // {@link WindowManager.LayoutParams.PRIVATE_FLAG_SHOW_FOR_ALL_USERS} in
1858 // {@link WindowManager.LayoutParams}. Note that permission
1859 // {@link android.Manifest.permission.INTERNAL_SYSTEM_WINDOW} is required as well.
1860 if ((attrs.privateFlags & PRIVATE_FLAG_SHOW_FOR_ALL_USERS) == 0) {
1861 return true;
1862 }
1863 break;
1864
1865 // These are the windows that by default are shown to all users. However, to
1866 // protect against spoofing, check permissions below.
1867 case TYPE_APPLICATION_STARTING:
1868 case TYPE_BOOT_PROGRESS:
1869 case TYPE_DISPLAY_OVERLAY:
Selim Cinekf83e8242015-05-19 18:08:14 -07001870 case TYPE_INPUT_CONSUMER:
Jim Miller5ecd8112013-01-09 18:50:26 -08001871 case TYPE_KEYGUARD_SCRIM:
Craig Mautner88400d32012-09-30 12:35:45 -07001872 case TYPE_KEYGUARD_DIALOG:
1873 case TYPE_MAGNIFICATION_OVERLAY:
1874 case TYPE_NAVIGATION_BAR:
1875 case TYPE_NAVIGATION_BAR_PANEL:
1876 case TYPE_PHONE:
1877 case TYPE_POINTER:
1878 case TYPE_PRIORITY_PHONE:
Craig Mautner88400d32012-09-30 12:35:45 -07001879 case TYPE_SEARCH_BAR:
1880 case TYPE_STATUS_BAR:
1881 case TYPE_STATUS_BAR_PANEL:
1882 case TYPE_STATUS_BAR_SUB_PANEL:
1883 case TYPE_SYSTEM_DIALOG:
Craig Mautner88400d32012-09-30 12:35:45 -07001884 case TYPE_VOLUME_OVERLAY:
keunyounga446bf02013-06-21 19:07:57 -07001885 case TYPE_PRIVATE_PRESENTATION:
Craig Mautner88400d32012-09-30 12:35:45 -07001886 break;
1887 }
1888
1889 // Check if third party app has set window to system window type.
1890 return mContext.checkCallingOrSelfPermission(
1891 android.Manifest.permission.INTERNAL_SYSTEM_WINDOW)
1892 != PackageManager.PERMISSION_GRANTED;
1893 }
1894
Craig Mautner967212c2013-04-13 21:10:58 -07001895 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001896 public void adjustWindowParamsLw(WindowManager.LayoutParams attrs) {
1897 switch (attrs.type) {
1898 case TYPE_SYSTEM_OVERLAY:
Jeff Brown3b2b3542010-10-15 00:54:27 -07001899 case TYPE_SECURE_SYSTEM_OVERLAY:
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001900 // These types of windows can't receive input events.
1901 attrs.flags |= WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE
1902 | WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE;
Jeff Brownbfcb60a2011-09-08 18:51:14 -07001903 attrs.flags &= ~WindowManager.LayoutParams.FLAG_WATCH_OUTSIDE_TOUCH;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001904 break;
Jorim Jaggi380ecb82014-03-14 17:25:20 +01001905 case TYPE_STATUS_BAR:
1906
1907 // If the Keyguard is in a hidden state (occluded by another window), we force to
1908 // remove the wallpaper and keyguard flag so that any change in-flight after setting
1909 // the keyguard as occluded wouldn't set these flags again.
1910 // See {@link #processKeyguardSetHiddenResultLw}.
1911 if (mKeyguardHidden) {
1912 attrs.flags &= ~WindowManager.LayoutParams.FLAG_SHOW_WALLPAPER;
1913 attrs.privateFlags &= ~WindowManager.LayoutParams.PRIVATE_FLAG_KEYGUARD;
1914 }
1915 break;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001916 }
Adrian Roos38502112014-04-09 21:04:11 +02001917
1918 if (attrs.type != TYPE_STATUS_BAR) {
1919 // The status bar is the only window allowed to exhibit keyguard behavior.
1920 attrs.privateFlags &= ~WindowManager.LayoutParams.PRIVATE_FLAG_KEYGUARD;
1921 }
Adrian Roosea562512014-05-05 13:33:03 +02001922
1923 if (ActivityManager.isHighEndGfx()
1924 && (attrs.flags & FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS) != 0) {
Adrian Roosf5e9b5c2014-09-10 15:27:41 +02001925 attrs.subtreeSystemUiVisibility |= View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
Adrian Roosea562512014-05-05 13:33:03 +02001926 | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION;
1927 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001928 }
RoboErik8a2cfc32014-05-16 11:19:38 -07001929
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001930 void readLidState() {
Jeff Brown2e7760e2012-04-11 15:14:55 -07001931 mLidState = mWindowManagerFuncs.getLidState();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001932 }
RoboErik8a2cfc32014-05-16 11:19:38 -07001933
Michael Wright3818c922014-09-02 13:59:07 -07001934 private void readCameraLensCoverState() {
1935 mCameraLensCoverState = mWindowManagerFuncs.getCameraLensCoverState();
1936 }
1937
Jeff Browndaa37532012-05-01 15:54:03 -07001938 private boolean isHidden(int accessibilityMode) {
1939 switch (accessibilityMode) {
1940 case 1:
1941 return mLidState == LID_CLOSED;
1942 case 2:
1943 return mLidState == LID_OPEN;
1944 default:
1945 return false;
Dianne Hackborn2862fff2009-09-15 22:56:29 -07001946 }
Dianne Hackborn2862fff2009-09-15 22:56:29 -07001947 }
Jeff Brownd04a88c2011-01-16 14:05:47 -08001948
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001949 /** {@inheritDoc} */
Craig Mautner967212c2013-04-13 21:10:58 -07001950 @Override
Jeff Browndaa37532012-05-01 15:54:03 -07001951 public void adjustConfigurationLw(Configuration config, int keyboardPresence,
1952 int navigationPresence) {
1953 mHaveBuiltInKeyboard = (keyboardPresence & PRESENCE_INTERNAL) != 0;
1954
Jeff Brownf71343d2013-05-31 17:59:11 -07001955 readConfigurationDependentBehaviors();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001956 readLidState();
Jeff Brownc458ce92012-04-30 14:58:40 -07001957 applyLidSwitchState();
Jeff Brownd04a88c2011-01-16 14:05:47 -08001958
Jeff Browndaa37532012-05-01 15:54:03 -07001959 if (config.keyboard == Configuration.KEYBOARD_NOKEYS
1960 || (keyboardPresence == PRESENCE_INTERNAL
1961 && isHidden(mLidKeyboardAccessibility))) {
Jeff Brownd04a88c2011-01-16 14:05:47 -08001962 config.hardKeyboardHidden = Configuration.HARDKEYBOARDHIDDEN_YES;
Jeff Browndaa37532012-05-01 15:54:03 -07001963 if (!mHasSoftInput) {
1964 config.keyboardHidden = Configuration.KEYBOARDHIDDEN_YES;
1965 }
Jeff Brownd04a88c2011-01-16 14:05:47 -08001966 }
1967
Jeff Browndaa37532012-05-01 15:54:03 -07001968 if (config.navigation == Configuration.NAVIGATION_NONAV
1969 || (navigationPresence == PRESENCE_INTERNAL
1970 && isHidden(mLidNavigationAccessibility))) {
Jeff Brownd04a88c2011-01-16 14:05:47 -08001971 config.navigationHidden = Configuration.NAVIGATIONHIDDEN_YES;
Jeff Brownd04a88c2011-01-16 14:05:47 -08001972 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001973 }
Jeff Brownd04a88c2011-01-16 14:05:47 -08001974
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001975 /** {@inheritDoc} */
Craig Mautner967212c2013-04-13 21:10:58 -07001976 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001977 public int windowTypeToLayerLw(int type) {
1978 if (type >= FIRST_APPLICATION_WINDOW && type <= LAST_APPLICATION_WINDOW) {
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001979 return 2;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001980 }
1981 switch (type) {
keunyounga446bf02013-06-21 19:07:57 -07001982 case TYPE_PRIVATE_PRESENTATION:
1983 return 2;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001984 case TYPE_WALLPAPER:
1985 // wallpaper is at the bottom, though the window manager may move it.
1986 return 2;
1987 case TYPE_PHONE:
1988 return 3;
1989 case TYPE_SEARCH_BAR:
Jorim Jaggi225d3b52015-04-01 11:18:57 -07001990 case TYPE_VOICE_INTERACTION_STARTING:
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001991 return 4;
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001992 case TYPE_VOICE_INTERACTION:
1993 // voice interaction layer is almost immediately above apps.
1994 return 5;
Selim Cinekf83e8242015-05-19 18:08:14 -07001995 case TYPE_INPUT_CONSUMER:
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001996 return 6;
Selim Cinekf83e8242015-05-19 18:08:14 -07001997 case TYPE_SYSTEM_DIALOG:
1998 return 7;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001999 case TYPE_TOAST:
2000 // toasts and the plugged-in battery thing
Selim Cinekf83e8242015-05-19 18:08:14 -07002001 return 8;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07002002 case TYPE_PRIORITY_PHONE:
2003 // SIM errors and unlock. Not sure if this really should be in a high layer.
Selim Cinekf83e8242015-05-19 18:08:14 -07002004 return 9;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07002005 case TYPE_DREAM:
2006 // used for Dreams (screensavers with TYPE_DREAM windows)
Selim Cinekf83e8242015-05-19 18:08:14 -07002007 return 10;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07002008 case TYPE_SYSTEM_ALERT:
2009 // like the ANR / app crashed dialogs
Selim Cinekf83e8242015-05-19 18:08:14 -07002010 return 11;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07002011 case TYPE_INPUT_METHOD:
2012 // on-screen keyboards and other such input method user interfaces go here.
Selim Cinekf83e8242015-05-19 18:08:14 -07002013 return 12;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07002014 case TYPE_INPUT_METHOD_DIALOG:
2015 // on-screen keyboards and other such input method user interfaces go here.
Selim Cinekf83e8242015-05-19 18:08:14 -07002016 return 13;
Jim Miller5ecd8112013-01-09 18:50:26 -08002017 case TYPE_KEYGUARD_SCRIM:
2018 // the safety window that shows behind keyguard while keyguard is starting
Jorim Jaggi380ecb82014-03-14 17:25:20 +01002019 return 14;
Selim Cinekf83e8242015-05-19 18:08:14 -07002020 case TYPE_STATUS_BAR_SUB_PANEL:
Jorim Jaggi380ecb82014-03-14 17:25:20 +01002021 return 15;
Selim Cinekf83e8242015-05-19 18:08:14 -07002022 case TYPE_STATUS_BAR:
Jorim Jaggi380ecb82014-03-14 17:25:20 +01002023 return 16;
Selim Cinekf83e8242015-05-19 18:08:14 -07002024 case TYPE_STATUS_BAR_PANEL:
Dianne Hackborne30e02f2014-05-27 18:24:45 -07002025 return 17;
Selim Cinekf83e8242015-05-19 18:08:14 -07002026 case TYPE_KEYGUARD_DIALOG:
2027 return 18;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07002028 case TYPE_VOLUME_OVERLAY:
2029 // the on-screen volume indicator and controller shown when the user
2030 // changes the device volume
Selim Cinekf83e8242015-05-19 18:08:14 -07002031 return 19;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07002032 case TYPE_SYSTEM_OVERLAY:
2033 // the on-screen volume indicator and controller shown when the user
2034 // changes the device volume
Selim Cinekf83e8242015-05-19 18:08:14 -07002035 return 20;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07002036 case TYPE_NAVIGATION_BAR:
2037 // the navigation bar, if available, shows atop most things
Selim Cinekf83e8242015-05-19 18:08:14 -07002038 return 21;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07002039 case TYPE_NAVIGATION_BAR_PANEL:
2040 // some panels (e.g. search) need to show on top of the navigation bar
Selim Cinekf83e8242015-05-19 18:08:14 -07002041 return 22;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07002042 case TYPE_SYSTEM_ERROR:
2043 // system-level error dialogs
Selim Cinekf83e8242015-05-19 18:08:14 -07002044 return 23;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07002045 case TYPE_MAGNIFICATION_OVERLAY:
2046 // used to highlight the magnified portion of a display
Selim Cinekf83e8242015-05-19 18:08:14 -07002047 return 24;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07002048 case TYPE_DISPLAY_OVERLAY:
2049 // used to simulate secondary display devices
Selim Cinekf83e8242015-05-19 18:08:14 -07002050 return 25;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07002051 case TYPE_DRAG:
2052 // the drag layer: input for drag-and-drop is associated with this window,
2053 // which sits above all other focusable windows
Selim Cinekf83e8242015-05-19 18:08:14 -07002054 return 26;
Svetoslav3a5c7212014-10-14 09:54:26 -07002055 case TYPE_ACCESSIBILITY_OVERLAY:
2056 // overlay put by accessibility services to intercept user interaction
Dianne Hackborne30e02f2014-05-27 18:24:45 -07002057 return 27;
Selim Cinekf83e8242015-05-19 18:08:14 -07002058 case TYPE_SECURE_SYSTEM_OVERLAY:
Svetoslav3a5c7212014-10-14 09:54:26 -07002059 return 28;
Selim Cinekf83e8242015-05-19 18:08:14 -07002060 case TYPE_BOOT_PROGRESS:
2061 return 29;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07002062 case TYPE_POINTER:
2063 // the (mouse) pointer layer
Svetoslav3a5c7212014-10-14 09:54:26 -07002064 return 30;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002065 }
2066 Log.e(TAG, "Unknown window type: " + type);
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07002067 return 2;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002068 }
2069
2070 /** {@inheritDoc} */
Craig Mautner46ac6fa2013-08-01 10:06:34 -07002071 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002072 public int subWindowTypeToLayerLw(int type) {
2073 switch (type) {
2074 case TYPE_APPLICATION_PANEL:
2075 case TYPE_APPLICATION_ATTACHED_DIALOG:
2076 return APPLICATION_PANEL_SUBLAYER;
2077 case TYPE_APPLICATION_MEDIA:
2078 return APPLICATION_MEDIA_SUBLAYER;
Dianne Hackborn5cb8d792009-05-21 17:34:15 -07002079 case TYPE_APPLICATION_MEDIA_OVERLAY:
2080 return APPLICATION_MEDIA_OVERLAY_SUBLAYER;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002081 case TYPE_APPLICATION_SUB_PANEL:
2082 return APPLICATION_SUB_PANEL_SUBLAYER;
Wale Ogunwale0a4dc222015-04-14 12:58:42 -07002083 case TYPE_APPLICATION_ABOVE_SUB_PANEL:
2084 return APPLICATION_ABOVE_SUB_PANEL_SUBLAYER;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002085 }
2086 Log.e(TAG, "Unknown sub-window type: " + type);
2087 return 0;
2088 }
2089
Craig Mautner46ac6fa2013-08-01 10:06:34 -07002090 @Override
Dianne Hackbornabe0da02009-09-18 01:55:39 -07002091 public int getMaxWallpaperLayer() {
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07002092 return windowTypeToLayerLw(TYPE_STATUS_BAR);
Dianne Hackbornabe0da02009-09-18 01:55:39 -07002093 }
2094
Craig Mautner46ac6fa2013-08-01 10:06:34 -07002095 @Override
Dianne Hackborn1f903c32011-09-13 19:18:06 -07002096 public int getNonDecorDisplayWidth(int fullWidth, int fullHeight, int rotation) {
Dianne Hackborn077ee852012-04-09 16:27:07 -07002097 if (mHasNavigationBar) {
2098 // For a basic navigation bar, when we are in landscape mode we place
2099 // the navigation bar to the side.
Daniel Sandler4a066c52012-04-20 14:49:13 -04002100 if (mNavigationBarCanMove && fullWidth > fullHeight) {
2101 return fullWidth - mNavigationBarWidthForRotation[rotation];
Dianne Hackborn077ee852012-04-09 16:27:07 -07002102 }
Dianne Hackborn1f903c32011-09-13 19:18:06 -07002103 }
2104 return fullWidth;
Dianne Hackborne2515ee2011-04-27 18:52:56 -04002105 }
2106
Jose Lima9546b202014-07-02 17:21:51 -07002107 @Override
Dianne Hackborn1f903c32011-09-13 19:18:06 -07002108 public int getNonDecorDisplayHeight(int fullWidth, int fullHeight, int rotation) {
Dianne Hackborn077ee852012-04-09 16:27:07 -07002109 if (mHasNavigationBar) {
2110 // For a basic navigation bar, when we are in portrait mode we place
2111 // the navigation bar to the bottom.
Daniel Sandler4a066c52012-04-20 14:49:13 -04002112 if (!mNavigationBarCanMove || fullWidth < fullHeight) {
2113 return fullHeight - mNavigationBarHeightForRotation[rotation];
Dianne Hackborn077ee852012-04-09 16:27:07 -07002114 }
2115 }
2116 return fullHeight;
Dianne Hackborn69cb8752011-05-19 18:13:32 -07002117 }
2118
Jose Lima9546b202014-07-02 17:21:51 -07002119 @Override
Dianne Hackborn1f903c32011-09-13 19:18:06 -07002120 public int getConfigDisplayWidth(int fullWidth, int fullHeight, int rotation) {
2121 return getNonDecorDisplayWidth(fullWidth, fullHeight, rotation);
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 getConfigDisplayHeight(int fullWidth, int fullHeight, int rotation) {
John Spurlock80f00c12013-06-13 11:10:51 -04002126 // There is a separate status bar at the top of the display. We don't count that as part
2127 // of the fixed decor, since it can hide; however, for purposes of configurations,
Dianne Hackborn077ee852012-04-09 16:27:07 -07002128 // we do want to exclude it since applications can't generally use that part
2129 // of the screen.
John Spurlock80f00c12013-06-13 11:10:51 -04002130 return getNonDecorDisplayHeight(fullWidth, fullHeight, rotation) - mStatusBarHeight;
Dianne Hackborne2515ee2011-04-27 18:52:56 -04002131 }
2132
Craig Mautnera3f4bf52012-10-10 20:37:48 -07002133 @Override
Craig Mautnerc9457fa2014-06-06 14:27:48 -07002134 public boolean isForceHiding(WindowManager.LayoutParams attrs) {
2135 return (attrs.privateFlags & PRIVATE_FLAG_KEYGUARD) != 0 ||
Jim Millerab954542014-10-10 18:21:49 -07002136 (isKeyguardHostWindow(attrs) &&
2137 (mKeyguardDelegate != null && mKeyguardDelegate.isShowing())) ||
Adrian Roos69e510d2014-07-13 14:57:59 +02002138 (attrs.type == TYPE_KEYGUARD_SCRIM);
Dianne Hackborn01ad2f42009-09-24 19:24:56 -07002139 }
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07002140
Craig Mautnera3f4bf52012-10-10 20:37:48 -07002141 @Override
Jorim Jaggi0d674622014-05-21 01:34:15 +02002142 public boolean isKeyguardHostWindow(WindowManager.LayoutParams attrs) {
2143 return attrs.type == TYPE_STATUS_BAR;
2144 }
2145
2146 @Override
Dianne Hackborn01ad2f42009-09-24 19:24:56 -07002147 public boolean canBeForceHidden(WindowState win, WindowManager.LayoutParams attrs) {
Craig Mautnera3f4bf52012-10-10 20:37:48 -07002148 switch (attrs.type) {
2149 case TYPE_STATUS_BAR:
2150 case TYPE_NAVIGATION_BAR:
2151 case TYPE_WALLPAPER:
2152 case TYPE_DREAM:
Jim Miller5ecd8112013-01-09 18:50:26 -08002153 case TYPE_KEYGUARD_SCRIM:
Craig Mautnera3f4bf52012-10-10 20:37:48 -07002154 return false;
2155 default:
Adrian Roos461829d2015-06-03 14:41:18 -07002156 // Hide only windows below the keyguard host window.
2157 return windowTypeToLayerLw(win.getBaseType())
2158 < windowTypeToLayerLw(TYPE_STATUS_BAR);
Craig Mautnera3f4bf52012-10-10 20:37:48 -07002159 }
Dianne Hackborn01ad2f42009-09-24 19:24:56 -07002160 }
Craig Mautner8e4df6c2012-05-23 16:57:23 -07002161
Craig Mautner7d7808f2014-09-11 18:02:38 -07002162 @Override
2163 public WindowState getWinShowWhenLockedLw() {
2164 return mWinShowWhenLocked;
2165 }
2166
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002167 /** {@inheritDoc} */
Craig Mautner8e4df6c2012-05-23 16:57:23 -07002168 @Override
Dianne Hackborn2f0b1752011-05-31 17:59:49 -07002169 public View addStartingWindow(IBinder appToken, String packageName, int theme,
2170 CompatibilityInfo compatInfo, CharSequence nonLocalizedLabel, int labelRes,
Adam Powell04fe6eb2013-05-31 14:39:48 -07002171 int icon, int logo, int windowFlags) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002172 if (!SHOW_STARTING_ANIMATIONS) {
2173 return null;
2174 }
2175 if (packageName == null) {
2176 return null;
2177 }
Craig Mautner8e4df6c2012-05-23 16:57:23 -07002178
Mathias Jeppssond1443e92012-08-24 15:25:32 +02002179 WindowManager wm = null;
2180 View view = null;
2181
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002182 try {
Dianne Hackborn867ab6472010-04-29 13:28:56 -07002183 Context context = mContext;
Craig Mautner6fbda632012-07-03 09:26:39 -07002184 if (DEBUG_STARTING_WINDOW) Slog.d(TAG, "addStartingWindow " + packageName
2185 + ": nonLocalizedLabel=" + nonLocalizedLabel + " theme="
2186 + Integer.toHexString(theme));
Dianne Hackborn247fe742011-01-08 17:25:57 -08002187 if (theme != context.getThemeResId() || labelRes != 0) {
Dianne Hackborn867ab6472010-04-29 13:28:56 -07002188 try {
2189 context = context.createPackageContext(packageName, 0);
Dianne Hackborn247fe742011-01-08 17:25:57 -08002190 context.setTheme(theme);
Dianne Hackborn867ab6472010-04-29 13:28:56 -07002191 } catch (PackageManager.NameNotFoundException e) {
2192 // Ignore
2193 }
2194 }
Craig Mautner8e4df6c2012-05-23 16:57:23 -07002195
Jorim Jaggia16cc152015-06-01 16:55:05 -07002196 PhoneWindow win = new PhoneWindow(context);
2197 win.setIsStartingWindow(true);
Craig Mautner8e4df6c2012-05-23 16:57:23 -07002198 final TypedArray ta = win.getWindowStyle();
2199 if (ta.getBoolean(
2200 com.android.internal.R.styleable.Window_windowDisablePreview, false)
2201 || ta.getBoolean(
2202 com.android.internal.R.styleable.Window_windowShowWallpaper,false)) {
Dianne Hackborn867ab6472010-04-29 13:28:56 -07002203 return null;
2204 }
Craig Mautner8e4df6c2012-05-23 16:57:23 -07002205
Dianne Hackborn867ab6472010-04-29 13:28:56 -07002206 Resources r = context.getResources();
2207 win.setTitle(r.getText(labelRes, nonLocalizedLabel));
Craig Mautner8e4df6c2012-05-23 16:57:23 -07002208
Dianne Hackborn867ab6472010-04-29 13:28:56 -07002209 win.setType(
2210 WindowManager.LayoutParams.TYPE_APPLICATION_STARTING);
Adrian Roos602c68e2015-04-24 16:03:47 -07002211
2212 synchronized (mWindowManagerFuncs.getWindowManagerLock()) {
2213 // Assumes it's safe to show starting windows of launched apps while
2214 // the keyguard is being hidden. This is okay because starting windows never show
2215 // secret information.
2216 if (mKeyguardHidden) {
2217 windowFlags |= FLAG_SHOW_WHEN_LOCKED;
2218 }
2219 }
2220
Dianne Hackborn867ab6472010-04-29 13:28:56 -07002221 // Force the window flags: this is a fake window, so it is not really
2222 // touchable or focusable by the user. We also add in the ALT_FOCUSABLE_IM
2223 // flag because we do know that the next window will take input
2224 // focus, so we want to get the IME window up on top of us right away.
2225 win.setFlags(
Dianne Hackborn7eec10e2010-11-12 18:03:47 -08002226 windowFlags|
Dianne Hackborn867ab6472010-04-29 13:28:56 -07002227 WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE|
2228 WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE|
2229 WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM,
Dianne Hackborn7eec10e2010-11-12 18:03:47 -08002230 windowFlags|
Dianne Hackborn867ab6472010-04-29 13:28:56 -07002231 WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE|
2232 WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE|
2233 WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM);
Craig Mautner8e4df6c2012-05-23 16:57:23 -07002234
Adam Powell04fe6eb2013-05-31 14:39:48 -07002235 win.setDefaultIcon(icon);
2236 win.setDefaultLogo(logo);
2237
Dianne Hackborn867ab6472010-04-29 13:28:56 -07002238 win.setLayout(WindowManager.LayoutParams.MATCH_PARENT,
Dianne Hackborn2f0b1752011-05-31 17:59:49 -07002239 WindowManager.LayoutParams.MATCH_PARENT);
Craig Mautner8e4df6c2012-05-23 16:57:23 -07002240
Dianne Hackborn867ab6472010-04-29 13:28:56 -07002241 final WindowManager.LayoutParams params = win.getAttributes();
2242 params.token = appToken;
2243 params.packageName = packageName;
2244 params.windowAnimations = win.getWindowStyle().getResourceId(
2245 com.android.internal.R.styleable.Window_windowAnimationStyle, 0);
John Reck61375a82014-09-18 19:27:48 +00002246 params.privateFlags |=
2247 WindowManager.LayoutParams.PRIVATE_FLAG_FAKE_HARDWARE_ACCELERATED;
Craig Mautner88400d32012-09-30 12:35:45 -07002248 params.privateFlags |= WindowManager.LayoutParams.PRIVATE_FLAG_SHOW_FOR_ALL_USERS;
Adam Lesinski95c42972013-10-02 10:13:27 -07002249
2250 if (!compatInfo.supportsScreen()) {
2251 params.privateFlags |= WindowManager.LayoutParams.PRIVATE_FLAG_COMPATIBLE_WINDOW;
2252 }
2253
Dianne Hackborn867ab6472010-04-29 13:28:56 -07002254 params.setTitle("Starting " + packageName);
2255
Mathias Jeppssond1443e92012-08-24 15:25:32 +02002256 wm = (WindowManager)context.getSystemService(Context.WINDOW_SERVICE);
2257 view = win.getDecorView();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002258
2259 if (win.isFloating()) {
2260 // Whoops, there is no way to display an animation/preview
2261 // of such a thing! After all that work... let's skip it.
2262 // (Note that we must do this here because it is in
2263 // getDecorView() where the theme is evaluated... maybe
2264 // we should peek the floating attribute from the theme
2265 // earlier.)
2266 return null;
2267 }
Craig Mautner8e4df6c2012-05-23 16:57:23 -07002268
Craig Mautner6fbda632012-07-03 09:26:39 -07002269 if (DEBUG_STARTING_WINDOW) Slog.d(
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002270 TAG, "Adding starting window for " + packageName
2271 + " / " + appToken + ": "
2272 + (view.getParent() != null ? view : null));
2273
2274 wm.addView(view, params);
2275
2276 // Only return the view if it was successfully added to the
2277 // window manager... which we can tell by it having a parent.
2278 return view.getParent() != null ? view : null;
Jeff Brown98365d72012-08-19 20:30:52 -07002279 } catch (WindowManager.BadTokenException e) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002280 // ignore
Craig Mautner42bf39e2014-02-21 16:46:22 -08002281 Log.w(TAG, appToken + " already running, starting window not displayed. " +
2282 e.getMessage());
Dianne Hackborn867ab6472010-04-29 13:28:56 -07002283 } catch (RuntimeException e) {
2284 // don't crash if something else bad happens, for example a
2285 // failure loading resources because we are loading from an app
2286 // on external storage that has been unmounted.
2287 Log.w(TAG, appToken + " failed creating starting window", e);
Mathias Jeppssond1443e92012-08-24 15:25:32 +02002288 } finally {
2289 if (view != null && view.getParent() == null) {
2290 Log.w(TAG, "view not successfully added to wm, removing view");
2291 wm.removeViewImmediate(view);
2292 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002293 }
2294
2295 return null;
2296 }
2297
2298 /** {@inheritDoc} */
Jose Lima9546b202014-07-02 17:21:51 -07002299 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002300 public void removeStartingWindow(IBinder appToken, View window) {
Craig Mautner276a6eb2014-11-04 15:32:57 -08002301 if (DEBUG_STARTING_WINDOW) Slog.v(TAG, "Removing starting window for " + appToken + ": "
2302 + window + " Callers=" + Debug.getCallers(4));
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002303
2304 if (window != null) {
Dianne Hackborn5fd21692011-06-07 14:09:47 -07002305 WindowManager wm = (WindowManager)mContext.getSystemService(Context.WINDOW_SERVICE);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002306 wm.removeView(window);
2307 }
2308 }
2309
2310 /**
2311 * Preflight adding a window to the system.
RoboErik8a2cfc32014-05-16 11:19:38 -07002312 *
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002313 * Currently enforces that three window types are singletons:
2314 * <ul>
2315 * <li>STATUS_BAR_TYPE</li>
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002316 * <li>KEYGUARD_TYPE</li>
2317 * </ul>
RoboErik8a2cfc32014-05-16 11:19:38 -07002318 *
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002319 * @param win The window to be added
2320 * @param attrs Information about the window to be added
RoboErik8a2cfc32014-05-16 11:19:38 -07002321 *
Jeff Brown98365d72012-08-19 20:30:52 -07002322 * @return If ok, WindowManagerImpl.ADD_OKAY. If too many singletons,
2323 * WindowManagerImpl.ADD_MULTIPLE_SINGLETON
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002324 */
Jose Lima9546b202014-07-02 17:21:51 -07002325 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002326 public int prepareAddWindowLw(WindowState win, WindowManager.LayoutParams attrs) {
2327 switch (attrs.type) {
2328 case TYPE_STATUS_BAR:
Joe Onorato8bc6c512010-06-04 16:21:12 -04002329 mContext.enforceCallingOrSelfPermission(
2330 android.Manifest.permission.STATUS_BAR_SERVICE,
2331 "PhoneWindowManager");
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002332 if (mStatusBar != null) {
Dianne Hackbornf87d1962012-04-04 12:48:24 -07002333 if (mStatusBar.isAlive()) {
Jeff Brown98365d72012-08-19 20:30:52 -07002334 return WindowManagerGlobal.ADD_MULTIPLE_SINGLETON;
Dianne Hackbornf87d1962012-04-04 12:48:24 -07002335 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002336 }
2337 mStatusBar = win;
John Spurlock27735a42013-08-14 17:57:38 -04002338 mStatusBarController.setWindow(win);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002339 break;
Daniel Sandler8956dbb2011-04-22 07:55:02 -04002340 case TYPE_NAVIGATION_BAR:
2341 mContext.enforceCallingOrSelfPermission(
2342 android.Manifest.permission.STATUS_BAR_SERVICE,
2343 "PhoneWindowManager");
Dianne Hackbornf87d1962012-04-04 12:48:24 -07002344 if (mNavigationBar != null) {
2345 if (mNavigationBar.isAlive()) {
Jeff Brown98365d72012-08-19 20:30:52 -07002346 return WindowManagerGlobal.ADD_MULTIPLE_SINGLETON;
Dianne Hackbornf87d1962012-04-04 12:48:24 -07002347 }
2348 }
Daniel Sandler8956dbb2011-04-22 07:55:02 -04002349 mNavigationBar = win;
John Spurlock27735a42013-08-14 17:57:38 -04002350 mNavigationBarController.setWindow(win);
Craig Mautnereda67292013-04-28 13:50:14 -07002351 if (DEBUG_LAYOUT) Slog.i(TAG, "NAVIGATION BAR: " + mNavigationBar);
Daniel Sandler8956dbb2011-04-22 07:55:02 -04002352 break;
Jim Millere898ac52012-04-06 17:10:57 -07002353 case TYPE_NAVIGATION_BAR_PANEL:
Dianne Hackborn08743722009-12-21 12:16:51 -08002354 case TYPE_STATUS_BAR_PANEL:
Joe Onorato29fc2c92010-11-24 10:26:50 -08002355 case TYPE_STATUS_BAR_SUB_PANEL:
Jorim Jaggi225d3b52015-04-01 11:18:57 -07002356 case TYPE_VOICE_INTERACTION_STARTING:
Joe Onorato29fc2c92010-11-24 10:26:50 -08002357 mContext.enforceCallingOrSelfPermission(
2358 android.Manifest.permission.STATUS_BAR_SERVICE,
2359 "PhoneWindowManager");
Joe Onorato29fc2c92010-11-24 10:26:50 -08002360 break;
Jim Miller5ecd8112013-01-09 18:50:26 -08002361 case TYPE_KEYGUARD_SCRIM:
Jim Miller25190572013-02-28 17:36:24 -08002362 if (mKeyguardScrim != null) {
2363 return WindowManagerGlobal.ADD_MULTIPLE_SINGLETON;
2364 }
Jim Miller5ecd8112013-01-09 18:50:26 -08002365 mKeyguardScrim = win;
2366 break;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002367 }
Jeff Brown98365d72012-08-19 20:30:52 -07002368 return WindowManagerGlobal.ADD_OKAY;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002369 }
2370
2371 /** {@inheritDoc} */
Jose Lima9546b202014-07-02 17:21:51 -07002372 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002373 public void removeWindowLw(WindowState win) {
2374 if (mStatusBar == win) {
2375 mStatusBar = null;
John Spurlock27735a42013-08-14 17:57:38 -04002376 mStatusBarController.setWindow(null);
Jim Millerc0b676d2013-03-22 16:11:08 -07002377 mKeyguardDelegate.showScrim();
Jim Miller5ecd8112013-01-09 18:50:26 -08002378 } else if (mKeyguardScrim == win) {
2379 Log.v(TAG, "Removing keyguard scrim");
2380 mKeyguardScrim = null;
2381 } if (mNavigationBar == win) {
Daniel Sandler8956dbb2011-04-22 07:55:02 -04002382 mNavigationBar = null;
John Spurlock27735a42013-08-14 17:57:38 -04002383 mNavigationBarController.setWindow(null);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002384 }
2385 }
2386
2387 static final boolean PRINT_ANIM = false;
RoboErik8a2cfc32014-05-16 11:19:38 -07002388
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002389 /** {@inheritDoc} */
Craig Mautner4b71aa12012-12-27 17:20:01 -08002390 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002391 public int selectAnimationLw(WindowState win, int transit) {
2392 if (PRINT_ANIM) Log.i(TAG, "selectAnimation in " + win
2393 + ": transit=" + transit);
Dianne Hackbornf87d1962012-04-04 12:48:24 -07002394 if (win == mStatusBar) {
Jorim Jaggi380ecb82014-03-14 17:25:20 +01002395 boolean isKeyguard = (win.getAttrs().privateFlags & PRIVATE_FLAG_KEYGUARD) != 0;
Craig Mautner4b71aa12012-12-27 17:20:01 -08002396 if (transit == TRANSIT_EXIT
2397 || transit == TRANSIT_HIDE) {
Jorim Jaggi380ecb82014-03-14 17:25:20 +01002398 return isKeyguard ? -1 : R.anim.dock_top_exit;
Craig Mautner4b71aa12012-12-27 17:20:01 -08002399 } else if (transit == TRANSIT_ENTER
2400 || transit == TRANSIT_SHOW) {
Jorim Jaggi380ecb82014-03-14 17:25:20 +01002401 return isKeyguard ? -1 : R.anim.dock_top_enter;
Dianne Hackbornf87d1962012-04-04 12:48:24 -07002402 }
2403 } else if (win == mNavigationBar) {
2404 // This can be on either the bottom or the right.
2405 if (mNavigationBarOnBottom) {
Craig Mautner4b71aa12012-12-27 17:20:01 -08002406 if (transit == TRANSIT_EXIT
2407 || transit == TRANSIT_HIDE) {
Dianne Hackbornf87d1962012-04-04 12:48:24 -07002408 return R.anim.dock_bottom_exit;
Craig Mautner4b71aa12012-12-27 17:20:01 -08002409 } else if (transit == TRANSIT_ENTER
2410 || transit == TRANSIT_SHOW) {
Dianne Hackbornf87d1962012-04-04 12:48:24 -07002411 return R.anim.dock_bottom_enter;
2412 }
2413 } else {
Craig Mautner4b71aa12012-12-27 17:20:01 -08002414 if (transit == TRANSIT_EXIT
2415 || transit == TRANSIT_HIDE) {
Dianne Hackbornf87d1962012-04-04 12:48:24 -07002416 return R.anim.dock_right_exit;
Craig Mautner4b71aa12012-12-27 17:20:01 -08002417 } else if (transit == TRANSIT_ENTER
2418 || transit == TRANSIT_SHOW) {
Dianne Hackbornf87d1962012-04-04 12:48:24 -07002419 return R.anim.dock_right_enter;
2420 }
2421 }
Craig Mautner4b71aa12012-12-27 17:20:01 -08002422 }
2423
2424 if (transit == TRANSIT_PREVIEW_DONE) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002425 if (win.hasAppShownWindows()) {
2426 if (PRINT_ANIM) Log.i(TAG, "**** STARTING EXIT");
2427 return com.android.internal.R.anim.app_starting_exit;
2428 }
Dianne Hackborn7ad44382012-10-18 17:46:00 -07002429 } else if (win.getAttrs().type == TYPE_DREAM && mDreamingLockscreen
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07002430 && transit == TRANSIT_ENTER) {
2431 // Special case: we are animating in a dream, while the keyguard
2432 // is shown. We don't want an animation on the dream, because
2433 // we need it shown immediately with the keyguard animating away
2434 // to reveal it.
2435 return -1;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002436 }
2437
2438 return 0;
2439 }
2440
Craig Mautner3c174372013-02-21 17:54:37 -08002441 @Override
2442 public void selectRotationAnimationLw(int anim[]) {
2443 if (PRINT_ANIM) Slog.i(TAG, "selectRotationAnimation mTopFullscreen="
2444 + mTopFullscreenOpaqueWindowState + " rotationAnimation="
2445 + (mTopFullscreenOpaqueWindowState == null ?
2446 "0" : mTopFullscreenOpaqueWindowState.getAttrs().rotationAnimation));
2447 if (mTopFullscreenOpaqueWindowState != null && mTopIsFullscreen) {
2448 switch (mTopFullscreenOpaqueWindowState.getAttrs().rotationAnimation) {
2449 case ROTATION_ANIMATION_CROSSFADE:
2450 anim[0] = R.anim.rotation_animation_xfade_exit;
2451 anim[1] = R.anim.rotation_animation_enter;
2452 break;
2453 case ROTATION_ANIMATION_JUMPCUT:
2454 anim[0] = R.anim.rotation_animation_jump_exit;
2455 anim[1] = R.anim.rotation_animation_enter;
2456 break;
2457 case ROTATION_ANIMATION_ROTATE:
2458 default:
2459 anim[0] = anim[1] = 0;
2460 break;
2461 }
2462 } else {
2463 anim[0] = anim[1] = 0;
2464 }
2465 }
2466
2467 @Override
2468 public boolean validateRotationAnimationLw(int exitAnimId, int enterAnimId,
2469 boolean forceDefault) {
2470 switch (exitAnimId) {
2471 case R.anim.rotation_animation_xfade_exit:
2472 case R.anim.rotation_animation_jump_exit:
2473 // These are the only cases that matter.
2474 if (forceDefault) {
2475 return false;
2476 }
2477 int anim[] = new int[2];
2478 selectRotationAnimationLw(anim);
2479 return (exitAnimId == anim[0] && enterAnimId == anim[1]);
2480 default:
2481 return true;
2482 }
2483 }
2484
2485 @Override
Jorim Jaggi84a3e7a2014-08-13 17:58:58 +02002486 public Animation createForceHideEnterAnimation(boolean onWallpaper,
2487 boolean goingToNotificationShade) {
2488 if (goingToNotificationShade) {
2489 return AnimationUtils.loadAnimation(mContext, R.anim.lock_screen_behind_enter_fade_in);
Craig Mautnerb8340802014-11-04 15:32:57 -08002490 }
Craig Mautner276a6eb2014-11-04 15:32:57 -08002491
2492 AnimationSet set = (AnimationSet) AnimationUtils.loadAnimation(mContext, onWallpaper ?
2493 R.anim.lock_screen_behind_enter_wallpaper :
2494 R.anim.lock_screen_behind_enter);
2495
2496 // TODO: Use XML interpolators when we have log interpolators available in XML.
2497 final List<Animation> animations = set.getAnimations();
2498 for (int i = animations.size() - 1; i >= 0; --i) {
2499 animations.get(i).setInterpolator(mLogDecelerateInterpolator);
2500 }
2501
2502 return set;
Jorim Jaggi76a16232014-08-08 17:00:47 +02002503 }
2504
2505
2506 @Override
Jorim Jaggi84a3e7a2014-08-13 17:58:58 +02002507 public Animation createForceHideWallpaperExitAnimation(boolean goingToNotificationShade) {
2508 if (goingToNotificationShade) {
2509 return null;
2510 } else {
2511 return AnimationUtils.loadAnimation(mContext, R.anim.lock_screen_wallpaper_exit);
2512 }
Dianne Hackborn01ad2f42009-09-24 19:24:56 -07002513 }
John Spurlockc8b46ca2013-04-08 12:59:26 -04002514
2515 private static void awakenDreams() {
2516 IDreamManager dreamManager = getDreamManager();
2517 if (dreamManager != null) {
2518 try {
2519 dreamManager.awaken();
2520 } catch (RemoteException e) {
2521 // fine, stay asleep then
2522 }
2523 }
2524 }
2525
2526 static IDreamManager getDreamManager() {
2527 return IDreamManager.Stub.asInterface(
2528 ServiceManager.checkService(DreamService.DREAM_SERVICE));
2529 }
2530
Tyler Gunnef9f6f92014-09-12 22:16:17 -07002531 TelecomManager getTelecommService() {
2532 return (TelecomManager) mContext.getSystemService(Context.TELECOM_SERVICE);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002533 }
2534
Jeff Brown4d396052010-10-29 21:50:21 -07002535 static IAudioService getAudioService() {
2536 IAudioService audioService = IAudioService.Stub.asInterface(
2537 ServiceManager.checkService(Context.AUDIO_SERVICE));
2538 if (audioService == null) {
2539 Log.w(TAG, "Unable to find IAudioService interface.");
2540 }
2541 return audioService;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002542 }
2543
2544 boolean keyguardOn() {
Jim Millerab954542014-10-10 18:21:49 -07002545 return isKeyguardShowingAndNotOccluded() || inKeyguardRestrictedKeyInputMode();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002546 }
2547
2548 private static final int[] WINDOW_TYPES_WHERE_HOME_DOESNT_WORK = {
2549 WindowManager.LayoutParams.TYPE_SYSTEM_ALERT,
2550 WindowManager.LayoutParams.TYPE_SYSTEM_ERROR,
2551 };
2552
2553 /** {@inheritDoc} */
Jeff Brown00fa7bd2010-07-02 15:37:36 -07002554 @Override
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002555 public long interceptKeyBeforeDispatching(WindowState win, KeyEvent event, int policyFlags) {
Jeff Brown00fa7bd2010-07-02 15:37:36 -07002556 final boolean keyguardOn = keyguardOn();
Jeff Brown1f245102010-11-18 20:53:46 -08002557 final int keyCode = event.getKeyCode();
2558 final int repeatCount = event.getRepeatCount();
2559 final int metaState = event.getMetaState();
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002560 final int flags = event.getFlags();
Jeff Brown1f245102010-11-18 20:53:46 -08002561 final boolean down = event.getAction() == KeyEvent.ACTION_DOWN;
2562 final boolean canceled = event.isCanceled();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002563
Jeff Brown40013652012-05-16 21:22:36 -07002564 if (DEBUG_INPUT) {
Jeff Brown00fa7bd2010-07-02 15:37:36 -07002565 Log.d(TAG, "interceptKeyTi keyCode=" + keyCode + " down=" + down + " repeatCount="
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002566 + repeatCount + " keyguardOn=" + keyguardOn + " mHomePressed=" + mHomePressed
2567 + " canceled=" + canceled);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002568 }
2569
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002570 // If we think we might have a volume down & power key chord on the way
2571 // but we're not sure, then tell the dispatcher to wait a little while and
2572 // try again later before dispatching.
Christopher Tatee90585f2012-03-05 18:56:25 -08002573 if (mScreenshotChordEnabled && (flags & KeyEvent.FLAG_FALLBACK) == 0) {
Jeff Brown13f00f02014-10-31 14:45:50 -07002574 if (mScreenshotChordVolumeDownKeyTriggered && !mScreenshotChordPowerKeyTriggered) {
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002575 final long now = SystemClock.uptimeMillis();
Jeff Brown13f00f02014-10-31 14:45:50 -07002576 final long timeoutTime = mScreenshotChordVolumeDownKeyTime
2577 + SCREENSHOT_CHORD_DEBOUNCE_DELAY_MILLIS;
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002578 if (now < timeoutTime) {
2579 return timeoutTime - now;
2580 }
2581 }
2582 if (keyCode == KeyEvent.KEYCODE_VOLUME_DOWN
Jeff Brown13f00f02014-10-31 14:45:50 -07002583 && mScreenshotChordVolumeDownKeyConsumed) {
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002584 if (!down) {
Jeff Brown13f00f02014-10-31 14:45:50 -07002585 mScreenshotChordVolumeDownKeyConsumed = false;
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002586 }
2587 return -1;
2588 }
2589 }
2590
Michael Wright6a62e552014-06-03 19:19:48 -07002591 // Cancel any pending meta actions if we see any other keys being pressed between the down
2592 // of the meta key and its corresponding up.
Michael Wright251e35d2014-08-22 15:40:27 -07002593 if (mPendingMetaAction && !KeyEvent.isMetaKey(keyCode)) {
Michael Wright6a62e552014-06-03 19:19:48 -07002594 mPendingMetaAction = false;
2595 }
2596
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002597 // First we always handle the home key here, so applications
2598 // can never break it, although if keyguard is on, we do let
2599 // it handle it, because that gives us the correct 5 second
2600 // timeout.
Jeff Brown00fa7bd2010-07-02 15:37:36 -07002601 if (keyCode == KeyEvent.KEYCODE_HOME) {
Michael Jurka7f2668c2012-03-27 07:49:52 -07002602
Jeff Brown49ed71d2010-12-06 17:13:33 -08002603 // If we have released the home key, and didn't do anything else
2604 // while it was pressed, then it is time to go home!
Michael Jurka7f2668c2012-03-27 07:49:52 -07002605 if (!down) {
Jeff Browncaca8812013-05-09 13:34:33 -07002606 cancelPreloadRecentApps();
2607
Jeff Brown49ed71d2010-12-06 17:13:33 -08002608 mHomePressed = false;
Jeff Browncaca8812013-05-09 13:34:33 -07002609 if (mHomeConsumed) {
2610 mHomeConsumed = false;
Michael Jurka7f2668c2012-03-27 07:49:52 -07002611 return -1;
Jeff Brown49ed71d2010-12-06 17:13:33 -08002612 }
Jeff Browncaca8812013-05-09 13:34:33 -07002613
2614 if (canceled) {
2615 Log.i(TAG, "Ignoring HOME; event canceled.");
2616 return -1;
2617 }
2618
Yorke Lee4f803242014-12-15 23:22:06 +00002619 // If an incoming call is ringing, HOME is totally disabled.
2620 // (The user is already on the InCallUI at this point,
2621 // and his ONLY options are to answer or reject the call.)
2622 TelecomManager telecomManager = getTelecommService();
2623 if (telecomManager != null && telecomManager.isRinging()) {
2624 Log.i(TAG, "Ignoring HOME; there's a ringing incoming call.");
2625 return -1;
2626 }
2627
Jeff Browncaca8812013-05-09 13:34:33 -07002628 // Delay handling home if a double-tap is possible.
2629 if (mDoubleTapOnHomeBehavior != DOUBLE_TAP_HOME_NOTHING) {
2630 mHandler.removeCallbacks(mHomeDoubleTapTimeoutRunnable); // just in case
2631 mHomeDoubleTapPending = true;
2632 mHandler.postDelayed(mHomeDoubleTapTimeoutRunnable,
2633 ViewConfiguration.getDoubleTapTimeout());
2634 return -1;
2635 }
2636
Jeff Brown13f00f02014-10-31 14:45:50 -07002637 handleShortPressOnHome();
Jeff Browncaca8812013-05-09 13:34:33 -07002638 return -1;
Jeff Brown49ed71d2010-12-06 17:13:33 -08002639 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002640
2641 // If a system window has focus, then it doesn't make sense
2642 // right now to interact with applications.
2643 WindowManager.LayoutParams attrs = win != null ? win.getAttrs() : null;
2644 if (attrs != null) {
2645 final int type = attrs.type;
Jorim Jaggi380ecb82014-03-14 17:25:20 +01002646 if (type == WindowManager.LayoutParams.TYPE_KEYGUARD_SCRIM
2647 || type == WindowManager.LayoutParams.TYPE_KEYGUARD_DIALOG
2648 || (attrs.privateFlags & PRIVATE_FLAG_KEYGUARD) != 0) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002649 // the "app" is keyguard, so give it the key
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002650 return 0;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002651 }
2652 final int typeCount = WINDOW_TYPES_WHERE_HOME_DOESNT_WORK.length;
2653 for (int i=0; i<typeCount; i++) {
2654 if (type == WINDOW_TYPES_WHERE_HOME_DOESNT_WORK[i]) {
2655 // don't do anything, but also don't pass it to the app
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002656 return -1;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002657 }
2658 }
2659 }
Jeff Browncaca8812013-05-09 13:34:33 -07002660
2661 // Remember that home is pressed and handle special actions.
2662 if (repeatCount == 0) {
2663 mHomePressed = true;
2664 if (mHomeDoubleTapPending) {
2665 mHomeDoubleTapPending = false;
2666 mHandler.removeCallbacks(mHomeDoubleTapTimeoutRunnable);
2667 handleDoubleTapOnHome();
2668 } else if (mLongPressOnHomeBehavior == LONG_PRESS_HOME_RECENT_SYSTEM_UI
2669 || mDoubleTapOnHomeBehavior == DOUBLE_TAP_HOME_RECENT_SYSTEM_UI) {
2670 preloadRecentApps();
Michael Jurka7f2668c2012-03-27 07:49:52 -07002671 }
Jeff Browncaca8812013-05-09 13:34:33 -07002672 } else if ((event.getFlags() & KeyEvent.FLAG_LONG_PRESS) != 0) {
2673 if (!keyguardOn) {
Tim Kilbourn0e5f1102015-06-05 16:18:09 -07002674 handleLongPressOnHome(event.getDeviceId());
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002675 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002676 }
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002677 return -1;
Jeff Brown00fa7bd2010-07-02 15:37:36 -07002678 } else if (keyCode == KeyEvent.KEYCODE_MENU) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002679 // Hijack modified menu keys for debugging features
2680 final int chordBug = KeyEvent.META_SHIFT_ON;
2681
2682 if (down && repeatCount == 0) {
Jeff Brown00fa7bd2010-07-02 15:37:36 -07002683 if (mEnableShiftMenuBugReports && (metaState & chordBug) == chordBug) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002684 Intent intent = new Intent(Intent.ACTION_BUG_REPORT);
Dianne Hackborn5ac72a22012-08-29 18:32:08 -07002685 mContext.sendOrderedBroadcastAsUser(intent, UserHandle.CURRENT,
2686 null, null, null, 0, null, null);
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002687 return -1;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002688 } else if (SHOW_PROCESSES_ON_ALT_MENU &&
Jeff Brown00fa7bd2010-07-02 15:37:36 -07002689 (metaState & KeyEvent.META_ALT_ON) == KeyEvent.META_ALT_ON) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002690 Intent service = new Intent();
2691 service.setClassName(mContext, "com.android.server.LoadAverageService");
2692 ContentResolver res = mContext.getContentResolver();
Jeff Sharkey8d9a1f62012-10-18 15:38:14 -07002693 boolean shown = Settings.Global.getInt(
2694 res, Settings.Global.SHOW_PROCESSES, 0) != 0;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002695 if (!shown) {
2696 mContext.startService(service);
2697 } else {
2698 mContext.stopService(service);
2699 }
Jeff Sharkey8d9a1f62012-10-18 15:38:14 -07002700 Settings.Global.putInt(
2701 res, Settings.Global.SHOW_PROCESSES, shown ? 0 : 1);
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002702 return -1;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002703 }
2704 }
Jeff Brown00fa7bd2010-07-02 15:37:36 -07002705 } else if (keyCode == KeyEvent.KEYCODE_SEARCH) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002706 if (down) {
2707 if (repeatCount == 0) {
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002708 mSearchKeyShortcutPending = true;
2709 mConsumeSearchKeyUp = false;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002710 }
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002711 } else {
2712 mSearchKeyShortcutPending = false;
2713 if (mConsumeSearchKeyUp) {
2714 mConsumeSearchKeyUp = false;
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002715 return -1;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002716 }
2717 }
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002718 return 0;
Jeff Brown49ed71d2010-12-06 17:13:33 -08002719 } else if (keyCode == KeyEvent.KEYCODE_APP_SWITCH) {
Michael Wrightc9ebea72013-01-16 19:25:02 -08002720 if (!keyguardOn) {
Jeff Browncaca8812013-05-09 13:34:33 -07002721 if (down && repeatCount == 0) {
2722 preloadRecentApps();
2723 } else if (!down) {
2724 toggleRecentApps();
Michael Wrightc9ebea72013-01-16 19:25:02 -08002725 }
Jeff Brown49ed71d2010-12-06 17:13:33 -08002726 }
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002727 return -1;
Jun Mukaid21b3c82015-04-23 14:09:34 -07002728 } else if (keyCode == KeyEvent.KEYCODE_N && event.isMetaPressed()) {
2729 if (down) {
2730 IStatusBarService service = getStatusBarService();
2731 if (service != null) {
2732 try {
2733 service.expandNotificationsPanel();
2734 } catch (RemoteException e) {
2735 // do nothing.
2736 }
2737 }
2738 }
Jeff Brownde7a8ea2012-06-13 18:28:57 -07002739 } else if (keyCode == KeyEvent.KEYCODE_ASSIST) {
2740 if (down) {
2741 if (repeatCount == 0) {
2742 mAssistKeyLongPressed = false;
2743 } else if (repeatCount == 1) {
2744 mAssistKeyLongPressed = true;
2745 if (!keyguardOn) {
2746 launchAssistLongPressAction();
2747 }
2748 }
2749 } else {
2750 if (mAssistKeyLongPressed) {
2751 mAssistKeyLongPressed = false;
2752 } else {
2753 if (!keyguardOn) {
Tim Kilbourn0e5f1102015-06-05 16:18:09 -07002754 launchAssistAction(null, event.getDeviceId());
Jeff Brownde7a8ea2012-06-13 18:28:57 -07002755 }
2756 }
2757 }
2758 return -1;
Michael Wrightdc63f7b2014-08-21 19:05:21 -07002759 } else if (keyCode == KeyEvent.KEYCODE_VOICE_ASSIST) {
2760 if (!down) {
2761 Intent voiceIntent;
Michael Wright869a67c2014-08-26 19:33:06 -07002762 if (!keyguardOn) {
Michael Wrightdc63f7b2014-08-21 19:05:21 -07002763 voiceIntent = new Intent(RecognizerIntent.ACTION_WEB_SEARCH);
2764 } else {
Dianne Hackbornb6683c42015-06-18 17:40:33 -07002765 IDeviceIdleController dic = IDeviceIdleController.Stub.asInterface(
2766 ServiceManager.getService(Context.DEVICE_IDLE_CONTROLLER));
2767 if (dic != null) {
2768 try {
2769 dic.exitIdle("voice-search");
2770 } catch (RemoteException e) {
2771 }
2772 }
Michael Wrightdc63f7b2014-08-21 19:05:21 -07002773 voiceIntent = new Intent(RecognizerIntent.ACTION_VOICE_SEARCH_HANDS_FREE);
Michael Wright869a67c2014-08-26 19:33:06 -07002774 voiceIntent.putExtra(RecognizerIntent.EXTRA_SECURE, true);
Michael Wrightdc63f7b2014-08-21 19:05:21 -07002775 }
Bart Sears8b1c27c2015-03-18 23:51:02 +00002776 startActivityAsUser(voiceIntent, UserHandle.CURRENT_OR_SELF);
Michael Wrightdc63f7b2014-08-21 19:05:21 -07002777 }
Jeff Sharkey2991fa32012-12-05 18:06:43 -08002778 } else if (keyCode == KeyEvent.KEYCODE_SYSRQ) {
2779 if (down && repeatCount == 0) {
2780 mHandler.post(mScreenshotRunnable);
2781 }
2782 return -1;
Michael Wrightb854e242013-02-05 17:54:02 -08002783 } else if (keyCode == KeyEvent.KEYCODE_BRIGHTNESS_UP
2784 || keyCode == KeyEvent.KEYCODE_BRIGHTNESS_DOWN) {
2785 if (down) {
2786 int direction = keyCode == KeyEvent.KEYCODE_BRIGHTNESS_UP ? 1 : -1;
2787
2788 // Disable autobrightness if it's on
2789 int auto = Settings.System.getIntForUser(
2790 mContext.getContentResolver(),
2791 Settings.System.SCREEN_BRIGHTNESS_MODE,
2792 Settings.System.SCREEN_BRIGHTNESS_MODE_MANUAL,
2793 UserHandle.USER_CURRENT_OR_SELF);
2794 if (auto != 0) {
2795 Settings.System.putIntForUser(mContext.getContentResolver(),
2796 Settings.System.SCREEN_BRIGHTNESS_MODE,
2797 Settings.System.SCREEN_BRIGHTNESS_MODE_MANUAL,
2798 UserHandle.USER_CURRENT_OR_SELF);
2799 }
2800
2801 int min = mPowerManager.getMinimumScreenBrightnessSetting();
2802 int max = mPowerManager.getMaximumScreenBrightnessSetting();
2803 int step = (max - min + BRIGHTNESS_STEPS - 1) / BRIGHTNESS_STEPS * direction;
2804 int brightness = Settings.System.getIntForUser(mContext.getContentResolver(),
2805 Settings.System.SCREEN_BRIGHTNESS,
2806 mPowerManager.getDefaultScreenBrightnessSetting(),
2807 UserHandle.USER_CURRENT_OR_SELF);
2808 brightness += step;
2809 // Make sure we don't go beyond the limits.
2810 brightness = Math.min(max, brightness);
2811 brightness = Math.max(min, brightness);
2812
2813 Settings.System.putIntForUser(mContext.getContentResolver(),
2814 Settings.System.SCREEN_BRIGHTNESS, brightness,
2815 UserHandle.USER_CURRENT_OR_SELF);
Bart Sears8b1c27c2015-03-18 23:51:02 +00002816 startActivityAsUser(new Intent(Intent.ACTION_SHOW_BRIGHTNESS_DIALOG),
Alan Viverette5a399492014-07-14 16:19:38 -07002817 UserHandle.CURRENT_OR_SELF);
Michael Wrightb854e242013-02-05 17:54:02 -08002818 }
2819 return -1;
Michael Wrightce0c13a2014-07-30 10:49:21 -07002820 } else if (KeyEvent.isMetaKey(keyCode)) {
Michael Wright6a62e552014-06-03 19:19:48 -07002821 if (down) {
2822 mPendingMetaAction = true;
2823 } else if (mPendingMetaAction) {
Tim Kilbourn0e5f1102015-06-05 16:18:09 -07002824 launchAssistAction(Intent.EXTRA_ASSIST_INPUT_HINT_KEYBOARD, event.getDeviceId());
Michael Wright6a62e552014-06-03 19:19:48 -07002825 }
2826 return -1;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002827 }
Jeff Browncaab4d02010-12-09 22:13:41 -08002828
Jeff Brownc1fb48d2010-12-08 16:52:09 -08002829 // Shortcuts are invoked through Search+key, so intercept those here
Jeff Browncaab4d02010-12-09 22:13:41 -08002830 // Any printing key that is chorded with Search should be consumed
2831 // even if no shortcut was invoked. This prevents text from being
2832 // inadvertently inserted when using a keyboard that has built-in macro
2833 // shortcut keys (that emit Search+x) and some of them are not registered.
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002834 if (mSearchKeyShortcutPending) {
Jeff Browncaab4d02010-12-09 22:13:41 -08002835 final KeyCharacterMap kcm = event.getKeyCharacterMap();
2836 if (kcm.isPrintingKey(keyCode)) {
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002837 mConsumeSearchKeyUp = true;
2838 mSearchKeyShortcutPending = false;
Jeff Browncaab4d02010-12-09 22:13:41 -08002839 if (down && repeatCount == 0 && !keyguardOn) {
2840 Intent shortcutIntent = mShortcutManager.getIntent(kcm, keyCode, metaState);
2841 if (shortcutIntent != null) {
2842 shortcutIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
Jeff Brownf0a3cc52011-01-26 18:42:46 -08002843 try {
Bart Sears8b1c27c2015-03-18 23:51:02 +00002844 startActivityAsUser(shortcutIntent, UserHandle.CURRENT);
Jeff Brownf0a3cc52011-01-26 18:42:46 -08002845 } catch (ActivityNotFoundException ex) {
2846 Slog.w(TAG, "Dropping shortcut key combination because "
2847 + "the activity to which it is registered was not found: "
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002848 + "SEARCH+" + KeyEvent.keyCodeToString(keyCode), ex);
Jeff Brownf0a3cc52011-01-26 18:42:46 -08002849 }
Jeff Browncaab4d02010-12-09 22:13:41 -08002850 } else {
2851 Slog.i(TAG, "Dropping unregistered shortcut key combination: "
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002852 + "SEARCH+" + KeyEvent.keyCodeToString(keyCode));
Jeff Brown49ed71d2010-12-06 17:13:33 -08002853 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002854 }
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002855 return -1;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002856 }
2857 }
2858
Jeff Brown68b909d2011-12-07 16:36:01 -08002859 // Invoke shortcuts using Meta.
Jeff Brown602ab322012-05-16 13:33:47 -07002860 if (down && repeatCount == 0 && !keyguardOn
Jeff Brown68b909d2011-12-07 16:36:01 -08002861 && (metaState & KeyEvent.META_META_ON) != 0) {
2862 final KeyCharacterMap kcm = event.getKeyCharacterMap();
Jeff Brown602ab322012-05-16 13:33:47 -07002863 if (kcm.isPrintingKey(keyCode)) {
2864 Intent shortcutIntent = mShortcutManager.getIntent(kcm, keyCode,
2865 metaState & ~(KeyEvent.META_META_ON
2866 | KeyEvent.META_META_LEFT_ON | KeyEvent.META_META_RIGHT_ON));
2867 if (shortcutIntent != null) {
2868 shortcutIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
2869 try {
Bart Sears8b1c27c2015-03-18 23:51:02 +00002870 startActivityAsUser(shortcutIntent, UserHandle.CURRENT);
Jeff Brown602ab322012-05-16 13:33:47 -07002871 } catch (ActivityNotFoundException ex) {
2872 Slog.w(TAG, "Dropping shortcut key combination because "
2873 + "the activity to which it is registered was not found: "
2874 + "META+" + KeyEvent.keyCodeToString(keyCode), ex);
2875 }
2876 return -1;
Jeff Brown68b909d2011-12-07 16:36:01 -08002877 }
Jeff Brown68b909d2011-12-07 16:36:01 -08002878 }
2879 }
2880
Jeff Brown6651a632011-11-28 12:59:11 -08002881 // Handle application launch keys.
Jeff Brown602ab322012-05-16 13:33:47 -07002882 if (down && repeatCount == 0 && !keyguardOn) {
Jeff Brown6651a632011-11-28 12:59:11 -08002883 String category = sApplicationLaunchKeyCategories.get(keyCode);
2884 if (category != null) {
Dianne Hackbornf5b86712011-12-05 17:42:41 -08002885 Intent intent = Intent.makeMainSelectorActivity(Intent.ACTION_MAIN, category);
Jeff Brown6651a632011-11-28 12:59:11 -08002886 intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
2887 try {
Bart Sears8b1c27c2015-03-18 23:51:02 +00002888 startActivityAsUser(intent, UserHandle.CURRENT);
Jeff Brown6651a632011-11-28 12:59:11 -08002889 } catch (ActivityNotFoundException ex) {
2890 Slog.w(TAG, "Dropping application launch key because "
2891 + "the activity to which it is registered was not found: "
2892 + "keyCode=" + keyCode + ", category=" + category, ex);
2893 }
Jeff Brown68b909d2011-12-07 16:36:01 -08002894 return -1;
Jeff Brown6651a632011-11-28 12:59:11 -08002895 }
2896 }
2897
Michael Wright61c46752014-08-21 16:57:33 -07002898 // Display task switcher for ALT-TAB.
Jeff Brown68b909d2011-12-07 16:36:01 -08002899 if (down && repeatCount == 0 && keyCode == KeyEvent.KEYCODE_TAB) {
Winson Chung1e8d71b2014-05-16 17:05:22 -07002900 if (mRecentAppsHeldModifiers == 0 && !keyguardOn) {
Jeff Brown68b909d2011-12-07 16:36:01 -08002901 final int shiftlessModifiers = event.getModifiers() & ~KeyEvent.META_SHIFT_MASK;
Michael Wright61c46752014-08-21 16:57:33 -07002902 if (KeyEvent.metaStateHasModifiers(shiftlessModifiers, KeyEvent.META_ALT_ON)) {
Winson Chung1e8d71b2014-05-16 17:05:22 -07002903 mRecentAppsHeldModifiers = shiftlessModifiers;
2904 showRecentApps(true);
Jeff Brown68b909d2011-12-07 16:36:01 -08002905 return -1;
2906 }
2907 }
Winson Chung1e8d71b2014-05-16 17:05:22 -07002908 } else if (!down && mRecentAppsHeldModifiers != 0
2909 && (metaState & mRecentAppsHeldModifiers) == 0) {
2910 mRecentAppsHeldModifiers = 0;
Winson Chungcdcd4872014-08-05 18:00:13 -07002911 hideRecentApps(true, false);
Jeff Brown68b909d2011-12-07 16:36:01 -08002912 }
2913
Jeff Browncf39bdf2012-05-18 14:41:19 -07002914 // Handle keyboard language switching.
2915 if (down && repeatCount == 0
2916 && (keyCode == KeyEvent.KEYCODE_LANGUAGE_SWITCH
2917 || (keyCode == KeyEvent.KEYCODE_SPACE
2918 && (metaState & KeyEvent.META_CTRL_MASK) != 0))) {
2919 int direction = (metaState & KeyEvent.META_SHIFT_MASK) != 0 ? -1 : 1;
2920 mWindowManagerFuncs.switchKeyboardLayout(event.getDeviceId(), direction);
2921 return -1;
2922 }
2923 if (mLanguageSwitchKeyPressed && !down
2924 && (keyCode == KeyEvent.KEYCODE_LANGUAGE_SWITCH
2925 || keyCode == KeyEvent.KEYCODE_SPACE)) {
2926 mLanguageSwitchKeyPressed = false;
2927 return -1;
2928 }
2929
Jeff Brown13f00f02014-10-31 14:45:50 -07002930 if (isValidGlobalKey(keyCode)
2931 && mGlobalKeyManager.handleGlobalKey(mContext, keyCode, event)) {
Justin Kohd378ad72013-04-01 12:18:26 -07002932 return -1;
2933 }
2934
Michael Wright6a62e552014-06-03 19:19:48 -07002935 // Reserve all the META modifier combos for system behavior
Michael Wrightce0c13a2014-07-30 10:49:21 -07002936 if ((metaState & KeyEvent.META_META_ON) != 0) {
Michael Wright6a62e552014-06-03 19:19:48 -07002937 return -1;
2938 }
2939
Jeff Brown68b909d2011-12-07 16:36:01 -08002940 // Let the application handle the key.
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002941 return 0;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002942 }
2943
Jeff Brown3915bb82010-11-05 15:02:16 -07002944 /** {@inheritDoc} */
2945 @Override
Jeff Brown49ed71d2010-12-06 17:13:33 -08002946 public KeyEvent dispatchUnhandledKey(WindowState win, KeyEvent event, int policyFlags) {
Jeff Brown54875002011-04-06 15:33:01 -07002947 // Note: This method is only called if the initial down was unhandled.
Jeff Brown40013652012-05-16 21:22:36 -07002948 if (DEBUG_INPUT) {
Jeff Brown1f245102010-11-18 20:53:46 -08002949 Slog.d(TAG, "Unhandled key: win=" + win + ", action=" + event.getAction()
2950 + ", flags=" + event.getFlags()
2951 + ", keyCode=" + event.getKeyCode()
2952 + ", scanCode=" + event.getScanCode()
2953 + ", metaState=" + event.getMetaState()
2954 + ", repeatCount=" + event.getRepeatCount()
2955 + ", policyFlags=" + policyFlags);
Jeff Brown3915bb82010-11-05 15:02:16 -07002956 }
Jeff Brown49ed71d2010-12-06 17:13:33 -08002957
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002958 KeyEvent fallbackEvent = null;
Jeff Brown49ed71d2010-12-06 17:13:33 -08002959 if ((event.getFlags() & KeyEvent.FLAG_FALLBACK) == 0) {
2960 final KeyCharacterMap kcm = event.getKeyCharacterMap();
Jeff Brownc1fb48d2010-12-08 16:52:09 -08002961 final int keyCode = event.getKeyCode();
2962 final int metaState = event.getMetaState();
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002963 final boolean initialDown = event.getAction() == KeyEvent.ACTION_DOWN
2964 && event.getRepeatCount() == 0;
Jeff Brown49ed71d2010-12-06 17:13:33 -08002965
Jeff Brown54875002011-04-06 15:33:01 -07002966 // Check for fallback actions specified by the key character map.
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002967 final FallbackAction fallbackAction;
2968 if (initialDown) {
2969 fallbackAction = kcm.getFallbackAction(keyCode, metaState);
2970 } else {
2971 fallbackAction = mFallbackActions.get(keyCode);
2972 }
2973
2974 if (fallbackAction != null) {
Jeff Brown40013652012-05-16 21:22:36 -07002975 if (DEBUG_INPUT) {
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002976 Slog.d(TAG, "Fallback: keyCode=" + fallbackAction.keyCode
2977 + " metaState=" + Integer.toHexString(fallbackAction.metaState));
Jeff Brown49ed71d2010-12-06 17:13:33 -08002978 }
2979
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002980 final int flags = event.getFlags() | KeyEvent.FLAG_FALLBACK;
2981 fallbackEvent = KeyEvent.obtain(
Jeff Brown49ed71d2010-12-06 17:13:33 -08002982 event.getDownTime(), event.getEventTime(),
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002983 event.getAction(), fallbackAction.keyCode,
2984 event.getRepeatCount(), fallbackAction.metaState,
Jeff Brown49ed71d2010-12-06 17:13:33 -08002985 event.getDeviceId(), event.getScanCode(),
2986 flags, event.getSource(), null);
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002987
2988 if (!interceptFallback(win, fallbackEvent, policyFlags)) {
2989 fallbackEvent.recycle();
2990 fallbackEvent = null;
Jeff Brown49ed71d2010-12-06 17:13:33 -08002991 }
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002992
2993 if (initialDown) {
2994 mFallbackActions.put(keyCode, fallbackAction);
2995 } else if (event.getAction() == KeyEvent.ACTION_UP) {
2996 mFallbackActions.remove(keyCode);
2997 fallbackAction.recycle();
2998 }
Jeff Brown49ed71d2010-12-06 17:13:33 -08002999 }
3000 }
3001
Jeff Brown40013652012-05-16 21:22:36 -07003002 if (DEBUG_INPUT) {
Jeff Brownfd23e3e2012-05-09 13:34:28 -07003003 if (fallbackEvent == null) {
3004 Slog.d(TAG, "No fallback.");
3005 } else {
3006 Slog.d(TAG, "Performing fallback: " + fallbackEvent);
3007 }
Jeff Brown49ed71d2010-12-06 17:13:33 -08003008 }
Jeff Brownfd23e3e2012-05-09 13:34:28 -07003009 return fallbackEvent;
Jeff Brown3915bb82010-11-05 15:02:16 -07003010 }
3011
Jeff Brownfd23e3e2012-05-09 13:34:28 -07003012 private boolean interceptFallback(WindowState win, KeyEvent fallbackEvent, int policyFlags) {
Jeff Brown037c33e2014-04-09 00:31:55 -07003013 int actions = interceptKeyBeforeQueueing(fallbackEvent, policyFlags);
Jeff Brownfd23e3e2012-05-09 13:34:28 -07003014 if ((actions & ACTION_PASS_TO_USER) != 0) {
3015 long delayMillis = interceptKeyBeforeDispatching(
3016 win, fallbackEvent, policyFlags);
3017 if (delayMillis == 0) {
3018 return true;
3019 }
3020 }
3021 return false;
Jeff Brown6f2fba42011-02-19 01:08:02 -08003022 }
3023
Jeff Brownde7a8ea2012-06-13 18:28:57 -07003024 private void launchAssistLongPressAction() {
3025 performHapticFeedbackLw(null, HapticFeedbackConstants.LONG_PRESS, false);
3026 sendCloseSystemWindows(SYSTEM_DIALOG_REASON_ASSIST);
3027
3028 // launch the search activity
3029 Intent intent = new Intent(Intent.ACTION_SEARCH_LONG_PRESS);
3030 intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
3031 try {
RoboErik8a2cfc32014-05-16 11:19:38 -07003032 // TODO: This only stops the factory-installed search manager.
Jim Miller45308b12012-06-18 19:23:39 -07003033 // Need to formalize an API to handle others
Jeff Brownde7a8ea2012-06-13 18:28:57 -07003034 SearchManager searchManager = getSearchManager();
3035 if (searchManager != null) {
3036 searchManager.stopSearch();
3037 }
Bart Sears8b1c27c2015-03-18 23:51:02 +00003038 startActivityAsUser(intent, UserHandle.CURRENT);
Jeff Brownde7a8ea2012-06-13 18:28:57 -07003039 } catch (ActivityNotFoundException e) {
3040 Slog.w(TAG, "No activity to handle assist long press action.", e);
3041 }
3042 }
3043
3044 private void launchAssistAction() {
Tim Kilbourn0e5f1102015-06-05 16:18:09 -07003045 launchAssistAction(null, Integer.MIN_VALUE);
Michael Wright8ab940a2014-09-01 11:01:27 -07003046 }
3047
3048 private void launchAssistAction(String hint) {
Tim Kilbourn0e5f1102015-06-05 16:18:09 -07003049 launchAssistAction(hint, Integer.MIN_VALUE);
3050 }
3051
3052 private void launchAssistAction(String hint, int deviceId) {
Jeff Brownde7a8ea2012-06-13 18:28:57 -07003053 sendCloseSystemWindows(SYSTEM_DIALOG_REASON_ASSIST);
Tim Kilbourn0e5f1102015-06-05 16:18:09 -07003054 Bundle args = null;
3055 if (deviceId > Integer.MIN_VALUE) {
3056 args = new Bundle();
3057 args.putInt(Intent.EXTRA_ASSIST_INPUT_DEVICE_ID, deviceId);
Jeff Brownde7a8ea2012-06-13 18:28:57 -07003058 }
Tim Kilbourn0e5f1102015-06-05 16:18:09 -07003059 ((SearchManager) mContext.getSystemService(Context.SEARCH_SERVICE))
3060 .launchAssistAction(hint, UserHandle.myUserId(), args);
Jeff Brownde7a8ea2012-06-13 18:28:57 -07003061 }
3062
Bart Sears8b1c27c2015-03-18 23:51:02 +00003063 private void startActivityAsUser(Intent intent, UserHandle handle) {
3064 if (isUserSetupComplete()) {
3065 mContext.startActivityAsUser(intent, handle);
3066 } else {
3067 Slog.i(TAG, "Not starting activity because user setup is in progress: " + intent);
3068 }
3069 }
3070
Jeff Brownde7a8ea2012-06-13 18:28:57 -07003071 private SearchManager getSearchManager() {
3072 if (mSearchManager == null) {
3073 mSearchManager = (SearchManager) mContext.getSystemService(Context.SEARCH_SERVICE);
3074 }
3075 return mSearchManager;
3076 }
3077
Jeff Browncaca8812013-05-09 13:34:33 -07003078 private void preloadRecentApps() {
3079 mPreloadedRecentApps = true;
3080 try {
3081 IStatusBarService statusbar = getStatusBarService();
3082 if (statusbar != null) {
3083 statusbar.preloadRecentApps();
3084 }
3085 } catch (RemoteException e) {
3086 Slog.e(TAG, "RemoteException when preloading recent apps", e);
3087 // re-acquire status bar service next time it is needed.
3088 mStatusBarService = null;
3089 }
3090 }
3091
3092 private void cancelPreloadRecentApps() {
3093 if (mPreloadedRecentApps) {
3094 mPreloadedRecentApps = false;
3095 try {
3096 IStatusBarService statusbar = getStatusBarService();
3097 if (statusbar != null) {
3098 statusbar.cancelPreloadRecentApps();
3099 }
3100 } catch (RemoteException e) {
Winson Chung1e8d71b2014-05-16 17:05:22 -07003101 Slog.e(TAG, "RemoteException when cancelling recent apps preload", e);
Jeff Browncaca8812013-05-09 13:34:33 -07003102 // re-acquire status bar service next time it is needed.
3103 mStatusBarService = null;
3104 }
3105 }
3106 }
3107
3108 private void toggleRecentApps() {
3109 mPreloadedRecentApps = false; // preloading no longer needs to be canceled
Jeff Browncaca8812013-05-09 13:34:33 -07003110 try {
3111 IStatusBarService statusbar = getStatusBarService();
3112 if (statusbar != null) {
3113 statusbar.toggleRecentApps();
3114 }
3115 } catch (RemoteException e) {
Winson Chung1e8d71b2014-05-16 17:05:22 -07003116 Slog.e(TAG, "RemoteException when toggling recent apps", e);
3117 // re-acquire status bar service next time it is needed.
3118 mStatusBarService = null;
3119 }
3120 }
3121
Craig Mautner84984fa2014-06-19 11:19:20 -07003122 @Override
3123 public void showRecentApps() {
3124 mHandler.removeMessages(MSG_DISPATCH_SHOW_RECENTS);
3125 mHandler.sendEmptyMessage(MSG_DISPATCH_SHOW_RECENTS);
3126 }
3127
Winson Chung1e8d71b2014-05-16 17:05:22 -07003128 private void showRecentApps(boolean triggeredFromAltTab) {
3129 mPreloadedRecentApps = false; // preloading no longer needs to be canceled
3130 try {
3131 IStatusBarService statusbar = getStatusBarService();
3132 if (statusbar != null) {
3133 statusbar.showRecentApps(triggeredFromAltTab);
3134 }
3135 } catch (RemoteException e) {
Jeff Browncaca8812013-05-09 13:34:33 -07003136 Slog.e(TAG, "RemoteException when showing recent apps", e);
3137 // re-acquire status bar service next time it is needed.
3138 mStatusBarService = null;
3139 }
3140 }
3141
Winson Chungcdcd4872014-08-05 18:00:13 -07003142 private void hideRecentApps(boolean triggeredFromAltTab, boolean triggeredFromHome) {
Winson Chung1e8d71b2014-05-16 17:05:22 -07003143 mPreloadedRecentApps = false; // preloading no longer needs to be canceled
3144 try {
3145 IStatusBarService statusbar = getStatusBarService();
3146 if (statusbar != null) {
Winson Chungcdcd4872014-08-05 18:00:13 -07003147 statusbar.hideRecentApps(triggeredFromAltTab, triggeredFromHome);
Winson Chung1e8d71b2014-05-16 17:05:22 -07003148 }
3149 } catch (RemoteException e) {
3150 Slog.e(TAG, "RemoteException when closing recent apps", e);
3151 // re-acquire status bar service next time it is needed.
3152 mStatusBarService = null;
3153 }
3154 }
3155
Filip Gruszczynskia483a1d2015-03-17 19:06:58 +00003156 void launchHomeFromHotKey() {
Bryce Lee662ed802015-04-10 20:11:39 +00003157 launchHomeFromHotKey(true /* awakenFromDreams */, true /*respectKeyguard*/);
Filip Gruszczynskia483a1d2015-03-17 19:06:58 +00003158 }
3159
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003160 /**
3161 * A home key -> launch home action was detected. Take the appropriate action
3162 * given the situation with the keyguard.
3163 */
Bryce Lee662ed802015-04-10 20:11:39 +00003164 void launchHomeFromHotKey(final boolean awakenFromDreams, final boolean respectKeyguard) {
3165 if (respectKeyguard) {
3166 if (isKeyguardShowingAndNotOccluded()) {
3167 // don't launch home if keyguard showing
3168 return;
3169 }
3170
3171 if (!mHideLockScreen && mKeyguardDelegate.isInputRestricted()) {
3172 // when in keyguard restricted mode, must first verify unlock
3173 // before launching home
3174 mKeyguardDelegate.verifyUnlock(new OnKeyguardExitResult() {
3175 @Override
3176 public void onKeyguardExitResult(boolean success) {
3177 if (success) {
3178 try {
3179 ActivityManagerNative.getDefault().stopAppSwitches();
3180 } catch (RemoteException e) {
3181 }
3182 sendCloseSystemWindows(SYSTEM_DIALOG_REASON_HOME_KEY);
3183 startDockOrHome(true /*fromHomeKey*/, awakenFromDreams);
Dianne Hackborn256dd3b2009-05-19 18:51:21 -07003184 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003185 }
Bryce Lee662ed802015-04-10 20:11:39 +00003186 });
3187 return;
3188 }
3189 }
3190
3191 // no keyguard stuff to worry about, just launch home!
3192 try {
3193 ActivityManagerNative.getDefault().stopAppSwitches();
3194 } catch (RemoteException e) {
3195 }
3196 if (mRecentsVisible) {
3197 // Hide Recents and notify it to launch Home
3198 if (awakenFromDreams) {
3199 awakenDreams();
3200 }
3201 sendCloseSystemWindows(SYSTEM_DIALOG_REASON_HOME_KEY);
3202 hideRecentApps(false, true);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003203 } else {
Bryce Lee662ed802015-04-10 20:11:39 +00003204 // Otherwise, just launch Home
3205 sendCloseSystemWindows(SYSTEM_DIALOG_REASON_HOME_KEY);
3206 startDockOrHome(true /*fromHomeKey*/, awakenFromDreams);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003207 }
3208 }
3209
John Spurlock04db1762013-05-13 12:46:41 -04003210 private final Runnable mClearHideNavigationFlag = new Runnable() {
3211 @Override
3212 public void run() {
3213 synchronized (mWindowManagerFuncs.getWindowManagerLock()) {
3214 // Clear flags.
3215 mForceClearedSystemUiFlags &=
3216 ~View.SYSTEM_UI_FLAG_HIDE_NAVIGATION;
3217 }
3218 mWindowManagerFuncs.reevaluateStatusBarVisibility();
Dianne Hackborne26ab702011-10-16 13:21:33 -07003219 }
3220 };
3221
3222 /**
3223 * Input handler used while nav bar is hidden. Captures any touch on the screen,
3224 * to determine when the nav bar should be shown and prevent applications from
3225 * receiving those touches.
3226 */
Jeff Brown32cbc38552011-12-01 14:01:49 -08003227 final class HideNavInputEventReceiver extends InputEventReceiver {
3228 public HideNavInputEventReceiver(InputChannel inputChannel, Looper looper) {
3229 super(inputChannel, looper);
3230 }
3231
Dianne Hackborndf89e652011-10-06 22:35:11 -07003232 @Override
Jeff Brown32cbc38552011-12-01 14:01:49 -08003233 public void onInputEvent(InputEvent event) {
Dianne Hackborndf89e652011-10-06 22:35:11 -07003234 boolean handled = false;
3235 try {
Jeff Brown4952dfd2011-11-30 19:23:22 -08003236 if (event instanceof MotionEvent
3237 && (event.getSource() & InputDevice.SOURCE_CLASS_POINTER) != 0) {
3238 final MotionEvent motionEvent = (MotionEvent)event;
3239 if (motionEvent.getAction() == MotionEvent.ACTION_DOWN) {
Dianne Hackborndf89e652011-10-06 22:35:11 -07003240 // When the user taps down, we re-show the nav bar.
3241 boolean changed = false;
John Spurlock04db1762013-05-13 12:46:41 -04003242 synchronized (mWindowManagerFuncs.getWindowManagerLock()) {
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07003243 // Any user activity always causes us to show the
3244 // navigation controls, if they had been hidden.
3245 // We also clear the low profile and only content
3246 // flags so that tapping on the screen will atomically
3247 // restore all currently hidden screen decorations.
3248 int newVal = mResettingSystemUiFlags |
3249 View.SYSTEM_UI_FLAG_HIDE_NAVIGATION |
3250 View.SYSTEM_UI_FLAG_LOW_PROFILE |
3251 View.SYSTEM_UI_FLAG_FULLSCREEN;
Dianne Hackborne26ab702011-10-16 13:21:33 -07003252 if (mResettingSystemUiFlags != newVal) {
3253 mResettingSystemUiFlags = newVal;
Dianne Hackborndf89e652011-10-06 22:35:11 -07003254 changed = true;
3255 }
Dianne Hackborne26ab702011-10-16 13:21:33 -07003256 // We don't allow the system's nav bar to be hidden
3257 // again for 1 second, to prevent applications from
3258 // spamming us and keeping it from being shown.
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07003259 newVal = mForceClearedSystemUiFlags |
3260 View.SYSTEM_UI_FLAG_HIDE_NAVIGATION;
Dianne Hackborne26ab702011-10-16 13:21:33 -07003261 if (mForceClearedSystemUiFlags != newVal) {
3262 mForceClearedSystemUiFlags = newVal;
3263 changed = true;
John Spurlock04db1762013-05-13 12:46:41 -04003264 mHandler.postDelayed(mClearHideNavigationFlag, 1000);
Dianne Hackborne26ab702011-10-16 13:21:33 -07003265 }
Dianne Hackborndf89e652011-10-06 22:35:11 -07003266 }
3267 if (changed) {
3268 mWindowManagerFuncs.reevaluateStatusBarVisibility();
3269 }
3270 }
3271 }
3272 } finally {
Jeff Brown32cbc38552011-12-01 14:01:49 -08003273 finishInputEvent(event, handled);
Dianne Hackborndf89e652011-10-06 22:35:11 -07003274 }
3275 }
Jeff Brown32cbc38552011-12-01 14:01:49 -08003276 }
3277 final InputEventReceiver.Factory mHideNavInputEventReceiverFactory =
3278 new InputEventReceiver.Factory() {
3279 @Override
3280 public InputEventReceiver createInputEventReceiver(
3281 InputChannel inputChannel, Looper looper) {
3282 return new HideNavInputEventReceiver(inputChannel, looper);
3283 }
Dianne Hackborndf89e652011-10-06 22:35:11 -07003284 };
3285
3286 @Override
3287 public int adjustSystemUiVisibilityLw(int visibility) {
John Spurlock5b9145b2013-08-20 15:13:47 -04003288 mStatusBarController.adjustSystemUiVisibilityLw(mLastSystemUiFlags, visibility);
3289 mNavigationBarController.adjustSystemUiVisibilityLw(mLastSystemUiFlags, visibility);
Winson Chungd42a6cf2014-06-03 16:24:04 -07003290 mRecentsVisible = (visibility & View.RECENT_APPS_VISIBLE) > 0;
John Spurlock27735a42013-08-14 17:57:38 -04003291
Dianne Hackborndf89e652011-10-06 22:35:11 -07003292 // Reset any bits in mForceClearingStatusBarVisibility that
3293 // are now clear.
Dianne Hackborne26ab702011-10-16 13:21:33 -07003294 mResettingSystemUiFlags &= visibility;
Dianne Hackborndf89e652011-10-06 22:35:11 -07003295 // Clear any bits in the new visibility that are currently being
3296 // force cleared, before reporting it.
Dianne Hackborne26ab702011-10-16 13:21:33 -07003297 return visibility & ~mResettingSystemUiFlags
3298 & ~mForceClearedSystemUiFlags;
Dianne Hackborndf89e652011-10-06 22:35:11 -07003299 }
3300
Craig Mautner69b08182012-09-05 13:07:13 -07003301 @Override
Adrian Roos37d7a682014-11-06 18:15:16 +01003302 public void getInsetHintLw(WindowManager.LayoutParams attrs, Rect outContentInsets,
3303 Rect outStableInsets) {
John Spurlockc6d1c602014-01-17 15:22:06 -05003304 final int fl = PolicyControl.getWindowFlags(null, attrs);
John Spurlock1db8b682014-02-18 11:18:59 -05003305 final int sysuiVis = PolicyControl.getSystemUiVisibility(null, attrs);
3306 final int systemUiVisibility = (sysuiVis | attrs.subtreeSystemUiVisibility);
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07003307
Dianne Hackborn5b5cc4d2012-05-16 13:15:00 -07003308 if ((fl & (FLAG_LAYOUT_IN_SCREEN | FLAG_LAYOUT_INSET_DECOR))
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003309 == (FLAG_LAYOUT_IN_SCREEN | FLAG_LAYOUT_INSET_DECOR)) {
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07003310 int availRight, availBottom;
Alan Viverette5a0f4ec2013-10-07 15:10:29 -07003311 if (canHideNavigationBar() &&
Dianne Hackborn5b5cc4d2012-05-16 13:15:00 -07003312 (systemUiVisibility & View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION) != 0) {
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07003313 availRight = mUnrestrictedScreenLeft + mUnrestrictedScreenWidth;
3314 availBottom = mUnrestrictedScreenTop + mUnrestrictedScreenHeight;
3315 } else {
3316 availRight = mRestrictedScreenLeft + mRestrictedScreenWidth;
3317 availBottom = mRestrictedScreenTop + mRestrictedScreenHeight;
3318 }
Dianne Hackborn5b5cc4d2012-05-16 13:15:00 -07003319 if ((systemUiVisibility & View.SYSTEM_UI_FLAG_LAYOUT_STABLE) != 0) {
3320 if ((fl & FLAG_FULLSCREEN) != 0) {
Adrian Roos37d7a682014-11-06 18:15:16 +01003321 outContentInsets.set(mStableFullscreenLeft, mStableFullscreenTop,
Dianne Hackborn5b5cc4d2012-05-16 13:15:00 -07003322 availRight - mStableFullscreenRight,
3323 availBottom - mStableFullscreenBottom);
3324 } else {
Adrian Roos37d7a682014-11-06 18:15:16 +01003325 outContentInsets.set(mStableLeft, mStableTop,
Dianne Hackborn5b5cc4d2012-05-16 13:15:00 -07003326 availRight - mStableRight, availBottom - mStableBottom);
3327 }
Dianne Hackbornc652de82013-02-15 16:32:56 -08003328 } else if ((fl & FLAG_FULLSCREEN) != 0 || (fl & FLAG_LAYOUT_IN_OVERSCAN) != 0) {
Adrian Roos37d7a682014-11-06 18:15:16 +01003329 outContentInsets.setEmpty();
Dianne Hackborn5b5cc4d2012-05-16 13:15:00 -07003330 } else if ((systemUiVisibility & (View.SYSTEM_UI_FLAG_FULLSCREEN
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07003331 | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN)) == 0) {
Adrian Roos37d7a682014-11-06 18:15:16 +01003332 outContentInsets.set(mCurLeft, mCurTop,
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07003333 availRight - mCurRight, availBottom - mCurBottom);
3334 } else {
Adrian Roos37d7a682014-11-06 18:15:16 +01003335 outContentInsets.set(mCurLeft, mCurTop,
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07003336 availRight - mCurRight, availBottom - mCurBottom);
3337 }
Adrian Roos37d7a682014-11-06 18:15:16 +01003338
3339 outStableInsets.set(mStableLeft, mStableTop,
3340 availRight - mStableRight, availBottom - mStableBottom);
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07003341 return;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003342 }
Adrian Roos37d7a682014-11-06 18:15:16 +01003343 outContentInsets.setEmpty();
3344 outStableInsets.setEmpty();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003345 }
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07003346
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003347 /** {@inheritDoc} */
Craig Mautner69b08182012-09-05 13:07:13 -07003348 @Override
3349 public void beginLayoutLw(boolean isDefaultDisplay, int displayWidth, int displayHeight,
3350 int displayRotation) {
Dianne Hackbornc652de82013-02-15 16:32:56 -08003351 final int overscanLeft, overscanTop, overscanRight, overscanBottom;
3352 if (isDefaultDisplay) {
3353 switch (displayRotation) {
3354 case Surface.ROTATION_90:
3355 overscanLeft = mOverscanTop;
3356 overscanTop = mOverscanRight;
3357 overscanRight = mOverscanBottom;
3358 overscanBottom = mOverscanLeft;
3359 break;
3360 case Surface.ROTATION_180:
3361 overscanLeft = mOverscanRight;
3362 overscanTop = mOverscanBottom;
3363 overscanRight = mOverscanLeft;
3364 overscanBottom = mOverscanTop;
3365 break;
3366 case Surface.ROTATION_270:
3367 overscanLeft = mOverscanBottom;
3368 overscanTop = mOverscanLeft;
3369 overscanRight = mOverscanTop;
3370 overscanBottom = mOverscanRight;
3371 break;
3372 default:
3373 overscanLeft = mOverscanLeft;
3374 overscanTop = mOverscanTop;
3375 overscanRight = mOverscanRight;
3376 overscanBottom = mOverscanBottom;
3377 break;
3378 }
3379 } else {
3380 overscanLeft = 0;
3381 overscanTop = 0;
3382 overscanRight = 0;
3383 overscanBottom = 0;
3384 }
Dianne Hackborn313440842013-02-19 19:22:59 -08003385 mOverscanScreenLeft = mRestrictedOverscanScreenLeft = 0;
3386 mOverscanScreenTop = mRestrictedOverscanScreenTop = 0;
3387 mOverscanScreenWidth = mRestrictedOverscanScreenWidth = displayWidth;
3388 mOverscanScreenHeight = mRestrictedOverscanScreenHeight = displayHeight;
Dianne Hackbornc652de82013-02-15 16:32:56 -08003389 mSystemLeft = 0;
3390 mSystemTop = 0;
3391 mSystemRight = displayWidth;
3392 mSystemBottom = displayHeight;
3393 mUnrestrictedScreenLeft = overscanLeft;
3394 mUnrestrictedScreenTop = overscanTop;
3395 mUnrestrictedScreenWidth = displayWidth - overscanLeft - overscanRight;
3396 mUnrestrictedScreenHeight = displayHeight - overscanTop - overscanBottom;
3397 mRestrictedScreenLeft = mUnrestrictedScreenLeft;
3398 mRestrictedScreenTop = mUnrestrictedScreenTop;
John Spurlockad3e6cb2013-04-30 08:47:43 -04003399 mRestrictedScreenWidth = mSystemGestures.screenWidth = mUnrestrictedScreenWidth;
3400 mRestrictedScreenHeight = mSystemGestures.screenHeight = mUnrestrictedScreenHeight;
Dianne Hackborne30e02f2014-05-27 18:24:45 -07003401 mDockLeft = mContentLeft = mVoiceContentLeft = mStableLeft = mStableFullscreenLeft
Dianne Hackbornc652de82013-02-15 16:32:56 -08003402 = mCurLeft = mUnrestrictedScreenLeft;
Dianne Hackborne30e02f2014-05-27 18:24:45 -07003403 mDockTop = mContentTop = mVoiceContentTop = mStableTop = mStableFullscreenTop
Dianne Hackbornc652de82013-02-15 16:32:56 -08003404 = mCurTop = mUnrestrictedScreenTop;
Dianne Hackborne30e02f2014-05-27 18:24:45 -07003405 mDockRight = mContentRight = mVoiceContentRight = mStableRight = mStableFullscreenRight
Dianne Hackbornc652de82013-02-15 16:32:56 -08003406 = mCurRight = displayWidth - overscanRight;
Dianne Hackborne30e02f2014-05-27 18:24:45 -07003407 mDockBottom = mContentBottom = mVoiceContentBottom = mStableBottom = mStableFullscreenBottom
Dianne Hackbornc652de82013-02-15 16:32:56 -08003408 = mCurBottom = displayHeight - overscanBottom;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003409 mDockLayer = 0x10000000;
Dianne Hackborn5c58de32012-04-28 19:52:37 -07003410 mStatusBarLayer = -1;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003411
Daniel Sandler8956dbb2011-04-22 07:55:02 -04003412 // start with the current dock rect, which will be (0,0,displayWidth,displayHeight)
3413 final Rect pf = mTmpParentFrame;
3414 final Rect df = mTmpDisplayFrame;
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003415 final Rect of = mTmpOverscanFrame;
Daniel Sandler8956dbb2011-04-22 07:55:02 -04003416 final Rect vf = mTmpVisibleFrame;
John Spurlock46646232013-09-30 22:32:42 -04003417 final Rect dcf = mTmpDecorFrame;
Filip Gruszczynski2217f612015-05-26 11:32:08 -07003418 final Rect osf = mTmpOutsetFrame;
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003419 pf.left = df.left = of.left = vf.left = mDockLeft;
3420 pf.top = df.top = of.top = vf.top = mDockTop;
3421 pf.right = df.right = of.right = vf.right = mDockRight;
3422 pf.bottom = df.bottom = of.bottom = vf.bottom = mDockBottom;
John Spurlock46646232013-09-30 22:32:42 -04003423 dcf.setEmpty(); // Decor frame N/A for system bars.
Daniel Sandler8956dbb2011-04-22 07:55:02 -04003424
Craig Mautner69b08182012-09-05 13:07:13 -07003425 if (isDefaultDisplay) {
3426 // For purposes of putting out fake window up to steal focus, we will
3427 // drive nav being hidden only by whether it is requested.
John Spurlocke1f366f2013-08-05 12:22:40 -04003428 final int sysui = mLastSystemUiFlags;
3429 boolean navVisible = (sysui & View.SYSTEM_UI_FLAG_HIDE_NAVIGATION) == 0;
Adrian Roosea562512014-05-05 13:33:03 +02003430 boolean navTranslucent = (sysui
3431 & (View.NAVIGATION_BAR_TRANSLUCENT | View.SYSTEM_UI_TRANSPARENT)) != 0;
John Spurlockf1a36642013-10-12 17:50:42 -04003432 boolean immersive = (sysui & View.SYSTEM_UI_FLAG_IMMERSIVE) != 0;
3433 boolean immersiveSticky = (sysui & View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY) != 0;
3434 boolean navAllowedHidden = immersive || immersiveSticky;
3435 navTranslucent &= !immersiveSticky; // transient trumps translucent
Adrian Roos4fb3ee32014-08-22 19:29:09 +02003436 boolean isKeyguardShowing = isStatusBarKeyguard() && !mHideLockScreen;
3437 if (!isKeyguardShowing) {
3438 navTranslucent &= areTranslucentBarsAllowed();
3439 }
Dianne Hackborne26ab702011-10-16 13:21:33 -07003440
Craig Mautner69b08182012-09-05 13:07:13 -07003441 // When the navigation bar isn't visible, we put up a fake
3442 // input window to catch all touch events. This way we can
3443 // detect when the user presses anywhere to bring back the nav
3444 // bar and ensure the application doesn't see the event.
John Spurlockf1a36642013-10-12 17:50:42 -04003445 if (navVisible || navAllowedHidden) {
Selim Cinekf83e8242015-05-19 18:08:14 -07003446 if (mInputConsumer != null) {
3447 mInputConsumer.dismiss();
3448 mInputConsumer = null;
Craig Mautner69b08182012-09-05 13:07:13 -07003449 }
Selim Cinekf83e8242015-05-19 18:08:14 -07003450 } else if (mInputConsumer == null) {
3451 mInputConsumer = mWindowManagerFuncs.addInputConsumer(mHandler.getLooper(),
3452 mHideNavInputEventReceiverFactory);
Dianne Hackborne26ab702011-10-16 13:21:33 -07003453 }
Dianne Hackborne26ab702011-10-16 13:21:33 -07003454
Craig Mautner69b08182012-09-05 13:07:13 -07003455 // For purposes of positioning and showing the nav bar, if we have
3456 // decided that it can't be hidden (because of the screen aspect ratio),
3457 // then take that into account.
Alan Viverette5a0f4ec2013-10-07 15:10:29 -07003458 navVisible |= !canHideNavigationBar();
Dianne Hackbornf87d1962012-04-04 12:48:24 -07003459
John Spurlockad3e6cb2013-04-30 08:47:43 -04003460 boolean updateSysUiVisibility = false;
Craig Mautner69b08182012-09-05 13:07:13 -07003461 if (mNavigationBar != null) {
John Spurlock27735a42013-08-14 17:57:38 -04003462 boolean transientNavBarShowing = mNavigationBarController.isTransientShowing();
Craig Mautner69b08182012-09-05 13:07:13 -07003463 // Force the navigation bar to its appropriate place and
3464 // size. We need to do this directly, instead of relying on
3465 // it to bubble up from the nav bar, because this needs to
3466 // change atomically with screen rotations.
3467 mNavigationBarOnBottom = (!mNavigationBarCanMove || displayWidth < displayHeight);
3468 if (mNavigationBarOnBottom) {
3469 // It's a system nav bar or a portrait screen; nav bar goes on bottom.
Dianne Hackbornc652de82013-02-15 16:32:56 -08003470 int top = displayHeight - overscanBottom
3471 - mNavigationBarHeightForRotation[displayRotation];
3472 mTmpNavigationFrame.set(0, top, displayWidth, displayHeight - overscanBottom);
Craig Mautner69b08182012-09-05 13:07:13 -07003473 mStableBottom = mStableFullscreenBottom = mTmpNavigationFrame.top;
John Spurlockf95b89a2013-10-10 22:10:42 -04003474 if (transientNavBarShowing) {
John Spurlock27735a42013-08-14 17:57:38 -04003475 mNavigationBarController.setBarShowingLw(true);
John Spurlockad3e6cb2013-04-30 08:47:43 -04003476 } else if (navVisible) {
John Spurlock27735a42013-08-14 17:57:38 -04003477 mNavigationBarController.setBarShowingLw(true);
Craig Mautner69b08182012-09-05 13:07:13 -07003478 mDockBottom = mTmpNavigationFrame.top;
Dianne Hackborn313440842013-02-19 19:22:59 -08003479 mRestrictedScreenHeight = mDockBottom - mRestrictedScreenTop;
3480 mRestrictedOverscanScreenHeight = mDockBottom - mRestrictedOverscanScreenTop;
Craig Mautner69b08182012-09-05 13:07:13 -07003481 } else {
3482 // We currently want to hide the navigation UI.
John Spurlock27735a42013-08-14 17:57:38 -04003483 mNavigationBarController.setBarShowingLw(false);
Craig Mautner69b08182012-09-05 13:07:13 -07003484 }
John Spurlockc6d1c602014-01-17 15:22:06 -05003485 if (navVisible && !navTranslucent && !navAllowedHidden
3486 && !mNavigationBar.isAnimatingLw()
John Spurlockbd957402013-10-03 11:38:39 -04003487 && !mNavigationBarController.wasRecentlyTranslucent()) {
John Spurlocke1f366f2013-08-05 12:22:40 -04003488 // If the opaque nav bar is currently requested to be visible,
Craig Mautner69b08182012-09-05 13:07:13 -07003489 // and not in the process of animating on or off, then
3490 // we can tell the app that it is covered by it.
3491 mSystemBottom = mTmpNavigationFrame.top;
3492 }
Dianne Hackbornf87d1962012-04-04 12:48:24 -07003493 } else {
Craig Mautner69b08182012-09-05 13:07:13 -07003494 // Landscape screen; nav bar goes to the right.
Dianne Hackbornc652de82013-02-15 16:32:56 -08003495 int left = displayWidth - overscanRight
3496 - mNavigationBarWidthForRotation[displayRotation];
3497 mTmpNavigationFrame.set(left, 0, displayWidth - overscanRight, displayHeight);
Craig Mautner69b08182012-09-05 13:07:13 -07003498 mStableRight = mStableFullscreenRight = mTmpNavigationFrame.left;
John Spurlockf95b89a2013-10-10 22:10:42 -04003499 if (transientNavBarShowing) {
John Spurlock27735a42013-08-14 17:57:38 -04003500 mNavigationBarController.setBarShowingLw(true);
John Spurlockad3e6cb2013-04-30 08:47:43 -04003501 } else if (navVisible) {
John Spurlock27735a42013-08-14 17:57:38 -04003502 mNavigationBarController.setBarShowingLw(true);
Craig Mautner69b08182012-09-05 13:07:13 -07003503 mDockRight = mTmpNavigationFrame.left;
Dianne Hackborn313440842013-02-19 19:22:59 -08003504 mRestrictedScreenWidth = mDockRight - mRestrictedScreenLeft;
3505 mRestrictedOverscanScreenWidth = mDockRight - mRestrictedOverscanScreenLeft;
Craig Mautner69b08182012-09-05 13:07:13 -07003506 } else {
3507 // We currently want to hide the navigation UI.
John Spurlock27735a42013-08-14 17:57:38 -04003508 mNavigationBarController.setBarShowingLw(false);
Craig Mautner69b08182012-09-05 13:07:13 -07003509 }
John Spurlockbd957402013-10-03 11:38:39 -04003510 if (navVisible && !navTranslucent && !mNavigationBar.isAnimatingLw()
3511 && !mNavigationBarController.wasRecentlyTranslucent()) {
Craig Mautner69b08182012-09-05 13:07:13 -07003512 // If the nav bar is currently requested to be visible,
3513 // and not in the process of animating on or off, then
3514 // we can tell the app that it is covered by it.
3515 mSystemRight = mTmpNavigationFrame.left;
3516 }
Dianne Hackbornf87d1962012-04-04 12:48:24 -07003517 }
Craig Mautner69b08182012-09-05 13:07:13 -07003518 // Make sure the content and current rectangles are updated to
3519 // account for the restrictions from the navigation bar.
Dianne Hackborne30e02f2014-05-27 18:24:45 -07003520 mContentTop = mVoiceContentTop = mCurTop = mDockTop;
3521 mContentBottom = mVoiceContentBottom = mCurBottom = mDockBottom;
3522 mContentLeft = mVoiceContentLeft = mCurLeft = mDockLeft;
3523 mContentRight = mVoiceContentRight = mCurRight = mDockRight;
Craig Mautner69b08182012-09-05 13:07:13 -07003524 mStatusBarLayer = mNavigationBar.getSurfaceLayer();
3525 // And compute the final frame.
3526 mNavigationBar.computeFrameLw(mTmpNavigationFrame, mTmpNavigationFrame,
Adrian Roosfa104232014-06-20 16:10:14 -07003527 mTmpNavigationFrame, mTmpNavigationFrame, mTmpNavigationFrame, dcf,
Filip Gruszczynski2217f612015-05-26 11:32:08 -07003528 mTmpNavigationFrame, mTmpNavigationFrame);
Craig Mautnereda67292013-04-28 13:50:14 -07003529 if (DEBUG_LAYOUT) Slog.i(TAG, "mNavigationBar frame: " + mTmpNavigationFrame);
John Spurlock27735a42013-08-14 17:57:38 -04003530 if (mNavigationBarController.checkHiddenLw()) {
John Spurlockad3e6cb2013-04-30 08:47:43 -04003531 updateSysUiVisibility = true;
3532 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003533 }
Craig Mautnereda67292013-04-28 13:50:14 -07003534 if (DEBUG_LAYOUT) Slog.i(TAG, String.format("mDock rect: (%d,%d - %d,%d)",
Craig Mautner69b08182012-09-05 13:07:13 -07003535 mDockLeft, mDockTop, mDockRight, mDockBottom));
3536
3537 // decide where the status bar goes ahead of time
3538 if (mStatusBar != null) {
3539 // apply any navigation bar insets
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003540 pf.left = df.left = of.left = mUnrestrictedScreenLeft;
3541 pf.top = df.top = of.top = mUnrestrictedScreenTop;
3542 pf.right = df.right = of.right = mUnrestrictedScreenWidth + mUnrestrictedScreenLeft;
3543 pf.bottom = df.bottom = of.bottom = mUnrestrictedScreenHeight
3544 + mUnrestrictedScreenTop;
Craig Mautner69b08182012-09-05 13:07:13 -07003545 vf.left = mStableLeft;
3546 vf.top = mStableTop;
3547 vf.right = mStableRight;
3548 vf.bottom = mStableBottom;
3549
3550 mStatusBarLayer = mStatusBar.getSurfaceLayer();
3551
3552 // Let the status bar determine its size.
Filip Gruszczynski2217f612015-05-26 11:32:08 -07003553 mStatusBar.computeFrameLw(pf /* parentFrame */, df /* displayFrame */,
3554 vf /* overlayFrame */, vf /* contentFrame */, vf /* visibleFrame */,
3555 dcf /* decorFrame */, vf /* stableFrame */, vf /* outsetFrame */);
Craig Mautner69b08182012-09-05 13:07:13 -07003556
3557 // For layout, the status bar is always at the top with our fixed height.
3558 mStableTop = mUnrestrictedScreenTop + mStatusBarHeight;
3559
John Spurlocke1f366f2013-08-05 12:22:40 -04003560 boolean statusBarTransient = (sysui & View.STATUS_BAR_TRANSIENT) != 0;
Adrian Roosea562512014-05-05 13:33:03 +02003561 boolean statusBarTranslucent = (sysui
3562 & (View.STATUS_BAR_TRANSLUCENT | View.SYSTEM_UI_TRANSPARENT)) != 0;
Adrian Roos4fb3ee32014-08-22 19:29:09 +02003563 if (!isKeyguardShowing) {
3564 statusBarTranslucent &= areTranslucentBarsAllowed();
3565 }
John Spurlock32beb2c2013-03-11 10:16:47 -04003566
Craig Mautner69b08182012-09-05 13:07:13 -07003567 // If the status bar is hidden, we don't want to cause
3568 // windows behind it to scroll.
John Spurlockeda1f692013-09-16 11:38:44 -04003569 if (mStatusBar.isVisibleLw() && !statusBarTransient) {
Craig Mautner69b08182012-09-05 13:07:13 -07003570 // Status bar may go away, so the screen area it occupies
3571 // is available to apps but just covering them when the
3572 // status bar is visible.
3573 mDockTop = mUnrestrictedScreenTop + mStatusBarHeight;
3574
Dianne Hackborne30e02f2014-05-27 18:24:45 -07003575 mContentTop = mVoiceContentTop = mCurTop = mDockTop;
3576 mContentBottom = mVoiceContentBottom = mCurBottom = mDockBottom;
3577 mContentLeft = mVoiceContentLeft = mCurLeft = mDockLeft;
3578 mContentRight = mVoiceContentRight = mCurRight = mDockRight;
Craig Mautner69b08182012-09-05 13:07:13 -07003579
Craig Mautnereda67292013-04-28 13:50:14 -07003580 if (DEBUG_LAYOUT) Slog.v(TAG, "Status bar: " +
Craig Mautner69b08182012-09-05 13:07:13 -07003581 String.format(
3582 "dock=[%d,%d][%d,%d] content=[%d,%d][%d,%d] cur=[%d,%d][%d,%d]",
3583 mDockLeft, mDockTop, mDockRight, mDockBottom,
3584 mContentLeft, mContentTop, mContentRight, mContentBottom,
3585 mCurLeft, mCurTop, mCurRight, mCurBottom));
3586 }
John Spurlocke1f366f2013-08-05 12:22:40 -04003587 if (mStatusBar.isVisibleLw() && !mStatusBar.isAnimatingLw()
John Spurlockbd957402013-10-03 11:38:39 -04003588 && !statusBarTransient && !statusBarTranslucent
3589 && !mStatusBarController.wasRecentlyTranslucent()) {
John Spurlocke1f366f2013-08-05 12:22:40 -04003590 // If the opaque status bar is currently requested to be visible,
Craig Mautner69b08182012-09-05 13:07:13 -07003591 // and not in the process of animating on or off, then
3592 // we can tell the app that it is covered by it.
3593 mSystemTop = mUnrestrictedScreenTop + mStatusBarHeight;
3594 }
John Spurlock27735a42013-08-14 17:57:38 -04003595 if (mStatusBarController.checkHiddenLw()) {
John Spurlockad3e6cb2013-04-30 08:47:43 -04003596 updateSysUiVisibility = true;
John Spurlock32beb2c2013-03-11 10:16:47 -04003597 }
Dianne Hackborn5c58de32012-04-28 19:52:37 -07003598 }
John Spurlockad3e6cb2013-04-30 08:47:43 -04003599 if (updateSysUiVisibility) {
3600 updateSystemUiVisibilityLw();
3601 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003602 }
3603 }
3604
Dianne Hackborn85afd1b2012-05-13 13:31:06 -07003605 /** {@inheritDoc} */
Craig Mautner967212c2013-04-13 21:10:58 -07003606 @Override
John Spurlock46646232013-09-30 22:32:42 -04003607 public int getSystemDecorLayerLw() {
Bryce Lee2ed3e5f2015-04-01 22:09:19 +00003608 if (mStatusBar != null && mStatusBar.isVisibleLw()) {
3609 return mStatusBar.getSurfaceLayer();
3610 }
3611
3612 if (mNavigationBar != null && mNavigationBar.isVisibleLw()) {
3613 return mNavigationBar.getSurfaceLayer();
3614 }
3615
Dianne Hackborn85afd1b2012-05-13 13:31:06 -07003616 return 0;
3617 }
3618
Craig Mautner967212c2013-04-13 21:10:58 -07003619 @Override
3620 public void getContentRectLw(Rect r) {
3621 r.set(mContentLeft, mContentTop, mContentRight, mContentBottom);
3622 }
3623
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003624 void setAttachedWindowFrames(WindowState win, int fl, int adjust, WindowState attached,
3625 boolean insetDecors, Rect pf, Rect df, Rect of, Rect cf, Rect vf) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003626 if (win.getSurfaceLayer() > mDockLayer && attached.getSurfaceLayer() < mDockLayer) {
3627 // Here's a special case: if this attached window is a panel that is
3628 // above the dock window, and the window it is attached to is below
3629 // the dock window, then the frames we computed for the window it is
3630 // attached to can not be used because the dock is effectively part
3631 // of the underlying window and the attached window is floating on top
3632 // of the whole thing. So, we ignore the attached window and explicitly
3633 // compute the frames that would be appropriate without the dock.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003634 df.left = of.left = cf.left = vf.left = mDockLeft;
3635 df.top = of.top = cf.top = vf.top = mDockTop;
3636 df.right = of.right = cf.right = vf.right = mDockRight;
3637 df.bottom = of.bottom = cf.bottom = vf.bottom = mDockBottom;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003638 } else {
3639 // The effective display frame of the attached window depends on
3640 // whether it is taking care of insetting its content. If not,
3641 // we need to use the parent's content frame so that the entire
3642 // window is positioned within that content. Otherwise we can use
Wale Ogunwale393b1c12014-10-18 16:22:01 -07003643 // the overscan frame and let the attached window take care of
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003644 // positioning its content appropriately.
Dianne Hackborndea3ef72010-10-28 14:24:22 -07003645 if (adjust != SOFT_INPUT_ADJUST_RESIZE) {
Wale Ogunwale393b1c12014-10-18 16:22:01 -07003646 // Set the content frame of the attached window to the parent's decor frame
3647 // (same as content frame when IME isn't present) if specifically requested by
3648 // setting {@link WindowManager.LayoutParams#FLAG_LAYOUT_ATTACHED_IN_DECOR} flag.
3649 // Otherwise, use the overscan frame.
3650 cf.set((fl & FLAG_LAYOUT_ATTACHED_IN_DECOR) != 0
3651 ? attached.getContentFrameLw() : attached.getOverscanFrameLw());
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003652 } else {
3653 // If the window is resizing, then we want to base the content
3654 // frame on our attached content frame to resize... however,
3655 // things can be tricky if the attached window is NOT in resize
3656 // mode, in which case its content frame will be larger.
3657 // Ungh. So to deal with that, make sure the content frame
3658 // we end up using is not covering the IM dock.
3659 cf.set(attached.getContentFrameLw());
Dianne Hackborne30e02f2014-05-27 18:24:45 -07003660 if (attached.isVoiceInteraction()) {
3661 if (cf.left < mVoiceContentLeft) cf.left = mVoiceContentLeft;
3662 if (cf.top < mVoiceContentTop) cf.top = mVoiceContentTop;
3663 if (cf.right > mVoiceContentRight) cf.right = mVoiceContentRight;
3664 if (cf.bottom > mVoiceContentBottom) cf.bottom = mVoiceContentBottom;
3665 } else if (attached.getSurfaceLayer() < mDockLayer) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003666 if (cf.left < mContentLeft) cf.left = mContentLeft;
3667 if (cf.top < mContentTop) cf.top = mContentTop;
3668 if (cf.right > mContentRight) cf.right = mContentRight;
3669 if (cf.bottom > mContentBottom) cf.bottom = mContentBottom;
3670 }
3671 }
3672 df.set(insetDecors ? attached.getDisplayFrameLw() : cf);
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003673 of.set(insetDecors ? attached.getOverscanFrameLw() : cf);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003674 vf.set(attached.getVisibleFrameLw());
3675 }
3676 // The LAYOUT_IN_SCREEN flag is used to determine whether the attached
3677 // window should be positioned relative to its parent or the entire
3678 // screen.
3679 pf.set((fl & FLAG_LAYOUT_IN_SCREEN) == 0
3680 ? attached.getFrameLw() : df);
3681 }
Dianne Hackborn5b5cc4d2012-05-16 13:15:00 -07003682
3683 private void applyStableConstraints(int sysui, int fl, Rect r) {
3684 if ((sysui & View.SYSTEM_UI_FLAG_LAYOUT_STABLE) != 0) {
3685 // If app is requesting a stable layout, don't let the
3686 // content insets go below the stable values.
3687 if ((fl & FLAG_FULLSCREEN) != 0) {
3688 if (r.left < mStableFullscreenLeft) r.left = mStableFullscreenLeft;
3689 if (r.top < mStableFullscreenTop) r.top = mStableFullscreenTop;
3690 if (r.right > mStableFullscreenRight) r.right = mStableFullscreenRight;
3691 if (r.bottom > mStableFullscreenBottom) r.bottom = mStableFullscreenBottom;
3692 } else {
3693 if (r.left < mStableLeft) r.left = mStableLeft;
3694 if (r.top < mStableTop) r.top = mStableTop;
3695 if (r.right > mStableRight) r.right = mStableRight;
3696 if (r.bottom > mStableBottom) r.bottom = mStableBottom;
3697 }
3698 }
3699 }
3700
Jorim Jaggiaa806142015-05-20 18:04:16 -07003701 private boolean canReceiveInput(WindowState win) {
3702 boolean notFocusable =
3703 (win.getAttrs().flags & WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE) != 0;
3704 boolean altFocusableIm =
3705 (win.getAttrs().flags & WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM) != 0;
3706 boolean notFocusableForIm = notFocusable ^ altFocusableIm;
3707 return !notFocusableForIm;
3708 }
3709
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003710 /** {@inheritDoc} */
Craig Mautner69b08182012-09-05 13:07:13 -07003711 @Override
Craig Mautnerc9457fa2014-06-06 14:27:48 -07003712 public void layoutWindowLw(WindowState win, WindowState attached) {
Jorim Jaggiaa806142015-05-20 18:04:16 -07003713 // We've already done the navigation bar and status bar. If the status bar can receive
3714 // input, we need to layout it again to accomodate for the IME window.
3715 if ((win == mStatusBar && !canReceiveInput(win)) || win == mNavigationBar) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003716 return;
3717 }
Jorim Jaggiaa806142015-05-20 18:04:16 -07003718 final WindowManager.LayoutParams attrs = win.getAttrs();
Craig Mautner69b08182012-09-05 13:07:13 -07003719 final boolean isDefaultDisplay = win.isDefaultDisplay();
3720 final boolean needsToOffsetInputMethodTarget = isDefaultDisplay &&
satok1bc0a492012-04-25 22:47:12 +09003721 (win == mLastInputMethodTargetWindow && mLastInputMethodWindow != null);
3722 if (needsToOffsetInputMethodTarget) {
Craig Mautnereda67292013-04-28 13:50:14 -07003723 if (DEBUG_LAYOUT) Slog.i(TAG, "Offset ime target window by the last ime window state");
satok1bc0a492012-04-25 22:47:12 +09003724 offsetInputMethodWindowLw(mLastInputMethodWindow);
3725 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003726
John Spurlockc6d1c602014-01-17 15:22:06 -05003727 final int fl = PolicyControl.getWindowFlags(win, attrs);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003728 final int sim = attrs.softInputMode;
John Spurlock1db8b682014-02-18 11:18:59 -05003729 final int sysUiFl = PolicyControl.getSystemUiVisibility(win, null);
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07003730
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003731 final Rect pf = mTmpParentFrame;
3732 final Rect df = mTmpDisplayFrame;
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003733 final Rect of = mTmpOverscanFrame;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003734 final Rect cf = mTmpContentFrame;
3735 final Rect vf = mTmpVisibleFrame;
John Spurlock46646232013-09-30 22:32:42 -04003736 final Rect dcf = mTmpDecorFrame;
Adrian Roosfa104232014-06-20 16:10:14 -07003737 final Rect sf = mTmpStableFrame;
Filip Gruszczynski2217f612015-05-26 11:32:08 -07003738 Rect osf = null;
John Spurlock46646232013-09-30 22:32:42 -04003739 dcf.setEmpty();
Craig Mautner69b08182012-09-05 13:07:13 -07003740
3741 final boolean hasNavBar = (isDefaultDisplay && mHasNavigationBar
Daniel Sandler36412a72011-08-04 09:35:13 -04003742 && mNavigationBar != null && mNavigationBar.isVisibleLw());
Daniel Sandler8956dbb2011-04-22 07:55:02 -04003743
Craig Mautnerf683b562012-10-02 11:10:57 -07003744 final int adjust = sim & SOFT_INPUT_MASK_ADJUST;
3745
Adrian Roosfa104232014-06-20 16:10:14 -07003746 if (isDefaultDisplay) {
3747 sf.set(mStableLeft, mStableTop, mStableRight, mStableBottom);
3748 } else {
3749 sf.set(mOverscanLeft, mOverscanTop, mOverscanRight, mOverscanBottom);
3750 }
3751
Craig Mautner69b08182012-09-05 13:07:13 -07003752 if (!isDefaultDisplay) {
3753 if (attached != null) {
3754 // If this window is attached to another, our display
3755 // frame is the same as the one we are attached to.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003756 setAttachedWindowFrames(win, fl, adjust, attached, true, pf, df, of, cf, vf);
Craig Mautner69b08182012-09-05 13:07:13 -07003757 } else {
3758 // Give the window full screen.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003759 pf.left = df.left = of.left = cf.left = mOverscanScreenLeft;
3760 pf.top = df.top = of.top = cf.top = mOverscanScreenTop;
3761 pf.right = df.right = of.right = cf.right
Dianne Hackbornc652de82013-02-15 16:32:56 -08003762 = mOverscanScreenLeft + mOverscanScreenWidth;
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003763 pf.bottom = df.bottom = of.bottom = cf.bottom
Dianne Hackbornc652de82013-02-15 16:32:56 -08003764 = mOverscanScreenTop + mOverscanScreenHeight;
Craig Mautner69b08182012-09-05 13:07:13 -07003765 }
Jorim Jaggi225d3b52015-04-01 11:18:57 -07003766 } else if (attrs.type == TYPE_INPUT_METHOD) {
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003767 pf.left = df.left = of.left = cf.left = vf.left = mDockLeft;
3768 pf.top = df.top = of.top = cf.top = vf.top = mDockTop;
3769 pf.right = df.right = of.right = cf.right = vf.right = mDockRight;
John Spurlockc68d5772013-10-08 11:47:58 -04003770 // IM dock windows layout below the nav bar...
John Spurlock57beb3b2013-10-10 10:27:44 -04003771 pf.bottom = df.bottom = of.bottom = mUnrestrictedScreenTop + mUnrestrictedScreenHeight;
John Spurlockc68d5772013-10-08 11:47:58 -04003772 // ...with content insets above the nav bar
3773 cf.bottom = vf.bottom = mStableBottom;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003774 // IM dock windows always go to the bottom of the screen.
3775 attrs.gravity = Gravity.BOTTOM;
3776 mDockLayer = win.getSurfaceLayer();
Jorim Jaggi225d3b52015-04-01 11:18:57 -07003777 } else if (attrs.type == TYPE_VOICE_INTERACTION) {
Stefan Kuhne2f280d062015-06-18 07:20:33 -10003778 pf.left = df.left = of.left = mUnrestrictedScreenLeft;
Jorim Jaggi225d3b52015-04-01 11:18:57 -07003779 pf.top = df.top = of.top = mUnrestrictedScreenTop;
Stefan Kuhne2f280d062015-06-18 07:20:33 -10003780 pf.right = df.right = of.right = mUnrestrictedScreenLeft + mUnrestrictedScreenWidth;
3781 pf.bottom = df.bottom = of.bottom = mUnrestrictedScreenTop + mUnrestrictedScreenHeight;
Jorim Jaggi225d3b52015-04-01 11:18:57 -07003782 cf.bottom = vf.bottom = mStableBottom;
Stefan Kuhne2f280d062015-06-18 07:20:33 -10003783 // Note: In Phone landscape mode, the button bar should also be excluded.
3784 cf.right = vf.right = mStableRight;
3785 cf.left = vf.left = mStableLeft;
Jorim Jaggi225d3b52015-04-01 11:18:57 -07003786 cf.top = vf.top = mStableTop;
Jorim Jaggiaa806142015-05-20 18:04:16 -07003787 } else if (win == mStatusBar) {
Jorim Jaggie0700182014-08-21 01:12:37 +02003788 pf.left = df.left = of.left = mUnrestrictedScreenLeft;
3789 pf.top = df.top = of.top = mUnrestrictedScreenTop;
3790 pf.right = df.right = of.right = mUnrestrictedScreenWidth + mUnrestrictedScreenLeft;
3791 pf.bottom = df.bottom = of.bottom = mUnrestrictedScreenHeight + mUnrestrictedScreenTop;
3792 cf.left = vf.left = mStableLeft;
3793 cf.top = vf.top = mStableTop;
3794 cf.right = vf.right = mStableRight;
3795 vf.bottom = mStableBottom;
3796 cf.bottom = mContentBottom;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003797 } else {
John Spurlock46646232013-09-30 22:32:42 -04003798
3799 // Default policy decor for the default display
3800 dcf.left = mSystemLeft;
3801 dcf.top = mSystemTop;
3802 dcf.right = mSystemRight;
3803 dcf.bottom = mSystemBottom;
John Spurlockbd957402013-10-03 11:38:39 -04003804 final boolean inheritTranslucentDecor = (attrs.privateFlags
3805 & WindowManager.LayoutParams.PRIVATE_FLAG_INHERIT_TRANSLUCENT_DECOR) != 0;
John Spurlock65567d42013-10-08 10:08:32 -04003806 final boolean isAppWindow =
3807 attrs.type >= WindowManager.LayoutParams.FIRST_APPLICATION_WINDOW &&
3808 attrs.type <= WindowManager.LayoutParams.LAST_APPLICATION_WINDOW;
3809 final boolean topAtRest =
3810 win == mTopFullscreenOpaqueWindowState && !win.isAnimatingLw();
3811 if (isAppWindow && !inheritTranslucentDecor && !topAtRest) {
John Spurlockbd957402013-10-03 11:38:39 -04003812 if ((sysUiFl & View.SYSTEM_UI_FLAG_FULLSCREEN) == 0
3813 && (fl & WindowManager.LayoutParams.FLAG_FULLSCREEN) == 0
Adrian Roosea562512014-05-05 13:33:03 +02003814 && (fl & WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS) == 0
3815 && (fl & WindowManager.LayoutParams.
3816 FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS) == 0) {
John Spurlock46646232013-09-30 22:32:42 -04003817 // Ensure policy decor includes status bar
3818 dcf.top = mStableTop;
3819 }
John Spurlockbd957402013-10-03 11:38:39 -04003820 if ((fl & WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION) == 0
Adrian Roosea562512014-05-05 13:33:03 +02003821 && (sysUiFl & View.SYSTEM_UI_FLAG_HIDE_NAVIGATION) == 0
3822 && (fl & WindowManager.LayoutParams.
3823 FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS) == 0) {
John Spurlock46646232013-09-30 22:32:42 -04003824 // Ensure policy decor includes navigation bar
3825 dcf.bottom = mStableBottom;
3826 dcf.right = mStableRight;
3827 }
3828 }
3829
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003830 if ((fl & (FLAG_LAYOUT_IN_SCREEN | FLAG_LAYOUT_INSET_DECOR))
3831 == (FLAG_LAYOUT_IN_SCREEN | FLAG_LAYOUT_INSET_DECOR)) {
RoboErik8a2cfc32014-05-16 11:19:38 -07003832 if (DEBUG_LAYOUT) Slog.v(TAG, "layoutWindowLw(" + attrs.getTitle()
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003833 + "): IN_SCREEN, INSET_DECOR");
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003834 // This is the case for a normal activity window: we want it
3835 // to cover all of the screen space, and it can take care of
3836 // moving its contents to account for screen decorations that
3837 // intrude into that space.
3838 if (attached != null) {
3839 // If this window is attached to another, our display
3840 // frame is the same as the one we are attached to.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003841 setAttachedWindowFrames(win, fl, adjust, attached, true, pf, df, of, cf, vf);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003842 } else {
Daniel Sandler8956dbb2011-04-22 07:55:02 -04003843 if (attrs.type == TYPE_STATUS_BAR_PANEL
3844 || attrs.type == TYPE_STATUS_BAR_SUB_PANEL) {
Joe Onorato29fc2c92010-11-24 10:26:50 -08003845 // Status bar panels are the only windows who can go on top of
3846 // the status bar. They are protected by the STATUS_BAR_SERVICE
3847 // permission, so they have the same privileges as the status
3848 // bar itself.
Daniel Sandler8956dbb2011-04-22 07:55:02 -04003849 //
Daniel Sandler8e8b4152011-07-21 01:16:43 -04003850 // However, they should still dodge the navigation bar if it exists.
Daniel Sandler8956dbb2011-04-22 07:55:02 -04003851
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003852 pf.left = df.left = of.left = hasNavBar
3853 ? mDockLeft : mUnrestrictedScreenLeft;
3854 pf.top = df.top = of.top = mUnrestrictedScreenTop;
3855 pf.right = df.right = of.right = hasNavBar
3856 ? mRestrictedScreenLeft+mRestrictedScreenWidth
3857 : mUnrestrictedScreenLeft + mUnrestrictedScreenWidth;
3858 pf.bottom = df.bottom = of.bottom = hasNavBar
3859 ? mRestrictedScreenTop+mRestrictedScreenHeight
3860 : mUnrestrictedScreenTop + mUnrestrictedScreenHeight;
Daniel Sandler8956dbb2011-04-22 07:55:02 -04003861
Craig Mautnereda67292013-04-28 13:50:14 -07003862 if (DEBUG_LAYOUT) Slog.v(TAG, String.format(
Daniel Sandler8e8b4152011-07-21 01:16:43 -04003863 "Laying out status bar window: (%d,%d - %d,%d)",
3864 pf.left, pf.top, pf.right, pf.bottom));
John Spurlock46646232013-09-30 22:32:42 -04003865 } else if ((fl & FLAG_LAYOUT_IN_OVERSCAN) != 0
Dianne Hackbornc652de82013-02-15 16:32:56 -08003866 && attrs.type >= WindowManager.LayoutParams.FIRST_APPLICATION_WINDOW
3867 && attrs.type <= WindowManager.LayoutParams.LAST_SUB_WINDOW) {
3868 // Asking to layout into the overscan region, so give it that pure
3869 // unrestricted area.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003870 pf.left = df.left = of.left = mOverscanScreenLeft;
3871 pf.top = df.top = of.top = mOverscanScreenTop;
3872 pf.right = df.right = of.right = mOverscanScreenLeft + mOverscanScreenWidth;
3873 pf.bottom = df.bottom = of.bottom = mOverscanScreenTop
3874 + mOverscanScreenHeight;
Alan Viverette5a0f4ec2013-10-07 15:10:29 -07003875 } else if (canHideNavigationBar()
Dianne Hackbornf87d1962012-04-04 12:48:24 -07003876 && (sysUiFl & View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION) != 0
Jorim Jaggi380ecb82014-03-14 17:25:20 +01003877 && attrs.type >= WindowManager.LayoutParams.FIRST_APPLICATION_WINDOW
3878 && attrs.type <= WindowManager.LayoutParams.LAST_SUB_WINDOW) {
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07003879 // Asking for layout as if the nav bar is hidden, lets the
Dianne Hackbornc652de82013-02-15 16:32:56 -08003880 // application extend into the unrestricted overscan screen area. We
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07003881 // only do this for application windows to ensure no window that
3882 // can be above the nav bar can do this.
Dianne Hackborn313440842013-02-19 19:22:59 -08003883 pf.left = df.left = mOverscanScreenLeft;
3884 pf.top = df.top = mOverscanScreenTop;
3885 pf.right = df.right = mOverscanScreenLeft + mOverscanScreenWidth;
3886 pf.bottom = df.bottom = mOverscanScreenTop + mOverscanScreenHeight;
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003887 // We need to tell the app about where the frame inside the overscan
3888 // is, so it can inset its content by that amount -- it didn't ask
3889 // to actually extend itself into the overscan region.
3890 of.left = mUnrestrictedScreenLeft;
3891 of.top = mUnrestrictedScreenTop;
3892 of.right = mUnrestrictedScreenLeft + mUnrestrictedScreenWidth;
3893 of.bottom = mUnrestrictedScreenTop + mUnrestrictedScreenHeight;
Joe Onorato29fc2c92010-11-24 10:26:50 -08003894 } else {
Dianne Hackborn313440842013-02-19 19:22:59 -08003895 pf.left = df.left = mRestrictedOverscanScreenLeft;
3896 pf.top = df.top = mRestrictedOverscanScreenTop;
3897 pf.right = df.right = mRestrictedOverscanScreenLeft
3898 + mRestrictedOverscanScreenWidth;
3899 pf.bottom = df.bottom = mRestrictedOverscanScreenTop
3900 + mRestrictedOverscanScreenHeight;
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003901 // We need to tell the app about where the frame inside the overscan
3902 // is, so it can inset its content by that amount -- it didn't ask
3903 // to actually extend itself into the overscan region.
3904 of.left = mUnrestrictedScreenLeft;
3905 of.top = mUnrestrictedScreenTop;
3906 of.right = mUnrestrictedScreenLeft + mUnrestrictedScreenWidth;
3907 of.bottom = mUnrestrictedScreenTop + mUnrestrictedScreenHeight;
Joe Onorato29fc2c92010-11-24 10:26:50 -08003908 }
Craig Mautner69b08182012-09-05 13:07:13 -07003909
John Spurlock46646232013-09-30 22:32:42 -04003910 if ((fl & FLAG_FULLSCREEN) == 0) {
Dianne Hackborne30e02f2014-05-27 18:24:45 -07003911 if (win.isVoiceInteraction()) {
3912 cf.left = mVoiceContentLeft;
3913 cf.top = mVoiceContentTop;
3914 cf.right = mVoiceContentRight;
3915 cf.bottom = mVoiceContentBottom;
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003916 } else {
Dianne Hackborne30e02f2014-05-27 18:24:45 -07003917 if (adjust != SOFT_INPUT_ADJUST_RESIZE) {
3918 cf.left = mDockLeft;
3919 cf.top = mDockTop;
3920 cf.right = mDockRight;
3921 cf.bottom = mDockBottom;
3922 } else {
3923 cf.left = mContentLeft;
3924 cf.top = mContentTop;
3925 cf.right = mContentRight;
3926 cf.bottom = mContentBottom;
3927 }
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003928 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003929 } else {
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003930 // Full screen windows are always given a layout that is as if the
3931 // status bar and other transient decors are gone. This is to avoid
3932 // bad states when moving from a window that is not hding the
3933 // status bar to one that is.
3934 cf.left = mRestrictedScreenLeft;
3935 cf.top = mRestrictedScreenTop;
3936 cf.right = mRestrictedScreenLeft + mRestrictedScreenWidth;
3937 cf.bottom = mRestrictedScreenTop + mRestrictedScreenHeight;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003938 }
Dianne Hackborn5b5cc4d2012-05-16 13:15:00 -07003939 applyStableConstraints(sysUiFl, fl, cf);
Dianne Hackborndea3ef72010-10-28 14:24:22 -07003940 if (adjust != SOFT_INPUT_ADJUST_NOTHING) {
3941 vf.left = mCurLeft;
3942 vf.top = mCurTop;
3943 vf.right = mCurRight;
3944 vf.bottom = mCurBottom;
3945 } else {
3946 vf.set(cf);
3947 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003948 }
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07003949 } else if ((fl & FLAG_LAYOUT_IN_SCREEN) != 0 || (sysUiFl
3950 & (View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
3951 | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION)) != 0) {
Craig Mautnereda67292013-04-28 13:50:14 -07003952 if (DEBUG_LAYOUT) Slog.v(TAG, "layoutWindowLw(" + attrs.getTitle() +
3953 "): IN_SCREEN");
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003954 // A window that has requested to fill the entire screen just
3955 // gets everything, period.
Daniel Sandler8956dbb2011-04-22 07:55:02 -04003956 if (attrs.type == TYPE_STATUS_BAR_PANEL
John Spurlock67a0f852015-06-15 15:35:47 -04003957 || attrs.type == TYPE_STATUS_BAR_SUB_PANEL
3958 || attrs.type == TYPE_VOLUME_OVERLAY) {
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003959 pf.left = df.left = of.left = cf.left = hasNavBar
3960 ? mDockLeft : mUnrestrictedScreenLeft;
3961 pf.top = df.top = of.top = cf.top = mUnrestrictedScreenTop;
3962 pf.right = df.right = of.right = cf.right = hasNavBar
Daniel Sandler8e8b4152011-07-21 01:16:43 -04003963 ? mRestrictedScreenLeft+mRestrictedScreenWidth
Dianne Hackbornc652de82013-02-15 16:32:56 -08003964 : mUnrestrictedScreenLeft + mUnrestrictedScreenWidth;
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003965 pf.bottom = df.bottom = of.bottom = cf.bottom = hasNavBar
Daniel Sandler8e8b4152011-07-21 01:16:43 -04003966 ? mRestrictedScreenTop+mRestrictedScreenHeight
Dianne Hackbornc652de82013-02-15 16:32:56 -08003967 : mUnrestrictedScreenTop + mUnrestrictedScreenHeight;
Craig Mautnereda67292013-04-28 13:50:14 -07003968 if (DEBUG_LAYOUT) Slog.v(TAG, String.format(
Daniel Sandler36412a72011-08-04 09:35:13 -04003969 "Laying out IN_SCREEN status bar window: (%d,%d - %d,%d)",
3970 pf.left, pf.top, pf.right, pf.bottom));
Jim Millere898ac52012-04-06 17:10:57 -07003971 } else if (attrs.type == TYPE_NAVIGATION_BAR
3972 || attrs.type == TYPE_NAVIGATION_BAR_PANEL) {
Daniel Sandler8e8b4152011-07-21 01:16:43 -04003973 // The navigation bar has Real Ultimate Power.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003974 pf.left = df.left = of.left = mUnrestrictedScreenLeft;
3975 pf.top = df.top = of.top = mUnrestrictedScreenTop;
3976 pf.right = df.right = of.right = mUnrestrictedScreenLeft
3977 + mUnrestrictedScreenWidth;
3978 pf.bottom = df.bottom = of.bottom = mUnrestrictedScreenTop
3979 + mUnrestrictedScreenHeight;
Craig Mautnereda67292013-04-28 13:50:14 -07003980 if (DEBUG_LAYOUT) Slog.v(TAG, String.format(
Daniel Sandler8e8b4152011-07-21 01:16:43 -04003981 "Laying out navigation bar window: (%d,%d - %d,%d)",
3982 pf.left, pf.top, pf.right, pf.bottom));
Dianne Hackborn01011c32012-02-21 13:54:21 -08003983 } else if ((attrs.type == TYPE_SECURE_SYSTEM_OVERLAY
3984 || attrs.type == TYPE_BOOT_PROGRESS)
Jeff Brownbfcb60a2011-09-08 18:51:14 -07003985 && ((fl & FLAG_FULLSCREEN) != 0)) {
3986 // Fullscreen secure system overlays get what they ask for.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003987 pf.left = df.left = of.left = cf.left = mOverscanScreenLeft;
3988 pf.top = df.top = of.top = cf.top = mOverscanScreenTop;
3989 pf.right = df.right = of.right = cf.right = mOverscanScreenLeft
3990 + mOverscanScreenWidth;
3991 pf.bottom = df.bottom = of.bottom = cf.bottom = mOverscanScreenTop
3992 + mOverscanScreenHeight;
Craig Mautner165be0c2015-01-27 15:16:58 -08003993 } else if (attrs.type == TYPE_BOOT_PROGRESS) {
Dianne Hackborn01011c32012-02-21 13:54:21 -08003994 // Boot progress screen always covers entire display.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003995 pf.left = df.left = of.left = cf.left = mOverscanScreenLeft;
3996 pf.top = df.top = of.top = cf.top = mOverscanScreenTop;
3997 pf.right = df.right = of.right = cf.right = mOverscanScreenLeft
3998 + mOverscanScreenWidth;
3999 pf.bottom = df.bottom = of.bottom = cf.bottom = mOverscanScreenTop
4000 + mOverscanScreenHeight;
John Spurlockef4adae2013-08-26 17:58:58 -04004001 } else if (attrs.type == TYPE_WALLPAPER) {
Dianne Hackborn067e5f62014-09-07 23:14:30 -07004002 // The wallpaper also has Real Ultimate Power, but we want to tell
4003 // it about the overscan area.
4004 pf.left = df.left = mOverscanScreenLeft;
4005 pf.top = df.top = mOverscanScreenTop;
4006 pf.right = df.right = mOverscanScreenLeft + mOverscanScreenWidth;
4007 pf.bottom = df.bottom = mOverscanScreenTop + mOverscanScreenHeight;
4008 of.left = cf.left = mUnrestrictedScreenLeft;
4009 of.top = cf.top = mUnrestrictedScreenTop;
4010 of.right = cf.right = mUnrestrictedScreenLeft + mUnrestrictedScreenWidth;
4011 of.bottom = cf.bottom = mUnrestrictedScreenTop + mUnrestrictedScreenHeight;
John Spurlock46646232013-09-30 22:32:42 -04004012 } else if ((fl & FLAG_LAYOUT_IN_OVERSCAN) != 0
Dianne Hackbornc652de82013-02-15 16:32:56 -08004013 && attrs.type >= WindowManager.LayoutParams.FIRST_APPLICATION_WINDOW
4014 && attrs.type <= WindowManager.LayoutParams.LAST_SUB_WINDOW) {
4015 // Asking to layout into the overscan region, so give it that pure
4016 // unrestricted area.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08004017 pf.left = df.left = of.left = cf.left = mOverscanScreenLeft;
4018 pf.top = df.top = of.top = cf.top = mOverscanScreenTop;
4019 pf.right = df.right = of.right = cf.right
Dianne Hackbornc652de82013-02-15 16:32:56 -08004020 = mOverscanScreenLeft + mOverscanScreenWidth;
Dianne Hackbornc4aad012013-02-22 15:05:25 -08004021 pf.bottom = df.bottom = of.bottom = cf.bottom
Dianne Hackbornc652de82013-02-15 16:32:56 -08004022 = mOverscanScreenTop + mOverscanScreenHeight;
Alan Viverette5a0f4ec2013-10-07 15:10:29 -07004023 } else if (canHideNavigationBar()
Dianne Hackbornf87d1962012-04-04 12:48:24 -07004024 && (sysUiFl & View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION) != 0
Craig Mautnerbeac1062014-06-03 14:38:57 -07004025 && (attrs.type == TYPE_STATUS_BAR
4026 || attrs.type == TYPE_TOAST
Jorim Jaggi2fdeeab2015-04-01 15:13:03 -07004027 || attrs.type == TYPE_VOICE_INTERACTION_STARTING
John Spurlock34e13d92013-08-10 06:52:28 -04004028 || (attrs.type >= WindowManager.LayoutParams.FIRST_APPLICATION_WINDOW
4029 && attrs.type <= WindowManager.LayoutParams.LAST_SUB_WINDOW))) {
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07004030 // Asking for layout as if the nav bar is hidden, lets the
4031 // application extend into the unrestricted screen area. We
John Spurlock34e13d92013-08-10 06:52:28 -04004032 // only do this for application windows (or toasts) to ensure no window that
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07004033 // can be above the nav bar can do this.
4034 // XXX This assumes that an app asking for this will also
4035 // ask for layout in only content. We can't currently figure out
4036 // what the screen would be if only laying out to hide the nav bar.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08004037 pf.left = df.left = of.left = cf.left = mUnrestrictedScreenLeft;
4038 pf.top = df.top = of.top = cf.top = mUnrestrictedScreenTop;
4039 pf.right = df.right = of.right = cf.right = mUnrestrictedScreenLeft
4040 + mUnrestrictedScreenWidth;
4041 pf.bottom = df.bottom = of.bottom = cf.bottom = mUnrestrictedScreenTop
4042 + mUnrestrictedScreenHeight;
Joe Onorato29fc2c92010-11-24 10:26:50 -08004043 } else {
Dianne Hackbornc4aad012013-02-22 15:05:25 -08004044 pf.left = df.left = of.left = cf.left = mRestrictedScreenLeft;
4045 pf.top = df.top = of.top = cf.top = mRestrictedScreenTop;
4046 pf.right = df.right = of.right = cf.right = mRestrictedScreenLeft
4047 + mRestrictedScreenWidth;
4048 pf.bottom = df.bottom = of.bottom = cf.bottom = mRestrictedScreenTop
4049 + mRestrictedScreenHeight;
Joe Onorato29fc2c92010-11-24 10:26:50 -08004050 }
Craig Mautner69b08182012-09-05 13:07:13 -07004051
Dianne Hackborn5b5cc4d2012-05-16 13:15:00 -07004052 applyStableConstraints(sysUiFl, fl, cf);
Craig Mautner69b08182012-09-05 13:07:13 -07004053
Dianne Hackborndea3ef72010-10-28 14:24:22 -07004054 if (adjust != SOFT_INPUT_ADJUST_NOTHING) {
4055 vf.left = mCurLeft;
4056 vf.top = mCurTop;
4057 vf.right = mCurRight;
4058 vf.bottom = mCurBottom;
4059 } else {
4060 vf.set(cf);
4061 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004062 } else if (attached != null) {
Craig Mautnereda67292013-04-28 13:50:14 -07004063 if (DEBUG_LAYOUT) Slog.v(TAG, "layoutWindowLw(" + attrs.getTitle() +
4064 "): attached to " + attached);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004065 // A child window should be placed inside of the same visible
4066 // frame that its parent had.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08004067 setAttachedWindowFrames(win, fl, adjust, attached, false, pf, df, of, cf, vf);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004068 } else {
Craig Mautnereda67292013-04-28 13:50:14 -07004069 if (DEBUG_LAYOUT) Slog.v(TAG, "layoutWindowLw(" + attrs.getTitle() +
4070 "): normal window");
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004071 // Otherwise, a normal window must be placed inside the content
4072 // of all screen decorations.
John Spurlock67a0f852015-06-15 15:35:47 -04004073 if (attrs.type == TYPE_STATUS_BAR_PANEL || attrs.type == TYPE_VOLUME_OVERLAY) {
4074 // Status bar panels and the volume dialog are the only windows who can go on
4075 // top of the status bar. They are protected by the STATUS_BAR_SERVICE
Dianne Hackborna239c842011-06-01 12:28:20 -07004076 // permission, so they have the same privileges as the status
4077 // bar itself.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08004078 pf.left = df.left = of.left = cf.left = mRestrictedScreenLeft;
4079 pf.top = df.top = of.top = cf.top = mRestrictedScreenTop;
4080 pf.right = df.right = of.right = cf.right = mRestrictedScreenLeft
4081 + mRestrictedScreenWidth;
4082 pf.bottom = df.bottom = of.bottom = cf.bottom = mRestrictedScreenTop
4083 + mRestrictedScreenHeight;
John Spurlock67a0f852015-06-15 15:35:47 -04004084 } else if (attrs.type == TYPE_TOAST || attrs.type == TYPE_SYSTEM_ALERT) {
John Spurlock414c1f02013-12-04 13:47:36 -05004085 // These dialogs are stable to interim decor changes.
John Spurlockbd957402013-10-03 11:38:39 -04004086 pf.left = df.left = of.left = cf.left = mStableLeft;
4087 pf.top = df.top = of.top = cf.top = mStableTop;
4088 pf.right = df.right = of.right = cf.right = mStableRight;
4089 pf.bottom = df.bottom = of.bottom = cf.bottom = mStableBottom;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004090 } else {
Dianne Hackborna239c842011-06-01 12:28:20 -07004091 pf.left = mContentLeft;
4092 pf.top = mContentTop;
4093 pf.right = mContentRight;
4094 pf.bottom = mContentBottom;
Dianne Hackborn20d94742014-05-29 18:35:45 -07004095 if (win.isVoiceInteraction()) {
4096 df.left = of.left = cf.left = mVoiceContentLeft;
4097 df.top = of.top = cf.top = mVoiceContentTop;
4098 df.right = of.right = cf.right = mVoiceContentRight;
4099 df.bottom = of.bottom = cf.bottom = mVoiceContentBottom;
4100 } else if (adjust != SOFT_INPUT_ADJUST_RESIZE) {
Dianne Hackbornc4aad012013-02-22 15:05:25 -08004101 df.left = of.left = cf.left = mDockLeft;
4102 df.top = of.top = cf.top = mDockTop;
4103 df.right = of.right = cf.right = mDockRight;
4104 df.bottom = of.bottom = cf.bottom = mDockBottom;
Dianne Hackborna239c842011-06-01 12:28:20 -07004105 } else {
Dianne Hackbornc4aad012013-02-22 15:05:25 -08004106 df.left = of.left = cf.left = mContentLeft;
4107 df.top = of.top = cf.top = mContentTop;
4108 df.right = of.right = cf.right = mContentRight;
4109 df.bottom = of.bottom = cf.bottom = mContentBottom;
Dianne Hackborna239c842011-06-01 12:28:20 -07004110 }
4111 if (adjust != SOFT_INPUT_ADJUST_NOTHING) {
4112 vf.left = mCurLeft;
4113 vf.top = mCurTop;
4114 vf.right = mCurRight;
4115 vf.bottom = mCurBottom;
4116 } else {
4117 vf.set(cf);
4118 }
Dianne Hackborndea3ef72010-10-28 14:24:22 -07004119 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004120 }
4121 }
Craig Mautner69b08182012-09-05 13:07:13 -07004122
Craig Mautnerb816bed2013-07-23 10:26:17 -07004123 // TYPE_SYSTEM_ERROR is above the NavigationBar so it can't be allowed to extend over it.
4124 if ((fl & FLAG_LAYOUT_NO_LIMITS) != 0 && attrs.type != TYPE_SYSTEM_ERROR) {
Dianne Hackborn067e5f62014-09-07 23:14:30 -07004125 df.left = df.top = -10000;
4126 df.right = df.bottom = 10000;
4127 if (attrs.type != TYPE_WALLPAPER) {
4128 of.left = of.top = cf.left = cf.top = vf.left = vf.top = -10000;
4129 of.right = of.bottom = cf.right = cf.bottom = vf.right = vf.bottom = 10000;
4130 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004131 }
4132
Filip Gruszczynski2217f612015-05-26 11:32:08 -07004133 // If the device has a chin (e.g. some watches), a dead area at the bottom of the screen we
4134 // need to provide information to the clients that want to pretend that you can draw there.
Filip Gruszczynskib0c673b2015-06-05 09:43:06 -07004135 // We only want to apply outsets to certain types of windows. For example, we never want to
4136 // apply the outsets to floating dialogs, because they wouldn't make sense there.
4137 final boolean useOutsets = attrs.type == TYPE_WALLPAPER
4138 || (fl & (WindowManager.LayoutParams.FLAG_FULLSCREEN
4139 | WindowManager.LayoutParams.FLAG_LAYOUT_IN_OVERSCAN)) != 0;
4140 if (isDefaultDisplay && useOutsets) {
Filip Gruszczynski2217f612015-05-26 11:32:08 -07004141 osf = mTmpOutsetFrame;
4142 osf.set(cf.left, cf.top, cf.right, cf.bottom);
4143 int outset = ScreenShapeHelper.getWindowOutsetBottomPx(mContext.getResources());
4144 if (outset > 0) {
4145 int rotation = Surface.ROTATION_0;
4146 try {
4147 rotation = mWindowManager.getRotation();
4148 } catch (RemoteException e) {
4149 }
4150 if (rotation == Surface.ROTATION_0) {
4151 osf.bottom += outset;
4152 } else if (rotation == Surface.ROTATION_90) {
4153 osf.right += outset;
4154 } else if (rotation == Surface.ROTATION_180) {
4155 osf.top -= outset;
4156 } else if (rotation == Surface.ROTATION_270) {
4157 osf.left -= outset;
4158 }
4159 if (DEBUG_LAYOUT) Slog.v(TAG, "applying bottom outset of " + outset
4160 + " with rotation " + rotation + ", result: " + osf);
4161 }
4162 }
4163
Craig Mautnereda67292013-04-28 13:50:14 -07004164 if (DEBUG_LAYOUT) Slog.v(TAG, "Compute frame " + attrs.getTitle()
The Android Open Source Project11267662009-03-18 17:39:47 -07004165 + ": sim=#" + Integer.toHexString(sim)
RoboErik8a2cfc32014-05-16 11:19:38 -07004166 + " attach=" + attached + " type=" + attrs.type
Daniel Sandler8956dbb2011-04-22 07:55:02 -04004167 + String.format(" flags=0x%08x", fl)
The Android Open Source Project11267662009-03-18 17:39:47 -07004168 + " pf=" + pf.toShortString() + " df=" + df.toShortString()
Dianne Hackbornc4aad012013-02-22 15:05:25 -08004169 + " of=" + of.toShortString()
John Spurlock46646232013-09-30 22:32:42 -04004170 + " cf=" + cf.toShortString() + " vf=" + vf.toShortString()
Adrian Roosfa104232014-06-20 16:10:14 -07004171 + " dcf=" + dcf.toShortString()
Filip Gruszczynski2217f612015-05-26 11:32:08 -07004172 + " sf=" + sf.toShortString()
4173 + " osf=" + (osf == null ? "null" : osf.toShortString()));
Craig Mautner69b08182012-09-05 13:07:13 -07004174
Filip Gruszczynski2217f612015-05-26 11:32:08 -07004175 win.computeFrameLw(pf, df, of, cf, vf, dcf, sf, osf);
Craig Mautner69b08182012-09-05 13:07:13 -07004176
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004177 // Dock windows carve out the bottom of the screen, so normal windows
4178 // can't appear underneath them.
Craig Mautner8bd206b2012-10-03 10:32:02 -07004179 if (attrs.type == TYPE_INPUT_METHOD && win.isVisibleOrBehindKeyguardLw()
4180 && !win.getGivenInsetsPendingLw()) {
satok1bc0a492012-04-25 22:47:12 +09004181 setLastInputMethodWindowLw(null, null);
4182 offsetInputMethodWindowLw(win);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004183 }
Dianne Hackborne30e02f2014-05-27 18:24:45 -07004184 if (attrs.type == TYPE_VOICE_INTERACTION && win.isVisibleOrBehindKeyguardLw()
4185 && !win.getGivenInsetsPendingLw()) {
4186 offsetVoiceInputWindowLw(win);
4187 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004188 }
4189
satok1bc0a492012-04-25 22:47:12 +09004190 private void offsetInputMethodWindowLw(WindowState win) {
Craig Mautner4774f6a2015-03-23 11:42:55 -07004191 int top = Math.max(win.getDisplayFrameLw().top, win.getContentFrameLw().top);
satok1bc0a492012-04-25 22:47:12 +09004192 top += win.getGivenContentInsetsLw().top;
4193 if (mContentBottom > top) {
4194 mContentBottom = top;
4195 }
Dianne Hackborne30e02f2014-05-27 18:24:45 -07004196 if (mVoiceContentBottom > top) {
4197 mVoiceContentBottom = top;
4198 }
satok1bc0a492012-04-25 22:47:12 +09004199 top = win.getVisibleFrameLw().top;
4200 top += win.getGivenVisibleInsetsLw().top;
4201 if (mCurBottom > top) {
4202 mCurBottom = top;
4203 }
Craig Mautnereda67292013-04-28 13:50:14 -07004204 if (DEBUG_LAYOUT) Slog.v(TAG, "Input method: mDockBottom="
satok1bc0a492012-04-25 22:47:12 +09004205 + mDockBottom + " mContentBottom="
4206 + mContentBottom + " mCurBottom=" + mCurBottom);
4207 }
4208
Dianne Hackborne30e02f2014-05-27 18:24:45 -07004209 private void offsetVoiceInputWindowLw(WindowState win) {
Craig Mautner4774f6a2015-03-23 11:42:55 -07004210 int top = Math.max(win.getDisplayFrameLw().top, win.getContentFrameLw().top);
Dianne Hackbornae6688b2015-02-11 17:02:41 -08004211 top += win.getGivenContentInsetsLw().top;
4212 if (mVoiceContentBottom > top) {
4213 mVoiceContentBottom = top;
Dianne Hackborne30e02f2014-05-27 18:24:45 -07004214 }
4215 }
4216
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004217 /** {@inheritDoc} */
Craig Mautner61ac6bb2012-02-02 17:29:33 -08004218 @Override
4219 public void finishLayoutLw() {
4220 return;
Dianne Hackborn5f3063e2010-03-10 16:01:58 -08004221 }
4222
4223 /** {@inheritDoc} */
Craig Mautnerad09bcc2012-10-08 13:33:11 -07004224 @Override
Craig Mautner39834192012-09-02 07:47:24 -07004225 public void beginPostLayoutPolicyLw(int displayWidth, int displayHeight) {
Dianne Hackborn5f3063e2010-03-10 16:01:58 -08004226 mTopFullscreenOpaqueWindowState = null;
Adrian Rooscd3884d2015-02-18 17:25:23 +01004227 mTopFullscreenOpaqueOrDimmingWindowState = null;
Craig Mautner2bc789b2014-03-19 19:48:38 -07004228 mAppsToBeHidden.clear();
Jorim Jaggic13fcac2014-09-11 17:36:57 +02004229 mAppsThatDismissKeyguard.clear();
Dianne Hackborn5f3063e2010-03-10 16:01:58 -08004230 mForceStatusBar = false;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07004231 mForceStatusBarFromKeyguard = false;
Selim Cinek4a4a2bddc2015-05-07 12:50:19 -07004232 mForceStatusBarTransparent = false;
Dianne Hackborn891d3fb2013-01-09 18:31:37 -08004233 mForcingShowNavBar = false;
4234 mForcingShowNavBarLayer = -1;
RoboErik8a2cfc32014-05-16 11:19:38 -07004235
Dianne Hackborn5f3063e2010-03-10 16:01:58 -08004236 mHideLockScreen = false;
4237 mAllowLockscreenWhenOn = false;
Craig Mautnerad09bcc2012-10-08 13:33:11 -07004238 mDismissKeyguard = DISMISS_KEYGUARD_NONE;
Dianne Hackborn7ad44382012-10-18 17:46:00 -07004239 mShowingLockscreen = false;
4240 mShowingDream = false;
Craig Mautnerc9457fa2014-06-06 14:27:48 -07004241 mWinShowWhenLocked = null;
Jim Millerab954542014-10-10 18:21:49 -07004242 mKeyguardSecure = isKeyguardSecure();
4243 mKeyguardSecureIncludingHidden = mKeyguardSecure
4244 && (mKeyguardDelegate != null && mKeyguardDelegate.isShowing());
Dianne Hackborn5f3063e2010-03-10 16:01:58 -08004245 }
4246
4247 /** {@inheritDoc} */
Craig Mautnerad09bcc2012-10-08 13:33:11 -07004248 @Override
Craig Mautnerc9457fa2014-06-06 14:27:48 -07004249 public void applyPostLayoutPolicyLw(WindowState win, WindowManager.LayoutParams attrs) {
Dianne Hackbornbc1aa7b2011-09-20 11:20:31 -07004250 if (DEBUG_LAYOUT) Slog.i(TAG, "Win " + win + ": isVisibleOrBehindKeyguardLw="
4251 + win.isVisibleOrBehindKeyguardLw());
John Spurlockc6d1c602014-01-17 15:22:06 -05004252 final int fl = PolicyControl.getWindowFlags(win, attrs);
John Spurlock414c1f02013-12-04 13:47:36 -05004253 if (mTopFullscreenOpaqueWindowState == null
4254 && win.isVisibleLw() && attrs.type == TYPE_INPUT_METHOD) {
4255 mForcingShowNavBar = true;
4256 mForcingShowNavBarLayer = win.getSurfaceLayer();
Dianne Hackborn891d3fb2013-01-09 18:31:37 -08004257 }
Selim Cinek4a4a2bddc2015-05-07 12:50:19 -07004258 if (attrs.type == TYPE_STATUS_BAR) {
4259 if ((attrs.privateFlags & PRIVATE_FLAG_KEYGUARD) != 0) {
4260 mForceStatusBarFromKeyguard = true;
4261 }
4262 if ((attrs.privateFlags & PRIVATE_FLAG_FORCE_STATUS_BAR_VISIBLE_TRANSPARENT) != 0) {
4263 mForceStatusBarTransparent = true;
4264 }
Jorim Jaggiafd4a552014-04-08 15:13:05 +02004265 }
Adrian Roos602c68e2015-04-24 16:03:47 -07004266
4267 boolean appWindow = attrs.type >= FIRST_APPLICATION_WINDOW
4268 && attrs.type < FIRST_SYSTEM_WINDOW;
4269 final boolean showWhenLocked = (fl & FLAG_SHOW_WHEN_LOCKED) != 0;
4270 final boolean dismissKeyguard = (fl & FLAG_DISMISS_KEYGUARD) != 0;
4271
Dianne Hackborn5f3063e2010-03-10 16:01:58 -08004272 if (mTopFullscreenOpaqueWindowState == null &&
Dianne Hackborn01b02a72012-01-12 14:05:03 -08004273 win.isVisibleOrBehindKeyguardLw() && !win.isGoneForLayoutLw()) {
John Spurlockc6d1c602014-01-17 15:22:06 -05004274 if ((fl & FLAG_FORCE_NOT_FULLSCREEN) != 0) {
Jorim Jaggi380ecb82014-03-14 17:25:20 +01004275 if ((attrs.privateFlags & PRIVATE_FLAG_KEYGUARD) != 0) {
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07004276 mForceStatusBarFromKeyguard = true;
4277 } else {
4278 mForceStatusBar = true;
4279 }
4280 }
Jorim Jaggi380ecb82014-03-14 17:25:20 +01004281 if ((attrs.privateFlags & PRIVATE_FLAG_KEYGUARD) != 0) {
Dianne Hackborn7ad44382012-10-18 17:46:00 -07004282 mShowingLockscreen = true;
Dianne Hackbornbc1aa7b2011-09-20 11:20:31 -07004283 }
Dianne Hackborn7ad44382012-10-18 17:46:00 -07004284 if (attrs.type == TYPE_DREAM) {
Jeff Brownc8018eb2012-10-29 21:33:27 -07004285 // If the lockscreen was showing when the dream started then wait
4286 // for the dream to draw before hiding the lockscreen.
4287 if (!mDreamingLockscreen
4288 || (win.isVisibleLw() && win.hasDrawnLw())) {
4289 mShowingDream = true;
Craig Mautnerab55e522014-03-03 13:26:03 -08004290 appWindow = true;
Dianne Hackborn7ad44382012-10-18 17:46:00 -07004291 }
4292 }
Craig Mautnerab55e522014-03-03 13:26:03 -08004293
Craig Mautnerab55e522014-03-03 13:26:03 -08004294 if (appWindow) {
Jorim Jaggic13fcac2014-09-11 17:36:57 +02004295 final IApplicationToken appToken = win.getAppToken();
4296 if (showWhenLocked) {
Craig Mautnerc9457fa2014-06-06 14:27:48 -07004297 // Remove any previous windows with the same appToken.
Jorim Jaggic13fcac2014-09-11 17:36:57 +02004298 mAppsToBeHidden.remove(appToken);
4299 mAppsThatDismissKeyguard.remove(appToken);
Craig Mautnerca0a1242014-12-02 12:25:14 -08004300 if (mAppsToBeHidden.isEmpty()) {
Craig Mautner192d6042014-12-02 23:24:48 -08004301 if (dismissKeyguard && !mKeyguardSecure) {
4302 mAppsThatDismissKeyguard.add(appToken);
4303 } else {
Craig Mautnerca0a1242014-12-02 12:25:14 -08004304 mWinShowWhenLocked = win;
4305 mHideLockScreen = true;
4306 mForceStatusBarFromKeyguard = false;
Craig Mautnerca0a1242014-12-02 12:25:14 -08004307 }
Craig Mautnerc9457fa2014-06-06 14:27:48 -07004308 }
Jorim Jaggic13fcac2014-09-11 17:36:57 +02004309 } else if (dismissKeyguard) {
Jim Millerab954542014-10-10 18:21:49 -07004310 if (mKeyguardSecure) {
Jorim Jaggic13fcac2014-09-11 17:36:57 +02004311 mAppsToBeHidden.add(appToken);
4312 } else {
4313 mAppsToBeHidden.remove(appToken);
4314 }
4315 mAppsThatDismissKeyguard.add(appToken);
Craig Mautner2bc789b2014-03-19 19:48:38 -07004316 } else {
Jorim Jaggic13fcac2014-09-11 17:36:57 +02004317 mAppsToBeHidden.add(appToken);
Craig Mautner2bc789b2014-03-19 19:48:38 -07004318 }
Craig Mautnerab55e522014-03-03 13:26:03 -08004319 if (attrs.x == 0 && attrs.y == 0
4320 && attrs.width == WindowManager.LayoutParams.MATCH_PARENT
4321 && attrs.height == WindowManager.LayoutParams.MATCH_PARENT) {
4322 if (DEBUG_LAYOUT) Slog.v(TAG, "Fullscreen window: " + win);
4323 mTopFullscreenOpaqueWindowState = win;
Adrian Rooscd3884d2015-02-18 17:25:23 +01004324 if (mTopFullscreenOpaqueOrDimmingWindowState == null) {
4325 mTopFullscreenOpaqueOrDimmingWindowState = win;
4326 }
Jorim Jaggic13fcac2014-09-11 17:36:57 +02004327 if (!mAppsThatDismissKeyguard.isEmpty() &&
4328 mDismissKeyguard == DISMISS_KEYGUARD_NONE) {
4329 if (DEBUG_LAYOUT) Slog.v(TAG,
4330 "Setting mDismissKeyguard true by win " + win);
tingna_sunge785ffa2015-05-12 13:23:15 +08004331 mDismissKeyguard = (mWinDismissingKeyguard == win
4332 && mSecureDismissingKeyguard == mKeyguardSecure)
4333 ? DISMISS_KEYGUARD_CONTINUE : DISMISS_KEYGUARD_START;
Jorim Jaggic13fcac2014-09-11 17:36:57 +02004334 mWinDismissingKeyguard = win;
tingna_sunge785ffa2015-05-12 13:23:15 +08004335 mSecureDismissingKeyguard = mKeyguardSecure;
Jim Millerab954542014-10-10 18:21:49 -07004336 mForceStatusBarFromKeyguard = mShowingLockscreen && mKeyguardSecure;
Jorim Jaggic13fcac2014-09-11 17:36:57 +02004337 } else if (mAppsToBeHidden.isEmpty() && showWhenLocked) {
4338 if (DEBUG_LAYOUT) Slog.v(TAG,
4339 "Setting mHideLockScreen to true by win " + win);
4340 mHideLockScreen = true;
4341 mForceStatusBarFromKeyguard = false;
Craig Mautnerab55e522014-03-03 13:26:03 -08004342 }
Craig Mautner00156ec2014-03-06 22:29:02 -08004343 if ((fl & FLAG_ALLOW_LOCK_WHILE_SCREEN_ON) != 0) {
Craig Mautnerab55e522014-03-03 13:26:03 -08004344 mAllowLockscreenWhenOn = true;
4345 }
Dianne Hackborn5f3063e2010-03-10 16:01:58 -08004346 }
Craig Mautnerc9457fa2014-06-06 14:27:48 -07004347
4348 if (mWinShowWhenLocked != null &&
Adrian Roos602c68e2015-04-24 16:03:47 -07004349 mWinShowWhenLocked.getAppToken() != win.getAppToken() &&
4350 (attrs.flags & FLAG_SHOW_WHEN_LOCKED) == 0) {
Craig Mautnerc9457fa2014-06-06 14:27:48 -07004351 win.hideLw(false);
4352 }
Dianne Hackborn5f3063e2010-03-10 16:01:58 -08004353 }
Adrian Roos602c68e2015-04-24 16:03:47 -07004354 } else if (mTopFullscreenOpaqueWindowState == null && mWinShowWhenLocked == null) {
4355 // No TopFullscreenOpaqueWindow is showing, but we found a SHOW_WHEN_LOCKED window
4356 // that is being hidden in an animation - keep the
4357 // keyguard hidden until the new window shows up and
4358 // we know whether to show the keyguard or not.
Adrian Roosb85e1ec2015-05-29 15:23:18 -07004359 if (win.isAnimatingLw() && appWindow && showWhenLocked && mKeyguardHidden) {
Adrian Roos602c68e2015-04-24 16:03:47 -07004360 mHideLockScreen = true;
4361 mWinShowWhenLocked = win;
4362 }
Dianne Hackborn5f3063e2010-03-10 16:01:58 -08004363 }
Adrian Rooscd3884d2015-02-18 17:25:23 +01004364 if (mTopFullscreenOpaqueOrDimmingWindowState == null
4365 && win.isVisibleOrBehindKeyguardLw() && !win.isGoneForLayoutLw()
4366 && win.isDimming()) {
4367 mTopFullscreenOpaqueOrDimmingWindowState = win;
4368 }
Dianne Hackborn5f3063e2010-03-10 16:01:58 -08004369 }
4370
4371 /** {@inheritDoc} */
Craig Mautnerad09bcc2012-10-08 13:33:11 -07004372 @Override
Craig Mautner39834192012-09-02 07:47:24 -07004373 public int finishPostLayoutPolicyLw() {
Craig Mautnerc5e73bf2015-04-21 15:41:26 +00004374 if (mWinShowWhenLocked != null && mTopFullscreenOpaqueWindowState != null &&
4375 mWinShowWhenLocked.getAppToken() != mTopFullscreenOpaqueWindowState.getAppToken()
4376 && isKeyguardLocked()) {
Craig Mautnerc9457fa2014-06-06 14:27:48 -07004377 // A dialog is dismissing the keyguard. Put the wallpaper behind it and hide the
4378 // fullscreen window.
4379 // TODO: Make sure FLAG_SHOW_WALLPAPER is restored when dialog is dismissed. Or not.
4380 mWinShowWhenLocked.getAttrs().flags |= FLAG_SHOW_WALLPAPER;
4381 mTopFullscreenOpaqueWindowState.hideLw(false);
4382 mTopFullscreenOpaqueWindowState = mWinShowWhenLocked;
4383 }
4384
Dianne Hackborn39c2d712009-09-22 11:41:31 -07004385 int changes = 0;
Joe Onorato93056472010-09-10 10:30:46 -04004386 boolean topIsFullscreen = false;
Daniel Sandlere02d8082010-10-08 15:13:22 -04004387
4388 final WindowManager.LayoutParams lp = (mTopFullscreenOpaqueWindowState != null)
4389 ? mTopFullscreenOpaqueWindowState.getAttrs()
4390 : null;
4391
Jeff Brownc8018eb2012-10-29 21:33:27 -07004392 // If we are not currently showing a dream then remember the current
4393 // lockscreen state. We will use this to determine whether the dream
4394 // started while the lockscreen was showing and remember this state
4395 // while the dream is showing.
Dianne Hackborn7ad44382012-10-18 17:46:00 -07004396 if (!mShowingDream) {
4397 mDreamingLockscreen = mShowingLockscreen;
Jeff Brown061ea992015-04-17 19:55:47 -07004398 if (mDreamingSleepTokenNeeded) {
4399 mDreamingSleepTokenNeeded = false;
4400 mHandler.obtainMessage(MSG_UPDATE_DREAMING_SLEEP_TOKEN, 0, 1).sendToTarget();
4401 }
4402 } else {
4403 if (!mDreamingSleepTokenNeeded) {
4404 mDreamingSleepTokenNeeded = true;
4405 mHandler.obtainMessage(MSG_UPDATE_DREAMING_SLEEP_TOKEN, 1, 1).sendToTarget();
4406 }
Dianne Hackborn7ad44382012-10-18 17:46:00 -07004407 }
4408
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004409 if (mStatusBar != null) {
Craig Mautnereda67292013-04-28 13:50:14 -07004410 if (DEBUG_LAYOUT) Slog.i(TAG, "force=" + mForceStatusBar
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07004411 + " forcefkg=" + mForceStatusBarFromKeyguard
Dianne Hackbornd70bc2f2009-10-06 23:25:51 -07004412 + " top=" + mTopFullscreenOpaqueWindowState);
Selim Cinek4a4a2bddc2015-05-07 12:50:19 -07004413 boolean shouldBeTransparent = mForceStatusBarTransparent
4414 && !mForceStatusBar
4415 && !mForceStatusBarFromKeyguard;
4416 if (!shouldBeTransparent) {
4417 mStatusBarController.setShowTransparent(false /* transparent */);
4418 } else if (!mStatusBar.isVisibleLw()) {
4419 mStatusBarController.setShowTransparent(true /* transparent */);
4420 }
4421 if (mForceStatusBar || mForceStatusBarFromKeyguard || mForceStatusBarTransparent) {
Craig Mautnereda67292013-04-28 13:50:14 -07004422 if (DEBUG_LAYOUT) Slog.v(TAG, "Showing status bar: forced");
John Spurlock27735a42013-08-14 17:57:38 -04004423 if (mStatusBarController.setBarShowingLw(true)) {
4424 changes |= FINISH_LAYOUT_REDO_LAYOUT;
4425 }
Craig Mautner81defc72013-10-29 11:10:42 -07004426 // Maintain fullscreen layout until incoming animation is complete.
4427 topIsFullscreen = mTopIsFullscreen && mStatusBar.isAnimatingLw();
John Spurlockf92b6162013-11-11 15:01:16 -05004428 // Transient status bar on the lockscreen is not allowed
4429 if (mForceStatusBarFromKeyguard && mStatusBarController.isTransientShowing()) {
4430 mStatusBarController.updateVisibilityLw(false /*transientAllowed*/,
4431 mLastSystemUiFlags, mLastSystemUiFlags);
4432 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004433 } else if (mTopFullscreenOpaqueWindowState != null) {
John Spurlockc6d1c602014-01-17 15:22:06 -05004434 final int fl = PolicyControl.getWindowFlags(null, lp);
Joe Onorato93056472010-09-10 10:30:46 -04004435 if (localLOGV) {
Craig Mautnereda67292013-04-28 13:50:14 -07004436 Slog.d(TAG, "frame: " + mTopFullscreenOpaqueWindowState.getFrameLw()
Joe Onorato93056472010-09-10 10:30:46 -04004437 + " shown frame: " + mTopFullscreenOpaqueWindowState.getShownFrameLw());
Craig Mautnereda67292013-04-28 13:50:14 -07004438 Slog.d(TAG, "attr: " + mTopFullscreenOpaqueWindowState.getAttrs()
John Spurlockc6d1c602014-01-17 15:22:06 -05004439 + " lp.flags=0x" + Integer.toHexString(fl));
Joe Onorato93056472010-09-10 10:30:46 -04004440 }
John Spurlockc6d1c602014-01-17 15:22:06 -05004441 topIsFullscreen = (fl & WindowManager.LayoutParams.FLAG_FULLSCREEN) != 0
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07004442 || (mLastSystemUiFlags & View.SYSTEM_UI_FLAG_FULLSCREEN) != 0;
Joe Onorato93056472010-09-10 10:30:46 -04004443 // The subtle difference between the window for mTopFullscreenOpaqueWindowState
Mark Dolinerd0646dc2014-08-27 16:04:02 -07004444 // and mTopIsFullscreen is that mTopIsFullscreen is set only if the window
Joe Onorato93056472010-09-10 10:30:46 -04004445 // has the FLAG_FULLSCREEN set. Not sure if there is another way that to be the
4446 // case though.
John Spurlock27735a42013-08-14 17:57:38 -04004447 if (mStatusBarController.isTransientShowing()) {
4448 if (mStatusBarController.setBarShowingLw(true)) {
John Spurlock32beb2c2013-03-11 10:16:47 -04004449 changes |= FINISH_LAYOUT_REDO_LAYOUT;
4450 }
4451 } else if (topIsFullscreen) {
Craig Mautnereda67292013-04-28 13:50:14 -07004452 if (DEBUG_LAYOUT) Slog.v(TAG, "** HIDING status bar");
John Spurlock27735a42013-08-14 17:57:38 -04004453 if (mStatusBarController.setBarShowingLw(false)) {
Dianne Hackbornf87d1962012-04-04 12:48:24 -07004454 changes |= FINISH_LAYOUT_REDO_LAYOUT;
Craig Mautnereda67292013-04-28 13:50:14 -07004455 } else {
Craig Mautnerc5a6e442013-06-05 17:22:35 -07004456 if (DEBUG_LAYOUT) Slog.v(TAG, "Status bar already hiding");
Daniel Sandler40427442010-07-16 11:44:52 -04004457 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004458 } else {
Craig Mautnereda67292013-04-28 13:50:14 -07004459 if (DEBUG_LAYOUT) Slog.v(TAG, "** SHOWING status bar: top is not fullscreen");
John Spurlock27735a42013-08-14 17:57:38 -04004460 if (mStatusBarController.setBarShowingLw(true)) {
4461 changes |= FINISH_LAYOUT_REDO_LAYOUT;
4462 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004463 }
4464 }
4465 }
Daniel Sandlere02d8082010-10-08 15:13:22 -04004466
Craig Mautner81defc72013-10-29 11:10:42 -07004467 if (mTopIsFullscreen != topIsFullscreen) {
4468 if (!topIsFullscreen) {
4469 // Force another layout when status bar becomes fully shown.
4470 changes |= FINISH_LAYOUT_REDO_LAYOUT;
4471 }
4472 mTopIsFullscreen = topIsFullscreen;
4473 }
Daniel Sandlere02d8082010-10-08 15:13:22 -04004474
Craig Mautner39834192012-09-02 07:47:24 -07004475 // Hide the key guard if a visible window explicitly specifies that it wants to be
4476 // displayed when the screen is locked.
Jorim Jaggi5cf17872014-03-26 18:31:48 +01004477 if (mKeyguardDelegate != null && mStatusBar != null) {
4478 if (localLOGV) Slog.v(TAG, "finishPostLayoutPolicyLw: mHideKeyguard="
4479 + mHideLockScreen);
Jim Millerab954542014-10-10 18:21:49 -07004480 if (mDismissKeyguard != DISMISS_KEYGUARD_NONE && !mKeyguardSecure) {
Jorim Jaggi5cf17872014-03-26 18:31:48 +01004481 mKeyguardHidden = true;
Jim Millerab954542014-10-10 18:21:49 -07004482 if (setKeyguardOccludedLw(true)) {
Dianne Hackborn39c2d712009-09-22 11:41:31 -07004483 changes |= FINISH_LAYOUT_REDO_LAYOUT
4484 | FINISH_LAYOUT_REDO_CONFIG
4485 | FINISH_LAYOUT_REDO_WALLPAPER;
4486 }
Jorim Jaggi5cf17872014-03-26 18:31:48 +01004487 if (mKeyguardDelegate.isShowing()) {
4488 mHandler.post(new Runnable() {
4489 @Override
4490 public void run() {
4491 mKeyguardDelegate.keyguardDone(false, false);
4492 }
4493 });
4494 }
4495 } else if (mHideLockScreen) {
4496 mKeyguardHidden = true;
Jorim Jaggi7d85ea92015-05-20 17:20:40 -07004497 mWinDismissingKeyguard = null;
Jim Millerab954542014-10-10 18:21:49 -07004498 if (setKeyguardOccludedLw(true)) {
Jorim Jaggi5cf17872014-03-26 18:31:48 +01004499 changes |= FINISH_LAYOUT_REDO_LAYOUT
4500 | FINISH_LAYOUT_REDO_CONFIG
4501 | FINISH_LAYOUT_REDO_WALLPAPER;
4502 }
4503 } else if (mDismissKeyguard != DISMISS_KEYGUARD_NONE) {
Jorim Jaggi7d85ea92015-05-20 17:20:40 -07004504 mKeyguardHidden = false;
4505 if (setKeyguardOccludedLw(false)) {
4506 changes |= FINISH_LAYOUT_REDO_LAYOUT
4507 | FINISH_LAYOUT_REDO_CONFIG
4508 | FINISH_LAYOUT_REDO_WALLPAPER;
4509 }
Jorim Jaggi5cf17872014-03-26 18:31:48 +01004510 if (mDismissKeyguard == DISMISS_KEYGUARD_START) {
4511 // Only launch the next keyguard unlock window once per window.
Jorim Jaggi5cf17872014-03-26 18:31:48 +01004512 mHandler.post(new Runnable() {
4513 @Override
4514 public void run() {
4515 mKeyguardDelegate.dismiss();
4516 }
4517 });
4518 }
4519 } else {
4520 mWinDismissingKeyguard = null;
tingna_sunge785ffa2015-05-12 13:23:15 +08004521 mSecureDismissingKeyguard = false;
Jorim Jaggi5cf17872014-03-26 18:31:48 +01004522 mKeyguardHidden = false;
Jim Millerab954542014-10-10 18:21:49 -07004523 if (setKeyguardOccludedLw(false)) {
Jorim Jaggi5cf17872014-03-26 18:31:48 +01004524 changes |= FINISH_LAYOUT_REDO_LAYOUT
4525 | FINISH_LAYOUT_REDO_CONFIG
4526 | FINISH_LAYOUT_REDO_WALLPAPER;
4527 }
Suchi Amalapurapu9cdc9032009-05-14 18:01:07 -07004528 }
4529 }
Joe Onorato664644d2011-01-23 17:53:23 -08004530
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07004531 if ((updateSystemUiVisibilityLw()&SYSTEM_UI_CHANGING_LAYOUT) != 0) {
Dianne Hackborndf89e652011-10-06 22:35:11 -07004532 // If the navigation bar has been hidden or shown, we need to do another
4533 // layout pass to update that window.
4534 changes |= FINISH_LAYOUT_REDO_LAYOUT;
4535 }
Joe Onorato664644d2011-01-23 17:53:23 -08004536
Mike Lockwood28569302010-01-28 11:54:40 -05004537 // update since mAllowLockscreenWhenOn might have changed
4538 updateLockScreenTimeout();
Dianne Hackborn39c2d712009-09-22 11:41:31 -07004539 return changes;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004540 }
4541
Jorim Jaggi380ecb82014-03-14 17:25:20 +01004542 /**
Jim Millerab954542014-10-10 18:21:49 -07004543 * Updates the occluded state of the Keyguard.
Jorim Jaggi380ecb82014-03-14 17:25:20 +01004544 *
Jorim Jaggi380ecb82014-03-14 17:25:20 +01004545 * @return Whether the flags have changed and we have to redo the layout.
4546 */
Jim Millerab954542014-10-10 18:21:49 -07004547 private boolean setKeyguardOccludedLw(boolean isOccluded) {
4548 boolean wasOccluded = mKeyguardOccluded;
4549 boolean showing = mKeyguardDelegate.isShowing();
4550 if (wasOccluded && !isOccluded && showing) {
4551 mKeyguardOccluded = false;
4552 mKeyguardDelegate.setOccluded(false);
Jorim Jaggi380ecb82014-03-14 17:25:20 +01004553 mStatusBar.getAttrs().privateFlags |= PRIVATE_FLAG_KEYGUARD;
4554 mStatusBar.getAttrs().flags |= FLAG_SHOW_WALLPAPER;
4555 return true;
Jim Millerab954542014-10-10 18:21:49 -07004556 } else if (!wasOccluded && isOccluded && showing) {
4557 mKeyguardOccluded = true;
4558 mKeyguardDelegate.setOccluded(true);
Jorim Jaggi380ecb82014-03-14 17:25:20 +01004559 mStatusBar.getAttrs().privateFlags &= ~PRIVATE_FLAG_KEYGUARD;
4560 mStatusBar.getAttrs().flags &= ~FLAG_SHOW_WALLPAPER;
4561 return true;
4562 } else {
4563 return false;
4564 }
4565 }
4566
4567 private boolean isStatusBarKeyguard() {
4568 return mStatusBar != null
4569 && (mStatusBar.getAttrs().privateFlags & PRIVATE_FLAG_KEYGUARD) != 0;
4570 }
4571
Jose Lima9546b202014-07-02 17:21:51 -07004572 @Override
Dianne Hackborn08743722009-12-21 12:16:51 -08004573 public boolean allowAppAnimationsLw() {
Jorim Jaggi380ecb82014-03-14 17:25:20 +01004574 if (isStatusBarKeyguard() || mShowingDream) {
Craig Mautner28816302013-10-10 20:31:00 -07004575 // If keyguard or dreams is currently visible, no reason to animate behind it.
Dianne Hackborn08743722009-12-21 12:16:51 -08004576 return false;
4577 }
Dianne Hackborn08743722009-12-21 12:16:51 -08004578 return true;
4579 }
4580
Jose Lima9546b202014-07-02 17:21:51 -07004581 @Override
Dianne Hackborndf89e652011-10-06 22:35:11 -07004582 public int focusChangedLw(WindowState lastFocus, WindowState newFocus) {
Joe Onorato664644d2011-01-23 17:53:23 -08004583 mFocusedWindow = newFocus;
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07004584 if ((updateSystemUiVisibilityLw()&SYSTEM_UI_CHANGING_LAYOUT) != 0) {
Dianne Hackborndf89e652011-10-06 22:35:11 -07004585 // If the navigation bar has been hidden or shown, we need to do another
4586 // layout pass to update that window.
4587 return FINISH_LAYOUT_REDO_LAYOUT;
4588 }
4589 return 0;
Joe Onorato664644d2011-01-23 17:53:23 -08004590 }
4591
Dianne Hackborn0ecadf72009-03-31 18:00:37 -07004592 /** {@inheritDoc} */
Jose Lima9546b202014-07-02 17:21:51 -07004593 @Override
Jeff Brown46b9ac02010-04-22 18:58:52 -07004594 public void notifyLidSwitchChanged(long whenNanos, boolean lidOpen) {
4595 // lid changed state
Jeff Brownc458ce92012-04-30 14:58:40 -07004596 final int newLidState = lidOpen ? LID_OPEN : LID_CLOSED;
4597 if (newLidState == mLidState) {
4598 return;
4599 }
Jeff Brown01a98dd2011-09-20 15:08:29 -07004600
Jeff Brownc458ce92012-04-30 14:58:40 -07004601 mLidState = newLidState;
4602 applyLidSwitchState();
Jeff Brown01a98dd2011-09-20 15:08:29 -07004603 updateRotation(true);
Jeff Brownc458ce92012-04-30 14:58:40 -07004604
4605 if (lidOpen) {
Bryce Lee584a4452014-10-21 15:55:55 -07004606 wakeUp(SystemClock.uptimeMillis(), mAllowTheaterModeWakeFromLidSwitch);
Jeff Brownc458ce92012-04-30 14:58:40 -07004607 } else if (!mLidControlsSleep) {
Jeff Brown96307042012-07-27 15:51:34 -07004608 mPowerManager.userActivity(SystemClock.uptimeMillis(), false);
Jeff Brown46b9ac02010-04-22 18:58:52 -07004609 }
4610 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004611
Michael Wright3818c922014-09-02 13:59:07 -07004612 @Override
4613 public void notifyCameraLensCoverSwitchChanged(long whenNanos, boolean lensCovered) {
4614 int lensCoverState = lensCovered ? CAMERA_LENS_COVERED : CAMERA_LENS_UNCOVERED;
4615 if (mCameraLensCoverState == lensCoverState) {
4616 return;
4617 }
4618 if (mCameraLensCoverState == CAMERA_LENS_COVERED &&
4619 lensCoverState == CAMERA_LENS_UNCOVERED) {
4620 Intent intent;
4621 final boolean keyguardActive = mKeyguardDelegate == null ? false :
4622 mKeyguardDelegate.isShowing();
4623 if (keyguardActive) {
4624 intent = new Intent(MediaStore.INTENT_ACTION_STILL_IMAGE_CAMERA_SECURE);
4625 } else {
4626 intent = new Intent(MediaStore.INTENT_ACTION_STILL_IMAGE_CAMERA);
4627 }
Bryce Lee584a4452014-10-21 15:55:55 -07004628 wakeUp(whenNanos / 1000000, mAllowTheaterModeWakeFromCameraLens);
Bart Sears8b1c27c2015-03-18 23:51:02 +00004629 startActivityAsUser(intent, UserHandle.CURRENT_OR_SELF);
Michael Wright3818c922014-09-02 13:59:07 -07004630 }
4631 mCameraLensCoverState = lensCoverState;
4632 }
4633
Dianne Hackbornad7fa7f2011-01-07 14:06:50 -08004634 void setHdmiPlugged(boolean plugged) {
4635 if (mHdmiPlugged != plugged) {
4636 mHdmiPlugged = plugged;
Dianne Hackbornf87d1962012-04-04 12:48:24 -07004637 updateRotation(true, true);
Dianne Hackbornad7fa7f2011-01-07 14:06:50 -08004638 Intent intent = new Intent(ACTION_HDMI_PLUGGED);
Joe Onoratodc100302011-01-11 17:07:41 -08004639 intent.addFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY_BEFORE_BOOT);
Dianne Hackbornad7fa7f2011-01-07 14:06:50 -08004640 intent.putExtra(EXTRA_HDMI_PLUGGED_STATE, plugged);
Dianne Hackborn5ac72a22012-08-29 18:32:08 -07004641 mContext.sendStickyBroadcastAsUser(intent, UserHandle.ALL);
Dianne Hackbornad7fa7f2011-01-07 14:06:50 -08004642 }
4643 }
4644
Joe Onoratoea495d42011-04-06 11:41:11 -07004645 void initializeHdmiState() {
Joe Onorato7ba631f2011-05-04 15:28:00 -07004646 boolean plugged = false;
Joe Onoratoea495d42011-04-06 11:41:11 -07004647 // watch for HDMI plug messages if the hdmi switch exists
4648 if (new File("/sys/devices/virtual/switch/hdmi/state").exists()) {
4649 mHDMIObserver.startObserving("DEVPATH=/devices/virtual/switch/hdmi");
4650
Joe Onoratoea495d42011-04-06 11:41:11 -07004651 final String filename = "/sys/class/switch/hdmi/state";
4652 FileReader reader = null;
4653 try {
4654 reader = new FileReader(filename);
4655 char[] buf = new char[15];
4656 int n = reader.read(buf);
4657 if (n > 1) {
4658 plugged = 0 != Integer.parseInt(new String(buf, 0, n-1));
4659 }
4660 } catch (IOException ex) {
4661 Slog.w(TAG, "Couldn't read hdmi state from " + filename + ": " + ex);
4662 } catch (NumberFormatException ex) {
4663 Slog.w(TAG, "Couldn't read hdmi state from " + filename + ": " + ex);
4664 } finally {
4665 if (reader != null) {
4666 try {
4667 reader.close();
4668 } catch (IOException ex) {
4669 }
Joe Onoratodc100302011-01-11 17:07:41 -08004670 }
4671 }
4672 }
Joe Onorato7ba631f2011-05-04 15:28:00 -07004673 // This dance forces the code in setHdmiPlugged to run.
4674 // Always do this so the sticky intent is stuck (to false) if there is no hdmi.
4675 mHdmiPlugged = !plugged;
4676 setHdmiPlugged(!mHdmiPlugged);
Joe Onoratodc100302011-01-11 17:07:41 -08004677 }
4678
Dianne Hackbornc0e3f242011-08-19 14:19:10 -07004679 final Object mScreenshotLock = new Object();
Dianne Hackbornfc8fa632011-08-17 16:20:47 -07004680 ServiceConnection mScreenshotConnection = null;
Dianne Hackbornfc8fa632011-08-17 16:20:47 -07004681
Jeff Brownd5bb82d2011-10-12 13:57:59 -07004682 final Runnable mScreenshotTimeout = new Runnable() {
4683 @Override public void run() {
4684 synchronized (mScreenshotLock) {
4685 if (mScreenshotConnection != null) {
4686 mContext.unbindService(mScreenshotConnection);
4687 mScreenshotConnection = null;
Dianne Hackbornfc8fa632011-08-17 16:20:47 -07004688 }
Winson Chung9112ec32011-06-27 13:15:32 -07004689 }
Jeff Brownd5bb82d2011-10-12 13:57:59 -07004690 }
4691 };
4692
4693 // Assume this is called from the Handler thread.
4694 private void takeScreenshot() {
4695 synchronized (mScreenshotLock) {
4696 if (mScreenshotConnection != null) {
4697 return;
4698 }
4699 ComponentName cn = new ComponentName("com.android.systemui",
4700 "com.android.systemui.screenshot.TakeScreenshotService");
4701 Intent intent = new Intent();
4702 intent.setComponent(cn);
4703 ServiceConnection conn = new ServiceConnection() {
4704 @Override
4705 public void onServiceConnected(ComponentName name, IBinder service) {
4706 synchronized (mScreenshotLock) {
4707 if (mScreenshotConnection != this) {
4708 return;
4709 }
4710 Messenger messenger = new Messenger(service);
4711 Message msg = Message.obtain(null, 1);
4712 final ServiceConnection myConn = this;
4713 Handler h = new Handler(mHandler.getLooper()) {
4714 @Override
4715 public void handleMessage(Message msg) {
4716 synchronized (mScreenshotLock) {
4717 if (mScreenshotConnection == myConn) {
4718 mContext.unbindService(mScreenshotConnection);
4719 mScreenshotConnection = null;
4720 mHandler.removeCallbacks(mScreenshotTimeout);
4721 }
4722 }
4723 }
4724 };
4725 msg.replyTo = new Messenger(h);
Winson Chunga63bb842011-10-17 10:26:28 -07004726 msg.arg1 = msg.arg2 = 0;
4727 if (mStatusBar != null && mStatusBar.isVisibleLw())
4728 msg.arg1 = 1;
4729 if (mNavigationBar != null && mNavigationBar.isVisibleLw())
4730 msg.arg2 = 1;
Jeff Brownd5bb82d2011-10-12 13:57:59 -07004731 try {
4732 messenger.send(msg);
4733 } catch (RemoteException e) {
4734 }
4735 }
4736 }
4737 @Override
4738 public void onServiceDisconnected(ComponentName name) {}
4739 };
Amith Yamasani27b89e62013-01-16 12:30:11 -08004740 if (mContext.bindServiceAsUser(
4741 intent, conn, Context.BIND_AUTO_CREATE, UserHandle.CURRENT)) {
Jeff Brownd5bb82d2011-10-12 13:57:59 -07004742 mScreenshotConnection = conn;
4743 mHandler.postDelayed(mScreenshotTimeout, 10000);
4744 }
4745 }
Winson Chung9112ec32011-06-27 13:15:32 -07004746 }
4747
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004748 /** {@inheritDoc} */
Jeff Brown00fa7bd2010-07-02 15:37:36 -07004749 @Override
Jeff Brown037c33e2014-04-09 00:31:55 -07004750 public int interceptKeyBeforeQueueing(KeyEvent event, int policyFlags) {
Jeff Brown96307042012-07-27 15:51:34 -07004751 if (!mSystemBooted) {
4752 // If we have not yet booted, don't let key events do anything.
4753 return 0;
4754 }
4755
Jeff Brown037c33e2014-04-09 00:31:55 -07004756 final boolean interactive = (policyFlags & FLAG_INTERACTIVE) != 0;
Jeff Brown1f245102010-11-18 20:53:46 -08004757 final boolean down = event.getAction() == KeyEvent.ACTION_DOWN;
4758 final boolean canceled = event.isCanceled();
4759 final int keyCode = event.getKeyCode();
Jeff Browne20c9e02010-10-11 14:20:19 -07004760
Jeff Brown3122e442010-10-11 23:32:49 -07004761 final boolean isInjected = (policyFlags & WindowManagerPolicy.FLAG_INJECTED) != 0;
Jeff Brown3122e442010-10-11 23:32:49 -07004762
Mike Lockwoodc72b15f2009-11-28 20:58:22 -05004763 // If screen is off then we treat the case where the keyguard is open but hidden
4764 // the same as if it were open and in front.
4765 // This will prevent any keys other than the power button from waking the screen
4766 // when the keyguard is hidden by another activity.
Jim Miller5ecd8112013-01-09 18:50:26 -08004767 final boolean keyguardActive = (mKeyguardDelegate == null ? false :
Jeff Brown037c33e2014-04-09 00:31:55 -07004768 (interactive ?
Jim Millerab954542014-10-10 18:21:49 -07004769 isKeyguardShowingAndNotOccluded() :
Jim Miller5ecd8112013-01-09 18:50:26 -08004770 mKeyguardDelegate.isShowing()));
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004771
Jeff Brown40013652012-05-16 21:22:36 -07004772 if (DEBUG_INPUT) {
Jeff Brown00fa7bd2010-07-02 15:37:36 -07004773 Log.d(TAG, "interceptKeyTq keycode=" + keyCode
Jeff Brown037c33e2014-04-09 00:31:55 -07004774 + " interactive=" + interactive + " keyguardActive=" + keyguardActive
Jeff Brown26875502014-01-30 21:47:47 -08004775 + " policyFlags=" + Integer.toHexString(policyFlags));
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004776 }
4777
Jeff Brown037c33e2014-04-09 00:31:55 -07004778 // Basic policy based on interactive state.
Jeff Brown4d396052010-10-29 21:50:21 -07004779 int result;
Michael Wright337d9d22014-04-22 15:03:48 -07004780 boolean isWakeKey = (policyFlags & WindowManagerPolicy.FLAG_WAKE) != 0
4781 || event.isWakeKey();
Michael Wrightfc01f042014-09-08 14:12:24 -07004782 if (interactive || (isInjected && !isWakeKey)) {
RoboErikde9ba392014-09-26 12:51:01 -07004783 // When the device is interactive or the key is injected pass the
4784 // key to the application.
Jeff Brown4d396052010-10-29 21:50:21 -07004785 result = ACTION_PASS_TO_USER;
Jose Lima9546b202014-07-02 17:21:51 -07004786 isWakeKey = false;
Michael Wrightfc01f042014-09-08 14:12:24 -07004787 } else if (!interactive && shouldDispatchInputWhenNonInteractive()) {
4788 // If we're currently dozing with the screen on and the keyguard showing, pass the key
4789 // to the application but preserve its wake key status to make sure we still move
4790 // from dozing to fully interactive if we would normally go from off to fully
4791 // interactive.
4792 result = ACTION_PASS_TO_USER;
Jeff Brown4d396052010-10-29 21:50:21 -07004793 } else {
4794 // When the screen is off and the key is not injected, determine whether
4795 // to wake the device but don't pass the key to the application.
4796 result = 0;
Jeff Brown26875502014-01-30 21:47:47 -08004797 if (isWakeKey && (!down || !isWakeKeyWhenScreenOff(keyCode))) {
4798 isWakeKey = false;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004799 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004800 }
4801
Justin Kohd378ad72013-04-01 12:18:26 -07004802 // If the key would be handled globally, just return the result, don't worry about special
4803 // key processing.
Jeff Brown13f00f02014-10-31 14:45:50 -07004804 if (isValidGlobalKey(keyCode)
4805 && mGlobalKeyManager.shouldHandleGlobalKey(keyCode, event)) {
Michael Wright85b1af62014-06-04 14:51:58 -07004806 if (isWakeKey) {
Jeff Brown13f00f02014-10-31 14:45:50 -07004807 wakeUp(event.getEventTime(), mAllowTheaterModeWakeFromKey);
Michael Wright85b1af62014-06-04 14:51:58 -07004808 }
Justin Kohd378ad72013-04-01 12:18:26 -07004809 return result;
4810 }
4811
Jeff Brownbae8e772014-06-12 19:59:45 -07004812 boolean useHapticFeedback = down
4813 && (policyFlags & WindowManagerPolicy.FLAG_VIRTUAL) != 0
4814 && event.getRepeatCount() == 0;
4815
Jeff Brown4d396052010-10-29 21:50:21 -07004816 // Handle special keys.
4817 switch (keyCode) {
4818 case KeyEvent.KEYCODE_VOLUME_DOWN:
Jeff Brownb0418da2010-11-01 15:24:01 -07004819 case KeyEvent.KEYCODE_VOLUME_UP:
4820 case KeyEvent.KEYCODE_VOLUME_MUTE: {
RoboErik001c59c2015-01-26 15:53:51 -08004821 if (mUseTvRouting) {
4822 // On TVs volume keys never go to the foreground app
4823 result &= ~ACTION_PASS_TO_USER;
4824 }
Jeff Brownd5bb82d2011-10-12 13:57:59 -07004825 if (keyCode == KeyEvent.KEYCODE_VOLUME_DOWN) {
4826 if (down) {
Jeff Brown13f00f02014-10-31 14:45:50 -07004827 if (interactive && !mScreenshotChordVolumeDownKeyTriggered
Jeff Brownd5bb82d2011-10-12 13:57:59 -07004828 && (event.getFlags() & KeyEvent.FLAG_FALLBACK) == 0) {
Jeff Brown13f00f02014-10-31 14:45:50 -07004829 mScreenshotChordVolumeDownKeyTriggered = true;
4830 mScreenshotChordVolumeDownKeyTime = event.getDownTime();
4831 mScreenshotChordVolumeDownKeyConsumed = false;
Jeff Brownd5bb82d2011-10-12 13:57:59 -07004832 cancelPendingPowerKeyAction();
4833 interceptScreenshotChord();
4834 }
4835 } else {
Jeff Brown13f00f02014-10-31 14:45:50 -07004836 mScreenshotChordVolumeDownKeyTriggered = false;
Jeff Brownd5bb82d2011-10-12 13:57:59 -07004837 cancelPendingScreenshotChordAction();
4838 }
4839 } else if (keyCode == KeyEvent.KEYCODE_VOLUME_UP) {
4840 if (down) {
Jeff Brown13f00f02014-10-31 14:45:50 -07004841 if (interactive && !mScreenshotChordVolumeUpKeyTriggered
Jeff Brownd5bb82d2011-10-12 13:57:59 -07004842 && (event.getFlags() & KeyEvent.FLAG_FALLBACK) == 0) {
Jeff Brown13f00f02014-10-31 14:45:50 -07004843 mScreenshotChordVolumeUpKeyTriggered = true;
Jeff Brownd5bb82d2011-10-12 13:57:59 -07004844 cancelPendingPowerKeyAction();
4845 cancelPendingScreenshotChordAction();
4846 }
4847 } else {
Jeff Brown13f00f02014-10-31 14:45:50 -07004848 mScreenshotChordVolumeUpKeyTriggered = false;
Jeff Brownd5bb82d2011-10-12 13:57:59 -07004849 cancelPendingScreenshotChordAction();
4850 }
4851 }
Jeff Brown4d396052010-10-29 21:50:21 -07004852 if (down) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -07004853 TelecomManager telecomManager = getTelecommService();
4854 if (telecomManager != null) {
4855 if (telecomManager.isRinging()) {
Santos Cordon6848f722014-05-21 15:22:12 -07004856 // If an incoming call is ringing, either VOLUME key means
4857 // "silence ringer". We handle these keys here, rather than
4858 // in the InCallScreen, to make sure we'll respond to them
4859 // even if the InCallScreen hasn't come to the foreground yet.
4860 // Look for the DOWN event here, to agree with the "fallback"
4861 // behavior in the InCallScreen.
4862 Log.i(TAG, "interceptKeyBeforeQueueing:"
4863 + " VOLUME key-down while ringing: Silence ringer!");
Jeff Brown4d396052010-10-29 21:50:21 -07004864
Santos Cordon6848f722014-05-21 15:22:12 -07004865 // Silence the ringer. (It's safe to call this
4866 // even if the ringer has already been silenced.)
Tyler Gunnef9f6f92014-09-12 22:16:17 -07004867 telecomManager.silenceRinger();
Jeff Brown4d396052010-10-29 21:50:21 -07004868
Santos Cordon6848f722014-05-21 15:22:12 -07004869 // And *don't* pass this key thru to the current activity
4870 // (which is probably the InCallScreen.)
4871 result &= ~ACTION_PASS_TO_USER;
4872 break;
4873 }
Tyler Gunnef9f6f92014-09-12 22:16:17 -07004874 if (telecomManager.isInCall()
Santos Cordon6848f722014-05-21 15:22:12 -07004875 && (result & ACTION_PASS_TO_USER) == 0) {
4876 // If we are in call but we decided not to pass the key to
RoboErik430fc482014-06-12 15:49:20 -07004877 // the application, just pass it to the session service.
4878
4879 MediaSessionLegacyHelper.getHelper(mContext)
RoboErik3c45c292014-07-08 16:47:31 -07004880 .sendVolumeKeyEvent(event, false);
Santos Cordon6848f722014-05-21 15:22:12 -07004881 break;
Jeff Brown4d396052010-10-29 21:50:21 -07004882 }
4883 }
4884
RoboErik430fc482014-06-12 15:49:20 -07004885 if ((result & ACTION_PASS_TO_USER) == 0) {
RoboErik001c59c2015-01-26 15:53:51 -08004886 if (mUseTvRouting) {
4887 dispatchDirectAudioEvent(event);
4888 } else {
4889 // If we aren't passing to the user and no one else
4890 // handled it send it to the session manager to
4891 // figure out.
4892 MediaSessionLegacyHelper.getHelper(mContext)
4893 .sendVolumeKeyEvent(event, true);
4894 }
Jeff Brown4d396052010-10-29 21:50:21 -07004895 break;
4896 }
4897 }
4898 break;
4899 }
4900
4901 case KeyEvent.KEYCODE_ENDCALL: {
4902 result &= ~ACTION_PASS_TO_USER;
4903 if (down) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -07004904 TelecomManager telecomManager = getTelecommService();
Jeff Brown4d396052010-10-29 21:50:21 -07004905 boolean hungUp = false;
Tyler Gunnef9f6f92014-09-12 22:16:17 -07004906 if (telecomManager != null) {
4907 hungUp = telecomManager.endCall();
Jeff Brown4d396052010-10-29 21:50:21 -07004908 }
Jeff Brown13f00f02014-10-31 14:45:50 -07004909 if (interactive && !hungUp) {
4910 mEndCallKeyHandled = false;
4911 mHandler.postDelayed(mEndCallLongPress,
4912 ViewConfiguration.get(mContext).getDeviceGlobalActionKeyTimeout());
4913 } else {
4914 mEndCallKeyHandled = true;
4915 }
Jeff Brown4d396052010-10-29 21:50:21 -07004916 } else {
Jeff Brown13f00f02014-10-31 14:45:50 -07004917 if (!mEndCallKeyHandled) {
4918 mHandler.removeCallbacks(mEndCallLongPress);
4919 if (!canceled) {
4920 if ((mEndcallBehavior
4921 & Settings.System.END_BUTTON_BEHAVIOR_HOME) != 0) {
4922 if (goHome()) {
4923 break;
4924 }
Dianne Hackborn0041e972009-07-24 17:14:43 -07004925 }
Jeff Brown13f00f02014-10-31 14:45:50 -07004926 if ((mEndcallBehavior
4927 & Settings.System.END_BUTTON_BEHAVIOR_SLEEP) != 0) {
4928 mPowerManager.goToSleep(event.getEventTime(),
4929 PowerManager.GO_TO_SLEEP_REASON_POWER_BUTTON, 0);
4930 isWakeKey = false;
4931 }
Jeff Brown4d396052010-10-29 21:50:21 -07004932 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004933 }
Jeff Brown4d396052010-10-29 21:50:21 -07004934 }
4935 break;
4936 }
4937
4938 case KeyEvent.KEYCODE_POWER: {
4939 result &= ~ACTION_PASS_TO_USER;
Jeff Brown13f00f02014-10-31 14:45:50 -07004940 isWakeKey = false; // wake-up will be handled separately
Jeff Brown4d396052010-10-29 21:50:21 -07004941 if (down) {
Jeff Brown13f00f02014-10-31 14:45:50 -07004942 interceptPowerKeyDown(event, interactive);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004943 } else {
Jeff Brown13f00f02014-10-31 14:45:50 -07004944 interceptPowerKeyUp(event, interactive, canceled);
Jeff Brown4d396052010-10-29 21:50:21 -07004945 }
4946 break;
4947 }
4948
Jeff Brown6212a492014-03-07 13:58:47 -08004949 case KeyEvent.KEYCODE_SLEEP: {
4950 result &= ~ACTION_PASS_TO_USER;
Filip Gruszczynskia483a1d2015-03-17 19:06:58 +00004951 isWakeKey = false;
Jeff Brownbae8e772014-06-12 19:59:45 -07004952 if (!mPowerManager.isInteractive()) {
4953 useHapticFeedback = false; // suppress feedback if already non-interactive
4954 }
Nick Vaccarob593a812015-05-15 11:23:05 -07004955 if (down) {
4956 sleepPress(event.getEventTime());
4957 } else {
4958 sleepRelease(event.getEventTime());
4959 }
Jeff Brown6212a492014-03-07 13:58:47 -08004960 break;
4961 }
4962
4963 case KeyEvent.KEYCODE_WAKEUP: {
4964 result &= ~ACTION_PASS_TO_USER;
Jose Lima9546b202014-07-02 17:21:51 -07004965 isWakeKey = true;
Jeff Brown6212a492014-03-07 13:58:47 -08004966 break;
4967 }
4968
Jeff Brown4d396052010-10-29 21:50:21 -07004969 case KeyEvent.KEYCODE_MEDIA_PLAY:
4970 case KeyEvent.KEYCODE_MEDIA_PAUSE:
4971 case KeyEvent.KEYCODE_MEDIA_PLAY_PAUSE:
Jeff Brown4d396052010-10-29 21:50:21 -07004972 case KeyEvent.KEYCODE_HEADSETHOOK:
4973 case KeyEvent.KEYCODE_MUTE:
4974 case KeyEvent.KEYCODE_MEDIA_STOP:
4975 case KeyEvent.KEYCODE_MEDIA_NEXT:
4976 case KeyEvent.KEYCODE_MEDIA_PREVIOUS:
4977 case KeyEvent.KEYCODE_MEDIA_REWIND:
4978 case KeyEvent.KEYCODE_MEDIA_RECORD:
Jaekyun Seokbfdad8e2013-07-08 13:53:21 +09004979 case KeyEvent.KEYCODE_MEDIA_FAST_FORWARD:
4980 case KeyEvent.KEYCODE_MEDIA_AUDIO_TRACK: {
RoboErikde9ba392014-09-26 12:51:01 -07004981 if (MediaSessionLegacyHelper.getHelper(mContext).isGlobalPriorityActive()) {
4982 // If the global session is active pass all media keys to it
4983 // instead of the active window.
4984 result &= ~ACTION_PASS_TO_USER;
4985 }
Jeff Brown4d396052010-10-29 21:50:21 -07004986 if ((result & ACTION_PASS_TO_USER) == 0) {
4987 // Only do this if we would otherwise not pass it to the user. In that
4988 // case, the PhoneWindow class will do the same thing, except it will
4989 // only do it if the showing app doesn't process the key on its own.
Jeff Brown40013652012-05-16 21:22:36 -07004990 // Note that we need to make a copy of the key event here because the
4991 // original key event will be recycled when we return.
Jeff Brown4d396052010-10-29 21:50:21 -07004992 mBroadcastWakeLock.acquire();
Jeff Brown40013652012-05-16 21:22:36 -07004993 Message msg = mHandler.obtainMessage(MSG_DISPATCH_MEDIA_KEY_WITH_WAKE_LOCK,
4994 new KeyEvent(event));
4995 msg.setAsynchronous(true);
4996 msg.sendToTarget();
Jeff Brown4d396052010-10-29 21:50:21 -07004997 }
4998 break;
Jeff Brown00fa7bd2010-07-02 15:37:36 -07004999 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005000
Jeff Brown4d396052010-10-29 21:50:21 -07005001 case KeyEvent.KEYCODE_CALL: {
5002 if (down) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -07005003 TelecomManager telecomManager = getTelecommService();
5004 if (telecomManager != null) {
5005 if (telecomManager.isRinging()) {
Santos Cordon6848f722014-05-21 15:22:12 -07005006 Log.i(TAG, "interceptKeyBeforeQueueing:"
5007 + " CALL key-down while ringing: Answer the call!");
Tyler Gunnef9f6f92014-09-12 22:16:17 -07005008 telecomManager.acceptRingingCall();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005009
Santos Cordon6848f722014-05-21 15:22:12 -07005010 // And *don't* pass this key thru to the current activity
5011 // (which is presumably the InCallScreen.)
5012 result &= ~ACTION_PASS_TO_USER;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005013 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005014 }
Jeff Brown00fa7bd2010-07-02 15:37:36 -07005015 }
Jeff Brown4d396052010-10-29 21:50:21 -07005016 break;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005017 }
Michael Wright869a67c2014-08-26 19:33:06 -07005018 case KeyEvent.KEYCODE_VOICE_ASSIST: {
5019 // Only do this if we would otherwise not pass it to the user. In that case,
5020 // interceptKeyBeforeDispatching would apply a similar but different policy in
5021 // order to invoke voice assist actions. Note that we need to make a copy of the
5022 // key event here because the original key event will be recycled when we return.
5023 if ((result & ACTION_PASS_TO_USER) == 0 && !down) {
5024 mBroadcastWakeLock.acquire();
5025 Message msg = mHandler.obtainMessage(MSG_LAUNCH_VOICE_ASSIST_WITH_WAKE_LOCK,
5026 keyguardActive ? 1 : 0, 0);
5027 msg.setAsynchronous(true);
5028 msg.sendToTarget();
5029 }
5030 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005031 }
Jeff Brown26875502014-01-30 21:47:47 -08005032
Jeff Brownbae8e772014-06-12 19:59:45 -07005033 if (useHapticFeedback) {
5034 performHapticFeedbackLw(null, HapticFeedbackConstants.VIRTUAL_KEY, false);
5035 }
5036
Jeff Brown26875502014-01-30 21:47:47 -08005037 if (isWakeKey) {
Jeff Brown13f00f02014-10-31 14:45:50 -07005038 wakeUp(event.getEventTime(), mAllowTheaterModeWakeFromKey);
Jeff Brown26875502014-01-30 21:47:47 -08005039 }
Bryce Lee584a4452014-10-21 15:55:55 -07005040
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005041 return result;
5042 }
5043
Jeff Brown1c2e4942012-11-06 16:32:01 -08005044 /**
Jeff Brown13f00f02014-10-31 14:45:50 -07005045 * Returns true if the key can have global actions attached to it.
5046 * We reserve all power management keys for the system since they require
5047 * very careful handling.
5048 */
5049 private static boolean isValidGlobalKey(int keyCode) {
5050 switch (keyCode) {
5051 case KeyEvent.KEYCODE_POWER:
5052 case KeyEvent.KEYCODE_WAKEUP:
5053 case KeyEvent.KEYCODE_SLEEP:
5054 return false;
5055 default:
5056 return true;
5057 }
5058 }
5059
5060 /**
Jeff Brown1c2e4942012-11-06 16:32:01 -08005061 * When the screen is off we ignore some keys that might otherwise typically
5062 * be considered wake keys. We filter them out here.
5063 *
5064 * {@link KeyEvent#KEYCODE_POWER} is notably absent from this list because it
5065 * is always considered a wake key.
5066 */
5067 private boolean isWakeKeyWhenScreenOff(int keyCode) {
5068 switch (keyCode) {
5069 // ignore volume keys unless docked
5070 case KeyEvent.KEYCODE_VOLUME_UP:
5071 case KeyEvent.KEYCODE_VOLUME_DOWN:
5072 case KeyEvent.KEYCODE_VOLUME_MUTE:
5073 return mDockMode != Intent.EXTRA_DOCK_STATE_UNDOCKED;
5074
5075 // ignore media and camera keys
5076 case KeyEvent.KEYCODE_MUTE:
5077 case KeyEvent.KEYCODE_HEADSETHOOK:
5078 case KeyEvent.KEYCODE_MEDIA_PLAY:
5079 case KeyEvent.KEYCODE_MEDIA_PAUSE:
5080 case KeyEvent.KEYCODE_MEDIA_PLAY_PAUSE:
5081 case KeyEvent.KEYCODE_MEDIA_STOP:
5082 case KeyEvent.KEYCODE_MEDIA_NEXT:
5083 case KeyEvent.KEYCODE_MEDIA_PREVIOUS:
5084 case KeyEvent.KEYCODE_MEDIA_REWIND:
5085 case KeyEvent.KEYCODE_MEDIA_RECORD:
5086 case KeyEvent.KEYCODE_MEDIA_FAST_FORWARD:
Jaekyun Seokbfdad8e2013-07-08 13:53:21 +09005087 case KeyEvent.KEYCODE_MEDIA_AUDIO_TRACK:
Jeff Brown1c2e4942012-11-06 16:32:01 -08005088 case KeyEvent.KEYCODE_CAMERA:
5089 return false;
5090 }
5091 return true;
5092 }
5093
5094
Jeff Brown56194eb2011-03-02 19:23:13 -08005095 /** {@inheritDoc} */
5096 @Override
Michael Wright70af00a2014-09-03 19:30:20 -07005097 public int interceptMotionBeforeQueueingNonInteractive(long whenNanos, int policyFlags) {
5098 if ((policyFlags & FLAG_WAKE) != 0) {
Bryce Lee5c138322014-11-03 08:26:09 -08005099 if (wakeUp(whenNanos / 1000000, mAllowTheaterModeWakeFromMotion)) {
5100 return 0;
5101 }
Michael Wright70af00a2014-09-03 19:30:20 -07005102 }
Bryce Lee5c138322014-11-03 08:26:09 -08005103
Michael Wright70af00a2014-09-03 19:30:20 -07005104 if (shouldDispatchInputWhenNonInteractive()) {
5105 return ACTION_PASS_TO_USER;
5106 }
Bryce Lee5c138322014-11-03 08:26:09 -08005107
Bryce Lee812d7022014-11-10 13:33:28 -08005108 // If we have not passed the action up and we are in theater mode without dreaming,
5109 // there will be no dream to intercept the touch and wake into ambient. The device should
5110 // wake up in this case.
5111 if (isTheaterModeEnabled() && (policyFlags & FLAG_WAKE) != 0) {
5112 wakeUp(whenNanos / 1000000, mAllowTheaterModeWakeFromMotionWhenNotDreaming);
5113 }
5114
Jeff Brown037c33e2014-04-09 00:31:55 -07005115 return 0;
Jeff Brown56194eb2011-03-02 19:23:13 -08005116 }
5117
Michael Wright70af00a2014-09-03 19:30:20 -07005118 private boolean shouldDispatchInputWhenNonInteractive() {
Bryce Lee5c138322014-11-03 08:26:09 -08005119 // Send events to keyguard while the screen is on.
Jim Millerab954542014-10-10 18:21:49 -07005120 if (isKeyguardShowingAndNotOccluded() && mDisplay != null
5121 && mDisplay.getState() != Display.STATE_OFF) {
Bryce Lee5c138322014-11-03 08:26:09 -08005122 return true;
5123 }
5124
5125 // Send events to a dozing dream even if the screen is off since the dream
5126 // is in control of the state of the screen.
5127 IDreamManager dreamManager = getDreamManager();
5128
5129 try {
5130 if (dreamManager != null && dreamManager.isDreaming()) {
5131 return true;
5132 }
5133 } catch (RemoteException e) {
5134 Slog.e(TAG, "RemoteException when checking if dreaming", e);
5135 }
5136
5137 // Otherwise, consume events since the user can't see what is being
5138 // interacted with.
5139 return false;
Michael Wright70af00a2014-09-03 19:30:20 -07005140 }
5141
RoboErik001c59c2015-01-26 15:53:51 -08005142 private void dispatchDirectAudioEvent(KeyEvent event) {
5143 if (event.getAction() != KeyEvent.ACTION_DOWN) {
5144 return;
5145 }
5146 int keyCode = event.getKeyCode();
John Spurlockb94f2d62015-03-17 14:11:57 -04005147 int flags = AudioManager.FLAG_SHOW_UI | AudioManager.FLAG_PLAY_SOUND
5148 | AudioManager.FLAG_FROM_KEY;
RoboErik001c59c2015-01-26 15:53:51 -08005149 String pkgName = mContext.getOpPackageName();
5150 switch (keyCode) {
5151 case KeyEvent.KEYCODE_VOLUME_UP:
5152 try {
John Spurlockee5ad722015-03-03 16:17:21 -05005153 getAudioService().adjustSuggestedStreamVolume(AudioManager.ADJUST_RAISE,
John Spurlock90874332015-03-10 16:00:54 -04005154 AudioManager.USE_DEFAULT_STREAM_TYPE, flags, pkgName, TAG);
RoboErik001c59c2015-01-26 15:53:51 -08005155 } catch (RemoteException e) {
5156 Log.e(TAG, "Error dispatching volume up in dispatchTvAudioEvent.", e);
5157 }
5158 break;
5159 case KeyEvent.KEYCODE_VOLUME_DOWN:
5160 try {
John Spurlockee5ad722015-03-03 16:17:21 -05005161 getAudioService().adjustSuggestedStreamVolume(AudioManager.ADJUST_LOWER,
John Spurlock90874332015-03-10 16:00:54 -04005162 AudioManager.USE_DEFAULT_STREAM_TYPE, flags, pkgName, TAG);
RoboErik001c59c2015-01-26 15:53:51 -08005163 } catch (RemoteException e) {
5164 Log.e(TAG, "Error dispatching volume down in dispatchTvAudioEvent.", e);
5165 }
5166 break;
5167 case KeyEvent.KEYCODE_VOLUME_MUTE:
5168 try {
5169 if (event.getRepeatCount() == 0) {
John Spurlockee5ad722015-03-03 16:17:21 -05005170 getAudioService().adjustSuggestedStreamVolume(
5171 AudioManager.ADJUST_TOGGLE_MUTE,
John Spurlock90874332015-03-10 16:00:54 -04005172 AudioManager.USE_DEFAULT_STREAM_TYPE, flags, pkgName, TAG);
RoboErik001c59c2015-01-26 15:53:51 -08005173 }
5174 } catch (RemoteException e) {
5175 Log.e(TAG, "Error dispatching mute in dispatchTvAudioEvent.", e);
5176 }
5177 break;
5178 }
5179 }
5180
Jeff Brown40013652012-05-16 21:22:36 -07005181 void dispatchMediaKeyWithWakeLock(KeyEvent event) {
5182 if (DEBUG_INPUT) {
5183 Slog.d(TAG, "dispatchMediaKeyWithWakeLock: " + event);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005184 }
5185
Jeff Brown40013652012-05-16 21:22:36 -07005186 if (mHavePendingMediaKeyRepeatWithWakeLock) {
5187 if (DEBUG_INPUT) {
5188 Slog.d(TAG, "dispatchMediaKeyWithWakeLock: canceled repeat");
5189 }
5190
5191 mHandler.removeMessages(MSG_DISPATCH_MEDIA_KEY_REPEAT_WITH_WAKE_LOCK);
5192 mHavePendingMediaKeyRepeatWithWakeLock = false;
5193 mBroadcastWakeLock.release(); // pending repeat was holding onto the wake lock
5194 }
5195
5196 dispatchMediaKeyWithWakeLockToAudioService(event);
5197
5198 if (event.getAction() == KeyEvent.ACTION_DOWN
5199 && event.getRepeatCount() == 0) {
5200 mHavePendingMediaKeyRepeatWithWakeLock = true;
5201
5202 Message msg = mHandler.obtainMessage(
5203 MSG_DISPATCH_MEDIA_KEY_REPEAT_WITH_WAKE_LOCK, event);
5204 msg.setAsynchronous(true);
5205 mHandler.sendMessageDelayed(msg, ViewConfiguration.getKeyRepeatTimeout());
5206 } else {
5207 mBroadcastWakeLock.release();
5208 }
5209 }
5210
5211 void dispatchMediaKeyRepeatWithWakeLock(KeyEvent event) {
5212 mHavePendingMediaKeyRepeatWithWakeLock = false;
5213
5214 KeyEvent repeatEvent = KeyEvent.changeTimeRepeat(event,
5215 SystemClock.uptimeMillis(), 1, event.getFlags() | KeyEvent.FLAG_LONG_PRESS);
5216 if (DEBUG_INPUT) {
5217 Slog.d(TAG, "dispatchMediaKeyRepeatWithWakeLock: " + repeatEvent);
5218 }
5219
5220 dispatchMediaKeyWithWakeLockToAudioService(repeatEvent);
5221 mBroadcastWakeLock.release();
5222 }
5223
5224 void dispatchMediaKeyWithWakeLockToAudioService(KeyEvent event) {
5225 if (ActivityManagerNative.isSystemReady()) {
RoboErik430fc482014-06-12 15:49:20 -07005226 MediaSessionLegacyHelper.getHelper(mContext).sendMediaButtonEvent(event, true);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005227 }
5228 }
5229
Michael Wright869a67c2014-08-26 19:33:06 -07005230 void launchVoiceAssistWithWakeLock(boolean keyguardActive) {
Dianne Hackbornb6683c42015-06-18 17:40:33 -07005231 IDeviceIdleController dic = IDeviceIdleController.Stub.asInterface(
5232 ServiceManager.getService(Context.DEVICE_IDLE_CONTROLLER));
5233 if (dic != null) {
5234 try {
5235 dic.exitIdle("voice-search");
5236 } catch (RemoteException e) {
5237 }
5238 }
Michael Wright869a67c2014-08-26 19:33:06 -07005239 Intent voiceIntent =
5240 new Intent(RecognizerIntent.ACTION_VOICE_SEARCH_HANDS_FREE);
5241 voiceIntent.putExtra(RecognizerIntent.EXTRA_SECURE, keyguardActive);
Bart Sears8b1c27c2015-03-18 23:51:02 +00005242 startActivityAsUser(voiceIntent, UserHandle.CURRENT_OR_SELF);
Michael Wright869a67c2014-08-26 19:33:06 -07005243 mBroadcastWakeLock.release();
5244 }
5245
Mike Lockwood1753f7f2009-08-24 14:49:07 -07005246 BroadcastReceiver mDockReceiver = new BroadcastReceiver() {
Craig Mautnereee29c42013-01-17 14:44:34 -08005247 @Override
Mike Lockwood1753f7f2009-08-24 14:49:07 -07005248 public void onReceive(Context context, Intent intent) {
Dianne Hackborn867ab6472010-04-29 13:28:56 -07005249 if (Intent.ACTION_DOCK_EVENT.equals(intent.getAction())) {
5250 mDockMode = intent.getIntExtra(Intent.EXTRA_DOCK_STATE,
5251 Intent.EXTRA_DOCK_STATE_UNDOCKED);
Daniel Sandler6396c722013-04-16 20:19:09 -04005252 } else {
5253 try {
5254 IUiModeManager uiModeService = IUiModeManager.Stub.asInterface(
5255 ServiceManager.getService(Context.UI_MODE_SERVICE));
5256 mUiMode = uiModeService.getCurrentModeType();
5257 } catch (RemoteException e) {
5258 }
Dianne Hackborn80fa1662009-10-07 14:02:10 -07005259 }
Jeff Brown01a98dd2011-09-20 15:08:29 -07005260 updateRotation(true);
Craig Mautnereee29c42013-01-17 14:44:34 -08005261 synchronized (mLock) {
5262 updateOrientationListenerLp();
5263 }
Mike Lockwood1753f7f2009-08-24 14:49:07 -07005264 }
5265 };
5266
Jeff Brown6aaf2952012-10-05 16:01:08 -07005267 BroadcastReceiver mDreamReceiver = new BroadcastReceiver() {
5268 @Override
5269 public void onReceive(Context context, Intent intent) {
5270 if (Intent.ACTION_DREAMING_STARTED.equals(intent.getAction())) {
Jim Miller5ecd8112013-01-09 18:50:26 -08005271 if (mKeyguardDelegate != null) {
5272 mKeyguardDelegate.onDreamingStarted();
Jeff Brown6aaf2952012-10-05 16:01:08 -07005273 }
5274 } else if (Intent.ACTION_DREAMING_STOPPED.equals(intent.getAction())) {
Jim Miller5ecd8112013-01-09 18:50:26 -08005275 if (mKeyguardDelegate != null) {
5276 mKeyguardDelegate.onDreamingStopped();
Jeff Brown6aaf2952012-10-05 16:01:08 -07005277 }
5278 }
5279 }
5280 };
5281
Christopher Tate5e08af02012-09-21 17:17:22 -07005282 BroadcastReceiver mMultiuserReceiver = new BroadcastReceiver() {
5283 @Override
5284 public void onReceive(Context context, Intent intent) {
5285 if (Intent.ACTION_USER_SWITCHED.equals(intent.getAction())) {
5286 // tickle the settings observer: this first ensures that we're
5287 // observing the relevant settings for the newly-active user,
5288 // and then updates our own bookkeeping based on the now-
5289 // current user.
5290 mSettingsObserver.onChange(false);
John Spurlockce479d82012-11-29 09:52:21 -05005291
5292 // force a re-application of focused window sysui visibility.
5293 // the window may never have been shown for this user
5294 // e.g. the keyguard when going through the new-user setup flow
John Spurlock04db1762013-05-13 12:46:41 -04005295 synchronized (mWindowManagerFuncs.getWindowManagerLock()) {
John Spurlockce479d82012-11-29 09:52:21 -05005296 mLastSystemUiFlags = 0;
5297 updateSystemUiVisibilityLw();
5298 }
Christopher Tate5e08af02012-09-21 17:17:22 -07005299 }
5300 }
5301 };
5302
Adrian Roosddc8b272015-05-21 16:28:27 -07005303 private final Runnable mHiddenNavPanic = new Runnable() {
John Spurlockd9b70bd2014-02-06 17:02:44 -05005304 @Override
5305 public void run() {
Adrian Roosddc8b272015-05-21 16:28:27 -07005306 synchronized (mWindowManagerFuncs.getWindowManagerLock()) {
5307 if (!isUserSetupComplete()) {
5308 // Swipe-up for navigation bar is disabled during setup
5309 return;
5310 }
5311 mPendingPanicGestureUptime = SystemClock.uptimeMillis();
5312 mNavigationBarController.showTransient();
5313 }
John Spurlockd9b70bd2014-02-06 17:02:44 -05005314 }
5315 };
5316
John Spurlocke1f366f2013-08-05 12:22:40 -04005317 private void requestTransientBars(WindowState swipeTarget) {
John Spurlock04db1762013-05-13 12:46:41 -04005318 synchronized (mWindowManagerFuncs.getWindowManagerLock()) {
Maurice Lam99c6e072014-04-28 18:24:28 -07005319 if (!isUserSetupComplete()) {
5320 // Swipe-up for navigation bar is disabled during setup
5321 return;
5322 }
John Spurlock27735a42013-08-14 17:57:38 -04005323 boolean sb = mStatusBarController.checkShowTransientBarLw();
5324 boolean nb = mNavigationBarController.checkShowTransientBarLw();
John Spurlockad3e6cb2013-04-30 08:47:43 -04005325 if (sb || nb) {
Adrian Roos62b65e42015-02-25 18:05:34 +01005326 // Don't show status bar when swiping on already visible navigation bar
5327 if (!nb && swipeTarget == mNavigationBar) {
John Spurlocke1f366f2013-08-05 12:22:40 -04005328 if (DEBUG) Slog.d(TAG, "Not showing transient bar, wrong swipe target");
John Spurlockad3e6cb2013-04-30 08:47:43 -04005329 return;
5330 }
John Spurlock27735a42013-08-14 17:57:38 -04005331 if (sb) mStatusBarController.showTransient();
5332 if (nb) mNavigationBarController.showTransient();
John Spurlockf1a36642013-10-12 17:50:42 -04005333 mImmersiveModeConfirmation.confirmCurrentPrompt();
John Spurlockad3e6cb2013-04-30 08:47:43 -04005334 updateSystemUiVisibilityLw();
John Spurlock32beb2c2013-03-11 10:16:47 -04005335 }
John Spurlockad3e6cb2013-04-30 08:47:43 -04005336 }
5337 }
5338
Jeff Brown3ee549c2014-09-22 20:14:39 -07005339 // Called on the PowerManager's Notifier thread.
Jeff Brownc38c9be2012-10-04 13:16:19 -07005340 @Override
Jeff Brown416c49c2015-05-26 19:50:18 -07005341 public void startedGoingToSleep(int why) {
5342 if (DEBUG_WAKEUP) Slog.i(TAG, "Started going to sleep... (why=" + why + ")");
Jorim Jaggid175b6c2015-05-27 15:39:09 -07005343 if (mKeyguardDelegate != null) {
5344 mKeyguardDelegate.onStartedGoingToSleep(why);
5345 }
Jeff Brown416c49c2015-05-26 19:50:18 -07005346 }
5347
5348 // Called on the PowerManager's Notifier thread.
5349 @Override
5350 public void finishedGoingToSleep(int why) {
Dianne Hackborn74489012009-03-24 20:50:09 -07005351 EventLog.writeEvent(70000, 0);
Jeff Brown416c49c2015-05-26 19:50:18 -07005352 if (DEBUG_WAKEUP) Slog.i(TAG, "Finished going to sleep... (why=" + why + ")");
Chris Wren9bb290b2015-06-29 12:02:13 -04005353 MetricsLogger.histogram(mContext, "screen_timeout", mLockScreenTimeout / 1000);
Jeff Brown3ee549c2014-09-22 20:14:39 -07005354
5355 // We must get this work done here because the power manager will drop
5356 // the wake lock and let the system suspend once this function returns.
The Android Open Source Project0727d222009-03-11 12:11:58 -07005357 synchronized (mLock) {
Jeff Brown3ee549c2014-09-22 20:14:39 -07005358 mAwake = false;
5359 mKeyguardDrawComplete = false;
Jeff Browna20dda42014-05-27 20:57:24 -07005360 updateWakeGestureListenerLp();
The Android Open Source Project0727d222009-03-11 12:11:58 -07005361 updateOrientationListenerLp();
Mike Lockwood28569302010-01-28 11:54:40 -05005362 updateLockScreenTimeout();
The Android Open Source Project0727d222009-03-11 12:11:58 -07005363 }
Jeff Brown3ee549c2014-09-22 20:14:39 -07005364 if (mKeyguardDelegate != null) {
Jorim Jaggid175b6c2015-05-27 15:39:09 -07005365 mKeyguardDelegate.onFinishedGoingToSleep(why);
Jeff Brown3ee549c2014-09-22 20:14:39 -07005366 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005367 }
5368
Jeff Brown3ee549c2014-09-22 20:14:39 -07005369 // Called on the PowerManager's Notifier thread.
Jeff Brownc38c9be2012-10-04 13:16:19 -07005370 @Override
Jeff Brown416c49c2015-05-26 19:50:18 -07005371 public void startedWakingUp() {
Dianne Hackborn74489012009-03-24 20:50:09 -07005372 EventLog.writeEvent(70000, 1);
Jeff Brown416c49c2015-05-26 19:50:18 -07005373 if (DEBUG_WAKEUP) Slog.i(TAG, "Started waking up...");
Craig Mautner8a0da012014-05-31 15:13:37 -07005374
Jeff Brown3ee549c2014-09-22 20:14:39 -07005375 // Since goToSleep performs these functions synchronously, we must
5376 // do the same here. We cannot post this work to a handler because
5377 // that might cause it to become reordered with respect to what
5378 // may happen in a future call to goToSleep.
The Android Open Source Project0727d222009-03-11 12:11:58 -07005379 synchronized (mLock) {
Jeff Brown3ee549c2014-09-22 20:14:39 -07005380 mAwake = true;
5381 mKeyguardDrawComplete = false;
5382 if (mKeyguardDelegate != null) {
5383 mHandler.removeMessages(MSG_KEYGUARD_DRAWN_TIMEOUT);
5384 mHandler.sendEmptyMessageDelayed(MSG_KEYGUARD_DRAWN_TIMEOUT, 1000);
5385 }
5386
Jeff Browna20dda42014-05-27 20:57:24 -07005387 updateWakeGestureListenerLp();
The Android Open Source Project0727d222009-03-11 12:11:58 -07005388 updateOrientationListenerLp();
Mike Lockwood28569302010-01-28 11:54:40 -05005389 updateLockScreenTimeout();
The Android Open Source Project0727d222009-03-11 12:11:58 -07005390 }
Jeff Brownc38c9be2012-10-04 13:16:19 -07005391
Jim Miller5ecd8112013-01-09 18:50:26 -08005392 if (mKeyguardDelegate != null) {
Jorim Jaggid175b6c2015-05-27 15:39:09 -07005393 mKeyguardDelegate.onStartedWakingUp(mKeyguardDelegateCallback);
Jeff Brown36c4db82014-09-19 12:05:31 -07005394 // ... eventually calls finishKeyguardDrawn
Jeff Brownc38c9be2012-10-04 13:16:19 -07005395 } else {
Craig Mautner8a0da012014-05-31 15:13:37 -07005396 if (DEBUG_WAKEUP) Slog.d(TAG, "null mKeyguardDelegate: setting mKeyguardDrawComplete.");
Jeff Brown36c4db82014-09-19 12:05:31 -07005397 finishKeyguardDrawn();
Jeff Brownc38c9be2012-10-04 13:16:19 -07005398 }
Jeff Brown36c4db82014-09-19 12:05:31 -07005399 }
5400
Jeff Brown416c49c2015-05-26 19:50:18 -07005401 // Called on the PowerManager's Notifier thread.
5402 @Override
5403 public void finishedWakingUp() {
5404 if (DEBUG_WAKEUP) Slog.i(TAG, "Finished waking up...");
5405 }
5406
5407 private void wakeUpFromPowerKey(long eventTime) {
5408 wakeUp(eventTime, mAllowTheaterModeWakeFromPowerKey);
5409 }
5410
5411 private boolean wakeUp(long wakeTime, boolean wakeInTheaterMode) {
Bryce Leed3896842015-06-23 17:06:51 -07005412 final boolean theaterModeEnabled = isTheaterModeEnabled();
5413 if (!wakeInTheaterMode && theaterModeEnabled) {
Jeff Brown416c49c2015-05-26 19:50:18 -07005414 return false;
5415 }
5416
Bryce Leed3896842015-06-23 17:06:51 -07005417 if (theaterModeEnabled) {
5418 Settings.Global.putInt(mContext.getContentResolver(),
5419 Settings.Global.THEATER_MODE_ON, 0);
5420 }
5421
Jeff Brown416c49c2015-05-26 19:50:18 -07005422 mPowerManager.wakeUp(wakeTime);
5423 return true;
5424 }
5425
Jeff Brown36c4db82014-09-19 12:05:31 -07005426 private void finishKeyguardDrawn() {
Jeff Brown3ee549c2014-09-22 20:14:39 -07005427 synchronized (mLock) {
5428 if (!mAwake || mKeyguardDrawComplete) {
Stefan Kuhne9326dc12015-06-12 09:25:32 -10005429 return; // We are not awake yet or we have already informed of this event.
Jeff Brown3ee549c2014-09-22 20:14:39 -07005430 }
5431
Jeff Brown36c4db82014-09-19 12:05:31 -07005432 mKeyguardDrawComplete = true;
Jeff Brown3ee549c2014-09-22 20:14:39 -07005433 if (mKeyguardDelegate != null) {
5434 mHandler.removeMessages(MSG_KEYGUARD_DRAWN_TIMEOUT);
5435 }
5436 }
5437
5438 finishScreenTurningOn();
5439 }
5440
5441 // Called on the DisplayManager's DisplayPowerController thread.
5442 @Override
5443 public void screenTurnedOff() {
5444 if (DEBUG_WAKEUP) Slog.i(TAG, "Screen turned off...");
5445
Jeff Brown48d1b142015-06-10 16:36:03 -07005446 updateScreenOffSleepToken(true);
Jeff Brown3ee549c2014-09-22 20:14:39 -07005447 synchronized (mLock) {
5448 mScreenOnEarly = false;
5449 mScreenOnFully = false;
5450 mWindowManagerDrawComplete = false;
5451 mScreenOnListener = null;
5452 updateOrientationListenerLp();
Jeff Brown36c4db82014-09-19 12:05:31 -07005453 }
5454 }
5455
Jeff Brown3ee549c2014-09-22 20:14:39 -07005456 // Called on the DisplayManager's DisplayPowerController thread.
Jeff Brown36c4db82014-09-19 12:05:31 -07005457 @Override
5458 public void screenTurningOn(final ScreenOnListener screenOnListener) {
Jeff Brown36c4db82014-09-19 12:05:31 -07005459 if (DEBUG_WAKEUP) Slog.i(TAG, "Screen turning on...");
Jeff Brown36c4db82014-09-19 12:05:31 -07005460
Jeff Brown48d1b142015-06-10 16:36:03 -07005461 updateScreenOffSleepToken(false);
Jeff Brown3ee549c2014-09-22 20:14:39 -07005462 synchronized (mLock) {
5463 mScreenOnEarly = true;
5464 mScreenOnFully = false;
5465 mWindowManagerDrawComplete = false;
5466 mScreenOnListener = screenOnListener;
Jeff Brown3ee549c2014-09-22 20:14:39 -07005467 }
Jeff Brown36c4db82014-09-19 12:05:31 -07005468
Craig Mautnerc3daedd2014-09-13 11:17:23 -07005469 mWindowManagerInternal.waitForAllWindowsDrawn(mWindowManagerDrawCallback,
5470 WAITING_FOR_DRAWN_TIMEOUT);
Stefan Kuhne9326dc12015-06-12 09:25:32 -10005471 // ... eventually calls finishWindowsDrawn which will finalize our screen turn on
5472 // as well as enabling the orientation change logic/sensor.
Jeff Brown36c4db82014-09-19 12:05:31 -07005473 }
5474
Jeff Brown36c4db82014-09-19 12:05:31 -07005475 private void finishWindowsDrawn() {
Jeff Brown3ee549c2014-09-22 20:14:39 -07005476 synchronized (mLock) {
5477 if (!mScreenOnEarly || mWindowManagerDrawComplete) {
Stefan Kuhne9326dc12015-06-12 09:25:32 -10005478 return; // Screen is not turned on or we did already handle this case earlier.
Jeff Brown3ee549c2014-09-22 20:14:39 -07005479 }
5480
Jeff Brown36c4db82014-09-19 12:05:31 -07005481 mWindowManagerDrawComplete = true;
Jeff Brown36c4db82014-09-19 12:05:31 -07005482 }
Jeff Brown3ee549c2014-09-22 20:14:39 -07005483
5484 finishScreenTurningOn();
Jeff Brownc38c9be2012-10-04 13:16:19 -07005485 }
5486
Craig Mautner8a0da012014-05-31 15:13:37 -07005487 private void finishScreenTurningOn() {
Stefan Kuhne9326dc12015-06-12 09:25:32 -10005488 synchronized (mLock) {
5489 // We have just finished drawing screen content. Since the orientation listener
5490 // gets only installed when all windows are drawn, we try to install it again.
5491 updateOrientationListenerLp();
5492 }
Jeff Brown3ee549c2014-09-22 20:14:39 -07005493 final ScreenOnListener listener;
5494 final boolean enableScreen;
Jeff Brown36c4db82014-09-19 12:05:31 -07005495 synchronized (mLock) {
Jeff Brown3ee549c2014-09-22 20:14:39 -07005496 if (DEBUG_WAKEUP) Slog.d(TAG,
5497 "finishScreenTurningOn: mAwake=" + mAwake
5498 + ", mScreenOnEarly=" + mScreenOnEarly
5499 + ", mScreenOnFully=" + mScreenOnFully
5500 + ", mKeyguardDrawComplete=" + mKeyguardDrawComplete
5501 + ", mWindowManagerDrawComplete=" + mWindowManagerDrawComplete);
5502
5503 if (mScreenOnFully || !mScreenOnEarly || !mWindowManagerDrawComplete
5504 || (mAwake && !mKeyguardDrawComplete)) {
5505 return; // spurious or not ready yet
Jeff Brown36c4db82014-09-19 12:05:31 -07005506 }
5507
Jeff Brown3ee549c2014-09-22 20:14:39 -07005508 if (DEBUG_WAKEUP) Slog.i(TAG, "Finished screen turning on...");
5509 listener = mScreenOnListener;
Craig Mautner13f6ea72014-06-23 14:57:02 -07005510 mScreenOnListener = null;
Jeff Brown3ee549c2014-09-22 20:14:39 -07005511 mScreenOnFully = true;
5512
5513 // Remember the first time we draw the keyguard so we know when we're done with
5514 // the main part of booting and can enable the screen and hide boot messages.
5515 if (!mKeyguardDrawnOnce && mAwake) {
5516 mKeyguardDrawnOnce = true;
5517 enableScreen = true;
5518 if (mBootMessageNeedsHiding) {
5519 mBootMessageNeedsHiding = false;
5520 hideBootMessages();
5521 }
5522 } else {
5523 enableScreen = false;
5524 }
Jeff Brownc38c9be2012-10-04 13:16:19 -07005525 }
5526
Jeff Brown3ee549c2014-09-22 20:14:39 -07005527 if (listener != null) {
5528 listener.onScreenOn();
5529 }
Jeff Brown4fc45272012-10-10 18:28:14 -07005530
Jeff Brown3ee549c2014-09-22 20:14:39 -07005531 if (enableScreen) {
5532 try {
5533 mWindowManager.enableScreenIfNeeded();
5534 } catch (RemoteException unhandled) {
Jeff Brown36c4db82014-09-19 12:05:31 -07005535 }
Craig Mautnera631d492014-08-05 15:16:01 -07005536 }
5537 }
5538
5539 private void handleHideBootMessage() {
Jeff Brown3ee549c2014-09-22 20:14:39 -07005540 synchronized (mLock) {
5541 if (!mKeyguardDrawnOnce) {
5542 mBootMessageNeedsHiding = true;
5543 return; // keyguard hasn't drawn the first time yet, not done booting
5544 }
Craig Mautnera631d492014-08-05 15:16:01 -07005545 }
Jeff Brown3ee549c2014-09-22 20:14:39 -07005546
5547 if (mBootMsgDialog != null) {
5548 if (DEBUG_WAKEUP) Slog.d(TAG, "handleHideBootMessage: dismissing");
5549 mBootMsgDialog.dismiss();
5550 mBootMsgDialog = null;
Craig Mautnera631d492014-08-05 15:16:01 -07005551 }
Jeff Brownc38c9be2012-10-04 13:16:19 -07005552 }
5553
5554 @Override
Jeff Brown3ee549c2014-09-22 20:14:39 -07005555 public boolean isScreenOn() {
5556 return mScreenOnFully;
Dianne Hackborn08743722009-12-21 12:16:51 -08005557 }
Jeff Brownc38c9be2012-10-04 13:16:19 -07005558
Dianne Hackborn08743722009-12-21 12:16:51 -08005559 /** {@inheritDoc} */
Jose Lima9546b202014-07-02 17:21:51 -07005560 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005561 public void enableKeyguard(boolean enabled) {
Jim Miller5ecd8112013-01-09 18:50:26 -08005562 if (mKeyguardDelegate != null) {
5563 mKeyguardDelegate.setKeyguardEnabled(enabled);
Mike Lockwood3a74bd32011-08-12 13:55:22 -07005564 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005565 }
5566
5567 /** {@inheritDoc} */
Jose Lima9546b202014-07-02 17:21:51 -07005568 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005569 public void exitKeyguardSecurely(OnKeyguardExitResult callback) {
Jim Miller5ecd8112013-01-09 18:50:26 -08005570 if (mKeyguardDelegate != null) {
5571 mKeyguardDelegate.verifyUnlock(callback);
Mike Lockwood3a74bd32011-08-12 13:55:22 -07005572 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005573 }
5574
Jim Millerab954542014-10-10 18:21:49 -07005575 private boolean isKeyguardShowingAndNotOccluded() {
Jim Miller5ecd8112013-01-09 18:50:26 -08005576 if (mKeyguardDelegate == null) return false;
Jim Millerab954542014-10-10 18:21:49 -07005577 return mKeyguardDelegate.isShowing() && !mKeyguardOccluded;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005578 }
5579
Mike Lockwood520d8bc2011-02-18 13:23:13 -05005580 /** {@inheritDoc} */
Jose Lima9546b202014-07-02 17:21:51 -07005581 @Override
Mike Lockwood520d8bc2011-02-18 13:23:13 -05005582 public boolean isKeyguardLocked() {
5583 return keyguardOn();
5584 }
5585
5586 /** {@inheritDoc} */
Jose Lima9546b202014-07-02 17:21:51 -07005587 @Override
Mike Lockwood520d8bc2011-02-18 13:23:13 -05005588 public boolean isKeyguardSecure() {
Jim Miller5ecd8112013-01-09 18:50:26 -08005589 if (mKeyguardDelegate == null) return false;
5590 return mKeyguardDelegate.isSecure();
Mike Lockwood520d8bc2011-02-18 13:23:13 -05005591 }
5592
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005593 /** {@inheritDoc} */
Jose Lima9546b202014-07-02 17:21:51 -07005594 @Override
Adrian Roos461829d2015-06-03 14:41:18 -07005595 public boolean isKeyguardShowingOrOccluded() {
5596 return mKeyguardDelegate == null ? false : mKeyguardDelegate.isShowing();
5597 }
5598
5599 /** {@inheritDoc} */
5600 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005601 public boolean inKeyguardRestrictedKeyInputMode() {
Jim Miller5ecd8112013-01-09 18:50:26 -08005602 if (mKeyguardDelegate == null) return false;
5603 return mKeyguardDelegate.isInputRestricted();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005604 }
5605
Jose Lima9546b202014-07-02 17:21:51 -07005606 @Override
Dianne Hackborn90c52de2011-09-23 12:57:44 -07005607 public void dismissKeyguardLw() {
RoboErik8a2cfc32014-05-16 11:19:38 -07005608 if (mKeyguardDelegate != null && mKeyguardDelegate.isShowing()) {
Craig Mautnerc0d2d0a2014-10-31 16:25:15 -07005609 if (DEBUG_KEYGUARD) Slog.d(TAG, "PWM.dismissKeyguardLw");
Daniel Sandler1ce804392012-11-07 15:07:12 -05005610 mHandler.post(new Runnable() {
Jose Lima9546b202014-07-02 17:21:51 -07005611 @Override
Daniel Sandler1ce804392012-11-07 15:07:12 -05005612 public void run() {
Jorim Jaggi8de4311c2014-08-11 22:36:20 +02005613 // ask the keyguard to prompt the user to authenticate if necessary
5614 mKeyguardDelegate.dismiss();
5615 }
5616 });
5617 }
5618 }
5619
5620 public void notifyActivityDrawnForKeyguardLw() {
5621 if (mKeyguardDelegate != null) {
5622 mHandler.post(new Runnable() {
5623 @Override
5624 public void run() {
5625 mKeyguardDelegate.onActivityDrawn();
Daniel Sandler1ce804392012-11-07 15:07:12 -05005626 }
5627 });
Dianne Hackborn90c52de2011-09-23 12:57:44 -07005628 }
5629 }
5630
Jorim Jaggicff0acb2014-03-31 16:35:15 +02005631 @Override
5632 public boolean isKeyguardDrawnLw() {
5633 synchronized (mLock) {
Jeff Brown3ee549c2014-09-22 20:14:39 -07005634 return mKeyguardDrawnOnce;
Jorim Jaggicff0acb2014-03-31 16:35:15 +02005635 }
5636 }
5637
Jorim Jaggi0d674622014-05-21 01:34:15 +02005638 @Override
Jorim Jaggie29b2db2014-05-30 23:17:03 +02005639 public void startKeyguardExitAnimation(long startTime, long fadeoutDuration) {
Jorim Jaggi0d674622014-05-21 01:34:15 +02005640 if (mKeyguardDelegate != null) {
Craig Mautnerc0d2d0a2014-10-31 16:25:15 -07005641 if (DEBUG_KEYGUARD) Slog.d(TAG, "PWM.startKeyguardExitAnimation");
Jorim Jaggie29b2db2014-05-30 23:17:03 +02005642 mKeyguardDelegate.startKeyguardExitAnimation(startTime, fadeoutDuration);
Jorim Jaggi0d674622014-05-21 01:34:15 +02005643 }
5644 }
5645
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005646 void sendCloseSystemWindows() {
Jorim Jaggib10e33f2015-02-04 21:57:40 +01005647 PhoneWindow.sendCloseSystemWindows(mContext, null);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005648 }
5649
5650 void sendCloseSystemWindows(String reason) {
Jorim Jaggib10e33f2015-02-04 21:57:40 +01005651 PhoneWindow.sendCloseSystemWindows(mContext, reason);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005652 }
Mitsuru Oshima831d0d92009-06-16 18:27:18 -07005653
Jeff Brown01a98dd2011-09-20 15:08:29 -07005654 @Override
5655 public int rotationForOrientationLw(int orientation, int lastRotation) {
Daniel Sandler2ed6ad62011-02-22 14:54:17 -05005656 if (false) {
5657 Slog.v(TAG, "rotationForOrientationLw(orient="
5658 + orientation + ", last=" + lastRotation
5659 + "); user=" + mUserRotation + " "
5660 + ((mUserRotationMode == WindowManagerPolicy.USER_ROTATION_LOCKED)
5661 ? "USER_ROTATION_LOCKED" : "")
5662 );
5663 }
5664
Craig Mautner46ac6fa2013-08-01 10:06:34 -07005665 if (mForceDefaultOrientation) {
5666 return Surface.ROTATION_0;
5667 }
5668
The Android Open Source Project0727d222009-03-11 12:11:58 -07005669 synchronized (mLock) {
Jeff Brownc0347aa2011-09-23 17:26:09 -07005670 int sensorRotation = mOrientationListener.getProposedRotation(); // may be -1
5671 if (sensorRotation < 0) {
Jeff Brown0f862b42012-09-27 21:11:01 -07005672 sensorRotation = lastRotation;
Jeff Brownc0347aa2011-09-23 17:26:09 -07005673 }
Jeff Brown01a98dd2011-09-20 15:08:29 -07005674
Jeff Browndec6cf42011-11-15 14:08:20 -08005675 final int preferredRotation;
Jeff Brown2e7760e2012-04-11 15:14:55 -07005676 if (mLidState == LID_OPEN && mLidOpenRotation >= 0) {
Jeff Brown01a98dd2011-09-20 15:08:29 -07005677 // Ignore sensor when lid switch is open and rotation is forced.
5678 preferredRotation = mLidOpenRotation;
5679 } else if (mDockMode == Intent.EXTRA_DOCK_STATE_CAR
Jeff Brownc0347aa2011-09-23 17:26:09 -07005680 && (mCarDockEnablesAccelerometer || mCarDockRotation >= 0)) {
Jeff Brown01a98dd2011-09-20 15:08:29 -07005681 // Ignore sensor when in car dock unless explicitly enabled.
5682 // This case can override the behavior of NOSENSOR, and can also
5683 // enable 180 degree rotation while docked.
Jeff Brownc0347aa2011-09-23 17:26:09 -07005684 preferredRotation = mCarDockEnablesAccelerometer
Jeff Brown01a98dd2011-09-20 15:08:29 -07005685 ? sensorRotation : mCarDockRotation;
Jeff Brown1a693182011-11-08 14:44:16 -08005686 } else if ((mDockMode == Intent.EXTRA_DOCK_STATE_DESK
5687 || mDockMode == Intent.EXTRA_DOCK_STATE_LE_DESK
5688 || mDockMode == Intent.EXTRA_DOCK_STATE_HE_DESK)
Jeff Brownc0347aa2011-09-23 17:26:09 -07005689 && (mDeskDockEnablesAccelerometer || mDeskDockRotation >= 0)) {
Jeff Brown01a98dd2011-09-20 15:08:29 -07005690 // Ignore sensor when in desk dock unless explicitly enabled.
5691 // This case can override the behavior of NOSENSOR, and can also
5692 // enable 180 degree rotation while docked.
Jeff Brownc0347aa2011-09-23 17:26:09 -07005693 preferredRotation = mDeskDockEnablesAccelerometer
Jeff Brown01a98dd2011-09-20 15:08:29 -07005694 ? sensorRotation : mDeskDockRotation;
Jeff Brownc82c89ed2013-04-17 17:18:15 -07005695 } else if (mHdmiPlugged && mDemoHdmiRotationLock) {
5696 // Ignore sensor when plugged into HDMI when demo HDMI rotation lock enabled.
Jeff Browneb3e4b92011-12-06 19:54:24 -08005697 // Note that the dock orientation overrides the HDMI orientation.
Jeff Brownc82c89ed2013-04-17 17:18:15 -07005698 preferredRotation = mDemoHdmiRotation;
5699 } else if (mHdmiPlugged && mDockMode == Intent.EXTRA_DOCK_STATE_UNDOCKED
5700 && mUndockedHdmiRotation >= 0) {
5701 // Ignore sensor when plugged into HDMI and an undocked orientation has
5702 // been specified in the configuration (only for legacy devices without
5703 // full multi-display support).
5704 // Note that the dock orientation overrides the HDMI orientation.
5705 preferredRotation = mUndockedHdmiRotation;
Chong Zhangae6119ff2014-11-11 18:54:39 -08005706 } else if (mDemoRotationLock) {
5707 // Ignore sensor when demo rotation lock is enabled.
5708 // Note that the dock orientation and HDMI rotation lock override this.
5709 preferredRotation = mDemoRotation;
Dianne Hackbornb9ec1ac2013-04-10 17:34:25 -07005710 } else if (orientation == ActivityInfo.SCREEN_ORIENTATION_LOCKED) {
5711 // Application just wants to remain locked in the last rotation.
5712 preferredRotation = lastRotation;
Jeff Brownbcdfc622014-03-06 19:13:04 -08005713 } else if (!mSupportAutoRotation) {
5714 // If we don't support auto-rotation then bail out here and ignore
5715 // the sensor and any rotation lock settings.
5716 preferredRotation = -1;
Jeff Brown207673cd2012-06-05 17:47:11 -07005717 } else if ((mUserRotationMode == WindowManagerPolicy.USER_ROTATION_FREE
Jeff Brown01a98dd2011-09-20 15:08:29 -07005718 && (orientation == ActivityInfo.SCREEN_ORIENTATION_USER
Dianne Hackbornb9ec1ac2013-04-10 17:34:25 -07005719 || orientation == ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED
5720 || orientation == ActivityInfo.SCREEN_ORIENTATION_USER_LANDSCAPE
5721 || orientation == ActivityInfo.SCREEN_ORIENTATION_USER_PORTRAIT
5722 || orientation == ActivityInfo.SCREEN_ORIENTATION_FULL_USER))
Jeff Brown01a98dd2011-09-20 15:08:29 -07005723 || orientation == ActivityInfo.SCREEN_ORIENTATION_SENSOR
5724 || orientation == ActivityInfo.SCREEN_ORIENTATION_FULL_SENSOR
5725 || orientation == ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE
5726 || orientation == ActivityInfo.SCREEN_ORIENTATION_SENSOR_PORTRAIT) {
5727 // Otherwise, use sensor only if requested by the application or enabled
5728 // by default for USER or UNSPECIFIED modes. Does not apply to NOSENSOR.
Jeff Brownd3187e32011-09-21 19:26:44 -07005729 if (mAllowAllRotations < 0) {
5730 // Can't read this during init() because the context doesn't
5731 // have display metrics at that time so we cannot determine
5732 // tablet vs. phone then.
5733 mAllowAllRotations = mContext.getResources().getBoolean(
5734 com.android.internal.R.bool.config_allowAllRotations) ? 1 : 0;
5735 }
Jeff Brown01a98dd2011-09-20 15:08:29 -07005736 if (sensorRotation != Surface.ROTATION_180
Jeff Brownd3187e32011-09-21 19:26:44 -07005737 || mAllowAllRotations == 1
Dianne Hackbornb9ec1ac2013-04-10 17:34:25 -07005738 || orientation == ActivityInfo.SCREEN_ORIENTATION_FULL_SENSOR
5739 || orientation == ActivityInfo.SCREEN_ORIENTATION_FULL_USER) {
Jeff Brown01a98dd2011-09-20 15:08:29 -07005740 preferredRotation = sensorRotation;
5741 } else {
5742 preferredRotation = lastRotation;
5743 }
Jeff Brown207673cd2012-06-05 17:47:11 -07005744 } else if (mUserRotationMode == WindowManagerPolicy.USER_ROTATION_LOCKED
5745 && orientation != ActivityInfo.SCREEN_ORIENTATION_NOSENSOR) {
5746 // Apply rotation lock. Does not apply to NOSENSOR.
5747 // The idea is that the user rotation expresses a weak preference for the direction
5748 // of gravity and as NOSENSOR is never affected by gravity, then neither should
5749 // NOSENSOR be affected by rotation lock (although it will be affected by docks).
Jeff Brown4dfce202011-10-05 12:00:10 -07005750 preferredRotation = mUserRotation;
Jeff Browndec6cf42011-11-15 14:08:20 -08005751 } else {
5752 // No overriding preference.
5753 // We will do exactly what the application asked us to do.
5754 preferredRotation = -1;
Jeff Brown01a98dd2011-09-20 15:08:29 -07005755 }
5756
Dianne Hackborne5439f22010-10-02 16:53:50 -07005757 switch (orientation) {
5758 case ActivityInfo.SCREEN_ORIENTATION_PORTRAIT:
Jeff Browndec6cf42011-11-15 14:08:20 -08005759 // Return portrait unless overridden.
5760 if (isAnyPortrait(preferredRotation)) {
5761 return preferredRotation;
5762 }
Dianne Hackborne5439f22010-10-02 16:53:50 -07005763 return mPortraitRotation;
Dianne Hackborne5439f22010-10-02 16:53:50 -07005764
Jeff Brown01a98dd2011-09-20 15:08:29 -07005765 case ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE:
Jeff Browndec6cf42011-11-15 14:08:20 -08005766 // Return landscape unless overridden.
5767 if (isLandscapeOrSeascape(preferredRotation)) {
5768 return preferredRotation;
5769 }
Jeff Brown01a98dd2011-09-20 15:08:29 -07005770 return mLandscapeRotation;
5771
5772 case ActivityInfo.SCREEN_ORIENTATION_REVERSE_PORTRAIT:
Jeff Browndec6cf42011-11-15 14:08:20 -08005773 // Return reverse portrait unless overridden.
5774 if (isAnyPortrait(preferredRotation)) {
5775 return preferredRotation;
5776 }
Jeff Brown01a98dd2011-09-20 15:08:29 -07005777 return mUpsideDownRotation;
5778
5779 case ActivityInfo.SCREEN_ORIENTATION_REVERSE_LANDSCAPE:
Jeff Browndec6cf42011-11-15 14:08:20 -08005780 // Return seascape unless overridden.
5781 if (isLandscapeOrSeascape(preferredRotation)) {
5782 return preferredRotation;
5783 }
Jeff Brown01a98dd2011-09-20 15:08:29 -07005784 return mSeascapeRotation;
5785
5786 case ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE:
Dianne Hackbornb9ec1ac2013-04-10 17:34:25 -07005787 case ActivityInfo.SCREEN_ORIENTATION_USER_LANDSCAPE:
Jeff Brown01a98dd2011-09-20 15:08:29 -07005788 // Return either landscape rotation.
5789 if (isLandscapeOrSeascape(preferredRotation)) {
5790 return preferredRotation;
5791 }
5792 if (isLandscapeOrSeascape(lastRotation)) {
Jeff Brown4519f072011-01-23 13:16:01 -08005793 return lastRotation;
5794 }
Jeff Brown01a98dd2011-09-20 15:08:29 -07005795 return mLandscapeRotation;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005796
Jeff Brown01a98dd2011-09-20 15:08:29 -07005797 case ActivityInfo.SCREEN_ORIENTATION_SENSOR_PORTRAIT:
Dianne Hackbornb9ec1ac2013-04-10 17:34:25 -07005798 case ActivityInfo.SCREEN_ORIENTATION_USER_PORTRAIT:
Jeff Brown01a98dd2011-09-20 15:08:29 -07005799 // Return either portrait rotation.
5800 if (isAnyPortrait(preferredRotation)) {
5801 return preferredRotation;
5802 }
5803 if (isAnyPortrait(lastRotation)) {
5804 return lastRotation;
5805 }
5806 return mPortraitRotation;
5807
5808 default:
Jeff Brown4dfce202011-10-05 12:00:10 -07005809 // For USER, UNSPECIFIED, NOSENSOR, SENSOR and FULL_SENSOR,
5810 // just return the preferred orientation we already calculated.
Jeff Brown01a98dd2011-09-20 15:08:29 -07005811 if (preferredRotation >= 0) {
5812 return preferredRotation;
5813 }
Dianne Hackborndacea8c2011-04-21 17:26:39 -07005814 return Surface.ROTATION_0;
Daniel Sandlere7e5ac22011-02-22 16:10:21 -05005815 }
5816 }
Steve Howarda7bfe6a2010-09-23 16:47:49 -07005817 }
5818
Jeff Brown01a98dd2011-09-20 15:08:29 -07005819 @Override
5820 public boolean rotationHasCompatibleMetricsLw(int orientation, int rotation) {
5821 switch (orientation) {
5822 case ActivityInfo.SCREEN_ORIENTATION_PORTRAIT:
5823 case ActivityInfo.SCREEN_ORIENTATION_REVERSE_PORTRAIT:
5824 case ActivityInfo.SCREEN_ORIENTATION_SENSOR_PORTRAIT:
5825 return isAnyPortrait(rotation);
5826
5827 case ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE:
5828 case ActivityInfo.SCREEN_ORIENTATION_REVERSE_LANDSCAPE:
5829 case ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE:
5830 return isLandscapeOrSeascape(rotation);
5831
5832 default:
5833 return true;
5834 }
Steve Howarda7bfe6a2010-09-23 16:47:49 -07005835 }
5836
Jeff Brownc0347aa2011-09-23 17:26:09 -07005837 @Override
5838 public void setRotationLw(int rotation) {
5839 mOrientationListener.setCurrentRotation(rotation);
5840 }
5841
Jeff Brown01a98dd2011-09-20 15:08:29 -07005842 private boolean isLandscapeOrSeascape(int rotation) {
5843 return rotation == mLandscapeRotation || rotation == mSeascapeRotation;
Dianne Hackborne5439f22010-10-02 16:53:50 -07005844 }
5845
Jeff Brown01a98dd2011-09-20 15:08:29 -07005846 private boolean isAnyPortrait(int rotation) {
5847 return rotation == mPortraitRotation || rotation == mUpsideDownRotation;
Dianne Hackborne5439f22010-10-02 16:53:50 -07005848 }
5849
Jose Lima9546b202014-07-02 17:21:51 -07005850 @Override
Svetoslav Ganov80943d82013-01-02 10:25:37 -08005851 public int getUserRotationMode() {
5852 return Settings.System.getIntForUser(mContext.getContentResolver(),
Brett Chabot7e55c402013-05-16 19:38:08 -07005853 Settings.System.ACCELEROMETER_ROTATION, 0, UserHandle.USER_CURRENT) != 0 ?
5854 WindowManagerPolicy.USER_ROTATION_FREE :
5855 WindowManagerPolicy.USER_ROTATION_LOCKED;
Svetoslav Ganov80943d82013-01-02 10:25:37 -08005856 }
Daniel Sandlerb73617d2010-08-17 00:41:00 -04005857
5858 // User rotation: to be used when all else fails in assigning an orientation to the device
Jose Lima9546b202014-07-02 17:21:51 -07005859 @Override
Daniel Sandlerb73617d2010-08-17 00:41:00 -04005860 public void setUserRotationMode(int mode, int rot) {
5861 ContentResolver res = mContext.getContentResolver();
Daniel Sandler2ed6ad62011-02-22 14:54:17 -05005862
5863 // mUserRotationMode and mUserRotation will be assigned by the content observer
Daniel Sandlerb73617d2010-08-17 00:41:00 -04005864 if (mode == WindowManagerPolicy.USER_ROTATION_LOCKED) {
Christopher Tate5e08af02012-09-21 17:17:22 -07005865 Settings.System.putIntForUser(res,
Daniel Sandlerb73617d2010-08-17 00:41:00 -04005866 Settings.System.USER_ROTATION,
Christopher Tate5e08af02012-09-21 17:17:22 -07005867 rot,
5868 UserHandle.USER_CURRENT);
5869 Settings.System.putIntForUser(res,
Daniel Sandler2ed6ad62011-02-22 14:54:17 -05005870 Settings.System.ACCELEROMETER_ROTATION,
Christopher Tate5e08af02012-09-21 17:17:22 -07005871 0,
5872 UserHandle.USER_CURRENT);
Daniel Sandlerb73617d2010-08-17 00:41:00 -04005873 } else {
Christopher Tate5e08af02012-09-21 17:17:22 -07005874 Settings.System.putIntForUser(res,
Daniel Sandlerb73617d2010-08-17 00:41:00 -04005875 Settings.System.ACCELEROMETER_ROTATION,
Christopher Tate5e08af02012-09-21 17:17:22 -07005876 1,
5877 UserHandle.USER_CURRENT);
Daniel Sandlerb73617d2010-08-17 00:41:00 -04005878 }
5879 }
5880
Jose Lima9546b202014-07-02 17:21:51 -07005881 @Override
Jeff Brownac143512012-04-05 18:57:33 -07005882 public void setSafeMode(boolean safeMode) {
5883 mSafeMode = safeMode;
5884 performHapticFeedbackLw(null, safeMode
5885 ? HapticFeedbackConstants.SAFE_MODE_ENABLED
5886 : HapticFeedbackConstants.SAFE_MODE_DISABLED, true);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005887 }
Craig Mautnereda67292013-04-28 13:50:14 -07005888
Dianne Hackborn181ceb52009-08-27 22:16:40 -07005889 static long[] getLongIntArray(Resources r, int resid) {
5890 int[] ar = r.getIntArray(resid);
5891 if (ar == null) {
5892 return null;
5893 }
5894 long[] out = new long[ar.length];
5895 for (int i=0; i<ar.length; i++) {
5896 out[i] = ar[i];
5897 }
5898 return out;
5899 }
Craig Mautnereda67292013-04-28 13:50:14 -07005900
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005901 /** {@inheritDoc} */
Craig Mautnereda67292013-04-28 13:50:14 -07005902 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005903 public void systemReady() {
Jim Millerab954542014-10-10 18:21:49 -07005904 mKeyguardDelegate = new KeyguardServiceDelegate(mContext);
Mike Lockwooded8902d2013-11-15 11:01:47 -08005905 mKeyguardDelegate.onSystemReady();
5906
Michael Wright3818c922014-09-02 13:59:07 -07005907 readCameraLensCoverState();
Jeff Brown4f5fa282014-06-12 19:19:15 -07005908 updateUiMode();
Dianne Hackbornb1a79802009-09-29 15:18:31 -07005909 synchronized (mLock) {
5910 updateOrientationListenerLp();
Dianne Hackbornc777e072010-02-12 13:07:59 -08005911 mSystemReady = true;
5912 mHandler.post(new Runnable() {
Craig Mautnereda67292013-04-28 13:50:14 -07005913 @Override
Dianne Hackbornc777e072010-02-12 13:07:59 -08005914 public void run() {
5915 updateSettings();
5916 }
5917 });
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005918 }
5919 }
Dianne Hackborn661cd522011-08-22 00:26:20 -07005920
Dianne Hackbornba24e4d2011-09-01 11:17:06 -07005921 /** {@inheritDoc} */
Jose Lima9546b202014-07-02 17:21:51 -07005922 @Override
Dianne Hackbornba24e4d2011-09-01 11:17:06 -07005923 public void systemBooted() {
Jim Millere5f910a2013-10-16 18:15:46 -07005924 if (mKeyguardDelegate != null) {
Jason Monk5eeebf52014-09-26 12:36:51 -04005925 mKeyguardDelegate.bindService(mContext);
Jim Millere5f910a2013-10-16 18:15:46 -07005926 mKeyguardDelegate.onBootCompleted();
5927 }
Dianne Hackbornba24e4d2011-09-01 11:17:06 -07005928 synchronized (mLock) {
5929 mSystemBooted = true;
5930 }
Jeff Brown416c49c2015-05-26 19:50:18 -07005931 startedWakingUp();
Jeff Brown36c4db82014-09-19 12:05:31 -07005932 screenTurningOn(null);
Dianne Hackbornba24e4d2011-09-01 11:17:06 -07005933 }
5934
Dianne Hackborn661cd522011-08-22 00:26:20 -07005935 ProgressDialog mBootMsgDialog = null;
5936
5937 /** {@inheritDoc} */
Jose Lima9546b202014-07-02 17:21:51 -07005938 @Override
Dianne Hackborn661cd522011-08-22 00:26:20 -07005939 public void showBootMessage(final CharSequence msg, final boolean always) {
5940 mHandler.post(new Runnable() {
5941 @Override public void run() {
5942 if (mBootMsgDialog == null) {
Craig Stout4c0cb8a2014-04-04 13:03:10 -07005943 int theme;
5944 if (mContext.getPackageManager().hasSystemFeature(
5945 PackageManager.FEATURE_WATCH)) {
5946 theme = com.android.internal.R.style.Theme_Micro_Dialog_Alert;
5947 } else if (mContext.getPackageManager().hasSystemFeature(
5948 PackageManager.FEATURE_TELEVISION)) {
5949 theme = com.android.internal.R.style.Theme_Leanback_Dialog_Alert;
5950 } else {
5951 theme = 0;
5952 }
Vinod Krishnanfa8fc412014-04-18 14:35:53 -07005953
5954 mBootMsgDialog = new ProgressDialog(mContext, theme) {
Dianne Hackborn295e3c22011-08-25 13:19:08 -07005955 // This dialog will consume all events coming in to
5956 // it, to avoid it trying to do things too early in boot.
5957 @Override public boolean dispatchKeyEvent(KeyEvent event) {
5958 return true;
5959 }
5960 @Override public boolean dispatchKeyShortcutEvent(KeyEvent event) {
5961 return true;
5962 }
5963 @Override public boolean dispatchTouchEvent(MotionEvent ev) {
5964 return true;
5965 }
5966 @Override public boolean dispatchTrackballEvent(MotionEvent ev) {
5967 return true;
5968 }
5969 @Override public boolean dispatchGenericMotionEvent(MotionEvent ev) {
5970 return true;
5971 }
5972 @Override public boolean dispatchPopulateAccessibilityEvent(
5973 AccessibilityEvent event) {
5974 return true;
5975 }
5976 };
Jeff Hao9f60c082014-10-28 18:51:07 -07005977 if (mContext.getPackageManager().isUpgrade()) {
5978 mBootMsgDialog.setTitle(R.string.android_upgrading_title);
5979 } else {
5980 mBootMsgDialog.setTitle(R.string.android_start_title);
5981 }
Dianne Hackborn661cd522011-08-22 00:26:20 -07005982 mBootMsgDialog.setProgressStyle(ProgressDialog.STYLE_SPINNER);
5983 mBootMsgDialog.setIndeterminate(true);
5984 mBootMsgDialog.getWindow().setType(
Dianne Hackborn29aae6f2011-08-18 18:30:09 -07005985 WindowManager.LayoutParams.TYPE_BOOT_PROGRESS);
Dianne Hackborn661cd522011-08-22 00:26:20 -07005986 mBootMsgDialog.getWindow().addFlags(
5987 WindowManager.LayoutParams.FLAG_DIM_BEHIND
5988 | WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN);
5989 mBootMsgDialog.getWindow().setDimAmount(1);
Dianne Hackbornd9efb952011-12-07 14:56:51 -08005990 WindowManager.LayoutParams lp = mBootMsgDialog.getWindow().getAttributes();
5991 lp.screenOrientation = ActivityInfo.SCREEN_ORIENTATION_NOSENSOR;
5992 mBootMsgDialog.getWindow().setAttributes(lp);
Dianne Hackborn661cd522011-08-22 00:26:20 -07005993 mBootMsgDialog.setCancelable(false);
5994 mBootMsgDialog.show();
5995 }
5996 mBootMsgDialog.setMessage(msg);
5997 }
5998 });
5999 }
6000
6001 /** {@inheritDoc} */
Jose Lima9546b202014-07-02 17:21:51 -07006002 @Override
Dianne Hackborn661cd522011-08-22 00:26:20 -07006003 public void hideBootMessages() {
Craig Mautnera631d492014-08-05 15:16:01 -07006004 mHandler.sendEmptyMessage(MSG_HIDE_BOOT_MESSAGE);
Dianne Hackborn661cd522011-08-22 00:26:20 -07006005 }
6006
Mike Lockwood28569302010-01-28 11:54:40 -05006007 /** {@inheritDoc} */
Jose Lima9546b202014-07-02 17:21:51 -07006008 @Override
Mike Lockwood28569302010-01-28 11:54:40 -05006009 public void userActivity() {
Dianne Hackborndf89e652011-10-06 22:35:11 -07006010 // ***************************************
6011 // NOTE NOTE NOTE NOTE NOTE NOTE NOTE NOTE
6012 // ***************************************
6013 // THIS IS CALLED FROM DEEP IN THE POWER MANAGER
6014 // WITH ITS LOCKS HELD.
6015 //
6016 // This code must be VERY careful about the locks
6017 // it acquires.
6018 // In fact, the current code acquires way too many,
6019 // and probably has lurking deadlocks.
6020
Mike Lockwood28569302010-01-28 11:54:40 -05006021 synchronized (mScreenLockTimeout) {
6022 if (mLockScreenTimerActive) {
6023 // reset the timer
6024 mHandler.removeCallbacks(mScreenLockTimeout);
6025 mHandler.postDelayed(mScreenLockTimeout, mLockScreenTimeout);
6026 }
6027 }
Daniel Sandler0601eb72011-04-13 01:01:32 -04006028 }
6029
Adam Cohenf7522022012-10-03 20:03:18 -07006030 class ScreenLockTimeout implements Runnable {
6031 Bundle options;
6032
6033 @Override
Mike Lockwood28569302010-01-28 11:54:40 -05006034 public void run() {
6035 synchronized (this) {
6036 if (localLOGV) Log.v(TAG, "mScreenLockTimeout activating keyguard");
Jim Miller5ecd8112013-01-09 18:50:26 -08006037 if (mKeyguardDelegate != null) {
6038 mKeyguardDelegate.doKeyguardTimeout(options);
Mike Lockwood3a74bd32011-08-12 13:55:22 -07006039 }
Mike Lockwood28569302010-01-28 11:54:40 -05006040 mLockScreenTimerActive = false;
Adam Cohenf7522022012-10-03 20:03:18 -07006041 options = null;
Mike Lockwood28569302010-01-28 11:54:40 -05006042 }
6043 }
Mike Lockwood28569302010-01-28 11:54:40 -05006044
Adam Cohenf7522022012-10-03 20:03:18 -07006045 public void setLockOptions(Bundle options) {
6046 this.options = options;
6047 }
6048 }
6049
6050 ScreenLockTimeout mScreenLockTimeout = new ScreenLockTimeout();
6051
Jose Lima9546b202014-07-02 17:21:51 -07006052 @Override
Adam Cohenf7522022012-10-03 20:03:18 -07006053 public void lockNow(Bundle options) {
Jim Miller93c518e2012-01-17 15:55:31 -08006054 mContext.enforceCallingOrSelfPermission(android.Manifest.permission.DEVICE_POWER, null);
6055 mHandler.removeCallbacks(mScreenLockTimeout);
Adam Cohenf7522022012-10-03 20:03:18 -07006056 if (options != null) {
6057 // In case multiple calls are made to lockNow, we don't wipe out the options
6058 // until the runnable actually executes.
6059 mScreenLockTimeout.setLockOptions(options);
6060 }
Jim Miller93c518e2012-01-17 15:55:31 -08006061 mHandler.post(mScreenLockTimeout);
6062 }
6063
Mike Lockwood28569302010-01-28 11:54:40 -05006064 private void updateLockScreenTimeout() {
6065 synchronized (mScreenLockTimeout) {
Jeff Brown3ee549c2014-09-22 20:14:39 -07006066 boolean enable = (mAllowLockscreenWhenOn && mAwake &&
Jim Miller5ecd8112013-01-09 18:50:26 -08006067 mKeyguardDelegate != null && mKeyguardDelegate.isSecure());
Mike Lockwood28569302010-01-28 11:54:40 -05006068 if (mLockScreenTimerActive != enable) {
6069 if (enable) {
6070 if (localLOGV) Log.v(TAG, "setting lockscreen timer");
6071 mHandler.postDelayed(mScreenLockTimeout, mLockScreenTimeout);
6072 } else {
6073 if (localLOGV) Log.v(TAG, "clearing lockscreen timer");
6074 mHandler.removeCallbacks(mScreenLockTimeout);
6075 }
6076 mLockScreenTimerActive = enable;
6077 }
6078 }
6079 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006080
Jeff Brown061ea992015-04-17 19:55:47 -07006081 private void updateDreamingSleepToken(boolean acquire) {
6082 if (acquire) {
6083 if (mDreamingSleepToken == null) {
6084 mDreamingSleepToken = mActivityManagerInternal.acquireSleepToken("Dream");
6085 }
6086 } else {
6087 if (mDreamingSleepToken != null) {
6088 mDreamingSleepToken.release();
Jeff Brown48d1b142015-06-10 16:36:03 -07006089 mDreamingSleepToken = null;
6090 }
6091 }
6092 }
6093
6094 private void updateScreenOffSleepToken(boolean acquire) {
6095 if (acquire) {
6096 if (mScreenOffSleepToken == null) {
6097 mScreenOffSleepToken = mActivityManagerInternal.acquireSleepToken("ScreenOff");
6098 }
6099 } else {
6100 if (mScreenOffSleepToken != null) {
6101 mScreenOffSleepToken.release();
6102 mScreenOffSleepToken = null;
Jeff Brown061ea992015-04-17 19:55:47 -07006103 }
6104 }
6105 }
6106
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006107 /** {@inheritDoc} */
Craig Mautnereda67292013-04-28 13:50:14 -07006108 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006109 public void enableScreenAfterBoot() {
6110 readLidState();
Jeff Brownc458ce92012-04-30 14:58:40 -07006111 applyLidSwitchState();
Jeff Brown01a98dd2011-09-20 15:08:29 -07006112 updateRotation(true);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006113 }
Dianne Hackbornf54c8f92009-09-19 14:03:57 -07006114
Jeff Brownc458ce92012-04-30 14:58:40 -07006115 private void applyLidSwitchState() {
Jeff Brownc458ce92012-04-30 14:58:40 -07006116 if (mLidState == LID_CLOSED && mLidControlsSleep) {
Jeff Brown6d8fd272014-05-20 21:24:38 -07006117 mPowerManager.goToSleep(SystemClock.uptimeMillis(),
Jeff Brownc12035c2014-08-13 18:52:25 -07006118 PowerManager.GO_TO_SLEEP_REASON_LID_SWITCH,
Jeff Brown6d8fd272014-05-20 21:24:38 -07006119 PowerManager.GO_TO_SLEEP_FLAG_NO_DOZE);
Jeff Brownc458ce92012-04-30 14:58:40 -07006120 }
Jeff Browna20dda42014-05-27 20:57:24 -07006121
6122 synchronized (mLock) {
6123 updateWakeGestureListenerLp();
6124 }
Jeff Brown01a98dd2011-09-20 15:08:29 -07006125 }
6126
Jeff Brown4f5fa282014-06-12 19:19:15 -07006127 void updateUiMode() {
6128 if (mUiModeManager == null) {
6129 mUiModeManager = IUiModeManager.Stub.asInterface(
6130 ServiceManager.getService(Context.UI_MODE_SERVICE));
6131 }
6132 try {
6133 mUiMode = mUiModeManager.getCurrentModeType();
6134 } catch (RemoteException e) {
6135 }
6136 }
6137
Jeff Brown01a98dd2011-09-20 15:08:29 -07006138 void updateRotation(boolean alwaysSendConfiguration) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006139 try {
6140 //set orientation on WindowManager
Dianne Hackbornf87d1962012-04-04 12:48:24 -07006141 mWindowManager.updateRotation(alwaysSendConfiguration, false);
6142 } catch (RemoteException e) {
6143 // Ignore
6144 }
6145 }
6146
6147 void updateRotation(boolean alwaysSendConfiguration, boolean forceRelayout) {
6148 try {
6149 //set orientation on WindowManager
6150 mWindowManager.updateRotation(alwaysSendConfiguration, forceRelayout);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006151 } catch (RemoteException e) {
6152 // Ignore
6153 }
6154 }
6155
Daniel Sandler6396c722013-04-16 20:19:09 -04006156 /**
6157 * Return an Intent to launch the currently active dock app as home. Returns
6158 * null if the standard home should be launched, which is the case if any of the following is
6159 * true:
6160 * <ul>
6161 * <li>The device is not in either car mode or desk mode
6162 * <li>The device is in car mode but ENABLE_CAR_DOCK_HOME_CAPTURE is false
6163 * <li>The device is in desk mode but ENABLE_DESK_DOCK_HOME_CAPTURE is false
6164 * <li>The device is in car mode but there's no CAR_DOCK app with METADATA_DOCK_HOME
6165 * <li>The device is in desk mode but there's no DESK_DOCK app with METADATA_DOCK_HOME
6166 * </ul>
Craig Mautnereda67292013-04-28 13:50:14 -07006167 * @return A dock intent.
Daniel Sandler6396c722013-04-16 20:19:09 -04006168 */
6169 Intent createHomeDockIntent() {
6170 Intent intent = null;
6171
6172 // What home does is based on the mode, not the dock state. That
6173 // is, when in car mode you should be taken to car home regardless
6174 // of whether we are actually in a car dock.
6175 if (mUiMode == Configuration.UI_MODE_TYPE_CAR) {
6176 if (ENABLE_CAR_DOCK_HOME_CAPTURE) {
6177 intent = mCarDockIntent;
6178 }
6179 } else if (mUiMode == Configuration.UI_MODE_TYPE_DESK) {
6180 if (ENABLE_DESK_DOCK_HOME_CAPTURE) {
6181 intent = mDeskDockIntent;
6182 }
Jeff Brown4f5fa282014-06-12 19:19:15 -07006183 } else if (mUiMode == Configuration.UI_MODE_TYPE_WATCH
6184 && (mDockMode == Intent.EXTRA_DOCK_STATE_DESK
6185 || mDockMode == Intent.EXTRA_DOCK_STATE_HE_DESK
6186 || mDockMode == Intent.EXTRA_DOCK_STATE_LE_DESK)) {
6187 // Always launch dock home from home when watch is docked, if it exists.
6188 intent = mDeskDockIntent;
Daniel Sandler6396c722013-04-16 20:19:09 -04006189 }
6190
6191 if (intent == null) {
6192 return null;
6193 }
6194
6195 ActivityInfo ai = null;
6196 ResolveInfo info = mContext.getPackageManager().resolveActivityAsUser(
6197 intent,
John Spurlockf56bef12013-07-09 09:51:46 -04006198 PackageManager.MATCH_DEFAULT_ONLY | PackageManager.GET_META_DATA,
Craig Mautnerd625ab22013-09-06 13:40:31 -07006199 mCurrentUserId);
Daniel Sandler6396c722013-04-16 20:19:09 -04006200 if (info != null) {
6201 ai = info.activityInfo;
6202 }
6203 if (ai != null
6204 && ai.metaData != null
6205 && ai.metaData.getBoolean(Intent.METADATA_DOCK_HOME)) {
6206 intent = new Intent(intent);
6207 intent.setClassName(ai.packageName, ai.name);
6208 return intent;
6209 }
6210
6211 return null;
6212 }
6213
Filip Gruszczynskia483a1d2015-03-17 19:06:58 +00006214 void startDockOrHome(boolean fromHomeKey, boolean awakenFromDreams) {
6215 if (awakenFromDreams) {
6216 awakenDreams();
6217 }
Daniel Sandler6396c722013-04-16 20:19:09 -04006218
6219 Intent dock = createHomeDockIntent();
6220 if (dock != null) {
6221 try {
Bryce Lee01b0c5f2015-02-05 18:24:04 -08006222 if (fromHomeKey) {
6223 dock.putExtra(WindowManagerPolicy.EXTRA_FROM_HOME_KEY, fromHomeKey);
6224 }
Bart Sears8b1c27c2015-03-18 23:51:02 +00006225 startActivityAsUser(dock, UserHandle.CURRENT);
Daniel Sandler6396c722013-04-16 20:19:09 -04006226 return;
6227 } catch (ActivityNotFoundException e) {
6228 }
6229 }
6230
Bryce Lee01b0c5f2015-02-05 18:24:04 -08006231 Intent intent;
6232
6233 if (fromHomeKey) {
6234 intent = new Intent(mHomeIntent);
6235 intent.putExtra(WindowManagerPolicy.EXTRA_FROM_HOME_KEY, fromHomeKey);
6236 } else {
6237 intent = mHomeIntent;
6238 }
6239
Bryce Lee9fc0b6f2015-03-19 21:37:45 +00006240 startActivityAsUser(intent, UserHandle.CURRENT);
Dianne Hackborn39c2d712009-09-22 11:41:31 -07006241 }
Craig Mautnereda67292013-04-28 13:50:14 -07006242
Dianne Hackborn39c2d712009-09-22 11:41:31 -07006243 /**
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006244 * goes to the home screen
6245 * @return whether it did anything
6246 */
6247 boolean goHome() {
Bart Sears8b1c27c2015-03-18 23:51:02 +00006248 if (!isUserSetupComplete()) {
6249 Slog.i(TAG, "Not going home because user setup is in progress.");
6250 return false;
6251 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006252 if (false) {
6253 // This code always brings home to the front.
Dianne Hackborn256dd3b2009-05-19 18:51:21 -07006254 try {
6255 ActivityManagerNative.getDefault().stopAppSwitches();
6256 } catch (RemoteException e) {
6257 }
Dianne Hackborn94a679d2009-07-28 17:51:07 -07006258 sendCloseSystemWindows();
Filip Gruszczynskia483a1d2015-03-17 19:06:58 +00006259 startDockOrHome(false /*fromHomeKey*/, true /* awakenFromDreams */);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006260 } else {
6261 // This code brings home to the front or, if it is already
6262 // at the front, puts the device to sleep.
6263 try {
Wink Savilled2e6a332010-02-12 12:12:06 -08006264 if (SystemProperties.getInt("persist.sys.uts-test-mode", 0) == 1) {
6265 /// Roll back EndcallBehavior as the cupcake design to pass P1 lab entry.
6266 Log.d(TAG, "UTS-TEST-MODE");
6267 } else {
6268 ActivityManagerNative.getDefault().stopAppSwitches();
6269 sendCloseSystemWindows();
Daniel Sandler6396c722013-04-16 20:19:09 -04006270 Intent dock = createHomeDockIntent();
6271 if (dock != null) {
6272 int result = ActivityManagerNative.getDefault()
6273 .startActivityAsUser(null, null, dock,
6274 dock.resolveTypeIfNeeded(mContext.getContentResolver()),
6275 null, null, 0,
6276 ActivityManager.START_FLAG_ONLY_IF_NEEDED,
Jeff Hao1b012d32014-08-20 10:35:34 -07006277 null, null, UserHandle.USER_CURRENT);
Daniel Sandler6396c722013-04-16 20:19:09 -04006278 if (result == ActivityManager.START_RETURN_INTENT_TO_CALLER) {
6279 return false;
6280 }
6281 }
Dianne Hackborn39c2d712009-09-22 11:41:31 -07006282 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006283 int result = ActivityManagerNative.getDefault()
Dianne Hackbornf265ea92013-01-31 15:00:51 -08006284 .startActivityAsUser(null, null, mHomeIntent,
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006285 mHomeIntent.resolveTypeIfNeeded(mContext.getContentResolver()),
Dianne Hackborna4972e92012-03-14 10:38:05 -07006286 null, null, 0,
6287 ActivityManager.START_FLAG_ONLY_IF_NEEDED,
Jeff Hao1b012d32014-08-20 10:35:34 -07006288 null, null, UserHandle.USER_CURRENT);
Dianne Hackborna4972e92012-03-14 10:38:05 -07006289 if (result == ActivityManager.START_RETURN_INTENT_TO_CALLER) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006290 return false;
6291 }
6292 } catch (RemoteException ex) {
6293 // bummer, the activity manager, which is in this process, is dead
6294 }
6295 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006296 return true;
6297 }
Craig Mautnereda67292013-04-28 13:50:14 -07006298
6299 @Override
The Android Open Source Project0727d222009-03-11 12:11:58 -07006300 public void setCurrentOrientationLw(int newOrientation) {
6301 synchronized (mLock) {
6302 if (newOrientation != mCurrentAppOrientation) {
6303 mCurrentAppOrientation = newOrientation;
6304 updateOrientationListenerLp();
6305 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006306 }
6307 }
Amith Yamasanic33cb712010-02-10 15:21:49 -08006308
Svetoslav Ganov7befb7d2012-09-27 16:49:23 -07006309 private void performAuditoryFeedbackForAccessibilityIfNeed() {
6310 if (!isGlobalAccessibilityGestureEnabled()) {
6311 return;
6312 }
6313 AudioManager audioManager = (AudioManager) mContext.getSystemService(
6314 Context.AUDIO_SERVICE);
6315 if (audioManager.isSilentMode()) {
6316 return;
6317 }
6318 Ringtone ringTone = RingtoneManager.getRingtone(mContext,
6319 Settings.System.DEFAULT_NOTIFICATION_URI);
6320 ringTone.setStreamType(AudioManager.STREAM_MUSIC);
6321 ringTone.play();
6322 }
Craig Mautnereda67292013-04-28 13:50:14 -07006323
Bryce Lee584a4452014-10-21 15:55:55 -07006324 private boolean isTheaterModeEnabled() {
6325 return Settings.Global.getInt(mContext.getContentResolver(),
6326 Settings.Global.THEATER_MODE_ON, 0) == 1;
6327 }
6328
Svetoslav Ganov7befb7d2012-09-27 16:49:23 -07006329 private boolean isGlobalAccessibilityGestureEnabled() {
6330 return Settings.Global.getInt(mContext.getContentResolver(),
6331 Settings.Global.ENABLE_ACCESSIBILITY_GLOBAL_GESTURE_ENABLED, 0) == 1;
6332 }
6333
Craig Mautnereda67292013-04-28 13:50:14 -07006334 @Override
The Android Open Source Project0727d222009-03-11 12:11:58 -07006335 public boolean performHapticFeedbackLw(WindowState win, int effectId, boolean always) {
Svetoslav Ganov96179212012-10-10 14:17:45 -07006336 if (!mVibrator.hasVibrator()) {
6337 return false;
6338 }
Christopher Tate5e08af02012-09-21 17:17:22 -07006339 final boolean hapticsDisabled = Settings.System.getIntForUser(mContext.getContentResolver(),
6340 Settings.System.HAPTIC_FEEDBACK_ENABLED, 0, UserHandle.USER_CURRENT) == 0;
Jeff Brown82379ba2014-07-25 19:03:28 -07006341 if (hapticsDisabled && !always) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006342 return false;
6343 }
Amith Yamasanic33cb712010-02-10 15:21:49 -08006344 long[] pattern = null;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006345 switch (effectId) {
6346 case HapticFeedbackConstants.LONG_PRESS:
Amith Yamasanic33cb712010-02-10 15:21:49 -08006347 pattern = mLongPressVibePattern;
6348 break;
Dianne Hackbornb1a79802009-09-29 15:18:31 -07006349 case HapticFeedbackConstants.VIRTUAL_KEY:
Amith Yamasanic33cb712010-02-10 15:21:49 -08006350 pattern = mVirtualKeyVibePattern;
6351 break;
6352 case HapticFeedbackConstants.KEYBOARD_TAP:
6353 pattern = mKeyboardTapVibePattern;
6354 break;
Fabrice Di Meglioeeff63a2013-08-05 12:07:24 -07006355 case HapticFeedbackConstants.CLOCK_TICK:
6356 pattern = mClockTickVibePattern;
6357 break;
Fabrice Di Megliobd9152f2013-10-01 11:21:31 -07006358 case HapticFeedbackConstants.CALENDAR_DATE:
6359 pattern = mCalendarDateVibePattern;
6360 break;
Dianne Hackbornb1a79802009-09-29 15:18:31 -07006361 case HapticFeedbackConstants.SAFE_MODE_DISABLED:
Amith Yamasanic33cb712010-02-10 15:21:49 -08006362 pattern = mSafeModeDisabledVibePattern;
6363 break;
Dianne Hackbornb1a79802009-09-29 15:18:31 -07006364 case HapticFeedbackConstants.SAFE_MODE_ENABLED:
Amith Yamasanic33cb712010-02-10 15:21:49 -08006365 pattern = mSafeModeEnabledVibePattern;
6366 break;
Mady Mellore8608912015-06-05 09:02:55 -07006367 case HapticFeedbackConstants.CONTEXT_CLICK:
6368 pattern = mContextClickVibePattern;
Mady Mellore82067b2015-04-30 09:58:35 -07006369 break;
Amith Yamasanic33cb712010-02-10 15:21:49 -08006370 default:
6371 return false;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006372 }
Dianne Hackbornf265ea92013-01-31 15:00:51 -08006373 int owningUid;
6374 String owningPackage;
6375 if (win != null) {
6376 owningUid = win.getOwningUid();
6377 owningPackage = win.getOwningPackage();
6378 } else {
6379 owningUid = android.os.Process.myUid();
Dianne Hackborn95d78532013-09-11 09:51:14 -07006380 owningPackage = mContext.getOpPackageName();
Dianne Hackbornf265ea92013-01-31 15:00:51 -08006381 }
Amith Yamasanic33cb712010-02-10 15:21:49 -08006382 if (pattern.length == 1) {
6383 // One-shot vibration
John Spurlock7b414672014-07-18 13:02:39 -04006384 mVibrator.vibrate(owningUid, owningPackage, pattern[0], VIBRATION_ATTRIBUTES);
Amith Yamasanic33cb712010-02-10 15:21:49 -08006385 } else {
6386 // Pattern vibration
John Spurlock7b414672014-07-18 13:02:39 -04006387 mVibrator.vibrate(owningUid, owningPackage, pattern, -1, VIBRATION_ATTRIBUTES);
Amith Yamasanic33cb712010-02-10 15:21:49 -08006388 }
6389 return true;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006390 }
Jeff Brownc38c9be2012-10-04 13:16:19 -07006391
6392 @Override
6393 public void keepScreenOnStartedLw() {
Daniel Sandler0601eb72011-04-13 01:01:32 -04006394 }
6395
Jeff Brownc38c9be2012-10-04 13:16:19 -07006396 @Override
6397 public void keepScreenOnStoppedLw() {
Jim Millerab954542014-10-10 18:21:49 -07006398 if (isKeyguardShowingAndNotOccluded()) {
Jim Miller25190572013-02-28 17:36:24 -08006399 mPowerManager.userActivity(SystemClock.uptimeMillis(), false);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006400 }
6401 }
Mike Lockwoodfcb39242009-10-21 23:01:07 -04006402
Dianne Hackborndf89e652011-10-06 22:35:11 -07006403 private int updateSystemUiVisibilityLw() {
Joe Onorato664644d2011-01-23 17:53:23 -08006404 // If there is no window focused, there will be nobody to handle the events
6405 // anyway, so just hang on in whatever state we're in until things settle down.
Adrian Roos53f28ec2014-10-29 17:26:12 +01006406 final WindowState win = mFocusedWindow != null ? mFocusedWindow
6407 : mTopFullscreenOpaqueWindowState;
John Spurlock79da8332013-09-20 12:04:47 -04006408 if (win == null) {
Dianne Hackborndf89e652011-10-06 22:35:11 -07006409 return 0;
6410 }
Jorim Jaggi380ecb82014-03-14 17:25:20 +01006411 if ((win.getAttrs().privateFlags & PRIVATE_FLAG_KEYGUARD) != 0 && mHideLockScreen == true) {
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07006412 // We are updating at a point where the keyguard has gotten
6413 // focus, but we were last in a state where the top window is
6414 // hiding it. This is probably because the keyguard as been
6415 // shown while the top window was displayed, so we want to ignore
6416 // it here because this is just a very transient change and it
6417 // will quickly lose focus once it correctly gets hidden.
6418 return 0;
6419 }
John Spurlock32beb2c2013-03-11 10:16:47 -04006420
John Spurlock1db8b682014-02-18 11:18:59 -05006421 int tmpVisibility = PolicyControl.getSystemUiVisibility(win, null)
Dianne Hackborne26ab702011-10-16 13:21:33 -07006422 & ~mResettingSystemUiFlags
6423 & ~mForceClearedSystemUiFlags;
John Spurlock79da8332013-09-20 12:04:47 -04006424 if (mForcingShowNavBar && win.getSurfaceLayer() < mForcingShowNavBarLayer) {
John Spurlockc6d1c602014-01-17 15:22:06 -05006425 tmpVisibility &= ~PolicyControl.adjustClearableFlags(win, View.SYSTEM_UI_CLEARABLE_FLAGS);
Dianne Hackborn891d3fb2013-01-09 18:31:37 -08006426 }
Adrian Rooscd3884d2015-02-18 17:25:23 +01006427 tmpVisibility = updateLightStatusBarLw(tmpVisibility);
John Spurlock79da8332013-09-20 12:04:47 -04006428 final int visibility = updateSystemBarsLw(win, mLastSystemUiFlags, tmpVisibility);
John Spurlockad3e6cb2013-04-30 08:47:43 -04006429 final int diff = visibility ^ mLastSystemUiFlags;
John Spurlock79da8332013-09-20 12:04:47 -04006430 final boolean needsMenu = win.getNeedsMenuLw(mTopFullscreenOpaqueWindowState);
Dianne Hackborne0f085d2011-11-30 18:41:15 -08006431 if (diff == 0 && mLastFocusNeedsMenu == needsMenu
John Spurlock79da8332013-09-20 12:04:47 -04006432 && mFocusedApp == win.getAppToken()) {
Dianne Hackborndf89e652011-10-06 22:35:11 -07006433 return 0;
6434 }
Dianne Hackborne26ab702011-10-16 13:21:33 -07006435 mLastSystemUiFlags = visibility;
Dianne Hackborn4eff8d32011-11-10 19:38:40 -08006436 mLastFocusNeedsMenu = needsMenu;
John Spurlock79da8332013-09-20 12:04:47 -04006437 mFocusedApp = win.getAppToken();
Dianne Hackborndf89e652011-10-06 22:35:11 -07006438 mHandler.post(new Runnable() {
Craig Mautnereda67292013-04-28 13:50:14 -07006439 @Override
Dianne Hackborndf89e652011-10-06 22:35:11 -07006440 public void run() {
Dianne Hackborn42e620c2012-06-24 13:20:51 -07006441 try {
6442 IStatusBarService statusbar = getStatusBarService();
6443 if (statusbar != null) {
Adrian Roos53f28ec2014-10-29 17:26:12 +01006444 statusbar.setSystemUiVisibility(visibility, 0xffffffff, win.toString());
Dianne Hackborn42e620c2012-06-24 13:20:51 -07006445 statusbar.topAppWindowChanged(needsMenu);
Joe Onorato664644d2011-01-23 17:53:23 -08006446 }
Dianne Hackborn42e620c2012-06-24 13:20:51 -07006447 } catch (RemoteException e) {
6448 // re-acquire status bar service next time it is needed.
6449 mStatusBarService = null;
Joe Onorato664644d2011-01-23 17:53:23 -08006450 }
Dianne Hackborndf89e652011-10-06 22:35:11 -07006451 }
6452 });
6453 return diff;
Joe Onorato664644d2011-01-23 17:53:23 -08006454 }
6455
Adrian Rooscd3884d2015-02-18 17:25:23 +01006456 private int updateLightStatusBarLw(int vis) {
6457 WindowState statusColorWin = isStatusBarKeyguard() && !mHideLockScreen
6458 ? mStatusBar
6459 : mTopFullscreenOpaqueOrDimmingWindowState;
6460
6461 if (statusColorWin != null) {
6462 if (statusColorWin == mTopFullscreenOpaqueWindowState) {
6463 // If the top fullscreen-or-dimming window is also the top fullscreen, respect
6464 // its light flag.
6465 vis &= ~View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR;
6466 vis |= PolicyControl.getSystemUiVisibility(statusColorWin, null)
6467 & View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR;
6468 } else if (statusColorWin != null && statusColorWin.isDimming()) {
6469 // Otherwise if it's dimming, clear the light flag.
6470 vis &= ~View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR;
6471 }
6472 }
6473 return vis;
6474 }
6475
John Spurlock79da8332013-09-20 12:04:47 -04006476 private int updateSystemBarsLw(WindowState win, int oldVis, int vis) {
John Spurlockbd957402013-10-03 11:38:39 -04006477 // apply translucent bar vis flags
Jorim Jaggi380ecb82014-03-14 17:25:20 +01006478 WindowState transWin = isStatusBarKeyguard() && !mHideLockScreen
6479 ? mStatusBar
John Spurlockbd957402013-10-03 11:38:39 -04006480 : mTopFullscreenOpaqueWindowState;
6481 vis = mStatusBarController.applyTranslucentFlagLw(transWin, vis, oldVis);
6482 vis = mNavigationBarController.applyTranslucentFlagLw(transWin, vis, oldVis);
6483
John Spurlock27735a42013-08-14 17:57:38 -04006484 // prevent status bar interaction from clearing certain flags
Selim Cinekf83e8242015-05-19 18:08:14 -07006485 int type = win.getAttrs().type;
6486 boolean statusBarHasFocus = type == TYPE_STATUS_BAR;
John Spurlock08ffcf52014-07-11 10:13:46 -04006487 if (statusBarHasFocus && !isStatusBarKeyguard()) {
John Spurlockad3e6cb2013-04-30 08:47:43 -04006488 int flags = View.SYSTEM_UI_FLAG_FULLSCREEN
6489 | View.SYSTEM_UI_FLAG_HIDE_NAVIGATION
John Spurlockcfc359a2013-09-05 10:42:03 -04006490 | View.SYSTEM_UI_FLAG_IMMERSIVE
Jorim Jaggi73fef8d2015-02-16 17:32:28 +01006491 | View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY
6492 | View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR;
John Spurlock08ffcf52014-07-11 10:13:46 -04006493 if (mHideLockScreen) {
Jorim Jaggi5cf17872014-03-26 18:31:48 +01006494 flags |= View.STATUS_BAR_TRANSLUCENT | View.NAVIGATION_BAR_TRANSLUCENT;
6495 }
John Spurlockbd957402013-10-03 11:38:39 -04006496 vis = (vis & ~flags) | (oldVis & flags);
John Spurlockad3e6cb2013-04-30 08:47:43 -04006497 }
John Spurlockad3e6cb2013-04-30 08:47:43 -04006498
Adrian Roos4fb3ee32014-08-22 19:29:09 +02006499 if (!areTranslucentBarsAllowed() && transWin != mStatusBar) {
Adrian Roosea562512014-05-05 13:33:03 +02006500 vis &= ~(View.NAVIGATION_BAR_TRANSLUCENT | View.STATUS_BAR_TRANSLUCENT
6501 | View.SYSTEM_UI_TRANSPARENT);
Alan Viverette5a0f4ec2013-10-07 15:10:29 -07006502 }
6503
John Spurlock27735a42013-08-14 17:57:38 -04006504 // update status bar
John Spurlockf1a36642013-10-12 17:50:42 -04006505 boolean immersiveSticky =
6506 (vis & View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY) != 0;
John Spurlock27735a42013-08-14 17:57:38 -04006507 boolean hideStatusBarWM =
John Spurlockbd957402013-10-03 11:38:39 -04006508 mTopFullscreenOpaqueWindowState != null &&
John Spurlockc6d1c602014-01-17 15:22:06 -05006509 (PolicyControl.getWindowFlags(mTopFullscreenOpaqueWindowState, null)
John Spurlock27735a42013-08-14 17:57:38 -04006510 & WindowManager.LayoutParams.FLAG_FULLSCREEN) != 0;
6511 boolean hideStatusBarSysui =
6512 (vis & View.SYSTEM_UI_FLAG_FULLSCREEN) != 0;
John Spurlockf1a36642013-10-12 17:50:42 -04006513 boolean hideNavBarSysui =
6514 (vis & View.SYSTEM_UI_FLAG_HIDE_NAVIGATION) != 0;
John Spurlockad3e6cb2013-04-30 08:47:43 -04006515
John Spurlock27735a42013-08-14 17:57:38 -04006516 boolean transientStatusBarAllowed =
6517 mStatusBar != null && (
6518 hideStatusBarWM
John Spurlockf1a36642013-10-12 17:50:42 -04006519 || (hideStatusBarSysui && immersiveSticky)
John Spurlock27735a42013-08-14 17:57:38 -04006520 || statusBarHasFocus);
6521
John Spurlockf1a36642013-10-12 17:50:42 -04006522 boolean transientNavBarAllowed =
6523 mNavigationBar != null &&
6524 hideNavBarSysui && immersiveSticky;
6525
Adrian Roosddc8b272015-05-21 16:28:27 -07006526 final long now = SystemClock.uptimeMillis();
6527 final boolean pendingPanic = mPendingPanicGestureUptime != 0
6528 && now - mPendingPanicGestureUptime <= PANIC_GESTURE_EXPIRATION;
6529 if (pendingPanic && hideNavBarSysui && !isStatusBarKeyguard() && mKeyguardDrawComplete) {
6530 // The user performed the panic gesture recently, we're about to hide the bars,
6531 // we're no longer on the Keyguard and the screen is ready. We can now request the bars.
6532 mPendingPanicGestureUptime = 0;
6533 mStatusBarController.showTransient();
6534 mNavigationBarController.showTransient();
6535 }
6536
John Spurlockf25706f2013-11-07 18:02:43 -05006537 boolean denyTransientStatus = mStatusBarController.isTransientShowRequested()
John Spurlockf1a36642013-10-12 17:50:42 -04006538 && !transientStatusBarAllowed && hideStatusBarSysui;
John Spurlockf25706f2013-11-07 18:02:43 -05006539 boolean denyTransientNav = mNavigationBarController.isTransientShowRequested()
John Spurlockf1a36642013-10-12 17:50:42 -04006540 && !transientNavBarAllowed;
6541 if (denyTransientStatus || denyTransientNav) {
John Spurlock27735a42013-08-14 17:57:38 -04006542 // clear the clearable flags instead
John Spurlockf1a36642013-10-12 17:50:42 -04006543 clearClearableFlagsLw();
tiger_huangc58d7562014-10-23 20:24:19 +08006544 vis &= ~View.SYSTEM_UI_CLEARABLE_FLAGS;
John Spurlockad3e6cb2013-04-30 08:47:43 -04006545 }
John Spurlock27735a42013-08-14 17:57:38 -04006546
Selim Cinekf98702e2015-05-20 22:48:40 -07006547 final boolean immersive = (vis & View.SYSTEM_UI_FLAG_IMMERSIVE) != 0;
6548 immersiveSticky = (vis & View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY) != 0;
6549 final boolean navAllowedHidden = immersive || immersiveSticky;
6550
Selim Cinekd6623612015-05-22 18:56:22 -07006551 if (hideNavBarSysui && !navAllowedHidden && windowTypeToLayerLw(win.getBaseType())
6552 > windowTypeToLayerLw(TYPE_INPUT_CONSUMER)) {
Selim Cinekf98702e2015-05-20 22:48:40 -07006553 // We can't hide the navbar from this window otherwise the input consumer would not get
6554 // the input events.
6555 vis = (vis & ~View.SYSTEM_UI_FLAG_HIDE_NAVIGATION);
6556 }
6557
John Spurlock27735a42013-08-14 17:57:38 -04006558 vis = mStatusBarController.updateVisibilityLw(transientStatusBarAllowed, oldVis, vis);
6559
6560 // update navigation bar
John Spurlockf1a36642013-10-12 17:50:42 -04006561 boolean oldImmersiveMode = isImmersiveMode(oldVis);
6562 boolean newImmersiveMode = isImmersiveMode(vis);
6563 if (win != null && oldImmersiveMode != newImmersiveMode) {
John Spurlock79da8332013-09-20 12:04:47 -04006564 final String pkg = win.getOwningPackage();
Maurice Lam99c6e072014-04-28 18:24:28 -07006565 mImmersiveModeConfirmation.immersiveModeChanged(pkg, newImmersiveMode,
6566 isUserSetupComplete());
John Spurlock34e13d92013-08-10 06:52:28 -04006567 }
John Spurlock27735a42013-08-14 17:57:38 -04006568
John Spurlockf1a36642013-10-12 17:50:42 -04006569 vis = mNavigationBarController.updateVisibilityLw(transientNavBarAllowed, oldVis, vis);
6570
John Spurlocke1f366f2013-08-05 12:22:40 -04006571 return vis;
John Spurlockad3e6cb2013-04-30 08:47:43 -04006572 }
6573
John Spurlockf1a36642013-10-12 17:50:42 -04006574 private void clearClearableFlagsLw() {
6575 int newVal = mResettingSystemUiFlags | View.SYSTEM_UI_CLEARABLE_FLAGS;
6576 if (newVal != mResettingSystemUiFlags) {
6577 mResettingSystemUiFlags = newVal;
6578 mWindowManagerFuncs.reevaluateStatusBarVisibility();
6579 }
6580 }
6581
6582 private boolean isImmersiveMode(int vis) {
6583 final int flags = View.SYSTEM_UI_FLAG_IMMERSIVE | View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY;
John Spurlock34e13d92013-08-10 06:52:28 -04006584 return mNavigationBar != null
6585 && (vis & View.SYSTEM_UI_FLAG_HIDE_NAVIGATION) != 0
Daniel Sandler900ece52013-10-18 15:53:27 -04006586 && (vis & flags) != 0
6587 && canHideNavigationBar();
John Spurlock34e13d92013-08-10 06:52:28 -04006588 }
6589
Alan Viverette5a0f4ec2013-10-07 15:10:29 -07006590 /**
Daniel Sandlerdd73ee42013-10-11 22:19:59 -04006591 * @return whether the navigation or status bar can be made translucent
6592 *
6593 * This should return true unless touch exploration is not enabled or
6594 * R.boolean.config_enableTranslucentDecor is false.
Alan Viverette5a0f4ec2013-10-07 15:10:29 -07006595 */
Daniel Sandlerdd73ee42013-10-11 22:19:59 -04006596 private boolean areTranslucentBarsAllowed() {
Svetoslav8e3feb12014-02-24 13:46:47 -08006597 return mTranslucentDecorEnabled
6598 && !mAccessibilityManager.isTouchExplorationEnabled();
Alan Viverette5a0f4ec2013-10-07 15:10:29 -07006599 }
6600
Daniel Sandler0c4ccff2011-10-19 16:39:14 -04006601 // Use this instead of checking config_showNavigationBar so that it can be consistently
6602 // overridden by qemu.hw.mainkeys in the emulator.
Craig Mautnereda67292013-04-28 13:50:14 -07006603 @Override
Daniel Sandler0c4ccff2011-10-19 16:39:14 -04006604 public boolean hasNavigationBar() {
6605 return mHasNavigationBar;
6606 }
6607
satok1bc0a492012-04-25 22:47:12 +09006608 @Override
6609 public void setLastInputMethodWindowLw(WindowState ime, WindowState target) {
6610 mLastInputMethodWindow = ime;
6611 mLastInputMethodTargetWindow = target;
6612 }
6613
Craig Mautnerf1b67412012-09-19 13:18:29 -07006614 @Override
Satoshi Kataoka658c7b82013-10-10 17:03:51 +09006615 public int getInputMethodWindowVisibleHeightLw() {
6616 return mDockBottom - mCurBottom;
6617 }
6618
6619 @Override
Craig Mautnerf1b67412012-09-19 13:18:29 -07006620 public void setCurrentUserLw(int newUserId) {
Craig Mautnerd625ab22013-09-06 13:40:31 -07006621 mCurrentUserId = newUserId;
Jim Miller5ecd8112013-01-09 18:50:26 -08006622 if (mKeyguardDelegate != null) {
6623 mKeyguardDelegate.setCurrentUser(newUserId);
Craig Mautnerf1b67412012-09-19 13:18:29 -07006624 }
John Spurlock13451a22012-09-28 14:40:41 -04006625 if (mStatusBarService != null) {
6626 try {
6627 mStatusBarService.setCurrentUser(newUserId);
6628 } catch (RemoteException e) {
6629 // oh well
6630 }
6631 }
Dianne Hackborn2ea9bae2012-11-02 18:43:48 -07006632 setLastInputMethodWindowLw(null, null);
Craig Mautnerf1b67412012-09-19 13:18:29 -07006633 }
6634
6635 @Override
Svetoslav Ganov545252f2012-12-10 18:29:24 -08006636 public boolean canMagnifyWindow(int windowType) {
6637 switch (windowType) {
6638 case WindowManager.LayoutParams.TYPE_INPUT_METHOD:
6639 case WindowManager.LayoutParams.TYPE_INPUT_METHOD_DIALOG:
6640 case WindowManager.LayoutParams.TYPE_NAVIGATION_BAR:
6641 case WindowManager.LayoutParams.TYPE_MAGNIFICATION_OVERLAY: {
6642 return false;
6643 }
6644 }
6645 return true;
6646 }
6647
6648 @Override
6649 public boolean isTopLevelWindow(int windowType) {
6650 if (windowType >= WindowManager.LayoutParams.FIRST_SUB_WINDOW
6651 && windowType <= WindowManager.LayoutParams.LAST_SUB_WINDOW) {
6652 return (windowType == WindowManager.LayoutParams.TYPE_APPLICATION_ATTACHED_DIALOG);
6653 }
6654 return true;
6655 }
6656
Jim Miller4eeb4f62012-11-08 00:04:29 -08006657 @Override
Jeff Brownd7a04de2012-06-17 14:17:52 -07006658 public void dump(String prefix, PrintWriter pw, String[] args) {
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08006659 pw.print(prefix); pw.print("mSafeMode="); pw.print(mSafeMode);
Dianne Hackbornba24e4d2011-09-01 11:17:06 -07006660 pw.print(" mSystemReady="); pw.print(mSystemReady);
6661 pw.print(" mSystemBooted="); pw.println(mSystemBooted);
Jeff Brown2e7760e2012-04-11 15:14:55 -07006662 pw.print(prefix); pw.print("mLidState="); pw.print(mLidState);
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08006663 pw.print(" mLidOpenRotation="); pw.print(mLidOpenRotation);
Michael Wright3818c922014-09-02 13:59:07 -07006664 pw.print(" mCameraLensCoverState="); pw.print(mCameraLensCoverState);
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08006665 pw.print(" mHdmiPlugged="); pw.println(mHdmiPlugged);
Dianne Hackborne26ab702011-10-16 13:21:33 -07006666 if (mLastSystemUiFlags != 0 || mResettingSystemUiFlags != 0
6667 || mForceClearedSystemUiFlags != 0) {
6668 pw.print(prefix); pw.print("mLastSystemUiFlags=0x");
6669 pw.print(Integer.toHexString(mLastSystemUiFlags));
6670 pw.print(" mResettingSystemUiFlags=0x");
6671 pw.print(Integer.toHexString(mResettingSystemUiFlags));
6672 pw.print(" mForceClearedSystemUiFlags=0x");
6673 pw.println(Integer.toHexString(mForceClearedSystemUiFlags));
Dianne Hackborndf89e652011-10-06 22:35:11 -07006674 }
Dianne Hackborn4eff8d32011-11-10 19:38:40 -08006675 if (mLastFocusNeedsMenu) {
6676 pw.print(prefix); pw.print("mLastFocusNeedsMenu=");
6677 pw.println(mLastFocusNeedsMenu);
6678 }
Jeff Browna20dda42014-05-27 20:57:24 -07006679 pw.print(prefix); pw.print("mWakeGestureEnabledSetting=");
6680 pw.println(mWakeGestureEnabledSetting);
6681
Jeff Brownbcdfc622014-03-06 19:13:04 -08006682 pw.print(prefix); pw.print("mSupportAutoRotation="); pw.println(mSupportAutoRotation);
Daniel Sandler6396c722013-04-16 20:19:09 -04006683 pw.print(prefix); pw.print("mUiMode="); pw.print(mUiMode);
6684 pw.print(" mDockMode="); pw.print(mDockMode);
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08006685 pw.print(" mCarDockRotation="); pw.print(mCarDockRotation);
6686 pw.print(" mDeskDockRotation="); pw.println(mDeskDockRotation);
6687 pw.print(prefix); pw.print("mUserRotationMode="); pw.print(mUserRotationMode);
6688 pw.print(" mUserRotation="); pw.print(mUserRotation);
Daniel Sandler2ed6ad62011-02-22 14:54:17 -05006689 pw.print(" mAllowAllRotations="); pw.println(mAllowAllRotations);
Dianne Hackborn6e2281d2012-06-19 17:48:32 -07006690 pw.print(prefix); pw.print("mCurrentAppOrientation="); pw.println(mCurrentAppOrientation);
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08006691 pw.print(prefix); pw.print("mCarDockEnablesAccelerometer=");
6692 pw.print(mCarDockEnablesAccelerometer);
6693 pw.print(" mDeskDockEnablesAccelerometer=");
6694 pw.println(mDeskDockEnablesAccelerometer);
6695 pw.print(prefix); pw.print("mLidKeyboardAccessibility=");
6696 pw.print(mLidKeyboardAccessibility);
6697 pw.print(" mLidNavigationAccessibility="); pw.print(mLidNavigationAccessibility);
Dianne Hackborn6e2281d2012-06-19 17:48:32 -07006698 pw.print(" mLidControlsSleep="); pw.println(mLidControlsSleep);
Jeff Brown6d8fd272014-05-20 21:24:38 -07006699 pw.print(prefix);
6700 pw.print("mShortPressOnPowerBehavior="); pw.print(mShortPressOnPowerBehavior);
6701 pw.print(" mLongPressOnPowerBehavior="); pw.println(mLongPressOnPowerBehavior);
Jeff Brown13f00f02014-10-31 14:45:50 -07006702 pw.print(prefix);
6703 pw.print("mDoublePressOnPowerBehavior="); pw.print(mDoublePressOnPowerBehavior);
6704 pw.print(" mTriplePressOnPowerBehavior="); pw.println(mTriplePressOnPowerBehavior);
Jeff Brown6d8fd272014-05-20 21:24:38 -07006705 pw.print(prefix); pw.print("mHasSoftInput="); pw.println(mHasSoftInput);
Jeff Brown3ee549c2014-09-22 20:14:39 -07006706 pw.print(prefix); pw.print("mAwake="); pw.println(mAwake);
6707 pw.print(prefix); pw.print("mScreenOnEarly="); pw.print(mScreenOnEarly);
6708 pw.print(" mScreenOnFully="); pw.println(mScreenOnFully);
6709 pw.print(prefix); pw.print("mKeyguardDrawComplete="); pw.print(mKeyguardDrawComplete);
6710 pw.print(" mWindowManagerDrawComplete="); pw.println(mWindowManagerDrawComplete);
6711 pw.print(prefix); pw.print("mOrientationSensorEnabled=");
6712 pw.println(mOrientationSensorEnabled);
Dianne Hackbornc652de82013-02-15 16:32:56 -08006713 pw.print(prefix); pw.print("mOverscanScreen=("); pw.print(mOverscanScreenLeft);
6714 pw.print(","); pw.print(mOverscanScreenTop);
6715 pw.print(") "); pw.print(mOverscanScreenWidth);
6716 pw.print("x"); pw.println(mOverscanScreenHeight);
6717 if (mOverscanLeft != 0 || mOverscanTop != 0
6718 || mOverscanRight != 0 || mOverscanBottom != 0) {
6719 pw.print(prefix); pw.print("mOverscan left="); pw.print(mOverscanLeft);
6720 pw.print(" top="); pw.print(mOverscanTop);
6721 pw.print(" right="); pw.print(mOverscanRight);
6722 pw.print(" bottom="); pw.println(mOverscanBottom);
6723 }
Dianne Hackborn313440842013-02-19 19:22:59 -08006724 pw.print(prefix); pw.print("mRestrictedOverscanScreen=(");
6725 pw.print(mRestrictedOverscanScreenLeft);
6726 pw.print(","); pw.print(mRestrictedOverscanScreenTop);
6727 pw.print(") "); pw.print(mRestrictedOverscanScreenWidth);
6728 pw.print("x"); pw.println(mRestrictedOverscanScreenHeight);
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08006729 pw.print(prefix); pw.print("mUnrestrictedScreen=("); pw.print(mUnrestrictedScreenLeft);
6730 pw.print(","); pw.print(mUnrestrictedScreenTop);
6731 pw.print(") "); pw.print(mUnrestrictedScreenWidth);
6732 pw.print("x"); pw.println(mUnrestrictedScreenHeight);
6733 pw.print(prefix); pw.print("mRestrictedScreen=("); pw.print(mRestrictedScreenLeft);
6734 pw.print(","); pw.print(mRestrictedScreenTop);
6735 pw.print(") "); pw.print(mRestrictedScreenWidth);
6736 pw.print("x"); pw.println(mRestrictedScreenHeight);
Dianne Hackborn5b5cc4d2012-05-16 13:15:00 -07006737 pw.print(prefix); pw.print("mStableFullscreen=("); pw.print(mStableFullscreenLeft);
6738 pw.print(","); pw.print(mStableFullscreenTop);
6739 pw.print(")-("); pw.print(mStableFullscreenRight);
6740 pw.print(","); pw.print(mStableFullscreenBottom); pw.println(")");
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07006741 pw.print(prefix); pw.print("mStable=("); pw.print(mStableLeft);
6742 pw.print(","); pw.print(mStableTop);
6743 pw.print(")-("); pw.print(mStableRight);
6744 pw.print(","); pw.print(mStableBottom); pw.println(")");
Dianne Hackborn5c58de32012-04-28 19:52:37 -07006745 pw.print(prefix); pw.print("mSystem=("); pw.print(mSystemLeft);
6746 pw.print(","); pw.print(mSystemTop);
6747 pw.print(")-("); pw.print(mSystemRight);
6748 pw.print(","); pw.print(mSystemBottom); pw.println(")");
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08006749 pw.print(prefix); pw.print("mCur=("); pw.print(mCurLeft);
6750 pw.print(","); pw.print(mCurTop);
6751 pw.print(")-("); pw.print(mCurRight);
6752 pw.print(","); pw.print(mCurBottom); pw.println(")");
6753 pw.print(prefix); pw.print("mContent=("); pw.print(mContentLeft);
6754 pw.print(","); pw.print(mContentTop);
6755 pw.print(")-("); pw.print(mContentRight);
6756 pw.print(","); pw.print(mContentBottom); pw.println(")");
Dianne Hackborne30e02f2014-05-27 18:24:45 -07006757 pw.print(prefix); pw.print("mVoiceContent=("); pw.print(mVoiceContentLeft);
6758 pw.print(","); pw.print(mVoiceContentTop);
6759 pw.print(")-("); pw.print(mVoiceContentRight);
6760 pw.print(","); pw.print(mVoiceContentBottom); pw.println(")");
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08006761 pw.print(prefix); pw.print("mDock=("); pw.print(mDockLeft);
6762 pw.print(","); pw.print(mDockTop);
6763 pw.print(")-("); pw.print(mDockRight);
6764 pw.print(","); pw.print(mDockBottom); pw.println(")");
Dianne Hackborn5c58de32012-04-28 19:52:37 -07006765 pw.print(prefix); pw.print("mDockLayer="); pw.print(mDockLayer);
6766 pw.print(" mStatusBarLayer="); pw.println(mStatusBarLayer);
Dianne Hackborn7ad44382012-10-18 17:46:00 -07006767 pw.print(prefix); pw.print("mShowingLockscreen="); pw.print(mShowingLockscreen);
6768 pw.print(" mShowingDream="); pw.print(mShowingDream);
Jeff Brown061ea992015-04-17 19:55:47 -07006769 pw.print(" mDreamingLockscreen="); pw.print(mDreamingLockscreen);
6770 pw.print(" mDreamingSleepToken="); pw.println(mDreamingSleepToken);
Dianne Hackborn2ea9bae2012-11-02 18:43:48 -07006771 if (mLastInputMethodWindow != null) {
6772 pw.print(prefix); pw.print("mLastInputMethodWindow=");
6773 pw.println(mLastInputMethodWindow);
6774 }
6775 if (mLastInputMethodTargetWindow != null) {
6776 pw.print(prefix); pw.print("mLastInputMethodTargetWindow=");
6777 pw.println(mLastInputMethodTargetWindow);
6778 }
6779 if (mStatusBar != null) {
6780 pw.print(prefix); pw.print("mStatusBar=");
Dianne Hackbornae6688b2015-02-11 17:02:41 -08006781 pw.print(mStatusBar); pw.print(" isStatusBarKeyguard=");
6782 pw.println(isStatusBarKeyguard());
Dianne Hackborn2ea9bae2012-11-02 18:43:48 -07006783 }
6784 if (mNavigationBar != null) {
6785 pw.print(prefix); pw.print("mNavigationBar=");
6786 pw.println(mNavigationBar);
6787 }
Dianne Hackborn2ea9bae2012-11-02 18:43:48 -07006788 if (mFocusedWindow != null) {
6789 pw.print(prefix); pw.print("mFocusedWindow=");
6790 pw.println(mFocusedWindow);
6791 }
6792 if (mFocusedApp != null) {
6793 pw.print(prefix); pw.print("mFocusedApp=");
6794 pw.println(mFocusedApp);
6795 }
6796 if (mWinDismissingKeyguard != null) {
6797 pw.print(prefix); pw.print("mWinDismissingKeyguard=");
6798 pw.println(mWinDismissingKeyguard);
6799 }
6800 if (mTopFullscreenOpaqueWindowState != null) {
6801 pw.print(prefix); pw.print("mTopFullscreenOpaqueWindowState=");
6802 pw.println(mTopFullscreenOpaqueWindowState);
6803 }
Adrian Rooscd3884d2015-02-18 17:25:23 +01006804 if (mTopFullscreenOpaqueOrDimmingWindowState != null) {
6805 pw.print(prefix); pw.print("mTopFullscreenOpaqueOrDimmingWindowState=");
6806 pw.println(mTopFullscreenOpaqueOrDimmingWindowState);
6807 }
Dianne Hackborn891d3fb2013-01-09 18:31:37 -08006808 if (mForcingShowNavBar) {
6809 pw.print(prefix); pw.print("mForcingShowNavBar=");
6810 pw.println(mForcingShowNavBar); pw.print( "mForcingShowNavBarLayer=");
6811 pw.println(mForcingShowNavBarLayer);
6812 }
Dianne Hackborn7ad44382012-10-18 17:46:00 -07006813 pw.print(prefix); pw.print("mTopIsFullscreen="); pw.print(mTopIsFullscreen);
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08006814 pw.print(" mHideLockScreen="); pw.println(mHideLockScreen);
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07006815 pw.print(prefix); pw.print("mForceStatusBar="); pw.print(mForceStatusBar);
6816 pw.print(" mForceStatusBarFromKeyguard=");
6817 pw.println(mForceStatusBarFromKeyguard);
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08006818 pw.print(prefix); pw.print("mDismissKeyguard="); pw.print(mDismissKeyguard);
Craig Mautnerad09bcc2012-10-08 13:33:11 -07006819 pw.print(" mWinDismissingKeyguard="); pw.print(mWinDismissingKeyguard);
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08006820 pw.print(" mHomePressed="); pw.println(mHomePressed);
6821 pw.print(prefix); pw.print("mAllowLockscreenWhenOn="); pw.print(mAllowLockscreenWhenOn);
6822 pw.print(" mLockScreenTimeout="); pw.print(mLockScreenTimeout);
6823 pw.print(" mLockScreenTimerActive="); pw.println(mLockScreenTimerActive);
6824 pw.print(prefix); pw.print("mEndcallBehavior="); pw.print(mEndcallBehavior);
6825 pw.print(" mIncallPowerBehavior="); pw.print(mIncallPowerBehavior);
6826 pw.print(" mLongPressOnHomeBehavior="); pw.println(mLongPressOnHomeBehavior);
6827 pw.print(prefix); pw.print("mLandscapeRotation="); pw.print(mLandscapeRotation);
6828 pw.print(" mSeascapeRotation="); pw.println(mSeascapeRotation);
6829 pw.print(prefix); pw.print("mPortraitRotation="); pw.print(mPortraitRotation);
6830 pw.print(" mUpsideDownRotation="); pw.println(mUpsideDownRotation);
Jeff Brownc82c89ed2013-04-17 17:18:15 -07006831 pw.print(prefix); pw.print("mDemoHdmiRotation="); pw.print(mDemoHdmiRotation);
6832 pw.print(" mDemoHdmiRotationLock="); pw.println(mDemoHdmiRotationLock);
6833 pw.print(prefix); pw.print("mUndockedHdmiRotation="); pw.println(mUndockedHdmiRotation);
Jeff Brown600f0032014-05-22 17:06:00 -07006834
Tim Kilbournd7c0c2e2014-05-29 16:08:10 -07006835 mGlobalKeyManager.dump(prefix, pw);
John Spurlock27735a42013-08-14 17:57:38 -04006836 mStatusBarController.dump(pw, prefix);
6837 mNavigationBarController.dump(pw, prefix);
John Spurlockc6d1c602014-01-17 15:22:06 -05006838 PolicyControl.dump(prefix, pw);
Jeff Brown600f0032014-05-22 17:06:00 -07006839
Jeff Browna20dda42014-05-27 20:57:24 -07006840 if (mWakeGestureListener != null) {
6841 mWakeGestureListener.dump(pw, prefix);
6842 }
Jeff Brown600f0032014-05-22 17:06:00 -07006843 if (mOrientationListener != null) {
6844 mOrientationListener.dump(pw, prefix);
6845 }
Filip Gruszczynskicfb31852015-02-25 21:47:12 +00006846 if (mBurnInProtectionHelper != null) {
6847 mBurnInProtectionHelper.dump(prefix, pw);
6848 }
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08006849 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006850}