blob: 5536d4dd5f19bd30fdf0ba44092f50f3e09cfda1 [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
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800288 /** If true, hitting shift & menu will broadcast Intent.ACTION_BUG_REPORT */
289 boolean mEnableShiftMenuBugReports = false;
Mike Lockwoodd747dc82011-09-13 16:28:22 -0400290
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800291 boolean mSafeMode;
292 WindowState mStatusBar = null;
Dianne Hackborn69cb8752011-05-19 18:13:32 -0700293 int mStatusBarHeight;
Daniel Sandler8956dbb2011-04-22 07:55:02 -0400294 WindowState mNavigationBar = null;
Daniel Sandler36412a72011-08-04 09:35:13 -0400295 boolean mHasNavigationBar = false;
Dianne Hackbornf87d1962012-04-04 12:48:24 -0700296 boolean mCanHideNavigationBar = false;
Daniel Sandler4a066c52012-04-20 14:49:13 -0400297 boolean mNavigationBarCanMove = false; // can the navigation bar ever move to the side?
298 boolean mNavigationBarOnBottom = true; // is the navigation bar on the bottom *right now*?
299 int[] mNavigationBarHeightForRotation = new int[4];
300 int[] mNavigationBarWidthForRotation = new int[4];
Daniel Sandler8956dbb2011-04-22 07:55:02 -0400301
Craig Mautnera631d492014-08-05 15:16:01 -0700302 boolean mBootMessageNeedsHiding;
Jim Miller5ecd8112013-01-09 18:50:26 -0800303 KeyguardServiceDelegate mKeyguardDelegate;
Craig Mautner13f6ea72014-06-23 14:57:02 -0700304 final Runnable mWindowManagerDrawCallback = new Runnable() {
Craig Mautner8a0da012014-05-31 15:13:37 -0700305 @Override
Craig Mautner13f6ea72014-06-23 14:57:02 -0700306 public void run() {
Craig Mautner8a0da012014-05-31 15:13:37 -0700307 if (DEBUG_WAKEUP) Slog.i(TAG, "All windows ready for display!");
308 mHandler.sendEmptyMessage(MSG_WINDOW_MANAGER_DRAWN_COMPLETE);
309 }
310 };
311 final ShowListener mKeyguardDelegateCallback = new ShowListener() {
312 @Override
313 public void onShown(IBinder windowToken) {
314 if (DEBUG_WAKEUP) Slog.d(TAG, "mKeyguardDelegate.ShowListener.onShown.");
315 mHandler.sendEmptyMessage(MSG_KEYGUARD_DRAWN_COMPLETE);
316 }
317 };
318
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800319 GlobalActions mGlobalActions;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800320 Handler mHandler;
satok1bc0a492012-04-25 22:47:12 +0900321 WindowState mLastInputMethodWindow = null;
322 WindowState mLastInputMethodTargetWindow = null;
Jeff Brown4aed78b2011-01-14 17:36:55 -0800323
Jeff Brown13f00f02014-10-31 14:45:50 -0700324 // FIXME This state is shared between the input reader and handler thread.
325 // Technically it's broken and buggy but it has been like this for many years
326 // and we have not yet seen any problems. Someday we'll rewrite this logic
327 // so that only one thread is involved in handling input policy. Unfortunately
328 // it's on a critical path for power management so we can't just post the work to the
329 // handler thread. We'll need to resolve this someday by teaching the input dispatcher
330 // to hold wakelocks during dispatch and eliminating the critical path.
331 volatile boolean mPowerKeyHandled;
Bryce Leed9268e32014-11-17 17:40:59 -0800332 volatile boolean mBeganFromNonInteractive;
Jeff Brown13f00f02014-10-31 14:45:50 -0700333 volatile int mPowerKeyPressCounter;
334 volatile boolean mEndCallKeyHandled;
335
Winson Chungd42a6cf2014-06-03 16:24:04 -0700336 boolean mRecentsVisible;
Winson Chung1e8d71b2014-05-16 17:05:22 -0700337 int mRecentAppsHeldModifiers;
Jeff Browncf39bdf2012-05-18 14:41:19 -0700338 boolean mLanguageSwitchKeyPressed;
Jeff Brown68b909d2011-12-07 16:36:01 -0800339
Jeff Brown2e7760e2012-04-11 15:14:55 -0700340 int mLidState = LID_ABSENT;
Michael Wright3818c922014-09-02 13:59:07 -0700341 int mCameraLensCoverState = CAMERA_LENS_COVER_ABSENT;
Jeff Browndaa37532012-05-01 15:54:03 -0700342 boolean mHaveBuiltInKeyboard;
Jeff Brown4aed78b2011-01-14 17:36:55 -0800343
Dianne Hackbornc777e072010-02-12 13:07:59 -0800344 boolean mSystemReady;
Dianne Hackbornba24e4d2011-09-01 11:17:06 -0700345 boolean mSystemBooted;
Dianne Hackbornad7fa7f2011-01-07 14:06:50 -0800346 boolean mHdmiPlugged;
Jeff Brown4f5fa282014-06-12 19:19:15 -0700347 IUiModeManager mUiModeManager;
Daniel Sandler6396c722013-04-16 20:19:09 -0400348 int mUiMode;
Dianne Hackborn867ab6472010-04-29 13:28:56 -0700349 int mDockMode = Intent.EXTRA_DOCK_STATE_UNDOCKED;
Mike Lockwood1753f7f2009-08-24 14:49:07 -0700350 int mLidOpenRotation;
Mike Lockwood2d1efbd2009-09-16 12:15:53 -0400351 int mCarDockRotation;
352 int mDeskDockRotation;
Jeff Brownc82c89ed2013-04-17 17:18:15 -0700353 int mUndockedHdmiRotation;
354 int mDemoHdmiRotation;
355 boolean mDemoHdmiRotationLock;
Chong Zhangae6119ff2014-11-11 18:54:39 -0800356 int mDemoRotation;
357 boolean mDemoRotationLock;
Daniel Sandlerb73617d2010-08-17 00:41:00 -0400358
Jeff Browna20dda42014-05-27 20:57:24 -0700359 boolean mWakeGestureEnabledSetting;
360 MyWakeGestureListener mWakeGestureListener;
361
Craig Mautner46ac6fa2013-08-01 10:06:34 -0700362 // Default display does not rotate, apps that require non-default orientation will have to
363 // have the orientation emulated.
364 private boolean mForceDefaultOrientation = false;
365
Daniel Sandlerb73617d2010-08-17 00:41:00 -0400366 int mUserRotationMode = WindowManagerPolicy.USER_ROTATION_FREE;
367 int mUserRotation = Surface.ROTATION_0;
Jeff Brown207673cd2012-06-05 17:47:11 -0700368 boolean mAccelerometerDefault;
Daniel Sandlerb73617d2010-08-17 00:41:00 -0400369
Jeff Brownbcdfc622014-03-06 19:13:04 -0800370 boolean mSupportAutoRotation;
Jeff Brownd3187e32011-09-21 19:26:44 -0700371 int mAllowAllRotations = -1;
Mike Lockwoode9867d22009-09-20 01:59:02 -0400372 boolean mCarDockEnablesAccelerometer;
373 boolean mDeskDockEnablesAccelerometer;
Dianne Hackborn2862fff2009-09-15 22:56:29 -0700374 int mLidKeyboardAccessibility;
375 int mLidNavigationAccessibility;
Jeff Brownc458ce92012-04-30 14:58:40 -0700376 boolean mLidControlsSleep;
Jeff Brown13f00f02014-10-31 14:45:50 -0700377 int mShortPressOnPowerBehavior;
378 int mLongPressOnPowerBehavior;
379 int mDoublePressOnPowerBehavior;
380 int mTriplePressOnPowerBehavior;
Filip Gruszczynskia483a1d2015-03-17 19:06:58 +0000381 int mShortPressOnSleepBehavior;
Jeff Brown3ee549c2014-09-22 20:14:39 -0700382 boolean mAwake;
383 boolean mScreenOnEarly;
384 boolean mScreenOnFully;
385 ScreenOnListener mScreenOnListener;
386 boolean mKeyguardDrawComplete;
387 boolean mWindowManagerDrawComplete;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800388 boolean mOrientationSensorEnabled = false;
389 int mCurrentAppOrientation = ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800390 boolean mHasSoftInput = false;
Daniel Sandlerdd73ee42013-10-11 22:19:59 -0400391 boolean mTranslucentDecorEnabled = true;
RoboErik001c59c2015-01-26 15:53:51 -0800392 boolean mUseTvRouting;
Craig Mautner967212c2013-04-13 21:10:58 -0700393
Jeff Brown70825162012-03-28 17:27:48 -0700394 int mPointerLocationMode = 0; // guarded by mLock
Joe Onorato664644d2011-01-23 17:53:23 -0800395
396 // The last window we were told about in focusChanged.
397 WindowState mFocusedWindow;
Dianne Hackborne0f085d2011-11-30 18:41:15 -0800398 IApplicationToken mFocusedApp;
Joe Onorato664644d2011-01-23 17:53:23 -0800399
Jeff Brown70825162012-03-28 17:27:48 -0700400 PointerLocationView mPointerLocationView;
Jeff Brown32cbc38552011-12-01 14:01:49 -0800401
Dianne Hackbornc652de82013-02-15 16:32:56 -0800402 // The current size of the screen; really; extends into the overscan area of
403 // the screen and doesn't account for any system elements like the status bar.
404 int mOverscanScreenLeft, mOverscanScreenTop;
405 int mOverscanScreenWidth, mOverscanScreenHeight;
406 // The current visible size of the screen; really; (ir)regardless of whether the status
407 // bar can be hidden but not extending into the overscan area.
Joe Onorato29fc2c92010-11-24 10:26:50 -0800408 int mUnrestrictedScreenLeft, mUnrestrictedScreenTop;
409 int mUnrestrictedScreenWidth, mUnrestrictedScreenHeight;
Dianne Hackborn313440842013-02-19 19:22:59 -0800410 // Like mOverscanScreen*, but allowed to move into the overscan region where appropriate.
411 int mRestrictedOverscanScreenLeft, mRestrictedOverscanScreenTop;
412 int mRestrictedOverscanScreenWidth, mRestrictedOverscanScreenHeight;
Dianne Hackborn82de1ae2010-10-28 11:28:39 -0700413 // The current size of the screen; these may be different than (0,0)-(dw,dh)
414 // if the status bar can't be hidden; in that case it effectively carves out
415 // that area of the display from all other windows.
Joe Onorato29fc2c92010-11-24 10:26:50 -0800416 int mRestrictedScreenLeft, mRestrictedScreenTop;
417 int mRestrictedScreenWidth, mRestrictedScreenHeight;
Dianne Hackborn5c58de32012-04-28 19:52:37 -0700418 // During layout, the current screen borders accounting for any currently
419 // visible system UI elements.
420 int mSystemLeft, mSystemTop, mSystemRight, mSystemBottom;
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -0700421 // For applications requesting stable content insets, these are them.
422 int mStableLeft, mStableTop, mStableRight, mStableBottom;
Dianne Hackborn5b5cc4d2012-05-16 13:15:00 -0700423 // For applications requesting stable content insets but have also set the
424 // fullscreen window flag, these are the stable dimensions without the status bar.
425 int mStableFullscreenLeft, mStableFullscreenTop;
426 int mStableFullscreenRight, mStableFullscreenBottom;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800427 // During layout, the current screen borders with all outer decoration
428 // (status bar, input method dock) accounted for.
429 int mCurLeft, mCurTop, mCurRight, mCurBottom;
430 // During layout, the frame in which content should be displayed
431 // to the user, accounting for all screen decoration except for any
432 // space they deem as available for other content. This is usually
433 // the same as mCur*, but may be larger if the screen decor has supplied
434 // content insets.
435 int mContentLeft, mContentTop, mContentRight, mContentBottom;
Dianne Hackborne30e02f2014-05-27 18:24:45 -0700436 // During layout, the frame in which voice content should be displayed
437 // to the user, accounting for all screen decoration except for any
438 // space they deem as available for other content.
439 int mVoiceContentLeft, mVoiceContentTop, mVoiceContentRight, mVoiceContentBottom;
Dianne Hackborn8e11ef02010-11-18 19:47:42 -0800440 // During layout, the current screen borders along which input method
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800441 // windows are placed.
442 int mDockLeft, mDockTop, mDockRight, mDockBottom;
443 // During layout, the layer at which the doc window is placed.
444 int mDockLayer;
Dianne Hackborn5c58de32012-04-28 19:52:37 -0700445 // During layout, this is the layer of the status bar.
446 int mStatusBarLayer;
Dianne Hackborne26ab702011-10-16 13:21:33 -0700447 int mLastSystemUiFlags;
448 // Bits that we are in the process of clearing, so we want to prevent
449 // them from being set by applications until everything has been updated
450 // to have them clear.
451 int mResettingSystemUiFlags = 0;
452 // Bits that we are currently always keeping cleared.
453 int mForceClearedSystemUiFlags = 0;
Dianne Hackborn4eff8d32011-11-10 19:38:40 -0800454 // What we last reported to system UI about whether the compatibility
455 // menu needs to be displayed.
456 boolean mLastFocusNeedsMenu = false;
Dianne Hackborndf89e652011-10-06 22:35:11 -0700457
458 FakeWindow mHideNavFakeWindow = null;
459
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800460 static final Rect mTmpParentFrame = new Rect();
461 static final Rect mTmpDisplayFrame = new Rect();
Dianne Hackbornc4aad012013-02-22 15:05:25 -0800462 static final Rect mTmpOverscanFrame = new Rect();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800463 static final Rect mTmpContentFrame = new Rect();
464 static final Rect mTmpVisibleFrame = new Rect();
John Spurlock46646232013-09-30 22:32:42 -0400465 static final Rect mTmpDecorFrame = new Rect();
Adrian Roosfa104232014-06-20 16:10:14 -0700466 static final Rect mTmpStableFrame = new Rect();
Dianne Hackborn1f903c32011-09-13 19:18:06 -0700467 static final Rect mTmpNavigationFrame = new Rect();
Craig Mautner967212c2013-04-13 21:10:58 -0700468
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800469 WindowState mTopFullscreenOpaqueWindowState;
Adrian Rooscd3884d2015-02-18 17:25:23 +0100470 WindowState mTopFullscreenOpaqueOrDimmingWindowState;
Craig Mautner2bc789b2014-03-19 19:48:38 -0700471 HashSet<IApplicationToken> mAppsToBeHidden = new HashSet<IApplicationToken>();
Jorim Jaggic13fcac2014-09-11 17:36:57 +0200472 HashSet<IApplicationToken> mAppsThatDismissKeyguard = new HashSet<IApplicationToken>();
Joe Onorato93056472010-09-10 10:30:46 -0400473 boolean mTopIsFullscreen;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800474 boolean mForceStatusBar;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -0700475 boolean mForceStatusBarFromKeyguard;
Dianne Hackborn39c2d712009-09-22 11:41:31 -0700476 boolean mHideLockScreen;
Dianne Hackborn891d3fb2013-01-09 18:31:37 -0800477 boolean mForcingShowNavBar;
478 int mForcingShowNavBarLayer;
Craig Mautnerad09bcc2012-10-08 13:33:11 -0700479
480 // States of keyguard dismiss.
481 private static final int DISMISS_KEYGUARD_NONE = 0; // Keyguard not being dismissed.
482 private static final int DISMISS_KEYGUARD_START = 1; // Keyguard needs to be dismissed.
483 private static final int DISMISS_KEYGUARD_CONTINUE = 2; // Keyguard has been dismissed.
484 int mDismissKeyguard = DISMISS_KEYGUARD_NONE;
485
486 /** The window that is currently dismissing the keyguard. Dismissing the keyguard must only
487 * be done once per window. */
488 private WindowState mWinDismissingKeyguard;
489
Craig Mautnerc9457fa2014-06-06 14:27:48 -0700490 /** The window that is currently showing "over" the keyguard. If there is an app window
491 * belonging to another app on top of this the keyguard shows. If there is a fullscreen
492 * app window under this, still dismiss the keyguard but don't show the app underneath. Show
493 * the wallpaper. */
494 private WindowState mWinShowWhenLocked;
495
Dianne Hackborn7ad44382012-10-18 17:46:00 -0700496 boolean mShowingLockscreen;
497 boolean mShowingDream;
498 boolean mDreamingLockscreen;
Jeff Brown061ea992015-04-17 19:55:47 -0700499 boolean mDreamingSleepTokenNeeded;
500 SleepToken mDreamingSleepToken;
Jim Millerab954542014-10-10 18:21:49 -0700501 boolean mKeyguardSecure;
502 boolean mKeyguardSecureIncludingHidden;
503 volatile boolean mKeyguardOccluded;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800504 boolean mHomePressed;
Jeff Browncaca8812013-05-09 13:34:33 -0700505 boolean mHomeConsumed;
506 boolean mHomeDoubleTapPending;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800507 Intent mHomeIntent;
Dianne Hackborn39c2d712009-09-22 11:41:31 -0700508 Intent mCarDockIntent;
509 Intent mDeskDockIntent;
Jeff Brownfd23e3e2012-05-09 13:34:28 -0700510 boolean mSearchKeyShortcutPending;
511 boolean mConsumeSearchKeyUp;
Jeff Brownde7a8ea2012-06-13 18:28:57 -0700512 boolean mAssistKeyLongPressed;
Michael Wright6a62e552014-06-03 19:19:48 -0700513 boolean mPendingMetaAction;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800514
Mike Lockwood28569302010-01-28 11:54:40 -0500515 // support for activating the lock screen while the screen is on
516 boolean mAllowLockscreenWhenOn;
517 int mLockScreenTimeout;
518 boolean mLockScreenTimerActive;
519
David Brownbaf8d092010-03-08 21:52:59 -0800520 // Behavior of ENDCALL Button. (See Settings.System.END_BUTTON_BEHAVIOR.)
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800521 int mEndcallBehavior;
David Brownbaf8d092010-03-08 21:52:59 -0800522
523 // Behavior of POWER button while in-call and screen on.
524 // (See Settings.Secure.INCALL_POWER_BUTTON_BEHAVIOR.)
525 int mIncallPowerBehavior;
526
Dianne Hackbornf87d1962012-04-04 12:48:24 -0700527 Display mDisplay;
528
Dianne Hackborn9d132642011-04-21 17:26:39 -0700529 int mLandscapeRotation = 0; // default landscape rotation
530 int mSeascapeRotation = 0; // "other" landscape rotation, 180 degrees from mLandscapeRotation
531 int mPortraitRotation = 0; // default portrait rotation
532 int mUpsideDownRotation = 0; // "other" portrait rotation
Mitsuru Oshima831d0d92009-06-16 18:27:18 -0700533
Dianne Hackbornc652de82013-02-15 16:32:56 -0800534 int mOverscanLeft = 0;
535 int mOverscanTop = 0;
536 int mOverscanRight = 0;
537 int mOverscanBottom = 0;
538
Joe Onorato46b0d682010-11-22 17:37:27 -0800539 // What we do when the user long presses on home
Jeff Browncaca8812013-05-09 13:34:33 -0700540 private int mLongPressOnHomeBehavior;
541
542 // What we do when the user double-taps on home
543 private int mDoubleTapOnHomeBehavior;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800544
Bryce Lee584a4452014-10-21 15:55:55 -0700545 // Allowed theater mode wake actions
546 private boolean mAllowTheaterModeWakeFromKey;
547 private boolean mAllowTheaterModeWakeFromPowerKey;
548 private boolean mAllowTheaterModeWakeFromMotion;
Bryce Lee812d7022014-11-10 13:33:28 -0800549 private boolean mAllowTheaterModeWakeFromMotionWhenNotDreaming;
Bryce Lee584a4452014-10-21 15:55:55 -0700550 private boolean mAllowTheaterModeWakeFromCameraLens;
551 private boolean mAllowTheaterModeWakeFromLidSwitch;
552 private boolean mAllowTheaterModeWakeFromWakeGesture;
553
Bryce Leed3b28402015-03-09 15:49:13 +0000554 // Whether to support long press from power button in non-interactive mode
555 private boolean mSupportLongPressPowerWhenNonInteractive;
556
Bryce Lee55e846d2014-11-04 12:43:44 -0800557 // Whether to go to sleep entering theater mode from power button
558 private boolean mGoToSleepOnButtonPressTheaterMode;
559
Winson Chung9112ec32011-06-27 13:15:32 -0700560 // Screenshot trigger states
Jeff Brownd5bb82d2011-10-12 13:57:59 -0700561 // Time to volume and power must be pressed within this interval of each other.
562 private static final long SCREENSHOT_CHORD_DEBOUNCE_DELAY_MILLIS = 150;
Winson Chung1cea2f32012-10-08 20:42:01 -0700563 // Increase the chord delay when taking a screenshot from the keyguard
564 private static final float KEYGUARD_SCREENSHOT_CHORD_DELAY_MULTIPLIER = 2.5f;
Christopher Tatee90585f2012-03-05 18:56:25 -0800565 private boolean mScreenshotChordEnabled;
Jeff Brown13f00f02014-10-31 14:45:50 -0700566 private boolean mScreenshotChordVolumeDownKeyTriggered;
567 private long mScreenshotChordVolumeDownKeyTime;
568 private boolean mScreenshotChordVolumeDownKeyConsumed;
569 private boolean mScreenshotChordVolumeUpKeyTriggered;
570 private boolean mScreenshotChordPowerKeyTriggered;
571 private long mScreenshotChordPowerKeyTime;
Winson Chung9112ec32011-06-27 13:15:32 -0700572
Michael Wrightb854e242013-02-05 17:54:02 -0800573 /* The number of steps between min and max brightness */
574 private static final int BRIGHTNESS_STEPS = 10;
575
Christopher Tate5e08af02012-09-21 17:17:22 -0700576 SettingsObserver mSettingsObserver;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800577 ShortcutManager mShortcutManager;
578 PowerManager.WakeLock mBroadcastWakeLock;
Jeff Brown13f00f02014-10-31 14:45:50 -0700579 PowerManager.WakeLock mPowerKeyWakeLock;
Jeff Brown40013652012-05-16 21:22:36 -0700580 boolean mHavePendingMediaKeyRepeatWithWakeLock;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800581
Craig Mautnerd625ab22013-09-06 13:40:31 -0700582 private int mCurrentUserId;
583
Justin Kohd378ad72013-04-01 12:18:26 -0700584 // Maps global key codes to the components that will handle them.
585 private GlobalKeyManager mGlobalKeyManager;
586
Jeff Brownfd23e3e2012-05-09 13:34:28 -0700587 // Fallback actions by key code.
588 private final SparseArray<KeyCharacterMap.FallbackAction> mFallbackActions =
589 new SparseArray<KeyCharacterMap.FallbackAction>();
Jeff Brown49ed71d2010-12-06 17:13:33 -0800590
Jorim Jaggi76a16232014-08-08 17:00:47 +0200591 private final LogDecelerateInterpolator mLogDecelerateInterpolator
592 = new LogDecelerateInterpolator(100, 0);
593
Jeff Brown70825162012-03-28 17:27:48 -0700594 private static final int MSG_ENABLE_POINTER_LOCATION = 1;
595 private static final int MSG_DISABLE_POINTER_LOCATION = 2;
Jeff Brown40013652012-05-16 21:22:36 -0700596 private static final int MSG_DISPATCH_MEDIA_KEY_WITH_WAKE_LOCK = 3;
597 private static final int MSG_DISPATCH_MEDIA_KEY_REPEAT_WITH_WAKE_LOCK = 4;
Craig Mautner8a0da012014-05-31 15:13:37 -0700598 private static final int MSG_KEYGUARD_DRAWN_COMPLETE = 5;
599 private static final int MSG_KEYGUARD_DRAWN_TIMEOUT = 6;
600 private static final int MSG_WINDOW_MANAGER_DRAWN_COMPLETE = 7;
Craig Mautner84984fa2014-06-19 11:19:20 -0700601 private static final int MSG_DISPATCH_SHOW_RECENTS = 9;
Alan Viverettee34560b22014-07-10 14:50:06 -0700602 private static final int MSG_DISPATCH_SHOW_GLOBAL_ACTIONS = 10;
Craig Mautnera631d492014-08-05 15:16:01 -0700603 private static final int MSG_HIDE_BOOT_MESSAGE = 11;
Michael Wright869a67c2014-08-26 19:33:06 -0700604 private static final int MSG_LAUNCH_VOICE_ASSIST_WITH_WAKE_LOCK = 12;
Jeff Brown13f00f02014-10-31 14:45:50 -0700605 private static final int MSG_POWER_DELAYED_PRESS = 13;
606 private static final int MSG_POWER_LONG_PRESS = 14;
Jeff Brown061ea992015-04-17 19:55:47 -0700607 private static final int MSG_UPDATE_DREAMING_SLEEP_TOKEN = 15;
Jeff Brown70825162012-03-28 17:27:48 -0700608
609 private class PolicyHandler extends Handler {
610 @Override
611 public void handleMessage(Message msg) {
612 switch (msg.what) {
613 case MSG_ENABLE_POINTER_LOCATION:
614 enablePointerLocation();
615 break;
616 case MSG_DISABLE_POINTER_LOCATION:
617 disablePointerLocation();
618 break;
Jeff Brown40013652012-05-16 21:22:36 -0700619 case MSG_DISPATCH_MEDIA_KEY_WITH_WAKE_LOCK:
620 dispatchMediaKeyWithWakeLock((KeyEvent)msg.obj);
621 break;
622 case MSG_DISPATCH_MEDIA_KEY_REPEAT_WITH_WAKE_LOCK:
623 dispatchMediaKeyRepeatWithWakeLock((KeyEvent)msg.obj);
624 break;
Craig Mautner84984fa2014-06-19 11:19:20 -0700625 case MSG_DISPATCH_SHOW_RECENTS:
626 showRecentApps(false);
627 break;
Alan Viverettee34560b22014-07-10 14:50:06 -0700628 case MSG_DISPATCH_SHOW_GLOBAL_ACTIONS:
629 showGlobalActionsInternal();
630 break;
Craig Mautner8a0da012014-05-31 15:13:37 -0700631 case MSG_KEYGUARD_DRAWN_COMPLETE:
632 if (DEBUG_WAKEUP) Slog.w(TAG, "Setting mKeyguardDrawComplete");
Jeff Brown36c4db82014-09-19 12:05:31 -0700633 finishKeyguardDrawn();
Craig Mautner8a0da012014-05-31 15:13:37 -0700634 break;
635 case MSG_KEYGUARD_DRAWN_TIMEOUT:
636 Slog.w(TAG, "Keyguard drawn timeout. Setting mKeyguardDrawComplete");
Jeff Brown36c4db82014-09-19 12:05:31 -0700637 finishKeyguardDrawn();
Craig Mautner8a0da012014-05-31 15:13:37 -0700638 break;
639 case MSG_WINDOW_MANAGER_DRAWN_COMPLETE:
640 if (DEBUG_WAKEUP) Slog.w(TAG, "Setting mWindowManagerDrawComplete");
Jeff Brown36c4db82014-09-19 12:05:31 -0700641 finishWindowsDrawn();
Craig Mautner8a0da012014-05-31 15:13:37 -0700642 break;
Craig Mautnera631d492014-08-05 15:16:01 -0700643 case MSG_HIDE_BOOT_MESSAGE:
644 handleHideBootMessage();
645 break;
Michael Wright869a67c2014-08-26 19:33:06 -0700646 case MSG_LAUNCH_VOICE_ASSIST_WITH_WAKE_LOCK:
647 launchVoiceAssistWithWakeLock(msg.arg1 != 0);
648 break;
Jeff Brown13f00f02014-10-31 14:45:50 -0700649 case MSG_POWER_DELAYED_PRESS:
650 powerPress((Long)msg.obj, msg.arg1 != 0, msg.arg2);
651 finishPowerKeyPress();
652 break;
653 case MSG_POWER_LONG_PRESS:
654 powerLongPress();
655 break;
Jeff Brown061ea992015-04-17 19:55:47 -0700656 case MSG_UPDATE_DREAMING_SLEEP_TOKEN:
657 updateDreamingSleepToken(msg.arg1 != 0);
658 break;
Jeff Brown70825162012-03-28 17:27:48 -0700659 }
660 }
661 }
662
Dianne Hackbornad7fa7f2011-01-07 14:06:50 -0800663 private UEventObserver mHDMIObserver = new UEventObserver() {
664 @Override
665 public void onUEvent(UEventObserver.UEvent event) {
666 setHdmiPlugged("1".equals(event.get("SWITCH_STATE")));
667 }
668 };
669
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800670 class SettingsObserver extends ContentObserver {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800671 SettingsObserver(Handler handler) {
672 super(handler);
673 }
David Brownbaf8d092010-03-08 21:52:59 -0800674
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800675 void observe() {
Christopher Tate5e08af02012-09-21 17:17:22 -0700676 // Observe all users' changes
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800677 ContentResolver resolver = mContext.getContentResolver();
678 resolver.registerContentObserver(Settings.System.getUriFor(
Christopher Tate5e08af02012-09-21 17:17:22 -0700679 Settings.System.END_BUTTON_BEHAVIOR), false, this,
680 UserHandle.USER_ALL);
David Brownbaf8d092010-03-08 21:52:59 -0800681 resolver.registerContentObserver(Settings.Secure.getUriFor(
Christopher Tate5e08af02012-09-21 17:17:22 -0700682 Settings.Secure.INCALL_POWER_BUTTON_BEHAVIOR), false, this,
683 UserHandle.USER_ALL);
Jeff Browna20dda42014-05-27 20:57:24 -0700684 resolver.registerContentObserver(Settings.Secure.getUriFor(
685 Settings.Secure.WAKE_GESTURE_ENABLED), false, this,
686 UserHandle.USER_ALL);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800687 resolver.registerContentObserver(Settings.System.getUriFor(
Christopher Tate5e08af02012-09-21 17:17:22 -0700688 Settings.System.ACCELEROMETER_ROTATION), false, this,
689 UserHandle.USER_ALL);
Mike Lockwood28569302010-01-28 11:54:40 -0500690 resolver.registerContentObserver(Settings.System.getUriFor(
Christopher Tate5e08af02012-09-21 17:17:22 -0700691 Settings.System.USER_ROTATION), false, this,
692 UserHandle.USER_ALL);
Daniel Sandlerb73617d2010-08-17 00:41:00 -0400693 resolver.registerContentObserver(Settings.System.getUriFor(
Christopher Tate5e08af02012-09-21 17:17:22 -0700694 Settings.System.SCREEN_OFF_TIMEOUT), false, this,
695 UserHandle.USER_ALL);
Dianne Hackbornc777e072010-02-12 13:07:59 -0800696 resolver.registerContentObserver(Settings.System.getUriFor(
Christopher Tate5e08af02012-09-21 17:17:22 -0700697 Settings.System.POINTER_LOCATION), false, this,
698 UserHandle.USER_ALL);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800699 resolver.registerContentObserver(Settings.Secure.getUriFor(
Christopher Tate5e08af02012-09-21 17:17:22 -0700700 Settings.Secure.DEFAULT_INPUT_METHOD), false, this,
701 UserHandle.USER_ALL);
John Spurlockd9b70bd2014-02-06 17:02:44 -0500702 resolver.registerContentObserver(Settings.Secure.getUriFor(
John Spurlockf1a36642013-10-12 17:50:42 -0400703 Settings.Secure.IMMERSIVE_MODE_CONFIRMATIONS), false, this,
Christopher Tate5e08af02012-09-21 17:17:22 -0700704 UserHandle.USER_ALL);
John Spurlockc6d1c602014-01-17 15:22:06 -0500705 resolver.registerContentObserver(Settings.Global.getUriFor(
706 Settings.Global.POLICY_CONTROL), false, this,
707 UserHandle.USER_ALL);
Dianne Hackbornc777e072010-02-12 13:07:59 -0800708 updateSettings();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800709 }
710
711 @Override public void onChange(boolean selfChange) {
Dianne Hackbornc777e072010-02-12 13:07:59 -0800712 updateSettings();
Jeff Brown01a98dd2011-09-20 15:08:29 -0700713 updateRotation(false);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800714 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800715 }
Craig Mautner967212c2013-04-13 21:10:58 -0700716
Jeff Browna20dda42014-05-27 20:57:24 -0700717 class MyWakeGestureListener extends WakeGestureListener {
718 MyWakeGestureListener(Context context, Handler handler) {
719 super(context, handler);
720 }
721
722 @Override
723 public void onWakeUp() {
724 synchronized (mLock) {
725 if (shouldEnableWakeGestureLp()) {
Jeff Browne07b94b2014-06-18 15:56:27 -0700726 performHapticFeedbackLw(null, HapticFeedbackConstants.VIRTUAL_KEY, false);
Bryce Lee584a4452014-10-21 15:55:55 -0700727 wakeUp(SystemClock.uptimeMillis(), mAllowTheaterModeWakeFromWakeGesture);
Jeff Browna20dda42014-05-27 20:57:24 -0700728 }
729 }
730 }
731 }
732
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800733 class MyOrientationListener extends WindowOrientationListener {
Craig Mautnereee29c42013-01-17 14:44:34 -0800734 MyOrientationListener(Context context, Handler handler) {
735 super(context, handler);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800736 }
Craig Mautner967212c2013-04-13 21:10:58 -0700737
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800738 @Override
Jeff Brownc0347aa2011-09-23 17:26:09 -0700739 public void onProposedRotationChanged(int rotation) {
Craig Mautnereda67292013-04-28 13:50:14 -0700740 if (localLOGV) Slog.v(TAG, "onProposedRotationChanged, rotation=" + rotation);
Jeff Brown01a98dd2011-09-20 15:08:29 -0700741 updateRotation(false);
742 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800743 }
744 MyOrientationListener mOrientationListener;
745
Jorim Jaggi24bec7c2015-02-04 12:40:14 +0100746 private final StatusBarController mStatusBarController = new StatusBarController();
John Spurlock5b9145b2013-08-20 15:13:47 -0400747
John Spurlock27735a42013-08-14 17:57:38 -0400748 private final BarController mNavigationBarController = new BarController("NavigationBar",
John Spurlock5b9145b2013-08-20 15:13:47 -0400749 View.NAVIGATION_BAR_TRANSIENT,
750 View.NAVIGATION_BAR_UNHIDE,
John Spurlockbd957402013-10-03 11:38:39 -0400751 View.NAVIGATION_BAR_TRANSLUCENT,
752 StatusBarManager.WINDOW_NAVIGATION_BAR,
753 WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION);
John Spurlock5b9145b2013-08-20 15:13:47 -0400754
John Spurlockf1a36642013-10-12 17:50:42 -0400755 private ImmersiveModeConfirmation mImmersiveModeConfirmation;
John Spurlock32beb2c2013-03-11 10:16:47 -0400756
Craig Mautner037aa8d2013-06-07 10:35:44 -0700757 private SystemGesturesPointerEventListener mSystemGestures;
John Spurlock32beb2c2013-03-11 10:16:47 -0400758
Dianne Hackborn42e620c2012-06-24 13:20:51 -0700759 IStatusBarService getStatusBarService() {
760 synchronized (mServiceAquireLock) {
761 if (mStatusBarService == null) {
762 mStatusBarService = IStatusBarService.Stub.asInterface(
763 ServiceManager.getService("statusbar"));
764 }
765 return mStatusBarService;
766 }
767 }
768
Suchi Amalapurapua9e1b162009-03-24 22:24:47 -0700769 /*
770 * We always let the sensor be switched on by default except when
771 * the user has explicitly disabled sensor based rotation or when the
772 * screen is switched off.
773 */
The Android Open Source Project0727d222009-03-11 12:11:58 -0700774 boolean needSensorRunningLp() {
Jeff Brownbcdfc622014-03-06 19:13:04 -0800775 if (mSupportAutoRotation) {
776 if (mCurrentAppOrientation == ActivityInfo.SCREEN_ORIENTATION_SENSOR
777 || mCurrentAppOrientation == ActivityInfo.SCREEN_ORIENTATION_FULL_SENSOR
778 || mCurrentAppOrientation == ActivityInfo.SCREEN_ORIENTATION_SENSOR_PORTRAIT
779 || mCurrentAppOrientation == ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE) {
780 // If the application has explicitly requested to follow the
781 // orientation, then we need to turn the sensor on.
782 return true;
783 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800784 }
Dianne Hackborn867ab6472010-04-29 13:28:56 -0700785 if ((mCarDockEnablesAccelerometer && mDockMode == Intent.EXTRA_DOCK_STATE_CAR) ||
Jeff Brown1a693182011-11-08 14:44:16 -0800786 (mDeskDockEnablesAccelerometer && (mDockMode == Intent.EXTRA_DOCK_STATE_DESK
787 || mDockMode == Intent.EXTRA_DOCK_STATE_LE_DESK
788 || mDockMode == Intent.EXTRA_DOCK_STATE_HE_DESK))) {
Mike Lockwoode9867d22009-09-20 01:59:02 -0400789 // enable accelerometer if we are docked in a dock that enables accelerometer
790 // orientation management,
791 return true;
792 }
Jeff Brown207673cd2012-06-05 17:47:11 -0700793 if (mUserRotationMode == USER_ROTATION_LOCKED) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800794 // If the setting for using the sensor by default is enabled, then
795 // we will always leave it on. Note that the user could go to
796 // a window that forces an orientation that does not use the
797 // sensor and in theory we could turn it off... however, when next
798 // turning it on we won't have a good value for the current
799 // orientation for a little bit, which can cause orientation
800 // changes to lag, so we'd like to keep it always on. (It will
801 // still be turned off when the screen is off.)
Suchi Amalapurapua9e1b162009-03-24 22:24:47 -0700802 return false;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800803 }
Jeff Brownbcdfc622014-03-06 19:13:04 -0800804 return mSupportAutoRotation;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800805 }
Craig Mautner46ac6fa2013-08-01 10:06:34 -0700806
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800807 /*
808 * Various use cases for invoking this function
809 * screen turning off, should always disable listeners if already enabled
Craig Mautner46ac6fa2013-08-01 10:06:34 -0700810 * screen turned on and current app has sensor based orientation, enable listeners
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800811 * if not already enabled
812 * screen turned on and current app does not have sensor orientation, disable listeners if
813 * already enabled
814 * screen turning on and current app has sensor based orientation, enable listeners if needed
815 * screen turning on and current app has nosensor based orientation, do nothing
816 */
The Android Open Source Project0727d222009-03-11 12:11:58 -0700817 void updateOrientationListenerLp() {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800818 if (!mOrientationListener.canDetectOrientation()) {
819 // If sensor is turned off or nonexistent for some reason
820 return;
821 }
822 //Could have been invoked due to screen turning on or off or
823 //change of the currently visible window's orientation
Jeff Brown3ee549c2014-09-22 20:14:39 -0700824 if (localLOGV) Slog.v(TAG, "mScreenOnEarly=" + mScreenOnEarly
825 + ", mAwake=" + mAwake + ", mCurrentAppOrientation=" + mCurrentAppOrientation
826 + ", mOrientationSensorEnabled=" + mOrientationSensorEnabled);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800827 boolean disable = true;
Jeff Brown3ee549c2014-09-22 20:14:39 -0700828 if (mScreenOnEarly && mAwake) {
The Android Open Source Project0727d222009-03-11 12:11:58 -0700829 if (needSensorRunningLp()) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800830 disable = false;
831 //enable listener if not already enabled
The Android Open Source Project0727d222009-03-11 12:11:58 -0700832 if (!mOrientationSensorEnabled) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800833 mOrientationListener.enable();
Craig Mautnereda67292013-04-28 13:50:14 -0700834 if(localLOGV) Slog.v(TAG, "Enabling listeners");
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800835 mOrientationSensorEnabled = true;
836 }
Craig Mautner46ac6fa2013-08-01 10:06:34 -0700837 }
838 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800839 //check if sensors need to be disabled
The Android Open Source Project0727d222009-03-11 12:11:58 -0700840 if (disable && mOrientationSensorEnabled) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800841 mOrientationListener.disable();
Craig Mautnereda67292013-04-28 13:50:14 -0700842 if(localLOGV) Slog.v(TAG, "Disabling listeners");
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800843 mOrientationSensorEnabled = false;
844 }
845 }
846
Jeff Brown13f00f02014-10-31 14:45:50 -0700847 private void interceptPowerKeyDown(KeyEvent event, boolean interactive) {
848 // Hold a wake lock until the power key is released.
849 if (!mPowerKeyWakeLock.isHeld()) {
850 mPowerKeyWakeLock.acquire();
851 }
852
853 // Cancel multi-press detection timeout.
854 if (mPowerKeyPressCounter != 0) {
855 mHandler.removeMessages(MSG_POWER_DELAYED_PRESS);
856 }
857
858 // Detect user pressing the power button in panic when an application has
859 // taken over the whole screen.
860 boolean panic = mImmersiveModeConfirmation.onPowerKeyDown(interactive,
Craig Mautner0124980e92014-11-30 21:15:34 -0800861 SystemClock.elapsedRealtime(), isImmersiveMode(mLastSystemUiFlags));
Jeff Brown13f00f02014-10-31 14:45:50 -0700862 if (panic) {
863 mHandler.post(mRequestTransientNav);
864 }
865
866 // Latch power key state to detect screenshot chord.
867 if (interactive && !mScreenshotChordPowerKeyTriggered
868 && (event.getFlags() & KeyEvent.FLAG_FALLBACK) == 0) {
869 mScreenshotChordPowerKeyTriggered = true;
870 mScreenshotChordPowerKeyTime = event.getDownTime();
871 interceptScreenshotChord();
872 }
873
874 // Stop ringing or end call if configured to do so when power is pressed.
875 TelecomManager telecomManager = getTelecommService();
876 boolean hungUp = false;
877 if (telecomManager != null) {
878 if (telecomManager.isRinging()) {
879 // Pressing Power while there's a ringing incoming
880 // call should silence the ringer.
881 telecomManager.silenceRinger();
882 } else if ((mIncallPowerBehavior
883 & Settings.Secure.INCALL_POWER_BUTTON_BEHAVIOR_HANGUP) != 0
884 && telecomManager.isInCall() && interactive) {
885 // Otherwise, if "Power button ends call" is enabled,
886 // the Power button will hang up any current active call.
887 hungUp = telecomManager.endCall();
888 }
889 }
890
891 // If the power key has still not yet been handled, then detect short
892 // press, long press, or multi press and decide what to do.
893 mPowerKeyHandled = hungUp || mScreenshotChordVolumeDownKeyTriggered
894 || mScreenshotChordVolumeUpKeyTriggered;
895 if (!mPowerKeyHandled) {
896 if (interactive) {
897 // When interactive, we're already awake.
898 // Wait for a long press or for the button to be released to decide what to do.
899 if (hasLongPressOnPowerBehavior()) {
900 Message msg = mHandler.obtainMessage(MSG_POWER_LONG_PRESS);
901 msg.setAsynchronous(true);
902 mHandler.sendMessageDelayed(msg,
903 ViewConfiguration.get(mContext).getDeviceGlobalActionKeyTimeout());
904 }
905 } else {
Bryce Leed9268e32014-11-17 17:40:59 -0800906 wakeUpFromPowerKey(event.getDownTime());
Bryce Leed9268e32014-11-17 17:40:59 -0800907
Bryce Leed3b28402015-03-09 15:49:13 +0000908 if (mSupportLongPressPowerWhenNonInteractive && hasLongPressOnPowerBehavior()) {
909 Message msg = mHandler.obtainMessage(MSG_POWER_LONG_PRESS);
910 msg.setAsynchronous(true);
911 mHandler.sendMessageDelayed(msg,
912 ViewConfiguration.get(mContext).getDeviceGlobalActionKeyTimeout());
Bryce Leed9268e32014-11-17 17:40:59 -0800913 mBeganFromNonInteractive = true;
Bryce Leed3b28402015-03-09 15:49:13 +0000914 } else {
915 final int maxCount = getMaxMultiPressPowerCount();
916
917 if (maxCount <= 1) {
918 mPowerKeyHandled = true;
919 } else {
920 mBeganFromNonInteractive = true;
921 }
Jeff Brown13f00f02014-10-31 14:45:50 -0700922 }
923 }
Jeff Brown4d396052010-10-29 21:50:21 -0700924 }
925 }
926
Jeff Brown13f00f02014-10-31 14:45:50 -0700927 private void interceptPowerKeyUp(KeyEvent event, boolean interactive, boolean canceled) {
928 final boolean handled = canceled || mPowerKeyHandled;
929 mScreenshotChordPowerKeyTriggered = false;
930 cancelPendingScreenshotChordAction();
931 cancelPendingPowerKeyAction();
932
933 if (!handled) {
934 // Figure out how to handle the key now that it has been released.
935 mPowerKeyPressCounter += 1;
936
937 final int maxCount = getMaxMultiPressPowerCount();
938 final long eventTime = event.getDownTime();
939 if (mPowerKeyPressCounter < maxCount) {
940 // This could be a multi-press. Wait a little bit longer to confirm.
941 // Continue holding the wake lock.
942 Message msg = mHandler.obtainMessage(MSG_POWER_DELAYED_PRESS,
943 interactive ? 1 : 0, mPowerKeyPressCounter, eventTime);
944 msg.setAsynchronous(true);
945 mHandler.sendMessageDelayed(msg, ViewConfiguration.getDoubleTapTimeout());
946 return;
947 }
948
949 // No other actions. Handle it immediately.
950 powerPress(eventTime, interactive, mPowerKeyPressCounter);
Jeff Brown4d396052010-10-29 21:50:21 -0700951 }
Jeff Brown13f00f02014-10-31 14:45:50 -0700952
953 // Done. Reset our state.
954 finishPowerKeyPress();
955 }
956
957 private void finishPowerKeyPress() {
Bryce Leed9268e32014-11-17 17:40:59 -0800958 mBeganFromNonInteractive = false;
Jeff Brown13f00f02014-10-31 14:45:50 -0700959 mPowerKeyPressCounter = 0;
960 if (mPowerKeyWakeLock.isHeld()) {
961 mPowerKeyWakeLock.release();
962 }
Jeff Brownd5bb82d2011-10-12 13:57:59 -0700963 }
964
965 private void cancelPendingPowerKeyAction() {
966 if (!mPowerKeyHandled) {
Jeff Brown13f00f02014-10-31 14:45:50 -0700967 mPowerKeyHandled = true;
968 mHandler.removeMessages(MSG_POWER_LONG_PRESS);
Jeff Brownd5bb82d2011-10-12 13:57:59 -0700969 }
Jeff Brown13f00f02014-10-31 14:45:50 -0700970 }
971
972 private void powerPress(long eventTime, boolean interactive, int count) {
973 if (mScreenOnEarly && !mScreenOnFully) {
974 Slog.i(TAG, "Suppressed redundant power key press while "
975 + "already in the process of turning the screen on.");
976 return;
Jeff Brownff204712011-10-25 21:27:54 -0700977 }
Jeff Brown13f00f02014-10-31 14:45:50 -0700978
979 if (count == 2) {
980 powerMultiPressAction(eventTime, interactive, mDoublePressOnPowerBehavior);
981 } else if (count == 3) {
982 powerMultiPressAction(eventTime, interactive, mTriplePressOnPowerBehavior);
Bryce Leed9268e32014-11-17 17:40:59 -0800983 } else if (interactive && !mBeganFromNonInteractive) {
Jeff Brown13f00f02014-10-31 14:45:50 -0700984 switch (mShortPressOnPowerBehavior) {
985 case SHORT_PRESS_POWER_NOTHING:
986 break;
987 case SHORT_PRESS_POWER_GO_TO_SLEEP:
988 mPowerManager.goToSleep(eventTime,
989 PowerManager.GO_TO_SLEEP_REASON_POWER_BUTTON, 0);
990 break;
991 case SHORT_PRESS_POWER_REALLY_GO_TO_SLEEP:
992 mPowerManager.goToSleep(eventTime,
993 PowerManager.GO_TO_SLEEP_REASON_POWER_BUTTON,
994 PowerManager.GO_TO_SLEEP_FLAG_NO_DOZE);
995 break;
996 case SHORT_PRESS_POWER_REALLY_GO_TO_SLEEP_AND_GO_HOME:
997 mPowerManager.goToSleep(eventTime,
998 PowerManager.GO_TO_SLEEP_REASON_POWER_BUTTON,
999 PowerManager.GO_TO_SLEEP_FLAG_NO_DOZE);
1000 launchHomeFromHotKey();
1001 break;
Bryce Lee01b0c5f2015-02-05 18:24:04 -08001002 case SHORT_PRESS_POWER_GO_HOME:
Bryce Lee662ed802015-04-10 20:11:39 +00001003 launchHomeFromHotKey(true /* awakenFromDreams */, false /*respectKeyguard*/);
Bryce Lee01b0c5f2015-02-05 18:24:04 -08001004 break;
Jeff Brown13f00f02014-10-31 14:45:50 -07001005 }
1006 }
1007 }
1008
1009 private void powerMultiPressAction(long eventTime, boolean interactive, int behavior) {
1010 switch (behavior) {
1011 case MULTI_PRESS_POWER_NOTHING:
1012 break;
1013 case MULTI_PRESS_POWER_THEATER_MODE:
1014 if (isTheaterModeEnabled()) {
1015 Slog.i(TAG, "Toggling theater mode off.");
1016 Settings.Global.putInt(mContext.getContentResolver(),
1017 Settings.Global.THEATER_MODE_ON, 0);
1018 if (!interactive) {
1019 wakeUpFromPowerKey(eventTime);
1020 }
1021 } else {
1022 Slog.i(TAG, "Toggling theater mode on.");
1023 Settings.Global.putInt(mContext.getContentResolver(),
1024 Settings.Global.THEATER_MODE_ON, 1);
Bryce Lee55e846d2014-11-04 12:43:44 -08001025
1026 if (mGoToSleepOnButtonPressTheaterMode && interactive) {
Jeff Brown13f00f02014-10-31 14:45:50 -07001027 mPowerManager.goToSleep(eventTime,
1028 PowerManager.GO_TO_SLEEP_REASON_POWER_BUTTON, 0);
1029 }
1030 }
1031 break;
1032 case MULTI_PRESS_POWER_BRIGHTNESS_BOOST:
Jeff Brown7b5be5e2014-11-12 18:45:31 -08001033 Slog.i(TAG, "Starting brightness boost.");
1034 if (!interactive) {
1035 wakeUpFromPowerKey(eventTime);
1036 }
Jeff Brown13f00f02014-10-31 14:45:50 -07001037 mPowerManager.boostScreenBrightness(eventTime);
1038 break;
1039 }
1040 }
1041
1042 private int getMaxMultiPressPowerCount() {
1043 if (mTriplePressOnPowerBehavior != MULTI_PRESS_POWER_NOTHING) {
1044 return 3;
1045 }
1046 if (mDoublePressOnPowerBehavior != MULTI_PRESS_POWER_NOTHING) {
1047 return 2;
1048 }
1049 return 1;
1050 }
1051
1052 private void powerLongPress() {
1053 final int behavior = getResolvedLongPressOnPowerBehavior();
1054 switch (behavior) {
1055 case LONG_PRESS_POWER_NOTHING:
1056 break;
1057 case LONG_PRESS_POWER_GLOBAL_ACTIONS:
1058 mPowerKeyHandled = true;
1059 if (!performHapticFeedbackLw(null, HapticFeedbackConstants.LONG_PRESS, false)) {
1060 performAuditoryFeedbackForAccessibilityIfNeed();
1061 }
1062 showGlobalActionsInternal();
1063 break;
1064 case LONG_PRESS_POWER_SHUT_OFF:
1065 case LONG_PRESS_POWER_SHUT_OFF_NO_CONFIRM:
1066 mPowerKeyHandled = true;
1067 performHapticFeedbackLw(null, HapticFeedbackConstants.LONG_PRESS, false);
1068 sendCloseSystemWindows(SYSTEM_DIALOG_REASON_GLOBAL_ACTIONS);
1069 mWindowManagerFuncs.shutdown(behavior == LONG_PRESS_POWER_SHUT_OFF);
1070 break;
1071 }
1072 }
1073
Filip Gruszczynskia483a1d2015-03-17 19:06:58 +00001074 private void sleepPress(KeyEvent event) {
1075 switch (mShortPressOnSleepBehavior) {
1076 case SHORT_PRESS_SLEEP_GO_TO_SLEEP:
1077 mPowerManager.goToSleep(event.getEventTime(),
1078 PowerManager.GO_TO_SLEEP_REASON_SLEEP_BUTTON, 0);
1079 break;
1080 case SHORT_PRESS_SLEEP_GO_TO_SLEEP_AND_GO_HOME:
Bryce Lee662ed802015-04-10 20:11:39 +00001081 launchHomeFromHotKey(false /* awakenDreams */, true /*respectKeyguard*/);
Filip Gruszczynskia483a1d2015-03-17 19:06:58 +00001082 mPowerManager.goToSleep(event.getEventTime(),
1083 PowerManager.GO_TO_SLEEP_REASON_SLEEP_BUTTON, 0);
1084 break;
1085 }
1086 }
1087
Jeff Brown13f00f02014-10-31 14:45:50 -07001088 private int getResolvedLongPressOnPowerBehavior() {
1089 if (FactoryTest.isLongPressOnPowerOffEnabled()) {
1090 return LONG_PRESS_POWER_SHUT_OFF_NO_CONFIRM;
1091 }
1092 return mLongPressOnPowerBehavior;
1093 }
1094
1095 private boolean hasLongPressOnPowerBehavior() {
1096 return getResolvedLongPressOnPowerBehavior() != LONG_PRESS_POWER_NOTHING;
Jeff Brownd5bb82d2011-10-12 13:57:59 -07001097 }
1098
1099 private void interceptScreenshotChord() {
Christopher Tatee90585f2012-03-05 18:56:25 -08001100 if (mScreenshotChordEnabled
Jeff Brown13f00f02014-10-31 14:45:50 -07001101 && mScreenshotChordVolumeDownKeyTriggered && mScreenshotChordPowerKeyTriggered
1102 && !mScreenshotChordVolumeUpKeyTriggered) {
Jeff Brownd5bb82d2011-10-12 13:57:59 -07001103 final long now = SystemClock.uptimeMillis();
Jeff Brown13f00f02014-10-31 14:45:50 -07001104 if (now <= mScreenshotChordVolumeDownKeyTime + SCREENSHOT_CHORD_DEBOUNCE_DELAY_MILLIS
1105 && now <= mScreenshotChordPowerKeyTime
1106 + SCREENSHOT_CHORD_DEBOUNCE_DELAY_MILLIS) {
1107 mScreenshotChordVolumeDownKeyConsumed = true;
Jeff Brownd5bb82d2011-10-12 13:57:59 -07001108 cancelPendingPowerKeyAction();
1109
Jeff Sharkey2991fa32012-12-05 18:06:43 -08001110 mHandler.postDelayed(mScreenshotRunnable, getScreenshotChordLongPressDelay());
Jeff Brownd5bb82d2011-10-12 13:57:59 -07001111 }
1112 }
1113 }
1114
Winson Chung1cea2f32012-10-08 20:42:01 -07001115 private long getScreenshotChordLongPressDelay() {
Jim Miller5ecd8112013-01-09 18:50:26 -08001116 if (mKeyguardDelegate.isShowing()) {
Winson Chung1cea2f32012-10-08 20:42:01 -07001117 // Double the time it takes to take a screenshot from the keyguard
1118 return (long) (KEYGUARD_SCREENSHOT_CHORD_DELAY_MULTIPLIER *
Justin Kohfeabd2c2014-05-02 10:02:44 -07001119 ViewConfiguration.get(mContext).getDeviceGlobalActionKeyTimeout());
Winson Chung1cea2f32012-10-08 20:42:01 -07001120 }
Justin Kohfeabd2c2014-05-02 10:02:44 -07001121 return ViewConfiguration.get(mContext).getDeviceGlobalActionKeyTimeout();
Winson Chung1cea2f32012-10-08 20:42:01 -07001122 }
1123
Jeff Brownd5bb82d2011-10-12 13:57:59 -07001124 private void cancelPendingScreenshotChordAction() {
Jeff Sharkey2991fa32012-12-05 18:06:43 -08001125 mHandler.removeCallbacks(mScreenshotRunnable);
Jeff Brown4d396052010-10-29 21:50:21 -07001126 }
1127
Jeff Brown13f00f02014-10-31 14:45:50 -07001128 private final Runnable mEndCallLongPress = new Runnable() {
Craig Mautnerf1b67412012-09-19 13:18:29 -07001129 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001130 public void run() {
Jeff Brown13f00f02014-10-31 14:45:50 -07001131 mEndCallKeyHandled = true;
1132 if (!performHapticFeedbackLw(null, HapticFeedbackConstants.LONG_PRESS, false)) {
1133 performAuditoryFeedbackForAccessibilityIfNeed();
Joe Onoratod208e702010-10-08 16:22:43 -04001134 }
Jeff Brown13f00f02014-10-31 14:45:50 -07001135 showGlobalActionsInternal();
Jeff Brownd5bb82d2011-10-12 13:57:59 -07001136 }
1137 };
1138
Jeff Sharkey2991fa32012-12-05 18:06:43 -08001139 private final Runnable mScreenshotRunnable = new Runnable() {
Craig Mautner0bf6ec92012-12-18 08:33:27 -08001140 @Override
Jeff Brownd5bb82d2011-10-12 13:57:59 -07001141 public void run() {
1142 takeScreenshot();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001143 }
1144 };
1145
Alan Viverettee34560b22014-07-10 14:50:06 -07001146 @Override
1147 public void showGlobalActions() {
1148 mHandler.removeMessages(MSG_DISPATCH_SHOW_GLOBAL_ACTIONS);
1149 mHandler.sendEmptyMessage(MSG_DISPATCH_SHOW_GLOBAL_ACTIONS);
1150 }
1151
1152 void showGlobalActionsInternal() {
1153 sendCloseSystemWindows(SYSTEM_DIALOG_REASON_GLOBAL_ACTIONS);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001154 if (mGlobalActions == null) {
Jeff Brown7304c342012-05-11 18:42:42 -07001155 mGlobalActions = new GlobalActions(mContext, mWindowManagerFuncs);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001156 }
Jim Millerab954542014-10-10 18:21:49 -07001157 final boolean keyguardShowing = isKeyguardShowingAndNotOccluded();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001158 mGlobalActions.showDialog(keyguardShowing, isDeviceProvisioned());
1159 if (keyguardShowing) {
1160 // since it took two seconds of long press to bring this up,
1161 // poke the wake lock so they have some time to see the dialog.
Jim Miller25190572013-02-28 17:36:24 -08001162 mPowerManager.userActivity(SystemClock.uptimeMillis(), false);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001163 }
1164 }
1165
1166 boolean isDeviceProvisioned() {
Jeff Brownbf6f6f92012-09-25 15:03:20 -07001167 return Settings.Global.getInt(
1168 mContext.getContentResolver(), Settings.Global.DEVICE_PROVISIONED, 0) != 0;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001169 }
1170
Maurice Lam99c6e072014-04-28 18:24:28 -07001171 boolean isUserSetupComplete() {
1172 return Settings.Secure.getIntForUser(mContext.getContentResolver(),
1173 Settings.Secure.USER_SETUP_COMPLETE, 0, UserHandle.USER_CURRENT) != 0;
1174 }
1175
Jeff Brown13f00f02014-10-31 14:45:50 -07001176 private void handleShortPressOnHome() {
1177 // If there's a dream running then use home to escape the dream
1178 // but don't actually go home.
1179 if (mDreamManagerInternal != null && mDreamManagerInternal.isDreaming()) {
1180 mDreamManagerInternal.stopDream(false /*immediate*/);
1181 return;
1182 }
1183
1184 // Go home!
1185 launchHomeFromHotKey();
1186 }
1187
Patrick Dubroyece94522011-02-23 18:35:01 -08001188 private void handleLongPressOnHome() {
Joe Onorato46b0d682010-11-22 17:37:27 -08001189 if (mLongPressOnHomeBehavior != LONG_PRESS_HOME_NOTHING) {
Jeff Browncaca8812013-05-09 13:34:33 -07001190 mHomeConsumed = true;
Joe Onorato46b0d682010-11-22 17:37:27 -08001191 performHapticFeedbackLw(null, HapticFeedbackConstants.LONG_PRESS, false);
Patrick Dubroyece94522011-02-23 18:35:01 -08001192
Jeff Browncaca8812013-05-09 13:34:33 -07001193 if (mLongPressOnHomeBehavior == LONG_PRESS_HOME_RECENT_SYSTEM_UI) {
1194 toggleRecentApps();
1195 } else if (mLongPressOnHomeBehavior == LONG_PRESS_HOME_ASSIST) {
1196 launchAssistAction();
Jim Millere6ad1a82010-08-20 19:25:39 -07001197 }
1198 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001199 }
Patrick Dubroyece94522011-02-23 18:35:01 -08001200
Jeff Browncaca8812013-05-09 13:34:33 -07001201 private void handleDoubleTapOnHome() {
1202 if (mDoubleTapOnHomeBehavior == DOUBLE_TAP_HOME_RECENT_SYSTEM_UI) {
1203 mHomeConsumed = true;
1204 toggleRecentApps();
1205 }
1206 }
1207
1208 private final Runnable mHomeDoubleTapTimeoutRunnable = new Runnable() {
1209 @Override
1210 public void run() {
1211 if (mHomeDoubleTapPending) {
1212 mHomeDoubleTapPending = false;
Jeff Brown13f00f02014-10-31 14:45:50 -07001213 handleShortPressOnHome();
Jeff Browncaca8812013-05-09 13:34:33 -07001214 }
1215 }
1216 };
1217
Mark Renoufc1256912015-03-11 14:38:23 -04001218 private boolean isRoundWindow() {
1219 return mContext.getResources().getBoolean(com.android.internal.R.bool.config_windowIsRound)
1220 || (Build.HARDWARE.contains("goldfish")
1221 && SystemProperties.getBoolean(ViewRootImpl.PROPERTY_EMULATOR_CIRCULAR, false));
1222 }
1223
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001224 /** {@inheritDoc} */
Craig Mautner0bf6ec92012-12-18 08:33:27 -08001225 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001226 public void init(Context context, IWindowManager windowManager,
Jeff Brown96307042012-07-27 15:51:34 -07001227 WindowManagerFuncs windowManagerFuncs) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001228 mContext = context;
1229 mWindowManager = windowManager;
Dianne Hackborndf89e652011-10-06 22:35:11 -07001230 mWindowManagerFuncs = windowManagerFuncs;
Craig Mautner8a0da012014-05-31 15:13:37 -07001231 mWindowManagerInternal = LocalServices.getService(WindowManagerInternal.class);
Jeff Brown061ea992015-04-17 19:55:47 -07001232 mActivityManagerInternal = LocalServices.getService(ActivityManagerInternal.class);
Jose Lima9546b202014-07-02 17:21:51 -07001233 mDreamManagerInternal = LocalServices.getService(DreamManagerInternal.class);
Mark Renoufc1256912015-03-11 14:38:23 -04001234
1235 // Init display burn-in protection
1236 boolean burnInProtectionEnabled = context.getResources().getBoolean(
1237 com.android.internal.R.bool.config_enableBurnInProtection);
1238 // Allow a system property to override this. Used by developer settings.
1239 boolean burnInProtectionDevMode =
1240 SystemProperties.getBoolean("persist.debug.force_burn_in", false);
1241 if (burnInProtectionEnabled || burnInProtectionDevMode) {
1242 final int minHorizontal;
1243 final int maxHorizontal;
1244 final int minVertical;
1245 final int maxVertical;
1246 final int maxRadius;
1247 if (burnInProtectionDevMode) {
1248 minHorizontal = -8;
1249 maxHorizontal = 8;
1250 minVertical = -8;
1251 maxVertical = -4;
1252 maxRadius = (isRoundWindow()) ? 6 : -1;
1253 } else {
1254 Resources resources = context.getResources();
1255 minHorizontal = resources.getInteger(
1256 com.android.internal.R.integer.config_burnInProtectionMinHorizontalOffset);
1257 maxHorizontal = resources.getInteger(
1258 com.android.internal.R.integer.config_burnInProtectionMaxHorizontalOffset);
1259 minVertical = resources.getInteger(
1260 com.android.internal.R.integer.config_burnInProtectionMinVerticalOffset);
1261 maxVertical = resources.getInteger(
1262 com.android.internal.R.integer.config_burnInProtectionMaxVerticalOffset);
1263 maxRadius = resources.getInteger(
1264 com.android.internal.R.integer.config_burnInProtectionMaxRadius);
1265 }
1266 mBurnInProtectionHelper = new BurnInProtectionHelper(
1267 context, minHorizontal, maxHorizontal, minVertical, maxVertical, maxRadius);
Filip Gruszczynskicfb31852015-02-25 21:47:12 +00001268 }
Craig Mautner8a0da012014-05-31 15:13:37 -07001269
Jeff Brown70825162012-03-28 17:27:48 -07001270 mHandler = new PolicyHandler();
Jeff Browna20dda42014-05-27 20:57:24 -07001271 mWakeGestureListener = new MyWakeGestureListener(mContext, mHandler);
Craig Mautnereee29c42013-01-17 14:44:34 -08001272 mOrientationListener = new MyOrientationListener(mContext, mHandler);
Jeff Brownc0347aa2011-09-23 17:26:09 -07001273 try {
1274 mOrientationListener.setCurrentRotation(windowManager.getRotation());
1275 } catch (RemoteException ex) { }
Christopher Tate5e08af02012-09-21 17:17:22 -07001276 mSettingsObserver = new SettingsObserver(mHandler);
1277 mSettingsObserver.observe();
Svetoslav683914b2015-01-15 14:22:26 -08001278 mShortcutManager = new ShortcutManager(context);
Daniel Sandler6396c722013-04-16 20:19:09 -04001279 mUiMode = context.getResources().getInteger(
1280 com.android.internal.R.integer.config_defaultUiModeType);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001281 mHomeIntent = new Intent(Intent.ACTION_MAIN, null);
1282 mHomeIntent.addCategory(Intent.CATEGORY_HOME);
1283 mHomeIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK
1284 | Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED);
Dianne Hackborn39c2d712009-09-22 11:41:31 -07001285 mCarDockIntent = new Intent(Intent.ACTION_MAIN, null);
1286 mCarDockIntent.addCategory(Intent.CATEGORY_CAR_DOCK);
1287 mCarDockIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK
1288 | Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED);
1289 mDeskDockIntent = new Intent(Intent.ACTION_MAIN, null);
1290 mDeskDockIntent.addCategory(Intent.CATEGORY_DESK_DOCK);
1291 mDeskDockIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK
1292 | Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED);
Jim Millere6ad1a82010-08-20 19:25:39 -07001293
Jeff Brown96307042012-07-27 15:51:34 -07001294 mPowerManager = (PowerManager)context.getSystemService(Context.POWER_SERVICE);
1295 mBroadcastWakeLock = mPowerManager.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK,
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001296 "PhoneWindowManager.mBroadcastWakeLock");
Jeff Brown13f00f02014-10-31 14:45:50 -07001297 mPowerKeyWakeLock = mPowerManager.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK,
1298 "PhoneWindowManager.mPowerKeyWakeLock");
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001299 mEnableShiftMenuBugReports = "1".equals(SystemProperties.get("ro.debuggable"));
Jeff Brownbcdfc622014-03-06 19:13:04 -08001300 mSupportAutoRotation = mContext.getResources().getBoolean(
1301 com.android.internal.R.bool.config_supportAutoRotation);
Dianne Hackborn2862fff2009-09-15 22:56:29 -07001302 mLidOpenRotation = readRotation(
Mike Lockwood2d1efbd2009-09-16 12:15:53 -04001303 com.android.internal.R.integer.config_lidOpenRotation);
1304 mCarDockRotation = readRotation(
1305 com.android.internal.R.integer.config_carDockRotation);
1306 mDeskDockRotation = readRotation(
1307 com.android.internal.R.integer.config_deskDockRotation);
Jeff Brownc82c89ed2013-04-17 17:18:15 -07001308 mUndockedHdmiRotation = readRotation(
1309 com.android.internal.R.integer.config_undockedHdmiRotation);
Mike Lockwoode9867d22009-09-20 01:59:02 -04001310 mCarDockEnablesAccelerometer = mContext.getResources().getBoolean(
1311 com.android.internal.R.bool.config_carDockEnablesAccelerometer);
1312 mDeskDockEnablesAccelerometer = mContext.getResources().getBoolean(
1313 com.android.internal.R.bool.config_deskDockEnablesAccelerometer);
Dianne Hackborn2862fff2009-09-15 22:56:29 -07001314 mLidKeyboardAccessibility = mContext.getResources().getInteger(
1315 com.android.internal.R.integer.config_lidKeyboardAccessibility);
1316 mLidNavigationAccessibility = mContext.getResources().getInteger(
1317 com.android.internal.R.integer.config_lidNavigationAccessibility);
Jeff Brownc458ce92012-04-30 14:58:40 -07001318 mLidControlsSleep = mContext.getResources().getBoolean(
1319 com.android.internal.R.bool.config_lidControlsSleep);
Daniel Sandlerdd73ee42013-10-11 22:19:59 -04001320 mTranslucentDecorEnabled = mContext.getResources().getBoolean(
1321 com.android.internal.R.bool.config_enableTranslucentDecor);
Bryce Lee584a4452014-10-21 15:55:55 -07001322
1323 mAllowTheaterModeWakeFromKey = mContext.getResources().getBoolean(
1324 com.android.internal.R.bool.config_allowTheaterModeWakeFromKey);
1325 mAllowTheaterModeWakeFromPowerKey = mAllowTheaterModeWakeFromKey
1326 || mContext.getResources().getBoolean(
1327 com.android.internal.R.bool.config_allowTheaterModeWakeFromPowerKey);
1328 mAllowTheaterModeWakeFromMotion = mContext.getResources().getBoolean(
1329 com.android.internal.R.bool.config_allowTheaterModeWakeFromMotion);
Bryce Lee812d7022014-11-10 13:33:28 -08001330 mAllowTheaterModeWakeFromMotionWhenNotDreaming = mContext.getResources().getBoolean(
1331 com.android.internal.R.bool.config_allowTheaterModeWakeFromMotionWhenNotDreaming);
Bryce Lee584a4452014-10-21 15:55:55 -07001332 mAllowTheaterModeWakeFromCameraLens = mContext.getResources().getBoolean(
1333 com.android.internal.R.bool.config_allowTheaterModeWakeFromCameraLens);
1334 mAllowTheaterModeWakeFromLidSwitch = mContext.getResources().getBoolean(
1335 com.android.internal.R.bool.config_allowTheaterModeWakeFromLidSwitch);
1336 mAllowTheaterModeWakeFromWakeGesture = mContext.getResources().getBoolean(
1337 com.android.internal.R.bool.config_allowTheaterModeWakeFromGesture);
1338
Bryce Lee55e846d2014-11-04 12:43:44 -08001339 mGoToSleepOnButtonPressTheaterMode = mContext.getResources().getBoolean(
1340 com.android.internal.R.bool.config_goToSleepOnButtonPressTheaterMode);
1341
Bryce Leed3b28402015-03-09 15:49:13 +00001342 mSupportLongPressPowerWhenNonInteractive = mContext.getResources().getBoolean(
1343 com.android.internal.R.bool.config_supportLongPressPowerWhenNonInteractive);
1344
Jeff Brown13f00f02014-10-31 14:45:50 -07001345 mShortPressOnPowerBehavior = mContext.getResources().getInteger(
1346 com.android.internal.R.integer.config_shortPressOnPowerBehavior);
1347 mLongPressOnPowerBehavior = mContext.getResources().getInteger(
1348 com.android.internal.R.integer.config_longPressOnPowerBehavior);
1349 mDoublePressOnPowerBehavior = mContext.getResources().getInteger(
1350 com.android.internal.R.integer.config_doublePressOnPowerBehavior);
1351 mTriplePressOnPowerBehavior = mContext.getResources().getInteger(
1352 com.android.internal.R.integer.config_triplePressOnPowerBehavior);
Filip Gruszczynskia483a1d2015-03-17 19:06:58 +00001353 mShortPressOnSleepBehavior = mContext.getResources().getInteger(
1354 com.android.internal.R.integer.config_shortPressOnSleepBehavior);
Jeff Brown13f00f02014-10-31 14:45:50 -07001355
John Spurlock61560172015-02-06 19:46:04 -05001356 mUseTvRouting = AudioSystem.getPlatformType(mContext) == AudioSystem.PLATFORM_TELEVISION;
RoboErik001c59c2015-01-26 15:53:51 -08001357
Jeff Brownf71343d2013-05-31 17:59:11 -07001358 readConfigurationDependentBehaviors();
Jeff Browncaca8812013-05-09 13:34:33 -07001359
Svetoslav8e3feb12014-02-24 13:46:47 -08001360 mAccessibilityManager = (AccessibilityManager) context.getSystemService(
1361 Context.ACCESSIBILITY_SERVICE);
1362
Mike Lockwood1753f7f2009-08-24 14:49:07 -07001363 // register for dock events
Dianne Hackborn78968392010-03-04 20:47:56 -08001364 IntentFilter filter = new IntentFilter();
1365 filter.addAction(UiModeManager.ACTION_ENTER_CAR_MODE);
1366 filter.addAction(UiModeManager.ACTION_EXIT_CAR_MODE);
1367 filter.addAction(UiModeManager.ACTION_ENTER_DESK_MODE);
1368 filter.addAction(UiModeManager.ACTION_EXIT_DESK_MODE);
Dianne Hackborn867ab6472010-04-29 13:28:56 -07001369 filter.addAction(Intent.ACTION_DOCK_EVENT);
1370 Intent intent = context.registerReceiver(mDockReceiver, filter);
1371 if (intent != null) {
1372 // Retrieve current sticky dock event broadcast.
1373 mDockMode = intent.getIntExtra(Intent.EXTRA_DOCK_STATE,
1374 Intent.EXTRA_DOCK_STATE_UNDOCKED);
1375 }
Daniel Sandler7e37df52011-11-16 22:08:23 -08001376
Jeff Brown6aaf2952012-10-05 16:01:08 -07001377 // register for dream-related broadcasts
1378 filter = new IntentFilter();
1379 filter.addAction(Intent.ACTION_DREAMING_STARTED);
1380 filter.addAction(Intent.ACTION_DREAMING_STOPPED);
1381 context.registerReceiver(mDreamReceiver, filter);
1382
Christopher Tate5e08af02012-09-21 17:17:22 -07001383 // register for multiuser-relevant broadcasts
1384 filter = new IntentFilter(Intent.ACTION_USER_SWITCHED);
1385 context.registerReceiver(mMultiuserReceiver, filter);
1386
John Spurlock57306e62013-04-22 09:48:49 -04001387 // monitor for system gestures
Craig Mautner037aa8d2013-06-07 10:35:44 -07001388 mSystemGestures = new SystemGesturesPointerEventListener(context,
1389 new SystemGesturesPointerEventListener.Callbacks() {
John Spurlock57306e62013-04-22 09:48:49 -04001390 @Override
1391 public void onSwipeFromTop() {
John Spurlock04db1762013-05-13 12:46:41 -04001392 if (mStatusBar != null) {
John Spurlocke1f366f2013-08-05 12:22:40 -04001393 requestTransientBars(mStatusBar);
John Spurlock04db1762013-05-13 12:46:41 -04001394 }
John Spurlockad3e6cb2013-04-30 08:47:43 -04001395 }
1396 @Override
1397 public void onSwipeFromBottom() {
John Spurlock04db1762013-05-13 12:46:41 -04001398 if (mNavigationBar != null && mNavigationBarOnBottom) {
John Spurlocke1f366f2013-08-05 12:22:40 -04001399 requestTransientBars(mNavigationBar);
John Spurlockad3e6cb2013-04-30 08:47:43 -04001400 }
1401 }
1402 @Override
1403 public void onSwipeFromRight() {
John Spurlock04db1762013-05-13 12:46:41 -04001404 if (mNavigationBar != null && !mNavigationBarOnBottom) {
John Spurlocke1f366f2013-08-05 12:22:40 -04001405 requestTransientBars(mNavigationBar);
John Spurlockad3e6cb2013-04-30 08:47:43 -04001406 }
1407 }
1408 @Override
1409 public void onDebug() {
John Spurlockd67ec252013-09-05 11:31:54 -04001410 // no-op
John Spurlockad3e6cb2013-04-30 08:47:43 -04001411 }
Adrian Roos3595be42015-03-05 16:31:15 +01001412 @Override
1413 public void onDown() {
1414 mOrientationListener.onTouchStart();
1415 }
1416 @Override
1417 public void onUpOrCancel() {
1418 mOrientationListener.onTouchEnd();
1419 }
John Spurlockad3e6cb2013-04-30 08:47:43 -04001420 });
John Spurlockf1a36642013-10-12 17:50:42 -04001421 mImmersiveModeConfirmation = new ImmersiveModeConfirmation(mContext);
Craig Mautner037aa8d2013-06-07 10:35:44 -07001422 mWindowManagerFuncs.registerPointerEventListener(mSystemGestures);
John Spurlock32beb2c2013-03-11 10:16:47 -04001423
Jeff Brownc2346132012-04-13 01:55:38 -07001424 mVibrator = (Vibrator)context.getSystemService(Context.VIBRATOR_SERVICE);
Dianne Hackbornb1a79802009-09-29 15:18:31 -07001425 mLongPressVibePattern = getLongIntArray(mContext.getResources(),
1426 com.android.internal.R.array.config_longPressVibePattern);
1427 mVirtualKeyVibePattern = getLongIntArray(mContext.getResources(),
1428 com.android.internal.R.array.config_virtualKeyVibePattern);
Amith Yamasanic33cb712010-02-10 15:21:49 -08001429 mKeyboardTapVibePattern = getLongIntArray(mContext.getResources(),
1430 com.android.internal.R.array.config_keyboardTapVibePattern);
Fabrice Di Meglioeeff63a2013-08-05 12:07:24 -07001431 mClockTickVibePattern = getLongIntArray(mContext.getResources(),
1432 com.android.internal.R.array.config_clockTickVibePattern);
Fabrice Di Megliobd9152f2013-10-01 11:21:31 -07001433 mCalendarDateVibePattern = getLongIntArray(mContext.getResources(),
1434 com.android.internal.R.array.config_calendarDateVibePattern);
Dianne Hackbornb1a79802009-09-29 15:18:31 -07001435 mSafeModeDisabledVibePattern = getLongIntArray(mContext.getResources(),
1436 com.android.internal.R.array.config_safeModeDisabledVibePattern);
1437 mSafeModeEnabledVibePattern = getLongIntArray(mContext.getResources(),
1438 com.android.internal.R.array.config_safeModeEnabledVibePattern);
Daniel Sandler40427442010-07-16 11:44:52 -04001439
Christopher Tatee90585f2012-03-05 18:56:25 -08001440 mScreenshotChordEnabled = mContext.getResources().getBoolean(
1441 com.android.internal.R.bool.config_enableScreenshotChord);
1442
Justin Kohd378ad72013-04-01 12:18:26 -07001443 mGlobalKeyManager = new GlobalKeyManager(mContext);
1444
Joe Onoratoea495d42011-04-06 11:41:11 -07001445 // Controls rotation and the like.
1446 initializeHdmiState();
Dianne Hackborn40011092011-09-22 13:37:48 -07001447
1448 // Match current screen state.
Craig Mautnera631d492014-08-05 15:16:01 -07001449 if (!mPowerManager.isInteractive()) {
Jeff Brown140ffc72014-05-01 15:18:00 -07001450 goingToSleep(WindowManagerPolicy.OFF_BECAUSE_OF_USER);
Dianne Hackborn40011092011-09-22 13:37:48 -07001451 }
Jorim Jaggi24bec7c2015-02-04 12:40:14 +01001452
1453 mWindowManagerInternal.registerAppTransitionListener(
1454 mStatusBarController.getAppTransitionListener());
Mike Lockwood1753f7f2009-08-24 14:49:07 -07001455 }
1456
Jeff Brownf71343d2013-05-31 17:59:11 -07001457 /**
1458 * Read values from config.xml that may be overridden depending on
1459 * the configuration of the device.
1460 * eg. Disable long press on home goes to recents on sw600dp.
1461 */
1462 private void readConfigurationDependentBehaviors() {
1463 mLongPressOnHomeBehavior = mContext.getResources().getInteger(
1464 com.android.internal.R.integer.config_longPressOnHomeBehavior);
1465 if (mLongPressOnHomeBehavior < LONG_PRESS_HOME_NOTHING ||
1466 mLongPressOnHomeBehavior > LONG_PRESS_HOME_ASSIST) {
1467 mLongPressOnHomeBehavior = LONG_PRESS_HOME_NOTHING;
1468 }
1469
1470 mDoubleTapOnHomeBehavior = mContext.getResources().getInteger(
1471 com.android.internal.R.integer.config_doubleTapOnHomeBehavior);
1472 if (mDoubleTapOnHomeBehavior < DOUBLE_TAP_HOME_NOTHING ||
1473 mDoubleTapOnHomeBehavior > DOUBLE_TAP_HOME_RECENT_SYSTEM_UI) {
1474 mDoubleTapOnHomeBehavior = LONG_PRESS_HOME_NOTHING;
1475 }
1476 }
1477
Craig Mautner0bf6ec92012-12-18 08:33:27 -08001478 @Override
Dianne Hackborndde331c2012-08-03 14:01:57 -07001479 public void setInitialDisplaySize(Display display, int width, int height, int density) {
Jeff Brownef981a42013-08-07 14:13:37 -07001480 // This method might be called before the policy has been fully initialized
1481 // or for other displays we don't care about.
1482 if (mContext == null || display.getDisplayId() != Display.DEFAULT_DISPLAY) {
1483 return;
Dianne Hackbornc652de82013-02-15 16:32:56 -08001484 }
Dianne Hackbornf87d1962012-04-04 12:48:24 -07001485 mDisplay = display;
1486
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001487 final Resources res = mContext.getResources();
Dianne Hackbornf87d1962012-04-04 12:48:24 -07001488 int shortSize, longSize;
Dianne Hackborn9d132642011-04-21 17:26:39 -07001489 if (width > height) {
Dianne Hackborn81e56d52011-05-26 00:55:58 -07001490 shortSize = height;
Dianne Hackbornf87d1962012-04-04 12:48:24 -07001491 longSize = width;
Dianne Hackborn9d132642011-04-21 17:26:39 -07001492 mLandscapeRotation = Surface.ROTATION_0;
1493 mSeascapeRotation = Surface.ROTATION_180;
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001494 if (res.getBoolean(com.android.internal.R.bool.config_reverseDefaultRotation)) {
Dianne Hackborn9d132642011-04-21 17:26:39 -07001495 mPortraitRotation = Surface.ROTATION_90;
1496 mUpsideDownRotation = Surface.ROTATION_270;
1497 } else {
1498 mPortraitRotation = Surface.ROTATION_270;
1499 mUpsideDownRotation = Surface.ROTATION_90;
1500 }
1501 } else {
Dianne Hackborn81e56d52011-05-26 00:55:58 -07001502 shortSize = width;
Dianne Hackbornf87d1962012-04-04 12:48:24 -07001503 longSize = height;
Dianne Hackborn9d132642011-04-21 17:26:39 -07001504 mPortraitRotation = Surface.ROTATION_0;
1505 mUpsideDownRotation = Surface.ROTATION_180;
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001506 if (res.getBoolean(com.android.internal.R.bool.config_reverseDefaultRotation)) {
Dianne Hackborn9d132642011-04-21 17:26:39 -07001507 mLandscapeRotation = Surface.ROTATION_270;
1508 mSeascapeRotation = Surface.ROTATION_90;
1509 } else {
1510 mLandscapeRotation = Surface.ROTATION_90;
1511 mSeascapeRotation = Surface.ROTATION_270;
1512 }
1513 }
Dianne Hackborn81e56d52011-05-26 00:55:58 -07001514
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001515 mStatusBarHeight =
1516 res.getDimensionPixelSize(com.android.internal.R.dimen.status_bar_height);
Dianne Hackbornf87d1962012-04-04 12:48:24 -07001517
Daniel Sandler9f65c4c2012-04-26 01:35:35 -04001518 // Height of the navigation bar when presented horizontally at bottom
1519 mNavigationBarHeightForRotation[mPortraitRotation] =
1520 mNavigationBarHeightForRotation[mUpsideDownRotation] =
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001521 res.getDimensionPixelSize(com.android.internal.R.dimen.navigation_bar_height);
Daniel Sandler9f65c4c2012-04-26 01:35:35 -04001522 mNavigationBarHeightForRotation[mLandscapeRotation] =
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001523 mNavigationBarHeightForRotation[mSeascapeRotation] = res.getDimensionPixelSize(
1524 com.android.internal.R.dimen.navigation_bar_height_landscape);
Daniel Sandler9f65c4c2012-04-26 01:35:35 -04001525
1526 // Width of the navigation bar when presented vertically along one side
1527 mNavigationBarWidthForRotation[mPortraitRotation] =
1528 mNavigationBarWidthForRotation[mUpsideDownRotation] =
1529 mNavigationBarWidthForRotation[mLandscapeRotation] =
1530 mNavigationBarWidthForRotation[mSeascapeRotation] =
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001531 res.getDimensionPixelSize(com.android.internal.R.dimen.navigation_bar_width);
Daniel Sandler4a066c52012-04-20 14:49:13 -04001532
1533 // SystemUI (status bar) layout policy
Dianne Hackborndde331c2012-08-03 14:01:57 -07001534 int shortSizeDp = shortSize * DisplayMetrics.DENSITY_DEFAULT / density;
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001535 int longSizeDp = longSize * DisplayMetrics.DENSITY_DEFAULT / density;
Daniel Sandler4a066c52012-04-20 14:49:13 -04001536
Devin Kimd7b12b42014-05-05 14:34:58 -07001537 // Allow the navigation bar to move on non-square small devices (phones).
1538 mNavigationBarCanMove = width != height && shortSizeDp < 600;
Daniel Sandler36412a72011-08-04 09:35:13 -04001539
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001540 mHasNavigationBar = res.getBoolean(com.android.internal.R.bool.config_showNavigationBar);
John Spurlock80f00c12013-06-13 11:10:51 -04001541 // Allow a system property to override this. Used by the emulator.
1542 // See also hasNavigationBar().
1543 String navBarOverride = SystemProperties.get("qemu.hw.mainkeys");
1544 if ("1".equals(navBarOverride)) {
Dianne Hackbornf87d1962012-04-04 12:48:24 -07001545 mHasNavigationBar = false;
John Spurlock80f00c12013-06-13 11:10:51 -04001546 } else if ("0".equals(navBarOverride)) {
1547 mHasNavigationBar = true;
Daniel Sandler0c4ccff2011-10-19 16:39:14 -04001548 }
1549
Jeff Brown27f1d672012-10-17 18:32:34 -07001550 // For demo purposes, allow the rotation of the HDMI display to be controlled.
1551 // By default, HDMI locks rotation to landscape.
Erik Gilling9a41ef82011-09-26 19:21:03 -07001552 if ("portrait".equals(SystemProperties.get("persist.demo.hdmirotation"))) {
Jeff Brownc82c89ed2013-04-17 17:18:15 -07001553 mDemoHdmiRotation = mPortraitRotation;
Erik Gilling9a41ef82011-09-26 19:21:03 -07001554 } else {
Jeff Brownc82c89ed2013-04-17 17:18:15 -07001555 mDemoHdmiRotation = mLandscapeRotation;
Erik Gilling9a41ef82011-09-26 19:21:03 -07001556 }
Jeff Brownc82c89ed2013-04-17 17:18:15 -07001557 mDemoHdmiRotationLock = SystemProperties.getBoolean("persist.demo.hdmirotationlock", false);
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001558
Chong Zhangae6119ff2014-11-11 18:54:39 -08001559 // For demo purposes, allow the rotation of the remote display to be controlled.
1560 // By default, remote display locks rotation to landscape.
1561 if ("portrait".equals(SystemProperties.get("persist.demo.remoterotation"))) {
1562 mDemoRotation = mPortraitRotation;
1563 } else {
1564 mDemoRotation = mLandscapeRotation;
1565 }
1566 mDemoRotationLock = SystemProperties.getBoolean(
1567 "persist.demo.rotationlock", false);
1568
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001569 // Only force the default orientation if the screen is xlarge, at least 960dp x 720dp, per
1570 // http://developer.android.com/guide/practices/screens_support.html#range
1571 mForceDefaultOrientation = longSizeDp >= 960 && shortSizeDp >= 720 &&
1572 res.getBoolean(com.android.internal.R.bool.config_forceDefaultOrientation) &&
1573 // For debug purposes the next line turns this feature off with:
1574 // $ adb shell setprop config.override_forced_orient true
1575 // $ adb shell wm size reset
1576 !"true".equals(SystemProperties.get("config.override_forced_orient"));
1577 }
1578
Alan Viverette5a0f4ec2013-10-07 15:10:29 -07001579 /**
1580 * @return whether the navigation bar can be hidden, e.g. the device has a
1581 * navigation bar and touch exploration is not enabled
1582 */
1583 private boolean canHideNavigationBar() {
Svetoslav8e3feb12014-02-24 13:46:47 -08001584 return mHasNavigationBar
1585 && !mAccessibilityManager.isTouchExplorationEnabled();
Alan Viverette5a0f4ec2013-10-07 15:10:29 -07001586 }
1587
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001588 @Override
1589 public boolean isDefaultOrientationForced() {
1590 return mForceDefaultOrientation;
Dianne Hackborn9d132642011-04-21 17:26:39 -07001591 }
1592
Dianne Hackbornc652de82013-02-15 16:32:56 -08001593 @Override
1594 public void setDisplayOverscan(Display display, int left, int top, int right, int bottom) {
1595 if (display.getDisplayId() == Display.DEFAULT_DISPLAY) {
1596 mOverscanLeft = left;
1597 mOverscanTop = top;
1598 mOverscanRight = right;
1599 mOverscanBottom = bottom;
1600 }
1601 }
1602
Dianne Hackbornc777e072010-02-12 13:07:59 -08001603 public void updateSettings() {
1604 ContentResolver resolver = mContext.getContentResolver();
1605 boolean updateRotation = false;
Dianne Hackbornc777e072010-02-12 13:07:59 -08001606 synchronized (mLock) {
Christopher Tate5e08af02012-09-21 17:17:22 -07001607 mEndcallBehavior = Settings.System.getIntForUser(resolver,
David Brownbaf8d092010-03-08 21:52:59 -08001608 Settings.System.END_BUTTON_BEHAVIOR,
Christopher Tate5e08af02012-09-21 17:17:22 -07001609 Settings.System.END_BUTTON_BEHAVIOR_DEFAULT,
1610 UserHandle.USER_CURRENT);
1611 mIncallPowerBehavior = Settings.Secure.getIntForUser(resolver,
David Brownbaf8d092010-03-08 21:52:59 -08001612 Settings.Secure.INCALL_POWER_BUTTON_BEHAVIOR,
Christopher Tate5e08af02012-09-21 17:17:22 -07001613 Settings.Secure.INCALL_POWER_BUTTON_BEHAVIOR_DEFAULT,
1614 UserHandle.USER_CURRENT);
Daniel Sandlerb73617d2010-08-17 00:41:00 -04001615
Jeff Browna20dda42014-05-27 20:57:24 -07001616 // Configure wake gesture.
1617 boolean wakeGestureEnabledSetting = Settings.Secure.getIntForUser(resolver,
1618 Settings.Secure.WAKE_GESTURE_ENABLED, 0,
1619 UserHandle.USER_CURRENT) != 0;
1620 if (mWakeGestureEnabledSetting != wakeGestureEnabledSetting) {
1621 mWakeGestureEnabledSetting = wakeGestureEnabledSetting;
1622 updateWakeGestureListenerLp();
1623 }
1624
Jeff Brown207673cd2012-06-05 17:47:11 -07001625 // Configure rotation lock.
Christopher Tate5e08af02012-09-21 17:17:22 -07001626 int userRotation = Settings.System.getIntForUser(resolver,
1627 Settings.System.USER_ROTATION, Surface.ROTATION_0,
1628 UserHandle.USER_CURRENT);
Jeff Brown207673cd2012-06-05 17:47:11 -07001629 if (mUserRotation != userRotation) {
1630 mUserRotation = userRotation;
1631 updateRotation = true;
1632 }
Christopher Tate5e08af02012-09-21 17:17:22 -07001633 int userRotationMode = Settings.System.getIntForUser(resolver,
1634 Settings.System.ACCELEROMETER_ROTATION, 0, UserHandle.USER_CURRENT) != 0 ?
Jeff Brown207673cd2012-06-05 17:47:11 -07001635 WindowManagerPolicy.USER_ROTATION_FREE :
1636 WindowManagerPolicy.USER_ROTATION_LOCKED;
1637 if (mUserRotationMode != userRotationMode) {
1638 mUserRotationMode = userRotationMode;
1639 updateRotation = true;
Dianne Hackbornc777e072010-02-12 13:07:59 -08001640 updateOrientationListenerLp();
1641 }
Daniel Sandlerb73617d2010-08-17 00:41:00 -04001642
Dianne Hackbornc777e072010-02-12 13:07:59 -08001643 if (mSystemReady) {
Christopher Tate5e08af02012-09-21 17:17:22 -07001644 int pointerLocation = Settings.System.getIntForUser(resolver,
1645 Settings.System.POINTER_LOCATION, 0, UserHandle.USER_CURRENT);
Dianne Hackbornc777e072010-02-12 13:07:59 -08001646 if (mPointerLocationMode != pointerLocation) {
1647 mPointerLocationMode = pointerLocation;
Jeff Brown70825162012-03-28 17:27:48 -07001648 mHandler.sendEmptyMessage(pointerLocation != 0 ?
1649 MSG_ENABLE_POINTER_LOCATION : MSG_DISABLE_POINTER_LOCATION);
Dianne Hackbornc777e072010-02-12 13:07:59 -08001650 }
1651 }
1652 // use screen off timeout setting as the timeout for the lockscreen
Christopher Tate5e08af02012-09-21 17:17:22 -07001653 mLockScreenTimeout = Settings.System.getIntForUser(resolver,
1654 Settings.System.SCREEN_OFF_TIMEOUT, 0, UserHandle.USER_CURRENT);
1655 String imId = Settings.Secure.getStringForUser(resolver,
1656 Settings.Secure.DEFAULT_INPUT_METHOD, UserHandle.USER_CURRENT);
Dianne Hackbornc777e072010-02-12 13:07:59 -08001657 boolean hasSoftInput = imId != null && imId.length() > 0;
1658 if (mHasSoftInput != hasSoftInput) {
1659 mHasSoftInput = hasSoftInput;
1660 updateRotation = true;
1661 }
John Spurlockf1a36642013-10-12 17:50:42 -04001662 if (mImmersiveModeConfirmation != null) {
John Spurlock4355a532014-02-19 09:49:25 -05001663 mImmersiveModeConfirmation.loadSetting(mCurrentUserId);
John Spurlockd67ec252013-09-05 11:31:54 -04001664 }
John Spurlockc6d1c602014-01-17 15:22:06 -05001665 PolicyControl.reloadFromSetting(mContext);
Dianne Hackbornc777e072010-02-12 13:07:59 -08001666 }
1667 if (updateRotation) {
Jeff Brown01a98dd2011-09-20 15:08:29 -07001668 updateRotation(true);
Dianne Hackbornc777e072010-02-12 13:07:59 -08001669 }
Jeff Brown70825162012-03-28 17:27:48 -07001670 }
1671
Jeff Browna20dda42014-05-27 20:57:24 -07001672 private void updateWakeGestureListenerLp() {
1673 if (shouldEnableWakeGestureLp()) {
1674 mWakeGestureListener.requestWakeUpTrigger();
1675 } else {
1676 mWakeGestureListener.cancelWakeUpTrigger();
1677 }
1678 }
1679
1680 private boolean shouldEnableWakeGestureLp() {
Jeff Brown3ee549c2014-09-22 20:14:39 -07001681 return mWakeGestureEnabledSetting && !mAwake
Jeff Browna20dda42014-05-27 20:57:24 -07001682 && (!mLidControlsSleep || mLidState != LID_CLOSED)
1683 && mWakeGestureListener.isSupported();
1684 }
1685
Jeff Brown70825162012-03-28 17:27:48 -07001686 private void enablePointerLocation() {
1687 if (mPointerLocationView == null) {
1688 mPointerLocationView = new PointerLocationView(mContext);
1689 mPointerLocationView.setPrintCoords(false);
Dianne Hackbornc777e072010-02-12 13:07:59 -08001690 WindowManager.LayoutParams lp = new WindowManager.LayoutParams(
1691 WindowManager.LayoutParams.MATCH_PARENT,
1692 WindowManager.LayoutParams.MATCH_PARENT);
Jeff Brown3b2b3542010-10-15 00:54:27 -07001693 lp.type = WindowManager.LayoutParams.TYPE_SECURE_SYSTEM_OVERLAY;
Jeff Brownbfcb60a2011-09-08 18:51:14 -07001694 lp.flags = WindowManager.LayoutParams.FLAG_FULLSCREEN
1695 | WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE
1696 | WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE
1697 | WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN;
Jeff Brown90fc9052012-10-01 14:44:24 -07001698 if (ActivityManager.isHighEndGfx()) {
1699 lp.flags |= WindowManager.LayoutParams.FLAG_HARDWARE_ACCELERATED;
1700 lp.privateFlags |=
1701 WindowManager.LayoutParams.PRIVATE_FLAG_FORCE_HARDWARE_ACCELERATED;
1702 }
Dianne Hackbornc777e072010-02-12 13:07:59 -08001703 lp.format = PixelFormat.TRANSLUCENT;
1704 lp.setTitle("PointerLocation");
Dianne Hackborn5fd21692011-06-07 14:09:47 -07001705 WindowManager wm = (WindowManager)
Dianne Hackbornc777e072010-02-12 13:07:59 -08001706 mContext.getSystemService(Context.WINDOW_SERVICE);
Jeff Browncc4f7db2011-08-30 20:34:48 -07001707 lp.inputFeatures |= WindowManager.LayoutParams.INPUT_FEATURE_NO_INPUT_CHANNEL;
Jeff Brown70825162012-03-28 17:27:48 -07001708 wm.addView(mPointerLocationView, lp);
Michael Wrightc9c487e2013-11-07 18:55:09 -08001709 mWindowManagerFuncs.registerPointerEventListener(mPointerLocationView);
Dianne Hackbornc777e072010-02-12 13:07:59 -08001710 }
Dianne Hackbornc777e072010-02-12 13:07:59 -08001711 }
Jeff Brown70825162012-03-28 17:27:48 -07001712
1713 private void disablePointerLocation() {
Jeff Brown70825162012-03-28 17:27:48 -07001714 if (mPointerLocationView != null) {
Michael Wrightc9c487e2013-11-07 18:55:09 -08001715 mWindowManagerFuncs.unregisterPointerEventListener(mPointerLocationView);
1716 WindowManager wm = (WindowManager) mContext.getSystemService(Context.WINDOW_SERVICE);
Jeff Brown70825162012-03-28 17:27:48 -07001717 wm.removeView(mPointerLocationView);
1718 mPointerLocationView = null;
1719 }
1720 }
1721
Mike Lockwood2d1efbd2009-09-16 12:15:53 -04001722 private int readRotation(int resID) {
Mike Lockwood1753f7f2009-08-24 14:49:07 -07001723 try {
1724 int rotation = mContext.getResources().getInteger(resID);
1725 switch (rotation) {
1726 case 0:
1727 return Surface.ROTATION_0;
1728 case 90:
1729 return Surface.ROTATION_90;
1730 case 180:
1731 return Surface.ROTATION_180;
1732 case 270:
1733 return Surface.ROTATION_270;
Mike Lockwood1753f7f2009-08-24 14:49:07 -07001734 }
1735 } catch (Resources.NotFoundException e) {
Mike Lockwood2d1efbd2009-09-16 12:15:53 -04001736 // fall through
Mike Lockwood1753f7f2009-08-24 14:49:07 -07001737 }
Mike Lockwood2d1efbd2009-09-16 12:15:53 -04001738 return -1;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001739 }
1740
1741 /** {@inheritDoc} */
Craig Mautner88400d32012-09-30 12:35:45 -07001742 @Override
Dianne Hackbornc2293022013-02-06 23:14:49 -08001743 public int checkAddPermission(WindowManager.LayoutParams attrs, int[] outAppOp) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001744 int type = attrs.type;
Dianne Hackbornc2293022013-02-06 23:14:49 -08001745
1746 outAppOp[0] = AppOpsManager.OP_NONE;
1747
Wale Ogunwale74bf0652015-01-12 10:24:36 -08001748 if (!((type >= FIRST_APPLICATION_WINDOW && type <= LAST_APPLICATION_WINDOW)
1749 || (type >= FIRST_SUB_WINDOW && type <= LAST_SUB_WINDOW)
1750 || (type >= FIRST_SYSTEM_WINDOW && type <= LAST_SYSTEM_WINDOW))) {
1751 return WindowManagerGlobal.ADD_INVALID_TYPE;
1752 }
1753
1754 if (type < FIRST_SYSTEM_WINDOW || type > LAST_SYSTEM_WINDOW) {
1755 // Window manager will make sure these are okay.
Jeff Brown98365d72012-08-19 20:30:52 -07001756 return WindowManagerGlobal.ADD_OKAY;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001757 }
1758 String permission = null;
1759 switch (type) {
1760 case TYPE_TOAST:
1761 // XXX right now the app process has complete control over
1762 // this... should introduce a token to let the system
1763 // monitor/control what they are doing.
Jason Monk1c7c3192014-06-26 12:52:18 -04001764 outAppOp[0] = AppOpsManager.OP_TOAST_WINDOW;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001765 break;
Daniel Sandler7d276c32012-01-30 14:33:52 -05001766 case TYPE_DREAM:
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001767 case TYPE_INPUT_METHOD:
Dianne Hackbornb7cd8b92009-08-08 20:53:03 -07001768 case TYPE_WALLPAPER:
keunyounga446bf02013-06-21 19:07:57 -07001769 case TYPE_PRIVATE_PRESENTATION:
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001770 case TYPE_VOICE_INTERACTION:
Svetoslav3a5c7212014-10-14 09:54:26 -07001771 case TYPE_ACCESSIBILITY_OVERLAY:
Dianne Hackbornb7cd8b92009-08-08 20:53:03 -07001772 // The window manager will check these.
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001773 break;
1774 case TYPE_PHONE:
1775 case TYPE_PRIORITY_PHONE:
1776 case TYPE_SYSTEM_ALERT:
1777 case TYPE_SYSTEM_ERROR:
1778 case TYPE_SYSTEM_OVERLAY:
1779 permission = android.Manifest.permission.SYSTEM_ALERT_WINDOW;
Dianne Hackbornc2293022013-02-06 23:14:49 -08001780 outAppOp[0] = AppOpsManager.OP_SYSTEM_ALERT_WINDOW;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001781 break;
1782 default:
1783 permission = android.Manifest.permission.INTERNAL_SYSTEM_WINDOW;
1784 }
1785 if (permission != null) {
1786 if (mContext.checkCallingOrSelfPermission(permission)
1787 != PackageManager.PERMISSION_GRANTED) {
Jeff Brown98365d72012-08-19 20:30:52 -07001788 return WindowManagerGlobal.ADD_PERMISSION_DENIED;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001789 }
1790 }
Jeff Brown98365d72012-08-19 20:30:52 -07001791 return WindowManagerGlobal.ADD_OKAY;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001792 }
Craig Mautner88400d32012-09-30 12:35:45 -07001793
1794 @Override
1795 public boolean checkShowToOwnerOnly(WindowManager.LayoutParams attrs) {
1796
1797 // If this switch statement is modified, modify the comment in the declarations of
1798 // the type in {@link WindowManager.LayoutParams} as well.
1799 switch (attrs.type) {
1800 default:
1801 // These are the windows that by default are shown only to the user that created
1802 // them. If this needs to be overridden, set
1803 // {@link WindowManager.LayoutParams.PRIVATE_FLAG_SHOW_FOR_ALL_USERS} in
1804 // {@link WindowManager.LayoutParams}. Note that permission
1805 // {@link android.Manifest.permission.INTERNAL_SYSTEM_WINDOW} is required as well.
1806 if ((attrs.privateFlags & PRIVATE_FLAG_SHOW_FOR_ALL_USERS) == 0) {
1807 return true;
1808 }
1809 break;
1810
1811 // These are the windows that by default are shown to all users. However, to
1812 // protect against spoofing, check permissions below.
1813 case TYPE_APPLICATION_STARTING:
1814 case TYPE_BOOT_PROGRESS:
1815 case TYPE_DISPLAY_OVERLAY:
1816 case TYPE_HIDDEN_NAV_CONSUMER:
Jim Miller5ecd8112013-01-09 18:50:26 -08001817 case TYPE_KEYGUARD_SCRIM:
Craig Mautner88400d32012-09-30 12:35:45 -07001818 case TYPE_KEYGUARD_DIALOG:
1819 case TYPE_MAGNIFICATION_OVERLAY:
1820 case TYPE_NAVIGATION_BAR:
1821 case TYPE_NAVIGATION_BAR_PANEL:
1822 case TYPE_PHONE:
1823 case TYPE_POINTER:
1824 case TYPE_PRIORITY_PHONE:
Craig Mautner88400d32012-09-30 12:35:45 -07001825 case TYPE_SEARCH_BAR:
1826 case TYPE_STATUS_BAR:
1827 case TYPE_STATUS_BAR_PANEL:
1828 case TYPE_STATUS_BAR_SUB_PANEL:
1829 case TYPE_SYSTEM_DIALOG:
Craig Mautner88400d32012-09-30 12:35:45 -07001830 case TYPE_VOLUME_OVERLAY:
keunyounga446bf02013-06-21 19:07:57 -07001831 case TYPE_PRIVATE_PRESENTATION:
Craig Mautner88400d32012-09-30 12:35:45 -07001832 break;
1833 }
1834
1835 // Check if third party app has set window to system window type.
1836 return mContext.checkCallingOrSelfPermission(
1837 android.Manifest.permission.INTERNAL_SYSTEM_WINDOW)
1838 != PackageManager.PERMISSION_GRANTED;
1839 }
1840
Craig Mautner967212c2013-04-13 21:10:58 -07001841 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001842 public void adjustWindowParamsLw(WindowManager.LayoutParams attrs) {
1843 switch (attrs.type) {
1844 case TYPE_SYSTEM_OVERLAY:
Jeff Brown3b2b3542010-10-15 00:54:27 -07001845 case TYPE_SECURE_SYSTEM_OVERLAY:
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001846 // These types of windows can't receive input events.
1847 attrs.flags |= WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE
1848 | WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE;
Jeff Brownbfcb60a2011-09-08 18:51:14 -07001849 attrs.flags &= ~WindowManager.LayoutParams.FLAG_WATCH_OUTSIDE_TOUCH;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001850 break;
Jorim Jaggi380ecb82014-03-14 17:25:20 +01001851 case TYPE_STATUS_BAR:
1852
1853 // If the Keyguard is in a hidden state (occluded by another window), we force to
1854 // remove the wallpaper and keyguard flag so that any change in-flight after setting
1855 // the keyguard as occluded wouldn't set these flags again.
1856 // See {@link #processKeyguardSetHiddenResultLw}.
1857 if (mKeyguardHidden) {
1858 attrs.flags &= ~WindowManager.LayoutParams.FLAG_SHOW_WALLPAPER;
1859 attrs.privateFlags &= ~WindowManager.LayoutParams.PRIVATE_FLAG_KEYGUARD;
1860 }
1861 break;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001862 }
Adrian Roos38502112014-04-09 21:04:11 +02001863
1864 if (attrs.type != TYPE_STATUS_BAR) {
1865 // The status bar is the only window allowed to exhibit keyguard behavior.
1866 attrs.privateFlags &= ~WindowManager.LayoutParams.PRIVATE_FLAG_KEYGUARD;
1867 }
Adrian Roosea562512014-05-05 13:33:03 +02001868
1869 if (ActivityManager.isHighEndGfx()
1870 && (attrs.flags & FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS) != 0) {
Adrian Roosf5e9b5c2014-09-10 15:27:41 +02001871 attrs.subtreeSystemUiVisibility |= View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
Adrian Roosea562512014-05-05 13:33:03 +02001872 | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION;
1873 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001874 }
RoboErik8a2cfc32014-05-16 11:19:38 -07001875
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001876 void readLidState() {
Jeff Brown2e7760e2012-04-11 15:14:55 -07001877 mLidState = mWindowManagerFuncs.getLidState();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001878 }
RoboErik8a2cfc32014-05-16 11:19:38 -07001879
Michael Wright3818c922014-09-02 13:59:07 -07001880 private void readCameraLensCoverState() {
1881 mCameraLensCoverState = mWindowManagerFuncs.getCameraLensCoverState();
1882 }
1883
Jeff Browndaa37532012-05-01 15:54:03 -07001884 private boolean isHidden(int accessibilityMode) {
1885 switch (accessibilityMode) {
1886 case 1:
1887 return mLidState == LID_CLOSED;
1888 case 2:
1889 return mLidState == LID_OPEN;
1890 default:
1891 return false;
Dianne Hackborn2862fff2009-09-15 22:56:29 -07001892 }
Dianne Hackborn2862fff2009-09-15 22:56:29 -07001893 }
Jeff Brownd04a88c2011-01-16 14:05:47 -08001894
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001895 /** {@inheritDoc} */
Craig Mautner967212c2013-04-13 21:10:58 -07001896 @Override
Jeff Browndaa37532012-05-01 15:54:03 -07001897 public void adjustConfigurationLw(Configuration config, int keyboardPresence,
1898 int navigationPresence) {
1899 mHaveBuiltInKeyboard = (keyboardPresence & PRESENCE_INTERNAL) != 0;
1900
Jeff Brownf71343d2013-05-31 17:59:11 -07001901 readConfigurationDependentBehaviors();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001902 readLidState();
Jeff Brownc458ce92012-04-30 14:58:40 -07001903 applyLidSwitchState();
Jeff Brownd04a88c2011-01-16 14:05:47 -08001904
Jeff Browndaa37532012-05-01 15:54:03 -07001905 if (config.keyboard == Configuration.KEYBOARD_NOKEYS
1906 || (keyboardPresence == PRESENCE_INTERNAL
1907 && isHidden(mLidKeyboardAccessibility))) {
Jeff Brownd04a88c2011-01-16 14:05:47 -08001908 config.hardKeyboardHidden = Configuration.HARDKEYBOARDHIDDEN_YES;
Jeff Browndaa37532012-05-01 15:54:03 -07001909 if (!mHasSoftInput) {
1910 config.keyboardHidden = Configuration.KEYBOARDHIDDEN_YES;
1911 }
Jeff Brownd04a88c2011-01-16 14:05:47 -08001912 }
1913
Jeff Browndaa37532012-05-01 15:54:03 -07001914 if (config.navigation == Configuration.NAVIGATION_NONAV
1915 || (navigationPresence == PRESENCE_INTERNAL
1916 && isHidden(mLidNavigationAccessibility))) {
Jeff Brownd04a88c2011-01-16 14:05:47 -08001917 config.navigationHidden = Configuration.NAVIGATIONHIDDEN_YES;
Jeff Brownd04a88c2011-01-16 14:05:47 -08001918 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001919 }
Jeff Brownd04a88c2011-01-16 14:05:47 -08001920
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001921 /** {@inheritDoc} */
Craig Mautner967212c2013-04-13 21:10:58 -07001922 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001923 public int windowTypeToLayerLw(int type) {
1924 if (type >= FIRST_APPLICATION_WINDOW && type <= LAST_APPLICATION_WINDOW) {
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001925 return 2;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001926 }
1927 switch (type) {
keunyounga446bf02013-06-21 19:07:57 -07001928 case TYPE_PRIVATE_PRESENTATION:
1929 return 2;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001930 case TYPE_WALLPAPER:
1931 // wallpaper is at the bottom, though the window manager may move it.
1932 return 2;
1933 case TYPE_PHONE:
1934 return 3;
1935 case TYPE_SEARCH_BAR:
Jorim Jaggi225d3b52015-04-01 11:18:57 -07001936 case TYPE_VOICE_INTERACTION_STARTING:
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001937 return 4;
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001938 case TYPE_VOICE_INTERACTION:
1939 // voice interaction layer is almost immediately above apps.
1940 return 5;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001941 case TYPE_SYSTEM_DIALOG:
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001942 return 6;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001943 case TYPE_TOAST:
1944 // toasts and the plugged-in battery thing
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001945 return 7;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001946 case TYPE_PRIORITY_PHONE:
1947 // SIM errors and unlock. Not sure if this really should be in a high layer.
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001948 return 8;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001949 case TYPE_DREAM:
1950 // used for Dreams (screensavers with TYPE_DREAM windows)
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001951 return 9;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001952 case TYPE_SYSTEM_ALERT:
1953 // like the ANR / app crashed dialogs
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001954 return 10;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001955 case TYPE_INPUT_METHOD:
1956 // on-screen keyboards and other such input method user interfaces go here.
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001957 return 11;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001958 case TYPE_INPUT_METHOD_DIALOG:
1959 // on-screen keyboards and other such input method user interfaces go here.
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001960 return 12;
Jim Miller5ecd8112013-01-09 18:50:26 -08001961 case TYPE_KEYGUARD_SCRIM:
1962 // the safety window that shows behind keyguard while keyguard is starting
Jorim Jaggi380ecb82014-03-14 17:25:20 +01001963 return 13;
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001964 case TYPE_STATUS_BAR_SUB_PANEL:
Jorim Jaggi380ecb82014-03-14 17:25:20 +01001965 return 14;
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001966 case TYPE_STATUS_BAR:
Jorim Jaggi380ecb82014-03-14 17:25:20 +01001967 return 15;
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001968 case TYPE_STATUS_BAR_PANEL:
Jorim Jaggi380ecb82014-03-14 17:25:20 +01001969 return 16;
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001970 case TYPE_KEYGUARD_DIALOG:
1971 return 17;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001972 case TYPE_VOLUME_OVERLAY:
1973 // the on-screen volume indicator and controller shown when the user
1974 // changes the device volume
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001975 return 18;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001976 case TYPE_SYSTEM_OVERLAY:
1977 // the on-screen volume indicator and controller shown when the user
1978 // changes the device volume
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001979 return 19;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001980 case TYPE_NAVIGATION_BAR:
1981 // the navigation bar, if available, shows atop most things
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001982 return 20;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001983 case TYPE_NAVIGATION_BAR_PANEL:
1984 // some panels (e.g. search) need to show on top of the navigation bar
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001985 return 21;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001986 case TYPE_SYSTEM_ERROR:
1987 // system-level error dialogs
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001988 return 22;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001989 case TYPE_MAGNIFICATION_OVERLAY:
1990 // used to highlight the magnified portion of a display
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001991 return 23;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001992 case TYPE_DISPLAY_OVERLAY:
1993 // used to simulate secondary display devices
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001994 return 24;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001995 case TYPE_DRAG:
1996 // the drag layer: input for drag-and-drop is associated with this window,
1997 // which sits above all other focusable windows
Jorim Jaggi380ecb82014-03-14 17:25:20 +01001998 return 25;
Svetoslav3a5c7212014-10-14 09:54:26 -07001999 case TYPE_ACCESSIBILITY_OVERLAY:
2000 // overlay put by accessibility services to intercept user interaction
Jorim Jaggi380ecb82014-03-14 17:25:20 +01002001 return 26;
Svetoslav3a5c7212014-10-14 09:54:26 -07002002 case TYPE_SECURE_SYSTEM_OVERLAY:
Dianne Hackborne30e02f2014-05-27 18:24:45 -07002003 return 27;
Svetoslav3a5c7212014-10-14 09:54:26 -07002004 case TYPE_BOOT_PROGRESS:
2005 return 28;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07002006 case TYPE_POINTER:
2007 // the (mouse) pointer layer
Dianne Hackborne30e02f2014-05-27 18:24:45 -07002008 return 29;
Svetoslav3a5c7212014-10-14 09:54:26 -07002009 case TYPE_HIDDEN_NAV_CONSUMER:
2010 return 30;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002011 }
2012 Log.e(TAG, "Unknown window type: " + type);
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07002013 return 2;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002014 }
2015
2016 /** {@inheritDoc} */
Craig Mautner46ac6fa2013-08-01 10:06:34 -07002017 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002018 public int subWindowTypeToLayerLw(int type) {
2019 switch (type) {
2020 case TYPE_APPLICATION_PANEL:
2021 case TYPE_APPLICATION_ATTACHED_DIALOG:
2022 return APPLICATION_PANEL_SUBLAYER;
2023 case TYPE_APPLICATION_MEDIA:
2024 return APPLICATION_MEDIA_SUBLAYER;
Dianne Hackborn5cb8d792009-05-21 17:34:15 -07002025 case TYPE_APPLICATION_MEDIA_OVERLAY:
2026 return APPLICATION_MEDIA_OVERLAY_SUBLAYER;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002027 case TYPE_APPLICATION_SUB_PANEL:
2028 return APPLICATION_SUB_PANEL_SUBLAYER;
Wale Ogunwale0a4dc222015-04-14 12:58:42 -07002029 case TYPE_APPLICATION_ABOVE_SUB_PANEL:
2030 return APPLICATION_ABOVE_SUB_PANEL_SUBLAYER;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002031 }
2032 Log.e(TAG, "Unknown sub-window type: " + type);
2033 return 0;
2034 }
2035
Craig Mautner46ac6fa2013-08-01 10:06:34 -07002036 @Override
Dianne Hackbornabe0da02009-09-18 01:55:39 -07002037 public int getMaxWallpaperLayer() {
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07002038 return windowTypeToLayerLw(TYPE_STATUS_BAR);
Dianne Hackbornabe0da02009-09-18 01:55:39 -07002039 }
2040
Craig Mautner46ac6fa2013-08-01 10:06:34 -07002041 @Override
Dianne Hackborn1f903c32011-09-13 19:18:06 -07002042 public int getNonDecorDisplayWidth(int fullWidth, int fullHeight, int rotation) {
Dianne Hackborn077ee852012-04-09 16:27:07 -07002043 if (mHasNavigationBar) {
2044 // For a basic navigation bar, when we are in landscape mode we place
2045 // the navigation bar to the side.
Daniel Sandler4a066c52012-04-20 14:49:13 -04002046 if (mNavigationBarCanMove && fullWidth > fullHeight) {
2047 return fullWidth - mNavigationBarWidthForRotation[rotation];
Dianne Hackborn077ee852012-04-09 16:27:07 -07002048 }
Dianne Hackborn1f903c32011-09-13 19:18:06 -07002049 }
2050 return fullWidth;
Dianne Hackborne2515ee2011-04-27 18:52:56 -04002051 }
2052
Jose Lima9546b202014-07-02 17:21:51 -07002053 @Override
Dianne Hackborn1f903c32011-09-13 19:18:06 -07002054 public int getNonDecorDisplayHeight(int fullWidth, int fullHeight, int rotation) {
Dianne Hackborn077ee852012-04-09 16:27:07 -07002055 if (mHasNavigationBar) {
2056 // For a basic navigation bar, when we are in portrait mode we place
2057 // the navigation bar to the bottom.
Daniel Sandler4a066c52012-04-20 14:49:13 -04002058 if (!mNavigationBarCanMove || fullWidth < fullHeight) {
2059 return fullHeight - mNavigationBarHeightForRotation[rotation];
Dianne Hackborn077ee852012-04-09 16:27:07 -07002060 }
2061 }
2062 return fullHeight;
Dianne Hackborn69cb8752011-05-19 18:13:32 -07002063 }
2064
Jose Lima9546b202014-07-02 17:21:51 -07002065 @Override
Dianne Hackborn1f903c32011-09-13 19:18:06 -07002066 public int getConfigDisplayWidth(int fullWidth, int fullHeight, int rotation) {
2067 return getNonDecorDisplayWidth(fullWidth, fullHeight, rotation);
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 getConfigDisplayHeight(int fullWidth, int fullHeight, int rotation) {
John Spurlock80f00c12013-06-13 11:10:51 -04002072 // There is a separate status bar at the top of the display. We don't count that as part
2073 // of the fixed decor, since it can hide; however, for purposes of configurations,
Dianne Hackborn077ee852012-04-09 16:27:07 -07002074 // we do want to exclude it since applications can't generally use that part
2075 // of the screen.
John Spurlock80f00c12013-06-13 11:10:51 -04002076 return getNonDecorDisplayHeight(fullWidth, fullHeight, rotation) - mStatusBarHeight;
Dianne Hackborne2515ee2011-04-27 18:52:56 -04002077 }
2078
Craig Mautnera3f4bf52012-10-10 20:37:48 -07002079 @Override
Craig Mautnerc9457fa2014-06-06 14:27:48 -07002080 public boolean isForceHiding(WindowManager.LayoutParams attrs) {
2081 return (attrs.privateFlags & PRIVATE_FLAG_KEYGUARD) != 0 ||
Jim Millerab954542014-10-10 18:21:49 -07002082 (isKeyguardHostWindow(attrs) &&
2083 (mKeyguardDelegate != null && mKeyguardDelegate.isShowing())) ||
Adrian Roos69e510d2014-07-13 14:57:59 +02002084 (attrs.type == TYPE_KEYGUARD_SCRIM);
Dianne Hackborn01ad2f42009-09-24 19:24:56 -07002085 }
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07002086
Craig Mautnera3f4bf52012-10-10 20:37:48 -07002087 @Override
Jorim Jaggi0d674622014-05-21 01:34:15 +02002088 public boolean isKeyguardHostWindow(WindowManager.LayoutParams attrs) {
2089 return attrs.type == TYPE_STATUS_BAR;
2090 }
2091
2092 @Override
Dianne Hackborn01ad2f42009-09-24 19:24:56 -07002093 public boolean canBeForceHidden(WindowState win, WindowManager.LayoutParams attrs) {
Craig Mautnera3f4bf52012-10-10 20:37:48 -07002094 switch (attrs.type) {
2095 case TYPE_STATUS_BAR:
2096 case TYPE_NAVIGATION_BAR:
2097 case TYPE_WALLPAPER:
2098 case TYPE_DREAM:
Jim Miller5ecd8112013-01-09 18:50:26 -08002099 case TYPE_KEYGUARD_SCRIM:
Craig Mautnera3f4bf52012-10-10 20:37:48 -07002100 return false;
2101 default:
2102 return true;
2103 }
Dianne Hackborn01ad2f42009-09-24 19:24:56 -07002104 }
Craig Mautner8e4df6c2012-05-23 16:57:23 -07002105
Craig Mautner7d7808f2014-09-11 18:02:38 -07002106 @Override
2107 public WindowState getWinShowWhenLockedLw() {
2108 return mWinShowWhenLocked;
2109 }
2110
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002111 /** {@inheritDoc} */
Craig Mautner8e4df6c2012-05-23 16:57:23 -07002112 @Override
Dianne Hackborn2f0b1752011-05-31 17:59:49 -07002113 public View addStartingWindow(IBinder appToken, String packageName, int theme,
2114 CompatibilityInfo compatInfo, CharSequence nonLocalizedLabel, int labelRes,
Adam Powell04fe6eb2013-05-31 14:39:48 -07002115 int icon, int logo, int windowFlags) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002116 if (!SHOW_STARTING_ANIMATIONS) {
2117 return null;
2118 }
2119 if (packageName == null) {
2120 return null;
2121 }
Craig Mautner8e4df6c2012-05-23 16:57:23 -07002122
Mathias Jeppssond1443e92012-08-24 15:25:32 +02002123 WindowManager wm = null;
2124 View view = null;
2125
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002126 try {
Dianne Hackborn867ab6472010-04-29 13:28:56 -07002127 Context context = mContext;
Craig Mautner6fbda632012-07-03 09:26:39 -07002128 if (DEBUG_STARTING_WINDOW) Slog.d(TAG, "addStartingWindow " + packageName
2129 + ": nonLocalizedLabel=" + nonLocalizedLabel + " theme="
2130 + Integer.toHexString(theme));
Dianne Hackborn247fe742011-01-08 17:25:57 -08002131 if (theme != context.getThemeResId() || labelRes != 0) {
Dianne Hackborn867ab6472010-04-29 13:28:56 -07002132 try {
2133 context = context.createPackageContext(packageName, 0);
Dianne Hackborn247fe742011-01-08 17:25:57 -08002134 context.setTheme(theme);
Dianne Hackborn867ab6472010-04-29 13:28:56 -07002135 } catch (PackageManager.NameNotFoundException e) {
2136 // Ignore
2137 }
2138 }
Craig Mautner8e4df6c2012-05-23 16:57:23 -07002139
Jorim Jaggib10e33f2015-02-04 21:57:40 +01002140 Window win = new PhoneWindow(context);
Craig Mautner8e4df6c2012-05-23 16:57:23 -07002141 final TypedArray ta = win.getWindowStyle();
2142 if (ta.getBoolean(
2143 com.android.internal.R.styleable.Window_windowDisablePreview, false)
2144 || ta.getBoolean(
2145 com.android.internal.R.styleable.Window_windowShowWallpaper,false)) {
Dianne Hackborn867ab6472010-04-29 13:28:56 -07002146 return null;
2147 }
Craig Mautner8e4df6c2012-05-23 16:57:23 -07002148
Dianne Hackborn867ab6472010-04-29 13:28:56 -07002149 Resources r = context.getResources();
2150 win.setTitle(r.getText(labelRes, nonLocalizedLabel));
Craig Mautner8e4df6c2012-05-23 16:57:23 -07002151
Dianne Hackborn867ab6472010-04-29 13:28:56 -07002152 win.setType(
2153 WindowManager.LayoutParams.TYPE_APPLICATION_STARTING);
Adrian Roos602c68e2015-04-24 16:03:47 -07002154
2155 synchronized (mWindowManagerFuncs.getWindowManagerLock()) {
2156 // Assumes it's safe to show starting windows of launched apps while
2157 // the keyguard is being hidden. This is okay because starting windows never show
2158 // secret information.
2159 if (mKeyguardHidden) {
2160 windowFlags |= FLAG_SHOW_WHEN_LOCKED;
2161 }
2162 }
2163
Dianne Hackborn867ab6472010-04-29 13:28:56 -07002164 // Force the window flags: this is a fake window, so it is not really
2165 // touchable or focusable by the user. We also add in the ALT_FOCUSABLE_IM
2166 // flag because we do know that the next window will take input
2167 // focus, so we want to get the IME window up on top of us right away.
2168 win.setFlags(
Dianne Hackborn7eec10e2010-11-12 18:03:47 -08002169 windowFlags|
Dianne Hackborn867ab6472010-04-29 13:28:56 -07002170 WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE|
2171 WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE|
2172 WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM,
Dianne Hackborn7eec10e2010-11-12 18:03:47 -08002173 windowFlags|
Dianne Hackborn867ab6472010-04-29 13:28:56 -07002174 WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE|
2175 WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE|
2176 WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM);
Craig Mautner8e4df6c2012-05-23 16:57:23 -07002177
Adam Powell04fe6eb2013-05-31 14:39:48 -07002178 win.setDefaultIcon(icon);
2179 win.setDefaultLogo(logo);
2180
Dianne Hackborn867ab6472010-04-29 13:28:56 -07002181 win.setLayout(WindowManager.LayoutParams.MATCH_PARENT,
Dianne Hackborn2f0b1752011-05-31 17:59:49 -07002182 WindowManager.LayoutParams.MATCH_PARENT);
Craig Mautner8e4df6c2012-05-23 16:57:23 -07002183
Dianne Hackborn867ab6472010-04-29 13:28:56 -07002184 final WindowManager.LayoutParams params = win.getAttributes();
2185 params.token = appToken;
2186 params.packageName = packageName;
2187 params.windowAnimations = win.getWindowStyle().getResourceId(
2188 com.android.internal.R.styleable.Window_windowAnimationStyle, 0);
John Reck61375a82014-09-18 19:27:48 +00002189 params.privateFlags |=
2190 WindowManager.LayoutParams.PRIVATE_FLAG_FAKE_HARDWARE_ACCELERATED;
Craig Mautner88400d32012-09-30 12:35:45 -07002191 params.privateFlags |= WindowManager.LayoutParams.PRIVATE_FLAG_SHOW_FOR_ALL_USERS;
Adam Lesinski95c42972013-10-02 10:13:27 -07002192
2193 if (!compatInfo.supportsScreen()) {
2194 params.privateFlags |= WindowManager.LayoutParams.PRIVATE_FLAG_COMPATIBLE_WINDOW;
2195 }
2196
Dianne Hackborn867ab6472010-04-29 13:28:56 -07002197 params.setTitle("Starting " + packageName);
2198
Mathias Jeppssond1443e92012-08-24 15:25:32 +02002199 wm = (WindowManager)context.getSystemService(Context.WINDOW_SERVICE);
2200 view = win.getDecorView();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002201
2202 if (win.isFloating()) {
2203 // Whoops, there is no way to display an animation/preview
2204 // of such a thing! After all that work... let's skip it.
2205 // (Note that we must do this here because it is in
2206 // getDecorView() where the theme is evaluated... maybe
2207 // we should peek the floating attribute from the theme
2208 // earlier.)
2209 return null;
2210 }
Craig Mautner8e4df6c2012-05-23 16:57:23 -07002211
Craig Mautner6fbda632012-07-03 09:26:39 -07002212 if (DEBUG_STARTING_WINDOW) Slog.d(
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002213 TAG, "Adding starting window for " + packageName
2214 + " / " + appToken + ": "
2215 + (view.getParent() != null ? view : null));
2216
2217 wm.addView(view, params);
2218
2219 // Only return the view if it was successfully added to the
2220 // window manager... which we can tell by it having a parent.
2221 return view.getParent() != null ? view : null;
Jeff Brown98365d72012-08-19 20:30:52 -07002222 } catch (WindowManager.BadTokenException e) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002223 // ignore
Craig Mautner42bf39e2014-02-21 16:46:22 -08002224 Log.w(TAG, appToken + " already running, starting window not displayed. " +
2225 e.getMessage());
Dianne Hackborn867ab6472010-04-29 13:28:56 -07002226 } catch (RuntimeException e) {
2227 // don't crash if something else bad happens, for example a
2228 // failure loading resources because we are loading from an app
2229 // on external storage that has been unmounted.
2230 Log.w(TAG, appToken + " failed creating starting window", e);
Mathias Jeppssond1443e92012-08-24 15:25:32 +02002231 } finally {
2232 if (view != null && view.getParent() == null) {
2233 Log.w(TAG, "view not successfully added to wm, removing view");
2234 wm.removeViewImmediate(view);
2235 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002236 }
2237
2238 return null;
2239 }
2240
2241 /** {@inheritDoc} */
Jose Lima9546b202014-07-02 17:21:51 -07002242 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002243 public void removeStartingWindow(IBinder appToken, View window) {
Craig Mautner276a6eb2014-11-04 15:32:57 -08002244 if (DEBUG_STARTING_WINDOW) Slog.v(TAG, "Removing starting window for " + appToken + ": "
2245 + window + " Callers=" + Debug.getCallers(4));
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002246
2247 if (window != null) {
Dianne Hackborn5fd21692011-06-07 14:09:47 -07002248 WindowManager wm = (WindowManager)mContext.getSystemService(Context.WINDOW_SERVICE);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002249 wm.removeView(window);
2250 }
2251 }
2252
2253 /**
2254 * Preflight adding a window to the system.
RoboErik8a2cfc32014-05-16 11:19:38 -07002255 *
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002256 * Currently enforces that three window types are singletons:
2257 * <ul>
2258 * <li>STATUS_BAR_TYPE</li>
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002259 * <li>KEYGUARD_TYPE</li>
2260 * </ul>
RoboErik8a2cfc32014-05-16 11:19:38 -07002261 *
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002262 * @param win The window to be added
2263 * @param attrs Information about the window to be added
RoboErik8a2cfc32014-05-16 11:19:38 -07002264 *
Jeff Brown98365d72012-08-19 20:30:52 -07002265 * @return If ok, WindowManagerImpl.ADD_OKAY. If too many singletons,
2266 * WindowManagerImpl.ADD_MULTIPLE_SINGLETON
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002267 */
Jose Lima9546b202014-07-02 17:21:51 -07002268 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002269 public int prepareAddWindowLw(WindowState win, WindowManager.LayoutParams attrs) {
2270 switch (attrs.type) {
2271 case TYPE_STATUS_BAR:
Joe Onorato8bc6c512010-06-04 16:21:12 -04002272 mContext.enforceCallingOrSelfPermission(
2273 android.Manifest.permission.STATUS_BAR_SERVICE,
2274 "PhoneWindowManager");
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002275 if (mStatusBar != null) {
Dianne Hackbornf87d1962012-04-04 12:48:24 -07002276 if (mStatusBar.isAlive()) {
Jeff Brown98365d72012-08-19 20:30:52 -07002277 return WindowManagerGlobal.ADD_MULTIPLE_SINGLETON;
Dianne Hackbornf87d1962012-04-04 12:48:24 -07002278 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002279 }
2280 mStatusBar = win;
John Spurlock27735a42013-08-14 17:57:38 -04002281 mStatusBarController.setWindow(win);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002282 break;
Daniel Sandler8956dbb2011-04-22 07:55:02 -04002283 case TYPE_NAVIGATION_BAR:
2284 mContext.enforceCallingOrSelfPermission(
2285 android.Manifest.permission.STATUS_BAR_SERVICE,
2286 "PhoneWindowManager");
Dianne Hackbornf87d1962012-04-04 12:48:24 -07002287 if (mNavigationBar != null) {
2288 if (mNavigationBar.isAlive()) {
Jeff Brown98365d72012-08-19 20:30:52 -07002289 return WindowManagerGlobal.ADD_MULTIPLE_SINGLETON;
Dianne Hackbornf87d1962012-04-04 12:48:24 -07002290 }
2291 }
Daniel Sandler8956dbb2011-04-22 07:55:02 -04002292 mNavigationBar = win;
John Spurlock27735a42013-08-14 17:57:38 -04002293 mNavigationBarController.setWindow(win);
Craig Mautnereda67292013-04-28 13:50:14 -07002294 if (DEBUG_LAYOUT) Slog.i(TAG, "NAVIGATION BAR: " + mNavigationBar);
Daniel Sandler8956dbb2011-04-22 07:55:02 -04002295 break;
Jim Millere898ac52012-04-06 17:10:57 -07002296 case TYPE_NAVIGATION_BAR_PANEL:
Dianne Hackborn08743722009-12-21 12:16:51 -08002297 case TYPE_STATUS_BAR_PANEL:
Joe Onorato29fc2c92010-11-24 10:26:50 -08002298 case TYPE_STATUS_BAR_SUB_PANEL:
Jorim Jaggi225d3b52015-04-01 11:18:57 -07002299 case TYPE_VOICE_INTERACTION_STARTING:
Joe Onorato29fc2c92010-11-24 10:26:50 -08002300 mContext.enforceCallingOrSelfPermission(
2301 android.Manifest.permission.STATUS_BAR_SERVICE,
2302 "PhoneWindowManager");
Joe Onorato29fc2c92010-11-24 10:26:50 -08002303 break;
Jim Miller5ecd8112013-01-09 18:50:26 -08002304 case TYPE_KEYGUARD_SCRIM:
Jim Miller25190572013-02-28 17:36:24 -08002305 if (mKeyguardScrim != null) {
2306 return WindowManagerGlobal.ADD_MULTIPLE_SINGLETON;
2307 }
Jim Miller5ecd8112013-01-09 18:50:26 -08002308 mKeyguardScrim = win;
2309 break;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002310 }
Jeff Brown98365d72012-08-19 20:30:52 -07002311 return WindowManagerGlobal.ADD_OKAY;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002312 }
2313
2314 /** {@inheritDoc} */
Jose Lima9546b202014-07-02 17:21:51 -07002315 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002316 public void removeWindowLw(WindowState win) {
2317 if (mStatusBar == win) {
2318 mStatusBar = null;
John Spurlock27735a42013-08-14 17:57:38 -04002319 mStatusBarController.setWindow(null);
Jim Millerc0b676d2013-03-22 16:11:08 -07002320 mKeyguardDelegate.showScrim();
Jim Miller5ecd8112013-01-09 18:50:26 -08002321 } else if (mKeyguardScrim == win) {
2322 Log.v(TAG, "Removing keyguard scrim");
2323 mKeyguardScrim = null;
2324 } if (mNavigationBar == win) {
Daniel Sandler8956dbb2011-04-22 07:55:02 -04002325 mNavigationBar = null;
John Spurlock27735a42013-08-14 17:57:38 -04002326 mNavigationBarController.setWindow(null);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002327 }
2328 }
2329
2330 static final boolean PRINT_ANIM = false;
RoboErik8a2cfc32014-05-16 11:19:38 -07002331
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002332 /** {@inheritDoc} */
Craig Mautner4b71aa12012-12-27 17:20:01 -08002333 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002334 public int selectAnimationLw(WindowState win, int transit) {
2335 if (PRINT_ANIM) Log.i(TAG, "selectAnimation in " + win
2336 + ": transit=" + transit);
Dianne Hackbornf87d1962012-04-04 12:48:24 -07002337 if (win == mStatusBar) {
Jorim Jaggi380ecb82014-03-14 17:25:20 +01002338 boolean isKeyguard = (win.getAttrs().privateFlags & PRIVATE_FLAG_KEYGUARD) != 0;
Craig Mautner4b71aa12012-12-27 17:20:01 -08002339 if (transit == TRANSIT_EXIT
2340 || transit == TRANSIT_HIDE) {
Jorim Jaggi380ecb82014-03-14 17:25:20 +01002341 return isKeyguard ? -1 : R.anim.dock_top_exit;
Craig Mautner4b71aa12012-12-27 17:20:01 -08002342 } else if (transit == TRANSIT_ENTER
2343 || transit == TRANSIT_SHOW) {
Jorim Jaggi380ecb82014-03-14 17:25:20 +01002344 return isKeyguard ? -1 : R.anim.dock_top_enter;
Dianne Hackbornf87d1962012-04-04 12:48:24 -07002345 }
2346 } else if (win == mNavigationBar) {
2347 // This can be on either the bottom or the right.
2348 if (mNavigationBarOnBottom) {
Craig Mautner4b71aa12012-12-27 17:20:01 -08002349 if (transit == TRANSIT_EXIT
2350 || transit == TRANSIT_HIDE) {
Dianne Hackbornf87d1962012-04-04 12:48:24 -07002351 return R.anim.dock_bottom_exit;
Craig Mautner4b71aa12012-12-27 17:20:01 -08002352 } else if (transit == TRANSIT_ENTER
2353 || transit == TRANSIT_SHOW) {
Dianne Hackbornf87d1962012-04-04 12:48:24 -07002354 return R.anim.dock_bottom_enter;
2355 }
2356 } else {
Craig Mautner4b71aa12012-12-27 17:20:01 -08002357 if (transit == TRANSIT_EXIT
2358 || transit == TRANSIT_HIDE) {
Dianne Hackbornf87d1962012-04-04 12:48:24 -07002359 return R.anim.dock_right_exit;
Craig Mautner4b71aa12012-12-27 17:20:01 -08002360 } else if (transit == TRANSIT_ENTER
2361 || transit == TRANSIT_SHOW) {
Dianne Hackbornf87d1962012-04-04 12:48:24 -07002362 return R.anim.dock_right_enter;
2363 }
2364 }
Craig Mautner4b71aa12012-12-27 17:20:01 -08002365 }
2366
2367 if (transit == TRANSIT_PREVIEW_DONE) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002368 if (win.hasAppShownWindows()) {
2369 if (PRINT_ANIM) Log.i(TAG, "**** STARTING EXIT");
2370 return com.android.internal.R.anim.app_starting_exit;
2371 }
Dianne Hackborn7ad44382012-10-18 17:46:00 -07002372 } else if (win.getAttrs().type == TYPE_DREAM && mDreamingLockscreen
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07002373 && transit == TRANSIT_ENTER) {
2374 // Special case: we are animating in a dream, while the keyguard
2375 // is shown. We don't want an animation on the dream, because
2376 // we need it shown immediately with the keyguard animating away
2377 // to reveal it.
2378 return -1;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002379 }
2380
2381 return 0;
2382 }
2383
Craig Mautner3c174372013-02-21 17:54:37 -08002384 @Override
2385 public void selectRotationAnimationLw(int anim[]) {
2386 if (PRINT_ANIM) Slog.i(TAG, "selectRotationAnimation mTopFullscreen="
2387 + mTopFullscreenOpaqueWindowState + " rotationAnimation="
2388 + (mTopFullscreenOpaqueWindowState == null ?
2389 "0" : mTopFullscreenOpaqueWindowState.getAttrs().rotationAnimation));
2390 if (mTopFullscreenOpaqueWindowState != null && mTopIsFullscreen) {
2391 switch (mTopFullscreenOpaqueWindowState.getAttrs().rotationAnimation) {
2392 case ROTATION_ANIMATION_CROSSFADE:
2393 anim[0] = R.anim.rotation_animation_xfade_exit;
2394 anim[1] = R.anim.rotation_animation_enter;
2395 break;
2396 case ROTATION_ANIMATION_JUMPCUT:
2397 anim[0] = R.anim.rotation_animation_jump_exit;
2398 anim[1] = R.anim.rotation_animation_enter;
2399 break;
2400 case ROTATION_ANIMATION_ROTATE:
2401 default:
2402 anim[0] = anim[1] = 0;
2403 break;
2404 }
2405 } else {
2406 anim[0] = anim[1] = 0;
2407 }
2408 }
2409
2410 @Override
2411 public boolean validateRotationAnimationLw(int exitAnimId, int enterAnimId,
2412 boolean forceDefault) {
2413 switch (exitAnimId) {
2414 case R.anim.rotation_animation_xfade_exit:
2415 case R.anim.rotation_animation_jump_exit:
2416 // These are the only cases that matter.
2417 if (forceDefault) {
2418 return false;
2419 }
2420 int anim[] = new int[2];
2421 selectRotationAnimationLw(anim);
2422 return (exitAnimId == anim[0] && enterAnimId == anim[1]);
2423 default:
2424 return true;
2425 }
2426 }
2427
2428 @Override
Jorim Jaggi84a3e7a2014-08-13 17:58:58 +02002429 public Animation createForceHideEnterAnimation(boolean onWallpaper,
2430 boolean goingToNotificationShade) {
2431 if (goingToNotificationShade) {
2432 return AnimationUtils.loadAnimation(mContext, R.anim.lock_screen_behind_enter_fade_in);
Craig Mautnerb8340802014-11-04 15:32:57 -08002433 }
Craig Mautner276a6eb2014-11-04 15:32:57 -08002434
2435 AnimationSet set = (AnimationSet) AnimationUtils.loadAnimation(mContext, onWallpaper ?
2436 R.anim.lock_screen_behind_enter_wallpaper :
2437 R.anim.lock_screen_behind_enter);
2438
2439 // TODO: Use XML interpolators when we have log interpolators available in XML.
2440 final List<Animation> animations = set.getAnimations();
2441 for (int i = animations.size() - 1; i >= 0; --i) {
2442 animations.get(i).setInterpolator(mLogDecelerateInterpolator);
2443 }
2444
2445 return set;
Jorim Jaggi76a16232014-08-08 17:00:47 +02002446 }
2447
2448
2449 @Override
Jorim Jaggi84a3e7a2014-08-13 17:58:58 +02002450 public Animation createForceHideWallpaperExitAnimation(boolean goingToNotificationShade) {
2451 if (goingToNotificationShade) {
2452 return null;
2453 } else {
2454 return AnimationUtils.loadAnimation(mContext, R.anim.lock_screen_wallpaper_exit);
2455 }
Dianne Hackborn01ad2f42009-09-24 19:24:56 -07002456 }
John Spurlockc8b46ca2013-04-08 12:59:26 -04002457
2458 private static void awakenDreams() {
2459 IDreamManager dreamManager = getDreamManager();
2460 if (dreamManager != null) {
2461 try {
2462 dreamManager.awaken();
2463 } catch (RemoteException e) {
2464 // fine, stay asleep then
2465 }
2466 }
2467 }
2468
2469 static IDreamManager getDreamManager() {
2470 return IDreamManager.Stub.asInterface(
2471 ServiceManager.checkService(DreamService.DREAM_SERVICE));
2472 }
2473
Tyler Gunnef9f6f92014-09-12 22:16:17 -07002474 TelecomManager getTelecommService() {
2475 return (TelecomManager) mContext.getSystemService(Context.TELECOM_SERVICE);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002476 }
2477
Jeff Brown4d396052010-10-29 21:50:21 -07002478 static IAudioService getAudioService() {
2479 IAudioService audioService = IAudioService.Stub.asInterface(
2480 ServiceManager.checkService(Context.AUDIO_SERVICE));
2481 if (audioService == null) {
2482 Log.w(TAG, "Unable to find IAudioService interface.");
2483 }
2484 return audioService;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002485 }
2486
2487 boolean keyguardOn() {
Jim Millerab954542014-10-10 18:21:49 -07002488 return isKeyguardShowingAndNotOccluded() || inKeyguardRestrictedKeyInputMode();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002489 }
2490
2491 private static final int[] WINDOW_TYPES_WHERE_HOME_DOESNT_WORK = {
2492 WindowManager.LayoutParams.TYPE_SYSTEM_ALERT,
2493 WindowManager.LayoutParams.TYPE_SYSTEM_ERROR,
2494 };
2495
2496 /** {@inheritDoc} */
Jeff Brown00fa7bd2010-07-02 15:37:36 -07002497 @Override
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002498 public long interceptKeyBeforeDispatching(WindowState win, KeyEvent event, int policyFlags) {
Jeff Brown00fa7bd2010-07-02 15:37:36 -07002499 final boolean keyguardOn = keyguardOn();
Jeff Brown1f245102010-11-18 20:53:46 -08002500 final int keyCode = event.getKeyCode();
2501 final int repeatCount = event.getRepeatCount();
2502 final int metaState = event.getMetaState();
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002503 final int flags = event.getFlags();
Jeff Brown1f245102010-11-18 20:53:46 -08002504 final boolean down = event.getAction() == KeyEvent.ACTION_DOWN;
2505 final boolean canceled = event.isCanceled();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002506
Jeff Brown40013652012-05-16 21:22:36 -07002507 if (DEBUG_INPUT) {
Jeff Brown00fa7bd2010-07-02 15:37:36 -07002508 Log.d(TAG, "interceptKeyTi keyCode=" + keyCode + " down=" + down + " repeatCount="
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002509 + repeatCount + " keyguardOn=" + keyguardOn + " mHomePressed=" + mHomePressed
2510 + " canceled=" + canceled);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002511 }
2512
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002513 // If we think we might have a volume down & power key chord on the way
2514 // but we're not sure, then tell the dispatcher to wait a little while and
2515 // try again later before dispatching.
Christopher Tatee90585f2012-03-05 18:56:25 -08002516 if (mScreenshotChordEnabled && (flags & KeyEvent.FLAG_FALLBACK) == 0) {
Jeff Brown13f00f02014-10-31 14:45:50 -07002517 if (mScreenshotChordVolumeDownKeyTriggered && !mScreenshotChordPowerKeyTriggered) {
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002518 final long now = SystemClock.uptimeMillis();
Jeff Brown13f00f02014-10-31 14:45:50 -07002519 final long timeoutTime = mScreenshotChordVolumeDownKeyTime
2520 + SCREENSHOT_CHORD_DEBOUNCE_DELAY_MILLIS;
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002521 if (now < timeoutTime) {
2522 return timeoutTime - now;
2523 }
2524 }
2525 if (keyCode == KeyEvent.KEYCODE_VOLUME_DOWN
Jeff Brown13f00f02014-10-31 14:45:50 -07002526 && mScreenshotChordVolumeDownKeyConsumed) {
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002527 if (!down) {
Jeff Brown13f00f02014-10-31 14:45:50 -07002528 mScreenshotChordVolumeDownKeyConsumed = false;
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002529 }
2530 return -1;
2531 }
2532 }
2533
Michael Wright6a62e552014-06-03 19:19:48 -07002534 // Cancel any pending meta actions if we see any other keys being pressed between the down
2535 // of the meta key and its corresponding up.
Michael Wright251e35d2014-08-22 15:40:27 -07002536 if (mPendingMetaAction && !KeyEvent.isMetaKey(keyCode)) {
Michael Wright6a62e552014-06-03 19:19:48 -07002537 mPendingMetaAction = false;
2538 }
2539
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002540 // First we always handle the home key here, so applications
2541 // can never break it, although if keyguard is on, we do let
2542 // it handle it, because that gives us the correct 5 second
2543 // timeout.
Jeff Brown00fa7bd2010-07-02 15:37:36 -07002544 if (keyCode == KeyEvent.KEYCODE_HOME) {
Michael Jurka7f2668c2012-03-27 07:49:52 -07002545
Jeff Brown49ed71d2010-12-06 17:13:33 -08002546 // If we have released the home key, and didn't do anything else
2547 // while it was pressed, then it is time to go home!
Michael Jurka7f2668c2012-03-27 07:49:52 -07002548 if (!down) {
Jeff Browncaca8812013-05-09 13:34:33 -07002549 cancelPreloadRecentApps();
2550
Jeff Brown49ed71d2010-12-06 17:13:33 -08002551 mHomePressed = false;
Jeff Browncaca8812013-05-09 13:34:33 -07002552 if (mHomeConsumed) {
2553 mHomeConsumed = false;
Michael Jurka7f2668c2012-03-27 07:49:52 -07002554 return -1;
Jeff Brown49ed71d2010-12-06 17:13:33 -08002555 }
Jeff Browncaca8812013-05-09 13:34:33 -07002556
2557 if (canceled) {
2558 Log.i(TAG, "Ignoring HOME; event canceled.");
2559 return -1;
2560 }
2561
Yorke Lee4f803242014-12-15 23:22:06 +00002562 // If an incoming call is ringing, HOME is totally disabled.
2563 // (The user is already on the InCallUI at this point,
2564 // and his ONLY options are to answer or reject the call.)
2565 TelecomManager telecomManager = getTelecommService();
2566 if (telecomManager != null && telecomManager.isRinging()) {
2567 Log.i(TAG, "Ignoring HOME; there's a ringing incoming call.");
2568 return -1;
2569 }
2570
Jeff Browncaca8812013-05-09 13:34:33 -07002571 // Delay handling home if a double-tap is possible.
2572 if (mDoubleTapOnHomeBehavior != DOUBLE_TAP_HOME_NOTHING) {
2573 mHandler.removeCallbacks(mHomeDoubleTapTimeoutRunnable); // just in case
2574 mHomeDoubleTapPending = true;
2575 mHandler.postDelayed(mHomeDoubleTapTimeoutRunnable,
2576 ViewConfiguration.getDoubleTapTimeout());
2577 return -1;
2578 }
2579
Jeff Brown13f00f02014-10-31 14:45:50 -07002580 handleShortPressOnHome();
Jeff Browncaca8812013-05-09 13:34:33 -07002581 return -1;
Jeff Brown49ed71d2010-12-06 17:13:33 -08002582 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002583
2584 // If a system window has focus, then it doesn't make sense
2585 // right now to interact with applications.
2586 WindowManager.LayoutParams attrs = win != null ? win.getAttrs() : null;
2587 if (attrs != null) {
2588 final int type = attrs.type;
Jorim Jaggi380ecb82014-03-14 17:25:20 +01002589 if (type == WindowManager.LayoutParams.TYPE_KEYGUARD_SCRIM
2590 || type == WindowManager.LayoutParams.TYPE_KEYGUARD_DIALOG
2591 || (attrs.privateFlags & PRIVATE_FLAG_KEYGUARD) != 0) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002592 // the "app" is keyguard, so give it the key
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002593 return 0;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002594 }
2595 final int typeCount = WINDOW_TYPES_WHERE_HOME_DOESNT_WORK.length;
2596 for (int i=0; i<typeCount; i++) {
2597 if (type == WINDOW_TYPES_WHERE_HOME_DOESNT_WORK[i]) {
2598 // don't do anything, but also don't pass it to the app
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002599 return -1;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002600 }
2601 }
2602 }
Jeff Browncaca8812013-05-09 13:34:33 -07002603
2604 // Remember that home is pressed and handle special actions.
2605 if (repeatCount == 0) {
2606 mHomePressed = true;
2607 if (mHomeDoubleTapPending) {
2608 mHomeDoubleTapPending = false;
2609 mHandler.removeCallbacks(mHomeDoubleTapTimeoutRunnable);
2610 handleDoubleTapOnHome();
2611 } else if (mLongPressOnHomeBehavior == LONG_PRESS_HOME_RECENT_SYSTEM_UI
2612 || mDoubleTapOnHomeBehavior == DOUBLE_TAP_HOME_RECENT_SYSTEM_UI) {
2613 preloadRecentApps();
Michael Jurka7f2668c2012-03-27 07:49:52 -07002614 }
Jeff Browncaca8812013-05-09 13:34:33 -07002615 } else if ((event.getFlags() & KeyEvent.FLAG_LONG_PRESS) != 0) {
2616 if (!keyguardOn) {
2617 handleLongPressOnHome();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002618 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002619 }
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002620 return -1;
Jeff Brown00fa7bd2010-07-02 15:37:36 -07002621 } else if (keyCode == KeyEvent.KEYCODE_MENU) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002622 // Hijack modified menu keys for debugging features
2623 final int chordBug = KeyEvent.META_SHIFT_ON;
2624
2625 if (down && repeatCount == 0) {
Jeff Brown00fa7bd2010-07-02 15:37:36 -07002626 if (mEnableShiftMenuBugReports && (metaState & chordBug) == chordBug) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002627 Intent intent = new Intent(Intent.ACTION_BUG_REPORT);
Dianne Hackborn5ac72a22012-08-29 18:32:08 -07002628 mContext.sendOrderedBroadcastAsUser(intent, UserHandle.CURRENT,
2629 null, null, null, 0, null, null);
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002630 return -1;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002631 } else if (SHOW_PROCESSES_ON_ALT_MENU &&
Jeff Brown00fa7bd2010-07-02 15:37:36 -07002632 (metaState & KeyEvent.META_ALT_ON) == KeyEvent.META_ALT_ON) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002633 Intent service = new Intent();
2634 service.setClassName(mContext, "com.android.server.LoadAverageService");
2635 ContentResolver res = mContext.getContentResolver();
Jeff Sharkey8d9a1f62012-10-18 15:38:14 -07002636 boolean shown = Settings.Global.getInt(
2637 res, Settings.Global.SHOW_PROCESSES, 0) != 0;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002638 if (!shown) {
2639 mContext.startService(service);
2640 } else {
2641 mContext.stopService(service);
2642 }
Jeff Sharkey8d9a1f62012-10-18 15:38:14 -07002643 Settings.Global.putInt(
2644 res, Settings.Global.SHOW_PROCESSES, shown ? 0 : 1);
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002645 return -1;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002646 }
2647 }
Jeff Brown00fa7bd2010-07-02 15:37:36 -07002648 } else if (keyCode == KeyEvent.KEYCODE_SEARCH) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002649 if (down) {
2650 if (repeatCount == 0) {
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002651 mSearchKeyShortcutPending = true;
2652 mConsumeSearchKeyUp = false;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002653 }
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002654 } else {
2655 mSearchKeyShortcutPending = false;
2656 if (mConsumeSearchKeyUp) {
2657 mConsumeSearchKeyUp = false;
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002658 return -1;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002659 }
2660 }
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002661 return 0;
Jeff Brown49ed71d2010-12-06 17:13:33 -08002662 } else if (keyCode == KeyEvent.KEYCODE_APP_SWITCH) {
Michael Wrightc9ebea72013-01-16 19:25:02 -08002663 if (!keyguardOn) {
Jeff Browncaca8812013-05-09 13:34:33 -07002664 if (down && repeatCount == 0) {
2665 preloadRecentApps();
2666 } else if (!down) {
2667 toggleRecentApps();
Michael Wrightc9ebea72013-01-16 19:25:02 -08002668 }
Jeff Brown49ed71d2010-12-06 17:13:33 -08002669 }
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002670 return -1;
Jeff Brownde7a8ea2012-06-13 18:28:57 -07002671 } else if (keyCode == KeyEvent.KEYCODE_ASSIST) {
2672 if (down) {
2673 if (repeatCount == 0) {
2674 mAssistKeyLongPressed = false;
2675 } else if (repeatCount == 1) {
2676 mAssistKeyLongPressed = true;
2677 if (!keyguardOn) {
2678 launchAssistLongPressAction();
2679 }
2680 }
2681 } else {
2682 if (mAssistKeyLongPressed) {
2683 mAssistKeyLongPressed = false;
2684 } else {
2685 if (!keyguardOn) {
2686 launchAssistAction();
2687 }
2688 }
2689 }
2690 return -1;
Michael Wrightdc63f7b2014-08-21 19:05:21 -07002691 } else if (keyCode == KeyEvent.KEYCODE_VOICE_ASSIST) {
2692 if (!down) {
2693 Intent voiceIntent;
Michael Wright869a67c2014-08-26 19:33:06 -07002694 if (!keyguardOn) {
Michael Wrightdc63f7b2014-08-21 19:05:21 -07002695 voiceIntent = new Intent(RecognizerIntent.ACTION_WEB_SEARCH);
2696 } else {
2697 voiceIntent = new Intent(RecognizerIntent.ACTION_VOICE_SEARCH_HANDS_FREE);
Michael Wright869a67c2014-08-26 19:33:06 -07002698 voiceIntent.putExtra(RecognizerIntent.EXTRA_SECURE, true);
Michael Wrightdc63f7b2014-08-21 19:05:21 -07002699 }
Bart Sears8b1c27c2015-03-18 23:51:02 +00002700 startActivityAsUser(voiceIntent, UserHandle.CURRENT_OR_SELF);
Michael Wrightdc63f7b2014-08-21 19:05:21 -07002701 }
Jeff Sharkey2991fa32012-12-05 18:06:43 -08002702 } else if (keyCode == KeyEvent.KEYCODE_SYSRQ) {
2703 if (down && repeatCount == 0) {
2704 mHandler.post(mScreenshotRunnable);
2705 }
2706 return -1;
Michael Wrightb854e242013-02-05 17:54:02 -08002707 } else if (keyCode == KeyEvent.KEYCODE_BRIGHTNESS_UP
2708 || keyCode == KeyEvent.KEYCODE_BRIGHTNESS_DOWN) {
2709 if (down) {
2710 int direction = keyCode == KeyEvent.KEYCODE_BRIGHTNESS_UP ? 1 : -1;
2711
2712 // Disable autobrightness if it's on
2713 int auto = Settings.System.getIntForUser(
2714 mContext.getContentResolver(),
2715 Settings.System.SCREEN_BRIGHTNESS_MODE,
2716 Settings.System.SCREEN_BRIGHTNESS_MODE_MANUAL,
2717 UserHandle.USER_CURRENT_OR_SELF);
2718 if (auto != 0) {
2719 Settings.System.putIntForUser(mContext.getContentResolver(),
2720 Settings.System.SCREEN_BRIGHTNESS_MODE,
2721 Settings.System.SCREEN_BRIGHTNESS_MODE_MANUAL,
2722 UserHandle.USER_CURRENT_OR_SELF);
2723 }
2724
2725 int min = mPowerManager.getMinimumScreenBrightnessSetting();
2726 int max = mPowerManager.getMaximumScreenBrightnessSetting();
2727 int step = (max - min + BRIGHTNESS_STEPS - 1) / BRIGHTNESS_STEPS * direction;
2728 int brightness = Settings.System.getIntForUser(mContext.getContentResolver(),
2729 Settings.System.SCREEN_BRIGHTNESS,
2730 mPowerManager.getDefaultScreenBrightnessSetting(),
2731 UserHandle.USER_CURRENT_OR_SELF);
2732 brightness += step;
2733 // Make sure we don't go beyond the limits.
2734 brightness = Math.min(max, brightness);
2735 brightness = Math.max(min, brightness);
2736
2737 Settings.System.putIntForUser(mContext.getContentResolver(),
2738 Settings.System.SCREEN_BRIGHTNESS, brightness,
2739 UserHandle.USER_CURRENT_OR_SELF);
Bart Sears8b1c27c2015-03-18 23:51:02 +00002740 startActivityAsUser(new Intent(Intent.ACTION_SHOW_BRIGHTNESS_DIALOG),
Alan Viverette5a399492014-07-14 16:19:38 -07002741 UserHandle.CURRENT_OR_SELF);
Michael Wrightb854e242013-02-05 17:54:02 -08002742 }
2743 return -1;
Michael Wrightce0c13a2014-07-30 10:49:21 -07002744 } else if (KeyEvent.isMetaKey(keyCode)) {
Michael Wright6a62e552014-06-03 19:19:48 -07002745 if (down) {
2746 mPendingMetaAction = true;
2747 } else if (mPendingMetaAction) {
Michael Wright8ab940a2014-09-01 11:01:27 -07002748 launchAssistAction(Intent.EXTRA_ASSIST_INPUT_HINT_KEYBOARD);
Michael Wright6a62e552014-06-03 19:19:48 -07002749 }
2750 return -1;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002751 }
Jeff Browncaab4d02010-12-09 22:13:41 -08002752
Jeff Brownc1fb48d2010-12-08 16:52:09 -08002753 // Shortcuts are invoked through Search+key, so intercept those here
Jeff Browncaab4d02010-12-09 22:13:41 -08002754 // Any printing key that is chorded with Search should be consumed
2755 // even if no shortcut was invoked. This prevents text from being
2756 // inadvertently inserted when using a keyboard that has built-in macro
2757 // shortcut keys (that emit Search+x) and some of them are not registered.
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002758 if (mSearchKeyShortcutPending) {
Jeff Browncaab4d02010-12-09 22:13:41 -08002759 final KeyCharacterMap kcm = event.getKeyCharacterMap();
2760 if (kcm.isPrintingKey(keyCode)) {
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002761 mConsumeSearchKeyUp = true;
2762 mSearchKeyShortcutPending = false;
Jeff Browncaab4d02010-12-09 22:13:41 -08002763 if (down && repeatCount == 0 && !keyguardOn) {
2764 Intent shortcutIntent = mShortcutManager.getIntent(kcm, keyCode, metaState);
2765 if (shortcutIntent != null) {
2766 shortcutIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
Jeff Brownf0a3cc52011-01-26 18:42:46 -08002767 try {
Bart Sears8b1c27c2015-03-18 23:51:02 +00002768 startActivityAsUser(shortcutIntent, UserHandle.CURRENT);
Jeff Brownf0a3cc52011-01-26 18:42:46 -08002769 } catch (ActivityNotFoundException ex) {
2770 Slog.w(TAG, "Dropping shortcut key combination because "
2771 + "the activity to which it is registered was not found: "
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002772 + "SEARCH+" + KeyEvent.keyCodeToString(keyCode), ex);
Jeff Brownf0a3cc52011-01-26 18:42:46 -08002773 }
Jeff Browncaab4d02010-12-09 22:13:41 -08002774 } else {
2775 Slog.i(TAG, "Dropping unregistered shortcut key combination: "
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002776 + "SEARCH+" + KeyEvent.keyCodeToString(keyCode));
Jeff Brown49ed71d2010-12-06 17:13:33 -08002777 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002778 }
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002779 return -1;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002780 }
2781 }
2782
Jeff Brown68b909d2011-12-07 16:36:01 -08002783 // Invoke shortcuts using Meta.
Jeff Brown602ab322012-05-16 13:33:47 -07002784 if (down && repeatCount == 0 && !keyguardOn
Jeff Brown68b909d2011-12-07 16:36:01 -08002785 && (metaState & KeyEvent.META_META_ON) != 0) {
2786 final KeyCharacterMap kcm = event.getKeyCharacterMap();
Jeff Brown602ab322012-05-16 13:33:47 -07002787 if (kcm.isPrintingKey(keyCode)) {
2788 Intent shortcutIntent = mShortcutManager.getIntent(kcm, keyCode,
2789 metaState & ~(KeyEvent.META_META_ON
2790 | KeyEvent.META_META_LEFT_ON | KeyEvent.META_META_RIGHT_ON));
2791 if (shortcutIntent != null) {
2792 shortcutIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
2793 try {
Bart Sears8b1c27c2015-03-18 23:51:02 +00002794 startActivityAsUser(shortcutIntent, UserHandle.CURRENT);
Jeff Brown602ab322012-05-16 13:33:47 -07002795 } catch (ActivityNotFoundException ex) {
2796 Slog.w(TAG, "Dropping shortcut key combination because "
2797 + "the activity to which it is registered was not found: "
2798 + "META+" + KeyEvent.keyCodeToString(keyCode), ex);
2799 }
2800 return -1;
Jeff Brown68b909d2011-12-07 16:36:01 -08002801 }
Jeff Brown68b909d2011-12-07 16:36:01 -08002802 }
2803 }
2804
Jeff Brown6651a632011-11-28 12:59:11 -08002805 // Handle application launch keys.
Jeff Brown602ab322012-05-16 13:33:47 -07002806 if (down && repeatCount == 0 && !keyguardOn) {
Jeff Brown6651a632011-11-28 12:59:11 -08002807 String category = sApplicationLaunchKeyCategories.get(keyCode);
2808 if (category != null) {
Dianne Hackbornf5b86712011-12-05 17:42:41 -08002809 Intent intent = Intent.makeMainSelectorActivity(Intent.ACTION_MAIN, category);
Jeff Brown6651a632011-11-28 12:59:11 -08002810 intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
2811 try {
Bart Sears8b1c27c2015-03-18 23:51:02 +00002812 startActivityAsUser(intent, UserHandle.CURRENT);
Jeff Brown6651a632011-11-28 12:59:11 -08002813 } catch (ActivityNotFoundException ex) {
2814 Slog.w(TAG, "Dropping application launch key because "
2815 + "the activity to which it is registered was not found: "
2816 + "keyCode=" + keyCode + ", category=" + category, ex);
2817 }
Jeff Brown68b909d2011-12-07 16:36:01 -08002818 return -1;
Jeff Brown6651a632011-11-28 12:59:11 -08002819 }
2820 }
2821
Michael Wright61c46752014-08-21 16:57:33 -07002822 // Display task switcher for ALT-TAB.
Jeff Brown68b909d2011-12-07 16:36:01 -08002823 if (down && repeatCount == 0 && keyCode == KeyEvent.KEYCODE_TAB) {
Winson Chung1e8d71b2014-05-16 17:05:22 -07002824 if (mRecentAppsHeldModifiers == 0 && !keyguardOn) {
Jeff Brown68b909d2011-12-07 16:36:01 -08002825 final int shiftlessModifiers = event.getModifiers() & ~KeyEvent.META_SHIFT_MASK;
Michael Wright61c46752014-08-21 16:57:33 -07002826 if (KeyEvent.metaStateHasModifiers(shiftlessModifiers, KeyEvent.META_ALT_ON)) {
Winson Chung1e8d71b2014-05-16 17:05:22 -07002827 mRecentAppsHeldModifiers = shiftlessModifiers;
2828 showRecentApps(true);
Jeff Brown68b909d2011-12-07 16:36:01 -08002829 return -1;
2830 }
2831 }
Winson Chung1e8d71b2014-05-16 17:05:22 -07002832 } else if (!down && mRecentAppsHeldModifiers != 0
2833 && (metaState & mRecentAppsHeldModifiers) == 0) {
2834 mRecentAppsHeldModifiers = 0;
Winson Chungcdcd4872014-08-05 18:00:13 -07002835 hideRecentApps(true, false);
Jeff Brown68b909d2011-12-07 16:36:01 -08002836 }
2837
Jeff Browncf39bdf2012-05-18 14:41:19 -07002838 // Handle keyboard language switching.
2839 if (down && repeatCount == 0
2840 && (keyCode == KeyEvent.KEYCODE_LANGUAGE_SWITCH
2841 || (keyCode == KeyEvent.KEYCODE_SPACE
2842 && (metaState & KeyEvent.META_CTRL_MASK) != 0))) {
2843 int direction = (metaState & KeyEvent.META_SHIFT_MASK) != 0 ? -1 : 1;
2844 mWindowManagerFuncs.switchKeyboardLayout(event.getDeviceId(), direction);
2845 return -1;
2846 }
2847 if (mLanguageSwitchKeyPressed && !down
2848 && (keyCode == KeyEvent.KEYCODE_LANGUAGE_SWITCH
2849 || keyCode == KeyEvent.KEYCODE_SPACE)) {
2850 mLanguageSwitchKeyPressed = false;
2851 return -1;
2852 }
2853
Jeff Brown13f00f02014-10-31 14:45:50 -07002854 if (isValidGlobalKey(keyCode)
2855 && mGlobalKeyManager.handleGlobalKey(mContext, keyCode, event)) {
Justin Kohd378ad72013-04-01 12:18:26 -07002856 return -1;
2857 }
2858
Michael Wright6a62e552014-06-03 19:19:48 -07002859 // Reserve all the META modifier combos for system behavior
Michael Wrightce0c13a2014-07-30 10:49:21 -07002860 if ((metaState & KeyEvent.META_META_ON) != 0) {
Michael Wright6a62e552014-06-03 19:19:48 -07002861 return -1;
2862 }
2863
Jeff Brown68b909d2011-12-07 16:36:01 -08002864 // Let the application handle the key.
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002865 return 0;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002866 }
2867
Jeff Brown3915bb82010-11-05 15:02:16 -07002868 /** {@inheritDoc} */
2869 @Override
Jeff Brown49ed71d2010-12-06 17:13:33 -08002870 public KeyEvent dispatchUnhandledKey(WindowState win, KeyEvent event, int policyFlags) {
Jeff Brown54875002011-04-06 15:33:01 -07002871 // Note: This method is only called if the initial down was unhandled.
Jeff Brown40013652012-05-16 21:22:36 -07002872 if (DEBUG_INPUT) {
Jeff Brown1f245102010-11-18 20:53:46 -08002873 Slog.d(TAG, "Unhandled key: win=" + win + ", action=" + event.getAction()
2874 + ", flags=" + event.getFlags()
2875 + ", keyCode=" + event.getKeyCode()
2876 + ", scanCode=" + event.getScanCode()
2877 + ", metaState=" + event.getMetaState()
2878 + ", repeatCount=" + event.getRepeatCount()
2879 + ", policyFlags=" + policyFlags);
Jeff Brown3915bb82010-11-05 15:02:16 -07002880 }
Jeff Brown49ed71d2010-12-06 17:13:33 -08002881
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002882 KeyEvent fallbackEvent = null;
Jeff Brown49ed71d2010-12-06 17:13:33 -08002883 if ((event.getFlags() & KeyEvent.FLAG_FALLBACK) == 0) {
2884 final KeyCharacterMap kcm = event.getKeyCharacterMap();
Jeff Brownc1fb48d2010-12-08 16:52:09 -08002885 final int keyCode = event.getKeyCode();
2886 final int metaState = event.getMetaState();
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002887 final boolean initialDown = event.getAction() == KeyEvent.ACTION_DOWN
2888 && event.getRepeatCount() == 0;
Jeff Brown49ed71d2010-12-06 17:13:33 -08002889
Jeff Brown54875002011-04-06 15:33:01 -07002890 // Check for fallback actions specified by the key character map.
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002891 final FallbackAction fallbackAction;
2892 if (initialDown) {
2893 fallbackAction = kcm.getFallbackAction(keyCode, metaState);
2894 } else {
2895 fallbackAction = mFallbackActions.get(keyCode);
2896 }
2897
2898 if (fallbackAction != null) {
Jeff Brown40013652012-05-16 21:22:36 -07002899 if (DEBUG_INPUT) {
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002900 Slog.d(TAG, "Fallback: keyCode=" + fallbackAction.keyCode
2901 + " metaState=" + Integer.toHexString(fallbackAction.metaState));
Jeff Brown49ed71d2010-12-06 17:13:33 -08002902 }
2903
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002904 final int flags = event.getFlags() | KeyEvent.FLAG_FALLBACK;
2905 fallbackEvent = KeyEvent.obtain(
Jeff Brown49ed71d2010-12-06 17:13:33 -08002906 event.getDownTime(), event.getEventTime(),
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002907 event.getAction(), fallbackAction.keyCode,
2908 event.getRepeatCount(), fallbackAction.metaState,
Jeff Brown49ed71d2010-12-06 17:13:33 -08002909 event.getDeviceId(), event.getScanCode(),
2910 flags, event.getSource(), null);
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002911
2912 if (!interceptFallback(win, fallbackEvent, policyFlags)) {
2913 fallbackEvent.recycle();
2914 fallbackEvent = null;
Jeff Brown49ed71d2010-12-06 17:13:33 -08002915 }
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002916
2917 if (initialDown) {
2918 mFallbackActions.put(keyCode, fallbackAction);
2919 } else if (event.getAction() == KeyEvent.ACTION_UP) {
2920 mFallbackActions.remove(keyCode);
2921 fallbackAction.recycle();
2922 }
Jeff Brown49ed71d2010-12-06 17:13:33 -08002923 }
2924 }
2925
Jeff Brown40013652012-05-16 21:22:36 -07002926 if (DEBUG_INPUT) {
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002927 if (fallbackEvent == null) {
2928 Slog.d(TAG, "No fallback.");
2929 } else {
2930 Slog.d(TAG, "Performing fallback: " + fallbackEvent);
2931 }
Jeff Brown49ed71d2010-12-06 17:13:33 -08002932 }
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002933 return fallbackEvent;
Jeff Brown3915bb82010-11-05 15:02:16 -07002934 }
2935
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002936 private boolean interceptFallback(WindowState win, KeyEvent fallbackEvent, int policyFlags) {
Jeff Brown037c33e2014-04-09 00:31:55 -07002937 int actions = interceptKeyBeforeQueueing(fallbackEvent, policyFlags);
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002938 if ((actions & ACTION_PASS_TO_USER) != 0) {
2939 long delayMillis = interceptKeyBeforeDispatching(
2940 win, fallbackEvent, policyFlags);
2941 if (delayMillis == 0) {
2942 return true;
2943 }
2944 }
2945 return false;
Jeff Brown6f2fba42011-02-19 01:08:02 -08002946 }
2947
Jeff Brownde7a8ea2012-06-13 18:28:57 -07002948 private void launchAssistLongPressAction() {
2949 performHapticFeedbackLw(null, HapticFeedbackConstants.LONG_PRESS, false);
2950 sendCloseSystemWindows(SYSTEM_DIALOG_REASON_ASSIST);
2951
2952 // launch the search activity
2953 Intent intent = new Intent(Intent.ACTION_SEARCH_LONG_PRESS);
2954 intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
2955 try {
RoboErik8a2cfc32014-05-16 11:19:38 -07002956 // TODO: This only stops the factory-installed search manager.
Jim Miller45308b12012-06-18 19:23:39 -07002957 // Need to formalize an API to handle others
Jeff Brownde7a8ea2012-06-13 18:28:57 -07002958 SearchManager searchManager = getSearchManager();
2959 if (searchManager != null) {
2960 searchManager.stopSearch();
2961 }
Bart Sears8b1c27c2015-03-18 23:51:02 +00002962 startActivityAsUser(intent, UserHandle.CURRENT);
Jeff Brownde7a8ea2012-06-13 18:28:57 -07002963 } catch (ActivityNotFoundException e) {
2964 Slog.w(TAG, "No activity to handle assist long press action.", e);
2965 }
2966 }
2967
2968 private void launchAssistAction() {
Michael Wright8ab940a2014-09-01 11:01:27 -07002969 launchAssistAction(null);
2970 }
2971
2972 private void launchAssistAction(String hint) {
Jeff Brownde7a8ea2012-06-13 18:28:57 -07002973 sendCloseSystemWindows(SYSTEM_DIALOG_REASON_ASSIST);
Amith Yamasanic1d07a42012-08-14 09:32:02 -07002974 Intent intent = ((SearchManager) mContext.getSystemService(Context.SEARCH_SERVICE))
Dianne Hackbornf9c5e0f2013-01-23 14:39:13 -08002975 .getAssistIntent(mContext, true, UserHandle.USER_CURRENT);
Jim Miller45308b12012-06-18 19:23:39 -07002976 if (intent != null) {
Michael Wright8ab940a2014-09-01 11:01:27 -07002977 if (hint != null) {
2978 intent.putExtra(hint, true);
2979 }
Jim Miller45308b12012-06-18 19:23:39 -07002980 intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK
2981 | Intent.FLAG_ACTIVITY_SINGLE_TOP
2982 | Intent.FLAG_ACTIVITY_CLEAR_TOP);
2983 try {
Bart Sears8b1c27c2015-03-18 23:51:02 +00002984 startActivityAsUser(intent, UserHandle.CURRENT);
Jim Miller45308b12012-06-18 19:23:39 -07002985 } catch (ActivityNotFoundException e) {
2986 Slog.w(TAG, "No activity to handle assist action.", e);
Jeff Brownde7a8ea2012-06-13 18:28:57 -07002987 }
2988 }
2989 }
2990
Bart Sears8b1c27c2015-03-18 23:51:02 +00002991 private void startActivityAsUser(Intent intent, UserHandle handle) {
2992 if (isUserSetupComplete()) {
2993 mContext.startActivityAsUser(intent, handle);
2994 } else {
2995 Slog.i(TAG, "Not starting activity because user setup is in progress: " + intent);
2996 }
2997 }
2998
Jeff Brownde7a8ea2012-06-13 18:28:57 -07002999 private SearchManager getSearchManager() {
3000 if (mSearchManager == null) {
3001 mSearchManager = (SearchManager) mContext.getSystemService(Context.SEARCH_SERVICE);
3002 }
3003 return mSearchManager;
3004 }
3005
Jeff Browncaca8812013-05-09 13:34:33 -07003006 private void preloadRecentApps() {
3007 mPreloadedRecentApps = true;
3008 try {
3009 IStatusBarService statusbar = getStatusBarService();
3010 if (statusbar != null) {
3011 statusbar.preloadRecentApps();
3012 }
3013 } catch (RemoteException e) {
3014 Slog.e(TAG, "RemoteException when preloading recent apps", e);
3015 // re-acquire status bar service next time it is needed.
3016 mStatusBarService = null;
3017 }
3018 }
3019
3020 private void cancelPreloadRecentApps() {
3021 if (mPreloadedRecentApps) {
3022 mPreloadedRecentApps = false;
3023 try {
3024 IStatusBarService statusbar = getStatusBarService();
3025 if (statusbar != null) {
3026 statusbar.cancelPreloadRecentApps();
3027 }
3028 } catch (RemoteException e) {
Winson Chung1e8d71b2014-05-16 17:05:22 -07003029 Slog.e(TAG, "RemoteException when cancelling recent apps preload", e);
Jeff Browncaca8812013-05-09 13:34:33 -07003030 // re-acquire status bar service next time it is needed.
3031 mStatusBarService = null;
3032 }
3033 }
3034 }
3035
3036 private void toggleRecentApps() {
3037 mPreloadedRecentApps = false; // preloading no longer needs to be canceled
Jeff Browncaca8812013-05-09 13:34:33 -07003038 try {
3039 IStatusBarService statusbar = getStatusBarService();
3040 if (statusbar != null) {
3041 statusbar.toggleRecentApps();
3042 }
3043 } catch (RemoteException e) {
Winson Chung1e8d71b2014-05-16 17:05:22 -07003044 Slog.e(TAG, "RemoteException when toggling recent apps", e);
3045 // re-acquire status bar service next time it is needed.
3046 mStatusBarService = null;
3047 }
3048 }
3049
Craig Mautner84984fa2014-06-19 11:19:20 -07003050 @Override
3051 public void showRecentApps() {
3052 mHandler.removeMessages(MSG_DISPATCH_SHOW_RECENTS);
3053 mHandler.sendEmptyMessage(MSG_DISPATCH_SHOW_RECENTS);
3054 }
3055
Winson Chung1e8d71b2014-05-16 17:05:22 -07003056 private void showRecentApps(boolean triggeredFromAltTab) {
3057 mPreloadedRecentApps = false; // preloading no longer needs to be canceled
3058 try {
3059 IStatusBarService statusbar = getStatusBarService();
3060 if (statusbar != null) {
3061 statusbar.showRecentApps(triggeredFromAltTab);
3062 }
3063 } catch (RemoteException e) {
Jeff Browncaca8812013-05-09 13:34:33 -07003064 Slog.e(TAG, "RemoteException when showing recent apps", e);
3065 // re-acquire status bar service next time it is needed.
3066 mStatusBarService = null;
3067 }
3068 }
3069
Winson Chungcdcd4872014-08-05 18:00:13 -07003070 private void hideRecentApps(boolean triggeredFromAltTab, boolean triggeredFromHome) {
Winson Chung1e8d71b2014-05-16 17:05:22 -07003071 mPreloadedRecentApps = false; // preloading no longer needs to be canceled
3072 try {
3073 IStatusBarService statusbar = getStatusBarService();
3074 if (statusbar != null) {
Winson Chungcdcd4872014-08-05 18:00:13 -07003075 statusbar.hideRecentApps(triggeredFromAltTab, triggeredFromHome);
Winson Chung1e8d71b2014-05-16 17:05:22 -07003076 }
3077 } catch (RemoteException e) {
3078 Slog.e(TAG, "RemoteException when closing recent apps", e);
3079 // re-acquire status bar service next time it is needed.
3080 mStatusBarService = null;
3081 }
3082 }
3083
Filip Gruszczynskia483a1d2015-03-17 19:06:58 +00003084 void launchHomeFromHotKey() {
Bryce Lee662ed802015-04-10 20:11:39 +00003085 launchHomeFromHotKey(true /* awakenFromDreams */, true /*respectKeyguard*/);
Filip Gruszczynskia483a1d2015-03-17 19:06:58 +00003086 }
3087
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003088 /**
3089 * A home key -> launch home action was detected. Take the appropriate action
3090 * given the situation with the keyguard.
3091 */
Bryce Lee662ed802015-04-10 20:11:39 +00003092 void launchHomeFromHotKey(final boolean awakenFromDreams, final boolean respectKeyguard) {
3093 if (respectKeyguard) {
3094 if (isKeyguardShowingAndNotOccluded()) {
3095 // don't launch home if keyguard showing
3096 return;
3097 }
3098
3099 if (!mHideLockScreen && mKeyguardDelegate.isInputRestricted()) {
3100 // when in keyguard restricted mode, must first verify unlock
3101 // before launching home
3102 mKeyguardDelegate.verifyUnlock(new OnKeyguardExitResult() {
3103 @Override
3104 public void onKeyguardExitResult(boolean success) {
3105 if (success) {
3106 try {
3107 ActivityManagerNative.getDefault().stopAppSwitches();
3108 } catch (RemoteException e) {
3109 }
3110 sendCloseSystemWindows(SYSTEM_DIALOG_REASON_HOME_KEY);
3111 startDockOrHome(true /*fromHomeKey*/, awakenFromDreams);
Dianne Hackborn256dd3b2009-05-19 18:51:21 -07003112 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003113 }
Bryce Lee662ed802015-04-10 20:11:39 +00003114 });
3115 return;
3116 }
3117 }
3118
3119 // no keyguard stuff to worry about, just launch home!
3120 try {
3121 ActivityManagerNative.getDefault().stopAppSwitches();
3122 } catch (RemoteException e) {
3123 }
3124 if (mRecentsVisible) {
3125 // Hide Recents and notify it to launch Home
3126 if (awakenFromDreams) {
3127 awakenDreams();
3128 }
3129 sendCloseSystemWindows(SYSTEM_DIALOG_REASON_HOME_KEY);
3130 hideRecentApps(false, true);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003131 } else {
Bryce Lee662ed802015-04-10 20:11:39 +00003132 // Otherwise, just launch Home
3133 sendCloseSystemWindows(SYSTEM_DIALOG_REASON_HOME_KEY);
3134 startDockOrHome(true /*fromHomeKey*/, awakenFromDreams);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003135 }
3136 }
3137
John Spurlock04db1762013-05-13 12:46:41 -04003138 private final Runnable mClearHideNavigationFlag = new Runnable() {
3139 @Override
3140 public void run() {
3141 synchronized (mWindowManagerFuncs.getWindowManagerLock()) {
3142 // Clear flags.
3143 mForceClearedSystemUiFlags &=
3144 ~View.SYSTEM_UI_FLAG_HIDE_NAVIGATION;
3145 }
3146 mWindowManagerFuncs.reevaluateStatusBarVisibility();
Dianne Hackborne26ab702011-10-16 13:21:33 -07003147 }
3148 };
3149
3150 /**
3151 * Input handler used while nav bar is hidden. Captures any touch on the screen,
3152 * to determine when the nav bar should be shown and prevent applications from
3153 * receiving those touches.
3154 */
Jeff Brown32cbc38552011-12-01 14:01:49 -08003155 final class HideNavInputEventReceiver extends InputEventReceiver {
3156 public HideNavInputEventReceiver(InputChannel inputChannel, Looper looper) {
3157 super(inputChannel, looper);
3158 }
3159
Dianne Hackborndf89e652011-10-06 22:35:11 -07003160 @Override
Jeff Brown32cbc38552011-12-01 14:01:49 -08003161 public void onInputEvent(InputEvent event) {
Dianne Hackborndf89e652011-10-06 22:35:11 -07003162 boolean handled = false;
3163 try {
Jeff Brown4952dfd2011-11-30 19:23:22 -08003164 if (event instanceof MotionEvent
3165 && (event.getSource() & InputDevice.SOURCE_CLASS_POINTER) != 0) {
3166 final MotionEvent motionEvent = (MotionEvent)event;
3167 if (motionEvent.getAction() == MotionEvent.ACTION_DOWN) {
Dianne Hackborndf89e652011-10-06 22:35:11 -07003168 // When the user taps down, we re-show the nav bar.
3169 boolean changed = false;
John Spurlock04db1762013-05-13 12:46:41 -04003170 synchronized (mWindowManagerFuncs.getWindowManagerLock()) {
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07003171 // Any user activity always causes us to show the
3172 // navigation controls, if they had been hidden.
3173 // We also clear the low profile and only content
3174 // flags so that tapping on the screen will atomically
3175 // restore all currently hidden screen decorations.
3176 int newVal = mResettingSystemUiFlags |
3177 View.SYSTEM_UI_FLAG_HIDE_NAVIGATION |
3178 View.SYSTEM_UI_FLAG_LOW_PROFILE |
3179 View.SYSTEM_UI_FLAG_FULLSCREEN;
Dianne Hackborne26ab702011-10-16 13:21:33 -07003180 if (mResettingSystemUiFlags != newVal) {
3181 mResettingSystemUiFlags = newVal;
Dianne Hackborndf89e652011-10-06 22:35:11 -07003182 changed = true;
3183 }
Dianne Hackborne26ab702011-10-16 13:21:33 -07003184 // We don't allow the system's nav bar to be hidden
3185 // again for 1 second, to prevent applications from
3186 // spamming us and keeping it from being shown.
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07003187 newVal = mForceClearedSystemUiFlags |
3188 View.SYSTEM_UI_FLAG_HIDE_NAVIGATION;
Dianne Hackborne26ab702011-10-16 13:21:33 -07003189 if (mForceClearedSystemUiFlags != newVal) {
3190 mForceClearedSystemUiFlags = newVal;
3191 changed = true;
John Spurlock04db1762013-05-13 12:46:41 -04003192 mHandler.postDelayed(mClearHideNavigationFlag, 1000);
Dianne Hackborne26ab702011-10-16 13:21:33 -07003193 }
Dianne Hackborndf89e652011-10-06 22:35:11 -07003194 }
3195 if (changed) {
3196 mWindowManagerFuncs.reevaluateStatusBarVisibility();
3197 }
3198 }
3199 }
3200 } finally {
Jeff Brown32cbc38552011-12-01 14:01:49 -08003201 finishInputEvent(event, handled);
Dianne Hackborndf89e652011-10-06 22:35:11 -07003202 }
3203 }
Jeff Brown32cbc38552011-12-01 14:01:49 -08003204 }
3205 final InputEventReceiver.Factory mHideNavInputEventReceiverFactory =
3206 new InputEventReceiver.Factory() {
3207 @Override
3208 public InputEventReceiver createInputEventReceiver(
3209 InputChannel inputChannel, Looper looper) {
3210 return new HideNavInputEventReceiver(inputChannel, looper);
3211 }
Dianne Hackborndf89e652011-10-06 22:35:11 -07003212 };
3213
3214 @Override
3215 public int adjustSystemUiVisibilityLw(int visibility) {
John Spurlock5b9145b2013-08-20 15:13:47 -04003216 mStatusBarController.adjustSystemUiVisibilityLw(mLastSystemUiFlags, visibility);
3217 mNavigationBarController.adjustSystemUiVisibilityLw(mLastSystemUiFlags, visibility);
Winson Chungd42a6cf2014-06-03 16:24:04 -07003218 mRecentsVisible = (visibility & View.RECENT_APPS_VISIBLE) > 0;
John Spurlock27735a42013-08-14 17:57:38 -04003219
Dianne Hackborndf89e652011-10-06 22:35:11 -07003220 // Reset any bits in mForceClearingStatusBarVisibility that
3221 // are now clear.
Dianne Hackborne26ab702011-10-16 13:21:33 -07003222 mResettingSystemUiFlags &= visibility;
Dianne Hackborndf89e652011-10-06 22:35:11 -07003223 // Clear any bits in the new visibility that are currently being
3224 // force cleared, before reporting it.
Dianne Hackborne26ab702011-10-16 13:21:33 -07003225 return visibility & ~mResettingSystemUiFlags
3226 & ~mForceClearedSystemUiFlags;
Dianne Hackborndf89e652011-10-06 22:35:11 -07003227 }
3228
Craig Mautner69b08182012-09-05 13:07:13 -07003229 @Override
Adrian Roos37d7a682014-11-06 18:15:16 +01003230 public void getInsetHintLw(WindowManager.LayoutParams attrs, Rect outContentInsets,
3231 Rect outStableInsets) {
John Spurlockc6d1c602014-01-17 15:22:06 -05003232 final int fl = PolicyControl.getWindowFlags(null, attrs);
John Spurlock1db8b682014-02-18 11:18:59 -05003233 final int sysuiVis = PolicyControl.getSystemUiVisibility(null, attrs);
3234 final int systemUiVisibility = (sysuiVis | attrs.subtreeSystemUiVisibility);
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07003235
Dianne Hackborn5b5cc4d2012-05-16 13:15:00 -07003236 if ((fl & (FLAG_LAYOUT_IN_SCREEN | FLAG_LAYOUT_INSET_DECOR))
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003237 == (FLAG_LAYOUT_IN_SCREEN | FLAG_LAYOUT_INSET_DECOR)) {
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07003238 int availRight, availBottom;
Alan Viverette5a0f4ec2013-10-07 15:10:29 -07003239 if (canHideNavigationBar() &&
Dianne Hackborn5b5cc4d2012-05-16 13:15:00 -07003240 (systemUiVisibility & View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION) != 0) {
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07003241 availRight = mUnrestrictedScreenLeft + mUnrestrictedScreenWidth;
3242 availBottom = mUnrestrictedScreenTop + mUnrestrictedScreenHeight;
3243 } else {
3244 availRight = mRestrictedScreenLeft + mRestrictedScreenWidth;
3245 availBottom = mRestrictedScreenTop + mRestrictedScreenHeight;
3246 }
Dianne Hackborn5b5cc4d2012-05-16 13:15:00 -07003247 if ((systemUiVisibility & View.SYSTEM_UI_FLAG_LAYOUT_STABLE) != 0) {
3248 if ((fl & FLAG_FULLSCREEN) != 0) {
Adrian Roos37d7a682014-11-06 18:15:16 +01003249 outContentInsets.set(mStableFullscreenLeft, mStableFullscreenTop,
Dianne Hackborn5b5cc4d2012-05-16 13:15:00 -07003250 availRight - mStableFullscreenRight,
3251 availBottom - mStableFullscreenBottom);
3252 } else {
Adrian Roos37d7a682014-11-06 18:15:16 +01003253 outContentInsets.set(mStableLeft, mStableTop,
Dianne Hackborn5b5cc4d2012-05-16 13:15:00 -07003254 availRight - mStableRight, availBottom - mStableBottom);
3255 }
Dianne Hackbornc652de82013-02-15 16:32:56 -08003256 } else if ((fl & FLAG_FULLSCREEN) != 0 || (fl & FLAG_LAYOUT_IN_OVERSCAN) != 0) {
Adrian Roos37d7a682014-11-06 18:15:16 +01003257 outContentInsets.setEmpty();
Dianne Hackborn5b5cc4d2012-05-16 13:15:00 -07003258 } else if ((systemUiVisibility & (View.SYSTEM_UI_FLAG_FULLSCREEN
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07003259 | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN)) == 0) {
Adrian Roos37d7a682014-11-06 18:15:16 +01003260 outContentInsets.set(mCurLeft, mCurTop,
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07003261 availRight - mCurRight, availBottom - mCurBottom);
3262 } else {
Adrian Roos37d7a682014-11-06 18:15:16 +01003263 outContentInsets.set(mCurLeft, mCurTop,
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07003264 availRight - mCurRight, availBottom - mCurBottom);
3265 }
Adrian Roos37d7a682014-11-06 18:15:16 +01003266
3267 outStableInsets.set(mStableLeft, mStableTop,
3268 availRight - mStableRight, availBottom - mStableBottom);
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07003269 return;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003270 }
Adrian Roos37d7a682014-11-06 18:15:16 +01003271 outContentInsets.setEmpty();
3272 outStableInsets.setEmpty();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003273 }
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07003274
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003275 /** {@inheritDoc} */
Craig Mautner69b08182012-09-05 13:07:13 -07003276 @Override
3277 public void beginLayoutLw(boolean isDefaultDisplay, int displayWidth, int displayHeight,
3278 int displayRotation) {
Dianne Hackbornc652de82013-02-15 16:32:56 -08003279 final int overscanLeft, overscanTop, overscanRight, overscanBottom;
3280 if (isDefaultDisplay) {
3281 switch (displayRotation) {
3282 case Surface.ROTATION_90:
3283 overscanLeft = mOverscanTop;
3284 overscanTop = mOverscanRight;
3285 overscanRight = mOverscanBottom;
3286 overscanBottom = mOverscanLeft;
3287 break;
3288 case Surface.ROTATION_180:
3289 overscanLeft = mOverscanRight;
3290 overscanTop = mOverscanBottom;
3291 overscanRight = mOverscanLeft;
3292 overscanBottom = mOverscanTop;
3293 break;
3294 case Surface.ROTATION_270:
3295 overscanLeft = mOverscanBottom;
3296 overscanTop = mOverscanLeft;
3297 overscanRight = mOverscanTop;
3298 overscanBottom = mOverscanRight;
3299 break;
3300 default:
3301 overscanLeft = mOverscanLeft;
3302 overscanTop = mOverscanTop;
3303 overscanRight = mOverscanRight;
3304 overscanBottom = mOverscanBottom;
3305 break;
3306 }
3307 } else {
3308 overscanLeft = 0;
3309 overscanTop = 0;
3310 overscanRight = 0;
3311 overscanBottom = 0;
3312 }
Dianne Hackborn313440842013-02-19 19:22:59 -08003313 mOverscanScreenLeft = mRestrictedOverscanScreenLeft = 0;
3314 mOverscanScreenTop = mRestrictedOverscanScreenTop = 0;
3315 mOverscanScreenWidth = mRestrictedOverscanScreenWidth = displayWidth;
3316 mOverscanScreenHeight = mRestrictedOverscanScreenHeight = displayHeight;
Dianne Hackbornc652de82013-02-15 16:32:56 -08003317 mSystemLeft = 0;
3318 mSystemTop = 0;
3319 mSystemRight = displayWidth;
3320 mSystemBottom = displayHeight;
3321 mUnrestrictedScreenLeft = overscanLeft;
3322 mUnrestrictedScreenTop = overscanTop;
3323 mUnrestrictedScreenWidth = displayWidth - overscanLeft - overscanRight;
3324 mUnrestrictedScreenHeight = displayHeight - overscanTop - overscanBottom;
3325 mRestrictedScreenLeft = mUnrestrictedScreenLeft;
3326 mRestrictedScreenTop = mUnrestrictedScreenTop;
John Spurlockad3e6cb2013-04-30 08:47:43 -04003327 mRestrictedScreenWidth = mSystemGestures.screenWidth = mUnrestrictedScreenWidth;
3328 mRestrictedScreenHeight = mSystemGestures.screenHeight = mUnrestrictedScreenHeight;
Dianne Hackborne30e02f2014-05-27 18:24:45 -07003329 mDockLeft = mContentLeft = mVoiceContentLeft = mStableLeft = mStableFullscreenLeft
Dianne Hackbornc652de82013-02-15 16:32:56 -08003330 = mCurLeft = mUnrestrictedScreenLeft;
Dianne Hackborne30e02f2014-05-27 18:24:45 -07003331 mDockTop = mContentTop = mVoiceContentTop = mStableTop = mStableFullscreenTop
Dianne Hackbornc652de82013-02-15 16:32:56 -08003332 = mCurTop = mUnrestrictedScreenTop;
Dianne Hackborne30e02f2014-05-27 18:24:45 -07003333 mDockRight = mContentRight = mVoiceContentRight = mStableRight = mStableFullscreenRight
Dianne Hackbornc652de82013-02-15 16:32:56 -08003334 = mCurRight = displayWidth - overscanRight;
Dianne Hackborne30e02f2014-05-27 18:24:45 -07003335 mDockBottom = mContentBottom = mVoiceContentBottom = mStableBottom = mStableFullscreenBottom
Dianne Hackbornc652de82013-02-15 16:32:56 -08003336 = mCurBottom = displayHeight - overscanBottom;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003337 mDockLayer = 0x10000000;
Dianne Hackborn5c58de32012-04-28 19:52:37 -07003338 mStatusBarLayer = -1;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003339
Daniel Sandler8956dbb2011-04-22 07:55:02 -04003340 // start with the current dock rect, which will be (0,0,displayWidth,displayHeight)
3341 final Rect pf = mTmpParentFrame;
3342 final Rect df = mTmpDisplayFrame;
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003343 final Rect of = mTmpOverscanFrame;
Daniel Sandler8956dbb2011-04-22 07:55:02 -04003344 final Rect vf = mTmpVisibleFrame;
John Spurlock46646232013-09-30 22:32:42 -04003345 final Rect dcf = mTmpDecorFrame;
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003346 pf.left = df.left = of.left = vf.left = mDockLeft;
3347 pf.top = df.top = of.top = vf.top = mDockTop;
3348 pf.right = df.right = of.right = vf.right = mDockRight;
3349 pf.bottom = df.bottom = of.bottom = vf.bottom = mDockBottom;
John Spurlock46646232013-09-30 22:32:42 -04003350 dcf.setEmpty(); // Decor frame N/A for system bars.
Daniel Sandler8956dbb2011-04-22 07:55:02 -04003351
Craig Mautner69b08182012-09-05 13:07:13 -07003352 if (isDefaultDisplay) {
3353 // For purposes of putting out fake window up to steal focus, we will
3354 // drive nav being hidden only by whether it is requested.
John Spurlocke1f366f2013-08-05 12:22:40 -04003355 final int sysui = mLastSystemUiFlags;
3356 boolean navVisible = (sysui & View.SYSTEM_UI_FLAG_HIDE_NAVIGATION) == 0;
Adrian Roosea562512014-05-05 13:33:03 +02003357 boolean navTranslucent = (sysui
3358 & (View.NAVIGATION_BAR_TRANSLUCENT | View.SYSTEM_UI_TRANSPARENT)) != 0;
John Spurlockf1a36642013-10-12 17:50:42 -04003359 boolean immersive = (sysui & View.SYSTEM_UI_FLAG_IMMERSIVE) != 0;
3360 boolean immersiveSticky = (sysui & View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY) != 0;
3361 boolean navAllowedHidden = immersive || immersiveSticky;
3362 navTranslucent &= !immersiveSticky; // transient trumps translucent
Adrian Roos4fb3ee32014-08-22 19:29:09 +02003363 boolean isKeyguardShowing = isStatusBarKeyguard() && !mHideLockScreen;
3364 if (!isKeyguardShowing) {
3365 navTranslucent &= areTranslucentBarsAllowed();
3366 }
Dianne Hackborne26ab702011-10-16 13:21:33 -07003367
Craig Mautner69b08182012-09-05 13:07:13 -07003368 // When the navigation bar isn't visible, we put up a fake
3369 // input window to catch all touch events. This way we can
3370 // detect when the user presses anywhere to bring back the nav
3371 // bar and ensure the application doesn't see the event.
John Spurlockf1a36642013-10-12 17:50:42 -04003372 if (navVisible || navAllowedHidden) {
Craig Mautner69b08182012-09-05 13:07:13 -07003373 if (mHideNavFakeWindow != null) {
3374 mHideNavFakeWindow.dismiss();
3375 mHideNavFakeWindow = null;
3376 }
3377 } else if (mHideNavFakeWindow == null) {
3378 mHideNavFakeWindow = mWindowManagerFuncs.addFakeWindow(
3379 mHandler.getLooper(), mHideNavInputEventReceiverFactory,
Adam Lesinski95c42972013-10-02 10:13:27 -07003380 "hidden nav", WindowManager.LayoutParams.TYPE_HIDDEN_NAV_CONSUMER, 0,
Craig Mautner69b08182012-09-05 13:07:13 -07003381 0, false, false, true);
Dianne Hackborne26ab702011-10-16 13:21:33 -07003382 }
Dianne Hackborne26ab702011-10-16 13:21:33 -07003383
Craig Mautner69b08182012-09-05 13:07:13 -07003384 // For purposes of positioning and showing the nav bar, if we have
3385 // decided that it can't be hidden (because of the screen aspect ratio),
3386 // then take that into account.
Alan Viverette5a0f4ec2013-10-07 15:10:29 -07003387 navVisible |= !canHideNavigationBar();
Dianne Hackbornf87d1962012-04-04 12:48:24 -07003388
John Spurlockad3e6cb2013-04-30 08:47:43 -04003389 boolean updateSysUiVisibility = false;
Craig Mautner69b08182012-09-05 13:07:13 -07003390 if (mNavigationBar != null) {
John Spurlock27735a42013-08-14 17:57:38 -04003391 boolean transientNavBarShowing = mNavigationBarController.isTransientShowing();
Craig Mautner69b08182012-09-05 13:07:13 -07003392 // Force the navigation bar to its appropriate place and
3393 // size. We need to do this directly, instead of relying on
3394 // it to bubble up from the nav bar, because this needs to
3395 // change atomically with screen rotations.
3396 mNavigationBarOnBottom = (!mNavigationBarCanMove || displayWidth < displayHeight);
3397 if (mNavigationBarOnBottom) {
3398 // It's a system nav bar or a portrait screen; nav bar goes on bottom.
Dianne Hackbornc652de82013-02-15 16:32:56 -08003399 int top = displayHeight - overscanBottom
3400 - mNavigationBarHeightForRotation[displayRotation];
3401 mTmpNavigationFrame.set(0, top, displayWidth, displayHeight - overscanBottom);
Craig Mautner69b08182012-09-05 13:07:13 -07003402 mStableBottom = mStableFullscreenBottom = mTmpNavigationFrame.top;
John Spurlockf95b89a2013-10-10 22:10:42 -04003403 if (transientNavBarShowing) {
John Spurlock27735a42013-08-14 17:57:38 -04003404 mNavigationBarController.setBarShowingLw(true);
John Spurlockad3e6cb2013-04-30 08:47:43 -04003405 } else if (navVisible) {
John Spurlock27735a42013-08-14 17:57:38 -04003406 mNavigationBarController.setBarShowingLw(true);
Craig Mautner69b08182012-09-05 13:07:13 -07003407 mDockBottom = mTmpNavigationFrame.top;
Dianne Hackborn313440842013-02-19 19:22:59 -08003408 mRestrictedScreenHeight = mDockBottom - mRestrictedScreenTop;
3409 mRestrictedOverscanScreenHeight = mDockBottom - mRestrictedOverscanScreenTop;
Craig Mautner69b08182012-09-05 13:07:13 -07003410 } else {
3411 // We currently want to hide the navigation UI.
John Spurlock27735a42013-08-14 17:57:38 -04003412 mNavigationBarController.setBarShowingLw(false);
Craig Mautner69b08182012-09-05 13:07:13 -07003413 }
John Spurlockc6d1c602014-01-17 15:22:06 -05003414 if (navVisible && !navTranslucent && !navAllowedHidden
3415 && !mNavigationBar.isAnimatingLw()
John Spurlockbd957402013-10-03 11:38:39 -04003416 && !mNavigationBarController.wasRecentlyTranslucent()) {
John Spurlocke1f366f2013-08-05 12:22:40 -04003417 // If the opaque nav bar is currently requested to be visible,
Craig Mautner69b08182012-09-05 13:07:13 -07003418 // and not in the process of animating on or off, then
3419 // we can tell the app that it is covered by it.
3420 mSystemBottom = mTmpNavigationFrame.top;
3421 }
Dianne Hackbornf87d1962012-04-04 12:48:24 -07003422 } else {
Craig Mautner69b08182012-09-05 13:07:13 -07003423 // Landscape screen; nav bar goes to the right.
Dianne Hackbornc652de82013-02-15 16:32:56 -08003424 int left = displayWidth - overscanRight
3425 - mNavigationBarWidthForRotation[displayRotation];
3426 mTmpNavigationFrame.set(left, 0, displayWidth - overscanRight, displayHeight);
Craig Mautner69b08182012-09-05 13:07:13 -07003427 mStableRight = mStableFullscreenRight = mTmpNavigationFrame.left;
John Spurlockf95b89a2013-10-10 22:10:42 -04003428 if (transientNavBarShowing) {
John Spurlock27735a42013-08-14 17:57:38 -04003429 mNavigationBarController.setBarShowingLw(true);
John Spurlockad3e6cb2013-04-30 08:47:43 -04003430 } else if (navVisible) {
John Spurlock27735a42013-08-14 17:57:38 -04003431 mNavigationBarController.setBarShowingLw(true);
Craig Mautner69b08182012-09-05 13:07:13 -07003432 mDockRight = mTmpNavigationFrame.left;
Dianne Hackborn313440842013-02-19 19:22:59 -08003433 mRestrictedScreenWidth = mDockRight - mRestrictedScreenLeft;
3434 mRestrictedOverscanScreenWidth = mDockRight - mRestrictedOverscanScreenLeft;
Craig Mautner69b08182012-09-05 13:07:13 -07003435 } else {
3436 // We currently want to hide the navigation UI.
John Spurlock27735a42013-08-14 17:57:38 -04003437 mNavigationBarController.setBarShowingLw(false);
Craig Mautner69b08182012-09-05 13:07:13 -07003438 }
John Spurlockbd957402013-10-03 11:38:39 -04003439 if (navVisible && !navTranslucent && !mNavigationBar.isAnimatingLw()
3440 && !mNavigationBarController.wasRecentlyTranslucent()) {
Craig Mautner69b08182012-09-05 13:07:13 -07003441 // If the nav bar is currently requested to be visible,
3442 // and not in the process of animating on or off, then
3443 // we can tell the app that it is covered by it.
3444 mSystemRight = mTmpNavigationFrame.left;
3445 }
Dianne Hackbornf87d1962012-04-04 12:48:24 -07003446 }
Craig Mautner69b08182012-09-05 13:07:13 -07003447 // Make sure the content and current rectangles are updated to
3448 // account for the restrictions from the navigation bar.
Dianne Hackborne30e02f2014-05-27 18:24:45 -07003449 mContentTop = mVoiceContentTop = mCurTop = mDockTop;
3450 mContentBottom = mVoiceContentBottom = mCurBottom = mDockBottom;
3451 mContentLeft = mVoiceContentLeft = mCurLeft = mDockLeft;
3452 mContentRight = mVoiceContentRight = mCurRight = mDockRight;
Craig Mautner69b08182012-09-05 13:07:13 -07003453 mStatusBarLayer = mNavigationBar.getSurfaceLayer();
3454 // And compute the final frame.
3455 mNavigationBar.computeFrameLw(mTmpNavigationFrame, mTmpNavigationFrame,
Adrian Roosfa104232014-06-20 16:10:14 -07003456 mTmpNavigationFrame, mTmpNavigationFrame, mTmpNavigationFrame, dcf,
3457 mTmpNavigationFrame);
Craig Mautnereda67292013-04-28 13:50:14 -07003458 if (DEBUG_LAYOUT) Slog.i(TAG, "mNavigationBar frame: " + mTmpNavigationFrame);
John Spurlock27735a42013-08-14 17:57:38 -04003459 if (mNavigationBarController.checkHiddenLw()) {
John Spurlockad3e6cb2013-04-30 08:47:43 -04003460 updateSysUiVisibility = true;
3461 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003462 }
Craig Mautnereda67292013-04-28 13:50:14 -07003463 if (DEBUG_LAYOUT) Slog.i(TAG, String.format("mDock rect: (%d,%d - %d,%d)",
Craig Mautner69b08182012-09-05 13:07:13 -07003464 mDockLeft, mDockTop, mDockRight, mDockBottom));
3465
3466 // decide where the status bar goes ahead of time
3467 if (mStatusBar != null) {
3468 // apply any navigation bar insets
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003469 pf.left = df.left = of.left = mUnrestrictedScreenLeft;
3470 pf.top = df.top = of.top = mUnrestrictedScreenTop;
3471 pf.right = df.right = of.right = mUnrestrictedScreenWidth + mUnrestrictedScreenLeft;
3472 pf.bottom = df.bottom = of.bottom = mUnrestrictedScreenHeight
3473 + mUnrestrictedScreenTop;
Craig Mautner69b08182012-09-05 13:07:13 -07003474 vf.left = mStableLeft;
3475 vf.top = mStableTop;
3476 vf.right = mStableRight;
3477 vf.bottom = mStableBottom;
3478
3479 mStatusBarLayer = mStatusBar.getSurfaceLayer();
3480
3481 // Let the status bar determine its size.
Adrian Roosfa104232014-06-20 16:10:14 -07003482 mStatusBar.computeFrameLw(pf, df, vf, vf, vf, dcf, vf);
Craig Mautner69b08182012-09-05 13:07:13 -07003483
3484 // For layout, the status bar is always at the top with our fixed height.
3485 mStableTop = mUnrestrictedScreenTop + mStatusBarHeight;
3486
John Spurlocke1f366f2013-08-05 12:22:40 -04003487 boolean statusBarTransient = (sysui & View.STATUS_BAR_TRANSIENT) != 0;
Adrian Roosea562512014-05-05 13:33:03 +02003488 boolean statusBarTranslucent = (sysui
3489 & (View.STATUS_BAR_TRANSLUCENT | View.SYSTEM_UI_TRANSPARENT)) != 0;
Adrian Roos4fb3ee32014-08-22 19:29:09 +02003490 if (!isKeyguardShowing) {
3491 statusBarTranslucent &= areTranslucentBarsAllowed();
3492 }
John Spurlock32beb2c2013-03-11 10:16:47 -04003493
Craig Mautner69b08182012-09-05 13:07:13 -07003494 // If the status bar is hidden, we don't want to cause
3495 // windows behind it to scroll.
John Spurlockeda1f692013-09-16 11:38:44 -04003496 if (mStatusBar.isVisibleLw() && !statusBarTransient) {
Craig Mautner69b08182012-09-05 13:07:13 -07003497 // Status bar may go away, so the screen area it occupies
3498 // is available to apps but just covering them when the
3499 // status bar is visible.
3500 mDockTop = mUnrestrictedScreenTop + mStatusBarHeight;
3501
Dianne Hackborne30e02f2014-05-27 18:24:45 -07003502 mContentTop = mVoiceContentTop = mCurTop = mDockTop;
3503 mContentBottom = mVoiceContentBottom = mCurBottom = mDockBottom;
3504 mContentLeft = mVoiceContentLeft = mCurLeft = mDockLeft;
3505 mContentRight = mVoiceContentRight = mCurRight = mDockRight;
Craig Mautner69b08182012-09-05 13:07:13 -07003506
Craig Mautnereda67292013-04-28 13:50:14 -07003507 if (DEBUG_LAYOUT) Slog.v(TAG, "Status bar: " +
Craig Mautner69b08182012-09-05 13:07:13 -07003508 String.format(
3509 "dock=[%d,%d][%d,%d] content=[%d,%d][%d,%d] cur=[%d,%d][%d,%d]",
3510 mDockLeft, mDockTop, mDockRight, mDockBottom,
3511 mContentLeft, mContentTop, mContentRight, mContentBottom,
3512 mCurLeft, mCurTop, mCurRight, mCurBottom));
3513 }
John Spurlocke1f366f2013-08-05 12:22:40 -04003514 if (mStatusBar.isVisibleLw() && !mStatusBar.isAnimatingLw()
John Spurlockbd957402013-10-03 11:38:39 -04003515 && !statusBarTransient && !statusBarTranslucent
3516 && !mStatusBarController.wasRecentlyTranslucent()) {
John Spurlocke1f366f2013-08-05 12:22:40 -04003517 // If the opaque status bar is currently requested to be visible,
Craig Mautner69b08182012-09-05 13:07:13 -07003518 // and not in the process of animating on or off, then
3519 // we can tell the app that it is covered by it.
3520 mSystemTop = mUnrestrictedScreenTop + mStatusBarHeight;
3521 }
John Spurlock27735a42013-08-14 17:57:38 -04003522 if (mStatusBarController.checkHiddenLw()) {
John Spurlockad3e6cb2013-04-30 08:47:43 -04003523 updateSysUiVisibility = true;
John Spurlock32beb2c2013-03-11 10:16:47 -04003524 }
Dianne Hackborn5c58de32012-04-28 19:52:37 -07003525 }
John Spurlockad3e6cb2013-04-30 08:47:43 -04003526 if (updateSysUiVisibility) {
3527 updateSystemUiVisibilityLw();
3528 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003529 }
3530 }
3531
Dianne Hackborn85afd1b2012-05-13 13:31:06 -07003532 /** {@inheritDoc} */
Craig Mautner967212c2013-04-13 21:10:58 -07003533 @Override
John Spurlock46646232013-09-30 22:32:42 -04003534 public int getSystemDecorLayerLw() {
Bryce Lee2ed3e5f2015-04-01 22:09:19 +00003535 if (mStatusBar != null && mStatusBar.isVisibleLw()) {
3536 return mStatusBar.getSurfaceLayer();
3537 }
3538
3539 if (mNavigationBar != null && mNavigationBar.isVisibleLw()) {
3540 return mNavigationBar.getSurfaceLayer();
3541 }
3542
Dianne Hackborn85afd1b2012-05-13 13:31:06 -07003543 return 0;
3544 }
3545
Craig Mautner967212c2013-04-13 21:10:58 -07003546 @Override
3547 public void getContentRectLw(Rect r) {
3548 r.set(mContentLeft, mContentTop, mContentRight, mContentBottom);
3549 }
3550
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003551 void setAttachedWindowFrames(WindowState win, int fl, int adjust, WindowState attached,
3552 boolean insetDecors, Rect pf, Rect df, Rect of, Rect cf, Rect vf) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003553 if (win.getSurfaceLayer() > mDockLayer && attached.getSurfaceLayer() < mDockLayer) {
3554 // Here's a special case: if this attached window is a panel that is
3555 // above the dock window, and the window it is attached to is below
3556 // the dock window, then the frames we computed for the window it is
3557 // attached to can not be used because the dock is effectively part
3558 // of the underlying window and the attached window is floating on top
3559 // of the whole thing. So, we ignore the attached window and explicitly
3560 // compute the frames that would be appropriate without the dock.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003561 df.left = of.left = cf.left = vf.left = mDockLeft;
3562 df.top = of.top = cf.top = vf.top = mDockTop;
3563 df.right = of.right = cf.right = vf.right = mDockRight;
3564 df.bottom = of.bottom = cf.bottom = vf.bottom = mDockBottom;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003565 } else {
3566 // The effective display frame of the attached window depends on
3567 // whether it is taking care of insetting its content. If not,
3568 // we need to use the parent's content frame so that the entire
3569 // window is positioned within that content. Otherwise we can use
Wale Ogunwale393b1c12014-10-18 16:22:01 -07003570 // the overscan frame and let the attached window take care of
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003571 // positioning its content appropriately.
Dianne Hackborndea3ef72010-10-28 14:24:22 -07003572 if (adjust != SOFT_INPUT_ADJUST_RESIZE) {
Wale Ogunwale393b1c12014-10-18 16:22:01 -07003573 // Set the content frame of the attached window to the parent's decor frame
3574 // (same as content frame when IME isn't present) if specifically requested by
3575 // setting {@link WindowManager.LayoutParams#FLAG_LAYOUT_ATTACHED_IN_DECOR} flag.
3576 // Otherwise, use the overscan frame.
3577 cf.set((fl & FLAG_LAYOUT_ATTACHED_IN_DECOR) != 0
3578 ? attached.getContentFrameLw() : attached.getOverscanFrameLw());
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003579 } else {
3580 // If the window is resizing, then we want to base the content
3581 // frame on our attached content frame to resize... however,
3582 // things can be tricky if the attached window is NOT in resize
3583 // mode, in which case its content frame will be larger.
3584 // Ungh. So to deal with that, make sure the content frame
3585 // we end up using is not covering the IM dock.
3586 cf.set(attached.getContentFrameLw());
Dianne Hackborne30e02f2014-05-27 18:24:45 -07003587 if (attached.isVoiceInteraction()) {
3588 if (cf.left < mVoiceContentLeft) cf.left = mVoiceContentLeft;
3589 if (cf.top < mVoiceContentTop) cf.top = mVoiceContentTop;
3590 if (cf.right > mVoiceContentRight) cf.right = mVoiceContentRight;
3591 if (cf.bottom > mVoiceContentBottom) cf.bottom = mVoiceContentBottom;
3592 } else if (attached.getSurfaceLayer() < mDockLayer) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003593 if (cf.left < mContentLeft) cf.left = mContentLeft;
3594 if (cf.top < mContentTop) cf.top = mContentTop;
3595 if (cf.right > mContentRight) cf.right = mContentRight;
3596 if (cf.bottom > mContentBottom) cf.bottom = mContentBottom;
3597 }
3598 }
3599 df.set(insetDecors ? attached.getDisplayFrameLw() : cf);
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003600 of.set(insetDecors ? attached.getOverscanFrameLw() : cf);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003601 vf.set(attached.getVisibleFrameLw());
3602 }
3603 // The LAYOUT_IN_SCREEN flag is used to determine whether the attached
3604 // window should be positioned relative to its parent or the entire
3605 // screen.
3606 pf.set((fl & FLAG_LAYOUT_IN_SCREEN) == 0
3607 ? attached.getFrameLw() : df);
3608 }
Dianne Hackborn5b5cc4d2012-05-16 13:15:00 -07003609
3610 private void applyStableConstraints(int sysui, int fl, Rect r) {
3611 if ((sysui & View.SYSTEM_UI_FLAG_LAYOUT_STABLE) != 0) {
3612 // If app is requesting a stable layout, don't let the
3613 // content insets go below the stable values.
3614 if ((fl & FLAG_FULLSCREEN) != 0) {
3615 if (r.left < mStableFullscreenLeft) r.left = mStableFullscreenLeft;
3616 if (r.top < mStableFullscreenTop) r.top = mStableFullscreenTop;
3617 if (r.right > mStableFullscreenRight) r.right = mStableFullscreenRight;
3618 if (r.bottom > mStableFullscreenBottom) r.bottom = mStableFullscreenBottom;
3619 } else {
3620 if (r.left < mStableLeft) r.left = mStableLeft;
3621 if (r.top < mStableTop) r.top = mStableTop;
3622 if (r.right > mStableRight) r.right = mStableRight;
3623 if (r.bottom > mStableBottom) r.bottom = mStableBottom;
3624 }
3625 }
3626 }
3627
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003628 /** {@inheritDoc} */
Craig Mautner69b08182012-09-05 13:07:13 -07003629 @Override
Craig Mautnerc9457fa2014-06-06 14:27:48 -07003630 public void layoutWindowLw(WindowState win, WindowState attached) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003631 // we've already done the status bar
Craig Mautnerc9457fa2014-06-06 14:27:48 -07003632 final WindowManager.LayoutParams attrs = win.getAttrs();
3633 if ((win == mStatusBar && (attrs.privateFlags & PRIVATE_FLAG_KEYGUARD) == 0) ||
3634 win == mNavigationBar) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003635 return;
3636 }
Craig Mautner69b08182012-09-05 13:07:13 -07003637 final boolean isDefaultDisplay = win.isDefaultDisplay();
3638 final boolean needsToOffsetInputMethodTarget = isDefaultDisplay &&
satok1bc0a492012-04-25 22:47:12 +09003639 (win == mLastInputMethodTargetWindow && mLastInputMethodWindow != null);
3640 if (needsToOffsetInputMethodTarget) {
Craig Mautnereda67292013-04-28 13:50:14 -07003641 if (DEBUG_LAYOUT) Slog.i(TAG, "Offset ime target window by the last ime window state");
satok1bc0a492012-04-25 22:47:12 +09003642 offsetInputMethodWindowLw(mLastInputMethodWindow);
3643 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003644
John Spurlockc6d1c602014-01-17 15:22:06 -05003645 final int fl = PolicyControl.getWindowFlags(win, attrs);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003646 final int sim = attrs.softInputMode;
John Spurlock1db8b682014-02-18 11:18:59 -05003647 final int sysUiFl = PolicyControl.getSystemUiVisibility(win, null);
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07003648
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003649 final Rect pf = mTmpParentFrame;
3650 final Rect df = mTmpDisplayFrame;
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003651 final Rect of = mTmpOverscanFrame;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003652 final Rect cf = mTmpContentFrame;
3653 final Rect vf = mTmpVisibleFrame;
John Spurlock46646232013-09-30 22:32:42 -04003654 final Rect dcf = mTmpDecorFrame;
Adrian Roosfa104232014-06-20 16:10:14 -07003655 final Rect sf = mTmpStableFrame;
John Spurlock46646232013-09-30 22:32:42 -04003656 dcf.setEmpty();
Craig Mautner69b08182012-09-05 13:07:13 -07003657
3658 final boolean hasNavBar = (isDefaultDisplay && mHasNavigationBar
Daniel Sandler36412a72011-08-04 09:35:13 -04003659 && mNavigationBar != null && mNavigationBar.isVisibleLw());
Daniel Sandler8956dbb2011-04-22 07:55:02 -04003660
Craig Mautnerf683b562012-10-02 11:10:57 -07003661 final int adjust = sim & SOFT_INPUT_MASK_ADJUST;
3662
Adrian Roosfa104232014-06-20 16:10:14 -07003663 if (isDefaultDisplay) {
3664 sf.set(mStableLeft, mStableTop, mStableRight, mStableBottom);
3665 } else {
3666 sf.set(mOverscanLeft, mOverscanTop, mOverscanRight, mOverscanBottom);
3667 }
3668
Craig Mautner69b08182012-09-05 13:07:13 -07003669 if (!isDefaultDisplay) {
3670 if (attached != null) {
3671 // If this window is attached to another, our display
3672 // frame is the same as the one we are attached to.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003673 setAttachedWindowFrames(win, fl, adjust, attached, true, pf, df, of, cf, vf);
Craig Mautner69b08182012-09-05 13:07:13 -07003674 } else {
3675 // Give the window full screen.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003676 pf.left = df.left = of.left = cf.left = mOverscanScreenLeft;
3677 pf.top = df.top = of.top = cf.top = mOverscanScreenTop;
3678 pf.right = df.right = of.right = cf.right
Dianne Hackbornc652de82013-02-15 16:32:56 -08003679 = mOverscanScreenLeft + mOverscanScreenWidth;
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003680 pf.bottom = df.bottom = of.bottom = cf.bottom
Dianne Hackbornc652de82013-02-15 16:32:56 -08003681 = mOverscanScreenTop + mOverscanScreenHeight;
Craig Mautner69b08182012-09-05 13:07:13 -07003682 }
Jorim Jaggi225d3b52015-04-01 11:18:57 -07003683 } else if (attrs.type == TYPE_INPUT_METHOD) {
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003684 pf.left = df.left = of.left = cf.left = vf.left = mDockLeft;
3685 pf.top = df.top = of.top = cf.top = vf.top = mDockTop;
3686 pf.right = df.right = of.right = cf.right = vf.right = mDockRight;
John Spurlockc68d5772013-10-08 11:47:58 -04003687 // IM dock windows layout below the nav bar...
John Spurlock57beb3b2013-10-10 10:27:44 -04003688 pf.bottom = df.bottom = of.bottom = mUnrestrictedScreenTop + mUnrestrictedScreenHeight;
John Spurlockc68d5772013-10-08 11:47:58 -04003689 // ...with content insets above the nav bar
3690 cf.bottom = vf.bottom = mStableBottom;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003691 // IM dock windows always go to the bottom of the screen.
3692 attrs.gravity = Gravity.BOTTOM;
3693 mDockLayer = win.getSurfaceLayer();
Jorim Jaggi225d3b52015-04-01 11:18:57 -07003694 } else if (attrs.type == TYPE_VOICE_INTERACTION) {
3695 pf.left = df.left = of.left = cf.left = vf.left = mUnrestrictedScreenLeft;
3696 pf.top = df.top = of.top = mUnrestrictedScreenTop;
3697 pf.right = df.right = of.right = cf.right = vf.right = mUnrestrictedScreenLeft
3698 + mUnrestrictedScreenWidth;
3699 pf.bottom = df.bottom = of.bottom = cf.bottom = mUnrestrictedScreenTop
3700 + mUnrestrictedScreenHeight;
3701 cf.bottom = vf.bottom = mStableBottom;
3702 cf.top = vf.top = mStableTop;
Jorim Jaggie0700182014-08-21 01:12:37 +02003703 } else if (win == mStatusBar && (attrs.privateFlags & PRIVATE_FLAG_KEYGUARD) != 0) {
3704 pf.left = df.left = of.left = mUnrestrictedScreenLeft;
3705 pf.top = df.top = of.top = mUnrestrictedScreenTop;
3706 pf.right = df.right = of.right = mUnrestrictedScreenWidth + mUnrestrictedScreenLeft;
3707 pf.bottom = df.bottom = of.bottom = mUnrestrictedScreenHeight + mUnrestrictedScreenTop;
3708 cf.left = vf.left = mStableLeft;
3709 cf.top = vf.top = mStableTop;
3710 cf.right = vf.right = mStableRight;
3711 vf.bottom = mStableBottom;
3712 cf.bottom = mContentBottom;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003713 } else {
John Spurlock46646232013-09-30 22:32:42 -04003714
3715 // Default policy decor for the default display
3716 dcf.left = mSystemLeft;
3717 dcf.top = mSystemTop;
3718 dcf.right = mSystemRight;
3719 dcf.bottom = mSystemBottom;
John Spurlockbd957402013-10-03 11:38:39 -04003720 final boolean inheritTranslucentDecor = (attrs.privateFlags
3721 & WindowManager.LayoutParams.PRIVATE_FLAG_INHERIT_TRANSLUCENT_DECOR) != 0;
John Spurlock65567d42013-10-08 10:08:32 -04003722 final boolean isAppWindow =
3723 attrs.type >= WindowManager.LayoutParams.FIRST_APPLICATION_WINDOW &&
3724 attrs.type <= WindowManager.LayoutParams.LAST_APPLICATION_WINDOW;
3725 final boolean topAtRest =
3726 win == mTopFullscreenOpaqueWindowState && !win.isAnimatingLw();
3727 if (isAppWindow && !inheritTranslucentDecor && !topAtRest) {
John Spurlockbd957402013-10-03 11:38:39 -04003728 if ((sysUiFl & View.SYSTEM_UI_FLAG_FULLSCREEN) == 0
3729 && (fl & WindowManager.LayoutParams.FLAG_FULLSCREEN) == 0
Adrian Roosea562512014-05-05 13:33:03 +02003730 && (fl & WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS) == 0
3731 && (fl & WindowManager.LayoutParams.
3732 FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS) == 0) {
John Spurlock46646232013-09-30 22:32:42 -04003733 // Ensure policy decor includes status bar
3734 dcf.top = mStableTop;
3735 }
John Spurlockbd957402013-10-03 11:38:39 -04003736 if ((fl & WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION) == 0
Adrian Roosea562512014-05-05 13:33:03 +02003737 && (sysUiFl & View.SYSTEM_UI_FLAG_HIDE_NAVIGATION) == 0
3738 && (fl & WindowManager.LayoutParams.
3739 FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS) == 0) {
John Spurlock46646232013-09-30 22:32:42 -04003740 // Ensure policy decor includes navigation bar
3741 dcf.bottom = mStableBottom;
3742 dcf.right = mStableRight;
3743 }
3744 }
3745
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003746 if ((fl & (FLAG_LAYOUT_IN_SCREEN | FLAG_LAYOUT_INSET_DECOR))
3747 == (FLAG_LAYOUT_IN_SCREEN | FLAG_LAYOUT_INSET_DECOR)) {
RoboErik8a2cfc32014-05-16 11:19:38 -07003748 if (DEBUG_LAYOUT) Slog.v(TAG, "layoutWindowLw(" + attrs.getTitle()
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003749 + "): IN_SCREEN, INSET_DECOR");
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003750 // This is the case for a normal activity window: we want it
3751 // to cover all of the screen space, and it can take care of
3752 // moving its contents to account for screen decorations that
3753 // intrude into that space.
3754 if (attached != null) {
3755 // If this window is attached to another, our display
3756 // frame is the same as the one we are attached to.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003757 setAttachedWindowFrames(win, fl, adjust, attached, true, pf, df, of, cf, vf);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003758 } else {
Daniel Sandler8956dbb2011-04-22 07:55:02 -04003759 if (attrs.type == TYPE_STATUS_BAR_PANEL
3760 || attrs.type == TYPE_STATUS_BAR_SUB_PANEL) {
Joe Onorato29fc2c92010-11-24 10:26:50 -08003761 // Status bar panels are the only windows who can go on top of
3762 // the status bar. They are protected by the STATUS_BAR_SERVICE
3763 // permission, so they have the same privileges as the status
3764 // bar itself.
Daniel Sandler8956dbb2011-04-22 07:55:02 -04003765 //
Daniel Sandler8e8b4152011-07-21 01:16:43 -04003766 // However, they should still dodge the navigation bar if it exists.
Daniel Sandler8956dbb2011-04-22 07:55:02 -04003767
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003768 pf.left = df.left = of.left = hasNavBar
3769 ? mDockLeft : mUnrestrictedScreenLeft;
3770 pf.top = df.top = of.top = mUnrestrictedScreenTop;
3771 pf.right = df.right = of.right = hasNavBar
3772 ? mRestrictedScreenLeft+mRestrictedScreenWidth
3773 : mUnrestrictedScreenLeft + mUnrestrictedScreenWidth;
3774 pf.bottom = df.bottom = of.bottom = hasNavBar
3775 ? mRestrictedScreenTop+mRestrictedScreenHeight
3776 : mUnrestrictedScreenTop + mUnrestrictedScreenHeight;
Daniel Sandler8956dbb2011-04-22 07:55:02 -04003777
Craig Mautnereda67292013-04-28 13:50:14 -07003778 if (DEBUG_LAYOUT) Slog.v(TAG, String.format(
Daniel Sandler8e8b4152011-07-21 01:16:43 -04003779 "Laying out status bar window: (%d,%d - %d,%d)",
3780 pf.left, pf.top, pf.right, pf.bottom));
John Spurlock46646232013-09-30 22:32:42 -04003781 } else if ((fl & FLAG_LAYOUT_IN_OVERSCAN) != 0
Dianne Hackbornc652de82013-02-15 16:32:56 -08003782 && attrs.type >= WindowManager.LayoutParams.FIRST_APPLICATION_WINDOW
3783 && attrs.type <= WindowManager.LayoutParams.LAST_SUB_WINDOW) {
3784 // Asking to layout into the overscan region, so give it that pure
3785 // unrestricted area.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003786 pf.left = df.left = of.left = mOverscanScreenLeft;
3787 pf.top = df.top = of.top = mOverscanScreenTop;
3788 pf.right = df.right = of.right = mOverscanScreenLeft + mOverscanScreenWidth;
3789 pf.bottom = df.bottom = of.bottom = mOverscanScreenTop
3790 + mOverscanScreenHeight;
Alan Viverette5a0f4ec2013-10-07 15:10:29 -07003791 } else if (canHideNavigationBar()
Dianne Hackbornf87d1962012-04-04 12:48:24 -07003792 && (sysUiFl & View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION) != 0
Jorim Jaggi380ecb82014-03-14 17:25:20 +01003793 && attrs.type >= WindowManager.LayoutParams.FIRST_APPLICATION_WINDOW
3794 && attrs.type <= WindowManager.LayoutParams.LAST_SUB_WINDOW) {
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07003795 // Asking for layout as if the nav bar is hidden, lets the
Dianne Hackbornc652de82013-02-15 16:32:56 -08003796 // application extend into the unrestricted overscan screen area. We
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07003797 // only do this for application windows to ensure no window that
3798 // can be above the nav bar can do this.
Dianne Hackborn313440842013-02-19 19:22:59 -08003799 pf.left = df.left = mOverscanScreenLeft;
3800 pf.top = df.top = mOverscanScreenTop;
3801 pf.right = df.right = mOverscanScreenLeft + mOverscanScreenWidth;
3802 pf.bottom = df.bottom = mOverscanScreenTop + mOverscanScreenHeight;
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003803 // We need to tell the app about where the frame inside the overscan
3804 // is, so it can inset its content by that amount -- it didn't ask
3805 // to actually extend itself into the overscan region.
3806 of.left = mUnrestrictedScreenLeft;
3807 of.top = mUnrestrictedScreenTop;
3808 of.right = mUnrestrictedScreenLeft + mUnrestrictedScreenWidth;
3809 of.bottom = mUnrestrictedScreenTop + mUnrestrictedScreenHeight;
Joe Onorato29fc2c92010-11-24 10:26:50 -08003810 } else {
Dianne Hackborn313440842013-02-19 19:22:59 -08003811 pf.left = df.left = mRestrictedOverscanScreenLeft;
3812 pf.top = df.top = mRestrictedOverscanScreenTop;
3813 pf.right = df.right = mRestrictedOverscanScreenLeft
3814 + mRestrictedOverscanScreenWidth;
3815 pf.bottom = df.bottom = mRestrictedOverscanScreenTop
3816 + mRestrictedOverscanScreenHeight;
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003817 // We need to tell the app about where the frame inside the overscan
3818 // is, so it can inset its content by that amount -- it didn't ask
3819 // to actually extend itself into the overscan region.
3820 of.left = mUnrestrictedScreenLeft;
3821 of.top = mUnrestrictedScreenTop;
3822 of.right = mUnrestrictedScreenLeft + mUnrestrictedScreenWidth;
3823 of.bottom = mUnrestrictedScreenTop + mUnrestrictedScreenHeight;
Joe Onorato29fc2c92010-11-24 10:26:50 -08003824 }
Craig Mautner69b08182012-09-05 13:07:13 -07003825
John Spurlock46646232013-09-30 22:32:42 -04003826 if ((fl & FLAG_FULLSCREEN) == 0) {
Dianne Hackborne30e02f2014-05-27 18:24:45 -07003827 if (win.isVoiceInteraction()) {
3828 cf.left = mVoiceContentLeft;
3829 cf.top = mVoiceContentTop;
3830 cf.right = mVoiceContentRight;
3831 cf.bottom = mVoiceContentBottom;
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003832 } else {
Dianne Hackborne30e02f2014-05-27 18:24:45 -07003833 if (adjust != SOFT_INPUT_ADJUST_RESIZE) {
3834 cf.left = mDockLeft;
3835 cf.top = mDockTop;
3836 cf.right = mDockRight;
3837 cf.bottom = mDockBottom;
3838 } else {
3839 cf.left = mContentLeft;
3840 cf.top = mContentTop;
3841 cf.right = mContentRight;
3842 cf.bottom = mContentBottom;
3843 }
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003844 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003845 } else {
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003846 // Full screen windows are always given a layout that is as if the
3847 // status bar and other transient decors are gone. This is to avoid
3848 // bad states when moving from a window that is not hding the
3849 // status bar to one that is.
3850 cf.left = mRestrictedScreenLeft;
3851 cf.top = mRestrictedScreenTop;
3852 cf.right = mRestrictedScreenLeft + mRestrictedScreenWidth;
3853 cf.bottom = mRestrictedScreenTop + mRestrictedScreenHeight;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003854 }
Dianne Hackborn5b5cc4d2012-05-16 13:15:00 -07003855 applyStableConstraints(sysUiFl, fl, cf);
Dianne Hackborndea3ef72010-10-28 14:24:22 -07003856 if (adjust != SOFT_INPUT_ADJUST_NOTHING) {
3857 vf.left = mCurLeft;
3858 vf.top = mCurTop;
3859 vf.right = mCurRight;
3860 vf.bottom = mCurBottom;
3861 } else {
3862 vf.set(cf);
3863 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003864 }
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07003865 } else if ((fl & FLAG_LAYOUT_IN_SCREEN) != 0 || (sysUiFl
3866 & (View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
3867 | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION)) != 0) {
Craig Mautnereda67292013-04-28 13:50:14 -07003868 if (DEBUG_LAYOUT) Slog.v(TAG, "layoutWindowLw(" + attrs.getTitle() +
3869 "): IN_SCREEN");
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003870 // A window that has requested to fill the entire screen just
3871 // gets everything, period.
Daniel Sandler8956dbb2011-04-22 07:55:02 -04003872 if (attrs.type == TYPE_STATUS_BAR_PANEL
3873 || attrs.type == TYPE_STATUS_BAR_SUB_PANEL) {
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003874 pf.left = df.left = of.left = cf.left = hasNavBar
3875 ? mDockLeft : mUnrestrictedScreenLeft;
3876 pf.top = df.top = of.top = cf.top = mUnrestrictedScreenTop;
3877 pf.right = df.right = of.right = cf.right = hasNavBar
Daniel Sandler8e8b4152011-07-21 01:16:43 -04003878 ? mRestrictedScreenLeft+mRestrictedScreenWidth
Dianne Hackbornc652de82013-02-15 16:32:56 -08003879 : mUnrestrictedScreenLeft + mUnrestrictedScreenWidth;
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003880 pf.bottom = df.bottom = of.bottom = cf.bottom = hasNavBar
Daniel Sandler8e8b4152011-07-21 01:16:43 -04003881 ? mRestrictedScreenTop+mRestrictedScreenHeight
Dianne Hackbornc652de82013-02-15 16:32:56 -08003882 : mUnrestrictedScreenTop + mUnrestrictedScreenHeight;
Craig Mautnereda67292013-04-28 13:50:14 -07003883 if (DEBUG_LAYOUT) Slog.v(TAG, String.format(
Daniel Sandler36412a72011-08-04 09:35:13 -04003884 "Laying out IN_SCREEN status bar window: (%d,%d - %d,%d)",
3885 pf.left, pf.top, pf.right, pf.bottom));
Jim Millere898ac52012-04-06 17:10:57 -07003886 } else if (attrs.type == TYPE_NAVIGATION_BAR
3887 || attrs.type == TYPE_NAVIGATION_BAR_PANEL) {
Daniel Sandler8e8b4152011-07-21 01:16:43 -04003888 // The navigation bar has Real Ultimate Power.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003889 pf.left = df.left = of.left = mUnrestrictedScreenLeft;
3890 pf.top = df.top = of.top = mUnrestrictedScreenTop;
3891 pf.right = df.right = of.right = mUnrestrictedScreenLeft
3892 + mUnrestrictedScreenWidth;
3893 pf.bottom = df.bottom = of.bottom = mUnrestrictedScreenTop
3894 + mUnrestrictedScreenHeight;
Craig Mautnereda67292013-04-28 13:50:14 -07003895 if (DEBUG_LAYOUT) Slog.v(TAG, String.format(
Daniel Sandler8e8b4152011-07-21 01:16:43 -04003896 "Laying out navigation bar window: (%d,%d - %d,%d)",
3897 pf.left, pf.top, pf.right, pf.bottom));
Dianne Hackborn01011c32012-02-21 13:54:21 -08003898 } else if ((attrs.type == TYPE_SECURE_SYSTEM_OVERLAY
3899 || attrs.type == TYPE_BOOT_PROGRESS)
Jeff Brownbfcb60a2011-09-08 18:51:14 -07003900 && ((fl & FLAG_FULLSCREEN) != 0)) {
3901 // Fullscreen secure system overlays get what they ask for.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003902 pf.left = df.left = of.left = cf.left = mOverscanScreenLeft;
3903 pf.top = df.top = of.top = cf.top = mOverscanScreenTop;
3904 pf.right = df.right = of.right = cf.right = mOverscanScreenLeft
3905 + mOverscanScreenWidth;
3906 pf.bottom = df.bottom = of.bottom = cf.bottom = mOverscanScreenTop
3907 + mOverscanScreenHeight;
Craig Mautner165be0c2015-01-27 15:16:58 -08003908 } else if (attrs.type == TYPE_BOOT_PROGRESS) {
Dianne Hackborn01011c32012-02-21 13:54:21 -08003909 // Boot progress screen always covers entire display.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003910 pf.left = df.left = of.left = cf.left = mOverscanScreenLeft;
3911 pf.top = df.top = of.top = cf.top = mOverscanScreenTop;
3912 pf.right = df.right = of.right = cf.right = mOverscanScreenLeft
3913 + mOverscanScreenWidth;
3914 pf.bottom = df.bottom = of.bottom = cf.bottom = mOverscanScreenTop
3915 + mOverscanScreenHeight;
John Spurlockef4adae2013-08-26 17:58:58 -04003916 } else if (attrs.type == TYPE_WALLPAPER) {
Dianne Hackborn067e5f62014-09-07 23:14:30 -07003917 // The wallpaper also has Real Ultimate Power, but we want to tell
3918 // it about the overscan area.
3919 pf.left = df.left = mOverscanScreenLeft;
3920 pf.top = df.top = mOverscanScreenTop;
3921 pf.right = df.right = mOverscanScreenLeft + mOverscanScreenWidth;
3922 pf.bottom = df.bottom = mOverscanScreenTop + mOverscanScreenHeight;
3923 of.left = cf.left = mUnrestrictedScreenLeft;
3924 of.top = cf.top = mUnrestrictedScreenTop;
3925 of.right = cf.right = mUnrestrictedScreenLeft + mUnrestrictedScreenWidth;
3926 of.bottom = cf.bottom = mUnrestrictedScreenTop + mUnrestrictedScreenHeight;
John Spurlock46646232013-09-30 22:32:42 -04003927 } else if ((fl & FLAG_LAYOUT_IN_OVERSCAN) != 0
Dianne Hackbornc652de82013-02-15 16:32:56 -08003928 && attrs.type >= WindowManager.LayoutParams.FIRST_APPLICATION_WINDOW
3929 && attrs.type <= WindowManager.LayoutParams.LAST_SUB_WINDOW) {
3930 // Asking to layout into the overscan region, so give it that pure
3931 // unrestricted area.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003932 pf.left = df.left = of.left = cf.left = mOverscanScreenLeft;
3933 pf.top = df.top = of.top = cf.top = mOverscanScreenTop;
3934 pf.right = df.right = of.right = cf.right
Dianne Hackbornc652de82013-02-15 16:32:56 -08003935 = mOverscanScreenLeft + mOverscanScreenWidth;
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003936 pf.bottom = df.bottom = of.bottom = cf.bottom
Dianne Hackbornc652de82013-02-15 16:32:56 -08003937 = mOverscanScreenTop + mOverscanScreenHeight;
Alan Viverette5a0f4ec2013-10-07 15:10:29 -07003938 } else if (canHideNavigationBar()
Dianne Hackbornf87d1962012-04-04 12:48:24 -07003939 && (sysUiFl & View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION) != 0
Craig Mautnerbeac1062014-06-03 14:38:57 -07003940 && (attrs.type == TYPE_STATUS_BAR
3941 || attrs.type == TYPE_TOAST
Jorim Jaggi2fdeeab2015-04-01 15:13:03 -07003942 || attrs.type == TYPE_VOICE_INTERACTION_STARTING
John Spurlock34e13d92013-08-10 06:52:28 -04003943 || (attrs.type >= WindowManager.LayoutParams.FIRST_APPLICATION_WINDOW
3944 && attrs.type <= WindowManager.LayoutParams.LAST_SUB_WINDOW))) {
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07003945 // Asking for layout as if the nav bar is hidden, lets the
3946 // application extend into the unrestricted screen area. We
John Spurlock34e13d92013-08-10 06:52:28 -04003947 // only do this for application windows (or toasts) to ensure no window that
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07003948 // can be above the nav bar can do this.
3949 // XXX This assumes that an app asking for this will also
3950 // ask for layout in only content. We can't currently figure out
3951 // what the screen would be if only laying out to hide the nav bar.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003952 pf.left = df.left = of.left = cf.left = mUnrestrictedScreenLeft;
3953 pf.top = df.top = of.top = cf.top = mUnrestrictedScreenTop;
3954 pf.right = df.right = of.right = cf.right = mUnrestrictedScreenLeft
3955 + mUnrestrictedScreenWidth;
3956 pf.bottom = df.bottom = of.bottom = cf.bottom = mUnrestrictedScreenTop
3957 + mUnrestrictedScreenHeight;
Joe Onorato29fc2c92010-11-24 10:26:50 -08003958 } else {
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003959 pf.left = df.left = of.left = cf.left = mRestrictedScreenLeft;
3960 pf.top = df.top = of.top = cf.top = mRestrictedScreenTop;
3961 pf.right = df.right = of.right = cf.right = mRestrictedScreenLeft
3962 + mRestrictedScreenWidth;
3963 pf.bottom = df.bottom = of.bottom = cf.bottom = mRestrictedScreenTop
3964 + mRestrictedScreenHeight;
Joe Onorato29fc2c92010-11-24 10:26:50 -08003965 }
Craig Mautner69b08182012-09-05 13:07:13 -07003966
Dianne Hackborn5b5cc4d2012-05-16 13:15:00 -07003967 applyStableConstraints(sysUiFl, fl, cf);
Craig Mautner69b08182012-09-05 13:07:13 -07003968
Dianne Hackborndea3ef72010-10-28 14:24:22 -07003969 if (adjust != SOFT_INPUT_ADJUST_NOTHING) {
3970 vf.left = mCurLeft;
3971 vf.top = mCurTop;
3972 vf.right = mCurRight;
3973 vf.bottom = mCurBottom;
3974 } else {
3975 vf.set(cf);
3976 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003977 } else if (attached != null) {
Craig Mautnereda67292013-04-28 13:50:14 -07003978 if (DEBUG_LAYOUT) Slog.v(TAG, "layoutWindowLw(" + attrs.getTitle() +
3979 "): attached to " + attached);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003980 // A child window should be placed inside of the same visible
3981 // frame that its parent had.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003982 setAttachedWindowFrames(win, fl, adjust, attached, false, pf, df, of, cf, vf);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003983 } else {
Craig Mautnereda67292013-04-28 13:50:14 -07003984 if (DEBUG_LAYOUT) Slog.v(TAG, "layoutWindowLw(" + attrs.getTitle() +
3985 "): normal window");
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003986 // Otherwise, a normal window must be placed inside the content
3987 // of all screen decorations.
Dianne Hackborna239c842011-06-01 12:28:20 -07003988 if (attrs.type == TYPE_STATUS_BAR_PANEL) {
3989 // Status bar panels are the only windows who can go on top of
3990 // the status bar. They are protected by the STATUS_BAR_SERVICE
3991 // permission, so they have the same privileges as the status
3992 // bar itself.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003993 pf.left = df.left = of.left = cf.left = mRestrictedScreenLeft;
3994 pf.top = df.top = of.top = cf.top = mRestrictedScreenTop;
3995 pf.right = df.right = of.right = cf.right = mRestrictedScreenLeft
3996 + mRestrictedScreenWidth;
3997 pf.bottom = df.bottom = of.bottom = cf.bottom = mRestrictedScreenTop
3998 + mRestrictedScreenHeight;
John Spurlock414c1f02013-12-04 13:47:36 -05003999 } else if (attrs.type == TYPE_TOAST || attrs.type == TYPE_SYSTEM_ALERT
4000 || attrs.type == TYPE_VOLUME_OVERLAY) {
4001 // These dialogs are stable to interim decor changes.
John Spurlockbd957402013-10-03 11:38:39 -04004002 pf.left = df.left = of.left = cf.left = mStableLeft;
4003 pf.top = df.top = of.top = cf.top = mStableTop;
4004 pf.right = df.right = of.right = cf.right = mStableRight;
4005 pf.bottom = df.bottom = of.bottom = cf.bottom = mStableBottom;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004006 } else {
Dianne Hackborna239c842011-06-01 12:28:20 -07004007 pf.left = mContentLeft;
4008 pf.top = mContentTop;
4009 pf.right = mContentRight;
4010 pf.bottom = mContentBottom;
Dianne Hackborn20d94742014-05-29 18:35:45 -07004011 if (win.isVoiceInteraction()) {
4012 df.left = of.left = cf.left = mVoiceContentLeft;
4013 df.top = of.top = cf.top = mVoiceContentTop;
4014 df.right = of.right = cf.right = mVoiceContentRight;
4015 df.bottom = of.bottom = cf.bottom = mVoiceContentBottom;
4016 } else if (adjust != SOFT_INPUT_ADJUST_RESIZE) {
Dianne Hackbornc4aad012013-02-22 15:05:25 -08004017 df.left = of.left = cf.left = mDockLeft;
4018 df.top = of.top = cf.top = mDockTop;
4019 df.right = of.right = cf.right = mDockRight;
4020 df.bottom = of.bottom = cf.bottom = mDockBottom;
Dianne Hackborna239c842011-06-01 12:28:20 -07004021 } else {
Dianne Hackbornc4aad012013-02-22 15:05:25 -08004022 df.left = of.left = cf.left = mContentLeft;
4023 df.top = of.top = cf.top = mContentTop;
4024 df.right = of.right = cf.right = mContentRight;
4025 df.bottom = of.bottom = cf.bottom = mContentBottom;
Dianne Hackborna239c842011-06-01 12:28:20 -07004026 }
4027 if (adjust != SOFT_INPUT_ADJUST_NOTHING) {
4028 vf.left = mCurLeft;
4029 vf.top = mCurTop;
4030 vf.right = mCurRight;
4031 vf.bottom = mCurBottom;
4032 } else {
4033 vf.set(cf);
4034 }
Dianne Hackborndea3ef72010-10-28 14:24:22 -07004035 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004036 }
4037 }
Craig Mautner69b08182012-09-05 13:07:13 -07004038
Craig Mautnerb816bed2013-07-23 10:26:17 -07004039 // TYPE_SYSTEM_ERROR is above the NavigationBar so it can't be allowed to extend over it.
4040 if ((fl & FLAG_LAYOUT_NO_LIMITS) != 0 && attrs.type != TYPE_SYSTEM_ERROR) {
Dianne Hackborn067e5f62014-09-07 23:14:30 -07004041 df.left = df.top = -10000;
4042 df.right = df.bottom = 10000;
4043 if (attrs.type != TYPE_WALLPAPER) {
4044 of.left = of.top = cf.left = cf.top = vf.left = vf.top = -10000;
4045 of.right = of.bottom = cf.right = cf.bottom = vf.right = vf.bottom = 10000;
4046 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004047 }
4048
Craig Mautnereda67292013-04-28 13:50:14 -07004049 if (DEBUG_LAYOUT) Slog.v(TAG, "Compute frame " + attrs.getTitle()
The Android Open Source Project11267662009-03-18 17:39:47 -07004050 + ": sim=#" + Integer.toHexString(sim)
RoboErik8a2cfc32014-05-16 11:19:38 -07004051 + " attach=" + attached + " type=" + attrs.type
Daniel Sandler8956dbb2011-04-22 07:55:02 -04004052 + String.format(" flags=0x%08x", fl)
The Android Open Source Project11267662009-03-18 17:39:47 -07004053 + " pf=" + pf.toShortString() + " df=" + df.toShortString()
Dianne Hackbornc4aad012013-02-22 15:05:25 -08004054 + " of=" + of.toShortString()
John Spurlock46646232013-09-30 22:32:42 -04004055 + " cf=" + cf.toShortString() + " vf=" + vf.toShortString()
Adrian Roosfa104232014-06-20 16:10:14 -07004056 + " dcf=" + dcf.toShortString()
4057 + " sf=" + sf.toShortString());
Craig Mautner69b08182012-09-05 13:07:13 -07004058
Adrian Roosfa104232014-06-20 16:10:14 -07004059 win.computeFrameLw(pf, df, of, cf, vf, dcf, sf);
Craig Mautner69b08182012-09-05 13:07:13 -07004060
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004061 // Dock windows carve out the bottom of the screen, so normal windows
4062 // can't appear underneath them.
Craig Mautner8bd206b2012-10-03 10:32:02 -07004063 if (attrs.type == TYPE_INPUT_METHOD && win.isVisibleOrBehindKeyguardLw()
4064 && !win.getGivenInsetsPendingLw()) {
satok1bc0a492012-04-25 22:47:12 +09004065 setLastInputMethodWindowLw(null, null);
4066 offsetInputMethodWindowLw(win);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004067 }
Dianne Hackborne30e02f2014-05-27 18:24:45 -07004068 if (attrs.type == TYPE_VOICE_INTERACTION && win.isVisibleOrBehindKeyguardLw()
4069 && !win.getGivenInsetsPendingLw()) {
4070 offsetVoiceInputWindowLw(win);
4071 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004072 }
4073
satok1bc0a492012-04-25 22:47:12 +09004074 private void offsetInputMethodWindowLw(WindowState win) {
Craig Mautner4774f6a2015-03-23 11:42:55 -07004075 int top = Math.max(win.getDisplayFrameLw().top, win.getContentFrameLw().top);
satok1bc0a492012-04-25 22:47:12 +09004076 top += win.getGivenContentInsetsLw().top;
4077 if (mContentBottom > top) {
4078 mContentBottom = top;
4079 }
Dianne Hackborne30e02f2014-05-27 18:24:45 -07004080 if (mVoiceContentBottom > top) {
4081 mVoiceContentBottom = top;
4082 }
satok1bc0a492012-04-25 22:47:12 +09004083 top = win.getVisibleFrameLw().top;
4084 top += win.getGivenVisibleInsetsLw().top;
4085 if (mCurBottom > top) {
4086 mCurBottom = top;
4087 }
Craig Mautnereda67292013-04-28 13:50:14 -07004088 if (DEBUG_LAYOUT) Slog.v(TAG, "Input method: mDockBottom="
satok1bc0a492012-04-25 22:47:12 +09004089 + mDockBottom + " mContentBottom="
4090 + mContentBottom + " mCurBottom=" + mCurBottom);
4091 }
4092
Dianne Hackborne30e02f2014-05-27 18:24:45 -07004093 private void offsetVoiceInputWindowLw(WindowState win) {
Craig Mautner4774f6a2015-03-23 11:42:55 -07004094 int top = Math.max(win.getDisplayFrameLw().top, win.getContentFrameLw().top);
Dianne Hackbornae6688b2015-02-11 17:02:41 -08004095 top += win.getGivenContentInsetsLw().top;
4096 if (mVoiceContentBottom > top) {
4097 mVoiceContentBottom = top;
Dianne Hackborne30e02f2014-05-27 18:24:45 -07004098 }
4099 }
4100
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004101 /** {@inheritDoc} */
Craig Mautner61ac6bb2012-02-02 17:29:33 -08004102 @Override
4103 public void finishLayoutLw() {
4104 return;
Dianne Hackborn5f3063e2010-03-10 16:01:58 -08004105 }
4106
4107 /** {@inheritDoc} */
Craig Mautnerad09bcc2012-10-08 13:33:11 -07004108 @Override
Craig Mautner39834192012-09-02 07:47:24 -07004109 public void beginPostLayoutPolicyLw(int displayWidth, int displayHeight) {
Dianne Hackborn5f3063e2010-03-10 16:01:58 -08004110 mTopFullscreenOpaqueWindowState = null;
Adrian Rooscd3884d2015-02-18 17:25:23 +01004111 mTopFullscreenOpaqueOrDimmingWindowState = null;
Craig Mautner2bc789b2014-03-19 19:48:38 -07004112 mAppsToBeHidden.clear();
Jorim Jaggic13fcac2014-09-11 17:36:57 +02004113 mAppsThatDismissKeyguard.clear();
Dianne Hackborn5f3063e2010-03-10 16:01:58 -08004114 mForceStatusBar = false;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07004115 mForceStatusBarFromKeyguard = false;
Dianne Hackborn891d3fb2013-01-09 18:31:37 -08004116 mForcingShowNavBar = false;
4117 mForcingShowNavBarLayer = -1;
RoboErik8a2cfc32014-05-16 11:19:38 -07004118
Dianne Hackborn5f3063e2010-03-10 16:01:58 -08004119 mHideLockScreen = false;
4120 mAllowLockscreenWhenOn = false;
Craig Mautnerad09bcc2012-10-08 13:33:11 -07004121 mDismissKeyguard = DISMISS_KEYGUARD_NONE;
Dianne Hackborn7ad44382012-10-18 17:46:00 -07004122 mShowingLockscreen = false;
4123 mShowingDream = false;
Craig Mautnerc9457fa2014-06-06 14:27:48 -07004124 mWinShowWhenLocked = null;
Jim Millerab954542014-10-10 18:21:49 -07004125 mKeyguardSecure = isKeyguardSecure();
4126 mKeyguardSecureIncludingHidden = mKeyguardSecure
4127 && (mKeyguardDelegate != null && mKeyguardDelegate.isShowing());
Dianne Hackborn5f3063e2010-03-10 16:01:58 -08004128 }
4129
4130 /** {@inheritDoc} */
Craig Mautnerad09bcc2012-10-08 13:33:11 -07004131 @Override
Craig Mautnerc9457fa2014-06-06 14:27:48 -07004132 public void applyPostLayoutPolicyLw(WindowState win, WindowManager.LayoutParams attrs) {
Dianne Hackbornbc1aa7b2011-09-20 11:20:31 -07004133 if (DEBUG_LAYOUT) Slog.i(TAG, "Win " + win + ": isVisibleOrBehindKeyguardLw="
4134 + win.isVisibleOrBehindKeyguardLw());
John Spurlockc6d1c602014-01-17 15:22:06 -05004135 final int fl = PolicyControl.getWindowFlags(win, attrs);
John Spurlock414c1f02013-12-04 13:47:36 -05004136 if (mTopFullscreenOpaqueWindowState == null
4137 && win.isVisibleLw() && attrs.type == TYPE_INPUT_METHOD) {
4138 mForcingShowNavBar = true;
4139 mForcingShowNavBarLayer = win.getSurfaceLayer();
Dianne Hackborn891d3fb2013-01-09 18:31:37 -08004140 }
Jorim Jaggiafd4a552014-04-08 15:13:05 +02004141 if (attrs.type == TYPE_STATUS_BAR && (attrs.privateFlags & PRIVATE_FLAG_KEYGUARD) != 0) {
Jorim Jaggiafd4a552014-04-08 15:13:05 +02004142 mForceStatusBarFromKeyguard = true;
4143 }
Adrian Roos602c68e2015-04-24 16:03:47 -07004144
4145 boolean appWindow = attrs.type >= FIRST_APPLICATION_WINDOW
4146 && attrs.type < FIRST_SYSTEM_WINDOW;
4147 final boolean showWhenLocked = (fl & FLAG_SHOW_WHEN_LOCKED) != 0;
4148 final boolean dismissKeyguard = (fl & FLAG_DISMISS_KEYGUARD) != 0;
4149
Dianne Hackborn5f3063e2010-03-10 16:01:58 -08004150 if (mTopFullscreenOpaqueWindowState == null &&
Dianne Hackborn01b02a72012-01-12 14:05:03 -08004151 win.isVisibleOrBehindKeyguardLw() && !win.isGoneForLayoutLw()) {
John Spurlockc6d1c602014-01-17 15:22:06 -05004152 if ((fl & FLAG_FORCE_NOT_FULLSCREEN) != 0) {
Jorim Jaggi380ecb82014-03-14 17:25:20 +01004153 if ((attrs.privateFlags & PRIVATE_FLAG_KEYGUARD) != 0) {
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07004154 mForceStatusBarFromKeyguard = true;
4155 } else {
4156 mForceStatusBar = true;
4157 }
4158 }
Jorim Jaggi380ecb82014-03-14 17:25:20 +01004159 if ((attrs.privateFlags & PRIVATE_FLAG_KEYGUARD) != 0) {
Dianne Hackborn7ad44382012-10-18 17:46:00 -07004160 mShowingLockscreen = true;
Dianne Hackbornbc1aa7b2011-09-20 11:20:31 -07004161 }
Dianne Hackborn7ad44382012-10-18 17:46:00 -07004162 if (attrs.type == TYPE_DREAM) {
Jeff Brownc8018eb2012-10-29 21:33:27 -07004163 // If the lockscreen was showing when the dream started then wait
4164 // for the dream to draw before hiding the lockscreen.
4165 if (!mDreamingLockscreen
4166 || (win.isVisibleLw() && win.hasDrawnLw())) {
4167 mShowingDream = true;
Craig Mautnerab55e522014-03-03 13:26:03 -08004168 appWindow = true;
Dianne Hackborn7ad44382012-10-18 17:46:00 -07004169 }
4170 }
Craig Mautnerab55e522014-03-03 13:26:03 -08004171
Craig Mautnerab55e522014-03-03 13:26:03 -08004172 if (appWindow) {
Jorim Jaggic13fcac2014-09-11 17:36:57 +02004173 final IApplicationToken appToken = win.getAppToken();
4174 if (showWhenLocked) {
Craig Mautnerc9457fa2014-06-06 14:27:48 -07004175 // Remove any previous windows with the same appToken.
Jorim Jaggic13fcac2014-09-11 17:36:57 +02004176 mAppsToBeHidden.remove(appToken);
4177 mAppsThatDismissKeyguard.remove(appToken);
Craig Mautnerca0a1242014-12-02 12:25:14 -08004178 if (mAppsToBeHidden.isEmpty()) {
Craig Mautner192d6042014-12-02 23:24:48 -08004179 if (dismissKeyguard && !mKeyguardSecure) {
4180 mAppsThatDismissKeyguard.add(appToken);
4181 } else {
Craig Mautnerca0a1242014-12-02 12:25:14 -08004182 mWinShowWhenLocked = win;
4183 mHideLockScreen = true;
4184 mForceStatusBarFromKeyguard = false;
Craig Mautnerca0a1242014-12-02 12:25:14 -08004185 }
Craig Mautnerc9457fa2014-06-06 14:27:48 -07004186 }
Jorim Jaggic13fcac2014-09-11 17:36:57 +02004187 } else if (dismissKeyguard) {
Jim Millerab954542014-10-10 18:21:49 -07004188 if (mKeyguardSecure) {
Jorim Jaggic13fcac2014-09-11 17:36:57 +02004189 mAppsToBeHidden.add(appToken);
4190 } else {
4191 mAppsToBeHidden.remove(appToken);
4192 }
4193 mAppsThatDismissKeyguard.add(appToken);
Craig Mautner2bc789b2014-03-19 19:48:38 -07004194 } else {
Jorim Jaggic13fcac2014-09-11 17:36:57 +02004195 mAppsToBeHidden.add(appToken);
Craig Mautner2bc789b2014-03-19 19:48:38 -07004196 }
Craig Mautnerab55e522014-03-03 13:26:03 -08004197 if (attrs.x == 0 && attrs.y == 0
4198 && attrs.width == WindowManager.LayoutParams.MATCH_PARENT
4199 && attrs.height == WindowManager.LayoutParams.MATCH_PARENT) {
4200 if (DEBUG_LAYOUT) Slog.v(TAG, "Fullscreen window: " + win);
4201 mTopFullscreenOpaqueWindowState = win;
Adrian Rooscd3884d2015-02-18 17:25:23 +01004202 if (mTopFullscreenOpaqueOrDimmingWindowState == null) {
4203 mTopFullscreenOpaqueOrDimmingWindowState = win;
4204 }
Jorim Jaggic13fcac2014-09-11 17:36:57 +02004205 if (!mAppsThatDismissKeyguard.isEmpty() &&
4206 mDismissKeyguard == DISMISS_KEYGUARD_NONE) {
4207 if (DEBUG_LAYOUT) Slog.v(TAG,
4208 "Setting mDismissKeyguard true by win " + win);
4209 mDismissKeyguard = mWinDismissingKeyguard == win ?
4210 DISMISS_KEYGUARD_CONTINUE : DISMISS_KEYGUARD_START;
4211 mWinDismissingKeyguard = win;
Jim Millerab954542014-10-10 18:21:49 -07004212 mForceStatusBarFromKeyguard = mShowingLockscreen && mKeyguardSecure;
Jorim Jaggic13fcac2014-09-11 17:36:57 +02004213 } else if (mAppsToBeHidden.isEmpty() && showWhenLocked) {
4214 if (DEBUG_LAYOUT) Slog.v(TAG,
4215 "Setting mHideLockScreen to true by win " + win);
4216 mHideLockScreen = true;
4217 mForceStatusBarFromKeyguard = false;
Craig Mautnerab55e522014-03-03 13:26:03 -08004218 }
Craig Mautner00156ec2014-03-06 22:29:02 -08004219 if ((fl & FLAG_ALLOW_LOCK_WHILE_SCREEN_ON) != 0) {
Craig Mautnerab55e522014-03-03 13:26:03 -08004220 mAllowLockscreenWhenOn = true;
4221 }
Dianne Hackborn5f3063e2010-03-10 16:01:58 -08004222 }
Craig Mautnerc9457fa2014-06-06 14:27:48 -07004223
4224 if (mWinShowWhenLocked != null &&
Adrian Roos602c68e2015-04-24 16:03:47 -07004225 mWinShowWhenLocked.getAppToken() != win.getAppToken() &&
4226 (attrs.flags & FLAG_SHOW_WHEN_LOCKED) == 0) {
Craig Mautnerc9457fa2014-06-06 14:27:48 -07004227 win.hideLw(false);
4228 }
Dianne Hackborn5f3063e2010-03-10 16:01:58 -08004229 }
Adrian Roos602c68e2015-04-24 16:03:47 -07004230 } else if (mTopFullscreenOpaqueWindowState == null && mWinShowWhenLocked == null) {
4231 // No TopFullscreenOpaqueWindow is showing, but we found a SHOW_WHEN_LOCKED window
4232 // that is being hidden in an animation - keep the
4233 // keyguard hidden until the new window shows up and
4234 // we know whether to show the keyguard or not.
4235 if (win.isAnimatingLw() && appWindow && showWhenLocked) {
4236 mHideLockScreen = true;
4237 mWinShowWhenLocked = win;
4238 }
Dianne Hackborn5f3063e2010-03-10 16:01:58 -08004239 }
Adrian Rooscd3884d2015-02-18 17:25:23 +01004240 if (mTopFullscreenOpaqueOrDimmingWindowState == null
4241 && win.isVisibleOrBehindKeyguardLw() && !win.isGoneForLayoutLw()
4242 && win.isDimming()) {
4243 mTopFullscreenOpaqueOrDimmingWindowState = win;
4244 }
Dianne Hackborn5f3063e2010-03-10 16:01:58 -08004245 }
4246
4247 /** {@inheritDoc} */
Craig Mautnerad09bcc2012-10-08 13:33:11 -07004248 @Override
Craig Mautner39834192012-09-02 07:47:24 -07004249 public int finishPostLayoutPolicyLw() {
Craig Mautnerc5e73bf2015-04-21 15:41:26 +00004250 if (mWinShowWhenLocked != null && mTopFullscreenOpaqueWindowState != null &&
4251 mWinShowWhenLocked.getAppToken() != mTopFullscreenOpaqueWindowState.getAppToken()
4252 && isKeyguardLocked()) {
Craig Mautnerc9457fa2014-06-06 14:27:48 -07004253 // A dialog is dismissing the keyguard. Put the wallpaper behind it and hide the
4254 // fullscreen window.
4255 // TODO: Make sure FLAG_SHOW_WALLPAPER is restored when dialog is dismissed. Or not.
4256 mWinShowWhenLocked.getAttrs().flags |= FLAG_SHOW_WALLPAPER;
4257 mTopFullscreenOpaqueWindowState.hideLw(false);
4258 mTopFullscreenOpaqueWindowState = mWinShowWhenLocked;
4259 }
4260
Dianne Hackborn39c2d712009-09-22 11:41:31 -07004261 int changes = 0;
Joe Onorato93056472010-09-10 10:30:46 -04004262 boolean topIsFullscreen = false;
Daniel Sandlere02d8082010-10-08 15:13:22 -04004263
4264 final WindowManager.LayoutParams lp = (mTopFullscreenOpaqueWindowState != null)
4265 ? mTopFullscreenOpaqueWindowState.getAttrs()
4266 : null;
4267
Jeff Brownc8018eb2012-10-29 21:33:27 -07004268 // If we are not currently showing a dream then remember the current
4269 // lockscreen state. We will use this to determine whether the dream
4270 // started while the lockscreen was showing and remember this state
4271 // while the dream is showing.
Dianne Hackborn7ad44382012-10-18 17:46:00 -07004272 if (!mShowingDream) {
4273 mDreamingLockscreen = mShowingLockscreen;
Jeff Brown061ea992015-04-17 19:55:47 -07004274 if (mDreamingSleepTokenNeeded) {
4275 mDreamingSleepTokenNeeded = false;
4276 mHandler.obtainMessage(MSG_UPDATE_DREAMING_SLEEP_TOKEN, 0, 1).sendToTarget();
4277 }
4278 } else {
4279 if (!mDreamingSleepTokenNeeded) {
4280 mDreamingSleepTokenNeeded = true;
4281 mHandler.obtainMessage(MSG_UPDATE_DREAMING_SLEEP_TOKEN, 1, 1).sendToTarget();
4282 }
Dianne Hackborn7ad44382012-10-18 17:46:00 -07004283 }
4284
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004285 if (mStatusBar != null) {
Craig Mautnereda67292013-04-28 13:50:14 -07004286 if (DEBUG_LAYOUT) Slog.i(TAG, "force=" + mForceStatusBar
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07004287 + " forcefkg=" + mForceStatusBarFromKeyguard
Dianne Hackbornd70bc2f2009-10-06 23:25:51 -07004288 + " top=" + mTopFullscreenOpaqueWindowState);
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07004289 if (mForceStatusBar || mForceStatusBarFromKeyguard) {
Craig Mautnereda67292013-04-28 13:50:14 -07004290 if (DEBUG_LAYOUT) Slog.v(TAG, "Showing status bar: forced");
John Spurlock27735a42013-08-14 17:57:38 -04004291 if (mStatusBarController.setBarShowingLw(true)) {
4292 changes |= FINISH_LAYOUT_REDO_LAYOUT;
4293 }
Craig Mautner81defc72013-10-29 11:10:42 -07004294 // Maintain fullscreen layout until incoming animation is complete.
4295 topIsFullscreen = mTopIsFullscreen && mStatusBar.isAnimatingLw();
John Spurlockf92b6162013-11-11 15:01:16 -05004296 // Transient status bar on the lockscreen is not allowed
4297 if (mForceStatusBarFromKeyguard && mStatusBarController.isTransientShowing()) {
4298 mStatusBarController.updateVisibilityLw(false /*transientAllowed*/,
4299 mLastSystemUiFlags, mLastSystemUiFlags);
4300 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004301 } else if (mTopFullscreenOpaqueWindowState != null) {
John Spurlockc6d1c602014-01-17 15:22:06 -05004302 final int fl = PolicyControl.getWindowFlags(null, lp);
Joe Onorato93056472010-09-10 10:30:46 -04004303 if (localLOGV) {
Craig Mautnereda67292013-04-28 13:50:14 -07004304 Slog.d(TAG, "frame: " + mTopFullscreenOpaqueWindowState.getFrameLw()
Joe Onorato93056472010-09-10 10:30:46 -04004305 + " shown frame: " + mTopFullscreenOpaqueWindowState.getShownFrameLw());
Craig Mautnereda67292013-04-28 13:50:14 -07004306 Slog.d(TAG, "attr: " + mTopFullscreenOpaqueWindowState.getAttrs()
John Spurlockc6d1c602014-01-17 15:22:06 -05004307 + " lp.flags=0x" + Integer.toHexString(fl));
Joe Onorato93056472010-09-10 10:30:46 -04004308 }
John Spurlockc6d1c602014-01-17 15:22:06 -05004309 topIsFullscreen = (fl & WindowManager.LayoutParams.FLAG_FULLSCREEN) != 0
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07004310 || (mLastSystemUiFlags & View.SYSTEM_UI_FLAG_FULLSCREEN) != 0;
Joe Onorato93056472010-09-10 10:30:46 -04004311 // The subtle difference between the window for mTopFullscreenOpaqueWindowState
Mark Dolinerd0646dc2014-08-27 16:04:02 -07004312 // and mTopIsFullscreen is that mTopIsFullscreen is set only if the window
Joe Onorato93056472010-09-10 10:30:46 -04004313 // has the FLAG_FULLSCREEN set. Not sure if there is another way that to be the
4314 // case though.
John Spurlock27735a42013-08-14 17:57:38 -04004315 if (mStatusBarController.isTransientShowing()) {
4316 if (mStatusBarController.setBarShowingLw(true)) {
John Spurlock32beb2c2013-03-11 10:16:47 -04004317 changes |= FINISH_LAYOUT_REDO_LAYOUT;
4318 }
4319 } else if (topIsFullscreen) {
Craig Mautnereda67292013-04-28 13:50:14 -07004320 if (DEBUG_LAYOUT) Slog.v(TAG, "** HIDING status bar");
John Spurlock27735a42013-08-14 17:57:38 -04004321 if (mStatusBarController.setBarShowingLw(false)) {
Dianne Hackbornf87d1962012-04-04 12:48:24 -07004322 changes |= FINISH_LAYOUT_REDO_LAYOUT;
Craig Mautnereda67292013-04-28 13:50:14 -07004323 } else {
Craig Mautnerc5a6e442013-06-05 17:22:35 -07004324 if (DEBUG_LAYOUT) Slog.v(TAG, "Status bar already hiding");
Daniel Sandler40427442010-07-16 11:44:52 -04004325 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004326 } else {
Craig Mautnereda67292013-04-28 13:50:14 -07004327 if (DEBUG_LAYOUT) Slog.v(TAG, "** SHOWING status bar: top is not fullscreen");
John Spurlock27735a42013-08-14 17:57:38 -04004328 if (mStatusBarController.setBarShowingLw(true)) {
4329 changes |= FINISH_LAYOUT_REDO_LAYOUT;
4330 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004331 }
4332 }
4333 }
Daniel Sandlere02d8082010-10-08 15:13:22 -04004334
Craig Mautner81defc72013-10-29 11:10:42 -07004335 if (mTopIsFullscreen != topIsFullscreen) {
4336 if (!topIsFullscreen) {
4337 // Force another layout when status bar becomes fully shown.
4338 changes |= FINISH_LAYOUT_REDO_LAYOUT;
4339 }
4340 mTopIsFullscreen = topIsFullscreen;
4341 }
Daniel Sandlere02d8082010-10-08 15:13:22 -04004342
Craig Mautner39834192012-09-02 07:47:24 -07004343 // Hide the key guard if a visible window explicitly specifies that it wants to be
4344 // displayed when the screen is locked.
Jorim Jaggi5cf17872014-03-26 18:31:48 +01004345 if (mKeyguardDelegate != null && mStatusBar != null) {
4346 if (localLOGV) Slog.v(TAG, "finishPostLayoutPolicyLw: mHideKeyguard="
4347 + mHideLockScreen);
Jim Millerab954542014-10-10 18:21:49 -07004348 if (mDismissKeyguard != DISMISS_KEYGUARD_NONE && !mKeyguardSecure) {
Jorim Jaggi5cf17872014-03-26 18:31:48 +01004349 mKeyguardHidden = true;
Jim Millerab954542014-10-10 18:21:49 -07004350 if (setKeyguardOccludedLw(true)) {
Dianne Hackborn39c2d712009-09-22 11:41:31 -07004351 changes |= FINISH_LAYOUT_REDO_LAYOUT
4352 | FINISH_LAYOUT_REDO_CONFIG
4353 | FINISH_LAYOUT_REDO_WALLPAPER;
4354 }
Jorim Jaggi5cf17872014-03-26 18:31:48 +01004355 if (mKeyguardDelegate.isShowing()) {
4356 mHandler.post(new Runnable() {
4357 @Override
4358 public void run() {
4359 mKeyguardDelegate.keyguardDone(false, false);
4360 }
4361 });
4362 }
4363 } else if (mHideLockScreen) {
4364 mKeyguardHidden = true;
Jim Millerab954542014-10-10 18:21:49 -07004365 if (setKeyguardOccludedLw(true)) {
Jorim Jaggi5cf17872014-03-26 18:31:48 +01004366 changes |= FINISH_LAYOUT_REDO_LAYOUT
4367 | FINISH_LAYOUT_REDO_CONFIG
4368 | FINISH_LAYOUT_REDO_WALLPAPER;
4369 }
4370 } else if (mDismissKeyguard != DISMISS_KEYGUARD_NONE) {
4371 // This is the case of keyguard isSecure() and not mHideLockScreen.
4372 if (mDismissKeyguard == DISMISS_KEYGUARD_START) {
4373 // Only launch the next keyguard unlock window once per window.
4374 mKeyguardHidden = false;
Jim Millerab954542014-10-10 18:21:49 -07004375 if (setKeyguardOccludedLw(false)) {
Jorim Jaggi5cf17872014-03-26 18:31:48 +01004376 changes |= FINISH_LAYOUT_REDO_LAYOUT
4377 | FINISH_LAYOUT_REDO_CONFIG
4378 | FINISH_LAYOUT_REDO_WALLPAPER;
Jorim Jaggi380ecb82014-03-14 17:25:20 +01004379 }
Jorim Jaggi5cf17872014-03-26 18:31:48 +01004380 mHandler.post(new Runnable() {
4381 @Override
4382 public void run() {
4383 mKeyguardDelegate.dismiss();
4384 }
4385 });
4386 }
4387 } else {
4388 mWinDismissingKeyguard = null;
4389 mKeyguardHidden = false;
Jim Millerab954542014-10-10 18:21:49 -07004390 if (setKeyguardOccludedLw(false)) {
Jorim Jaggi5cf17872014-03-26 18:31:48 +01004391 changes |= FINISH_LAYOUT_REDO_LAYOUT
4392 | FINISH_LAYOUT_REDO_CONFIG
4393 | FINISH_LAYOUT_REDO_WALLPAPER;
4394 }
Suchi Amalapurapu9cdc9032009-05-14 18:01:07 -07004395 }
4396 }
Joe Onorato664644d2011-01-23 17:53:23 -08004397
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07004398 if ((updateSystemUiVisibilityLw()&SYSTEM_UI_CHANGING_LAYOUT) != 0) {
Dianne Hackborndf89e652011-10-06 22:35:11 -07004399 // If the navigation bar has been hidden or shown, we need to do another
4400 // layout pass to update that window.
4401 changes |= FINISH_LAYOUT_REDO_LAYOUT;
4402 }
Joe Onorato664644d2011-01-23 17:53:23 -08004403
Mike Lockwood28569302010-01-28 11:54:40 -05004404 // update since mAllowLockscreenWhenOn might have changed
4405 updateLockScreenTimeout();
Dianne Hackborn39c2d712009-09-22 11:41:31 -07004406 return changes;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004407 }
4408
Jorim Jaggi380ecb82014-03-14 17:25:20 +01004409 /**
Jim Millerab954542014-10-10 18:21:49 -07004410 * Updates the occluded state of the Keyguard.
Jorim Jaggi380ecb82014-03-14 17:25:20 +01004411 *
Jorim Jaggi380ecb82014-03-14 17:25:20 +01004412 * @return Whether the flags have changed and we have to redo the layout.
4413 */
Jim Millerab954542014-10-10 18:21:49 -07004414 private boolean setKeyguardOccludedLw(boolean isOccluded) {
4415 boolean wasOccluded = mKeyguardOccluded;
4416 boolean showing = mKeyguardDelegate.isShowing();
4417 if (wasOccluded && !isOccluded && showing) {
4418 mKeyguardOccluded = false;
4419 mKeyguardDelegate.setOccluded(false);
Jorim Jaggi380ecb82014-03-14 17:25:20 +01004420 mStatusBar.getAttrs().privateFlags |= PRIVATE_FLAG_KEYGUARD;
4421 mStatusBar.getAttrs().flags |= FLAG_SHOW_WALLPAPER;
4422 return true;
Jim Millerab954542014-10-10 18:21:49 -07004423 } else if (!wasOccluded && isOccluded && showing) {
4424 mKeyguardOccluded = true;
4425 mKeyguardDelegate.setOccluded(true);
Jorim Jaggi380ecb82014-03-14 17:25:20 +01004426 mStatusBar.getAttrs().privateFlags &= ~PRIVATE_FLAG_KEYGUARD;
4427 mStatusBar.getAttrs().flags &= ~FLAG_SHOW_WALLPAPER;
4428 return true;
4429 } else {
4430 return false;
4431 }
4432 }
4433
4434 private boolean isStatusBarKeyguard() {
4435 return mStatusBar != null
4436 && (mStatusBar.getAttrs().privateFlags & PRIVATE_FLAG_KEYGUARD) != 0;
4437 }
4438
Jose Lima9546b202014-07-02 17:21:51 -07004439 @Override
Dianne Hackborn08743722009-12-21 12:16:51 -08004440 public boolean allowAppAnimationsLw() {
Jorim Jaggi380ecb82014-03-14 17:25:20 +01004441 if (isStatusBarKeyguard() || mShowingDream) {
Craig Mautner28816302013-10-10 20:31:00 -07004442 // If keyguard or dreams is currently visible, no reason to animate behind it.
Dianne Hackborn08743722009-12-21 12:16:51 -08004443 return false;
4444 }
Dianne Hackborn08743722009-12-21 12:16:51 -08004445 return true;
4446 }
4447
Jose Lima9546b202014-07-02 17:21:51 -07004448 @Override
Dianne Hackborndf89e652011-10-06 22:35:11 -07004449 public int focusChangedLw(WindowState lastFocus, WindowState newFocus) {
Joe Onorato664644d2011-01-23 17:53:23 -08004450 mFocusedWindow = newFocus;
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07004451 if ((updateSystemUiVisibilityLw()&SYSTEM_UI_CHANGING_LAYOUT) != 0) {
Dianne Hackborndf89e652011-10-06 22:35:11 -07004452 // If the navigation bar has been hidden or shown, we need to do another
4453 // layout pass to update that window.
4454 return FINISH_LAYOUT_REDO_LAYOUT;
4455 }
4456 return 0;
Joe Onorato664644d2011-01-23 17:53:23 -08004457 }
4458
Dianne Hackborn0ecadf72009-03-31 18:00:37 -07004459 /** {@inheritDoc} */
Jose Lima9546b202014-07-02 17:21:51 -07004460 @Override
Jeff Brown46b9ac02010-04-22 18:58:52 -07004461 public void notifyLidSwitchChanged(long whenNanos, boolean lidOpen) {
4462 // lid changed state
Jeff Brownc458ce92012-04-30 14:58:40 -07004463 final int newLidState = lidOpen ? LID_OPEN : LID_CLOSED;
4464 if (newLidState == mLidState) {
4465 return;
4466 }
Jeff Brown01a98dd2011-09-20 15:08:29 -07004467
Jeff Brownc458ce92012-04-30 14:58:40 -07004468 mLidState = newLidState;
4469 applyLidSwitchState();
Jeff Brown01a98dd2011-09-20 15:08:29 -07004470 updateRotation(true);
Jeff Brownc458ce92012-04-30 14:58:40 -07004471
4472 if (lidOpen) {
Bryce Lee584a4452014-10-21 15:55:55 -07004473 wakeUp(SystemClock.uptimeMillis(), mAllowTheaterModeWakeFromLidSwitch);
Jeff Brownc458ce92012-04-30 14:58:40 -07004474 } else if (!mLidControlsSleep) {
Jeff Brown96307042012-07-27 15:51:34 -07004475 mPowerManager.userActivity(SystemClock.uptimeMillis(), false);
Jeff Brown46b9ac02010-04-22 18:58:52 -07004476 }
4477 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004478
Michael Wright3818c922014-09-02 13:59:07 -07004479 @Override
4480 public void notifyCameraLensCoverSwitchChanged(long whenNanos, boolean lensCovered) {
4481 int lensCoverState = lensCovered ? CAMERA_LENS_COVERED : CAMERA_LENS_UNCOVERED;
4482 if (mCameraLensCoverState == lensCoverState) {
4483 return;
4484 }
4485 if (mCameraLensCoverState == CAMERA_LENS_COVERED &&
4486 lensCoverState == CAMERA_LENS_UNCOVERED) {
4487 Intent intent;
4488 final boolean keyguardActive = mKeyguardDelegate == null ? false :
4489 mKeyguardDelegate.isShowing();
4490 if (keyguardActive) {
4491 intent = new Intent(MediaStore.INTENT_ACTION_STILL_IMAGE_CAMERA_SECURE);
4492 } else {
4493 intent = new Intent(MediaStore.INTENT_ACTION_STILL_IMAGE_CAMERA);
4494 }
Bryce Lee584a4452014-10-21 15:55:55 -07004495 wakeUp(whenNanos / 1000000, mAllowTheaterModeWakeFromCameraLens);
Bart Sears8b1c27c2015-03-18 23:51:02 +00004496 startActivityAsUser(intent, UserHandle.CURRENT_OR_SELF);
Michael Wright3818c922014-09-02 13:59:07 -07004497 }
4498 mCameraLensCoverState = lensCoverState;
4499 }
4500
Dianne Hackbornad7fa7f2011-01-07 14:06:50 -08004501 void setHdmiPlugged(boolean plugged) {
4502 if (mHdmiPlugged != plugged) {
4503 mHdmiPlugged = plugged;
Dianne Hackbornf87d1962012-04-04 12:48:24 -07004504 updateRotation(true, true);
Dianne Hackbornad7fa7f2011-01-07 14:06:50 -08004505 Intent intent = new Intent(ACTION_HDMI_PLUGGED);
Joe Onoratodc100302011-01-11 17:07:41 -08004506 intent.addFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY_BEFORE_BOOT);
Dianne Hackbornad7fa7f2011-01-07 14:06:50 -08004507 intent.putExtra(EXTRA_HDMI_PLUGGED_STATE, plugged);
Dianne Hackborn5ac72a22012-08-29 18:32:08 -07004508 mContext.sendStickyBroadcastAsUser(intent, UserHandle.ALL);
Dianne Hackbornad7fa7f2011-01-07 14:06:50 -08004509 }
4510 }
4511
Joe Onoratoea495d42011-04-06 11:41:11 -07004512 void initializeHdmiState() {
Joe Onorato7ba631f2011-05-04 15:28:00 -07004513 boolean plugged = false;
Joe Onoratoea495d42011-04-06 11:41:11 -07004514 // watch for HDMI plug messages if the hdmi switch exists
4515 if (new File("/sys/devices/virtual/switch/hdmi/state").exists()) {
4516 mHDMIObserver.startObserving("DEVPATH=/devices/virtual/switch/hdmi");
4517
Joe Onoratoea495d42011-04-06 11:41:11 -07004518 final String filename = "/sys/class/switch/hdmi/state";
4519 FileReader reader = null;
4520 try {
4521 reader = new FileReader(filename);
4522 char[] buf = new char[15];
4523 int n = reader.read(buf);
4524 if (n > 1) {
4525 plugged = 0 != Integer.parseInt(new String(buf, 0, n-1));
4526 }
4527 } catch (IOException ex) {
4528 Slog.w(TAG, "Couldn't read hdmi state from " + filename + ": " + ex);
4529 } catch (NumberFormatException ex) {
4530 Slog.w(TAG, "Couldn't read hdmi state from " + filename + ": " + ex);
4531 } finally {
4532 if (reader != null) {
4533 try {
4534 reader.close();
4535 } catch (IOException ex) {
4536 }
Joe Onoratodc100302011-01-11 17:07:41 -08004537 }
4538 }
4539 }
Joe Onorato7ba631f2011-05-04 15:28:00 -07004540 // This dance forces the code in setHdmiPlugged to run.
4541 // Always do this so the sticky intent is stuck (to false) if there is no hdmi.
4542 mHdmiPlugged = !plugged;
4543 setHdmiPlugged(!mHdmiPlugged);
Joe Onoratodc100302011-01-11 17:07:41 -08004544 }
4545
Dianne Hackbornc0e3f242011-08-19 14:19:10 -07004546 final Object mScreenshotLock = new Object();
Dianne Hackbornfc8fa632011-08-17 16:20:47 -07004547 ServiceConnection mScreenshotConnection = null;
Dianne Hackbornfc8fa632011-08-17 16:20:47 -07004548
Jeff Brownd5bb82d2011-10-12 13:57:59 -07004549 final Runnable mScreenshotTimeout = new Runnable() {
4550 @Override public void run() {
4551 synchronized (mScreenshotLock) {
4552 if (mScreenshotConnection != null) {
4553 mContext.unbindService(mScreenshotConnection);
4554 mScreenshotConnection = null;
Dianne Hackbornfc8fa632011-08-17 16:20:47 -07004555 }
Winson Chung9112ec32011-06-27 13:15:32 -07004556 }
Jeff Brownd5bb82d2011-10-12 13:57:59 -07004557 }
4558 };
4559
4560 // Assume this is called from the Handler thread.
4561 private void takeScreenshot() {
4562 synchronized (mScreenshotLock) {
4563 if (mScreenshotConnection != null) {
4564 return;
4565 }
4566 ComponentName cn = new ComponentName("com.android.systemui",
4567 "com.android.systemui.screenshot.TakeScreenshotService");
4568 Intent intent = new Intent();
4569 intent.setComponent(cn);
4570 ServiceConnection conn = new ServiceConnection() {
4571 @Override
4572 public void onServiceConnected(ComponentName name, IBinder service) {
4573 synchronized (mScreenshotLock) {
4574 if (mScreenshotConnection != this) {
4575 return;
4576 }
4577 Messenger messenger = new Messenger(service);
4578 Message msg = Message.obtain(null, 1);
4579 final ServiceConnection myConn = this;
4580 Handler h = new Handler(mHandler.getLooper()) {
4581 @Override
4582 public void handleMessage(Message msg) {
4583 synchronized (mScreenshotLock) {
4584 if (mScreenshotConnection == myConn) {
4585 mContext.unbindService(mScreenshotConnection);
4586 mScreenshotConnection = null;
4587 mHandler.removeCallbacks(mScreenshotTimeout);
4588 }
4589 }
4590 }
4591 };
4592 msg.replyTo = new Messenger(h);
Winson Chunga63bb842011-10-17 10:26:28 -07004593 msg.arg1 = msg.arg2 = 0;
4594 if (mStatusBar != null && mStatusBar.isVisibleLw())
4595 msg.arg1 = 1;
4596 if (mNavigationBar != null && mNavigationBar.isVisibleLw())
4597 msg.arg2 = 1;
Jeff Brownd5bb82d2011-10-12 13:57:59 -07004598 try {
4599 messenger.send(msg);
4600 } catch (RemoteException e) {
4601 }
4602 }
4603 }
4604 @Override
4605 public void onServiceDisconnected(ComponentName name) {}
4606 };
Amith Yamasani27b89e62013-01-16 12:30:11 -08004607 if (mContext.bindServiceAsUser(
4608 intent, conn, Context.BIND_AUTO_CREATE, UserHandle.CURRENT)) {
Jeff Brownd5bb82d2011-10-12 13:57:59 -07004609 mScreenshotConnection = conn;
4610 mHandler.postDelayed(mScreenshotTimeout, 10000);
4611 }
4612 }
Winson Chung9112ec32011-06-27 13:15:32 -07004613 }
4614
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004615 /** {@inheritDoc} */
Jeff Brown00fa7bd2010-07-02 15:37:36 -07004616 @Override
Jeff Brown037c33e2014-04-09 00:31:55 -07004617 public int interceptKeyBeforeQueueing(KeyEvent event, int policyFlags) {
Jeff Brown96307042012-07-27 15:51:34 -07004618 if (!mSystemBooted) {
4619 // If we have not yet booted, don't let key events do anything.
4620 return 0;
4621 }
4622
Jeff Brown037c33e2014-04-09 00:31:55 -07004623 final boolean interactive = (policyFlags & FLAG_INTERACTIVE) != 0;
Jeff Brown1f245102010-11-18 20:53:46 -08004624 final boolean down = event.getAction() == KeyEvent.ACTION_DOWN;
4625 final boolean canceled = event.isCanceled();
4626 final int keyCode = event.getKeyCode();
Jeff Browne20c9e02010-10-11 14:20:19 -07004627
Jeff Brown3122e442010-10-11 23:32:49 -07004628 final boolean isInjected = (policyFlags & WindowManagerPolicy.FLAG_INJECTED) != 0;
Jeff Brown3122e442010-10-11 23:32:49 -07004629
Mike Lockwoodc72b15f2009-11-28 20:58:22 -05004630 // If screen is off then we treat the case where the keyguard is open but hidden
4631 // the same as if it were open and in front.
4632 // This will prevent any keys other than the power button from waking the screen
4633 // when the keyguard is hidden by another activity.
Jim Miller5ecd8112013-01-09 18:50:26 -08004634 final boolean keyguardActive = (mKeyguardDelegate == null ? false :
Jeff Brown037c33e2014-04-09 00:31:55 -07004635 (interactive ?
Jim Millerab954542014-10-10 18:21:49 -07004636 isKeyguardShowingAndNotOccluded() :
Jim Miller5ecd8112013-01-09 18:50:26 -08004637 mKeyguardDelegate.isShowing()));
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004638
Jeff Brown40013652012-05-16 21:22:36 -07004639 if (DEBUG_INPUT) {
Jeff Brown00fa7bd2010-07-02 15:37:36 -07004640 Log.d(TAG, "interceptKeyTq keycode=" + keyCode
Jeff Brown037c33e2014-04-09 00:31:55 -07004641 + " interactive=" + interactive + " keyguardActive=" + keyguardActive
Jeff Brown26875502014-01-30 21:47:47 -08004642 + " policyFlags=" + Integer.toHexString(policyFlags));
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004643 }
4644
Jeff Brown037c33e2014-04-09 00:31:55 -07004645 // Basic policy based on interactive state.
Jeff Brown4d396052010-10-29 21:50:21 -07004646 int result;
Michael Wright337d9d22014-04-22 15:03:48 -07004647 boolean isWakeKey = (policyFlags & WindowManagerPolicy.FLAG_WAKE) != 0
4648 || event.isWakeKey();
Michael Wrightfc01f042014-09-08 14:12:24 -07004649 if (interactive || (isInjected && !isWakeKey)) {
RoboErikde9ba392014-09-26 12:51:01 -07004650 // When the device is interactive or the key is injected pass the
4651 // key to the application.
Jeff Brown4d396052010-10-29 21:50:21 -07004652 result = ACTION_PASS_TO_USER;
Jose Lima9546b202014-07-02 17:21:51 -07004653 isWakeKey = false;
Michael Wrightfc01f042014-09-08 14:12:24 -07004654 } else if (!interactive && shouldDispatchInputWhenNonInteractive()) {
4655 // If we're currently dozing with the screen on and the keyguard showing, pass the key
4656 // to the application but preserve its wake key status to make sure we still move
4657 // from dozing to fully interactive if we would normally go from off to fully
4658 // interactive.
4659 result = ACTION_PASS_TO_USER;
Jeff Brown4d396052010-10-29 21:50:21 -07004660 } else {
4661 // When the screen is off and the key is not injected, determine whether
4662 // to wake the device but don't pass the key to the application.
4663 result = 0;
Jeff Brown26875502014-01-30 21:47:47 -08004664 if (isWakeKey && (!down || !isWakeKeyWhenScreenOff(keyCode))) {
4665 isWakeKey = false;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004666 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004667 }
4668
Justin Kohd378ad72013-04-01 12:18:26 -07004669 // If the key would be handled globally, just return the result, don't worry about special
4670 // key processing.
Jeff Brown13f00f02014-10-31 14:45:50 -07004671 if (isValidGlobalKey(keyCode)
4672 && mGlobalKeyManager.shouldHandleGlobalKey(keyCode, event)) {
Michael Wright85b1af62014-06-04 14:51:58 -07004673 if (isWakeKey) {
Jeff Brown13f00f02014-10-31 14:45:50 -07004674 wakeUp(event.getEventTime(), mAllowTheaterModeWakeFromKey);
Michael Wright85b1af62014-06-04 14:51:58 -07004675 }
Justin Kohd378ad72013-04-01 12:18:26 -07004676 return result;
4677 }
4678
Jeff Brownbae8e772014-06-12 19:59:45 -07004679 boolean useHapticFeedback = down
4680 && (policyFlags & WindowManagerPolicy.FLAG_VIRTUAL) != 0
4681 && event.getRepeatCount() == 0;
4682
Jeff Brown4d396052010-10-29 21:50:21 -07004683 // Handle special keys.
4684 switch (keyCode) {
4685 case KeyEvent.KEYCODE_VOLUME_DOWN:
Jeff Brownb0418da2010-11-01 15:24:01 -07004686 case KeyEvent.KEYCODE_VOLUME_UP:
4687 case KeyEvent.KEYCODE_VOLUME_MUTE: {
RoboErik001c59c2015-01-26 15:53:51 -08004688 if (mUseTvRouting) {
4689 // On TVs volume keys never go to the foreground app
4690 result &= ~ACTION_PASS_TO_USER;
4691 }
Jeff Brownd5bb82d2011-10-12 13:57:59 -07004692 if (keyCode == KeyEvent.KEYCODE_VOLUME_DOWN) {
4693 if (down) {
Jeff Brown13f00f02014-10-31 14:45:50 -07004694 if (interactive && !mScreenshotChordVolumeDownKeyTriggered
Jeff Brownd5bb82d2011-10-12 13:57:59 -07004695 && (event.getFlags() & KeyEvent.FLAG_FALLBACK) == 0) {
Jeff Brown13f00f02014-10-31 14:45:50 -07004696 mScreenshotChordVolumeDownKeyTriggered = true;
4697 mScreenshotChordVolumeDownKeyTime = event.getDownTime();
4698 mScreenshotChordVolumeDownKeyConsumed = false;
Jeff Brownd5bb82d2011-10-12 13:57:59 -07004699 cancelPendingPowerKeyAction();
4700 interceptScreenshotChord();
4701 }
4702 } else {
Jeff Brown13f00f02014-10-31 14:45:50 -07004703 mScreenshotChordVolumeDownKeyTriggered = false;
Jeff Brownd5bb82d2011-10-12 13:57:59 -07004704 cancelPendingScreenshotChordAction();
4705 }
4706 } else if (keyCode == KeyEvent.KEYCODE_VOLUME_UP) {
4707 if (down) {
Jeff Brown13f00f02014-10-31 14:45:50 -07004708 if (interactive && !mScreenshotChordVolumeUpKeyTriggered
Jeff Brownd5bb82d2011-10-12 13:57:59 -07004709 && (event.getFlags() & KeyEvent.FLAG_FALLBACK) == 0) {
Jeff Brown13f00f02014-10-31 14:45:50 -07004710 mScreenshotChordVolumeUpKeyTriggered = true;
Jeff Brownd5bb82d2011-10-12 13:57:59 -07004711 cancelPendingPowerKeyAction();
4712 cancelPendingScreenshotChordAction();
4713 }
4714 } else {
Jeff Brown13f00f02014-10-31 14:45:50 -07004715 mScreenshotChordVolumeUpKeyTriggered = false;
Jeff Brownd5bb82d2011-10-12 13:57:59 -07004716 cancelPendingScreenshotChordAction();
4717 }
4718 }
Jeff Brown4d396052010-10-29 21:50:21 -07004719 if (down) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -07004720 TelecomManager telecomManager = getTelecommService();
4721 if (telecomManager != null) {
4722 if (telecomManager.isRinging()) {
Santos Cordon6848f722014-05-21 15:22:12 -07004723 // If an incoming call is ringing, either VOLUME key means
4724 // "silence ringer". We handle these keys here, rather than
4725 // in the InCallScreen, to make sure we'll respond to them
4726 // even if the InCallScreen hasn't come to the foreground yet.
4727 // Look for the DOWN event here, to agree with the "fallback"
4728 // behavior in the InCallScreen.
4729 Log.i(TAG, "interceptKeyBeforeQueueing:"
4730 + " VOLUME key-down while ringing: Silence ringer!");
Jeff Brown4d396052010-10-29 21:50:21 -07004731
Santos Cordon6848f722014-05-21 15:22:12 -07004732 // Silence the ringer. (It's safe to call this
4733 // even if the ringer has already been silenced.)
Tyler Gunnef9f6f92014-09-12 22:16:17 -07004734 telecomManager.silenceRinger();
Jeff Brown4d396052010-10-29 21:50:21 -07004735
Santos Cordon6848f722014-05-21 15:22:12 -07004736 // And *don't* pass this key thru to the current activity
4737 // (which is probably the InCallScreen.)
4738 result &= ~ACTION_PASS_TO_USER;
4739 break;
4740 }
Tyler Gunnef9f6f92014-09-12 22:16:17 -07004741 if (telecomManager.isInCall()
Santos Cordon6848f722014-05-21 15:22:12 -07004742 && (result & ACTION_PASS_TO_USER) == 0) {
4743 // If we are in call but we decided not to pass the key to
RoboErik430fc482014-06-12 15:49:20 -07004744 // the application, just pass it to the session service.
4745
4746 MediaSessionLegacyHelper.getHelper(mContext)
RoboErik3c45c292014-07-08 16:47:31 -07004747 .sendVolumeKeyEvent(event, false);
Santos Cordon6848f722014-05-21 15:22:12 -07004748 break;
Jeff Brown4d396052010-10-29 21:50:21 -07004749 }
4750 }
4751
RoboErik430fc482014-06-12 15:49:20 -07004752 if ((result & ACTION_PASS_TO_USER) == 0) {
RoboErik001c59c2015-01-26 15:53:51 -08004753 if (mUseTvRouting) {
4754 dispatchDirectAudioEvent(event);
4755 } else {
4756 // If we aren't passing to the user and no one else
4757 // handled it send it to the session manager to
4758 // figure out.
4759 MediaSessionLegacyHelper.getHelper(mContext)
4760 .sendVolumeKeyEvent(event, true);
4761 }
Jeff Brown4d396052010-10-29 21:50:21 -07004762 break;
4763 }
4764 }
4765 break;
4766 }
4767
4768 case KeyEvent.KEYCODE_ENDCALL: {
4769 result &= ~ACTION_PASS_TO_USER;
4770 if (down) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -07004771 TelecomManager telecomManager = getTelecommService();
Jeff Brown4d396052010-10-29 21:50:21 -07004772 boolean hungUp = false;
Tyler Gunnef9f6f92014-09-12 22:16:17 -07004773 if (telecomManager != null) {
4774 hungUp = telecomManager.endCall();
Jeff Brown4d396052010-10-29 21:50:21 -07004775 }
Jeff Brown13f00f02014-10-31 14:45:50 -07004776 if (interactive && !hungUp) {
4777 mEndCallKeyHandled = false;
4778 mHandler.postDelayed(mEndCallLongPress,
4779 ViewConfiguration.get(mContext).getDeviceGlobalActionKeyTimeout());
4780 } else {
4781 mEndCallKeyHandled = true;
4782 }
Jeff Brown4d396052010-10-29 21:50:21 -07004783 } else {
Jeff Brown13f00f02014-10-31 14:45:50 -07004784 if (!mEndCallKeyHandled) {
4785 mHandler.removeCallbacks(mEndCallLongPress);
4786 if (!canceled) {
4787 if ((mEndcallBehavior
4788 & Settings.System.END_BUTTON_BEHAVIOR_HOME) != 0) {
4789 if (goHome()) {
4790 break;
4791 }
Dianne Hackborn0041e972009-07-24 17:14:43 -07004792 }
Jeff Brown13f00f02014-10-31 14:45:50 -07004793 if ((mEndcallBehavior
4794 & Settings.System.END_BUTTON_BEHAVIOR_SLEEP) != 0) {
4795 mPowerManager.goToSleep(event.getEventTime(),
4796 PowerManager.GO_TO_SLEEP_REASON_POWER_BUTTON, 0);
4797 isWakeKey = false;
4798 }
Jeff Brown4d396052010-10-29 21:50:21 -07004799 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004800 }
Jeff Brown4d396052010-10-29 21:50:21 -07004801 }
4802 break;
4803 }
4804
4805 case KeyEvent.KEYCODE_POWER: {
4806 result &= ~ACTION_PASS_TO_USER;
Jeff Brown13f00f02014-10-31 14:45:50 -07004807 isWakeKey = false; // wake-up will be handled separately
Jeff Brown4d396052010-10-29 21:50:21 -07004808 if (down) {
Jeff Brown13f00f02014-10-31 14:45:50 -07004809 interceptPowerKeyDown(event, interactive);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004810 } else {
Jeff Brown13f00f02014-10-31 14:45:50 -07004811 interceptPowerKeyUp(event, interactive, canceled);
Jeff Brown4d396052010-10-29 21:50:21 -07004812 }
4813 break;
4814 }
4815
Jeff Brown6212a492014-03-07 13:58:47 -08004816 case KeyEvent.KEYCODE_SLEEP: {
4817 result &= ~ACTION_PASS_TO_USER;
Filip Gruszczynskia483a1d2015-03-17 19:06:58 +00004818 isWakeKey = false;
Jeff Brownbae8e772014-06-12 19:59:45 -07004819 if (!mPowerManager.isInteractive()) {
4820 useHapticFeedback = false; // suppress feedback if already non-interactive
4821 }
Filip Gruszczynskia483a1d2015-03-17 19:06:58 +00004822 sleepPress(event);
Jeff Brown6212a492014-03-07 13:58:47 -08004823 break;
4824 }
4825
4826 case KeyEvent.KEYCODE_WAKEUP: {
4827 result &= ~ACTION_PASS_TO_USER;
Jose Lima9546b202014-07-02 17:21:51 -07004828 isWakeKey = true;
Jeff Brown6212a492014-03-07 13:58:47 -08004829 break;
4830 }
4831
Jeff Brown4d396052010-10-29 21:50:21 -07004832 case KeyEvent.KEYCODE_MEDIA_PLAY:
4833 case KeyEvent.KEYCODE_MEDIA_PAUSE:
4834 case KeyEvent.KEYCODE_MEDIA_PLAY_PAUSE:
Jeff Brown4d396052010-10-29 21:50:21 -07004835 case KeyEvent.KEYCODE_HEADSETHOOK:
4836 case KeyEvent.KEYCODE_MUTE:
4837 case KeyEvent.KEYCODE_MEDIA_STOP:
4838 case KeyEvent.KEYCODE_MEDIA_NEXT:
4839 case KeyEvent.KEYCODE_MEDIA_PREVIOUS:
4840 case KeyEvent.KEYCODE_MEDIA_REWIND:
4841 case KeyEvent.KEYCODE_MEDIA_RECORD:
Jaekyun Seokbfdad8e2013-07-08 13:53:21 +09004842 case KeyEvent.KEYCODE_MEDIA_FAST_FORWARD:
4843 case KeyEvent.KEYCODE_MEDIA_AUDIO_TRACK: {
RoboErikde9ba392014-09-26 12:51:01 -07004844 if (MediaSessionLegacyHelper.getHelper(mContext).isGlobalPriorityActive()) {
4845 // If the global session is active pass all media keys to it
4846 // instead of the active window.
4847 result &= ~ACTION_PASS_TO_USER;
4848 }
Jeff Brown4d396052010-10-29 21:50:21 -07004849 if ((result & ACTION_PASS_TO_USER) == 0) {
4850 // Only do this if we would otherwise not pass it to the user. In that
4851 // case, the PhoneWindow class will do the same thing, except it will
4852 // only do it if the showing app doesn't process the key on its own.
Jeff Brown40013652012-05-16 21:22:36 -07004853 // Note that we need to make a copy of the key event here because the
4854 // original key event will be recycled when we return.
Jeff Brown4d396052010-10-29 21:50:21 -07004855 mBroadcastWakeLock.acquire();
Jeff Brown40013652012-05-16 21:22:36 -07004856 Message msg = mHandler.obtainMessage(MSG_DISPATCH_MEDIA_KEY_WITH_WAKE_LOCK,
4857 new KeyEvent(event));
4858 msg.setAsynchronous(true);
4859 msg.sendToTarget();
Jeff Brown4d396052010-10-29 21:50:21 -07004860 }
4861 break;
Jeff Brown00fa7bd2010-07-02 15:37:36 -07004862 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004863
Jeff Brown4d396052010-10-29 21:50:21 -07004864 case KeyEvent.KEYCODE_CALL: {
4865 if (down) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -07004866 TelecomManager telecomManager = getTelecommService();
4867 if (telecomManager != null) {
4868 if (telecomManager.isRinging()) {
Santos Cordon6848f722014-05-21 15:22:12 -07004869 Log.i(TAG, "interceptKeyBeforeQueueing:"
4870 + " CALL key-down while ringing: Answer the call!");
Tyler Gunnef9f6f92014-09-12 22:16:17 -07004871 telecomManager.acceptRingingCall();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004872
Santos Cordon6848f722014-05-21 15:22:12 -07004873 // And *don't* pass this key thru to the current activity
4874 // (which is presumably the InCallScreen.)
4875 result &= ~ACTION_PASS_TO_USER;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004876 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004877 }
Jeff Brown00fa7bd2010-07-02 15:37:36 -07004878 }
Jeff Brown4d396052010-10-29 21:50:21 -07004879 break;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004880 }
Michael Wright869a67c2014-08-26 19:33:06 -07004881 case KeyEvent.KEYCODE_VOICE_ASSIST: {
4882 // Only do this if we would otherwise not pass it to the user. In that case,
4883 // interceptKeyBeforeDispatching would apply a similar but different policy in
4884 // order to invoke voice assist actions. Note that we need to make a copy of the
4885 // key event here because the original key event will be recycled when we return.
4886 if ((result & ACTION_PASS_TO_USER) == 0 && !down) {
4887 mBroadcastWakeLock.acquire();
4888 Message msg = mHandler.obtainMessage(MSG_LAUNCH_VOICE_ASSIST_WITH_WAKE_LOCK,
4889 keyguardActive ? 1 : 0, 0);
4890 msg.setAsynchronous(true);
4891 msg.sendToTarget();
4892 }
4893 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004894 }
Jeff Brown26875502014-01-30 21:47:47 -08004895
Jeff Brownbae8e772014-06-12 19:59:45 -07004896 if (useHapticFeedback) {
4897 performHapticFeedbackLw(null, HapticFeedbackConstants.VIRTUAL_KEY, false);
4898 }
4899
Jeff Brown26875502014-01-30 21:47:47 -08004900 if (isWakeKey) {
Jeff Brown13f00f02014-10-31 14:45:50 -07004901 wakeUp(event.getEventTime(), mAllowTheaterModeWakeFromKey);
Jeff Brown26875502014-01-30 21:47:47 -08004902 }
Bryce Lee584a4452014-10-21 15:55:55 -07004903
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004904 return result;
4905 }
4906
Jeff Brown1c2e4942012-11-06 16:32:01 -08004907 /**
Jeff Brown13f00f02014-10-31 14:45:50 -07004908 * Returns true if the key can have global actions attached to it.
4909 * We reserve all power management keys for the system since they require
4910 * very careful handling.
4911 */
4912 private static boolean isValidGlobalKey(int keyCode) {
4913 switch (keyCode) {
4914 case KeyEvent.KEYCODE_POWER:
4915 case KeyEvent.KEYCODE_WAKEUP:
4916 case KeyEvent.KEYCODE_SLEEP:
4917 return false;
4918 default:
4919 return true;
4920 }
4921 }
4922
4923 /**
Jeff Brown1c2e4942012-11-06 16:32:01 -08004924 * When the screen is off we ignore some keys that might otherwise typically
4925 * be considered wake keys. We filter them out here.
4926 *
4927 * {@link KeyEvent#KEYCODE_POWER} is notably absent from this list because it
4928 * is always considered a wake key.
4929 */
4930 private boolean isWakeKeyWhenScreenOff(int keyCode) {
4931 switch (keyCode) {
4932 // ignore volume keys unless docked
4933 case KeyEvent.KEYCODE_VOLUME_UP:
4934 case KeyEvent.KEYCODE_VOLUME_DOWN:
4935 case KeyEvent.KEYCODE_VOLUME_MUTE:
4936 return mDockMode != Intent.EXTRA_DOCK_STATE_UNDOCKED;
4937
4938 // ignore media and camera keys
4939 case KeyEvent.KEYCODE_MUTE:
4940 case KeyEvent.KEYCODE_HEADSETHOOK:
4941 case KeyEvent.KEYCODE_MEDIA_PLAY:
4942 case KeyEvent.KEYCODE_MEDIA_PAUSE:
4943 case KeyEvent.KEYCODE_MEDIA_PLAY_PAUSE:
4944 case KeyEvent.KEYCODE_MEDIA_STOP:
4945 case KeyEvent.KEYCODE_MEDIA_NEXT:
4946 case KeyEvent.KEYCODE_MEDIA_PREVIOUS:
4947 case KeyEvent.KEYCODE_MEDIA_REWIND:
4948 case KeyEvent.KEYCODE_MEDIA_RECORD:
4949 case KeyEvent.KEYCODE_MEDIA_FAST_FORWARD:
Jaekyun Seokbfdad8e2013-07-08 13:53:21 +09004950 case KeyEvent.KEYCODE_MEDIA_AUDIO_TRACK:
Jeff Brown1c2e4942012-11-06 16:32:01 -08004951 case KeyEvent.KEYCODE_CAMERA:
4952 return false;
4953 }
4954 return true;
4955 }
4956
4957
Jeff Brown56194eb2011-03-02 19:23:13 -08004958 /** {@inheritDoc} */
4959 @Override
Michael Wright70af00a2014-09-03 19:30:20 -07004960 public int interceptMotionBeforeQueueingNonInteractive(long whenNanos, int policyFlags) {
4961 if ((policyFlags & FLAG_WAKE) != 0) {
Bryce Lee5c138322014-11-03 08:26:09 -08004962 if (wakeUp(whenNanos / 1000000, mAllowTheaterModeWakeFromMotion)) {
4963 return 0;
4964 }
Michael Wright70af00a2014-09-03 19:30:20 -07004965 }
Bryce Lee5c138322014-11-03 08:26:09 -08004966
Michael Wright70af00a2014-09-03 19:30:20 -07004967 if (shouldDispatchInputWhenNonInteractive()) {
4968 return ACTION_PASS_TO_USER;
4969 }
Bryce Lee5c138322014-11-03 08:26:09 -08004970
Bryce Lee812d7022014-11-10 13:33:28 -08004971 // If we have not passed the action up and we are in theater mode without dreaming,
4972 // there will be no dream to intercept the touch and wake into ambient. The device should
4973 // wake up in this case.
4974 if (isTheaterModeEnabled() && (policyFlags & FLAG_WAKE) != 0) {
4975 wakeUp(whenNanos / 1000000, mAllowTheaterModeWakeFromMotionWhenNotDreaming);
4976 }
4977
Jeff Brown037c33e2014-04-09 00:31:55 -07004978 return 0;
Jeff Brown56194eb2011-03-02 19:23:13 -08004979 }
4980
Michael Wright70af00a2014-09-03 19:30:20 -07004981 private boolean shouldDispatchInputWhenNonInteractive() {
Bryce Lee5c138322014-11-03 08:26:09 -08004982 // Send events to keyguard while the screen is on.
Jim Millerab954542014-10-10 18:21:49 -07004983 if (isKeyguardShowingAndNotOccluded() && mDisplay != null
4984 && mDisplay.getState() != Display.STATE_OFF) {
Bryce Lee5c138322014-11-03 08:26:09 -08004985 return true;
4986 }
4987
4988 // Send events to a dozing dream even if the screen is off since the dream
4989 // is in control of the state of the screen.
4990 IDreamManager dreamManager = getDreamManager();
4991
4992 try {
4993 if (dreamManager != null && dreamManager.isDreaming()) {
4994 return true;
4995 }
4996 } catch (RemoteException e) {
4997 Slog.e(TAG, "RemoteException when checking if dreaming", e);
4998 }
4999
5000 // Otherwise, consume events since the user can't see what is being
5001 // interacted with.
5002 return false;
Michael Wright70af00a2014-09-03 19:30:20 -07005003 }
5004
RoboErik001c59c2015-01-26 15:53:51 -08005005 private void dispatchDirectAudioEvent(KeyEvent event) {
5006 if (event.getAction() != KeyEvent.ACTION_DOWN) {
5007 return;
5008 }
5009 int keyCode = event.getKeyCode();
John Spurlockb94f2d62015-03-17 14:11:57 -04005010 int flags = AudioManager.FLAG_SHOW_UI | AudioManager.FLAG_PLAY_SOUND
5011 | AudioManager.FLAG_FROM_KEY;
RoboErik001c59c2015-01-26 15:53:51 -08005012 String pkgName = mContext.getOpPackageName();
5013 switch (keyCode) {
5014 case KeyEvent.KEYCODE_VOLUME_UP:
5015 try {
John Spurlockee5ad722015-03-03 16:17:21 -05005016 getAudioService().adjustSuggestedStreamVolume(AudioManager.ADJUST_RAISE,
John Spurlock90874332015-03-10 16:00:54 -04005017 AudioManager.USE_DEFAULT_STREAM_TYPE, flags, pkgName, TAG);
RoboErik001c59c2015-01-26 15:53:51 -08005018 } catch (RemoteException e) {
5019 Log.e(TAG, "Error dispatching volume up in dispatchTvAudioEvent.", e);
5020 }
5021 break;
5022 case KeyEvent.KEYCODE_VOLUME_DOWN:
5023 try {
John Spurlockee5ad722015-03-03 16:17:21 -05005024 getAudioService().adjustSuggestedStreamVolume(AudioManager.ADJUST_LOWER,
John Spurlock90874332015-03-10 16:00:54 -04005025 AudioManager.USE_DEFAULT_STREAM_TYPE, flags, pkgName, TAG);
RoboErik001c59c2015-01-26 15:53:51 -08005026 } catch (RemoteException e) {
5027 Log.e(TAG, "Error dispatching volume down in dispatchTvAudioEvent.", e);
5028 }
5029 break;
5030 case KeyEvent.KEYCODE_VOLUME_MUTE:
5031 try {
5032 if (event.getRepeatCount() == 0) {
John Spurlockee5ad722015-03-03 16:17:21 -05005033 getAudioService().adjustSuggestedStreamVolume(
5034 AudioManager.ADJUST_TOGGLE_MUTE,
John Spurlock90874332015-03-10 16:00:54 -04005035 AudioManager.USE_DEFAULT_STREAM_TYPE, flags, pkgName, TAG);
RoboErik001c59c2015-01-26 15:53:51 -08005036 }
5037 } catch (RemoteException e) {
5038 Log.e(TAG, "Error dispatching mute in dispatchTvAudioEvent.", e);
5039 }
5040 break;
5041 }
5042 }
5043
Jeff Brown40013652012-05-16 21:22:36 -07005044 void dispatchMediaKeyWithWakeLock(KeyEvent event) {
5045 if (DEBUG_INPUT) {
5046 Slog.d(TAG, "dispatchMediaKeyWithWakeLock: " + event);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005047 }
5048
Jeff Brown40013652012-05-16 21:22:36 -07005049 if (mHavePendingMediaKeyRepeatWithWakeLock) {
5050 if (DEBUG_INPUT) {
5051 Slog.d(TAG, "dispatchMediaKeyWithWakeLock: canceled repeat");
5052 }
5053
5054 mHandler.removeMessages(MSG_DISPATCH_MEDIA_KEY_REPEAT_WITH_WAKE_LOCK);
5055 mHavePendingMediaKeyRepeatWithWakeLock = false;
5056 mBroadcastWakeLock.release(); // pending repeat was holding onto the wake lock
5057 }
5058
5059 dispatchMediaKeyWithWakeLockToAudioService(event);
5060
5061 if (event.getAction() == KeyEvent.ACTION_DOWN
5062 && event.getRepeatCount() == 0) {
5063 mHavePendingMediaKeyRepeatWithWakeLock = true;
5064
5065 Message msg = mHandler.obtainMessage(
5066 MSG_DISPATCH_MEDIA_KEY_REPEAT_WITH_WAKE_LOCK, event);
5067 msg.setAsynchronous(true);
5068 mHandler.sendMessageDelayed(msg, ViewConfiguration.getKeyRepeatTimeout());
5069 } else {
5070 mBroadcastWakeLock.release();
5071 }
5072 }
5073
5074 void dispatchMediaKeyRepeatWithWakeLock(KeyEvent event) {
5075 mHavePendingMediaKeyRepeatWithWakeLock = false;
5076
5077 KeyEvent repeatEvent = KeyEvent.changeTimeRepeat(event,
5078 SystemClock.uptimeMillis(), 1, event.getFlags() | KeyEvent.FLAG_LONG_PRESS);
5079 if (DEBUG_INPUT) {
5080 Slog.d(TAG, "dispatchMediaKeyRepeatWithWakeLock: " + repeatEvent);
5081 }
5082
5083 dispatchMediaKeyWithWakeLockToAudioService(repeatEvent);
5084 mBroadcastWakeLock.release();
5085 }
5086
5087 void dispatchMediaKeyWithWakeLockToAudioService(KeyEvent event) {
5088 if (ActivityManagerNative.isSystemReady()) {
RoboErik430fc482014-06-12 15:49:20 -07005089 MediaSessionLegacyHelper.getHelper(mContext).sendMediaButtonEvent(event, true);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005090 }
5091 }
5092
Michael Wright869a67c2014-08-26 19:33:06 -07005093 void launchVoiceAssistWithWakeLock(boolean keyguardActive) {
5094 Intent voiceIntent =
5095 new Intent(RecognizerIntent.ACTION_VOICE_SEARCH_HANDS_FREE);
5096 voiceIntent.putExtra(RecognizerIntent.EXTRA_SECURE, keyguardActive);
Bart Sears8b1c27c2015-03-18 23:51:02 +00005097 startActivityAsUser(voiceIntent, UserHandle.CURRENT_OR_SELF);
Michael Wright869a67c2014-08-26 19:33:06 -07005098 mBroadcastWakeLock.release();
5099 }
5100
Mike Lockwood1753f7f2009-08-24 14:49:07 -07005101 BroadcastReceiver mDockReceiver = new BroadcastReceiver() {
Craig Mautnereee29c42013-01-17 14:44:34 -08005102 @Override
Mike Lockwood1753f7f2009-08-24 14:49:07 -07005103 public void onReceive(Context context, Intent intent) {
Dianne Hackborn867ab6472010-04-29 13:28:56 -07005104 if (Intent.ACTION_DOCK_EVENT.equals(intent.getAction())) {
5105 mDockMode = intent.getIntExtra(Intent.EXTRA_DOCK_STATE,
5106 Intent.EXTRA_DOCK_STATE_UNDOCKED);
Daniel Sandler6396c722013-04-16 20:19:09 -04005107 } else {
5108 try {
5109 IUiModeManager uiModeService = IUiModeManager.Stub.asInterface(
5110 ServiceManager.getService(Context.UI_MODE_SERVICE));
5111 mUiMode = uiModeService.getCurrentModeType();
5112 } catch (RemoteException e) {
5113 }
Dianne Hackborn80fa1662009-10-07 14:02:10 -07005114 }
Jeff Brown01a98dd2011-09-20 15:08:29 -07005115 updateRotation(true);
Craig Mautnereee29c42013-01-17 14:44:34 -08005116 synchronized (mLock) {
5117 updateOrientationListenerLp();
5118 }
Mike Lockwood1753f7f2009-08-24 14:49:07 -07005119 }
5120 };
5121
Jeff Brown6aaf2952012-10-05 16:01:08 -07005122 BroadcastReceiver mDreamReceiver = new BroadcastReceiver() {
5123 @Override
5124 public void onReceive(Context context, Intent intent) {
5125 if (Intent.ACTION_DREAMING_STARTED.equals(intent.getAction())) {
Jim Miller5ecd8112013-01-09 18:50:26 -08005126 if (mKeyguardDelegate != null) {
5127 mKeyguardDelegate.onDreamingStarted();
Jeff Brown6aaf2952012-10-05 16:01:08 -07005128 }
5129 } else if (Intent.ACTION_DREAMING_STOPPED.equals(intent.getAction())) {
Jim Miller5ecd8112013-01-09 18:50:26 -08005130 if (mKeyguardDelegate != null) {
5131 mKeyguardDelegate.onDreamingStopped();
Jeff Brown6aaf2952012-10-05 16:01:08 -07005132 }
5133 }
5134 }
5135 };
5136
Christopher Tate5e08af02012-09-21 17:17:22 -07005137 BroadcastReceiver mMultiuserReceiver = new BroadcastReceiver() {
5138 @Override
5139 public void onReceive(Context context, Intent intent) {
5140 if (Intent.ACTION_USER_SWITCHED.equals(intent.getAction())) {
5141 // tickle the settings observer: this first ensures that we're
5142 // observing the relevant settings for the newly-active user,
5143 // and then updates our own bookkeeping based on the now-
5144 // current user.
5145 mSettingsObserver.onChange(false);
John Spurlockce479d82012-11-29 09:52:21 -05005146
5147 // force a re-application of focused window sysui visibility.
5148 // the window may never have been shown for this user
5149 // e.g. the keyguard when going through the new-user setup flow
John Spurlock04db1762013-05-13 12:46:41 -04005150 synchronized (mWindowManagerFuncs.getWindowManagerLock()) {
John Spurlockce479d82012-11-29 09:52:21 -05005151 mLastSystemUiFlags = 0;
5152 updateSystemUiVisibilityLw();
5153 }
Christopher Tate5e08af02012-09-21 17:17:22 -07005154 }
5155 }
5156 };
5157
John Spurlockd9b70bd2014-02-06 17:02:44 -05005158 private final Runnable mRequestTransientNav = new Runnable() {
5159 @Override
5160 public void run() {
5161 requestTransientBars(mNavigationBar);
5162 }
5163 };
5164
John Spurlocke1f366f2013-08-05 12:22:40 -04005165 private void requestTransientBars(WindowState swipeTarget) {
John Spurlock04db1762013-05-13 12:46:41 -04005166 synchronized (mWindowManagerFuncs.getWindowManagerLock()) {
Maurice Lam99c6e072014-04-28 18:24:28 -07005167 if (!isUserSetupComplete()) {
5168 // Swipe-up for navigation bar is disabled during setup
5169 return;
5170 }
John Spurlock27735a42013-08-14 17:57:38 -04005171 boolean sb = mStatusBarController.checkShowTransientBarLw();
5172 boolean nb = mNavigationBarController.checkShowTransientBarLw();
John Spurlockad3e6cb2013-04-30 08:47:43 -04005173 if (sb || nb) {
Adrian Roos62b65e42015-02-25 18:05:34 +01005174 // Don't show status bar when swiping on already visible navigation bar
5175 if (!nb && swipeTarget == mNavigationBar) {
John Spurlocke1f366f2013-08-05 12:22:40 -04005176 if (DEBUG) Slog.d(TAG, "Not showing transient bar, wrong swipe target");
John Spurlockad3e6cb2013-04-30 08:47:43 -04005177 return;
5178 }
John Spurlock27735a42013-08-14 17:57:38 -04005179 if (sb) mStatusBarController.showTransient();
5180 if (nb) mNavigationBarController.showTransient();
John Spurlockf1a36642013-10-12 17:50:42 -04005181 mImmersiveModeConfirmation.confirmCurrentPrompt();
John Spurlockad3e6cb2013-04-30 08:47:43 -04005182 updateSystemUiVisibilityLw();
John Spurlock32beb2c2013-03-11 10:16:47 -04005183 }
John Spurlockad3e6cb2013-04-30 08:47:43 -04005184 }
5185 }
5186
Jeff Brown3ee549c2014-09-22 20:14:39 -07005187 // Called on the PowerManager's Notifier thread.
Jeff Brownc38c9be2012-10-04 13:16:19 -07005188 @Override
Jeff Brown140ffc72014-05-01 15:18:00 -07005189 public void goingToSleep(int why) {
Dianne Hackborn74489012009-03-24 20:50:09 -07005190 EventLog.writeEvent(70000, 0);
Jeff Brown36c4db82014-09-19 12:05:31 -07005191 if (DEBUG_WAKEUP) Slog.i(TAG, "Going to sleep...");
Jeff Brown3ee549c2014-09-22 20:14:39 -07005192
5193 // We must get this work done here because the power manager will drop
5194 // the wake lock and let the system suspend once this function returns.
The Android Open Source Project0727d222009-03-11 12:11:58 -07005195 synchronized (mLock) {
Jeff Brown3ee549c2014-09-22 20:14:39 -07005196 mAwake = false;
5197 mKeyguardDrawComplete = false;
Jeff Browna20dda42014-05-27 20:57:24 -07005198 updateWakeGestureListenerLp();
The Android Open Source Project0727d222009-03-11 12:11:58 -07005199 updateOrientationListenerLp();
Mike Lockwood28569302010-01-28 11:54:40 -05005200 updateLockScreenTimeout();
The Android Open Source Project0727d222009-03-11 12:11:58 -07005201 }
Jeff Brown3ee549c2014-09-22 20:14:39 -07005202
5203 if (mKeyguardDelegate != null) {
5204 mKeyguardDelegate.onScreenTurnedOff(why);
5205 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005206 }
5207
Jeff Brown13f00f02014-10-31 14:45:50 -07005208 private void wakeUpFromPowerKey(long eventTime) {
5209 wakeUp(eventTime, mAllowTheaterModeWakeFromPowerKey);
5210 }
5211
Bryce Lee5c138322014-11-03 08:26:09 -08005212 private boolean wakeUp(long wakeTime, boolean wakeInTheaterMode) {
Bryce Lee584a4452014-10-21 15:55:55 -07005213 if (!wakeInTheaterMode && isTheaterModeEnabled()) {
Bryce Lee5c138322014-11-03 08:26:09 -08005214 return false;
Bryce Lee584a4452014-10-21 15:55:55 -07005215 }
5216
5217 mPowerManager.wakeUp(wakeTime);
Bryce Lee5c138322014-11-03 08:26:09 -08005218 return true;
Bryce Lee584a4452014-10-21 15:55:55 -07005219 }
5220
Jeff Brown3ee549c2014-09-22 20:14:39 -07005221 // Called on the PowerManager's Notifier thread.
Jeff Brownc38c9be2012-10-04 13:16:19 -07005222 @Override
Jeff Brown36c4db82014-09-19 12:05:31 -07005223 public void wakingUp() {
Dianne Hackborn74489012009-03-24 20:50:09 -07005224 EventLog.writeEvent(70000, 1);
Jeff Brown36c4db82014-09-19 12:05:31 -07005225 if (DEBUG_WAKEUP) Slog.i(TAG, "Waking up...");
Craig Mautner8a0da012014-05-31 15:13:37 -07005226
Jeff Brown3ee549c2014-09-22 20:14:39 -07005227 // Since goToSleep performs these functions synchronously, we must
5228 // do the same here. We cannot post this work to a handler because
5229 // that might cause it to become reordered with respect to what
5230 // may happen in a future call to goToSleep.
The Android Open Source Project0727d222009-03-11 12:11:58 -07005231 synchronized (mLock) {
Jeff Brown3ee549c2014-09-22 20:14:39 -07005232 mAwake = true;
5233 mKeyguardDrawComplete = false;
5234 if (mKeyguardDelegate != null) {
5235 mHandler.removeMessages(MSG_KEYGUARD_DRAWN_TIMEOUT);
5236 mHandler.sendEmptyMessageDelayed(MSG_KEYGUARD_DRAWN_TIMEOUT, 1000);
5237 }
5238
Jeff Browna20dda42014-05-27 20:57:24 -07005239 updateWakeGestureListenerLp();
The Android Open Source Project0727d222009-03-11 12:11:58 -07005240 updateOrientationListenerLp();
Mike Lockwood28569302010-01-28 11:54:40 -05005241 updateLockScreenTimeout();
The Android Open Source Project0727d222009-03-11 12:11:58 -07005242 }
Jeff Brownc38c9be2012-10-04 13:16:19 -07005243
Jim Miller5ecd8112013-01-09 18:50:26 -08005244 if (mKeyguardDelegate != null) {
Craig Mautner8a0da012014-05-31 15:13:37 -07005245 mKeyguardDelegate.onScreenTurnedOn(mKeyguardDelegateCallback);
Jeff Brown36c4db82014-09-19 12:05:31 -07005246 // ... eventually calls finishKeyguardDrawn
Jeff Brownc38c9be2012-10-04 13:16:19 -07005247 } else {
Craig Mautner8a0da012014-05-31 15:13:37 -07005248 if (DEBUG_WAKEUP) Slog.d(TAG, "null mKeyguardDelegate: setting mKeyguardDrawComplete.");
Jeff Brown36c4db82014-09-19 12:05:31 -07005249 finishKeyguardDrawn();
Jeff Brownc38c9be2012-10-04 13:16:19 -07005250 }
Jeff Brown36c4db82014-09-19 12:05:31 -07005251 }
5252
Jeff Brown36c4db82014-09-19 12:05:31 -07005253 private void finishKeyguardDrawn() {
Jeff Brown3ee549c2014-09-22 20:14:39 -07005254 synchronized (mLock) {
5255 if (!mAwake || mKeyguardDrawComplete) {
5256 return; // spurious
5257 }
5258
Jeff Brown36c4db82014-09-19 12:05:31 -07005259 mKeyguardDrawComplete = true;
Jeff Brown3ee549c2014-09-22 20:14:39 -07005260 if (mKeyguardDelegate != null) {
5261 mHandler.removeMessages(MSG_KEYGUARD_DRAWN_TIMEOUT);
5262 }
5263 }
5264
5265 finishScreenTurningOn();
5266 }
5267
5268 // Called on the DisplayManager's DisplayPowerController thread.
5269 @Override
5270 public void screenTurnedOff() {
5271 if (DEBUG_WAKEUP) Slog.i(TAG, "Screen turned off...");
5272
5273 synchronized (mLock) {
5274 mScreenOnEarly = false;
5275 mScreenOnFully = false;
5276 mWindowManagerDrawComplete = false;
5277 mScreenOnListener = null;
5278 updateOrientationListenerLp();
Jeff Brown36c4db82014-09-19 12:05:31 -07005279 }
5280 }
5281
Jeff Brown3ee549c2014-09-22 20:14:39 -07005282 // Called on the DisplayManager's DisplayPowerController thread.
Jeff Brown36c4db82014-09-19 12:05:31 -07005283 @Override
5284 public void screenTurningOn(final ScreenOnListener screenOnListener) {
Jeff Brown36c4db82014-09-19 12:05:31 -07005285 if (DEBUG_WAKEUP) Slog.i(TAG, "Screen turning on...");
Jeff Brown36c4db82014-09-19 12:05:31 -07005286
Jeff Brown3ee549c2014-09-22 20:14:39 -07005287 synchronized (mLock) {
5288 mScreenOnEarly = true;
5289 mScreenOnFully = false;
5290 mWindowManagerDrawComplete = false;
5291 mScreenOnListener = screenOnListener;
5292 updateOrientationListenerLp();
5293 }
Jeff Brown36c4db82014-09-19 12:05:31 -07005294
Craig Mautnerc3daedd2014-09-13 11:17:23 -07005295 mWindowManagerInternal.waitForAllWindowsDrawn(mWindowManagerDrawCallback,
5296 WAITING_FOR_DRAWN_TIMEOUT);
Jeff Brown36c4db82014-09-19 12:05:31 -07005297 // ... eventually calls finishWindowsDrawn
5298 }
5299
Jeff Brown36c4db82014-09-19 12:05:31 -07005300 private void finishWindowsDrawn() {
Jeff Brown3ee549c2014-09-22 20:14:39 -07005301 synchronized (mLock) {
5302 if (!mScreenOnEarly || mWindowManagerDrawComplete) {
5303 return; // spurious
5304 }
5305
Jeff Brown36c4db82014-09-19 12:05:31 -07005306 mWindowManagerDrawComplete = true;
Jeff Brown36c4db82014-09-19 12:05:31 -07005307 }
Jeff Brown3ee549c2014-09-22 20:14:39 -07005308
5309 finishScreenTurningOn();
Jeff Brownc38c9be2012-10-04 13:16:19 -07005310 }
5311
Craig Mautner8a0da012014-05-31 15:13:37 -07005312 private void finishScreenTurningOn() {
Jeff Brown3ee549c2014-09-22 20:14:39 -07005313 final ScreenOnListener listener;
5314 final boolean enableScreen;
Jeff Brown36c4db82014-09-19 12:05:31 -07005315 synchronized (mLock) {
Jeff Brown3ee549c2014-09-22 20:14:39 -07005316 if (DEBUG_WAKEUP) Slog.d(TAG,
5317 "finishScreenTurningOn: mAwake=" + mAwake
5318 + ", mScreenOnEarly=" + mScreenOnEarly
5319 + ", mScreenOnFully=" + mScreenOnFully
5320 + ", mKeyguardDrawComplete=" + mKeyguardDrawComplete
5321 + ", mWindowManagerDrawComplete=" + mWindowManagerDrawComplete);
5322
5323 if (mScreenOnFully || !mScreenOnEarly || !mWindowManagerDrawComplete
5324 || (mAwake && !mKeyguardDrawComplete)) {
5325 return; // spurious or not ready yet
Jeff Brown36c4db82014-09-19 12:05:31 -07005326 }
5327
Jeff Brown3ee549c2014-09-22 20:14:39 -07005328 if (DEBUG_WAKEUP) Slog.i(TAG, "Finished screen turning on...");
5329 listener = mScreenOnListener;
Craig Mautner13f6ea72014-06-23 14:57:02 -07005330 mScreenOnListener = null;
Jeff Brown3ee549c2014-09-22 20:14:39 -07005331 mScreenOnFully = true;
5332
5333 // Remember the first time we draw the keyguard so we know when we're done with
5334 // the main part of booting and can enable the screen and hide boot messages.
5335 if (!mKeyguardDrawnOnce && mAwake) {
5336 mKeyguardDrawnOnce = true;
5337 enableScreen = true;
5338 if (mBootMessageNeedsHiding) {
5339 mBootMessageNeedsHiding = false;
5340 hideBootMessages();
5341 }
5342 } else {
5343 enableScreen = false;
5344 }
Jeff Brownc38c9be2012-10-04 13:16:19 -07005345 }
5346
Jeff Brown3ee549c2014-09-22 20:14:39 -07005347 if (listener != null) {
5348 listener.onScreenOn();
5349 }
Jeff Brown4fc45272012-10-10 18:28:14 -07005350
Jeff Brown3ee549c2014-09-22 20:14:39 -07005351 if (enableScreen) {
5352 try {
5353 mWindowManager.enableScreenIfNeeded();
5354 } catch (RemoteException unhandled) {
Jeff Brown36c4db82014-09-19 12:05:31 -07005355 }
Craig Mautnera631d492014-08-05 15:16:01 -07005356 }
5357 }
5358
5359 private void handleHideBootMessage() {
Jeff Brown3ee549c2014-09-22 20:14:39 -07005360 synchronized (mLock) {
5361 if (!mKeyguardDrawnOnce) {
5362 mBootMessageNeedsHiding = true;
5363 return; // keyguard hasn't drawn the first time yet, not done booting
5364 }
Craig Mautnera631d492014-08-05 15:16:01 -07005365 }
Jeff Brown3ee549c2014-09-22 20:14:39 -07005366
5367 if (mBootMsgDialog != null) {
5368 if (DEBUG_WAKEUP) Slog.d(TAG, "handleHideBootMessage: dismissing");
5369 mBootMsgDialog.dismiss();
5370 mBootMsgDialog = null;
Craig Mautnera631d492014-08-05 15:16:01 -07005371 }
Jeff Brownc38c9be2012-10-04 13:16:19 -07005372 }
5373
5374 @Override
Jeff Brown3ee549c2014-09-22 20:14:39 -07005375 public boolean isScreenOn() {
5376 return mScreenOnFully;
Dianne Hackborn08743722009-12-21 12:16:51 -08005377 }
Jeff Brownc38c9be2012-10-04 13:16:19 -07005378
Dianne Hackborn08743722009-12-21 12:16:51 -08005379 /** {@inheritDoc} */
Jose Lima9546b202014-07-02 17:21:51 -07005380 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005381 public void enableKeyguard(boolean enabled) {
Jim Miller5ecd8112013-01-09 18:50:26 -08005382 if (mKeyguardDelegate != null) {
5383 mKeyguardDelegate.setKeyguardEnabled(enabled);
Mike Lockwood3a74bd32011-08-12 13:55:22 -07005384 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005385 }
5386
5387 /** {@inheritDoc} */
Jose Lima9546b202014-07-02 17:21:51 -07005388 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005389 public void exitKeyguardSecurely(OnKeyguardExitResult callback) {
Jim Miller5ecd8112013-01-09 18:50:26 -08005390 if (mKeyguardDelegate != null) {
5391 mKeyguardDelegate.verifyUnlock(callback);
Mike Lockwood3a74bd32011-08-12 13:55:22 -07005392 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005393 }
5394
Jim Millerab954542014-10-10 18:21:49 -07005395 private boolean isKeyguardShowingAndNotOccluded() {
Jim Miller5ecd8112013-01-09 18:50:26 -08005396 if (mKeyguardDelegate == null) return false;
Jim Millerab954542014-10-10 18:21:49 -07005397 return mKeyguardDelegate.isShowing() && !mKeyguardOccluded;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005398 }
5399
Mike Lockwood520d8bc2011-02-18 13:23:13 -05005400 /** {@inheritDoc} */
Jose Lima9546b202014-07-02 17:21:51 -07005401 @Override
Mike Lockwood520d8bc2011-02-18 13:23:13 -05005402 public boolean isKeyguardLocked() {
5403 return keyguardOn();
5404 }
5405
5406 /** {@inheritDoc} */
Jose Lima9546b202014-07-02 17:21:51 -07005407 @Override
Mike Lockwood520d8bc2011-02-18 13:23:13 -05005408 public boolean isKeyguardSecure() {
Jim Miller5ecd8112013-01-09 18:50:26 -08005409 if (mKeyguardDelegate == null) return false;
5410 return mKeyguardDelegate.isSecure();
Mike Lockwood520d8bc2011-02-18 13:23:13 -05005411 }
5412
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005413 /** {@inheritDoc} */
Jose Lima9546b202014-07-02 17:21:51 -07005414 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005415 public boolean inKeyguardRestrictedKeyInputMode() {
Jim Miller5ecd8112013-01-09 18:50:26 -08005416 if (mKeyguardDelegate == null) return false;
5417 return mKeyguardDelegate.isInputRestricted();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005418 }
5419
Jose Lima9546b202014-07-02 17:21:51 -07005420 @Override
Dianne Hackborn90c52de2011-09-23 12:57:44 -07005421 public void dismissKeyguardLw() {
RoboErik8a2cfc32014-05-16 11:19:38 -07005422 if (mKeyguardDelegate != null && mKeyguardDelegate.isShowing()) {
Craig Mautnerc0d2d0a2014-10-31 16:25:15 -07005423 if (DEBUG_KEYGUARD) Slog.d(TAG, "PWM.dismissKeyguardLw");
Daniel Sandler1ce804392012-11-07 15:07:12 -05005424 mHandler.post(new Runnable() {
Jose Lima9546b202014-07-02 17:21:51 -07005425 @Override
Daniel Sandler1ce804392012-11-07 15:07:12 -05005426 public void run() {
Jorim Jaggi8de4311c2014-08-11 22:36:20 +02005427 // ask the keyguard to prompt the user to authenticate if necessary
5428 mKeyguardDelegate.dismiss();
5429 }
5430 });
5431 }
5432 }
5433
5434 public void notifyActivityDrawnForKeyguardLw() {
5435 if (mKeyguardDelegate != null) {
5436 mHandler.post(new Runnable() {
5437 @Override
5438 public void run() {
5439 mKeyguardDelegate.onActivityDrawn();
Daniel Sandler1ce804392012-11-07 15:07:12 -05005440 }
5441 });
Dianne Hackborn90c52de2011-09-23 12:57:44 -07005442 }
5443 }
5444
Jorim Jaggicff0acb2014-03-31 16:35:15 +02005445 @Override
5446 public boolean isKeyguardDrawnLw() {
5447 synchronized (mLock) {
Jeff Brown3ee549c2014-09-22 20:14:39 -07005448 return mKeyguardDrawnOnce;
Jorim Jaggicff0acb2014-03-31 16:35:15 +02005449 }
5450 }
5451
Jorim Jaggi0d674622014-05-21 01:34:15 +02005452 @Override
Jorim Jaggie29b2db2014-05-30 23:17:03 +02005453 public void startKeyguardExitAnimation(long startTime, long fadeoutDuration) {
Jorim Jaggi0d674622014-05-21 01:34:15 +02005454 if (mKeyguardDelegate != null) {
Craig Mautnerc0d2d0a2014-10-31 16:25:15 -07005455 if (DEBUG_KEYGUARD) Slog.d(TAG, "PWM.startKeyguardExitAnimation");
Jorim Jaggie29b2db2014-05-30 23:17:03 +02005456 mKeyguardDelegate.startKeyguardExitAnimation(startTime, fadeoutDuration);
Jorim Jaggi0d674622014-05-21 01:34:15 +02005457 }
5458 }
5459
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005460 void sendCloseSystemWindows() {
Jorim Jaggib10e33f2015-02-04 21:57:40 +01005461 PhoneWindow.sendCloseSystemWindows(mContext, null);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005462 }
5463
5464 void sendCloseSystemWindows(String reason) {
Jorim Jaggib10e33f2015-02-04 21:57:40 +01005465 PhoneWindow.sendCloseSystemWindows(mContext, reason);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005466 }
Mitsuru Oshima831d0d92009-06-16 18:27:18 -07005467
Jeff Brown01a98dd2011-09-20 15:08:29 -07005468 @Override
5469 public int rotationForOrientationLw(int orientation, int lastRotation) {
Daniel Sandler2ed6ad62011-02-22 14:54:17 -05005470 if (false) {
5471 Slog.v(TAG, "rotationForOrientationLw(orient="
5472 + orientation + ", last=" + lastRotation
5473 + "); user=" + mUserRotation + " "
5474 + ((mUserRotationMode == WindowManagerPolicy.USER_ROTATION_LOCKED)
5475 ? "USER_ROTATION_LOCKED" : "")
5476 );
5477 }
5478
Craig Mautner46ac6fa2013-08-01 10:06:34 -07005479 if (mForceDefaultOrientation) {
5480 return Surface.ROTATION_0;
5481 }
5482
The Android Open Source Project0727d222009-03-11 12:11:58 -07005483 synchronized (mLock) {
Jeff Brownc0347aa2011-09-23 17:26:09 -07005484 int sensorRotation = mOrientationListener.getProposedRotation(); // may be -1
5485 if (sensorRotation < 0) {
Jeff Brown0f862b42012-09-27 21:11:01 -07005486 sensorRotation = lastRotation;
Jeff Brownc0347aa2011-09-23 17:26:09 -07005487 }
Jeff Brown01a98dd2011-09-20 15:08:29 -07005488
Jeff Browndec6cf42011-11-15 14:08:20 -08005489 final int preferredRotation;
Jeff Brown2e7760e2012-04-11 15:14:55 -07005490 if (mLidState == LID_OPEN && mLidOpenRotation >= 0) {
Jeff Brown01a98dd2011-09-20 15:08:29 -07005491 // Ignore sensor when lid switch is open and rotation is forced.
5492 preferredRotation = mLidOpenRotation;
5493 } else if (mDockMode == Intent.EXTRA_DOCK_STATE_CAR
Jeff Brownc0347aa2011-09-23 17:26:09 -07005494 && (mCarDockEnablesAccelerometer || mCarDockRotation >= 0)) {
Jeff Brown01a98dd2011-09-20 15:08:29 -07005495 // Ignore sensor when in car dock unless explicitly enabled.
5496 // This case can override the behavior of NOSENSOR, and can also
5497 // enable 180 degree rotation while docked.
Jeff Brownc0347aa2011-09-23 17:26:09 -07005498 preferredRotation = mCarDockEnablesAccelerometer
Jeff Brown01a98dd2011-09-20 15:08:29 -07005499 ? sensorRotation : mCarDockRotation;
Jeff Brown1a693182011-11-08 14:44:16 -08005500 } else if ((mDockMode == Intent.EXTRA_DOCK_STATE_DESK
5501 || mDockMode == Intent.EXTRA_DOCK_STATE_LE_DESK
5502 || mDockMode == Intent.EXTRA_DOCK_STATE_HE_DESK)
Jeff Brownc0347aa2011-09-23 17:26:09 -07005503 && (mDeskDockEnablesAccelerometer || mDeskDockRotation >= 0)) {
Jeff Brown01a98dd2011-09-20 15:08:29 -07005504 // Ignore sensor when in desk dock unless explicitly enabled.
5505 // This case can override the behavior of NOSENSOR, and can also
5506 // enable 180 degree rotation while docked.
Jeff Brownc0347aa2011-09-23 17:26:09 -07005507 preferredRotation = mDeskDockEnablesAccelerometer
Jeff Brown01a98dd2011-09-20 15:08:29 -07005508 ? sensorRotation : mDeskDockRotation;
Jeff Brownc82c89ed2013-04-17 17:18:15 -07005509 } else if (mHdmiPlugged && mDemoHdmiRotationLock) {
5510 // Ignore sensor when plugged into HDMI when demo HDMI rotation lock enabled.
Jeff Browneb3e4b92011-12-06 19:54:24 -08005511 // Note that the dock orientation overrides the HDMI orientation.
Jeff Brownc82c89ed2013-04-17 17:18:15 -07005512 preferredRotation = mDemoHdmiRotation;
5513 } else if (mHdmiPlugged && mDockMode == Intent.EXTRA_DOCK_STATE_UNDOCKED
5514 && mUndockedHdmiRotation >= 0) {
5515 // Ignore sensor when plugged into HDMI and an undocked orientation has
5516 // been specified in the configuration (only for legacy devices without
5517 // full multi-display support).
5518 // Note that the dock orientation overrides the HDMI orientation.
5519 preferredRotation = mUndockedHdmiRotation;
Chong Zhangae6119ff2014-11-11 18:54:39 -08005520 } else if (mDemoRotationLock) {
5521 // Ignore sensor when demo rotation lock is enabled.
5522 // Note that the dock orientation and HDMI rotation lock override this.
5523 preferredRotation = mDemoRotation;
Dianne Hackbornb9ec1ac2013-04-10 17:34:25 -07005524 } else if (orientation == ActivityInfo.SCREEN_ORIENTATION_LOCKED) {
5525 // Application just wants to remain locked in the last rotation.
5526 preferredRotation = lastRotation;
Jeff Brownbcdfc622014-03-06 19:13:04 -08005527 } else if (!mSupportAutoRotation) {
5528 // If we don't support auto-rotation then bail out here and ignore
5529 // the sensor and any rotation lock settings.
5530 preferredRotation = -1;
Jeff Brown207673cd2012-06-05 17:47:11 -07005531 } else if ((mUserRotationMode == WindowManagerPolicy.USER_ROTATION_FREE
Jeff Brown01a98dd2011-09-20 15:08:29 -07005532 && (orientation == ActivityInfo.SCREEN_ORIENTATION_USER
Dianne Hackbornb9ec1ac2013-04-10 17:34:25 -07005533 || orientation == ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED
5534 || orientation == ActivityInfo.SCREEN_ORIENTATION_USER_LANDSCAPE
5535 || orientation == ActivityInfo.SCREEN_ORIENTATION_USER_PORTRAIT
5536 || orientation == ActivityInfo.SCREEN_ORIENTATION_FULL_USER))
Jeff Brown01a98dd2011-09-20 15:08:29 -07005537 || orientation == ActivityInfo.SCREEN_ORIENTATION_SENSOR
5538 || orientation == ActivityInfo.SCREEN_ORIENTATION_FULL_SENSOR
5539 || orientation == ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE
5540 || orientation == ActivityInfo.SCREEN_ORIENTATION_SENSOR_PORTRAIT) {
5541 // Otherwise, use sensor only if requested by the application or enabled
5542 // by default for USER or UNSPECIFIED modes. Does not apply to NOSENSOR.
Jeff Brownd3187e32011-09-21 19:26:44 -07005543 if (mAllowAllRotations < 0) {
5544 // Can't read this during init() because the context doesn't
5545 // have display metrics at that time so we cannot determine
5546 // tablet vs. phone then.
5547 mAllowAllRotations = mContext.getResources().getBoolean(
5548 com.android.internal.R.bool.config_allowAllRotations) ? 1 : 0;
5549 }
Jeff Brown01a98dd2011-09-20 15:08:29 -07005550 if (sensorRotation != Surface.ROTATION_180
Jeff Brownd3187e32011-09-21 19:26:44 -07005551 || mAllowAllRotations == 1
Dianne Hackbornb9ec1ac2013-04-10 17:34:25 -07005552 || orientation == ActivityInfo.SCREEN_ORIENTATION_FULL_SENSOR
5553 || orientation == ActivityInfo.SCREEN_ORIENTATION_FULL_USER) {
Jeff Brown01a98dd2011-09-20 15:08:29 -07005554 preferredRotation = sensorRotation;
5555 } else {
5556 preferredRotation = lastRotation;
5557 }
Jeff Brown207673cd2012-06-05 17:47:11 -07005558 } else if (mUserRotationMode == WindowManagerPolicy.USER_ROTATION_LOCKED
5559 && orientation != ActivityInfo.SCREEN_ORIENTATION_NOSENSOR) {
5560 // Apply rotation lock. Does not apply to NOSENSOR.
5561 // The idea is that the user rotation expresses a weak preference for the direction
5562 // of gravity and as NOSENSOR is never affected by gravity, then neither should
5563 // NOSENSOR be affected by rotation lock (although it will be affected by docks).
Jeff Brown4dfce202011-10-05 12:00:10 -07005564 preferredRotation = mUserRotation;
Jeff Browndec6cf42011-11-15 14:08:20 -08005565 } else {
5566 // No overriding preference.
5567 // We will do exactly what the application asked us to do.
5568 preferredRotation = -1;
Jeff Brown01a98dd2011-09-20 15:08:29 -07005569 }
5570
Dianne Hackborne5439f22010-10-02 16:53:50 -07005571 switch (orientation) {
5572 case ActivityInfo.SCREEN_ORIENTATION_PORTRAIT:
Jeff Browndec6cf42011-11-15 14:08:20 -08005573 // Return portrait unless overridden.
5574 if (isAnyPortrait(preferredRotation)) {
5575 return preferredRotation;
5576 }
Dianne Hackborne5439f22010-10-02 16:53:50 -07005577 return mPortraitRotation;
Dianne Hackborne5439f22010-10-02 16:53:50 -07005578
Jeff Brown01a98dd2011-09-20 15:08:29 -07005579 case ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE:
Jeff Browndec6cf42011-11-15 14:08:20 -08005580 // Return landscape unless overridden.
5581 if (isLandscapeOrSeascape(preferredRotation)) {
5582 return preferredRotation;
5583 }
Jeff Brown01a98dd2011-09-20 15:08:29 -07005584 return mLandscapeRotation;
5585
5586 case ActivityInfo.SCREEN_ORIENTATION_REVERSE_PORTRAIT:
Jeff Browndec6cf42011-11-15 14:08:20 -08005587 // Return reverse portrait unless overridden.
5588 if (isAnyPortrait(preferredRotation)) {
5589 return preferredRotation;
5590 }
Jeff Brown01a98dd2011-09-20 15:08:29 -07005591 return mUpsideDownRotation;
5592
5593 case ActivityInfo.SCREEN_ORIENTATION_REVERSE_LANDSCAPE:
Jeff Browndec6cf42011-11-15 14:08:20 -08005594 // Return seascape unless overridden.
5595 if (isLandscapeOrSeascape(preferredRotation)) {
5596 return preferredRotation;
5597 }
Jeff Brown01a98dd2011-09-20 15:08:29 -07005598 return mSeascapeRotation;
5599
5600 case ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE:
Dianne Hackbornb9ec1ac2013-04-10 17:34:25 -07005601 case ActivityInfo.SCREEN_ORIENTATION_USER_LANDSCAPE:
Jeff Brown01a98dd2011-09-20 15:08:29 -07005602 // Return either landscape rotation.
5603 if (isLandscapeOrSeascape(preferredRotation)) {
5604 return preferredRotation;
5605 }
5606 if (isLandscapeOrSeascape(lastRotation)) {
Jeff Brown4519f072011-01-23 13:16:01 -08005607 return lastRotation;
5608 }
Jeff Brown01a98dd2011-09-20 15:08:29 -07005609 return mLandscapeRotation;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005610
Jeff Brown01a98dd2011-09-20 15:08:29 -07005611 case ActivityInfo.SCREEN_ORIENTATION_SENSOR_PORTRAIT:
Dianne Hackbornb9ec1ac2013-04-10 17:34:25 -07005612 case ActivityInfo.SCREEN_ORIENTATION_USER_PORTRAIT:
Jeff Brown01a98dd2011-09-20 15:08:29 -07005613 // Return either portrait rotation.
5614 if (isAnyPortrait(preferredRotation)) {
5615 return preferredRotation;
5616 }
5617 if (isAnyPortrait(lastRotation)) {
5618 return lastRotation;
5619 }
5620 return mPortraitRotation;
5621
5622 default:
Jeff Brown4dfce202011-10-05 12:00:10 -07005623 // For USER, UNSPECIFIED, NOSENSOR, SENSOR and FULL_SENSOR,
5624 // just return the preferred orientation we already calculated.
Jeff Brown01a98dd2011-09-20 15:08:29 -07005625 if (preferredRotation >= 0) {
5626 return preferredRotation;
5627 }
Dianne Hackborndacea8c2011-04-21 17:26:39 -07005628 return Surface.ROTATION_0;
Daniel Sandlere7e5ac22011-02-22 16:10:21 -05005629 }
5630 }
Steve Howarda7bfe6a2010-09-23 16:47:49 -07005631 }
5632
Jeff Brown01a98dd2011-09-20 15:08:29 -07005633 @Override
5634 public boolean rotationHasCompatibleMetricsLw(int orientation, int rotation) {
5635 switch (orientation) {
5636 case ActivityInfo.SCREEN_ORIENTATION_PORTRAIT:
5637 case ActivityInfo.SCREEN_ORIENTATION_REVERSE_PORTRAIT:
5638 case ActivityInfo.SCREEN_ORIENTATION_SENSOR_PORTRAIT:
5639 return isAnyPortrait(rotation);
5640
5641 case ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE:
5642 case ActivityInfo.SCREEN_ORIENTATION_REVERSE_LANDSCAPE:
5643 case ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE:
5644 return isLandscapeOrSeascape(rotation);
5645
5646 default:
5647 return true;
5648 }
Steve Howarda7bfe6a2010-09-23 16:47:49 -07005649 }
5650
Jeff Brownc0347aa2011-09-23 17:26:09 -07005651 @Override
5652 public void setRotationLw(int rotation) {
5653 mOrientationListener.setCurrentRotation(rotation);
5654 }
5655
Jeff Brown01a98dd2011-09-20 15:08:29 -07005656 private boolean isLandscapeOrSeascape(int rotation) {
5657 return rotation == mLandscapeRotation || rotation == mSeascapeRotation;
Dianne Hackborne5439f22010-10-02 16:53:50 -07005658 }
5659
Jeff Brown01a98dd2011-09-20 15:08:29 -07005660 private boolean isAnyPortrait(int rotation) {
5661 return rotation == mPortraitRotation || rotation == mUpsideDownRotation;
Dianne Hackborne5439f22010-10-02 16:53:50 -07005662 }
5663
Jose Lima9546b202014-07-02 17:21:51 -07005664 @Override
Svetoslav Ganov80943d82013-01-02 10:25:37 -08005665 public int getUserRotationMode() {
5666 return Settings.System.getIntForUser(mContext.getContentResolver(),
Brett Chabot7e55c402013-05-16 19:38:08 -07005667 Settings.System.ACCELEROMETER_ROTATION, 0, UserHandle.USER_CURRENT) != 0 ?
5668 WindowManagerPolicy.USER_ROTATION_FREE :
5669 WindowManagerPolicy.USER_ROTATION_LOCKED;
Svetoslav Ganov80943d82013-01-02 10:25:37 -08005670 }
Daniel Sandlerb73617d2010-08-17 00:41:00 -04005671
5672 // User rotation: to be used when all else fails in assigning an orientation to the device
Jose Lima9546b202014-07-02 17:21:51 -07005673 @Override
Daniel Sandlerb73617d2010-08-17 00:41:00 -04005674 public void setUserRotationMode(int mode, int rot) {
5675 ContentResolver res = mContext.getContentResolver();
Daniel Sandler2ed6ad62011-02-22 14:54:17 -05005676
5677 // mUserRotationMode and mUserRotation will be assigned by the content observer
Daniel Sandlerb73617d2010-08-17 00:41:00 -04005678 if (mode == WindowManagerPolicy.USER_ROTATION_LOCKED) {
Christopher Tate5e08af02012-09-21 17:17:22 -07005679 Settings.System.putIntForUser(res,
Daniel Sandlerb73617d2010-08-17 00:41:00 -04005680 Settings.System.USER_ROTATION,
Christopher Tate5e08af02012-09-21 17:17:22 -07005681 rot,
5682 UserHandle.USER_CURRENT);
5683 Settings.System.putIntForUser(res,
Daniel Sandler2ed6ad62011-02-22 14:54:17 -05005684 Settings.System.ACCELEROMETER_ROTATION,
Christopher Tate5e08af02012-09-21 17:17:22 -07005685 0,
5686 UserHandle.USER_CURRENT);
Daniel Sandlerb73617d2010-08-17 00:41:00 -04005687 } else {
Christopher Tate5e08af02012-09-21 17:17:22 -07005688 Settings.System.putIntForUser(res,
Daniel Sandlerb73617d2010-08-17 00:41:00 -04005689 Settings.System.ACCELEROMETER_ROTATION,
Christopher Tate5e08af02012-09-21 17:17:22 -07005690 1,
5691 UserHandle.USER_CURRENT);
Daniel Sandlerb73617d2010-08-17 00:41:00 -04005692 }
5693 }
5694
Jose Lima9546b202014-07-02 17:21:51 -07005695 @Override
Jeff Brownac143512012-04-05 18:57:33 -07005696 public void setSafeMode(boolean safeMode) {
5697 mSafeMode = safeMode;
5698 performHapticFeedbackLw(null, safeMode
5699 ? HapticFeedbackConstants.SAFE_MODE_ENABLED
5700 : HapticFeedbackConstants.SAFE_MODE_DISABLED, true);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005701 }
Craig Mautnereda67292013-04-28 13:50:14 -07005702
Dianne Hackborn181ceb52009-08-27 22:16:40 -07005703 static long[] getLongIntArray(Resources r, int resid) {
5704 int[] ar = r.getIntArray(resid);
5705 if (ar == null) {
5706 return null;
5707 }
5708 long[] out = new long[ar.length];
5709 for (int i=0; i<ar.length; i++) {
5710 out[i] = ar[i];
5711 }
5712 return out;
5713 }
Craig Mautnereda67292013-04-28 13:50:14 -07005714
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005715 /** {@inheritDoc} */
Craig Mautnereda67292013-04-28 13:50:14 -07005716 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005717 public void systemReady() {
Jim Millerab954542014-10-10 18:21:49 -07005718 mKeyguardDelegate = new KeyguardServiceDelegate(mContext);
Mike Lockwooded8902d2013-11-15 11:01:47 -08005719 mKeyguardDelegate.onSystemReady();
5720
Michael Wright3818c922014-09-02 13:59:07 -07005721 readCameraLensCoverState();
Jeff Brown4f5fa282014-06-12 19:19:15 -07005722 updateUiMode();
Dianne Hackbornb1a79802009-09-29 15:18:31 -07005723 synchronized (mLock) {
5724 updateOrientationListenerLp();
Dianne Hackbornc777e072010-02-12 13:07:59 -08005725 mSystemReady = true;
5726 mHandler.post(new Runnable() {
Craig Mautnereda67292013-04-28 13:50:14 -07005727 @Override
Dianne Hackbornc777e072010-02-12 13:07:59 -08005728 public void run() {
5729 updateSettings();
5730 }
5731 });
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005732 }
5733 }
Dianne Hackborn661cd522011-08-22 00:26:20 -07005734
Dianne Hackbornba24e4d2011-09-01 11:17:06 -07005735 /** {@inheritDoc} */
Jose Lima9546b202014-07-02 17:21:51 -07005736 @Override
Dianne Hackbornba24e4d2011-09-01 11:17:06 -07005737 public void systemBooted() {
Jim Millere5f910a2013-10-16 18:15:46 -07005738 if (mKeyguardDelegate != null) {
Jason Monk5eeebf52014-09-26 12:36:51 -04005739 mKeyguardDelegate.bindService(mContext);
Jim Millere5f910a2013-10-16 18:15:46 -07005740 mKeyguardDelegate.onBootCompleted();
5741 }
Dianne Hackbornba24e4d2011-09-01 11:17:06 -07005742 synchronized (mLock) {
5743 mSystemBooted = true;
5744 }
Jeff Brown36c4db82014-09-19 12:05:31 -07005745 wakingUp();
5746 screenTurningOn(null);
Dianne Hackbornba24e4d2011-09-01 11:17:06 -07005747 }
5748
Dianne Hackborn661cd522011-08-22 00:26:20 -07005749 ProgressDialog mBootMsgDialog = null;
5750
5751 /** {@inheritDoc} */
Jose Lima9546b202014-07-02 17:21:51 -07005752 @Override
Dianne Hackborn661cd522011-08-22 00:26:20 -07005753 public void showBootMessage(final CharSequence msg, final boolean always) {
5754 mHandler.post(new Runnable() {
5755 @Override public void run() {
5756 if (mBootMsgDialog == null) {
Craig Stout4c0cb8a2014-04-04 13:03:10 -07005757 int theme;
5758 if (mContext.getPackageManager().hasSystemFeature(
5759 PackageManager.FEATURE_WATCH)) {
5760 theme = com.android.internal.R.style.Theme_Micro_Dialog_Alert;
5761 } else if (mContext.getPackageManager().hasSystemFeature(
5762 PackageManager.FEATURE_TELEVISION)) {
5763 theme = com.android.internal.R.style.Theme_Leanback_Dialog_Alert;
5764 } else {
5765 theme = 0;
5766 }
Vinod Krishnanfa8fc412014-04-18 14:35:53 -07005767
5768 mBootMsgDialog = new ProgressDialog(mContext, theme) {
Dianne Hackborn295e3c22011-08-25 13:19:08 -07005769 // This dialog will consume all events coming in to
5770 // it, to avoid it trying to do things too early in boot.
5771 @Override public boolean dispatchKeyEvent(KeyEvent event) {
5772 return true;
5773 }
5774 @Override public boolean dispatchKeyShortcutEvent(KeyEvent event) {
5775 return true;
5776 }
5777 @Override public boolean dispatchTouchEvent(MotionEvent ev) {
5778 return true;
5779 }
5780 @Override public boolean dispatchTrackballEvent(MotionEvent ev) {
5781 return true;
5782 }
5783 @Override public boolean dispatchGenericMotionEvent(MotionEvent ev) {
5784 return true;
5785 }
5786 @Override public boolean dispatchPopulateAccessibilityEvent(
5787 AccessibilityEvent event) {
5788 return true;
5789 }
5790 };
Jeff Hao9f60c082014-10-28 18:51:07 -07005791 if (mContext.getPackageManager().isUpgrade()) {
5792 mBootMsgDialog.setTitle(R.string.android_upgrading_title);
5793 } else {
5794 mBootMsgDialog.setTitle(R.string.android_start_title);
5795 }
Dianne Hackborn661cd522011-08-22 00:26:20 -07005796 mBootMsgDialog.setProgressStyle(ProgressDialog.STYLE_SPINNER);
5797 mBootMsgDialog.setIndeterminate(true);
5798 mBootMsgDialog.getWindow().setType(
Dianne Hackborn29aae6f2011-08-18 18:30:09 -07005799 WindowManager.LayoutParams.TYPE_BOOT_PROGRESS);
Dianne Hackborn661cd522011-08-22 00:26:20 -07005800 mBootMsgDialog.getWindow().addFlags(
5801 WindowManager.LayoutParams.FLAG_DIM_BEHIND
5802 | WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN);
5803 mBootMsgDialog.getWindow().setDimAmount(1);
Dianne Hackbornd9efb952011-12-07 14:56:51 -08005804 WindowManager.LayoutParams lp = mBootMsgDialog.getWindow().getAttributes();
5805 lp.screenOrientation = ActivityInfo.SCREEN_ORIENTATION_NOSENSOR;
5806 mBootMsgDialog.getWindow().setAttributes(lp);
Dianne Hackborn661cd522011-08-22 00:26:20 -07005807 mBootMsgDialog.setCancelable(false);
5808 mBootMsgDialog.show();
5809 }
5810 mBootMsgDialog.setMessage(msg);
5811 }
5812 });
5813 }
5814
5815 /** {@inheritDoc} */
Jose Lima9546b202014-07-02 17:21:51 -07005816 @Override
Dianne Hackborn661cd522011-08-22 00:26:20 -07005817 public void hideBootMessages() {
Craig Mautnera631d492014-08-05 15:16:01 -07005818 mHandler.sendEmptyMessage(MSG_HIDE_BOOT_MESSAGE);
Dianne Hackborn661cd522011-08-22 00:26:20 -07005819 }
5820
Mike Lockwood28569302010-01-28 11:54:40 -05005821 /** {@inheritDoc} */
Jose Lima9546b202014-07-02 17:21:51 -07005822 @Override
Mike Lockwood28569302010-01-28 11:54:40 -05005823 public void userActivity() {
Dianne Hackborndf89e652011-10-06 22:35:11 -07005824 // ***************************************
5825 // NOTE NOTE NOTE NOTE NOTE NOTE NOTE NOTE
5826 // ***************************************
5827 // THIS IS CALLED FROM DEEP IN THE POWER MANAGER
5828 // WITH ITS LOCKS HELD.
5829 //
5830 // This code must be VERY careful about the locks
5831 // it acquires.
5832 // In fact, the current code acquires way too many,
5833 // and probably has lurking deadlocks.
5834
Mike Lockwood28569302010-01-28 11:54:40 -05005835 synchronized (mScreenLockTimeout) {
5836 if (mLockScreenTimerActive) {
5837 // reset the timer
5838 mHandler.removeCallbacks(mScreenLockTimeout);
5839 mHandler.postDelayed(mScreenLockTimeout, mLockScreenTimeout);
5840 }
5841 }
Daniel Sandler0601eb72011-04-13 01:01:32 -04005842 }
5843
Adam Cohenf7522022012-10-03 20:03:18 -07005844 class ScreenLockTimeout implements Runnable {
5845 Bundle options;
5846
5847 @Override
Mike Lockwood28569302010-01-28 11:54:40 -05005848 public void run() {
5849 synchronized (this) {
5850 if (localLOGV) Log.v(TAG, "mScreenLockTimeout activating keyguard");
Jim Miller5ecd8112013-01-09 18:50:26 -08005851 if (mKeyguardDelegate != null) {
5852 mKeyguardDelegate.doKeyguardTimeout(options);
Mike Lockwood3a74bd32011-08-12 13:55:22 -07005853 }
Mike Lockwood28569302010-01-28 11:54:40 -05005854 mLockScreenTimerActive = false;
Adam Cohenf7522022012-10-03 20:03:18 -07005855 options = null;
Mike Lockwood28569302010-01-28 11:54:40 -05005856 }
5857 }
Mike Lockwood28569302010-01-28 11:54:40 -05005858
Adam Cohenf7522022012-10-03 20:03:18 -07005859 public void setLockOptions(Bundle options) {
5860 this.options = options;
5861 }
5862 }
5863
5864 ScreenLockTimeout mScreenLockTimeout = new ScreenLockTimeout();
5865
Jose Lima9546b202014-07-02 17:21:51 -07005866 @Override
Adam Cohenf7522022012-10-03 20:03:18 -07005867 public void lockNow(Bundle options) {
Jim Miller93c518e2012-01-17 15:55:31 -08005868 mContext.enforceCallingOrSelfPermission(android.Manifest.permission.DEVICE_POWER, null);
5869 mHandler.removeCallbacks(mScreenLockTimeout);
Adam Cohenf7522022012-10-03 20:03:18 -07005870 if (options != null) {
5871 // In case multiple calls are made to lockNow, we don't wipe out the options
5872 // until the runnable actually executes.
5873 mScreenLockTimeout.setLockOptions(options);
5874 }
Jim Miller93c518e2012-01-17 15:55:31 -08005875 mHandler.post(mScreenLockTimeout);
5876 }
5877
Mike Lockwood28569302010-01-28 11:54:40 -05005878 private void updateLockScreenTimeout() {
5879 synchronized (mScreenLockTimeout) {
Jeff Brown3ee549c2014-09-22 20:14:39 -07005880 boolean enable = (mAllowLockscreenWhenOn && mAwake &&
Jim Miller5ecd8112013-01-09 18:50:26 -08005881 mKeyguardDelegate != null && mKeyguardDelegate.isSecure());
Mike Lockwood28569302010-01-28 11:54:40 -05005882 if (mLockScreenTimerActive != enable) {
5883 if (enable) {
5884 if (localLOGV) Log.v(TAG, "setting lockscreen timer");
5885 mHandler.postDelayed(mScreenLockTimeout, mLockScreenTimeout);
5886 } else {
5887 if (localLOGV) Log.v(TAG, "clearing lockscreen timer");
5888 mHandler.removeCallbacks(mScreenLockTimeout);
5889 }
5890 mLockScreenTimerActive = enable;
5891 }
5892 }
5893 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005894
Jeff Brown061ea992015-04-17 19:55:47 -07005895 private void updateDreamingSleepToken(boolean acquire) {
5896 if (acquire) {
5897 if (mDreamingSleepToken == null) {
5898 mDreamingSleepToken = mActivityManagerInternal.acquireSleepToken("Dream");
5899 }
5900 } else {
5901 if (mDreamingSleepToken != null) {
5902 mDreamingSleepToken.release();
5903 }
5904 }
5905 }
5906
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005907 /** {@inheritDoc} */
Craig Mautnereda67292013-04-28 13:50:14 -07005908 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005909 public void enableScreenAfterBoot() {
5910 readLidState();
Jeff Brownc458ce92012-04-30 14:58:40 -07005911 applyLidSwitchState();
Jeff Brown01a98dd2011-09-20 15:08:29 -07005912 updateRotation(true);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005913 }
Dianne Hackbornf54c8f92009-09-19 14:03:57 -07005914
Jeff Brownc458ce92012-04-30 14:58:40 -07005915 private void applyLidSwitchState() {
Jeff Brownc458ce92012-04-30 14:58:40 -07005916 if (mLidState == LID_CLOSED && mLidControlsSleep) {
Jeff Brown6d8fd272014-05-20 21:24:38 -07005917 mPowerManager.goToSleep(SystemClock.uptimeMillis(),
Jeff Brownc12035c2014-08-13 18:52:25 -07005918 PowerManager.GO_TO_SLEEP_REASON_LID_SWITCH,
Jeff Brown6d8fd272014-05-20 21:24:38 -07005919 PowerManager.GO_TO_SLEEP_FLAG_NO_DOZE);
Jeff Brownc458ce92012-04-30 14:58:40 -07005920 }
Jeff Browna20dda42014-05-27 20:57:24 -07005921
5922 synchronized (mLock) {
5923 updateWakeGestureListenerLp();
5924 }
Jeff Brown01a98dd2011-09-20 15:08:29 -07005925 }
5926
Jeff Brown4f5fa282014-06-12 19:19:15 -07005927 void updateUiMode() {
5928 if (mUiModeManager == null) {
5929 mUiModeManager = IUiModeManager.Stub.asInterface(
5930 ServiceManager.getService(Context.UI_MODE_SERVICE));
5931 }
5932 try {
5933 mUiMode = mUiModeManager.getCurrentModeType();
5934 } catch (RemoteException e) {
5935 }
5936 }
5937
Jeff Brown01a98dd2011-09-20 15:08:29 -07005938 void updateRotation(boolean alwaysSendConfiguration) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005939 try {
5940 //set orientation on WindowManager
Dianne Hackbornf87d1962012-04-04 12:48:24 -07005941 mWindowManager.updateRotation(alwaysSendConfiguration, false);
5942 } catch (RemoteException e) {
5943 // Ignore
5944 }
5945 }
5946
5947 void updateRotation(boolean alwaysSendConfiguration, boolean forceRelayout) {
5948 try {
5949 //set orientation on WindowManager
5950 mWindowManager.updateRotation(alwaysSendConfiguration, forceRelayout);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005951 } catch (RemoteException e) {
5952 // Ignore
5953 }
5954 }
5955
Daniel Sandler6396c722013-04-16 20:19:09 -04005956 /**
5957 * Return an Intent to launch the currently active dock app as home. Returns
5958 * null if the standard home should be launched, which is the case if any of the following is
5959 * true:
5960 * <ul>
5961 * <li>The device is not in either car mode or desk mode
5962 * <li>The device is in car mode but ENABLE_CAR_DOCK_HOME_CAPTURE is false
5963 * <li>The device is in desk mode but ENABLE_DESK_DOCK_HOME_CAPTURE is false
5964 * <li>The device is in car mode but there's no CAR_DOCK app with METADATA_DOCK_HOME
5965 * <li>The device is in desk mode but there's no DESK_DOCK app with METADATA_DOCK_HOME
5966 * </ul>
Craig Mautnereda67292013-04-28 13:50:14 -07005967 * @return A dock intent.
Daniel Sandler6396c722013-04-16 20:19:09 -04005968 */
5969 Intent createHomeDockIntent() {
5970 Intent intent = null;
5971
5972 // What home does is based on the mode, not the dock state. That
5973 // is, when in car mode you should be taken to car home regardless
5974 // of whether we are actually in a car dock.
5975 if (mUiMode == Configuration.UI_MODE_TYPE_CAR) {
5976 if (ENABLE_CAR_DOCK_HOME_CAPTURE) {
5977 intent = mCarDockIntent;
5978 }
5979 } else if (mUiMode == Configuration.UI_MODE_TYPE_DESK) {
5980 if (ENABLE_DESK_DOCK_HOME_CAPTURE) {
5981 intent = mDeskDockIntent;
5982 }
Jeff Brown4f5fa282014-06-12 19:19:15 -07005983 } else if (mUiMode == Configuration.UI_MODE_TYPE_WATCH
5984 && (mDockMode == Intent.EXTRA_DOCK_STATE_DESK
5985 || mDockMode == Intent.EXTRA_DOCK_STATE_HE_DESK
5986 || mDockMode == Intent.EXTRA_DOCK_STATE_LE_DESK)) {
5987 // Always launch dock home from home when watch is docked, if it exists.
5988 intent = mDeskDockIntent;
Daniel Sandler6396c722013-04-16 20:19:09 -04005989 }
5990
5991 if (intent == null) {
5992 return null;
5993 }
5994
5995 ActivityInfo ai = null;
5996 ResolveInfo info = mContext.getPackageManager().resolveActivityAsUser(
5997 intent,
John Spurlockf56bef12013-07-09 09:51:46 -04005998 PackageManager.MATCH_DEFAULT_ONLY | PackageManager.GET_META_DATA,
Craig Mautnerd625ab22013-09-06 13:40:31 -07005999 mCurrentUserId);
Daniel Sandler6396c722013-04-16 20:19:09 -04006000 if (info != null) {
6001 ai = info.activityInfo;
6002 }
6003 if (ai != null
6004 && ai.metaData != null
6005 && ai.metaData.getBoolean(Intent.METADATA_DOCK_HOME)) {
6006 intent = new Intent(intent);
6007 intent.setClassName(ai.packageName, ai.name);
6008 return intent;
6009 }
6010
6011 return null;
6012 }
6013
Filip Gruszczynskia483a1d2015-03-17 19:06:58 +00006014 void startDockOrHome(boolean fromHomeKey, boolean awakenFromDreams) {
6015 if (awakenFromDreams) {
6016 awakenDreams();
6017 }
Daniel Sandler6396c722013-04-16 20:19:09 -04006018
6019 Intent dock = createHomeDockIntent();
6020 if (dock != null) {
6021 try {
Bryce Lee01b0c5f2015-02-05 18:24:04 -08006022 if (fromHomeKey) {
6023 dock.putExtra(WindowManagerPolicy.EXTRA_FROM_HOME_KEY, fromHomeKey);
6024 }
Bart Sears8b1c27c2015-03-18 23:51:02 +00006025 startActivityAsUser(dock, UserHandle.CURRENT);
Daniel Sandler6396c722013-04-16 20:19:09 -04006026 return;
6027 } catch (ActivityNotFoundException e) {
6028 }
6029 }
6030
Bryce Lee01b0c5f2015-02-05 18:24:04 -08006031 Intent intent;
6032
6033 if (fromHomeKey) {
6034 intent = new Intent(mHomeIntent);
6035 intent.putExtra(WindowManagerPolicy.EXTRA_FROM_HOME_KEY, fromHomeKey);
6036 } else {
6037 intent = mHomeIntent;
6038 }
6039
Bryce Lee9fc0b6f2015-03-19 21:37:45 +00006040 startActivityAsUser(intent, UserHandle.CURRENT);
Dianne Hackborn39c2d712009-09-22 11:41:31 -07006041 }
Craig Mautnereda67292013-04-28 13:50:14 -07006042
Dianne Hackborn39c2d712009-09-22 11:41:31 -07006043 /**
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006044 * goes to the home screen
6045 * @return whether it did anything
6046 */
6047 boolean goHome() {
Bart Sears8b1c27c2015-03-18 23:51:02 +00006048 if (!isUserSetupComplete()) {
6049 Slog.i(TAG, "Not going home because user setup is in progress.");
6050 return false;
6051 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006052 if (false) {
6053 // This code always brings home to the front.
Dianne Hackborn256dd3b2009-05-19 18:51:21 -07006054 try {
6055 ActivityManagerNative.getDefault().stopAppSwitches();
6056 } catch (RemoteException e) {
6057 }
Dianne Hackborn94a679d2009-07-28 17:51:07 -07006058 sendCloseSystemWindows();
Filip Gruszczynskia483a1d2015-03-17 19:06:58 +00006059 startDockOrHome(false /*fromHomeKey*/, true /* awakenFromDreams */);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006060 } else {
6061 // This code brings home to the front or, if it is already
6062 // at the front, puts the device to sleep.
6063 try {
Wink Savilled2e6a332010-02-12 12:12:06 -08006064 if (SystemProperties.getInt("persist.sys.uts-test-mode", 0) == 1) {
6065 /// Roll back EndcallBehavior as the cupcake design to pass P1 lab entry.
6066 Log.d(TAG, "UTS-TEST-MODE");
6067 } else {
6068 ActivityManagerNative.getDefault().stopAppSwitches();
6069 sendCloseSystemWindows();
Daniel Sandler6396c722013-04-16 20:19:09 -04006070 Intent dock = createHomeDockIntent();
6071 if (dock != null) {
6072 int result = ActivityManagerNative.getDefault()
6073 .startActivityAsUser(null, null, dock,
6074 dock.resolveTypeIfNeeded(mContext.getContentResolver()),
6075 null, null, 0,
6076 ActivityManager.START_FLAG_ONLY_IF_NEEDED,
Jeff Hao1b012d32014-08-20 10:35:34 -07006077 null, null, UserHandle.USER_CURRENT);
Daniel Sandler6396c722013-04-16 20:19:09 -04006078 if (result == ActivityManager.START_RETURN_INTENT_TO_CALLER) {
6079 return false;
6080 }
6081 }
Dianne Hackborn39c2d712009-09-22 11:41:31 -07006082 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006083 int result = ActivityManagerNative.getDefault()
Dianne Hackbornf265ea92013-01-31 15:00:51 -08006084 .startActivityAsUser(null, null, mHomeIntent,
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006085 mHomeIntent.resolveTypeIfNeeded(mContext.getContentResolver()),
Dianne Hackborna4972e92012-03-14 10:38:05 -07006086 null, null, 0,
6087 ActivityManager.START_FLAG_ONLY_IF_NEEDED,
Jeff Hao1b012d32014-08-20 10:35:34 -07006088 null, null, UserHandle.USER_CURRENT);
Dianne Hackborna4972e92012-03-14 10:38:05 -07006089 if (result == ActivityManager.START_RETURN_INTENT_TO_CALLER) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006090 return false;
6091 }
6092 } catch (RemoteException ex) {
6093 // bummer, the activity manager, which is in this process, is dead
6094 }
6095 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006096 return true;
6097 }
Craig Mautnereda67292013-04-28 13:50:14 -07006098
6099 @Override
The Android Open Source Project0727d222009-03-11 12:11:58 -07006100 public void setCurrentOrientationLw(int newOrientation) {
6101 synchronized (mLock) {
6102 if (newOrientation != mCurrentAppOrientation) {
6103 mCurrentAppOrientation = newOrientation;
6104 updateOrientationListenerLp();
6105 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006106 }
6107 }
Amith Yamasanic33cb712010-02-10 15:21:49 -08006108
Svetoslav Ganov7befb7d2012-09-27 16:49:23 -07006109 private void performAuditoryFeedbackForAccessibilityIfNeed() {
6110 if (!isGlobalAccessibilityGestureEnabled()) {
6111 return;
6112 }
6113 AudioManager audioManager = (AudioManager) mContext.getSystemService(
6114 Context.AUDIO_SERVICE);
6115 if (audioManager.isSilentMode()) {
6116 return;
6117 }
6118 Ringtone ringTone = RingtoneManager.getRingtone(mContext,
6119 Settings.System.DEFAULT_NOTIFICATION_URI);
6120 ringTone.setStreamType(AudioManager.STREAM_MUSIC);
6121 ringTone.play();
6122 }
Craig Mautnereda67292013-04-28 13:50:14 -07006123
Bryce Lee584a4452014-10-21 15:55:55 -07006124 private boolean isTheaterModeEnabled() {
6125 return Settings.Global.getInt(mContext.getContentResolver(),
6126 Settings.Global.THEATER_MODE_ON, 0) == 1;
6127 }
6128
Svetoslav Ganov7befb7d2012-09-27 16:49:23 -07006129 private boolean isGlobalAccessibilityGestureEnabled() {
6130 return Settings.Global.getInt(mContext.getContentResolver(),
6131 Settings.Global.ENABLE_ACCESSIBILITY_GLOBAL_GESTURE_ENABLED, 0) == 1;
6132 }
6133
Craig Mautnereda67292013-04-28 13:50:14 -07006134 @Override
The Android Open Source Project0727d222009-03-11 12:11:58 -07006135 public boolean performHapticFeedbackLw(WindowState win, int effectId, boolean always) {
Svetoslav Ganov96179212012-10-10 14:17:45 -07006136 if (!mVibrator.hasVibrator()) {
6137 return false;
6138 }
Christopher Tate5e08af02012-09-21 17:17:22 -07006139 final boolean hapticsDisabled = Settings.System.getIntForUser(mContext.getContentResolver(),
6140 Settings.System.HAPTIC_FEEDBACK_ENABLED, 0, UserHandle.USER_CURRENT) == 0;
Jeff Brown82379ba2014-07-25 19:03:28 -07006141 if (hapticsDisabled && !always) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006142 return false;
6143 }
Amith Yamasanic33cb712010-02-10 15:21:49 -08006144 long[] pattern = null;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006145 switch (effectId) {
6146 case HapticFeedbackConstants.LONG_PRESS:
Amith Yamasanic33cb712010-02-10 15:21:49 -08006147 pattern = mLongPressVibePattern;
6148 break;
Dianne Hackbornb1a79802009-09-29 15:18:31 -07006149 case HapticFeedbackConstants.VIRTUAL_KEY:
Amith Yamasanic33cb712010-02-10 15:21:49 -08006150 pattern = mVirtualKeyVibePattern;
6151 break;
6152 case HapticFeedbackConstants.KEYBOARD_TAP:
6153 pattern = mKeyboardTapVibePattern;
6154 break;
Fabrice Di Meglioeeff63a2013-08-05 12:07:24 -07006155 case HapticFeedbackConstants.CLOCK_TICK:
6156 pattern = mClockTickVibePattern;
6157 break;
Fabrice Di Megliobd9152f2013-10-01 11:21:31 -07006158 case HapticFeedbackConstants.CALENDAR_DATE:
6159 pattern = mCalendarDateVibePattern;
6160 break;
Dianne Hackbornb1a79802009-09-29 15:18:31 -07006161 case HapticFeedbackConstants.SAFE_MODE_DISABLED:
Amith Yamasanic33cb712010-02-10 15:21:49 -08006162 pattern = mSafeModeDisabledVibePattern;
6163 break;
Dianne Hackbornb1a79802009-09-29 15:18:31 -07006164 case HapticFeedbackConstants.SAFE_MODE_ENABLED:
Amith Yamasanic33cb712010-02-10 15:21:49 -08006165 pattern = mSafeModeEnabledVibePattern;
6166 break;
Amith Yamasanic33cb712010-02-10 15:21:49 -08006167 default:
6168 return false;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006169 }
Dianne Hackbornf265ea92013-01-31 15:00:51 -08006170 int owningUid;
6171 String owningPackage;
6172 if (win != null) {
6173 owningUid = win.getOwningUid();
6174 owningPackage = win.getOwningPackage();
6175 } else {
6176 owningUid = android.os.Process.myUid();
Dianne Hackborn95d78532013-09-11 09:51:14 -07006177 owningPackage = mContext.getOpPackageName();
Dianne Hackbornf265ea92013-01-31 15:00:51 -08006178 }
Amith Yamasanic33cb712010-02-10 15:21:49 -08006179 if (pattern.length == 1) {
6180 // One-shot vibration
John Spurlock7b414672014-07-18 13:02:39 -04006181 mVibrator.vibrate(owningUid, owningPackage, pattern[0], VIBRATION_ATTRIBUTES);
Amith Yamasanic33cb712010-02-10 15:21:49 -08006182 } else {
6183 // Pattern vibration
John Spurlock7b414672014-07-18 13:02:39 -04006184 mVibrator.vibrate(owningUid, owningPackage, pattern, -1, VIBRATION_ATTRIBUTES);
Amith Yamasanic33cb712010-02-10 15:21:49 -08006185 }
6186 return true;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006187 }
Jeff Brownc38c9be2012-10-04 13:16:19 -07006188
6189 @Override
6190 public void keepScreenOnStartedLw() {
Daniel Sandler0601eb72011-04-13 01:01:32 -04006191 }
6192
Jeff Brownc38c9be2012-10-04 13:16:19 -07006193 @Override
6194 public void keepScreenOnStoppedLw() {
Jim Millerab954542014-10-10 18:21:49 -07006195 if (isKeyguardShowingAndNotOccluded()) {
Jim Miller25190572013-02-28 17:36:24 -08006196 mPowerManager.userActivity(SystemClock.uptimeMillis(), false);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006197 }
6198 }
Mike Lockwoodfcb39242009-10-21 23:01:07 -04006199
Dianne Hackborndf89e652011-10-06 22:35:11 -07006200 private int updateSystemUiVisibilityLw() {
Joe Onorato664644d2011-01-23 17:53:23 -08006201 // If there is no window focused, there will be nobody to handle the events
6202 // anyway, so just hang on in whatever state we're in until things settle down.
Adrian Roos53f28ec2014-10-29 17:26:12 +01006203 final WindowState win = mFocusedWindow != null ? mFocusedWindow
6204 : mTopFullscreenOpaqueWindowState;
John Spurlock79da8332013-09-20 12:04:47 -04006205 if (win == null) {
Dianne Hackborndf89e652011-10-06 22:35:11 -07006206 return 0;
6207 }
Jorim Jaggi380ecb82014-03-14 17:25:20 +01006208 if ((win.getAttrs().privateFlags & PRIVATE_FLAG_KEYGUARD) != 0 && mHideLockScreen == true) {
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07006209 // We are updating at a point where the keyguard has gotten
6210 // focus, but we were last in a state where the top window is
6211 // hiding it. This is probably because the keyguard as been
6212 // shown while the top window was displayed, so we want to ignore
6213 // it here because this is just a very transient change and it
6214 // will quickly lose focus once it correctly gets hidden.
6215 return 0;
6216 }
John Spurlock32beb2c2013-03-11 10:16:47 -04006217
John Spurlock1db8b682014-02-18 11:18:59 -05006218 int tmpVisibility = PolicyControl.getSystemUiVisibility(win, null)
Dianne Hackborne26ab702011-10-16 13:21:33 -07006219 & ~mResettingSystemUiFlags
6220 & ~mForceClearedSystemUiFlags;
John Spurlock79da8332013-09-20 12:04:47 -04006221 if (mForcingShowNavBar && win.getSurfaceLayer() < mForcingShowNavBarLayer) {
John Spurlockc6d1c602014-01-17 15:22:06 -05006222 tmpVisibility &= ~PolicyControl.adjustClearableFlags(win, View.SYSTEM_UI_CLEARABLE_FLAGS);
Dianne Hackborn891d3fb2013-01-09 18:31:37 -08006223 }
Adrian Rooscd3884d2015-02-18 17:25:23 +01006224 tmpVisibility = updateLightStatusBarLw(tmpVisibility);
John Spurlock79da8332013-09-20 12:04:47 -04006225 final int visibility = updateSystemBarsLw(win, mLastSystemUiFlags, tmpVisibility);
John Spurlockad3e6cb2013-04-30 08:47:43 -04006226 final int diff = visibility ^ mLastSystemUiFlags;
John Spurlock79da8332013-09-20 12:04:47 -04006227 final boolean needsMenu = win.getNeedsMenuLw(mTopFullscreenOpaqueWindowState);
Dianne Hackborne0f085d2011-11-30 18:41:15 -08006228 if (diff == 0 && mLastFocusNeedsMenu == needsMenu
John Spurlock79da8332013-09-20 12:04:47 -04006229 && mFocusedApp == win.getAppToken()) {
Dianne Hackborndf89e652011-10-06 22:35:11 -07006230 return 0;
6231 }
Dianne Hackborne26ab702011-10-16 13:21:33 -07006232 mLastSystemUiFlags = visibility;
Dianne Hackborn4eff8d32011-11-10 19:38:40 -08006233 mLastFocusNeedsMenu = needsMenu;
John Spurlock79da8332013-09-20 12:04:47 -04006234 mFocusedApp = win.getAppToken();
Dianne Hackborndf89e652011-10-06 22:35:11 -07006235 mHandler.post(new Runnable() {
Craig Mautnereda67292013-04-28 13:50:14 -07006236 @Override
Dianne Hackborndf89e652011-10-06 22:35:11 -07006237 public void run() {
Dianne Hackborn42e620c2012-06-24 13:20:51 -07006238 try {
6239 IStatusBarService statusbar = getStatusBarService();
6240 if (statusbar != null) {
Adrian Roos53f28ec2014-10-29 17:26:12 +01006241 statusbar.setSystemUiVisibility(visibility, 0xffffffff, win.toString());
Dianne Hackborn42e620c2012-06-24 13:20:51 -07006242 statusbar.topAppWindowChanged(needsMenu);
Joe Onorato664644d2011-01-23 17:53:23 -08006243 }
Dianne Hackborn42e620c2012-06-24 13:20:51 -07006244 } catch (RemoteException e) {
6245 // re-acquire status bar service next time it is needed.
6246 mStatusBarService = null;
Joe Onorato664644d2011-01-23 17:53:23 -08006247 }
Dianne Hackborndf89e652011-10-06 22:35:11 -07006248 }
6249 });
6250 return diff;
Joe Onorato664644d2011-01-23 17:53:23 -08006251 }
6252
Adrian Rooscd3884d2015-02-18 17:25:23 +01006253 private int updateLightStatusBarLw(int vis) {
6254 WindowState statusColorWin = isStatusBarKeyguard() && !mHideLockScreen
6255 ? mStatusBar
6256 : mTopFullscreenOpaqueOrDimmingWindowState;
6257
6258 if (statusColorWin != null) {
6259 if (statusColorWin == mTopFullscreenOpaqueWindowState) {
6260 // If the top fullscreen-or-dimming window is also the top fullscreen, respect
6261 // its light flag.
6262 vis &= ~View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR;
6263 vis |= PolicyControl.getSystemUiVisibility(statusColorWin, null)
6264 & View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR;
6265 } else if (statusColorWin != null && statusColorWin.isDimming()) {
6266 // Otherwise if it's dimming, clear the light flag.
6267 vis &= ~View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR;
6268 }
6269 }
6270 return vis;
6271 }
6272
John Spurlock79da8332013-09-20 12:04:47 -04006273 private int updateSystemBarsLw(WindowState win, int oldVis, int vis) {
John Spurlockbd957402013-10-03 11:38:39 -04006274 // apply translucent bar vis flags
Jorim Jaggi380ecb82014-03-14 17:25:20 +01006275 WindowState transWin = isStatusBarKeyguard() && !mHideLockScreen
6276 ? mStatusBar
John Spurlockbd957402013-10-03 11:38:39 -04006277 : mTopFullscreenOpaqueWindowState;
6278 vis = mStatusBarController.applyTranslucentFlagLw(transWin, vis, oldVis);
6279 vis = mNavigationBarController.applyTranslucentFlagLw(transWin, vis, oldVis);
6280
John Spurlock27735a42013-08-14 17:57:38 -04006281 // prevent status bar interaction from clearing certain flags
John Spurlock79da8332013-09-20 12:04:47 -04006282 boolean statusBarHasFocus = win.getAttrs().type == TYPE_STATUS_BAR;
John Spurlock08ffcf52014-07-11 10:13:46 -04006283 if (statusBarHasFocus && !isStatusBarKeyguard()) {
John Spurlockad3e6cb2013-04-30 08:47:43 -04006284 int flags = View.SYSTEM_UI_FLAG_FULLSCREEN
6285 | View.SYSTEM_UI_FLAG_HIDE_NAVIGATION
John Spurlockcfc359a2013-09-05 10:42:03 -04006286 | View.SYSTEM_UI_FLAG_IMMERSIVE
Jorim Jaggi73fef8d2015-02-16 17:32:28 +01006287 | View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY
6288 | View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR;
John Spurlock08ffcf52014-07-11 10:13:46 -04006289 if (mHideLockScreen) {
Jorim Jaggi5cf17872014-03-26 18:31:48 +01006290 flags |= View.STATUS_BAR_TRANSLUCENT | View.NAVIGATION_BAR_TRANSLUCENT;
6291 }
John Spurlockbd957402013-10-03 11:38:39 -04006292 vis = (vis & ~flags) | (oldVis & flags);
John Spurlockad3e6cb2013-04-30 08:47:43 -04006293 }
John Spurlockad3e6cb2013-04-30 08:47:43 -04006294
Adrian Roos4fb3ee32014-08-22 19:29:09 +02006295 if (!areTranslucentBarsAllowed() && transWin != mStatusBar) {
Adrian Roosea562512014-05-05 13:33:03 +02006296 vis &= ~(View.NAVIGATION_BAR_TRANSLUCENT | View.STATUS_BAR_TRANSLUCENT
6297 | View.SYSTEM_UI_TRANSPARENT);
Alan Viverette5a0f4ec2013-10-07 15:10:29 -07006298 }
6299
John Spurlock27735a42013-08-14 17:57:38 -04006300 // update status bar
John Spurlockf1a36642013-10-12 17:50:42 -04006301 boolean immersiveSticky =
6302 (vis & View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY) != 0;
John Spurlock27735a42013-08-14 17:57:38 -04006303 boolean hideStatusBarWM =
John Spurlockbd957402013-10-03 11:38:39 -04006304 mTopFullscreenOpaqueWindowState != null &&
John Spurlockc6d1c602014-01-17 15:22:06 -05006305 (PolicyControl.getWindowFlags(mTopFullscreenOpaqueWindowState, null)
John Spurlock27735a42013-08-14 17:57:38 -04006306 & WindowManager.LayoutParams.FLAG_FULLSCREEN) != 0;
6307 boolean hideStatusBarSysui =
6308 (vis & View.SYSTEM_UI_FLAG_FULLSCREEN) != 0;
John Spurlockf1a36642013-10-12 17:50:42 -04006309 boolean hideNavBarSysui =
6310 (vis & View.SYSTEM_UI_FLAG_HIDE_NAVIGATION) != 0;
John Spurlockad3e6cb2013-04-30 08:47:43 -04006311
John Spurlock27735a42013-08-14 17:57:38 -04006312 boolean transientStatusBarAllowed =
6313 mStatusBar != null && (
6314 hideStatusBarWM
John Spurlockf1a36642013-10-12 17:50:42 -04006315 || (hideStatusBarSysui && immersiveSticky)
John Spurlock27735a42013-08-14 17:57:38 -04006316 || statusBarHasFocus);
6317
John Spurlockf1a36642013-10-12 17:50:42 -04006318 boolean transientNavBarAllowed =
6319 mNavigationBar != null &&
6320 hideNavBarSysui && immersiveSticky;
6321
John Spurlockf25706f2013-11-07 18:02:43 -05006322 boolean denyTransientStatus = mStatusBarController.isTransientShowRequested()
John Spurlockf1a36642013-10-12 17:50:42 -04006323 && !transientStatusBarAllowed && hideStatusBarSysui;
John Spurlockf25706f2013-11-07 18:02:43 -05006324 boolean denyTransientNav = mNavigationBarController.isTransientShowRequested()
John Spurlockf1a36642013-10-12 17:50:42 -04006325 && !transientNavBarAllowed;
6326 if (denyTransientStatus || denyTransientNav) {
John Spurlock27735a42013-08-14 17:57:38 -04006327 // clear the clearable flags instead
John Spurlockf1a36642013-10-12 17:50:42 -04006328 clearClearableFlagsLw();
tiger_huangc58d7562014-10-23 20:24:19 +08006329 vis &= ~View.SYSTEM_UI_CLEARABLE_FLAGS;
John Spurlockad3e6cb2013-04-30 08:47:43 -04006330 }
John Spurlock27735a42013-08-14 17:57:38 -04006331
6332 vis = mStatusBarController.updateVisibilityLw(transientStatusBarAllowed, oldVis, vis);
6333
6334 // update navigation bar
John Spurlockf1a36642013-10-12 17:50:42 -04006335 boolean oldImmersiveMode = isImmersiveMode(oldVis);
6336 boolean newImmersiveMode = isImmersiveMode(vis);
6337 if (win != null && oldImmersiveMode != newImmersiveMode) {
John Spurlock79da8332013-09-20 12:04:47 -04006338 final String pkg = win.getOwningPackage();
Maurice Lam99c6e072014-04-28 18:24:28 -07006339 mImmersiveModeConfirmation.immersiveModeChanged(pkg, newImmersiveMode,
6340 isUserSetupComplete());
John Spurlock34e13d92013-08-10 06:52:28 -04006341 }
John Spurlock27735a42013-08-14 17:57:38 -04006342
John Spurlockf1a36642013-10-12 17:50:42 -04006343 vis = mNavigationBarController.updateVisibilityLw(transientNavBarAllowed, oldVis, vis);
6344
John Spurlocke1f366f2013-08-05 12:22:40 -04006345 return vis;
John Spurlockad3e6cb2013-04-30 08:47:43 -04006346 }
6347
John Spurlockf1a36642013-10-12 17:50:42 -04006348 private void clearClearableFlagsLw() {
6349 int newVal = mResettingSystemUiFlags | View.SYSTEM_UI_CLEARABLE_FLAGS;
6350 if (newVal != mResettingSystemUiFlags) {
6351 mResettingSystemUiFlags = newVal;
6352 mWindowManagerFuncs.reevaluateStatusBarVisibility();
6353 }
6354 }
6355
6356 private boolean isImmersiveMode(int vis) {
6357 final int flags = View.SYSTEM_UI_FLAG_IMMERSIVE | View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY;
John Spurlock34e13d92013-08-10 06:52:28 -04006358 return mNavigationBar != null
6359 && (vis & View.SYSTEM_UI_FLAG_HIDE_NAVIGATION) != 0
Daniel Sandler900ece52013-10-18 15:53:27 -04006360 && (vis & flags) != 0
6361 && canHideNavigationBar();
John Spurlock34e13d92013-08-10 06:52:28 -04006362 }
6363
Alan Viverette5a0f4ec2013-10-07 15:10:29 -07006364 /**
Daniel Sandlerdd73ee42013-10-11 22:19:59 -04006365 * @return whether the navigation or status bar can be made translucent
6366 *
6367 * This should return true unless touch exploration is not enabled or
6368 * R.boolean.config_enableTranslucentDecor is false.
Alan Viverette5a0f4ec2013-10-07 15:10:29 -07006369 */
Daniel Sandlerdd73ee42013-10-11 22:19:59 -04006370 private boolean areTranslucentBarsAllowed() {
Svetoslav8e3feb12014-02-24 13:46:47 -08006371 return mTranslucentDecorEnabled
6372 && !mAccessibilityManager.isTouchExplorationEnabled();
Alan Viverette5a0f4ec2013-10-07 15:10:29 -07006373 }
6374
Daniel Sandler0c4ccff2011-10-19 16:39:14 -04006375 // Use this instead of checking config_showNavigationBar so that it can be consistently
6376 // overridden by qemu.hw.mainkeys in the emulator.
Craig Mautnereda67292013-04-28 13:50:14 -07006377 @Override
Daniel Sandler0c4ccff2011-10-19 16:39:14 -04006378 public boolean hasNavigationBar() {
6379 return mHasNavigationBar;
6380 }
6381
satok1bc0a492012-04-25 22:47:12 +09006382 @Override
6383 public void setLastInputMethodWindowLw(WindowState ime, WindowState target) {
6384 mLastInputMethodWindow = ime;
6385 mLastInputMethodTargetWindow = target;
6386 }
6387
Craig Mautnerf1b67412012-09-19 13:18:29 -07006388 @Override
Satoshi Kataoka658c7b82013-10-10 17:03:51 +09006389 public int getInputMethodWindowVisibleHeightLw() {
6390 return mDockBottom - mCurBottom;
6391 }
6392
6393 @Override
Craig Mautnerf1b67412012-09-19 13:18:29 -07006394 public void setCurrentUserLw(int newUserId) {
Craig Mautnerd625ab22013-09-06 13:40:31 -07006395 mCurrentUserId = newUserId;
Jim Miller5ecd8112013-01-09 18:50:26 -08006396 if (mKeyguardDelegate != null) {
6397 mKeyguardDelegate.setCurrentUser(newUserId);
Craig Mautnerf1b67412012-09-19 13:18:29 -07006398 }
John Spurlock13451a22012-09-28 14:40:41 -04006399 if (mStatusBarService != null) {
6400 try {
6401 mStatusBarService.setCurrentUser(newUserId);
6402 } catch (RemoteException e) {
6403 // oh well
6404 }
6405 }
Dianne Hackborn2ea9bae2012-11-02 18:43:48 -07006406 setLastInputMethodWindowLw(null, null);
Craig Mautnerf1b67412012-09-19 13:18:29 -07006407 }
6408
6409 @Override
Svetoslav Ganov545252f2012-12-10 18:29:24 -08006410 public boolean canMagnifyWindow(int windowType) {
6411 switch (windowType) {
6412 case WindowManager.LayoutParams.TYPE_INPUT_METHOD:
6413 case WindowManager.LayoutParams.TYPE_INPUT_METHOD_DIALOG:
6414 case WindowManager.LayoutParams.TYPE_NAVIGATION_BAR:
6415 case WindowManager.LayoutParams.TYPE_MAGNIFICATION_OVERLAY: {
6416 return false;
6417 }
6418 }
6419 return true;
6420 }
6421
6422 @Override
6423 public boolean isTopLevelWindow(int windowType) {
6424 if (windowType >= WindowManager.LayoutParams.FIRST_SUB_WINDOW
6425 && windowType <= WindowManager.LayoutParams.LAST_SUB_WINDOW) {
6426 return (windowType == WindowManager.LayoutParams.TYPE_APPLICATION_ATTACHED_DIALOG);
6427 }
6428 return true;
6429 }
6430
Jim Miller4eeb4f62012-11-08 00:04:29 -08006431 @Override
Jeff Brownd7a04de2012-06-17 14:17:52 -07006432 public void dump(String prefix, PrintWriter pw, String[] args) {
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08006433 pw.print(prefix); pw.print("mSafeMode="); pw.print(mSafeMode);
Dianne Hackbornba24e4d2011-09-01 11:17:06 -07006434 pw.print(" mSystemReady="); pw.print(mSystemReady);
6435 pw.print(" mSystemBooted="); pw.println(mSystemBooted);
Jeff Brown2e7760e2012-04-11 15:14:55 -07006436 pw.print(prefix); pw.print("mLidState="); pw.print(mLidState);
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08006437 pw.print(" mLidOpenRotation="); pw.print(mLidOpenRotation);
Michael Wright3818c922014-09-02 13:59:07 -07006438 pw.print(" mCameraLensCoverState="); pw.print(mCameraLensCoverState);
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08006439 pw.print(" mHdmiPlugged="); pw.println(mHdmiPlugged);
Dianne Hackborne26ab702011-10-16 13:21:33 -07006440 if (mLastSystemUiFlags != 0 || mResettingSystemUiFlags != 0
6441 || mForceClearedSystemUiFlags != 0) {
6442 pw.print(prefix); pw.print("mLastSystemUiFlags=0x");
6443 pw.print(Integer.toHexString(mLastSystemUiFlags));
6444 pw.print(" mResettingSystemUiFlags=0x");
6445 pw.print(Integer.toHexString(mResettingSystemUiFlags));
6446 pw.print(" mForceClearedSystemUiFlags=0x");
6447 pw.println(Integer.toHexString(mForceClearedSystemUiFlags));
Dianne Hackborndf89e652011-10-06 22:35:11 -07006448 }
Dianne Hackborn4eff8d32011-11-10 19:38:40 -08006449 if (mLastFocusNeedsMenu) {
6450 pw.print(prefix); pw.print("mLastFocusNeedsMenu=");
6451 pw.println(mLastFocusNeedsMenu);
6452 }
Jeff Browna20dda42014-05-27 20:57:24 -07006453 pw.print(prefix); pw.print("mWakeGestureEnabledSetting=");
6454 pw.println(mWakeGestureEnabledSetting);
6455
Jeff Brownbcdfc622014-03-06 19:13:04 -08006456 pw.print(prefix); pw.print("mSupportAutoRotation="); pw.println(mSupportAutoRotation);
Daniel Sandler6396c722013-04-16 20:19:09 -04006457 pw.print(prefix); pw.print("mUiMode="); pw.print(mUiMode);
6458 pw.print(" mDockMode="); pw.print(mDockMode);
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08006459 pw.print(" mCarDockRotation="); pw.print(mCarDockRotation);
6460 pw.print(" mDeskDockRotation="); pw.println(mDeskDockRotation);
6461 pw.print(prefix); pw.print("mUserRotationMode="); pw.print(mUserRotationMode);
6462 pw.print(" mUserRotation="); pw.print(mUserRotation);
Daniel Sandler2ed6ad62011-02-22 14:54:17 -05006463 pw.print(" mAllowAllRotations="); pw.println(mAllowAllRotations);
Dianne Hackborn6e2281d2012-06-19 17:48:32 -07006464 pw.print(prefix); pw.print("mCurrentAppOrientation="); pw.println(mCurrentAppOrientation);
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08006465 pw.print(prefix); pw.print("mCarDockEnablesAccelerometer=");
6466 pw.print(mCarDockEnablesAccelerometer);
6467 pw.print(" mDeskDockEnablesAccelerometer=");
6468 pw.println(mDeskDockEnablesAccelerometer);
6469 pw.print(prefix); pw.print("mLidKeyboardAccessibility=");
6470 pw.print(mLidKeyboardAccessibility);
6471 pw.print(" mLidNavigationAccessibility="); pw.print(mLidNavigationAccessibility);
Dianne Hackborn6e2281d2012-06-19 17:48:32 -07006472 pw.print(" mLidControlsSleep="); pw.println(mLidControlsSleep);
Jeff Brown6d8fd272014-05-20 21:24:38 -07006473 pw.print(prefix);
6474 pw.print("mShortPressOnPowerBehavior="); pw.print(mShortPressOnPowerBehavior);
6475 pw.print(" mLongPressOnPowerBehavior="); pw.println(mLongPressOnPowerBehavior);
Jeff Brown13f00f02014-10-31 14:45:50 -07006476 pw.print(prefix);
6477 pw.print("mDoublePressOnPowerBehavior="); pw.print(mDoublePressOnPowerBehavior);
6478 pw.print(" mTriplePressOnPowerBehavior="); pw.println(mTriplePressOnPowerBehavior);
Jeff Brown6d8fd272014-05-20 21:24:38 -07006479 pw.print(prefix); pw.print("mHasSoftInput="); pw.println(mHasSoftInput);
Jeff Brown3ee549c2014-09-22 20:14:39 -07006480 pw.print(prefix); pw.print("mAwake="); pw.println(mAwake);
6481 pw.print(prefix); pw.print("mScreenOnEarly="); pw.print(mScreenOnEarly);
6482 pw.print(" mScreenOnFully="); pw.println(mScreenOnFully);
6483 pw.print(prefix); pw.print("mKeyguardDrawComplete="); pw.print(mKeyguardDrawComplete);
6484 pw.print(" mWindowManagerDrawComplete="); pw.println(mWindowManagerDrawComplete);
6485 pw.print(prefix); pw.print("mOrientationSensorEnabled=");
6486 pw.println(mOrientationSensorEnabled);
Dianne Hackbornc652de82013-02-15 16:32:56 -08006487 pw.print(prefix); pw.print("mOverscanScreen=("); pw.print(mOverscanScreenLeft);
6488 pw.print(","); pw.print(mOverscanScreenTop);
6489 pw.print(") "); pw.print(mOverscanScreenWidth);
6490 pw.print("x"); pw.println(mOverscanScreenHeight);
6491 if (mOverscanLeft != 0 || mOverscanTop != 0
6492 || mOverscanRight != 0 || mOverscanBottom != 0) {
6493 pw.print(prefix); pw.print("mOverscan left="); pw.print(mOverscanLeft);
6494 pw.print(" top="); pw.print(mOverscanTop);
6495 pw.print(" right="); pw.print(mOverscanRight);
6496 pw.print(" bottom="); pw.println(mOverscanBottom);
6497 }
Dianne Hackborn313440842013-02-19 19:22:59 -08006498 pw.print(prefix); pw.print("mRestrictedOverscanScreen=(");
6499 pw.print(mRestrictedOverscanScreenLeft);
6500 pw.print(","); pw.print(mRestrictedOverscanScreenTop);
6501 pw.print(") "); pw.print(mRestrictedOverscanScreenWidth);
6502 pw.print("x"); pw.println(mRestrictedOverscanScreenHeight);
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08006503 pw.print(prefix); pw.print("mUnrestrictedScreen=("); pw.print(mUnrestrictedScreenLeft);
6504 pw.print(","); pw.print(mUnrestrictedScreenTop);
6505 pw.print(") "); pw.print(mUnrestrictedScreenWidth);
6506 pw.print("x"); pw.println(mUnrestrictedScreenHeight);
6507 pw.print(prefix); pw.print("mRestrictedScreen=("); pw.print(mRestrictedScreenLeft);
6508 pw.print(","); pw.print(mRestrictedScreenTop);
6509 pw.print(") "); pw.print(mRestrictedScreenWidth);
6510 pw.print("x"); pw.println(mRestrictedScreenHeight);
Dianne Hackborn5b5cc4d2012-05-16 13:15:00 -07006511 pw.print(prefix); pw.print("mStableFullscreen=("); pw.print(mStableFullscreenLeft);
6512 pw.print(","); pw.print(mStableFullscreenTop);
6513 pw.print(")-("); pw.print(mStableFullscreenRight);
6514 pw.print(","); pw.print(mStableFullscreenBottom); pw.println(")");
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07006515 pw.print(prefix); pw.print("mStable=("); pw.print(mStableLeft);
6516 pw.print(","); pw.print(mStableTop);
6517 pw.print(")-("); pw.print(mStableRight);
6518 pw.print(","); pw.print(mStableBottom); pw.println(")");
Dianne Hackborn5c58de32012-04-28 19:52:37 -07006519 pw.print(prefix); pw.print("mSystem=("); pw.print(mSystemLeft);
6520 pw.print(","); pw.print(mSystemTop);
6521 pw.print(")-("); pw.print(mSystemRight);
6522 pw.print(","); pw.print(mSystemBottom); pw.println(")");
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08006523 pw.print(prefix); pw.print("mCur=("); pw.print(mCurLeft);
6524 pw.print(","); pw.print(mCurTop);
6525 pw.print(")-("); pw.print(mCurRight);
6526 pw.print(","); pw.print(mCurBottom); pw.println(")");
6527 pw.print(prefix); pw.print("mContent=("); pw.print(mContentLeft);
6528 pw.print(","); pw.print(mContentTop);
6529 pw.print(")-("); pw.print(mContentRight);
6530 pw.print(","); pw.print(mContentBottom); pw.println(")");
Dianne Hackborne30e02f2014-05-27 18:24:45 -07006531 pw.print(prefix); pw.print("mVoiceContent=("); pw.print(mVoiceContentLeft);
6532 pw.print(","); pw.print(mVoiceContentTop);
6533 pw.print(")-("); pw.print(mVoiceContentRight);
6534 pw.print(","); pw.print(mVoiceContentBottom); pw.println(")");
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08006535 pw.print(prefix); pw.print("mDock=("); pw.print(mDockLeft);
6536 pw.print(","); pw.print(mDockTop);
6537 pw.print(")-("); pw.print(mDockRight);
6538 pw.print(","); pw.print(mDockBottom); pw.println(")");
Dianne Hackborn5c58de32012-04-28 19:52:37 -07006539 pw.print(prefix); pw.print("mDockLayer="); pw.print(mDockLayer);
6540 pw.print(" mStatusBarLayer="); pw.println(mStatusBarLayer);
Dianne Hackborn7ad44382012-10-18 17:46:00 -07006541 pw.print(prefix); pw.print("mShowingLockscreen="); pw.print(mShowingLockscreen);
6542 pw.print(" mShowingDream="); pw.print(mShowingDream);
Jeff Brown061ea992015-04-17 19:55:47 -07006543 pw.print(" mDreamingLockscreen="); pw.print(mDreamingLockscreen);
6544 pw.print(" mDreamingSleepToken="); pw.println(mDreamingSleepToken);
Dianne Hackborn2ea9bae2012-11-02 18:43:48 -07006545 if (mLastInputMethodWindow != null) {
6546 pw.print(prefix); pw.print("mLastInputMethodWindow=");
6547 pw.println(mLastInputMethodWindow);
6548 }
6549 if (mLastInputMethodTargetWindow != null) {
6550 pw.print(prefix); pw.print("mLastInputMethodTargetWindow=");
6551 pw.println(mLastInputMethodTargetWindow);
6552 }
6553 if (mStatusBar != null) {
6554 pw.print(prefix); pw.print("mStatusBar=");
Dianne Hackbornae6688b2015-02-11 17:02:41 -08006555 pw.print(mStatusBar); pw.print(" isStatusBarKeyguard=");
6556 pw.println(isStatusBarKeyguard());
Dianne Hackborn2ea9bae2012-11-02 18:43:48 -07006557 }
6558 if (mNavigationBar != null) {
6559 pw.print(prefix); pw.print("mNavigationBar=");
6560 pw.println(mNavigationBar);
6561 }
Dianne Hackborn2ea9bae2012-11-02 18:43:48 -07006562 if (mFocusedWindow != null) {
6563 pw.print(prefix); pw.print("mFocusedWindow=");
6564 pw.println(mFocusedWindow);
6565 }
6566 if (mFocusedApp != null) {
6567 pw.print(prefix); pw.print("mFocusedApp=");
6568 pw.println(mFocusedApp);
6569 }
6570 if (mWinDismissingKeyguard != null) {
6571 pw.print(prefix); pw.print("mWinDismissingKeyguard=");
6572 pw.println(mWinDismissingKeyguard);
6573 }
6574 if (mTopFullscreenOpaqueWindowState != null) {
6575 pw.print(prefix); pw.print("mTopFullscreenOpaqueWindowState=");
6576 pw.println(mTopFullscreenOpaqueWindowState);
6577 }
Adrian Rooscd3884d2015-02-18 17:25:23 +01006578 if (mTopFullscreenOpaqueOrDimmingWindowState != null) {
6579 pw.print(prefix); pw.print("mTopFullscreenOpaqueOrDimmingWindowState=");
6580 pw.println(mTopFullscreenOpaqueOrDimmingWindowState);
6581 }
Dianne Hackborn891d3fb2013-01-09 18:31:37 -08006582 if (mForcingShowNavBar) {
6583 pw.print(prefix); pw.print("mForcingShowNavBar=");
6584 pw.println(mForcingShowNavBar); pw.print( "mForcingShowNavBarLayer=");
6585 pw.println(mForcingShowNavBarLayer);
6586 }
Dianne Hackborn7ad44382012-10-18 17:46:00 -07006587 pw.print(prefix); pw.print("mTopIsFullscreen="); pw.print(mTopIsFullscreen);
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08006588 pw.print(" mHideLockScreen="); pw.println(mHideLockScreen);
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07006589 pw.print(prefix); pw.print("mForceStatusBar="); pw.print(mForceStatusBar);
6590 pw.print(" mForceStatusBarFromKeyguard=");
6591 pw.println(mForceStatusBarFromKeyguard);
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08006592 pw.print(prefix); pw.print("mDismissKeyguard="); pw.print(mDismissKeyguard);
Craig Mautnerad09bcc2012-10-08 13:33:11 -07006593 pw.print(" mWinDismissingKeyguard="); pw.print(mWinDismissingKeyguard);
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08006594 pw.print(" mHomePressed="); pw.println(mHomePressed);
6595 pw.print(prefix); pw.print("mAllowLockscreenWhenOn="); pw.print(mAllowLockscreenWhenOn);
6596 pw.print(" mLockScreenTimeout="); pw.print(mLockScreenTimeout);
6597 pw.print(" mLockScreenTimerActive="); pw.println(mLockScreenTimerActive);
6598 pw.print(prefix); pw.print("mEndcallBehavior="); pw.print(mEndcallBehavior);
6599 pw.print(" mIncallPowerBehavior="); pw.print(mIncallPowerBehavior);
6600 pw.print(" mLongPressOnHomeBehavior="); pw.println(mLongPressOnHomeBehavior);
6601 pw.print(prefix); pw.print("mLandscapeRotation="); pw.print(mLandscapeRotation);
6602 pw.print(" mSeascapeRotation="); pw.println(mSeascapeRotation);
6603 pw.print(prefix); pw.print("mPortraitRotation="); pw.print(mPortraitRotation);
6604 pw.print(" mUpsideDownRotation="); pw.println(mUpsideDownRotation);
Jeff Brownc82c89ed2013-04-17 17:18:15 -07006605 pw.print(prefix); pw.print("mDemoHdmiRotation="); pw.print(mDemoHdmiRotation);
6606 pw.print(" mDemoHdmiRotationLock="); pw.println(mDemoHdmiRotationLock);
6607 pw.print(prefix); pw.print("mUndockedHdmiRotation="); pw.println(mUndockedHdmiRotation);
Jeff Brown600f0032014-05-22 17:06:00 -07006608
Tim Kilbournd7c0c2e2014-05-29 16:08:10 -07006609 mGlobalKeyManager.dump(prefix, pw);
John Spurlock27735a42013-08-14 17:57:38 -04006610 mStatusBarController.dump(pw, prefix);
6611 mNavigationBarController.dump(pw, prefix);
John Spurlockc6d1c602014-01-17 15:22:06 -05006612 PolicyControl.dump(prefix, pw);
Jeff Brown600f0032014-05-22 17:06:00 -07006613
Jeff Browna20dda42014-05-27 20:57:24 -07006614 if (mWakeGestureListener != null) {
6615 mWakeGestureListener.dump(pw, prefix);
6616 }
Jeff Brown600f0032014-05-22 17:06:00 -07006617 if (mOrientationListener != null) {
6618 mOrientationListener.dump(pw, prefix);
6619 }
Filip Gruszczynskicfb31852015-02-25 21:47:12 +00006620 if (mBurnInProtectionHelper != null) {
6621 mBurnInProtectionHelper.dump(prefix, pw);
6622 }
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08006623 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006624}