blob: bfe68b34066e63713592777e979c1625bb3138ca [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;
Jinsuk Kime601b712015-07-07 08:01:02 +090047import android.hardware.hdmi.HdmiControlManager;
48import android.hardware.hdmi.HdmiPlaybackClient;
49import android.hardware.hdmi.HdmiPlaybackClient.OneTouchPlayCallback;
John Spurlock7b414672014-07-18 13:02:39 -040050import android.media.AudioAttributes;
Michael Jurka7a348952012-02-27 13:07:58 -080051import android.media.AudioManager;
John Spurlock61560172015-02-06 19:46:04 -050052import android.media.AudioSystem;
Michael Jurka7a348952012-02-27 13:07:58 -080053import android.media.IAudioService;
Svetoslav Ganov7befb7d2012-09-27 16:49:23 -070054import android.media.Ringtone;
55import android.media.RingtoneManager;
RoboErik8a2cfc32014-05-16 11:19:38 -070056import android.media.session.MediaSessionLegacyHelper;
Billy Laucbe540f2015-06-25 01:51:44 +010057import android.os.Binder;
Dianne Hackborn38e29a62011-09-18 14:43:08 -070058import android.os.Bundle;
Craig Mautner276a6eb2014-11-04 15:32:57 -080059import android.os.Debug;
Jeff Brown9a538ee2012-08-20 14:56:57 -070060import android.os.FactoryTest;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -080061import android.os.Handler;
62import android.os.IBinder;
Dianne Hackbornb6683c42015-06-18 17:40:33 -070063import android.os.IDeviceIdleController;
Jeff Brown32cbc38552011-12-01 14:01:49 -080064import android.os.Looper;
Dianne Hackbornfc8fa632011-08-17 16:20:47 -070065import android.os.Message;
66import android.os.Messenger;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -080067import android.os.PowerManager;
Nick Armstrong-Crews56ecfcc2015-09-07 21:46:50 -070068import android.os.PowerManagerInternal;
Billy Laucbe540f2015-06-25 01:51:44 +010069import android.os.Process;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -080070import android.os.RemoteException;
71import android.os.ServiceManager;
72import android.os.SystemClock;
73import android.os.SystemProperties;
Dianne Hackbornad7fa7f2011-01-07 14:06:50 -080074import android.os.UEventObserver;
Dianne Hackbornf02b60a2012-08-16 10:48:27 -070075import android.os.UserHandle;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -080076import android.os.Vibrator;
Michael Wright3818c922014-09-02 13:59:07 -070077import android.provider.MediaStore;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -080078import android.provider.Settings;
Jose Lima9546b202014-07-02 17:21:51 -070079import android.service.dreams.DreamManagerInternal;
John Spurlockc8b46ca2013-04-08 12:59:26 -040080import android.service.dreams.DreamService;
81import android.service.dreams.IDreamManager;
Michael Wrightdc63f7b2014-08-21 19:05:21 -070082import android.speech.RecognizerIntent;
Tyler Gunnef9f6f92014-09-12 22:16:17 -070083import android.telecom.TelecomManager;
Dianne Hackborn81e56d52011-05-26 00:55:58 -070084import android.util.DisplayMetrics;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -080085import android.util.EventLog;
86import android.util.Log;
Jeff Browna41ca772010-08-11 14:46:32 -070087import android.util.Slog;
Jeff Brown6651a632011-11-28 12:59:11 -080088import android.util.SparseArray;
Dianne Hackbornf87d1962012-04-04 12:48:24 -070089import android.view.Display;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -080090import android.view.Gravity;
91import android.view.HapticFeedbackConstants;
Dianne Hackborne0f085d2011-11-30 18:41:15 -080092import android.view.IApplicationToken;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -080093import android.view.IWindowManager;
Jeff Browna41ca772010-08-11 14:46:32 -070094import android.view.InputChannel;
Jeff Brown4d396052010-10-29 21:50:21 -070095import android.view.InputDevice;
Jeff Brown4952dfd2011-11-30 19:23:22 -080096import android.view.InputEvent;
Jeff Brown32cbc38552011-12-01 14:01:49 -080097import android.view.InputEventReceiver;
Jeff Brown6b53e8d2010-11-10 16:03:06 -080098import android.view.KeyCharacterMap;
Craig Mautnerae446592012-12-06 19:05:05 -080099import android.view.KeyCharacterMap.FallbackAction;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800100import android.view.KeyEvent;
101import android.view.MotionEvent;
Chris Wren9bb290b2015-06-29 12:02:13 -0400102
103import com.android.internal.logging.MetricsLogger;
Adam Powell6711f3b2015-05-06 15:57:09 -0700104import com.android.internal.policy.PhoneWindow;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800105import android.view.Surface;
106import android.view.View;
107import android.view.ViewConfiguration;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800108import android.view.WindowManager;
Craig Mautnerae446592012-12-06 19:05:05 -0800109import android.view.WindowManagerGlobal;
Craig Mautner8a0da012014-05-31 15:13:37 -0700110import android.view.WindowManagerInternal;
Craig Mautnerae446592012-12-06 19:05:05 -0800111import android.view.WindowManagerPolicy;
Craig Mautnerae446592012-12-06 19:05:05 -0800112import android.view.accessibility.AccessibilityEvent;
Svetoslav8e3feb12014-02-24 13:46:47 -0800113import android.view.accessibility.AccessibilityManager;
Craig Mautnerae446592012-12-06 19:05:05 -0800114import android.view.animation.Animation;
Jorim Jaggi76a16232014-08-08 17:00:47 +0200115import android.view.animation.AnimationSet;
Craig Mautnerae446592012-12-06 19:05:05 -0800116import android.view.animation.AnimationUtils;
Craig Mautnerae446592012-12-06 19:05:05 -0800117import com.android.internal.R;
Craig Mautnerae446592012-12-06 19:05:05 -0800118import com.android.internal.statusbar.IStatusBarService;
Filip Gruszczynski2217f612015-05-26 11:32:08 -0700119import com.android.internal.util.ScreenShapeHelper;
Craig Mautnerae446592012-12-06 19:05:05 -0800120import com.android.internal.widget.PointerLocationView;
Adrian Roos5941c982015-09-03 15:59:49 -0700121import com.android.server.GestureLauncherService;
Craig Mautner8a0da012014-05-31 15:13:37 -0700122import com.android.server.LocalServices;
Jorim Jaggib10e33f2015-02-04 21:57:40 +0100123import com.android.server.policy.keyguard.KeyguardServiceDelegate;
Jorim Jaggi740452e2015-07-09 12:13:59 -0700124import com.android.server.policy.keyguard.KeyguardServiceDelegate.DrawnListener;
Craig Mautnerae446592012-12-06 19:05:05 -0800125
126import java.io.File;
127import java.io.FileReader;
128import java.io.IOException;
129import java.io.PrintWriter;
Craig Mautner2bc789b2014-03-19 19:48:38 -0700130import java.util.HashSet;
Craig Mautner276a6eb2014-11-04 15:32:57 -0800131import java.util.List;
Craig Mautnerae446592012-12-06 19:05:05 -0800132
Dianne Hackbornc652de82013-02-15 16:32:56 -0800133import static android.view.WindowManager.LayoutParams.*;
Jeff Brownac143512012-04-05 18:57:33 -0700134import static android.view.WindowManagerPolicy.WindowManagerFuncs.LID_ABSENT;
135import static android.view.WindowManagerPolicy.WindowManagerFuncs.LID_OPEN;
136import static android.view.WindowManagerPolicy.WindowManagerFuncs.LID_CLOSED;
Michael Wright3818c922014-09-02 13:59:07 -0700137import static android.view.WindowManagerPolicy.WindowManagerFuncs.CAMERA_LENS_COVER_ABSENT;
138import static android.view.WindowManagerPolicy.WindowManagerFuncs.CAMERA_LENS_UNCOVERED;
139import static android.view.WindowManagerPolicy.WindowManagerFuncs.CAMERA_LENS_COVERED;
Dianne Hackborn08743722009-12-21 12:16:51 -0800140
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800141/**
The Android Open Source Project0727d222009-03-11 12:11:58 -0700142 * WindowManagerPolicy implementation for the Android phone UI. This
143 * introduces a new method suffix, Lp, for an internal lock of the
144 * PhoneWindowManager. This is used to protect some internal state, and
John Spurlock04db1762013-05-13 12:46:41 -0400145 * can be acquired with either the Lw and Li lock held, so has the restrictions
The Android Open Source Project0727d222009-03-11 12:11:58 -0700146 * of both of those when held.
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800147 */
148public class PhoneWindowManager implements WindowManagerPolicy {
149 static final String TAG = "WindowManager";
150 static final boolean DEBUG = false;
Joe Onorato43a17652011-04-06 19:22:23 -0700151 static final boolean localLOGV = false;
Jeff Brown40013652012-05-16 21:22:36 -0700152 static final boolean DEBUG_INPUT = false;
Craig Mautnerc0d2d0a2014-10-31 16:25:15 -0700153 static final boolean DEBUG_KEYGUARD = false;
154 static final boolean DEBUG_LAYOUT = false;
Craig Mautner6fbda632012-07-03 09:26:39 -0700155 static final boolean DEBUG_STARTING_WINDOW = false;
Craig Mautner8a0da012014-05-31 15:13:37 -0700156 static final boolean DEBUG_WAKEUP = false;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800157 static final boolean SHOW_STARTING_ANIMATIONS = true;
158 static final boolean SHOW_PROCESSES_ON_ALT_MENU = false;
Joe Onoratod208e702010-10-08 16:22:43 -0400159
Daniel Sandler6396c722013-04-16 20:19:09 -0400160 // Whether to allow dock apps with METADATA_DOCK_HOME to temporarily take over the Home key.
161 // No longer recommended for desk docks; still useful in car docks.
162 static final boolean ENABLE_CAR_DOCK_HOME_CAPTURE = true;
163 static final boolean ENABLE_DESK_DOCK_HOME_CAPTURE = false;
164
Jeff Brown6d8fd272014-05-20 21:24:38 -0700165 static final int SHORT_PRESS_POWER_NOTHING = 0;
166 static final int SHORT_PRESS_POWER_GO_TO_SLEEP = 1;
167 static final int SHORT_PRESS_POWER_REALLY_GO_TO_SLEEP = 2;
168 static final int SHORT_PRESS_POWER_REALLY_GO_TO_SLEEP_AND_GO_HOME = 3;
Bryce Lee01b0c5f2015-02-05 18:24:04 -0800169 static final int SHORT_PRESS_POWER_GO_HOME = 4;
Jeff Brown6d8fd272014-05-20 21:24:38 -0700170
Joe Onoratod208e702010-10-08 16:22:43 -0400171 static final int LONG_PRESS_POWER_NOTHING = 0;
172 static final int LONG_PRESS_POWER_GLOBAL_ACTIONS = 1;
173 static final int LONG_PRESS_POWER_SHUT_OFF = 2;
Jeff Brown9a538ee2012-08-20 14:56:57 -0700174 static final int LONG_PRESS_POWER_SHUT_OFF_NO_CONFIRM = 3;
Michael Jurka3b1fc472011-06-13 10:54:40 -0700175
Jeff Brown13f00f02014-10-31 14:45:50 -0700176 static final int MULTI_PRESS_POWER_NOTHING = 0;
177 static final int MULTI_PRESS_POWER_THEATER_MODE = 1;
178 static final int MULTI_PRESS_POWER_BRIGHTNESS_BOOST = 2;
179
Michael Jurka3b1fc472011-06-13 10:54:40 -0700180 // These need to match the documentation/constant in
181 // core/res/res/values/config.xml
Joe Onorato46b0d682010-11-22 17:37:27 -0800182 static final int LONG_PRESS_HOME_NOTHING = 0;
Michael Wrightc9ebea72013-01-16 19:25:02 -0800183 static final int LONG_PRESS_HOME_RECENT_SYSTEM_UI = 1;
Jeff Browncaca8812013-05-09 13:34:33 -0700184 static final int LONG_PRESS_HOME_ASSIST = 2;
185
186 static final int DOUBLE_TAP_HOME_NOTHING = 0;
187 static final int DOUBLE_TAP_HOME_RECENT_SYSTEM_UI = 1;
Joe Onorato46b0d682010-11-22 17:37:27 -0800188
Filip Gruszczynskia483a1d2015-03-17 19:06:58 +0000189 static final int SHORT_PRESS_SLEEP_GO_TO_SLEEP = 0;
190 static final int SHORT_PRESS_SLEEP_GO_TO_SLEEP_AND_GO_HOME = 1;
191
Dianne Hackborn5cb8d792009-05-21 17:34:15 -0700192 static final int APPLICATION_MEDIA_SUBLAYER = -2;
193 static final int APPLICATION_MEDIA_OVERLAY_SUBLAYER = -1;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800194 static final int APPLICATION_PANEL_SUBLAYER = 1;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800195 static final int APPLICATION_SUB_PANEL_SUBLAYER = 2;
Wale Ogunwale0a4dc222015-04-14 12:58:42 -0700196 static final int APPLICATION_ABOVE_SUB_PANEL_SUBLAYER = 3;
Craig Mautner88400d32012-09-30 12:35:45 -0700197
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800198 static public final String SYSTEM_DIALOG_REASON_KEY = "reason";
199 static public final String SYSTEM_DIALOG_REASON_GLOBAL_ACTIONS = "globalactions";
200 static public final String SYSTEM_DIALOG_REASON_RECENT_APPS = "recentapps";
Joe Onoratof275f0c2009-11-24 16:11:13 -0500201 static public final String SYSTEM_DIALOG_REASON_HOME_KEY = "homekey";
Jeff Brownde7a8ea2012-06-13 18:28:57 -0700202 static public final String SYSTEM_DIALOG_REASON_ASSIST = "assist";
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800203
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -0700204 /**
205 * These are the system UI flags that, when changing, can cause the layout
206 * of the screen to change.
207 */
208 static final int SYSTEM_UI_CHANGING_LAYOUT =
John Spurlocke1f366f2013-08-05 12:22:40 -0400209 View.SYSTEM_UI_FLAG_HIDE_NAVIGATION
John Spurlock7f4820a2013-10-08 12:54:35 -0400210 | View.SYSTEM_UI_FLAG_FULLSCREEN
211 | View.STATUS_BAR_TRANSLUCENT
Adrian Roosea562512014-05-05 13:33:03 +0200212 | View.NAVIGATION_BAR_TRANSLUCENT
213 | View.SYSTEM_UI_TRANSPARENT;
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -0700214
John Spurlock7b414672014-07-18 13:02:39 -0400215 private static final AudioAttributes VIBRATION_ATTRIBUTES = new AudioAttributes.Builder()
216 .setContentType(AudioAttributes.CONTENT_TYPE_SONIFICATION)
217 .setUsage(AudioAttributes.USAGE_ASSISTANCE_SONIFICATION)
218 .build();
219
Adrian Roosddc8b272015-05-21 16:28:27 -0700220 // The panic gesture may become active only after the keyguard is dismissed and the immersive
221 // app shows again. If that doesn't happen for 30s we drop the gesture.
222 private static final long PANIC_GESTURE_EXPIRATION = 30000;
223
Jim Miller5ecd8112013-01-09 18:50:26 -0800224 /**
225 * Keyguard stuff
226 */
227 private WindowState mKeyguardScrim;
Jorim Jaggi380ecb82014-03-14 17:25:20 +0100228 private boolean mKeyguardHidden;
Jeff Brown3ee549c2014-09-22 20:14:39 -0700229 private boolean mKeyguardDrawnOnce;
Jim Miller5ecd8112013-01-09 18:50:26 -0800230
Jeff Brown6651a632011-11-28 12:59:11 -0800231 /* Table of Application Launch keys. Maps from key codes to intent categories.
232 *
233 * These are special keys that are used to launch particular kinds of applications,
234 * such as a web browser. HID defines nearly a hundred of them in the Consumer (0x0C)
235 * usage page. We don't support quite that many yet...
236 */
237 static SparseArray<String> sApplicationLaunchKeyCategories;
238 static {
239 sApplicationLaunchKeyCategories = new SparseArray<String>();
240 sApplicationLaunchKeyCategories.append(
241 KeyEvent.KEYCODE_EXPLORER, Intent.CATEGORY_APP_BROWSER);
242 sApplicationLaunchKeyCategories.append(
243 KeyEvent.KEYCODE_ENVELOPE, Intent.CATEGORY_APP_EMAIL);
244 sApplicationLaunchKeyCategories.append(
245 KeyEvent.KEYCODE_CONTACTS, Intent.CATEGORY_APP_CONTACTS);
246 sApplicationLaunchKeyCategories.append(
247 KeyEvent.KEYCODE_CALENDAR, Intent.CATEGORY_APP_CALENDAR);
248 sApplicationLaunchKeyCategories.append(
249 KeyEvent.KEYCODE_MUSIC, Intent.CATEGORY_APP_MUSIC);
250 sApplicationLaunchKeyCategories.append(
251 KeyEvent.KEYCODE_CALCULATOR, Intent.CATEGORY_APP_CALCULATOR);
252 }
253
Craig Mautnerc3daedd2014-09-13 11:17:23 -0700254 /** Amount of time (in milliseconds) to wait for windows drawn before powering on. */
Jorim Jaggi0d210f62015-07-10 14:24:44 -0700255 static final int WAITING_FOR_DRAWN_TIMEOUT = 1000;
Craig Mautnerc3daedd2014-09-13 11:17:23 -0700256
Dianne Hackborndf89e652011-10-06 22:35:11 -0700257 /**
258 * Lock protecting internal state. Must not call out into window
259 * manager with lock held. (This lock will be acquired in places
260 * where the window manager is calling in with its own lock held.)
261 */
Craig Mautner0bf6ec92012-12-18 08:33:27 -0800262 private final Object mLock = new Object();
Dianne Hackborndf89e652011-10-06 22:35:11 -0700263
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800264 Context mContext;
265 IWindowManager mWindowManager;
Dianne Hackborndf89e652011-10-06 22:35:11 -0700266 WindowManagerFuncs mWindowManagerFuncs;
Craig Mautner8a0da012014-05-31 15:13:37 -0700267 WindowManagerInternal mWindowManagerInternal;
Jeff Brown96307042012-07-27 15:51:34 -0700268 PowerManager mPowerManager;
Jeff Brown061ea992015-04-17 19:55:47 -0700269 ActivityManagerInternal mActivityManagerInternal;
Jose Lima9546b202014-07-02 17:21:51 -0700270 DreamManagerInternal mDreamManagerInternal;
Michael Wrighta4d22d72015-09-16 23:19:26 +0100271 PowerManagerInternal mPowerManagerInternal;
Joe Onorato93056472010-09-10 10:30:46 -0400272 IStatusBarService mStatusBarService;
Jeff Browncaca8812013-05-09 13:34:33 -0700273 boolean mPreloadedRecentApps;
Dianne Hackborn42e620c2012-06-24 13:20:51 -0700274 final Object mServiceAquireLock = new Object();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800275 Vibrator mVibrator; // Vibrator for giving feedback of orientation changes
Jeff Brownde7a8ea2012-06-13 18:28:57 -0700276 SearchManager mSearchManager;
Svetoslav8e3feb12014-02-24 13:46:47 -0800277 AccessibilityManager mAccessibilityManager;
Filip Gruszczynskicfb31852015-02-25 21:47:12 +0000278 BurnInProtectionHelper mBurnInProtectionHelper;
Billy Laucbe540f2015-06-25 01:51:44 +0100279 AppOpsManager mAppOpsManager;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800280
Dianne Hackborn181ceb52009-08-27 22:16:40 -0700281 // Vibrator pattern for haptic feedback of a long press.
282 long[] mLongPressVibePattern;
Craig Mautner88400d32012-09-30 12:35:45 -0700283
Dianne Hackborn181ceb52009-08-27 22:16:40 -0700284 // Vibrator pattern for haptic feedback of virtual key press.
285 long[] mVirtualKeyVibePattern;
Craig Mautner967212c2013-04-13 21:10:58 -0700286
Amith Yamasanic33cb712010-02-10 15:21:49 -0800287 // Vibrator pattern for a short vibration.
288 long[] mKeyboardTapVibePattern;
289
Fabrice Di Meglioeeff63a2013-08-05 12:07:24 -0700290 // Vibrator pattern for a short vibration when tapping on an hour/minute tick of a Clock.
291 long[] mClockTickVibePattern;
292
Fabrice Di Megliobd9152f2013-10-01 11:21:31 -0700293 // Vibrator pattern for a short vibration when tapping on a day/month/year date of a Calendar.
294 long[] mCalendarDateVibePattern;
295
Dianne Hackbornb1a79802009-09-29 15:18:31 -0700296 // Vibrator pattern for haptic feedback during boot when safe mode is disabled.
297 long[] mSafeModeDisabledVibePattern;
Craig Mautner967212c2013-04-13 21:10:58 -0700298
Dianne Hackbornb1a79802009-09-29 15:18:31 -0700299 // Vibrator pattern for haptic feedback during boot when safe mode is enabled.
300 long[] mSafeModeEnabledVibePattern;
Romain Guy8154cd32010-03-29 14:41:15 -0700301
Mady Mellore8608912015-06-05 09:02:55 -0700302 // Vibrator pattern for haptic feedback of a context click.
303 long[] mContextClickVibePattern;
Mady Mellore82067b2015-04-30 09:58:35 -0700304
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800305 /** If true, hitting shift & menu will broadcast Intent.ACTION_BUG_REPORT */
306 boolean mEnableShiftMenuBugReports = false;
Mike Lockwoodd747dc82011-09-13 16:28:22 -0400307
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800308 boolean mSafeMode;
309 WindowState mStatusBar = null;
Dianne Hackborn69cb8752011-05-19 18:13:32 -0700310 int mStatusBarHeight;
Daniel Sandler8956dbb2011-04-22 07:55:02 -0400311 WindowState mNavigationBar = null;
Daniel Sandler36412a72011-08-04 09:35:13 -0400312 boolean mHasNavigationBar = false;
Dianne Hackbornf87d1962012-04-04 12:48:24 -0700313 boolean mCanHideNavigationBar = false;
Daniel Sandler4a066c52012-04-20 14:49:13 -0400314 boolean mNavigationBarCanMove = false; // can the navigation bar ever move to the side?
315 boolean mNavigationBarOnBottom = true; // is the navigation bar on the bottom *right now*?
316 int[] mNavigationBarHeightForRotation = new int[4];
317 int[] mNavigationBarWidthForRotation = new int[4];
Daniel Sandler8956dbb2011-04-22 07:55:02 -0400318
Craig Mautnera631d492014-08-05 15:16:01 -0700319 boolean mBootMessageNeedsHiding;
Jim Miller5ecd8112013-01-09 18:50:26 -0800320 KeyguardServiceDelegate mKeyguardDelegate;
Craig Mautner13f6ea72014-06-23 14:57:02 -0700321 final Runnable mWindowManagerDrawCallback = new Runnable() {
Craig Mautner8a0da012014-05-31 15:13:37 -0700322 @Override
Craig Mautner13f6ea72014-06-23 14:57:02 -0700323 public void run() {
Craig Mautner8a0da012014-05-31 15:13:37 -0700324 if (DEBUG_WAKEUP) Slog.i(TAG, "All windows ready for display!");
325 mHandler.sendEmptyMessage(MSG_WINDOW_MANAGER_DRAWN_COMPLETE);
326 }
327 };
Jorim Jaggi740452e2015-07-09 12:13:59 -0700328 final DrawnListener mKeyguardDrawnCallback = new DrawnListener() {
Craig Mautner8a0da012014-05-31 15:13:37 -0700329 @Override
Jorim Jaggi740452e2015-07-09 12:13:59 -0700330 public void onDrawn() {
331 if (DEBUG_WAKEUP) Slog.d(TAG, "mKeyguardDelegate.ShowListener.onDrawn.");
Craig Mautner8a0da012014-05-31 15:13:37 -0700332 mHandler.sendEmptyMessage(MSG_KEYGUARD_DRAWN_COMPLETE);
333 }
334 };
335
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800336 GlobalActions mGlobalActions;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800337 Handler mHandler;
satok1bc0a492012-04-25 22:47:12 +0900338 WindowState mLastInputMethodWindow = null;
339 WindowState mLastInputMethodTargetWindow = null;
Jeff Brown4aed78b2011-01-14 17:36:55 -0800340
Jeff Brown13f00f02014-10-31 14:45:50 -0700341 // FIXME This state is shared between the input reader and handler thread.
342 // Technically it's broken and buggy but it has been like this for many years
343 // and we have not yet seen any problems. Someday we'll rewrite this logic
344 // so that only one thread is involved in handling input policy. Unfortunately
345 // it's on a critical path for power management so we can't just post the work to the
346 // handler thread. We'll need to resolve this someday by teaching the input dispatcher
347 // to hold wakelocks during dispatch and eliminating the critical path.
348 volatile boolean mPowerKeyHandled;
Bryce Leed9268e32014-11-17 17:40:59 -0800349 volatile boolean mBeganFromNonInteractive;
Jeff Brown13f00f02014-10-31 14:45:50 -0700350 volatile int mPowerKeyPressCounter;
351 volatile boolean mEndCallKeyHandled;
352
Winson Chungd42a6cf2014-06-03 16:24:04 -0700353 boolean mRecentsVisible;
Winson Chung1e8d71b2014-05-16 17:05:22 -0700354 int mRecentAppsHeldModifiers;
Jeff Browncf39bdf2012-05-18 14:41:19 -0700355 boolean mLanguageSwitchKeyPressed;
Jeff Brown68b909d2011-12-07 16:36:01 -0800356
Jeff Brown2e7760e2012-04-11 15:14:55 -0700357 int mLidState = LID_ABSENT;
Michael Wright3818c922014-09-02 13:59:07 -0700358 int mCameraLensCoverState = CAMERA_LENS_COVER_ABSENT;
Jeff Browndaa37532012-05-01 15:54:03 -0700359 boolean mHaveBuiltInKeyboard;
Jeff Brown4aed78b2011-01-14 17:36:55 -0800360
Dianne Hackbornc777e072010-02-12 13:07:59 -0800361 boolean mSystemReady;
Dianne Hackbornba24e4d2011-09-01 11:17:06 -0700362 boolean mSystemBooted;
Adrian Roos3542f7d2015-07-13 15:57:53 -0700363 private boolean mDeferBindKeyguard;
Dianne Hackbornad7fa7f2011-01-07 14:06:50 -0800364 boolean mHdmiPlugged;
Jinsuk Kime601b712015-07-07 08:01:02 +0900365 HdmiControl mHdmiControl;
Jeff Brown4f5fa282014-06-12 19:19:15 -0700366 IUiModeManager mUiModeManager;
Daniel Sandler6396c722013-04-16 20:19:09 -0400367 int mUiMode;
Dianne Hackborn867ab6472010-04-29 13:28:56 -0700368 int mDockMode = Intent.EXTRA_DOCK_STATE_UNDOCKED;
Mike Lockwood1753f7f2009-08-24 14:49:07 -0700369 int mLidOpenRotation;
Mike Lockwood2d1efbd2009-09-16 12:15:53 -0400370 int mCarDockRotation;
371 int mDeskDockRotation;
Jeff Brownc82c89ed2013-04-17 17:18:15 -0700372 int mUndockedHdmiRotation;
373 int mDemoHdmiRotation;
374 boolean mDemoHdmiRotationLock;
Chong Zhangae6119ff2014-11-11 18:54:39 -0800375 int mDemoRotation;
376 boolean mDemoRotationLock;
Daniel Sandlerb73617d2010-08-17 00:41:00 -0400377
Jeff Browna20dda42014-05-27 20:57:24 -0700378 boolean mWakeGestureEnabledSetting;
379 MyWakeGestureListener mWakeGestureListener;
380
Craig Mautner46ac6fa2013-08-01 10:06:34 -0700381 // Default display does not rotate, apps that require non-default orientation will have to
382 // have the orientation emulated.
383 private boolean mForceDefaultOrientation = false;
384
Daniel Sandlerb73617d2010-08-17 00:41:00 -0400385 int mUserRotationMode = WindowManagerPolicy.USER_ROTATION_FREE;
386 int mUserRotation = Surface.ROTATION_0;
Jeff Brown207673cd2012-06-05 17:47:11 -0700387 boolean mAccelerometerDefault;
Daniel Sandlerb73617d2010-08-17 00:41:00 -0400388
Jeff Brownbcdfc622014-03-06 19:13:04 -0800389 boolean mSupportAutoRotation;
Jeff Brownd3187e32011-09-21 19:26:44 -0700390 int mAllowAllRotations = -1;
Mike Lockwoode9867d22009-09-20 01:59:02 -0400391 boolean mCarDockEnablesAccelerometer;
392 boolean mDeskDockEnablesAccelerometer;
Dianne Hackborn2862fff2009-09-15 22:56:29 -0700393 int mLidKeyboardAccessibility;
394 int mLidNavigationAccessibility;
Edward Savage-Jones7def60d2015-11-13 13:27:03 +0100395 boolean mLidControlsScreenLock;
Jeff Brownc458ce92012-04-30 14:58:40 -0700396 boolean mLidControlsSleep;
Jeff Brown13f00f02014-10-31 14:45:50 -0700397 int mShortPressOnPowerBehavior;
398 int mLongPressOnPowerBehavior;
399 int mDoublePressOnPowerBehavior;
400 int mTriplePressOnPowerBehavior;
Filip Gruszczynskia483a1d2015-03-17 19:06:58 +0000401 int mShortPressOnSleepBehavior;
Jeff Brown3ee549c2014-09-22 20:14:39 -0700402 boolean mAwake;
403 boolean mScreenOnEarly;
404 boolean mScreenOnFully;
405 ScreenOnListener mScreenOnListener;
406 boolean mKeyguardDrawComplete;
407 boolean mWindowManagerDrawComplete;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800408 boolean mOrientationSensorEnabled = false;
409 int mCurrentAppOrientation = ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800410 boolean mHasSoftInput = false;
Daniel Sandlerdd73ee42013-10-11 22:19:59 -0400411 boolean mTranslucentDecorEnabled = true;
RoboErik001c59c2015-01-26 15:53:51 -0800412 boolean mUseTvRouting;
Craig Mautner967212c2013-04-13 21:10:58 -0700413
Jeff Brown70825162012-03-28 17:27:48 -0700414 int mPointerLocationMode = 0; // guarded by mLock
Joe Onorato664644d2011-01-23 17:53:23 -0800415
416 // The last window we were told about in focusChanged.
417 WindowState mFocusedWindow;
Dianne Hackborne0f085d2011-11-30 18:41:15 -0800418 IApplicationToken mFocusedApp;
Joe Onorato664644d2011-01-23 17:53:23 -0800419
Jeff Brown70825162012-03-28 17:27:48 -0700420 PointerLocationView mPointerLocationView;
Jeff Brown32cbc38552011-12-01 14:01:49 -0800421
Dianne Hackbornc652de82013-02-15 16:32:56 -0800422 // The current size of the screen; really; extends into the overscan area of
423 // the screen and doesn't account for any system elements like the status bar.
424 int mOverscanScreenLeft, mOverscanScreenTop;
425 int mOverscanScreenWidth, mOverscanScreenHeight;
426 // The current visible size of the screen; really; (ir)regardless of whether the status
427 // bar can be hidden but not extending into the overscan area.
Joe Onorato29fc2c92010-11-24 10:26:50 -0800428 int mUnrestrictedScreenLeft, mUnrestrictedScreenTop;
429 int mUnrestrictedScreenWidth, mUnrestrictedScreenHeight;
Dianne Hackborn313440842013-02-19 19:22:59 -0800430 // Like mOverscanScreen*, but allowed to move into the overscan region where appropriate.
431 int mRestrictedOverscanScreenLeft, mRestrictedOverscanScreenTop;
432 int mRestrictedOverscanScreenWidth, mRestrictedOverscanScreenHeight;
Dianne Hackborn82de1ae2010-10-28 11:28:39 -0700433 // The current size of the screen; these may be different than (0,0)-(dw,dh)
434 // if the status bar can't be hidden; in that case it effectively carves out
435 // that area of the display from all other windows.
Joe Onorato29fc2c92010-11-24 10:26:50 -0800436 int mRestrictedScreenLeft, mRestrictedScreenTop;
437 int mRestrictedScreenWidth, mRestrictedScreenHeight;
Dianne Hackborn5c58de32012-04-28 19:52:37 -0700438 // During layout, the current screen borders accounting for any currently
439 // visible system UI elements.
440 int mSystemLeft, mSystemTop, mSystemRight, mSystemBottom;
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -0700441 // For applications requesting stable content insets, these are them.
442 int mStableLeft, mStableTop, mStableRight, mStableBottom;
Dianne Hackborn5b5cc4d2012-05-16 13:15:00 -0700443 // For applications requesting stable content insets but have also set the
444 // fullscreen window flag, these are the stable dimensions without the status bar.
445 int mStableFullscreenLeft, mStableFullscreenTop;
446 int mStableFullscreenRight, mStableFullscreenBottom;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800447 // During layout, the current screen borders with all outer decoration
448 // (status bar, input method dock) accounted for.
449 int mCurLeft, mCurTop, mCurRight, mCurBottom;
450 // During layout, the frame in which content should be displayed
451 // to the user, accounting for all screen decoration except for any
452 // space they deem as available for other content. This is usually
453 // the same as mCur*, but may be larger if the screen decor has supplied
454 // content insets.
455 int mContentLeft, mContentTop, mContentRight, mContentBottom;
Dianne Hackborne30e02f2014-05-27 18:24:45 -0700456 // During layout, the frame in which voice content should be displayed
457 // to the user, accounting for all screen decoration except for any
458 // space they deem as available for other content.
459 int mVoiceContentLeft, mVoiceContentTop, mVoiceContentRight, mVoiceContentBottom;
Dianne Hackborn8e11ef02010-11-18 19:47:42 -0800460 // During layout, the current screen borders along which input method
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800461 // windows are placed.
462 int mDockLeft, mDockTop, mDockRight, mDockBottom;
463 // During layout, the layer at which the doc window is placed.
464 int mDockLayer;
Dianne Hackborn5c58de32012-04-28 19:52:37 -0700465 // During layout, this is the layer of the status bar.
466 int mStatusBarLayer;
Dianne Hackborne26ab702011-10-16 13:21:33 -0700467 int mLastSystemUiFlags;
468 // Bits that we are in the process of clearing, so we want to prevent
469 // them from being set by applications until everything has been updated
470 // to have them clear.
471 int mResettingSystemUiFlags = 0;
472 // Bits that we are currently always keeping cleared.
473 int mForceClearedSystemUiFlags = 0;
Dianne Hackborn4eff8d32011-11-10 19:38:40 -0800474 // What we last reported to system UI about whether the compatibility
475 // menu needs to be displayed.
476 boolean mLastFocusNeedsMenu = false;
Adrian Roosddc8b272015-05-21 16:28:27 -0700477 // If nonzero, a panic gesture was performed at that time in uptime millis and is still pending.
478 private long mPendingPanicGestureUptime;
Dianne Hackborndf89e652011-10-06 22:35:11 -0700479
Selim Cinekf83e8242015-05-19 18:08:14 -0700480 InputConsumer mInputConsumer = null;
Dianne Hackborndf89e652011-10-06 22:35:11 -0700481
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800482 static final Rect mTmpParentFrame = new Rect();
483 static final Rect mTmpDisplayFrame = new Rect();
Dianne Hackbornc4aad012013-02-22 15:05:25 -0800484 static final Rect mTmpOverscanFrame = new Rect();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800485 static final Rect mTmpContentFrame = new Rect();
486 static final Rect mTmpVisibleFrame = new Rect();
John Spurlock46646232013-09-30 22:32:42 -0400487 static final Rect mTmpDecorFrame = new Rect();
Adrian Roosfa104232014-06-20 16:10:14 -0700488 static final Rect mTmpStableFrame = new Rect();
Dianne Hackborn1f903c32011-09-13 19:18:06 -0700489 static final Rect mTmpNavigationFrame = new Rect();
Filip Gruszczynski2217f612015-05-26 11:32:08 -0700490 static final Rect mTmpOutsetFrame = new Rect();
Craig Mautner967212c2013-04-13 21:10:58 -0700491
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800492 WindowState mTopFullscreenOpaqueWindowState;
Adrian Rooscd3884d2015-02-18 17:25:23 +0100493 WindowState mTopFullscreenOpaqueOrDimmingWindowState;
Craig Mautner2bc789b2014-03-19 19:48:38 -0700494 HashSet<IApplicationToken> mAppsToBeHidden = new HashSet<IApplicationToken>();
Jorim Jaggic13fcac2014-09-11 17:36:57 +0200495 HashSet<IApplicationToken> mAppsThatDismissKeyguard = new HashSet<IApplicationToken>();
Joe Onorato93056472010-09-10 10:30:46 -0400496 boolean mTopIsFullscreen;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800497 boolean mForceStatusBar;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -0700498 boolean mForceStatusBarFromKeyguard;
Selim Cinek4a4a2bddc2015-05-07 12:50:19 -0700499 private boolean mForceStatusBarTransparent;
Dianne Hackborn39c2d712009-09-22 11:41:31 -0700500 boolean mHideLockScreen;
Dianne Hackborn891d3fb2013-01-09 18:31:37 -0800501 boolean mForcingShowNavBar;
502 int mForcingShowNavBarLayer;
Craig Mautnerad09bcc2012-10-08 13:33:11 -0700503
504 // States of keyguard dismiss.
505 private static final int DISMISS_KEYGUARD_NONE = 0; // Keyguard not being dismissed.
506 private static final int DISMISS_KEYGUARD_START = 1; // Keyguard needs to be dismissed.
507 private static final int DISMISS_KEYGUARD_CONTINUE = 2; // Keyguard has been dismissed.
508 int mDismissKeyguard = DISMISS_KEYGUARD_NONE;
509
510 /** The window that is currently dismissing the keyguard. Dismissing the keyguard must only
511 * be done once per window. */
512 private WindowState mWinDismissingKeyguard;
513
tingna_sunge785ffa2015-05-12 13:23:15 +0800514 /** When window is currently dismissing the keyguard, dismissing the keyguard must handle
515 * the keygaurd secure state change instantly case, e.g. the use case of inserting a PIN
516 * lock SIM card. This variable is used to record the previous keyguard secure state for
517 * monitoring secure state change on window dismissing keyguard. */
518 private boolean mSecureDismissingKeyguard;
519
Craig Mautnerc9457fa2014-06-06 14:27:48 -0700520 /** The window that is currently showing "over" the keyguard. If there is an app window
521 * belonging to another app on top of this the keyguard shows. If there is a fullscreen
522 * app window under this, still dismiss the keyguard but don't show the app underneath. Show
523 * the wallpaper. */
524 private WindowState mWinShowWhenLocked;
525
Dianne Hackborn7ad44382012-10-18 17:46:00 -0700526 boolean mShowingLockscreen;
527 boolean mShowingDream;
528 boolean mDreamingLockscreen;
Jeff Brown061ea992015-04-17 19:55:47 -0700529 boolean mDreamingSleepTokenNeeded;
530 SleepToken mDreamingSleepToken;
Jeff Brown48d1b142015-06-10 16:36:03 -0700531 SleepToken mScreenOffSleepToken;
Jim Millerab954542014-10-10 18:21:49 -0700532 boolean mKeyguardSecure;
533 boolean mKeyguardSecureIncludingHidden;
534 volatile boolean mKeyguardOccluded;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800535 boolean mHomePressed;
Jeff Browncaca8812013-05-09 13:34:33 -0700536 boolean mHomeConsumed;
537 boolean mHomeDoubleTapPending;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800538 Intent mHomeIntent;
Dianne Hackborn39c2d712009-09-22 11:41:31 -0700539 Intent mCarDockIntent;
540 Intent mDeskDockIntent;
Jeff Brownfd23e3e2012-05-09 13:34:28 -0700541 boolean mSearchKeyShortcutPending;
542 boolean mConsumeSearchKeyUp;
Jeff Brownde7a8ea2012-06-13 18:28:57 -0700543 boolean mAssistKeyLongPressed;
Michael Wright6a62e552014-06-03 19:19:48 -0700544 boolean mPendingMetaAction;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800545
Mike Lockwood28569302010-01-28 11:54:40 -0500546 // support for activating the lock screen while the screen is on
547 boolean mAllowLockscreenWhenOn;
548 int mLockScreenTimeout;
549 boolean mLockScreenTimerActive;
550
David Brownbaf8d092010-03-08 21:52:59 -0800551 // Behavior of ENDCALL Button. (See Settings.System.END_BUTTON_BEHAVIOR.)
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800552 int mEndcallBehavior;
David Brownbaf8d092010-03-08 21:52:59 -0800553
554 // Behavior of POWER button while in-call and screen on.
555 // (See Settings.Secure.INCALL_POWER_BUTTON_BEHAVIOR.)
556 int mIncallPowerBehavior;
557
Dianne Hackbornf87d1962012-04-04 12:48:24 -0700558 Display mDisplay;
559
Filip Gruszczynski2987f612015-06-30 15:03:30 -0700560 private int mDisplayRotation;
561
Dianne Hackborn9d132642011-04-21 17:26:39 -0700562 int mLandscapeRotation = 0; // default landscape rotation
563 int mSeascapeRotation = 0; // "other" landscape rotation, 180 degrees from mLandscapeRotation
564 int mPortraitRotation = 0; // default portrait rotation
565 int mUpsideDownRotation = 0; // "other" portrait rotation
Mitsuru Oshima831d0d92009-06-16 18:27:18 -0700566
Dianne Hackbornc652de82013-02-15 16:32:56 -0800567 int mOverscanLeft = 0;
568 int mOverscanTop = 0;
569 int mOverscanRight = 0;
570 int mOverscanBottom = 0;
571
Joe Onorato46b0d682010-11-22 17:37:27 -0800572 // What we do when the user long presses on home
Jeff Browncaca8812013-05-09 13:34:33 -0700573 private int mLongPressOnHomeBehavior;
574
575 // What we do when the user double-taps on home
576 private int mDoubleTapOnHomeBehavior;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800577
Bryce Lee584a4452014-10-21 15:55:55 -0700578 // Allowed theater mode wake actions
579 private boolean mAllowTheaterModeWakeFromKey;
580 private boolean mAllowTheaterModeWakeFromPowerKey;
581 private boolean mAllowTheaterModeWakeFromMotion;
Bryce Lee812d7022014-11-10 13:33:28 -0800582 private boolean mAllowTheaterModeWakeFromMotionWhenNotDreaming;
Bryce Lee584a4452014-10-21 15:55:55 -0700583 private boolean mAllowTheaterModeWakeFromCameraLens;
584 private boolean mAllowTheaterModeWakeFromLidSwitch;
585 private boolean mAllowTheaterModeWakeFromWakeGesture;
586
Bryce Leed3b28402015-03-09 15:49:13 +0000587 // Whether to support long press from power button in non-interactive mode
588 private boolean mSupportLongPressPowerWhenNonInteractive;
589
Bryce Lee55e846d2014-11-04 12:43:44 -0800590 // Whether to go to sleep entering theater mode from power button
591 private boolean mGoToSleepOnButtonPressTheaterMode;
592
Winson Chung9112ec32011-06-27 13:15:32 -0700593 // Screenshot trigger states
Jeff Brownd5bb82d2011-10-12 13:57:59 -0700594 // Time to volume and power must be pressed within this interval of each other.
595 private static final long SCREENSHOT_CHORD_DEBOUNCE_DELAY_MILLIS = 150;
Winson Chung1cea2f32012-10-08 20:42:01 -0700596 // Increase the chord delay when taking a screenshot from the keyguard
597 private static final float KEYGUARD_SCREENSHOT_CHORD_DELAY_MULTIPLIER = 2.5f;
Christopher Tatee90585f2012-03-05 18:56:25 -0800598 private boolean mScreenshotChordEnabled;
Jeff Brown13f00f02014-10-31 14:45:50 -0700599 private boolean mScreenshotChordVolumeDownKeyTriggered;
600 private long mScreenshotChordVolumeDownKeyTime;
601 private boolean mScreenshotChordVolumeDownKeyConsumed;
602 private boolean mScreenshotChordVolumeUpKeyTriggered;
603 private boolean mScreenshotChordPowerKeyTriggered;
604 private long mScreenshotChordPowerKeyTime;
Winson Chung9112ec32011-06-27 13:15:32 -0700605
Michael Wrightb854e242013-02-05 17:54:02 -0800606 /* The number of steps between min and max brightness */
607 private static final int BRIGHTNESS_STEPS = 10;
608
Christopher Tate5e08af02012-09-21 17:17:22 -0700609 SettingsObserver mSettingsObserver;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800610 ShortcutManager mShortcutManager;
611 PowerManager.WakeLock mBroadcastWakeLock;
Jeff Brown13f00f02014-10-31 14:45:50 -0700612 PowerManager.WakeLock mPowerKeyWakeLock;
Jeff Brown40013652012-05-16 21:22:36 -0700613 boolean mHavePendingMediaKeyRepeatWithWakeLock;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800614
Craig Mautnerd625ab22013-09-06 13:40:31 -0700615 private int mCurrentUserId;
616
Justin Kohd378ad72013-04-01 12:18:26 -0700617 // Maps global key codes to the components that will handle them.
618 private GlobalKeyManager mGlobalKeyManager;
619
Jeff Brownfd23e3e2012-05-09 13:34:28 -0700620 // Fallback actions by key code.
621 private final SparseArray<KeyCharacterMap.FallbackAction> mFallbackActions =
622 new SparseArray<KeyCharacterMap.FallbackAction>();
Jeff Brown49ed71d2010-12-06 17:13:33 -0800623
Jorim Jaggi76a16232014-08-08 17:00:47 +0200624 private final LogDecelerateInterpolator mLogDecelerateInterpolator
625 = new LogDecelerateInterpolator(100, 0);
626
Jeff Brown70825162012-03-28 17:27:48 -0700627 private static final int MSG_ENABLE_POINTER_LOCATION = 1;
628 private static final int MSG_DISABLE_POINTER_LOCATION = 2;
Jeff Brown40013652012-05-16 21:22:36 -0700629 private static final int MSG_DISPATCH_MEDIA_KEY_WITH_WAKE_LOCK = 3;
630 private static final int MSG_DISPATCH_MEDIA_KEY_REPEAT_WITH_WAKE_LOCK = 4;
Craig Mautner8a0da012014-05-31 15:13:37 -0700631 private static final int MSG_KEYGUARD_DRAWN_COMPLETE = 5;
632 private static final int MSG_KEYGUARD_DRAWN_TIMEOUT = 6;
633 private static final int MSG_WINDOW_MANAGER_DRAWN_COMPLETE = 7;
Craig Mautner84984fa2014-06-19 11:19:20 -0700634 private static final int MSG_DISPATCH_SHOW_RECENTS = 9;
Alan Viverettee34560b22014-07-10 14:50:06 -0700635 private static final int MSG_DISPATCH_SHOW_GLOBAL_ACTIONS = 10;
Craig Mautnera631d492014-08-05 15:16:01 -0700636 private static final int MSG_HIDE_BOOT_MESSAGE = 11;
Michael Wright869a67c2014-08-26 19:33:06 -0700637 private static final int MSG_LAUNCH_VOICE_ASSIST_WITH_WAKE_LOCK = 12;
Jeff Brown13f00f02014-10-31 14:45:50 -0700638 private static final int MSG_POWER_DELAYED_PRESS = 13;
639 private static final int MSG_POWER_LONG_PRESS = 14;
Jeff Brown061ea992015-04-17 19:55:47 -0700640 private static final int MSG_UPDATE_DREAMING_SLEEP_TOKEN = 15;
Jeff Brown70825162012-03-28 17:27:48 -0700641
642 private class PolicyHandler extends Handler {
643 @Override
644 public void handleMessage(Message msg) {
645 switch (msg.what) {
646 case MSG_ENABLE_POINTER_LOCATION:
647 enablePointerLocation();
648 break;
649 case MSG_DISABLE_POINTER_LOCATION:
650 disablePointerLocation();
651 break;
Jeff Brown40013652012-05-16 21:22:36 -0700652 case MSG_DISPATCH_MEDIA_KEY_WITH_WAKE_LOCK:
653 dispatchMediaKeyWithWakeLock((KeyEvent)msg.obj);
654 break;
655 case MSG_DISPATCH_MEDIA_KEY_REPEAT_WITH_WAKE_LOCK:
656 dispatchMediaKeyRepeatWithWakeLock((KeyEvent)msg.obj);
657 break;
Craig Mautner84984fa2014-06-19 11:19:20 -0700658 case MSG_DISPATCH_SHOW_RECENTS:
659 showRecentApps(false);
660 break;
Alan Viverettee34560b22014-07-10 14:50:06 -0700661 case MSG_DISPATCH_SHOW_GLOBAL_ACTIONS:
662 showGlobalActionsInternal();
663 break;
Craig Mautner8a0da012014-05-31 15:13:37 -0700664 case MSG_KEYGUARD_DRAWN_COMPLETE:
665 if (DEBUG_WAKEUP) Slog.w(TAG, "Setting mKeyguardDrawComplete");
Jeff Brown36c4db82014-09-19 12:05:31 -0700666 finishKeyguardDrawn();
Craig Mautner8a0da012014-05-31 15:13:37 -0700667 break;
668 case MSG_KEYGUARD_DRAWN_TIMEOUT:
669 Slog.w(TAG, "Keyguard drawn timeout. Setting mKeyguardDrawComplete");
Jeff Brown36c4db82014-09-19 12:05:31 -0700670 finishKeyguardDrawn();
Craig Mautner8a0da012014-05-31 15:13:37 -0700671 break;
672 case MSG_WINDOW_MANAGER_DRAWN_COMPLETE:
673 if (DEBUG_WAKEUP) Slog.w(TAG, "Setting mWindowManagerDrawComplete");
Jeff Brown36c4db82014-09-19 12:05:31 -0700674 finishWindowsDrawn();
Craig Mautner8a0da012014-05-31 15:13:37 -0700675 break;
Craig Mautnera631d492014-08-05 15:16:01 -0700676 case MSG_HIDE_BOOT_MESSAGE:
677 handleHideBootMessage();
678 break;
Michael Wright869a67c2014-08-26 19:33:06 -0700679 case MSG_LAUNCH_VOICE_ASSIST_WITH_WAKE_LOCK:
680 launchVoiceAssistWithWakeLock(msg.arg1 != 0);
681 break;
Jeff Brown13f00f02014-10-31 14:45:50 -0700682 case MSG_POWER_DELAYED_PRESS:
683 powerPress((Long)msg.obj, msg.arg1 != 0, msg.arg2);
684 finishPowerKeyPress();
685 break;
686 case MSG_POWER_LONG_PRESS:
687 powerLongPress();
688 break;
Jeff Brown061ea992015-04-17 19:55:47 -0700689 case MSG_UPDATE_DREAMING_SLEEP_TOKEN:
690 updateDreamingSleepToken(msg.arg1 != 0);
691 break;
Jeff Brown70825162012-03-28 17:27:48 -0700692 }
693 }
694 }
695
Dianne Hackbornad7fa7f2011-01-07 14:06:50 -0800696 private UEventObserver mHDMIObserver = new UEventObserver() {
697 @Override
698 public void onUEvent(UEventObserver.UEvent event) {
699 setHdmiPlugged("1".equals(event.get("SWITCH_STATE")));
700 }
701 };
702
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800703 class SettingsObserver extends ContentObserver {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800704 SettingsObserver(Handler handler) {
705 super(handler);
706 }
David Brownbaf8d092010-03-08 21:52:59 -0800707
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800708 void observe() {
Christopher Tate5e08af02012-09-21 17:17:22 -0700709 // Observe all users' changes
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800710 ContentResolver resolver = mContext.getContentResolver();
711 resolver.registerContentObserver(Settings.System.getUriFor(
Christopher Tate5e08af02012-09-21 17:17:22 -0700712 Settings.System.END_BUTTON_BEHAVIOR), false, this,
713 UserHandle.USER_ALL);
David Brownbaf8d092010-03-08 21:52:59 -0800714 resolver.registerContentObserver(Settings.Secure.getUriFor(
Christopher Tate5e08af02012-09-21 17:17:22 -0700715 Settings.Secure.INCALL_POWER_BUTTON_BEHAVIOR), false, this,
716 UserHandle.USER_ALL);
Jeff Browna20dda42014-05-27 20:57:24 -0700717 resolver.registerContentObserver(Settings.Secure.getUriFor(
718 Settings.Secure.WAKE_GESTURE_ENABLED), false, this,
719 UserHandle.USER_ALL);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800720 resolver.registerContentObserver(Settings.System.getUriFor(
Christopher Tate5e08af02012-09-21 17:17:22 -0700721 Settings.System.ACCELEROMETER_ROTATION), false, this,
722 UserHandle.USER_ALL);
Mike Lockwood28569302010-01-28 11:54:40 -0500723 resolver.registerContentObserver(Settings.System.getUriFor(
Christopher Tate5e08af02012-09-21 17:17:22 -0700724 Settings.System.USER_ROTATION), false, this,
725 UserHandle.USER_ALL);
Daniel Sandlerb73617d2010-08-17 00:41:00 -0400726 resolver.registerContentObserver(Settings.System.getUriFor(
Christopher Tate5e08af02012-09-21 17:17:22 -0700727 Settings.System.SCREEN_OFF_TIMEOUT), false, this,
728 UserHandle.USER_ALL);
Dianne Hackbornc777e072010-02-12 13:07:59 -0800729 resolver.registerContentObserver(Settings.System.getUriFor(
Christopher Tate5e08af02012-09-21 17:17:22 -0700730 Settings.System.POINTER_LOCATION), false, this,
731 UserHandle.USER_ALL);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800732 resolver.registerContentObserver(Settings.Secure.getUriFor(
Christopher Tate5e08af02012-09-21 17:17:22 -0700733 Settings.Secure.DEFAULT_INPUT_METHOD), false, this,
734 UserHandle.USER_ALL);
John Spurlockd9b70bd2014-02-06 17:02:44 -0500735 resolver.registerContentObserver(Settings.Secure.getUriFor(
John Spurlockf1a36642013-10-12 17:50:42 -0400736 Settings.Secure.IMMERSIVE_MODE_CONFIRMATIONS), false, this,
Christopher Tate5e08af02012-09-21 17:17:22 -0700737 UserHandle.USER_ALL);
John Spurlockc6d1c602014-01-17 15:22:06 -0500738 resolver.registerContentObserver(Settings.Global.getUriFor(
739 Settings.Global.POLICY_CONTROL), false, this,
740 UserHandle.USER_ALL);
Dianne Hackbornc777e072010-02-12 13:07:59 -0800741 updateSettings();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800742 }
743
744 @Override public void onChange(boolean selfChange) {
Dianne Hackbornc777e072010-02-12 13:07:59 -0800745 updateSettings();
Jeff Brown01a98dd2011-09-20 15:08:29 -0700746 updateRotation(false);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800747 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800748 }
Craig Mautner967212c2013-04-13 21:10:58 -0700749
Jeff Browna20dda42014-05-27 20:57:24 -0700750 class MyWakeGestureListener extends WakeGestureListener {
751 MyWakeGestureListener(Context context, Handler handler) {
752 super(context, handler);
753 }
754
755 @Override
756 public void onWakeUp() {
757 synchronized (mLock) {
758 if (shouldEnableWakeGestureLp()) {
Jeff Browne07b94b2014-06-18 15:56:27 -0700759 performHapticFeedbackLw(null, HapticFeedbackConstants.VIRTUAL_KEY, false);
Dianne Hackborn280a64e2015-07-13 14:48:08 -0700760 wakeUp(SystemClock.uptimeMillis(), mAllowTheaterModeWakeFromWakeGesture,
761 "android.policy:GESTURE");
Jeff Browna20dda42014-05-27 20:57:24 -0700762 }
763 }
764 }
765 }
766
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800767 class MyOrientationListener extends WindowOrientationListener {
Chong Zhang5aaa0b32015-08-28 10:22:36 -0700768 private final Runnable mUpdateRotationRunnable = new Runnable() {
769 @Override
770 public void run() {
Tim Murray1f407642015-10-01 17:07:12 -0700771 // send interaction hint to improve redraw performance
772 mPowerManagerInternal.powerHint(PowerManagerInternal.POWER_HINT_INTERACTION, 0);
Chong Zhang5aaa0b32015-08-28 10:22:36 -0700773 updateRotation(false);
774 }
775 };
776
Craig Mautnereee29c42013-01-17 14:44:34 -0800777 MyOrientationListener(Context context, Handler handler) {
778 super(context, handler);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800779 }
Craig Mautner967212c2013-04-13 21:10:58 -0700780
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800781 @Override
Jeff Brownc0347aa2011-09-23 17:26:09 -0700782 public void onProposedRotationChanged(int rotation) {
Craig Mautnereda67292013-04-28 13:50:14 -0700783 if (localLOGV) Slog.v(TAG, "onProposedRotationChanged, rotation=" + rotation);
Chong Zhang5aaa0b32015-08-28 10:22:36 -0700784 mHandler.post(mUpdateRotationRunnable);
Jeff Brown01a98dd2011-09-20 15:08:29 -0700785 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800786 }
787 MyOrientationListener mOrientationListener;
788
Jorim Jaggi24bec7c2015-02-04 12:40:14 +0100789 private final StatusBarController mStatusBarController = new StatusBarController();
John Spurlock5b9145b2013-08-20 15:13:47 -0400790
John Spurlock27735a42013-08-14 17:57:38 -0400791 private final BarController mNavigationBarController = new BarController("NavigationBar",
John Spurlock5b9145b2013-08-20 15:13:47 -0400792 View.NAVIGATION_BAR_TRANSIENT,
793 View.NAVIGATION_BAR_UNHIDE,
John Spurlockbd957402013-10-03 11:38:39 -0400794 View.NAVIGATION_BAR_TRANSLUCENT,
795 StatusBarManager.WINDOW_NAVIGATION_BAR,
796 WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION);
John Spurlock5b9145b2013-08-20 15:13:47 -0400797
John Spurlockf1a36642013-10-12 17:50:42 -0400798 private ImmersiveModeConfirmation mImmersiveModeConfirmation;
John Spurlock32beb2c2013-03-11 10:16:47 -0400799
Craig Mautner037aa8d2013-06-07 10:35:44 -0700800 private SystemGesturesPointerEventListener mSystemGestures;
John Spurlock32beb2c2013-03-11 10:16:47 -0400801
Dianne Hackborn42e620c2012-06-24 13:20:51 -0700802 IStatusBarService getStatusBarService() {
803 synchronized (mServiceAquireLock) {
804 if (mStatusBarService == null) {
805 mStatusBarService = IStatusBarService.Stub.asInterface(
806 ServiceManager.getService("statusbar"));
807 }
808 return mStatusBarService;
809 }
810 }
811
Suchi Amalapurapua9e1b162009-03-24 22:24:47 -0700812 /*
813 * We always let the sensor be switched on by default except when
814 * the user has explicitly disabled sensor based rotation or when the
815 * screen is switched off.
816 */
The Android Open Source Project0727d222009-03-11 12:11:58 -0700817 boolean needSensorRunningLp() {
Jeff Brownbcdfc622014-03-06 19:13:04 -0800818 if (mSupportAutoRotation) {
819 if (mCurrentAppOrientation == ActivityInfo.SCREEN_ORIENTATION_SENSOR
820 || mCurrentAppOrientation == ActivityInfo.SCREEN_ORIENTATION_FULL_SENSOR
821 || mCurrentAppOrientation == ActivityInfo.SCREEN_ORIENTATION_SENSOR_PORTRAIT
822 || mCurrentAppOrientation == ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE) {
823 // If the application has explicitly requested to follow the
824 // orientation, then we need to turn the sensor on.
825 return true;
826 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800827 }
Dianne Hackborn867ab6472010-04-29 13:28:56 -0700828 if ((mCarDockEnablesAccelerometer && mDockMode == Intent.EXTRA_DOCK_STATE_CAR) ||
Jeff Brown1a693182011-11-08 14:44:16 -0800829 (mDeskDockEnablesAccelerometer && (mDockMode == Intent.EXTRA_DOCK_STATE_DESK
830 || mDockMode == Intent.EXTRA_DOCK_STATE_LE_DESK
831 || mDockMode == Intent.EXTRA_DOCK_STATE_HE_DESK))) {
Mike Lockwoode9867d22009-09-20 01:59:02 -0400832 // enable accelerometer if we are docked in a dock that enables accelerometer
833 // orientation management,
834 return true;
835 }
Jeff Brown207673cd2012-06-05 17:47:11 -0700836 if (mUserRotationMode == USER_ROTATION_LOCKED) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800837 // If the setting for using the sensor by default is enabled, then
838 // we will always leave it on. Note that the user could go to
839 // a window that forces an orientation that does not use the
840 // sensor and in theory we could turn it off... however, when next
841 // turning it on we won't have a good value for the current
842 // orientation for a little bit, which can cause orientation
843 // changes to lag, so we'd like to keep it always on. (It will
844 // still be turned off when the screen is off.)
Suchi Amalapurapua9e1b162009-03-24 22:24:47 -0700845 return false;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800846 }
Jeff Brownbcdfc622014-03-06 19:13:04 -0800847 return mSupportAutoRotation;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800848 }
Craig Mautner46ac6fa2013-08-01 10:06:34 -0700849
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800850 /*
851 * Various use cases for invoking this function
852 * screen turning off, should always disable listeners if already enabled
Craig Mautner46ac6fa2013-08-01 10:06:34 -0700853 * screen turned on and current app has sensor based orientation, enable listeners
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800854 * if not already enabled
855 * screen turned on and current app does not have sensor orientation, disable listeners if
856 * already enabled
857 * screen turning on and current app has sensor based orientation, enable listeners if needed
858 * screen turning on and current app has nosensor based orientation, do nothing
859 */
The Android Open Source Project0727d222009-03-11 12:11:58 -0700860 void updateOrientationListenerLp() {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800861 if (!mOrientationListener.canDetectOrientation()) {
862 // If sensor is turned off or nonexistent for some reason
863 return;
864 }
Stefan Kuhne9326dc12015-06-12 09:25:32 -1000865 // Could have been invoked due to screen turning on or off or
866 // change of the currently visible window's orientation.
Jeff Brown3ee549c2014-09-22 20:14:39 -0700867 if (localLOGV) Slog.v(TAG, "mScreenOnEarly=" + mScreenOnEarly
868 + ", mAwake=" + mAwake + ", mCurrentAppOrientation=" + mCurrentAppOrientation
Stefan Kuhne9326dc12015-06-12 09:25:32 -1000869 + ", mOrientationSensorEnabled=" + mOrientationSensorEnabled
870 + ", mKeyguardDrawComplete=" + mKeyguardDrawComplete
871 + ", mWindowManagerDrawComplete=" + mWindowManagerDrawComplete);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800872 boolean disable = true;
Stefan Kuhne9326dc12015-06-12 09:25:32 -1000873 // Note: We postpone the rotating of the screen until the keyguard as well as the
874 // window manager have reported a draw complete.
875 if (mScreenOnEarly && mAwake &&
876 mKeyguardDrawComplete && mWindowManagerDrawComplete) {
The Android Open Source Project0727d222009-03-11 12:11:58 -0700877 if (needSensorRunningLp()) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800878 disable = false;
879 //enable listener if not already enabled
The Android Open Source Project0727d222009-03-11 12:11:58 -0700880 if (!mOrientationSensorEnabled) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800881 mOrientationListener.enable();
Craig Mautnereda67292013-04-28 13:50:14 -0700882 if(localLOGV) Slog.v(TAG, "Enabling listeners");
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800883 mOrientationSensorEnabled = true;
884 }
Craig Mautner46ac6fa2013-08-01 10:06:34 -0700885 }
886 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800887 //check if sensors need to be disabled
The Android Open Source Project0727d222009-03-11 12:11:58 -0700888 if (disable && mOrientationSensorEnabled) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800889 mOrientationListener.disable();
Craig Mautnereda67292013-04-28 13:50:14 -0700890 if(localLOGV) Slog.v(TAG, "Disabling listeners");
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800891 mOrientationSensorEnabled = false;
892 }
893 }
894
Jeff Brown13f00f02014-10-31 14:45:50 -0700895 private void interceptPowerKeyDown(KeyEvent event, boolean interactive) {
896 // Hold a wake lock until the power key is released.
897 if (!mPowerKeyWakeLock.isHeld()) {
898 mPowerKeyWakeLock.acquire();
899 }
900
901 // Cancel multi-press detection timeout.
902 if (mPowerKeyPressCounter != 0) {
903 mHandler.removeMessages(MSG_POWER_DELAYED_PRESS);
904 }
905
906 // Detect user pressing the power button in panic when an application has
907 // taken over the whole screen.
908 boolean panic = mImmersiveModeConfirmation.onPowerKeyDown(interactive,
Craig Mautner0124980e92014-11-30 21:15:34 -0800909 SystemClock.elapsedRealtime(), isImmersiveMode(mLastSystemUiFlags));
Jeff Brown13f00f02014-10-31 14:45:50 -0700910 if (panic) {
Adrian Roosddc8b272015-05-21 16:28:27 -0700911 mHandler.post(mHiddenNavPanic);
Jeff Brown13f00f02014-10-31 14:45:50 -0700912 }
913
914 // Latch power key state to detect screenshot chord.
915 if (interactive && !mScreenshotChordPowerKeyTriggered
916 && (event.getFlags() & KeyEvent.FLAG_FALLBACK) == 0) {
917 mScreenshotChordPowerKeyTriggered = true;
918 mScreenshotChordPowerKeyTime = event.getDownTime();
919 interceptScreenshotChord();
920 }
921
922 // Stop ringing or end call if configured to do so when power is pressed.
923 TelecomManager telecomManager = getTelecommService();
924 boolean hungUp = false;
925 if (telecomManager != null) {
926 if (telecomManager.isRinging()) {
927 // Pressing Power while there's a ringing incoming
928 // call should silence the ringer.
929 telecomManager.silenceRinger();
930 } else if ((mIncallPowerBehavior
931 & Settings.Secure.INCALL_POWER_BUTTON_BEHAVIOR_HANGUP) != 0
932 && telecomManager.isInCall() && interactive) {
933 // Otherwise, if "Power button ends call" is enabled,
934 // the Power button will hang up any current active call.
935 hungUp = telecomManager.endCall();
936 }
937 }
938
Adrian Roos5941c982015-09-03 15:59:49 -0700939 GestureLauncherService gestureService = LocalServices.getService(
940 GestureLauncherService.class);
941 boolean gesturedServiceIntercepted = false;
942 if (gestureService != null) {
943 gesturedServiceIntercepted = gestureService.interceptPowerKeyDown(event, interactive);
944 }
945
Jeff Brown13f00f02014-10-31 14:45:50 -0700946 // If the power key has still not yet been handled, then detect short
947 // press, long press, or multi press and decide what to do.
948 mPowerKeyHandled = hungUp || mScreenshotChordVolumeDownKeyTriggered
Adrian Roos5941c982015-09-03 15:59:49 -0700949 || mScreenshotChordVolumeUpKeyTriggered || gesturedServiceIntercepted;
Jeff Brown13f00f02014-10-31 14:45:50 -0700950 if (!mPowerKeyHandled) {
951 if (interactive) {
952 // When interactive, we're already awake.
953 // Wait for a long press or for the button to be released to decide what to do.
954 if (hasLongPressOnPowerBehavior()) {
955 Message msg = mHandler.obtainMessage(MSG_POWER_LONG_PRESS);
956 msg.setAsynchronous(true);
957 mHandler.sendMessageDelayed(msg,
958 ViewConfiguration.get(mContext).getDeviceGlobalActionKeyTimeout());
959 }
960 } else {
Bryce Leed9268e32014-11-17 17:40:59 -0800961 wakeUpFromPowerKey(event.getDownTime());
Bryce Leed9268e32014-11-17 17:40:59 -0800962
Bryce Leed3b28402015-03-09 15:49:13 +0000963 if (mSupportLongPressPowerWhenNonInteractive && hasLongPressOnPowerBehavior()) {
964 Message msg = mHandler.obtainMessage(MSG_POWER_LONG_PRESS);
965 msg.setAsynchronous(true);
966 mHandler.sendMessageDelayed(msg,
967 ViewConfiguration.get(mContext).getDeviceGlobalActionKeyTimeout());
Bryce Leed9268e32014-11-17 17:40:59 -0800968 mBeganFromNonInteractive = true;
Bryce Leed3b28402015-03-09 15:49:13 +0000969 } else {
970 final int maxCount = getMaxMultiPressPowerCount();
971
972 if (maxCount <= 1) {
973 mPowerKeyHandled = true;
974 } else {
975 mBeganFromNonInteractive = true;
976 }
Jeff Brown13f00f02014-10-31 14:45:50 -0700977 }
978 }
Jeff Brown4d396052010-10-29 21:50:21 -0700979 }
980 }
981
Jeff Brown13f00f02014-10-31 14:45:50 -0700982 private void interceptPowerKeyUp(KeyEvent event, boolean interactive, boolean canceled) {
983 final boolean handled = canceled || mPowerKeyHandled;
984 mScreenshotChordPowerKeyTriggered = false;
985 cancelPendingScreenshotChordAction();
986 cancelPendingPowerKeyAction();
987
988 if (!handled) {
989 // Figure out how to handle the key now that it has been released.
990 mPowerKeyPressCounter += 1;
991
992 final int maxCount = getMaxMultiPressPowerCount();
993 final long eventTime = event.getDownTime();
994 if (mPowerKeyPressCounter < maxCount) {
995 // This could be a multi-press. Wait a little bit longer to confirm.
996 // Continue holding the wake lock.
997 Message msg = mHandler.obtainMessage(MSG_POWER_DELAYED_PRESS,
998 interactive ? 1 : 0, mPowerKeyPressCounter, eventTime);
999 msg.setAsynchronous(true);
1000 mHandler.sendMessageDelayed(msg, ViewConfiguration.getDoubleTapTimeout());
1001 return;
1002 }
1003
1004 // No other actions. Handle it immediately.
1005 powerPress(eventTime, interactive, mPowerKeyPressCounter);
Jeff Brown4d396052010-10-29 21:50:21 -07001006 }
Jeff Brown13f00f02014-10-31 14:45:50 -07001007
1008 // Done. Reset our state.
1009 finishPowerKeyPress();
1010 }
1011
1012 private void finishPowerKeyPress() {
Bryce Leed9268e32014-11-17 17:40:59 -08001013 mBeganFromNonInteractive = false;
Jeff Brown13f00f02014-10-31 14:45:50 -07001014 mPowerKeyPressCounter = 0;
1015 if (mPowerKeyWakeLock.isHeld()) {
1016 mPowerKeyWakeLock.release();
1017 }
Jeff Brownd5bb82d2011-10-12 13:57:59 -07001018 }
1019
1020 private void cancelPendingPowerKeyAction() {
1021 if (!mPowerKeyHandled) {
Jeff Brown13f00f02014-10-31 14:45:50 -07001022 mPowerKeyHandled = true;
1023 mHandler.removeMessages(MSG_POWER_LONG_PRESS);
Jeff Brownd5bb82d2011-10-12 13:57:59 -07001024 }
Jeff Brown13f00f02014-10-31 14:45:50 -07001025 }
1026
1027 private void powerPress(long eventTime, boolean interactive, int count) {
1028 if (mScreenOnEarly && !mScreenOnFully) {
1029 Slog.i(TAG, "Suppressed redundant power key press while "
1030 + "already in the process of turning the screen on.");
1031 return;
Jeff Brownff204712011-10-25 21:27:54 -07001032 }
Jeff Brown13f00f02014-10-31 14:45:50 -07001033
1034 if (count == 2) {
1035 powerMultiPressAction(eventTime, interactive, mDoublePressOnPowerBehavior);
1036 } else if (count == 3) {
1037 powerMultiPressAction(eventTime, interactive, mTriplePressOnPowerBehavior);
Bryce Leed9268e32014-11-17 17:40:59 -08001038 } else if (interactive && !mBeganFromNonInteractive) {
Jeff Brown13f00f02014-10-31 14:45:50 -07001039 switch (mShortPressOnPowerBehavior) {
1040 case SHORT_PRESS_POWER_NOTHING:
1041 break;
1042 case SHORT_PRESS_POWER_GO_TO_SLEEP:
1043 mPowerManager.goToSleep(eventTime,
1044 PowerManager.GO_TO_SLEEP_REASON_POWER_BUTTON, 0);
1045 break;
1046 case SHORT_PRESS_POWER_REALLY_GO_TO_SLEEP:
1047 mPowerManager.goToSleep(eventTime,
1048 PowerManager.GO_TO_SLEEP_REASON_POWER_BUTTON,
1049 PowerManager.GO_TO_SLEEP_FLAG_NO_DOZE);
1050 break;
1051 case SHORT_PRESS_POWER_REALLY_GO_TO_SLEEP_AND_GO_HOME:
1052 mPowerManager.goToSleep(eventTime,
1053 PowerManager.GO_TO_SLEEP_REASON_POWER_BUTTON,
1054 PowerManager.GO_TO_SLEEP_FLAG_NO_DOZE);
1055 launchHomeFromHotKey();
1056 break;
Bryce Lee01b0c5f2015-02-05 18:24:04 -08001057 case SHORT_PRESS_POWER_GO_HOME:
Bryce Lee662ed802015-04-10 20:11:39 +00001058 launchHomeFromHotKey(true /* awakenFromDreams */, false /*respectKeyguard*/);
Bryce Lee01b0c5f2015-02-05 18:24:04 -08001059 break;
Jeff Brown13f00f02014-10-31 14:45:50 -07001060 }
1061 }
1062 }
1063
1064 private void powerMultiPressAction(long eventTime, boolean interactive, int behavior) {
1065 switch (behavior) {
1066 case MULTI_PRESS_POWER_NOTHING:
1067 break;
1068 case MULTI_PRESS_POWER_THEATER_MODE:
Bryce Lee3ae447e2015-06-30 12:31:41 -07001069 if (!isUserSetupComplete()) {
1070 Slog.i(TAG, "Ignoring toggling theater mode - device not setup.");
1071 break;
1072 }
1073
Jeff Brown13f00f02014-10-31 14:45:50 -07001074 if (isTheaterModeEnabled()) {
1075 Slog.i(TAG, "Toggling theater mode off.");
1076 Settings.Global.putInt(mContext.getContentResolver(),
1077 Settings.Global.THEATER_MODE_ON, 0);
1078 if (!interactive) {
1079 wakeUpFromPowerKey(eventTime);
1080 }
1081 } else {
1082 Slog.i(TAG, "Toggling theater mode on.");
1083 Settings.Global.putInt(mContext.getContentResolver(),
1084 Settings.Global.THEATER_MODE_ON, 1);
Bryce Lee55e846d2014-11-04 12:43:44 -08001085
1086 if (mGoToSleepOnButtonPressTheaterMode && interactive) {
Jeff Brown13f00f02014-10-31 14:45:50 -07001087 mPowerManager.goToSleep(eventTime,
1088 PowerManager.GO_TO_SLEEP_REASON_POWER_BUTTON, 0);
1089 }
1090 }
1091 break;
1092 case MULTI_PRESS_POWER_BRIGHTNESS_BOOST:
Jeff Brown7b5be5e2014-11-12 18:45:31 -08001093 Slog.i(TAG, "Starting brightness boost.");
1094 if (!interactive) {
1095 wakeUpFromPowerKey(eventTime);
1096 }
Jeff Brown13f00f02014-10-31 14:45:50 -07001097 mPowerManager.boostScreenBrightness(eventTime);
1098 break;
1099 }
1100 }
1101
1102 private int getMaxMultiPressPowerCount() {
1103 if (mTriplePressOnPowerBehavior != MULTI_PRESS_POWER_NOTHING) {
1104 return 3;
1105 }
1106 if (mDoublePressOnPowerBehavior != MULTI_PRESS_POWER_NOTHING) {
1107 return 2;
1108 }
1109 return 1;
1110 }
1111
1112 private void powerLongPress() {
1113 final int behavior = getResolvedLongPressOnPowerBehavior();
1114 switch (behavior) {
1115 case LONG_PRESS_POWER_NOTHING:
1116 break;
1117 case LONG_PRESS_POWER_GLOBAL_ACTIONS:
1118 mPowerKeyHandled = true;
1119 if (!performHapticFeedbackLw(null, HapticFeedbackConstants.LONG_PRESS, false)) {
1120 performAuditoryFeedbackForAccessibilityIfNeed();
1121 }
1122 showGlobalActionsInternal();
1123 break;
1124 case LONG_PRESS_POWER_SHUT_OFF:
1125 case LONG_PRESS_POWER_SHUT_OFF_NO_CONFIRM:
1126 mPowerKeyHandled = true;
1127 performHapticFeedbackLw(null, HapticFeedbackConstants.LONG_PRESS, false);
1128 sendCloseSystemWindows(SYSTEM_DIALOG_REASON_GLOBAL_ACTIONS);
1129 mWindowManagerFuncs.shutdown(behavior == LONG_PRESS_POWER_SHUT_OFF);
1130 break;
1131 }
1132 }
1133
Nick Vaccarob593a812015-05-15 11:23:05 -07001134 private void sleepPress(long eventTime) {
1135 if (mShortPressOnSleepBehavior == SHORT_PRESS_SLEEP_GO_TO_SLEEP_AND_GO_HOME) {
1136 launchHomeFromHotKey(false /* awakenDreams */, true /*respectKeyguard*/);
1137 }
1138 }
1139
1140 private void sleepRelease(long eventTime) {
Filip Gruszczynskia483a1d2015-03-17 19:06:58 +00001141 switch (mShortPressOnSleepBehavior) {
1142 case SHORT_PRESS_SLEEP_GO_TO_SLEEP:
Filip Gruszczynskia483a1d2015-03-17 19:06:58 +00001143 case SHORT_PRESS_SLEEP_GO_TO_SLEEP_AND_GO_HOME:
Nick Vaccarob593a812015-05-15 11:23:05 -07001144 Slog.i(TAG, "sleepRelease() calling goToSleep(GO_TO_SLEEP_REASON_SLEEP_BUTTON)");
1145 mPowerManager.goToSleep(eventTime,
1146 PowerManager.GO_TO_SLEEP_REASON_SLEEP_BUTTON, 0);
Filip Gruszczynskia483a1d2015-03-17 19:06:58 +00001147 break;
1148 }
1149 }
1150
Jeff Brown13f00f02014-10-31 14:45:50 -07001151 private int getResolvedLongPressOnPowerBehavior() {
1152 if (FactoryTest.isLongPressOnPowerOffEnabled()) {
1153 return LONG_PRESS_POWER_SHUT_OFF_NO_CONFIRM;
1154 }
1155 return mLongPressOnPowerBehavior;
1156 }
1157
1158 private boolean hasLongPressOnPowerBehavior() {
1159 return getResolvedLongPressOnPowerBehavior() != LONG_PRESS_POWER_NOTHING;
Jeff Brownd5bb82d2011-10-12 13:57:59 -07001160 }
1161
1162 private void interceptScreenshotChord() {
Christopher Tatee90585f2012-03-05 18:56:25 -08001163 if (mScreenshotChordEnabled
Jeff Brown13f00f02014-10-31 14:45:50 -07001164 && mScreenshotChordVolumeDownKeyTriggered && mScreenshotChordPowerKeyTriggered
1165 && !mScreenshotChordVolumeUpKeyTriggered) {
Jeff Brownd5bb82d2011-10-12 13:57:59 -07001166 final long now = SystemClock.uptimeMillis();
Jeff Brown13f00f02014-10-31 14:45:50 -07001167 if (now <= mScreenshotChordVolumeDownKeyTime + SCREENSHOT_CHORD_DEBOUNCE_DELAY_MILLIS
1168 && now <= mScreenshotChordPowerKeyTime
1169 + SCREENSHOT_CHORD_DEBOUNCE_DELAY_MILLIS) {
1170 mScreenshotChordVolumeDownKeyConsumed = true;
Jeff Brownd5bb82d2011-10-12 13:57:59 -07001171 cancelPendingPowerKeyAction();
1172
Jeff Sharkey2991fa32012-12-05 18:06:43 -08001173 mHandler.postDelayed(mScreenshotRunnable, getScreenshotChordLongPressDelay());
Jeff Brownd5bb82d2011-10-12 13:57:59 -07001174 }
1175 }
1176 }
1177
Winson Chung1cea2f32012-10-08 20:42:01 -07001178 private long getScreenshotChordLongPressDelay() {
Jim Miller5ecd8112013-01-09 18:50:26 -08001179 if (mKeyguardDelegate.isShowing()) {
Winson Chung1cea2f32012-10-08 20:42:01 -07001180 // Double the time it takes to take a screenshot from the keyguard
1181 return (long) (KEYGUARD_SCREENSHOT_CHORD_DELAY_MULTIPLIER *
Justin Kohfeabd2c2014-05-02 10:02:44 -07001182 ViewConfiguration.get(mContext).getDeviceGlobalActionKeyTimeout());
Winson Chung1cea2f32012-10-08 20:42:01 -07001183 }
Justin Kohfeabd2c2014-05-02 10:02:44 -07001184 return ViewConfiguration.get(mContext).getDeviceGlobalActionKeyTimeout();
Winson Chung1cea2f32012-10-08 20:42:01 -07001185 }
1186
Jeff Brownd5bb82d2011-10-12 13:57:59 -07001187 private void cancelPendingScreenshotChordAction() {
Jeff Sharkey2991fa32012-12-05 18:06:43 -08001188 mHandler.removeCallbacks(mScreenshotRunnable);
Jeff Brown4d396052010-10-29 21:50:21 -07001189 }
1190
Jeff Brown13f00f02014-10-31 14:45:50 -07001191 private final Runnable mEndCallLongPress = new Runnable() {
Craig Mautnerf1b67412012-09-19 13:18:29 -07001192 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001193 public void run() {
Jeff Brown13f00f02014-10-31 14:45:50 -07001194 mEndCallKeyHandled = true;
1195 if (!performHapticFeedbackLw(null, HapticFeedbackConstants.LONG_PRESS, false)) {
1196 performAuditoryFeedbackForAccessibilityIfNeed();
Joe Onoratod208e702010-10-08 16:22:43 -04001197 }
Jeff Brown13f00f02014-10-31 14:45:50 -07001198 showGlobalActionsInternal();
Jeff Brownd5bb82d2011-10-12 13:57:59 -07001199 }
1200 };
1201
Jeff Sharkey2991fa32012-12-05 18:06:43 -08001202 private final Runnable mScreenshotRunnable = new Runnable() {
Craig Mautner0bf6ec92012-12-18 08:33:27 -08001203 @Override
Jeff Brownd5bb82d2011-10-12 13:57:59 -07001204 public void run() {
1205 takeScreenshot();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001206 }
1207 };
1208
Alan Viverettee34560b22014-07-10 14:50:06 -07001209 @Override
1210 public void showGlobalActions() {
1211 mHandler.removeMessages(MSG_DISPATCH_SHOW_GLOBAL_ACTIONS);
1212 mHandler.sendEmptyMessage(MSG_DISPATCH_SHOW_GLOBAL_ACTIONS);
1213 }
1214
1215 void showGlobalActionsInternal() {
1216 sendCloseSystemWindows(SYSTEM_DIALOG_REASON_GLOBAL_ACTIONS);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001217 if (mGlobalActions == null) {
Jeff Brown7304c342012-05-11 18:42:42 -07001218 mGlobalActions = new GlobalActions(mContext, mWindowManagerFuncs);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001219 }
Jim Millerab954542014-10-10 18:21:49 -07001220 final boolean keyguardShowing = isKeyguardShowingAndNotOccluded();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001221 mGlobalActions.showDialog(keyguardShowing, isDeviceProvisioned());
1222 if (keyguardShowing) {
1223 // since it took two seconds of long press to bring this up,
1224 // poke the wake lock so they have some time to see the dialog.
Jim Miller25190572013-02-28 17:36:24 -08001225 mPowerManager.userActivity(SystemClock.uptimeMillis(), false);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001226 }
1227 }
1228
1229 boolean isDeviceProvisioned() {
Jeff Brownbf6f6f92012-09-25 15:03:20 -07001230 return Settings.Global.getInt(
1231 mContext.getContentResolver(), Settings.Global.DEVICE_PROVISIONED, 0) != 0;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001232 }
1233
Maurice Lam99c6e072014-04-28 18:24:28 -07001234 boolean isUserSetupComplete() {
1235 return Settings.Secure.getIntForUser(mContext.getContentResolver(),
1236 Settings.Secure.USER_SETUP_COMPLETE, 0, UserHandle.USER_CURRENT) != 0;
1237 }
1238
Jeff Brown13f00f02014-10-31 14:45:50 -07001239 private void handleShortPressOnHome() {
Jinsuk Kime601b712015-07-07 08:01:02 +09001240 // Turn on the connected TV and switch HDMI input if we're a HDMI playback device.
1241 getHdmiControl().turnOnTv();
1242
Jeff Brown13f00f02014-10-31 14:45:50 -07001243 // If there's a dream running then use home to escape the dream
1244 // but don't actually go home.
1245 if (mDreamManagerInternal != null && mDreamManagerInternal.isDreaming()) {
1246 mDreamManagerInternal.stopDream(false /*immediate*/);
1247 return;
1248 }
1249
1250 // Go home!
1251 launchHomeFromHotKey();
1252 }
1253
Jinsuk Kime601b712015-07-07 08:01:02 +09001254 /**
1255 * Creates an accessor to HDMI control service that performs the operation of
1256 * turning on TV (optional) and switching input to us. If HDMI control service
1257 * is not available or we're not a HDMI playback device, the operation is no-op.
1258 */
1259 private HdmiControl getHdmiControl() {
1260 if (null == mHdmiControl) {
1261 HdmiControlManager manager = (HdmiControlManager) mContext.getSystemService(
1262 Context.HDMI_CONTROL_SERVICE);
1263 HdmiPlaybackClient client = null;
1264 if (manager != null) {
1265 client = manager.getPlaybackClient();
1266 }
1267 mHdmiControl = new HdmiControl(client);
1268 }
1269 return mHdmiControl;
1270 }
1271
1272 private static class HdmiControl {
1273 private final HdmiPlaybackClient mClient;
1274
1275 private HdmiControl(HdmiPlaybackClient client) {
1276 mClient = client;
1277 }
1278
1279 public void turnOnTv() {
1280 if (mClient == null) {
1281 return;
1282 }
1283 mClient.oneTouchPlay(new OneTouchPlayCallback() {
1284 @Override
1285 public void onComplete(int result) {
1286 if (result != HdmiControlManager.RESULT_SUCCESS) {
1287 Log.w(TAG, "One touch play failed: " + result);
1288 }
1289 }
1290 });
1291 }
1292 }
1293
Tim Kilbourn0e5f1102015-06-05 16:18:09 -07001294 private void handleLongPressOnHome(int deviceId) {
Joe Onorato46b0d682010-11-22 17:37:27 -08001295 if (mLongPressOnHomeBehavior != LONG_PRESS_HOME_NOTHING) {
Jeff Browncaca8812013-05-09 13:34:33 -07001296 mHomeConsumed = true;
Joe Onorato46b0d682010-11-22 17:37:27 -08001297 performHapticFeedbackLw(null, HapticFeedbackConstants.LONG_PRESS, false);
Patrick Dubroyece94522011-02-23 18:35:01 -08001298
Jeff Browncaca8812013-05-09 13:34:33 -07001299 if (mLongPressOnHomeBehavior == LONG_PRESS_HOME_RECENT_SYSTEM_UI) {
1300 toggleRecentApps();
1301 } else if (mLongPressOnHomeBehavior == LONG_PRESS_HOME_ASSIST) {
Tim Kilbourn0e5f1102015-06-05 16:18:09 -07001302 launchAssistAction(null, deviceId);
Jim Millere6ad1a82010-08-20 19:25:39 -07001303 }
1304 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001305 }
Patrick Dubroyece94522011-02-23 18:35:01 -08001306
Jeff Browncaca8812013-05-09 13:34:33 -07001307 private void handleDoubleTapOnHome() {
1308 if (mDoubleTapOnHomeBehavior == DOUBLE_TAP_HOME_RECENT_SYSTEM_UI) {
1309 mHomeConsumed = true;
1310 toggleRecentApps();
1311 }
1312 }
1313
1314 private final Runnable mHomeDoubleTapTimeoutRunnable = new Runnable() {
1315 @Override
1316 public void run() {
1317 if (mHomeDoubleTapPending) {
1318 mHomeDoubleTapPending = false;
Jeff Brown13f00f02014-10-31 14:45:50 -07001319 handleShortPressOnHome();
Jeff Browncaca8812013-05-09 13:34:33 -07001320 }
1321 }
1322 };
1323
Mark Renoufc1256912015-03-11 14:38:23 -04001324 private boolean isRoundWindow() {
Adam Powell01f280d2015-05-18 16:07:42 -07001325 return mContext.getResources().getConfiguration().isScreenRound();
Mark Renoufc1256912015-03-11 14:38:23 -04001326 }
1327
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001328 /** {@inheritDoc} */
Craig Mautner0bf6ec92012-12-18 08:33:27 -08001329 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001330 public void init(Context context, IWindowManager windowManager,
Jeff Brown96307042012-07-27 15:51:34 -07001331 WindowManagerFuncs windowManagerFuncs) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001332 mContext = context;
1333 mWindowManager = windowManager;
Dianne Hackborndf89e652011-10-06 22:35:11 -07001334 mWindowManagerFuncs = windowManagerFuncs;
Craig Mautner8a0da012014-05-31 15:13:37 -07001335 mWindowManagerInternal = LocalServices.getService(WindowManagerInternal.class);
Jeff Brown061ea992015-04-17 19:55:47 -07001336 mActivityManagerInternal = LocalServices.getService(ActivityManagerInternal.class);
Jose Lima9546b202014-07-02 17:21:51 -07001337 mDreamManagerInternal = LocalServices.getService(DreamManagerInternal.class);
Michael Wrighta4d22d72015-09-16 23:19:26 +01001338 mPowerManagerInternal = LocalServices.getService(PowerManagerInternal.class);
Billy Laucbe540f2015-06-25 01:51:44 +01001339 mAppOpsManager = (AppOpsManager) mContext.getSystemService(Context.APP_OPS_SERVICE);
Nick Armstrong-Crews56ecfcc2015-09-07 21:46:50 -07001340 mPowerManagerInternal = LocalServices.getService(PowerManagerInternal.class);
Mark Renoufc1256912015-03-11 14:38:23 -04001341
1342 // Init display burn-in protection
1343 boolean burnInProtectionEnabled = context.getResources().getBoolean(
1344 com.android.internal.R.bool.config_enableBurnInProtection);
1345 // Allow a system property to override this. Used by developer settings.
1346 boolean burnInProtectionDevMode =
1347 SystemProperties.getBoolean("persist.debug.force_burn_in", false);
1348 if (burnInProtectionEnabled || burnInProtectionDevMode) {
1349 final int minHorizontal;
1350 final int maxHorizontal;
1351 final int minVertical;
1352 final int maxVertical;
1353 final int maxRadius;
1354 if (burnInProtectionDevMode) {
1355 minHorizontal = -8;
1356 maxHorizontal = 8;
1357 minVertical = -8;
1358 maxVertical = -4;
1359 maxRadius = (isRoundWindow()) ? 6 : -1;
1360 } else {
1361 Resources resources = context.getResources();
1362 minHorizontal = resources.getInteger(
1363 com.android.internal.R.integer.config_burnInProtectionMinHorizontalOffset);
1364 maxHorizontal = resources.getInteger(
1365 com.android.internal.R.integer.config_burnInProtectionMaxHorizontalOffset);
1366 minVertical = resources.getInteger(
1367 com.android.internal.R.integer.config_burnInProtectionMinVerticalOffset);
1368 maxVertical = resources.getInteger(
1369 com.android.internal.R.integer.config_burnInProtectionMaxVerticalOffset);
1370 maxRadius = resources.getInteger(
1371 com.android.internal.R.integer.config_burnInProtectionMaxRadius);
1372 }
1373 mBurnInProtectionHelper = new BurnInProtectionHelper(
1374 context, minHorizontal, maxHorizontal, minVertical, maxVertical, maxRadius);
Filip Gruszczynskicfb31852015-02-25 21:47:12 +00001375 }
Craig Mautner8a0da012014-05-31 15:13:37 -07001376
Jeff Brown70825162012-03-28 17:27:48 -07001377 mHandler = new PolicyHandler();
Jeff Browna20dda42014-05-27 20:57:24 -07001378 mWakeGestureListener = new MyWakeGestureListener(mContext, mHandler);
Craig Mautnereee29c42013-01-17 14:44:34 -08001379 mOrientationListener = new MyOrientationListener(mContext, mHandler);
Jeff Brownc0347aa2011-09-23 17:26:09 -07001380 try {
1381 mOrientationListener.setCurrentRotation(windowManager.getRotation());
1382 } catch (RemoteException ex) { }
Christopher Tate5e08af02012-09-21 17:17:22 -07001383 mSettingsObserver = new SettingsObserver(mHandler);
1384 mSettingsObserver.observe();
Svetoslav683914b2015-01-15 14:22:26 -08001385 mShortcutManager = new ShortcutManager(context);
Daniel Sandler6396c722013-04-16 20:19:09 -04001386 mUiMode = context.getResources().getInteger(
1387 com.android.internal.R.integer.config_defaultUiModeType);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001388 mHomeIntent = new Intent(Intent.ACTION_MAIN, null);
1389 mHomeIntent.addCategory(Intent.CATEGORY_HOME);
1390 mHomeIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK
1391 | Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED);
Dianne Hackborn39c2d712009-09-22 11:41:31 -07001392 mCarDockIntent = new Intent(Intent.ACTION_MAIN, null);
1393 mCarDockIntent.addCategory(Intent.CATEGORY_CAR_DOCK);
1394 mCarDockIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK
1395 | Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED);
1396 mDeskDockIntent = new Intent(Intent.ACTION_MAIN, null);
1397 mDeskDockIntent.addCategory(Intent.CATEGORY_DESK_DOCK);
1398 mDeskDockIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK
1399 | Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED);
Jim Millere6ad1a82010-08-20 19:25:39 -07001400
Jeff Brown96307042012-07-27 15:51:34 -07001401 mPowerManager = (PowerManager)context.getSystemService(Context.POWER_SERVICE);
1402 mBroadcastWakeLock = mPowerManager.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK,
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001403 "PhoneWindowManager.mBroadcastWakeLock");
Jeff Brown13f00f02014-10-31 14:45:50 -07001404 mPowerKeyWakeLock = mPowerManager.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK,
1405 "PhoneWindowManager.mPowerKeyWakeLock");
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001406 mEnableShiftMenuBugReports = "1".equals(SystemProperties.get("ro.debuggable"));
Jeff Brownbcdfc622014-03-06 19:13:04 -08001407 mSupportAutoRotation = mContext.getResources().getBoolean(
1408 com.android.internal.R.bool.config_supportAutoRotation);
Dianne Hackborn2862fff2009-09-15 22:56:29 -07001409 mLidOpenRotation = readRotation(
Mike Lockwood2d1efbd2009-09-16 12:15:53 -04001410 com.android.internal.R.integer.config_lidOpenRotation);
1411 mCarDockRotation = readRotation(
1412 com.android.internal.R.integer.config_carDockRotation);
1413 mDeskDockRotation = readRotation(
1414 com.android.internal.R.integer.config_deskDockRotation);
Jeff Brownc82c89ed2013-04-17 17:18:15 -07001415 mUndockedHdmiRotation = readRotation(
1416 com.android.internal.R.integer.config_undockedHdmiRotation);
Mike Lockwoode9867d22009-09-20 01:59:02 -04001417 mCarDockEnablesAccelerometer = mContext.getResources().getBoolean(
1418 com.android.internal.R.bool.config_carDockEnablesAccelerometer);
1419 mDeskDockEnablesAccelerometer = mContext.getResources().getBoolean(
1420 com.android.internal.R.bool.config_deskDockEnablesAccelerometer);
Dianne Hackborn2862fff2009-09-15 22:56:29 -07001421 mLidKeyboardAccessibility = mContext.getResources().getInteger(
1422 com.android.internal.R.integer.config_lidKeyboardAccessibility);
1423 mLidNavigationAccessibility = mContext.getResources().getInteger(
1424 com.android.internal.R.integer.config_lidNavigationAccessibility);
Edward Savage-Jones7def60d2015-11-13 13:27:03 +01001425 mLidControlsScreenLock = mContext.getResources().getBoolean(
1426 com.android.internal.R.bool.config_lidControlsScreenLock);
Jeff Brownc458ce92012-04-30 14:58:40 -07001427 mLidControlsSleep = mContext.getResources().getBoolean(
1428 com.android.internal.R.bool.config_lidControlsSleep);
Daniel Sandlerdd73ee42013-10-11 22:19:59 -04001429 mTranslucentDecorEnabled = mContext.getResources().getBoolean(
1430 com.android.internal.R.bool.config_enableTranslucentDecor);
Bryce Lee584a4452014-10-21 15:55:55 -07001431
1432 mAllowTheaterModeWakeFromKey = mContext.getResources().getBoolean(
1433 com.android.internal.R.bool.config_allowTheaterModeWakeFromKey);
1434 mAllowTheaterModeWakeFromPowerKey = mAllowTheaterModeWakeFromKey
1435 || mContext.getResources().getBoolean(
1436 com.android.internal.R.bool.config_allowTheaterModeWakeFromPowerKey);
1437 mAllowTheaterModeWakeFromMotion = mContext.getResources().getBoolean(
1438 com.android.internal.R.bool.config_allowTheaterModeWakeFromMotion);
Bryce Lee812d7022014-11-10 13:33:28 -08001439 mAllowTheaterModeWakeFromMotionWhenNotDreaming = mContext.getResources().getBoolean(
1440 com.android.internal.R.bool.config_allowTheaterModeWakeFromMotionWhenNotDreaming);
Bryce Lee584a4452014-10-21 15:55:55 -07001441 mAllowTheaterModeWakeFromCameraLens = mContext.getResources().getBoolean(
1442 com.android.internal.R.bool.config_allowTheaterModeWakeFromCameraLens);
1443 mAllowTheaterModeWakeFromLidSwitch = mContext.getResources().getBoolean(
1444 com.android.internal.R.bool.config_allowTheaterModeWakeFromLidSwitch);
1445 mAllowTheaterModeWakeFromWakeGesture = mContext.getResources().getBoolean(
1446 com.android.internal.R.bool.config_allowTheaterModeWakeFromGesture);
1447
Bryce Lee55e846d2014-11-04 12:43:44 -08001448 mGoToSleepOnButtonPressTheaterMode = mContext.getResources().getBoolean(
1449 com.android.internal.R.bool.config_goToSleepOnButtonPressTheaterMode);
1450
Bryce Leed3b28402015-03-09 15:49:13 +00001451 mSupportLongPressPowerWhenNonInteractive = mContext.getResources().getBoolean(
1452 com.android.internal.R.bool.config_supportLongPressPowerWhenNonInteractive);
1453
Jeff Brown13f00f02014-10-31 14:45:50 -07001454 mShortPressOnPowerBehavior = mContext.getResources().getInteger(
1455 com.android.internal.R.integer.config_shortPressOnPowerBehavior);
1456 mLongPressOnPowerBehavior = mContext.getResources().getInteger(
1457 com.android.internal.R.integer.config_longPressOnPowerBehavior);
1458 mDoublePressOnPowerBehavior = mContext.getResources().getInteger(
1459 com.android.internal.R.integer.config_doublePressOnPowerBehavior);
1460 mTriplePressOnPowerBehavior = mContext.getResources().getInteger(
1461 com.android.internal.R.integer.config_triplePressOnPowerBehavior);
Filip Gruszczynskia483a1d2015-03-17 19:06:58 +00001462 mShortPressOnSleepBehavior = mContext.getResources().getInteger(
1463 com.android.internal.R.integer.config_shortPressOnSleepBehavior);
Jeff Brown13f00f02014-10-31 14:45:50 -07001464
John Spurlock61560172015-02-06 19:46:04 -05001465 mUseTvRouting = AudioSystem.getPlatformType(mContext) == AudioSystem.PLATFORM_TELEVISION;
RoboErik001c59c2015-01-26 15:53:51 -08001466
Jeff Brownf71343d2013-05-31 17:59:11 -07001467 readConfigurationDependentBehaviors();
Jeff Browncaca8812013-05-09 13:34:33 -07001468
Svetoslav8e3feb12014-02-24 13:46:47 -08001469 mAccessibilityManager = (AccessibilityManager) context.getSystemService(
1470 Context.ACCESSIBILITY_SERVICE);
1471
Mike Lockwood1753f7f2009-08-24 14:49:07 -07001472 // register for dock events
Dianne Hackborn78968392010-03-04 20:47:56 -08001473 IntentFilter filter = new IntentFilter();
1474 filter.addAction(UiModeManager.ACTION_ENTER_CAR_MODE);
1475 filter.addAction(UiModeManager.ACTION_EXIT_CAR_MODE);
1476 filter.addAction(UiModeManager.ACTION_ENTER_DESK_MODE);
1477 filter.addAction(UiModeManager.ACTION_EXIT_DESK_MODE);
Dianne Hackborn867ab6472010-04-29 13:28:56 -07001478 filter.addAction(Intent.ACTION_DOCK_EVENT);
1479 Intent intent = context.registerReceiver(mDockReceiver, filter);
1480 if (intent != null) {
1481 // Retrieve current sticky dock event broadcast.
1482 mDockMode = intent.getIntExtra(Intent.EXTRA_DOCK_STATE,
1483 Intent.EXTRA_DOCK_STATE_UNDOCKED);
1484 }
Daniel Sandler7e37df52011-11-16 22:08:23 -08001485
Jeff Brown6aaf2952012-10-05 16:01:08 -07001486 // register for dream-related broadcasts
1487 filter = new IntentFilter();
1488 filter.addAction(Intent.ACTION_DREAMING_STARTED);
1489 filter.addAction(Intent.ACTION_DREAMING_STOPPED);
1490 context.registerReceiver(mDreamReceiver, filter);
1491
Christopher Tate5e08af02012-09-21 17:17:22 -07001492 // register for multiuser-relevant broadcasts
1493 filter = new IntentFilter(Intent.ACTION_USER_SWITCHED);
1494 context.registerReceiver(mMultiuserReceiver, filter);
1495
John Spurlock57306e62013-04-22 09:48:49 -04001496 // monitor for system gestures
Craig Mautner037aa8d2013-06-07 10:35:44 -07001497 mSystemGestures = new SystemGesturesPointerEventListener(context,
1498 new SystemGesturesPointerEventListener.Callbacks() {
John Spurlock57306e62013-04-22 09:48:49 -04001499 @Override
1500 public void onSwipeFromTop() {
John Spurlock04db1762013-05-13 12:46:41 -04001501 if (mStatusBar != null) {
John Spurlocke1f366f2013-08-05 12:22:40 -04001502 requestTransientBars(mStatusBar);
John Spurlock04db1762013-05-13 12:46:41 -04001503 }
John Spurlockad3e6cb2013-04-30 08:47:43 -04001504 }
1505 @Override
1506 public void onSwipeFromBottom() {
John Spurlock04db1762013-05-13 12:46:41 -04001507 if (mNavigationBar != null && mNavigationBarOnBottom) {
John Spurlocke1f366f2013-08-05 12:22:40 -04001508 requestTransientBars(mNavigationBar);
John Spurlockad3e6cb2013-04-30 08:47:43 -04001509 }
1510 }
1511 @Override
1512 public void onSwipeFromRight() {
John Spurlock04db1762013-05-13 12:46:41 -04001513 if (mNavigationBar != null && !mNavigationBarOnBottom) {
John Spurlocke1f366f2013-08-05 12:22:40 -04001514 requestTransientBars(mNavigationBar);
John Spurlockad3e6cb2013-04-30 08:47:43 -04001515 }
1516 }
1517 @Override
Michael Wrighta4d22d72015-09-16 23:19:26 +01001518 public void onFling(int duration) {
1519 if (mPowerManagerInternal != null) {
1520 mPowerManagerInternal.powerHint(
1521 PowerManagerInternal.POWER_HINT_INTERACTION, duration);
1522 }
1523 }
1524 @Override
John Spurlockad3e6cb2013-04-30 08:47:43 -04001525 public void onDebug() {
John Spurlockd67ec252013-09-05 11:31:54 -04001526 // no-op
John Spurlockad3e6cb2013-04-30 08:47:43 -04001527 }
Adrian Roos3595be42015-03-05 16:31:15 +01001528 @Override
1529 public void onDown() {
1530 mOrientationListener.onTouchStart();
1531 }
1532 @Override
1533 public void onUpOrCancel() {
1534 mOrientationListener.onTouchEnd();
1535 }
John Spurlockad3e6cb2013-04-30 08:47:43 -04001536 });
John Spurlockf1a36642013-10-12 17:50:42 -04001537 mImmersiveModeConfirmation = new ImmersiveModeConfirmation(mContext);
Craig Mautner037aa8d2013-06-07 10:35:44 -07001538 mWindowManagerFuncs.registerPointerEventListener(mSystemGestures);
John Spurlock32beb2c2013-03-11 10:16:47 -04001539
Jeff Brownc2346132012-04-13 01:55:38 -07001540 mVibrator = (Vibrator)context.getSystemService(Context.VIBRATOR_SERVICE);
Dianne Hackbornb1a79802009-09-29 15:18:31 -07001541 mLongPressVibePattern = getLongIntArray(mContext.getResources(),
1542 com.android.internal.R.array.config_longPressVibePattern);
1543 mVirtualKeyVibePattern = getLongIntArray(mContext.getResources(),
1544 com.android.internal.R.array.config_virtualKeyVibePattern);
Amith Yamasanic33cb712010-02-10 15:21:49 -08001545 mKeyboardTapVibePattern = getLongIntArray(mContext.getResources(),
1546 com.android.internal.R.array.config_keyboardTapVibePattern);
Fabrice Di Meglioeeff63a2013-08-05 12:07:24 -07001547 mClockTickVibePattern = getLongIntArray(mContext.getResources(),
1548 com.android.internal.R.array.config_clockTickVibePattern);
Fabrice Di Megliobd9152f2013-10-01 11:21:31 -07001549 mCalendarDateVibePattern = getLongIntArray(mContext.getResources(),
1550 com.android.internal.R.array.config_calendarDateVibePattern);
Dianne Hackbornb1a79802009-09-29 15:18:31 -07001551 mSafeModeDisabledVibePattern = getLongIntArray(mContext.getResources(),
1552 com.android.internal.R.array.config_safeModeDisabledVibePattern);
1553 mSafeModeEnabledVibePattern = getLongIntArray(mContext.getResources(),
1554 com.android.internal.R.array.config_safeModeEnabledVibePattern);
Mady Mellore8608912015-06-05 09:02:55 -07001555 mContextClickVibePattern = getLongIntArray(mContext.getResources(),
1556 com.android.internal.R.array.config_contextClickVibePattern);
Daniel Sandler40427442010-07-16 11:44:52 -04001557
Christopher Tatee90585f2012-03-05 18:56:25 -08001558 mScreenshotChordEnabled = mContext.getResources().getBoolean(
1559 com.android.internal.R.bool.config_enableScreenshotChord);
1560
Justin Kohd378ad72013-04-01 12:18:26 -07001561 mGlobalKeyManager = new GlobalKeyManager(mContext);
1562
Joe Onoratoea495d42011-04-06 11:41:11 -07001563 // Controls rotation and the like.
1564 initializeHdmiState();
Dianne Hackborn40011092011-09-22 13:37:48 -07001565
1566 // Match current screen state.
Craig Mautnera631d492014-08-05 15:16:01 -07001567 if (!mPowerManager.isInteractive()) {
Jeff Brown416c49c2015-05-26 19:50:18 -07001568 startedGoingToSleep(WindowManagerPolicy.OFF_BECAUSE_OF_USER);
1569 finishedGoingToSleep(WindowManagerPolicy.OFF_BECAUSE_OF_USER);
Dianne Hackborn40011092011-09-22 13:37:48 -07001570 }
Jorim Jaggi24bec7c2015-02-04 12:40:14 +01001571
1572 mWindowManagerInternal.registerAppTransitionListener(
1573 mStatusBarController.getAppTransitionListener());
Mike Lockwood1753f7f2009-08-24 14:49:07 -07001574 }
1575
Jeff Brownf71343d2013-05-31 17:59:11 -07001576 /**
1577 * Read values from config.xml that may be overridden depending on
1578 * the configuration of the device.
1579 * eg. Disable long press on home goes to recents on sw600dp.
1580 */
1581 private void readConfigurationDependentBehaviors() {
1582 mLongPressOnHomeBehavior = mContext.getResources().getInteger(
1583 com.android.internal.R.integer.config_longPressOnHomeBehavior);
1584 if (mLongPressOnHomeBehavior < LONG_PRESS_HOME_NOTHING ||
1585 mLongPressOnHomeBehavior > LONG_PRESS_HOME_ASSIST) {
1586 mLongPressOnHomeBehavior = LONG_PRESS_HOME_NOTHING;
1587 }
1588
1589 mDoubleTapOnHomeBehavior = mContext.getResources().getInteger(
1590 com.android.internal.R.integer.config_doubleTapOnHomeBehavior);
1591 if (mDoubleTapOnHomeBehavior < DOUBLE_TAP_HOME_NOTHING ||
1592 mDoubleTapOnHomeBehavior > DOUBLE_TAP_HOME_RECENT_SYSTEM_UI) {
1593 mDoubleTapOnHomeBehavior = LONG_PRESS_HOME_NOTHING;
1594 }
1595 }
1596
Craig Mautner0bf6ec92012-12-18 08:33:27 -08001597 @Override
Dianne Hackborndde331c2012-08-03 14:01:57 -07001598 public void setInitialDisplaySize(Display display, int width, int height, int density) {
Jeff Brownef981a42013-08-07 14:13:37 -07001599 // This method might be called before the policy has been fully initialized
1600 // or for other displays we don't care about.
1601 if (mContext == null || display.getDisplayId() != Display.DEFAULT_DISPLAY) {
1602 return;
Dianne Hackbornc652de82013-02-15 16:32:56 -08001603 }
Dianne Hackbornf87d1962012-04-04 12:48:24 -07001604 mDisplay = display;
1605
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001606 final Resources res = mContext.getResources();
Dianne Hackbornf87d1962012-04-04 12:48:24 -07001607 int shortSize, longSize;
Dianne Hackborn9d132642011-04-21 17:26:39 -07001608 if (width > height) {
Dianne Hackborn81e56d52011-05-26 00:55:58 -07001609 shortSize = height;
Dianne Hackbornf87d1962012-04-04 12:48:24 -07001610 longSize = width;
Dianne Hackborn9d132642011-04-21 17:26:39 -07001611 mLandscapeRotation = Surface.ROTATION_0;
1612 mSeascapeRotation = Surface.ROTATION_180;
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001613 if (res.getBoolean(com.android.internal.R.bool.config_reverseDefaultRotation)) {
Dianne Hackborn9d132642011-04-21 17:26:39 -07001614 mPortraitRotation = Surface.ROTATION_90;
1615 mUpsideDownRotation = Surface.ROTATION_270;
1616 } else {
1617 mPortraitRotation = Surface.ROTATION_270;
1618 mUpsideDownRotation = Surface.ROTATION_90;
1619 }
1620 } else {
Dianne Hackborn81e56d52011-05-26 00:55:58 -07001621 shortSize = width;
Dianne Hackbornf87d1962012-04-04 12:48:24 -07001622 longSize = height;
Dianne Hackborn9d132642011-04-21 17:26:39 -07001623 mPortraitRotation = Surface.ROTATION_0;
1624 mUpsideDownRotation = Surface.ROTATION_180;
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001625 if (res.getBoolean(com.android.internal.R.bool.config_reverseDefaultRotation)) {
Dianne Hackborn9d132642011-04-21 17:26:39 -07001626 mLandscapeRotation = Surface.ROTATION_270;
1627 mSeascapeRotation = Surface.ROTATION_90;
1628 } else {
1629 mLandscapeRotation = Surface.ROTATION_90;
1630 mSeascapeRotation = Surface.ROTATION_270;
1631 }
1632 }
Dianne Hackborn81e56d52011-05-26 00:55:58 -07001633
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001634 mStatusBarHeight =
1635 res.getDimensionPixelSize(com.android.internal.R.dimen.status_bar_height);
Dianne Hackbornf87d1962012-04-04 12:48:24 -07001636
Daniel Sandler9f65c4c2012-04-26 01:35:35 -04001637 // Height of the navigation bar when presented horizontally at bottom
1638 mNavigationBarHeightForRotation[mPortraitRotation] =
1639 mNavigationBarHeightForRotation[mUpsideDownRotation] =
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001640 res.getDimensionPixelSize(com.android.internal.R.dimen.navigation_bar_height);
Daniel Sandler9f65c4c2012-04-26 01:35:35 -04001641 mNavigationBarHeightForRotation[mLandscapeRotation] =
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001642 mNavigationBarHeightForRotation[mSeascapeRotation] = res.getDimensionPixelSize(
1643 com.android.internal.R.dimen.navigation_bar_height_landscape);
Daniel Sandler9f65c4c2012-04-26 01:35:35 -04001644
1645 // Width of the navigation bar when presented vertically along one side
1646 mNavigationBarWidthForRotation[mPortraitRotation] =
1647 mNavigationBarWidthForRotation[mUpsideDownRotation] =
1648 mNavigationBarWidthForRotation[mLandscapeRotation] =
1649 mNavigationBarWidthForRotation[mSeascapeRotation] =
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001650 res.getDimensionPixelSize(com.android.internal.R.dimen.navigation_bar_width);
Daniel Sandler4a066c52012-04-20 14:49:13 -04001651
1652 // SystemUI (status bar) layout policy
Dianne Hackborndde331c2012-08-03 14:01:57 -07001653 int shortSizeDp = shortSize * DisplayMetrics.DENSITY_DEFAULT / density;
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001654 int longSizeDp = longSize * DisplayMetrics.DENSITY_DEFAULT / density;
Daniel Sandler4a066c52012-04-20 14:49:13 -04001655
Devin Kimd7b12b42014-05-05 14:34:58 -07001656 // Allow the navigation bar to move on non-square small devices (phones).
1657 mNavigationBarCanMove = width != height && shortSizeDp < 600;
Daniel Sandler36412a72011-08-04 09:35:13 -04001658
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001659 mHasNavigationBar = res.getBoolean(com.android.internal.R.bool.config_showNavigationBar);
John Spurlock80f00c12013-06-13 11:10:51 -04001660 // Allow a system property to override this. Used by the emulator.
1661 // See also hasNavigationBar().
1662 String navBarOverride = SystemProperties.get("qemu.hw.mainkeys");
1663 if ("1".equals(navBarOverride)) {
Dianne Hackbornf87d1962012-04-04 12:48:24 -07001664 mHasNavigationBar = false;
John Spurlock80f00c12013-06-13 11:10:51 -04001665 } else if ("0".equals(navBarOverride)) {
1666 mHasNavigationBar = true;
Daniel Sandler0c4ccff2011-10-19 16:39:14 -04001667 }
1668
Jeff Brown27f1d672012-10-17 18:32:34 -07001669 // For demo purposes, allow the rotation of the HDMI display to be controlled.
1670 // By default, HDMI locks rotation to landscape.
Erik Gilling9a41ef82011-09-26 19:21:03 -07001671 if ("portrait".equals(SystemProperties.get("persist.demo.hdmirotation"))) {
Jeff Brownc82c89ed2013-04-17 17:18:15 -07001672 mDemoHdmiRotation = mPortraitRotation;
Erik Gilling9a41ef82011-09-26 19:21:03 -07001673 } else {
Jeff Brownc82c89ed2013-04-17 17:18:15 -07001674 mDemoHdmiRotation = mLandscapeRotation;
Erik Gilling9a41ef82011-09-26 19:21:03 -07001675 }
Jeff Brownc82c89ed2013-04-17 17:18:15 -07001676 mDemoHdmiRotationLock = SystemProperties.getBoolean("persist.demo.hdmirotationlock", false);
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001677
Chong Zhangae6119ff2014-11-11 18:54:39 -08001678 // For demo purposes, allow the rotation of the remote display to be controlled.
1679 // By default, remote display locks rotation to landscape.
1680 if ("portrait".equals(SystemProperties.get("persist.demo.remoterotation"))) {
1681 mDemoRotation = mPortraitRotation;
1682 } else {
1683 mDemoRotation = mLandscapeRotation;
1684 }
1685 mDemoRotationLock = SystemProperties.getBoolean(
1686 "persist.demo.rotationlock", false);
1687
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001688 // Only force the default orientation if the screen is xlarge, at least 960dp x 720dp, per
1689 // http://developer.android.com/guide/practices/screens_support.html#range
1690 mForceDefaultOrientation = longSizeDp >= 960 && shortSizeDp >= 720 &&
1691 res.getBoolean(com.android.internal.R.bool.config_forceDefaultOrientation) &&
1692 // For debug purposes the next line turns this feature off with:
1693 // $ adb shell setprop config.override_forced_orient true
1694 // $ adb shell wm size reset
1695 !"true".equals(SystemProperties.get("config.override_forced_orient"));
1696 }
1697
Alan Viverette5a0f4ec2013-10-07 15:10:29 -07001698 /**
1699 * @return whether the navigation bar can be hidden, e.g. the device has a
1700 * navigation bar and touch exploration is not enabled
1701 */
1702 private boolean canHideNavigationBar() {
Svetoslav8e3feb12014-02-24 13:46:47 -08001703 return mHasNavigationBar
1704 && !mAccessibilityManager.isTouchExplorationEnabled();
Alan Viverette5a0f4ec2013-10-07 15:10:29 -07001705 }
1706
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001707 @Override
1708 public boolean isDefaultOrientationForced() {
1709 return mForceDefaultOrientation;
Dianne Hackborn9d132642011-04-21 17:26:39 -07001710 }
1711
Dianne Hackbornc652de82013-02-15 16:32:56 -08001712 @Override
1713 public void setDisplayOverscan(Display display, int left, int top, int right, int bottom) {
1714 if (display.getDisplayId() == Display.DEFAULT_DISPLAY) {
1715 mOverscanLeft = left;
1716 mOverscanTop = top;
1717 mOverscanRight = right;
1718 mOverscanBottom = bottom;
1719 }
1720 }
1721
Dianne Hackbornc777e072010-02-12 13:07:59 -08001722 public void updateSettings() {
1723 ContentResolver resolver = mContext.getContentResolver();
1724 boolean updateRotation = false;
Dianne Hackbornc777e072010-02-12 13:07:59 -08001725 synchronized (mLock) {
Christopher Tate5e08af02012-09-21 17:17:22 -07001726 mEndcallBehavior = Settings.System.getIntForUser(resolver,
David Brownbaf8d092010-03-08 21:52:59 -08001727 Settings.System.END_BUTTON_BEHAVIOR,
Christopher Tate5e08af02012-09-21 17:17:22 -07001728 Settings.System.END_BUTTON_BEHAVIOR_DEFAULT,
1729 UserHandle.USER_CURRENT);
1730 mIncallPowerBehavior = Settings.Secure.getIntForUser(resolver,
David Brownbaf8d092010-03-08 21:52:59 -08001731 Settings.Secure.INCALL_POWER_BUTTON_BEHAVIOR,
Christopher Tate5e08af02012-09-21 17:17:22 -07001732 Settings.Secure.INCALL_POWER_BUTTON_BEHAVIOR_DEFAULT,
1733 UserHandle.USER_CURRENT);
Daniel Sandlerb73617d2010-08-17 00:41:00 -04001734
Jeff Browna20dda42014-05-27 20:57:24 -07001735 // Configure wake gesture.
1736 boolean wakeGestureEnabledSetting = Settings.Secure.getIntForUser(resolver,
1737 Settings.Secure.WAKE_GESTURE_ENABLED, 0,
1738 UserHandle.USER_CURRENT) != 0;
1739 if (mWakeGestureEnabledSetting != wakeGestureEnabledSetting) {
1740 mWakeGestureEnabledSetting = wakeGestureEnabledSetting;
1741 updateWakeGestureListenerLp();
1742 }
1743
Jeff Brown207673cd2012-06-05 17:47:11 -07001744 // Configure rotation lock.
Christopher Tate5e08af02012-09-21 17:17:22 -07001745 int userRotation = Settings.System.getIntForUser(resolver,
1746 Settings.System.USER_ROTATION, Surface.ROTATION_0,
1747 UserHandle.USER_CURRENT);
Jeff Brown207673cd2012-06-05 17:47:11 -07001748 if (mUserRotation != userRotation) {
1749 mUserRotation = userRotation;
1750 updateRotation = true;
1751 }
Christopher Tate5e08af02012-09-21 17:17:22 -07001752 int userRotationMode = Settings.System.getIntForUser(resolver,
1753 Settings.System.ACCELEROMETER_ROTATION, 0, UserHandle.USER_CURRENT) != 0 ?
Jeff Brown207673cd2012-06-05 17:47:11 -07001754 WindowManagerPolicy.USER_ROTATION_FREE :
1755 WindowManagerPolicy.USER_ROTATION_LOCKED;
1756 if (mUserRotationMode != userRotationMode) {
1757 mUserRotationMode = userRotationMode;
1758 updateRotation = true;
Dianne Hackbornc777e072010-02-12 13:07:59 -08001759 updateOrientationListenerLp();
1760 }
Daniel Sandlerb73617d2010-08-17 00:41:00 -04001761
Dianne Hackbornc777e072010-02-12 13:07:59 -08001762 if (mSystemReady) {
Christopher Tate5e08af02012-09-21 17:17:22 -07001763 int pointerLocation = Settings.System.getIntForUser(resolver,
1764 Settings.System.POINTER_LOCATION, 0, UserHandle.USER_CURRENT);
Dianne Hackbornc777e072010-02-12 13:07:59 -08001765 if (mPointerLocationMode != pointerLocation) {
1766 mPointerLocationMode = pointerLocation;
Jeff Brown70825162012-03-28 17:27:48 -07001767 mHandler.sendEmptyMessage(pointerLocation != 0 ?
1768 MSG_ENABLE_POINTER_LOCATION : MSG_DISABLE_POINTER_LOCATION);
Dianne Hackbornc777e072010-02-12 13:07:59 -08001769 }
1770 }
1771 // use screen off timeout setting as the timeout for the lockscreen
Christopher Tate5e08af02012-09-21 17:17:22 -07001772 mLockScreenTimeout = Settings.System.getIntForUser(resolver,
1773 Settings.System.SCREEN_OFF_TIMEOUT, 0, UserHandle.USER_CURRENT);
1774 String imId = Settings.Secure.getStringForUser(resolver,
1775 Settings.Secure.DEFAULT_INPUT_METHOD, UserHandle.USER_CURRENT);
Dianne Hackbornc777e072010-02-12 13:07:59 -08001776 boolean hasSoftInput = imId != null && imId.length() > 0;
1777 if (mHasSoftInput != hasSoftInput) {
1778 mHasSoftInput = hasSoftInput;
1779 updateRotation = true;
1780 }
John Spurlockf1a36642013-10-12 17:50:42 -04001781 if (mImmersiveModeConfirmation != null) {
John Spurlock4355a532014-02-19 09:49:25 -05001782 mImmersiveModeConfirmation.loadSetting(mCurrentUserId);
John Spurlockd67ec252013-09-05 11:31:54 -04001783 }
tiger_huangcc6366d2015-06-29 17:17:30 +08001784 }
1785 synchronized (mWindowManagerFuncs.getWindowManagerLock()) {
John Spurlockc6d1c602014-01-17 15:22:06 -05001786 PolicyControl.reloadFromSetting(mContext);
Dianne Hackbornc777e072010-02-12 13:07:59 -08001787 }
1788 if (updateRotation) {
Jeff Brown01a98dd2011-09-20 15:08:29 -07001789 updateRotation(true);
Dianne Hackbornc777e072010-02-12 13:07:59 -08001790 }
Jeff Brown70825162012-03-28 17:27:48 -07001791 }
1792
Jeff Browna20dda42014-05-27 20:57:24 -07001793 private void updateWakeGestureListenerLp() {
1794 if (shouldEnableWakeGestureLp()) {
1795 mWakeGestureListener.requestWakeUpTrigger();
1796 } else {
1797 mWakeGestureListener.cancelWakeUpTrigger();
1798 }
1799 }
1800
1801 private boolean shouldEnableWakeGestureLp() {
Jeff Brown3ee549c2014-09-22 20:14:39 -07001802 return mWakeGestureEnabledSetting && !mAwake
Jeff Browna20dda42014-05-27 20:57:24 -07001803 && (!mLidControlsSleep || mLidState != LID_CLOSED)
1804 && mWakeGestureListener.isSupported();
1805 }
1806
Jeff Brown70825162012-03-28 17:27:48 -07001807 private void enablePointerLocation() {
1808 if (mPointerLocationView == null) {
1809 mPointerLocationView = new PointerLocationView(mContext);
1810 mPointerLocationView.setPrintCoords(false);
Dianne Hackbornc777e072010-02-12 13:07:59 -08001811 WindowManager.LayoutParams lp = new WindowManager.LayoutParams(
1812 WindowManager.LayoutParams.MATCH_PARENT,
1813 WindowManager.LayoutParams.MATCH_PARENT);
Jeff Brown3b2b3542010-10-15 00:54:27 -07001814 lp.type = WindowManager.LayoutParams.TYPE_SECURE_SYSTEM_OVERLAY;
Jeff Brownbfcb60a2011-09-08 18:51:14 -07001815 lp.flags = WindowManager.LayoutParams.FLAG_FULLSCREEN
1816 | WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE
1817 | WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE
1818 | WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN;
Jeff Brown90fc9052012-10-01 14:44:24 -07001819 if (ActivityManager.isHighEndGfx()) {
1820 lp.flags |= WindowManager.LayoutParams.FLAG_HARDWARE_ACCELERATED;
1821 lp.privateFlags |=
1822 WindowManager.LayoutParams.PRIVATE_FLAG_FORCE_HARDWARE_ACCELERATED;
1823 }
Dianne Hackbornc777e072010-02-12 13:07:59 -08001824 lp.format = PixelFormat.TRANSLUCENT;
1825 lp.setTitle("PointerLocation");
Dianne Hackborn5fd21692011-06-07 14:09:47 -07001826 WindowManager wm = (WindowManager)
Dianne Hackbornc777e072010-02-12 13:07:59 -08001827 mContext.getSystemService(Context.WINDOW_SERVICE);
Jeff Browncc4f7db2011-08-30 20:34:48 -07001828 lp.inputFeatures |= WindowManager.LayoutParams.INPUT_FEATURE_NO_INPUT_CHANNEL;
Jeff Brown70825162012-03-28 17:27:48 -07001829 wm.addView(mPointerLocationView, lp);
Michael Wrightc9c487e2013-11-07 18:55:09 -08001830 mWindowManagerFuncs.registerPointerEventListener(mPointerLocationView);
Dianne Hackbornc777e072010-02-12 13:07:59 -08001831 }
Dianne Hackbornc777e072010-02-12 13:07:59 -08001832 }
Jeff Brown70825162012-03-28 17:27:48 -07001833
1834 private void disablePointerLocation() {
Jeff Brown70825162012-03-28 17:27:48 -07001835 if (mPointerLocationView != null) {
Michael Wrightc9c487e2013-11-07 18:55:09 -08001836 mWindowManagerFuncs.unregisterPointerEventListener(mPointerLocationView);
1837 WindowManager wm = (WindowManager) mContext.getSystemService(Context.WINDOW_SERVICE);
Jeff Brown70825162012-03-28 17:27:48 -07001838 wm.removeView(mPointerLocationView);
1839 mPointerLocationView = null;
1840 }
1841 }
1842
Mike Lockwood2d1efbd2009-09-16 12:15:53 -04001843 private int readRotation(int resID) {
Mike Lockwood1753f7f2009-08-24 14:49:07 -07001844 try {
1845 int rotation = mContext.getResources().getInteger(resID);
1846 switch (rotation) {
1847 case 0:
1848 return Surface.ROTATION_0;
1849 case 90:
1850 return Surface.ROTATION_90;
1851 case 180:
1852 return Surface.ROTATION_180;
1853 case 270:
1854 return Surface.ROTATION_270;
Mike Lockwood1753f7f2009-08-24 14:49:07 -07001855 }
1856 } catch (Resources.NotFoundException e) {
Mike Lockwood2d1efbd2009-09-16 12:15:53 -04001857 // fall through
Mike Lockwood1753f7f2009-08-24 14:49:07 -07001858 }
Mike Lockwood2d1efbd2009-09-16 12:15:53 -04001859 return -1;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001860 }
1861
1862 /** {@inheritDoc} */
Craig Mautner88400d32012-09-30 12:35:45 -07001863 @Override
Dianne Hackbornc2293022013-02-06 23:14:49 -08001864 public int checkAddPermission(WindowManager.LayoutParams attrs, int[] outAppOp) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001865 int type = attrs.type;
Dianne Hackbornc2293022013-02-06 23:14:49 -08001866
1867 outAppOp[0] = AppOpsManager.OP_NONE;
1868
Wale Ogunwale74bf0652015-01-12 10:24:36 -08001869 if (!((type >= FIRST_APPLICATION_WINDOW && type <= LAST_APPLICATION_WINDOW)
1870 || (type >= FIRST_SUB_WINDOW && type <= LAST_SUB_WINDOW)
1871 || (type >= FIRST_SYSTEM_WINDOW && type <= LAST_SYSTEM_WINDOW))) {
1872 return WindowManagerGlobal.ADD_INVALID_TYPE;
1873 }
1874
1875 if (type < FIRST_SYSTEM_WINDOW || type > LAST_SYSTEM_WINDOW) {
1876 // Window manager will make sure these are okay.
Jeff Brown98365d72012-08-19 20:30:52 -07001877 return WindowManagerGlobal.ADD_OKAY;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001878 }
1879 String permission = null;
1880 switch (type) {
1881 case TYPE_TOAST:
1882 // XXX right now the app process has complete control over
1883 // this... should introduce a token to let the system
1884 // monitor/control what they are doing.
Jason Monk1c7c3192014-06-26 12:52:18 -04001885 outAppOp[0] = AppOpsManager.OP_TOAST_WINDOW;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001886 break;
Daniel Sandler7d276c32012-01-30 14:33:52 -05001887 case TYPE_DREAM:
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001888 case TYPE_INPUT_METHOD:
Dianne Hackbornb7cd8b92009-08-08 20:53:03 -07001889 case TYPE_WALLPAPER:
keunyounga446bf02013-06-21 19:07:57 -07001890 case TYPE_PRIVATE_PRESENTATION:
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001891 case TYPE_VOICE_INTERACTION:
Svetoslav3a5c7212014-10-14 09:54:26 -07001892 case TYPE_ACCESSIBILITY_OVERLAY:
Dianne Hackbornb7cd8b92009-08-08 20:53:03 -07001893 // The window manager will check these.
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001894 break;
1895 case TYPE_PHONE:
1896 case TYPE_PRIORITY_PHONE:
1897 case TYPE_SYSTEM_ALERT:
1898 case TYPE_SYSTEM_ERROR:
1899 case TYPE_SYSTEM_OVERLAY:
1900 permission = android.Manifest.permission.SYSTEM_ALERT_WINDOW;
Dianne Hackbornc2293022013-02-06 23:14:49 -08001901 outAppOp[0] = AppOpsManager.OP_SYSTEM_ALERT_WINDOW;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001902 break;
1903 default:
1904 permission = android.Manifest.permission.INTERNAL_SYSTEM_WINDOW;
1905 }
1906 if (permission != null) {
Billy Laucbe540f2015-06-25 01:51:44 +01001907 if (permission == android.Manifest.permission.SYSTEM_ALERT_WINDOW) {
1908 final int callingUid = Binder.getCallingUid();
Billy Lau060275f2015-07-15 22:29:19 +01001909 // system processes will be automatically allowed privilege to draw
Billy Laucbe540f2015-06-25 01:51:44 +01001910 if (callingUid == Process.SYSTEM_UID) {
1911 return WindowManagerGlobal.ADD_OKAY;
1912 }
1913
Billy Lau060275f2015-07-15 22:29:19 +01001914 // check if user has enabled this operation. SecurityException will be thrown if
1915 // this app has not been allowed by the user
Billy Laucbe540f2015-06-25 01:51:44 +01001916 final int mode = mAppOpsManager.checkOp(outAppOp[0], callingUid,
1917 attrs.packageName);
Billy Lau060275f2015-07-15 22:29:19 +01001918 switch (mode) {
1919 case AppOpsManager.MODE_ALLOWED:
1920 case AppOpsManager.MODE_IGNORED:
1921 // although we return ADD_OKAY for MODE_IGNORED, the added window will
1922 // actually be hidden in WindowManagerService
1923 return WindowManagerGlobal.ADD_OKAY;
1924 case AppOpsManager.MODE_ERRORED:
Billy Laucbe540f2015-06-25 01:51:44 +01001925 return WindowManagerGlobal.ADD_PERMISSION_DENIED;
Billy Lau060275f2015-07-15 22:29:19 +01001926 default:
1927 // in the default mode, we will make a decision here based on
1928 // checkCallingPermission()
1929 if (mContext.checkCallingPermission(permission) !=
1930 PackageManager.PERMISSION_GRANTED) {
1931 return WindowManagerGlobal.ADD_PERMISSION_DENIED;
1932 } else {
1933 return WindowManagerGlobal.ADD_OKAY;
1934 }
Billy Laucbe540f2015-06-25 01:51:44 +01001935 }
Billy Laucbe540f2015-06-25 01:51:44 +01001936 }
1937
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001938 if (mContext.checkCallingOrSelfPermission(permission)
1939 != PackageManager.PERMISSION_GRANTED) {
Jeff Brown98365d72012-08-19 20:30:52 -07001940 return WindowManagerGlobal.ADD_PERMISSION_DENIED;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001941 }
1942 }
Jeff Brown98365d72012-08-19 20:30:52 -07001943 return WindowManagerGlobal.ADD_OKAY;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001944 }
Craig Mautner88400d32012-09-30 12:35:45 -07001945
1946 @Override
1947 public boolean checkShowToOwnerOnly(WindowManager.LayoutParams attrs) {
1948
1949 // If this switch statement is modified, modify the comment in the declarations of
1950 // the type in {@link WindowManager.LayoutParams} as well.
1951 switch (attrs.type) {
1952 default:
1953 // These are the windows that by default are shown only to the user that created
1954 // them. If this needs to be overridden, set
1955 // {@link WindowManager.LayoutParams.PRIVATE_FLAG_SHOW_FOR_ALL_USERS} in
1956 // {@link WindowManager.LayoutParams}. Note that permission
1957 // {@link android.Manifest.permission.INTERNAL_SYSTEM_WINDOW} is required as well.
1958 if ((attrs.privateFlags & PRIVATE_FLAG_SHOW_FOR_ALL_USERS) == 0) {
1959 return true;
1960 }
1961 break;
1962
1963 // These are the windows that by default are shown to all users. However, to
1964 // protect against spoofing, check permissions below.
1965 case TYPE_APPLICATION_STARTING:
1966 case TYPE_BOOT_PROGRESS:
1967 case TYPE_DISPLAY_OVERLAY:
Selim Cinekf83e8242015-05-19 18:08:14 -07001968 case TYPE_INPUT_CONSUMER:
Jim Miller5ecd8112013-01-09 18:50:26 -08001969 case TYPE_KEYGUARD_SCRIM:
Craig Mautner88400d32012-09-30 12:35:45 -07001970 case TYPE_KEYGUARD_DIALOG:
1971 case TYPE_MAGNIFICATION_OVERLAY:
1972 case TYPE_NAVIGATION_BAR:
1973 case TYPE_NAVIGATION_BAR_PANEL:
1974 case TYPE_PHONE:
1975 case TYPE_POINTER:
1976 case TYPE_PRIORITY_PHONE:
Craig Mautner88400d32012-09-30 12:35:45 -07001977 case TYPE_SEARCH_BAR:
1978 case TYPE_STATUS_BAR:
1979 case TYPE_STATUS_BAR_PANEL:
1980 case TYPE_STATUS_BAR_SUB_PANEL:
1981 case TYPE_SYSTEM_DIALOG:
Craig Mautner88400d32012-09-30 12:35:45 -07001982 case TYPE_VOLUME_OVERLAY:
keunyounga446bf02013-06-21 19:07:57 -07001983 case TYPE_PRIVATE_PRESENTATION:
Craig Mautner88400d32012-09-30 12:35:45 -07001984 break;
1985 }
1986
1987 // Check if third party app has set window to system window type.
1988 return mContext.checkCallingOrSelfPermission(
1989 android.Manifest.permission.INTERNAL_SYSTEM_WINDOW)
1990 != PackageManager.PERMISSION_GRANTED;
1991 }
1992
Craig Mautner967212c2013-04-13 21:10:58 -07001993 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001994 public void adjustWindowParamsLw(WindowManager.LayoutParams attrs) {
1995 switch (attrs.type) {
1996 case TYPE_SYSTEM_OVERLAY:
Jeff Brown3b2b3542010-10-15 00:54:27 -07001997 case TYPE_SECURE_SYSTEM_OVERLAY:
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001998 // These types of windows can't receive input events.
1999 attrs.flags |= WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE
2000 | WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE;
Jeff Brownbfcb60a2011-09-08 18:51:14 -07002001 attrs.flags &= ~WindowManager.LayoutParams.FLAG_WATCH_OUTSIDE_TOUCH;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002002 break;
Jorim Jaggi380ecb82014-03-14 17:25:20 +01002003 case TYPE_STATUS_BAR:
2004
2005 // If the Keyguard is in a hidden state (occluded by another window), we force to
2006 // remove the wallpaper and keyguard flag so that any change in-flight after setting
2007 // the keyguard as occluded wouldn't set these flags again.
2008 // See {@link #processKeyguardSetHiddenResultLw}.
2009 if (mKeyguardHidden) {
2010 attrs.flags &= ~WindowManager.LayoutParams.FLAG_SHOW_WALLPAPER;
2011 attrs.privateFlags &= ~WindowManager.LayoutParams.PRIVATE_FLAG_KEYGUARD;
2012 }
2013 break;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002014 }
Adrian Roos38502112014-04-09 21:04:11 +02002015
2016 if (attrs.type != TYPE_STATUS_BAR) {
2017 // The status bar is the only window allowed to exhibit keyguard behavior.
2018 attrs.privateFlags &= ~WindowManager.LayoutParams.PRIVATE_FLAG_KEYGUARD;
2019 }
Adrian Roosea562512014-05-05 13:33:03 +02002020
2021 if (ActivityManager.isHighEndGfx()
2022 && (attrs.flags & FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS) != 0) {
Adrian Roosf5e9b5c2014-09-10 15:27:41 +02002023 attrs.subtreeSystemUiVisibility |= View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
Adrian Roosea562512014-05-05 13:33:03 +02002024 | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION;
2025 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002026 }
RoboErik8a2cfc32014-05-16 11:19:38 -07002027
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002028 void readLidState() {
Jeff Brown2e7760e2012-04-11 15:14:55 -07002029 mLidState = mWindowManagerFuncs.getLidState();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002030 }
RoboErik8a2cfc32014-05-16 11:19:38 -07002031
Michael Wright3818c922014-09-02 13:59:07 -07002032 private void readCameraLensCoverState() {
2033 mCameraLensCoverState = mWindowManagerFuncs.getCameraLensCoverState();
2034 }
2035
Jeff Browndaa37532012-05-01 15:54:03 -07002036 private boolean isHidden(int accessibilityMode) {
2037 switch (accessibilityMode) {
2038 case 1:
2039 return mLidState == LID_CLOSED;
2040 case 2:
2041 return mLidState == LID_OPEN;
2042 default:
2043 return false;
Dianne Hackborn2862fff2009-09-15 22:56:29 -07002044 }
Dianne Hackborn2862fff2009-09-15 22:56:29 -07002045 }
Jeff Brownd04a88c2011-01-16 14:05:47 -08002046
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002047 /** {@inheritDoc} */
Craig Mautner967212c2013-04-13 21:10:58 -07002048 @Override
Jeff Browndaa37532012-05-01 15:54:03 -07002049 public void adjustConfigurationLw(Configuration config, int keyboardPresence,
2050 int navigationPresence) {
2051 mHaveBuiltInKeyboard = (keyboardPresence & PRESENCE_INTERNAL) != 0;
2052
Jeff Brownf71343d2013-05-31 17:59:11 -07002053 readConfigurationDependentBehaviors();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002054 readLidState();
Jeff Brownc458ce92012-04-30 14:58:40 -07002055 applyLidSwitchState();
Jeff Brownd04a88c2011-01-16 14:05:47 -08002056
Jeff Browndaa37532012-05-01 15:54:03 -07002057 if (config.keyboard == Configuration.KEYBOARD_NOKEYS
2058 || (keyboardPresence == PRESENCE_INTERNAL
2059 && isHidden(mLidKeyboardAccessibility))) {
Jeff Brownd04a88c2011-01-16 14:05:47 -08002060 config.hardKeyboardHidden = Configuration.HARDKEYBOARDHIDDEN_YES;
Jeff Browndaa37532012-05-01 15:54:03 -07002061 if (!mHasSoftInput) {
2062 config.keyboardHidden = Configuration.KEYBOARDHIDDEN_YES;
2063 }
Jeff Brownd04a88c2011-01-16 14:05:47 -08002064 }
2065
Jeff Browndaa37532012-05-01 15:54:03 -07002066 if (config.navigation == Configuration.NAVIGATION_NONAV
2067 || (navigationPresence == PRESENCE_INTERNAL
2068 && isHidden(mLidNavigationAccessibility))) {
Jeff Brownd04a88c2011-01-16 14:05:47 -08002069 config.navigationHidden = Configuration.NAVIGATIONHIDDEN_YES;
Jeff Brownd04a88c2011-01-16 14:05:47 -08002070 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002071 }
Jeff Brownd04a88c2011-01-16 14:05:47 -08002072
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002073 /** {@inheritDoc} */
Craig Mautner967212c2013-04-13 21:10:58 -07002074 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002075 public int windowTypeToLayerLw(int type) {
2076 if (type >= FIRST_APPLICATION_WINDOW && type <= LAST_APPLICATION_WINDOW) {
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07002077 return 2;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002078 }
2079 switch (type) {
keunyounga446bf02013-06-21 19:07:57 -07002080 case TYPE_PRIVATE_PRESENTATION:
2081 return 2;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07002082 case TYPE_WALLPAPER:
2083 // wallpaper is at the bottom, though the window manager may move it.
2084 return 2;
2085 case TYPE_PHONE:
2086 return 3;
2087 case TYPE_SEARCH_BAR:
Jorim Jaggi225d3b52015-04-01 11:18:57 -07002088 case TYPE_VOICE_INTERACTION_STARTING:
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07002089 return 4;
Dianne Hackborne30e02f2014-05-27 18:24:45 -07002090 case TYPE_VOICE_INTERACTION:
2091 // voice interaction layer is almost immediately above apps.
2092 return 5;
Selim Cinekf83e8242015-05-19 18:08:14 -07002093 case TYPE_INPUT_CONSUMER:
Dianne Hackborne30e02f2014-05-27 18:24:45 -07002094 return 6;
Selim Cinekf83e8242015-05-19 18:08:14 -07002095 case TYPE_SYSTEM_DIALOG:
2096 return 7;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07002097 case TYPE_TOAST:
2098 // toasts and the plugged-in battery thing
Selim Cinekf83e8242015-05-19 18:08:14 -07002099 return 8;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07002100 case TYPE_PRIORITY_PHONE:
2101 // SIM errors and unlock. Not sure if this really should be in a high layer.
Selim Cinekf83e8242015-05-19 18:08:14 -07002102 return 9;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07002103 case TYPE_DREAM:
2104 // used for Dreams (screensavers with TYPE_DREAM windows)
Selim Cinekf83e8242015-05-19 18:08:14 -07002105 return 10;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07002106 case TYPE_SYSTEM_ALERT:
2107 // like the ANR / app crashed dialogs
Selim Cinekf83e8242015-05-19 18:08:14 -07002108 return 11;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07002109 case TYPE_INPUT_METHOD:
2110 // on-screen keyboards and other such input method user interfaces go here.
Selim Cinekf83e8242015-05-19 18:08:14 -07002111 return 12;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07002112 case TYPE_INPUT_METHOD_DIALOG:
2113 // on-screen keyboards and other such input method user interfaces go here.
Selim Cinekf83e8242015-05-19 18:08:14 -07002114 return 13;
Jim Miller5ecd8112013-01-09 18:50:26 -08002115 case TYPE_KEYGUARD_SCRIM:
2116 // the safety window that shows behind keyguard while keyguard is starting
Jorim Jaggi380ecb82014-03-14 17:25:20 +01002117 return 14;
Selim Cinekf83e8242015-05-19 18:08:14 -07002118 case TYPE_STATUS_BAR_SUB_PANEL:
Jorim Jaggi380ecb82014-03-14 17:25:20 +01002119 return 15;
Selim Cinekf83e8242015-05-19 18:08:14 -07002120 case TYPE_STATUS_BAR:
Jorim Jaggi380ecb82014-03-14 17:25:20 +01002121 return 16;
Selim Cinekf83e8242015-05-19 18:08:14 -07002122 case TYPE_STATUS_BAR_PANEL:
Dianne Hackborne30e02f2014-05-27 18:24:45 -07002123 return 17;
Selim Cinekf83e8242015-05-19 18:08:14 -07002124 case TYPE_KEYGUARD_DIALOG:
2125 return 18;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07002126 case TYPE_VOLUME_OVERLAY:
2127 // the on-screen volume indicator and controller shown when the user
2128 // changes the device volume
Selim Cinekf83e8242015-05-19 18:08:14 -07002129 return 19;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07002130 case TYPE_SYSTEM_OVERLAY:
2131 // the on-screen volume indicator and controller shown when the user
2132 // changes the device volume
Selim Cinekf83e8242015-05-19 18:08:14 -07002133 return 20;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07002134 case TYPE_NAVIGATION_BAR:
2135 // the navigation bar, if available, shows atop most things
Selim Cinekf83e8242015-05-19 18:08:14 -07002136 return 21;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07002137 case TYPE_NAVIGATION_BAR_PANEL:
2138 // some panels (e.g. search) need to show on top of the navigation bar
Selim Cinekf83e8242015-05-19 18:08:14 -07002139 return 22;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07002140 case TYPE_SYSTEM_ERROR:
2141 // system-level error dialogs
Selim Cinekf83e8242015-05-19 18:08:14 -07002142 return 23;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07002143 case TYPE_MAGNIFICATION_OVERLAY:
2144 // used to highlight the magnified portion of a display
Selim Cinekf83e8242015-05-19 18:08:14 -07002145 return 24;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07002146 case TYPE_DISPLAY_OVERLAY:
2147 // used to simulate secondary display devices
Selim Cinekf83e8242015-05-19 18:08:14 -07002148 return 25;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07002149 case TYPE_DRAG:
2150 // the drag layer: input for drag-and-drop is associated with this window,
2151 // which sits above all other focusable windows
Selim Cinekf83e8242015-05-19 18:08:14 -07002152 return 26;
Svetoslav3a5c7212014-10-14 09:54:26 -07002153 case TYPE_ACCESSIBILITY_OVERLAY:
2154 // overlay put by accessibility services to intercept user interaction
Dianne Hackborne30e02f2014-05-27 18:24:45 -07002155 return 27;
Selim Cinekf83e8242015-05-19 18:08:14 -07002156 case TYPE_SECURE_SYSTEM_OVERLAY:
Svetoslav3a5c7212014-10-14 09:54:26 -07002157 return 28;
Selim Cinekf83e8242015-05-19 18:08:14 -07002158 case TYPE_BOOT_PROGRESS:
2159 return 29;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07002160 case TYPE_POINTER:
2161 // the (mouse) pointer layer
Svetoslav3a5c7212014-10-14 09:54:26 -07002162 return 30;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002163 }
2164 Log.e(TAG, "Unknown window type: " + type);
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07002165 return 2;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002166 }
2167
2168 /** {@inheritDoc} */
Craig Mautner46ac6fa2013-08-01 10:06:34 -07002169 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002170 public int subWindowTypeToLayerLw(int type) {
2171 switch (type) {
2172 case TYPE_APPLICATION_PANEL:
2173 case TYPE_APPLICATION_ATTACHED_DIALOG:
2174 return APPLICATION_PANEL_SUBLAYER;
2175 case TYPE_APPLICATION_MEDIA:
2176 return APPLICATION_MEDIA_SUBLAYER;
Dianne Hackborn5cb8d792009-05-21 17:34:15 -07002177 case TYPE_APPLICATION_MEDIA_OVERLAY:
2178 return APPLICATION_MEDIA_OVERLAY_SUBLAYER;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002179 case TYPE_APPLICATION_SUB_PANEL:
2180 return APPLICATION_SUB_PANEL_SUBLAYER;
Wale Ogunwale0a4dc222015-04-14 12:58:42 -07002181 case TYPE_APPLICATION_ABOVE_SUB_PANEL:
2182 return APPLICATION_ABOVE_SUB_PANEL_SUBLAYER;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002183 }
2184 Log.e(TAG, "Unknown sub-window type: " + type);
2185 return 0;
2186 }
2187
Craig Mautner46ac6fa2013-08-01 10:06:34 -07002188 @Override
Dianne Hackbornabe0da02009-09-18 01:55:39 -07002189 public int getMaxWallpaperLayer() {
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07002190 return windowTypeToLayerLw(TYPE_STATUS_BAR);
Dianne Hackbornabe0da02009-09-18 01:55:39 -07002191 }
2192
Craig Mautner46ac6fa2013-08-01 10:06:34 -07002193 @Override
Dianne Hackborn1f903c32011-09-13 19:18:06 -07002194 public int getNonDecorDisplayWidth(int fullWidth, int fullHeight, int rotation) {
Dianne Hackborn077ee852012-04-09 16:27:07 -07002195 if (mHasNavigationBar) {
2196 // For a basic navigation bar, when we are in landscape mode we place
2197 // the navigation bar to the side.
Daniel Sandler4a066c52012-04-20 14:49:13 -04002198 if (mNavigationBarCanMove && fullWidth > fullHeight) {
2199 return fullWidth - mNavigationBarWidthForRotation[rotation];
Dianne Hackborn077ee852012-04-09 16:27:07 -07002200 }
Dianne Hackborn1f903c32011-09-13 19:18:06 -07002201 }
2202 return fullWidth;
Dianne Hackborne2515ee2011-04-27 18:52:56 -04002203 }
2204
Jose Lima9546b202014-07-02 17:21:51 -07002205 @Override
Dianne Hackborn1f903c32011-09-13 19:18:06 -07002206 public int getNonDecorDisplayHeight(int fullWidth, int fullHeight, int rotation) {
Dianne Hackborn077ee852012-04-09 16:27:07 -07002207 if (mHasNavigationBar) {
2208 // For a basic navigation bar, when we are in portrait mode we place
2209 // the navigation bar to the bottom.
Daniel Sandler4a066c52012-04-20 14:49:13 -04002210 if (!mNavigationBarCanMove || fullWidth < fullHeight) {
2211 return fullHeight - mNavigationBarHeightForRotation[rotation];
Dianne Hackborn077ee852012-04-09 16:27:07 -07002212 }
2213 }
2214 return fullHeight;
Dianne Hackborn69cb8752011-05-19 18:13:32 -07002215 }
2216
Jose Lima9546b202014-07-02 17:21:51 -07002217 @Override
Dianne Hackborn1f903c32011-09-13 19:18:06 -07002218 public int getConfigDisplayWidth(int fullWidth, int fullHeight, int rotation) {
2219 return getNonDecorDisplayWidth(fullWidth, fullHeight, rotation);
Dianne Hackborn69cb8752011-05-19 18:13:32 -07002220 }
2221
Jose Lima9546b202014-07-02 17:21:51 -07002222 @Override
Dianne Hackborn1f903c32011-09-13 19:18:06 -07002223 public int getConfigDisplayHeight(int fullWidth, int fullHeight, int rotation) {
John Spurlock80f00c12013-06-13 11:10:51 -04002224 // There is a separate status bar at the top of the display. We don't count that as part
2225 // of the fixed decor, since it can hide; however, for purposes of configurations,
Dianne Hackborn077ee852012-04-09 16:27:07 -07002226 // we do want to exclude it since applications can't generally use that part
2227 // of the screen.
John Spurlock80f00c12013-06-13 11:10:51 -04002228 return getNonDecorDisplayHeight(fullWidth, fullHeight, rotation) - mStatusBarHeight;
Dianne Hackborne2515ee2011-04-27 18:52:56 -04002229 }
2230
Craig Mautnera3f4bf52012-10-10 20:37:48 -07002231 @Override
Craig Mautnerc9457fa2014-06-06 14:27:48 -07002232 public boolean isForceHiding(WindowManager.LayoutParams attrs) {
2233 return (attrs.privateFlags & PRIVATE_FLAG_KEYGUARD) != 0 ||
Jim Millerab954542014-10-10 18:21:49 -07002234 (isKeyguardHostWindow(attrs) &&
2235 (mKeyguardDelegate != null && mKeyguardDelegate.isShowing())) ||
Adrian Roos69e510d2014-07-13 14:57:59 +02002236 (attrs.type == TYPE_KEYGUARD_SCRIM);
Dianne Hackborn01ad2f42009-09-24 19:24:56 -07002237 }
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07002238
Craig Mautnera3f4bf52012-10-10 20:37:48 -07002239 @Override
Jorim Jaggi0d674622014-05-21 01:34:15 +02002240 public boolean isKeyguardHostWindow(WindowManager.LayoutParams attrs) {
2241 return attrs.type == TYPE_STATUS_BAR;
2242 }
2243
2244 @Override
Dianne Hackborn01ad2f42009-09-24 19:24:56 -07002245 public boolean canBeForceHidden(WindowState win, WindowManager.LayoutParams attrs) {
Craig Mautnera3f4bf52012-10-10 20:37:48 -07002246 switch (attrs.type) {
2247 case TYPE_STATUS_BAR:
2248 case TYPE_NAVIGATION_BAR:
2249 case TYPE_WALLPAPER:
2250 case TYPE_DREAM:
Jim Miller5ecd8112013-01-09 18:50:26 -08002251 case TYPE_KEYGUARD_SCRIM:
Craig Mautnera3f4bf52012-10-10 20:37:48 -07002252 return false;
2253 default:
Adrian Roos461829d2015-06-03 14:41:18 -07002254 // Hide only windows below the keyguard host window.
2255 return windowTypeToLayerLw(win.getBaseType())
2256 < windowTypeToLayerLw(TYPE_STATUS_BAR);
Craig Mautnera3f4bf52012-10-10 20:37:48 -07002257 }
Dianne Hackborn01ad2f42009-09-24 19:24:56 -07002258 }
Craig Mautner8e4df6c2012-05-23 16:57:23 -07002259
Craig Mautner7d7808f2014-09-11 18:02:38 -07002260 @Override
2261 public WindowState getWinShowWhenLockedLw() {
2262 return mWinShowWhenLocked;
2263 }
2264
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002265 /** {@inheritDoc} */
Craig Mautner8e4df6c2012-05-23 16:57:23 -07002266 @Override
Dianne Hackborn2f0b1752011-05-31 17:59:49 -07002267 public View addStartingWindow(IBinder appToken, String packageName, int theme,
2268 CompatibilityInfo compatInfo, CharSequence nonLocalizedLabel, int labelRes,
Adam Powell04fe6eb2013-05-31 14:39:48 -07002269 int icon, int logo, int windowFlags) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002270 if (!SHOW_STARTING_ANIMATIONS) {
2271 return null;
2272 }
2273 if (packageName == null) {
2274 return null;
2275 }
Craig Mautner8e4df6c2012-05-23 16:57:23 -07002276
Mathias Jeppssond1443e92012-08-24 15:25:32 +02002277 WindowManager wm = null;
2278 View view = null;
2279
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002280 try {
Dianne Hackborn867ab6472010-04-29 13:28:56 -07002281 Context context = mContext;
Craig Mautner6fbda632012-07-03 09:26:39 -07002282 if (DEBUG_STARTING_WINDOW) Slog.d(TAG, "addStartingWindow " + packageName
2283 + ": nonLocalizedLabel=" + nonLocalizedLabel + " theme="
2284 + Integer.toHexString(theme));
Dianne Hackborn247fe742011-01-08 17:25:57 -08002285 if (theme != context.getThemeResId() || labelRes != 0) {
Dianne Hackborn867ab6472010-04-29 13:28:56 -07002286 try {
2287 context = context.createPackageContext(packageName, 0);
Dianne Hackborn247fe742011-01-08 17:25:57 -08002288 context.setTheme(theme);
Dianne Hackborn867ab6472010-04-29 13:28:56 -07002289 } catch (PackageManager.NameNotFoundException e) {
2290 // Ignore
2291 }
2292 }
Craig Mautner8e4df6c2012-05-23 16:57:23 -07002293
Jorim Jaggia16cc152015-06-01 16:55:05 -07002294 PhoneWindow win = new PhoneWindow(context);
2295 win.setIsStartingWindow(true);
Craig Mautner8e4df6c2012-05-23 16:57:23 -07002296 final TypedArray ta = win.getWindowStyle();
2297 if (ta.getBoolean(
2298 com.android.internal.R.styleable.Window_windowDisablePreview, false)
2299 || ta.getBoolean(
2300 com.android.internal.R.styleable.Window_windowShowWallpaper,false)) {
Dianne Hackborn867ab6472010-04-29 13:28:56 -07002301 return null;
2302 }
Craig Mautner8e4df6c2012-05-23 16:57:23 -07002303
Dianne Hackborn867ab6472010-04-29 13:28:56 -07002304 Resources r = context.getResources();
2305 win.setTitle(r.getText(labelRes, nonLocalizedLabel));
Craig Mautner8e4df6c2012-05-23 16:57:23 -07002306
Dianne Hackborn867ab6472010-04-29 13:28:56 -07002307 win.setType(
2308 WindowManager.LayoutParams.TYPE_APPLICATION_STARTING);
Adrian Roos602c68e2015-04-24 16:03:47 -07002309
2310 synchronized (mWindowManagerFuncs.getWindowManagerLock()) {
2311 // Assumes it's safe to show starting windows of launched apps while
2312 // the keyguard is being hidden. This is okay because starting windows never show
2313 // secret information.
2314 if (mKeyguardHidden) {
2315 windowFlags |= FLAG_SHOW_WHEN_LOCKED;
2316 }
2317 }
2318
Dianne Hackborn867ab6472010-04-29 13:28:56 -07002319 // Force the window flags: this is a fake window, so it is not really
2320 // touchable or focusable by the user. We also add in the ALT_FOCUSABLE_IM
2321 // flag because we do know that the next window will take input
2322 // focus, so we want to get the IME window up on top of us right away.
2323 win.setFlags(
Dianne Hackborn7eec10e2010-11-12 18:03:47 -08002324 windowFlags|
Dianne Hackborn867ab6472010-04-29 13:28:56 -07002325 WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE|
2326 WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE|
2327 WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM,
Dianne Hackborn7eec10e2010-11-12 18:03:47 -08002328 windowFlags|
Dianne Hackborn867ab6472010-04-29 13:28:56 -07002329 WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE|
2330 WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE|
2331 WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM);
Craig Mautner8e4df6c2012-05-23 16:57:23 -07002332
Adam Powell04fe6eb2013-05-31 14:39:48 -07002333 win.setDefaultIcon(icon);
2334 win.setDefaultLogo(logo);
2335
Dianne Hackborn867ab6472010-04-29 13:28:56 -07002336 win.setLayout(WindowManager.LayoutParams.MATCH_PARENT,
Dianne Hackborn2f0b1752011-05-31 17:59:49 -07002337 WindowManager.LayoutParams.MATCH_PARENT);
Craig Mautner8e4df6c2012-05-23 16:57:23 -07002338
Dianne Hackborn867ab6472010-04-29 13:28:56 -07002339 final WindowManager.LayoutParams params = win.getAttributes();
2340 params.token = appToken;
2341 params.packageName = packageName;
2342 params.windowAnimations = win.getWindowStyle().getResourceId(
2343 com.android.internal.R.styleable.Window_windowAnimationStyle, 0);
John Reck61375a82014-09-18 19:27:48 +00002344 params.privateFlags |=
2345 WindowManager.LayoutParams.PRIVATE_FLAG_FAKE_HARDWARE_ACCELERATED;
Craig Mautner88400d32012-09-30 12:35:45 -07002346 params.privateFlags |= WindowManager.LayoutParams.PRIVATE_FLAG_SHOW_FOR_ALL_USERS;
Adam Lesinski95c42972013-10-02 10:13:27 -07002347
2348 if (!compatInfo.supportsScreen()) {
2349 params.privateFlags |= WindowManager.LayoutParams.PRIVATE_FLAG_COMPATIBLE_WINDOW;
2350 }
2351
Dianne Hackborn867ab6472010-04-29 13:28:56 -07002352 params.setTitle("Starting " + packageName);
2353
Mathias Jeppssond1443e92012-08-24 15:25:32 +02002354 wm = (WindowManager)context.getSystemService(Context.WINDOW_SERVICE);
2355 view = win.getDecorView();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002356
2357 if (win.isFloating()) {
2358 // Whoops, there is no way to display an animation/preview
2359 // of such a thing! After all that work... let's skip it.
2360 // (Note that we must do this here because it is in
2361 // getDecorView() where the theme is evaluated... maybe
2362 // we should peek the floating attribute from the theme
2363 // earlier.)
2364 return null;
2365 }
Craig Mautner8e4df6c2012-05-23 16:57:23 -07002366
Craig Mautner6fbda632012-07-03 09:26:39 -07002367 if (DEBUG_STARTING_WINDOW) Slog.d(
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002368 TAG, "Adding starting window for " + packageName
2369 + " / " + appToken + ": "
2370 + (view.getParent() != null ? view : null));
2371
2372 wm.addView(view, params);
2373
2374 // Only return the view if it was successfully added to the
2375 // window manager... which we can tell by it having a parent.
2376 return view.getParent() != null ? view : null;
Jeff Brown98365d72012-08-19 20:30:52 -07002377 } catch (WindowManager.BadTokenException e) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002378 // ignore
Craig Mautner42bf39e2014-02-21 16:46:22 -08002379 Log.w(TAG, appToken + " already running, starting window not displayed. " +
2380 e.getMessage());
Dianne Hackborn867ab6472010-04-29 13:28:56 -07002381 } catch (RuntimeException e) {
2382 // don't crash if something else bad happens, for example a
2383 // failure loading resources because we are loading from an app
2384 // on external storage that has been unmounted.
2385 Log.w(TAG, appToken + " failed creating starting window", e);
Mathias Jeppssond1443e92012-08-24 15:25:32 +02002386 } finally {
2387 if (view != null && view.getParent() == null) {
2388 Log.w(TAG, "view not successfully added to wm, removing view");
2389 wm.removeViewImmediate(view);
2390 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002391 }
2392
2393 return null;
2394 }
2395
2396 /** {@inheritDoc} */
Jose Lima9546b202014-07-02 17:21:51 -07002397 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002398 public void removeStartingWindow(IBinder appToken, View window) {
Craig Mautner276a6eb2014-11-04 15:32:57 -08002399 if (DEBUG_STARTING_WINDOW) Slog.v(TAG, "Removing starting window for " + appToken + ": "
2400 + window + " Callers=" + Debug.getCallers(4));
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002401
2402 if (window != null) {
Dianne Hackborn5fd21692011-06-07 14:09:47 -07002403 WindowManager wm = (WindowManager)mContext.getSystemService(Context.WINDOW_SERVICE);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002404 wm.removeView(window);
2405 }
2406 }
2407
2408 /**
2409 * Preflight adding a window to the system.
RoboErik8a2cfc32014-05-16 11:19:38 -07002410 *
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002411 * Currently enforces that three window types are singletons:
2412 * <ul>
2413 * <li>STATUS_BAR_TYPE</li>
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002414 * <li>KEYGUARD_TYPE</li>
2415 * </ul>
RoboErik8a2cfc32014-05-16 11:19:38 -07002416 *
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002417 * @param win The window to be added
2418 * @param attrs Information about the window to be added
RoboErik8a2cfc32014-05-16 11:19:38 -07002419 *
Jeff Brown98365d72012-08-19 20:30:52 -07002420 * @return If ok, WindowManagerImpl.ADD_OKAY. If too many singletons,
2421 * WindowManagerImpl.ADD_MULTIPLE_SINGLETON
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002422 */
Jose Lima9546b202014-07-02 17:21:51 -07002423 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002424 public int prepareAddWindowLw(WindowState win, WindowManager.LayoutParams attrs) {
2425 switch (attrs.type) {
2426 case TYPE_STATUS_BAR:
Joe Onorato8bc6c512010-06-04 16:21:12 -04002427 mContext.enforceCallingOrSelfPermission(
2428 android.Manifest.permission.STATUS_BAR_SERVICE,
2429 "PhoneWindowManager");
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002430 if (mStatusBar != null) {
Dianne Hackbornf87d1962012-04-04 12:48:24 -07002431 if (mStatusBar.isAlive()) {
Jeff Brown98365d72012-08-19 20:30:52 -07002432 return WindowManagerGlobal.ADD_MULTIPLE_SINGLETON;
Dianne Hackbornf87d1962012-04-04 12:48:24 -07002433 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002434 }
2435 mStatusBar = win;
John Spurlock27735a42013-08-14 17:57:38 -04002436 mStatusBarController.setWindow(win);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002437 break;
Daniel Sandler8956dbb2011-04-22 07:55:02 -04002438 case TYPE_NAVIGATION_BAR:
2439 mContext.enforceCallingOrSelfPermission(
2440 android.Manifest.permission.STATUS_BAR_SERVICE,
2441 "PhoneWindowManager");
Dianne Hackbornf87d1962012-04-04 12:48:24 -07002442 if (mNavigationBar != null) {
2443 if (mNavigationBar.isAlive()) {
Jeff Brown98365d72012-08-19 20:30:52 -07002444 return WindowManagerGlobal.ADD_MULTIPLE_SINGLETON;
Dianne Hackbornf87d1962012-04-04 12:48:24 -07002445 }
2446 }
Daniel Sandler8956dbb2011-04-22 07:55:02 -04002447 mNavigationBar = win;
John Spurlock27735a42013-08-14 17:57:38 -04002448 mNavigationBarController.setWindow(win);
Craig Mautnereda67292013-04-28 13:50:14 -07002449 if (DEBUG_LAYOUT) Slog.i(TAG, "NAVIGATION BAR: " + mNavigationBar);
Daniel Sandler8956dbb2011-04-22 07:55:02 -04002450 break;
Jim Millere898ac52012-04-06 17:10:57 -07002451 case TYPE_NAVIGATION_BAR_PANEL:
Dianne Hackborn08743722009-12-21 12:16:51 -08002452 case TYPE_STATUS_BAR_PANEL:
Joe Onorato29fc2c92010-11-24 10:26:50 -08002453 case TYPE_STATUS_BAR_SUB_PANEL:
Jorim Jaggi225d3b52015-04-01 11:18:57 -07002454 case TYPE_VOICE_INTERACTION_STARTING:
Joe Onorato29fc2c92010-11-24 10:26:50 -08002455 mContext.enforceCallingOrSelfPermission(
2456 android.Manifest.permission.STATUS_BAR_SERVICE,
2457 "PhoneWindowManager");
Joe Onorato29fc2c92010-11-24 10:26:50 -08002458 break;
Jim Miller5ecd8112013-01-09 18:50:26 -08002459 case TYPE_KEYGUARD_SCRIM:
Jim Miller25190572013-02-28 17:36:24 -08002460 if (mKeyguardScrim != null) {
2461 return WindowManagerGlobal.ADD_MULTIPLE_SINGLETON;
2462 }
Jim Miller5ecd8112013-01-09 18:50:26 -08002463 mKeyguardScrim = win;
2464 break;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002465 }
Jeff Brown98365d72012-08-19 20:30:52 -07002466 return WindowManagerGlobal.ADD_OKAY;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002467 }
2468
2469 /** {@inheritDoc} */
Jose Lima9546b202014-07-02 17:21:51 -07002470 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002471 public void removeWindowLw(WindowState win) {
2472 if (mStatusBar == win) {
2473 mStatusBar = null;
John Spurlock27735a42013-08-14 17:57:38 -04002474 mStatusBarController.setWindow(null);
Jim Millerc0b676d2013-03-22 16:11:08 -07002475 mKeyguardDelegate.showScrim();
Jim Miller5ecd8112013-01-09 18:50:26 -08002476 } else if (mKeyguardScrim == win) {
2477 Log.v(TAG, "Removing keyguard scrim");
2478 mKeyguardScrim = null;
2479 } if (mNavigationBar == win) {
Daniel Sandler8956dbb2011-04-22 07:55:02 -04002480 mNavigationBar = null;
John Spurlock27735a42013-08-14 17:57:38 -04002481 mNavigationBarController.setWindow(null);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002482 }
2483 }
2484
2485 static final boolean PRINT_ANIM = false;
RoboErik8a2cfc32014-05-16 11:19:38 -07002486
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002487 /** {@inheritDoc} */
Craig Mautner4b71aa12012-12-27 17:20:01 -08002488 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002489 public int selectAnimationLw(WindowState win, int transit) {
2490 if (PRINT_ANIM) Log.i(TAG, "selectAnimation in " + win
2491 + ": transit=" + transit);
Dianne Hackbornf87d1962012-04-04 12:48:24 -07002492 if (win == mStatusBar) {
Jorim Jaggi380ecb82014-03-14 17:25:20 +01002493 boolean isKeyguard = (win.getAttrs().privateFlags & PRIVATE_FLAG_KEYGUARD) != 0;
Craig Mautner4b71aa12012-12-27 17:20:01 -08002494 if (transit == TRANSIT_EXIT
2495 || transit == TRANSIT_HIDE) {
Jorim Jaggi380ecb82014-03-14 17:25:20 +01002496 return isKeyguard ? -1 : R.anim.dock_top_exit;
Craig Mautner4b71aa12012-12-27 17:20:01 -08002497 } else if (transit == TRANSIT_ENTER
2498 || transit == TRANSIT_SHOW) {
Jorim Jaggi380ecb82014-03-14 17:25:20 +01002499 return isKeyguard ? -1 : R.anim.dock_top_enter;
Dianne Hackbornf87d1962012-04-04 12:48:24 -07002500 }
2501 } else if (win == mNavigationBar) {
Jorim Jaggi0d210f62015-07-10 14:24:44 -07002502 if (win.getAttrs().windowAnimations != 0) {
2503 return 0;
2504 }
Dianne Hackbornf87d1962012-04-04 12:48:24 -07002505 // This can be on either the bottom or the right.
2506 if (mNavigationBarOnBottom) {
Craig Mautner4b71aa12012-12-27 17:20:01 -08002507 if (transit == TRANSIT_EXIT
2508 || transit == TRANSIT_HIDE) {
Dianne Hackbornf87d1962012-04-04 12:48:24 -07002509 return R.anim.dock_bottom_exit;
Craig Mautner4b71aa12012-12-27 17:20:01 -08002510 } else if (transit == TRANSIT_ENTER
2511 || transit == TRANSIT_SHOW) {
Dianne Hackbornf87d1962012-04-04 12:48:24 -07002512 return R.anim.dock_bottom_enter;
2513 }
2514 } else {
Craig Mautner4b71aa12012-12-27 17:20:01 -08002515 if (transit == TRANSIT_EXIT
2516 || transit == TRANSIT_HIDE) {
Dianne Hackbornf87d1962012-04-04 12:48:24 -07002517 return R.anim.dock_right_exit;
Craig Mautner4b71aa12012-12-27 17:20:01 -08002518 } else if (transit == TRANSIT_ENTER
2519 || transit == TRANSIT_SHOW) {
Dianne Hackbornf87d1962012-04-04 12:48:24 -07002520 return R.anim.dock_right_enter;
2521 }
2522 }
Craig Mautner4b71aa12012-12-27 17:20:01 -08002523 }
2524
2525 if (transit == TRANSIT_PREVIEW_DONE) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002526 if (win.hasAppShownWindows()) {
2527 if (PRINT_ANIM) Log.i(TAG, "**** STARTING EXIT");
2528 return com.android.internal.R.anim.app_starting_exit;
2529 }
Dianne Hackborn7ad44382012-10-18 17:46:00 -07002530 } else if (win.getAttrs().type == TYPE_DREAM && mDreamingLockscreen
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07002531 && transit == TRANSIT_ENTER) {
2532 // Special case: we are animating in a dream, while the keyguard
2533 // is shown. We don't want an animation on the dream, because
2534 // we need it shown immediately with the keyguard animating away
2535 // to reveal it.
2536 return -1;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002537 }
2538
2539 return 0;
2540 }
2541
Craig Mautner3c174372013-02-21 17:54:37 -08002542 @Override
2543 public void selectRotationAnimationLw(int anim[]) {
2544 if (PRINT_ANIM) Slog.i(TAG, "selectRotationAnimation mTopFullscreen="
2545 + mTopFullscreenOpaqueWindowState + " rotationAnimation="
2546 + (mTopFullscreenOpaqueWindowState == null ?
2547 "0" : mTopFullscreenOpaqueWindowState.getAttrs().rotationAnimation));
2548 if (mTopFullscreenOpaqueWindowState != null && mTopIsFullscreen) {
2549 switch (mTopFullscreenOpaqueWindowState.getAttrs().rotationAnimation) {
2550 case ROTATION_ANIMATION_CROSSFADE:
2551 anim[0] = R.anim.rotation_animation_xfade_exit;
2552 anim[1] = R.anim.rotation_animation_enter;
2553 break;
2554 case ROTATION_ANIMATION_JUMPCUT:
2555 anim[0] = R.anim.rotation_animation_jump_exit;
2556 anim[1] = R.anim.rotation_animation_enter;
2557 break;
2558 case ROTATION_ANIMATION_ROTATE:
2559 default:
2560 anim[0] = anim[1] = 0;
2561 break;
2562 }
2563 } else {
2564 anim[0] = anim[1] = 0;
2565 }
2566 }
2567
2568 @Override
2569 public boolean validateRotationAnimationLw(int exitAnimId, int enterAnimId,
2570 boolean forceDefault) {
2571 switch (exitAnimId) {
2572 case R.anim.rotation_animation_xfade_exit:
2573 case R.anim.rotation_animation_jump_exit:
2574 // These are the only cases that matter.
2575 if (forceDefault) {
2576 return false;
2577 }
2578 int anim[] = new int[2];
2579 selectRotationAnimationLw(anim);
2580 return (exitAnimId == anim[0] && enterAnimId == anim[1]);
2581 default:
2582 return true;
2583 }
2584 }
2585
2586 @Override
Jorim Jaggi84a3e7a2014-08-13 17:58:58 +02002587 public Animation createForceHideEnterAnimation(boolean onWallpaper,
2588 boolean goingToNotificationShade) {
2589 if (goingToNotificationShade) {
2590 return AnimationUtils.loadAnimation(mContext, R.anim.lock_screen_behind_enter_fade_in);
Craig Mautnerb8340802014-11-04 15:32:57 -08002591 }
Craig Mautner276a6eb2014-11-04 15:32:57 -08002592
2593 AnimationSet set = (AnimationSet) AnimationUtils.loadAnimation(mContext, onWallpaper ?
2594 R.anim.lock_screen_behind_enter_wallpaper :
2595 R.anim.lock_screen_behind_enter);
2596
2597 // TODO: Use XML interpolators when we have log interpolators available in XML.
2598 final List<Animation> animations = set.getAnimations();
2599 for (int i = animations.size() - 1; i >= 0; --i) {
2600 animations.get(i).setInterpolator(mLogDecelerateInterpolator);
2601 }
2602
2603 return set;
Jorim Jaggi76a16232014-08-08 17:00:47 +02002604 }
2605
2606
2607 @Override
Jorim Jaggi84a3e7a2014-08-13 17:58:58 +02002608 public Animation createForceHideWallpaperExitAnimation(boolean goingToNotificationShade) {
2609 if (goingToNotificationShade) {
2610 return null;
2611 } else {
2612 return AnimationUtils.loadAnimation(mContext, R.anim.lock_screen_wallpaper_exit);
2613 }
Dianne Hackborn01ad2f42009-09-24 19:24:56 -07002614 }
John Spurlockc8b46ca2013-04-08 12:59:26 -04002615
2616 private static void awakenDreams() {
2617 IDreamManager dreamManager = getDreamManager();
2618 if (dreamManager != null) {
2619 try {
2620 dreamManager.awaken();
2621 } catch (RemoteException e) {
2622 // fine, stay asleep then
2623 }
2624 }
2625 }
2626
2627 static IDreamManager getDreamManager() {
2628 return IDreamManager.Stub.asInterface(
2629 ServiceManager.checkService(DreamService.DREAM_SERVICE));
2630 }
2631
Tyler Gunnef9f6f92014-09-12 22:16:17 -07002632 TelecomManager getTelecommService() {
2633 return (TelecomManager) mContext.getSystemService(Context.TELECOM_SERVICE);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002634 }
2635
Jeff Brown4d396052010-10-29 21:50:21 -07002636 static IAudioService getAudioService() {
2637 IAudioService audioService = IAudioService.Stub.asInterface(
2638 ServiceManager.checkService(Context.AUDIO_SERVICE));
2639 if (audioService == null) {
2640 Log.w(TAG, "Unable to find IAudioService interface.");
2641 }
2642 return audioService;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002643 }
2644
2645 boolean keyguardOn() {
Jim Millerab954542014-10-10 18:21:49 -07002646 return isKeyguardShowingAndNotOccluded() || inKeyguardRestrictedKeyInputMode();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002647 }
2648
2649 private static final int[] WINDOW_TYPES_WHERE_HOME_DOESNT_WORK = {
2650 WindowManager.LayoutParams.TYPE_SYSTEM_ALERT,
2651 WindowManager.LayoutParams.TYPE_SYSTEM_ERROR,
2652 };
2653
2654 /** {@inheritDoc} */
Jeff Brown00fa7bd2010-07-02 15:37:36 -07002655 @Override
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002656 public long interceptKeyBeforeDispatching(WindowState win, KeyEvent event, int policyFlags) {
Jeff Brown00fa7bd2010-07-02 15:37:36 -07002657 final boolean keyguardOn = keyguardOn();
Jeff Brown1f245102010-11-18 20:53:46 -08002658 final int keyCode = event.getKeyCode();
2659 final int repeatCount = event.getRepeatCount();
2660 final int metaState = event.getMetaState();
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002661 final int flags = event.getFlags();
Jeff Brown1f245102010-11-18 20:53:46 -08002662 final boolean down = event.getAction() == KeyEvent.ACTION_DOWN;
2663 final boolean canceled = event.isCanceled();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002664
Jeff Brown40013652012-05-16 21:22:36 -07002665 if (DEBUG_INPUT) {
Jeff Brown00fa7bd2010-07-02 15:37:36 -07002666 Log.d(TAG, "interceptKeyTi keyCode=" + keyCode + " down=" + down + " repeatCount="
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002667 + repeatCount + " keyguardOn=" + keyguardOn + " mHomePressed=" + mHomePressed
2668 + " canceled=" + canceled);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002669 }
2670
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002671 // If we think we might have a volume down & power key chord on the way
2672 // but we're not sure, then tell the dispatcher to wait a little while and
2673 // try again later before dispatching.
Christopher Tatee90585f2012-03-05 18:56:25 -08002674 if (mScreenshotChordEnabled && (flags & KeyEvent.FLAG_FALLBACK) == 0) {
Jeff Brown13f00f02014-10-31 14:45:50 -07002675 if (mScreenshotChordVolumeDownKeyTriggered && !mScreenshotChordPowerKeyTriggered) {
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002676 final long now = SystemClock.uptimeMillis();
Jeff Brown13f00f02014-10-31 14:45:50 -07002677 final long timeoutTime = mScreenshotChordVolumeDownKeyTime
2678 + SCREENSHOT_CHORD_DEBOUNCE_DELAY_MILLIS;
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002679 if (now < timeoutTime) {
2680 return timeoutTime - now;
2681 }
2682 }
2683 if (keyCode == KeyEvent.KEYCODE_VOLUME_DOWN
Jeff Brown13f00f02014-10-31 14:45:50 -07002684 && mScreenshotChordVolumeDownKeyConsumed) {
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002685 if (!down) {
Jeff Brown13f00f02014-10-31 14:45:50 -07002686 mScreenshotChordVolumeDownKeyConsumed = false;
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002687 }
2688 return -1;
2689 }
2690 }
2691
Michael Wright6a62e552014-06-03 19:19:48 -07002692 // Cancel any pending meta actions if we see any other keys being pressed between the down
2693 // of the meta key and its corresponding up.
Michael Wright251e35d2014-08-22 15:40:27 -07002694 if (mPendingMetaAction && !KeyEvent.isMetaKey(keyCode)) {
Michael Wright6a62e552014-06-03 19:19:48 -07002695 mPendingMetaAction = false;
2696 }
2697
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002698 // First we always handle the home key here, so applications
2699 // can never break it, although if keyguard is on, we do let
2700 // it handle it, because that gives us the correct 5 second
2701 // timeout.
Jeff Brown00fa7bd2010-07-02 15:37:36 -07002702 if (keyCode == KeyEvent.KEYCODE_HOME) {
Michael Jurka7f2668c2012-03-27 07:49:52 -07002703
Jeff Brown49ed71d2010-12-06 17:13:33 -08002704 // If we have released the home key, and didn't do anything else
2705 // while it was pressed, then it is time to go home!
Michael Jurka7f2668c2012-03-27 07:49:52 -07002706 if (!down) {
Jeff Browncaca8812013-05-09 13:34:33 -07002707 cancelPreloadRecentApps();
2708
Jeff Brown49ed71d2010-12-06 17:13:33 -08002709 mHomePressed = false;
Jeff Browncaca8812013-05-09 13:34:33 -07002710 if (mHomeConsumed) {
2711 mHomeConsumed = false;
Michael Jurka7f2668c2012-03-27 07:49:52 -07002712 return -1;
Jeff Brown49ed71d2010-12-06 17:13:33 -08002713 }
Jeff Browncaca8812013-05-09 13:34:33 -07002714
2715 if (canceled) {
2716 Log.i(TAG, "Ignoring HOME; event canceled.");
2717 return -1;
2718 }
2719
Yorke Lee4f803242014-12-15 23:22:06 +00002720 // If an incoming call is ringing, HOME is totally disabled.
2721 // (The user is already on the InCallUI at this point,
2722 // and his ONLY options are to answer or reject the call.)
2723 TelecomManager telecomManager = getTelecommService();
2724 if (telecomManager != null && telecomManager.isRinging()) {
2725 Log.i(TAG, "Ignoring HOME; there's a ringing incoming call.");
2726 return -1;
2727 }
2728
Jeff Browncaca8812013-05-09 13:34:33 -07002729 // Delay handling home if a double-tap is possible.
2730 if (mDoubleTapOnHomeBehavior != DOUBLE_TAP_HOME_NOTHING) {
2731 mHandler.removeCallbacks(mHomeDoubleTapTimeoutRunnable); // just in case
2732 mHomeDoubleTapPending = true;
2733 mHandler.postDelayed(mHomeDoubleTapTimeoutRunnable,
2734 ViewConfiguration.getDoubleTapTimeout());
2735 return -1;
2736 }
2737
Jeff Brown13f00f02014-10-31 14:45:50 -07002738 handleShortPressOnHome();
Jeff Browncaca8812013-05-09 13:34:33 -07002739 return -1;
Jeff Brown49ed71d2010-12-06 17:13:33 -08002740 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002741
2742 // If a system window has focus, then it doesn't make sense
2743 // right now to interact with applications.
2744 WindowManager.LayoutParams attrs = win != null ? win.getAttrs() : null;
2745 if (attrs != null) {
2746 final int type = attrs.type;
Jorim Jaggi380ecb82014-03-14 17:25:20 +01002747 if (type == WindowManager.LayoutParams.TYPE_KEYGUARD_SCRIM
2748 || type == WindowManager.LayoutParams.TYPE_KEYGUARD_DIALOG
2749 || (attrs.privateFlags & PRIVATE_FLAG_KEYGUARD) != 0) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002750 // the "app" is keyguard, so give it the key
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002751 return 0;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002752 }
2753 final int typeCount = WINDOW_TYPES_WHERE_HOME_DOESNT_WORK.length;
2754 for (int i=0; i<typeCount; i++) {
2755 if (type == WINDOW_TYPES_WHERE_HOME_DOESNT_WORK[i]) {
2756 // don't do anything, but also don't pass it to the app
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002757 return -1;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002758 }
2759 }
2760 }
Jeff Browncaca8812013-05-09 13:34:33 -07002761
2762 // Remember that home is pressed and handle special actions.
2763 if (repeatCount == 0) {
2764 mHomePressed = true;
2765 if (mHomeDoubleTapPending) {
2766 mHomeDoubleTapPending = false;
2767 mHandler.removeCallbacks(mHomeDoubleTapTimeoutRunnable);
2768 handleDoubleTapOnHome();
2769 } else if (mLongPressOnHomeBehavior == LONG_PRESS_HOME_RECENT_SYSTEM_UI
2770 || mDoubleTapOnHomeBehavior == DOUBLE_TAP_HOME_RECENT_SYSTEM_UI) {
2771 preloadRecentApps();
Michael Jurka7f2668c2012-03-27 07:49:52 -07002772 }
Jeff Browncaca8812013-05-09 13:34:33 -07002773 } else if ((event.getFlags() & KeyEvent.FLAG_LONG_PRESS) != 0) {
2774 if (!keyguardOn) {
Tim Kilbourn0e5f1102015-06-05 16:18:09 -07002775 handleLongPressOnHome(event.getDeviceId());
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002776 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002777 }
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002778 return -1;
Jeff Brown00fa7bd2010-07-02 15:37:36 -07002779 } else if (keyCode == KeyEvent.KEYCODE_MENU) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002780 // Hijack modified menu keys for debugging features
2781 final int chordBug = KeyEvent.META_SHIFT_ON;
2782
2783 if (down && repeatCount == 0) {
Jeff Brown00fa7bd2010-07-02 15:37:36 -07002784 if (mEnableShiftMenuBugReports && (metaState & chordBug) == chordBug) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002785 Intent intent = new Intent(Intent.ACTION_BUG_REPORT);
Dianne Hackborn5ac72a22012-08-29 18:32:08 -07002786 mContext.sendOrderedBroadcastAsUser(intent, UserHandle.CURRENT,
2787 null, null, null, 0, null, null);
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002788 return -1;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002789 } else if (SHOW_PROCESSES_ON_ALT_MENU &&
Jeff Brown00fa7bd2010-07-02 15:37:36 -07002790 (metaState & KeyEvent.META_ALT_ON) == KeyEvent.META_ALT_ON) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002791 Intent service = new Intent();
2792 service.setClassName(mContext, "com.android.server.LoadAverageService");
2793 ContentResolver res = mContext.getContentResolver();
Jeff Sharkey8d9a1f62012-10-18 15:38:14 -07002794 boolean shown = Settings.Global.getInt(
2795 res, Settings.Global.SHOW_PROCESSES, 0) != 0;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002796 if (!shown) {
2797 mContext.startService(service);
2798 } else {
2799 mContext.stopService(service);
2800 }
Jeff Sharkey8d9a1f62012-10-18 15:38:14 -07002801 Settings.Global.putInt(
2802 res, Settings.Global.SHOW_PROCESSES, shown ? 0 : 1);
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002803 return -1;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002804 }
2805 }
Jeff Brown00fa7bd2010-07-02 15:37:36 -07002806 } else if (keyCode == KeyEvent.KEYCODE_SEARCH) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002807 if (down) {
2808 if (repeatCount == 0) {
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002809 mSearchKeyShortcutPending = true;
2810 mConsumeSearchKeyUp = false;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002811 }
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002812 } else {
2813 mSearchKeyShortcutPending = false;
2814 if (mConsumeSearchKeyUp) {
2815 mConsumeSearchKeyUp = false;
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002816 return -1;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002817 }
2818 }
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002819 return 0;
Jeff Brown49ed71d2010-12-06 17:13:33 -08002820 } else if (keyCode == KeyEvent.KEYCODE_APP_SWITCH) {
Michael Wrightc9ebea72013-01-16 19:25:02 -08002821 if (!keyguardOn) {
Jeff Browncaca8812013-05-09 13:34:33 -07002822 if (down && repeatCount == 0) {
2823 preloadRecentApps();
2824 } else if (!down) {
2825 toggleRecentApps();
Michael Wrightc9ebea72013-01-16 19:25:02 -08002826 }
Jeff Brown49ed71d2010-12-06 17:13:33 -08002827 }
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002828 return -1;
Jun Mukaid21b3c82015-04-23 14:09:34 -07002829 } else if (keyCode == KeyEvent.KEYCODE_N && event.isMetaPressed()) {
2830 if (down) {
2831 IStatusBarService service = getStatusBarService();
2832 if (service != null) {
2833 try {
2834 service.expandNotificationsPanel();
2835 } catch (RemoteException e) {
2836 // do nothing.
2837 }
2838 }
2839 }
Jeff Brownde7a8ea2012-06-13 18:28:57 -07002840 } else if (keyCode == KeyEvent.KEYCODE_ASSIST) {
2841 if (down) {
2842 if (repeatCount == 0) {
2843 mAssistKeyLongPressed = false;
2844 } else if (repeatCount == 1) {
2845 mAssistKeyLongPressed = true;
2846 if (!keyguardOn) {
2847 launchAssistLongPressAction();
2848 }
2849 }
2850 } else {
2851 if (mAssistKeyLongPressed) {
2852 mAssistKeyLongPressed = false;
2853 } else {
2854 if (!keyguardOn) {
Tim Kilbourn0e5f1102015-06-05 16:18:09 -07002855 launchAssistAction(null, event.getDeviceId());
Jeff Brownde7a8ea2012-06-13 18:28:57 -07002856 }
2857 }
2858 }
2859 return -1;
Michael Wrightdc63f7b2014-08-21 19:05:21 -07002860 } else if (keyCode == KeyEvent.KEYCODE_VOICE_ASSIST) {
2861 if (!down) {
2862 Intent voiceIntent;
Michael Wright869a67c2014-08-26 19:33:06 -07002863 if (!keyguardOn) {
Michael Wrightdc63f7b2014-08-21 19:05:21 -07002864 voiceIntent = new Intent(RecognizerIntent.ACTION_WEB_SEARCH);
2865 } else {
Dianne Hackbornb6683c42015-06-18 17:40:33 -07002866 IDeviceIdleController dic = IDeviceIdleController.Stub.asInterface(
2867 ServiceManager.getService(Context.DEVICE_IDLE_CONTROLLER));
2868 if (dic != null) {
2869 try {
2870 dic.exitIdle("voice-search");
2871 } catch (RemoteException e) {
2872 }
2873 }
Michael Wrightdc63f7b2014-08-21 19:05:21 -07002874 voiceIntent = new Intent(RecognizerIntent.ACTION_VOICE_SEARCH_HANDS_FREE);
Michael Wright869a67c2014-08-26 19:33:06 -07002875 voiceIntent.putExtra(RecognizerIntent.EXTRA_SECURE, true);
Michael Wrightdc63f7b2014-08-21 19:05:21 -07002876 }
Bart Sears8b1c27c2015-03-18 23:51:02 +00002877 startActivityAsUser(voiceIntent, UserHandle.CURRENT_OR_SELF);
Michael Wrightdc63f7b2014-08-21 19:05:21 -07002878 }
Jeff Sharkey2991fa32012-12-05 18:06:43 -08002879 } else if (keyCode == KeyEvent.KEYCODE_SYSRQ) {
2880 if (down && repeatCount == 0) {
2881 mHandler.post(mScreenshotRunnable);
2882 }
2883 return -1;
Michael Wrightb854e242013-02-05 17:54:02 -08002884 } else if (keyCode == KeyEvent.KEYCODE_BRIGHTNESS_UP
2885 || keyCode == KeyEvent.KEYCODE_BRIGHTNESS_DOWN) {
2886 if (down) {
2887 int direction = keyCode == KeyEvent.KEYCODE_BRIGHTNESS_UP ? 1 : -1;
2888
2889 // Disable autobrightness if it's on
2890 int auto = Settings.System.getIntForUser(
2891 mContext.getContentResolver(),
2892 Settings.System.SCREEN_BRIGHTNESS_MODE,
2893 Settings.System.SCREEN_BRIGHTNESS_MODE_MANUAL,
2894 UserHandle.USER_CURRENT_OR_SELF);
2895 if (auto != 0) {
2896 Settings.System.putIntForUser(mContext.getContentResolver(),
2897 Settings.System.SCREEN_BRIGHTNESS_MODE,
2898 Settings.System.SCREEN_BRIGHTNESS_MODE_MANUAL,
2899 UserHandle.USER_CURRENT_OR_SELF);
2900 }
2901
2902 int min = mPowerManager.getMinimumScreenBrightnessSetting();
2903 int max = mPowerManager.getMaximumScreenBrightnessSetting();
2904 int step = (max - min + BRIGHTNESS_STEPS - 1) / BRIGHTNESS_STEPS * direction;
2905 int brightness = Settings.System.getIntForUser(mContext.getContentResolver(),
2906 Settings.System.SCREEN_BRIGHTNESS,
2907 mPowerManager.getDefaultScreenBrightnessSetting(),
2908 UserHandle.USER_CURRENT_OR_SELF);
2909 brightness += step;
2910 // Make sure we don't go beyond the limits.
2911 brightness = Math.min(max, brightness);
2912 brightness = Math.max(min, brightness);
2913
2914 Settings.System.putIntForUser(mContext.getContentResolver(),
2915 Settings.System.SCREEN_BRIGHTNESS, brightness,
2916 UserHandle.USER_CURRENT_OR_SELF);
Bart Sears8b1c27c2015-03-18 23:51:02 +00002917 startActivityAsUser(new Intent(Intent.ACTION_SHOW_BRIGHTNESS_DIALOG),
Alan Viverette5a399492014-07-14 16:19:38 -07002918 UserHandle.CURRENT_OR_SELF);
Michael Wrightb854e242013-02-05 17:54:02 -08002919 }
2920 return -1;
Michael Wrightce0c13a2014-07-30 10:49:21 -07002921 } else if (KeyEvent.isMetaKey(keyCode)) {
Michael Wright6a62e552014-06-03 19:19:48 -07002922 if (down) {
2923 mPendingMetaAction = true;
2924 } else if (mPendingMetaAction) {
Tim Kilbourn0e5f1102015-06-05 16:18:09 -07002925 launchAssistAction(Intent.EXTRA_ASSIST_INPUT_HINT_KEYBOARD, event.getDeviceId());
Michael Wright6a62e552014-06-03 19:19:48 -07002926 }
2927 return -1;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002928 }
Jeff Browncaab4d02010-12-09 22:13:41 -08002929
Jeff Brownc1fb48d2010-12-08 16:52:09 -08002930 // Shortcuts are invoked through Search+key, so intercept those here
Jeff Browncaab4d02010-12-09 22:13:41 -08002931 // Any printing key that is chorded with Search should be consumed
2932 // even if no shortcut was invoked. This prevents text from being
2933 // inadvertently inserted when using a keyboard that has built-in macro
2934 // shortcut keys (that emit Search+x) and some of them are not registered.
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002935 if (mSearchKeyShortcutPending) {
Jeff Browncaab4d02010-12-09 22:13:41 -08002936 final KeyCharacterMap kcm = event.getKeyCharacterMap();
2937 if (kcm.isPrintingKey(keyCode)) {
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002938 mConsumeSearchKeyUp = true;
2939 mSearchKeyShortcutPending = false;
Jeff Browncaab4d02010-12-09 22:13:41 -08002940 if (down && repeatCount == 0 && !keyguardOn) {
2941 Intent shortcutIntent = mShortcutManager.getIntent(kcm, keyCode, metaState);
2942 if (shortcutIntent != null) {
2943 shortcutIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
Jeff Brownf0a3cc52011-01-26 18:42:46 -08002944 try {
Bart Sears8b1c27c2015-03-18 23:51:02 +00002945 startActivityAsUser(shortcutIntent, UserHandle.CURRENT);
Jeff Brownf0a3cc52011-01-26 18:42:46 -08002946 } catch (ActivityNotFoundException ex) {
2947 Slog.w(TAG, "Dropping shortcut key combination because "
2948 + "the activity to which it is registered was not found: "
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002949 + "SEARCH+" + KeyEvent.keyCodeToString(keyCode), ex);
Jeff Brownf0a3cc52011-01-26 18:42:46 -08002950 }
Jeff Browncaab4d02010-12-09 22:13:41 -08002951 } else {
2952 Slog.i(TAG, "Dropping unregistered shortcut key combination: "
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002953 + "SEARCH+" + KeyEvent.keyCodeToString(keyCode));
Jeff Brown49ed71d2010-12-06 17:13:33 -08002954 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002955 }
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002956 return -1;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002957 }
2958 }
2959
Jeff Brown68b909d2011-12-07 16:36:01 -08002960 // Invoke shortcuts using Meta.
Jeff Brown602ab322012-05-16 13:33:47 -07002961 if (down && repeatCount == 0 && !keyguardOn
Jeff Brown68b909d2011-12-07 16:36:01 -08002962 && (metaState & KeyEvent.META_META_ON) != 0) {
2963 final KeyCharacterMap kcm = event.getKeyCharacterMap();
Jeff Brown602ab322012-05-16 13:33:47 -07002964 if (kcm.isPrintingKey(keyCode)) {
2965 Intent shortcutIntent = mShortcutManager.getIntent(kcm, keyCode,
2966 metaState & ~(KeyEvent.META_META_ON
2967 | KeyEvent.META_META_LEFT_ON | KeyEvent.META_META_RIGHT_ON));
2968 if (shortcutIntent != null) {
2969 shortcutIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
2970 try {
Bart Sears8b1c27c2015-03-18 23:51:02 +00002971 startActivityAsUser(shortcutIntent, UserHandle.CURRENT);
Jeff Brown602ab322012-05-16 13:33:47 -07002972 } catch (ActivityNotFoundException ex) {
2973 Slog.w(TAG, "Dropping shortcut key combination because "
2974 + "the activity to which it is registered was not found: "
2975 + "META+" + KeyEvent.keyCodeToString(keyCode), ex);
2976 }
2977 return -1;
Jeff Brown68b909d2011-12-07 16:36:01 -08002978 }
Jeff Brown68b909d2011-12-07 16:36:01 -08002979 }
2980 }
2981
Jeff Brown6651a632011-11-28 12:59:11 -08002982 // Handle application launch keys.
Jeff Brown602ab322012-05-16 13:33:47 -07002983 if (down && repeatCount == 0 && !keyguardOn) {
Jeff Brown6651a632011-11-28 12:59:11 -08002984 String category = sApplicationLaunchKeyCategories.get(keyCode);
2985 if (category != null) {
Dianne Hackbornf5b86712011-12-05 17:42:41 -08002986 Intent intent = Intent.makeMainSelectorActivity(Intent.ACTION_MAIN, category);
Jeff Brown6651a632011-11-28 12:59:11 -08002987 intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
2988 try {
Bart Sears8b1c27c2015-03-18 23:51:02 +00002989 startActivityAsUser(intent, UserHandle.CURRENT);
Jeff Brown6651a632011-11-28 12:59:11 -08002990 } catch (ActivityNotFoundException ex) {
2991 Slog.w(TAG, "Dropping application launch key because "
2992 + "the activity to which it is registered was not found: "
2993 + "keyCode=" + keyCode + ", category=" + category, ex);
2994 }
Jeff Brown68b909d2011-12-07 16:36:01 -08002995 return -1;
Jeff Brown6651a632011-11-28 12:59:11 -08002996 }
2997 }
2998
Michael Wright61c46752014-08-21 16:57:33 -07002999 // Display task switcher for ALT-TAB.
Jeff Brown68b909d2011-12-07 16:36:01 -08003000 if (down && repeatCount == 0 && keyCode == KeyEvent.KEYCODE_TAB) {
Winson Chung1e8d71b2014-05-16 17:05:22 -07003001 if (mRecentAppsHeldModifiers == 0 && !keyguardOn) {
Jeff Brown68b909d2011-12-07 16:36:01 -08003002 final int shiftlessModifiers = event.getModifiers() & ~KeyEvent.META_SHIFT_MASK;
Michael Wright61c46752014-08-21 16:57:33 -07003003 if (KeyEvent.metaStateHasModifiers(shiftlessModifiers, KeyEvent.META_ALT_ON)) {
Winson Chung1e8d71b2014-05-16 17:05:22 -07003004 mRecentAppsHeldModifiers = shiftlessModifiers;
3005 showRecentApps(true);
Jeff Brown68b909d2011-12-07 16:36:01 -08003006 return -1;
3007 }
3008 }
Winson Chung1e8d71b2014-05-16 17:05:22 -07003009 } else if (!down && mRecentAppsHeldModifiers != 0
3010 && (metaState & mRecentAppsHeldModifiers) == 0) {
3011 mRecentAppsHeldModifiers = 0;
Winson Chungcdcd4872014-08-05 18:00:13 -07003012 hideRecentApps(true, false);
Jeff Brown68b909d2011-12-07 16:36:01 -08003013 }
3014
Jeff Browncf39bdf2012-05-18 14:41:19 -07003015 // Handle keyboard language switching.
3016 if (down && repeatCount == 0
3017 && (keyCode == KeyEvent.KEYCODE_LANGUAGE_SWITCH
3018 || (keyCode == KeyEvent.KEYCODE_SPACE
3019 && (metaState & KeyEvent.META_CTRL_MASK) != 0))) {
3020 int direction = (metaState & KeyEvent.META_SHIFT_MASK) != 0 ? -1 : 1;
3021 mWindowManagerFuncs.switchKeyboardLayout(event.getDeviceId(), direction);
3022 return -1;
3023 }
3024 if (mLanguageSwitchKeyPressed && !down
3025 && (keyCode == KeyEvent.KEYCODE_LANGUAGE_SWITCH
3026 || keyCode == KeyEvent.KEYCODE_SPACE)) {
3027 mLanguageSwitchKeyPressed = false;
3028 return -1;
3029 }
3030
Jeff Brown13f00f02014-10-31 14:45:50 -07003031 if (isValidGlobalKey(keyCode)
3032 && mGlobalKeyManager.handleGlobalKey(mContext, keyCode, event)) {
Justin Kohd378ad72013-04-01 12:18:26 -07003033 return -1;
3034 }
3035
Michael Wright6a62e552014-06-03 19:19:48 -07003036 // Reserve all the META modifier combos for system behavior
Michael Wrightce0c13a2014-07-30 10:49:21 -07003037 if ((metaState & KeyEvent.META_META_ON) != 0) {
Michael Wright6a62e552014-06-03 19:19:48 -07003038 return -1;
3039 }
3040
Jeff Brown68b909d2011-12-07 16:36:01 -08003041 // Let the application handle the key.
Jeff Brownd5bb82d2011-10-12 13:57:59 -07003042 return 0;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003043 }
3044
Jeff Brown3915bb82010-11-05 15:02:16 -07003045 /** {@inheritDoc} */
3046 @Override
Jeff Brown49ed71d2010-12-06 17:13:33 -08003047 public KeyEvent dispatchUnhandledKey(WindowState win, KeyEvent event, int policyFlags) {
Jeff Brown54875002011-04-06 15:33:01 -07003048 // Note: This method is only called if the initial down was unhandled.
Jeff Brown40013652012-05-16 21:22:36 -07003049 if (DEBUG_INPUT) {
Jeff Brown1f245102010-11-18 20:53:46 -08003050 Slog.d(TAG, "Unhandled key: win=" + win + ", action=" + event.getAction()
3051 + ", flags=" + event.getFlags()
3052 + ", keyCode=" + event.getKeyCode()
3053 + ", scanCode=" + event.getScanCode()
3054 + ", metaState=" + event.getMetaState()
3055 + ", repeatCount=" + event.getRepeatCount()
3056 + ", policyFlags=" + policyFlags);
Jeff Brown3915bb82010-11-05 15:02:16 -07003057 }
Jeff Brown49ed71d2010-12-06 17:13:33 -08003058
Jeff Brownfd23e3e2012-05-09 13:34:28 -07003059 KeyEvent fallbackEvent = null;
Jeff Brown49ed71d2010-12-06 17:13:33 -08003060 if ((event.getFlags() & KeyEvent.FLAG_FALLBACK) == 0) {
3061 final KeyCharacterMap kcm = event.getKeyCharacterMap();
Jeff Brownc1fb48d2010-12-08 16:52:09 -08003062 final int keyCode = event.getKeyCode();
3063 final int metaState = event.getMetaState();
Jeff Brownfd23e3e2012-05-09 13:34:28 -07003064 final boolean initialDown = event.getAction() == KeyEvent.ACTION_DOWN
3065 && event.getRepeatCount() == 0;
Jeff Brown49ed71d2010-12-06 17:13:33 -08003066
Jeff Brown54875002011-04-06 15:33:01 -07003067 // Check for fallback actions specified by the key character map.
Jeff Brownfd23e3e2012-05-09 13:34:28 -07003068 final FallbackAction fallbackAction;
3069 if (initialDown) {
3070 fallbackAction = kcm.getFallbackAction(keyCode, metaState);
3071 } else {
3072 fallbackAction = mFallbackActions.get(keyCode);
3073 }
3074
3075 if (fallbackAction != null) {
Jeff Brown40013652012-05-16 21:22:36 -07003076 if (DEBUG_INPUT) {
Jeff Brownfd23e3e2012-05-09 13:34:28 -07003077 Slog.d(TAG, "Fallback: keyCode=" + fallbackAction.keyCode
3078 + " metaState=" + Integer.toHexString(fallbackAction.metaState));
Jeff Brown49ed71d2010-12-06 17:13:33 -08003079 }
3080
Jeff Brownfd23e3e2012-05-09 13:34:28 -07003081 final int flags = event.getFlags() | KeyEvent.FLAG_FALLBACK;
3082 fallbackEvent = KeyEvent.obtain(
Jeff Brown49ed71d2010-12-06 17:13:33 -08003083 event.getDownTime(), event.getEventTime(),
Jeff Brownfd23e3e2012-05-09 13:34:28 -07003084 event.getAction(), fallbackAction.keyCode,
3085 event.getRepeatCount(), fallbackAction.metaState,
Jeff Brown49ed71d2010-12-06 17:13:33 -08003086 event.getDeviceId(), event.getScanCode(),
3087 flags, event.getSource(), null);
Jeff Brownfd23e3e2012-05-09 13:34:28 -07003088
3089 if (!interceptFallback(win, fallbackEvent, policyFlags)) {
3090 fallbackEvent.recycle();
3091 fallbackEvent = null;
Jeff Brown49ed71d2010-12-06 17:13:33 -08003092 }
Jeff Brownfd23e3e2012-05-09 13:34:28 -07003093
3094 if (initialDown) {
3095 mFallbackActions.put(keyCode, fallbackAction);
3096 } else if (event.getAction() == KeyEvent.ACTION_UP) {
3097 mFallbackActions.remove(keyCode);
3098 fallbackAction.recycle();
3099 }
Jeff Brown49ed71d2010-12-06 17:13:33 -08003100 }
3101 }
3102
Jeff Brown40013652012-05-16 21:22:36 -07003103 if (DEBUG_INPUT) {
Jeff Brownfd23e3e2012-05-09 13:34:28 -07003104 if (fallbackEvent == null) {
3105 Slog.d(TAG, "No fallback.");
3106 } else {
3107 Slog.d(TAG, "Performing fallback: " + fallbackEvent);
3108 }
Jeff Brown49ed71d2010-12-06 17:13:33 -08003109 }
Jeff Brownfd23e3e2012-05-09 13:34:28 -07003110 return fallbackEvent;
Jeff Brown3915bb82010-11-05 15:02:16 -07003111 }
3112
Jeff Brownfd23e3e2012-05-09 13:34:28 -07003113 private boolean interceptFallback(WindowState win, KeyEvent fallbackEvent, int policyFlags) {
Jeff Brown037c33e2014-04-09 00:31:55 -07003114 int actions = interceptKeyBeforeQueueing(fallbackEvent, policyFlags);
Jeff Brownfd23e3e2012-05-09 13:34:28 -07003115 if ((actions & ACTION_PASS_TO_USER) != 0) {
3116 long delayMillis = interceptKeyBeforeDispatching(
3117 win, fallbackEvent, policyFlags);
3118 if (delayMillis == 0) {
3119 return true;
3120 }
3121 }
3122 return false;
Jeff Brown6f2fba42011-02-19 01:08:02 -08003123 }
3124
Jeff Brownde7a8ea2012-06-13 18:28:57 -07003125 private void launchAssistLongPressAction() {
3126 performHapticFeedbackLw(null, HapticFeedbackConstants.LONG_PRESS, false);
3127 sendCloseSystemWindows(SYSTEM_DIALOG_REASON_ASSIST);
3128
3129 // launch the search activity
3130 Intent intent = new Intent(Intent.ACTION_SEARCH_LONG_PRESS);
3131 intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
3132 try {
RoboErik8a2cfc32014-05-16 11:19:38 -07003133 // TODO: This only stops the factory-installed search manager.
Jim Miller45308b12012-06-18 19:23:39 -07003134 // Need to formalize an API to handle others
Jeff Brownde7a8ea2012-06-13 18:28:57 -07003135 SearchManager searchManager = getSearchManager();
3136 if (searchManager != null) {
3137 searchManager.stopSearch();
3138 }
Bart Sears8b1c27c2015-03-18 23:51:02 +00003139 startActivityAsUser(intent, UserHandle.CURRENT);
Jeff Brownde7a8ea2012-06-13 18:28:57 -07003140 } catch (ActivityNotFoundException e) {
3141 Slog.w(TAG, "No activity to handle assist long press action.", e);
3142 }
3143 }
3144
Tim Kilbourn0e5f1102015-06-05 16:18:09 -07003145 private void launchAssistAction(String hint, int deviceId) {
Jeff Brownde7a8ea2012-06-13 18:28:57 -07003146 sendCloseSystemWindows(SYSTEM_DIALOG_REASON_ASSIST);
Maurice Lam39d13812015-07-23 20:49:20 -07003147 if (!isUserSetupComplete()) {
3148 // Disable opening assist window during setup
3149 return;
3150 }
Tim Kilbourn0e5f1102015-06-05 16:18:09 -07003151 Bundle args = null;
3152 if (deviceId > Integer.MIN_VALUE) {
3153 args = new Bundle();
3154 args.putInt(Intent.EXTRA_ASSIST_INPUT_DEVICE_ID, deviceId);
Jeff Brownde7a8ea2012-06-13 18:28:57 -07003155 }
Jorim Jaggi165ce062015-07-06 16:18:11 -07003156 if ((mContext.getResources().getConfiguration().uiMode
3157 & Configuration.UI_MODE_TYPE_MASK) == Configuration.UI_MODE_TYPE_TELEVISION) {
3158 // On TV, use legacy handling until assistants are implemented in the proper way.
3159 ((SearchManager) mContext.getSystemService(Context.SEARCH_SERVICE))
3160 .launchLegacyAssist(hint, UserHandle.myUserId(), args);
3161 } else {
3162 try {
3163 if (hint != null) {
3164 if (args == null) {
3165 args = new Bundle();
3166 }
3167 args.putBoolean(hint, true);
3168 }
3169 IStatusBarService statusbar = getStatusBarService();
3170 if (statusbar != null) {
3171 statusbar.startAssist(args);
3172 }
3173 } catch (RemoteException e) {
3174 Slog.e(TAG, "RemoteException when starting assist", e);
3175 // re-acquire status bar service next time it is needed.
3176 mStatusBarService = null;
3177 }
3178 }
Jeff Brownde7a8ea2012-06-13 18:28:57 -07003179 }
3180
Bart Sears8b1c27c2015-03-18 23:51:02 +00003181 private void startActivityAsUser(Intent intent, UserHandle handle) {
3182 if (isUserSetupComplete()) {
3183 mContext.startActivityAsUser(intent, handle);
3184 } else {
3185 Slog.i(TAG, "Not starting activity because user setup is in progress: " + intent);
3186 }
3187 }
3188
Jeff Brownde7a8ea2012-06-13 18:28:57 -07003189 private SearchManager getSearchManager() {
3190 if (mSearchManager == null) {
3191 mSearchManager = (SearchManager) mContext.getSystemService(Context.SEARCH_SERVICE);
3192 }
3193 return mSearchManager;
3194 }
3195
Jeff Browncaca8812013-05-09 13:34:33 -07003196 private void preloadRecentApps() {
3197 mPreloadedRecentApps = true;
3198 try {
3199 IStatusBarService statusbar = getStatusBarService();
3200 if (statusbar != null) {
3201 statusbar.preloadRecentApps();
3202 }
3203 } catch (RemoteException e) {
3204 Slog.e(TAG, "RemoteException when preloading recent apps", e);
3205 // re-acquire status bar service next time it is needed.
3206 mStatusBarService = null;
3207 }
3208 }
3209
3210 private void cancelPreloadRecentApps() {
3211 if (mPreloadedRecentApps) {
3212 mPreloadedRecentApps = false;
3213 try {
3214 IStatusBarService statusbar = getStatusBarService();
3215 if (statusbar != null) {
3216 statusbar.cancelPreloadRecentApps();
3217 }
3218 } catch (RemoteException e) {
Winson Chung1e8d71b2014-05-16 17:05:22 -07003219 Slog.e(TAG, "RemoteException when cancelling recent apps preload", e);
Jeff Browncaca8812013-05-09 13:34:33 -07003220 // re-acquire status bar service next time it is needed.
3221 mStatusBarService = null;
3222 }
3223 }
3224 }
3225
3226 private void toggleRecentApps() {
3227 mPreloadedRecentApps = false; // preloading no longer needs to be canceled
Jeff Browncaca8812013-05-09 13:34:33 -07003228 try {
3229 IStatusBarService statusbar = getStatusBarService();
3230 if (statusbar != null) {
3231 statusbar.toggleRecentApps();
3232 }
3233 } catch (RemoteException e) {
Winson Chung1e8d71b2014-05-16 17:05:22 -07003234 Slog.e(TAG, "RemoteException when toggling recent apps", e);
3235 // re-acquire status bar service next time it is needed.
3236 mStatusBarService = null;
3237 }
3238 }
3239
Craig Mautner84984fa2014-06-19 11:19:20 -07003240 @Override
3241 public void showRecentApps() {
3242 mHandler.removeMessages(MSG_DISPATCH_SHOW_RECENTS);
3243 mHandler.sendEmptyMessage(MSG_DISPATCH_SHOW_RECENTS);
3244 }
3245
Winson Chung1e8d71b2014-05-16 17:05:22 -07003246 private void showRecentApps(boolean triggeredFromAltTab) {
3247 mPreloadedRecentApps = false; // preloading no longer needs to be canceled
3248 try {
3249 IStatusBarService statusbar = getStatusBarService();
3250 if (statusbar != null) {
3251 statusbar.showRecentApps(triggeredFromAltTab);
3252 }
3253 } catch (RemoteException e) {
Jeff Browncaca8812013-05-09 13:34:33 -07003254 Slog.e(TAG, "RemoteException when showing recent apps", e);
3255 // re-acquire status bar service next time it is needed.
3256 mStatusBarService = null;
3257 }
3258 }
3259
Winson Chungcdcd4872014-08-05 18:00:13 -07003260 private void hideRecentApps(boolean triggeredFromAltTab, boolean triggeredFromHome) {
Winson Chung1e8d71b2014-05-16 17:05:22 -07003261 mPreloadedRecentApps = false; // preloading no longer needs to be canceled
3262 try {
3263 IStatusBarService statusbar = getStatusBarService();
3264 if (statusbar != null) {
Winson Chungcdcd4872014-08-05 18:00:13 -07003265 statusbar.hideRecentApps(triggeredFromAltTab, triggeredFromHome);
Winson Chung1e8d71b2014-05-16 17:05:22 -07003266 }
3267 } catch (RemoteException e) {
3268 Slog.e(TAG, "RemoteException when closing recent apps", e);
3269 // re-acquire status bar service next time it is needed.
3270 mStatusBarService = null;
3271 }
3272 }
3273
Filip Gruszczynskia483a1d2015-03-17 19:06:58 +00003274 void launchHomeFromHotKey() {
Bryce Lee662ed802015-04-10 20:11:39 +00003275 launchHomeFromHotKey(true /* awakenFromDreams */, true /*respectKeyguard*/);
Filip Gruszczynskia483a1d2015-03-17 19:06:58 +00003276 }
3277
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003278 /**
3279 * A home key -> launch home action was detected. Take the appropriate action
3280 * given the situation with the keyguard.
3281 */
Bryce Lee662ed802015-04-10 20:11:39 +00003282 void launchHomeFromHotKey(final boolean awakenFromDreams, final boolean respectKeyguard) {
3283 if (respectKeyguard) {
3284 if (isKeyguardShowingAndNotOccluded()) {
3285 // don't launch home if keyguard showing
3286 return;
3287 }
3288
3289 if (!mHideLockScreen && mKeyguardDelegate.isInputRestricted()) {
3290 // when in keyguard restricted mode, must first verify unlock
3291 // before launching home
3292 mKeyguardDelegate.verifyUnlock(new OnKeyguardExitResult() {
3293 @Override
3294 public void onKeyguardExitResult(boolean success) {
3295 if (success) {
3296 try {
3297 ActivityManagerNative.getDefault().stopAppSwitches();
3298 } catch (RemoteException e) {
3299 }
3300 sendCloseSystemWindows(SYSTEM_DIALOG_REASON_HOME_KEY);
3301 startDockOrHome(true /*fromHomeKey*/, awakenFromDreams);
Dianne Hackborn256dd3b2009-05-19 18:51:21 -07003302 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003303 }
Bryce Lee662ed802015-04-10 20:11:39 +00003304 });
3305 return;
3306 }
3307 }
3308
3309 // no keyguard stuff to worry about, just launch home!
3310 try {
3311 ActivityManagerNative.getDefault().stopAppSwitches();
3312 } catch (RemoteException e) {
3313 }
3314 if (mRecentsVisible) {
3315 // Hide Recents and notify it to launch Home
3316 if (awakenFromDreams) {
3317 awakenDreams();
3318 }
3319 sendCloseSystemWindows(SYSTEM_DIALOG_REASON_HOME_KEY);
3320 hideRecentApps(false, true);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003321 } else {
Bryce Lee662ed802015-04-10 20:11:39 +00003322 // Otherwise, just launch Home
3323 sendCloseSystemWindows(SYSTEM_DIALOG_REASON_HOME_KEY);
3324 startDockOrHome(true /*fromHomeKey*/, awakenFromDreams);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003325 }
3326 }
3327
John Spurlock04db1762013-05-13 12:46:41 -04003328 private final Runnable mClearHideNavigationFlag = new Runnable() {
3329 @Override
3330 public void run() {
3331 synchronized (mWindowManagerFuncs.getWindowManagerLock()) {
3332 // Clear flags.
3333 mForceClearedSystemUiFlags &=
3334 ~View.SYSTEM_UI_FLAG_HIDE_NAVIGATION;
3335 }
3336 mWindowManagerFuncs.reevaluateStatusBarVisibility();
Dianne Hackborne26ab702011-10-16 13:21:33 -07003337 }
3338 };
3339
3340 /**
3341 * Input handler used while nav bar is hidden. Captures any touch on the screen,
3342 * to determine when the nav bar should be shown and prevent applications from
3343 * receiving those touches.
3344 */
Jeff Brown32cbc38552011-12-01 14:01:49 -08003345 final class HideNavInputEventReceiver extends InputEventReceiver {
3346 public HideNavInputEventReceiver(InputChannel inputChannel, Looper looper) {
3347 super(inputChannel, looper);
3348 }
3349
Dianne Hackborndf89e652011-10-06 22:35:11 -07003350 @Override
Jeff Brown32cbc38552011-12-01 14:01:49 -08003351 public void onInputEvent(InputEvent event) {
Dianne Hackborndf89e652011-10-06 22:35:11 -07003352 boolean handled = false;
3353 try {
Jeff Brown4952dfd2011-11-30 19:23:22 -08003354 if (event instanceof MotionEvent
3355 && (event.getSource() & InputDevice.SOURCE_CLASS_POINTER) != 0) {
3356 final MotionEvent motionEvent = (MotionEvent)event;
3357 if (motionEvent.getAction() == MotionEvent.ACTION_DOWN) {
Dianne Hackborndf89e652011-10-06 22:35:11 -07003358 // When the user taps down, we re-show the nav bar.
3359 boolean changed = false;
John Spurlock04db1762013-05-13 12:46:41 -04003360 synchronized (mWindowManagerFuncs.getWindowManagerLock()) {
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07003361 // Any user activity always causes us to show the
3362 // navigation controls, if they had been hidden.
3363 // We also clear the low profile and only content
3364 // flags so that tapping on the screen will atomically
3365 // restore all currently hidden screen decorations.
3366 int newVal = mResettingSystemUiFlags |
3367 View.SYSTEM_UI_FLAG_HIDE_NAVIGATION |
3368 View.SYSTEM_UI_FLAG_LOW_PROFILE |
3369 View.SYSTEM_UI_FLAG_FULLSCREEN;
Dianne Hackborne26ab702011-10-16 13:21:33 -07003370 if (mResettingSystemUiFlags != newVal) {
3371 mResettingSystemUiFlags = newVal;
Dianne Hackborndf89e652011-10-06 22:35:11 -07003372 changed = true;
3373 }
Dianne Hackborne26ab702011-10-16 13:21:33 -07003374 // We don't allow the system's nav bar to be hidden
3375 // again for 1 second, to prevent applications from
3376 // spamming us and keeping it from being shown.
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07003377 newVal = mForceClearedSystemUiFlags |
3378 View.SYSTEM_UI_FLAG_HIDE_NAVIGATION;
Dianne Hackborne26ab702011-10-16 13:21:33 -07003379 if (mForceClearedSystemUiFlags != newVal) {
3380 mForceClearedSystemUiFlags = newVal;
3381 changed = true;
John Spurlock04db1762013-05-13 12:46:41 -04003382 mHandler.postDelayed(mClearHideNavigationFlag, 1000);
Dianne Hackborne26ab702011-10-16 13:21:33 -07003383 }
Dianne Hackborndf89e652011-10-06 22:35:11 -07003384 }
3385 if (changed) {
3386 mWindowManagerFuncs.reevaluateStatusBarVisibility();
3387 }
3388 }
3389 }
3390 } finally {
Jeff Brown32cbc38552011-12-01 14:01:49 -08003391 finishInputEvent(event, handled);
Dianne Hackborndf89e652011-10-06 22:35:11 -07003392 }
3393 }
Jeff Brown32cbc38552011-12-01 14:01:49 -08003394 }
3395 final InputEventReceiver.Factory mHideNavInputEventReceiverFactory =
3396 new InputEventReceiver.Factory() {
3397 @Override
3398 public InputEventReceiver createInputEventReceiver(
3399 InputChannel inputChannel, Looper looper) {
3400 return new HideNavInputEventReceiver(inputChannel, looper);
3401 }
Dianne Hackborndf89e652011-10-06 22:35:11 -07003402 };
3403
3404 @Override
3405 public int adjustSystemUiVisibilityLw(int visibility) {
John Spurlock5b9145b2013-08-20 15:13:47 -04003406 mStatusBarController.adjustSystemUiVisibilityLw(mLastSystemUiFlags, visibility);
3407 mNavigationBarController.adjustSystemUiVisibilityLw(mLastSystemUiFlags, visibility);
Winson Chungd42a6cf2014-06-03 16:24:04 -07003408 mRecentsVisible = (visibility & View.RECENT_APPS_VISIBLE) > 0;
John Spurlock27735a42013-08-14 17:57:38 -04003409
Dianne Hackborndf89e652011-10-06 22:35:11 -07003410 // Reset any bits in mForceClearingStatusBarVisibility that
3411 // are now clear.
Dianne Hackborne26ab702011-10-16 13:21:33 -07003412 mResettingSystemUiFlags &= visibility;
Dianne Hackborndf89e652011-10-06 22:35:11 -07003413 // Clear any bits in the new visibility that are currently being
3414 // force cleared, before reporting it.
Dianne Hackborne26ab702011-10-16 13:21:33 -07003415 return visibility & ~mResettingSystemUiFlags
3416 & ~mForceClearedSystemUiFlags;
Dianne Hackborndf89e652011-10-06 22:35:11 -07003417 }
3418
Craig Mautner69b08182012-09-05 13:07:13 -07003419 @Override
Filip Gruszczynski2987f612015-06-30 15:03:30 -07003420 public void getInsetHintLw(WindowManager.LayoutParams attrs, int displayRotation,
3421 Rect outContentInsets, Rect outStableInsets, Rect outOutsets) {
John Spurlockc6d1c602014-01-17 15:22:06 -05003422 final int fl = PolicyControl.getWindowFlags(null, attrs);
John Spurlock1db8b682014-02-18 11:18:59 -05003423 final int sysuiVis = PolicyControl.getSystemUiVisibility(null, attrs);
3424 final int systemUiVisibility = (sysuiVis | attrs.subtreeSystemUiVisibility);
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07003425
Filip Gruszczynski2987f612015-06-30 15:03:30 -07003426 final boolean useOutsets = outOutsets != null && shouldUseOutsets(attrs, fl);
3427 if (useOutsets) {
3428 int outset = ScreenShapeHelper.getWindowOutsetBottomPx(mContext.getResources());
3429 if (outset > 0) {
3430 if (displayRotation == Surface.ROTATION_0) {
3431 outOutsets.bottom += outset;
3432 } else if (displayRotation == Surface.ROTATION_90) {
3433 outOutsets.right += outset;
3434 } else if (displayRotation == Surface.ROTATION_180) {
3435 outOutsets.top += outset;
3436 } else if (displayRotation == Surface.ROTATION_270) {
3437 outOutsets.left += outset;
3438 }
3439 }
3440 }
3441
Dianne Hackborn5b5cc4d2012-05-16 13:15:00 -07003442 if ((fl & (FLAG_LAYOUT_IN_SCREEN | FLAG_LAYOUT_INSET_DECOR))
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003443 == (FLAG_LAYOUT_IN_SCREEN | FLAG_LAYOUT_INSET_DECOR)) {
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07003444 int availRight, availBottom;
Alan Viverette5a0f4ec2013-10-07 15:10:29 -07003445 if (canHideNavigationBar() &&
Dianne Hackborn5b5cc4d2012-05-16 13:15:00 -07003446 (systemUiVisibility & View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION) != 0) {
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07003447 availRight = mUnrestrictedScreenLeft + mUnrestrictedScreenWidth;
3448 availBottom = mUnrestrictedScreenTop + mUnrestrictedScreenHeight;
3449 } else {
3450 availRight = mRestrictedScreenLeft + mRestrictedScreenWidth;
3451 availBottom = mRestrictedScreenTop + mRestrictedScreenHeight;
3452 }
Dianne Hackborn5b5cc4d2012-05-16 13:15:00 -07003453 if ((systemUiVisibility & View.SYSTEM_UI_FLAG_LAYOUT_STABLE) != 0) {
3454 if ((fl & FLAG_FULLSCREEN) != 0) {
Adrian Roos37d7a682014-11-06 18:15:16 +01003455 outContentInsets.set(mStableFullscreenLeft, mStableFullscreenTop,
Dianne Hackborn5b5cc4d2012-05-16 13:15:00 -07003456 availRight - mStableFullscreenRight,
3457 availBottom - mStableFullscreenBottom);
3458 } else {
Adrian Roos37d7a682014-11-06 18:15:16 +01003459 outContentInsets.set(mStableLeft, mStableTop,
Dianne Hackborn5b5cc4d2012-05-16 13:15:00 -07003460 availRight - mStableRight, availBottom - mStableBottom);
3461 }
Dianne Hackbornc652de82013-02-15 16:32:56 -08003462 } else if ((fl & FLAG_FULLSCREEN) != 0 || (fl & FLAG_LAYOUT_IN_OVERSCAN) != 0) {
Adrian Roos37d7a682014-11-06 18:15:16 +01003463 outContentInsets.setEmpty();
Dianne Hackborn5b5cc4d2012-05-16 13:15:00 -07003464 } else if ((systemUiVisibility & (View.SYSTEM_UI_FLAG_FULLSCREEN
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07003465 | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN)) == 0) {
Adrian Roos37d7a682014-11-06 18:15:16 +01003466 outContentInsets.set(mCurLeft, mCurTop,
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07003467 availRight - mCurRight, availBottom - mCurBottom);
3468 } else {
Adrian Roos37d7a682014-11-06 18:15:16 +01003469 outContentInsets.set(mCurLeft, mCurTop,
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07003470 availRight - mCurRight, availBottom - mCurBottom);
3471 }
Adrian Roos37d7a682014-11-06 18:15:16 +01003472
3473 outStableInsets.set(mStableLeft, mStableTop,
3474 availRight - mStableRight, availBottom - mStableBottom);
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07003475 return;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003476 }
Adrian Roos37d7a682014-11-06 18:15:16 +01003477 outContentInsets.setEmpty();
3478 outStableInsets.setEmpty();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003479 }
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07003480
Filip Gruszczynski2987f612015-06-30 15:03:30 -07003481 private boolean shouldUseOutsets(WindowManager.LayoutParams attrs, int fl) {
3482 return attrs.type == TYPE_WALLPAPER || (fl & (WindowManager.LayoutParams.FLAG_FULLSCREEN
3483 | WindowManager.LayoutParams.FLAG_LAYOUT_IN_OVERSCAN)) != 0;
3484 }
3485
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003486 /** {@inheritDoc} */
Craig Mautner69b08182012-09-05 13:07:13 -07003487 @Override
3488 public void beginLayoutLw(boolean isDefaultDisplay, int displayWidth, int displayHeight,
3489 int displayRotation) {
Filip Gruszczynski2987f612015-06-30 15:03:30 -07003490 mDisplayRotation = displayRotation;
Dianne Hackbornc652de82013-02-15 16:32:56 -08003491 final int overscanLeft, overscanTop, overscanRight, overscanBottom;
3492 if (isDefaultDisplay) {
3493 switch (displayRotation) {
3494 case Surface.ROTATION_90:
3495 overscanLeft = mOverscanTop;
3496 overscanTop = mOverscanRight;
3497 overscanRight = mOverscanBottom;
3498 overscanBottom = mOverscanLeft;
3499 break;
3500 case Surface.ROTATION_180:
3501 overscanLeft = mOverscanRight;
3502 overscanTop = mOverscanBottom;
3503 overscanRight = mOverscanLeft;
3504 overscanBottom = mOverscanTop;
3505 break;
3506 case Surface.ROTATION_270:
3507 overscanLeft = mOverscanBottom;
3508 overscanTop = mOverscanLeft;
3509 overscanRight = mOverscanTop;
3510 overscanBottom = mOverscanRight;
3511 break;
3512 default:
3513 overscanLeft = mOverscanLeft;
3514 overscanTop = mOverscanTop;
3515 overscanRight = mOverscanRight;
3516 overscanBottom = mOverscanBottom;
3517 break;
3518 }
3519 } else {
3520 overscanLeft = 0;
3521 overscanTop = 0;
3522 overscanRight = 0;
3523 overscanBottom = 0;
3524 }
Dianne Hackborn313440842013-02-19 19:22:59 -08003525 mOverscanScreenLeft = mRestrictedOverscanScreenLeft = 0;
3526 mOverscanScreenTop = mRestrictedOverscanScreenTop = 0;
3527 mOverscanScreenWidth = mRestrictedOverscanScreenWidth = displayWidth;
3528 mOverscanScreenHeight = mRestrictedOverscanScreenHeight = displayHeight;
Dianne Hackbornc652de82013-02-15 16:32:56 -08003529 mSystemLeft = 0;
3530 mSystemTop = 0;
3531 mSystemRight = displayWidth;
3532 mSystemBottom = displayHeight;
3533 mUnrestrictedScreenLeft = overscanLeft;
3534 mUnrestrictedScreenTop = overscanTop;
3535 mUnrestrictedScreenWidth = displayWidth - overscanLeft - overscanRight;
3536 mUnrestrictedScreenHeight = displayHeight - overscanTop - overscanBottom;
3537 mRestrictedScreenLeft = mUnrestrictedScreenLeft;
3538 mRestrictedScreenTop = mUnrestrictedScreenTop;
John Spurlockad3e6cb2013-04-30 08:47:43 -04003539 mRestrictedScreenWidth = mSystemGestures.screenWidth = mUnrestrictedScreenWidth;
3540 mRestrictedScreenHeight = mSystemGestures.screenHeight = mUnrestrictedScreenHeight;
Dianne Hackborne30e02f2014-05-27 18:24:45 -07003541 mDockLeft = mContentLeft = mVoiceContentLeft = mStableLeft = mStableFullscreenLeft
Dianne Hackbornc652de82013-02-15 16:32:56 -08003542 = mCurLeft = mUnrestrictedScreenLeft;
Dianne Hackborne30e02f2014-05-27 18:24:45 -07003543 mDockTop = mContentTop = mVoiceContentTop = mStableTop = mStableFullscreenTop
Dianne Hackbornc652de82013-02-15 16:32:56 -08003544 = mCurTop = mUnrestrictedScreenTop;
Dianne Hackborne30e02f2014-05-27 18:24:45 -07003545 mDockRight = mContentRight = mVoiceContentRight = mStableRight = mStableFullscreenRight
Dianne Hackbornc652de82013-02-15 16:32:56 -08003546 = mCurRight = displayWidth - overscanRight;
Dianne Hackborne30e02f2014-05-27 18:24:45 -07003547 mDockBottom = mContentBottom = mVoiceContentBottom = mStableBottom = mStableFullscreenBottom
Dianne Hackbornc652de82013-02-15 16:32:56 -08003548 = mCurBottom = displayHeight - overscanBottom;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003549 mDockLayer = 0x10000000;
Dianne Hackborn5c58de32012-04-28 19:52:37 -07003550 mStatusBarLayer = -1;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003551
Daniel Sandler8956dbb2011-04-22 07:55:02 -04003552 // start with the current dock rect, which will be (0,0,displayWidth,displayHeight)
3553 final Rect pf = mTmpParentFrame;
3554 final Rect df = mTmpDisplayFrame;
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003555 final Rect of = mTmpOverscanFrame;
Daniel Sandler8956dbb2011-04-22 07:55:02 -04003556 final Rect vf = mTmpVisibleFrame;
John Spurlock46646232013-09-30 22:32:42 -04003557 final Rect dcf = mTmpDecorFrame;
Filip Gruszczynski2217f612015-05-26 11:32:08 -07003558 final Rect osf = mTmpOutsetFrame;
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003559 pf.left = df.left = of.left = vf.left = mDockLeft;
3560 pf.top = df.top = of.top = vf.top = mDockTop;
3561 pf.right = df.right = of.right = vf.right = mDockRight;
3562 pf.bottom = df.bottom = of.bottom = vf.bottom = mDockBottom;
John Spurlock46646232013-09-30 22:32:42 -04003563 dcf.setEmpty(); // Decor frame N/A for system bars.
Daniel Sandler8956dbb2011-04-22 07:55:02 -04003564
Craig Mautner69b08182012-09-05 13:07:13 -07003565 if (isDefaultDisplay) {
3566 // For purposes of putting out fake window up to steal focus, we will
3567 // drive nav being hidden only by whether it is requested.
John Spurlocke1f366f2013-08-05 12:22:40 -04003568 final int sysui = mLastSystemUiFlags;
3569 boolean navVisible = (sysui & View.SYSTEM_UI_FLAG_HIDE_NAVIGATION) == 0;
Adrian Roosea562512014-05-05 13:33:03 +02003570 boolean navTranslucent = (sysui
3571 & (View.NAVIGATION_BAR_TRANSLUCENT | View.SYSTEM_UI_TRANSPARENT)) != 0;
John Spurlockf1a36642013-10-12 17:50:42 -04003572 boolean immersive = (sysui & View.SYSTEM_UI_FLAG_IMMERSIVE) != 0;
3573 boolean immersiveSticky = (sysui & View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY) != 0;
3574 boolean navAllowedHidden = immersive || immersiveSticky;
3575 navTranslucent &= !immersiveSticky; // transient trumps translucent
Adrian Roos4fb3ee32014-08-22 19:29:09 +02003576 boolean isKeyguardShowing = isStatusBarKeyguard() && !mHideLockScreen;
3577 if (!isKeyguardShowing) {
3578 navTranslucent &= areTranslucentBarsAllowed();
3579 }
Dianne Hackborne26ab702011-10-16 13:21:33 -07003580
Craig Mautner69b08182012-09-05 13:07:13 -07003581 // When the navigation bar isn't visible, we put up a fake
3582 // input window to catch all touch events. This way we can
3583 // detect when the user presses anywhere to bring back the nav
3584 // bar and ensure the application doesn't see the event.
John Spurlockf1a36642013-10-12 17:50:42 -04003585 if (navVisible || navAllowedHidden) {
Selim Cinekf83e8242015-05-19 18:08:14 -07003586 if (mInputConsumer != null) {
3587 mInputConsumer.dismiss();
3588 mInputConsumer = null;
Craig Mautner69b08182012-09-05 13:07:13 -07003589 }
Selim Cinekf83e8242015-05-19 18:08:14 -07003590 } else if (mInputConsumer == null) {
3591 mInputConsumer = mWindowManagerFuncs.addInputConsumer(mHandler.getLooper(),
3592 mHideNavInputEventReceiverFactory);
Dianne Hackborne26ab702011-10-16 13:21:33 -07003593 }
Dianne Hackborne26ab702011-10-16 13:21:33 -07003594
Craig Mautner69b08182012-09-05 13:07:13 -07003595 // For purposes of positioning and showing the nav bar, if we have
3596 // decided that it can't be hidden (because of the screen aspect ratio),
3597 // then take that into account.
Alan Viverette5a0f4ec2013-10-07 15:10:29 -07003598 navVisible |= !canHideNavigationBar();
Dianne Hackbornf87d1962012-04-04 12:48:24 -07003599
John Spurlockad3e6cb2013-04-30 08:47:43 -04003600 boolean updateSysUiVisibility = false;
Craig Mautner69b08182012-09-05 13:07:13 -07003601 if (mNavigationBar != null) {
John Spurlock27735a42013-08-14 17:57:38 -04003602 boolean transientNavBarShowing = mNavigationBarController.isTransientShowing();
Craig Mautner69b08182012-09-05 13:07:13 -07003603 // Force the navigation bar to its appropriate place and
3604 // size. We need to do this directly, instead of relying on
3605 // it to bubble up from the nav bar, because this needs to
3606 // change atomically with screen rotations.
3607 mNavigationBarOnBottom = (!mNavigationBarCanMove || displayWidth < displayHeight);
3608 if (mNavigationBarOnBottom) {
3609 // It's a system nav bar or a portrait screen; nav bar goes on bottom.
Dianne Hackbornc652de82013-02-15 16:32:56 -08003610 int top = displayHeight - overscanBottom
3611 - mNavigationBarHeightForRotation[displayRotation];
3612 mTmpNavigationFrame.set(0, top, displayWidth, displayHeight - overscanBottom);
Craig Mautner69b08182012-09-05 13:07:13 -07003613 mStableBottom = mStableFullscreenBottom = mTmpNavigationFrame.top;
John Spurlockf95b89a2013-10-10 22:10:42 -04003614 if (transientNavBarShowing) {
John Spurlock27735a42013-08-14 17:57:38 -04003615 mNavigationBarController.setBarShowingLw(true);
John Spurlockad3e6cb2013-04-30 08:47:43 -04003616 } else if (navVisible) {
John Spurlock27735a42013-08-14 17:57:38 -04003617 mNavigationBarController.setBarShowingLw(true);
Craig Mautner69b08182012-09-05 13:07:13 -07003618 mDockBottom = mTmpNavigationFrame.top;
Dianne Hackborn313440842013-02-19 19:22:59 -08003619 mRestrictedScreenHeight = mDockBottom - mRestrictedScreenTop;
3620 mRestrictedOverscanScreenHeight = mDockBottom - mRestrictedOverscanScreenTop;
Craig Mautner69b08182012-09-05 13:07:13 -07003621 } else {
3622 // We currently want to hide the navigation UI.
John Spurlock27735a42013-08-14 17:57:38 -04003623 mNavigationBarController.setBarShowingLw(false);
Craig Mautner69b08182012-09-05 13:07:13 -07003624 }
John Spurlockc6d1c602014-01-17 15:22:06 -05003625 if (navVisible && !navTranslucent && !navAllowedHidden
3626 && !mNavigationBar.isAnimatingLw()
John Spurlockbd957402013-10-03 11:38:39 -04003627 && !mNavigationBarController.wasRecentlyTranslucent()) {
John Spurlocke1f366f2013-08-05 12:22:40 -04003628 // If the opaque nav bar is currently requested to be visible,
Craig Mautner69b08182012-09-05 13:07:13 -07003629 // and not in the process of animating on or off, then
3630 // we can tell the app that it is covered by it.
3631 mSystemBottom = mTmpNavigationFrame.top;
3632 }
Dianne Hackbornf87d1962012-04-04 12:48:24 -07003633 } else {
Craig Mautner69b08182012-09-05 13:07:13 -07003634 // Landscape screen; nav bar goes to the right.
Dianne Hackbornc652de82013-02-15 16:32:56 -08003635 int left = displayWidth - overscanRight
3636 - mNavigationBarWidthForRotation[displayRotation];
3637 mTmpNavigationFrame.set(left, 0, displayWidth - overscanRight, displayHeight);
Craig Mautner69b08182012-09-05 13:07:13 -07003638 mStableRight = mStableFullscreenRight = mTmpNavigationFrame.left;
John Spurlockf95b89a2013-10-10 22:10:42 -04003639 if (transientNavBarShowing) {
John Spurlock27735a42013-08-14 17:57:38 -04003640 mNavigationBarController.setBarShowingLw(true);
John Spurlockad3e6cb2013-04-30 08:47:43 -04003641 } else if (navVisible) {
John Spurlock27735a42013-08-14 17:57:38 -04003642 mNavigationBarController.setBarShowingLw(true);
Craig Mautner69b08182012-09-05 13:07:13 -07003643 mDockRight = mTmpNavigationFrame.left;
Dianne Hackborn313440842013-02-19 19:22:59 -08003644 mRestrictedScreenWidth = mDockRight - mRestrictedScreenLeft;
3645 mRestrictedOverscanScreenWidth = mDockRight - mRestrictedOverscanScreenLeft;
Craig Mautner69b08182012-09-05 13:07:13 -07003646 } else {
3647 // We currently want to hide the navigation UI.
John Spurlock27735a42013-08-14 17:57:38 -04003648 mNavigationBarController.setBarShowingLw(false);
Craig Mautner69b08182012-09-05 13:07:13 -07003649 }
Adrian Roosfe836fa2015-08-11 17:36:43 -07003650 if (navVisible && !navTranslucent && !navAllowedHidden
3651 && !mNavigationBar.isAnimatingLw()
John Spurlockbd957402013-10-03 11:38:39 -04003652 && !mNavigationBarController.wasRecentlyTranslucent()) {
Craig Mautner69b08182012-09-05 13:07:13 -07003653 // If the nav bar is currently requested to be visible,
3654 // and not in the process of animating on or off, then
3655 // we can tell the app that it is covered by it.
3656 mSystemRight = mTmpNavigationFrame.left;
3657 }
Dianne Hackbornf87d1962012-04-04 12:48:24 -07003658 }
Craig Mautner69b08182012-09-05 13:07:13 -07003659 // Make sure the content and current rectangles are updated to
3660 // account for the restrictions from the navigation bar.
Dianne Hackborne30e02f2014-05-27 18:24:45 -07003661 mContentTop = mVoiceContentTop = mCurTop = mDockTop;
3662 mContentBottom = mVoiceContentBottom = mCurBottom = mDockBottom;
3663 mContentLeft = mVoiceContentLeft = mCurLeft = mDockLeft;
3664 mContentRight = mVoiceContentRight = mCurRight = mDockRight;
Craig Mautner69b08182012-09-05 13:07:13 -07003665 mStatusBarLayer = mNavigationBar.getSurfaceLayer();
3666 // And compute the final frame.
3667 mNavigationBar.computeFrameLw(mTmpNavigationFrame, mTmpNavigationFrame,
Adrian Roosfa104232014-06-20 16:10:14 -07003668 mTmpNavigationFrame, mTmpNavigationFrame, mTmpNavigationFrame, dcf,
Filip Gruszczynski2217f612015-05-26 11:32:08 -07003669 mTmpNavigationFrame, mTmpNavigationFrame);
Craig Mautnereda67292013-04-28 13:50:14 -07003670 if (DEBUG_LAYOUT) Slog.i(TAG, "mNavigationBar frame: " + mTmpNavigationFrame);
John Spurlock27735a42013-08-14 17:57:38 -04003671 if (mNavigationBarController.checkHiddenLw()) {
John Spurlockad3e6cb2013-04-30 08:47:43 -04003672 updateSysUiVisibility = true;
3673 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003674 }
Craig Mautnereda67292013-04-28 13:50:14 -07003675 if (DEBUG_LAYOUT) Slog.i(TAG, String.format("mDock rect: (%d,%d - %d,%d)",
Craig Mautner69b08182012-09-05 13:07:13 -07003676 mDockLeft, mDockTop, mDockRight, mDockBottom));
3677
3678 // decide where the status bar goes ahead of time
3679 if (mStatusBar != null) {
3680 // apply any navigation bar insets
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003681 pf.left = df.left = of.left = mUnrestrictedScreenLeft;
3682 pf.top = df.top = of.top = mUnrestrictedScreenTop;
3683 pf.right = df.right = of.right = mUnrestrictedScreenWidth + mUnrestrictedScreenLeft;
3684 pf.bottom = df.bottom = of.bottom = mUnrestrictedScreenHeight
3685 + mUnrestrictedScreenTop;
Craig Mautner69b08182012-09-05 13:07:13 -07003686 vf.left = mStableLeft;
3687 vf.top = mStableTop;
3688 vf.right = mStableRight;
3689 vf.bottom = mStableBottom;
3690
3691 mStatusBarLayer = mStatusBar.getSurfaceLayer();
3692
3693 // Let the status bar determine its size.
Filip Gruszczynski2217f612015-05-26 11:32:08 -07003694 mStatusBar.computeFrameLw(pf /* parentFrame */, df /* displayFrame */,
3695 vf /* overlayFrame */, vf /* contentFrame */, vf /* visibleFrame */,
3696 dcf /* decorFrame */, vf /* stableFrame */, vf /* outsetFrame */);
Craig Mautner69b08182012-09-05 13:07:13 -07003697
3698 // For layout, the status bar is always at the top with our fixed height.
3699 mStableTop = mUnrestrictedScreenTop + mStatusBarHeight;
3700
John Spurlocke1f366f2013-08-05 12:22:40 -04003701 boolean statusBarTransient = (sysui & View.STATUS_BAR_TRANSIENT) != 0;
Adrian Roosea562512014-05-05 13:33:03 +02003702 boolean statusBarTranslucent = (sysui
3703 & (View.STATUS_BAR_TRANSLUCENT | View.SYSTEM_UI_TRANSPARENT)) != 0;
Adrian Roos4fb3ee32014-08-22 19:29:09 +02003704 if (!isKeyguardShowing) {
3705 statusBarTranslucent &= areTranslucentBarsAllowed();
3706 }
John Spurlock32beb2c2013-03-11 10:16:47 -04003707
Craig Mautner69b08182012-09-05 13:07:13 -07003708 // If the status bar is hidden, we don't want to cause
3709 // windows behind it to scroll.
John Spurlockeda1f692013-09-16 11:38:44 -04003710 if (mStatusBar.isVisibleLw() && !statusBarTransient) {
Craig Mautner69b08182012-09-05 13:07:13 -07003711 // Status bar may go away, so the screen area it occupies
3712 // is available to apps but just covering them when the
3713 // status bar is visible.
3714 mDockTop = mUnrestrictedScreenTop + mStatusBarHeight;
3715
Dianne Hackborne30e02f2014-05-27 18:24:45 -07003716 mContentTop = mVoiceContentTop = mCurTop = mDockTop;
3717 mContentBottom = mVoiceContentBottom = mCurBottom = mDockBottom;
3718 mContentLeft = mVoiceContentLeft = mCurLeft = mDockLeft;
3719 mContentRight = mVoiceContentRight = mCurRight = mDockRight;
Craig Mautner69b08182012-09-05 13:07:13 -07003720
Craig Mautnereda67292013-04-28 13:50:14 -07003721 if (DEBUG_LAYOUT) Slog.v(TAG, "Status bar: " +
Craig Mautner69b08182012-09-05 13:07:13 -07003722 String.format(
3723 "dock=[%d,%d][%d,%d] content=[%d,%d][%d,%d] cur=[%d,%d][%d,%d]",
3724 mDockLeft, mDockTop, mDockRight, mDockBottom,
3725 mContentLeft, mContentTop, mContentRight, mContentBottom,
3726 mCurLeft, mCurTop, mCurRight, mCurBottom));
3727 }
John Spurlocke1f366f2013-08-05 12:22:40 -04003728 if (mStatusBar.isVisibleLw() && !mStatusBar.isAnimatingLw()
John Spurlockbd957402013-10-03 11:38:39 -04003729 && !statusBarTransient && !statusBarTranslucent
3730 && !mStatusBarController.wasRecentlyTranslucent()) {
John Spurlocke1f366f2013-08-05 12:22:40 -04003731 // If the opaque status bar is currently requested to be visible,
Craig Mautner69b08182012-09-05 13:07:13 -07003732 // and not in the process of animating on or off, then
3733 // we can tell the app that it is covered by it.
3734 mSystemTop = mUnrestrictedScreenTop + mStatusBarHeight;
3735 }
John Spurlock27735a42013-08-14 17:57:38 -04003736 if (mStatusBarController.checkHiddenLw()) {
John Spurlockad3e6cb2013-04-30 08:47:43 -04003737 updateSysUiVisibility = true;
John Spurlock32beb2c2013-03-11 10:16:47 -04003738 }
Dianne Hackborn5c58de32012-04-28 19:52:37 -07003739 }
John Spurlockad3e6cb2013-04-30 08:47:43 -04003740 if (updateSysUiVisibility) {
3741 updateSystemUiVisibilityLw();
3742 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003743 }
3744 }
3745
Dianne Hackborn85afd1b2012-05-13 13:31:06 -07003746 /** {@inheritDoc} */
Craig Mautner967212c2013-04-13 21:10:58 -07003747 @Override
John Spurlock46646232013-09-30 22:32:42 -04003748 public int getSystemDecorLayerLw() {
Bryce Lee2ed3e5f2015-04-01 22:09:19 +00003749 if (mStatusBar != null && mStatusBar.isVisibleLw()) {
3750 return mStatusBar.getSurfaceLayer();
3751 }
3752
3753 if (mNavigationBar != null && mNavigationBar.isVisibleLw()) {
3754 return mNavigationBar.getSurfaceLayer();
3755 }
3756
Dianne Hackborn85afd1b2012-05-13 13:31:06 -07003757 return 0;
3758 }
3759
Craig Mautner967212c2013-04-13 21:10:58 -07003760 @Override
3761 public void getContentRectLw(Rect r) {
3762 r.set(mContentLeft, mContentTop, mContentRight, mContentBottom);
3763 }
3764
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003765 void setAttachedWindowFrames(WindowState win, int fl, int adjust, WindowState attached,
3766 boolean insetDecors, Rect pf, Rect df, Rect of, Rect cf, Rect vf) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003767 if (win.getSurfaceLayer() > mDockLayer && attached.getSurfaceLayer() < mDockLayer) {
3768 // Here's a special case: if this attached window is a panel that is
3769 // above the dock window, and the window it is attached to is below
3770 // the dock window, then the frames we computed for the window it is
3771 // attached to can not be used because the dock is effectively part
3772 // of the underlying window and the attached window is floating on top
3773 // of the whole thing. So, we ignore the attached window and explicitly
3774 // compute the frames that would be appropriate without the dock.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003775 df.left = of.left = cf.left = vf.left = mDockLeft;
3776 df.top = of.top = cf.top = vf.top = mDockTop;
3777 df.right = of.right = cf.right = vf.right = mDockRight;
3778 df.bottom = of.bottom = cf.bottom = vf.bottom = mDockBottom;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003779 } else {
3780 // The effective display frame of the attached window depends on
3781 // whether it is taking care of insetting its content. If not,
3782 // we need to use the parent's content frame so that the entire
3783 // window is positioned within that content. Otherwise we can use
Wale Ogunwale393b1c12014-10-18 16:22:01 -07003784 // the overscan frame and let the attached window take care of
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003785 // positioning its content appropriately.
Dianne Hackborndea3ef72010-10-28 14:24:22 -07003786 if (adjust != SOFT_INPUT_ADJUST_RESIZE) {
Wale Ogunwale393b1c12014-10-18 16:22:01 -07003787 // Set the content frame of the attached window to the parent's decor frame
3788 // (same as content frame when IME isn't present) if specifically requested by
3789 // setting {@link WindowManager.LayoutParams#FLAG_LAYOUT_ATTACHED_IN_DECOR} flag.
3790 // Otherwise, use the overscan frame.
3791 cf.set((fl & FLAG_LAYOUT_ATTACHED_IN_DECOR) != 0
3792 ? attached.getContentFrameLw() : attached.getOverscanFrameLw());
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003793 } else {
3794 // If the window is resizing, then we want to base the content
3795 // frame on our attached content frame to resize... however,
3796 // things can be tricky if the attached window is NOT in resize
3797 // mode, in which case its content frame will be larger.
3798 // Ungh. So to deal with that, make sure the content frame
3799 // we end up using is not covering the IM dock.
3800 cf.set(attached.getContentFrameLw());
Dianne Hackborne30e02f2014-05-27 18:24:45 -07003801 if (attached.isVoiceInteraction()) {
3802 if (cf.left < mVoiceContentLeft) cf.left = mVoiceContentLeft;
3803 if (cf.top < mVoiceContentTop) cf.top = mVoiceContentTop;
3804 if (cf.right > mVoiceContentRight) cf.right = mVoiceContentRight;
3805 if (cf.bottom > mVoiceContentBottom) cf.bottom = mVoiceContentBottom;
3806 } else if (attached.getSurfaceLayer() < mDockLayer) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003807 if (cf.left < mContentLeft) cf.left = mContentLeft;
3808 if (cf.top < mContentTop) cf.top = mContentTop;
3809 if (cf.right > mContentRight) cf.right = mContentRight;
3810 if (cf.bottom > mContentBottom) cf.bottom = mContentBottom;
3811 }
3812 }
3813 df.set(insetDecors ? attached.getDisplayFrameLw() : cf);
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003814 of.set(insetDecors ? attached.getOverscanFrameLw() : cf);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003815 vf.set(attached.getVisibleFrameLw());
3816 }
3817 // The LAYOUT_IN_SCREEN flag is used to determine whether the attached
3818 // window should be positioned relative to its parent or the entire
3819 // screen.
3820 pf.set((fl & FLAG_LAYOUT_IN_SCREEN) == 0
3821 ? attached.getFrameLw() : df);
3822 }
Dianne Hackborn5b5cc4d2012-05-16 13:15:00 -07003823
3824 private void applyStableConstraints(int sysui, int fl, Rect r) {
3825 if ((sysui & View.SYSTEM_UI_FLAG_LAYOUT_STABLE) != 0) {
3826 // If app is requesting a stable layout, don't let the
3827 // content insets go below the stable values.
3828 if ((fl & FLAG_FULLSCREEN) != 0) {
3829 if (r.left < mStableFullscreenLeft) r.left = mStableFullscreenLeft;
3830 if (r.top < mStableFullscreenTop) r.top = mStableFullscreenTop;
3831 if (r.right > mStableFullscreenRight) r.right = mStableFullscreenRight;
3832 if (r.bottom > mStableFullscreenBottom) r.bottom = mStableFullscreenBottom;
3833 } else {
3834 if (r.left < mStableLeft) r.left = mStableLeft;
3835 if (r.top < mStableTop) r.top = mStableTop;
3836 if (r.right > mStableRight) r.right = mStableRight;
3837 if (r.bottom > mStableBottom) r.bottom = mStableBottom;
3838 }
3839 }
3840 }
3841
Jorim Jaggiaa806142015-05-20 18:04:16 -07003842 private boolean canReceiveInput(WindowState win) {
3843 boolean notFocusable =
3844 (win.getAttrs().flags & WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE) != 0;
3845 boolean altFocusableIm =
3846 (win.getAttrs().flags & WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM) != 0;
3847 boolean notFocusableForIm = notFocusable ^ altFocusableIm;
3848 return !notFocusableForIm;
3849 }
3850
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003851 /** {@inheritDoc} */
Craig Mautner69b08182012-09-05 13:07:13 -07003852 @Override
Craig Mautnerc9457fa2014-06-06 14:27:48 -07003853 public void layoutWindowLw(WindowState win, WindowState attached) {
Jorim Jaggiaa806142015-05-20 18:04:16 -07003854 // We've already done the navigation bar and status bar. If the status bar can receive
3855 // input, we need to layout it again to accomodate for the IME window.
3856 if ((win == mStatusBar && !canReceiveInput(win)) || win == mNavigationBar) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003857 return;
3858 }
Jorim Jaggiaa806142015-05-20 18:04:16 -07003859 final WindowManager.LayoutParams attrs = win.getAttrs();
Craig Mautner69b08182012-09-05 13:07:13 -07003860 final boolean isDefaultDisplay = win.isDefaultDisplay();
3861 final boolean needsToOffsetInputMethodTarget = isDefaultDisplay &&
satok1bc0a492012-04-25 22:47:12 +09003862 (win == mLastInputMethodTargetWindow && mLastInputMethodWindow != null);
3863 if (needsToOffsetInputMethodTarget) {
Craig Mautnereda67292013-04-28 13:50:14 -07003864 if (DEBUG_LAYOUT) Slog.i(TAG, "Offset ime target window by the last ime window state");
satok1bc0a492012-04-25 22:47:12 +09003865 offsetInputMethodWindowLw(mLastInputMethodWindow);
3866 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003867
John Spurlockc6d1c602014-01-17 15:22:06 -05003868 final int fl = PolicyControl.getWindowFlags(win, attrs);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003869 final int sim = attrs.softInputMode;
John Spurlock1db8b682014-02-18 11:18:59 -05003870 final int sysUiFl = PolicyControl.getSystemUiVisibility(win, null);
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07003871
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003872 final Rect pf = mTmpParentFrame;
3873 final Rect df = mTmpDisplayFrame;
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003874 final Rect of = mTmpOverscanFrame;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003875 final Rect cf = mTmpContentFrame;
3876 final Rect vf = mTmpVisibleFrame;
John Spurlock46646232013-09-30 22:32:42 -04003877 final Rect dcf = mTmpDecorFrame;
Adrian Roosfa104232014-06-20 16:10:14 -07003878 final Rect sf = mTmpStableFrame;
Filip Gruszczynski2217f612015-05-26 11:32:08 -07003879 Rect osf = null;
John Spurlock46646232013-09-30 22:32:42 -04003880 dcf.setEmpty();
Craig Mautner69b08182012-09-05 13:07:13 -07003881
3882 final boolean hasNavBar = (isDefaultDisplay && mHasNavigationBar
Daniel Sandler36412a72011-08-04 09:35:13 -04003883 && mNavigationBar != null && mNavigationBar.isVisibleLw());
Daniel Sandler8956dbb2011-04-22 07:55:02 -04003884
Craig Mautnerf683b562012-10-02 11:10:57 -07003885 final int adjust = sim & SOFT_INPUT_MASK_ADJUST;
3886
Adrian Roosfa104232014-06-20 16:10:14 -07003887 if (isDefaultDisplay) {
3888 sf.set(mStableLeft, mStableTop, mStableRight, mStableBottom);
3889 } else {
3890 sf.set(mOverscanLeft, mOverscanTop, mOverscanRight, mOverscanBottom);
3891 }
3892
Craig Mautner69b08182012-09-05 13:07:13 -07003893 if (!isDefaultDisplay) {
3894 if (attached != null) {
3895 // If this window is attached to another, our display
3896 // frame is the same as the one we are attached to.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003897 setAttachedWindowFrames(win, fl, adjust, attached, true, pf, df, of, cf, vf);
Craig Mautner69b08182012-09-05 13:07:13 -07003898 } else {
3899 // Give the window full screen.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003900 pf.left = df.left = of.left = cf.left = mOverscanScreenLeft;
3901 pf.top = df.top = of.top = cf.top = mOverscanScreenTop;
3902 pf.right = df.right = of.right = cf.right
Dianne Hackbornc652de82013-02-15 16:32:56 -08003903 = mOverscanScreenLeft + mOverscanScreenWidth;
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003904 pf.bottom = df.bottom = of.bottom = cf.bottom
Dianne Hackbornc652de82013-02-15 16:32:56 -08003905 = mOverscanScreenTop + mOverscanScreenHeight;
Craig Mautner69b08182012-09-05 13:07:13 -07003906 }
Jorim Jaggi225d3b52015-04-01 11:18:57 -07003907 } else if (attrs.type == TYPE_INPUT_METHOD) {
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003908 pf.left = df.left = of.left = cf.left = vf.left = mDockLeft;
3909 pf.top = df.top = of.top = cf.top = vf.top = mDockTop;
3910 pf.right = df.right = of.right = cf.right = vf.right = mDockRight;
John Spurlockc68d5772013-10-08 11:47:58 -04003911 // IM dock windows layout below the nav bar...
John Spurlock57beb3b2013-10-10 10:27:44 -04003912 pf.bottom = df.bottom = of.bottom = mUnrestrictedScreenTop + mUnrestrictedScreenHeight;
John Spurlockc68d5772013-10-08 11:47:58 -04003913 // ...with content insets above the nav bar
3914 cf.bottom = vf.bottom = mStableBottom;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003915 // IM dock windows always go to the bottom of the screen.
3916 attrs.gravity = Gravity.BOTTOM;
3917 mDockLayer = win.getSurfaceLayer();
Jorim Jaggi225d3b52015-04-01 11:18:57 -07003918 } else if (attrs.type == TYPE_VOICE_INTERACTION) {
Stefan Kuhne2f280d062015-06-18 07:20:33 -10003919 pf.left = df.left = of.left = mUnrestrictedScreenLeft;
Jorim Jaggi225d3b52015-04-01 11:18:57 -07003920 pf.top = df.top = of.top = mUnrestrictedScreenTop;
Stefan Kuhne2f280d062015-06-18 07:20:33 -10003921 pf.right = df.right = of.right = mUnrestrictedScreenLeft + mUnrestrictedScreenWidth;
3922 pf.bottom = df.bottom = of.bottom = mUnrestrictedScreenTop + mUnrestrictedScreenHeight;
Jorim Jaggi225d3b52015-04-01 11:18:57 -07003923 cf.bottom = vf.bottom = mStableBottom;
Stefan Kuhne2f280d062015-06-18 07:20:33 -10003924 // Note: In Phone landscape mode, the button bar should also be excluded.
3925 cf.right = vf.right = mStableRight;
3926 cf.left = vf.left = mStableLeft;
Jorim Jaggi225d3b52015-04-01 11:18:57 -07003927 cf.top = vf.top = mStableTop;
Jorim Jaggiaa806142015-05-20 18:04:16 -07003928 } else if (win == mStatusBar) {
Jorim Jaggie0700182014-08-21 01:12:37 +02003929 pf.left = df.left = of.left = mUnrestrictedScreenLeft;
3930 pf.top = df.top = of.top = mUnrestrictedScreenTop;
3931 pf.right = df.right = of.right = mUnrestrictedScreenWidth + mUnrestrictedScreenLeft;
3932 pf.bottom = df.bottom = of.bottom = mUnrestrictedScreenHeight + mUnrestrictedScreenTop;
3933 cf.left = vf.left = mStableLeft;
3934 cf.top = vf.top = mStableTop;
3935 cf.right = vf.right = mStableRight;
3936 vf.bottom = mStableBottom;
3937 cf.bottom = mContentBottom;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003938 } else {
John Spurlock46646232013-09-30 22:32:42 -04003939
3940 // Default policy decor for the default display
3941 dcf.left = mSystemLeft;
3942 dcf.top = mSystemTop;
3943 dcf.right = mSystemRight;
3944 dcf.bottom = mSystemBottom;
John Spurlockbd957402013-10-03 11:38:39 -04003945 final boolean inheritTranslucentDecor = (attrs.privateFlags
3946 & WindowManager.LayoutParams.PRIVATE_FLAG_INHERIT_TRANSLUCENT_DECOR) != 0;
John Spurlock65567d42013-10-08 10:08:32 -04003947 final boolean isAppWindow =
3948 attrs.type >= WindowManager.LayoutParams.FIRST_APPLICATION_WINDOW &&
3949 attrs.type <= WindowManager.LayoutParams.LAST_APPLICATION_WINDOW;
3950 final boolean topAtRest =
3951 win == mTopFullscreenOpaqueWindowState && !win.isAnimatingLw();
3952 if (isAppWindow && !inheritTranslucentDecor && !topAtRest) {
John Spurlockbd957402013-10-03 11:38:39 -04003953 if ((sysUiFl & View.SYSTEM_UI_FLAG_FULLSCREEN) == 0
3954 && (fl & WindowManager.LayoutParams.FLAG_FULLSCREEN) == 0
Adrian Roosea562512014-05-05 13:33:03 +02003955 && (fl & WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS) == 0
3956 && (fl & WindowManager.LayoutParams.
3957 FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS) == 0) {
John Spurlock46646232013-09-30 22:32:42 -04003958 // Ensure policy decor includes status bar
3959 dcf.top = mStableTop;
3960 }
John Spurlockbd957402013-10-03 11:38:39 -04003961 if ((fl & WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION) == 0
Adrian Roosea562512014-05-05 13:33:03 +02003962 && (sysUiFl & View.SYSTEM_UI_FLAG_HIDE_NAVIGATION) == 0
3963 && (fl & WindowManager.LayoutParams.
3964 FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS) == 0) {
John Spurlock46646232013-09-30 22:32:42 -04003965 // Ensure policy decor includes navigation bar
3966 dcf.bottom = mStableBottom;
3967 dcf.right = mStableRight;
3968 }
3969 }
3970
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003971 if ((fl & (FLAG_LAYOUT_IN_SCREEN | FLAG_LAYOUT_INSET_DECOR))
3972 == (FLAG_LAYOUT_IN_SCREEN | FLAG_LAYOUT_INSET_DECOR)) {
RoboErik8a2cfc32014-05-16 11:19:38 -07003973 if (DEBUG_LAYOUT) Slog.v(TAG, "layoutWindowLw(" + attrs.getTitle()
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003974 + "): IN_SCREEN, INSET_DECOR");
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003975 // This is the case for a normal activity window: we want it
3976 // to cover all of the screen space, and it can take care of
3977 // moving its contents to account for screen decorations that
3978 // intrude into that space.
3979 if (attached != null) {
3980 // If this window is attached to another, our display
3981 // frame is the same as the one we are attached to.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003982 setAttachedWindowFrames(win, fl, adjust, attached, true, pf, df, of, cf, vf);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003983 } else {
Daniel Sandler8956dbb2011-04-22 07:55:02 -04003984 if (attrs.type == TYPE_STATUS_BAR_PANEL
3985 || attrs.type == TYPE_STATUS_BAR_SUB_PANEL) {
Joe Onorato29fc2c92010-11-24 10:26:50 -08003986 // Status bar panels are the only windows who can go on top of
3987 // the status bar. They are protected by the STATUS_BAR_SERVICE
3988 // permission, so they have the same privileges as the status
3989 // bar itself.
Daniel Sandler8956dbb2011-04-22 07:55:02 -04003990 //
Daniel Sandler8e8b4152011-07-21 01:16:43 -04003991 // However, they should still dodge the navigation bar if it exists.
Daniel Sandler8956dbb2011-04-22 07:55:02 -04003992
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003993 pf.left = df.left = of.left = hasNavBar
3994 ? mDockLeft : mUnrestrictedScreenLeft;
3995 pf.top = df.top = of.top = mUnrestrictedScreenTop;
3996 pf.right = df.right = of.right = hasNavBar
3997 ? mRestrictedScreenLeft+mRestrictedScreenWidth
3998 : mUnrestrictedScreenLeft + mUnrestrictedScreenWidth;
3999 pf.bottom = df.bottom = of.bottom = hasNavBar
4000 ? mRestrictedScreenTop+mRestrictedScreenHeight
4001 : mUnrestrictedScreenTop + mUnrestrictedScreenHeight;
Daniel Sandler8956dbb2011-04-22 07:55:02 -04004002
Craig Mautnereda67292013-04-28 13:50:14 -07004003 if (DEBUG_LAYOUT) Slog.v(TAG, String.format(
Daniel Sandler8e8b4152011-07-21 01:16:43 -04004004 "Laying out status bar window: (%d,%d - %d,%d)",
4005 pf.left, pf.top, pf.right, pf.bottom));
John Spurlock46646232013-09-30 22:32:42 -04004006 } else if ((fl & FLAG_LAYOUT_IN_OVERSCAN) != 0
Dianne Hackbornc652de82013-02-15 16:32:56 -08004007 && attrs.type >= WindowManager.LayoutParams.FIRST_APPLICATION_WINDOW
4008 && attrs.type <= WindowManager.LayoutParams.LAST_SUB_WINDOW) {
4009 // Asking to layout into the overscan region, so give it that pure
4010 // unrestricted area.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08004011 pf.left = df.left = of.left = mOverscanScreenLeft;
4012 pf.top = df.top = of.top = mOverscanScreenTop;
4013 pf.right = df.right = of.right = mOverscanScreenLeft + mOverscanScreenWidth;
4014 pf.bottom = df.bottom = of.bottom = mOverscanScreenTop
4015 + mOverscanScreenHeight;
Alan Viverette5a0f4ec2013-10-07 15:10:29 -07004016 } else if (canHideNavigationBar()
Dianne Hackbornf87d1962012-04-04 12:48:24 -07004017 && (sysUiFl & View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION) != 0
Jorim Jaggi380ecb82014-03-14 17:25:20 +01004018 && attrs.type >= WindowManager.LayoutParams.FIRST_APPLICATION_WINDOW
4019 && attrs.type <= WindowManager.LayoutParams.LAST_SUB_WINDOW) {
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07004020 // Asking for layout as if the nav bar is hidden, lets the
Dianne Hackbornc652de82013-02-15 16:32:56 -08004021 // application extend into the unrestricted overscan screen area. We
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07004022 // only do this for application windows to ensure no window that
4023 // can be above the nav bar can do this.
Dianne Hackborn313440842013-02-19 19:22:59 -08004024 pf.left = df.left = mOverscanScreenLeft;
4025 pf.top = df.top = mOverscanScreenTop;
4026 pf.right = df.right = mOverscanScreenLeft + mOverscanScreenWidth;
4027 pf.bottom = df.bottom = mOverscanScreenTop + mOverscanScreenHeight;
Dianne Hackbornc4aad012013-02-22 15:05:25 -08004028 // We need to tell the app about where the frame inside the overscan
4029 // is, so it can inset its content by that amount -- it didn't ask
4030 // to actually extend itself into the overscan region.
4031 of.left = mUnrestrictedScreenLeft;
4032 of.top = mUnrestrictedScreenTop;
4033 of.right = mUnrestrictedScreenLeft + mUnrestrictedScreenWidth;
4034 of.bottom = mUnrestrictedScreenTop + mUnrestrictedScreenHeight;
Joe Onorato29fc2c92010-11-24 10:26:50 -08004035 } else {
Dianne Hackborn313440842013-02-19 19:22:59 -08004036 pf.left = df.left = mRestrictedOverscanScreenLeft;
4037 pf.top = df.top = mRestrictedOverscanScreenTop;
4038 pf.right = df.right = mRestrictedOverscanScreenLeft
4039 + mRestrictedOverscanScreenWidth;
4040 pf.bottom = df.bottom = mRestrictedOverscanScreenTop
4041 + mRestrictedOverscanScreenHeight;
Dianne Hackbornc4aad012013-02-22 15:05:25 -08004042 // We need to tell the app about where the frame inside the overscan
4043 // is, so it can inset its content by that amount -- it didn't ask
4044 // to actually extend itself into the overscan region.
4045 of.left = mUnrestrictedScreenLeft;
4046 of.top = mUnrestrictedScreenTop;
4047 of.right = mUnrestrictedScreenLeft + mUnrestrictedScreenWidth;
4048 of.bottom = mUnrestrictedScreenTop + mUnrestrictedScreenHeight;
Joe Onorato29fc2c92010-11-24 10:26:50 -08004049 }
Craig Mautner69b08182012-09-05 13:07:13 -07004050
John Spurlock46646232013-09-30 22:32:42 -04004051 if ((fl & FLAG_FULLSCREEN) == 0) {
Dianne Hackborne30e02f2014-05-27 18:24:45 -07004052 if (win.isVoiceInteraction()) {
4053 cf.left = mVoiceContentLeft;
4054 cf.top = mVoiceContentTop;
4055 cf.right = mVoiceContentRight;
4056 cf.bottom = mVoiceContentBottom;
Dianne Hackbornc4aad012013-02-22 15:05:25 -08004057 } else {
Dianne Hackborne30e02f2014-05-27 18:24:45 -07004058 if (adjust != SOFT_INPUT_ADJUST_RESIZE) {
4059 cf.left = mDockLeft;
4060 cf.top = mDockTop;
4061 cf.right = mDockRight;
4062 cf.bottom = mDockBottom;
4063 } else {
4064 cf.left = mContentLeft;
4065 cf.top = mContentTop;
4066 cf.right = mContentRight;
4067 cf.bottom = mContentBottom;
4068 }
Dianne Hackbornc4aad012013-02-22 15:05:25 -08004069 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004070 } else {
Dianne Hackbornc4aad012013-02-22 15:05:25 -08004071 // Full screen windows are always given a layout that is as if the
4072 // status bar and other transient decors are gone. This is to avoid
4073 // bad states when moving from a window that is not hding the
4074 // status bar to one that is.
4075 cf.left = mRestrictedScreenLeft;
4076 cf.top = mRestrictedScreenTop;
4077 cf.right = mRestrictedScreenLeft + mRestrictedScreenWidth;
4078 cf.bottom = mRestrictedScreenTop + mRestrictedScreenHeight;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004079 }
Dianne Hackborn5b5cc4d2012-05-16 13:15:00 -07004080 applyStableConstraints(sysUiFl, fl, cf);
Dianne Hackborndea3ef72010-10-28 14:24:22 -07004081 if (adjust != SOFT_INPUT_ADJUST_NOTHING) {
4082 vf.left = mCurLeft;
4083 vf.top = mCurTop;
4084 vf.right = mCurRight;
4085 vf.bottom = mCurBottom;
4086 } else {
4087 vf.set(cf);
4088 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004089 }
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07004090 } else if ((fl & FLAG_LAYOUT_IN_SCREEN) != 0 || (sysUiFl
4091 & (View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
4092 | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION)) != 0) {
Craig Mautnereda67292013-04-28 13:50:14 -07004093 if (DEBUG_LAYOUT) Slog.v(TAG, "layoutWindowLw(" + attrs.getTitle() +
4094 "): IN_SCREEN");
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004095 // A window that has requested to fill the entire screen just
4096 // gets everything, period.
Daniel Sandler8956dbb2011-04-22 07:55:02 -04004097 if (attrs.type == TYPE_STATUS_BAR_PANEL
John Spurlock67a0f852015-06-15 15:35:47 -04004098 || attrs.type == TYPE_STATUS_BAR_SUB_PANEL
4099 || attrs.type == TYPE_VOLUME_OVERLAY) {
Dianne Hackbornc4aad012013-02-22 15:05:25 -08004100 pf.left = df.left = of.left = cf.left = hasNavBar
4101 ? mDockLeft : mUnrestrictedScreenLeft;
4102 pf.top = df.top = of.top = cf.top = mUnrestrictedScreenTop;
4103 pf.right = df.right = of.right = cf.right = hasNavBar
Daniel Sandler8e8b4152011-07-21 01:16:43 -04004104 ? mRestrictedScreenLeft+mRestrictedScreenWidth
Dianne Hackbornc652de82013-02-15 16:32:56 -08004105 : mUnrestrictedScreenLeft + mUnrestrictedScreenWidth;
Dianne Hackbornc4aad012013-02-22 15:05:25 -08004106 pf.bottom = df.bottom = of.bottom = cf.bottom = hasNavBar
Daniel Sandler8e8b4152011-07-21 01:16:43 -04004107 ? mRestrictedScreenTop+mRestrictedScreenHeight
Dianne Hackbornc652de82013-02-15 16:32:56 -08004108 : mUnrestrictedScreenTop + mUnrestrictedScreenHeight;
Craig Mautnereda67292013-04-28 13:50:14 -07004109 if (DEBUG_LAYOUT) Slog.v(TAG, String.format(
Daniel Sandler36412a72011-08-04 09:35:13 -04004110 "Laying out IN_SCREEN status bar window: (%d,%d - %d,%d)",
4111 pf.left, pf.top, pf.right, pf.bottom));
Jim Millere898ac52012-04-06 17:10:57 -07004112 } else if (attrs.type == TYPE_NAVIGATION_BAR
4113 || attrs.type == TYPE_NAVIGATION_BAR_PANEL) {
Daniel Sandler8e8b4152011-07-21 01:16:43 -04004114 // The navigation bar has Real Ultimate Power.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08004115 pf.left = df.left = of.left = mUnrestrictedScreenLeft;
4116 pf.top = df.top = of.top = mUnrestrictedScreenTop;
4117 pf.right = df.right = of.right = mUnrestrictedScreenLeft
4118 + mUnrestrictedScreenWidth;
4119 pf.bottom = df.bottom = of.bottom = mUnrestrictedScreenTop
4120 + mUnrestrictedScreenHeight;
Craig Mautnereda67292013-04-28 13:50:14 -07004121 if (DEBUG_LAYOUT) Slog.v(TAG, String.format(
Daniel Sandler8e8b4152011-07-21 01:16:43 -04004122 "Laying out navigation bar window: (%d,%d - %d,%d)",
4123 pf.left, pf.top, pf.right, pf.bottom));
Dianne Hackborn01011c32012-02-21 13:54:21 -08004124 } else if ((attrs.type == TYPE_SECURE_SYSTEM_OVERLAY
4125 || attrs.type == TYPE_BOOT_PROGRESS)
Jeff Brownbfcb60a2011-09-08 18:51:14 -07004126 && ((fl & FLAG_FULLSCREEN) != 0)) {
4127 // Fullscreen secure system overlays get what they ask for.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08004128 pf.left = df.left = of.left = cf.left = mOverscanScreenLeft;
4129 pf.top = df.top = of.top = cf.top = mOverscanScreenTop;
4130 pf.right = df.right = of.right = cf.right = mOverscanScreenLeft
4131 + mOverscanScreenWidth;
4132 pf.bottom = df.bottom = of.bottom = cf.bottom = mOverscanScreenTop
4133 + mOverscanScreenHeight;
Craig Mautner165be0c2015-01-27 15:16:58 -08004134 } else if (attrs.type == TYPE_BOOT_PROGRESS) {
Dianne Hackborn01011c32012-02-21 13:54:21 -08004135 // Boot progress screen always covers entire display.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08004136 pf.left = df.left = of.left = cf.left = mOverscanScreenLeft;
4137 pf.top = df.top = of.top = cf.top = mOverscanScreenTop;
4138 pf.right = df.right = of.right = cf.right = mOverscanScreenLeft
4139 + mOverscanScreenWidth;
4140 pf.bottom = df.bottom = of.bottom = cf.bottom = mOverscanScreenTop
4141 + mOverscanScreenHeight;
John Spurlockef4adae2013-08-26 17:58:58 -04004142 } else if (attrs.type == TYPE_WALLPAPER) {
Dianne Hackborn067e5f62014-09-07 23:14:30 -07004143 // The wallpaper also has Real Ultimate Power, but we want to tell
4144 // it about the overscan area.
4145 pf.left = df.left = mOverscanScreenLeft;
4146 pf.top = df.top = mOverscanScreenTop;
4147 pf.right = df.right = mOverscanScreenLeft + mOverscanScreenWidth;
4148 pf.bottom = df.bottom = mOverscanScreenTop + mOverscanScreenHeight;
4149 of.left = cf.left = mUnrestrictedScreenLeft;
4150 of.top = cf.top = mUnrestrictedScreenTop;
4151 of.right = cf.right = mUnrestrictedScreenLeft + mUnrestrictedScreenWidth;
4152 of.bottom = cf.bottom = mUnrestrictedScreenTop + mUnrestrictedScreenHeight;
John Spurlock46646232013-09-30 22:32:42 -04004153 } else if ((fl & FLAG_LAYOUT_IN_OVERSCAN) != 0
Dianne Hackbornc652de82013-02-15 16:32:56 -08004154 && attrs.type >= WindowManager.LayoutParams.FIRST_APPLICATION_WINDOW
4155 && attrs.type <= WindowManager.LayoutParams.LAST_SUB_WINDOW) {
4156 // Asking to layout into the overscan region, so give it that pure
4157 // unrestricted area.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08004158 pf.left = df.left = of.left = cf.left = mOverscanScreenLeft;
4159 pf.top = df.top = of.top = cf.top = mOverscanScreenTop;
4160 pf.right = df.right = of.right = cf.right
Dianne Hackbornc652de82013-02-15 16:32:56 -08004161 = mOverscanScreenLeft + mOverscanScreenWidth;
Dianne Hackbornc4aad012013-02-22 15:05:25 -08004162 pf.bottom = df.bottom = of.bottom = cf.bottom
Dianne Hackbornc652de82013-02-15 16:32:56 -08004163 = mOverscanScreenTop + mOverscanScreenHeight;
Alan Viverette5a0f4ec2013-10-07 15:10:29 -07004164 } else if (canHideNavigationBar()
Dianne Hackbornf87d1962012-04-04 12:48:24 -07004165 && (sysUiFl & View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION) != 0
Craig Mautnerbeac1062014-06-03 14:38:57 -07004166 && (attrs.type == TYPE_STATUS_BAR
4167 || attrs.type == TYPE_TOAST
Jorim Jaggi2fdeeab2015-04-01 15:13:03 -07004168 || attrs.type == TYPE_VOICE_INTERACTION_STARTING
John Spurlock34e13d92013-08-10 06:52:28 -04004169 || (attrs.type >= WindowManager.LayoutParams.FIRST_APPLICATION_WINDOW
4170 && attrs.type <= WindowManager.LayoutParams.LAST_SUB_WINDOW))) {
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07004171 // Asking for layout as if the nav bar is hidden, lets the
4172 // application extend into the unrestricted screen area. We
John Spurlock34e13d92013-08-10 06:52:28 -04004173 // only do this for application windows (or toasts) to ensure no window that
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07004174 // can be above the nav bar can do this.
4175 // XXX This assumes that an app asking for this will also
4176 // ask for layout in only content. We can't currently figure out
4177 // what the screen would be if only laying out to hide the nav bar.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08004178 pf.left = df.left = of.left = cf.left = mUnrestrictedScreenLeft;
4179 pf.top = df.top = of.top = cf.top = mUnrestrictedScreenTop;
4180 pf.right = df.right = of.right = cf.right = mUnrestrictedScreenLeft
4181 + mUnrestrictedScreenWidth;
4182 pf.bottom = df.bottom = of.bottom = cf.bottom = mUnrestrictedScreenTop
4183 + mUnrestrictedScreenHeight;
Joe Onorato29fc2c92010-11-24 10:26:50 -08004184 } else {
Dianne Hackbornc4aad012013-02-22 15:05:25 -08004185 pf.left = df.left = of.left = cf.left = mRestrictedScreenLeft;
4186 pf.top = df.top = of.top = cf.top = mRestrictedScreenTop;
4187 pf.right = df.right = of.right = cf.right = mRestrictedScreenLeft
4188 + mRestrictedScreenWidth;
4189 pf.bottom = df.bottom = of.bottom = cf.bottom = mRestrictedScreenTop
4190 + mRestrictedScreenHeight;
Joe Onorato29fc2c92010-11-24 10:26:50 -08004191 }
Craig Mautner69b08182012-09-05 13:07:13 -07004192
Dianne Hackborn5b5cc4d2012-05-16 13:15:00 -07004193 applyStableConstraints(sysUiFl, fl, cf);
Craig Mautner69b08182012-09-05 13:07:13 -07004194
Dianne Hackborndea3ef72010-10-28 14:24:22 -07004195 if (adjust != SOFT_INPUT_ADJUST_NOTHING) {
4196 vf.left = mCurLeft;
4197 vf.top = mCurTop;
4198 vf.right = mCurRight;
4199 vf.bottom = mCurBottom;
4200 } else {
4201 vf.set(cf);
4202 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004203 } else if (attached != null) {
Craig Mautnereda67292013-04-28 13:50:14 -07004204 if (DEBUG_LAYOUT) Slog.v(TAG, "layoutWindowLw(" + attrs.getTitle() +
4205 "): attached to " + attached);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004206 // A child window should be placed inside of the same visible
4207 // frame that its parent had.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08004208 setAttachedWindowFrames(win, fl, adjust, attached, false, pf, df, of, cf, vf);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004209 } else {
Craig Mautnereda67292013-04-28 13:50:14 -07004210 if (DEBUG_LAYOUT) Slog.v(TAG, "layoutWindowLw(" + attrs.getTitle() +
4211 "): normal window");
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004212 // Otherwise, a normal window must be placed inside the content
4213 // of all screen decorations.
John Spurlock67a0f852015-06-15 15:35:47 -04004214 if (attrs.type == TYPE_STATUS_BAR_PANEL || attrs.type == TYPE_VOLUME_OVERLAY) {
4215 // Status bar panels and the volume dialog are the only windows who can go on
4216 // top of the status bar. They are protected by the STATUS_BAR_SERVICE
Dianne Hackborna239c842011-06-01 12:28:20 -07004217 // permission, so they have the same privileges as the status
4218 // bar itself.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08004219 pf.left = df.left = of.left = cf.left = mRestrictedScreenLeft;
4220 pf.top = df.top = of.top = cf.top = mRestrictedScreenTop;
4221 pf.right = df.right = of.right = cf.right = mRestrictedScreenLeft
4222 + mRestrictedScreenWidth;
4223 pf.bottom = df.bottom = of.bottom = cf.bottom = mRestrictedScreenTop
4224 + mRestrictedScreenHeight;
John Spurlock67a0f852015-06-15 15:35:47 -04004225 } else if (attrs.type == TYPE_TOAST || attrs.type == TYPE_SYSTEM_ALERT) {
John Spurlock414c1f02013-12-04 13:47:36 -05004226 // These dialogs are stable to interim decor changes.
John Spurlockbd957402013-10-03 11:38:39 -04004227 pf.left = df.left = of.left = cf.left = mStableLeft;
4228 pf.top = df.top = of.top = cf.top = mStableTop;
4229 pf.right = df.right = of.right = cf.right = mStableRight;
4230 pf.bottom = df.bottom = of.bottom = cf.bottom = mStableBottom;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004231 } else {
Dianne Hackborna239c842011-06-01 12:28:20 -07004232 pf.left = mContentLeft;
4233 pf.top = mContentTop;
4234 pf.right = mContentRight;
4235 pf.bottom = mContentBottom;
Dianne Hackborn20d94742014-05-29 18:35:45 -07004236 if (win.isVoiceInteraction()) {
4237 df.left = of.left = cf.left = mVoiceContentLeft;
4238 df.top = of.top = cf.top = mVoiceContentTop;
4239 df.right = of.right = cf.right = mVoiceContentRight;
4240 df.bottom = of.bottom = cf.bottom = mVoiceContentBottom;
4241 } else if (adjust != SOFT_INPUT_ADJUST_RESIZE) {
Dianne Hackbornc4aad012013-02-22 15:05:25 -08004242 df.left = of.left = cf.left = mDockLeft;
4243 df.top = of.top = cf.top = mDockTop;
4244 df.right = of.right = cf.right = mDockRight;
4245 df.bottom = of.bottom = cf.bottom = mDockBottom;
Dianne Hackborna239c842011-06-01 12:28:20 -07004246 } else {
Dianne Hackbornc4aad012013-02-22 15:05:25 -08004247 df.left = of.left = cf.left = mContentLeft;
4248 df.top = of.top = cf.top = mContentTop;
4249 df.right = of.right = cf.right = mContentRight;
4250 df.bottom = of.bottom = cf.bottom = mContentBottom;
Dianne Hackborna239c842011-06-01 12:28:20 -07004251 }
4252 if (adjust != SOFT_INPUT_ADJUST_NOTHING) {
4253 vf.left = mCurLeft;
4254 vf.top = mCurTop;
4255 vf.right = mCurRight;
4256 vf.bottom = mCurBottom;
4257 } else {
4258 vf.set(cf);
4259 }
Dianne Hackborndea3ef72010-10-28 14:24:22 -07004260 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004261 }
4262 }
Craig Mautner69b08182012-09-05 13:07:13 -07004263
Craig Mautnerb816bed2013-07-23 10:26:17 -07004264 // TYPE_SYSTEM_ERROR is above the NavigationBar so it can't be allowed to extend over it.
4265 if ((fl & FLAG_LAYOUT_NO_LIMITS) != 0 && attrs.type != TYPE_SYSTEM_ERROR) {
Dianne Hackborn067e5f62014-09-07 23:14:30 -07004266 df.left = df.top = -10000;
4267 df.right = df.bottom = 10000;
4268 if (attrs.type != TYPE_WALLPAPER) {
4269 of.left = of.top = cf.left = cf.top = vf.left = vf.top = -10000;
4270 of.right = of.bottom = cf.right = cf.bottom = vf.right = vf.bottom = 10000;
4271 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004272 }
4273
Filip Gruszczynski2217f612015-05-26 11:32:08 -07004274 // If the device has a chin (e.g. some watches), a dead area at the bottom of the screen we
4275 // need to provide information to the clients that want to pretend that you can draw there.
Filip Gruszczynskib0c673b2015-06-05 09:43:06 -07004276 // We only want to apply outsets to certain types of windows. For example, we never want to
4277 // apply the outsets to floating dialogs, because they wouldn't make sense there.
Filip Gruszczynski2987f612015-06-30 15:03:30 -07004278 final boolean useOutsets = shouldUseOutsets(attrs, fl);
Filip Gruszczynskib0c673b2015-06-05 09:43:06 -07004279 if (isDefaultDisplay && useOutsets) {
Filip Gruszczynski2217f612015-05-26 11:32:08 -07004280 osf = mTmpOutsetFrame;
4281 osf.set(cf.left, cf.top, cf.right, cf.bottom);
4282 int outset = ScreenShapeHelper.getWindowOutsetBottomPx(mContext.getResources());
4283 if (outset > 0) {
Filip Gruszczynski2987f612015-06-30 15:03:30 -07004284 int rotation = mDisplayRotation;
Filip Gruszczynski2217f612015-05-26 11:32:08 -07004285 if (rotation == Surface.ROTATION_0) {
4286 osf.bottom += outset;
4287 } else if (rotation == Surface.ROTATION_90) {
4288 osf.right += outset;
4289 } else if (rotation == Surface.ROTATION_180) {
4290 osf.top -= outset;
4291 } else if (rotation == Surface.ROTATION_270) {
4292 osf.left -= outset;
4293 }
4294 if (DEBUG_LAYOUT) Slog.v(TAG, "applying bottom outset of " + outset
4295 + " with rotation " + rotation + ", result: " + osf);
4296 }
4297 }
4298
Craig Mautnereda67292013-04-28 13:50:14 -07004299 if (DEBUG_LAYOUT) Slog.v(TAG, "Compute frame " + attrs.getTitle()
The Android Open Source Project11267662009-03-18 17:39:47 -07004300 + ": sim=#" + Integer.toHexString(sim)
RoboErik8a2cfc32014-05-16 11:19:38 -07004301 + " attach=" + attached + " type=" + attrs.type
Daniel Sandler8956dbb2011-04-22 07:55:02 -04004302 + String.format(" flags=0x%08x", fl)
The Android Open Source Project11267662009-03-18 17:39:47 -07004303 + " pf=" + pf.toShortString() + " df=" + df.toShortString()
Dianne Hackbornc4aad012013-02-22 15:05:25 -08004304 + " of=" + of.toShortString()
John Spurlock46646232013-09-30 22:32:42 -04004305 + " cf=" + cf.toShortString() + " vf=" + vf.toShortString()
Adrian Roosfa104232014-06-20 16:10:14 -07004306 + " dcf=" + dcf.toShortString()
Filip Gruszczynski2217f612015-05-26 11:32:08 -07004307 + " sf=" + sf.toShortString()
4308 + " osf=" + (osf == null ? "null" : osf.toShortString()));
Craig Mautner69b08182012-09-05 13:07:13 -07004309
Filip Gruszczynski2217f612015-05-26 11:32:08 -07004310 win.computeFrameLw(pf, df, of, cf, vf, dcf, sf, osf);
Craig Mautner69b08182012-09-05 13:07:13 -07004311
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004312 // Dock windows carve out the bottom of the screen, so normal windows
4313 // can't appear underneath them.
Craig Mautner8bd206b2012-10-03 10:32:02 -07004314 if (attrs.type == TYPE_INPUT_METHOD && win.isVisibleOrBehindKeyguardLw()
4315 && !win.getGivenInsetsPendingLw()) {
satok1bc0a492012-04-25 22:47:12 +09004316 setLastInputMethodWindowLw(null, null);
4317 offsetInputMethodWindowLw(win);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004318 }
Dianne Hackborne30e02f2014-05-27 18:24:45 -07004319 if (attrs.type == TYPE_VOICE_INTERACTION && win.isVisibleOrBehindKeyguardLw()
4320 && !win.getGivenInsetsPendingLw()) {
4321 offsetVoiceInputWindowLw(win);
4322 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004323 }
4324
satok1bc0a492012-04-25 22:47:12 +09004325 private void offsetInputMethodWindowLw(WindowState win) {
Craig Mautner4774f6a2015-03-23 11:42:55 -07004326 int top = Math.max(win.getDisplayFrameLw().top, win.getContentFrameLw().top);
satok1bc0a492012-04-25 22:47:12 +09004327 top += win.getGivenContentInsetsLw().top;
4328 if (mContentBottom > top) {
4329 mContentBottom = top;
4330 }
Dianne Hackborne30e02f2014-05-27 18:24:45 -07004331 if (mVoiceContentBottom > top) {
4332 mVoiceContentBottom = top;
4333 }
satok1bc0a492012-04-25 22:47:12 +09004334 top = win.getVisibleFrameLw().top;
4335 top += win.getGivenVisibleInsetsLw().top;
4336 if (mCurBottom > top) {
4337 mCurBottom = top;
4338 }
Craig Mautnereda67292013-04-28 13:50:14 -07004339 if (DEBUG_LAYOUT) Slog.v(TAG, "Input method: mDockBottom="
satok1bc0a492012-04-25 22:47:12 +09004340 + mDockBottom + " mContentBottom="
4341 + mContentBottom + " mCurBottom=" + mCurBottom);
4342 }
4343
Dianne Hackborne30e02f2014-05-27 18:24:45 -07004344 private void offsetVoiceInputWindowLw(WindowState win) {
Craig Mautner4774f6a2015-03-23 11:42:55 -07004345 int top = Math.max(win.getDisplayFrameLw().top, win.getContentFrameLw().top);
Dianne Hackbornae6688b2015-02-11 17:02:41 -08004346 top += win.getGivenContentInsetsLw().top;
4347 if (mVoiceContentBottom > top) {
4348 mVoiceContentBottom = top;
Dianne Hackborne30e02f2014-05-27 18:24:45 -07004349 }
4350 }
4351
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004352 /** {@inheritDoc} */
Craig Mautner61ac6bb2012-02-02 17:29:33 -08004353 @Override
4354 public void finishLayoutLw() {
4355 return;
Dianne Hackborn5f3063e2010-03-10 16:01:58 -08004356 }
4357
4358 /** {@inheritDoc} */
Craig Mautnerad09bcc2012-10-08 13:33:11 -07004359 @Override
Craig Mautner39834192012-09-02 07:47:24 -07004360 public void beginPostLayoutPolicyLw(int displayWidth, int displayHeight) {
Dianne Hackborn5f3063e2010-03-10 16:01:58 -08004361 mTopFullscreenOpaqueWindowState = null;
Adrian Rooscd3884d2015-02-18 17:25:23 +01004362 mTopFullscreenOpaqueOrDimmingWindowState = null;
Craig Mautner2bc789b2014-03-19 19:48:38 -07004363 mAppsToBeHidden.clear();
Jorim Jaggic13fcac2014-09-11 17:36:57 +02004364 mAppsThatDismissKeyguard.clear();
Dianne Hackborn5f3063e2010-03-10 16:01:58 -08004365 mForceStatusBar = false;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07004366 mForceStatusBarFromKeyguard = false;
Selim Cinek4a4a2bddc2015-05-07 12:50:19 -07004367 mForceStatusBarTransparent = false;
Dianne Hackborn891d3fb2013-01-09 18:31:37 -08004368 mForcingShowNavBar = false;
4369 mForcingShowNavBarLayer = -1;
RoboErik8a2cfc32014-05-16 11:19:38 -07004370
Dianne Hackborn5f3063e2010-03-10 16:01:58 -08004371 mHideLockScreen = false;
4372 mAllowLockscreenWhenOn = false;
Craig Mautnerad09bcc2012-10-08 13:33:11 -07004373 mDismissKeyguard = DISMISS_KEYGUARD_NONE;
Dianne Hackborn7ad44382012-10-18 17:46:00 -07004374 mShowingLockscreen = false;
4375 mShowingDream = false;
Craig Mautnerc9457fa2014-06-06 14:27:48 -07004376 mWinShowWhenLocked = null;
Jim Millerab954542014-10-10 18:21:49 -07004377 mKeyguardSecure = isKeyguardSecure();
4378 mKeyguardSecureIncludingHidden = mKeyguardSecure
4379 && (mKeyguardDelegate != null && mKeyguardDelegate.isShowing());
Dianne Hackborn5f3063e2010-03-10 16:01:58 -08004380 }
4381
4382 /** {@inheritDoc} */
Craig Mautnerad09bcc2012-10-08 13:33:11 -07004383 @Override
Yohei Yukawad1a09222015-06-30 16:22:05 -07004384 public void applyPostLayoutPolicyLw(WindowState win, WindowManager.LayoutParams attrs,
4385 WindowState attached) {
Dianne Hackbornbc1aa7b2011-09-20 11:20:31 -07004386 if (DEBUG_LAYOUT) Slog.i(TAG, "Win " + win + ": isVisibleOrBehindKeyguardLw="
4387 + win.isVisibleOrBehindKeyguardLw());
John Spurlockc6d1c602014-01-17 15:22:06 -05004388 final int fl = PolicyControl.getWindowFlags(win, attrs);
John Spurlock414c1f02013-12-04 13:47:36 -05004389 if (mTopFullscreenOpaqueWindowState == null
4390 && win.isVisibleLw() && attrs.type == TYPE_INPUT_METHOD) {
4391 mForcingShowNavBar = true;
4392 mForcingShowNavBarLayer = win.getSurfaceLayer();
Dianne Hackborn891d3fb2013-01-09 18:31:37 -08004393 }
Selim Cinek4a4a2bddc2015-05-07 12:50:19 -07004394 if (attrs.type == TYPE_STATUS_BAR) {
4395 if ((attrs.privateFlags & PRIVATE_FLAG_KEYGUARD) != 0) {
4396 mForceStatusBarFromKeyguard = true;
Jorim Jaggie1de9f62015-09-23 14:59:50 -07004397 mShowingLockscreen = true;
Selim Cinek4a4a2bddc2015-05-07 12:50:19 -07004398 }
4399 if ((attrs.privateFlags & PRIVATE_FLAG_FORCE_STATUS_BAR_VISIBLE_TRANSPARENT) != 0) {
4400 mForceStatusBarTransparent = true;
4401 }
Jorim Jaggiafd4a552014-04-08 15:13:05 +02004402 }
Adrian Roos602c68e2015-04-24 16:03:47 -07004403
4404 boolean appWindow = attrs.type >= FIRST_APPLICATION_WINDOW
4405 && attrs.type < FIRST_SYSTEM_WINDOW;
4406 final boolean showWhenLocked = (fl & FLAG_SHOW_WHEN_LOCKED) != 0;
4407 final boolean dismissKeyguard = (fl & FLAG_DISMISS_KEYGUARD) != 0;
4408
Dianne Hackborn5f3063e2010-03-10 16:01:58 -08004409 if (mTopFullscreenOpaqueWindowState == null &&
Dianne Hackborn01b02a72012-01-12 14:05:03 -08004410 win.isVisibleOrBehindKeyguardLw() && !win.isGoneForLayoutLw()) {
John Spurlockc6d1c602014-01-17 15:22:06 -05004411 if ((fl & FLAG_FORCE_NOT_FULLSCREEN) != 0) {
Jorim Jaggi380ecb82014-03-14 17:25:20 +01004412 if ((attrs.privateFlags & PRIVATE_FLAG_KEYGUARD) != 0) {
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07004413 mForceStatusBarFromKeyguard = true;
4414 } else {
4415 mForceStatusBar = true;
4416 }
4417 }
Dianne Hackborn7ad44382012-10-18 17:46:00 -07004418 if (attrs.type == TYPE_DREAM) {
Jeff Brownc8018eb2012-10-29 21:33:27 -07004419 // If the lockscreen was showing when the dream started then wait
4420 // for the dream to draw before hiding the lockscreen.
4421 if (!mDreamingLockscreen
4422 || (win.isVisibleLw() && win.hasDrawnLw())) {
4423 mShowingDream = true;
Craig Mautnerab55e522014-03-03 13:26:03 -08004424 appWindow = true;
Dianne Hackborn7ad44382012-10-18 17:46:00 -07004425 }
4426 }
Craig Mautnerab55e522014-03-03 13:26:03 -08004427
Yohei Yukawad1a09222015-06-30 16:22:05 -07004428 final IApplicationToken appToken = win.getAppToken();
4429
4430 // For app windows that are not attached, we decide if all windows in the app they
4431 // represent should be hidden or if we should hide the lockscreen. For attached app
4432 // windows we defer the decision to the window it is attached to.
4433 if (appWindow && attached == null) {
Jorim Jaggic13fcac2014-09-11 17:36:57 +02004434 if (showWhenLocked) {
Craig Mautnerc9457fa2014-06-06 14:27:48 -07004435 // Remove any previous windows with the same appToken.
Jorim Jaggic13fcac2014-09-11 17:36:57 +02004436 mAppsToBeHidden.remove(appToken);
4437 mAppsThatDismissKeyguard.remove(appToken);
Craig Mautnerca0a1242014-12-02 12:25:14 -08004438 if (mAppsToBeHidden.isEmpty()) {
Craig Mautner192d6042014-12-02 23:24:48 -08004439 if (dismissKeyguard && !mKeyguardSecure) {
4440 mAppsThatDismissKeyguard.add(appToken);
Selim Cinek90b5e072015-08-28 17:05:56 -07004441 } else if (win.isDrawnLw() || win.hasAppShownWindows()) {
Craig Mautnerca0a1242014-12-02 12:25:14 -08004442 mWinShowWhenLocked = win;
4443 mHideLockScreen = true;
4444 mForceStatusBarFromKeyguard = false;
Craig Mautnerca0a1242014-12-02 12:25:14 -08004445 }
Craig Mautnerc9457fa2014-06-06 14:27:48 -07004446 }
Jorim Jaggic13fcac2014-09-11 17:36:57 +02004447 } else if (dismissKeyguard) {
Jim Millerab954542014-10-10 18:21:49 -07004448 if (mKeyguardSecure) {
Jorim Jaggic13fcac2014-09-11 17:36:57 +02004449 mAppsToBeHidden.add(appToken);
4450 } else {
4451 mAppsToBeHidden.remove(appToken);
4452 }
4453 mAppsThatDismissKeyguard.add(appToken);
Craig Mautner2bc789b2014-03-19 19:48:38 -07004454 } else {
Jorim Jaggic13fcac2014-09-11 17:36:57 +02004455 mAppsToBeHidden.add(appToken);
Craig Mautner2bc789b2014-03-19 19:48:38 -07004456 }
Craig Mautnerab55e522014-03-03 13:26:03 -08004457 if (attrs.x == 0 && attrs.y == 0
4458 && attrs.width == WindowManager.LayoutParams.MATCH_PARENT
4459 && attrs.height == WindowManager.LayoutParams.MATCH_PARENT) {
4460 if (DEBUG_LAYOUT) Slog.v(TAG, "Fullscreen window: " + win);
4461 mTopFullscreenOpaqueWindowState = win;
Adrian Rooscd3884d2015-02-18 17:25:23 +01004462 if (mTopFullscreenOpaqueOrDimmingWindowState == null) {
4463 mTopFullscreenOpaqueOrDimmingWindowState = win;
4464 }
Jorim Jaggic13fcac2014-09-11 17:36:57 +02004465 if (!mAppsThatDismissKeyguard.isEmpty() &&
4466 mDismissKeyguard == DISMISS_KEYGUARD_NONE) {
4467 if (DEBUG_LAYOUT) Slog.v(TAG,
4468 "Setting mDismissKeyguard true by win " + win);
tingna_sunge785ffa2015-05-12 13:23:15 +08004469 mDismissKeyguard = (mWinDismissingKeyguard == win
4470 && mSecureDismissingKeyguard == mKeyguardSecure)
4471 ? DISMISS_KEYGUARD_CONTINUE : DISMISS_KEYGUARD_START;
Jorim Jaggic13fcac2014-09-11 17:36:57 +02004472 mWinDismissingKeyguard = win;
tingna_sunge785ffa2015-05-12 13:23:15 +08004473 mSecureDismissingKeyguard = mKeyguardSecure;
Jim Millerab954542014-10-10 18:21:49 -07004474 mForceStatusBarFromKeyguard = mShowingLockscreen && mKeyguardSecure;
Selim Cinek90b5e072015-08-28 17:05:56 -07004475 } else if (mAppsToBeHidden.isEmpty() && showWhenLocked
4476 && (win.isDrawnLw() || win.hasAppShownWindows())) {
Jorim Jaggic13fcac2014-09-11 17:36:57 +02004477 if (DEBUG_LAYOUT) Slog.v(TAG,
4478 "Setting mHideLockScreen to true by win " + win);
4479 mHideLockScreen = true;
4480 mForceStatusBarFromKeyguard = false;
Craig Mautnerab55e522014-03-03 13:26:03 -08004481 }
Craig Mautner00156ec2014-03-06 22:29:02 -08004482 if ((fl & FLAG_ALLOW_LOCK_WHILE_SCREEN_ON) != 0) {
Craig Mautnerab55e522014-03-03 13:26:03 -08004483 mAllowLockscreenWhenOn = true;
4484 }
Dianne Hackborn5f3063e2010-03-10 16:01:58 -08004485 }
Craig Mautnerc9457fa2014-06-06 14:27:48 -07004486
4487 if (mWinShowWhenLocked != null &&
Adrian Roos602c68e2015-04-24 16:03:47 -07004488 mWinShowWhenLocked.getAppToken() != win.getAppToken() &&
4489 (attrs.flags & FLAG_SHOW_WHEN_LOCKED) == 0) {
Craig Mautnerc9457fa2014-06-06 14:27:48 -07004490 win.hideLw(false);
4491 }
Dianne Hackborn5f3063e2010-03-10 16:01:58 -08004492 }
Adrian Roos602c68e2015-04-24 16:03:47 -07004493 } else if (mTopFullscreenOpaqueWindowState == null && mWinShowWhenLocked == null) {
4494 // No TopFullscreenOpaqueWindow is showing, but we found a SHOW_WHEN_LOCKED window
4495 // that is being hidden in an animation - keep the
4496 // keyguard hidden until the new window shows up and
4497 // we know whether to show the keyguard or not.
Adrian Roosb85e1ec2015-05-29 15:23:18 -07004498 if (win.isAnimatingLw() && appWindow && showWhenLocked && mKeyguardHidden) {
Adrian Roos602c68e2015-04-24 16:03:47 -07004499 mHideLockScreen = true;
4500 mWinShowWhenLocked = win;
4501 }
Dianne Hackborn5f3063e2010-03-10 16:01:58 -08004502 }
Adrian Rooscd3884d2015-02-18 17:25:23 +01004503 if (mTopFullscreenOpaqueOrDimmingWindowState == null
4504 && win.isVisibleOrBehindKeyguardLw() && !win.isGoneForLayoutLw()
4505 && win.isDimming()) {
4506 mTopFullscreenOpaqueOrDimmingWindowState = win;
4507 }
Dianne Hackborn5f3063e2010-03-10 16:01:58 -08004508 }
4509
4510 /** {@inheritDoc} */
Craig Mautnerad09bcc2012-10-08 13:33:11 -07004511 @Override
Craig Mautner39834192012-09-02 07:47:24 -07004512 public int finishPostLayoutPolicyLw() {
Craig Mautnerc5e73bf2015-04-21 15:41:26 +00004513 if (mWinShowWhenLocked != null && mTopFullscreenOpaqueWindowState != null &&
4514 mWinShowWhenLocked.getAppToken() != mTopFullscreenOpaqueWindowState.getAppToken()
4515 && isKeyguardLocked()) {
Craig Mautnerc9457fa2014-06-06 14:27:48 -07004516 // A dialog is dismissing the keyguard. Put the wallpaper behind it and hide the
4517 // fullscreen window.
4518 // TODO: Make sure FLAG_SHOW_WALLPAPER is restored when dialog is dismissed. Or not.
4519 mWinShowWhenLocked.getAttrs().flags |= FLAG_SHOW_WALLPAPER;
4520 mTopFullscreenOpaqueWindowState.hideLw(false);
4521 mTopFullscreenOpaqueWindowState = mWinShowWhenLocked;
4522 }
4523
Dianne Hackborn39c2d712009-09-22 11:41:31 -07004524 int changes = 0;
Joe Onorato93056472010-09-10 10:30:46 -04004525 boolean topIsFullscreen = false;
Daniel Sandlere02d8082010-10-08 15:13:22 -04004526
4527 final WindowManager.LayoutParams lp = (mTopFullscreenOpaqueWindowState != null)
4528 ? mTopFullscreenOpaqueWindowState.getAttrs()
4529 : null;
4530
Jeff Brownc8018eb2012-10-29 21:33:27 -07004531 // If we are not currently showing a dream then remember the current
4532 // lockscreen state. We will use this to determine whether the dream
4533 // started while the lockscreen was showing and remember this state
4534 // while the dream is showing.
Dianne Hackborn7ad44382012-10-18 17:46:00 -07004535 if (!mShowingDream) {
4536 mDreamingLockscreen = mShowingLockscreen;
Jeff Brown061ea992015-04-17 19:55:47 -07004537 if (mDreamingSleepTokenNeeded) {
4538 mDreamingSleepTokenNeeded = false;
4539 mHandler.obtainMessage(MSG_UPDATE_DREAMING_SLEEP_TOKEN, 0, 1).sendToTarget();
4540 }
4541 } else {
4542 if (!mDreamingSleepTokenNeeded) {
4543 mDreamingSleepTokenNeeded = true;
4544 mHandler.obtainMessage(MSG_UPDATE_DREAMING_SLEEP_TOKEN, 1, 1).sendToTarget();
4545 }
Dianne Hackborn7ad44382012-10-18 17:46:00 -07004546 }
4547
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004548 if (mStatusBar != null) {
Craig Mautnereda67292013-04-28 13:50:14 -07004549 if (DEBUG_LAYOUT) Slog.i(TAG, "force=" + mForceStatusBar
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07004550 + " forcefkg=" + mForceStatusBarFromKeyguard
Dianne Hackbornd70bc2f2009-10-06 23:25:51 -07004551 + " top=" + mTopFullscreenOpaqueWindowState);
Selim Cinek4a4a2bddc2015-05-07 12:50:19 -07004552 boolean shouldBeTransparent = mForceStatusBarTransparent
4553 && !mForceStatusBar
4554 && !mForceStatusBarFromKeyguard;
4555 if (!shouldBeTransparent) {
4556 mStatusBarController.setShowTransparent(false /* transparent */);
4557 } else if (!mStatusBar.isVisibleLw()) {
4558 mStatusBarController.setShowTransparent(true /* transparent */);
4559 }
4560 if (mForceStatusBar || mForceStatusBarFromKeyguard || mForceStatusBarTransparent) {
Craig Mautnereda67292013-04-28 13:50:14 -07004561 if (DEBUG_LAYOUT) Slog.v(TAG, "Showing status bar: forced");
John Spurlock27735a42013-08-14 17:57:38 -04004562 if (mStatusBarController.setBarShowingLw(true)) {
4563 changes |= FINISH_LAYOUT_REDO_LAYOUT;
4564 }
Craig Mautner81defc72013-10-29 11:10:42 -07004565 // Maintain fullscreen layout until incoming animation is complete.
4566 topIsFullscreen = mTopIsFullscreen && mStatusBar.isAnimatingLw();
John Spurlockf92b6162013-11-11 15:01:16 -05004567 // Transient status bar on the lockscreen is not allowed
4568 if (mForceStatusBarFromKeyguard && mStatusBarController.isTransientShowing()) {
4569 mStatusBarController.updateVisibilityLw(false /*transientAllowed*/,
4570 mLastSystemUiFlags, mLastSystemUiFlags);
4571 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004572 } else if (mTopFullscreenOpaqueWindowState != null) {
John Spurlockc6d1c602014-01-17 15:22:06 -05004573 final int fl = PolicyControl.getWindowFlags(null, lp);
Joe Onorato93056472010-09-10 10:30:46 -04004574 if (localLOGV) {
Craig Mautnereda67292013-04-28 13:50:14 -07004575 Slog.d(TAG, "frame: " + mTopFullscreenOpaqueWindowState.getFrameLw()
Joe Onorato93056472010-09-10 10:30:46 -04004576 + " shown frame: " + mTopFullscreenOpaqueWindowState.getShownFrameLw());
Craig Mautnereda67292013-04-28 13:50:14 -07004577 Slog.d(TAG, "attr: " + mTopFullscreenOpaqueWindowState.getAttrs()
John Spurlockc6d1c602014-01-17 15:22:06 -05004578 + " lp.flags=0x" + Integer.toHexString(fl));
Joe Onorato93056472010-09-10 10:30:46 -04004579 }
John Spurlockc6d1c602014-01-17 15:22:06 -05004580 topIsFullscreen = (fl & WindowManager.LayoutParams.FLAG_FULLSCREEN) != 0
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07004581 || (mLastSystemUiFlags & View.SYSTEM_UI_FLAG_FULLSCREEN) != 0;
Joe Onorato93056472010-09-10 10:30:46 -04004582 // The subtle difference between the window for mTopFullscreenOpaqueWindowState
Mark Dolinerd0646dc2014-08-27 16:04:02 -07004583 // and mTopIsFullscreen is that mTopIsFullscreen is set only if the window
Joe Onorato93056472010-09-10 10:30:46 -04004584 // has the FLAG_FULLSCREEN set. Not sure if there is another way that to be the
4585 // case though.
John Spurlock27735a42013-08-14 17:57:38 -04004586 if (mStatusBarController.isTransientShowing()) {
4587 if (mStatusBarController.setBarShowingLw(true)) {
John Spurlock32beb2c2013-03-11 10:16:47 -04004588 changes |= FINISH_LAYOUT_REDO_LAYOUT;
4589 }
4590 } else if (topIsFullscreen) {
Craig Mautnereda67292013-04-28 13:50:14 -07004591 if (DEBUG_LAYOUT) Slog.v(TAG, "** HIDING status bar");
John Spurlock27735a42013-08-14 17:57:38 -04004592 if (mStatusBarController.setBarShowingLw(false)) {
Dianne Hackbornf87d1962012-04-04 12:48:24 -07004593 changes |= FINISH_LAYOUT_REDO_LAYOUT;
Craig Mautnereda67292013-04-28 13:50:14 -07004594 } else {
Craig Mautnerc5a6e442013-06-05 17:22:35 -07004595 if (DEBUG_LAYOUT) Slog.v(TAG, "Status bar already hiding");
Daniel Sandler40427442010-07-16 11:44:52 -04004596 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004597 } else {
Craig Mautnereda67292013-04-28 13:50:14 -07004598 if (DEBUG_LAYOUT) Slog.v(TAG, "** SHOWING status bar: top is not fullscreen");
John Spurlock27735a42013-08-14 17:57:38 -04004599 if (mStatusBarController.setBarShowingLw(true)) {
4600 changes |= FINISH_LAYOUT_REDO_LAYOUT;
4601 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004602 }
4603 }
4604 }
Daniel Sandlere02d8082010-10-08 15:13:22 -04004605
Craig Mautner81defc72013-10-29 11:10:42 -07004606 if (mTopIsFullscreen != topIsFullscreen) {
4607 if (!topIsFullscreen) {
4608 // Force another layout when status bar becomes fully shown.
4609 changes |= FINISH_LAYOUT_REDO_LAYOUT;
4610 }
4611 mTopIsFullscreen = topIsFullscreen;
4612 }
Daniel Sandlere02d8082010-10-08 15:13:22 -04004613
Craig Mautner39834192012-09-02 07:47:24 -07004614 // Hide the key guard if a visible window explicitly specifies that it wants to be
4615 // displayed when the screen is locked.
Jorim Jaggi5cf17872014-03-26 18:31:48 +01004616 if (mKeyguardDelegate != null && mStatusBar != null) {
4617 if (localLOGV) Slog.v(TAG, "finishPostLayoutPolicyLw: mHideKeyguard="
4618 + mHideLockScreen);
Jim Millerab954542014-10-10 18:21:49 -07004619 if (mDismissKeyguard != DISMISS_KEYGUARD_NONE && !mKeyguardSecure) {
Jorim Jaggi5cf17872014-03-26 18:31:48 +01004620 mKeyguardHidden = true;
Jim Millerab954542014-10-10 18:21:49 -07004621 if (setKeyguardOccludedLw(true)) {
Dianne Hackborn39c2d712009-09-22 11:41:31 -07004622 changes |= FINISH_LAYOUT_REDO_LAYOUT
4623 | FINISH_LAYOUT_REDO_CONFIG
4624 | FINISH_LAYOUT_REDO_WALLPAPER;
4625 }
Jorim Jaggi5cf17872014-03-26 18:31:48 +01004626 if (mKeyguardDelegate.isShowing()) {
4627 mHandler.post(new Runnable() {
4628 @Override
4629 public void run() {
4630 mKeyguardDelegate.keyguardDone(false, false);
4631 }
4632 });
4633 }
4634 } else if (mHideLockScreen) {
4635 mKeyguardHidden = true;
Jorim Jaggi7d85ea92015-05-20 17:20:40 -07004636 mWinDismissingKeyguard = null;
Jim Millerab954542014-10-10 18:21:49 -07004637 if (setKeyguardOccludedLw(true)) {
Jorim Jaggi5cf17872014-03-26 18:31:48 +01004638 changes |= FINISH_LAYOUT_REDO_LAYOUT
4639 | FINISH_LAYOUT_REDO_CONFIG
4640 | FINISH_LAYOUT_REDO_WALLPAPER;
4641 }
4642 } else if (mDismissKeyguard != DISMISS_KEYGUARD_NONE) {
Jorim Jaggi7d85ea92015-05-20 17:20:40 -07004643 mKeyguardHidden = false;
4644 if (setKeyguardOccludedLw(false)) {
4645 changes |= FINISH_LAYOUT_REDO_LAYOUT
4646 | FINISH_LAYOUT_REDO_CONFIG
4647 | FINISH_LAYOUT_REDO_WALLPAPER;
4648 }
Jorim Jaggi5cf17872014-03-26 18:31:48 +01004649 if (mDismissKeyguard == DISMISS_KEYGUARD_START) {
4650 // Only launch the next keyguard unlock window once per window.
Jorim Jaggi5cf17872014-03-26 18:31:48 +01004651 mHandler.post(new Runnable() {
4652 @Override
4653 public void run() {
4654 mKeyguardDelegate.dismiss();
4655 }
4656 });
4657 }
4658 } else {
4659 mWinDismissingKeyguard = null;
tingna_sunge785ffa2015-05-12 13:23:15 +08004660 mSecureDismissingKeyguard = false;
Jorim Jaggi5cf17872014-03-26 18:31:48 +01004661 mKeyguardHidden = false;
Jim Millerab954542014-10-10 18:21:49 -07004662 if (setKeyguardOccludedLw(false)) {
Jorim Jaggi5cf17872014-03-26 18:31:48 +01004663 changes |= FINISH_LAYOUT_REDO_LAYOUT
4664 | FINISH_LAYOUT_REDO_CONFIG
4665 | FINISH_LAYOUT_REDO_WALLPAPER;
4666 }
Suchi Amalapurapu9cdc9032009-05-14 18:01:07 -07004667 }
4668 }
Joe Onorato664644d2011-01-23 17:53:23 -08004669
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07004670 if ((updateSystemUiVisibilityLw()&SYSTEM_UI_CHANGING_LAYOUT) != 0) {
Dianne Hackborndf89e652011-10-06 22:35:11 -07004671 // If the navigation bar has been hidden or shown, we need to do another
4672 // layout pass to update that window.
4673 changes |= FINISH_LAYOUT_REDO_LAYOUT;
4674 }
Joe Onorato664644d2011-01-23 17:53:23 -08004675
Mike Lockwood28569302010-01-28 11:54:40 -05004676 // update since mAllowLockscreenWhenOn might have changed
4677 updateLockScreenTimeout();
Dianne Hackborn39c2d712009-09-22 11:41:31 -07004678 return changes;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004679 }
4680
Jorim Jaggi380ecb82014-03-14 17:25:20 +01004681 /**
Jim Millerab954542014-10-10 18:21:49 -07004682 * Updates the occluded state of the Keyguard.
Jorim Jaggi380ecb82014-03-14 17:25:20 +01004683 *
Jorim Jaggi380ecb82014-03-14 17:25:20 +01004684 * @return Whether the flags have changed and we have to redo the layout.
4685 */
Jim Millerab954542014-10-10 18:21:49 -07004686 private boolean setKeyguardOccludedLw(boolean isOccluded) {
4687 boolean wasOccluded = mKeyguardOccluded;
4688 boolean showing = mKeyguardDelegate.isShowing();
4689 if (wasOccluded && !isOccluded && showing) {
4690 mKeyguardOccluded = false;
4691 mKeyguardDelegate.setOccluded(false);
Jorim Jaggi380ecb82014-03-14 17:25:20 +01004692 mStatusBar.getAttrs().privateFlags |= PRIVATE_FLAG_KEYGUARD;
4693 mStatusBar.getAttrs().flags |= FLAG_SHOW_WALLPAPER;
4694 return true;
Jim Millerab954542014-10-10 18:21:49 -07004695 } else if (!wasOccluded && isOccluded && showing) {
4696 mKeyguardOccluded = true;
4697 mKeyguardDelegate.setOccluded(true);
Jorim Jaggi380ecb82014-03-14 17:25:20 +01004698 mStatusBar.getAttrs().privateFlags &= ~PRIVATE_FLAG_KEYGUARD;
4699 mStatusBar.getAttrs().flags &= ~FLAG_SHOW_WALLPAPER;
4700 return true;
4701 } else {
4702 return false;
4703 }
4704 }
4705
4706 private boolean isStatusBarKeyguard() {
4707 return mStatusBar != null
4708 && (mStatusBar.getAttrs().privateFlags & PRIVATE_FLAG_KEYGUARD) != 0;
4709 }
4710
Jose Lima9546b202014-07-02 17:21:51 -07004711 @Override
Dianne Hackborn08743722009-12-21 12:16:51 -08004712 public boolean allowAppAnimationsLw() {
Jorim Jaggi380ecb82014-03-14 17:25:20 +01004713 if (isStatusBarKeyguard() || mShowingDream) {
Craig Mautner28816302013-10-10 20:31:00 -07004714 // If keyguard or dreams is currently visible, no reason to animate behind it.
Dianne Hackborn08743722009-12-21 12:16:51 -08004715 return false;
4716 }
Dianne Hackborn08743722009-12-21 12:16:51 -08004717 return true;
4718 }
4719
Jose Lima9546b202014-07-02 17:21:51 -07004720 @Override
Dianne Hackborndf89e652011-10-06 22:35:11 -07004721 public int focusChangedLw(WindowState lastFocus, WindowState newFocus) {
Joe Onorato664644d2011-01-23 17:53:23 -08004722 mFocusedWindow = newFocus;
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07004723 if ((updateSystemUiVisibilityLw()&SYSTEM_UI_CHANGING_LAYOUT) != 0) {
Dianne Hackborndf89e652011-10-06 22:35:11 -07004724 // If the navigation bar has been hidden or shown, we need to do another
4725 // layout pass to update that window.
4726 return FINISH_LAYOUT_REDO_LAYOUT;
4727 }
4728 return 0;
Joe Onorato664644d2011-01-23 17:53:23 -08004729 }
4730
Dianne Hackborn0ecadf72009-03-31 18:00:37 -07004731 /** {@inheritDoc} */
Jose Lima9546b202014-07-02 17:21:51 -07004732 @Override
Jeff Brown46b9ac02010-04-22 18:58:52 -07004733 public void notifyLidSwitchChanged(long whenNanos, boolean lidOpen) {
4734 // lid changed state
Jeff Brownc458ce92012-04-30 14:58:40 -07004735 final int newLidState = lidOpen ? LID_OPEN : LID_CLOSED;
4736 if (newLidState == mLidState) {
4737 return;
4738 }
Jeff Brown01a98dd2011-09-20 15:08:29 -07004739
Jeff Brownc458ce92012-04-30 14:58:40 -07004740 mLidState = newLidState;
4741 applyLidSwitchState();
Jeff Brown01a98dd2011-09-20 15:08:29 -07004742 updateRotation(true);
Jeff Brownc458ce92012-04-30 14:58:40 -07004743
4744 if (lidOpen) {
Dianne Hackborn280a64e2015-07-13 14:48:08 -07004745 wakeUp(SystemClock.uptimeMillis(), mAllowTheaterModeWakeFromLidSwitch,
4746 "android.policy:LID");
Jeff Brownc458ce92012-04-30 14:58:40 -07004747 } else if (!mLidControlsSleep) {
Jeff Brown96307042012-07-27 15:51:34 -07004748 mPowerManager.userActivity(SystemClock.uptimeMillis(), false);
Jeff Brown46b9ac02010-04-22 18:58:52 -07004749 }
4750 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004751
Michael Wright3818c922014-09-02 13:59:07 -07004752 @Override
4753 public void notifyCameraLensCoverSwitchChanged(long whenNanos, boolean lensCovered) {
4754 int lensCoverState = lensCovered ? CAMERA_LENS_COVERED : CAMERA_LENS_UNCOVERED;
4755 if (mCameraLensCoverState == lensCoverState) {
4756 return;
4757 }
4758 if (mCameraLensCoverState == CAMERA_LENS_COVERED &&
4759 lensCoverState == CAMERA_LENS_UNCOVERED) {
4760 Intent intent;
4761 final boolean keyguardActive = mKeyguardDelegate == null ? false :
4762 mKeyguardDelegate.isShowing();
4763 if (keyguardActive) {
4764 intent = new Intent(MediaStore.INTENT_ACTION_STILL_IMAGE_CAMERA_SECURE);
4765 } else {
4766 intent = new Intent(MediaStore.INTENT_ACTION_STILL_IMAGE_CAMERA);
4767 }
Dianne Hackborn280a64e2015-07-13 14:48:08 -07004768 wakeUp(whenNanos / 1000000, mAllowTheaterModeWakeFromCameraLens,
4769 "android.policy:CAMERA_COVER");
Bart Sears8b1c27c2015-03-18 23:51:02 +00004770 startActivityAsUser(intent, UserHandle.CURRENT_OR_SELF);
Michael Wright3818c922014-09-02 13:59:07 -07004771 }
4772 mCameraLensCoverState = lensCoverState;
4773 }
4774
Dianne Hackbornad7fa7f2011-01-07 14:06:50 -08004775 void setHdmiPlugged(boolean plugged) {
4776 if (mHdmiPlugged != plugged) {
4777 mHdmiPlugged = plugged;
Dianne Hackbornf87d1962012-04-04 12:48:24 -07004778 updateRotation(true, true);
Dianne Hackbornad7fa7f2011-01-07 14:06:50 -08004779 Intent intent = new Intent(ACTION_HDMI_PLUGGED);
Joe Onoratodc100302011-01-11 17:07:41 -08004780 intent.addFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY_BEFORE_BOOT);
Dianne Hackbornad7fa7f2011-01-07 14:06:50 -08004781 intent.putExtra(EXTRA_HDMI_PLUGGED_STATE, plugged);
Dianne Hackborn5ac72a22012-08-29 18:32:08 -07004782 mContext.sendStickyBroadcastAsUser(intent, UserHandle.ALL);
Dianne Hackbornad7fa7f2011-01-07 14:06:50 -08004783 }
4784 }
4785
Joe Onoratoea495d42011-04-06 11:41:11 -07004786 void initializeHdmiState() {
Joe Onorato7ba631f2011-05-04 15:28:00 -07004787 boolean plugged = false;
Joe Onoratoea495d42011-04-06 11:41:11 -07004788 // watch for HDMI plug messages if the hdmi switch exists
4789 if (new File("/sys/devices/virtual/switch/hdmi/state").exists()) {
4790 mHDMIObserver.startObserving("DEVPATH=/devices/virtual/switch/hdmi");
4791
Joe Onoratoea495d42011-04-06 11:41:11 -07004792 final String filename = "/sys/class/switch/hdmi/state";
4793 FileReader reader = null;
4794 try {
4795 reader = new FileReader(filename);
4796 char[] buf = new char[15];
4797 int n = reader.read(buf);
4798 if (n > 1) {
4799 plugged = 0 != Integer.parseInt(new String(buf, 0, n-1));
4800 }
4801 } catch (IOException ex) {
4802 Slog.w(TAG, "Couldn't read hdmi state from " + filename + ": " + ex);
4803 } catch (NumberFormatException ex) {
4804 Slog.w(TAG, "Couldn't read hdmi state from " + filename + ": " + ex);
4805 } finally {
4806 if (reader != null) {
4807 try {
4808 reader.close();
4809 } catch (IOException ex) {
4810 }
Joe Onoratodc100302011-01-11 17:07:41 -08004811 }
4812 }
4813 }
Joe Onorato7ba631f2011-05-04 15:28:00 -07004814 // This dance forces the code in setHdmiPlugged to run.
4815 // Always do this so the sticky intent is stuck (to false) if there is no hdmi.
4816 mHdmiPlugged = !plugged;
4817 setHdmiPlugged(!mHdmiPlugged);
Joe Onoratodc100302011-01-11 17:07:41 -08004818 }
4819
Dianne Hackbornc0e3f242011-08-19 14:19:10 -07004820 final Object mScreenshotLock = new Object();
Dianne Hackbornfc8fa632011-08-17 16:20:47 -07004821 ServiceConnection mScreenshotConnection = null;
Dianne Hackbornfc8fa632011-08-17 16:20:47 -07004822
Jeff Brownd5bb82d2011-10-12 13:57:59 -07004823 final Runnable mScreenshotTimeout = new Runnable() {
4824 @Override public void run() {
4825 synchronized (mScreenshotLock) {
4826 if (mScreenshotConnection != null) {
4827 mContext.unbindService(mScreenshotConnection);
4828 mScreenshotConnection = null;
Dianne Hackbornfc8fa632011-08-17 16:20:47 -07004829 }
Winson Chung9112ec32011-06-27 13:15:32 -07004830 }
Jeff Brownd5bb82d2011-10-12 13:57:59 -07004831 }
4832 };
4833
4834 // Assume this is called from the Handler thread.
4835 private void takeScreenshot() {
4836 synchronized (mScreenshotLock) {
4837 if (mScreenshotConnection != null) {
4838 return;
4839 }
4840 ComponentName cn = new ComponentName("com.android.systemui",
4841 "com.android.systemui.screenshot.TakeScreenshotService");
4842 Intent intent = new Intent();
4843 intent.setComponent(cn);
4844 ServiceConnection conn = new ServiceConnection() {
4845 @Override
4846 public void onServiceConnected(ComponentName name, IBinder service) {
4847 synchronized (mScreenshotLock) {
4848 if (mScreenshotConnection != this) {
4849 return;
4850 }
4851 Messenger messenger = new Messenger(service);
4852 Message msg = Message.obtain(null, 1);
4853 final ServiceConnection myConn = this;
4854 Handler h = new Handler(mHandler.getLooper()) {
4855 @Override
4856 public void handleMessage(Message msg) {
4857 synchronized (mScreenshotLock) {
4858 if (mScreenshotConnection == myConn) {
4859 mContext.unbindService(mScreenshotConnection);
4860 mScreenshotConnection = null;
4861 mHandler.removeCallbacks(mScreenshotTimeout);
4862 }
4863 }
4864 }
4865 };
4866 msg.replyTo = new Messenger(h);
Winson Chunga63bb842011-10-17 10:26:28 -07004867 msg.arg1 = msg.arg2 = 0;
4868 if (mStatusBar != null && mStatusBar.isVisibleLw())
4869 msg.arg1 = 1;
4870 if (mNavigationBar != null && mNavigationBar.isVisibleLw())
4871 msg.arg2 = 1;
Jeff Brownd5bb82d2011-10-12 13:57:59 -07004872 try {
4873 messenger.send(msg);
4874 } catch (RemoteException e) {
4875 }
4876 }
4877 }
4878 @Override
4879 public void onServiceDisconnected(ComponentName name) {}
4880 };
Amith Yamasani27b89e62013-01-16 12:30:11 -08004881 if (mContext.bindServiceAsUser(
4882 intent, conn, Context.BIND_AUTO_CREATE, UserHandle.CURRENT)) {
Jeff Brownd5bb82d2011-10-12 13:57:59 -07004883 mScreenshotConnection = conn;
4884 mHandler.postDelayed(mScreenshotTimeout, 10000);
4885 }
4886 }
Winson Chung9112ec32011-06-27 13:15:32 -07004887 }
4888
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004889 /** {@inheritDoc} */
Jeff Brown00fa7bd2010-07-02 15:37:36 -07004890 @Override
Jeff Brown037c33e2014-04-09 00:31:55 -07004891 public int interceptKeyBeforeQueueing(KeyEvent event, int policyFlags) {
Jeff Brown96307042012-07-27 15:51:34 -07004892 if (!mSystemBooted) {
4893 // If we have not yet booted, don't let key events do anything.
4894 return 0;
4895 }
4896
Jeff Brown037c33e2014-04-09 00:31:55 -07004897 final boolean interactive = (policyFlags & FLAG_INTERACTIVE) != 0;
Jeff Brown1f245102010-11-18 20:53:46 -08004898 final boolean down = event.getAction() == KeyEvent.ACTION_DOWN;
4899 final boolean canceled = event.isCanceled();
4900 final int keyCode = event.getKeyCode();
Jeff Browne20c9e02010-10-11 14:20:19 -07004901
Jeff Brown3122e442010-10-11 23:32:49 -07004902 final boolean isInjected = (policyFlags & WindowManagerPolicy.FLAG_INJECTED) != 0;
Jeff Brown3122e442010-10-11 23:32:49 -07004903
Mike Lockwoodc72b15f2009-11-28 20:58:22 -05004904 // If screen is off then we treat the case where the keyguard is open but hidden
4905 // the same as if it were open and in front.
4906 // This will prevent any keys other than the power button from waking the screen
4907 // when the keyguard is hidden by another activity.
Jim Miller5ecd8112013-01-09 18:50:26 -08004908 final boolean keyguardActive = (mKeyguardDelegate == null ? false :
Jeff Brown037c33e2014-04-09 00:31:55 -07004909 (interactive ?
Jim Millerab954542014-10-10 18:21:49 -07004910 isKeyguardShowingAndNotOccluded() :
Jim Miller5ecd8112013-01-09 18:50:26 -08004911 mKeyguardDelegate.isShowing()));
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004912
Jeff Brown40013652012-05-16 21:22:36 -07004913 if (DEBUG_INPUT) {
Jeff Brown00fa7bd2010-07-02 15:37:36 -07004914 Log.d(TAG, "interceptKeyTq keycode=" + keyCode
Jeff Brown037c33e2014-04-09 00:31:55 -07004915 + " interactive=" + interactive + " keyguardActive=" + keyguardActive
Jeff Brown26875502014-01-30 21:47:47 -08004916 + " policyFlags=" + Integer.toHexString(policyFlags));
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004917 }
4918
Jeff Brown037c33e2014-04-09 00:31:55 -07004919 // Basic policy based on interactive state.
Jeff Brown4d396052010-10-29 21:50:21 -07004920 int result;
Michael Wright337d9d22014-04-22 15:03:48 -07004921 boolean isWakeKey = (policyFlags & WindowManagerPolicy.FLAG_WAKE) != 0
4922 || event.isWakeKey();
Michael Wrightfc01f042014-09-08 14:12:24 -07004923 if (interactive || (isInjected && !isWakeKey)) {
RoboErikde9ba392014-09-26 12:51:01 -07004924 // When the device is interactive or the key is injected pass the
4925 // key to the application.
Jeff Brown4d396052010-10-29 21:50:21 -07004926 result = ACTION_PASS_TO_USER;
Jose Lima9546b202014-07-02 17:21:51 -07004927 isWakeKey = false;
Michael Wrightfc01f042014-09-08 14:12:24 -07004928 } else if (!interactive && shouldDispatchInputWhenNonInteractive()) {
4929 // If we're currently dozing with the screen on and the keyguard showing, pass the key
4930 // to the application but preserve its wake key status to make sure we still move
4931 // from dozing to fully interactive if we would normally go from off to fully
4932 // interactive.
4933 result = ACTION_PASS_TO_USER;
Jeff Brown4d396052010-10-29 21:50:21 -07004934 } else {
4935 // When the screen is off and the key is not injected, determine whether
4936 // to wake the device but don't pass the key to the application.
4937 result = 0;
Jeff Brown26875502014-01-30 21:47:47 -08004938 if (isWakeKey && (!down || !isWakeKeyWhenScreenOff(keyCode))) {
4939 isWakeKey = false;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004940 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004941 }
4942
Justin Kohd378ad72013-04-01 12:18:26 -07004943 // If the key would be handled globally, just return the result, don't worry about special
4944 // key processing.
Jeff Brown13f00f02014-10-31 14:45:50 -07004945 if (isValidGlobalKey(keyCode)
4946 && mGlobalKeyManager.shouldHandleGlobalKey(keyCode, event)) {
Michael Wright85b1af62014-06-04 14:51:58 -07004947 if (isWakeKey) {
Dianne Hackborn280a64e2015-07-13 14:48:08 -07004948 wakeUp(event.getEventTime(), mAllowTheaterModeWakeFromKey, "android.policy:KEY");
Michael Wright85b1af62014-06-04 14:51:58 -07004949 }
Justin Kohd378ad72013-04-01 12:18:26 -07004950 return result;
4951 }
4952
Jeff Brownbae8e772014-06-12 19:59:45 -07004953 boolean useHapticFeedback = down
4954 && (policyFlags & WindowManagerPolicy.FLAG_VIRTUAL) != 0
4955 && event.getRepeatCount() == 0;
4956
Jeff Brown4d396052010-10-29 21:50:21 -07004957 // Handle special keys.
4958 switch (keyCode) {
4959 case KeyEvent.KEYCODE_VOLUME_DOWN:
Jeff Brownb0418da2010-11-01 15:24:01 -07004960 case KeyEvent.KEYCODE_VOLUME_UP:
4961 case KeyEvent.KEYCODE_VOLUME_MUTE: {
RoboErik001c59c2015-01-26 15:53:51 -08004962 if (mUseTvRouting) {
4963 // On TVs volume keys never go to the foreground app
4964 result &= ~ACTION_PASS_TO_USER;
4965 }
Jeff Brownd5bb82d2011-10-12 13:57:59 -07004966 if (keyCode == KeyEvent.KEYCODE_VOLUME_DOWN) {
4967 if (down) {
Jeff Brown13f00f02014-10-31 14:45:50 -07004968 if (interactive && !mScreenshotChordVolumeDownKeyTriggered
Jeff Brownd5bb82d2011-10-12 13:57:59 -07004969 && (event.getFlags() & KeyEvent.FLAG_FALLBACK) == 0) {
Jeff Brown13f00f02014-10-31 14:45:50 -07004970 mScreenshotChordVolumeDownKeyTriggered = true;
4971 mScreenshotChordVolumeDownKeyTime = event.getDownTime();
4972 mScreenshotChordVolumeDownKeyConsumed = false;
Jeff Brownd5bb82d2011-10-12 13:57:59 -07004973 cancelPendingPowerKeyAction();
4974 interceptScreenshotChord();
4975 }
4976 } else {
Jeff Brown13f00f02014-10-31 14:45:50 -07004977 mScreenshotChordVolumeDownKeyTriggered = false;
Jeff Brownd5bb82d2011-10-12 13:57:59 -07004978 cancelPendingScreenshotChordAction();
4979 }
4980 } else if (keyCode == KeyEvent.KEYCODE_VOLUME_UP) {
4981 if (down) {
Jeff Brown13f00f02014-10-31 14:45:50 -07004982 if (interactive && !mScreenshotChordVolumeUpKeyTriggered
Jeff Brownd5bb82d2011-10-12 13:57:59 -07004983 && (event.getFlags() & KeyEvent.FLAG_FALLBACK) == 0) {
Jeff Brown13f00f02014-10-31 14:45:50 -07004984 mScreenshotChordVolumeUpKeyTriggered = true;
Jeff Brownd5bb82d2011-10-12 13:57:59 -07004985 cancelPendingPowerKeyAction();
4986 cancelPendingScreenshotChordAction();
4987 }
4988 } else {
Jeff Brown13f00f02014-10-31 14:45:50 -07004989 mScreenshotChordVolumeUpKeyTriggered = false;
Jeff Brownd5bb82d2011-10-12 13:57:59 -07004990 cancelPendingScreenshotChordAction();
4991 }
4992 }
Jeff Brown4d396052010-10-29 21:50:21 -07004993 if (down) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -07004994 TelecomManager telecomManager = getTelecommService();
4995 if (telecomManager != null) {
4996 if (telecomManager.isRinging()) {
Santos Cordon6848f722014-05-21 15:22:12 -07004997 // If an incoming call is ringing, either VOLUME key means
4998 // "silence ringer". We handle these keys here, rather than
4999 // in the InCallScreen, to make sure we'll respond to them
5000 // even if the InCallScreen hasn't come to the foreground yet.
5001 // Look for the DOWN event here, to agree with the "fallback"
5002 // behavior in the InCallScreen.
5003 Log.i(TAG, "interceptKeyBeforeQueueing:"
5004 + " VOLUME key-down while ringing: Silence ringer!");
Jeff Brown4d396052010-10-29 21:50:21 -07005005
Santos Cordon6848f722014-05-21 15:22:12 -07005006 // Silence the ringer. (It's safe to call this
5007 // even if the ringer has already been silenced.)
Tyler Gunnef9f6f92014-09-12 22:16:17 -07005008 telecomManager.silenceRinger();
Jeff Brown4d396052010-10-29 21:50:21 -07005009
Santos Cordon6848f722014-05-21 15:22:12 -07005010 // And *don't* pass this key thru to the current activity
5011 // (which is probably the InCallScreen.)
5012 result &= ~ACTION_PASS_TO_USER;
5013 break;
5014 }
Tyler Gunnef9f6f92014-09-12 22:16:17 -07005015 if (telecomManager.isInCall()
Santos Cordon6848f722014-05-21 15:22:12 -07005016 && (result & ACTION_PASS_TO_USER) == 0) {
5017 // If we are in call but we decided not to pass the key to
RoboErik430fc482014-06-12 15:49:20 -07005018 // the application, just pass it to the session service.
5019
5020 MediaSessionLegacyHelper.getHelper(mContext)
RoboErik3c45c292014-07-08 16:47:31 -07005021 .sendVolumeKeyEvent(event, false);
Santos Cordon6848f722014-05-21 15:22:12 -07005022 break;
Jeff Brown4d396052010-10-29 21:50:21 -07005023 }
5024 }
5025
RoboErik430fc482014-06-12 15:49:20 -07005026 if ((result & ACTION_PASS_TO_USER) == 0) {
RoboErik001c59c2015-01-26 15:53:51 -08005027 if (mUseTvRouting) {
5028 dispatchDirectAudioEvent(event);
5029 } else {
5030 // If we aren't passing to the user and no one else
5031 // handled it send it to the session manager to
5032 // figure out.
5033 MediaSessionLegacyHelper.getHelper(mContext)
5034 .sendVolumeKeyEvent(event, true);
5035 }
Jeff Brown4d396052010-10-29 21:50:21 -07005036 break;
5037 }
5038 }
5039 break;
5040 }
5041
5042 case KeyEvent.KEYCODE_ENDCALL: {
5043 result &= ~ACTION_PASS_TO_USER;
5044 if (down) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -07005045 TelecomManager telecomManager = getTelecommService();
Jeff Brown4d396052010-10-29 21:50:21 -07005046 boolean hungUp = false;
Tyler Gunnef9f6f92014-09-12 22:16:17 -07005047 if (telecomManager != null) {
5048 hungUp = telecomManager.endCall();
Jeff Brown4d396052010-10-29 21:50:21 -07005049 }
Jeff Brown13f00f02014-10-31 14:45:50 -07005050 if (interactive && !hungUp) {
5051 mEndCallKeyHandled = false;
5052 mHandler.postDelayed(mEndCallLongPress,
5053 ViewConfiguration.get(mContext).getDeviceGlobalActionKeyTimeout());
5054 } else {
5055 mEndCallKeyHandled = true;
5056 }
Jeff Brown4d396052010-10-29 21:50:21 -07005057 } else {
Jeff Brown13f00f02014-10-31 14:45:50 -07005058 if (!mEndCallKeyHandled) {
5059 mHandler.removeCallbacks(mEndCallLongPress);
5060 if (!canceled) {
5061 if ((mEndcallBehavior
5062 & Settings.System.END_BUTTON_BEHAVIOR_HOME) != 0) {
5063 if (goHome()) {
5064 break;
5065 }
Dianne Hackborn0041e972009-07-24 17:14:43 -07005066 }
Jeff Brown13f00f02014-10-31 14:45:50 -07005067 if ((mEndcallBehavior
5068 & Settings.System.END_BUTTON_BEHAVIOR_SLEEP) != 0) {
5069 mPowerManager.goToSleep(event.getEventTime(),
5070 PowerManager.GO_TO_SLEEP_REASON_POWER_BUTTON, 0);
5071 isWakeKey = false;
5072 }
Jeff Brown4d396052010-10-29 21:50:21 -07005073 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005074 }
Jeff Brown4d396052010-10-29 21:50:21 -07005075 }
5076 break;
5077 }
5078
5079 case KeyEvent.KEYCODE_POWER: {
5080 result &= ~ACTION_PASS_TO_USER;
Jeff Brown13f00f02014-10-31 14:45:50 -07005081 isWakeKey = false; // wake-up will be handled separately
Jeff Brown4d396052010-10-29 21:50:21 -07005082 if (down) {
Jeff Brown13f00f02014-10-31 14:45:50 -07005083 interceptPowerKeyDown(event, interactive);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005084 } else {
Jeff Brown13f00f02014-10-31 14:45:50 -07005085 interceptPowerKeyUp(event, interactive, canceled);
Jeff Brown4d396052010-10-29 21:50:21 -07005086 }
5087 break;
5088 }
5089
Jeff Brown6212a492014-03-07 13:58:47 -08005090 case KeyEvent.KEYCODE_SLEEP: {
5091 result &= ~ACTION_PASS_TO_USER;
Filip Gruszczynskia483a1d2015-03-17 19:06:58 +00005092 isWakeKey = false;
Jeff Brownbae8e772014-06-12 19:59:45 -07005093 if (!mPowerManager.isInteractive()) {
5094 useHapticFeedback = false; // suppress feedback if already non-interactive
5095 }
Nick Vaccarob593a812015-05-15 11:23:05 -07005096 if (down) {
5097 sleepPress(event.getEventTime());
5098 } else {
5099 sleepRelease(event.getEventTime());
5100 }
Jeff Brown6212a492014-03-07 13:58:47 -08005101 break;
5102 }
5103
Nick Armstrong-Crews56ecfcc2015-09-07 21:46:50 -07005104 case KeyEvent.KEYCODE_SOFT_SLEEP: {
5105 result &= ~ACTION_PASS_TO_USER;
5106 isWakeKey = false;
5107 if (!down) {
5108 mPowerManagerInternal.setUserInactiveOverrideFromWindowManager();
5109 }
5110 break;
5111 }
5112
Jeff Brown6212a492014-03-07 13:58:47 -08005113 case KeyEvent.KEYCODE_WAKEUP: {
5114 result &= ~ACTION_PASS_TO_USER;
Jose Lima9546b202014-07-02 17:21:51 -07005115 isWakeKey = true;
Jeff Brown6212a492014-03-07 13:58:47 -08005116 break;
5117 }
5118
Jeff Brown4d396052010-10-29 21:50:21 -07005119 case KeyEvent.KEYCODE_MEDIA_PLAY:
5120 case KeyEvent.KEYCODE_MEDIA_PAUSE:
5121 case KeyEvent.KEYCODE_MEDIA_PLAY_PAUSE:
Jeff Brown4d396052010-10-29 21:50:21 -07005122 case KeyEvent.KEYCODE_HEADSETHOOK:
5123 case KeyEvent.KEYCODE_MUTE:
5124 case KeyEvent.KEYCODE_MEDIA_STOP:
5125 case KeyEvent.KEYCODE_MEDIA_NEXT:
5126 case KeyEvent.KEYCODE_MEDIA_PREVIOUS:
5127 case KeyEvent.KEYCODE_MEDIA_REWIND:
5128 case KeyEvent.KEYCODE_MEDIA_RECORD:
Jaekyun Seokbfdad8e2013-07-08 13:53:21 +09005129 case KeyEvent.KEYCODE_MEDIA_FAST_FORWARD:
5130 case KeyEvent.KEYCODE_MEDIA_AUDIO_TRACK: {
RoboErikde9ba392014-09-26 12:51:01 -07005131 if (MediaSessionLegacyHelper.getHelper(mContext).isGlobalPriorityActive()) {
5132 // If the global session is active pass all media keys to it
5133 // instead of the active window.
5134 result &= ~ACTION_PASS_TO_USER;
5135 }
Jeff Brown4d396052010-10-29 21:50:21 -07005136 if ((result & ACTION_PASS_TO_USER) == 0) {
5137 // Only do this if we would otherwise not pass it to the user. In that
5138 // case, the PhoneWindow class will do the same thing, except it will
5139 // only do it if the showing app doesn't process the key on its own.
Jeff Brown40013652012-05-16 21:22:36 -07005140 // Note that we need to make a copy of the key event here because the
5141 // original key event will be recycled when we return.
Jeff Brown4d396052010-10-29 21:50:21 -07005142 mBroadcastWakeLock.acquire();
Jeff Brown40013652012-05-16 21:22:36 -07005143 Message msg = mHandler.obtainMessage(MSG_DISPATCH_MEDIA_KEY_WITH_WAKE_LOCK,
5144 new KeyEvent(event));
5145 msg.setAsynchronous(true);
5146 msg.sendToTarget();
Jeff Brown4d396052010-10-29 21:50:21 -07005147 }
5148 break;
Jeff Brown00fa7bd2010-07-02 15:37:36 -07005149 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005150
Jeff Brown4d396052010-10-29 21:50:21 -07005151 case KeyEvent.KEYCODE_CALL: {
5152 if (down) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -07005153 TelecomManager telecomManager = getTelecommService();
5154 if (telecomManager != null) {
5155 if (telecomManager.isRinging()) {
Santos Cordon6848f722014-05-21 15:22:12 -07005156 Log.i(TAG, "interceptKeyBeforeQueueing:"
5157 + " CALL key-down while ringing: Answer the call!");
Tyler Gunnef9f6f92014-09-12 22:16:17 -07005158 telecomManager.acceptRingingCall();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005159
Santos Cordon6848f722014-05-21 15:22:12 -07005160 // And *don't* pass this key thru to the current activity
5161 // (which is presumably the InCallScreen.)
5162 result &= ~ACTION_PASS_TO_USER;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005163 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005164 }
Jeff Brown00fa7bd2010-07-02 15:37:36 -07005165 }
Jeff Brown4d396052010-10-29 21:50:21 -07005166 break;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005167 }
Michael Wright869a67c2014-08-26 19:33:06 -07005168 case KeyEvent.KEYCODE_VOICE_ASSIST: {
5169 // Only do this if we would otherwise not pass it to the user. In that case,
5170 // interceptKeyBeforeDispatching would apply a similar but different policy in
5171 // order to invoke voice assist actions. Note that we need to make a copy of the
5172 // key event here because the original key event will be recycled when we return.
5173 if ((result & ACTION_PASS_TO_USER) == 0 && !down) {
5174 mBroadcastWakeLock.acquire();
5175 Message msg = mHandler.obtainMessage(MSG_LAUNCH_VOICE_ASSIST_WITH_WAKE_LOCK,
5176 keyguardActive ? 1 : 0, 0);
5177 msg.setAsynchronous(true);
5178 msg.sendToTarget();
5179 }
5180 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005181 }
Jeff Brown26875502014-01-30 21:47:47 -08005182
Jeff Brownbae8e772014-06-12 19:59:45 -07005183 if (useHapticFeedback) {
5184 performHapticFeedbackLw(null, HapticFeedbackConstants.VIRTUAL_KEY, false);
5185 }
5186
Jeff Brown26875502014-01-30 21:47:47 -08005187 if (isWakeKey) {
Dianne Hackborn280a64e2015-07-13 14:48:08 -07005188 wakeUp(event.getEventTime(), mAllowTheaterModeWakeFromKey, "android.policy:KEY");
Jeff Brown26875502014-01-30 21:47:47 -08005189 }
Bryce Lee584a4452014-10-21 15:55:55 -07005190
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005191 return result;
5192 }
5193
Jeff Brown1c2e4942012-11-06 16:32:01 -08005194 /**
Jeff Brown13f00f02014-10-31 14:45:50 -07005195 * Returns true if the key can have global actions attached to it.
5196 * We reserve all power management keys for the system since they require
5197 * very careful handling.
5198 */
5199 private static boolean isValidGlobalKey(int keyCode) {
5200 switch (keyCode) {
5201 case KeyEvent.KEYCODE_POWER:
5202 case KeyEvent.KEYCODE_WAKEUP:
5203 case KeyEvent.KEYCODE_SLEEP:
5204 return false;
5205 default:
5206 return true;
5207 }
5208 }
5209
5210 /**
Jeff Brown1c2e4942012-11-06 16:32:01 -08005211 * When the screen is off we ignore some keys that might otherwise typically
5212 * be considered wake keys. We filter them out here.
5213 *
5214 * {@link KeyEvent#KEYCODE_POWER} is notably absent from this list because it
5215 * is always considered a wake key.
5216 */
5217 private boolean isWakeKeyWhenScreenOff(int keyCode) {
5218 switch (keyCode) {
5219 // ignore volume keys unless docked
5220 case KeyEvent.KEYCODE_VOLUME_UP:
5221 case KeyEvent.KEYCODE_VOLUME_DOWN:
5222 case KeyEvent.KEYCODE_VOLUME_MUTE:
5223 return mDockMode != Intent.EXTRA_DOCK_STATE_UNDOCKED;
5224
5225 // ignore media and camera keys
5226 case KeyEvent.KEYCODE_MUTE:
5227 case KeyEvent.KEYCODE_HEADSETHOOK:
5228 case KeyEvent.KEYCODE_MEDIA_PLAY:
5229 case KeyEvent.KEYCODE_MEDIA_PAUSE:
5230 case KeyEvent.KEYCODE_MEDIA_PLAY_PAUSE:
5231 case KeyEvent.KEYCODE_MEDIA_STOP:
5232 case KeyEvent.KEYCODE_MEDIA_NEXT:
5233 case KeyEvent.KEYCODE_MEDIA_PREVIOUS:
5234 case KeyEvent.KEYCODE_MEDIA_REWIND:
5235 case KeyEvent.KEYCODE_MEDIA_RECORD:
5236 case KeyEvent.KEYCODE_MEDIA_FAST_FORWARD:
Jaekyun Seokbfdad8e2013-07-08 13:53:21 +09005237 case KeyEvent.KEYCODE_MEDIA_AUDIO_TRACK:
Jeff Brown1c2e4942012-11-06 16:32:01 -08005238 case KeyEvent.KEYCODE_CAMERA:
5239 return false;
5240 }
5241 return true;
5242 }
5243
5244
Jeff Brown56194eb2011-03-02 19:23:13 -08005245 /** {@inheritDoc} */
5246 @Override
Michael Wright70af00a2014-09-03 19:30:20 -07005247 public int interceptMotionBeforeQueueingNonInteractive(long whenNanos, int policyFlags) {
5248 if ((policyFlags & FLAG_WAKE) != 0) {
Dianne Hackborn280a64e2015-07-13 14:48:08 -07005249 if (wakeUp(whenNanos / 1000000, mAllowTheaterModeWakeFromMotion,
5250 "android.policy:MOTION")) {
Bryce Lee5c138322014-11-03 08:26:09 -08005251 return 0;
5252 }
Michael Wright70af00a2014-09-03 19:30:20 -07005253 }
Bryce Lee5c138322014-11-03 08:26:09 -08005254
Michael Wright70af00a2014-09-03 19:30:20 -07005255 if (shouldDispatchInputWhenNonInteractive()) {
5256 return ACTION_PASS_TO_USER;
5257 }
Bryce Lee5c138322014-11-03 08:26:09 -08005258
Bryce Lee812d7022014-11-10 13:33:28 -08005259 // If we have not passed the action up and we are in theater mode without dreaming,
5260 // there will be no dream to intercept the touch and wake into ambient. The device should
5261 // wake up in this case.
5262 if (isTheaterModeEnabled() && (policyFlags & FLAG_WAKE) != 0) {
Dianne Hackborn280a64e2015-07-13 14:48:08 -07005263 wakeUp(whenNanos / 1000000, mAllowTheaterModeWakeFromMotionWhenNotDreaming,
5264 "android.policy:MOTION");
Bryce Lee812d7022014-11-10 13:33:28 -08005265 }
5266
Jeff Brown037c33e2014-04-09 00:31:55 -07005267 return 0;
Jeff Brown56194eb2011-03-02 19:23:13 -08005268 }
5269
Michael Wright70af00a2014-09-03 19:30:20 -07005270 private boolean shouldDispatchInputWhenNonInteractive() {
Michael Wright2ccf0c82015-08-04 23:03:03 +01005271 if (mDisplay == null || mDisplay.getState() == Display.STATE_OFF) {
5272 return false;
5273 }
5274 // Send events to keyguard while the screen is on and it's showing.
5275 if (isKeyguardShowingAndNotOccluded()) {
Bryce Lee5c138322014-11-03 08:26:09 -08005276 return true;
5277 }
5278
5279 // Send events to a dozing dream even if the screen is off since the dream
5280 // is in control of the state of the screen.
5281 IDreamManager dreamManager = getDreamManager();
5282
5283 try {
5284 if (dreamManager != null && dreamManager.isDreaming()) {
5285 return true;
5286 }
5287 } catch (RemoteException e) {
5288 Slog.e(TAG, "RemoteException when checking if dreaming", e);
5289 }
5290
5291 // Otherwise, consume events since the user can't see what is being
5292 // interacted with.
5293 return false;
Michael Wright70af00a2014-09-03 19:30:20 -07005294 }
5295
RoboErik001c59c2015-01-26 15:53:51 -08005296 private void dispatchDirectAudioEvent(KeyEvent event) {
5297 if (event.getAction() != KeyEvent.ACTION_DOWN) {
5298 return;
5299 }
5300 int keyCode = event.getKeyCode();
John Spurlockb94f2d62015-03-17 14:11:57 -04005301 int flags = AudioManager.FLAG_SHOW_UI | AudioManager.FLAG_PLAY_SOUND
5302 | AudioManager.FLAG_FROM_KEY;
RoboErik001c59c2015-01-26 15:53:51 -08005303 String pkgName = mContext.getOpPackageName();
5304 switch (keyCode) {
5305 case KeyEvent.KEYCODE_VOLUME_UP:
5306 try {
John Spurlockee5ad722015-03-03 16:17:21 -05005307 getAudioService().adjustSuggestedStreamVolume(AudioManager.ADJUST_RAISE,
John Spurlock90874332015-03-10 16:00:54 -04005308 AudioManager.USE_DEFAULT_STREAM_TYPE, flags, pkgName, TAG);
RoboErik001c59c2015-01-26 15:53:51 -08005309 } catch (RemoteException e) {
5310 Log.e(TAG, "Error dispatching volume up in dispatchTvAudioEvent.", e);
5311 }
5312 break;
5313 case KeyEvent.KEYCODE_VOLUME_DOWN:
5314 try {
John Spurlockee5ad722015-03-03 16:17:21 -05005315 getAudioService().adjustSuggestedStreamVolume(AudioManager.ADJUST_LOWER,
John Spurlock90874332015-03-10 16:00:54 -04005316 AudioManager.USE_DEFAULT_STREAM_TYPE, flags, pkgName, TAG);
RoboErik001c59c2015-01-26 15:53:51 -08005317 } catch (RemoteException e) {
5318 Log.e(TAG, "Error dispatching volume down in dispatchTvAudioEvent.", e);
5319 }
5320 break;
5321 case KeyEvent.KEYCODE_VOLUME_MUTE:
5322 try {
5323 if (event.getRepeatCount() == 0) {
John Spurlockee5ad722015-03-03 16:17:21 -05005324 getAudioService().adjustSuggestedStreamVolume(
5325 AudioManager.ADJUST_TOGGLE_MUTE,
John Spurlock90874332015-03-10 16:00:54 -04005326 AudioManager.USE_DEFAULT_STREAM_TYPE, flags, pkgName, TAG);
RoboErik001c59c2015-01-26 15:53:51 -08005327 }
5328 } catch (RemoteException e) {
5329 Log.e(TAG, "Error dispatching mute in dispatchTvAudioEvent.", e);
5330 }
5331 break;
5332 }
5333 }
5334
Jeff Brown40013652012-05-16 21:22:36 -07005335 void dispatchMediaKeyWithWakeLock(KeyEvent event) {
5336 if (DEBUG_INPUT) {
5337 Slog.d(TAG, "dispatchMediaKeyWithWakeLock: " + event);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005338 }
5339
Jeff Brown40013652012-05-16 21:22:36 -07005340 if (mHavePendingMediaKeyRepeatWithWakeLock) {
5341 if (DEBUG_INPUT) {
5342 Slog.d(TAG, "dispatchMediaKeyWithWakeLock: canceled repeat");
5343 }
5344
5345 mHandler.removeMessages(MSG_DISPATCH_MEDIA_KEY_REPEAT_WITH_WAKE_LOCK);
5346 mHavePendingMediaKeyRepeatWithWakeLock = false;
5347 mBroadcastWakeLock.release(); // pending repeat was holding onto the wake lock
5348 }
5349
5350 dispatchMediaKeyWithWakeLockToAudioService(event);
5351
5352 if (event.getAction() == KeyEvent.ACTION_DOWN
5353 && event.getRepeatCount() == 0) {
5354 mHavePendingMediaKeyRepeatWithWakeLock = true;
5355
5356 Message msg = mHandler.obtainMessage(
5357 MSG_DISPATCH_MEDIA_KEY_REPEAT_WITH_WAKE_LOCK, event);
5358 msg.setAsynchronous(true);
5359 mHandler.sendMessageDelayed(msg, ViewConfiguration.getKeyRepeatTimeout());
5360 } else {
5361 mBroadcastWakeLock.release();
5362 }
5363 }
5364
5365 void dispatchMediaKeyRepeatWithWakeLock(KeyEvent event) {
5366 mHavePendingMediaKeyRepeatWithWakeLock = false;
5367
5368 KeyEvent repeatEvent = KeyEvent.changeTimeRepeat(event,
5369 SystemClock.uptimeMillis(), 1, event.getFlags() | KeyEvent.FLAG_LONG_PRESS);
5370 if (DEBUG_INPUT) {
5371 Slog.d(TAG, "dispatchMediaKeyRepeatWithWakeLock: " + repeatEvent);
5372 }
5373
5374 dispatchMediaKeyWithWakeLockToAudioService(repeatEvent);
5375 mBroadcastWakeLock.release();
5376 }
5377
5378 void dispatchMediaKeyWithWakeLockToAudioService(KeyEvent event) {
5379 if (ActivityManagerNative.isSystemReady()) {
RoboErik430fc482014-06-12 15:49:20 -07005380 MediaSessionLegacyHelper.getHelper(mContext).sendMediaButtonEvent(event, true);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005381 }
5382 }
5383
Michael Wright869a67c2014-08-26 19:33:06 -07005384 void launchVoiceAssistWithWakeLock(boolean keyguardActive) {
Dianne Hackbornb6683c42015-06-18 17:40:33 -07005385 IDeviceIdleController dic = IDeviceIdleController.Stub.asInterface(
5386 ServiceManager.getService(Context.DEVICE_IDLE_CONTROLLER));
5387 if (dic != null) {
5388 try {
5389 dic.exitIdle("voice-search");
5390 } catch (RemoteException e) {
5391 }
5392 }
Michael Wright869a67c2014-08-26 19:33:06 -07005393 Intent voiceIntent =
5394 new Intent(RecognizerIntent.ACTION_VOICE_SEARCH_HANDS_FREE);
5395 voiceIntent.putExtra(RecognizerIntent.EXTRA_SECURE, keyguardActive);
Bart Sears8b1c27c2015-03-18 23:51:02 +00005396 startActivityAsUser(voiceIntent, UserHandle.CURRENT_OR_SELF);
Michael Wright869a67c2014-08-26 19:33:06 -07005397 mBroadcastWakeLock.release();
5398 }
5399
Mike Lockwood1753f7f2009-08-24 14:49:07 -07005400 BroadcastReceiver mDockReceiver = new BroadcastReceiver() {
Craig Mautnereee29c42013-01-17 14:44:34 -08005401 @Override
Mike Lockwood1753f7f2009-08-24 14:49:07 -07005402 public void onReceive(Context context, Intent intent) {
Dianne Hackborn867ab6472010-04-29 13:28:56 -07005403 if (Intent.ACTION_DOCK_EVENT.equals(intent.getAction())) {
5404 mDockMode = intent.getIntExtra(Intent.EXTRA_DOCK_STATE,
5405 Intent.EXTRA_DOCK_STATE_UNDOCKED);
Daniel Sandler6396c722013-04-16 20:19:09 -04005406 } else {
5407 try {
5408 IUiModeManager uiModeService = IUiModeManager.Stub.asInterface(
5409 ServiceManager.getService(Context.UI_MODE_SERVICE));
5410 mUiMode = uiModeService.getCurrentModeType();
5411 } catch (RemoteException e) {
5412 }
Dianne Hackborn80fa1662009-10-07 14:02:10 -07005413 }
Jeff Brown01a98dd2011-09-20 15:08:29 -07005414 updateRotation(true);
Craig Mautnereee29c42013-01-17 14:44:34 -08005415 synchronized (mLock) {
5416 updateOrientationListenerLp();
5417 }
Mike Lockwood1753f7f2009-08-24 14:49:07 -07005418 }
5419 };
5420
Jeff Brown6aaf2952012-10-05 16:01:08 -07005421 BroadcastReceiver mDreamReceiver = new BroadcastReceiver() {
5422 @Override
5423 public void onReceive(Context context, Intent intent) {
5424 if (Intent.ACTION_DREAMING_STARTED.equals(intent.getAction())) {
Jim Miller5ecd8112013-01-09 18:50:26 -08005425 if (mKeyguardDelegate != null) {
5426 mKeyguardDelegate.onDreamingStarted();
Jeff Brown6aaf2952012-10-05 16:01:08 -07005427 }
5428 } else if (Intent.ACTION_DREAMING_STOPPED.equals(intent.getAction())) {
Jim Miller5ecd8112013-01-09 18:50:26 -08005429 if (mKeyguardDelegate != null) {
5430 mKeyguardDelegate.onDreamingStopped();
Jeff Brown6aaf2952012-10-05 16:01:08 -07005431 }
5432 }
5433 }
5434 };
5435
Christopher Tate5e08af02012-09-21 17:17:22 -07005436 BroadcastReceiver mMultiuserReceiver = new BroadcastReceiver() {
5437 @Override
5438 public void onReceive(Context context, Intent intent) {
5439 if (Intent.ACTION_USER_SWITCHED.equals(intent.getAction())) {
5440 // tickle the settings observer: this first ensures that we're
5441 // observing the relevant settings for the newly-active user,
5442 // and then updates our own bookkeeping based on the now-
5443 // current user.
5444 mSettingsObserver.onChange(false);
John Spurlockce479d82012-11-29 09:52:21 -05005445
5446 // force a re-application of focused window sysui visibility.
5447 // the window may never have been shown for this user
5448 // e.g. the keyguard when going through the new-user setup flow
John Spurlock04db1762013-05-13 12:46:41 -04005449 synchronized (mWindowManagerFuncs.getWindowManagerLock()) {
John Spurlockce479d82012-11-29 09:52:21 -05005450 mLastSystemUiFlags = 0;
5451 updateSystemUiVisibilityLw();
5452 }
Christopher Tate5e08af02012-09-21 17:17:22 -07005453 }
5454 }
5455 };
5456
Adrian Roosddc8b272015-05-21 16:28:27 -07005457 private final Runnable mHiddenNavPanic = new Runnable() {
John Spurlockd9b70bd2014-02-06 17:02:44 -05005458 @Override
5459 public void run() {
Adrian Roosddc8b272015-05-21 16:28:27 -07005460 synchronized (mWindowManagerFuncs.getWindowManagerLock()) {
5461 if (!isUserSetupComplete()) {
5462 // Swipe-up for navigation bar is disabled during setup
5463 return;
5464 }
5465 mPendingPanicGestureUptime = SystemClock.uptimeMillis();
5466 mNavigationBarController.showTransient();
5467 }
John Spurlockd9b70bd2014-02-06 17:02:44 -05005468 }
5469 };
5470
John Spurlocke1f366f2013-08-05 12:22:40 -04005471 private void requestTransientBars(WindowState swipeTarget) {
John Spurlock04db1762013-05-13 12:46:41 -04005472 synchronized (mWindowManagerFuncs.getWindowManagerLock()) {
Maurice Lam99c6e072014-04-28 18:24:28 -07005473 if (!isUserSetupComplete()) {
5474 // Swipe-up for navigation bar is disabled during setup
5475 return;
5476 }
John Spurlock27735a42013-08-14 17:57:38 -04005477 boolean sb = mStatusBarController.checkShowTransientBarLw();
5478 boolean nb = mNavigationBarController.checkShowTransientBarLw();
John Spurlockad3e6cb2013-04-30 08:47:43 -04005479 if (sb || nb) {
Adrian Roos62b65e42015-02-25 18:05:34 +01005480 // Don't show status bar when swiping on already visible navigation bar
5481 if (!nb && swipeTarget == mNavigationBar) {
John Spurlocke1f366f2013-08-05 12:22:40 -04005482 if (DEBUG) Slog.d(TAG, "Not showing transient bar, wrong swipe target");
John Spurlockad3e6cb2013-04-30 08:47:43 -04005483 return;
5484 }
John Spurlock27735a42013-08-14 17:57:38 -04005485 if (sb) mStatusBarController.showTransient();
5486 if (nb) mNavigationBarController.showTransient();
John Spurlockf1a36642013-10-12 17:50:42 -04005487 mImmersiveModeConfirmation.confirmCurrentPrompt();
John Spurlockad3e6cb2013-04-30 08:47:43 -04005488 updateSystemUiVisibilityLw();
John Spurlock32beb2c2013-03-11 10:16:47 -04005489 }
John Spurlockad3e6cb2013-04-30 08:47:43 -04005490 }
5491 }
5492
Jeff Brown3ee549c2014-09-22 20:14:39 -07005493 // Called on the PowerManager's Notifier thread.
Jeff Brownc38c9be2012-10-04 13:16:19 -07005494 @Override
Jeff Brown416c49c2015-05-26 19:50:18 -07005495 public void startedGoingToSleep(int why) {
5496 if (DEBUG_WAKEUP) Slog.i(TAG, "Started going to sleep... (why=" + why + ")");
Jorim Jaggid175b6c2015-05-27 15:39:09 -07005497 if (mKeyguardDelegate != null) {
5498 mKeyguardDelegate.onStartedGoingToSleep(why);
5499 }
Jeff Brown416c49c2015-05-26 19:50:18 -07005500 }
5501
5502 // Called on the PowerManager's Notifier thread.
5503 @Override
5504 public void finishedGoingToSleep(int why) {
Dianne Hackborn74489012009-03-24 20:50:09 -07005505 EventLog.writeEvent(70000, 0);
Jeff Brown416c49c2015-05-26 19:50:18 -07005506 if (DEBUG_WAKEUP) Slog.i(TAG, "Finished going to sleep... (why=" + why + ")");
Chris Wren9bb290b2015-06-29 12:02:13 -04005507 MetricsLogger.histogram(mContext, "screen_timeout", mLockScreenTimeout / 1000);
Jeff Brown3ee549c2014-09-22 20:14:39 -07005508
5509 // We must get this work done here because the power manager will drop
5510 // the wake lock and let the system suspend once this function returns.
The Android Open Source Project0727d222009-03-11 12:11:58 -07005511 synchronized (mLock) {
Jeff Brown3ee549c2014-09-22 20:14:39 -07005512 mAwake = false;
Jeff Browna20dda42014-05-27 20:57:24 -07005513 updateWakeGestureListenerLp();
The Android Open Source Project0727d222009-03-11 12:11:58 -07005514 updateOrientationListenerLp();
Mike Lockwood28569302010-01-28 11:54:40 -05005515 updateLockScreenTimeout();
The Android Open Source Project0727d222009-03-11 12:11:58 -07005516 }
Jeff Brown3ee549c2014-09-22 20:14:39 -07005517 if (mKeyguardDelegate != null) {
Jorim Jaggid175b6c2015-05-27 15:39:09 -07005518 mKeyguardDelegate.onFinishedGoingToSleep(why);
Jeff Brown3ee549c2014-09-22 20:14:39 -07005519 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005520 }
5521
Jeff Brown3ee549c2014-09-22 20:14:39 -07005522 // Called on the PowerManager's Notifier thread.
Jeff Brownc38c9be2012-10-04 13:16:19 -07005523 @Override
Jeff Brown416c49c2015-05-26 19:50:18 -07005524 public void startedWakingUp() {
Dianne Hackborn74489012009-03-24 20:50:09 -07005525 EventLog.writeEvent(70000, 1);
Jeff Brown416c49c2015-05-26 19:50:18 -07005526 if (DEBUG_WAKEUP) Slog.i(TAG, "Started waking up...");
Craig Mautner8a0da012014-05-31 15:13:37 -07005527
Jeff Brown3ee549c2014-09-22 20:14:39 -07005528 // Since goToSleep performs these functions synchronously, we must
5529 // do the same here. We cannot post this work to a handler because
5530 // that might cause it to become reordered with respect to what
5531 // may happen in a future call to goToSleep.
The Android Open Source Project0727d222009-03-11 12:11:58 -07005532 synchronized (mLock) {
Jeff Brown3ee549c2014-09-22 20:14:39 -07005533 mAwake = true;
Jeff Brown3ee549c2014-09-22 20:14:39 -07005534
Jeff Browna20dda42014-05-27 20:57:24 -07005535 updateWakeGestureListenerLp();
The Android Open Source Project0727d222009-03-11 12:11:58 -07005536 updateOrientationListenerLp();
Mike Lockwood28569302010-01-28 11:54:40 -05005537 updateLockScreenTimeout();
The Android Open Source Project0727d222009-03-11 12:11:58 -07005538 }
Jeff Brownc38c9be2012-10-04 13:16:19 -07005539
Jim Miller5ecd8112013-01-09 18:50:26 -08005540 if (mKeyguardDelegate != null) {
Jorim Jaggi740452e2015-07-09 12:13:59 -07005541 mKeyguardDelegate.onStartedWakingUp();
Jeff Brownc38c9be2012-10-04 13:16:19 -07005542 }
Jeff Brown36c4db82014-09-19 12:05:31 -07005543 }
5544
Jeff Brown416c49c2015-05-26 19:50:18 -07005545 // Called on the PowerManager's Notifier thread.
5546 @Override
5547 public void finishedWakingUp() {
5548 if (DEBUG_WAKEUP) Slog.i(TAG, "Finished waking up...");
5549 }
5550
5551 private void wakeUpFromPowerKey(long eventTime) {
Dianne Hackborn280a64e2015-07-13 14:48:08 -07005552 wakeUp(eventTime, mAllowTheaterModeWakeFromPowerKey, "android.policy:POWER");
Jeff Brown416c49c2015-05-26 19:50:18 -07005553 }
5554
Dianne Hackborn280a64e2015-07-13 14:48:08 -07005555 private boolean wakeUp(long wakeTime, boolean wakeInTheaterMode, String reason) {
Bryce Leed3896842015-06-23 17:06:51 -07005556 final boolean theaterModeEnabled = isTheaterModeEnabled();
5557 if (!wakeInTheaterMode && theaterModeEnabled) {
Jeff Brown416c49c2015-05-26 19:50:18 -07005558 return false;
5559 }
5560
Bryce Leed3896842015-06-23 17:06:51 -07005561 if (theaterModeEnabled) {
5562 Settings.Global.putInt(mContext.getContentResolver(),
5563 Settings.Global.THEATER_MODE_ON, 0);
5564 }
5565
Dianne Hackborn280a64e2015-07-13 14:48:08 -07005566 mPowerManager.wakeUp(wakeTime, reason);
Jeff Brown416c49c2015-05-26 19:50:18 -07005567 return true;
5568 }
5569
Jeff Brown36c4db82014-09-19 12:05:31 -07005570 private void finishKeyguardDrawn() {
Jeff Brown3ee549c2014-09-22 20:14:39 -07005571 synchronized (mLock) {
Jorim Jaggif3255482015-07-24 12:32:42 -07005572 if (!mScreenOnEarly || mKeyguardDrawComplete) {
Stefan Kuhne9326dc12015-06-12 09:25:32 -10005573 return; // We are not awake yet or we have already informed of this event.
Jeff Brown3ee549c2014-09-22 20:14:39 -07005574 }
5575
Jeff Brown36c4db82014-09-19 12:05:31 -07005576 mKeyguardDrawComplete = true;
Jeff Brown3ee549c2014-09-22 20:14:39 -07005577 if (mKeyguardDelegate != null) {
5578 mHandler.removeMessages(MSG_KEYGUARD_DRAWN_TIMEOUT);
5579 }
Jorim Jaggi740452e2015-07-09 12:13:59 -07005580 mWindowManagerDrawComplete = false;
Jeff Brown3ee549c2014-09-22 20:14:39 -07005581 }
5582
Jorim Jaggi740452e2015-07-09 12:13:59 -07005583 // ... eventually calls finishWindowsDrawn which will finalize our screen turn on
5584 // as well as enabling the orientation change logic/sensor.
5585 mWindowManagerInternal.waitForAllWindowsDrawn(mWindowManagerDrawCallback,
5586 WAITING_FOR_DRAWN_TIMEOUT);
Jeff Brown3ee549c2014-09-22 20:14:39 -07005587 }
5588
5589 // Called on the DisplayManager's DisplayPowerController thread.
5590 @Override
5591 public void screenTurnedOff() {
5592 if (DEBUG_WAKEUP) Slog.i(TAG, "Screen turned off...");
5593
Jeff Brown48d1b142015-06-10 16:36:03 -07005594 updateScreenOffSleepToken(true);
Jeff Brown3ee549c2014-09-22 20:14:39 -07005595 synchronized (mLock) {
5596 mScreenOnEarly = false;
5597 mScreenOnFully = false;
Jorim Jaggi95c6dae2015-07-29 15:17:23 -07005598 mKeyguardDrawComplete = false;
Jeff Brown3ee549c2014-09-22 20:14:39 -07005599 mWindowManagerDrawComplete = false;
5600 mScreenOnListener = null;
5601 updateOrientationListenerLp();
Jorim Jaggi0d210f62015-07-10 14:24:44 -07005602
5603 if (mKeyguardDelegate != null) {
5604 mKeyguardDelegate.onScreenTurnedOff();
5605 }
Jeff Brown36c4db82014-09-19 12:05:31 -07005606 }
5607 }
5608
Jeff Brown3ee549c2014-09-22 20:14:39 -07005609 // Called on the DisplayManager's DisplayPowerController thread.
Jeff Brown36c4db82014-09-19 12:05:31 -07005610 @Override
5611 public void screenTurningOn(final ScreenOnListener screenOnListener) {
Jeff Brown36c4db82014-09-19 12:05:31 -07005612 if (DEBUG_WAKEUP) Slog.i(TAG, "Screen turning on...");
Jeff Brown36c4db82014-09-19 12:05:31 -07005613
Jeff Brown48d1b142015-06-10 16:36:03 -07005614 updateScreenOffSleepToken(false);
Jeff Brown3ee549c2014-09-22 20:14:39 -07005615 synchronized (mLock) {
5616 mScreenOnEarly = true;
5617 mScreenOnFully = false;
Jorim Jaggi95c6dae2015-07-29 15:17:23 -07005618 mKeyguardDrawComplete = false;
Jeff Brown3ee549c2014-09-22 20:14:39 -07005619 mWindowManagerDrawComplete = false;
5620 mScreenOnListener = screenOnListener;
Jeff Brown36c4db82014-09-19 12:05:31 -07005621
Jorim Jaggi740452e2015-07-09 12:13:59 -07005622 if (mKeyguardDelegate != null) {
Jorim Jaggia4b51bc2015-08-10 18:20:43 -07005623 mHandler.removeMessages(MSG_KEYGUARD_DRAWN_TIMEOUT);
5624 mHandler.sendEmptyMessageDelayed(MSG_KEYGUARD_DRAWN_TIMEOUT, 1000);
Jorim Jaggi740452e2015-07-09 12:13:59 -07005625 mKeyguardDelegate.onScreenTurningOn(mKeyguardDrawnCallback);
5626 } else {
5627 if (DEBUG_WAKEUP) Slog.d(TAG,
5628 "null mKeyguardDelegate: setting mKeyguardDrawComplete.");
5629 finishKeyguardDrawn();
5630 }
5631 }
Jeff Brown36c4db82014-09-19 12:05:31 -07005632 }
5633
Jorim Jaggi0d210f62015-07-10 14:24:44 -07005634 // Called on the DisplayManager's DisplayPowerController thread.
5635 @Override
5636 public void screenTurnedOn() {
5637 synchronized (mLock) {
5638 if (mKeyguardDelegate != null) {
5639 mKeyguardDelegate.onScreenTurnedOn();
5640 }
5641 }
5642 }
5643
Jeff Brown36c4db82014-09-19 12:05:31 -07005644 private void finishWindowsDrawn() {
Jeff Brown3ee549c2014-09-22 20:14:39 -07005645 synchronized (mLock) {
5646 if (!mScreenOnEarly || mWindowManagerDrawComplete) {
Stefan Kuhne9326dc12015-06-12 09:25:32 -10005647 return; // Screen is not turned on or we did already handle this case earlier.
Jeff Brown3ee549c2014-09-22 20:14:39 -07005648 }
5649
Jeff Brown36c4db82014-09-19 12:05:31 -07005650 mWindowManagerDrawComplete = true;
Jeff Brown36c4db82014-09-19 12:05:31 -07005651 }
Jeff Brown3ee549c2014-09-22 20:14:39 -07005652
5653 finishScreenTurningOn();
Jeff Brownc38c9be2012-10-04 13:16:19 -07005654 }
5655
Craig Mautner8a0da012014-05-31 15:13:37 -07005656 private void finishScreenTurningOn() {
Stefan Kuhne9326dc12015-06-12 09:25:32 -10005657 synchronized (mLock) {
5658 // We have just finished drawing screen content. Since the orientation listener
5659 // gets only installed when all windows are drawn, we try to install it again.
5660 updateOrientationListenerLp();
5661 }
Jeff Brown3ee549c2014-09-22 20:14:39 -07005662 final ScreenOnListener listener;
5663 final boolean enableScreen;
Jeff Brown36c4db82014-09-19 12:05:31 -07005664 synchronized (mLock) {
Jeff Brown3ee549c2014-09-22 20:14:39 -07005665 if (DEBUG_WAKEUP) Slog.d(TAG,
5666 "finishScreenTurningOn: mAwake=" + mAwake
5667 + ", mScreenOnEarly=" + mScreenOnEarly
5668 + ", mScreenOnFully=" + mScreenOnFully
5669 + ", mKeyguardDrawComplete=" + mKeyguardDrawComplete
5670 + ", mWindowManagerDrawComplete=" + mWindowManagerDrawComplete);
5671
5672 if (mScreenOnFully || !mScreenOnEarly || !mWindowManagerDrawComplete
5673 || (mAwake && !mKeyguardDrawComplete)) {
5674 return; // spurious or not ready yet
Jeff Brown36c4db82014-09-19 12:05:31 -07005675 }
5676
Jeff Brown3ee549c2014-09-22 20:14:39 -07005677 if (DEBUG_WAKEUP) Slog.i(TAG, "Finished screen turning on...");
5678 listener = mScreenOnListener;
Craig Mautner13f6ea72014-06-23 14:57:02 -07005679 mScreenOnListener = null;
Jeff Brown3ee549c2014-09-22 20:14:39 -07005680 mScreenOnFully = true;
5681
5682 // Remember the first time we draw the keyguard so we know when we're done with
5683 // the main part of booting and can enable the screen and hide boot messages.
5684 if (!mKeyguardDrawnOnce && mAwake) {
5685 mKeyguardDrawnOnce = true;
5686 enableScreen = true;
5687 if (mBootMessageNeedsHiding) {
5688 mBootMessageNeedsHiding = false;
5689 hideBootMessages();
5690 }
5691 } else {
5692 enableScreen = false;
5693 }
Jeff Brownc38c9be2012-10-04 13:16:19 -07005694 }
5695
Jeff Brown3ee549c2014-09-22 20:14:39 -07005696 if (listener != null) {
5697 listener.onScreenOn();
5698 }
Jeff Brown4fc45272012-10-10 18:28:14 -07005699
Jeff Brown3ee549c2014-09-22 20:14:39 -07005700 if (enableScreen) {
5701 try {
5702 mWindowManager.enableScreenIfNeeded();
5703 } catch (RemoteException unhandled) {
Jeff Brown36c4db82014-09-19 12:05:31 -07005704 }
Craig Mautnera631d492014-08-05 15:16:01 -07005705 }
5706 }
5707
5708 private void handleHideBootMessage() {
Jeff Brown3ee549c2014-09-22 20:14:39 -07005709 synchronized (mLock) {
5710 if (!mKeyguardDrawnOnce) {
5711 mBootMessageNeedsHiding = true;
5712 return; // keyguard hasn't drawn the first time yet, not done booting
5713 }
Craig Mautnera631d492014-08-05 15:16:01 -07005714 }
Jeff Brown3ee549c2014-09-22 20:14:39 -07005715
5716 if (mBootMsgDialog != null) {
5717 if (DEBUG_WAKEUP) Slog.d(TAG, "handleHideBootMessage: dismissing");
5718 mBootMsgDialog.dismiss();
5719 mBootMsgDialog = null;
Craig Mautnera631d492014-08-05 15:16:01 -07005720 }
Jeff Brownc38c9be2012-10-04 13:16:19 -07005721 }
5722
5723 @Override
Jeff Brown3ee549c2014-09-22 20:14:39 -07005724 public boolean isScreenOn() {
5725 return mScreenOnFully;
Dianne Hackborn08743722009-12-21 12:16:51 -08005726 }
Jeff Brownc38c9be2012-10-04 13:16:19 -07005727
Dianne Hackborn08743722009-12-21 12:16:51 -08005728 /** {@inheritDoc} */
Jose Lima9546b202014-07-02 17:21:51 -07005729 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005730 public void enableKeyguard(boolean enabled) {
Jim Miller5ecd8112013-01-09 18:50:26 -08005731 if (mKeyguardDelegate != null) {
5732 mKeyguardDelegate.setKeyguardEnabled(enabled);
Mike Lockwood3a74bd32011-08-12 13:55:22 -07005733 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005734 }
5735
5736 /** {@inheritDoc} */
Jose Lima9546b202014-07-02 17:21:51 -07005737 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005738 public void exitKeyguardSecurely(OnKeyguardExitResult callback) {
Jim Miller5ecd8112013-01-09 18:50:26 -08005739 if (mKeyguardDelegate != null) {
5740 mKeyguardDelegate.verifyUnlock(callback);
Mike Lockwood3a74bd32011-08-12 13:55:22 -07005741 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005742 }
5743
Jim Millerab954542014-10-10 18:21:49 -07005744 private boolean isKeyguardShowingAndNotOccluded() {
Jim Miller5ecd8112013-01-09 18:50:26 -08005745 if (mKeyguardDelegate == null) return false;
Jim Millerab954542014-10-10 18:21:49 -07005746 return mKeyguardDelegate.isShowing() && !mKeyguardOccluded;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005747 }
5748
Mike Lockwood520d8bc2011-02-18 13:23:13 -05005749 /** {@inheritDoc} */
Jose Lima9546b202014-07-02 17:21:51 -07005750 @Override
Mike Lockwood520d8bc2011-02-18 13:23:13 -05005751 public boolean isKeyguardLocked() {
5752 return keyguardOn();
5753 }
5754
5755 /** {@inheritDoc} */
Jose Lima9546b202014-07-02 17:21:51 -07005756 @Override
Mike Lockwood520d8bc2011-02-18 13:23:13 -05005757 public boolean isKeyguardSecure() {
Jim Miller5ecd8112013-01-09 18:50:26 -08005758 if (mKeyguardDelegate == null) return false;
5759 return mKeyguardDelegate.isSecure();
Mike Lockwood520d8bc2011-02-18 13:23:13 -05005760 }
5761
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005762 /** {@inheritDoc} */
Jose Lima9546b202014-07-02 17:21:51 -07005763 @Override
Adrian Roos461829d2015-06-03 14:41:18 -07005764 public boolean isKeyguardShowingOrOccluded() {
5765 return mKeyguardDelegate == null ? false : mKeyguardDelegate.isShowing();
5766 }
5767
5768 /** {@inheritDoc} */
5769 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005770 public boolean inKeyguardRestrictedKeyInputMode() {
Jim Miller5ecd8112013-01-09 18:50:26 -08005771 if (mKeyguardDelegate == null) return false;
5772 return mKeyguardDelegate.isInputRestricted();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005773 }
5774
Jose Lima9546b202014-07-02 17:21:51 -07005775 @Override
Dianne Hackborn90c52de2011-09-23 12:57:44 -07005776 public void dismissKeyguardLw() {
RoboErik8a2cfc32014-05-16 11:19:38 -07005777 if (mKeyguardDelegate != null && mKeyguardDelegate.isShowing()) {
Craig Mautnerc0d2d0a2014-10-31 16:25:15 -07005778 if (DEBUG_KEYGUARD) Slog.d(TAG, "PWM.dismissKeyguardLw");
Daniel Sandler1ce804392012-11-07 15:07:12 -05005779 mHandler.post(new Runnable() {
Jose Lima9546b202014-07-02 17:21:51 -07005780 @Override
Daniel Sandler1ce804392012-11-07 15:07:12 -05005781 public void run() {
Jorim Jaggi8de4311c2014-08-11 22:36:20 +02005782 // ask the keyguard to prompt the user to authenticate if necessary
5783 mKeyguardDelegate.dismiss();
5784 }
5785 });
5786 }
5787 }
5788
5789 public void notifyActivityDrawnForKeyguardLw() {
5790 if (mKeyguardDelegate != null) {
5791 mHandler.post(new Runnable() {
5792 @Override
5793 public void run() {
5794 mKeyguardDelegate.onActivityDrawn();
Daniel Sandler1ce804392012-11-07 15:07:12 -05005795 }
5796 });
Dianne Hackborn90c52de2011-09-23 12:57:44 -07005797 }
5798 }
5799
Jorim Jaggicff0acb2014-03-31 16:35:15 +02005800 @Override
5801 public boolean isKeyguardDrawnLw() {
5802 synchronized (mLock) {
Jeff Brown3ee549c2014-09-22 20:14:39 -07005803 return mKeyguardDrawnOnce;
Jorim Jaggicff0acb2014-03-31 16:35:15 +02005804 }
5805 }
5806
Jorim Jaggi0d674622014-05-21 01:34:15 +02005807 @Override
Jorim Jaggie29b2db2014-05-30 23:17:03 +02005808 public void startKeyguardExitAnimation(long startTime, long fadeoutDuration) {
Jorim Jaggi0d674622014-05-21 01:34:15 +02005809 if (mKeyguardDelegate != null) {
Craig Mautnerc0d2d0a2014-10-31 16:25:15 -07005810 if (DEBUG_KEYGUARD) Slog.d(TAG, "PWM.startKeyguardExitAnimation");
Jorim Jaggie29b2db2014-05-30 23:17:03 +02005811 mKeyguardDelegate.startKeyguardExitAnimation(startTime, fadeoutDuration);
Jorim Jaggi0d674622014-05-21 01:34:15 +02005812 }
5813 }
5814
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005815 void sendCloseSystemWindows() {
Jorim Jaggib10e33f2015-02-04 21:57:40 +01005816 PhoneWindow.sendCloseSystemWindows(mContext, null);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005817 }
5818
5819 void sendCloseSystemWindows(String reason) {
Jorim Jaggib10e33f2015-02-04 21:57:40 +01005820 PhoneWindow.sendCloseSystemWindows(mContext, reason);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005821 }
Mitsuru Oshima831d0d92009-06-16 18:27:18 -07005822
Jeff Brown01a98dd2011-09-20 15:08:29 -07005823 @Override
5824 public int rotationForOrientationLw(int orientation, int lastRotation) {
Daniel Sandler2ed6ad62011-02-22 14:54:17 -05005825 if (false) {
5826 Slog.v(TAG, "rotationForOrientationLw(orient="
5827 + orientation + ", last=" + lastRotation
5828 + "); user=" + mUserRotation + " "
5829 + ((mUserRotationMode == WindowManagerPolicy.USER_ROTATION_LOCKED)
5830 ? "USER_ROTATION_LOCKED" : "")
5831 );
5832 }
5833
Craig Mautner46ac6fa2013-08-01 10:06:34 -07005834 if (mForceDefaultOrientation) {
5835 return Surface.ROTATION_0;
5836 }
5837
The Android Open Source Project0727d222009-03-11 12:11:58 -07005838 synchronized (mLock) {
Jeff Brownc0347aa2011-09-23 17:26:09 -07005839 int sensorRotation = mOrientationListener.getProposedRotation(); // may be -1
5840 if (sensorRotation < 0) {
Jeff Brown0f862b42012-09-27 21:11:01 -07005841 sensorRotation = lastRotation;
Jeff Brownc0347aa2011-09-23 17:26:09 -07005842 }
Jeff Brown01a98dd2011-09-20 15:08:29 -07005843
Jeff Browndec6cf42011-11-15 14:08:20 -08005844 final int preferredRotation;
Jeff Brown2e7760e2012-04-11 15:14:55 -07005845 if (mLidState == LID_OPEN && mLidOpenRotation >= 0) {
Jeff Brown01a98dd2011-09-20 15:08:29 -07005846 // Ignore sensor when lid switch is open and rotation is forced.
5847 preferredRotation = mLidOpenRotation;
5848 } else if (mDockMode == Intent.EXTRA_DOCK_STATE_CAR
Jeff Brownc0347aa2011-09-23 17:26:09 -07005849 && (mCarDockEnablesAccelerometer || mCarDockRotation >= 0)) {
Jeff Brown01a98dd2011-09-20 15:08:29 -07005850 // Ignore sensor when in car dock unless explicitly enabled.
5851 // This case can override the behavior of NOSENSOR, and can also
5852 // enable 180 degree rotation while docked.
Jeff Brownc0347aa2011-09-23 17:26:09 -07005853 preferredRotation = mCarDockEnablesAccelerometer
Jeff Brown01a98dd2011-09-20 15:08:29 -07005854 ? sensorRotation : mCarDockRotation;
Jeff Brown1a693182011-11-08 14:44:16 -08005855 } else if ((mDockMode == Intent.EXTRA_DOCK_STATE_DESK
5856 || mDockMode == Intent.EXTRA_DOCK_STATE_LE_DESK
5857 || mDockMode == Intent.EXTRA_DOCK_STATE_HE_DESK)
Jeff Brownc0347aa2011-09-23 17:26:09 -07005858 && (mDeskDockEnablesAccelerometer || mDeskDockRotation >= 0)) {
Jeff Brown01a98dd2011-09-20 15:08:29 -07005859 // Ignore sensor when in desk dock unless explicitly enabled.
5860 // This case can override the behavior of NOSENSOR, and can also
5861 // enable 180 degree rotation while docked.
Jeff Brownc0347aa2011-09-23 17:26:09 -07005862 preferredRotation = mDeskDockEnablesAccelerometer
Jeff Brown01a98dd2011-09-20 15:08:29 -07005863 ? sensorRotation : mDeskDockRotation;
Jeff Brownc82c89ed2013-04-17 17:18:15 -07005864 } else if (mHdmiPlugged && mDemoHdmiRotationLock) {
5865 // Ignore sensor when plugged into HDMI when demo HDMI rotation lock enabled.
Jeff Browneb3e4b92011-12-06 19:54:24 -08005866 // Note that the dock orientation overrides the HDMI orientation.
Jeff Brownc82c89ed2013-04-17 17:18:15 -07005867 preferredRotation = mDemoHdmiRotation;
5868 } else if (mHdmiPlugged && mDockMode == Intent.EXTRA_DOCK_STATE_UNDOCKED
5869 && mUndockedHdmiRotation >= 0) {
5870 // Ignore sensor when plugged into HDMI and an undocked orientation has
5871 // been specified in the configuration (only for legacy devices without
5872 // full multi-display support).
5873 // Note that the dock orientation overrides the HDMI orientation.
5874 preferredRotation = mUndockedHdmiRotation;
Chong Zhangae6119ff2014-11-11 18:54:39 -08005875 } else if (mDemoRotationLock) {
5876 // Ignore sensor when demo rotation lock is enabled.
5877 // Note that the dock orientation and HDMI rotation lock override this.
5878 preferredRotation = mDemoRotation;
Dianne Hackbornb9ec1ac2013-04-10 17:34:25 -07005879 } else if (orientation == ActivityInfo.SCREEN_ORIENTATION_LOCKED) {
5880 // Application just wants to remain locked in the last rotation.
5881 preferredRotation = lastRotation;
Jeff Brownbcdfc622014-03-06 19:13:04 -08005882 } else if (!mSupportAutoRotation) {
5883 // If we don't support auto-rotation then bail out here and ignore
5884 // the sensor and any rotation lock settings.
5885 preferredRotation = -1;
Jeff Brown207673cd2012-06-05 17:47:11 -07005886 } else if ((mUserRotationMode == WindowManagerPolicy.USER_ROTATION_FREE
Jeff Brown01a98dd2011-09-20 15:08:29 -07005887 && (orientation == ActivityInfo.SCREEN_ORIENTATION_USER
Dianne Hackbornb9ec1ac2013-04-10 17:34:25 -07005888 || orientation == ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED
5889 || orientation == ActivityInfo.SCREEN_ORIENTATION_USER_LANDSCAPE
5890 || orientation == ActivityInfo.SCREEN_ORIENTATION_USER_PORTRAIT
5891 || orientation == ActivityInfo.SCREEN_ORIENTATION_FULL_USER))
Jeff Brown01a98dd2011-09-20 15:08:29 -07005892 || orientation == ActivityInfo.SCREEN_ORIENTATION_SENSOR
5893 || orientation == ActivityInfo.SCREEN_ORIENTATION_FULL_SENSOR
5894 || orientation == ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE
5895 || orientation == ActivityInfo.SCREEN_ORIENTATION_SENSOR_PORTRAIT) {
5896 // Otherwise, use sensor only if requested by the application or enabled
5897 // by default for USER or UNSPECIFIED modes. Does not apply to NOSENSOR.
Jeff Brownd3187e32011-09-21 19:26:44 -07005898 if (mAllowAllRotations < 0) {
5899 // Can't read this during init() because the context doesn't
5900 // have display metrics at that time so we cannot determine
5901 // tablet vs. phone then.
5902 mAllowAllRotations = mContext.getResources().getBoolean(
5903 com.android.internal.R.bool.config_allowAllRotations) ? 1 : 0;
5904 }
Jeff Brown01a98dd2011-09-20 15:08:29 -07005905 if (sensorRotation != Surface.ROTATION_180
Jeff Brownd3187e32011-09-21 19:26:44 -07005906 || mAllowAllRotations == 1
Dianne Hackbornb9ec1ac2013-04-10 17:34:25 -07005907 || orientation == ActivityInfo.SCREEN_ORIENTATION_FULL_SENSOR
5908 || orientation == ActivityInfo.SCREEN_ORIENTATION_FULL_USER) {
Jeff Brown01a98dd2011-09-20 15:08:29 -07005909 preferredRotation = sensorRotation;
5910 } else {
5911 preferredRotation = lastRotation;
5912 }
Jeff Brown207673cd2012-06-05 17:47:11 -07005913 } else if (mUserRotationMode == WindowManagerPolicy.USER_ROTATION_LOCKED
5914 && orientation != ActivityInfo.SCREEN_ORIENTATION_NOSENSOR) {
5915 // Apply rotation lock. Does not apply to NOSENSOR.
5916 // The idea is that the user rotation expresses a weak preference for the direction
5917 // of gravity and as NOSENSOR is never affected by gravity, then neither should
5918 // NOSENSOR be affected by rotation lock (although it will be affected by docks).
Jeff Brown4dfce202011-10-05 12:00:10 -07005919 preferredRotation = mUserRotation;
Jeff Browndec6cf42011-11-15 14:08:20 -08005920 } else {
5921 // No overriding preference.
5922 // We will do exactly what the application asked us to do.
5923 preferredRotation = -1;
Jeff Brown01a98dd2011-09-20 15:08:29 -07005924 }
5925
Dianne Hackborne5439f22010-10-02 16:53:50 -07005926 switch (orientation) {
5927 case ActivityInfo.SCREEN_ORIENTATION_PORTRAIT:
Jeff Browndec6cf42011-11-15 14:08:20 -08005928 // Return portrait unless overridden.
5929 if (isAnyPortrait(preferredRotation)) {
5930 return preferredRotation;
5931 }
Dianne Hackborne5439f22010-10-02 16:53:50 -07005932 return mPortraitRotation;
Dianne Hackborne5439f22010-10-02 16:53:50 -07005933
Jeff Brown01a98dd2011-09-20 15:08:29 -07005934 case ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE:
Jeff Browndec6cf42011-11-15 14:08:20 -08005935 // Return landscape unless overridden.
5936 if (isLandscapeOrSeascape(preferredRotation)) {
5937 return preferredRotation;
5938 }
Jeff Brown01a98dd2011-09-20 15:08:29 -07005939 return mLandscapeRotation;
5940
5941 case ActivityInfo.SCREEN_ORIENTATION_REVERSE_PORTRAIT:
Jeff Browndec6cf42011-11-15 14:08:20 -08005942 // Return reverse portrait unless overridden.
5943 if (isAnyPortrait(preferredRotation)) {
5944 return preferredRotation;
5945 }
Jeff Brown01a98dd2011-09-20 15:08:29 -07005946 return mUpsideDownRotation;
5947
5948 case ActivityInfo.SCREEN_ORIENTATION_REVERSE_LANDSCAPE:
Jeff Browndec6cf42011-11-15 14:08:20 -08005949 // Return seascape unless overridden.
5950 if (isLandscapeOrSeascape(preferredRotation)) {
5951 return preferredRotation;
5952 }
Jeff Brown01a98dd2011-09-20 15:08:29 -07005953 return mSeascapeRotation;
5954
5955 case ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE:
Dianne Hackbornb9ec1ac2013-04-10 17:34:25 -07005956 case ActivityInfo.SCREEN_ORIENTATION_USER_LANDSCAPE:
Jeff Brown01a98dd2011-09-20 15:08:29 -07005957 // Return either landscape rotation.
5958 if (isLandscapeOrSeascape(preferredRotation)) {
5959 return preferredRotation;
5960 }
5961 if (isLandscapeOrSeascape(lastRotation)) {
Jeff Brown4519f072011-01-23 13:16:01 -08005962 return lastRotation;
5963 }
Jeff Brown01a98dd2011-09-20 15:08:29 -07005964 return mLandscapeRotation;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005965
Jeff Brown01a98dd2011-09-20 15:08:29 -07005966 case ActivityInfo.SCREEN_ORIENTATION_SENSOR_PORTRAIT:
Dianne Hackbornb9ec1ac2013-04-10 17:34:25 -07005967 case ActivityInfo.SCREEN_ORIENTATION_USER_PORTRAIT:
Jeff Brown01a98dd2011-09-20 15:08:29 -07005968 // Return either portrait rotation.
5969 if (isAnyPortrait(preferredRotation)) {
5970 return preferredRotation;
5971 }
5972 if (isAnyPortrait(lastRotation)) {
5973 return lastRotation;
5974 }
5975 return mPortraitRotation;
5976
5977 default:
Jeff Brown4dfce202011-10-05 12:00:10 -07005978 // For USER, UNSPECIFIED, NOSENSOR, SENSOR and FULL_SENSOR,
5979 // just return the preferred orientation we already calculated.
Jeff Brown01a98dd2011-09-20 15:08:29 -07005980 if (preferredRotation >= 0) {
5981 return preferredRotation;
5982 }
Dianne Hackborndacea8c2011-04-21 17:26:39 -07005983 return Surface.ROTATION_0;
Daniel Sandlere7e5ac22011-02-22 16:10:21 -05005984 }
5985 }
Steve Howarda7bfe6a2010-09-23 16:47:49 -07005986 }
5987
Jeff Brown01a98dd2011-09-20 15:08:29 -07005988 @Override
5989 public boolean rotationHasCompatibleMetricsLw(int orientation, int rotation) {
5990 switch (orientation) {
5991 case ActivityInfo.SCREEN_ORIENTATION_PORTRAIT:
5992 case ActivityInfo.SCREEN_ORIENTATION_REVERSE_PORTRAIT:
5993 case ActivityInfo.SCREEN_ORIENTATION_SENSOR_PORTRAIT:
5994 return isAnyPortrait(rotation);
5995
5996 case ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE:
5997 case ActivityInfo.SCREEN_ORIENTATION_REVERSE_LANDSCAPE:
5998 case ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE:
5999 return isLandscapeOrSeascape(rotation);
6000
6001 default:
6002 return true;
6003 }
Steve Howarda7bfe6a2010-09-23 16:47:49 -07006004 }
6005
Jeff Brownc0347aa2011-09-23 17:26:09 -07006006 @Override
6007 public void setRotationLw(int rotation) {
6008 mOrientationListener.setCurrentRotation(rotation);
6009 }
6010
Jeff Brown01a98dd2011-09-20 15:08:29 -07006011 private boolean isLandscapeOrSeascape(int rotation) {
6012 return rotation == mLandscapeRotation || rotation == mSeascapeRotation;
Dianne Hackborne5439f22010-10-02 16:53:50 -07006013 }
6014
Jeff Brown01a98dd2011-09-20 15:08:29 -07006015 private boolean isAnyPortrait(int rotation) {
6016 return rotation == mPortraitRotation || rotation == mUpsideDownRotation;
Dianne Hackborne5439f22010-10-02 16:53:50 -07006017 }
6018
Jose Lima9546b202014-07-02 17:21:51 -07006019 @Override
Svetoslav Ganov80943d82013-01-02 10:25:37 -08006020 public int getUserRotationMode() {
6021 return Settings.System.getIntForUser(mContext.getContentResolver(),
Brett Chabot7e55c402013-05-16 19:38:08 -07006022 Settings.System.ACCELEROMETER_ROTATION, 0, UserHandle.USER_CURRENT) != 0 ?
6023 WindowManagerPolicy.USER_ROTATION_FREE :
6024 WindowManagerPolicy.USER_ROTATION_LOCKED;
Svetoslav Ganov80943d82013-01-02 10:25:37 -08006025 }
Daniel Sandlerb73617d2010-08-17 00:41:00 -04006026
6027 // User rotation: to be used when all else fails in assigning an orientation to the device
Jose Lima9546b202014-07-02 17:21:51 -07006028 @Override
Daniel Sandlerb73617d2010-08-17 00:41:00 -04006029 public void setUserRotationMode(int mode, int rot) {
6030 ContentResolver res = mContext.getContentResolver();
Daniel Sandler2ed6ad62011-02-22 14:54:17 -05006031
6032 // mUserRotationMode and mUserRotation will be assigned by the content observer
Daniel Sandlerb73617d2010-08-17 00:41:00 -04006033 if (mode == WindowManagerPolicy.USER_ROTATION_LOCKED) {
Christopher Tate5e08af02012-09-21 17:17:22 -07006034 Settings.System.putIntForUser(res,
Daniel Sandlerb73617d2010-08-17 00:41:00 -04006035 Settings.System.USER_ROTATION,
Christopher Tate5e08af02012-09-21 17:17:22 -07006036 rot,
6037 UserHandle.USER_CURRENT);
6038 Settings.System.putIntForUser(res,
Daniel Sandler2ed6ad62011-02-22 14:54:17 -05006039 Settings.System.ACCELEROMETER_ROTATION,
Christopher Tate5e08af02012-09-21 17:17:22 -07006040 0,
6041 UserHandle.USER_CURRENT);
Daniel Sandlerb73617d2010-08-17 00:41:00 -04006042 } else {
Christopher Tate5e08af02012-09-21 17:17:22 -07006043 Settings.System.putIntForUser(res,
Daniel Sandlerb73617d2010-08-17 00:41:00 -04006044 Settings.System.ACCELEROMETER_ROTATION,
Christopher Tate5e08af02012-09-21 17:17:22 -07006045 1,
6046 UserHandle.USER_CURRENT);
Daniel Sandlerb73617d2010-08-17 00:41:00 -04006047 }
6048 }
6049
Jose Lima9546b202014-07-02 17:21:51 -07006050 @Override
Jeff Brownac143512012-04-05 18:57:33 -07006051 public void setSafeMode(boolean safeMode) {
6052 mSafeMode = safeMode;
6053 performHapticFeedbackLw(null, safeMode
6054 ? HapticFeedbackConstants.SAFE_MODE_ENABLED
6055 : HapticFeedbackConstants.SAFE_MODE_DISABLED, true);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006056 }
Craig Mautnereda67292013-04-28 13:50:14 -07006057
Dianne Hackborn181ceb52009-08-27 22:16:40 -07006058 static long[] getLongIntArray(Resources r, int resid) {
6059 int[] ar = r.getIntArray(resid);
6060 if (ar == null) {
6061 return null;
6062 }
6063 long[] out = new long[ar.length];
6064 for (int i=0; i<ar.length; i++) {
6065 out[i] = ar[i];
6066 }
6067 return out;
6068 }
Craig Mautnereda67292013-04-28 13:50:14 -07006069
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006070 /** {@inheritDoc} */
Craig Mautnereda67292013-04-28 13:50:14 -07006071 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006072 public void systemReady() {
Jim Millerab954542014-10-10 18:21:49 -07006073 mKeyguardDelegate = new KeyguardServiceDelegate(mContext);
Mike Lockwooded8902d2013-11-15 11:01:47 -08006074 mKeyguardDelegate.onSystemReady();
6075
Michael Wright3818c922014-09-02 13:59:07 -07006076 readCameraLensCoverState();
Jeff Brown4f5fa282014-06-12 19:19:15 -07006077 updateUiMode();
Adrian Roos3542f7d2015-07-13 15:57:53 -07006078 boolean bindKeyguardNow;
Dianne Hackbornb1a79802009-09-29 15:18:31 -07006079 synchronized (mLock) {
6080 updateOrientationListenerLp();
Dianne Hackbornc777e072010-02-12 13:07:59 -08006081 mSystemReady = true;
6082 mHandler.post(new Runnable() {
Craig Mautnereda67292013-04-28 13:50:14 -07006083 @Override
Dianne Hackbornc777e072010-02-12 13:07:59 -08006084 public void run() {
6085 updateSettings();
6086 }
6087 });
Adrian Roos3542f7d2015-07-13 15:57:53 -07006088
6089 bindKeyguardNow = mDeferBindKeyguard;
6090 if (bindKeyguardNow) {
6091 // systemBooted ran but wasn't able to bind to the Keyguard, we'll do it now.
6092 mDeferBindKeyguard = false;
6093 }
6094 }
6095
6096 if (bindKeyguardNow) {
6097 mKeyguardDelegate.bindService(mContext);
6098 mKeyguardDelegate.onBootCompleted();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006099 }
Michael Wrighta4d22d72015-09-16 23:19:26 +01006100 mSystemGestures.systemReady();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006101 }
Dianne Hackborn661cd522011-08-22 00:26:20 -07006102
Dianne Hackbornba24e4d2011-09-01 11:17:06 -07006103 /** {@inheritDoc} */
Jose Lima9546b202014-07-02 17:21:51 -07006104 @Override
Dianne Hackbornba24e4d2011-09-01 11:17:06 -07006105 public void systemBooted() {
Adrian Roos3542f7d2015-07-13 15:57:53 -07006106 boolean bindKeyguardNow = false;
6107 synchronized (mLock) {
6108 // Time to bind Keyguard; take care to only bind it once, either here if ready or
6109 // in systemReady if not.
6110 if (mKeyguardDelegate != null) {
6111 bindKeyguardNow = true;
6112 } else {
6113 // Because mKeyguardDelegate is null, we know that the synchronized block in
6114 // systemReady didn't run yet and setting this will actually have an effect.
6115 mDeferBindKeyguard = true;
6116 }
6117 }
6118 if (bindKeyguardNow) {
Jason Monk5eeebf52014-09-26 12:36:51 -04006119 mKeyguardDelegate.bindService(mContext);
Jim Millere5f910a2013-10-16 18:15:46 -07006120 mKeyguardDelegate.onBootCompleted();
6121 }
Dianne Hackbornba24e4d2011-09-01 11:17:06 -07006122 synchronized (mLock) {
6123 mSystemBooted = true;
6124 }
Jeff Brown416c49c2015-05-26 19:50:18 -07006125 startedWakingUp();
Jeff Brown36c4db82014-09-19 12:05:31 -07006126 screenTurningOn(null);
Jorim Jaggic0496072015-08-19 15:14:52 -07006127 screenTurnedOn();
Dianne Hackbornba24e4d2011-09-01 11:17:06 -07006128 }
6129
Dianne Hackborn661cd522011-08-22 00:26:20 -07006130 ProgressDialog mBootMsgDialog = null;
6131
6132 /** {@inheritDoc} */
Jose Lima9546b202014-07-02 17:21:51 -07006133 @Override
Dianne Hackborn661cd522011-08-22 00:26:20 -07006134 public void showBootMessage(final CharSequence msg, final boolean always) {
6135 mHandler.post(new Runnable() {
6136 @Override public void run() {
6137 if (mBootMsgDialog == null) {
Craig Stout4c0cb8a2014-04-04 13:03:10 -07006138 int theme;
6139 if (mContext.getPackageManager().hasSystemFeature(
6140 PackageManager.FEATURE_WATCH)) {
6141 theme = com.android.internal.R.style.Theme_Micro_Dialog_Alert;
6142 } else if (mContext.getPackageManager().hasSystemFeature(
6143 PackageManager.FEATURE_TELEVISION)) {
6144 theme = com.android.internal.R.style.Theme_Leanback_Dialog_Alert;
6145 } else {
6146 theme = 0;
6147 }
Vinod Krishnanfa8fc412014-04-18 14:35:53 -07006148
6149 mBootMsgDialog = new ProgressDialog(mContext, theme) {
Dianne Hackborn295e3c22011-08-25 13:19:08 -07006150 // This dialog will consume all events coming in to
6151 // it, to avoid it trying to do things too early in boot.
6152 @Override public boolean dispatchKeyEvent(KeyEvent event) {
6153 return true;
6154 }
6155 @Override public boolean dispatchKeyShortcutEvent(KeyEvent event) {
6156 return true;
6157 }
6158 @Override public boolean dispatchTouchEvent(MotionEvent ev) {
6159 return true;
6160 }
6161 @Override public boolean dispatchTrackballEvent(MotionEvent ev) {
6162 return true;
6163 }
6164 @Override public boolean dispatchGenericMotionEvent(MotionEvent ev) {
6165 return true;
6166 }
6167 @Override public boolean dispatchPopulateAccessibilityEvent(
6168 AccessibilityEvent event) {
6169 return true;
6170 }
6171 };
Jeff Hao9f60c082014-10-28 18:51:07 -07006172 if (mContext.getPackageManager().isUpgrade()) {
6173 mBootMsgDialog.setTitle(R.string.android_upgrading_title);
6174 } else {
6175 mBootMsgDialog.setTitle(R.string.android_start_title);
6176 }
Dianne Hackborn661cd522011-08-22 00:26:20 -07006177 mBootMsgDialog.setProgressStyle(ProgressDialog.STYLE_SPINNER);
6178 mBootMsgDialog.setIndeterminate(true);
6179 mBootMsgDialog.getWindow().setType(
Dianne Hackborn29aae6f2011-08-18 18:30:09 -07006180 WindowManager.LayoutParams.TYPE_BOOT_PROGRESS);
Dianne Hackborn661cd522011-08-22 00:26:20 -07006181 mBootMsgDialog.getWindow().addFlags(
6182 WindowManager.LayoutParams.FLAG_DIM_BEHIND
6183 | WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN);
6184 mBootMsgDialog.getWindow().setDimAmount(1);
Dianne Hackbornd9efb952011-12-07 14:56:51 -08006185 WindowManager.LayoutParams lp = mBootMsgDialog.getWindow().getAttributes();
6186 lp.screenOrientation = ActivityInfo.SCREEN_ORIENTATION_NOSENSOR;
6187 mBootMsgDialog.getWindow().setAttributes(lp);
Dianne Hackborn661cd522011-08-22 00:26:20 -07006188 mBootMsgDialog.setCancelable(false);
6189 mBootMsgDialog.show();
6190 }
6191 mBootMsgDialog.setMessage(msg);
6192 }
6193 });
6194 }
6195
6196 /** {@inheritDoc} */
Jose Lima9546b202014-07-02 17:21:51 -07006197 @Override
Dianne Hackborn661cd522011-08-22 00:26:20 -07006198 public void hideBootMessages() {
Craig Mautnera631d492014-08-05 15:16:01 -07006199 mHandler.sendEmptyMessage(MSG_HIDE_BOOT_MESSAGE);
Dianne Hackborn661cd522011-08-22 00:26:20 -07006200 }
6201
Mike Lockwood28569302010-01-28 11:54:40 -05006202 /** {@inheritDoc} */
Jose Lima9546b202014-07-02 17:21:51 -07006203 @Override
Mike Lockwood28569302010-01-28 11:54:40 -05006204 public void userActivity() {
Dianne Hackborndf89e652011-10-06 22:35:11 -07006205 // ***************************************
6206 // NOTE NOTE NOTE NOTE NOTE NOTE NOTE NOTE
6207 // ***************************************
6208 // THIS IS CALLED FROM DEEP IN THE POWER MANAGER
6209 // WITH ITS LOCKS HELD.
6210 //
6211 // This code must be VERY careful about the locks
6212 // it acquires.
6213 // In fact, the current code acquires way too many,
6214 // and probably has lurking deadlocks.
6215
Mike Lockwood28569302010-01-28 11:54:40 -05006216 synchronized (mScreenLockTimeout) {
6217 if (mLockScreenTimerActive) {
6218 // reset the timer
6219 mHandler.removeCallbacks(mScreenLockTimeout);
6220 mHandler.postDelayed(mScreenLockTimeout, mLockScreenTimeout);
6221 }
6222 }
Daniel Sandler0601eb72011-04-13 01:01:32 -04006223 }
6224
Adam Cohenf7522022012-10-03 20:03:18 -07006225 class ScreenLockTimeout implements Runnable {
6226 Bundle options;
6227
6228 @Override
Mike Lockwood28569302010-01-28 11:54:40 -05006229 public void run() {
6230 synchronized (this) {
6231 if (localLOGV) Log.v(TAG, "mScreenLockTimeout activating keyguard");
Jim Miller5ecd8112013-01-09 18:50:26 -08006232 if (mKeyguardDelegate != null) {
6233 mKeyguardDelegate.doKeyguardTimeout(options);
Mike Lockwood3a74bd32011-08-12 13:55:22 -07006234 }
Mike Lockwood28569302010-01-28 11:54:40 -05006235 mLockScreenTimerActive = false;
Adam Cohenf7522022012-10-03 20:03:18 -07006236 options = null;
Mike Lockwood28569302010-01-28 11:54:40 -05006237 }
6238 }
Mike Lockwood28569302010-01-28 11:54:40 -05006239
Adam Cohenf7522022012-10-03 20:03:18 -07006240 public void setLockOptions(Bundle options) {
6241 this.options = options;
6242 }
6243 }
6244
6245 ScreenLockTimeout mScreenLockTimeout = new ScreenLockTimeout();
6246
Jose Lima9546b202014-07-02 17:21:51 -07006247 @Override
Adam Cohenf7522022012-10-03 20:03:18 -07006248 public void lockNow(Bundle options) {
Jim Miller93c518e2012-01-17 15:55:31 -08006249 mContext.enforceCallingOrSelfPermission(android.Manifest.permission.DEVICE_POWER, null);
6250 mHandler.removeCallbacks(mScreenLockTimeout);
Adam Cohenf7522022012-10-03 20:03:18 -07006251 if (options != null) {
6252 // In case multiple calls are made to lockNow, we don't wipe out the options
6253 // until the runnable actually executes.
6254 mScreenLockTimeout.setLockOptions(options);
6255 }
Jim Miller93c518e2012-01-17 15:55:31 -08006256 mHandler.post(mScreenLockTimeout);
6257 }
6258
Mike Lockwood28569302010-01-28 11:54:40 -05006259 private void updateLockScreenTimeout() {
6260 synchronized (mScreenLockTimeout) {
Jeff Brown3ee549c2014-09-22 20:14:39 -07006261 boolean enable = (mAllowLockscreenWhenOn && mAwake &&
Jim Miller5ecd8112013-01-09 18:50:26 -08006262 mKeyguardDelegate != null && mKeyguardDelegate.isSecure());
Mike Lockwood28569302010-01-28 11:54:40 -05006263 if (mLockScreenTimerActive != enable) {
6264 if (enable) {
6265 if (localLOGV) Log.v(TAG, "setting lockscreen timer");
6266 mHandler.postDelayed(mScreenLockTimeout, mLockScreenTimeout);
6267 } else {
6268 if (localLOGV) Log.v(TAG, "clearing lockscreen timer");
6269 mHandler.removeCallbacks(mScreenLockTimeout);
6270 }
6271 mLockScreenTimerActive = enable;
6272 }
6273 }
6274 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006275
Jeff Brown061ea992015-04-17 19:55:47 -07006276 private void updateDreamingSleepToken(boolean acquire) {
6277 if (acquire) {
6278 if (mDreamingSleepToken == null) {
6279 mDreamingSleepToken = mActivityManagerInternal.acquireSleepToken("Dream");
6280 }
6281 } else {
6282 if (mDreamingSleepToken != null) {
6283 mDreamingSleepToken.release();
Jeff Brown48d1b142015-06-10 16:36:03 -07006284 mDreamingSleepToken = null;
6285 }
6286 }
6287 }
6288
6289 private void updateScreenOffSleepToken(boolean acquire) {
6290 if (acquire) {
6291 if (mScreenOffSleepToken == null) {
6292 mScreenOffSleepToken = mActivityManagerInternal.acquireSleepToken("ScreenOff");
6293 }
6294 } else {
6295 if (mScreenOffSleepToken != null) {
6296 mScreenOffSleepToken.release();
6297 mScreenOffSleepToken = null;
Jeff Brown061ea992015-04-17 19:55:47 -07006298 }
6299 }
6300 }
6301
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006302 /** {@inheritDoc} */
Craig Mautnereda67292013-04-28 13:50:14 -07006303 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006304 public void enableScreenAfterBoot() {
6305 readLidState();
Jeff Brownc458ce92012-04-30 14:58:40 -07006306 applyLidSwitchState();
Jeff Brown01a98dd2011-09-20 15:08:29 -07006307 updateRotation(true);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006308 }
Dianne Hackbornf54c8f92009-09-19 14:03:57 -07006309
Jeff Brownc458ce92012-04-30 14:58:40 -07006310 private void applyLidSwitchState() {
Jeff Brownc458ce92012-04-30 14:58:40 -07006311 if (mLidState == LID_CLOSED && mLidControlsSleep) {
Jeff Brown6d8fd272014-05-20 21:24:38 -07006312 mPowerManager.goToSleep(SystemClock.uptimeMillis(),
Jeff Brownc12035c2014-08-13 18:52:25 -07006313 PowerManager.GO_TO_SLEEP_REASON_LID_SWITCH,
Jeff Brown6d8fd272014-05-20 21:24:38 -07006314 PowerManager.GO_TO_SLEEP_FLAG_NO_DOZE);
Edward Savage-Jones7def60d2015-11-13 13:27:03 +01006315 } else if (mLidState == LID_CLOSED && mLidControlsScreenLock) {
6316 mWindowManagerFuncs.lockDeviceNow();
Jeff Brownc458ce92012-04-30 14:58:40 -07006317 }
Jeff Browna20dda42014-05-27 20:57:24 -07006318
6319 synchronized (mLock) {
6320 updateWakeGestureListenerLp();
6321 }
Jeff Brown01a98dd2011-09-20 15:08:29 -07006322 }
6323
Jeff Brown4f5fa282014-06-12 19:19:15 -07006324 void updateUiMode() {
6325 if (mUiModeManager == null) {
6326 mUiModeManager = IUiModeManager.Stub.asInterface(
6327 ServiceManager.getService(Context.UI_MODE_SERVICE));
6328 }
6329 try {
6330 mUiMode = mUiModeManager.getCurrentModeType();
6331 } catch (RemoteException e) {
6332 }
6333 }
6334
Jeff Brown01a98dd2011-09-20 15:08:29 -07006335 void updateRotation(boolean alwaysSendConfiguration) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006336 try {
6337 //set orientation on WindowManager
Dianne Hackbornf87d1962012-04-04 12:48:24 -07006338 mWindowManager.updateRotation(alwaysSendConfiguration, false);
6339 } catch (RemoteException e) {
6340 // Ignore
6341 }
6342 }
6343
6344 void updateRotation(boolean alwaysSendConfiguration, boolean forceRelayout) {
6345 try {
6346 //set orientation on WindowManager
6347 mWindowManager.updateRotation(alwaysSendConfiguration, forceRelayout);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006348 } catch (RemoteException e) {
6349 // Ignore
6350 }
6351 }
6352
Daniel Sandler6396c722013-04-16 20:19:09 -04006353 /**
6354 * Return an Intent to launch the currently active dock app as home. Returns
6355 * null if the standard home should be launched, which is the case if any of the following is
6356 * true:
6357 * <ul>
6358 * <li>The device is not in either car mode or desk mode
6359 * <li>The device is in car mode but ENABLE_CAR_DOCK_HOME_CAPTURE is false
6360 * <li>The device is in desk mode but ENABLE_DESK_DOCK_HOME_CAPTURE is false
6361 * <li>The device is in car mode but there's no CAR_DOCK app with METADATA_DOCK_HOME
6362 * <li>The device is in desk mode but there's no DESK_DOCK app with METADATA_DOCK_HOME
6363 * </ul>
Craig Mautnereda67292013-04-28 13:50:14 -07006364 * @return A dock intent.
Daniel Sandler6396c722013-04-16 20:19:09 -04006365 */
6366 Intent createHomeDockIntent() {
6367 Intent intent = null;
6368
6369 // What home does is based on the mode, not the dock state. That
6370 // is, when in car mode you should be taken to car home regardless
6371 // of whether we are actually in a car dock.
6372 if (mUiMode == Configuration.UI_MODE_TYPE_CAR) {
6373 if (ENABLE_CAR_DOCK_HOME_CAPTURE) {
6374 intent = mCarDockIntent;
6375 }
6376 } else if (mUiMode == Configuration.UI_MODE_TYPE_DESK) {
6377 if (ENABLE_DESK_DOCK_HOME_CAPTURE) {
6378 intent = mDeskDockIntent;
6379 }
Jeff Brown4f5fa282014-06-12 19:19:15 -07006380 } else if (mUiMode == Configuration.UI_MODE_TYPE_WATCH
6381 && (mDockMode == Intent.EXTRA_DOCK_STATE_DESK
6382 || mDockMode == Intent.EXTRA_DOCK_STATE_HE_DESK
6383 || mDockMode == Intent.EXTRA_DOCK_STATE_LE_DESK)) {
6384 // Always launch dock home from home when watch is docked, if it exists.
6385 intent = mDeskDockIntent;
Daniel Sandler6396c722013-04-16 20:19:09 -04006386 }
6387
6388 if (intent == null) {
6389 return null;
6390 }
6391
6392 ActivityInfo ai = null;
6393 ResolveInfo info = mContext.getPackageManager().resolveActivityAsUser(
6394 intent,
John Spurlockf56bef12013-07-09 09:51:46 -04006395 PackageManager.MATCH_DEFAULT_ONLY | PackageManager.GET_META_DATA,
Craig Mautnerd625ab22013-09-06 13:40:31 -07006396 mCurrentUserId);
Daniel Sandler6396c722013-04-16 20:19:09 -04006397 if (info != null) {
6398 ai = info.activityInfo;
6399 }
6400 if (ai != null
6401 && ai.metaData != null
6402 && ai.metaData.getBoolean(Intent.METADATA_DOCK_HOME)) {
6403 intent = new Intent(intent);
6404 intent.setClassName(ai.packageName, ai.name);
6405 return intent;
6406 }
6407
6408 return null;
6409 }
6410
Filip Gruszczynskia483a1d2015-03-17 19:06:58 +00006411 void startDockOrHome(boolean fromHomeKey, boolean awakenFromDreams) {
6412 if (awakenFromDreams) {
6413 awakenDreams();
6414 }
Daniel Sandler6396c722013-04-16 20:19:09 -04006415
6416 Intent dock = createHomeDockIntent();
6417 if (dock != null) {
6418 try {
Bryce Lee01b0c5f2015-02-05 18:24:04 -08006419 if (fromHomeKey) {
6420 dock.putExtra(WindowManagerPolicy.EXTRA_FROM_HOME_KEY, fromHomeKey);
6421 }
Bart Sears8b1c27c2015-03-18 23:51:02 +00006422 startActivityAsUser(dock, UserHandle.CURRENT);
Daniel Sandler6396c722013-04-16 20:19:09 -04006423 return;
6424 } catch (ActivityNotFoundException e) {
6425 }
6426 }
6427
Bryce Lee01b0c5f2015-02-05 18:24:04 -08006428 Intent intent;
6429
6430 if (fromHomeKey) {
6431 intent = new Intent(mHomeIntent);
6432 intent.putExtra(WindowManagerPolicy.EXTRA_FROM_HOME_KEY, fromHomeKey);
6433 } else {
6434 intent = mHomeIntent;
6435 }
6436
Bryce Lee9fc0b6f2015-03-19 21:37:45 +00006437 startActivityAsUser(intent, UserHandle.CURRENT);
Dianne Hackborn39c2d712009-09-22 11:41:31 -07006438 }
Craig Mautnereda67292013-04-28 13:50:14 -07006439
Dianne Hackborn39c2d712009-09-22 11:41:31 -07006440 /**
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006441 * goes to the home screen
6442 * @return whether it did anything
6443 */
6444 boolean goHome() {
Bart Sears8b1c27c2015-03-18 23:51:02 +00006445 if (!isUserSetupComplete()) {
6446 Slog.i(TAG, "Not going home because user setup is in progress.");
6447 return false;
6448 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006449 if (false) {
6450 // This code always brings home to the front.
Dianne Hackborn256dd3b2009-05-19 18:51:21 -07006451 try {
6452 ActivityManagerNative.getDefault().stopAppSwitches();
6453 } catch (RemoteException e) {
6454 }
Dianne Hackborn94a679d2009-07-28 17:51:07 -07006455 sendCloseSystemWindows();
Filip Gruszczynskia483a1d2015-03-17 19:06:58 +00006456 startDockOrHome(false /*fromHomeKey*/, true /* awakenFromDreams */);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006457 } else {
6458 // This code brings home to the front or, if it is already
6459 // at the front, puts the device to sleep.
6460 try {
Wink Savilled2e6a332010-02-12 12:12:06 -08006461 if (SystemProperties.getInt("persist.sys.uts-test-mode", 0) == 1) {
6462 /// Roll back EndcallBehavior as the cupcake design to pass P1 lab entry.
6463 Log.d(TAG, "UTS-TEST-MODE");
6464 } else {
6465 ActivityManagerNative.getDefault().stopAppSwitches();
6466 sendCloseSystemWindows();
Daniel Sandler6396c722013-04-16 20:19:09 -04006467 Intent dock = createHomeDockIntent();
6468 if (dock != null) {
6469 int result = ActivityManagerNative.getDefault()
6470 .startActivityAsUser(null, null, dock,
6471 dock.resolveTypeIfNeeded(mContext.getContentResolver()),
6472 null, null, 0,
6473 ActivityManager.START_FLAG_ONLY_IF_NEEDED,
Jeff Hao1b012d32014-08-20 10:35:34 -07006474 null, null, UserHandle.USER_CURRENT);
Daniel Sandler6396c722013-04-16 20:19:09 -04006475 if (result == ActivityManager.START_RETURN_INTENT_TO_CALLER) {
6476 return false;
6477 }
6478 }
Dianne Hackborn39c2d712009-09-22 11:41:31 -07006479 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006480 int result = ActivityManagerNative.getDefault()
Dianne Hackbornf265ea92013-01-31 15:00:51 -08006481 .startActivityAsUser(null, null, mHomeIntent,
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006482 mHomeIntent.resolveTypeIfNeeded(mContext.getContentResolver()),
Dianne Hackborna4972e92012-03-14 10:38:05 -07006483 null, null, 0,
6484 ActivityManager.START_FLAG_ONLY_IF_NEEDED,
Jeff Hao1b012d32014-08-20 10:35:34 -07006485 null, null, UserHandle.USER_CURRENT);
Dianne Hackborna4972e92012-03-14 10:38:05 -07006486 if (result == ActivityManager.START_RETURN_INTENT_TO_CALLER) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006487 return false;
6488 }
6489 } catch (RemoteException ex) {
6490 // bummer, the activity manager, which is in this process, is dead
6491 }
6492 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006493 return true;
6494 }
Craig Mautnereda67292013-04-28 13:50:14 -07006495
6496 @Override
The Android Open Source Project0727d222009-03-11 12:11:58 -07006497 public void setCurrentOrientationLw(int newOrientation) {
6498 synchronized (mLock) {
6499 if (newOrientation != mCurrentAppOrientation) {
6500 mCurrentAppOrientation = newOrientation;
6501 updateOrientationListenerLp();
6502 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006503 }
6504 }
Amith Yamasanic33cb712010-02-10 15:21:49 -08006505
Svetoslav Ganov7befb7d2012-09-27 16:49:23 -07006506 private void performAuditoryFeedbackForAccessibilityIfNeed() {
6507 if (!isGlobalAccessibilityGestureEnabled()) {
6508 return;
6509 }
6510 AudioManager audioManager = (AudioManager) mContext.getSystemService(
6511 Context.AUDIO_SERVICE);
6512 if (audioManager.isSilentMode()) {
6513 return;
6514 }
6515 Ringtone ringTone = RingtoneManager.getRingtone(mContext,
6516 Settings.System.DEFAULT_NOTIFICATION_URI);
6517 ringTone.setStreamType(AudioManager.STREAM_MUSIC);
6518 ringTone.play();
6519 }
Craig Mautnereda67292013-04-28 13:50:14 -07006520
Bryce Lee584a4452014-10-21 15:55:55 -07006521 private boolean isTheaterModeEnabled() {
6522 return Settings.Global.getInt(mContext.getContentResolver(),
6523 Settings.Global.THEATER_MODE_ON, 0) == 1;
6524 }
6525
Svetoslav Ganov7befb7d2012-09-27 16:49:23 -07006526 private boolean isGlobalAccessibilityGestureEnabled() {
6527 return Settings.Global.getInt(mContext.getContentResolver(),
6528 Settings.Global.ENABLE_ACCESSIBILITY_GLOBAL_GESTURE_ENABLED, 0) == 1;
6529 }
6530
Craig Mautnereda67292013-04-28 13:50:14 -07006531 @Override
The Android Open Source Project0727d222009-03-11 12:11:58 -07006532 public boolean performHapticFeedbackLw(WindowState win, int effectId, boolean always) {
Svetoslav Ganov96179212012-10-10 14:17:45 -07006533 if (!mVibrator.hasVibrator()) {
6534 return false;
6535 }
Christopher Tate5e08af02012-09-21 17:17:22 -07006536 final boolean hapticsDisabled = Settings.System.getIntForUser(mContext.getContentResolver(),
6537 Settings.System.HAPTIC_FEEDBACK_ENABLED, 0, UserHandle.USER_CURRENT) == 0;
Jeff Brown82379ba2014-07-25 19:03:28 -07006538 if (hapticsDisabled && !always) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006539 return false;
6540 }
Amith Yamasanic33cb712010-02-10 15:21:49 -08006541 long[] pattern = null;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006542 switch (effectId) {
6543 case HapticFeedbackConstants.LONG_PRESS:
Amith Yamasanic33cb712010-02-10 15:21:49 -08006544 pattern = mLongPressVibePattern;
6545 break;
Dianne Hackbornb1a79802009-09-29 15:18:31 -07006546 case HapticFeedbackConstants.VIRTUAL_KEY:
Amith Yamasanic33cb712010-02-10 15:21:49 -08006547 pattern = mVirtualKeyVibePattern;
6548 break;
6549 case HapticFeedbackConstants.KEYBOARD_TAP:
6550 pattern = mKeyboardTapVibePattern;
6551 break;
Fabrice Di Meglioeeff63a2013-08-05 12:07:24 -07006552 case HapticFeedbackConstants.CLOCK_TICK:
6553 pattern = mClockTickVibePattern;
6554 break;
Fabrice Di Megliobd9152f2013-10-01 11:21:31 -07006555 case HapticFeedbackConstants.CALENDAR_DATE:
6556 pattern = mCalendarDateVibePattern;
6557 break;
Dianne Hackbornb1a79802009-09-29 15:18:31 -07006558 case HapticFeedbackConstants.SAFE_MODE_DISABLED:
Amith Yamasanic33cb712010-02-10 15:21:49 -08006559 pattern = mSafeModeDisabledVibePattern;
6560 break;
Dianne Hackbornb1a79802009-09-29 15:18:31 -07006561 case HapticFeedbackConstants.SAFE_MODE_ENABLED:
Amith Yamasanic33cb712010-02-10 15:21:49 -08006562 pattern = mSafeModeEnabledVibePattern;
6563 break;
Mady Mellore8608912015-06-05 09:02:55 -07006564 case HapticFeedbackConstants.CONTEXT_CLICK:
6565 pattern = mContextClickVibePattern;
Mady Mellore82067b2015-04-30 09:58:35 -07006566 break;
Amith Yamasanic33cb712010-02-10 15:21:49 -08006567 default:
6568 return false;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006569 }
Dianne Hackbornf265ea92013-01-31 15:00:51 -08006570 int owningUid;
6571 String owningPackage;
6572 if (win != null) {
6573 owningUid = win.getOwningUid();
6574 owningPackage = win.getOwningPackage();
6575 } else {
6576 owningUid = android.os.Process.myUid();
Dianne Hackborn95d78532013-09-11 09:51:14 -07006577 owningPackage = mContext.getOpPackageName();
Dianne Hackbornf265ea92013-01-31 15:00:51 -08006578 }
Amith Yamasanic33cb712010-02-10 15:21:49 -08006579 if (pattern.length == 1) {
6580 // One-shot vibration
John Spurlock7b414672014-07-18 13:02:39 -04006581 mVibrator.vibrate(owningUid, owningPackage, pattern[0], VIBRATION_ATTRIBUTES);
Amith Yamasanic33cb712010-02-10 15:21:49 -08006582 } else {
6583 // Pattern vibration
John Spurlock7b414672014-07-18 13:02:39 -04006584 mVibrator.vibrate(owningUid, owningPackage, pattern, -1, VIBRATION_ATTRIBUTES);
Amith Yamasanic33cb712010-02-10 15:21:49 -08006585 }
6586 return true;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006587 }
Jeff Brownc38c9be2012-10-04 13:16:19 -07006588
6589 @Override
6590 public void keepScreenOnStartedLw() {
Daniel Sandler0601eb72011-04-13 01:01:32 -04006591 }
6592
Jeff Brownc38c9be2012-10-04 13:16:19 -07006593 @Override
6594 public void keepScreenOnStoppedLw() {
Jim Millerab954542014-10-10 18:21:49 -07006595 if (isKeyguardShowingAndNotOccluded()) {
Jim Miller25190572013-02-28 17:36:24 -08006596 mPowerManager.userActivity(SystemClock.uptimeMillis(), false);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006597 }
6598 }
Mike Lockwoodfcb39242009-10-21 23:01:07 -04006599
Dianne Hackborndf89e652011-10-06 22:35:11 -07006600 private int updateSystemUiVisibilityLw() {
Joe Onorato664644d2011-01-23 17:53:23 -08006601 // If there is no window focused, there will be nobody to handle the events
6602 // anyway, so just hang on in whatever state we're in until things settle down.
Adrian Roos53f28ec2014-10-29 17:26:12 +01006603 final WindowState win = mFocusedWindow != null ? mFocusedWindow
6604 : mTopFullscreenOpaqueWindowState;
John Spurlock79da8332013-09-20 12:04:47 -04006605 if (win == null) {
Dianne Hackborndf89e652011-10-06 22:35:11 -07006606 return 0;
6607 }
Jorim Jaggi380ecb82014-03-14 17:25:20 +01006608 if ((win.getAttrs().privateFlags & PRIVATE_FLAG_KEYGUARD) != 0 && mHideLockScreen == true) {
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07006609 // We are updating at a point where the keyguard has gotten
6610 // focus, but we were last in a state where the top window is
6611 // hiding it. This is probably because the keyguard as been
6612 // shown while the top window was displayed, so we want to ignore
6613 // it here because this is just a very transient change and it
6614 // will quickly lose focus once it correctly gets hidden.
6615 return 0;
6616 }
John Spurlock32beb2c2013-03-11 10:16:47 -04006617
John Spurlock1db8b682014-02-18 11:18:59 -05006618 int tmpVisibility = PolicyControl.getSystemUiVisibility(win, null)
Dianne Hackborne26ab702011-10-16 13:21:33 -07006619 & ~mResettingSystemUiFlags
6620 & ~mForceClearedSystemUiFlags;
John Spurlock79da8332013-09-20 12:04:47 -04006621 if (mForcingShowNavBar && win.getSurfaceLayer() < mForcingShowNavBarLayer) {
John Spurlockc6d1c602014-01-17 15:22:06 -05006622 tmpVisibility &= ~PolicyControl.adjustClearableFlags(win, View.SYSTEM_UI_CLEARABLE_FLAGS);
Dianne Hackborn891d3fb2013-01-09 18:31:37 -08006623 }
Adrian Rooscd3884d2015-02-18 17:25:23 +01006624 tmpVisibility = updateLightStatusBarLw(tmpVisibility);
John Spurlock79da8332013-09-20 12:04:47 -04006625 final int visibility = updateSystemBarsLw(win, mLastSystemUiFlags, tmpVisibility);
John Spurlockad3e6cb2013-04-30 08:47:43 -04006626 final int diff = visibility ^ mLastSystemUiFlags;
John Spurlock79da8332013-09-20 12:04:47 -04006627 final boolean needsMenu = win.getNeedsMenuLw(mTopFullscreenOpaqueWindowState);
Dianne Hackborne0f085d2011-11-30 18:41:15 -08006628 if (diff == 0 && mLastFocusNeedsMenu == needsMenu
John Spurlock79da8332013-09-20 12:04:47 -04006629 && mFocusedApp == win.getAppToken()) {
Dianne Hackborndf89e652011-10-06 22:35:11 -07006630 return 0;
6631 }
Dianne Hackborne26ab702011-10-16 13:21:33 -07006632 mLastSystemUiFlags = visibility;
Dianne Hackborn4eff8d32011-11-10 19:38:40 -08006633 mLastFocusNeedsMenu = needsMenu;
John Spurlock79da8332013-09-20 12:04:47 -04006634 mFocusedApp = win.getAppToken();
Dianne Hackborndf89e652011-10-06 22:35:11 -07006635 mHandler.post(new Runnable() {
Craig Mautnereda67292013-04-28 13:50:14 -07006636 @Override
Dianne Hackborndf89e652011-10-06 22:35:11 -07006637 public void run() {
Dianne Hackborn42e620c2012-06-24 13:20:51 -07006638 try {
6639 IStatusBarService statusbar = getStatusBarService();
6640 if (statusbar != null) {
Adrian Roos53f28ec2014-10-29 17:26:12 +01006641 statusbar.setSystemUiVisibility(visibility, 0xffffffff, win.toString());
Dianne Hackborn42e620c2012-06-24 13:20:51 -07006642 statusbar.topAppWindowChanged(needsMenu);
Joe Onorato664644d2011-01-23 17:53:23 -08006643 }
Dianne Hackborn42e620c2012-06-24 13:20:51 -07006644 } catch (RemoteException e) {
6645 // re-acquire status bar service next time it is needed.
6646 mStatusBarService = null;
Joe Onorato664644d2011-01-23 17:53:23 -08006647 }
Dianne Hackborndf89e652011-10-06 22:35:11 -07006648 }
6649 });
6650 return diff;
Joe Onorato664644d2011-01-23 17:53:23 -08006651 }
6652
Adrian Rooscd3884d2015-02-18 17:25:23 +01006653 private int updateLightStatusBarLw(int vis) {
6654 WindowState statusColorWin = isStatusBarKeyguard() && !mHideLockScreen
6655 ? mStatusBar
6656 : mTopFullscreenOpaqueOrDimmingWindowState;
6657
6658 if (statusColorWin != null) {
6659 if (statusColorWin == mTopFullscreenOpaqueWindowState) {
6660 // If the top fullscreen-or-dimming window is also the top fullscreen, respect
6661 // its light flag.
6662 vis &= ~View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR;
6663 vis |= PolicyControl.getSystemUiVisibility(statusColorWin, null)
6664 & View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR;
6665 } else if (statusColorWin != null && statusColorWin.isDimming()) {
6666 // Otherwise if it's dimming, clear the light flag.
6667 vis &= ~View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR;
6668 }
6669 }
6670 return vis;
6671 }
6672
John Spurlock79da8332013-09-20 12:04:47 -04006673 private int updateSystemBarsLw(WindowState win, int oldVis, int vis) {
John Spurlockbd957402013-10-03 11:38:39 -04006674 // apply translucent bar vis flags
Jorim Jaggi380ecb82014-03-14 17:25:20 +01006675 WindowState transWin = isStatusBarKeyguard() && !mHideLockScreen
6676 ? mStatusBar
John Spurlockbd957402013-10-03 11:38:39 -04006677 : mTopFullscreenOpaqueWindowState;
6678 vis = mStatusBarController.applyTranslucentFlagLw(transWin, vis, oldVis);
6679 vis = mNavigationBarController.applyTranslucentFlagLw(transWin, vis, oldVis);
6680
John Spurlock27735a42013-08-14 17:57:38 -04006681 // prevent status bar interaction from clearing certain flags
Selim Cinekf83e8242015-05-19 18:08:14 -07006682 int type = win.getAttrs().type;
6683 boolean statusBarHasFocus = type == TYPE_STATUS_BAR;
John Spurlock08ffcf52014-07-11 10:13:46 -04006684 if (statusBarHasFocus && !isStatusBarKeyguard()) {
John Spurlockad3e6cb2013-04-30 08:47:43 -04006685 int flags = View.SYSTEM_UI_FLAG_FULLSCREEN
6686 | View.SYSTEM_UI_FLAG_HIDE_NAVIGATION
John Spurlockcfc359a2013-09-05 10:42:03 -04006687 | View.SYSTEM_UI_FLAG_IMMERSIVE
Jorim Jaggi73fef8d2015-02-16 17:32:28 +01006688 | View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY
6689 | View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR;
John Spurlock08ffcf52014-07-11 10:13:46 -04006690 if (mHideLockScreen) {
Jorim Jaggi5cf17872014-03-26 18:31:48 +01006691 flags |= View.STATUS_BAR_TRANSLUCENT | View.NAVIGATION_BAR_TRANSLUCENT;
6692 }
John Spurlockbd957402013-10-03 11:38:39 -04006693 vis = (vis & ~flags) | (oldVis & flags);
John Spurlockad3e6cb2013-04-30 08:47:43 -04006694 }
John Spurlockad3e6cb2013-04-30 08:47:43 -04006695
Adrian Roos4fb3ee32014-08-22 19:29:09 +02006696 if (!areTranslucentBarsAllowed() && transWin != mStatusBar) {
Adrian Roosea562512014-05-05 13:33:03 +02006697 vis &= ~(View.NAVIGATION_BAR_TRANSLUCENT | View.STATUS_BAR_TRANSLUCENT
6698 | View.SYSTEM_UI_TRANSPARENT);
Alan Viverette5a0f4ec2013-10-07 15:10:29 -07006699 }
6700
John Spurlock27735a42013-08-14 17:57:38 -04006701 // update status bar
John Spurlockf1a36642013-10-12 17:50:42 -04006702 boolean immersiveSticky =
6703 (vis & View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY) != 0;
John Spurlock27735a42013-08-14 17:57:38 -04006704 boolean hideStatusBarWM =
John Spurlockbd957402013-10-03 11:38:39 -04006705 mTopFullscreenOpaqueWindowState != null &&
John Spurlockc6d1c602014-01-17 15:22:06 -05006706 (PolicyControl.getWindowFlags(mTopFullscreenOpaqueWindowState, null)
John Spurlock27735a42013-08-14 17:57:38 -04006707 & WindowManager.LayoutParams.FLAG_FULLSCREEN) != 0;
6708 boolean hideStatusBarSysui =
6709 (vis & View.SYSTEM_UI_FLAG_FULLSCREEN) != 0;
John Spurlockf1a36642013-10-12 17:50:42 -04006710 boolean hideNavBarSysui =
6711 (vis & View.SYSTEM_UI_FLAG_HIDE_NAVIGATION) != 0;
John Spurlockad3e6cb2013-04-30 08:47:43 -04006712
John Spurlock27735a42013-08-14 17:57:38 -04006713 boolean transientStatusBarAllowed =
6714 mStatusBar != null && (
6715 hideStatusBarWM
John Spurlockf1a36642013-10-12 17:50:42 -04006716 || (hideStatusBarSysui && immersiveSticky)
John Spurlock27735a42013-08-14 17:57:38 -04006717 || statusBarHasFocus);
6718
John Spurlockf1a36642013-10-12 17:50:42 -04006719 boolean transientNavBarAllowed =
6720 mNavigationBar != null &&
6721 hideNavBarSysui && immersiveSticky;
6722
Adrian Roosddc8b272015-05-21 16:28:27 -07006723 final long now = SystemClock.uptimeMillis();
6724 final boolean pendingPanic = mPendingPanicGestureUptime != 0
6725 && now - mPendingPanicGestureUptime <= PANIC_GESTURE_EXPIRATION;
6726 if (pendingPanic && hideNavBarSysui && !isStatusBarKeyguard() && mKeyguardDrawComplete) {
6727 // The user performed the panic gesture recently, we're about to hide the bars,
6728 // we're no longer on the Keyguard and the screen is ready. We can now request the bars.
6729 mPendingPanicGestureUptime = 0;
6730 mStatusBarController.showTransient();
6731 mNavigationBarController.showTransient();
6732 }
6733
John Spurlockf25706f2013-11-07 18:02:43 -05006734 boolean denyTransientStatus = mStatusBarController.isTransientShowRequested()
John Spurlockf1a36642013-10-12 17:50:42 -04006735 && !transientStatusBarAllowed && hideStatusBarSysui;
John Spurlockf25706f2013-11-07 18:02:43 -05006736 boolean denyTransientNav = mNavigationBarController.isTransientShowRequested()
John Spurlockf1a36642013-10-12 17:50:42 -04006737 && !transientNavBarAllowed;
6738 if (denyTransientStatus || denyTransientNav) {
John Spurlock27735a42013-08-14 17:57:38 -04006739 // clear the clearable flags instead
John Spurlockf1a36642013-10-12 17:50:42 -04006740 clearClearableFlagsLw();
tiger_huangc58d7562014-10-23 20:24:19 +08006741 vis &= ~View.SYSTEM_UI_CLEARABLE_FLAGS;
John Spurlockad3e6cb2013-04-30 08:47:43 -04006742 }
John Spurlock27735a42013-08-14 17:57:38 -04006743
Selim Cinekf98702e2015-05-20 22:48:40 -07006744 final boolean immersive = (vis & View.SYSTEM_UI_FLAG_IMMERSIVE) != 0;
6745 immersiveSticky = (vis & View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY) != 0;
6746 final boolean navAllowedHidden = immersive || immersiveSticky;
6747
Selim Cinekd6623612015-05-22 18:56:22 -07006748 if (hideNavBarSysui && !navAllowedHidden && windowTypeToLayerLw(win.getBaseType())
6749 > windowTypeToLayerLw(TYPE_INPUT_CONSUMER)) {
Selim Cinekf98702e2015-05-20 22:48:40 -07006750 // We can't hide the navbar from this window otherwise the input consumer would not get
6751 // the input events.
6752 vis = (vis & ~View.SYSTEM_UI_FLAG_HIDE_NAVIGATION);
6753 }
6754
John Spurlock27735a42013-08-14 17:57:38 -04006755 vis = mStatusBarController.updateVisibilityLw(transientStatusBarAllowed, oldVis, vis);
6756
6757 // update navigation bar
John Spurlockf1a36642013-10-12 17:50:42 -04006758 boolean oldImmersiveMode = isImmersiveMode(oldVis);
6759 boolean newImmersiveMode = isImmersiveMode(vis);
6760 if (win != null && oldImmersiveMode != newImmersiveMode) {
John Spurlock79da8332013-09-20 12:04:47 -04006761 final String pkg = win.getOwningPackage();
Maurice Lam99c6e072014-04-28 18:24:28 -07006762 mImmersiveModeConfirmation.immersiveModeChanged(pkg, newImmersiveMode,
6763 isUserSetupComplete());
John Spurlock34e13d92013-08-10 06:52:28 -04006764 }
John Spurlock27735a42013-08-14 17:57:38 -04006765
John Spurlockf1a36642013-10-12 17:50:42 -04006766 vis = mNavigationBarController.updateVisibilityLw(transientNavBarAllowed, oldVis, vis);
6767
John Spurlocke1f366f2013-08-05 12:22:40 -04006768 return vis;
John Spurlockad3e6cb2013-04-30 08:47:43 -04006769 }
6770
John Spurlockf1a36642013-10-12 17:50:42 -04006771 private void clearClearableFlagsLw() {
6772 int newVal = mResettingSystemUiFlags | View.SYSTEM_UI_CLEARABLE_FLAGS;
6773 if (newVal != mResettingSystemUiFlags) {
6774 mResettingSystemUiFlags = newVal;
6775 mWindowManagerFuncs.reevaluateStatusBarVisibility();
6776 }
6777 }
6778
6779 private boolean isImmersiveMode(int vis) {
6780 final int flags = View.SYSTEM_UI_FLAG_IMMERSIVE | View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY;
John Spurlock34e13d92013-08-10 06:52:28 -04006781 return mNavigationBar != null
6782 && (vis & View.SYSTEM_UI_FLAG_HIDE_NAVIGATION) != 0
Daniel Sandler900ece52013-10-18 15:53:27 -04006783 && (vis & flags) != 0
6784 && canHideNavigationBar();
John Spurlock34e13d92013-08-10 06:52:28 -04006785 }
6786
Alan Viverette5a0f4ec2013-10-07 15:10:29 -07006787 /**
Daniel Sandlerdd73ee42013-10-11 22:19:59 -04006788 * @return whether the navigation or status bar can be made translucent
6789 *
6790 * This should return true unless touch exploration is not enabled or
6791 * R.boolean.config_enableTranslucentDecor is false.
Alan Viverette5a0f4ec2013-10-07 15:10:29 -07006792 */
Daniel Sandlerdd73ee42013-10-11 22:19:59 -04006793 private boolean areTranslucentBarsAllowed() {
Svetoslav8e3feb12014-02-24 13:46:47 -08006794 return mTranslucentDecorEnabled
6795 && !mAccessibilityManager.isTouchExplorationEnabled();
Alan Viverette5a0f4ec2013-10-07 15:10:29 -07006796 }
6797
Daniel Sandler0c4ccff2011-10-19 16:39:14 -04006798 // Use this instead of checking config_showNavigationBar so that it can be consistently
6799 // overridden by qemu.hw.mainkeys in the emulator.
Craig Mautnereda67292013-04-28 13:50:14 -07006800 @Override
Daniel Sandler0c4ccff2011-10-19 16:39:14 -04006801 public boolean hasNavigationBar() {
6802 return mHasNavigationBar;
6803 }
6804
satok1bc0a492012-04-25 22:47:12 +09006805 @Override
6806 public void setLastInputMethodWindowLw(WindowState ime, WindowState target) {
6807 mLastInputMethodWindow = ime;
6808 mLastInputMethodTargetWindow = target;
6809 }
6810
Craig Mautnerf1b67412012-09-19 13:18:29 -07006811 @Override
Satoshi Kataoka658c7b82013-10-10 17:03:51 +09006812 public int getInputMethodWindowVisibleHeightLw() {
6813 return mDockBottom - mCurBottom;
6814 }
6815
6816 @Override
Craig Mautnerf1b67412012-09-19 13:18:29 -07006817 public void setCurrentUserLw(int newUserId) {
Craig Mautnerd625ab22013-09-06 13:40:31 -07006818 mCurrentUserId = newUserId;
Jim Miller5ecd8112013-01-09 18:50:26 -08006819 if (mKeyguardDelegate != null) {
6820 mKeyguardDelegate.setCurrentUser(newUserId);
Craig Mautnerf1b67412012-09-19 13:18:29 -07006821 }
John Spurlock13451a22012-09-28 14:40:41 -04006822 if (mStatusBarService != null) {
6823 try {
6824 mStatusBarService.setCurrentUser(newUserId);
6825 } catch (RemoteException e) {
6826 // oh well
6827 }
6828 }
Dianne Hackborn2ea9bae2012-11-02 18:43:48 -07006829 setLastInputMethodWindowLw(null, null);
Craig Mautnerf1b67412012-09-19 13:18:29 -07006830 }
6831
6832 @Override
Svetoslav Ganov545252f2012-12-10 18:29:24 -08006833 public boolean canMagnifyWindow(int windowType) {
6834 switch (windowType) {
6835 case WindowManager.LayoutParams.TYPE_INPUT_METHOD:
6836 case WindowManager.LayoutParams.TYPE_INPUT_METHOD_DIALOG:
6837 case WindowManager.LayoutParams.TYPE_NAVIGATION_BAR:
6838 case WindowManager.LayoutParams.TYPE_MAGNIFICATION_OVERLAY: {
6839 return false;
6840 }
6841 }
6842 return true;
6843 }
6844
6845 @Override
6846 public boolean isTopLevelWindow(int windowType) {
6847 if (windowType >= WindowManager.LayoutParams.FIRST_SUB_WINDOW
6848 && windowType <= WindowManager.LayoutParams.LAST_SUB_WINDOW) {
6849 return (windowType == WindowManager.LayoutParams.TYPE_APPLICATION_ATTACHED_DIALOG);
6850 }
6851 return true;
6852 }
6853
Jim Miller4eeb4f62012-11-08 00:04:29 -08006854 @Override
Jeff Brownd7a04de2012-06-17 14:17:52 -07006855 public void dump(String prefix, PrintWriter pw, String[] args) {
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08006856 pw.print(prefix); pw.print("mSafeMode="); pw.print(mSafeMode);
Dianne Hackbornba24e4d2011-09-01 11:17:06 -07006857 pw.print(" mSystemReady="); pw.print(mSystemReady);
6858 pw.print(" mSystemBooted="); pw.println(mSystemBooted);
Jeff Brown2e7760e2012-04-11 15:14:55 -07006859 pw.print(prefix); pw.print("mLidState="); pw.print(mLidState);
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08006860 pw.print(" mLidOpenRotation="); pw.print(mLidOpenRotation);
Michael Wright3818c922014-09-02 13:59:07 -07006861 pw.print(" mCameraLensCoverState="); pw.print(mCameraLensCoverState);
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08006862 pw.print(" mHdmiPlugged="); pw.println(mHdmiPlugged);
Dianne Hackborne26ab702011-10-16 13:21:33 -07006863 if (mLastSystemUiFlags != 0 || mResettingSystemUiFlags != 0
6864 || mForceClearedSystemUiFlags != 0) {
6865 pw.print(prefix); pw.print("mLastSystemUiFlags=0x");
6866 pw.print(Integer.toHexString(mLastSystemUiFlags));
6867 pw.print(" mResettingSystemUiFlags=0x");
6868 pw.print(Integer.toHexString(mResettingSystemUiFlags));
6869 pw.print(" mForceClearedSystemUiFlags=0x");
6870 pw.println(Integer.toHexString(mForceClearedSystemUiFlags));
Dianne Hackborndf89e652011-10-06 22:35:11 -07006871 }
Dianne Hackborn4eff8d32011-11-10 19:38:40 -08006872 if (mLastFocusNeedsMenu) {
6873 pw.print(prefix); pw.print("mLastFocusNeedsMenu=");
6874 pw.println(mLastFocusNeedsMenu);
6875 }
Jeff Browna20dda42014-05-27 20:57:24 -07006876 pw.print(prefix); pw.print("mWakeGestureEnabledSetting=");
6877 pw.println(mWakeGestureEnabledSetting);
6878
Jeff Brownbcdfc622014-03-06 19:13:04 -08006879 pw.print(prefix); pw.print("mSupportAutoRotation="); pw.println(mSupportAutoRotation);
Daniel Sandler6396c722013-04-16 20:19:09 -04006880 pw.print(prefix); pw.print("mUiMode="); pw.print(mUiMode);
6881 pw.print(" mDockMode="); pw.print(mDockMode);
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08006882 pw.print(" mCarDockRotation="); pw.print(mCarDockRotation);
6883 pw.print(" mDeskDockRotation="); pw.println(mDeskDockRotation);
6884 pw.print(prefix); pw.print("mUserRotationMode="); pw.print(mUserRotationMode);
6885 pw.print(" mUserRotation="); pw.print(mUserRotation);
Daniel Sandler2ed6ad62011-02-22 14:54:17 -05006886 pw.print(" mAllowAllRotations="); pw.println(mAllowAllRotations);
Dianne Hackborn6e2281d2012-06-19 17:48:32 -07006887 pw.print(prefix); pw.print("mCurrentAppOrientation="); pw.println(mCurrentAppOrientation);
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08006888 pw.print(prefix); pw.print("mCarDockEnablesAccelerometer=");
6889 pw.print(mCarDockEnablesAccelerometer);
6890 pw.print(" mDeskDockEnablesAccelerometer=");
6891 pw.println(mDeskDockEnablesAccelerometer);
6892 pw.print(prefix); pw.print("mLidKeyboardAccessibility=");
6893 pw.print(mLidKeyboardAccessibility);
6894 pw.print(" mLidNavigationAccessibility="); pw.print(mLidNavigationAccessibility);
Edward Savage-Jones7def60d2015-11-13 13:27:03 +01006895 pw.print(" mLidControlsScreenLock="); pw.println(mLidControlsScreenLock);
Dianne Hackborn6e2281d2012-06-19 17:48:32 -07006896 pw.print(" mLidControlsSleep="); pw.println(mLidControlsSleep);
Jeff Brown6d8fd272014-05-20 21:24:38 -07006897 pw.print(prefix);
6898 pw.print("mShortPressOnPowerBehavior="); pw.print(mShortPressOnPowerBehavior);
6899 pw.print(" mLongPressOnPowerBehavior="); pw.println(mLongPressOnPowerBehavior);
Jeff Brown13f00f02014-10-31 14:45:50 -07006900 pw.print(prefix);
6901 pw.print("mDoublePressOnPowerBehavior="); pw.print(mDoublePressOnPowerBehavior);
6902 pw.print(" mTriplePressOnPowerBehavior="); pw.println(mTriplePressOnPowerBehavior);
Jeff Brown6d8fd272014-05-20 21:24:38 -07006903 pw.print(prefix); pw.print("mHasSoftInput="); pw.println(mHasSoftInput);
Jeff Brown3ee549c2014-09-22 20:14:39 -07006904 pw.print(prefix); pw.print("mAwake="); pw.println(mAwake);
6905 pw.print(prefix); pw.print("mScreenOnEarly="); pw.print(mScreenOnEarly);
6906 pw.print(" mScreenOnFully="); pw.println(mScreenOnFully);
6907 pw.print(prefix); pw.print("mKeyguardDrawComplete="); pw.print(mKeyguardDrawComplete);
6908 pw.print(" mWindowManagerDrawComplete="); pw.println(mWindowManagerDrawComplete);
6909 pw.print(prefix); pw.print("mOrientationSensorEnabled=");
6910 pw.println(mOrientationSensorEnabled);
Dianne Hackbornc652de82013-02-15 16:32:56 -08006911 pw.print(prefix); pw.print("mOverscanScreen=("); pw.print(mOverscanScreenLeft);
6912 pw.print(","); pw.print(mOverscanScreenTop);
6913 pw.print(") "); pw.print(mOverscanScreenWidth);
6914 pw.print("x"); pw.println(mOverscanScreenHeight);
6915 if (mOverscanLeft != 0 || mOverscanTop != 0
6916 || mOverscanRight != 0 || mOverscanBottom != 0) {
6917 pw.print(prefix); pw.print("mOverscan left="); pw.print(mOverscanLeft);
6918 pw.print(" top="); pw.print(mOverscanTop);
6919 pw.print(" right="); pw.print(mOverscanRight);
6920 pw.print(" bottom="); pw.println(mOverscanBottom);
6921 }
Dianne Hackborn313440842013-02-19 19:22:59 -08006922 pw.print(prefix); pw.print("mRestrictedOverscanScreen=(");
6923 pw.print(mRestrictedOverscanScreenLeft);
6924 pw.print(","); pw.print(mRestrictedOverscanScreenTop);
6925 pw.print(") "); pw.print(mRestrictedOverscanScreenWidth);
6926 pw.print("x"); pw.println(mRestrictedOverscanScreenHeight);
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08006927 pw.print(prefix); pw.print("mUnrestrictedScreen=("); pw.print(mUnrestrictedScreenLeft);
6928 pw.print(","); pw.print(mUnrestrictedScreenTop);
6929 pw.print(") "); pw.print(mUnrestrictedScreenWidth);
6930 pw.print("x"); pw.println(mUnrestrictedScreenHeight);
6931 pw.print(prefix); pw.print("mRestrictedScreen=("); pw.print(mRestrictedScreenLeft);
6932 pw.print(","); pw.print(mRestrictedScreenTop);
6933 pw.print(") "); pw.print(mRestrictedScreenWidth);
6934 pw.print("x"); pw.println(mRestrictedScreenHeight);
Dianne Hackborn5b5cc4d2012-05-16 13:15:00 -07006935 pw.print(prefix); pw.print("mStableFullscreen=("); pw.print(mStableFullscreenLeft);
6936 pw.print(","); pw.print(mStableFullscreenTop);
6937 pw.print(")-("); pw.print(mStableFullscreenRight);
6938 pw.print(","); pw.print(mStableFullscreenBottom); pw.println(")");
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07006939 pw.print(prefix); pw.print("mStable=("); pw.print(mStableLeft);
6940 pw.print(","); pw.print(mStableTop);
6941 pw.print(")-("); pw.print(mStableRight);
6942 pw.print(","); pw.print(mStableBottom); pw.println(")");
Dianne Hackborn5c58de32012-04-28 19:52:37 -07006943 pw.print(prefix); pw.print("mSystem=("); pw.print(mSystemLeft);
6944 pw.print(","); pw.print(mSystemTop);
6945 pw.print(")-("); pw.print(mSystemRight);
6946 pw.print(","); pw.print(mSystemBottom); pw.println(")");
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08006947 pw.print(prefix); pw.print("mCur=("); pw.print(mCurLeft);
6948 pw.print(","); pw.print(mCurTop);
6949 pw.print(")-("); pw.print(mCurRight);
6950 pw.print(","); pw.print(mCurBottom); pw.println(")");
6951 pw.print(prefix); pw.print("mContent=("); pw.print(mContentLeft);
6952 pw.print(","); pw.print(mContentTop);
6953 pw.print(")-("); pw.print(mContentRight);
6954 pw.print(","); pw.print(mContentBottom); pw.println(")");
Dianne Hackborne30e02f2014-05-27 18:24:45 -07006955 pw.print(prefix); pw.print("mVoiceContent=("); pw.print(mVoiceContentLeft);
6956 pw.print(","); pw.print(mVoiceContentTop);
6957 pw.print(")-("); pw.print(mVoiceContentRight);
6958 pw.print(","); pw.print(mVoiceContentBottom); pw.println(")");
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08006959 pw.print(prefix); pw.print("mDock=("); pw.print(mDockLeft);
6960 pw.print(","); pw.print(mDockTop);
6961 pw.print(")-("); pw.print(mDockRight);
6962 pw.print(","); pw.print(mDockBottom); pw.println(")");
Dianne Hackborn5c58de32012-04-28 19:52:37 -07006963 pw.print(prefix); pw.print("mDockLayer="); pw.print(mDockLayer);
6964 pw.print(" mStatusBarLayer="); pw.println(mStatusBarLayer);
Dianne Hackborn7ad44382012-10-18 17:46:00 -07006965 pw.print(prefix); pw.print("mShowingLockscreen="); pw.print(mShowingLockscreen);
6966 pw.print(" mShowingDream="); pw.print(mShowingDream);
Jeff Brown061ea992015-04-17 19:55:47 -07006967 pw.print(" mDreamingLockscreen="); pw.print(mDreamingLockscreen);
6968 pw.print(" mDreamingSleepToken="); pw.println(mDreamingSleepToken);
Dianne Hackborn2ea9bae2012-11-02 18:43:48 -07006969 if (mLastInputMethodWindow != null) {
6970 pw.print(prefix); pw.print("mLastInputMethodWindow=");
6971 pw.println(mLastInputMethodWindow);
6972 }
6973 if (mLastInputMethodTargetWindow != null) {
6974 pw.print(prefix); pw.print("mLastInputMethodTargetWindow=");
6975 pw.println(mLastInputMethodTargetWindow);
6976 }
6977 if (mStatusBar != null) {
6978 pw.print(prefix); pw.print("mStatusBar=");
Dianne Hackbornae6688b2015-02-11 17:02:41 -08006979 pw.print(mStatusBar); pw.print(" isStatusBarKeyguard=");
6980 pw.println(isStatusBarKeyguard());
Dianne Hackborn2ea9bae2012-11-02 18:43:48 -07006981 }
6982 if (mNavigationBar != null) {
6983 pw.print(prefix); pw.print("mNavigationBar=");
6984 pw.println(mNavigationBar);
6985 }
Dianne Hackborn2ea9bae2012-11-02 18:43:48 -07006986 if (mFocusedWindow != null) {
6987 pw.print(prefix); pw.print("mFocusedWindow=");
6988 pw.println(mFocusedWindow);
6989 }
6990 if (mFocusedApp != null) {
6991 pw.print(prefix); pw.print("mFocusedApp=");
6992 pw.println(mFocusedApp);
6993 }
6994 if (mWinDismissingKeyguard != null) {
6995 pw.print(prefix); pw.print("mWinDismissingKeyguard=");
6996 pw.println(mWinDismissingKeyguard);
6997 }
6998 if (mTopFullscreenOpaqueWindowState != null) {
6999 pw.print(prefix); pw.print("mTopFullscreenOpaqueWindowState=");
7000 pw.println(mTopFullscreenOpaqueWindowState);
7001 }
Adrian Rooscd3884d2015-02-18 17:25:23 +01007002 if (mTopFullscreenOpaqueOrDimmingWindowState != null) {
7003 pw.print(prefix); pw.print("mTopFullscreenOpaqueOrDimmingWindowState=");
7004 pw.println(mTopFullscreenOpaqueOrDimmingWindowState);
7005 }
Dianne Hackborn891d3fb2013-01-09 18:31:37 -08007006 if (mForcingShowNavBar) {
7007 pw.print(prefix); pw.print("mForcingShowNavBar=");
7008 pw.println(mForcingShowNavBar); pw.print( "mForcingShowNavBarLayer=");
7009 pw.println(mForcingShowNavBarLayer);
7010 }
Dianne Hackborn7ad44382012-10-18 17:46:00 -07007011 pw.print(prefix); pw.print("mTopIsFullscreen="); pw.print(mTopIsFullscreen);
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08007012 pw.print(" mHideLockScreen="); pw.println(mHideLockScreen);
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07007013 pw.print(prefix); pw.print("mForceStatusBar="); pw.print(mForceStatusBar);
7014 pw.print(" mForceStatusBarFromKeyguard=");
7015 pw.println(mForceStatusBarFromKeyguard);
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08007016 pw.print(prefix); pw.print("mDismissKeyguard="); pw.print(mDismissKeyguard);
Craig Mautnerad09bcc2012-10-08 13:33:11 -07007017 pw.print(" mWinDismissingKeyguard="); pw.print(mWinDismissingKeyguard);
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08007018 pw.print(" mHomePressed="); pw.println(mHomePressed);
7019 pw.print(prefix); pw.print("mAllowLockscreenWhenOn="); pw.print(mAllowLockscreenWhenOn);
7020 pw.print(" mLockScreenTimeout="); pw.print(mLockScreenTimeout);
7021 pw.print(" mLockScreenTimerActive="); pw.println(mLockScreenTimerActive);
7022 pw.print(prefix); pw.print("mEndcallBehavior="); pw.print(mEndcallBehavior);
7023 pw.print(" mIncallPowerBehavior="); pw.print(mIncallPowerBehavior);
7024 pw.print(" mLongPressOnHomeBehavior="); pw.println(mLongPressOnHomeBehavior);
7025 pw.print(prefix); pw.print("mLandscapeRotation="); pw.print(mLandscapeRotation);
7026 pw.print(" mSeascapeRotation="); pw.println(mSeascapeRotation);
7027 pw.print(prefix); pw.print("mPortraitRotation="); pw.print(mPortraitRotation);
7028 pw.print(" mUpsideDownRotation="); pw.println(mUpsideDownRotation);
Jeff Brownc82c89ed2013-04-17 17:18:15 -07007029 pw.print(prefix); pw.print("mDemoHdmiRotation="); pw.print(mDemoHdmiRotation);
7030 pw.print(" mDemoHdmiRotationLock="); pw.println(mDemoHdmiRotationLock);
7031 pw.print(prefix); pw.print("mUndockedHdmiRotation="); pw.println(mUndockedHdmiRotation);
Jeff Brown600f0032014-05-22 17:06:00 -07007032
Tim Kilbournd7c0c2e2014-05-29 16:08:10 -07007033 mGlobalKeyManager.dump(prefix, pw);
John Spurlock27735a42013-08-14 17:57:38 -04007034 mStatusBarController.dump(pw, prefix);
7035 mNavigationBarController.dump(pw, prefix);
John Spurlockc6d1c602014-01-17 15:22:06 -05007036 PolicyControl.dump(prefix, pw);
Jeff Brown600f0032014-05-22 17:06:00 -07007037
Jeff Browna20dda42014-05-27 20:57:24 -07007038 if (mWakeGestureListener != null) {
7039 mWakeGestureListener.dump(pw, prefix);
7040 }
Jeff Brown600f0032014-05-22 17:06:00 -07007041 if (mOrientationListener != null) {
7042 mOrientationListener.dump(pw, prefix);
7043 }
Filip Gruszczynskicfb31852015-02-25 21:47:12 +00007044 if (mBurnInProtectionHelper != null) {
7045 mBurnInProtectionHelper.dump(prefix, pw);
7046 }
Jorim Jaggi84dc08a2015-09-11 17:45:22 -07007047 if (mKeyguardDelegate != null) {
7048 mKeyguardDelegate.dump(prefix, pw);
7049 }
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08007050 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08007051}