blob: adc3a7d54136cfece90a024e68dd245ab34c7703 [file] [log] [blame]
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001/*
Jeff Brown37df39a92015-02-25 15:42:31 -08002 * Copyright (C) 2006 The Android Open Source Project
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
Jorim Jaggib10e33f2015-02-04 21:57:40 +010017package com.android.server.policy;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -080018
Dianne Hackborna4972e92012-03-14 10:38:05 -070019import android.app.ActivityManager;
Jeff Brown061ea992015-04-17 19:55:47 -070020import android.app.ActivityManagerInternal;
21import android.app.ActivityManagerInternal.SleepToken;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -080022import android.app.ActivityManagerNative;
Dianne Hackbornc2293022013-02-06 23:14:49 -080023import android.app.AppOpsManager;
Daniel Sandler6396c722013-04-16 20:19:09 -040024import android.app.IUiModeManager;
Dianne Hackborn661cd522011-08-22 00:26:20 -070025import android.app.ProgressDialog;
Jeff Brownde7a8ea2012-06-13 18:28:57 -070026import android.app.SearchManager;
John Spurlock97642182013-07-29 17:58:39 -040027import android.app.StatusBarManager;
Dianne Hackborn78968392010-03-04 20:47:56 -080028import android.app.UiModeManager;
Dianne Hackborn39c2d712009-09-22 11:41:31 -070029import android.content.ActivityNotFoundException;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -080030import android.content.BroadcastReceiver;
Daniel Sandler0601eb72011-04-13 01:01:32 -040031import android.content.ComponentName;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -080032import android.content.ContentResolver;
33import android.content.Context;
34import android.content.Intent;
Mike Lockwood1753f7f2009-08-24 14:49:07 -070035import android.content.IntentFilter;
Winson Chung9112ec32011-06-27 13:15:32 -070036import android.content.ServiceConnection;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -080037import android.content.pm.ActivityInfo;
38import android.content.pm.PackageManager;
Daniel Sandler6396c722013-04-16 20:19:09 -040039import android.content.pm.ResolveInfo;
Dianne Hackborn2f0b1752011-05-31 17:59:49 -070040import android.content.res.CompatibilityInfo;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -080041import android.content.res.Configuration;
42import android.content.res.Resources;
Craig Mautner8e4df6c2012-05-23 16:57:23 -070043import android.content.res.TypedArray;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -080044import android.database.ContentObserver;
Dianne Hackbornc777e072010-02-12 13:07:59 -080045import android.graphics.PixelFormat;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -080046import android.graphics.Rect;
John Spurlock7b414672014-07-18 13:02:39 -040047import android.media.AudioAttributes;
Michael Jurka7a348952012-02-27 13:07:58 -080048import android.media.AudioManager;
John Spurlock61560172015-02-06 19:46:04 -050049import android.media.AudioSystem;
Michael Jurka7a348952012-02-27 13:07:58 -080050import android.media.IAudioService;
Svetoslav Ganov7befb7d2012-09-27 16:49:23 -070051import android.media.Ringtone;
52import android.media.RingtoneManager;
RoboErik8a2cfc32014-05-16 11:19:38 -070053import android.media.session.MediaSessionLegacyHelper;
Mark Renoufc1256912015-03-11 14:38:23 -040054import android.os.Build;
Dianne Hackborn38e29a62011-09-18 14:43:08 -070055import android.os.Bundle;
Craig Mautner276a6eb2014-11-04 15:32:57 -080056import android.os.Debug;
Jeff Brown9a538ee2012-08-20 14:56:57 -070057import android.os.FactoryTest;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -080058import android.os.Handler;
59import android.os.IBinder;
Jeff Brown32cbc38552011-12-01 14:01:49 -080060import android.os.Looper;
Dianne Hackbornfc8fa632011-08-17 16:20:47 -070061import android.os.Message;
62import android.os.Messenger;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -080063import android.os.PowerManager;
64import android.os.RemoteException;
65import android.os.ServiceManager;
66import android.os.SystemClock;
67import android.os.SystemProperties;
Dianne Hackbornad7fa7f2011-01-07 14:06:50 -080068import android.os.UEventObserver;
Dianne Hackbornf02b60a2012-08-16 10:48:27 -070069import android.os.UserHandle;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -080070import android.os.Vibrator;
Michael Wright3818c922014-09-02 13:59:07 -070071import android.provider.MediaStore;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -080072import android.provider.Settings;
Jose Lima9546b202014-07-02 17:21:51 -070073import android.service.dreams.DreamManagerInternal;
John Spurlockc8b46ca2013-04-08 12:59:26 -040074import android.service.dreams.DreamService;
75import android.service.dreams.IDreamManager;
Michael Wrightdc63f7b2014-08-21 19:05:21 -070076import android.speech.RecognizerIntent;
Tyler Gunnef9f6f92014-09-12 22:16:17 -070077import android.telecom.TelecomManager;
Dianne Hackborn81e56d52011-05-26 00:55:58 -070078import android.util.DisplayMetrics;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -080079import android.util.EventLog;
80import android.util.Log;
Jeff Browna41ca772010-08-11 14:46:32 -070081import android.util.Slog;
Jeff Brown6651a632011-11-28 12:59:11 -080082import android.util.SparseArray;
Dianne Hackbornf87d1962012-04-04 12:48:24 -070083import android.view.Display;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -080084import android.view.Gravity;
85import android.view.HapticFeedbackConstants;
Dianne Hackborne0f085d2011-11-30 18:41:15 -080086import android.view.IApplicationToken;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -080087import android.view.IWindowManager;
Jeff Browna41ca772010-08-11 14:46:32 -070088import android.view.InputChannel;
Jeff Brown4d396052010-10-29 21:50:21 -070089import android.view.InputDevice;
Jeff Brown4952dfd2011-11-30 19:23:22 -080090import android.view.InputEvent;
Jeff Brown32cbc38552011-12-01 14:01:49 -080091import android.view.InputEventReceiver;
Jeff Brown6b53e8d2010-11-10 16:03:06 -080092import android.view.KeyCharacterMap;
Craig Mautnerae446592012-12-06 19:05:05 -080093import android.view.KeyCharacterMap.FallbackAction;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -080094import android.view.KeyEvent;
95import android.view.MotionEvent;
Jorim Jaggib10e33f2015-02-04 21:57:40 +010096import android.view.PhoneWindow;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -080097import android.view.Surface;
98import android.view.View;
99import android.view.ViewConfiguration;
Mark Renoufc1256912015-03-11 14:38:23 -0400100import android.view.ViewRootImpl;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800101import android.view.Window;
102import android.view.WindowManager;
Craig Mautnerae446592012-12-06 19:05:05 -0800103import android.view.WindowManagerGlobal;
Craig Mautner8a0da012014-05-31 15:13:37 -0700104import android.view.WindowManagerInternal;
Craig Mautnerae446592012-12-06 19:05:05 -0800105import android.view.WindowManagerPolicy;
Craig Mautnerae446592012-12-06 19:05:05 -0800106import android.view.accessibility.AccessibilityEvent;
Svetoslav8e3feb12014-02-24 13:46:47 -0800107import android.view.accessibility.AccessibilityManager;
Craig Mautnerae446592012-12-06 19:05:05 -0800108import android.view.animation.Animation;
Jorim Jaggi76a16232014-08-08 17:00:47 +0200109import android.view.animation.AnimationSet;
Craig Mautnerae446592012-12-06 19:05:05 -0800110import android.view.animation.AnimationUtils;
Craig Mautnerae446592012-12-06 19:05:05 -0800111import com.android.internal.R;
Craig Mautnerae446592012-12-06 19:05:05 -0800112import com.android.internal.statusbar.IStatusBarService;
Craig Mautnerae446592012-12-06 19:05:05 -0800113import com.android.internal.widget.PointerLocationView;
Craig Mautner8a0da012014-05-31 15:13:37 -0700114import com.android.server.LocalServices;
Jorim Jaggib10e33f2015-02-04 21:57:40 +0100115import com.android.server.policy.keyguard.KeyguardServiceDelegate;
116import com.android.server.policy.keyguard.KeyguardServiceDelegate.ShowListener;
Craig Mautnerae446592012-12-06 19:05:05 -0800117
118import java.io.File;
119import java.io.FileReader;
120import java.io.IOException;
121import java.io.PrintWriter;
Craig Mautner2bc789b2014-03-19 19:48:38 -0700122import java.util.HashSet;
Craig Mautner276a6eb2014-11-04 15:32:57 -0800123import java.util.List;
Craig Mautnerae446592012-12-06 19:05:05 -0800124
Dianne Hackbornc652de82013-02-15 16:32:56 -0800125import static android.view.WindowManager.LayoutParams.*;
Jeff Brownac143512012-04-05 18:57:33 -0700126import static android.view.WindowManagerPolicy.WindowManagerFuncs.LID_ABSENT;
127import static android.view.WindowManagerPolicy.WindowManagerFuncs.LID_OPEN;
128import static android.view.WindowManagerPolicy.WindowManagerFuncs.LID_CLOSED;
Michael Wright3818c922014-09-02 13:59:07 -0700129import static android.view.WindowManagerPolicy.WindowManagerFuncs.CAMERA_LENS_COVER_ABSENT;
130import static android.view.WindowManagerPolicy.WindowManagerFuncs.CAMERA_LENS_UNCOVERED;
131import static android.view.WindowManagerPolicy.WindowManagerFuncs.CAMERA_LENS_COVERED;
Dianne Hackborn08743722009-12-21 12:16:51 -0800132
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800133/**
The Android Open Source Project0727d222009-03-11 12:11:58 -0700134 * WindowManagerPolicy implementation for the Android phone UI. This
135 * introduces a new method suffix, Lp, for an internal lock of the
136 * PhoneWindowManager. This is used to protect some internal state, and
John Spurlock04db1762013-05-13 12:46:41 -0400137 * 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 -0700138 * of both of those when held.
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800139 */
140public class PhoneWindowManager implements WindowManagerPolicy {
141 static final String TAG = "WindowManager";
142 static final boolean DEBUG = false;
Joe Onorato43a17652011-04-06 19:22:23 -0700143 static final boolean localLOGV = false;
Jeff Brown40013652012-05-16 21:22:36 -0700144 static final boolean DEBUG_INPUT = false;
Craig Mautnerc0d2d0a2014-10-31 16:25:15 -0700145 static final boolean DEBUG_KEYGUARD = false;
146 static final boolean DEBUG_LAYOUT = false;
Craig Mautner6fbda632012-07-03 09:26:39 -0700147 static final boolean DEBUG_STARTING_WINDOW = false;
Craig Mautner8a0da012014-05-31 15:13:37 -0700148 static final boolean DEBUG_WAKEUP = false;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800149 static final boolean SHOW_STARTING_ANIMATIONS = true;
150 static final boolean SHOW_PROCESSES_ON_ALT_MENU = false;
Joe Onoratod208e702010-10-08 16:22:43 -0400151
Daniel Sandler6396c722013-04-16 20:19:09 -0400152 // Whether to allow dock apps with METADATA_DOCK_HOME to temporarily take over the Home key.
153 // No longer recommended for desk docks; still useful in car docks.
154 static final boolean ENABLE_CAR_DOCK_HOME_CAPTURE = true;
155 static final boolean ENABLE_DESK_DOCK_HOME_CAPTURE = false;
156
Jeff Brown6d8fd272014-05-20 21:24:38 -0700157 static final int SHORT_PRESS_POWER_NOTHING = 0;
158 static final int SHORT_PRESS_POWER_GO_TO_SLEEP = 1;
159 static final int SHORT_PRESS_POWER_REALLY_GO_TO_SLEEP = 2;
160 static final int SHORT_PRESS_POWER_REALLY_GO_TO_SLEEP_AND_GO_HOME = 3;
Bryce Lee01b0c5f2015-02-05 18:24:04 -0800161 static final int SHORT_PRESS_POWER_GO_HOME = 4;
Jeff Brown6d8fd272014-05-20 21:24:38 -0700162
Joe Onoratod208e702010-10-08 16:22:43 -0400163 static final int LONG_PRESS_POWER_NOTHING = 0;
164 static final int LONG_PRESS_POWER_GLOBAL_ACTIONS = 1;
165 static final int LONG_PRESS_POWER_SHUT_OFF = 2;
Jeff Brown9a538ee2012-08-20 14:56:57 -0700166 static final int LONG_PRESS_POWER_SHUT_OFF_NO_CONFIRM = 3;
Michael Jurka3b1fc472011-06-13 10:54:40 -0700167
Jeff Brown13f00f02014-10-31 14:45:50 -0700168 static final int MULTI_PRESS_POWER_NOTHING = 0;
169 static final int MULTI_PRESS_POWER_THEATER_MODE = 1;
170 static final int MULTI_PRESS_POWER_BRIGHTNESS_BOOST = 2;
171
Michael Jurka3b1fc472011-06-13 10:54:40 -0700172 // These need to match the documentation/constant in
173 // core/res/res/values/config.xml
Joe Onorato46b0d682010-11-22 17:37:27 -0800174 static final int LONG_PRESS_HOME_NOTHING = 0;
Michael Wrightc9ebea72013-01-16 19:25:02 -0800175 static final int LONG_PRESS_HOME_RECENT_SYSTEM_UI = 1;
Jeff Browncaca8812013-05-09 13:34:33 -0700176 static final int LONG_PRESS_HOME_ASSIST = 2;
177
178 static final int DOUBLE_TAP_HOME_NOTHING = 0;
179 static final int DOUBLE_TAP_HOME_RECENT_SYSTEM_UI = 1;
Joe Onorato46b0d682010-11-22 17:37:27 -0800180
Filip Gruszczynskia483a1d2015-03-17 19:06:58 +0000181 static final int SHORT_PRESS_SLEEP_GO_TO_SLEEP = 0;
182 static final int SHORT_PRESS_SLEEP_GO_TO_SLEEP_AND_GO_HOME = 1;
183
Dianne Hackborn5cb8d792009-05-21 17:34:15 -0700184 static final int APPLICATION_MEDIA_SUBLAYER = -2;
185 static final int APPLICATION_MEDIA_OVERLAY_SUBLAYER = -1;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800186 static final int APPLICATION_PANEL_SUBLAYER = 1;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800187 static final int APPLICATION_SUB_PANEL_SUBLAYER = 2;
Wale Ogunwale0a4dc222015-04-14 12:58:42 -0700188 static final int APPLICATION_ABOVE_SUB_PANEL_SUBLAYER = 3;
Craig Mautner88400d32012-09-30 12:35:45 -0700189
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800190 static public final String SYSTEM_DIALOG_REASON_KEY = "reason";
191 static public final String SYSTEM_DIALOG_REASON_GLOBAL_ACTIONS = "globalactions";
192 static public final String SYSTEM_DIALOG_REASON_RECENT_APPS = "recentapps";
Joe Onoratof275f0c2009-11-24 16:11:13 -0500193 static public final String SYSTEM_DIALOG_REASON_HOME_KEY = "homekey";
Jeff Brownde7a8ea2012-06-13 18:28:57 -0700194 static public final String SYSTEM_DIALOG_REASON_ASSIST = "assist";
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800195
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -0700196 /**
197 * These are the system UI flags that, when changing, can cause the layout
198 * of the screen to change.
199 */
200 static final int SYSTEM_UI_CHANGING_LAYOUT =
John Spurlocke1f366f2013-08-05 12:22:40 -0400201 View.SYSTEM_UI_FLAG_HIDE_NAVIGATION
John Spurlock7f4820a2013-10-08 12:54:35 -0400202 | View.SYSTEM_UI_FLAG_FULLSCREEN
203 | View.STATUS_BAR_TRANSLUCENT
Adrian Roosea562512014-05-05 13:33:03 +0200204 | View.NAVIGATION_BAR_TRANSLUCENT
205 | View.SYSTEM_UI_TRANSPARENT;
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -0700206
John Spurlock7b414672014-07-18 13:02:39 -0400207 private static final AudioAttributes VIBRATION_ATTRIBUTES = new AudioAttributes.Builder()
208 .setContentType(AudioAttributes.CONTENT_TYPE_SONIFICATION)
209 .setUsage(AudioAttributes.USAGE_ASSISTANCE_SONIFICATION)
210 .build();
211
Jim Miller5ecd8112013-01-09 18:50:26 -0800212 /**
213 * Keyguard stuff
214 */
215 private WindowState mKeyguardScrim;
Jorim Jaggi380ecb82014-03-14 17:25:20 +0100216 private boolean mKeyguardHidden;
Jeff Brown3ee549c2014-09-22 20:14:39 -0700217 private boolean mKeyguardDrawnOnce;
Jim Miller5ecd8112013-01-09 18:50:26 -0800218
Jeff Brown6651a632011-11-28 12:59:11 -0800219 /* Table of Application Launch keys. Maps from key codes to intent categories.
220 *
221 * These are special keys that are used to launch particular kinds of applications,
222 * such as a web browser. HID defines nearly a hundred of them in the Consumer (0x0C)
223 * usage page. We don't support quite that many yet...
224 */
225 static SparseArray<String> sApplicationLaunchKeyCategories;
226 static {
227 sApplicationLaunchKeyCategories = new SparseArray<String>();
228 sApplicationLaunchKeyCategories.append(
229 KeyEvent.KEYCODE_EXPLORER, Intent.CATEGORY_APP_BROWSER);
230 sApplicationLaunchKeyCategories.append(
231 KeyEvent.KEYCODE_ENVELOPE, Intent.CATEGORY_APP_EMAIL);
232 sApplicationLaunchKeyCategories.append(
233 KeyEvent.KEYCODE_CONTACTS, Intent.CATEGORY_APP_CONTACTS);
234 sApplicationLaunchKeyCategories.append(
235 KeyEvent.KEYCODE_CALENDAR, Intent.CATEGORY_APP_CALENDAR);
236 sApplicationLaunchKeyCategories.append(
237 KeyEvent.KEYCODE_MUSIC, Intent.CATEGORY_APP_MUSIC);
238 sApplicationLaunchKeyCategories.append(
239 KeyEvent.KEYCODE_CALCULATOR, Intent.CATEGORY_APP_CALCULATOR);
240 }
241
Craig Mautnerc3daedd2014-09-13 11:17:23 -0700242 /** Amount of time (in milliseconds) to wait for windows drawn before powering on. */
243 static final int WAITING_FOR_DRAWN_TIMEOUT = 1000;
244
Dianne Hackborndf89e652011-10-06 22:35:11 -0700245 /**
246 * Lock protecting internal state. Must not call out into window
247 * manager with lock held. (This lock will be acquired in places
248 * where the window manager is calling in with its own lock held.)
249 */
Craig Mautner0bf6ec92012-12-18 08:33:27 -0800250 private final Object mLock = new Object();
Dianne Hackborndf89e652011-10-06 22:35:11 -0700251
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800252 Context mContext;
253 IWindowManager mWindowManager;
Dianne Hackborndf89e652011-10-06 22:35:11 -0700254 WindowManagerFuncs mWindowManagerFuncs;
Craig Mautner8a0da012014-05-31 15:13:37 -0700255 WindowManagerInternal mWindowManagerInternal;
Jeff Brown96307042012-07-27 15:51:34 -0700256 PowerManager mPowerManager;
Jeff Brown061ea992015-04-17 19:55:47 -0700257 ActivityManagerInternal mActivityManagerInternal;
Jose Lima9546b202014-07-02 17:21:51 -0700258 DreamManagerInternal mDreamManagerInternal;
Joe Onorato93056472010-09-10 10:30:46 -0400259 IStatusBarService mStatusBarService;
Jeff Browncaca8812013-05-09 13:34:33 -0700260 boolean mPreloadedRecentApps;
Dianne Hackborn42e620c2012-06-24 13:20:51 -0700261 final Object mServiceAquireLock = new Object();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800262 Vibrator mVibrator; // Vibrator for giving feedback of orientation changes
Jeff Brownde7a8ea2012-06-13 18:28:57 -0700263 SearchManager mSearchManager;
Svetoslav8e3feb12014-02-24 13:46:47 -0800264 AccessibilityManager mAccessibilityManager;
Filip Gruszczynskicfb31852015-02-25 21:47:12 +0000265 BurnInProtectionHelper mBurnInProtectionHelper;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800266
Dianne Hackborn181ceb52009-08-27 22:16:40 -0700267 // Vibrator pattern for haptic feedback of a long press.
268 long[] mLongPressVibePattern;
Craig Mautner88400d32012-09-30 12:35:45 -0700269
Dianne Hackborn181ceb52009-08-27 22:16:40 -0700270 // Vibrator pattern for haptic feedback of virtual key press.
271 long[] mVirtualKeyVibePattern;
Craig Mautner967212c2013-04-13 21:10:58 -0700272
Amith Yamasanic33cb712010-02-10 15:21:49 -0800273 // Vibrator pattern for a short vibration.
274 long[] mKeyboardTapVibePattern;
275
Fabrice Di Meglioeeff63a2013-08-05 12:07:24 -0700276 // Vibrator pattern for a short vibration when tapping on an hour/minute tick of a Clock.
277 long[] mClockTickVibePattern;
278
Fabrice Di Megliobd9152f2013-10-01 11:21:31 -0700279 // Vibrator pattern for a short vibration when tapping on a day/month/year date of a Calendar.
280 long[] mCalendarDateVibePattern;
281
Dianne Hackbornb1a79802009-09-29 15:18:31 -0700282 // Vibrator pattern for haptic feedback during boot when safe mode is disabled.
283 long[] mSafeModeDisabledVibePattern;
Craig Mautner967212c2013-04-13 21:10:58 -0700284
Dianne Hackbornb1a79802009-09-29 15:18:31 -0700285 // Vibrator pattern for haptic feedback during boot when safe mode is enabled.
286 long[] mSafeModeEnabledVibePattern;
Romain Guy8154cd32010-03-29 14:41:15 -0700287
Mady Mellore82067b2015-04-30 09:58:35 -0700288 // Vibrator pattern for haptic feedback of a stylus button press.
289 long[] mStylusButtonPressVibePattern;
290
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800291 /** If true, hitting shift & menu will broadcast Intent.ACTION_BUG_REPORT */
292 boolean mEnableShiftMenuBugReports = false;
Mike Lockwoodd747dc82011-09-13 16:28:22 -0400293
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800294 boolean mSafeMode;
295 WindowState mStatusBar = null;
Dianne Hackborn69cb8752011-05-19 18:13:32 -0700296 int mStatusBarHeight;
Daniel Sandler8956dbb2011-04-22 07:55:02 -0400297 WindowState mNavigationBar = null;
Daniel Sandler36412a72011-08-04 09:35:13 -0400298 boolean mHasNavigationBar = false;
Dianne Hackbornf87d1962012-04-04 12:48:24 -0700299 boolean mCanHideNavigationBar = false;
Daniel Sandler4a066c52012-04-20 14:49:13 -0400300 boolean mNavigationBarCanMove = false; // can the navigation bar ever move to the side?
301 boolean mNavigationBarOnBottom = true; // is the navigation bar on the bottom *right now*?
302 int[] mNavigationBarHeightForRotation = new int[4];
303 int[] mNavigationBarWidthForRotation = new int[4];
Daniel Sandler8956dbb2011-04-22 07:55:02 -0400304
Craig Mautnera631d492014-08-05 15:16:01 -0700305 boolean mBootMessageNeedsHiding;
Jim Miller5ecd8112013-01-09 18:50:26 -0800306 KeyguardServiceDelegate mKeyguardDelegate;
Craig Mautner13f6ea72014-06-23 14:57:02 -0700307 final Runnable mWindowManagerDrawCallback = new Runnable() {
Craig Mautner8a0da012014-05-31 15:13:37 -0700308 @Override
Craig Mautner13f6ea72014-06-23 14:57:02 -0700309 public void run() {
Craig Mautner8a0da012014-05-31 15:13:37 -0700310 if (DEBUG_WAKEUP) Slog.i(TAG, "All windows ready for display!");
311 mHandler.sendEmptyMessage(MSG_WINDOW_MANAGER_DRAWN_COMPLETE);
312 }
313 };
314 final ShowListener mKeyguardDelegateCallback = new ShowListener() {
315 @Override
316 public void onShown(IBinder windowToken) {
317 if (DEBUG_WAKEUP) Slog.d(TAG, "mKeyguardDelegate.ShowListener.onShown.");
318 mHandler.sendEmptyMessage(MSG_KEYGUARD_DRAWN_COMPLETE);
319 }
320 };
321
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800322 GlobalActions mGlobalActions;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800323 Handler mHandler;
satok1bc0a492012-04-25 22:47:12 +0900324 WindowState mLastInputMethodWindow = null;
325 WindowState mLastInputMethodTargetWindow = null;
Jeff Brown4aed78b2011-01-14 17:36:55 -0800326
Jeff Brown13f00f02014-10-31 14:45:50 -0700327 // FIXME This state is shared between the input reader and handler thread.
328 // Technically it's broken and buggy but it has been like this for many years
329 // and we have not yet seen any problems. Someday we'll rewrite this logic
330 // so that only one thread is involved in handling input policy. Unfortunately
331 // it's on a critical path for power management so we can't just post the work to the
332 // handler thread. We'll need to resolve this someday by teaching the input dispatcher
333 // to hold wakelocks during dispatch and eliminating the critical path.
334 volatile boolean mPowerKeyHandled;
Bryce Leed9268e32014-11-17 17:40:59 -0800335 volatile boolean mBeganFromNonInteractive;
Jeff Brown13f00f02014-10-31 14:45:50 -0700336 volatile int mPowerKeyPressCounter;
337 volatile boolean mEndCallKeyHandled;
338
Winson Chungd42a6cf2014-06-03 16:24:04 -0700339 boolean mRecentsVisible;
Winson Chung1e8d71b2014-05-16 17:05:22 -0700340 int mRecentAppsHeldModifiers;
Jeff Browncf39bdf2012-05-18 14:41:19 -0700341 boolean mLanguageSwitchKeyPressed;
Jeff Brown68b909d2011-12-07 16:36:01 -0800342
Jeff Brown2e7760e2012-04-11 15:14:55 -0700343 int mLidState = LID_ABSENT;
Michael Wright3818c922014-09-02 13:59:07 -0700344 int mCameraLensCoverState = CAMERA_LENS_COVER_ABSENT;
Jeff Browndaa37532012-05-01 15:54:03 -0700345 boolean mHaveBuiltInKeyboard;
Jeff Brown4aed78b2011-01-14 17:36:55 -0800346
Dianne Hackbornc777e072010-02-12 13:07:59 -0800347 boolean mSystemReady;
Dianne Hackbornba24e4d2011-09-01 11:17:06 -0700348 boolean mSystemBooted;
Dianne Hackbornad7fa7f2011-01-07 14:06:50 -0800349 boolean mHdmiPlugged;
Jeff Brown4f5fa282014-06-12 19:19:15 -0700350 IUiModeManager mUiModeManager;
Daniel Sandler6396c722013-04-16 20:19:09 -0400351 int mUiMode;
Dianne Hackborn867ab6472010-04-29 13:28:56 -0700352 int mDockMode = Intent.EXTRA_DOCK_STATE_UNDOCKED;
Mike Lockwood1753f7f2009-08-24 14:49:07 -0700353 int mLidOpenRotation;
Mike Lockwood2d1efbd2009-09-16 12:15:53 -0400354 int mCarDockRotation;
355 int mDeskDockRotation;
Jeff Brownc82c89ed2013-04-17 17:18:15 -0700356 int mUndockedHdmiRotation;
357 int mDemoHdmiRotation;
358 boolean mDemoHdmiRotationLock;
Chong Zhangae6119ff2014-11-11 18:54:39 -0800359 int mDemoRotation;
360 boolean mDemoRotationLock;
Daniel Sandlerb73617d2010-08-17 00:41:00 -0400361
Jeff Browna20dda42014-05-27 20:57:24 -0700362 boolean mWakeGestureEnabledSetting;
363 MyWakeGestureListener mWakeGestureListener;
364
Craig Mautner46ac6fa2013-08-01 10:06:34 -0700365 // Default display does not rotate, apps that require non-default orientation will have to
366 // have the orientation emulated.
367 private boolean mForceDefaultOrientation = false;
368
Daniel Sandlerb73617d2010-08-17 00:41:00 -0400369 int mUserRotationMode = WindowManagerPolicy.USER_ROTATION_FREE;
370 int mUserRotation = Surface.ROTATION_0;
Jeff Brown207673cd2012-06-05 17:47:11 -0700371 boolean mAccelerometerDefault;
Daniel Sandlerb73617d2010-08-17 00:41:00 -0400372
Jeff Brownbcdfc622014-03-06 19:13:04 -0800373 boolean mSupportAutoRotation;
Jeff Brownd3187e32011-09-21 19:26:44 -0700374 int mAllowAllRotations = -1;
Mike Lockwoode9867d22009-09-20 01:59:02 -0400375 boolean mCarDockEnablesAccelerometer;
376 boolean mDeskDockEnablesAccelerometer;
Dianne Hackborn2862fff2009-09-15 22:56:29 -0700377 int mLidKeyboardAccessibility;
378 int mLidNavigationAccessibility;
Jeff Brownc458ce92012-04-30 14:58:40 -0700379 boolean mLidControlsSleep;
Jeff Brown13f00f02014-10-31 14:45:50 -0700380 int mShortPressOnPowerBehavior;
381 int mLongPressOnPowerBehavior;
382 int mDoublePressOnPowerBehavior;
383 int mTriplePressOnPowerBehavior;
Filip Gruszczynskia483a1d2015-03-17 19:06:58 +0000384 int mShortPressOnSleepBehavior;
Jeff Brown3ee549c2014-09-22 20:14:39 -0700385 boolean mAwake;
386 boolean mScreenOnEarly;
387 boolean mScreenOnFully;
388 ScreenOnListener mScreenOnListener;
389 boolean mKeyguardDrawComplete;
390 boolean mWindowManagerDrawComplete;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800391 boolean mOrientationSensorEnabled = false;
392 int mCurrentAppOrientation = ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800393 boolean mHasSoftInput = false;
Daniel Sandlerdd73ee42013-10-11 22:19:59 -0400394 boolean mTranslucentDecorEnabled = true;
RoboErik001c59c2015-01-26 15:53:51 -0800395 boolean mUseTvRouting;
Craig Mautner967212c2013-04-13 21:10:58 -0700396
Jeff Brown70825162012-03-28 17:27:48 -0700397 int mPointerLocationMode = 0; // guarded by mLock
Joe Onorato664644d2011-01-23 17:53:23 -0800398
399 // The last window we were told about in focusChanged.
400 WindowState mFocusedWindow;
Dianne Hackborne0f085d2011-11-30 18:41:15 -0800401 IApplicationToken mFocusedApp;
Joe Onorato664644d2011-01-23 17:53:23 -0800402
Jeff Brown70825162012-03-28 17:27:48 -0700403 PointerLocationView mPointerLocationView;
Jeff Brown32cbc38552011-12-01 14:01:49 -0800404
Dianne Hackbornc652de82013-02-15 16:32:56 -0800405 // The current size of the screen; really; extends into the overscan area of
406 // the screen and doesn't account for any system elements like the status bar.
407 int mOverscanScreenLeft, mOverscanScreenTop;
408 int mOverscanScreenWidth, mOverscanScreenHeight;
409 // The current visible size of the screen; really; (ir)regardless of whether the status
410 // bar can be hidden but not extending into the overscan area.
Joe Onorato29fc2c92010-11-24 10:26:50 -0800411 int mUnrestrictedScreenLeft, mUnrestrictedScreenTop;
412 int mUnrestrictedScreenWidth, mUnrestrictedScreenHeight;
Dianne Hackborn313440842013-02-19 19:22:59 -0800413 // Like mOverscanScreen*, but allowed to move into the overscan region where appropriate.
414 int mRestrictedOverscanScreenLeft, mRestrictedOverscanScreenTop;
415 int mRestrictedOverscanScreenWidth, mRestrictedOverscanScreenHeight;
Dianne Hackborn82de1ae2010-10-28 11:28:39 -0700416 // The current size of the screen; these may be different than (0,0)-(dw,dh)
417 // if the status bar can't be hidden; in that case it effectively carves out
418 // that area of the display from all other windows.
Joe Onorato29fc2c92010-11-24 10:26:50 -0800419 int mRestrictedScreenLeft, mRestrictedScreenTop;
420 int mRestrictedScreenWidth, mRestrictedScreenHeight;
Dianne Hackborn5c58de32012-04-28 19:52:37 -0700421 // During layout, the current screen borders accounting for any currently
422 // visible system UI elements.
423 int mSystemLeft, mSystemTop, mSystemRight, mSystemBottom;
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -0700424 // For applications requesting stable content insets, these are them.
425 int mStableLeft, mStableTop, mStableRight, mStableBottom;
Dianne Hackborn5b5cc4d2012-05-16 13:15:00 -0700426 // For applications requesting stable content insets but have also set the
427 // fullscreen window flag, these are the stable dimensions without the status bar.
428 int mStableFullscreenLeft, mStableFullscreenTop;
429 int mStableFullscreenRight, mStableFullscreenBottom;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800430 // During layout, the current screen borders with all outer decoration
431 // (status bar, input method dock) accounted for.
432 int mCurLeft, mCurTop, mCurRight, mCurBottom;
433 // During layout, the frame in which content should be displayed
434 // to the user, accounting for all screen decoration except for any
435 // space they deem as available for other content. This is usually
436 // the same as mCur*, but may be larger if the screen decor has supplied
437 // content insets.
438 int mContentLeft, mContentTop, mContentRight, mContentBottom;
Dianne Hackborne30e02f2014-05-27 18:24:45 -0700439 // During layout, the frame in which voice content should be displayed
440 // to the user, accounting for all screen decoration except for any
441 // space they deem as available for other content.
442 int mVoiceContentLeft, mVoiceContentTop, mVoiceContentRight, mVoiceContentBottom;
Dianne Hackborn8e11ef02010-11-18 19:47:42 -0800443 // During layout, the current screen borders along which input method
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800444 // windows are placed.
445 int mDockLeft, mDockTop, mDockRight, mDockBottom;
446 // During layout, the layer at which the doc window is placed.
447 int mDockLayer;
Dianne Hackborn5c58de32012-04-28 19:52:37 -0700448 // During layout, this is the layer of the status bar.
449 int mStatusBarLayer;
Dianne Hackborne26ab702011-10-16 13:21:33 -0700450 int mLastSystemUiFlags;
451 // Bits that we are in the process of clearing, so we want to prevent
452 // them from being set by applications until everything has been updated
453 // to have them clear.
454 int mResettingSystemUiFlags = 0;
455 // Bits that we are currently always keeping cleared.
456 int mForceClearedSystemUiFlags = 0;
Dianne Hackborn4eff8d32011-11-10 19:38:40 -0800457 // What we last reported to system UI about whether the compatibility
458 // menu needs to be displayed.
459 boolean mLastFocusNeedsMenu = false;
Dianne Hackborndf89e652011-10-06 22:35:11 -0700460
461 FakeWindow mHideNavFakeWindow = null;
462
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800463 static final Rect mTmpParentFrame = new Rect();
464 static final Rect mTmpDisplayFrame = new Rect();
Dianne Hackbornc4aad012013-02-22 15:05:25 -0800465 static final Rect mTmpOverscanFrame = new Rect();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800466 static final Rect mTmpContentFrame = new Rect();
467 static final Rect mTmpVisibleFrame = new Rect();
John Spurlock46646232013-09-30 22:32:42 -0400468 static final Rect mTmpDecorFrame = new Rect();
Adrian Roosfa104232014-06-20 16:10:14 -0700469 static final Rect mTmpStableFrame = new Rect();
Dianne Hackborn1f903c32011-09-13 19:18:06 -0700470 static final Rect mTmpNavigationFrame = new Rect();
Craig Mautner967212c2013-04-13 21:10:58 -0700471
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800472 WindowState mTopFullscreenOpaqueWindowState;
Adrian Rooscd3884d2015-02-18 17:25:23 +0100473 WindowState mTopFullscreenOpaqueOrDimmingWindowState;
Craig Mautner2bc789b2014-03-19 19:48:38 -0700474 HashSet<IApplicationToken> mAppsToBeHidden = new HashSet<IApplicationToken>();
Jorim Jaggic13fcac2014-09-11 17:36:57 +0200475 HashSet<IApplicationToken> mAppsThatDismissKeyguard = new HashSet<IApplicationToken>();
Joe Onorato93056472010-09-10 10:30:46 -0400476 boolean mTopIsFullscreen;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800477 boolean mForceStatusBar;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -0700478 boolean mForceStatusBarFromKeyguard;
Dianne Hackborn39c2d712009-09-22 11:41:31 -0700479 boolean mHideLockScreen;
Dianne Hackborn891d3fb2013-01-09 18:31:37 -0800480 boolean mForcingShowNavBar;
481 int mForcingShowNavBarLayer;
Craig Mautnerad09bcc2012-10-08 13:33:11 -0700482
483 // States of keyguard dismiss.
484 private static final int DISMISS_KEYGUARD_NONE = 0; // Keyguard not being dismissed.
485 private static final int DISMISS_KEYGUARD_START = 1; // Keyguard needs to be dismissed.
486 private static final int DISMISS_KEYGUARD_CONTINUE = 2; // Keyguard has been dismissed.
487 int mDismissKeyguard = DISMISS_KEYGUARD_NONE;
488
489 /** The window that is currently dismissing the keyguard. Dismissing the keyguard must only
490 * be done once per window. */
491 private WindowState mWinDismissingKeyguard;
492
Craig Mautnerc9457fa2014-06-06 14:27:48 -0700493 /** The window that is currently showing "over" the keyguard. If there is an app window
494 * belonging to another app on top of this the keyguard shows. If there is a fullscreen
495 * app window under this, still dismiss the keyguard but don't show the app underneath. Show
496 * the wallpaper. */
497 private WindowState mWinShowWhenLocked;
498
Dianne Hackborn7ad44382012-10-18 17:46:00 -0700499 boolean mShowingLockscreen;
500 boolean mShowingDream;
501 boolean mDreamingLockscreen;
Jeff Brown061ea992015-04-17 19:55:47 -0700502 boolean mDreamingSleepTokenNeeded;
503 SleepToken mDreamingSleepToken;
Jim Millerab954542014-10-10 18:21:49 -0700504 boolean mKeyguardSecure;
505 boolean mKeyguardSecureIncludingHidden;
506 volatile boolean mKeyguardOccluded;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800507 boolean mHomePressed;
Jeff Browncaca8812013-05-09 13:34:33 -0700508 boolean mHomeConsumed;
509 boolean mHomeDoubleTapPending;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800510 Intent mHomeIntent;
Dianne Hackborn39c2d712009-09-22 11:41:31 -0700511 Intent mCarDockIntent;
512 Intent mDeskDockIntent;
Jeff Brownfd23e3e2012-05-09 13:34:28 -0700513 boolean mSearchKeyShortcutPending;
514 boolean mConsumeSearchKeyUp;
Jeff Brownde7a8ea2012-06-13 18:28:57 -0700515 boolean mAssistKeyLongPressed;
Michael Wright6a62e552014-06-03 19:19:48 -0700516 boolean mPendingMetaAction;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800517
Mike Lockwood28569302010-01-28 11:54:40 -0500518 // support for activating the lock screen while the screen is on
519 boolean mAllowLockscreenWhenOn;
520 int mLockScreenTimeout;
521 boolean mLockScreenTimerActive;
522
David Brownbaf8d092010-03-08 21:52:59 -0800523 // Behavior of ENDCALL Button. (See Settings.System.END_BUTTON_BEHAVIOR.)
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800524 int mEndcallBehavior;
David Brownbaf8d092010-03-08 21:52:59 -0800525
526 // Behavior of POWER button while in-call and screen on.
527 // (See Settings.Secure.INCALL_POWER_BUTTON_BEHAVIOR.)
528 int mIncallPowerBehavior;
529
Dianne Hackbornf87d1962012-04-04 12:48:24 -0700530 Display mDisplay;
531
Dianne Hackborn9d132642011-04-21 17:26:39 -0700532 int mLandscapeRotation = 0; // default landscape rotation
533 int mSeascapeRotation = 0; // "other" landscape rotation, 180 degrees from mLandscapeRotation
534 int mPortraitRotation = 0; // default portrait rotation
535 int mUpsideDownRotation = 0; // "other" portrait rotation
Mitsuru Oshima831d0d92009-06-16 18:27:18 -0700536
Dianne Hackbornc652de82013-02-15 16:32:56 -0800537 int mOverscanLeft = 0;
538 int mOverscanTop = 0;
539 int mOverscanRight = 0;
540 int mOverscanBottom = 0;
541
Joe Onorato46b0d682010-11-22 17:37:27 -0800542 // What we do when the user long presses on home
Jeff Browncaca8812013-05-09 13:34:33 -0700543 private int mLongPressOnHomeBehavior;
544
545 // What we do when the user double-taps on home
546 private int mDoubleTapOnHomeBehavior;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800547
Bryce Lee584a4452014-10-21 15:55:55 -0700548 // Allowed theater mode wake actions
549 private boolean mAllowTheaterModeWakeFromKey;
550 private boolean mAllowTheaterModeWakeFromPowerKey;
551 private boolean mAllowTheaterModeWakeFromMotion;
Bryce Lee812d7022014-11-10 13:33:28 -0800552 private boolean mAllowTheaterModeWakeFromMotionWhenNotDreaming;
Bryce Lee584a4452014-10-21 15:55:55 -0700553 private boolean mAllowTheaterModeWakeFromCameraLens;
554 private boolean mAllowTheaterModeWakeFromLidSwitch;
555 private boolean mAllowTheaterModeWakeFromWakeGesture;
556
Bryce Leed3b28402015-03-09 15:49:13 +0000557 // Whether to support long press from power button in non-interactive mode
558 private boolean mSupportLongPressPowerWhenNonInteractive;
559
Bryce Lee55e846d2014-11-04 12:43:44 -0800560 // Whether to go to sleep entering theater mode from power button
561 private boolean mGoToSleepOnButtonPressTheaterMode;
562
Winson Chung9112ec32011-06-27 13:15:32 -0700563 // Screenshot trigger states
Jeff Brownd5bb82d2011-10-12 13:57:59 -0700564 // Time to volume and power must be pressed within this interval of each other.
565 private static final long SCREENSHOT_CHORD_DEBOUNCE_DELAY_MILLIS = 150;
Winson Chung1cea2f32012-10-08 20:42:01 -0700566 // Increase the chord delay when taking a screenshot from the keyguard
567 private static final float KEYGUARD_SCREENSHOT_CHORD_DELAY_MULTIPLIER = 2.5f;
Christopher Tatee90585f2012-03-05 18:56:25 -0800568 private boolean mScreenshotChordEnabled;
Jeff Brown13f00f02014-10-31 14:45:50 -0700569 private boolean mScreenshotChordVolumeDownKeyTriggered;
570 private long mScreenshotChordVolumeDownKeyTime;
571 private boolean mScreenshotChordVolumeDownKeyConsumed;
572 private boolean mScreenshotChordVolumeUpKeyTriggered;
573 private boolean mScreenshotChordPowerKeyTriggered;
574 private long mScreenshotChordPowerKeyTime;
Winson Chung9112ec32011-06-27 13:15:32 -0700575
Michael Wrightb854e242013-02-05 17:54:02 -0800576 /* The number of steps between min and max brightness */
577 private static final int BRIGHTNESS_STEPS = 10;
578
Christopher Tate5e08af02012-09-21 17:17:22 -0700579 SettingsObserver mSettingsObserver;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800580 ShortcutManager mShortcutManager;
581 PowerManager.WakeLock mBroadcastWakeLock;
Jeff Brown13f00f02014-10-31 14:45:50 -0700582 PowerManager.WakeLock mPowerKeyWakeLock;
Jeff Brown40013652012-05-16 21:22:36 -0700583 boolean mHavePendingMediaKeyRepeatWithWakeLock;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800584
Craig Mautnerd625ab22013-09-06 13:40:31 -0700585 private int mCurrentUserId;
586
Justin Kohd378ad72013-04-01 12:18:26 -0700587 // Maps global key codes to the components that will handle them.
588 private GlobalKeyManager mGlobalKeyManager;
589
Jeff Brownfd23e3e2012-05-09 13:34:28 -0700590 // Fallback actions by key code.
591 private final SparseArray<KeyCharacterMap.FallbackAction> mFallbackActions =
592 new SparseArray<KeyCharacterMap.FallbackAction>();
Jeff Brown49ed71d2010-12-06 17:13:33 -0800593
Jorim Jaggi76a16232014-08-08 17:00:47 +0200594 private final LogDecelerateInterpolator mLogDecelerateInterpolator
595 = new LogDecelerateInterpolator(100, 0);
596
Jeff Brown70825162012-03-28 17:27:48 -0700597 private static final int MSG_ENABLE_POINTER_LOCATION = 1;
598 private static final int MSG_DISABLE_POINTER_LOCATION = 2;
Jeff Brown40013652012-05-16 21:22:36 -0700599 private static final int MSG_DISPATCH_MEDIA_KEY_WITH_WAKE_LOCK = 3;
600 private static final int MSG_DISPATCH_MEDIA_KEY_REPEAT_WITH_WAKE_LOCK = 4;
Craig Mautner8a0da012014-05-31 15:13:37 -0700601 private static final int MSG_KEYGUARD_DRAWN_COMPLETE = 5;
602 private static final int MSG_KEYGUARD_DRAWN_TIMEOUT = 6;
603 private static final int MSG_WINDOW_MANAGER_DRAWN_COMPLETE = 7;
Craig Mautner84984fa2014-06-19 11:19:20 -0700604 private static final int MSG_DISPATCH_SHOW_RECENTS = 9;
Alan Viverettee34560b22014-07-10 14:50:06 -0700605 private static final int MSG_DISPATCH_SHOW_GLOBAL_ACTIONS = 10;
Craig Mautnera631d492014-08-05 15:16:01 -0700606 private static final int MSG_HIDE_BOOT_MESSAGE = 11;
Michael Wright869a67c2014-08-26 19:33:06 -0700607 private static final int MSG_LAUNCH_VOICE_ASSIST_WITH_WAKE_LOCK = 12;
Jeff Brown13f00f02014-10-31 14:45:50 -0700608 private static final int MSG_POWER_DELAYED_PRESS = 13;
609 private static final int MSG_POWER_LONG_PRESS = 14;
Jeff Brown061ea992015-04-17 19:55:47 -0700610 private static final int MSG_UPDATE_DREAMING_SLEEP_TOKEN = 15;
Jeff Brown70825162012-03-28 17:27:48 -0700611
612 private class PolicyHandler extends Handler {
613 @Override
614 public void handleMessage(Message msg) {
615 switch (msg.what) {
616 case MSG_ENABLE_POINTER_LOCATION:
617 enablePointerLocation();
618 break;
619 case MSG_DISABLE_POINTER_LOCATION:
620 disablePointerLocation();
621 break;
Jeff Brown40013652012-05-16 21:22:36 -0700622 case MSG_DISPATCH_MEDIA_KEY_WITH_WAKE_LOCK:
623 dispatchMediaKeyWithWakeLock((KeyEvent)msg.obj);
624 break;
625 case MSG_DISPATCH_MEDIA_KEY_REPEAT_WITH_WAKE_LOCK:
626 dispatchMediaKeyRepeatWithWakeLock((KeyEvent)msg.obj);
627 break;
Craig Mautner84984fa2014-06-19 11:19:20 -0700628 case MSG_DISPATCH_SHOW_RECENTS:
629 showRecentApps(false);
630 break;
Alan Viverettee34560b22014-07-10 14:50:06 -0700631 case MSG_DISPATCH_SHOW_GLOBAL_ACTIONS:
632 showGlobalActionsInternal();
633 break;
Craig Mautner8a0da012014-05-31 15:13:37 -0700634 case MSG_KEYGUARD_DRAWN_COMPLETE:
635 if (DEBUG_WAKEUP) Slog.w(TAG, "Setting mKeyguardDrawComplete");
Jeff Brown36c4db82014-09-19 12:05:31 -0700636 finishKeyguardDrawn();
Craig Mautner8a0da012014-05-31 15:13:37 -0700637 break;
638 case MSG_KEYGUARD_DRAWN_TIMEOUT:
639 Slog.w(TAG, "Keyguard drawn timeout. Setting mKeyguardDrawComplete");
Jeff Brown36c4db82014-09-19 12:05:31 -0700640 finishKeyguardDrawn();
Craig Mautner8a0da012014-05-31 15:13:37 -0700641 break;
642 case MSG_WINDOW_MANAGER_DRAWN_COMPLETE:
643 if (DEBUG_WAKEUP) Slog.w(TAG, "Setting mWindowManagerDrawComplete");
Jeff Brown36c4db82014-09-19 12:05:31 -0700644 finishWindowsDrawn();
Craig Mautner8a0da012014-05-31 15:13:37 -0700645 break;
Craig Mautnera631d492014-08-05 15:16:01 -0700646 case MSG_HIDE_BOOT_MESSAGE:
647 handleHideBootMessage();
648 break;
Michael Wright869a67c2014-08-26 19:33:06 -0700649 case MSG_LAUNCH_VOICE_ASSIST_WITH_WAKE_LOCK:
650 launchVoiceAssistWithWakeLock(msg.arg1 != 0);
651 break;
Jeff Brown13f00f02014-10-31 14:45:50 -0700652 case MSG_POWER_DELAYED_PRESS:
653 powerPress((Long)msg.obj, msg.arg1 != 0, msg.arg2);
654 finishPowerKeyPress();
655 break;
656 case MSG_POWER_LONG_PRESS:
657 powerLongPress();
658 break;
Jeff Brown061ea992015-04-17 19:55:47 -0700659 case MSG_UPDATE_DREAMING_SLEEP_TOKEN:
660 updateDreamingSleepToken(msg.arg1 != 0);
661 break;
Jeff Brown70825162012-03-28 17:27:48 -0700662 }
663 }
664 }
665
Dianne Hackbornad7fa7f2011-01-07 14:06:50 -0800666 private UEventObserver mHDMIObserver = new UEventObserver() {
667 @Override
668 public void onUEvent(UEventObserver.UEvent event) {
669 setHdmiPlugged("1".equals(event.get("SWITCH_STATE")));
670 }
671 };
672
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800673 class SettingsObserver extends ContentObserver {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800674 SettingsObserver(Handler handler) {
675 super(handler);
676 }
David Brownbaf8d092010-03-08 21:52:59 -0800677
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800678 void observe() {
Christopher Tate5e08af02012-09-21 17:17:22 -0700679 // Observe all users' changes
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800680 ContentResolver resolver = mContext.getContentResolver();
681 resolver.registerContentObserver(Settings.System.getUriFor(
Christopher Tate5e08af02012-09-21 17:17:22 -0700682 Settings.System.END_BUTTON_BEHAVIOR), false, this,
683 UserHandle.USER_ALL);
David Brownbaf8d092010-03-08 21:52:59 -0800684 resolver.registerContentObserver(Settings.Secure.getUriFor(
Christopher Tate5e08af02012-09-21 17:17:22 -0700685 Settings.Secure.INCALL_POWER_BUTTON_BEHAVIOR), false, this,
686 UserHandle.USER_ALL);
Jeff Browna20dda42014-05-27 20:57:24 -0700687 resolver.registerContentObserver(Settings.Secure.getUriFor(
688 Settings.Secure.WAKE_GESTURE_ENABLED), false, this,
689 UserHandle.USER_ALL);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800690 resolver.registerContentObserver(Settings.System.getUriFor(
Christopher Tate5e08af02012-09-21 17:17:22 -0700691 Settings.System.ACCELEROMETER_ROTATION), false, this,
692 UserHandle.USER_ALL);
Mike Lockwood28569302010-01-28 11:54:40 -0500693 resolver.registerContentObserver(Settings.System.getUriFor(
Christopher Tate5e08af02012-09-21 17:17:22 -0700694 Settings.System.USER_ROTATION), false, this,
695 UserHandle.USER_ALL);
Daniel Sandlerb73617d2010-08-17 00:41:00 -0400696 resolver.registerContentObserver(Settings.System.getUriFor(
Christopher Tate5e08af02012-09-21 17:17:22 -0700697 Settings.System.SCREEN_OFF_TIMEOUT), false, this,
698 UserHandle.USER_ALL);
Dianne Hackbornc777e072010-02-12 13:07:59 -0800699 resolver.registerContentObserver(Settings.System.getUriFor(
Christopher Tate5e08af02012-09-21 17:17:22 -0700700 Settings.System.POINTER_LOCATION), false, this,
701 UserHandle.USER_ALL);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800702 resolver.registerContentObserver(Settings.Secure.getUriFor(
Christopher Tate5e08af02012-09-21 17:17:22 -0700703 Settings.Secure.DEFAULT_INPUT_METHOD), false, this,
704 UserHandle.USER_ALL);
John Spurlockd9b70bd2014-02-06 17:02:44 -0500705 resolver.registerContentObserver(Settings.Secure.getUriFor(
John Spurlockf1a36642013-10-12 17:50:42 -0400706 Settings.Secure.IMMERSIVE_MODE_CONFIRMATIONS), false, this,
Christopher Tate5e08af02012-09-21 17:17:22 -0700707 UserHandle.USER_ALL);
John Spurlockc6d1c602014-01-17 15:22:06 -0500708 resolver.registerContentObserver(Settings.Global.getUriFor(
709 Settings.Global.POLICY_CONTROL), false, this,
710 UserHandle.USER_ALL);
Dianne Hackbornc777e072010-02-12 13:07:59 -0800711 updateSettings();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800712 }
713
714 @Override public void onChange(boolean selfChange) {
Dianne Hackbornc777e072010-02-12 13:07:59 -0800715 updateSettings();
Jeff Brown01a98dd2011-09-20 15:08:29 -0700716 updateRotation(false);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800717 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800718 }
Craig Mautner967212c2013-04-13 21:10:58 -0700719
Jeff Browna20dda42014-05-27 20:57:24 -0700720 class MyWakeGestureListener extends WakeGestureListener {
721 MyWakeGestureListener(Context context, Handler handler) {
722 super(context, handler);
723 }
724
725 @Override
726 public void onWakeUp() {
727 synchronized (mLock) {
728 if (shouldEnableWakeGestureLp()) {
Jeff Browne07b94b2014-06-18 15:56:27 -0700729 performHapticFeedbackLw(null, HapticFeedbackConstants.VIRTUAL_KEY, false);
Bryce Lee584a4452014-10-21 15:55:55 -0700730 wakeUp(SystemClock.uptimeMillis(), mAllowTheaterModeWakeFromWakeGesture);
Jeff Browna20dda42014-05-27 20:57:24 -0700731 }
732 }
733 }
734 }
735
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800736 class MyOrientationListener extends WindowOrientationListener {
Craig Mautnereee29c42013-01-17 14:44:34 -0800737 MyOrientationListener(Context context, Handler handler) {
738 super(context, handler);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800739 }
Craig Mautner967212c2013-04-13 21:10:58 -0700740
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800741 @Override
Jeff Brownc0347aa2011-09-23 17:26:09 -0700742 public void onProposedRotationChanged(int rotation) {
Craig Mautnereda67292013-04-28 13:50:14 -0700743 if (localLOGV) Slog.v(TAG, "onProposedRotationChanged, rotation=" + rotation);
Jeff Brown01a98dd2011-09-20 15:08:29 -0700744 updateRotation(false);
745 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800746 }
747 MyOrientationListener mOrientationListener;
748
Jorim Jaggi24bec7c2015-02-04 12:40:14 +0100749 private final StatusBarController mStatusBarController = new StatusBarController();
John Spurlock5b9145b2013-08-20 15:13:47 -0400750
John Spurlock27735a42013-08-14 17:57:38 -0400751 private final BarController mNavigationBarController = new BarController("NavigationBar",
John Spurlock5b9145b2013-08-20 15:13:47 -0400752 View.NAVIGATION_BAR_TRANSIENT,
753 View.NAVIGATION_BAR_UNHIDE,
John Spurlockbd957402013-10-03 11:38:39 -0400754 View.NAVIGATION_BAR_TRANSLUCENT,
755 StatusBarManager.WINDOW_NAVIGATION_BAR,
756 WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION);
John Spurlock5b9145b2013-08-20 15:13:47 -0400757
John Spurlockf1a36642013-10-12 17:50:42 -0400758 private ImmersiveModeConfirmation mImmersiveModeConfirmation;
John Spurlock32beb2c2013-03-11 10:16:47 -0400759
Craig Mautner037aa8d2013-06-07 10:35:44 -0700760 private SystemGesturesPointerEventListener mSystemGestures;
John Spurlock32beb2c2013-03-11 10:16:47 -0400761
Dianne Hackborn42e620c2012-06-24 13:20:51 -0700762 IStatusBarService getStatusBarService() {
763 synchronized (mServiceAquireLock) {
764 if (mStatusBarService == null) {
765 mStatusBarService = IStatusBarService.Stub.asInterface(
766 ServiceManager.getService("statusbar"));
767 }
768 return mStatusBarService;
769 }
770 }
771
Suchi Amalapurapua9e1b162009-03-24 22:24:47 -0700772 /*
773 * We always let the sensor be switched on by default except when
774 * the user has explicitly disabled sensor based rotation or when the
775 * screen is switched off.
776 */
The Android Open Source Project0727d222009-03-11 12:11:58 -0700777 boolean needSensorRunningLp() {
Jeff Brownbcdfc622014-03-06 19:13:04 -0800778 if (mSupportAutoRotation) {
779 if (mCurrentAppOrientation == ActivityInfo.SCREEN_ORIENTATION_SENSOR
780 || mCurrentAppOrientation == ActivityInfo.SCREEN_ORIENTATION_FULL_SENSOR
781 || mCurrentAppOrientation == ActivityInfo.SCREEN_ORIENTATION_SENSOR_PORTRAIT
782 || mCurrentAppOrientation == ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE) {
783 // If the application has explicitly requested to follow the
784 // orientation, then we need to turn the sensor on.
785 return true;
786 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800787 }
Dianne Hackborn867ab6472010-04-29 13:28:56 -0700788 if ((mCarDockEnablesAccelerometer && mDockMode == Intent.EXTRA_DOCK_STATE_CAR) ||
Jeff Brown1a693182011-11-08 14:44:16 -0800789 (mDeskDockEnablesAccelerometer && (mDockMode == Intent.EXTRA_DOCK_STATE_DESK
790 || mDockMode == Intent.EXTRA_DOCK_STATE_LE_DESK
791 || mDockMode == Intent.EXTRA_DOCK_STATE_HE_DESK))) {
Mike Lockwoode9867d22009-09-20 01:59:02 -0400792 // enable accelerometer if we are docked in a dock that enables accelerometer
793 // orientation management,
794 return true;
795 }
Jeff Brown207673cd2012-06-05 17:47:11 -0700796 if (mUserRotationMode == USER_ROTATION_LOCKED) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800797 // If the setting for using the sensor by default is enabled, then
798 // we will always leave it on. Note that the user could go to
799 // a window that forces an orientation that does not use the
800 // sensor and in theory we could turn it off... however, when next
801 // turning it on we won't have a good value for the current
802 // orientation for a little bit, which can cause orientation
803 // changes to lag, so we'd like to keep it always on. (It will
804 // still be turned off when the screen is off.)
Suchi Amalapurapua9e1b162009-03-24 22:24:47 -0700805 return false;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800806 }
Jeff Brownbcdfc622014-03-06 19:13:04 -0800807 return mSupportAutoRotation;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800808 }
Craig Mautner46ac6fa2013-08-01 10:06:34 -0700809
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800810 /*
811 * Various use cases for invoking this function
812 * screen turning off, should always disable listeners if already enabled
Craig Mautner46ac6fa2013-08-01 10:06:34 -0700813 * screen turned on and current app has sensor based orientation, enable listeners
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800814 * if not already enabled
815 * screen turned on and current app does not have sensor orientation, disable listeners if
816 * already enabled
817 * screen turning on and current app has sensor based orientation, enable listeners if needed
818 * screen turning on and current app has nosensor based orientation, do nothing
819 */
The Android Open Source Project0727d222009-03-11 12:11:58 -0700820 void updateOrientationListenerLp() {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800821 if (!mOrientationListener.canDetectOrientation()) {
822 // If sensor is turned off or nonexistent for some reason
823 return;
824 }
825 //Could have been invoked due to screen turning on or off or
826 //change of the currently visible window's orientation
Jeff Brown3ee549c2014-09-22 20:14:39 -0700827 if (localLOGV) Slog.v(TAG, "mScreenOnEarly=" + mScreenOnEarly
828 + ", mAwake=" + mAwake + ", mCurrentAppOrientation=" + mCurrentAppOrientation
829 + ", mOrientationSensorEnabled=" + mOrientationSensorEnabled);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800830 boolean disable = true;
Jeff Brown3ee549c2014-09-22 20:14:39 -0700831 if (mScreenOnEarly && mAwake) {
The Android Open Source Project0727d222009-03-11 12:11:58 -0700832 if (needSensorRunningLp()) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800833 disable = false;
834 //enable listener if not already enabled
The Android Open Source Project0727d222009-03-11 12:11:58 -0700835 if (!mOrientationSensorEnabled) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800836 mOrientationListener.enable();
Craig Mautnereda67292013-04-28 13:50:14 -0700837 if(localLOGV) Slog.v(TAG, "Enabling listeners");
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800838 mOrientationSensorEnabled = true;
839 }
Craig Mautner46ac6fa2013-08-01 10:06:34 -0700840 }
841 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800842 //check if sensors need to be disabled
The Android Open Source Project0727d222009-03-11 12:11:58 -0700843 if (disable && mOrientationSensorEnabled) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800844 mOrientationListener.disable();
Craig Mautnereda67292013-04-28 13:50:14 -0700845 if(localLOGV) Slog.v(TAG, "Disabling listeners");
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800846 mOrientationSensorEnabled = false;
847 }
848 }
849
Jeff Brown13f00f02014-10-31 14:45:50 -0700850 private void interceptPowerKeyDown(KeyEvent event, boolean interactive) {
851 // Hold a wake lock until the power key is released.
852 if (!mPowerKeyWakeLock.isHeld()) {
853 mPowerKeyWakeLock.acquire();
854 }
855
856 // Cancel multi-press detection timeout.
857 if (mPowerKeyPressCounter != 0) {
858 mHandler.removeMessages(MSG_POWER_DELAYED_PRESS);
859 }
860
861 // Detect user pressing the power button in panic when an application has
862 // taken over the whole screen.
863 boolean panic = mImmersiveModeConfirmation.onPowerKeyDown(interactive,
Craig Mautner0124980e92014-11-30 21:15:34 -0800864 SystemClock.elapsedRealtime(), isImmersiveMode(mLastSystemUiFlags));
Jeff Brown13f00f02014-10-31 14:45:50 -0700865 if (panic) {
866 mHandler.post(mRequestTransientNav);
867 }
868
869 // Latch power key state to detect screenshot chord.
870 if (interactive && !mScreenshotChordPowerKeyTriggered
871 && (event.getFlags() & KeyEvent.FLAG_FALLBACK) == 0) {
872 mScreenshotChordPowerKeyTriggered = true;
873 mScreenshotChordPowerKeyTime = event.getDownTime();
874 interceptScreenshotChord();
875 }
876
877 // Stop ringing or end call if configured to do so when power is pressed.
878 TelecomManager telecomManager = getTelecommService();
879 boolean hungUp = false;
880 if (telecomManager != null) {
881 if (telecomManager.isRinging()) {
882 // Pressing Power while there's a ringing incoming
883 // call should silence the ringer.
884 telecomManager.silenceRinger();
885 } else if ((mIncallPowerBehavior
886 & Settings.Secure.INCALL_POWER_BUTTON_BEHAVIOR_HANGUP) != 0
887 && telecomManager.isInCall() && interactive) {
888 // Otherwise, if "Power button ends call" is enabled,
889 // the Power button will hang up any current active call.
890 hungUp = telecomManager.endCall();
891 }
892 }
893
894 // If the power key has still not yet been handled, then detect short
895 // press, long press, or multi press and decide what to do.
896 mPowerKeyHandled = hungUp || mScreenshotChordVolumeDownKeyTriggered
897 || mScreenshotChordVolumeUpKeyTriggered;
898 if (!mPowerKeyHandled) {
899 if (interactive) {
900 // When interactive, we're already awake.
901 // Wait for a long press or for the button to be released to decide what to do.
902 if (hasLongPressOnPowerBehavior()) {
903 Message msg = mHandler.obtainMessage(MSG_POWER_LONG_PRESS);
904 msg.setAsynchronous(true);
905 mHandler.sendMessageDelayed(msg,
906 ViewConfiguration.get(mContext).getDeviceGlobalActionKeyTimeout());
907 }
908 } else {
Bryce Leed9268e32014-11-17 17:40:59 -0800909 wakeUpFromPowerKey(event.getDownTime());
Bryce Leed9268e32014-11-17 17:40:59 -0800910
Bryce Leed3b28402015-03-09 15:49:13 +0000911 if (mSupportLongPressPowerWhenNonInteractive && hasLongPressOnPowerBehavior()) {
912 Message msg = mHandler.obtainMessage(MSG_POWER_LONG_PRESS);
913 msg.setAsynchronous(true);
914 mHandler.sendMessageDelayed(msg,
915 ViewConfiguration.get(mContext).getDeviceGlobalActionKeyTimeout());
Bryce Leed9268e32014-11-17 17:40:59 -0800916 mBeganFromNonInteractive = true;
Bryce Leed3b28402015-03-09 15:49:13 +0000917 } else {
918 final int maxCount = getMaxMultiPressPowerCount();
919
920 if (maxCount <= 1) {
921 mPowerKeyHandled = true;
922 } else {
923 mBeganFromNonInteractive = true;
924 }
Jeff Brown13f00f02014-10-31 14:45:50 -0700925 }
926 }
Jeff Brown4d396052010-10-29 21:50:21 -0700927 }
928 }
929
Jeff Brown13f00f02014-10-31 14:45:50 -0700930 private void interceptPowerKeyUp(KeyEvent event, boolean interactive, boolean canceled) {
931 final boolean handled = canceled || mPowerKeyHandled;
932 mScreenshotChordPowerKeyTriggered = false;
933 cancelPendingScreenshotChordAction();
934 cancelPendingPowerKeyAction();
935
936 if (!handled) {
937 // Figure out how to handle the key now that it has been released.
938 mPowerKeyPressCounter += 1;
939
940 final int maxCount = getMaxMultiPressPowerCount();
941 final long eventTime = event.getDownTime();
942 if (mPowerKeyPressCounter < maxCount) {
943 // This could be a multi-press. Wait a little bit longer to confirm.
944 // Continue holding the wake lock.
945 Message msg = mHandler.obtainMessage(MSG_POWER_DELAYED_PRESS,
946 interactive ? 1 : 0, mPowerKeyPressCounter, eventTime);
947 msg.setAsynchronous(true);
948 mHandler.sendMessageDelayed(msg, ViewConfiguration.getDoubleTapTimeout());
949 return;
950 }
951
952 // No other actions. Handle it immediately.
953 powerPress(eventTime, interactive, mPowerKeyPressCounter);
Jeff Brown4d396052010-10-29 21:50:21 -0700954 }
Jeff Brown13f00f02014-10-31 14:45:50 -0700955
956 // Done. Reset our state.
957 finishPowerKeyPress();
958 }
959
960 private void finishPowerKeyPress() {
Bryce Leed9268e32014-11-17 17:40:59 -0800961 mBeganFromNonInteractive = false;
Jeff Brown13f00f02014-10-31 14:45:50 -0700962 mPowerKeyPressCounter = 0;
963 if (mPowerKeyWakeLock.isHeld()) {
964 mPowerKeyWakeLock.release();
965 }
Jeff Brownd5bb82d2011-10-12 13:57:59 -0700966 }
967
968 private void cancelPendingPowerKeyAction() {
969 if (!mPowerKeyHandled) {
Jeff Brown13f00f02014-10-31 14:45:50 -0700970 mPowerKeyHandled = true;
971 mHandler.removeMessages(MSG_POWER_LONG_PRESS);
Jeff Brownd5bb82d2011-10-12 13:57:59 -0700972 }
Jeff Brown13f00f02014-10-31 14:45:50 -0700973 }
974
975 private void powerPress(long eventTime, boolean interactive, int count) {
976 if (mScreenOnEarly && !mScreenOnFully) {
977 Slog.i(TAG, "Suppressed redundant power key press while "
978 + "already in the process of turning the screen on.");
979 return;
Jeff Brownff204712011-10-25 21:27:54 -0700980 }
Jeff Brown13f00f02014-10-31 14:45:50 -0700981
982 if (count == 2) {
983 powerMultiPressAction(eventTime, interactive, mDoublePressOnPowerBehavior);
984 } else if (count == 3) {
985 powerMultiPressAction(eventTime, interactive, mTriplePressOnPowerBehavior);
Bryce Leed9268e32014-11-17 17:40:59 -0800986 } else if (interactive && !mBeganFromNonInteractive) {
Jeff Brown13f00f02014-10-31 14:45:50 -0700987 switch (mShortPressOnPowerBehavior) {
988 case SHORT_PRESS_POWER_NOTHING:
989 break;
990 case SHORT_PRESS_POWER_GO_TO_SLEEP:
991 mPowerManager.goToSleep(eventTime,
992 PowerManager.GO_TO_SLEEP_REASON_POWER_BUTTON, 0);
993 break;
994 case SHORT_PRESS_POWER_REALLY_GO_TO_SLEEP:
995 mPowerManager.goToSleep(eventTime,
996 PowerManager.GO_TO_SLEEP_REASON_POWER_BUTTON,
997 PowerManager.GO_TO_SLEEP_FLAG_NO_DOZE);
998 break;
999 case SHORT_PRESS_POWER_REALLY_GO_TO_SLEEP_AND_GO_HOME:
1000 mPowerManager.goToSleep(eventTime,
1001 PowerManager.GO_TO_SLEEP_REASON_POWER_BUTTON,
1002 PowerManager.GO_TO_SLEEP_FLAG_NO_DOZE);
1003 launchHomeFromHotKey();
1004 break;
Bryce Lee01b0c5f2015-02-05 18:24:04 -08001005 case SHORT_PRESS_POWER_GO_HOME:
Bryce Lee662ed802015-04-10 20:11:39 +00001006 launchHomeFromHotKey(true /* awakenFromDreams */, false /*respectKeyguard*/);
Bryce Lee01b0c5f2015-02-05 18:24:04 -08001007 break;
Jeff Brown13f00f02014-10-31 14:45:50 -07001008 }
1009 }
1010 }
1011
1012 private void powerMultiPressAction(long eventTime, boolean interactive, int behavior) {
1013 switch (behavior) {
1014 case MULTI_PRESS_POWER_NOTHING:
1015 break;
1016 case MULTI_PRESS_POWER_THEATER_MODE:
1017 if (isTheaterModeEnabled()) {
1018 Slog.i(TAG, "Toggling theater mode off.");
1019 Settings.Global.putInt(mContext.getContentResolver(),
1020 Settings.Global.THEATER_MODE_ON, 0);
1021 if (!interactive) {
1022 wakeUpFromPowerKey(eventTime);
1023 }
1024 } else {
1025 Slog.i(TAG, "Toggling theater mode on.");
1026 Settings.Global.putInt(mContext.getContentResolver(),
1027 Settings.Global.THEATER_MODE_ON, 1);
Bryce Lee55e846d2014-11-04 12:43:44 -08001028
1029 if (mGoToSleepOnButtonPressTheaterMode && interactive) {
Jeff Brown13f00f02014-10-31 14:45:50 -07001030 mPowerManager.goToSleep(eventTime,
1031 PowerManager.GO_TO_SLEEP_REASON_POWER_BUTTON, 0);
1032 }
1033 }
1034 break;
1035 case MULTI_PRESS_POWER_BRIGHTNESS_BOOST:
Jeff Brown7b5be5e2014-11-12 18:45:31 -08001036 Slog.i(TAG, "Starting brightness boost.");
1037 if (!interactive) {
1038 wakeUpFromPowerKey(eventTime);
1039 }
Jeff Brown13f00f02014-10-31 14:45:50 -07001040 mPowerManager.boostScreenBrightness(eventTime);
1041 break;
1042 }
1043 }
1044
1045 private int getMaxMultiPressPowerCount() {
1046 if (mTriplePressOnPowerBehavior != MULTI_PRESS_POWER_NOTHING) {
1047 return 3;
1048 }
1049 if (mDoublePressOnPowerBehavior != MULTI_PRESS_POWER_NOTHING) {
1050 return 2;
1051 }
1052 return 1;
1053 }
1054
1055 private void powerLongPress() {
1056 final int behavior = getResolvedLongPressOnPowerBehavior();
1057 switch (behavior) {
1058 case LONG_PRESS_POWER_NOTHING:
1059 break;
1060 case LONG_PRESS_POWER_GLOBAL_ACTIONS:
1061 mPowerKeyHandled = true;
1062 if (!performHapticFeedbackLw(null, HapticFeedbackConstants.LONG_PRESS, false)) {
1063 performAuditoryFeedbackForAccessibilityIfNeed();
1064 }
1065 showGlobalActionsInternal();
1066 break;
1067 case LONG_PRESS_POWER_SHUT_OFF:
1068 case LONG_PRESS_POWER_SHUT_OFF_NO_CONFIRM:
1069 mPowerKeyHandled = true;
1070 performHapticFeedbackLw(null, HapticFeedbackConstants.LONG_PRESS, false);
1071 sendCloseSystemWindows(SYSTEM_DIALOG_REASON_GLOBAL_ACTIONS);
1072 mWindowManagerFuncs.shutdown(behavior == LONG_PRESS_POWER_SHUT_OFF);
1073 break;
1074 }
1075 }
1076
Filip Gruszczynskia483a1d2015-03-17 19:06:58 +00001077 private void sleepPress(KeyEvent event) {
1078 switch (mShortPressOnSleepBehavior) {
1079 case SHORT_PRESS_SLEEP_GO_TO_SLEEP:
1080 mPowerManager.goToSleep(event.getEventTime(),
1081 PowerManager.GO_TO_SLEEP_REASON_SLEEP_BUTTON, 0);
1082 break;
1083 case SHORT_PRESS_SLEEP_GO_TO_SLEEP_AND_GO_HOME:
Bryce Lee662ed802015-04-10 20:11:39 +00001084 launchHomeFromHotKey(false /* awakenDreams */, true /*respectKeyguard*/);
Filip Gruszczynskia483a1d2015-03-17 19:06:58 +00001085 mPowerManager.goToSleep(event.getEventTime(),
1086 PowerManager.GO_TO_SLEEP_REASON_SLEEP_BUTTON, 0);
1087 break;
1088 }
1089 }
1090
Jeff Brown13f00f02014-10-31 14:45:50 -07001091 private int getResolvedLongPressOnPowerBehavior() {
1092 if (FactoryTest.isLongPressOnPowerOffEnabled()) {
1093 return LONG_PRESS_POWER_SHUT_OFF_NO_CONFIRM;
1094 }
1095 return mLongPressOnPowerBehavior;
1096 }
1097
1098 private boolean hasLongPressOnPowerBehavior() {
1099 return getResolvedLongPressOnPowerBehavior() != LONG_PRESS_POWER_NOTHING;
Jeff Brownd5bb82d2011-10-12 13:57:59 -07001100 }
1101
1102 private void interceptScreenshotChord() {
Christopher Tatee90585f2012-03-05 18:56:25 -08001103 if (mScreenshotChordEnabled
Jeff Brown13f00f02014-10-31 14:45:50 -07001104 && mScreenshotChordVolumeDownKeyTriggered && mScreenshotChordPowerKeyTriggered
1105 && !mScreenshotChordVolumeUpKeyTriggered) {
Jeff Brownd5bb82d2011-10-12 13:57:59 -07001106 final long now = SystemClock.uptimeMillis();
Jeff Brown13f00f02014-10-31 14:45:50 -07001107 if (now <= mScreenshotChordVolumeDownKeyTime + SCREENSHOT_CHORD_DEBOUNCE_DELAY_MILLIS
1108 && now <= mScreenshotChordPowerKeyTime
1109 + SCREENSHOT_CHORD_DEBOUNCE_DELAY_MILLIS) {
1110 mScreenshotChordVolumeDownKeyConsumed = true;
Jeff Brownd5bb82d2011-10-12 13:57:59 -07001111 cancelPendingPowerKeyAction();
1112
Jeff Sharkey2991fa32012-12-05 18:06:43 -08001113 mHandler.postDelayed(mScreenshotRunnable, getScreenshotChordLongPressDelay());
Jeff Brownd5bb82d2011-10-12 13:57:59 -07001114 }
1115 }
1116 }
1117
Winson Chung1cea2f32012-10-08 20:42:01 -07001118 private long getScreenshotChordLongPressDelay() {
Jim Miller5ecd8112013-01-09 18:50:26 -08001119 if (mKeyguardDelegate.isShowing()) {
Winson Chung1cea2f32012-10-08 20:42:01 -07001120 // Double the time it takes to take a screenshot from the keyguard
1121 return (long) (KEYGUARD_SCREENSHOT_CHORD_DELAY_MULTIPLIER *
Justin Kohfeabd2c2014-05-02 10:02:44 -07001122 ViewConfiguration.get(mContext).getDeviceGlobalActionKeyTimeout());
Winson Chung1cea2f32012-10-08 20:42:01 -07001123 }
Justin Kohfeabd2c2014-05-02 10:02:44 -07001124 return ViewConfiguration.get(mContext).getDeviceGlobalActionKeyTimeout();
Winson Chung1cea2f32012-10-08 20:42:01 -07001125 }
1126
Jeff Brownd5bb82d2011-10-12 13:57:59 -07001127 private void cancelPendingScreenshotChordAction() {
Jeff Sharkey2991fa32012-12-05 18:06:43 -08001128 mHandler.removeCallbacks(mScreenshotRunnable);
Jeff Brown4d396052010-10-29 21:50:21 -07001129 }
1130
Jeff Brown13f00f02014-10-31 14:45:50 -07001131 private final Runnable mEndCallLongPress = new Runnable() {
Craig Mautnerf1b67412012-09-19 13:18:29 -07001132 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001133 public void run() {
Jeff Brown13f00f02014-10-31 14:45:50 -07001134 mEndCallKeyHandled = true;
1135 if (!performHapticFeedbackLw(null, HapticFeedbackConstants.LONG_PRESS, false)) {
1136 performAuditoryFeedbackForAccessibilityIfNeed();
Joe Onoratod208e702010-10-08 16:22:43 -04001137 }
Jeff Brown13f00f02014-10-31 14:45:50 -07001138 showGlobalActionsInternal();
Jeff Brownd5bb82d2011-10-12 13:57:59 -07001139 }
1140 };
1141
Jeff Sharkey2991fa32012-12-05 18:06:43 -08001142 private final Runnable mScreenshotRunnable = new Runnable() {
Craig Mautner0bf6ec92012-12-18 08:33:27 -08001143 @Override
Jeff Brownd5bb82d2011-10-12 13:57:59 -07001144 public void run() {
1145 takeScreenshot();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001146 }
1147 };
1148
Alan Viverettee34560b22014-07-10 14:50:06 -07001149 @Override
1150 public void showGlobalActions() {
1151 mHandler.removeMessages(MSG_DISPATCH_SHOW_GLOBAL_ACTIONS);
1152 mHandler.sendEmptyMessage(MSG_DISPATCH_SHOW_GLOBAL_ACTIONS);
1153 }
1154
1155 void showGlobalActionsInternal() {
1156 sendCloseSystemWindows(SYSTEM_DIALOG_REASON_GLOBAL_ACTIONS);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001157 if (mGlobalActions == null) {
Jeff Brown7304c342012-05-11 18:42:42 -07001158 mGlobalActions = new GlobalActions(mContext, mWindowManagerFuncs);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001159 }
Jim Millerab954542014-10-10 18:21:49 -07001160 final boolean keyguardShowing = isKeyguardShowingAndNotOccluded();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001161 mGlobalActions.showDialog(keyguardShowing, isDeviceProvisioned());
1162 if (keyguardShowing) {
1163 // since it took two seconds of long press to bring this up,
1164 // poke the wake lock so they have some time to see the dialog.
Jim Miller25190572013-02-28 17:36:24 -08001165 mPowerManager.userActivity(SystemClock.uptimeMillis(), false);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001166 }
1167 }
1168
1169 boolean isDeviceProvisioned() {
Jeff Brownbf6f6f92012-09-25 15:03:20 -07001170 return Settings.Global.getInt(
1171 mContext.getContentResolver(), Settings.Global.DEVICE_PROVISIONED, 0) != 0;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001172 }
1173
Maurice Lam99c6e072014-04-28 18:24:28 -07001174 boolean isUserSetupComplete() {
1175 return Settings.Secure.getIntForUser(mContext.getContentResolver(),
1176 Settings.Secure.USER_SETUP_COMPLETE, 0, UserHandle.USER_CURRENT) != 0;
1177 }
1178
Jeff Brown13f00f02014-10-31 14:45:50 -07001179 private void handleShortPressOnHome() {
1180 // If there's a dream running then use home to escape the dream
1181 // but don't actually go home.
1182 if (mDreamManagerInternal != null && mDreamManagerInternal.isDreaming()) {
1183 mDreamManagerInternal.stopDream(false /*immediate*/);
1184 return;
1185 }
1186
1187 // Go home!
1188 launchHomeFromHotKey();
1189 }
1190
Patrick Dubroyece94522011-02-23 18:35:01 -08001191 private void handleLongPressOnHome() {
Joe Onorato46b0d682010-11-22 17:37:27 -08001192 if (mLongPressOnHomeBehavior != LONG_PRESS_HOME_NOTHING) {
Jeff Browncaca8812013-05-09 13:34:33 -07001193 mHomeConsumed = true;
Joe Onorato46b0d682010-11-22 17:37:27 -08001194 performHapticFeedbackLw(null, HapticFeedbackConstants.LONG_PRESS, false);
Patrick Dubroyece94522011-02-23 18:35:01 -08001195
Jeff Browncaca8812013-05-09 13:34:33 -07001196 if (mLongPressOnHomeBehavior == LONG_PRESS_HOME_RECENT_SYSTEM_UI) {
1197 toggleRecentApps();
1198 } else if (mLongPressOnHomeBehavior == LONG_PRESS_HOME_ASSIST) {
1199 launchAssistAction();
Jim Millere6ad1a82010-08-20 19:25:39 -07001200 }
1201 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001202 }
Patrick Dubroyece94522011-02-23 18:35:01 -08001203
Jeff Browncaca8812013-05-09 13:34:33 -07001204 private void handleDoubleTapOnHome() {
1205 if (mDoubleTapOnHomeBehavior == DOUBLE_TAP_HOME_RECENT_SYSTEM_UI) {
1206 mHomeConsumed = true;
1207 toggleRecentApps();
1208 }
1209 }
1210
1211 private final Runnable mHomeDoubleTapTimeoutRunnable = new Runnable() {
1212 @Override
1213 public void run() {
1214 if (mHomeDoubleTapPending) {
1215 mHomeDoubleTapPending = false;
Jeff Brown13f00f02014-10-31 14:45:50 -07001216 handleShortPressOnHome();
Jeff Browncaca8812013-05-09 13:34:33 -07001217 }
1218 }
1219 };
1220
Mark Renoufc1256912015-03-11 14:38:23 -04001221 private boolean isRoundWindow() {
1222 return mContext.getResources().getBoolean(com.android.internal.R.bool.config_windowIsRound)
1223 || (Build.HARDWARE.contains("goldfish")
1224 && SystemProperties.getBoolean(ViewRootImpl.PROPERTY_EMULATOR_CIRCULAR, false));
1225 }
1226
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001227 /** {@inheritDoc} */
Craig Mautner0bf6ec92012-12-18 08:33:27 -08001228 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001229 public void init(Context context, IWindowManager windowManager,
Jeff Brown96307042012-07-27 15:51:34 -07001230 WindowManagerFuncs windowManagerFuncs) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001231 mContext = context;
1232 mWindowManager = windowManager;
Dianne Hackborndf89e652011-10-06 22:35:11 -07001233 mWindowManagerFuncs = windowManagerFuncs;
Craig Mautner8a0da012014-05-31 15:13:37 -07001234 mWindowManagerInternal = LocalServices.getService(WindowManagerInternal.class);
Jeff Brown061ea992015-04-17 19:55:47 -07001235 mActivityManagerInternal = LocalServices.getService(ActivityManagerInternal.class);
Jose Lima9546b202014-07-02 17:21:51 -07001236 mDreamManagerInternal = LocalServices.getService(DreamManagerInternal.class);
Mark Renoufc1256912015-03-11 14:38:23 -04001237
1238 // Init display burn-in protection
1239 boolean burnInProtectionEnabled = context.getResources().getBoolean(
1240 com.android.internal.R.bool.config_enableBurnInProtection);
1241 // Allow a system property to override this. Used by developer settings.
1242 boolean burnInProtectionDevMode =
1243 SystemProperties.getBoolean("persist.debug.force_burn_in", false);
1244 if (burnInProtectionEnabled || burnInProtectionDevMode) {
1245 final int minHorizontal;
1246 final int maxHorizontal;
1247 final int minVertical;
1248 final int maxVertical;
1249 final int maxRadius;
1250 if (burnInProtectionDevMode) {
1251 minHorizontal = -8;
1252 maxHorizontal = 8;
1253 minVertical = -8;
1254 maxVertical = -4;
1255 maxRadius = (isRoundWindow()) ? 6 : -1;
1256 } else {
1257 Resources resources = context.getResources();
1258 minHorizontal = resources.getInteger(
1259 com.android.internal.R.integer.config_burnInProtectionMinHorizontalOffset);
1260 maxHorizontal = resources.getInteger(
1261 com.android.internal.R.integer.config_burnInProtectionMaxHorizontalOffset);
1262 minVertical = resources.getInteger(
1263 com.android.internal.R.integer.config_burnInProtectionMinVerticalOffset);
1264 maxVertical = resources.getInteger(
1265 com.android.internal.R.integer.config_burnInProtectionMaxVerticalOffset);
1266 maxRadius = resources.getInteger(
1267 com.android.internal.R.integer.config_burnInProtectionMaxRadius);
1268 }
1269 mBurnInProtectionHelper = new BurnInProtectionHelper(
1270 context, minHorizontal, maxHorizontal, minVertical, maxVertical, maxRadius);
Filip Gruszczynskicfb31852015-02-25 21:47:12 +00001271 }
Craig Mautner8a0da012014-05-31 15:13:37 -07001272
Jeff Brown70825162012-03-28 17:27:48 -07001273 mHandler = new PolicyHandler();
Jeff Browna20dda42014-05-27 20:57:24 -07001274 mWakeGestureListener = new MyWakeGestureListener(mContext, mHandler);
Craig Mautnereee29c42013-01-17 14:44:34 -08001275 mOrientationListener = new MyOrientationListener(mContext, mHandler);
Jeff Brownc0347aa2011-09-23 17:26:09 -07001276 try {
1277 mOrientationListener.setCurrentRotation(windowManager.getRotation());
1278 } catch (RemoteException ex) { }
Christopher Tate5e08af02012-09-21 17:17:22 -07001279 mSettingsObserver = new SettingsObserver(mHandler);
1280 mSettingsObserver.observe();
Svetoslav683914b2015-01-15 14:22:26 -08001281 mShortcutManager = new ShortcutManager(context);
Daniel Sandler6396c722013-04-16 20:19:09 -04001282 mUiMode = context.getResources().getInteger(
1283 com.android.internal.R.integer.config_defaultUiModeType);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001284 mHomeIntent = new Intent(Intent.ACTION_MAIN, null);
1285 mHomeIntent.addCategory(Intent.CATEGORY_HOME);
1286 mHomeIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK
1287 | Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED);
Dianne Hackborn39c2d712009-09-22 11:41:31 -07001288 mCarDockIntent = new Intent(Intent.ACTION_MAIN, null);
1289 mCarDockIntent.addCategory(Intent.CATEGORY_CAR_DOCK);
1290 mCarDockIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK
1291 | Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED);
1292 mDeskDockIntent = new Intent(Intent.ACTION_MAIN, null);
1293 mDeskDockIntent.addCategory(Intent.CATEGORY_DESK_DOCK);
1294 mDeskDockIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK
1295 | Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED);
Jim Millere6ad1a82010-08-20 19:25:39 -07001296
Jeff Brown96307042012-07-27 15:51:34 -07001297 mPowerManager = (PowerManager)context.getSystemService(Context.POWER_SERVICE);
1298 mBroadcastWakeLock = mPowerManager.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK,
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001299 "PhoneWindowManager.mBroadcastWakeLock");
Jeff Brown13f00f02014-10-31 14:45:50 -07001300 mPowerKeyWakeLock = mPowerManager.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK,
1301 "PhoneWindowManager.mPowerKeyWakeLock");
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001302 mEnableShiftMenuBugReports = "1".equals(SystemProperties.get("ro.debuggable"));
Jeff Brownbcdfc622014-03-06 19:13:04 -08001303 mSupportAutoRotation = mContext.getResources().getBoolean(
1304 com.android.internal.R.bool.config_supportAutoRotation);
Dianne Hackborn2862fff2009-09-15 22:56:29 -07001305 mLidOpenRotation = readRotation(
Mike Lockwood2d1efbd2009-09-16 12:15:53 -04001306 com.android.internal.R.integer.config_lidOpenRotation);
1307 mCarDockRotation = readRotation(
1308 com.android.internal.R.integer.config_carDockRotation);
1309 mDeskDockRotation = readRotation(
1310 com.android.internal.R.integer.config_deskDockRotation);
Jeff Brownc82c89ed2013-04-17 17:18:15 -07001311 mUndockedHdmiRotation = readRotation(
1312 com.android.internal.R.integer.config_undockedHdmiRotation);
Mike Lockwoode9867d22009-09-20 01:59:02 -04001313 mCarDockEnablesAccelerometer = mContext.getResources().getBoolean(
1314 com.android.internal.R.bool.config_carDockEnablesAccelerometer);
1315 mDeskDockEnablesAccelerometer = mContext.getResources().getBoolean(
1316 com.android.internal.R.bool.config_deskDockEnablesAccelerometer);
Dianne Hackborn2862fff2009-09-15 22:56:29 -07001317 mLidKeyboardAccessibility = mContext.getResources().getInteger(
1318 com.android.internal.R.integer.config_lidKeyboardAccessibility);
1319 mLidNavigationAccessibility = mContext.getResources().getInteger(
1320 com.android.internal.R.integer.config_lidNavigationAccessibility);
Jeff Brownc458ce92012-04-30 14:58:40 -07001321 mLidControlsSleep = mContext.getResources().getBoolean(
1322 com.android.internal.R.bool.config_lidControlsSleep);
Daniel Sandlerdd73ee42013-10-11 22:19:59 -04001323 mTranslucentDecorEnabled = mContext.getResources().getBoolean(
1324 com.android.internal.R.bool.config_enableTranslucentDecor);
Bryce Lee584a4452014-10-21 15:55:55 -07001325
1326 mAllowTheaterModeWakeFromKey = mContext.getResources().getBoolean(
1327 com.android.internal.R.bool.config_allowTheaterModeWakeFromKey);
1328 mAllowTheaterModeWakeFromPowerKey = mAllowTheaterModeWakeFromKey
1329 || mContext.getResources().getBoolean(
1330 com.android.internal.R.bool.config_allowTheaterModeWakeFromPowerKey);
1331 mAllowTheaterModeWakeFromMotion = mContext.getResources().getBoolean(
1332 com.android.internal.R.bool.config_allowTheaterModeWakeFromMotion);
Bryce Lee812d7022014-11-10 13:33:28 -08001333 mAllowTheaterModeWakeFromMotionWhenNotDreaming = mContext.getResources().getBoolean(
1334 com.android.internal.R.bool.config_allowTheaterModeWakeFromMotionWhenNotDreaming);
Bryce Lee584a4452014-10-21 15:55:55 -07001335 mAllowTheaterModeWakeFromCameraLens = mContext.getResources().getBoolean(
1336 com.android.internal.R.bool.config_allowTheaterModeWakeFromCameraLens);
1337 mAllowTheaterModeWakeFromLidSwitch = mContext.getResources().getBoolean(
1338 com.android.internal.R.bool.config_allowTheaterModeWakeFromLidSwitch);
1339 mAllowTheaterModeWakeFromWakeGesture = mContext.getResources().getBoolean(
1340 com.android.internal.R.bool.config_allowTheaterModeWakeFromGesture);
1341
Bryce Lee55e846d2014-11-04 12:43:44 -08001342 mGoToSleepOnButtonPressTheaterMode = mContext.getResources().getBoolean(
1343 com.android.internal.R.bool.config_goToSleepOnButtonPressTheaterMode);
1344
Bryce Leed3b28402015-03-09 15:49:13 +00001345 mSupportLongPressPowerWhenNonInteractive = mContext.getResources().getBoolean(
1346 com.android.internal.R.bool.config_supportLongPressPowerWhenNonInteractive);
1347
Jeff Brown13f00f02014-10-31 14:45:50 -07001348 mShortPressOnPowerBehavior = mContext.getResources().getInteger(
1349 com.android.internal.R.integer.config_shortPressOnPowerBehavior);
1350 mLongPressOnPowerBehavior = mContext.getResources().getInteger(
1351 com.android.internal.R.integer.config_longPressOnPowerBehavior);
1352 mDoublePressOnPowerBehavior = mContext.getResources().getInteger(
1353 com.android.internal.R.integer.config_doublePressOnPowerBehavior);
1354 mTriplePressOnPowerBehavior = mContext.getResources().getInteger(
1355 com.android.internal.R.integer.config_triplePressOnPowerBehavior);
Filip Gruszczynskia483a1d2015-03-17 19:06:58 +00001356 mShortPressOnSleepBehavior = mContext.getResources().getInteger(
1357 com.android.internal.R.integer.config_shortPressOnSleepBehavior);
Jeff Brown13f00f02014-10-31 14:45:50 -07001358
John Spurlock61560172015-02-06 19:46:04 -05001359 mUseTvRouting = AudioSystem.getPlatformType(mContext) == AudioSystem.PLATFORM_TELEVISION;
RoboErik001c59c2015-01-26 15:53:51 -08001360
Jeff Brownf71343d2013-05-31 17:59:11 -07001361 readConfigurationDependentBehaviors();
Jeff Browncaca8812013-05-09 13:34:33 -07001362
Svetoslav8e3feb12014-02-24 13:46:47 -08001363 mAccessibilityManager = (AccessibilityManager) context.getSystemService(
1364 Context.ACCESSIBILITY_SERVICE);
1365
Mike Lockwood1753f7f2009-08-24 14:49:07 -07001366 // register for dock events
Dianne Hackborn78968392010-03-04 20:47:56 -08001367 IntentFilter filter = new IntentFilter();
1368 filter.addAction(UiModeManager.ACTION_ENTER_CAR_MODE);
1369 filter.addAction(UiModeManager.ACTION_EXIT_CAR_MODE);
1370 filter.addAction(UiModeManager.ACTION_ENTER_DESK_MODE);
1371 filter.addAction(UiModeManager.ACTION_EXIT_DESK_MODE);
Dianne Hackborn867ab6472010-04-29 13:28:56 -07001372 filter.addAction(Intent.ACTION_DOCK_EVENT);
1373 Intent intent = context.registerReceiver(mDockReceiver, filter);
1374 if (intent != null) {
1375 // Retrieve current sticky dock event broadcast.
1376 mDockMode = intent.getIntExtra(Intent.EXTRA_DOCK_STATE,
1377 Intent.EXTRA_DOCK_STATE_UNDOCKED);
1378 }
Daniel Sandler7e37df52011-11-16 22:08:23 -08001379
Jeff Brown6aaf2952012-10-05 16:01:08 -07001380 // register for dream-related broadcasts
1381 filter = new IntentFilter();
1382 filter.addAction(Intent.ACTION_DREAMING_STARTED);
1383 filter.addAction(Intent.ACTION_DREAMING_STOPPED);
1384 context.registerReceiver(mDreamReceiver, filter);
1385
Christopher Tate5e08af02012-09-21 17:17:22 -07001386 // register for multiuser-relevant broadcasts
1387 filter = new IntentFilter(Intent.ACTION_USER_SWITCHED);
1388 context.registerReceiver(mMultiuserReceiver, filter);
1389
John Spurlock57306e62013-04-22 09:48:49 -04001390 // monitor for system gestures
Craig Mautner037aa8d2013-06-07 10:35:44 -07001391 mSystemGestures = new SystemGesturesPointerEventListener(context,
1392 new SystemGesturesPointerEventListener.Callbacks() {
John Spurlock57306e62013-04-22 09:48:49 -04001393 @Override
1394 public void onSwipeFromTop() {
John Spurlock04db1762013-05-13 12:46:41 -04001395 if (mStatusBar != null) {
John Spurlocke1f366f2013-08-05 12:22:40 -04001396 requestTransientBars(mStatusBar);
John Spurlock04db1762013-05-13 12:46:41 -04001397 }
John Spurlockad3e6cb2013-04-30 08:47:43 -04001398 }
1399 @Override
1400 public void onSwipeFromBottom() {
John Spurlock04db1762013-05-13 12:46:41 -04001401 if (mNavigationBar != null && mNavigationBarOnBottom) {
John Spurlocke1f366f2013-08-05 12:22:40 -04001402 requestTransientBars(mNavigationBar);
John Spurlockad3e6cb2013-04-30 08:47:43 -04001403 }
1404 }
1405 @Override
1406 public void onSwipeFromRight() {
John Spurlock04db1762013-05-13 12:46:41 -04001407 if (mNavigationBar != null && !mNavigationBarOnBottom) {
John Spurlocke1f366f2013-08-05 12:22:40 -04001408 requestTransientBars(mNavigationBar);
John Spurlockad3e6cb2013-04-30 08:47:43 -04001409 }
1410 }
1411 @Override
1412 public void onDebug() {
John Spurlockd67ec252013-09-05 11:31:54 -04001413 // no-op
John Spurlockad3e6cb2013-04-30 08:47:43 -04001414 }
Adrian Roos3595be42015-03-05 16:31:15 +01001415 @Override
1416 public void onDown() {
1417 mOrientationListener.onTouchStart();
1418 }
1419 @Override
1420 public void onUpOrCancel() {
1421 mOrientationListener.onTouchEnd();
1422 }
John Spurlockad3e6cb2013-04-30 08:47:43 -04001423 });
John Spurlockf1a36642013-10-12 17:50:42 -04001424 mImmersiveModeConfirmation = new ImmersiveModeConfirmation(mContext);
Craig Mautner037aa8d2013-06-07 10:35:44 -07001425 mWindowManagerFuncs.registerPointerEventListener(mSystemGestures);
John Spurlock32beb2c2013-03-11 10:16:47 -04001426
Jeff Brownc2346132012-04-13 01:55:38 -07001427 mVibrator = (Vibrator)context.getSystemService(Context.VIBRATOR_SERVICE);
Dianne Hackbornb1a79802009-09-29 15:18:31 -07001428 mLongPressVibePattern = getLongIntArray(mContext.getResources(),
1429 com.android.internal.R.array.config_longPressVibePattern);
1430 mVirtualKeyVibePattern = getLongIntArray(mContext.getResources(),
1431 com.android.internal.R.array.config_virtualKeyVibePattern);
Amith Yamasanic33cb712010-02-10 15:21:49 -08001432 mKeyboardTapVibePattern = getLongIntArray(mContext.getResources(),
1433 com.android.internal.R.array.config_keyboardTapVibePattern);
Fabrice Di Meglioeeff63a2013-08-05 12:07:24 -07001434 mClockTickVibePattern = getLongIntArray(mContext.getResources(),
1435 com.android.internal.R.array.config_clockTickVibePattern);
Fabrice Di Megliobd9152f2013-10-01 11:21:31 -07001436 mCalendarDateVibePattern = getLongIntArray(mContext.getResources(),
1437 com.android.internal.R.array.config_calendarDateVibePattern);
Dianne Hackbornb1a79802009-09-29 15:18:31 -07001438 mSafeModeDisabledVibePattern = getLongIntArray(mContext.getResources(),
1439 com.android.internal.R.array.config_safeModeDisabledVibePattern);
1440 mSafeModeEnabledVibePattern = getLongIntArray(mContext.getResources(),
1441 com.android.internal.R.array.config_safeModeEnabledVibePattern);
Mady Mellore82067b2015-04-30 09:58:35 -07001442 mStylusButtonPressVibePattern = getLongIntArray(mContext.getResources(),
1443 com.android.internal.R.array.config_stylusButtonPressVibePattern);
Daniel Sandler40427442010-07-16 11:44:52 -04001444
Christopher Tatee90585f2012-03-05 18:56:25 -08001445 mScreenshotChordEnabled = mContext.getResources().getBoolean(
1446 com.android.internal.R.bool.config_enableScreenshotChord);
1447
Justin Kohd378ad72013-04-01 12:18:26 -07001448 mGlobalKeyManager = new GlobalKeyManager(mContext);
1449
Joe Onoratoea495d42011-04-06 11:41:11 -07001450 // Controls rotation and the like.
1451 initializeHdmiState();
Dianne Hackborn40011092011-09-22 13:37:48 -07001452
1453 // Match current screen state.
Craig Mautnera631d492014-08-05 15:16:01 -07001454 if (!mPowerManager.isInteractive()) {
Jeff Brown140ffc72014-05-01 15:18:00 -07001455 goingToSleep(WindowManagerPolicy.OFF_BECAUSE_OF_USER);
Dianne Hackborn40011092011-09-22 13:37:48 -07001456 }
Jorim Jaggi24bec7c2015-02-04 12:40:14 +01001457
1458 mWindowManagerInternal.registerAppTransitionListener(
1459 mStatusBarController.getAppTransitionListener());
Mike Lockwood1753f7f2009-08-24 14:49:07 -07001460 }
1461
Jeff Brownf71343d2013-05-31 17:59:11 -07001462 /**
1463 * Read values from config.xml that may be overridden depending on
1464 * the configuration of the device.
1465 * eg. Disable long press on home goes to recents on sw600dp.
1466 */
1467 private void readConfigurationDependentBehaviors() {
1468 mLongPressOnHomeBehavior = mContext.getResources().getInteger(
1469 com.android.internal.R.integer.config_longPressOnHomeBehavior);
1470 if (mLongPressOnHomeBehavior < LONG_PRESS_HOME_NOTHING ||
1471 mLongPressOnHomeBehavior > LONG_PRESS_HOME_ASSIST) {
1472 mLongPressOnHomeBehavior = LONG_PRESS_HOME_NOTHING;
1473 }
1474
1475 mDoubleTapOnHomeBehavior = mContext.getResources().getInteger(
1476 com.android.internal.R.integer.config_doubleTapOnHomeBehavior);
1477 if (mDoubleTapOnHomeBehavior < DOUBLE_TAP_HOME_NOTHING ||
1478 mDoubleTapOnHomeBehavior > DOUBLE_TAP_HOME_RECENT_SYSTEM_UI) {
1479 mDoubleTapOnHomeBehavior = LONG_PRESS_HOME_NOTHING;
1480 }
1481 }
1482
Craig Mautner0bf6ec92012-12-18 08:33:27 -08001483 @Override
Dianne Hackborndde331c2012-08-03 14:01:57 -07001484 public void setInitialDisplaySize(Display display, int width, int height, int density) {
Jeff Brownef981a42013-08-07 14:13:37 -07001485 // This method might be called before the policy has been fully initialized
1486 // or for other displays we don't care about.
1487 if (mContext == null || display.getDisplayId() != Display.DEFAULT_DISPLAY) {
1488 return;
Dianne Hackbornc652de82013-02-15 16:32:56 -08001489 }
Dianne Hackbornf87d1962012-04-04 12:48:24 -07001490 mDisplay = display;
1491
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001492 final Resources res = mContext.getResources();
Dianne Hackbornf87d1962012-04-04 12:48:24 -07001493 int shortSize, longSize;
Dianne Hackborn9d132642011-04-21 17:26:39 -07001494 if (width > height) {
Dianne Hackborn81e56d52011-05-26 00:55:58 -07001495 shortSize = height;
Dianne Hackbornf87d1962012-04-04 12:48:24 -07001496 longSize = width;
Dianne Hackborn9d132642011-04-21 17:26:39 -07001497 mLandscapeRotation = Surface.ROTATION_0;
1498 mSeascapeRotation = Surface.ROTATION_180;
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001499 if (res.getBoolean(com.android.internal.R.bool.config_reverseDefaultRotation)) {
Dianne Hackborn9d132642011-04-21 17:26:39 -07001500 mPortraitRotation = Surface.ROTATION_90;
1501 mUpsideDownRotation = Surface.ROTATION_270;
1502 } else {
1503 mPortraitRotation = Surface.ROTATION_270;
1504 mUpsideDownRotation = Surface.ROTATION_90;
1505 }
1506 } else {
Dianne Hackborn81e56d52011-05-26 00:55:58 -07001507 shortSize = width;
Dianne Hackbornf87d1962012-04-04 12:48:24 -07001508 longSize = height;
Dianne Hackborn9d132642011-04-21 17:26:39 -07001509 mPortraitRotation = Surface.ROTATION_0;
1510 mUpsideDownRotation = Surface.ROTATION_180;
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001511 if (res.getBoolean(com.android.internal.R.bool.config_reverseDefaultRotation)) {
Dianne Hackborn9d132642011-04-21 17:26:39 -07001512 mLandscapeRotation = Surface.ROTATION_270;
1513 mSeascapeRotation = Surface.ROTATION_90;
1514 } else {
1515 mLandscapeRotation = Surface.ROTATION_90;
1516 mSeascapeRotation = Surface.ROTATION_270;
1517 }
1518 }
Dianne Hackborn81e56d52011-05-26 00:55:58 -07001519
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001520 mStatusBarHeight =
1521 res.getDimensionPixelSize(com.android.internal.R.dimen.status_bar_height);
Dianne Hackbornf87d1962012-04-04 12:48:24 -07001522
Daniel Sandler9f65c4c2012-04-26 01:35:35 -04001523 // Height of the navigation bar when presented horizontally at bottom
1524 mNavigationBarHeightForRotation[mPortraitRotation] =
1525 mNavigationBarHeightForRotation[mUpsideDownRotation] =
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001526 res.getDimensionPixelSize(com.android.internal.R.dimen.navigation_bar_height);
Daniel Sandler9f65c4c2012-04-26 01:35:35 -04001527 mNavigationBarHeightForRotation[mLandscapeRotation] =
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001528 mNavigationBarHeightForRotation[mSeascapeRotation] = res.getDimensionPixelSize(
1529 com.android.internal.R.dimen.navigation_bar_height_landscape);
Daniel Sandler9f65c4c2012-04-26 01:35:35 -04001530
1531 // Width of the navigation bar when presented vertically along one side
1532 mNavigationBarWidthForRotation[mPortraitRotation] =
1533 mNavigationBarWidthForRotation[mUpsideDownRotation] =
1534 mNavigationBarWidthForRotation[mLandscapeRotation] =
1535 mNavigationBarWidthForRotation[mSeascapeRotation] =
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001536 res.getDimensionPixelSize(com.android.internal.R.dimen.navigation_bar_width);
Daniel Sandler4a066c52012-04-20 14:49:13 -04001537
1538 // SystemUI (status bar) layout policy
Dianne Hackborndde331c2012-08-03 14:01:57 -07001539 int shortSizeDp = shortSize * DisplayMetrics.DENSITY_DEFAULT / density;
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001540 int longSizeDp = longSize * DisplayMetrics.DENSITY_DEFAULT / density;
Daniel Sandler4a066c52012-04-20 14:49:13 -04001541
Devin Kimd7b12b42014-05-05 14:34:58 -07001542 // Allow the navigation bar to move on non-square small devices (phones).
1543 mNavigationBarCanMove = width != height && shortSizeDp < 600;
Daniel Sandler36412a72011-08-04 09:35:13 -04001544
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001545 mHasNavigationBar = res.getBoolean(com.android.internal.R.bool.config_showNavigationBar);
John Spurlock80f00c12013-06-13 11:10:51 -04001546 // Allow a system property to override this. Used by the emulator.
1547 // See also hasNavigationBar().
1548 String navBarOverride = SystemProperties.get("qemu.hw.mainkeys");
1549 if ("1".equals(navBarOverride)) {
Dianne Hackbornf87d1962012-04-04 12:48:24 -07001550 mHasNavigationBar = false;
John Spurlock80f00c12013-06-13 11:10:51 -04001551 } else if ("0".equals(navBarOverride)) {
1552 mHasNavigationBar = true;
Daniel Sandler0c4ccff2011-10-19 16:39:14 -04001553 }
1554
Jeff Brown27f1d672012-10-17 18:32:34 -07001555 // For demo purposes, allow the rotation of the HDMI display to be controlled.
1556 // By default, HDMI locks rotation to landscape.
Erik Gilling9a41ef82011-09-26 19:21:03 -07001557 if ("portrait".equals(SystemProperties.get("persist.demo.hdmirotation"))) {
Jeff Brownc82c89ed2013-04-17 17:18:15 -07001558 mDemoHdmiRotation = mPortraitRotation;
Erik Gilling9a41ef82011-09-26 19:21:03 -07001559 } else {
Jeff Brownc82c89ed2013-04-17 17:18:15 -07001560 mDemoHdmiRotation = mLandscapeRotation;
Erik Gilling9a41ef82011-09-26 19:21:03 -07001561 }
Jeff Brownc82c89ed2013-04-17 17:18:15 -07001562 mDemoHdmiRotationLock = SystemProperties.getBoolean("persist.demo.hdmirotationlock", false);
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001563
Chong Zhangae6119ff2014-11-11 18:54:39 -08001564 // For demo purposes, allow the rotation of the remote display to be controlled.
1565 // By default, remote display locks rotation to landscape.
1566 if ("portrait".equals(SystemProperties.get("persist.demo.remoterotation"))) {
1567 mDemoRotation = mPortraitRotation;
1568 } else {
1569 mDemoRotation = mLandscapeRotation;
1570 }
1571 mDemoRotationLock = SystemProperties.getBoolean(
1572 "persist.demo.rotationlock", false);
1573
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001574 // Only force the default orientation if the screen is xlarge, at least 960dp x 720dp, per
1575 // http://developer.android.com/guide/practices/screens_support.html#range
1576 mForceDefaultOrientation = longSizeDp >= 960 && shortSizeDp >= 720 &&
1577 res.getBoolean(com.android.internal.R.bool.config_forceDefaultOrientation) &&
1578 // For debug purposes the next line turns this feature off with:
1579 // $ adb shell setprop config.override_forced_orient true
1580 // $ adb shell wm size reset
1581 !"true".equals(SystemProperties.get("config.override_forced_orient"));
1582 }
1583
Alan Viverette5a0f4ec2013-10-07 15:10:29 -07001584 /**
1585 * @return whether the navigation bar can be hidden, e.g. the device has a
1586 * navigation bar and touch exploration is not enabled
1587 */
1588 private boolean canHideNavigationBar() {
Svetoslav8e3feb12014-02-24 13:46:47 -08001589 return mHasNavigationBar
1590 && !mAccessibilityManager.isTouchExplorationEnabled();
Alan Viverette5a0f4ec2013-10-07 15:10:29 -07001591 }
1592
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001593 @Override
1594 public boolean isDefaultOrientationForced() {
1595 return mForceDefaultOrientation;
Dianne Hackborn9d132642011-04-21 17:26:39 -07001596 }
1597
Dianne Hackbornc652de82013-02-15 16:32:56 -08001598 @Override
1599 public void setDisplayOverscan(Display display, int left, int top, int right, int bottom) {
1600 if (display.getDisplayId() == Display.DEFAULT_DISPLAY) {
1601 mOverscanLeft = left;
1602 mOverscanTop = top;
1603 mOverscanRight = right;
1604 mOverscanBottom = bottom;
1605 }
1606 }
1607
Dianne Hackbornc777e072010-02-12 13:07:59 -08001608 public void updateSettings() {
1609 ContentResolver resolver = mContext.getContentResolver();
1610 boolean updateRotation = false;
Dianne Hackbornc777e072010-02-12 13:07:59 -08001611 synchronized (mLock) {
Christopher Tate5e08af02012-09-21 17:17:22 -07001612 mEndcallBehavior = Settings.System.getIntForUser(resolver,
David Brownbaf8d092010-03-08 21:52:59 -08001613 Settings.System.END_BUTTON_BEHAVIOR,
Christopher Tate5e08af02012-09-21 17:17:22 -07001614 Settings.System.END_BUTTON_BEHAVIOR_DEFAULT,
1615 UserHandle.USER_CURRENT);
1616 mIncallPowerBehavior = Settings.Secure.getIntForUser(resolver,
David Brownbaf8d092010-03-08 21:52:59 -08001617 Settings.Secure.INCALL_POWER_BUTTON_BEHAVIOR,
Christopher Tate5e08af02012-09-21 17:17:22 -07001618 Settings.Secure.INCALL_POWER_BUTTON_BEHAVIOR_DEFAULT,
1619 UserHandle.USER_CURRENT);
Daniel Sandlerb73617d2010-08-17 00:41:00 -04001620
Jeff Browna20dda42014-05-27 20:57:24 -07001621 // Configure wake gesture.
1622 boolean wakeGestureEnabledSetting = Settings.Secure.getIntForUser(resolver,
1623 Settings.Secure.WAKE_GESTURE_ENABLED, 0,
1624 UserHandle.USER_CURRENT) != 0;
1625 if (mWakeGestureEnabledSetting != wakeGestureEnabledSetting) {
1626 mWakeGestureEnabledSetting = wakeGestureEnabledSetting;
1627 updateWakeGestureListenerLp();
1628 }
1629
Jeff Brown207673cd2012-06-05 17:47:11 -07001630 // Configure rotation lock.
Christopher Tate5e08af02012-09-21 17:17:22 -07001631 int userRotation = Settings.System.getIntForUser(resolver,
1632 Settings.System.USER_ROTATION, Surface.ROTATION_0,
1633 UserHandle.USER_CURRENT);
Jeff Brown207673cd2012-06-05 17:47:11 -07001634 if (mUserRotation != userRotation) {
1635 mUserRotation = userRotation;
1636 updateRotation = true;
1637 }
Christopher Tate5e08af02012-09-21 17:17:22 -07001638 int userRotationMode = Settings.System.getIntForUser(resolver,
1639 Settings.System.ACCELEROMETER_ROTATION, 0, UserHandle.USER_CURRENT) != 0 ?
Jeff Brown207673cd2012-06-05 17:47:11 -07001640 WindowManagerPolicy.USER_ROTATION_FREE :
1641 WindowManagerPolicy.USER_ROTATION_LOCKED;
1642 if (mUserRotationMode != userRotationMode) {
1643 mUserRotationMode = userRotationMode;
1644 updateRotation = true;
Dianne Hackbornc777e072010-02-12 13:07:59 -08001645 updateOrientationListenerLp();
1646 }
Daniel Sandlerb73617d2010-08-17 00:41:00 -04001647
Dianne Hackbornc777e072010-02-12 13:07:59 -08001648 if (mSystemReady) {
Christopher Tate5e08af02012-09-21 17:17:22 -07001649 int pointerLocation = Settings.System.getIntForUser(resolver,
1650 Settings.System.POINTER_LOCATION, 0, UserHandle.USER_CURRENT);
Dianne Hackbornc777e072010-02-12 13:07:59 -08001651 if (mPointerLocationMode != pointerLocation) {
1652 mPointerLocationMode = pointerLocation;
Jeff Brown70825162012-03-28 17:27:48 -07001653 mHandler.sendEmptyMessage(pointerLocation != 0 ?
1654 MSG_ENABLE_POINTER_LOCATION : MSG_DISABLE_POINTER_LOCATION);
Dianne Hackbornc777e072010-02-12 13:07:59 -08001655 }
1656 }
1657 // use screen off timeout setting as the timeout for the lockscreen
Christopher Tate5e08af02012-09-21 17:17:22 -07001658 mLockScreenTimeout = Settings.System.getIntForUser(resolver,
1659 Settings.System.SCREEN_OFF_TIMEOUT, 0, UserHandle.USER_CURRENT);
1660 String imId = Settings.Secure.getStringForUser(resolver,
1661 Settings.Secure.DEFAULT_INPUT_METHOD, UserHandle.USER_CURRENT);
Dianne Hackbornc777e072010-02-12 13:07:59 -08001662 boolean hasSoftInput = imId != null && imId.length() > 0;
1663 if (mHasSoftInput != hasSoftInput) {
1664 mHasSoftInput = hasSoftInput;
1665 updateRotation = true;
1666 }
John Spurlockf1a36642013-10-12 17:50:42 -04001667 if (mImmersiveModeConfirmation != null) {
John Spurlock4355a532014-02-19 09:49:25 -05001668 mImmersiveModeConfirmation.loadSetting(mCurrentUserId);
John Spurlockd67ec252013-09-05 11:31:54 -04001669 }
John Spurlockc6d1c602014-01-17 15:22:06 -05001670 PolicyControl.reloadFromSetting(mContext);
Dianne Hackbornc777e072010-02-12 13:07:59 -08001671 }
1672 if (updateRotation) {
Jeff Brown01a98dd2011-09-20 15:08:29 -07001673 updateRotation(true);
Dianne Hackbornc777e072010-02-12 13:07:59 -08001674 }
Jeff Brown70825162012-03-28 17:27:48 -07001675 }
1676
Jeff Browna20dda42014-05-27 20:57:24 -07001677 private void updateWakeGestureListenerLp() {
1678 if (shouldEnableWakeGestureLp()) {
1679 mWakeGestureListener.requestWakeUpTrigger();
1680 } else {
1681 mWakeGestureListener.cancelWakeUpTrigger();
1682 }
1683 }
1684
1685 private boolean shouldEnableWakeGestureLp() {
Jeff Brown3ee549c2014-09-22 20:14:39 -07001686 return mWakeGestureEnabledSetting && !mAwake
Jeff Browna20dda42014-05-27 20:57:24 -07001687 && (!mLidControlsSleep || mLidState != LID_CLOSED)
1688 && mWakeGestureListener.isSupported();
1689 }
1690
Jeff Brown70825162012-03-28 17:27:48 -07001691 private void enablePointerLocation() {
1692 if (mPointerLocationView == null) {
1693 mPointerLocationView = new PointerLocationView(mContext);
1694 mPointerLocationView.setPrintCoords(false);
Dianne Hackbornc777e072010-02-12 13:07:59 -08001695 WindowManager.LayoutParams lp = new WindowManager.LayoutParams(
1696 WindowManager.LayoutParams.MATCH_PARENT,
1697 WindowManager.LayoutParams.MATCH_PARENT);
Jeff Brown3b2b3542010-10-15 00:54:27 -07001698 lp.type = WindowManager.LayoutParams.TYPE_SECURE_SYSTEM_OVERLAY;
Jeff Brownbfcb60a2011-09-08 18:51:14 -07001699 lp.flags = WindowManager.LayoutParams.FLAG_FULLSCREEN
1700 | WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE
1701 | WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE
1702 | WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN;
Jeff Brown90fc9052012-10-01 14:44:24 -07001703 if (ActivityManager.isHighEndGfx()) {
1704 lp.flags |= WindowManager.LayoutParams.FLAG_HARDWARE_ACCELERATED;
1705 lp.privateFlags |=
1706 WindowManager.LayoutParams.PRIVATE_FLAG_FORCE_HARDWARE_ACCELERATED;
1707 }
Dianne Hackbornc777e072010-02-12 13:07:59 -08001708 lp.format = PixelFormat.TRANSLUCENT;
1709 lp.setTitle("PointerLocation");
Dianne Hackborn5fd21692011-06-07 14:09:47 -07001710 WindowManager wm = (WindowManager)
Dianne Hackbornc777e072010-02-12 13:07:59 -08001711 mContext.getSystemService(Context.WINDOW_SERVICE);
Jeff Browncc4f7db2011-08-30 20:34:48 -07001712 lp.inputFeatures |= WindowManager.LayoutParams.INPUT_FEATURE_NO_INPUT_CHANNEL;
Jeff Brown70825162012-03-28 17:27:48 -07001713 wm.addView(mPointerLocationView, lp);
Michael Wrightc9c487e2013-11-07 18:55:09 -08001714 mWindowManagerFuncs.registerPointerEventListener(mPointerLocationView);
Dianne Hackbornc777e072010-02-12 13:07:59 -08001715 }
Dianne Hackbornc777e072010-02-12 13:07:59 -08001716 }
Jeff Brown70825162012-03-28 17:27:48 -07001717
1718 private void disablePointerLocation() {
Jeff Brown70825162012-03-28 17:27:48 -07001719 if (mPointerLocationView != null) {
Michael Wrightc9c487e2013-11-07 18:55:09 -08001720 mWindowManagerFuncs.unregisterPointerEventListener(mPointerLocationView);
1721 WindowManager wm = (WindowManager) mContext.getSystemService(Context.WINDOW_SERVICE);
Jeff Brown70825162012-03-28 17:27:48 -07001722 wm.removeView(mPointerLocationView);
1723 mPointerLocationView = null;
1724 }
1725 }
1726
Mike Lockwood2d1efbd2009-09-16 12:15:53 -04001727 private int readRotation(int resID) {
Mike Lockwood1753f7f2009-08-24 14:49:07 -07001728 try {
1729 int rotation = mContext.getResources().getInteger(resID);
1730 switch (rotation) {
1731 case 0:
1732 return Surface.ROTATION_0;
1733 case 90:
1734 return Surface.ROTATION_90;
1735 case 180:
1736 return Surface.ROTATION_180;
1737 case 270:
1738 return Surface.ROTATION_270;
Mike Lockwood1753f7f2009-08-24 14:49:07 -07001739 }
1740 } catch (Resources.NotFoundException e) {
Mike Lockwood2d1efbd2009-09-16 12:15:53 -04001741 // fall through
Mike Lockwood1753f7f2009-08-24 14:49:07 -07001742 }
Mike Lockwood2d1efbd2009-09-16 12:15:53 -04001743 return -1;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001744 }
1745
1746 /** {@inheritDoc} */
Craig Mautner88400d32012-09-30 12:35:45 -07001747 @Override
Dianne Hackbornc2293022013-02-06 23:14:49 -08001748 public int checkAddPermission(WindowManager.LayoutParams attrs, int[] outAppOp) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001749 int type = attrs.type;
Dianne Hackbornc2293022013-02-06 23:14:49 -08001750
1751 outAppOp[0] = AppOpsManager.OP_NONE;
1752
Wale Ogunwale74bf0652015-01-12 10:24:36 -08001753 if (!((type >= FIRST_APPLICATION_WINDOW && type <= LAST_APPLICATION_WINDOW)
1754 || (type >= FIRST_SUB_WINDOW && type <= LAST_SUB_WINDOW)
1755 || (type >= FIRST_SYSTEM_WINDOW && type <= LAST_SYSTEM_WINDOW))) {
1756 return WindowManagerGlobal.ADD_INVALID_TYPE;
1757 }
1758
1759 if (type < FIRST_SYSTEM_WINDOW || type > LAST_SYSTEM_WINDOW) {
1760 // Window manager will make sure these are okay.
Jeff Brown98365d72012-08-19 20:30:52 -07001761 return WindowManagerGlobal.ADD_OKAY;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001762 }
1763 String permission = null;
1764 switch (type) {
1765 case TYPE_TOAST:
1766 // XXX right now the app process has complete control over
1767 // this... should introduce a token to let the system
1768 // monitor/control what they are doing.
Jason Monk1c7c3192014-06-26 12:52:18 -04001769 outAppOp[0] = AppOpsManager.OP_TOAST_WINDOW;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001770 break;
Daniel Sandler7d276c32012-01-30 14:33:52 -05001771 case TYPE_DREAM:
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001772 case TYPE_INPUT_METHOD:
Dianne Hackbornb7cd8b92009-08-08 20:53:03 -07001773 case TYPE_WALLPAPER:
keunyounga446bf02013-06-21 19:07:57 -07001774 case TYPE_PRIVATE_PRESENTATION:
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001775 case TYPE_VOICE_INTERACTION:
Svetoslav3a5c7212014-10-14 09:54:26 -07001776 case TYPE_ACCESSIBILITY_OVERLAY:
Dianne Hackbornb7cd8b92009-08-08 20:53:03 -07001777 // The window manager will check these.
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001778 break;
1779 case TYPE_PHONE:
1780 case TYPE_PRIORITY_PHONE:
1781 case TYPE_SYSTEM_ALERT:
1782 case TYPE_SYSTEM_ERROR:
1783 case TYPE_SYSTEM_OVERLAY:
1784 permission = android.Manifest.permission.SYSTEM_ALERT_WINDOW;
Dianne Hackbornc2293022013-02-06 23:14:49 -08001785 outAppOp[0] = AppOpsManager.OP_SYSTEM_ALERT_WINDOW;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001786 break;
1787 default:
1788 permission = android.Manifest.permission.INTERNAL_SYSTEM_WINDOW;
1789 }
1790 if (permission != null) {
1791 if (mContext.checkCallingOrSelfPermission(permission)
1792 != PackageManager.PERMISSION_GRANTED) {
Jeff Brown98365d72012-08-19 20:30:52 -07001793 return WindowManagerGlobal.ADD_PERMISSION_DENIED;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001794 }
1795 }
Jeff Brown98365d72012-08-19 20:30:52 -07001796 return WindowManagerGlobal.ADD_OKAY;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001797 }
Craig Mautner88400d32012-09-30 12:35:45 -07001798
1799 @Override
1800 public boolean checkShowToOwnerOnly(WindowManager.LayoutParams attrs) {
1801
1802 // If this switch statement is modified, modify the comment in the declarations of
1803 // the type in {@link WindowManager.LayoutParams} as well.
1804 switch (attrs.type) {
1805 default:
1806 // These are the windows that by default are shown only to the user that created
1807 // them. If this needs to be overridden, set
1808 // {@link WindowManager.LayoutParams.PRIVATE_FLAG_SHOW_FOR_ALL_USERS} in
1809 // {@link WindowManager.LayoutParams}. Note that permission
1810 // {@link android.Manifest.permission.INTERNAL_SYSTEM_WINDOW} is required as well.
1811 if ((attrs.privateFlags & PRIVATE_FLAG_SHOW_FOR_ALL_USERS) == 0) {
1812 return true;
1813 }
1814 break;
1815
1816 // These are the windows that by default are shown to all users. However, to
1817 // protect against spoofing, check permissions below.
1818 case TYPE_APPLICATION_STARTING:
1819 case TYPE_BOOT_PROGRESS:
1820 case TYPE_DISPLAY_OVERLAY:
1821 case TYPE_HIDDEN_NAV_CONSUMER:
Jim Miller5ecd8112013-01-09 18:50:26 -08001822 case TYPE_KEYGUARD_SCRIM:
Craig Mautner88400d32012-09-30 12:35:45 -07001823 case TYPE_KEYGUARD_DIALOG:
1824 case TYPE_MAGNIFICATION_OVERLAY:
1825 case TYPE_NAVIGATION_BAR:
1826 case TYPE_NAVIGATION_BAR_PANEL:
1827 case TYPE_PHONE:
1828 case TYPE_POINTER:
1829 case TYPE_PRIORITY_PHONE:
Craig Mautner88400d32012-09-30 12:35:45 -07001830 case TYPE_SEARCH_BAR:
1831 case TYPE_STATUS_BAR:
1832 case TYPE_STATUS_BAR_PANEL:
1833 case TYPE_STATUS_BAR_SUB_PANEL:
1834 case TYPE_SYSTEM_DIALOG:
Craig Mautner88400d32012-09-30 12:35:45 -07001835 case TYPE_VOLUME_OVERLAY:
keunyounga446bf02013-06-21 19:07:57 -07001836 case TYPE_PRIVATE_PRESENTATION:
Craig Mautner88400d32012-09-30 12:35:45 -07001837 break;
1838 }
1839
1840 // Check if third party app has set window to system window type.
1841 return mContext.checkCallingOrSelfPermission(
1842 android.Manifest.permission.INTERNAL_SYSTEM_WINDOW)
1843 != PackageManager.PERMISSION_GRANTED;
1844 }
1845
Craig Mautner967212c2013-04-13 21:10:58 -07001846 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001847 public void adjustWindowParamsLw(WindowManager.LayoutParams attrs) {
1848 switch (attrs.type) {
1849 case TYPE_SYSTEM_OVERLAY:
Jeff Brown3b2b3542010-10-15 00:54:27 -07001850 case TYPE_SECURE_SYSTEM_OVERLAY:
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001851 // These types of windows can't receive input events.
1852 attrs.flags |= WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE
1853 | WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE;
Jeff Brownbfcb60a2011-09-08 18:51:14 -07001854 attrs.flags &= ~WindowManager.LayoutParams.FLAG_WATCH_OUTSIDE_TOUCH;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001855 break;
Jorim Jaggi380ecb82014-03-14 17:25:20 +01001856 case TYPE_STATUS_BAR:
1857
1858 // If the Keyguard is in a hidden state (occluded by another window), we force to
1859 // remove the wallpaper and keyguard flag so that any change in-flight after setting
1860 // the keyguard as occluded wouldn't set these flags again.
1861 // See {@link #processKeyguardSetHiddenResultLw}.
1862 if (mKeyguardHidden) {
1863 attrs.flags &= ~WindowManager.LayoutParams.FLAG_SHOW_WALLPAPER;
1864 attrs.privateFlags &= ~WindowManager.LayoutParams.PRIVATE_FLAG_KEYGUARD;
1865 }
1866 break;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001867 }
Adrian Roos38502112014-04-09 21:04:11 +02001868
1869 if (attrs.type != TYPE_STATUS_BAR) {
1870 // The status bar is the only window allowed to exhibit keyguard behavior.
1871 attrs.privateFlags &= ~WindowManager.LayoutParams.PRIVATE_FLAG_KEYGUARD;
1872 }
Adrian Roosea562512014-05-05 13:33:03 +02001873
1874 if (ActivityManager.isHighEndGfx()
1875 && (attrs.flags & FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS) != 0) {
Adrian Roosf5e9b5c2014-09-10 15:27:41 +02001876 attrs.subtreeSystemUiVisibility |= View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
Adrian Roosea562512014-05-05 13:33:03 +02001877 | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION;
1878 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001879 }
RoboErik8a2cfc32014-05-16 11:19:38 -07001880
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001881 void readLidState() {
Jeff Brown2e7760e2012-04-11 15:14:55 -07001882 mLidState = mWindowManagerFuncs.getLidState();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001883 }
RoboErik8a2cfc32014-05-16 11:19:38 -07001884
Michael Wright3818c922014-09-02 13:59:07 -07001885 private void readCameraLensCoverState() {
1886 mCameraLensCoverState = mWindowManagerFuncs.getCameraLensCoverState();
1887 }
1888
Jeff Browndaa37532012-05-01 15:54:03 -07001889 private boolean isHidden(int accessibilityMode) {
1890 switch (accessibilityMode) {
1891 case 1:
1892 return mLidState == LID_CLOSED;
1893 case 2:
1894 return mLidState == LID_OPEN;
1895 default:
1896 return false;
Dianne Hackborn2862fff2009-09-15 22:56:29 -07001897 }
Dianne Hackborn2862fff2009-09-15 22:56:29 -07001898 }
Jeff Brownd04a88c2011-01-16 14:05:47 -08001899
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001900 /** {@inheritDoc} */
Craig Mautner967212c2013-04-13 21:10:58 -07001901 @Override
Jeff Browndaa37532012-05-01 15:54:03 -07001902 public void adjustConfigurationLw(Configuration config, int keyboardPresence,
1903 int navigationPresence) {
1904 mHaveBuiltInKeyboard = (keyboardPresence & PRESENCE_INTERNAL) != 0;
1905
Jeff Brownf71343d2013-05-31 17:59:11 -07001906 readConfigurationDependentBehaviors();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001907 readLidState();
Jeff Brownc458ce92012-04-30 14:58:40 -07001908 applyLidSwitchState();
Jeff Brownd04a88c2011-01-16 14:05:47 -08001909
Jeff Browndaa37532012-05-01 15:54:03 -07001910 if (config.keyboard == Configuration.KEYBOARD_NOKEYS
1911 || (keyboardPresence == PRESENCE_INTERNAL
1912 && isHidden(mLidKeyboardAccessibility))) {
Jeff Brownd04a88c2011-01-16 14:05:47 -08001913 config.hardKeyboardHidden = Configuration.HARDKEYBOARDHIDDEN_YES;
Jeff Browndaa37532012-05-01 15:54:03 -07001914 if (!mHasSoftInput) {
1915 config.keyboardHidden = Configuration.KEYBOARDHIDDEN_YES;
1916 }
Jeff Brownd04a88c2011-01-16 14:05:47 -08001917 }
1918
Jeff Browndaa37532012-05-01 15:54:03 -07001919 if (config.navigation == Configuration.NAVIGATION_NONAV
1920 || (navigationPresence == PRESENCE_INTERNAL
1921 && isHidden(mLidNavigationAccessibility))) {
Jeff Brownd04a88c2011-01-16 14:05:47 -08001922 config.navigationHidden = Configuration.NAVIGATIONHIDDEN_YES;
Jeff Brownd04a88c2011-01-16 14:05:47 -08001923 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001924 }
Jeff Brownd04a88c2011-01-16 14:05:47 -08001925
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001926 /** {@inheritDoc} */
Craig Mautner967212c2013-04-13 21:10:58 -07001927 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001928 public int windowTypeToLayerLw(int type) {
1929 if (type >= FIRST_APPLICATION_WINDOW && type <= LAST_APPLICATION_WINDOW) {
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001930 return 2;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001931 }
1932 switch (type) {
keunyounga446bf02013-06-21 19:07:57 -07001933 case TYPE_PRIVATE_PRESENTATION:
1934 return 2;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001935 case TYPE_WALLPAPER:
1936 // wallpaper is at the bottom, though the window manager may move it.
1937 return 2;
1938 case TYPE_PHONE:
1939 return 3;
1940 case TYPE_SEARCH_BAR:
Jorim Jaggi225d3b52015-04-01 11:18:57 -07001941 case TYPE_VOICE_INTERACTION_STARTING:
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001942 return 4;
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001943 case TYPE_VOICE_INTERACTION:
1944 // voice interaction layer is almost immediately above apps.
1945 return 5;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001946 case TYPE_SYSTEM_DIALOG:
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001947 return 6;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001948 case TYPE_TOAST:
1949 // toasts and the plugged-in battery thing
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001950 return 7;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001951 case TYPE_PRIORITY_PHONE:
1952 // SIM errors and unlock. Not sure if this really should be in a high layer.
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001953 return 8;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001954 case TYPE_DREAM:
1955 // used for Dreams (screensavers with TYPE_DREAM windows)
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001956 return 9;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001957 case TYPE_SYSTEM_ALERT:
1958 // like the ANR / app crashed dialogs
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001959 return 10;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001960 case TYPE_INPUT_METHOD:
1961 // on-screen keyboards and other such input method user interfaces go here.
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001962 return 11;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001963 case TYPE_INPUT_METHOD_DIALOG:
1964 // on-screen keyboards and other such input method user interfaces go here.
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001965 return 12;
Jim Miller5ecd8112013-01-09 18:50:26 -08001966 case TYPE_KEYGUARD_SCRIM:
1967 // the safety window that shows behind keyguard while keyguard is starting
Jorim Jaggi380ecb82014-03-14 17:25:20 +01001968 return 13;
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001969 case TYPE_STATUS_BAR_SUB_PANEL:
Jorim Jaggi380ecb82014-03-14 17:25:20 +01001970 return 14;
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001971 case TYPE_STATUS_BAR:
Jorim Jaggi380ecb82014-03-14 17:25:20 +01001972 return 15;
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001973 case TYPE_STATUS_BAR_PANEL:
Jorim Jaggi380ecb82014-03-14 17:25:20 +01001974 return 16;
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001975 case TYPE_KEYGUARD_DIALOG:
1976 return 17;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001977 case TYPE_VOLUME_OVERLAY:
1978 // the on-screen volume indicator and controller shown when the user
1979 // changes the device volume
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001980 return 18;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001981 case TYPE_SYSTEM_OVERLAY:
1982 // the on-screen volume indicator and controller shown when the user
1983 // changes the device volume
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001984 return 19;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001985 case TYPE_NAVIGATION_BAR:
1986 // the navigation bar, if available, shows atop most things
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001987 return 20;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001988 case TYPE_NAVIGATION_BAR_PANEL:
1989 // some panels (e.g. search) need to show on top of the navigation bar
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001990 return 21;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001991 case TYPE_SYSTEM_ERROR:
1992 // system-level error dialogs
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001993 return 22;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001994 case TYPE_MAGNIFICATION_OVERLAY:
1995 // used to highlight the magnified portion of a display
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001996 return 23;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001997 case TYPE_DISPLAY_OVERLAY:
1998 // used to simulate secondary display devices
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001999 return 24;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07002000 case TYPE_DRAG:
2001 // the drag layer: input for drag-and-drop is associated with this window,
2002 // which sits above all other focusable windows
Jorim Jaggi380ecb82014-03-14 17:25:20 +01002003 return 25;
Svetoslav3a5c7212014-10-14 09:54:26 -07002004 case TYPE_ACCESSIBILITY_OVERLAY:
2005 // overlay put by accessibility services to intercept user interaction
Jorim Jaggi380ecb82014-03-14 17:25:20 +01002006 return 26;
Svetoslav3a5c7212014-10-14 09:54:26 -07002007 case TYPE_SECURE_SYSTEM_OVERLAY:
Dianne Hackborne30e02f2014-05-27 18:24:45 -07002008 return 27;
Svetoslav3a5c7212014-10-14 09:54:26 -07002009 case TYPE_BOOT_PROGRESS:
2010 return 28;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07002011 case TYPE_POINTER:
2012 // the (mouse) pointer layer
Dianne Hackborne30e02f2014-05-27 18:24:45 -07002013 return 29;
Svetoslav3a5c7212014-10-14 09:54:26 -07002014 case TYPE_HIDDEN_NAV_CONSUMER:
2015 return 30;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002016 }
2017 Log.e(TAG, "Unknown window type: " + type);
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07002018 return 2;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002019 }
2020
2021 /** {@inheritDoc} */
Craig Mautner46ac6fa2013-08-01 10:06:34 -07002022 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002023 public int subWindowTypeToLayerLw(int type) {
2024 switch (type) {
2025 case TYPE_APPLICATION_PANEL:
2026 case TYPE_APPLICATION_ATTACHED_DIALOG:
2027 return APPLICATION_PANEL_SUBLAYER;
2028 case TYPE_APPLICATION_MEDIA:
2029 return APPLICATION_MEDIA_SUBLAYER;
Dianne Hackborn5cb8d792009-05-21 17:34:15 -07002030 case TYPE_APPLICATION_MEDIA_OVERLAY:
2031 return APPLICATION_MEDIA_OVERLAY_SUBLAYER;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002032 case TYPE_APPLICATION_SUB_PANEL:
2033 return APPLICATION_SUB_PANEL_SUBLAYER;
Wale Ogunwale0a4dc222015-04-14 12:58:42 -07002034 case TYPE_APPLICATION_ABOVE_SUB_PANEL:
2035 return APPLICATION_ABOVE_SUB_PANEL_SUBLAYER;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002036 }
2037 Log.e(TAG, "Unknown sub-window type: " + type);
2038 return 0;
2039 }
2040
Craig Mautner46ac6fa2013-08-01 10:06:34 -07002041 @Override
Dianne Hackbornabe0da02009-09-18 01:55:39 -07002042 public int getMaxWallpaperLayer() {
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07002043 return windowTypeToLayerLw(TYPE_STATUS_BAR);
Dianne Hackbornabe0da02009-09-18 01:55:39 -07002044 }
2045
Craig Mautner46ac6fa2013-08-01 10:06:34 -07002046 @Override
Dianne Hackborn1f903c32011-09-13 19:18:06 -07002047 public int getNonDecorDisplayWidth(int fullWidth, int fullHeight, int rotation) {
Dianne Hackborn077ee852012-04-09 16:27:07 -07002048 if (mHasNavigationBar) {
2049 // For a basic navigation bar, when we are in landscape mode we place
2050 // the navigation bar to the side.
Daniel Sandler4a066c52012-04-20 14:49:13 -04002051 if (mNavigationBarCanMove && fullWidth > fullHeight) {
2052 return fullWidth - mNavigationBarWidthForRotation[rotation];
Dianne Hackborn077ee852012-04-09 16:27:07 -07002053 }
Dianne Hackborn1f903c32011-09-13 19:18:06 -07002054 }
2055 return fullWidth;
Dianne Hackborne2515ee2011-04-27 18:52:56 -04002056 }
2057
Jose Lima9546b202014-07-02 17:21:51 -07002058 @Override
Dianne Hackborn1f903c32011-09-13 19:18:06 -07002059 public int getNonDecorDisplayHeight(int fullWidth, int fullHeight, int rotation) {
Dianne Hackborn077ee852012-04-09 16:27:07 -07002060 if (mHasNavigationBar) {
2061 // For a basic navigation bar, when we are in portrait mode we place
2062 // the navigation bar to the bottom.
Daniel Sandler4a066c52012-04-20 14:49:13 -04002063 if (!mNavigationBarCanMove || fullWidth < fullHeight) {
2064 return fullHeight - mNavigationBarHeightForRotation[rotation];
Dianne Hackborn077ee852012-04-09 16:27:07 -07002065 }
2066 }
2067 return fullHeight;
Dianne Hackborn69cb8752011-05-19 18:13:32 -07002068 }
2069
Jose Lima9546b202014-07-02 17:21:51 -07002070 @Override
Dianne Hackborn1f903c32011-09-13 19:18:06 -07002071 public int getConfigDisplayWidth(int fullWidth, int fullHeight, int rotation) {
2072 return getNonDecorDisplayWidth(fullWidth, fullHeight, rotation);
Dianne Hackborn69cb8752011-05-19 18:13:32 -07002073 }
2074
Jose Lima9546b202014-07-02 17:21:51 -07002075 @Override
Dianne Hackborn1f903c32011-09-13 19:18:06 -07002076 public int getConfigDisplayHeight(int fullWidth, int fullHeight, int rotation) {
John Spurlock80f00c12013-06-13 11:10:51 -04002077 // There is a separate status bar at the top of the display. We don't count that as part
2078 // of the fixed decor, since it can hide; however, for purposes of configurations,
Dianne Hackborn077ee852012-04-09 16:27:07 -07002079 // we do want to exclude it since applications can't generally use that part
2080 // of the screen.
John Spurlock80f00c12013-06-13 11:10:51 -04002081 return getNonDecorDisplayHeight(fullWidth, fullHeight, rotation) - mStatusBarHeight;
Dianne Hackborne2515ee2011-04-27 18:52:56 -04002082 }
2083
Craig Mautnera3f4bf52012-10-10 20:37:48 -07002084 @Override
Craig Mautnerc9457fa2014-06-06 14:27:48 -07002085 public boolean isForceHiding(WindowManager.LayoutParams attrs) {
2086 return (attrs.privateFlags & PRIVATE_FLAG_KEYGUARD) != 0 ||
Jim Millerab954542014-10-10 18:21:49 -07002087 (isKeyguardHostWindow(attrs) &&
2088 (mKeyguardDelegate != null && mKeyguardDelegate.isShowing())) ||
Adrian Roos69e510d2014-07-13 14:57:59 +02002089 (attrs.type == TYPE_KEYGUARD_SCRIM);
Dianne Hackborn01ad2f42009-09-24 19:24:56 -07002090 }
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07002091
Craig Mautnera3f4bf52012-10-10 20:37:48 -07002092 @Override
Jorim Jaggi0d674622014-05-21 01:34:15 +02002093 public boolean isKeyguardHostWindow(WindowManager.LayoutParams attrs) {
2094 return attrs.type == TYPE_STATUS_BAR;
2095 }
2096
2097 @Override
Dianne Hackborn01ad2f42009-09-24 19:24:56 -07002098 public boolean canBeForceHidden(WindowState win, WindowManager.LayoutParams attrs) {
Craig Mautnera3f4bf52012-10-10 20:37:48 -07002099 switch (attrs.type) {
2100 case TYPE_STATUS_BAR:
2101 case TYPE_NAVIGATION_BAR:
2102 case TYPE_WALLPAPER:
2103 case TYPE_DREAM:
Jim Miller5ecd8112013-01-09 18:50:26 -08002104 case TYPE_KEYGUARD_SCRIM:
Craig Mautnera3f4bf52012-10-10 20:37:48 -07002105 return false;
2106 default:
2107 return true;
2108 }
Dianne Hackborn01ad2f42009-09-24 19:24:56 -07002109 }
Craig Mautner8e4df6c2012-05-23 16:57:23 -07002110
Craig Mautner7d7808f2014-09-11 18:02:38 -07002111 @Override
2112 public WindowState getWinShowWhenLockedLw() {
2113 return mWinShowWhenLocked;
2114 }
2115
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002116 /** {@inheritDoc} */
Craig Mautner8e4df6c2012-05-23 16:57:23 -07002117 @Override
Dianne Hackborn2f0b1752011-05-31 17:59:49 -07002118 public View addStartingWindow(IBinder appToken, String packageName, int theme,
2119 CompatibilityInfo compatInfo, CharSequence nonLocalizedLabel, int labelRes,
Adam Powell04fe6eb2013-05-31 14:39:48 -07002120 int icon, int logo, int windowFlags) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002121 if (!SHOW_STARTING_ANIMATIONS) {
2122 return null;
2123 }
2124 if (packageName == null) {
2125 return null;
2126 }
Craig Mautner8e4df6c2012-05-23 16:57:23 -07002127
Mathias Jeppssond1443e92012-08-24 15:25:32 +02002128 WindowManager wm = null;
2129 View view = null;
2130
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002131 try {
Dianne Hackborn867ab6472010-04-29 13:28:56 -07002132 Context context = mContext;
Craig Mautner6fbda632012-07-03 09:26:39 -07002133 if (DEBUG_STARTING_WINDOW) Slog.d(TAG, "addStartingWindow " + packageName
2134 + ": nonLocalizedLabel=" + nonLocalizedLabel + " theme="
2135 + Integer.toHexString(theme));
Dianne Hackborn247fe742011-01-08 17:25:57 -08002136 if (theme != context.getThemeResId() || labelRes != 0) {
Dianne Hackborn867ab6472010-04-29 13:28:56 -07002137 try {
2138 context = context.createPackageContext(packageName, 0);
Dianne Hackborn247fe742011-01-08 17:25:57 -08002139 context.setTheme(theme);
Dianne Hackborn867ab6472010-04-29 13:28:56 -07002140 } catch (PackageManager.NameNotFoundException e) {
2141 // Ignore
2142 }
2143 }
Craig Mautner8e4df6c2012-05-23 16:57:23 -07002144
Jorim Jaggib10e33f2015-02-04 21:57:40 +01002145 Window win = new PhoneWindow(context);
Craig Mautner8e4df6c2012-05-23 16:57:23 -07002146 final TypedArray ta = win.getWindowStyle();
2147 if (ta.getBoolean(
2148 com.android.internal.R.styleable.Window_windowDisablePreview, false)
2149 || ta.getBoolean(
2150 com.android.internal.R.styleable.Window_windowShowWallpaper,false)) {
Dianne Hackborn867ab6472010-04-29 13:28:56 -07002151 return null;
2152 }
Craig Mautner8e4df6c2012-05-23 16:57:23 -07002153
Dianne Hackborn867ab6472010-04-29 13:28:56 -07002154 Resources r = context.getResources();
2155 win.setTitle(r.getText(labelRes, nonLocalizedLabel));
Craig Mautner8e4df6c2012-05-23 16:57:23 -07002156
Dianne Hackborn867ab6472010-04-29 13:28:56 -07002157 win.setType(
2158 WindowManager.LayoutParams.TYPE_APPLICATION_STARTING);
Adrian Roos602c68e2015-04-24 16:03:47 -07002159
2160 synchronized (mWindowManagerFuncs.getWindowManagerLock()) {
2161 // Assumes it's safe to show starting windows of launched apps while
2162 // the keyguard is being hidden. This is okay because starting windows never show
2163 // secret information.
2164 if (mKeyguardHidden) {
2165 windowFlags |= FLAG_SHOW_WHEN_LOCKED;
2166 }
2167 }
2168
Dianne Hackborn867ab6472010-04-29 13:28:56 -07002169 // Force the window flags: this is a fake window, so it is not really
2170 // touchable or focusable by the user. We also add in the ALT_FOCUSABLE_IM
2171 // flag because we do know that the next window will take input
2172 // focus, so we want to get the IME window up on top of us right away.
2173 win.setFlags(
Dianne Hackborn7eec10e2010-11-12 18:03:47 -08002174 windowFlags|
Dianne Hackborn867ab6472010-04-29 13:28:56 -07002175 WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE|
2176 WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE|
2177 WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM,
Dianne Hackborn7eec10e2010-11-12 18:03:47 -08002178 windowFlags|
Dianne Hackborn867ab6472010-04-29 13:28:56 -07002179 WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE|
2180 WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE|
2181 WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM);
Craig Mautner8e4df6c2012-05-23 16:57:23 -07002182
Adam Powell04fe6eb2013-05-31 14:39:48 -07002183 win.setDefaultIcon(icon);
2184 win.setDefaultLogo(logo);
2185
Dianne Hackborn867ab6472010-04-29 13:28:56 -07002186 win.setLayout(WindowManager.LayoutParams.MATCH_PARENT,
Dianne Hackborn2f0b1752011-05-31 17:59:49 -07002187 WindowManager.LayoutParams.MATCH_PARENT);
Craig Mautner8e4df6c2012-05-23 16:57:23 -07002188
Dianne Hackborn867ab6472010-04-29 13:28:56 -07002189 final WindowManager.LayoutParams params = win.getAttributes();
2190 params.token = appToken;
2191 params.packageName = packageName;
2192 params.windowAnimations = win.getWindowStyle().getResourceId(
2193 com.android.internal.R.styleable.Window_windowAnimationStyle, 0);
John Reck61375a82014-09-18 19:27:48 +00002194 params.privateFlags |=
2195 WindowManager.LayoutParams.PRIVATE_FLAG_FAKE_HARDWARE_ACCELERATED;
Craig Mautner88400d32012-09-30 12:35:45 -07002196 params.privateFlags |= WindowManager.LayoutParams.PRIVATE_FLAG_SHOW_FOR_ALL_USERS;
Adam Lesinski95c42972013-10-02 10:13:27 -07002197
2198 if (!compatInfo.supportsScreen()) {
2199 params.privateFlags |= WindowManager.LayoutParams.PRIVATE_FLAG_COMPATIBLE_WINDOW;
2200 }
2201
Dianne Hackborn867ab6472010-04-29 13:28:56 -07002202 params.setTitle("Starting " + packageName);
2203
Mathias Jeppssond1443e92012-08-24 15:25:32 +02002204 wm = (WindowManager)context.getSystemService(Context.WINDOW_SERVICE);
2205 view = win.getDecorView();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002206
2207 if (win.isFloating()) {
2208 // Whoops, there is no way to display an animation/preview
2209 // of such a thing! After all that work... let's skip it.
2210 // (Note that we must do this here because it is in
2211 // getDecorView() where the theme is evaluated... maybe
2212 // we should peek the floating attribute from the theme
2213 // earlier.)
2214 return null;
2215 }
Craig Mautner8e4df6c2012-05-23 16:57:23 -07002216
Craig Mautner6fbda632012-07-03 09:26:39 -07002217 if (DEBUG_STARTING_WINDOW) Slog.d(
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002218 TAG, "Adding starting window for " + packageName
2219 + " / " + appToken + ": "
2220 + (view.getParent() != null ? view : null));
2221
2222 wm.addView(view, params);
2223
2224 // Only return the view if it was successfully added to the
2225 // window manager... which we can tell by it having a parent.
2226 return view.getParent() != null ? view : null;
Jeff Brown98365d72012-08-19 20:30:52 -07002227 } catch (WindowManager.BadTokenException e) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002228 // ignore
Craig Mautner42bf39e2014-02-21 16:46:22 -08002229 Log.w(TAG, appToken + " already running, starting window not displayed. " +
2230 e.getMessage());
Dianne Hackborn867ab6472010-04-29 13:28:56 -07002231 } catch (RuntimeException e) {
2232 // don't crash if something else bad happens, for example a
2233 // failure loading resources because we are loading from an app
2234 // on external storage that has been unmounted.
2235 Log.w(TAG, appToken + " failed creating starting window", e);
Mathias Jeppssond1443e92012-08-24 15:25:32 +02002236 } finally {
2237 if (view != null && view.getParent() == null) {
2238 Log.w(TAG, "view not successfully added to wm, removing view");
2239 wm.removeViewImmediate(view);
2240 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002241 }
2242
2243 return null;
2244 }
2245
2246 /** {@inheritDoc} */
Jose Lima9546b202014-07-02 17:21:51 -07002247 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002248 public void removeStartingWindow(IBinder appToken, View window) {
Craig Mautner276a6eb2014-11-04 15:32:57 -08002249 if (DEBUG_STARTING_WINDOW) Slog.v(TAG, "Removing starting window for " + appToken + ": "
2250 + window + " Callers=" + Debug.getCallers(4));
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002251
2252 if (window != null) {
Dianne Hackborn5fd21692011-06-07 14:09:47 -07002253 WindowManager wm = (WindowManager)mContext.getSystemService(Context.WINDOW_SERVICE);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002254 wm.removeView(window);
2255 }
2256 }
2257
2258 /**
2259 * Preflight adding a window to the system.
RoboErik8a2cfc32014-05-16 11:19:38 -07002260 *
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002261 * Currently enforces that three window types are singletons:
2262 * <ul>
2263 * <li>STATUS_BAR_TYPE</li>
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002264 * <li>KEYGUARD_TYPE</li>
2265 * </ul>
RoboErik8a2cfc32014-05-16 11:19:38 -07002266 *
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002267 * @param win The window to be added
2268 * @param attrs Information about the window to be added
RoboErik8a2cfc32014-05-16 11:19:38 -07002269 *
Jeff Brown98365d72012-08-19 20:30:52 -07002270 * @return If ok, WindowManagerImpl.ADD_OKAY. If too many singletons,
2271 * WindowManagerImpl.ADD_MULTIPLE_SINGLETON
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002272 */
Jose Lima9546b202014-07-02 17:21:51 -07002273 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002274 public int prepareAddWindowLw(WindowState win, WindowManager.LayoutParams attrs) {
2275 switch (attrs.type) {
2276 case TYPE_STATUS_BAR:
Joe Onorato8bc6c512010-06-04 16:21:12 -04002277 mContext.enforceCallingOrSelfPermission(
2278 android.Manifest.permission.STATUS_BAR_SERVICE,
2279 "PhoneWindowManager");
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002280 if (mStatusBar != null) {
Dianne Hackbornf87d1962012-04-04 12:48:24 -07002281 if (mStatusBar.isAlive()) {
Jeff Brown98365d72012-08-19 20:30:52 -07002282 return WindowManagerGlobal.ADD_MULTIPLE_SINGLETON;
Dianne Hackbornf87d1962012-04-04 12:48:24 -07002283 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002284 }
2285 mStatusBar = win;
John Spurlock27735a42013-08-14 17:57:38 -04002286 mStatusBarController.setWindow(win);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002287 break;
Daniel Sandler8956dbb2011-04-22 07:55:02 -04002288 case TYPE_NAVIGATION_BAR:
2289 mContext.enforceCallingOrSelfPermission(
2290 android.Manifest.permission.STATUS_BAR_SERVICE,
2291 "PhoneWindowManager");
Dianne Hackbornf87d1962012-04-04 12:48:24 -07002292 if (mNavigationBar != null) {
2293 if (mNavigationBar.isAlive()) {
Jeff Brown98365d72012-08-19 20:30:52 -07002294 return WindowManagerGlobal.ADD_MULTIPLE_SINGLETON;
Dianne Hackbornf87d1962012-04-04 12:48:24 -07002295 }
2296 }
Daniel Sandler8956dbb2011-04-22 07:55:02 -04002297 mNavigationBar = win;
John Spurlock27735a42013-08-14 17:57:38 -04002298 mNavigationBarController.setWindow(win);
Craig Mautnereda67292013-04-28 13:50:14 -07002299 if (DEBUG_LAYOUT) Slog.i(TAG, "NAVIGATION BAR: " + mNavigationBar);
Daniel Sandler8956dbb2011-04-22 07:55:02 -04002300 break;
Jim Millere898ac52012-04-06 17:10:57 -07002301 case TYPE_NAVIGATION_BAR_PANEL:
Dianne Hackborn08743722009-12-21 12:16:51 -08002302 case TYPE_STATUS_BAR_PANEL:
Joe Onorato29fc2c92010-11-24 10:26:50 -08002303 case TYPE_STATUS_BAR_SUB_PANEL:
Jorim Jaggi225d3b52015-04-01 11:18:57 -07002304 case TYPE_VOICE_INTERACTION_STARTING:
Joe Onorato29fc2c92010-11-24 10:26:50 -08002305 mContext.enforceCallingOrSelfPermission(
2306 android.Manifest.permission.STATUS_BAR_SERVICE,
2307 "PhoneWindowManager");
Joe Onorato29fc2c92010-11-24 10:26:50 -08002308 break;
Jim Miller5ecd8112013-01-09 18:50:26 -08002309 case TYPE_KEYGUARD_SCRIM:
Jim Miller25190572013-02-28 17:36:24 -08002310 if (mKeyguardScrim != null) {
2311 return WindowManagerGlobal.ADD_MULTIPLE_SINGLETON;
2312 }
Jim Miller5ecd8112013-01-09 18:50:26 -08002313 mKeyguardScrim = win;
2314 break;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002315 }
Jeff Brown98365d72012-08-19 20:30:52 -07002316 return WindowManagerGlobal.ADD_OKAY;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002317 }
2318
2319 /** {@inheritDoc} */
Jose Lima9546b202014-07-02 17:21:51 -07002320 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002321 public void removeWindowLw(WindowState win) {
2322 if (mStatusBar == win) {
2323 mStatusBar = null;
John Spurlock27735a42013-08-14 17:57:38 -04002324 mStatusBarController.setWindow(null);
Jim Millerc0b676d2013-03-22 16:11:08 -07002325 mKeyguardDelegate.showScrim();
Jim Miller5ecd8112013-01-09 18:50:26 -08002326 } else if (mKeyguardScrim == win) {
2327 Log.v(TAG, "Removing keyguard scrim");
2328 mKeyguardScrim = null;
2329 } if (mNavigationBar == win) {
Daniel Sandler8956dbb2011-04-22 07:55:02 -04002330 mNavigationBar = null;
John Spurlock27735a42013-08-14 17:57:38 -04002331 mNavigationBarController.setWindow(null);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002332 }
2333 }
2334
2335 static final boolean PRINT_ANIM = false;
RoboErik8a2cfc32014-05-16 11:19:38 -07002336
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002337 /** {@inheritDoc} */
Craig Mautner4b71aa12012-12-27 17:20:01 -08002338 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002339 public int selectAnimationLw(WindowState win, int transit) {
2340 if (PRINT_ANIM) Log.i(TAG, "selectAnimation in " + win
2341 + ": transit=" + transit);
Dianne Hackbornf87d1962012-04-04 12:48:24 -07002342 if (win == mStatusBar) {
Jorim Jaggi380ecb82014-03-14 17:25:20 +01002343 boolean isKeyguard = (win.getAttrs().privateFlags & PRIVATE_FLAG_KEYGUARD) != 0;
Craig Mautner4b71aa12012-12-27 17:20:01 -08002344 if (transit == TRANSIT_EXIT
2345 || transit == TRANSIT_HIDE) {
Jorim Jaggi380ecb82014-03-14 17:25:20 +01002346 return isKeyguard ? -1 : R.anim.dock_top_exit;
Craig Mautner4b71aa12012-12-27 17:20:01 -08002347 } else if (transit == TRANSIT_ENTER
2348 || transit == TRANSIT_SHOW) {
Jorim Jaggi380ecb82014-03-14 17:25:20 +01002349 return isKeyguard ? -1 : R.anim.dock_top_enter;
Dianne Hackbornf87d1962012-04-04 12:48:24 -07002350 }
2351 } else if (win == mNavigationBar) {
2352 // This can be on either the bottom or the right.
2353 if (mNavigationBarOnBottom) {
Craig Mautner4b71aa12012-12-27 17:20:01 -08002354 if (transit == TRANSIT_EXIT
2355 || transit == TRANSIT_HIDE) {
Dianne Hackbornf87d1962012-04-04 12:48:24 -07002356 return R.anim.dock_bottom_exit;
Craig Mautner4b71aa12012-12-27 17:20:01 -08002357 } else if (transit == TRANSIT_ENTER
2358 || transit == TRANSIT_SHOW) {
Dianne Hackbornf87d1962012-04-04 12:48:24 -07002359 return R.anim.dock_bottom_enter;
2360 }
2361 } else {
Craig Mautner4b71aa12012-12-27 17:20:01 -08002362 if (transit == TRANSIT_EXIT
2363 || transit == TRANSIT_HIDE) {
Dianne Hackbornf87d1962012-04-04 12:48:24 -07002364 return R.anim.dock_right_exit;
Craig Mautner4b71aa12012-12-27 17:20:01 -08002365 } else if (transit == TRANSIT_ENTER
2366 || transit == TRANSIT_SHOW) {
Dianne Hackbornf87d1962012-04-04 12:48:24 -07002367 return R.anim.dock_right_enter;
2368 }
2369 }
Craig Mautner4b71aa12012-12-27 17:20:01 -08002370 }
2371
2372 if (transit == TRANSIT_PREVIEW_DONE) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002373 if (win.hasAppShownWindows()) {
2374 if (PRINT_ANIM) Log.i(TAG, "**** STARTING EXIT");
2375 return com.android.internal.R.anim.app_starting_exit;
2376 }
Dianne Hackborn7ad44382012-10-18 17:46:00 -07002377 } else if (win.getAttrs().type == TYPE_DREAM && mDreamingLockscreen
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07002378 && transit == TRANSIT_ENTER) {
2379 // Special case: we are animating in a dream, while the keyguard
2380 // is shown. We don't want an animation on the dream, because
2381 // we need it shown immediately with the keyguard animating away
2382 // to reveal it.
2383 return -1;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002384 }
2385
2386 return 0;
2387 }
2388
Craig Mautner3c174372013-02-21 17:54:37 -08002389 @Override
2390 public void selectRotationAnimationLw(int anim[]) {
2391 if (PRINT_ANIM) Slog.i(TAG, "selectRotationAnimation mTopFullscreen="
2392 + mTopFullscreenOpaqueWindowState + " rotationAnimation="
2393 + (mTopFullscreenOpaqueWindowState == null ?
2394 "0" : mTopFullscreenOpaqueWindowState.getAttrs().rotationAnimation));
2395 if (mTopFullscreenOpaqueWindowState != null && mTopIsFullscreen) {
2396 switch (mTopFullscreenOpaqueWindowState.getAttrs().rotationAnimation) {
2397 case ROTATION_ANIMATION_CROSSFADE:
2398 anim[0] = R.anim.rotation_animation_xfade_exit;
2399 anim[1] = R.anim.rotation_animation_enter;
2400 break;
2401 case ROTATION_ANIMATION_JUMPCUT:
2402 anim[0] = R.anim.rotation_animation_jump_exit;
2403 anim[1] = R.anim.rotation_animation_enter;
2404 break;
2405 case ROTATION_ANIMATION_ROTATE:
2406 default:
2407 anim[0] = anim[1] = 0;
2408 break;
2409 }
2410 } else {
2411 anim[0] = anim[1] = 0;
2412 }
2413 }
2414
2415 @Override
2416 public boolean validateRotationAnimationLw(int exitAnimId, int enterAnimId,
2417 boolean forceDefault) {
2418 switch (exitAnimId) {
2419 case R.anim.rotation_animation_xfade_exit:
2420 case R.anim.rotation_animation_jump_exit:
2421 // These are the only cases that matter.
2422 if (forceDefault) {
2423 return false;
2424 }
2425 int anim[] = new int[2];
2426 selectRotationAnimationLw(anim);
2427 return (exitAnimId == anim[0] && enterAnimId == anim[1]);
2428 default:
2429 return true;
2430 }
2431 }
2432
2433 @Override
Jorim Jaggi84a3e7a2014-08-13 17:58:58 +02002434 public Animation createForceHideEnterAnimation(boolean onWallpaper,
2435 boolean goingToNotificationShade) {
2436 if (goingToNotificationShade) {
2437 return AnimationUtils.loadAnimation(mContext, R.anim.lock_screen_behind_enter_fade_in);
Craig Mautnerb8340802014-11-04 15:32:57 -08002438 }
Craig Mautner276a6eb2014-11-04 15:32:57 -08002439
2440 AnimationSet set = (AnimationSet) AnimationUtils.loadAnimation(mContext, onWallpaper ?
2441 R.anim.lock_screen_behind_enter_wallpaper :
2442 R.anim.lock_screen_behind_enter);
2443
2444 // TODO: Use XML interpolators when we have log interpolators available in XML.
2445 final List<Animation> animations = set.getAnimations();
2446 for (int i = animations.size() - 1; i >= 0; --i) {
2447 animations.get(i).setInterpolator(mLogDecelerateInterpolator);
2448 }
2449
2450 return set;
Jorim Jaggi76a16232014-08-08 17:00:47 +02002451 }
2452
2453
2454 @Override
Jorim Jaggi84a3e7a2014-08-13 17:58:58 +02002455 public Animation createForceHideWallpaperExitAnimation(boolean goingToNotificationShade) {
2456 if (goingToNotificationShade) {
2457 return null;
2458 } else {
2459 return AnimationUtils.loadAnimation(mContext, R.anim.lock_screen_wallpaper_exit);
2460 }
Dianne Hackborn01ad2f42009-09-24 19:24:56 -07002461 }
John Spurlockc8b46ca2013-04-08 12:59:26 -04002462
2463 private static void awakenDreams() {
2464 IDreamManager dreamManager = getDreamManager();
2465 if (dreamManager != null) {
2466 try {
2467 dreamManager.awaken();
2468 } catch (RemoteException e) {
2469 // fine, stay asleep then
2470 }
2471 }
2472 }
2473
2474 static IDreamManager getDreamManager() {
2475 return IDreamManager.Stub.asInterface(
2476 ServiceManager.checkService(DreamService.DREAM_SERVICE));
2477 }
2478
Tyler Gunnef9f6f92014-09-12 22:16:17 -07002479 TelecomManager getTelecommService() {
2480 return (TelecomManager) mContext.getSystemService(Context.TELECOM_SERVICE);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002481 }
2482
Jeff Brown4d396052010-10-29 21:50:21 -07002483 static IAudioService getAudioService() {
2484 IAudioService audioService = IAudioService.Stub.asInterface(
2485 ServiceManager.checkService(Context.AUDIO_SERVICE));
2486 if (audioService == null) {
2487 Log.w(TAG, "Unable to find IAudioService interface.");
2488 }
2489 return audioService;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002490 }
2491
2492 boolean keyguardOn() {
Jim Millerab954542014-10-10 18:21:49 -07002493 return isKeyguardShowingAndNotOccluded() || inKeyguardRestrictedKeyInputMode();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002494 }
2495
2496 private static final int[] WINDOW_TYPES_WHERE_HOME_DOESNT_WORK = {
2497 WindowManager.LayoutParams.TYPE_SYSTEM_ALERT,
2498 WindowManager.LayoutParams.TYPE_SYSTEM_ERROR,
2499 };
2500
2501 /** {@inheritDoc} */
Jeff Brown00fa7bd2010-07-02 15:37:36 -07002502 @Override
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002503 public long interceptKeyBeforeDispatching(WindowState win, KeyEvent event, int policyFlags) {
Jeff Brown00fa7bd2010-07-02 15:37:36 -07002504 final boolean keyguardOn = keyguardOn();
Jeff Brown1f245102010-11-18 20:53:46 -08002505 final int keyCode = event.getKeyCode();
2506 final int repeatCount = event.getRepeatCount();
2507 final int metaState = event.getMetaState();
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002508 final int flags = event.getFlags();
Jeff Brown1f245102010-11-18 20:53:46 -08002509 final boolean down = event.getAction() == KeyEvent.ACTION_DOWN;
2510 final boolean canceled = event.isCanceled();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002511
Jeff Brown40013652012-05-16 21:22:36 -07002512 if (DEBUG_INPUT) {
Jeff Brown00fa7bd2010-07-02 15:37:36 -07002513 Log.d(TAG, "interceptKeyTi keyCode=" + keyCode + " down=" + down + " repeatCount="
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002514 + repeatCount + " keyguardOn=" + keyguardOn + " mHomePressed=" + mHomePressed
2515 + " canceled=" + canceled);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002516 }
2517
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002518 // If we think we might have a volume down & power key chord on the way
2519 // but we're not sure, then tell the dispatcher to wait a little while and
2520 // try again later before dispatching.
Christopher Tatee90585f2012-03-05 18:56:25 -08002521 if (mScreenshotChordEnabled && (flags & KeyEvent.FLAG_FALLBACK) == 0) {
Jeff Brown13f00f02014-10-31 14:45:50 -07002522 if (mScreenshotChordVolumeDownKeyTriggered && !mScreenshotChordPowerKeyTriggered) {
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002523 final long now = SystemClock.uptimeMillis();
Jeff Brown13f00f02014-10-31 14:45:50 -07002524 final long timeoutTime = mScreenshotChordVolumeDownKeyTime
2525 + SCREENSHOT_CHORD_DEBOUNCE_DELAY_MILLIS;
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002526 if (now < timeoutTime) {
2527 return timeoutTime - now;
2528 }
2529 }
2530 if (keyCode == KeyEvent.KEYCODE_VOLUME_DOWN
Jeff Brown13f00f02014-10-31 14:45:50 -07002531 && mScreenshotChordVolumeDownKeyConsumed) {
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002532 if (!down) {
Jeff Brown13f00f02014-10-31 14:45:50 -07002533 mScreenshotChordVolumeDownKeyConsumed = false;
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002534 }
2535 return -1;
2536 }
2537 }
2538
Michael Wright6a62e552014-06-03 19:19:48 -07002539 // Cancel any pending meta actions if we see any other keys being pressed between the down
2540 // of the meta key and its corresponding up.
Michael Wright251e35d2014-08-22 15:40:27 -07002541 if (mPendingMetaAction && !KeyEvent.isMetaKey(keyCode)) {
Michael Wright6a62e552014-06-03 19:19:48 -07002542 mPendingMetaAction = false;
2543 }
2544
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002545 // First we always handle the home key here, so applications
2546 // can never break it, although if keyguard is on, we do let
2547 // it handle it, because that gives us the correct 5 second
2548 // timeout.
Jeff Brown00fa7bd2010-07-02 15:37:36 -07002549 if (keyCode == KeyEvent.KEYCODE_HOME) {
Michael Jurka7f2668c2012-03-27 07:49:52 -07002550
Jeff Brown49ed71d2010-12-06 17:13:33 -08002551 // If we have released the home key, and didn't do anything else
2552 // while it was pressed, then it is time to go home!
Michael Jurka7f2668c2012-03-27 07:49:52 -07002553 if (!down) {
Jeff Browncaca8812013-05-09 13:34:33 -07002554 cancelPreloadRecentApps();
2555
Jeff Brown49ed71d2010-12-06 17:13:33 -08002556 mHomePressed = false;
Jeff Browncaca8812013-05-09 13:34:33 -07002557 if (mHomeConsumed) {
2558 mHomeConsumed = false;
Michael Jurka7f2668c2012-03-27 07:49:52 -07002559 return -1;
Jeff Brown49ed71d2010-12-06 17:13:33 -08002560 }
Jeff Browncaca8812013-05-09 13:34:33 -07002561
2562 if (canceled) {
2563 Log.i(TAG, "Ignoring HOME; event canceled.");
2564 return -1;
2565 }
2566
Yorke Lee4f803242014-12-15 23:22:06 +00002567 // If an incoming call is ringing, HOME is totally disabled.
2568 // (The user is already on the InCallUI at this point,
2569 // and his ONLY options are to answer or reject the call.)
2570 TelecomManager telecomManager = getTelecommService();
2571 if (telecomManager != null && telecomManager.isRinging()) {
2572 Log.i(TAG, "Ignoring HOME; there's a ringing incoming call.");
2573 return -1;
2574 }
2575
Jeff Browncaca8812013-05-09 13:34:33 -07002576 // Delay handling home if a double-tap is possible.
2577 if (mDoubleTapOnHomeBehavior != DOUBLE_TAP_HOME_NOTHING) {
2578 mHandler.removeCallbacks(mHomeDoubleTapTimeoutRunnable); // just in case
2579 mHomeDoubleTapPending = true;
2580 mHandler.postDelayed(mHomeDoubleTapTimeoutRunnable,
2581 ViewConfiguration.getDoubleTapTimeout());
2582 return -1;
2583 }
2584
Jeff Brown13f00f02014-10-31 14:45:50 -07002585 handleShortPressOnHome();
Jeff Browncaca8812013-05-09 13:34:33 -07002586 return -1;
Jeff Brown49ed71d2010-12-06 17:13:33 -08002587 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002588
2589 // If a system window has focus, then it doesn't make sense
2590 // right now to interact with applications.
2591 WindowManager.LayoutParams attrs = win != null ? win.getAttrs() : null;
2592 if (attrs != null) {
2593 final int type = attrs.type;
Jorim Jaggi380ecb82014-03-14 17:25:20 +01002594 if (type == WindowManager.LayoutParams.TYPE_KEYGUARD_SCRIM
2595 || type == WindowManager.LayoutParams.TYPE_KEYGUARD_DIALOG
2596 || (attrs.privateFlags & PRIVATE_FLAG_KEYGUARD) != 0) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002597 // the "app" is keyguard, so give it the key
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002598 return 0;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002599 }
2600 final int typeCount = WINDOW_TYPES_WHERE_HOME_DOESNT_WORK.length;
2601 for (int i=0; i<typeCount; i++) {
2602 if (type == WINDOW_TYPES_WHERE_HOME_DOESNT_WORK[i]) {
2603 // don't do anything, but also don't pass it to the app
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002604 return -1;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002605 }
2606 }
2607 }
Jeff Browncaca8812013-05-09 13:34:33 -07002608
2609 // Remember that home is pressed and handle special actions.
2610 if (repeatCount == 0) {
2611 mHomePressed = true;
2612 if (mHomeDoubleTapPending) {
2613 mHomeDoubleTapPending = false;
2614 mHandler.removeCallbacks(mHomeDoubleTapTimeoutRunnable);
2615 handleDoubleTapOnHome();
2616 } else if (mLongPressOnHomeBehavior == LONG_PRESS_HOME_RECENT_SYSTEM_UI
2617 || mDoubleTapOnHomeBehavior == DOUBLE_TAP_HOME_RECENT_SYSTEM_UI) {
2618 preloadRecentApps();
Michael Jurka7f2668c2012-03-27 07:49:52 -07002619 }
Jeff Browncaca8812013-05-09 13:34:33 -07002620 } else if ((event.getFlags() & KeyEvent.FLAG_LONG_PRESS) != 0) {
2621 if (!keyguardOn) {
2622 handleLongPressOnHome();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002623 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002624 }
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002625 return -1;
Jeff Brown00fa7bd2010-07-02 15:37:36 -07002626 } else if (keyCode == KeyEvent.KEYCODE_MENU) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002627 // Hijack modified menu keys for debugging features
2628 final int chordBug = KeyEvent.META_SHIFT_ON;
2629
2630 if (down && repeatCount == 0) {
Jeff Brown00fa7bd2010-07-02 15:37:36 -07002631 if (mEnableShiftMenuBugReports && (metaState & chordBug) == chordBug) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002632 Intent intent = new Intent(Intent.ACTION_BUG_REPORT);
Dianne Hackborn5ac72a22012-08-29 18:32:08 -07002633 mContext.sendOrderedBroadcastAsUser(intent, UserHandle.CURRENT,
2634 null, null, null, 0, null, null);
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002635 return -1;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002636 } else if (SHOW_PROCESSES_ON_ALT_MENU &&
Jeff Brown00fa7bd2010-07-02 15:37:36 -07002637 (metaState & KeyEvent.META_ALT_ON) == KeyEvent.META_ALT_ON) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002638 Intent service = new Intent();
2639 service.setClassName(mContext, "com.android.server.LoadAverageService");
2640 ContentResolver res = mContext.getContentResolver();
Jeff Sharkey8d9a1f62012-10-18 15:38:14 -07002641 boolean shown = Settings.Global.getInt(
2642 res, Settings.Global.SHOW_PROCESSES, 0) != 0;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002643 if (!shown) {
2644 mContext.startService(service);
2645 } else {
2646 mContext.stopService(service);
2647 }
Jeff Sharkey8d9a1f62012-10-18 15:38:14 -07002648 Settings.Global.putInt(
2649 res, Settings.Global.SHOW_PROCESSES, shown ? 0 : 1);
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002650 return -1;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002651 }
2652 }
Jeff Brown00fa7bd2010-07-02 15:37:36 -07002653 } else if (keyCode == KeyEvent.KEYCODE_SEARCH) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002654 if (down) {
2655 if (repeatCount == 0) {
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002656 mSearchKeyShortcutPending = true;
2657 mConsumeSearchKeyUp = false;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002658 }
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002659 } else {
2660 mSearchKeyShortcutPending = false;
2661 if (mConsumeSearchKeyUp) {
2662 mConsumeSearchKeyUp = false;
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002663 return -1;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002664 }
2665 }
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002666 return 0;
Jeff Brown49ed71d2010-12-06 17:13:33 -08002667 } else if (keyCode == KeyEvent.KEYCODE_APP_SWITCH) {
Michael Wrightc9ebea72013-01-16 19:25:02 -08002668 if (!keyguardOn) {
Jeff Browncaca8812013-05-09 13:34:33 -07002669 if (down && repeatCount == 0) {
2670 preloadRecentApps();
2671 } else if (!down) {
2672 toggleRecentApps();
Michael Wrightc9ebea72013-01-16 19:25:02 -08002673 }
Jeff Brown49ed71d2010-12-06 17:13:33 -08002674 }
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002675 return -1;
Jeff Brownde7a8ea2012-06-13 18:28:57 -07002676 } else if (keyCode == KeyEvent.KEYCODE_ASSIST) {
2677 if (down) {
2678 if (repeatCount == 0) {
2679 mAssistKeyLongPressed = false;
2680 } else if (repeatCount == 1) {
2681 mAssistKeyLongPressed = true;
2682 if (!keyguardOn) {
2683 launchAssistLongPressAction();
2684 }
2685 }
2686 } else {
2687 if (mAssistKeyLongPressed) {
2688 mAssistKeyLongPressed = false;
2689 } else {
2690 if (!keyguardOn) {
2691 launchAssistAction();
2692 }
2693 }
2694 }
2695 return -1;
Michael Wrightdc63f7b2014-08-21 19:05:21 -07002696 } else if (keyCode == KeyEvent.KEYCODE_VOICE_ASSIST) {
2697 if (!down) {
2698 Intent voiceIntent;
Michael Wright869a67c2014-08-26 19:33:06 -07002699 if (!keyguardOn) {
Michael Wrightdc63f7b2014-08-21 19:05:21 -07002700 voiceIntent = new Intent(RecognizerIntent.ACTION_WEB_SEARCH);
2701 } else {
2702 voiceIntent = new Intent(RecognizerIntent.ACTION_VOICE_SEARCH_HANDS_FREE);
Michael Wright869a67c2014-08-26 19:33:06 -07002703 voiceIntent.putExtra(RecognizerIntent.EXTRA_SECURE, true);
Michael Wrightdc63f7b2014-08-21 19:05:21 -07002704 }
Bart Sears8b1c27c2015-03-18 23:51:02 +00002705 startActivityAsUser(voiceIntent, UserHandle.CURRENT_OR_SELF);
Michael Wrightdc63f7b2014-08-21 19:05:21 -07002706 }
Jeff Sharkey2991fa32012-12-05 18:06:43 -08002707 } else if (keyCode == KeyEvent.KEYCODE_SYSRQ) {
2708 if (down && repeatCount == 0) {
2709 mHandler.post(mScreenshotRunnable);
2710 }
2711 return -1;
Michael Wrightb854e242013-02-05 17:54:02 -08002712 } else if (keyCode == KeyEvent.KEYCODE_BRIGHTNESS_UP
2713 || keyCode == KeyEvent.KEYCODE_BRIGHTNESS_DOWN) {
2714 if (down) {
2715 int direction = keyCode == KeyEvent.KEYCODE_BRIGHTNESS_UP ? 1 : -1;
2716
2717 // Disable autobrightness if it's on
2718 int auto = Settings.System.getIntForUser(
2719 mContext.getContentResolver(),
2720 Settings.System.SCREEN_BRIGHTNESS_MODE,
2721 Settings.System.SCREEN_BRIGHTNESS_MODE_MANUAL,
2722 UserHandle.USER_CURRENT_OR_SELF);
2723 if (auto != 0) {
2724 Settings.System.putIntForUser(mContext.getContentResolver(),
2725 Settings.System.SCREEN_BRIGHTNESS_MODE,
2726 Settings.System.SCREEN_BRIGHTNESS_MODE_MANUAL,
2727 UserHandle.USER_CURRENT_OR_SELF);
2728 }
2729
2730 int min = mPowerManager.getMinimumScreenBrightnessSetting();
2731 int max = mPowerManager.getMaximumScreenBrightnessSetting();
2732 int step = (max - min + BRIGHTNESS_STEPS - 1) / BRIGHTNESS_STEPS * direction;
2733 int brightness = Settings.System.getIntForUser(mContext.getContentResolver(),
2734 Settings.System.SCREEN_BRIGHTNESS,
2735 mPowerManager.getDefaultScreenBrightnessSetting(),
2736 UserHandle.USER_CURRENT_OR_SELF);
2737 brightness += step;
2738 // Make sure we don't go beyond the limits.
2739 brightness = Math.min(max, brightness);
2740 brightness = Math.max(min, brightness);
2741
2742 Settings.System.putIntForUser(mContext.getContentResolver(),
2743 Settings.System.SCREEN_BRIGHTNESS, brightness,
2744 UserHandle.USER_CURRENT_OR_SELF);
Bart Sears8b1c27c2015-03-18 23:51:02 +00002745 startActivityAsUser(new Intent(Intent.ACTION_SHOW_BRIGHTNESS_DIALOG),
Alan Viverette5a399492014-07-14 16:19:38 -07002746 UserHandle.CURRENT_OR_SELF);
Michael Wrightb854e242013-02-05 17:54:02 -08002747 }
2748 return -1;
Michael Wrightce0c13a2014-07-30 10:49:21 -07002749 } else if (KeyEvent.isMetaKey(keyCode)) {
Michael Wright6a62e552014-06-03 19:19:48 -07002750 if (down) {
2751 mPendingMetaAction = true;
2752 } else if (mPendingMetaAction) {
Michael Wright8ab940a2014-09-01 11:01:27 -07002753 launchAssistAction(Intent.EXTRA_ASSIST_INPUT_HINT_KEYBOARD);
Michael Wright6a62e552014-06-03 19:19:48 -07002754 }
2755 return -1;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002756 }
Jeff Browncaab4d02010-12-09 22:13:41 -08002757
Jeff Brownc1fb48d2010-12-08 16:52:09 -08002758 // Shortcuts are invoked through Search+key, so intercept those here
Jeff Browncaab4d02010-12-09 22:13:41 -08002759 // Any printing key that is chorded with Search should be consumed
2760 // even if no shortcut was invoked. This prevents text from being
2761 // inadvertently inserted when using a keyboard that has built-in macro
2762 // shortcut keys (that emit Search+x) and some of them are not registered.
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002763 if (mSearchKeyShortcutPending) {
Jeff Browncaab4d02010-12-09 22:13:41 -08002764 final KeyCharacterMap kcm = event.getKeyCharacterMap();
2765 if (kcm.isPrintingKey(keyCode)) {
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002766 mConsumeSearchKeyUp = true;
2767 mSearchKeyShortcutPending = false;
Jeff Browncaab4d02010-12-09 22:13:41 -08002768 if (down && repeatCount == 0 && !keyguardOn) {
2769 Intent shortcutIntent = mShortcutManager.getIntent(kcm, keyCode, metaState);
2770 if (shortcutIntent != null) {
2771 shortcutIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
Jeff Brownf0a3cc52011-01-26 18:42:46 -08002772 try {
Bart Sears8b1c27c2015-03-18 23:51:02 +00002773 startActivityAsUser(shortcutIntent, UserHandle.CURRENT);
Jeff Brownf0a3cc52011-01-26 18:42:46 -08002774 } catch (ActivityNotFoundException ex) {
2775 Slog.w(TAG, "Dropping shortcut key combination because "
2776 + "the activity to which it is registered was not found: "
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002777 + "SEARCH+" + KeyEvent.keyCodeToString(keyCode), ex);
Jeff Brownf0a3cc52011-01-26 18:42:46 -08002778 }
Jeff Browncaab4d02010-12-09 22:13:41 -08002779 } else {
2780 Slog.i(TAG, "Dropping unregistered shortcut key combination: "
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002781 + "SEARCH+" + KeyEvent.keyCodeToString(keyCode));
Jeff Brown49ed71d2010-12-06 17:13:33 -08002782 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002783 }
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002784 return -1;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002785 }
2786 }
2787
Jeff Brown68b909d2011-12-07 16:36:01 -08002788 // Invoke shortcuts using Meta.
Jeff Brown602ab322012-05-16 13:33:47 -07002789 if (down && repeatCount == 0 && !keyguardOn
Jeff Brown68b909d2011-12-07 16:36:01 -08002790 && (metaState & KeyEvent.META_META_ON) != 0) {
2791 final KeyCharacterMap kcm = event.getKeyCharacterMap();
Jeff Brown602ab322012-05-16 13:33:47 -07002792 if (kcm.isPrintingKey(keyCode)) {
2793 Intent shortcutIntent = mShortcutManager.getIntent(kcm, keyCode,
2794 metaState & ~(KeyEvent.META_META_ON
2795 | KeyEvent.META_META_LEFT_ON | KeyEvent.META_META_RIGHT_ON));
2796 if (shortcutIntent != null) {
2797 shortcutIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
2798 try {
Bart Sears8b1c27c2015-03-18 23:51:02 +00002799 startActivityAsUser(shortcutIntent, UserHandle.CURRENT);
Jeff Brown602ab322012-05-16 13:33:47 -07002800 } catch (ActivityNotFoundException ex) {
2801 Slog.w(TAG, "Dropping shortcut key combination because "
2802 + "the activity to which it is registered was not found: "
2803 + "META+" + KeyEvent.keyCodeToString(keyCode), ex);
2804 }
2805 return -1;
Jeff Brown68b909d2011-12-07 16:36:01 -08002806 }
Jeff Brown68b909d2011-12-07 16:36:01 -08002807 }
2808 }
2809
Jeff Brown6651a632011-11-28 12:59:11 -08002810 // Handle application launch keys.
Jeff Brown602ab322012-05-16 13:33:47 -07002811 if (down && repeatCount == 0 && !keyguardOn) {
Jeff Brown6651a632011-11-28 12:59:11 -08002812 String category = sApplicationLaunchKeyCategories.get(keyCode);
2813 if (category != null) {
Dianne Hackbornf5b86712011-12-05 17:42:41 -08002814 Intent intent = Intent.makeMainSelectorActivity(Intent.ACTION_MAIN, category);
Jeff Brown6651a632011-11-28 12:59:11 -08002815 intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
2816 try {
Bart Sears8b1c27c2015-03-18 23:51:02 +00002817 startActivityAsUser(intent, UserHandle.CURRENT);
Jeff Brown6651a632011-11-28 12:59:11 -08002818 } catch (ActivityNotFoundException ex) {
2819 Slog.w(TAG, "Dropping application launch key because "
2820 + "the activity to which it is registered was not found: "
2821 + "keyCode=" + keyCode + ", category=" + category, ex);
2822 }
Jeff Brown68b909d2011-12-07 16:36:01 -08002823 return -1;
Jeff Brown6651a632011-11-28 12:59:11 -08002824 }
2825 }
2826
Michael Wright61c46752014-08-21 16:57:33 -07002827 // Display task switcher for ALT-TAB.
Jeff Brown68b909d2011-12-07 16:36:01 -08002828 if (down && repeatCount == 0 && keyCode == KeyEvent.KEYCODE_TAB) {
Winson Chung1e8d71b2014-05-16 17:05:22 -07002829 if (mRecentAppsHeldModifiers == 0 && !keyguardOn) {
Jeff Brown68b909d2011-12-07 16:36:01 -08002830 final int shiftlessModifiers = event.getModifiers() & ~KeyEvent.META_SHIFT_MASK;
Michael Wright61c46752014-08-21 16:57:33 -07002831 if (KeyEvent.metaStateHasModifiers(shiftlessModifiers, KeyEvent.META_ALT_ON)) {
Winson Chung1e8d71b2014-05-16 17:05:22 -07002832 mRecentAppsHeldModifiers = shiftlessModifiers;
2833 showRecentApps(true);
Jeff Brown68b909d2011-12-07 16:36:01 -08002834 return -1;
2835 }
2836 }
Winson Chung1e8d71b2014-05-16 17:05:22 -07002837 } else if (!down && mRecentAppsHeldModifiers != 0
2838 && (metaState & mRecentAppsHeldModifiers) == 0) {
2839 mRecentAppsHeldModifiers = 0;
Winson Chungcdcd4872014-08-05 18:00:13 -07002840 hideRecentApps(true, false);
Jeff Brown68b909d2011-12-07 16:36:01 -08002841 }
2842
Jeff Browncf39bdf2012-05-18 14:41:19 -07002843 // Handle keyboard language switching.
2844 if (down && repeatCount == 0
2845 && (keyCode == KeyEvent.KEYCODE_LANGUAGE_SWITCH
2846 || (keyCode == KeyEvent.KEYCODE_SPACE
2847 && (metaState & KeyEvent.META_CTRL_MASK) != 0))) {
2848 int direction = (metaState & KeyEvent.META_SHIFT_MASK) != 0 ? -1 : 1;
2849 mWindowManagerFuncs.switchKeyboardLayout(event.getDeviceId(), direction);
2850 return -1;
2851 }
2852 if (mLanguageSwitchKeyPressed && !down
2853 && (keyCode == KeyEvent.KEYCODE_LANGUAGE_SWITCH
2854 || keyCode == KeyEvent.KEYCODE_SPACE)) {
2855 mLanguageSwitchKeyPressed = false;
2856 return -1;
2857 }
2858
Jeff Brown13f00f02014-10-31 14:45:50 -07002859 if (isValidGlobalKey(keyCode)
2860 && mGlobalKeyManager.handleGlobalKey(mContext, keyCode, event)) {
Justin Kohd378ad72013-04-01 12:18:26 -07002861 return -1;
2862 }
2863
Michael Wright6a62e552014-06-03 19:19:48 -07002864 // Reserve all the META modifier combos for system behavior
Michael Wrightce0c13a2014-07-30 10:49:21 -07002865 if ((metaState & KeyEvent.META_META_ON) != 0) {
Michael Wright6a62e552014-06-03 19:19:48 -07002866 return -1;
2867 }
2868
Jeff Brown68b909d2011-12-07 16:36:01 -08002869 // Let the application handle the key.
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002870 return 0;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002871 }
2872
Jeff Brown3915bb82010-11-05 15:02:16 -07002873 /** {@inheritDoc} */
2874 @Override
Jeff Brown49ed71d2010-12-06 17:13:33 -08002875 public KeyEvent dispatchUnhandledKey(WindowState win, KeyEvent event, int policyFlags) {
Jeff Brown54875002011-04-06 15:33:01 -07002876 // Note: This method is only called if the initial down was unhandled.
Jeff Brown40013652012-05-16 21:22:36 -07002877 if (DEBUG_INPUT) {
Jeff Brown1f245102010-11-18 20:53:46 -08002878 Slog.d(TAG, "Unhandled key: win=" + win + ", action=" + event.getAction()
2879 + ", flags=" + event.getFlags()
2880 + ", keyCode=" + event.getKeyCode()
2881 + ", scanCode=" + event.getScanCode()
2882 + ", metaState=" + event.getMetaState()
2883 + ", repeatCount=" + event.getRepeatCount()
2884 + ", policyFlags=" + policyFlags);
Jeff Brown3915bb82010-11-05 15:02:16 -07002885 }
Jeff Brown49ed71d2010-12-06 17:13:33 -08002886
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002887 KeyEvent fallbackEvent = null;
Jeff Brown49ed71d2010-12-06 17:13:33 -08002888 if ((event.getFlags() & KeyEvent.FLAG_FALLBACK) == 0) {
2889 final KeyCharacterMap kcm = event.getKeyCharacterMap();
Jeff Brownc1fb48d2010-12-08 16:52:09 -08002890 final int keyCode = event.getKeyCode();
2891 final int metaState = event.getMetaState();
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002892 final boolean initialDown = event.getAction() == KeyEvent.ACTION_DOWN
2893 && event.getRepeatCount() == 0;
Jeff Brown49ed71d2010-12-06 17:13:33 -08002894
Jeff Brown54875002011-04-06 15:33:01 -07002895 // Check for fallback actions specified by the key character map.
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002896 final FallbackAction fallbackAction;
2897 if (initialDown) {
2898 fallbackAction = kcm.getFallbackAction(keyCode, metaState);
2899 } else {
2900 fallbackAction = mFallbackActions.get(keyCode);
2901 }
2902
2903 if (fallbackAction != null) {
Jeff Brown40013652012-05-16 21:22:36 -07002904 if (DEBUG_INPUT) {
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002905 Slog.d(TAG, "Fallback: keyCode=" + fallbackAction.keyCode
2906 + " metaState=" + Integer.toHexString(fallbackAction.metaState));
Jeff Brown49ed71d2010-12-06 17:13:33 -08002907 }
2908
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002909 final int flags = event.getFlags() | KeyEvent.FLAG_FALLBACK;
2910 fallbackEvent = KeyEvent.obtain(
Jeff Brown49ed71d2010-12-06 17:13:33 -08002911 event.getDownTime(), event.getEventTime(),
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002912 event.getAction(), fallbackAction.keyCode,
2913 event.getRepeatCount(), fallbackAction.metaState,
Jeff Brown49ed71d2010-12-06 17:13:33 -08002914 event.getDeviceId(), event.getScanCode(),
2915 flags, event.getSource(), null);
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002916
2917 if (!interceptFallback(win, fallbackEvent, policyFlags)) {
2918 fallbackEvent.recycle();
2919 fallbackEvent = null;
Jeff Brown49ed71d2010-12-06 17:13:33 -08002920 }
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002921
2922 if (initialDown) {
2923 mFallbackActions.put(keyCode, fallbackAction);
2924 } else if (event.getAction() == KeyEvent.ACTION_UP) {
2925 mFallbackActions.remove(keyCode);
2926 fallbackAction.recycle();
2927 }
Jeff Brown49ed71d2010-12-06 17:13:33 -08002928 }
2929 }
2930
Jeff Brown40013652012-05-16 21:22:36 -07002931 if (DEBUG_INPUT) {
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002932 if (fallbackEvent == null) {
2933 Slog.d(TAG, "No fallback.");
2934 } else {
2935 Slog.d(TAG, "Performing fallback: " + fallbackEvent);
2936 }
Jeff Brown49ed71d2010-12-06 17:13:33 -08002937 }
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002938 return fallbackEvent;
Jeff Brown3915bb82010-11-05 15:02:16 -07002939 }
2940
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002941 private boolean interceptFallback(WindowState win, KeyEvent fallbackEvent, int policyFlags) {
Jeff Brown037c33e2014-04-09 00:31:55 -07002942 int actions = interceptKeyBeforeQueueing(fallbackEvent, policyFlags);
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002943 if ((actions & ACTION_PASS_TO_USER) != 0) {
2944 long delayMillis = interceptKeyBeforeDispatching(
2945 win, fallbackEvent, policyFlags);
2946 if (delayMillis == 0) {
2947 return true;
2948 }
2949 }
2950 return false;
Jeff Brown6f2fba42011-02-19 01:08:02 -08002951 }
2952
Jeff Brownde7a8ea2012-06-13 18:28:57 -07002953 private void launchAssistLongPressAction() {
2954 performHapticFeedbackLw(null, HapticFeedbackConstants.LONG_PRESS, false);
2955 sendCloseSystemWindows(SYSTEM_DIALOG_REASON_ASSIST);
2956
2957 // launch the search activity
2958 Intent intent = new Intent(Intent.ACTION_SEARCH_LONG_PRESS);
2959 intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
2960 try {
RoboErik8a2cfc32014-05-16 11:19:38 -07002961 // TODO: This only stops the factory-installed search manager.
Jim Miller45308b12012-06-18 19:23:39 -07002962 // Need to formalize an API to handle others
Jeff Brownde7a8ea2012-06-13 18:28:57 -07002963 SearchManager searchManager = getSearchManager();
2964 if (searchManager != null) {
2965 searchManager.stopSearch();
2966 }
Bart Sears8b1c27c2015-03-18 23:51:02 +00002967 startActivityAsUser(intent, UserHandle.CURRENT);
Jeff Brownde7a8ea2012-06-13 18:28:57 -07002968 } catch (ActivityNotFoundException e) {
2969 Slog.w(TAG, "No activity to handle assist long press action.", e);
2970 }
2971 }
2972
2973 private void launchAssistAction() {
Michael Wright8ab940a2014-09-01 11:01:27 -07002974 launchAssistAction(null);
2975 }
2976
2977 private void launchAssistAction(String hint) {
Jeff Brownde7a8ea2012-06-13 18:28:57 -07002978 sendCloseSystemWindows(SYSTEM_DIALOG_REASON_ASSIST);
Amith Yamasanic1d07a42012-08-14 09:32:02 -07002979 Intent intent = ((SearchManager) mContext.getSystemService(Context.SEARCH_SERVICE))
Dianne Hackbornf9c5e0f2013-01-23 14:39:13 -08002980 .getAssistIntent(mContext, true, UserHandle.USER_CURRENT);
Jim Miller45308b12012-06-18 19:23:39 -07002981 if (intent != null) {
Michael Wright8ab940a2014-09-01 11:01:27 -07002982 if (hint != null) {
2983 intent.putExtra(hint, true);
2984 }
Jim Miller45308b12012-06-18 19:23:39 -07002985 intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK
2986 | Intent.FLAG_ACTIVITY_SINGLE_TOP
2987 | Intent.FLAG_ACTIVITY_CLEAR_TOP);
2988 try {
Bart Sears8b1c27c2015-03-18 23:51:02 +00002989 startActivityAsUser(intent, UserHandle.CURRENT);
Jim Miller45308b12012-06-18 19:23:39 -07002990 } catch (ActivityNotFoundException e) {
2991 Slog.w(TAG, "No activity to handle assist action.", e);
Jeff Brownde7a8ea2012-06-13 18:28:57 -07002992 }
2993 }
2994 }
2995
Bart Sears8b1c27c2015-03-18 23:51:02 +00002996 private void startActivityAsUser(Intent intent, UserHandle handle) {
2997 if (isUserSetupComplete()) {
2998 mContext.startActivityAsUser(intent, handle);
2999 } else {
3000 Slog.i(TAG, "Not starting activity because user setup is in progress: " + intent);
3001 }
3002 }
3003
Jeff Brownde7a8ea2012-06-13 18:28:57 -07003004 private SearchManager getSearchManager() {
3005 if (mSearchManager == null) {
3006 mSearchManager = (SearchManager) mContext.getSystemService(Context.SEARCH_SERVICE);
3007 }
3008 return mSearchManager;
3009 }
3010
Jeff Browncaca8812013-05-09 13:34:33 -07003011 private void preloadRecentApps() {
3012 mPreloadedRecentApps = true;
3013 try {
3014 IStatusBarService statusbar = getStatusBarService();
3015 if (statusbar != null) {
3016 statusbar.preloadRecentApps();
3017 }
3018 } catch (RemoteException e) {
3019 Slog.e(TAG, "RemoteException when preloading recent apps", e);
3020 // re-acquire status bar service next time it is needed.
3021 mStatusBarService = null;
3022 }
3023 }
3024
3025 private void cancelPreloadRecentApps() {
3026 if (mPreloadedRecentApps) {
3027 mPreloadedRecentApps = false;
3028 try {
3029 IStatusBarService statusbar = getStatusBarService();
3030 if (statusbar != null) {
3031 statusbar.cancelPreloadRecentApps();
3032 }
3033 } catch (RemoteException e) {
Winson Chung1e8d71b2014-05-16 17:05:22 -07003034 Slog.e(TAG, "RemoteException when cancelling recent apps preload", e);
Jeff Browncaca8812013-05-09 13:34:33 -07003035 // re-acquire status bar service next time it is needed.
3036 mStatusBarService = null;
3037 }
3038 }
3039 }
3040
3041 private void toggleRecentApps() {
3042 mPreloadedRecentApps = false; // preloading no longer needs to be canceled
Jeff Browncaca8812013-05-09 13:34:33 -07003043 try {
3044 IStatusBarService statusbar = getStatusBarService();
3045 if (statusbar != null) {
3046 statusbar.toggleRecentApps();
3047 }
3048 } catch (RemoteException e) {
Winson Chung1e8d71b2014-05-16 17:05:22 -07003049 Slog.e(TAG, "RemoteException when toggling recent apps", e);
3050 // re-acquire status bar service next time it is needed.
3051 mStatusBarService = null;
3052 }
3053 }
3054
Craig Mautner84984fa2014-06-19 11:19:20 -07003055 @Override
3056 public void showRecentApps() {
3057 mHandler.removeMessages(MSG_DISPATCH_SHOW_RECENTS);
3058 mHandler.sendEmptyMessage(MSG_DISPATCH_SHOW_RECENTS);
3059 }
3060
Winson Chung1e8d71b2014-05-16 17:05:22 -07003061 private void showRecentApps(boolean triggeredFromAltTab) {
3062 mPreloadedRecentApps = false; // preloading no longer needs to be canceled
3063 try {
3064 IStatusBarService statusbar = getStatusBarService();
3065 if (statusbar != null) {
3066 statusbar.showRecentApps(triggeredFromAltTab);
3067 }
3068 } catch (RemoteException e) {
Jeff Browncaca8812013-05-09 13:34:33 -07003069 Slog.e(TAG, "RemoteException when showing recent apps", e);
3070 // re-acquire status bar service next time it is needed.
3071 mStatusBarService = null;
3072 }
3073 }
3074
Winson Chungcdcd4872014-08-05 18:00:13 -07003075 private void hideRecentApps(boolean triggeredFromAltTab, boolean triggeredFromHome) {
Winson Chung1e8d71b2014-05-16 17:05:22 -07003076 mPreloadedRecentApps = false; // preloading no longer needs to be canceled
3077 try {
3078 IStatusBarService statusbar = getStatusBarService();
3079 if (statusbar != null) {
Winson Chungcdcd4872014-08-05 18:00:13 -07003080 statusbar.hideRecentApps(triggeredFromAltTab, triggeredFromHome);
Winson Chung1e8d71b2014-05-16 17:05:22 -07003081 }
3082 } catch (RemoteException e) {
3083 Slog.e(TAG, "RemoteException when closing recent apps", e);
3084 // re-acquire status bar service next time it is needed.
3085 mStatusBarService = null;
3086 }
3087 }
3088
Filip Gruszczynskia483a1d2015-03-17 19:06:58 +00003089 void launchHomeFromHotKey() {
Bryce Lee662ed802015-04-10 20:11:39 +00003090 launchHomeFromHotKey(true /* awakenFromDreams */, true /*respectKeyguard*/);
Filip Gruszczynskia483a1d2015-03-17 19:06:58 +00003091 }
3092
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003093 /**
3094 * A home key -> launch home action was detected. Take the appropriate action
3095 * given the situation with the keyguard.
3096 */
Bryce Lee662ed802015-04-10 20:11:39 +00003097 void launchHomeFromHotKey(final boolean awakenFromDreams, final boolean respectKeyguard) {
3098 if (respectKeyguard) {
3099 if (isKeyguardShowingAndNotOccluded()) {
3100 // don't launch home if keyguard showing
3101 return;
3102 }
3103
3104 if (!mHideLockScreen && mKeyguardDelegate.isInputRestricted()) {
3105 // when in keyguard restricted mode, must first verify unlock
3106 // before launching home
3107 mKeyguardDelegate.verifyUnlock(new OnKeyguardExitResult() {
3108 @Override
3109 public void onKeyguardExitResult(boolean success) {
3110 if (success) {
3111 try {
3112 ActivityManagerNative.getDefault().stopAppSwitches();
3113 } catch (RemoteException e) {
3114 }
3115 sendCloseSystemWindows(SYSTEM_DIALOG_REASON_HOME_KEY);
3116 startDockOrHome(true /*fromHomeKey*/, awakenFromDreams);
Dianne Hackborn256dd3b2009-05-19 18:51:21 -07003117 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003118 }
Bryce Lee662ed802015-04-10 20:11:39 +00003119 });
3120 return;
3121 }
3122 }
3123
3124 // no keyguard stuff to worry about, just launch home!
3125 try {
3126 ActivityManagerNative.getDefault().stopAppSwitches();
3127 } catch (RemoteException e) {
3128 }
3129 if (mRecentsVisible) {
3130 // Hide Recents and notify it to launch Home
3131 if (awakenFromDreams) {
3132 awakenDreams();
3133 }
3134 sendCloseSystemWindows(SYSTEM_DIALOG_REASON_HOME_KEY);
3135 hideRecentApps(false, true);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003136 } else {
Bryce Lee662ed802015-04-10 20:11:39 +00003137 // Otherwise, just launch Home
3138 sendCloseSystemWindows(SYSTEM_DIALOG_REASON_HOME_KEY);
3139 startDockOrHome(true /*fromHomeKey*/, awakenFromDreams);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003140 }
3141 }
3142
John Spurlock04db1762013-05-13 12:46:41 -04003143 private final Runnable mClearHideNavigationFlag = new Runnable() {
3144 @Override
3145 public void run() {
3146 synchronized (mWindowManagerFuncs.getWindowManagerLock()) {
3147 // Clear flags.
3148 mForceClearedSystemUiFlags &=
3149 ~View.SYSTEM_UI_FLAG_HIDE_NAVIGATION;
3150 }
3151 mWindowManagerFuncs.reevaluateStatusBarVisibility();
Dianne Hackborne26ab702011-10-16 13:21:33 -07003152 }
3153 };
3154
3155 /**
3156 * Input handler used while nav bar is hidden. Captures any touch on the screen,
3157 * to determine when the nav bar should be shown and prevent applications from
3158 * receiving those touches.
3159 */
Jeff Brown32cbc38552011-12-01 14:01:49 -08003160 final class HideNavInputEventReceiver extends InputEventReceiver {
3161 public HideNavInputEventReceiver(InputChannel inputChannel, Looper looper) {
3162 super(inputChannel, looper);
3163 }
3164
Dianne Hackborndf89e652011-10-06 22:35:11 -07003165 @Override
Jeff Brown32cbc38552011-12-01 14:01:49 -08003166 public void onInputEvent(InputEvent event) {
Dianne Hackborndf89e652011-10-06 22:35:11 -07003167 boolean handled = false;
3168 try {
Jeff Brown4952dfd2011-11-30 19:23:22 -08003169 if (event instanceof MotionEvent
3170 && (event.getSource() & InputDevice.SOURCE_CLASS_POINTER) != 0) {
3171 final MotionEvent motionEvent = (MotionEvent)event;
3172 if (motionEvent.getAction() == MotionEvent.ACTION_DOWN) {
Dianne Hackborndf89e652011-10-06 22:35:11 -07003173 // When the user taps down, we re-show the nav bar.
3174 boolean changed = false;
John Spurlock04db1762013-05-13 12:46:41 -04003175 synchronized (mWindowManagerFuncs.getWindowManagerLock()) {
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07003176 // Any user activity always causes us to show the
3177 // navigation controls, if they had been hidden.
3178 // We also clear the low profile and only content
3179 // flags so that tapping on the screen will atomically
3180 // restore all currently hidden screen decorations.
3181 int newVal = mResettingSystemUiFlags |
3182 View.SYSTEM_UI_FLAG_HIDE_NAVIGATION |
3183 View.SYSTEM_UI_FLAG_LOW_PROFILE |
3184 View.SYSTEM_UI_FLAG_FULLSCREEN;
Dianne Hackborne26ab702011-10-16 13:21:33 -07003185 if (mResettingSystemUiFlags != newVal) {
3186 mResettingSystemUiFlags = newVal;
Dianne Hackborndf89e652011-10-06 22:35:11 -07003187 changed = true;
3188 }
Dianne Hackborne26ab702011-10-16 13:21:33 -07003189 // We don't allow the system's nav bar to be hidden
3190 // again for 1 second, to prevent applications from
3191 // spamming us and keeping it from being shown.
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07003192 newVal = mForceClearedSystemUiFlags |
3193 View.SYSTEM_UI_FLAG_HIDE_NAVIGATION;
Dianne Hackborne26ab702011-10-16 13:21:33 -07003194 if (mForceClearedSystemUiFlags != newVal) {
3195 mForceClearedSystemUiFlags = newVal;
3196 changed = true;
John Spurlock04db1762013-05-13 12:46:41 -04003197 mHandler.postDelayed(mClearHideNavigationFlag, 1000);
Dianne Hackborne26ab702011-10-16 13:21:33 -07003198 }
Dianne Hackborndf89e652011-10-06 22:35:11 -07003199 }
3200 if (changed) {
3201 mWindowManagerFuncs.reevaluateStatusBarVisibility();
3202 }
3203 }
3204 }
3205 } finally {
Jeff Brown32cbc38552011-12-01 14:01:49 -08003206 finishInputEvent(event, handled);
Dianne Hackborndf89e652011-10-06 22:35:11 -07003207 }
3208 }
Jeff Brown32cbc38552011-12-01 14:01:49 -08003209 }
3210 final InputEventReceiver.Factory mHideNavInputEventReceiverFactory =
3211 new InputEventReceiver.Factory() {
3212 @Override
3213 public InputEventReceiver createInputEventReceiver(
3214 InputChannel inputChannel, Looper looper) {
3215 return new HideNavInputEventReceiver(inputChannel, looper);
3216 }
Dianne Hackborndf89e652011-10-06 22:35:11 -07003217 };
3218
3219 @Override
3220 public int adjustSystemUiVisibilityLw(int visibility) {
John Spurlock5b9145b2013-08-20 15:13:47 -04003221 mStatusBarController.adjustSystemUiVisibilityLw(mLastSystemUiFlags, visibility);
3222 mNavigationBarController.adjustSystemUiVisibilityLw(mLastSystemUiFlags, visibility);
Winson Chungd42a6cf2014-06-03 16:24:04 -07003223 mRecentsVisible = (visibility & View.RECENT_APPS_VISIBLE) > 0;
John Spurlock27735a42013-08-14 17:57:38 -04003224
Dianne Hackborndf89e652011-10-06 22:35:11 -07003225 // Reset any bits in mForceClearingStatusBarVisibility that
3226 // are now clear.
Dianne Hackborne26ab702011-10-16 13:21:33 -07003227 mResettingSystemUiFlags &= visibility;
Dianne Hackborndf89e652011-10-06 22:35:11 -07003228 // Clear any bits in the new visibility that are currently being
3229 // force cleared, before reporting it.
Dianne Hackborne26ab702011-10-16 13:21:33 -07003230 return visibility & ~mResettingSystemUiFlags
3231 & ~mForceClearedSystemUiFlags;
Dianne Hackborndf89e652011-10-06 22:35:11 -07003232 }
3233
Craig Mautner69b08182012-09-05 13:07:13 -07003234 @Override
Adrian Roos37d7a682014-11-06 18:15:16 +01003235 public void getInsetHintLw(WindowManager.LayoutParams attrs, Rect outContentInsets,
3236 Rect outStableInsets) {
John Spurlockc6d1c602014-01-17 15:22:06 -05003237 final int fl = PolicyControl.getWindowFlags(null, attrs);
John Spurlock1db8b682014-02-18 11:18:59 -05003238 final int sysuiVis = PolicyControl.getSystemUiVisibility(null, attrs);
3239 final int systemUiVisibility = (sysuiVis | attrs.subtreeSystemUiVisibility);
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07003240
Dianne Hackborn5b5cc4d2012-05-16 13:15:00 -07003241 if ((fl & (FLAG_LAYOUT_IN_SCREEN | FLAG_LAYOUT_INSET_DECOR))
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003242 == (FLAG_LAYOUT_IN_SCREEN | FLAG_LAYOUT_INSET_DECOR)) {
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07003243 int availRight, availBottom;
Alan Viverette5a0f4ec2013-10-07 15:10:29 -07003244 if (canHideNavigationBar() &&
Dianne Hackborn5b5cc4d2012-05-16 13:15:00 -07003245 (systemUiVisibility & View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION) != 0) {
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07003246 availRight = mUnrestrictedScreenLeft + mUnrestrictedScreenWidth;
3247 availBottom = mUnrestrictedScreenTop + mUnrestrictedScreenHeight;
3248 } else {
3249 availRight = mRestrictedScreenLeft + mRestrictedScreenWidth;
3250 availBottom = mRestrictedScreenTop + mRestrictedScreenHeight;
3251 }
Dianne Hackborn5b5cc4d2012-05-16 13:15:00 -07003252 if ((systemUiVisibility & View.SYSTEM_UI_FLAG_LAYOUT_STABLE) != 0) {
3253 if ((fl & FLAG_FULLSCREEN) != 0) {
Adrian Roos37d7a682014-11-06 18:15:16 +01003254 outContentInsets.set(mStableFullscreenLeft, mStableFullscreenTop,
Dianne Hackborn5b5cc4d2012-05-16 13:15:00 -07003255 availRight - mStableFullscreenRight,
3256 availBottom - mStableFullscreenBottom);
3257 } else {
Adrian Roos37d7a682014-11-06 18:15:16 +01003258 outContentInsets.set(mStableLeft, mStableTop,
Dianne Hackborn5b5cc4d2012-05-16 13:15:00 -07003259 availRight - mStableRight, availBottom - mStableBottom);
3260 }
Dianne Hackbornc652de82013-02-15 16:32:56 -08003261 } else if ((fl & FLAG_FULLSCREEN) != 0 || (fl & FLAG_LAYOUT_IN_OVERSCAN) != 0) {
Adrian Roos37d7a682014-11-06 18:15:16 +01003262 outContentInsets.setEmpty();
Dianne Hackborn5b5cc4d2012-05-16 13:15:00 -07003263 } else if ((systemUiVisibility & (View.SYSTEM_UI_FLAG_FULLSCREEN
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07003264 | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN)) == 0) {
Adrian Roos37d7a682014-11-06 18:15:16 +01003265 outContentInsets.set(mCurLeft, mCurTop,
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07003266 availRight - mCurRight, availBottom - mCurBottom);
3267 } else {
Adrian Roos37d7a682014-11-06 18:15:16 +01003268 outContentInsets.set(mCurLeft, mCurTop,
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07003269 availRight - mCurRight, availBottom - mCurBottom);
3270 }
Adrian Roos37d7a682014-11-06 18:15:16 +01003271
3272 outStableInsets.set(mStableLeft, mStableTop,
3273 availRight - mStableRight, availBottom - mStableBottom);
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07003274 return;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003275 }
Adrian Roos37d7a682014-11-06 18:15:16 +01003276 outContentInsets.setEmpty();
3277 outStableInsets.setEmpty();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003278 }
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07003279
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003280 /** {@inheritDoc} */
Craig Mautner69b08182012-09-05 13:07:13 -07003281 @Override
3282 public void beginLayoutLw(boolean isDefaultDisplay, int displayWidth, int displayHeight,
3283 int displayRotation) {
Dianne Hackbornc652de82013-02-15 16:32:56 -08003284 final int overscanLeft, overscanTop, overscanRight, overscanBottom;
3285 if (isDefaultDisplay) {
3286 switch (displayRotation) {
3287 case Surface.ROTATION_90:
3288 overscanLeft = mOverscanTop;
3289 overscanTop = mOverscanRight;
3290 overscanRight = mOverscanBottom;
3291 overscanBottom = mOverscanLeft;
3292 break;
3293 case Surface.ROTATION_180:
3294 overscanLeft = mOverscanRight;
3295 overscanTop = mOverscanBottom;
3296 overscanRight = mOverscanLeft;
3297 overscanBottom = mOverscanTop;
3298 break;
3299 case Surface.ROTATION_270:
3300 overscanLeft = mOverscanBottom;
3301 overscanTop = mOverscanLeft;
3302 overscanRight = mOverscanTop;
3303 overscanBottom = mOverscanRight;
3304 break;
3305 default:
3306 overscanLeft = mOverscanLeft;
3307 overscanTop = mOverscanTop;
3308 overscanRight = mOverscanRight;
3309 overscanBottom = mOverscanBottom;
3310 break;
3311 }
3312 } else {
3313 overscanLeft = 0;
3314 overscanTop = 0;
3315 overscanRight = 0;
3316 overscanBottom = 0;
3317 }
Dianne Hackborn313440842013-02-19 19:22:59 -08003318 mOverscanScreenLeft = mRestrictedOverscanScreenLeft = 0;
3319 mOverscanScreenTop = mRestrictedOverscanScreenTop = 0;
3320 mOverscanScreenWidth = mRestrictedOverscanScreenWidth = displayWidth;
3321 mOverscanScreenHeight = mRestrictedOverscanScreenHeight = displayHeight;
Dianne Hackbornc652de82013-02-15 16:32:56 -08003322 mSystemLeft = 0;
3323 mSystemTop = 0;
3324 mSystemRight = displayWidth;
3325 mSystemBottom = displayHeight;
3326 mUnrestrictedScreenLeft = overscanLeft;
3327 mUnrestrictedScreenTop = overscanTop;
3328 mUnrestrictedScreenWidth = displayWidth - overscanLeft - overscanRight;
3329 mUnrestrictedScreenHeight = displayHeight - overscanTop - overscanBottom;
3330 mRestrictedScreenLeft = mUnrestrictedScreenLeft;
3331 mRestrictedScreenTop = mUnrestrictedScreenTop;
John Spurlockad3e6cb2013-04-30 08:47:43 -04003332 mRestrictedScreenWidth = mSystemGestures.screenWidth = mUnrestrictedScreenWidth;
3333 mRestrictedScreenHeight = mSystemGestures.screenHeight = mUnrestrictedScreenHeight;
Dianne Hackborne30e02f2014-05-27 18:24:45 -07003334 mDockLeft = mContentLeft = mVoiceContentLeft = mStableLeft = mStableFullscreenLeft
Dianne Hackbornc652de82013-02-15 16:32:56 -08003335 = mCurLeft = mUnrestrictedScreenLeft;
Dianne Hackborne30e02f2014-05-27 18:24:45 -07003336 mDockTop = mContentTop = mVoiceContentTop = mStableTop = mStableFullscreenTop
Dianne Hackbornc652de82013-02-15 16:32:56 -08003337 = mCurTop = mUnrestrictedScreenTop;
Dianne Hackborne30e02f2014-05-27 18:24:45 -07003338 mDockRight = mContentRight = mVoiceContentRight = mStableRight = mStableFullscreenRight
Dianne Hackbornc652de82013-02-15 16:32:56 -08003339 = mCurRight = displayWidth - overscanRight;
Dianne Hackborne30e02f2014-05-27 18:24:45 -07003340 mDockBottom = mContentBottom = mVoiceContentBottom = mStableBottom = mStableFullscreenBottom
Dianne Hackbornc652de82013-02-15 16:32:56 -08003341 = mCurBottom = displayHeight - overscanBottom;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003342 mDockLayer = 0x10000000;
Dianne Hackborn5c58de32012-04-28 19:52:37 -07003343 mStatusBarLayer = -1;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003344
Daniel Sandler8956dbb2011-04-22 07:55:02 -04003345 // start with the current dock rect, which will be (0,0,displayWidth,displayHeight)
3346 final Rect pf = mTmpParentFrame;
3347 final Rect df = mTmpDisplayFrame;
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003348 final Rect of = mTmpOverscanFrame;
Daniel Sandler8956dbb2011-04-22 07:55:02 -04003349 final Rect vf = mTmpVisibleFrame;
John Spurlock46646232013-09-30 22:32:42 -04003350 final Rect dcf = mTmpDecorFrame;
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003351 pf.left = df.left = of.left = vf.left = mDockLeft;
3352 pf.top = df.top = of.top = vf.top = mDockTop;
3353 pf.right = df.right = of.right = vf.right = mDockRight;
3354 pf.bottom = df.bottom = of.bottom = vf.bottom = mDockBottom;
John Spurlock46646232013-09-30 22:32:42 -04003355 dcf.setEmpty(); // Decor frame N/A for system bars.
Daniel Sandler8956dbb2011-04-22 07:55:02 -04003356
Craig Mautner69b08182012-09-05 13:07:13 -07003357 if (isDefaultDisplay) {
3358 // For purposes of putting out fake window up to steal focus, we will
3359 // drive nav being hidden only by whether it is requested.
John Spurlocke1f366f2013-08-05 12:22:40 -04003360 final int sysui = mLastSystemUiFlags;
3361 boolean navVisible = (sysui & View.SYSTEM_UI_FLAG_HIDE_NAVIGATION) == 0;
Adrian Roosea562512014-05-05 13:33:03 +02003362 boolean navTranslucent = (sysui
3363 & (View.NAVIGATION_BAR_TRANSLUCENT | View.SYSTEM_UI_TRANSPARENT)) != 0;
John Spurlockf1a36642013-10-12 17:50:42 -04003364 boolean immersive = (sysui & View.SYSTEM_UI_FLAG_IMMERSIVE) != 0;
3365 boolean immersiveSticky = (sysui & View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY) != 0;
3366 boolean navAllowedHidden = immersive || immersiveSticky;
3367 navTranslucent &= !immersiveSticky; // transient trumps translucent
Adrian Roos4fb3ee32014-08-22 19:29:09 +02003368 boolean isKeyguardShowing = isStatusBarKeyguard() && !mHideLockScreen;
3369 if (!isKeyguardShowing) {
3370 navTranslucent &= areTranslucentBarsAllowed();
3371 }
Dianne Hackborne26ab702011-10-16 13:21:33 -07003372
Craig Mautner69b08182012-09-05 13:07:13 -07003373 // When the navigation bar isn't visible, we put up a fake
3374 // input window to catch all touch events. This way we can
3375 // detect when the user presses anywhere to bring back the nav
3376 // bar and ensure the application doesn't see the event.
John Spurlockf1a36642013-10-12 17:50:42 -04003377 if (navVisible || navAllowedHidden) {
Craig Mautner69b08182012-09-05 13:07:13 -07003378 if (mHideNavFakeWindow != null) {
3379 mHideNavFakeWindow.dismiss();
3380 mHideNavFakeWindow = null;
3381 }
3382 } else if (mHideNavFakeWindow == null) {
3383 mHideNavFakeWindow = mWindowManagerFuncs.addFakeWindow(
3384 mHandler.getLooper(), mHideNavInputEventReceiverFactory,
Adam Lesinski95c42972013-10-02 10:13:27 -07003385 "hidden nav", WindowManager.LayoutParams.TYPE_HIDDEN_NAV_CONSUMER, 0,
Craig Mautner69b08182012-09-05 13:07:13 -07003386 0, false, false, true);
Dianne Hackborne26ab702011-10-16 13:21:33 -07003387 }
Dianne Hackborne26ab702011-10-16 13:21:33 -07003388
Craig Mautner69b08182012-09-05 13:07:13 -07003389 // For purposes of positioning and showing the nav bar, if we have
3390 // decided that it can't be hidden (because of the screen aspect ratio),
3391 // then take that into account.
Alan Viverette5a0f4ec2013-10-07 15:10:29 -07003392 navVisible |= !canHideNavigationBar();
Dianne Hackbornf87d1962012-04-04 12:48:24 -07003393
John Spurlockad3e6cb2013-04-30 08:47:43 -04003394 boolean updateSysUiVisibility = false;
Craig Mautner69b08182012-09-05 13:07:13 -07003395 if (mNavigationBar != null) {
John Spurlock27735a42013-08-14 17:57:38 -04003396 boolean transientNavBarShowing = mNavigationBarController.isTransientShowing();
Craig Mautner69b08182012-09-05 13:07:13 -07003397 // Force the navigation bar to its appropriate place and
3398 // size. We need to do this directly, instead of relying on
3399 // it to bubble up from the nav bar, because this needs to
3400 // change atomically with screen rotations.
3401 mNavigationBarOnBottom = (!mNavigationBarCanMove || displayWidth < displayHeight);
3402 if (mNavigationBarOnBottom) {
3403 // It's a system nav bar or a portrait screen; nav bar goes on bottom.
Dianne Hackbornc652de82013-02-15 16:32:56 -08003404 int top = displayHeight - overscanBottom
3405 - mNavigationBarHeightForRotation[displayRotation];
3406 mTmpNavigationFrame.set(0, top, displayWidth, displayHeight - overscanBottom);
Craig Mautner69b08182012-09-05 13:07:13 -07003407 mStableBottom = mStableFullscreenBottom = mTmpNavigationFrame.top;
John Spurlockf95b89a2013-10-10 22:10:42 -04003408 if (transientNavBarShowing) {
John Spurlock27735a42013-08-14 17:57:38 -04003409 mNavigationBarController.setBarShowingLw(true);
John Spurlockad3e6cb2013-04-30 08:47:43 -04003410 } else if (navVisible) {
John Spurlock27735a42013-08-14 17:57:38 -04003411 mNavigationBarController.setBarShowingLw(true);
Craig Mautner69b08182012-09-05 13:07:13 -07003412 mDockBottom = mTmpNavigationFrame.top;
Dianne Hackborn313440842013-02-19 19:22:59 -08003413 mRestrictedScreenHeight = mDockBottom - mRestrictedScreenTop;
3414 mRestrictedOverscanScreenHeight = mDockBottom - mRestrictedOverscanScreenTop;
Craig Mautner69b08182012-09-05 13:07:13 -07003415 } else {
3416 // We currently want to hide the navigation UI.
John Spurlock27735a42013-08-14 17:57:38 -04003417 mNavigationBarController.setBarShowingLw(false);
Craig Mautner69b08182012-09-05 13:07:13 -07003418 }
John Spurlockc6d1c602014-01-17 15:22:06 -05003419 if (navVisible && !navTranslucent && !navAllowedHidden
3420 && !mNavigationBar.isAnimatingLw()
John Spurlockbd957402013-10-03 11:38:39 -04003421 && !mNavigationBarController.wasRecentlyTranslucent()) {
John Spurlocke1f366f2013-08-05 12:22:40 -04003422 // If the opaque nav bar is currently requested to be visible,
Craig Mautner69b08182012-09-05 13:07:13 -07003423 // and not in the process of animating on or off, then
3424 // we can tell the app that it is covered by it.
3425 mSystemBottom = mTmpNavigationFrame.top;
3426 }
Dianne Hackbornf87d1962012-04-04 12:48:24 -07003427 } else {
Craig Mautner69b08182012-09-05 13:07:13 -07003428 // Landscape screen; nav bar goes to the right.
Dianne Hackbornc652de82013-02-15 16:32:56 -08003429 int left = displayWidth - overscanRight
3430 - mNavigationBarWidthForRotation[displayRotation];
3431 mTmpNavigationFrame.set(left, 0, displayWidth - overscanRight, displayHeight);
Craig Mautner69b08182012-09-05 13:07:13 -07003432 mStableRight = mStableFullscreenRight = mTmpNavigationFrame.left;
John Spurlockf95b89a2013-10-10 22:10:42 -04003433 if (transientNavBarShowing) {
John Spurlock27735a42013-08-14 17:57:38 -04003434 mNavigationBarController.setBarShowingLw(true);
John Spurlockad3e6cb2013-04-30 08:47:43 -04003435 } else if (navVisible) {
John Spurlock27735a42013-08-14 17:57:38 -04003436 mNavigationBarController.setBarShowingLw(true);
Craig Mautner69b08182012-09-05 13:07:13 -07003437 mDockRight = mTmpNavigationFrame.left;
Dianne Hackborn313440842013-02-19 19:22:59 -08003438 mRestrictedScreenWidth = mDockRight - mRestrictedScreenLeft;
3439 mRestrictedOverscanScreenWidth = mDockRight - mRestrictedOverscanScreenLeft;
Craig Mautner69b08182012-09-05 13:07:13 -07003440 } else {
3441 // We currently want to hide the navigation UI.
John Spurlock27735a42013-08-14 17:57:38 -04003442 mNavigationBarController.setBarShowingLw(false);
Craig Mautner69b08182012-09-05 13:07:13 -07003443 }
John Spurlockbd957402013-10-03 11:38:39 -04003444 if (navVisible && !navTranslucent && !mNavigationBar.isAnimatingLw()
3445 && !mNavigationBarController.wasRecentlyTranslucent()) {
Craig Mautner69b08182012-09-05 13:07:13 -07003446 // If the nav bar is currently requested to be visible,
3447 // and not in the process of animating on or off, then
3448 // we can tell the app that it is covered by it.
3449 mSystemRight = mTmpNavigationFrame.left;
3450 }
Dianne Hackbornf87d1962012-04-04 12:48:24 -07003451 }
Craig Mautner69b08182012-09-05 13:07:13 -07003452 // Make sure the content and current rectangles are updated to
3453 // account for the restrictions from the navigation bar.
Dianne Hackborne30e02f2014-05-27 18:24:45 -07003454 mContentTop = mVoiceContentTop = mCurTop = mDockTop;
3455 mContentBottom = mVoiceContentBottom = mCurBottom = mDockBottom;
3456 mContentLeft = mVoiceContentLeft = mCurLeft = mDockLeft;
3457 mContentRight = mVoiceContentRight = mCurRight = mDockRight;
Craig Mautner69b08182012-09-05 13:07:13 -07003458 mStatusBarLayer = mNavigationBar.getSurfaceLayer();
3459 // And compute the final frame.
3460 mNavigationBar.computeFrameLw(mTmpNavigationFrame, mTmpNavigationFrame,
Adrian Roosfa104232014-06-20 16:10:14 -07003461 mTmpNavigationFrame, mTmpNavigationFrame, mTmpNavigationFrame, dcf,
3462 mTmpNavigationFrame);
Craig Mautnereda67292013-04-28 13:50:14 -07003463 if (DEBUG_LAYOUT) Slog.i(TAG, "mNavigationBar frame: " + mTmpNavigationFrame);
John Spurlock27735a42013-08-14 17:57:38 -04003464 if (mNavigationBarController.checkHiddenLw()) {
John Spurlockad3e6cb2013-04-30 08:47:43 -04003465 updateSysUiVisibility = true;
3466 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003467 }
Craig Mautnereda67292013-04-28 13:50:14 -07003468 if (DEBUG_LAYOUT) Slog.i(TAG, String.format("mDock rect: (%d,%d - %d,%d)",
Craig Mautner69b08182012-09-05 13:07:13 -07003469 mDockLeft, mDockTop, mDockRight, mDockBottom));
3470
3471 // decide where the status bar goes ahead of time
3472 if (mStatusBar != null) {
3473 // apply any navigation bar insets
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003474 pf.left = df.left = of.left = mUnrestrictedScreenLeft;
3475 pf.top = df.top = of.top = mUnrestrictedScreenTop;
3476 pf.right = df.right = of.right = mUnrestrictedScreenWidth + mUnrestrictedScreenLeft;
3477 pf.bottom = df.bottom = of.bottom = mUnrestrictedScreenHeight
3478 + mUnrestrictedScreenTop;
Craig Mautner69b08182012-09-05 13:07:13 -07003479 vf.left = mStableLeft;
3480 vf.top = mStableTop;
3481 vf.right = mStableRight;
3482 vf.bottom = mStableBottom;
3483
3484 mStatusBarLayer = mStatusBar.getSurfaceLayer();
3485
3486 // Let the status bar determine its size.
Adrian Roosfa104232014-06-20 16:10:14 -07003487 mStatusBar.computeFrameLw(pf, df, vf, vf, vf, dcf, vf);
Craig Mautner69b08182012-09-05 13:07:13 -07003488
3489 // For layout, the status bar is always at the top with our fixed height.
3490 mStableTop = mUnrestrictedScreenTop + mStatusBarHeight;
3491
John Spurlocke1f366f2013-08-05 12:22:40 -04003492 boolean statusBarTransient = (sysui & View.STATUS_BAR_TRANSIENT) != 0;
Adrian Roosea562512014-05-05 13:33:03 +02003493 boolean statusBarTranslucent = (sysui
3494 & (View.STATUS_BAR_TRANSLUCENT | View.SYSTEM_UI_TRANSPARENT)) != 0;
Adrian Roos4fb3ee32014-08-22 19:29:09 +02003495 if (!isKeyguardShowing) {
3496 statusBarTranslucent &= areTranslucentBarsAllowed();
3497 }
John Spurlock32beb2c2013-03-11 10:16:47 -04003498
Craig Mautner69b08182012-09-05 13:07:13 -07003499 // If the status bar is hidden, we don't want to cause
3500 // windows behind it to scroll.
John Spurlockeda1f692013-09-16 11:38:44 -04003501 if (mStatusBar.isVisibleLw() && !statusBarTransient) {
Craig Mautner69b08182012-09-05 13:07:13 -07003502 // Status bar may go away, so the screen area it occupies
3503 // is available to apps but just covering them when the
3504 // status bar is visible.
3505 mDockTop = mUnrestrictedScreenTop + mStatusBarHeight;
3506
Dianne Hackborne30e02f2014-05-27 18:24:45 -07003507 mContentTop = mVoiceContentTop = mCurTop = mDockTop;
3508 mContentBottom = mVoiceContentBottom = mCurBottom = mDockBottom;
3509 mContentLeft = mVoiceContentLeft = mCurLeft = mDockLeft;
3510 mContentRight = mVoiceContentRight = mCurRight = mDockRight;
Craig Mautner69b08182012-09-05 13:07:13 -07003511
Craig Mautnereda67292013-04-28 13:50:14 -07003512 if (DEBUG_LAYOUT) Slog.v(TAG, "Status bar: " +
Craig Mautner69b08182012-09-05 13:07:13 -07003513 String.format(
3514 "dock=[%d,%d][%d,%d] content=[%d,%d][%d,%d] cur=[%d,%d][%d,%d]",
3515 mDockLeft, mDockTop, mDockRight, mDockBottom,
3516 mContentLeft, mContentTop, mContentRight, mContentBottom,
3517 mCurLeft, mCurTop, mCurRight, mCurBottom));
3518 }
John Spurlocke1f366f2013-08-05 12:22:40 -04003519 if (mStatusBar.isVisibleLw() && !mStatusBar.isAnimatingLw()
John Spurlockbd957402013-10-03 11:38:39 -04003520 && !statusBarTransient && !statusBarTranslucent
3521 && !mStatusBarController.wasRecentlyTranslucent()) {
John Spurlocke1f366f2013-08-05 12:22:40 -04003522 // If the opaque status bar is currently requested to be visible,
Craig Mautner69b08182012-09-05 13:07:13 -07003523 // and not in the process of animating on or off, then
3524 // we can tell the app that it is covered by it.
3525 mSystemTop = mUnrestrictedScreenTop + mStatusBarHeight;
3526 }
John Spurlock27735a42013-08-14 17:57:38 -04003527 if (mStatusBarController.checkHiddenLw()) {
John Spurlockad3e6cb2013-04-30 08:47:43 -04003528 updateSysUiVisibility = true;
John Spurlock32beb2c2013-03-11 10:16:47 -04003529 }
Dianne Hackborn5c58de32012-04-28 19:52:37 -07003530 }
John Spurlockad3e6cb2013-04-30 08:47:43 -04003531 if (updateSysUiVisibility) {
3532 updateSystemUiVisibilityLw();
3533 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003534 }
3535 }
3536
Dianne Hackborn85afd1b2012-05-13 13:31:06 -07003537 /** {@inheritDoc} */
Craig Mautner967212c2013-04-13 21:10:58 -07003538 @Override
John Spurlock46646232013-09-30 22:32:42 -04003539 public int getSystemDecorLayerLw() {
Bryce Lee2ed3e5f2015-04-01 22:09:19 +00003540 if (mStatusBar != null && mStatusBar.isVisibleLw()) {
3541 return mStatusBar.getSurfaceLayer();
3542 }
3543
3544 if (mNavigationBar != null && mNavigationBar.isVisibleLw()) {
3545 return mNavigationBar.getSurfaceLayer();
3546 }
3547
Dianne Hackborn85afd1b2012-05-13 13:31:06 -07003548 return 0;
3549 }
3550
Craig Mautner967212c2013-04-13 21:10:58 -07003551 @Override
3552 public void getContentRectLw(Rect r) {
3553 r.set(mContentLeft, mContentTop, mContentRight, mContentBottom);
3554 }
3555
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003556 void setAttachedWindowFrames(WindowState win, int fl, int adjust, WindowState attached,
3557 boolean insetDecors, Rect pf, Rect df, Rect of, Rect cf, Rect vf) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003558 if (win.getSurfaceLayer() > mDockLayer && attached.getSurfaceLayer() < mDockLayer) {
3559 // Here's a special case: if this attached window is a panel that is
3560 // above the dock window, and the window it is attached to is below
3561 // the dock window, then the frames we computed for the window it is
3562 // attached to can not be used because the dock is effectively part
3563 // of the underlying window and the attached window is floating on top
3564 // of the whole thing. So, we ignore the attached window and explicitly
3565 // compute the frames that would be appropriate without the dock.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003566 df.left = of.left = cf.left = vf.left = mDockLeft;
3567 df.top = of.top = cf.top = vf.top = mDockTop;
3568 df.right = of.right = cf.right = vf.right = mDockRight;
3569 df.bottom = of.bottom = cf.bottom = vf.bottom = mDockBottom;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003570 } else {
3571 // The effective display frame of the attached window depends on
3572 // whether it is taking care of insetting its content. If not,
3573 // we need to use the parent's content frame so that the entire
3574 // window is positioned within that content. Otherwise we can use
Wale Ogunwale393b1c12014-10-18 16:22:01 -07003575 // the overscan frame and let the attached window take care of
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003576 // positioning its content appropriately.
Dianne Hackborndea3ef72010-10-28 14:24:22 -07003577 if (adjust != SOFT_INPUT_ADJUST_RESIZE) {
Wale Ogunwale393b1c12014-10-18 16:22:01 -07003578 // Set the content frame of the attached window to the parent's decor frame
3579 // (same as content frame when IME isn't present) if specifically requested by
3580 // setting {@link WindowManager.LayoutParams#FLAG_LAYOUT_ATTACHED_IN_DECOR} flag.
3581 // Otherwise, use the overscan frame.
3582 cf.set((fl & FLAG_LAYOUT_ATTACHED_IN_DECOR) != 0
3583 ? attached.getContentFrameLw() : attached.getOverscanFrameLw());
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003584 } else {
3585 // If the window is resizing, then we want to base the content
3586 // frame on our attached content frame to resize... however,
3587 // things can be tricky if the attached window is NOT in resize
3588 // mode, in which case its content frame will be larger.
3589 // Ungh. So to deal with that, make sure the content frame
3590 // we end up using is not covering the IM dock.
3591 cf.set(attached.getContentFrameLw());
Dianne Hackborne30e02f2014-05-27 18:24:45 -07003592 if (attached.isVoiceInteraction()) {
3593 if (cf.left < mVoiceContentLeft) cf.left = mVoiceContentLeft;
3594 if (cf.top < mVoiceContentTop) cf.top = mVoiceContentTop;
3595 if (cf.right > mVoiceContentRight) cf.right = mVoiceContentRight;
3596 if (cf.bottom > mVoiceContentBottom) cf.bottom = mVoiceContentBottom;
3597 } else if (attached.getSurfaceLayer() < mDockLayer) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003598 if (cf.left < mContentLeft) cf.left = mContentLeft;
3599 if (cf.top < mContentTop) cf.top = mContentTop;
3600 if (cf.right > mContentRight) cf.right = mContentRight;
3601 if (cf.bottom > mContentBottom) cf.bottom = mContentBottom;
3602 }
3603 }
3604 df.set(insetDecors ? attached.getDisplayFrameLw() : cf);
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003605 of.set(insetDecors ? attached.getOverscanFrameLw() : cf);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003606 vf.set(attached.getVisibleFrameLw());
3607 }
3608 // The LAYOUT_IN_SCREEN flag is used to determine whether the attached
3609 // window should be positioned relative to its parent or the entire
3610 // screen.
3611 pf.set((fl & FLAG_LAYOUT_IN_SCREEN) == 0
3612 ? attached.getFrameLw() : df);
3613 }
Dianne Hackborn5b5cc4d2012-05-16 13:15:00 -07003614
3615 private void applyStableConstraints(int sysui, int fl, Rect r) {
3616 if ((sysui & View.SYSTEM_UI_FLAG_LAYOUT_STABLE) != 0) {
3617 // If app is requesting a stable layout, don't let the
3618 // content insets go below the stable values.
3619 if ((fl & FLAG_FULLSCREEN) != 0) {
3620 if (r.left < mStableFullscreenLeft) r.left = mStableFullscreenLeft;
3621 if (r.top < mStableFullscreenTop) r.top = mStableFullscreenTop;
3622 if (r.right > mStableFullscreenRight) r.right = mStableFullscreenRight;
3623 if (r.bottom > mStableFullscreenBottom) r.bottom = mStableFullscreenBottom;
3624 } else {
3625 if (r.left < mStableLeft) r.left = mStableLeft;
3626 if (r.top < mStableTop) r.top = mStableTop;
3627 if (r.right > mStableRight) r.right = mStableRight;
3628 if (r.bottom > mStableBottom) r.bottom = mStableBottom;
3629 }
3630 }
3631 }
3632
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003633 /** {@inheritDoc} */
Craig Mautner69b08182012-09-05 13:07:13 -07003634 @Override
Craig Mautnerc9457fa2014-06-06 14:27:48 -07003635 public void layoutWindowLw(WindowState win, WindowState attached) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003636 // we've already done the status bar
Craig Mautnerc9457fa2014-06-06 14:27:48 -07003637 final WindowManager.LayoutParams attrs = win.getAttrs();
3638 if ((win == mStatusBar && (attrs.privateFlags & PRIVATE_FLAG_KEYGUARD) == 0) ||
3639 win == mNavigationBar) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003640 return;
3641 }
Craig Mautner69b08182012-09-05 13:07:13 -07003642 final boolean isDefaultDisplay = win.isDefaultDisplay();
3643 final boolean needsToOffsetInputMethodTarget = isDefaultDisplay &&
satok1bc0a492012-04-25 22:47:12 +09003644 (win == mLastInputMethodTargetWindow && mLastInputMethodWindow != null);
3645 if (needsToOffsetInputMethodTarget) {
Craig Mautnereda67292013-04-28 13:50:14 -07003646 if (DEBUG_LAYOUT) Slog.i(TAG, "Offset ime target window by the last ime window state");
satok1bc0a492012-04-25 22:47:12 +09003647 offsetInputMethodWindowLw(mLastInputMethodWindow);
3648 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003649
John Spurlockc6d1c602014-01-17 15:22:06 -05003650 final int fl = PolicyControl.getWindowFlags(win, attrs);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003651 final int sim = attrs.softInputMode;
John Spurlock1db8b682014-02-18 11:18:59 -05003652 final int sysUiFl = PolicyControl.getSystemUiVisibility(win, null);
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07003653
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003654 final Rect pf = mTmpParentFrame;
3655 final Rect df = mTmpDisplayFrame;
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003656 final Rect of = mTmpOverscanFrame;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003657 final Rect cf = mTmpContentFrame;
3658 final Rect vf = mTmpVisibleFrame;
John Spurlock46646232013-09-30 22:32:42 -04003659 final Rect dcf = mTmpDecorFrame;
Adrian Roosfa104232014-06-20 16:10:14 -07003660 final Rect sf = mTmpStableFrame;
John Spurlock46646232013-09-30 22:32:42 -04003661 dcf.setEmpty();
Craig Mautner69b08182012-09-05 13:07:13 -07003662
3663 final boolean hasNavBar = (isDefaultDisplay && mHasNavigationBar
Daniel Sandler36412a72011-08-04 09:35:13 -04003664 && mNavigationBar != null && mNavigationBar.isVisibleLw());
Daniel Sandler8956dbb2011-04-22 07:55:02 -04003665
Craig Mautnerf683b562012-10-02 11:10:57 -07003666 final int adjust = sim & SOFT_INPUT_MASK_ADJUST;
3667
Adrian Roosfa104232014-06-20 16:10:14 -07003668 if (isDefaultDisplay) {
3669 sf.set(mStableLeft, mStableTop, mStableRight, mStableBottom);
3670 } else {
3671 sf.set(mOverscanLeft, mOverscanTop, mOverscanRight, mOverscanBottom);
3672 }
3673
Craig Mautner69b08182012-09-05 13:07:13 -07003674 if (!isDefaultDisplay) {
3675 if (attached != null) {
3676 // If this window is attached to another, our display
3677 // frame is the same as the one we are attached to.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003678 setAttachedWindowFrames(win, fl, adjust, attached, true, pf, df, of, cf, vf);
Craig Mautner69b08182012-09-05 13:07:13 -07003679 } else {
3680 // Give the window full screen.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003681 pf.left = df.left = of.left = cf.left = mOverscanScreenLeft;
3682 pf.top = df.top = of.top = cf.top = mOverscanScreenTop;
3683 pf.right = df.right = of.right = cf.right
Dianne Hackbornc652de82013-02-15 16:32:56 -08003684 = mOverscanScreenLeft + mOverscanScreenWidth;
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003685 pf.bottom = df.bottom = of.bottom = cf.bottom
Dianne Hackbornc652de82013-02-15 16:32:56 -08003686 = mOverscanScreenTop + mOverscanScreenHeight;
Craig Mautner69b08182012-09-05 13:07:13 -07003687 }
Jorim Jaggi225d3b52015-04-01 11:18:57 -07003688 } else if (attrs.type == TYPE_INPUT_METHOD) {
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003689 pf.left = df.left = of.left = cf.left = vf.left = mDockLeft;
3690 pf.top = df.top = of.top = cf.top = vf.top = mDockTop;
3691 pf.right = df.right = of.right = cf.right = vf.right = mDockRight;
John Spurlockc68d5772013-10-08 11:47:58 -04003692 // IM dock windows layout below the nav bar...
John Spurlock57beb3b2013-10-10 10:27:44 -04003693 pf.bottom = df.bottom = of.bottom = mUnrestrictedScreenTop + mUnrestrictedScreenHeight;
John Spurlockc68d5772013-10-08 11:47:58 -04003694 // ...with content insets above the nav bar
3695 cf.bottom = vf.bottom = mStableBottom;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003696 // IM dock windows always go to the bottom of the screen.
3697 attrs.gravity = Gravity.BOTTOM;
3698 mDockLayer = win.getSurfaceLayer();
Jorim Jaggi225d3b52015-04-01 11:18:57 -07003699 } else if (attrs.type == TYPE_VOICE_INTERACTION) {
3700 pf.left = df.left = of.left = cf.left = vf.left = mUnrestrictedScreenLeft;
3701 pf.top = df.top = of.top = mUnrestrictedScreenTop;
3702 pf.right = df.right = of.right = cf.right = vf.right = mUnrestrictedScreenLeft
3703 + mUnrestrictedScreenWidth;
3704 pf.bottom = df.bottom = of.bottom = cf.bottom = mUnrestrictedScreenTop
3705 + mUnrestrictedScreenHeight;
3706 cf.bottom = vf.bottom = mStableBottom;
3707 cf.top = vf.top = mStableTop;
Jorim Jaggie0700182014-08-21 01:12:37 +02003708 } else if (win == mStatusBar && (attrs.privateFlags & PRIVATE_FLAG_KEYGUARD) != 0) {
3709 pf.left = df.left = of.left = mUnrestrictedScreenLeft;
3710 pf.top = df.top = of.top = mUnrestrictedScreenTop;
3711 pf.right = df.right = of.right = mUnrestrictedScreenWidth + mUnrestrictedScreenLeft;
3712 pf.bottom = df.bottom = of.bottom = mUnrestrictedScreenHeight + mUnrestrictedScreenTop;
3713 cf.left = vf.left = mStableLeft;
3714 cf.top = vf.top = mStableTop;
3715 cf.right = vf.right = mStableRight;
3716 vf.bottom = mStableBottom;
3717 cf.bottom = mContentBottom;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003718 } else {
John Spurlock46646232013-09-30 22:32:42 -04003719
3720 // Default policy decor for the default display
3721 dcf.left = mSystemLeft;
3722 dcf.top = mSystemTop;
3723 dcf.right = mSystemRight;
3724 dcf.bottom = mSystemBottom;
John Spurlockbd957402013-10-03 11:38:39 -04003725 final boolean inheritTranslucentDecor = (attrs.privateFlags
3726 & WindowManager.LayoutParams.PRIVATE_FLAG_INHERIT_TRANSLUCENT_DECOR) != 0;
John Spurlock65567d42013-10-08 10:08:32 -04003727 final boolean isAppWindow =
3728 attrs.type >= WindowManager.LayoutParams.FIRST_APPLICATION_WINDOW &&
3729 attrs.type <= WindowManager.LayoutParams.LAST_APPLICATION_WINDOW;
3730 final boolean topAtRest =
3731 win == mTopFullscreenOpaqueWindowState && !win.isAnimatingLw();
3732 if (isAppWindow && !inheritTranslucentDecor && !topAtRest) {
John Spurlockbd957402013-10-03 11:38:39 -04003733 if ((sysUiFl & View.SYSTEM_UI_FLAG_FULLSCREEN) == 0
3734 && (fl & WindowManager.LayoutParams.FLAG_FULLSCREEN) == 0
Adrian Roosea562512014-05-05 13:33:03 +02003735 && (fl & WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS) == 0
3736 && (fl & WindowManager.LayoutParams.
3737 FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS) == 0) {
John Spurlock46646232013-09-30 22:32:42 -04003738 // Ensure policy decor includes status bar
3739 dcf.top = mStableTop;
3740 }
John Spurlockbd957402013-10-03 11:38:39 -04003741 if ((fl & WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION) == 0
Adrian Roosea562512014-05-05 13:33:03 +02003742 && (sysUiFl & View.SYSTEM_UI_FLAG_HIDE_NAVIGATION) == 0
3743 && (fl & WindowManager.LayoutParams.
3744 FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS) == 0) {
John Spurlock46646232013-09-30 22:32:42 -04003745 // Ensure policy decor includes navigation bar
3746 dcf.bottom = mStableBottom;
3747 dcf.right = mStableRight;
3748 }
3749 }
3750
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003751 if ((fl & (FLAG_LAYOUT_IN_SCREEN | FLAG_LAYOUT_INSET_DECOR))
3752 == (FLAG_LAYOUT_IN_SCREEN | FLAG_LAYOUT_INSET_DECOR)) {
RoboErik8a2cfc32014-05-16 11:19:38 -07003753 if (DEBUG_LAYOUT) Slog.v(TAG, "layoutWindowLw(" + attrs.getTitle()
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003754 + "): IN_SCREEN, INSET_DECOR");
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003755 // This is the case for a normal activity window: we want it
3756 // to cover all of the screen space, and it can take care of
3757 // moving its contents to account for screen decorations that
3758 // intrude into that space.
3759 if (attached != null) {
3760 // If this window is attached to another, our display
3761 // frame is the same as the one we are attached to.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003762 setAttachedWindowFrames(win, fl, adjust, attached, true, pf, df, of, cf, vf);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003763 } else {
Daniel Sandler8956dbb2011-04-22 07:55:02 -04003764 if (attrs.type == TYPE_STATUS_BAR_PANEL
3765 || attrs.type == TYPE_STATUS_BAR_SUB_PANEL) {
Joe Onorato29fc2c92010-11-24 10:26:50 -08003766 // Status bar panels are the only windows who can go on top of
3767 // the status bar. They are protected by the STATUS_BAR_SERVICE
3768 // permission, so they have the same privileges as the status
3769 // bar itself.
Daniel Sandler8956dbb2011-04-22 07:55:02 -04003770 //
Daniel Sandler8e8b4152011-07-21 01:16:43 -04003771 // However, they should still dodge the navigation bar if it exists.
Daniel Sandler8956dbb2011-04-22 07:55:02 -04003772
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003773 pf.left = df.left = of.left = hasNavBar
3774 ? mDockLeft : mUnrestrictedScreenLeft;
3775 pf.top = df.top = of.top = mUnrestrictedScreenTop;
3776 pf.right = df.right = of.right = hasNavBar
3777 ? mRestrictedScreenLeft+mRestrictedScreenWidth
3778 : mUnrestrictedScreenLeft + mUnrestrictedScreenWidth;
3779 pf.bottom = df.bottom = of.bottom = hasNavBar
3780 ? mRestrictedScreenTop+mRestrictedScreenHeight
3781 : mUnrestrictedScreenTop + mUnrestrictedScreenHeight;
Daniel Sandler8956dbb2011-04-22 07:55:02 -04003782
Craig Mautnereda67292013-04-28 13:50:14 -07003783 if (DEBUG_LAYOUT) Slog.v(TAG, String.format(
Daniel Sandler8e8b4152011-07-21 01:16:43 -04003784 "Laying out status bar window: (%d,%d - %d,%d)",
3785 pf.left, pf.top, pf.right, pf.bottom));
John Spurlock46646232013-09-30 22:32:42 -04003786 } else if ((fl & FLAG_LAYOUT_IN_OVERSCAN) != 0
Dianne Hackbornc652de82013-02-15 16:32:56 -08003787 && attrs.type >= WindowManager.LayoutParams.FIRST_APPLICATION_WINDOW
3788 && attrs.type <= WindowManager.LayoutParams.LAST_SUB_WINDOW) {
3789 // Asking to layout into the overscan region, so give it that pure
3790 // unrestricted area.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003791 pf.left = df.left = of.left = mOverscanScreenLeft;
3792 pf.top = df.top = of.top = mOverscanScreenTop;
3793 pf.right = df.right = of.right = mOverscanScreenLeft + mOverscanScreenWidth;
3794 pf.bottom = df.bottom = of.bottom = mOverscanScreenTop
3795 + mOverscanScreenHeight;
Alan Viverette5a0f4ec2013-10-07 15:10:29 -07003796 } else if (canHideNavigationBar()
Dianne Hackbornf87d1962012-04-04 12:48:24 -07003797 && (sysUiFl & View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION) != 0
Jorim Jaggi380ecb82014-03-14 17:25:20 +01003798 && attrs.type >= WindowManager.LayoutParams.FIRST_APPLICATION_WINDOW
3799 && attrs.type <= WindowManager.LayoutParams.LAST_SUB_WINDOW) {
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07003800 // Asking for layout as if the nav bar is hidden, lets the
Dianne Hackbornc652de82013-02-15 16:32:56 -08003801 // application extend into the unrestricted overscan screen area. We
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07003802 // only do this for application windows to ensure no window that
3803 // can be above the nav bar can do this.
Dianne Hackborn313440842013-02-19 19:22:59 -08003804 pf.left = df.left = mOverscanScreenLeft;
3805 pf.top = df.top = mOverscanScreenTop;
3806 pf.right = df.right = mOverscanScreenLeft + mOverscanScreenWidth;
3807 pf.bottom = df.bottom = mOverscanScreenTop + mOverscanScreenHeight;
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003808 // We need to tell the app about where the frame inside the overscan
3809 // is, so it can inset its content by that amount -- it didn't ask
3810 // to actually extend itself into the overscan region.
3811 of.left = mUnrestrictedScreenLeft;
3812 of.top = mUnrestrictedScreenTop;
3813 of.right = mUnrestrictedScreenLeft + mUnrestrictedScreenWidth;
3814 of.bottom = mUnrestrictedScreenTop + mUnrestrictedScreenHeight;
Joe Onorato29fc2c92010-11-24 10:26:50 -08003815 } else {
Dianne Hackborn313440842013-02-19 19:22:59 -08003816 pf.left = df.left = mRestrictedOverscanScreenLeft;
3817 pf.top = df.top = mRestrictedOverscanScreenTop;
3818 pf.right = df.right = mRestrictedOverscanScreenLeft
3819 + mRestrictedOverscanScreenWidth;
3820 pf.bottom = df.bottom = mRestrictedOverscanScreenTop
3821 + mRestrictedOverscanScreenHeight;
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003822 // We need to tell the app about where the frame inside the overscan
3823 // is, so it can inset its content by that amount -- it didn't ask
3824 // to actually extend itself into the overscan region.
3825 of.left = mUnrestrictedScreenLeft;
3826 of.top = mUnrestrictedScreenTop;
3827 of.right = mUnrestrictedScreenLeft + mUnrestrictedScreenWidth;
3828 of.bottom = mUnrestrictedScreenTop + mUnrestrictedScreenHeight;
Joe Onorato29fc2c92010-11-24 10:26:50 -08003829 }
Craig Mautner69b08182012-09-05 13:07:13 -07003830
John Spurlock46646232013-09-30 22:32:42 -04003831 if ((fl & FLAG_FULLSCREEN) == 0) {
Dianne Hackborne30e02f2014-05-27 18:24:45 -07003832 if (win.isVoiceInteraction()) {
3833 cf.left = mVoiceContentLeft;
3834 cf.top = mVoiceContentTop;
3835 cf.right = mVoiceContentRight;
3836 cf.bottom = mVoiceContentBottom;
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003837 } else {
Dianne Hackborne30e02f2014-05-27 18:24:45 -07003838 if (adjust != SOFT_INPUT_ADJUST_RESIZE) {
3839 cf.left = mDockLeft;
3840 cf.top = mDockTop;
3841 cf.right = mDockRight;
3842 cf.bottom = mDockBottom;
3843 } else {
3844 cf.left = mContentLeft;
3845 cf.top = mContentTop;
3846 cf.right = mContentRight;
3847 cf.bottom = mContentBottom;
3848 }
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003849 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003850 } else {
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003851 // Full screen windows are always given a layout that is as if the
3852 // status bar and other transient decors are gone. This is to avoid
3853 // bad states when moving from a window that is not hding the
3854 // status bar to one that is.
3855 cf.left = mRestrictedScreenLeft;
3856 cf.top = mRestrictedScreenTop;
3857 cf.right = mRestrictedScreenLeft + mRestrictedScreenWidth;
3858 cf.bottom = mRestrictedScreenTop + mRestrictedScreenHeight;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003859 }
Dianne Hackborn5b5cc4d2012-05-16 13:15:00 -07003860 applyStableConstraints(sysUiFl, fl, cf);
Dianne Hackborndea3ef72010-10-28 14:24:22 -07003861 if (adjust != SOFT_INPUT_ADJUST_NOTHING) {
3862 vf.left = mCurLeft;
3863 vf.top = mCurTop;
3864 vf.right = mCurRight;
3865 vf.bottom = mCurBottom;
3866 } else {
3867 vf.set(cf);
3868 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003869 }
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07003870 } else if ((fl & FLAG_LAYOUT_IN_SCREEN) != 0 || (sysUiFl
3871 & (View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
3872 | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION)) != 0) {
Craig Mautnereda67292013-04-28 13:50:14 -07003873 if (DEBUG_LAYOUT) Slog.v(TAG, "layoutWindowLw(" + attrs.getTitle() +
3874 "): IN_SCREEN");
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003875 // A window that has requested to fill the entire screen just
3876 // gets everything, period.
Daniel Sandler8956dbb2011-04-22 07:55:02 -04003877 if (attrs.type == TYPE_STATUS_BAR_PANEL
3878 || attrs.type == TYPE_STATUS_BAR_SUB_PANEL) {
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003879 pf.left = df.left = of.left = cf.left = hasNavBar
3880 ? mDockLeft : mUnrestrictedScreenLeft;
3881 pf.top = df.top = of.top = cf.top = mUnrestrictedScreenTop;
3882 pf.right = df.right = of.right = cf.right = hasNavBar
Daniel Sandler8e8b4152011-07-21 01:16:43 -04003883 ? mRestrictedScreenLeft+mRestrictedScreenWidth
Dianne Hackbornc652de82013-02-15 16:32:56 -08003884 : mUnrestrictedScreenLeft + mUnrestrictedScreenWidth;
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003885 pf.bottom = df.bottom = of.bottom = cf.bottom = hasNavBar
Daniel Sandler8e8b4152011-07-21 01:16:43 -04003886 ? mRestrictedScreenTop+mRestrictedScreenHeight
Dianne Hackbornc652de82013-02-15 16:32:56 -08003887 : mUnrestrictedScreenTop + mUnrestrictedScreenHeight;
Craig Mautnereda67292013-04-28 13:50:14 -07003888 if (DEBUG_LAYOUT) Slog.v(TAG, String.format(
Daniel Sandler36412a72011-08-04 09:35:13 -04003889 "Laying out IN_SCREEN status bar window: (%d,%d - %d,%d)",
3890 pf.left, pf.top, pf.right, pf.bottom));
Jim Millere898ac52012-04-06 17:10:57 -07003891 } else if (attrs.type == TYPE_NAVIGATION_BAR
3892 || attrs.type == TYPE_NAVIGATION_BAR_PANEL) {
Daniel Sandler8e8b4152011-07-21 01:16:43 -04003893 // The navigation bar has Real Ultimate Power.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003894 pf.left = df.left = of.left = mUnrestrictedScreenLeft;
3895 pf.top = df.top = of.top = mUnrestrictedScreenTop;
3896 pf.right = df.right = of.right = mUnrestrictedScreenLeft
3897 + mUnrestrictedScreenWidth;
3898 pf.bottom = df.bottom = of.bottom = mUnrestrictedScreenTop
3899 + mUnrestrictedScreenHeight;
Craig Mautnereda67292013-04-28 13:50:14 -07003900 if (DEBUG_LAYOUT) Slog.v(TAG, String.format(
Daniel Sandler8e8b4152011-07-21 01:16:43 -04003901 "Laying out navigation bar window: (%d,%d - %d,%d)",
3902 pf.left, pf.top, pf.right, pf.bottom));
Dianne Hackborn01011c32012-02-21 13:54:21 -08003903 } else if ((attrs.type == TYPE_SECURE_SYSTEM_OVERLAY
3904 || attrs.type == TYPE_BOOT_PROGRESS)
Jeff Brownbfcb60a2011-09-08 18:51:14 -07003905 && ((fl & FLAG_FULLSCREEN) != 0)) {
3906 // Fullscreen secure system overlays get what they ask for.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003907 pf.left = df.left = of.left = cf.left = mOverscanScreenLeft;
3908 pf.top = df.top = of.top = cf.top = mOverscanScreenTop;
3909 pf.right = df.right = of.right = cf.right = mOverscanScreenLeft
3910 + mOverscanScreenWidth;
3911 pf.bottom = df.bottom = of.bottom = cf.bottom = mOverscanScreenTop
3912 + mOverscanScreenHeight;
Craig Mautner165be0c2015-01-27 15:16:58 -08003913 } else if (attrs.type == TYPE_BOOT_PROGRESS) {
Dianne Hackborn01011c32012-02-21 13:54:21 -08003914 // Boot progress screen always covers entire display.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003915 pf.left = df.left = of.left = cf.left = mOverscanScreenLeft;
3916 pf.top = df.top = of.top = cf.top = mOverscanScreenTop;
3917 pf.right = df.right = of.right = cf.right = mOverscanScreenLeft
3918 + mOverscanScreenWidth;
3919 pf.bottom = df.bottom = of.bottom = cf.bottom = mOverscanScreenTop
3920 + mOverscanScreenHeight;
John Spurlockef4adae2013-08-26 17:58:58 -04003921 } else if (attrs.type == TYPE_WALLPAPER) {
Dianne Hackborn067e5f62014-09-07 23:14:30 -07003922 // The wallpaper also has Real Ultimate Power, but we want to tell
3923 // it about the overscan area.
3924 pf.left = df.left = mOverscanScreenLeft;
3925 pf.top = df.top = mOverscanScreenTop;
3926 pf.right = df.right = mOverscanScreenLeft + mOverscanScreenWidth;
3927 pf.bottom = df.bottom = mOverscanScreenTop + mOverscanScreenHeight;
3928 of.left = cf.left = mUnrestrictedScreenLeft;
3929 of.top = cf.top = mUnrestrictedScreenTop;
3930 of.right = cf.right = mUnrestrictedScreenLeft + mUnrestrictedScreenWidth;
3931 of.bottom = cf.bottom = mUnrestrictedScreenTop + mUnrestrictedScreenHeight;
John Spurlock46646232013-09-30 22:32:42 -04003932 } else if ((fl & FLAG_LAYOUT_IN_OVERSCAN) != 0
Dianne Hackbornc652de82013-02-15 16:32:56 -08003933 && attrs.type >= WindowManager.LayoutParams.FIRST_APPLICATION_WINDOW
3934 && attrs.type <= WindowManager.LayoutParams.LAST_SUB_WINDOW) {
3935 // Asking to layout into the overscan region, so give it that pure
3936 // unrestricted area.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003937 pf.left = df.left = of.left = cf.left = mOverscanScreenLeft;
3938 pf.top = df.top = of.top = cf.top = mOverscanScreenTop;
3939 pf.right = df.right = of.right = cf.right
Dianne Hackbornc652de82013-02-15 16:32:56 -08003940 = mOverscanScreenLeft + mOverscanScreenWidth;
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003941 pf.bottom = df.bottom = of.bottom = cf.bottom
Dianne Hackbornc652de82013-02-15 16:32:56 -08003942 = mOverscanScreenTop + mOverscanScreenHeight;
Alan Viverette5a0f4ec2013-10-07 15:10:29 -07003943 } else if (canHideNavigationBar()
Dianne Hackbornf87d1962012-04-04 12:48:24 -07003944 && (sysUiFl & View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION) != 0
Craig Mautnerbeac1062014-06-03 14:38:57 -07003945 && (attrs.type == TYPE_STATUS_BAR
3946 || attrs.type == TYPE_TOAST
Jorim Jaggi2fdeeab2015-04-01 15:13:03 -07003947 || attrs.type == TYPE_VOICE_INTERACTION_STARTING
John Spurlock34e13d92013-08-10 06:52:28 -04003948 || (attrs.type >= WindowManager.LayoutParams.FIRST_APPLICATION_WINDOW
3949 && attrs.type <= WindowManager.LayoutParams.LAST_SUB_WINDOW))) {
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07003950 // Asking for layout as if the nav bar is hidden, lets the
3951 // application extend into the unrestricted screen area. We
John Spurlock34e13d92013-08-10 06:52:28 -04003952 // only do this for application windows (or toasts) to ensure no window that
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07003953 // can be above the nav bar can do this.
3954 // XXX This assumes that an app asking for this will also
3955 // ask for layout in only content. We can't currently figure out
3956 // what the screen would be if only laying out to hide the nav bar.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003957 pf.left = df.left = of.left = cf.left = mUnrestrictedScreenLeft;
3958 pf.top = df.top = of.top = cf.top = mUnrestrictedScreenTop;
3959 pf.right = df.right = of.right = cf.right = mUnrestrictedScreenLeft
3960 + mUnrestrictedScreenWidth;
3961 pf.bottom = df.bottom = of.bottom = cf.bottom = mUnrestrictedScreenTop
3962 + mUnrestrictedScreenHeight;
Joe Onorato29fc2c92010-11-24 10:26:50 -08003963 } else {
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003964 pf.left = df.left = of.left = cf.left = mRestrictedScreenLeft;
3965 pf.top = df.top = of.top = cf.top = mRestrictedScreenTop;
3966 pf.right = df.right = of.right = cf.right = mRestrictedScreenLeft
3967 + mRestrictedScreenWidth;
3968 pf.bottom = df.bottom = of.bottom = cf.bottom = mRestrictedScreenTop
3969 + mRestrictedScreenHeight;
Joe Onorato29fc2c92010-11-24 10:26:50 -08003970 }
Craig Mautner69b08182012-09-05 13:07:13 -07003971
Dianne Hackborn5b5cc4d2012-05-16 13:15:00 -07003972 applyStableConstraints(sysUiFl, fl, cf);
Craig Mautner69b08182012-09-05 13:07:13 -07003973
Dianne Hackborndea3ef72010-10-28 14:24:22 -07003974 if (adjust != SOFT_INPUT_ADJUST_NOTHING) {
3975 vf.left = mCurLeft;
3976 vf.top = mCurTop;
3977 vf.right = mCurRight;
3978 vf.bottom = mCurBottom;
3979 } else {
3980 vf.set(cf);
3981 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003982 } else if (attached != null) {
Craig Mautnereda67292013-04-28 13:50:14 -07003983 if (DEBUG_LAYOUT) Slog.v(TAG, "layoutWindowLw(" + attrs.getTitle() +
3984 "): attached to " + attached);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003985 // A child window should be placed inside of the same visible
3986 // frame that its parent had.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003987 setAttachedWindowFrames(win, fl, adjust, attached, false, pf, df, of, cf, vf);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003988 } else {
Craig Mautnereda67292013-04-28 13:50:14 -07003989 if (DEBUG_LAYOUT) Slog.v(TAG, "layoutWindowLw(" + attrs.getTitle() +
3990 "): normal window");
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003991 // Otherwise, a normal window must be placed inside the content
3992 // of all screen decorations.
Dianne Hackborna239c842011-06-01 12:28:20 -07003993 if (attrs.type == TYPE_STATUS_BAR_PANEL) {
3994 // Status bar panels are the only windows who can go on top of
3995 // the status bar. They are protected by the STATUS_BAR_SERVICE
3996 // permission, so they have the same privileges as the status
3997 // bar itself.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003998 pf.left = df.left = of.left = cf.left = mRestrictedScreenLeft;
3999 pf.top = df.top = of.top = cf.top = mRestrictedScreenTop;
4000 pf.right = df.right = of.right = cf.right = mRestrictedScreenLeft
4001 + mRestrictedScreenWidth;
4002 pf.bottom = df.bottom = of.bottom = cf.bottom = mRestrictedScreenTop
4003 + mRestrictedScreenHeight;
John Spurlock414c1f02013-12-04 13:47:36 -05004004 } else if (attrs.type == TYPE_TOAST || attrs.type == TYPE_SYSTEM_ALERT
4005 || attrs.type == TYPE_VOLUME_OVERLAY) {
4006 // These dialogs are stable to interim decor changes.
John Spurlockbd957402013-10-03 11:38:39 -04004007 pf.left = df.left = of.left = cf.left = mStableLeft;
4008 pf.top = df.top = of.top = cf.top = mStableTop;
4009 pf.right = df.right = of.right = cf.right = mStableRight;
4010 pf.bottom = df.bottom = of.bottom = cf.bottom = mStableBottom;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004011 } else {
Dianne Hackborna239c842011-06-01 12:28:20 -07004012 pf.left = mContentLeft;
4013 pf.top = mContentTop;
4014 pf.right = mContentRight;
4015 pf.bottom = mContentBottom;
Dianne Hackborn20d94742014-05-29 18:35:45 -07004016 if (win.isVoiceInteraction()) {
4017 df.left = of.left = cf.left = mVoiceContentLeft;
4018 df.top = of.top = cf.top = mVoiceContentTop;
4019 df.right = of.right = cf.right = mVoiceContentRight;
4020 df.bottom = of.bottom = cf.bottom = mVoiceContentBottom;
4021 } else if (adjust != SOFT_INPUT_ADJUST_RESIZE) {
Dianne Hackbornc4aad012013-02-22 15:05:25 -08004022 df.left = of.left = cf.left = mDockLeft;
4023 df.top = of.top = cf.top = mDockTop;
4024 df.right = of.right = cf.right = mDockRight;
4025 df.bottom = of.bottom = cf.bottom = mDockBottom;
Dianne Hackborna239c842011-06-01 12:28:20 -07004026 } else {
Dianne Hackbornc4aad012013-02-22 15:05:25 -08004027 df.left = of.left = cf.left = mContentLeft;
4028 df.top = of.top = cf.top = mContentTop;
4029 df.right = of.right = cf.right = mContentRight;
4030 df.bottom = of.bottom = cf.bottom = mContentBottom;
Dianne Hackborna239c842011-06-01 12:28:20 -07004031 }
4032 if (adjust != SOFT_INPUT_ADJUST_NOTHING) {
4033 vf.left = mCurLeft;
4034 vf.top = mCurTop;
4035 vf.right = mCurRight;
4036 vf.bottom = mCurBottom;
4037 } else {
4038 vf.set(cf);
4039 }
Dianne Hackborndea3ef72010-10-28 14:24:22 -07004040 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004041 }
4042 }
Craig Mautner69b08182012-09-05 13:07:13 -07004043
Craig Mautnerb816bed2013-07-23 10:26:17 -07004044 // TYPE_SYSTEM_ERROR is above the NavigationBar so it can't be allowed to extend over it.
4045 if ((fl & FLAG_LAYOUT_NO_LIMITS) != 0 && attrs.type != TYPE_SYSTEM_ERROR) {
Dianne Hackborn067e5f62014-09-07 23:14:30 -07004046 df.left = df.top = -10000;
4047 df.right = df.bottom = 10000;
4048 if (attrs.type != TYPE_WALLPAPER) {
4049 of.left = of.top = cf.left = cf.top = vf.left = vf.top = -10000;
4050 of.right = of.bottom = cf.right = cf.bottom = vf.right = vf.bottom = 10000;
4051 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004052 }
4053
Craig Mautnereda67292013-04-28 13:50:14 -07004054 if (DEBUG_LAYOUT) Slog.v(TAG, "Compute frame " + attrs.getTitle()
The Android Open Source Project11267662009-03-18 17:39:47 -07004055 + ": sim=#" + Integer.toHexString(sim)
RoboErik8a2cfc32014-05-16 11:19:38 -07004056 + " attach=" + attached + " type=" + attrs.type
Daniel Sandler8956dbb2011-04-22 07:55:02 -04004057 + String.format(" flags=0x%08x", fl)
The Android Open Source Project11267662009-03-18 17:39:47 -07004058 + " pf=" + pf.toShortString() + " df=" + df.toShortString()
Dianne Hackbornc4aad012013-02-22 15:05:25 -08004059 + " of=" + of.toShortString()
John Spurlock46646232013-09-30 22:32:42 -04004060 + " cf=" + cf.toShortString() + " vf=" + vf.toShortString()
Adrian Roosfa104232014-06-20 16:10:14 -07004061 + " dcf=" + dcf.toShortString()
4062 + " sf=" + sf.toShortString());
Craig Mautner69b08182012-09-05 13:07:13 -07004063
Adrian Roosfa104232014-06-20 16:10:14 -07004064 win.computeFrameLw(pf, df, of, cf, vf, dcf, sf);
Craig Mautner69b08182012-09-05 13:07:13 -07004065
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004066 // Dock windows carve out the bottom of the screen, so normal windows
4067 // can't appear underneath them.
Craig Mautner8bd206b2012-10-03 10:32:02 -07004068 if (attrs.type == TYPE_INPUT_METHOD && win.isVisibleOrBehindKeyguardLw()
4069 && !win.getGivenInsetsPendingLw()) {
satok1bc0a492012-04-25 22:47:12 +09004070 setLastInputMethodWindowLw(null, null);
4071 offsetInputMethodWindowLw(win);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004072 }
Dianne Hackborne30e02f2014-05-27 18:24:45 -07004073 if (attrs.type == TYPE_VOICE_INTERACTION && win.isVisibleOrBehindKeyguardLw()
4074 && !win.getGivenInsetsPendingLw()) {
4075 offsetVoiceInputWindowLw(win);
4076 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004077 }
4078
satok1bc0a492012-04-25 22:47:12 +09004079 private void offsetInputMethodWindowLw(WindowState win) {
Craig Mautner4774f6a2015-03-23 11:42:55 -07004080 int top = Math.max(win.getDisplayFrameLw().top, win.getContentFrameLw().top);
satok1bc0a492012-04-25 22:47:12 +09004081 top += win.getGivenContentInsetsLw().top;
4082 if (mContentBottom > top) {
4083 mContentBottom = top;
4084 }
Dianne Hackborne30e02f2014-05-27 18:24:45 -07004085 if (mVoiceContentBottom > top) {
4086 mVoiceContentBottom = top;
4087 }
satok1bc0a492012-04-25 22:47:12 +09004088 top = win.getVisibleFrameLw().top;
4089 top += win.getGivenVisibleInsetsLw().top;
4090 if (mCurBottom > top) {
4091 mCurBottom = top;
4092 }
Craig Mautnereda67292013-04-28 13:50:14 -07004093 if (DEBUG_LAYOUT) Slog.v(TAG, "Input method: mDockBottom="
satok1bc0a492012-04-25 22:47:12 +09004094 + mDockBottom + " mContentBottom="
4095 + mContentBottom + " mCurBottom=" + mCurBottom);
4096 }
4097
Dianne Hackborne30e02f2014-05-27 18:24:45 -07004098 private void offsetVoiceInputWindowLw(WindowState win) {
Craig Mautner4774f6a2015-03-23 11:42:55 -07004099 int top = Math.max(win.getDisplayFrameLw().top, win.getContentFrameLw().top);
Dianne Hackbornae6688b2015-02-11 17:02:41 -08004100 top += win.getGivenContentInsetsLw().top;
4101 if (mVoiceContentBottom > top) {
4102 mVoiceContentBottom = top;
Dianne Hackborne30e02f2014-05-27 18:24:45 -07004103 }
4104 }
4105
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004106 /** {@inheritDoc} */
Craig Mautner61ac6bb2012-02-02 17:29:33 -08004107 @Override
4108 public void finishLayoutLw() {
4109 return;
Dianne Hackborn5f3063e2010-03-10 16:01:58 -08004110 }
4111
4112 /** {@inheritDoc} */
Craig Mautnerad09bcc2012-10-08 13:33:11 -07004113 @Override
Craig Mautner39834192012-09-02 07:47:24 -07004114 public void beginPostLayoutPolicyLw(int displayWidth, int displayHeight) {
Dianne Hackborn5f3063e2010-03-10 16:01:58 -08004115 mTopFullscreenOpaqueWindowState = null;
Adrian Rooscd3884d2015-02-18 17:25:23 +01004116 mTopFullscreenOpaqueOrDimmingWindowState = null;
Craig Mautner2bc789b2014-03-19 19:48:38 -07004117 mAppsToBeHidden.clear();
Jorim Jaggic13fcac2014-09-11 17:36:57 +02004118 mAppsThatDismissKeyguard.clear();
Dianne Hackborn5f3063e2010-03-10 16:01:58 -08004119 mForceStatusBar = false;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07004120 mForceStatusBarFromKeyguard = false;
Dianne Hackborn891d3fb2013-01-09 18:31:37 -08004121 mForcingShowNavBar = false;
4122 mForcingShowNavBarLayer = -1;
RoboErik8a2cfc32014-05-16 11:19:38 -07004123
Dianne Hackborn5f3063e2010-03-10 16:01:58 -08004124 mHideLockScreen = false;
4125 mAllowLockscreenWhenOn = false;
Craig Mautnerad09bcc2012-10-08 13:33:11 -07004126 mDismissKeyguard = DISMISS_KEYGUARD_NONE;
Dianne Hackborn7ad44382012-10-18 17:46:00 -07004127 mShowingLockscreen = false;
4128 mShowingDream = false;
Craig Mautnerc9457fa2014-06-06 14:27:48 -07004129 mWinShowWhenLocked = null;
Jim Millerab954542014-10-10 18:21:49 -07004130 mKeyguardSecure = isKeyguardSecure();
4131 mKeyguardSecureIncludingHidden = mKeyguardSecure
4132 && (mKeyguardDelegate != null && mKeyguardDelegate.isShowing());
Dianne Hackborn5f3063e2010-03-10 16:01:58 -08004133 }
4134
4135 /** {@inheritDoc} */
Craig Mautnerad09bcc2012-10-08 13:33:11 -07004136 @Override
Craig Mautnerc9457fa2014-06-06 14:27:48 -07004137 public void applyPostLayoutPolicyLw(WindowState win, WindowManager.LayoutParams attrs) {
Dianne Hackbornbc1aa7b2011-09-20 11:20:31 -07004138 if (DEBUG_LAYOUT) Slog.i(TAG, "Win " + win + ": isVisibleOrBehindKeyguardLw="
4139 + win.isVisibleOrBehindKeyguardLw());
John Spurlockc6d1c602014-01-17 15:22:06 -05004140 final int fl = PolicyControl.getWindowFlags(win, attrs);
John Spurlock414c1f02013-12-04 13:47:36 -05004141 if (mTopFullscreenOpaqueWindowState == null
4142 && win.isVisibleLw() && attrs.type == TYPE_INPUT_METHOD) {
4143 mForcingShowNavBar = true;
4144 mForcingShowNavBarLayer = win.getSurfaceLayer();
Dianne Hackborn891d3fb2013-01-09 18:31:37 -08004145 }
Jorim Jaggiafd4a552014-04-08 15:13:05 +02004146 if (attrs.type == TYPE_STATUS_BAR && (attrs.privateFlags & PRIVATE_FLAG_KEYGUARD) != 0) {
Jorim Jaggiafd4a552014-04-08 15:13:05 +02004147 mForceStatusBarFromKeyguard = true;
4148 }
Adrian Roos602c68e2015-04-24 16:03:47 -07004149
4150 boolean appWindow = attrs.type >= FIRST_APPLICATION_WINDOW
4151 && attrs.type < FIRST_SYSTEM_WINDOW;
4152 final boolean showWhenLocked = (fl & FLAG_SHOW_WHEN_LOCKED) != 0;
4153 final boolean dismissKeyguard = (fl & FLAG_DISMISS_KEYGUARD) != 0;
4154
Dianne Hackborn5f3063e2010-03-10 16:01:58 -08004155 if (mTopFullscreenOpaqueWindowState == null &&
Dianne Hackborn01b02a72012-01-12 14:05:03 -08004156 win.isVisibleOrBehindKeyguardLw() && !win.isGoneForLayoutLw()) {
John Spurlockc6d1c602014-01-17 15:22:06 -05004157 if ((fl & FLAG_FORCE_NOT_FULLSCREEN) != 0) {
Jorim Jaggi380ecb82014-03-14 17:25:20 +01004158 if ((attrs.privateFlags & PRIVATE_FLAG_KEYGUARD) != 0) {
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07004159 mForceStatusBarFromKeyguard = true;
4160 } else {
4161 mForceStatusBar = true;
4162 }
4163 }
Jorim Jaggi380ecb82014-03-14 17:25:20 +01004164 if ((attrs.privateFlags & PRIVATE_FLAG_KEYGUARD) != 0) {
Dianne Hackborn7ad44382012-10-18 17:46:00 -07004165 mShowingLockscreen = true;
Dianne Hackbornbc1aa7b2011-09-20 11:20:31 -07004166 }
Dianne Hackborn7ad44382012-10-18 17:46:00 -07004167 if (attrs.type == TYPE_DREAM) {
Jeff Brownc8018eb2012-10-29 21:33:27 -07004168 // If the lockscreen was showing when the dream started then wait
4169 // for the dream to draw before hiding the lockscreen.
4170 if (!mDreamingLockscreen
4171 || (win.isVisibleLw() && win.hasDrawnLw())) {
4172 mShowingDream = true;
Craig Mautnerab55e522014-03-03 13:26:03 -08004173 appWindow = true;
Dianne Hackborn7ad44382012-10-18 17:46:00 -07004174 }
4175 }
Craig Mautnerab55e522014-03-03 13:26:03 -08004176
Craig Mautnerab55e522014-03-03 13:26:03 -08004177 if (appWindow) {
Jorim Jaggic13fcac2014-09-11 17:36:57 +02004178 final IApplicationToken appToken = win.getAppToken();
4179 if (showWhenLocked) {
Craig Mautnerc9457fa2014-06-06 14:27:48 -07004180 // Remove any previous windows with the same appToken.
Jorim Jaggic13fcac2014-09-11 17:36:57 +02004181 mAppsToBeHidden.remove(appToken);
4182 mAppsThatDismissKeyguard.remove(appToken);
Craig Mautnerca0a1242014-12-02 12:25:14 -08004183 if (mAppsToBeHidden.isEmpty()) {
Craig Mautner192d6042014-12-02 23:24:48 -08004184 if (dismissKeyguard && !mKeyguardSecure) {
4185 mAppsThatDismissKeyguard.add(appToken);
4186 } else {
Craig Mautnerca0a1242014-12-02 12:25:14 -08004187 mWinShowWhenLocked = win;
4188 mHideLockScreen = true;
4189 mForceStatusBarFromKeyguard = false;
Craig Mautnerca0a1242014-12-02 12:25:14 -08004190 }
Craig Mautnerc9457fa2014-06-06 14:27:48 -07004191 }
Jorim Jaggic13fcac2014-09-11 17:36:57 +02004192 } else if (dismissKeyguard) {
Jim Millerab954542014-10-10 18:21:49 -07004193 if (mKeyguardSecure) {
Jorim Jaggic13fcac2014-09-11 17:36:57 +02004194 mAppsToBeHidden.add(appToken);
4195 } else {
4196 mAppsToBeHidden.remove(appToken);
4197 }
4198 mAppsThatDismissKeyguard.add(appToken);
Craig Mautner2bc789b2014-03-19 19:48:38 -07004199 } else {
Jorim Jaggic13fcac2014-09-11 17:36:57 +02004200 mAppsToBeHidden.add(appToken);
Craig Mautner2bc789b2014-03-19 19:48:38 -07004201 }
Craig Mautnerab55e522014-03-03 13:26:03 -08004202 if (attrs.x == 0 && attrs.y == 0
4203 && attrs.width == WindowManager.LayoutParams.MATCH_PARENT
4204 && attrs.height == WindowManager.LayoutParams.MATCH_PARENT) {
4205 if (DEBUG_LAYOUT) Slog.v(TAG, "Fullscreen window: " + win);
4206 mTopFullscreenOpaqueWindowState = win;
Adrian Rooscd3884d2015-02-18 17:25:23 +01004207 if (mTopFullscreenOpaqueOrDimmingWindowState == null) {
4208 mTopFullscreenOpaqueOrDimmingWindowState = win;
4209 }
Jorim Jaggic13fcac2014-09-11 17:36:57 +02004210 if (!mAppsThatDismissKeyguard.isEmpty() &&
4211 mDismissKeyguard == DISMISS_KEYGUARD_NONE) {
4212 if (DEBUG_LAYOUT) Slog.v(TAG,
4213 "Setting mDismissKeyguard true by win " + win);
4214 mDismissKeyguard = mWinDismissingKeyguard == win ?
4215 DISMISS_KEYGUARD_CONTINUE : DISMISS_KEYGUARD_START;
4216 mWinDismissingKeyguard = win;
Jim Millerab954542014-10-10 18:21:49 -07004217 mForceStatusBarFromKeyguard = mShowingLockscreen && mKeyguardSecure;
Jorim Jaggic13fcac2014-09-11 17:36:57 +02004218 } else if (mAppsToBeHidden.isEmpty() && showWhenLocked) {
4219 if (DEBUG_LAYOUT) Slog.v(TAG,
4220 "Setting mHideLockScreen to true by win " + win);
4221 mHideLockScreen = true;
4222 mForceStatusBarFromKeyguard = false;
Craig Mautnerab55e522014-03-03 13:26:03 -08004223 }
Craig Mautner00156ec2014-03-06 22:29:02 -08004224 if ((fl & FLAG_ALLOW_LOCK_WHILE_SCREEN_ON) != 0) {
Craig Mautnerab55e522014-03-03 13:26:03 -08004225 mAllowLockscreenWhenOn = true;
4226 }
Dianne Hackborn5f3063e2010-03-10 16:01:58 -08004227 }
Craig Mautnerc9457fa2014-06-06 14:27:48 -07004228
4229 if (mWinShowWhenLocked != null &&
Adrian Roos602c68e2015-04-24 16:03:47 -07004230 mWinShowWhenLocked.getAppToken() != win.getAppToken() &&
4231 (attrs.flags & FLAG_SHOW_WHEN_LOCKED) == 0) {
Craig Mautnerc9457fa2014-06-06 14:27:48 -07004232 win.hideLw(false);
4233 }
Dianne Hackborn5f3063e2010-03-10 16:01:58 -08004234 }
Adrian Roos602c68e2015-04-24 16:03:47 -07004235 } else if (mTopFullscreenOpaqueWindowState == null && mWinShowWhenLocked == null) {
4236 // No TopFullscreenOpaqueWindow is showing, but we found a SHOW_WHEN_LOCKED window
4237 // that is being hidden in an animation - keep the
4238 // keyguard hidden until the new window shows up and
4239 // we know whether to show the keyguard or not.
4240 if (win.isAnimatingLw() && appWindow && showWhenLocked) {
4241 mHideLockScreen = true;
4242 mWinShowWhenLocked = win;
4243 }
Dianne Hackborn5f3063e2010-03-10 16:01:58 -08004244 }
Adrian Rooscd3884d2015-02-18 17:25:23 +01004245 if (mTopFullscreenOpaqueOrDimmingWindowState == null
4246 && win.isVisibleOrBehindKeyguardLw() && !win.isGoneForLayoutLw()
4247 && win.isDimming()) {
4248 mTopFullscreenOpaqueOrDimmingWindowState = win;
4249 }
Dianne Hackborn5f3063e2010-03-10 16:01:58 -08004250 }
4251
4252 /** {@inheritDoc} */
Craig Mautnerad09bcc2012-10-08 13:33:11 -07004253 @Override
Craig Mautner39834192012-09-02 07:47:24 -07004254 public int finishPostLayoutPolicyLw() {
Craig Mautnerc5e73bf2015-04-21 15:41:26 +00004255 if (mWinShowWhenLocked != null && mTopFullscreenOpaqueWindowState != null &&
4256 mWinShowWhenLocked.getAppToken() != mTopFullscreenOpaqueWindowState.getAppToken()
4257 && isKeyguardLocked()) {
Craig Mautnerc9457fa2014-06-06 14:27:48 -07004258 // A dialog is dismissing the keyguard. Put the wallpaper behind it and hide the
4259 // fullscreen window.
4260 // TODO: Make sure FLAG_SHOW_WALLPAPER is restored when dialog is dismissed. Or not.
4261 mWinShowWhenLocked.getAttrs().flags |= FLAG_SHOW_WALLPAPER;
4262 mTopFullscreenOpaqueWindowState.hideLw(false);
4263 mTopFullscreenOpaqueWindowState = mWinShowWhenLocked;
4264 }
4265
Dianne Hackborn39c2d712009-09-22 11:41:31 -07004266 int changes = 0;
Joe Onorato93056472010-09-10 10:30:46 -04004267 boolean topIsFullscreen = false;
Daniel Sandlere02d8082010-10-08 15:13:22 -04004268
4269 final WindowManager.LayoutParams lp = (mTopFullscreenOpaqueWindowState != null)
4270 ? mTopFullscreenOpaqueWindowState.getAttrs()
4271 : null;
4272
Jeff Brownc8018eb2012-10-29 21:33:27 -07004273 // If we are not currently showing a dream then remember the current
4274 // lockscreen state. We will use this to determine whether the dream
4275 // started while the lockscreen was showing and remember this state
4276 // while the dream is showing.
Dianne Hackborn7ad44382012-10-18 17:46:00 -07004277 if (!mShowingDream) {
4278 mDreamingLockscreen = mShowingLockscreen;
Jeff Brown061ea992015-04-17 19:55:47 -07004279 if (mDreamingSleepTokenNeeded) {
4280 mDreamingSleepTokenNeeded = false;
4281 mHandler.obtainMessage(MSG_UPDATE_DREAMING_SLEEP_TOKEN, 0, 1).sendToTarget();
4282 }
4283 } else {
4284 if (!mDreamingSleepTokenNeeded) {
4285 mDreamingSleepTokenNeeded = true;
4286 mHandler.obtainMessage(MSG_UPDATE_DREAMING_SLEEP_TOKEN, 1, 1).sendToTarget();
4287 }
Dianne Hackborn7ad44382012-10-18 17:46:00 -07004288 }
4289
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004290 if (mStatusBar != null) {
Craig Mautnereda67292013-04-28 13:50:14 -07004291 if (DEBUG_LAYOUT) Slog.i(TAG, "force=" + mForceStatusBar
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07004292 + " forcefkg=" + mForceStatusBarFromKeyguard
Dianne Hackbornd70bc2f2009-10-06 23:25:51 -07004293 + " top=" + mTopFullscreenOpaqueWindowState);
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07004294 if (mForceStatusBar || mForceStatusBarFromKeyguard) {
Craig Mautnereda67292013-04-28 13:50:14 -07004295 if (DEBUG_LAYOUT) Slog.v(TAG, "Showing status bar: forced");
John Spurlock27735a42013-08-14 17:57:38 -04004296 if (mStatusBarController.setBarShowingLw(true)) {
4297 changes |= FINISH_LAYOUT_REDO_LAYOUT;
4298 }
Craig Mautner81defc72013-10-29 11:10:42 -07004299 // Maintain fullscreen layout until incoming animation is complete.
4300 topIsFullscreen = mTopIsFullscreen && mStatusBar.isAnimatingLw();
John Spurlockf92b6162013-11-11 15:01:16 -05004301 // Transient status bar on the lockscreen is not allowed
4302 if (mForceStatusBarFromKeyguard && mStatusBarController.isTransientShowing()) {
4303 mStatusBarController.updateVisibilityLw(false /*transientAllowed*/,
4304 mLastSystemUiFlags, mLastSystemUiFlags);
4305 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004306 } else if (mTopFullscreenOpaqueWindowState != null) {
John Spurlockc6d1c602014-01-17 15:22:06 -05004307 final int fl = PolicyControl.getWindowFlags(null, lp);
Joe Onorato93056472010-09-10 10:30:46 -04004308 if (localLOGV) {
Craig Mautnereda67292013-04-28 13:50:14 -07004309 Slog.d(TAG, "frame: " + mTopFullscreenOpaqueWindowState.getFrameLw()
Joe Onorato93056472010-09-10 10:30:46 -04004310 + " shown frame: " + mTopFullscreenOpaqueWindowState.getShownFrameLw());
Craig Mautnereda67292013-04-28 13:50:14 -07004311 Slog.d(TAG, "attr: " + mTopFullscreenOpaqueWindowState.getAttrs()
John Spurlockc6d1c602014-01-17 15:22:06 -05004312 + " lp.flags=0x" + Integer.toHexString(fl));
Joe Onorato93056472010-09-10 10:30:46 -04004313 }
John Spurlockc6d1c602014-01-17 15:22:06 -05004314 topIsFullscreen = (fl & WindowManager.LayoutParams.FLAG_FULLSCREEN) != 0
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07004315 || (mLastSystemUiFlags & View.SYSTEM_UI_FLAG_FULLSCREEN) != 0;
Joe Onorato93056472010-09-10 10:30:46 -04004316 // The subtle difference between the window for mTopFullscreenOpaqueWindowState
Mark Dolinerd0646dc2014-08-27 16:04:02 -07004317 // and mTopIsFullscreen is that mTopIsFullscreen is set only if the window
Joe Onorato93056472010-09-10 10:30:46 -04004318 // has the FLAG_FULLSCREEN set. Not sure if there is another way that to be the
4319 // case though.
John Spurlock27735a42013-08-14 17:57:38 -04004320 if (mStatusBarController.isTransientShowing()) {
4321 if (mStatusBarController.setBarShowingLw(true)) {
John Spurlock32beb2c2013-03-11 10:16:47 -04004322 changes |= FINISH_LAYOUT_REDO_LAYOUT;
4323 }
4324 } else if (topIsFullscreen) {
Craig Mautnereda67292013-04-28 13:50:14 -07004325 if (DEBUG_LAYOUT) Slog.v(TAG, "** HIDING status bar");
John Spurlock27735a42013-08-14 17:57:38 -04004326 if (mStatusBarController.setBarShowingLw(false)) {
Dianne Hackbornf87d1962012-04-04 12:48:24 -07004327 changes |= FINISH_LAYOUT_REDO_LAYOUT;
Craig Mautnereda67292013-04-28 13:50:14 -07004328 } else {
Craig Mautnerc5a6e442013-06-05 17:22:35 -07004329 if (DEBUG_LAYOUT) Slog.v(TAG, "Status bar already hiding");
Daniel Sandler40427442010-07-16 11:44:52 -04004330 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004331 } else {
Craig Mautnereda67292013-04-28 13:50:14 -07004332 if (DEBUG_LAYOUT) Slog.v(TAG, "** SHOWING status bar: top is not fullscreen");
John Spurlock27735a42013-08-14 17:57:38 -04004333 if (mStatusBarController.setBarShowingLw(true)) {
4334 changes |= FINISH_LAYOUT_REDO_LAYOUT;
4335 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004336 }
4337 }
4338 }
Daniel Sandlere02d8082010-10-08 15:13:22 -04004339
Craig Mautner81defc72013-10-29 11:10:42 -07004340 if (mTopIsFullscreen != topIsFullscreen) {
4341 if (!topIsFullscreen) {
4342 // Force another layout when status bar becomes fully shown.
4343 changes |= FINISH_LAYOUT_REDO_LAYOUT;
4344 }
4345 mTopIsFullscreen = topIsFullscreen;
4346 }
Daniel Sandlere02d8082010-10-08 15:13:22 -04004347
Craig Mautner39834192012-09-02 07:47:24 -07004348 // Hide the key guard if a visible window explicitly specifies that it wants to be
4349 // displayed when the screen is locked.
Jorim Jaggi5cf17872014-03-26 18:31:48 +01004350 if (mKeyguardDelegate != null && mStatusBar != null) {
4351 if (localLOGV) Slog.v(TAG, "finishPostLayoutPolicyLw: mHideKeyguard="
4352 + mHideLockScreen);
Jim Millerab954542014-10-10 18:21:49 -07004353 if (mDismissKeyguard != DISMISS_KEYGUARD_NONE && !mKeyguardSecure) {
Jorim Jaggi5cf17872014-03-26 18:31:48 +01004354 mKeyguardHidden = true;
Jim Millerab954542014-10-10 18:21:49 -07004355 if (setKeyguardOccludedLw(true)) {
Dianne Hackborn39c2d712009-09-22 11:41:31 -07004356 changes |= FINISH_LAYOUT_REDO_LAYOUT
4357 | FINISH_LAYOUT_REDO_CONFIG
4358 | FINISH_LAYOUT_REDO_WALLPAPER;
4359 }
Jorim Jaggi5cf17872014-03-26 18:31:48 +01004360 if (mKeyguardDelegate.isShowing()) {
4361 mHandler.post(new Runnable() {
4362 @Override
4363 public void run() {
4364 mKeyguardDelegate.keyguardDone(false, false);
4365 }
4366 });
4367 }
4368 } else if (mHideLockScreen) {
4369 mKeyguardHidden = true;
Jim Millerab954542014-10-10 18:21:49 -07004370 if (setKeyguardOccludedLw(true)) {
Jorim Jaggi5cf17872014-03-26 18:31:48 +01004371 changes |= FINISH_LAYOUT_REDO_LAYOUT
4372 | FINISH_LAYOUT_REDO_CONFIG
4373 | FINISH_LAYOUT_REDO_WALLPAPER;
4374 }
4375 } else if (mDismissKeyguard != DISMISS_KEYGUARD_NONE) {
4376 // This is the case of keyguard isSecure() and not mHideLockScreen.
4377 if (mDismissKeyguard == DISMISS_KEYGUARD_START) {
4378 // Only launch the next keyguard unlock window once per window.
4379 mKeyguardHidden = false;
Jim Millerab954542014-10-10 18:21:49 -07004380 if (setKeyguardOccludedLw(false)) {
Jorim Jaggi5cf17872014-03-26 18:31:48 +01004381 changes |= FINISH_LAYOUT_REDO_LAYOUT
4382 | FINISH_LAYOUT_REDO_CONFIG
4383 | FINISH_LAYOUT_REDO_WALLPAPER;
Jorim Jaggi380ecb82014-03-14 17:25:20 +01004384 }
Jorim Jaggi5cf17872014-03-26 18:31:48 +01004385 mHandler.post(new Runnable() {
4386 @Override
4387 public void run() {
4388 mKeyguardDelegate.dismiss();
4389 }
4390 });
4391 }
4392 } else {
4393 mWinDismissingKeyguard = null;
4394 mKeyguardHidden = false;
Jim Millerab954542014-10-10 18:21:49 -07004395 if (setKeyguardOccludedLw(false)) {
Jorim Jaggi5cf17872014-03-26 18:31:48 +01004396 changes |= FINISH_LAYOUT_REDO_LAYOUT
4397 | FINISH_LAYOUT_REDO_CONFIG
4398 | FINISH_LAYOUT_REDO_WALLPAPER;
4399 }
Suchi Amalapurapu9cdc9032009-05-14 18:01:07 -07004400 }
4401 }
Joe Onorato664644d2011-01-23 17:53:23 -08004402
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07004403 if ((updateSystemUiVisibilityLw()&SYSTEM_UI_CHANGING_LAYOUT) != 0) {
Dianne Hackborndf89e652011-10-06 22:35:11 -07004404 // If the navigation bar has been hidden or shown, we need to do another
4405 // layout pass to update that window.
4406 changes |= FINISH_LAYOUT_REDO_LAYOUT;
4407 }
Joe Onorato664644d2011-01-23 17:53:23 -08004408
Mike Lockwood28569302010-01-28 11:54:40 -05004409 // update since mAllowLockscreenWhenOn might have changed
4410 updateLockScreenTimeout();
Dianne Hackborn39c2d712009-09-22 11:41:31 -07004411 return changes;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004412 }
4413
Jorim Jaggi380ecb82014-03-14 17:25:20 +01004414 /**
Jim Millerab954542014-10-10 18:21:49 -07004415 * Updates the occluded state of the Keyguard.
Jorim Jaggi380ecb82014-03-14 17:25:20 +01004416 *
Jorim Jaggi380ecb82014-03-14 17:25:20 +01004417 * @return Whether the flags have changed and we have to redo the layout.
4418 */
Jim Millerab954542014-10-10 18:21:49 -07004419 private boolean setKeyguardOccludedLw(boolean isOccluded) {
4420 boolean wasOccluded = mKeyguardOccluded;
4421 boolean showing = mKeyguardDelegate.isShowing();
4422 if (wasOccluded && !isOccluded && showing) {
4423 mKeyguardOccluded = false;
4424 mKeyguardDelegate.setOccluded(false);
Jorim Jaggi380ecb82014-03-14 17:25:20 +01004425 mStatusBar.getAttrs().privateFlags |= PRIVATE_FLAG_KEYGUARD;
4426 mStatusBar.getAttrs().flags |= FLAG_SHOW_WALLPAPER;
4427 return true;
Jim Millerab954542014-10-10 18:21:49 -07004428 } else if (!wasOccluded && isOccluded && showing) {
4429 mKeyguardOccluded = true;
4430 mKeyguardDelegate.setOccluded(true);
Jorim Jaggi380ecb82014-03-14 17:25:20 +01004431 mStatusBar.getAttrs().privateFlags &= ~PRIVATE_FLAG_KEYGUARD;
4432 mStatusBar.getAttrs().flags &= ~FLAG_SHOW_WALLPAPER;
4433 return true;
4434 } else {
4435 return false;
4436 }
4437 }
4438
4439 private boolean isStatusBarKeyguard() {
4440 return mStatusBar != null
4441 && (mStatusBar.getAttrs().privateFlags & PRIVATE_FLAG_KEYGUARD) != 0;
4442 }
4443
Jose Lima9546b202014-07-02 17:21:51 -07004444 @Override
Dianne Hackborn08743722009-12-21 12:16:51 -08004445 public boolean allowAppAnimationsLw() {
Jorim Jaggi380ecb82014-03-14 17:25:20 +01004446 if (isStatusBarKeyguard() || mShowingDream) {
Craig Mautner28816302013-10-10 20:31:00 -07004447 // If keyguard or dreams is currently visible, no reason to animate behind it.
Dianne Hackborn08743722009-12-21 12:16:51 -08004448 return false;
4449 }
Dianne Hackborn08743722009-12-21 12:16:51 -08004450 return true;
4451 }
4452
Jose Lima9546b202014-07-02 17:21:51 -07004453 @Override
Dianne Hackborndf89e652011-10-06 22:35:11 -07004454 public int focusChangedLw(WindowState lastFocus, WindowState newFocus) {
Joe Onorato664644d2011-01-23 17:53:23 -08004455 mFocusedWindow = newFocus;
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07004456 if ((updateSystemUiVisibilityLw()&SYSTEM_UI_CHANGING_LAYOUT) != 0) {
Dianne Hackborndf89e652011-10-06 22:35:11 -07004457 // If the navigation bar has been hidden or shown, we need to do another
4458 // layout pass to update that window.
4459 return FINISH_LAYOUT_REDO_LAYOUT;
4460 }
4461 return 0;
Joe Onorato664644d2011-01-23 17:53:23 -08004462 }
4463
Dianne Hackborn0ecadf72009-03-31 18:00:37 -07004464 /** {@inheritDoc} */
Jose Lima9546b202014-07-02 17:21:51 -07004465 @Override
Jeff Brown46b9ac02010-04-22 18:58:52 -07004466 public void notifyLidSwitchChanged(long whenNanos, boolean lidOpen) {
4467 // lid changed state
Jeff Brownc458ce92012-04-30 14:58:40 -07004468 final int newLidState = lidOpen ? LID_OPEN : LID_CLOSED;
4469 if (newLidState == mLidState) {
4470 return;
4471 }
Jeff Brown01a98dd2011-09-20 15:08:29 -07004472
Jeff Brownc458ce92012-04-30 14:58:40 -07004473 mLidState = newLidState;
4474 applyLidSwitchState();
Jeff Brown01a98dd2011-09-20 15:08:29 -07004475 updateRotation(true);
Jeff Brownc458ce92012-04-30 14:58:40 -07004476
4477 if (lidOpen) {
Bryce Lee584a4452014-10-21 15:55:55 -07004478 wakeUp(SystemClock.uptimeMillis(), mAllowTheaterModeWakeFromLidSwitch);
Jeff Brownc458ce92012-04-30 14:58:40 -07004479 } else if (!mLidControlsSleep) {
Jeff Brown96307042012-07-27 15:51:34 -07004480 mPowerManager.userActivity(SystemClock.uptimeMillis(), false);
Jeff Brown46b9ac02010-04-22 18:58:52 -07004481 }
4482 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004483
Michael Wright3818c922014-09-02 13:59:07 -07004484 @Override
4485 public void notifyCameraLensCoverSwitchChanged(long whenNanos, boolean lensCovered) {
4486 int lensCoverState = lensCovered ? CAMERA_LENS_COVERED : CAMERA_LENS_UNCOVERED;
4487 if (mCameraLensCoverState == lensCoverState) {
4488 return;
4489 }
4490 if (mCameraLensCoverState == CAMERA_LENS_COVERED &&
4491 lensCoverState == CAMERA_LENS_UNCOVERED) {
4492 Intent intent;
4493 final boolean keyguardActive = mKeyguardDelegate == null ? false :
4494 mKeyguardDelegate.isShowing();
4495 if (keyguardActive) {
4496 intent = new Intent(MediaStore.INTENT_ACTION_STILL_IMAGE_CAMERA_SECURE);
4497 } else {
4498 intent = new Intent(MediaStore.INTENT_ACTION_STILL_IMAGE_CAMERA);
4499 }
Bryce Lee584a4452014-10-21 15:55:55 -07004500 wakeUp(whenNanos / 1000000, mAllowTheaterModeWakeFromCameraLens);
Bart Sears8b1c27c2015-03-18 23:51:02 +00004501 startActivityAsUser(intent, UserHandle.CURRENT_OR_SELF);
Michael Wright3818c922014-09-02 13:59:07 -07004502 }
4503 mCameraLensCoverState = lensCoverState;
4504 }
4505
Dianne Hackbornad7fa7f2011-01-07 14:06:50 -08004506 void setHdmiPlugged(boolean plugged) {
4507 if (mHdmiPlugged != plugged) {
4508 mHdmiPlugged = plugged;
Dianne Hackbornf87d1962012-04-04 12:48:24 -07004509 updateRotation(true, true);
Dianne Hackbornad7fa7f2011-01-07 14:06:50 -08004510 Intent intent = new Intent(ACTION_HDMI_PLUGGED);
Joe Onoratodc100302011-01-11 17:07:41 -08004511 intent.addFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY_BEFORE_BOOT);
Dianne Hackbornad7fa7f2011-01-07 14:06:50 -08004512 intent.putExtra(EXTRA_HDMI_PLUGGED_STATE, plugged);
Dianne Hackborn5ac72a22012-08-29 18:32:08 -07004513 mContext.sendStickyBroadcastAsUser(intent, UserHandle.ALL);
Dianne Hackbornad7fa7f2011-01-07 14:06:50 -08004514 }
4515 }
4516
Joe Onoratoea495d42011-04-06 11:41:11 -07004517 void initializeHdmiState() {
Joe Onorato7ba631f2011-05-04 15:28:00 -07004518 boolean plugged = false;
Joe Onoratoea495d42011-04-06 11:41:11 -07004519 // watch for HDMI plug messages if the hdmi switch exists
4520 if (new File("/sys/devices/virtual/switch/hdmi/state").exists()) {
4521 mHDMIObserver.startObserving("DEVPATH=/devices/virtual/switch/hdmi");
4522
Joe Onoratoea495d42011-04-06 11:41:11 -07004523 final String filename = "/sys/class/switch/hdmi/state";
4524 FileReader reader = null;
4525 try {
4526 reader = new FileReader(filename);
4527 char[] buf = new char[15];
4528 int n = reader.read(buf);
4529 if (n > 1) {
4530 plugged = 0 != Integer.parseInt(new String(buf, 0, n-1));
4531 }
4532 } catch (IOException ex) {
4533 Slog.w(TAG, "Couldn't read hdmi state from " + filename + ": " + ex);
4534 } catch (NumberFormatException ex) {
4535 Slog.w(TAG, "Couldn't read hdmi state from " + filename + ": " + ex);
4536 } finally {
4537 if (reader != null) {
4538 try {
4539 reader.close();
4540 } catch (IOException ex) {
4541 }
Joe Onoratodc100302011-01-11 17:07:41 -08004542 }
4543 }
4544 }
Joe Onorato7ba631f2011-05-04 15:28:00 -07004545 // This dance forces the code in setHdmiPlugged to run.
4546 // Always do this so the sticky intent is stuck (to false) if there is no hdmi.
4547 mHdmiPlugged = !plugged;
4548 setHdmiPlugged(!mHdmiPlugged);
Joe Onoratodc100302011-01-11 17:07:41 -08004549 }
4550
Dianne Hackbornc0e3f242011-08-19 14:19:10 -07004551 final Object mScreenshotLock = new Object();
Dianne Hackbornfc8fa632011-08-17 16:20:47 -07004552 ServiceConnection mScreenshotConnection = null;
Dianne Hackbornfc8fa632011-08-17 16:20:47 -07004553
Jeff Brownd5bb82d2011-10-12 13:57:59 -07004554 final Runnable mScreenshotTimeout = new Runnable() {
4555 @Override public void run() {
4556 synchronized (mScreenshotLock) {
4557 if (mScreenshotConnection != null) {
4558 mContext.unbindService(mScreenshotConnection);
4559 mScreenshotConnection = null;
Dianne Hackbornfc8fa632011-08-17 16:20:47 -07004560 }
Winson Chung9112ec32011-06-27 13:15:32 -07004561 }
Jeff Brownd5bb82d2011-10-12 13:57:59 -07004562 }
4563 };
4564
4565 // Assume this is called from the Handler thread.
4566 private void takeScreenshot() {
4567 synchronized (mScreenshotLock) {
4568 if (mScreenshotConnection != null) {
4569 return;
4570 }
4571 ComponentName cn = new ComponentName("com.android.systemui",
4572 "com.android.systemui.screenshot.TakeScreenshotService");
4573 Intent intent = new Intent();
4574 intent.setComponent(cn);
4575 ServiceConnection conn = new ServiceConnection() {
4576 @Override
4577 public void onServiceConnected(ComponentName name, IBinder service) {
4578 synchronized (mScreenshotLock) {
4579 if (mScreenshotConnection != this) {
4580 return;
4581 }
4582 Messenger messenger = new Messenger(service);
4583 Message msg = Message.obtain(null, 1);
4584 final ServiceConnection myConn = this;
4585 Handler h = new Handler(mHandler.getLooper()) {
4586 @Override
4587 public void handleMessage(Message msg) {
4588 synchronized (mScreenshotLock) {
4589 if (mScreenshotConnection == myConn) {
4590 mContext.unbindService(mScreenshotConnection);
4591 mScreenshotConnection = null;
4592 mHandler.removeCallbacks(mScreenshotTimeout);
4593 }
4594 }
4595 }
4596 };
4597 msg.replyTo = new Messenger(h);
Winson Chunga63bb842011-10-17 10:26:28 -07004598 msg.arg1 = msg.arg2 = 0;
4599 if (mStatusBar != null && mStatusBar.isVisibleLw())
4600 msg.arg1 = 1;
4601 if (mNavigationBar != null && mNavigationBar.isVisibleLw())
4602 msg.arg2 = 1;
Jeff Brownd5bb82d2011-10-12 13:57:59 -07004603 try {
4604 messenger.send(msg);
4605 } catch (RemoteException e) {
4606 }
4607 }
4608 }
4609 @Override
4610 public void onServiceDisconnected(ComponentName name) {}
4611 };
Amith Yamasani27b89e62013-01-16 12:30:11 -08004612 if (mContext.bindServiceAsUser(
4613 intent, conn, Context.BIND_AUTO_CREATE, UserHandle.CURRENT)) {
Jeff Brownd5bb82d2011-10-12 13:57:59 -07004614 mScreenshotConnection = conn;
4615 mHandler.postDelayed(mScreenshotTimeout, 10000);
4616 }
4617 }
Winson Chung9112ec32011-06-27 13:15:32 -07004618 }
4619
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004620 /** {@inheritDoc} */
Jeff Brown00fa7bd2010-07-02 15:37:36 -07004621 @Override
Jeff Brown037c33e2014-04-09 00:31:55 -07004622 public int interceptKeyBeforeQueueing(KeyEvent event, int policyFlags) {
Jeff Brown96307042012-07-27 15:51:34 -07004623 if (!mSystemBooted) {
4624 // If we have not yet booted, don't let key events do anything.
4625 return 0;
4626 }
4627
Jeff Brown037c33e2014-04-09 00:31:55 -07004628 final boolean interactive = (policyFlags & FLAG_INTERACTIVE) != 0;
Jeff Brown1f245102010-11-18 20:53:46 -08004629 final boolean down = event.getAction() == KeyEvent.ACTION_DOWN;
4630 final boolean canceled = event.isCanceled();
4631 final int keyCode = event.getKeyCode();
Jeff Browne20c9e02010-10-11 14:20:19 -07004632
Jeff Brown3122e442010-10-11 23:32:49 -07004633 final boolean isInjected = (policyFlags & WindowManagerPolicy.FLAG_INJECTED) != 0;
Jeff Brown3122e442010-10-11 23:32:49 -07004634
Mike Lockwoodc72b15f2009-11-28 20:58:22 -05004635 // If screen is off then we treat the case where the keyguard is open but hidden
4636 // the same as if it were open and in front.
4637 // This will prevent any keys other than the power button from waking the screen
4638 // when the keyguard is hidden by another activity.
Jim Miller5ecd8112013-01-09 18:50:26 -08004639 final boolean keyguardActive = (mKeyguardDelegate == null ? false :
Jeff Brown037c33e2014-04-09 00:31:55 -07004640 (interactive ?
Jim Millerab954542014-10-10 18:21:49 -07004641 isKeyguardShowingAndNotOccluded() :
Jim Miller5ecd8112013-01-09 18:50:26 -08004642 mKeyguardDelegate.isShowing()));
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004643
Jeff Brown40013652012-05-16 21:22:36 -07004644 if (DEBUG_INPUT) {
Jeff Brown00fa7bd2010-07-02 15:37:36 -07004645 Log.d(TAG, "interceptKeyTq keycode=" + keyCode
Jeff Brown037c33e2014-04-09 00:31:55 -07004646 + " interactive=" + interactive + " keyguardActive=" + keyguardActive
Jeff Brown26875502014-01-30 21:47:47 -08004647 + " policyFlags=" + Integer.toHexString(policyFlags));
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004648 }
4649
Jeff Brown037c33e2014-04-09 00:31:55 -07004650 // Basic policy based on interactive state.
Jeff Brown4d396052010-10-29 21:50:21 -07004651 int result;
Michael Wright337d9d22014-04-22 15:03:48 -07004652 boolean isWakeKey = (policyFlags & WindowManagerPolicy.FLAG_WAKE) != 0
4653 || event.isWakeKey();
Michael Wrightfc01f042014-09-08 14:12:24 -07004654 if (interactive || (isInjected && !isWakeKey)) {
RoboErikde9ba392014-09-26 12:51:01 -07004655 // When the device is interactive or the key is injected pass the
4656 // key to the application.
Jeff Brown4d396052010-10-29 21:50:21 -07004657 result = ACTION_PASS_TO_USER;
Jose Lima9546b202014-07-02 17:21:51 -07004658 isWakeKey = false;
Michael Wrightfc01f042014-09-08 14:12:24 -07004659 } else if (!interactive && shouldDispatchInputWhenNonInteractive()) {
4660 // If we're currently dozing with the screen on and the keyguard showing, pass the key
4661 // to the application but preserve its wake key status to make sure we still move
4662 // from dozing to fully interactive if we would normally go from off to fully
4663 // interactive.
4664 result = ACTION_PASS_TO_USER;
Jeff Brown4d396052010-10-29 21:50:21 -07004665 } else {
4666 // When the screen is off and the key is not injected, determine whether
4667 // to wake the device but don't pass the key to the application.
4668 result = 0;
Jeff Brown26875502014-01-30 21:47:47 -08004669 if (isWakeKey && (!down || !isWakeKeyWhenScreenOff(keyCode))) {
4670 isWakeKey = false;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004671 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004672 }
4673
Justin Kohd378ad72013-04-01 12:18:26 -07004674 // If the key would be handled globally, just return the result, don't worry about special
4675 // key processing.
Jeff Brown13f00f02014-10-31 14:45:50 -07004676 if (isValidGlobalKey(keyCode)
4677 && mGlobalKeyManager.shouldHandleGlobalKey(keyCode, event)) {
Michael Wright85b1af62014-06-04 14:51:58 -07004678 if (isWakeKey) {
Jeff Brown13f00f02014-10-31 14:45:50 -07004679 wakeUp(event.getEventTime(), mAllowTheaterModeWakeFromKey);
Michael Wright85b1af62014-06-04 14:51:58 -07004680 }
Justin Kohd378ad72013-04-01 12:18:26 -07004681 return result;
4682 }
4683
Jeff Brownbae8e772014-06-12 19:59:45 -07004684 boolean useHapticFeedback = down
4685 && (policyFlags & WindowManagerPolicy.FLAG_VIRTUAL) != 0
4686 && event.getRepeatCount() == 0;
4687
Jeff Brown4d396052010-10-29 21:50:21 -07004688 // Handle special keys.
4689 switch (keyCode) {
4690 case KeyEvent.KEYCODE_VOLUME_DOWN:
Jeff Brownb0418da2010-11-01 15:24:01 -07004691 case KeyEvent.KEYCODE_VOLUME_UP:
4692 case KeyEvent.KEYCODE_VOLUME_MUTE: {
RoboErik001c59c2015-01-26 15:53:51 -08004693 if (mUseTvRouting) {
4694 // On TVs volume keys never go to the foreground app
4695 result &= ~ACTION_PASS_TO_USER;
4696 }
Jeff Brownd5bb82d2011-10-12 13:57:59 -07004697 if (keyCode == KeyEvent.KEYCODE_VOLUME_DOWN) {
4698 if (down) {
Jeff Brown13f00f02014-10-31 14:45:50 -07004699 if (interactive && !mScreenshotChordVolumeDownKeyTriggered
Jeff Brownd5bb82d2011-10-12 13:57:59 -07004700 && (event.getFlags() & KeyEvent.FLAG_FALLBACK) == 0) {
Jeff Brown13f00f02014-10-31 14:45:50 -07004701 mScreenshotChordVolumeDownKeyTriggered = true;
4702 mScreenshotChordVolumeDownKeyTime = event.getDownTime();
4703 mScreenshotChordVolumeDownKeyConsumed = false;
Jeff Brownd5bb82d2011-10-12 13:57:59 -07004704 cancelPendingPowerKeyAction();
4705 interceptScreenshotChord();
4706 }
4707 } else {
Jeff Brown13f00f02014-10-31 14:45:50 -07004708 mScreenshotChordVolumeDownKeyTriggered = false;
Jeff Brownd5bb82d2011-10-12 13:57:59 -07004709 cancelPendingScreenshotChordAction();
4710 }
4711 } else if (keyCode == KeyEvent.KEYCODE_VOLUME_UP) {
4712 if (down) {
Jeff Brown13f00f02014-10-31 14:45:50 -07004713 if (interactive && !mScreenshotChordVolumeUpKeyTriggered
Jeff Brownd5bb82d2011-10-12 13:57:59 -07004714 && (event.getFlags() & KeyEvent.FLAG_FALLBACK) == 0) {
Jeff Brown13f00f02014-10-31 14:45:50 -07004715 mScreenshotChordVolumeUpKeyTriggered = true;
Jeff Brownd5bb82d2011-10-12 13:57:59 -07004716 cancelPendingPowerKeyAction();
4717 cancelPendingScreenshotChordAction();
4718 }
4719 } else {
Jeff Brown13f00f02014-10-31 14:45:50 -07004720 mScreenshotChordVolumeUpKeyTriggered = false;
Jeff Brownd5bb82d2011-10-12 13:57:59 -07004721 cancelPendingScreenshotChordAction();
4722 }
4723 }
Jeff Brown4d396052010-10-29 21:50:21 -07004724 if (down) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -07004725 TelecomManager telecomManager = getTelecommService();
4726 if (telecomManager != null) {
4727 if (telecomManager.isRinging()) {
Santos Cordon6848f722014-05-21 15:22:12 -07004728 // If an incoming call is ringing, either VOLUME key means
4729 // "silence ringer". We handle these keys here, rather than
4730 // in the InCallScreen, to make sure we'll respond to them
4731 // even if the InCallScreen hasn't come to the foreground yet.
4732 // Look for the DOWN event here, to agree with the "fallback"
4733 // behavior in the InCallScreen.
4734 Log.i(TAG, "interceptKeyBeforeQueueing:"
4735 + " VOLUME key-down while ringing: Silence ringer!");
Jeff Brown4d396052010-10-29 21:50:21 -07004736
Santos Cordon6848f722014-05-21 15:22:12 -07004737 // Silence the ringer. (It's safe to call this
4738 // even if the ringer has already been silenced.)
Tyler Gunnef9f6f92014-09-12 22:16:17 -07004739 telecomManager.silenceRinger();
Jeff Brown4d396052010-10-29 21:50:21 -07004740
Santos Cordon6848f722014-05-21 15:22:12 -07004741 // And *don't* pass this key thru to the current activity
4742 // (which is probably the InCallScreen.)
4743 result &= ~ACTION_PASS_TO_USER;
4744 break;
4745 }
Tyler Gunnef9f6f92014-09-12 22:16:17 -07004746 if (telecomManager.isInCall()
Santos Cordon6848f722014-05-21 15:22:12 -07004747 && (result & ACTION_PASS_TO_USER) == 0) {
4748 // If we are in call but we decided not to pass the key to
RoboErik430fc482014-06-12 15:49:20 -07004749 // the application, just pass it to the session service.
4750
4751 MediaSessionLegacyHelper.getHelper(mContext)
RoboErik3c45c292014-07-08 16:47:31 -07004752 .sendVolumeKeyEvent(event, false);
Santos Cordon6848f722014-05-21 15:22:12 -07004753 break;
Jeff Brown4d396052010-10-29 21:50:21 -07004754 }
4755 }
4756
RoboErik430fc482014-06-12 15:49:20 -07004757 if ((result & ACTION_PASS_TO_USER) == 0) {
RoboErik001c59c2015-01-26 15:53:51 -08004758 if (mUseTvRouting) {
4759 dispatchDirectAudioEvent(event);
4760 } else {
4761 // If we aren't passing to the user and no one else
4762 // handled it send it to the session manager to
4763 // figure out.
4764 MediaSessionLegacyHelper.getHelper(mContext)
4765 .sendVolumeKeyEvent(event, true);
4766 }
Jeff Brown4d396052010-10-29 21:50:21 -07004767 break;
4768 }
4769 }
4770 break;
4771 }
4772
4773 case KeyEvent.KEYCODE_ENDCALL: {
4774 result &= ~ACTION_PASS_TO_USER;
4775 if (down) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -07004776 TelecomManager telecomManager = getTelecommService();
Jeff Brown4d396052010-10-29 21:50:21 -07004777 boolean hungUp = false;
Tyler Gunnef9f6f92014-09-12 22:16:17 -07004778 if (telecomManager != null) {
4779 hungUp = telecomManager.endCall();
Jeff Brown4d396052010-10-29 21:50:21 -07004780 }
Jeff Brown13f00f02014-10-31 14:45:50 -07004781 if (interactive && !hungUp) {
4782 mEndCallKeyHandled = false;
4783 mHandler.postDelayed(mEndCallLongPress,
4784 ViewConfiguration.get(mContext).getDeviceGlobalActionKeyTimeout());
4785 } else {
4786 mEndCallKeyHandled = true;
4787 }
Jeff Brown4d396052010-10-29 21:50:21 -07004788 } else {
Jeff Brown13f00f02014-10-31 14:45:50 -07004789 if (!mEndCallKeyHandled) {
4790 mHandler.removeCallbacks(mEndCallLongPress);
4791 if (!canceled) {
4792 if ((mEndcallBehavior
4793 & Settings.System.END_BUTTON_BEHAVIOR_HOME) != 0) {
4794 if (goHome()) {
4795 break;
4796 }
Dianne Hackborn0041e972009-07-24 17:14:43 -07004797 }
Jeff Brown13f00f02014-10-31 14:45:50 -07004798 if ((mEndcallBehavior
4799 & Settings.System.END_BUTTON_BEHAVIOR_SLEEP) != 0) {
4800 mPowerManager.goToSleep(event.getEventTime(),
4801 PowerManager.GO_TO_SLEEP_REASON_POWER_BUTTON, 0);
4802 isWakeKey = false;
4803 }
Jeff Brown4d396052010-10-29 21:50:21 -07004804 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004805 }
Jeff Brown4d396052010-10-29 21:50:21 -07004806 }
4807 break;
4808 }
4809
4810 case KeyEvent.KEYCODE_POWER: {
4811 result &= ~ACTION_PASS_TO_USER;
Jeff Brown13f00f02014-10-31 14:45:50 -07004812 isWakeKey = false; // wake-up will be handled separately
Jeff Brown4d396052010-10-29 21:50:21 -07004813 if (down) {
Jeff Brown13f00f02014-10-31 14:45:50 -07004814 interceptPowerKeyDown(event, interactive);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004815 } else {
Jeff Brown13f00f02014-10-31 14:45:50 -07004816 interceptPowerKeyUp(event, interactive, canceled);
Jeff Brown4d396052010-10-29 21:50:21 -07004817 }
4818 break;
4819 }
4820
Jeff Brown6212a492014-03-07 13:58:47 -08004821 case KeyEvent.KEYCODE_SLEEP: {
4822 result &= ~ACTION_PASS_TO_USER;
Filip Gruszczynskia483a1d2015-03-17 19:06:58 +00004823 isWakeKey = false;
Jeff Brownbae8e772014-06-12 19:59:45 -07004824 if (!mPowerManager.isInteractive()) {
4825 useHapticFeedback = false; // suppress feedback if already non-interactive
4826 }
Filip Gruszczynskia483a1d2015-03-17 19:06:58 +00004827 sleepPress(event);
Jeff Brown6212a492014-03-07 13:58:47 -08004828 break;
4829 }
4830
4831 case KeyEvent.KEYCODE_WAKEUP: {
4832 result &= ~ACTION_PASS_TO_USER;
Jose Lima9546b202014-07-02 17:21:51 -07004833 isWakeKey = true;
Jeff Brown6212a492014-03-07 13:58:47 -08004834 break;
4835 }
4836
Jeff Brown4d396052010-10-29 21:50:21 -07004837 case KeyEvent.KEYCODE_MEDIA_PLAY:
4838 case KeyEvent.KEYCODE_MEDIA_PAUSE:
4839 case KeyEvent.KEYCODE_MEDIA_PLAY_PAUSE:
Jeff Brown4d396052010-10-29 21:50:21 -07004840 case KeyEvent.KEYCODE_HEADSETHOOK:
4841 case KeyEvent.KEYCODE_MUTE:
4842 case KeyEvent.KEYCODE_MEDIA_STOP:
4843 case KeyEvent.KEYCODE_MEDIA_NEXT:
4844 case KeyEvent.KEYCODE_MEDIA_PREVIOUS:
4845 case KeyEvent.KEYCODE_MEDIA_REWIND:
4846 case KeyEvent.KEYCODE_MEDIA_RECORD:
Jaekyun Seokbfdad8e2013-07-08 13:53:21 +09004847 case KeyEvent.KEYCODE_MEDIA_FAST_FORWARD:
4848 case KeyEvent.KEYCODE_MEDIA_AUDIO_TRACK: {
RoboErikde9ba392014-09-26 12:51:01 -07004849 if (MediaSessionLegacyHelper.getHelper(mContext).isGlobalPriorityActive()) {
4850 // If the global session is active pass all media keys to it
4851 // instead of the active window.
4852 result &= ~ACTION_PASS_TO_USER;
4853 }
Jeff Brown4d396052010-10-29 21:50:21 -07004854 if ((result & ACTION_PASS_TO_USER) == 0) {
4855 // Only do this if we would otherwise not pass it to the user. In that
4856 // case, the PhoneWindow class will do the same thing, except it will
4857 // only do it if the showing app doesn't process the key on its own.
Jeff Brown40013652012-05-16 21:22:36 -07004858 // Note that we need to make a copy of the key event here because the
4859 // original key event will be recycled when we return.
Jeff Brown4d396052010-10-29 21:50:21 -07004860 mBroadcastWakeLock.acquire();
Jeff Brown40013652012-05-16 21:22:36 -07004861 Message msg = mHandler.obtainMessage(MSG_DISPATCH_MEDIA_KEY_WITH_WAKE_LOCK,
4862 new KeyEvent(event));
4863 msg.setAsynchronous(true);
4864 msg.sendToTarget();
Jeff Brown4d396052010-10-29 21:50:21 -07004865 }
4866 break;
Jeff Brown00fa7bd2010-07-02 15:37:36 -07004867 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004868
Jeff Brown4d396052010-10-29 21:50:21 -07004869 case KeyEvent.KEYCODE_CALL: {
4870 if (down) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -07004871 TelecomManager telecomManager = getTelecommService();
4872 if (telecomManager != null) {
4873 if (telecomManager.isRinging()) {
Santos Cordon6848f722014-05-21 15:22:12 -07004874 Log.i(TAG, "interceptKeyBeforeQueueing:"
4875 + " CALL key-down while ringing: Answer the call!");
Tyler Gunnef9f6f92014-09-12 22:16:17 -07004876 telecomManager.acceptRingingCall();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004877
Santos Cordon6848f722014-05-21 15:22:12 -07004878 // And *don't* pass this key thru to the current activity
4879 // (which is presumably the InCallScreen.)
4880 result &= ~ACTION_PASS_TO_USER;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004881 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004882 }
Jeff Brown00fa7bd2010-07-02 15:37:36 -07004883 }
Jeff Brown4d396052010-10-29 21:50:21 -07004884 break;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004885 }
Michael Wright869a67c2014-08-26 19:33:06 -07004886 case KeyEvent.KEYCODE_VOICE_ASSIST: {
4887 // Only do this if we would otherwise not pass it to the user. In that case,
4888 // interceptKeyBeforeDispatching would apply a similar but different policy in
4889 // order to invoke voice assist actions. Note that we need to make a copy of the
4890 // key event here because the original key event will be recycled when we return.
4891 if ((result & ACTION_PASS_TO_USER) == 0 && !down) {
4892 mBroadcastWakeLock.acquire();
4893 Message msg = mHandler.obtainMessage(MSG_LAUNCH_VOICE_ASSIST_WITH_WAKE_LOCK,
4894 keyguardActive ? 1 : 0, 0);
4895 msg.setAsynchronous(true);
4896 msg.sendToTarget();
4897 }
4898 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004899 }
Jeff Brown26875502014-01-30 21:47:47 -08004900
Jeff Brownbae8e772014-06-12 19:59:45 -07004901 if (useHapticFeedback) {
4902 performHapticFeedbackLw(null, HapticFeedbackConstants.VIRTUAL_KEY, false);
4903 }
4904
Jeff Brown26875502014-01-30 21:47:47 -08004905 if (isWakeKey) {
Jeff Brown13f00f02014-10-31 14:45:50 -07004906 wakeUp(event.getEventTime(), mAllowTheaterModeWakeFromKey);
Jeff Brown26875502014-01-30 21:47:47 -08004907 }
Bryce Lee584a4452014-10-21 15:55:55 -07004908
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004909 return result;
4910 }
4911
Jeff Brown1c2e4942012-11-06 16:32:01 -08004912 /**
Jeff Brown13f00f02014-10-31 14:45:50 -07004913 * Returns true if the key can have global actions attached to it.
4914 * We reserve all power management keys for the system since they require
4915 * very careful handling.
4916 */
4917 private static boolean isValidGlobalKey(int keyCode) {
4918 switch (keyCode) {
4919 case KeyEvent.KEYCODE_POWER:
4920 case KeyEvent.KEYCODE_WAKEUP:
4921 case KeyEvent.KEYCODE_SLEEP:
4922 return false;
4923 default:
4924 return true;
4925 }
4926 }
4927
4928 /**
Jeff Brown1c2e4942012-11-06 16:32:01 -08004929 * When the screen is off we ignore some keys that might otherwise typically
4930 * be considered wake keys. We filter them out here.
4931 *
4932 * {@link KeyEvent#KEYCODE_POWER} is notably absent from this list because it
4933 * is always considered a wake key.
4934 */
4935 private boolean isWakeKeyWhenScreenOff(int keyCode) {
4936 switch (keyCode) {
4937 // ignore volume keys unless docked
4938 case KeyEvent.KEYCODE_VOLUME_UP:
4939 case KeyEvent.KEYCODE_VOLUME_DOWN:
4940 case KeyEvent.KEYCODE_VOLUME_MUTE:
4941 return mDockMode != Intent.EXTRA_DOCK_STATE_UNDOCKED;
4942
4943 // ignore media and camera keys
4944 case KeyEvent.KEYCODE_MUTE:
4945 case KeyEvent.KEYCODE_HEADSETHOOK:
4946 case KeyEvent.KEYCODE_MEDIA_PLAY:
4947 case KeyEvent.KEYCODE_MEDIA_PAUSE:
4948 case KeyEvent.KEYCODE_MEDIA_PLAY_PAUSE:
4949 case KeyEvent.KEYCODE_MEDIA_STOP:
4950 case KeyEvent.KEYCODE_MEDIA_NEXT:
4951 case KeyEvent.KEYCODE_MEDIA_PREVIOUS:
4952 case KeyEvent.KEYCODE_MEDIA_REWIND:
4953 case KeyEvent.KEYCODE_MEDIA_RECORD:
4954 case KeyEvent.KEYCODE_MEDIA_FAST_FORWARD:
Jaekyun Seokbfdad8e2013-07-08 13:53:21 +09004955 case KeyEvent.KEYCODE_MEDIA_AUDIO_TRACK:
Jeff Brown1c2e4942012-11-06 16:32:01 -08004956 case KeyEvent.KEYCODE_CAMERA:
4957 return false;
4958 }
4959 return true;
4960 }
4961
4962
Jeff Brown56194eb2011-03-02 19:23:13 -08004963 /** {@inheritDoc} */
4964 @Override
Michael Wright70af00a2014-09-03 19:30:20 -07004965 public int interceptMotionBeforeQueueingNonInteractive(long whenNanos, int policyFlags) {
4966 if ((policyFlags & FLAG_WAKE) != 0) {
Bryce Lee5c138322014-11-03 08:26:09 -08004967 if (wakeUp(whenNanos / 1000000, mAllowTheaterModeWakeFromMotion)) {
4968 return 0;
4969 }
Michael Wright70af00a2014-09-03 19:30:20 -07004970 }
Bryce Lee5c138322014-11-03 08:26:09 -08004971
Michael Wright70af00a2014-09-03 19:30:20 -07004972 if (shouldDispatchInputWhenNonInteractive()) {
4973 return ACTION_PASS_TO_USER;
4974 }
Bryce Lee5c138322014-11-03 08:26:09 -08004975
Bryce Lee812d7022014-11-10 13:33:28 -08004976 // If we have not passed the action up and we are in theater mode without dreaming,
4977 // there will be no dream to intercept the touch and wake into ambient. The device should
4978 // wake up in this case.
4979 if (isTheaterModeEnabled() && (policyFlags & FLAG_WAKE) != 0) {
4980 wakeUp(whenNanos / 1000000, mAllowTheaterModeWakeFromMotionWhenNotDreaming);
4981 }
4982
Jeff Brown037c33e2014-04-09 00:31:55 -07004983 return 0;
Jeff Brown56194eb2011-03-02 19:23:13 -08004984 }
4985
Michael Wright70af00a2014-09-03 19:30:20 -07004986 private boolean shouldDispatchInputWhenNonInteractive() {
Bryce Lee5c138322014-11-03 08:26:09 -08004987 // Send events to keyguard while the screen is on.
Jim Millerab954542014-10-10 18:21:49 -07004988 if (isKeyguardShowingAndNotOccluded() && mDisplay != null
4989 && mDisplay.getState() != Display.STATE_OFF) {
Bryce Lee5c138322014-11-03 08:26:09 -08004990 return true;
4991 }
4992
4993 // Send events to a dozing dream even if the screen is off since the dream
4994 // is in control of the state of the screen.
4995 IDreamManager dreamManager = getDreamManager();
4996
4997 try {
4998 if (dreamManager != null && dreamManager.isDreaming()) {
4999 return true;
5000 }
5001 } catch (RemoteException e) {
5002 Slog.e(TAG, "RemoteException when checking if dreaming", e);
5003 }
5004
5005 // Otherwise, consume events since the user can't see what is being
5006 // interacted with.
5007 return false;
Michael Wright70af00a2014-09-03 19:30:20 -07005008 }
5009
RoboErik001c59c2015-01-26 15:53:51 -08005010 private void dispatchDirectAudioEvent(KeyEvent event) {
5011 if (event.getAction() != KeyEvent.ACTION_DOWN) {
5012 return;
5013 }
5014 int keyCode = event.getKeyCode();
John Spurlockb94f2d62015-03-17 14:11:57 -04005015 int flags = AudioManager.FLAG_SHOW_UI | AudioManager.FLAG_PLAY_SOUND
5016 | AudioManager.FLAG_FROM_KEY;
RoboErik001c59c2015-01-26 15:53:51 -08005017 String pkgName = mContext.getOpPackageName();
5018 switch (keyCode) {
5019 case KeyEvent.KEYCODE_VOLUME_UP:
5020 try {
John Spurlockee5ad722015-03-03 16:17:21 -05005021 getAudioService().adjustSuggestedStreamVolume(AudioManager.ADJUST_RAISE,
John Spurlock90874332015-03-10 16:00:54 -04005022 AudioManager.USE_DEFAULT_STREAM_TYPE, flags, pkgName, TAG);
RoboErik001c59c2015-01-26 15:53:51 -08005023 } catch (RemoteException e) {
5024 Log.e(TAG, "Error dispatching volume up in dispatchTvAudioEvent.", e);
5025 }
5026 break;
5027 case KeyEvent.KEYCODE_VOLUME_DOWN:
5028 try {
John Spurlockee5ad722015-03-03 16:17:21 -05005029 getAudioService().adjustSuggestedStreamVolume(AudioManager.ADJUST_LOWER,
John Spurlock90874332015-03-10 16:00:54 -04005030 AudioManager.USE_DEFAULT_STREAM_TYPE, flags, pkgName, TAG);
RoboErik001c59c2015-01-26 15:53:51 -08005031 } catch (RemoteException e) {
5032 Log.e(TAG, "Error dispatching volume down in dispatchTvAudioEvent.", e);
5033 }
5034 break;
5035 case KeyEvent.KEYCODE_VOLUME_MUTE:
5036 try {
5037 if (event.getRepeatCount() == 0) {
John Spurlockee5ad722015-03-03 16:17:21 -05005038 getAudioService().adjustSuggestedStreamVolume(
5039 AudioManager.ADJUST_TOGGLE_MUTE,
John Spurlock90874332015-03-10 16:00:54 -04005040 AudioManager.USE_DEFAULT_STREAM_TYPE, flags, pkgName, TAG);
RoboErik001c59c2015-01-26 15:53:51 -08005041 }
5042 } catch (RemoteException e) {
5043 Log.e(TAG, "Error dispatching mute in dispatchTvAudioEvent.", e);
5044 }
5045 break;
5046 }
5047 }
5048
Jeff Brown40013652012-05-16 21:22:36 -07005049 void dispatchMediaKeyWithWakeLock(KeyEvent event) {
5050 if (DEBUG_INPUT) {
5051 Slog.d(TAG, "dispatchMediaKeyWithWakeLock: " + event);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005052 }
5053
Jeff Brown40013652012-05-16 21:22:36 -07005054 if (mHavePendingMediaKeyRepeatWithWakeLock) {
5055 if (DEBUG_INPUT) {
5056 Slog.d(TAG, "dispatchMediaKeyWithWakeLock: canceled repeat");
5057 }
5058
5059 mHandler.removeMessages(MSG_DISPATCH_MEDIA_KEY_REPEAT_WITH_WAKE_LOCK);
5060 mHavePendingMediaKeyRepeatWithWakeLock = false;
5061 mBroadcastWakeLock.release(); // pending repeat was holding onto the wake lock
5062 }
5063
5064 dispatchMediaKeyWithWakeLockToAudioService(event);
5065
5066 if (event.getAction() == KeyEvent.ACTION_DOWN
5067 && event.getRepeatCount() == 0) {
5068 mHavePendingMediaKeyRepeatWithWakeLock = true;
5069
5070 Message msg = mHandler.obtainMessage(
5071 MSG_DISPATCH_MEDIA_KEY_REPEAT_WITH_WAKE_LOCK, event);
5072 msg.setAsynchronous(true);
5073 mHandler.sendMessageDelayed(msg, ViewConfiguration.getKeyRepeatTimeout());
5074 } else {
5075 mBroadcastWakeLock.release();
5076 }
5077 }
5078
5079 void dispatchMediaKeyRepeatWithWakeLock(KeyEvent event) {
5080 mHavePendingMediaKeyRepeatWithWakeLock = false;
5081
5082 KeyEvent repeatEvent = KeyEvent.changeTimeRepeat(event,
5083 SystemClock.uptimeMillis(), 1, event.getFlags() | KeyEvent.FLAG_LONG_PRESS);
5084 if (DEBUG_INPUT) {
5085 Slog.d(TAG, "dispatchMediaKeyRepeatWithWakeLock: " + repeatEvent);
5086 }
5087
5088 dispatchMediaKeyWithWakeLockToAudioService(repeatEvent);
5089 mBroadcastWakeLock.release();
5090 }
5091
5092 void dispatchMediaKeyWithWakeLockToAudioService(KeyEvent event) {
5093 if (ActivityManagerNative.isSystemReady()) {
RoboErik430fc482014-06-12 15:49:20 -07005094 MediaSessionLegacyHelper.getHelper(mContext).sendMediaButtonEvent(event, true);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005095 }
5096 }
5097
Michael Wright869a67c2014-08-26 19:33:06 -07005098 void launchVoiceAssistWithWakeLock(boolean keyguardActive) {
5099 Intent voiceIntent =
5100 new Intent(RecognizerIntent.ACTION_VOICE_SEARCH_HANDS_FREE);
5101 voiceIntent.putExtra(RecognizerIntent.EXTRA_SECURE, keyguardActive);
Bart Sears8b1c27c2015-03-18 23:51:02 +00005102 startActivityAsUser(voiceIntent, UserHandle.CURRENT_OR_SELF);
Michael Wright869a67c2014-08-26 19:33:06 -07005103 mBroadcastWakeLock.release();
5104 }
5105
Mike Lockwood1753f7f2009-08-24 14:49:07 -07005106 BroadcastReceiver mDockReceiver = new BroadcastReceiver() {
Craig Mautnereee29c42013-01-17 14:44:34 -08005107 @Override
Mike Lockwood1753f7f2009-08-24 14:49:07 -07005108 public void onReceive(Context context, Intent intent) {
Dianne Hackborn867ab6472010-04-29 13:28:56 -07005109 if (Intent.ACTION_DOCK_EVENT.equals(intent.getAction())) {
5110 mDockMode = intent.getIntExtra(Intent.EXTRA_DOCK_STATE,
5111 Intent.EXTRA_DOCK_STATE_UNDOCKED);
Daniel Sandler6396c722013-04-16 20:19:09 -04005112 } else {
5113 try {
5114 IUiModeManager uiModeService = IUiModeManager.Stub.asInterface(
5115 ServiceManager.getService(Context.UI_MODE_SERVICE));
5116 mUiMode = uiModeService.getCurrentModeType();
5117 } catch (RemoteException e) {
5118 }
Dianne Hackborn80fa1662009-10-07 14:02:10 -07005119 }
Jeff Brown01a98dd2011-09-20 15:08:29 -07005120 updateRotation(true);
Craig Mautnereee29c42013-01-17 14:44:34 -08005121 synchronized (mLock) {
5122 updateOrientationListenerLp();
5123 }
Mike Lockwood1753f7f2009-08-24 14:49:07 -07005124 }
5125 };
5126
Jeff Brown6aaf2952012-10-05 16:01:08 -07005127 BroadcastReceiver mDreamReceiver = new BroadcastReceiver() {
5128 @Override
5129 public void onReceive(Context context, Intent intent) {
5130 if (Intent.ACTION_DREAMING_STARTED.equals(intent.getAction())) {
Jim Miller5ecd8112013-01-09 18:50:26 -08005131 if (mKeyguardDelegate != null) {
5132 mKeyguardDelegate.onDreamingStarted();
Jeff Brown6aaf2952012-10-05 16:01:08 -07005133 }
5134 } else if (Intent.ACTION_DREAMING_STOPPED.equals(intent.getAction())) {
Jim Miller5ecd8112013-01-09 18:50:26 -08005135 if (mKeyguardDelegate != null) {
5136 mKeyguardDelegate.onDreamingStopped();
Jeff Brown6aaf2952012-10-05 16:01:08 -07005137 }
5138 }
5139 }
5140 };
5141
Christopher Tate5e08af02012-09-21 17:17:22 -07005142 BroadcastReceiver mMultiuserReceiver = new BroadcastReceiver() {
5143 @Override
5144 public void onReceive(Context context, Intent intent) {
5145 if (Intent.ACTION_USER_SWITCHED.equals(intent.getAction())) {
5146 // tickle the settings observer: this first ensures that we're
5147 // observing the relevant settings for the newly-active user,
5148 // and then updates our own bookkeeping based on the now-
5149 // current user.
5150 mSettingsObserver.onChange(false);
John Spurlockce479d82012-11-29 09:52:21 -05005151
5152 // force a re-application of focused window sysui visibility.
5153 // the window may never have been shown for this user
5154 // e.g. the keyguard when going through the new-user setup flow
John Spurlock04db1762013-05-13 12:46:41 -04005155 synchronized (mWindowManagerFuncs.getWindowManagerLock()) {
John Spurlockce479d82012-11-29 09:52:21 -05005156 mLastSystemUiFlags = 0;
5157 updateSystemUiVisibilityLw();
5158 }
Christopher Tate5e08af02012-09-21 17:17:22 -07005159 }
5160 }
5161 };
5162
John Spurlockd9b70bd2014-02-06 17:02:44 -05005163 private final Runnable mRequestTransientNav = new Runnable() {
5164 @Override
5165 public void run() {
5166 requestTransientBars(mNavigationBar);
5167 }
5168 };
5169
John Spurlocke1f366f2013-08-05 12:22:40 -04005170 private void requestTransientBars(WindowState swipeTarget) {
John Spurlock04db1762013-05-13 12:46:41 -04005171 synchronized (mWindowManagerFuncs.getWindowManagerLock()) {
Maurice Lam99c6e072014-04-28 18:24:28 -07005172 if (!isUserSetupComplete()) {
5173 // Swipe-up for navigation bar is disabled during setup
5174 return;
5175 }
John Spurlock27735a42013-08-14 17:57:38 -04005176 boolean sb = mStatusBarController.checkShowTransientBarLw();
5177 boolean nb = mNavigationBarController.checkShowTransientBarLw();
John Spurlockad3e6cb2013-04-30 08:47:43 -04005178 if (sb || nb) {
Adrian Roos62b65e42015-02-25 18:05:34 +01005179 // Don't show status bar when swiping on already visible navigation bar
5180 if (!nb && swipeTarget == mNavigationBar) {
John Spurlocke1f366f2013-08-05 12:22:40 -04005181 if (DEBUG) Slog.d(TAG, "Not showing transient bar, wrong swipe target");
John Spurlockad3e6cb2013-04-30 08:47:43 -04005182 return;
5183 }
John Spurlock27735a42013-08-14 17:57:38 -04005184 if (sb) mStatusBarController.showTransient();
5185 if (nb) mNavigationBarController.showTransient();
John Spurlockf1a36642013-10-12 17:50:42 -04005186 mImmersiveModeConfirmation.confirmCurrentPrompt();
John Spurlockad3e6cb2013-04-30 08:47:43 -04005187 updateSystemUiVisibilityLw();
John Spurlock32beb2c2013-03-11 10:16:47 -04005188 }
John Spurlockad3e6cb2013-04-30 08:47:43 -04005189 }
5190 }
5191
Jeff Brown3ee549c2014-09-22 20:14:39 -07005192 // Called on the PowerManager's Notifier thread.
Jeff Brownc38c9be2012-10-04 13:16:19 -07005193 @Override
Jeff Brown140ffc72014-05-01 15:18:00 -07005194 public void goingToSleep(int why) {
Dianne Hackborn74489012009-03-24 20:50:09 -07005195 EventLog.writeEvent(70000, 0);
Jeff Brown36c4db82014-09-19 12:05:31 -07005196 if (DEBUG_WAKEUP) Slog.i(TAG, "Going to sleep...");
Jeff Brown3ee549c2014-09-22 20:14:39 -07005197
5198 // We must get this work done here because the power manager will drop
5199 // the wake lock and let the system suspend once this function returns.
The Android Open Source Project0727d222009-03-11 12:11:58 -07005200 synchronized (mLock) {
Jeff Brown3ee549c2014-09-22 20:14:39 -07005201 mAwake = false;
5202 mKeyguardDrawComplete = false;
Jeff Browna20dda42014-05-27 20:57:24 -07005203 updateWakeGestureListenerLp();
The Android Open Source Project0727d222009-03-11 12:11:58 -07005204 updateOrientationListenerLp();
Mike Lockwood28569302010-01-28 11:54:40 -05005205 updateLockScreenTimeout();
The Android Open Source Project0727d222009-03-11 12:11:58 -07005206 }
Jeff Brown3ee549c2014-09-22 20:14:39 -07005207
5208 if (mKeyguardDelegate != null) {
5209 mKeyguardDelegate.onScreenTurnedOff(why);
5210 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005211 }
5212
Jeff Brown13f00f02014-10-31 14:45:50 -07005213 private void wakeUpFromPowerKey(long eventTime) {
5214 wakeUp(eventTime, mAllowTheaterModeWakeFromPowerKey);
5215 }
5216
Bryce Lee5c138322014-11-03 08:26:09 -08005217 private boolean wakeUp(long wakeTime, boolean wakeInTheaterMode) {
Bryce Lee584a4452014-10-21 15:55:55 -07005218 if (!wakeInTheaterMode && isTheaterModeEnabled()) {
Bryce Lee5c138322014-11-03 08:26:09 -08005219 return false;
Bryce Lee584a4452014-10-21 15:55:55 -07005220 }
5221
5222 mPowerManager.wakeUp(wakeTime);
Bryce Lee5c138322014-11-03 08:26:09 -08005223 return true;
Bryce Lee584a4452014-10-21 15:55:55 -07005224 }
5225
Jeff Brown3ee549c2014-09-22 20:14:39 -07005226 // Called on the PowerManager's Notifier thread.
Jeff Brownc38c9be2012-10-04 13:16:19 -07005227 @Override
Jeff Brown36c4db82014-09-19 12:05:31 -07005228 public void wakingUp() {
Dianne Hackborn74489012009-03-24 20:50:09 -07005229 EventLog.writeEvent(70000, 1);
Jeff Brown36c4db82014-09-19 12:05:31 -07005230 if (DEBUG_WAKEUP) Slog.i(TAG, "Waking up...");
Craig Mautner8a0da012014-05-31 15:13:37 -07005231
Jeff Brown3ee549c2014-09-22 20:14:39 -07005232 // Since goToSleep performs these functions synchronously, we must
5233 // do the same here. We cannot post this work to a handler because
5234 // that might cause it to become reordered with respect to what
5235 // may happen in a future call to goToSleep.
The Android Open Source Project0727d222009-03-11 12:11:58 -07005236 synchronized (mLock) {
Jeff Brown3ee549c2014-09-22 20:14:39 -07005237 mAwake = true;
5238 mKeyguardDrawComplete = false;
5239 if (mKeyguardDelegate != null) {
5240 mHandler.removeMessages(MSG_KEYGUARD_DRAWN_TIMEOUT);
5241 mHandler.sendEmptyMessageDelayed(MSG_KEYGUARD_DRAWN_TIMEOUT, 1000);
5242 }
5243
Jeff Browna20dda42014-05-27 20:57:24 -07005244 updateWakeGestureListenerLp();
The Android Open Source Project0727d222009-03-11 12:11:58 -07005245 updateOrientationListenerLp();
Mike Lockwood28569302010-01-28 11:54:40 -05005246 updateLockScreenTimeout();
The Android Open Source Project0727d222009-03-11 12:11:58 -07005247 }
Jeff Brownc38c9be2012-10-04 13:16:19 -07005248
Jim Miller5ecd8112013-01-09 18:50:26 -08005249 if (mKeyguardDelegate != null) {
Craig Mautner8a0da012014-05-31 15:13:37 -07005250 mKeyguardDelegate.onScreenTurnedOn(mKeyguardDelegateCallback);
Jeff Brown36c4db82014-09-19 12:05:31 -07005251 // ... eventually calls finishKeyguardDrawn
Jeff Brownc38c9be2012-10-04 13:16:19 -07005252 } else {
Craig Mautner8a0da012014-05-31 15:13:37 -07005253 if (DEBUG_WAKEUP) Slog.d(TAG, "null mKeyguardDelegate: setting mKeyguardDrawComplete.");
Jeff Brown36c4db82014-09-19 12:05:31 -07005254 finishKeyguardDrawn();
Jeff Brownc38c9be2012-10-04 13:16:19 -07005255 }
Jeff Brown36c4db82014-09-19 12:05:31 -07005256 }
5257
Jeff Brown36c4db82014-09-19 12:05:31 -07005258 private void finishKeyguardDrawn() {
Jeff Brown3ee549c2014-09-22 20:14:39 -07005259 synchronized (mLock) {
5260 if (!mAwake || mKeyguardDrawComplete) {
5261 return; // spurious
5262 }
5263
Jeff Brown36c4db82014-09-19 12:05:31 -07005264 mKeyguardDrawComplete = true;
Jeff Brown3ee549c2014-09-22 20:14:39 -07005265 if (mKeyguardDelegate != null) {
5266 mHandler.removeMessages(MSG_KEYGUARD_DRAWN_TIMEOUT);
5267 }
5268 }
5269
5270 finishScreenTurningOn();
5271 }
5272
5273 // Called on the DisplayManager's DisplayPowerController thread.
5274 @Override
5275 public void screenTurnedOff() {
5276 if (DEBUG_WAKEUP) Slog.i(TAG, "Screen turned off...");
5277
5278 synchronized (mLock) {
5279 mScreenOnEarly = false;
5280 mScreenOnFully = false;
5281 mWindowManagerDrawComplete = false;
5282 mScreenOnListener = null;
5283 updateOrientationListenerLp();
Jeff Brown36c4db82014-09-19 12:05:31 -07005284 }
5285 }
5286
Jeff Brown3ee549c2014-09-22 20:14:39 -07005287 // Called on the DisplayManager's DisplayPowerController thread.
Jeff Brown36c4db82014-09-19 12:05:31 -07005288 @Override
5289 public void screenTurningOn(final ScreenOnListener screenOnListener) {
Jeff Brown36c4db82014-09-19 12:05:31 -07005290 if (DEBUG_WAKEUP) Slog.i(TAG, "Screen turning on...");
Jeff Brown36c4db82014-09-19 12:05:31 -07005291
Jeff Brown3ee549c2014-09-22 20:14:39 -07005292 synchronized (mLock) {
5293 mScreenOnEarly = true;
5294 mScreenOnFully = false;
5295 mWindowManagerDrawComplete = false;
5296 mScreenOnListener = screenOnListener;
5297 updateOrientationListenerLp();
5298 }
Jeff Brown36c4db82014-09-19 12:05:31 -07005299
Craig Mautnerc3daedd2014-09-13 11:17:23 -07005300 mWindowManagerInternal.waitForAllWindowsDrawn(mWindowManagerDrawCallback,
5301 WAITING_FOR_DRAWN_TIMEOUT);
Jeff Brown36c4db82014-09-19 12:05:31 -07005302 // ... eventually calls finishWindowsDrawn
5303 }
5304
Jeff Brown36c4db82014-09-19 12:05:31 -07005305 private void finishWindowsDrawn() {
Jeff Brown3ee549c2014-09-22 20:14:39 -07005306 synchronized (mLock) {
5307 if (!mScreenOnEarly || mWindowManagerDrawComplete) {
5308 return; // spurious
5309 }
5310
Jeff Brown36c4db82014-09-19 12:05:31 -07005311 mWindowManagerDrawComplete = true;
Jeff Brown36c4db82014-09-19 12:05:31 -07005312 }
Jeff Brown3ee549c2014-09-22 20:14:39 -07005313
5314 finishScreenTurningOn();
Jeff Brownc38c9be2012-10-04 13:16:19 -07005315 }
5316
Craig Mautner8a0da012014-05-31 15:13:37 -07005317 private void finishScreenTurningOn() {
Jeff Brown3ee549c2014-09-22 20:14:39 -07005318 final ScreenOnListener listener;
5319 final boolean enableScreen;
Jeff Brown36c4db82014-09-19 12:05:31 -07005320 synchronized (mLock) {
Jeff Brown3ee549c2014-09-22 20:14:39 -07005321 if (DEBUG_WAKEUP) Slog.d(TAG,
5322 "finishScreenTurningOn: mAwake=" + mAwake
5323 + ", mScreenOnEarly=" + mScreenOnEarly
5324 + ", mScreenOnFully=" + mScreenOnFully
5325 + ", mKeyguardDrawComplete=" + mKeyguardDrawComplete
5326 + ", mWindowManagerDrawComplete=" + mWindowManagerDrawComplete);
5327
5328 if (mScreenOnFully || !mScreenOnEarly || !mWindowManagerDrawComplete
5329 || (mAwake && !mKeyguardDrawComplete)) {
5330 return; // spurious or not ready yet
Jeff Brown36c4db82014-09-19 12:05:31 -07005331 }
5332
Jeff Brown3ee549c2014-09-22 20:14:39 -07005333 if (DEBUG_WAKEUP) Slog.i(TAG, "Finished screen turning on...");
5334 listener = mScreenOnListener;
Craig Mautner13f6ea72014-06-23 14:57:02 -07005335 mScreenOnListener = null;
Jeff Brown3ee549c2014-09-22 20:14:39 -07005336 mScreenOnFully = true;
5337
5338 // Remember the first time we draw the keyguard so we know when we're done with
5339 // the main part of booting and can enable the screen and hide boot messages.
5340 if (!mKeyguardDrawnOnce && mAwake) {
5341 mKeyguardDrawnOnce = true;
5342 enableScreen = true;
5343 if (mBootMessageNeedsHiding) {
5344 mBootMessageNeedsHiding = false;
5345 hideBootMessages();
5346 }
5347 } else {
5348 enableScreen = false;
5349 }
Jeff Brownc38c9be2012-10-04 13:16:19 -07005350 }
5351
Jeff Brown3ee549c2014-09-22 20:14:39 -07005352 if (listener != null) {
5353 listener.onScreenOn();
5354 }
Jeff Brown4fc45272012-10-10 18:28:14 -07005355
Jeff Brown3ee549c2014-09-22 20:14:39 -07005356 if (enableScreen) {
5357 try {
5358 mWindowManager.enableScreenIfNeeded();
5359 } catch (RemoteException unhandled) {
Jeff Brown36c4db82014-09-19 12:05:31 -07005360 }
Craig Mautnera631d492014-08-05 15:16:01 -07005361 }
5362 }
5363
5364 private void handleHideBootMessage() {
Jeff Brown3ee549c2014-09-22 20:14:39 -07005365 synchronized (mLock) {
5366 if (!mKeyguardDrawnOnce) {
5367 mBootMessageNeedsHiding = true;
5368 return; // keyguard hasn't drawn the first time yet, not done booting
5369 }
Craig Mautnera631d492014-08-05 15:16:01 -07005370 }
Jeff Brown3ee549c2014-09-22 20:14:39 -07005371
5372 if (mBootMsgDialog != null) {
5373 if (DEBUG_WAKEUP) Slog.d(TAG, "handleHideBootMessage: dismissing");
5374 mBootMsgDialog.dismiss();
5375 mBootMsgDialog = null;
Craig Mautnera631d492014-08-05 15:16:01 -07005376 }
Jeff Brownc38c9be2012-10-04 13:16:19 -07005377 }
5378
5379 @Override
Jeff Brown3ee549c2014-09-22 20:14:39 -07005380 public boolean isScreenOn() {
5381 return mScreenOnFully;
Dianne Hackborn08743722009-12-21 12:16:51 -08005382 }
Jeff Brownc38c9be2012-10-04 13:16:19 -07005383
Dianne Hackborn08743722009-12-21 12:16:51 -08005384 /** {@inheritDoc} */
Jose Lima9546b202014-07-02 17:21:51 -07005385 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005386 public void enableKeyguard(boolean enabled) {
Jim Miller5ecd8112013-01-09 18:50:26 -08005387 if (mKeyguardDelegate != null) {
5388 mKeyguardDelegate.setKeyguardEnabled(enabled);
Mike Lockwood3a74bd32011-08-12 13:55:22 -07005389 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005390 }
5391
5392 /** {@inheritDoc} */
Jose Lima9546b202014-07-02 17:21:51 -07005393 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005394 public void exitKeyguardSecurely(OnKeyguardExitResult callback) {
Jim Miller5ecd8112013-01-09 18:50:26 -08005395 if (mKeyguardDelegate != null) {
5396 mKeyguardDelegate.verifyUnlock(callback);
Mike Lockwood3a74bd32011-08-12 13:55:22 -07005397 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005398 }
5399
Jim Millerab954542014-10-10 18:21:49 -07005400 private boolean isKeyguardShowingAndNotOccluded() {
Jim Miller5ecd8112013-01-09 18:50:26 -08005401 if (mKeyguardDelegate == null) return false;
Jim Millerab954542014-10-10 18:21:49 -07005402 return mKeyguardDelegate.isShowing() && !mKeyguardOccluded;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005403 }
5404
Mike Lockwood520d8bc2011-02-18 13:23:13 -05005405 /** {@inheritDoc} */
Jose Lima9546b202014-07-02 17:21:51 -07005406 @Override
Mike Lockwood520d8bc2011-02-18 13:23:13 -05005407 public boolean isKeyguardLocked() {
5408 return keyguardOn();
5409 }
5410
5411 /** {@inheritDoc} */
Jose Lima9546b202014-07-02 17:21:51 -07005412 @Override
Mike Lockwood520d8bc2011-02-18 13:23:13 -05005413 public boolean isKeyguardSecure() {
Jim Miller5ecd8112013-01-09 18:50:26 -08005414 if (mKeyguardDelegate == null) return false;
5415 return mKeyguardDelegate.isSecure();
Mike Lockwood520d8bc2011-02-18 13:23:13 -05005416 }
5417
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005418 /** {@inheritDoc} */
Jose Lima9546b202014-07-02 17:21:51 -07005419 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005420 public boolean inKeyguardRestrictedKeyInputMode() {
Jim Miller5ecd8112013-01-09 18:50:26 -08005421 if (mKeyguardDelegate == null) return false;
5422 return mKeyguardDelegate.isInputRestricted();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005423 }
5424
Jose Lima9546b202014-07-02 17:21:51 -07005425 @Override
Dianne Hackborn90c52de2011-09-23 12:57:44 -07005426 public void dismissKeyguardLw() {
RoboErik8a2cfc32014-05-16 11:19:38 -07005427 if (mKeyguardDelegate != null && mKeyguardDelegate.isShowing()) {
Craig Mautnerc0d2d0a2014-10-31 16:25:15 -07005428 if (DEBUG_KEYGUARD) Slog.d(TAG, "PWM.dismissKeyguardLw");
Daniel Sandler1ce804392012-11-07 15:07:12 -05005429 mHandler.post(new Runnable() {
Jose Lima9546b202014-07-02 17:21:51 -07005430 @Override
Daniel Sandler1ce804392012-11-07 15:07:12 -05005431 public void run() {
Jorim Jaggi8de4311c2014-08-11 22:36:20 +02005432 // ask the keyguard to prompt the user to authenticate if necessary
5433 mKeyguardDelegate.dismiss();
5434 }
5435 });
5436 }
5437 }
5438
5439 public void notifyActivityDrawnForKeyguardLw() {
5440 if (mKeyguardDelegate != null) {
5441 mHandler.post(new Runnable() {
5442 @Override
5443 public void run() {
5444 mKeyguardDelegate.onActivityDrawn();
Daniel Sandler1ce804392012-11-07 15:07:12 -05005445 }
5446 });
Dianne Hackborn90c52de2011-09-23 12:57:44 -07005447 }
5448 }
5449
Jorim Jaggicff0acb2014-03-31 16:35:15 +02005450 @Override
5451 public boolean isKeyguardDrawnLw() {
5452 synchronized (mLock) {
Jeff Brown3ee549c2014-09-22 20:14:39 -07005453 return mKeyguardDrawnOnce;
Jorim Jaggicff0acb2014-03-31 16:35:15 +02005454 }
5455 }
5456
Jorim Jaggi0d674622014-05-21 01:34:15 +02005457 @Override
Jorim Jaggie29b2db2014-05-30 23:17:03 +02005458 public void startKeyguardExitAnimation(long startTime, long fadeoutDuration) {
Jorim Jaggi0d674622014-05-21 01:34:15 +02005459 if (mKeyguardDelegate != null) {
Craig Mautnerc0d2d0a2014-10-31 16:25:15 -07005460 if (DEBUG_KEYGUARD) Slog.d(TAG, "PWM.startKeyguardExitAnimation");
Jorim Jaggie29b2db2014-05-30 23:17:03 +02005461 mKeyguardDelegate.startKeyguardExitAnimation(startTime, fadeoutDuration);
Jorim Jaggi0d674622014-05-21 01:34:15 +02005462 }
5463 }
5464
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005465 void sendCloseSystemWindows() {
Jorim Jaggib10e33f2015-02-04 21:57:40 +01005466 PhoneWindow.sendCloseSystemWindows(mContext, null);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005467 }
5468
5469 void sendCloseSystemWindows(String reason) {
Jorim Jaggib10e33f2015-02-04 21:57:40 +01005470 PhoneWindow.sendCloseSystemWindows(mContext, reason);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005471 }
Mitsuru Oshima831d0d92009-06-16 18:27:18 -07005472
Jeff Brown01a98dd2011-09-20 15:08:29 -07005473 @Override
5474 public int rotationForOrientationLw(int orientation, int lastRotation) {
Daniel Sandler2ed6ad62011-02-22 14:54:17 -05005475 if (false) {
5476 Slog.v(TAG, "rotationForOrientationLw(orient="
5477 + orientation + ", last=" + lastRotation
5478 + "); user=" + mUserRotation + " "
5479 + ((mUserRotationMode == WindowManagerPolicy.USER_ROTATION_LOCKED)
5480 ? "USER_ROTATION_LOCKED" : "")
5481 );
5482 }
5483
Craig Mautner46ac6fa2013-08-01 10:06:34 -07005484 if (mForceDefaultOrientation) {
5485 return Surface.ROTATION_0;
5486 }
5487
The Android Open Source Project0727d222009-03-11 12:11:58 -07005488 synchronized (mLock) {
Jeff Brownc0347aa2011-09-23 17:26:09 -07005489 int sensorRotation = mOrientationListener.getProposedRotation(); // may be -1
5490 if (sensorRotation < 0) {
Jeff Brown0f862b42012-09-27 21:11:01 -07005491 sensorRotation = lastRotation;
Jeff Brownc0347aa2011-09-23 17:26:09 -07005492 }
Jeff Brown01a98dd2011-09-20 15:08:29 -07005493
Jeff Browndec6cf42011-11-15 14:08:20 -08005494 final int preferredRotation;
Jeff Brown2e7760e2012-04-11 15:14:55 -07005495 if (mLidState == LID_OPEN && mLidOpenRotation >= 0) {
Jeff Brown01a98dd2011-09-20 15:08:29 -07005496 // Ignore sensor when lid switch is open and rotation is forced.
5497 preferredRotation = mLidOpenRotation;
5498 } else if (mDockMode == Intent.EXTRA_DOCK_STATE_CAR
Jeff Brownc0347aa2011-09-23 17:26:09 -07005499 && (mCarDockEnablesAccelerometer || mCarDockRotation >= 0)) {
Jeff Brown01a98dd2011-09-20 15:08:29 -07005500 // Ignore sensor when in car dock unless explicitly enabled.
5501 // This case can override the behavior of NOSENSOR, and can also
5502 // enable 180 degree rotation while docked.
Jeff Brownc0347aa2011-09-23 17:26:09 -07005503 preferredRotation = mCarDockEnablesAccelerometer
Jeff Brown01a98dd2011-09-20 15:08:29 -07005504 ? sensorRotation : mCarDockRotation;
Jeff Brown1a693182011-11-08 14:44:16 -08005505 } else if ((mDockMode == Intent.EXTRA_DOCK_STATE_DESK
5506 || mDockMode == Intent.EXTRA_DOCK_STATE_LE_DESK
5507 || mDockMode == Intent.EXTRA_DOCK_STATE_HE_DESK)
Jeff Brownc0347aa2011-09-23 17:26:09 -07005508 && (mDeskDockEnablesAccelerometer || mDeskDockRotation >= 0)) {
Jeff Brown01a98dd2011-09-20 15:08:29 -07005509 // Ignore sensor when in desk dock unless explicitly enabled.
5510 // This case can override the behavior of NOSENSOR, and can also
5511 // enable 180 degree rotation while docked.
Jeff Brownc0347aa2011-09-23 17:26:09 -07005512 preferredRotation = mDeskDockEnablesAccelerometer
Jeff Brown01a98dd2011-09-20 15:08:29 -07005513 ? sensorRotation : mDeskDockRotation;
Jeff Brownc82c89ed2013-04-17 17:18:15 -07005514 } else if (mHdmiPlugged && mDemoHdmiRotationLock) {
5515 // Ignore sensor when plugged into HDMI when demo HDMI rotation lock enabled.
Jeff Browneb3e4b92011-12-06 19:54:24 -08005516 // Note that the dock orientation overrides the HDMI orientation.
Jeff Brownc82c89ed2013-04-17 17:18:15 -07005517 preferredRotation = mDemoHdmiRotation;
5518 } else if (mHdmiPlugged && mDockMode == Intent.EXTRA_DOCK_STATE_UNDOCKED
5519 && mUndockedHdmiRotation >= 0) {
5520 // Ignore sensor when plugged into HDMI and an undocked orientation has
5521 // been specified in the configuration (only for legacy devices without
5522 // full multi-display support).
5523 // Note that the dock orientation overrides the HDMI orientation.
5524 preferredRotation = mUndockedHdmiRotation;
Chong Zhangae6119ff2014-11-11 18:54:39 -08005525 } else if (mDemoRotationLock) {
5526 // Ignore sensor when demo rotation lock is enabled.
5527 // Note that the dock orientation and HDMI rotation lock override this.
5528 preferredRotation = mDemoRotation;
Dianne Hackbornb9ec1ac2013-04-10 17:34:25 -07005529 } else if (orientation == ActivityInfo.SCREEN_ORIENTATION_LOCKED) {
5530 // Application just wants to remain locked in the last rotation.
5531 preferredRotation = lastRotation;
Jeff Brownbcdfc622014-03-06 19:13:04 -08005532 } else if (!mSupportAutoRotation) {
5533 // If we don't support auto-rotation then bail out here and ignore
5534 // the sensor and any rotation lock settings.
5535 preferredRotation = -1;
Jeff Brown207673cd2012-06-05 17:47:11 -07005536 } else if ((mUserRotationMode == WindowManagerPolicy.USER_ROTATION_FREE
Jeff Brown01a98dd2011-09-20 15:08:29 -07005537 && (orientation == ActivityInfo.SCREEN_ORIENTATION_USER
Dianne Hackbornb9ec1ac2013-04-10 17:34:25 -07005538 || orientation == ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED
5539 || orientation == ActivityInfo.SCREEN_ORIENTATION_USER_LANDSCAPE
5540 || orientation == ActivityInfo.SCREEN_ORIENTATION_USER_PORTRAIT
5541 || orientation == ActivityInfo.SCREEN_ORIENTATION_FULL_USER))
Jeff Brown01a98dd2011-09-20 15:08:29 -07005542 || orientation == ActivityInfo.SCREEN_ORIENTATION_SENSOR
5543 || orientation == ActivityInfo.SCREEN_ORIENTATION_FULL_SENSOR
5544 || orientation == ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE
5545 || orientation == ActivityInfo.SCREEN_ORIENTATION_SENSOR_PORTRAIT) {
5546 // Otherwise, use sensor only if requested by the application or enabled
5547 // by default for USER or UNSPECIFIED modes. Does not apply to NOSENSOR.
Jeff Brownd3187e32011-09-21 19:26:44 -07005548 if (mAllowAllRotations < 0) {
5549 // Can't read this during init() because the context doesn't
5550 // have display metrics at that time so we cannot determine
5551 // tablet vs. phone then.
5552 mAllowAllRotations = mContext.getResources().getBoolean(
5553 com.android.internal.R.bool.config_allowAllRotations) ? 1 : 0;
5554 }
Jeff Brown01a98dd2011-09-20 15:08:29 -07005555 if (sensorRotation != Surface.ROTATION_180
Jeff Brownd3187e32011-09-21 19:26:44 -07005556 || mAllowAllRotations == 1
Dianne Hackbornb9ec1ac2013-04-10 17:34:25 -07005557 || orientation == ActivityInfo.SCREEN_ORIENTATION_FULL_SENSOR
5558 || orientation == ActivityInfo.SCREEN_ORIENTATION_FULL_USER) {
Jeff Brown01a98dd2011-09-20 15:08:29 -07005559 preferredRotation = sensorRotation;
5560 } else {
5561 preferredRotation = lastRotation;
5562 }
Jeff Brown207673cd2012-06-05 17:47:11 -07005563 } else if (mUserRotationMode == WindowManagerPolicy.USER_ROTATION_LOCKED
5564 && orientation != ActivityInfo.SCREEN_ORIENTATION_NOSENSOR) {
5565 // Apply rotation lock. Does not apply to NOSENSOR.
5566 // The idea is that the user rotation expresses a weak preference for the direction
5567 // of gravity and as NOSENSOR is never affected by gravity, then neither should
5568 // NOSENSOR be affected by rotation lock (although it will be affected by docks).
Jeff Brown4dfce202011-10-05 12:00:10 -07005569 preferredRotation = mUserRotation;
Jeff Browndec6cf42011-11-15 14:08:20 -08005570 } else {
5571 // No overriding preference.
5572 // We will do exactly what the application asked us to do.
5573 preferredRotation = -1;
Jeff Brown01a98dd2011-09-20 15:08:29 -07005574 }
5575
Dianne Hackborne5439f22010-10-02 16:53:50 -07005576 switch (orientation) {
5577 case ActivityInfo.SCREEN_ORIENTATION_PORTRAIT:
Jeff Browndec6cf42011-11-15 14:08:20 -08005578 // Return portrait unless overridden.
5579 if (isAnyPortrait(preferredRotation)) {
5580 return preferredRotation;
5581 }
Dianne Hackborne5439f22010-10-02 16:53:50 -07005582 return mPortraitRotation;
Dianne Hackborne5439f22010-10-02 16:53:50 -07005583
Jeff Brown01a98dd2011-09-20 15:08:29 -07005584 case ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE:
Jeff Browndec6cf42011-11-15 14:08:20 -08005585 // Return landscape unless overridden.
5586 if (isLandscapeOrSeascape(preferredRotation)) {
5587 return preferredRotation;
5588 }
Jeff Brown01a98dd2011-09-20 15:08:29 -07005589 return mLandscapeRotation;
5590
5591 case ActivityInfo.SCREEN_ORIENTATION_REVERSE_PORTRAIT:
Jeff Browndec6cf42011-11-15 14:08:20 -08005592 // Return reverse portrait unless overridden.
5593 if (isAnyPortrait(preferredRotation)) {
5594 return preferredRotation;
5595 }
Jeff Brown01a98dd2011-09-20 15:08:29 -07005596 return mUpsideDownRotation;
5597
5598 case ActivityInfo.SCREEN_ORIENTATION_REVERSE_LANDSCAPE:
Jeff Browndec6cf42011-11-15 14:08:20 -08005599 // Return seascape unless overridden.
5600 if (isLandscapeOrSeascape(preferredRotation)) {
5601 return preferredRotation;
5602 }
Jeff Brown01a98dd2011-09-20 15:08:29 -07005603 return mSeascapeRotation;
5604
5605 case ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE:
Dianne Hackbornb9ec1ac2013-04-10 17:34:25 -07005606 case ActivityInfo.SCREEN_ORIENTATION_USER_LANDSCAPE:
Jeff Brown01a98dd2011-09-20 15:08:29 -07005607 // Return either landscape rotation.
5608 if (isLandscapeOrSeascape(preferredRotation)) {
5609 return preferredRotation;
5610 }
5611 if (isLandscapeOrSeascape(lastRotation)) {
Jeff Brown4519f072011-01-23 13:16:01 -08005612 return lastRotation;
5613 }
Jeff Brown01a98dd2011-09-20 15:08:29 -07005614 return mLandscapeRotation;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005615
Jeff Brown01a98dd2011-09-20 15:08:29 -07005616 case ActivityInfo.SCREEN_ORIENTATION_SENSOR_PORTRAIT:
Dianne Hackbornb9ec1ac2013-04-10 17:34:25 -07005617 case ActivityInfo.SCREEN_ORIENTATION_USER_PORTRAIT:
Jeff Brown01a98dd2011-09-20 15:08:29 -07005618 // Return either portrait rotation.
5619 if (isAnyPortrait(preferredRotation)) {
5620 return preferredRotation;
5621 }
5622 if (isAnyPortrait(lastRotation)) {
5623 return lastRotation;
5624 }
5625 return mPortraitRotation;
5626
5627 default:
Jeff Brown4dfce202011-10-05 12:00:10 -07005628 // For USER, UNSPECIFIED, NOSENSOR, SENSOR and FULL_SENSOR,
5629 // just return the preferred orientation we already calculated.
Jeff Brown01a98dd2011-09-20 15:08:29 -07005630 if (preferredRotation >= 0) {
5631 return preferredRotation;
5632 }
Dianne Hackborndacea8c2011-04-21 17:26:39 -07005633 return Surface.ROTATION_0;
Daniel Sandlere7e5ac22011-02-22 16:10:21 -05005634 }
5635 }
Steve Howarda7bfe6a2010-09-23 16:47:49 -07005636 }
5637
Jeff Brown01a98dd2011-09-20 15:08:29 -07005638 @Override
5639 public boolean rotationHasCompatibleMetricsLw(int orientation, int rotation) {
5640 switch (orientation) {
5641 case ActivityInfo.SCREEN_ORIENTATION_PORTRAIT:
5642 case ActivityInfo.SCREEN_ORIENTATION_REVERSE_PORTRAIT:
5643 case ActivityInfo.SCREEN_ORIENTATION_SENSOR_PORTRAIT:
5644 return isAnyPortrait(rotation);
5645
5646 case ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE:
5647 case ActivityInfo.SCREEN_ORIENTATION_REVERSE_LANDSCAPE:
5648 case ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE:
5649 return isLandscapeOrSeascape(rotation);
5650
5651 default:
5652 return true;
5653 }
Steve Howarda7bfe6a2010-09-23 16:47:49 -07005654 }
5655
Jeff Brownc0347aa2011-09-23 17:26:09 -07005656 @Override
5657 public void setRotationLw(int rotation) {
5658 mOrientationListener.setCurrentRotation(rotation);
5659 }
5660
Jeff Brown01a98dd2011-09-20 15:08:29 -07005661 private boolean isLandscapeOrSeascape(int rotation) {
5662 return rotation == mLandscapeRotation || rotation == mSeascapeRotation;
Dianne Hackborne5439f22010-10-02 16:53:50 -07005663 }
5664
Jeff Brown01a98dd2011-09-20 15:08:29 -07005665 private boolean isAnyPortrait(int rotation) {
5666 return rotation == mPortraitRotation || rotation == mUpsideDownRotation;
Dianne Hackborne5439f22010-10-02 16:53:50 -07005667 }
5668
Jose Lima9546b202014-07-02 17:21:51 -07005669 @Override
Svetoslav Ganov80943d82013-01-02 10:25:37 -08005670 public int getUserRotationMode() {
5671 return Settings.System.getIntForUser(mContext.getContentResolver(),
Brett Chabot7e55c402013-05-16 19:38:08 -07005672 Settings.System.ACCELEROMETER_ROTATION, 0, UserHandle.USER_CURRENT) != 0 ?
5673 WindowManagerPolicy.USER_ROTATION_FREE :
5674 WindowManagerPolicy.USER_ROTATION_LOCKED;
Svetoslav Ganov80943d82013-01-02 10:25:37 -08005675 }
Daniel Sandlerb73617d2010-08-17 00:41:00 -04005676
5677 // User rotation: to be used when all else fails in assigning an orientation to the device
Jose Lima9546b202014-07-02 17:21:51 -07005678 @Override
Daniel Sandlerb73617d2010-08-17 00:41:00 -04005679 public void setUserRotationMode(int mode, int rot) {
5680 ContentResolver res = mContext.getContentResolver();
Daniel Sandler2ed6ad62011-02-22 14:54:17 -05005681
5682 // mUserRotationMode and mUserRotation will be assigned by the content observer
Daniel Sandlerb73617d2010-08-17 00:41:00 -04005683 if (mode == WindowManagerPolicy.USER_ROTATION_LOCKED) {
Christopher Tate5e08af02012-09-21 17:17:22 -07005684 Settings.System.putIntForUser(res,
Daniel Sandlerb73617d2010-08-17 00:41:00 -04005685 Settings.System.USER_ROTATION,
Christopher Tate5e08af02012-09-21 17:17:22 -07005686 rot,
5687 UserHandle.USER_CURRENT);
5688 Settings.System.putIntForUser(res,
Daniel Sandler2ed6ad62011-02-22 14:54:17 -05005689 Settings.System.ACCELEROMETER_ROTATION,
Christopher Tate5e08af02012-09-21 17:17:22 -07005690 0,
5691 UserHandle.USER_CURRENT);
Daniel Sandlerb73617d2010-08-17 00:41:00 -04005692 } else {
Christopher Tate5e08af02012-09-21 17:17:22 -07005693 Settings.System.putIntForUser(res,
Daniel Sandlerb73617d2010-08-17 00:41:00 -04005694 Settings.System.ACCELEROMETER_ROTATION,
Christopher Tate5e08af02012-09-21 17:17:22 -07005695 1,
5696 UserHandle.USER_CURRENT);
Daniel Sandlerb73617d2010-08-17 00:41:00 -04005697 }
5698 }
5699
Jose Lima9546b202014-07-02 17:21:51 -07005700 @Override
Jeff Brownac143512012-04-05 18:57:33 -07005701 public void setSafeMode(boolean safeMode) {
5702 mSafeMode = safeMode;
5703 performHapticFeedbackLw(null, safeMode
5704 ? HapticFeedbackConstants.SAFE_MODE_ENABLED
5705 : HapticFeedbackConstants.SAFE_MODE_DISABLED, true);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005706 }
Craig Mautnereda67292013-04-28 13:50:14 -07005707
Dianne Hackborn181ceb52009-08-27 22:16:40 -07005708 static long[] getLongIntArray(Resources r, int resid) {
5709 int[] ar = r.getIntArray(resid);
5710 if (ar == null) {
5711 return null;
5712 }
5713 long[] out = new long[ar.length];
5714 for (int i=0; i<ar.length; i++) {
5715 out[i] = ar[i];
5716 }
5717 return out;
5718 }
Craig Mautnereda67292013-04-28 13:50:14 -07005719
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005720 /** {@inheritDoc} */
Craig Mautnereda67292013-04-28 13:50:14 -07005721 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005722 public void systemReady() {
Jim Millerab954542014-10-10 18:21:49 -07005723 mKeyguardDelegate = new KeyguardServiceDelegate(mContext);
Mike Lockwooded8902d2013-11-15 11:01:47 -08005724 mKeyguardDelegate.onSystemReady();
5725
Michael Wright3818c922014-09-02 13:59:07 -07005726 readCameraLensCoverState();
Jeff Brown4f5fa282014-06-12 19:19:15 -07005727 updateUiMode();
Dianne Hackbornb1a79802009-09-29 15:18:31 -07005728 synchronized (mLock) {
5729 updateOrientationListenerLp();
Dianne Hackbornc777e072010-02-12 13:07:59 -08005730 mSystemReady = true;
5731 mHandler.post(new Runnable() {
Craig Mautnereda67292013-04-28 13:50:14 -07005732 @Override
Dianne Hackbornc777e072010-02-12 13:07:59 -08005733 public void run() {
5734 updateSettings();
5735 }
5736 });
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005737 }
5738 }
Dianne Hackborn661cd522011-08-22 00:26:20 -07005739
Dianne Hackbornba24e4d2011-09-01 11:17:06 -07005740 /** {@inheritDoc} */
Jose Lima9546b202014-07-02 17:21:51 -07005741 @Override
Dianne Hackbornba24e4d2011-09-01 11:17:06 -07005742 public void systemBooted() {
Jim Millere5f910a2013-10-16 18:15:46 -07005743 if (mKeyguardDelegate != null) {
Jason Monk5eeebf52014-09-26 12:36:51 -04005744 mKeyguardDelegate.bindService(mContext);
Jim Millere5f910a2013-10-16 18:15:46 -07005745 mKeyguardDelegate.onBootCompleted();
5746 }
Dianne Hackbornba24e4d2011-09-01 11:17:06 -07005747 synchronized (mLock) {
5748 mSystemBooted = true;
5749 }
Jeff Brown36c4db82014-09-19 12:05:31 -07005750 wakingUp();
5751 screenTurningOn(null);
Dianne Hackbornba24e4d2011-09-01 11:17:06 -07005752 }
5753
Dianne Hackborn661cd522011-08-22 00:26:20 -07005754 ProgressDialog mBootMsgDialog = null;
5755
5756 /** {@inheritDoc} */
Jose Lima9546b202014-07-02 17:21:51 -07005757 @Override
Dianne Hackborn661cd522011-08-22 00:26:20 -07005758 public void showBootMessage(final CharSequence msg, final boolean always) {
5759 mHandler.post(new Runnable() {
5760 @Override public void run() {
5761 if (mBootMsgDialog == null) {
Craig Stout4c0cb8a2014-04-04 13:03:10 -07005762 int theme;
5763 if (mContext.getPackageManager().hasSystemFeature(
5764 PackageManager.FEATURE_WATCH)) {
5765 theme = com.android.internal.R.style.Theme_Micro_Dialog_Alert;
5766 } else if (mContext.getPackageManager().hasSystemFeature(
5767 PackageManager.FEATURE_TELEVISION)) {
5768 theme = com.android.internal.R.style.Theme_Leanback_Dialog_Alert;
5769 } else {
5770 theme = 0;
5771 }
Vinod Krishnanfa8fc412014-04-18 14:35:53 -07005772
5773 mBootMsgDialog = new ProgressDialog(mContext, theme) {
Dianne Hackborn295e3c22011-08-25 13:19:08 -07005774 // This dialog will consume all events coming in to
5775 // it, to avoid it trying to do things too early in boot.
5776 @Override public boolean dispatchKeyEvent(KeyEvent event) {
5777 return true;
5778 }
5779 @Override public boolean dispatchKeyShortcutEvent(KeyEvent event) {
5780 return true;
5781 }
5782 @Override public boolean dispatchTouchEvent(MotionEvent ev) {
5783 return true;
5784 }
5785 @Override public boolean dispatchTrackballEvent(MotionEvent ev) {
5786 return true;
5787 }
5788 @Override public boolean dispatchGenericMotionEvent(MotionEvent ev) {
5789 return true;
5790 }
5791 @Override public boolean dispatchPopulateAccessibilityEvent(
5792 AccessibilityEvent event) {
5793 return true;
5794 }
5795 };
Jeff Hao9f60c082014-10-28 18:51:07 -07005796 if (mContext.getPackageManager().isUpgrade()) {
5797 mBootMsgDialog.setTitle(R.string.android_upgrading_title);
5798 } else {
5799 mBootMsgDialog.setTitle(R.string.android_start_title);
5800 }
Dianne Hackborn661cd522011-08-22 00:26:20 -07005801 mBootMsgDialog.setProgressStyle(ProgressDialog.STYLE_SPINNER);
5802 mBootMsgDialog.setIndeterminate(true);
5803 mBootMsgDialog.getWindow().setType(
Dianne Hackborn29aae6f2011-08-18 18:30:09 -07005804 WindowManager.LayoutParams.TYPE_BOOT_PROGRESS);
Dianne Hackborn661cd522011-08-22 00:26:20 -07005805 mBootMsgDialog.getWindow().addFlags(
5806 WindowManager.LayoutParams.FLAG_DIM_BEHIND
5807 | WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN);
5808 mBootMsgDialog.getWindow().setDimAmount(1);
Dianne Hackbornd9efb952011-12-07 14:56:51 -08005809 WindowManager.LayoutParams lp = mBootMsgDialog.getWindow().getAttributes();
5810 lp.screenOrientation = ActivityInfo.SCREEN_ORIENTATION_NOSENSOR;
5811 mBootMsgDialog.getWindow().setAttributes(lp);
Dianne Hackborn661cd522011-08-22 00:26:20 -07005812 mBootMsgDialog.setCancelable(false);
5813 mBootMsgDialog.show();
5814 }
5815 mBootMsgDialog.setMessage(msg);
5816 }
5817 });
5818 }
5819
5820 /** {@inheritDoc} */
Jose Lima9546b202014-07-02 17:21:51 -07005821 @Override
Dianne Hackborn661cd522011-08-22 00:26:20 -07005822 public void hideBootMessages() {
Craig Mautnera631d492014-08-05 15:16:01 -07005823 mHandler.sendEmptyMessage(MSG_HIDE_BOOT_MESSAGE);
Dianne Hackborn661cd522011-08-22 00:26:20 -07005824 }
5825
Mike Lockwood28569302010-01-28 11:54:40 -05005826 /** {@inheritDoc} */
Jose Lima9546b202014-07-02 17:21:51 -07005827 @Override
Mike Lockwood28569302010-01-28 11:54:40 -05005828 public void userActivity() {
Dianne Hackborndf89e652011-10-06 22:35:11 -07005829 // ***************************************
5830 // NOTE NOTE NOTE NOTE NOTE NOTE NOTE NOTE
5831 // ***************************************
5832 // THIS IS CALLED FROM DEEP IN THE POWER MANAGER
5833 // WITH ITS LOCKS HELD.
5834 //
5835 // This code must be VERY careful about the locks
5836 // it acquires.
5837 // In fact, the current code acquires way too many,
5838 // and probably has lurking deadlocks.
5839
Mike Lockwood28569302010-01-28 11:54:40 -05005840 synchronized (mScreenLockTimeout) {
5841 if (mLockScreenTimerActive) {
5842 // reset the timer
5843 mHandler.removeCallbacks(mScreenLockTimeout);
5844 mHandler.postDelayed(mScreenLockTimeout, mLockScreenTimeout);
5845 }
5846 }
Daniel Sandler0601eb72011-04-13 01:01:32 -04005847 }
5848
Adam Cohenf7522022012-10-03 20:03:18 -07005849 class ScreenLockTimeout implements Runnable {
5850 Bundle options;
5851
5852 @Override
Mike Lockwood28569302010-01-28 11:54:40 -05005853 public void run() {
5854 synchronized (this) {
5855 if (localLOGV) Log.v(TAG, "mScreenLockTimeout activating keyguard");
Jim Miller5ecd8112013-01-09 18:50:26 -08005856 if (mKeyguardDelegate != null) {
5857 mKeyguardDelegate.doKeyguardTimeout(options);
Mike Lockwood3a74bd32011-08-12 13:55:22 -07005858 }
Mike Lockwood28569302010-01-28 11:54:40 -05005859 mLockScreenTimerActive = false;
Adam Cohenf7522022012-10-03 20:03:18 -07005860 options = null;
Mike Lockwood28569302010-01-28 11:54:40 -05005861 }
5862 }
Mike Lockwood28569302010-01-28 11:54:40 -05005863
Adam Cohenf7522022012-10-03 20:03:18 -07005864 public void setLockOptions(Bundle options) {
5865 this.options = options;
5866 }
5867 }
5868
5869 ScreenLockTimeout mScreenLockTimeout = new ScreenLockTimeout();
5870
Jose Lima9546b202014-07-02 17:21:51 -07005871 @Override
Adam Cohenf7522022012-10-03 20:03:18 -07005872 public void lockNow(Bundle options) {
Jim Miller93c518e2012-01-17 15:55:31 -08005873 mContext.enforceCallingOrSelfPermission(android.Manifest.permission.DEVICE_POWER, null);
5874 mHandler.removeCallbacks(mScreenLockTimeout);
Adam Cohenf7522022012-10-03 20:03:18 -07005875 if (options != null) {
5876 // In case multiple calls are made to lockNow, we don't wipe out the options
5877 // until the runnable actually executes.
5878 mScreenLockTimeout.setLockOptions(options);
5879 }
Jim Miller93c518e2012-01-17 15:55:31 -08005880 mHandler.post(mScreenLockTimeout);
5881 }
5882
Mike Lockwood28569302010-01-28 11:54:40 -05005883 private void updateLockScreenTimeout() {
5884 synchronized (mScreenLockTimeout) {
Jeff Brown3ee549c2014-09-22 20:14:39 -07005885 boolean enable = (mAllowLockscreenWhenOn && mAwake &&
Jim Miller5ecd8112013-01-09 18:50:26 -08005886 mKeyguardDelegate != null && mKeyguardDelegate.isSecure());
Mike Lockwood28569302010-01-28 11:54:40 -05005887 if (mLockScreenTimerActive != enable) {
5888 if (enable) {
5889 if (localLOGV) Log.v(TAG, "setting lockscreen timer");
5890 mHandler.postDelayed(mScreenLockTimeout, mLockScreenTimeout);
5891 } else {
5892 if (localLOGV) Log.v(TAG, "clearing lockscreen timer");
5893 mHandler.removeCallbacks(mScreenLockTimeout);
5894 }
5895 mLockScreenTimerActive = enable;
5896 }
5897 }
5898 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005899
Jeff Brown061ea992015-04-17 19:55:47 -07005900 private void updateDreamingSleepToken(boolean acquire) {
5901 if (acquire) {
5902 if (mDreamingSleepToken == null) {
5903 mDreamingSleepToken = mActivityManagerInternal.acquireSleepToken("Dream");
5904 }
5905 } else {
5906 if (mDreamingSleepToken != null) {
5907 mDreamingSleepToken.release();
5908 }
5909 }
5910 }
5911
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005912 /** {@inheritDoc} */
Craig Mautnereda67292013-04-28 13:50:14 -07005913 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005914 public void enableScreenAfterBoot() {
5915 readLidState();
Jeff Brownc458ce92012-04-30 14:58:40 -07005916 applyLidSwitchState();
Jeff Brown01a98dd2011-09-20 15:08:29 -07005917 updateRotation(true);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005918 }
Dianne Hackbornf54c8f92009-09-19 14:03:57 -07005919
Jeff Brownc458ce92012-04-30 14:58:40 -07005920 private void applyLidSwitchState() {
Jeff Brownc458ce92012-04-30 14:58:40 -07005921 if (mLidState == LID_CLOSED && mLidControlsSleep) {
Jeff Brown6d8fd272014-05-20 21:24:38 -07005922 mPowerManager.goToSleep(SystemClock.uptimeMillis(),
Jeff Brownc12035c2014-08-13 18:52:25 -07005923 PowerManager.GO_TO_SLEEP_REASON_LID_SWITCH,
Jeff Brown6d8fd272014-05-20 21:24:38 -07005924 PowerManager.GO_TO_SLEEP_FLAG_NO_DOZE);
Jeff Brownc458ce92012-04-30 14:58:40 -07005925 }
Jeff Browna20dda42014-05-27 20:57:24 -07005926
5927 synchronized (mLock) {
5928 updateWakeGestureListenerLp();
5929 }
Jeff Brown01a98dd2011-09-20 15:08:29 -07005930 }
5931
Jeff Brown4f5fa282014-06-12 19:19:15 -07005932 void updateUiMode() {
5933 if (mUiModeManager == null) {
5934 mUiModeManager = IUiModeManager.Stub.asInterface(
5935 ServiceManager.getService(Context.UI_MODE_SERVICE));
5936 }
5937 try {
5938 mUiMode = mUiModeManager.getCurrentModeType();
5939 } catch (RemoteException e) {
5940 }
5941 }
5942
Jeff Brown01a98dd2011-09-20 15:08:29 -07005943 void updateRotation(boolean alwaysSendConfiguration) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005944 try {
5945 //set orientation on WindowManager
Dianne Hackbornf87d1962012-04-04 12:48:24 -07005946 mWindowManager.updateRotation(alwaysSendConfiguration, false);
5947 } catch (RemoteException e) {
5948 // Ignore
5949 }
5950 }
5951
5952 void updateRotation(boolean alwaysSendConfiguration, boolean forceRelayout) {
5953 try {
5954 //set orientation on WindowManager
5955 mWindowManager.updateRotation(alwaysSendConfiguration, forceRelayout);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005956 } catch (RemoteException e) {
5957 // Ignore
5958 }
5959 }
5960
Daniel Sandler6396c722013-04-16 20:19:09 -04005961 /**
5962 * Return an Intent to launch the currently active dock app as home. Returns
5963 * null if the standard home should be launched, which is the case if any of the following is
5964 * true:
5965 * <ul>
5966 * <li>The device is not in either car mode or desk mode
5967 * <li>The device is in car mode but ENABLE_CAR_DOCK_HOME_CAPTURE is false
5968 * <li>The device is in desk mode but ENABLE_DESK_DOCK_HOME_CAPTURE is false
5969 * <li>The device is in car mode but there's no CAR_DOCK app with METADATA_DOCK_HOME
5970 * <li>The device is in desk mode but there's no DESK_DOCK app with METADATA_DOCK_HOME
5971 * </ul>
Craig Mautnereda67292013-04-28 13:50:14 -07005972 * @return A dock intent.
Daniel Sandler6396c722013-04-16 20:19:09 -04005973 */
5974 Intent createHomeDockIntent() {
5975 Intent intent = null;
5976
5977 // What home does is based on the mode, not the dock state. That
5978 // is, when in car mode you should be taken to car home regardless
5979 // of whether we are actually in a car dock.
5980 if (mUiMode == Configuration.UI_MODE_TYPE_CAR) {
5981 if (ENABLE_CAR_DOCK_HOME_CAPTURE) {
5982 intent = mCarDockIntent;
5983 }
5984 } else if (mUiMode == Configuration.UI_MODE_TYPE_DESK) {
5985 if (ENABLE_DESK_DOCK_HOME_CAPTURE) {
5986 intent = mDeskDockIntent;
5987 }
Jeff Brown4f5fa282014-06-12 19:19:15 -07005988 } else if (mUiMode == Configuration.UI_MODE_TYPE_WATCH
5989 && (mDockMode == Intent.EXTRA_DOCK_STATE_DESK
5990 || mDockMode == Intent.EXTRA_DOCK_STATE_HE_DESK
5991 || mDockMode == Intent.EXTRA_DOCK_STATE_LE_DESK)) {
5992 // Always launch dock home from home when watch is docked, if it exists.
5993 intent = mDeskDockIntent;
Daniel Sandler6396c722013-04-16 20:19:09 -04005994 }
5995
5996 if (intent == null) {
5997 return null;
5998 }
5999
6000 ActivityInfo ai = null;
6001 ResolveInfo info = mContext.getPackageManager().resolveActivityAsUser(
6002 intent,
John Spurlockf56bef12013-07-09 09:51:46 -04006003 PackageManager.MATCH_DEFAULT_ONLY | PackageManager.GET_META_DATA,
Craig Mautnerd625ab22013-09-06 13:40:31 -07006004 mCurrentUserId);
Daniel Sandler6396c722013-04-16 20:19:09 -04006005 if (info != null) {
6006 ai = info.activityInfo;
6007 }
6008 if (ai != null
6009 && ai.metaData != null
6010 && ai.metaData.getBoolean(Intent.METADATA_DOCK_HOME)) {
6011 intent = new Intent(intent);
6012 intent.setClassName(ai.packageName, ai.name);
6013 return intent;
6014 }
6015
6016 return null;
6017 }
6018
Filip Gruszczynskia483a1d2015-03-17 19:06:58 +00006019 void startDockOrHome(boolean fromHomeKey, boolean awakenFromDreams) {
6020 if (awakenFromDreams) {
6021 awakenDreams();
6022 }
Daniel Sandler6396c722013-04-16 20:19:09 -04006023
6024 Intent dock = createHomeDockIntent();
6025 if (dock != null) {
6026 try {
Bryce Lee01b0c5f2015-02-05 18:24:04 -08006027 if (fromHomeKey) {
6028 dock.putExtra(WindowManagerPolicy.EXTRA_FROM_HOME_KEY, fromHomeKey);
6029 }
Bart Sears8b1c27c2015-03-18 23:51:02 +00006030 startActivityAsUser(dock, UserHandle.CURRENT);
Daniel Sandler6396c722013-04-16 20:19:09 -04006031 return;
6032 } catch (ActivityNotFoundException e) {
6033 }
6034 }
6035
Bryce Lee01b0c5f2015-02-05 18:24:04 -08006036 Intent intent;
6037
6038 if (fromHomeKey) {
6039 intent = new Intent(mHomeIntent);
6040 intent.putExtra(WindowManagerPolicy.EXTRA_FROM_HOME_KEY, fromHomeKey);
6041 } else {
6042 intent = mHomeIntent;
6043 }
6044
Bryce Lee9fc0b6f2015-03-19 21:37:45 +00006045 startActivityAsUser(intent, UserHandle.CURRENT);
Dianne Hackborn39c2d712009-09-22 11:41:31 -07006046 }
Craig Mautnereda67292013-04-28 13:50:14 -07006047
Dianne Hackborn39c2d712009-09-22 11:41:31 -07006048 /**
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006049 * goes to the home screen
6050 * @return whether it did anything
6051 */
6052 boolean goHome() {
Bart Sears8b1c27c2015-03-18 23:51:02 +00006053 if (!isUserSetupComplete()) {
6054 Slog.i(TAG, "Not going home because user setup is in progress.");
6055 return false;
6056 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006057 if (false) {
6058 // This code always brings home to the front.
Dianne Hackborn256dd3b2009-05-19 18:51:21 -07006059 try {
6060 ActivityManagerNative.getDefault().stopAppSwitches();
6061 } catch (RemoteException e) {
6062 }
Dianne Hackborn94a679d2009-07-28 17:51:07 -07006063 sendCloseSystemWindows();
Filip Gruszczynskia483a1d2015-03-17 19:06:58 +00006064 startDockOrHome(false /*fromHomeKey*/, true /* awakenFromDreams */);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006065 } else {
6066 // This code brings home to the front or, if it is already
6067 // at the front, puts the device to sleep.
6068 try {
Wink Savilled2e6a332010-02-12 12:12:06 -08006069 if (SystemProperties.getInt("persist.sys.uts-test-mode", 0) == 1) {
6070 /// Roll back EndcallBehavior as the cupcake design to pass P1 lab entry.
6071 Log.d(TAG, "UTS-TEST-MODE");
6072 } else {
6073 ActivityManagerNative.getDefault().stopAppSwitches();
6074 sendCloseSystemWindows();
Daniel Sandler6396c722013-04-16 20:19:09 -04006075 Intent dock = createHomeDockIntent();
6076 if (dock != null) {
6077 int result = ActivityManagerNative.getDefault()
6078 .startActivityAsUser(null, null, dock,
6079 dock.resolveTypeIfNeeded(mContext.getContentResolver()),
6080 null, null, 0,
6081 ActivityManager.START_FLAG_ONLY_IF_NEEDED,
Jeff Hao1b012d32014-08-20 10:35:34 -07006082 null, null, UserHandle.USER_CURRENT);
Daniel Sandler6396c722013-04-16 20:19:09 -04006083 if (result == ActivityManager.START_RETURN_INTENT_TO_CALLER) {
6084 return false;
6085 }
6086 }
Dianne Hackborn39c2d712009-09-22 11:41:31 -07006087 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006088 int result = ActivityManagerNative.getDefault()
Dianne Hackbornf265ea92013-01-31 15:00:51 -08006089 .startActivityAsUser(null, null, mHomeIntent,
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006090 mHomeIntent.resolveTypeIfNeeded(mContext.getContentResolver()),
Dianne Hackborna4972e92012-03-14 10:38:05 -07006091 null, null, 0,
6092 ActivityManager.START_FLAG_ONLY_IF_NEEDED,
Jeff Hao1b012d32014-08-20 10:35:34 -07006093 null, null, UserHandle.USER_CURRENT);
Dianne Hackborna4972e92012-03-14 10:38:05 -07006094 if (result == ActivityManager.START_RETURN_INTENT_TO_CALLER) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006095 return false;
6096 }
6097 } catch (RemoteException ex) {
6098 // bummer, the activity manager, which is in this process, is dead
6099 }
6100 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006101 return true;
6102 }
Craig Mautnereda67292013-04-28 13:50:14 -07006103
6104 @Override
The Android Open Source Project0727d222009-03-11 12:11:58 -07006105 public void setCurrentOrientationLw(int newOrientation) {
6106 synchronized (mLock) {
6107 if (newOrientation != mCurrentAppOrientation) {
6108 mCurrentAppOrientation = newOrientation;
6109 updateOrientationListenerLp();
6110 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006111 }
6112 }
Amith Yamasanic33cb712010-02-10 15:21:49 -08006113
Svetoslav Ganov7befb7d2012-09-27 16:49:23 -07006114 private void performAuditoryFeedbackForAccessibilityIfNeed() {
6115 if (!isGlobalAccessibilityGestureEnabled()) {
6116 return;
6117 }
6118 AudioManager audioManager = (AudioManager) mContext.getSystemService(
6119 Context.AUDIO_SERVICE);
6120 if (audioManager.isSilentMode()) {
6121 return;
6122 }
6123 Ringtone ringTone = RingtoneManager.getRingtone(mContext,
6124 Settings.System.DEFAULT_NOTIFICATION_URI);
6125 ringTone.setStreamType(AudioManager.STREAM_MUSIC);
6126 ringTone.play();
6127 }
Craig Mautnereda67292013-04-28 13:50:14 -07006128
Bryce Lee584a4452014-10-21 15:55:55 -07006129 private boolean isTheaterModeEnabled() {
6130 return Settings.Global.getInt(mContext.getContentResolver(),
6131 Settings.Global.THEATER_MODE_ON, 0) == 1;
6132 }
6133
Svetoslav Ganov7befb7d2012-09-27 16:49:23 -07006134 private boolean isGlobalAccessibilityGestureEnabled() {
6135 return Settings.Global.getInt(mContext.getContentResolver(),
6136 Settings.Global.ENABLE_ACCESSIBILITY_GLOBAL_GESTURE_ENABLED, 0) == 1;
6137 }
6138
Craig Mautnereda67292013-04-28 13:50:14 -07006139 @Override
The Android Open Source Project0727d222009-03-11 12:11:58 -07006140 public boolean performHapticFeedbackLw(WindowState win, int effectId, boolean always) {
Svetoslav Ganov96179212012-10-10 14:17:45 -07006141 if (!mVibrator.hasVibrator()) {
6142 return false;
6143 }
Christopher Tate5e08af02012-09-21 17:17:22 -07006144 final boolean hapticsDisabled = Settings.System.getIntForUser(mContext.getContentResolver(),
6145 Settings.System.HAPTIC_FEEDBACK_ENABLED, 0, UserHandle.USER_CURRENT) == 0;
Jeff Brown82379ba2014-07-25 19:03:28 -07006146 if (hapticsDisabled && !always) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006147 return false;
6148 }
Amith Yamasanic33cb712010-02-10 15:21:49 -08006149 long[] pattern = null;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006150 switch (effectId) {
6151 case HapticFeedbackConstants.LONG_PRESS:
Amith Yamasanic33cb712010-02-10 15:21:49 -08006152 pattern = mLongPressVibePattern;
6153 break;
Dianne Hackbornb1a79802009-09-29 15:18:31 -07006154 case HapticFeedbackConstants.VIRTUAL_KEY:
Amith Yamasanic33cb712010-02-10 15:21:49 -08006155 pattern = mVirtualKeyVibePattern;
6156 break;
6157 case HapticFeedbackConstants.KEYBOARD_TAP:
6158 pattern = mKeyboardTapVibePattern;
6159 break;
Fabrice Di Meglioeeff63a2013-08-05 12:07:24 -07006160 case HapticFeedbackConstants.CLOCK_TICK:
6161 pattern = mClockTickVibePattern;
6162 break;
Fabrice Di Megliobd9152f2013-10-01 11:21:31 -07006163 case HapticFeedbackConstants.CALENDAR_DATE:
6164 pattern = mCalendarDateVibePattern;
6165 break;
Dianne Hackbornb1a79802009-09-29 15:18:31 -07006166 case HapticFeedbackConstants.SAFE_MODE_DISABLED:
Amith Yamasanic33cb712010-02-10 15:21:49 -08006167 pattern = mSafeModeDisabledVibePattern;
6168 break;
Dianne Hackbornb1a79802009-09-29 15:18:31 -07006169 case HapticFeedbackConstants.SAFE_MODE_ENABLED:
Amith Yamasanic33cb712010-02-10 15:21:49 -08006170 pattern = mSafeModeEnabledVibePattern;
6171 break;
Mady Mellore82067b2015-04-30 09:58:35 -07006172 case HapticFeedbackConstants.STYLUS_BUTTON_PRESS:
6173 pattern = mStylusButtonPressVibePattern;
6174 break;
Amith Yamasanic33cb712010-02-10 15:21:49 -08006175 default:
6176 return false;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006177 }
Dianne Hackbornf265ea92013-01-31 15:00:51 -08006178 int owningUid;
6179 String owningPackage;
6180 if (win != null) {
6181 owningUid = win.getOwningUid();
6182 owningPackage = win.getOwningPackage();
6183 } else {
6184 owningUid = android.os.Process.myUid();
Dianne Hackborn95d78532013-09-11 09:51:14 -07006185 owningPackage = mContext.getOpPackageName();
Dianne Hackbornf265ea92013-01-31 15:00:51 -08006186 }
Amith Yamasanic33cb712010-02-10 15:21:49 -08006187 if (pattern.length == 1) {
6188 // One-shot vibration
John Spurlock7b414672014-07-18 13:02:39 -04006189 mVibrator.vibrate(owningUid, owningPackage, pattern[0], VIBRATION_ATTRIBUTES);
Amith Yamasanic33cb712010-02-10 15:21:49 -08006190 } else {
6191 // Pattern vibration
John Spurlock7b414672014-07-18 13:02:39 -04006192 mVibrator.vibrate(owningUid, owningPackage, pattern, -1, VIBRATION_ATTRIBUTES);
Amith Yamasanic33cb712010-02-10 15:21:49 -08006193 }
6194 return true;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006195 }
Jeff Brownc38c9be2012-10-04 13:16:19 -07006196
6197 @Override
6198 public void keepScreenOnStartedLw() {
Daniel Sandler0601eb72011-04-13 01:01:32 -04006199 }
6200
Jeff Brownc38c9be2012-10-04 13:16:19 -07006201 @Override
6202 public void keepScreenOnStoppedLw() {
Jim Millerab954542014-10-10 18:21:49 -07006203 if (isKeyguardShowingAndNotOccluded()) {
Jim Miller25190572013-02-28 17:36:24 -08006204 mPowerManager.userActivity(SystemClock.uptimeMillis(), false);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006205 }
6206 }
Mike Lockwoodfcb39242009-10-21 23:01:07 -04006207
Dianne Hackborndf89e652011-10-06 22:35:11 -07006208 private int updateSystemUiVisibilityLw() {
Joe Onorato664644d2011-01-23 17:53:23 -08006209 // If there is no window focused, there will be nobody to handle the events
6210 // anyway, so just hang on in whatever state we're in until things settle down.
Adrian Roos53f28ec2014-10-29 17:26:12 +01006211 final WindowState win = mFocusedWindow != null ? mFocusedWindow
6212 : mTopFullscreenOpaqueWindowState;
John Spurlock79da8332013-09-20 12:04:47 -04006213 if (win == null) {
Dianne Hackborndf89e652011-10-06 22:35:11 -07006214 return 0;
6215 }
Jorim Jaggi380ecb82014-03-14 17:25:20 +01006216 if ((win.getAttrs().privateFlags & PRIVATE_FLAG_KEYGUARD) != 0 && mHideLockScreen == true) {
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07006217 // We are updating at a point where the keyguard has gotten
6218 // focus, but we were last in a state where the top window is
6219 // hiding it. This is probably because the keyguard as been
6220 // shown while the top window was displayed, so we want to ignore
6221 // it here because this is just a very transient change and it
6222 // will quickly lose focus once it correctly gets hidden.
6223 return 0;
6224 }
John Spurlock32beb2c2013-03-11 10:16:47 -04006225
John Spurlock1db8b682014-02-18 11:18:59 -05006226 int tmpVisibility = PolicyControl.getSystemUiVisibility(win, null)
Dianne Hackborne26ab702011-10-16 13:21:33 -07006227 & ~mResettingSystemUiFlags
6228 & ~mForceClearedSystemUiFlags;
John Spurlock79da8332013-09-20 12:04:47 -04006229 if (mForcingShowNavBar && win.getSurfaceLayer() < mForcingShowNavBarLayer) {
John Spurlockc6d1c602014-01-17 15:22:06 -05006230 tmpVisibility &= ~PolicyControl.adjustClearableFlags(win, View.SYSTEM_UI_CLEARABLE_FLAGS);
Dianne Hackborn891d3fb2013-01-09 18:31:37 -08006231 }
Adrian Rooscd3884d2015-02-18 17:25:23 +01006232 tmpVisibility = updateLightStatusBarLw(tmpVisibility);
John Spurlock79da8332013-09-20 12:04:47 -04006233 final int visibility = updateSystemBarsLw(win, mLastSystemUiFlags, tmpVisibility);
John Spurlockad3e6cb2013-04-30 08:47:43 -04006234 final int diff = visibility ^ mLastSystemUiFlags;
John Spurlock79da8332013-09-20 12:04:47 -04006235 final boolean needsMenu = win.getNeedsMenuLw(mTopFullscreenOpaqueWindowState);
Dianne Hackborne0f085d2011-11-30 18:41:15 -08006236 if (diff == 0 && mLastFocusNeedsMenu == needsMenu
John Spurlock79da8332013-09-20 12:04:47 -04006237 && mFocusedApp == win.getAppToken()) {
Dianne Hackborndf89e652011-10-06 22:35:11 -07006238 return 0;
6239 }
Dianne Hackborne26ab702011-10-16 13:21:33 -07006240 mLastSystemUiFlags = visibility;
Dianne Hackborn4eff8d32011-11-10 19:38:40 -08006241 mLastFocusNeedsMenu = needsMenu;
John Spurlock79da8332013-09-20 12:04:47 -04006242 mFocusedApp = win.getAppToken();
Dianne Hackborndf89e652011-10-06 22:35:11 -07006243 mHandler.post(new Runnable() {
Craig Mautnereda67292013-04-28 13:50:14 -07006244 @Override
Dianne Hackborndf89e652011-10-06 22:35:11 -07006245 public void run() {
Dianne Hackborn42e620c2012-06-24 13:20:51 -07006246 try {
6247 IStatusBarService statusbar = getStatusBarService();
6248 if (statusbar != null) {
Adrian Roos53f28ec2014-10-29 17:26:12 +01006249 statusbar.setSystemUiVisibility(visibility, 0xffffffff, win.toString());
Dianne Hackborn42e620c2012-06-24 13:20:51 -07006250 statusbar.topAppWindowChanged(needsMenu);
Joe Onorato664644d2011-01-23 17:53:23 -08006251 }
Dianne Hackborn42e620c2012-06-24 13:20:51 -07006252 } catch (RemoteException e) {
6253 // re-acquire status bar service next time it is needed.
6254 mStatusBarService = null;
Joe Onorato664644d2011-01-23 17:53:23 -08006255 }
Dianne Hackborndf89e652011-10-06 22:35:11 -07006256 }
6257 });
6258 return diff;
Joe Onorato664644d2011-01-23 17:53:23 -08006259 }
6260
Adrian Rooscd3884d2015-02-18 17:25:23 +01006261 private int updateLightStatusBarLw(int vis) {
6262 WindowState statusColorWin = isStatusBarKeyguard() && !mHideLockScreen
6263 ? mStatusBar
6264 : mTopFullscreenOpaqueOrDimmingWindowState;
6265
6266 if (statusColorWin != null) {
6267 if (statusColorWin == mTopFullscreenOpaqueWindowState) {
6268 // If the top fullscreen-or-dimming window is also the top fullscreen, respect
6269 // its light flag.
6270 vis &= ~View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR;
6271 vis |= PolicyControl.getSystemUiVisibility(statusColorWin, null)
6272 & View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR;
6273 } else if (statusColorWin != null && statusColorWin.isDimming()) {
6274 // Otherwise if it's dimming, clear the light flag.
6275 vis &= ~View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR;
6276 }
6277 }
6278 return vis;
6279 }
6280
John Spurlock79da8332013-09-20 12:04:47 -04006281 private int updateSystemBarsLw(WindowState win, int oldVis, int vis) {
John Spurlockbd957402013-10-03 11:38:39 -04006282 // apply translucent bar vis flags
Jorim Jaggi380ecb82014-03-14 17:25:20 +01006283 WindowState transWin = isStatusBarKeyguard() && !mHideLockScreen
6284 ? mStatusBar
John Spurlockbd957402013-10-03 11:38:39 -04006285 : mTopFullscreenOpaqueWindowState;
6286 vis = mStatusBarController.applyTranslucentFlagLw(transWin, vis, oldVis);
6287 vis = mNavigationBarController.applyTranslucentFlagLw(transWin, vis, oldVis);
6288
John Spurlock27735a42013-08-14 17:57:38 -04006289 // prevent status bar interaction from clearing certain flags
John Spurlock79da8332013-09-20 12:04:47 -04006290 boolean statusBarHasFocus = win.getAttrs().type == TYPE_STATUS_BAR;
John Spurlock08ffcf52014-07-11 10:13:46 -04006291 if (statusBarHasFocus && !isStatusBarKeyguard()) {
John Spurlockad3e6cb2013-04-30 08:47:43 -04006292 int flags = View.SYSTEM_UI_FLAG_FULLSCREEN
6293 | View.SYSTEM_UI_FLAG_HIDE_NAVIGATION
John Spurlockcfc359a2013-09-05 10:42:03 -04006294 | View.SYSTEM_UI_FLAG_IMMERSIVE
Jorim Jaggi73fef8d2015-02-16 17:32:28 +01006295 | View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY
6296 | View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR;
John Spurlock08ffcf52014-07-11 10:13:46 -04006297 if (mHideLockScreen) {
Jorim Jaggi5cf17872014-03-26 18:31:48 +01006298 flags |= View.STATUS_BAR_TRANSLUCENT | View.NAVIGATION_BAR_TRANSLUCENT;
6299 }
John Spurlockbd957402013-10-03 11:38:39 -04006300 vis = (vis & ~flags) | (oldVis & flags);
John Spurlockad3e6cb2013-04-30 08:47:43 -04006301 }
John Spurlockad3e6cb2013-04-30 08:47:43 -04006302
Adrian Roos4fb3ee32014-08-22 19:29:09 +02006303 if (!areTranslucentBarsAllowed() && transWin != mStatusBar) {
Adrian Roosea562512014-05-05 13:33:03 +02006304 vis &= ~(View.NAVIGATION_BAR_TRANSLUCENT | View.STATUS_BAR_TRANSLUCENT
6305 | View.SYSTEM_UI_TRANSPARENT);
Alan Viverette5a0f4ec2013-10-07 15:10:29 -07006306 }
6307
John Spurlock27735a42013-08-14 17:57:38 -04006308 // update status bar
John Spurlockf1a36642013-10-12 17:50:42 -04006309 boolean immersiveSticky =
6310 (vis & View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY) != 0;
John Spurlock27735a42013-08-14 17:57:38 -04006311 boolean hideStatusBarWM =
John Spurlockbd957402013-10-03 11:38:39 -04006312 mTopFullscreenOpaqueWindowState != null &&
John Spurlockc6d1c602014-01-17 15:22:06 -05006313 (PolicyControl.getWindowFlags(mTopFullscreenOpaqueWindowState, null)
John Spurlock27735a42013-08-14 17:57:38 -04006314 & WindowManager.LayoutParams.FLAG_FULLSCREEN) != 0;
6315 boolean hideStatusBarSysui =
6316 (vis & View.SYSTEM_UI_FLAG_FULLSCREEN) != 0;
John Spurlockf1a36642013-10-12 17:50:42 -04006317 boolean hideNavBarSysui =
6318 (vis & View.SYSTEM_UI_FLAG_HIDE_NAVIGATION) != 0;
John Spurlockad3e6cb2013-04-30 08:47:43 -04006319
John Spurlock27735a42013-08-14 17:57:38 -04006320 boolean transientStatusBarAllowed =
6321 mStatusBar != null && (
6322 hideStatusBarWM
John Spurlockf1a36642013-10-12 17:50:42 -04006323 || (hideStatusBarSysui && immersiveSticky)
John Spurlock27735a42013-08-14 17:57:38 -04006324 || statusBarHasFocus);
6325
John Spurlockf1a36642013-10-12 17:50:42 -04006326 boolean transientNavBarAllowed =
6327 mNavigationBar != null &&
6328 hideNavBarSysui && immersiveSticky;
6329
John Spurlockf25706f2013-11-07 18:02:43 -05006330 boolean denyTransientStatus = mStatusBarController.isTransientShowRequested()
John Spurlockf1a36642013-10-12 17:50:42 -04006331 && !transientStatusBarAllowed && hideStatusBarSysui;
John Spurlockf25706f2013-11-07 18:02:43 -05006332 boolean denyTransientNav = mNavigationBarController.isTransientShowRequested()
John Spurlockf1a36642013-10-12 17:50:42 -04006333 && !transientNavBarAllowed;
6334 if (denyTransientStatus || denyTransientNav) {
John Spurlock27735a42013-08-14 17:57:38 -04006335 // clear the clearable flags instead
John Spurlockf1a36642013-10-12 17:50:42 -04006336 clearClearableFlagsLw();
tiger_huangc58d7562014-10-23 20:24:19 +08006337 vis &= ~View.SYSTEM_UI_CLEARABLE_FLAGS;
John Spurlockad3e6cb2013-04-30 08:47:43 -04006338 }
John Spurlock27735a42013-08-14 17:57:38 -04006339
6340 vis = mStatusBarController.updateVisibilityLw(transientStatusBarAllowed, oldVis, vis);
6341
6342 // update navigation bar
John Spurlockf1a36642013-10-12 17:50:42 -04006343 boolean oldImmersiveMode = isImmersiveMode(oldVis);
6344 boolean newImmersiveMode = isImmersiveMode(vis);
6345 if (win != null && oldImmersiveMode != newImmersiveMode) {
John Spurlock79da8332013-09-20 12:04:47 -04006346 final String pkg = win.getOwningPackage();
Maurice Lam99c6e072014-04-28 18:24:28 -07006347 mImmersiveModeConfirmation.immersiveModeChanged(pkg, newImmersiveMode,
6348 isUserSetupComplete());
John Spurlock34e13d92013-08-10 06:52:28 -04006349 }
John Spurlock27735a42013-08-14 17:57:38 -04006350
John Spurlockf1a36642013-10-12 17:50:42 -04006351 vis = mNavigationBarController.updateVisibilityLw(transientNavBarAllowed, oldVis, vis);
6352
John Spurlocke1f366f2013-08-05 12:22:40 -04006353 return vis;
John Spurlockad3e6cb2013-04-30 08:47:43 -04006354 }
6355
John Spurlockf1a36642013-10-12 17:50:42 -04006356 private void clearClearableFlagsLw() {
6357 int newVal = mResettingSystemUiFlags | View.SYSTEM_UI_CLEARABLE_FLAGS;
6358 if (newVal != mResettingSystemUiFlags) {
6359 mResettingSystemUiFlags = newVal;
6360 mWindowManagerFuncs.reevaluateStatusBarVisibility();
6361 }
6362 }
6363
6364 private boolean isImmersiveMode(int vis) {
6365 final int flags = View.SYSTEM_UI_FLAG_IMMERSIVE | View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY;
John Spurlock34e13d92013-08-10 06:52:28 -04006366 return mNavigationBar != null
6367 && (vis & View.SYSTEM_UI_FLAG_HIDE_NAVIGATION) != 0
Daniel Sandler900ece52013-10-18 15:53:27 -04006368 && (vis & flags) != 0
6369 && canHideNavigationBar();
John Spurlock34e13d92013-08-10 06:52:28 -04006370 }
6371
Alan Viverette5a0f4ec2013-10-07 15:10:29 -07006372 /**
Daniel Sandlerdd73ee42013-10-11 22:19:59 -04006373 * @return whether the navigation or status bar can be made translucent
6374 *
6375 * This should return true unless touch exploration is not enabled or
6376 * R.boolean.config_enableTranslucentDecor is false.
Alan Viverette5a0f4ec2013-10-07 15:10:29 -07006377 */
Daniel Sandlerdd73ee42013-10-11 22:19:59 -04006378 private boolean areTranslucentBarsAllowed() {
Svetoslav8e3feb12014-02-24 13:46:47 -08006379 return mTranslucentDecorEnabled
6380 && !mAccessibilityManager.isTouchExplorationEnabled();
Alan Viverette5a0f4ec2013-10-07 15:10:29 -07006381 }
6382
Daniel Sandler0c4ccff2011-10-19 16:39:14 -04006383 // Use this instead of checking config_showNavigationBar so that it can be consistently
6384 // overridden by qemu.hw.mainkeys in the emulator.
Craig Mautnereda67292013-04-28 13:50:14 -07006385 @Override
Daniel Sandler0c4ccff2011-10-19 16:39:14 -04006386 public boolean hasNavigationBar() {
6387 return mHasNavigationBar;
6388 }
6389
satok1bc0a492012-04-25 22:47:12 +09006390 @Override
6391 public void setLastInputMethodWindowLw(WindowState ime, WindowState target) {
6392 mLastInputMethodWindow = ime;
6393 mLastInputMethodTargetWindow = target;
6394 }
6395
Craig Mautnerf1b67412012-09-19 13:18:29 -07006396 @Override
Satoshi Kataoka658c7b82013-10-10 17:03:51 +09006397 public int getInputMethodWindowVisibleHeightLw() {
6398 return mDockBottom - mCurBottom;
6399 }
6400
6401 @Override
Craig Mautnerf1b67412012-09-19 13:18:29 -07006402 public void setCurrentUserLw(int newUserId) {
Craig Mautnerd625ab22013-09-06 13:40:31 -07006403 mCurrentUserId = newUserId;
Jim Miller5ecd8112013-01-09 18:50:26 -08006404 if (mKeyguardDelegate != null) {
6405 mKeyguardDelegate.setCurrentUser(newUserId);
Craig Mautnerf1b67412012-09-19 13:18:29 -07006406 }
John Spurlock13451a22012-09-28 14:40:41 -04006407 if (mStatusBarService != null) {
6408 try {
6409 mStatusBarService.setCurrentUser(newUserId);
6410 } catch (RemoteException e) {
6411 // oh well
6412 }
6413 }
Dianne Hackborn2ea9bae2012-11-02 18:43:48 -07006414 setLastInputMethodWindowLw(null, null);
Craig Mautnerf1b67412012-09-19 13:18:29 -07006415 }
6416
6417 @Override
Svetoslav Ganov545252f2012-12-10 18:29:24 -08006418 public boolean canMagnifyWindow(int windowType) {
6419 switch (windowType) {
6420 case WindowManager.LayoutParams.TYPE_INPUT_METHOD:
6421 case WindowManager.LayoutParams.TYPE_INPUT_METHOD_DIALOG:
6422 case WindowManager.LayoutParams.TYPE_NAVIGATION_BAR:
6423 case WindowManager.LayoutParams.TYPE_MAGNIFICATION_OVERLAY: {
6424 return false;
6425 }
6426 }
6427 return true;
6428 }
6429
6430 @Override
6431 public boolean isTopLevelWindow(int windowType) {
6432 if (windowType >= WindowManager.LayoutParams.FIRST_SUB_WINDOW
6433 && windowType <= WindowManager.LayoutParams.LAST_SUB_WINDOW) {
6434 return (windowType == WindowManager.LayoutParams.TYPE_APPLICATION_ATTACHED_DIALOG);
6435 }
6436 return true;
6437 }
6438
Jim Miller4eeb4f62012-11-08 00:04:29 -08006439 @Override
Jeff Brownd7a04de2012-06-17 14:17:52 -07006440 public void dump(String prefix, PrintWriter pw, String[] args) {
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08006441 pw.print(prefix); pw.print("mSafeMode="); pw.print(mSafeMode);
Dianne Hackbornba24e4d2011-09-01 11:17:06 -07006442 pw.print(" mSystemReady="); pw.print(mSystemReady);
6443 pw.print(" mSystemBooted="); pw.println(mSystemBooted);
Jeff Brown2e7760e2012-04-11 15:14:55 -07006444 pw.print(prefix); pw.print("mLidState="); pw.print(mLidState);
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08006445 pw.print(" mLidOpenRotation="); pw.print(mLidOpenRotation);
Michael Wright3818c922014-09-02 13:59:07 -07006446 pw.print(" mCameraLensCoverState="); pw.print(mCameraLensCoverState);
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08006447 pw.print(" mHdmiPlugged="); pw.println(mHdmiPlugged);
Dianne Hackborne26ab702011-10-16 13:21:33 -07006448 if (mLastSystemUiFlags != 0 || mResettingSystemUiFlags != 0
6449 || mForceClearedSystemUiFlags != 0) {
6450 pw.print(prefix); pw.print("mLastSystemUiFlags=0x");
6451 pw.print(Integer.toHexString(mLastSystemUiFlags));
6452 pw.print(" mResettingSystemUiFlags=0x");
6453 pw.print(Integer.toHexString(mResettingSystemUiFlags));
6454 pw.print(" mForceClearedSystemUiFlags=0x");
6455 pw.println(Integer.toHexString(mForceClearedSystemUiFlags));
Dianne Hackborndf89e652011-10-06 22:35:11 -07006456 }
Dianne Hackborn4eff8d32011-11-10 19:38:40 -08006457 if (mLastFocusNeedsMenu) {
6458 pw.print(prefix); pw.print("mLastFocusNeedsMenu=");
6459 pw.println(mLastFocusNeedsMenu);
6460 }
Jeff Browna20dda42014-05-27 20:57:24 -07006461 pw.print(prefix); pw.print("mWakeGestureEnabledSetting=");
6462 pw.println(mWakeGestureEnabledSetting);
6463
Jeff Brownbcdfc622014-03-06 19:13:04 -08006464 pw.print(prefix); pw.print("mSupportAutoRotation="); pw.println(mSupportAutoRotation);
Daniel Sandler6396c722013-04-16 20:19:09 -04006465 pw.print(prefix); pw.print("mUiMode="); pw.print(mUiMode);
6466 pw.print(" mDockMode="); pw.print(mDockMode);
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08006467 pw.print(" mCarDockRotation="); pw.print(mCarDockRotation);
6468 pw.print(" mDeskDockRotation="); pw.println(mDeskDockRotation);
6469 pw.print(prefix); pw.print("mUserRotationMode="); pw.print(mUserRotationMode);
6470 pw.print(" mUserRotation="); pw.print(mUserRotation);
Daniel Sandler2ed6ad62011-02-22 14:54:17 -05006471 pw.print(" mAllowAllRotations="); pw.println(mAllowAllRotations);
Dianne Hackborn6e2281d2012-06-19 17:48:32 -07006472 pw.print(prefix); pw.print("mCurrentAppOrientation="); pw.println(mCurrentAppOrientation);
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08006473 pw.print(prefix); pw.print("mCarDockEnablesAccelerometer=");
6474 pw.print(mCarDockEnablesAccelerometer);
6475 pw.print(" mDeskDockEnablesAccelerometer=");
6476 pw.println(mDeskDockEnablesAccelerometer);
6477 pw.print(prefix); pw.print("mLidKeyboardAccessibility=");
6478 pw.print(mLidKeyboardAccessibility);
6479 pw.print(" mLidNavigationAccessibility="); pw.print(mLidNavigationAccessibility);
Dianne Hackborn6e2281d2012-06-19 17:48:32 -07006480 pw.print(" mLidControlsSleep="); pw.println(mLidControlsSleep);
Jeff Brown6d8fd272014-05-20 21:24:38 -07006481 pw.print(prefix);
6482 pw.print("mShortPressOnPowerBehavior="); pw.print(mShortPressOnPowerBehavior);
6483 pw.print(" mLongPressOnPowerBehavior="); pw.println(mLongPressOnPowerBehavior);
Jeff Brown13f00f02014-10-31 14:45:50 -07006484 pw.print(prefix);
6485 pw.print("mDoublePressOnPowerBehavior="); pw.print(mDoublePressOnPowerBehavior);
6486 pw.print(" mTriplePressOnPowerBehavior="); pw.println(mTriplePressOnPowerBehavior);
Jeff Brown6d8fd272014-05-20 21:24:38 -07006487 pw.print(prefix); pw.print("mHasSoftInput="); pw.println(mHasSoftInput);
Jeff Brown3ee549c2014-09-22 20:14:39 -07006488 pw.print(prefix); pw.print("mAwake="); pw.println(mAwake);
6489 pw.print(prefix); pw.print("mScreenOnEarly="); pw.print(mScreenOnEarly);
6490 pw.print(" mScreenOnFully="); pw.println(mScreenOnFully);
6491 pw.print(prefix); pw.print("mKeyguardDrawComplete="); pw.print(mKeyguardDrawComplete);
6492 pw.print(" mWindowManagerDrawComplete="); pw.println(mWindowManagerDrawComplete);
6493 pw.print(prefix); pw.print("mOrientationSensorEnabled=");
6494 pw.println(mOrientationSensorEnabled);
Dianne Hackbornc652de82013-02-15 16:32:56 -08006495 pw.print(prefix); pw.print("mOverscanScreen=("); pw.print(mOverscanScreenLeft);
6496 pw.print(","); pw.print(mOverscanScreenTop);
6497 pw.print(") "); pw.print(mOverscanScreenWidth);
6498 pw.print("x"); pw.println(mOverscanScreenHeight);
6499 if (mOverscanLeft != 0 || mOverscanTop != 0
6500 || mOverscanRight != 0 || mOverscanBottom != 0) {
6501 pw.print(prefix); pw.print("mOverscan left="); pw.print(mOverscanLeft);
6502 pw.print(" top="); pw.print(mOverscanTop);
6503 pw.print(" right="); pw.print(mOverscanRight);
6504 pw.print(" bottom="); pw.println(mOverscanBottom);
6505 }
Dianne Hackborn313440842013-02-19 19:22:59 -08006506 pw.print(prefix); pw.print("mRestrictedOverscanScreen=(");
6507 pw.print(mRestrictedOverscanScreenLeft);
6508 pw.print(","); pw.print(mRestrictedOverscanScreenTop);
6509 pw.print(") "); pw.print(mRestrictedOverscanScreenWidth);
6510 pw.print("x"); pw.println(mRestrictedOverscanScreenHeight);
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08006511 pw.print(prefix); pw.print("mUnrestrictedScreen=("); pw.print(mUnrestrictedScreenLeft);
6512 pw.print(","); pw.print(mUnrestrictedScreenTop);
6513 pw.print(") "); pw.print(mUnrestrictedScreenWidth);
6514 pw.print("x"); pw.println(mUnrestrictedScreenHeight);
6515 pw.print(prefix); pw.print("mRestrictedScreen=("); pw.print(mRestrictedScreenLeft);
6516 pw.print(","); pw.print(mRestrictedScreenTop);
6517 pw.print(") "); pw.print(mRestrictedScreenWidth);
6518 pw.print("x"); pw.println(mRestrictedScreenHeight);
Dianne Hackborn5b5cc4d2012-05-16 13:15:00 -07006519 pw.print(prefix); pw.print("mStableFullscreen=("); pw.print(mStableFullscreenLeft);
6520 pw.print(","); pw.print(mStableFullscreenTop);
6521 pw.print(")-("); pw.print(mStableFullscreenRight);
6522 pw.print(","); pw.print(mStableFullscreenBottom); pw.println(")");
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07006523 pw.print(prefix); pw.print("mStable=("); pw.print(mStableLeft);
6524 pw.print(","); pw.print(mStableTop);
6525 pw.print(")-("); pw.print(mStableRight);
6526 pw.print(","); pw.print(mStableBottom); pw.println(")");
Dianne Hackborn5c58de32012-04-28 19:52:37 -07006527 pw.print(prefix); pw.print("mSystem=("); pw.print(mSystemLeft);
6528 pw.print(","); pw.print(mSystemTop);
6529 pw.print(")-("); pw.print(mSystemRight);
6530 pw.print(","); pw.print(mSystemBottom); pw.println(")");
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08006531 pw.print(prefix); pw.print("mCur=("); pw.print(mCurLeft);
6532 pw.print(","); pw.print(mCurTop);
6533 pw.print(")-("); pw.print(mCurRight);
6534 pw.print(","); pw.print(mCurBottom); pw.println(")");
6535 pw.print(prefix); pw.print("mContent=("); pw.print(mContentLeft);
6536 pw.print(","); pw.print(mContentTop);
6537 pw.print(")-("); pw.print(mContentRight);
6538 pw.print(","); pw.print(mContentBottom); pw.println(")");
Dianne Hackborne30e02f2014-05-27 18:24:45 -07006539 pw.print(prefix); pw.print("mVoiceContent=("); pw.print(mVoiceContentLeft);
6540 pw.print(","); pw.print(mVoiceContentTop);
6541 pw.print(")-("); pw.print(mVoiceContentRight);
6542 pw.print(","); pw.print(mVoiceContentBottom); pw.println(")");
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08006543 pw.print(prefix); pw.print("mDock=("); pw.print(mDockLeft);
6544 pw.print(","); pw.print(mDockTop);
6545 pw.print(")-("); pw.print(mDockRight);
6546 pw.print(","); pw.print(mDockBottom); pw.println(")");
Dianne Hackborn5c58de32012-04-28 19:52:37 -07006547 pw.print(prefix); pw.print("mDockLayer="); pw.print(mDockLayer);
6548 pw.print(" mStatusBarLayer="); pw.println(mStatusBarLayer);
Dianne Hackborn7ad44382012-10-18 17:46:00 -07006549 pw.print(prefix); pw.print("mShowingLockscreen="); pw.print(mShowingLockscreen);
6550 pw.print(" mShowingDream="); pw.print(mShowingDream);
Jeff Brown061ea992015-04-17 19:55:47 -07006551 pw.print(" mDreamingLockscreen="); pw.print(mDreamingLockscreen);
6552 pw.print(" mDreamingSleepToken="); pw.println(mDreamingSleepToken);
Dianne Hackborn2ea9bae2012-11-02 18:43:48 -07006553 if (mLastInputMethodWindow != null) {
6554 pw.print(prefix); pw.print("mLastInputMethodWindow=");
6555 pw.println(mLastInputMethodWindow);
6556 }
6557 if (mLastInputMethodTargetWindow != null) {
6558 pw.print(prefix); pw.print("mLastInputMethodTargetWindow=");
6559 pw.println(mLastInputMethodTargetWindow);
6560 }
6561 if (mStatusBar != null) {
6562 pw.print(prefix); pw.print("mStatusBar=");
Dianne Hackbornae6688b2015-02-11 17:02:41 -08006563 pw.print(mStatusBar); pw.print(" isStatusBarKeyguard=");
6564 pw.println(isStatusBarKeyguard());
Dianne Hackborn2ea9bae2012-11-02 18:43:48 -07006565 }
6566 if (mNavigationBar != null) {
6567 pw.print(prefix); pw.print("mNavigationBar=");
6568 pw.println(mNavigationBar);
6569 }
Dianne Hackborn2ea9bae2012-11-02 18:43:48 -07006570 if (mFocusedWindow != null) {
6571 pw.print(prefix); pw.print("mFocusedWindow=");
6572 pw.println(mFocusedWindow);
6573 }
6574 if (mFocusedApp != null) {
6575 pw.print(prefix); pw.print("mFocusedApp=");
6576 pw.println(mFocusedApp);
6577 }
6578 if (mWinDismissingKeyguard != null) {
6579 pw.print(prefix); pw.print("mWinDismissingKeyguard=");
6580 pw.println(mWinDismissingKeyguard);
6581 }
6582 if (mTopFullscreenOpaqueWindowState != null) {
6583 pw.print(prefix); pw.print("mTopFullscreenOpaqueWindowState=");
6584 pw.println(mTopFullscreenOpaqueWindowState);
6585 }
Adrian Rooscd3884d2015-02-18 17:25:23 +01006586 if (mTopFullscreenOpaqueOrDimmingWindowState != null) {
6587 pw.print(prefix); pw.print("mTopFullscreenOpaqueOrDimmingWindowState=");
6588 pw.println(mTopFullscreenOpaqueOrDimmingWindowState);
6589 }
Dianne Hackborn891d3fb2013-01-09 18:31:37 -08006590 if (mForcingShowNavBar) {
6591 pw.print(prefix); pw.print("mForcingShowNavBar=");
6592 pw.println(mForcingShowNavBar); pw.print( "mForcingShowNavBarLayer=");
6593 pw.println(mForcingShowNavBarLayer);
6594 }
Dianne Hackborn7ad44382012-10-18 17:46:00 -07006595 pw.print(prefix); pw.print("mTopIsFullscreen="); pw.print(mTopIsFullscreen);
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08006596 pw.print(" mHideLockScreen="); pw.println(mHideLockScreen);
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07006597 pw.print(prefix); pw.print("mForceStatusBar="); pw.print(mForceStatusBar);
6598 pw.print(" mForceStatusBarFromKeyguard=");
6599 pw.println(mForceStatusBarFromKeyguard);
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08006600 pw.print(prefix); pw.print("mDismissKeyguard="); pw.print(mDismissKeyguard);
Craig Mautnerad09bcc2012-10-08 13:33:11 -07006601 pw.print(" mWinDismissingKeyguard="); pw.print(mWinDismissingKeyguard);
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08006602 pw.print(" mHomePressed="); pw.println(mHomePressed);
6603 pw.print(prefix); pw.print("mAllowLockscreenWhenOn="); pw.print(mAllowLockscreenWhenOn);
6604 pw.print(" mLockScreenTimeout="); pw.print(mLockScreenTimeout);
6605 pw.print(" mLockScreenTimerActive="); pw.println(mLockScreenTimerActive);
6606 pw.print(prefix); pw.print("mEndcallBehavior="); pw.print(mEndcallBehavior);
6607 pw.print(" mIncallPowerBehavior="); pw.print(mIncallPowerBehavior);
6608 pw.print(" mLongPressOnHomeBehavior="); pw.println(mLongPressOnHomeBehavior);
6609 pw.print(prefix); pw.print("mLandscapeRotation="); pw.print(mLandscapeRotation);
6610 pw.print(" mSeascapeRotation="); pw.println(mSeascapeRotation);
6611 pw.print(prefix); pw.print("mPortraitRotation="); pw.print(mPortraitRotation);
6612 pw.print(" mUpsideDownRotation="); pw.println(mUpsideDownRotation);
Jeff Brownc82c89ed2013-04-17 17:18:15 -07006613 pw.print(prefix); pw.print("mDemoHdmiRotation="); pw.print(mDemoHdmiRotation);
6614 pw.print(" mDemoHdmiRotationLock="); pw.println(mDemoHdmiRotationLock);
6615 pw.print(prefix); pw.print("mUndockedHdmiRotation="); pw.println(mUndockedHdmiRotation);
Jeff Brown600f0032014-05-22 17:06:00 -07006616
Tim Kilbournd7c0c2e2014-05-29 16:08:10 -07006617 mGlobalKeyManager.dump(prefix, pw);
John Spurlock27735a42013-08-14 17:57:38 -04006618 mStatusBarController.dump(pw, prefix);
6619 mNavigationBarController.dump(pw, prefix);
John Spurlockc6d1c602014-01-17 15:22:06 -05006620 PolicyControl.dump(prefix, pw);
Jeff Brown600f0032014-05-22 17:06:00 -07006621
Jeff Browna20dda42014-05-27 20:57:24 -07006622 if (mWakeGestureListener != null) {
6623 mWakeGestureListener.dump(pw, prefix);
6624 }
Jeff Brown600f0032014-05-22 17:06:00 -07006625 if (mOrientationListener != null) {
6626 mOrientationListener.dump(pw, prefix);
6627 }
Filip Gruszczynskicfb31852015-02-25 21:47:12 +00006628 if (mBurnInProtectionHelper != null) {
6629 mBurnInProtectionHelper.dump(prefix, pw);
6630 }
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08006631 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006632}