blob: 234c4b2ae7ae34bc5e0576b85b4694b3ae792663 [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;
Adam Powell6711f3b2015-05-06 15:57:09 -070098import com.android.internal.policy.PhoneWindow;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -080099import android.view.Surface;
100import android.view.View;
101import android.view.ViewConfiguration;
102import android.view.Window;
103import android.view.WindowManager;
Craig Mautnerae446592012-12-06 19:05:05 -0800104import android.view.WindowManagerGlobal;
Craig Mautner8a0da012014-05-31 15:13:37 -0700105import android.view.WindowManagerInternal;
Craig Mautnerae446592012-12-06 19:05:05 -0800106import android.view.WindowManagerPolicy;
Craig Mautnerae446592012-12-06 19:05:05 -0800107import android.view.accessibility.AccessibilityEvent;
Svetoslav8e3feb12014-02-24 13:46:47 -0800108import android.view.accessibility.AccessibilityManager;
Craig Mautnerae446592012-12-06 19:05:05 -0800109import android.view.animation.Animation;
Jorim Jaggi76a16232014-08-08 17:00:47 +0200110import android.view.animation.AnimationSet;
Craig Mautnerae446592012-12-06 19:05:05 -0800111import android.view.animation.AnimationUtils;
Craig Mautnerae446592012-12-06 19:05:05 -0800112import com.android.internal.R;
Craig Mautnerae446592012-12-06 19:05:05 -0800113import com.android.internal.statusbar.IStatusBarService;
Filip Gruszczynski2217f612015-05-26 11:32:08 -0700114import com.android.internal.util.ScreenShapeHelper;
Craig Mautnerae446592012-12-06 19:05:05 -0800115import com.android.internal.widget.PointerLocationView;
Craig Mautner8a0da012014-05-31 15:13:37 -0700116import com.android.server.LocalServices;
Jorim Jaggib10e33f2015-02-04 21:57:40 +0100117import com.android.server.policy.keyguard.KeyguardServiceDelegate;
118import com.android.server.policy.keyguard.KeyguardServiceDelegate.ShowListener;
Craig Mautnerae446592012-12-06 19:05:05 -0800119
120import java.io.File;
121import java.io.FileReader;
122import java.io.IOException;
123import java.io.PrintWriter;
Craig Mautner2bc789b2014-03-19 19:48:38 -0700124import java.util.HashSet;
Craig Mautner276a6eb2014-11-04 15:32:57 -0800125import java.util.List;
Craig Mautnerae446592012-12-06 19:05:05 -0800126
Dianne Hackbornc652de82013-02-15 16:32:56 -0800127import static android.view.WindowManager.LayoutParams.*;
Jeff Brownac143512012-04-05 18:57:33 -0700128import static android.view.WindowManagerPolicy.WindowManagerFuncs.LID_ABSENT;
129import static android.view.WindowManagerPolicy.WindowManagerFuncs.LID_OPEN;
130import static android.view.WindowManagerPolicy.WindowManagerFuncs.LID_CLOSED;
Michael Wright3818c922014-09-02 13:59:07 -0700131import static android.view.WindowManagerPolicy.WindowManagerFuncs.CAMERA_LENS_COVER_ABSENT;
132import static android.view.WindowManagerPolicy.WindowManagerFuncs.CAMERA_LENS_UNCOVERED;
133import static android.view.WindowManagerPolicy.WindowManagerFuncs.CAMERA_LENS_COVERED;
Dianne Hackborn08743722009-12-21 12:16:51 -0800134
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800135/**
The Android Open Source Project0727d222009-03-11 12:11:58 -0700136 * WindowManagerPolicy implementation for the Android phone UI. This
137 * introduces a new method suffix, Lp, for an internal lock of the
138 * PhoneWindowManager. This is used to protect some internal state, and
John Spurlock04db1762013-05-13 12:46:41 -0400139 * 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 -0700140 * of both of those when held.
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800141 */
142public class PhoneWindowManager implements WindowManagerPolicy {
143 static final String TAG = "WindowManager";
144 static final boolean DEBUG = false;
Joe Onorato43a17652011-04-06 19:22:23 -0700145 static final boolean localLOGV = false;
Jeff Brown40013652012-05-16 21:22:36 -0700146 static final boolean DEBUG_INPUT = false;
Craig Mautnerc0d2d0a2014-10-31 16:25:15 -0700147 static final boolean DEBUG_KEYGUARD = false;
148 static final boolean DEBUG_LAYOUT = false;
Craig Mautner6fbda632012-07-03 09:26:39 -0700149 static final boolean DEBUG_STARTING_WINDOW = false;
Craig Mautner8a0da012014-05-31 15:13:37 -0700150 static final boolean DEBUG_WAKEUP = false;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800151 static final boolean SHOW_STARTING_ANIMATIONS = true;
152 static final boolean SHOW_PROCESSES_ON_ALT_MENU = false;
Joe Onoratod208e702010-10-08 16:22:43 -0400153
Daniel Sandler6396c722013-04-16 20:19:09 -0400154 // Whether to allow dock apps with METADATA_DOCK_HOME to temporarily take over the Home key.
155 // No longer recommended for desk docks; still useful in car docks.
156 static final boolean ENABLE_CAR_DOCK_HOME_CAPTURE = true;
157 static final boolean ENABLE_DESK_DOCK_HOME_CAPTURE = false;
158
Jeff Brown6d8fd272014-05-20 21:24:38 -0700159 static final int SHORT_PRESS_POWER_NOTHING = 0;
160 static final int SHORT_PRESS_POWER_GO_TO_SLEEP = 1;
161 static final int SHORT_PRESS_POWER_REALLY_GO_TO_SLEEP = 2;
162 static final int SHORT_PRESS_POWER_REALLY_GO_TO_SLEEP_AND_GO_HOME = 3;
Bryce Lee01b0c5f2015-02-05 18:24:04 -0800163 static final int SHORT_PRESS_POWER_GO_HOME = 4;
Jeff Brown6d8fd272014-05-20 21:24:38 -0700164
Joe Onoratod208e702010-10-08 16:22:43 -0400165 static final int LONG_PRESS_POWER_NOTHING = 0;
166 static final int LONG_PRESS_POWER_GLOBAL_ACTIONS = 1;
167 static final int LONG_PRESS_POWER_SHUT_OFF = 2;
Jeff Brown9a538ee2012-08-20 14:56:57 -0700168 static final int LONG_PRESS_POWER_SHUT_OFF_NO_CONFIRM = 3;
Michael Jurka3b1fc472011-06-13 10:54:40 -0700169
Jeff Brown13f00f02014-10-31 14:45:50 -0700170 static final int MULTI_PRESS_POWER_NOTHING = 0;
171 static final int MULTI_PRESS_POWER_THEATER_MODE = 1;
172 static final int MULTI_PRESS_POWER_BRIGHTNESS_BOOST = 2;
173
Michael Jurka3b1fc472011-06-13 10:54:40 -0700174 // These need to match the documentation/constant in
175 // core/res/res/values/config.xml
Joe Onorato46b0d682010-11-22 17:37:27 -0800176 static final int LONG_PRESS_HOME_NOTHING = 0;
Michael Wrightc9ebea72013-01-16 19:25:02 -0800177 static final int LONG_PRESS_HOME_RECENT_SYSTEM_UI = 1;
Jeff Browncaca8812013-05-09 13:34:33 -0700178 static final int LONG_PRESS_HOME_ASSIST = 2;
179
180 static final int DOUBLE_TAP_HOME_NOTHING = 0;
181 static final int DOUBLE_TAP_HOME_RECENT_SYSTEM_UI = 1;
Joe Onorato46b0d682010-11-22 17:37:27 -0800182
Filip Gruszczynskia483a1d2015-03-17 19:06:58 +0000183 static final int SHORT_PRESS_SLEEP_GO_TO_SLEEP = 0;
184 static final int SHORT_PRESS_SLEEP_GO_TO_SLEEP_AND_GO_HOME = 1;
185
Dianne Hackborn5cb8d792009-05-21 17:34:15 -0700186 static final int APPLICATION_MEDIA_SUBLAYER = -2;
187 static final int APPLICATION_MEDIA_OVERLAY_SUBLAYER = -1;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800188 static final int APPLICATION_PANEL_SUBLAYER = 1;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800189 static final int APPLICATION_SUB_PANEL_SUBLAYER = 2;
Wale Ogunwale0a4dc222015-04-14 12:58:42 -0700190 static final int APPLICATION_ABOVE_SUB_PANEL_SUBLAYER = 3;
Craig Mautner88400d32012-09-30 12:35:45 -0700191
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800192 static public final String SYSTEM_DIALOG_REASON_KEY = "reason";
193 static public final String SYSTEM_DIALOG_REASON_GLOBAL_ACTIONS = "globalactions";
194 static public final String SYSTEM_DIALOG_REASON_RECENT_APPS = "recentapps";
Joe Onoratof275f0c2009-11-24 16:11:13 -0500195 static public final String SYSTEM_DIALOG_REASON_HOME_KEY = "homekey";
Jeff Brownde7a8ea2012-06-13 18:28:57 -0700196 static public final String SYSTEM_DIALOG_REASON_ASSIST = "assist";
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800197
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -0700198 /**
199 * These are the system UI flags that, when changing, can cause the layout
200 * of the screen to change.
201 */
202 static final int SYSTEM_UI_CHANGING_LAYOUT =
John Spurlocke1f366f2013-08-05 12:22:40 -0400203 View.SYSTEM_UI_FLAG_HIDE_NAVIGATION
John Spurlock7f4820a2013-10-08 12:54:35 -0400204 | View.SYSTEM_UI_FLAG_FULLSCREEN
205 | View.STATUS_BAR_TRANSLUCENT
Adrian Roosea562512014-05-05 13:33:03 +0200206 | View.NAVIGATION_BAR_TRANSLUCENT
207 | View.SYSTEM_UI_TRANSPARENT;
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -0700208
John Spurlock7b414672014-07-18 13:02:39 -0400209 private static final AudioAttributes VIBRATION_ATTRIBUTES = new AudioAttributes.Builder()
210 .setContentType(AudioAttributes.CONTENT_TYPE_SONIFICATION)
211 .setUsage(AudioAttributes.USAGE_ASSISTANCE_SONIFICATION)
212 .build();
213
Adrian Roosddc8b272015-05-21 16:28:27 -0700214 // The panic gesture may become active only after the keyguard is dismissed and the immersive
215 // app shows again. If that doesn't happen for 30s we drop the gesture.
216 private static final long PANIC_GESTURE_EXPIRATION = 30000;
217
Jim Miller5ecd8112013-01-09 18:50:26 -0800218 /**
219 * Keyguard stuff
220 */
221 private WindowState mKeyguardScrim;
Jorim Jaggi380ecb82014-03-14 17:25:20 +0100222 private boolean mKeyguardHidden;
Jeff Brown3ee549c2014-09-22 20:14:39 -0700223 private boolean mKeyguardDrawnOnce;
Jim Miller5ecd8112013-01-09 18:50:26 -0800224
Jeff Brown6651a632011-11-28 12:59:11 -0800225 /* Table of Application Launch keys. Maps from key codes to intent categories.
226 *
227 * These are special keys that are used to launch particular kinds of applications,
228 * such as a web browser. HID defines nearly a hundred of them in the Consumer (0x0C)
229 * usage page. We don't support quite that many yet...
230 */
231 static SparseArray<String> sApplicationLaunchKeyCategories;
232 static {
233 sApplicationLaunchKeyCategories = new SparseArray<String>();
234 sApplicationLaunchKeyCategories.append(
235 KeyEvent.KEYCODE_EXPLORER, Intent.CATEGORY_APP_BROWSER);
236 sApplicationLaunchKeyCategories.append(
237 KeyEvent.KEYCODE_ENVELOPE, Intent.CATEGORY_APP_EMAIL);
238 sApplicationLaunchKeyCategories.append(
239 KeyEvent.KEYCODE_CONTACTS, Intent.CATEGORY_APP_CONTACTS);
240 sApplicationLaunchKeyCategories.append(
241 KeyEvent.KEYCODE_CALENDAR, Intent.CATEGORY_APP_CALENDAR);
242 sApplicationLaunchKeyCategories.append(
243 KeyEvent.KEYCODE_MUSIC, Intent.CATEGORY_APP_MUSIC);
244 sApplicationLaunchKeyCategories.append(
245 KeyEvent.KEYCODE_CALCULATOR, Intent.CATEGORY_APP_CALCULATOR);
246 }
247
Craig Mautnerc3daedd2014-09-13 11:17:23 -0700248 /** Amount of time (in milliseconds) to wait for windows drawn before powering on. */
Stefan Kuhne9326dc12015-06-12 09:25:32 -1000249 static final int WAITING_FOR_DRAWN_TIMEOUT = 500;
Craig Mautnerc3daedd2014-09-13 11:17:23 -0700250
Dianne Hackborndf89e652011-10-06 22:35:11 -0700251 /**
252 * Lock protecting internal state. Must not call out into window
253 * manager with lock held. (This lock will be acquired in places
254 * where the window manager is calling in with its own lock held.)
255 */
Craig Mautner0bf6ec92012-12-18 08:33:27 -0800256 private final Object mLock = new Object();
Dianne Hackborndf89e652011-10-06 22:35:11 -0700257
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800258 Context mContext;
259 IWindowManager mWindowManager;
Dianne Hackborndf89e652011-10-06 22:35:11 -0700260 WindowManagerFuncs mWindowManagerFuncs;
Craig Mautner8a0da012014-05-31 15:13:37 -0700261 WindowManagerInternal mWindowManagerInternal;
Jeff Brown96307042012-07-27 15:51:34 -0700262 PowerManager mPowerManager;
Jeff Brown061ea992015-04-17 19:55:47 -0700263 ActivityManagerInternal mActivityManagerInternal;
Jose Lima9546b202014-07-02 17:21:51 -0700264 DreamManagerInternal mDreamManagerInternal;
Joe Onorato93056472010-09-10 10:30:46 -0400265 IStatusBarService mStatusBarService;
Jeff Browncaca8812013-05-09 13:34:33 -0700266 boolean mPreloadedRecentApps;
Dianne Hackborn42e620c2012-06-24 13:20:51 -0700267 final Object mServiceAquireLock = new Object();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800268 Vibrator mVibrator; // Vibrator for giving feedback of orientation changes
Jeff Brownde7a8ea2012-06-13 18:28:57 -0700269 SearchManager mSearchManager;
Svetoslav8e3feb12014-02-24 13:46:47 -0800270 AccessibilityManager mAccessibilityManager;
Filip Gruszczynskicfb31852015-02-25 21:47:12 +0000271 BurnInProtectionHelper mBurnInProtectionHelper;
Billy Laucbe540f2015-06-25 01:51:44 +0100272 AppOpsManager mAppOpsManager;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800273
Dianne Hackborn181ceb52009-08-27 22:16:40 -0700274 // Vibrator pattern for haptic feedback of a long press.
275 long[] mLongPressVibePattern;
Craig Mautner88400d32012-09-30 12:35:45 -0700276
Dianne Hackborn181ceb52009-08-27 22:16:40 -0700277 // Vibrator pattern for haptic feedback of virtual key press.
278 long[] mVirtualKeyVibePattern;
Craig Mautner967212c2013-04-13 21:10:58 -0700279
Amith Yamasanic33cb712010-02-10 15:21:49 -0800280 // Vibrator pattern for a short vibration.
281 long[] mKeyboardTapVibePattern;
282
Fabrice Di Meglioeeff63a2013-08-05 12:07:24 -0700283 // Vibrator pattern for a short vibration when tapping on an hour/minute tick of a Clock.
284 long[] mClockTickVibePattern;
285
Fabrice Di Megliobd9152f2013-10-01 11:21:31 -0700286 // Vibrator pattern for a short vibration when tapping on a day/month/year date of a Calendar.
287 long[] mCalendarDateVibePattern;
288
Dianne Hackbornb1a79802009-09-29 15:18:31 -0700289 // Vibrator pattern for haptic feedback during boot when safe mode is disabled.
290 long[] mSafeModeDisabledVibePattern;
Craig Mautner967212c2013-04-13 21:10:58 -0700291
Dianne Hackbornb1a79802009-09-29 15:18:31 -0700292 // Vibrator pattern for haptic feedback during boot when safe mode is enabled.
293 long[] mSafeModeEnabledVibePattern;
Romain Guy8154cd32010-03-29 14:41:15 -0700294
Mady Mellore8608912015-06-05 09:02:55 -0700295 // Vibrator pattern for haptic feedback of a context click.
296 long[] mContextClickVibePattern;
Mady Mellore82067b2015-04-30 09:58:35 -0700297
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800298 /** If true, hitting shift & menu will broadcast Intent.ACTION_BUG_REPORT */
299 boolean mEnableShiftMenuBugReports = false;
Mike Lockwoodd747dc82011-09-13 16:28:22 -0400300
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800301 boolean mSafeMode;
302 WindowState mStatusBar = null;
Dianne Hackborn69cb8752011-05-19 18:13:32 -0700303 int mStatusBarHeight;
Daniel Sandler8956dbb2011-04-22 07:55:02 -0400304 WindowState mNavigationBar = null;
Daniel Sandler36412a72011-08-04 09:35:13 -0400305 boolean mHasNavigationBar = false;
Dianne Hackbornf87d1962012-04-04 12:48:24 -0700306 boolean mCanHideNavigationBar = false;
Daniel Sandler4a066c52012-04-20 14:49:13 -0400307 boolean mNavigationBarCanMove = false; // can the navigation bar ever move to the side?
308 boolean mNavigationBarOnBottom = true; // is the navigation bar on the bottom *right now*?
309 int[] mNavigationBarHeightForRotation = new int[4];
310 int[] mNavigationBarWidthForRotation = new int[4];
Daniel Sandler8956dbb2011-04-22 07:55:02 -0400311
Craig Mautnera631d492014-08-05 15:16:01 -0700312 boolean mBootMessageNeedsHiding;
Jim Miller5ecd8112013-01-09 18:50:26 -0800313 KeyguardServiceDelegate mKeyguardDelegate;
Craig Mautner13f6ea72014-06-23 14:57:02 -0700314 final Runnable mWindowManagerDrawCallback = new Runnable() {
Craig Mautner8a0da012014-05-31 15:13:37 -0700315 @Override
Craig Mautner13f6ea72014-06-23 14:57:02 -0700316 public void run() {
Craig Mautner8a0da012014-05-31 15:13:37 -0700317 if (DEBUG_WAKEUP) Slog.i(TAG, "All windows ready for display!");
318 mHandler.sendEmptyMessage(MSG_WINDOW_MANAGER_DRAWN_COMPLETE);
319 }
320 };
321 final ShowListener mKeyguardDelegateCallback = new ShowListener() {
322 @Override
323 public void onShown(IBinder windowToken) {
324 if (DEBUG_WAKEUP) Slog.d(TAG, "mKeyguardDelegate.ShowListener.onShown.");
325 mHandler.sendEmptyMessage(MSG_KEYGUARD_DRAWN_COMPLETE);
326 }
327 };
328
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800329 GlobalActions mGlobalActions;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800330 Handler mHandler;
satok1bc0a492012-04-25 22:47:12 +0900331 WindowState mLastInputMethodWindow = null;
332 WindowState mLastInputMethodTargetWindow = null;
Jeff Brown4aed78b2011-01-14 17:36:55 -0800333
Jeff Brown13f00f02014-10-31 14:45:50 -0700334 // FIXME This state is shared between the input reader and handler thread.
335 // Technically it's broken and buggy but it has been like this for many years
336 // and we have not yet seen any problems. Someday we'll rewrite this logic
337 // so that only one thread is involved in handling input policy. Unfortunately
338 // it's on a critical path for power management so we can't just post the work to the
339 // handler thread. We'll need to resolve this someday by teaching the input dispatcher
340 // to hold wakelocks during dispatch and eliminating the critical path.
341 volatile boolean mPowerKeyHandled;
Bryce Leed9268e32014-11-17 17:40:59 -0800342 volatile boolean mBeganFromNonInteractive;
Jeff Brown13f00f02014-10-31 14:45:50 -0700343 volatile int mPowerKeyPressCounter;
344 volatile boolean mEndCallKeyHandled;
345
Winson Chungd42a6cf2014-06-03 16:24:04 -0700346 boolean mRecentsVisible;
Winson Chung1e8d71b2014-05-16 17:05:22 -0700347 int mRecentAppsHeldModifiers;
Jeff Browncf39bdf2012-05-18 14:41:19 -0700348 boolean mLanguageSwitchKeyPressed;
Jeff Brown68b909d2011-12-07 16:36:01 -0800349
Jeff Brown2e7760e2012-04-11 15:14:55 -0700350 int mLidState = LID_ABSENT;
Michael Wright3818c922014-09-02 13:59:07 -0700351 int mCameraLensCoverState = CAMERA_LENS_COVER_ABSENT;
Jeff Browndaa37532012-05-01 15:54:03 -0700352 boolean mHaveBuiltInKeyboard;
Jeff Brown4aed78b2011-01-14 17:36:55 -0800353
Dianne Hackbornc777e072010-02-12 13:07:59 -0800354 boolean mSystemReady;
Dianne Hackbornba24e4d2011-09-01 11:17:06 -0700355 boolean mSystemBooted;
Dianne Hackbornad7fa7f2011-01-07 14:06:50 -0800356 boolean mHdmiPlugged;
Jeff Brown4f5fa282014-06-12 19:19:15 -0700357 IUiModeManager mUiModeManager;
Daniel Sandler6396c722013-04-16 20:19:09 -0400358 int mUiMode;
Dianne Hackborn867ab6472010-04-29 13:28:56 -0700359 int mDockMode = Intent.EXTRA_DOCK_STATE_UNDOCKED;
Mike Lockwood1753f7f2009-08-24 14:49:07 -0700360 int mLidOpenRotation;
Mike Lockwood2d1efbd2009-09-16 12:15:53 -0400361 int mCarDockRotation;
362 int mDeskDockRotation;
Jeff Brownc82c89ed2013-04-17 17:18:15 -0700363 int mUndockedHdmiRotation;
364 int mDemoHdmiRotation;
365 boolean mDemoHdmiRotationLock;
Chong Zhangae6119ff2014-11-11 18:54:39 -0800366 int mDemoRotation;
367 boolean mDemoRotationLock;
Daniel Sandlerb73617d2010-08-17 00:41:00 -0400368
Jeff Browna20dda42014-05-27 20:57:24 -0700369 boolean mWakeGestureEnabledSetting;
370 MyWakeGestureListener mWakeGestureListener;
371
Craig Mautner46ac6fa2013-08-01 10:06:34 -0700372 // Default display does not rotate, apps that require non-default orientation will have to
373 // have the orientation emulated.
374 private boolean mForceDefaultOrientation = false;
375
Daniel Sandlerb73617d2010-08-17 00:41:00 -0400376 int mUserRotationMode = WindowManagerPolicy.USER_ROTATION_FREE;
377 int mUserRotation = Surface.ROTATION_0;
Jeff Brown207673cd2012-06-05 17:47:11 -0700378 boolean mAccelerometerDefault;
Daniel Sandlerb73617d2010-08-17 00:41:00 -0400379
Jeff Brownbcdfc622014-03-06 19:13:04 -0800380 boolean mSupportAutoRotation;
Jeff Brownd3187e32011-09-21 19:26:44 -0700381 int mAllowAllRotations = -1;
Mike Lockwoode9867d22009-09-20 01:59:02 -0400382 boolean mCarDockEnablesAccelerometer;
383 boolean mDeskDockEnablesAccelerometer;
Dianne Hackborn2862fff2009-09-15 22:56:29 -0700384 int mLidKeyboardAccessibility;
385 int mLidNavigationAccessibility;
Jeff Brownc458ce92012-04-30 14:58:40 -0700386 boolean mLidControlsSleep;
Jeff Brown13f00f02014-10-31 14:45:50 -0700387 int mShortPressOnPowerBehavior;
388 int mLongPressOnPowerBehavior;
389 int mDoublePressOnPowerBehavior;
390 int mTriplePressOnPowerBehavior;
Filip Gruszczynskia483a1d2015-03-17 19:06:58 +0000391 int mShortPressOnSleepBehavior;
Jeff Brown3ee549c2014-09-22 20:14:39 -0700392 boolean mAwake;
393 boolean mScreenOnEarly;
394 boolean mScreenOnFully;
395 ScreenOnListener mScreenOnListener;
396 boolean mKeyguardDrawComplete;
397 boolean mWindowManagerDrawComplete;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800398 boolean mOrientationSensorEnabled = false;
399 int mCurrentAppOrientation = ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800400 boolean mHasSoftInput = false;
Daniel Sandlerdd73ee42013-10-11 22:19:59 -0400401 boolean mTranslucentDecorEnabled = true;
RoboErik001c59c2015-01-26 15:53:51 -0800402 boolean mUseTvRouting;
Craig Mautner967212c2013-04-13 21:10:58 -0700403
Jeff Brown70825162012-03-28 17:27:48 -0700404 int mPointerLocationMode = 0; // guarded by mLock
Joe Onorato664644d2011-01-23 17:53:23 -0800405
406 // The last window we were told about in focusChanged.
407 WindowState mFocusedWindow;
Dianne Hackborne0f085d2011-11-30 18:41:15 -0800408 IApplicationToken mFocusedApp;
Joe Onorato664644d2011-01-23 17:53:23 -0800409
Jeff Brown70825162012-03-28 17:27:48 -0700410 PointerLocationView mPointerLocationView;
Jeff Brown32cbc38552011-12-01 14:01:49 -0800411
Dianne Hackbornc652de82013-02-15 16:32:56 -0800412 // The current size of the screen; really; extends into the overscan area of
413 // the screen and doesn't account for any system elements like the status bar.
414 int mOverscanScreenLeft, mOverscanScreenTop;
415 int mOverscanScreenWidth, mOverscanScreenHeight;
416 // The current visible size of the screen; really; (ir)regardless of whether the status
417 // bar can be hidden but not extending into the overscan area.
Joe Onorato29fc2c92010-11-24 10:26:50 -0800418 int mUnrestrictedScreenLeft, mUnrestrictedScreenTop;
419 int mUnrestrictedScreenWidth, mUnrestrictedScreenHeight;
Dianne Hackborn313440842013-02-19 19:22:59 -0800420 // Like mOverscanScreen*, but allowed to move into the overscan region where appropriate.
421 int mRestrictedOverscanScreenLeft, mRestrictedOverscanScreenTop;
422 int mRestrictedOverscanScreenWidth, mRestrictedOverscanScreenHeight;
Dianne Hackborn82de1ae2010-10-28 11:28:39 -0700423 // The current size of the screen; these may be different than (0,0)-(dw,dh)
424 // if the status bar can't be hidden; in that case it effectively carves out
425 // that area of the display from all other windows.
Joe Onorato29fc2c92010-11-24 10:26:50 -0800426 int mRestrictedScreenLeft, mRestrictedScreenTop;
427 int mRestrictedScreenWidth, mRestrictedScreenHeight;
Dianne Hackborn5c58de32012-04-28 19:52:37 -0700428 // During layout, the current screen borders accounting for any currently
429 // visible system UI elements.
430 int mSystemLeft, mSystemTop, mSystemRight, mSystemBottom;
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -0700431 // For applications requesting stable content insets, these are them.
432 int mStableLeft, mStableTop, mStableRight, mStableBottom;
Dianne Hackborn5b5cc4d2012-05-16 13:15:00 -0700433 // For applications requesting stable content insets but have also set the
434 // fullscreen window flag, these are the stable dimensions without the status bar.
435 int mStableFullscreenLeft, mStableFullscreenTop;
436 int mStableFullscreenRight, mStableFullscreenBottom;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800437 // During layout, the current screen borders with all outer decoration
438 // (status bar, input method dock) accounted for.
439 int mCurLeft, mCurTop, mCurRight, mCurBottom;
440 // During layout, the frame in which content should be displayed
441 // to the user, accounting for all screen decoration except for any
442 // space they deem as available for other content. This is usually
443 // the same as mCur*, but may be larger if the screen decor has supplied
444 // content insets.
445 int mContentLeft, mContentTop, mContentRight, mContentBottom;
Dianne Hackborne30e02f2014-05-27 18:24:45 -0700446 // During layout, the frame in which voice content should be displayed
447 // to the user, accounting for all screen decoration except for any
448 // space they deem as available for other content.
449 int mVoiceContentLeft, mVoiceContentTop, mVoiceContentRight, mVoiceContentBottom;
Dianne Hackborn8e11ef02010-11-18 19:47:42 -0800450 // During layout, the current screen borders along which input method
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800451 // windows are placed.
452 int mDockLeft, mDockTop, mDockRight, mDockBottom;
453 // During layout, the layer at which the doc window is placed.
454 int mDockLayer;
Dianne Hackborn5c58de32012-04-28 19:52:37 -0700455 // During layout, this is the layer of the status bar.
456 int mStatusBarLayer;
Dianne Hackborne26ab702011-10-16 13:21:33 -0700457 int mLastSystemUiFlags;
458 // Bits that we are in the process of clearing, so we want to prevent
459 // them from being set by applications until everything has been updated
460 // to have them clear.
461 int mResettingSystemUiFlags = 0;
462 // Bits that we are currently always keeping cleared.
463 int mForceClearedSystemUiFlags = 0;
Dianne Hackborn4eff8d32011-11-10 19:38:40 -0800464 // What we last reported to system UI about whether the compatibility
465 // menu needs to be displayed.
466 boolean mLastFocusNeedsMenu = false;
Adrian Roosddc8b272015-05-21 16:28:27 -0700467 // If nonzero, a panic gesture was performed at that time in uptime millis and is still pending.
468 private long mPendingPanicGestureUptime;
Dianne Hackborndf89e652011-10-06 22:35:11 -0700469
Selim Cinekf83e8242015-05-19 18:08:14 -0700470 InputConsumer mInputConsumer = null;
Dianne Hackborndf89e652011-10-06 22:35:11 -0700471
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800472 static final Rect mTmpParentFrame = new Rect();
473 static final Rect mTmpDisplayFrame = new Rect();
Dianne Hackbornc4aad012013-02-22 15:05:25 -0800474 static final Rect mTmpOverscanFrame = new Rect();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800475 static final Rect mTmpContentFrame = new Rect();
476 static final Rect mTmpVisibleFrame = new Rect();
John Spurlock46646232013-09-30 22:32:42 -0400477 static final Rect mTmpDecorFrame = new Rect();
Adrian Roosfa104232014-06-20 16:10:14 -0700478 static final Rect mTmpStableFrame = new Rect();
Dianne Hackborn1f903c32011-09-13 19:18:06 -0700479 static final Rect mTmpNavigationFrame = new Rect();
Filip Gruszczynski2217f612015-05-26 11:32:08 -0700480 static final Rect mTmpOutsetFrame = new Rect();
Craig Mautner967212c2013-04-13 21:10:58 -0700481
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800482 WindowState mTopFullscreenOpaqueWindowState;
Adrian Rooscd3884d2015-02-18 17:25:23 +0100483 WindowState mTopFullscreenOpaqueOrDimmingWindowState;
Craig Mautner2bc789b2014-03-19 19:48:38 -0700484 HashSet<IApplicationToken> mAppsToBeHidden = new HashSet<IApplicationToken>();
Jorim Jaggic13fcac2014-09-11 17:36:57 +0200485 HashSet<IApplicationToken> mAppsThatDismissKeyguard = new HashSet<IApplicationToken>();
Joe Onorato93056472010-09-10 10:30:46 -0400486 boolean mTopIsFullscreen;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800487 boolean mForceStatusBar;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -0700488 boolean mForceStatusBarFromKeyguard;
Selim Cinek4a4a2bddc2015-05-07 12:50:19 -0700489 private boolean mForceStatusBarTransparent;
Dianne Hackborn39c2d712009-09-22 11:41:31 -0700490 boolean mHideLockScreen;
Dianne Hackborn891d3fb2013-01-09 18:31:37 -0800491 boolean mForcingShowNavBar;
492 int mForcingShowNavBarLayer;
Craig Mautnerad09bcc2012-10-08 13:33:11 -0700493
494 // States of keyguard dismiss.
495 private static final int DISMISS_KEYGUARD_NONE = 0; // Keyguard not being dismissed.
496 private static final int DISMISS_KEYGUARD_START = 1; // Keyguard needs to be dismissed.
497 private static final int DISMISS_KEYGUARD_CONTINUE = 2; // Keyguard has been dismissed.
498 int mDismissKeyguard = DISMISS_KEYGUARD_NONE;
499
500 /** The window that is currently dismissing the keyguard. Dismissing the keyguard must only
501 * be done once per window. */
502 private WindowState mWinDismissingKeyguard;
503
tingna_sunge785ffa2015-05-12 13:23:15 +0800504 /** When window is currently dismissing the keyguard, dismissing the keyguard must handle
505 * the keygaurd secure state change instantly case, e.g. the use case of inserting a PIN
506 * lock SIM card. This variable is used to record the previous keyguard secure state for
507 * monitoring secure state change on window dismissing keyguard. */
508 private boolean mSecureDismissingKeyguard;
509
Craig Mautnerc9457fa2014-06-06 14:27:48 -0700510 /** The window that is currently showing "over" the keyguard. If there is an app window
511 * belonging to another app on top of this the keyguard shows. If there is a fullscreen
512 * app window under this, still dismiss the keyguard but don't show the app underneath. Show
513 * the wallpaper. */
514 private WindowState mWinShowWhenLocked;
515
Dianne Hackborn7ad44382012-10-18 17:46:00 -0700516 boolean mShowingLockscreen;
517 boolean mShowingDream;
518 boolean mDreamingLockscreen;
Jeff Brown061ea992015-04-17 19:55:47 -0700519 boolean mDreamingSleepTokenNeeded;
520 SleepToken mDreamingSleepToken;
Jeff Brown48d1b142015-06-10 16:36:03 -0700521 SleepToken mScreenOffSleepToken;
Jim Millerab954542014-10-10 18:21:49 -0700522 boolean mKeyguardSecure;
523 boolean mKeyguardSecureIncludingHidden;
524 volatile boolean mKeyguardOccluded;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800525 boolean mHomePressed;
Jeff Browncaca8812013-05-09 13:34:33 -0700526 boolean mHomeConsumed;
527 boolean mHomeDoubleTapPending;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800528 Intent mHomeIntent;
Dianne Hackborn39c2d712009-09-22 11:41:31 -0700529 Intent mCarDockIntent;
530 Intent mDeskDockIntent;
Jeff Brownfd23e3e2012-05-09 13:34:28 -0700531 boolean mSearchKeyShortcutPending;
532 boolean mConsumeSearchKeyUp;
Jeff Brownde7a8ea2012-06-13 18:28:57 -0700533 boolean mAssistKeyLongPressed;
Michael Wright6a62e552014-06-03 19:19:48 -0700534 boolean mPendingMetaAction;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800535
Mike Lockwood28569302010-01-28 11:54:40 -0500536 // support for activating the lock screen while the screen is on
537 boolean mAllowLockscreenWhenOn;
538 int mLockScreenTimeout;
539 boolean mLockScreenTimerActive;
540
David Brownbaf8d092010-03-08 21:52:59 -0800541 // Behavior of ENDCALL Button. (See Settings.System.END_BUTTON_BEHAVIOR.)
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800542 int mEndcallBehavior;
David Brownbaf8d092010-03-08 21:52:59 -0800543
544 // Behavior of POWER button while in-call and screen on.
545 // (See Settings.Secure.INCALL_POWER_BUTTON_BEHAVIOR.)
546 int mIncallPowerBehavior;
547
Dianne Hackbornf87d1962012-04-04 12:48:24 -0700548 Display mDisplay;
549
Dianne Hackborn9d132642011-04-21 17:26:39 -0700550 int mLandscapeRotation = 0; // default landscape rotation
551 int mSeascapeRotation = 0; // "other" landscape rotation, 180 degrees from mLandscapeRotation
552 int mPortraitRotation = 0; // default portrait rotation
553 int mUpsideDownRotation = 0; // "other" portrait rotation
Mitsuru Oshima831d0d92009-06-16 18:27:18 -0700554
Dianne Hackbornc652de82013-02-15 16:32:56 -0800555 int mOverscanLeft = 0;
556 int mOverscanTop = 0;
557 int mOverscanRight = 0;
558 int mOverscanBottom = 0;
559
Joe Onorato46b0d682010-11-22 17:37:27 -0800560 // What we do when the user long presses on home
Jeff Browncaca8812013-05-09 13:34:33 -0700561 private int mLongPressOnHomeBehavior;
562
563 // What we do when the user double-taps on home
564 private int mDoubleTapOnHomeBehavior;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800565
Bryce Lee584a4452014-10-21 15:55:55 -0700566 // Allowed theater mode wake actions
567 private boolean mAllowTheaterModeWakeFromKey;
568 private boolean mAllowTheaterModeWakeFromPowerKey;
569 private boolean mAllowTheaterModeWakeFromMotion;
Bryce Lee812d7022014-11-10 13:33:28 -0800570 private boolean mAllowTheaterModeWakeFromMotionWhenNotDreaming;
Bryce Lee584a4452014-10-21 15:55:55 -0700571 private boolean mAllowTheaterModeWakeFromCameraLens;
572 private boolean mAllowTheaterModeWakeFromLidSwitch;
573 private boolean mAllowTheaterModeWakeFromWakeGesture;
574
Bryce Leed3b28402015-03-09 15:49:13 +0000575 // Whether to support long press from power button in non-interactive mode
576 private boolean mSupportLongPressPowerWhenNonInteractive;
577
Bryce Lee55e846d2014-11-04 12:43:44 -0800578 // Whether to go to sleep entering theater mode from power button
579 private boolean mGoToSleepOnButtonPressTheaterMode;
580
Winson Chung9112ec32011-06-27 13:15:32 -0700581 // Screenshot trigger states
Jeff Brownd5bb82d2011-10-12 13:57:59 -0700582 // Time to volume and power must be pressed within this interval of each other.
583 private static final long SCREENSHOT_CHORD_DEBOUNCE_DELAY_MILLIS = 150;
Winson Chung1cea2f32012-10-08 20:42:01 -0700584 // Increase the chord delay when taking a screenshot from the keyguard
585 private static final float KEYGUARD_SCREENSHOT_CHORD_DELAY_MULTIPLIER = 2.5f;
Christopher Tatee90585f2012-03-05 18:56:25 -0800586 private boolean mScreenshotChordEnabled;
Jeff Brown13f00f02014-10-31 14:45:50 -0700587 private boolean mScreenshotChordVolumeDownKeyTriggered;
588 private long mScreenshotChordVolumeDownKeyTime;
589 private boolean mScreenshotChordVolumeDownKeyConsumed;
590 private boolean mScreenshotChordVolumeUpKeyTriggered;
591 private boolean mScreenshotChordPowerKeyTriggered;
592 private long mScreenshotChordPowerKeyTime;
Winson Chung9112ec32011-06-27 13:15:32 -0700593
Michael Wrightb854e242013-02-05 17:54:02 -0800594 /* The number of steps between min and max brightness */
595 private static final int BRIGHTNESS_STEPS = 10;
596
Christopher Tate5e08af02012-09-21 17:17:22 -0700597 SettingsObserver mSettingsObserver;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800598 ShortcutManager mShortcutManager;
599 PowerManager.WakeLock mBroadcastWakeLock;
Jeff Brown13f00f02014-10-31 14:45:50 -0700600 PowerManager.WakeLock mPowerKeyWakeLock;
Jeff Brown40013652012-05-16 21:22:36 -0700601 boolean mHavePendingMediaKeyRepeatWithWakeLock;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800602
Craig Mautnerd625ab22013-09-06 13:40:31 -0700603 private int mCurrentUserId;
604
Justin Kohd378ad72013-04-01 12:18:26 -0700605 // Maps global key codes to the components that will handle them.
606 private GlobalKeyManager mGlobalKeyManager;
607
Jeff Brownfd23e3e2012-05-09 13:34:28 -0700608 // Fallback actions by key code.
609 private final SparseArray<KeyCharacterMap.FallbackAction> mFallbackActions =
610 new SparseArray<KeyCharacterMap.FallbackAction>();
Jeff Brown49ed71d2010-12-06 17:13:33 -0800611
Jorim Jaggi76a16232014-08-08 17:00:47 +0200612 private final LogDecelerateInterpolator mLogDecelerateInterpolator
613 = new LogDecelerateInterpolator(100, 0);
614
Jeff Brown70825162012-03-28 17:27:48 -0700615 private static final int MSG_ENABLE_POINTER_LOCATION = 1;
616 private static final int MSG_DISABLE_POINTER_LOCATION = 2;
Jeff Brown40013652012-05-16 21:22:36 -0700617 private static final int MSG_DISPATCH_MEDIA_KEY_WITH_WAKE_LOCK = 3;
618 private static final int MSG_DISPATCH_MEDIA_KEY_REPEAT_WITH_WAKE_LOCK = 4;
Craig Mautner8a0da012014-05-31 15:13:37 -0700619 private static final int MSG_KEYGUARD_DRAWN_COMPLETE = 5;
620 private static final int MSG_KEYGUARD_DRAWN_TIMEOUT = 6;
621 private static final int MSG_WINDOW_MANAGER_DRAWN_COMPLETE = 7;
Craig Mautner84984fa2014-06-19 11:19:20 -0700622 private static final int MSG_DISPATCH_SHOW_RECENTS = 9;
Alan Viverettee34560b22014-07-10 14:50:06 -0700623 private static final int MSG_DISPATCH_SHOW_GLOBAL_ACTIONS = 10;
Craig Mautnera631d492014-08-05 15:16:01 -0700624 private static final int MSG_HIDE_BOOT_MESSAGE = 11;
Michael Wright869a67c2014-08-26 19:33:06 -0700625 private static final int MSG_LAUNCH_VOICE_ASSIST_WITH_WAKE_LOCK = 12;
Jeff Brown13f00f02014-10-31 14:45:50 -0700626 private static final int MSG_POWER_DELAYED_PRESS = 13;
627 private static final int MSG_POWER_LONG_PRESS = 14;
Jeff Brown061ea992015-04-17 19:55:47 -0700628 private static final int MSG_UPDATE_DREAMING_SLEEP_TOKEN = 15;
Jeff Brown70825162012-03-28 17:27:48 -0700629
630 private class PolicyHandler extends Handler {
631 @Override
632 public void handleMessage(Message msg) {
633 switch (msg.what) {
634 case MSG_ENABLE_POINTER_LOCATION:
635 enablePointerLocation();
636 break;
637 case MSG_DISABLE_POINTER_LOCATION:
638 disablePointerLocation();
639 break;
Jeff Brown40013652012-05-16 21:22:36 -0700640 case MSG_DISPATCH_MEDIA_KEY_WITH_WAKE_LOCK:
641 dispatchMediaKeyWithWakeLock((KeyEvent)msg.obj);
642 break;
643 case MSG_DISPATCH_MEDIA_KEY_REPEAT_WITH_WAKE_LOCK:
644 dispatchMediaKeyRepeatWithWakeLock((KeyEvent)msg.obj);
645 break;
Craig Mautner84984fa2014-06-19 11:19:20 -0700646 case MSG_DISPATCH_SHOW_RECENTS:
647 showRecentApps(false);
648 break;
Alan Viverettee34560b22014-07-10 14:50:06 -0700649 case MSG_DISPATCH_SHOW_GLOBAL_ACTIONS:
650 showGlobalActionsInternal();
651 break;
Craig Mautner8a0da012014-05-31 15:13:37 -0700652 case MSG_KEYGUARD_DRAWN_COMPLETE:
653 if (DEBUG_WAKEUP) Slog.w(TAG, "Setting mKeyguardDrawComplete");
Jeff Brown36c4db82014-09-19 12:05:31 -0700654 finishKeyguardDrawn();
Craig Mautner8a0da012014-05-31 15:13:37 -0700655 break;
656 case MSG_KEYGUARD_DRAWN_TIMEOUT:
657 Slog.w(TAG, "Keyguard drawn timeout. Setting mKeyguardDrawComplete");
Jeff Brown36c4db82014-09-19 12:05:31 -0700658 finishKeyguardDrawn();
Craig Mautner8a0da012014-05-31 15:13:37 -0700659 break;
660 case MSG_WINDOW_MANAGER_DRAWN_COMPLETE:
661 if (DEBUG_WAKEUP) Slog.w(TAG, "Setting mWindowManagerDrawComplete");
Jeff Brown36c4db82014-09-19 12:05:31 -0700662 finishWindowsDrawn();
Craig Mautner8a0da012014-05-31 15:13:37 -0700663 break;
Craig Mautnera631d492014-08-05 15:16:01 -0700664 case MSG_HIDE_BOOT_MESSAGE:
665 handleHideBootMessage();
666 break;
Michael Wright869a67c2014-08-26 19:33:06 -0700667 case MSG_LAUNCH_VOICE_ASSIST_WITH_WAKE_LOCK:
668 launchVoiceAssistWithWakeLock(msg.arg1 != 0);
669 break;
Jeff Brown13f00f02014-10-31 14:45:50 -0700670 case MSG_POWER_DELAYED_PRESS:
671 powerPress((Long)msg.obj, msg.arg1 != 0, msg.arg2);
672 finishPowerKeyPress();
673 break;
674 case MSG_POWER_LONG_PRESS:
675 powerLongPress();
676 break;
Jeff Brown061ea992015-04-17 19:55:47 -0700677 case MSG_UPDATE_DREAMING_SLEEP_TOKEN:
678 updateDreamingSleepToken(msg.arg1 != 0);
679 break;
Jeff Brown70825162012-03-28 17:27:48 -0700680 }
681 }
682 }
683
Dianne Hackbornad7fa7f2011-01-07 14:06:50 -0800684 private UEventObserver mHDMIObserver = new UEventObserver() {
685 @Override
686 public void onUEvent(UEventObserver.UEvent event) {
687 setHdmiPlugged("1".equals(event.get("SWITCH_STATE")));
688 }
689 };
690
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800691 class SettingsObserver extends ContentObserver {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800692 SettingsObserver(Handler handler) {
693 super(handler);
694 }
David Brownbaf8d092010-03-08 21:52:59 -0800695
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800696 void observe() {
Christopher Tate5e08af02012-09-21 17:17:22 -0700697 // Observe all users' changes
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800698 ContentResolver resolver = mContext.getContentResolver();
699 resolver.registerContentObserver(Settings.System.getUriFor(
Christopher Tate5e08af02012-09-21 17:17:22 -0700700 Settings.System.END_BUTTON_BEHAVIOR), false, this,
701 UserHandle.USER_ALL);
David Brownbaf8d092010-03-08 21:52:59 -0800702 resolver.registerContentObserver(Settings.Secure.getUriFor(
Christopher Tate5e08af02012-09-21 17:17:22 -0700703 Settings.Secure.INCALL_POWER_BUTTON_BEHAVIOR), false, this,
704 UserHandle.USER_ALL);
Jeff Browna20dda42014-05-27 20:57:24 -0700705 resolver.registerContentObserver(Settings.Secure.getUriFor(
706 Settings.Secure.WAKE_GESTURE_ENABLED), false, this,
707 UserHandle.USER_ALL);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800708 resolver.registerContentObserver(Settings.System.getUriFor(
Christopher Tate5e08af02012-09-21 17:17:22 -0700709 Settings.System.ACCELEROMETER_ROTATION), false, this,
710 UserHandle.USER_ALL);
Mike Lockwood28569302010-01-28 11:54:40 -0500711 resolver.registerContentObserver(Settings.System.getUriFor(
Christopher Tate5e08af02012-09-21 17:17:22 -0700712 Settings.System.USER_ROTATION), false, this,
713 UserHandle.USER_ALL);
Daniel Sandlerb73617d2010-08-17 00:41:00 -0400714 resolver.registerContentObserver(Settings.System.getUriFor(
Christopher Tate5e08af02012-09-21 17:17:22 -0700715 Settings.System.SCREEN_OFF_TIMEOUT), false, this,
716 UserHandle.USER_ALL);
Dianne Hackbornc777e072010-02-12 13:07:59 -0800717 resolver.registerContentObserver(Settings.System.getUriFor(
Christopher Tate5e08af02012-09-21 17:17:22 -0700718 Settings.System.POINTER_LOCATION), false, this,
719 UserHandle.USER_ALL);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800720 resolver.registerContentObserver(Settings.Secure.getUriFor(
Christopher Tate5e08af02012-09-21 17:17:22 -0700721 Settings.Secure.DEFAULT_INPUT_METHOD), false, this,
722 UserHandle.USER_ALL);
John Spurlockd9b70bd2014-02-06 17:02:44 -0500723 resolver.registerContentObserver(Settings.Secure.getUriFor(
John Spurlockf1a36642013-10-12 17:50:42 -0400724 Settings.Secure.IMMERSIVE_MODE_CONFIRMATIONS), false, this,
Christopher Tate5e08af02012-09-21 17:17:22 -0700725 UserHandle.USER_ALL);
John Spurlockc6d1c602014-01-17 15:22:06 -0500726 resolver.registerContentObserver(Settings.Global.getUriFor(
727 Settings.Global.POLICY_CONTROL), false, this,
728 UserHandle.USER_ALL);
Dianne Hackbornc777e072010-02-12 13:07:59 -0800729 updateSettings();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800730 }
731
732 @Override public void onChange(boolean selfChange) {
Dianne Hackbornc777e072010-02-12 13:07:59 -0800733 updateSettings();
Jeff Brown01a98dd2011-09-20 15:08:29 -0700734 updateRotation(false);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800735 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800736 }
Craig Mautner967212c2013-04-13 21:10:58 -0700737
Jeff Browna20dda42014-05-27 20:57:24 -0700738 class MyWakeGestureListener extends WakeGestureListener {
739 MyWakeGestureListener(Context context, Handler handler) {
740 super(context, handler);
741 }
742
743 @Override
744 public void onWakeUp() {
745 synchronized (mLock) {
746 if (shouldEnableWakeGestureLp()) {
Jeff Browne07b94b2014-06-18 15:56:27 -0700747 performHapticFeedbackLw(null, HapticFeedbackConstants.VIRTUAL_KEY, false);
Bryce Lee584a4452014-10-21 15:55:55 -0700748 wakeUp(SystemClock.uptimeMillis(), mAllowTheaterModeWakeFromWakeGesture);
Jeff Browna20dda42014-05-27 20:57:24 -0700749 }
750 }
751 }
752 }
753
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800754 class MyOrientationListener extends WindowOrientationListener {
Craig Mautnereee29c42013-01-17 14:44:34 -0800755 MyOrientationListener(Context context, Handler handler) {
756 super(context, handler);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800757 }
Craig Mautner967212c2013-04-13 21:10:58 -0700758
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800759 @Override
Jeff Brownc0347aa2011-09-23 17:26:09 -0700760 public void onProposedRotationChanged(int rotation) {
Craig Mautnereda67292013-04-28 13:50:14 -0700761 if (localLOGV) Slog.v(TAG, "onProposedRotationChanged, rotation=" + rotation);
Jeff Brown01a98dd2011-09-20 15:08:29 -0700762 updateRotation(false);
763 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800764 }
765 MyOrientationListener mOrientationListener;
766
Jorim Jaggi24bec7c2015-02-04 12:40:14 +0100767 private final StatusBarController mStatusBarController = new StatusBarController();
John Spurlock5b9145b2013-08-20 15:13:47 -0400768
John Spurlock27735a42013-08-14 17:57:38 -0400769 private final BarController mNavigationBarController = new BarController("NavigationBar",
John Spurlock5b9145b2013-08-20 15:13:47 -0400770 View.NAVIGATION_BAR_TRANSIENT,
771 View.NAVIGATION_BAR_UNHIDE,
John Spurlockbd957402013-10-03 11:38:39 -0400772 View.NAVIGATION_BAR_TRANSLUCENT,
773 StatusBarManager.WINDOW_NAVIGATION_BAR,
774 WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION);
John Spurlock5b9145b2013-08-20 15:13:47 -0400775
John Spurlockf1a36642013-10-12 17:50:42 -0400776 private ImmersiveModeConfirmation mImmersiveModeConfirmation;
John Spurlock32beb2c2013-03-11 10:16:47 -0400777
Craig Mautner037aa8d2013-06-07 10:35:44 -0700778 private SystemGesturesPointerEventListener mSystemGestures;
John Spurlock32beb2c2013-03-11 10:16:47 -0400779
Dianne Hackborn42e620c2012-06-24 13:20:51 -0700780 IStatusBarService getStatusBarService() {
781 synchronized (mServiceAquireLock) {
782 if (mStatusBarService == null) {
783 mStatusBarService = IStatusBarService.Stub.asInterface(
784 ServiceManager.getService("statusbar"));
785 }
786 return mStatusBarService;
787 }
788 }
789
Suchi Amalapurapua9e1b162009-03-24 22:24:47 -0700790 /*
791 * We always let the sensor be switched on by default except when
792 * the user has explicitly disabled sensor based rotation or when the
793 * screen is switched off.
794 */
The Android Open Source Project0727d222009-03-11 12:11:58 -0700795 boolean needSensorRunningLp() {
Jeff Brownbcdfc622014-03-06 19:13:04 -0800796 if (mSupportAutoRotation) {
797 if (mCurrentAppOrientation == ActivityInfo.SCREEN_ORIENTATION_SENSOR
798 || mCurrentAppOrientation == ActivityInfo.SCREEN_ORIENTATION_FULL_SENSOR
799 || mCurrentAppOrientation == ActivityInfo.SCREEN_ORIENTATION_SENSOR_PORTRAIT
800 || mCurrentAppOrientation == ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE) {
801 // If the application has explicitly requested to follow the
802 // orientation, then we need to turn the sensor on.
803 return true;
804 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800805 }
Dianne Hackborn867ab6472010-04-29 13:28:56 -0700806 if ((mCarDockEnablesAccelerometer && mDockMode == Intent.EXTRA_DOCK_STATE_CAR) ||
Jeff Brown1a693182011-11-08 14:44:16 -0800807 (mDeskDockEnablesAccelerometer && (mDockMode == Intent.EXTRA_DOCK_STATE_DESK
808 || mDockMode == Intent.EXTRA_DOCK_STATE_LE_DESK
809 || mDockMode == Intent.EXTRA_DOCK_STATE_HE_DESK))) {
Mike Lockwoode9867d22009-09-20 01:59:02 -0400810 // enable accelerometer if we are docked in a dock that enables accelerometer
811 // orientation management,
812 return true;
813 }
Jeff Brown207673cd2012-06-05 17:47:11 -0700814 if (mUserRotationMode == USER_ROTATION_LOCKED) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800815 // If the setting for using the sensor by default is enabled, then
816 // we will always leave it on. Note that the user could go to
817 // a window that forces an orientation that does not use the
818 // sensor and in theory we could turn it off... however, when next
819 // turning it on we won't have a good value for the current
820 // orientation for a little bit, which can cause orientation
821 // changes to lag, so we'd like to keep it always on. (It will
822 // still be turned off when the screen is off.)
Suchi Amalapurapua9e1b162009-03-24 22:24:47 -0700823 return false;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800824 }
Jeff Brownbcdfc622014-03-06 19:13:04 -0800825 return mSupportAutoRotation;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800826 }
Craig Mautner46ac6fa2013-08-01 10:06:34 -0700827
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800828 /*
829 * Various use cases for invoking this function
830 * screen turning off, should always disable listeners if already enabled
Craig Mautner46ac6fa2013-08-01 10:06:34 -0700831 * screen turned on and current app has sensor based orientation, enable listeners
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800832 * if not already enabled
833 * screen turned on and current app does not have sensor orientation, disable listeners if
834 * already enabled
835 * screen turning on and current app has sensor based orientation, enable listeners if needed
836 * screen turning on and current app has nosensor based orientation, do nothing
837 */
The Android Open Source Project0727d222009-03-11 12:11:58 -0700838 void updateOrientationListenerLp() {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800839 if (!mOrientationListener.canDetectOrientation()) {
840 // If sensor is turned off or nonexistent for some reason
841 return;
842 }
Stefan Kuhne9326dc12015-06-12 09:25:32 -1000843 // Could have been invoked due to screen turning on or off or
844 // change of the currently visible window's orientation.
Jeff Brown3ee549c2014-09-22 20:14:39 -0700845 if (localLOGV) Slog.v(TAG, "mScreenOnEarly=" + mScreenOnEarly
846 + ", mAwake=" + mAwake + ", mCurrentAppOrientation=" + mCurrentAppOrientation
Stefan Kuhne9326dc12015-06-12 09:25:32 -1000847 + ", mOrientationSensorEnabled=" + mOrientationSensorEnabled
848 + ", mKeyguardDrawComplete=" + mKeyguardDrawComplete
849 + ", mWindowManagerDrawComplete=" + mWindowManagerDrawComplete);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800850 boolean disable = true;
Stefan Kuhne9326dc12015-06-12 09:25:32 -1000851 // Note: We postpone the rotating of the screen until the keyguard as well as the
852 // window manager have reported a draw complete.
853 if (mScreenOnEarly && mAwake &&
854 mKeyguardDrawComplete && mWindowManagerDrawComplete) {
The Android Open Source Project0727d222009-03-11 12:11:58 -0700855 if (needSensorRunningLp()) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800856 disable = false;
857 //enable listener if not already enabled
The Android Open Source Project0727d222009-03-11 12:11:58 -0700858 if (!mOrientationSensorEnabled) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800859 mOrientationListener.enable();
Craig Mautnereda67292013-04-28 13:50:14 -0700860 if(localLOGV) Slog.v(TAG, "Enabling listeners");
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800861 mOrientationSensorEnabled = true;
862 }
Craig Mautner46ac6fa2013-08-01 10:06:34 -0700863 }
864 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800865 //check if sensors need to be disabled
The Android Open Source Project0727d222009-03-11 12:11:58 -0700866 if (disable && mOrientationSensorEnabled) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800867 mOrientationListener.disable();
Craig Mautnereda67292013-04-28 13:50:14 -0700868 if(localLOGV) Slog.v(TAG, "Disabling listeners");
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800869 mOrientationSensorEnabled = false;
870 }
871 }
872
Jeff Brown13f00f02014-10-31 14:45:50 -0700873 private void interceptPowerKeyDown(KeyEvent event, boolean interactive) {
874 // Hold a wake lock until the power key is released.
875 if (!mPowerKeyWakeLock.isHeld()) {
876 mPowerKeyWakeLock.acquire();
877 }
878
879 // Cancel multi-press detection timeout.
880 if (mPowerKeyPressCounter != 0) {
881 mHandler.removeMessages(MSG_POWER_DELAYED_PRESS);
882 }
883
884 // Detect user pressing the power button in panic when an application has
885 // taken over the whole screen.
886 boolean panic = mImmersiveModeConfirmation.onPowerKeyDown(interactive,
Craig Mautner0124980e92014-11-30 21:15:34 -0800887 SystemClock.elapsedRealtime(), isImmersiveMode(mLastSystemUiFlags));
Jeff Brown13f00f02014-10-31 14:45:50 -0700888 if (panic) {
Adrian Roosddc8b272015-05-21 16:28:27 -0700889 mHandler.post(mHiddenNavPanic);
Jeff Brown13f00f02014-10-31 14:45:50 -0700890 }
891
892 // Latch power key state to detect screenshot chord.
893 if (interactive && !mScreenshotChordPowerKeyTriggered
894 && (event.getFlags() & KeyEvent.FLAG_FALLBACK) == 0) {
895 mScreenshotChordPowerKeyTriggered = true;
896 mScreenshotChordPowerKeyTime = event.getDownTime();
897 interceptScreenshotChord();
898 }
899
900 // Stop ringing or end call if configured to do so when power is pressed.
901 TelecomManager telecomManager = getTelecommService();
902 boolean hungUp = false;
903 if (telecomManager != null) {
904 if (telecomManager.isRinging()) {
905 // Pressing Power while there's a ringing incoming
906 // call should silence the ringer.
907 telecomManager.silenceRinger();
908 } else if ((mIncallPowerBehavior
909 & Settings.Secure.INCALL_POWER_BUTTON_BEHAVIOR_HANGUP) != 0
910 && telecomManager.isInCall() && interactive) {
911 // Otherwise, if "Power button ends call" is enabled,
912 // the Power button will hang up any current active call.
913 hungUp = telecomManager.endCall();
914 }
915 }
916
917 // If the power key has still not yet been handled, then detect short
918 // press, long press, or multi press and decide what to do.
919 mPowerKeyHandled = hungUp || mScreenshotChordVolumeDownKeyTriggered
920 || mScreenshotChordVolumeUpKeyTriggered;
921 if (!mPowerKeyHandled) {
922 if (interactive) {
923 // When interactive, we're already awake.
924 // Wait for a long press or for the button to be released to decide what to do.
925 if (hasLongPressOnPowerBehavior()) {
926 Message msg = mHandler.obtainMessage(MSG_POWER_LONG_PRESS);
927 msg.setAsynchronous(true);
928 mHandler.sendMessageDelayed(msg,
929 ViewConfiguration.get(mContext).getDeviceGlobalActionKeyTimeout());
930 }
931 } else {
Bryce Leed9268e32014-11-17 17:40:59 -0800932 wakeUpFromPowerKey(event.getDownTime());
Bryce Leed9268e32014-11-17 17:40:59 -0800933
Bryce Leed3b28402015-03-09 15:49:13 +0000934 if (mSupportLongPressPowerWhenNonInteractive && hasLongPressOnPowerBehavior()) {
935 Message msg = mHandler.obtainMessage(MSG_POWER_LONG_PRESS);
936 msg.setAsynchronous(true);
937 mHandler.sendMessageDelayed(msg,
938 ViewConfiguration.get(mContext).getDeviceGlobalActionKeyTimeout());
Bryce Leed9268e32014-11-17 17:40:59 -0800939 mBeganFromNonInteractive = true;
Bryce Leed3b28402015-03-09 15:49:13 +0000940 } else {
941 final int maxCount = getMaxMultiPressPowerCount();
942
943 if (maxCount <= 1) {
944 mPowerKeyHandled = true;
945 } else {
946 mBeganFromNonInteractive = true;
947 }
Jeff Brown13f00f02014-10-31 14:45:50 -0700948 }
949 }
Jeff Brown4d396052010-10-29 21:50:21 -0700950 }
951 }
952
Jeff Brown13f00f02014-10-31 14:45:50 -0700953 private void interceptPowerKeyUp(KeyEvent event, boolean interactive, boolean canceled) {
954 final boolean handled = canceled || mPowerKeyHandled;
955 mScreenshotChordPowerKeyTriggered = false;
956 cancelPendingScreenshotChordAction();
957 cancelPendingPowerKeyAction();
958
959 if (!handled) {
960 // Figure out how to handle the key now that it has been released.
961 mPowerKeyPressCounter += 1;
962
963 final int maxCount = getMaxMultiPressPowerCount();
964 final long eventTime = event.getDownTime();
965 if (mPowerKeyPressCounter < maxCount) {
966 // This could be a multi-press. Wait a little bit longer to confirm.
967 // Continue holding the wake lock.
968 Message msg = mHandler.obtainMessage(MSG_POWER_DELAYED_PRESS,
969 interactive ? 1 : 0, mPowerKeyPressCounter, eventTime);
970 msg.setAsynchronous(true);
971 mHandler.sendMessageDelayed(msg, ViewConfiguration.getDoubleTapTimeout());
972 return;
973 }
974
975 // No other actions. Handle it immediately.
976 powerPress(eventTime, interactive, mPowerKeyPressCounter);
Jeff Brown4d396052010-10-29 21:50:21 -0700977 }
Jeff Brown13f00f02014-10-31 14:45:50 -0700978
979 // Done. Reset our state.
980 finishPowerKeyPress();
981 }
982
983 private void finishPowerKeyPress() {
Bryce Leed9268e32014-11-17 17:40:59 -0800984 mBeganFromNonInteractive = false;
Jeff Brown13f00f02014-10-31 14:45:50 -0700985 mPowerKeyPressCounter = 0;
986 if (mPowerKeyWakeLock.isHeld()) {
987 mPowerKeyWakeLock.release();
988 }
Jeff Brownd5bb82d2011-10-12 13:57:59 -0700989 }
990
991 private void cancelPendingPowerKeyAction() {
992 if (!mPowerKeyHandled) {
Jeff Brown13f00f02014-10-31 14:45:50 -0700993 mPowerKeyHandled = true;
994 mHandler.removeMessages(MSG_POWER_LONG_PRESS);
Jeff Brownd5bb82d2011-10-12 13:57:59 -0700995 }
Jeff Brown13f00f02014-10-31 14:45:50 -0700996 }
997
998 private void powerPress(long eventTime, boolean interactive, int count) {
999 if (mScreenOnEarly && !mScreenOnFully) {
1000 Slog.i(TAG, "Suppressed redundant power key press while "
1001 + "already in the process of turning the screen on.");
1002 return;
Jeff Brownff204712011-10-25 21:27:54 -07001003 }
Jeff Brown13f00f02014-10-31 14:45:50 -07001004
1005 if (count == 2) {
1006 powerMultiPressAction(eventTime, interactive, mDoublePressOnPowerBehavior);
1007 } else if (count == 3) {
1008 powerMultiPressAction(eventTime, interactive, mTriplePressOnPowerBehavior);
Bryce Leed9268e32014-11-17 17:40:59 -08001009 } else if (interactive && !mBeganFromNonInteractive) {
Jeff Brown13f00f02014-10-31 14:45:50 -07001010 switch (mShortPressOnPowerBehavior) {
1011 case SHORT_PRESS_POWER_NOTHING:
1012 break;
1013 case SHORT_PRESS_POWER_GO_TO_SLEEP:
1014 mPowerManager.goToSleep(eventTime,
1015 PowerManager.GO_TO_SLEEP_REASON_POWER_BUTTON, 0);
1016 break;
1017 case SHORT_PRESS_POWER_REALLY_GO_TO_SLEEP:
1018 mPowerManager.goToSleep(eventTime,
1019 PowerManager.GO_TO_SLEEP_REASON_POWER_BUTTON,
1020 PowerManager.GO_TO_SLEEP_FLAG_NO_DOZE);
1021 break;
1022 case SHORT_PRESS_POWER_REALLY_GO_TO_SLEEP_AND_GO_HOME:
1023 mPowerManager.goToSleep(eventTime,
1024 PowerManager.GO_TO_SLEEP_REASON_POWER_BUTTON,
1025 PowerManager.GO_TO_SLEEP_FLAG_NO_DOZE);
1026 launchHomeFromHotKey();
1027 break;
Bryce Lee01b0c5f2015-02-05 18:24:04 -08001028 case SHORT_PRESS_POWER_GO_HOME:
Bryce Lee662ed802015-04-10 20:11:39 +00001029 launchHomeFromHotKey(true /* awakenFromDreams */, false /*respectKeyguard*/);
Bryce Lee01b0c5f2015-02-05 18:24:04 -08001030 break;
Jeff Brown13f00f02014-10-31 14:45:50 -07001031 }
1032 }
1033 }
1034
1035 private void powerMultiPressAction(long eventTime, boolean interactive, int behavior) {
1036 switch (behavior) {
1037 case MULTI_PRESS_POWER_NOTHING:
1038 break;
1039 case MULTI_PRESS_POWER_THEATER_MODE:
1040 if (isTheaterModeEnabled()) {
1041 Slog.i(TAG, "Toggling theater mode off.");
1042 Settings.Global.putInt(mContext.getContentResolver(),
1043 Settings.Global.THEATER_MODE_ON, 0);
1044 if (!interactive) {
1045 wakeUpFromPowerKey(eventTime);
1046 }
1047 } else {
1048 Slog.i(TAG, "Toggling theater mode on.");
1049 Settings.Global.putInt(mContext.getContentResolver(),
1050 Settings.Global.THEATER_MODE_ON, 1);
Bryce Lee55e846d2014-11-04 12:43:44 -08001051
1052 if (mGoToSleepOnButtonPressTheaterMode && interactive) {
Jeff Brown13f00f02014-10-31 14:45:50 -07001053 mPowerManager.goToSleep(eventTime,
1054 PowerManager.GO_TO_SLEEP_REASON_POWER_BUTTON, 0);
1055 }
1056 }
1057 break;
1058 case MULTI_PRESS_POWER_BRIGHTNESS_BOOST:
Jeff Brown7b5be5e2014-11-12 18:45:31 -08001059 Slog.i(TAG, "Starting brightness boost.");
1060 if (!interactive) {
1061 wakeUpFromPowerKey(eventTime);
1062 }
Jeff Brown13f00f02014-10-31 14:45:50 -07001063 mPowerManager.boostScreenBrightness(eventTime);
1064 break;
1065 }
1066 }
1067
1068 private int getMaxMultiPressPowerCount() {
1069 if (mTriplePressOnPowerBehavior != MULTI_PRESS_POWER_NOTHING) {
1070 return 3;
1071 }
1072 if (mDoublePressOnPowerBehavior != MULTI_PRESS_POWER_NOTHING) {
1073 return 2;
1074 }
1075 return 1;
1076 }
1077
1078 private void powerLongPress() {
1079 final int behavior = getResolvedLongPressOnPowerBehavior();
1080 switch (behavior) {
1081 case LONG_PRESS_POWER_NOTHING:
1082 break;
1083 case LONG_PRESS_POWER_GLOBAL_ACTIONS:
1084 mPowerKeyHandled = true;
1085 if (!performHapticFeedbackLw(null, HapticFeedbackConstants.LONG_PRESS, false)) {
1086 performAuditoryFeedbackForAccessibilityIfNeed();
1087 }
1088 showGlobalActionsInternal();
1089 break;
1090 case LONG_PRESS_POWER_SHUT_OFF:
1091 case LONG_PRESS_POWER_SHUT_OFF_NO_CONFIRM:
1092 mPowerKeyHandled = true;
1093 performHapticFeedbackLw(null, HapticFeedbackConstants.LONG_PRESS, false);
1094 sendCloseSystemWindows(SYSTEM_DIALOG_REASON_GLOBAL_ACTIONS);
1095 mWindowManagerFuncs.shutdown(behavior == LONG_PRESS_POWER_SHUT_OFF);
1096 break;
1097 }
1098 }
1099
Nick Vaccarob593a812015-05-15 11:23:05 -07001100 private void sleepPress(long eventTime) {
1101 if (mShortPressOnSleepBehavior == SHORT_PRESS_SLEEP_GO_TO_SLEEP_AND_GO_HOME) {
1102 launchHomeFromHotKey(false /* awakenDreams */, true /*respectKeyguard*/);
1103 }
1104 }
1105
1106 private void sleepRelease(long eventTime) {
Filip Gruszczynskia483a1d2015-03-17 19:06:58 +00001107 switch (mShortPressOnSleepBehavior) {
1108 case SHORT_PRESS_SLEEP_GO_TO_SLEEP:
Filip Gruszczynskia483a1d2015-03-17 19:06:58 +00001109 case SHORT_PRESS_SLEEP_GO_TO_SLEEP_AND_GO_HOME:
Nick Vaccarob593a812015-05-15 11:23:05 -07001110 Slog.i(TAG, "sleepRelease() calling goToSleep(GO_TO_SLEEP_REASON_SLEEP_BUTTON)");
1111 mPowerManager.goToSleep(eventTime,
1112 PowerManager.GO_TO_SLEEP_REASON_SLEEP_BUTTON, 0);
Filip Gruszczynskia483a1d2015-03-17 19:06:58 +00001113 break;
1114 }
1115 }
1116
Jeff Brown13f00f02014-10-31 14:45:50 -07001117 private int getResolvedLongPressOnPowerBehavior() {
1118 if (FactoryTest.isLongPressOnPowerOffEnabled()) {
1119 return LONG_PRESS_POWER_SHUT_OFF_NO_CONFIRM;
1120 }
1121 return mLongPressOnPowerBehavior;
1122 }
1123
1124 private boolean hasLongPressOnPowerBehavior() {
1125 return getResolvedLongPressOnPowerBehavior() != LONG_PRESS_POWER_NOTHING;
Jeff Brownd5bb82d2011-10-12 13:57:59 -07001126 }
1127
1128 private void interceptScreenshotChord() {
Christopher Tatee90585f2012-03-05 18:56:25 -08001129 if (mScreenshotChordEnabled
Jeff Brown13f00f02014-10-31 14:45:50 -07001130 && mScreenshotChordVolumeDownKeyTriggered && mScreenshotChordPowerKeyTriggered
1131 && !mScreenshotChordVolumeUpKeyTriggered) {
Jeff Brownd5bb82d2011-10-12 13:57:59 -07001132 final long now = SystemClock.uptimeMillis();
Jeff Brown13f00f02014-10-31 14:45:50 -07001133 if (now <= mScreenshotChordVolumeDownKeyTime + SCREENSHOT_CHORD_DEBOUNCE_DELAY_MILLIS
1134 && now <= mScreenshotChordPowerKeyTime
1135 + SCREENSHOT_CHORD_DEBOUNCE_DELAY_MILLIS) {
1136 mScreenshotChordVolumeDownKeyConsumed = true;
Jeff Brownd5bb82d2011-10-12 13:57:59 -07001137 cancelPendingPowerKeyAction();
1138
Jeff Sharkey2991fa32012-12-05 18:06:43 -08001139 mHandler.postDelayed(mScreenshotRunnable, getScreenshotChordLongPressDelay());
Jeff Brownd5bb82d2011-10-12 13:57:59 -07001140 }
1141 }
1142 }
1143
Winson Chung1cea2f32012-10-08 20:42:01 -07001144 private long getScreenshotChordLongPressDelay() {
Jim Miller5ecd8112013-01-09 18:50:26 -08001145 if (mKeyguardDelegate.isShowing()) {
Winson Chung1cea2f32012-10-08 20:42:01 -07001146 // Double the time it takes to take a screenshot from the keyguard
1147 return (long) (KEYGUARD_SCREENSHOT_CHORD_DELAY_MULTIPLIER *
Justin Kohfeabd2c2014-05-02 10:02:44 -07001148 ViewConfiguration.get(mContext).getDeviceGlobalActionKeyTimeout());
Winson Chung1cea2f32012-10-08 20:42:01 -07001149 }
Justin Kohfeabd2c2014-05-02 10:02:44 -07001150 return ViewConfiguration.get(mContext).getDeviceGlobalActionKeyTimeout();
Winson Chung1cea2f32012-10-08 20:42:01 -07001151 }
1152
Jeff Brownd5bb82d2011-10-12 13:57:59 -07001153 private void cancelPendingScreenshotChordAction() {
Jeff Sharkey2991fa32012-12-05 18:06:43 -08001154 mHandler.removeCallbacks(mScreenshotRunnable);
Jeff Brown4d396052010-10-29 21:50:21 -07001155 }
1156
Jeff Brown13f00f02014-10-31 14:45:50 -07001157 private final Runnable mEndCallLongPress = new Runnable() {
Craig Mautnerf1b67412012-09-19 13:18:29 -07001158 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001159 public void run() {
Jeff Brown13f00f02014-10-31 14:45:50 -07001160 mEndCallKeyHandled = true;
1161 if (!performHapticFeedbackLw(null, HapticFeedbackConstants.LONG_PRESS, false)) {
1162 performAuditoryFeedbackForAccessibilityIfNeed();
Joe Onoratod208e702010-10-08 16:22:43 -04001163 }
Jeff Brown13f00f02014-10-31 14:45:50 -07001164 showGlobalActionsInternal();
Jeff Brownd5bb82d2011-10-12 13:57:59 -07001165 }
1166 };
1167
Jeff Sharkey2991fa32012-12-05 18:06:43 -08001168 private final Runnable mScreenshotRunnable = new Runnable() {
Craig Mautner0bf6ec92012-12-18 08:33:27 -08001169 @Override
Jeff Brownd5bb82d2011-10-12 13:57:59 -07001170 public void run() {
1171 takeScreenshot();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001172 }
1173 };
1174
Alan Viverettee34560b22014-07-10 14:50:06 -07001175 @Override
1176 public void showGlobalActions() {
1177 mHandler.removeMessages(MSG_DISPATCH_SHOW_GLOBAL_ACTIONS);
1178 mHandler.sendEmptyMessage(MSG_DISPATCH_SHOW_GLOBAL_ACTIONS);
1179 }
1180
1181 void showGlobalActionsInternal() {
1182 sendCloseSystemWindows(SYSTEM_DIALOG_REASON_GLOBAL_ACTIONS);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001183 if (mGlobalActions == null) {
Jeff Brown7304c342012-05-11 18:42:42 -07001184 mGlobalActions = new GlobalActions(mContext, mWindowManagerFuncs);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001185 }
Jim Millerab954542014-10-10 18:21:49 -07001186 final boolean keyguardShowing = isKeyguardShowingAndNotOccluded();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001187 mGlobalActions.showDialog(keyguardShowing, isDeviceProvisioned());
1188 if (keyguardShowing) {
1189 // since it took two seconds of long press to bring this up,
1190 // poke the wake lock so they have some time to see the dialog.
Jim Miller25190572013-02-28 17:36:24 -08001191 mPowerManager.userActivity(SystemClock.uptimeMillis(), false);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001192 }
1193 }
1194
1195 boolean isDeviceProvisioned() {
Jeff Brownbf6f6f92012-09-25 15:03:20 -07001196 return Settings.Global.getInt(
1197 mContext.getContentResolver(), Settings.Global.DEVICE_PROVISIONED, 0) != 0;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001198 }
1199
Maurice Lam99c6e072014-04-28 18:24:28 -07001200 boolean isUserSetupComplete() {
1201 return Settings.Secure.getIntForUser(mContext.getContentResolver(),
1202 Settings.Secure.USER_SETUP_COMPLETE, 0, UserHandle.USER_CURRENT) != 0;
1203 }
1204
Jeff Brown13f00f02014-10-31 14:45:50 -07001205 private void handleShortPressOnHome() {
1206 // If there's a dream running then use home to escape the dream
1207 // but don't actually go home.
1208 if (mDreamManagerInternal != null && mDreamManagerInternal.isDreaming()) {
1209 mDreamManagerInternal.stopDream(false /*immediate*/);
1210 return;
1211 }
1212
1213 // Go home!
1214 launchHomeFromHotKey();
1215 }
1216
Tim Kilbourn0e5f1102015-06-05 16:18:09 -07001217 private void handleLongPressOnHome(int deviceId) {
Joe Onorato46b0d682010-11-22 17:37:27 -08001218 if (mLongPressOnHomeBehavior != LONG_PRESS_HOME_NOTHING) {
Jeff Browncaca8812013-05-09 13:34:33 -07001219 mHomeConsumed = true;
Joe Onorato46b0d682010-11-22 17:37:27 -08001220 performHapticFeedbackLw(null, HapticFeedbackConstants.LONG_PRESS, false);
Patrick Dubroyece94522011-02-23 18:35:01 -08001221
Jeff Browncaca8812013-05-09 13:34:33 -07001222 if (mLongPressOnHomeBehavior == LONG_PRESS_HOME_RECENT_SYSTEM_UI) {
1223 toggleRecentApps();
1224 } else if (mLongPressOnHomeBehavior == LONG_PRESS_HOME_ASSIST) {
Tim Kilbourn0e5f1102015-06-05 16:18:09 -07001225 launchAssistAction(null, deviceId);
Jim Millere6ad1a82010-08-20 19:25:39 -07001226 }
1227 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001228 }
Patrick Dubroyece94522011-02-23 18:35:01 -08001229
Jeff Browncaca8812013-05-09 13:34:33 -07001230 private void handleDoubleTapOnHome() {
1231 if (mDoubleTapOnHomeBehavior == DOUBLE_TAP_HOME_RECENT_SYSTEM_UI) {
1232 mHomeConsumed = true;
1233 toggleRecentApps();
1234 }
1235 }
1236
1237 private final Runnable mHomeDoubleTapTimeoutRunnable = new Runnable() {
1238 @Override
1239 public void run() {
1240 if (mHomeDoubleTapPending) {
1241 mHomeDoubleTapPending = false;
Jeff Brown13f00f02014-10-31 14:45:50 -07001242 handleShortPressOnHome();
Jeff Browncaca8812013-05-09 13:34:33 -07001243 }
1244 }
1245 };
1246
Mark Renoufc1256912015-03-11 14:38:23 -04001247 private boolean isRoundWindow() {
Adam Powell01f280d2015-05-18 16:07:42 -07001248 return mContext.getResources().getConfiguration().isScreenRound();
Mark Renoufc1256912015-03-11 14:38:23 -04001249 }
1250
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001251 /** {@inheritDoc} */
Craig Mautner0bf6ec92012-12-18 08:33:27 -08001252 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001253 public void init(Context context, IWindowManager windowManager,
Jeff Brown96307042012-07-27 15:51:34 -07001254 WindowManagerFuncs windowManagerFuncs) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001255 mContext = context;
1256 mWindowManager = windowManager;
Dianne Hackborndf89e652011-10-06 22:35:11 -07001257 mWindowManagerFuncs = windowManagerFuncs;
Craig Mautner8a0da012014-05-31 15:13:37 -07001258 mWindowManagerInternal = LocalServices.getService(WindowManagerInternal.class);
Jeff Brown061ea992015-04-17 19:55:47 -07001259 mActivityManagerInternal = LocalServices.getService(ActivityManagerInternal.class);
Jose Lima9546b202014-07-02 17:21:51 -07001260 mDreamManagerInternal = LocalServices.getService(DreamManagerInternal.class);
Billy Laucbe540f2015-06-25 01:51:44 +01001261 mAppOpsManager = (AppOpsManager) mContext.getSystemService(Context.APP_OPS_SERVICE);
Mark Renoufc1256912015-03-11 14:38:23 -04001262
1263 // Init display burn-in protection
1264 boolean burnInProtectionEnabled = context.getResources().getBoolean(
1265 com.android.internal.R.bool.config_enableBurnInProtection);
1266 // Allow a system property to override this. Used by developer settings.
1267 boolean burnInProtectionDevMode =
1268 SystemProperties.getBoolean("persist.debug.force_burn_in", false);
1269 if (burnInProtectionEnabled || burnInProtectionDevMode) {
1270 final int minHorizontal;
1271 final int maxHorizontal;
1272 final int minVertical;
1273 final int maxVertical;
1274 final int maxRadius;
1275 if (burnInProtectionDevMode) {
1276 minHorizontal = -8;
1277 maxHorizontal = 8;
1278 minVertical = -8;
1279 maxVertical = -4;
1280 maxRadius = (isRoundWindow()) ? 6 : -1;
1281 } else {
1282 Resources resources = context.getResources();
1283 minHorizontal = resources.getInteger(
1284 com.android.internal.R.integer.config_burnInProtectionMinHorizontalOffset);
1285 maxHorizontal = resources.getInteger(
1286 com.android.internal.R.integer.config_burnInProtectionMaxHorizontalOffset);
1287 minVertical = resources.getInteger(
1288 com.android.internal.R.integer.config_burnInProtectionMinVerticalOffset);
1289 maxVertical = resources.getInteger(
1290 com.android.internal.R.integer.config_burnInProtectionMaxVerticalOffset);
1291 maxRadius = resources.getInteger(
1292 com.android.internal.R.integer.config_burnInProtectionMaxRadius);
1293 }
1294 mBurnInProtectionHelper = new BurnInProtectionHelper(
1295 context, minHorizontal, maxHorizontal, minVertical, maxVertical, maxRadius);
Filip Gruszczynskicfb31852015-02-25 21:47:12 +00001296 }
Craig Mautner8a0da012014-05-31 15:13:37 -07001297
Jeff Brown70825162012-03-28 17:27:48 -07001298 mHandler = new PolicyHandler();
Jeff Browna20dda42014-05-27 20:57:24 -07001299 mWakeGestureListener = new MyWakeGestureListener(mContext, mHandler);
Craig Mautnereee29c42013-01-17 14:44:34 -08001300 mOrientationListener = new MyOrientationListener(mContext, mHandler);
Jeff Brownc0347aa2011-09-23 17:26:09 -07001301 try {
1302 mOrientationListener.setCurrentRotation(windowManager.getRotation());
1303 } catch (RemoteException ex) { }
Christopher Tate5e08af02012-09-21 17:17:22 -07001304 mSettingsObserver = new SettingsObserver(mHandler);
1305 mSettingsObserver.observe();
Svetoslav683914b2015-01-15 14:22:26 -08001306 mShortcutManager = new ShortcutManager(context);
Daniel Sandler6396c722013-04-16 20:19:09 -04001307 mUiMode = context.getResources().getInteger(
1308 com.android.internal.R.integer.config_defaultUiModeType);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001309 mHomeIntent = new Intent(Intent.ACTION_MAIN, null);
1310 mHomeIntent.addCategory(Intent.CATEGORY_HOME);
1311 mHomeIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK
1312 | Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED);
Dianne Hackborn39c2d712009-09-22 11:41:31 -07001313 mCarDockIntent = new Intent(Intent.ACTION_MAIN, null);
1314 mCarDockIntent.addCategory(Intent.CATEGORY_CAR_DOCK);
1315 mCarDockIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK
1316 | Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED);
1317 mDeskDockIntent = new Intent(Intent.ACTION_MAIN, null);
1318 mDeskDockIntent.addCategory(Intent.CATEGORY_DESK_DOCK);
1319 mDeskDockIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK
1320 | Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED);
Jim Millere6ad1a82010-08-20 19:25:39 -07001321
Jeff Brown96307042012-07-27 15:51:34 -07001322 mPowerManager = (PowerManager)context.getSystemService(Context.POWER_SERVICE);
1323 mBroadcastWakeLock = mPowerManager.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK,
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001324 "PhoneWindowManager.mBroadcastWakeLock");
Jeff Brown13f00f02014-10-31 14:45:50 -07001325 mPowerKeyWakeLock = mPowerManager.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK,
1326 "PhoneWindowManager.mPowerKeyWakeLock");
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001327 mEnableShiftMenuBugReports = "1".equals(SystemProperties.get("ro.debuggable"));
Jeff Brownbcdfc622014-03-06 19:13:04 -08001328 mSupportAutoRotation = mContext.getResources().getBoolean(
1329 com.android.internal.R.bool.config_supportAutoRotation);
Dianne Hackborn2862fff2009-09-15 22:56:29 -07001330 mLidOpenRotation = readRotation(
Mike Lockwood2d1efbd2009-09-16 12:15:53 -04001331 com.android.internal.R.integer.config_lidOpenRotation);
1332 mCarDockRotation = readRotation(
1333 com.android.internal.R.integer.config_carDockRotation);
1334 mDeskDockRotation = readRotation(
1335 com.android.internal.R.integer.config_deskDockRotation);
Jeff Brownc82c89ed2013-04-17 17:18:15 -07001336 mUndockedHdmiRotation = readRotation(
1337 com.android.internal.R.integer.config_undockedHdmiRotation);
Mike Lockwoode9867d22009-09-20 01:59:02 -04001338 mCarDockEnablesAccelerometer = mContext.getResources().getBoolean(
1339 com.android.internal.R.bool.config_carDockEnablesAccelerometer);
1340 mDeskDockEnablesAccelerometer = mContext.getResources().getBoolean(
1341 com.android.internal.R.bool.config_deskDockEnablesAccelerometer);
Dianne Hackborn2862fff2009-09-15 22:56:29 -07001342 mLidKeyboardAccessibility = mContext.getResources().getInteger(
1343 com.android.internal.R.integer.config_lidKeyboardAccessibility);
1344 mLidNavigationAccessibility = mContext.getResources().getInteger(
1345 com.android.internal.R.integer.config_lidNavigationAccessibility);
Jeff Brownc458ce92012-04-30 14:58:40 -07001346 mLidControlsSleep = mContext.getResources().getBoolean(
1347 com.android.internal.R.bool.config_lidControlsSleep);
Daniel Sandlerdd73ee42013-10-11 22:19:59 -04001348 mTranslucentDecorEnabled = mContext.getResources().getBoolean(
1349 com.android.internal.R.bool.config_enableTranslucentDecor);
Bryce Lee584a4452014-10-21 15:55:55 -07001350
1351 mAllowTheaterModeWakeFromKey = mContext.getResources().getBoolean(
1352 com.android.internal.R.bool.config_allowTheaterModeWakeFromKey);
1353 mAllowTheaterModeWakeFromPowerKey = mAllowTheaterModeWakeFromKey
1354 || mContext.getResources().getBoolean(
1355 com.android.internal.R.bool.config_allowTheaterModeWakeFromPowerKey);
1356 mAllowTheaterModeWakeFromMotion = mContext.getResources().getBoolean(
1357 com.android.internal.R.bool.config_allowTheaterModeWakeFromMotion);
Bryce Lee812d7022014-11-10 13:33:28 -08001358 mAllowTheaterModeWakeFromMotionWhenNotDreaming = mContext.getResources().getBoolean(
1359 com.android.internal.R.bool.config_allowTheaterModeWakeFromMotionWhenNotDreaming);
Bryce Lee584a4452014-10-21 15:55:55 -07001360 mAllowTheaterModeWakeFromCameraLens = mContext.getResources().getBoolean(
1361 com.android.internal.R.bool.config_allowTheaterModeWakeFromCameraLens);
1362 mAllowTheaterModeWakeFromLidSwitch = mContext.getResources().getBoolean(
1363 com.android.internal.R.bool.config_allowTheaterModeWakeFromLidSwitch);
1364 mAllowTheaterModeWakeFromWakeGesture = mContext.getResources().getBoolean(
1365 com.android.internal.R.bool.config_allowTheaterModeWakeFromGesture);
1366
Bryce Lee55e846d2014-11-04 12:43:44 -08001367 mGoToSleepOnButtonPressTheaterMode = mContext.getResources().getBoolean(
1368 com.android.internal.R.bool.config_goToSleepOnButtonPressTheaterMode);
1369
Bryce Leed3b28402015-03-09 15:49:13 +00001370 mSupportLongPressPowerWhenNonInteractive = mContext.getResources().getBoolean(
1371 com.android.internal.R.bool.config_supportLongPressPowerWhenNonInteractive);
1372
Jeff Brown13f00f02014-10-31 14:45:50 -07001373 mShortPressOnPowerBehavior = mContext.getResources().getInteger(
1374 com.android.internal.R.integer.config_shortPressOnPowerBehavior);
1375 mLongPressOnPowerBehavior = mContext.getResources().getInteger(
1376 com.android.internal.R.integer.config_longPressOnPowerBehavior);
1377 mDoublePressOnPowerBehavior = mContext.getResources().getInteger(
1378 com.android.internal.R.integer.config_doublePressOnPowerBehavior);
1379 mTriplePressOnPowerBehavior = mContext.getResources().getInteger(
1380 com.android.internal.R.integer.config_triplePressOnPowerBehavior);
Filip Gruszczynskia483a1d2015-03-17 19:06:58 +00001381 mShortPressOnSleepBehavior = mContext.getResources().getInteger(
1382 com.android.internal.R.integer.config_shortPressOnSleepBehavior);
Jeff Brown13f00f02014-10-31 14:45:50 -07001383
John Spurlock61560172015-02-06 19:46:04 -05001384 mUseTvRouting = AudioSystem.getPlatformType(mContext) == AudioSystem.PLATFORM_TELEVISION;
RoboErik001c59c2015-01-26 15:53:51 -08001385
Jeff Brownf71343d2013-05-31 17:59:11 -07001386 readConfigurationDependentBehaviors();
Jeff Browncaca8812013-05-09 13:34:33 -07001387
Svetoslav8e3feb12014-02-24 13:46:47 -08001388 mAccessibilityManager = (AccessibilityManager) context.getSystemService(
1389 Context.ACCESSIBILITY_SERVICE);
1390
Mike Lockwood1753f7f2009-08-24 14:49:07 -07001391 // register for dock events
Dianne Hackborn78968392010-03-04 20:47:56 -08001392 IntentFilter filter = new IntentFilter();
1393 filter.addAction(UiModeManager.ACTION_ENTER_CAR_MODE);
1394 filter.addAction(UiModeManager.ACTION_EXIT_CAR_MODE);
1395 filter.addAction(UiModeManager.ACTION_ENTER_DESK_MODE);
1396 filter.addAction(UiModeManager.ACTION_EXIT_DESK_MODE);
Dianne Hackborn867ab6472010-04-29 13:28:56 -07001397 filter.addAction(Intent.ACTION_DOCK_EVENT);
1398 Intent intent = context.registerReceiver(mDockReceiver, filter);
1399 if (intent != null) {
1400 // Retrieve current sticky dock event broadcast.
1401 mDockMode = intent.getIntExtra(Intent.EXTRA_DOCK_STATE,
1402 Intent.EXTRA_DOCK_STATE_UNDOCKED);
1403 }
Daniel Sandler7e37df52011-11-16 22:08:23 -08001404
Jeff Brown6aaf2952012-10-05 16:01:08 -07001405 // register for dream-related broadcasts
1406 filter = new IntentFilter();
1407 filter.addAction(Intent.ACTION_DREAMING_STARTED);
1408 filter.addAction(Intent.ACTION_DREAMING_STOPPED);
1409 context.registerReceiver(mDreamReceiver, filter);
1410
Christopher Tate5e08af02012-09-21 17:17:22 -07001411 // register for multiuser-relevant broadcasts
1412 filter = new IntentFilter(Intent.ACTION_USER_SWITCHED);
1413 context.registerReceiver(mMultiuserReceiver, filter);
1414
John Spurlock57306e62013-04-22 09:48:49 -04001415 // monitor for system gestures
Craig Mautner037aa8d2013-06-07 10:35:44 -07001416 mSystemGestures = new SystemGesturesPointerEventListener(context,
1417 new SystemGesturesPointerEventListener.Callbacks() {
John Spurlock57306e62013-04-22 09:48:49 -04001418 @Override
1419 public void onSwipeFromTop() {
John Spurlock04db1762013-05-13 12:46:41 -04001420 if (mStatusBar != null) {
John Spurlocke1f366f2013-08-05 12:22:40 -04001421 requestTransientBars(mStatusBar);
John Spurlock04db1762013-05-13 12:46:41 -04001422 }
John Spurlockad3e6cb2013-04-30 08:47:43 -04001423 }
1424 @Override
1425 public void onSwipeFromBottom() {
John Spurlock04db1762013-05-13 12:46:41 -04001426 if (mNavigationBar != null && mNavigationBarOnBottom) {
John Spurlocke1f366f2013-08-05 12:22:40 -04001427 requestTransientBars(mNavigationBar);
John Spurlockad3e6cb2013-04-30 08:47:43 -04001428 }
1429 }
1430 @Override
1431 public void onSwipeFromRight() {
John Spurlock04db1762013-05-13 12:46:41 -04001432 if (mNavigationBar != null && !mNavigationBarOnBottom) {
John Spurlocke1f366f2013-08-05 12:22:40 -04001433 requestTransientBars(mNavigationBar);
John Spurlockad3e6cb2013-04-30 08:47:43 -04001434 }
1435 }
1436 @Override
1437 public void onDebug() {
John Spurlockd67ec252013-09-05 11:31:54 -04001438 // no-op
John Spurlockad3e6cb2013-04-30 08:47:43 -04001439 }
Adrian Roos3595be42015-03-05 16:31:15 +01001440 @Override
1441 public void onDown() {
1442 mOrientationListener.onTouchStart();
1443 }
1444 @Override
1445 public void onUpOrCancel() {
1446 mOrientationListener.onTouchEnd();
1447 }
John Spurlockad3e6cb2013-04-30 08:47:43 -04001448 });
John Spurlockf1a36642013-10-12 17:50:42 -04001449 mImmersiveModeConfirmation = new ImmersiveModeConfirmation(mContext);
Craig Mautner037aa8d2013-06-07 10:35:44 -07001450 mWindowManagerFuncs.registerPointerEventListener(mSystemGestures);
John Spurlock32beb2c2013-03-11 10:16:47 -04001451
Jeff Brownc2346132012-04-13 01:55:38 -07001452 mVibrator = (Vibrator)context.getSystemService(Context.VIBRATOR_SERVICE);
Dianne Hackbornb1a79802009-09-29 15:18:31 -07001453 mLongPressVibePattern = getLongIntArray(mContext.getResources(),
1454 com.android.internal.R.array.config_longPressVibePattern);
1455 mVirtualKeyVibePattern = getLongIntArray(mContext.getResources(),
1456 com.android.internal.R.array.config_virtualKeyVibePattern);
Amith Yamasanic33cb712010-02-10 15:21:49 -08001457 mKeyboardTapVibePattern = getLongIntArray(mContext.getResources(),
1458 com.android.internal.R.array.config_keyboardTapVibePattern);
Fabrice Di Meglioeeff63a2013-08-05 12:07:24 -07001459 mClockTickVibePattern = getLongIntArray(mContext.getResources(),
1460 com.android.internal.R.array.config_clockTickVibePattern);
Fabrice Di Megliobd9152f2013-10-01 11:21:31 -07001461 mCalendarDateVibePattern = getLongIntArray(mContext.getResources(),
1462 com.android.internal.R.array.config_calendarDateVibePattern);
Dianne Hackbornb1a79802009-09-29 15:18:31 -07001463 mSafeModeDisabledVibePattern = getLongIntArray(mContext.getResources(),
1464 com.android.internal.R.array.config_safeModeDisabledVibePattern);
1465 mSafeModeEnabledVibePattern = getLongIntArray(mContext.getResources(),
1466 com.android.internal.R.array.config_safeModeEnabledVibePattern);
Mady Mellore8608912015-06-05 09:02:55 -07001467 mContextClickVibePattern = getLongIntArray(mContext.getResources(),
1468 com.android.internal.R.array.config_contextClickVibePattern);
Daniel Sandler40427442010-07-16 11:44:52 -04001469
Christopher Tatee90585f2012-03-05 18:56:25 -08001470 mScreenshotChordEnabled = mContext.getResources().getBoolean(
1471 com.android.internal.R.bool.config_enableScreenshotChord);
1472
Justin Kohd378ad72013-04-01 12:18:26 -07001473 mGlobalKeyManager = new GlobalKeyManager(mContext);
1474
Joe Onoratoea495d42011-04-06 11:41:11 -07001475 // Controls rotation and the like.
1476 initializeHdmiState();
Dianne Hackborn40011092011-09-22 13:37:48 -07001477
1478 // Match current screen state.
Craig Mautnera631d492014-08-05 15:16:01 -07001479 if (!mPowerManager.isInteractive()) {
Jeff Brown416c49c2015-05-26 19:50:18 -07001480 startedGoingToSleep(WindowManagerPolicy.OFF_BECAUSE_OF_USER);
1481 finishedGoingToSleep(WindowManagerPolicy.OFF_BECAUSE_OF_USER);
Dianne Hackborn40011092011-09-22 13:37:48 -07001482 }
Jorim Jaggi24bec7c2015-02-04 12:40:14 +01001483
1484 mWindowManagerInternal.registerAppTransitionListener(
1485 mStatusBarController.getAppTransitionListener());
Mike Lockwood1753f7f2009-08-24 14:49:07 -07001486 }
1487
Jeff Brownf71343d2013-05-31 17:59:11 -07001488 /**
1489 * Read values from config.xml that may be overridden depending on
1490 * the configuration of the device.
1491 * eg. Disable long press on home goes to recents on sw600dp.
1492 */
1493 private void readConfigurationDependentBehaviors() {
1494 mLongPressOnHomeBehavior = mContext.getResources().getInteger(
1495 com.android.internal.R.integer.config_longPressOnHomeBehavior);
1496 if (mLongPressOnHomeBehavior < LONG_PRESS_HOME_NOTHING ||
1497 mLongPressOnHomeBehavior > LONG_PRESS_HOME_ASSIST) {
1498 mLongPressOnHomeBehavior = LONG_PRESS_HOME_NOTHING;
1499 }
1500
1501 mDoubleTapOnHomeBehavior = mContext.getResources().getInteger(
1502 com.android.internal.R.integer.config_doubleTapOnHomeBehavior);
1503 if (mDoubleTapOnHomeBehavior < DOUBLE_TAP_HOME_NOTHING ||
1504 mDoubleTapOnHomeBehavior > DOUBLE_TAP_HOME_RECENT_SYSTEM_UI) {
1505 mDoubleTapOnHomeBehavior = LONG_PRESS_HOME_NOTHING;
1506 }
1507 }
1508
Craig Mautner0bf6ec92012-12-18 08:33:27 -08001509 @Override
Dianne Hackborndde331c2012-08-03 14:01:57 -07001510 public void setInitialDisplaySize(Display display, int width, int height, int density) {
Jeff Brownef981a42013-08-07 14:13:37 -07001511 // This method might be called before the policy has been fully initialized
1512 // or for other displays we don't care about.
1513 if (mContext == null || display.getDisplayId() != Display.DEFAULT_DISPLAY) {
1514 return;
Dianne Hackbornc652de82013-02-15 16:32:56 -08001515 }
Dianne Hackbornf87d1962012-04-04 12:48:24 -07001516 mDisplay = display;
1517
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001518 final Resources res = mContext.getResources();
Dianne Hackbornf87d1962012-04-04 12:48:24 -07001519 int shortSize, longSize;
Dianne Hackborn9d132642011-04-21 17:26:39 -07001520 if (width > height) {
Dianne Hackborn81e56d52011-05-26 00:55:58 -07001521 shortSize = height;
Dianne Hackbornf87d1962012-04-04 12:48:24 -07001522 longSize = width;
Dianne Hackborn9d132642011-04-21 17:26:39 -07001523 mLandscapeRotation = Surface.ROTATION_0;
1524 mSeascapeRotation = Surface.ROTATION_180;
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001525 if (res.getBoolean(com.android.internal.R.bool.config_reverseDefaultRotation)) {
Dianne Hackborn9d132642011-04-21 17:26:39 -07001526 mPortraitRotation = Surface.ROTATION_90;
1527 mUpsideDownRotation = Surface.ROTATION_270;
1528 } else {
1529 mPortraitRotation = Surface.ROTATION_270;
1530 mUpsideDownRotation = Surface.ROTATION_90;
1531 }
1532 } else {
Dianne Hackborn81e56d52011-05-26 00:55:58 -07001533 shortSize = width;
Dianne Hackbornf87d1962012-04-04 12:48:24 -07001534 longSize = height;
Dianne Hackborn9d132642011-04-21 17:26:39 -07001535 mPortraitRotation = Surface.ROTATION_0;
1536 mUpsideDownRotation = Surface.ROTATION_180;
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001537 if (res.getBoolean(com.android.internal.R.bool.config_reverseDefaultRotation)) {
Dianne Hackborn9d132642011-04-21 17:26:39 -07001538 mLandscapeRotation = Surface.ROTATION_270;
1539 mSeascapeRotation = Surface.ROTATION_90;
1540 } else {
1541 mLandscapeRotation = Surface.ROTATION_90;
1542 mSeascapeRotation = Surface.ROTATION_270;
1543 }
1544 }
Dianne Hackborn81e56d52011-05-26 00:55:58 -07001545
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001546 mStatusBarHeight =
1547 res.getDimensionPixelSize(com.android.internal.R.dimen.status_bar_height);
Dianne Hackbornf87d1962012-04-04 12:48:24 -07001548
Daniel Sandler9f65c4c2012-04-26 01:35:35 -04001549 // Height of the navigation bar when presented horizontally at bottom
1550 mNavigationBarHeightForRotation[mPortraitRotation] =
1551 mNavigationBarHeightForRotation[mUpsideDownRotation] =
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001552 res.getDimensionPixelSize(com.android.internal.R.dimen.navigation_bar_height);
Daniel Sandler9f65c4c2012-04-26 01:35:35 -04001553 mNavigationBarHeightForRotation[mLandscapeRotation] =
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001554 mNavigationBarHeightForRotation[mSeascapeRotation] = res.getDimensionPixelSize(
1555 com.android.internal.R.dimen.navigation_bar_height_landscape);
Daniel Sandler9f65c4c2012-04-26 01:35:35 -04001556
1557 // Width of the navigation bar when presented vertically along one side
1558 mNavigationBarWidthForRotation[mPortraitRotation] =
1559 mNavigationBarWidthForRotation[mUpsideDownRotation] =
1560 mNavigationBarWidthForRotation[mLandscapeRotation] =
1561 mNavigationBarWidthForRotation[mSeascapeRotation] =
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001562 res.getDimensionPixelSize(com.android.internal.R.dimen.navigation_bar_width);
Daniel Sandler4a066c52012-04-20 14:49:13 -04001563
1564 // SystemUI (status bar) layout policy
Dianne Hackborndde331c2012-08-03 14:01:57 -07001565 int shortSizeDp = shortSize * DisplayMetrics.DENSITY_DEFAULT / density;
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001566 int longSizeDp = longSize * DisplayMetrics.DENSITY_DEFAULT / density;
Daniel Sandler4a066c52012-04-20 14:49:13 -04001567
Devin Kimd7b12b42014-05-05 14:34:58 -07001568 // Allow the navigation bar to move on non-square small devices (phones).
1569 mNavigationBarCanMove = width != height && shortSizeDp < 600;
Daniel Sandler36412a72011-08-04 09:35:13 -04001570
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001571 mHasNavigationBar = res.getBoolean(com.android.internal.R.bool.config_showNavigationBar);
John Spurlock80f00c12013-06-13 11:10:51 -04001572 // Allow a system property to override this. Used by the emulator.
1573 // See also hasNavigationBar().
1574 String navBarOverride = SystemProperties.get("qemu.hw.mainkeys");
1575 if ("1".equals(navBarOverride)) {
Dianne Hackbornf87d1962012-04-04 12:48:24 -07001576 mHasNavigationBar = false;
John Spurlock80f00c12013-06-13 11:10:51 -04001577 } else if ("0".equals(navBarOverride)) {
1578 mHasNavigationBar = true;
Daniel Sandler0c4ccff2011-10-19 16:39:14 -04001579 }
1580
Jeff Brown27f1d672012-10-17 18:32:34 -07001581 // For demo purposes, allow the rotation of the HDMI display to be controlled.
1582 // By default, HDMI locks rotation to landscape.
Erik Gilling9a41ef82011-09-26 19:21:03 -07001583 if ("portrait".equals(SystemProperties.get("persist.demo.hdmirotation"))) {
Jeff Brownc82c89ed2013-04-17 17:18:15 -07001584 mDemoHdmiRotation = mPortraitRotation;
Erik Gilling9a41ef82011-09-26 19:21:03 -07001585 } else {
Jeff Brownc82c89ed2013-04-17 17:18:15 -07001586 mDemoHdmiRotation = mLandscapeRotation;
Erik Gilling9a41ef82011-09-26 19:21:03 -07001587 }
Jeff Brownc82c89ed2013-04-17 17:18:15 -07001588 mDemoHdmiRotationLock = SystemProperties.getBoolean("persist.demo.hdmirotationlock", false);
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001589
Chong Zhangae6119ff2014-11-11 18:54:39 -08001590 // For demo purposes, allow the rotation of the remote display to be controlled.
1591 // By default, remote display locks rotation to landscape.
1592 if ("portrait".equals(SystemProperties.get("persist.demo.remoterotation"))) {
1593 mDemoRotation = mPortraitRotation;
1594 } else {
1595 mDemoRotation = mLandscapeRotation;
1596 }
1597 mDemoRotationLock = SystemProperties.getBoolean(
1598 "persist.demo.rotationlock", false);
1599
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001600 // Only force the default orientation if the screen is xlarge, at least 960dp x 720dp, per
1601 // http://developer.android.com/guide/practices/screens_support.html#range
1602 mForceDefaultOrientation = longSizeDp >= 960 && shortSizeDp >= 720 &&
1603 res.getBoolean(com.android.internal.R.bool.config_forceDefaultOrientation) &&
1604 // For debug purposes the next line turns this feature off with:
1605 // $ adb shell setprop config.override_forced_orient true
1606 // $ adb shell wm size reset
1607 !"true".equals(SystemProperties.get("config.override_forced_orient"));
1608 }
1609
Alan Viverette5a0f4ec2013-10-07 15:10:29 -07001610 /**
1611 * @return whether the navigation bar can be hidden, e.g. the device has a
1612 * navigation bar and touch exploration is not enabled
1613 */
1614 private boolean canHideNavigationBar() {
Svetoslav8e3feb12014-02-24 13:46:47 -08001615 return mHasNavigationBar
1616 && !mAccessibilityManager.isTouchExplorationEnabled();
Alan Viverette5a0f4ec2013-10-07 15:10:29 -07001617 }
1618
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001619 @Override
1620 public boolean isDefaultOrientationForced() {
1621 return mForceDefaultOrientation;
Dianne Hackborn9d132642011-04-21 17:26:39 -07001622 }
1623
Dianne Hackbornc652de82013-02-15 16:32:56 -08001624 @Override
1625 public void setDisplayOverscan(Display display, int left, int top, int right, int bottom) {
1626 if (display.getDisplayId() == Display.DEFAULT_DISPLAY) {
1627 mOverscanLeft = left;
1628 mOverscanTop = top;
1629 mOverscanRight = right;
1630 mOverscanBottom = bottom;
1631 }
1632 }
1633
Dianne Hackbornc777e072010-02-12 13:07:59 -08001634 public void updateSettings() {
1635 ContentResolver resolver = mContext.getContentResolver();
1636 boolean updateRotation = false;
Dianne Hackbornc777e072010-02-12 13:07:59 -08001637 synchronized (mLock) {
Christopher Tate5e08af02012-09-21 17:17:22 -07001638 mEndcallBehavior = Settings.System.getIntForUser(resolver,
David Brownbaf8d092010-03-08 21:52:59 -08001639 Settings.System.END_BUTTON_BEHAVIOR,
Christopher Tate5e08af02012-09-21 17:17:22 -07001640 Settings.System.END_BUTTON_BEHAVIOR_DEFAULT,
1641 UserHandle.USER_CURRENT);
1642 mIncallPowerBehavior = Settings.Secure.getIntForUser(resolver,
David Brownbaf8d092010-03-08 21:52:59 -08001643 Settings.Secure.INCALL_POWER_BUTTON_BEHAVIOR,
Christopher Tate5e08af02012-09-21 17:17:22 -07001644 Settings.Secure.INCALL_POWER_BUTTON_BEHAVIOR_DEFAULT,
1645 UserHandle.USER_CURRENT);
Daniel Sandlerb73617d2010-08-17 00:41:00 -04001646
Jeff Browna20dda42014-05-27 20:57:24 -07001647 // Configure wake gesture.
1648 boolean wakeGestureEnabledSetting = Settings.Secure.getIntForUser(resolver,
1649 Settings.Secure.WAKE_GESTURE_ENABLED, 0,
1650 UserHandle.USER_CURRENT) != 0;
1651 if (mWakeGestureEnabledSetting != wakeGestureEnabledSetting) {
1652 mWakeGestureEnabledSetting = wakeGestureEnabledSetting;
1653 updateWakeGestureListenerLp();
1654 }
1655
Jeff Brown207673cd2012-06-05 17:47:11 -07001656 // Configure rotation lock.
Christopher Tate5e08af02012-09-21 17:17:22 -07001657 int userRotation = Settings.System.getIntForUser(resolver,
1658 Settings.System.USER_ROTATION, Surface.ROTATION_0,
1659 UserHandle.USER_CURRENT);
Jeff Brown207673cd2012-06-05 17:47:11 -07001660 if (mUserRotation != userRotation) {
1661 mUserRotation = userRotation;
1662 updateRotation = true;
1663 }
Christopher Tate5e08af02012-09-21 17:17:22 -07001664 int userRotationMode = Settings.System.getIntForUser(resolver,
1665 Settings.System.ACCELEROMETER_ROTATION, 0, UserHandle.USER_CURRENT) != 0 ?
Jeff Brown207673cd2012-06-05 17:47:11 -07001666 WindowManagerPolicy.USER_ROTATION_FREE :
1667 WindowManagerPolicy.USER_ROTATION_LOCKED;
1668 if (mUserRotationMode != userRotationMode) {
1669 mUserRotationMode = userRotationMode;
1670 updateRotation = true;
Dianne Hackbornc777e072010-02-12 13:07:59 -08001671 updateOrientationListenerLp();
1672 }
Daniel Sandlerb73617d2010-08-17 00:41:00 -04001673
Dianne Hackbornc777e072010-02-12 13:07:59 -08001674 if (mSystemReady) {
Christopher Tate5e08af02012-09-21 17:17:22 -07001675 int pointerLocation = Settings.System.getIntForUser(resolver,
1676 Settings.System.POINTER_LOCATION, 0, UserHandle.USER_CURRENT);
Dianne Hackbornc777e072010-02-12 13:07:59 -08001677 if (mPointerLocationMode != pointerLocation) {
1678 mPointerLocationMode = pointerLocation;
Jeff Brown70825162012-03-28 17:27:48 -07001679 mHandler.sendEmptyMessage(pointerLocation != 0 ?
1680 MSG_ENABLE_POINTER_LOCATION : MSG_DISABLE_POINTER_LOCATION);
Dianne Hackbornc777e072010-02-12 13:07:59 -08001681 }
1682 }
1683 // use screen off timeout setting as the timeout for the lockscreen
Christopher Tate5e08af02012-09-21 17:17:22 -07001684 mLockScreenTimeout = Settings.System.getIntForUser(resolver,
1685 Settings.System.SCREEN_OFF_TIMEOUT, 0, UserHandle.USER_CURRENT);
1686 String imId = Settings.Secure.getStringForUser(resolver,
1687 Settings.Secure.DEFAULT_INPUT_METHOD, UserHandle.USER_CURRENT);
Dianne Hackbornc777e072010-02-12 13:07:59 -08001688 boolean hasSoftInput = imId != null && imId.length() > 0;
1689 if (mHasSoftInput != hasSoftInput) {
1690 mHasSoftInput = hasSoftInput;
1691 updateRotation = true;
1692 }
John Spurlockf1a36642013-10-12 17:50:42 -04001693 if (mImmersiveModeConfirmation != null) {
John Spurlock4355a532014-02-19 09:49:25 -05001694 mImmersiveModeConfirmation.loadSetting(mCurrentUserId);
John Spurlockd67ec252013-09-05 11:31:54 -04001695 }
John Spurlockc6d1c602014-01-17 15:22:06 -05001696 PolicyControl.reloadFromSetting(mContext);
Dianne Hackbornc777e072010-02-12 13:07:59 -08001697 }
1698 if (updateRotation) {
Jeff Brown01a98dd2011-09-20 15:08:29 -07001699 updateRotation(true);
Dianne Hackbornc777e072010-02-12 13:07:59 -08001700 }
Jeff Brown70825162012-03-28 17:27:48 -07001701 }
1702
Jeff Browna20dda42014-05-27 20:57:24 -07001703 private void updateWakeGestureListenerLp() {
1704 if (shouldEnableWakeGestureLp()) {
1705 mWakeGestureListener.requestWakeUpTrigger();
1706 } else {
1707 mWakeGestureListener.cancelWakeUpTrigger();
1708 }
1709 }
1710
1711 private boolean shouldEnableWakeGestureLp() {
Jeff Brown3ee549c2014-09-22 20:14:39 -07001712 return mWakeGestureEnabledSetting && !mAwake
Jeff Browna20dda42014-05-27 20:57:24 -07001713 && (!mLidControlsSleep || mLidState != LID_CLOSED)
1714 && mWakeGestureListener.isSupported();
1715 }
1716
Jeff Brown70825162012-03-28 17:27:48 -07001717 private void enablePointerLocation() {
1718 if (mPointerLocationView == null) {
1719 mPointerLocationView = new PointerLocationView(mContext);
1720 mPointerLocationView.setPrintCoords(false);
Dianne Hackbornc777e072010-02-12 13:07:59 -08001721 WindowManager.LayoutParams lp = new WindowManager.LayoutParams(
1722 WindowManager.LayoutParams.MATCH_PARENT,
1723 WindowManager.LayoutParams.MATCH_PARENT);
Jeff Brown3b2b3542010-10-15 00:54:27 -07001724 lp.type = WindowManager.LayoutParams.TYPE_SECURE_SYSTEM_OVERLAY;
Jeff Brownbfcb60a2011-09-08 18:51:14 -07001725 lp.flags = WindowManager.LayoutParams.FLAG_FULLSCREEN
1726 | WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE
1727 | WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE
1728 | WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN;
Jeff Brown90fc9052012-10-01 14:44:24 -07001729 if (ActivityManager.isHighEndGfx()) {
1730 lp.flags |= WindowManager.LayoutParams.FLAG_HARDWARE_ACCELERATED;
1731 lp.privateFlags |=
1732 WindowManager.LayoutParams.PRIVATE_FLAG_FORCE_HARDWARE_ACCELERATED;
1733 }
Dianne Hackbornc777e072010-02-12 13:07:59 -08001734 lp.format = PixelFormat.TRANSLUCENT;
1735 lp.setTitle("PointerLocation");
Dianne Hackborn5fd21692011-06-07 14:09:47 -07001736 WindowManager wm = (WindowManager)
Dianne Hackbornc777e072010-02-12 13:07:59 -08001737 mContext.getSystemService(Context.WINDOW_SERVICE);
Jeff Browncc4f7db2011-08-30 20:34:48 -07001738 lp.inputFeatures |= WindowManager.LayoutParams.INPUT_FEATURE_NO_INPUT_CHANNEL;
Jeff Brown70825162012-03-28 17:27:48 -07001739 wm.addView(mPointerLocationView, lp);
Michael Wrightc9c487e2013-11-07 18:55:09 -08001740 mWindowManagerFuncs.registerPointerEventListener(mPointerLocationView);
Dianne Hackbornc777e072010-02-12 13:07:59 -08001741 }
Dianne Hackbornc777e072010-02-12 13:07:59 -08001742 }
Jeff Brown70825162012-03-28 17:27:48 -07001743
1744 private void disablePointerLocation() {
Jeff Brown70825162012-03-28 17:27:48 -07001745 if (mPointerLocationView != null) {
Michael Wrightc9c487e2013-11-07 18:55:09 -08001746 mWindowManagerFuncs.unregisterPointerEventListener(mPointerLocationView);
1747 WindowManager wm = (WindowManager) mContext.getSystemService(Context.WINDOW_SERVICE);
Jeff Brown70825162012-03-28 17:27:48 -07001748 wm.removeView(mPointerLocationView);
1749 mPointerLocationView = null;
1750 }
1751 }
1752
Mike Lockwood2d1efbd2009-09-16 12:15:53 -04001753 private int readRotation(int resID) {
Mike Lockwood1753f7f2009-08-24 14:49:07 -07001754 try {
1755 int rotation = mContext.getResources().getInteger(resID);
1756 switch (rotation) {
1757 case 0:
1758 return Surface.ROTATION_0;
1759 case 90:
1760 return Surface.ROTATION_90;
1761 case 180:
1762 return Surface.ROTATION_180;
1763 case 270:
1764 return Surface.ROTATION_270;
Mike Lockwood1753f7f2009-08-24 14:49:07 -07001765 }
1766 } catch (Resources.NotFoundException e) {
Mike Lockwood2d1efbd2009-09-16 12:15:53 -04001767 // fall through
Mike Lockwood1753f7f2009-08-24 14:49:07 -07001768 }
Mike Lockwood2d1efbd2009-09-16 12:15:53 -04001769 return -1;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001770 }
1771
1772 /** {@inheritDoc} */
Craig Mautner88400d32012-09-30 12:35:45 -07001773 @Override
Dianne Hackbornc2293022013-02-06 23:14:49 -08001774 public int checkAddPermission(WindowManager.LayoutParams attrs, int[] outAppOp) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001775 int type = attrs.type;
Dianne Hackbornc2293022013-02-06 23:14:49 -08001776
1777 outAppOp[0] = AppOpsManager.OP_NONE;
1778
Wale Ogunwale74bf0652015-01-12 10:24:36 -08001779 if (!((type >= FIRST_APPLICATION_WINDOW && type <= LAST_APPLICATION_WINDOW)
1780 || (type >= FIRST_SUB_WINDOW && type <= LAST_SUB_WINDOW)
1781 || (type >= FIRST_SYSTEM_WINDOW && type <= LAST_SYSTEM_WINDOW))) {
1782 return WindowManagerGlobal.ADD_INVALID_TYPE;
1783 }
1784
1785 if (type < FIRST_SYSTEM_WINDOW || type > LAST_SYSTEM_WINDOW) {
1786 // Window manager will make sure these are okay.
Jeff Brown98365d72012-08-19 20:30:52 -07001787 return WindowManagerGlobal.ADD_OKAY;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001788 }
1789 String permission = null;
1790 switch (type) {
1791 case TYPE_TOAST:
1792 // XXX right now the app process has complete control over
1793 // this... should introduce a token to let the system
1794 // monitor/control what they are doing.
Jason Monk1c7c3192014-06-26 12:52:18 -04001795 outAppOp[0] = AppOpsManager.OP_TOAST_WINDOW;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001796 break;
Daniel Sandler7d276c32012-01-30 14:33:52 -05001797 case TYPE_DREAM:
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001798 case TYPE_INPUT_METHOD:
Dianne Hackbornb7cd8b92009-08-08 20:53:03 -07001799 case TYPE_WALLPAPER:
keunyounga446bf02013-06-21 19:07:57 -07001800 case TYPE_PRIVATE_PRESENTATION:
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001801 case TYPE_VOICE_INTERACTION:
Svetoslav3a5c7212014-10-14 09:54:26 -07001802 case TYPE_ACCESSIBILITY_OVERLAY:
Dianne Hackbornb7cd8b92009-08-08 20:53:03 -07001803 // The window manager will check these.
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001804 break;
1805 case TYPE_PHONE:
1806 case TYPE_PRIORITY_PHONE:
1807 case TYPE_SYSTEM_ALERT:
1808 case TYPE_SYSTEM_ERROR:
1809 case TYPE_SYSTEM_OVERLAY:
1810 permission = android.Manifest.permission.SYSTEM_ALERT_WINDOW;
Dianne Hackbornc2293022013-02-06 23:14:49 -08001811 outAppOp[0] = AppOpsManager.OP_SYSTEM_ALERT_WINDOW;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001812 break;
1813 default:
1814 permission = android.Manifest.permission.INTERNAL_SYSTEM_WINDOW;
1815 }
1816 if (permission != null) {
Billy Laucbe540f2015-06-25 01:51:44 +01001817 if (permission == android.Manifest.permission.SYSTEM_ALERT_WINDOW) {
1818 final int callingUid = Binder.getCallingUid();
1819 // check if this is a system uid first before bothering with
1820 // obtaining package name
1821 if (callingUid == Process.SYSTEM_UID) {
1822 return WindowManagerGlobal.ADD_OKAY;
1823 }
1824
1825 final int mode = mAppOpsManager.checkOp(outAppOp[0], callingUid,
1826 attrs.packageName);
1827 if (mode == AppOpsManager.MODE_DEFAULT) {
1828 if (mContext.checkCallingPermission(permission) !=
1829 PackageManager.PERMISSION_GRANTED) {
1830 return WindowManagerGlobal.ADD_PERMISSION_DENIED;
1831 }
1832 }
1833 return WindowManagerGlobal.ADD_OKAY;
1834 }
1835
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001836 if (mContext.checkCallingOrSelfPermission(permission)
1837 != PackageManager.PERMISSION_GRANTED) {
Jeff Brown98365d72012-08-19 20:30:52 -07001838 return WindowManagerGlobal.ADD_PERMISSION_DENIED;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001839 }
1840 }
Jeff Brown98365d72012-08-19 20:30:52 -07001841 return WindowManagerGlobal.ADD_OKAY;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001842 }
Craig Mautner88400d32012-09-30 12:35:45 -07001843
1844 @Override
1845 public boolean checkShowToOwnerOnly(WindowManager.LayoutParams attrs) {
1846
1847 // If this switch statement is modified, modify the comment in the declarations of
1848 // the type in {@link WindowManager.LayoutParams} as well.
1849 switch (attrs.type) {
1850 default:
1851 // These are the windows that by default are shown only to the user that created
1852 // them. If this needs to be overridden, set
1853 // {@link WindowManager.LayoutParams.PRIVATE_FLAG_SHOW_FOR_ALL_USERS} in
1854 // {@link WindowManager.LayoutParams}. Note that permission
1855 // {@link android.Manifest.permission.INTERNAL_SYSTEM_WINDOW} is required as well.
1856 if ((attrs.privateFlags & PRIVATE_FLAG_SHOW_FOR_ALL_USERS) == 0) {
1857 return true;
1858 }
1859 break;
1860
1861 // These are the windows that by default are shown to all users. However, to
1862 // protect against spoofing, check permissions below.
1863 case TYPE_APPLICATION_STARTING:
1864 case TYPE_BOOT_PROGRESS:
1865 case TYPE_DISPLAY_OVERLAY:
Selim Cinekf83e8242015-05-19 18:08:14 -07001866 case TYPE_INPUT_CONSUMER:
Jim Miller5ecd8112013-01-09 18:50:26 -08001867 case TYPE_KEYGUARD_SCRIM:
Craig Mautner88400d32012-09-30 12:35:45 -07001868 case TYPE_KEYGUARD_DIALOG:
1869 case TYPE_MAGNIFICATION_OVERLAY:
1870 case TYPE_NAVIGATION_BAR:
1871 case TYPE_NAVIGATION_BAR_PANEL:
1872 case TYPE_PHONE:
1873 case TYPE_POINTER:
1874 case TYPE_PRIORITY_PHONE:
Craig Mautner88400d32012-09-30 12:35:45 -07001875 case TYPE_SEARCH_BAR:
1876 case TYPE_STATUS_BAR:
1877 case TYPE_STATUS_BAR_PANEL:
1878 case TYPE_STATUS_BAR_SUB_PANEL:
1879 case TYPE_SYSTEM_DIALOG:
Craig Mautner88400d32012-09-30 12:35:45 -07001880 case TYPE_VOLUME_OVERLAY:
keunyounga446bf02013-06-21 19:07:57 -07001881 case TYPE_PRIVATE_PRESENTATION:
Craig Mautner88400d32012-09-30 12:35:45 -07001882 break;
1883 }
1884
1885 // Check if third party app has set window to system window type.
1886 return mContext.checkCallingOrSelfPermission(
1887 android.Manifest.permission.INTERNAL_SYSTEM_WINDOW)
1888 != PackageManager.PERMISSION_GRANTED;
1889 }
1890
Craig Mautner967212c2013-04-13 21:10:58 -07001891 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001892 public void adjustWindowParamsLw(WindowManager.LayoutParams attrs) {
1893 switch (attrs.type) {
1894 case TYPE_SYSTEM_OVERLAY:
Jeff Brown3b2b3542010-10-15 00:54:27 -07001895 case TYPE_SECURE_SYSTEM_OVERLAY:
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001896 // These types of windows can't receive input events.
1897 attrs.flags |= WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE
1898 | WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE;
Jeff Brownbfcb60a2011-09-08 18:51:14 -07001899 attrs.flags &= ~WindowManager.LayoutParams.FLAG_WATCH_OUTSIDE_TOUCH;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001900 break;
Jorim Jaggi380ecb82014-03-14 17:25:20 +01001901 case TYPE_STATUS_BAR:
1902
1903 // If the Keyguard is in a hidden state (occluded by another window), we force to
1904 // remove the wallpaper and keyguard flag so that any change in-flight after setting
1905 // the keyguard as occluded wouldn't set these flags again.
1906 // See {@link #processKeyguardSetHiddenResultLw}.
1907 if (mKeyguardHidden) {
1908 attrs.flags &= ~WindowManager.LayoutParams.FLAG_SHOW_WALLPAPER;
1909 attrs.privateFlags &= ~WindowManager.LayoutParams.PRIVATE_FLAG_KEYGUARD;
1910 }
1911 break;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001912 }
Adrian Roos38502112014-04-09 21:04:11 +02001913
1914 if (attrs.type != TYPE_STATUS_BAR) {
1915 // The status bar is the only window allowed to exhibit keyguard behavior.
1916 attrs.privateFlags &= ~WindowManager.LayoutParams.PRIVATE_FLAG_KEYGUARD;
1917 }
Adrian Roosea562512014-05-05 13:33:03 +02001918
1919 if (ActivityManager.isHighEndGfx()
1920 && (attrs.flags & FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS) != 0) {
Adrian Roosf5e9b5c2014-09-10 15:27:41 +02001921 attrs.subtreeSystemUiVisibility |= View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
Adrian Roosea562512014-05-05 13:33:03 +02001922 | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION;
1923 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001924 }
RoboErik8a2cfc32014-05-16 11:19:38 -07001925
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001926 void readLidState() {
Jeff Brown2e7760e2012-04-11 15:14:55 -07001927 mLidState = mWindowManagerFuncs.getLidState();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001928 }
RoboErik8a2cfc32014-05-16 11:19:38 -07001929
Michael Wright3818c922014-09-02 13:59:07 -07001930 private void readCameraLensCoverState() {
1931 mCameraLensCoverState = mWindowManagerFuncs.getCameraLensCoverState();
1932 }
1933
Jeff Browndaa37532012-05-01 15:54:03 -07001934 private boolean isHidden(int accessibilityMode) {
1935 switch (accessibilityMode) {
1936 case 1:
1937 return mLidState == LID_CLOSED;
1938 case 2:
1939 return mLidState == LID_OPEN;
1940 default:
1941 return false;
Dianne Hackborn2862fff2009-09-15 22:56:29 -07001942 }
Dianne Hackborn2862fff2009-09-15 22:56:29 -07001943 }
Jeff Brownd04a88c2011-01-16 14:05:47 -08001944
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001945 /** {@inheritDoc} */
Craig Mautner967212c2013-04-13 21:10:58 -07001946 @Override
Jeff Browndaa37532012-05-01 15:54:03 -07001947 public void adjustConfigurationLw(Configuration config, int keyboardPresence,
1948 int navigationPresence) {
1949 mHaveBuiltInKeyboard = (keyboardPresence & PRESENCE_INTERNAL) != 0;
1950
Jeff Brownf71343d2013-05-31 17:59:11 -07001951 readConfigurationDependentBehaviors();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001952 readLidState();
Jeff Brownc458ce92012-04-30 14:58:40 -07001953 applyLidSwitchState();
Jeff Brownd04a88c2011-01-16 14:05:47 -08001954
Jeff Browndaa37532012-05-01 15:54:03 -07001955 if (config.keyboard == Configuration.KEYBOARD_NOKEYS
1956 || (keyboardPresence == PRESENCE_INTERNAL
1957 && isHidden(mLidKeyboardAccessibility))) {
Jeff Brownd04a88c2011-01-16 14:05:47 -08001958 config.hardKeyboardHidden = Configuration.HARDKEYBOARDHIDDEN_YES;
Jeff Browndaa37532012-05-01 15:54:03 -07001959 if (!mHasSoftInput) {
1960 config.keyboardHidden = Configuration.KEYBOARDHIDDEN_YES;
1961 }
Jeff Brownd04a88c2011-01-16 14:05:47 -08001962 }
1963
Jeff Browndaa37532012-05-01 15:54:03 -07001964 if (config.navigation == Configuration.NAVIGATION_NONAV
1965 || (navigationPresence == PRESENCE_INTERNAL
1966 && isHidden(mLidNavigationAccessibility))) {
Jeff Brownd04a88c2011-01-16 14:05:47 -08001967 config.navigationHidden = Configuration.NAVIGATIONHIDDEN_YES;
Jeff Brownd04a88c2011-01-16 14:05:47 -08001968 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001969 }
Jeff Brownd04a88c2011-01-16 14:05:47 -08001970
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001971 /** {@inheritDoc} */
Craig Mautner967212c2013-04-13 21:10:58 -07001972 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001973 public int windowTypeToLayerLw(int type) {
1974 if (type >= FIRST_APPLICATION_WINDOW && type <= LAST_APPLICATION_WINDOW) {
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001975 return 2;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001976 }
1977 switch (type) {
keunyounga446bf02013-06-21 19:07:57 -07001978 case TYPE_PRIVATE_PRESENTATION:
1979 return 2;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001980 case TYPE_WALLPAPER:
1981 // wallpaper is at the bottom, though the window manager may move it.
1982 return 2;
1983 case TYPE_PHONE:
1984 return 3;
1985 case TYPE_SEARCH_BAR:
Jorim Jaggi225d3b52015-04-01 11:18:57 -07001986 case TYPE_VOICE_INTERACTION_STARTING:
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001987 return 4;
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001988 case TYPE_VOICE_INTERACTION:
1989 // voice interaction layer is almost immediately above apps.
1990 return 5;
Selim Cinekf83e8242015-05-19 18:08:14 -07001991 case TYPE_INPUT_CONSUMER:
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001992 return 6;
Selim Cinekf83e8242015-05-19 18:08:14 -07001993 case TYPE_SYSTEM_DIALOG:
1994 return 7;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001995 case TYPE_TOAST:
1996 // toasts and the plugged-in battery thing
Selim Cinekf83e8242015-05-19 18:08:14 -07001997 return 8;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001998 case TYPE_PRIORITY_PHONE:
1999 // SIM errors and unlock. Not sure if this really should be in a high layer.
Selim Cinekf83e8242015-05-19 18:08:14 -07002000 return 9;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07002001 case TYPE_DREAM:
2002 // used for Dreams (screensavers with TYPE_DREAM windows)
Selim Cinekf83e8242015-05-19 18:08:14 -07002003 return 10;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07002004 case TYPE_SYSTEM_ALERT:
2005 // like the ANR / app crashed dialogs
Selim Cinekf83e8242015-05-19 18:08:14 -07002006 return 11;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07002007 case TYPE_INPUT_METHOD:
2008 // on-screen keyboards and other such input method user interfaces go here.
Selim Cinekf83e8242015-05-19 18:08:14 -07002009 return 12;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07002010 case TYPE_INPUT_METHOD_DIALOG:
2011 // on-screen keyboards and other such input method user interfaces go here.
Selim Cinekf83e8242015-05-19 18:08:14 -07002012 return 13;
Jim Miller5ecd8112013-01-09 18:50:26 -08002013 case TYPE_KEYGUARD_SCRIM:
2014 // the safety window that shows behind keyguard while keyguard is starting
Jorim Jaggi380ecb82014-03-14 17:25:20 +01002015 return 14;
Selim Cinekf83e8242015-05-19 18:08:14 -07002016 case TYPE_STATUS_BAR_SUB_PANEL:
Jorim Jaggi380ecb82014-03-14 17:25:20 +01002017 return 15;
Selim Cinekf83e8242015-05-19 18:08:14 -07002018 case TYPE_STATUS_BAR:
Jorim Jaggi380ecb82014-03-14 17:25:20 +01002019 return 16;
Selim Cinekf83e8242015-05-19 18:08:14 -07002020 case TYPE_STATUS_BAR_PANEL:
Dianne Hackborne30e02f2014-05-27 18:24:45 -07002021 return 17;
Selim Cinekf83e8242015-05-19 18:08:14 -07002022 case TYPE_KEYGUARD_DIALOG:
2023 return 18;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07002024 case TYPE_VOLUME_OVERLAY:
2025 // the on-screen volume indicator and controller shown when the user
2026 // changes the device volume
Selim Cinekf83e8242015-05-19 18:08:14 -07002027 return 19;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07002028 case TYPE_SYSTEM_OVERLAY:
2029 // the on-screen volume indicator and controller shown when the user
2030 // changes the device volume
Selim Cinekf83e8242015-05-19 18:08:14 -07002031 return 20;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07002032 case TYPE_NAVIGATION_BAR:
2033 // the navigation bar, if available, shows atop most things
Selim Cinekf83e8242015-05-19 18:08:14 -07002034 return 21;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07002035 case TYPE_NAVIGATION_BAR_PANEL:
2036 // some panels (e.g. search) need to show on top of the navigation bar
Selim Cinekf83e8242015-05-19 18:08:14 -07002037 return 22;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07002038 case TYPE_SYSTEM_ERROR:
2039 // system-level error dialogs
Selim Cinekf83e8242015-05-19 18:08:14 -07002040 return 23;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07002041 case TYPE_MAGNIFICATION_OVERLAY:
2042 // used to highlight the magnified portion of a display
Selim Cinekf83e8242015-05-19 18:08:14 -07002043 return 24;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07002044 case TYPE_DISPLAY_OVERLAY:
2045 // used to simulate secondary display devices
Selim Cinekf83e8242015-05-19 18:08:14 -07002046 return 25;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07002047 case TYPE_DRAG:
2048 // the drag layer: input for drag-and-drop is associated with this window,
2049 // which sits above all other focusable windows
Selim Cinekf83e8242015-05-19 18:08:14 -07002050 return 26;
Svetoslav3a5c7212014-10-14 09:54:26 -07002051 case TYPE_ACCESSIBILITY_OVERLAY:
2052 // overlay put by accessibility services to intercept user interaction
Dianne Hackborne30e02f2014-05-27 18:24:45 -07002053 return 27;
Selim Cinekf83e8242015-05-19 18:08:14 -07002054 case TYPE_SECURE_SYSTEM_OVERLAY:
Svetoslav3a5c7212014-10-14 09:54:26 -07002055 return 28;
Selim Cinekf83e8242015-05-19 18:08:14 -07002056 case TYPE_BOOT_PROGRESS:
2057 return 29;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07002058 case TYPE_POINTER:
2059 // the (mouse) pointer layer
Svetoslav3a5c7212014-10-14 09:54:26 -07002060 return 30;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002061 }
2062 Log.e(TAG, "Unknown window type: " + type);
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07002063 return 2;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002064 }
2065
2066 /** {@inheritDoc} */
Craig Mautner46ac6fa2013-08-01 10:06:34 -07002067 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002068 public int subWindowTypeToLayerLw(int type) {
2069 switch (type) {
2070 case TYPE_APPLICATION_PANEL:
2071 case TYPE_APPLICATION_ATTACHED_DIALOG:
2072 return APPLICATION_PANEL_SUBLAYER;
2073 case TYPE_APPLICATION_MEDIA:
2074 return APPLICATION_MEDIA_SUBLAYER;
Dianne Hackborn5cb8d792009-05-21 17:34:15 -07002075 case TYPE_APPLICATION_MEDIA_OVERLAY:
2076 return APPLICATION_MEDIA_OVERLAY_SUBLAYER;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002077 case TYPE_APPLICATION_SUB_PANEL:
2078 return APPLICATION_SUB_PANEL_SUBLAYER;
Wale Ogunwale0a4dc222015-04-14 12:58:42 -07002079 case TYPE_APPLICATION_ABOVE_SUB_PANEL:
2080 return APPLICATION_ABOVE_SUB_PANEL_SUBLAYER;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002081 }
2082 Log.e(TAG, "Unknown sub-window type: " + type);
2083 return 0;
2084 }
2085
Craig Mautner46ac6fa2013-08-01 10:06:34 -07002086 @Override
Dianne Hackbornabe0da02009-09-18 01:55:39 -07002087 public int getMaxWallpaperLayer() {
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07002088 return windowTypeToLayerLw(TYPE_STATUS_BAR);
Dianne Hackbornabe0da02009-09-18 01:55:39 -07002089 }
2090
Craig Mautner46ac6fa2013-08-01 10:06:34 -07002091 @Override
Dianne Hackborn1f903c32011-09-13 19:18:06 -07002092 public int getNonDecorDisplayWidth(int fullWidth, int fullHeight, int rotation) {
Dianne Hackborn077ee852012-04-09 16:27:07 -07002093 if (mHasNavigationBar) {
2094 // For a basic navigation bar, when we are in landscape mode we place
2095 // the navigation bar to the side.
Daniel Sandler4a066c52012-04-20 14:49:13 -04002096 if (mNavigationBarCanMove && fullWidth > fullHeight) {
2097 return fullWidth - mNavigationBarWidthForRotation[rotation];
Dianne Hackborn077ee852012-04-09 16:27:07 -07002098 }
Dianne Hackborn1f903c32011-09-13 19:18:06 -07002099 }
2100 return fullWidth;
Dianne Hackborne2515ee2011-04-27 18:52:56 -04002101 }
2102
Jose Lima9546b202014-07-02 17:21:51 -07002103 @Override
Dianne Hackborn1f903c32011-09-13 19:18:06 -07002104 public int getNonDecorDisplayHeight(int fullWidth, int fullHeight, int rotation) {
Dianne Hackborn077ee852012-04-09 16:27:07 -07002105 if (mHasNavigationBar) {
2106 // For a basic navigation bar, when we are in portrait mode we place
2107 // the navigation bar to the bottom.
Daniel Sandler4a066c52012-04-20 14:49:13 -04002108 if (!mNavigationBarCanMove || fullWidth < fullHeight) {
2109 return fullHeight - mNavigationBarHeightForRotation[rotation];
Dianne Hackborn077ee852012-04-09 16:27:07 -07002110 }
2111 }
2112 return fullHeight;
Dianne Hackborn69cb8752011-05-19 18:13:32 -07002113 }
2114
Jose Lima9546b202014-07-02 17:21:51 -07002115 @Override
Dianne Hackborn1f903c32011-09-13 19:18:06 -07002116 public int getConfigDisplayWidth(int fullWidth, int fullHeight, int rotation) {
2117 return getNonDecorDisplayWidth(fullWidth, fullHeight, rotation);
Dianne Hackborn69cb8752011-05-19 18:13:32 -07002118 }
2119
Jose Lima9546b202014-07-02 17:21:51 -07002120 @Override
Dianne Hackborn1f903c32011-09-13 19:18:06 -07002121 public int getConfigDisplayHeight(int fullWidth, int fullHeight, int rotation) {
John Spurlock80f00c12013-06-13 11:10:51 -04002122 // There is a separate status bar at the top of the display. We don't count that as part
2123 // of the fixed decor, since it can hide; however, for purposes of configurations,
Dianne Hackborn077ee852012-04-09 16:27:07 -07002124 // we do want to exclude it since applications can't generally use that part
2125 // of the screen.
John Spurlock80f00c12013-06-13 11:10:51 -04002126 return getNonDecorDisplayHeight(fullWidth, fullHeight, rotation) - mStatusBarHeight;
Dianne Hackborne2515ee2011-04-27 18:52:56 -04002127 }
2128
Craig Mautnera3f4bf52012-10-10 20:37:48 -07002129 @Override
Craig Mautnerc9457fa2014-06-06 14:27:48 -07002130 public boolean isForceHiding(WindowManager.LayoutParams attrs) {
2131 return (attrs.privateFlags & PRIVATE_FLAG_KEYGUARD) != 0 ||
Jim Millerab954542014-10-10 18:21:49 -07002132 (isKeyguardHostWindow(attrs) &&
2133 (mKeyguardDelegate != null && mKeyguardDelegate.isShowing())) ||
Adrian Roos69e510d2014-07-13 14:57:59 +02002134 (attrs.type == TYPE_KEYGUARD_SCRIM);
Dianne Hackborn01ad2f42009-09-24 19:24:56 -07002135 }
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07002136
Craig Mautnera3f4bf52012-10-10 20:37:48 -07002137 @Override
Jorim Jaggi0d674622014-05-21 01:34:15 +02002138 public boolean isKeyguardHostWindow(WindowManager.LayoutParams attrs) {
2139 return attrs.type == TYPE_STATUS_BAR;
2140 }
2141
2142 @Override
Dianne Hackborn01ad2f42009-09-24 19:24:56 -07002143 public boolean canBeForceHidden(WindowState win, WindowManager.LayoutParams attrs) {
Craig Mautnera3f4bf52012-10-10 20:37:48 -07002144 switch (attrs.type) {
2145 case TYPE_STATUS_BAR:
2146 case TYPE_NAVIGATION_BAR:
2147 case TYPE_WALLPAPER:
2148 case TYPE_DREAM:
Jim Miller5ecd8112013-01-09 18:50:26 -08002149 case TYPE_KEYGUARD_SCRIM:
Craig Mautnera3f4bf52012-10-10 20:37:48 -07002150 return false;
2151 default:
Adrian Roos461829d2015-06-03 14:41:18 -07002152 // Hide only windows below the keyguard host window.
2153 return windowTypeToLayerLw(win.getBaseType())
2154 < windowTypeToLayerLw(TYPE_STATUS_BAR);
Craig Mautnera3f4bf52012-10-10 20:37:48 -07002155 }
Dianne Hackborn01ad2f42009-09-24 19:24:56 -07002156 }
Craig Mautner8e4df6c2012-05-23 16:57:23 -07002157
Craig Mautner7d7808f2014-09-11 18:02:38 -07002158 @Override
2159 public WindowState getWinShowWhenLockedLw() {
2160 return mWinShowWhenLocked;
2161 }
2162
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002163 /** {@inheritDoc} */
Craig Mautner8e4df6c2012-05-23 16:57:23 -07002164 @Override
Dianne Hackborn2f0b1752011-05-31 17:59:49 -07002165 public View addStartingWindow(IBinder appToken, String packageName, int theme,
2166 CompatibilityInfo compatInfo, CharSequence nonLocalizedLabel, int labelRes,
Adam Powell04fe6eb2013-05-31 14:39:48 -07002167 int icon, int logo, int windowFlags) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002168 if (!SHOW_STARTING_ANIMATIONS) {
2169 return null;
2170 }
2171 if (packageName == null) {
2172 return null;
2173 }
Craig Mautner8e4df6c2012-05-23 16:57:23 -07002174
Mathias Jeppssond1443e92012-08-24 15:25:32 +02002175 WindowManager wm = null;
2176 View view = null;
2177
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002178 try {
Dianne Hackborn867ab6472010-04-29 13:28:56 -07002179 Context context = mContext;
Craig Mautner6fbda632012-07-03 09:26:39 -07002180 if (DEBUG_STARTING_WINDOW) Slog.d(TAG, "addStartingWindow " + packageName
2181 + ": nonLocalizedLabel=" + nonLocalizedLabel + " theme="
2182 + Integer.toHexString(theme));
Dianne Hackborn247fe742011-01-08 17:25:57 -08002183 if (theme != context.getThemeResId() || labelRes != 0) {
Dianne Hackborn867ab6472010-04-29 13:28:56 -07002184 try {
2185 context = context.createPackageContext(packageName, 0);
Dianne Hackborn247fe742011-01-08 17:25:57 -08002186 context.setTheme(theme);
Dianne Hackborn867ab6472010-04-29 13:28:56 -07002187 } catch (PackageManager.NameNotFoundException e) {
2188 // Ignore
2189 }
2190 }
Craig Mautner8e4df6c2012-05-23 16:57:23 -07002191
Jorim Jaggia16cc152015-06-01 16:55:05 -07002192 PhoneWindow win = new PhoneWindow(context);
2193 win.setIsStartingWindow(true);
Craig Mautner8e4df6c2012-05-23 16:57:23 -07002194 final TypedArray ta = win.getWindowStyle();
2195 if (ta.getBoolean(
2196 com.android.internal.R.styleable.Window_windowDisablePreview, false)
2197 || ta.getBoolean(
2198 com.android.internal.R.styleable.Window_windowShowWallpaper,false)) {
Dianne Hackborn867ab6472010-04-29 13:28:56 -07002199 return null;
2200 }
Craig Mautner8e4df6c2012-05-23 16:57:23 -07002201
Dianne Hackborn867ab6472010-04-29 13:28:56 -07002202 Resources r = context.getResources();
2203 win.setTitle(r.getText(labelRes, nonLocalizedLabel));
Craig Mautner8e4df6c2012-05-23 16:57:23 -07002204
Dianne Hackborn867ab6472010-04-29 13:28:56 -07002205 win.setType(
2206 WindowManager.LayoutParams.TYPE_APPLICATION_STARTING);
Adrian Roos602c68e2015-04-24 16:03:47 -07002207
2208 synchronized (mWindowManagerFuncs.getWindowManagerLock()) {
2209 // Assumes it's safe to show starting windows of launched apps while
2210 // the keyguard is being hidden. This is okay because starting windows never show
2211 // secret information.
2212 if (mKeyguardHidden) {
2213 windowFlags |= FLAG_SHOW_WHEN_LOCKED;
2214 }
2215 }
2216
Dianne Hackborn867ab6472010-04-29 13:28:56 -07002217 // Force the window flags: this is a fake window, so it is not really
2218 // touchable or focusable by the user. We also add in the ALT_FOCUSABLE_IM
2219 // flag because we do know that the next window will take input
2220 // focus, so we want to get the IME window up on top of us right away.
2221 win.setFlags(
Dianne Hackborn7eec10e2010-11-12 18:03:47 -08002222 windowFlags|
Dianne Hackborn867ab6472010-04-29 13:28:56 -07002223 WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE|
2224 WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE|
2225 WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM,
Dianne Hackborn7eec10e2010-11-12 18:03:47 -08002226 windowFlags|
Dianne Hackborn867ab6472010-04-29 13:28:56 -07002227 WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE|
2228 WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE|
2229 WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM);
Craig Mautner8e4df6c2012-05-23 16:57:23 -07002230
Adam Powell04fe6eb2013-05-31 14:39:48 -07002231 win.setDefaultIcon(icon);
2232 win.setDefaultLogo(logo);
2233
Dianne Hackborn867ab6472010-04-29 13:28:56 -07002234 win.setLayout(WindowManager.LayoutParams.MATCH_PARENT,
Dianne Hackborn2f0b1752011-05-31 17:59:49 -07002235 WindowManager.LayoutParams.MATCH_PARENT);
Craig Mautner8e4df6c2012-05-23 16:57:23 -07002236
Dianne Hackborn867ab6472010-04-29 13:28:56 -07002237 final WindowManager.LayoutParams params = win.getAttributes();
2238 params.token = appToken;
2239 params.packageName = packageName;
2240 params.windowAnimations = win.getWindowStyle().getResourceId(
2241 com.android.internal.R.styleable.Window_windowAnimationStyle, 0);
John Reck61375a82014-09-18 19:27:48 +00002242 params.privateFlags |=
2243 WindowManager.LayoutParams.PRIVATE_FLAG_FAKE_HARDWARE_ACCELERATED;
Craig Mautner88400d32012-09-30 12:35:45 -07002244 params.privateFlags |= WindowManager.LayoutParams.PRIVATE_FLAG_SHOW_FOR_ALL_USERS;
Adam Lesinski95c42972013-10-02 10:13:27 -07002245
2246 if (!compatInfo.supportsScreen()) {
2247 params.privateFlags |= WindowManager.LayoutParams.PRIVATE_FLAG_COMPATIBLE_WINDOW;
2248 }
2249
Dianne Hackborn867ab6472010-04-29 13:28:56 -07002250 params.setTitle("Starting " + packageName);
2251
Mathias Jeppssond1443e92012-08-24 15:25:32 +02002252 wm = (WindowManager)context.getSystemService(Context.WINDOW_SERVICE);
2253 view = win.getDecorView();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002254
2255 if (win.isFloating()) {
2256 // Whoops, there is no way to display an animation/preview
2257 // of such a thing! After all that work... let's skip it.
2258 // (Note that we must do this here because it is in
2259 // getDecorView() where the theme is evaluated... maybe
2260 // we should peek the floating attribute from the theme
2261 // earlier.)
2262 return null;
2263 }
Craig Mautner8e4df6c2012-05-23 16:57:23 -07002264
Craig Mautner6fbda632012-07-03 09:26:39 -07002265 if (DEBUG_STARTING_WINDOW) Slog.d(
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002266 TAG, "Adding starting window for " + packageName
2267 + " / " + appToken + ": "
2268 + (view.getParent() != null ? view : null));
2269
2270 wm.addView(view, params);
2271
2272 // Only return the view if it was successfully added to the
2273 // window manager... which we can tell by it having a parent.
2274 return view.getParent() != null ? view : null;
Jeff Brown98365d72012-08-19 20:30:52 -07002275 } catch (WindowManager.BadTokenException e) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002276 // ignore
Craig Mautner42bf39e2014-02-21 16:46:22 -08002277 Log.w(TAG, appToken + " already running, starting window not displayed. " +
2278 e.getMessage());
Dianne Hackborn867ab6472010-04-29 13:28:56 -07002279 } catch (RuntimeException e) {
2280 // don't crash if something else bad happens, for example a
2281 // failure loading resources because we are loading from an app
2282 // on external storage that has been unmounted.
2283 Log.w(TAG, appToken + " failed creating starting window", e);
Mathias Jeppssond1443e92012-08-24 15:25:32 +02002284 } finally {
2285 if (view != null && view.getParent() == null) {
2286 Log.w(TAG, "view not successfully added to wm, removing view");
2287 wm.removeViewImmediate(view);
2288 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002289 }
2290
2291 return null;
2292 }
2293
2294 /** {@inheritDoc} */
Jose Lima9546b202014-07-02 17:21:51 -07002295 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002296 public void removeStartingWindow(IBinder appToken, View window) {
Craig Mautner276a6eb2014-11-04 15:32:57 -08002297 if (DEBUG_STARTING_WINDOW) Slog.v(TAG, "Removing starting window for " + appToken + ": "
2298 + window + " Callers=" + Debug.getCallers(4));
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002299
2300 if (window != null) {
Dianne Hackborn5fd21692011-06-07 14:09:47 -07002301 WindowManager wm = (WindowManager)mContext.getSystemService(Context.WINDOW_SERVICE);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002302 wm.removeView(window);
2303 }
2304 }
2305
2306 /**
2307 * Preflight adding a window to the system.
RoboErik8a2cfc32014-05-16 11:19:38 -07002308 *
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002309 * Currently enforces that three window types are singletons:
2310 * <ul>
2311 * <li>STATUS_BAR_TYPE</li>
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002312 * <li>KEYGUARD_TYPE</li>
2313 * </ul>
RoboErik8a2cfc32014-05-16 11:19:38 -07002314 *
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002315 * @param win The window to be added
2316 * @param attrs Information about the window to be added
RoboErik8a2cfc32014-05-16 11:19:38 -07002317 *
Jeff Brown98365d72012-08-19 20:30:52 -07002318 * @return If ok, WindowManagerImpl.ADD_OKAY. If too many singletons,
2319 * WindowManagerImpl.ADD_MULTIPLE_SINGLETON
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002320 */
Jose Lima9546b202014-07-02 17:21:51 -07002321 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002322 public int prepareAddWindowLw(WindowState win, WindowManager.LayoutParams attrs) {
2323 switch (attrs.type) {
2324 case TYPE_STATUS_BAR:
Joe Onorato8bc6c512010-06-04 16:21:12 -04002325 mContext.enforceCallingOrSelfPermission(
2326 android.Manifest.permission.STATUS_BAR_SERVICE,
2327 "PhoneWindowManager");
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002328 if (mStatusBar != null) {
Dianne Hackbornf87d1962012-04-04 12:48:24 -07002329 if (mStatusBar.isAlive()) {
Jeff Brown98365d72012-08-19 20:30:52 -07002330 return WindowManagerGlobal.ADD_MULTIPLE_SINGLETON;
Dianne Hackbornf87d1962012-04-04 12:48:24 -07002331 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002332 }
2333 mStatusBar = win;
John Spurlock27735a42013-08-14 17:57:38 -04002334 mStatusBarController.setWindow(win);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002335 break;
Daniel Sandler8956dbb2011-04-22 07:55:02 -04002336 case TYPE_NAVIGATION_BAR:
2337 mContext.enforceCallingOrSelfPermission(
2338 android.Manifest.permission.STATUS_BAR_SERVICE,
2339 "PhoneWindowManager");
Dianne Hackbornf87d1962012-04-04 12:48:24 -07002340 if (mNavigationBar != null) {
2341 if (mNavigationBar.isAlive()) {
Jeff Brown98365d72012-08-19 20:30:52 -07002342 return WindowManagerGlobal.ADD_MULTIPLE_SINGLETON;
Dianne Hackbornf87d1962012-04-04 12:48:24 -07002343 }
2344 }
Daniel Sandler8956dbb2011-04-22 07:55:02 -04002345 mNavigationBar = win;
John Spurlock27735a42013-08-14 17:57:38 -04002346 mNavigationBarController.setWindow(win);
Craig Mautnereda67292013-04-28 13:50:14 -07002347 if (DEBUG_LAYOUT) Slog.i(TAG, "NAVIGATION BAR: " + mNavigationBar);
Daniel Sandler8956dbb2011-04-22 07:55:02 -04002348 break;
Jim Millere898ac52012-04-06 17:10:57 -07002349 case TYPE_NAVIGATION_BAR_PANEL:
Dianne Hackborn08743722009-12-21 12:16:51 -08002350 case TYPE_STATUS_BAR_PANEL:
Joe Onorato29fc2c92010-11-24 10:26:50 -08002351 case TYPE_STATUS_BAR_SUB_PANEL:
Jorim Jaggi225d3b52015-04-01 11:18:57 -07002352 case TYPE_VOICE_INTERACTION_STARTING:
Joe Onorato29fc2c92010-11-24 10:26:50 -08002353 mContext.enforceCallingOrSelfPermission(
2354 android.Manifest.permission.STATUS_BAR_SERVICE,
2355 "PhoneWindowManager");
Joe Onorato29fc2c92010-11-24 10:26:50 -08002356 break;
Jim Miller5ecd8112013-01-09 18:50:26 -08002357 case TYPE_KEYGUARD_SCRIM:
Jim Miller25190572013-02-28 17:36:24 -08002358 if (mKeyguardScrim != null) {
2359 return WindowManagerGlobal.ADD_MULTIPLE_SINGLETON;
2360 }
Jim Miller5ecd8112013-01-09 18:50:26 -08002361 mKeyguardScrim = win;
2362 break;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002363 }
Jeff Brown98365d72012-08-19 20:30:52 -07002364 return WindowManagerGlobal.ADD_OKAY;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002365 }
2366
2367 /** {@inheritDoc} */
Jose Lima9546b202014-07-02 17:21:51 -07002368 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002369 public void removeWindowLw(WindowState win) {
2370 if (mStatusBar == win) {
2371 mStatusBar = null;
John Spurlock27735a42013-08-14 17:57:38 -04002372 mStatusBarController.setWindow(null);
Jim Millerc0b676d2013-03-22 16:11:08 -07002373 mKeyguardDelegate.showScrim();
Jim Miller5ecd8112013-01-09 18:50:26 -08002374 } else if (mKeyguardScrim == win) {
2375 Log.v(TAG, "Removing keyguard scrim");
2376 mKeyguardScrim = null;
2377 } if (mNavigationBar == win) {
Daniel Sandler8956dbb2011-04-22 07:55:02 -04002378 mNavigationBar = null;
John Spurlock27735a42013-08-14 17:57:38 -04002379 mNavigationBarController.setWindow(null);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002380 }
2381 }
2382
2383 static final boolean PRINT_ANIM = false;
RoboErik8a2cfc32014-05-16 11:19:38 -07002384
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002385 /** {@inheritDoc} */
Craig Mautner4b71aa12012-12-27 17:20:01 -08002386 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002387 public int selectAnimationLw(WindowState win, int transit) {
2388 if (PRINT_ANIM) Log.i(TAG, "selectAnimation in " + win
2389 + ": transit=" + transit);
Dianne Hackbornf87d1962012-04-04 12:48:24 -07002390 if (win == mStatusBar) {
Jorim Jaggi380ecb82014-03-14 17:25:20 +01002391 boolean isKeyguard = (win.getAttrs().privateFlags & PRIVATE_FLAG_KEYGUARD) != 0;
Craig Mautner4b71aa12012-12-27 17:20:01 -08002392 if (transit == TRANSIT_EXIT
2393 || transit == TRANSIT_HIDE) {
Jorim Jaggi380ecb82014-03-14 17:25:20 +01002394 return isKeyguard ? -1 : R.anim.dock_top_exit;
Craig Mautner4b71aa12012-12-27 17:20:01 -08002395 } else if (transit == TRANSIT_ENTER
2396 || transit == TRANSIT_SHOW) {
Jorim Jaggi380ecb82014-03-14 17:25:20 +01002397 return isKeyguard ? -1 : R.anim.dock_top_enter;
Dianne Hackbornf87d1962012-04-04 12:48:24 -07002398 }
2399 } else if (win == mNavigationBar) {
2400 // This can be on either the bottom or the right.
2401 if (mNavigationBarOnBottom) {
Craig Mautner4b71aa12012-12-27 17:20:01 -08002402 if (transit == TRANSIT_EXIT
2403 || transit == TRANSIT_HIDE) {
Dianne Hackbornf87d1962012-04-04 12:48:24 -07002404 return R.anim.dock_bottom_exit;
Craig Mautner4b71aa12012-12-27 17:20:01 -08002405 } else if (transit == TRANSIT_ENTER
2406 || transit == TRANSIT_SHOW) {
Dianne Hackbornf87d1962012-04-04 12:48:24 -07002407 return R.anim.dock_bottom_enter;
2408 }
2409 } else {
Craig Mautner4b71aa12012-12-27 17:20:01 -08002410 if (transit == TRANSIT_EXIT
2411 || transit == TRANSIT_HIDE) {
Dianne Hackbornf87d1962012-04-04 12:48:24 -07002412 return R.anim.dock_right_exit;
Craig Mautner4b71aa12012-12-27 17:20:01 -08002413 } else if (transit == TRANSIT_ENTER
2414 || transit == TRANSIT_SHOW) {
Dianne Hackbornf87d1962012-04-04 12:48:24 -07002415 return R.anim.dock_right_enter;
2416 }
2417 }
Craig Mautner4b71aa12012-12-27 17:20:01 -08002418 }
2419
2420 if (transit == TRANSIT_PREVIEW_DONE) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002421 if (win.hasAppShownWindows()) {
2422 if (PRINT_ANIM) Log.i(TAG, "**** STARTING EXIT");
2423 return com.android.internal.R.anim.app_starting_exit;
2424 }
Dianne Hackborn7ad44382012-10-18 17:46:00 -07002425 } else if (win.getAttrs().type == TYPE_DREAM && mDreamingLockscreen
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07002426 && transit == TRANSIT_ENTER) {
2427 // Special case: we are animating in a dream, while the keyguard
2428 // is shown. We don't want an animation on the dream, because
2429 // we need it shown immediately with the keyguard animating away
2430 // to reveal it.
2431 return -1;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002432 }
2433
2434 return 0;
2435 }
2436
Craig Mautner3c174372013-02-21 17:54:37 -08002437 @Override
2438 public void selectRotationAnimationLw(int anim[]) {
2439 if (PRINT_ANIM) Slog.i(TAG, "selectRotationAnimation mTopFullscreen="
2440 + mTopFullscreenOpaqueWindowState + " rotationAnimation="
2441 + (mTopFullscreenOpaqueWindowState == null ?
2442 "0" : mTopFullscreenOpaqueWindowState.getAttrs().rotationAnimation));
2443 if (mTopFullscreenOpaqueWindowState != null && mTopIsFullscreen) {
2444 switch (mTopFullscreenOpaqueWindowState.getAttrs().rotationAnimation) {
2445 case ROTATION_ANIMATION_CROSSFADE:
2446 anim[0] = R.anim.rotation_animation_xfade_exit;
2447 anim[1] = R.anim.rotation_animation_enter;
2448 break;
2449 case ROTATION_ANIMATION_JUMPCUT:
2450 anim[0] = R.anim.rotation_animation_jump_exit;
2451 anim[1] = R.anim.rotation_animation_enter;
2452 break;
2453 case ROTATION_ANIMATION_ROTATE:
2454 default:
2455 anim[0] = anim[1] = 0;
2456 break;
2457 }
2458 } else {
2459 anim[0] = anim[1] = 0;
2460 }
2461 }
2462
2463 @Override
2464 public boolean validateRotationAnimationLw(int exitAnimId, int enterAnimId,
2465 boolean forceDefault) {
2466 switch (exitAnimId) {
2467 case R.anim.rotation_animation_xfade_exit:
2468 case R.anim.rotation_animation_jump_exit:
2469 // These are the only cases that matter.
2470 if (forceDefault) {
2471 return false;
2472 }
2473 int anim[] = new int[2];
2474 selectRotationAnimationLw(anim);
2475 return (exitAnimId == anim[0] && enterAnimId == anim[1]);
2476 default:
2477 return true;
2478 }
2479 }
2480
2481 @Override
Jorim Jaggi84a3e7a2014-08-13 17:58:58 +02002482 public Animation createForceHideEnterAnimation(boolean onWallpaper,
2483 boolean goingToNotificationShade) {
2484 if (goingToNotificationShade) {
2485 return AnimationUtils.loadAnimation(mContext, R.anim.lock_screen_behind_enter_fade_in);
Craig Mautnerb8340802014-11-04 15:32:57 -08002486 }
Craig Mautner276a6eb2014-11-04 15:32:57 -08002487
2488 AnimationSet set = (AnimationSet) AnimationUtils.loadAnimation(mContext, onWallpaper ?
2489 R.anim.lock_screen_behind_enter_wallpaper :
2490 R.anim.lock_screen_behind_enter);
2491
2492 // TODO: Use XML interpolators when we have log interpolators available in XML.
2493 final List<Animation> animations = set.getAnimations();
2494 for (int i = animations.size() - 1; i >= 0; --i) {
2495 animations.get(i).setInterpolator(mLogDecelerateInterpolator);
2496 }
2497
2498 return set;
Jorim Jaggi76a16232014-08-08 17:00:47 +02002499 }
2500
2501
2502 @Override
Jorim Jaggi84a3e7a2014-08-13 17:58:58 +02002503 public Animation createForceHideWallpaperExitAnimation(boolean goingToNotificationShade) {
2504 if (goingToNotificationShade) {
2505 return null;
2506 } else {
2507 return AnimationUtils.loadAnimation(mContext, R.anim.lock_screen_wallpaper_exit);
2508 }
Dianne Hackborn01ad2f42009-09-24 19:24:56 -07002509 }
John Spurlockc8b46ca2013-04-08 12:59:26 -04002510
2511 private static void awakenDreams() {
2512 IDreamManager dreamManager = getDreamManager();
2513 if (dreamManager != null) {
2514 try {
2515 dreamManager.awaken();
2516 } catch (RemoteException e) {
2517 // fine, stay asleep then
2518 }
2519 }
2520 }
2521
2522 static IDreamManager getDreamManager() {
2523 return IDreamManager.Stub.asInterface(
2524 ServiceManager.checkService(DreamService.DREAM_SERVICE));
2525 }
2526
Tyler Gunnef9f6f92014-09-12 22:16:17 -07002527 TelecomManager getTelecommService() {
2528 return (TelecomManager) mContext.getSystemService(Context.TELECOM_SERVICE);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002529 }
2530
Jeff Brown4d396052010-10-29 21:50:21 -07002531 static IAudioService getAudioService() {
2532 IAudioService audioService = IAudioService.Stub.asInterface(
2533 ServiceManager.checkService(Context.AUDIO_SERVICE));
2534 if (audioService == null) {
2535 Log.w(TAG, "Unable to find IAudioService interface.");
2536 }
2537 return audioService;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002538 }
2539
2540 boolean keyguardOn() {
Jim Millerab954542014-10-10 18:21:49 -07002541 return isKeyguardShowingAndNotOccluded() || inKeyguardRestrictedKeyInputMode();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002542 }
2543
2544 private static final int[] WINDOW_TYPES_WHERE_HOME_DOESNT_WORK = {
2545 WindowManager.LayoutParams.TYPE_SYSTEM_ALERT,
2546 WindowManager.LayoutParams.TYPE_SYSTEM_ERROR,
2547 };
2548
2549 /** {@inheritDoc} */
Jeff Brown00fa7bd2010-07-02 15:37:36 -07002550 @Override
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002551 public long interceptKeyBeforeDispatching(WindowState win, KeyEvent event, int policyFlags) {
Jeff Brown00fa7bd2010-07-02 15:37:36 -07002552 final boolean keyguardOn = keyguardOn();
Jeff Brown1f245102010-11-18 20:53:46 -08002553 final int keyCode = event.getKeyCode();
2554 final int repeatCount = event.getRepeatCount();
2555 final int metaState = event.getMetaState();
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002556 final int flags = event.getFlags();
Jeff Brown1f245102010-11-18 20:53:46 -08002557 final boolean down = event.getAction() == KeyEvent.ACTION_DOWN;
2558 final boolean canceled = event.isCanceled();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002559
Jeff Brown40013652012-05-16 21:22:36 -07002560 if (DEBUG_INPUT) {
Jeff Brown00fa7bd2010-07-02 15:37:36 -07002561 Log.d(TAG, "interceptKeyTi keyCode=" + keyCode + " down=" + down + " repeatCount="
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002562 + repeatCount + " keyguardOn=" + keyguardOn + " mHomePressed=" + mHomePressed
2563 + " canceled=" + canceled);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002564 }
2565
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002566 // If we think we might have a volume down & power key chord on the way
2567 // but we're not sure, then tell the dispatcher to wait a little while and
2568 // try again later before dispatching.
Christopher Tatee90585f2012-03-05 18:56:25 -08002569 if (mScreenshotChordEnabled && (flags & KeyEvent.FLAG_FALLBACK) == 0) {
Jeff Brown13f00f02014-10-31 14:45:50 -07002570 if (mScreenshotChordVolumeDownKeyTriggered && !mScreenshotChordPowerKeyTriggered) {
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002571 final long now = SystemClock.uptimeMillis();
Jeff Brown13f00f02014-10-31 14:45:50 -07002572 final long timeoutTime = mScreenshotChordVolumeDownKeyTime
2573 + SCREENSHOT_CHORD_DEBOUNCE_DELAY_MILLIS;
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002574 if (now < timeoutTime) {
2575 return timeoutTime - now;
2576 }
2577 }
2578 if (keyCode == KeyEvent.KEYCODE_VOLUME_DOWN
Jeff Brown13f00f02014-10-31 14:45:50 -07002579 && mScreenshotChordVolumeDownKeyConsumed) {
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002580 if (!down) {
Jeff Brown13f00f02014-10-31 14:45:50 -07002581 mScreenshotChordVolumeDownKeyConsumed = false;
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002582 }
2583 return -1;
2584 }
2585 }
2586
Michael Wright6a62e552014-06-03 19:19:48 -07002587 // Cancel any pending meta actions if we see any other keys being pressed between the down
2588 // of the meta key and its corresponding up.
Michael Wright251e35d2014-08-22 15:40:27 -07002589 if (mPendingMetaAction && !KeyEvent.isMetaKey(keyCode)) {
Michael Wright6a62e552014-06-03 19:19:48 -07002590 mPendingMetaAction = false;
2591 }
2592
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002593 // First we always handle the home key here, so applications
2594 // can never break it, although if keyguard is on, we do let
2595 // it handle it, because that gives us the correct 5 second
2596 // timeout.
Jeff Brown00fa7bd2010-07-02 15:37:36 -07002597 if (keyCode == KeyEvent.KEYCODE_HOME) {
Michael Jurka7f2668c2012-03-27 07:49:52 -07002598
Jeff Brown49ed71d2010-12-06 17:13:33 -08002599 // If we have released the home key, and didn't do anything else
2600 // while it was pressed, then it is time to go home!
Michael Jurka7f2668c2012-03-27 07:49:52 -07002601 if (!down) {
Jeff Browncaca8812013-05-09 13:34:33 -07002602 cancelPreloadRecentApps();
2603
Jeff Brown49ed71d2010-12-06 17:13:33 -08002604 mHomePressed = false;
Jeff Browncaca8812013-05-09 13:34:33 -07002605 if (mHomeConsumed) {
2606 mHomeConsumed = false;
Michael Jurka7f2668c2012-03-27 07:49:52 -07002607 return -1;
Jeff Brown49ed71d2010-12-06 17:13:33 -08002608 }
Jeff Browncaca8812013-05-09 13:34:33 -07002609
2610 if (canceled) {
2611 Log.i(TAG, "Ignoring HOME; event canceled.");
2612 return -1;
2613 }
2614
Yorke Lee4f803242014-12-15 23:22:06 +00002615 // If an incoming call is ringing, HOME is totally disabled.
2616 // (The user is already on the InCallUI at this point,
2617 // and his ONLY options are to answer or reject the call.)
2618 TelecomManager telecomManager = getTelecommService();
2619 if (telecomManager != null && telecomManager.isRinging()) {
2620 Log.i(TAG, "Ignoring HOME; there's a ringing incoming call.");
2621 return -1;
2622 }
2623
Jeff Browncaca8812013-05-09 13:34:33 -07002624 // Delay handling home if a double-tap is possible.
2625 if (mDoubleTapOnHomeBehavior != DOUBLE_TAP_HOME_NOTHING) {
2626 mHandler.removeCallbacks(mHomeDoubleTapTimeoutRunnable); // just in case
2627 mHomeDoubleTapPending = true;
2628 mHandler.postDelayed(mHomeDoubleTapTimeoutRunnable,
2629 ViewConfiguration.getDoubleTapTimeout());
2630 return -1;
2631 }
2632
Jeff Brown13f00f02014-10-31 14:45:50 -07002633 handleShortPressOnHome();
Jeff Browncaca8812013-05-09 13:34:33 -07002634 return -1;
Jeff Brown49ed71d2010-12-06 17:13:33 -08002635 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002636
2637 // If a system window has focus, then it doesn't make sense
2638 // right now to interact with applications.
2639 WindowManager.LayoutParams attrs = win != null ? win.getAttrs() : null;
2640 if (attrs != null) {
2641 final int type = attrs.type;
Jorim Jaggi380ecb82014-03-14 17:25:20 +01002642 if (type == WindowManager.LayoutParams.TYPE_KEYGUARD_SCRIM
2643 || type == WindowManager.LayoutParams.TYPE_KEYGUARD_DIALOG
2644 || (attrs.privateFlags & PRIVATE_FLAG_KEYGUARD) != 0) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002645 // the "app" is keyguard, so give it the key
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002646 return 0;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002647 }
2648 final int typeCount = WINDOW_TYPES_WHERE_HOME_DOESNT_WORK.length;
2649 for (int i=0; i<typeCount; i++) {
2650 if (type == WINDOW_TYPES_WHERE_HOME_DOESNT_WORK[i]) {
2651 // don't do anything, but also don't pass it to the app
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002652 return -1;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002653 }
2654 }
2655 }
Jeff Browncaca8812013-05-09 13:34:33 -07002656
2657 // Remember that home is pressed and handle special actions.
2658 if (repeatCount == 0) {
2659 mHomePressed = true;
2660 if (mHomeDoubleTapPending) {
2661 mHomeDoubleTapPending = false;
2662 mHandler.removeCallbacks(mHomeDoubleTapTimeoutRunnable);
2663 handleDoubleTapOnHome();
2664 } else if (mLongPressOnHomeBehavior == LONG_PRESS_HOME_RECENT_SYSTEM_UI
2665 || mDoubleTapOnHomeBehavior == DOUBLE_TAP_HOME_RECENT_SYSTEM_UI) {
2666 preloadRecentApps();
Michael Jurka7f2668c2012-03-27 07:49:52 -07002667 }
Jeff Browncaca8812013-05-09 13:34:33 -07002668 } else if ((event.getFlags() & KeyEvent.FLAG_LONG_PRESS) != 0) {
2669 if (!keyguardOn) {
Tim Kilbourn0e5f1102015-06-05 16:18:09 -07002670 handleLongPressOnHome(event.getDeviceId());
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002671 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002672 }
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002673 return -1;
Jeff Brown00fa7bd2010-07-02 15:37:36 -07002674 } else if (keyCode == KeyEvent.KEYCODE_MENU) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002675 // Hijack modified menu keys for debugging features
2676 final int chordBug = KeyEvent.META_SHIFT_ON;
2677
2678 if (down && repeatCount == 0) {
Jeff Brown00fa7bd2010-07-02 15:37:36 -07002679 if (mEnableShiftMenuBugReports && (metaState & chordBug) == chordBug) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002680 Intent intent = new Intent(Intent.ACTION_BUG_REPORT);
Dianne Hackborn5ac72a22012-08-29 18:32:08 -07002681 mContext.sendOrderedBroadcastAsUser(intent, UserHandle.CURRENT,
2682 null, null, null, 0, null, null);
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002683 return -1;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002684 } else if (SHOW_PROCESSES_ON_ALT_MENU &&
Jeff Brown00fa7bd2010-07-02 15:37:36 -07002685 (metaState & KeyEvent.META_ALT_ON) == KeyEvent.META_ALT_ON) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002686 Intent service = new Intent();
2687 service.setClassName(mContext, "com.android.server.LoadAverageService");
2688 ContentResolver res = mContext.getContentResolver();
Jeff Sharkey8d9a1f62012-10-18 15:38:14 -07002689 boolean shown = Settings.Global.getInt(
2690 res, Settings.Global.SHOW_PROCESSES, 0) != 0;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002691 if (!shown) {
2692 mContext.startService(service);
2693 } else {
2694 mContext.stopService(service);
2695 }
Jeff Sharkey8d9a1f62012-10-18 15:38:14 -07002696 Settings.Global.putInt(
2697 res, Settings.Global.SHOW_PROCESSES, shown ? 0 : 1);
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002698 return -1;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002699 }
2700 }
Jeff Brown00fa7bd2010-07-02 15:37:36 -07002701 } else if (keyCode == KeyEvent.KEYCODE_SEARCH) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002702 if (down) {
2703 if (repeatCount == 0) {
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002704 mSearchKeyShortcutPending = true;
2705 mConsumeSearchKeyUp = false;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002706 }
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002707 } else {
2708 mSearchKeyShortcutPending = false;
2709 if (mConsumeSearchKeyUp) {
2710 mConsumeSearchKeyUp = false;
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002711 return -1;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002712 }
2713 }
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002714 return 0;
Jeff Brown49ed71d2010-12-06 17:13:33 -08002715 } else if (keyCode == KeyEvent.KEYCODE_APP_SWITCH) {
Michael Wrightc9ebea72013-01-16 19:25:02 -08002716 if (!keyguardOn) {
Jeff Browncaca8812013-05-09 13:34:33 -07002717 if (down && repeatCount == 0) {
2718 preloadRecentApps();
2719 } else if (!down) {
2720 toggleRecentApps();
Michael Wrightc9ebea72013-01-16 19:25:02 -08002721 }
Jeff Brown49ed71d2010-12-06 17:13:33 -08002722 }
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002723 return -1;
Jun Mukaid21b3c82015-04-23 14:09:34 -07002724 } else if (keyCode == KeyEvent.KEYCODE_N && event.isMetaPressed()) {
2725 if (down) {
2726 IStatusBarService service = getStatusBarService();
2727 if (service != null) {
2728 try {
2729 service.expandNotificationsPanel();
2730 } catch (RemoteException e) {
2731 // do nothing.
2732 }
2733 }
2734 }
Jeff Brownde7a8ea2012-06-13 18:28:57 -07002735 } else if (keyCode == KeyEvent.KEYCODE_ASSIST) {
2736 if (down) {
2737 if (repeatCount == 0) {
2738 mAssistKeyLongPressed = false;
2739 } else if (repeatCount == 1) {
2740 mAssistKeyLongPressed = true;
2741 if (!keyguardOn) {
2742 launchAssistLongPressAction();
2743 }
2744 }
2745 } else {
2746 if (mAssistKeyLongPressed) {
2747 mAssistKeyLongPressed = false;
2748 } else {
2749 if (!keyguardOn) {
Tim Kilbourn0e5f1102015-06-05 16:18:09 -07002750 launchAssistAction(null, event.getDeviceId());
Jeff Brownde7a8ea2012-06-13 18:28:57 -07002751 }
2752 }
2753 }
2754 return -1;
Michael Wrightdc63f7b2014-08-21 19:05:21 -07002755 } else if (keyCode == KeyEvent.KEYCODE_VOICE_ASSIST) {
2756 if (!down) {
2757 Intent voiceIntent;
Michael Wright869a67c2014-08-26 19:33:06 -07002758 if (!keyguardOn) {
Michael Wrightdc63f7b2014-08-21 19:05:21 -07002759 voiceIntent = new Intent(RecognizerIntent.ACTION_WEB_SEARCH);
2760 } else {
Dianne Hackbornb6683c42015-06-18 17:40:33 -07002761 IDeviceIdleController dic = IDeviceIdleController.Stub.asInterface(
2762 ServiceManager.getService(Context.DEVICE_IDLE_CONTROLLER));
2763 if (dic != null) {
2764 try {
2765 dic.exitIdle("voice-search");
2766 } catch (RemoteException e) {
2767 }
2768 }
Michael Wrightdc63f7b2014-08-21 19:05:21 -07002769 voiceIntent = new Intent(RecognizerIntent.ACTION_VOICE_SEARCH_HANDS_FREE);
Michael Wright869a67c2014-08-26 19:33:06 -07002770 voiceIntent.putExtra(RecognizerIntent.EXTRA_SECURE, true);
Michael Wrightdc63f7b2014-08-21 19:05:21 -07002771 }
Bart Sears8b1c27c2015-03-18 23:51:02 +00002772 startActivityAsUser(voiceIntent, UserHandle.CURRENT_OR_SELF);
Michael Wrightdc63f7b2014-08-21 19:05:21 -07002773 }
Jeff Sharkey2991fa32012-12-05 18:06:43 -08002774 } else if (keyCode == KeyEvent.KEYCODE_SYSRQ) {
2775 if (down && repeatCount == 0) {
2776 mHandler.post(mScreenshotRunnable);
2777 }
2778 return -1;
Michael Wrightb854e242013-02-05 17:54:02 -08002779 } else if (keyCode == KeyEvent.KEYCODE_BRIGHTNESS_UP
2780 || keyCode == KeyEvent.KEYCODE_BRIGHTNESS_DOWN) {
2781 if (down) {
2782 int direction = keyCode == KeyEvent.KEYCODE_BRIGHTNESS_UP ? 1 : -1;
2783
2784 // Disable autobrightness if it's on
2785 int auto = Settings.System.getIntForUser(
2786 mContext.getContentResolver(),
2787 Settings.System.SCREEN_BRIGHTNESS_MODE,
2788 Settings.System.SCREEN_BRIGHTNESS_MODE_MANUAL,
2789 UserHandle.USER_CURRENT_OR_SELF);
2790 if (auto != 0) {
2791 Settings.System.putIntForUser(mContext.getContentResolver(),
2792 Settings.System.SCREEN_BRIGHTNESS_MODE,
2793 Settings.System.SCREEN_BRIGHTNESS_MODE_MANUAL,
2794 UserHandle.USER_CURRENT_OR_SELF);
2795 }
2796
2797 int min = mPowerManager.getMinimumScreenBrightnessSetting();
2798 int max = mPowerManager.getMaximumScreenBrightnessSetting();
2799 int step = (max - min + BRIGHTNESS_STEPS - 1) / BRIGHTNESS_STEPS * direction;
2800 int brightness = Settings.System.getIntForUser(mContext.getContentResolver(),
2801 Settings.System.SCREEN_BRIGHTNESS,
2802 mPowerManager.getDefaultScreenBrightnessSetting(),
2803 UserHandle.USER_CURRENT_OR_SELF);
2804 brightness += step;
2805 // Make sure we don't go beyond the limits.
2806 brightness = Math.min(max, brightness);
2807 brightness = Math.max(min, brightness);
2808
2809 Settings.System.putIntForUser(mContext.getContentResolver(),
2810 Settings.System.SCREEN_BRIGHTNESS, brightness,
2811 UserHandle.USER_CURRENT_OR_SELF);
Bart Sears8b1c27c2015-03-18 23:51:02 +00002812 startActivityAsUser(new Intent(Intent.ACTION_SHOW_BRIGHTNESS_DIALOG),
Alan Viverette5a399492014-07-14 16:19:38 -07002813 UserHandle.CURRENT_OR_SELF);
Michael Wrightb854e242013-02-05 17:54:02 -08002814 }
2815 return -1;
Michael Wrightce0c13a2014-07-30 10:49:21 -07002816 } else if (KeyEvent.isMetaKey(keyCode)) {
Michael Wright6a62e552014-06-03 19:19:48 -07002817 if (down) {
2818 mPendingMetaAction = true;
2819 } else if (mPendingMetaAction) {
Tim Kilbourn0e5f1102015-06-05 16:18:09 -07002820 launchAssistAction(Intent.EXTRA_ASSIST_INPUT_HINT_KEYBOARD, event.getDeviceId());
Michael Wright6a62e552014-06-03 19:19:48 -07002821 }
2822 return -1;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002823 }
Jeff Browncaab4d02010-12-09 22:13:41 -08002824
Jeff Brownc1fb48d2010-12-08 16:52:09 -08002825 // Shortcuts are invoked through Search+key, so intercept those here
Jeff Browncaab4d02010-12-09 22:13:41 -08002826 // Any printing key that is chorded with Search should be consumed
2827 // even if no shortcut was invoked. This prevents text from being
2828 // inadvertently inserted when using a keyboard that has built-in macro
2829 // shortcut keys (that emit Search+x) and some of them are not registered.
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002830 if (mSearchKeyShortcutPending) {
Jeff Browncaab4d02010-12-09 22:13:41 -08002831 final KeyCharacterMap kcm = event.getKeyCharacterMap();
2832 if (kcm.isPrintingKey(keyCode)) {
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002833 mConsumeSearchKeyUp = true;
2834 mSearchKeyShortcutPending = false;
Jeff Browncaab4d02010-12-09 22:13:41 -08002835 if (down && repeatCount == 0 && !keyguardOn) {
2836 Intent shortcutIntent = mShortcutManager.getIntent(kcm, keyCode, metaState);
2837 if (shortcutIntent != null) {
2838 shortcutIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
Jeff Brownf0a3cc52011-01-26 18:42:46 -08002839 try {
Bart Sears8b1c27c2015-03-18 23:51:02 +00002840 startActivityAsUser(shortcutIntent, UserHandle.CURRENT);
Jeff Brownf0a3cc52011-01-26 18:42:46 -08002841 } catch (ActivityNotFoundException ex) {
2842 Slog.w(TAG, "Dropping shortcut key combination because "
2843 + "the activity to which it is registered was not found: "
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002844 + "SEARCH+" + KeyEvent.keyCodeToString(keyCode), ex);
Jeff Brownf0a3cc52011-01-26 18:42:46 -08002845 }
Jeff Browncaab4d02010-12-09 22:13:41 -08002846 } else {
2847 Slog.i(TAG, "Dropping unregistered shortcut key combination: "
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002848 + "SEARCH+" + KeyEvent.keyCodeToString(keyCode));
Jeff Brown49ed71d2010-12-06 17:13:33 -08002849 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002850 }
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002851 return -1;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002852 }
2853 }
2854
Jeff Brown68b909d2011-12-07 16:36:01 -08002855 // Invoke shortcuts using Meta.
Jeff Brown602ab322012-05-16 13:33:47 -07002856 if (down && repeatCount == 0 && !keyguardOn
Jeff Brown68b909d2011-12-07 16:36:01 -08002857 && (metaState & KeyEvent.META_META_ON) != 0) {
2858 final KeyCharacterMap kcm = event.getKeyCharacterMap();
Jeff Brown602ab322012-05-16 13:33:47 -07002859 if (kcm.isPrintingKey(keyCode)) {
2860 Intent shortcutIntent = mShortcutManager.getIntent(kcm, keyCode,
2861 metaState & ~(KeyEvent.META_META_ON
2862 | KeyEvent.META_META_LEFT_ON | KeyEvent.META_META_RIGHT_ON));
2863 if (shortcutIntent != null) {
2864 shortcutIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
2865 try {
Bart Sears8b1c27c2015-03-18 23:51:02 +00002866 startActivityAsUser(shortcutIntent, UserHandle.CURRENT);
Jeff Brown602ab322012-05-16 13:33:47 -07002867 } catch (ActivityNotFoundException ex) {
2868 Slog.w(TAG, "Dropping shortcut key combination because "
2869 + "the activity to which it is registered was not found: "
2870 + "META+" + KeyEvent.keyCodeToString(keyCode), ex);
2871 }
2872 return -1;
Jeff Brown68b909d2011-12-07 16:36:01 -08002873 }
Jeff Brown68b909d2011-12-07 16:36:01 -08002874 }
2875 }
2876
Jeff Brown6651a632011-11-28 12:59:11 -08002877 // Handle application launch keys.
Jeff Brown602ab322012-05-16 13:33:47 -07002878 if (down && repeatCount == 0 && !keyguardOn) {
Jeff Brown6651a632011-11-28 12:59:11 -08002879 String category = sApplicationLaunchKeyCategories.get(keyCode);
2880 if (category != null) {
Dianne Hackbornf5b86712011-12-05 17:42:41 -08002881 Intent intent = Intent.makeMainSelectorActivity(Intent.ACTION_MAIN, category);
Jeff Brown6651a632011-11-28 12:59:11 -08002882 intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
2883 try {
Bart Sears8b1c27c2015-03-18 23:51:02 +00002884 startActivityAsUser(intent, UserHandle.CURRENT);
Jeff Brown6651a632011-11-28 12:59:11 -08002885 } catch (ActivityNotFoundException ex) {
2886 Slog.w(TAG, "Dropping application launch key because "
2887 + "the activity to which it is registered was not found: "
2888 + "keyCode=" + keyCode + ", category=" + category, ex);
2889 }
Jeff Brown68b909d2011-12-07 16:36:01 -08002890 return -1;
Jeff Brown6651a632011-11-28 12:59:11 -08002891 }
2892 }
2893
Michael Wright61c46752014-08-21 16:57:33 -07002894 // Display task switcher for ALT-TAB.
Jeff Brown68b909d2011-12-07 16:36:01 -08002895 if (down && repeatCount == 0 && keyCode == KeyEvent.KEYCODE_TAB) {
Winson Chung1e8d71b2014-05-16 17:05:22 -07002896 if (mRecentAppsHeldModifiers == 0 && !keyguardOn) {
Jeff Brown68b909d2011-12-07 16:36:01 -08002897 final int shiftlessModifiers = event.getModifiers() & ~KeyEvent.META_SHIFT_MASK;
Michael Wright61c46752014-08-21 16:57:33 -07002898 if (KeyEvent.metaStateHasModifiers(shiftlessModifiers, KeyEvent.META_ALT_ON)) {
Winson Chung1e8d71b2014-05-16 17:05:22 -07002899 mRecentAppsHeldModifiers = shiftlessModifiers;
2900 showRecentApps(true);
Jeff Brown68b909d2011-12-07 16:36:01 -08002901 return -1;
2902 }
2903 }
Winson Chung1e8d71b2014-05-16 17:05:22 -07002904 } else if (!down && mRecentAppsHeldModifiers != 0
2905 && (metaState & mRecentAppsHeldModifiers) == 0) {
2906 mRecentAppsHeldModifiers = 0;
Winson Chungcdcd4872014-08-05 18:00:13 -07002907 hideRecentApps(true, false);
Jeff Brown68b909d2011-12-07 16:36:01 -08002908 }
2909
Jeff Browncf39bdf2012-05-18 14:41:19 -07002910 // Handle keyboard language switching.
2911 if (down && repeatCount == 0
2912 && (keyCode == KeyEvent.KEYCODE_LANGUAGE_SWITCH
2913 || (keyCode == KeyEvent.KEYCODE_SPACE
2914 && (metaState & KeyEvent.META_CTRL_MASK) != 0))) {
2915 int direction = (metaState & KeyEvent.META_SHIFT_MASK) != 0 ? -1 : 1;
2916 mWindowManagerFuncs.switchKeyboardLayout(event.getDeviceId(), direction);
2917 return -1;
2918 }
2919 if (mLanguageSwitchKeyPressed && !down
2920 && (keyCode == KeyEvent.KEYCODE_LANGUAGE_SWITCH
2921 || keyCode == KeyEvent.KEYCODE_SPACE)) {
2922 mLanguageSwitchKeyPressed = false;
2923 return -1;
2924 }
2925
Jeff Brown13f00f02014-10-31 14:45:50 -07002926 if (isValidGlobalKey(keyCode)
2927 && mGlobalKeyManager.handleGlobalKey(mContext, keyCode, event)) {
Justin Kohd378ad72013-04-01 12:18:26 -07002928 return -1;
2929 }
2930
Michael Wright6a62e552014-06-03 19:19:48 -07002931 // Reserve all the META modifier combos for system behavior
Michael Wrightce0c13a2014-07-30 10:49:21 -07002932 if ((metaState & KeyEvent.META_META_ON) != 0) {
Michael Wright6a62e552014-06-03 19:19:48 -07002933 return -1;
2934 }
2935
Jeff Brown68b909d2011-12-07 16:36:01 -08002936 // Let the application handle the key.
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002937 return 0;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002938 }
2939
Jeff Brown3915bb82010-11-05 15:02:16 -07002940 /** {@inheritDoc} */
2941 @Override
Jeff Brown49ed71d2010-12-06 17:13:33 -08002942 public KeyEvent dispatchUnhandledKey(WindowState win, KeyEvent event, int policyFlags) {
Jeff Brown54875002011-04-06 15:33:01 -07002943 // Note: This method is only called if the initial down was unhandled.
Jeff Brown40013652012-05-16 21:22:36 -07002944 if (DEBUG_INPUT) {
Jeff Brown1f245102010-11-18 20:53:46 -08002945 Slog.d(TAG, "Unhandled key: win=" + win + ", action=" + event.getAction()
2946 + ", flags=" + event.getFlags()
2947 + ", keyCode=" + event.getKeyCode()
2948 + ", scanCode=" + event.getScanCode()
2949 + ", metaState=" + event.getMetaState()
2950 + ", repeatCount=" + event.getRepeatCount()
2951 + ", policyFlags=" + policyFlags);
Jeff Brown3915bb82010-11-05 15:02:16 -07002952 }
Jeff Brown49ed71d2010-12-06 17:13:33 -08002953
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002954 KeyEvent fallbackEvent = null;
Jeff Brown49ed71d2010-12-06 17:13:33 -08002955 if ((event.getFlags() & KeyEvent.FLAG_FALLBACK) == 0) {
2956 final KeyCharacterMap kcm = event.getKeyCharacterMap();
Jeff Brownc1fb48d2010-12-08 16:52:09 -08002957 final int keyCode = event.getKeyCode();
2958 final int metaState = event.getMetaState();
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002959 final boolean initialDown = event.getAction() == KeyEvent.ACTION_DOWN
2960 && event.getRepeatCount() == 0;
Jeff Brown49ed71d2010-12-06 17:13:33 -08002961
Jeff Brown54875002011-04-06 15:33:01 -07002962 // Check for fallback actions specified by the key character map.
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002963 final FallbackAction fallbackAction;
2964 if (initialDown) {
2965 fallbackAction = kcm.getFallbackAction(keyCode, metaState);
2966 } else {
2967 fallbackAction = mFallbackActions.get(keyCode);
2968 }
2969
2970 if (fallbackAction != null) {
Jeff Brown40013652012-05-16 21:22:36 -07002971 if (DEBUG_INPUT) {
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002972 Slog.d(TAG, "Fallback: keyCode=" + fallbackAction.keyCode
2973 + " metaState=" + Integer.toHexString(fallbackAction.metaState));
Jeff Brown49ed71d2010-12-06 17:13:33 -08002974 }
2975
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002976 final int flags = event.getFlags() | KeyEvent.FLAG_FALLBACK;
2977 fallbackEvent = KeyEvent.obtain(
Jeff Brown49ed71d2010-12-06 17:13:33 -08002978 event.getDownTime(), event.getEventTime(),
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002979 event.getAction(), fallbackAction.keyCode,
2980 event.getRepeatCount(), fallbackAction.metaState,
Jeff Brown49ed71d2010-12-06 17:13:33 -08002981 event.getDeviceId(), event.getScanCode(),
2982 flags, event.getSource(), null);
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002983
2984 if (!interceptFallback(win, fallbackEvent, policyFlags)) {
2985 fallbackEvent.recycle();
2986 fallbackEvent = null;
Jeff Brown49ed71d2010-12-06 17:13:33 -08002987 }
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002988
2989 if (initialDown) {
2990 mFallbackActions.put(keyCode, fallbackAction);
2991 } else if (event.getAction() == KeyEvent.ACTION_UP) {
2992 mFallbackActions.remove(keyCode);
2993 fallbackAction.recycle();
2994 }
Jeff Brown49ed71d2010-12-06 17:13:33 -08002995 }
2996 }
2997
Jeff Brown40013652012-05-16 21:22:36 -07002998 if (DEBUG_INPUT) {
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002999 if (fallbackEvent == null) {
3000 Slog.d(TAG, "No fallback.");
3001 } else {
3002 Slog.d(TAG, "Performing fallback: " + fallbackEvent);
3003 }
Jeff Brown49ed71d2010-12-06 17:13:33 -08003004 }
Jeff Brownfd23e3e2012-05-09 13:34:28 -07003005 return fallbackEvent;
Jeff Brown3915bb82010-11-05 15:02:16 -07003006 }
3007
Jeff Brownfd23e3e2012-05-09 13:34:28 -07003008 private boolean interceptFallback(WindowState win, KeyEvent fallbackEvent, int policyFlags) {
Jeff Brown037c33e2014-04-09 00:31:55 -07003009 int actions = interceptKeyBeforeQueueing(fallbackEvent, policyFlags);
Jeff Brownfd23e3e2012-05-09 13:34:28 -07003010 if ((actions & ACTION_PASS_TO_USER) != 0) {
3011 long delayMillis = interceptKeyBeforeDispatching(
3012 win, fallbackEvent, policyFlags);
3013 if (delayMillis == 0) {
3014 return true;
3015 }
3016 }
3017 return false;
Jeff Brown6f2fba42011-02-19 01:08:02 -08003018 }
3019
Jeff Brownde7a8ea2012-06-13 18:28:57 -07003020 private void launchAssistLongPressAction() {
3021 performHapticFeedbackLw(null, HapticFeedbackConstants.LONG_PRESS, false);
3022 sendCloseSystemWindows(SYSTEM_DIALOG_REASON_ASSIST);
3023
3024 // launch the search activity
3025 Intent intent = new Intent(Intent.ACTION_SEARCH_LONG_PRESS);
3026 intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
3027 try {
RoboErik8a2cfc32014-05-16 11:19:38 -07003028 // TODO: This only stops the factory-installed search manager.
Jim Miller45308b12012-06-18 19:23:39 -07003029 // Need to formalize an API to handle others
Jeff Brownde7a8ea2012-06-13 18:28:57 -07003030 SearchManager searchManager = getSearchManager();
3031 if (searchManager != null) {
3032 searchManager.stopSearch();
3033 }
Bart Sears8b1c27c2015-03-18 23:51:02 +00003034 startActivityAsUser(intent, UserHandle.CURRENT);
Jeff Brownde7a8ea2012-06-13 18:28:57 -07003035 } catch (ActivityNotFoundException e) {
3036 Slog.w(TAG, "No activity to handle assist long press action.", e);
3037 }
3038 }
3039
3040 private void launchAssistAction() {
Tim Kilbourn0e5f1102015-06-05 16:18:09 -07003041 launchAssistAction(null, Integer.MIN_VALUE);
Michael Wright8ab940a2014-09-01 11:01:27 -07003042 }
3043
3044 private void launchAssistAction(String hint) {
Tim Kilbourn0e5f1102015-06-05 16:18:09 -07003045 launchAssistAction(hint, Integer.MIN_VALUE);
3046 }
3047
3048 private void launchAssistAction(String hint, int deviceId) {
Jeff Brownde7a8ea2012-06-13 18:28:57 -07003049 sendCloseSystemWindows(SYSTEM_DIALOG_REASON_ASSIST);
Tim Kilbourn0e5f1102015-06-05 16:18:09 -07003050 Bundle args = null;
3051 if (deviceId > Integer.MIN_VALUE) {
3052 args = new Bundle();
3053 args.putInt(Intent.EXTRA_ASSIST_INPUT_DEVICE_ID, deviceId);
Jeff Brownde7a8ea2012-06-13 18:28:57 -07003054 }
Tim Kilbourn0e5f1102015-06-05 16:18:09 -07003055 ((SearchManager) mContext.getSystemService(Context.SEARCH_SERVICE))
3056 .launchAssistAction(hint, UserHandle.myUserId(), args);
Jeff Brownde7a8ea2012-06-13 18:28:57 -07003057 }
3058
Bart Sears8b1c27c2015-03-18 23:51:02 +00003059 private void startActivityAsUser(Intent intent, UserHandle handle) {
3060 if (isUserSetupComplete()) {
3061 mContext.startActivityAsUser(intent, handle);
3062 } else {
3063 Slog.i(TAG, "Not starting activity because user setup is in progress: " + intent);
3064 }
3065 }
3066
Jeff Brownde7a8ea2012-06-13 18:28:57 -07003067 private SearchManager getSearchManager() {
3068 if (mSearchManager == null) {
3069 mSearchManager = (SearchManager) mContext.getSystemService(Context.SEARCH_SERVICE);
3070 }
3071 return mSearchManager;
3072 }
3073
Jeff Browncaca8812013-05-09 13:34:33 -07003074 private void preloadRecentApps() {
3075 mPreloadedRecentApps = true;
3076 try {
3077 IStatusBarService statusbar = getStatusBarService();
3078 if (statusbar != null) {
3079 statusbar.preloadRecentApps();
3080 }
3081 } catch (RemoteException e) {
3082 Slog.e(TAG, "RemoteException when preloading recent apps", e);
3083 // re-acquire status bar service next time it is needed.
3084 mStatusBarService = null;
3085 }
3086 }
3087
3088 private void cancelPreloadRecentApps() {
3089 if (mPreloadedRecentApps) {
3090 mPreloadedRecentApps = false;
3091 try {
3092 IStatusBarService statusbar = getStatusBarService();
3093 if (statusbar != null) {
3094 statusbar.cancelPreloadRecentApps();
3095 }
3096 } catch (RemoteException e) {
Winson Chung1e8d71b2014-05-16 17:05:22 -07003097 Slog.e(TAG, "RemoteException when cancelling recent apps preload", e);
Jeff Browncaca8812013-05-09 13:34:33 -07003098 // re-acquire status bar service next time it is needed.
3099 mStatusBarService = null;
3100 }
3101 }
3102 }
3103
3104 private void toggleRecentApps() {
3105 mPreloadedRecentApps = false; // preloading no longer needs to be canceled
Jeff Browncaca8812013-05-09 13:34:33 -07003106 try {
3107 IStatusBarService statusbar = getStatusBarService();
3108 if (statusbar != null) {
3109 statusbar.toggleRecentApps();
3110 }
3111 } catch (RemoteException e) {
Winson Chung1e8d71b2014-05-16 17:05:22 -07003112 Slog.e(TAG, "RemoteException when toggling recent apps", e);
3113 // re-acquire status bar service next time it is needed.
3114 mStatusBarService = null;
3115 }
3116 }
3117
Craig Mautner84984fa2014-06-19 11:19:20 -07003118 @Override
3119 public void showRecentApps() {
3120 mHandler.removeMessages(MSG_DISPATCH_SHOW_RECENTS);
3121 mHandler.sendEmptyMessage(MSG_DISPATCH_SHOW_RECENTS);
3122 }
3123
Winson Chung1e8d71b2014-05-16 17:05:22 -07003124 private void showRecentApps(boolean triggeredFromAltTab) {
3125 mPreloadedRecentApps = false; // preloading no longer needs to be canceled
3126 try {
3127 IStatusBarService statusbar = getStatusBarService();
3128 if (statusbar != null) {
3129 statusbar.showRecentApps(triggeredFromAltTab);
3130 }
3131 } catch (RemoteException e) {
Jeff Browncaca8812013-05-09 13:34:33 -07003132 Slog.e(TAG, "RemoteException when showing recent apps", e);
3133 // re-acquire status bar service next time it is needed.
3134 mStatusBarService = null;
3135 }
3136 }
3137
Winson Chungcdcd4872014-08-05 18:00:13 -07003138 private void hideRecentApps(boolean triggeredFromAltTab, boolean triggeredFromHome) {
Winson Chung1e8d71b2014-05-16 17:05:22 -07003139 mPreloadedRecentApps = false; // preloading no longer needs to be canceled
3140 try {
3141 IStatusBarService statusbar = getStatusBarService();
3142 if (statusbar != null) {
Winson Chungcdcd4872014-08-05 18:00:13 -07003143 statusbar.hideRecentApps(triggeredFromAltTab, triggeredFromHome);
Winson Chung1e8d71b2014-05-16 17:05:22 -07003144 }
3145 } catch (RemoteException e) {
3146 Slog.e(TAG, "RemoteException when closing recent apps", e);
3147 // re-acquire status bar service next time it is needed.
3148 mStatusBarService = null;
3149 }
3150 }
3151
Filip Gruszczynskia483a1d2015-03-17 19:06:58 +00003152 void launchHomeFromHotKey() {
Bryce Lee662ed802015-04-10 20:11:39 +00003153 launchHomeFromHotKey(true /* awakenFromDreams */, true /*respectKeyguard*/);
Filip Gruszczynskia483a1d2015-03-17 19:06:58 +00003154 }
3155
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003156 /**
3157 * A home key -> launch home action was detected. Take the appropriate action
3158 * given the situation with the keyguard.
3159 */
Bryce Lee662ed802015-04-10 20:11:39 +00003160 void launchHomeFromHotKey(final boolean awakenFromDreams, final boolean respectKeyguard) {
3161 if (respectKeyguard) {
3162 if (isKeyguardShowingAndNotOccluded()) {
3163 // don't launch home if keyguard showing
3164 return;
3165 }
3166
3167 if (!mHideLockScreen && mKeyguardDelegate.isInputRestricted()) {
3168 // when in keyguard restricted mode, must first verify unlock
3169 // before launching home
3170 mKeyguardDelegate.verifyUnlock(new OnKeyguardExitResult() {
3171 @Override
3172 public void onKeyguardExitResult(boolean success) {
3173 if (success) {
3174 try {
3175 ActivityManagerNative.getDefault().stopAppSwitches();
3176 } catch (RemoteException e) {
3177 }
3178 sendCloseSystemWindows(SYSTEM_DIALOG_REASON_HOME_KEY);
3179 startDockOrHome(true /*fromHomeKey*/, awakenFromDreams);
Dianne Hackborn256dd3b2009-05-19 18:51:21 -07003180 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003181 }
Bryce Lee662ed802015-04-10 20:11:39 +00003182 });
3183 return;
3184 }
3185 }
3186
3187 // no keyguard stuff to worry about, just launch home!
3188 try {
3189 ActivityManagerNative.getDefault().stopAppSwitches();
3190 } catch (RemoteException e) {
3191 }
3192 if (mRecentsVisible) {
3193 // Hide Recents and notify it to launch Home
3194 if (awakenFromDreams) {
3195 awakenDreams();
3196 }
3197 sendCloseSystemWindows(SYSTEM_DIALOG_REASON_HOME_KEY);
3198 hideRecentApps(false, true);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003199 } else {
Bryce Lee662ed802015-04-10 20:11:39 +00003200 // Otherwise, just launch Home
3201 sendCloseSystemWindows(SYSTEM_DIALOG_REASON_HOME_KEY);
3202 startDockOrHome(true /*fromHomeKey*/, awakenFromDreams);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003203 }
3204 }
3205
John Spurlock04db1762013-05-13 12:46:41 -04003206 private final Runnable mClearHideNavigationFlag = new Runnable() {
3207 @Override
3208 public void run() {
3209 synchronized (mWindowManagerFuncs.getWindowManagerLock()) {
3210 // Clear flags.
3211 mForceClearedSystemUiFlags &=
3212 ~View.SYSTEM_UI_FLAG_HIDE_NAVIGATION;
3213 }
3214 mWindowManagerFuncs.reevaluateStatusBarVisibility();
Dianne Hackborne26ab702011-10-16 13:21:33 -07003215 }
3216 };
3217
3218 /**
3219 * Input handler used while nav bar is hidden. Captures any touch on the screen,
3220 * to determine when the nav bar should be shown and prevent applications from
3221 * receiving those touches.
3222 */
Jeff Brown32cbc38552011-12-01 14:01:49 -08003223 final class HideNavInputEventReceiver extends InputEventReceiver {
3224 public HideNavInputEventReceiver(InputChannel inputChannel, Looper looper) {
3225 super(inputChannel, looper);
3226 }
3227
Dianne Hackborndf89e652011-10-06 22:35:11 -07003228 @Override
Jeff Brown32cbc38552011-12-01 14:01:49 -08003229 public void onInputEvent(InputEvent event) {
Dianne Hackborndf89e652011-10-06 22:35:11 -07003230 boolean handled = false;
3231 try {
Jeff Brown4952dfd2011-11-30 19:23:22 -08003232 if (event instanceof MotionEvent
3233 && (event.getSource() & InputDevice.SOURCE_CLASS_POINTER) != 0) {
3234 final MotionEvent motionEvent = (MotionEvent)event;
3235 if (motionEvent.getAction() == MotionEvent.ACTION_DOWN) {
Dianne Hackborndf89e652011-10-06 22:35:11 -07003236 // When the user taps down, we re-show the nav bar.
3237 boolean changed = false;
John Spurlock04db1762013-05-13 12:46:41 -04003238 synchronized (mWindowManagerFuncs.getWindowManagerLock()) {
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07003239 // Any user activity always causes us to show the
3240 // navigation controls, if they had been hidden.
3241 // We also clear the low profile and only content
3242 // flags so that tapping on the screen will atomically
3243 // restore all currently hidden screen decorations.
3244 int newVal = mResettingSystemUiFlags |
3245 View.SYSTEM_UI_FLAG_HIDE_NAVIGATION |
3246 View.SYSTEM_UI_FLAG_LOW_PROFILE |
3247 View.SYSTEM_UI_FLAG_FULLSCREEN;
Dianne Hackborne26ab702011-10-16 13:21:33 -07003248 if (mResettingSystemUiFlags != newVal) {
3249 mResettingSystemUiFlags = newVal;
Dianne Hackborndf89e652011-10-06 22:35:11 -07003250 changed = true;
3251 }
Dianne Hackborne26ab702011-10-16 13:21:33 -07003252 // We don't allow the system's nav bar to be hidden
3253 // again for 1 second, to prevent applications from
3254 // spamming us and keeping it from being shown.
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07003255 newVal = mForceClearedSystemUiFlags |
3256 View.SYSTEM_UI_FLAG_HIDE_NAVIGATION;
Dianne Hackborne26ab702011-10-16 13:21:33 -07003257 if (mForceClearedSystemUiFlags != newVal) {
3258 mForceClearedSystemUiFlags = newVal;
3259 changed = true;
John Spurlock04db1762013-05-13 12:46:41 -04003260 mHandler.postDelayed(mClearHideNavigationFlag, 1000);
Dianne Hackborne26ab702011-10-16 13:21:33 -07003261 }
Dianne Hackborndf89e652011-10-06 22:35:11 -07003262 }
3263 if (changed) {
3264 mWindowManagerFuncs.reevaluateStatusBarVisibility();
3265 }
3266 }
3267 }
3268 } finally {
Jeff Brown32cbc38552011-12-01 14:01:49 -08003269 finishInputEvent(event, handled);
Dianne Hackborndf89e652011-10-06 22:35:11 -07003270 }
3271 }
Jeff Brown32cbc38552011-12-01 14:01:49 -08003272 }
3273 final InputEventReceiver.Factory mHideNavInputEventReceiverFactory =
3274 new InputEventReceiver.Factory() {
3275 @Override
3276 public InputEventReceiver createInputEventReceiver(
3277 InputChannel inputChannel, Looper looper) {
3278 return new HideNavInputEventReceiver(inputChannel, looper);
3279 }
Dianne Hackborndf89e652011-10-06 22:35:11 -07003280 };
3281
3282 @Override
3283 public int adjustSystemUiVisibilityLw(int visibility) {
John Spurlock5b9145b2013-08-20 15:13:47 -04003284 mStatusBarController.adjustSystemUiVisibilityLw(mLastSystemUiFlags, visibility);
3285 mNavigationBarController.adjustSystemUiVisibilityLw(mLastSystemUiFlags, visibility);
Winson Chungd42a6cf2014-06-03 16:24:04 -07003286 mRecentsVisible = (visibility & View.RECENT_APPS_VISIBLE) > 0;
John Spurlock27735a42013-08-14 17:57:38 -04003287
Dianne Hackborndf89e652011-10-06 22:35:11 -07003288 // Reset any bits in mForceClearingStatusBarVisibility that
3289 // are now clear.
Dianne Hackborne26ab702011-10-16 13:21:33 -07003290 mResettingSystemUiFlags &= visibility;
Dianne Hackborndf89e652011-10-06 22:35:11 -07003291 // Clear any bits in the new visibility that are currently being
3292 // force cleared, before reporting it.
Dianne Hackborne26ab702011-10-16 13:21:33 -07003293 return visibility & ~mResettingSystemUiFlags
3294 & ~mForceClearedSystemUiFlags;
Dianne Hackborndf89e652011-10-06 22:35:11 -07003295 }
3296
Craig Mautner69b08182012-09-05 13:07:13 -07003297 @Override
Adrian Roos37d7a682014-11-06 18:15:16 +01003298 public void getInsetHintLw(WindowManager.LayoutParams attrs, Rect outContentInsets,
3299 Rect outStableInsets) {
John Spurlockc6d1c602014-01-17 15:22:06 -05003300 final int fl = PolicyControl.getWindowFlags(null, attrs);
John Spurlock1db8b682014-02-18 11:18:59 -05003301 final int sysuiVis = PolicyControl.getSystemUiVisibility(null, attrs);
3302 final int systemUiVisibility = (sysuiVis | attrs.subtreeSystemUiVisibility);
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07003303
Dianne Hackborn5b5cc4d2012-05-16 13:15:00 -07003304 if ((fl & (FLAG_LAYOUT_IN_SCREEN | FLAG_LAYOUT_INSET_DECOR))
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003305 == (FLAG_LAYOUT_IN_SCREEN | FLAG_LAYOUT_INSET_DECOR)) {
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07003306 int availRight, availBottom;
Alan Viverette5a0f4ec2013-10-07 15:10:29 -07003307 if (canHideNavigationBar() &&
Dianne Hackborn5b5cc4d2012-05-16 13:15:00 -07003308 (systemUiVisibility & View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION) != 0) {
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07003309 availRight = mUnrestrictedScreenLeft + mUnrestrictedScreenWidth;
3310 availBottom = mUnrestrictedScreenTop + mUnrestrictedScreenHeight;
3311 } else {
3312 availRight = mRestrictedScreenLeft + mRestrictedScreenWidth;
3313 availBottom = mRestrictedScreenTop + mRestrictedScreenHeight;
3314 }
Dianne Hackborn5b5cc4d2012-05-16 13:15:00 -07003315 if ((systemUiVisibility & View.SYSTEM_UI_FLAG_LAYOUT_STABLE) != 0) {
3316 if ((fl & FLAG_FULLSCREEN) != 0) {
Adrian Roos37d7a682014-11-06 18:15:16 +01003317 outContentInsets.set(mStableFullscreenLeft, mStableFullscreenTop,
Dianne Hackborn5b5cc4d2012-05-16 13:15:00 -07003318 availRight - mStableFullscreenRight,
3319 availBottom - mStableFullscreenBottom);
3320 } else {
Adrian Roos37d7a682014-11-06 18:15:16 +01003321 outContentInsets.set(mStableLeft, mStableTop,
Dianne Hackborn5b5cc4d2012-05-16 13:15:00 -07003322 availRight - mStableRight, availBottom - mStableBottom);
3323 }
Dianne Hackbornc652de82013-02-15 16:32:56 -08003324 } else if ((fl & FLAG_FULLSCREEN) != 0 || (fl & FLAG_LAYOUT_IN_OVERSCAN) != 0) {
Adrian Roos37d7a682014-11-06 18:15:16 +01003325 outContentInsets.setEmpty();
Dianne Hackborn5b5cc4d2012-05-16 13:15:00 -07003326 } else if ((systemUiVisibility & (View.SYSTEM_UI_FLAG_FULLSCREEN
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07003327 | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN)) == 0) {
Adrian Roos37d7a682014-11-06 18:15:16 +01003328 outContentInsets.set(mCurLeft, mCurTop,
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07003329 availRight - mCurRight, availBottom - mCurBottom);
3330 } else {
Adrian Roos37d7a682014-11-06 18:15:16 +01003331 outContentInsets.set(mCurLeft, mCurTop,
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07003332 availRight - mCurRight, availBottom - mCurBottom);
3333 }
Adrian Roos37d7a682014-11-06 18:15:16 +01003334
3335 outStableInsets.set(mStableLeft, mStableTop,
3336 availRight - mStableRight, availBottom - mStableBottom);
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07003337 return;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003338 }
Adrian Roos37d7a682014-11-06 18:15:16 +01003339 outContentInsets.setEmpty();
3340 outStableInsets.setEmpty();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003341 }
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07003342
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003343 /** {@inheritDoc} */
Craig Mautner69b08182012-09-05 13:07:13 -07003344 @Override
3345 public void beginLayoutLw(boolean isDefaultDisplay, int displayWidth, int displayHeight,
3346 int displayRotation) {
Dianne Hackbornc652de82013-02-15 16:32:56 -08003347 final int overscanLeft, overscanTop, overscanRight, overscanBottom;
3348 if (isDefaultDisplay) {
3349 switch (displayRotation) {
3350 case Surface.ROTATION_90:
3351 overscanLeft = mOverscanTop;
3352 overscanTop = mOverscanRight;
3353 overscanRight = mOverscanBottom;
3354 overscanBottom = mOverscanLeft;
3355 break;
3356 case Surface.ROTATION_180:
3357 overscanLeft = mOverscanRight;
3358 overscanTop = mOverscanBottom;
3359 overscanRight = mOverscanLeft;
3360 overscanBottom = mOverscanTop;
3361 break;
3362 case Surface.ROTATION_270:
3363 overscanLeft = mOverscanBottom;
3364 overscanTop = mOverscanLeft;
3365 overscanRight = mOverscanTop;
3366 overscanBottom = mOverscanRight;
3367 break;
3368 default:
3369 overscanLeft = mOverscanLeft;
3370 overscanTop = mOverscanTop;
3371 overscanRight = mOverscanRight;
3372 overscanBottom = mOverscanBottom;
3373 break;
3374 }
3375 } else {
3376 overscanLeft = 0;
3377 overscanTop = 0;
3378 overscanRight = 0;
3379 overscanBottom = 0;
3380 }
Dianne Hackborn313440842013-02-19 19:22:59 -08003381 mOverscanScreenLeft = mRestrictedOverscanScreenLeft = 0;
3382 mOverscanScreenTop = mRestrictedOverscanScreenTop = 0;
3383 mOverscanScreenWidth = mRestrictedOverscanScreenWidth = displayWidth;
3384 mOverscanScreenHeight = mRestrictedOverscanScreenHeight = displayHeight;
Dianne Hackbornc652de82013-02-15 16:32:56 -08003385 mSystemLeft = 0;
3386 mSystemTop = 0;
3387 mSystemRight = displayWidth;
3388 mSystemBottom = displayHeight;
3389 mUnrestrictedScreenLeft = overscanLeft;
3390 mUnrestrictedScreenTop = overscanTop;
3391 mUnrestrictedScreenWidth = displayWidth - overscanLeft - overscanRight;
3392 mUnrestrictedScreenHeight = displayHeight - overscanTop - overscanBottom;
3393 mRestrictedScreenLeft = mUnrestrictedScreenLeft;
3394 mRestrictedScreenTop = mUnrestrictedScreenTop;
John Spurlockad3e6cb2013-04-30 08:47:43 -04003395 mRestrictedScreenWidth = mSystemGestures.screenWidth = mUnrestrictedScreenWidth;
3396 mRestrictedScreenHeight = mSystemGestures.screenHeight = mUnrestrictedScreenHeight;
Dianne Hackborne30e02f2014-05-27 18:24:45 -07003397 mDockLeft = mContentLeft = mVoiceContentLeft = mStableLeft = mStableFullscreenLeft
Dianne Hackbornc652de82013-02-15 16:32:56 -08003398 = mCurLeft = mUnrestrictedScreenLeft;
Dianne Hackborne30e02f2014-05-27 18:24:45 -07003399 mDockTop = mContentTop = mVoiceContentTop = mStableTop = mStableFullscreenTop
Dianne Hackbornc652de82013-02-15 16:32:56 -08003400 = mCurTop = mUnrestrictedScreenTop;
Dianne Hackborne30e02f2014-05-27 18:24:45 -07003401 mDockRight = mContentRight = mVoiceContentRight = mStableRight = mStableFullscreenRight
Dianne Hackbornc652de82013-02-15 16:32:56 -08003402 = mCurRight = displayWidth - overscanRight;
Dianne Hackborne30e02f2014-05-27 18:24:45 -07003403 mDockBottom = mContentBottom = mVoiceContentBottom = mStableBottom = mStableFullscreenBottom
Dianne Hackbornc652de82013-02-15 16:32:56 -08003404 = mCurBottom = displayHeight - overscanBottom;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003405 mDockLayer = 0x10000000;
Dianne Hackborn5c58de32012-04-28 19:52:37 -07003406 mStatusBarLayer = -1;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003407
Daniel Sandler8956dbb2011-04-22 07:55:02 -04003408 // start with the current dock rect, which will be (0,0,displayWidth,displayHeight)
3409 final Rect pf = mTmpParentFrame;
3410 final Rect df = mTmpDisplayFrame;
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003411 final Rect of = mTmpOverscanFrame;
Daniel Sandler8956dbb2011-04-22 07:55:02 -04003412 final Rect vf = mTmpVisibleFrame;
John Spurlock46646232013-09-30 22:32:42 -04003413 final Rect dcf = mTmpDecorFrame;
Filip Gruszczynski2217f612015-05-26 11:32:08 -07003414 final Rect osf = mTmpOutsetFrame;
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003415 pf.left = df.left = of.left = vf.left = mDockLeft;
3416 pf.top = df.top = of.top = vf.top = mDockTop;
3417 pf.right = df.right = of.right = vf.right = mDockRight;
3418 pf.bottom = df.bottom = of.bottom = vf.bottom = mDockBottom;
John Spurlock46646232013-09-30 22:32:42 -04003419 dcf.setEmpty(); // Decor frame N/A for system bars.
Daniel Sandler8956dbb2011-04-22 07:55:02 -04003420
Craig Mautner69b08182012-09-05 13:07:13 -07003421 if (isDefaultDisplay) {
3422 // For purposes of putting out fake window up to steal focus, we will
3423 // drive nav being hidden only by whether it is requested.
John Spurlocke1f366f2013-08-05 12:22:40 -04003424 final int sysui = mLastSystemUiFlags;
3425 boolean navVisible = (sysui & View.SYSTEM_UI_FLAG_HIDE_NAVIGATION) == 0;
Adrian Roosea562512014-05-05 13:33:03 +02003426 boolean navTranslucent = (sysui
3427 & (View.NAVIGATION_BAR_TRANSLUCENT | View.SYSTEM_UI_TRANSPARENT)) != 0;
John Spurlockf1a36642013-10-12 17:50:42 -04003428 boolean immersive = (sysui & View.SYSTEM_UI_FLAG_IMMERSIVE) != 0;
3429 boolean immersiveSticky = (sysui & View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY) != 0;
3430 boolean navAllowedHidden = immersive || immersiveSticky;
3431 navTranslucent &= !immersiveSticky; // transient trumps translucent
Adrian Roos4fb3ee32014-08-22 19:29:09 +02003432 boolean isKeyguardShowing = isStatusBarKeyguard() && !mHideLockScreen;
3433 if (!isKeyguardShowing) {
3434 navTranslucent &= areTranslucentBarsAllowed();
3435 }
Dianne Hackborne26ab702011-10-16 13:21:33 -07003436
Craig Mautner69b08182012-09-05 13:07:13 -07003437 // When the navigation bar isn't visible, we put up a fake
3438 // input window to catch all touch events. This way we can
3439 // detect when the user presses anywhere to bring back the nav
3440 // bar and ensure the application doesn't see the event.
John Spurlockf1a36642013-10-12 17:50:42 -04003441 if (navVisible || navAllowedHidden) {
Selim Cinekf83e8242015-05-19 18:08:14 -07003442 if (mInputConsumer != null) {
3443 mInputConsumer.dismiss();
3444 mInputConsumer = null;
Craig Mautner69b08182012-09-05 13:07:13 -07003445 }
Selim Cinekf83e8242015-05-19 18:08:14 -07003446 } else if (mInputConsumer == null) {
3447 mInputConsumer = mWindowManagerFuncs.addInputConsumer(mHandler.getLooper(),
3448 mHideNavInputEventReceiverFactory);
Dianne Hackborne26ab702011-10-16 13:21:33 -07003449 }
Dianne Hackborne26ab702011-10-16 13:21:33 -07003450
Craig Mautner69b08182012-09-05 13:07:13 -07003451 // For purposes of positioning and showing the nav bar, if we have
3452 // decided that it can't be hidden (because of the screen aspect ratio),
3453 // then take that into account.
Alan Viverette5a0f4ec2013-10-07 15:10:29 -07003454 navVisible |= !canHideNavigationBar();
Dianne Hackbornf87d1962012-04-04 12:48:24 -07003455
John Spurlockad3e6cb2013-04-30 08:47:43 -04003456 boolean updateSysUiVisibility = false;
Craig Mautner69b08182012-09-05 13:07:13 -07003457 if (mNavigationBar != null) {
John Spurlock27735a42013-08-14 17:57:38 -04003458 boolean transientNavBarShowing = mNavigationBarController.isTransientShowing();
Craig Mautner69b08182012-09-05 13:07:13 -07003459 // Force the navigation bar to its appropriate place and
3460 // size. We need to do this directly, instead of relying on
3461 // it to bubble up from the nav bar, because this needs to
3462 // change atomically with screen rotations.
3463 mNavigationBarOnBottom = (!mNavigationBarCanMove || displayWidth < displayHeight);
3464 if (mNavigationBarOnBottom) {
3465 // It's a system nav bar or a portrait screen; nav bar goes on bottom.
Dianne Hackbornc652de82013-02-15 16:32:56 -08003466 int top = displayHeight - overscanBottom
3467 - mNavigationBarHeightForRotation[displayRotation];
3468 mTmpNavigationFrame.set(0, top, displayWidth, displayHeight - overscanBottom);
Craig Mautner69b08182012-09-05 13:07:13 -07003469 mStableBottom = mStableFullscreenBottom = mTmpNavigationFrame.top;
John Spurlockf95b89a2013-10-10 22:10:42 -04003470 if (transientNavBarShowing) {
John Spurlock27735a42013-08-14 17:57:38 -04003471 mNavigationBarController.setBarShowingLw(true);
John Spurlockad3e6cb2013-04-30 08:47:43 -04003472 } else if (navVisible) {
John Spurlock27735a42013-08-14 17:57:38 -04003473 mNavigationBarController.setBarShowingLw(true);
Craig Mautner69b08182012-09-05 13:07:13 -07003474 mDockBottom = mTmpNavigationFrame.top;
Dianne Hackborn313440842013-02-19 19:22:59 -08003475 mRestrictedScreenHeight = mDockBottom - mRestrictedScreenTop;
3476 mRestrictedOverscanScreenHeight = mDockBottom - mRestrictedOverscanScreenTop;
Craig Mautner69b08182012-09-05 13:07:13 -07003477 } else {
3478 // We currently want to hide the navigation UI.
John Spurlock27735a42013-08-14 17:57:38 -04003479 mNavigationBarController.setBarShowingLw(false);
Craig Mautner69b08182012-09-05 13:07:13 -07003480 }
John Spurlockc6d1c602014-01-17 15:22:06 -05003481 if (navVisible && !navTranslucent && !navAllowedHidden
3482 && !mNavigationBar.isAnimatingLw()
John Spurlockbd957402013-10-03 11:38:39 -04003483 && !mNavigationBarController.wasRecentlyTranslucent()) {
John Spurlocke1f366f2013-08-05 12:22:40 -04003484 // If the opaque nav bar is currently requested to be visible,
Craig Mautner69b08182012-09-05 13:07:13 -07003485 // and not in the process of animating on or off, then
3486 // we can tell the app that it is covered by it.
3487 mSystemBottom = mTmpNavigationFrame.top;
3488 }
Dianne Hackbornf87d1962012-04-04 12:48:24 -07003489 } else {
Craig Mautner69b08182012-09-05 13:07:13 -07003490 // Landscape screen; nav bar goes to the right.
Dianne Hackbornc652de82013-02-15 16:32:56 -08003491 int left = displayWidth - overscanRight
3492 - mNavigationBarWidthForRotation[displayRotation];
3493 mTmpNavigationFrame.set(left, 0, displayWidth - overscanRight, displayHeight);
Craig Mautner69b08182012-09-05 13:07:13 -07003494 mStableRight = mStableFullscreenRight = mTmpNavigationFrame.left;
John Spurlockf95b89a2013-10-10 22:10:42 -04003495 if (transientNavBarShowing) {
John Spurlock27735a42013-08-14 17:57:38 -04003496 mNavigationBarController.setBarShowingLw(true);
John Spurlockad3e6cb2013-04-30 08:47:43 -04003497 } else if (navVisible) {
John Spurlock27735a42013-08-14 17:57:38 -04003498 mNavigationBarController.setBarShowingLw(true);
Craig Mautner69b08182012-09-05 13:07:13 -07003499 mDockRight = mTmpNavigationFrame.left;
Dianne Hackborn313440842013-02-19 19:22:59 -08003500 mRestrictedScreenWidth = mDockRight - mRestrictedScreenLeft;
3501 mRestrictedOverscanScreenWidth = mDockRight - mRestrictedOverscanScreenLeft;
Craig Mautner69b08182012-09-05 13:07:13 -07003502 } else {
3503 // We currently want to hide the navigation UI.
John Spurlock27735a42013-08-14 17:57:38 -04003504 mNavigationBarController.setBarShowingLw(false);
Craig Mautner69b08182012-09-05 13:07:13 -07003505 }
John Spurlockbd957402013-10-03 11:38:39 -04003506 if (navVisible && !navTranslucent && !mNavigationBar.isAnimatingLw()
3507 && !mNavigationBarController.wasRecentlyTranslucent()) {
Craig Mautner69b08182012-09-05 13:07:13 -07003508 // If the nav bar is currently requested to be visible,
3509 // and not in the process of animating on or off, then
3510 // we can tell the app that it is covered by it.
3511 mSystemRight = mTmpNavigationFrame.left;
3512 }
Dianne Hackbornf87d1962012-04-04 12:48:24 -07003513 }
Craig Mautner69b08182012-09-05 13:07:13 -07003514 // Make sure the content and current rectangles are updated to
3515 // account for the restrictions from the navigation bar.
Dianne Hackborne30e02f2014-05-27 18:24:45 -07003516 mContentTop = mVoiceContentTop = mCurTop = mDockTop;
3517 mContentBottom = mVoiceContentBottom = mCurBottom = mDockBottom;
3518 mContentLeft = mVoiceContentLeft = mCurLeft = mDockLeft;
3519 mContentRight = mVoiceContentRight = mCurRight = mDockRight;
Craig Mautner69b08182012-09-05 13:07:13 -07003520 mStatusBarLayer = mNavigationBar.getSurfaceLayer();
3521 // And compute the final frame.
3522 mNavigationBar.computeFrameLw(mTmpNavigationFrame, mTmpNavigationFrame,
Adrian Roosfa104232014-06-20 16:10:14 -07003523 mTmpNavigationFrame, mTmpNavigationFrame, mTmpNavigationFrame, dcf,
Filip Gruszczynski2217f612015-05-26 11:32:08 -07003524 mTmpNavigationFrame, mTmpNavigationFrame);
Craig Mautnereda67292013-04-28 13:50:14 -07003525 if (DEBUG_LAYOUT) Slog.i(TAG, "mNavigationBar frame: " + mTmpNavigationFrame);
John Spurlock27735a42013-08-14 17:57:38 -04003526 if (mNavigationBarController.checkHiddenLw()) {
John Spurlockad3e6cb2013-04-30 08:47:43 -04003527 updateSysUiVisibility = true;
3528 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003529 }
Craig Mautnereda67292013-04-28 13:50:14 -07003530 if (DEBUG_LAYOUT) Slog.i(TAG, String.format("mDock rect: (%d,%d - %d,%d)",
Craig Mautner69b08182012-09-05 13:07:13 -07003531 mDockLeft, mDockTop, mDockRight, mDockBottom));
3532
3533 // decide where the status bar goes ahead of time
3534 if (mStatusBar != null) {
3535 // apply any navigation bar insets
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003536 pf.left = df.left = of.left = mUnrestrictedScreenLeft;
3537 pf.top = df.top = of.top = mUnrestrictedScreenTop;
3538 pf.right = df.right = of.right = mUnrestrictedScreenWidth + mUnrestrictedScreenLeft;
3539 pf.bottom = df.bottom = of.bottom = mUnrestrictedScreenHeight
3540 + mUnrestrictedScreenTop;
Craig Mautner69b08182012-09-05 13:07:13 -07003541 vf.left = mStableLeft;
3542 vf.top = mStableTop;
3543 vf.right = mStableRight;
3544 vf.bottom = mStableBottom;
3545
3546 mStatusBarLayer = mStatusBar.getSurfaceLayer();
3547
3548 // Let the status bar determine its size.
Filip Gruszczynski2217f612015-05-26 11:32:08 -07003549 mStatusBar.computeFrameLw(pf /* parentFrame */, df /* displayFrame */,
3550 vf /* overlayFrame */, vf /* contentFrame */, vf /* visibleFrame */,
3551 dcf /* decorFrame */, vf /* stableFrame */, vf /* outsetFrame */);
Craig Mautner69b08182012-09-05 13:07:13 -07003552
3553 // For layout, the status bar is always at the top with our fixed height.
3554 mStableTop = mUnrestrictedScreenTop + mStatusBarHeight;
3555
John Spurlocke1f366f2013-08-05 12:22:40 -04003556 boolean statusBarTransient = (sysui & View.STATUS_BAR_TRANSIENT) != 0;
Adrian Roosea562512014-05-05 13:33:03 +02003557 boolean statusBarTranslucent = (sysui
3558 & (View.STATUS_BAR_TRANSLUCENT | View.SYSTEM_UI_TRANSPARENT)) != 0;
Adrian Roos4fb3ee32014-08-22 19:29:09 +02003559 if (!isKeyguardShowing) {
3560 statusBarTranslucent &= areTranslucentBarsAllowed();
3561 }
John Spurlock32beb2c2013-03-11 10:16:47 -04003562
Craig Mautner69b08182012-09-05 13:07:13 -07003563 // If the status bar is hidden, we don't want to cause
3564 // windows behind it to scroll.
John Spurlockeda1f692013-09-16 11:38:44 -04003565 if (mStatusBar.isVisibleLw() && !statusBarTransient) {
Craig Mautner69b08182012-09-05 13:07:13 -07003566 // Status bar may go away, so the screen area it occupies
3567 // is available to apps but just covering them when the
3568 // status bar is visible.
3569 mDockTop = mUnrestrictedScreenTop + mStatusBarHeight;
3570
Dianne Hackborne30e02f2014-05-27 18:24:45 -07003571 mContentTop = mVoiceContentTop = mCurTop = mDockTop;
3572 mContentBottom = mVoiceContentBottom = mCurBottom = mDockBottom;
3573 mContentLeft = mVoiceContentLeft = mCurLeft = mDockLeft;
3574 mContentRight = mVoiceContentRight = mCurRight = mDockRight;
Craig Mautner69b08182012-09-05 13:07:13 -07003575
Craig Mautnereda67292013-04-28 13:50:14 -07003576 if (DEBUG_LAYOUT) Slog.v(TAG, "Status bar: " +
Craig Mautner69b08182012-09-05 13:07:13 -07003577 String.format(
3578 "dock=[%d,%d][%d,%d] content=[%d,%d][%d,%d] cur=[%d,%d][%d,%d]",
3579 mDockLeft, mDockTop, mDockRight, mDockBottom,
3580 mContentLeft, mContentTop, mContentRight, mContentBottom,
3581 mCurLeft, mCurTop, mCurRight, mCurBottom));
3582 }
John Spurlocke1f366f2013-08-05 12:22:40 -04003583 if (mStatusBar.isVisibleLw() && !mStatusBar.isAnimatingLw()
John Spurlockbd957402013-10-03 11:38:39 -04003584 && !statusBarTransient && !statusBarTranslucent
3585 && !mStatusBarController.wasRecentlyTranslucent()) {
John Spurlocke1f366f2013-08-05 12:22:40 -04003586 // If the opaque status bar is currently requested to be visible,
Craig Mautner69b08182012-09-05 13:07:13 -07003587 // and not in the process of animating on or off, then
3588 // we can tell the app that it is covered by it.
3589 mSystemTop = mUnrestrictedScreenTop + mStatusBarHeight;
3590 }
John Spurlock27735a42013-08-14 17:57:38 -04003591 if (mStatusBarController.checkHiddenLw()) {
John Spurlockad3e6cb2013-04-30 08:47:43 -04003592 updateSysUiVisibility = true;
John Spurlock32beb2c2013-03-11 10:16:47 -04003593 }
Dianne Hackborn5c58de32012-04-28 19:52:37 -07003594 }
John Spurlockad3e6cb2013-04-30 08:47:43 -04003595 if (updateSysUiVisibility) {
3596 updateSystemUiVisibilityLw();
3597 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003598 }
3599 }
3600
Dianne Hackborn85afd1b2012-05-13 13:31:06 -07003601 /** {@inheritDoc} */
Craig Mautner967212c2013-04-13 21:10:58 -07003602 @Override
John Spurlock46646232013-09-30 22:32:42 -04003603 public int getSystemDecorLayerLw() {
Bryce Lee2ed3e5f2015-04-01 22:09:19 +00003604 if (mStatusBar != null && mStatusBar.isVisibleLw()) {
3605 return mStatusBar.getSurfaceLayer();
3606 }
3607
3608 if (mNavigationBar != null && mNavigationBar.isVisibleLw()) {
3609 return mNavigationBar.getSurfaceLayer();
3610 }
3611
Dianne Hackborn85afd1b2012-05-13 13:31:06 -07003612 return 0;
3613 }
3614
Craig Mautner967212c2013-04-13 21:10:58 -07003615 @Override
3616 public void getContentRectLw(Rect r) {
3617 r.set(mContentLeft, mContentTop, mContentRight, mContentBottom);
3618 }
3619
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003620 void setAttachedWindowFrames(WindowState win, int fl, int adjust, WindowState attached,
3621 boolean insetDecors, Rect pf, Rect df, Rect of, Rect cf, Rect vf) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003622 if (win.getSurfaceLayer() > mDockLayer && attached.getSurfaceLayer() < mDockLayer) {
3623 // Here's a special case: if this attached window is a panel that is
3624 // above the dock window, and the window it is attached to is below
3625 // the dock window, then the frames we computed for the window it is
3626 // attached to can not be used because the dock is effectively part
3627 // of the underlying window and the attached window is floating on top
3628 // of the whole thing. So, we ignore the attached window and explicitly
3629 // compute the frames that would be appropriate without the dock.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003630 df.left = of.left = cf.left = vf.left = mDockLeft;
3631 df.top = of.top = cf.top = vf.top = mDockTop;
3632 df.right = of.right = cf.right = vf.right = mDockRight;
3633 df.bottom = of.bottom = cf.bottom = vf.bottom = mDockBottom;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003634 } else {
3635 // The effective display frame of the attached window depends on
3636 // whether it is taking care of insetting its content. If not,
3637 // we need to use the parent's content frame so that the entire
3638 // window is positioned within that content. Otherwise we can use
Wale Ogunwale393b1c12014-10-18 16:22:01 -07003639 // the overscan frame and let the attached window take care of
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003640 // positioning its content appropriately.
Dianne Hackborndea3ef72010-10-28 14:24:22 -07003641 if (adjust != SOFT_INPUT_ADJUST_RESIZE) {
Wale Ogunwale393b1c12014-10-18 16:22:01 -07003642 // Set the content frame of the attached window to the parent's decor frame
3643 // (same as content frame when IME isn't present) if specifically requested by
3644 // setting {@link WindowManager.LayoutParams#FLAG_LAYOUT_ATTACHED_IN_DECOR} flag.
3645 // Otherwise, use the overscan frame.
3646 cf.set((fl & FLAG_LAYOUT_ATTACHED_IN_DECOR) != 0
3647 ? attached.getContentFrameLw() : attached.getOverscanFrameLw());
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003648 } else {
3649 // If the window is resizing, then we want to base the content
3650 // frame on our attached content frame to resize... however,
3651 // things can be tricky if the attached window is NOT in resize
3652 // mode, in which case its content frame will be larger.
3653 // Ungh. So to deal with that, make sure the content frame
3654 // we end up using is not covering the IM dock.
3655 cf.set(attached.getContentFrameLw());
Dianne Hackborne30e02f2014-05-27 18:24:45 -07003656 if (attached.isVoiceInteraction()) {
3657 if (cf.left < mVoiceContentLeft) cf.left = mVoiceContentLeft;
3658 if (cf.top < mVoiceContentTop) cf.top = mVoiceContentTop;
3659 if (cf.right > mVoiceContentRight) cf.right = mVoiceContentRight;
3660 if (cf.bottom > mVoiceContentBottom) cf.bottom = mVoiceContentBottom;
3661 } else if (attached.getSurfaceLayer() < mDockLayer) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003662 if (cf.left < mContentLeft) cf.left = mContentLeft;
3663 if (cf.top < mContentTop) cf.top = mContentTop;
3664 if (cf.right > mContentRight) cf.right = mContentRight;
3665 if (cf.bottom > mContentBottom) cf.bottom = mContentBottom;
3666 }
3667 }
3668 df.set(insetDecors ? attached.getDisplayFrameLw() : cf);
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003669 of.set(insetDecors ? attached.getOverscanFrameLw() : cf);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003670 vf.set(attached.getVisibleFrameLw());
3671 }
3672 // The LAYOUT_IN_SCREEN flag is used to determine whether the attached
3673 // window should be positioned relative to its parent or the entire
3674 // screen.
3675 pf.set((fl & FLAG_LAYOUT_IN_SCREEN) == 0
3676 ? attached.getFrameLw() : df);
3677 }
Dianne Hackborn5b5cc4d2012-05-16 13:15:00 -07003678
3679 private void applyStableConstraints(int sysui, int fl, Rect r) {
3680 if ((sysui & View.SYSTEM_UI_FLAG_LAYOUT_STABLE) != 0) {
3681 // If app is requesting a stable layout, don't let the
3682 // content insets go below the stable values.
3683 if ((fl & FLAG_FULLSCREEN) != 0) {
3684 if (r.left < mStableFullscreenLeft) r.left = mStableFullscreenLeft;
3685 if (r.top < mStableFullscreenTop) r.top = mStableFullscreenTop;
3686 if (r.right > mStableFullscreenRight) r.right = mStableFullscreenRight;
3687 if (r.bottom > mStableFullscreenBottom) r.bottom = mStableFullscreenBottom;
3688 } else {
3689 if (r.left < mStableLeft) r.left = mStableLeft;
3690 if (r.top < mStableTop) r.top = mStableTop;
3691 if (r.right > mStableRight) r.right = mStableRight;
3692 if (r.bottom > mStableBottom) r.bottom = mStableBottom;
3693 }
3694 }
3695 }
3696
Jorim Jaggiaa806142015-05-20 18:04:16 -07003697 private boolean canReceiveInput(WindowState win) {
3698 boolean notFocusable =
3699 (win.getAttrs().flags & WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE) != 0;
3700 boolean altFocusableIm =
3701 (win.getAttrs().flags & WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM) != 0;
3702 boolean notFocusableForIm = notFocusable ^ altFocusableIm;
3703 return !notFocusableForIm;
3704 }
3705
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003706 /** {@inheritDoc} */
Craig Mautner69b08182012-09-05 13:07:13 -07003707 @Override
Craig Mautnerc9457fa2014-06-06 14:27:48 -07003708 public void layoutWindowLw(WindowState win, WindowState attached) {
Jorim Jaggiaa806142015-05-20 18:04:16 -07003709 // We've already done the navigation bar and status bar. If the status bar can receive
3710 // input, we need to layout it again to accomodate for the IME window.
3711 if ((win == mStatusBar && !canReceiveInput(win)) || win == mNavigationBar) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003712 return;
3713 }
Jorim Jaggiaa806142015-05-20 18:04:16 -07003714 final WindowManager.LayoutParams attrs = win.getAttrs();
Craig Mautner69b08182012-09-05 13:07:13 -07003715 final boolean isDefaultDisplay = win.isDefaultDisplay();
3716 final boolean needsToOffsetInputMethodTarget = isDefaultDisplay &&
satok1bc0a492012-04-25 22:47:12 +09003717 (win == mLastInputMethodTargetWindow && mLastInputMethodWindow != null);
3718 if (needsToOffsetInputMethodTarget) {
Craig Mautnereda67292013-04-28 13:50:14 -07003719 if (DEBUG_LAYOUT) Slog.i(TAG, "Offset ime target window by the last ime window state");
satok1bc0a492012-04-25 22:47:12 +09003720 offsetInputMethodWindowLw(mLastInputMethodWindow);
3721 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003722
John Spurlockc6d1c602014-01-17 15:22:06 -05003723 final int fl = PolicyControl.getWindowFlags(win, attrs);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003724 final int sim = attrs.softInputMode;
John Spurlock1db8b682014-02-18 11:18:59 -05003725 final int sysUiFl = PolicyControl.getSystemUiVisibility(win, null);
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07003726
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003727 final Rect pf = mTmpParentFrame;
3728 final Rect df = mTmpDisplayFrame;
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003729 final Rect of = mTmpOverscanFrame;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003730 final Rect cf = mTmpContentFrame;
3731 final Rect vf = mTmpVisibleFrame;
John Spurlock46646232013-09-30 22:32:42 -04003732 final Rect dcf = mTmpDecorFrame;
Adrian Roosfa104232014-06-20 16:10:14 -07003733 final Rect sf = mTmpStableFrame;
Filip Gruszczynski2217f612015-05-26 11:32:08 -07003734 Rect osf = null;
John Spurlock46646232013-09-30 22:32:42 -04003735 dcf.setEmpty();
Craig Mautner69b08182012-09-05 13:07:13 -07003736
3737 final boolean hasNavBar = (isDefaultDisplay && mHasNavigationBar
Daniel Sandler36412a72011-08-04 09:35:13 -04003738 && mNavigationBar != null && mNavigationBar.isVisibleLw());
Daniel Sandler8956dbb2011-04-22 07:55:02 -04003739
Craig Mautnerf683b562012-10-02 11:10:57 -07003740 final int adjust = sim & SOFT_INPUT_MASK_ADJUST;
3741
Adrian Roosfa104232014-06-20 16:10:14 -07003742 if (isDefaultDisplay) {
3743 sf.set(mStableLeft, mStableTop, mStableRight, mStableBottom);
3744 } else {
3745 sf.set(mOverscanLeft, mOverscanTop, mOverscanRight, mOverscanBottom);
3746 }
3747
Craig Mautner69b08182012-09-05 13:07:13 -07003748 if (!isDefaultDisplay) {
3749 if (attached != null) {
3750 // If this window is attached to another, our display
3751 // frame is the same as the one we are attached to.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003752 setAttachedWindowFrames(win, fl, adjust, attached, true, pf, df, of, cf, vf);
Craig Mautner69b08182012-09-05 13:07:13 -07003753 } else {
3754 // Give the window full screen.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003755 pf.left = df.left = of.left = cf.left = mOverscanScreenLeft;
3756 pf.top = df.top = of.top = cf.top = mOverscanScreenTop;
3757 pf.right = df.right = of.right = cf.right
Dianne Hackbornc652de82013-02-15 16:32:56 -08003758 = mOverscanScreenLeft + mOverscanScreenWidth;
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003759 pf.bottom = df.bottom = of.bottom = cf.bottom
Dianne Hackbornc652de82013-02-15 16:32:56 -08003760 = mOverscanScreenTop + mOverscanScreenHeight;
Craig Mautner69b08182012-09-05 13:07:13 -07003761 }
Jorim Jaggi225d3b52015-04-01 11:18:57 -07003762 } else if (attrs.type == TYPE_INPUT_METHOD) {
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003763 pf.left = df.left = of.left = cf.left = vf.left = mDockLeft;
3764 pf.top = df.top = of.top = cf.top = vf.top = mDockTop;
3765 pf.right = df.right = of.right = cf.right = vf.right = mDockRight;
John Spurlockc68d5772013-10-08 11:47:58 -04003766 // IM dock windows layout below the nav bar...
John Spurlock57beb3b2013-10-10 10:27:44 -04003767 pf.bottom = df.bottom = of.bottom = mUnrestrictedScreenTop + mUnrestrictedScreenHeight;
John Spurlockc68d5772013-10-08 11:47:58 -04003768 // ...with content insets above the nav bar
3769 cf.bottom = vf.bottom = mStableBottom;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003770 // IM dock windows always go to the bottom of the screen.
3771 attrs.gravity = Gravity.BOTTOM;
3772 mDockLayer = win.getSurfaceLayer();
Jorim Jaggi225d3b52015-04-01 11:18:57 -07003773 } else if (attrs.type == TYPE_VOICE_INTERACTION) {
Stefan Kuhne2f280d062015-06-18 07:20:33 -10003774 pf.left = df.left = of.left = mUnrestrictedScreenLeft;
Jorim Jaggi225d3b52015-04-01 11:18:57 -07003775 pf.top = df.top = of.top = mUnrestrictedScreenTop;
Stefan Kuhne2f280d062015-06-18 07:20:33 -10003776 pf.right = df.right = of.right = mUnrestrictedScreenLeft + mUnrestrictedScreenWidth;
3777 pf.bottom = df.bottom = of.bottom = mUnrestrictedScreenTop + mUnrestrictedScreenHeight;
Jorim Jaggi225d3b52015-04-01 11:18:57 -07003778 cf.bottom = vf.bottom = mStableBottom;
Stefan Kuhne2f280d062015-06-18 07:20:33 -10003779 // Note: In Phone landscape mode, the button bar should also be excluded.
3780 cf.right = vf.right = mStableRight;
3781 cf.left = vf.left = mStableLeft;
Jorim Jaggi225d3b52015-04-01 11:18:57 -07003782 cf.top = vf.top = mStableTop;
Jorim Jaggiaa806142015-05-20 18:04:16 -07003783 } else if (win == mStatusBar) {
Jorim Jaggie0700182014-08-21 01:12:37 +02003784 pf.left = df.left = of.left = mUnrestrictedScreenLeft;
3785 pf.top = df.top = of.top = mUnrestrictedScreenTop;
3786 pf.right = df.right = of.right = mUnrestrictedScreenWidth + mUnrestrictedScreenLeft;
3787 pf.bottom = df.bottom = of.bottom = mUnrestrictedScreenHeight + mUnrestrictedScreenTop;
3788 cf.left = vf.left = mStableLeft;
3789 cf.top = vf.top = mStableTop;
3790 cf.right = vf.right = mStableRight;
3791 vf.bottom = mStableBottom;
3792 cf.bottom = mContentBottom;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003793 } else {
John Spurlock46646232013-09-30 22:32:42 -04003794
3795 // Default policy decor for the default display
3796 dcf.left = mSystemLeft;
3797 dcf.top = mSystemTop;
3798 dcf.right = mSystemRight;
3799 dcf.bottom = mSystemBottom;
John Spurlockbd957402013-10-03 11:38:39 -04003800 final boolean inheritTranslucentDecor = (attrs.privateFlags
3801 & WindowManager.LayoutParams.PRIVATE_FLAG_INHERIT_TRANSLUCENT_DECOR) != 0;
John Spurlock65567d42013-10-08 10:08:32 -04003802 final boolean isAppWindow =
3803 attrs.type >= WindowManager.LayoutParams.FIRST_APPLICATION_WINDOW &&
3804 attrs.type <= WindowManager.LayoutParams.LAST_APPLICATION_WINDOW;
3805 final boolean topAtRest =
3806 win == mTopFullscreenOpaqueWindowState && !win.isAnimatingLw();
3807 if (isAppWindow && !inheritTranslucentDecor && !topAtRest) {
John Spurlockbd957402013-10-03 11:38:39 -04003808 if ((sysUiFl & View.SYSTEM_UI_FLAG_FULLSCREEN) == 0
3809 && (fl & WindowManager.LayoutParams.FLAG_FULLSCREEN) == 0
Adrian Roosea562512014-05-05 13:33:03 +02003810 && (fl & WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS) == 0
3811 && (fl & WindowManager.LayoutParams.
3812 FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS) == 0) {
John Spurlock46646232013-09-30 22:32:42 -04003813 // Ensure policy decor includes status bar
3814 dcf.top = mStableTop;
3815 }
John Spurlockbd957402013-10-03 11:38:39 -04003816 if ((fl & WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION) == 0
Adrian Roosea562512014-05-05 13:33:03 +02003817 && (sysUiFl & View.SYSTEM_UI_FLAG_HIDE_NAVIGATION) == 0
3818 && (fl & WindowManager.LayoutParams.
3819 FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS) == 0) {
John Spurlock46646232013-09-30 22:32:42 -04003820 // Ensure policy decor includes navigation bar
3821 dcf.bottom = mStableBottom;
3822 dcf.right = mStableRight;
3823 }
3824 }
3825
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003826 if ((fl & (FLAG_LAYOUT_IN_SCREEN | FLAG_LAYOUT_INSET_DECOR))
3827 == (FLAG_LAYOUT_IN_SCREEN | FLAG_LAYOUT_INSET_DECOR)) {
RoboErik8a2cfc32014-05-16 11:19:38 -07003828 if (DEBUG_LAYOUT) Slog.v(TAG, "layoutWindowLw(" + attrs.getTitle()
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003829 + "): IN_SCREEN, INSET_DECOR");
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003830 // This is the case for a normal activity window: we want it
3831 // to cover all of the screen space, and it can take care of
3832 // moving its contents to account for screen decorations that
3833 // intrude into that space.
3834 if (attached != null) {
3835 // If this window is attached to another, our display
3836 // frame is the same as the one we are attached to.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003837 setAttachedWindowFrames(win, fl, adjust, attached, true, pf, df, of, cf, vf);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003838 } else {
Daniel Sandler8956dbb2011-04-22 07:55:02 -04003839 if (attrs.type == TYPE_STATUS_BAR_PANEL
3840 || attrs.type == TYPE_STATUS_BAR_SUB_PANEL) {
Joe Onorato29fc2c92010-11-24 10:26:50 -08003841 // Status bar panels are the only windows who can go on top of
3842 // the status bar. They are protected by the STATUS_BAR_SERVICE
3843 // permission, so they have the same privileges as the status
3844 // bar itself.
Daniel Sandler8956dbb2011-04-22 07:55:02 -04003845 //
Daniel Sandler8e8b4152011-07-21 01:16:43 -04003846 // However, they should still dodge the navigation bar if it exists.
Daniel Sandler8956dbb2011-04-22 07:55:02 -04003847
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003848 pf.left = df.left = of.left = hasNavBar
3849 ? mDockLeft : mUnrestrictedScreenLeft;
3850 pf.top = df.top = of.top = mUnrestrictedScreenTop;
3851 pf.right = df.right = of.right = hasNavBar
3852 ? mRestrictedScreenLeft+mRestrictedScreenWidth
3853 : mUnrestrictedScreenLeft + mUnrestrictedScreenWidth;
3854 pf.bottom = df.bottom = of.bottom = hasNavBar
3855 ? mRestrictedScreenTop+mRestrictedScreenHeight
3856 : mUnrestrictedScreenTop + mUnrestrictedScreenHeight;
Daniel Sandler8956dbb2011-04-22 07:55:02 -04003857
Craig Mautnereda67292013-04-28 13:50:14 -07003858 if (DEBUG_LAYOUT) Slog.v(TAG, String.format(
Daniel Sandler8e8b4152011-07-21 01:16:43 -04003859 "Laying out status bar window: (%d,%d - %d,%d)",
3860 pf.left, pf.top, pf.right, pf.bottom));
John Spurlock46646232013-09-30 22:32:42 -04003861 } else if ((fl & FLAG_LAYOUT_IN_OVERSCAN) != 0
Dianne Hackbornc652de82013-02-15 16:32:56 -08003862 && attrs.type >= WindowManager.LayoutParams.FIRST_APPLICATION_WINDOW
3863 && attrs.type <= WindowManager.LayoutParams.LAST_SUB_WINDOW) {
3864 // Asking to layout into the overscan region, so give it that pure
3865 // unrestricted area.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003866 pf.left = df.left = of.left = mOverscanScreenLeft;
3867 pf.top = df.top = of.top = mOverscanScreenTop;
3868 pf.right = df.right = of.right = mOverscanScreenLeft + mOverscanScreenWidth;
3869 pf.bottom = df.bottom = of.bottom = mOverscanScreenTop
3870 + mOverscanScreenHeight;
Alan Viverette5a0f4ec2013-10-07 15:10:29 -07003871 } else if (canHideNavigationBar()
Dianne Hackbornf87d1962012-04-04 12:48:24 -07003872 && (sysUiFl & View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION) != 0
Jorim Jaggi380ecb82014-03-14 17:25:20 +01003873 && attrs.type >= WindowManager.LayoutParams.FIRST_APPLICATION_WINDOW
3874 && attrs.type <= WindowManager.LayoutParams.LAST_SUB_WINDOW) {
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07003875 // Asking for layout as if the nav bar is hidden, lets the
Dianne Hackbornc652de82013-02-15 16:32:56 -08003876 // application extend into the unrestricted overscan screen area. We
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07003877 // only do this for application windows to ensure no window that
3878 // can be above the nav bar can do this.
Dianne Hackborn313440842013-02-19 19:22:59 -08003879 pf.left = df.left = mOverscanScreenLeft;
3880 pf.top = df.top = mOverscanScreenTop;
3881 pf.right = df.right = mOverscanScreenLeft + mOverscanScreenWidth;
3882 pf.bottom = df.bottom = mOverscanScreenTop + mOverscanScreenHeight;
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003883 // We need to tell the app about where the frame inside the overscan
3884 // is, so it can inset its content by that amount -- it didn't ask
3885 // to actually extend itself into the overscan region.
3886 of.left = mUnrestrictedScreenLeft;
3887 of.top = mUnrestrictedScreenTop;
3888 of.right = mUnrestrictedScreenLeft + mUnrestrictedScreenWidth;
3889 of.bottom = mUnrestrictedScreenTop + mUnrestrictedScreenHeight;
Joe Onorato29fc2c92010-11-24 10:26:50 -08003890 } else {
Dianne Hackborn313440842013-02-19 19:22:59 -08003891 pf.left = df.left = mRestrictedOverscanScreenLeft;
3892 pf.top = df.top = mRestrictedOverscanScreenTop;
3893 pf.right = df.right = mRestrictedOverscanScreenLeft
3894 + mRestrictedOverscanScreenWidth;
3895 pf.bottom = df.bottom = mRestrictedOverscanScreenTop
3896 + mRestrictedOverscanScreenHeight;
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003897 // We need to tell the app about where the frame inside the overscan
3898 // is, so it can inset its content by that amount -- it didn't ask
3899 // to actually extend itself into the overscan region.
3900 of.left = mUnrestrictedScreenLeft;
3901 of.top = mUnrestrictedScreenTop;
3902 of.right = mUnrestrictedScreenLeft + mUnrestrictedScreenWidth;
3903 of.bottom = mUnrestrictedScreenTop + mUnrestrictedScreenHeight;
Joe Onorato29fc2c92010-11-24 10:26:50 -08003904 }
Craig Mautner69b08182012-09-05 13:07:13 -07003905
John Spurlock46646232013-09-30 22:32:42 -04003906 if ((fl & FLAG_FULLSCREEN) == 0) {
Dianne Hackborne30e02f2014-05-27 18:24:45 -07003907 if (win.isVoiceInteraction()) {
3908 cf.left = mVoiceContentLeft;
3909 cf.top = mVoiceContentTop;
3910 cf.right = mVoiceContentRight;
3911 cf.bottom = mVoiceContentBottom;
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003912 } else {
Dianne Hackborne30e02f2014-05-27 18:24:45 -07003913 if (adjust != SOFT_INPUT_ADJUST_RESIZE) {
3914 cf.left = mDockLeft;
3915 cf.top = mDockTop;
3916 cf.right = mDockRight;
3917 cf.bottom = mDockBottom;
3918 } else {
3919 cf.left = mContentLeft;
3920 cf.top = mContentTop;
3921 cf.right = mContentRight;
3922 cf.bottom = mContentBottom;
3923 }
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003924 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003925 } else {
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003926 // Full screen windows are always given a layout that is as if the
3927 // status bar and other transient decors are gone. This is to avoid
3928 // bad states when moving from a window that is not hding the
3929 // status bar to one that is.
3930 cf.left = mRestrictedScreenLeft;
3931 cf.top = mRestrictedScreenTop;
3932 cf.right = mRestrictedScreenLeft + mRestrictedScreenWidth;
3933 cf.bottom = mRestrictedScreenTop + mRestrictedScreenHeight;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003934 }
Dianne Hackborn5b5cc4d2012-05-16 13:15:00 -07003935 applyStableConstraints(sysUiFl, fl, cf);
Dianne Hackborndea3ef72010-10-28 14:24:22 -07003936 if (adjust != SOFT_INPUT_ADJUST_NOTHING) {
3937 vf.left = mCurLeft;
3938 vf.top = mCurTop;
3939 vf.right = mCurRight;
3940 vf.bottom = mCurBottom;
3941 } else {
3942 vf.set(cf);
3943 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003944 }
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07003945 } else if ((fl & FLAG_LAYOUT_IN_SCREEN) != 0 || (sysUiFl
3946 & (View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
3947 | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION)) != 0) {
Craig Mautnereda67292013-04-28 13:50:14 -07003948 if (DEBUG_LAYOUT) Slog.v(TAG, "layoutWindowLw(" + attrs.getTitle() +
3949 "): IN_SCREEN");
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003950 // A window that has requested to fill the entire screen just
3951 // gets everything, period.
Daniel Sandler8956dbb2011-04-22 07:55:02 -04003952 if (attrs.type == TYPE_STATUS_BAR_PANEL
John Spurlock67a0f852015-06-15 15:35:47 -04003953 || attrs.type == TYPE_STATUS_BAR_SUB_PANEL
3954 || attrs.type == TYPE_VOLUME_OVERLAY) {
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003955 pf.left = df.left = of.left = cf.left = hasNavBar
3956 ? mDockLeft : mUnrestrictedScreenLeft;
3957 pf.top = df.top = of.top = cf.top = mUnrestrictedScreenTop;
3958 pf.right = df.right = of.right = cf.right = hasNavBar
Daniel Sandler8e8b4152011-07-21 01:16:43 -04003959 ? mRestrictedScreenLeft+mRestrictedScreenWidth
Dianne Hackbornc652de82013-02-15 16:32:56 -08003960 : mUnrestrictedScreenLeft + mUnrestrictedScreenWidth;
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003961 pf.bottom = df.bottom = of.bottom = cf.bottom = hasNavBar
Daniel Sandler8e8b4152011-07-21 01:16:43 -04003962 ? mRestrictedScreenTop+mRestrictedScreenHeight
Dianne Hackbornc652de82013-02-15 16:32:56 -08003963 : mUnrestrictedScreenTop + mUnrestrictedScreenHeight;
Craig Mautnereda67292013-04-28 13:50:14 -07003964 if (DEBUG_LAYOUT) Slog.v(TAG, String.format(
Daniel Sandler36412a72011-08-04 09:35:13 -04003965 "Laying out IN_SCREEN status bar window: (%d,%d - %d,%d)",
3966 pf.left, pf.top, pf.right, pf.bottom));
Jim Millere898ac52012-04-06 17:10:57 -07003967 } else if (attrs.type == TYPE_NAVIGATION_BAR
3968 || attrs.type == TYPE_NAVIGATION_BAR_PANEL) {
Daniel Sandler8e8b4152011-07-21 01:16:43 -04003969 // The navigation bar has Real Ultimate Power.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003970 pf.left = df.left = of.left = mUnrestrictedScreenLeft;
3971 pf.top = df.top = of.top = mUnrestrictedScreenTop;
3972 pf.right = df.right = of.right = mUnrestrictedScreenLeft
3973 + mUnrestrictedScreenWidth;
3974 pf.bottom = df.bottom = of.bottom = mUnrestrictedScreenTop
3975 + mUnrestrictedScreenHeight;
Craig Mautnereda67292013-04-28 13:50:14 -07003976 if (DEBUG_LAYOUT) Slog.v(TAG, String.format(
Daniel Sandler8e8b4152011-07-21 01:16:43 -04003977 "Laying out navigation bar window: (%d,%d - %d,%d)",
3978 pf.left, pf.top, pf.right, pf.bottom));
Dianne Hackborn01011c32012-02-21 13:54:21 -08003979 } else if ((attrs.type == TYPE_SECURE_SYSTEM_OVERLAY
3980 || attrs.type == TYPE_BOOT_PROGRESS)
Jeff Brownbfcb60a2011-09-08 18:51:14 -07003981 && ((fl & FLAG_FULLSCREEN) != 0)) {
3982 // Fullscreen secure system overlays get what they ask for.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003983 pf.left = df.left = of.left = cf.left = mOverscanScreenLeft;
3984 pf.top = df.top = of.top = cf.top = mOverscanScreenTop;
3985 pf.right = df.right = of.right = cf.right = mOverscanScreenLeft
3986 + mOverscanScreenWidth;
3987 pf.bottom = df.bottom = of.bottom = cf.bottom = mOverscanScreenTop
3988 + mOverscanScreenHeight;
Craig Mautner165be0c2015-01-27 15:16:58 -08003989 } else if (attrs.type == TYPE_BOOT_PROGRESS) {
Dianne Hackborn01011c32012-02-21 13:54:21 -08003990 // Boot progress screen always covers entire display.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003991 pf.left = df.left = of.left = cf.left = mOverscanScreenLeft;
3992 pf.top = df.top = of.top = cf.top = mOverscanScreenTop;
3993 pf.right = df.right = of.right = cf.right = mOverscanScreenLeft
3994 + mOverscanScreenWidth;
3995 pf.bottom = df.bottom = of.bottom = cf.bottom = mOverscanScreenTop
3996 + mOverscanScreenHeight;
John Spurlockef4adae2013-08-26 17:58:58 -04003997 } else if (attrs.type == TYPE_WALLPAPER) {
Dianne Hackborn067e5f62014-09-07 23:14:30 -07003998 // The wallpaper also has Real Ultimate Power, but we want to tell
3999 // it about the overscan area.
4000 pf.left = df.left = mOverscanScreenLeft;
4001 pf.top = df.top = mOverscanScreenTop;
4002 pf.right = df.right = mOverscanScreenLeft + mOverscanScreenWidth;
4003 pf.bottom = df.bottom = mOverscanScreenTop + mOverscanScreenHeight;
4004 of.left = cf.left = mUnrestrictedScreenLeft;
4005 of.top = cf.top = mUnrestrictedScreenTop;
4006 of.right = cf.right = mUnrestrictedScreenLeft + mUnrestrictedScreenWidth;
4007 of.bottom = cf.bottom = mUnrestrictedScreenTop + mUnrestrictedScreenHeight;
John Spurlock46646232013-09-30 22:32:42 -04004008 } else if ((fl & FLAG_LAYOUT_IN_OVERSCAN) != 0
Dianne Hackbornc652de82013-02-15 16:32:56 -08004009 && attrs.type >= WindowManager.LayoutParams.FIRST_APPLICATION_WINDOW
4010 && attrs.type <= WindowManager.LayoutParams.LAST_SUB_WINDOW) {
4011 // Asking to layout into the overscan region, so give it that pure
4012 // unrestricted area.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08004013 pf.left = df.left = of.left = cf.left = mOverscanScreenLeft;
4014 pf.top = df.top = of.top = cf.top = mOverscanScreenTop;
4015 pf.right = df.right = of.right = cf.right
Dianne Hackbornc652de82013-02-15 16:32:56 -08004016 = mOverscanScreenLeft + mOverscanScreenWidth;
Dianne Hackbornc4aad012013-02-22 15:05:25 -08004017 pf.bottom = df.bottom = of.bottom = cf.bottom
Dianne Hackbornc652de82013-02-15 16:32:56 -08004018 = mOverscanScreenTop + mOverscanScreenHeight;
Alan Viverette5a0f4ec2013-10-07 15:10:29 -07004019 } else if (canHideNavigationBar()
Dianne Hackbornf87d1962012-04-04 12:48:24 -07004020 && (sysUiFl & View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION) != 0
Craig Mautnerbeac1062014-06-03 14:38:57 -07004021 && (attrs.type == TYPE_STATUS_BAR
4022 || attrs.type == TYPE_TOAST
Jorim Jaggi2fdeeab2015-04-01 15:13:03 -07004023 || attrs.type == TYPE_VOICE_INTERACTION_STARTING
John Spurlock34e13d92013-08-10 06:52:28 -04004024 || (attrs.type >= WindowManager.LayoutParams.FIRST_APPLICATION_WINDOW
4025 && attrs.type <= WindowManager.LayoutParams.LAST_SUB_WINDOW))) {
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07004026 // Asking for layout as if the nav bar is hidden, lets the
4027 // application extend into the unrestricted screen area. We
John Spurlock34e13d92013-08-10 06:52:28 -04004028 // only do this for application windows (or toasts) to ensure no window that
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07004029 // can be above the nav bar can do this.
4030 // XXX This assumes that an app asking for this will also
4031 // ask for layout in only content. We can't currently figure out
4032 // what the screen would be if only laying out to hide the nav bar.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08004033 pf.left = df.left = of.left = cf.left = mUnrestrictedScreenLeft;
4034 pf.top = df.top = of.top = cf.top = mUnrestrictedScreenTop;
4035 pf.right = df.right = of.right = cf.right = mUnrestrictedScreenLeft
4036 + mUnrestrictedScreenWidth;
4037 pf.bottom = df.bottom = of.bottom = cf.bottom = mUnrestrictedScreenTop
4038 + mUnrestrictedScreenHeight;
Joe Onorato29fc2c92010-11-24 10:26:50 -08004039 } else {
Dianne Hackbornc4aad012013-02-22 15:05:25 -08004040 pf.left = df.left = of.left = cf.left = mRestrictedScreenLeft;
4041 pf.top = df.top = of.top = cf.top = mRestrictedScreenTop;
4042 pf.right = df.right = of.right = cf.right = mRestrictedScreenLeft
4043 + mRestrictedScreenWidth;
4044 pf.bottom = df.bottom = of.bottom = cf.bottom = mRestrictedScreenTop
4045 + mRestrictedScreenHeight;
Joe Onorato29fc2c92010-11-24 10:26:50 -08004046 }
Craig Mautner69b08182012-09-05 13:07:13 -07004047
Dianne Hackborn5b5cc4d2012-05-16 13:15:00 -07004048 applyStableConstraints(sysUiFl, fl, cf);
Craig Mautner69b08182012-09-05 13:07:13 -07004049
Dianne Hackborndea3ef72010-10-28 14:24:22 -07004050 if (adjust != SOFT_INPUT_ADJUST_NOTHING) {
4051 vf.left = mCurLeft;
4052 vf.top = mCurTop;
4053 vf.right = mCurRight;
4054 vf.bottom = mCurBottom;
4055 } else {
4056 vf.set(cf);
4057 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004058 } else if (attached != null) {
Craig Mautnereda67292013-04-28 13:50:14 -07004059 if (DEBUG_LAYOUT) Slog.v(TAG, "layoutWindowLw(" + attrs.getTitle() +
4060 "): attached to " + attached);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004061 // A child window should be placed inside of the same visible
4062 // frame that its parent had.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08004063 setAttachedWindowFrames(win, fl, adjust, attached, false, pf, df, of, cf, vf);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004064 } else {
Craig Mautnereda67292013-04-28 13:50:14 -07004065 if (DEBUG_LAYOUT) Slog.v(TAG, "layoutWindowLw(" + attrs.getTitle() +
4066 "): normal window");
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004067 // Otherwise, a normal window must be placed inside the content
4068 // of all screen decorations.
John Spurlock67a0f852015-06-15 15:35:47 -04004069 if (attrs.type == TYPE_STATUS_BAR_PANEL || attrs.type == TYPE_VOLUME_OVERLAY) {
4070 // Status bar panels and the volume dialog are the only windows who can go on
4071 // top of the status bar. They are protected by the STATUS_BAR_SERVICE
Dianne Hackborna239c842011-06-01 12:28:20 -07004072 // permission, so they have the same privileges as the status
4073 // bar itself.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08004074 pf.left = df.left = of.left = cf.left = mRestrictedScreenLeft;
4075 pf.top = df.top = of.top = cf.top = mRestrictedScreenTop;
4076 pf.right = df.right = of.right = cf.right = mRestrictedScreenLeft
4077 + mRestrictedScreenWidth;
4078 pf.bottom = df.bottom = of.bottom = cf.bottom = mRestrictedScreenTop
4079 + mRestrictedScreenHeight;
John Spurlock67a0f852015-06-15 15:35:47 -04004080 } else if (attrs.type == TYPE_TOAST || attrs.type == TYPE_SYSTEM_ALERT) {
John Spurlock414c1f02013-12-04 13:47:36 -05004081 // These dialogs are stable to interim decor changes.
John Spurlockbd957402013-10-03 11:38:39 -04004082 pf.left = df.left = of.left = cf.left = mStableLeft;
4083 pf.top = df.top = of.top = cf.top = mStableTop;
4084 pf.right = df.right = of.right = cf.right = mStableRight;
4085 pf.bottom = df.bottom = of.bottom = cf.bottom = mStableBottom;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004086 } else {
Dianne Hackborna239c842011-06-01 12:28:20 -07004087 pf.left = mContentLeft;
4088 pf.top = mContentTop;
4089 pf.right = mContentRight;
4090 pf.bottom = mContentBottom;
Dianne Hackborn20d94742014-05-29 18:35:45 -07004091 if (win.isVoiceInteraction()) {
4092 df.left = of.left = cf.left = mVoiceContentLeft;
4093 df.top = of.top = cf.top = mVoiceContentTop;
4094 df.right = of.right = cf.right = mVoiceContentRight;
4095 df.bottom = of.bottom = cf.bottom = mVoiceContentBottom;
4096 } else if (adjust != SOFT_INPUT_ADJUST_RESIZE) {
Dianne Hackbornc4aad012013-02-22 15:05:25 -08004097 df.left = of.left = cf.left = mDockLeft;
4098 df.top = of.top = cf.top = mDockTop;
4099 df.right = of.right = cf.right = mDockRight;
4100 df.bottom = of.bottom = cf.bottom = mDockBottom;
Dianne Hackborna239c842011-06-01 12:28:20 -07004101 } else {
Dianne Hackbornc4aad012013-02-22 15:05:25 -08004102 df.left = of.left = cf.left = mContentLeft;
4103 df.top = of.top = cf.top = mContentTop;
4104 df.right = of.right = cf.right = mContentRight;
4105 df.bottom = of.bottom = cf.bottom = mContentBottom;
Dianne Hackborna239c842011-06-01 12:28:20 -07004106 }
4107 if (adjust != SOFT_INPUT_ADJUST_NOTHING) {
4108 vf.left = mCurLeft;
4109 vf.top = mCurTop;
4110 vf.right = mCurRight;
4111 vf.bottom = mCurBottom;
4112 } else {
4113 vf.set(cf);
4114 }
Dianne Hackborndea3ef72010-10-28 14:24:22 -07004115 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004116 }
4117 }
Craig Mautner69b08182012-09-05 13:07:13 -07004118
Craig Mautnerb816bed2013-07-23 10:26:17 -07004119 // TYPE_SYSTEM_ERROR is above the NavigationBar so it can't be allowed to extend over it.
4120 if ((fl & FLAG_LAYOUT_NO_LIMITS) != 0 && attrs.type != TYPE_SYSTEM_ERROR) {
Dianne Hackborn067e5f62014-09-07 23:14:30 -07004121 df.left = df.top = -10000;
4122 df.right = df.bottom = 10000;
4123 if (attrs.type != TYPE_WALLPAPER) {
4124 of.left = of.top = cf.left = cf.top = vf.left = vf.top = -10000;
4125 of.right = of.bottom = cf.right = cf.bottom = vf.right = vf.bottom = 10000;
4126 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004127 }
4128
Filip Gruszczynski2217f612015-05-26 11:32:08 -07004129 // If the device has a chin (e.g. some watches), a dead area at the bottom of the screen we
4130 // need to provide information to the clients that want to pretend that you can draw there.
Filip Gruszczynskib0c673b2015-06-05 09:43:06 -07004131 // We only want to apply outsets to certain types of windows. For example, we never want to
4132 // apply the outsets to floating dialogs, because they wouldn't make sense there.
4133 final boolean useOutsets = attrs.type == TYPE_WALLPAPER
4134 || (fl & (WindowManager.LayoutParams.FLAG_FULLSCREEN
4135 | WindowManager.LayoutParams.FLAG_LAYOUT_IN_OVERSCAN)) != 0;
4136 if (isDefaultDisplay && useOutsets) {
Filip Gruszczynski2217f612015-05-26 11:32:08 -07004137 osf = mTmpOutsetFrame;
4138 osf.set(cf.left, cf.top, cf.right, cf.bottom);
4139 int outset = ScreenShapeHelper.getWindowOutsetBottomPx(mContext.getResources());
4140 if (outset > 0) {
4141 int rotation = Surface.ROTATION_0;
4142 try {
4143 rotation = mWindowManager.getRotation();
4144 } catch (RemoteException e) {
4145 }
4146 if (rotation == Surface.ROTATION_0) {
4147 osf.bottom += outset;
4148 } else if (rotation == Surface.ROTATION_90) {
4149 osf.right += outset;
4150 } else if (rotation == Surface.ROTATION_180) {
4151 osf.top -= outset;
4152 } else if (rotation == Surface.ROTATION_270) {
4153 osf.left -= outset;
4154 }
4155 if (DEBUG_LAYOUT) Slog.v(TAG, "applying bottom outset of " + outset
4156 + " with rotation " + rotation + ", result: " + osf);
4157 }
4158 }
4159
Craig Mautnereda67292013-04-28 13:50:14 -07004160 if (DEBUG_LAYOUT) Slog.v(TAG, "Compute frame " + attrs.getTitle()
The Android Open Source Project11267662009-03-18 17:39:47 -07004161 + ": sim=#" + Integer.toHexString(sim)
RoboErik8a2cfc32014-05-16 11:19:38 -07004162 + " attach=" + attached + " type=" + attrs.type
Daniel Sandler8956dbb2011-04-22 07:55:02 -04004163 + String.format(" flags=0x%08x", fl)
The Android Open Source Project11267662009-03-18 17:39:47 -07004164 + " pf=" + pf.toShortString() + " df=" + df.toShortString()
Dianne Hackbornc4aad012013-02-22 15:05:25 -08004165 + " of=" + of.toShortString()
John Spurlock46646232013-09-30 22:32:42 -04004166 + " cf=" + cf.toShortString() + " vf=" + vf.toShortString()
Adrian Roosfa104232014-06-20 16:10:14 -07004167 + " dcf=" + dcf.toShortString()
Filip Gruszczynski2217f612015-05-26 11:32:08 -07004168 + " sf=" + sf.toShortString()
4169 + " osf=" + (osf == null ? "null" : osf.toShortString()));
Craig Mautner69b08182012-09-05 13:07:13 -07004170
Filip Gruszczynski2217f612015-05-26 11:32:08 -07004171 win.computeFrameLw(pf, df, of, cf, vf, dcf, sf, osf);
Craig Mautner69b08182012-09-05 13:07:13 -07004172
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004173 // Dock windows carve out the bottom of the screen, so normal windows
4174 // can't appear underneath them.
Craig Mautner8bd206b2012-10-03 10:32:02 -07004175 if (attrs.type == TYPE_INPUT_METHOD && win.isVisibleOrBehindKeyguardLw()
4176 && !win.getGivenInsetsPendingLw()) {
satok1bc0a492012-04-25 22:47:12 +09004177 setLastInputMethodWindowLw(null, null);
4178 offsetInputMethodWindowLw(win);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004179 }
Dianne Hackborne30e02f2014-05-27 18:24:45 -07004180 if (attrs.type == TYPE_VOICE_INTERACTION && win.isVisibleOrBehindKeyguardLw()
4181 && !win.getGivenInsetsPendingLw()) {
4182 offsetVoiceInputWindowLw(win);
4183 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004184 }
4185
satok1bc0a492012-04-25 22:47:12 +09004186 private void offsetInputMethodWindowLw(WindowState win) {
Craig Mautner4774f6a2015-03-23 11:42:55 -07004187 int top = Math.max(win.getDisplayFrameLw().top, win.getContentFrameLw().top);
satok1bc0a492012-04-25 22:47:12 +09004188 top += win.getGivenContentInsetsLw().top;
4189 if (mContentBottom > top) {
4190 mContentBottom = top;
4191 }
Dianne Hackborne30e02f2014-05-27 18:24:45 -07004192 if (mVoiceContentBottom > top) {
4193 mVoiceContentBottom = top;
4194 }
satok1bc0a492012-04-25 22:47:12 +09004195 top = win.getVisibleFrameLw().top;
4196 top += win.getGivenVisibleInsetsLw().top;
4197 if (mCurBottom > top) {
4198 mCurBottom = top;
4199 }
Craig Mautnereda67292013-04-28 13:50:14 -07004200 if (DEBUG_LAYOUT) Slog.v(TAG, "Input method: mDockBottom="
satok1bc0a492012-04-25 22:47:12 +09004201 + mDockBottom + " mContentBottom="
4202 + mContentBottom + " mCurBottom=" + mCurBottom);
4203 }
4204
Dianne Hackborne30e02f2014-05-27 18:24:45 -07004205 private void offsetVoiceInputWindowLw(WindowState win) {
Craig Mautner4774f6a2015-03-23 11:42:55 -07004206 int top = Math.max(win.getDisplayFrameLw().top, win.getContentFrameLw().top);
Dianne Hackbornae6688b2015-02-11 17:02:41 -08004207 top += win.getGivenContentInsetsLw().top;
4208 if (mVoiceContentBottom > top) {
4209 mVoiceContentBottom = top;
Dianne Hackborne30e02f2014-05-27 18:24:45 -07004210 }
4211 }
4212
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004213 /** {@inheritDoc} */
Craig Mautner61ac6bb2012-02-02 17:29:33 -08004214 @Override
4215 public void finishLayoutLw() {
4216 return;
Dianne Hackborn5f3063e2010-03-10 16:01:58 -08004217 }
4218
4219 /** {@inheritDoc} */
Craig Mautnerad09bcc2012-10-08 13:33:11 -07004220 @Override
Craig Mautner39834192012-09-02 07:47:24 -07004221 public void beginPostLayoutPolicyLw(int displayWidth, int displayHeight) {
Dianne Hackborn5f3063e2010-03-10 16:01:58 -08004222 mTopFullscreenOpaqueWindowState = null;
Adrian Rooscd3884d2015-02-18 17:25:23 +01004223 mTopFullscreenOpaqueOrDimmingWindowState = null;
Craig Mautner2bc789b2014-03-19 19:48:38 -07004224 mAppsToBeHidden.clear();
Jorim Jaggic13fcac2014-09-11 17:36:57 +02004225 mAppsThatDismissKeyguard.clear();
Dianne Hackborn5f3063e2010-03-10 16:01:58 -08004226 mForceStatusBar = false;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07004227 mForceStatusBarFromKeyguard = false;
Selim Cinek4a4a2bddc2015-05-07 12:50:19 -07004228 mForceStatusBarTransparent = false;
Dianne Hackborn891d3fb2013-01-09 18:31:37 -08004229 mForcingShowNavBar = false;
4230 mForcingShowNavBarLayer = -1;
RoboErik8a2cfc32014-05-16 11:19:38 -07004231
Dianne Hackborn5f3063e2010-03-10 16:01:58 -08004232 mHideLockScreen = false;
4233 mAllowLockscreenWhenOn = false;
Craig Mautnerad09bcc2012-10-08 13:33:11 -07004234 mDismissKeyguard = DISMISS_KEYGUARD_NONE;
Dianne Hackborn7ad44382012-10-18 17:46:00 -07004235 mShowingLockscreen = false;
4236 mShowingDream = false;
Craig Mautnerc9457fa2014-06-06 14:27:48 -07004237 mWinShowWhenLocked = null;
Jim Millerab954542014-10-10 18:21:49 -07004238 mKeyguardSecure = isKeyguardSecure();
4239 mKeyguardSecureIncludingHidden = mKeyguardSecure
4240 && (mKeyguardDelegate != null && mKeyguardDelegate.isShowing());
Dianne Hackborn5f3063e2010-03-10 16:01:58 -08004241 }
4242
4243 /** {@inheritDoc} */
Craig Mautnerad09bcc2012-10-08 13:33:11 -07004244 @Override
Craig Mautnerc9457fa2014-06-06 14:27:48 -07004245 public void applyPostLayoutPolicyLw(WindowState win, WindowManager.LayoutParams attrs) {
Dianne Hackbornbc1aa7b2011-09-20 11:20:31 -07004246 if (DEBUG_LAYOUT) Slog.i(TAG, "Win " + win + ": isVisibleOrBehindKeyguardLw="
4247 + win.isVisibleOrBehindKeyguardLw());
John Spurlockc6d1c602014-01-17 15:22:06 -05004248 final int fl = PolicyControl.getWindowFlags(win, attrs);
John Spurlock414c1f02013-12-04 13:47:36 -05004249 if (mTopFullscreenOpaqueWindowState == null
4250 && win.isVisibleLw() && attrs.type == TYPE_INPUT_METHOD) {
4251 mForcingShowNavBar = true;
4252 mForcingShowNavBarLayer = win.getSurfaceLayer();
Dianne Hackborn891d3fb2013-01-09 18:31:37 -08004253 }
Selim Cinek4a4a2bddc2015-05-07 12:50:19 -07004254 if (attrs.type == TYPE_STATUS_BAR) {
4255 if ((attrs.privateFlags & PRIVATE_FLAG_KEYGUARD) != 0) {
4256 mForceStatusBarFromKeyguard = true;
4257 }
4258 if ((attrs.privateFlags & PRIVATE_FLAG_FORCE_STATUS_BAR_VISIBLE_TRANSPARENT) != 0) {
4259 mForceStatusBarTransparent = true;
4260 }
Jorim Jaggiafd4a552014-04-08 15:13:05 +02004261 }
Adrian Roos602c68e2015-04-24 16:03:47 -07004262
4263 boolean appWindow = attrs.type >= FIRST_APPLICATION_WINDOW
4264 && attrs.type < FIRST_SYSTEM_WINDOW;
4265 final boolean showWhenLocked = (fl & FLAG_SHOW_WHEN_LOCKED) != 0;
4266 final boolean dismissKeyguard = (fl & FLAG_DISMISS_KEYGUARD) != 0;
4267
Dianne Hackborn5f3063e2010-03-10 16:01:58 -08004268 if (mTopFullscreenOpaqueWindowState == null &&
Dianne Hackborn01b02a72012-01-12 14:05:03 -08004269 win.isVisibleOrBehindKeyguardLw() && !win.isGoneForLayoutLw()) {
John Spurlockc6d1c602014-01-17 15:22:06 -05004270 if ((fl & FLAG_FORCE_NOT_FULLSCREEN) != 0) {
Jorim Jaggi380ecb82014-03-14 17:25:20 +01004271 if ((attrs.privateFlags & PRIVATE_FLAG_KEYGUARD) != 0) {
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07004272 mForceStatusBarFromKeyguard = true;
4273 } else {
4274 mForceStatusBar = true;
4275 }
4276 }
Jorim Jaggi380ecb82014-03-14 17:25:20 +01004277 if ((attrs.privateFlags & PRIVATE_FLAG_KEYGUARD) != 0) {
Dianne Hackborn7ad44382012-10-18 17:46:00 -07004278 mShowingLockscreen = true;
Dianne Hackbornbc1aa7b2011-09-20 11:20:31 -07004279 }
Dianne Hackborn7ad44382012-10-18 17:46:00 -07004280 if (attrs.type == TYPE_DREAM) {
Jeff Brownc8018eb2012-10-29 21:33:27 -07004281 // If the lockscreen was showing when the dream started then wait
4282 // for the dream to draw before hiding the lockscreen.
4283 if (!mDreamingLockscreen
4284 || (win.isVisibleLw() && win.hasDrawnLw())) {
4285 mShowingDream = true;
Craig Mautnerab55e522014-03-03 13:26:03 -08004286 appWindow = true;
Dianne Hackborn7ad44382012-10-18 17:46:00 -07004287 }
4288 }
Craig Mautnerab55e522014-03-03 13:26:03 -08004289
Craig Mautnerab55e522014-03-03 13:26:03 -08004290 if (appWindow) {
Jorim Jaggic13fcac2014-09-11 17:36:57 +02004291 final IApplicationToken appToken = win.getAppToken();
4292 if (showWhenLocked) {
Craig Mautnerc9457fa2014-06-06 14:27:48 -07004293 // Remove any previous windows with the same appToken.
Jorim Jaggic13fcac2014-09-11 17:36:57 +02004294 mAppsToBeHidden.remove(appToken);
4295 mAppsThatDismissKeyguard.remove(appToken);
Craig Mautnerca0a1242014-12-02 12:25:14 -08004296 if (mAppsToBeHidden.isEmpty()) {
Craig Mautner192d6042014-12-02 23:24:48 -08004297 if (dismissKeyguard && !mKeyguardSecure) {
4298 mAppsThatDismissKeyguard.add(appToken);
4299 } else {
Craig Mautnerca0a1242014-12-02 12:25:14 -08004300 mWinShowWhenLocked = win;
4301 mHideLockScreen = true;
4302 mForceStatusBarFromKeyguard = false;
Craig Mautnerca0a1242014-12-02 12:25:14 -08004303 }
Craig Mautnerc9457fa2014-06-06 14:27:48 -07004304 }
Jorim Jaggic13fcac2014-09-11 17:36:57 +02004305 } else if (dismissKeyguard) {
Jim Millerab954542014-10-10 18:21:49 -07004306 if (mKeyguardSecure) {
Jorim Jaggic13fcac2014-09-11 17:36:57 +02004307 mAppsToBeHidden.add(appToken);
4308 } else {
4309 mAppsToBeHidden.remove(appToken);
4310 }
4311 mAppsThatDismissKeyguard.add(appToken);
Craig Mautner2bc789b2014-03-19 19:48:38 -07004312 } else {
Jorim Jaggic13fcac2014-09-11 17:36:57 +02004313 mAppsToBeHidden.add(appToken);
Craig Mautner2bc789b2014-03-19 19:48:38 -07004314 }
Craig Mautnerab55e522014-03-03 13:26:03 -08004315 if (attrs.x == 0 && attrs.y == 0
4316 && attrs.width == WindowManager.LayoutParams.MATCH_PARENT
4317 && attrs.height == WindowManager.LayoutParams.MATCH_PARENT) {
4318 if (DEBUG_LAYOUT) Slog.v(TAG, "Fullscreen window: " + win);
4319 mTopFullscreenOpaqueWindowState = win;
Adrian Rooscd3884d2015-02-18 17:25:23 +01004320 if (mTopFullscreenOpaqueOrDimmingWindowState == null) {
4321 mTopFullscreenOpaqueOrDimmingWindowState = win;
4322 }
Jorim Jaggic13fcac2014-09-11 17:36:57 +02004323 if (!mAppsThatDismissKeyguard.isEmpty() &&
4324 mDismissKeyguard == DISMISS_KEYGUARD_NONE) {
4325 if (DEBUG_LAYOUT) Slog.v(TAG,
4326 "Setting mDismissKeyguard true by win " + win);
tingna_sunge785ffa2015-05-12 13:23:15 +08004327 mDismissKeyguard = (mWinDismissingKeyguard == win
4328 && mSecureDismissingKeyguard == mKeyguardSecure)
4329 ? DISMISS_KEYGUARD_CONTINUE : DISMISS_KEYGUARD_START;
Jorim Jaggic13fcac2014-09-11 17:36:57 +02004330 mWinDismissingKeyguard = win;
tingna_sunge785ffa2015-05-12 13:23:15 +08004331 mSecureDismissingKeyguard = mKeyguardSecure;
Jim Millerab954542014-10-10 18:21:49 -07004332 mForceStatusBarFromKeyguard = mShowingLockscreen && mKeyguardSecure;
Jorim Jaggic13fcac2014-09-11 17:36:57 +02004333 } else if (mAppsToBeHidden.isEmpty() && showWhenLocked) {
4334 if (DEBUG_LAYOUT) Slog.v(TAG,
4335 "Setting mHideLockScreen to true by win " + win);
4336 mHideLockScreen = true;
4337 mForceStatusBarFromKeyguard = false;
Craig Mautnerab55e522014-03-03 13:26:03 -08004338 }
Craig Mautner00156ec2014-03-06 22:29:02 -08004339 if ((fl & FLAG_ALLOW_LOCK_WHILE_SCREEN_ON) != 0) {
Craig Mautnerab55e522014-03-03 13:26:03 -08004340 mAllowLockscreenWhenOn = true;
4341 }
Dianne Hackborn5f3063e2010-03-10 16:01:58 -08004342 }
Craig Mautnerc9457fa2014-06-06 14:27:48 -07004343
4344 if (mWinShowWhenLocked != null &&
Adrian Roos602c68e2015-04-24 16:03:47 -07004345 mWinShowWhenLocked.getAppToken() != win.getAppToken() &&
4346 (attrs.flags & FLAG_SHOW_WHEN_LOCKED) == 0) {
Craig Mautnerc9457fa2014-06-06 14:27:48 -07004347 win.hideLw(false);
4348 }
Dianne Hackborn5f3063e2010-03-10 16:01:58 -08004349 }
Adrian Roos602c68e2015-04-24 16:03:47 -07004350 } else if (mTopFullscreenOpaqueWindowState == null && mWinShowWhenLocked == null) {
4351 // No TopFullscreenOpaqueWindow is showing, but we found a SHOW_WHEN_LOCKED window
4352 // that is being hidden in an animation - keep the
4353 // keyguard hidden until the new window shows up and
4354 // we know whether to show the keyguard or not.
Adrian Roosb85e1ec2015-05-29 15:23:18 -07004355 if (win.isAnimatingLw() && appWindow && showWhenLocked && mKeyguardHidden) {
Adrian Roos602c68e2015-04-24 16:03:47 -07004356 mHideLockScreen = true;
4357 mWinShowWhenLocked = win;
4358 }
Dianne Hackborn5f3063e2010-03-10 16:01:58 -08004359 }
Adrian Rooscd3884d2015-02-18 17:25:23 +01004360 if (mTopFullscreenOpaqueOrDimmingWindowState == null
4361 && win.isVisibleOrBehindKeyguardLw() && !win.isGoneForLayoutLw()
4362 && win.isDimming()) {
4363 mTopFullscreenOpaqueOrDimmingWindowState = win;
4364 }
Dianne Hackborn5f3063e2010-03-10 16:01:58 -08004365 }
4366
4367 /** {@inheritDoc} */
Craig Mautnerad09bcc2012-10-08 13:33:11 -07004368 @Override
Craig Mautner39834192012-09-02 07:47:24 -07004369 public int finishPostLayoutPolicyLw() {
Craig Mautnerc5e73bf2015-04-21 15:41:26 +00004370 if (mWinShowWhenLocked != null && mTopFullscreenOpaqueWindowState != null &&
4371 mWinShowWhenLocked.getAppToken() != mTopFullscreenOpaqueWindowState.getAppToken()
4372 && isKeyguardLocked()) {
Craig Mautnerc9457fa2014-06-06 14:27:48 -07004373 // A dialog is dismissing the keyguard. Put the wallpaper behind it and hide the
4374 // fullscreen window.
4375 // TODO: Make sure FLAG_SHOW_WALLPAPER is restored when dialog is dismissed. Or not.
4376 mWinShowWhenLocked.getAttrs().flags |= FLAG_SHOW_WALLPAPER;
4377 mTopFullscreenOpaqueWindowState.hideLw(false);
4378 mTopFullscreenOpaqueWindowState = mWinShowWhenLocked;
4379 }
4380
Dianne Hackborn39c2d712009-09-22 11:41:31 -07004381 int changes = 0;
Joe Onorato93056472010-09-10 10:30:46 -04004382 boolean topIsFullscreen = false;
Daniel Sandlere02d8082010-10-08 15:13:22 -04004383
4384 final WindowManager.LayoutParams lp = (mTopFullscreenOpaqueWindowState != null)
4385 ? mTopFullscreenOpaqueWindowState.getAttrs()
4386 : null;
4387
Jeff Brownc8018eb2012-10-29 21:33:27 -07004388 // If we are not currently showing a dream then remember the current
4389 // lockscreen state. We will use this to determine whether the dream
4390 // started while the lockscreen was showing and remember this state
4391 // while the dream is showing.
Dianne Hackborn7ad44382012-10-18 17:46:00 -07004392 if (!mShowingDream) {
4393 mDreamingLockscreen = mShowingLockscreen;
Jeff Brown061ea992015-04-17 19:55:47 -07004394 if (mDreamingSleepTokenNeeded) {
4395 mDreamingSleepTokenNeeded = false;
4396 mHandler.obtainMessage(MSG_UPDATE_DREAMING_SLEEP_TOKEN, 0, 1).sendToTarget();
4397 }
4398 } else {
4399 if (!mDreamingSleepTokenNeeded) {
4400 mDreamingSleepTokenNeeded = true;
4401 mHandler.obtainMessage(MSG_UPDATE_DREAMING_SLEEP_TOKEN, 1, 1).sendToTarget();
4402 }
Dianne Hackborn7ad44382012-10-18 17:46:00 -07004403 }
4404
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004405 if (mStatusBar != null) {
Craig Mautnereda67292013-04-28 13:50:14 -07004406 if (DEBUG_LAYOUT) Slog.i(TAG, "force=" + mForceStatusBar
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07004407 + " forcefkg=" + mForceStatusBarFromKeyguard
Dianne Hackbornd70bc2f2009-10-06 23:25:51 -07004408 + " top=" + mTopFullscreenOpaqueWindowState);
Selim Cinek4a4a2bddc2015-05-07 12:50:19 -07004409 boolean shouldBeTransparent = mForceStatusBarTransparent
4410 && !mForceStatusBar
4411 && !mForceStatusBarFromKeyguard;
4412 if (!shouldBeTransparent) {
4413 mStatusBarController.setShowTransparent(false /* transparent */);
4414 } else if (!mStatusBar.isVisibleLw()) {
4415 mStatusBarController.setShowTransparent(true /* transparent */);
4416 }
4417 if (mForceStatusBar || mForceStatusBarFromKeyguard || mForceStatusBarTransparent) {
Craig Mautnereda67292013-04-28 13:50:14 -07004418 if (DEBUG_LAYOUT) Slog.v(TAG, "Showing status bar: forced");
John Spurlock27735a42013-08-14 17:57:38 -04004419 if (mStatusBarController.setBarShowingLw(true)) {
4420 changes |= FINISH_LAYOUT_REDO_LAYOUT;
4421 }
Craig Mautner81defc72013-10-29 11:10:42 -07004422 // Maintain fullscreen layout until incoming animation is complete.
4423 topIsFullscreen = mTopIsFullscreen && mStatusBar.isAnimatingLw();
John Spurlockf92b6162013-11-11 15:01:16 -05004424 // Transient status bar on the lockscreen is not allowed
4425 if (mForceStatusBarFromKeyguard && mStatusBarController.isTransientShowing()) {
4426 mStatusBarController.updateVisibilityLw(false /*transientAllowed*/,
4427 mLastSystemUiFlags, mLastSystemUiFlags);
4428 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004429 } else if (mTopFullscreenOpaqueWindowState != null) {
John Spurlockc6d1c602014-01-17 15:22:06 -05004430 final int fl = PolicyControl.getWindowFlags(null, lp);
Joe Onorato93056472010-09-10 10:30:46 -04004431 if (localLOGV) {
Craig Mautnereda67292013-04-28 13:50:14 -07004432 Slog.d(TAG, "frame: " + mTopFullscreenOpaqueWindowState.getFrameLw()
Joe Onorato93056472010-09-10 10:30:46 -04004433 + " shown frame: " + mTopFullscreenOpaqueWindowState.getShownFrameLw());
Craig Mautnereda67292013-04-28 13:50:14 -07004434 Slog.d(TAG, "attr: " + mTopFullscreenOpaqueWindowState.getAttrs()
John Spurlockc6d1c602014-01-17 15:22:06 -05004435 + " lp.flags=0x" + Integer.toHexString(fl));
Joe Onorato93056472010-09-10 10:30:46 -04004436 }
John Spurlockc6d1c602014-01-17 15:22:06 -05004437 topIsFullscreen = (fl & WindowManager.LayoutParams.FLAG_FULLSCREEN) != 0
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07004438 || (mLastSystemUiFlags & View.SYSTEM_UI_FLAG_FULLSCREEN) != 0;
Joe Onorato93056472010-09-10 10:30:46 -04004439 // The subtle difference between the window for mTopFullscreenOpaqueWindowState
Mark Dolinerd0646dc2014-08-27 16:04:02 -07004440 // and mTopIsFullscreen is that mTopIsFullscreen is set only if the window
Joe Onorato93056472010-09-10 10:30:46 -04004441 // has the FLAG_FULLSCREEN set. Not sure if there is another way that to be the
4442 // case though.
John Spurlock27735a42013-08-14 17:57:38 -04004443 if (mStatusBarController.isTransientShowing()) {
4444 if (mStatusBarController.setBarShowingLw(true)) {
John Spurlock32beb2c2013-03-11 10:16:47 -04004445 changes |= FINISH_LAYOUT_REDO_LAYOUT;
4446 }
4447 } else if (topIsFullscreen) {
Craig Mautnereda67292013-04-28 13:50:14 -07004448 if (DEBUG_LAYOUT) Slog.v(TAG, "** HIDING status bar");
John Spurlock27735a42013-08-14 17:57:38 -04004449 if (mStatusBarController.setBarShowingLw(false)) {
Dianne Hackbornf87d1962012-04-04 12:48:24 -07004450 changes |= FINISH_LAYOUT_REDO_LAYOUT;
Craig Mautnereda67292013-04-28 13:50:14 -07004451 } else {
Craig Mautnerc5a6e442013-06-05 17:22:35 -07004452 if (DEBUG_LAYOUT) Slog.v(TAG, "Status bar already hiding");
Daniel Sandler40427442010-07-16 11:44:52 -04004453 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004454 } else {
Craig Mautnereda67292013-04-28 13:50:14 -07004455 if (DEBUG_LAYOUT) Slog.v(TAG, "** SHOWING status bar: top is not fullscreen");
John Spurlock27735a42013-08-14 17:57:38 -04004456 if (mStatusBarController.setBarShowingLw(true)) {
4457 changes |= FINISH_LAYOUT_REDO_LAYOUT;
4458 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004459 }
4460 }
4461 }
Daniel Sandlere02d8082010-10-08 15:13:22 -04004462
Craig Mautner81defc72013-10-29 11:10:42 -07004463 if (mTopIsFullscreen != topIsFullscreen) {
4464 if (!topIsFullscreen) {
4465 // Force another layout when status bar becomes fully shown.
4466 changes |= FINISH_LAYOUT_REDO_LAYOUT;
4467 }
4468 mTopIsFullscreen = topIsFullscreen;
4469 }
Daniel Sandlere02d8082010-10-08 15:13:22 -04004470
Craig Mautner39834192012-09-02 07:47:24 -07004471 // Hide the key guard if a visible window explicitly specifies that it wants to be
4472 // displayed when the screen is locked.
Jorim Jaggi5cf17872014-03-26 18:31:48 +01004473 if (mKeyguardDelegate != null && mStatusBar != null) {
4474 if (localLOGV) Slog.v(TAG, "finishPostLayoutPolicyLw: mHideKeyguard="
4475 + mHideLockScreen);
Jim Millerab954542014-10-10 18:21:49 -07004476 if (mDismissKeyguard != DISMISS_KEYGUARD_NONE && !mKeyguardSecure) {
Jorim Jaggi5cf17872014-03-26 18:31:48 +01004477 mKeyguardHidden = true;
Jim Millerab954542014-10-10 18:21:49 -07004478 if (setKeyguardOccludedLw(true)) {
Dianne Hackborn39c2d712009-09-22 11:41:31 -07004479 changes |= FINISH_LAYOUT_REDO_LAYOUT
4480 | FINISH_LAYOUT_REDO_CONFIG
4481 | FINISH_LAYOUT_REDO_WALLPAPER;
4482 }
Jorim Jaggi5cf17872014-03-26 18:31:48 +01004483 if (mKeyguardDelegate.isShowing()) {
4484 mHandler.post(new Runnable() {
4485 @Override
4486 public void run() {
4487 mKeyguardDelegate.keyguardDone(false, false);
4488 }
4489 });
4490 }
4491 } else if (mHideLockScreen) {
4492 mKeyguardHidden = true;
Jorim Jaggi7d85ea92015-05-20 17:20:40 -07004493 mWinDismissingKeyguard = null;
Jim Millerab954542014-10-10 18:21:49 -07004494 if (setKeyguardOccludedLw(true)) {
Jorim Jaggi5cf17872014-03-26 18:31:48 +01004495 changes |= FINISH_LAYOUT_REDO_LAYOUT
4496 | FINISH_LAYOUT_REDO_CONFIG
4497 | FINISH_LAYOUT_REDO_WALLPAPER;
4498 }
4499 } else if (mDismissKeyguard != DISMISS_KEYGUARD_NONE) {
Jorim Jaggi7d85ea92015-05-20 17:20:40 -07004500 mKeyguardHidden = false;
4501 if (setKeyguardOccludedLw(false)) {
4502 changes |= FINISH_LAYOUT_REDO_LAYOUT
4503 | FINISH_LAYOUT_REDO_CONFIG
4504 | FINISH_LAYOUT_REDO_WALLPAPER;
4505 }
Jorim Jaggi5cf17872014-03-26 18:31:48 +01004506 if (mDismissKeyguard == DISMISS_KEYGUARD_START) {
4507 // Only launch the next keyguard unlock window once per window.
Jorim Jaggi5cf17872014-03-26 18:31:48 +01004508 mHandler.post(new Runnable() {
4509 @Override
4510 public void run() {
4511 mKeyguardDelegate.dismiss();
4512 }
4513 });
4514 }
4515 } else {
4516 mWinDismissingKeyguard = null;
tingna_sunge785ffa2015-05-12 13:23:15 +08004517 mSecureDismissingKeyguard = false;
Jorim Jaggi5cf17872014-03-26 18:31:48 +01004518 mKeyguardHidden = false;
Jim Millerab954542014-10-10 18:21:49 -07004519 if (setKeyguardOccludedLw(false)) {
Jorim Jaggi5cf17872014-03-26 18:31:48 +01004520 changes |= FINISH_LAYOUT_REDO_LAYOUT
4521 | FINISH_LAYOUT_REDO_CONFIG
4522 | FINISH_LAYOUT_REDO_WALLPAPER;
4523 }
Suchi Amalapurapu9cdc9032009-05-14 18:01:07 -07004524 }
4525 }
Joe Onorato664644d2011-01-23 17:53:23 -08004526
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07004527 if ((updateSystemUiVisibilityLw()&SYSTEM_UI_CHANGING_LAYOUT) != 0) {
Dianne Hackborndf89e652011-10-06 22:35:11 -07004528 // If the navigation bar has been hidden or shown, we need to do another
4529 // layout pass to update that window.
4530 changes |= FINISH_LAYOUT_REDO_LAYOUT;
4531 }
Joe Onorato664644d2011-01-23 17:53:23 -08004532
Mike Lockwood28569302010-01-28 11:54:40 -05004533 // update since mAllowLockscreenWhenOn might have changed
4534 updateLockScreenTimeout();
Dianne Hackborn39c2d712009-09-22 11:41:31 -07004535 return changes;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004536 }
4537
Jorim Jaggi380ecb82014-03-14 17:25:20 +01004538 /**
Jim Millerab954542014-10-10 18:21:49 -07004539 * Updates the occluded state of the Keyguard.
Jorim Jaggi380ecb82014-03-14 17:25:20 +01004540 *
Jorim Jaggi380ecb82014-03-14 17:25:20 +01004541 * @return Whether the flags have changed and we have to redo the layout.
4542 */
Jim Millerab954542014-10-10 18:21:49 -07004543 private boolean setKeyguardOccludedLw(boolean isOccluded) {
4544 boolean wasOccluded = mKeyguardOccluded;
4545 boolean showing = mKeyguardDelegate.isShowing();
4546 if (wasOccluded && !isOccluded && showing) {
4547 mKeyguardOccluded = false;
4548 mKeyguardDelegate.setOccluded(false);
Jorim Jaggi380ecb82014-03-14 17:25:20 +01004549 mStatusBar.getAttrs().privateFlags |= PRIVATE_FLAG_KEYGUARD;
4550 mStatusBar.getAttrs().flags |= FLAG_SHOW_WALLPAPER;
4551 return true;
Jim Millerab954542014-10-10 18:21:49 -07004552 } else if (!wasOccluded && isOccluded && showing) {
4553 mKeyguardOccluded = true;
4554 mKeyguardDelegate.setOccluded(true);
Jorim Jaggi380ecb82014-03-14 17:25:20 +01004555 mStatusBar.getAttrs().privateFlags &= ~PRIVATE_FLAG_KEYGUARD;
4556 mStatusBar.getAttrs().flags &= ~FLAG_SHOW_WALLPAPER;
4557 return true;
4558 } else {
4559 return false;
4560 }
4561 }
4562
4563 private boolean isStatusBarKeyguard() {
4564 return mStatusBar != null
4565 && (mStatusBar.getAttrs().privateFlags & PRIVATE_FLAG_KEYGUARD) != 0;
4566 }
4567
Jose Lima9546b202014-07-02 17:21:51 -07004568 @Override
Dianne Hackborn08743722009-12-21 12:16:51 -08004569 public boolean allowAppAnimationsLw() {
Jorim Jaggi380ecb82014-03-14 17:25:20 +01004570 if (isStatusBarKeyguard() || mShowingDream) {
Craig Mautner28816302013-10-10 20:31:00 -07004571 // If keyguard or dreams is currently visible, no reason to animate behind it.
Dianne Hackborn08743722009-12-21 12:16:51 -08004572 return false;
4573 }
Dianne Hackborn08743722009-12-21 12:16:51 -08004574 return true;
4575 }
4576
Jose Lima9546b202014-07-02 17:21:51 -07004577 @Override
Dianne Hackborndf89e652011-10-06 22:35:11 -07004578 public int focusChangedLw(WindowState lastFocus, WindowState newFocus) {
Joe Onorato664644d2011-01-23 17:53:23 -08004579 mFocusedWindow = newFocus;
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07004580 if ((updateSystemUiVisibilityLw()&SYSTEM_UI_CHANGING_LAYOUT) != 0) {
Dianne Hackborndf89e652011-10-06 22:35:11 -07004581 // If the navigation bar has been hidden or shown, we need to do another
4582 // layout pass to update that window.
4583 return FINISH_LAYOUT_REDO_LAYOUT;
4584 }
4585 return 0;
Joe Onorato664644d2011-01-23 17:53:23 -08004586 }
4587
Dianne Hackborn0ecadf72009-03-31 18:00:37 -07004588 /** {@inheritDoc} */
Jose Lima9546b202014-07-02 17:21:51 -07004589 @Override
Jeff Brown46b9ac02010-04-22 18:58:52 -07004590 public void notifyLidSwitchChanged(long whenNanos, boolean lidOpen) {
4591 // lid changed state
Jeff Brownc458ce92012-04-30 14:58:40 -07004592 final int newLidState = lidOpen ? LID_OPEN : LID_CLOSED;
4593 if (newLidState == mLidState) {
4594 return;
4595 }
Jeff Brown01a98dd2011-09-20 15:08:29 -07004596
Jeff Brownc458ce92012-04-30 14:58:40 -07004597 mLidState = newLidState;
4598 applyLidSwitchState();
Jeff Brown01a98dd2011-09-20 15:08:29 -07004599 updateRotation(true);
Jeff Brownc458ce92012-04-30 14:58:40 -07004600
4601 if (lidOpen) {
Bryce Lee584a4452014-10-21 15:55:55 -07004602 wakeUp(SystemClock.uptimeMillis(), mAllowTheaterModeWakeFromLidSwitch);
Jeff Brownc458ce92012-04-30 14:58:40 -07004603 } else if (!mLidControlsSleep) {
Jeff Brown96307042012-07-27 15:51:34 -07004604 mPowerManager.userActivity(SystemClock.uptimeMillis(), false);
Jeff Brown46b9ac02010-04-22 18:58:52 -07004605 }
4606 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004607
Michael Wright3818c922014-09-02 13:59:07 -07004608 @Override
4609 public void notifyCameraLensCoverSwitchChanged(long whenNanos, boolean lensCovered) {
4610 int lensCoverState = lensCovered ? CAMERA_LENS_COVERED : CAMERA_LENS_UNCOVERED;
4611 if (mCameraLensCoverState == lensCoverState) {
4612 return;
4613 }
4614 if (mCameraLensCoverState == CAMERA_LENS_COVERED &&
4615 lensCoverState == CAMERA_LENS_UNCOVERED) {
4616 Intent intent;
4617 final boolean keyguardActive = mKeyguardDelegate == null ? false :
4618 mKeyguardDelegate.isShowing();
4619 if (keyguardActive) {
4620 intent = new Intent(MediaStore.INTENT_ACTION_STILL_IMAGE_CAMERA_SECURE);
4621 } else {
4622 intent = new Intent(MediaStore.INTENT_ACTION_STILL_IMAGE_CAMERA);
4623 }
Bryce Lee584a4452014-10-21 15:55:55 -07004624 wakeUp(whenNanos / 1000000, mAllowTheaterModeWakeFromCameraLens);
Bart Sears8b1c27c2015-03-18 23:51:02 +00004625 startActivityAsUser(intent, UserHandle.CURRENT_OR_SELF);
Michael Wright3818c922014-09-02 13:59:07 -07004626 }
4627 mCameraLensCoverState = lensCoverState;
4628 }
4629
Dianne Hackbornad7fa7f2011-01-07 14:06:50 -08004630 void setHdmiPlugged(boolean plugged) {
4631 if (mHdmiPlugged != plugged) {
4632 mHdmiPlugged = plugged;
Dianne Hackbornf87d1962012-04-04 12:48:24 -07004633 updateRotation(true, true);
Dianne Hackbornad7fa7f2011-01-07 14:06:50 -08004634 Intent intent = new Intent(ACTION_HDMI_PLUGGED);
Joe Onoratodc100302011-01-11 17:07:41 -08004635 intent.addFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY_BEFORE_BOOT);
Dianne Hackbornad7fa7f2011-01-07 14:06:50 -08004636 intent.putExtra(EXTRA_HDMI_PLUGGED_STATE, plugged);
Dianne Hackborn5ac72a22012-08-29 18:32:08 -07004637 mContext.sendStickyBroadcastAsUser(intent, UserHandle.ALL);
Dianne Hackbornad7fa7f2011-01-07 14:06:50 -08004638 }
4639 }
4640
Joe Onoratoea495d42011-04-06 11:41:11 -07004641 void initializeHdmiState() {
Joe Onorato7ba631f2011-05-04 15:28:00 -07004642 boolean plugged = false;
Joe Onoratoea495d42011-04-06 11:41:11 -07004643 // watch for HDMI plug messages if the hdmi switch exists
4644 if (new File("/sys/devices/virtual/switch/hdmi/state").exists()) {
4645 mHDMIObserver.startObserving("DEVPATH=/devices/virtual/switch/hdmi");
4646
Joe Onoratoea495d42011-04-06 11:41:11 -07004647 final String filename = "/sys/class/switch/hdmi/state";
4648 FileReader reader = null;
4649 try {
4650 reader = new FileReader(filename);
4651 char[] buf = new char[15];
4652 int n = reader.read(buf);
4653 if (n > 1) {
4654 plugged = 0 != Integer.parseInt(new String(buf, 0, n-1));
4655 }
4656 } catch (IOException ex) {
4657 Slog.w(TAG, "Couldn't read hdmi state from " + filename + ": " + ex);
4658 } catch (NumberFormatException ex) {
4659 Slog.w(TAG, "Couldn't read hdmi state from " + filename + ": " + ex);
4660 } finally {
4661 if (reader != null) {
4662 try {
4663 reader.close();
4664 } catch (IOException ex) {
4665 }
Joe Onoratodc100302011-01-11 17:07:41 -08004666 }
4667 }
4668 }
Joe Onorato7ba631f2011-05-04 15:28:00 -07004669 // This dance forces the code in setHdmiPlugged to run.
4670 // Always do this so the sticky intent is stuck (to false) if there is no hdmi.
4671 mHdmiPlugged = !plugged;
4672 setHdmiPlugged(!mHdmiPlugged);
Joe Onoratodc100302011-01-11 17:07:41 -08004673 }
4674
Dianne Hackbornc0e3f242011-08-19 14:19:10 -07004675 final Object mScreenshotLock = new Object();
Dianne Hackbornfc8fa632011-08-17 16:20:47 -07004676 ServiceConnection mScreenshotConnection = null;
Dianne Hackbornfc8fa632011-08-17 16:20:47 -07004677
Jeff Brownd5bb82d2011-10-12 13:57:59 -07004678 final Runnable mScreenshotTimeout = new Runnable() {
4679 @Override public void run() {
4680 synchronized (mScreenshotLock) {
4681 if (mScreenshotConnection != null) {
4682 mContext.unbindService(mScreenshotConnection);
4683 mScreenshotConnection = null;
Dianne Hackbornfc8fa632011-08-17 16:20:47 -07004684 }
Winson Chung9112ec32011-06-27 13:15:32 -07004685 }
Jeff Brownd5bb82d2011-10-12 13:57:59 -07004686 }
4687 };
4688
4689 // Assume this is called from the Handler thread.
4690 private void takeScreenshot() {
4691 synchronized (mScreenshotLock) {
4692 if (mScreenshotConnection != null) {
4693 return;
4694 }
4695 ComponentName cn = new ComponentName("com.android.systemui",
4696 "com.android.systemui.screenshot.TakeScreenshotService");
4697 Intent intent = new Intent();
4698 intent.setComponent(cn);
4699 ServiceConnection conn = new ServiceConnection() {
4700 @Override
4701 public void onServiceConnected(ComponentName name, IBinder service) {
4702 synchronized (mScreenshotLock) {
4703 if (mScreenshotConnection != this) {
4704 return;
4705 }
4706 Messenger messenger = new Messenger(service);
4707 Message msg = Message.obtain(null, 1);
4708 final ServiceConnection myConn = this;
4709 Handler h = new Handler(mHandler.getLooper()) {
4710 @Override
4711 public void handleMessage(Message msg) {
4712 synchronized (mScreenshotLock) {
4713 if (mScreenshotConnection == myConn) {
4714 mContext.unbindService(mScreenshotConnection);
4715 mScreenshotConnection = null;
4716 mHandler.removeCallbacks(mScreenshotTimeout);
4717 }
4718 }
4719 }
4720 };
4721 msg.replyTo = new Messenger(h);
Winson Chunga63bb842011-10-17 10:26:28 -07004722 msg.arg1 = msg.arg2 = 0;
4723 if (mStatusBar != null && mStatusBar.isVisibleLw())
4724 msg.arg1 = 1;
4725 if (mNavigationBar != null && mNavigationBar.isVisibleLw())
4726 msg.arg2 = 1;
Jeff Brownd5bb82d2011-10-12 13:57:59 -07004727 try {
4728 messenger.send(msg);
4729 } catch (RemoteException e) {
4730 }
4731 }
4732 }
4733 @Override
4734 public void onServiceDisconnected(ComponentName name) {}
4735 };
Amith Yamasani27b89e62013-01-16 12:30:11 -08004736 if (mContext.bindServiceAsUser(
4737 intent, conn, Context.BIND_AUTO_CREATE, UserHandle.CURRENT)) {
Jeff Brownd5bb82d2011-10-12 13:57:59 -07004738 mScreenshotConnection = conn;
4739 mHandler.postDelayed(mScreenshotTimeout, 10000);
4740 }
4741 }
Winson Chung9112ec32011-06-27 13:15:32 -07004742 }
4743
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004744 /** {@inheritDoc} */
Jeff Brown00fa7bd2010-07-02 15:37:36 -07004745 @Override
Jeff Brown037c33e2014-04-09 00:31:55 -07004746 public int interceptKeyBeforeQueueing(KeyEvent event, int policyFlags) {
Jeff Brown96307042012-07-27 15:51:34 -07004747 if (!mSystemBooted) {
4748 // If we have not yet booted, don't let key events do anything.
4749 return 0;
4750 }
4751
Jeff Brown037c33e2014-04-09 00:31:55 -07004752 final boolean interactive = (policyFlags & FLAG_INTERACTIVE) != 0;
Jeff Brown1f245102010-11-18 20:53:46 -08004753 final boolean down = event.getAction() == KeyEvent.ACTION_DOWN;
4754 final boolean canceled = event.isCanceled();
4755 final int keyCode = event.getKeyCode();
Jeff Browne20c9e02010-10-11 14:20:19 -07004756
Jeff Brown3122e442010-10-11 23:32:49 -07004757 final boolean isInjected = (policyFlags & WindowManagerPolicy.FLAG_INJECTED) != 0;
Jeff Brown3122e442010-10-11 23:32:49 -07004758
Mike Lockwoodc72b15f2009-11-28 20:58:22 -05004759 // If screen is off then we treat the case where the keyguard is open but hidden
4760 // the same as if it were open and in front.
4761 // This will prevent any keys other than the power button from waking the screen
4762 // when the keyguard is hidden by another activity.
Jim Miller5ecd8112013-01-09 18:50:26 -08004763 final boolean keyguardActive = (mKeyguardDelegate == null ? false :
Jeff Brown037c33e2014-04-09 00:31:55 -07004764 (interactive ?
Jim Millerab954542014-10-10 18:21:49 -07004765 isKeyguardShowingAndNotOccluded() :
Jim Miller5ecd8112013-01-09 18:50:26 -08004766 mKeyguardDelegate.isShowing()));
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004767
Jeff Brown40013652012-05-16 21:22:36 -07004768 if (DEBUG_INPUT) {
Jeff Brown00fa7bd2010-07-02 15:37:36 -07004769 Log.d(TAG, "interceptKeyTq keycode=" + keyCode
Jeff Brown037c33e2014-04-09 00:31:55 -07004770 + " interactive=" + interactive + " keyguardActive=" + keyguardActive
Jeff Brown26875502014-01-30 21:47:47 -08004771 + " policyFlags=" + Integer.toHexString(policyFlags));
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004772 }
4773
Jeff Brown037c33e2014-04-09 00:31:55 -07004774 // Basic policy based on interactive state.
Jeff Brown4d396052010-10-29 21:50:21 -07004775 int result;
Michael Wright337d9d22014-04-22 15:03:48 -07004776 boolean isWakeKey = (policyFlags & WindowManagerPolicy.FLAG_WAKE) != 0
4777 || event.isWakeKey();
Michael Wrightfc01f042014-09-08 14:12:24 -07004778 if (interactive || (isInjected && !isWakeKey)) {
RoboErikde9ba392014-09-26 12:51:01 -07004779 // When the device is interactive or the key is injected pass the
4780 // key to the application.
Jeff Brown4d396052010-10-29 21:50:21 -07004781 result = ACTION_PASS_TO_USER;
Jose Lima9546b202014-07-02 17:21:51 -07004782 isWakeKey = false;
Michael Wrightfc01f042014-09-08 14:12:24 -07004783 } else if (!interactive && shouldDispatchInputWhenNonInteractive()) {
4784 // If we're currently dozing with the screen on and the keyguard showing, pass the key
4785 // to the application but preserve its wake key status to make sure we still move
4786 // from dozing to fully interactive if we would normally go from off to fully
4787 // interactive.
4788 result = ACTION_PASS_TO_USER;
Jeff Brown4d396052010-10-29 21:50:21 -07004789 } else {
4790 // When the screen is off and the key is not injected, determine whether
4791 // to wake the device but don't pass the key to the application.
4792 result = 0;
Jeff Brown26875502014-01-30 21:47:47 -08004793 if (isWakeKey && (!down || !isWakeKeyWhenScreenOff(keyCode))) {
4794 isWakeKey = false;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004795 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004796 }
4797
Justin Kohd378ad72013-04-01 12:18:26 -07004798 // If the key would be handled globally, just return the result, don't worry about special
4799 // key processing.
Jeff Brown13f00f02014-10-31 14:45:50 -07004800 if (isValidGlobalKey(keyCode)
4801 && mGlobalKeyManager.shouldHandleGlobalKey(keyCode, event)) {
Michael Wright85b1af62014-06-04 14:51:58 -07004802 if (isWakeKey) {
Jeff Brown13f00f02014-10-31 14:45:50 -07004803 wakeUp(event.getEventTime(), mAllowTheaterModeWakeFromKey);
Michael Wright85b1af62014-06-04 14:51:58 -07004804 }
Justin Kohd378ad72013-04-01 12:18:26 -07004805 return result;
4806 }
4807
Jeff Brownbae8e772014-06-12 19:59:45 -07004808 boolean useHapticFeedback = down
4809 && (policyFlags & WindowManagerPolicy.FLAG_VIRTUAL) != 0
4810 && event.getRepeatCount() == 0;
4811
Jeff Brown4d396052010-10-29 21:50:21 -07004812 // Handle special keys.
4813 switch (keyCode) {
4814 case KeyEvent.KEYCODE_VOLUME_DOWN:
Jeff Brownb0418da2010-11-01 15:24:01 -07004815 case KeyEvent.KEYCODE_VOLUME_UP:
4816 case KeyEvent.KEYCODE_VOLUME_MUTE: {
RoboErik001c59c2015-01-26 15:53:51 -08004817 if (mUseTvRouting) {
4818 // On TVs volume keys never go to the foreground app
4819 result &= ~ACTION_PASS_TO_USER;
4820 }
Jeff Brownd5bb82d2011-10-12 13:57:59 -07004821 if (keyCode == KeyEvent.KEYCODE_VOLUME_DOWN) {
4822 if (down) {
Jeff Brown13f00f02014-10-31 14:45:50 -07004823 if (interactive && !mScreenshotChordVolumeDownKeyTriggered
Jeff Brownd5bb82d2011-10-12 13:57:59 -07004824 && (event.getFlags() & KeyEvent.FLAG_FALLBACK) == 0) {
Jeff Brown13f00f02014-10-31 14:45:50 -07004825 mScreenshotChordVolumeDownKeyTriggered = true;
4826 mScreenshotChordVolumeDownKeyTime = event.getDownTime();
4827 mScreenshotChordVolumeDownKeyConsumed = false;
Jeff Brownd5bb82d2011-10-12 13:57:59 -07004828 cancelPendingPowerKeyAction();
4829 interceptScreenshotChord();
4830 }
4831 } else {
Jeff Brown13f00f02014-10-31 14:45:50 -07004832 mScreenshotChordVolumeDownKeyTriggered = false;
Jeff Brownd5bb82d2011-10-12 13:57:59 -07004833 cancelPendingScreenshotChordAction();
4834 }
4835 } else if (keyCode == KeyEvent.KEYCODE_VOLUME_UP) {
4836 if (down) {
Jeff Brown13f00f02014-10-31 14:45:50 -07004837 if (interactive && !mScreenshotChordVolumeUpKeyTriggered
Jeff Brownd5bb82d2011-10-12 13:57:59 -07004838 && (event.getFlags() & KeyEvent.FLAG_FALLBACK) == 0) {
Jeff Brown13f00f02014-10-31 14:45:50 -07004839 mScreenshotChordVolumeUpKeyTriggered = true;
Jeff Brownd5bb82d2011-10-12 13:57:59 -07004840 cancelPendingPowerKeyAction();
4841 cancelPendingScreenshotChordAction();
4842 }
4843 } else {
Jeff Brown13f00f02014-10-31 14:45:50 -07004844 mScreenshotChordVolumeUpKeyTriggered = false;
Jeff Brownd5bb82d2011-10-12 13:57:59 -07004845 cancelPendingScreenshotChordAction();
4846 }
4847 }
Jeff Brown4d396052010-10-29 21:50:21 -07004848 if (down) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -07004849 TelecomManager telecomManager = getTelecommService();
4850 if (telecomManager != null) {
4851 if (telecomManager.isRinging()) {
Santos Cordon6848f722014-05-21 15:22:12 -07004852 // If an incoming call is ringing, either VOLUME key means
4853 // "silence ringer". We handle these keys here, rather than
4854 // in the InCallScreen, to make sure we'll respond to them
4855 // even if the InCallScreen hasn't come to the foreground yet.
4856 // Look for the DOWN event here, to agree with the "fallback"
4857 // behavior in the InCallScreen.
4858 Log.i(TAG, "interceptKeyBeforeQueueing:"
4859 + " VOLUME key-down while ringing: Silence ringer!");
Jeff Brown4d396052010-10-29 21:50:21 -07004860
Santos Cordon6848f722014-05-21 15:22:12 -07004861 // Silence the ringer. (It's safe to call this
4862 // even if the ringer has already been silenced.)
Tyler Gunnef9f6f92014-09-12 22:16:17 -07004863 telecomManager.silenceRinger();
Jeff Brown4d396052010-10-29 21:50:21 -07004864
Santos Cordon6848f722014-05-21 15:22:12 -07004865 // And *don't* pass this key thru to the current activity
4866 // (which is probably the InCallScreen.)
4867 result &= ~ACTION_PASS_TO_USER;
4868 break;
4869 }
Tyler Gunnef9f6f92014-09-12 22:16:17 -07004870 if (telecomManager.isInCall()
Santos Cordon6848f722014-05-21 15:22:12 -07004871 && (result & ACTION_PASS_TO_USER) == 0) {
4872 // If we are in call but we decided not to pass the key to
RoboErik430fc482014-06-12 15:49:20 -07004873 // the application, just pass it to the session service.
4874
4875 MediaSessionLegacyHelper.getHelper(mContext)
RoboErik3c45c292014-07-08 16:47:31 -07004876 .sendVolumeKeyEvent(event, false);
Santos Cordon6848f722014-05-21 15:22:12 -07004877 break;
Jeff Brown4d396052010-10-29 21:50:21 -07004878 }
4879 }
4880
RoboErik430fc482014-06-12 15:49:20 -07004881 if ((result & ACTION_PASS_TO_USER) == 0) {
RoboErik001c59c2015-01-26 15:53:51 -08004882 if (mUseTvRouting) {
4883 dispatchDirectAudioEvent(event);
4884 } else {
4885 // If we aren't passing to the user and no one else
4886 // handled it send it to the session manager to
4887 // figure out.
4888 MediaSessionLegacyHelper.getHelper(mContext)
4889 .sendVolumeKeyEvent(event, true);
4890 }
Jeff Brown4d396052010-10-29 21:50:21 -07004891 break;
4892 }
4893 }
4894 break;
4895 }
4896
4897 case KeyEvent.KEYCODE_ENDCALL: {
4898 result &= ~ACTION_PASS_TO_USER;
4899 if (down) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -07004900 TelecomManager telecomManager = getTelecommService();
Jeff Brown4d396052010-10-29 21:50:21 -07004901 boolean hungUp = false;
Tyler Gunnef9f6f92014-09-12 22:16:17 -07004902 if (telecomManager != null) {
4903 hungUp = telecomManager.endCall();
Jeff Brown4d396052010-10-29 21:50:21 -07004904 }
Jeff Brown13f00f02014-10-31 14:45:50 -07004905 if (interactive && !hungUp) {
4906 mEndCallKeyHandled = false;
4907 mHandler.postDelayed(mEndCallLongPress,
4908 ViewConfiguration.get(mContext).getDeviceGlobalActionKeyTimeout());
4909 } else {
4910 mEndCallKeyHandled = true;
4911 }
Jeff Brown4d396052010-10-29 21:50:21 -07004912 } else {
Jeff Brown13f00f02014-10-31 14:45:50 -07004913 if (!mEndCallKeyHandled) {
4914 mHandler.removeCallbacks(mEndCallLongPress);
4915 if (!canceled) {
4916 if ((mEndcallBehavior
4917 & Settings.System.END_BUTTON_BEHAVIOR_HOME) != 0) {
4918 if (goHome()) {
4919 break;
4920 }
Dianne Hackborn0041e972009-07-24 17:14:43 -07004921 }
Jeff Brown13f00f02014-10-31 14:45:50 -07004922 if ((mEndcallBehavior
4923 & Settings.System.END_BUTTON_BEHAVIOR_SLEEP) != 0) {
4924 mPowerManager.goToSleep(event.getEventTime(),
4925 PowerManager.GO_TO_SLEEP_REASON_POWER_BUTTON, 0);
4926 isWakeKey = false;
4927 }
Jeff Brown4d396052010-10-29 21:50:21 -07004928 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004929 }
Jeff Brown4d396052010-10-29 21:50:21 -07004930 }
4931 break;
4932 }
4933
4934 case KeyEvent.KEYCODE_POWER: {
4935 result &= ~ACTION_PASS_TO_USER;
Jeff Brown13f00f02014-10-31 14:45:50 -07004936 isWakeKey = false; // wake-up will be handled separately
Jeff Brown4d396052010-10-29 21:50:21 -07004937 if (down) {
Jeff Brown13f00f02014-10-31 14:45:50 -07004938 interceptPowerKeyDown(event, interactive);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004939 } else {
Jeff Brown13f00f02014-10-31 14:45:50 -07004940 interceptPowerKeyUp(event, interactive, canceled);
Jeff Brown4d396052010-10-29 21:50:21 -07004941 }
4942 break;
4943 }
4944
Jeff Brown6212a492014-03-07 13:58:47 -08004945 case KeyEvent.KEYCODE_SLEEP: {
4946 result &= ~ACTION_PASS_TO_USER;
Filip Gruszczynskia483a1d2015-03-17 19:06:58 +00004947 isWakeKey = false;
Jeff Brownbae8e772014-06-12 19:59:45 -07004948 if (!mPowerManager.isInteractive()) {
4949 useHapticFeedback = false; // suppress feedback if already non-interactive
4950 }
Nick Vaccarob593a812015-05-15 11:23:05 -07004951 if (down) {
4952 sleepPress(event.getEventTime());
4953 } else {
4954 sleepRelease(event.getEventTime());
4955 }
Jeff Brown6212a492014-03-07 13:58:47 -08004956 break;
4957 }
4958
4959 case KeyEvent.KEYCODE_WAKEUP: {
4960 result &= ~ACTION_PASS_TO_USER;
Jose Lima9546b202014-07-02 17:21:51 -07004961 isWakeKey = true;
Jeff Brown6212a492014-03-07 13:58:47 -08004962 break;
4963 }
4964
Jeff Brown4d396052010-10-29 21:50:21 -07004965 case KeyEvent.KEYCODE_MEDIA_PLAY:
4966 case KeyEvent.KEYCODE_MEDIA_PAUSE:
4967 case KeyEvent.KEYCODE_MEDIA_PLAY_PAUSE:
Jeff Brown4d396052010-10-29 21:50:21 -07004968 case KeyEvent.KEYCODE_HEADSETHOOK:
4969 case KeyEvent.KEYCODE_MUTE:
4970 case KeyEvent.KEYCODE_MEDIA_STOP:
4971 case KeyEvent.KEYCODE_MEDIA_NEXT:
4972 case KeyEvent.KEYCODE_MEDIA_PREVIOUS:
4973 case KeyEvent.KEYCODE_MEDIA_REWIND:
4974 case KeyEvent.KEYCODE_MEDIA_RECORD:
Jaekyun Seokbfdad8e2013-07-08 13:53:21 +09004975 case KeyEvent.KEYCODE_MEDIA_FAST_FORWARD:
4976 case KeyEvent.KEYCODE_MEDIA_AUDIO_TRACK: {
RoboErikde9ba392014-09-26 12:51:01 -07004977 if (MediaSessionLegacyHelper.getHelper(mContext).isGlobalPriorityActive()) {
4978 // If the global session is active pass all media keys to it
4979 // instead of the active window.
4980 result &= ~ACTION_PASS_TO_USER;
4981 }
Jeff Brown4d396052010-10-29 21:50:21 -07004982 if ((result & ACTION_PASS_TO_USER) == 0) {
4983 // Only do this if we would otherwise not pass it to the user. In that
4984 // case, the PhoneWindow class will do the same thing, except it will
4985 // only do it if the showing app doesn't process the key on its own.
Jeff Brown40013652012-05-16 21:22:36 -07004986 // Note that we need to make a copy of the key event here because the
4987 // original key event will be recycled when we return.
Jeff Brown4d396052010-10-29 21:50:21 -07004988 mBroadcastWakeLock.acquire();
Jeff Brown40013652012-05-16 21:22:36 -07004989 Message msg = mHandler.obtainMessage(MSG_DISPATCH_MEDIA_KEY_WITH_WAKE_LOCK,
4990 new KeyEvent(event));
4991 msg.setAsynchronous(true);
4992 msg.sendToTarget();
Jeff Brown4d396052010-10-29 21:50:21 -07004993 }
4994 break;
Jeff Brown00fa7bd2010-07-02 15:37:36 -07004995 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004996
Jeff Brown4d396052010-10-29 21:50:21 -07004997 case KeyEvent.KEYCODE_CALL: {
4998 if (down) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -07004999 TelecomManager telecomManager = getTelecommService();
5000 if (telecomManager != null) {
5001 if (telecomManager.isRinging()) {
Santos Cordon6848f722014-05-21 15:22:12 -07005002 Log.i(TAG, "interceptKeyBeforeQueueing:"
5003 + " CALL key-down while ringing: Answer the call!");
Tyler Gunnef9f6f92014-09-12 22:16:17 -07005004 telecomManager.acceptRingingCall();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005005
Santos Cordon6848f722014-05-21 15:22:12 -07005006 // And *don't* pass this key thru to the current activity
5007 // (which is presumably the InCallScreen.)
5008 result &= ~ACTION_PASS_TO_USER;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005009 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005010 }
Jeff Brown00fa7bd2010-07-02 15:37:36 -07005011 }
Jeff Brown4d396052010-10-29 21:50:21 -07005012 break;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005013 }
Michael Wright869a67c2014-08-26 19:33:06 -07005014 case KeyEvent.KEYCODE_VOICE_ASSIST: {
5015 // Only do this if we would otherwise not pass it to the user. In that case,
5016 // interceptKeyBeforeDispatching would apply a similar but different policy in
5017 // order to invoke voice assist actions. Note that we need to make a copy of the
5018 // key event here because the original key event will be recycled when we return.
5019 if ((result & ACTION_PASS_TO_USER) == 0 && !down) {
5020 mBroadcastWakeLock.acquire();
5021 Message msg = mHandler.obtainMessage(MSG_LAUNCH_VOICE_ASSIST_WITH_WAKE_LOCK,
5022 keyguardActive ? 1 : 0, 0);
5023 msg.setAsynchronous(true);
5024 msg.sendToTarget();
5025 }
5026 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005027 }
Jeff Brown26875502014-01-30 21:47:47 -08005028
Jeff Brownbae8e772014-06-12 19:59:45 -07005029 if (useHapticFeedback) {
5030 performHapticFeedbackLw(null, HapticFeedbackConstants.VIRTUAL_KEY, false);
5031 }
5032
Jeff Brown26875502014-01-30 21:47:47 -08005033 if (isWakeKey) {
Jeff Brown13f00f02014-10-31 14:45:50 -07005034 wakeUp(event.getEventTime(), mAllowTheaterModeWakeFromKey);
Jeff Brown26875502014-01-30 21:47:47 -08005035 }
Bryce Lee584a4452014-10-21 15:55:55 -07005036
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005037 return result;
5038 }
5039
Jeff Brown1c2e4942012-11-06 16:32:01 -08005040 /**
Jeff Brown13f00f02014-10-31 14:45:50 -07005041 * Returns true if the key can have global actions attached to it.
5042 * We reserve all power management keys for the system since they require
5043 * very careful handling.
5044 */
5045 private static boolean isValidGlobalKey(int keyCode) {
5046 switch (keyCode) {
5047 case KeyEvent.KEYCODE_POWER:
5048 case KeyEvent.KEYCODE_WAKEUP:
5049 case KeyEvent.KEYCODE_SLEEP:
5050 return false;
5051 default:
5052 return true;
5053 }
5054 }
5055
5056 /**
Jeff Brown1c2e4942012-11-06 16:32:01 -08005057 * When the screen is off we ignore some keys that might otherwise typically
5058 * be considered wake keys. We filter them out here.
5059 *
5060 * {@link KeyEvent#KEYCODE_POWER} is notably absent from this list because it
5061 * is always considered a wake key.
5062 */
5063 private boolean isWakeKeyWhenScreenOff(int keyCode) {
5064 switch (keyCode) {
5065 // ignore volume keys unless docked
5066 case KeyEvent.KEYCODE_VOLUME_UP:
5067 case KeyEvent.KEYCODE_VOLUME_DOWN:
5068 case KeyEvent.KEYCODE_VOLUME_MUTE:
5069 return mDockMode != Intent.EXTRA_DOCK_STATE_UNDOCKED;
5070
5071 // ignore media and camera keys
5072 case KeyEvent.KEYCODE_MUTE:
5073 case KeyEvent.KEYCODE_HEADSETHOOK:
5074 case KeyEvent.KEYCODE_MEDIA_PLAY:
5075 case KeyEvent.KEYCODE_MEDIA_PAUSE:
5076 case KeyEvent.KEYCODE_MEDIA_PLAY_PAUSE:
5077 case KeyEvent.KEYCODE_MEDIA_STOP:
5078 case KeyEvent.KEYCODE_MEDIA_NEXT:
5079 case KeyEvent.KEYCODE_MEDIA_PREVIOUS:
5080 case KeyEvent.KEYCODE_MEDIA_REWIND:
5081 case KeyEvent.KEYCODE_MEDIA_RECORD:
5082 case KeyEvent.KEYCODE_MEDIA_FAST_FORWARD:
Jaekyun Seokbfdad8e2013-07-08 13:53:21 +09005083 case KeyEvent.KEYCODE_MEDIA_AUDIO_TRACK:
Jeff Brown1c2e4942012-11-06 16:32:01 -08005084 case KeyEvent.KEYCODE_CAMERA:
5085 return false;
5086 }
5087 return true;
5088 }
5089
5090
Jeff Brown56194eb2011-03-02 19:23:13 -08005091 /** {@inheritDoc} */
5092 @Override
Michael Wright70af00a2014-09-03 19:30:20 -07005093 public int interceptMotionBeforeQueueingNonInteractive(long whenNanos, int policyFlags) {
5094 if ((policyFlags & FLAG_WAKE) != 0) {
Bryce Lee5c138322014-11-03 08:26:09 -08005095 if (wakeUp(whenNanos / 1000000, mAllowTheaterModeWakeFromMotion)) {
5096 return 0;
5097 }
Michael Wright70af00a2014-09-03 19:30:20 -07005098 }
Bryce Lee5c138322014-11-03 08:26:09 -08005099
Michael Wright70af00a2014-09-03 19:30:20 -07005100 if (shouldDispatchInputWhenNonInteractive()) {
5101 return ACTION_PASS_TO_USER;
5102 }
Bryce Lee5c138322014-11-03 08:26:09 -08005103
Bryce Lee812d7022014-11-10 13:33:28 -08005104 // If we have not passed the action up and we are in theater mode without dreaming,
5105 // there will be no dream to intercept the touch and wake into ambient. The device should
5106 // wake up in this case.
5107 if (isTheaterModeEnabled() && (policyFlags & FLAG_WAKE) != 0) {
5108 wakeUp(whenNanos / 1000000, mAllowTheaterModeWakeFromMotionWhenNotDreaming);
5109 }
5110
Jeff Brown037c33e2014-04-09 00:31:55 -07005111 return 0;
Jeff Brown56194eb2011-03-02 19:23:13 -08005112 }
5113
Michael Wright70af00a2014-09-03 19:30:20 -07005114 private boolean shouldDispatchInputWhenNonInteractive() {
Bryce Lee5c138322014-11-03 08:26:09 -08005115 // Send events to keyguard while the screen is on.
Jim Millerab954542014-10-10 18:21:49 -07005116 if (isKeyguardShowingAndNotOccluded() && mDisplay != null
5117 && mDisplay.getState() != Display.STATE_OFF) {
Bryce Lee5c138322014-11-03 08:26:09 -08005118 return true;
5119 }
5120
5121 // Send events to a dozing dream even if the screen is off since the dream
5122 // is in control of the state of the screen.
5123 IDreamManager dreamManager = getDreamManager();
5124
5125 try {
5126 if (dreamManager != null && dreamManager.isDreaming()) {
5127 return true;
5128 }
5129 } catch (RemoteException e) {
5130 Slog.e(TAG, "RemoteException when checking if dreaming", e);
5131 }
5132
5133 // Otherwise, consume events since the user can't see what is being
5134 // interacted with.
5135 return false;
Michael Wright70af00a2014-09-03 19:30:20 -07005136 }
5137
RoboErik001c59c2015-01-26 15:53:51 -08005138 private void dispatchDirectAudioEvent(KeyEvent event) {
5139 if (event.getAction() != KeyEvent.ACTION_DOWN) {
5140 return;
5141 }
5142 int keyCode = event.getKeyCode();
John Spurlockb94f2d62015-03-17 14:11:57 -04005143 int flags = AudioManager.FLAG_SHOW_UI | AudioManager.FLAG_PLAY_SOUND
5144 | AudioManager.FLAG_FROM_KEY;
RoboErik001c59c2015-01-26 15:53:51 -08005145 String pkgName = mContext.getOpPackageName();
5146 switch (keyCode) {
5147 case KeyEvent.KEYCODE_VOLUME_UP:
5148 try {
John Spurlockee5ad722015-03-03 16:17:21 -05005149 getAudioService().adjustSuggestedStreamVolume(AudioManager.ADJUST_RAISE,
John Spurlock90874332015-03-10 16:00:54 -04005150 AudioManager.USE_DEFAULT_STREAM_TYPE, flags, pkgName, TAG);
RoboErik001c59c2015-01-26 15:53:51 -08005151 } catch (RemoteException e) {
5152 Log.e(TAG, "Error dispatching volume up in dispatchTvAudioEvent.", e);
5153 }
5154 break;
5155 case KeyEvent.KEYCODE_VOLUME_DOWN:
5156 try {
John Spurlockee5ad722015-03-03 16:17:21 -05005157 getAudioService().adjustSuggestedStreamVolume(AudioManager.ADJUST_LOWER,
John Spurlock90874332015-03-10 16:00:54 -04005158 AudioManager.USE_DEFAULT_STREAM_TYPE, flags, pkgName, TAG);
RoboErik001c59c2015-01-26 15:53:51 -08005159 } catch (RemoteException e) {
5160 Log.e(TAG, "Error dispatching volume down in dispatchTvAudioEvent.", e);
5161 }
5162 break;
5163 case KeyEvent.KEYCODE_VOLUME_MUTE:
5164 try {
5165 if (event.getRepeatCount() == 0) {
John Spurlockee5ad722015-03-03 16:17:21 -05005166 getAudioService().adjustSuggestedStreamVolume(
5167 AudioManager.ADJUST_TOGGLE_MUTE,
John Spurlock90874332015-03-10 16:00:54 -04005168 AudioManager.USE_DEFAULT_STREAM_TYPE, flags, pkgName, TAG);
RoboErik001c59c2015-01-26 15:53:51 -08005169 }
5170 } catch (RemoteException e) {
5171 Log.e(TAG, "Error dispatching mute in dispatchTvAudioEvent.", e);
5172 }
5173 break;
5174 }
5175 }
5176
Jeff Brown40013652012-05-16 21:22:36 -07005177 void dispatchMediaKeyWithWakeLock(KeyEvent event) {
5178 if (DEBUG_INPUT) {
5179 Slog.d(TAG, "dispatchMediaKeyWithWakeLock: " + event);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005180 }
5181
Jeff Brown40013652012-05-16 21:22:36 -07005182 if (mHavePendingMediaKeyRepeatWithWakeLock) {
5183 if (DEBUG_INPUT) {
5184 Slog.d(TAG, "dispatchMediaKeyWithWakeLock: canceled repeat");
5185 }
5186
5187 mHandler.removeMessages(MSG_DISPATCH_MEDIA_KEY_REPEAT_WITH_WAKE_LOCK);
5188 mHavePendingMediaKeyRepeatWithWakeLock = false;
5189 mBroadcastWakeLock.release(); // pending repeat was holding onto the wake lock
5190 }
5191
5192 dispatchMediaKeyWithWakeLockToAudioService(event);
5193
5194 if (event.getAction() == KeyEvent.ACTION_DOWN
5195 && event.getRepeatCount() == 0) {
5196 mHavePendingMediaKeyRepeatWithWakeLock = true;
5197
5198 Message msg = mHandler.obtainMessage(
5199 MSG_DISPATCH_MEDIA_KEY_REPEAT_WITH_WAKE_LOCK, event);
5200 msg.setAsynchronous(true);
5201 mHandler.sendMessageDelayed(msg, ViewConfiguration.getKeyRepeatTimeout());
5202 } else {
5203 mBroadcastWakeLock.release();
5204 }
5205 }
5206
5207 void dispatchMediaKeyRepeatWithWakeLock(KeyEvent event) {
5208 mHavePendingMediaKeyRepeatWithWakeLock = false;
5209
5210 KeyEvent repeatEvent = KeyEvent.changeTimeRepeat(event,
5211 SystemClock.uptimeMillis(), 1, event.getFlags() | KeyEvent.FLAG_LONG_PRESS);
5212 if (DEBUG_INPUT) {
5213 Slog.d(TAG, "dispatchMediaKeyRepeatWithWakeLock: " + repeatEvent);
5214 }
5215
5216 dispatchMediaKeyWithWakeLockToAudioService(repeatEvent);
5217 mBroadcastWakeLock.release();
5218 }
5219
5220 void dispatchMediaKeyWithWakeLockToAudioService(KeyEvent event) {
5221 if (ActivityManagerNative.isSystemReady()) {
RoboErik430fc482014-06-12 15:49:20 -07005222 MediaSessionLegacyHelper.getHelper(mContext).sendMediaButtonEvent(event, true);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005223 }
5224 }
5225
Michael Wright869a67c2014-08-26 19:33:06 -07005226 void launchVoiceAssistWithWakeLock(boolean keyguardActive) {
Dianne Hackbornb6683c42015-06-18 17:40:33 -07005227 IDeviceIdleController dic = IDeviceIdleController.Stub.asInterface(
5228 ServiceManager.getService(Context.DEVICE_IDLE_CONTROLLER));
5229 if (dic != null) {
5230 try {
5231 dic.exitIdle("voice-search");
5232 } catch (RemoteException e) {
5233 }
5234 }
Michael Wright869a67c2014-08-26 19:33:06 -07005235 Intent voiceIntent =
5236 new Intent(RecognizerIntent.ACTION_VOICE_SEARCH_HANDS_FREE);
5237 voiceIntent.putExtra(RecognizerIntent.EXTRA_SECURE, keyguardActive);
Bart Sears8b1c27c2015-03-18 23:51:02 +00005238 startActivityAsUser(voiceIntent, UserHandle.CURRENT_OR_SELF);
Michael Wright869a67c2014-08-26 19:33:06 -07005239 mBroadcastWakeLock.release();
5240 }
5241
Mike Lockwood1753f7f2009-08-24 14:49:07 -07005242 BroadcastReceiver mDockReceiver = new BroadcastReceiver() {
Craig Mautnereee29c42013-01-17 14:44:34 -08005243 @Override
Mike Lockwood1753f7f2009-08-24 14:49:07 -07005244 public void onReceive(Context context, Intent intent) {
Dianne Hackborn867ab6472010-04-29 13:28:56 -07005245 if (Intent.ACTION_DOCK_EVENT.equals(intent.getAction())) {
5246 mDockMode = intent.getIntExtra(Intent.EXTRA_DOCK_STATE,
5247 Intent.EXTRA_DOCK_STATE_UNDOCKED);
Daniel Sandler6396c722013-04-16 20:19:09 -04005248 } else {
5249 try {
5250 IUiModeManager uiModeService = IUiModeManager.Stub.asInterface(
5251 ServiceManager.getService(Context.UI_MODE_SERVICE));
5252 mUiMode = uiModeService.getCurrentModeType();
5253 } catch (RemoteException e) {
5254 }
Dianne Hackborn80fa1662009-10-07 14:02:10 -07005255 }
Jeff Brown01a98dd2011-09-20 15:08:29 -07005256 updateRotation(true);
Craig Mautnereee29c42013-01-17 14:44:34 -08005257 synchronized (mLock) {
5258 updateOrientationListenerLp();
5259 }
Mike Lockwood1753f7f2009-08-24 14:49:07 -07005260 }
5261 };
5262
Jeff Brown6aaf2952012-10-05 16:01:08 -07005263 BroadcastReceiver mDreamReceiver = new BroadcastReceiver() {
5264 @Override
5265 public void onReceive(Context context, Intent intent) {
5266 if (Intent.ACTION_DREAMING_STARTED.equals(intent.getAction())) {
Jim Miller5ecd8112013-01-09 18:50:26 -08005267 if (mKeyguardDelegate != null) {
5268 mKeyguardDelegate.onDreamingStarted();
Jeff Brown6aaf2952012-10-05 16:01:08 -07005269 }
5270 } else if (Intent.ACTION_DREAMING_STOPPED.equals(intent.getAction())) {
Jim Miller5ecd8112013-01-09 18:50:26 -08005271 if (mKeyguardDelegate != null) {
5272 mKeyguardDelegate.onDreamingStopped();
Jeff Brown6aaf2952012-10-05 16:01:08 -07005273 }
5274 }
5275 }
5276 };
5277
Christopher Tate5e08af02012-09-21 17:17:22 -07005278 BroadcastReceiver mMultiuserReceiver = new BroadcastReceiver() {
5279 @Override
5280 public void onReceive(Context context, Intent intent) {
5281 if (Intent.ACTION_USER_SWITCHED.equals(intent.getAction())) {
5282 // tickle the settings observer: this first ensures that we're
5283 // observing the relevant settings for the newly-active user,
5284 // and then updates our own bookkeeping based on the now-
5285 // current user.
5286 mSettingsObserver.onChange(false);
John Spurlockce479d82012-11-29 09:52:21 -05005287
5288 // force a re-application of focused window sysui visibility.
5289 // the window may never have been shown for this user
5290 // e.g. the keyguard when going through the new-user setup flow
John Spurlock04db1762013-05-13 12:46:41 -04005291 synchronized (mWindowManagerFuncs.getWindowManagerLock()) {
John Spurlockce479d82012-11-29 09:52:21 -05005292 mLastSystemUiFlags = 0;
5293 updateSystemUiVisibilityLw();
5294 }
Christopher Tate5e08af02012-09-21 17:17:22 -07005295 }
5296 }
5297 };
5298
Adrian Roosddc8b272015-05-21 16:28:27 -07005299 private final Runnable mHiddenNavPanic = new Runnable() {
John Spurlockd9b70bd2014-02-06 17:02:44 -05005300 @Override
5301 public void run() {
Adrian Roosddc8b272015-05-21 16:28:27 -07005302 synchronized (mWindowManagerFuncs.getWindowManagerLock()) {
5303 if (!isUserSetupComplete()) {
5304 // Swipe-up for navigation bar is disabled during setup
5305 return;
5306 }
5307 mPendingPanicGestureUptime = SystemClock.uptimeMillis();
5308 mNavigationBarController.showTransient();
5309 }
John Spurlockd9b70bd2014-02-06 17:02:44 -05005310 }
5311 };
5312
John Spurlocke1f366f2013-08-05 12:22:40 -04005313 private void requestTransientBars(WindowState swipeTarget) {
John Spurlock04db1762013-05-13 12:46:41 -04005314 synchronized (mWindowManagerFuncs.getWindowManagerLock()) {
Maurice Lam99c6e072014-04-28 18:24:28 -07005315 if (!isUserSetupComplete()) {
5316 // Swipe-up for navigation bar is disabled during setup
5317 return;
5318 }
John Spurlock27735a42013-08-14 17:57:38 -04005319 boolean sb = mStatusBarController.checkShowTransientBarLw();
5320 boolean nb = mNavigationBarController.checkShowTransientBarLw();
John Spurlockad3e6cb2013-04-30 08:47:43 -04005321 if (sb || nb) {
Adrian Roos62b65e42015-02-25 18:05:34 +01005322 // Don't show status bar when swiping on already visible navigation bar
5323 if (!nb && swipeTarget == mNavigationBar) {
John Spurlocke1f366f2013-08-05 12:22:40 -04005324 if (DEBUG) Slog.d(TAG, "Not showing transient bar, wrong swipe target");
John Spurlockad3e6cb2013-04-30 08:47:43 -04005325 return;
5326 }
John Spurlock27735a42013-08-14 17:57:38 -04005327 if (sb) mStatusBarController.showTransient();
5328 if (nb) mNavigationBarController.showTransient();
John Spurlockf1a36642013-10-12 17:50:42 -04005329 mImmersiveModeConfirmation.confirmCurrentPrompt();
John Spurlockad3e6cb2013-04-30 08:47:43 -04005330 updateSystemUiVisibilityLw();
John Spurlock32beb2c2013-03-11 10:16:47 -04005331 }
John Spurlockad3e6cb2013-04-30 08:47:43 -04005332 }
5333 }
5334
Jeff Brown3ee549c2014-09-22 20:14:39 -07005335 // Called on the PowerManager's Notifier thread.
Jeff Brownc38c9be2012-10-04 13:16:19 -07005336 @Override
Jeff Brown416c49c2015-05-26 19:50:18 -07005337 public void startedGoingToSleep(int why) {
5338 if (DEBUG_WAKEUP) Slog.i(TAG, "Started going to sleep... (why=" + why + ")");
Jorim Jaggid175b6c2015-05-27 15:39:09 -07005339 if (mKeyguardDelegate != null) {
5340 mKeyguardDelegate.onStartedGoingToSleep(why);
5341 }
Jeff Brown416c49c2015-05-26 19:50:18 -07005342 }
5343
5344 // Called on the PowerManager's Notifier thread.
5345 @Override
5346 public void finishedGoingToSleep(int why) {
Dianne Hackborn74489012009-03-24 20:50:09 -07005347 EventLog.writeEvent(70000, 0);
Jeff Brown416c49c2015-05-26 19:50:18 -07005348 if (DEBUG_WAKEUP) Slog.i(TAG, "Finished going to sleep... (why=" + why + ")");
Jeff Brown3ee549c2014-09-22 20:14:39 -07005349
5350 // We must get this work done here because the power manager will drop
5351 // the wake lock and let the system suspend once this function returns.
The Android Open Source Project0727d222009-03-11 12:11:58 -07005352 synchronized (mLock) {
Jeff Brown3ee549c2014-09-22 20:14:39 -07005353 mAwake = false;
5354 mKeyguardDrawComplete = false;
Jeff Browna20dda42014-05-27 20:57:24 -07005355 updateWakeGestureListenerLp();
The Android Open Source Project0727d222009-03-11 12:11:58 -07005356 updateOrientationListenerLp();
Mike Lockwood28569302010-01-28 11:54:40 -05005357 updateLockScreenTimeout();
The Android Open Source Project0727d222009-03-11 12:11:58 -07005358 }
Jeff Brown3ee549c2014-09-22 20:14:39 -07005359 if (mKeyguardDelegate != null) {
Jorim Jaggid175b6c2015-05-27 15:39:09 -07005360 mKeyguardDelegate.onFinishedGoingToSleep(why);
Jeff Brown3ee549c2014-09-22 20:14:39 -07005361 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005362 }
5363
Jeff Brown3ee549c2014-09-22 20:14:39 -07005364 // Called on the PowerManager's Notifier thread.
Jeff Brownc38c9be2012-10-04 13:16:19 -07005365 @Override
Jeff Brown416c49c2015-05-26 19:50:18 -07005366 public void startedWakingUp() {
Dianne Hackborn74489012009-03-24 20:50:09 -07005367 EventLog.writeEvent(70000, 1);
Jeff Brown416c49c2015-05-26 19:50:18 -07005368 if (DEBUG_WAKEUP) Slog.i(TAG, "Started waking up...");
Craig Mautner8a0da012014-05-31 15:13:37 -07005369
Jeff Brown3ee549c2014-09-22 20:14:39 -07005370 // Since goToSleep performs these functions synchronously, we must
5371 // do the same here. We cannot post this work to a handler because
5372 // that might cause it to become reordered with respect to what
5373 // may happen in a future call to goToSleep.
The Android Open Source Project0727d222009-03-11 12:11:58 -07005374 synchronized (mLock) {
Jeff Brown3ee549c2014-09-22 20:14:39 -07005375 mAwake = true;
5376 mKeyguardDrawComplete = false;
5377 if (mKeyguardDelegate != null) {
5378 mHandler.removeMessages(MSG_KEYGUARD_DRAWN_TIMEOUT);
5379 mHandler.sendEmptyMessageDelayed(MSG_KEYGUARD_DRAWN_TIMEOUT, 1000);
5380 }
5381
Jeff Browna20dda42014-05-27 20:57:24 -07005382 updateWakeGestureListenerLp();
The Android Open Source Project0727d222009-03-11 12:11:58 -07005383 updateOrientationListenerLp();
Mike Lockwood28569302010-01-28 11:54:40 -05005384 updateLockScreenTimeout();
The Android Open Source Project0727d222009-03-11 12:11:58 -07005385 }
Jeff Brownc38c9be2012-10-04 13:16:19 -07005386
Jim Miller5ecd8112013-01-09 18:50:26 -08005387 if (mKeyguardDelegate != null) {
Jorim Jaggid175b6c2015-05-27 15:39:09 -07005388 mKeyguardDelegate.onStartedWakingUp(mKeyguardDelegateCallback);
Jeff Brown36c4db82014-09-19 12:05:31 -07005389 // ... eventually calls finishKeyguardDrawn
Jeff Brownc38c9be2012-10-04 13:16:19 -07005390 } else {
Craig Mautner8a0da012014-05-31 15:13:37 -07005391 if (DEBUG_WAKEUP) Slog.d(TAG, "null mKeyguardDelegate: setting mKeyguardDrawComplete.");
Jeff Brown36c4db82014-09-19 12:05:31 -07005392 finishKeyguardDrawn();
Jeff Brownc38c9be2012-10-04 13:16:19 -07005393 }
Jeff Brown36c4db82014-09-19 12:05:31 -07005394 }
5395
Jeff Brown416c49c2015-05-26 19:50:18 -07005396 // Called on the PowerManager's Notifier thread.
5397 @Override
5398 public void finishedWakingUp() {
5399 if (DEBUG_WAKEUP) Slog.i(TAG, "Finished waking up...");
5400 }
5401
5402 private void wakeUpFromPowerKey(long eventTime) {
5403 wakeUp(eventTime, mAllowTheaterModeWakeFromPowerKey);
5404 }
5405
5406 private boolean wakeUp(long wakeTime, boolean wakeInTheaterMode) {
Bryce Leed3896842015-06-23 17:06:51 -07005407 final boolean theaterModeEnabled = isTheaterModeEnabled();
5408 if (!wakeInTheaterMode && theaterModeEnabled) {
Jeff Brown416c49c2015-05-26 19:50:18 -07005409 return false;
5410 }
5411
Bryce Leed3896842015-06-23 17:06:51 -07005412 if (theaterModeEnabled) {
5413 Settings.Global.putInt(mContext.getContentResolver(),
5414 Settings.Global.THEATER_MODE_ON, 0);
5415 }
5416
Jeff Brown416c49c2015-05-26 19:50:18 -07005417 mPowerManager.wakeUp(wakeTime);
5418 return true;
5419 }
5420
Jeff Brown36c4db82014-09-19 12:05:31 -07005421 private void finishKeyguardDrawn() {
Jeff Brown3ee549c2014-09-22 20:14:39 -07005422 synchronized (mLock) {
5423 if (!mAwake || mKeyguardDrawComplete) {
Stefan Kuhne9326dc12015-06-12 09:25:32 -10005424 return; // We are not awake yet or we have already informed of this event.
Jeff Brown3ee549c2014-09-22 20:14:39 -07005425 }
5426
Jeff Brown36c4db82014-09-19 12:05:31 -07005427 mKeyguardDrawComplete = true;
Jeff Brown3ee549c2014-09-22 20:14:39 -07005428 if (mKeyguardDelegate != null) {
5429 mHandler.removeMessages(MSG_KEYGUARD_DRAWN_TIMEOUT);
5430 }
5431 }
5432
5433 finishScreenTurningOn();
5434 }
5435
5436 // Called on the DisplayManager's DisplayPowerController thread.
5437 @Override
5438 public void screenTurnedOff() {
5439 if (DEBUG_WAKEUP) Slog.i(TAG, "Screen turned off...");
5440
Jeff Brown48d1b142015-06-10 16:36:03 -07005441 updateScreenOffSleepToken(true);
Jeff Brown3ee549c2014-09-22 20:14:39 -07005442 synchronized (mLock) {
5443 mScreenOnEarly = false;
5444 mScreenOnFully = false;
5445 mWindowManagerDrawComplete = false;
5446 mScreenOnListener = null;
5447 updateOrientationListenerLp();
Jeff Brown36c4db82014-09-19 12:05:31 -07005448 }
5449 }
5450
Jeff Brown3ee549c2014-09-22 20:14:39 -07005451 // Called on the DisplayManager's DisplayPowerController thread.
Jeff Brown36c4db82014-09-19 12:05:31 -07005452 @Override
5453 public void screenTurningOn(final ScreenOnListener screenOnListener) {
Jeff Brown36c4db82014-09-19 12:05:31 -07005454 if (DEBUG_WAKEUP) Slog.i(TAG, "Screen turning on...");
Jeff Brown36c4db82014-09-19 12:05:31 -07005455
Jeff Brown48d1b142015-06-10 16:36:03 -07005456 updateScreenOffSleepToken(false);
Jeff Brown3ee549c2014-09-22 20:14:39 -07005457 synchronized (mLock) {
5458 mScreenOnEarly = true;
5459 mScreenOnFully = false;
5460 mWindowManagerDrawComplete = false;
5461 mScreenOnListener = screenOnListener;
Jeff Brown3ee549c2014-09-22 20:14:39 -07005462 }
Jeff Brown36c4db82014-09-19 12:05:31 -07005463
Craig Mautnerc3daedd2014-09-13 11:17:23 -07005464 mWindowManagerInternal.waitForAllWindowsDrawn(mWindowManagerDrawCallback,
5465 WAITING_FOR_DRAWN_TIMEOUT);
Stefan Kuhne9326dc12015-06-12 09:25:32 -10005466 // ... eventually calls finishWindowsDrawn which will finalize our screen turn on
5467 // as well as enabling the orientation change logic/sensor.
Jeff Brown36c4db82014-09-19 12:05:31 -07005468 }
5469
Jeff Brown36c4db82014-09-19 12:05:31 -07005470 private void finishWindowsDrawn() {
Jeff Brown3ee549c2014-09-22 20:14:39 -07005471 synchronized (mLock) {
5472 if (!mScreenOnEarly || mWindowManagerDrawComplete) {
Stefan Kuhne9326dc12015-06-12 09:25:32 -10005473 return; // Screen is not turned on or we did already handle this case earlier.
Jeff Brown3ee549c2014-09-22 20:14:39 -07005474 }
5475
Jeff Brown36c4db82014-09-19 12:05:31 -07005476 mWindowManagerDrawComplete = true;
Jeff Brown36c4db82014-09-19 12:05:31 -07005477 }
Jeff Brown3ee549c2014-09-22 20:14:39 -07005478
5479 finishScreenTurningOn();
Jeff Brownc38c9be2012-10-04 13:16:19 -07005480 }
5481
Craig Mautner8a0da012014-05-31 15:13:37 -07005482 private void finishScreenTurningOn() {
Stefan Kuhne9326dc12015-06-12 09:25:32 -10005483 synchronized (mLock) {
5484 // We have just finished drawing screen content. Since the orientation listener
5485 // gets only installed when all windows are drawn, we try to install it again.
5486 updateOrientationListenerLp();
5487 }
Jeff Brown3ee549c2014-09-22 20:14:39 -07005488 final ScreenOnListener listener;
5489 final boolean enableScreen;
Jeff Brown36c4db82014-09-19 12:05:31 -07005490 synchronized (mLock) {
Jeff Brown3ee549c2014-09-22 20:14:39 -07005491 if (DEBUG_WAKEUP) Slog.d(TAG,
5492 "finishScreenTurningOn: mAwake=" + mAwake
5493 + ", mScreenOnEarly=" + mScreenOnEarly
5494 + ", mScreenOnFully=" + mScreenOnFully
5495 + ", mKeyguardDrawComplete=" + mKeyguardDrawComplete
5496 + ", mWindowManagerDrawComplete=" + mWindowManagerDrawComplete);
5497
5498 if (mScreenOnFully || !mScreenOnEarly || !mWindowManagerDrawComplete
5499 || (mAwake && !mKeyguardDrawComplete)) {
5500 return; // spurious or not ready yet
Jeff Brown36c4db82014-09-19 12:05:31 -07005501 }
5502
Jeff Brown3ee549c2014-09-22 20:14:39 -07005503 if (DEBUG_WAKEUP) Slog.i(TAG, "Finished screen turning on...");
5504 listener = mScreenOnListener;
Craig Mautner13f6ea72014-06-23 14:57:02 -07005505 mScreenOnListener = null;
Jeff Brown3ee549c2014-09-22 20:14:39 -07005506 mScreenOnFully = true;
5507
5508 // Remember the first time we draw the keyguard so we know when we're done with
5509 // the main part of booting and can enable the screen and hide boot messages.
5510 if (!mKeyguardDrawnOnce && mAwake) {
5511 mKeyguardDrawnOnce = true;
5512 enableScreen = true;
5513 if (mBootMessageNeedsHiding) {
5514 mBootMessageNeedsHiding = false;
5515 hideBootMessages();
5516 }
5517 } else {
5518 enableScreen = false;
5519 }
Jeff Brownc38c9be2012-10-04 13:16:19 -07005520 }
5521
Jeff Brown3ee549c2014-09-22 20:14:39 -07005522 if (listener != null) {
5523 listener.onScreenOn();
5524 }
Jeff Brown4fc45272012-10-10 18:28:14 -07005525
Jeff Brown3ee549c2014-09-22 20:14:39 -07005526 if (enableScreen) {
5527 try {
5528 mWindowManager.enableScreenIfNeeded();
5529 } catch (RemoteException unhandled) {
Jeff Brown36c4db82014-09-19 12:05:31 -07005530 }
Craig Mautnera631d492014-08-05 15:16:01 -07005531 }
5532 }
5533
5534 private void handleHideBootMessage() {
Jeff Brown3ee549c2014-09-22 20:14:39 -07005535 synchronized (mLock) {
5536 if (!mKeyguardDrawnOnce) {
5537 mBootMessageNeedsHiding = true;
5538 return; // keyguard hasn't drawn the first time yet, not done booting
5539 }
Craig Mautnera631d492014-08-05 15:16:01 -07005540 }
Jeff Brown3ee549c2014-09-22 20:14:39 -07005541
5542 if (mBootMsgDialog != null) {
5543 if (DEBUG_WAKEUP) Slog.d(TAG, "handleHideBootMessage: dismissing");
5544 mBootMsgDialog.dismiss();
5545 mBootMsgDialog = null;
Craig Mautnera631d492014-08-05 15:16:01 -07005546 }
Jeff Brownc38c9be2012-10-04 13:16:19 -07005547 }
5548
5549 @Override
Jeff Brown3ee549c2014-09-22 20:14:39 -07005550 public boolean isScreenOn() {
5551 return mScreenOnFully;
Dianne Hackborn08743722009-12-21 12:16:51 -08005552 }
Jeff Brownc38c9be2012-10-04 13:16:19 -07005553
Dianne Hackborn08743722009-12-21 12:16:51 -08005554 /** {@inheritDoc} */
Jose Lima9546b202014-07-02 17:21:51 -07005555 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005556 public void enableKeyguard(boolean enabled) {
Jim Miller5ecd8112013-01-09 18:50:26 -08005557 if (mKeyguardDelegate != null) {
5558 mKeyguardDelegate.setKeyguardEnabled(enabled);
Mike Lockwood3a74bd32011-08-12 13:55:22 -07005559 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005560 }
5561
5562 /** {@inheritDoc} */
Jose Lima9546b202014-07-02 17:21:51 -07005563 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005564 public void exitKeyguardSecurely(OnKeyguardExitResult callback) {
Jim Miller5ecd8112013-01-09 18:50:26 -08005565 if (mKeyguardDelegate != null) {
5566 mKeyguardDelegate.verifyUnlock(callback);
Mike Lockwood3a74bd32011-08-12 13:55:22 -07005567 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005568 }
5569
Jim Millerab954542014-10-10 18:21:49 -07005570 private boolean isKeyguardShowingAndNotOccluded() {
Jim Miller5ecd8112013-01-09 18:50:26 -08005571 if (mKeyguardDelegate == null) return false;
Jim Millerab954542014-10-10 18:21:49 -07005572 return mKeyguardDelegate.isShowing() && !mKeyguardOccluded;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005573 }
5574
Mike Lockwood520d8bc2011-02-18 13:23:13 -05005575 /** {@inheritDoc} */
Jose Lima9546b202014-07-02 17:21:51 -07005576 @Override
Mike Lockwood520d8bc2011-02-18 13:23:13 -05005577 public boolean isKeyguardLocked() {
5578 return keyguardOn();
5579 }
5580
5581 /** {@inheritDoc} */
Jose Lima9546b202014-07-02 17:21:51 -07005582 @Override
Mike Lockwood520d8bc2011-02-18 13:23:13 -05005583 public boolean isKeyguardSecure() {
Jim Miller5ecd8112013-01-09 18:50:26 -08005584 if (mKeyguardDelegate == null) return false;
5585 return mKeyguardDelegate.isSecure();
Mike Lockwood520d8bc2011-02-18 13:23:13 -05005586 }
5587
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005588 /** {@inheritDoc} */
Jose Lima9546b202014-07-02 17:21:51 -07005589 @Override
Adrian Roos461829d2015-06-03 14:41:18 -07005590 public boolean isKeyguardShowingOrOccluded() {
5591 return mKeyguardDelegate == null ? false : mKeyguardDelegate.isShowing();
5592 }
5593
5594 /** {@inheritDoc} */
5595 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005596 public boolean inKeyguardRestrictedKeyInputMode() {
Jim Miller5ecd8112013-01-09 18:50:26 -08005597 if (mKeyguardDelegate == null) return false;
5598 return mKeyguardDelegate.isInputRestricted();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005599 }
5600
Jose Lima9546b202014-07-02 17:21:51 -07005601 @Override
Dianne Hackborn90c52de2011-09-23 12:57:44 -07005602 public void dismissKeyguardLw() {
RoboErik8a2cfc32014-05-16 11:19:38 -07005603 if (mKeyguardDelegate != null && mKeyguardDelegate.isShowing()) {
Craig Mautnerc0d2d0a2014-10-31 16:25:15 -07005604 if (DEBUG_KEYGUARD) Slog.d(TAG, "PWM.dismissKeyguardLw");
Daniel Sandler1ce804392012-11-07 15:07:12 -05005605 mHandler.post(new Runnable() {
Jose Lima9546b202014-07-02 17:21:51 -07005606 @Override
Daniel Sandler1ce804392012-11-07 15:07:12 -05005607 public void run() {
Jorim Jaggi8de4311c2014-08-11 22:36:20 +02005608 // ask the keyguard to prompt the user to authenticate if necessary
5609 mKeyguardDelegate.dismiss();
5610 }
5611 });
5612 }
5613 }
5614
5615 public void notifyActivityDrawnForKeyguardLw() {
5616 if (mKeyguardDelegate != null) {
5617 mHandler.post(new Runnable() {
5618 @Override
5619 public void run() {
5620 mKeyguardDelegate.onActivityDrawn();
Daniel Sandler1ce804392012-11-07 15:07:12 -05005621 }
5622 });
Dianne Hackborn90c52de2011-09-23 12:57:44 -07005623 }
5624 }
5625
Jorim Jaggicff0acb2014-03-31 16:35:15 +02005626 @Override
5627 public boolean isKeyguardDrawnLw() {
5628 synchronized (mLock) {
Jeff Brown3ee549c2014-09-22 20:14:39 -07005629 return mKeyguardDrawnOnce;
Jorim Jaggicff0acb2014-03-31 16:35:15 +02005630 }
5631 }
5632
Jorim Jaggi0d674622014-05-21 01:34:15 +02005633 @Override
Jorim Jaggie29b2db2014-05-30 23:17:03 +02005634 public void startKeyguardExitAnimation(long startTime, long fadeoutDuration) {
Jorim Jaggi0d674622014-05-21 01:34:15 +02005635 if (mKeyguardDelegate != null) {
Craig Mautnerc0d2d0a2014-10-31 16:25:15 -07005636 if (DEBUG_KEYGUARD) Slog.d(TAG, "PWM.startKeyguardExitAnimation");
Jorim Jaggie29b2db2014-05-30 23:17:03 +02005637 mKeyguardDelegate.startKeyguardExitAnimation(startTime, fadeoutDuration);
Jorim Jaggi0d674622014-05-21 01:34:15 +02005638 }
5639 }
5640
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005641 void sendCloseSystemWindows() {
Jorim Jaggib10e33f2015-02-04 21:57:40 +01005642 PhoneWindow.sendCloseSystemWindows(mContext, null);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005643 }
5644
5645 void sendCloseSystemWindows(String reason) {
Jorim Jaggib10e33f2015-02-04 21:57:40 +01005646 PhoneWindow.sendCloseSystemWindows(mContext, reason);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005647 }
Mitsuru Oshima831d0d92009-06-16 18:27:18 -07005648
Jeff Brown01a98dd2011-09-20 15:08:29 -07005649 @Override
5650 public int rotationForOrientationLw(int orientation, int lastRotation) {
Daniel Sandler2ed6ad62011-02-22 14:54:17 -05005651 if (false) {
5652 Slog.v(TAG, "rotationForOrientationLw(orient="
5653 + orientation + ", last=" + lastRotation
5654 + "); user=" + mUserRotation + " "
5655 + ((mUserRotationMode == WindowManagerPolicy.USER_ROTATION_LOCKED)
5656 ? "USER_ROTATION_LOCKED" : "")
5657 );
5658 }
5659
Craig Mautner46ac6fa2013-08-01 10:06:34 -07005660 if (mForceDefaultOrientation) {
5661 return Surface.ROTATION_0;
5662 }
5663
The Android Open Source Project0727d222009-03-11 12:11:58 -07005664 synchronized (mLock) {
Jeff Brownc0347aa2011-09-23 17:26:09 -07005665 int sensorRotation = mOrientationListener.getProposedRotation(); // may be -1
5666 if (sensorRotation < 0) {
Jeff Brown0f862b42012-09-27 21:11:01 -07005667 sensorRotation = lastRotation;
Jeff Brownc0347aa2011-09-23 17:26:09 -07005668 }
Jeff Brown01a98dd2011-09-20 15:08:29 -07005669
Jeff Browndec6cf42011-11-15 14:08:20 -08005670 final int preferredRotation;
Jeff Brown2e7760e2012-04-11 15:14:55 -07005671 if (mLidState == LID_OPEN && mLidOpenRotation >= 0) {
Jeff Brown01a98dd2011-09-20 15:08:29 -07005672 // Ignore sensor when lid switch is open and rotation is forced.
5673 preferredRotation = mLidOpenRotation;
5674 } else if (mDockMode == Intent.EXTRA_DOCK_STATE_CAR
Jeff Brownc0347aa2011-09-23 17:26:09 -07005675 && (mCarDockEnablesAccelerometer || mCarDockRotation >= 0)) {
Jeff Brown01a98dd2011-09-20 15:08:29 -07005676 // Ignore sensor when in car dock unless explicitly enabled.
5677 // This case can override the behavior of NOSENSOR, and can also
5678 // enable 180 degree rotation while docked.
Jeff Brownc0347aa2011-09-23 17:26:09 -07005679 preferredRotation = mCarDockEnablesAccelerometer
Jeff Brown01a98dd2011-09-20 15:08:29 -07005680 ? sensorRotation : mCarDockRotation;
Jeff Brown1a693182011-11-08 14:44:16 -08005681 } else if ((mDockMode == Intent.EXTRA_DOCK_STATE_DESK
5682 || mDockMode == Intent.EXTRA_DOCK_STATE_LE_DESK
5683 || mDockMode == Intent.EXTRA_DOCK_STATE_HE_DESK)
Jeff Brownc0347aa2011-09-23 17:26:09 -07005684 && (mDeskDockEnablesAccelerometer || mDeskDockRotation >= 0)) {
Jeff Brown01a98dd2011-09-20 15:08:29 -07005685 // Ignore sensor when in desk dock unless explicitly enabled.
5686 // This case can override the behavior of NOSENSOR, and can also
5687 // enable 180 degree rotation while docked.
Jeff Brownc0347aa2011-09-23 17:26:09 -07005688 preferredRotation = mDeskDockEnablesAccelerometer
Jeff Brown01a98dd2011-09-20 15:08:29 -07005689 ? sensorRotation : mDeskDockRotation;
Jeff Brownc82c89ed2013-04-17 17:18:15 -07005690 } else if (mHdmiPlugged && mDemoHdmiRotationLock) {
5691 // Ignore sensor when plugged into HDMI when demo HDMI rotation lock enabled.
Jeff Browneb3e4b92011-12-06 19:54:24 -08005692 // Note that the dock orientation overrides the HDMI orientation.
Jeff Brownc82c89ed2013-04-17 17:18:15 -07005693 preferredRotation = mDemoHdmiRotation;
5694 } else if (mHdmiPlugged && mDockMode == Intent.EXTRA_DOCK_STATE_UNDOCKED
5695 && mUndockedHdmiRotation >= 0) {
5696 // Ignore sensor when plugged into HDMI and an undocked orientation has
5697 // been specified in the configuration (only for legacy devices without
5698 // full multi-display support).
5699 // Note that the dock orientation overrides the HDMI orientation.
5700 preferredRotation = mUndockedHdmiRotation;
Chong Zhangae6119ff2014-11-11 18:54:39 -08005701 } else if (mDemoRotationLock) {
5702 // Ignore sensor when demo rotation lock is enabled.
5703 // Note that the dock orientation and HDMI rotation lock override this.
5704 preferredRotation = mDemoRotation;
Dianne Hackbornb9ec1ac2013-04-10 17:34:25 -07005705 } else if (orientation == ActivityInfo.SCREEN_ORIENTATION_LOCKED) {
5706 // Application just wants to remain locked in the last rotation.
5707 preferredRotation = lastRotation;
Jeff Brownbcdfc622014-03-06 19:13:04 -08005708 } else if (!mSupportAutoRotation) {
5709 // If we don't support auto-rotation then bail out here and ignore
5710 // the sensor and any rotation lock settings.
5711 preferredRotation = -1;
Jeff Brown207673cd2012-06-05 17:47:11 -07005712 } else if ((mUserRotationMode == WindowManagerPolicy.USER_ROTATION_FREE
Jeff Brown01a98dd2011-09-20 15:08:29 -07005713 && (orientation == ActivityInfo.SCREEN_ORIENTATION_USER
Dianne Hackbornb9ec1ac2013-04-10 17:34:25 -07005714 || orientation == ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED
5715 || orientation == ActivityInfo.SCREEN_ORIENTATION_USER_LANDSCAPE
5716 || orientation == ActivityInfo.SCREEN_ORIENTATION_USER_PORTRAIT
5717 || orientation == ActivityInfo.SCREEN_ORIENTATION_FULL_USER))
Jeff Brown01a98dd2011-09-20 15:08:29 -07005718 || orientation == ActivityInfo.SCREEN_ORIENTATION_SENSOR
5719 || orientation == ActivityInfo.SCREEN_ORIENTATION_FULL_SENSOR
5720 || orientation == ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE
5721 || orientation == ActivityInfo.SCREEN_ORIENTATION_SENSOR_PORTRAIT) {
5722 // Otherwise, use sensor only if requested by the application or enabled
5723 // by default for USER or UNSPECIFIED modes. Does not apply to NOSENSOR.
Jeff Brownd3187e32011-09-21 19:26:44 -07005724 if (mAllowAllRotations < 0) {
5725 // Can't read this during init() because the context doesn't
5726 // have display metrics at that time so we cannot determine
5727 // tablet vs. phone then.
5728 mAllowAllRotations = mContext.getResources().getBoolean(
5729 com.android.internal.R.bool.config_allowAllRotations) ? 1 : 0;
5730 }
Jeff Brown01a98dd2011-09-20 15:08:29 -07005731 if (sensorRotation != Surface.ROTATION_180
Jeff Brownd3187e32011-09-21 19:26:44 -07005732 || mAllowAllRotations == 1
Dianne Hackbornb9ec1ac2013-04-10 17:34:25 -07005733 || orientation == ActivityInfo.SCREEN_ORIENTATION_FULL_SENSOR
5734 || orientation == ActivityInfo.SCREEN_ORIENTATION_FULL_USER) {
Jeff Brown01a98dd2011-09-20 15:08:29 -07005735 preferredRotation = sensorRotation;
5736 } else {
5737 preferredRotation = lastRotation;
5738 }
Jeff Brown207673cd2012-06-05 17:47:11 -07005739 } else if (mUserRotationMode == WindowManagerPolicy.USER_ROTATION_LOCKED
5740 && orientation != ActivityInfo.SCREEN_ORIENTATION_NOSENSOR) {
5741 // Apply rotation lock. Does not apply to NOSENSOR.
5742 // The idea is that the user rotation expresses a weak preference for the direction
5743 // of gravity and as NOSENSOR is never affected by gravity, then neither should
5744 // NOSENSOR be affected by rotation lock (although it will be affected by docks).
Jeff Brown4dfce202011-10-05 12:00:10 -07005745 preferredRotation = mUserRotation;
Jeff Browndec6cf42011-11-15 14:08:20 -08005746 } else {
5747 // No overriding preference.
5748 // We will do exactly what the application asked us to do.
5749 preferredRotation = -1;
Jeff Brown01a98dd2011-09-20 15:08:29 -07005750 }
5751
Dianne Hackborne5439f22010-10-02 16:53:50 -07005752 switch (orientation) {
5753 case ActivityInfo.SCREEN_ORIENTATION_PORTRAIT:
Jeff Browndec6cf42011-11-15 14:08:20 -08005754 // Return portrait unless overridden.
5755 if (isAnyPortrait(preferredRotation)) {
5756 return preferredRotation;
5757 }
Dianne Hackborne5439f22010-10-02 16:53:50 -07005758 return mPortraitRotation;
Dianne Hackborne5439f22010-10-02 16:53:50 -07005759
Jeff Brown01a98dd2011-09-20 15:08:29 -07005760 case ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE:
Jeff Browndec6cf42011-11-15 14:08:20 -08005761 // Return landscape unless overridden.
5762 if (isLandscapeOrSeascape(preferredRotation)) {
5763 return preferredRotation;
5764 }
Jeff Brown01a98dd2011-09-20 15:08:29 -07005765 return mLandscapeRotation;
5766
5767 case ActivityInfo.SCREEN_ORIENTATION_REVERSE_PORTRAIT:
Jeff Browndec6cf42011-11-15 14:08:20 -08005768 // Return reverse portrait unless overridden.
5769 if (isAnyPortrait(preferredRotation)) {
5770 return preferredRotation;
5771 }
Jeff Brown01a98dd2011-09-20 15:08:29 -07005772 return mUpsideDownRotation;
5773
5774 case ActivityInfo.SCREEN_ORIENTATION_REVERSE_LANDSCAPE:
Jeff Browndec6cf42011-11-15 14:08:20 -08005775 // Return seascape unless overridden.
5776 if (isLandscapeOrSeascape(preferredRotation)) {
5777 return preferredRotation;
5778 }
Jeff Brown01a98dd2011-09-20 15:08:29 -07005779 return mSeascapeRotation;
5780
5781 case ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE:
Dianne Hackbornb9ec1ac2013-04-10 17:34:25 -07005782 case ActivityInfo.SCREEN_ORIENTATION_USER_LANDSCAPE:
Jeff Brown01a98dd2011-09-20 15:08:29 -07005783 // Return either landscape rotation.
5784 if (isLandscapeOrSeascape(preferredRotation)) {
5785 return preferredRotation;
5786 }
5787 if (isLandscapeOrSeascape(lastRotation)) {
Jeff Brown4519f072011-01-23 13:16:01 -08005788 return lastRotation;
5789 }
Jeff Brown01a98dd2011-09-20 15:08:29 -07005790 return mLandscapeRotation;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005791
Jeff Brown01a98dd2011-09-20 15:08:29 -07005792 case ActivityInfo.SCREEN_ORIENTATION_SENSOR_PORTRAIT:
Dianne Hackbornb9ec1ac2013-04-10 17:34:25 -07005793 case ActivityInfo.SCREEN_ORIENTATION_USER_PORTRAIT:
Jeff Brown01a98dd2011-09-20 15:08:29 -07005794 // Return either portrait rotation.
5795 if (isAnyPortrait(preferredRotation)) {
5796 return preferredRotation;
5797 }
5798 if (isAnyPortrait(lastRotation)) {
5799 return lastRotation;
5800 }
5801 return mPortraitRotation;
5802
5803 default:
Jeff Brown4dfce202011-10-05 12:00:10 -07005804 // For USER, UNSPECIFIED, NOSENSOR, SENSOR and FULL_SENSOR,
5805 // just return the preferred orientation we already calculated.
Jeff Brown01a98dd2011-09-20 15:08:29 -07005806 if (preferredRotation >= 0) {
5807 return preferredRotation;
5808 }
Dianne Hackborndacea8c2011-04-21 17:26:39 -07005809 return Surface.ROTATION_0;
Daniel Sandlere7e5ac22011-02-22 16:10:21 -05005810 }
5811 }
Steve Howarda7bfe6a2010-09-23 16:47:49 -07005812 }
5813
Jeff Brown01a98dd2011-09-20 15:08:29 -07005814 @Override
5815 public boolean rotationHasCompatibleMetricsLw(int orientation, int rotation) {
5816 switch (orientation) {
5817 case ActivityInfo.SCREEN_ORIENTATION_PORTRAIT:
5818 case ActivityInfo.SCREEN_ORIENTATION_REVERSE_PORTRAIT:
5819 case ActivityInfo.SCREEN_ORIENTATION_SENSOR_PORTRAIT:
5820 return isAnyPortrait(rotation);
5821
5822 case ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE:
5823 case ActivityInfo.SCREEN_ORIENTATION_REVERSE_LANDSCAPE:
5824 case ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE:
5825 return isLandscapeOrSeascape(rotation);
5826
5827 default:
5828 return true;
5829 }
Steve Howarda7bfe6a2010-09-23 16:47:49 -07005830 }
5831
Jeff Brownc0347aa2011-09-23 17:26:09 -07005832 @Override
5833 public void setRotationLw(int rotation) {
5834 mOrientationListener.setCurrentRotation(rotation);
5835 }
5836
Jeff Brown01a98dd2011-09-20 15:08:29 -07005837 private boolean isLandscapeOrSeascape(int rotation) {
5838 return rotation == mLandscapeRotation || rotation == mSeascapeRotation;
Dianne Hackborne5439f22010-10-02 16:53:50 -07005839 }
5840
Jeff Brown01a98dd2011-09-20 15:08:29 -07005841 private boolean isAnyPortrait(int rotation) {
5842 return rotation == mPortraitRotation || rotation == mUpsideDownRotation;
Dianne Hackborne5439f22010-10-02 16:53:50 -07005843 }
5844
Jose Lima9546b202014-07-02 17:21:51 -07005845 @Override
Svetoslav Ganov80943d82013-01-02 10:25:37 -08005846 public int getUserRotationMode() {
5847 return Settings.System.getIntForUser(mContext.getContentResolver(),
Brett Chabot7e55c402013-05-16 19:38:08 -07005848 Settings.System.ACCELEROMETER_ROTATION, 0, UserHandle.USER_CURRENT) != 0 ?
5849 WindowManagerPolicy.USER_ROTATION_FREE :
5850 WindowManagerPolicy.USER_ROTATION_LOCKED;
Svetoslav Ganov80943d82013-01-02 10:25:37 -08005851 }
Daniel Sandlerb73617d2010-08-17 00:41:00 -04005852
5853 // User rotation: to be used when all else fails in assigning an orientation to the device
Jose Lima9546b202014-07-02 17:21:51 -07005854 @Override
Daniel Sandlerb73617d2010-08-17 00:41:00 -04005855 public void setUserRotationMode(int mode, int rot) {
5856 ContentResolver res = mContext.getContentResolver();
Daniel Sandler2ed6ad62011-02-22 14:54:17 -05005857
5858 // mUserRotationMode and mUserRotation will be assigned by the content observer
Daniel Sandlerb73617d2010-08-17 00:41:00 -04005859 if (mode == WindowManagerPolicy.USER_ROTATION_LOCKED) {
Christopher Tate5e08af02012-09-21 17:17:22 -07005860 Settings.System.putIntForUser(res,
Daniel Sandlerb73617d2010-08-17 00:41:00 -04005861 Settings.System.USER_ROTATION,
Christopher Tate5e08af02012-09-21 17:17:22 -07005862 rot,
5863 UserHandle.USER_CURRENT);
5864 Settings.System.putIntForUser(res,
Daniel Sandler2ed6ad62011-02-22 14:54:17 -05005865 Settings.System.ACCELEROMETER_ROTATION,
Christopher Tate5e08af02012-09-21 17:17:22 -07005866 0,
5867 UserHandle.USER_CURRENT);
Daniel Sandlerb73617d2010-08-17 00:41:00 -04005868 } else {
Christopher Tate5e08af02012-09-21 17:17:22 -07005869 Settings.System.putIntForUser(res,
Daniel Sandlerb73617d2010-08-17 00:41:00 -04005870 Settings.System.ACCELEROMETER_ROTATION,
Christopher Tate5e08af02012-09-21 17:17:22 -07005871 1,
5872 UserHandle.USER_CURRENT);
Daniel Sandlerb73617d2010-08-17 00:41:00 -04005873 }
5874 }
5875
Jose Lima9546b202014-07-02 17:21:51 -07005876 @Override
Jeff Brownac143512012-04-05 18:57:33 -07005877 public void setSafeMode(boolean safeMode) {
5878 mSafeMode = safeMode;
5879 performHapticFeedbackLw(null, safeMode
5880 ? HapticFeedbackConstants.SAFE_MODE_ENABLED
5881 : HapticFeedbackConstants.SAFE_MODE_DISABLED, true);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005882 }
Craig Mautnereda67292013-04-28 13:50:14 -07005883
Dianne Hackborn181ceb52009-08-27 22:16:40 -07005884 static long[] getLongIntArray(Resources r, int resid) {
5885 int[] ar = r.getIntArray(resid);
5886 if (ar == null) {
5887 return null;
5888 }
5889 long[] out = new long[ar.length];
5890 for (int i=0; i<ar.length; i++) {
5891 out[i] = ar[i];
5892 }
5893 return out;
5894 }
Craig Mautnereda67292013-04-28 13:50:14 -07005895
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005896 /** {@inheritDoc} */
Craig Mautnereda67292013-04-28 13:50:14 -07005897 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005898 public void systemReady() {
Jim Millerab954542014-10-10 18:21:49 -07005899 mKeyguardDelegate = new KeyguardServiceDelegate(mContext);
Mike Lockwooded8902d2013-11-15 11:01:47 -08005900 mKeyguardDelegate.onSystemReady();
5901
Michael Wright3818c922014-09-02 13:59:07 -07005902 readCameraLensCoverState();
Jeff Brown4f5fa282014-06-12 19:19:15 -07005903 updateUiMode();
Dianne Hackbornb1a79802009-09-29 15:18:31 -07005904 synchronized (mLock) {
5905 updateOrientationListenerLp();
Dianne Hackbornc777e072010-02-12 13:07:59 -08005906 mSystemReady = true;
5907 mHandler.post(new Runnable() {
Craig Mautnereda67292013-04-28 13:50:14 -07005908 @Override
Dianne Hackbornc777e072010-02-12 13:07:59 -08005909 public void run() {
5910 updateSettings();
5911 }
5912 });
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005913 }
5914 }
Dianne Hackborn661cd522011-08-22 00:26:20 -07005915
Dianne Hackbornba24e4d2011-09-01 11:17:06 -07005916 /** {@inheritDoc} */
Jose Lima9546b202014-07-02 17:21:51 -07005917 @Override
Dianne Hackbornba24e4d2011-09-01 11:17:06 -07005918 public void systemBooted() {
Jim Millere5f910a2013-10-16 18:15:46 -07005919 if (mKeyguardDelegate != null) {
Jason Monk5eeebf52014-09-26 12:36:51 -04005920 mKeyguardDelegate.bindService(mContext);
Jim Millere5f910a2013-10-16 18:15:46 -07005921 mKeyguardDelegate.onBootCompleted();
5922 }
Dianne Hackbornba24e4d2011-09-01 11:17:06 -07005923 synchronized (mLock) {
5924 mSystemBooted = true;
5925 }
Jeff Brown416c49c2015-05-26 19:50:18 -07005926 startedWakingUp();
Jeff Brown36c4db82014-09-19 12:05:31 -07005927 screenTurningOn(null);
Dianne Hackbornba24e4d2011-09-01 11:17:06 -07005928 }
5929
Dianne Hackborn661cd522011-08-22 00:26:20 -07005930 ProgressDialog mBootMsgDialog = null;
5931
5932 /** {@inheritDoc} */
Jose Lima9546b202014-07-02 17:21:51 -07005933 @Override
Dianne Hackborn661cd522011-08-22 00:26:20 -07005934 public void showBootMessage(final CharSequence msg, final boolean always) {
5935 mHandler.post(new Runnable() {
5936 @Override public void run() {
5937 if (mBootMsgDialog == null) {
Craig Stout4c0cb8a2014-04-04 13:03:10 -07005938 int theme;
5939 if (mContext.getPackageManager().hasSystemFeature(
5940 PackageManager.FEATURE_WATCH)) {
5941 theme = com.android.internal.R.style.Theme_Micro_Dialog_Alert;
5942 } else if (mContext.getPackageManager().hasSystemFeature(
5943 PackageManager.FEATURE_TELEVISION)) {
5944 theme = com.android.internal.R.style.Theme_Leanback_Dialog_Alert;
5945 } else {
5946 theme = 0;
5947 }
Vinod Krishnanfa8fc412014-04-18 14:35:53 -07005948
5949 mBootMsgDialog = new ProgressDialog(mContext, theme) {
Dianne Hackborn295e3c22011-08-25 13:19:08 -07005950 // This dialog will consume all events coming in to
5951 // it, to avoid it trying to do things too early in boot.
5952 @Override public boolean dispatchKeyEvent(KeyEvent event) {
5953 return true;
5954 }
5955 @Override public boolean dispatchKeyShortcutEvent(KeyEvent event) {
5956 return true;
5957 }
5958 @Override public boolean dispatchTouchEvent(MotionEvent ev) {
5959 return true;
5960 }
5961 @Override public boolean dispatchTrackballEvent(MotionEvent ev) {
5962 return true;
5963 }
5964 @Override public boolean dispatchGenericMotionEvent(MotionEvent ev) {
5965 return true;
5966 }
5967 @Override public boolean dispatchPopulateAccessibilityEvent(
5968 AccessibilityEvent event) {
5969 return true;
5970 }
5971 };
Jeff Hao9f60c082014-10-28 18:51:07 -07005972 if (mContext.getPackageManager().isUpgrade()) {
5973 mBootMsgDialog.setTitle(R.string.android_upgrading_title);
5974 } else {
5975 mBootMsgDialog.setTitle(R.string.android_start_title);
5976 }
Dianne Hackborn661cd522011-08-22 00:26:20 -07005977 mBootMsgDialog.setProgressStyle(ProgressDialog.STYLE_SPINNER);
5978 mBootMsgDialog.setIndeterminate(true);
5979 mBootMsgDialog.getWindow().setType(
Dianne Hackborn29aae6f2011-08-18 18:30:09 -07005980 WindowManager.LayoutParams.TYPE_BOOT_PROGRESS);
Dianne Hackborn661cd522011-08-22 00:26:20 -07005981 mBootMsgDialog.getWindow().addFlags(
5982 WindowManager.LayoutParams.FLAG_DIM_BEHIND
5983 | WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN);
5984 mBootMsgDialog.getWindow().setDimAmount(1);
Dianne Hackbornd9efb952011-12-07 14:56:51 -08005985 WindowManager.LayoutParams lp = mBootMsgDialog.getWindow().getAttributes();
5986 lp.screenOrientation = ActivityInfo.SCREEN_ORIENTATION_NOSENSOR;
5987 mBootMsgDialog.getWindow().setAttributes(lp);
Dianne Hackborn661cd522011-08-22 00:26:20 -07005988 mBootMsgDialog.setCancelable(false);
5989 mBootMsgDialog.show();
5990 }
5991 mBootMsgDialog.setMessage(msg);
5992 }
5993 });
5994 }
5995
5996 /** {@inheritDoc} */
Jose Lima9546b202014-07-02 17:21:51 -07005997 @Override
Dianne Hackborn661cd522011-08-22 00:26:20 -07005998 public void hideBootMessages() {
Craig Mautnera631d492014-08-05 15:16:01 -07005999 mHandler.sendEmptyMessage(MSG_HIDE_BOOT_MESSAGE);
Dianne Hackborn661cd522011-08-22 00:26:20 -07006000 }
6001
Mike Lockwood28569302010-01-28 11:54:40 -05006002 /** {@inheritDoc} */
Jose Lima9546b202014-07-02 17:21:51 -07006003 @Override
Mike Lockwood28569302010-01-28 11:54:40 -05006004 public void userActivity() {
Dianne Hackborndf89e652011-10-06 22:35:11 -07006005 // ***************************************
6006 // NOTE NOTE NOTE NOTE NOTE NOTE NOTE NOTE
6007 // ***************************************
6008 // THIS IS CALLED FROM DEEP IN THE POWER MANAGER
6009 // WITH ITS LOCKS HELD.
6010 //
6011 // This code must be VERY careful about the locks
6012 // it acquires.
6013 // In fact, the current code acquires way too many,
6014 // and probably has lurking deadlocks.
6015
Mike Lockwood28569302010-01-28 11:54:40 -05006016 synchronized (mScreenLockTimeout) {
6017 if (mLockScreenTimerActive) {
6018 // reset the timer
6019 mHandler.removeCallbacks(mScreenLockTimeout);
6020 mHandler.postDelayed(mScreenLockTimeout, mLockScreenTimeout);
6021 }
6022 }
Daniel Sandler0601eb72011-04-13 01:01:32 -04006023 }
6024
Adam Cohenf7522022012-10-03 20:03:18 -07006025 class ScreenLockTimeout implements Runnable {
6026 Bundle options;
6027
6028 @Override
Mike Lockwood28569302010-01-28 11:54:40 -05006029 public void run() {
6030 synchronized (this) {
6031 if (localLOGV) Log.v(TAG, "mScreenLockTimeout activating keyguard");
Jim Miller5ecd8112013-01-09 18:50:26 -08006032 if (mKeyguardDelegate != null) {
6033 mKeyguardDelegate.doKeyguardTimeout(options);
Mike Lockwood3a74bd32011-08-12 13:55:22 -07006034 }
Mike Lockwood28569302010-01-28 11:54:40 -05006035 mLockScreenTimerActive = false;
Adam Cohenf7522022012-10-03 20:03:18 -07006036 options = null;
Mike Lockwood28569302010-01-28 11:54:40 -05006037 }
6038 }
Mike Lockwood28569302010-01-28 11:54:40 -05006039
Adam Cohenf7522022012-10-03 20:03:18 -07006040 public void setLockOptions(Bundle options) {
6041 this.options = options;
6042 }
6043 }
6044
6045 ScreenLockTimeout mScreenLockTimeout = new ScreenLockTimeout();
6046
Jose Lima9546b202014-07-02 17:21:51 -07006047 @Override
Adam Cohenf7522022012-10-03 20:03:18 -07006048 public void lockNow(Bundle options) {
Jim Miller93c518e2012-01-17 15:55:31 -08006049 mContext.enforceCallingOrSelfPermission(android.Manifest.permission.DEVICE_POWER, null);
6050 mHandler.removeCallbacks(mScreenLockTimeout);
Adam Cohenf7522022012-10-03 20:03:18 -07006051 if (options != null) {
6052 // In case multiple calls are made to lockNow, we don't wipe out the options
6053 // until the runnable actually executes.
6054 mScreenLockTimeout.setLockOptions(options);
6055 }
Jim Miller93c518e2012-01-17 15:55:31 -08006056 mHandler.post(mScreenLockTimeout);
6057 }
6058
Mike Lockwood28569302010-01-28 11:54:40 -05006059 private void updateLockScreenTimeout() {
6060 synchronized (mScreenLockTimeout) {
Jeff Brown3ee549c2014-09-22 20:14:39 -07006061 boolean enable = (mAllowLockscreenWhenOn && mAwake &&
Jim Miller5ecd8112013-01-09 18:50:26 -08006062 mKeyguardDelegate != null && mKeyguardDelegate.isSecure());
Mike Lockwood28569302010-01-28 11:54:40 -05006063 if (mLockScreenTimerActive != enable) {
6064 if (enable) {
6065 if (localLOGV) Log.v(TAG, "setting lockscreen timer");
6066 mHandler.postDelayed(mScreenLockTimeout, mLockScreenTimeout);
6067 } else {
6068 if (localLOGV) Log.v(TAG, "clearing lockscreen timer");
6069 mHandler.removeCallbacks(mScreenLockTimeout);
6070 }
6071 mLockScreenTimerActive = enable;
6072 }
6073 }
6074 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006075
Jeff Brown061ea992015-04-17 19:55:47 -07006076 private void updateDreamingSleepToken(boolean acquire) {
6077 if (acquire) {
6078 if (mDreamingSleepToken == null) {
6079 mDreamingSleepToken = mActivityManagerInternal.acquireSleepToken("Dream");
6080 }
6081 } else {
6082 if (mDreamingSleepToken != null) {
6083 mDreamingSleepToken.release();
Jeff Brown48d1b142015-06-10 16:36:03 -07006084 mDreamingSleepToken = null;
6085 }
6086 }
6087 }
6088
6089 private void updateScreenOffSleepToken(boolean acquire) {
6090 if (acquire) {
6091 if (mScreenOffSleepToken == null) {
6092 mScreenOffSleepToken = mActivityManagerInternal.acquireSleepToken("ScreenOff");
6093 }
6094 } else {
6095 if (mScreenOffSleepToken != null) {
6096 mScreenOffSleepToken.release();
6097 mScreenOffSleepToken = null;
Jeff Brown061ea992015-04-17 19:55:47 -07006098 }
6099 }
6100 }
6101
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006102 /** {@inheritDoc} */
Craig Mautnereda67292013-04-28 13:50:14 -07006103 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006104 public void enableScreenAfterBoot() {
6105 readLidState();
Jeff Brownc458ce92012-04-30 14:58:40 -07006106 applyLidSwitchState();
Jeff Brown01a98dd2011-09-20 15:08:29 -07006107 updateRotation(true);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006108 }
Dianne Hackbornf54c8f92009-09-19 14:03:57 -07006109
Jeff Brownc458ce92012-04-30 14:58:40 -07006110 private void applyLidSwitchState() {
Jeff Brownc458ce92012-04-30 14:58:40 -07006111 if (mLidState == LID_CLOSED && mLidControlsSleep) {
Jeff Brown6d8fd272014-05-20 21:24:38 -07006112 mPowerManager.goToSleep(SystemClock.uptimeMillis(),
Jeff Brownc12035c2014-08-13 18:52:25 -07006113 PowerManager.GO_TO_SLEEP_REASON_LID_SWITCH,
Jeff Brown6d8fd272014-05-20 21:24:38 -07006114 PowerManager.GO_TO_SLEEP_FLAG_NO_DOZE);
Jeff Brownc458ce92012-04-30 14:58:40 -07006115 }
Jeff Browna20dda42014-05-27 20:57:24 -07006116
6117 synchronized (mLock) {
6118 updateWakeGestureListenerLp();
6119 }
Jeff Brown01a98dd2011-09-20 15:08:29 -07006120 }
6121
Jeff Brown4f5fa282014-06-12 19:19:15 -07006122 void updateUiMode() {
6123 if (mUiModeManager == null) {
6124 mUiModeManager = IUiModeManager.Stub.asInterface(
6125 ServiceManager.getService(Context.UI_MODE_SERVICE));
6126 }
6127 try {
6128 mUiMode = mUiModeManager.getCurrentModeType();
6129 } catch (RemoteException e) {
6130 }
6131 }
6132
Jeff Brown01a98dd2011-09-20 15:08:29 -07006133 void updateRotation(boolean alwaysSendConfiguration) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006134 try {
6135 //set orientation on WindowManager
Dianne Hackbornf87d1962012-04-04 12:48:24 -07006136 mWindowManager.updateRotation(alwaysSendConfiguration, false);
6137 } catch (RemoteException e) {
6138 // Ignore
6139 }
6140 }
6141
6142 void updateRotation(boolean alwaysSendConfiguration, boolean forceRelayout) {
6143 try {
6144 //set orientation on WindowManager
6145 mWindowManager.updateRotation(alwaysSendConfiguration, forceRelayout);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006146 } catch (RemoteException e) {
6147 // Ignore
6148 }
6149 }
6150
Daniel Sandler6396c722013-04-16 20:19:09 -04006151 /**
6152 * Return an Intent to launch the currently active dock app as home. Returns
6153 * null if the standard home should be launched, which is the case if any of the following is
6154 * true:
6155 * <ul>
6156 * <li>The device is not in either car mode or desk mode
6157 * <li>The device is in car mode but ENABLE_CAR_DOCK_HOME_CAPTURE is false
6158 * <li>The device is in desk mode but ENABLE_DESK_DOCK_HOME_CAPTURE is false
6159 * <li>The device is in car mode but there's no CAR_DOCK app with METADATA_DOCK_HOME
6160 * <li>The device is in desk mode but there's no DESK_DOCK app with METADATA_DOCK_HOME
6161 * </ul>
Craig Mautnereda67292013-04-28 13:50:14 -07006162 * @return A dock intent.
Daniel Sandler6396c722013-04-16 20:19:09 -04006163 */
6164 Intent createHomeDockIntent() {
6165 Intent intent = null;
6166
6167 // What home does is based on the mode, not the dock state. That
6168 // is, when in car mode you should be taken to car home regardless
6169 // of whether we are actually in a car dock.
6170 if (mUiMode == Configuration.UI_MODE_TYPE_CAR) {
6171 if (ENABLE_CAR_DOCK_HOME_CAPTURE) {
6172 intent = mCarDockIntent;
6173 }
6174 } else if (mUiMode == Configuration.UI_MODE_TYPE_DESK) {
6175 if (ENABLE_DESK_DOCK_HOME_CAPTURE) {
6176 intent = mDeskDockIntent;
6177 }
Jeff Brown4f5fa282014-06-12 19:19:15 -07006178 } else if (mUiMode == Configuration.UI_MODE_TYPE_WATCH
6179 && (mDockMode == Intent.EXTRA_DOCK_STATE_DESK
6180 || mDockMode == Intent.EXTRA_DOCK_STATE_HE_DESK
6181 || mDockMode == Intent.EXTRA_DOCK_STATE_LE_DESK)) {
6182 // Always launch dock home from home when watch is docked, if it exists.
6183 intent = mDeskDockIntent;
Daniel Sandler6396c722013-04-16 20:19:09 -04006184 }
6185
6186 if (intent == null) {
6187 return null;
6188 }
6189
6190 ActivityInfo ai = null;
6191 ResolveInfo info = mContext.getPackageManager().resolveActivityAsUser(
6192 intent,
John Spurlockf56bef12013-07-09 09:51:46 -04006193 PackageManager.MATCH_DEFAULT_ONLY | PackageManager.GET_META_DATA,
Craig Mautnerd625ab22013-09-06 13:40:31 -07006194 mCurrentUserId);
Daniel Sandler6396c722013-04-16 20:19:09 -04006195 if (info != null) {
6196 ai = info.activityInfo;
6197 }
6198 if (ai != null
6199 && ai.metaData != null
6200 && ai.metaData.getBoolean(Intent.METADATA_DOCK_HOME)) {
6201 intent = new Intent(intent);
6202 intent.setClassName(ai.packageName, ai.name);
6203 return intent;
6204 }
6205
6206 return null;
6207 }
6208
Filip Gruszczynskia483a1d2015-03-17 19:06:58 +00006209 void startDockOrHome(boolean fromHomeKey, boolean awakenFromDreams) {
6210 if (awakenFromDreams) {
6211 awakenDreams();
6212 }
Daniel Sandler6396c722013-04-16 20:19:09 -04006213
6214 Intent dock = createHomeDockIntent();
6215 if (dock != null) {
6216 try {
Bryce Lee01b0c5f2015-02-05 18:24:04 -08006217 if (fromHomeKey) {
6218 dock.putExtra(WindowManagerPolicy.EXTRA_FROM_HOME_KEY, fromHomeKey);
6219 }
Bart Sears8b1c27c2015-03-18 23:51:02 +00006220 startActivityAsUser(dock, UserHandle.CURRENT);
Daniel Sandler6396c722013-04-16 20:19:09 -04006221 return;
6222 } catch (ActivityNotFoundException e) {
6223 }
6224 }
6225
Bryce Lee01b0c5f2015-02-05 18:24:04 -08006226 Intent intent;
6227
6228 if (fromHomeKey) {
6229 intent = new Intent(mHomeIntent);
6230 intent.putExtra(WindowManagerPolicy.EXTRA_FROM_HOME_KEY, fromHomeKey);
6231 } else {
6232 intent = mHomeIntent;
6233 }
6234
Bryce Lee9fc0b6f2015-03-19 21:37:45 +00006235 startActivityAsUser(intent, UserHandle.CURRENT);
Dianne Hackborn39c2d712009-09-22 11:41:31 -07006236 }
Craig Mautnereda67292013-04-28 13:50:14 -07006237
Dianne Hackborn39c2d712009-09-22 11:41:31 -07006238 /**
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006239 * goes to the home screen
6240 * @return whether it did anything
6241 */
6242 boolean goHome() {
Bart Sears8b1c27c2015-03-18 23:51:02 +00006243 if (!isUserSetupComplete()) {
6244 Slog.i(TAG, "Not going home because user setup is in progress.");
6245 return false;
6246 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006247 if (false) {
6248 // This code always brings home to the front.
Dianne Hackborn256dd3b2009-05-19 18:51:21 -07006249 try {
6250 ActivityManagerNative.getDefault().stopAppSwitches();
6251 } catch (RemoteException e) {
6252 }
Dianne Hackborn94a679d2009-07-28 17:51:07 -07006253 sendCloseSystemWindows();
Filip Gruszczynskia483a1d2015-03-17 19:06:58 +00006254 startDockOrHome(false /*fromHomeKey*/, true /* awakenFromDreams */);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006255 } else {
6256 // This code brings home to the front or, if it is already
6257 // at the front, puts the device to sleep.
6258 try {
Wink Savilled2e6a332010-02-12 12:12:06 -08006259 if (SystemProperties.getInt("persist.sys.uts-test-mode", 0) == 1) {
6260 /// Roll back EndcallBehavior as the cupcake design to pass P1 lab entry.
6261 Log.d(TAG, "UTS-TEST-MODE");
6262 } else {
6263 ActivityManagerNative.getDefault().stopAppSwitches();
6264 sendCloseSystemWindows();
Daniel Sandler6396c722013-04-16 20:19:09 -04006265 Intent dock = createHomeDockIntent();
6266 if (dock != null) {
6267 int result = ActivityManagerNative.getDefault()
6268 .startActivityAsUser(null, null, dock,
6269 dock.resolveTypeIfNeeded(mContext.getContentResolver()),
6270 null, null, 0,
6271 ActivityManager.START_FLAG_ONLY_IF_NEEDED,
Jeff Hao1b012d32014-08-20 10:35:34 -07006272 null, null, UserHandle.USER_CURRENT);
Daniel Sandler6396c722013-04-16 20:19:09 -04006273 if (result == ActivityManager.START_RETURN_INTENT_TO_CALLER) {
6274 return false;
6275 }
6276 }
Dianne Hackborn39c2d712009-09-22 11:41:31 -07006277 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006278 int result = ActivityManagerNative.getDefault()
Dianne Hackbornf265ea92013-01-31 15:00:51 -08006279 .startActivityAsUser(null, null, mHomeIntent,
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006280 mHomeIntent.resolveTypeIfNeeded(mContext.getContentResolver()),
Dianne Hackborna4972e92012-03-14 10:38:05 -07006281 null, null, 0,
6282 ActivityManager.START_FLAG_ONLY_IF_NEEDED,
Jeff Hao1b012d32014-08-20 10:35:34 -07006283 null, null, UserHandle.USER_CURRENT);
Dianne Hackborna4972e92012-03-14 10:38:05 -07006284 if (result == ActivityManager.START_RETURN_INTENT_TO_CALLER) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006285 return false;
6286 }
6287 } catch (RemoteException ex) {
6288 // bummer, the activity manager, which is in this process, is dead
6289 }
6290 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006291 return true;
6292 }
Craig Mautnereda67292013-04-28 13:50:14 -07006293
6294 @Override
The Android Open Source Project0727d222009-03-11 12:11:58 -07006295 public void setCurrentOrientationLw(int newOrientation) {
6296 synchronized (mLock) {
6297 if (newOrientation != mCurrentAppOrientation) {
6298 mCurrentAppOrientation = newOrientation;
6299 updateOrientationListenerLp();
6300 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006301 }
6302 }
Amith Yamasanic33cb712010-02-10 15:21:49 -08006303
Svetoslav Ganov7befb7d2012-09-27 16:49:23 -07006304 private void performAuditoryFeedbackForAccessibilityIfNeed() {
6305 if (!isGlobalAccessibilityGestureEnabled()) {
6306 return;
6307 }
6308 AudioManager audioManager = (AudioManager) mContext.getSystemService(
6309 Context.AUDIO_SERVICE);
6310 if (audioManager.isSilentMode()) {
6311 return;
6312 }
6313 Ringtone ringTone = RingtoneManager.getRingtone(mContext,
6314 Settings.System.DEFAULT_NOTIFICATION_URI);
6315 ringTone.setStreamType(AudioManager.STREAM_MUSIC);
6316 ringTone.play();
6317 }
Craig Mautnereda67292013-04-28 13:50:14 -07006318
Bryce Lee584a4452014-10-21 15:55:55 -07006319 private boolean isTheaterModeEnabled() {
6320 return Settings.Global.getInt(mContext.getContentResolver(),
6321 Settings.Global.THEATER_MODE_ON, 0) == 1;
6322 }
6323
Svetoslav Ganov7befb7d2012-09-27 16:49:23 -07006324 private boolean isGlobalAccessibilityGestureEnabled() {
6325 return Settings.Global.getInt(mContext.getContentResolver(),
6326 Settings.Global.ENABLE_ACCESSIBILITY_GLOBAL_GESTURE_ENABLED, 0) == 1;
6327 }
6328
Craig Mautnereda67292013-04-28 13:50:14 -07006329 @Override
The Android Open Source Project0727d222009-03-11 12:11:58 -07006330 public boolean performHapticFeedbackLw(WindowState win, int effectId, boolean always) {
Svetoslav Ganov96179212012-10-10 14:17:45 -07006331 if (!mVibrator.hasVibrator()) {
6332 return false;
6333 }
Christopher Tate5e08af02012-09-21 17:17:22 -07006334 final boolean hapticsDisabled = Settings.System.getIntForUser(mContext.getContentResolver(),
6335 Settings.System.HAPTIC_FEEDBACK_ENABLED, 0, UserHandle.USER_CURRENT) == 0;
Jeff Brown82379ba2014-07-25 19:03:28 -07006336 if (hapticsDisabled && !always) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006337 return false;
6338 }
Amith Yamasanic33cb712010-02-10 15:21:49 -08006339 long[] pattern = null;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006340 switch (effectId) {
6341 case HapticFeedbackConstants.LONG_PRESS:
Amith Yamasanic33cb712010-02-10 15:21:49 -08006342 pattern = mLongPressVibePattern;
6343 break;
Dianne Hackbornb1a79802009-09-29 15:18:31 -07006344 case HapticFeedbackConstants.VIRTUAL_KEY:
Amith Yamasanic33cb712010-02-10 15:21:49 -08006345 pattern = mVirtualKeyVibePattern;
6346 break;
6347 case HapticFeedbackConstants.KEYBOARD_TAP:
6348 pattern = mKeyboardTapVibePattern;
6349 break;
Fabrice Di Meglioeeff63a2013-08-05 12:07:24 -07006350 case HapticFeedbackConstants.CLOCK_TICK:
6351 pattern = mClockTickVibePattern;
6352 break;
Fabrice Di Megliobd9152f2013-10-01 11:21:31 -07006353 case HapticFeedbackConstants.CALENDAR_DATE:
6354 pattern = mCalendarDateVibePattern;
6355 break;
Dianne Hackbornb1a79802009-09-29 15:18:31 -07006356 case HapticFeedbackConstants.SAFE_MODE_DISABLED:
Amith Yamasanic33cb712010-02-10 15:21:49 -08006357 pattern = mSafeModeDisabledVibePattern;
6358 break;
Dianne Hackbornb1a79802009-09-29 15:18:31 -07006359 case HapticFeedbackConstants.SAFE_MODE_ENABLED:
Amith Yamasanic33cb712010-02-10 15:21:49 -08006360 pattern = mSafeModeEnabledVibePattern;
6361 break;
Mady Mellore8608912015-06-05 09:02:55 -07006362 case HapticFeedbackConstants.CONTEXT_CLICK:
6363 pattern = mContextClickVibePattern;
Mady Mellore82067b2015-04-30 09:58:35 -07006364 break;
Amith Yamasanic33cb712010-02-10 15:21:49 -08006365 default:
6366 return false;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006367 }
Dianne Hackbornf265ea92013-01-31 15:00:51 -08006368 int owningUid;
6369 String owningPackage;
6370 if (win != null) {
6371 owningUid = win.getOwningUid();
6372 owningPackage = win.getOwningPackage();
6373 } else {
6374 owningUid = android.os.Process.myUid();
Dianne Hackborn95d78532013-09-11 09:51:14 -07006375 owningPackage = mContext.getOpPackageName();
Dianne Hackbornf265ea92013-01-31 15:00:51 -08006376 }
Amith Yamasanic33cb712010-02-10 15:21:49 -08006377 if (pattern.length == 1) {
6378 // One-shot vibration
John Spurlock7b414672014-07-18 13:02:39 -04006379 mVibrator.vibrate(owningUid, owningPackage, pattern[0], VIBRATION_ATTRIBUTES);
Amith Yamasanic33cb712010-02-10 15:21:49 -08006380 } else {
6381 // Pattern vibration
John Spurlock7b414672014-07-18 13:02:39 -04006382 mVibrator.vibrate(owningUid, owningPackage, pattern, -1, VIBRATION_ATTRIBUTES);
Amith Yamasanic33cb712010-02-10 15:21:49 -08006383 }
6384 return true;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006385 }
Jeff Brownc38c9be2012-10-04 13:16:19 -07006386
6387 @Override
6388 public void keepScreenOnStartedLw() {
Daniel Sandler0601eb72011-04-13 01:01:32 -04006389 }
6390
Jeff Brownc38c9be2012-10-04 13:16:19 -07006391 @Override
6392 public void keepScreenOnStoppedLw() {
Jim Millerab954542014-10-10 18:21:49 -07006393 if (isKeyguardShowingAndNotOccluded()) {
Jim Miller25190572013-02-28 17:36:24 -08006394 mPowerManager.userActivity(SystemClock.uptimeMillis(), false);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006395 }
6396 }
Mike Lockwoodfcb39242009-10-21 23:01:07 -04006397
Dianne Hackborndf89e652011-10-06 22:35:11 -07006398 private int updateSystemUiVisibilityLw() {
Joe Onorato664644d2011-01-23 17:53:23 -08006399 // If there is no window focused, there will be nobody to handle the events
6400 // anyway, so just hang on in whatever state we're in until things settle down.
Adrian Roos53f28ec2014-10-29 17:26:12 +01006401 final WindowState win = mFocusedWindow != null ? mFocusedWindow
6402 : mTopFullscreenOpaqueWindowState;
John Spurlock79da8332013-09-20 12:04:47 -04006403 if (win == null) {
Dianne Hackborndf89e652011-10-06 22:35:11 -07006404 return 0;
6405 }
Jorim Jaggi380ecb82014-03-14 17:25:20 +01006406 if ((win.getAttrs().privateFlags & PRIVATE_FLAG_KEYGUARD) != 0 && mHideLockScreen == true) {
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07006407 // We are updating at a point where the keyguard has gotten
6408 // focus, but we were last in a state where the top window is
6409 // hiding it. This is probably because the keyguard as been
6410 // shown while the top window was displayed, so we want to ignore
6411 // it here because this is just a very transient change and it
6412 // will quickly lose focus once it correctly gets hidden.
6413 return 0;
6414 }
John Spurlock32beb2c2013-03-11 10:16:47 -04006415
John Spurlock1db8b682014-02-18 11:18:59 -05006416 int tmpVisibility = PolicyControl.getSystemUiVisibility(win, null)
Dianne Hackborne26ab702011-10-16 13:21:33 -07006417 & ~mResettingSystemUiFlags
6418 & ~mForceClearedSystemUiFlags;
John Spurlock79da8332013-09-20 12:04:47 -04006419 if (mForcingShowNavBar && win.getSurfaceLayer() < mForcingShowNavBarLayer) {
John Spurlockc6d1c602014-01-17 15:22:06 -05006420 tmpVisibility &= ~PolicyControl.adjustClearableFlags(win, View.SYSTEM_UI_CLEARABLE_FLAGS);
Dianne Hackborn891d3fb2013-01-09 18:31:37 -08006421 }
Adrian Rooscd3884d2015-02-18 17:25:23 +01006422 tmpVisibility = updateLightStatusBarLw(tmpVisibility);
John Spurlock79da8332013-09-20 12:04:47 -04006423 final int visibility = updateSystemBarsLw(win, mLastSystemUiFlags, tmpVisibility);
John Spurlockad3e6cb2013-04-30 08:47:43 -04006424 final int diff = visibility ^ mLastSystemUiFlags;
John Spurlock79da8332013-09-20 12:04:47 -04006425 final boolean needsMenu = win.getNeedsMenuLw(mTopFullscreenOpaqueWindowState);
Dianne Hackborne0f085d2011-11-30 18:41:15 -08006426 if (diff == 0 && mLastFocusNeedsMenu == needsMenu
John Spurlock79da8332013-09-20 12:04:47 -04006427 && mFocusedApp == win.getAppToken()) {
Dianne Hackborndf89e652011-10-06 22:35:11 -07006428 return 0;
6429 }
Dianne Hackborne26ab702011-10-16 13:21:33 -07006430 mLastSystemUiFlags = visibility;
Dianne Hackborn4eff8d32011-11-10 19:38:40 -08006431 mLastFocusNeedsMenu = needsMenu;
John Spurlock79da8332013-09-20 12:04:47 -04006432 mFocusedApp = win.getAppToken();
Dianne Hackborndf89e652011-10-06 22:35:11 -07006433 mHandler.post(new Runnable() {
Craig Mautnereda67292013-04-28 13:50:14 -07006434 @Override
Dianne Hackborndf89e652011-10-06 22:35:11 -07006435 public void run() {
Dianne Hackborn42e620c2012-06-24 13:20:51 -07006436 try {
6437 IStatusBarService statusbar = getStatusBarService();
6438 if (statusbar != null) {
Adrian Roos53f28ec2014-10-29 17:26:12 +01006439 statusbar.setSystemUiVisibility(visibility, 0xffffffff, win.toString());
Dianne Hackborn42e620c2012-06-24 13:20:51 -07006440 statusbar.topAppWindowChanged(needsMenu);
Joe Onorato664644d2011-01-23 17:53:23 -08006441 }
Dianne Hackborn42e620c2012-06-24 13:20:51 -07006442 } catch (RemoteException e) {
6443 // re-acquire status bar service next time it is needed.
6444 mStatusBarService = null;
Joe Onorato664644d2011-01-23 17:53:23 -08006445 }
Dianne Hackborndf89e652011-10-06 22:35:11 -07006446 }
6447 });
6448 return diff;
Joe Onorato664644d2011-01-23 17:53:23 -08006449 }
6450
Adrian Rooscd3884d2015-02-18 17:25:23 +01006451 private int updateLightStatusBarLw(int vis) {
6452 WindowState statusColorWin = isStatusBarKeyguard() && !mHideLockScreen
6453 ? mStatusBar
6454 : mTopFullscreenOpaqueOrDimmingWindowState;
6455
6456 if (statusColorWin != null) {
6457 if (statusColorWin == mTopFullscreenOpaqueWindowState) {
6458 // If the top fullscreen-or-dimming window is also the top fullscreen, respect
6459 // its light flag.
6460 vis &= ~View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR;
6461 vis |= PolicyControl.getSystemUiVisibility(statusColorWin, null)
6462 & View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR;
6463 } else if (statusColorWin != null && statusColorWin.isDimming()) {
6464 // Otherwise if it's dimming, clear the light flag.
6465 vis &= ~View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR;
6466 }
6467 }
6468 return vis;
6469 }
6470
John Spurlock79da8332013-09-20 12:04:47 -04006471 private int updateSystemBarsLw(WindowState win, int oldVis, int vis) {
John Spurlockbd957402013-10-03 11:38:39 -04006472 // apply translucent bar vis flags
Jorim Jaggi380ecb82014-03-14 17:25:20 +01006473 WindowState transWin = isStatusBarKeyguard() && !mHideLockScreen
6474 ? mStatusBar
John Spurlockbd957402013-10-03 11:38:39 -04006475 : mTopFullscreenOpaqueWindowState;
6476 vis = mStatusBarController.applyTranslucentFlagLw(transWin, vis, oldVis);
6477 vis = mNavigationBarController.applyTranslucentFlagLw(transWin, vis, oldVis);
6478
John Spurlock27735a42013-08-14 17:57:38 -04006479 // prevent status bar interaction from clearing certain flags
Selim Cinekf83e8242015-05-19 18:08:14 -07006480 int type = win.getAttrs().type;
6481 boolean statusBarHasFocus = type == TYPE_STATUS_BAR;
John Spurlock08ffcf52014-07-11 10:13:46 -04006482 if (statusBarHasFocus && !isStatusBarKeyguard()) {
John Spurlockad3e6cb2013-04-30 08:47:43 -04006483 int flags = View.SYSTEM_UI_FLAG_FULLSCREEN
6484 | View.SYSTEM_UI_FLAG_HIDE_NAVIGATION
John Spurlockcfc359a2013-09-05 10:42:03 -04006485 | View.SYSTEM_UI_FLAG_IMMERSIVE
Jorim Jaggi73fef8d2015-02-16 17:32:28 +01006486 | View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY
6487 | View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR;
John Spurlock08ffcf52014-07-11 10:13:46 -04006488 if (mHideLockScreen) {
Jorim Jaggi5cf17872014-03-26 18:31:48 +01006489 flags |= View.STATUS_BAR_TRANSLUCENT | View.NAVIGATION_BAR_TRANSLUCENT;
6490 }
John Spurlockbd957402013-10-03 11:38:39 -04006491 vis = (vis & ~flags) | (oldVis & flags);
John Spurlockad3e6cb2013-04-30 08:47:43 -04006492 }
John Spurlockad3e6cb2013-04-30 08:47:43 -04006493
Adrian Roos4fb3ee32014-08-22 19:29:09 +02006494 if (!areTranslucentBarsAllowed() && transWin != mStatusBar) {
Adrian Roosea562512014-05-05 13:33:03 +02006495 vis &= ~(View.NAVIGATION_BAR_TRANSLUCENT | View.STATUS_BAR_TRANSLUCENT
6496 | View.SYSTEM_UI_TRANSPARENT);
Alan Viverette5a0f4ec2013-10-07 15:10:29 -07006497 }
6498
John Spurlock27735a42013-08-14 17:57:38 -04006499 // update status bar
John Spurlockf1a36642013-10-12 17:50:42 -04006500 boolean immersiveSticky =
6501 (vis & View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY) != 0;
John Spurlock27735a42013-08-14 17:57:38 -04006502 boolean hideStatusBarWM =
John Spurlockbd957402013-10-03 11:38:39 -04006503 mTopFullscreenOpaqueWindowState != null &&
John Spurlockc6d1c602014-01-17 15:22:06 -05006504 (PolicyControl.getWindowFlags(mTopFullscreenOpaqueWindowState, null)
John Spurlock27735a42013-08-14 17:57:38 -04006505 & WindowManager.LayoutParams.FLAG_FULLSCREEN) != 0;
6506 boolean hideStatusBarSysui =
6507 (vis & View.SYSTEM_UI_FLAG_FULLSCREEN) != 0;
John Spurlockf1a36642013-10-12 17:50:42 -04006508 boolean hideNavBarSysui =
6509 (vis & View.SYSTEM_UI_FLAG_HIDE_NAVIGATION) != 0;
John Spurlockad3e6cb2013-04-30 08:47:43 -04006510
John Spurlock27735a42013-08-14 17:57:38 -04006511 boolean transientStatusBarAllowed =
6512 mStatusBar != null && (
6513 hideStatusBarWM
John Spurlockf1a36642013-10-12 17:50:42 -04006514 || (hideStatusBarSysui && immersiveSticky)
John Spurlock27735a42013-08-14 17:57:38 -04006515 || statusBarHasFocus);
6516
John Spurlockf1a36642013-10-12 17:50:42 -04006517 boolean transientNavBarAllowed =
6518 mNavigationBar != null &&
6519 hideNavBarSysui && immersiveSticky;
6520
Adrian Roosddc8b272015-05-21 16:28:27 -07006521 final long now = SystemClock.uptimeMillis();
6522 final boolean pendingPanic = mPendingPanicGestureUptime != 0
6523 && now - mPendingPanicGestureUptime <= PANIC_GESTURE_EXPIRATION;
6524 if (pendingPanic && hideNavBarSysui && !isStatusBarKeyguard() && mKeyguardDrawComplete) {
6525 // The user performed the panic gesture recently, we're about to hide the bars,
6526 // we're no longer on the Keyguard and the screen is ready. We can now request the bars.
6527 mPendingPanicGestureUptime = 0;
6528 mStatusBarController.showTransient();
6529 mNavigationBarController.showTransient();
6530 }
6531
John Spurlockf25706f2013-11-07 18:02:43 -05006532 boolean denyTransientStatus = mStatusBarController.isTransientShowRequested()
John Spurlockf1a36642013-10-12 17:50:42 -04006533 && !transientStatusBarAllowed && hideStatusBarSysui;
John Spurlockf25706f2013-11-07 18:02:43 -05006534 boolean denyTransientNav = mNavigationBarController.isTransientShowRequested()
John Spurlockf1a36642013-10-12 17:50:42 -04006535 && !transientNavBarAllowed;
6536 if (denyTransientStatus || denyTransientNav) {
John Spurlock27735a42013-08-14 17:57:38 -04006537 // clear the clearable flags instead
John Spurlockf1a36642013-10-12 17:50:42 -04006538 clearClearableFlagsLw();
tiger_huangc58d7562014-10-23 20:24:19 +08006539 vis &= ~View.SYSTEM_UI_CLEARABLE_FLAGS;
John Spurlockad3e6cb2013-04-30 08:47:43 -04006540 }
John Spurlock27735a42013-08-14 17:57:38 -04006541
Selim Cinekf98702e2015-05-20 22:48:40 -07006542 final boolean immersive = (vis & View.SYSTEM_UI_FLAG_IMMERSIVE) != 0;
6543 immersiveSticky = (vis & View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY) != 0;
6544 final boolean navAllowedHidden = immersive || immersiveSticky;
6545
Selim Cinekd6623612015-05-22 18:56:22 -07006546 if (hideNavBarSysui && !navAllowedHidden && windowTypeToLayerLw(win.getBaseType())
6547 > windowTypeToLayerLw(TYPE_INPUT_CONSUMER)) {
Selim Cinekf98702e2015-05-20 22:48:40 -07006548 // We can't hide the navbar from this window otherwise the input consumer would not get
6549 // the input events.
6550 vis = (vis & ~View.SYSTEM_UI_FLAG_HIDE_NAVIGATION);
6551 }
6552
John Spurlock27735a42013-08-14 17:57:38 -04006553 vis = mStatusBarController.updateVisibilityLw(transientStatusBarAllowed, oldVis, vis);
6554
6555 // update navigation bar
John Spurlockf1a36642013-10-12 17:50:42 -04006556 boolean oldImmersiveMode = isImmersiveMode(oldVis);
6557 boolean newImmersiveMode = isImmersiveMode(vis);
6558 if (win != null && oldImmersiveMode != newImmersiveMode) {
John Spurlock79da8332013-09-20 12:04:47 -04006559 final String pkg = win.getOwningPackage();
Maurice Lam99c6e072014-04-28 18:24:28 -07006560 mImmersiveModeConfirmation.immersiveModeChanged(pkg, newImmersiveMode,
6561 isUserSetupComplete());
John Spurlock34e13d92013-08-10 06:52:28 -04006562 }
John Spurlock27735a42013-08-14 17:57:38 -04006563
John Spurlockf1a36642013-10-12 17:50:42 -04006564 vis = mNavigationBarController.updateVisibilityLw(transientNavBarAllowed, oldVis, vis);
6565
John Spurlocke1f366f2013-08-05 12:22:40 -04006566 return vis;
John Spurlockad3e6cb2013-04-30 08:47:43 -04006567 }
6568
John Spurlockf1a36642013-10-12 17:50:42 -04006569 private void clearClearableFlagsLw() {
6570 int newVal = mResettingSystemUiFlags | View.SYSTEM_UI_CLEARABLE_FLAGS;
6571 if (newVal != mResettingSystemUiFlags) {
6572 mResettingSystemUiFlags = newVal;
6573 mWindowManagerFuncs.reevaluateStatusBarVisibility();
6574 }
6575 }
6576
6577 private boolean isImmersiveMode(int vis) {
6578 final int flags = View.SYSTEM_UI_FLAG_IMMERSIVE | View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY;
John Spurlock34e13d92013-08-10 06:52:28 -04006579 return mNavigationBar != null
6580 && (vis & View.SYSTEM_UI_FLAG_HIDE_NAVIGATION) != 0
Daniel Sandler900ece52013-10-18 15:53:27 -04006581 && (vis & flags) != 0
6582 && canHideNavigationBar();
John Spurlock34e13d92013-08-10 06:52:28 -04006583 }
6584
Alan Viverette5a0f4ec2013-10-07 15:10:29 -07006585 /**
Daniel Sandlerdd73ee42013-10-11 22:19:59 -04006586 * @return whether the navigation or status bar can be made translucent
6587 *
6588 * This should return true unless touch exploration is not enabled or
6589 * R.boolean.config_enableTranslucentDecor is false.
Alan Viverette5a0f4ec2013-10-07 15:10:29 -07006590 */
Daniel Sandlerdd73ee42013-10-11 22:19:59 -04006591 private boolean areTranslucentBarsAllowed() {
Svetoslav8e3feb12014-02-24 13:46:47 -08006592 return mTranslucentDecorEnabled
6593 && !mAccessibilityManager.isTouchExplorationEnabled();
Alan Viverette5a0f4ec2013-10-07 15:10:29 -07006594 }
6595
Daniel Sandler0c4ccff2011-10-19 16:39:14 -04006596 // Use this instead of checking config_showNavigationBar so that it can be consistently
6597 // overridden by qemu.hw.mainkeys in the emulator.
Craig Mautnereda67292013-04-28 13:50:14 -07006598 @Override
Daniel Sandler0c4ccff2011-10-19 16:39:14 -04006599 public boolean hasNavigationBar() {
6600 return mHasNavigationBar;
6601 }
6602
satok1bc0a492012-04-25 22:47:12 +09006603 @Override
6604 public void setLastInputMethodWindowLw(WindowState ime, WindowState target) {
6605 mLastInputMethodWindow = ime;
6606 mLastInputMethodTargetWindow = target;
6607 }
6608
Craig Mautnerf1b67412012-09-19 13:18:29 -07006609 @Override
Satoshi Kataoka658c7b82013-10-10 17:03:51 +09006610 public int getInputMethodWindowVisibleHeightLw() {
6611 return mDockBottom - mCurBottom;
6612 }
6613
6614 @Override
Craig Mautnerf1b67412012-09-19 13:18:29 -07006615 public void setCurrentUserLw(int newUserId) {
Craig Mautnerd625ab22013-09-06 13:40:31 -07006616 mCurrentUserId = newUserId;
Jim Miller5ecd8112013-01-09 18:50:26 -08006617 if (mKeyguardDelegate != null) {
6618 mKeyguardDelegate.setCurrentUser(newUserId);
Craig Mautnerf1b67412012-09-19 13:18:29 -07006619 }
John Spurlock13451a22012-09-28 14:40:41 -04006620 if (mStatusBarService != null) {
6621 try {
6622 mStatusBarService.setCurrentUser(newUserId);
6623 } catch (RemoteException e) {
6624 // oh well
6625 }
6626 }
Dianne Hackborn2ea9bae2012-11-02 18:43:48 -07006627 setLastInputMethodWindowLw(null, null);
Craig Mautnerf1b67412012-09-19 13:18:29 -07006628 }
6629
6630 @Override
Svetoslav Ganov545252f2012-12-10 18:29:24 -08006631 public boolean canMagnifyWindow(int windowType) {
6632 switch (windowType) {
6633 case WindowManager.LayoutParams.TYPE_INPUT_METHOD:
6634 case WindowManager.LayoutParams.TYPE_INPUT_METHOD_DIALOG:
6635 case WindowManager.LayoutParams.TYPE_NAVIGATION_BAR:
6636 case WindowManager.LayoutParams.TYPE_MAGNIFICATION_OVERLAY: {
6637 return false;
6638 }
6639 }
6640 return true;
6641 }
6642
6643 @Override
6644 public boolean isTopLevelWindow(int windowType) {
6645 if (windowType >= WindowManager.LayoutParams.FIRST_SUB_WINDOW
6646 && windowType <= WindowManager.LayoutParams.LAST_SUB_WINDOW) {
6647 return (windowType == WindowManager.LayoutParams.TYPE_APPLICATION_ATTACHED_DIALOG);
6648 }
6649 return true;
6650 }
6651
Jim Miller4eeb4f62012-11-08 00:04:29 -08006652 @Override
Jeff Brownd7a04de2012-06-17 14:17:52 -07006653 public void dump(String prefix, PrintWriter pw, String[] args) {
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08006654 pw.print(prefix); pw.print("mSafeMode="); pw.print(mSafeMode);
Dianne Hackbornba24e4d2011-09-01 11:17:06 -07006655 pw.print(" mSystemReady="); pw.print(mSystemReady);
6656 pw.print(" mSystemBooted="); pw.println(mSystemBooted);
Jeff Brown2e7760e2012-04-11 15:14:55 -07006657 pw.print(prefix); pw.print("mLidState="); pw.print(mLidState);
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08006658 pw.print(" mLidOpenRotation="); pw.print(mLidOpenRotation);
Michael Wright3818c922014-09-02 13:59:07 -07006659 pw.print(" mCameraLensCoverState="); pw.print(mCameraLensCoverState);
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08006660 pw.print(" mHdmiPlugged="); pw.println(mHdmiPlugged);
Dianne Hackborne26ab702011-10-16 13:21:33 -07006661 if (mLastSystemUiFlags != 0 || mResettingSystemUiFlags != 0
6662 || mForceClearedSystemUiFlags != 0) {
6663 pw.print(prefix); pw.print("mLastSystemUiFlags=0x");
6664 pw.print(Integer.toHexString(mLastSystemUiFlags));
6665 pw.print(" mResettingSystemUiFlags=0x");
6666 pw.print(Integer.toHexString(mResettingSystemUiFlags));
6667 pw.print(" mForceClearedSystemUiFlags=0x");
6668 pw.println(Integer.toHexString(mForceClearedSystemUiFlags));
Dianne Hackborndf89e652011-10-06 22:35:11 -07006669 }
Dianne Hackborn4eff8d32011-11-10 19:38:40 -08006670 if (mLastFocusNeedsMenu) {
6671 pw.print(prefix); pw.print("mLastFocusNeedsMenu=");
6672 pw.println(mLastFocusNeedsMenu);
6673 }
Jeff Browna20dda42014-05-27 20:57:24 -07006674 pw.print(prefix); pw.print("mWakeGestureEnabledSetting=");
6675 pw.println(mWakeGestureEnabledSetting);
6676
Jeff Brownbcdfc622014-03-06 19:13:04 -08006677 pw.print(prefix); pw.print("mSupportAutoRotation="); pw.println(mSupportAutoRotation);
Daniel Sandler6396c722013-04-16 20:19:09 -04006678 pw.print(prefix); pw.print("mUiMode="); pw.print(mUiMode);
6679 pw.print(" mDockMode="); pw.print(mDockMode);
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08006680 pw.print(" mCarDockRotation="); pw.print(mCarDockRotation);
6681 pw.print(" mDeskDockRotation="); pw.println(mDeskDockRotation);
6682 pw.print(prefix); pw.print("mUserRotationMode="); pw.print(mUserRotationMode);
6683 pw.print(" mUserRotation="); pw.print(mUserRotation);
Daniel Sandler2ed6ad62011-02-22 14:54:17 -05006684 pw.print(" mAllowAllRotations="); pw.println(mAllowAllRotations);
Dianne Hackborn6e2281d2012-06-19 17:48:32 -07006685 pw.print(prefix); pw.print("mCurrentAppOrientation="); pw.println(mCurrentAppOrientation);
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08006686 pw.print(prefix); pw.print("mCarDockEnablesAccelerometer=");
6687 pw.print(mCarDockEnablesAccelerometer);
6688 pw.print(" mDeskDockEnablesAccelerometer=");
6689 pw.println(mDeskDockEnablesAccelerometer);
6690 pw.print(prefix); pw.print("mLidKeyboardAccessibility=");
6691 pw.print(mLidKeyboardAccessibility);
6692 pw.print(" mLidNavigationAccessibility="); pw.print(mLidNavigationAccessibility);
Dianne Hackborn6e2281d2012-06-19 17:48:32 -07006693 pw.print(" mLidControlsSleep="); pw.println(mLidControlsSleep);
Jeff Brown6d8fd272014-05-20 21:24:38 -07006694 pw.print(prefix);
6695 pw.print("mShortPressOnPowerBehavior="); pw.print(mShortPressOnPowerBehavior);
6696 pw.print(" mLongPressOnPowerBehavior="); pw.println(mLongPressOnPowerBehavior);
Jeff Brown13f00f02014-10-31 14:45:50 -07006697 pw.print(prefix);
6698 pw.print("mDoublePressOnPowerBehavior="); pw.print(mDoublePressOnPowerBehavior);
6699 pw.print(" mTriplePressOnPowerBehavior="); pw.println(mTriplePressOnPowerBehavior);
Jeff Brown6d8fd272014-05-20 21:24:38 -07006700 pw.print(prefix); pw.print("mHasSoftInput="); pw.println(mHasSoftInput);
Jeff Brown3ee549c2014-09-22 20:14:39 -07006701 pw.print(prefix); pw.print("mAwake="); pw.println(mAwake);
6702 pw.print(prefix); pw.print("mScreenOnEarly="); pw.print(mScreenOnEarly);
6703 pw.print(" mScreenOnFully="); pw.println(mScreenOnFully);
6704 pw.print(prefix); pw.print("mKeyguardDrawComplete="); pw.print(mKeyguardDrawComplete);
6705 pw.print(" mWindowManagerDrawComplete="); pw.println(mWindowManagerDrawComplete);
6706 pw.print(prefix); pw.print("mOrientationSensorEnabled=");
6707 pw.println(mOrientationSensorEnabled);
Dianne Hackbornc652de82013-02-15 16:32:56 -08006708 pw.print(prefix); pw.print("mOverscanScreen=("); pw.print(mOverscanScreenLeft);
6709 pw.print(","); pw.print(mOverscanScreenTop);
6710 pw.print(") "); pw.print(mOverscanScreenWidth);
6711 pw.print("x"); pw.println(mOverscanScreenHeight);
6712 if (mOverscanLeft != 0 || mOverscanTop != 0
6713 || mOverscanRight != 0 || mOverscanBottom != 0) {
6714 pw.print(prefix); pw.print("mOverscan left="); pw.print(mOverscanLeft);
6715 pw.print(" top="); pw.print(mOverscanTop);
6716 pw.print(" right="); pw.print(mOverscanRight);
6717 pw.print(" bottom="); pw.println(mOverscanBottom);
6718 }
Dianne Hackborn313440842013-02-19 19:22:59 -08006719 pw.print(prefix); pw.print("mRestrictedOverscanScreen=(");
6720 pw.print(mRestrictedOverscanScreenLeft);
6721 pw.print(","); pw.print(mRestrictedOverscanScreenTop);
6722 pw.print(") "); pw.print(mRestrictedOverscanScreenWidth);
6723 pw.print("x"); pw.println(mRestrictedOverscanScreenHeight);
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08006724 pw.print(prefix); pw.print("mUnrestrictedScreen=("); pw.print(mUnrestrictedScreenLeft);
6725 pw.print(","); pw.print(mUnrestrictedScreenTop);
6726 pw.print(") "); pw.print(mUnrestrictedScreenWidth);
6727 pw.print("x"); pw.println(mUnrestrictedScreenHeight);
6728 pw.print(prefix); pw.print("mRestrictedScreen=("); pw.print(mRestrictedScreenLeft);
6729 pw.print(","); pw.print(mRestrictedScreenTop);
6730 pw.print(") "); pw.print(mRestrictedScreenWidth);
6731 pw.print("x"); pw.println(mRestrictedScreenHeight);
Dianne Hackborn5b5cc4d2012-05-16 13:15:00 -07006732 pw.print(prefix); pw.print("mStableFullscreen=("); pw.print(mStableFullscreenLeft);
6733 pw.print(","); pw.print(mStableFullscreenTop);
6734 pw.print(")-("); pw.print(mStableFullscreenRight);
6735 pw.print(","); pw.print(mStableFullscreenBottom); pw.println(")");
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07006736 pw.print(prefix); pw.print("mStable=("); pw.print(mStableLeft);
6737 pw.print(","); pw.print(mStableTop);
6738 pw.print(")-("); pw.print(mStableRight);
6739 pw.print(","); pw.print(mStableBottom); pw.println(")");
Dianne Hackborn5c58de32012-04-28 19:52:37 -07006740 pw.print(prefix); pw.print("mSystem=("); pw.print(mSystemLeft);
6741 pw.print(","); pw.print(mSystemTop);
6742 pw.print(")-("); pw.print(mSystemRight);
6743 pw.print(","); pw.print(mSystemBottom); pw.println(")");
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08006744 pw.print(prefix); pw.print("mCur=("); pw.print(mCurLeft);
6745 pw.print(","); pw.print(mCurTop);
6746 pw.print(")-("); pw.print(mCurRight);
6747 pw.print(","); pw.print(mCurBottom); pw.println(")");
6748 pw.print(prefix); pw.print("mContent=("); pw.print(mContentLeft);
6749 pw.print(","); pw.print(mContentTop);
6750 pw.print(")-("); pw.print(mContentRight);
6751 pw.print(","); pw.print(mContentBottom); pw.println(")");
Dianne Hackborne30e02f2014-05-27 18:24:45 -07006752 pw.print(prefix); pw.print("mVoiceContent=("); pw.print(mVoiceContentLeft);
6753 pw.print(","); pw.print(mVoiceContentTop);
6754 pw.print(")-("); pw.print(mVoiceContentRight);
6755 pw.print(","); pw.print(mVoiceContentBottom); pw.println(")");
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08006756 pw.print(prefix); pw.print("mDock=("); pw.print(mDockLeft);
6757 pw.print(","); pw.print(mDockTop);
6758 pw.print(")-("); pw.print(mDockRight);
6759 pw.print(","); pw.print(mDockBottom); pw.println(")");
Dianne Hackborn5c58de32012-04-28 19:52:37 -07006760 pw.print(prefix); pw.print("mDockLayer="); pw.print(mDockLayer);
6761 pw.print(" mStatusBarLayer="); pw.println(mStatusBarLayer);
Dianne Hackborn7ad44382012-10-18 17:46:00 -07006762 pw.print(prefix); pw.print("mShowingLockscreen="); pw.print(mShowingLockscreen);
6763 pw.print(" mShowingDream="); pw.print(mShowingDream);
Jeff Brown061ea992015-04-17 19:55:47 -07006764 pw.print(" mDreamingLockscreen="); pw.print(mDreamingLockscreen);
6765 pw.print(" mDreamingSleepToken="); pw.println(mDreamingSleepToken);
Dianne Hackborn2ea9bae2012-11-02 18:43:48 -07006766 if (mLastInputMethodWindow != null) {
6767 pw.print(prefix); pw.print("mLastInputMethodWindow=");
6768 pw.println(mLastInputMethodWindow);
6769 }
6770 if (mLastInputMethodTargetWindow != null) {
6771 pw.print(prefix); pw.print("mLastInputMethodTargetWindow=");
6772 pw.println(mLastInputMethodTargetWindow);
6773 }
6774 if (mStatusBar != null) {
6775 pw.print(prefix); pw.print("mStatusBar=");
Dianne Hackbornae6688b2015-02-11 17:02:41 -08006776 pw.print(mStatusBar); pw.print(" isStatusBarKeyguard=");
6777 pw.println(isStatusBarKeyguard());
Dianne Hackborn2ea9bae2012-11-02 18:43:48 -07006778 }
6779 if (mNavigationBar != null) {
6780 pw.print(prefix); pw.print("mNavigationBar=");
6781 pw.println(mNavigationBar);
6782 }
Dianne Hackborn2ea9bae2012-11-02 18:43:48 -07006783 if (mFocusedWindow != null) {
6784 pw.print(prefix); pw.print("mFocusedWindow=");
6785 pw.println(mFocusedWindow);
6786 }
6787 if (mFocusedApp != null) {
6788 pw.print(prefix); pw.print("mFocusedApp=");
6789 pw.println(mFocusedApp);
6790 }
6791 if (mWinDismissingKeyguard != null) {
6792 pw.print(prefix); pw.print("mWinDismissingKeyguard=");
6793 pw.println(mWinDismissingKeyguard);
6794 }
6795 if (mTopFullscreenOpaqueWindowState != null) {
6796 pw.print(prefix); pw.print("mTopFullscreenOpaqueWindowState=");
6797 pw.println(mTopFullscreenOpaqueWindowState);
6798 }
Adrian Rooscd3884d2015-02-18 17:25:23 +01006799 if (mTopFullscreenOpaqueOrDimmingWindowState != null) {
6800 pw.print(prefix); pw.print("mTopFullscreenOpaqueOrDimmingWindowState=");
6801 pw.println(mTopFullscreenOpaqueOrDimmingWindowState);
6802 }
Dianne Hackborn891d3fb2013-01-09 18:31:37 -08006803 if (mForcingShowNavBar) {
6804 pw.print(prefix); pw.print("mForcingShowNavBar=");
6805 pw.println(mForcingShowNavBar); pw.print( "mForcingShowNavBarLayer=");
6806 pw.println(mForcingShowNavBarLayer);
6807 }
Dianne Hackborn7ad44382012-10-18 17:46:00 -07006808 pw.print(prefix); pw.print("mTopIsFullscreen="); pw.print(mTopIsFullscreen);
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08006809 pw.print(" mHideLockScreen="); pw.println(mHideLockScreen);
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07006810 pw.print(prefix); pw.print("mForceStatusBar="); pw.print(mForceStatusBar);
6811 pw.print(" mForceStatusBarFromKeyguard=");
6812 pw.println(mForceStatusBarFromKeyguard);
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08006813 pw.print(prefix); pw.print("mDismissKeyguard="); pw.print(mDismissKeyguard);
Craig Mautnerad09bcc2012-10-08 13:33:11 -07006814 pw.print(" mWinDismissingKeyguard="); pw.print(mWinDismissingKeyguard);
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08006815 pw.print(" mHomePressed="); pw.println(mHomePressed);
6816 pw.print(prefix); pw.print("mAllowLockscreenWhenOn="); pw.print(mAllowLockscreenWhenOn);
6817 pw.print(" mLockScreenTimeout="); pw.print(mLockScreenTimeout);
6818 pw.print(" mLockScreenTimerActive="); pw.println(mLockScreenTimerActive);
6819 pw.print(prefix); pw.print("mEndcallBehavior="); pw.print(mEndcallBehavior);
6820 pw.print(" mIncallPowerBehavior="); pw.print(mIncallPowerBehavior);
6821 pw.print(" mLongPressOnHomeBehavior="); pw.println(mLongPressOnHomeBehavior);
6822 pw.print(prefix); pw.print("mLandscapeRotation="); pw.print(mLandscapeRotation);
6823 pw.print(" mSeascapeRotation="); pw.println(mSeascapeRotation);
6824 pw.print(prefix); pw.print("mPortraitRotation="); pw.print(mPortraitRotation);
6825 pw.print(" mUpsideDownRotation="); pw.println(mUpsideDownRotation);
Jeff Brownc82c89ed2013-04-17 17:18:15 -07006826 pw.print(prefix); pw.print("mDemoHdmiRotation="); pw.print(mDemoHdmiRotation);
6827 pw.print(" mDemoHdmiRotationLock="); pw.println(mDemoHdmiRotationLock);
6828 pw.print(prefix); pw.print("mUndockedHdmiRotation="); pw.println(mUndockedHdmiRotation);
Jeff Brown600f0032014-05-22 17:06:00 -07006829
Tim Kilbournd7c0c2e2014-05-29 16:08:10 -07006830 mGlobalKeyManager.dump(prefix, pw);
John Spurlock27735a42013-08-14 17:57:38 -04006831 mStatusBarController.dump(pw, prefix);
6832 mNavigationBarController.dump(pw, prefix);
John Spurlockc6d1c602014-01-17 15:22:06 -05006833 PolicyControl.dump(prefix, pw);
Jeff Brown600f0032014-05-22 17:06:00 -07006834
Jeff Browna20dda42014-05-27 20:57:24 -07006835 if (mWakeGestureListener != null) {
6836 mWakeGestureListener.dump(pw, prefix);
6837 }
Jeff Brown600f0032014-05-22 17:06:00 -07006838 if (mOrientationListener != null) {
6839 mOrientationListener.dump(pw, prefix);
6840 }
Filip Gruszczynskicfb31852015-02-25 21:47:12 +00006841 if (mBurnInProtectionHelper != null) {
6842 mBurnInProtectionHelper.dump(prefix, pw);
6843 }
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08006844 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006845}