blob: 689141a89f142a90455dbfe29cb9002dc6cf0050 [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
Filip Gruszczynski2987f612015-06-30 15:03:30 -0700552 private int mDisplayRotation;
553
Dianne Hackborn9d132642011-04-21 17:26:39 -0700554 int mLandscapeRotation = 0; // default landscape rotation
555 int mSeascapeRotation = 0; // "other" landscape rotation, 180 degrees from mLandscapeRotation
556 int mPortraitRotation = 0; // default portrait rotation
557 int mUpsideDownRotation = 0; // "other" portrait rotation
Mitsuru Oshima831d0d92009-06-16 18:27:18 -0700558
Dianne Hackbornc652de82013-02-15 16:32:56 -0800559 int mOverscanLeft = 0;
560 int mOverscanTop = 0;
561 int mOverscanRight = 0;
562 int mOverscanBottom = 0;
563
Joe Onorato46b0d682010-11-22 17:37:27 -0800564 // What we do when the user long presses on home
Jeff Browncaca8812013-05-09 13:34:33 -0700565 private int mLongPressOnHomeBehavior;
566
567 // What we do when the user double-taps on home
568 private int mDoubleTapOnHomeBehavior;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800569
Bryce Lee584a4452014-10-21 15:55:55 -0700570 // Allowed theater mode wake actions
571 private boolean mAllowTheaterModeWakeFromKey;
572 private boolean mAllowTheaterModeWakeFromPowerKey;
573 private boolean mAllowTheaterModeWakeFromMotion;
Bryce Lee812d7022014-11-10 13:33:28 -0800574 private boolean mAllowTheaterModeWakeFromMotionWhenNotDreaming;
Bryce Lee584a4452014-10-21 15:55:55 -0700575 private boolean mAllowTheaterModeWakeFromCameraLens;
576 private boolean mAllowTheaterModeWakeFromLidSwitch;
577 private boolean mAllowTheaterModeWakeFromWakeGesture;
578
Bryce Leed3b28402015-03-09 15:49:13 +0000579 // Whether to support long press from power button in non-interactive mode
580 private boolean mSupportLongPressPowerWhenNonInteractive;
581
Bryce Lee55e846d2014-11-04 12:43:44 -0800582 // Whether to go to sleep entering theater mode from power button
583 private boolean mGoToSleepOnButtonPressTheaterMode;
584
Winson Chung9112ec32011-06-27 13:15:32 -0700585 // Screenshot trigger states
Jeff Brownd5bb82d2011-10-12 13:57:59 -0700586 // Time to volume and power must be pressed within this interval of each other.
587 private static final long SCREENSHOT_CHORD_DEBOUNCE_DELAY_MILLIS = 150;
Winson Chung1cea2f32012-10-08 20:42:01 -0700588 // Increase the chord delay when taking a screenshot from the keyguard
589 private static final float KEYGUARD_SCREENSHOT_CHORD_DELAY_MULTIPLIER = 2.5f;
Christopher Tatee90585f2012-03-05 18:56:25 -0800590 private boolean mScreenshotChordEnabled;
Jeff Brown13f00f02014-10-31 14:45:50 -0700591 private boolean mScreenshotChordVolumeDownKeyTriggered;
592 private long mScreenshotChordVolumeDownKeyTime;
593 private boolean mScreenshotChordVolumeDownKeyConsumed;
594 private boolean mScreenshotChordVolumeUpKeyTriggered;
595 private boolean mScreenshotChordPowerKeyTriggered;
596 private long mScreenshotChordPowerKeyTime;
Winson Chung9112ec32011-06-27 13:15:32 -0700597
Michael Wrightb854e242013-02-05 17:54:02 -0800598 /* The number of steps between min and max brightness */
599 private static final int BRIGHTNESS_STEPS = 10;
600
Christopher Tate5e08af02012-09-21 17:17:22 -0700601 SettingsObserver mSettingsObserver;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800602 ShortcutManager mShortcutManager;
603 PowerManager.WakeLock mBroadcastWakeLock;
Jeff Brown13f00f02014-10-31 14:45:50 -0700604 PowerManager.WakeLock mPowerKeyWakeLock;
Jeff Brown40013652012-05-16 21:22:36 -0700605 boolean mHavePendingMediaKeyRepeatWithWakeLock;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800606
Craig Mautnerd625ab22013-09-06 13:40:31 -0700607 private int mCurrentUserId;
608
Justin Kohd378ad72013-04-01 12:18:26 -0700609 // Maps global key codes to the components that will handle them.
610 private GlobalKeyManager mGlobalKeyManager;
611
Jeff Brownfd23e3e2012-05-09 13:34:28 -0700612 // Fallback actions by key code.
613 private final SparseArray<KeyCharacterMap.FallbackAction> mFallbackActions =
614 new SparseArray<KeyCharacterMap.FallbackAction>();
Jeff Brown49ed71d2010-12-06 17:13:33 -0800615
Jorim Jaggi76a16232014-08-08 17:00:47 +0200616 private final LogDecelerateInterpolator mLogDecelerateInterpolator
617 = new LogDecelerateInterpolator(100, 0);
618
Jeff Brown70825162012-03-28 17:27:48 -0700619 private static final int MSG_ENABLE_POINTER_LOCATION = 1;
620 private static final int MSG_DISABLE_POINTER_LOCATION = 2;
Jeff Brown40013652012-05-16 21:22:36 -0700621 private static final int MSG_DISPATCH_MEDIA_KEY_WITH_WAKE_LOCK = 3;
622 private static final int MSG_DISPATCH_MEDIA_KEY_REPEAT_WITH_WAKE_LOCK = 4;
Craig Mautner8a0da012014-05-31 15:13:37 -0700623 private static final int MSG_KEYGUARD_DRAWN_COMPLETE = 5;
624 private static final int MSG_KEYGUARD_DRAWN_TIMEOUT = 6;
625 private static final int MSG_WINDOW_MANAGER_DRAWN_COMPLETE = 7;
Craig Mautner84984fa2014-06-19 11:19:20 -0700626 private static final int MSG_DISPATCH_SHOW_RECENTS = 9;
Alan Viverettee34560b22014-07-10 14:50:06 -0700627 private static final int MSG_DISPATCH_SHOW_GLOBAL_ACTIONS = 10;
Craig Mautnera631d492014-08-05 15:16:01 -0700628 private static final int MSG_HIDE_BOOT_MESSAGE = 11;
Michael Wright869a67c2014-08-26 19:33:06 -0700629 private static final int MSG_LAUNCH_VOICE_ASSIST_WITH_WAKE_LOCK = 12;
Jeff Brown13f00f02014-10-31 14:45:50 -0700630 private static final int MSG_POWER_DELAYED_PRESS = 13;
631 private static final int MSG_POWER_LONG_PRESS = 14;
Jeff Brown061ea992015-04-17 19:55:47 -0700632 private static final int MSG_UPDATE_DREAMING_SLEEP_TOKEN = 15;
Jeff Brown70825162012-03-28 17:27:48 -0700633
634 private class PolicyHandler extends Handler {
635 @Override
636 public void handleMessage(Message msg) {
637 switch (msg.what) {
638 case MSG_ENABLE_POINTER_LOCATION:
639 enablePointerLocation();
640 break;
641 case MSG_DISABLE_POINTER_LOCATION:
642 disablePointerLocation();
643 break;
Jeff Brown40013652012-05-16 21:22:36 -0700644 case MSG_DISPATCH_MEDIA_KEY_WITH_WAKE_LOCK:
645 dispatchMediaKeyWithWakeLock((KeyEvent)msg.obj);
646 break;
647 case MSG_DISPATCH_MEDIA_KEY_REPEAT_WITH_WAKE_LOCK:
648 dispatchMediaKeyRepeatWithWakeLock((KeyEvent)msg.obj);
649 break;
Craig Mautner84984fa2014-06-19 11:19:20 -0700650 case MSG_DISPATCH_SHOW_RECENTS:
651 showRecentApps(false);
652 break;
Alan Viverettee34560b22014-07-10 14:50:06 -0700653 case MSG_DISPATCH_SHOW_GLOBAL_ACTIONS:
654 showGlobalActionsInternal();
655 break;
Craig Mautner8a0da012014-05-31 15:13:37 -0700656 case MSG_KEYGUARD_DRAWN_COMPLETE:
657 if (DEBUG_WAKEUP) Slog.w(TAG, "Setting mKeyguardDrawComplete");
Jeff Brown36c4db82014-09-19 12:05:31 -0700658 finishKeyguardDrawn();
Craig Mautner8a0da012014-05-31 15:13:37 -0700659 break;
660 case MSG_KEYGUARD_DRAWN_TIMEOUT:
661 Slog.w(TAG, "Keyguard drawn timeout. Setting mKeyguardDrawComplete");
Jeff Brown36c4db82014-09-19 12:05:31 -0700662 finishKeyguardDrawn();
Craig Mautner8a0da012014-05-31 15:13:37 -0700663 break;
664 case MSG_WINDOW_MANAGER_DRAWN_COMPLETE:
665 if (DEBUG_WAKEUP) Slog.w(TAG, "Setting mWindowManagerDrawComplete");
Jeff Brown36c4db82014-09-19 12:05:31 -0700666 finishWindowsDrawn();
Craig Mautner8a0da012014-05-31 15:13:37 -0700667 break;
Craig Mautnera631d492014-08-05 15:16:01 -0700668 case MSG_HIDE_BOOT_MESSAGE:
669 handleHideBootMessage();
670 break;
Michael Wright869a67c2014-08-26 19:33:06 -0700671 case MSG_LAUNCH_VOICE_ASSIST_WITH_WAKE_LOCK:
672 launchVoiceAssistWithWakeLock(msg.arg1 != 0);
673 break;
Jeff Brown13f00f02014-10-31 14:45:50 -0700674 case MSG_POWER_DELAYED_PRESS:
675 powerPress((Long)msg.obj, msg.arg1 != 0, msg.arg2);
676 finishPowerKeyPress();
677 break;
678 case MSG_POWER_LONG_PRESS:
679 powerLongPress();
680 break;
Jeff Brown061ea992015-04-17 19:55:47 -0700681 case MSG_UPDATE_DREAMING_SLEEP_TOKEN:
682 updateDreamingSleepToken(msg.arg1 != 0);
683 break;
Jeff Brown70825162012-03-28 17:27:48 -0700684 }
685 }
686 }
687
Dianne Hackbornad7fa7f2011-01-07 14:06:50 -0800688 private UEventObserver mHDMIObserver = new UEventObserver() {
689 @Override
690 public void onUEvent(UEventObserver.UEvent event) {
691 setHdmiPlugged("1".equals(event.get("SWITCH_STATE")));
692 }
693 };
694
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800695 class SettingsObserver extends ContentObserver {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800696 SettingsObserver(Handler handler) {
697 super(handler);
698 }
David Brownbaf8d092010-03-08 21:52:59 -0800699
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800700 void observe() {
Christopher Tate5e08af02012-09-21 17:17:22 -0700701 // Observe all users' changes
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800702 ContentResolver resolver = mContext.getContentResolver();
703 resolver.registerContentObserver(Settings.System.getUriFor(
Christopher Tate5e08af02012-09-21 17:17:22 -0700704 Settings.System.END_BUTTON_BEHAVIOR), false, this,
705 UserHandle.USER_ALL);
David Brownbaf8d092010-03-08 21:52:59 -0800706 resolver.registerContentObserver(Settings.Secure.getUriFor(
Christopher Tate5e08af02012-09-21 17:17:22 -0700707 Settings.Secure.INCALL_POWER_BUTTON_BEHAVIOR), false, this,
708 UserHandle.USER_ALL);
Jeff Browna20dda42014-05-27 20:57:24 -0700709 resolver.registerContentObserver(Settings.Secure.getUriFor(
710 Settings.Secure.WAKE_GESTURE_ENABLED), false, this,
711 UserHandle.USER_ALL);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800712 resolver.registerContentObserver(Settings.System.getUriFor(
Christopher Tate5e08af02012-09-21 17:17:22 -0700713 Settings.System.ACCELEROMETER_ROTATION), false, this,
714 UserHandle.USER_ALL);
Mike Lockwood28569302010-01-28 11:54:40 -0500715 resolver.registerContentObserver(Settings.System.getUriFor(
Christopher Tate5e08af02012-09-21 17:17:22 -0700716 Settings.System.USER_ROTATION), false, this,
717 UserHandle.USER_ALL);
Daniel Sandlerb73617d2010-08-17 00:41:00 -0400718 resolver.registerContentObserver(Settings.System.getUriFor(
Christopher Tate5e08af02012-09-21 17:17:22 -0700719 Settings.System.SCREEN_OFF_TIMEOUT), false, this,
720 UserHandle.USER_ALL);
Dianne Hackbornc777e072010-02-12 13:07:59 -0800721 resolver.registerContentObserver(Settings.System.getUriFor(
Christopher Tate5e08af02012-09-21 17:17:22 -0700722 Settings.System.POINTER_LOCATION), false, this,
723 UserHandle.USER_ALL);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800724 resolver.registerContentObserver(Settings.Secure.getUriFor(
Christopher Tate5e08af02012-09-21 17:17:22 -0700725 Settings.Secure.DEFAULT_INPUT_METHOD), false, this,
726 UserHandle.USER_ALL);
John Spurlockd9b70bd2014-02-06 17:02:44 -0500727 resolver.registerContentObserver(Settings.Secure.getUriFor(
John Spurlockf1a36642013-10-12 17:50:42 -0400728 Settings.Secure.IMMERSIVE_MODE_CONFIRMATIONS), false, this,
Christopher Tate5e08af02012-09-21 17:17:22 -0700729 UserHandle.USER_ALL);
John Spurlockc6d1c602014-01-17 15:22:06 -0500730 resolver.registerContentObserver(Settings.Global.getUriFor(
731 Settings.Global.POLICY_CONTROL), false, this,
732 UserHandle.USER_ALL);
Dianne Hackbornc777e072010-02-12 13:07:59 -0800733 updateSettings();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800734 }
735
736 @Override public void onChange(boolean selfChange) {
Dianne Hackbornc777e072010-02-12 13:07:59 -0800737 updateSettings();
Jeff Brown01a98dd2011-09-20 15:08:29 -0700738 updateRotation(false);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800739 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800740 }
Craig Mautner967212c2013-04-13 21:10:58 -0700741
Jeff Browna20dda42014-05-27 20:57:24 -0700742 class MyWakeGestureListener extends WakeGestureListener {
743 MyWakeGestureListener(Context context, Handler handler) {
744 super(context, handler);
745 }
746
747 @Override
748 public void onWakeUp() {
749 synchronized (mLock) {
750 if (shouldEnableWakeGestureLp()) {
Jeff Browne07b94b2014-06-18 15:56:27 -0700751 performHapticFeedbackLw(null, HapticFeedbackConstants.VIRTUAL_KEY, false);
Bryce Lee584a4452014-10-21 15:55:55 -0700752 wakeUp(SystemClock.uptimeMillis(), mAllowTheaterModeWakeFromWakeGesture);
Jeff Browna20dda42014-05-27 20:57:24 -0700753 }
754 }
755 }
756 }
757
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800758 class MyOrientationListener extends WindowOrientationListener {
Craig Mautnereee29c42013-01-17 14:44:34 -0800759 MyOrientationListener(Context context, Handler handler) {
760 super(context, handler);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800761 }
Craig Mautner967212c2013-04-13 21:10:58 -0700762
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800763 @Override
Jeff Brownc0347aa2011-09-23 17:26:09 -0700764 public void onProposedRotationChanged(int rotation) {
Craig Mautnereda67292013-04-28 13:50:14 -0700765 if (localLOGV) Slog.v(TAG, "onProposedRotationChanged, rotation=" + rotation);
Jeff Brown01a98dd2011-09-20 15:08:29 -0700766 updateRotation(false);
767 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800768 }
769 MyOrientationListener mOrientationListener;
770
Jorim Jaggi24bec7c2015-02-04 12:40:14 +0100771 private final StatusBarController mStatusBarController = new StatusBarController();
John Spurlock5b9145b2013-08-20 15:13:47 -0400772
John Spurlock27735a42013-08-14 17:57:38 -0400773 private final BarController mNavigationBarController = new BarController("NavigationBar",
John Spurlock5b9145b2013-08-20 15:13:47 -0400774 View.NAVIGATION_BAR_TRANSIENT,
775 View.NAVIGATION_BAR_UNHIDE,
John Spurlockbd957402013-10-03 11:38:39 -0400776 View.NAVIGATION_BAR_TRANSLUCENT,
777 StatusBarManager.WINDOW_NAVIGATION_BAR,
778 WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION);
John Spurlock5b9145b2013-08-20 15:13:47 -0400779
John Spurlockf1a36642013-10-12 17:50:42 -0400780 private ImmersiveModeConfirmation mImmersiveModeConfirmation;
John Spurlock32beb2c2013-03-11 10:16:47 -0400781
Craig Mautner037aa8d2013-06-07 10:35:44 -0700782 private SystemGesturesPointerEventListener mSystemGestures;
John Spurlock32beb2c2013-03-11 10:16:47 -0400783
Dianne Hackborn42e620c2012-06-24 13:20:51 -0700784 IStatusBarService getStatusBarService() {
785 synchronized (mServiceAquireLock) {
786 if (mStatusBarService == null) {
787 mStatusBarService = IStatusBarService.Stub.asInterface(
788 ServiceManager.getService("statusbar"));
789 }
790 return mStatusBarService;
791 }
792 }
793
Suchi Amalapurapua9e1b162009-03-24 22:24:47 -0700794 /*
795 * We always let the sensor be switched on by default except when
796 * the user has explicitly disabled sensor based rotation or when the
797 * screen is switched off.
798 */
The Android Open Source Project0727d222009-03-11 12:11:58 -0700799 boolean needSensorRunningLp() {
Jeff Brownbcdfc622014-03-06 19:13:04 -0800800 if (mSupportAutoRotation) {
801 if (mCurrentAppOrientation == ActivityInfo.SCREEN_ORIENTATION_SENSOR
802 || mCurrentAppOrientation == ActivityInfo.SCREEN_ORIENTATION_FULL_SENSOR
803 || mCurrentAppOrientation == ActivityInfo.SCREEN_ORIENTATION_SENSOR_PORTRAIT
804 || mCurrentAppOrientation == ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE) {
805 // If the application has explicitly requested to follow the
806 // orientation, then we need to turn the sensor on.
807 return true;
808 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800809 }
Dianne Hackborn867ab6472010-04-29 13:28:56 -0700810 if ((mCarDockEnablesAccelerometer && mDockMode == Intent.EXTRA_DOCK_STATE_CAR) ||
Jeff Brown1a693182011-11-08 14:44:16 -0800811 (mDeskDockEnablesAccelerometer && (mDockMode == Intent.EXTRA_DOCK_STATE_DESK
812 || mDockMode == Intent.EXTRA_DOCK_STATE_LE_DESK
813 || mDockMode == Intent.EXTRA_DOCK_STATE_HE_DESK))) {
Mike Lockwoode9867d22009-09-20 01:59:02 -0400814 // enable accelerometer if we are docked in a dock that enables accelerometer
815 // orientation management,
816 return true;
817 }
Jeff Brown207673cd2012-06-05 17:47:11 -0700818 if (mUserRotationMode == USER_ROTATION_LOCKED) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800819 // If the setting for using the sensor by default is enabled, then
820 // we will always leave it on. Note that the user could go to
821 // a window that forces an orientation that does not use the
822 // sensor and in theory we could turn it off... however, when next
823 // turning it on we won't have a good value for the current
824 // orientation for a little bit, which can cause orientation
825 // changes to lag, so we'd like to keep it always on. (It will
826 // still be turned off when the screen is off.)
Suchi Amalapurapua9e1b162009-03-24 22:24:47 -0700827 return false;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800828 }
Jeff Brownbcdfc622014-03-06 19:13:04 -0800829 return mSupportAutoRotation;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800830 }
Craig Mautner46ac6fa2013-08-01 10:06:34 -0700831
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800832 /*
833 * Various use cases for invoking this function
834 * screen turning off, should always disable listeners if already enabled
Craig Mautner46ac6fa2013-08-01 10:06:34 -0700835 * screen turned on and current app has sensor based orientation, enable listeners
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800836 * if not already enabled
837 * screen turned on and current app does not have sensor orientation, disable listeners if
838 * already enabled
839 * screen turning on and current app has sensor based orientation, enable listeners if needed
840 * screen turning on and current app has nosensor based orientation, do nothing
841 */
The Android Open Source Project0727d222009-03-11 12:11:58 -0700842 void updateOrientationListenerLp() {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800843 if (!mOrientationListener.canDetectOrientation()) {
844 // If sensor is turned off or nonexistent for some reason
845 return;
846 }
Stefan Kuhne9326dc12015-06-12 09:25:32 -1000847 // Could have been invoked due to screen turning on or off or
848 // change of the currently visible window's orientation.
Jeff Brown3ee549c2014-09-22 20:14:39 -0700849 if (localLOGV) Slog.v(TAG, "mScreenOnEarly=" + mScreenOnEarly
850 + ", mAwake=" + mAwake + ", mCurrentAppOrientation=" + mCurrentAppOrientation
Stefan Kuhne9326dc12015-06-12 09:25:32 -1000851 + ", mOrientationSensorEnabled=" + mOrientationSensorEnabled
852 + ", mKeyguardDrawComplete=" + mKeyguardDrawComplete
853 + ", mWindowManagerDrawComplete=" + mWindowManagerDrawComplete);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800854 boolean disable = true;
Stefan Kuhne9326dc12015-06-12 09:25:32 -1000855 // Note: We postpone the rotating of the screen until the keyguard as well as the
856 // window manager have reported a draw complete.
857 if (mScreenOnEarly && mAwake &&
858 mKeyguardDrawComplete && mWindowManagerDrawComplete) {
The Android Open Source Project0727d222009-03-11 12:11:58 -0700859 if (needSensorRunningLp()) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800860 disable = false;
861 //enable listener if not already enabled
The Android Open Source Project0727d222009-03-11 12:11:58 -0700862 if (!mOrientationSensorEnabled) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800863 mOrientationListener.enable();
Craig Mautnereda67292013-04-28 13:50:14 -0700864 if(localLOGV) Slog.v(TAG, "Enabling listeners");
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800865 mOrientationSensorEnabled = true;
866 }
Craig Mautner46ac6fa2013-08-01 10:06:34 -0700867 }
868 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800869 //check if sensors need to be disabled
The Android Open Source Project0727d222009-03-11 12:11:58 -0700870 if (disable && mOrientationSensorEnabled) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800871 mOrientationListener.disable();
Craig Mautnereda67292013-04-28 13:50:14 -0700872 if(localLOGV) Slog.v(TAG, "Disabling listeners");
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800873 mOrientationSensorEnabled = false;
874 }
875 }
876
Jeff Brown13f00f02014-10-31 14:45:50 -0700877 private void interceptPowerKeyDown(KeyEvent event, boolean interactive) {
878 // Hold a wake lock until the power key is released.
879 if (!mPowerKeyWakeLock.isHeld()) {
880 mPowerKeyWakeLock.acquire();
881 }
882
883 // Cancel multi-press detection timeout.
884 if (mPowerKeyPressCounter != 0) {
885 mHandler.removeMessages(MSG_POWER_DELAYED_PRESS);
886 }
887
888 // Detect user pressing the power button in panic when an application has
889 // taken over the whole screen.
890 boolean panic = mImmersiveModeConfirmation.onPowerKeyDown(interactive,
Craig Mautner0124980e92014-11-30 21:15:34 -0800891 SystemClock.elapsedRealtime(), isImmersiveMode(mLastSystemUiFlags));
Jeff Brown13f00f02014-10-31 14:45:50 -0700892 if (panic) {
Adrian Roosddc8b272015-05-21 16:28:27 -0700893 mHandler.post(mHiddenNavPanic);
Jeff Brown13f00f02014-10-31 14:45:50 -0700894 }
895
896 // Latch power key state to detect screenshot chord.
897 if (interactive && !mScreenshotChordPowerKeyTriggered
898 && (event.getFlags() & KeyEvent.FLAG_FALLBACK) == 0) {
899 mScreenshotChordPowerKeyTriggered = true;
900 mScreenshotChordPowerKeyTime = event.getDownTime();
901 interceptScreenshotChord();
902 }
903
904 // Stop ringing or end call if configured to do so when power is pressed.
905 TelecomManager telecomManager = getTelecommService();
906 boolean hungUp = false;
907 if (telecomManager != null) {
908 if (telecomManager.isRinging()) {
909 // Pressing Power while there's a ringing incoming
910 // call should silence the ringer.
911 telecomManager.silenceRinger();
912 } else if ((mIncallPowerBehavior
913 & Settings.Secure.INCALL_POWER_BUTTON_BEHAVIOR_HANGUP) != 0
914 && telecomManager.isInCall() && interactive) {
915 // Otherwise, if "Power button ends call" is enabled,
916 // the Power button will hang up any current active call.
917 hungUp = telecomManager.endCall();
918 }
919 }
920
921 // If the power key has still not yet been handled, then detect short
922 // press, long press, or multi press and decide what to do.
923 mPowerKeyHandled = hungUp || mScreenshotChordVolumeDownKeyTriggered
924 || mScreenshotChordVolumeUpKeyTriggered;
925 if (!mPowerKeyHandled) {
926 if (interactive) {
927 // When interactive, we're already awake.
928 // Wait for a long press or for the button to be released to decide what to do.
929 if (hasLongPressOnPowerBehavior()) {
930 Message msg = mHandler.obtainMessage(MSG_POWER_LONG_PRESS);
931 msg.setAsynchronous(true);
932 mHandler.sendMessageDelayed(msg,
933 ViewConfiguration.get(mContext).getDeviceGlobalActionKeyTimeout());
934 }
935 } else {
Bryce Leed9268e32014-11-17 17:40:59 -0800936 wakeUpFromPowerKey(event.getDownTime());
Bryce Leed9268e32014-11-17 17:40:59 -0800937
Bryce Leed3b28402015-03-09 15:49:13 +0000938 if (mSupportLongPressPowerWhenNonInteractive && hasLongPressOnPowerBehavior()) {
939 Message msg = mHandler.obtainMessage(MSG_POWER_LONG_PRESS);
940 msg.setAsynchronous(true);
941 mHandler.sendMessageDelayed(msg,
942 ViewConfiguration.get(mContext).getDeviceGlobalActionKeyTimeout());
Bryce Leed9268e32014-11-17 17:40:59 -0800943 mBeganFromNonInteractive = true;
Bryce Leed3b28402015-03-09 15:49:13 +0000944 } else {
945 final int maxCount = getMaxMultiPressPowerCount();
946
947 if (maxCount <= 1) {
948 mPowerKeyHandled = true;
949 } else {
950 mBeganFromNonInteractive = true;
951 }
Jeff Brown13f00f02014-10-31 14:45:50 -0700952 }
953 }
Jeff Brown4d396052010-10-29 21:50:21 -0700954 }
955 }
956
Jeff Brown13f00f02014-10-31 14:45:50 -0700957 private void interceptPowerKeyUp(KeyEvent event, boolean interactive, boolean canceled) {
958 final boolean handled = canceled || mPowerKeyHandled;
959 mScreenshotChordPowerKeyTriggered = false;
960 cancelPendingScreenshotChordAction();
961 cancelPendingPowerKeyAction();
962
963 if (!handled) {
964 // Figure out how to handle the key now that it has been released.
965 mPowerKeyPressCounter += 1;
966
967 final int maxCount = getMaxMultiPressPowerCount();
968 final long eventTime = event.getDownTime();
969 if (mPowerKeyPressCounter < maxCount) {
970 // This could be a multi-press. Wait a little bit longer to confirm.
971 // Continue holding the wake lock.
972 Message msg = mHandler.obtainMessage(MSG_POWER_DELAYED_PRESS,
973 interactive ? 1 : 0, mPowerKeyPressCounter, eventTime);
974 msg.setAsynchronous(true);
975 mHandler.sendMessageDelayed(msg, ViewConfiguration.getDoubleTapTimeout());
976 return;
977 }
978
979 // No other actions. Handle it immediately.
980 powerPress(eventTime, interactive, mPowerKeyPressCounter);
Jeff Brown4d396052010-10-29 21:50:21 -0700981 }
Jeff Brown13f00f02014-10-31 14:45:50 -0700982
983 // Done. Reset our state.
984 finishPowerKeyPress();
985 }
986
987 private void finishPowerKeyPress() {
Bryce Leed9268e32014-11-17 17:40:59 -0800988 mBeganFromNonInteractive = false;
Jeff Brown13f00f02014-10-31 14:45:50 -0700989 mPowerKeyPressCounter = 0;
990 if (mPowerKeyWakeLock.isHeld()) {
991 mPowerKeyWakeLock.release();
992 }
Jeff Brownd5bb82d2011-10-12 13:57:59 -0700993 }
994
995 private void cancelPendingPowerKeyAction() {
996 if (!mPowerKeyHandled) {
Jeff Brown13f00f02014-10-31 14:45:50 -0700997 mPowerKeyHandled = true;
998 mHandler.removeMessages(MSG_POWER_LONG_PRESS);
Jeff Brownd5bb82d2011-10-12 13:57:59 -0700999 }
Jeff Brown13f00f02014-10-31 14:45:50 -07001000 }
1001
1002 private void powerPress(long eventTime, boolean interactive, int count) {
1003 if (mScreenOnEarly && !mScreenOnFully) {
1004 Slog.i(TAG, "Suppressed redundant power key press while "
1005 + "already in the process of turning the screen on.");
1006 return;
Jeff Brownff204712011-10-25 21:27:54 -07001007 }
Jeff Brown13f00f02014-10-31 14:45:50 -07001008
1009 if (count == 2) {
1010 powerMultiPressAction(eventTime, interactive, mDoublePressOnPowerBehavior);
1011 } else if (count == 3) {
1012 powerMultiPressAction(eventTime, interactive, mTriplePressOnPowerBehavior);
Bryce Leed9268e32014-11-17 17:40:59 -08001013 } else if (interactive && !mBeganFromNonInteractive) {
Jeff Brown13f00f02014-10-31 14:45:50 -07001014 switch (mShortPressOnPowerBehavior) {
1015 case SHORT_PRESS_POWER_NOTHING:
1016 break;
1017 case SHORT_PRESS_POWER_GO_TO_SLEEP:
1018 mPowerManager.goToSleep(eventTime,
1019 PowerManager.GO_TO_SLEEP_REASON_POWER_BUTTON, 0);
1020 break;
1021 case SHORT_PRESS_POWER_REALLY_GO_TO_SLEEP:
1022 mPowerManager.goToSleep(eventTime,
1023 PowerManager.GO_TO_SLEEP_REASON_POWER_BUTTON,
1024 PowerManager.GO_TO_SLEEP_FLAG_NO_DOZE);
1025 break;
1026 case SHORT_PRESS_POWER_REALLY_GO_TO_SLEEP_AND_GO_HOME:
1027 mPowerManager.goToSleep(eventTime,
1028 PowerManager.GO_TO_SLEEP_REASON_POWER_BUTTON,
1029 PowerManager.GO_TO_SLEEP_FLAG_NO_DOZE);
1030 launchHomeFromHotKey();
1031 break;
Bryce Lee01b0c5f2015-02-05 18:24:04 -08001032 case SHORT_PRESS_POWER_GO_HOME:
Bryce Lee662ed802015-04-10 20:11:39 +00001033 launchHomeFromHotKey(true /* awakenFromDreams */, false /*respectKeyguard*/);
Bryce Lee01b0c5f2015-02-05 18:24:04 -08001034 break;
Jeff Brown13f00f02014-10-31 14:45:50 -07001035 }
1036 }
1037 }
1038
1039 private void powerMultiPressAction(long eventTime, boolean interactive, int behavior) {
1040 switch (behavior) {
1041 case MULTI_PRESS_POWER_NOTHING:
1042 break;
1043 case MULTI_PRESS_POWER_THEATER_MODE:
Bryce Lee3ae447e2015-06-30 12:31:41 -07001044 if (!isUserSetupComplete()) {
1045 Slog.i(TAG, "Ignoring toggling theater mode - device not setup.");
1046 break;
1047 }
1048
Jeff Brown13f00f02014-10-31 14:45:50 -07001049 if (isTheaterModeEnabled()) {
1050 Slog.i(TAG, "Toggling theater mode off.");
1051 Settings.Global.putInt(mContext.getContentResolver(),
1052 Settings.Global.THEATER_MODE_ON, 0);
1053 if (!interactive) {
1054 wakeUpFromPowerKey(eventTime);
1055 }
1056 } else {
1057 Slog.i(TAG, "Toggling theater mode on.");
1058 Settings.Global.putInt(mContext.getContentResolver(),
1059 Settings.Global.THEATER_MODE_ON, 1);
Bryce Lee55e846d2014-11-04 12:43:44 -08001060
1061 if (mGoToSleepOnButtonPressTheaterMode && interactive) {
Jeff Brown13f00f02014-10-31 14:45:50 -07001062 mPowerManager.goToSleep(eventTime,
1063 PowerManager.GO_TO_SLEEP_REASON_POWER_BUTTON, 0);
1064 }
1065 }
1066 break;
1067 case MULTI_PRESS_POWER_BRIGHTNESS_BOOST:
Jeff Brown7b5be5e2014-11-12 18:45:31 -08001068 Slog.i(TAG, "Starting brightness boost.");
1069 if (!interactive) {
1070 wakeUpFromPowerKey(eventTime);
1071 }
Jeff Brown13f00f02014-10-31 14:45:50 -07001072 mPowerManager.boostScreenBrightness(eventTime);
1073 break;
1074 }
1075 }
1076
1077 private int getMaxMultiPressPowerCount() {
1078 if (mTriplePressOnPowerBehavior != MULTI_PRESS_POWER_NOTHING) {
1079 return 3;
1080 }
1081 if (mDoublePressOnPowerBehavior != MULTI_PRESS_POWER_NOTHING) {
1082 return 2;
1083 }
1084 return 1;
1085 }
1086
1087 private void powerLongPress() {
1088 final int behavior = getResolvedLongPressOnPowerBehavior();
1089 switch (behavior) {
1090 case LONG_PRESS_POWER_NOTHING:
1091 break;
1092 case LONG_PRESS_POWER_GLOBAL_ACTIONS:
1093 mPowerKeyHandled = true;
1094 if (!performHapticFeedbackLw(null, HapticFeedbackConstants.LONG_PRESS, false)) {
1095 performAuditoryFeedbackForAccessibilityIfNeed();
1096 }
1097 showGlobalActionsInternal();
1098 break;
1099 case LONG_PRESS_POWER_SHUT_OFF:
1100 case LONG_PRESS_POWER_SHUT_OFF_NO_CONFIRM:
1101 mPowerKeyHandled = true;
1102 performHapticFeedbackLw(null, HapticFeedbackConstants.LONG_PRESS, false);
1103 sendCloseSystemWindows(SYSTEM_DIALOG_REASON_GLOBAL_ACTIONS);
1104 mWindowManagerFuncs.shutdown(behavior == LONG_PRESS_POWER_SHUT_OFF);
1105 break;
1106 }
1107 }
1108
Nick Vaccarob593a812015-05-15 11:23:05 -07001109 private void sleepPress(long eventTime) {
1110 if (mShortPressOnSleepBehavior == SHORT_PRESS_SLEEP_GO_TO_SLEEP_AND_GO_HOME) {
1111 launchHomeFromHotKey(false /* awakenDreams */, true /*respectKeyguard*/);
1112 }
1113 }
1114
1115 private void sleepRelease(long eventTime) {
Filip Gruszczynskia483a1d2015-03-17 19:06:58 +00001116 switch (mShortPressOnSleepBehavior) {
1117 case SHORT_PRESS_SLEEP_GO_TO_SLEEP:
Filip Gruszczynskia483a1d2015-03-17 19:06:58 +00001118 case SHORT_PRESS_SLEEP_GO_TO_SLEEP_AND_GO_HOME:
Nick Vaccarob593a812015-05-15 11:23:05 -07001119 Slog.i(TAG, "sleepRelease() calling goToSleep(GO_TO_SLEEP_REASON_SLEEP_BUTTON)");
1120 mPowerManager.goToSleep(eventTime,
1121 PowerManager.GO_TO_SLEEP_REASON_SLEEP_BUTTON, 0);
Filip Gruszczynskia483a1d2015-03-17 19:06:58 +00001122 break;
1123 }
1124 }
1125
Jeff Brown13f00f02014-10-31 14:45:50 -07001126 private int getResolvedLongPressOnPowerBehavior() {
1127 if (FactoryTest.isLongPressOnPowerOffEnabled()) {
1128 return LONG_PRESS_POWER_SHUT_OFF_NO_CONFIRM;
1129 }
1130 return mLongPressOnPowerBehavior;
1131 }
1132
1133 private boolean hasLongPressOnPowerBehavior() {
1134 return getResolvedLongPressOnPowerBehavior() != LONG_PRESS_POWER_NOTHING;
Jeff Brownd5bb82d2011-10-12 13:57:59 -07001135 }
1136
1137 private void interceptScreenshotChord() {
Christopher Tatee90585f2012-03-05 18:56:25 -08001138 if (mScreenshotChordEnabled
Jeff Brown13f00f02014-10-31 14:45:50 -07001139 && mScreenshotChordVolumeDownKeyTriggered && mScreenshotChordPowerKeyTriggered
1140 && !mScreenshotChordVolumeUpKeyTriggered) {
Jeff Brownd5bb82d2011-10-12 13:57:59 -07001141 final long now = SystemClock.uptimeMillis();
Jeff Brown13f00f02014-10-31 14:45:50 -07001142 if (now <= mScreenshotChordVolumeDownKeyTime + SCREENSHOT_CHORD_DEBOUNCE_DELAY_MILLIS
1143 && now <= mScreenshotChordPowerKeyTime
1144 + SCREENSHOT_CHORD_DEBOUNCE_DELAY_MILLIS) {
1145 mScreenshotChordVolumeDownKeyConsumed = true;
Jeff Brownd5bb82d2011-10-12 13:57:59 -07001146 cancelPendingPowerKeyAction();
1147
Jeff Sharkey2991fa32012-12-05 18:06:43 -08001148 mHandler.postDelayed(mScreenshotRunnable, getScreenshotChordLongPressDelay());
Jeff Brownd5bb82d2011-10-12 13:57:59 -07001149 }
1150 }
1151 }
1152
Winson Chung1cea2f32012-10-08 20:42:01 -07001153 private long getScreenshotChordLongPressDelay() {
Jim Miller5ecd8112013-01-09 18:50:26 -08001154 if (mKeyguardDelegate.isShowing()) {
Winson Chung1cea2f32012-10-08 20:42:01 -07001155 // Double the time it takes to take a screenshot from the keyguard
1156 return (long) (KEYGUARD_SCREENSHOT_CHORD_DELAY_MULTIPLIER *
Justin Kohfeabd2c2014-05-02 10:02:44 -07001157 ViewConfiguration.get(mContext).getDeviceGlobalActionKeyTimeout());
Winson Chung1cea2f32012-10-08 20:42:01 -07001158 }
Justin Kohfeabd2c2014-05-02 10:02:44 -07001159 return ViewConfiguration.get(mContext).getDeviceGlobalActionKeyTimeout();
Winson Chung1cea2f32012-10-08 20:42:01 -07001160 }
1161
Jeff Brownd5bb82d2011-10-12 13:57:59 -07001162 private void cancelPendingScreenshotChordAction() {
Jeff Sharkey2991fa32012-12-05 18:06:43 -08001163 mHandler.removeCallbacks(mScreenshotRunnable);
Jeff Brown4d396052010-10-29 21:50:21 -07001164 }
1165
Jeff Brown13f00f02014-10-31 14:45:50 -07001166 private final Runnable mEndCallLongPress = new Runnable() {
Craig Mautnerf1b67412012-09-19 13:18:29 -07001167 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001168 public void run() {
Jeff Brown13f00f02014-10-31 14:45:50 -07001169 mEndCallKeyHandled = true;
1170 if (!performHapticFeedbackLw(null, HapticFeedbackConstants.LONG_PRESS, false)) {
1171 performAuditoryFeedbackForAccessibilityIfNeed();
Joe Onoratod208e702010-10-08 16:22:43 -04001172 }
Jeff Brown13f00f02014-10-31 14:45:50 -07001173 showGlobalActionsInternal();
Jeff Brownd5bb82d2011-10-12 13:57:59 -07001174 }
1175 };
1176
Jeff Sharkey2991fa32012-12-05 18:06:43 -08001177 private final Runnable mScreenshotRunnable = new Runnable() {
Craig Mautner0bf6ec92012-12-18 08:33:27 -08001178 @Override
Jeff Brownd5bb82d2011-10-12 13:57:59 -07001179 public void run() {
1180 takeScreenshot();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001181 }
1182 };
1183
Alan Viverettee34560b22014-07-10 14:50:06 -07001184 @Override
1185 public void showGlobalActions() {
1186 mHandler.removeMessages(MSG_DISPATCH_SHOW_GLOBAL_ACTIONS);
1187 mHandler.sendEmptyMessage(MSG_DISPATCH_SHOW_GLOBAL_ACTIONS);
1188 }
1189
1190 void showGlobalActionsInternal() {
1191 sendCloseSystemWindows(SYSTEM_DIALOG_REASON_GLOBAL_ACTIONS);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001192 if (mGlobalActions == null) {
Jeff Brown7304c342012-05-11 18:42:42 -07001193 mGlobalActions = new GlobalActions(mContext, mWindowManagerFuncs);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001194 }
Jim Millerab954542014-10-10 18:21:49 -07001195 final boolean keyguardShowing = isKeyguardShowingAndNotOccluded();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001196 mGlobalActions.showDialog(keyguardShowing, isDeviceProvisioned());
1197 if (keyguardShowing) {
1198 // since it took two seconds of long press to bring this up,
1199 // poke the wake lock so they have some time to see the dialog.
Jim Miller25190572013-02-28 17:36:24 -08001200 mPowerManager.userActivity(SystemClock.uptimeMillis(), false);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001201 }
1202 }
1203
1204 boolean isDeviceProvisioned() {
Jeff Brownbf6f6f92012-09-25 15:03:20 -07001205 return Settings.Global.getInt(
1206 mContext.getContentResolver(), Settings.Global.DEVICE_PROVISIONED, 0) != 0;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001207 }
1208
Maurice Lam99c6e072014-04-28 18:24:28 -07001209 boolean isUserSetupComplete() {
1210 return Settings.Secure.getIntForUser(mContext.getContentResolver(),
1211 Settings.Secure.USER_SETUP_COMPLETE, 0, UserHandle.USER_CURRENT) != 0;
1212 }
1213
Jeff Brown13f00f02014-10-31 14:45:50 -07001214 private void handleShortPressOnHome() {
1215 // If there's a dream running then use home to escape the dream
1216 // but don't actually go home.
1217 if (mDreamManagerInternal != null && mDreamManagerInternal.isDreaming()) {
1218 mDreamManagerInternal.stopDream(false /*immediate*/);
1219 return;
1220 }
1221
1222 // Go home!
1223 launchHomeFromHotKey();
1224 }
1225
Tim Kilbourn0e5f1102015-06-05 16:18:09 -07001226 private void handleLongPressOnHome(int deviceId) {
Joe Onorato46b0d682010-11-22 17:37:27 -08001227 if (mLongPressOnHomeBehavior != LONG_PRESS_HOME_NOTHING) {
Jeff Browncaca8812013-05-09 13:34:33 -07001228 mHomeConsumed = true;
Joe Onorato46b0d682010-11-22 17:37:27 -08001229 performHapticFeedbackLw(null, HapticFeedbackConstants.LONG_PRESS, false);
Patrick Dubroyece94522011-02-23 18:35:01 -08001230
Jeff Browncaca8812013-05-09 13:34:33 -07001231 if (mLongPressOnHomeBehavior == LONG_PRESS_HOME_RECENT_SYSTEM_UI) {
1232 toggleRecentApps();
1233 } else if (mLongPressOnHomeBehavior == LONG_PRESS_HOME_ASSIST) {
Tim Kilbourn0e5f1102015-06-05 16:18:09 -07001234 launchAssistAction(null, deviceId);
Jim Millere6ad1a82010-08-20 19:25:39 -07001235 }
1236 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001237 }
Patrick Dubroyece94522011-02-23 18:35:01 -08001238
Jeff Browncaca8812013-05-09 13:34:33 -07001239 private void handleDoubleTapOnHome() {
1240 if (mDoubleTapOnHomeBehavior == DOUBLE_TAP_HOME_RECENT_SYSTEM_UI) {
1241 mHomeConsumed = true;
1242 toggleRecentApps();
1243 }
1244 }
1245
1246 private final Runnable mHomeDoubleTapTimeoutRunnable = new Runnable() {
1247 @Override
1248 public void run() {
1249 if (mHomeDoubleTapPending) {
1250 mHomeDoubleTapPending = false;
Jeff Brown13f00f02014-10-31 14:45:50 -07001251 handleShortPressOnHome();
Jeff Browncaca8812013-05-09 13:34:33 -07001252 }
1253 }
1254 };
1255
Mark Renoufc1256912015-03-11 14:38:23 -04001256 private boolean isRoundWindow() {
Adam Powell01f280d2015-05-18 16:07:42 -07001257 return mContext.getResources().getConfiguration().isScreenRound();
Mark Renoufc1256912015-03-11 14:38:23 -04001258 }
1259
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001260 /** {@inheritDoc} */
Craig Mautner0bf6ec92012-12-18 08:33:27 -08001261 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001262 public void init(Context context, IWindowManager windowManager,
Jeff Brown96307042012-07-27 15:51:34 -07001263 WindowManagerFuncs windowManagerFuncs) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001264 mContext = context;
1265 mWindowManager = windowManager;
Dianne Hackborndf89e652011-10-06 22:35:11 -07001266 mWindowManagerFuncs = windowManagerFuncs;
Craig Mautner8a0da012014-05-31 15:13:37 -07001267 mWindowManagerInternal = LocalServices.getService(WindowManagerInternal.class);
Jeff Brown061ea992015-04-17 19:55:47 -07001268 mActivityManagerInternal = LocalServices.getService(ActivityManagerInternal.class);
Jose Lima9546b202014-07-02 17:21:51 -07001269 mDreamManagerInternal = LocalServices.getService(DreamManagerInternal.class);
Billy Laucbe540f2015-06-25 01:51:44 +01001270 mAppOpsManager = (AppOpsManager) mContext.getSystemService(Context.APP_OPS_SERVICE);
Mark Renoufc1256912015-03-11 14:38:23 -04001271
1272 // Init display burn-in protection
1273 boolean burnInProtectionEnabled = context.getResources().getBoolean(
1274 com.android.internal.R.bool.config_enableBurnInProtection);
1275 // Allow a system property to override this. Used by developer settings.
1276 boolean burnInProtectionDevMode =
1277 SystemProperties.getBoolean("persist.debug.force_burn_in", false);
1278 if (burnInProtectionEnabled || burnInProtectionDevMode) {
1279 final int minHorizontal;
1280 final int maxHorizontal;
1281 final int minVertical;
1282 final int maxVertical;
1283 final int maxRadius;
1284 if (burnInProtectionDevMode) {
1285 minHorizontal = -8;
1286 maxHorizontal = 8;
1287 minVertical = -8;
1288 maxVertical = -4;
1289 maxRadius = (isRoundWindow()) ? 6 : -1;
1290 } else {
1291 Resources resources = context.getResources();
1292 minHorizontal = resources.getInteger(
1293 com.android.internal.R.integer.config_burnInProtectionMinHorizontalOffset);
1294 maxHorizontal = resources.getInteger(
1295 com.android.internal.R.integer.config_burnInProtectionMaxHorizontalOffset);
1296 minVertical = resources.getInteger(
1297 com.android.internal.R.integer.config_burnInProtectionMinVerticalOffset);
1298 maxVertical = resources.getInteger(
1299 com.android.internal.R.integer.config_burnInProtectionMaxVerticalOffset);
1300 maxRadius = resources.getInteger(
1301 com.android.internal.R.integer.config_burnInProtectionMaxRadius);
1302 }
1303 mBurnInProtectionHelper = new BurnInProtectionHelper(
1304 context, minHorizontal, maxHorizontal, minVertical, maxVertical, maxRadius);
Filip Gruszczynskicfb31852015-02-25 21:47:12 +00001305 }
Craig Mautner8a0da012014-05-31 15:13:37 -07001306
Jeff Brown70825162012-03-28 17:27:48 -07001307 mHandler = new PolicyHandler();
Jeff Browna20dda42014-05-27 20:57:24 -07001308 mWakeGestureListener = new MyWakeGestureListener(mContext, mHandler);
Craig Mautnereee29c42013-01-17 14:44:34 -08001309 mOrientationListener = new MyOrientationListener(mContext, mHandler);
Jeff Brownc0347aa2011-09-23 17:26:09 -07001310 try {
1311 mOrientationListener.setCurrentRotation(windowManager.getRotation());
1312 } catch (RemoteException ex) { }
Christopher Tate5e08af02012-09-21 17:17:22 -07001313 mSettingsObserver = new SettingsObserver(mHandler);
1314 mSettingsObserver.observe();
Svetoslav683914b2015-01-15 14:22:26 -08001315 mShortcutManager = new ShortcutManager(context);
Daniel Sandler6396c722013-04-16 20:19:09 -04001316 mUiMode = context.getResources().getInteger(
1317 com.android.internal.R.integer.config_defaultUiModeType);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001318 mHomeIntent = new Intent(Intent.ACTION_MAIN, null);
1319 mHomeIntent.addCategory(Intent.CATEGORY_HOME);
1320 mHomeIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK
1321 | Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED);
Dianne Hackborn39c2d712009-09-22 11:41:31 -07001322 mCarDockIntent = new Intent(Intent.ACTION_MAIN, null);
1323 mCarDockIntent.addCategory(Intent.CATEGORY_CAR_DOCK);
1324 mCarDockIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK
1325 | Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED);
1326 mDeskDockIntent = new Intent(Intent.ACTION_MAIN, null);
1327 mDeskDockIntent.addCategory(Intent.CATEGORY_DESK_DOCK);
1328 mDeskDockIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK
1329 | Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED);
Jim Millere6ad1a82010-08-20 19:25:39 -07001330
Jeff Brown96307042012-07-27 15:51:34 -07001331 mPowerManager = (PowerManager)context.getSystemService(Context.POWER_SERVICE);
1332 mBroadcastWakeLock = mPowerManager.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK,
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001333 "PhoneWindowManager.mBroadcastWakeLock");
Jeff Brown13f00f02014-10-31 14:45:50 -07001334 mPowerKeyWakeLock = mPowerManager.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK,
1335 "PhoneWindowManager.mPowerKeyWakeLock");
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001336 mEnableShiftMenuBugReports = "1".equals(SystemProperties.get("ro.debuggable"));
Jeff Brownbcdfc622014-03-06 19:13:04 -08001337 mSupportAutoRotation = mContext.getResources().getBoolean(
1338 com.android.internal.R.bool.config_supportAutoRotation);
Dianne Hackborn2862fff2009-09-15 22:56:29 -07001339 mLidOpenRotation = readRotation(
Mike Lockwood2d1efbd2009-09-16 12:15:53 -04001340 com.android.internal.R.integer.config_lidOpenRotation);
1341 mCarDockRotation = readRotation(
1342 com.android.internal.R.integer.config_carDockRotation);
1343 mDeskDockRotation = readRotation(
1344 com.android.internal.R.integer.config_deskDockRotation);
Jeff Brownc82c89ed2013-04-17 17:18:15 -07001345 mUndockedHdmiRotation = readRotation(
1346 com.android.internal.R.integer.config_undockedHdmiRotation);
Mike Lockwoode9867d22009-09-20 01:59:02 -04001347 mCarDockEnablesAccelerometer = mContext.getResources().getBoolean(
1348 com.android.internal.R.bool.config_carDockEnablesAccelerometer);
1349 mDeskDockEnablesAccelerometer = mContext.getResources().getBoolean(
1350 com.android.internal.R.bool.config_deskDockEnablesAccelerometer);
Dianne Hackborn2862fff2009-09-15 22:56:29 -07001351 mLidKeyboardAccessibility = mContext.getResources().getInteger(
1352 com.android.internal.R.integer.config_lidKeyboardAccessibility);
1353 mLidNavigationAccessibility = mContext.getResources().getInteger(
1354 com.android.internal.R.integer.config_lidNavigationAccessibility);
Jeff Brownc458ce92012-04-30 14:58:40 -07001355 mLidControlsSleep = mContext.getResources().getBoolean(
1356 com.android.internal.R.bool.config_lidControlsSleep);
Daniel Sandlerdd73ee42013-10-11 22:19:59 -04001357 mTranslucentDecorEnabled = mContext.getResources().getBoolean(
1358 com.android.internal.R.bool.config_enableTranslucentDecor);
Bryce Lee584a4452014-10-21 15:55:55 -07001359
1360 mAllowTheaterModeWakeFromKey = mContext.getResources().getBoolean(
1361 com.android.internal.R.bool.config_allowTheaterModeWakeFromKey);
1362 mAllowTheaterModeWakeFromPowerKey = mAllowTheaterModeWakeFromKey
1363 || mContext.getResources().getBoolean(
1364 com.android.internal.R.bool.config_allowTheaterModeWakeFromPowerKey);
1365 mAllowTheaterModeWakeFromMotion = mContext.getResources().getBoolean(
1366 com.android.internal.R.bool.config_allowTheaterModeWakeFromMotion);
Bryce Lee812d7022014-11-10 13:33:28 -08001367 mAllowTheaterModeWakeFromMotionWhenNotDreaming = mContext.getResources().getBoolean(
1368 com.android.internal.R.bool.config_allowTheaterModeWakeFromMotionWhenNotDreaming);
Bryce Lee584a4452014-10-21 15:55:55 -07001369 mAllowTheaterModeWakeFromCameraLens = mContext.getResources().getBoolean(
1370 com.android.internal.R.bool.config_allowTheaterModeWakeFromCameraLens);
1371 mAllowTheaterModeWakeFromLidSwitch = mContext.getResources().getBoolean(
1372 com.android.internal.R.bool.config_allowTheaterModeWakeFromLidSwitch);
1373 mAllowTheaterModeWakeFromWakeGesture = mContext.getResources().getBoolean(
1374 com.android.internal.R.bool.config_allowTheaterModeWakeFromGesture);
1375
Bryce Lee55e846d2014-11-04 12:43:44 -08001376 mGoToSleepOnButtonPressTheaterMode = mContext.getResources().getBoolean(
1377 com.android.internal.R.bool.config_goToSleepOnButtonPressTheaterMode);
1378
Bryce Leed3b28402015-03-09 15:49:13 +00001379 mSupportLongPressPowerWhenNonInteractive = mContext.getResources().getBoolean(
1380 com.android.internal.R.bool.config_supportLongPressPowerWhenNonInteractive);
1381
Jeff Brown13f00f02014-10-31 14:45:50 -07001382 mShortPressOnPowerBehavior = mContext.getResources().getInteger(
1383 com.android.internal.R.integer.config_shortPressOnPowerBehavior);
1384 mLongPressOnPowerBehavior = mContext.getResources().getInteger(
1385 com.android.internal.R.integer.config_longPressOnPowerBehavior);
1386 mDoublePressOnPowerBehavior = mContext.getResources().getInteger(
1387 com.android.internal.R.integer.config_doublePressOnPowerBehavior);
1388 mTriplePressOnPowerBehavior = mContext.getResources().getInteger(
1389 com.android.internal.R.integer.config_triplePressOnPowerBehavior);
Filip Gruszczynskia483a1d2015-03-17 19:06:58 +00001390 mShortPressOnSleepBehavior = mContext.getResources().getInteger(
1391 com.android.internal.R.integer.config_shortPressOnSleepBehavior);
Jeff Brown13f00f02014-10-31 14:45:50 -07001392
John Spurlock61560172015-02-06 19:46:04 -05001393 mUseTvRouting = AudioSystem.getPlatformType(mContext) == AudioSystem.PLATFORM_TELEVISION;
RoboErik001c59c2015-01-26 15:53:51 -08001394
Jeff Brownf71343d2013-05-31 17:59:11 -07001395 readConfigurationDependentBehaviors();
Jeff Browncaca8812013-05-09 13:34:33 -07001396
Svetoslav8e3feb12014-02-24 13:46:47 -08001397 mAccessibilityManager = (AccessibilityManager) context.getSystemService(
1398 Context.ACCESSIBILITY_SERVICE);
1399
Mike Lockwood1753f7f2009-08-24 14:49:07 -07001400 // register for dock events
Dianne Hackborn78968392010-03-04 20:47:56 -08001401 IntentFilter filter = new IntentFilter();
1402 filter.addAction(UiModeManager.ACTION_ENTER_CAR_MODE);
1403 filter.addAction(UiModeManager.ACTION_EXIT_CAR_MODE);
1404 filter.addAction(UiModeManager.ACTION_ENTER_DESK_MODE);
1405 filter.addAction(UiModeManager.ACTION_EXIT_DESK_MODE);
Dianne Hackborn867ab6472010-04-29 13:28:56 -07001406 filter.addAction(Intent.ACTION_DOCK_EVENT);
1407 Intent intent = context.registerReceiver(mDockReceiver, filter);
1408 if (intent != null) {
1409 // Retrieve current sticky dock event broadcast.
1410 mDockMode = intent.getIntExtra(Intent.EXTRA_DOCK_STATE,
1411 Intent.EXTRA_DOCK_STATE_UNDOCKED);
1412 }
Daniel Sandler7e37df52011-11-16 22:08:23 -08001413
Jeff Brown6aaf2952012-10-05 16:01:08 -07001414 // register for dream-related broadcasts
1415 filter = new IntentFilter();
1416 filter.addAction(Intent.ACTION_DREAMING_STARTED);
1417 filter.addAction(Intent.ACTION_DREAMING_STOPPED);
1418 context.registerReceiver(mDreamReceiver, filter);
1419
Christopher Tate5e08af02012-09-21 17:17:22 -07001420 // register for multiuser-relevant broadcasts
1421 filter = new IntentFilter(Intent.ACTION_USER_SWITCHED);
1422 context.registerReceiver(mMultiuserReceiver, filter);
1423
John Spurlock57306e62013-04-22 09:48:49 -04001424 // monitor for system gestures
Craig Mautner037aa8d2013-06-07 10:35:44 -07001425 mSystemGestures = new SystemGesturesPointerEventListener(context,
1426 new SystemGesturesPointerEventListener.Callbacks() {
John Spurlock57306e62013-04-22 09:48:49 -04001427 @Override
1428 public void onSwipeFromTop() {
John Spurlock04db1762013-05-13 12:46:41 -04001429 if (mStatusBar != null) {
John Spurlocke1f366f2013-08-05 12:22:40 -04001430 requestTransientBars(mStatusBar);
John Spurlock04db1762013-05-13 12:46:41 -04001431 }
John Spurlockad3e6cb2013-04-30 08:47:43 -04001432 }
1433 @Override
1434 public void onSwipeFromBottom() {
John Spurlock04db1762013-05-13 12:46:41 -04001435 if (mNavigationBar != null && mNavigationBarOnBottom) {
John Spurlocke1f366f2013-08-05 12:22:40 -04001436 requestTransientBars(mNavigationBar);
John Spurlockad3e6cb2013-04-30 08:47:43 -04001437 }
1438 }
1439 @Override
1440 public void onSwipeFromRight() {
John Spurlock04db1762013-05-13 12:46:41 -04001441 if (mNavigationBar != null && !mNavigationBarOnBottom) {
John Spurlocke1f366f2013-08-05 12:22:40 -04001442 requestTransientBars(mNavigationBar);
John Spurlockad3e6cb2013-04-30 08:47:43 -04001443 }
1444 }
1445 @Override
1446 public void onDebug() {
John Spurlockd67ec252013-09-05 11:31:54 -04001447 // no-op
John Spurlockad3e6cb2013-04-30 08:47:43 -04001448 }
Adrian Roos3595be42015-03-05 16:31:15 +01001449 @Override
1450 public void onDown() {
1451 mOrientationListener.onTouchStart();
1452 }
1453 @Override
1454 public void onUpOrCancel() {
1455 mOrientationListener.onTouchEnd();
1456 }
John Spurlockad3e6cb2013-04-30 08:47:43 -04001457 });
John Spurlockf1a36642013-10-12 17:50:42 -04001458 mImmersiveModeConfirmation = new ImmersiveModeConfirmation(mContext);
Craig Mautner037aa8d2013-06-07 10:35:44 -07001459 mWindowManagerFuncs.registerPointerEventListener(mSystemGestures);
John Spurlock32beb2c2013-03-11 10:16:47 -04001460
Jeff Brownc2346132012-04-13 01:55:38 -07001461 mVibrator = (Vibrator)context.getSystemService(Context.VIBRATOR_SERVICE);
Dianne Hackbornb1a79802009-09-29 15:18:31 -07001462 mLongPressVibePattern = getLongIntArray(mContext.getResources(),
1463 com.android.internal.R.array.config_longPressVibePattern);
1464 mVirtualKeyVibePattern = getLongIntArray(mContext.getResources(),
1465 com.android.internal.R.array.config_virtualKeyVibePattern);
Amith Yamasanic33cb712010-02-10 15:21:49 -08001466 mKeyboardTapVibePattern = getLongIntArray(mContext.getResources(),
1467 com.android.internal.R.array.config_keyboardTapVibePattern);
Fabrice Di Meglioeeff63a2013-08-05 12:07:24 -07001468 mClockTickVibePattern = getLongIntArray(mContext.getResources(),
1469 com.android.internal.R.array.config_clockTickVibePattern);
Fabrice Di Megliobd9152f2013-10-01 11:21:31 -07001470 mCalendarDateVibePattern = getLongIntArray(mContext.getResources(),
1471 com.android.internal.R.array.config_calendarDateVibePattern);
Dianne Hackbornb1a79802009-09-29 15:18:31 -07001472 mSafeModeDisabledVibePattern = getLongIntArray(mContext.getResources(),
1473 com.android.internal.R.array.config_safeModeDisabledVibePattern);
1474 mSafeModeEnabledVibePattern = getLongIntArray(mContext.getResources(),
1475 com.android.internal.R.array.config_safeModeEnabledVibePattern);
Mady Mellore8608912015-06-05 09:02:55 -07001476 mContextClickVibePattern = getLongIntArray(mContext.getResources(),
1477 com.android.internal.R.array.config_contextClickVibePattern);
Daniel Sandler40427442010-07-16 11:44:52 -04001478
Christopher Tatee90585f2012-03-05 18:56:25 -08001479 mScreenshotChordEnabled = mContext.getResources().getBoolean(
1480 com.android.internal.R.bool.config_enableScreenshotChord);
1481
Justin Kohd378ad72013-04-01 12:18:26 -07001482 mGlobalKeyManager = new GlobalKeyManager(mContext);
1483
Joe Onoratoea495d42011-04-06 11:41:11 -07001484 // Controls rotation and the like.
1485 initializeHdmiState();
Dianne Hackborn40011092011-09-22 13:37:48 -07001486
1487 // Match current screen state.
Craig Mautnera631d492014-08-05 15:16:01 -07001488 if (!mPowerManager.isInteractive()) {
Jeff Brown416c49c2015-05-26 19:50:18 -07001489 startedGoingToSleep(WindowManagerPolicy.OFF_BECAUSE_OF_USER);
1490 finishedGoingToSleep(WindowManagerPolicy.OFF_BECAUSE_OF_USER);
Dianne Hackborn40011092011-09-22 13:37:48 -07001491 }
Jorim Jaggi24bec7c2015-02-04 12:40:14 +01001492
1493 mWindowManagerInternal.registerAppTransitionListener(
1494 mStatusBarController.getAppTransitionListener());
Mike Lockwood1753f7f2009-08-24 14:49:07 -07001495 }
1496
Jeff Brownf71343d2013-05-31 17:59:11 -07001497 /**
1498 * Read values from config.xml that may be overridden depending on
1499 * the configuration of the device.
1500 * eg. Disable long press on home goes to recents on sw600dp.
1501 */
1502 private void readConfigurationDependentBehaviors() {
1503 mLongPressOnHomeBehavior = mContext.getResources().getInteger(
1504 com.android.internal.R.integer.config_longPressOnHomeBehavior);
1505 if (mLongPressOnHomeBehavior < LONG_PRESS_HOME_NOTHING ||
1506 mLongPressOnHomeBehavior > LONG_PRESS_HOME_ASSIST) {
1507 mLongPressOnHomeBehavior = LONG_PRESS_HOME_NOTHING;
1508 }
1509
1510 mDoubleTapOnHomeBehavior = mContext.getResources().getInteger(
1511 com.android.internal.R.integer.config_doubleTapOnHomeBehavior);
1512 if (mDoubleTapOnHomeBehavior < DOUBLE_TAP_HOME_NOTHING ||
1513 mDoubleTapOnHomeBehavior > DOUBLE_TAP_HOME_RECENT_SYSTEM_UI) {
1514 mDoubleTapOnHomeBehavior = LONG_PRESS_HOME_NOTHING;
1515 }
1516 }
1517
Craig Mautner0bf6ec92012-12-18 08:33:27 -08001518 @Override
Dianne Hackborndde331c2012-08-03 14:01:57 -07001519 public void setInitialDisplaySize(Display display, int width, int height, int density) {
Jeff Brownef981a42013-08-07 14:13:37 -07001520 // This method might be called before the policy has been fully initialized
1521 // or for other displays we don't care about.
1522 if (mContext == null || display.getDisplayId() != Display.DEFAULT_DISPLAY) {
1523 return;
Dianne Hackbornc652de82013-02-15 16:32:56 -08001524 }
Dianne Hackbornf87d1962012-04-04 12:48:24 -07001525 mDisplay = display;
1526
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001527 final Resources res = mContext.getResources();
Dianne Hackbornf87d1962012-04-04 12:48:24 -07001528 int shortSize, longSize;
Dianne Hackborn9d132642011-04-21 17:26:39 -07001529 if (width > height) {
Dianne Hackborn81e56d52011-05-26 00:55:58 -07001530 shortSize = height;
Dianne Hackbornf87d1962012-04-04 12:48:24 -07001531 longSize = width;
Dianne Hackborn9d132642011-04-21 17:26:39 -07001532 mLandscapeRotation = Surface.ROTATION_0;
1533 mSeascapeRotation = Surface.ROTATION_180;
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001534 if (res.getBoolean(com.android.internal.R.bool.config_reverseDefaultRotation)) {
Dianne Hackborn9d132642011-04-21 17:26:39 -07001535 mPortraitRotation = Surface.ROTATION_90;
1536 mUpsideDownRotation = Surface.ROTATION_270;
1537 } else {
1538 mPortraitRotation = Surface.ROTATION_270;
1539 mUpsideDownRotation = Surface.ROTATION_90;
1540 }
1541 } else {
Dianne Hackborn81e56d52011-05-26 00:55:58 -07001542 shortSize = width;
Dianne Hackbornf87d1962012-04-04 12:48:24 -07001543 longSize = height;
Dianne Hackborn9d132642011-04-21 17:26:39 -07001544 mPortraitRotation = Surface.ROTATION_0;
1545 mUpsideDownRotation = Surface.ROTATION_180;
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001546 if (res.getBoolean(com.android.internal.R.bool.config_reverseDefaultRotation)) {
Dianne Hackborn9d132642011-04-21 17:26:39 -07001547 mLandscapeRotation = Surface.ROTATION_270;
1548 mSeascapeRotation = Surface.ROTATION_90;
1549 } else {
1550 mLandscapeRotation = Surface.ROTATION_90;
1551 mSeascapeRotation = Surface.ROTATION_270;
1552 }
1553 }
Dianne Hackborn81e56d52011-05-26 00:55:58 -07001554
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001555 mStatusBarHeight =
1556 res.getDimensionPixelSize(com.android.internal.R.dimen.status_bar_height);
Dianne Hackbornf87d1962012-04-04 12:48:24 -07001557
Daniel Sandler9f65c4c2012-04-26 01:35:35 -04001558 // Height of the navigation bar when presented horizontally at bottom
1559 mNavigationBarHeightForRotation[mPortraitRotation] =
1560 mNavigationBarHeightForRotation[mUpsideDownRotation] =
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001561 res.getDimensionPixelSize(com.android.internal.R.dimen.navigation_bar_height);
Daniel Sandler9f65c4c2012-04-26 01:35:35 -04001562 mNavigationBarHeightForRotation[mLandscapeRotation] =
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001563 mNavigationBarHeightForRotation[mSeascapeRotation] = res.getDimensionPixelSize(
1564 com.android.internal.R.dimen.navigation_bar_height_landscape);
Daniel Sandler9f65c4c2012-04-26 01:35:35 -04001565
1566 // Width of the navigation bar when presented vertically along one side
1567 mNavigationBarWidthForRotation[mPortraitRotation] =
1568 mNavigationBarWidthForRotation[mUpsideDownRotation] =
1569 mNavigationBarWidthForRotation[mLandscapeRotation] =
1570 mNavigationBarWidthForRotation[mSeascapeRotation] =
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001571 res.getDimensionPixelSize(com.android.internal.R.dimen.navigation_bar_width);
Daniel Sandler4a066c52012-04-20 14:49:13 -04001572
1573 // SystemUI (status bar) layout policy
Dianne Hackborndde331c2012-08-03 14:01:57 -07001574 int shortSizeDp = shortSize * DisplayMetrics.DENSITY_DEFAULT / density;
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001575 int longSizeDp = longSize * DisplayMetrics.DENSITY_DEFAULT / density;
Daniel Sandler4a066c52012-04-20 14:49:13 -04001576
Devin Kimd7b12b42014-05-05 14:34:58 -07001577 // Allow the navigation bar to move on non-square small devices (phones).
1578 mNavigationBarCanMove = width != height && shortSizeDp < 600;
Daniel Sandler36412a72011-08-04 09:35:13 -04001579
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001580 mHasNavigationBar = res.getBoolean(com.android.internal.R.bool.config_showNavigationBar);
John Spurlock80f00c12013-06-13 11:10:51 -04001581 // Allow a system property to override this. Used by the emulator.
1582 // See also hasNavigationBar().
1583 String navBarOverride = SystemProperties.get("qemu.hw.mainkeys");
1584 if ("1".equals(navBarOverride)) {
Dianne Hackbornf87d1962012-04-04 12:48:24 -07001585 mHasNavigationBar = false;
John Spurlock80f00c12013-06-13 11:10:51 -04001586 } else if ("0".equals(navBarOverride)) {
1587 mHasNavigationBar = true;
Daniel Sandler0c4ccff2011-10-19 16:39:14 -04001588 }
1589
Jeff Brown27f1d672012-10-17 18:32:34 -07001590 // For demo purposes, allow the rotation of the HDMI display to be controlled.
1591 // By default, HDMI locks rotation to landscape.
Erik Gilling9a41ef82011-09-26 19:21:03 -07001592 if ("portrait".equals(SystemProperties.get("persist.demo.hdmirotation"))) {
Jeff Brownc82c89ed2013-04-17 17:18:15 -07001593 mDemoHdmiRotation = mPortraitRotation;
Erik Gilling9a41ef82011-09-26 19:21:03 -07001594 } else {
Jeff Brownc82c89ed2013-04-17 17:18:15 -07001595 mDemoHdmiRotation = mLandscapeRotation;
Erik Gilling9a41ef82011-09-26 19:21:03 -07001596 }
Jeff Brownc82c89ed2013-04-17 17:18:15 -07001597 mDemoHdmiRotationLock = SystemProperties.getBoolean("persist.demo.hdmirotationlock", false);
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001598
Chong Zhangae6119ff2014-11-11 18:54:39 -08001599 // For demo purposes, allow the rotation of the remote display to be controlled.
1600 // By default, remote display locks rotation to landscape.
1601 if ("portrait".equals(SystemProperties.get("persist.demo.remoterotation"))) {
1602 mDemoRotation = mPortraitRotation;
1603 } else {
1604 mDemoRotation = mLandscapeRotation;
1605 }
1606 mDemoRotationLock = SystemProperties.getBoolean(
1607 "persist.demo.rotationlock", false);
1608
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001609 // Only force the default orientation if the screen is xlarge, at least 960dp x 720dp, per
1610 // http://developer.android.com/guide/practices/screens_support.html#range
1611 mForceDefaultOrientation = longSizeDp >= 960 && shortSizeDp >= 720 &&
1612 res.getBoolean(com.android.internal.R.bool.config_forceDefaultOrientation) &&
1613 // For debug purposes the next line turns this feature off with:
1614 // $ adb shell setprop config.override_forced_orient true
1615 // $ adb shell wm size reset
1616 !"true".equals(SystemProperties.get("config.override_forced_orient"));
1617 }
1618
Alan Viverette5a0f4ec2013-10-07 15:10:29 -07001619 /**
1620 * @return whether the navigation bar can be hidden, e.g. the device has a
1621 * navigation bar and touch exploration is not enabled
1622 */
1623 private boolean canHideNavigationBar() {
Svetoslav8e3feb12014-02-24 13:46:47 -08001624 return mHasNavigationBar
1625 && !mAccessibilityManager.isTouchExplorationEnabled();
Alan Viverette5a0f4ec2013-10-07 15:10:29 -07001626 }
1627
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001628 @Override
1629 public boolean isDefaultOrientationForced() {
1630 return mForceDefaultOrientation;
Dianne Hackborn9d132642011-04-21 17:26:39 -07001631 }
1632
Dianne Hackbornc652de82013-02-15 16:32:56 -08001633 @Override
1634 public void setDisplayOverscan(Display display, int left, int top, int right, int bottom) {
1635 if (display.getDisplayId() == Display.DEFAULT_DISPLAY) {
1636 mOverscanLeft = left;
1637 mOverscanTop = top;
1638 mOverscanRight = right;
1639 mOverscanBottom = bottom;
1640 }
1641 }
1642
Dianne Hackbornc777e072010-02-12 13:07:59 -08001643 public void updateSettings() {
1644 ContentResolver resolver = mContext.getContentResolver();
1645 boolean updateRotation = false;
Dianne Hackbornc777e072010-02-12 13:07:59 -08001646 synchronized (mLock) {
Christopher Tate5e08af02012-09-21 17:17:22 -07001647 mEndcallBehavior = Settings.System.getIntForUser(resolver,
David Brownbaf8d092010-03-08 21:52:59 -08001648 Settings.System.END_BUTTON_BEHAVIOR,
Christopher Tate5e08af02012-09-21 17:17:22 -07001649 Settings.System.END_BUTTON_BEHAVIOR_DEFAULT,
1650 UserHandle.USER_CURRENT);
1651 mIncallPowerBehavior = Settings.Secure.getIntForUser(resolver,
David Brownbaf8d092010-03-08 21:52:59 -08001652 Settings.Secure.INCALL_POWER_BUTTON_BEHAVIOR,
Christopher Tate5e08af02012-09-21 17:17:22 -07001653 Settings.Secure.INCALL_POWER_BUTTON_BEHAVIOR_DEFAULT,
1654 UserHandle.USER_CURRENT);
Daniel Sandlerb73617d2010-08-17 00:41:00 -04001655
Jeff Browna20dda42014-05-27 20:57:24 -07001656 // Configure wake gesture.
1657 boolean wakeGestureEnabledSetting = Settings.Secure.getIntForUser(resolver,
1658 Settings.Secure.WAKE_GESTURE_ENABLED, 0,
1659 UserHandle.USER_CURRENT) != 0;
1660 if (mWakeGestureEnabledSetting != wakeGestureEnabledSetting) {
1661 mWakeGestureEnabledSetting = wakeGestureEnabledSetting;
1662 updateWakeGestureListenerLp();
1663 }
1664
Jeff Brown207673cd2012-06-05 17:47:11 -07001665 // Configure rotation lock.
Christopher Tate5e08af02012-09-21 17:17:22 -07001666 int userRotation = Settings.System.getIntForUser(resolver,
1667 Settings.System.USER_ROTATION, Surface.ROTATION_0,
1668 UserHandle.USER_CURRENT);
Jeff Brown207673cd2012-06-05 17:47:11 -07001669 if (mUserRotation != userRotation) {
1670 mUserRotation = userRotation;
1671 updateRotation = true;
1672 }
Christopher Tate5e08af02012-09-21 17:17:22 -07001673 int userRotationMode = Settings.System.getIntForUser(resolver,
1674 Settings.System.ACCELEROMETER_ROTATION, 0, UserHandle.USER_CURRENT) != 0 ?
Jeff Brown207673cd2012-06-05 17:47:11 -07001675 WindowManagerPolicy.USER_ROTATION_FREE :
1676 WindowManagerPolicy.USER_ROTATION_LOCKED;
1677 if (mUserRotationMode != userRotationMode) {
1678 mUserRotationMode = userRotationMode;
1679 updateRotation = true;
Dianne Hackbornc777e072010-02-12 13:07:59 -08001680 updateOrientationListenerLp();
1681 }
Daniel Sandlerb73617d2010-08-17 00:41:00 -04001682
Dianne Hackbornc777e072010-02-12 13:07:59 -08001683 if (mSystemReady) {
Christopher Tate5e08af02012-09-21 17:17:22 -07001684 int pointerLocation = Settings.System.getIntForUser(resolver,
1685 Settings.System.POINTER_LOCATION, 0, UserHandle.USER_CURRENT);
Dianne Hackbornc777e072010-02-12 13:07:59 -08001686 if (mPointerLocationMode != pointerLocation) {
1687 mPointerLocationMode = pointerLocation;
Jeff Brown70825162012-03-28 17:27:48 -07001688 mHandler.sendEmptyMessage(pointerLocation != 0 ?
1689 MSG_ENABLE_POINTER_LOCATION : MSG_DISABLE_POINTER_LOCATION);
Dianne Hackbornc777e072010-02-12 13:07:59 -08001690 }
1691 }
1692 // use screen off timeout setting as the timeout for the lockscreen
Christopher Tate5e08af02012-09-21 17:17:22 -07001693 mLockScreenTimeout = Settings.System.getIntForUser(resolver,
1694 Settings.System.SCREEN_OFF_TIMEOUT, 0, UserHandle.USER_CURRENT);
1695 String imId = Settings.Secure.getStringForUser(resolver,
1696 Settings.Secure.DEFAULT_INPUT_METHOD, UserHandle.USER_CURRENT);
Dianne Hackbornc777e072010-02-12 13:07:59 -08001697 boolean hasSoftInput = imId != null && imId.length() > 0;
1698 if (mHasSoftInput != hasSoftInput) {
1699 mHasSoftInput = hasSoftInput;
1700 updateRotation = true;
1701 }
John Spurlockf1a36642013-10-12 17:50:42 -04001702 if (mImmersiveModeConfirmation != null) {
John Spurlock4355a532014-02-19 09:49:25 -05001703 mImmersiveModeConfirmation.loadSetting(mCurrentUserId);
John Spurlockd67ec252013-09-05 11:31:54 -04001704 }
tiger_huangcc6366d2015-06-29 17:17:30 +08001705 }
1706 synchronized (mWindowManagerFuncs.getWindowManagerLock()) {
John Spurlockc6d1c602014-01-17 15:22:06 -05001707 PolicyControl.reloadFromSetting(mContext);
Dianne Hackbornc777e072010-02-12 13:07:59 -08001708 }
1709 if (updateRotation) {
Jeff Brown01a98dd2011-09-20 15:08:29 -07001710 updateRotation(true);
Dianne Hackbornc777e072010-02-12 13:07:59 -08001711 }
Jeff Brown70825162012-03-28 17:27:48 -07001712 }
1713
Jeff Browna20dda42014-05-27 20:57:24 -07001714 private void updateWakeGestureListenerLp() {
1715 if (shouldEnableWakeGestureLp()) {
1716 mWakeGestureListener.requestWakeUpTrigger();
1717 } else {
1718 mWakeGestureListener.cancelWakeUpTrigger();
1719 }
1720 }
1721
1722 private boolean shouldEnableWakeGestureLp() {
Jeff Brown3ee549c2014-09-22 20:14:39 -07001723 return mWakeGestureEnabledSetting && !mAwake
Jeff Browna20dda42014-05-27 20:57:24 -07001724 && (!mLidControlsSleep || mLidState != LID_CLOSED)
1725 && mWakeGestureListener.isSupported();
1726 }
1727
Jeff Brown70825162012-03-28 17:27:48 -07001728 private void enablePointerLocation() {
1729 if (mPointerLocationView == null) {
1730 mPointerLocationView = new PointerLocationView(mContext);
1731 mPointerLocationView.setPrintCoords(false);
Dianne Hackbornc777e072010-02-12 13:07:59 -08001732 WindowManager.LayoutParams lp = new WindowManager.LayoutParams(
1733 WindowManager.LayoutParams.MATCH_PARENT,
1734 WindowManager.LayoutParams.MATCH_PARENT);
Jeff Brown3b2b3542010-10-15 00:54:27 -07001735 lp.type = WindowManager.LayoutParams.TYPE_SECURE_SYSTEM_OVERLAY;
Jeff Brownbfcb60a2011-09-08 18:51:14 -07001736 lp.flags = WindowManager.LayoutParams.FLAG_FULLSCREEN
1737 | WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE
1738 | WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE
1739 | WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN;
Jeff Brown90fc9052012-10-01 14:44:24 -07001740 if (ActivityManager.isHighEndGfx()) {
1741 lp.flags |= WindowManager.LayoutParams.FLAG_HARDWARE_ACCELERATED;
1742 lp.privateFlags |=
1743 WindowManager.LayoutParams.PRIVATE_FLAG_FORCE_HARDWARE_ACCELERATED;
1744 }
Dianne Hackbornc777e072010-02-12 13:07:59 -08001745 lp.format = PixelFormat.TRANSLUCENT;
1746 lp.setTitle("PointerLocation");
Dianne Hackborn5fd21692011-06-07 14:09:47 -07001747 WindowManager wm = (WindowManager)
Dianne Hackbornc777e072010-02-12 13:07:59 -08001748 mContext.getSystemService(Context.WINDOW_SERVICE);
Jeff Browncc4f7db2011-08-30 20:34:48 -07001749 lp.inputFeatures |= WindowManager.LayoutParams.INPUT_FEATURE_NO_INPUT_CHANNEL;
Jeff Brown70825162012-03-28 17:27:48 -07001750 wm.addView(mPointerLocationView, lp);
Michael Wrightc9c487e2013-11-07 18:55:09 -08001751 mWindowManagerFuncs.registerPointerEventListener(mPointerLocationView);
Dianne Hackbornc777e072010-02-12 13:07:59 -08001752 }
Dianne Hackbornc777e072010-02-12 13:07:59 -08001753 }
Jeff Brown70825162012-03-28 17:27:48 -07001754
1755 private void disablePointerLocation() {
Jeff Brown70825162012-03-28 17:27:48 -07001756 if (mPointerLocationView != null) {
Michael Wrightc9c487e2013-11-07 18:55:09 -08001757 mWindowManagerFuncs.unregisterPointerEventListener(mPointerLocationView);
1758 WindowManager wm = (WindowManager) mContext.getSystemService(Context.WINDOW_SERVICE);
Jeff Brown70825162012-03-28 17:27:48 -07001759 wm.removeView(mPointerLocationView);
1760 mPointerLocationView = null;
1761 }
1762 }
1763
Mike Lockwood2d1efbd2009-09-16 12:15:53 -04001764 private int readRotation(int resID) {
Mike Lockwood1753f7f2009-08-24 14:49:07 -07001765 try {
1766 int rotation = mContext.getResources().getInteger(resID);
1767 switch (rotation) {
1768 case 0:
1769 return Surface.ROTATION_0;
1770 case 90:
1771 return Surface.ROTATION_90;
1772 case 180:
1773 return Surface.ROTATION_180;
1774 case 270:
1775 return Surface.ROTATION_270;
Mike Lockwood1753f7f2009-08-24 14:49:07 -07001776 }
1777 } catch (Resources.NotFoundException e) {
Mike Lockwood2d1efbd2009-09-16 12:15:53 -04001778 // fall through
Mike Lockwood1753f7f2009-08-24 14:49:07 -07001779 }
Mike Lockwood2d1efbd2009-09-16 12:15:53 -04001780 return -1;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001781 }
1782
1783 /** {@inheritDoc} */
Craig Mautner88400d32012-09-30 12:35:45 -07001784 @Override
Dianne Hackbornc2293022013-02-06 23:14:49 -08001785 public int checkAddPermission(WindowManager.LayoutParams attrs, int[] outAppOp) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001786 int type = attrs.type;
Dianne Hackbornc2293022013-02-06 23:14:49 -08001787
1788 outAppOp[0] = AppOpsManager.OP_NONE;
1789
Wale Ogunwale74bf0652015-01-12 10:24:36 -08001790 if (!((type >= FIRST_APPLICATION_WINDOW && type <= LAST_APPLICATION_WINDOW)
1791 || (type >= FIRST_SUB_WINDOW && type <= LAST_SUB_WINDOW)
1792 || (type >= FIRST_SYSTEM_WINDOW && type <= LAST_SYSTEM_WINDOW))) {
1793 return WindowManagerGlobal.ADD_INVALID_TYPE;
1794 }
1795
1796 if (type < FIRST_SYSTEM_WINDOW || type > LAST_SYSTEM_WINDOW) {
1797 // Window manager will make sure these are okay.
Jeff Brown98365d72012-08-19 20:30:52 -07001798 return WindowManagerGlobal.ADD_OKAY;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001799 }
1800 String permission = null;
1801 switch (type) {
1802 case TYPE_TOAST:
1803 // XXX right now the app process has complete control over
1804 // this... should introduce a token to let the system
1805 // monitor/control what they are doing.
Jason Monk1c7c3192014-06-26 12:52:18 -04001806 outAppOp[0] = AppOpsManager.OP_TOAST_WINDOW;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001807 break;
Daniel Sandler7d276c32012-01-30 14:33:52 -05001808 case TYPE_DREAM:
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001809 case TYPE_INPUT_METHOD:
Dianne Hackbornb7cd8b92009-08-08 20:53:03 -07001810 case TYPE_WALLPAPER:
keunyounga446bf02013-06-21 19:07:57 -07001811 case TYPE_PRIVATE_PRESENTATION:
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001812 case TYPE_VOICE_INTERACTION:
Svetoslav3a5c7212014-10-14 09:54:26 -07001813 case TYPE_ACCESSIBILITY_OVERLAY:
Dianne Hackbornb7cd8b92009-08-08 20:53:03 -07001814 // The window manager will check these.
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001815 break;
1816 case TYPE_PHONE:
1817 case TYPE_PRIORITY_PHONE:
1818 case TYPE_SYSTEM_ALERT:
1819 case TYPE_SYSTEM_ERROR:
1820 case TYPE_SYSTEM_OVERLAY:
1821 permission = android.Manifest.permission.SYSTEM_ALERT_WINDOW;
Dianne Hackbornc2293022013-02-06 23:14:49 -08001822 outAppOp[0] = AppOpsManager.OP_SYSTEM_ALERT_WINDOW;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001823 break;
1824 default:
1825 permission = android.Manifest.permission.INTERNAL_SYSTEM_WINDOW;
1826 }
1827 if (permission != null) {
Billy Laucbe540f2015-06-25 01:51:44 +01001828 if (permission == android.Manifest.permission.SYSTEM_ALERT_WINDOW) {
1829 final int callingUid = Binder.getCallingUid();
1830 // check if this is a system uid first before bothering with
1831 // obtaining package name
1832 if (callingUid == Process.SYSTEM_UID) {
1833 return WindowManagerGlobal.ADD_OKAY;
1834 }
1835
1836 final int mode = mAppOpsManager.checkOp(outAppOp[0], callingUid,
1837 attrs.packageName);
1838 if (mode == AppOpsManager.MODE_DEFAULT) {
1839 if (mContext.checkCallingPermission(permission) !=
1840 PackageManager.PERMISSION_GRANTED) {
1841 return WindowManagerGlobal.ADD_PERMISSION_DENIED;
1842 }
1843 }
1844 return WindowManagerGlobal.ADD_OKAY;
1845 }
1846
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001847 if (mContext.checkCallingOrSelfPermission(permission)
1848 != PackageManager.PERMISSION_GRANTED) {
Jeff Brown98365d72012-08-19 20:30:52 -07001849 return WindowManagerGlobal.ADD_PERMISSION_DENIED;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001850 }
1851 }
Jeff Brown98365d72012-08-19 20:30:52 -07001852 return WindowManagerGlobal.ADD_OKAY;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001853 }
Craig Mautner88400d32012-09-30 12:35:45 -07001854
1855 @Override
1856 public boolean checkShowToOwnerOnly(WindowManager.LayoutParams attrs) {
1857
1858 // If this switch statement is modified, modify the comment in the declarations of
1859 // the type in {@link WindowManager.LayoutParams} as well.
1860 switch (attrs.type) {
1861 default:
1862 // These are the windows that by default are shown only to the user that created
1863 // them. If this needs to be overridden, set
1864 // {@link WindowManager.LayoutParams.PRIVATE_FLAG_SHOW_FOR_ALL_USERS} in
1865 // {@link WindowManager.LayoutParams}. Note that permission
1866 // {@link android.Manifest.permission.INTERNAL_SYSTEM_WINDOW} is required as well.
1867 if ((attrs.privateFlags & PRIVATE_FLAG_SHOW_FOR_ALL_USERS) == 0) {
1868 return true;
1869 }
1870 break;
1871
1872 // These are the windows that by default are shown to all users. However, to
1873 // protect against spoofing, check permissions below.
1874 case TYPE_APPLICATION_STARTING:
1875 case TYPE_BOOT_PROGRESS:
1876 case TYPE_DISPLAY_OVERLAY:
Selim Cinekf83e8242015-05-19 18:08:14 -07001877 case TYPE_INPUT_CONSUMER:
Jim Miller5ecd8112013-01-09 18:50:26 -08001878 case TYPE_KEYGUARD_SCRIM:
Craig Mautner88400d32012-09-30 12:35:45 -07001879 case TYPE_KEYGUARD_DIALOG:
1880 case TYPE_MAGNIFICATION_OVERLAY:
1881 case TYPE_NAVIGATION_BAR:
1882 case TYPE_NAVIGATION_BAR_PANEL:
1883 case TYPE_PHONE:
1884 case TYPE_POINTER:
1885 case TYPE_PRIORITY_PHONE:
Craig Mautner88400d32012-09-30 12:35:45 -07001886 case TYPE_SEARCH_BAR:
1887 case TYPE_STATUS_BAR:
1888 case TYPE_STATUS_BAR_PANEL:
1889 case TYPE_STATUS_BAR_SUB_PANEL:
1890 case TYPE_SYSTEM_DIALOG:
Craig Mautner88400d32012-09-30 12:35:45 -07001891 case TYPE_VOLUME_OVERLAY:
keunyounga446bf02013-06-21 19:07:57 -07001892 case TYPE_PRIVATE_PRESENTATION:
Craig Mautner88400d32012-09-30 12:35:45 -07001893 break;
1894 }
1895
1896 // Check if third party app has set window to system window type.
1897 return mContext.checkCallingOrSelfPermission(
1898 android.Manifest.permission.INTERNAL_SYSTEM_WINDOW)
1899 != PackageManager.PERMISSION_GRANTED;
1900 }
1901
Craig Mautner967212c2013-04-13 21:10:58 -07001902 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001903 public void adjustWindowParamsLw(WindowManager.LayoutParams attrs) {
1904 switch (attrs.type) {
1905 case TYPE_SYSTEM_OVERLAY:
Jeff Brown3b2b3542010-10-15 00:54:27 -07001906 case TYPE_SECURE_SYSTEM_OVERLAY:
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001907 // These types of windows can't receive input events.
1908 attrs.flags |= WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE
1909 | WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE;
Jeff Brownbfcb60a2011-09-08 18:51:14 -07001910 attrs.flags &= ~WindowManager.LayoutParams.FLAG_WATCH_OUTSIDE_TOUCH;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001911 break;
Jorim Jaggi380ecb82014-03-14 17:25:20 +01001912 case TYPE_STATUS_BAR:
1913
1914 // If the Keyguard is in a hidden state (occluded by another window), we force to
1915 // remove the wallpaper and keyguard flag so that any change in-flight after setting
1916 // the keyguard as occluded wouldn't set these flags again.
1917 // See {@link #processKeyguardSetHiddenResultLw}.
1918 if (mKeyguardHidden) {
1919 attrs.flags &= ~WindowManager.LayoutParams.FLAG_SHOW_WALLPAPER;
1920 attrs.privateFlags &= ~WindowManager.LayoutParams.PRIVATE_FLAG_KEYGUARD;
1921 }
1922 break;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001923 }
Adrian Roos38502112014-04-09 21:04:11 +02001924
1925 if (attrs.type != TYPE_STATUS_BAR) {
1926 // The status bar is the only window allowed to exhibit keyguard behavior.
1927 attrs.privateFlags &= ~WindowManager.LayoutParams.PRIVATE_FLAG_KEYGUARD;
1928 }
Adrian Roosea562512014-05-05 13:33:03 +02001929
1930 if (ActivityManager.isHighEndGfx()
1931 && (attrs.flags & FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS) != 0) {
Adrian Roosf5e9b5c2014-09-10 15:27:41 +02001932 attrs.subtreeSystemUiVisibility |= View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
Adrian Roosea562512014-05-05 13:33:03 +02001933 | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION;
1934 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001935 }
RoboErik8a2cfc32014-05-16 11:19:38 -07001936
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001937 void readLidState() {
Jeff Brown2e7760e2012-04-11 15:14:55 -07001938 mLidState = mWindowManagerFuncs.getLidState();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001939 }
RoboErik8a2cfc32014-05-16 11:19:38 -07001940
Michael Wright3818c922014-09-02 13:59:07 -07001941 private void readCameraLensCoverState() {
1942 mCameraLensCoverState = mWindowManagerFuncs.getCameraLensCoverState();
1943 }
1944
Jeff Browndaa37532012-05-01 15:54:03 -07001945 private boolean isHidden(int accessibilityMode) {
1946 switch (accessibilityMode) {
1947 case 1:
1948 return mLidState == LID_CLOSED;
1949 case 2:
1950 return mLidState == LID_OPEN;
1951 default:
1952 return false;
Dianne Hackborn2862fff2009-09-15 22:56:29 -07001953 }
Dianne Hackborn2862fff2009-09-15 22:56:29 -07001954 }
Jeff Brownd04a88c2011-01-16 14:05:47 -08001955
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001956 /** {@inheritDoc} */
Craig Mautner967212c2013-04-13 21:10:58 -07001957 @Override
Jeff Browndaa37532012-05-01 15:54:03 -07001958 public void adjustConfigurationLw(Configuration config, int keyboardPresence,
1959 int navigationPresence) {
1960 mHaveBuiltInKeyboard = (keyboardPresence & PRESENCE_INTERNAL) != 0;
1961
Jeff Brownf71343d2013-05-31 17:59:11 -07001962 readConfigurationDependentBehaviors();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001963 readLidState();
Jeff Brownc458ce92012-04-30 14:58:40 -07001964 applyLidSwitchState();
Jeff Brownd04a88c2011-01-16 14:05:47 -08001965
Jeff Browndaa37532012-05-01 15:54:03 -07001966 if (config.keyboard == Configuration.KEYBOARD_NOKEYS
1967 || (keyboardPresence == PRESENCE_INTERNAL
1968 && isHidden(mLidKeyboardAccessibility))) {
Jeff Brownd04a88c2011-01-16 14:05:47 -08001969 config.hardKeyboardHidden = Configuration.HARDKEYBOARDHIDDEN_YES;
Jeff Browndaa37532012-05-01 15:54:03 -07001970 if (!mHasSoftInput) {
1971 config.keyboardHidden = Configuration.KEYBOARDHIDDEN_YES;
1972 }
Jeff Brownd04a88c2011-01-16 14:05:47 -08001973 }
1974
Jeff Browndaa37532012-05-01 15:54:03 -07001975 if (config.navigation == Configuration.NAVIGATION_NONAV
1976 || (navigationPresence == PRESENCE_INTERNAL
1977 && isHidden(mLidNavigationAccessibility))) {
Jeff Brownd04a88c2011-01-16 14:05:47 -08001978 config.navigationHidden = Configuration.NAVIGATIONHIDDEN_YES;
Jeff Brownd04a88c2011-01-16 14:05:47 -08001979 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001980 }
Jeff Brownd04a88c2011-01-16 14:05:47 -08001981
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001982 /** {@inheritDoc} */
Craig Mautner967212c2013-04-13 21:10:58 -07001983 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001984 public int windowTypeToLayerLw(int type) {
1985 if (type >= FIRST_APPLICATION_WINDOW && type <= LAST_APPLICATION_WINDOW) {
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001986 return 2;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001987 }
1988 switch (type) {
keunyounga446bf02013-06-21 19:07:57 -07001989 case TYPE_PRIVATE_PRESENTATION:
1990 return 2;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001991 case TYPE_WALLPAPER:
1992 // wallpaper is at the bottom, though the window manager may move it.
1993 return 2;
1994 case TYPE_PHONE:
1995 return 3;
1996 case TYPE_SEARCH_BAR:
Jorim Jaggi225d3b52015-04-01 11:18:57 -07001997 case TYPE_VOICE_INTERACTION_STARTING:
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001998 return 4;
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001999 case TYPE_VOICE_INTERACTION:
2000 // voice interaction layer is almost immediately above apps.
2001 return 5;
Selim Cinekf83e8242015-05-19 18:08:14 -07002002 case TYPE_INPUT_CONSUMER:
Dianne Hackborne30e02f2014-05-27 18:24:45 -07002003 return 6;
Selim Cinekf83e8242015-05-19 18:08:14 -07002004 case TYPE_SYSTEM_DIALOG:
2005 return 7;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07002006 case TYPE_TOAST:
2007 // toasts and the plugged-in battery thing
Selim Cinekf83e8242015-05-19 18:08:14 -07002008 return 8;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07002009 case TYPE_PRIORITY_PHONE:
2010 // SIM errors and unlock. Not sure if this really should be in a high layer.
Selim Cinekf83e8242015-05-19 18:08:14 -07002011 return 9;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07002012 case TYPE_DREAM:
2013 // used for Dreams (screensavers with TYPE_DREAM windows)
Selim Cinekf83e8242015-05-19 18:08:14 -07002014 return 10;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07002015 case TYPE_SYSTEM_ALERT:
2016 // like the ANR / app crashed dialogs
Selim Cinekf83e8242015-05-19 18:08:14 -07002017 return 11;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07002018 case TYPE_INPUT_METHOD:
2019 // on-screen keyboards and other such input method user interfaces go here.
Selim Cinekf83e8242015-05-19 18:08:14 -07002020 return 12;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07002021 case TYPE_INPUT_METHOD_DIALOG:
2022 // on-screen keyboards and other such input method user interfaces go here.
Selim Cinekf83e8242015-05-19 18:08:14 -07002023 return 13;
Jim Miller5ecd8112013-01-09 18:50:26 -08002024 case TYPE_KEYGUARD_SCRIM:
2025 // the safety window that shows behind keyguard while keyguard is starting
Jorim Jaggi380ecb82014-03-14 17:25:20 +01002026 return 14;
Selim Cinekf83e8242015-05-19 18:08:14 -07002027 case TYPE_STATUS_BAR_SUB_PANEL:
Jorim Jaggi380ecb82014-03-14 17:25:20 +01002028 return 15;
Selim Cinekf83e8242015-05-19 18:08:14 -07002029 case TYPE_STATUS_BAR:
Jorim Jaggi380ecb82014-03-14 17:25:20 +01002030 return 16;
Selim Cinekf83e8242015-05-19 18:08:14 -07002031 case TYPE_STATUS_BAR_PANEL:
Dianne Hackborne30e02f2014-05-27 18:24:45 -07002032 return 17;
Selim Cinekf83e8242015-05-19 18:08:14 -07002033 case TYPE_KEYGUARD_DIALOG:
2034 return 18;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07002035 case TYPE_VOLUME_OVERLAY:
2036 // the on-screen volume indicator and controller shown when the user
2037 // changes the device volume
Selim Cinekf83e8242015-05-19 18:08:14 -07002038 return 19;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07002039 case TYPE_SYSTEM_OVERLAY:
2040 // the on-screen volume indicator and controller shown when the user
2041 // changes the device volume
Selim Cinekf83e8242015-05-19 18:08:14 -07002042 return 20;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07002043 case TYPE_NAVIGATION_BAR:
2044 // the navigation bar, if available, shows atop most things
Selim Cinekf83e8242015-05-19 18:08:14 -07002045 return 21;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07002046 case TYPE_NAVIGATION_BAR_PANEL:
2047 // some panels (e.g. search) need to show on top of the navigation bar
Selim Cinekf83e8242015-05-19 18:08:14 -07002048 return 22;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07002049 case TYPE_SYSTEM_ERROR:
2050 // system-level error dialogs
Selim Cinekf83e8242015-05-19 18:08:14 -07002051 return 23;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07002052 case TYPE_MAGNIFICATION_OVERLAY:
2053 // used to highlight the magnified portion of a display
Selim Cinekf83e8242015-05-19 18:08:14 -07002054 return 24;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07002055 case TYPE_DISPLAY_OVERLAY:
2056 // used to simulate secondary display devices
Selim Cinekf83e8242015-05-19 18:08:14 -07002057 return 25;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07002058 case TYPE_DRAG:
2059 // the drag layer: input for drag-and-drop is associated with this window,
2060 // which sits above all other focusable windows
Selim Cinekf83e8242015-05-19 18:08:14 -07002061 return 26;
Svetoslav3a5c7212014-10-14 09:54:26 -07002062 case TYPE_ACCESSIBILITY_OVERLAY:
2063 // overlay put by accessibility services to intercept user interaction
Dianne Hackborne30e02f2014-05-27 18:24:45 -07002064 return 27;
Selim Cinekf83e8242015-05-19 18:08:14 -07002065 case TYPE_SECURE_SYSTEM_OVERLAY:
Svetoslav3a5c7212014-10-14 09:54:26 -07002066 return 28;
Selim Cinekf83e8242015-05-19 18:08:14 -07002067 case TYPE_BOOT_PROGRESS:
2068 return 29;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07002069 case TYPE_POINTER:
2070 // the (mouse) pointer layer
Svetoslav3a5c7212014-10-14 09:54:26 -07002071 return 30;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002072 }
2073 Log.e(TAG, "Unknown window type: " + type);
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07002074 return 2;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002075 }
2076
2077 /** {@inheritDoc} */
Craig Mautner46ac6fa2013-08-01 10:06:34 -07002078 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002079 public int subWindowTypeToLayerLw(int type) {
2080 switch (type) {
2081 case TYPE_APPLICATION_PANEL:
2082 case TYPE_APPLICATION_ATTACHED_DIALOG:
2083 return APPLICATION_PANEL_SUBLAYER;
2084 case TYPE_APPLICATION_MEDIA:
2085 return APPLICATION_MEDIA_SUBLAYER;
Dianne Hackborn5cb8d792009-05-21 17:34:15 -07002086 case TYPE_APPLICATION_MEDIA_OVERLAY:
2087 return APPLICATION_MEDIA_OVERLAY_SUBLAYER;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002088 case TYPE_APPLICATION_SUB_PANEL:
2089 return APPLICATION_SUB_PANEL_SUBLAYER;
Wale Ogunwale0a4dc222015-04-14 12:58:42 -07002090 case TYPE_APPLICATION_ABOVE_SUB_PANEL:
2091 return APPLICATION_ABOVE_SUB_PANEL_SUBLAYER;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002092 }
2093 Log.e(TAG, "Unknown sub-window type: " + type);
2094 return 0;
2095 }
2096
Craig Mautner46ac6fa2013-08-01 10:06:34 -07002097 @Override
Dianne Hackbornabe0da02009-09-18 01:55:39 -07002098 public int getMaxWallpaperLayer() {
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07002099 return windowTypeToLayerLw(TYPE_STATUS_BAR);
Dianne Hackbornabe0da02009-09-18 01:55:39 -07002100 }
2101
Craig Mautner46ac6fa2013-08-01 10:06:34 -07002102 @Override
Dianne Hackborn1f903c32011-09-13 19:18:06 -07002103 public int getNonDecorDisplayWidth(int fullWidth, int fullHeight, int rotation) {
Dianne Hackborn077ee852012-04-09 16:27:07 -07002104 if (mHasNavigationBar) {
2105 // For a basic navigation bar, when we are in landscape mode we place
2106 // the navigation bar to the side.
Daniel Sandler4a066c52012-04-20 14:49:13 -04002107 if (mNavigationBarCanMove && fullWidth > fullHeight) {
2108 return fullWidth - mNavigationBarWidthForRotation[rotation];
Dianne Hackborn077ee852012-04-09 16:27:07 -07002109 }
Dianne Hackborn1f903c32011-09-13 19:18:06 -07002110 }
2111 return fullWidth;
Dianne Hackborne2515ee2011-04-27 18:52:56 -04002112 }
2113
Jose Lima9546b202014-07-02 17:21:51 -07002114 @Override
Dianne Hackborn1f903c32011-09-13 19:18:06 -07002115 public int getNonDecorDisplayHeight(int fullWidth, int fullHeight, int rotation) {
Dianne Hackborn077ee852012-04-09 16:27:07 -07002116 if (mHasNavigationBar) {
2117 // For a basic navigation bar, when we are in portrait mode we place
2118 // the navigation bar to the bottom.
Daniel Sandler4a066c52012-04-20 14:49:13 -04002119 if (!mNavigationBarCanMove || fullWidth < fullHeight) {
2120 return fullHeight - mNavigationBarHeightForRotation[rotation];
Dianne Hackborn077ee852012-04-09 16:27:07 -07002121 }
2122 }
2123 return fullHeight;
Dianne Hackborn69cb8752011-05-19 18:13:32 -07002124 }
2125
Jose Lima9546b202014-07-02 17:21:51 -07002126 @Override
Dianne Hackborn1f903c32011-09-13 19:18:06 -07002127 public int getConfigDisplayWidth(int fullWidth, int fullHeight, int rotation) {
2128 return getNonDecorDisplayWidth(fullWidth, fullHeight, rotation);
Dianne Hackborn69cb8752011-05-19 18:13:32 -07002129 }
2130
Jose Lima9546b202014-07-02 17:21:51 -07002131 @Override
Dianne Hackborn1f903c32011-09-13 19:18:06 -07002132 public int getConfigDisplayHeight(int fullWidth, int fullHeight, int rotation) {
John Spurlock80f00c12013-06-13 11:10:51 -04002133 // There is a separate status bar at the top of the display. We don't count that as part
2134 // of the fixed decor, since it can hide; however, for purposes of configurations,
Dianne Hackborn077ee852012-04-09 16:27:07 -07002135 // we do want to exclude it since applications can't generally use that part
2136 // of the screen.
John Spurlock80f00c12013-06-13 11:10:51 -04002137 return getNonDecorDisplayHeight(fullWidth, fullHeight, rotation) - mStatusBarHeight;
Dianne Hackborne2515ee2011-04-27 18:52:56 -04002138 }
2139
Craig Mautnera3f4bf52012-10-10 20:37:48 -07002140 @Override
Craig Mautnerc9457fa2014-06-06 14:27:48 -07002141 public boolean isForceHiding(WindowManager.LayoutParams attrs) {
2142 return (attrs.privateFlags & PRIVATE_FLAG_KEYGUARD) != 0 ||
Jim Millerab954542014-10-10 18:21:49 -07002143 (isKeyguardHostWindow(attrs) &&
2144 (mKeyguardDelegate != null && mKeyguardDelegate.isShowing())) ||
Adrian Roos69e510d2014-07-13 14:57:59 +02002145 (attrs.type == TYPE_KEYGUARD_SCRIM);
Dianne Hackborn01ad2f42009-09-24 19:24:56 -07002146 }
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07002147
Craig Mautnera3f4bf52012-10-10 20:37:48 -07002148 @Override
Jorim Jaggi0d674622014-05-21 01:34:15 +02002149 public boolean isKeyguardHostWindow(WindowManager.LayoutParams attrs) {
2150 return attrs.type == TYPE_STATUS_BAR;
2151 }
2152
2153 @Override
Dianne Hackborn01ad2f42009-09-24 19:24:56 -07002154 public boolean canBeForceHidden(WindowState win, WindowManager.LayoutParams attrs) {
Craig Mautnera3f4bf52012-10-10 20:37:48 -07002155 switch (attrs.type) {
2156 case TYPE_STATUS_BAR:
2157 case TYPE_NAVIGATION_BAR:
2158 case TYPE_WALLPAPER:
2159 case TYPE_DREAM:
Jim Miller5ecd8112013-01-09 18:50:26 -08002160 case TYPE_KEYGUARD_SCRIM:
Craig Mautnera3f4bf52012-10-10 20:37:48 -07002161 return false;
2162 default:
Adrian Roos461829d2015-06-03 14:41:18 -07002163 // Hide only windows below the keyguard host window.
2164 return windowTypeToLayerLw(win.getBaseType())
2165 < windowTypeToLayerLw(TYPE_STATUS_BAR);
Craig Mautnera3f4bf52012-10-10 20:37:48 -07002166 }
Dianne Hackborn01ad2f42009-09-24 19:24:56 -07002167 }
Craig Mautner8e4df6c2012-05-23 16:57:23 -07002168
Craig Mautner7d7808f2014-09-11 18:02:38 -07002169 @Override
2170 public WindowState getWinShowWhenLockedLw() {
2171 return mWinShowWhenLocked;
2172 }
2173
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002174 /** {@inheritDoc} */
Craig Mautner8e4df6c2012-05-23 16:57:23 -07002175 @Override
Dianne Hackborn2f0b1752011-05-31 17:59:49 -07002176 public View addStartingWindow(IBinder appToken, String packageName, int theme,
2177 CompatibilityInfo compatInfo, CharSequence nonLocalizedLabel, int labelRes,
Adam Powell04fe6eb2013-05-31 14:39:48 -07002178 int icon, int logo, int windowFlags) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002179 if (!SHOW_STARTING_ANIMATIONS) {
2180 return null;
2181 }
2182 if (packageName == null) {
2183 return null;
2184 }
Craig Mautner8e4df6c2012-05-23 16:57:23 -07002185
Mathias Jeppssond1443e92012-08-24 15:25:32 +02002186 WindowManager wm = null;
2187 View view = null;
2188
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002189 try {
Dianne Hackborn867ab6472010-04-29 13:28:56 -07002190 Context context = mContext;
Craig Mautner6fbda632012-07-03 09:26:39 -07002191 if (DEBUG_STARTING_WINDOW) Slog.d(TAG, "addStartingWindow " + packageName
2192 + ": nonLocalizedLabel=" + nonLocalizedLabel + " theme="
2193 + Integer.toHexString(theme));
Dianne Hackborn247fe742011-01-08 17:25:57 -08002194 if (theme != context.getThemeResId() || labelRes != 0) {
Dianne Hackborn867ab6472010-04-29 13:28:56 -07002195 try {
2196 context = context.createPackageContext(packageName, 0);
Dianne Hackborn247fe742011-01-08 17:25:57 -08002197 context.setTheme(theme);
Dianne Hackborn867ab6472010-04-29 13:28:56 -07002198 } catch (PackageManager.NameNotFoundException e) {
2199 // Ignore
2200 }
2201 }
Craig Mautner8e4df6c2012-05-23 16:57:23 -07002202
Jorim Jaggia16cc152015-06-01 16:55:05 -07002203 PhoneWindow win = new PhoneWindow(context);
2204 win.setIsStartingWindow(true);
Craig Mautner8e4df6c2012-05-23 16:57:23 -07002205 final TypedArray ta = win.getWindowStyle();
2206 if (ta.getBoolean(
2207 com.android.internal.R.styleable.Window_windowDisablePreview, false)
2208 || ta.getBoolean(
2209 com.android.internal.R.styleable.Window_windowShowWallpaper,false)) {
Dianne Hackborn867ab6472010-04-29 13:28:56 -07002210 return null;
2211 }
Craig Mautner8e4df6c2012-05-23 16:57:23 -07002212
Dianne Hackborn867ab6472010-04-29 13:28:56 -07002213 Resources r = context.getResources();
2214 win.setTitle(r.getText(labelRes, nonLocalizedLabel));
Craig Mautner8e4df6c2012-05-23 16:57:23 -07002215
Dianne Hackborn867ab6472010-04-29 13:28:56 -07002216 win.setType(
2217 WindowManager.LayoutParams.TYPE_APPLICATION_STARTING);
Adrian Roos602c68e2015-04-24 16:03:47 -07002218
2219 synchronized (mWindowManagerFuncs.getWindowManagerLock()) {
2220 // Assumes it's safe to show starting windows of launched apps while
2221 // the keyguard is being hidden. This is okay because starting windows never show
2222 // secret information.
2223 if (mKeyguardHidden) {
2224 windowFlags |= FLAG_SHOW_WHEN_LOCKED;
2225 }
2226 }
2227
Dianne Hackborn867ab6472010-04-29 13:28:56 -07002228 // Force the window flags: this is a fake window, so it is not really
2229 // touchable or focusable by the user. We also add in the ALT_FOCUSABLE_IM
2230 // flag because we do know that the next window will take input
2231 // focus, so we want to get the IME window up on top of us right away.
2232 win.setFlags(
Dianne Hackborn7eec10e2010-11-12 18:03:47 -08002233 windowFlags|
Dianne Hackborn867ab6472010-04-29 13:28:56 -07002234 WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE|
2235 WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE|
2236 WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM,
Dianne Hackborn7eec10e2010-11-12 18:03:47 -08002237 windowFlags|
Dianne Hackborn867ab6472010-04-29 13:28:56 -07002238 WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE|
2239 WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE|
2240 WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM);
Craig Mautner8e4df6c2012-05-23 16:57:23 -07002241
Adam Powell04fe6eb2013-05-31 14:39:48 -07002242 win.setDefaultIcon(icon);
2243 win.setDefaultLogo(logo);
2244
Dianne Hackborn867ab6472010-04-29 13:28:56 -07002245 win.setLayout(WindowManager.LayoutParams.MATCH_PARENT,
Dianne Hackborn2f0b1752011-05-31 17:59:49 -07002246 WindowManager.LayoutParams.MATCH_PARENT);
Craig Mautner8e4df6c2012-05-23 16:57:23 -07002247
Dianne Hackborn867ab6472010-04-29 13:28:56 -07002248 final WindowManager.LayoutParams params = win.getAttributes();
2249 params.token = appToken;
2250 params.packageName = packageName;
2251 params.windowAnimations = win.getWindowStyle().getResourceId(
2252 com.android.internal.R.styleable.Window_windowAnimationStyle, 0);
John Reck61375a82014-09-18 19:27:48 +00002253 params.privateFlags |=
2254 WindowManager.LayoutParams.PRIVATE_FLAG_FAKE_HARDWARE_ACCELERATED;
Craig Mautner88400d32012-09-30 12:35:45 -07002255 params.privateFlags |= WindowManager.LayoutParams.PRIVATE_FLAG_SHOW_FOR_ALL_USERS;
Adam Lesinski95c42972013-10-02 10:13:27 -07002256
2257 if (!compatInfo.supportsScreen()) {
2258 params.privateFlags |= WindowManager.LayoutParams.PRIVATE_FLAG_COMPATIBLE_WINDOW;
2259 }
2260
Dianne Hackborn867ab6472010-04-29 13:28:56 -07002261 params.setTitle("Starting " + packageName);
2262
Mathias Jeppssond1443e92012-08-24 15:25:32 +02002263 wm = (WindowManager)context.getSystemService(Context.WINDOW_SERVICE);
2264 view = win.getDecorView();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002265
2266 if (win.isFloating()) {
2267 // Whoops, there is no way to display an animation/preview
2268 // of such a thing! After all that work... let's skip it.
2269 // (Note that we must do this here because it is in
2270 // getDecorView() where the theme is evaluated... maybe
2271 // we should peek the floating attribute from the theme
2272 // earlier.)
2273 return null;
2274 }
Craig Mautner8e4df6c2012-05-23 16:57:23 -07002275
Craig Mautner6fbda632012-07-03 09:26:39 -07002276 if (DEBUG_STARTING_WINDOW) Slog.d(
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002277 TAG, "Adding starting window for " + packageName
2278 + " / " + appToken + ": "
2279 + (view.getParent() != null ? view : null));
2280
2281 wm.addView(view, params);
2282
2283 // Only return the view if it was successfully added to the
2284 // window manager... which we can tell by it having a parent.
2285 return view.getParent() != null ? view : null;
Jeff Brown98365d72012-08-19 20:30:52 -07002286 } catch (WindowManager.BadTokenException e) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002287 // ignore
Craig Mautner42bf39e2014-02-21 16:46:22 -08002288 Log.w(TAG, appToken + " already running, starting window not displayed. " +
2289 e.getMessage());
Dianne Hackborn867ab6472010-04-29 13:28:56 -07002290 } catch (RuntimeException e) {
2291 // don't crash if something else bad happens, for example a
2292 // failure loading resources because we are loading from an app
2293 // on external storage that has been unmounted.
2294 Log.w(TAG, appToken + " failed creating starting window", e);
Mathias Jeppssond1443e92012-08-24 15:25:32 +02002295 } finally {
2296 if (view != null && view.getParent() == null) {
2297 Log.w(TAG, "view not successfully added to wm, removing view");
2298 wm.removeViewImmediate(view);
2299 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002300 }
2301
2302 return null;
2303 }
2304
2305 /** {@inheritDoc} */
Jose Lima9546b202014-07-02 17:21:51 -07002306 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002307 public void removeStartingWindow(IBinder appToken, View window) {
Craig Mautner276a6eb2014-11-04 15:32:57 -08002308 if (DEBUG_STARTING_WINDOW) Slog.v(TAG, "Removing starting window for " + appToken + ": "
2309 + window + " Callers=" + Debug.getCallers(4));
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002310
2311 if (window != null) {
Dianne Hackborn5fd21692011-06-07 14:09:47 -07002312 WindowManager wm = (WindowManager)mContext.getSystemService(Context.WINDOW_SERVICE);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002313 wm.removeView(window);
2314 }
2315 }
2316
2317 /**
2318 * Preflight adding a window to the system.
RoboErik8a2cfc32014-05-16 11:19:38 -07002319 *
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002320 * Currently enforces that three window types are singletons:
2321 * <ul>
2322 * <li>STATUS_BAR_TYPE</li>
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002323 * <li>KEYGUARD_TYPE</li>
2324 * </ul>
RoboErik8a2cfc32014-05-16 11:19:38 -07002325 *
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002326 * @param win The window to be added
2327 * @param attrs Information about the window to be added
RoboErik8a2cfc32014-05-16 11:19:38 -07002328 *
Jeff Brown98365d72012-08-19 20:30:52 -07002329 * @return If ok, WindowManagerImpl.ADD_OKAY. If too many singletons,
2330 * WindowManagerImpl.ADD_MULTIPLE_SINGLETON
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002331 */
Jose Lima9546b202014-07-02 17:21:51 -07002332 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002333 public int prepareAddWindowLw(WindowState win, WindowManager.LayoutParams attrs) {
2334 switch (attrs.type) {
2335 case TYPE_STATUS_BAR:
Joe Onorato8bc6c512010-06-04 16:21:12 -04002336 mContext.enforceCallingOrSelfPermission(
2337 android.Manifest.permission.STATUS_BAR_SERVICE,
2338 "PhoneWindowManager");
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002339 if (mStatusBar != null) {
Dianne Hackbornf87d1962012-04-04 12:48:24 -07002340 if (mStatusBar.isAlive()) {
Jeff Brown98365d72012-08-19 20:30:52 -07002341 return WindowManagerGlobal.ADD_MULTIPLE_SINGLETON;
Dianne Hackbornf87d1962012-04-04 12:48:24 -07002342 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002343 }
2344 mStatusBar = win;
John Spurlock27735a42013-08-14 17:57:38 -04002345 mStatusBarController.setWindow(win);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002346 break;
Daniel Sandler8956dbb2011-04-22 07:55:02 -04002347 case TYPE_NAVIGATION_BAR:
2348 mContext.enforceCallingOrSelfPermission(
2349 android.Manifest.permission.STATUS_BAR_SERVICE,
2350 "PhoneWindowManager");
Dianne Hackbornf87d1962012-04-04 12:48:24 -07002351 if (mNavigationBar != null) {
2352 if (mNavigationBar.isAlive()) {
Jeff Brown98365d72012-08-19 20:30:52 -07002353 return WindowManagerGlobal.ADD_MULTIPLE_SINGLETON;
Dianne Hackbornf87d1962012-04-04 12:48:24 -07002354 }
2355 }
Daniel Sandler8956dbb2011-04-22 07:55:02 -04002356 mNavigationBar = win;
John Spurlock27735a42013-08-14 17:57:38 -04002357 mNavigationBarController.setWindow(win);
Craig Mautnereda67292013-04-28 13:50:14 -07002358 if (DEBUG_LAYOUT) Slog.i(TAG, "NAVIGATION BAR: " + mNavigationBar);
Daniel Sandler8956dbb2011-04-22 07:55:02 -04002359 break;
Jim Millere898ac52012-04-06 17:10:57 -07002360 case TYPE_NAVIGATION_BAR_PANEL:
Dianne Hackborn08743722009-12-21 12:16:51 -08002361 case TYPE_STATUS_BAR_PANEL:
Joe Onorato29fc2c92010-11-24 10:26:50 -08002362 case TYPE_STATUS_BAR_SUB_PANEL:
Jorim Jaggi225d3b52015-04-01 11:18:57 -07002363 case TYPE_VOICE_INTERACTION_STARTING:
Joe Onorato29fc2c92010-11-24 10:26:50 -08002364 mContext.enforceCallingOrSelfPermission(
2365 android.Manifest.permission.STATUS_BAR_SERVICE,
2366 "PhoneWindowManager");
Joe Onorato29fc2c92010-11-24 10:26:50 -08002367 break;
Jim Miller5ecd8112013-01-09 18:50:26 -08002368 case TYPE_KEYGUARD_SCRIM:
Jim Miller25190572013-02-28 17:36:24 -08002369 if (mKeyguardScrim != null) {
2370 return WindowManagerGlobal.ADD_MULTIPLE_SINGLETON;
2371 }
Jim Miller5ecd8112013-01-09 18:50:26 -08002372 mKeyguardScrim = win;
2373 break;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002374 }
Jeff Brown98365d72012-08-19 20:30:52 -07002375 return WindowManagerGlobal.ADD_OKAY;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002376 }
2377
2378 /** {@inheritDoc} */
Jose Lima9546b202014-07-02 17:21:51 -07002379 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002380 public void removeWindowLw(WindowState win) {
2381 if (mStatusBar == win) {
2382 mStatusBar = null;
John Spurlock27735a42013-08-14 17:57:38 -04002383 mStatusBarController.setWindow(null);
Jim Millerc0b676d2013-03-22 16:11:08 -07002384 mKeyguardDelegate.showScrim();
Jim Miller5ecd8112013-01-09 18:50:26 -08002385 } else if (mKeyguardScrim == win) {
2386 Log.v(TAG, "Removing keyguard scrim");
2387 mKeyguardScrim = null;
2388 } if (mNavigationBar == win) {
Daniel Sandler8956dbb2011-04-22 07:55:02 -04002389 mNavigationBar = null;
John Spurlock27735a42013-08-14 17:57:38 -04002390 mNavigationBarController.setWindow(null);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002391 }
2392 }
2393
2394 static final boolean PRINT_ANIM = false;
RoboErik8a2cfc32014-05-16 11:19:38 -07002395
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002396 /** {@inheritDoc} */
Craig Mautner4b71aa12012-12-27 17:20:01 -08002397 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002398 public int selectAnimationLw(WindowState win, int transit) {
2399 if (PRINT_ANIM) Log.i(TAG, "selectAnimation in " + win
2400 + ": transit=" + transit);
Dianne Hackbornf87d1962012-04-04 12:48:24 -07002401 if (win == mStatusBar) {
Jorim Jaggi380ecb82014-03-14 17:25:20 +01002402 boolean isKeyguard = (win.getAttrs().privateFlags & PRIVATE_FLAG_KEYGUARD) != 0;
Craig Mautner4b71aa12012-12-27 17:20:01 -08002403 if (transit == TRANSIT_EXIT
2404 || transit == TRANSIT_HIDE) {
Jorim Jaggi380ecb82014-03-14 17:25:20 +01002405 return isKeyguard ? -1 : R.anim.dock_top_exit;
Craig Mautner4b71aa12012-12-27 17:20:01 -08002406 } else if (transit == TRANSIT_ENTER
2407 || transit == TRANSIT_SHOW) {
Jorim Jaggi380ecb82014-03-14 17:25:20 +01002408 return isKeyguard ? -1 : R.anim.dock_top_enter;
Dianne Hackbornf87d1962012-04-04 12:48:24 -07002409 }
2410 } else if (win == mNavigationBar) {
2411 // This can be on either the bottom or the right.
2412 if (mNavigationBarOnBottom) {
Craig Mautner4b71aa12012-12-27 17:20:01 -08002413 if (transit == TRANSIT_EXIT
2414 || transit == TRANSIT_HIDE) {
Dianne Hackbornf87d1962012-04-04 12:48:24 -07002415 return R.anim.dock_bottom_exit;
Craig Mautner4b71aa12012-12-27 17:20:01 -08002416 } else if (transit == TRANSIT_ENTER
2417 || transit == TRANSIT_SHOW) {
Dianne Hackbornf87d1962012-04-04 12:48:24 -07002418 return R.anim.dock_bottom_enter;
2419 }
2420 } else {
Craig Mautner4b71aa12012-12-27 17:20:01 -08002421 if (transit == TRANSIT_EXIT
2422 || transit == TRANSIT_HIDE) {
Dianne Hackbornf87d1962012-04-04 12:48:24 -07002423 return R.anim.dock_right_exit;
Craig Mautner4b71aa12012-12-27 17:20:01 -08002424 } else if (transit == TRANSIT_ENTER
2425 || transit == TRANSIT_SHOW) {
Dianne Hackbornf87d1962012-04-04 12:48:24 -07002426 return R.anim.dock_right_enter;
2427 }
2428 }
Craig Mautner4b71aa12012-12-27 17:20:01 -08002429 }
2430
2431 if (transit == TRANSIT_PREVIEW_DONE) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002432 if (win.hasAppShownWindows()) {
2433 if (PRINT_ANIM) Log.i(TAG, "**** STARTING EXIT");
2434 return com.android.internal.R.anim.app_starting_exit;
2435 }
Dianne Hackborn7ad44382012-10-18 17:46:00 -07002436 } else if (win.getAttrs().type == TYPE_DREAM && mDreamingLockscreen
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07002437 && transit == TRANSIT_ENTER) {
2438 // Special case: we are animating in a dream, while the keyguard
2439 // is shown. We don't want an animation on the dream, because
2440 // we need it shown immediately with the keyguard animating away
2441 // to reveal it.
2442 return -1;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002443 }
2444
2445 return 0;
2446 }
2447
Craig Mautner3c174372013-02-21 17:54:37 -08002448 @Override
2449 public void selectRotationAnimationLw(int anim[]) {
2450 if (PRINT_ANIM) Slog.i(TAG, "selectRotationAnimation mTopFullscreen="
2451 + mTopFullscreenOpaqueWindowState + " rotationAnimation="
2452 + (mTopFullscreenOpaqueWindowState == null ?
2453 "0" : mTopFullscreenOpaqueWindowState.getAttrs().rotationAnimation));
2454 if (mTopFullscreenOpaqueWindowState != null && mTopIsFullscreen) {
2455 switch (mTopFullscreenOpaqueWindowState.getAttrs().rotationAnimation) {
2456 case ROTATION_ANIMATION_CROSSFADE:
2457 anim[0] = R.anim.rotation_animation_xfade_exit;
2458 anim[1] = R.anim.rotation_animation_enter;
2459 break;
2460 case ROTATION_ANIMATION_JUMPCUT:
2461 anim[0] = R.anim.rotation_animation_jump_exit;
2462 anim[1] = R.anim.rotation_animation_enter;
2463 break;
2464 case ROTATION_ANIMATION_ROTATE:
2465 default:
2466 anim[0] = anim[1] = 0;
2467 break;
2468 }
2469 } else {
2470 anim[0] = anim[1] = 0;
2471 }
2472 }
2473
2474 @Override
2475 public boolean validateRotationAnimationLw(int exitAnimId, int enterAnimId,
2476 boolean forceDefault) {
2477 switch (exitAnimId) {
2478 case R.anim.rotation_animation_xfade_exit:
2479 case R.anim.rotation_animation_jump_exit:
2480 // These are the only cases that matter.
2481 if (forceDefault) {
2482 return false;
2483 }
2484 int anim[] = new int[2];
2485 selectRotationAnimationLw(anim);
2486 return (exitAnimId == anim[0] && enterAnimId == anim[1]);
2487 default:
2488 return true;
2489 }
2490 }
2491
2492 @Override
Jorim Jaggi84a3e7a2014-08-13 17:58:58 +02002493 public Animation createForceHideEnterAnimation(boolean onWallpaper,
2494 boolean goingToNotificationShade) {
2495 if (goingToNotificationShade) {
2496 return AnimationUtils.loadAnimation(mContext, R.anim.lock_screen_behind_enter_fade_in);
Craig Mautnerb8340802014-11-04 15:32:57 -08002497 }
Craig Mautner276a6eb2014-11-04 15:32:57 -08002498
2499 AnimationSet set = (AnimationSet) AnimationUtils.loadAnimation(mContext, onWallpaper ?
2500 R.anim.lock_screen_behind_enter_wallpaper :
2501 R.anim.lock_screen_behind_enter);
2502
2503 // TODO: Use XML interpolators when we have log interpolators available in XML.
2504 final List<Animation> animations = set.getAnimations();
2505 for (int i = animations.size() - 1; i >= 0; --i) {
2506 animations.get(i).setInterpolator(mLogDecelerateInterpolator);
2507 }
2508
2509 return set;
Jorim Jaggi76a16232014-08-08 17:00:47 +02002510 }
2511
2512
2513 @Override
Jorim Jaggi84a3e7a2014-08-13 17:58:58 +02002514 public Animation createForceHideWallpaperExitAnimation(boolean goingToNotificationShade) {
2515 if (goingToNotificationShade) {
2516 return null;
2517 } else {
2518 return AnimationUtils.loadAnimation(mContext, R.anim.lock_screen_wallpaper_exit);
2519 }
Dianne Hackborn01ad2f42009-09-24 19:24:56 -07002520 }
John Spurlockc8b46ca2013-04-08 12:59:26 -04002521
2522 private static void awakenDreams() {
2523 IDreamManager dreamManager = getDreamManager();
2524 if (dreamManager != null) {
2525 try {
2526 dreamManager.awaken();
2527 } catch (RemoteException e) {
2528 // fine, stay asleep then
2529 }
2530 }
2531 }
2532
2533 static IDreamManager getDreamManager() {
2534 return IDreamManager.Stub.asInterface(
2535 ServiceManager.checkService(DreamService.DREAM_SERVICE));
2536 }
2537
Tyler Gunnef9f6f92014-09-12 22:16:17 -07002538 TelecomManager getTelecommService() {
2539 return (TelecomManager) mContext.getSystemService(Context.TELECOM_SERVICE);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002540 }
2541
Jeff Brown4d396052010-10-29 21:50:21 -07002542 static IAudioService getAudioService() {
2543 IAudioService audioService = IAudioService.Stub.asInterface(
2544 ServiceManager.checkService(Context.AUDIO_SERVICE));
2545 if (audioService == null) {
2546 Log.w(TAG, "Unable to find IAudioService interface.");
2547 }
2548 return audioService;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002549 }
2550
2551 boolean keyguardOn() {
Jim Millerab954542014-10-10 18:21:49 -07002552 return isKeyguardShowingAndNotOccluded() || inKeyguardRestrictedKeyInputMode();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002553 }
2554
2555 private static final int[] WINDOW_TYPES_WHERE_HOME_DOESNT_WORK = {
2556 WindowManager.LayoutParams.TYPE_SYSTEM_ALERT,
2557 WindowManager.LayoutParams.TYPE_SYSTEM_ERROR,
2558 };
2559
2560 /** {@inheritDoc} */
Jeff Brown00fa7bd2010-07-02 15:37:36 -07002561 @Override
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002562 public long interceptKeyBeforeDispatching(WindowState win, KeyEvent event, int policyFlags) {
Jeff Brown00fa7bd2010-07-02 15:37:36 -07002563 final boolean keyguardOn = keyguardOn();
Jeff Brown1f245102010-11-18 20:53:46 -08002564 final int keyCode = event.getKeyCode();
2565 final int repeatCount = event.getRepeatCount();
2566 final int metaState = event.getMetaState();
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002567 final int flags = event.getFlags();
Jeff Brown1f245102010-11-18 20:53:46 -08002568 final boolean down = event.getAction() == KeyEvent.ACTION_DOWN;
2569 final boolean canceled = event.isCanceled();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002570
Jeff Brown40013652012-05-16 21:22:36 -07002571 if (DEBUG_INPUT) {
Jeff Brown00fa7bd2010-07-02 15:37:36 -07002572 Log.d(TAG, "interceptKeyTi keyCode=" + keyCode + " down=" + down + " repeatCount="
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002573 + repeatCount + " keyguardOn=" + keyguardOn + " mHomePressed=" + mHomePressed
2574 + " canceled=" + canceled);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002575 }
2576
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002577 // If we think we might have a volume down & power key chord on the way
2578 // but we're not sure, then tell the dispatcher to wait a little while and
2579 // try again later before dispatching.
Christopher Tatee90585f2012-03-05 18:56:25 -08002580 if (mScreenshotChordEnabled && (flags & KeyEvent.FLAG_FALLBACK) == 0) {
Jeff Brown13f00f02014-10-31 14:45:50 -07002581 if (mScreenshotChordVolumeDownKeyTriggered && !mScreenshotChordPowerKeyTriggered) {
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002582 final long now = SystemClock.uptimeMillis();
Jeff Brown13f00f02014-10-31 14:45:50 -07002583 final long timeoutTime = mScreenshotChordVolumeDownKeyTime
2584 + SCREENSHOT_CHORD_DEBOUNCE_DELAY_MILLIS;
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002585 if (now < timeoutTime) {
2586 return timeoutTime - now;
2587 }
2588 }
2589 if (keyCode == KeyEvent.KEYCODE_VOLUME_DOWN
Jeff Brown13f00f02014-10-31 14:45:50 -07002590 && mScreenshotChordVolumeDownKeyConsumed) {
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002591 if (!down) {
Jeff Brown13f00f02014-10-31 14:45:50 -07002592 mScreenshotChordVolumeDownKeyConsumed = false;
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002593 }
2594 return -1;
2595 }
2596 }
2597
Michael Wright6a62e552014-06-03 19:19:48 -07002598 // Cancel any pending meta actions if we see any other keys being pressed between the down
2599 // of the meta key and its corresponding up.
Michael Wright251e35d2014-08-22 15:40:27 -07002600 if (mPendingMetaAction && !KeyEvent.isMetaKey(keyCode)) {
Michael Wright6a62e552014-06-03 19:19:48 -07002601 mPendingMetaAction = false;
2602 }
2603
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002604 // First we always handle the home key here, so applications
2605 // can never break it, although if keyguard is on, we do let
2606 // it handle it, because that gives us the correct 5 second
2607 // timeout.
Jeff Brown00fa7bd2010-07-02 15:37:36 -07002608 if (keyCode == KeyEvent.KEYCODE_HOME) {
Michael Jurka7f2668c2012-03-27 07:49:52 -07002609
Jeff Brown49ed71d2010-12-06 17:13:33 -08002610 // If we have released the home key, and didn't do anything else
2611 // while it was pressed, then it is time to go home!
Michael Jurka7f2668c2012-03-27 07:49:52 -07002612 if (!down) {
Jeff Browncaca8812013-05-09 13:34:33 -07002613 cancelPreloadRecentApps();
2614
Jeff Brown49ed71d2010-12-06 17:13:33 -08002615 mHomePressed = false;
Jeff Browncaca8812013-05-09 13:34:33 -07002616 if (mHomeConsumed) {
2617 mHomeConsumed = false;
Michael Jurka7f2668c2012-03-27 07:49:52 -07002618 return -1;
Jeff Brown49ed71d2010-12-06 17:13:33 -08002619 }
Jeff Browncaca8812013-05-09 13:34:33 -07002620
2621 if (canceled) {
2622 Log.i(TAG, "Ignoring HOME; event canceled.");
2623 return -1;
2624 }
2625
Yorke Lee4f803242014-12-15 23:22:06 +00002626 // If an incoming call is ringing, HOME is totally disabled.
2627 // (The user is already on the InCallUI at this point,
2628 // and his ONLY options are to answer or reject the call.)
2629 TelecomManager telecomManager = getTelecommService();
2630 if (telecomManager != null && telecomManager.isRinging()) {
2631 Log.i(TAG, "Ignoring HOME; there's a ringing incoming call.");
2632 return -1;
2633 }
2634
Jeff Browncaca8812013-05-09 13:34:33 -07002635 // Delay handling home if a double-tap is possible.
2636 if (mDoubleTapOnHomeBehavior != DOUBLE_TAP_HOME_NOTHING) {
2637 mHandler.removeCallbacks(mHomeDoubleTapTimeoutRunnable); // just in case
2638 mHomeDoubleTapPending = true;
2639 mHandler.postDelayed(mHomeDoubleTapTimeoutRunnable,
2640 ViewConfiguration.getDoubleTapTimeout());
2641 return -1;
2642 }
2643
Jeff Brown13f00f02014-10-31 14:45:50 -07002644 handleShortPressOnHome();
Jeff Browncaca8812013-05-09 13:34:33 -07002645 return -1;
Jeff Brown49ed71d2010-12-06 17:13:33 -08002646 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002647
2648 // If a system window has focus, then it doesn't make sense
2649 // right now to interact with applications.
2650 WindowManager.LayoutParams attrs = win != null ? win.getAttrs() : null;
2651 if (attrs != null) {
2652 final int type = attrs.type;
Jorim Jaggi380ecb82014-03-14 17:25:20 +01002653 if (type == WindowManager.LayoutParams.TYPE_KEYGUARD_SCRIM
2654 || type == WindowManager.LayoutParams.TYPE_KEYGUARD_DIALOG
2655 || (attrs.privateFlags & PRIVATE_FLAG_KEYGUARD) != 0) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002656 // the "app" is keyguard, so give it the key
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002657 return 0;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002658 }
2659 final int typeCount = WINDOW_TYPES_WHERE_HOME_DOESNT_WORK.length;
2660 for (int i=0; i<typeCount; i++) {
2661 if (type == WINDOW_TYPES_WHERE_HOME_DOESNT_WORK[i]) {
2662 // don't do anything, but also don't pass it to the app
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002663 return -1;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002664 }
2665 }
2666 }
Jeff Browncaca8812013-05-09 13:34:33 -07002667
2668 // Remember that home is pressed and handle special actions.
2669 if (repeatCount == 0) {
2670 mHomePressed = true;
2671 if (mHomeDoubleTapPending) {
2672 mHomeDoubleTapPending = false;
2673 mHandler.removeCallbacks(mHomeDoubleTapTimeoutRunnable);
2674 handleDoubleTapOnHome();
2675 } else if (mLongPressOnHomeBehavior == LONG_PRESS_HOME_RECENT_SYSTEM_UI
2676 || mDoubleTapOnHomeBehavior == DOUBLE_TAP_HOME_RECENT_SYSTEM_UI) {
2677 preloadRecentApps();
Michael Jurka7f2668c2012-03-27 07:49:52 -07002678 }
Jeff Browncaca8812013-05-09 13:34:33 -07002679 } else if ((event.getFlags() & KeyEvent.FLAG_LONG_PRESS) != 0) {
2680 if (!keyguardOn) {
Tim Kilbourn0e5f1102015-06-05 16:18:09 -07002681 handleLongPressOnHome(event.getDeviceId());
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002682 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002683 }
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002684 return -1;
Jeff Brown00fa7bd2010-07-02 15:37:36 -07002685 } else if (keyCode == KeyEvent.KEYCODE_MENU) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002686 // Hijack modified menu keys for debugging features
2687 final int chordBug = KeyEvent.META_SHIFT_ON;
2688
2689 if (down && repeatCount == 0) {
Jeff Brown00fa7bd2010-07-02 15:37:36 -07002690 if (mEnableShiftMenuBugReports && (metaState & chordBug) == chordBug) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002691 Intent intent = new Intent(Intent.ACTION_BUG_REPORT);
Dianne Hackborn5ac72a22012-08-29 18:32:08 -07002692 mContext.sendOrderedBroadcastAsUser(intent, UserHandle.CURRENT,
2693 null, null, null, 0, null, null);
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002694 return -1;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002695 } else if (SHOW_PROCESSES_ON_ALT_MENU &&
Jeff Brown00fa7bd2010-07-02 15:37:36 -07002696 (metaState & KeyEvent.META_ALT_ON) == KeyEvent.META_ALT_ON) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002697 Intent service = new Intent();
2698 service.setClassName(mContext, "com.android.server.LoadAverageService");
2699 ContentResolver res = mContext.getContentResolver();
Jeff Sharkey8d9a1f62012-10-18 15:38:14 -07002700 boolean shown = Settings.Global.getInt(
2701 res, Settings.Global.SHOW_PROCESSES, 0) != 0;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002702 if (!shown) {
2703 mContext.startService(service);
2704 } else {
2705 mContext.stopService(service);
2706 }
Jeff Sharkey8d9a1f62012-10-18 15:38:14 -07002707 Settings.Global.putInt(
2708 res, Settings.Global.SHOW_PROCESSES, shown ? 0 : 1);
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002709 return -1;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002710 }
2711 }
Jeff Brown00fa7bd2010-07-02 15:37:36 -07002712 } else if (keyCode == KeyEvent.KEYCODE_SEARCH) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002713 if (down) {
2714 if (repeatCount == 0) {
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002715 mSearchKeyShortcutPending = true;
2716 mConsumeSearchKeyUp = false;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002717 }
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002718 } else {
2719 mSearchKeyShortcutPending = false;
2720 if (mConsumeSearchKeyUp) {
2721 mConsumeSearchKeyUp = false;
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002722 return -1;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002723 }
2724 }
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002725 return 0;
Jeff Brown49ed71d2010-12-06 17:13:33 -08002726 } else if (keyCode == KeyEvent.KEYCODE_APP_SWITCH) {
Michael Wrightc9ebea72013-01-16 19:25:02 -08002727 if (!keyguardOn) {
Jeff Browncaca8812013-05-09 13:34:33 -07002728 if (down && repeatCount == 0) {
2729 preloadRecentApps();
2730 } else if (!down) {
2731 toggleRecentApps();
Michael Wrightc9ebea72013-01-16 19:25:02 -08002732 }
Jeff Brown49ed71d2010-12-06 17:13:33 -08002733 }
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002734 return -1;
Jun Mukaid21b3c82015-04-23 14:09:34 -07002735 } else if (keyCode == KeyEvent.KEYCODE_N && event.isMetaPressed()) {
2736 if (down) {
2737 IStatusBarService service = getStatusBarService();
2738 if (service != null) {
2739 try {
2740 service.expandNotificationsPanel();
2741 } catch (RemoteException e) {
2742 // do nothing.
2743 }
2744 }
2745 }
Jeff Brownde7a8ea2012-06-13 18:28:57 -07002746 } else if (keyCode == KeyEvent.KEYCODE_ASSIST) {
2747 if (down) {
2748 if (repeatCount == 0) {
2749 mAssistKeyLongPressed = false;
2750 } else if (repeatCount == 1) {
2751 mAssistKeyLongPressed = true;
2752 if (!keyguardOn) {
2753 launchAssistLongPressAction();
2754 }
2755 }
2756 } else {
2757 if (mAssistKeyLongPressed) {
2758 mAssistKeyLongPressed = false;
2759 } else {
2760 if (!keyguardOn) {
Tim Kilbourn0e5f1102015-06-05 16:18:09 -07002761 launchAssistAction(null, event.getDeviceId());
Jeff Brownde7a8ea2012-06-13 18:28:57 -07002762 }
2763 }
2764 }
2765 return -1;
Michael Wrightdc63f7b2014-08-21 19:05:21 -07002766 } else if (keyCode == KeyEvent.KEYCODE_VOICE_ASSIST) {
2767 if (!down) {
2768 Intent voiceIntent;
Michael Wright869a67c2014-08-26 19:33:06 -07002769 if (!keyguardOn) {
Michael Wrightdc63f7b2014-08-21 19:05:21 -07002770 voiceIntent = new Intent(RecognizerIntent.ACTION_WEB_SEARCH);
2771 } else {
Dianne Hackbornb6683c42015-06-18 17:40:33 -07002772 IDeviceIdleController dic = IDeviceIdleController.Stub.asInterface(
2773 ServiceManager.getService(Context.DEVICE_IDLE_CONTROLLER));
2774 if (dic != null) {
2775 try {
2776 dic.exitIdle("voice-search");
2777 } catch (RemoteException e) {
2778 }
2779 }
Michael Wrightdc63f7b2014-08-21 19:05:21 -07002780 voiceIntent = new Intent(RecognizerIntent.ACTION_VOICE_SEARCH_HANDS_FREE);
Michael Wright869a67c2014-08-26 19:33:06 -07002781 voiceIntent.putExtra(RecognizerIntent.EXTRA_SECURE, true);
Michael Wrightdc63f7b2014-08-21 19:05:21 -07002782 }
Bart Sears8b1c27c2015-03-18 23:51:02 +00002783 startActivityAsUser(voiceIntent, UserHandle.CURRENT_OR_SELF);
Michael Wrightdc63f7b2014-08-21 19:05:21 -07002784 }
Jeff Sharkey2991fa32012-12-05 18:06:43 -08002785 } else if (keyCode == KeyEvent.KEYCODE_SYSRQ) {
2786 if (down && repeatCount == 0) {
2787 mHandler.post(mScreenshotRunnable);
2788 }
2789 return -1;
Michael Wrightb854e242013-02-05 17:54:02 -08002790 } else if (keyCode == KeyEvent.KEYCODE_BRIGHTNESS_UP
2791 || keyCode == KeyEvent.KEYCODE_BRIGHTNESS_DOWN) {
2792 if (down) {
2793 int direction = keyCode == KeyEvent.KEYCODE_BRIGHTNESS_UP ? 1 : -1;
2794
2795 // Disable autobrightness if it's on
2796 int auto = Settings.System.getIntForUser(
2797 mContext.getContentResolver(),
2798 Settings.System.SCREEN_BRIGHTNESS_MODE,
2799 Settings.System.SCREEN_BRIGHTNESS_MODE_MANUAL,
2800 UserHandle.USER_CURRENT_OR_SELF);
2801 if (auto != 0) {
2802 Settings.System.putIntForUser(mContext.getContentResolver(),
2803 Settings.System.SCREEN_BRIGHTNESS_MODE,
2804 Settings.System.SCREEN_BRIGHTNESS_MODE_MANUAL,
2805 UserHandle.USER_CURRENT_OR_SELF);
2806 }
2807
2808 int min = mPowerManager.getMinimumScreenBrightnessSetting();
2809 int max = mPowerManager.getMaximumScreenBrightnessSetting();
2810 int step = (max - min + BRIGHTNESS_STEPS - 1) / BRIGHTNESS_STEPS * direction;
2811 int brightness = Settings.System.getIntForUser(mContext.getContentResolver(),
2812 Settings.System.SCREEN_BRIGHTNESS,
2813 mPowerManager.getDefaultScreenBrightnessSetting(),
2814 UserHandle.USER_CURRENT_OR_SELF);
2815 brightness += step;
2816 // Make sure we don't go beyond the limits.
2817 brightness = Math.min(max, brightness);
2818 brightness = Math.max(min, brightness);
2819
2820 Settings.System.putIntForUser(mContext.getContentResolver(),
2821 Settings.System.SCREEN_BRIGHTNESS, brightness,
2822 UserHandle.USER_CURRENT_OR_SELF);
Bart Sears8b1c27c2015-03-18 23:51:02 +00002823 startActivityAsUser(new Intent(Intent.ACTION_SHOW_BRIGHTNESS_DIALOG),
Alan Viverette5a399492014-07-14 16:19:38 -07002824 UserHandle.CURRENT_OR_SELF);
Michael Wrightb854e242013-02-05 17:54:02 -08002825 }
2826 return -1;
Michael Wrightce0c13a2014-07-30 10:49:21 -07002827 } else if (KeyEvent.isMetaKey(keyCode)) {
Michael Wright6a62e552014-06-03 19:19:48 -07002828 if (down) {
2829 mPendingMetaAction = true;
2830 } else if (mPendingMetaAction) {
Tim Kilbourn0e5f1102015-06-05 16:18:09 -07002831 launchAssistAction(Intent.EXTRA_ASSIST_INPUT_HINT_KEYBOARD, event.getDeviceId());
Michael Wright6a62e552014-06-03 19:19:48 -07002832 }
2833 return -1;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002834 }
Jeff Browncaab4d02010-12-09 22:13:41 -08002835
Jeff Brownc1fb48d2010-12-08 16:52:09 -08002836 // Shortcuts are invoked through Search+key, so intercept those here
Jeff Browncaab4d02010-12-09 22:13:41 -08002837 // Any printing key that is chorded with Search should be consumed
2838 // even if no shortcut was invoked. This prevents text from being
2839 // inadvertently inserted when using a keyboard that has built-in macro
2840 // shortcut keys (that emit Search+x) and some of them are not registered.
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002841 if (mSearchKeyShortcutPending) {
Jeff Browncaab4d02010-12-09 22:13:41 -08002842 final KeyCharacterMap kcm = event.getKeyCharacterMap();
2843 if (kcm.isPrintingKey(keyCode)) {
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002844 mConsumeSearchKeyUp = true;
2845 mSearchKeyShortcutPending = false;
Jeff Browncaab4d02010-12-09 22:13:41 -08002846 if (down && repeatCount == 0 && !keyguardOn) {
2847 Intent shortcutIntent = mShortcutManager.getIntent(kcm, keyCode, metaState);
2848 if (shortcutIntent != null) {
2849 shortcutIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
Jeff Brownf0a3cc52011-01-26 18:42:46 -08002850 try {
Bart Sears8b1c27c2015-03-18 23:51:02 +00002851 startActivityAsUser(shortcutIntent, UserHandle.CURRENT);
Jeff Brownf0a3cc52011-01-26 18:42:46 -08002852 } catch (ActivityNotFoundException ex) {
2853 Slog.w(TAG, "Dropping shortcut key combination because "
2854 + "the activity to which it is registered was not found: "
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002855 + "SEARCH+" + KeyEvent.keyCodeToString(keyCode), ex);
Jeff Brownf0a3cc52011-01-26 18:42:46 -08002856 }
Jeff Browncaab4d02010-12-09 22:13:41 -08002857 } else {
2858 Slog.i(TAG, "Dropping unregistered shortcut key combination: "
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002859 + "SEARCH+" + KeyEvent.keyCodeToString(keyCode));
Jeff Brown49ed71d2010-12-06 17:13:33 -08002860 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002861 }
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002862 return -1;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002863 }
2864 }
2865
Jeff Brown68b909d2011-12-07 16:36:01 -08002866 // Invoke shortcuts using Meta.
Jeff Brown602ab322012-05-16 13:33:47 -07002867 if (down && repeatCount == 0 && !keyguardOn
Jeff Brown68b909d2011-12-07 16:36:01 -08002868 && (metaState & KeyEvent.META_META_ON) != 0) {
2869 final KeyCharacterMap kcm = event.getKeyCharacterMap();
Jeff Brown602ab322012-05-16 13:33:47 -07002870 if (kcm.isPrintingKey(keyCode)) {
2871 Intent shortcutIntent = mShortcutManager.getIntent(kcm, keyCode,
2872 metaState & ~(KeyEvent.META_META_ON
2873 | KeyEvent.META_META_LEFT_ON | KeyEvent.META_META_RIGHT_ON));
2874 if (shortcutIntent != null) {
2875 shortcutIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
2876 try {
Bart Sears8b1c27c2015-03-18 23:51:02 +00002877 startActivityAsUser(shortcutIntent, UserHandle.CURRENT);
Jeff Brown602ab322012-05-16 13:33:47 -07002878 } catch (ActivityNotFoundException ex) {
2879 Slog.w(TAG, "Dropping shortcut key combination because "
2880 + "the activity to which it is registered was not found: "
2881 + "META+" + KeyEvent.keyCodeToString(keyCode), ex);
2882 }
2883 return -1;
Jeff Brown68b909d2011-12-07 16:36:01 -08002884 }
Jeff Brown68b909d2011-12-07 16:36:01 -08002885 }
2886 }
2887
Jeff Brown6651a632011-11-28 12:59:11 -08002888 // Handle application launch keys.
Jeff Brown602ab322012-05-16 13:33:47 -07002889 if (down && repeatCount == 0 && !keyguardOn) {
Jeff Brown6651a632011-11-28 12:59:11 -08002890 String category = sApplicationLaunchKeyCategories.get(keyCode);
2891 if (category != null) {
Dianne Hackbornf5b86712011-12-05 17:42:41 -08002892 Intent intent = Intent.makeMainSelectorActivity(Intent.ACTION_MAIN, category);
Jeff Brown6651a632011-11-28 12:59:11 -08002893 intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
2894 try {
Bart Sears8b1c27c2015-03-18 23:51:02 +00002895 startActivityAsUser(intent, UserHandle.CURRENT);
Jeff Brown6651a632011-11-28 12:59:11 -08002896 } catch (ActivityNotFoundException ex) {
2897 Slog.w(TAG, "Dropping application launch key because "
2898 + "the activity to which it is registered was not found: "
2899 + "keyCode=" + keyCode + ", category=" + category, ex);
2900 }
Jeff Brown68b909d2011-12-07 16:36:01 -08002901 return -1;
Jeff Brown6651a632011-11-28 12:59:11 -08002902 }
2903 }
2904
Michael Wright61c46752014-08-21 16:57:33 -07002905 // Display task switcher for ALT-TAB.
Jeff Brown68b909d2011-12-07 16:36:01 -08002906 if (down && repeatCount == 0 && keyCode == KeyEvent.KEYCODE_TAB) {
Winson Chung1e8d71b2014-05-16 17:05:22 -07002907 if (mRecentAppsHeldModifiers == 0 && !keyguardOn) {
Jeff Brown68b909d2011-12-07 16:36:01 -08002908 final int shiftlessModifiers = event.getModifiers() & ~KeyEvent.META_SHIFT_MASK;
Michael Wright61c46752014-08-21 16:57:33 -07002909 if (KeyEvent.metaStateHasModifiers(shiftlessModifiers, KeyEvent.META_ALT_ON)) {
Winson Chung1e8d71b2014-05-16 17:05:22 -07002910 mRecentAppsHeldModifiers = shiftlessModifiers;
2911 showRecentApps(true);
Jeff Brown68b909d2011-12-07 16:36:01 -08002912 return -1;
2913 }
2914 }
Winson Chung1e8d71b2014-05-16 17:05:22 -07002915 } else if (!down && mRecentAppsHeldModifiers != 0
2916 && (metaState & mRecentAppsHeldModifiers) == 0) {
2917 mRecentAppsHeldModifiers = 0;
Winson Chungcdcd4872014-08-05 18:00:13 -07002918 hideRecentApps(true, false);
Jeff Brown68b909d2011-12-07 16:36:01 -08002919 }
2920
Jeff Browncf39bdf2012-05-18 14:41:19 -07002921 // Handle keyboard language switching.
2922 if (down && repeatCount == 0
2923 && (keyCode == KeyEvent.KEYCODE_LANGUAGE_SWITCH
2924 || (keyCode == KeyEvent.KEYCODE_SPACE
2925 && (metaState & KeyEvent.META_CTRL_MASK) != 0))) {
2926 int direction = (metaState & KeyEvent.META_SHIFT_MASK) != 0 ? -1 : 1;
2927 mWindowManagerFuncs.switchKeyboardLayout(event.getDeviceId(), direction);
2928 return -1;
2929 }
2930 if (mLanguageSwitchKeyPressed && !down
2931 && (keyCode == KeyEvent.KEYCODE_LANGUAGE_SWITCH
2932 || keyCode == KeyEvent.KEYCODE_SPACE)) {
2933 mLanguageSwitchKeyPressed = false;
2934 return -1;
2935 }
2936
Jeff Brown13f00f02014-10-31 14:45:50 -07002937 if (isValidGlobalKey(keyCode)
2938 && mGlobalKeyManager.handleGlobalKey(mContext, keyCode, event)) {
Justin Kohd378ad72013-04-01 12:18:26 -07002939 return -1;
2940 }
2941
Michael Wright6a62e552014-06-03 19:19:48 -07002942 // Reserve all the META modifier combos for system behavior
Michael Wrightce0c13a2014-07-30 10:49:21 -07002943 if ((metaState & KeyEvent.META_META_ON) != 0) {
Michael Wright6a62e552014-06-03 19:19:48 -07002944 return -1;
2945 }
2946
Jeff Brown68b909d2011-12-07 16:36:01 -08002947 // Let the application handle the key.
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002948 return 0;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002949 }
2950
Jeff Brown3915bb82010-11-05 15:02:16 -07002951 /** {@inheritDoc} */
2952 @Override
Jeff Brown49ed71d2010-12-06 17:13:33 -08002953 public KeyEvent dispatchUnhandledKey(WindowState win, KeyEvent event, int policyFlags) {
Jeff Brown54875002011-04-06 15:33:01 -07002954 // Note: This method is only called if the initial down was unhandled.
Jeff Brown40013652012-05-16 21:22:36 -07002955 if (DEBUG_INPUT) {
Jeff Brown1f245102010-11-18 20:53:46 -08002956 Slog.d(TAG, "Unhandled key: win=" + win + ", action=" + event.getAction()
2957 + ", flags=" + event.getFlags()
2958 + ", keyCode=" + event.getKeyCode()
2959 + ", scanCode=" + event.getScanCode()
2960 + ", metaState=" + event.getMetaState()
2961 + ", repeatCount=" + event.getRepeatCount()
2962 + ", policyFlags=" + policyFlags);
Jeff Brown3915bb82010-11-05 15:02:16 -07002963 }
Jeff Brown49ed71d2010-12-06 17:13:33 -08002964
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002965 KeyEvent fallbackEvent = null;
Jeff Brown49ed71d2010-12-06 17:13:33 -08002966 if ((event.getFlags() & KeyEvent.FLAG_FALLBACK) == 0) {
2967 final KeyCharacterMap kcm = event.getKeyCharacterMap();
Jeff Brownc1fb48d2010-12-08 16:52:09 -08002968 final int keyCode = event.getKeyCode();
2969 final int metaState = event.getMetaState();
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002970 final boolean initialDown = event.getAction() == KeyEvent.ACTION_DOWN
2971 && event.getRepeatCount() == 0;
Jeff Brown49ed71d2010-12-06 17:13:33 -08002972
Jeff Brown54875002011-04-06 15:33:01 -07002973 // Check for fallback actions specified by the key character map.
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002974 final FallbackAction fallbackAction;
2975 if (initialDown) {
2976 fallbackAction = kcm.getFallbackAction(keyCode, metaState);
2977 } else {
2978 fallbackAction = mFallbackActions.get(keyCode);
2979 }
2980
2981 if (fallbackAction != null) {
Jeff Brown40013652012-05-16 21:22:36 -07002982 if (DEBUG_INPUT) {
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002983 Slog.d(TAG, "Fallback: keyCode=" + fallbackAction.keyCode
2984 + " metaState=" + Integer.toHexString(fallbackAction.metaState));
Jeff Brown49ed71d2010-12-06 17:13:33 -08002985 }
2986
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002987 final int flags = event.getFlags() | KeyEvent.FLAG_FALLBACK;
2988 fallbackEvent = KeyEvent.obtain(
Jeff Brown49ed71d2010-12-06 17:13:33 -08002989 event.getDownTime(), event.getEventTime(),
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002990 event.getAction(), fallbackAction.keyCode,
2991 event.getRepeatCount(), fallbackAction.metaState,
Jeff Brown49ed71d2010-12-06 17:13:33 -08002992 event.getDeviceId(), event.getScanCode(),
2993 flags, event.getSource(), null);
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002994
2995 if (!interceptFallback(win, fallbackEvent, policyFlags)) {
2996 fallbackEvent.recycle();
2997 fallbackEvent = null;
Jeff Brown49ed71d2010-12-06 17:13:33 -08002998 }
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002999
3000 if (initialDown) {
3001 mFallbackActions.put(keyCode, fallbackAction);
3002 } else if (event.getAction() == KeyEvent.ACTION_UP) {
3003 mFallbackActions.remove(keyCode);
3004 fallbackAction.recycle();
3005 }
Jeff Brown49ed71d2010-12-06 17:13:33 -08003006 }
3007 }
3008
Jeff Brown40013652012-05-16 21:22:36 -07003009 if (DEBUG_INPUT) {
Jeff Brownfd23e3e2012-05-09 13:34:28 -07003010 if (fallbackEvent == null) {
3011 Slog.d(TAG, "No fallback.");
3012 } else {
3013 Slog.d(TAG, "Performing fallback: " + fallbackEvent);
3014 }
Jeff Brown49ed71d2010-12-06 17:13:33 -08003015 }
Jeff Brownfd23e3e2012-05-09 13:34:28 -07003016 return fallbackEvent;
Jeff Brown3915bb82010-11-05 15:02:16 -07003017 }
3018
Jeff Brownfd23e3e2012-05-09 13:34:28 -07003019 private boolean interceptFallback(WindowState win, KeyEvent fallbackEvent, int policyFlags) {
Jeff Brown037c33e2014-04-09 00:31:55 -07003020 int actions = interceptKeyBeforeQueueing(fallbackEvent, policyFlags);
Jeff Brownfd23e3e2012-05-09 13:34:28 -07003021 if ((actions & ACTION_PASS_TO_USER) != 0) {
3022 long delayMillis = interceptKeyBeforeDispatching(
3023 win, fallbackEvent, policyFlags);
3024 if (delayMillis == 0) {
3025 return true;
3026 }
3027 }
3028 return false;
Jeff Brown6f2fba42011-02-19 01:08:02 -08003029 }
3030
Jeff Brownde7a8ea2012-06-13 18:28:57 -07003031 private void launchAssistLongPressAction() {
3032 performHapticFeedbackLw(null, HapticFeedbackConstants.LONG_PRESS, false);
3033 sendCloseSystemWindows(SYSTEM_DIALOG_REASON_ASSIST);
3034
3035 // launch the search activity
3036 Intent intent = new Intent(Intent.ACTION_SEARCH_LONG_PRESS);
3037 intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
3038 try {
RoboErik8a2cfc32014-05-16 11:19:38 -07003039 // TODO: This only stops the factory-installed search manager.
Jim Miller45308b12012-06-18 19:23:39 -07003040 // Need to formalize an API to handle others
Jeff Brownde7a8ea2012-06-13 18:28:57 -07003041 SearchManager searchManager = getSearchManager();
3042 if (searchManager != null) {
3043 searchManager.stopSearch();
3044 }
Bart Sears8b1c27c2015-03-18 23:51:02 +00003045 startActivityAsUser(intent, UserHandle.CURRENT);
Jeff Brownde7a8ea2012-06-13 18:28:57 -07003046 } catch (ActivityNotFoundException e) {
3047 Slog.w(TAG, "No activity to handle assist long press action.", e);
3048 }
3049 }
3050
3051 private void launchAssistAction() {
Tim Kilbourn0e5f1102015-06-05 16:18:09 -07003052 launchAssistAction(null, Integer.MIN_VALUE);
Michael Wright8ab940a2014-09-01 11:01:27 -07003053 }
3054
3055 private void launchAssistAction(String hint) {
Tim Kilbourn0e5f1102015-06-05 16:18:09 -07003056 launchAssistAction(hint, Integer.MIN_VALUE);
3057 }
3058
3059 private void launchAssistAction(String hint, int deviceId) {
Jeff Brownde7a8ea2012-06-13 18:28:57 -07003060 sendCloseSystemWindows(SYSTEM_DIALOG_REASON_ASSIST);
Tim Kilbourn0e5f1102015-06-05 16:18:09 -07003061 Bundle args = null;
3062 if (deviceId > Integer.MIN_VALUE) {
3063 args = new Bundle();
3064 args.putInt(Intent.EXTRA_ASSIST_INPUT_DEVICE_ID, deviceId);
Jeff Brownde7a8ea2012-06-13 18:28:57 -07003065 }
Tim Kilbourn0e5f1102015-06-05 16:18:09 -07003066 ((SearchManager) mContext.getSystemService(Context.SEARCH_SERVICE))
3067 .launchAssistAction(hint, UserHandle.myUserId(), args);
Jeff Brownde7a8ea2012-06-13 18:28:57 -07003068 }
3069
Bart Sears8b1c27c2015-03-18 23:51:02 +00003070 private void startActivityAsUser(Intent intent, UserHandle handle) {
3071 if (isUserSetupComplete()) {
3072 mContext.startActivityAsUser(intent, handle);
3073 } else {
3074 Slog.i(TAG, "Not starting activity because user setup is in progress: " + intent);
3075 }
3076 }
3077
Jeff Brownde7a8ea2012-06-13 18:28:57 -07003078 private SearchManager getSearchManager() {
3079 if (mSearchManager == null) {
3080 mSearchManager = (SearchManager) mContext.getSystemService(Context.SEARCH_SERVICE);
3081 }
3082 return mSearchManager;
3083 }
3084
Jeff Browncaca8812013-05-09 13:34:33 -07003085 private void preloadRecentApps() {
3086 mPreloadedRecentApps = true;
3087 try {
3088 IStatusBarService statusbar = getStatusBarService();
3089 if (statusbar != null) {
3090 statusbar.preloadRecentApps();
3091 }
3092 } catch (RemoteException e) {
3093 Slog.e(TAG, "RemoteException when preloading recent apps", e);
3094 // re-acquire status bar service next time it is needed.
3095 mStatusBarService = null;
3096 }
3097 }
3098
3099 private void cancelPreloadRecentApps() {
3100 if (mPreloadedRecentApps) {
3101 mPreloadedRecentApps = false;
3102 try {
3103 IStatusBarService statusbar = getStatusBarService();
3104 if (statusbar != null) {
3105 statusbar.cancelPreloadRecentApps();
3106 }
3107 } catch (RemoteException e) {
Winson Chung1e8d71b2014-05-16 17:05:22 -07003108 Slog.e(TAG, "RemoteException when cancelling recent apps preload", e);
Jeff Browncaca8812013-05-09 13:34:33 -07003109 // re-acquire status bar service next time it is needed.
3110 mStatusBarService = null;
3111 }
3112 }
3113 }
3114
3115 private void toggleRecentApps() {
3116 mPreloadedRecentApps = false; // preloading no longer needs to be canceled
Jeff Browncaca8812013-05-09 13:34:33 -07003117 try {
3118 IStatusBarService statusbar = getStatusBarService();
3119 if (statusbar != null) {
3120 statusbar.toggleRecentApps();
3121 }
3122 } catch (RemoteException e) {
Winson Chung1e8d71b2014-05-16 17:05:22 -07003123 Slog.e(TAG, "RemoteException when toggling recent apps", e);
3124 // re-acquire status bar service next time it is needed.
3125 mStatusBarService = null;
3126 }
3127 }
3128
Craig Mautner84984fa2014-06-19 11:19:20 -07003129 @Override
3130 public void showRecentApps() {
3131 mHandler.removeMessages(MSG_DISPATCH_SHOW_RECENTS);
3132 mHandler.sendEmptyMessage(MSG_DISPATCH_SHOW_RECENTS);
3133 }
3134
Winson Chung1e8d71b2014-05-16 17:05:22 -07003135 private void showRecentApps(boolean triggeredFromAltTab) {
3136 mPreloadedRecentApps = false; // preloading no longer needs to be canceled
3137 try {
3138 IStatusBarService statusbar = getStatusBarService();
3139 if (statusbar != null) {
3140 statusbar.showRecentApps(triggeredFromAltTab);
3141 }
3142 } catch (RemoteException e) {
Jeff Browncaca8812013-05-09 13:34:33 -07003143 Slog.e(TAG, "RemoteException when showing recent apps", e);
3144 // re-acquire status bar service next time it is needed.
3145 mStatusBarService = null;
3146 }
3147 }
3148
Winson Chungcdcd4872014-08-05 18:00:13 -07003149 private void hideRecentApps(boolean triggeredFromAltTab, boolean triggeredFromHome) {
Winson Chung1e8d71b2014-05-16 17:05:22 -07003150 mPreloadedRecentApps = false; // preloading no longer needs to be canceled
3151 try {
3152 IStatusBarService statusbar = getStatusBarService();
3153 if (statusbar != null) {
Winson Chungcdcd4872014-08-05 18:00:13 -07003154 statusbar.hideRecentApps(triggeredFromAltTab, triggeredFromHome);
Winson Chung1e8d71b2014-05-16 17:05:22 -07003155 }
3156 } catch (RemoteException e) {
3157 Slog.e(TAG, "RemoteException when closing recent apps", e);
3158 // re-acquire status bar service next time it is needed.
3159 mStatusBarService = null;
3160 }
3161 }
3162
Filip Gruszczynskia483a1d2015-03-17 19:06:58 +00003163 void launchHomeFromHotKey() {
Bryce Lee662ed802015-04-10 20:11:39 +00003164 launchHomeFromHotKey(true /* awakenFromDreams */, true /*respectKeyguard*/);
Filip Gruszczynskia483a1d2015-03-17 19:06:58 +00003165 }
3166
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003167 /**
3168 * A home key -> launch home action was detected. Take the appropriate action
3169 * given the situation with the keyguard.
3170 */
Bryce Lee662ed802015-04-10 20:11:39 +00003171 void launchHomeFromHotKey(final boolean awakenFromDreams, final boolean respectKeyguard) {
3172 if (respectKeyguard) {
3173 if (isKeyguardShowingAndNotOccluded()) {
3174 // don't launch home if keyguard showing
3175 return;
3176 }
3177
3178 if (!mHideLockScreen && mKeyguardDelegate.isInputRestricted()) {
3179 // when in keyguard restricted mode, must first verify unlock
3180 // before launching home
3181 mKeyguardDelegate.verifyUnlock(new OnKeyguardExitResult() {
3182 @Override
3183 public void onKeyguardExitResult(boolean success) {
3184 if (success) {
3185 try {
3186 ActivityManagerNative.getDefault().stopAppSwitches();
3187 } catch (RemoteException e) {
3188 }
3189 sendCloseSystemWindows(SYSTEM_DIALOG_REASON_HOME_KEY);
3190 startDockOrHome(true /*fromHomeKey*/, awakenFromDreams);
Dianne Hackborn256dd3b2009-05-19 18:51:21 -07003191 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003192 }
Bryce Lee662ed802015-04-10 20:11:39 +00003193 });
3194 return;
3195 }
3196 }
3197
3198 // no keyguard stuff to worry about, just launch home!
3199 try {
3200 ActivityManagerNative.getDefault().stopAppSwitches();
3201 } catch (RemoteException e) {
3202 }
3203 if (mRecentsVisible) {
3204 // Hide Recents and notify it to launch Home
3205 if (awakenFromDreams) {
3206 awakenDreams();
3207 }
3208 sendCloseSystemWindows(SYSTEM_DIALOG_REASON_HOME_KEY);
3209 hideRecentApps(false, true);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003210 } else {
Bryce Lee662ed802015-04-10 20:11:39 +00003211 // Otherwise, just launch Home
3212 sendCloseSystemWindows(SYSTEM_DIALOG_REASON_HOME_KEY);
3213 startDockOrHome(true /*fromHomeKey*/, awakenFromDreams);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003214 }
3215 }
3216
John Spurlock04db1762013-05-13 12:46:41 -04003217 private final Runnable mClearHideNavigationFlag = new Runnable() {
3218 @Override
3219 public void run() {
3220 synchronized (mWindowManagerFuncs.getWindowManagerLock()) {
3221 // Clear flags.
3222 mForceClearedSystemUiFlags &=
3223 ~View.SYSTEM_UI_FLAG_HIDE_NAVIGATION;
3224 }
3225 mWindowManagerFuncs.reevaluateStatusBarVisibility();
Dianne Hackborne26ab702011-10-16 13:21:33 -07003226 }
3227 };
3228
3229 /**
3230 * Input handler used while nav bar is hidden. Captures any touch on the screen,
3231 * to determine when the nav bar should be shown and prevent applications from
3232 * receiving those touches.
3233 */
Jeff Brown32cbc38552011-12-01 14:01:49 -08003234 final class HideNavInputEventReceiver extends InputEventReceiver {
3235 public HideNavInputEventReceiver(InputChannel inputChannel, Looper looper) {
3236 super(inputChannel, looper);
3237 }
3238
Dianne Hackborndf89e652011-10-06 22:35:11 -07003239 @Override
Jeff Brown32cbc38552011-12-01 14:01:49 -08003240 public void onInputEvent(InputEvent event) {
Dianne Hackborndf89e652011-10-06 22:35:11 -07003241 boolean handled = false;
3242 try {
Jeff Brown4952dfd2011-11-30 19:23:22 -08003243 if (event instanceof MotionEvent
3244 && (event.getSource() & InputDevice.SOURCE_CLASS_POINTER) != 0) {
3245 final MotionEvent motionEvent = (MotionEvent)event;
3246 if (motionEvent.getAction() == MotionEvent.ACTION_DOWN) {
Dianne Hackborndf89e652011-10-06 22:35:11 -07003247 // When the user taps down, we re-show the nav bar.
3248 boolean changed = false;
John Spurlock04db1762013-05-13 12:46:41 -04003249 synchronized (mWindowManagerFuncs.getWindowManagerLock()) {
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07003250 // Any user activity always causes us to show the
3251 // navigation controls, if they had been hidden.
3252 // We also clear the low profile and only content
3253 // flags so that tapping on the screen will atomically
3254 // restore all currently hidden screen decorations.
3255 int newVal = mResettingSystemUiFlags |
3256 View.SYSTEM_UI_FLAG_HIDE_NAVIGATION |
3257 View.SYSTEM_UI_FLAG_LOW_PROFILE |
3258 View.SYSTEM_UI_FLAG_FULLSCREEN;
Dianne Hackborne26ab702011-10-16 13:21:33 -07003259 if (mResettingSystemUiFlags != newVal) {
3260 mResettingSystemUiFlags = newVal;
Dianne Hackborndf89e652011-10-06 22:35:11 -07003261 changed = true;
3262 }
Dianne Hackborne26ab702011-10-16 13:21:33 -07003263 // We don't allow the system's nav bar to be hidden
3264 // again for 1 second, to prevent applications from
3265 // spamming us and keeping it from being shown.
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07003266 newVal = mForceClearedSystemUiFlags |
3267 View.SYSTEM_UI_FLAG_HIDE_NAVIGATION;
Dianne Hackborne26ab702011-10-16 13:21:33 -07003268 if (mForceClearedSystemUiFlags != newVal) {
3269 mForceClearedSystemUiFlags = newVal;
3270 changed = true;
John Spurlock04db1762013-05-13 12:46:41 -04003271 mHandler.postDelayed(mClearHideNavigationFlag, 1000);
Dianne Hackborne26ab702011-10-16 13:21:33 -07003272 }
Dianne Hackborndf89e652011-10-06 22:35:11 -07003273 }
3274 if (changed) {
3275 mWindowManagerFuncs.reevaluateStatusBarVisibility();
3276 }
3277 }
3278 }
3279 } finally {
Jeff Brown32cbc38552011-12-01 14:01:49 -08003280 finishInputEvent(event, handled);
Dianne Hackborndf89e652011-10-06 22:35:11 -07003281 }
3282 }
Jeff Brown32cbc38552011-12-01 14:01:49 -08003283 }
3284 final InputEventReceiver.Factory mHideNavInputEventReceiverFactory =
3285 new InputEventReceiver.Factory() {
3286 @Override
3287 public InputEventReceiver createInputEventReceiver(
3288 InputChannel inputChannel, Looper looper) {
3289 return new HideNavInputEventReceiver(inputChannel, looper);
3290 }
Dianne Hackborndf89e652011-10-06 22:35:11 -07003291 };
3292
3293 @Override
3294 public int adjustSystemUiVisibilityLw(int visibility) {
John Spurlock5b9145b2013-08-20 15:13:47 -04003295 mStatusBarController.adjustSystemUiVisibilityLw(mLastSystemUiFlags, visibility);
3296 mNavigationBarController.adjustSystemUiVisibilityLw(mLastSystemUiFlags, visibility);
Winson Chungd42a6cf2014-06-03 16:24:04 -07003297 mRecentsVisible = (visibility & View.RECENT_APPS_VISIBLE) > 0;
John Spurlock27735a42013-08-14 17:57:38 -04003298
Dianne Hackborndf89e652011-10-06 22:35:11 -07003299 // Reset any bits in mForceClearingStatusBarVisibility that
3300 // are now clear.
Dianne Hackborne26ab702011-10-16 13:21:33 -07003301 mResettingSystemUiFlags &= visibility;
Dianne Hackborndf89e652011-10-06 22:35:11 -07003302 // Clear any bits in the new visibility that are currently being
3303 // force cleared, before reporting it.
Dianne Hackborne26ab702011-10-16 13:21:33 -07003304 return visibility & ~mResettingSystemUiFlags
3305 & ~mForceClearedSystemUiFlags;
Dianne Hackborndf89e652011-10-06 22:35:11 -07003306 }
3307
Craig Mautner69b08182012-09-05 13:07:13 -07003308 @Override
Filip Gruszczynski2987f612015-06-30 15:03:30 -07003309 public void getInsetHintLw(WindowManager.LayoutParams attrs, int displayRotation,
3310 Rect outContentInsets, Rect outStableInsets, Rect outOutsets) {
John Spurlockc6d1c602014-01-17 15:22:06 -05003311 final int fl = PolicyControl.getWindowFlags(null, attrs);
John Spurlock1db8b682014-02-18 11:18:59 -05003312 final int sysuiVis = PolicyControl.getSystemUiVisibility(null, attrs);
3313 final int systemUiVisibility = (sysuiVis | attrs.subtreeSystemUiVisibility);
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07003314
Filip Gruszczynski2987f612015-06-30 15:03:30 -07003315 final boolean useOutsets = outOutsets != null && shouldUseOutsets(attrs, fl);
3316 if (useOutsets) {
3317 int outset = ScreenShapeHelper.getWindowOutsetBottomPx(mContext.getResources());
3318 if (outset > 0) {
3319 if (displayRotation == Surface.ROTATION_0) {
3320 outOutsets.bottom += outset;
3321 } else if (displayRotation == Surface.ROTATION_90) {
3322 outOutsets.right += outset;
3323 } else if (displayRotation == Surface.ROTATION_180) {
3324 outOutsets.top += outset;
3325 } else if (displayRotation == Surface.ROTATION_270) {
3326 outOutsets.left += outset;
3327 }
3328 }
3329 }
3330
Dianne Hackborn5b5cc4d2012-05-16 13:15:00 -07003331 if ((fl & (FLAG_LAYOUT_IN_SCREEN | FLAG_LAYOUT_INSET_DECOR))
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003332 == (FLAG_LAYOUT_IN_SCREEN | FLAG_LAYOUT_INSET_DECOR)) {
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07003333 int availRight, availBottom;
Alan Viverette5a0f4ec2013-10-07 15:10:29 -07003334 if (canHideNavigationBar() &&
Dianne Hackborn5b5cc4d2012-05-16 13:15:00 -07003335 (systemUiVisibility & View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION) != 0) {
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07003336 availRight = mUnrestrictedScreenLeft + mUnrestrictedScreenWidth;
3337 availBottom = mUnrestrictedScreenTop + mUnrestrictedScreenHeight;
3338 } else {
3339 availRight = mRestrictedScreenLeft + mRestrictedScreenWidth;
3340 availBottom = mRestrictedScreenTop + mRestrictedScreenHeight;
3341 }
Dianne Hackborn5b5cc4d2012-05-16 13:15:00 -07003342 if ((systemUiVisibility & View.SYSTEM_UI_FLAG_LAYOUT_STABLE) != 0) {
3343 if ((fl & FLAG_FULLSCREEN) != 0) {
Adrian Roos37d7a682014-11-06 18:15:16 +01003344 outContentInsets.set(mStableFullscreenLeft, mStableFullscreenTop,
Dianne Hackborn5b5cc4d2012-05-16 13:15:00 -07003345 availRight - mStableFullscreenRight,
3346 availBottom - mStableFullscreenBottom);
3347 } else {
Adrian Roos37d7a682014-11-06 18:15:16 +01003348 outContentInsets.set(mStableLeft, mStableTop,
Dianne Hackborn5b5cc4d2012-05-16 13:15:00 -07003349 availRight - mStableRight, availBottom - mStableBottom);
3350 }
Dianne Hackbornc652de82013-02-15 16:32:56 -08003351 } else if ((fl & FLAG_FULLSCREEN) != 0 || (fl & FLAG_LAYOUT_IN_OVERSCAN) != 0) {
Adrian Roos37d7a682014-11-06 18:15:16 +01003352 outContentInsets.setEmpty();
Dianne Hackborn5b5cc4d2012-05-16 13:15:00 -07003353 } else if ((systemUiVisibility & (View.SYSTEM_UI_FLAG_FULLSCREEN
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07003354 | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN)) == 0) {
Adrian Roos37d7a682014-11-06 18:15:16 +01003355 outContentInsets.set(mCurLeft, mCurTop,
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07003356 availRight - mCurRight, availBottom - mCurBottom);
3357 } else {
Adrian Roos37d7a682014-11-06 18:15:16 +01003358 outContentInsets.set(mCurLeft, mCurTop,
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07003359 availRight - mCurRight, availBottom - mCurBottom);
3360 }
Adrian Roos37d7a682014-11-06 18:15:16 +01003361
3362 outStableInsets.set(mStableLeft, mStableTop,
3363 availRight - mStableRight, availBottom - mStableBottom);
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07003364 return;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003365 }
Adrian Roos37d7a682014-11-06 18:15:16 +01003366 outContentInsets.setEmpty();
3367 outStableInsets.setEmpty();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003368 }
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07003369
Filip Gruszczynski2987f612015-06-30 15:03:30 -07003370 private boolean shouldUseOutsets(WindowManager.LayoutParams attrs, int fl) {
3371 return attrs.type == TYPE_WALLPAPER || (fl & (WindowManager.LayoutParams.FLAG_FULLSCREEN
3372 | WindowManager.LayoutParams.FLAG_LAYOUT_IN_OVERSCAN)) != 0;
3373 }
3374
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003375 /** {@inheritDoc} */
Craig Mautner69b08182012-09-05 13:07:13 -07003376 @Override
3377 public void beginLayoutLw(boolean isDefaultDisplay, int displayWidth, int displayHeight,
3378 int displayRotation) {
Filip Gruszczynski2987f612015-06-30 15:03:30 -07003379 mDisplayRotation = displayRotation;
Dianne Hackbornc652de82013-02-15 16:32:56 -08003380 final int overscanLeft, overscanTop, overscanRight, overscanBottom;
3381 if (isDefaultDisplay) {
3382 switch (displayRotation) {
3383 case Surface.ROTATION_90:
3384 overscanLeft = mOverscanTop;
3385 overscanTop = mOverscanRight;
3386 overscanRight = mOverscanBottom;
3387 overscanBottom = mOverscanLeft;
3388 break;
3389 case Surface.ROTATION_180:
3390 overscanLeft = mOverscanRight;
3391 overscanTop = mOverscanBottom;
3392 overscanRight = mOverscanLeft;
3393 overscanBottom = mOverscanTop;
3394 break;
3395 case Surface.ROTATION_270:
3396 overscanLeft = mOverscanBottom;
3397 overscanTop = mOverscanLeft;
3398 overscanRight = mOverscanTop;
3399 overscanBottom = mOverscanRight;
3400 break;
3401 default:
3402 overscanLeft = mOverscanLeft;
3403 overscanTop = mOverscanTop;
3404 overscanRight = mOverscanRight;
3405 overscanBottom = mOverscanBottom;
3406 break;
3407 }
3408 } else {
3409 overscanLeft = 0;
3410 overscanTop = 0;
3411 overscanRight = 0;
3412 overscanBottom = 0;
3413 }
Dianne Hackborn313440842013-02-19 19:22:59 -08003414 mOverscanScreenLeft = mRestrictedOverscanScreenLeft = 0;
3415 mOverscanScreenTop = mRestrictedOverscanScreenTop = 0;
3416 mOverscanScreenWidth = mRestrictedOverscanScreenWidth = displayWidth;
3417 mOverscanScreenHeight = mRestrictedOverscanScreenHeight = displayHeight;
Dianne Hackbornc652de82013-02-15 16:32:56 -08003418 mSystemLeft = 0;
3419 mSystemTop = 0;
3420 mSystemRight = displayWidth;
3421 mSystemBottom = displayHeight;
3422 mUnrestrictedScreenLeft = overscanLeft;
3423 mUnrestrictedScreenTop = overscanTop;
3424 mUnrestrictedScreenWidth = displayWidth - overscanLeft - overscanRight;
3425 mUnrestrictedScreenHeight = displayHeight - overscanTop - overscanBottom;
3426 mRestrictedScreenLeft = mUnrestrictedScreenLeft;
3427 mRestrictedScreenTop = mUnrestrictedScreenTop;
John Spurlockad3e6cb2013-04-30 08:47:43 -04003428 mRestrictedScreenWidth = mSystemGestures.screenWidth = mUnrestrictedScreenWidth;
3429 mRestrictedScreenHeight = mSystemGestures.screenHeight = mUnrestrictedScreenHeight;
Dianne Hackborne30e02f2014-05-27 18:24:45 -07003430 mDockLeft = mContentLeft = mVoiceContentLeft = mStableLeft = mStableFullscreenLeft
Dianne Hackbornc652de82013-02-15 16:32:56 -08003431 = mCurLeft = mUnrestrictedScreenLeft;
Dianne Hackborne30e02f2014-05-27 18:24:45 -07003432 mDockTop = mContentTop = mVoiceContentTop = mStableTop = mStableFullscreenTop
Dianne Hackbornc652de82013-02-15 16:32:56 -08003433 = mCurTop = mUnrestrictedScreenTop;
Dianne Hackborne30e02f2014-05-27 18:24:45 -07003434 mDockRight = mContentRight = mVoiceContentRight = mStableRight = mStableFullscreenRight
Dianne Hackbornc652de82013-02-15 16:32:56 -08003435 = mCurRight = displayWidth - overscanRight;
Dianne Hackborne30e02f2014-05-27 18:24:45 -07003436 mDockBottom = mContentBottom = mVoiceContentBottom = mStableBottom = mStableFullscreenBottom
Dianne Hackbornc652de82013-02-15 16:32:56 -08003437 = mCurBottom = displayHeight - overscanBottom;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003438 mDockLayer = 0x10000000;
Dianne Hackborn5c58de32012-04-28 19:52:37 -07003439 mStatusBarLayer = -1;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003440
Daniel Sandler8956dbb2011-04-22 07:55:02 -04003441 // start with the current dock rect, which will be (0,0,displayWidth,displayHeight)
3442 final Rect pf = mTmpParentFrame;
3443 final Rect df = mTmpDisplayFrame;
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003444 final Rect of = mTmpOverscanFrame;
Daniel Sandler8956dbb2011-04-22 07:55:02 -04003445 final Rect vf = mTmpVisibleFrame;
John Spurlock46646232013-09-30 22:32:42 -04003446 final Rect dcf = mTmpDecorFrame;
Filip Gruszczynski2217f612015-05-26 11:32:08 -07003447 final Rect osf = mTmpOutsetFrame;
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003448 pf.left = df.left = of.left = vf.left = mDockLeft;
3449 pf.top = df.top = of.top = vf.top = mDockTop;
3450 pf.right = df.right = of.right = vf.right = mDockRight;
3451 pf.bottom = df.bottom = of.bottom = vf.bottom = mDockBottom;
John Spurlock46646232013-09-30 22:32:42 -04003452 dcf.setEmpty(); // Decor frame N/A for system bars.
Daniel Sandler8956dbb2011-04-22 07:55:02 -04003453
Craig Mautner69b08182012-09-05 13:07:13 -07003454 if (isDefaultDisplay) {
3455 // For purposes of putting out fake window up to steal focus, we will
3456 // drive nav being hidden only by whether it is requested.
John Spurlocke1f366f2013-08-05 12:22:40 -04003457 final int sysui = mLastSystemUiFlags;
3458 boolean navVisible = (sysui & View.SYSTEM_UI_FLAG_HIDE_NAVIGATION) == 0;
Adrian Roosea562512014-05-05 13:33:03 +02003459 boolean navTranslucent = (sysui
3460 & (View.NAVIGATION_BAR_TRANSLUCENT | View.SYSTEM_UI_TRANSPARENT)) != 0;
John Spurlockf1a36642013-10-12 17:50:42 -04003461 boolean immersive = (sysui & View.SYSTEM_UI_FLAG_IMMERSIVE) != 0;
3462 boolean immersiveSticky = (sysui & View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY) != 0;
3463 boolean navAllowedHidden = immersive || immersiveSticky;
3464 navTranslucent &= !immersiveSticky; // transient trumps translucent
Adrian Roos4fb3ee32014-08-22 19:29:09 +02003465 boolean isKeyguardShowing = isStatusBarKeyguard() && !mHideLockScreen;
3466 if (!isKeyguardShowing) {
3467 navTranslucent &= areTranslucentBarsAllowed();
3468 }
Dianne Hackborne26ab702011-10-16 13:21:33 -07003469
Craig Mautner69b08182012-09-05 13:07:13 -07003470 // When the navigation bar isn't visible, we put up a fake
3471 // input window to catch all touch events. This way we can
3472 // detect when the user presses anywhere to bring back the nav
3473 // bar and ensure the application doesn't see the event.
John Spurlockf1a36642013-10-12 17:50:42 -04003474 if (navVisible || navAllowedHidden) {
Selim Cinekf83e8242015-05-19 18:08:14 -07003475 if (mInputConsumer != null) {
3476 mInputConsumer.dismiss();
3477 mInputConsumer = null;
Craig Mautner69b08182012-09-05 13:07:13 -07003478 }
Selim Cinekf83e8242015-05-19 18:08:14 -07003479 } else if (mInputConsumer == null) {
3480 mInputConsumer = mWindowManagerFuncs.addInputConsumer(mHandler.getLooper(),
3481 mHideNavInputEventReceiverFactory);
Dianne Hackborne26ab702011-10-16 13:21:33 -07003482 }
Dianne Hackborne26ab702011-10-16 13:21:33 -07003483
Craig Mautner69b08182012-09-05 13:07:13 -07003484 // For purposes of positioning and showing the nav bar, if we have
3485 // decided that it can't be hidden (because of the screen aspect ratio),
3486 // then take that into account.
Alan Viverette5a0f4ec2013-10-07 15:10:29 -07003487 navVisible |= !canHideNavigationBar();
Dianne Hackbornf87d1962012-04-04 12:48:24 -07003488
John Spurlockad3e6cb2013-04-30 08:47:43 -04003489 boolean updateSysUiVisibility = false;
Craig Mautner69b08182012-09-05 13:07:13 -07003490 if (mNavigationBar != null) {
John Spurlock27735a42013-08-14 17:57:38 -04003491 boolean transientNavBarShowing = mNavigationBarController.isTransientShowing();
Craig Mautner69b08182012-09-05 13:07:13 -07003492 // Force the navigation bar to its appropriate place and
3493 // size. We need to do this directly, instead of relying on
3494 // it to bubble up from the nav bar, because this needs to
3495 // change atomically with screen rotations.
3496 mNavigationBarOnBottom = (!mNavigationBarCanMove || displayWidth < displayHeight);
3497 if (mNavigationBarOnBottom) {
3498 // It's a system nav bar or a portrait screen; nav bar goes on bottom.
Dianne Hackbornc652de82013-02-15 16:32:56 -08003499 int top = displayHeight - overscanBottom
3500 - mNavigationBarHeightForRotation[displayRotation];
3501 mTmpNavigationFrame.set(0, top, displayWidth, displayHeight - overscanBottom);
Craig Mautner69b08182012-09-05 13:07:13 -07003502 mStableBottom = mStableFullscreenBottom = mTmpNavigationFrame.top;
John Spurlockf95b89a2013-10-10 22:10:42 -04003503 if (transientNavBarShowing) {
John Spurlock27735a42013-08-14 17:57:38 -04003504 mNavigationBarController.setBarShowingLw(true);
John Spurlockad3e6cb2013-04-30 08:47:43 -04003505 } else if (navVisible) {
John Spurlock27735a42013-08-14 17:57:38 -04003506 mNavigationBarController.setBarShowingLw(true);
Craig Mautner69b08182012-09-05 13:07:13 -07003507 mDockBottom = mTmpNavigationFrame.top;
Dianne Hackborn313440842013-02-19 19:22:59 -08003508 mRestrictedScreenHeight = mDockBottom - mRestrictedScreenTop;
3509 mRestrictedOverscanScreenHeight = mDockBottom - mRestrictedOverscanScreenTop;
Craig Mautner69b08182012-09-05 13:07:13 -07003510 } else {
3511 // We currently want to hide the navigation UI.
John Spurlock27735a42013-08-14 17:57:38 -04003512 mNavigationBarController.setBarShowingLw(false);
Craig Mautner69b08182012-09-05 13:07:13 -07003513 }
John Spurlockc6d1c602014-01-17 15:22:06 -05003514 if (navVisible && !navTranslucent && !navAllowedHidden
3515 && !mNavigationBar.isAnimatingLw()
John Spurlockbd957402013-10-03 11:38:39 -04003516 && !mNavigationBarController.wasRecentlyTranslucent()) {
John Spurlocke1f366f2013-08-05 12:22:40 -04003517 // If the opaque nav bar is currently requested to be visible,
Craig Mautner69b08182012-09-05 13:07:13 -07003518 // and not in the process of animating on or off, then
3519 // we can tell the app that it is covered by it.
3520 mSystemBottom = mTmpNavigationFrame.top;
3521 }
Dianne Hackbornf87d1962012-04-04 12:48:24 -07003522 } else {
Craig Mautner69b08182012-09-05 13:07:13 -07003523 // Landscape screen; nav bar goes to the right.
Dianne Hackbornc652de82013-02-15 16:32:56 -08003524 int left = displayWidth - overscanRight
3525 - mNavigationBarWidthForRotation[displayRotation];
3526 mTmpNavigationFrame.set(left, 0, displayWidth - overscanRight, displayHeight);
Craig Mautner69b08182012-09-05 13:07:13 -07003527 mStableRight = mStableFullscreenRight = mTmpNavigationFrame.left;
John Spurlockf95b89a2013-10-10 22:10:42 -04003528 if (transientNavBarShowing) {
John Spurlock27735a42013-08-14 17:57:38 -04003529 mNavigationBarController.setBarShowingLw(true);
John Spurlockad3e6cb2013-04-30 08:47:43 -04003530 } else if (navVisible) {
John Spurlock27735a42013-08-14 17:57:38 -04003531 mNavigationBarController.setBarShowingLw(true);
Craig Mautner69b08182012-09-05 13:07:13 -07003532 mDockRight = mTmpNavigationFrame.left;
Dianne Hackborn313440842013-02-19 19:22:59 -08003533 mRestrictedScreenWidth = mDockRight - mRestrictedScreenLeft;
3534 mRestrictedOverscanScreenWidth = mDockRight - mRestrictedOverscanScreenLeft;
Craig Mautner69b08182012-09-05 13:07:13 -07003535 } else {
3536 // We currently want to hide the navigation UI.
John Spurlock27735a42013-08-14 17:57:38 -04003537 mNavigationBarController.setBarShowingLw(false);
Craig Mautner69b08182012-09-05 13:07:13 -07003538 }
John Spurlockbd957402013-10-03 11:38:39 -04003539 if (navVisible && !navTranslucent && !mNavigationBar.isAnimatingLw()
3540 && !mNavigationBarController.wasRecentlyTranslucent()) {
Craig Mautner69b08182012-09-05 13:07:13 -07003541 // If the nav bar is currently requested to be visible,
3542 // and not in the process of animating on or off, then
3543 // we can tell the app that it is covered by it.
3544 mSystemRight = mTmpNavigationFrame.left;
3545 }
Dianne Hackbornf87d1962012-04-04 12:48:24 -07003546 }
Craig Mautner69b08182012-09-05 13:07:13 -07003547 // Make sure the content and current rectangles are updated to
3548 // account for the restrictions from the navigation bar.
Dianne Hackborne30e02f2014-05-27 18:24:45 -07003549 mContentTop = mVoiceContentTop = mCurTop = mDockTop;
3550 mContentBottom = mVoiceContentBottom = mCurBottom = mDockBottom;
3551 mContentLeft = mVoiceContentLeft = mCurLeft = mDockLeft;
3552 mContentRight = mVoiceContentRight = mCurRight = mDockRight;
Craig Mautner69b08182012-09-05 13:07:13 -07003553 mStatusBarLayer = mNavigationBar.getSurfaceLayer();
3554 // And compute the final frame.
3555 mNavigationBar.computeFrameLw(mTmpNavigationFrame, mTmpNavigationFrame,
Adrian Roosfa104232014-06-20 16:10:14 -07003556 mTmpNavigationFrame, mTmpNavigationFrame, mTmpNavigationFrame, dcf,
Filip Gruszczynski2217f612015-05-26 11:32:08 -07003557 mTmpNavigationFrame, mTmpNavigationFrame);
Craig Mautnereda67292013-04-28 13:50:14 -07003558 if (DEBUG_LAYOUT) Slog.i(TAG, "mNavigationBar frame: " + mTmpNavigationFrame);
John Spurlock27735a42013-08-14 17:57:38 -04003559 if (mNavigationBarController.checkHiddenLw()) {
John Spurlockad3e6cb2013-04-30 08:47:43 -04003560 updateSysUiVisibility = true;
3561 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003562 }
Craig Mautnereda67292013-04-28 13:50:14 -07003563 if (DEBUG_LAYOUT) Slog.i(TAG, String.format("mDock rect: (%d,%d - %d,%d)",
Craig Mautner69b08182012-09-05 13:07:13 -07003564 mDockLeft, mDockTop, mDockRight, mDockBottom));
3565
3566 // decide where the status bar goes ahead of time
3567 if (mStatusBar != null) {
3568 // apply any navigation bar insets
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003569 pf.left = df.left = of.left = mUnrestrictedScreenLeft;
3570 pf.top = df.top = of.top = mUnrestrictedScreenTop;
3571 pf.right = df.right = of.right = mUnrestrictedScreenWidth + mUnrestrictedScreenLeft;
3572 pf.bottom = df.bottom = of.bottom = mUnrestrictedScreenHeight
3573 + mUnrestrictedScreenTop;
Craig Mautner69b08182012-09-05 13:07:13 -07003574 vf.left = mStableLeft;
3575 vf.top = mStableTop;
3576 vf.right = mStableRight;
3577 vf.bottom = mStableBottom;
3578
3579 mStatusBarLayer = mStatusBar.getSurfaceLayer();
3580
3581 // Let the status bar determine its size.
Filip Gruszczynski2217f612015-05-26 11:32:08 -07003582 mStatusBar.computeFrameLw(pf /* parentFrame */, df /* displayFrame */,
3583 vf /* overlayFrame */, vf /* contentFrame */, vf /* visibleFrame */,
3584 dcf /* decorFrame */, vf /* stableFrame */, vf /* outsetFrame */);
Craig Mautner69b08182012-09-05 13:07:13 -07003585
3586 // For layout, the status bar is always at the top with our fixed height.
3587 mStableTop = mUnrestrictedScreenTop + mStatusBarHeight;
3588
John Spurlocke1f366f2013-08-05 12:22:40 -04003589 boolean statusBarTransient = (sysui & View.STATUS_BAR_TRANSIENT) != 0;
Adrian Roosea562512014-05-05 13:33:03 +02003590 boolean statusBarTranslucent = (sysui
3591 & (View.STATUS_BAR_TRANSLUCENT | View.SYSTEM_UI_TRANSPARENT)) != 0;
Adrian Roos4fb3ee32014-08-22 19:29:09 +02003592 if (!isKeyguardShowing) {
3593 statusBarTranslucent &= areTranslucentBarsAllowed();
3594 }
John Spurlock32beb2c2013-03-11 10:16:47 -04003595
Craig Mautner69b08182012-09-05 13:07:13 -07003596 // If the status bar is hidden, we don't want to cause
3597 // windows behind it to scroll.
John Spurlockeda1f692013-09-16 11:38:44 -04003598 if (mStatusBar.isVisibleLw() && !statusBarTransient) {
Craig Mautner69b08182012-09-05 13:07:13 -07003599 // Status bar may go away, so the screen area it occupies
3600 // is available to apps but just covering them when the
3601 // status bar is visible.
3602 mDockTop = mUnrestrictedScreenTop + mStatusBarHeight;
3603
Dianne Hackborne30e02f2014-05-27 18:24:45 -07003604 mContentTop = mVoiceContentTop = mCurTop = mDockTop;
3605 mContentBottom = mVoiceContentBottom = mCurBottom = mDockBottom;
3606 mContentLeft = mVoiceContentLeft = mCurLeft = mDockLeft;
3607 mContentRight = mVoiceContentRight = mCurRight = mDockRight;
Craig Mautner69b08182012-09-05 13:07:13 -07003608
Craig Mautnereda67292013-04-28 13:50:14 -07003609 if (DEBUG_LAYOUT) Slog.v(TAG, "Status bar: " +
Craig Mautner69b08182012-09-05 13:07:13 -07003610 String.format(
3611 "dock=[%d,%d][%d,%d] content=[%d,%d][%d,%d] cur=[%d,%d][%d,%d]",
3612 mDockLeft, mDockTop, mDockRight, mDockBottom,
3613 mContentLeft, mContentTop, mContentRight, mContentBottom,
3614 mCurLeft, mCurTop, mCurRight, mCurBottom));
3615 }
John Spurlocke1f366f2013-08-05 12:22:40 -04003616 if (mStatusBar.isVisibleLw() && !mStatusBar.isAnimatingLw()
John Spurlockbd957402013-10-03 11:38:39 -04003617 && !statusBarTransient && !statusBarTranslucent
3618 && !mStatusBarController.wasRecentlyTranslucent()) {
John Spurlocke1f366f2013-08-05 12:22:40 -04003619 // If the opaque status bar is currently requested to be visible,
Craig Mautner69b08182012-09-05 13:07:13 -07003620 // and not in the process of animating on or off, then
3621 // we can tell the app that it is covered by it.
3622 mSystemTop = mUnrestrictedScreenTop + mStatusBarHeight;
3623 }
John Spurlock27735a42013-08-14 17:57:38 -04003624 if (mStatusBarController.checkHiddenLw()) {
John Spurlockad3e6cb2013-04-30 08:47:43 -04003625 updateSysUiVisibility = true;
John Spurlock32beb2c2013-03-11 10:16:47 -04003626 }
Dianne Hackborn5c58de32012-04-28 19:52:37 -07003627 }
John Spurlockad3e6cb2013-04-30 08:47:43 -04003628 if (updateSysUiVisibility) {
3629 updateSystemUiVisibilityLw();
3630 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003631 }
3632 }
3633
Dianne Hackborn85afd1b2012-05-13 13:31:06 -07003634 /** {@inheritDoc} */
Craig Mautner967212c2013-04-13 21:10:58 -07003635 @Override
John Spurlock46646232013-09-30 22:32:42 -04003636 public int getSystemDecorLayerLw() {
Bryce Lee2ed3e5f2015-04-01 22:09:19 +00003637 if (mStatusBar != null && mStatusBar.isVisibleLw()) {
3638 return mStatusBar.getSurfaceLayer();
3639 }
3640
3641 if (mNavigationBar != null && mNavigationBar.isVisibleLw()) {
3642 return mNavigationBar.getSurfaceLayer();
3643 }
3644
Dianne Hackborn85afd1b2012-05-13 13:31:06 -07003645 return 0;
3646 }
3647
Craig Mautner967212c2013-04-13 21:10:58 -07003648 @Override
3649 public void getContentRectLw(Rect r) {
3650 r.set(mContentLeft, mContentTop, mContentRight, mContentBottom);
3651 }
3652
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003653 void setAttachedWindowFrames(WindowState win, int fl, int adjust, WindowState attached,
3654 boolean insetDecors, Rect pf, Rect df, Rect of, Rect cf, Rect vf) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003655 if (win.getSurfaceLayer() > mDockLayer && attached.getSurfaceLayer() < mDockLayer) {
3656 // Here's a special case: if this attached window is a panel that is
3657 // above the dock window, and the window it is attached to is below
3658 // the dock window, then the frames we computed for the window it is
3659 // attached to can not be used because the dock is effectively part
3660 // of the underlying window and the attached window is floating on top
3661 // of the whole thing. So, we ignore the attached window and explicitly
3662 // compute the frames that would be appropriate without the dock.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003663 df.left = of.left = cf.left = vf.left = mDockLeft;
3664 df.top = of.top = cf.top = vf.top = mDockTop;
3665 df.right = of.right = cf.right = vf.right = mDockRight;
3666 df.bottom = of.bottom = cf.bottom = vf.bottom = mDockBottom;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003667 } else {
3668 // The effective display frame of the attached window depends on
3669 // whether it is taking care of insetting its content. If not,
3670 // we need to use the parent's content frame so that the entire
3671 // window is positioned within that content. Otherwise we can use
Wale Ogunwale393b1c12014-10-18 16:22:01 -07003672 // the overscan frame and let the attached window take care of
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003673 // positioning its content appropriately.
Dianne Hackborndea3ef72010-10-28 14:24:22 -07003674 if (adjust != SOFT_INPUT_ADJUST_RESIZE) {
Wale Ogunwale393b1c12014-10-18 16:22:01 -07003675 // Set the content frame of the attached window to the parent's decor frame
3676 // (same as content frame when IME isn't present) if specifically requested by
3677 // setting {@link WindowManager.LayoutParams#FLAG_LAYOUT_ATTACHED_IN_DECOR} flag.
3678 // Otherwise, use the overscan frame.
3679 cf.set((fl & FLAG_LAYOUT_ATTACHED_IN_DECOR) != 0
3680 ? attached.getContentFrameLw() : attached.getOverscanFrameLw());
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003681 } else {
3682 // If the window is resizing, then we want to base the content
3683 // frame on our attached content frame to resize... however,
3684 // things can be tricky if the attached window is NOT in resize
3685 // mode, in which case its content frame will be larger.
3686 // Ungh. So to deal with that, make sure the content frame
3687 // we end up using is not covering the IM dock.
3688 cf.set(attached.getContentFrameLw());
Dianne Hackborne30e02f2014-05-27 18:24:45 -07003689 if (attached.isVoiceInteraction()) {
3690 if (cf.left < mVoiceContentLeft) cf.left = mVoiceContentLeft;
3691 if (cf.top < mVoiceContentTop) cf.top = mVoiceContentTop;
3692 if (cf.right > mVoiceContentRight) cf.right = mVoiceContentRight;
3693 if (cf.bottom > mVoiceContentBottom) cf.bottom = mVoiceContentBottom;
3694 } else if (attached.getSurfaceLayer() < mDockLayer) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003695 if (cf.left < mContentLeft) cf.left = mContentLeft;
3696 if (cf.top < mContentTop) cf.top = mContentTop;
3697 if (cf.right > mContentRight) cf.right = mContentRight;
3698 if (cf.bottom > mContentBottom) cf.bottom = mContentBottom;
3699 }
3700 }
3701 df.set(insetDecors ? attached.getDisplayFrameLw() : cf);
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003702 of.set(insetDecors ? attached.getOverscanFrameLw() : cf);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003703 vf.set(attached.getVisibleFrameLw());
3704 }
3705 // The LAYOUT_IN_SCREEN flag is used to determine whether the attached
3706 // window should be positioned relative to its parent or the entire
3707 // screen.
3708 pf.set((fl & FLAG_LAYOUT_IN_SCREEN) == 0
3709 ? attached.getFrameLw() : df);
3710 }
Dianne Hackborn5b5cc4d2012-05-16 13:15:00 -07003711
3712 private void applyStableConstraints(int sysui, int fl, Rect r) {
3713 if ((sysui & View.SYSTEM_UI_FLAG_LAYOUT_STABLE) != 0) {
3714 // If app is requesting a stable layout, don't let the
3715 // content insets go below the stable values.
3716 if ((fl & FLAG_FULLSCREEN) != 0) {
3717 if (r.left < mStableFullscreenLeft) r.left = mStableFullscreenLeft;
3718 if (r.top < mStableFullscreenTop) r.top = mStableFullscreenTop;
3719 if (r.right > mStableFullscreenRight) r.right = mStableFullscreenRight;
3720 if (r.bottom > mStableFullscreenBottom) r.bottom = mStableFullscreenBottom;
3721 } else {
3722 if (r.left < mStableLeft) r.left = mStableLeft;
3723 if (r.top < mStableTop) r.top = mStableTop;
3724 if (r.right > mStableRight) r.right = mStableRight;
3725 if (r.bottom > mStableBottom) r.bottom = mStableBottom;
3726 }
3727 }
3728 }
3729
Jorim Jaggiaa806142015-05-20 18:04:16 -07003730 private boolean canReceiveInput(WindowState win) {
3731 boolean notFocusable =
3732 (win.getAttrs().flags & WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE) != 0;
3733 boolean altFocusableIm =
3734 (win.getAttrs().flags & WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM) != 0;
3735 boolean notFocusableForIm = notFocusable ^ altFocusableIm;
3736 return !notFocusableForIm;
3737 }
3738
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003739 /** {@inheritDoc} */
Craig Mautner69b08182012-09-05 13:07:13 -07003740 @Override
Craig Mautnerc9457fa2014-06-06 14:27:48 -07003741 public void layoutWindowLw(WindowState win, WindowState attached) {
Jorim Jaggiaa806142015-05-20 18:04:16 -07003742 // We've already done the navigation bar and status bar. If the status bar can receive
3743 // input, we need to layout it again to accomodate for the IME window.
3744 if ((win == mStatusBar && !canReceiveInput(win)) || win == mNavigationBar) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003745 return;
3746 }
Jorim Jaggiaa806142015-05-20 18:04:16 -07003747 final WindowManager.LayoutParams attrs = win.getAttrs();
Craig Mautner69b08182012-09-05 13:07:13 -07003748 final boolean isDefaultDisplay = win.isDefaultDisplay();
3749 final boolean needsToOffsetInputMethodTarget = isDefaultDisplay &&
satok1bc0a492012-04-25 22:47:12 +09003750 (win == mLastInputMethodTargetWindow && mLastInputMethodWindow != null);
3751 if (needsToOffsetInputMethodTarget) {
Craig Mautnereda67292013-04-28 13:50:14 -07003752 if (DEBUG_LAYOUT) Slog.i(TAG, "Offset ime target window by the last ime window state");
satok1bc0a492012-04-25 22:47:12 +09003753 offsetInputMethodWindowLw(mLastInputMethodWindow);
3754 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003755
John Spurlockc6d1c602014-01-17 15:22:06 -05003756 final int fl = PolicyControl.getWindowFlags(win, attrs);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003757 final int sim = attrs.softInputMode;
John Spurlock1db8b682014-02-18 11:18:59 -05003758 final int sysUiFl = PolicyControl.getSystemUiVisibility(win, null);
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07003759
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003760 final Rect pf = mTmpParentFrame;
3761 final Rect df = mTmpDisplayFrame;
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003762 final Rect of = mTmpOverscanFrame;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003763 final Rect cf = mTmpContentFrame;
3764 final Rect vf = mTmpVisibleFrame;
John Spurlock46646232013-09-30 22:32:42 -04003765 final Rect dcf = mTmpDecorFrame;
Adrian Roosfa104232014-06-20 16:10:14 -07003766 final Rect sf = mTmpStableFrame;
Filip Gruszczynski2217f612015-05-26 11:32:08 -07003767 Rect osf = null;
John Spurlock46646232013-09-30 22:32:42 -04003768 dcf.setEmpty();
Craig Mautner69b08182012-09-05 13:07:13 -07003769
3770 final boolean hasNavBar = (isDefaultDisplay && mHasNavigationBar
Daniel Sandler36412a72011-08-04 09:35:13 -04003771 && mNavigationBar != null && mNavigationBar.isVisibleLw());
Daniel Sandler8956dbb2011-04-22 07:55:02 -04003772
Craig Mautnerf683b562012-10-02 11:10:57 -07003773 final int adjust = sim & SOFT_INPUT_MASK_ADJUST;
3774
Adrian Roosfa104232014-06-20 16:10:14 -07003775 if (isDefaultDisplay) {
3776 sf.set(mStableLeft, mStableTop, mStableRight, mStableBottom);
3777 } else {
3778 sf.set(mOverscanLeft, mOverscanTop, mOverscanRight, mOverscanBottom);
3779 }
3780
Craig Mautner69b08182012-09-05 13:07:13 -07003781 if (!isDefaultDisplay) {
3782 if (attached != null) {
3783 // If this window is attached to another, our display
3784 // frame is the same as the one we are attached to.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003785 setAttachedWindowFrames(win, fl, adjust, attached, true, pf, df, of, cf, vf);
Craig Mautner69b08182012-09-05 13:07:13 -07003786 } else {
3787 // Give the window full screen.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003788 pf.left = df.left = of.left = cf.left = mOverscanScreenLeft;
3789 pf.top = df.top = of.top = cf.top = mOverscanScreenTop;
3790 pf.right = df.right = of.right = cf.right
Dianne Hackbornc652de82013-02-15 16:32:56 -08003791 = mOverscanScreenLeft + mOverscanScreenWidth;
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003792 pf.bottom = df.bottom = of.bottom = cf.bottom
Dianne Hackbornc652de82013-02-15 16:32:56 -08003793 = mOverscanScreenTop + mOverscanScreenHeight;
Craig Mautner69b08182012-09-05 13:07:13 -07003794 }
Jorim Jaggi225d3b52015-04-01 11:18:57 -07003795 } else if (attrs.type == TYPE_INPUT_METHOD) {
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003796 pf.left = df.left = of.left = cf.left = vf.left = mDockLeft;
3797 pf.top = df.top = of.top = cf.top = vf.top = mDockTop;
3798 pf.right = df.right = of.right = cf.right = vf.right = mDockRight;
John Spurlockc68d5772013-10-08 11:47:58 -04003799 // IM dock windows layout below the nav bar...
John Spurlock57beb3b2013-10-10 10:27:44 -04003800 pf.bottom = df.bottom = of.bottom = mUnrestrictedScreenTop + mUnrestrictedScreenHeight;
John Spurlockc68d5772013-10-08 11:47:58 -04003801 // ...with content insets above the nav bar
3802 cf.bottom = vf.bottom = mStableBottom;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003803 // IM dock windows always go to the bottom of the screen.
3804 attrs.gravity = Gravity.BOTTOM;
3805 mDockLayer = win.getSurfaceLayer();
Jorim Jaggi225d3b52015-04-01 11:18:57 -07003806 } else if (attrs.type == TYPE_VOICE_INTERACTION) {
Stefan Kuhne2f280d062015-06-18 07:20:33 -10003807 pf.left = df.left = of.left = mUnrestrictedScreenLeft;
Jorim Jaggi225d3b52015-04-01 11:18:57 -07003808 pf.top = df.top = of.top = mUnrestrictedScreenTop;
Stefan Kuhne2f280d062015-06-18 07:20:33 -10003809 pf.right = df.right = of.right = mUnrestrictedScreenLeft + mUnrestrictedScreenWidth;
3810 pf.bottom = df.bottom = of.bottom = mUnrestrictedScreenTop + mUnrestrictedScreenHeight;
Jorim Jaggi225d3b52015-04-01 11:18:57 -07003811 cf.bottom = vf.bottom = mStableBottom;
Stefan Kuhne2f280d062015-06-18 07:20:33 -10003812 // Note: In Phone landscape mode, the button bar should also be excluded.
3813 cf.right = vf.right = mStableRight;
3814 cf.left = vf.left = mStableLeft;
Jorim Jaggi225d3b52015-04-01 11:18:57 -07003815 cf.top = vf.top = mStableTop;
Jorim Jaggiaa806142015-05-20 18:04:16 -07003816 } else if (win == mStatusBar) {
Jorim Jaggie0700182014-08-21 01:12:37 +02003817 pf.left = df.left = of.left = mUnrestrictedScreenLeft;
3818 pf.top = df.top = of.top = mUnrestrictedScreenTop;
3819 pf.right = df.right = of.right = mUnrestrictedScreenWidth + mUnrestrictedScreenLeft;
3820 pf.bottom = df.bottom = of.bottom = mUnrestrictedScreenHeight + mUnrestrictedScreenTop;
3821 cf.left = vf.left = mStableLeft;
3822 cf.top = vf.top = mStableTop;
3823 cf.right = vf.right = mStableRight;
3824 vf.bottom = mStableBottom;
3825 cf.bottom = mContentBottom;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003826 } else {
John Spurlock46646232013-09-30 22:32:42 -04003827
3828 // Default policy decor for the default display
3829 dcf.left = mSystemLeft;
3830 dcf.top = mSystemTop;
3831 dcf.right = mSystemRight;
3832 dcf.bottom = mSystemBottom;
John Spurlockbd957402013-10-03 11:38:39 -04003833 final boolean inheritTranslucentDecor = (attrs.privateFlags
3834 & WindowManager.LayoutParams.PRIVATE_FLAG_INHERIT_TRANSLUCENT_DECOR) != 0;
John Spurlock65567d42013-10-08 10:08:32 -04003835 final boolean isAppWindow =
3836 attrs.type >= WindowManager.LayoutParams.FIRST_APPLICATION_WINDOW &&
3837 attrs.type <= WindowManager.LayoutParams.LAST_APPLICATION_WINDOW;
3838 final boolean topAtRest =
3839 win == mTopFullscreenOpaqueWindowState && !win.isAnimatingLw();
3840 if (isAppWindow && !inheritTranslucentDecor && !topAtRest) {
John Spurlockbd957402013-10-03 11:38:39 -04003841 if ((sysUiFl & View.SYSTEM_UI_FLAG_FULLSCREEN) == 0
3842 && (fl & WindowManager.LayoutParams.FLAG_FULLSCREEN) == 0
Adrian Roosea562512014-05-05 13:33:03 +02003843 && (fl & WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS) == 0
3844 && (fl & WindowManager.LayoutParams.
3845 FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS) == 0) {
John Spurlock46646232013-09-30 22:32:42 -04003846 // Ensure policy decor includes status bar
3847 dcf.top = mStableTop;
3848 }
John Spurlockbd957402013-10-03 11:38:39 -04003849 if ((fl & WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION) == 0
Adrian Roosea562512014-05-05 13:33:03 +02003850 && (sysUiFl & View.SYSTEM_UI_FLAG_HIDE_NAVIGATION) == 0
3851 && (fl & WindowManager.LayoutParams.
3852 FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS) == 0) {
John Spurlock46646232013-09-30 22:32:42 -04003853 // Ensure policy decor includes navigation bar
3854 dcf.bottom = mStableBottom;
3855 dcf.right = mStableRight;
3856 }
3857 }
3858
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003859 if ((fl & (FLAG_LAYOUT_IN_SCREEN | FLAG_LAYOUT_INSET_DECOR))
3860 == (FLAG_LAYOUT_IN_SCREEN | FLAG_LAYOUT_INSET_DECOR)) {
RoboErik8a2cfc32014-05-16 11:19:38 -07003861 if (DEBUG_LAYOUT) Slog.v(TAG, "layoutWindowLw(" + attrs.getTitle()
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003862 + "): IN_SCREEN, INSET_DECOR");
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003863 // This is the case for a normal activity window: we want it
3864 // to cover all of the screen space, and it can take care of
3865 // moving its contents to account for screen decorations that
3866 // intrude into that space.
3867 if (attached != null) {
3868 // If this window is attached to another, our display
3869 // frame is the same as the one we are attached to.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003870 setAttachedWindowFrames(win, fl, adjust, attached, true, pf, df, of, cf, vf);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003871 } else {
Daniel Sandler8956dbb2011-04-22 07:55:02 -04003872 if (attrs.type == TYPE_STATUS_BAR_PANEL
3873 || attrs.type == TYPE_STATUS_BAR_SUB_PANEL) {
Joe Onorato29fc2c92010-11-24 10:26:50 -08003874 // Status bar panels are the only windows who can go on top of
3875 // the status bar. They are protected by the STATUS_BAR_SERVICE
3876 // permission, so they have the same privileges as the status
3877 // bar itself.
Daniel Sandler8956dbb2011-04-22 07:55:02 -04003878 //
Daniel Sandler8e8b4152011-07-21 01:16:43 -04003879 // However, they should still dodge the navigation bar if it exists.
Daniel Sandler8956dbb2011-04-22 07:55:02 -04003880
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003881 pf.left = df.left = of.left = hasNavBar
3882 ? mDockLeft : mUnrestrictedScreenLeft;
3883 pf.top = df.top = of.top = mUnrestrictedScreenTop;
3884 pf.right = df.right = of.right = hasNavBar
3885 ? mRestrictedScreenLeft+mRestrictedScreenWidth
3886 : mUnrestrictedScreenLeft + mUnrestrictedScreenWidth;
3887 pf.bottom = df.bottom = of.bottom = hasNavBar
3888 ? mRestrictedScreenTop+mRestrictedScreenHeight
3889 : mUnrestrictedScreenTop + mUnrestrictedScreenHeight;
Daniel Sandler8956dbb2011-04-22 07:55:02 -04003890
Craig Mautnereda67292013-04-28 13:50:14 -07003891 if (DEBUG_LAYOUT) Slog.v(TAG, String.format(
Daniel Sandler8e8b4152011-07-21 01:16:43 -04003892 "Laying out status bar window: (%d,%d - %d,%d)",
3893 pf.left, pf.top, pf.right, pf.bottom));
John Spurlock46646232013-09-30 22:32:42 -04003894 } else if ((fl & FLAG_LAYOUT_IN_OVERSCAN) != 0
Dianne Hackbornc652de82013-02-15 16:32:56 -08003895 && attrs.type >= WindowManager.LayoutParams.FIRST_APPLICATION_WINDOW
3896 && attrs.type <= WindowManager.LayoutParams.LAST_SUB_WINDOW) {
3897 // Asking to layout into the overscan region, so give it that pure
3898 // unrestricted area.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003899 pf.left = df.left = of.left = mOverscanScreenLeft;
3900 pf.top = df.top = of.top = mOverscanScreenTop;
3901 pf.right = df.right = of.right = mOverscanScreenLeft + mOverscanScreenWidth;
3902 pf.bottom = df.bottom = of.bottom = mOverscanScreenTop
3903 + mOverscanScreenHeight;
Alan Viverette5a0f4ec2013-10-07 15:10:29 -07003904 } else if (canHideNavigationBar()
Dianne Hackbornf87d1962012-04-04 12:48:24 -07003905 && (sysUiFl & View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION) != 0
Jorim Jaggi380ecb82014-03-14 17:25:20 +01003906 && attrs.type >= WindowManager.LayoutParams.FIRST_APPLICATION_WINDOW
3907 && attrs.type <= WindowManager.LayoutParams.LAST_SUB_WINDOW) {
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07003908 // Asking for layout as if the nav bar is hidden, lets the
Dianne Hackbornc652de82013-02-15 16:32:56 -08003909 // application extend into the unrestricted overscan screen area. We
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07003910 // only do this for application windows to ensure no window that
3911 // can be above the nav bar can do this.
Dianne Hackborn313440842013-02-19 19:22:59 -08003912 pf.left = df.left = mOverscanScreenLeft;
3913 pf.top = df.top = mOverscanScreenTop;
3914 pf.right = df.right = mOverscanScreenLeft + mOverscanScreenWidth;
3915 pf.bottom = df.bottom = mOverscanScreenTop + mOverscanScreenHeight;
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003916 // We need to tell the app about where the frame inside the overscan
3917 // is, so it can inset its content by that amount -- it didn't ask
3918 // to actually extend itself into the overscan region.
3919 of.left = mUnrestrictedScreenLeft;
3920 of.top = mUnrestrictedScreenTop;
3921 of.right = mUnrestrictedScreenLeft + mUnrestrictedScreenWidth;
3922 of.bottom = mUnrestrictedScreenTop + mUnrestrictedScreenHeight;
Joe Onorato29fc2c92010-11-24 10:26:50 -08003923 } else {
Dianne Hackborn313440842013-02-19 19:22:59 -08003924 pf.left = df.left = mRestrictedOverscanScreenLeft;
3925 pf.top = df.top = mRestrictedOverscanScreenTop;
3926 pf.right = df.right = mRestrictedOverscanScreenLeft
3927 + mRestrictedOverscanScreenWidth;
3928 pf.bottom = df.bottom = mRestrictedOverscanScreenTop
3929 + mRestrictedOverscanScreenHeight;
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003930 // We need to tell the app about where the frame inside the overscan
3931 // is, so it can inset its content by that amount -- it didn't ask
3932 // to actually extend itself into the overscan region.
3933 of.left = mUnrestrictedScreenLeft;
3934 of.top = mUnrestrictedScreenTop;
3935 of.right = mUnrestrictedScreenLeft + mUnrestrictedScreenWidth;
3936 of.bottom = mUnrestrictedScreenTop + mUnrestrictedScreenHeight;
Joe Onorato29fc2c92010-11-24 10:26:50 -08003937 }
Craig Mautner69b08182012-09-05 13:07:13 -07003938
John Spurlock46646232013-09-30 22:32:42 -04003939 if ((fl & FLAG_FULLSCREEN) == 0) {
Dianne Hackborne30e02f2014-05-27 18:24:45 -07003940 if (win.isVoiceInteraction()) {
3941 cf.left = mVoiceContentLeft;
3942 cf.top = mVoiceContentTop;
3943 cf.right = mVoiceContentRight;
3944 cf.bottom = mVoiceContentBottom;
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003945 } else {
Dianne Hackborne30e02f2014-05-27 18:24:45 -07003946 if (adjust != SOFT_INPUT_ADJUST_RESIZE) {
3947 cf.left = mDockLeft;
3948 cf.top = mDockTop;
3949 cf.right = mDockRight;
3950 cf.bottom = mDockBottom;
3951 } else {
3952 cf.left = mContentLeft;
3953 cf.top = mContentTop;
3954 cf.right = mContentRight;
3955 cf.bottom = mContentBottom;
3956 }
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003957 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003958 } else {
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003959 // Full screen windows are always given a layout that is as if the
3960 // status bar and other transient decors are gone. This is to avoid
3961 // bad states when moving from a window that is not hding the
3962 // status bar to one that is.
3963 cf.left = mRestrictedScreenLeft;
3964 cf.top = mRestrictedScreenTop;
3965 cf.right = mRestrictedScreenLeft + mRestrictedScreenWidth;
3966 cf.bottom = mRestrictedScreenTop + mRestrictedScreenHeight;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003967 }
Dianne Hackborn5b5cc4d2012-05-16 13:15:00 -07003968 applyStableConstraints(sysUiFl, fl, cf);
Dianne Hackborndea3ef72010-10-28 14:24:22 -07003969 if (adjust != SOFT_INPUT_ADJUST_NOTHING) {
3970 vf.left = mCurLeft;
3971 vf.top = mCurTop;
3972 vf.right = mCurRight;
3973 vf.bottom = mCurBottom;
3974 } else {
3975 vf.set(cf);
3976 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003977 }
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07003978 } else if ((fl & FLAG_LAYOUT_IN_SCREEN) != 0 || (sysUiFl
3979 & (View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
3980 | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION)) != 0) {
Craig Mautnereda67292013-04-28 13:50:14 -07003981 if (DEBUG_LAYOUT) Slog.v(TAG, "layoutWindowLw(" + attrs.getTitle() +
3982 "): IN_SCREEN");
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003983 // A window that has requested to fill the entire screen just
3984 // gets everything, period.
Daniel Sandler8956dbb2011-04-22 07:55:02 -04003985 if (attrs.type == TYPE_STATUS_BAR_PANEL
John Spurlock67a0f852015-06-15 15:35:47 -04003986 || attrs.type == TYPE_STATUS_BAR_SUB_PANEL
3987 || attrs.type == TYPE_VOLUME_OVERLAY) {
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003988 pf.left = df.left = of.left = cf.left = hasNavBar
3989 ? mDockLeft : mUnrestrictedScreenLeft;
3990 pf.top = df.top = of.top = cf.top = mUnrestrictedScreenTop;
3991 pf.right = df.right = of.right = cf.right = hasNavBar
Daniel Sandler8e8b4152011-07-21 01:16:43 -04003992 ? mRestrictedScreenLeft+mRestrictedScreenWidth
Dianne Hackbornc652de82013-02-15 16:32:56 -08003993 : mUnrestrictedScreenLeft + mUnrestrictedScreenWidth;
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003994 pf.bottom = df.bottom = of.bottom = cf.bottom = hasNavBar
Daniel Sandler8e8b4152011-07-21 01:16:43 -04003995 ? mRestrictedScreenTop+mRestrictedScreenHeight
Dianne Hackbornc652de82013-02-15 16:32:56 -08003996 : mUnrestrictedScreenTop + mUnrestrictedScreenHeight;
Craig Mautnereda67292013-04-28 13:50:14 -07003997 if (DEBUG_LAYOUT) Slog.v(TAG, String.format(
Daniel Sandler36412a72011-08-04 09:35:13 -04003998 "Laying out IN_SCREEN status bar window: (%d,%d - %d,%d)",
3999 pf.left, pf.top, pf.right, pf.bottom));
Jim Millere898ac52012-04-06 17:10:57 -07004000 } else if (attrs.type == TYPE_NAVIGATION_BAR
4001 || attrs.type == TYPE_NAVIGATION_BAR_PANEL) {
Daniel Sandler8e8b4152011-07-21 01:16:43 -04004002 // The navigation bar has Real Ultimate Power.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08004003 pf.left = df.left = of.left = mUnrestrictedScreenLeft;
4004 pf.top = df.top = of.top = mUnrestrictedScreenTop;
4005 pf.right = df.right = of.right = mUnrestrictedScreenLeft
4006 + mUnrestrictedScreenWidth;
4007 pf.bottom = df.bottom = of.bottom = mUnrestrictedScreenTop
4008 + mUnrestrictedScreenHeight;
Craig Mautnereda67292013-04-28 13:50:14 -07004009 if (DEBUG_LAYOUT) Slog.v(TAG, String.format(
Daniel Sandler8e8b4152011-07-21 01:16:43 -04004010 "Laying out navigation bar window: (%d,%d - %d,%d)",
4011 pf.left, pf.top, pf.right, pf.bottom));
Dianne Hackborn01011c32012-02-21 13:54:21 -08004012 } else if ((attrs.type == TYPE_SECURE_SYSTEM_OVERLAY
4013 || attrs.type == TYPE_BOOT_PROGRESS)
Jeff Brownbfcb60a2011-09-08 18:51:14 -07004014 && ((fl & FLAG_FULLSCREEN) != 0)) {
4015 // Fullscreen secure system overlays get what they ask for.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08004016 pf.left = df.left = of.left = cf.left = mOverscanScreenLeft;
4017 pf.top = df.top = of.top = cf.top = mOverscanScreenTop;
4018 pf.right = df.right = of.right = cf.right = mOverscanScreenLeft
4019 + mOverscanScreenWidth;
4020 pf.bottom = df.bottom = of.bottom = cf.bottom = mOverscanScreenTop
4021 + mOverscanScreenHeight;
Craig Mautner165be0c2015-01-27 15:16:58 -08004022 } else if (attrs.type == TYPE_BOOT_PROGRESS) {
Dianne Hackborn01011c32012-02-21 13:54:21 -08004023 // Boot progress screen always covers entire display.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08004024 pf.left = df.left = of.left = cf.left = mOverscanScreenLeft;
4025 pf.top = df.top = of.top = cf.top = mOverscanScreenTop;
4026 pf.right = df.right = of.right = cf.right = mOverscanScreenLeft
4027 + mOverscanScreenWidth;
4028 pf.bottom = df.bottom = of.bottom = cf.bottom = mOverscanScreenTop
4029 + mOverscanScreenHeight;
John Spurlockef4adae2013-08-26 17:58:58 -04004030 } else if (attrs.type == TYPE_WALLPAPER) {
Dianne Hackborn067e5f62014-09-07 23:14:30 -07004031 // The wallpaper also has Real Ultimate Power, but we want to tell
4032 // it about the overscan area.
4033 pf.left = df.left = mOverscanScreenLeft;
4034 pf.top = df.top = mOverscanScreenTop;
4035 pf.right = df.right = mOverscanScreenLeft + mOverscanScreenWidth;
4036 pf.bottom = df.bottom = mOverscanScreenTop + mOverscanScreenHeight;
4037 of.left = cf.left = mUnrestrictedScreenLeft;
4038 of.top = cf.top = mUnrestrictedScreenTop;
4039 of.right = cf.right = mUnrestrictedScreenLeft + mUnrestrictedScreenWidth;
4040 of.bottom = cf.bottom = mUnrestrictedScreenTop + mUnrestrictedScreenHeight;
John Spurlock46646232013-09-30 22:32:42 -04004041 } else if ((fl & FLAG_LAYOUT_IN_OVERSCAN) != 0
Dianne Hackbornc652de82013-02-15 16:32:56 -08004042 && attrs.type >= WindowManager.LayoutParams.FIRST_APPLICATION_WINDOW
4043 && attrs.type <= WindowManager.LayoutParams.LAST_SUB_WINDOW) {
4044 // Asking to layout into the overscan region, so give it that pure
4045 // unrestricted area.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08004046 pf.left = df.left = of.left = cf.left = mOverscanScreenLeft;
4047 pf.top = df.top = of.top = cf.top = mOverscanScreenTop;
4048 pf.right = df.right = of.right = cf.right
Dianne Hackbornc652de82013-02-15 16:32:56 -08004049 = mOverscanScreenLeft + mOverscanScreenWidth;
Dianne Hackbornc4aad012013-02-22 15:05:25 -08004050 pf.bottom = df.bottom = of.bottom = cf.bottom
Dianne Hackbornc652de82013-02-15 16:32:56 -08004051 = mOverscanScreenTop + mOverscanScreenHeight;
Alan Viverette5a0f4ec2013-10-07 15:10:29 -07004052 } else if (canHideNavigationBar()
Dianne Hackbornf87d1962012-04-04 12:48:24 -07004053 && (sysUiFl & View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION) != 0
Craig Mautnerbeac1062014-06-03 14:38:57 -07004054 && (attrs.type == TYPE_STATUS_BAR
4055 || attrs.type == TYPE_TOAST
Jorim Jaggi2fdeeab2015-04-01 15:13:03 -07004056 || attrs.type == TYPE_VOICE_INTERACTION_STARTING
John Spurlock34e13d92013-08-10 06:52:28 -04004057 || (attrs.type >= WindowManager.LayoutParams.FIRST_APPLICATION_WINDOW
4058 && attrs.type <= WindowManager.LayoutParams.LAST_SUB_WINDOW))) {
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07004059 // Asking for layout as if the nav bar is hidden, lets the
4060 // application extend into the unrestricted screen area. We
John Spurlock34e13d92013-08-10 06:52:28 -04004061 // only do this for application windows (or toasts) to ensure no window that
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07004062 // can be above the nav bar can do this.
4063 // XXX This assumes that an app asking for this will also
4064 // ask for layout in only content. We can't currently figure out
4065 // what the screen would be if only laying out to hide the nav bar.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08004066 pf.left = df.left = of.left = cf.left = mUnrestrictedScreenLeft;
4067 pf.top = df.top = of.top = cf.top = mUnrestrictedScreenTop;
4068 pf.right = df.right = of.right = cf.right = mUnrestrictedScreenLeft
4069 + mUnrestrictedScreenWidth;
4070 pf.bottom = df.bottom = of.bottom = cf.bottom = mUnrestrictedScreenTop
4071 + mUnrestrictedScreenHeight;
Joe Onorato29fc2c92010-11-24 10:26:50 -08004072 } else {
Dianne Hackbornc4aad012013-02-22 15:05:25 -08004073 pf.left = df.left = of.left = cf.left = mRestrictedScreenLeft;
4074 pf.top = df.top = of.top = cf.top = mRestrictedScreenTop;
4075 pf.right = df.right = of.right = cf.right = mRestrictedScreenLeft
4076 + mRestrictedScreenWidth;
4077 pf.bottom = df.bottom = of.bottom = cf.bottom = mRestrictedScreenTop
4078 + mRestrictedScreenHeight;
Joe Onorato29fc2c92010-11-24 10:26:50 -08004079 }
Craig Mautner69b08182012-09-05 13:07:13 -07004080
Dianne Hackborn5b5cc4d2012-05-16 13:15:00 -07004081 applyStableConstraints(sysUiFl, fl, cf);
Craig Mautner69b08182012-09-05 13:07:13 -07004082
Dianne Hackborndea3ef72010-10-28 14:24:22 -07004083 if (adjust != SOFT_INPUT_ADJUST_NOTHING) {
4084 vf.left = mCurLeft;
4085 vf.top = mCurTop;
4086 vf.right = mCurRight;
4087 vf.bottom = mCurBottom;
4088 } else {
4089 vf.set(cf);
4090 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004091 } else if (attached != null) {
Craig Mautnereda67292013-04-28 13:50:14 -07004092 if (DEBUG_LAYOUT) Slog.v(TAG, "layoutWindowLw(" + attrs.getTitle() +
4093 "): attached to " + attached);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004094 // A child window should be placed inside of the same visible
4095 // frame that its parent had.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08004096 setAttachedWindowFrames(win, fl, adjust, attached, false, pf, df, of, cf, vf);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004097 } else {
Craig Mautnereda67292013-04-28 13:50:14 -07004098 if (DEBUG_LAYOUT) Slog.v(TAG, "layoutWindowLw(" + attrs.getTitle() +
4099 "): normal window");
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004100 // Otherwise, a normal window must be placed inside the content
4101 // of all screen decorations.
John Spurlock67a0f852015-06-15 15:35:47 -04004102 if (attrs.type == TYPE_STATUS_BAR_PANEL || attrs.type == TYPE_VOLUME_OVERLAY) {
4103 // Status bar panels and the volume dialog are the only windows who can go on
4104 // top of the status bar. They are protected by the STATUS_BAR_SERVICE
Dianne Hackborna239c842011-06-01 12:28:20 -07004105 // permission, so they have the same privileges as the status
4106 // bar itself.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08004107 pf.left = df.left = of.left = cf.left = mRestrictedScreenLeft;
4108 pf.top = df.top = of.top = cf.top = mRestrictedScreenTop;
4109 pf.right = df.right = of.right = cf.right = mRestrictedScreenLeft
4110 + mRestrictedScreenWidth;
4111 pf.bottom = df.bottom = of.bottom = cf.bottom = mRestrictedScreenTop
4112 + mRestrictedScreenHeight;
John Spurlock67a0f852015-06-15 15:35:47 -04004113 } else if (attrs.type == TYPE_TOAST || attrs.type == TYPE_SYSTEM_ALERT) {
John Spurlock414c1f02013-12-04 13:47:36 -05004114 // These dialogs are stable to interim decor changes.
John Spurlockbd957402013-10-03 11:38:39 -04004115 pf.left = df.left = of.left = cf.left = mStableLeft;
4116 pf.top = df.top = of.top = cf.top = mStableTop;
4117 pf.right = df.right = of.right = cf.right = mStableRight;
4118 pf.bottom = df.bottom = of.bottom = cf.bottom = mStableBottom;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004119 } else {
Dianne Hackborna239c842011-06-01 12:28:20 -07004120 pf.left = mContentLeft;
4121 pf.top = mContentTop;
4122 pf.right = mContentRight;
4123 pf.bottom = mContentBottom;
Dianne Hackborn20d94742014-05-29 18:35:45 -07004124 if (win.isVoiceInteraction()) {
4125 df.left = of.left = cf.left = mVoiceContentLeft;
4126 df.top = of.top = cf.top = mVoiceContentTop;
4127 df.right = of.right = cf.right = mVoiceContentRight;
4128 df.bottom = of.bottom = cf.bottom = mVoiceContentBottom;
4129 } else if (adjust != SOFT_INPUT_ADJUST_RESIZE) {
Dianne Hackbornc4aad012013-02-22 15:05:25 -08004130 df.left = of.left = cf.left = mDockLeft;
4131 df.top = of.top = cf.top = mDockTop;
4132 df.right = of.right = cf.right = mDockRight;
4133 df.bottom = of.bottom = cf.bottom = mDockBottom;
Dianne Hackborna239c842011-06-01 12:28:20 -07004134 } else {
Dianne Hackbornc4aad012013-02-22 15:05:25 -08004135 df.left = of.left = cf.left = mContentLeft;
4136 df.top = of.top = cf.top = mContentTop;
4137 df.right = of.right = cf.right = mContentRight;
4138 df.bottom = of.bottom = cf.bottom = mContentBottom;
Dianne Hackborna239c842011-06-01 12:28:20 -07004139 }
4140 if (adjust != SOFT_INPUT_ADJUST_NOTHING) {
4141 vf.left = mCurLeft;
4142 vf.top = mCurTop;
4143 vf.right = mCurRight;
4144 vf.bottom = mCurBottom;
4145 } else {
4146 vf.set(cf);
4147 }
Dianne Hackborndea3ef72010-10-28 14:24:22 -07004148 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004149 }
4150 }
Craig Mautner69b08182012-09-05 13:07:13 -07004151
Craig Mautnerb816bed2013-07-23 10:26:17 -07004152 // TYPE_SYSTEM_ERROR is above the NavigationBar so it can't be allowed to extend over it.
4153 if ((fl & FLAG_LAYOUT_NO_LIMITS) != 0 && attrs.type != TYPE_SYSTEM_ERROR) {
Dianne Hackborn067e5f62014-09-07 23:14:30 -07004154 df.left = df.top = -10000;
4155 df.right = df.bottom = 10000;
4156 if (attrs.type != TYPE_WALLPAPER) {
4157 of.left = of.top = cf.left = cf.top = vf.left = vf.top = -10000;
4158 of.right = of.bottom = cf.right = cf.bottom = vf.right = vf.bottom = 10000;
4159 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004160 }
4161
Filip Gruszczynski2217f612015-05-26 11:32:08 -07004162 // If the device has a chin (e.g. some watches), a dead area at the bottom of the screen we
4163 // need to provide information to the clients that want to pretend that you can draw there.
Filip Gruszczynskib0c673b2015-06-05 09:43:06 -07004164 // We only want to apply outsets to certain types of windows. For example, we never want to
4165 // apply the outsets to floating dialogs, because they wouldn't make sense there.
Filip Gruszczynski2987f612015-06-30 15:03:30 -07004166 final boolean useOutsets = shouldUseOutsets(attrs, fl);
Filip Gruszczynskib0c673b2015-06-05 09:43:06 -07004167 if (isDefaultDisplay && useOutsets) {
Filip Gruszczynski2217f612015-05-26 11:32:08 -07004168 osf = mTmpOutsetFrame;
4169 osf.set(cf.left, cf.top, cf.right, cf.bottom);
4170 int outset = ScreenShapeHelper.getWindowOutsetBottomPx(mContext.getResources());
4171 if (outset > 0) {
Filip Gruszczynski2987f612015-06-30 15:03:30 -07004172 int rotation = mDisplayRotation;
Filip Gruszczynski2217f612015-05-26 11:32:08 -07004173 if (rotation == Surface.ROTATION_0) {
4174 osf.bottom += outset;
4175 } else if (rotation == Surface.ROTATION_90) {
4176 osf.right += outset;
4177 } else if (rotation == Surface.ROTATION_180) {
4178 osf.top -= outset;
4179 } else if (rotation == Surface.ROTATION_270) {
4180 osf.left -= outset;
4181 }
4182 if (DEBUG_LAYOUT) Slog.v(TAG, "applying bottom outset of " + outset
4183 + " with rotation " + rotation + ", result: " + osf);
4184 }
4185 }
4186
Craig Mautnereda67292013-04-28 13:50:14 -07004187 if (DEBUG_LAYOUT) Slog.v(TAG, "Compute frame " + attrs.getTitle()
The Android Open Source Project11267662009-03-18 17:39:47 -07004188 + ": sim=#" + Integer.toHexString(sim)
RoboErik8a2cfc32014-05-16 11:19:38 -07004189 + " attach=" + attached + " type=" + attrs.type
Daniel Sandler8956dbb2011-04-22 07:55:02 -04004190 + String.format(" flags=0x%08x", fl)
The Android Open Source Project11267662009-03-18 17:39:47 -07004191 + " pf=" + pf.toShortString() + " df=" + df.toShortString()
Dianne Hackbornc4aad012013-02-22 15:05:25 -08004192 + " of=" + of.toShortString()
John Spurlock46646232013-09-30 22:32:42 -04004193 + " cf=" + cf.toShortString() + " vf=" + vf.toShortString()
Adrian Roosfa104232014-06-20 16:10:14 -07004194 + " dcf=" + dcf.toShortString()
Filip Gruszczynski2217f612015-05-26 11:32:08 -07004195 + " sf=" + sf.toShortString()
4196 + " osf=" + (osf == null ? "null" : osf.toShortString()));
Craig Mautner69b08182012-09-05 13:07:13 -07004197
Filip Gruszczynski2217f612015-05-26 11:32:08 -07004198 win.computeFrameLw(pf, df, of, cf, vf, dcf, sf, osf);
Craig Mautner69b08182012-09-05 13:07:13 -07004199
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004200 // Dock windows carve out the bottom of the screen, so normal windows
4201 // can't appear underneath them.
Craig Mautner8bd206b2012-10-03 10:32:02 -07004202 if (attrs.type == TYPE_INPUT_METHOD && win.isVisibleOrBehindKeyguardLw()
4203 && !win.getGivenInsetsPendingLw()) {
satok1bc0a492012-04-25 22:47:12 +09004204 setLastInputMethodWindowLw(null, null);
4205 offsetInputMethodWindowLw(win);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004206 }
Dianne Hackborne30e02f2014-05-27 18:24:45 -07004207 if (attrs.type == TYPE_VOICE_INTERACTION && win.isVisibleOrBehindKeyguardLw()
4208 && !win.getGivenInsetsPendingLw()) {
4209 offsetVoiceInputWindowLw(win);
4210 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004211 }
4212
satok1bc0a492012-04-25 22:47:12 +09004213 private void offsetInputMethodWindowLw(WindowState win) {
Craig Mautner4774f6a2015-03-23 11:42:55 -07004214 int top = Math.max(win.getDisplayFrameLw().top, win.getContentFrameLw().top);
satok1bc0a492012-04-25 22:47:12 +09004215 top += win.getGivenContentInsetsLw().top;
4216 if (mContentBottom > top) {
4217 mContentBottom = top;
4218 }
Dianne Hackborne30e02f2014-05-27 18:24:45 -07004219 if (mVoiceContentBottom > top) {
4220 mVoiceContentBottom = top;
4221 }
satok1bc0a492012-04-25 22:47:12 +09004222 top = win.getVisibleFrameLw().top;
4223 top += win.getGivenVisibleInsetsLw().top;
4224 if (mCurBottom > top) {
4225 mCurBottom = top;
4226 }
Craig Mautnereda67292013-04-28 13:50:14 -07004227 if (DEBUG_LAYOUT) Slog.v(TAG, "Input method: mDockBottom="
satok1bc0a492012-04-25 22:47:12 +09004228 + mDockBottom + " mContentBottom="
4229 + mContentBottom + " mCurBottom=" + mCurBottom);
4230 }
4231
Dianne Hackborne30e02f2014-05-27 18:24:45 -07004232 private void offsetVoiceInputWindowLw(WindowState win) {
Craig Mautner4774f6a2015-03-23 11:42:55 -07004233 int top = Math.max(win.getDisplayFrameLw().top, win.getContentFrameLw().top);
Dianne Hackbornae6688b2015-02-11 17:02:41 -08004234 top += win.getGivenContentInsetsLw().top;
4235 if (mVoiceContentBottom > top) {
4236 mVoiceContentBottom = top;
Dianne Hackborne30e02f2014-05-27 18:24:45 -07004237 }
4238 }
4239
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004240 /** {@inheritDoc} */
Craig Mautner61ac6bb2012-02-02 17:29:33 -08004241 @Override
4242 public void finishLayoutLw() {
4243 return;
Dianne Hackborn5f3063e2010-03-10 16:01:58 -08004244 }
4245
4246 /** {@inheritDoc} */
Craig Mautnerad09bcc2012-10-08 13:33:11 -07004247 @Override
Craig Mautner39834192012-09-02 07:47:24 -07004248 public void beginPostLayoutPolicyLw(int displayWidth, int displayHeight) {
Dianne Hackborn5f3063e2010-03-10 16:01:58 -08004249 mTopFullscreenOpaqueWindowState = null;
Adrian Rooscd3884d2015-02-18 17:25:23 +01004250 mTopFullscreenOpaqueOrDimmingWindowState = null;
Craig Mautner2bc789b2014-03-19 19:48:38 -07004251 mAppsToBeHidden.clear();
Jorim Jaggic13fcac2014-09-11 17:36:57 +02004252 mAppsThatDismissKeyguard.clear();
Dianne Hackborn5f3063e2010-03-10 16:01:58 -08004253 mForceStatusBar = false;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07004254 mForceStatusBarFromKeyguard = false;
Selim Cinek4a4a2bddc2015-05-07 12:50:19 -07004255 mForceStatusBarTransparent = false;
Dianne Hackborn891d3fb2013-01-09 18:31:37 -08004256 mForcingShowNavBar = false;
4257 mForcingShowNavBarLayer = -1;
RoboErik8a2cfc32014-05-16 11:19:38 -07004258
Dianne Hackborn5f3063e2010-03-10 16:01:58 -08004259 mHideLockScreen = false;
4260 mAllowLockscreenWhenOn = false;
Craig Mautnerad09bcc2012-10-08 13:33:11 -07004261 mDismissKeyguard = DISMISS_KEYGUARD_NONE;
Dianne Hackborn7ad44382012-10-18 17:46:00 -07004262 mShowingLockscreen = false;
4263 mShowingDream = false;
Craig Mautnerc9457fa2014-06-06 14:27:48 -07004264 mWinShowWhenLocked = null;
Jim Millerab954542014-10-10 18:21:49 -07004265 mKeyguardSecure = isKeyguardSecure();
4266 mKeyguardSecureIncludingHidden = mKeyguardSecure
4267 && (mKeyguardDelegate != null && mKeyguardDelegate.isShowing());
Dianne Hackborn5f3063e2010-03-10 16:01:58 -08004268 }
4269
4270 /** {@inheritDoc} */
Craig Mautnerad09bcc2012-10-08 13:33:11 -07004271 @Override
Craig Mautnerc9457fa2014-06-06 14:27:48 -07004272 public void applyPostLayoutPolicyLw(WindowState win, WindowManager.LayoutParams attrs) {
Dianne Hackbornbc1aa7b2011-09-20 11:20:31 -07004273 if (DEBUG_LAYOUT) Slog.i(TAG, "Win " + win + ": isVisibleOrBehindKeyguardLw="
4274 + win.isVisibleOrBehindKeyguardLw());
John Spurlockc6d1c602014-01-17 15:22:06 -05004275 final int fl = PolicyControl.getWindowFlags(win, attrs);
John Spurlock414c1f02013-12-04 13:47:36 -05004276 if (mTopFullscreenOpaqueWindowState == null
4277 && win.isVisibleLw() && attrs.type == TYPE_INPUT_METHOD) {
4278 mForcingShowNavBar = true;
4279 mForcingShowNavBarLayer = win.getSurfaceLayer();
Dianne Hackborn891d3fb2013-01-09 18:31:37 -08004280 }
Selim Cinek4a4a2bddc2015-05-07 12:50:19 -07004281 if (attrs.type == TYPE_STATUS_BAR) {
4282 if ((attrs.privateFlags & PRIVATE_FLAG_KEYGUARD) != 0) {
4283 mForceStatusBarFromKeyguard = true;
4284 }
4285 if ((attrs.privateFlags & PRIVATE_FLAG_FORCE_STATUS_BAR_VISIBLE_TRANSPARENT) != 0) {
4286 mForceStatusBarTransparent = true;
4287 }
Jorim Jaggiafd4a552014-04-08 15:13:05 +02004288 }
Adrian Roos602c68e2015-04-24 16:03:47 -07004289
4290 boolean appWindow = attrs.type >= FIRST_APPLICATION_WINDOW
4291 && attrs.type < FIRST_SYSTEM_WINDOW;
4292 final boolean showWhenLocked = (fl & FLAG_SHOW_WHEN_LOCKED) != 0;
4293 final boolean dismissKeyguard = (fl & FLAG_DISMISS_KEYGUARD) != 0;
4294
Dianne Hackborn5f3063e2010-03-10 16:01:58 -08004295 if (mTopFullscreenOpaqueWindowState == null &&
Dianne Hackborn01b02a72012-01-12 14:05:03 -08004296 win.isVisibleOrBehindKeyguardLw() && !win.isGoneForLayoutLw()) {
John Spurlockc6d1c602014-01-17 15:22:06 -05004297 if ((fl & FLAG_FORCE_NOT_FULLSCREEN) != 0) {
Jorim Jaggi380ecb82014-03-14 17:25:20 +01004298 if ((attrs.privateFlags & PRIVATE_FLAG_KEYGUARD) != 0) {
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07004299 mForceStatusBarFromKeyguard = true;
4300 } else {
4301 mForceStatusBar = true;
4302 }
4303 }
Jorim Jaggi380ecb82014-03-14 17:25:20 +01004304 if ((attrs.privateFlags & PRIVATE_FLAG_KEYGUARD) != 0) {
Dianne Hackborn7ad44382012-10-18 17:46:00 -07004305 mShowingLockscreen = true;
Dianne Hackbornbc1aa7b2011-09-20 11:20:31 -07004306 }
Dianne Hackborn7ad44382012-10-18 17:46:00 -07004307 if (attrs.type == TYPE_DREAM) {
Jeff Brownc8018eb2012-10-29 21:33:27 -07004308 // If the lockscreen was showing when the dream started then wait
4309 // for the dream to draw before hiding the lockscreen.
4310 if (!mDreamingLockscreen
4311 || (win.isVisibleLw() && win.hasDrawnLw())) {
4312 mShowingDream = true;
Craig Mautnerab55e522014-03-03 13:26:03 -08004313 appWindow = true;
Dianne Hackborn7ad44382012-10-18 17:46:00 -07004314 }
4315 }
Craig Mautnerab55e522014-03-03 13:26:03 -08004316
Craig Mautnerab55e522014-03-03 13:26:03 -08004317 if (appWindow) {
Jorim Jaggic13fcac2014-09-11 17:36:57 +02004318 final IApplicationToken appToken = win.getAppToken();
4319 if (showWhenLocked) {
Craig Mautnerc9457fa2014-06-06 14:27:48 -07004320 // Remove any previous windows with the same appToken.
Jorim Jaggic13fcac2014-09-11 17:36:57 +02004321 mAppsToBeHidden.remove(appToken);
4322 mAppsThatDismissKeyguard.remove(appToken);
Craig Mautnerca0a1242014-12-02 12:25:14 -08004323 if (mAppsToBeHidden.isEmpty()) {
Craig Mautner192d6042014-12-02 23:24:48 -08004324 if (dismissKeyguard && !mKeyguardSecure) {
4325 mAppsThatDismissKeyguard.add(appToken);
4326 } else {
Craig Mautnerca0a1242014-12-02 12:25:14 -08004327 mWinShowWhenLocked = win;
4328 mHideLockScreen = true;
4329 mForceStatusBarFromKeyguard = false;
Craig Mautnerca0a1242014-12-02 12:25:14 -08004330 }
Craig Mautnerc9457fa2014-06-06 14:27:48 -07004331 }
Jorim Jaggic13fcac2014-09-11 17:36:57 +02004332 } else if (dismissKeyguard) {
Jim Millerab954542014-10-10 18:21:49 -07004333 if (mKeyguardSecure) {
Jorim Jaggic13fcac2014-09-11 17:36:57 +02004334 mAppsToBeHidden.add(appToken);
4335 } else {
4336 mAppsToBeHidden.remove(appToken);
4337 }
4338 mAppsThatDismissKeyguard.add(appToken);
Craig Mautner2bc789b2014-03-19 19:48:38 -07004339 } else {
Jorim Jaggic13fcac2014-09-11 17:36:57 +02004340 mAppsToBeHidden.add(appToken);
Craig Mautner2bc789b2014-03-19 19:48:38 -07004341 }
Craig Mautnerab55e522014-03-03 13:26:03 -08004342 if (attrs.x == 0 && attrs.y == 0
4343 && attrs.width == WindowManager.LayoutParams.MATCH_PARENT
4344 && attrs.height == WindowManager.LayoutParams.MATCH_PARENT) {
4345 if (DEBUG_LAYOUT) Slog.v(TAG, "Fullscreen window: " + win);
4346 mTopFullscreenOpaqueWindowState = win;
Adrian Rooscd3884d2015-02-18 17:25:23 +01004347 if (mTopFullscreenOpaqueOrDimmingWindowState == null) {
4348 mTopFullscreenOpaqueOrDimmingWindowState = win;
4349 }
Jorim Jaggic13fcac2014-09-11 17:36:57 +02004350 if (!mAppsThatDismissKeyguard.isEmpty() &&
4351 mDismissKeyguard == DISMISS_KEYGUARD_NONE) {
4352 if (DEBUG_LAYOUT) Slog.v(TAG,
4353 "Setting mDismissKeyguard true by win " + win);
tingna_sunge785ffa2015-05-12 13:23:15 +08004354 mDismissKeyguard = (mWinDismissingKeyguard == win
4355 && mSecureDismissingKeyguard == mKeyguardSecure)
4356 ? DISMISS_KEYGUARD_CONTINUE : DISMISS_KEYGUARD_START;
Jorim Jaggic13fcac2014-09-11 17:36:57 +02004357 mWinDismissingKeyguard = win;
tingna_sunge785ffa2015-05-12 13:23:15 +08004358 mSecureDismissingKeyguard = mKeyguardSecure;
Jim Millerab954542014-10-10 18:21:49 -07004359 mForceStatusBarFromKeyguard = mShowingLockscreen && mKeyguardSecure;
Jorim Jaggic13fcac2014-09-11 17:36:57 +02004360 } else if (mAppsToBeHidden.isEmpty() && showWhenLocked) {
4361 if (DEBUG_LAYOUT) Slog.v(TAG,
4362 "Setting mHideLockScreen to true by win " + win);
4363 mHideLockScreen = true;
4364 mForceStatusBarFromKeyguard = false;
Craig Mautnerab55e522014-03-03 13:26:03 -08004365 }
Craig Mautner00156ec2014-03-06 22:29:02 -08004366 if ((fl & FLAG_ALLOW_LOCK_WHILE_SCREEN_ON) != 0) {
Craig Mautnerab55e522014-03-03 13:26:03 -08004367 mAllowLockscreenWhenOn = true;
4368 }
Dianne Hackborn5f3063e2010-03-10 16:01:58 -08004369 }
Craig Mautnerc9457fa2014-06-06 14:27:48 -07004370
4371 if (mWinShowWhenLocked != null &&
Adrian Roos602c68e2015-04-24 16:03:47 -07004372 mWinShowWhenLocked.getAppToken() != win.getAppToken() &&
4373 (attrs.flags & FLAG_SHOW_WHEN_LOCKED) == 0) {
Craig Mautnerc9457fa2014-06-06 14:27:48 -07004374 win.hideLw(false);
4375 }
Dianne Hackborn5f3063e2010-03-10 16:01:58 -08004376 }
Adrian Roos602c68e2015-04-24 16:03:47 -07004377 } else if (mTopFullscreenOpaqueWindowState == null && mWinShowWhenLocked == null) {
4378 // No TopFullscreenOpaqueWindow is showing, but we found a SHOW_WHEN_LOCKED window
4379 // that is being hidden in an animation - keep the
4380 // keyguard hidden until the new window shows up and
4381 // we know whether to show the keyguard or not.
Adrian Roosb85e1ec2015-05-29 15:23:18 -07004382 if (win.isAnimatingLw() && appWindow && showWhenLocked && mKeyguardHidden) {
Adrian Roos602c68e2015-04-24 16:03:47 -07004383 mHideLockScreen = true;
4384 mWinShowWhenLocked = win;
4385 }
Dianne Hackborn5f3063e2010-03-10 16:01:58 -08004386 }
Adrian Rooscd3884d2015-02-18 17:25:23 +01004387 if (mTopFullscreenOpaqueOrDimmingWindowState == null
4388 && win.isVisibleOrBehindKeyguardLw() && !win.isGoneForLayoutLw()
4389 && win.isDimming()) {
4390 mTopFullscreenOpaqueOrDimmingWindowState = win;
4391 }
Dianne Hackborn5f3063e2010-03-10 16:01:58 -08004392 }
4393
4394 /** {@inheritDoc} */
Craig Mautnerad09bcc2012-10-08 13:33:11 -07004395 @Override
Craig Mautner39834192012-09-02 07:47:24 -07004396 public int finishPostLayoutPolicyLw() {
Craig Mautnerc5e73bf2015-04-21 15:41:26 +00004397 if (mWinShowWhenLocked != null && mTopFullscreenOpaqueWindowState != null &&
4398 mWinShowWhenLocked.getAppToken() != mTopFullscreenOpaqueWindowState.getAppToken()
4399 && isKeyguardLocked()) {
Craig Mautnerc9457fa2014-06-06 14:27:48 -07004400 // A dialog is dismissing the keyguard. Put the wallpaper behind it and hide the
4401 // fullscreen window.
4402 // TODO: Make sure FLAG_SHOW_WALLPAPER is restored when dialog is dismissed. Or not.
4403 mWinShowWhenLocked.getAttrs().flags |= FLAG_SHOW_WALLPAPER;
4404 mTopFullscreenOpaqueWindowState.hideLw(false);
4405 mTopFullscreenOpaqueWindowState = mWinShowWhenLocked;
4406 }
4407
Dianne Hackborn39c2d712009-09-22 11:41:31 -07004408 int changes = 0;
Joe Onorato93056472010-09-10 10:30:46 -04004409 boolean topIsFullscreen = false;
Daniel Sandlere02d8082010-10-08 15:13:22 -04004410
4411 final WindowManager.LayoutParams lp = (mTopFullscreenOpaqueWindowState != null)
4412 ? mTopFullscreenOpaqueWindowState.getAttrs()
4413 : null;
4414
Jeff Brownc8018eb2012-10-29 21:33:27 -07004415 // If we are not currently showing a dream then remember the current
4416 // lockscreen state. We will use this to determine whether the dream
4417 // started while the lockscreen was showing and remember this state
4418 // while the dream is showing.
Dianne Hackborn7ad44382012-10-18 17:46:00 -07004419 if (!mShowingDream) {
4420 mDreamingLockscreen = mShowingLockscreen;
Jeff Brown061ea992015-04-17 19:55:47 -07004421 if (mDreamingSleepTokenNeeded) {
4422 mDreamingSleepTokenNeeded = false;
4423 mHandler.obtainMessage(MSG_UPDATE_DREAMING_SLEEP_TOKEN, 0, 1).sendToTarget();
4424 }
4425 } else {
4426 if (!mDreamingSleepTokenNeeded) {
4427 mDreamingSleepTokenNeeded = true;
4428 mHandler.obtainMessage(MSG_UPDATE_DREAMING_SLEEP_TOKEN, 1, 1).sendToTarget();
4429 }
Dianne Hackborn7ad44382012-10-18 17:46:00 -07004430 }
4431
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004432 if (mStatusBar != null) {
Craig Mautnereda67292013-04-28 13:50:14 -07004433 if (DEBUG_LAYOUT) Slog.i(TAG, "force=" + mForceStatusBar
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07004434 + " forcefkg=" + mForceStatusBarFromKeyguard
Dianne Hackbornd70bc2f2009-10-06 23:25:51 -07004435 + " top=" + mTopFullscreenOpaqueWindowState);
Selim Cinek4a4a2bddc2015-05-07 12:50:19 -07004436 boolean shouldBeTransparent = mForceStatusBarTransparent
4437 && !mForceStatusBar
4438 && !mForceStatusBarFromKeyguard;
4439 if (!shouldBeTransparent) {
4440 mStatusBarController.setShowTransparent(false /* transparent */);
4441 } else if (!mStatusBar.isVisibleLw()) {
4442 mStatusBarController.setShowTransparent(true /* transparent */);
4443 }
4444 if (mForceStatusBar || mForceStatusBarFromKeyguard || mForceStatusBarTransparent) {
Craig Mautnereda67292013-04-28 13:50:14 -07004445 if (DEBUG_LAYOUT) Slog.v(TAG, "Showing status bar: forced");
John Spurlock27735a42013-08-14 17:57:38 -04004446 if (mStatusBarController.setBarShowingLw(true)) {
4447 changes |= FINISH_LAYOUT_REDO_LAYOUT;
4448 }
Craig Mautner81defc72013-10-29 11:10:42 -07004449 // Maintain fullscreen layout until incoming animation is complete.
4450 topIsFullscreen = mTopIsFullscreen && mStatusBar.isAnimatingLw();
John Spurlockf92b6162013-11-11 15:01:16 -05004451 // Transient status bar on the lockscreen is not allowed
4452 if (mForceStatusBarFromKeyguard && mStatusBarController.isTransientShowing()) {
4453 mStatusBarController.updateVisibilityLw(false /*transientAllowed*/,
4454 mLastSystemUiFlags, mLastSystemUiFlags);
4455 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004456 } else if (mTopFullscreenOpaqueWindowState != null) {
John Spurlockc6d1c602014-01-17 15:22:06 -05004457 final int fl = PolicyControl.getWindowFlags(null, lp);
Joe Onorato93056472010-09-10 10:30:46 -04004458 if (localLOGV) {
Craig Mautnereda67292013-04-28 13:50:14 -07004459 Slog.d(TAG, "frame: " + mTopFullscreenOpaqueWindowState.getFrameLw()
Joe Onorato93056472010-09-10 10:30:46 -04004460 + " shown frame: " + mTopFullscreenOpaqueWindowState.getShownFrameLw());
Craig Mautnereda67292013-04-28 13:50:14 -07004461 Slog.d(TAG, "attr: " + mTopFullscreenOpaqueWindowState.getAttrs()
John Spurlockc6d1c602014-01-17 15:22:06 -05004462 + " lp.flags=0x" + Integer.toHexString(fl));
Joe Onorato93056472010-09-10 10:30:46 -04004463 }
John Spurlockc6d1c602014-01-17 15:22:06 -05004464 topIsFullscreen = (fl & WindowManager.LayoutParams.FLAG_FULLSCREEN) != 0
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07004465 || (mLastSystemUiFlags & View.SYSTEM_UI_FLAG_FULLSCREEN) != 0;
Joe Onorato93056472010-09-10 10:30:46 -04004466 // The subtle difference between the window for mTopFullscreenOpaqueWindowState
Mark Dolinerd0646dc2014-08-27 16:04:02 -07004467 // and mTopIsFullscreen is that mTopIsFullscreen is set only if the window
Joe Onorato93056472010-09-10 10:30:46 -04004468 // has the FLAG_FULLSCREEN set. Not sure if there is another way that to be the
4469 // case though.
John Spurlock27735a42013-08-14 17:57:38 -04004470 if (mStatusBarController.isTransientShowing()) {
4471 if (mStatusBarController.setBarShowingLw(true)) {
John Spurlock32beb2c2013-03-11 10:16:47 -04004472 changes |= FINISH_LAYOUT_REDO_LAYOUT;
4473 }
4474 } else if (topIsFullscreen) {
Craig Mautnereda67292013-04-28 13:50:14 -07004475 if (DEBUG_LAYOUT) Slog.v(TAG, "** HIDING status bar");
John Spurlock27735a42013-08-14 17:57:38 -04004476 if (mStatusBarController.setBarShowingLw(false)) {
Dianne Hackbornf87d1962012-04-04 12:48:24 -07004477 changes |= FINISH_LAYOUT_REDO_LAYOUT;
Craig Mautnereda67292013-04-28 13:50:14 -07004478 } else {
Craig Mautnerc5a6e442013-06-05 17:22:35 -07004479 if (DEBUG_LAYOUT) Slog.v(TAG, "Status bar already hiding");
Daniel Sandler40427442010-07-16 11:44:52 -04004480 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004481 } else {
Craig Mautnereda67292013-04-28 13:50:14 -07004482 if (DEBUG_LAYOUT) Slog.v(TAG, "** SHOWING status bar: top is not fullscreen");
John Spurlock27735a42013-08-14 17:57:38 -04004483 if (mStatusBarController.setBarShowingLw(true)) {
4484 changes |= FINISH_LAYOUT_REDO_LAYOUT;
4485 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004486 }
4487 }
4488 }
Daniel Sandlere02d8082010-10-08 15:13:22 -04004489
Craig Mautner81defc72013-10-29 11:10:42 -07004490 if (mTopIsFullscreen != topIsFullscreen) {
4491 if (!topIsFullscreen) {
4492 // Force another layout when status bar becomes fully shown.
4493 changes |= FINISH_LAYOUT_REDO_LAYOUT;
4494 }
4495 mTopIsFullscreen = topIsFullscreen;
4496 }
Daniel Sandlere02d8082010-10-08 15:13:22 -04004497
Craig Mautner39834192012-09-02 07:47:24 -07004498 // Hide the key guard if a visible window explicitly specifies that it wants to be
4499 // displayed when the screen is locked.
Jorim Jaggi5cf17872014-03-26 18:31:48 +01004500 if (mKeyguardDelegate != null && mStatusBar != null) {
4501 if (localLOGV) Slog.v(TAG, "finishPostLayoutPolicyLw: mHideKeyguard="
4502 + mHideLockScreen);
Jim Millerab954542014-10-10 18:21:49 -07004503 if (mDismissKeyguard != DISMISS_KEYGUARD_NONE && !mKeyguardSecure) {
Jorim Jaggi5cf17872014-03-26 18:31:48 +01004504 mKeyguardHidden = true;
Jim Millerab954542014-10-10 18:21:49 -07004505 if (setKeyguardOccludedLw(true)) {
Dianne Hackborn39c2d712009-09-22 11:41:31 -07004506 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 (mKeyguardDelegate.isShowing()) {
4511 mHandler.post(new Runnable() {
4512 @Override
4513 public void run() {
4514 mKeyguardDelegate.keyguardDone(false, false);
4515 }
4516 });
4517 }
4518 } else if (mHideLockScreen) {
4519 mKeyguardHidden = true;
Jorim Jaggi7d85ea92015-05-20 17:20:40 -07004520 mWinDismissingKeyguard = null;
Jim Millerab954542014-10-10 18:21:49 -07004521 if (setKeyguardOccludedLw(true)) {
Jorim Jaggi5cf17872014-03-26 18:31:48 +01004522 changes |= FINISH_LAYOUT_REDO_LAYOUT
4523 | FINISH_LAYOUT_REDO_CONFIG
4524 | FINISH_LAYOUT_REDO_WALLPAPER;
4525 }
4526 } else if (mDismissKeyguard != DISMISS_KEYGUARD_NONE) {
Jorim Jaggi7d85ea92015-05-20 17:20:40 -07004527 mKeyguardHidden = false;
4528 if (setKeyguardOccludedLw(false)) {
4529 changes |= FINISH_LAYOUT_REDO_LAYOUT
4530 | FINISH_LAYOUT_REDO_CONFIG
4531 | FINISH_LAYOUT_REDO_WALLPAPER;
4532 }
Jorim Jaggi5cf17872014-03-26 18:31:48 +01004533 if (mDismissKeyguard == DISMISS_KEYGUARD_START) {
4534 // Only launch the next keyguard unlock window once per window.
Jorim Jaggi5cf17872014-03-26 18:31:48 +01004535 mHandler.post(new Runnable() {
4536 @Override
4537 public void run() {
4538 mKeyguardDelegate.dismiss();
4539 }
4540 });
4541 }
4542 } else {
4543 mWinDismissingKeyguard = null;
tingna_sunge785ffa2015-05-12 13:23:15 +08004544 mSecureDismissingKeyguard = false;
Jorim Jaggi5cf17872014-03-26 18:31:48 +01004545 mKeyguardHidden = false;
Jim Millerab954542014-10-10 18:21:49 -07004546 if (setKeyguardOccludedLw(false)) {
Jorim Jaggi5cf17872014-03-26 18:31:48 +01004547 changes |= FINISH_LAYOUT_REDO_LAYOUT
4548 | FINISH_LAYOUT_REDO_CONFIG
4549 | FINISH_LAYOUT_REDO_WALLPAPER;
4550 }
Suchi Amalapurapu9cdc9032009-05-14 18:01:07 -07004551 }
4552 }
Joe Onorato664644d2011-01-23 17:53:23 -08004553
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07004554 if ((updateSystemUiVisibilityLw()&SYSTEM_UI_CHANGING_LAYOUT) != 0) {
Dianne Hackborndf89e652011-10-06 22:35:11 -07004555 // If the navigation bar has been hidden or shown, we need to do another
4556 // layout pass to update that window.
4557 changes |= FINISH_LAYOUT_REDO_LAYOUT;
4558 }
Joe Onorato664644d2011-01-23 17:53:23 -08004559
Mike Lockwood28569302010-01-28 11:54:40 -05004560 // update since mAllowLockscreenWhenOn might have changed
4561 updateLockScreenTimeout();
Dianne Hackborn39c2d712009-09-22 11:41:31 -07004562 return changes;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004563 }
4564
Jorim Jaggi380ecb82014-03-14 17:25:20 +01004565 /**
Jim Millerab954542014-10-10 18:21:49 -07004566 * Updates the occluded state of the Keyguard.
Jorim Jaggi380ecb82014-03-14 17:25:20 +01004567 *
Jorim Jaggi380ecb82014-03-14 17:25:20 +01004568 * @return Whether the flags have changed and we have to redo the layout.
4569 */
Jim Millerab954542014-10-10 18:21:49 -07004570 private boolean setKeyguardOccludedLw(boolean isOccluded) {
4571 boolean wasOccluded = mKeyguardOccluded;
4572 boolean showing = mKeyguardDelegate.isShowing();
4573 if (wasOccluded && !isOccluded && showing) {
4574 mKeyguardOccluded = false;
4575 mKeyguardDelegate.setOccluded(false);
Jorim Jaggi380ecb82014-03-14 17:25:20 +01004576 mStatusBar.getAttrs().privateFlags |= PRIVATE_FLAG_KEYGUARD;
4577 mStatusBar.getAttrs().flags |= FLAG_SHOW_WALLPAPER;
4578 return true;
Jim Millerab954542014-10-10 18:21:49 -07004579 } else if (!wasOccluded && isOccluded && showing) {
4580 mKeyguardOccluded = true;
4581 mKeyguardDelegate.setOccluded(true);
Jorim Jaggi380ecb82014-03-14 17:25:20 +01004582 mStatusBar.getAttrs().privateFlags &= ~PRIVATE_FLAG_KEYGUARD;
4583 mStatusBar.getAttrs().flags &= ~FLAG_SHOW_WALLPAPER;
4584 return true;
4585 } else {
4586 return false;
4587 }
4588 }
4589
4590 private boolean isStatusBarKeyguard() {
4591 return mStatusBar != null
4592 && (mStatusBar.getAttrs().privateFlags & PRIVATE_FLAG_KEYGUARD) != 0;
4593 }
4594
Jose Lima9546b202014-07-02 17:21:51 -07004595 @Override
Dianne Hackborn08743722009-12-21 12:16:51 -08004596 public boolean allowAppAnimationsLw() {
Jorim Jaggi380ecb82014-03-14 17:25:20 +01004597 if (isStatusBarKeyguard() || mShowingDream) {
Craig Mautner28816302013-10-10 20:31:00 -07004598 // If keyguard or dreams is currently visible, no reason to animate behind it.
Dianne Hackborn08743722009-12-21 12:16:51 -08004599 return false;
4600 }
Dianne Hackborn08743722009-12-21 12:16:51 -08004601 return true;
4602 }
4603
Jose Lima9546b202014-07-02 17:21:51 -07004604 @Override
Dianne Hackborndf89e652011-10-06 22:35:11 -07004605 public int focusChangedLw(WindowState lastFocus, WindowState newFocus) {
Joe Onorato664644d2011-01-23 17:53:23 -08004606 mFocusedWindow = newFocus;
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07004607 if ((updateSystemUiVisibilityLw()&SYSTEM_UI_CHANGING_LAYOUT) != 0) {
Dianne Hackborndf89e652011-10-06 22:35:11 -07004608 // If the navigation bar has been hidden or shown, we need to do another
4609 // layout pass to update that window.
4610 return FINISH_LAYOUT_REDO_LAYOUT;
4611 }
4612 return 0;
Joe Onorato664644d2011-01-23 17:53:23 -08004613 }
4614
Dianne Hackborn0ecadf72009-03-31 18:00:37 -07004615 /** {@inheritDoc} */
Jose Lima9546b202014-07-02 17:21:51 -07004616 @Override
Jeff Brown46b9ac02010-04-22 18:58:52 -07004617 public void notifyLidSwitchChanged(long whenNanos, boolean lidOpen) {
4618 // lid changed state
Jeff Brownc458ce92012-04-30 14:58:40 -07004619 final int newLidState = lidOpen ? LID_OPEN : LID_CLOSED;
4620 if (newLidState == mLidState) {
4621 return;
4622 }
Jeff Brown01a98dd2011-09-20 15:08:29 -07004623
Jeff Brownc458ce92012-04-30 14:58:40 -07004624 mLidState = newLidState;
4625 applyLidSwitchState();
Jeff Brown01a98dd2011-09-20 15:08:29 -07004626 updateRotation(true);
Jeff Brownc458ce92012-04-30 14:58:40 -07004627
4628 if (lidOpen) {
Bryce Lee584a4452014-10-21 15:55:55 -07004629 wakeUp(SystemClock.uptimeMillis(), mAllowTheaterModeWakeFromLidSwitch);
Jeff Brownc458ce92012-04-30 14:58:40 -07004630 } else if (!mLidControlsSleep) {
Jeff Brown96307042012-07-27 15:51:34 -07004631 mPowerManager.userActivity(SystemClock.uptimeMillis(), false);
Jeff Brown46b9ac02010-04-22 18:58:52 -07004632 }
4633 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004634
Michael Wright3818c922014-09-02 13:59:07 -07004635 @Override
4636 public void notifyCameraLensCoverSwitchChanged(long whenNanos, boolean lensCovered) {
4637 int lensCoverState = lensCovered ? CAMERA_LENS_COVERED : CAMERA_LENS_UNCOVERED;
4638 if (mCameraLensCoverState == lensCoverState) {
4639 return;
4640 }
4641 if (mCameraLensCoverState == CAMERA_LENS_COVERED &&
4642 lensCoverState == CAMERA_LENS_UNCOVERED) {
4643 Intent intent;
4644 final boolean keyguardActive = mKeyguardDelegate == null ? false :
4645 mKeyguardDelegate.isShowing();
4646 if (keyguardActive) {
4647 intent = new Intent(MediaStore.INTENT_ACTION_STILL_IMAGE_CAMERA_SECURE);
4648 } else {
4649 intent = new Intent(MediaStore.INTENT_ACTION_STILL_IMAGE_CAMERA);
4650 }
Bryce Lee584a4452014-10-21 15:55:55 -07004651 wakeUp(whenNanos / 1000000, mAllowTheaterModeWakeFromCameraLens);
Bart Sears8b1c27c2015-03-18 23:51:02 +00004652 startActivityAsUser(intent, UserHandle.CURRENT_OR_SELF);
Michael Wright3818c922014-09-02 13:59:07 -07004653 }
4654 mCameraLensCoverState = lensCoverState;
4655 }
4656
Dianne Hackbornad7fa7f2011-01-07 14:06:50 -08004657 void setHdmiPlugged(boolean plugged) {
4658 if (mHdmiPlugged != plugged) {
4659 mHdmiPlugged = plugged;
Dianne Hackbornf87d1962012-04-04 12:48:24 -07004660 updateRotation(true, true);
Dianne Hackbornad7fa7f2011-01-07 14:06:50 -08004661 Intent intent = new Intent(ACTION_HDMI_PLUGGED);
Joe Onoratodc100302011-01-11 17:07:41 -08004662 intent.addFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY_BEFORE_BOOT);
Dianne Hackbornad7fa7f2011-01-07 14:06:50 -08004663 intent.putExtra(EXTRA_HDMI_PLUGGED_STATE, plugged);
Dianne Hackborn5ac72a22012-08-29 18:32:08 -07004664 mContext.sendStickyBroadcastAsUser(intent, UserHandle.ALL);
Dianne Hackbornad7fa7f2011-01-07 14:06:50 -08004665 }
4666 }
4667
Joe Onoratoea495d42011-04-06 11:41:11 -07004668 void initializeHdmiState() {
Joe Onorato7ba631f2011-05-04 15:28:00 -07004669 boolean plugged = false;
Joe Onoratoea495d42011-04-06 11:41:11 -07004670 // watch for HDMI plug messages if the hdmi switch exists
4671 if (new File("/sys/devices/virtual/switch/hdmi/state").exists()) {
4672 mHDMIObserver.startObserving("DEVPATH=/devices/virtual/switch/hdmi");
4673
Joe Onoratoea495d42011-04-06 11:41:11 -07004674 final String filename = "/sys/class/switch/hdmi/state";
4675 FileReader reader = null;
4676 try {
4677 reader = new FileReader(filename);
4678 char[] buf = new char[15];
4679 int n = reader.read(buf);
4680 if (n > 1) {
4681 plugged = 0 != Integer.parseInt(new String(buf, 0, n-1));
4682 }
4683 } catch (IOException ex) {
4684 Slog.w(TAG, "Couldn't read hdmi state from " + filename + ": " + ex);
4685 } catch (NumberFormatException ex) {
4686 Slog.w(TAG, "Couldn't read hdmi state from " + filename + ": " + ex);
4687 } finally {
4688 if (reader != null) {
4689 try {
4690 reader.close();
4691 } catch (IOException ex) {
4692 }
Joe Onoratodc100302011-01-11 17:07:41 -08004693 }
4694 }
4695 }
Joe Onorato7ba631f2011-05-04 15:28:00 -07004696 // This dance forces the code in setHdmiPlugged to run.
4697 // Always do this so the sticky intent is stuck (to false) if there is no hdmi.
4698 mHdmiPlugged = !plugged;
4699 setHdmiPlugged(!mHdmiPlugged);
Joe Onoratodc100302011-01-11 17:07:41 -08004700 }
4701
Dianne Hackbornc0e3f242011-08-19 14:19:10 -07004702 final Object mScreenshotLock = new Object();
Dianne Hackbornfc8fa632011-08-17 16:20:47 -07004703 ServiceConnection mScreenshotConnection = null;
Dianne Hackbornfc8fa632011-08-17 16:20:47 -07004704
Jeff Brownd5bb82d2011-10-12 13:57:59 -07004705 final Runnable mScreenshotTimeout = new Runnable() {
4706 @Override public void run() {
4707 synchronized (mScreenshotLock) {
4708 if (mScreenshotConnection != null) {
4709 mContext.unbindService(mScreenshotConnection);
4710 mScreenshotConnection = null;
Dianne Hackbornfc8fa632011-08-17 16:20:47 -07004711 }
Winson Chung9112ec32011-06-27 13:15:32 -07004712 }
Jeff Brownd5bb82d2011-10-12 13:57:59 -07004713 }
4714 };
4715
4716 // Assume this is called from the Handler thread.
4717 private void takeScreenshot() {
4718 synchronized (mScreenshotLock) {
4719 if (mScreenshotConnection != null) {
4720 return;
4721 }
4722 ComponentName cn = new ComponentName("com.android.systemui",
4723 "com.android.systemui.screenshot.TakeScreenshotService");
4724 Intent intent = new Intent();
4725 intent.setComponent(cn);
4726 ServiceConnection conn = new ServiceConnection() {
4727 @Override
4728 public void onServiceConnected(ComponentName name, IBinder service) {
4729 synchronized (mScreenshotLock) {
4730 if (mScreenshotConnection != this) {
4731 return;
4732 }
4733 Messenger messenger = new Messenger(service);
4734 Message msg = Message.obtain(null, 1);
4735 final ServiceConnection myConn = this;
4736 Handler h = new Handler(mHandler.getLooper()) {
4737 @Override
4738 public void handleMessage(Message msg) {
4739 synchronized (mScreenshotLock) {
4740 if (mScreenshotConnection == myConn) {
4741 mContext.unbindService(mScreenshotConnection);
4742 mScreenshotConnection = null;
4743 mHandler.removeCallbacks(mScreenshotTimeout);
4744 }
4745 }
4746 }
4747 };
4748 msg.replyTo = new Messenger(h);
Winson Chunga63bb842011-10-17 10:26:28 -07004749 msg.arg1 = msg.arg2 = 0;
4750 if (mStatusBar != null && mStatusBar.isVisibleLw())
4751 msg.arg1 = 1;
4752 if (mNavigationBar != null && mNavigationBar.isVisibleLw())
4753 msg.arg2 = 1;
Jeff Brownd5bb82d2011-10-12 13:57:59 -07004754 try {
4755 messenger.send(msg);
4756 } catch (RemoteException e) {
4757 }
4758 }
4759 }
4760 @Override
4761 public void onServiceDisconnected(ComponentName name) {}
4762 };
Amith Yamasani27b89e62013-01-16 12:30:11 -08004763 if (mContext.bindServiceAsUser(
4764 intent, conn, Context.BIND_AUTO_CREATE, UserHandle.CURRENT)) {
Jeff Brownd5bb82d2011-10-12 13:57:59 -07004765 mScreenshotConnection = conn;
4766 mHandler.postDelayed(mScreenshotTimeout, 10000);
4767 }
4768 }
Winson Chung9112ec32011-06-27 13:15:32 -07004769 }
4770
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004771 /** {@inheritDoc} */
Jeff Brown00fa7bd2010-07-02 15:37:36 -07004772 @Override
Jeff Brown037c33e2014-04-09 00:31:55 -07004773 public int interceptKeyBeforeQueueing(KeyEvent event, int policyFlags) {
Jeff Brown96307042012-07-27 15:51:34 -07004774 if (!mSystemBooted) {
4775 // If we have not yet booted, don't let key events do anything.
4776 return 0;
4777 }
4778
Jeff Brown037c33e2014-04-09 00:31:55 -07004779 final boolean interactive = (policyFlags & FLAG_INTERACTIVE) != 0;
Jeff Brown1f245102010-11-18 20:53:46 -08004780 final boolean down = event.getAction() == KeyEvent.ACTION_DOWN;
4781 final boolean canceled = event.isCanceled();
4782 final int keyCode = event.getKeyCode();
Jeff Browne20c9e02010-10-11 14:20:19 -07004783
Jeff Brown3122e442010-10-11 23:32:49 -07004784 final boolean isInjected = (policyFlags & WindowManagerPolicy.FLAG_INJECTED) != 0;
Jeff Brown3122e442010-10-11 23:32:49 -07004785
Mike Lockwoodc72b15f2009-11-28 20:58:22 -05004786 // If screen is off then we treat the case where the keyguard is open but hidden
4787 // the same as if it were open and in front.
4788 // This will prevent any keys other than the power button from waking the screen
4789 // when the keyguard is hidden by another activity.
Jim Miller5ecd8112013-01-09 18:50:26 -08004790 final boolean keyguardActive = (mKeyguardDelegate == null ? false :
Jeff Brown037c33e2014-04-09 00:31:55 -07004791 (interactive ?
Jim Millerab954542014-10-10 18:21:49 -07004792 isKeyguardShowingAndNotOccluded() :
Jim Miller5ecd8112013-01-09 18:50:26 -08004793 mKeyguardDelegate.isShowing()));
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004794
Jeff Brown40013652012-05-16 21:22:36 -07004795 if (DEBUG_INPUT) {
Jeff Brown00fa7bd2010-07-02 15:37:36 -07004796 Log.d(TAG, "interceptKeyTq keycode=" + keyCode
Jeff Brown037c33e2014-04-09 00:31:55 -07004797 + " interactive=" + interactive + " keyguardActive=" + keyguardActive
Jeff Brown26875502014-01-30 21:47:47 -08004798 + " policyFlags=" + Integer.toHexString(policyFlags));
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004799 }
4800
Jeff Brown037c33e2014-04-09 00:31:55 -07004801 // Basic policy based on interactive state.
Jeff Brown4d396052010-10-29 21:50:21 -07004802 int result;
Michael Wright337d9d22014-04-22 15:03:48 -07004803 boolean isWakeKey = (policyFlags & WindowManagerPolicy.FLAG_WAKE) != 0
4804 || event.isWakeKey();
Michael Wrightfc01f042014-09-08 14:12:24 -07004805 if (interactive || (isInjected && !isWakeKey)) {
RoboErikde9ba392014-09-26 12:51:01 -07004806 // When the device is interactive or the key is injected pass the
4807 // key to the application.
Jeff Brown4d396052010-10-29 21:50:21 -07004808 result = ACTION_PASS_TO_USER;
Jose Lima9546b202014-07-02 17:21:51 -07004809 isWakeKey = false;
Michael Wrightfc01f042014-09-08 14:12:24 -07004810 } else if (!interactive && shouldDispatchInputWhenNonInteractive()) {
4811 // If we're currently dozing with the screen on and the keyguard showing, pass the key
4812 // to the application but preserve its wake key status to make sure we still move
4813 // from dozing to fully interactive if we would normally go from off to fully
4814 // interactive.
4815 result = ACTION_PASS_TO_USER;
Jeff Brown4d396052010-10-29 21:50:21 -07004816 } else {
4817 // When the screen is off and the key is not injected, determine whether
4818 // to wake the device but don't pass the key to the application.
4819 result = 0;
Jeff Brown26875502014-01-30 21:47:47 -08004820 if (isWakeKey && (!down || !isWakeKeyWhenScreenOff(keyCode))) {
4821 isWakeKey = false;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004822 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004823 }
4824
Justin Kohd378ad72013-04-01 12:18:26 -07004825 // If the key would be handled globally, just return the result, don't worry about special
4826 // key processing.
Jeff Brown13f00f02014-10-31 14:45:50 -07004827 if (isValidGlobalKey(keyCode)
4828 && mGlobalKeyManager.shouldHandleGlobalKey(keyCode, event)) {
Michael Wright85b1af62014-06-04 14:51:58 -07004829 if (isWakeKey) {
Jeff Brown13f00f02014-10-31 14:45:50 -07004830 wakeUp(event.getEventTime(), mAllowTheaterModeWakeFromKey);
Michael Wright85b1af62014-06-04 14:51:58 -07004831 }
Justin Kohd378ad72013-04-01 12:18:26 -07004832 return result;
4833 }
4834
Jeff Brownbae8e772014-06-12 19:59:45 -07004835 boolean useHapticFeedback = down
4836 && (policyFlags & WindowManagerPolicy.FLAG_VIRTUAL) != 0
4837 && event.getRepeatCount() == 0;
4838
Jeff Brown4d396052010-10-29 21:50:21 -07004839 // Handle special keys.
4840 switch (keyCode) {
4841 case KeyEvent.KEYCODE_VOLUME_DOWN:
Jeff Brownb0418da2010-11-01 15:24:01 -07004842 case KeyEvent.KEYCODE_VOLUME_UP:
4843 case KeyEvent.KEYCODE_VOLUME_MUTE: {
RoboErik001c59c2015-01-26 15:53:51 -08004844 if (mUseTvRouting) {
4845 // On TVs volume keys never go to the foreground app
4846 result &= ~ACTION_PASS_TO_USER;
4847 }
Jeff Brownd5bb82d2011-10-12 13:57:59 -07004848 if (keyCode == KeyEvent.KEYCODE_VOLUME_DOWN) {
4849 if (down) {
Jeff Brown13f00f02014-10-31 14:45:50 -07004850 if (interactive && !mScreenshotChordVolumeDownKeyTriggered
Jeff Brownd5bb82d2011-10-12 13:57:59 -07004851 && (event.getFlags() & KeyEvent.FLAG_FALLBACK) == 0) {
Jeff Brown13f00f02014-10-31 14:45:50 -07004852 mScreenshotChordVolumeDownKeyTriggered = true;
4853 mScreenshotChordVolumeDownKeyTime = event.getDownTime();
4854 mScreenshotChordVolumeDownKeyConsumed = false;
Jeff Brownd5bb82d2011-10-12 13:57:59 -07004855 cancelPendingPowerKeyAction();
4856 interceptScreenshotChord();
4857 }
4858 } else {
Jeff Brown13f00f02014-10-31 14:45:50 -07004859 mScreenshotChordVolumeDownKeyTriggered = false;
Jeff Brownd5bb82d2011-10-12 13:57:59 -07004860 cancelPendingScreenshotChordAction();
4861 }
4862 } else if (keyCode == KeyEvent.KEYCODE_VOLUME_UP) {
4863 if (down) {
Jeff Brown13f00f02014-10-31 14:45:50 -07004864 if (interactive && !mScreenshotChordVolumeUpKeyTriggered
Jeff Brownd5bb82d2011-10-12 13:57:59 -07004865 && (event.getFlags() & KeyEvent.FLAG_FALLBACK) == 0) {
Jeff Brown13f00f02014-10-31 14:45:50 -07004866 mScreenshotChordVolumeUpKeyTriggered = true;
Jeff Brownd5bb82d2011-10-12 13:57:59 -07004867 cancelPendingPowerKeyAction();
4868 cancelPendingScreenshotChordAction();
4869 }
4870 } else {
Jeff Brown13f00f02014-10-31 14:45:50 -07004871 mScreenshotChordVolumeUpKeyTriggered = false;
Jeff Brownd5bb82d2011-10-12 13:57:59 -07004872 cancelPendingScreenshotChordAction();
4873 }
4874 }
Jeff Brown4d396052010-10-29 21:50:21 -07004875 if (down) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -07004876 TelecomManager telecomManager = getTelecommService();
4877 if (telecomManager != null) {
4878 if (telecomManager.isRinging()) {
Santos Cordon6848f722014-05-21 15:22:12 -07004879 // If an incoming call is ringing, either VOLUME key means
4880 // "silence ringer". We handle these keys here, rather than
4881 // in the InCallScreen, to make sure we'll respond to them
4882 // even if the InCallScreen hasn't come to the foreground yet.
4883 // Look for the DOWN event here, to agree with the "fallback"
4884 // behavior in the InCallScreen.
4885 Log.i(TAG, "interceptKeyBeforeQueueing:"
4886 + " VOLUME key-down while ringing: Silence ringer!");
Jeff Brown4d396052010-10-29 21:50:21 -07004887
Santos Cordon6848f722014-05-21 15:22:12 -07004888 // Silence the ringer. (It's safe to call this
4889 // even if the ringer has already been silenced.)
Tyler Gunnef9f6f92014-09-12 22:16:17 -07004890 telecomManager.silenceRinger();
Jeff Brown4d396052010-10-29 21:50:21 -07004891
Santos Cordon6848f722014-05-21 15:22:12 -07004892 // And *don't* pass this key thru to the current activity
4893 // (which is probably the InCallScreen.)
4894 result &= ~ACTION_PASS_TO_USER;
4895 break;
4896 }
Tyler Gunnef9f6f92014-09-12 22:16:17 -07004897 if (telecomManager.isInCall()
Santos Cordon6848f722014-05-21 15:22:12 -07004898 && (result & ACTION_PASS_TO_USER) == 0) {
4899 // If we are in call but we decided not to pass the key to
RoboErik430fc482014-06-12 15:49:20 -07004900 // the application, just pass it to the session service.
4901
4902 MediaSessionLegacyHelper.getHelper(mContext)
RoboErik3c45c292014-07-08 16:47:31 -07004903 .sendVolumeKeyEvent(event, false);
Santos Cordon6848f722014-05-21 15:22:12 -07004904 break;
Jeff Brown4d396052010-10-29 21:50:21 -07004905 }
4906 }
4907
RoboErik430fc482014-06-12 15:49:20 -07004908 if ((result & ACTION_PASS_TO_USER) == 0) {
RoboErik001c59c2015-01-26 15:53:51 -08004909 if (mUseTvRouting) {
4910 dispatchDirectAudioEvent(event);
4911 } else {
4912 // If we aren't passing to the user and no one else
4913 // handled it send it to the session manager to
4914 // figure out.
4915 MediaSessionLegacyHelper.getHelper(mContext)
4916 .sendVolumeKeyEvent(event, true);
4917 }
Jeff Brown4d396052010-10-29 21:50:21 -07004918 break;
4919 }
4920 }
4921 break;
4922 }
4923
4924 case KeyEvent.KEYCODE_ENDCALL: {
4925 result &= ~ACTION_PASS_TO_USER;
4926 if (down) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -07004927 TelecomManager telecomManager = getTelecommService();
Jeff Brown4d396052010-10-29 21:50:21 -07004928 boolean hungUp = false;
Tyler Gunnef9f6f92014-09-12 22:16:17 -07004929 if (telecomManager != null) {
4930 hungUp = telecomManager.endCall();
Jeff Brown4d396052010-10-29 21:50:21 -07004931 }
Jeff Brown13f00f02014-10-31 14:45:50 -07004932 if (interactive && !hungUp) {
4933 mEndCallKeyHandled = false;
4934 mHandler.postDelayed(mEndCallLongPress,
4935 ViewConfiguration.get(mContext).getDeviceGlobalActionKeyTimeout());
4936 } else {
4937 mEndCallKeyHandled = true;
4938 }
Jeff Brown4d396052010-10-29 21:50:21 -07004939 } else {
Jeff Brown13f00f02014-10-31 14:45:50 -07004940 if (!mEndCallKeyHandled) {
4941 mHandler.removeCallbacks(mEndCallLongPress);
4942 if (!canceled) {
4943 if ((mEndcallBehavior
4944 & Settings.System.END_BUTTON_BEHAVIOR_HOME) != 0) {
4945 if (goHome()) {
4946 break;
4947 }
Dianne Hackborn0041e972009-07-24 17:14:43 -07004948 }
Jeff Brown13f00f02014-10-31 14:45:50 -07004949 if ((mEndcallBehavior
4950 & Settings.System.END_BUTTON_BEHAVIOR_SLEEP) != 0) {
4951 mPowerManager.goToSleep(event.getEventTime(),
4952 PowerManager.GO_TO_SLEEP_REASON_POWER_BUTTON, 0);
4953 isWakeKey = false;
4954 }
Jeff Brown4d396052010-10-29 21:50:21 -07004955 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004956 }
Jeff Brown4d396052010-10-29 21:50:21 -07004957 }
4958 break;
4959 }
4960
4961 case KeyEvent.KEYCODE_POWER: {
4962 result &= ~ACTION_PASS_TO_USER;
Jeff Brown13f00f02014-10-31 14:45:50 -07004963 isWakeKey = false; // wake-up will be handled separately
Jeff Brown4d396052010-10-29 21:50:21 -07004964 if (down) {
Jeff Brown13f00f02014-10-31 14:45:50 -07004965 interceptPowerKeyDown(event, interactive);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004966 } else {
Jeff Brown13f00f02014-10-31 14:45:50 -07004967 interceptPowerKeyUp(event, interactive, canceled);
Jeff Brown4d396052010-10-29 21:50:21 -07004968 }
4969 break;
4970 }
4971
Jeff Brown6212a492014-03-07 13:58:47 -08004972 case KeyEvent.KEYCODE_SLEEP: {
4973 result &= ~ACTION_PASS_TO_USER;
Filip Gruszczynskia483a1d2015-03-17 19:06:58 +00004974 isWakeKey = false;
Jeff Brownbae8e772014-06-12 19:59:45 -07004975 if (!mPowerManager.isInteractive()) {
4976 useHapticFeedback = false; // suppress feedback if already non-interactive
4977 }
Nick Vaccarob593a812015-05-15 11:23:05 -07004978 if (down) {
4979 sleepPress(event.getEventTime());
4980 } else {
4981 sleepRelease(event.getEventTime());
4982 }
Jeff Brown6212a492014-03-07 13:58:47 -08004983 break;
4984 }
4985
4986 case KeyEvent.KEYCODE_WAKEUP: {
4987 result &= ~ACTION_PASS_TO_USER;
Jose Lima9546b202014-07-02 17:21:51 -07004988 isWakeKey = true;
Jeff Brown6212a492014-03-07 13:58:47 -08004989 break;
4990 }
4991
Jeff Brown4d396052010-10-29 21:50:21 -07004992 case KeyEvent.KEYCODE_MEDIA_PLAY:
4993 case KeyEvent.KEYCODE_MEDIA_PAUSE:
4994 case KeyEvent.KEYCODE_MEDIA_PLAY_PAUSE:
Jeff Brown4d396052010-10-29 21:50:21 -07004995 case KeyEvent.KEYCODE_HEADSETHOOK:
4996 case KeyEvent.KEYCODE_MUTE:
4997 case KeyEvent.KEYCODE_MEDIA_STOP:
4998 case KeyEvent.KEYCODE_MEDIA_NEXT:
4999 case KeyEvent.KEYCODE_MEDIA_PREVIOUS:
5000 case KeyEvent.KEYCODE_MEDIA_REWIND:
5001 case KeyEvent.KEYCODE_MEDIA_RECORD:
Jaekyun Seokbfdad8e2013-07-08 13:53:21 +09005002 case KeyEvent.KEYCODE_MEDIA_FAST_FORWARD:
5003 case KeyEvent.KEYCODE_MEDIA_AUDIO_TRACK: {
RoboErikde9ba392014-09-26 12:51:01 -07005004 if (MediaSessionLegacyHelper.getHelper(mContext).isGlobalPriorityActive()) {
5005 // If the global session is active pass all media keys to it
5006 // instead of the active window.
5007 result &= ~ACTION_PASS_TO_USER;
5008 }
Jeff Brown4d396052010-10-29 21:50:21 -07005009 if ((result & ACTION_PASS_TO_USER) == 0) {
5010 // Only do this if we would otherwise not pass it to the user. In that
5011 // case, the PhoneWindow class will do the same thing, except it will
5012 // only do it if the showing app doesn't process the key on its own.
Jeff Brown40013652012-05-16 21:22:36 -07005013 // Note that we need to make a copy of the key event here because the
5014 // original key event will be recycled when we return.
Jeff Brown4d396052010-10-29 21:50:21 -07005015 mBroadcastWakeLock.acquire();
Jeff Brown40013652012-05-16 21:22:36 -07005016 Message msg = mHandler.obtainMessage(MSG_DISPATCH_MEDIA_KEY_WITH_WAKE_LOCK,
5017 new KeyEvent(event));
5018 msg.setAsynchronous(true);
5019 msg.sendToTarget();
Jeff Brown4d396052010-10-29 21:50:21 -07005020 }
5021 break;
Jeff Brown00fa7bd2010-07-02 15:37:36 -07005022 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005023
Jeff Brown4d396052010-10-29 21:50:21 -07005024 case KeyEvent.KEYCODE_CALL: {
5025 if (down) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -07005026 TelecomManager telecomManager = getTelecommService();
5027 if (telecomManager != null) {
5028 if (telecomManager.isRinging()) {
Santos Cordon6848f722014-05-21 15:22:12 -07005029 Log.i(TAG, "interceptKeyBeforeQueueing:"
5030 + " CALL key-down while ringing: Answer the call!");
Tyler Gunnef9f6f92014-09-12 22:16:17 -07005031 telecomManager.acceptRingingCall();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005032
Santos Cordon6848f722014-05-21 15:22:12 -07005033 // And *don't* pass this key thru to the current activity
5034 // (which is presumably the InCallScreen.)
5035 result &= ~ACTION_PASS_TO_USER;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005036 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005037 }
Jeff Brown00fa7bd2010-07-02 15:37:36 -07005038 }
Jeff Brown4d396052010-10-29 21:50:21 -07005039 break;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005040 }
Michael Wright869a67c2014-08-26 19:33:06 -07005041 case KeyEvent.KEYCODE_VOICE_ASSIST: {
5042 // Only do this if we would otherwise not pass it to the user. In that case,
5043 // interceptKeyBeforeDispatching would apply a similar but different policy in
5044 // order to invoke voice assist actions. Note that we need to make a copy of the
5045 // key event here because the original key event will be recycled when we return.
5046 if ((result & ACTION_PASS_TO_USER) == 0 && !down) {
5047 mBroadcastWakeLock.acquire();
5048 Message msg = mHandler.obtainMessage(MSG_LAUNCH_VOICE_ASSIST_WITH_WAKE_LOCK,
5049 keyguardActive ? 1 : 0, 0);
5050 msg.setAsynchronous(true);
5051 msg.sendToTarget();
5052 }
5053 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005054 }
Jeff Brown26875502014-01-30 21:47:47 -08005055
Jeff Brownbae8e772014-06-12 19:59:45 -07005056 if (useHapticFeedback) {
5057 performHapticFeedbackLw(null, HapticFeedbackConstants.VIRTUAL_KEY, false);
5058 }
5059
Jeff Brown26875502014-01-30 21:47:47 -08005060 if (isWakeKey) {
Jeff Brown13f00f02014-10-31 14:45:50 -07005061 wakeUp(event.getEventTime(), mAllowTheaterModeWakeFromKey);
Jeff Brown26875502014-01-30 21:47:47 -08005062 }
Bryce Lee584a4452014-10-21 15:55:55 -07005063
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005064 return result;
5065 }
5066
Jeff Brown1c2e4942012-11-06 16:32:01 -08005067 /**
Jeff Brown13f00f02014-10-31 14:45:50 -07005068 * Returns true if the key can have global actions attached to it.
5069 * We reserve all power management keys for the system since they require
5070 * very careful handling.
5071 */
5072 private static boolean isValidGlobalKey(int keyCode) {
5073 switch (keyCode) {
5074 case KeyEvent.KEYCODE_POWER:
5075 case KeyEvent.KEYCODE_WAKEUP:
5076 case KeyEvent.KEYCODE_SLEEP:
5077 return false;
5078 default:
5079 return true;
5080 }
5081 }
5082
5083 /**
Jeff Brown1c2e4942012-11-06 16:32:01 -08005084 * When the screen is off we ignore some keys that might otherwise typically
5085 * be considered wake keys. We filter them out here.
5086 *
5087 * {@link KeyEvent#KEYCODE_POWER} is notably absent from this list because it
5088 * is always considered a wake key.
5089 */
5090 private boolean isWakeKeyWhenScreenOff(int keyCode) {
5091 switch (keyCode) {
5092 // ignore volume keys unless docked
5093 case KeyEvent.KEYCODE_VOLUME_UP:
5094 case KeyEvent.KEYCODE_VOLUME_DOWN:
5095 case KeyEvent.KEYCODE_VOLUME_MUTE:
5096 return mDockMode != Intent.EXTRA_DOCK_STATE_UNDOCKED;
5097
5098 // ignore media and camera keys
5099 case KeyEvent.KEYCODE_MUTE:
5100 case KeyEvent.KEYCODE_HEADSETHOOK:
5101 case KeyEvent.KEYCODE_MEDIA_PLAY:
5102 case KeyEvent.KEYCODE_MEDIA_PAUSE:
5103 case KeyEvent.KEYCODE_MEDIA_PLAY_PAUSE:
5104 case KeyEvent.KEYCODE_MEDIA_STOP:
5105 case KeyEvent.KEYCODE_MEDIA_NEXT:
5106 case KeyEvent.KEYCODE_MEDIA_PREVIOUS:
5107 case KeyEvent.KEYCODE_MEDIA_REWIND:
5108 case KeyEvent.KEYCODE_MEDIA_RECORD:
5109 case KeyEvent.KEYCODE_MEDIA_FAST_FORWARD:
Jaekyun Seokbfdad8e2013-07-08 13:53:21 +09005110 case KeyEvent.KEYCODE_MEDIA_AUDIO_TRACK:
Jeff Brown1c2e4942012-11-06 16:32:01 -08005111 case KeyEvent.KEYCODE_CAMERA:
5112 return false;
5113 }
5114 return true;
5115 }
5116
5117
Jeff Brown56194eb2011-03-02 19:23:13 -08005118 /** {@inheritDoc} */
5119 @Override
Michael Wright70af00a2014-09-03 19:30:20 -07005120 public int interceptMotionBeforeQueueingNonInteractive(long whenNanos, int policyFlags) {
5121 if ((policyFlags & FLAG_WAKE) != 0) {
Bryce Lee5c138322014-11-03 08:26:09 -08005122 if (wakeUp(whenNanos / 1000000, mAllowTheaterModeWakeFromMotion)) {
5123 return 0;
5124 }
Michael Wright70af00a2014-09-03 19:30:20 -07005125 }
Bryce Lee5c138322014-11-03 08:26:09 -08005126
Michael Wright70af00a2014-09-03 19:30:20 -07005127 if (shouldDispatchInputWhenNonInteractive()) {
5128 return ACTION_PASS_TO_USER;
5129 }
Bryce Lee5c138322014-11-03 08:26:09 -08005130
Bryce Lee812d7022014-11-10 13:33:28 -08005131 // If we have not passed the action up and we are in theater mode without dreaming,
5132 // there will be no dream to intercept the touch and wake into ambient. The device should
5133 // wake up in this case.
5134 if (isTheaterModeEnabled() && (policyFlags & FLAG_WAKE) != 0) {
5135 wakeUp(whenNanos / 1000000, mAllowTheaterModeWakeFromMotionWhenNotDreaming);
5136 }
5137
Jeff Brown037c33e2014-04-09 00:31:55 -07005138 return 0;
Jeff Brown56194eb2011-03-02 19:23:13 -08005139 }
5140
Michael Wright70af00a2014-09-03 19:30:20 -07005141 private boolean shouldDispatchInputWhenNonInteractive() {
Bryce Lee5c138322014-11-03 08:26:09 -08005142 // Send events to keyguard while the screen is on.
Jim Millerab954542014-10-10 18:21:49 -07005143 if (isKeyguardShowingAndNotOccluded() && mDisplay != null
5144 && mDisplay.getState() != Display.STATE_OFF) {
Bryce Lee5c138322014-11-03 08:26:09 -08005145 return true;
5146 }
5147
5148 // Send events to a dozing dream even if the screen is off since the dream
5149 // is in control of the state of the screen.
5150 IDreamManager dreamManager = getDreamManager();
5151
5152 try {
5153 if (dreamManager != null && dreamManager.isDreaming()) {
5154 return true;
5155 }
5156 } catch (RemoteException e) {
5157 Slog.e(TAG, "RemoteException when checking if dreaming", e);
5158 }
5159
5160 // Otherwise, consume events since the user can't see what is being
5161 // interacted with.
5162 return false;
Michael Wright70af00a2014-09-03 19:30:20 -07005163 }
5164
RoboErik001c59c2015-01-26 15:53:51 -08005165 private void dispatchDirectAudioEvent(KeyEvent event) {
5166 if (event.getAction() != KeyEvent.ACTION_DOWN) {
5167 return;
5168 }
5169 int keyCode = event.getKeyCode();
John Spurlockb94f2d62015-03-17 14:11:57 -04005170 int flags = AudioManager.FLAG_SHOW_UI | AudioManager.FLAG_PLAY_SOUND
5171 | AudioManager.FLAG_FROM_KEY;
RoboErik001c59c2015-01-26 15:53:51 -08005172 String pkgName = mContext.getOpPackageName();
5173 switch (keyCode) {
5174 case KeyEvent.KEYCODE_VOLUME_UP:
5175 try {
John Spurlockee5ad722015-03-03 16:17:21 -05005176 getAudioService().adjustSuggestedStreamVolume(AudioManager.ADJUST_RAISE,
John Spurlock90874332015-03-10 16:00:54 -04005177 AudioManager.USE_DEFAULT_STREAM_TYPE, flags, pkgName, TAG);
RoboErik001c59c2015-01-26 15:53:51 -08005178 } catch (RemoteException e) {
5179 Log.e(TAG, "Error dispatching volume up in dispatchTvAudioEvent.", e);
5180 }
5181 break;
5182 case KeyEvent.KEYCODE_VOLUME_DOWN:
5183 try {
John Spurlockee5ad722015-03-03 16:17:21 -05005184 getAudioService().adjustSuggestedStreamVolume(AudioManager.ADJUST_LOWER,
John Spurlock90874332015-03-10 16:00:54 -04005185 AudioManager.USE_DEFAULT_STREAM_TYPE, flags, pkgName, TAG);
RoboErik001c59c2015-01-26 15:53:51 -08005186 } catch (RemoteException e) {
5187 Log.e(TAG, "Error dispatching volume down in dispatchTvAudioEvent.", e);
5188 }
5189 break;
5190 case KeyEvent.KEYCODE_VOLUME_MUTE:
5191 try {
5192 if (event.getRepeatCount() == 0) {
John Spurlockee5ad722015-03-03 16:17:21 -05005193 getAudioService().adjustSuggestedStreamVolume(
5194 AudioManager.ADJUST_TOGGLE_MUTE,
John Spurlock90874332015-03-10 16:00:54 -04005195 AudioManager.USE_DEFAULT_STREAM_TYPE, flags, pkgName, TAG);
RoboErik001c59c2015-01-26 15:53:51 -08005196 }
5197 } catch (RemoteException e) {
5198 Log.e(TAG, "Error dispatching mute in dispatchTvAudioEvent.", e);
5199 }
5200 break;
5201 }
5202 }
5203
Jeff Brown40013652012-05-16 21:22:36 -07005204 void dispatchMediaKeyWithWakeLock(KeyEvent event) {
5205 if (DEBUG_INPUT) {
5206 Slog.d(TAG, "dispatchMediaKeyWithWakeLock: " + event);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005207 }
5208
Jeff Brown40013652012-05-16 21:22:36 -07005209 if (mHavePendingMediaKeyRepeatWithWakeLock) {
5210 if (DEBUG_INPUT) {
5211 Slog.d(TAG, "dispatchMediaKeyWithWakeLock: canceled repeat");
5212 }
5213
5214 mHandler.removeMessages(MSG_DISPATCH_MEDIA_KEY_REPEAT_WITH_WAKE_LOCK);
5215 mHavePendingMediaKeyRepeatWithWakeLock = false;
5216 mBroadcastWakeLock.release(); // pending repeat was holding onto the wake lock
5217 }
5218
5219 dispatchMediaKeyWithWakeLockToAudioService(event);
5220
5221 if (event.getAction() == KeyEvent.ACTION_DOWN
5222 && event.getRepeatCount() == 0) {
5223 mHavePendingMediaKeyRepeatWithWakeLock = true;
5224
5225 Message msg = mHandler.obtainMessage(
5226 MSG_DISPATCH_MEDIA_KEY_REPEAT_WITH_WAKE_LOCK, event);
5227 msg.setAsynchronous(true);
5228 mHandler.sendMessageDelayed(msg, ViewConfiguration.getKeyRepeatTimeout());
5229 } else {
5230 mBroadcastWakeLock.release();
5231 }
5232 }
5233
5234 void dispatchMediaKeyRepeatWithWakeLock(KeyEvent event) {
5235 mHavePendingMediaKeyRepeatWithWakeLock = false;
5236
5237 KeyEvent repeatEvent = KeyEvent.changeTimeRepeat(event,
5238 SystemClock.uptimeMillis(), 1, event.getFlags() | KeyEvent.FLAG_LONG_PRESS);
5239 if (DEBUG_INPUT) {
5240 Slog.d(TAG, "dispatchMediaKeyRepeatWithWakeLock: " + repeatEvent);
5241 }
5242
5243 dispatchMediaKeyWithWakeLockToAudioService(repeatEvent);
5244 mBroadcastWakeLock.release();
5245 }
5246
5247 void dispatchMediaKeyWithWakeLockToAudioService(KeyEvent event) {
5248 if (ActivityManagerNative.isSystemReady()) {
RoboErik430fc482014-06-12 15:49:20 -07005249 MediaSessionLegacyHelper.getHelper(mContext).sendMediaButtonEvent(event, true);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005250 }
5251 }
5252
Michael Wright869a67c2014-08-26 19:33:06 -07005253 void launchVoiceAssistWithWakeLock(boolean keyguardActive) {
Dianne Hackbornb6683c42015-06-18 17:40:33 -07005254 IDeviceIdleController dic = IDeviceIdleController.Stub.asInterface(
5255 ServiceManager.getService(Context.DEVICE_IDLE_CONTROLLER));
5256 if (dic != null) {
5257 try {
5258 dic.exitIdle("voice-search");
5259 } catch (RemoteException e) {
5260 }
5261 }
Michael Wright869a67c2014-08-26 19:33:06 -07005262 Intent voiceIntent =
5263 new Intent(RecognizerIntent.ACTION_VOICE_SEARCH_HANDS_FREE);
5264 voiceIntent.putExtra(RecognizerIntent.EXTRA_SECURE, keyguardActive);
Bart Sears8b1c27c2015-03-18 23:51:02 +00005265 startActivityAsUser(voiceIntent, UserHandle.CURRENT_OR_SELF);
Michael Wright869a67c2014-08-26 19:33:06 -07005266 mBroadcastWakeLock.release();
5267 }
5268
Mike Lockwood1753f7f2009-08-24 14:49:07 -07005269 BroadcastReceiver mDockReceiver = new BroadcastReceiver() {
Craig Mautnereee29c42013-01-17 14:44:34 -08005270 @Override
Mike Lockwood1753f7f2009-08-24 14:49:07 -07005271 public void onReceive(Context context, Intent intent) {
Dianne Hackborn867ab6472010-04-29 13:28:56 -07005272 if (Intent.ACTION_DOCK_EVENT.equals(intent.getAction())) {
5273 mDockMode = intent.getIntExtra(Intent.EXTRA_DOCK_STATE,
5274 Intent.EXTRA_DOCK_STATE_UNDOCKED);
Daniel Sandler6396c722013-04-16 20:19:09 -04005275 } else {
5276 try {
5277 IUiModeManager uiModeService = IUiModeManager.Stub.asInterface(
5278 ServiceManager.getService(Context.UI_MODE_SERVICE));
5279 mUiMode = uiModeService.getCurrentModeType();
5280 } catch (RemoteException e) {
5281 }
Dianne Hackborn80fa1662009-10-07 14:02:10 -07005282 }
Jeff Brown01a98dd2011-09-20 15:08:29 -07005283 updateRotation(true);
Craig Mautnereee29c42013-01-17 14:44:34 -08005284 synchronized (mLock) {
5285 updateOrientationListenerLp();
5286 }
Mike Lockwood1753f7f2009-08-24 14:49:07 -07005287 }
5288 };
5289
Jeff Brown6aaf2952012-10-05 16:01:08 -07005290 BroadcastReceiver mDreamReceiver = new BroadcastReceiver() {
5291 @Override
5292 public void onReceive(Context context, Intent intent) {
5293 if (Intent.ACTION_DREAMING_STARTED.equals(intent.getAction())) {
Jim Miller5ecd8112013-01-09 18:50:26 -08005294 if (mKeyguardDelegate != null) {
5295 mKeyguardDelegate.onDreamingStarted();
Jeff Brown6aaf2952012-10-05 16:01:08 -07005296 }
5297 } else if (Intent.ACTION_DREAMING_STOPPED.equals(intent.getAction())) {
Jim Miller5ecd8112013-01-09 18:50:26 -08005298 if (mKeyguardDelegate != null) {
5299 mKeyguardDelegate.onDreamingStopped();
Jeff Brown6aaf2952012-10-05 16:01:08 -07005300 }
5301 }
5302 }
5303 };
5304
Christopher Tate5e08af02012-09-21 17:17:22 -07005305 BroadcastReceiver mMultiuserReceiver = new BroadcastReceiver() {
5306 @Override
5307 public void onReceive(Context context, Intent intent) {
5308 if (Intent.ACTION_USER_SWITCHED.equals(intent.getAction())) {
5309 // tickle the settings observer: this first ensures that we're
5310 // observing the relevant settings for the newly-active user,
5311 // and then updates our own bookkeeping based on the now-
5312 // current user.
5313 mSettingsObserver.onChange(false);
John Spurlockce479d82012-11-29 09:52:21 -05005314
5315 // force a re-application of focused window sysui visibility.
5316 // the window may never have been shown for this user
5317 // e.g. the keyguard when going through the new-user setup flow
John Spurlock04db1762013-05-13 12:46:41 -04005318 synchronized (mWindowManagerFuncs.getWindowManagerLock()) {
John Spurlockce479d82012-11-29 09:52:21 -05005319 mLastSystemUiFlags = 0;
5320 updateSystemUiVisibilityLw();
5321 }
Christopher Tate5e08af02012-09-21 17:17:22 -07005322 }
5323 }
5324 };
5325
Adrian Roosddc8b272015-05-21 16:28:27 -07005326 private final Runnable mHiddenNavPanic = new Runnable() {
John Spurlockd9b70bd2014-02-06 17:02:44 -05005327 @Override
5328 public void run() {
Adrian Roosddc8b272015-05-21 16:28:27 -07005329 synchronized (mWindowManagerFuncs.getWindowManagerLock()) {
5330 if (!isUserSetupComplete()) {
5331 // Swipe-up for navigation bar is disabled during setup
5332 return;
5333 }
5334 mPendingPanicGestureUptime = SystemClock.uptimeMillis();
5335 mNavigationBarController.showTransient();
5336 }
John Spurlockd9b70bd2014-02-06 17:02:44 -05005337 }
5338 };
5339
John Spurlocke1f366f2013-08-05 12:22:40 -04005340 private void requestTransientBars(WindowState swipeTarget) {
John Spurlock04db1762013-05-13 12:46:41 -04005341 synchronized (mWindowManagerFuncs.getWindowManagerLock()) {
Maurice Lam99c6e072014-04-28 18:24:28 -07005342 if (!isUserSetupComplete()) {
5343 // Swipe-up for navigation bar is disabled during setup
5344 return;
5345 }
John Spurlock27735a42013-08-14 17:57:38 -04005346 boolean sb = mStatusBarController.checkShowTransientBarLw();
5347 boolean nb = mNavigationBarController.checkShowTransientBarLw();
John Spurlockad3e6cb2013-04-30 08:47:43 -04005348 if (sb || nb) {
Adrian Roos62b65e42015-02-25 18:05:34 +01005349 // Don't show status bar when swiping on already visible navigation bar
5350 if (!nb && swipeTarget == mNavigationBar) {
John Spurlocke1f366f2013-08-05 12:22:40 -04005351 if (DEBUG) Slog.d(TAG, "Not showing transient bar, wrong swipe target");
John Spurlockad3e6cb2013-04-30 08:47:43 -04005352 return;
5353 }
John Spurlock27735a42013-08-14 17:57:38 -04005354 if (sb) mStatusBarController.showTransient();
5355 if (nb) mNavigationBarController.showTransient();
John Spurlockf1a36642013-10-12 17:50:42 -04005356 mImmersiveModeConfirmation.confirmCurrentPrompt();
John Spurlockad3e6cb2013-04-30 08:47:43 -04005357 updateSystemUiVisibilityLw();
John Spurlock32beb2c2013-03-11 10:16:47 -04005358 }
John Spurlockad3e6cb2013-04-30 08:47:43 -04005359 }
5360 }
5361
Jeff Brown3ee549c2014-09-22 20:14:39 -07005362 // Called on the PowerManager's Notifier thread.
Jeff Brownc38c9be2012-10-04 13:16:19 -07005363 @Override
Jeff Brown416c49c2015-05-26 19:50:18 -07005364 public void startedGoingToSleep(int why) {
5365 if (DEBUG_WAKEUP) Slog.i(TAG, "Started going to sleep... (why=" + why + ")");
Jorim Jaggid175b6c2015-05-27 15:39:09 -07005366 if (mKeyguardDelegate != null) {
5367 mKeyguardDelegate.onStartedGoingToSleep(why);
5368 }
Jeff Brown416c49c2015-05-26 19:50:18 -07005369 }
5370
5371 // Called on the PowerManager's Notifier thread.
5372 @Override
5373 public void finishedGoingToSleep(int why) {
Dianne Hackborn74489012009-03-24 20:50:09 -07005374 EventLog.writeEvent(70000, 0);
Jeff Brown416c49c2015-05-26 19:50:18 -07005375 if (DEBUG_WAKEUP) Slog.i(TAG, "Finished going to sleep... (why=" + why + ")");
Chris Wren9bb290b2015-06-29 12:02:13 -04005376 MetricsLogger.histogram(mContext, "screen_timeout", mLockScreenTimeout / 1000);
Jeff Brown3ee549c2014-09-22 20:14:39 -07005377
5378 // We must get this work done here because the power manager will drop
5379 // the wake lock and let the system suspend once this function returns.
The Android Open Source Project0727d222009-03-11 12:11:58 -07005380 synchronized (mLock) {
Jeff Brown3ee549c2014-09-22 20:14:39 -07005381 mAwake = false;
5382 mKeyguardDrawComplete = false;
Jeff Browna20dda42014-05-27 20:57:24 -07005383 updateWakeGestureListenerLp();
The Android Open Source Project0727d222009-03-11 12:11:58 -07005384 updateOrientationListenerLp();
Mike Lockwood28569302010-01-28 11:54:40 -05005385 updateLockScreenTimeout();
The Android Open Source Project0727d222009-03-11 12:11:58 -07005386 }
Jeff Brown3ee549c2014-09-22 20:14:39 -07005387 if (mKeyguardDelegate != null) {
Jorim Jaggid175b6c2015-05-27 15:39:09 -07005388 mKeyguardDelegate.onFinishedGoingToSleep(why);
Jeff Brown3ee549c2014-09-22 20:14:39 -07005389 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005390 }
5391
Jeff Brown3ee549c2014-09-22 20:14:39 -07005392 // Called on the PowerManager's Notifier thread.
Jeff Brownc38c9be2012-10-04 13:16:19 -07005393 @Override
Jeff Brown416c49c2015-05-26 19:50:18 -07005394 public void startedWakingUp() {
Dianne Hackborn74489012009-03-24 20:50:09 -07005395 EventLog.writeEvent(70000, 1);
Jeff Brown416c49c2015-05-26 19:50:18 -07005396 if (DEBUG_WAKEUP) Slog.i(TAG, "Started waking up...");
Craig Mautner8a0da012014-05-31 15:13:37 -07005397
Jeff Brown3ee549c2014-09-22 20:14:39 -07005398 // Since goToSleep performs these functions synchronously, we must
5399 // do the same here. We cannot post this work to a handler because
5400 // that might cause it to become reordered with respect to what
5401 // may happen in a future call to goToSleep.
The Android Open Source Project0727d222009-03-11 12:11:58 -07005402 synchronized (mLock) {
Jeff Brown3ee549c2014-09-22 20:14:39 -07005403 mAwake = true;
5404 mKeyguardDrawComplete = false;
5405 if (mKeyguardDelegate != null) {
5406 mHandler.removeMessages(MSG_KEYGUARD_DRAWN_TIMEOUT);
5407 mHandler.sendEmptyMessageDelayed(MSG_KEYGUARD_DRAWN_TIMEOUT, 1000);
5408 }
5409
Jeff Browna20dda42014-05-27 20:57:24 -07005410 updateWakeGestureListenerLp();
The Android Open Source Project0727d222009-03-11 12:11:58 -07005411 updateOrientationListenerLp();
Mike Lockwood28569302010-01-28 11:54:40 -05005412 updateLockScreenTimeout();
The Android Open Source Project0727d222009-03-11 12:11:58 -07005413 }
Jeff Brownc38c9be2012-10-04 13:16:19 -07005414
Jim Miller5ecd8112013-01-09 18:50:26 -08005415 if (mKeyguardDelegate != null) {
Jorim Jaggid175b6c2015-05-27 15:39:09 -07005416 mKeyguardDelegate.onStartedWakingUp(mKeyguardDelegateCallback);
Jeff Brown36c4db82014-09-19 12:05:31 -07005417 // ... eventually calls finishKeyguardDrawn
Jeff Brownc38c9be2012-10-04 13:16:19 -07005418 } else {
Craig Mautner8a0da012014-05-31 15:13:37 -07005419 if (DEBUG_WAKEUP) Slog.d(TAG, "null mKeyguardDelegate: setting mKeyguardDrawComplete.");
Jeff Brown36c4db82014-09-19 12:05:31 -07005420 finishKeyguardDrawn();
Jeff Brownc38c9be2012-10-04 13:16:19 -07005421 }
Jeff Brown36c4db82014-09-19 12:05:31 -07005422 }
5423
Jeff Brown416c49c2015-05-26 19:50:18 -07005424 // Called on the PowerManager's Notifier thread.
5425 @Override
5426 public void finishedWakingUp() {
5427 if (DEBUG_WAKEUP) Slog.i(TAG, "Finished waking up...");
5428 }
5429
5430 private void wakeUpFromPowerKey(long eventTime) {
5431 wakeUp(eventTime, mAllowTheaterModeWakeFromPowerKey);
5432 }
5433
5434 private boolean wakeUp(long wakeTime, boolean wakeInTheaterMode) {
Bryce Leed3896842015-06-23 17:06:51 -07005435 final boolean theaterModeEnabled = isTheaterModeEnabled();
5436 if (!wakeInTheaterMode && theaterModeEnabled) {
Jeff Brown416c49c2015-05-26 19:50:18 -07005437 return false;
5438 }
5439
Bryce Leed3896842015-06-23 17:06:51 -07005440 if (theaterModeEnabled) {
5441 Settings.Global.putInt(mContext.getContentResolver(),
5442 Settings.Global.THEATER_MODE_ON, 0);
5443 }
5444
Jeff Brown416c49c2015-05-26 19:50:18 -07005445 mPowerManager.wakeUp(wakeTime);
5446 return true;
5447 }
5448
Jeff Brown36c4db82014-09-19 12:05:31 -07005449 private void finishKeyguardDrawn() {
Jeff Brown3ee549c2014-09-22 20:14:39 -07005450 synchronized (mLock) {
5451 if (!mAwake || mKeyguardDrawComplete) {
Stefan Kuhne9326dc12015-06-12 09:25:32 -10005452 return; // We are not awake yet or we have already informed of this event.
Jeff Brown3ee549c2014-09-22 20:14:39 -07005453 }
5454
Jeff Brown36c4db82014-09-19 12:05:31 -07005455 mKeyguardDrawComplete = true;
Jeff Brown3ee549c2014-09-22 20:14:39 -07005456 if (mKeyguardDelegate != null) {
5457 mHandler.removeMessages(MSG_KEYGUARD_DRAWN_TIMEOUT);
5458 }
5459 }
5460
5461 finishScreenTurningOn();
5462 }
5463
5464 // Called on the DisplayManager's DisplayPowerController thread.
5465 @Override
5466 public void screenTurnedOff() {
5467 if (DEBUG_WAKEUP) Slog.i(TAG, "Screen turned off...");
5468
Jeff Brown48d1b142015-06-10 16:36:03 -07005469 updateScreenOffSleepToken(true);
Jeff Brown3ee549c2014-09-22 20:14:39 -07005470 synchronized (mLock) {
5471 mScreenOnEarly = false;
5472 mScreenOnFully = false;
5473 mWindowManagerDrawComplete = false;
5474 mScreenOnListener = null;
5475 updateOrientationListenerLp();
Jeff Brown36c4db82014-09-19 12:05:31 -07005476 }
5477 }
5478
Jeff Brown3ee549c2014-09-22 20:14:39 -07005479 // Called on the DisplayManager's DisplayPowerController thread.
Jeff Brown36c4db82014-09-19 12:05:31 -07005480 @Override
5481 public void screenTurningOn(final ScreenOnListener screenOnListener) {
Jeff Brown36c4db82014-09-19 12:05:31 -07005482 if (DEBUG_WAKEUP) Slog.i(TAG, "Screen turning on...");
Jeff Brown36c4db82014-09-19 12:05:31 -07005483
Jeff Brown48d1b142015-06-10 16:36:03 -07005484 updateScreenOffSleepToken(false);
Jeff Brown3ee549c2014-09-22 20:14:39 -07005485 synchronized (mLock) {
5486 mScreenOnEarly = true;
5487 mScreenOnFully = false;
5488 mWindowManagerDrawComplete = false;
5489 mScreenOnListener = screenOnListener;
Jeff Brown3ee549c2014-09-22 20:14:39 -07005490 }
Jeff Brown36c4db82014-09-19 12:05:31 -07005491
Craig Mautnerc3daedd2014-09-13 11:17:23 -07005492 mWindowManagerInternal.waitForAllWindowsDrawn(mWindowManagerDrawCallback,
5493 WAITING_FOR_DRAWN_TIMEOUT);
Stefan Kuhne9326dc12015-06-12 09:25:32 -10005494 // ... eventually calls finishWindowsDrawn which will finalize our screen turn on
5495 // as well as enabling the orientation change logic/sensor.
Jeff Brown36c4db82014-09-19 12:05:31 -07005496 }
5497
Jeff Brown36c4db82014-09-19 12:05:31 -07005498 private void finishWindowsDrawn() {
Jeff Brown3ee549c2014-09-22 20:14:39 -07005499 synchronized (mLock) {
5500 if (!mScreenOnEarly || mWindowManagerDrawComplete) {
Stefan Kuhne9326dc12015-06-12 09:25:32 -10005501 return; // Screen is not turned on or we did already handle this case earlier.
Jeff Brown3ee549c2014-09-22 20:14:39 -07005502 }
5503
Jeff Brown36c4db82014-09-19 12:05:31 -07005504 mWindowManagerDrawComplete = true;
Jeff Brown36c4db82014-09-19 12:05:31 -07005505 }
Jeff Brown3ee549c2014-09-22 20:14:39 -07005506
5507 finishScreenTurningOn();
Jeff Brownc38c9be2012-10-04 13:16:19 -07005508 }
5509
Craig Mautner8a0da012014-05-31 15:13:37 -07005510 private void finishScreenTurningOn() {
Stefan Kuhne9326dc12015-06-12 09:25:32 -10005511 synchronized (mLock) {
5512 // We have just finished drawing screen content. Since the orientation listener
5513 // gets only installed when all windows are drawn, we try to install it again.
5514 updateOrientationListenerLp();
5515 }
Jeff Brown3ee549c2014-09-22 20:14:39 -07005516 final ScreenOnListener listener;
5517 final boolean enableScreen;
Jeff Brown36c4db82014-09-19 12:05:31 -07005518 synchronized (mLock) {
Jeff Brown3ee549c2014-09-22 20:14:39 -07005519 if (DEBUG_WAKEUP) Slog.d(TAG,
5520 "finishScreenTurningOn: mAwake=" + mAwake
5521 + ", mScreenOnEarly=" + mScreenOnEarly
5522 + ", mScreenOnFully=" + mScreenOnFully
5523 + ", mKeyguardDrawComplete=" + mKeyguardDrawComplete
5524 + ", mWindowManagerDrawComplete=" + mWindowManagerDrawComplete);
5525
5526 if (mScreenOnFully || !mScreenOnEarly || !mWindowManagerDrawComplete
5527 || (mAwake && !mKeyguardDrawComplete)) {
5528 return; // spurious or not ready yet
Jeff Brown36c4db82014-09-19 12:05:31 -07005529 }
5530
Jeff Brown3ee549c2014-09-22 20:14:39 -07005531 if (DEBUG_WAKEUP) Slog.i(TAG, "Finished screen turning on...");
5532 listener = mScreenOnListener;
Craig Mautner13f6ea72014-06-23 14:57:02 -07005533 mScreenOnListener = null;
Jeff Brown3ee549c2014-09-22 20:14:39 -07005534 mScreenOnFully = true;
5535
5536 // Remember the first time we draw the keyguard so we know when we're done with
5537 // the main part of booting and can enable the screen and hide boot messages.
5538 if (!mKeyguardDrawnOnce && mAwake) {
5539 mKeyguardDrawnOnce = true;
5540 enableScreen = true;
5541 if (mBootMessageNeedsHiding) {
5542 mBootMessageNeedsHiding = false;
5543 hideBootMessages();
5544 }
5545 } else {
5546 enableScreen = false;
5547 }
Jeff Brownc38c9be2012-10-04 13:16:19 -07005548 }
5549
Jeff Brown3ee549c2014-09-22 20:14:39 -07005550 if (listener != null) {
5551 listener.onScreenOn();
5552 }
Jeff Brown4fc45272012-10-10 18:28:14 -07005553
Jeff Brown3ee549c2014-09-22 20:14:39 -07005554 if (enableScreen) {
5555 try {
5556 mWindowManager.enableScreenIfNeeded();
5557 } catch (RemoteException unhandled) {
Jeff Brown36c4db82014-09-19 12:05:31 -07005558 }
Craig Mautnera631d492014-08-05 15:16:01 -07005559 }
5560 }
5561
5562 private void handleHideBootMessage() {
Jeff Brown3ee549c2014-09-22 20:14:39 -07005563 synchronized (mLock) {
5564 if (!mKeyguardDrawnOnce) {
5565 mBootMessageNeedsHiding = true;
5566 return; // keyguard hasn't drawn the first time yet, not done booting
5567 }
Craig Mautnera631d492014-08-05 15:16:01 -07005568 }
Jeff Brown3ee549c2014-09-22 20:14:39 -07005569
5570 if (mBootMsgDialog != null) {
5571 if (DEBUG_WAKEUP) Slog.d(TAG, "handleHideBootMessage: dismissing");
5572 mBootMsgDialog.dismiss();
5573 mBootMsgDialog = null;
Craig Mautnera631d492014-08-05 15:16:01 -07005574 }
Jeff Brownc38c9be2012-10-04 13:16:19 -07005575 }
5576
5577 @Override
Jeff Brown3ee549c2014-09-22 20:14:39 -07005578 public boolean isScreenOn() {
5579 return mScreenOnFully;
Dianne Hackborn08743722009-12-21 12:16:51 -08005580 }
Jeff Brownc38c9be2012-10-04 13:16:19 -07005581
Dianne Hackborn08743722009-12-21 12:16:51 -08005582 /** {@inheritDoc} */
Jose Lima9546b202014-07-02 17:21:51 -07005583 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005584 public void enableKeyguard(boolean enabled) {
Jim Miller5ecd8112013-01-09 18:50:26 -08005585 if (mKeyguardDelegate != null) {
5586 mKeyguardDelegate.setKeyguardEnabled(enabled);
Mike Lockwood3a74bd32011-08-12 13:55:22 -07005587 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005588 }
5589
5590 /** {@inheritDoc} */
Jose Lima9546b202014-07-02 17:21:51 -07005591 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005592 public void exitKeyguardSecurely(OnKeyguardExitResult callback) {
Jim Miller5ecd8112013-01-09 18:50:26 -08005593 if (mKeyguardDelegate != null) {
5594 mKeyguardDelegate.verifyUnlock(callback);
Mike Lockwood3a74bd32011-08-12 13:55:22 -07005595 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005596 }
5597
Jim Millerab954542014-10-10 18:21:49 -07005598 private boolean isKeyguardShowingAndNotOccluded() {
Jim Miller5ecd8112013-01-09 18:50:26 -08005599 if (mKeyguardDelegate == null) return false;
Jim Millerab954542014-10-10 18:21:49 -07005600 return mKeyguardDelegate.isShowing() && !mKeyguardOccluded;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005601 }
5602
Mike Lockwood520d8bc2011-02-18 13:23:13 -05005603 /** {@inheritDoc} */
Jose Lima9546b202014-07-02 17:21:51 -07005604 @Override
Mike Lockwood520d8bc2011-02-18 13:23:13 -05005605 public boolean isKeyguardLocked() {
5606 return keyguardOn();
5607 }
5608
5609 /** {@inheritDoc} */
Jose Lima9546b202014-07-02 17:21:51 -07005610 @Override
Mike Lockwood520d8bc2011-02-18 13:23:13 -05005611 public boolean isKeyguardSecure() {
Jim Miller5ecd8112013-01-09 18:50:26 -08005612 if (mKeyguardDelegate == null) return false;
5613 return mKeyguardDelegate.isSecure();
Mike Lockwood520d8bc2011-02-18 13:23:13 -05005614 }
5615
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005616 /** {@inheritDoc} */
Jose Lima9546b202014-07-02 17:21:51 -07005617 @Override
Adrian Roos461829d2015-06-03 14:41:18 -07005618 public boolean isKeyguardShowingOrOccluded() {
5619 return mKeyguardDelegate == null ? false : mKeyguardDelegate.isShowing();
5620 }
5621
5622 /** {@inheritDoc} */
5623 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005624 public boolean inKeyguardRestrictedKeyInputMode() {
Jim Miller5ecd8112013-01-09 18:50:26 -08005625 if (mKeyguardDelegate == null) return false;
5626 return mKeyguardDelegate.isInputRestricted();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005627 }
5628
Jose Lima9546b202014-07-02 17:21:51 -07005629 @Override
Dianne Hackborn90c52de2011-09-23 12:57:44 -07005630 public void dismissKeyguardLw() {
RoboErik8a2cfc32014-05-16 11:19:38 -07005631 if (mKeyguardDelegate != null && mKeyguardDelegate.isShowing()) {
Craig Mautnerc0d2d0a2014-10-31 16:25:15 -07005632 if (DEBUG_KEYGUARD) Slog.d(TAG, "PWM.dismissKeyguardLw");
Daniel Sandler1ce804392012-11-07 15:07:12 -05005633 mHandler.post(new Runnable() {
Jose Lima9546b202014-07-02 17:21:51 -07005634 @Override
Daniel Sandler1ce804392012-11-07 15:07:12 -05005635 public void run() {
Jorim Jaggi8de4311c2014-08-11 22:36:20 +02005636 // ask the keyguard to prompt the user to authenticate if necessary
5637 mKeyguardDelegate.dismiss();
5638 }
5639 });
5640 }
5641 }
5642
5643 public void notifyActivityDrawnForKeyguardLw() {
5644 if (mKeyguardDelegate != null) {
5645 mHandler.post(new Runnable() {
5646 @Override
5647 public void run() {
5648 mKeyguardDelegate.onActivityDrawn();
Daniel Sandler1ce804392012-11-07 15:07:12 -05005649 }
5650 });
Dianne Hackborn90c52de2011-09-23 12:57:44 -07005651 }
5652 }
5653
Jorim Jaggicff0acb2014-03-31 16:35:15 +02005654 @Override
5655 public boolean isKeyguardDrawnLw() {
5656 synchronized (mLock) {
Jeff Brown3ee549c2014-09-22 20:14:39 -07005657 return mKeyguardDrawnOnce;
Jorim Jaggicff0acb2014-03-31 16:35:15 +02005658 }
5659 }
5660
Jorim Jaggi0d674622014-05-21 01:34:15 +02005661 @Override
Jorim Jaggie29b2db2014-05-30 23:17:03 +02005662 public void startKeyguardExitAnimation(long startTime, long fadeoutDuration) {
Jorim Jaggi0d674622014-05-21 01:34:15 +02005663 if (mKeyguardDelegate != null) {
Craig Mautnerc0d2d0a2014-10-31 16:25:15 -07005664 if (DEBUG_KEYGUARD) Slog.d(TAG, "PWM.startKeyguardExitAnimation");
Jorim Jaggie29b2db2014-05-30 23:17:03 +02005665 mKeyguardDelegate.startKeyguardExitAnimation(startTime, fadeoutDuration);
Jorim Jaggi0d674622014-05-21 01:34:15 +02005666 }
5667 }
5668
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005669 void sendCloseSystemWindows() {
Jorim Jaggib10e33f2015-02-04 21:57:40 +01005670 PhoneWindow.sendCloseSystemWindows(mContext, null);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005671 }
5672
5673 void sendCloseSystemWindows(String reason) {
Jorim Jaggib10e33f2015-02-04 21:57:40 +01005674 PhoneWindow.sendCloseSystemWindows(mContext, reason);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005675 }
Mitsuru Oshima831d0d92009-06-16 18:27:18 -07005676
Jeff Brown01a98dd2011-09-20 15:08:29 -07005677 @Override
5678 public int rotationForOrientationLw(int orientation, int lastRotation) {
Daniel Sandler2ed6ad62011-02-22 14:54:17 -05005679 if (false) {
5680 Slog.v(TAG, "rotationForOrientationLw(orient="
5681 + orientation + ", last=" + lastRotation
5682 + "); user=" + mUserRotation + " "
5683 + ((mUserRotationMode == WindowManagerPolicy.USER_ROTATION_LOCKED)
5684 ? "USER_ROTATION_LOCKED" : "")
5685 );
5686 }
5687
Craig Mautner46ac6fa2013-08-01 10:06:34 -07005688 if (mForceDefaultOrientation) {
5689 return Surface.ROTATION_0;
5690 }
5691
The Android Open Source Project0727d222009-03-11 12:11:58 -07005692 synchronized (mLock) {
Jeff Brownc0347aa2011-09-23 17:26:09 -07005693 int sensorRotation = mOrientationListener.getProposedRotation(); // may be -1
5694 if (sensorRotation < 0) {
Jeff Brown0f862b42012-09-27 21:11:01 -07005695 sensorRotation = lastRotation;
Jeff Brownc0347aa2011-09-23 17:26:09 -07005696 }
Jeff Brown01a98dd2011-09-20 15:08:29 -07005697
Jeff Browndec6cf42011-11-15 14:08:20 -08005698 final int preferredRotation;
Jeff Brown2e7760e2012-04-11 15:14:55 -07005699 if (mLidState == LID_OPEN && mLidOpenRotation >= 0) {
Jeff Brown01a98dd2011-09-20 15:08:29 -07005700 // Ignore sensor when lid switch is open and rotation is forced.
5701 preferredRotation = mLidOpenRotation;
5702 } else if (mDockMode == Intent.EXTRA_DOCK_STATE_CAR
Jeff Brownc0347aa2011-09-23 17:26:09 -07005703 && (mCarDockEnablesAccelerometer || mCarDockRotation >= 0)) {
Jeff Brown01a98dd2011-09-20 15:08:29 -07005704 // Ignore sensor when in car dock unless explicitly enabled.
5705 // This case can override the behavior of NOSENSOR, and can also
5706 // enable 180 degree rotation while docked.
Jeff Brownc0347aa2011-09-23 17:26:09 -07005707 preferredRotation = mCarDockEnablesAccelerometer
Jeff Brown01a98dd2011-09-20 15:08:29 -07005708 ? sensorRotation : mCarDockRotation;
Jeff Brown1a693182011-11-08 14:44:16 -08005709 } else if ((mDockMode == Intent.EXTRA_DOCK_STATE_DESK
5710 || mDockMode == Intent.EXTRA_DOCK_STATE_LE_DESK
5711 || mDockMode == Intent.EXTRA_DOCK_STATE_HE_DESK)
Jeff Brownc0347aa2011-09-23 17:26:09 -07005712 && (mDeskDockEnablesAccelerometer || mDeskDockRotation >= 0)) {
Jeff Brown01a98dd2011-09-20 15:08:29 -07005713 // Ignore sensor when in desk dock unless explicitly enabled.
5714 // This case can override the behavior of NOSENSOR, and can also
5715 // enable 180 degree rotation while docked.
Jeff Brownc0347aa2011-09-23 17:26:09 -07005716 preferredRotation = mDeskDockEnablesAccelerometer
Jeff Brown01a98dd2011-09-20 15:08:29 -07005717 ? sensorRotation : mDeskDockRotation;
Jeff Brownc82c89ed2013-04-17 17:18:15 -07005718 } else if (mHdmiPlugged && mDemoHdmiRotationLock) {
5719 // Ignore sensor when plugged into HDMI when demo HDMI rotation lock enabled.
Jeff Browneb3e4b92011-12-06 19:54:24 -08005720 // Note that the dock orientation overrides the HDMI orientation.
Jeff Brownc82c89ed2013-04-17 17:18:15 -07005721 preferredRotation = mDemoHdmiRotation;
5722 } else if (mHdmiPlugged && mDockMode == Intent.EXTRA_DOCK_STATE_UNDOCKED
5723 && mUndockedHdmiRotation >= 0) {
5724 // Ignore sensor when plugged into HDMI and an undocked orientation has
5725 // been specified in the configuration (only for legacy devices without
5726 // full multi-display support).
5727 // Note that the dock orientation overrides the HDMI orientation.
5728 preferredRotation = mUndockedHdmiRotation;
Chong Zhangae6119ff2014-11-11 18:54:39 -08005729 } else if (mDemoRotationLock) {
5730 // Ignore sensor when demo rotation lock is enabled.
5731 // Note that the dock orientation and HDMI rotation lock override this.
5732 preferredRotation = mDemoRotation;
Dianne Hackbornb9ec1ac2013-04-10 17:34:25 -07005733 } else if (orientation == ActivityInfo.SCREEN_ORIENTATION_LOCKED) {
5734 // Application just wants to remain locked in the last rotation.
5735 preferredRotation = lastRotation;
Jeff Brownbcdfc622014-03-06 19:13:04 -08005736 } else if (!mSupportAutoRotation) {
5737 // If we don't support auto-rotation then bail out here and ignore
5738 // the sensor and any rotation lock settings.
5739 preferredRotation = -1;
Jeff Brown207673cd2012-06-05 17:47:11 -07005740 } else if ((mUserRotationMode == WindowManagerPolicy.USER_ROTATION_FREE
Jeff Brown01a98dd2011-09-20 15:08:29 -07005741 && (orientation == ActivityInfo.SCREEN_ORIENTATION_USER
Dianne Hackbornb9ec1ac2013-04-10 17:34:25 -07005742 || orientation == ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED
5743 || orientation == ActivityInfo.SCREEN_ORIENTATION_USER_LANDSCAPE
5744 || orientation == ActivityInfo.SCREEN_ORIENTATION_USER_PORTRAIT
5745 || orientation == ActivityInfo.SCREEN_ORIENTATION_FULL_USER))
Jeff Brown01a98dd2011-09-20 15:08:29 -07005746 || orientation == ActivityInfo.SCREEN_ORIENTATION_SENSOR
5747 || orientation == ActivityInfo.SCREEN_ORIENTATION_FULL_SENSOR
5748 || orientation == ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE
5749 || orientation == ActivityInfo.SCREEN_ORIENTATION_SENSOR_PORTRAIT) {
5750 // Otherwise, use sensor only if requested by the application or enabled
5751 // by default for USER or UNSPECIFIED modes. Does not apply to NOSENSOR.
Jeff Brownd3187e32011-09-21 19:26:44 -07005752 if (mAllowAllRotations < 0) {
5753 // Can't read this during init() because the context doesn't
5754 // have display metrics at that time so we cannot determine
5755 // tablet vs. phone then.
5756 mAllowAllRotations = mContext.getResources().getBoolean(
5757 com.android.internal.R.bool.config_allowAllRotations) ? 1 : 0;
5758 }
Jeff Brown01a98dd2011-09-20 15:08:29 -07005759 if (sensorRotation != Surface.ROTATION_180
Jeff Brownd3187e32011-09-21 19:26:44 -07005760 || mAllowAllRotations == 1
Dianne Hackbornb9ec1ac2013-04-10 17:34:25 -07005761 || orientation == ActivityInfo.SCREEN_ORIENTATION_FULL_SENSOR
5762 || orientation == ActivityInfo.SCREEN_ORIENTATION_FULL_USER) {
Jeff Brown01a98dd2011-09-20 15:08:29 -07005763 preferredRotation = sensorRotation;
5764 } else {
5765 preferredRotation = lastRotation;
5766 }
Jeff Brown207673cd2012-06-05 17:47:11 -07005767 } else if (mUserRotationMode == WindowManagerPolicy.USER_ROTATION_LOCKED
5768 && orientation != ActivityInfo.SCREEN_ORIENTATION_NOSENSOR) {
5769 // Apply rotation lock. Does not apply to NOSENSOR.
5770 // The idea is that the user rotation expresses a weak preference for the direction
5771 // of gravity and as NOSENSOR is never affected by gravity, then neither should
5772 // NOSENSOR be affected by rotation lock (although it will be affected by docks).
Jeff Brown4dfce202011-10-05 12:00:10 -07005773 preferredRotation = mUserRotation;
Jeff Browndec6cf42011-11-15 14:08:20 -08005774 } else {
5775 // No overriding preference.
5776 // We will do exactly what the application asked us to do.
5777 preferredRotation = -1;
Jeff Brown01a98dd2011-09-20 15:08:29 -07005778 }
5779
Dianne Hackborne5439f22010-10-02 16:53:50 -07005780 switch (orientation) {
5781 case ActivityInfo.SCREEN_ORIENTATION_PORTRAIT:
Jeff Browndec6cf42011-11-15 14:08:20 -08005782 // Return portrait unless overridden.
5783 if (isAnyPortrait(preferredRotation)) {
5784 return preferredRotation;
5785 }
Dianne Hackborne5439f22010-10-02 16:53:50 -07005786 return mPortraitRotation;
Dianne Hackborne5439f22010-10-02 16:53:50 -07005787
Jeff Brown01a98dd2011-09-20 15:08:29 -07005788 case ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE:
Jeff Browndec6cf42011-11-15 14:08:20 -08005789 // Return landscape unless overridden.
5790 if (isLandscapeOrSeascape(preferredRotation)) {
5791 return preferredRotation;
5792 }
Jeff Brown01a98dd2011-09-20 15:08:29 -07005793 return mLandscapeRotation;
5794
5795 case ActivityInfo.SCREEN_ORIENTATION_REVERSE_PORTRAIT:
Jeff Browndec6cf42011-11-15 14:08:20 -08005796 // Return reverse portrait unless overridden.
5797 if (isAnyPortrait(preferredRotation)) {
5798 return preferredRotation;
5799 }
Jeff Brown01a98dd2011-09-20 15:08:29 -07005800 return mUpsideDownRotation;
5801
5802 case ActivityInfo.SCREEN_ORIENTATION_REVERSE_LANDSCAPE:
Jeff Browndec6cf42011-11-15 14:08:20 -08005803 // Return seascape unless overridden.
5804 if (isLandscapeOrSeascape(preferredRotation)) {
5805 return preferredRotation;
5806 }
Jeff Brown01a98dd2011-09-20 15:08:29 -07005807 return mSeascapeRotation;
5808
5809 case ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE:
Dianne Hackbornb9ec1ac2013-04-10 17:34:25 -07005810 case ActivityInfo.SCREEN_ORIENTATION_USER_LANDSCAPE:
Jeff Brown01a98dd2011-09-20 15:08:29 -07005811 // Return either landscape rotation.
5812 if (isLandscapeOrSeascape(preferredRotation)) {
5813 return preferredRotation;
5814 }
5815 if (isLandscapeOrSeascape(lastRotation)) {
Jeff Brown4519f072011-01-23 13:16:01 -08005816 return lastRotation;
5817 }
Jeff Brown01a98dd2011-09-20 15:08:29 -07005818 return mLandscapeRotation;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005819
Jeff Brown01a98dd2011-09-20 15:08:29 -07005820 case ActivityInfo.SCREEN_ORIENTATION_SENSOR_PORTRAIT:
Dianne Hackbornb9ec1ac2013-04-10 17:34:25 -07005821 case ActivityInfo.SCREEN_ORIENTATION_USER_PORTRAIT:
Jeff Brown01a98dd2011-09-20 15:08:29 -07005822 // Return either portrait rotation.
5823 if (isAnyPortrait(preferredRotation)) {
5824 return preferredRotation;
5825 }
5826 if (isAnyPortrait(lastRotation)) {
5827 return lastRotation;
5828 }
5829 return mPortraitRotation;
5830
5831 default:
Jeff Brown4dfce202011-10-05 12:00:10 -07005832 // For USER, UNSPECIFIED, NOSENSOR, SENSOR and FULL_SENSOR,
5833 // just return the preferred orientation we already calculated.
Jeff Brown01a98dd2011-09-20 15:08:29 -07005834 if (preferredRotation >= 0) {
5835 return preferredRotation;
5836 }
Dianne Hackborndacea8c2011-04-21 17:26:39 -07005837 return Surface.ROTATION_0;
Daniel Sandlere7e5ac22011-02-22 16:10:21 -05005838 }
5839 }
Steve Howarda7bfe6a2010-09-23 16:47:49 -07005840 }
5841
Jeff Brown01a98dd2011-09-20 15:08:29 -07005842 @Override
5843 public boolean rotationHasCompatibleMetricsLw(int orientation, int rotation) {
5844 switch (orientation) {
5845 case ActivityInfo.SCREEN_ORIENTATION_PORTRAIT:
5846 case ActivityInfo.SCREEN_ORIENTATION_REVERSE_PORTRAIT:
5847 case ActivityInfo.SCREEN_ORIENTATION_SENSOR_PORTRAIT:
5848 return isAnyPortrait(rotation);
5849
5850 case ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE:
5851 case ActivityInfo.SCREEN_ORIENTATION_REVERSE_LANDSCAPE:
5852 case ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE:
5853 return isLandscapeOrSeascape(rotation);
5854
5855 default:
5856 return true;
5857 }
Steve Howarda7bfe6a2010-09-23 16:47:49 -07005858 }
5859
Jeff Brownc0347aa2011-09-23 17:26:09 -07005860 @Override
5861 public void setRotationLw(int rotation) {
5862 mOrientationListener.setCurrentRotation(rotation);
5863 }
5864
Jeff Brown01a98dd2011-09-20 15:08:29 -07005865 private boolean isLandscapeOrSeascape(int rotation) {
5866 return rotation == mLandscapeRotation || rotation == mSeascapeRotation;
Dianne Hackborne5439f22010-10-02 16:53:50 -07005867 }
5868
Jeff Brown01a98dd2011-09-20 15:08:29 -07005869 private boolean isAnyPortrait(int rotation) {
5870 return rotation == mPortraitRotation || rotation == mUpsideDownRotation;
Dianne Hackborne5439f22010-10-02 16:53:50 -07005871 }
5872
Jose Lima9546b202014-07-02 17:21:51 -07005873 @Override
Svetoslav Ganov80943d82013-01-02 10:25:37 -08005874 public int getUserRotationMode() {
5875 return Settings.System.getIntForUser(mContext.getContentResolver(),
Brett Chabot7e55c402013-05-16 19:38:08 -07005876 Settings.System.ACCELEROMETER_ROTATION, 0, UserHandle.USER_CURRENT) != 0 ?
5877 WindowManagerPolicy.USER_ROTATION_FREE :
5878 WindowManagerPolicy.USER_ROTATION_LOCKED;
Svetoslav Ganov80943d82013-01-02 10:25:37 -08005879 }
Daniel Sandlerb73617d2010-08-17 00:41:00 -04005880
5881 // User rotation: to be used when all else fails in assigning an orientation to the device
Jose Lima9546b202014-07-02 17:21:51 -07005882 @Override
Daniel Sandlerb73617d2010-08-17 00:41:00 -04005883 public void setUserRotationMode(int mode, int rot) {
5884 ContentResolver res = mContext.getContentResolver();
Daniel Sandler2ed6ad62011-02-22 14:54:17 -05005885
5886 // mUserRotationMode and mUserRotation will be assigned by the content observer
Daniel Sandlerb73617d2010-08-17 00:41:00 -04005887 if (mode == WindowManagerPolicy.USER_ROTATION_LOCKED) {
Christopher Tate5e08af02012-09-21 17:17:22 -07005888 Settings.System.putIntForUser(res,
Daniel Sandlerb73617d2010-08-17 00:41:00 -04005889 Settings.System.USER_ROTATION,
Christopher Tate5e08af02012-09-21 17:17:22 -07005890 rot,
5891 UserHandle.USER_CURRENT);
5892 Settings.System.putIntForUser(res,
Daniel Sandler2ed6ad62011-02-22 14:54:17 -05005893 Settings.System.ACCELEROMETER_ROTATION,
Christopher Tate5e08af02012-09-21 17:17:22 -07005894 0,
5895 UserHandle.USER_CURRENT);
Daniel Sandlerb73617d2010-08-17 00:41:00 -04005896 } else {
Christopher Tate5e08af02012-09-21 17:17:22 -07005897 Settings.System.putIntForUser(res,
Daniel Sandlerb73617d2010-08-17 00:41:00 -04005898 Settings.System.ACCELEROMETER_ROTATION,
Christopher Tate5e08af02012-09-21 17:17:22 -07005899 1,
5900 UserHandle.USER_CURRENT);
Daniel Sandlerb73617d2010-08-17 00:41:00 -04005901 }
5902 }
5903
Jose Lima9546b202014-07-02 17:21:51 -07005904 @Override
Jeff Brownac143512012-04-05 18:57:33 -07005905 public void setSafeMode(boolean safeMode) {
5906 mSafeMode = safeMode;
5907 performHapticFeedbackLw(null, safeMode
5908 ? HapticFeedbackConstants.SAFE_MODE_ENABLED
5909 : HapticFeedbackConstants.SAFE_MODE_DISABLED, true);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005910 }
Craig Mautnereda67292013-04-28 13:50:14 -07005911
Dianne Hackborn181ceb52009-08-27 22:16:40 -07005912 static long[] getLongIntArray(Resources r, int resid) {
5913 int[] ar = r.getIntArray(resid);
5914 if (ar == null) {
5915 return null;
5916 }
5917 long[] out = new long[ar.length];
5918 for (int i=0; i<ar.length; i++) {
5919 out[i] = ar[i];
5920 }
5921 return out;
5922 }
Craig Mautnereda67292013-04-28 13:50:14 -07005923
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005924 /** {@inheritDoc} */
Craig Mautnereda67292013-04-28 13:50:14 -07005925 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005926 public void systemReady() {
Jim Millerab954542014-10-10 18:21:49 -07005927 mKeyguardDelegate = new KeyguardServiceDelegate(mContext);
Mike Lockwooded8902d2013-11-15 11:01:47 -08005928 mKeyguardDelegate.onSystemReady();
5929
Michael Wright3818c922014-09-02 13:59:07 -07005930 readCameraLensCoverState();
Jeff Brown4f5fa282014-06-12 19:19:15 -07005931 updateUiMode();
Dianne Hackbornb1a79802009-09-29 15:18:31 -07005932 synchronized (mLock) {
5933 updateOrientationListenerLp();
Dianne Hackbornc777e072010-02-12 13:07:59 -08005934 mSystemReady = true;
5935 mHandler.post(new Runnable() {
Craig Mautnereda67292013-04-28 13:50:14 -07005936 @Override
Dianne Hackbornc777e072010-02-12 13:07:59 -08005937 public void run() {
5938 updateSettings();
5939 }
5940 });
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005941 }
5942 }
Dianne Hackborn661cd522011-08-22 00:26:20 -07005943
Dianne Hackbornba24e4d2011-09-01 11:17:06 -07005944 /** {@inheritDoc} */
Jose Lima9546b202014-07-02 17:21:51 -07005945 @Override
Dianne Hackbornba24e4d2011-09-01 11:17:06 -07005946 public void systemBooted() {
Jim Millere5f910a2013-10-16 18:15:46 -07005947 if (mKeyguardDelegate != null) {
Jason Monk5eeebf52014-09-26 12:36:51 -04005948 mKeyguardDelegate.bindService(mContext);
Jim Millere5f910a2013-10-16 18:15:46 -07005949 mKeyguardDelegate.onBootCompleted();
5950 }
Dianne Hackbornba24e4d2011-09-01 11:17:06 -07005951 synchronized (mLock) {
5952 mSystemBooted = true;
5953 }
Jeff Brown416c49c2015-05-26 19:50:18 -07005954 startedWakingUp();
Jeff Brown36c4db82014-09-19 12:05:31 -07005955 screenTurningOn(null);
Dianne Hackbornba24e4d2011-09-01 11:17:06 -07005956 }
5957
Dianne Hackborn661cd522011-08-22 00:26:20 -07005958 ProgressDialog mBootMsgDialog = null;
5959
5960 /** {@inheritDoc} */
Jose Lima9546b202014-07-02 17:21:51 -07005961 @Override
Dianne Hackborn661cd522011-08-22 00:26:20 -07005962 public void showBootMessage(final CharSequence msg, final boolean always) {
5963 mHandler.post(new Runnable() {
5964 @Override public void run() {
5965 if (mBootMsgDialog == null) {
Craig Stout4c0cb8a2014-04-04 13:03:10 -07005966 int theme;
5967 if (mContext.getPackageManager().hasSystemFeature(
5968 PackageManager.FEATURE_WATCH)) {
5969 theme = com.android.internal.R.style.Theme_Micro_Dialog_Alert;
5970 } else if (mContext.getPackageManager().hasSystemFeature(
5971 PackageManager.FEATURE_TELEVISION)) {
5972 theme = com.android.internal.R.style.Theme_Leanback_Dialog_Alert;
5973 } else {
5974 theme = 0;
5975 }
Vinod Krishnanfa8fc412014-04-18 14:35:53 -07005976
5977 mBootMsgDialog = new ProgressDialog(mContext, theme) {
Dianne Hackborn295e3c22011-08-25 13:19:08 -07005978 // This dialog will consume all events coming in to
5979 // it, to avoid it trying to do things too early in boot.
5980 @Override public boolean dispatchKeyEvent(KeyEvent event) {
5981 return true;
5982 }
5983 @Override public boolean dispatchKeyShortcutEvent(KeyEvent event) {
5984 return true;
5985 }
5986 @Override public boolean dispatchTouchEvent(MotionEvent ev) {
5987 return true;
5988 }
5989 @Override public boolean dispatchTrackballEvent(MotionEvent ev) {
5990 return true;
5991 }
5992 @Override public boolean dispatchGenericMotionEvent(MotionEvent ev) {
5993 return true;
5994 }
5995 @Override public boolean dispatchPopulateAccessibilityEvent(
5996 AccessibilityEvent event) {
5997 return true;
5998 }
5999 };
Jeff Hao9f60c082014-10-28 18:51:07 -07006000 if (mContext.getPackageManager().isUpgrade()) {
6001 mBootMsgDialog.setTitle(R.string.android_upgrading_title);
6002 } else {
6003 mBootMsgDialog.setTitle(R.string.android_start_title);
6004 }
Dianne Hackborn661cd522011-08-22 00:26:20 -07006005 mBootMsgDialog.setProgressStyle(ProgressDialog.STYLE_SPINNER);
6006 mBootMsgDialog.setIndeterminate(true);
6007 mBootMsgDialog.getWindow().setType(
Dianne Hackborn29aae6f2011-08-18 18:30:09 -07006008 WindowManager.LayoutParams.TYPE_BOOT_PROGRESS);
Dianne Hackborn661cd522011-08-22 00:26:20 -07006009 mBootMsgDialog.getWindow().addFlags(
6010 WindowManager.LayoutParams.FLAG_DIM_BEHIND
6011 | WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN);
6012 mBootMsgDialog.getWindow().setDimAmount(1);
Dianne Hackbornd9efb952011-12-07 14:56:51 -08006013 WindowManager.LayoutParams lp = mBootMsgDialog.getWindow().getAttributes();
6014 lp.screenOrientation = ActivityInfo.SCREEN_ORIENTATION_NOSENSOR;
6015 mBootMsgDialog.getWindow().setAttributes(lp);
Dianne Hackborn661cd522011-08-22 00:26:20 -07006016 mBootMsgDialog.setCancelable(false);
6017 mBootMsgDialog.show();
6018 }
6019 mBootMsgDialog.setMessage(msg);
6020 }
6021 });
6022 }
6023
6024 /** {@inheritDoc} */
Jose Lima9546b202014-07-02 17:21:51 -07006025 @Override
Dianne Hackborn661cd522011-08-22 00:26:20 -07006026 public void hideBootMessages() {
Craig Mautnera631d492014-08-05 15:16:01 -07006027 mHandler.sendEmptyMessage(MSG_HIDE_BOOT_MESSAGE);
Dianne Hackborn661cd522011-08-22 00:26:20 -07006028 }
6029
Mike Lockwood28569302010-01-28 11:54:40 -05006030 /** {@inheritDoc} */
Jose Lima9546b202014-07-02 17:21:51 -07006031 @Override
Mike Lockwood28569302010-01-28 11:54:40 -05006032 public void userActivity() {
Dianne Hackborndf89e652011-10-06 22:35:11 -07006033 // ***************************************
6034 // NOTE NOTE NOTE NOTE NOTE NOTE NOTE NOTE
6035 // ***************************************
6036 // THIS IS CALLED FROM DEEP IN THE POWER MANAGER
6037 // WITH ITS LOCKS HELD.
6038 //
6039 // This code must be VERY careful about the locks
6040 // it acquires.
6041 // In fact, the current code acquires way too many,
6042 // and probably has lurking deadlocks.
6043
Mike Lockwood28569302010-01-28 11:54:40 -05006044 synchronized (mScreenLockTimeout) {
6045 if (mLockScreenTimerActive) {
6046 // reset the timer
6047 mHandler.removeCallbacks(mScreenLockTimeout);
6048 mHandler.postDelayed(mScreenLockTimeout, mLockScreenTimeout);
6049 }
6050 }
Daniel Sandler0601eb72011-04-13 01:01:32 -04006051 }
6052
Adam Cohenf7522022012-10-03 20:03:18 -07006053 class ScreenLockTimeout implements Runnable {
6054 Bundle options;
6055
6056 @Override
Mike Lockwood28569302010-01-28 11:54:40 -05006057 public void run() {
6058 synchronized (this) {
6059 if (localLOGV) Log.v(TAG, "mScreenLockTimeout activating keyguard");
Jim Miller5ecd8112013-01-09 18:50:26 -08006060 if (mKeyguardDelegate != null) {
6061 mKeyguardDelegate.doKeyguardTimeout(options);
Mike Lockwood3a74bd32011-08-12 13:55:22 -07006062 }
Mike Lockwood28569302010-01-28 11:54:40 -05006063 mLockScreenTimerActive = false;
Adam Cohenf7522022012-10-03 20:03:18 -07006064 options = null;
Mike Lockwood28569302010-01-28 11:54:40 -05006065 }
6066 }
Mike Lockwood28569302010-01-28 11:54:40 -05006067
Adam Cohenf7522022012-10-03 20:03:18 -07006068 public void setLockOptions(Bundle options) {
6069 this.options = options;
6070 }
6071 }
6072
6073 ScreenLockTimeout mScreenLockTimeout = new ScreenLockTimeout();
6074
Jose Lima9546b202014-07-02 17:21:51 -07006075 @Override
Adam Cohenf7522022012-10-03 20:03:18 -07006076 public void lockNow(Bundle options) {
Jim Miller93c518e2012-01-17 15:55:31 -08006077 mContext.enforceCallingOrSelfPermission(android.Manifest.permission.DEVICE_POWER, null);
6078 mHandler.removeCallbacks(mScreenLockTimeout);
Adam Cohenf7522022012-10-03 20:03:18 -07006079 if (options != null) {
6080 // In case multiple calls are made to lockNow, we don't wipe out the options
6081 // until the runnable actually executes.
6082 mScreenLockTimeout.setLockOptions(options);
6083 }
Jim Miller93c518e2012-01-17 15:55:31 -08006084 mHandler.post(mScreenLockTimeout);
6085 }
6086
Mike Lockwood28569302010-01-28 11:54:40 -05006087 private void updateLockScreenTimeout() {
6088 synchronized (mScreenLockTimeout) {
Jeff Brown3ee549c2014-09-22 20:14:39 -07006089 boolean enable = (mAllowLockscreenWhenOn && mAwake &&
Jim Miller5ecd8112013-01-09 18:50:26 -08006090 mKeyguardDelegate != null && mKeyguardDelegate.isSecure());
Mike Lockwood28569302010-01-28 11:54:40 -05006091 if (mLockScreenTimerActive != enable) {
6092 if (enable) {
6093 if (localLOGV) Log.v(TAG, "setting lockscreen timer");
6094 mHandler.postDelayed(mScreenLockTimeout, mLockScreenTimeout);
6095 } else {
6096 if (localLOGV) Log.v(TAG, "clearing lockscreen timer");
6097 mHandler.removeCallbacks(mScreenLockTimeout);
6098 }
6099 mLockScreenTimerActive = enable;
6100 }
6101 }
6102 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006103
Jeff Brown061ea992015-04-17 19:55:47 -07006104 private void updateDreamingSleepToken(boolean acquire) {
6105 if (acquire) {
6106 if (mDreamingSleepToken == null) {
6107 mDreamingSleepToken = mActivityManagerInternal.acquireSleepToken("Dream");
6108 }
6109 } else {
6110 if (mDreamingSleepToken != null) {
6111 mDreamingSleepToken.release();
Jeff Brown48d1b142015-06-10 16:36:03 -07006112 mDreamingSleepToken = null;
6113 }
6114 }
6115 }
6116
6117 private void updateScreenOffSleepToken(boolean acquire) {
6118 if (acquire) {
6119 if (mScreenOffSleepToken == null) {
6120 mScreenOffSleepToken = mActivityManagerInternal.acquireSleepToken("ScreenOff");
6121 }
6122 } else {
6123 if (mScreenOffSleepToken != null) {
6124 mScreenOffSleepToken.release();
6125 mScreenOffSleepToken = null;
Jeff Brown061ea992015-04-17 19:55:47 -07006126 }
6127 }
6128 }
6129
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006130 /** {@inheritDoc} */
Craig Mautnereda67292013-04-28 13:50:14 -07006131 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006132 public void enableScreenAfterBoot() {
6133 readLidState();
Jeff Brownc458ce92012-04-30 14:58:40 -07006134 applyLidSwitchState();
Jeff Brown01a98dd2011-09-20 15:08:29 -07006135 updateRotation(true);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006136 }
Dianne Hackbornf54c8f92009-09-19 14:03:57 -07006137
Jeff Brownc458ce92012-04-30 14:58:40 -07006138 private void applyLidSwitchState() {
Jeff Brownc458ce92012-04-30 14:58:40 -07006139 if (mLidState == LID_CLOSED && mLidControlsSleep) {
Jeff Brown6d8fd272014-05-20 21:24:38 -07006140 mPowerManager.goToSleep(SystemClock.uptimeMillis(),
Jeff Brownc12035c2014-08-13 18:52:25 -07006141 PowerManager.GO_TO_SLEEP_REASON_LID_SWITCH,
Jeff Brown6d8fd272014-05-20 21:24:38 -07006142 PowerManager.GO_TO_SLEEP_FLAG_NO_DOZE);
Jeff Brownc458ce92012-04-30 14:58:40 -07006143 }
Jeff Browna20dda42014-05-27 20:57:24 -07006144
6145 synchronized (mLock) {
6146 updateWakeGestureListenerLp();
6147 }
Jeff Brown01a98dd2011-09-20 15:08:29 -07006148 }
6149
Jeff Brown4f5fa282014-06-12 19:19:15 -07006150 void updateUiMode() {
6151 if (mUiModeManager == null) {
6152 mUiModeManager = IUiModeManager.Stub.asInterface(
6153 ServiceManager.getService(Context.UI_MODE_SERVICE));
6154 }
6155 try {
6156 mUiMode = mUiModeManager.getCurrentModeType();
6157 } catch (RemoteException e) {
6158 }
6159 }
6160
Jeff Brown01a98dd2011-09-20 15:08:29 -07006161 void updateRotation(boolean alwaysSendConfiguration) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006162 try {
6163 //set orientation on WindowManager
Dianne Hackbornf87d1962012-04-04 12:48:24 -07006164 mWindowManager.updateRotation(alwaysSendConfiguration, false);
6165 } catch (RemoteException e) {
6166 // Ignore
6167 }
6168 }
6169
6170 void updateRotation(boolean alwaysSendConfiguration, boolean forceRelayout) {
6171 try {
6172 //set orientation on WindowManager
6173 mWindowManager.updateRotation(alwaysSendConfiguration, forceRelayout);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006174 } catch (RemoteException e) {
6175 // Ignore
6176 }
6177 }
6178
Daniel Sandler6396c722013-04-16 20:19:09 -04006179 /**
6180 * Return an Intent to launch the currently active dock app as home. Returns
6181 * null if the standard home should be launched, which is the case if any of the following is
6182 * true:
6183 * <ul>
6184 * <li>The device is not in either car mode or desk mode
6185 * <li>The device is in car mode but ENABLE_CAR_DOCK_HOME_CAPTURE is false
6186 * <li>The device is in desk mode but ENABLE_DESK_DOCK_HOME_CAPTURE is false
6187 * <li>The device is in car mode but there's no CAR_DOCK app with METADATA_DOCK_HOME
6188 * <li>The device is in desk mode but there's no DESK_DOCK app with METADATA_DOCK_HOME
6189 * </ul>
Craig Mautnereda67292013-04-28 13:50:14 -07006190 * @return A dock intent.
Daniel Sandler6396c722013-04-16 20:19:09 -04006191 */
6192 Intent createHomeDockIntent() {
6193 Intent intent = null;
6194
6195 // What home does is based on the mode, not the dock state. That
6196 // is, when in car mode you should be taken to car home regardless
6197 // of whether we are actually in a car dock.
6198 if (mUiMode == Configuration.UI_MODE_TYPE_CAR) {
6199 if (ENABLE_CAR_DOCK_HOME_CAPTURE) {
6200 intent = mCarDockIntent;
6201 }
6202 } else if (mUiMode == Configuration.UI_MODE_TYPE_DESK) {
6203 if (ENABLE_DESK_DOCK_HOME_CAPTURE) {
6204 intent = mDeskDockIntent;
6205 }
Jeff Brown4f5fa282014-06-12 19:19:15 -07006206 } else if (mUiMode == Configuration.UI_MODE_TYPE_WATCH
6207 && (mDockMode == Intent.EXTRA_DOCK_STATE_DESK
6208 || mDockMode == Intent.EXTRA_DOCK_STATE_HE_DESK
6209 || mDockMode == Intent.EXTRA_DOCK_STATE_LE_DESK)) {
6210 // Always launch dock home from home when watch is docked, if it exists.
6211 intent = mDeskDockIntent;
Daniel Sandler6396c722013-04-16 20:19:09 -04006212 }
6213
6214 if (intent == null) {
6215 return null;
6216 }
6217
6218 ActivityInfo ai = null;
6219 ResolveInfo info = mContext.getPackageManager().resolveActivityAsUser(
6220 intent,
John Spurlockf56bef12013-07-09 09:51:46 -04006221 PackageManager.MATCH_DEFAULT_ONLY | PackageManager.GET_META_DATA,
Craig Mautnerd625ab22013-09-06 13:40:31 -07006222 mCurrentUserId);
Daniel Sandler6396c722013-04-16 20:19:09 -04006223 if (info != null) {
6224 ai = info.activityInfo;
6225 }
6226 if (ai != null
6227 && ai.metaData != null
6228 && ai.metaData.getBoolean(Intent.METADATA_DOCK_HOME)) {
6229 intent = new Intent(intent);
6230 intent.setClassName(ai.packageName, ai.name);
6231 return intent;
6232 }
6233
6234 return null;
6235 }
6236
Filip Gruszczynskia483a1d2015-03-17 19:06:58 +00006237 void startDockOrHome(boolean fromHomeKey, boolean awakenFromDreams) {
6238 if (awakenFromDreams) {
6239 awakenDreams();
6240 }
Daniel Sandler6396c722013-04-16 20:19:09 -04006241
6242 Intent dock = createHomeDockIntent();
6243 if (dock != null) {
6244 try {
Bryce Lee01b0c5f2015-02-05 18:24:04 -08006245 if (fromHomeKey) {
6246 dock.putExtra(WindowManagerPolicy.EXTRA_FROM_HOME_KEY, fromHomeKey);
6247 }
Bart Sears8b1c27c2015-03-18 23:51:02 +00006248 startActivityAsUser(dock, UserHandle.CURRENT);
Daniel Sandler6396c722013-04-16 20:19:09 -04006249 return;
6250 } catch (ActivityNotFoundException e) {
6251 }
6252 }
6253
Bryce Lee01b0c5f2015-02-05 18:24:04 -08006254 Intent intent;
6255
6256 if (fromHomeKey) {
6257 intent = new Intent(mHomeIntent);
6258 intent.putExtra(WindowManagerPolicy.EXTRA_FROM_HOME_KEY, fromHomeKey);
6259 } else {
6260 intent = mHomeIntent;
6261 }
6262
Bryce Lee9fc0b6f2015-03-19 21:37:45 +00006263 startActivityAsUser(intent, UserHandle.CURRENT);
Dianne Hackborn39c2d712009-09-22 11:41:31 -07006264 }
Craig Mautnereda67292013-04-28 13:50:14 -07006265
Dianne Hackborn39c2d712009-09-22 11:41:31 -07006266 /**
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006267 * goes to the home screen
6268 * @return whether it did anything
6269 */
6270 boolean goHome() {
Bart Sears8b1c27c2015-03-18 23:51:02 +00006271 if (!isUserSetupComplete()) {
6272 Slog.i(TAG, "Not going home because user setup is in progress.");
6273 return false;
6274 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006275 if (false) {
6276 // This code always brings home to the front.
Dianne Hackborn256dd3b2009-05-19 18:51:21 -07006277 try {
6278 ActivityManagerNative.getDefault().stopAppSwitches();
6279 } catch (RemoteException e) {
6280 }
Dianne Hackborn94a679d2009-07-28 17:51:07 -07006281 sendCloseSystemWindows();
Filip Gruszczynskia483a1d2015-03-17 19:06:58 +00006282 startDockOrHome(false /*fromHomeKey*/, true /* awakenFromDreams */);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006283 } else {
6284 // This code brings home to the front or, if it is already
6285 // at the front, puts the device to sleep.
6286 try {
Wink Savilled2e6a332010-02-12 12:12:06 -08006287 if (SystemProperties.getInt("persist.sys.uts-test-mode", 0) == 1) {
6288 /// Roll back EndcallBehavior as the cupcake design to pass P1 lab entry.
6289 Log.d(TAG, "UTS-TEST-MODE");
6290 } else {
6291 ActivityManagerNative.getDefault().stopAppSwitches();
6292 sendCloseSystemWindows();
Daniel Sandler6396c722013-04-16 20:19:09 -04006293 Intent dock = createHomeDockIntent();
6294 if (dock != null) {
6295 int result = ActivityManagerNative.getDefault()
6296 .startActivityAsUser(null, null, dock,
6297 dock.resolveTypeIfNeeded(mContext.getContentResolver()),
6298 null, null, 0,
6299 ActivityManager.START_FLAG_ONLY_IF_NEEDED,
Jeff Hao1b012d32014-08-20 10:35:34 -07006300 null, null, UserHandle.USER_CURRENT);
Daniel Sandler6396c722013-04-16 20:19:09 -04006301 if (result == ActivityManager.START_RETURN_INTENT_TO_CALLER) {
6302 return false;
6303 }
6304 }
Dianne Hackborn39c2d712009-09-22 11:41:31 -07006305 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006306 int result = ActivityManagerNative.getDefault()
Dianne Hackbornf265ea92013-01-31 15:00:51 -08006307 .startActivityAsUser(null, null, mHomeIntent,
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006308 mHomeIntent.resolveTypeIfNeeded(mContext.getContentResolver()),
Dianne Hackborna4972e92012-03-14 10:38:05 -07006309 null, null, 0,
6310 ActivityManager.START_FLAG_ONLY_IF_NEEDED,
Jeff Hao1b012d32014-08-20 10:35:34 -07006311 null, null, UserHandle.USER_CURRENT);
Dianne Hackborna4972e92012-03-14 10:38:05 -07006312 if (result == ActivityManager.START_RETURN_INTENT_TO_CALLER) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006313 return false;
6314 }
6315 } catch (RemoteException ex) {
6316 // bummer, the activity manager, which is in this process, is dead
6317 }
6318 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006319 return true;
6320 }
Craig Mautnereda67292013-04-28 13:50:14 -07006321
6322 @Override
The Android Open Source Project0727d222009-03-11 12:11:58 -07006323 public void setCurrentOrientationLw(int newOrientation) {
6324 synchronized (mLock) {
6325 if (newOrientation != mCurrentAppOrientation) {
6326 mCurrentAppOrientation = newOrientation;
6327 updateOrientationListenerLp();
6328 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006329 }
6330 }
Amith Yamasanic33cb712010-02-10 15:21:49 -08006331
Svetoslav Ganov7befb7d2012-09-27 16:49:23 -07006332 private void performAuditoryFeedbackForAccessibilityIfNeed() {
6333 if (!isGlobalAccessibilityGestureEnabled()) {
6334 return;
6335 }
6336 AudioManager audioManager = (AudioManager) mContext.getSystemService(
6337 Context.AUDIO_SERVICE);
6338 if (audioManager.isSilentMode()) {
6339 return;
6340 }
6341 Ringtone ringTone = RingtoneManager.getRingtone(mContext,
6342 Settings.System.DEFAULT_NOTIFICATION_URI);
6343 ringTone.setStreamType(AudioManager.STREAM_MUSIC);
6344 ringTone.play();
6345 }
Craig Mautnereda67292013-04-28 13:50:14 -07006346
Bryce Lee584a4452014-10-21 15:55:55 -07006347 private boolean isTheaterModeEnabled() {
6348 return Settings.Global.getInt(mContext.getContentResolver(),
6349 Settings.Global.THEATER_MODE_ON, 0) == 1;
6350 }
6351
Svetoslav Ganov7befb7d2012-09-27 16:49:23 -07006352 private boolean isGlobalAccessibilityGestureEnabled() {
6353 return Settings.Global.getInt(mContext.getContentResolver(),
6354 Settings.Global.ENABLE_ACCESSIBILITY_GLOBAL_GESTURE_ENABLED, 0) == 1;
6355 }
6356
Craig Mautnereda67292013-04-28 13:50:14 -07006357 @Override
The Android Open Source Project0727d222009-03-11 12:11:58 -07006358 public boolean performHapticFeedbackLw(WindowState win, int effectId, boolean always) {
Svetoslav Ganov96179212012-10-10 14:17:45 -07006359 if (!mVibrator.hasVibrator()) {
6360 return false;
6361 }
Christopher Tate5e08af02012-09-21 17:17:22 -07006362 final boolean hapticsDisabled = Settings.System.getIntForUser(mContext.getContentResolver(),
6363 Settings.System.HAPTIC_FEEDBACK_ENABLED, 0, UserHandle.USER_CURRENT) == 0;
Jeff Brown82379ba2014-07-25 19:03:28 -07006364 if (hapticsDisabled && !always) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006365 return false;
6366 }
Amith Yamasanic33cb712010-02-10 15:21:49 -08006367 long[] pattern = null;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006368 switch (effectId) {
6369 case HapticFeedbackConstants.LONG_PRESS:
Amith Yamasanic33cb712010-02-10 15:21:49 -08006370 pattern = mLongPressVibePattern;
6371 break;
Dianne Hackbornb1a79802009-09-29 15:18:31 -07006372 case HapticFeedbackConstants.VIRTUAL_KEY:
Amith Yamasanic33cb712010-02-10 15:21:49 -08006373 pattern = mVirtualKeyVibePattern;
6374 break;
6375 case HapticFeedbackConstants.KEYBOARD_TAP:
6376 pattern = mKeyboardTapVibePattern;
6377 break;
Fabrice Di Meglioeeff63a2013-08-05 12:07:24 -07006378 case HapticFeedbackConstants.CLOCK_TICK:
6379 pattern = mClockTickVibePattern;
6380 break;
Fabrice Di Megliobd9152f2013-10-01 11:21:31 -07006381 case HapticFeedbackConstants.CALENDAR_DATE:
6382 pattern = mCalendarDateVibePattern;
6383 break;
Dianne Hackbornb1a79802009-09-29 15:18:31 -07006384 case HapticFeedbackConstants.SAFE_MODE_DISABLED:
Amith Yamasanic33cb712010-02-10 15:21:49 -08006385 pattern = mSafeModeDisabledVibePattern;
6386 break;
Dianne Hackbornb1a79802009-09-29 15:18:31 -07006387 case HapticFeedbackConstants.SAFE_MODE_ENABLED:
Amith Yamasanic33cb712010-02-10 15:21:49 -08006388 pattern = mSafeModeEnabledVibePattern;
6389 break;
Mady Mellore8608912015-06-05 09:02:55 -07006390 case HapticFeedbackConstants.CONTEXT_CLICK:
6391 pattern = mContextClickVibePattern;
Mady Mellore82067b2015-04-30 09:58:35 -07006392 break;
Amith Yamasanic33cb712010-02-10 15:21:49 -08006393 default:
6394 return false;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006395 }
Dianne Hackbornf265ea92013-01-31 15:00:51 -08006396 int owningUid;
6397 String owningPackage;
6398 if (win != null) {
6399 owningUid = win.getOwningUid();
6400 owningPackage = win.getOwningPackage();
6401 } else {
6402 owningUid = android.os.Process.myUid();
Dianne Hackborn95d78532013-09-11 09:51:14 -07006403 owningPackage = mContext.getOpPackageName();
Dianne Hackbornf265ea92013-01-31 15:00:51 -08006404 }
Amith Yamasanic33cb712010-02-10 15:21:49 -08006405 if (pattern.length == 1) {
6406 // One-shot vibration
John Spurlock7b414672014-07-18 13:02:39 -04006407 mVibrator.vibrate(owningUid, owningPackage, pattern[0], VIBRATION_ATTRIBUTES);
Amith Yamasanic33cb712010-02-10 15:21:49 -08006408 } else {
6409 // Pattern vibration
John Spurlock7b414672014-07-18 13:02:39 -04006410 mVibrator.vibrate(owningUid, owningPackage, pattern, -1, VIBRATION_ATTRIBUTES);
Amith Yamasanic33cb712010-02-10 15:21:49 -08006411 }
6412 return true;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006413 }
Jeff Brownc38c9be2012-10-04 13:16:19 -07006414
6415 @Override
6416 public void keepScreenOnStartedLw() {
Daniel Sandler0601eb72011-04-13 01:01:32 -04006417 }
6418
Jeff Brownc38c9be2012-10-04 13:16:19 -07006419 @Override
6420 public void keepScreenOnStoppedLw() {
Jim Millerab954542014-10-10 18:21:49 -07006421 if (isKeyguardShowingAndNotOccluded()) {
Jim Miller25190572013-02-28 17:36:24 -08006422 mPowerManager.userActivity(SystemClock.uptimeMillis(), false);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006423 }
6424 }
Mike Lockwoodfcb39242009-10-21 23:01:07 -04006425
Dianne Hackborndf89e652011-10-06 22:35:11 -07006426 private int updateSystemUiVisibilityLw() {
Joe Onorato664644d2011-01-23 17:53:23 -08006427 // If there is no window focused, there will be nobody to handle the events
6428 // anyway, so just hang on in whatever state we're in until things settle down.
Adrian Roos53f28ec2014-10-29 17:26:12 +01006429 final WindowState win = mFocusedWindow != null ? mFocusedWindow
6430 : mTopFullscreenOpaqueWindowState;
John Spurlock79da8332013-09-20 12:04:47 -04006431 if (win == null) {
Dianne Hackborndf89e652011-10-06 22:35:11 -07006432 return 0;
6433 }
Jorim Jaggi380ecb82014-03-14 17:25:20 +01006434 if ((win.getAttrs().privateFlags & PRIVATE_FLAG_KEYGUARD) != 0 && mHideLockScreen == true) {
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07006435 // We are updating at a point where the keyguard has gotten
6436 // focus, but we were last in a state where the top window is
6437 // hiding it. This is probably because the keyguard as been
6438 // shown while the top window was displayed, so we want to ignore
6439 // it here because this is just a very transient change and it
6440 // will quickly lose focus once it correctly gets hidden.
6441 return 0;
6442 }
John Spurlock32beb2c2013-03-11 10:16:47 -04006443
John Spurlock1db8b682014-02-18 11:18:59 -05006444 int tmpVisibility = PolicyControl.getSystemUiVisibility(win, null)
Dianne Hackborne26ab702011-10-16 13:21:33 -07006445 & ~mResettingSystemUiFlags
6446 & ~mForceClearedSystemUiFlags;
John Spurlock79da8332013-09-20 12:04:47 -04006447 if (mForcingShowNavBar && win.getSurfaceLayer() < mForcingShowNavBarLayer) {
John Spurlockc6d1c602014-01-17 15:22:06 -05006448 tmpVisibility &= ~PolicyControl.adjustClearableFlags(win, View.SYSTEM_UI_CLEARABLE_FLAGS);
Dianne Hackborn891d3fb2013-01-09 18:31:37 -08006449 }
Adrian Rooscd3884d2015-02-18 17:25:23 +01006450 tmpVisibility = updateLightStatusBarLw(tmpVisibility);
John Spurlock79da8332013-09-20 12:04:47 -04006451 final int visibility = updateSystemBarsLw(win, mLastSystemUiFlags, tmpVisibility);
John Spurlockad3e6cb2013-04-30 08:47:43 -04006452 final int diff = visibility ^ mLastSystemUiFlags;
John Spurlock79da8332013-09-20 12:04:47 -04006453 final boolean needsMenu = win.getNeedsMenuLw(mTopFullscreenOpaqueWindowState);
Dianne Hackborne0f085d2011-11-30 18:41:15 -08006454 if (diff == 0 && mLastFocusNeedsMenu == needsMenu
John Spurlock79da8332013-09-20 12:04:47 -04006455 && mFocusedApp == win.getAppToken()) {
Dianne Hackborndf89e652011-10-06 22:35:11 -07006456 return 0;
6457 }
Dianne Hackborne26ab702011-10-16 13:21:33 -07006458 mLastSystemUiFlags = visibility;
Dianne Hackborn4eff8d32011-11-10 19:38:40 -08006459 mLastFocusNeedsMenu = needsMenu;
John Spurlock79da8332013-09-20 12:04:47 -04006460 mFocusedApp = win.getAppToken();
Dianne Hackborndf89e652011-10-06 22:35:11 -07006461 mHandler.post(new Runnable() {
Craig Mautnereda67292013-04-28 13:50:14 -07006462 @Override
Dianne Hackborndf89e652011-10-06 22:35:11 -07006463 public void run() {
Dianne Hackborn42e620c2012-06-24 13:20:51 -07006464 try {
6465 IStatusBarService statusbar = getStatusBarService();
6466 if (statusbar != null) {
Adrian Roos53f28ec2014-10-29 17:26:12 +01006467 statusbar.setSystemUiVisibility(visibility, 0xffffffff, win.toString());
Dianne Hackborn42e620c2012-06-24 13:20:51 -07006468 statusbar.topAppWindowChanged(needsMenu);
Joe Onorato664644d2011-01-23 17:53:23 -08006469 }
Dianne Hackborn42e620c2012-06-24 13:20:51 -07006470 } catch (RemoteException e) {
6471 // re-acquire status bar service next time it is needed.
6472 mStatusBarService = null;
Joe Onorato664644d2011-01-23 17:53:23 -08006473 }
Dianne Hackborndf89e652011-10-06 22:35:11 -07006474 }
6475 });
6476 return diff;
Joe Onorato664644d2011-01-23 17:53:23 -08006477 }
6478
Adrian Rooscd3884d2015-02-18 17:25:23 +01006479 private int updateLightStatusBarLw(int vis) {
6480 WindowState statusColorWin = isStatusBarKeyguard() && !mHideLockScreen
6481 ? mStatusBar
6482 : mTopFullscreenOpaqueOrDimmingWindowState;
6483
6484 if (statusColorWin != null) {
6485 if (statusColorWin == mTopFullscreenOpaqueWindowState) {
6486 // If the top fullscreen-or-dimming window is also the top fullscreen, respect
6487 // its light flag.
6488 vis &= ~View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR;
6489 vis |= PolicyControl.getSystemUiVisibility(statusColorWin, null)
6490 & View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR;
6491 } else if (statusColorWin != null && statusColorWin.isDimming()) {
6492 // Otherwise if it's dimming, clear the light flag.
6493 vis &= ~View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR;
6494 }
6495 }
6496 return vis;
6497 }
6498
John Spurlock79da8332013-09-20 12:04:47 -04006499 private int updateSystemBarsLw(WindowState win, int oldVis, int vis) {
John Spurlockbd957402013-10-03 11:38:39 -04006500 // apply translucent bar vis flags
Jorim Jaggi380ecb82014-03-14 17:25:20 +01006501 WindowState transWin = isStatusBarKeyguard() && !mHideLockScreen
6502 ? mStatusBar
John Spurlockbd957402013-10-03 11:38:39 -04006503 : mTopFullscreenOpaqueWindowState;
6504 vis = mStatusBarController.applyTranslucentFlagLw(transWin, vis, oldVis);
6505 vis = mNavigationBarController.applyTranslucentFlagLw(transWin, vis, oldVis);
6506
John Spurlock27735a42013-08-14 17:57:38 -04006507 // prevent status bar interaction from clearing certain flags
Selim Cinekf83e8242015-05-19 18:08:14 -07006508 int type = win.getAttrs().type;
6509 boolean statusBarHasFocus = type == TYPE_STATUS_BAR;
John Spurlock08ffcf52014-07-11 10:13:46 -04006510 if (statusBarHasFocus && !isStatusBarKeyguard()) {
John Spurlockad3e6cb2013-04-30 08:47:43 -04006511 int flags = View.SYSTEM_UI_FLAG_FULLSCREEN
6512 | View.SYSTEM_UI_FLAG_HIDE_NAVIGATION
John Spurlockcfc359a2013-09-05 10:42:03 -04006513 | View.SYSTEM_UI_FLAG_IMMERSIVE
Jorim Jaggi73fef8d2015-02-16 17:32:28 +01006514 | View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY
6515 | View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR;
John Spurlock08ffcf52014-07-11 10:13:46 -04006516 if (mHideLockScreen) {
Jorim Jaggi5cf17872014-03-26 18:31:48 +01006517 flags |= View.STATUS_BAR_TRANSLUCENT | View.NAVIGATION_BAR_TRANSLUCENT;
6518 }
John Spurlockbd957402013-10-03 11:38:39 -04006519 vis = (vis & ~flags) | (oldVis & flags);
John Spurlockad3e6cb2013-04-30 08:47:43 -04006520 }
John Spurlockad3e6cb2013-04-30 08:47:43 -04006521
Adrian Roos4fb3ee32014-08-22 19:29:09 +02006522 if (!areTranslucentBarsAllowed() && transWin != mStatusBar) {
Adrian Roosea562512014-05-05 13:33:03 +02006523 vis &= ~(View.NAVIGATION_BAR_TRANSLUCENT | View.STATUS_BAR_TRANSLUCENT
6524 | View.SYSTEM_UI_TRANSPARENT);
Alan Viverette5a0f4ec2013-10-07 15:10:29 -07006525 }
6526
John Spurlock27735a42013-08-14 17:57:38 -04006527 // update status bar
John Spurlockf1a36642013-10-12 17:50:42 -04006528 boolean immersiveSticky =
6529 (vis & View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY) != 0;
John Spurlock27735a42013-08-14 17:57:38 -04006530 boolean hideStatusBarWM =
John Spurlockbd957402013-10-03 11:38:39 -04006531 mTopFullscreenOpaqueWindowState != null &&
John Spurlockc6d1c602014-01-17 15:22:06 -05006532 (PolicyControl.getWindowFlags(mTopFullscreenOpaqueWindowState, null)
John Spurlock27735a42013-08-14 17:57:38 -04006533 & WindowManager.LayoutParams.FLAG_FULLSCREEN) != 0;
6534 boolean hideStatusBarSysui =
6535 (vis & View.SYSTEM_UI_FLAG_FULLSCREEN) != 0;
John Spurlockf1a36642013-10-12 17:50:42 -04006536 boolean hideNavBarSysui =
6537 (vis & View.SYSTEM_UI_FLAG_HIDE_NAVIGATION) != 0;
John Spurlockad3e6cb2013-04-30 08:47:43 -04006538
John Spurlock27735a42013-08-14 17:57:38 -04006539 boolean transientStatusBarAllowed =
6540 mStatusBar != null && (
6541 hideStatusBarWM
John Spurlockf1a36642013-10-12 17:50:42 -04006542 || (hideStatusBarSysui && immersiveSticky)
John Spurlock27735a42013-08-14 17:57:38 -04006543 || statusBarHasFocus);
6544
John Spurlockf1a36642013-10-12 17:50:42 -04006545 boolean transientNavBarAllowed =
6546 mNavigationBar != null &&
6547 hideNavBarSysui && immersiveSticky;
6548
Adrian Roosddc8b272015-05-21 16:28:27 -07006549 final long now = SystemClock.uptimeMillis();
6550 final boolean pendingPanic = mPendingPanicGestureUptime != 0
6551 && now - mPendingPanicGestureUptime <= PANIC_GESTURE_EXPIRATION;
6552 if (pendingPanic && hideNavBarSysui && !isStatusBarKeyguard() && mKeyguardDrawComplete) {
6553 // The user performed the panic gesture recently, we're about to hide the bars,
6554 // we're no longer on the Keyguard and the screen is ready. We can now request the bars.
6555 mPendingPanicGestureUptime = 0;
6556 mStatusBarController.showTransient();
6557 mNavigationBarController.showTransient();
6558 }
6559
John Spurlockf25706f2013-11-07 18:02:43 -05006560 boolean denyTransientStatus = mStatusBarController.isTransientShowRequested()
John Spurlockf1a36642013-10-12 17:50:42 -04006561 && !transientStatusBarAllowed && hideStatusBarSysui;
John Spurlockf25706f2013-11-07 18:02:43 -05006562 boolean denyTransientNav = mNavigationBarController.isTransientShowRequested()
John Spurlockf1a36642013-10-12 17:50:42 -04006563 && !transientNavBarAllowed;
6564 if (denyTransientStatus || denyTransientNav) {
John Spurlock27735a42013-08-14 17:57:38 -04006565 // clear the clearable flags instead
John Spurlockf1a36642013-10-12 17:50:42 -04006566 clearClearableFlagsLw();
tiger_huangc58d7562014-10-23 20:24:19 +08006567 vis &= ~View.SYSTEM_UI_CLEARABLE_FLAGS;
John Spurlockad3e6cb2013-04-30 08:47:43 -04006568 }
John Spurlock27735a42013-08-14 17:57:38 -04006569
Selim Cinekf98702e2015-05-20 22:48:40 -07006570 final boolean immersive = (vis & View.SYSTEM_UI_FLAG_IMMERSIVE) != 0;
6571 immersiveSticky = (vis & View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY) != 0;
6572 final boolean navAllowedHidden = immersive || immersiveSticky;
6573
Selim Cinekd6623612015-05-22 18:56:22 -07006574 if (hideNavBarSysui && !navAllowedHidden && windowTypeToLayerLw(win.getBaseType())
6575 > windowTypeToLayerLw(TYPE_INPUT_CONSUMER)) {
Selim Cinekf98702e2015-05-20 22:48:40 -07006576 // We can't hide the navbar from this window otherwise the input consumer would not get
6577 // the input events.
6578 vis = (vis & ~View.SYSTEM_UI_FLAG_HIDE_NAVIGATION);
6579 }
6580
John Spurlock27735a42013-08-14 17:57:38 -04006581 vis = mStatusBarController.updateVisibilityLw(transientStatusBarAllowed, oldVis, vis);
6582
6583 // update navigation bar
John Spurlockf1a36642013-10-12 17:50:42 -04006584 boolean oldImmersiveMode = isImmersiveMode(oldVis);
6585 boolean newImmersiveMode = isImmersiveMode(vis);
6586 if (win != null && oldImmersiveMode != newImmersiveMode) {
John Spurlock79da8332013-09-20 12:04:47 -04006587 final String pkg = win.getOwningPackage();
Maurice Lam99c6e072014-04-28 18:24:28 -07006588 mImmersiveModeConfirmation.immersiveModeChanged(pkg, newImmersiveMode,
6589 isUserSetupComplete());
John Spurlock34e13d92013-08-10 06:52:28 -04006590 }
John Spurlock27735a42013-08-14 17:57:38 -04006591
John Spurlockf1a36642013-10-12 17:50:42 -04006592 vis = mNavigationBarController.updateVisibilityLw(transientNavBarAllowed, oldVis, vis);
6593
John Spurlocke1f366f2013-08-05 12:22:40 -04006594 return vis;
John Spurlockad3e6cb2013-04-30 08:47:43 -04006595 }
6596
John Spurlockf1a36642013-10-12 17:50:42 -04006597 private void clearClearableFlagsLw() {
6598 int newVal = mResettingSystemUiFlags | View.SYSTEM_UI_CLEARABLE_FLAGS;
6599 if (newVal != mResettingSystemUiFlags) {
6600 mResettingSystemUiFlags = newVal;
6601 mWindowManagerFuncs.reevaluateStatusBarVisibility();
6602 }
6603 }
6604
6605 private boolean isImmersiveMode(int vis) {
6606 final int flags = View.SYSTEM_UI_FLAG_IMMERSIVE | View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY;
John Spurlock34e13d92013-08-10 06:52:28 -04006607 return mNavigationBar != null
6608 && (vis & View.SYSTEM_UI_FLAG_HIDE_NAVIGATION) != 0
Daniel Sandler900ece52013-10-18 15:53:27 -04006609 && (vis & flags) != 0
6610 && canHideNavigationBar();
John Spurlock34e13d92013-08-10 06:52:28 -04006611 }
6612
Alan Viverette5a0f4ec2013-10-07 15:10:29 -07006613 /**
Daniel Sandlerdd73ee42013-10-11 22:19:59 -04006614 * @return whether the navigation or status bar can be made translucent
6615 *
6616 * This should return true unless touch exploration is not enabled or
6617 * R.boolean.config_enableTranslucentDecor is false.
Alan Viverette5a0f4ec2013-10-07 15:10:29 -07006618 */
Daniel Sandlerdd73ee42013-10-11 22:19:59 -04006619 private boolean areTranslucentBarsAllowed() {
Svetoslav8e3feb12014-02-24 13:46:47 -08006620 return mTranslucentDecorEnabled
6621 && !mAccessibilityManager.isTouchExplorationEnabled();
Alan Viverette5a0f4ec2013-10-07 15:10:29 -07006622 }
6623
Daniel Sandler0c4ccff2011-10-19 16:39:14 -04006624 // Use this instead of checking config_showNavigationBar so that it can be consistently
6625 // overridden by qemu.hw.mainkeys in the emulator.
Craig Mautnereda67292013-04-28 13:50:14 -07006626 @Override
Daniel Sandler0c4ccff2011-10-19 16:39:14 -04006627 public boolean hasNavigationBar() {
6628 return mHasNavigationBar;
6629 }
6630
satok1bc0a492012-04-25 22:47:12 +09006631 @Override
6632 public void setLastInputMethodWindowLw(WindowState ime, WindowState target) {
6633 mLastInputMethodWindow = ime;
6634 mLastInputMethodTargetWindow = target;
6635 }
6636
Craig Mautnerf1b67412012-09-19 13:18:29 -07006637 @Override
Satoshi Kataoka658c7b82013-10-10 17:03:51 +09006638 public int getInputMethodWindowVisibleHeightLw() {
6639 return mDockBottom - mCurBottom;
6640 }
6641
6642 @Override
Craig Mautnerf1b67412012-09-19 13:18:29 -07006643 public void setCurrentUserLw(int newUserId) {
Craig Mautnerd625ab22013-09-06 13:40:31 -07006644 mCurrentUserId = newUserId;
Jim Miller5ecd8112013-01-09 18:50:26 -08006645 if (mKeyguardDelegate != null) {
6646 mKeyguardDelegate.setCurrentUser(newUserId);
Craig Mautnerf1b67412012-09-19 13:18:29 -07006647 }
John Spurlock13451a22012-09-28 14:40:41 -04006648 if (mStatusBarService != null) {
6649 try {
6650 mStatusBarService.setCurrentUser(newUserId);
6651 } catch (RemoteException e) {
6652 // oh well
6653 }
6654 }
Dianne Hackborn2ea9bae2012-11-02 18:43:48 -07006655 setLastInputMethodWindowLw(null, null);
Craig Mautnerf1b67412012-09-19 13:18:29 -07006656 }
6657
6658 @Override
Svetoslav Ganov545252f2012-12-10 18:29:24 -08006659 public boolean canMagnifyWindow(int windowType) {
6660 switch (windowType) {
6661 case WindowManager.LayoutParams.TYPE_INPUT_METHOD:
6662 case WindowManager.LayoutParams.TYPE_INPUT_METHOD_DIALOG:
6663 case WindowManager.LayoutParams.TYPE_NAVIGATION_BAR:
6664 case WindowManager.LayoutParams.TYPE_MAGNIFICATION_OVERLAY: {
6665 return false;
6666 }
6667 }
6668 return true;
6669 }
6670
6671 @Override
6672 public boolean isTopLevelWindow(int windowType) {
6673 if (windowType >= WindowManager.LayoutParams.FIRST_SUB_WINDOW
6674 && windowType <= WindowManager.LayoutParams.LAST_SUB_WINDOW) {
6675 return (windowType == WindowManager.LayoutParams.TYPE_APPLICATION_ATTACHED_DIALOG);
6676 }
6677 return true;
6678 }
6679
Jim Miller4eeb4f62012-11-08 00:04:29 -08006680 @Override
Jeff Brownd7a04de2012-06-17 14:17:52 -07006681 public void dump(String prefix, PrintWriter pw, String[] args) {
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08006682 pw.print(prefix); pw.print("mSafeMode="); pw.print(mSafeMode);
Dianne Hackbornba24e4d2011-09-01 11:17:06 -07006683 pw.print(" mSystemReady="); pw.print(mSystemReady);
6684 pw.print(" mSystemBooted="); pw.println(mSystemBooted);
Jeff Brown2e7760e2012-04-11 15:14:55 -07006685 pw.print(prefix); pw.print("mLidState="); pw.print(mLidState);
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08006686 pw.print(" mLidOpenRotation="); pw.print(mLidOpenRotation);
Michael Wright3818c922014-09-02 13:59:07 -07006687 pw.print(" mCameraLensCoverState="); pw.print(mCameraLensCoverState);
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08006688 pw.print(" mHdmiPlugged="); pw.println(mHdmiPlugged);
Dianne Hackborne26ab702011-10-16 13:21:33 -07006689 if (mLastSystemUiFlags != 0 || mResettingSystemUiFlags != 0
6690 || mForceClearedSystemUiFlags != 0) {
6691 pw.print(prefix); pw.print("mLastSystemUiFlags=0x");
6692 pw.print(Integer.toHexString(mLastSystemUiFlags));
6693 pw.print(" mResettingSystemUiFlags=0x");
6694 pw.print(Integer.toHexString(mResettingSystemUiFlags));
6695 pw.print(" mForceClearedSystemUiFlags=0x");
6696 pw.println(Integer.toHexString(mForceClearedSystemUiFlags));
Dianne Hackborndf89e652011-10-06 22:35:11 -07006697 }
Dianne Hackborn4eff8d32011-11-10 19:38:40 -08006698 if (mLastFocusNeedsMenu) {
6699 pw.print(prefix); pw.print("mLastFocusNeedsMenu=");
6700 pw.println(mLastFocusNeedsMenu);
6701 }
Jeff Browna20dda42014-05-27 20:57:24 -07006702 pw.print(prefix); pw.print("mWakeGestureEnabledSetting=");
6703 pw.println(mWakeGestureEnabledSetting);
6704
Jeff Brownbcdfc622014-03-06 19:13:04 -08006705 pw.print(prefix); pw.print("mSupportAutoRotation="); pw.println(mSupportAutoRotation);
Daniel Sandler6396c722013-04-16 20:19:09 -04006706 pw.print(prefix); pw.print("mUiMode="); pw.print(mUiMode);
6707 pw.print(" mDockMode="); pw.print(mDockMode);
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08006708 pw.print(" mCarDockRotation="); pw.print(mCarDockRotation);
6709 pw.print(" mDeskDockRotation="); pw.println(mDeskDockRotation);
6710 pw.print(prefix); pw.print("mUserRotationMode="); pw.print(mUserRotationMode);
6711 pw.print(" mUserRotation="); pw.print(mUserRotation);
Daniel Sandler2ed6ad62011-02-22 14:54:17 -05006712 pw.print(" mAllowAllRotations="); pw.println(mAllowAllRotations);
Dianne Hackborn6e2281d2012-06-19 17:48:32 -07006713 pw.print(prefix); pw.print("mCurrentAppOrientation="); pw.println(mCurrentAppOrientation);
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08006714 pw.print(prefix); pw.print("mCarDockEnablesAccelerometer=");
6715 pw.print(mCarDockEnablesAccelerometer);
6716 pw.print(" mDeskDockEnablesAccelerometer=");
6717 pw.println(mDeskDockEnablesAccelerometer);
6718 pw.print(prefix); pw.print("mLidKeyboardAccessibility=");
6719 pw.print(mLidKeyboardAccessibility);
6720 pw.print(" mLidNavigationAccessibility="); pw.print(mLidNavigationAccessibility);
Dianne Hackborn6e2281d2012-06-19 17:48:32 -07006721 pw.print(" mLidControlsSleep="); pw.println(mLidControlsSleep);
Jeff Brown6d8fd272014-05-20 21:24:38 -07006722 pw.print(prefix);
6723 pw.print("mShortPressOnPowerBehavior="); pw.print(mShortPressOnPowerBehavior);
6724 pw.print(" mLongPressOnPowerBehavior="); pw.println(mLongPressOnPowerBehavior);
Jeff Brown13f00f02014-10-31 14:45:50 -07006725 pw.print(prefix);
6726 pw.print("mDoublePressOnPowerBehavior="); pw.print(mDoublePressOnPowerBehavior);
6727 pw.print(" mTriplePressOnPowerBehavior="); pw.println(mTriplePressOnPowerBehavior);
Jeff Brown6d8fd272014-05-20 21:24:38 -07006728 pw.print(prefix); pw.print("mHasSoftInput="); pw.println(mHasSoftInput);
Jeff Brown3ee549c2014-09-22 20:14:39 -07006729 pw.print(prefix); pw.print("mAwake="); pw.println(mAwake);
6730 pw.print(prefix); pw.print("mScreenOnEarly="); pw.print(mScreenOnEarly);
6731 pw.print(" mScreenOnFully="); pw.println(mScreenOnFully);
6732 pw.print(prefix); pw.print("mKeyguardDrawComplete="); pw.print(mKeyguardDrawComplete);
6733 pw.print(" mWindowManagerDrawComplete="); pw.println(mWindowManagerDrawComplete);
6734 pw.print(prefix); pw.print("mOrientationSensorEnabled=");
6735 pw.println(mOrientationSensorEnabled);
Dianne Hackbornc652de82013-02-15 16:32:56 -08006736 pw.print(prefix); pw.print("mOverscanScreen=("); pw.print(mOverscanScreenLeft);
6737 pw.print(","); pw.print(mOverscanScreenTop);
6738 pw.print(") "); pw.print(mOverscanScreenWidth);
6739 pw.print("x"); pw.println(mOverscanScreenHeight);
6740 if (mOverscanLeft != 0 || mOverscanTop != 0
6741 || mOverscanRight != 0 || mOverscanBottom != 0) {
6742 pw.print(prefix); pw.print("mOverscan left="); pw.print(mOverscanLeft);
6743 pw.print(" top="); pw.print(mOverscanTop);
6744 pw.print(" right="); pw.print(mOverscanRight);
6745 pw.print(" bottom="); pw.println(mOverscanBottom);
6746 }
Dianne Hackborn313440842013-02-19 19:22:59 -08006747 pw.print(prefix); pw.print("mRestrictedOverscanScreen=(");
6748 pw.print(mRestrictedOverscanScreenLeft);
6749 pw.print(","); pw.print(mRestrictedOverscanScreenTop);
6750 pw.print(") "); pw.print(mRestrictedOverscanScreenWidth);
6751 pw.print("x"); pw.println(mRestrictedOverscanScreenHeight);
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08006752 pw.print(prefix); pw.print("mUnrestrictedScreen=("); pw.print(mUnrestrictedScreenLeft);
6753 pw.print(","); pw.print(mUnrestrictedScreenTop);
6754 pw.print(") "); pw.print(mUnrestrictedScreenWidth);
6755 pw.print("x"); pw.println(mUnrestrictedScreenHeight);
6756 pw.print(prefix); pw.print("mRestrictedScreen=("); pw.print(mRestrictedScreenLeft);
6757 pw.print(","); pw.print(mRestrictedScreenTop);
6758 pw.print(") "); pw.print(mRestrictedScreenWidth);
6759 pw.print("x"); pw.println(mRestrictedScreenHeight);
Dianne Hackborn5b5cc4d2012-05-16 13:15:00 -07006760 pw.print(prefix); pw.print("mStableFullscreen=("); pw.print(mStableFullscreenLeft);
6761 pw.print(","); pw.print(mStableFullscreenTop);
6762 pw.print(")-("); pw.print(mStableFullscreenRight);
6763 pw.print(","); pw.print(mStableFullscreenBottom); pw.println(")");
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07006764 pw.print(prefix); pw.print("mStable=("); pw.print(mStableLeft);
6765 pw.print(","); pw.print(mStableTop);
6766 pw.print(")-("); pw.print(mStableRight);
6767 pw.print(","); pw.print(mStableBottom); pw.println(")");
Dianne Hackborn5c58de32012-04-28 19:52:37 -07006768 pw.print(prefix); pw.print("mSystem=("); pw.print(mSystemLeft);
6769 pw.print(","); pw.print(mSystemTop);
6770 pw.print(")-("); pw.print(mSystemRight);
6771 pw.print(","); pw.print(mSystemBottom); pw.println(")");
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08006772 pw.print(prefix); pw.print("mCur=("); pw.print(mCurLeft);
6773 pw.print(","); pw.print(mCurTop);
6774 pw.print(")-("); pw.print(mCurRight);
6775 pw.print(","); pw.print(mCurBottom); pw.println(")");
6776 pw.print(prefix); pw.print("mContent=("); pw.print(mContentLeft);
6777 pw.print(","); pw.print(mContentTop);
6778 pw.print(")-("); pw.print(mContentRight);
6779 pw.print(","); pw.print(mContentBottom); pw.println(")");
Dianne Hackborne30e02f2014-05-27 18:24:45 -07006780 pw.print(prefix); pw.print("mVoiceContent=("); pw.print(mVoiceContentLeft);
6781 pw.print(","); pw.print(mVoiceContentTop);
6782 pw.print(")-("); pw.print(mVoiceContentRight);
6783 pw.print(","); pw.print(mVoiceContentBottom); pw.println(")");
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08006784 pw.print(prefix); pw.print("mDock=("); pw.print(mDockLeft);
6785 pw.print(","); pw.print(mDockTop);
6786 pw.print(")-("); pw.print(mDockRight);
6787 pw.print(","); pw.print(mDockBottom); pw.println(")");
Dianne Hackborn5c58de32012-04-28 19:52:37 -07006788 pw.print(prefix); pw.print("mDockLayer="); pw.print(mDockLayer);
6789 pw.print(" mStatusBarLayer="); pw.println(mStatusBarLayer);
Dianne Hackborn7ad44382012-10-18 17:46:00 -07006790 pw.print(prefix); pw.print("mShowingLockscreen="); pw.print(mShowingLockscreen);
6791 pw.print(" mShowingDream="); pw.print(mShowingDream);
Jeff Brown061ea992015-04-17 19:55:47 -07006792 pw.print(" mDreamingLockscreen="); pw.print(mDreamingLockscreen);
6793 pw.print(" mDreamingSleepToken="); pw.println(mDreamingSleepToken);
Dianne Hackborn2ea9bae2012-11-02 18:43:48 -07006794 if (mLastInputMethodWindow != null) {
6795 pw.print(prefix); pw.print("mLastInputMethodWindow=");
6796 pw.println(mLastInputMethodWindow);
6797 }
6798 if (mLastInputMethodTargetWindow != null) {
6799 pw.print(prefix); pw.print("mLastInputMethodTargetWindow=");
6800 pw.println(mLastInputMethodTargetWindow);
6801 }
6802 if (mStatusBar != null) {
6803 pw.print(prefix); pw.print("mStatusBar=");
Dianne Hackbornae6688b2015-02-11 17:02:41 -08006804 pw.print(mStatusBar); pw.print(" isStatusBarKeyguard=");
6805 pw.println(isStatusBarKeyguard());
Dianne Hackborn2ea9bae2012-11-02 18:43:48 -07006806 }
6807 if (mNavigationBar != null) {
6808 pw.print(prefix); pw.print("mNavigationBar=");
6809 pw.println(mNavigationBar);
6810 }
Dianne Hackborn2ea9bae2012-11-02 18:43:48 -07006811 if (mFocusedWindow != null) {
6812 pw.print(prefix); pw.print("mFocusedWindow=");
6813 pw.println(mFocusedWindow);
6814 }
6815 if (mFocusedApp != null) {
6816 pw.print(prefix); pw.print("mFocusedApp=");
6817 pw.println(mFocusedApp);
6818 }
6819 if (mWinDismissingKeyguard != null) {
6820 pw.print(prefix); pw.print("mWinDismissingKeyguard=");
6821 pw.println(mWinDismissingKeyguard);
6822 }
6823 if (mTopFullscreenOpaqueWindowState != null) {
6824 pw.print(prefix); pw.print("mTopFullscreenOpaqueWindowState=");
6825 pw.println(mTopFullscreenOpaqueWindowState);
6826 }
Adrian Rooscd3884d2015-02-18 17:25:23 +01006827 if (mTopFullscreenOpaqueOrDimmingWindowState != null) {
6828 pw.print(prefix); pw.print("mTopFullscreenOpaqueOrDimmingWindowState=");
6829 pw.println(mTopFullscreenOpaqueOrDimmingWindowState);
6830 }
Dianne Hackborn891d3fb2013-01-09 18:31:37 -08006831 if (mForcingShowNavBar) {
6832 pw.print(prefix); pw.print("mForcingShowNavBar=");
6833 pw.println(mForcingShowNavBar); pw.print( "mForcingShowNavBarLayer=");
6834 pw.println(mForcingShowNavBarLayer);
6835 }
Dianne Hackborn7ad44382012-10-18 17:46:00 -07006836 pw.print(prefix); pw.print("mTopIsFullscreen="); pw.print(mTopIsFullscreen);
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08006837 pw.print(" mHideLockScreen="); pw.println(mHideLockScreen);
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07006838 pw.print(prefix); pw.print("mForceStatusBar="); pw.print(mForceStatusBar);
6839 pw.print(" mForceStatusBarFromKeyguard=");
6840 pw.println(mForceStatusBarFromKeyguard);
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08006841 pw.print(prefix); pw.print("mDismissKeyguard="); pw.print(mDismissKeyguard);
Craig Mautnerad09bcc2012-10-08 13:33:11 -07006842 pw.print(" mWinDismissingKeyguard="); pw.print(mWinDismissingKeyguard);
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08006843 pw.print(" mHomePressed="); pw.println(mHomePressed);
6844 pw.print(prefix); pw.print("mAllowLockscreenWhenOn="); pw.print(mAllowLockscreenWhenOn);
6845 pw.print(" mLockScreenTimeout="); pw.print(mLockScreenTimeout);
6846 pw.print(" mLockScreenTimerActive="); pw.println(mLockScreenTimerActive);
6847 pw.print(prefix); pw.print("mEndcallBehavior="); pw.print(mEndcallBehavior);
6848 pw.print(" mIncallPowerBehavior="); pw.print(mIncallPowerBehavior);
6849 pw.print(" mLongPressOnHomeBehavior="); pw.println(mLongPressOnHomeBehavior);
6850 pw.print(prefix); pw.print("mLandscapeRotation="); pw.print(mLandscapeRotation);
6851 pw.print(" mSeascapeRotation="); pw.println(mSeascapeRotation);
6852 pw.print(prefix); pw.print("mPortraitRotation="); pw.print(mPortraitRotation);
6853 pw.print(" mUpsideDownRotation="); pw.println(mUpsideDownRotation);
Jeff Brownc82c89ed2013-04-17 17:18:15 -07006854 pw.print(prefix); pw.print("mDemoHdmiRotation="); pw.print(mDemoHdmiRotation);
6855 pw.print(" mDemoHdmiRotationLock="); pw.println(mDemoHdmiRotationLock);
6856 pw.print(prefix); pw.print("mUndockedHdmiRotation="); pw.println(mUndockedHdmiRotation);
Jeff Brown600f0032014-05-22 17:06:00 -07006857
Tim Kilbournd7c0c2e2014-05-29 16:08:10 -07006858 mGlobalKeyManager.dump(prefix, pw);
John Spurlock27735a42013-08-14 17:57:38 -04006859 mStatusBarController.dump(pw, prefix);
6860 mNavigationBarController.dump(pw, prefix);
John Spurlockc6d1c602014-01-17 15:22:06 -05006861 PolicyControl.dump(prefix, pw);
Jeff Brown600f0032014-05-22 17:06:00 -07006862
Jeff Browna20dda42014-05-27 20:57:24 -07006863 if (mWakeGestureListener != null) {
6864 mWakeGestureListener.dump(pw, prefix);
6865 }
Jeff Brown600f0032014-05-22 17:06:00 -07006866 if (mOrientationListener != null) {
6867 mOrientationListener.dump(pw, prefix);
6868 }
Filip Gruszczynskicfb31852015-02-25 21:47:12 +00006869 if (mBurnInProtectionHelper != null) {
6870 mBurnInProtectionHelper.dump(prefix, pw);
6871 }
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08006872 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006873}