blob: 9bb5e404a90713f6a95a1d5b01b4599c29500b86 [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;
Dianne Hackborn38e29a62011-09-18 14:43:08 -070054import android.os.Bundle;
Craig Mautner276a6eb2014-11-04 15:32:57 -080055import android.os.Debug;
Jeff Brown9a538ee2012-08-20 14:56:57 -070056import android.os.FactoryTest;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -080057import android.os.Handler;
58import android.os.IBinder;
Jeff Brown32cbc38552011-12-01 14:01:49 -080059import android.os.Looper;
Dianne Hackbornfc8fa632011-08-17 16:20:47 -070060import android.os.Message;
61import android.os.Messenger;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -080062import android.os.PowerManager;
63import android.os.RemoteException;
64import android.os.ServiceManager;
65import android.os.SystemClock;
66import android.os.SystemProperties;
Dianne Hackbornad7fa7f2011-01-07 14:06:50 -080067import android.os.UEventObserver;
Dianne Hackbornf02b60a2012-08-16 10:48:27 -070068import android.os.UserHandle;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -080069import android.os.Vibrator;
Michael Wright3818c922014-09-02 13:59:07 -070070import android.provider.MediaStore;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -080071import android.provider.Settings;
Jose Lima9546b202014-07-02 17:21:51 -070072import android.service.dreams.DreamManagerInternal;
John Spurlockc8b46ca2013-04-08 12:59:26 -040073import android.service.dreams.DreamService;
74import android.service.dreams.IDreamManager;
Michael Wrightdc63f7b2014-08-21 19:05:21 -070075import android.speech.RecognizerIntent;
Tyler Gunnef9f6f92014-09-12 22:16:17 -070076import android.telecom.TelecomManager;
Dianne Hackborn81e56d52011-05-26 00:55:58 -070077import android.util.DisplayMetrics;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -080078import android.util.EventLog;
79import android.util.Log;
Jeff Browna41ca772010-08-11 14:46:32 -070080import android.util.Slog;
Jeff Brown6651a632011-11-28 12:59:11 -080081import android.util.SparseArray;
Dianne Hackbornf87d1962012-04-04 12:48:24 -070082import android.view.Display;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -080083import android.view.Gravity;
84import android.view.HapticFeedbackConstants;
Dianne Hackborne0f085d2011-11-30 18:41:15 -080085import android.view.IApplicationToken;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -080086import android.view.IWindowManager;
Jeff Browna41ca772010-08-11 14:46:32 -070087import android.view.InputChannel;
Jeff Brown4d396052010-10-29 21:50:21 -070088import android.view.InputDevice;
Jeff Brown4952dfd2011-11-30 19:23:22 -080089import android.view.InputEvent;
Jeff Brown32cbc38552011-12-01 14:01:49 -080090import android.view.InputEventReceiver;
Jeff Brown6b53e8d2010-11-10 16:03:06 -080091import android.view.KeyCharacterMap;
Craig Mautnerae446592012-12-06 19:05:05 -080092import android.view.KeyCharacterMap.FallbackAction;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -080093import android.view.KeyEvent;
94import android.view.MotionEvent;
Adam Powell6711f3b2015-05-06 15:57:09 -070095import com.android.internal.policy.PhoneWindow;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -080096import android.view.Surface;
97import android.view.View;
98import android.view.ViewConfiguration;
99import android.view.Window;
100import android.view.WindowManager;
Craig Mautnerae446592012-12-06 19:05:05 -0800101import android.view.WindowManagerGlobal;
Craig Mautner8a0da012014-05-31 15:13:37 -0700102import android.view.WindowManagerInternal;
Craig Mautnerae446592012-12-06 19:05:05 -0800103import android.view.WindowManagerPolicy;
Craig Mautnerae446592012-12-06 19:05:05 -0800104import android.view.accessibility.AccessibilityEvent;
Svetoslav8e3feb12014-02-24 13:46:47 -0800105import android.view.accessibility.AccessibilityManager;
Craig Mautnerae446592012-12-06 19:05:05 -0800106import android.view.animation.Animation;
Jorim Jaggi76a16232014-08-08 17:00:47 +0200107import android.view.animation.AnimationSet;
Craig Mautnerae446592012-12-06 19:05:05 -0800108import android.view.animation.AnimationUtils;
Craig Mautnerae446592012-12-06 19:05:05 -0800109import com.android.internal.R;
Craig Mautnerae446592012-12-06 19:05:05 -0800110import com.android.internal.statusbar.IStatusBarService;
Craig Mautnerae446592012-12-06 19:05:05 -0800111import com.android.internal.widget.PointerLocationView;
Craig Mautner8a0da012014-05-31 15:13:37 -0700112import com.android.server.LocalServices;
Jorim Jaggib10e33f2015-02-04 21:57:40 +0100113import com.android.server.policy.keyguard.KeyguardServiceDelegate;
114import com.android.server.policy.keyguard.KeyguardServiceDelegate.ShowListener;
Craig Mautnerae446592012-12-06 19:05:05 -0800115
116import java.io.File;
117import java.io.FileReader;
118import java.io.IOException;
119import java.io.PrintWriter;
Craig Mautner2bc789b2014-03-19 19:48:38 -0700120import java.util.HashSet;
Craig Mautner276a6eb2014-11-04 15:32:57 -0800121import java.util.List;
Craig Mautnerae446592012-12-06 19:05:05 -0800122
Dianne Hackbornc652de82013-02-15 16:32:56 -0800123import static android.view.WindowManager.LayoutParams.*;
Jeff Brownac143512012-04-05 18:57:33 -0700124import static android.view.WindowManagerPolicy.WindowManagerFuncs.LID_ABSENT;
125import static android.view.WindowManagerPolicy.WindowManagerFuncs.LID_OPEN;
126import static android.view.WindowManagerPolicy.WindowManagerFuncs.LID_CLOSED;
Michael Wright3818c922014-09-02 13:59:07 -0700127import static android.view.WindowManagerPolicy.WindowManagerFuncs.CAMERA_LENS_COVER_ABSENT;
128import static android.view.WindowManagerPolicy.WindowManagerFuncs.CAMERA_LENS_UNCOVERED;
129import static android.view.WindowManagerPolicy.WindowManagerFuncs.CAMERA_LENS_COVERED;
Dianne Hackborn08743722009-12-21 12:16:51 -0800130
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800131/**
The Android Open Source Project0727d222009-03-11 12:11:58 -0700132 * WindowManagerPolicy implementation for the Android phone UI. This
133 * introduces a new method suffix, Lp, for an internal lock of the
134 * PhoneWindowManager. This is used to protect some internal state, and
John Spurlock04db1762013-05-13 12:46:41 -0400135 * 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 -0700136 * of both of those when held.
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800137 */
138public class PhoneWindowManager implements WindowManagerPolicy {
139 static final String TAG = "WindowManager";
140 static final boolean DEBUG = false;
Joe Onorato43a17652011-04-06 19:22:23 -0700141 static final boolean localLOGV = false;
Jeff Brown40013652012-05-16 21:22:36 -0700142 static final boolean DEBUG_INPUT = false;
Craig Mautnerc0d2d0a2014-10-31 16:25:15 -0700143 static final boolean DEBUG_KEYGUARD = false;
144 static final boolean DEBUG_LAYOUT = false;
Craig Mautner6fbda632012-07-03 09:26:39 -0700145 static final boolean DEBUG_STARTING_WINDOW = false;
Craig Mautner8a0da012014-05-31 15:13:37 -0700146 static final boolean DEBUG_WAKEUP = false;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800147 static final boolean SHOW_STARTING_ANIMATIONS = true;
148 static final boolean SHOW_PROCESSES_ON_ALT_MENU = false;
Joe Onoratod208e702010-10-08 16:22:43 -0400149
Daniel Sandler6396c722013-04-16 20:19:09 -0400150 // Whether to allow dock apps with METADATA_DOCK_HOME to temporarily take over the Home key.
151 // No longer recommended for desk docks; still useful in car docks.
152 static final boolean ENABLE_CAR_DOCK_HOME_CAPTURE = true;
153 static final boolean ENABLE_DESK_DOCK_HOME_CAPTURE = false;
154
Jeff Brown6d8fd272014-05-20 21:24:38 -0700155 static final int SHORT_PRESS_POWER_NOTHING = 0;
156 static final int SHORT_PRESS_POWER_GO_TO_SLEEP = 1;
157 static final int SHORT_PRESS_POWER_REALLY_GO_TO_SLEEP = 2;
158 static final int SHORT_PRESS_POWER_REALLY_GO_TO_SLEEP_AND_GO_HOME = 3;
Bryce Lee01b0c5f2015-02-05 18:24:04 -0800159 static final int SHORT_PRESS_POWER_GO_HOME = 4;
Jeff Brown6d8fd272014-05-20 21:24:38 -0700160
Joe Onoratod208e702010-10-08 16:22:43 -0400161 static final int LONG_PRESS_POWER_NOTHING = 0;
162 static final int LONG_PRESS_POWER_GLOBAL_ACTIONS = 1;
163 static final int LONG_PRESS_POWER_SHUT_OFF = 2;
Jeff Brown9a538ee2012-08-20 14:56:57 -0700164 static final int LONG_PRESS_POWER_SHUT_OFF_NO_CONFIRM = 3;
Michael Jurka3b1fc472011-06-13 10:54:40 -0700165
Jeff Brown13f00f02014-10-31 14:45:50 -0700166 static final int MULTI_PRESS_POWER_NOTHING = 0;
167 static final int MULTI_PRESS_POWER_THEATER_MODE = 1;
168 static final int MULTI_PRESS_POWER_BRIGHTNESS_BOOST = 2;
169
Michael Jurka3b1fc472011-06-13 10:54:40 -0700170 // These need to match the documentation/constant in
171 // core/res/res/values/config.xml
Joe Onorato46b0d682010-11-22 17:37:27 -0800172 static final int LONG_PRESS_HOME_NOTHING = 0;
Michael Wrightc9ebea72013-01-16 19:25:02 -0800173 static final int LONG_PRESS_HOME_RECENT_SYSTEM_UI = 1;
Jeff Browncaca8812013-05-09 13:34:33 -0700174 static final int LONG_PRESS_HOME_ASSIST = 2;
175
176 static final int DOUBLE_TAP_HOME_NOTHING = 0;
177 static final int DOUBLE_TAP_HOME_RECENT_SYSTEM_UI = 1;
Joe Onorato46b0d682010-11-22 17:37:27 -0800178
Filip Gruszczynskia483a1d2015-03-17 19:06:58 +0000179 static final int SHORT_PRESS_SLEEP_GO_TO_SLEEP = 0;
180 static final int SHORT_PRESS_SLEEP_GO_TO_SLEEP_AND_GO_HOME = 1;
181
Dianne Hackborn5cb8d792009-05-21 17:34:15 -0700182 static final int APPLICATION_MEDIA_SUBLAYER = -2;
183 static final int APPLICATION_MEDIA_OVERLAY_SUBLAYER = -1;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800184 static final int APPLICATION_PANEL_SUBLAYER = 1;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800185 static final int APPLICATION_SUB_PANEL_SUBLAYER = 2;
Wale Ogunwale0a4dc222015-04-14 12:58:42 -0700186 static final int APPLICATION_ABOVE_SUB_PANEL_SUBLAYER = 3;
Craig Mautner88400d32012-09-30 12:35:45 -0700187
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800188 static public final String SYSTEM_DIALOG_REASON_KEY = "reason";
189 static public final String SYSTEM_DIALOG_REASON_GLOBAL_ACTIONS = "globalactions";
190 static public final String SYSTEM_DIALOG_REASON_RECENT_APPS = "recentapps";
Joe Onoratof275f0c2009-11-24 16:11:13 -0500191 static public final String SYSTEM_DIALOG_REASON_HOME_KEY = "homekey";
Jeff Brownde7a8ea2012-06-13 18:28:57 -0700192 static public final String SYSTEM_DIALOG_REASON_ASSIST = "assist";
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800193
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -0700194 /**
195 * These are the system UI flags that, when changing, can cause the layout
196 * of the screen to change.
197 */
198 static final int SYSTEM_UI_CHANGING_LAYOUT =
John Spurlocke1f366f2013-08-05 12:22:40 -0400199 View.SYSTEM_UI_FLAG_HIDE_NAVIGATION
John Spurlock7f4820a2013-10-08 12:54:35 -0400200 | View.SYSTEM_UI_FLAG_FULLSCREEN
201 | View.STATUS_BAR_TRANSLUCENT
Adrian Roosea562512014-05-05 13:33:03 +0200202 | View.NAVIGATION_BAR_TRANSLUCENT
203 | View.SYSTEM_UI_TRANSPARENT;
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -0700204
John Spurlock7b414672014-07-18 13:02:39 -0400205 private static final AudioAttributes VIBRATION_ATTRIBUTES = new AudioAttributes.Builder()
206 .setContentType(AudioAttributes.CONTENT_TYPE_SONIFICATION)
207 .setUsage(AudioAttributes.USAGE_ASSISTANCE_SONIFICATION)
208 .build();
209
Jim Miller5ecd8112013-01-09 18:50:26 -0800210 /**
211 * Keyguard stuff
212 */
213 private WindowState mKeyguardScrim;
Jorim Jaggi380ecb82014-03-14 17:25:20 +0100214 private boolean mKeyguardHidden;
Jeff Brown3ee549c2014-09-22 20:14:39 -0700215 private boolean mKeyguardDrawnOnce;
Jim Miller5ecd8112013-01-09 18:50:26 -0800216
Jeff Brown6651a632011-11-28 12:59:11 -0800217 /* Table of Application Launch keys. Maps from key codes to intent categories.
218 *
219 * These are special keys that are used to launch particular kinds of applications,
220 * such as a web browser. HID defines nearly a hundred of them in the Consumer (0x0C)
221 * usage page. We don't support quite that many yet...
222 */
223 static SparseArray<String> sApplicationLaunchKeyCategories;
224 static {
225 sApplicationLaunchKeyCategories = new SparseArray<String>();
226 sApplicationLaunchKeyCategories.append(
227 KeyEvent.KEYCODE_EXPLORER, Intent.CATEGORY_APP_BROWSER);
228 sApplicationLaunchKeyCategories.append(
229 KeyEvent.KEYCODE_ENVELOPE, Intent.CATEGORY_APP_EMAIL);
230 sApplicationLaunchKeyCategories.append(
231 KeyEvent.KEYCODE_CONTACTS, Intent.CATEGORY_APP_CONTACTS);
232 sApplicationLaunchKeyCategories.append(
233 KeyEvent.KEYCODE_CALENDAR, Intent.CATEGORY_APP_CALENDAR);
234 sApplicationLaunchKeyCategories.append(
235 KeyEvent.KEYCODE_MUSIC, Intent.CATEGORY_APP_MUSIC);
236 sApplicationLaunchKeyCategories.append(
237 KeyEvent.KEYCODE_CALCULATOR, Intent.CATEGORY_APP_CALCULATOR);
238 }
239
Craig Mautnerc3daedd2014-09-13 11:17:23 -0700240 /** Amount of time (in milliseconds) to wait for windows drawn before powering on. */
241 static final int WAITING_FOR_DRAWN_TIMEOUT = 1000;
242
Dianne Hackborndf89e652011-10-06 22:35:11 -0700243 /**
244 * Lock protecting internal state. Must not call out into window
245 * manager with lock held. (This lock will be acquired in places
246 * where the window manager is calling in with its own lock held.)
247 */
Craig Mautner0bf6ec92012-12-18 08:33:27 -0800248 private final Object mLock = new Object();
Dianne Hackborndf89e652011-10-06 22:35:11 -0700249
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800250 Context mContext;
251 IWindowManager mWindowManager;
Dianne Hackborndf89e652011-10-06 22:35:11 -0700252 WindowManagerFuncs mWindowManagerFuncs;
Craig Mautner8a0da012014-05-31 15:13:37 -0700253 WindowManagerInternal mWindowManagerInternal;
Jeff Brown96307042012-07-27 15:51:34 -0700254 PowerManager mPowerManager;
Jeff Brown061ea992015-04-17 19:55:47 -0700255 ActivityManagerInternal mActivityManagerInternal;
Jose Lima9546b202014-07-02 17:21:51 -0700256 DreamManagerInternal mDreamManagerInternal;
Joe Onorato93056472010-09-10 10:30:46 -0400257 IStatusBarService mStatusBarService;
Jeff Browncaca8812013-05-09 13:34:33 -0700258 boolean mPreloadedRecentApps;
Dianne Hackborn42e620c2012-06-24 13:20:51 -0700259 final Object mServiceAquireLock = new Object();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800260 Vibrator mVibrator; // Vibrator for giving feedback of orientation changes
Jeff Brownde7a8ea2012-06-13 18:28:57 -0700261 SearchManager mSearchManager;
Svetoslav8e3feb12014-02-24 13:46:47 -0800262 AccessibilityManager mAccessibilityManager;
Filip Gruszczynskicfb31852015-02-25 21:47:12 +0000263 BurnInProtectionHelper mBurnInProtectionHelper;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800264
Dianne Hackborn181ceb52009-08-27 22:16:40 -0700265 // Vibrator pattern for haptic feedback of a long press.
266 long[] mLongPressVibePattern;
Craig Mautner88400d32012-09-30 12:35:45 -0700267
Dianne Hackborn181ceb52009-08-27 22:16:40 -0700268 // Vibrator pattern for haptic feedback of virtual key press.
269 long[] mVirtualKeyVibePattern;
Craig Mautner967212c2013-04-13 21:10:58 -0700270
Amith Yamasanic33cb712010-02-10 15:21:49 -0800271 // Vibrator pattern for a short vibration.
272 long[] mKeyboardTapVibePattern;
273
Fabrice Di Meglioeeff63a2013-08-05 12:07:24 -0700274 // Vibrator pattern for a short vibration when tapping on an hour/minute tick of a Clock.
275 long[] mClockTickVibePattern;
276
Fabrice Di Megliobd9152f2013-10-01 11:21:31 -0700277 // Vibrator pattern for a short vibration when tapping on a day/month/year date of a Calendar.
278 long[] mCalendarDateVibePattern;
279
Dianne Hackbornb1a79802009-09-29 15:18:31 -0700280 // Vibrator pattern for haptic feedback during boot when safe mode is disabled.
281 long[] mSafeModeDisabledVibePattern;
Craig Mautner967212c2013-04-13 21:10:58 -0700282
Dianne Hackbornb1a79802009-09-29 15:18:31 -0700283 // Vibrator pattern for haptic feedback during boot when safe mode is enabled.
284 long[] mSafeModeEnabledVibePattern;
Romain Guy8154cd32010-03-29 14:41:15 -0700285
Mady Mellore82067b2015-04-30 09:58:35 -0700286 // Vibrator pattern for haptic feedback of a stylus button press.
287 long[] mStylusButtonPressVibePattern;
288
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800289 /** If true, hitting shift & menu will broadcast Intent.ACTION_BUG_REPORT */
290 boolean mEnableShiftMenuBugReports = false;
Mike Lockwoodd747dc82011-09-13 16:28:22 -0400291
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800292 boolean mSafeMode;
293 WindowState mStatusBar = null;
Dianne Hackborn69cb8752011-05-19 18:13:32 -0700294 int mStatusBarHeight;
Daniel Sandler8956dbb2011-04-22 07:55:02 -0400295 WindowState mNavigationBar = null;
Daniel Sandler36412a72011-08-04 09:35:13 -0400296 boolean mHasNavigationBar = false;
Dianne Hackbornf87d1962012-04-04 12:48:24 -0700297 boolean mCanHideNavigationBar = false;
Daniel Sandler4a066c52012-04-20 14:49:13 -0400298 boolean mNavigationBarCanMove = false; // can the navigation bar ever move to the side?
299 boolean mNavigationBarOnBottom = true; // is the navigation bar on the bottom *right now*?
300 int[] mNavigationBarHeightForRotation = new int[4];
301 int[] mNavigationBarWidthForRotation = new int[4];
Daniel Sandler8956dbb2011-04-22 07:55:02 -0400302
Craig Mautnera631d492014-08-05 15:16:01 -0700303 boolean mBootMessageNeedsHiding;
Jim Miller5ecd8112013-01-09 18:50:26 -0800304 KeyguardServiceDelegate mKeyguardDelegate;
Craig Mautner13f6ea72014-06-23 14:57:02 -0700305 final Runnable mWindowManagerDrawCallback = new Runnable() {
Craig Mautner8a0da012014-05-31 15:13:37 -0700306 @Override
Craig Mautner13f6ea72014-06-23 14:57:02 -0700307 public void run() {
Craig Mautner8a0da012014-05-31 15:13:37 -0700308 if (DEBUG_WAKEUP) Slog.i(TAG, "All windows ready for display!");
309 mHandler.sendEmptyMessage(MSG_WINDOW_MANAGER_DRAWN_COMPLETE);
310 }
311 };
312 final ShowListener mKeyguardDelegateCallback = new ShowListener() {
313 @Override
314 public void onShown(IBinder windowToken) {
315 if (DEBUG_WAKEUP) Slog.d(TAG, "mKeyguardDelegate.ShowListener.onShown.");
316 mHandler.sendEmptyMessage(MSG_KEYGUARD_DRAWN_COMPLETE);
317 }
318 };
319
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800320 GlobalActions mGlobalActions;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800321 Handler mHandler;
satok1bc0a492012-04-25 22:47:12 +0900322 WindowState mLastInputMethodWindow = null;
323 WindowState mLastInputMethodTargetWindow = null;
Jeff Brown4aed78b2011-01-14 17:36:55 -0800324
Jeff Brown13f00f02014-10-31 14:45:50 -0700325 // FIXME This state is shared between the input reader and handler thread.
326 // Technically it's broken and buggy but it has been like this for many years
327 // and we have not yet seen any problems. Someday we'll rewrite this logic
328 // so that only one thread is involved in handling input policy. Unfortunately
329 // it's on a critical path for power management so we can't just post the work to the
330 // handler thread. We'll need to resolve this someday by teaching the input dispatcher
331 // to hold wakelocks during dispatch and eliminating the critical path.
332 volatile boolean mPowerKeyHandled;
Bryce Leed9268e32014-11-17 17:40:59 -0800333 volatile boolean mBeganFromNonInteractive;
Jeff Brown13f00f02014-10-31 14:45:50 -0700334 volatile int mPowerKeyPressCounter;
335 volatile boolean mEndCallKeyHandled;
336
Winson Chungd42a6cf2014-06-03 16:24:04 -0700337 boolean mRecentsVisible;
Winson Chung1e8d71b2014-05-16 17:05:22 -0700338 int mRecentAppsHeldModifiers;
Jeff Browncf39bdf2012-05-18 14:41:19 -0700339 boolean mLanguageSwitchKeyPressed;
Jeff Brown68b909d2011-12-07 16:36:01 -0800340
Jeff Brown2e7760e2012-04-11 15:14:55 -0700341 int mLidState = LID_ABSENT;
Michael Wright3818c922014-09-02 13:59:07 -0700342 int mCameraLensCoverState = CAMERA_LENS_COVER_ABSENT;
Jeff Browndaa37532012-05-01 15:54:03 -0700343 boolean mHaveBuiltInKeyboard;
Jeff Brown4aed78b2011-01-14 17:36:55 -0800344
Dianne Hackbornc777e072010-02-12 13:07:59 -0800345 boolean mSystemReady;
Dianne Hackbornba24e4d2011-09-01 11:17:06 -0700346 boolean mSystemBooted;
Dianne Hackbornad7fa7f2011-01-07 14:06:50 -0800347 boolean mHdmiPlugged;
Jeff Brown4f5fa282014-06-12 19:19:15 -0700348 IUiModeManager mUiModeManager;
Daniel Sandler6396c722013-04-16 20:19:09 -0400349 int mUiMode;
Dianne Hackborn867ab6472010-04-29 13:28:56 -0700350 int mDockMode = Intent.EXTRA_DOCK_STATE_UNDOCKED;
Mike Lockwood1753f7f2009-08-24 14:49:07 -0700351 int mLidOpenRotation;
Mike Lockwood2d1efbd2009-09-16 12:15:53 -0400352 int mCarDockRotation;
353 int mDeskDockRotation;
Jeff Brownc82c89ed2013-04-17 17:18:15 -0700354 int mUndockedHdmiRotation;
355 int mDemoHdmiRotation;
356 boolean mDemoHdmiRotationLock;
Chong Zhangae6119ff2014-11-11 18:54:39 -0800357 int mDemoRotation;
358 boolean mDemoRotationLock;
Daniel Sandlerb73617d2010-08-17 00:41:00 -0400359
Jeff Browna20dda42014-05-27 20:57:24 -0700360 boolean mWakeGestureEnabledSetting;
361 MyWakeGestureListener mWakeGestureListener;
362
Craig Mautner46ac6fa2013-08-01 10:06:34 -0700363 // Default display does not rotate, apps that require non-default orientation will have to
364 // have the orientation emulated.
365 private boolean mForceDefaultOrientation = false;
366
Daniel Sandlerb73617d2010-08-17 00:41:00 -0400367 int mUserRotationMode = WindowManagerPolicy.USER_ROTATION_FREE;
368 int mUserRotation = Surface.ROTATION_0;
Jeff Brown207673cd2012-06-05 17:47:11 -0700369 boolean mAccelerometerDefault;
Daniel Sandlerb73617d2010-08-17 00:41:00 -0400370
Jeff Brownbcdfc622014-03-06 19:13:04 -0800371 boolean mSupportAutoRotation;
Jeff Brownd3187e32011-09-21 19:26:44 -0700372 int mAllowAllRotations = -1;
Mike Lockwoode9867d22009-09-20 01:59:02 -0400373 boolean mCarDockEnablesAccelerometer;
374 boolean mDeskDockEnablesAccelerometer;
Dianne Hackborn2862fff2009-09-15 22:56:29 -0700375 int mLidKeyboardAccessibility;
376 int mLidNavigationAccessibility;
Jeff Brownc458ce92012-04-30 14:58:40 -0700377 boolean mLidControlsSleep;
Jeff Brown13f00f02014-10-31 14:45:50 -0700378 int mShortPressOnPowerBehavior;
379 int mLongPressOnPowerBehavior;
380 int mDoublePressOnPowerBehavior;
381 int mTriplePressOnPowerBehavior;
Filip Gruszczynskia483a1d2015-03-17 19:06:58 +0000382 int mShortPressOnSleepBehavior;
Jeff Brown3ee549c2014-09-22 20:14:39 -0700383 boolean mAwake;
384 boolean mScreenOnEarly;
385 boolean mScreenOnFully;
386 ScreenOnListener mScreenOnListener;
387 boolean mKeyguardDrawComplete;
388 boolean mWindowManagerDrawComplete;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800389 boolean mOrientationSensorEnabled = false;
390 int mCurrentAppOrientation = ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800391 boolean mHasSoftInput = false;
Daniel Sandlerdd73ee42013-10-11 22:19:59 -0400392 boolean mTranslucentDecorEnabled = true;
RoboErik001c59c2015-01-26 15:53:51 -0800393 boolean mUseTvRouting;
Craig Mautner967212c2013-04-13 21:10:58 -0700394
Jeff Brown70825162012-03-28 17:27:48 -0700395 int mPointerLocationMode = 0; // guarded by mLock
Joe Onorato664644d2011-01-23 17:53:23 -0800396
397 // The last window we were told about in focusChanged.
398 WindowState mFocusedWindow;
Dianne Hackborne0f085d2011-11-30 18:41:15 -0800399 IApplicationToken mFocusedApp;
Joe Onorato664644d2011-01-23 17:53:23 -0800400
Jeff Brown70825162012-03-28 17:27:48 -0700401 PointerLocationView mPointerLocationView;
Jeff Brown32cbc38552011-12-01 14:01:49 -0800402
Dianne Hackbornc652de82013-02-15 16:32:56 -0800403 // The current size of the screen; really; extends into the overscan area of
404 // the screen and doesn't account for any system elements like the status bar.
405 int mOverscanScreenLeft, mOverscanScreenTop;
406 int mOverscanScreenWidth, mOverscanScreenHeight;
407 // The current visible size of the screen; really; (ir)regardless of whether the status
408 // bar can be hidden but not extending into the overscan area.
Joe Onorato29fc2c92010-11-24 10:26:50 -0800409 int mUnrestrictedScreenLeft, mUnrestrictedScreenTop;
410 int mUnrestrictedScreenWidth, mUnrestrictedScreenHeight;
Dianne Hackborn313440842013-02-19 19:22:59 -0800411 // Like mOverscanScreen*, but allowed to move into the overscan region where appropriate.
412 int mRestrictedOverscanScreenLeft, mRestrictedOverscanScreenTop;
413 int mRestrictedOverscanScreenWidth, mRestrictedOverscanScreenHeight;
Dianne Hackborn82de1ae2010-10-28 11:28:39 -0700414 // The current size of the screen; these may be different than (0,0)-(dw,dh)
415 // if the status bar can't be hidden; in that case it effectively carves out
416 // that area of the display from all other windows.
Joe Onorato29fc2c92010-11-24 10:26:50 -0800417 int mRestrictedScreenLeft, mRestrictedScreenTop;
418 int mRestrictedScreenWidth, mRestrictedScreenHeight;
Dianne Hackborn5c58de32012-04-28 19:52:37 -0700419 // During layout, the current screen borders accounting for any currently
420 // visible system UI elements.
421 int mSystemLeft, mSystemTop, mSystemRight, mSystemBottom;
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -0700422 // For applications requesting stable content insets, these are them.
423 int mStableLeft, mStableTop, mStableRight, mStableBottom;
Dianne Hackborn5b5cc4d2012-05-16 13:15:00 -0700424 // For applications requesting stable content insets but have also set the
425 // fullscreen window flag, these are the stable dimensions without the status bar.
426 int mStableFullscreenLeft, mStableFullscreenTop;
427 int mStableFullscreenRight, mStableFullscreenBottom;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800428 // During layout, the current screen borders with all outer decoration
429 // (status bar, input method dock) accounted for.
430 int mCurLeft, mCurTop, mCurRight, mCurBottom;
431 // During layout, the frame in which content should be displayed
432 // to the user, accounting for all screen decoration except for any
433 // space they deem as available for other content. This is usually
434 // the same as mCur*, but may be larger if the screen decor has supplied
435 // content insets.
436 int mContentLeft, mContentTop, mContentRight, mContentBottom;
Dianne Hackborne30e02f2014-05-27 18:24:45 -0700437 // During layout, the frame in which voice content should be displayed
438 // to the user, accounting for all screen decoration except for any
439 // space they deem as available for other content.
440 int mVoiceContentLeft, mVoiceContentTop, mVoiceContentRight, mVoiceContentBottom;
Dianne Hackborn8e11ef02010-11-18 19:47:42 -0800441 // During layout, the current screen borders along which input method
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800442 // windows are placed.
443 int mDockLeft, mDockTop, mDockRight, mDockBottom;
444 // During layout, the layer at which the doc window is placed.
445 int mDockLayer;
Dianne Hackborn5c58de32012-04-28 19:52:37 -0700446 // During layout, this is the layer of the status bar.
447 int mStatusBarLayer;
Dianne Hackborne26ab702011-10-16 13:21:33 -0700448 int mLastSystemUiFlags;
449 // Bits that we are in the process of clearing, so we want to prevent
450 // them from being set by applications until everything has been updated
451 // to have them clear.
452 int mResettingSystemUiFlags = 0;
453 // Bits that we are currently always keeping cleared.
454 int mForceClearedSystemUiFlags = 0;
Dianne Hackborn4eff8d32011-11-10 19:38:40 -0800455 // What we last reported to system UI about whether the compatibility
456 // menu needs to be displayed.
457 boolean mLastFocusNeedsMenu = false;
Dianne Hackborndf89e652011-10-06 22:35:11 -0700458
Selim Cinekf83e8242015-05-19 18:08:14 -0700459 InputConsumer mInputConsumer = null;
Dianne Hackborndf89e652011-10-06 22:35:11 -0700460
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800461 static final Rect mTmpParentFrame = new Rect();
462 static final Rect mTmpDisplayFrame = new Rect();
Dianne Hackbornc4aad012013-02-22 15:05:25 -0800463 static final Rect mTmpOverscanFrame = new Rect();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800464 static final Rect mTmpContentFrame = new Rect();
465 static final Rect mTmpVisibleFrame = new Rect();
John Spurlock46646232013-09-30 22:32:42 -0400466 static final Rect mTmpDecorFrame = new Rect();
Adrian Roosfa104232014-06-20 16:10:14 -0700467 static final Rect mTmpStableFrame = new Rect();
Dianne Hackborn1f903c32011-09-13 19:18:06 -0700468 static final Rect mTmpNavigationFrame = new Rect();
Craig Mautner967212c2013-04-13 21:10:58 -0700469
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800470 WindowState mTopFullscreenOpaqueWindowState;
Adrian Rooscd3884d2015-02-18 17:25:23 +0100471 WindowState mTopFullscreenOpaqueOrDimmingWindowState;
Craig Mautner2bc789b2014-03-19 19:48:38 -0700472 HashSet<IApplicationToken> mAppsToBeHidden = new HashSet<IApplicationToken>();
Jorim Jaggic13fcac2014-09-11 17:36:57 +0200473 HashSet<IApplicationToken> mAppsThatDismissKeyguard = new HashSet<IApplicationToken>();
Joe Onorato93056472010-09-10 10:30:46 -0400474 boolean mTopIsFullscreen;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800475 boolean mForceStatusBar;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -0700476 boolean mForceStatusBarFromKeyguard;
Selim Cinek4a4a2bddc2015-05-07 12:50:19 -0700477 private boolean mForceStatusBarTransparent;
Dianne Hackborn39c2d712009-09-22 11:41:31 -0700478 boolean mHideLockScreen;
Dianne Hackborn891d3fb2013-01-09 18:31:37 -0800479 boolean mForcingShowNavBar;
480 int mForcingShowNavBarLayer;
Craig Mautnerad09bcc2012-10-08 13:33:11 -0700481
482 // States of keyguard dismiss.
483 private static final int DISMISS_KEYGUARD_NONE = 0; // Keyguard not being dismissed.
484 private static final int DISMISS_KEYGUARD_START = 1; // Keyguard needs to be dismissed.
485 private static final int DISMISS_KEYGUARD_CONTINUE = 2; // Keyguard has been dismissed.
486 int mDismissKeyguard = DISMISS_KEYGUARD_NONE;
487
488 /** The window that is currently dismissing the keyguard. Dismissing the keyguard must only
489 * be done once per window. */
490 private WindowState mWinDismissingKeyguard;
491
Craig Mautnerc9457fa2014-06-06 14:27:48 -0700492 /** The window that is currently showing "over" the keyguard. If there is an app window
493 * belonging to another app on top of this the keyguard shows. If there is a fullscreen
494 * app window under this, still dismiss the keyguard but don't show the app underneath. Show
495 * the wallpaper. */
496 private WindowState mWinShowWhenLocked;
497
Dianne Hackborn7ad44382012-10-18 17:46:00 -0700498 boolean mShowingLockscreen;
499 boolean mShowingDream;
500 boolean mDreamingLockscreen;
Jeff Brown061ea992015-04-17 19:55:47 -0700501 boolean mDreamingSleepTokenNeeded;
502 SleepToken mDreamingSleepToken;
Jim Millerab954542014-10-10 18:21:49 -0700503 boolean mKeyguardSecure;
504 boolean mKeyguardSecureIncludingHidden;
505 volatile boolean mKeyguardOccluded;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800506 boolean mHomePressed;
Jeff Browncaca8812013-05-09 13:34:33 -0700507 boolean mHomeConsumed;
508 boolean mHomeDoubleTapPending;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800509 Intent mHomeIntent;
Dianne Hackborn39c2d712009-09-22 11:41:31 -0700510 Intent mCarDockIntent;
511 Intent mDeskDockIntent;
Jeff Brownfd23e3e2012-05-09 13:34:28 -0700512 boolean mSearchKeyShortcutPending;
513 boolean mConsumeSearchKeyUp;
Jeff Brownde7a8ea2012-06-13 18:28:57 -0700514 boolean mAssistKeyLongPressed;
Michael Wright6a62e552014-06-03 19:19:48 -0700515 boolean mPendingMetaAction;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800516
Mike Lockwood28569302010-01-28 11:54:40 -0500517 // support for activating the lock screen while the screen is on
518 boolean mAllowLockscreenWhenOn;
519 int mLockScreenTimeout;
520 boolean mLockScreenTimerActive;
521
David Brownbaf8d092010-03-08 21:52:59 -0800522 // Behavior of ENDCALL Button. (See Settings.System.END_BUTTON_BEHAVIOR.)
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800523 int mEndcallBehavior;
David Brownbaf8d092010-03-08 21:52:59 -0800524
525 // Behavior of POWER button while in-call and screen on.
526 // (See Settings.Secure.INCALL_POWER_BUTTON_BEHAVIOR.)
527 int mIncallPowerBehavior;
528
Dianne Hackbornf87d1962012-04-04 12:48:24 -0700529 Display mDisplay;
530
Dianne Hackborn9d132642011-04-21 17:26:39 -0700531 int mLandscapeRotation = 0; // default landscape rotation
532 int mSeascapeRotation = 0; // "other" landscape rotation, 180 degrees from mLandscapeRotation
533 int mPortraitRotation = 0; // default portrait rotation
534 int mUpsideDownRotation = 0; // "other" portrait rotation
Mitsuru Oshima831d0d92009-06-16 18:27:18 -0700535
Dianne Hackbornc652de82013-02-15 16:32:56 -0800536 int mOverscanLeft = 0;
537 int mOverscanTop = 0;
538 int mOverscanRight = 0;
539 int mOverscanBottom = 0;
540
Joe Onorato46b0d682010-11-22 17:37:27 -0800541 // What we do when the user long presses on home
Jeff Browncaca8812013-05-09 13:34:33 -0700542 private int mLongPressOnHomeBehavior;
543
544 // What we do when the user double-taps on home
545 private int mDoubleTapOnHomeBehavior;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800546
Bryce Lee584a4452014-10-21 15:55:55 -0700547 // Allowed theater mode wake actions
548 private boolean mAllowTheaterModeWakeFromKey;
549 private boolean mAllowTheaterModeWakeFromPowerKey;
550 private boolean mAllowTheaterModeWakeFromMotion;
Bryce Lee812d7022014-11-10 13:33:28 -0800551 private boolean mAllowTheaterModeWakeFromMotionWhenNotDreaming;
Bryce Lee584a4452014-10-21 15:55:55 -0700552 private boolean mAllowTheaterModeWakeFromCameraLens;
553 private boolean mAllowTheaterModeWakeFromLidSwitch;
554 private boolean mAllowTheaterModeWakeFromWakeGesture;
555
Bryce Leed3b28402015-03-09 15:49:13 +0000556 // Whether to support long press from power button in non-interactive mode
557 private boolean mSupportLongPressPowerWhenNonInteractive;
558
Bryce Lee55e846d2014-11-04 12:43:44 -0800559 // Whether to go to sleep entering theater mode from power button
560 private boolean mGoToSleepOnButtonPressTheaterMode;
561
Winson Chung9112ec32011-06-27 13:15:32 -0700562 // Screenshot trigger states
Jeff Brownd5bb82d2011-10-12 13:57:59 -0700563 // Time to volume and power must be pressed within this interval of each other.
564 private static final long SCREENSHOT_CHORD_DEBOUNCE_DELAY_MILLIS = 150;
Winson Chung1cea2f32012-10-08 20:42:01 -0700565 // Increase the chord delay when taking a screenshot from the keyguard
566 private static final float KEYGUARD_SCREENSHOT_CHORD_DELAY_MULTIPLIER = 2.5f;
Christopher Tatee90585f2012-03-05 18:56:25 -0800567 private boolean mScreenshotChordEnabled;
Jeff Brown13f00f02014-10-31 14:45:50 -0700568 private boolean mScreenshotChordVolumeDownKeyTriggered;
569 private long mScreenshotChordVolumeDownKeyTime;
570 private boolean mScreenshotChordVolumeDownKeyConsumed;
571 private boolean mScreenshotChordVolumeUpKeyTriggered;
572 private boolean mScreenshotChordPowerKeyTriggered;
573 private long mScreenshotChordPowerKeyTime;
Winson Chung9112ec32011-06-27 13:15:32 -0700574
Michael Wrightb854e242013-02-05 17:54:02 -0800575 /* The number of steps between min and max brightness */
576 private static final int BRIGHTNESS_STEPS = 10;
577
Christopher Tate5e08af02012-09-21 17:17:22 -0700578 SettingsObserver mSettingsObserver;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800579 ShortcutManager mShortcutManager;
580 PowerManager.WakeLock mBroadcastWakeLock;
Jeff Brown13f00f02014-10-31 14:45:50 -0700581 PowerManager.WakeLock mPowerKeyWakeLock;
Jeff Brown40013652012-05-16 21:22:36 -0700582 boolean mHavePendingMediaKeyRepeatWithWakeLock;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800583
Craig Mautnerd625ab22013-09-06 13:40:31 -0700584 private int mCurrentUserId;
585
Justin Kohd378ad72013-04-01 12:18:26 -0700586 // Maps global key codes to the components that will handle them.
587 private GlobalKeyManager mGlobalKeyManager;
588
Jeff Brownfd23e3e2012-05-09 13:34:28 -0700589 // Fallback actions by key code.
590 private final SparseArray<KeyCharacterMap.FallbackAction> mFallbackActions =
591 new SparseArray<KeyCharacterMap.FallbackAction>();
Jeff Brown49ed71d2010-12-06 17:13:33 -0800592
Jorim Jaggi76a16232014-08-08 17:00:47 +0200593 private final LogDecelerateInterpolator mLogDecelerateInterpolator
594 = new LogDecelerateInterpolator(100, 0);
595
Jeff Brown70825162012-03-28 17:27:48 -0700596 private static final int MSG_ENABLE_POINTER_LOCATION = 1;
597 private static final int MSG_DISABLE_POINTER_LOCATION = 2;
Jeff Brown40013652012-05-16 21:22:36 -0700598 private static final int MSG_DISPATCH_MEDIA_KEY_WITH_WAKE_LOCK = 3;
599 private static final int MSG_DISPATCH_MEDIA_KEY_REPEAT_WITH_WAKE_LOCK = 4;
Craig Mautner8a0da012014-05-31 15:13:37 -0700600 private static final int MSG_KEYGUARD_DRAWN_COMPLETE = 5;
601 private static final int MSG_KEYGUARD_DRAWN_TIMEOUT = 6;
602 private static final int MSG_WINDOW_MANAGER_DRAWN_COMPLETE = 7;
Craig Mautner84984fa2014-06-19 11:19:20 -0700603 private static final int MSG_DISPATCH_SHOW_RECENTS = 9;
Alan Viverettee34560b22014-07-10 14:50:06 -0700604 private static final int MSG_DISPATCH_SHOW_GLOBAL_ACTIONS = 10;
Craig Mautnera631d492014-08-05 15:16:01 -0700605 private static final int MSG_HIDE_BOOT_MESSAGE = 11;
Michael Wright869a67c2014-08-26 19:33:06 -0700606 private static final int MSG_LAUNCH_VOICE_ASSIST_WITH_WAKE_LOCK = 12;
Jeff Brown13f00f02014-10-31 14:45:50 -0700607 private static final int MSG_POWER_DELAYED_PRESS = 13;
608 private static final int MSG_POWER_LONG_PRESS = 14;
Jeff Brown061ea992015-04-17 19:55:47 -0700609 private static final int MSG_UPDATE_DREAMING_SLEEP_TOKEN = 15;
Jeff Brown70825162012-03-28 17:27:48 -0700610
611 private class PolicyHandler extends Handler {
612 @Override
613 public void handleMessage(Message msg) {
614 switch (msg.what) {
615 case MSG_ENABLE_POINTER_LOCATION:
616 enablePointerLocation();
617 break;
618 case MSG_DISABLE_POINTER_LOCATION:
619 disablePointerLocation();
620 break;
Jeff Brown40013652012-05-16 21:22:36 -0700621 case MSG_DISPATCH_MEDIA_KEY_WITH_WAKE_LOCK:
622 dispatchMediaKeyWithWakeLock((KeyEvent)msg.obj);
623 break;
624 case MSG_DISPATCH_MEDIA_KEY_REPEAT_WITH_WAKE_LOCK:
625 dispatchMediaKeyRepeatWithWakeLock((KeyEvent)msg.obj);
626 break;
Craig Mautner84984fa2014-06-19 11:19:20 -0700627 case MSG_DISPATCH_SHOW_RECENTS:
628 showRecentApps(false);
629 break;
Alan Viverettee34560b22014-07-10 14:50:06 -0700630 case MSG_DISPATCH_SHOW_GLOBAL_ACTIONS:
631 showGlobalActionsInternal();
632 break;
Craig Mautner8a0da012014-05-31 15:13:37 -0700633 case MSG_KEYGUARD_DRAWN_COMPLETE:
634 if (DEBUG_WAKEUP) Slog.w(TAG, "Setting mKeyguardDrawComplete");
Jeff Brown36c4db82014-09-19 12:05:31 -0700635 finishKeyguardDrawn();
Craig Mautner8a0da012014-05-31 15:13:37 -0700636 break;
637 case MSG_KEYGUARD_DRAWN_TIMEOUT:
638 Slog.w(TAG, "Keyguard drawn timeout. Setting mKeyguardDrawComplete");
Jeff Brown36c4db82014-09-19 12:05:31 -0700639 finishKeyguardDrawn();
Craig Mautner8a0da012014-05-31 15:13:37 -0700640 break;
641 case MSG_WINDOW_MANAGER_DRAWN_COMPLETE:
642 if (DEBUG_WAKEUP) Slog.w(TAG, "Setting mWindowManagerDrawComplete");
Jeff Brown36c4db82014-09-19 12:05:31 -0700643 finishWindowsDrawn();
Craig Mautner8a0da012014-05-31 15:13:37 -0700644 break;
Craig Mautnera631d492014-08-05 15:16:01 -0700645 case MSG_HIDE_BOOT_MESSAGE:
646 handleHideBootMessage();
647 break;
Michael Wright869a67c2014-08-26 19:33:06 -0700648 case MSG_LAUNCH_VOICE_ASSIST_WITH_WAKE_LOCK:
649 launchVoiceAssistWithWakeLock(msg.arg1 != 0);
650 break;
Jeff Brown13f00f02014-10-31 14:45:50 -0700651 case MSG_POWER_DELAYED_PRESS:
652 powerPress((Long)msg.obj, msg.arg1 != 0, msg.arg2);
653 finishPowerKeyPress();
654 break;
655 case MSG_POWER_LONG_PRESS:
656 powerLongPress();
657 break;
Jeff Brown061ea992015-04-17 19:55:47 -0700658 case MSG_UPDATE_DREAMING_SLEEP_TOKEN:
659 updateDreamingSleepToken(msg.arg1 != 0);
660 break;
Jeff Brown70825162012-03-28 17:27:48 -0700661 }
662 }
663 }
664
Dianne Hackbornad7fa7f2011-01-07 14:06:50 -0800665 private UEventObserver mHDMIObserver = new UEventObserver() {
666 @Override
667 public void onUEvent(UEventObserver.UEvent event) {
668 setHdmiPlugged("1".equals(event.get("SWITCH_STATE")));
669 }
670 };
671
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800672 class SettingsObserver extends ContentObserver {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800673 SettingsObserver(Handler handler) {
674 super(handler);
675 }
David Brownbaf8d092010-03-08 21:52:59 -0800676
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800677 void observe() {
Christopher Tate5e08af02012-09-21 17:17:22 -0700678 // Observe all users' changes
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800679 ContentResolver resolver = mContext.getContentResolver();
680 resolver.registerContentObserver(Settings.System.getUriFor(
Christopher Tate5e08af02012-09-21 17:17:22 -0700681 Settings.System.END_BUTTON_BEHAVIOR), false, this,
682 UserHandle.USER_ALL);
David Brownbaf8d092010-03-08 21:52:59 -0800683 resolver.registerContentObserver(Settings.Secure.getUriFor(
Christopher Tate5e08af02012-09-21 17:17:22 -0700684 Settings.Secure.INCALL_POWER_BUTTON_BEHAVIOR), false, this,
685 UserHandle.USER_ALL);
Jeff Browna20dda42014-05-27 20:57:24 -0700686 resolver.registerContentObserver(Settings.Secure.getUriFor(
687 Settings.Secure.WAKE_GESTURE_ENABLED), false, this,
688 UserHandle.USER_ALL);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800689 resolver.registerContentObserver(Settings.System.getUriFor(
Christopher Tate5e08af02012-09-21 17:17:22 -0700690 Settings.System.ACCELEROMETER_ROTATION), false, this,
691 UserHandle.USER_ALL);
Mike Lockwood28569302010-01-28 11:54:40 -0500692 resolver.registerContentObserver(Settings.System.getUriFor(
Christopher Tate5e08af02012-09-21 17:17:22 -0700693 Settings.System.USER_ROTATION), false, this,
694 UserHandle.USER_ALL);
Daniel Sandlerb73617d2010-08-17 00:41:00 -0400695 resolver.registerContentObserver(Settings.System.getUriFor(
Christopher Tate5e08af02012-09-21 17:17:22 -0700696 Settings.System.SCREEN_OFF_TIMEOUT), false, this,
697 UserHandle.USER_ALL);
Dianne Hackbornc777e072010-02-12 13:07:59 -0800698 resolver.registerContentObserver(Settings.System.getUriFor(
Christopher Tate5e08af02012-09-21 17:17:22 -0700699 Settings.System.POINTER_LOCATION), false, this,
700 UserHandle.USER_ALL);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800701 resolver.registerContentObserver(Settings.Secure.getUriFor(
Christopher Tate5e08af02012-09-21 17:17:22 -0700702 Settings.Secure.DEFAULT_INPUT_METHOD), false, this,
703 UserHandle.USER_ALL);
John Spurlockd9b70bd2014-02-06 17:02:44 -0500704 resolver.registerContentObserver(Settings.Secure.getUriFor(
John Spurlockf1a36642013-10-12 17:50:42 -0400705 Settings.Secure.IMMERSIVE_MODE_CONFIRMATIONS), false, this,
Christopher Tate5e08af02012-09-21 17:17:22 -0700706 UserHandle.USER_ALL);
John Spurlockc6d1c602014-01-17 15:22:06 -0500707 resolver.registerContentObserver(Settings.Global.getUriFor(
708 Settings.Global.POLICY_CONTROL), false, this,
709 UserHandle.USER_ALL);
Dianne Hackbornc777e072010-02-12 13:07:59 -0800710 updateSettings();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800711 }
712
713 @Override public void onChange(boolean selfChange) {
Dianne Hackbornc777e072010-02-12 13:07:59 -0800714 updateSettings();
Jeff Brown01a98dd2011-09-20 15:08:29 -0700715 updateRotation(false);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800716 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800717 }
Craig Mautner967212c2013-04-13 21:10:58 -0700718
Jeff Browna20dda42014-05-27 20:57:24 -0700719 class MyWakeGestureListener extends WakeGestureListener {
720 MyWakeGestureListener(Context context, Handler handler) {
721 super(context, handler);
722 }
723
724 @Override
725 public void onWakeUp() {
726 synchronized (mLock) {
727 if (shouldEnableWakeGestureLp()) {
Jeff Browne07b94b2014-06-18 15:56:27 -0700728 performHapticFeedbackLw(null, HapticFeedbackConstants.VIRTUAL_KEY, false);
Bryce Lee584a4452014-10-21 15:55:55 -0700729 wakeUp(SystemClock.uptimeMillis(), mAllowTheaterModeWakeFromWakeGesture);
Jeff Browna20dda42014-05-27 20:57:24 -0700730 }
731 }
732 }
733 }
734
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800735 class MyOrientationListener extends WindowOrientationListener {
Craig Mautnereee29c42013-01-17 14:44:34 -0800736 MyOrientationListener(Context context, Handler handler) {
737 super(context, handler);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800738 }
Craig Mautner967212c2013-04-13 21:10:58 -0700739
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800740 @Override
Jeff Brownc0347aa2011-09-23 17:26:09 -0700741 public void onProposedRotationChanged(int rotation) {
Craig Mautnereda67292013-04-28 13:50:14 -0700742 if (localLOGV) Slog.v(TAG, "onProposedRotationChanged, rotation=" + rotation);
Jeff Brown01a98dd2011-09-20 15:08:29 -0700743 updateRotation(false);
744 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800745 }
746 MyOrientationListener mOrientationListener;
747
Jorim Jaggi24bec7c2015-02-04 12:40:14 +0100748 private final StatusBarController mStatusBarController = new StatusBarController();
John Spurlock5b9145b2013-08-20 15:13:47 -0400749
John Spurlock27735a42013-08-14 17:57:38 -0400750 private final BarController mNavigationBarController = new BarController("NavigationBar",
John Spurlock5b9145b2013-08-20 15:13:47 -0400751 View.NAVIGATION_BAR_TRANSIENT,
752 View.NAVIGATION_BAR_UNHIDE,
John Spurlockbd957402013-10-03 11:38:39 -0400753 View.NAVIGATION_BAR_TRANSLUCENT,
754 StatusBarManager.WINDOW_NAVIGATION_BAR,
755 WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION);
John Spurlock5b9145b2013-08-20 15:13:47 -0400756
John Spurlockf1a36642013-10-12 17:50:42 -0400757 private ImmersiveModeConfirmation mImmersiveModeConfirmation;
John Spurlock32beb2c2013-03-11 10:16:47 -0400758
Craig Mautner037aa8d2013-06-07 10:35:44 -0700759 private SystemGesturesPointerEventListener mSystemGestures;
John Spurlock32beb2c2013-03-11 10:16:47 -0400760
Dianne Hackborn42e620c2012-06-24 13:20:51 -0700761 IStatusBarService getStatusBarService() {
762 synchronized (mServiceAquireLock) {
763 if (mStatusBarService == null) {
764 mStatusBarService = IStatusBarService.Stub.asInterface(
765 ServiceManager.getService("statusbar"));
766 }
767 return mStatusBarService;
768 }
769 }
770
Suchi Amalapurapua9e1b162009-03-24 22:24:47 -0700771 /*
772 * We always let the sensor be switched on by default except when
773 * the user has explicitly disabled sensor based rotation or when the
774 * screen is switched off.
775 */
The Android Open Source Project0727d222009-03-11 12:11:58 -0700776 boolean needSensorRunningLp() {
Jeff Brownbcdfc622014-03-06 19:13:04 -0800777 if (mSupportAutoRotation) {
778 if (mCurrentAppOrientation == ActivityInfo.SCREEN_ORIENTATION_SENSOR
779 || mCurrentAppOrientation == ActivityInfo.SCREEN_ORIENTATION_FULL_SENSOR
780 || mCurrentAppOrientation == ActivityInfo.SCREEN_ORIENTATION_SENSOR_PORTRAIT
781 || mCurrentAppOrientation == ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE) {
782 // If the application has explicitly requested to follow the
783 // orientation, then we need to turn the sensor on.
784 return true;
785 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800786 }
Dianne Hackborn867ab6472010-04-29 13:28:56 -0700787 if ((mCarDockEnablesAccelerometer && mDockMode == Intent.EXTRA_DOCK_STATE_CAR) ||
Jeff Brown1a693182011-11-08 14:44:16 -0800788 (mDeskDockEnablesAccelerometer && (mDockMode == Intent.EXTRA_DOCK_STATE_DESK
789 || mDockMode == Intent.EXTRA_DOCK_STATE_LE_DESK
790 || mDockMode == Intent.EXTRA_DOCK_STATE_HE_DESK))) {
Mike Lockwoode9867d22009-09-20 01:59:02 -0400791 // enable accelerometer if we are docked in a dock that enables accelerometer
792 // orientation management,
793 return true;
794 }
Jeff Brown207673cd2012-06-05 17:47:11 -0700795 if (mUserRotationMode == USER_ROTATION_LOCKED) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800796 // If the setting for using the sensor by default is enabled, then
797 // we will always leave it on. Note that the user could go to
798 // a window that forces an orientation that does not use the
799 // sensor and in theory we could turn it off... however, when next
800 // turning it on we won't have a good value for the current
801 // orientation for a little bit, which can cause orientation
802 // changes to lag, so we'd like to keep it always on. (It will
803 // still be turned off when the screen is off.)
Suchi Amalapurapua9e1b162009-03-24 22:24:47 -0700804 return false;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800805 }
Jeff Brownbcdfc622014-03-06 19:13:04 -0800806 return mSupportAutoRotation;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800807 }
Craig Mautner46ac6fa2013-08-01 10:06:34 -0700808
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800809 /*
810 * Various use cases for invoking this function
811 * screen turning off, should always disable listeners if already enabled
Craig Mautner46ac6fa2013-08-01 10:06:34 -0700812 * screen turned on and current app has sensor based orientation, enable listeners
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800813 * if not already enabled
814 * screen turned on and current app does not have sensor orientation, disable listeners if
815 * already enabled
816 * screen turning on and current app has sensor based orientation, enable listeners if needed
817 * screen turning on and current app has nosensor based orientation, do nothing
818 */
The Android Open Source Project0727d222009-03-11 12:11:58 -0700819 void updateOrientationListenerLp() {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800820 if (!mOrientationListener.canDetectOrientation()) {
821 // If sensor is turned off or nonexistent for some reason
822 return;
823 }
824 //Could have been invoked due to screen turning on or off or
825 //change of the currently visible window's orientation
Jeff Brown3ee549c2014-09-22 20:14:39 -0700826 if (localLOGV) Slog.v(TAG, "mScreenOnEarly=" + mScreenOnEarly
827 + ", mAwake=" + mAwake + ", mCurrentAppOrientation=" + mCurrentAppOrientation
828 + ", mOrientationSensorEnabled=" + mOrientationSensorEnabled);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800829 boolean disable = true;
Jeff Brown3ee549c2014-09-22 20:14:39 -0700830 if (mScreenOnEarly && mAwake) {
The Android Open Source Project0727d222009-03-11 12:11:58 -0700831 if (needSensorRunningLp()) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800832 disable = false;
833 //enable listener if not already enabled
The Android Open Source Project0727d222009-03-11 12:11:58 -0700834 if (!mOrientationSensorEnabled) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800835 mOrientationListener.enable();
Craig Mautnereda67292013-04-28 13:50:14 -0700836 if(localLOGV) Slog.v(TAG, "Enabling listeners");
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800837 mOrientationSensorEnabled = true;
838 }
Craig Mautner46ac6fa2013-08-01 10:06:34 -0700839 }
840 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800841 //check if sensors need to be disabled
The Android Open Source Project0727d222009-03-11 12:11:58 -0700842 if (disable && mOrientationSensorEnabled) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800843 mOrientationListener.disable();
Craig Mautnereda67292013-04-28 13:50:14 -0700844 if(localLOGV) Slog.v(TAG, "Disabling listeners");
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800845 mOrientationSensorEnabled = false;
846 }
847 }
848
Jeff Brown13f00f02014-10-31 14:45:50 -0700849 private void interceptPowerKeyDown(KeyEvent event, boolean interactive) {
850 // Hold a wake lock until the power key is released.
851 if (!mPowerKeyWakeLock.isHeld()) {
852 mPowerKeyWakeLock.acquire();
853 }
854
855 // Cancel multi-press detection timeout.
856 if (mPowerKeyPressCounter != 0) {
857 mHandler.removeMessages(MSG_POWER_DELAYED_PRESS);
858 }
859
860 // Detect user pressing the power button in panic when an application has
861 // taken over the whole screen.
862 boolean panic = mImmersiveModeConfirmation.onPowerKeyDown(interactive,
Craig Mautner0124980e92014-11-30 21:15:34 -0800863 SystemClock.elapsedRealtime(), isImmersiveMode(mLastSystemUiFlags));
Jeff Brown13f00f02014-10-31 14:45:50 -0700864 if (panic) {
865 mHandler.post(mRequestTransientNav);
866 }
867
868 // Latch power key state to detect screenshot chord.
869 if (interactive && !mScreenshotChordPowerKeyTriggered
870 && (event.getFlags() & KeyEvent.FLAG_FALLBACK) == 0) {
871 mScreenshotChordPowerKeyTriggered = true;
872 mScreenshotChordPowerKeyTime = event.getDownTime();
873 interceptScreenshotChord();
874 }
875
876 // Stop ringing or end call if configured to do so when power is pressed.
877 TelecomManager telecomManager = getTelecommService();
878 boolean hungUp = false;
879 if (telecomManager != null) {
880 if (telecomManager.isRinging()) {
881 // Pressing Power while there's a ringing incoming
882 // call should silence the ringer.
883 telecomManager.silenceRinger();
884 } else if ((mIncallPowerBehavior
885 & Settings.Secure.INCALL_POWER_BUTTON_BEHAVIOR_HANGUP) != 0
886 && telecomManager.isInCall() && interactive) {
887 // Otherwise, if "Power button ends call" is enabled,
888 // the Power button will hang up any current active call.
889 hungUp = telecomManager.endCall();
890 }
891 }
892
893 // If the power key has still not yet been handled, then detect short
894 // press, long press, or multi press and decide what to do.
895 mPowerKeyHandled = hungUp || mScreenshotChordVolumeDownKeyTriggered
896 || mScreenshotChordVolumeUpKeyTriggered;
897 if (!mPowerKeyHandled) {
898 if (interactive) {
899 // When interactive, we're already awake.
900 // Wait for a long press or for the button to be released to decide what to do.
901 if (hasLongPressOnPowerBehavior()) {
902 Message msg = mHandler.obtainMessage(MSG_POWER_LONG_PRESS);
903 msg.setAsynchronous(true);
904 mHandler.sendMessageDelayed(msg,
905 ViewConfiguration.get(mContext).getDeviceGlobalActionKeyTimeout());
906 }
907 } else {
Bryce Leed9268e32014-11-17 17:40:59 -0800908 wakeUpFromPowerKey(event.getDownTime());
Bryce Leed9268e32014-11-17 17:40:59 -0800909
Bryce Leed3b28402015-03-09 15:49:13 +0000910 if (mSupportLongPressPowerWhenNonInteractive && hasLongPressOnPowerBehavior()) {
911 Message msg = mHandler.obtainMessage(MSG_POWER_LONG_PRESS);
912 msg.setAsynchronous(true);
913 mHandler.sendMessageDelayed(msg,
914 ViewConfiguration.get(mContext).getDeviceGlobalActionKeyTimeout());
Bryce Leed9268e32014-11-17 17:40:59 -0800915 mBeganFromNonInteractive = true;
Bryce Leed3b28402015-03-09 15:49:13 +0000916 } else {
917 final int maxCount = getMaxMultiPressPowerCount();
918
919 if (maxCount <= 1) {
920 mPowerKeyHandled = true;
921 } else {
922 mBeganFromNonInteractive = true;
923 }
Jeff Brown13f00f02014-10-31 14:45:50 -0700924 }
925 }
Jeff Brown4d396052010-10-29 21:50:21 -0700926 }
927 }
928
Jeff Brown13f00f02014-10-31 14:45:50 -0700929 private void interceptPowerKeyUp(KeyEvent event, boolean interactive, boolean canceled) {
930 final boolean handled = canceled || mPowerKeyHandled;
931 mScreenshotChordPowerKeyTriggered = false;
932 cancelPendingScreenshotChordAction();
933 cancelPendingPowerKeyAction();
934
935 if (!handled) {
936 // Figure out how to handle the key now that it has been released.
937 mPowerKeyPressCounter += 1;
938
939 final int maxCount = getMaxMultiPressPowerCount();
940 final long eventTime = event.getDownTime();
941 if (mPowerKeyPressCounter < maxCount) {
942 // This could be a multi-press. Wait a little bit longer to confirm.
943 // Continue holding the wake lock.
944 Message msg = mHandler.obtainMessage(MSG_POWER_DELAYED_PRESS,
945 interactive ? 1 : 0, mPowerKeyPressCounter, eventTime);
946 msg.setAsynchronous(true);
947 mHandler.sendMessageDelayed(msg, ViewConfiguration.getDoubleTapTimeout());
948 return;
949 }
950
951 // No other actions. Handle it immediately.
952 powerPress(eventTime, interactive, mPowerKeyPressCounter);
Jeff Brown4d396052010-10-29 21:50:21 -0700953 }
Jeff Brown13f00f02014-10-31 14:45:50 -0700954
955 // Done. Reset our state.
956 finishPowerKeyPress();
957 }
958
959 private void finishPowerKeyPress() {
Bryce Leed9268e32014-11-17 17:40:59 -0800960 mBeganFromNonInteractive = false;
Jeff Brown13f00f02014-10-31 14:45:50 -0700961 mPowerKeyPressCounter = 0;
962 if (mPowerKeyWakeLock.isHeld()) {
963 mPowerKeyWakeLock.release();
964 }
Jeff Brownd5bb82d2011-10-12 13:57:59 -0700965 }
966
967 private void cancelPendingPowerKeyAction() {
968 if (!mPowerKeyHandled) {
Jeff Brown13f00f02014-10-31 14:45:50 -0700969 mPowerKeyHandled = true;
970 mHandler.removeMessages(MSG_POWER_LONG_PRESS);
Jeff Brownd5bb82d2011-10-12 13:57:59 -0700971 }
Jeff Brown13f00f02014-10-31 14:45:50 -0700972 }
973
974 private void powerPress(long eventTime, boolean interactive, int count) {
975 if (mScreenOnEarly && !mScreenOnFully) {
976 Slog.i(TAG, "Suppressed redundant power key press while "
977 + "already in the process of turning the screen on.");
978 return;
Jeff Brownff204712011-10-25 21:27:54 -0700979 }
Jeff Brown13f00f02014-10-31 14:45:50 -0700980
981 if (count == 2) {
982 powerMultiPressAction(eventTime, interactive, mDoublePressOnPowerBehavior);
983 } else if (count == 3) {
984 powerMultiPressAction(eventTime, interactive, mTriplePressOnPowerBehavior);
Bryce Leed9268e32014-11-17 17:40:59 -0800985 } else if (interactive && !mBeganFromNonInteractive) {
Jeff Brown13f00f02014-10-31 14:45:50 -0700986 switch (mShortPressOnPowerBehavior) {
987 case SHORT_PRESS_POWER_NOTHING:
988 break;
989 case SHORT_PRESS_POWER_GO_TO_SLEEP:
990 mPowerManager.goToSleep(eventTime,
991 PowerManager.GO_TO_SLEEP_REASON_POWER_BUTTON, 0);
992 break;
993 case SHORT_PRESS_POWER_REALLY_GO_TO_SLEEP:
994 mPowerManager.goToSleep(eventTime,
995 PowerManager.GO_TO_SLEEP_REASON_POWER_BUTTON,
996 PowerManager.GO_TO_SLEEP_FLAG_NO_DOZE);
997 break;
998 case SHORT_PRESS_POWER_REALLY_GO_TO_SLEEP_AND_GO_HOME:
999 mPowerManager.goToSleep(eventTime,
1000 PowerManager.GO_TO_SLEEP_REASON_POWER_BUTTON,
1001 PowerManager.GO_TO_SLEEP_FLAG_NO_DOZE);
1002 launchHomeFromHotKey();
1003 break;
Bryce Lee01b0c5f2015-02-05 18:24:04 -08001004 case SHORT_PRESS_POWER_GO_HOME:
Bryce Lee662ed802015-04-10 20:11:39 +00001005 launchHomeFromHotKey(true /* awakenFromDreams */, false /*respectKeyguard*/);
Bryce Lee01b0c5f2015-02-05 18:24:04 -08001006 break;
Jeff Brown13f00f02014-10-31 14:45:50 -07001007 }
1008 }
1009 }
1010
1011 private void powerMultiPressAction(long eventTime, boolean interactive, int behavior) {
1012 switch (behavior) {
1013 case MULTI_PRESS_POWER_NOTHING:
1014 break;
1015 case MULTI_PRESS_POWER_THEATER_MODE:
1016 if (isTheaterModeEnabled()) {
1017 Slog.i(TAG, "Toggling theater mode off.");
1018 Settings.Global.putInt(mContext.getContentResolver(),
1019 Settings.Global.THEATER_MODE_ON, 0);
1020 if (!interactive) {
1021 wakeUpFromPowerKey(eventTime);
1022 }
1023 } else {
1024 Slog.i(TAG, "Toggling theater mode on.");
1025 Settings.Global.putInt(mContext.getContentResolver(),
1026 Settings.Global.THEATER_MODE_ON, 1);
Bryce Lee55e846d2014-11-04 12:43:44 -08001027
1028 if (mGoToSleepOnButtonPressTheaterMode && interactive) {
Jeff Brown13f00f02014-10-31 14:45:50 -07001029 mPowerManager.goToSleep(eventTime,
1030 PowerManager.GO_TO_SLEEP_REASON_POWER_BUTTON, 0);
1031 }
1032 }
1033 break;
1034 case MULTI_PRESS_POWER_BRIGHTNESS_BOOST:
Jeff Brown7b5be5e2014-11-12 18:45:31 -08001035 Slog.i(TAG, "Starting brightness boost.");
1036 if (!interactive) {
1037 wakeUpFromPowerKey(eventTime);
1038 }
Jeff Brown13f00f02014-10-31 14:45:50 -07001039 mPowerManager.boostScreenBrightness(eventTime);
1040 break;
1041 }
1042 }
1043
1044 private int getMaxMultiPressPowerCount() {
1045 if (mTriplePressOnPowerBehavior != MULTI_PRESS_POWER_NOTHING) {
1046 return 3;
1047 }
1048 if (mDoublePressOnPowerBehavior != MULTI_PRESS_POWER_NOTHING) {
1049 return 2;
1050 }
1051 return 1;
1052 }
1053
1054 private void powerLongPress() {
1055 final int behavior = getResolvedLongPressOnPowerBehavior();
1056 switch (behavior) {
1057 case LONG_PRESS_POWER_NOTHING:
1058 break;
1059 case LONG_PRESS_POWER_GLOBAL_ACTIONS:
1060 mPowerKeyHandled = true;
1061 if (!performHapticFeedbackLw(null, HapticFeedbackConstants.LONG_PRESS, false)) {
1062 performAuditoryFeedbackForAccessibilityIfNeed();
1063 }
1064 showGlobalActionsInternal();
1065 break;
1066 case LONG_PRESS_POWER_SHUT_OFF:
1067 case LONG_PRESS_POWER_SHUT_OFF_NO_CONFIRM:
1068 mPowerKeyHandled = true;
1069 performHapticFeedbackLw(null, HapticFeedbackConstants.LONG_PRESS, false);
1070 sendCloseSystemWindows(SYSTEM_DIALOG_REASON_GLOBAL_ACTIONS);
1071 mWindowManagerFuncs.shutdown(behavior == LONG_PRESS_POWER_SHUT_OFF);
1072 break;
1073 }
1074 }
1075
Filip Gruszczynskia483a1d2015-03-17 19:06:58 +00001076 private void sleepPress(KeyEvent event) {
1077 switch (mShortPressOnSleepBehavior) {
1078 case SHORT_PRESS_SLEEP_GO_TO_SLEEP:
1079 mPowerManager.goToSleep(event.getEventTime(),
1080 PowerManager.GO_TO_SLEEP_REASON_SLEEP_BUTTON, 0);
1081 break;
1082 case SHORT_PRESS_SLEEP_GO_TO_SLEEP_AND_GO_HOME:
Bryce Lee662ed802015-04-10 20:11:39 +00001083 launchHomeFromHotKey(false /* awakenDreams */, true /*respectKeyguard*/);
Filip Gruszczynskia483a1d2015-03-17 19:06:58 +00001084 mPowerManager.goToSleep(event.getEventTime(),
1085 PowerManager.GO_TO_SLEEP_REASON_SLEEP_BUTTON, 0);
1086 break;
1087 }
1088 }
1089
Jeff Brown13f00f02014-10-31 14:45:50 -07001090 private int getResolvedLongPressOnPowerBehavior() {
1091 if (FactoryTest.isLongPressOnPowerOffEnabled()) {
1092 return LONG_PRESS_POWER_SHUT_OFF_NO_CONFIRM;
1093 }
1094 return mLongPressOnPowerBehavior;
1095 }
1096
1097 private boolean hasLongPressOnPowerBehavior() {
1098 return getResolvedLongPressOnPowerBehavior() != LONG_PRESS_POWER_NOTHING;
Jeff Brownd5bb82d2011-10-12 13:57:59 -07001099 }
1100
1101 private void interceptScreenshotChord() {
Christopher Tatee90585f2012-03-05 18:56:25 -08001102 if (mScreenshotChordEnabled
Jeff Brown13f00f02014-10-31 14:45:50 -07001103 && mScreenshotChordVolumeDownKeyTriggered && mScreenshotChordPowerKeyTriggered
1104 && !mScreenshotChordVolumeUpKeyTriggered) {
Jeff Brownd5bb82d2011-10-12 13:57:59 -07001105 final long now = SystemClock.uptimeMillis();
Jeff Brown13f00f02014-10-31 14:45:50 -07001106 if (now <= mScreenshotChordVolumeDownKeyTime + SCREENSHOT_CHORD_DEBOUNCE_DELAY_MILLIS
1107 && now <= mScreenshotChordPowerKeyTime
1108 + SCREENSHOT_CHORD_DEBOUNCE_DELAY_MILLIS) {
1109 mScreenshotChordVolumeDownKeyConsumed = true;
Jeff Brownd5bb82d2011-10-12 13:57:59 -07001110 cancelPendingPowerKeyAction();
1111
Jeff Sharkey2991fa32012-12-05 18:06:43 -08001112 mHandler.postDelayed(mScreenshotRunnable, getScreenshotChordLongPressDelay());
Jeff Brownd5bb82d2011-10-12 13:57:59 -07001113 }
1114 }
1115 }
1116
Winson Chung1cea2f32012-10-08 20:42:01 -07001117 private long getScreenshotChordLongPressDelay() {
Jim Miller5ecd8112013-01-09 18:50:26 -08001118 if (mKeyguardDelegate.isShowing()) {
Winson Chung1cea2f32012-10-08 20:42:01 -07001119 // Double the time it takes to take a screenshot from the keyguard
1120 return (long) (KEYGUARD_SCREENSHOT_CHORD_DELAY_MULTIPLIER *
Justin Kohfeabd2c2014-05-02 10:02:44 -07001121 ViewConfiguration.get(mContext).getDeviceGlobalActionKeyTimeout());
Winson Chung1cea2f32012-10-08 20:42:01 -07001122 }
Justin Kohfeabd2c2014-05-02 10:02:44 -07001123 return ViewConfiguration.get(mContext).getDeviceGlobalActionKeyTimeout();
Winson Chung1cea2f32012-10-08 20:42:01 -07001124 }
1125
Jeff Brownd5bb82d2011-10-12 13:57:59 -07001126 private void cancelPendingScreenshotChordAction() {
Jeff Sharkey2991fa32012-12-05 18:06:43 -08001127 mHandler.removeCallbacks(mScreenshotRunnable);
Jeff Brown4d396052010-10-29 21:50:21 -07001128 }
1129
Jeff Brown13f00f02014-10-31 14:45:50 -07001130 private final Runnable mEndCallLongPress = new Runnable() {
Craig Mautnerf1b67412012-09-19 13:18:29 -07001131 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001132 public void run() {
Jeff Brown13f00f02014-10-31 14:45:50 -07001133 mEndCallKeyHandled = true;
1134 if (!performHapticFeedbackLw(null, HapticFeedbackConstants.LONG_PRESS, false)) {
1135 performAuditoryFeedbackForAccessibilityIfNeed();
Joe Onoratod208e702010-10-08 16:22:43 -04001136 }
Jeff Brown13f00f02014-10-31 14:45:50 -07001137 showGlobalActionsInternal();
Jeff Brownd5bb82d2011-10-12 13:57:59 -07001138 }
1139 };
1140
Jeff Sharkey2991fa32012-12-05 18:06:43 -08001141 private final Runnable mScreenshotRunnable = new Runnable() {
Craig Mautner0bf6ec92012-12-18 08:33:27 -08001142 @Override
Jeff Brownd5bb82d2011-10-12 13:57:59 -07001143 public void run() {
1144 takeScreenshot();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001145 }
1146 };
1147
Alan Viverettee34560b22014-07-10 14:50:06 -07001148 @Override
1149 public void showGlobalActions() {
1150 mHandler.removeMessages(MSG_DISPATCH_SHOW_GLOBAL_ACTIONS);
1151 mHandler.sendEmptyMessage(MSG_DISPATCH_SHOW_GLOBAL_ACTIONS);
1152 }
1153
1154 void showGlobalActionsInternal() {
1155 sendCloseSystemWindows(SYSTEM_DIALOG_REASON_GLOBAL_ACTIONS);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001156 if (mGlobalActions == null) {
Jeff Brown7304c342012-05-11 18:42:42 -07001157 mGlobalActions = new GlobalActions(mContext, mWindowManagerFuncs);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001158 }
Jim Millerab954542014-10-10 18:21:49 -07001159 final boolean keyguardShowing = isKeyguardShowingAndNotOccluded();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001160 mGlobalActions.showDialog(keyguardShowing, isDeviceProvisioned());
1161 if (keyguardShowing) {
1162 // since it took two seconds of long press to bring this up,
1163 // poke the wake lock so they have some time to see the dialog.
Jim Miller25190572013-02-28 17:36:24 -08001164 mPowerManager.userActivity(SystemClock.uptimeMillis(), false);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001165 }
1166 }
1167
1168 boolean isDeviceProvisioned() {
Jeff Brownbf6f6f92012-09-25 15:03:20 -07001169 return Settings.Global.getInt(
1170 mContext.getContentResolver(), Settings.Global.DEVICE_PROVISIONED, 0) != 0;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001171 }
1172
Maurice Lam99c6e072014-04-28 18:24:28 -07001173 boolean isUserSetupComplete() {
1174 return Settings.Secure.getIntForUser(mContext.getContentResolver(),
1175 Settings.Secure.USER_SETUP_COMPLETE, 0, UserHandle.USER_CURRENT) != 0;
1176 }
1177
Jeff Brown13f00f02014-10-31 14:45:50 -07001178 private void handleShortPressOnHome() {
1179 // If there's a dream running then use home to escape the dream
1180 // but don't actually go home.
1181 if (mDreamManagerInternal != null && mDreamManagerInternal.isDreaming()) {
1182 mDreamManagerInternal.stopDream(false /*immediate*/);
1183 return;
1184 }
1185
1186 // Go home!
1187 launchHomeFromHotKey();
1188 }
1189
Patrick Dubroyece94522011-02-23 18:35:01 -08001190 private void handleLongPressOnHome() {
Joe Onorato46b0d682010-11-22 17:37:27 -08001191 if (mLongPressOnHomeBehavior != LONG_PRESS_HOME_NOTHING) {
Jeff Browncaca8812013-05-09 13:34:33 -07001192 mHomeConsumed = true;
Joe Onorato46b0d682010-11-22 17:37:27 -08001193 performHapticFeedbackLw(null, HapticFeedbackConstants.LONG_PRESS, false);
Patrick Dubroyece94522011-02-23 18:35:01 -08001194
Jeff Browncaca8812013-05-09 13:34:33 -07001195 if (mLongPressOnHomeBehavior == LONG_PRESS_HOME_RECENT_SYSTEM_UI) {
1196 toggleRecentApps();
1197 } else if (mLongPressOnHomeBehavior == LONG_PRESS_HOME_ASSIST) {
1198 launchAssistAction();
Jim Millere6ad1a82010-08-20 19:25:39 -07001199 }
1200 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001201 }
Patrick Dubroyece94522011-02-23 18:35:01 -08001202
Jeff Browncaca8812013-05-09 13:34:33 -07001203 private void handleDoubleTapOnHome() {
1204 if (mDoubleTapOnHomeBehavior == DOUBLE_TAP_HOME_RECENT_SYSTEM_UI) {
1205 mHomeConsumed = true;
1206 toggleRecentApps();
1207 }
1208 }
1209
1210 private final Runnable mHomeDoubleTapTimeoutRunnable = new Runnable() {
1211 @Override
1212 public void run() {
1213 if (mHomeDoubleTapPending) {
1214 mHomeDoubleTapPending = false;
Jeff Brown13f00f02014-10-31 14:45:50 -07001215 handleShortPressOnHome();
Jeff Browncaca8812013-05-09 13:34:33 -07001216 }
1217 }
1218 };
1219
Mark Renoufc1256912015-03-11 14:38:23 -04001220 private boolean isRoundWindow() {
Adam Powell01f280d2015-05-18 16:07:42 -07001221 return mContext.getResources().getConfiguration().isScreenRound();
Mark Renoufc1256912015-03-11 14:38:23 -04001222 }
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);
Mady Mellore82067b2015-04-30 09:58:35 -07001439 mStylusButtonPressVibePattern = getLongIntArray(mContext.getResources(),
1440 com.android.internal.R.array.config_stylusButtonPressVibePattern);
Daniel Sandler40427442010-07-16 11:44:52 -04001441
Christopher Tatee90585f2012-03-05 18:56:25 -08001442 mScreenshotChordEnabled = mContext.getResources().getBoolean(
1443 com.android.internal.R.bool.config_enableScreenshotChord);
1444
Justin Kohd378ad72013-04-01 12:18:26 -07001445 mGlobalKeyManager = new GlobalKeyManager(mContext);
1446
Joe Onoratoea495d42011-04-06 11:41:11 -07001447 // Controls rotation and the like.
1448 initializeHdmiState();
Dianne Hackborn40011092011-09-22 13:37:48 -07001449
1450 // Match current screen state.
Craig Mautnera631d492014-08-05 15:16:01 -07001451 if (!mPowerManager.isInteractive()) {
Jeff Brown140ffc72014-05-01 15:18:00 -07001452 goingToSleep(WindowManagerPolicy.OFF_BECAUSE_OF_USER);
Dianne Hackborn40011092011-09-22 13:37:48 -07001453 }
Jorim Jaggi24bec7c2015-02-04 12:40:14 +01001454
1455 mWindowManagerInternal.registerAppTransitionListener(
1456 mStatusBarController.getAppTransitionListener());
Mike Lockwood1753f7f2009-08-24 14:49:07 -07001457 }
1458
Jeff Brownf71343d2013-05-31 17:59:11 -07001459 /**
1460 * Read values from config.xml that may be overridden depending on
1461 * the configuration of the device.
1462 * eg. Disable long press on home goes to recents on sw600dp.
1463 */
1464 private void readConfigurationDependentBehaviors() {
1465 mLongPressOnHomeBehavior = mContext.getResources().getInteger(
1466 com.android.internal.R.integer.config_longPressOnHomeBehavior);
1467 if (mLongPressOnHomeBehavior < LONG_PRESS_HOME_NOTHING ||
1468 mLongPressOnHomeBehavior > LONG_PRESS_HOME_ASSIST) {
1469 mLongPressOnHomeBehavior = LONG_PRESS_HOME_NOTHING;
1470 }
1471
1472 mDoubleTapOnHomeBehavior = mContext.getResources().getInteger(
1473 com.android.internal.R.integer.config_doubleTapOnHomeBehavior);
1474 if (mDoubleTapOnHomeBehavior < DOUBLE_TAP_HOME_NOTHING ||
1475 mDoubleTapOnHomeBehavior > DOUBLE_TAP_HOME_RECENT_SYSTEM_UI) {
1476 mDoubleTapOnHomeBehavior = LONG_PRESS_HOME_NOTHING;
1477 }
1478 }
1479
Craig Mautner0bf6ec92012-12-18 08:33:27 -08001480 @Override
Dianne Hackborndde331c2012-08-03 14:01:57 -07001481 public void setInitialDisplaySize(Display display, int width, int height, int density) {
Jeff Brownef981a42013-08-07 14:13:37 -07001482 // This method might be called before the policy has been fully initialized
1483 // or for other displays we don't care about.
1484 if (mContext == null || display.getDisplayId() != Display.DEFAULT_DISPLAY) {
1485 return;
Dianne Hackbornc652de82013-02-15 16:32:56 -08001486 }
Dianne Hackbornf87d1962012-04-04 12:48:24 -07001487 mDisplay = display;
1488
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001489 final Resources res = mContext.getResources();
Dianne Hackbornf87d1962012-04-04 12:48:24 -07001490 int shortSize, longSize;
Dianne Hackborn9d132642011-04-21 17:26:39 -07001491 if (width > height) {
Dianne Hackborn81e56d52011-05-26 00:55:58 -07001492 shortSize = height;
Dianne Hackbornf87d1962012-04-04 12:48:24 -07001493 longSize = width;
Dianne Hackborn9d132642011-04-21 17:26:39 -07001494 mLandscapeRotation = Surface.ROTATION_0;
1495 mSeascapeRotation = Surface.ROTATION_180;
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001496 if (res.getBoolean(com.android.internal.R.bool.config_reverseDefaultRotation)) {
Dianne Hackborn9d132642011-04-21 17:26:39 -07001497 mPortraitRotation = Surface.ROTATION_90;
1498 mUpsideDownRotation = Surface.ROTATION_270;
1499 } else {
1500 mPortraitRotation = Surface.ROTATION_270;
1501 mUpsideDownRotation = Surface.ROTATION_90;
1502 }
1503 } else {
Dianne Hackborn81e56d52011-05-26 00:55:58 -07001504 shortSize = width;
Dianne Hackbornf87d1962012-04-04 12:48:24 -07001505 longSize = height;
Dianne Hackborn9d132642011-04-21 17:26:39 -07001506 mPortraitRotation = Surface.ROTATION_0;
1507 mUpsideDownRotation = Surface.ROTATION_180;
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001508 if (res.getBoolean(com.android.internal.R.bool.config_reverseDefaultRotation)) {
Dianne Hackborn9d132642011-04-21 17:26:39 -07001509 mLandscapeRotation = Surface.ROTATION_270;
1510 mSeascapeRotation = Surface.ROTATION_90;
1511 } else {
1512 mLandscapeRotation = Surface.ROTATION_90;
1513 mSeascapeRotation = Surface.ROTATION_270;
1514 }
1515 }
Dianne Hackborn81e56d52011-05-26 00:55:58 -07001516
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001517 mStatusBarHeight =
1518 res.getDimensionPixelSize(com.android.internal.R.dimen.status_bar_height);
Dianne Hackbornf87d1962012-04-04 12:48:24 -07001519
Daniel Sandler9f65c4c2012-04-26 01:35:35 -04001520 // Height of the navigation bar when presented horizontally at bottom
1521 mNavigationBarHeightForRotation[mPortraitRotation] =
1522 mNavigationBarHeightForRotation[mUpsideDownRotation] =
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001523 res.getDimensionPixelSize(com.android.internal.R.dimen.navigation_bar_height);
Daniel Sandler9f65c4c2012-04-26 01:35:35 -04001524 mNavigationBarHeightForRotation[mLandscapeRotation] =
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001525 mNavigationBarHeightForRotation[mSeascapeRotation] = res.getDimensionPixelSize(
1526 com.android.internal.R.dimen.navigation_bar_height_landscape);
Daniel Sandler9f65c4c2012-04-26 01:35:35 -04001527
1528 // Width of the navigation bar when presented vertically along one side
1529 mNavigationBarWidthForRotation[mPortraitRotation] =
1530 mNavigationBarWidthForRotation[mUpsideDownRotation] =
1531 mNavigationBarWidthForRotation[mLandscapeRotation] =
1532 mNavigationBarWidthForRotation[mSeascapeRotation] =
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001533 res.getDimensionPixelSize(com.android.internal.R.dimen.navigation_bar_width);
Daniel Sandler4a066c52012-04-20 14:49:13 -04001534
1535 // SystemUI (status bar) layout policy
Dianne Hackborndde331c2012-08-03 14:01:57 -07001536 int shortSizeDp = shortSize * DisplayMetrics.DENSITY_DEFAULT / density;
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001537 int longSizeDp = longSize * DisplayMetrics.DENSITY_DEFAULT / density;
Daniel Sandler4a066c52012-04-20 14:49:13 -04001538
Devin Kimd7b12b42014-05-05 14:34:58 -07001539 // Allow the navigation bar to move on non-square small devices (phones).
1540 mNavigationBarCanMove = width != height && shortSizeDp < 600;
Daniel Sandler36412a72011-08-04 09:35:13 -04001541
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001542 mHasNavigationBar = res.getBoolean(com.android.internal.R.bool.config_showNavigationBar);
John Spurlock80f00c12013-06-13 11:10:51 -04001543 // Allow a system property to override this. Used by the emulator.
1544 // See also hasNavigationBar().
1545 String navBarOverride = SystemProperties.get("qemu.hw.mainkeys");
1546 if ("1".equals(navBarOverride)) {
Dianne Hackbornf87d1962012-04-04 12:48:24 -07001547 mHasNavigationBar = false;
John Spurlock80f00c12013-06-13 11:10:51 -04001548 } else if ("0".equals(navBarOverride)) {
1549 mHasNavigationBar = true;
Daniel Sandler0c4ccff2011-10-19 16:39:14 -04001550 }
1551
Jeff Brown27f1d672012-10-17 18:32:34 -07001552 // For demo purposes, allow the rotation of the HDMI display to be controlled.
1553 // By default, HDMI locks rotation to landscape.
Erik Gilling9a41ef82011-09-26 19:21:03 -07001554 if ("portrait".equals(SystemProperties.get("persist.demo.hdmirotation"))) {
Jeff Brownc82c89ed2013-04-17 17:18:15 -07001555 mDemoHdmiRotation = mPortraitRotation;
Erik Gilling9a41ef82011-09-26 19:21:03 -07001556 } else {
Jeff Brownc82c89ed2013-04-17 17:18:15 -07001557 mDemoHdmiRotation = mLandscapeRotation;
Erik Gilling9a41ef82011-09-26 19:21:03 -07001558 }
Jeff Brownc82c89ed2013-04-17 17:18:15 -07001559 mDemoHdmiRotationLock = SystemProperties.getBoolean("persist.demo.hdmirotationlock", false);
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001560
Chong Zhangae6119ff2014-11-11 18:54:39 -08001561 // For demo purposes, allow the rotation of the remote display to be controlled.
1562 // By default, remote display locks rotation to landscape.
1563 if ("portrait".equals(SystemProperties.get("persist.demo.remoterotation"))) {
1564 mDemoRotation = mPortraitRotation;
1565 } else {
1566 mDemoRotation = mLandscapeRotation;
1567 }
1568 mDemoRotationLock = SystemProperties.getBoolean(
1569 "persist.demo.rotationlock", false);
1570
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001571 // Only force the default orientation if the screen is xlarge, at least 960dp x 720dp, per
1572 // http://developer.android.com/guide/practices/screens_support.html#range
1573 mForceDefaultOrientation = longSizeDp >= 960 && shortSizeDp >= 720 &&
1574 res.getBoolean(com.android.internal.R.bool.config_forceDefaultOrientation) &&
1575 // For debug purposes the next line turns this feature off with:
1576 // $ adb shell setprop config.override_forced_orient true
1577 // $ adb shell wm size reset
1578 !"true".equals(SystemProperties.get("config.override_forced_orient"));
1579 }
1580
Alan Viverette5a0f4ec2013-10-07 15:10:29 -07001581 /**
1582 * @return whether the navigation bar can be hidden, e.g. the device has a
1583 * navigation bar and touch exploration is not enabled
1584 */
1585 private boolean canHideNavigationBar() {
Svetoslav8e3feb12014-02-24 13:46:47 -08001586 return mHasNavigationBar
1587 && !mAccessibilityManager.isTouchExplorationEnabled();
Alan Viverette5a0f4ec2013-10-07 15:10:29 -07001588 }
1589
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001590 @Override
1591 public boolean isDefaultOrientationForced() {
1592 return mForceDefaultOrientation;
Dianne Hackborn9d132642011-04-21 17:26:39 -07001593 }
1594
Dianne Hackbornc652de82013-02-15 16:32:56 -08001595 @Override
1596 public void setDisplayOverscan(Display display, int left, int top, int right, int bottom) {
1597 if (display.getDisplayId() == Display.DEFAULT_DISPLAY) {
1598 mOverscanLeft = left;
1599 mOverscanTop = top;
1600 mOverscanRight = right;
1601 mOverscanBottom = bottom;
1602 }
1603 }
1604
Dianne Hackbornc777e072010-02-12 13:07:59 -08001605 public void updateSettings() {
1606 ContentResolver resolver = mContext.getContentResolver();
1607 boolean updateRotation = false;
Dianne Hackbornc777e072010-02-12 13:07:59 -08001608 synchronized (mLock) {
Christopher Tate5e08af02012-09-21 17:17:22 -07001609 mEndcallBehavior = Settings.System.getIntForUser(resolver,
David Brownbaf8d092010-03-08 21:52:59 -08001610 Settings.System.END_BUTTON_BEHAVIOR,
Christopher Tate5e08af02012-09-21 17:17:22 -07001611 Settings.System.END_BUTTON_BEHAVIOR_DEFAULT,
1612 UserHandle.USER_CURRENT);
1613 mIncallPowerBehavior = Settings.Secure.getIntForUser(resolver,
David Brownbaf8d092010-03-08 21:52:59 -08001614 Settings.Secure.INCALL_POWER_BUTTON_BEHAVIOR,
Christopher Tate5e08af02012-09-21 17:17:22 -07001615 Settings.Secure.INCALL_POWER_BUTTON_BEHAVIOR_DEFAULT,
1616 UserHandle.USER_CURRENT);
Daniel Sandlerb73617d2010-08-17 00:41:00 -04001617
Jeff Browna20dda42014-05-27 20:57:24 -07001618 // Configure wake gesture.
1619 boolean wakeGestureEnabledSetting = Settings.Secure.getIntForUser(resolver,
1620 Settings.Secure.WAKE_GESTURE_ENABLED, 0,
1621 UserHandle.USER_CURRENT) != 0;
1622 if (mWakeGestureEnabledSetting != wakeGestureEnabledSetting) {
1623 mWakeGestureEnabledSetting = wakeGestureEnabledSetting;
1624 updateWakeGestureListenerLp();
1625 }
1626
Jeff Brown207673cd2012-06-05 17:47:11 -07001627 // Configure rotation lock.
Christopher Tate5e08af02012-09-21 17:17:22 -07001628 int userRotation = Settings.System.getIntForUser(resolver,
1629 Settings.System.USER_ROTATION, Surface.ROTATION_0,
1630 UserHandle.USER_CURRENT);
Jeff Brown207673cd2012-06-05 17:47:11 -07001631 if (mUserRotation != userRotation) {
1632 mUserRotation = userRotation;
1633 updateRotation = true;
1634 }
Christopher Tate5e08af02012-09-21 17:17:22 -07001635 int userRotationMode = Settings.System.getIntForUser(resolver,
1636 Settings.System.ACCELEROMETER_ROTATION, 0, UserHandle.USER_CURRENT) != 0 ?
Jeff Brown207673cd2012-06-05 17:47:11 -07001637 WindowManagerPolicy.USER_ROTATION_FREE :
1638 WindowManagerPolicy.USER_ROTATION_LOCKED;
1639 if (mUserRotationMode != userRotationMode) {
1640 mUserRotationMode = userRotationMode;
1641 updateRotation = true;
Dianne Hackbornc777e072010-02-12 13:07:59 -08001642 updateOrientationListenerLp();
1643 }
Daniel Sandlerb73617d2010-08-17 00:41:00 -04001644
Dianne Hackbornc777e072010-02-12 13:07:59 -08001645 if (mSystemReady) {
Christopher Tate5e08af02012-09-21 17:17:22 -07001646 int pointerLocation = Settings.System.getIntForUser(resolver,
1647 Settings.System.POINTER_LOCATION, 0, UserHandle.USER_CURRENT);
Dianne Hackbornc777e072010-02-12 13:07:59 -08001648 if (mPointerLocationMode != pointerLocation) {
1649 mPointerLocationMode = pointerLocation;
Jeff Brown70825162012-03-28 17:27:48 -07001650 mHandler.sendEmptyMessage(pointerLocation != 0 ?
1651 MSG_ENABLE_POINTER_LOCATION : MSG_DISABLE_POINTER_LOCATION);
Dianne Hackbornc777e072010-02-12 13:07:59 -08001652 }
1653 }
1654 // use screen off timeout setting as the timeout for the lockscreen
Christopher Tate5e08af02012-09-21 17:17:22 -07001655 mLockScreenTimeout = Settings.System.getIntForUser(resolver,
1656 Settings.System.SCREEN_OFF_TIMEOUT, 0, UserHandle.USER_CURRENT);
1657 String imId = Settings.Secure.getStringForUser(resolver,
1658 Settings.Secure.DEFAULT_INPUT_METHOD, UserHandle.USER_CURRENT);
Dianne Hackbornc777e072010-02-12 13:07:59 -08001659 boolean hasSoftInput = imId != null && imId.length() > 0;
1660 if (mHasSoftInput != hasSoftInput) {
1661 mHasSoftInput = hasSoftInput;
1662 updateRotation = true;
1663 }
John Spurlockf1a36642013-10-12 17:50:42 -04001664 if (mImmersiveModeConfirmation != null) {
John Spurlock4355a532014-02-19 09:49:25 -05001665 mImmersiveModeConfirmation.loadSetting(mCurrentUserId);
John Spurlockd67ec252013-09-05 11:31:54 -04001666 }
John Spurlockc6d1c602014-01-17 15:22:06 -05001667 PolicyControl.reloadFromSetting(mContext);
Dianne Hackbornc777e072010-02-12 13:07:59 -08001668 }
1669 if (updateRotation) {
Jeff Brown01a98dd2011-09-20 15:08:29 -07001670 updateRotation(true);
Dianne Hackbornc777e072010-02-12 13:07:59 -08001671 }
Jeff Brown70825162012-03-28 17:27:48 -07001672 }
1673
Jeff Browna20dda42014-05-27 20:57:24 -07001674 private void updateWakeGestureListenerLp() {
1675 if (shouldEnableWakeGestureLp()) {
1676 mWakeGestureListener.requestWakeUpTrigger();
1677 } else {
1678 mWakeGestureListener.cancelWakeUpTrigger();
1679 }
1680 }
1681
1682 private boolean shouldEnableWakeGestureLp() {
Jeff Brown3ee549c2014-09-22 20:14:39 -07001683 return mWakeGestureEnabledSetting && !mAwake
Jeff Browna20dda42014-05-27 20:57:24 -07001684 && (!mLidControlsSleep || mLidState != LID_CLOSED)
1685 && mWakeGestureListener.isSupported();
1686 }
1687
Jeff Brown70825162012-03-28 17:27:48 -07001688 private void enablePointerLocation() {
1689 if (mPointerLocationView == null) {
1690 mPointerLocationView = new PointerLocationView(mContext);
1691 mPointerLocationView.setPrintCoords(false);
Dianne Hackbornc777e072010-02-12 13:07:59 -08001692 WindowManager.LayoutParams lp = new WindowManager.LayoutParams(
1693 WindowManager.LayoutParams.MATCH_PARENT,
1694 WindowManager.LayoutParams.MATCH_PARENT);
Jeff Brown3b2b3542010-10-15 00:54:27 -07001695 lp.type = WindowManager.LayoutParams.TYPE_SECURE_SYSTEM_OVERLAY;
Jeff Brownbfcb60a2011-09-08 18:51:14 -07001696 lp.flags = WindowManager.LayoutParams.FLAG_FULLSCREEN
1697 | WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE
1698 | WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE
1699 | WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN;
Jeff Brown90fc9052012-10-01 14:44:24 -07001700 if (ActivityManager.isHighEndGfx()) {
1701 lp.flags |= WindowManager.LayoutParams.FLAG_HARDWARE_ACCELERATED;
1702 lp.privateFlags |=
1703 WindowManager.LayoutParams.PRIVATE_FLAG_FORCE_HARDWARE_ACCELERATED;
1704 }
Dianne Hackbornc777e072010-02-12 13:07:59 -08001705 lp.format = PixelFormat.TRANSLUCENT;
1706 lp.setTitle("PointerLocation");
Dianne Hackborn5fd21692011-06-07 14:09:47 -07001707 WindowManager wm = (WindowManager)
Dianne Hackbornc777e072010-02-12 13:07:59 -08001708 mContext.getSystemService(Context.WINDOW_SERVICE);
Jeff Browncc4f7db2011-08-30 20:34:48 -07001709 lp.inputFeatures |= WindowManager.LayoutParams.INPUT_FEATURE_NO_INPUT_CHANNEL;
Jeff Brown70825162012-03-28 17:27:48 -07001710 wm.addView(mPointerLocationView, lp);
Michael Wrightc9c487e2013-11-07 18:55:09 -08001711 mWindowManagerFuncs.registerPointerEventListener(mPointerLocationView);
Dianne Hackbornc777e072010-02-12 13:07:59 -08001712 }
Dianne Hackbornc777e072010-02-12 13:07:59 -08001713 }
Jeff Brown70825162012-03-28 17:27:48 -07001714
1715 private void disablePointerLocation() {
Jeff Brown70825162012-03-28 17:27:48 -07001716 if (mPointerLocationView != null) {
Michael Wrightc9c487e2013-11-07 18:55:09 -08001717 mWindowManagerFuncs.unregisterPointerEventListener(mPointerLocationView);
1718 WindowManager wm = (WindowManager) mContext.getSystemService(Context.WINDOW_SERVICE);
Jeff Brown70825162012-03-28 17:27:48 -07001719 wm.removeView(mPointerLocationView);
1720 mPointerLocationView = null;
1721 }
1722 }
1723
Mike Lockwood2d1efbd2009-09-16 12:15:53 -04001724 private int readRotation(int resID) {
Mike Lockwood1753f7f2009-08-24 14:49:07 -07001725 try {
1726 int rotation = mContext.getResources().getInteger(resID);
1727 switch (rotation) {
1728 case 0:
1729 return Surface.ROTATION_0;
1730 case 90:
1731 return Surface.ROTATION_90;
1732 case 180:
1733 return Surface.ROTATION_180;
1734 case 270:
1735 return Surface.ROTATION_270;
Mike Lockwood1753f7f2009-08-24 14:49:07 -07001736 }
1737 } catch (Resources.NotFoundException e) {
Mike Lockwood2d1efbd2009-09-16 12:15:53 -04001738 // fall through
Mike Lockwood1753f7f2009-08-24 14:49:07 -07001739 }
Mike Lockwood2d1efbd2009-09-16 12:15:53 -04001740 return -1;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001741 }
1742
1743 /** {@inheritDoc} */
Craig Mautner88400d32012-09-30 12:35:45 -07001744 @Override
Dianne Hackbornc2293022013-02-06 23:14:49 -08001745 public int checkAddPermission(WindowManager.LayoutParams attrs, int[] outAppOp) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001746 int type = attrs.type;
Dianne Hackbornc2293022013-02-06 23:14:49 -08001747
1748 outAppOp[0] = AppOpsManager.OP_NONE;
1749
Wale Ogunwale74bf0652015-01-12 10:24:36 -08001750 if (!((type >= FIRST_APPLICATION_WINDOW && type <= LAST_APPLICATION_WINDOW)
1751 || (type >= FIRST_SUB_WINDOW && type <= LAST_SUB_WINDOW)
1752 || (type >= FIRST_SYSTEM_WINDOW && type <= LAST_SYSTEM_WINDOW))) {
1753 return WindowManagerGlobal.ADD_INVALID_TYPE;
1754 }
1755
1756 if (type < FIRST_SYSTEM_WINDOW || type > LAST_SYSTEM_WINDOW) {
1757 // Window manager will make sure these are okay.
Jeff Brown98365d72012-08-19 20:30:52 -07001758 return WindowManagerGlobal.ADD_OKAY;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001759 }
1760 String permission = null;
1761 switch (type) {
1762 case TYPE_TOAST:
1763 // XXX right now the app process has complete control over
1764 // this... should introduce a token to let the system
1765 // monitor/control what they are doing.
Jason Monk1c7c3192014-06-26 12:52:18 -04001766 outAppOp[0] = AppOpsManager.OP_TOAST_WINDOW;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001767 break;
Daniel Sandler7d276c32012-01-30 14:33:52 -05001768 case TYPE_DREAM:
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001769 case TYPE_INPUT_METHOD:
Dianne Hackbornb7cd8b92009-08-08 20:53:03 -07001770 case TYPE_WALLPAPER:
keunyounga446bf02013-06-21 19:07:57 -07001771 case TYPE_PRIVATE_PRESENTATION:
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001772 case TYPE_VOICE_INTERACTION:
Svetoslav3a5c7212014-10-14 09:54:26 -07001773 case TYPE_ACCESSIBILITY_OVERLAY:
Dianne Hackbornb7cd8b92009-08-08 20:53:03 -07001774 // The window manager will check these.
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001775 break;
1776 case TYPE_PHONE:
1777 case TYPE_PRIORITY_PHONE:
1778 case TYPE_SYSTEM_ALERT:
1779 case TYPE_SYSTEM_ERROR:
1780 case TYPE_SYSTEM_OVERLAY:
1781 permission = android.Manifest.permission.SYSTEM_ALERT_WINDOW;
Dianne Hackbornc2293022013-02-06 23:14:49 -08001782 outAppOp[0] = AppOpsManager.OP_SYSTEM_ALERT_WINDOW;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001783 break;
1784 default:
1785 permission = android.Manifest.permission.INTERNAL_SYSTEM_WINDOW;
1786 }
1787 if (permission != null) {
1788 if (mContext.checkCallingOrSelfPermission(permission)
1789 != PackageManager.PERMISSION_GRANTED) {
Jeff Brown98365d72012-08-19 20:30:52 -07001790 return WindowManagerGlobal.ADD_PERMISSION_DENIED;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001791 }
1792 }
Jeff Brown98365d72012-08-19 20:30:52 -07001793 return WindowManagerGlobal.ADD_OKAY;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001794 }
Craig Mautner88400d32012-09-30 12:35:45 -07001795
1796 @Override
1797 public boolean checkShowToOwnerOnly(WindowManager.LayoutParams attrs) {
1798
1799 // If this switch statement is modified, modify the comment in the declarations of
1800 // the type in {@link WindowManager.LayoutParams} as well.
1801 switch (attrs.type) {
1802 default:
1803 // These are the windows that by default are shown only to the user that created
1804 // them. If this needs to be overridden, set
1805 // {@link WindowManager.LayoutParams.PRIVATE_FLAG_SHOW_FOR_ALL_USERS} in
1806 // {@link WindowManager.LayoutParams}. Note that permission
1807 // {@link android.Manifest.permission.INTERNAL_SYSTEM_WINDOW} is required as well.
1808 if ((attrs.privateFlags & PRIVATE_FLAG_SHOW_FOR_ALL_USERS) == 0) {
1809 return true;
1810 }
1811 break;
1812
1813 // These are the windows that by default are shown to all users. However, to
1814 // protect against spoofing, check permissions below.
1815 case TYPE_APPLICATION_STARTING:
1816 case TYPE_BOOT_PROGRESS:
1817 case TYPE_DISPLAY_OVERLAY:
Selim Cinekf83e8242015-05-19 18:08:14 -07001818 case TYPE_INPUT_CONSUMER:
Jim Miller5ecd8112013-01-09 18:50:26 -08001819 case TYPE_KEYGUARD_SCRIM:
Craig Mautner88400d32012-09-30 12:35:45 -07001820 case TYPE_KEYGUARD_DIALOG:
1821 case TYPE_MAGNIFICATION_OVERLAY:
1822 case TYPE_NAVIGATION_BAR:
1823 case TYPE_NAVIGATION_BAR_PANEL:
1824 case TYPE_PHONE:
1825 case TYPE_POINTER:
1826 case TYPE_PRIORITY_PHONE:
Craig Mautner88400d32012-09-30 12:35:45 -07001827 case TYPE_SEARCH_BAR:
1828 case TYPE_STATUS_BAR:
1829 case TYPE_STATUS_BAR_PANEL:
1830 case TYPE_STATUS_BAR_SUB_PANEL:
1831 case TYPE_SYSTEM_DIALOG:
Craig Mautner88400d32012-09-30 12:35:45 -07001832 case TYPE_VOLUME_OVERLAY:
keunyounga446bf02013-06-21 19:07:57 -07001833 case TYPE_PRIVATE_PRESENTATION:
Craig Mautner88400d32012-09-30 12:35:45 -07001834 break;
1835 }
1836
1837 // Check if third party app has set window to system window type.
1838 return mContext.checkCallingOrSelfPermission(
1839 android.Manifest.permission.INTERNAL_SYSTEM_WINDOW)
1840 != PackageManager.PERMISSION_GRANTED;
1841 }
1842
Craig Mautner967212c2013-04-13 21:10:58 -07001843 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001844 public void adjustWindowParamsLw(WindowManager.LayoutParams attrs) {
1845 switch (attrs.type) {
1846 case TYPE_SYSTEM_OVERLAY:
Jeff Brown3b2b3542010-10-15 00:54:27 -07001847 case TYPE_SECURE_SYSTEM_OVERLAY:
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001848 // These types of windows can't receive input events.
1849 attrs.flags |= WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE
1850 | WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE;
Jeff Brownbfcb60a2011-09-08 18:51:14 -07001851 attrs.flags &= ~WindowManager.LayoutParams.FLAG_WATCH_OUTSIDE_TOUCH;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001852 break;
Jorim Jaggi380ecb82014-03-14 17:25:20 +01001853 case TYPE_STATUS_BAR:
1854
1855 // If the Keyguard is in a hidden state (occluded by another window), we force to
1856 // remove the wallpaper and keyguard flag so that any change in-flight after setting
1857 // the keyguard as occluded wouldn't set these flags again.
1858 // See {@link #processKeyguardSetHiddenResultLw}.
1859 if (mKeyguardHidden) {
1860 attrs.flags &= ~WindowManager.LayoutParams.FLAG_SHOW_WALLPAPER;
1861 attrs.privateFlags &= ~WindowManager.LayoutParams.PRIVATE_FLAG_KEYGUARD;
1862 }
1863 break;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001864 }
Adrian Roos38502112014-04-09 21:04:11 +02001865
1866 if (attrs.type != TYPE_STATUS_BAR) {
1867 // The status bar is the only window allowed to exhibit keyguard behavior.
1868 attrs.privateFlags &= ~WindowManager.LayoutParams.PRIVATE_FLAG_KEYGUARD;
1869 }
Adrian Roosea562512014-05-05 13:33:03 +02001870
1871 if (ActivityManager.isHighEndGfx()
1872 && (attrs.flags & FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS) != 0) {
Adrian Roosf5e9b5c2014-09-10 15:27:41 +02001873 attrs.subtreeSystemUiVisibility |= View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
Adrian Roosea562512014-05-05 13:33:03 +02001874 | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION;
1875 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001876 }
RoboErik8a2cfc32014-05-16 11:19:38 -07001877
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001878 void readLidState() {
Jeff Brown2e7760e2012-04-11 15:14:55 -07001879 mLidState = mWindowManagerFuncs.getLidState();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001880 }
RoboErik8a2cfc32014-05-16 11:19:38 -07001881
Michael Wright3818c922014-09-02 13:59:07 -07001882 private void readCameraLensCoverState() {
1883 mCameraLensCoverState = mWindowManagerFuncs.getCameraLensCoverState();
1884 }
1885
Jeff Browndaa37532012-05-01 15:54:03 -07001886 private boolean isHidden(int accessibilityMode) {
1887 switch (accessibilityMode) {
1888 case 1:
1889 return mLidState == LID_CLOSED;
1890 case 2:
1891 return mLidState == LID_OPEN;
1892 default:
1893 return false;
Dianne Hackborn2862fff2009-09-15 22:56:29 -07001894 }
Dianne Hackborn2862fff2009-09-15 22:56:29 -07001895 }
Jeff Brownd04a88c2011-01-16 14:05:47 -08001896
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001897 /** {@inheritDoc} */
Craig Mautner967212c2013-04-13 21:10:58 -07001898 @Override
Jeff Browndaa37532012-05-01 15:54:03 -07001899 public void adjustConfigurationLw(Configuration config, int keyboardPresence,
1900 int navigationPresence) {
1901 mHaveBuiltInKeyboard = (keyboardPresence & PRESENCE_INTERNAL) != 0;
1902
Jeff Brownf71343d2013-05-31 17:59:11 -07001903 readConfigurationDependentBehaviors();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001904 readLidState();
Jeff Brownc458ce92012-04-30 14:58:40 -07001905 applyLidSwitchState();
Jeff Brownd04a88c2011-01-16 14:05:47 -08001906
Jeff Browndaa37532012-05-01 15:54:03 -07001907 if (config.keyboard == Configuration.KEYBOARD_NOKEYS
1908 || (keyboardPresence == PRESENCE_INTERNAL
1909 && isHidden(mLidKeyboardAccessibility))) {
Jeff Brownd04a88c2011-01-16 14:05:47 -08001910 config.hardKeyboardHidden = Configuration.HARDKEYBOARDHIDDEN_YES;
Jeff Browndaa37532012-05-01 15:54:03 -07001911 if (!mHasSoftInput) {
1912 config.keyboardHidden = Configuration.KEYBOARDHIDDEN_YES;
1913 }
Jeff Brownd04a88c2011-01-16 14:05:47 -08001914 }
1915
Jeff Browndaa37532012-05-01 15:54:03 -07001916 if (config.navigation == Configuration.NAVIGATION_NONAV
1917 || (navigationPresence == PRESENCE_INTERNAL
1918 && isHidden(mLidNavigationAccessibility))) {
Jeff Brownd04a88c2011-01-16 14:05:47 -08001919 config.navigationHidden = Configuration.NAVIGATIONHIDDEN_YES;
Jeff Brownd04a88c2011-01-16 14:05:47 -08001920 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001921 }
Jeff Brownd04a88c2011-01-16 14:05:47 -08001922
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001923 /** {@inheritDoc} */
Craig Mautner967212c2013-04-13 21:10:58 -07001924 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001925 public int windowTypeToLayerLw(int type) {
1926 if (type >= FIRST_APPLICATION_WINDOW && type <= LAST_APPLICATION_WINDOW) {
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001927 return 2;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001928 }
1929 switch (type) {
keunyounga446bf02013-06-21 19:07:57 -07001930 case TYPE_PRIVATE_PRESENTATION:
1931 return 2;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001932 case TYPE_WALLPAPER:
1933 // wallpaper is at the bottom, though the window manager may move it.
1934 return 2;
1935 case TYPE_PHONE:
1936 return 3;
1937 case TYPE_SEARCH_BAR:
Jorim Jaggi225d3b52015-04-01 11:18:57 -07001938 case TYPE_VOICE_INTERACTION_STARTING:
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001939 return 4;
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001940 case TYPE_VOICE_INTERACTION:
1941 // voice interaction layer is almost immediately above apps.
1942 return 5;
Selim Cinekf83e8242015-05-19 18:08:14 -07001943 case TYPE_INPUT_CONSUMER:
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001944 return 6;
Selim Cinekf83e8242015-05-19 18:08:14 -07001945 case TYPE_SYSTEM_DIALOG:
1946 return 7;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001947 case TYPE_TOAST:
1948 // toasts and the plugged-in battery thing
Selim Cinekf83e8242015-05-19 18:08:14 -07001949 return 8;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001950 case TYPE_PRIORITY_PHONE:
1951 // SIM errors and unlock. Not sure if this really should be in a high layer.
Selim Cinekf83e8242015-05-19 18:08:14 -07001952 return 9;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001953 case TYPE_DREAM:
1954 // used for Dreams (screensavers with TYPE_DREAM windows)
Selim Cinekf83e8242015-05-19 18:08:14 -07001955 return 10;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001956 case TYPE_SYSTEM_ALERT:
1957 // like the ANR / app crashed dialogs
Selim Cinekf83e8242015-05-19 18:08:14 -07001958 return 11;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001959 case TYPE_INPUT_METHOD:
1960 // on-screen keyboards and other such input method user interfaces go here.
Selim Cinekf83e8242015-05-19 18:08:14 -07001961 return 12;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001962 case TYPE_INPUT_METHOD_DIALOG:
1963 // on-screen keyboards and other such input method user interfaces go here.
Selim Cinekf83e8242015-05-19 18:08:14 -07001964 return 13;
Jim Miller5ecd8112013-01-09 18:50:26 -08001965 case TYPE_KEYGUARD_SCRIM:
1966 // the safety window that shows behind keyguard while keyguard is starting
Jorim Jaggi380ecb82014-03-14 17:25:20 +01001967 return 14;
Selim Cinekf83e8242015-05-19 18:08:14 -07001968 case TYPE_STATUS_BAR_SUB_PANEL:
Jorim Jaggi380ecb82014-03-14 17:25:20 +01001969 return 15;
Selim Cinekf83e8242015-05-19 18:08:14 -07001970 case TYPE_STATUS_BAR:
Jorim Jaggi380ecb82014-03-14 17:25:20 +01001971 return 16;
Selim Cinekf83e8242015-05-19 18:08:14 -07001972 case TYPE_STATUS_BAR_PANEL:
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001973 return 17;
Selim Cinekf83e8242015-05-19 18:08:14 -07001974 case TYPE_KEYGUARD_DIALOG:
1975 return 18;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001976 case TYPE_VOLUME_OVERLAY:
1977 // the on-screen volume indicator and controller shown when the user
1978 // changes the device volume
Selim Cinekf83e8242015-05-19 18:08:14 -07001979 return 19;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001980 case TYPE_SYSTEM_OVERLAY:
1981 // the on-screen volume indicator and controller shown when the user
1982 // changes the device volume
Selim Cinekf83e8242015-05-19 18:08:14 -07001983 return 20;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001984 case TYPE_NAVIGATION_BAR:
1985 // the navigation bar, if available, shows atop most things
Selim Cinekf83e8242015-05-19 18:08:14 -07001986 return 21;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001987 case TYPE_NAVIGATION_BAR_PANEL:
1988 // some panels (e.g. search) need to show on top of the navigation bar
Selim Cinekf83e8242015-05-19 18:08:14 -07001989 return 22;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001990 case TYPE_SYSTEM_ERROR:
1991 // system-level error dialogs
Selim Cinekf83e8242015-05-19 18:08:14 -07001992 return 23;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001993 case TYPE_MAGNIFICATION_OVERLAY:
1994 // used to highlight the magnified portion of a display
Selim Cinekf83e8242015-05-19 18:08:14 -07001995 return 24;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001996 case TYPE_DISPLAY_OVERLAY:
1997 // used to simulate secondary display devices
Selim Cinekf83e8242015-05-19 18:08:14 -07001998 return 25;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001999 case TYPE_DRAG:
2000 // the drag layer: input for drag-and-drop is associated with this window,
2001 // which sits above all other focusable windows
Selim Cinekf83e8242015-05-19 18:08:14 -07002002 return 26;
Svetoslav3a5c7212014-10-14 09:54:26 -07002003 case TYPE_ACCESSIBILITY_OVERLAY:
2004 // overlay put by accessibility services to intercept user interaction
Dianne Hackborne30e02f2014-05-27 18:24:45 -07002005 return 27;
Selim Cinekf83e8242015-05-19 18:08:14 -07002006 case TYPE_SECURE_SYSTEM_OVERLAY:
Svetoslav3a5c7212014-10-14 09:54:26 -07002007 return 28;
Selim Cinekf83e8242015-05-19 18:08:14 -07002008 case TYPE_BOOT_PROGRESS:
2009 return 29;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07002010 case TYPE_POINTER:
2011 // the (mouse) pointer layer
Svetoslav3a5c7212014-10-14 09:54:26 -07002012 return 30;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002013 }
2014 Log.e(TAG, "Unknown window type: " + type);
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07002015 return 2;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002016 }
2017
2018 /** {@inheritDoc} */
Craig Mautner46ac6fa2013-08-01 10:06:34 -07002019 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002020 public int subWindowTypeToLayerLw(int type) {
2021 switch (type) {
2022 case TYPE_APPLICATION_PANEL:
2023 case TYPE_APPLICATION_ATTACHED_DIALOG:
2024 return APPLICATION_PANEL_SUBLAYER;
2025 case TYPE_APPLICATION_MEDIA:
2026 return APPLICATION_MEDIA_SUBLAYER;
Dianne Hackborn5cb8d792009-05-21 17:34:15 -07002027 case TYPE_APPLICATION_MEDIA_OVERLAY:
2028 return APPLICATION_MEDIA_OVERLAY_SUBLAYER;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002029 case TYPE_APPLICATION_SUB_PANEL:
2030 return APPLICATION_SUB_PANEL_SUBLAYER;
Wale Ogunwale0a4dc222015-04-14 12:58:42 -07002031 case TYPE_APPLICATION_ABOVE_SUB_PANEL:
2032 return APPLICATION_ABOVE_SUB_PANEL_SUBLAYER;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002033 }
2034 Log.e(TAG, "Unknown sub-window type: " + type);
2035 return 0;
2036 }
2037
Craig Mautner46ac6fa2013-08-01 10:06:34 -07002038 @Override
Dianne Hackbornabe0da02009-09-18 01:55:39 -07002039 public int getMaxWallpaperLayer() {
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07002040 return windowTypeToLayerLw(TYPE_STATUS_BAR);
Dianne Hackbornabe0da02009-09-18 01:55:39 -07002041 }
2042
Craig Mautner46ac6fa2013-08-01 10:06:34 -07002043 @Override
Dianne Hackborn1f903c32011-09-13 19:18:06 -07002044 public int getNonDecorDisplayWidth(int fullWidth, int fullHeight, int rotation) {
Dianne Hackborn077ee852012-04-09 16:27:07 -07002045 if (mHasNavigationBar) {
2046 // For a basic navigation bar, when we are in landscape mode we place
2047 // the navigation bar to the side.
Daniel Sandler4a066c52012-04-20 14:49:13 -04002048 if (mNavigationBarCanMove && fullWidth > fullHeight) {
2049 return fullWidth - mNavigationBarWidthForRotation[rotation];
Dianne Hackborn077ee852012-04-09 16:27:07 -07002050 }
Dianne Hackborn1f903c32011-09-13 19:18:06 -07002051 }
2052 return fullWidth;
Dianne Hackborne2515ee2011-04-27 18:52:56 -04002053 }
2054
Jose Lima9546b202014-07-02 17:21:51 -07002055 @Override
Dianne Hackborn1f903c32011-09-13 19:18:06 -07002056 public int getNonDecorDisplayHeight(int fullWidth, int fullHeight, int rotation) {
Dianne Hackborn077ee852012-04-09 16:27:07 -07002057 if (mHasNavigationBar) {
2058 // For a basic navigation bar, when we are in portrait mode we place
2059 // the navigation bar to the bottom.
Daniel Sandler4a066c52012-04-20 14:49:13 -04002060 if (!mNavigationBarCanMove || fullWidth < fullHeight) {
2061 return fullHeight - mNavigationBarHeightForRotation[rotation];
Dianne Hackborn077ee852012-04-09 16:27:07 -07002062 }
2063 }
2064 return fullHeight;
Dianne Hackborn69cb8752011-05-19 18:13:32 -07002065 }
2066
Jose Lima9546b202014-07-02 17:21:51 -07002067 @Override
Dianne Hackborn1f903c32011-09-13 19:18:06 -07002068 public int getConfigDisplayWidth(int fullWidth, int fullHeight, int rotation) {
2069 return getNonDecorDisplayWidth(fullWidth, fullHeight, rotation);
Dianne Hackborn69cb8752011-05-19 18:13:32 -07002070 }
2071
Jose Lima9546b202014-07-02 17:21:51 -07002072 @Override
Dianne Hackborn1f903c32011-09-13 19:18:06 -07002073 public int getConfigDisplayHeight(int fullWidth, int fullHeight, int rotation) {
John Spurlock80f00c12013-06-13 11:10:51 -04002074 // There is a separate status bar at the top of the display. We don't count that as part
2075 // of the fixed decor, since it can hide; however, for purposes of configurations,
Dianne Hackborn077ee852012-04-09 16:27:07 -07002076 // we do want to exclude it since applications can't generally use that part
2077 // of the screen.
John Spurlock80f00c12013-06-13 11:10:51 -04002078 return getNonDecorDisplayHeight(fullWidth, fullHeight, rotation) - mStatusBarHeight;
Dianne Hackborne2515ee2011-04-27 18:52:56 -04002079 }
2080
Craig Mautnera3f4bf52012-10-10 20:37:48 -07002081 @Override
Craig Mautnerc9457fa2014-06-06 14:27:48 -07002082 public boolean isForceHiding(WindowManager.LayoutParams attrs) {
2083 return (attrs.privateFlags & PRIVATE_FLAG_KEYGUARD) != 0 ||
Jim Millerab954542014-10-10 18:21:49 -07002084 (isKeyguardHostWindow(attrs) &&
2085 (mKeyguardDelegate != null && mKeyguardDelegate.isShowing())) ||
Adrian Roos69e510d2014-07-13 14:57:59 +02002086 (attrs.type == TYPE_KEYGUARD_SCRIM);
Dianne Hackborn01ad2f42009-09-24 19:24:56 -07002087 }
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07002088
Craig Mautnera3f4bf52012-10-10 20:37:48 -07002089 @Override
Jorim Jaggi0d674622014-05-21 01:34:15 +02002090 public boolean isKeyguardHostWindow(WindowManager.LayoutParams attrs) {
2091 return attrs.type == TYPE_STATUS_BAR;
2092 }
2093
2094 @Override
Dianne Hackborn01ad2f42009-09-24 19:24:56 -07002095 public boolean canBeForceHidden(WindowState win, WindowManager.LayoutParams attrs) {
Craig Mautnera3f4bf52012-10-10 20:37:48 -07002096 switch (attrs.type) {
2097 case TYPE_STATUS_BAR:
2098 case TYPE_NAVIGATION_BAR:
2099 case TYPE_WALLPAPER:
2100 case TYPE_DREAM:
Jim Miller5ecd8112013-01-09 18:50:26 -08002101 case TYPE_KEYGUARD_SCRIM:
Craig Mautnera3f4bf52012-10-10 20:37:48 -07002102 return false;
2103 default:
2104 return true;
2105 }
Dianne Hackborn01ad2f42009-09-24 19:24:56 -07002106 }
Craig Mautner8e4df6c2012-05-23 16:57:23 -07002107
Craig Mautner7d7808f2014-09-11 18:02:38 -07002108 @Override
2109 public WindowState getWinShowWhenLockedLw() {
2110 return mWinShowWhenLocked;
2111 }
2112
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002113 /** {@inheritDoc} */
Craig Mautner8e4df6c2012-05-23 16:57:23 -07002114 @Override
Dianne Hackborn2f0b1752011-05-31 17:59:49 -07002115 public View addStartingWindow(IBinder appToken, String packageName, int theme,
2116 CompatibilityInfo compatInfo, CharSequence nonLocalizedLabel, int labelRes,
Adam Powell04fe6eb2013-05-31 14:39:48 -07002117 int icon, int logo, int windowFlags) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002118 if (!SHOW_STARTING_ANIMATIONS) {
2119 return null;
2120 }
2121 if (packageName == null) {
2122 return null;
2123 }
Craig Mautner8e4df6c2012-05-23 16:57:23 -07002124
Mathias Jeppssond1443e92012-08-24 15:25:32 +02002125 WindowManager wm = null;
2126 View view = null;
2127
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002128 try {
Dianne Hackborn867ab6472010-04-29 13:28:56 -07002129 Context context = mContext;
Craig Mautner6fbda632012-07-03 09:26:39 -07002130 if (DEBUG_STARTING_WINDOW) Slog.d(TAG, "addStartingWindow " + packageName
2131 + ": nonLocalizedLabel=" + nonLocalizedLabel + " theme="
2132 + Integer.toHexString(theme));
Dianne Hackborn247fe742011-01-08 17:25:57 -08002133 if (theme != context.getThemeResId() || labelRes != 0) {
Dianne Hackborn867ab6472010-04-29 13:28:56 -07002134 try {
2135 context = context.createPackageContext(packageName, 0);
Dianne Hackborn247fe742011-01-08 17:25:57 -08002136 context.setTheme(theme);
Dianne Hackborn867ab6472010-04-29 13:28:56 -07002137 } catch (PackageManager.NameNotFoundException e) {
2138 // Ignore
2139 }
2140 }
Craig Mautner8e4df6c2012-05-23 16:57:23 -07002141
Jorim Jaggib10e33f2015-02-04 21:57:40 +01002142 Window win = new PhoneWindow(context);
Craig Mautner8e4df6c2012-05-23 16:57:23 -07002143 final TypedArray ta = win.getWindowStyle();
2144 if (ta.getBoolean(
2145 com.android.internal.R.styleable.Window_windowDisablePreview, false)
2146 || ta.getBoolean(
2147 com.android.internal.R.styleable.Window_windowShowWallpaper,false)) {
Dianne Hackborn867ab6472010-04-29 13:28:56 -07002148 return null;
2149 }
Craig Mautner8e4df6c2012-05-23 16:57:23 -07002150
Dianne Hackborn867ab6472010-04-29 13:28:56 -07002151 Resources r = context.getResources();
2152 win.setTitle(r.getText(labelRes, nonLocalizedLabel));
Craig Mautner8e4df6c2012-05-23 16:57:23 -07002153
Dianne Hackborn867ab6472010-04-29 13:28:56 -07002154 win.setType(
2155 WindowManager.LayoutParams.TYPE_APPLICATION_STARTING);
Adrian Roos602c68e2015-04-24 16:03:47 -07002156
2157 synchronized (mWindowManagerFuncs.getWindowManagerLock()) {
2158 // Assumes it's safe to show starting windows of launched apps while
2159 // the keyguard is being hidden. This is okay because starting windows never show
2160 // secret information.
2161 if (mKeyguardHidden) {
2162 windowFlags |= FLAG_SHOW_WHEN_LOCKED;
2163 }
2164 }
2165
Dianne Hackborn867ab6472010-04-29 13:28:56 -07002166 // Force the window flags: this is a fake window, so it is not really
2167 // touchable or focusable by the user. We also add in the ALT_FOCUSABLE_IM
2168 // flag because we do know that the next window will take input
2169 // focus, so we want to get the IME window up on top of us right away.
2170 win.setFlags(
Dianne Hackborn7eec10e2010-11-12 18:03:47 -08002171 windowFlags|
Dianne Hackborn867ab6472010-04-29 13:28:56 -07002172 WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE|
2173 WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE|
2174 WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM,
Dianne Hackborn7eec10e2010-11-12 18:03:47 -08002175 windowFlags|
Dianne Hackborn867ab6472010-04-29 13:28:56 -07002176 WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE|
2177 WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE|
2178 WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM);
Craig Mautner8e4df6c2012-05-23 16:57:23 -07002179
Adam Powell04fe6eb2013-05-31 14:39:48 -07002180 win.setDefaultIcon(icon);
2181 win.setDefaultLogo(logo);
2182
Dianne Hackborn867ab6472010-04-29 13:28:56 -07002183 win.setLayout(WindowManager.LayoutParams.MATCH_PARENT,
Dianne Hackborn2f0b1752011-05-31 17:59:49 -07002184 WindowManager.LayoutParams.MATCH_PARENT);
Craig Mautner8e4df6c2012-05-23 16:57:23 -07002185
Dianne Hackborn867ab6472010-04-29 13:28:56 -07002186 final WindowManager.LayoutParams params = win.getAttributes();
2187 params.token = appToken;
2188 params.packageName = packageName;
2189 params.windowAnimations = win.getWindowStyle().getResourceId(
2190 com.android.internal.R.styleable.Window_windowAnimationStyle, 0);
John Reck61375a82014-09-18 19:27:48 +00002191 params.privateFlags |=
2192 WindowManager.LayoutParams.PRIVATE_FLAG_FAKE_HARDWARE_ACCELERATED;
Craig Mautner88400d32012-09-30 12:35:45 -07002193 params.privateFlags |= WindowManager.LayoutParams.PRIVATE_FLAG_SHOW_FOR_ALL_USERS;
Adam Lesinski95c42972013-10-02 10:13:27 -07002194
2195 if (!compatInfo.supportsScreen()) {
2196 params.privateFlags |= WindowManager.LayoutParams.PRIVATE_FLAG_COMPATIBLE_WINDOW;
2197 }
2198
Dianne Hackborn867ab6472010-04-29 13:28:56 -07002199 params.setTitle("Starting " + packageName);
2200
Mathias Jeppssond1443e92012-08-24 15:25:32 +02002201 wm = (WindowManager)context.getSystemService(Context.WINDOW_SERVICE);
2202 view = win.getDecorView();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002203
2204 if (win.isFloating()) {
2205 // Whoops, there is no way to display an animation/preview
2206 // of such a thing! After all that work... let's skip it.
2207 // (Note that we must do this here because it is in
2208 // getDecorView() where the theme is evaluated... maybe
2209 // we should peek the floating attribute from the theme
2210 // earlier.)
2211 return null;
2212 }
Craig Mautner8e4df6c2012-05-23 16:57:23 -07002213
Craig Mautner6fbda632012-07-03 09:26:39 -07002214 if (DEBUG_STARTING_WINDOW) Slog.d(
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002215 TAG, "Adding starting window for " + packageName
2216 + " / " + appToken + ": "
2217 + (view.getParent() != null ? view : null));
2218
2219 wm.addView(view, params);
2220
2221 // Only return the view if it was successfully added to the
2222 // window manager... which we can tell by it having a parent.
2223 return view.getParent() != null ? view : null;
Jeff Brown98365d72012-08-19 20:30:52 -07002224 } catch (WindowManager.BadTokenException e) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002225 // ignore
Craig Mautner42bf39e2014-02-21 16:46:22 -08002226 Log.w(TAG, appToken + " already running, starting window not displayed. " +
2227 e.getMessage());
Dianne Hackborn867ab6472010-04-29 13:28:56 -07002228 } catch (RuntimeException e) {
2229 // don't crash if something else bad happens, for example a
2230 // failure loading resources because we are loading from an app
2231 // on external storage that has been unmounted.
2232 Log.w(TAG, appToken + " failed creating starting window", e);
Mathias Jeppssond1443e92012-08-24 15:25:32 +02002233 } finally {
2234 if (view != null && view.getParent() == null) {
2235 Log.w(TAG, "view not successfully added to wm, removing view");
2236 wm.removeViewImmediate(view);
2237 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002238 }
2239
2240 return null;
2241 }
2242
2243 /** {@inheritDoc} */
Jose Lima9546b202014-07-02 17:21:51 -07002244 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002245 public void removeStartingWindow(IBinder appToken, View window) {
Craig Mautner276a6eb2014-11-04 15:32:57 -08002246 if (DEBUG_STARTING_WINDOW) Slog.v(TAG, "Removing starting window for " + appToken + ": "
2247 + window + " Callers=" + Debug.getCallers(4));
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002248
2249 if (window != null) {
Dianne Hackborn5fd21692011-06-07 14:09:47 -07002250 WindowManager wm = (WindowManager)mContext.getSystemService(Context.WINDOW_SERVICE);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002251 wm.removeView(window);
2252 }
2253 }
2254
2255 /**
2256 * Preflight adding a window to the system.
RoboErik8a2cfc32014-05-16 11:19:38 -07002257 *
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002258 * Currently enforces that three window types are singletons:
2259 * <ul>
2260 * <li>STATUS_BAR_TYPE</li>
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002261 * <li>KEYGUARD_TYPE</li>
2262 * </ul>
RoboErik8a2cfc32014-05-16 11:19:38 -07002263 *
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002264 * @param win The window to be added
2265 * @param attrs Information about the window to be added
RoboErik8a2cfc32014-05-16 11:19:38 -07002266 *
Jeff Brown98365d72012-08-19 20:30:52 -07002267 * @return If ok, WindowManagerImpl.ADD_OKAY. If too many singletons,
2268 * WindowManagerImpl.ADD_MULTIPLE_SINGLETON
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002269 */
Jose Lima9546b202014-07-02 17:21:51 -07002270 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002271 public int prepareAddWindowLw(WindowState win, WindowManager.LayoutParams attrs) {
2272 switch (attrs.type) {
2273 case TYPE_STATUS_BAR:
Joe Onorato8bc6c512010-06-04 16:21:12 -04002274 mContext.enforceCallingOrSelfPermission(
2275 android.Manifest.permission.STATUS_BAR_SERVICE,
2276 "PhoneWindowManager");
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002277 if (mStatusBar != null) {
Dianne Hackbornf87d1962012-04-04 12:48:24 -07002278 if (mStatusBar.isAlive()) {
Jeff Brown98365d72012-08-19 20:30:52 -07002279 return WindowManagerGlobal.ADD_MULTIPLE_SINGLETON;
Dianne Hackbornf87d1962012-04-04 12:48:24 -07002280 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002281 }
2282 mStatusBar = win;
John Spurlock27735a42013-08-14 17:57:38 -04002283 mStatusBarController.setWindow(win);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002284 break;
Daniel Sandler8956dbb2011-04-22 07:55:02 -04002285 case TYPE_NAVIGATION_BAR:
2286 mContext.enforceCallingOrSelfPermission(
2287 android.Manifest.permission.STATUS_BAR_SERVICE,
2288 "PhoneWindowManager");
Dianne Hackbornf87d1962012-04-04 12:48:24 -07002289 if (mNavigationBar != null) {
2290 if (mNavigationBar.isAlive()) {
Jeff Brown98365d72012-08-19 20:30:52 -07002291 return WindowManagerGlobal.ADD_MULTIPLE_SINGLETON;
Dianne Hackbornf87d1962012-04-04 12:48:24 -07002292 }
2293 }
Daniel Sandler8956dbb2011-04-22 07:55:02 -04002294 mNavigationBar = win;
John Spurlock27735a42013-08-14 17:57:38 -04002295 mNavigationBarController.setWindow(win);
Craig Mautnereda67292013-04-28 13:50:14 -07002296 if (DEBUG_LAYOUT) Slog.i(TAG, "NAVIGATION BAR: " + mNavigationBar);
Daniel Sandler8956dbb2011-04-22 07:55:02 -04002297 break;
Jim Millere898ac52012-04-06 17:10:57 -07002298 case TYPE_NAVIGATION_BAR_PANEL:
Dianne Hackborn08743722009-12-21 12:16:51 -08002299 case TYPE_STATUS_BAR_PANEL:
Joe Onorato29fc2c92010-11-24 10:26:50 -08002300 case TYPE_STATUS_BAR_SUB_PANEL:
Jorim Jaggi225d3b52015-04-01 11:18:57 -07002301 case TYPE_VOICE_INTERACTION_STARTING:
Joe Onorato29fc2c92010-11-24 10:26:50 -08002302 mContext.enforceCallingOrSelfPermission(
2303 android.Manifest.permission.STATUS_BAR_SERVICE,
2304 "PhoneWindowManager");
Joe Onorato29fc2c92010-11-24 10:26:50 -08002305 break;
Jim Miller5ecd8112013-01-09 18:50:26 -08002306 case TYPE_KEYGUARD_SCRIM:
Jim Miller25190572013-02-28 17:36:24 -08002307 if (mKeyguardScrim != null) {
2308 return WindowManagerGlobal.ADD_MULTIPLE_SINGLETON;
2309 }
Jim Miller5ecd8112013-01-09 18:50:26 -08002310 mKeyguardScrim = win;
2311 break;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002312 }
Jeff Brown98365d72012-08-19 20:30:52 -07002313 return WindowManagerGlobal.ADD_OKAY;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002314 }
2315
2316 /** {@inheritDoc} */
Jose Lima9546b202014-07-02 17:21:51 -07002317 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002318 public void removeWindowLw(WindowState win) {
2319 if (mStatusBar == win) {
2320 mStatusBar = null;
John Spurlock27735a42013-08-14 17:57:38 -04002321 mStatusBarController.setWindow(null);
Jim Millerc0b676d2013-03-22 16:11:08 -07002322 mKeyguardDelegate.showScrim();
Jim Miller5ecd8112013-01-09 18:50:26 -08002323 } else if (mKeyguardScrim == win) {
2324 Log.v(TAG, "Removing keyguard scrim");
2325 mKeyguardScrim = null;
2326 } if (mNavigationBar == win) {
Daniel Sandler8956dbb2011-04-22 07:55:02 -04002327 mNavigationBar = null;
John Spurlock27735a42013-08-14 17:57:38 -04002328 mNavigationBarController.setWindow(null);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002329 }
2330 }
2331
2332 static final boolean PRINT_ANIM = false;
RoboErik8a2cfc32014-05-16 11:19:38 -07002333
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002334 /** {@inheritDoc} */
Craig Mautner4b71aa12012-12-27 17:20:01 -08002335 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002336 public int selectAnimationLw(WindowState win, int transit) {
2337 if (PRINT_ANIM) Log.i(TAG, "selectAnimation in " + win
2338 + ": transit=" + transit);
Dianne Hackbornf87d1962012-04-04 12:48:24 -07002339 if (win == mStatusBar) {
Jorim Jaggi380ecb82014-03-14 17:25:20 +01002340 boolean isKeyguard = (win.getAttrs().privateFlags & PRIVATE_FLAG_KEYGUARD) != 0;
Craig Mautner4b71aa12012-12-27 17:20:01 -08002341 if (transit == TRANSIT_EXIT
2342 || transit == TRANSIT_HIDE) {
Jorim Jaggi380ecb82014-03-14 17:25:20 +01002343 return isKeyguard ? -1 : R.anim.dock_top_exit;
Craig Mautner4b71aa12012-12-27 17:20:01 -08002344 } else if (transit == TRANSIT_ENTER
2345 || transit == TRANSIT_SHOW) {
Jorim Jaggi380ecb82014-03-14 17:25:20 +01002346 return isKeyguard ? -1 : R.anim.dock_top_enter;
Dianne Hackbornf87d1962012-04-04 12:48:24 -07002347 }
2348 } else if (win == mNavigationBar) {
2349 // This can be on either the bottom or the right.
2350 if (mNavigationBarOnBottom) {
Craig Mautner4b71aa12012-12-27 17:20:01 -08002351 if (transit == TRANSIT_EXIT
2352 || transit == TRANSIT_HIDE) {
Dianne Hackbornf87d1962012-04-04 12:48:24 -07002353 return R.anim.dock_bottom_exit;
Craig Mautner4b71aa12012-12-27 17:20:01 -08002354 } else if (transit == TRANSIT_ENTER
2355 || transit == TRANSIT_SHOW) {
Dianne Hackbornf87d1962012-04-04 12:48:24 -07002356 return R.anim.dock_bottom_enter;
2357 }
2358 } else {
Craig Mautner4b71aa12012-12-27 17:20:01 -08002359 if (transit == TRANSIT_EXIT
2360 || transit == TRANSIT_HIDE) {
Dianne Hackbornf87d1962012-04-04 12:48:24 -07002361 return R.anim.dock_right_exit;
Craig Mautner4b71aa12012-12-27 17:20:01 -08002362 } else if (transit == TRANSIT_ENTER
2363 || transit == TRANSIT_SHOW) {
Dianne Hackbornf87d1962012-04-04 12:48:24 -07002364 return R.anim.dock_right_enter;
2365 }
2366 }
Craig Mautner4b71aa12012-12-27 17:20:01 -08002367 }
2368
2369 if (transit == TRANSIT_PREVIEW_DONE) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002370 if (win.hasAppShownWindows()) {
2371 if (PRINT_ANIM) Log.i(TAG, "**** STARTING EXIT");
2372 return com.android.internal.R.anim.app_starting_exit;
2373 }
Dianne Hackborn7ad44382012-10-18 17:46:00 -07002374 } else if (win.getAttrs().type == TYPE_DREAM && mDreamingLockscreen
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07002375 && transit == TRANSIT_ENTER) {
2376 // Special case: we are animating in a dream, while the keyguard
2377 // is shown. We don't want an animation on the dream, because
2378 // we need it shown immediately with the keyguard animating away
2379 // to reveal it.
2380 return -1;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002381 }
2382
2383 return 0;
2384 }
2385
Craig Mautner3c174372013-02-21 17:54:37 -08002386 @Override
2387 public void selectRotationAnimationLw(int anim[]) {
2388 if (PRINT_ANIM) Slog.i(TAG, "selectRotationAnimation mTopFullscreen="
2389 + mTopFullscreenOpaqueWindowState + " rotationAnimation="
2390 + (mTopFullscreenOpaqueWindowState == null ?
2391 "0" : mTopFullscreenOpaqueWindowState.getAttrs().rotationAnimation));
2392 if (mTopFullscreenOpaqueWindowState != null && mTopIsFullscreen) {
2393 switch (mTopFullscreenOpaqueWindowState.getAttrs().rotationAnimation) {
2394 case ROTATION_ANIMATION_CROSSFADE:
2395 anim[0] = R.anim.rotation_animation_xfade_exit;
2396 anim[1] = R.anim.rotation_animation_enter;
2397 break;
2398 case ROTATION_ANIMATION_JUMPCUT:
2399 anim[0] = R.anim.rotation_animation_jump_exit;
2400 anim[1] = R.anim.rotation_animation_enter;
2401 break;
2402 case ROTATION_ANIMATION_ROTATE:
2403 default:
2404 anim[0] = anim[1] = 0;
2405 break;
2406 }
2407 } else {
2408 anim[0] = anim[1] = 0;
2409 }
2410 }
2411
2412 @Override
2413 public boolean validateRotationAnimationLw(int exitAnimId, int enterAnimId,
2414 boolean forceDefault) {
2415 switch (exitAnimId) {
2416 case R.anim.rotation_animation_xfade_exit:
2417 case R.anim.rotation_animation_jump_exit:
2418 // These are the only cases that matter.
2419 if (forceDefault) {
2420 return false;
2421 }
2422 int anim[] = new int[2];
2423 selectRotationAnimationLw(anim);
2424 return (exitAnimId == anim[0] && enterAnimId == anim[1]);
2425 default:
2426 return true;
2427 }
2428 }
2429
2430 @Override
Jorim Jaggi84a3e7a2014-08-13 17:58:58 +02002431 public Animation createForceHideEnterAnimation(boolean onWallpaper,
2432 boolean goingToNotificationShade) {
2433 if (goingToNotificationShade) {
2434 return AnimationUtils.loadAnimation(mContext, R.anim.lock_screen_behind_enter_fade_in);
Craig Mautnerb8340802014-11-04 15:32:57 -08002435 }
Craig Mautner276a6eb2014-11-04 15:32:57 -08002436
2437 AnimationSet set = (AnimationSet) AnimationUtils.loadAnimation(mContext, onWallpaper ?
2438 R.anim.lock_screen_behind_enter_wallpaper :
2439 R.anim.lock_screen_behind_enter);
2440
2441 // TODO: Use XML interpolators when we have log interpolators available in XML.
2442 final List<Animation> animations = set.getAnimations();
2443 for (int i = animations.size() - 1; i >= 0; --i) {
2444 animations.get(i).setInterpolator(mLogDecelerateInterpolator);
2445 }
2446
2447 return set;
Jorim Jaggi76a16232014-08-08 17:00:47 +02002448 }
2449
2450
2451 @Override
Jorim Jaggi84a3e7a2014-08-13 17:58:58 +02002452 public Animation createForceHideWallpaperExitAnimation(boolean goingToNotificationShade) {
2453 if (goingToNotificationShade) {
2454 return null;
2455 } else {
2456 return AnimationUtils.loadAnimation(mContext, R.anim.lock_screen_wallpaper_exit);
2457 }
Dianne Hackborn01ad2f42009-09-24 19:24:56 -07002458 }
John Spurlockc8b46ca2013-04-08 12:59:26 -04002459
2460 private static void awakenDreams() {
2461 IDreamManager dreamManager = getDreamManager();
2462 if (dreamManager != null) {
2463 try {
2464 dreamManager.awaken();
2465 } catch (RemoteException e) {
2466 // fine, stay asleep then
2467 }
2468 }
2469 }
2470
2471 static IDreamManager getDreamManager() {
2472 return IDreamManager.Stub.asInterface(
2473 ServiceManager.checkService(DreamService.DREAM_SERVICE));
2474 }
2475
Tyler Gunnef9f6f92014-09-12 22:16:17 -07002476 TelecomManager getTelecommService() {
2477 return (TelecomManager) mContext.getSystemService(Context.TELECOM_SERVICE);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002478 }
2479
Jeff Brown4d396052010-10-29 21:50:21 -07002480 static IAudioService getAudioService() {
2481 IAudioService audioService = IAudioService.Stub.asInterface(
2482 ServiceManager.checkService(Context.AUDIO_SERVICE));
2483 if (audioService == null) {
2484 Log.w(TAG, "Unable to find IAudioService interface.");
2485 }
2486 return audioService;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002487 }
2488
2489 boolean keyguardOn() {
Jim Millerab954542014-10-10 18:21:49 -07002490 return isKeyguardShowingAndNotOccluded() || inKeyguardRestrictedKeyInputMode();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002491 }
2492
2493 private static final int[] WINDOW_TYPES_WHERE_HOME_DOESNT_WORK = {
2494 WindowManager.LayoutParams.TYPE_SYSTEM_ALERT,
2495 WindowManager.LayoutParams.TYPE_SYSTEM_ERROR,
2496 };
2497
2498 /** {@inheritDoc} */
Jeff Brown00fa7bd2010-07-02 15:37:36 -07002499 @Override
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002500 public long interceptKeyBeforeDispatching(WindowState win, KeyEvent event, int policyFlags) {
Jeff Brown00fa7bd2010-07-02 15:37:36 -07002501 final boolean keyguardOn = keyguardOn();
Jeff Brown1f245102010-11-18 20:53:46 -08002502 final int keyCode = event.getKeyCode();
2503 final int repeatCount = event.getRepeatCount();
2504 final int metaState = event.getMetaState();
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002505 final int flags = event.getFlags();
Jeff Brown1f245102010-11-18 20:53:46 -08002506 final boolean down = event.getAction() == KeyEvent.ACTION_DOWN;
2507 final boolean canceled = event.isCanceled();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002508
Jeff Brown40013652012-05-16 21:22:36 -07002509 if (DEBUG_INPUT) {
Jeff Brown00fa7bd2010-07-02 15:37:36 -07002510 Log.d(TAG, "interceptKeyTi keyCode=" + keyCode + " down=" + down + " repeatCount="
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002511 + repeatCount + " keyguardOn=" + keyguardOn + " mHomePressed=" + mHomePressed
2512 + " canceled=" + canceled);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002513 }
2514
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002515 // If we think we might have a volume down & power key chord on the way
2516 // but we're not sure, then tell the dispatcher to wait a little while and
2517 // try again later before dispatching.
Christopher Tatee90585f2012-03-05 18:56:25 -08002518 if (mScreenshotChordEnabled && (flags & KeyEvent.FLAG_FALLBACK) == 0) {
Jeff Brown13f00f02014-10-31 14:45:50 -07002519 if (mScreenshotChordVolumeDownKeyTriggered && !mScreenshotChordPowerKeyTriggered) {
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002520 final long now = SystemClock.uptimeMillis();
Jeff Brown13f00f02014-10-31 14:45:50 -07002521 final long timeoutTime = mScreenshotChordVolumeDownKeyTime
2522 + SCREENSHOT_CHORD_DEBOUNCE_DELAY_MILLIS;
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002523 if (now < timeoutTime) {
2524 return timeoutTime - now;
2525 }
2526 }
2527 if (keyCode == KeyEvent.KEYCODE_VOLUME_DOWN
Jeff Brown13f00f02014-10-31 14:45:50 -07002528 && mScreenshotChordVolumeDownKeyConsumed) {
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002529 if (!down) {
Jeff Brown13f00f02014-10-31 14:45:50 -07002530 mScreenshotChordVolumeDownKeyConsumed = false;
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002531 }
2532 return -1;
2533 }
2534 }
2535
Michael Wright6a62e552014-06-03 19:19:48 -07002536 // Cancel any pending meta actions if we see any other keys being pressed between the down
2537 // of the meta key and its corresponding up.
Michael Wright251e35d2014-08-22 15:40:27 -07002538 if (mPendingMetaAction && !KeyEvent.isMetaKey(keyCode)) {
Michael Wright6a62e552014-06-03 19:19:48 -07002539 mPendingMetaAction = false;
2540 }
2541
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002542 // First we always handle the home key here, so applications
2543 // can never break it, although if keyguard is on, we do let
2544 // it handle it, because that gives us the correct 5 second
2545 // timeout.
Jeff Brown00fa7bd2010-07-02 15:37:36 -07002546 if (keyCode == KeyEvent.KEYCODE_HOME) {
Michael Jurka7f2668c2012-03-27 07:49:52 -07002547
Jeff Brown49ed71d2010-12-06 17:13:33 -08002548 // If we have released the home key, and didn't do anything else
2549 // while it was pressed, then it is time to go home!
Michael Jurka7f2668c2012-03-27 07:49:52 -07002550 if (!down) {
Jeff Browncaca8812013-05-09 13:34:33 -07002551 cancelPreloadRecentApps();
2552
Jeff Brown49ed71d2010-12-06 17:13:33 -08002553 mHomePressed = false;
Jeff Browncaca8812013-05-09 13:34:33 -07002554 if (mHomeConsumed) {
2555 mHomeConsumed = false;
Michael Jurka7f2668c2012-03-27 07:49:52 -07002556 return -1;
Jeff Brown49ed71d2010-12-06 17:13:33 -08002557 }
Jeff Browncaca8812013-05-09 13:34:33 -07002558
2559 if (canceled) {
2560 Log.i(TAG, "Ignoring HOME; event canceled.");
2561 return -1;
2562 }
2563
Yorke Lee4f803242014-12-15 23:22:06 +00002564 // If an incoming call is ringing, HOME is totally disabled.
2565 // (The user is already on the InCallUI at this point,
2566 // and his ONLY options are to answer or reject the call.)
2567 TelecomManager telecomManager = getTelecommService();
2568 if (telecomManager != null && telecomManager.isRinging()) {
2569 Log.i(TAG, "Ignoring HOME; there's a ringing incoming call.");
2570 return -1;
2571 }
2572
Jeff Browncaca8812013-05-09 13:34:33 -07002573 // Delay handling home if a double-tap is possible.
2574 if (mDoubleTapOnHomeBehavior != DOUBLE_TAP_HOME_NOTHING) {
2575 mHandler.removeCallbacks(mHomeDoubleTapTimeoutRunnable); // just in case
2576 mHomeDoubleTapPending = true;
2577 mHandler.postDelayed(mHomeDoubleTapTimeoutRunnable,
2578 ViewConfiguration.getDoubleTapTimeout());
2579 return -1;
2580 }
2581
Jeff Brown13f00f02014-10-31 14:45:50 -07002582 handleShortPressOnHome();
Jeff Browncaca8812013-05-09 13:34:33 -07002583 return -1;
Jeff Brown49ed71d2010-12-06 17:13:33 -08002584 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002585
2586 // If a system window has focus, then it doesn't make sense
2587 // right now to interact with applications.
2588 WindowManager.LayoutParams attrs = win != null ? win.getAttrs() : null;
2589 if (attrs != null) {
2590 final int type = attrs.type;
Jorim Jaggi380ecb82014-03-14 17:25:20 +01002591 if (type == WindowManager.LayoutParams.TYPE_KEYGUARD_SCRIM
2592 || type == WindowManager.LayoutParams.TYPE_KEYGUARD_DIALOG
2593 || (attrs.privateFlags & PRIVATE_FLAG_KEYGUARD) != 0) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002594 // the "app" is keyguard, so give it the key
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002595 return 0;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002596 }
2597 final int typeCount = WINDOW_TYPES_WHERE_HOME_DOESNT_WORK.length;
2598 for (int i=0; i<typeCount; i++) {
2599 if (type == WINDOW_TYPES_WHERE_HOME_DOESNT_WORK[i]) {
2600 // don't do anything, but also don't pass it to the app
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002601 return -1;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002602 }
2603 }
2604 }
Jeff Browncaca8812013-05-09 13:34:33 -07002605
2606 // Remember that home is pressed and handle special actions.
2607 if (repeatCount == 0) {
2608 mHomePressed = true;
2609 if (mHomeDoubleTapPending) {
2610 mHomeDoubleTapPending = false;
2611 mHandler.removeCallbacks(mHomeDoubleTapTimeoutRunnable);
2612 handleDoubleTapOnHome();
2613 } else if (mLongPressOnHomeBehavior == LONG_PRESS_HOME_RECENT_SYSTEM_UI
2614 || mDoubleTapOnHomeBehavior == DOUBLE_TAP_HOME_RECENT_SYSTEM_UI) {
2615 preloadRecentApps();
Michael Jurka7f2668c2012-03-27 07:49:52 -07002616 }
Jeff Browncaca8812013-05-09 13:34:33 -07002617 } else if ((event.getFlags() & KeyEvent.FLAG_LONG_PRESS) != 0) {
2618 if (!keyguardOn) {
2619 handleLongPressOnHome();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002620 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002621 }
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002622 return -1;
Jeff Brown00fa7bd2010-07-02 15:37:36 -07002623 } else if (keyCode == KeyEvent.KEYCODE_MENU) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002624 // Hijack modified menu keys for debugging features
2625 final int chordBug = KeyEvent.META_SHIFT_ON;
2626
2627 if (down && repeatCount == 0) {
Jeff Brown00fa7bd2010-07-02 15:37:36 -07002628 if (mEnableShiftMenuBugReports && (metaState & chordBug) == chordBug) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002629 Intent intent = new Intent(Intent.ACTION_BUG_REPORT);
Dianne Hackborn5ac72a22012-08-29 18:32:08 -07002630 mContext.sendOrderedBroadcastAsUser(intent, UserHandle.CURRENT,
2631 null, null, null, 0, null, null);
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002632 return -1;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002633 } else if (SHOW_PROCESSES_ON_ALT_MENU &&
Jeff Brown00fa7bd2010-07-02 15:37:36 -07002634 (metaState & KeyEvent.META_ALT_ON) == KeyEvent.META_ALT_ON) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002635 Intent service = new Intent();
2636 service.setClassName(mContext, "com.android.server.LoadAverageService");
2637 ContentResolver res = mContext.getContentResolver();
Jeff Sharkey8d9a1f62012-10-18 15:38:14 -07002638 boolean shown = Settings.Global.getInt(
2639 res, Settings.Global.SHOW_PROCESSES, 0) != 0;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002640 if (!shown) {
2641 mContext.startService(service);
2642 } else {
2643 mContext.stopService(service);
2644 }
Jeff Sharkey8d9a1f62012-10-18 15:38:14 -07002645 Settings.Global.putInt(
2646 res, Settings.Global.SHOW_PROCESSES, shown ? 0 : 1);
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002647 return -1;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002648 }
2649 }
Jeff Brown00fa7bd2010-07-02 15:37:36 -07002650 } else if (keyCode == KeyEvent.KEYCODE_SEARCH) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002651 if (down) {
2652 if (repeatCount == 0) {
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002653 mSearchKeyShortcutPending = true;
2654 mConsumeSearchKeyUp = false;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002655 }
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002656 } else {
2657 mSearchKeyShortcutPending = false;
2658 if (mConsumeSearchKeyUp) {
2659 mConsumeSearchKeyUp = false;
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002660 return -1;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002661 }
2662 }
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002663 return 0;
Jeff Brown49ed71d2010-12-06 17:13:33 -08002664 } else if (keyCode == KeyEvent.KEYCODE_APP_SWITCH) {
Michael Wrightc9ebea72013-01-16 19:25:02 -08002665 if (!keyguardOn) {
Jeff Browncaca8812013-05-09 13:34:33 -07002666 if (down && repeatCount == 0) {
2667 preloadRecentApps();
2668 } else if (!down) {
2669 toggleRecentApps();
Michael Wrightc9ebea72013-01-16 19:25:02 -08002670 }
Jeff Brown49ed71d2010-12-06 17:13:33 -08002671 }
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002672 return -1;
Jun Mukaid21b3c82015-04-23 14:09:34 -07002673 } else if (keyCode == KeyEvent.KEYCODE_N && event.isMetaPressed()) {
2674 if (down) {
2675 IStatusBarService service = getStatusBarService();
2676 if (service != null) {
2677 try {
2678 service.expandNotificationsPanel();
2679 } catch (RemoteException e) {
2680 // do nothing.
2681 }
2682 }
2683 }
Jeff Brownde7a8ea2012-06-13 18:28:57 -07002684 } else if (keyCode == KeyEvent.KEYCODE_ASSIST) {
2685 if (down) {
2686 if (repeatCount == 0) {
2687 mAssistKeyLongPressed = false;
2688 } else if (repeatCount == 1) {
2689 mAssistKeyLongPressed = true;
2690 if (!keyguardOn) {
2691 launchAssistLongPressAction();
2692 }
2693 }
2694 } else {
2695 if (mAssistKeyLongPressed) {
2696 mAssistKeyLongPressed = false;
2697 } else {
2698 if (!keyguardOn) {
2699 launchAssistAction();
2700 }
2701 }
2702 }
2703 return -1;
Michael Wrightdc63f7b2014-08-21 19:05:21 -07002704 } else if (keyCode == KeyEvent.KEYCODE_VOICE_ASSIST) {
2705 if (!down) {
2706 Intent voiceIntent;
Michael Wright869a67c2014-08-26 19:33:06 -07002707 if (!keyguardOn) {
Michael Wrightdc63f7b2014-08-21 19:05:21 -07002708 voiceIntent = new Intent(RecognizerIntent.ACTION_WEB_SEARCH);
2709 } else {
2710 voiceIntent = new Intent(RecognizerIntent.ACTION_VOICE_SEARCH_HANDS_FREE);
Michael Wright869a67c2014-08-26 19:33:06 -07002711 voiceIntent.putExtra(RecognizerIntent.EXTRA_SECURE, true);
Michael Wrightdc63f7b2014-08-21 19:05:21 -07002712 }
Bart Sears8b1c27c2015-03-18 23:51:02 +00002713 startActivityAsUser(voiceIntent, UserHandle.CURRENT_OR_SELF);
Michael Wrightdc63f7b2014-08-21 19:05:21 -07002714 }
Jeff Sharkey2991fa32012-12-05 18:06:43 -08002715 } else if (keyCode == KeyEvent.KEYCODE_SYSRQ) {
2716 if (down && repeatCount == 0) {
2717 mHandler.post(mScreenshotRunnable);
2718 }
2719 return -1;
Michael Wrightb854e242013-02-05 17:54:02 -08002720 } else if (keyCode == KeyEvent.KEYCODE_BRIGHTNESS_UP
2721 || keyCode == KeyEvent.KEYCODE_BRIGHTNESS_DOWN) {
2722 if (down) {
2723 int direction = keyCode == KeyEvent.KEYCODE_BRIGHTNESS_UP ? 1 : -1;
2724
2725 // Disable autobrightness if it's on
2726 int auto = Settings.System.getIntForUser(
2727 mContext.getContentResolver(),
2728 Settings.System.SCREEN_BRIGHTNESS_MODE,
2729 Settings.System.SCREEN_BRIGHTNESS_MODE_MANUAL,
2730 UserHandle.USER_CURRENT_OR_SELF);
2731 if (auto != 0) {
2732 Settings.System.putIntForUser(mContext.getContentResolver(),
2733 Settings.System.SCREEN_BRIGHTNESS_MODE,
2734 Settings.System.SCREEN_BRIGHTNESS_MODE_MANUAL,
2735 UserHandle.USER_CURRENT_OR_SELF);
2736 }
2737
2738 int min = mPowerManager.getMinimumScreenBrightnessSetting();
2739 int max = mPowerManager.getMaximumScreenBrightnessSetting();
2740 int step = (max - min + BRIGHTNESS_STEPS - 1) / BRIGHTNESS_STEPS * direction;
2741 int brightness = Settings.System.getIntForUser(mContext.getContentResolver(),
2742 Settings.System.SCREEN_BRIGHTNESS,
2743 mPowerManager.getDefaultScreenBrightnessSetting(),
2744 UserHandle.USER_CURRENT_OR_SELF);
2745 brightness += step;
2746 // Make sure we don't go beyond the limits.
2747 brightness = Math.min(max, brightness);
2748 brightness = Math.max(min, brightness);
2749
2750 Settings.System.putIntForUser(mContext.getContentResolver(),
2751 Settings.System.SCREEN_BRIGHTNESS, brightness,
2752 UserHandle.USER_CURRENT_OR_SELF);
Bart Sears8b1c27c2015-03-18 23:51:02 +00002753 startActivityAsUser(new Intent(Intent.ACTION_SHOW_BRIGHTNESS_DIALOG),
Alan Viverette5a399492014-07-14 16:19:38 -07002754 UserHandle.CURRENT_OR_SELF);
Michael Wrightb854e242013-02-05 17:54:02 -08002755 }
2756 return -1;
Michael Wrightce0c13a2014-07-30 10:49:21 -07002757 } else if (KeyEvent.isMetaKey(keyCode)) {
Michael Wright6a62e552014-06-03 19:19:48 -07002758 if (down) {
2759 mPendingMetaAction = true;
2760 } else if (mPendingMetaAction) {
Michael Wright8ab940a2014-09-01 11:01:27 -07002761 launchAssistAction(Intent.EXTRA_ASSIST_INPUT_HINT_KEYBOARD);
Michael Wright6a62e552014-06-03 19:19:48 -07002762 }
2763 return -1;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002764 }
Jeff Browncaab4d02010-12-09 22:13:41 -08002765
Jeff Brownc1fb48d2010-12-08 16:52:09 -08002766 // Shortcuts are invoked through Search+key, so intercept those here
Jeff Browncaab4d02010-12-09 22:13:41 -08002767 // Any printing key that is chorded with Search should be consumed
2768 // even if no shortcut was invoked. This prevents text from being
2769 // inadvertently inserted when using a keyboard that has built-in macro
2770 // shortcut keys (that emit Search+x) and some of them are not registered.
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002771 if (mSearchKeyShortcutPending) {
Jeff Browncaab4d02010-12-09 22:13:41 -08002772 final KeyCharacterMap kcm = event.getKeyCharacterMap();
2773 if (kcm.isPrintingKey(keyCode)) {
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002774 mConsumeSearchKeyUp = true;
2775 mSearchKeyShortcutPending = false;
Jeff Browncaab4d02010-12-09 22:13:41 -08002776 if (down && repeatCount == 0 && !keyguardOn) {
2777 Intent shortcutIntent = mShortcutManager.getIntent(kcm, keyCode, metaState);
2778 if (shortcutIntent != null) {
2779 shortcutIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
Jeff Brownf0a3cc52011-01-26 18:42:46 -08002780 try {
Bart Sears8b1c27c2015-03-18 23:51:02 +00002781 startActivityAsUser(shortcutIntent, UserHandle.CURRENT);
Jeff Brownf0a3cc52011-01-26 18:42:46 -08002782 } catch (ActivityNotFoundException ex) {
2783 Slog.w(TAG, "Dropping shortcut key combination because "
2784 + "the activity to which it is registered was not found: "
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002785 + "SEARCH+" + KeyEvent.keyCodeToString(keyCode), ex);
Jeff Brownf0a3cc52011-01-26 18:42:46 -08002786 }
Jeff Browncaab4d02010-12-09 22:13:41 -08002787 } else {
2788 Slog.i(TAG, "Dropping unregistered shortcut key combination: "
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002789 + "SEARCH+" + KeyEvent.keyCodeToString(keyCode));
Jeff Brown49ed71d2010-12-06 17:13:33 -08002790 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002791 }
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002792 return -1;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002793 }
2794 }
2795
Jeff Brown68b909d2011-12-07 16:36:01 -08002796 // Invoke shortcuts using Meta.
Jeff Brown602ab322012-05-16 13:33:47 -07002797 if (down && repeatCount == 0 && !keyguardOn
Jeff Brown68b909d2011-12-07 16:36:01 -08002798 && (metaState & KeyEvent.META_META_ON) != 0) {
2799 final KeyCharacterMap kcm = event.getKeyCharacterMap();
Jeff Brown602ab322012-05-16 13:33:47 -07002800 if (kcm.isPrintingKey(keyCode)) {
2801 Intent shortcutIntent = mShortcutManager.getIntent(kcm, keyCode,
2802 metaState & ~(KeyEvent.META_META_ON
2803 | KeyEvent.META_META_LEFT_ON | KeyEvent.META_META_RIGHT_ON));
2804 if (shortcutIntent != null) {
2805 shortcutIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
2806 try {
Bart Sears8b1c27c2015-03-18 23:51:02 +00002807 startActivityAsUser(shortcutIntent, UserHandle.CURRENT);
Jeff Brown602ab322012-05-16 13:33:47 -07002808 } catch (ActivityNotFoundException ex) {
2809 Slog.w(TAG, "Dropping shortcut key combination because "
2810 + "the activity to which it is registered was not found: "
2811 + "META+" + KeyEvent.keyCodeToString(keyCode), ex);
2812 }
2813 return -1;
Jeff Brown68b909d2011-12-07 16:36:01 -08002814 }
Jeff Brown68b909d2011-12-07 16:36:01 -08002815 }
2816 }
2817
Jeff Brown6651a632011-11-28 12:59:11 -08002818 // Handle application launch keys.
Jeff Brown602ab322012-05-16 13:33:47 -07002819 if (down && repeatCount == 0 && !keyguardOn) {
Jeff Brown6651a632011-11-28 12:59:11 -08002820 String category = sApplicationLaunchKeyCategories.get(keyCode);
2821 if (category != null) {
Dianne Hackbornf5b86712011-12-05 17:42:41 -08002822 Intent intent = Intent.makeMainSelectorActivity(Intent.ACTION_MAIN, category);
Jeff Brown6651a632011-11-28 12:59:11 -08002823 intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
2824 try {
Bart Sears8b1c27c2015-03-18 23:51:02 +00002825 startActivityAsUser(intent, UserHandle.CURRENT);
Jeff Brown6651a632011-11-28 12:59:11 -08002826 } catch (ActivityNotFoundException ex) {
2827 Slog.w(TAG, "Dropping application launch key because "
2828 + "the activity to which it is registered was not found: "
2829 + "keyCode=" + keyCode + ", category=" + category, ex);
2830 }
Jeff Brown68b909d2011-12-07 16:36:01 -08002831 return -1;
Jeff Brown6651a632011-11-28 12:59:11 -08002832 }
2833 }
2834
Michael Wright61c46752014-08-21 16:57:33 -07002835 // Display task switcher for ALT-TAB.
Jeff Brown68b909d2011-12-07 16:36:01 -08002836 if (down && repeatCount == 0 && keyCode == KeyEvent.KEYCODE_TAB) {
Winson Chung1e8d71b2014-05-16 17:05:22 -07002837 if (mRecentAppsHeldModifiers == 0 && !keyguardOn) {
Jeff Brown68b909d2011-12-07 16:36:01 -08002838 final int shiftlessModifiers = event.getModifiers() & ~KeyEvent.META_SHIFT_MASK;
Michael Wright61c46752014-08-21 16:57:33 -07002839 if (KeyEvent.metaStateHasModifiers(shiftlessModifiers, KeyEvent.META_ALT_ON)) {
Winson Chung1e8d71b2014-05-16 17:05:22 -07002840 mRecentAppsHeldModifiers = shiftlessModifiers;
2841 showRecentApps(true);
Jeff Brown68b909d2011-12-07 16:36:01 -08002842 return -1;
2843 }
2844 }
Winson Chung1e8d71b2014-05-16 17:05:22 -07002845 } else if (!down && mRecentAppsHeldModifiers != 0
2846 && (metaState & mRecentAppsHeldModifiers) == 0) {
2847 mRecentAppsHeldModifiers = 0;
Winson Chungcdcd4872014-08-05 18:00:13 -07002848 hideRecentApps(true, false);
Jeff Brown68b909d2011-12-07 16:36:01 -08002849 }
2850
Jeff Browncf39bdf2012-05-18 14:41:19 -07002851 // Handle keyboard language switching.
2852 if (down && repeatCount == 0
2853 && (keyCode == KeyEvent.KEYCODE_LANGUAGE_SWITCH
2854 || (keyCode == KeyEvent.KEYCODE_SPACE
2855 && (metaState & KeyEvent.META_CTRL_MASK) != 0))) {
2856 int direction = (metaState & KeyEvent.META_SHIFT_MASK) != 0 ? -1 : 1;
2857 mWindowManagerFuncs.switchKeyboardLayout(event.getDeviceId(), direction);
2858 return -1;
2859 }
2860 if (mLanguageSwitchKeyPressed && !down
2861 && (keyCode == KeyEvent.KEYCODE_LANGUAGE_SWITCH
2862 || keyCode == KeyEvent.KEYCODE_SPACE)) {
2863 mLanguageSwitchKeyPressed = false;
2864 return -1;
2865 }
2866
Jeff Brown13f00f02014-10-31 14:45:50 -07002867 if (isValidGlobalKey(keyCode)
2868 && mGlobalKeyManager.handleGlobalKey(mContext, keyCode, event)) {
Justin Kohd378ad72013-04-01 12:18:26 -07002869 return -1;
2870 }
2871
Michael Wright6a62e552014-06-03 19:19:48 -07002872 // Reserve all the META modifier combos for system behavior
Michael Wrightce0c13a2014-07-30 10:49:21 -07002873 if ((metaState & KeyEvent.META_META_ON) != 0) {
Michael Wright6a62e552014-06-03 19:19:48 -07002874 return -1;
2875 }
2876
Jeff Brown68b909d2011-12-07 16:36:01 -08002877 // Let the application handle the key.
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002878 return 0;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002879 }
2880
Jeff Brown3915bb82010-11-05 15:02:16 -07002881 /** {@inheritDoc} */
2882 @Override
Jeff Brown49ed71d2010-12-06 17:13:33 -08002883 public KeyEvent dispatchUnhandledKey(WindowState win, KeyEvent event, int policyFlags) {
Jeff Brown54875002011-04-06 15:33:01 -07002884 // Note: This method is only called if the initial down was unhandled.
Jeff Brown40013652012-05-16 21:22:36 -07002885 if (DEBUG_INPUT) {
Jeff Brown1f245102010-11-18 20:53:46 -08002886 Slog.d(TAG, "Unhandled key: win=" + win + ", action=" + event.getAction()
2887 + ", flags=" + event.getFlags()
2888 + ", keyCode=" + event.getKeyCode()
2889 + ", scanCode=" + event.getScanCode()
2890 + ", metaState=" + event.getMetaState()
2891 + ", repeatCount=" + event.getRepeatCount()
2892 + ", policyFlags=" + policyFlags);
Jeff Brown3915bb82010-11-05 15:02:16 -07002893 }
Jeff Brown49ed71d2010-12-06 17:13:33 -08002894
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002895 KeyEvent fallbackEvent = null;
Jeff Brown49ed71d2010-12-06 17:13:33 -08002896 if ((event.getFlags() & KeyEvent.FLAG_FALLBACK) == 0) {
2897 final KeyCharacterMap kcm = event.getKeyCharacterMap();
Jeff Brownc1fb48d2010-12-08 16:52:09 -08002898 final int keyCode = event.getKeyCode();
2899 final int metaState = event.getMetaState();
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002900 final boolean initialDown = event.getAction() == KeyEvent.ACTION_DOWN
2901 && event.getRepeatCount() == 0;
Jeff Brown49ed71d2010-12-06 17:13:33 -08002902
Jeff Brown54875002011-04-06 15:33:01 -07002903 // Check for fallback actions specified by the key character map.
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002904 final FallbackAction fallbackAction;
2905 if (initialDown) {
2906 fallbackAction = kcm.getFallbackAction(keyCode, metaState);
2907 } else {
2908 fallbackAction = mFallbackActions.get(keyCode);
2909 }
2910
2911 if (fallbackAction != null) {
Jeff Brown40013652012-05-16 21:22:36 -07002912 if (DEBUG_INPUT) {
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002913 Slog.d(TAG, "Fallback: keyCode=" + fallbackAction.keyCode
2914 + " metaState=" + Integer.toHexString(fallbackAction.metaState));
Jeff Brown49ed71d2010-12-06 17:13:33 -08002915 }
2916
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002917 final int flags = event.getFlags() | KeyEvent.FLAG_FALLBACK;
2918 fallbackEvent = KeyEvent.obtain(
Jeff Brown49ed71d2010-12-06 17:13:33 -08002919 event.getDownTime(), event.getEventTime(),
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002920 event.getAction(), fallbackAction.keyCode,
2921 event.getRepeatCount(), fallbackAction.metaState,
Jeff Brown49ed71d2010-12-06 17:13:33 -08002922 event.getDeviceId(), event.getScanCode(),
2923 flags, event.getSource(), null);
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002924
2925 if (!interceptFallback(win, fallbackEvent, policyFlags)) {
2926 fallbackEvent.recycle();
2927 fallbackEvent = null;
Jeff Brown49ed71d2010-12-06 17:13:33 -08002928 }
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002929
2930 if (initialDown) {
2931 mFallbackActions.put(keyCode, fallbackAction);
2932 } else if (event.getAction() == KeyEvent.ACTION_UP) {
2933 mFallbackActions.remove(keyCode);
2934 fallbackAction.recycle();
2935 }
Jeff Brown49ed71d2010-12-06 17:13:33 -08002936 }
2937 }
2938
Jeff Brown40013652012-05-16 21:22:36 -07002939 if (DEBUG_INPUT) {
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002940 if (fallbackEvent == null) {
2941 Slog.d(TAG, "No fallback.");
2942 } else {
2943 Slog.d(TAG, "Performing fallback: " + fallbackEvent);
2944 }
Jeff Brown49ed71d2010-12-06 17:13:33 -08002945 }
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002946 return fallbackEvent;
Jeff Brown3915bb82010-11-05 15:02:16 -07002947 }
2948
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002949 private boolean interceptFallback(WindowState win, KeyEvent fallbackEvent, int policyFlags) {
Jeff Brown037c33e2014-04-09 00:31:55 -07002950 int actions = interceptKeyBeforeQueueing(fallbackEvent, policyFlags);
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002951 if ((actions & ACTION_PASS_TO_USER) != 0) {
2952 long delayMillis = interceptKeyBeforeDispatching(
2953 win, fallbackEvent, policyFlags);
2954 if (delayMillis == 0) {
2955 return true;
2956 }
2957 }
2958 return false;
Jeff Brown6f2fba42011-02-19 01:08:02 -08002959 }
2960
Jeff Brownde7a8ea2012-06-13 18:28:57 -07002961 private void launchAssistLongPressAction() {
2962 performHapticFeedbackLw(null, HapticFeedbackConstants.LONG_PRESS, false);
2963 sendCloseSystemWindows(SYSTEM_DIALOG_REASON_ASSIST);
2964
2965 // launch the search activity
2966 Intent intent = new Intent(Intent.ACTION_SEARCH_LONG_PRESS);
2967 intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
2968 try {
RoboErik8a2cfc32014-05-16 11:19:38 -07002969 // TODO: This only stops the factory-installed search manager.
Jim Miller45308b12012-06-18 19:23:39 -07002970 // Need to formalize an API to handle others
Jeff Brownde7a8ea2012-06-13 18:28:57 -07002971 SearchManager searchManager = getSearchManager();
2972 if (searchManager != null) {
2973 searchManager.stopSearch();
2974 }
Bart Sears8b1c27c2015-03-18 23:51:02 +00002975 startActivityAsUser(intent, UserHandle.CURRENT);
Jeff Brownde7a8ea2012-06-13 18:28:57 -07002976 } catch (ActivityNotFoundException e) {
2977 Slog.w(TAG, "No activity to handle assist long press action.", e);
2978 }
2979 }
2980
2981 private void launchAssistAction() {
Michael Wright8ab940a2014-09-01 11:01:27 -07002982 launchAssistAction(null);
2983 }
2984
2985 private void launchAssistAction(String hint) {
Jeff Brownde7a8ea2012-06-13 18:28:57 -07002986 sendCloseSystemWindows(SYSTEM_DIALOG_REASON_ASSIST);
Amith Yamasanic1d07a42012-08-14 09:32:02 -07002987 Intent intent = ((SearchManager) mContext.getSystemService(Context.SEARCH_SERVICE))
Dianne Hackbornf9c5e0f2013-01-23 14:39:13 -08002988 .getAssistIntent(mContext, true, UserHandle.USER_CURRENT);
Jim Miller45308b12012-06-18 19:23:39 -07002989 if (intent != null) {
Michael Wright8ab940a2014-09-01 11:01:27 -07002990 if (hint != null) {
2991 intent.putExtra(hint, true);
2992 }
Jim Miller45308b12012-06-18 19:23:39 -07002993 intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK
2994 | Intent.FLAG_ACTIVITY_SINGLE_TOP
2995 | Intent.FLAG_ACTIVITY_CLEAR_TOP);
2996 try {
Bart Sears8b1c27c2015-03-18 23:51:02 +00002997 startActivityAsUser(intent, UserHandle.CURRENT);
Jim Miller45308b12012-06-18 19:23:39 -07002998 } catch (ActivityNotFoundException e) {
2999 Slog.w(TAG, "No activity to handle assist action.", e);
Jeff Brownde7a8ea2012-06-13 18:28:57 -07003000 }
3001 }
3002 }
3003
Bart Sears8b1c27c2015-03-18 23:51:02 +00003004 private void startActivityAsUser(Intent intent, UserHandle handle) {
3005 if (isUserSetupComplete()) {
3006 mContext.startActivityAsUser(intent, handle);
3007 } else {
3008 Slog.i(TAG, "Not starting activity because user setup is in progress: " + intent);
3009 }
3010 }
3011
Jeff Brownde7a8ea2012-06-13 18:28:57 -07003012 private SearchManager getSearchManager() {
3013 if (mSearchManager == null) {
3014 mSearchManager = (SearchManager) mContext.getSystemService(Context.SEARCH_SERVICE);
3015 }
3016 return mSearchManager;
3017 }
3018
Jeff Browncaca8812013-05-09 13:34:33 -07003019 private void preloadRecentApps() {
3020 mPreloadedRecentApps = true;
3021 try {
3022 IStatusBarService statusbar = getStatusBarService();
3023 if (statusbar != null) {
3024 statusbar.preloadRecentApps();
3025 }
3026 } catch (RemoteException e) {
3027 Slog.e(TAG, "RemoteException when preloading recent apps", e);
3028 // re-acquire status bar service next time it is needed.
3029 mStatusBarService = null;
3030 }
3031 }
3032
3033 private void cancelPreloadRecentApps() {
3034 if (mPreloadedRecentApps) {
3035 mPreloadedRecentApps = false;
3036 try {
3037 IStatusBarService statusbar = getStatusBarService();
3038 if (statusbar != null) {
3039 statusbar.cancelPreloadRecentApps();
3040 }
3041 } catch (RemoteException e) {
Winson Chung1e8d71b2014-05-16 17:05:22 -07003042 Slog.e(TAG, "RemoteException when cancelling recent apps preload", e);
Jeff Browncaca8812013-05-09 13:34:33 -07003043 // re-acquire status bar service next time it is needed.
3044 mStatusBarService = null;
3045 }
3046 }
3047 }
3048
3049 private void toggleRecentApps() {
3050 mPreloadedRecentApps = false; // preloading no longer needs to be canceled
Jeff Browncaca8812013-05-09 13:34:33 -07003051 try {
3052 IStatusBarService statusbar = getStatusBarService();
3053 if (statusbar != null) {
3054 statusbar.toggleRecentApps();
3055 }
3056 } catch (RemoteException e) {
Winson Chung1e8d71b2014-05-16 17:05:22 -07003057 Slog.e(TAG, "RemoteException when toggling recent apps", e);
3058 // re-acquire status bar service next time it is needed.
3059 mStatusBarService = null;
3060 }
3061 }
3062
Craig Mautner84984fa2014-06-19 11:19:20 -07003063 @Override
3064 public void showRecentApps() {
3065 mHandler.removeMessages(MSG_DISPATCH_SHOW_RECENTS);
3066 mHandler.sendEmptyMessage(MSG_DISPATCH_SHOW_RECENTS);
3067 }
3068
Winson Chung1e8d71b2014-05-16 17:05:22 -07003069 private void showRecentApps(boolean triggeredFromAltTab) {
3070 mPreloadedRecentApps = false; // preloading no longer needs to be canceled
3071 try {
3072 IStatusBarService statusbar = getStatusBarService();
3073 if (statusbar != null) {
3074 statusbar.showRecentApps(triggeredFromAltTab);
3075 }
3076 } catch (RemoteException e) {
Jeff Browncaca8812013-05-09 13:34:33 -07003077 Slog.e(TAG, "RemoteException when showing recent apps", e);
3078 // re-acquire status bar service next time it is needed.
3079 mStatusBarService = null;
3080 }
3081 }
3082
Winson Chungcdcd4872014-08-05 18:00:13 -07003083 private void hideRecentApps(boolean triggeredFromAltTab, boolean triggeredFromHome) {
Winson Chung1e8d71b2014-05-16 17:05:22 -07003084 mPreloadedRecentApps = false; // preloading no longer needs to be canceled
3085 try {
3086 IStatusBarService statusbar = getStatusBarService();
3087 if (statusbar != null) {
Winson Chungcdcd4872014-08-05 18:00:13 -07003088 statusbar.hideRecentApps(triggeredFromAltTab, triggeredFromHome);
Winson Chung1e8d71b2014-05-16 17:05:22 -07003089 }
3090 } catch (RemoteException e) {
3091 Slog.e(TAG, "RemoteException when closing recent apps", e);
3092 // re-acquire status bar service next time it is needed.
3093 mStatusBarService = null;
3094 }
3095 }
3096
Filip Gruszczynskia483a1d2015-03-17 19:06:58 +00003097 void launchHomeFromHotKey() {
Bryce Lee662ed802015-04-10 20:11:39 +00003098 launchHomeFromHotKey(true /* awakenFromDreams */, true /*respectKeyguard*/);
Filip Gruszczynskia483a1d2015-03-17 19:06:58 +00003099 }
3100
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003101 /**
3102 * A home key -> launch home action was detected. Take the appropriate action
3103 * given the situation with the keyguard.
3104 */
Bryce Lee662ed802015-04-10 20:11:39 +00003105 void launchHomeFromHotKey(final boolean awakenFromDreams, final boolean respectKeyguard) {
3106 if (respectKeyguard) {
3107 if (isKeyguardShowingAndNotOccluded()) {
3108 // don't launch home if keyguard showing
3109 return;
3110 }
3111
3112 if (!mHideLockScreen && mKeyguardDelegate.isInputRestricted()) {
3113 // when in keyguard restricted mode, must first verify unlock
3114 // before launching home
3115 mKeyguardDelegate.verifyUnlock(new OnKeyguardExitResult() {
3116 @Override
3117 public void onKeyguardExitResult(boolean success) {
3118 if (success) {
3119 try {
3120 ActivityManagerNative.getDefault().stopAppSwitches();
3121 } catch (RemoteException e) {
3122 }
3123 sendCloseSystemWindows(SYSTEM_DIALOG_REASON_HOME_KEY);
3124 startDockOrHome(true /*fromHomeKey*/, awakenFromDreams);
Dianne Hackborn256dd3b2009-05-19 18:51:21 -07003125 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003126 }
Bryce Lee662ed802015-04-10 20:11:39 +00003127 });
3128 return;
3129 }
3130 }
3131
3132 // no keyguard stuff to worry about, just launch home!
3133 try {
3134 ActivityManagerNative.getDefault().stopAppSwitches();
3135 } catch (RemoteException e) {
3136 }
3137 if (mRecentsVisible) {
3138 // Hide Recents and notify it to launch Home
3139 if (awakenFromDreams) {
3140 awakenDreams();
3141 }
3142 sendCloseSystemWindows(SYSTEM_DIALOG_REASON_HOME_KEY);
3143 hideRecentApps(false, true);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003144 } else {
Bryce Lee662ed802015-04-10 20:11:39 +00003145 // Otherwise, just launch Home
3146 sendCloseSystemWindows(SYSTEM_DIALOG_REASON_HOME_KEY);
3147 startDockOrHome(true /*fromHomeKey*/, awakenFromDreams);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003148 }
3149 }
3150
John Spurlock04db1762013-05-13 12:46:41 -04003151 private final Runnable mClearHideNavigationFlag = new Runnable() {
3152 @Override
3153 public void run() {
3154 synchronized (mWindowManagerFuncs.getWindowManagerLock()) {
3155 // Clear flags.
3156 mForceClearedSystemUiFlags &=
3157 ~View.SYSTEM_UI_FLAG_HIDE_NAVIGATION;
3158 }
3159 mWindowManagerFuncs.reevaluateStatusBarVisibility();
Dianne Hackborne26ab702011-10-16 13:21:33 -07003160 }
3161 };
3162
3163 /**
3164 * Input handler used while nav bar is hidden. Captures any touch on the screen,
3165 * to determine when the nav bar should be shown and prevent applications from
3166 * receiving those touches.
3167 */
Jeff Brown32cbc38552011-12-01 14:01:49 -08003168 final class HideNavInputEventReceiver extends InputEventReceiver {
3169 public HideNavInputEventReceiver(InputChannel inputChannel, Looper looper) {
3170 super(inputChannel, looper);
3171 }
3172
Dianne Hackborndf89e652011-10-06 22:35:11 -07003173 @Override
Jeff Brown32cbc38552011-12-01 14:01:49 -08003174 public void onInputEvent(InputEvent event) {
Dianne Hackborndf89e652011-10-06 22:35:11 -07003175 boolean handled = false;
3176 try {
Jeff Brown4952dfd2011-11-30 19:23:22 -08003177 if (event instanceof MotionEvent
3178 && (event.getSource() & InputDevice.SOURCE_CLASS_POINTER) != 0) {
3179 final MotionEvent motionEvent = (MotionEvent)event;
3180 if (motionEvent.getAction() == MotionEvent.ACTION_DOWN) {
Dianne Hackborndf89e652011-10-06 22:35:11 -07003181 // When the user taps down, we re-show the nav bar.
3182 boolean changed = false;
John Spurlock04db1762013-05-13 12:46:41 -04003183 synchronized (mWindowManagerFuncs.getWindowManagerLock()) {
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07003184 // Any user activity always causes us to show the
3185 // navigation controls, if they had been hidden.
3186 // We also clear the low profile and only content
3187 // flags so that tapping on the screen will atomically
3188 // restore all currently hidden screen decorations.
3189 int newVal = mResettingSystemUiFlags |
3190 View.SYSTEM_UI_FLAG_HIDE_NAVIGATION |
3191 View.SYSTEM_UI_FLAG_LOW_PROFILE |
3192 View.SYSTEM_UI_FLAG_FULLSCREEN;
Dianne Hackborne26ab702011-10-16 13:21:33 -07003193 if (mResettingSystemUiFlags != newVal) {
3194 mResettingSystemUiFlags = newVal;
Dianne Hackborndf89e652011-10-06 22:35:11 -07003195 changed = true;
3196 }
Dianne Hackborne26ab702011-10-16 13:21:33 -07003197 // We don't allow the system's nav bar to be hidden
3198 // again for 1 second, to prevent applications from
3199 // spamming us and keeping it from being shown.
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07003200 newVal = mForceClearedSystemUiFlags |
3201 View.SYSTEM_UI_FLAG_HIDE_NAVIGATION;
Dianne Hackborne26ab702011-10-16 13:21:33 -07003202 if (mForceClearedSystemUiFlags != newVal) {
3203 mForceClearedSystemUiFlags = newVal;
3204 changed = true;
John Spurlock04db1762013-05-13 12:46:41 -04003205 mHandler.postDelayed(mClearHideNavigationFlag, 1000);
Dianne Hackborne26ab702011-10-16 13:21:33 -07003206 }
Dianne Hackborndf89e652011-10-06 22:35:11 -07003207 }
3208 if (changed) {
3209 mWindowManagerFuncs.reevaluateStatusBarVisibility();
3210 }
3211 }
3212 }
3213 } finally {
Jeff Brown32cbc38552011-12-01 14:01:49 -08003214 finishInputEvent(event, handled);
Dianne Hackborndf89e652011-10-06 22:35:11 -07003215 }
3216 }
Jeff Brown32cbc38552011-12-01 14:01:49 -08003217 }
3218 final InputEventReceiver.Factory mHideNavInputEventReceiverFactory =
3219 new InputEventReceiver.Factory() {
3220 @Override
3221 public InputEventReceiver createInputEventReceiver(
3222 InputChannel inputChannel, Looper looper) {
3223 return new HideNavInputEventReceiver(inputChannel, looper);
3224 }
Dianne Hackborndf89e652011-10-06 22:35:11 -07003225 };
3226
3227 @Override
3228 public int adjustSystemUiVisibilityLw(int visibility) {
John Spurlock5b9145b2013-08-20 15:13:47 -04003229 mStatusBarController.adjustSystemUiVisibilityLw(mLastSystemUiFlags, visibility);
3230 mNavigationBarController.adjustSystemUiVisibilityLw(mLastSystemUiFlags, visibility);
Winson Chungd42a6cf2014-06-03 16:24:04 -07003231 mRecentsVisible = (visibility & View.RECENT_APPS_VISIBLE) > 0;
John Spurlock27735a42013-08-14 17:57:38 -04003232
Dianne Hackborndf89e652011-10-06 22:35:11 -07003233 // Reset any bits in mForceClearingStatusBarVisibility that
3234 // are now clear.
Dianne Hackborne26ab702011-10-16 13:21:33 -07003235 mResettingSystemUiFlags &= visibility;
Dianne Hackborndf89e652011-10-06 22:35:11 -07003236 // Clear any bits in the new visibility that are currently being
3237 // force cleared, before reporting it.
Dianne Hackborne26ab702011-10-16 13:21:33 -07003238 return visibility & ~mResettingSystemUiFlags
3239 & ~mForceClearedSystemUiFlags;
Dianne Hackborndf89e652011-10-06 22:35:11 -07003240 }
3241
Craig Mautner69b08182012-09-05 13:07:13 -07003242 @Override
Adrian Roos37d7a682014-11-06 18:15:16 +01003243 public void getInsetHintLw(WindowManager.LayoutParams attrs, Rect outContentInsets,
3244 Rect outStableInsets) {
John Spurlockc6d1c602014-01-17 15:22:06 -05003245 final int fl = PolicyControl.getWindowFlags(null, attrs);
John Spurlock1db8b682014-02-18 11:18:59 -05003246 final int sysuiVis = PolicyControl.getSystemUiVisibility(null, attrs);
3247 final int systemUiVisibility = (sysuiVis | attrs.subtreeSystemUiVisibility);
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07003248
Dianne Hackborn5b5cc4d2012-05-16 13:15:00 -07003249 if ((fl & (FLAG_LAYOUT_IN_SCREEN | FLAG_LAYOUT_INSET_DECOR))
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003250 == (FLAG_LAYOUT_IN_SCREEN | FLAG_LAYOUT_INSET_DECOR)) {
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07003251 int availRight, availBottom;
Alan Viverette5a0f4ec2013-10-07 15:10:29 -07003252 if (canHideNavigationBar() &&
Dianne Hackborn5b5cc4d2012-05-16 13:15:00 -07003253 (systemUiVisibility & View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION) != 0) {
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07003254 availRight = mUnrestrictedScreenLeft + mUnrestrictedScreenWidth;
3255 availBottom = mUnrestrictedScreenTop + mUnrestrictedScreenHeight;
3256 } else {
3257 availRight = mRestrictedScreenLeft + mRestrictedScreenWidth;
3258 availBottom = mRestrictedScreenTop + mRestrictedScreenHeight;
3259 }
Dianne Hackborn5b5cc4d2012-05-16 13:15:00 -07003260 if ((systemUiVisibility & View.SYSTEM_UI_FLAG_LAYOUT_STABLE) != 0) {
3261 if ((fl & FLAG_FULLSCREEN) != 0) {
Adrian Roos37d7a682014-11-06 18:15:16 +01003262 outContentInsets.set(mStableFullscreenLeft, mStableFullscreenTop,
Dianne Hackborn5b5cc4d2012-05-16 13:15:00 -07003263 availRight - mStableFullscreenRight,
3264 availBottom - mStableFullscreenBottom);
3265 } else {
Adrian Roos37d7a682014-11-06 18:15:16 +01003266 outContentInsets.set(mStableLeft, mStableTop,
Dianne Hackborn5b5cc4d2012-05-16 13:15:00 -07003267 availRight - mStableRight, availBottom - mStableBottom);
3268 }
Dianne Hackbornc652de82013-02-15 16:32:56 -08003269 } else if ((fl & FLAG_FULLSCREEN) != 0 || (fl & FLAG_LAYOUT_IN_OVERSCAN) != 0) {
Adrian Roos37d7a682014-11-06 18:15:16 +01003270 outContentInsets.setEmpty();
Dianne Hackborn5b5cc4d2012-05-16 13:15:00 -07003271 } else if ((systemUiVisibility & (View.SYSTEM_UI_FLAG_FULLSCREEN
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07003272 | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN)) == 0) {
Adrian Roos37d7a682014-11-06 18:15:16 +01003273 outContentInsets.set(mCurLeft, mCurTop,
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07003274 availRight - mCurRight, availBottom - mCurBottom);
3275 } else {
Adrian Roos37d7a682014-11-06 18:15:16 +01003276 outContentInsets.set(mCurLeft, mCurTop,
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07003277 availRight - mCurRight, availBottom - mCurBottom);
3278 }
Adrian Roos37d7a682014-11-06 18:15:16 +01003279
3280 outStableInsets.set(mStableLeft, mStableTop,
3281 availRight - mStableRight, availBottom - mStableBottom);
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07003282 return;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003283 }
Adrian Roos37d7a682014-11-06 18:15:16 +01003284 outContentInsets.setEmpty();
3285 outStableInsets.setEmpty();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003286 }
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07003287
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003288 /** {@inheritDoc} */
Craig Mautner69b08182012-09-05 13:07:13 -07003289 @Override
3290 public void beginLayoutLw(boolean isDefaultDisplay, int displayWidth, int displayHeight,
3291 int displayRotation) {
Dianne Hackbornc652de82013-02-15 16:32:56 -08003292 final int overscanLeft, overscanTop, overscanRight, overscanBottom;
3293 if (isDefaultDisplay) {
3294 switch (displayRotation) {
3295 case Surface.ROTATION_90:
3296 overscanLeft = mOverscanTop;
3297 overscanTop = mOverscanRight;
3298 overscanRight = mOverscanBottom;
3299 overscanBottom = mOverscanLeft;
3300 break;
3301 case Surface.ROTATION_180:
3302 overscanLeft = mOverscanRight;
3303 overscanTop = mOverscanBottom;
3304 overscanRight = mOverscanLeft;
3305 overscanBottom = mOverscanTop;
3306 break;
3307 case Surface.ROTATION_270:
3308 overscanLeft = mOverscanBottom;
3309 overscanTop = mOverscanLeft;
3310 overscanRight = mOverscanTop;
3311 overscanBottom = mOverscanRight;
3312 break;
3313 default:
3314 overscanLeft = mOverscanLeft;
3315 overscanTop = mOverscanTop;
3316 overscanRight = mOverscanRight;
3317 overscanBottom = mOverscanBottom;
3318 break;
3319 }
3320 } else {
3321 overscanLeft = 0;
3322 overscanTop = 0;
3323 overscanRight = 0;
3324 overscanBottom = 0;
3325 }
Dianne Hackborn313440842013-02-19 19:22:59 -08003326 mOverscanScreenLeft = mRestrictedOverscanScreenLeft = 0;
3327 mOverscanScreenTop = mRestrictedOverscanScreenTop = 0;
3328 mOverscanScreenWidth = mRestrictedOverscanScreenWidth = displayWidth;
3329 mOverscanScreenHeight = mRestrictedOverscanScreenHeight = displayHeight;
Dianne Hackbornc652de82013-02-15 16:32:56 -08003330 mSystemLeft = 0;
3331 mSystemTop = 0;
3332 mSystemRight = displayWidth;
3333 mSystemBottom = displayHeight;
3334 mUnrestrictedScreenLeft = overscanLeft;
3335 mUnrestrictedScreenTop = overscanTop;
3336 mUnrestrictedScreenWidth = displayWidth - overscanLeft - overscanRight;
3337 mUnrestrictedScreenHeight = displayHeight - overscanTop - overscanBottom;
3338 mRestrictedScreenLeft = mUnrestrictedScreenLeft;
3339 mRestrictedScreenTop = mUnrestrictedScreenTop;
John Spurlockad3e6cb2013-04-30 08:47:43 -04003340 mRestrictedScreenWidth = mSystemGestures.screenWidth = mUnrestrictedScreenWidth;
3341 mRestrictedScreenHeight = mSystemGestures.screenHeight = mUnrestrictedScreenHeight;
Dianne Hackborne30e02f2014-05-27 18:24:45 -07003342 mDockLeft = mContentLeft = mVoiceContentLeft = mStableLeft = mStableFullscreenLeft
Dianne Hackbornc652de82013-02-15 16:32:56 -08003343 = mCurLeft = mUnrestrictedScreenLeft;
Dianne Hackborne30e02f2014-05-27 18:24:45 -07003344 mDockTop = mContentTop = mVoiceContentTop = mStableTop = mStableFullscreenTop
Dianne Hackbornc652de82013-02-15 16:32:56 -08003345 = mCurTop = mUnrestrictedScreenTop;
Dianne Hackborne30e02f2014-05-27 18:24:45 -07003346 mDockRight = mContentRight = mVoiceContentRight = mStableRight = mStableFullscreenRight
Dianne Hackbornc652de82013-02-15 16:32:56 -08003347 = mCurRight = displayWidth - overscanRight;
Dianne Hackborne30e02f2014-05-27 18:24:45 -07003348 mDockBottom = mContentBottom = mVoiceContentBottom = mStableBottom = mStableFullscreenBottom
Dianne Hackbornc652de82013-02-15 16:32:56 -08003349 = mCurBottom = displayHeight - overscanBottom;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003350 mDockLayer = 0x10000000;
Dianne Hackborn5c58de32012-04-28 19:52:37 -07003351 mStatusBarLayer = -1;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003352
Daniel Sandler8956dbb2011-04-22 07:55:02 -04003353 // start with the current dock rect, which will be (0,0,displayWidth,displayHeight)
3354 final Rect pf = mTmpParentFrame;
3355 final Rect df = mTmpDisplayFrame;
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003356 final Rect of = mTmpOverscanFrame;
Daniel Sandler8956dbb2011-04-22 07:55:02 -04003357 final Rect vf = mTmpVisibleFrame;
John Spurlock46646232013-09-30 22:32:42 -04003358 final Rect dcf = mTmpDecorFrame;
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003359 pf.left = df.left = of.left = vf.left = mDockLeft;
3360 pf.top = df.top = of.top = vf.top = mDockTop;
3361 pf.right = df.right = of.right = vf.right = mDockRight;
3362 pf.bottom = df.bottom = of.bottom = vf.bottom = mDockBottom;
John Spurlock46646232013-09-30 22:32:42 -04003363 dcf.setEmpty(); // Decor frame N/A for system bars.
Daniel Sandler8956dbb2011-04-22 07:55:02 -04003364
Craig Mautner69b08182012-09-05 13:07:13 -07003365 if (isDefaultDisplay) {
3366 // For purposes of putting out fake window up to steal focus, we will
3367 // drive nav being hidden only by whether it is requested.
John Spurlocke1f366f2013-08-05 12:22:40 -04003368 final int sysui = mLastSystemUiFlags;
3369 boolean navVisible = (sysui & View.SYSTEM_UI_FLAG_HIDE_NAVIGATION) == 0;
Adrian Roosea562512014-05-05 13:33:03 +02003370 boolean navTranslucent = (sysui
3371 & (View.NAVIGATION_BAR_TRANSLUCENT | View.SYSTEM_UI_TRANSPARENT)) != 0;
John Spurlockf1a36642013-10-12 17:50:42 -04003372 boolean immersive = (sysui & View.SYSTEM_UI_FLAG_IMMERSIVE) != 0;
3373 boolean immersiveSticky = (sysui & View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY) != 0;
3374 boolean navAllowedHidden = immersive || immersiveSticky;
3375 navTranslucent &= !immersiveSticky; // transient trumps translucent
Adrian Roos4fb3ee32014-08-22 19:29:09 +02003376 boolean isKeyguardShowing = isStatusBarKeyguard() && !mHideLockScreen;
3377 if (!isKeyguardShowing) {
3378 navTranslucent &= areTranslucentBarsAllowed();
3379 }
Dianne Hackborne26ab702011-10-16 13:21:33 -07003380
Craig Mautner69b08182012-09-05 13:07:13 -07003381 // When the navigation bar isn't visible, we put up a fake
3382 // input window to catch all touch events. This way we can
3383 // detect when the user presses anywhere to bring back the nav
3384 // bar and ensure the application doesn't see the event.
John Spurlockf1a36642013-10-12 17:50:42 -04003385 if (navVisible || navAllowedHidden) {
Selim Cinekf83e8242015-05-19 18:08:14 -07003386 if (mInputConsumer != null) {
3387 mInputConsumer.dismiss();
3388 mInputConsumer = null;
Craig Mautner69b08182012-09-05 13:07:13 -07003389 }
Selim Cinekf83e8242015-05-19 18:08:14 -07003390 } else if (mInputConsumer == null) {
3391 mInputConsumer = mWindowManagerFuncs.addInputConsumer(mHandler.getLooper(),
3392 mHideNavInputEventReceiverFactory);
Dianne Hackborne26ab702011-10-16 13:21:33 -07003393 }
Dianne Hackborne26ab702011-10-16 13:21:33 -07003394
Craig Mautner69b08182012-09-05 13:07:13 -07003395 // For purposes of positioning and showing the nav bar, if we have
3396 // decided that it can't be hidden (because of the screen aspect ratio),
3397 // then take that into account.
Alan Viverette5a0f4ec2013-10-07 15:10:29 -07003398 navVisible |= !canHideNavigationBar();
Dianne Hackbornf87d1962012-04-04 12:48:24 -07003399
John Spurlockad3e6cb2013-04-30 08:47:43 -04003400 boolean updateSysUiVisibility = false;
Craig Mautner69b08182012-09-05 13:07:13 -07003401 if (mNavigationBar != null) {
John Spurlock27735a42013-08-14 17:57:38 -04003402 boolean transientNavBarShowing = mNavigationBarController.isTransientShowing();
Craig Mautner69b08182012-09-05 13:07:13 -07003403 // Force the navigation bar to its appropriate place and
3404 // size. We need to do this directly, instead of relying on
3405 // it to bubble up from the nav bar, because this needs to
3406 // change atomically with screen rotations.
3407 mNavigationBarOnBottom = (!mNavigationBarCanMove || displayWidth < displayHeight);
3408 if (mNavigationBarOnBottom) {
3409 // It's a system nav bar or a portrait screen; nav bar goes on bottom.
Dianne Hackbornc652de82013-02-15 16:32:56 -08003410 int top = displayHeight - overscanBottom
3411 - mNavigationBarHeightForRotation[displayRotation];
3412 mTmpNavigationFrame.set(0, top, displayWidth, displayHeight - overscanBottom);
Craig Mautner69b08182012-09-05 13:07:13 -07003413 mStableBottom = mStableFullscreenBottom = mTmpNavigationFrame.top;
John Spurlockf95b89a2013-10-10 22:10:42 -04003414 if (transientNavBarShowing) {
John Spurlock27735a42013-08-14 17:57:38 -04003415 mNavigationBarController.setBarShowingLw(true);
John Spurlockad3e6cb2013-04-30 08:47:43 -04003416 } else if (navVisible) {
John Spurlock27735a42013-08-14 17:57:38 -04003417 mNavigationBarController.setBarShowingLw(true);
Craig Mautner69b08182012-09-05 13:07:13 -07003418 mDockBottom = mTmpNavigationFrame.top;
Dianne Hackborn313440842013-02-19 19:22:59 -08003419 mRestrictedScreenHeight = mDockBottom - mRestrictedScreenTop;
3420 mRestrictedOverscanScreenHeight = mDockBottom - mRestrictedOverscanScreenTop;
Craig Mautner69b08182012-09-05 13:07:13 -07003421 } else {
3422 // We currently want to hide the navigation UI.
John Spurlock27735a42013-08-14 17:57:38 -04003423 mNavigationBarController.setBarShowingLw(false);
Craig Mautner69b08182012-09-05 13:07:13 -07003424 }
John Spurlockc6d1c602014-01-17 15:22:06 -05003425 if (navVisible && !navTranslucent && !navAllowedHidden
3426 && !mNavigationBar.isAnimatingLw()
John Spurlockbd957402013-10-03 11:38:39 -04003427 && !mNavigationBarController.wasRecentlyTranslucent()) {
John Spurlocke1f366f2013-08-05 12:22:40 -04003428 // If the opaque nav bar is currently requested to be visible,
Craig Mautner69b08182012-09-05 13:07:13 -07003429 // and not in the process of animating on or off, then
3430 // we can tell the app that it is covered by it.
3431 mSystemBottom = mTmpNavigationFrame.top;
3432 }
Dianne Hackbornf87d1962012-04-04 12:48:24 -07003433 } else {
Craig Mautner69b08182012-09-05 13:07:13 -07003434 // Landscape screen; nav bar goes to the right.
Dianne Hackbornc652de82013-02-15 16:32:56 -08003435 int left = displayWidth - overscanRight
3436 - mNavigationBarWidthForRotation[displayRotation];
3437 mTmpNavigationFrame.set(left, 0, displayWidth - overscanRight, displayHeight);
Craig Mautner69b08182012-09-05 13:07:13 -07003438 mStableRight = mStableFullscreenRight = mTmpNavigationFrame.left;
John Spurlockf95b89a2013-10-10 22:10:42 -04003439 if (transientNavBarShowing) {
John Spurlock27735a42013-08-14 17:57:38 -04003440 mNavigationBarController.setBarShowingLw(true);
John Spurlockad3e6cb2013-04-30 08:47:43 -04003441 } else if (navVisible) {
John Spurlock27735a42013-08-14 17:57:38 -04003442 mNavigationBarController.setBarShowingLw(true);
Craig Mautner69b08182012-09-05 13:07:13 -07003443 mDockRight = mTmpNavigationFrame.left;
Dianne Hackborn313440842013-02-19 19:22:59 -08003444 mRestrictedScreenWidth = mDockRight - mRestrictedScreenLeft;
3445 mRestrictedOverscanScreenWidth = mDockRight - mRestrictedOverscanScreenLeft;
Craig Mautner69b08182012-09-05 13:07:13 -07003446 } else {
3447 // We currently want to hide the navigation UI.
John Spurlock27735a42013-08-14 17:57:38 -04003448 mNavigationBarController.setBarShowingLw(false);
Craig Mautner69b08182012-09-05 13:07:13 -07003449 }
John Spurlockbd957402013-10-03 11:38:39 -04003450 if (navVisible && !navTranslucent && !mNavigationBar.isAnimatingLw()
3451 && !mNavigationBarController.wasRecentlyTranslucent()) {
Craig Mautner69b08182012-09-05 13:07:13 -07003452 // If the nav bar is currently requested to be visible,
3453 // and not in the process of animating on or off, then
3454 // we can tell the app that it is covered by it.
3455 mSystemRight = mTmpNavigationFrame.left;
3456 }
Dianne Hackbornf87d1962012-04-04 12:48:24 -07003457 }
Craig Mautner69b08182012-09-05 13:07:13 -07003458 // Make sure the content and current rectangles are updated to
3459 // account for the restrictions from the navigation bar.
Dianne Hackborne30e02f2014-05-27 18:24:45 -07003460 mContentTop = mVoiceContentTop = mCurTop = mDockTop;
3461 mContentBottom = mVoiceContentBottom = mCurBottom = mDockBottom;
3462 mContentLeft = mVoiceContentLeft = mCurLeft = mDockLeft;
3463 mContentRight = mVoiceContentRight = mCurRight = mDockRight;
Craig Mautner69b08182012-09-05 13:07:13 -07003464 mStatusBarLayer = mNavigationBar.getSurfaceLayer();
3465 // And compute the final frame.
3466 mNavigationBar.computeFrameLw(mTmpNavigationFrame, mTmpNavigationFrame,
Adrian Roosfa104232014-06-20 16:10:14 -07003467 mTmpNavigationFrame, mTmpNavigationFrame, mTmpNavigationFrame, dcf,
3468 mTmpNavigationFrame);
Craig Mautnereda67292013-04-28 13:50:14 -07003469 if (DEBUG_LAYOUT) Slog.i(TAG, "mNavigationBar frame: " + mTmpNavigationFrame);
John Spurlock27735a42013-08-14 17:57:38 -04003470 if (mNavigationBarController.checkHiddenLw()) {
John Spurlockad3e6cb2013-04-30 08:47:43 -04003471 updateSysUiVisibility = true;
3472 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003473 }
Craig Mautnereda67292013-04-28 13:50:14 -07003474 if (DEBUG_LAYOUT) Slog.i(TAG, String.format("mDock rect: (%d,%d - %d,%d)",
Craig Mautner69b08182012-09-05 13:07:13 -07003475 mDockLeft, mDockTop, mDockRight, mDockBottom));
3476
3477 // decide where the status bar goes ahead of time
3478 if (mStatusBar != null) {
3479 // apply any navigation bar insets
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003480 pf.left = df.left = of.left = mUnrestrictedScreenLeft;
3481 pf.top = df.top = of.top = mUnrestrictedScreenTop;
3482 pf.right = df.right = of.right = mUnrestrictedScreenWidth + mUnrestrictedScreenLeft;
3483 pf.bottom = df.bottom = of.bottom = mUnrestrictedScreenHeight
3484 + mUnrestrictedScreenTop;
Craig Mautner69b08182012-09-05 13:07:13 -07003485 vf.left = mStableLeft;
3486 vf.top = mStableTop;
3487 vf.right = mStableRight;
3488 vf.bottom = mStableBottom;
3489
3490 mStatusBarLayer = mStatusBar.getSurfaceLayer();
3491
3492 // Let the status bar determine its size.
Adrian Roosfa104232014-06-20 16:10:14 -07003493 mStatusBar.computeFrameLw(pf, df, vf, vf, vf, dcf, vf);
Craig Mautner69b08182012-09-05 13:07:13 -07003494
3495 // For layout, the status bar is always at the top with our fixed height.
3496 mStableTop = mUnrestrictedScreenTop + mStatusBarHeight;
3497
John Spurlocke1f366f2013-08-05 12:22:40 -04003498 boolean statusBarTransient = (sysui & View.STATUS_BAR_TRANSIENT) != 0;
Adrian Roosea562512014-05-05 13:33:03 +02003499 boolean statusBarTranslucent = (sysui
3500 & (View.STATUS_BAR_TRANSLUCENT | View.SYSTEM_UI_TRANSPARENT)) != 0;
Adrian Roos4fb3ee32014-08-22 19:29:09 +02003501 if (!isKeyguardShowing) {
3502 statusBarTranslucent &= areTranslucentBarsAllowed();
3503 }
John Spurlock32beb2c2013-03-11 10:16:47 -04003504
Craig Mautner69b08182012-09-05 13:07:13 -07003505 // If the status bar is hidden, we don't want to cause
3506 // windows behind it to scroll.
John Spurlockeda1f692013-09-16 11:38:44 -04003507 if (mStatusBar.isVisibleLw() && !statusBarTransient) {
Craig Mautner69b08182012-09-05 13:07:13 -07003508 // Status bar may go away, so the screen area it occupies
3509 // is available to apps but just covering them when the
3510 // status bar is visible.
3511 mDockTop = mUnrestrictedScreenTop + mStatusBarHeight;
3512
Dianne Hackborne30e02f2014-05-27 18:24:45 -07003513 mContentTop = mVoiceContentTop = mCurTop = mDockTop;
3514 mContentBottom = mVoiceContentBottom = mCurBottom = mDockBottom;
3515 mContentLeft = mVoiceContentLeft = mCurLeft = mDockLeft;
3516 mContentRight = mVoiceContentRight = mCurRight = mDockRight;
Craig Mautner69b08182012-09-05 13:07:13 -07003517
Craig Mautnereda67292013-04-28 13:50:14 -07003518 if (DEBUG_LAYOUT) Slog.v(TAG, "Status bar: " +
Craig Mautner69b08182012-09-05 13:07:13 -07003519 String.format(
3520 "dock=[%d,%d][%d,%d] content=[%d,%d][%d,%d] cur=[%d,%d][%d,%d]",
3521 mDockLeft, mDockTop, mDockRight, mDockBottom,
3522 mContentLeft, mContentTop, mContentRight, mContentBottom,
3523 mCurLeft, mCurTop, mCurRight, mCurBottom));
3524 }
John Spurlocke1f366f2013-08-05 12:22:40 -04003525 if (mStatusBar.isVisibleLw() && !mStatusBar.isAnimatingLw()
John Spurlockbd957402013-10-03 11:38:39 -04003526 && !statusBarTransient && !statusBarTranslucent
3527 && !mStatusBarController.wasRecentlyTranslucent()) {
John Spurlocke1f366f2013-08-05 12:22:40 -04003528 // If the opaque status bar is currently requested to be visible,
Craig Mautner69b08182012-09-05 13:07:13 -07003529 // and not in the process of animating on or off, then
3530 // we can tell the app that it is covered by it.
3531 mSystemTop = mUnrestrictedScreenTop + mStatusBarHeight;
3532 }
John Spurlock27735a42013-08-14 17:57:38 -04003533 if (mStatusBarController.checkHiddenLw()) {
John Spurlockad3e6cb2013-04-30 08:47:43 -04003534 updateSysUiVisibility = true;
John Spurlock32beb2c2013-03-11 10:16:47 -04003535 }
Dianne Hackborn5c58de32012-04-28 19:52:37 -07003536 }
John Spurlockad3e6cb2013-04-30 08:47:43 -04003537 if (updateSysUiVisibility) {
3538 updateSystemUiVisibilityLw();
3539 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003540 }
3541 }
3542
Dianne Hackborn85afd1b2012-05-13 13:31:06 -07003543 /** {@inheritDoc} */
Craig Mautner967212c2013-04-13 21:10:58 -07003544 @Override
John Spurlock46646232013-09-30 22:32:42 -04003545 public int getSystemDecorLayerLw() {
Bryce Lee2ed3e5f2015-04-01 22:09:19 +00003546 if (mStatusBar != null && mStatusBar.isVisibleLw()) {
3547 return mStatusBar.getSurfaceLayer();
3548 }
3549
3550 if (mNavigationBar != null && mNavigationBar.isVisibleLw()) {
3551 return mNavigationBar.getSurfaceLayer();
3552 }
3553
Dianne Hackborn85afd1b2012-05-13 13:31:06 -07003554 return 0;
3555 }
3556
Craig Mautner967212c2013-04-13 21:10:58 -07003557 @Override
3558 public void getContentRectLw(Rect r) {
3559 r.set(mContentLeft, mContentTop, mContentRight, mContentBottom);
3560 }
3561
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003562 void setAttachedWindowFrames(WindowState win, int fl, int adjust, WindowState attached,
3563 boolean insetDecors, Rect pf, Rect df, Rect of, Rect cf, Rect vf) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003564 if (win.getSurfaceLayer() > mDockLayer && attached.getSurfaceLayer() < mDockLayer) {
3565 // Here's a special case: if this attached window is a panel that is
3566 // above the dock window, and the window it is attached to is below
3567 // the dock window, then the frames we computed for the window it is
3568 // attached to can not be used because the dock is effectively part
3569 // of the underlying window and the attached window is floating on top
3570 // of the whole thing. So, we ignore the attached window and explicitly
3571 // compute the frames that would be appropriate without the dock.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003572 df.left = of.left = cf.left = vf.left = mDockLeft;
3573 df.top = of.top = cf.top = vf.top = mDockTop;
3574 df.right = of.right = cf.right = vf.right = mDockRight;
3575 df.bottom = of.bottom = cf.bottom = vf.bottom = mDockBottom;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003576 } else {
3577 // The effective display frame of the attached window depends on
3578 // whether it is taking care of insetting its content. If not,
3579 // we need to use the parent's content frame so that the entire
3580 // window is positioned within that content. Otherwise we can use
Wale Ogunwale393b1c12014-10-18 16:22:01 -07003581 // the overscan frame and let the attached window take care of
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003582 // positioning its content appropriately.
Dianne Hackborndea3ef72010-10-28 14:24:22 -07003583 if (adjust != SOFT_INPUT_ADJUST_RESIZE) {
Wale Ogunwale393b1c12014-10-18 16:22:01 -07003584 // Set the content frame of the attached window to the parent's decor frame
3585 // (same as content frame when IME isn't present) if specifically requested by
3586 // setting {@link WindowManager.LayoutParams#FLAG_LAYOUT_ATTACHED_IN_DECOR} flag.
3587 // Otherwise, use the overscan frame.
3588 cf.set((fl & FLAG_LAYOUT_ATTACHED_IN_DECOR) != 0
3589 ? attached.getContentFrameLw() : attached.getOverscanFrameLw());
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003590 } else {
3591 // If the window is resizing, then we want to base the content
3592 // frame on our attached content frame to resize... however,
3593 // things can be tricky if the attached window is NOT in resize
3594 // mode, in which case its content frame will be larger.
3595 // Ungh. So to deal with that, make sure the content frame
3596 // we end up using is not covering the IM dock.
3597 cf.set(attached.getContentFrameLw());
Dianne Hackborne30e02f2014-05-27 18:24:45 -07003598 if (attached.isVoiceInteraction()) {
3599 if (cf.left < mVoiceContentLeft) cf.left = mVoiceContentLeft;
3600 if (cf.top < mVoiceContentTop) cf.top = mVoiceContentTop;
3601 if (cf.right > mVoiceContentRight) cf.right = mVoiceContentRight;
3602 if (cf.bottom > mVoiceContentBottom) cf.bottom = mVoiceContentBottom;
3603 } else if (attached.getSurfaceLayer() < mDockLayer) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003604 if (cf.left < mContentLeft) cf.left = mContentLeft;
3605 if (cf.top < mContentTop) cf.top = mContentTop;
3606 if (cf.right > mContentRight) cf.right = mContentRight;
3607 if (cf.bottom > mContentBottom) cf.bottom = mContentBottom;
3608 }
3609 }
3610 df.set(insetDecors ? attached.getDisplayFrameLw() : cf);
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003611 of.set(insetDecors ? attached.getOverscanFrameLw() : cf);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003612 vf.set(attached.getVisibleFrameLw());
3613 }
3614 // The LAYOUT_IN_SCREEN flag is used to determine whether the attached
3615 // window should be positioned relative to its parent or the entire
3616 // screen.
3617 pf.set((fl & FLAG_LAYOUT_IN_SCREEN) == 0
3618 ? attached.getFrameLw() : df);
3619 }
Dianne Hackborn5b5cc4d2012-05-16 13:15:00 -07003620
3621 private void applyStableConstraints(int sysui, int fl, Rect r) {
3622 if ((sysui & View.SYSTEM_UI_FLAG_LAYOUT_STABLE) != 0) {
3623 // If app is requesting a stable layout, don't let the
3624 // content insets go below the stable values.
3625 if ((fl & FLAG_FULLSCREEN) != 0) {
3626 if (r.left < mStableFullscreenLeft) r.left = mStableFullscreenLeft;
3627 if (r.top < mStableFullscreenTop) r.top = mStableFullscreenTop;
3628 if (r.right > mStableFullscreenRight) r.right = mStableFullscreenRight;
3629 if (r.bottom > mStableFullscreenBottom) r.bottom = mStableFullscreenBottom;
3630 } else {
3631 if (r.left < mStableLeft) r.left = mStableLeft;
3632 if (r.top < mStableTop) r.top = mStableTop;
3633 if (r.right > mStableRight) r.right = mStableRight;
3634 if (r.bottom > mStableBottom) r.bottom = mStableBottom;
3635 }
3636 }
3637 }
3638
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003639 /** {@inheritDoc} */
Craig Mautner69b08182012-09-05 13:07:13 -07003640 @Override
Craig Mautnerc9457fa2014-06-06 14:27:48 -07003641 public void layoutWindowLw(WindowState win, WindowState attached) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003642 // we've already done the status bar
Craig Mautnerc9457fa2014-06-06 14:27:48 -07003643 final WindowManager.LayoutParams attrs = win.getAttrs();
3644 if ((win == mStatusBar && (attrs.privateFlags & PRIVATE_FLAG_KEYGUARD) == 0) ||
3645 win == mNavigationBar) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003646 return;
3647 }
Craig Mautner69b08182012-09-05 13:07:13 -07003648 final boolean isDefaultDisplay = win.isDefaultDisplay();
3649 final boolean needsToOffsetInputMethodTarget = isDefaultDisplay &&
satok1bc0a492012-04-25 22:47:12 +09003650 (win == mLastInputMethodTargetWindow && mLastInputMethodWindow != null);
3651 if (needsToOffsetInputMethodTarget) {
Craig Mautnereda67292013-04-28 13:50:14 -07003652 if (DEBUG_LAYOUT) Slog.i(TAG, "Offset ime target window by the last ime window state");
satok1bc0a492012-04-25 22:47:12 +09003653 offsetInputMethodWindowLw(mLastInputMethodWindow);
3654 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003655
John Spurlockc6d1c602014-01-17 15:22:06 -05003656 final int fl = PolicyControl.getWindowFlags(win, attrs);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003657 final int sim = attrs.softInputMode;
John Spurlock1db8b682014-02-18 11:18:59 -05003658 final int sysUiFl = PolicyControl.getSystemUiVisibility(win, null);
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07003659
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003660 final Rect pf = mTmpParentFrame;
3661 final Rect df = mTmpDisplayFrame;
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003662 final Rect of = mTmpOverscanFrame;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003663 final Rect cf = mTmpContentFrame;
3664 final Rect vf = mTmpVisibleFrame;
John Spurlock46646232013-09-30 22:32:42 -04003665 final Rect dcf = mTmpDecorFrame;
Adrian Roosfa104232014-06-20 16:10:14 -07003666 final Rect sf = mTmpStableFrame;
John Spurlock46646232013-09-30 22:32:42 -04003667 dcf.setEmpty();
Craig Mautner69b08182012-09-05 13:07:13 -07003668
3669 final boolean hasNavBar = (isDefaultDisplay && mHasNavigationBar
Daniel Sandler36412a72011-08-04 09:35:13 -04003670 && mNavigationBar != null && mNavigationBar.isVisibleLw());
Daniel Sandler8956dbb2011-04-22 07:55:02 -04003671
Craig Mautnerf683b562012-10-02 11:10:57 -07003672 final int adjust = sim & SOFT_INPUT_MASK_ADJUST;
3673
Adrian Roosfa104232014-06-20 16:10:14 -07003674 if (isDefaultDisplay) {
3675 sf.set(mStableLeft, mStableTop, mStableRight, mStableBottom);
3676 } else {
3677 sf.set(mOverscanLeft, mOverscanTop, mOverscanRight, mOverscanBottom);
3678 }
3679
Craig Mautner69b08182012-09-05 13:07:13 -07003680 if (!isDefaultDisplay) {
3681 if (attached != null) {
3682 // If this window is attached to another, our display
3683 // frame is the same as the one we are attached to.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003684 setAttachedWindowFrames(win, fl, adjust, attached, true, pf, df, of, cf, vf);
Craig Mautner69b08182012-09-05 13:07:13 -07003685 } else {
3686 // Give the window full screen.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003687 pf.left = df.left = of.left = cf.left = mOverscanScreenLeft;
3688 pf.top = df.top = of.top = cf.top = mOverscanScreenTop;
3689 pf.right = df.right = of.right = cf.right
Dianne Hackbornc652de82013-02-15 16:32:56 -08003690 = mOverscanScreenLeft + mOverscanScreenWidth;
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003691 pf.bottom = df.bottom = of.bottom = cf.bottom
Dianne Hackbornc652de82013-02-15 16:32:56 -08003692 = mOverscanScreenTop + mOverscanScreenHeight;
Craig Mautner69b08182012-09-05 13:07:13 -07003693 }
Jorim Jaggi225d3b52015-04-01 11:18:57 -07003694 } else if (attrs.type == TYPE_INPUT_METHOD) {
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003695 pf.left = df.left = of.left = cf.left = vf.left = mDockLeft;
3696 pf.top = df.top = of.top = cf.top = vf.top = mDockTop;
3697 pf.right = df.right = of.right = cf.right = vf.right = mDockRight;
John Spurlockc68d5772013-10-08 11:47:58 -04003698 // IM dock windows layout below the nav bar...
John Spurlock57beb3b2013-10-10 10:27:44 -04003699 pf.bottom = df.bottom = of.bottom = mUnrestrictedScreenTop + mUnrestrictedScreenHeight;
John Spurlockc68d5772013-10-08 11:47:58 -04003700 // ...with content insets above the nav bar
3701 cf.bottom = vf.bottom = mStableBottom;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003702 // IM dock windows always go to the bottom of the screen.
3703 attrs.gravity = Gravity.BOTTOM;
3704 mDockLayer = win.getSurfaceLayer();
Jorim Jaggi225d3b52015-04-01 11:18:57 -07003705 } else if (attrs.type == TYPE_VOICE_INTERACTION) {
3706 pf.left = df.left = of.left = cf.left = vf.left = mUnrestrictedScreenLeft;
3707 pf.top = df.top = of.top = mUnrestrictedScreenTop;
3708 pf.right = df.right = of.right = cf.right = vf.right = mUnrestrictedScreenLeft
3709 + mUnrestrictedScreenWidth;
3710 pf.bottom = df.bottom = of.bottom = cf.bottom = mUnrestrictedScreenTop
3711 + mUnrestrictedScreenHeight;
3712 cf.bottom = vf.bottom = mStableBottom;
3713 cf.top = vf.top = mStableTop;
Jorim Jaggie0700182014-08-21 01:12:37 +02003714 } else if (win == mStatusBar && (attrs.privateFlags & PRIVATE_FLAG_KEYGUARD) != 0) {
3715 pf.left = df.left = of.left = mUnrestrictedScreenLeft;
3716 pf.top = df.top = of.top = mUnrestrictedScreenTop;
3717 pf.right = df.right = of.right = mUnrestrictedScreenWidth + mUnrestrictedScreenLeft;
3718 pf.bottom = df.bottom = of.bottom = mUnrestrictedScreenHeight + mUnrestrictedScreenTop;
3719 cf.left = vf.left = mStableLeft;
3720 cf.top = vf.top = mStableTop;
3721 cf.right = vf.right = mStableRight;
3722 vf.bottom = mStableBottom;
3723 cf.bottom = mContentBottom;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003724 } else {
John Spurlock46646232013-09-30 22:32:42 -04003725
3726 // Default policy decor for the default display
3727 dcf.left = mSystemLeft;
3728 dcf.top = mSystemTop;
3729 dcf.right = mSystemRight;
3730 dcf.bottom = mSystemBottom;
John Spurlockbd957402013-10-03 11:38:39 -04003731 final boolean inheritTranslucentDecor = (attrs.privateFlags
3732 & WindowManager.LayoutParams.PRIVATE_FLAG_INHERIT_TRANSLUCENT_DECOR) != 0;
John Spurlock65567d42013-10-08 10:08:32 -04003733 final boolean isAppWindow =
3734 attrs.type >= WindowManager.LayoutParams.FIRST_APPLICATION_WINDOW &&
3735 attrs.type <= WindowManager.LayoutParams.LAST_APPLICATION_WINDOW;
3736 final boolean topAtRest =
3737 win == mTopFullscreenOpaqueWindowState && !win.isAnimatingLw();
3738 if (isAppWindow && !inheritTranslucentDecor && !topAtRest) {
John Spurlockbd957402013-10-03 11:38:39 -04003739 if ((sysUiFl & View.SYSTEM_UI_FLAG_FULLSCREEN) == 0
3740 && (fl & WindowManager.LayoutParams.FLAG_FULLSCREEN) == 0
Adrian Roosea562512014-05-05 13:33:03 +02003741 && (fl & WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS) == 0
3742 && (fl & WindowManager.LayoutParams.
3743 FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS) == 0) {
John Spurlock46646232013-09-30 22:32:42 -04003744 // Ensure policy decor includes status bar
3745 dcf.top = mStableTop;
3746 }
John Spurlockbd957402013-10-03 11:38:39 -04003747 if ((fl & WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION) == 0
Adrian Roosea562512014-05-05 13:33:03 +02003748 && (sysUiFl & View.SYSTEM_UI_FLAG_HIDE_NAVIGATION) == 0
3749 && (fl & WindowManager.LayoutParams.
3750 FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS) == 0) {
John Spurlock46646232013-09-30 22:32:42 -04003751 // Ensure policy decor includes navigation bar
3752 dcf.bottom = mStableBottom;
3753 dcf.right = mStableRight;
3754 }
3755 }
3756
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003757 if ((fl & (FLAG_LAYOUT_IN_SCREEN | FLAG_LAYOUT_INSET_DECOR))
3758 == (FLAG_LAYOUT_IN_SCREEN | FLAG_LAYOUT_INSET_DECOR)) {
RoboErik8a2cfc32014-05-16 11:19:38 -07003759 if (DEBUG_LAYOUT) Slog.v(TAG, "layoutWindowLw(" + attrs.getTitle()
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003760 + "): IN_SCREEN, INSET_DECOR");
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003761 // This is the case for a normal activity window: we want it
3762 // to cover all of the screen space, and it can take care of
3763 // moving its contents to account for screen decorations that
3764 // intrude into that space.
3765 if (attached != null) {
3766 // If this window is attached to another, our display
3767 // frame is the same as the one we are attached to.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003768 setAttachedWindowFrames(win, fl, adjust, attached, true, pf, df, of, cf, vf);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003769 } else {
Daniel Sandler8956dbb2011-04-22 07:55:02 -04003770 if (attrs.type == TYPE_STATUS_BAR_PANEL
3771 || attrs.type == TYPE_STATUS_BAR_SUB_PANEL) {
Joe Onorato29fc2c92010-11-24 10:26:50 -08003772 // Status bar panels are the only windows who can go on top of
3773 // the status bar. They are protected by the STATUS_BAR_SERVICE
3774 // permission, so they have the same privileges as the status
3775 // bar itself.
Daniel Sandler8956dbb2011-04-22 07:55:02 -04003776 //
Daniel Sandler8e8b4152011-07-21 01:16:43 -04003777 // However, they should still dodge the navigation bar if it exists.
Daniel Sandler8956dbb2011-04-22 07:55:02 -04003778
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003779 pf.left = df.left = of.left = hasNavBar
3780 ? mDockLeft : mUnrestrictedScreenLeft;
3781 pf.top = df.top = of.top = mUnrestrictedScreenTop;
3782 pf.right = df.right = of.right = hasNavBar
3783 ? mRestrictedScreenLeft+mRestrictedScreenWidth
3784 : mUnrestrictedScreenLeft + mUnrestrictedScreenWidth;
3785 pf.bottom = df.bottom = of.bottom = hasNavBar
3786 ? mRestrictedScreenTop+mRestrictedScreenHeight
3787 : mUnrestrictedScreenTop + mUnrestrictedScreenHeight;
Daniel Sandler8956dbb2011-04-22 07:55:02 -04003788
Craig Mautnereda67292013-04-28 13:50:14 -07003789 if (DEBUG_LAYOUT) Slog.v(TAG, String.format(
Daniel Sandler8e8b4152011-07-21 01:16:43 -04003790 "Laying out status bar window: (%d,%d - %d,%d)",
3791 pf.left, pf.top, pf.right, pf.bottom));
John Spurlock46646232013-09-30 22:32:42 -04003792 } else if ((fl & FLAG_LAYOUT_IN_OVERSCAN) != 0
Dianne Hackbornc652de82013-02-15 16:32:56 -08003793 && attrs.type >= WindowManager.LayoutParams.FIRST_APPLICATION_WINDOW
3794 && attrs.type <= WindowManager.LayoutParams.LAST_SUB_WINDOW) {
3795 // Asking to layout into the overscan region, so give it that pure
3796 // unrestricted area.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003797 pf.left = df.left = of.left = mOverscanScreenLeft;
3798 pf.top = df.top = of.top = mOverscanScreenTop;
3799 pf.right = df.right = of.right = mOverscanScreenLeft + mOverscanScreenWidth;
3800 pf.bottom = df.bottom = of.bottom = mOverscanScreenTop
3801 + mOverscanScreenHeight;
Alan Viverette5a0f4ec2013-10-07 15:10:29 -07003802 } else if (canHideNavigationBar()
Dianne Hackbornf87d1962012-04-04 12:48:24 -07003803 && (sysUiFl & View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION) != 0
Jorim Jaggi380ecb82014-03-14 17:25:20 +01003804 && attrs.type >= WindowManager.LayoutParams.FIRST_APPLICATION_WINDOW
3805 && attrs.type <= WindowManager.LayoutParams.LAST_SUB_WINDOW) {
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07003806 // Asking for layout as if the nav bar is hidden, lets the
Dianne Hackbornc652de82013-02-15 16:32:56 -08003807 // application extend into the unrestricted overscan screen area. We
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07003808 // only do this for application windows to ensure no window that
3809 // can be above the nav bar can do this.
Dianne Hackborn313440842013-02-19 19:22:59 -08003810 pf.left = df.left = mOverscanScreenLeft;
3811 pf.top = df.top = mOverscanScreenTop;
3812 pf.right = df.right = mOverscanScreenLeft + mOverscanScreenWidth;
3813 pf.bottom = df.bottom = mOverscanScreenTop + mOverscanScreenHeight;
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003814 // We need to tell the app about where the frame inside the overscan
3815 // is, so it can inset its content by that amount -- it didn't ask
3816 // to actually extend itself into the overscan region.
3817 of.left = mUnrestrictedScreenLeft;
3818 of.top = mUnrestrictedScreenTop;
3819 of.right = mUnrestrictedScreenLeft + mUnrestrictedScreenWidth;
3820 of.bottom = mUnrestrictedScreenTop + mUnrestrictedScreenHeight;
Joe Onorato29fc2c92010-11-24 10:26:50 -08003821 } else {
Dianne Hackborn313440842013-02-19 19:22:59 -08003822 pf.left = df.left = mRestrictedOverscanScreenLeft;
3823 pf.top = df.top = mRestrictedOverscanScreenTop;
3824 pf.right = df.right = mRestrictedOverscanScreenLeft
3825 + mRestrictedOverscanScreenWidth;
3826 pf.bottom = df.bottom = mRestrictedOverscanScreenTop
3827 + mRestrictedOverscanScreenHeight;
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003828 // We need to tell the app about where the frame inside the overscan
3829 // is, so it can inset its content by that amount -- it didn't ask
3830 // to actually extend itself into the overscan region.
3831 of.left = mUnrestrictedScreenLeft;
3832 of.top = mUnrestrictedScreenTop;
3833 of.right = mUnrestrictedScreenLeft + mUnrestrictedScreenWidth;
3834 of.bottom = mUnrestrictedScreenTop + mUnrestrictedScreenHeight;
Joe Onorato29fc2c92010-11-24 10:26:50 -08003835 }
Craig Mautner69b08182012-09-05 13:07:13 -07003836
John Spurlock46646232013-09-30 22:32:42 -04003837 if ((fl & FLAG_FULLSCREEN) == 0) {
Dianne Hackborne30e02f2014-05-27 18:24:45 -07003838 if (win.isVoiceInteraction()) {
3839 cf.left = mVoiceContentLeft;
3840 cf.top = mVoiceContentTop;
3841 cf.right = mVoiceContentRight;
3842 cf.bottom = mVoiceContentBottom;
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003843 } else {
Dianne Hackborne30e02f2014-05-27 18:24:45 -07003844 if (adjust != SOFT_INPUT_ADJUST_RESIZE) {
3845 cf.left = mDockLeft;
3846 cf.top = mDockTop;
3847 cf.right = mDockRight;
3848 cf.bottom = mDockBottom;
3849 } else {
3850 cf.left = mContentLeft;
3851 cf.top = mContentTop;
3852 cf.right = mContentRight;
3853 cf.bottom = mContentBottom;
3854 }
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003855 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003856 } else {
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003857 // Full screen windows are always given a layout that is as if the
3858 // status bar and other transient decors are gone. This is to avoid
3859 // bad states when moving from a window that is not hding the
3860 // status bar to one that is.
3861 cf.left = mRestrictedScreenLeft;
3862 cf.top = mRestrictedScreenTop;
3863 cf.right = mRestrictedScreenLeft + mRestrictedScreenWidth;
3864 cf.bottom = mRestrictedScreenTop + mRestrictedScreenHeight;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003865 }
Dianne Hackborn5b5cc4d2012-05-16 13:15:00 -07003866 applyStableConstraints(sysUiFl, fl, cf);
Dianne Hackborndea3ef72010-10-28 14:24:22 -07003867 if (adjust != SOFT_INPUT_ADJUST_NOTHING) {
3868 vf.left = mCurLeft;
3869 vf.top = mCurTop;
3870 vf.right = mCurRight;
3871 vf.bottom = mCurBottom;
3872 } else {
3873 vf.set(cf);
3874 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003875 }
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07003876 } else if ((fl & FLAG_LAYOUT_IN_SCREEN) != 0 || (sysUiFl
3877 & (View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
3878 | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION)) != 0) {
Craig Mautnereda67292013-04-28 13:50:14 -07003879 if (DEBUG_LAYOUT) Slog.v(TAG, "layoutWindowLw(" + attrs.getTitle() +
3880 "): IN_SCREEN");
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003881 // A window that has requested to fill the entire screen just
3882 // gets everything, period.
Daniel Sandler8956dbb2011-04-22 07:55:02 -04003883 if (attrs.type == TYPE_STATUS_BAR_PANEL
3884 || attrs.type == TYPE_STATUS_BAR_SUB_PANEL) {
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003885 pf.left = df.left = of.left = cf.left = hasNavBar
3886 ? mDockLeft : mUnrestrictedScreenLeft;
3887 pf.top = df.top = of.top = cf.top = mUnrestrictedScreenTop;
3888 pf.right = df.right = of.right = cf.right = hasNavBar
Daniel Sandler8e8b4152011-07-21 01:16:43 -04003889 ? mRestrictedScreenLeft+mRestrictedScreenWidth
Dianne Hackbornc652de82013-02-15 16:32:56 -08003890 : mUnrestrictedScreenLeft + mUnrestrictedScreenWidth;
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003891 pf.bottom = df.bottom = of.bottom = cf.bottom = hasNavBar
Daniel Sandler8e8b4152011-07-21 01:16:43 -04003892 ? mRestrictedScreenTop+mRestrictedScreenHeight
Dianne Hackbornc652de82013-02-15 16:32:56 -08003893 : mUnrestrictedScreenTop + mUnrestrictedScreenHeight;
Craig Mautnereda67292013-04-28 13:50:14 -07003894 if (DEBUG_LAYOUT) Slog.v(TAG, String.format(
Daniel Sandler36412a72011-08-04 09:35:13 -04003895 "Laying out IN_SCREEN status bar window: (%d,%d - %d,%d)",
3896 pf.left, pf.top, pf.right, pf.bottom));
Jim Millere898ac52012-04-06 17:10:57 -07003897 } else if (attrs.type == TYPE_NAVIGATION_BAR
3898 || attrs.type == TYPE_NAVIGATION_BAR_PANEL) {
Daniel Sandler8e8b4152011-07-21 01:16:43 -04003899 // The navigation bar has Real Ultimate Power.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003900 pf.left = df.left = of.left = mUnrestrictedScreenLeft;
3901 pf.top = df.top = of.top = mUnrestrictedScreenTop;
3902 pf.right = df.right = of.right = mUnrestrictedScreenLeft
3903 + mUnrestrictedScreenWidth;
3904 pf.bottom = df.bottom = of.bottom = mUnrestrictedScreenTop
3905 + mUnrestrictedScreenHeight;
Craig Mautnereda67292013-04-28 13:50:14 -07003906 if (DEBUG_LAYOUT) Slog.v(TAG, String.format(
Daniel Sandler8e8b4152011-07-21 01:16:43 -04003907 "Laying out navigation bar window: (%d,%d - %d,%d)",
3908 pf.left, pf.top, pf.right, pf.bottom));
Dianne Hackborn01011c32012-02-21 13:54:21 -08003909 } else if ((attrs.type == TYPE_SECURE_SYSTEM_OVERLAY
3910 || attrs.type == TYPE_BOOT_PROGRESS)
Jeff Brownbfcb60a2011-09-08 18:51:14 -07003911 && ((fl & FLAG_FULLSCREEN) != 0)) {
3912 // Fullscreen secure system overlays get what they ask for.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003913 pf.left = df.left = of.left = cf.left = mOverscanScreenLeft;
3914 pf.top = df.top = of.top = cf.top = mOverscanScreenTop;
3915 pf.right = df.right = of.right = cf.right = mOverscanScreenLeft
3916 + mOverscanScreenWidth;
3917 pf.bottom = df.bottom = of.bottom = cf.bottom = mOverscanScreenTop
3918 + mOverscanScreenHeight;
Craig Mautner165be0c2015-01-27 15:16:58 -08003919 } else if (attrs.type == TYPE_BOOT_PROGRESS) {
Dianne Hackborn01011c32012-02-21 13:54:21 -08003920 // Boot progress screen always covers entire display.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003921 pf.left = df.left = of.left = cf.left = mOverscanScreenLeft;
3922 pf.top = df.top = of.top = cf.top = mOverscanScreenTop;
3923 pf.right = df.right = of.right = cf.right = mOverscanScreenLeft
3924 + mOverscanScreenWidth;
3925 pf.bottom = df.bottom = of.bottom = cf.bottom = mOverscanScreenTop
3926 + mOverscanScreenHeight;
John Spurlockef4adae2013-08-26 17:58:58 -04003927 } else if (attrs.type == TYPE_WALLPAPER) {
Dianne Hackborn067e5f62014-09-07 23:14:30 -07003928 // The wallpaper also has Real Ultimate Power, but we want to tell
3929 // it about the overscan area.
3930 pf.left = df.left = mOverscanScreenLeft;
3931 pf.top = df.top = mOverscanScreenTop;
3932 pf.right = df.right = mOverscanScreenLeft + mOverscanScreenWidth;
3933 pf.bottom = df.bottom = mOverscanScreenTop + mOverscanScreenHeight;
3934 of.left = cf.left = mUnrestrictedScreenLeft;
3935 of.top = cf.top = mUnrestrictedScreenTop;
3936 of.right = cf.right = mUnrestrictedScreenLeft + mUnrestrictedScreenWidth;
3937 of.bottom = cf.bottom = mUnrestrictedScreenTop + mUnrestrictedScreenHeight;
John Spurlock46646232013-09-30 22:32:42 -04003938 } else if ((fl & FLAG_LAYOUT_IN_OVERSCAN) != 0
Dianne Hackbornc652de82013-02-15 16:32:56 -08003939 && attrs.type >= WindowManager.LayoutParams.FIRST_APPLICATION_WINDOW
3940 && attrs.type <= WindowManager.LayoutParams.LAST_SUB_WINDOW) {
3941 // Asking to layout into the overscan region, so give it that pure
3942 // unrestricted area.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003943 pf.left = df.left = of.left = cf.left = mOverscanScreenLeft;
3944 pf.top = df.top = of.top = cf.top = mOverscanScreenTop;
3945 pf.right = df.right = of.right = cf.right
Dianne Hackbornc652de82013-02-15 16:32:56 -08003946 = mOverscanScreenLeft + mOverscanScreenWidth;
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003947 pf.bottom = df.bottom = of.bottom = cf.bottom
Dianne Hackbornc652de82013-02-15 16:32:56 -08003948 = mOverscanScreenTop + mOverscanScreenHeight;
Alan Viverette5a0f4ec2013-10-07 15:10:29 -07003949 } else if (canHideNavigationBar()
Dianne Hackbornf87d1962012-04-04 12:48:24 -07003950 && (sysUiFl & View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION) != 0
Craig Mautnerbeac1062014-06-03 14:38:57 -07003951 && (attrs.type == TYPE_STATUS_BAR
3952 || attrs.type == TYPE_TOAST
Jorim Jaggi2fdeeab2015-04-01 15:13:03 -07003953 || attrs.type == TYPE_VOICE_INTERACTION_STARTING
John Spurlock34e13d92013-08-10 06:52:28 -04003954 || (attrs.type >= WindowManager.LayoutParams.FIRST_APPLICATION_WINDOW
3955 && attrs.type <= WindowManager.LayoutParams.LAST_SUB_WINDOW))) {
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07003956 // Asking for layout as if the nav bar is hidden, lets the
3957 // application extend into the unrestricted screen area. We
John Spurlock34e13d92013-08-10 06:52:28 -04003958 // only do this for application windows (or toasts) to ensure no window that
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07003959 // can be above the nav bar can do this.
3960 // XXX This assumes that an app asking for this will also
3961 // ask for layout in only content. We can't currently figure out
3962 // what the screen would be if only laying out to hide the nav bar.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003963 pf.left = df.left = of.left = cf.left = mUnrestrictedScreenLeft;
3964 pf.top = df.top = of.top = cf.top = mUnrestrictedScreenTop;
3965 pf.right = df.right = of.right = cf.right = mUnrestrictedScreenLeft
3966 + mUnrestrictedScreenWidth;
3967 pf.bottom = df.bottom = of.bottom = cf.bottom = mUnrestrictedScreenTop
3968 + mUnrestrictedScreenHeight;
Joe Onorato29fc2c92010-11-24 10:26:50 -08003969 } else {
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003970 pf.left = df.left = of.left = cf.left = mRestrictedScreenLeft;
3971 pf.top = df.top = of.top = cf.top = mRestrictedScreenTop;
3972 pf.right = df.right = of.right = cf.right = mRestrictedScreenLeft
3973 + mRestrictedScreenWidth;
3974 pf.bottom = df.bottom = of.bottom = cf.bottom = mRestrictedScreenTop
3975 + mRestrictedScreenHeight;
Joe Onorato29fc2c92010-11-24 10:26:50 -08003976 }
Craig Mautner69b08182012-09-05 13:07:13 -07003977
Dianne Hackborn5b5cc4d2012-05-16 13:15:00 -07003978 applyStableConstraints(sysUiFl, fl, cf);
Craig Mautner69b08182012-09-05 13:07:13 -07003979
Dianne Hackborndea3ef72010-10-28 14:24:22 -07003980 if (adjust != SOFT_INPUT_ADJUST_NOTHING) {
3981 vf.left = mCurLeft;
3982 vf.top = mCurTop;
3983 vf.right = mCurRight;
3984 vf.bottom = mCurBottom;
3985 } else {
3986 vf.set(cf);
3987 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003988 } else if (attached != null) {
Craig Mautnereda67292013-04-28 13:50:14 -07003989 if (DEBUG_LAYOUT) Slog.v(TAG, "layoutWindowLw(" + attrs.getTitle() +
3990 "): attached to " + attached);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003991 // A child window should be placed inside of the same visible
3992 // frame that its parent had.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003993 setAttachedWindowFrames(win, fl, adjust, attached, false, pf, df, of, cf, vf);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003994 } else {
Craig Mautnereda67292013-04-28 13:50:14 -07003995 if (DEBUG_LAYOUT) Slog.v(TAG, "layoutWindowLw(" + attrs.getTitle() +
3996 "): normal window");
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003997 // Otherwise, a normal window must be placed inside the content
3998 // of all screen decorations.
Dianne Hackborna239c842011-06-01 12:28:20 -07003999 if (attrs.type == TYPE_STATUS_BAR_PANEL) {
4000 // Status bar panels are the only windows who can go on top of
4001 // the status bar. They are protected by the STATUS_BAR_SERVICE
4002 // permission, so they have the same privileges as the status
4003 // bar itself.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08004004 pf.left = df.left = of.left = cf.left = mRestrictedScreenLeft;
4005 pf.top = df.top = of.top = cf.top = mRestrictedScreenTop;
4006 pf.right = df.right = of.right = cf.right = mRestrictedScreenLeft
4007 + mRestrictedScreenWidth;
4008 pf.bottom = df.bottom = of.bottom = cf.bottom = mRestrictedScreenTop
4009 + mRestrictedScreenHeight;
John Spurlock414c1f02013-12-04 13:47:36 -05004010 } else if (attrs.type == TYPE_TOAST || attrs.type == TYPE_SYSTEM_ALERT
4011 || attrs.type == TYPE_VOLUME_OVERLAY) {
4012 // These dialogs are stable to interim decor changes.
John Spurlockbd957402013-10-03 11:38:39 -04004013 pf.left = df.left = of.left = cf.left = mStableLeft;
4014 pf.top = df.top = of.top = cf.top = mStableTop;
4015 pf.right = df.right = of.right = cf.right = mStableRight;
4016 pf.bottom = df.bottom = of.bottom = cf.bottom = mStableBottom;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004017 } else {
Dianne Hackborna239c842011-06-01 12:28:20 -07004018 pf.left = mContentLeft;
4019 pf.top = mContentTop;
4020 pf.right = mContentRight;
4021 pf.bottom = mContentBottom;
Dianne Hackborn20d94742014-05-29 18:35:45 -07004022 if (win.isVoiceInteraction()) {
4023 df.left = of.left = cf.left = mVoiceContentLeft;
4024 df.top = of.top = cf.top = mVoiceContentTop;
4025 df.right = of.right = cf.right = mVoiceContentRight;
4026 df.bottom = of.bottom = cf.bottom = mVoiceContentBottom;
4027 } else if (adjust != SOFT_INPUT_ADJUST_RESIZE) {
Dianne Hackbornc4aad012013-02-22 15:05:25 -08004028 df.left = of.left = cf.left = mDockLeft;
4029 df.top = of.top = cf.top = mDockTop;
4030 df.right = of.right = cf.right = mDockRight;
4031 df.bottom = of.bottom = cf.bottom = mDockBottom;
Dianne Hackborna239c842011-06-01 12:28:20 -07004032 } else {
Dianne Hackbornc4aad012013-02-22 15:05:25 -08004033 df.left = of.left = cf.left = mContentLeft;
4034 df.top = of.top = cf.top = mContentTop;
4035 df.right = of.right = cf.right = mContentRight;
4036 df.bottom = of.bottom = cf.bottom = mContentBottom;
Dianne Hackborna239c842011-06-01 12:28:20 -07004037 }
4038 if (adjust != SOFT_INPUT_ADJUST_NOTHING) {
4039 vf.left = mCurLeft;
4040 vf.top = mCurTop;
4041 vf.right = mCurRight;
4042 vf.bottom = mCurBottom;
4043 } else {
4044 vf.set(cf);
4045 }
Dianne Hackborndea3ef72010-10-28 14:24:22 -07004046 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004047 }
4048 }
Craig Mautner69b08182012-09-05 13:07:13 -07004049
Craig Mautnerb816bed2013-07-23 10:26:17 -07004050 // TYPE_SYSTEM_ERROR is above the NavigationBar so it can't be allowed to extend over it.
4051 if ((fl & FLAG_LAYOUT_NO_LIMITS) != 0 && attrs.type != TYPE_SYSTEM_ERROR) {
Dianne Hackborn067e5f62014-09-07 23:14:30 -07004052 df.left = df.top = -10000;
4053 df.right = df.bottom = 10000;
4054 if (attrs.type != TYPE_WALLPAPER) {
4055 of.left = of.top = cf.left = cf.top = vf.left = vf.top = -10000;
4056 of.right = of.bottom = cf.right = cf.bottom = vf.right = vf.bottom = 10000;
4057 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004058 }
4059
Craig Mautnereda67292013-04-28 13:50:14 -07004060 if (DEBUG_LAYOUT) Slog.v(TAG, "Compute frame " + attrs.getTitle()
The Android Open Source Project11267662009-03-18 17:39:47 -07004061 + ": sim=#" + Integer.toHexString(sim)
RoboErik8a2cfc32014-05-16 11:19:38 -07004062 + " attach=" + attached + " type=" + attrs.type
Daniel Sandler8956dbb2011-04-22 07:55:02 -04004063 + String.format(" flags=0x%08x", fl)
The Android Open Source Project11267662009-03-18 17:39:47 -07004064 + " pf=" + pf.toShortString() + " df=" + df.toShortString()
Dianne Hackbornc4aad012013-02-22 15:05:25 -08004065 + " of=" + of.toShortString()
John Spurlock46646232013-09-30 22:32:42 -04004066 + " cf=" + cf.toShortString() + " vf=" + vf.toShortString()
Adrian Roosfa104232014-06-20 16:10:14 -07004067 + " dcf=" + dcf.toShortString()
4068 + " sf=" + sf.toShortString());
Craig Mautner69b08182012-09-05 13:07:13 -07004069
Adrian Roosfa104232014-06-20 16:10:14 -07004070 win.computeFrameLw(pf, df, of, cf, vf, dcf, sf);
Craig Mautner69b08182012-09-05 13:07:13 -07004071
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004072 // Dock windows carve out the bottom of the screen, so normal windows
4073 // can't appear underneath them.
Craig Mautner8bd206b2012-10-03 10:32:02 -07004074 if (attrs.type == TYPE_INPUT_METHOD && win.isVisibleOrBehindKeyguardLw()
4075 && !win.getGivenInsetsPendingLw()) {
satok1bc0a492012-04-25 22:47:12 +09004076 setLastInputMethodWindowLw(null, null);
4077 offsetInputMethodWindowLw(win);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004078 }
Dianne Hackborne30e02f2014-05-27 18:24:45 -07004079 if (attrs.type == TYPE_VOICE_INTERACTION && win.isVisibleOrBehindKeyguardLw()
4080 && !win.getGivenInsetsPendingLw()) {
4081 offsetVoiceInputWindowLw(win);
4082 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004083 }
4084
satok1bc0a492012-04-25 22:47:12 +09004085 private void offsetInputMethodWindowLw(WindowState win) {
Craig Mautner4774f6a2015-03-23 11:42:55 -07004086 int top = Math.max(win.getDisplayFrameLw().top, win.getContentFrameLw().top);
satok1bc0a492012-04-25 22:47:12 +09004087 top += win.getGivenContentInsetsLw().top;
4088 if (mContentBottom > top) {
4089 mContentBottom = top;
4090 }
Dianne Hackborne30e02f2014-05-27 18:24:45 -07004091 if (mVoiceContentBottom > top) {
4092 mVoiceContentBottom = top;
4093 }
satok1bc0a492012-04-25 22:47:12 +09004094 top = win.getVisibleFrameLw().top;
4095 top += win.getGivenVisibleInsetsLw().top;
4096 if (mCurBottom > top) {
4097 mCurBottom = top;
4098 }
Craig Mautnereda67292013-04-28 13:50:14 -07004099 if (DEBUG_LAYOUT) Slog.v(TAG, "Input method: mDockBottom="
satok1bc0a492012-04-25 22:47:12 +09004100 + mDockBottom + " mContentBottom="
4101 + mContentBottom + " mCurBottom=" + mCurBottom);
4102 }
4103
Dianne Hackborne30e02f2014-05-27 18:24:45 -07004104 private void offsetVoiceInputWindowLw(WindowState win) {
Craig Mautner4774f6a2015-03-23 11:42:55 -07004105 int top = Math.max(win.getDisplayFrameLw().top, win.getContentFrameLw().top);
Dianne Hackbornae6688b2015-02-11 17:02:41 -08004106 top += win.getGivenContentInsetsLw().top;
4107 if (mVoiceContentBottom > top) {
4108 mVoiceContentBottom = top;
Dianne Hackborne30e02f2014-05-27 18:24:45 -07004109 }
4110 }
4111
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004112 /** {@inheritDoc} */
Craig Mautner61ac6bb2012-02-02 17:29:33 -08004113 @Override
4114 public void finishLayoutLw() {
4115 return;
Dianne Hackborn5f3063e2010-03-10 16:01:58 -08004116 }
4117
4118 /** {@inheritDoc} */
Craig Mautnerad09bcc2012-10-08 13:33:11 -07004119 @Override
Craig Mautner39834192012-09-02 07:47:24 -07004120 public void beginPostLayoutPolicyLw(int displayWidth, int displayHeight) {
Dianne Hackborn5f3063e2010-03-10 16:01:58 -08004121 mTopFullscreenOpaqueWindowState = null;
Adrian Rooscd3884d2015-02-18 17:25:23 +01004122 mTopFullscreenOpaqueOrDimmingWindowState = null;
Craig Mautner2bc789b2014-03-19 19:48:38 -07004123 mAppsToBeHidden.clear();
Jorim Jaggic13fcac2014-09-11 17:36:57 +02004124 mAppsThatDismissKeyguard.clear();
Dianne Hackborn5f3063e2010-03-10 16:01:58 -08004125 mForceStatusBar = false;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07004126 mForceStatusBarFromKeyguard = false;
Selim Cinek4a4a2bddc2015-05-07 12:50:19 -07004127 mForceStatusBarTransparent = false;
Dianne Hackborn891d3fb2013-01-09 18:31:37 -08004128 mForcingShowNavBar = false;
4129 mForcingShowNavBarLayer = -1;
RoboErik8a2cfc32014-05-16 11:19:38 -07004130
Dianne Hackborn5f3063e2010-03-10 16:01:58 -08004131 mHideLockScreen = false;
4132 mAllowLockscreenWhenOn = false;
Craig Mautnerad09bcc2012-10-08 13:33:11 -07004133 mDismissKeyguard = DISMISS_KEYGUARD_NONE;
Dianne Hackborn7ad44382012-10-18 17:46:00 -07004134 mShowingLockscreen = false;
4135 mShowingDream = false;
Craig Mautnerc9457fa2014-06-06 14:27:48 -07004136 mWinShowWhenLocked = null;
Jim Millerab954542014-10-10 18:21:49 -07004137 mKeyguardSecure = isKeyguardSecure();
4138 mKeyguardSecureIncludingHidden = mKeyguardSecure
4139 && (mKeyguardDelegate != null && mKeyguardDelegate.isShowing());
Dianne Hackborn5f3063e2010-03-10 16:01:58 -08004140 }
4141
4142 /** {@inheritDoc} */
Craig Mautnerad09bcc2012-10-08 13:33:11 -07004143 @Override
Craig Mautnerc9457fa2014-06-06 14:27:48 -07004144 public void applyPostLayoutPolicyLw(WindowState win, WindowManager.LayoutParams attrs) {
Dianne Hackbornbc1aa7b2011-09-20 11:20:31 -07004145 if (DEBUG_LAYOUT) Slog.i(TAG, "Win " + win + ": isVisibleOrBehindKeyguardLw="
4146 + win.isVisibleOrBehindKeyguardLw());
John Spurlockc6d1c602014-01-17 15:22:06 -05004147 final int fl = PolicyControl.getWindowFlags(win, attrs);
John Spurlock414c1f02013-12-04 13:47:36 -05004148 if (mTopFullscreenOpaqueWindowState == null
4149 && win.isVisibleLw() && attrs.type == TYPE_INPUT_METHOD) {
4150 mForcingShowNavBar = true;
4151 mForcingShowNavBarLayer = win.getSurfaceLayer();
Dianne Hackborn891d3fb2013-01-09 18:31:37 -08004152 }
Selim Cinek4a4a2bddc2015-05-07 12:50:19 -07004153 if (attrs.type == TYPE_STATUS_BAR) {
4154 if ((attrs.privateFlags & PRIVATE_FLAG_KEYGUARD) != 0) {
4155 mForceStatusBarFromKeyguard = true;
4156 }
4157 if ((attrs.privateFlags & PRIVATE_FLAG_FORCE_STATUS_BAR_VISIBLE_TRANSPARENT) != 0) {
4158 mForceStatusBarTransparent = true;
4159 }
Jorim Jaggiafd4a552014-04-08 15:13:05 +02004160 }
Adrian Roos602c68e2015-04-24 16:03:47 -07004161
4162 boolean appWindow = attrs.type >= FIRST_APPLICATION_WINDOW
4163 && attrs.type < FIRST_SYSTEM_WINDOW;
4164 final boolean showWhenLocked = (fl & FLAG_SHOW_WHEN_LOCKED) != 0;
4165 final boolean dismissKeyguard = (fl & FLAG_DISMISS_KEYGUARD) != 0;
4166
Dianne Hackborn5f3063e2010-03-10 16:01:58 -08004167 if (mTopFullscreenOpaqueWindowState == null &&
Dianne Hackborn01b02a72012-01-12 14:05:03 -08004168 win.isVisibleOrBehindKeyguardLw() && !win.isGoneForLayoutLw()) {
John Spurlockc6d1c602014-01-17 15:22:06 -05004169 if ((fl & FLAG_FORCE_NOT_FULLSCREEN) != 0) {
Jorim Jaggi380ecb82014-03-14 17:25:20 +01004170 if ((attrs.privateFlags & PRIVATE_FLAG_KEYGUARD) != 0) {
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07004171 mForceStatusBarFromKeyguard = true;
4172 } else {
4173 mForceStatusBar = true;
4174 }
4175 }
Jorim Jaggi380ecb82014-03-14 17:25:20 +01004176 if ((attrs.privateFlags & PRIVATE_FLAG_KEYGUARD) != 0) {
Dianne Hackborn7ad44382012-10-18 17:46:00 -07004177 mShowingLockscreen = true;
Dianne Hackbornbc1aa7b2011-09-20 11:20:31 -07004178 }
Dianne Hackborn7ad44382012-10-18 17:46:00 -07004179 if (attrs.type == TYPE_DREAM) {
Jeff Brownc8018eb2012-10-29 21:33:27 -07004180 // If the lockscreen was showing when the dream started then wait
4181 // for the dream to draw before hiding the lockscreen.
4182 if (!mDreamingLockscreen
4183 || (win.isVisibleLw() && win.hasDrawnLw())) {
4184 mShowingDream = true;
Craig Mautnerab55e522014-03-03 13:26:03 -08004185 appWindow = true;
Dianne Hackborn7ad44382012-10-18 17:46:00 -07004186 }
4187 }
Craig Mautnerab55e522014-03-03 13:26:03 -08004188
Craig Mautnerab55e522014-03-03 13:26:03 -08004189 if (appWindow) {
Jorim Jaggic13fcac2014-09-11 17:36:57 +02004190 final IApplicationToken appToken = win.getAppToken();
4191 if (showWhenLocked) {
Craig Mautnerc9457fa2014-06-06 14:27:48 -07004192 // Remove any previous windows with the same appToken.
Jorim Jaggic13fcac2014-09-11 17:36:57 +02004193 mAppsToBeHidden.remove(appToken);
4194 mAppsThatDismissKeyguard.remove(appToken);
Craig Mautnerca0a1242014-12-02 12:25:14 -08004195 if (mAppsToBeHidden.isEmpty()) {
Craig Mautner192d6042014-12-02 23:24:48 -08004196 if (dismissKeyguard && !mKeyguardSecure) {
4197 mAppsThatDismissKeyguard.add(appToken);
4198 } else {
Craig Mautnerca0a1242014-12-02 12:25:14 -08004199 mWinShowWhenLocked = win;
4200 mHideLockScreen = true;
4201 mForceStatusBarFromKeyguard = false;
Craig Mautnerca0a1242014-12-02 12:25:14 -08004202 }
Craig Mautnerc9457fa2014-06-06 14:27:48 -07004203 }
Jorim Jaggic13fcac2014-09-11 17:36:57 +02004204 } else if (dismissKeyguard) {
Jim Millerab954542014-10-10 18:21:49 -07004205 if (mKeyguardSecure) {
Jorim Jaggic13fcac2014-09-11 17:36:57 +02004206 mAppsToBeHidden.add(appToken);
4207 } else {
4208 mAppsToBeHidden.remove(appToken);
4209 }
4210 mAppsThatDismissKeyguard.add(appToken);
Craig Mautner2bc789b2014-03-19 19:48:38 -07004211 } else {
Jorim Jaggic13fcac2014-09-11 17:36:57 +02004212 mAppsToBeHidden.add(appToken);
Craig Mautner2bc789b2014-03-19 19:48:38 -07004213 }
Craig Mautnerab55e522014-03-03 13:26:03 -08004214 if (attrs.x == 0 && attrs.y == 0
4215 && attrs.width == WindowManager.LayoutParams.MATCH_PARENT
4216 && attrs.height == WindowManager.LayoutParams.MATCH_PARENT) {
4217 if (DEBUG_LAYOUT) Slog.v(TAG, "Fullscreen window: " + win);
4218 mTopFullscreenOpaqueWindowState = win;
Adrian Rooscd3884d2015-02-18 17:25:23 +01004219 if (mTopFullscreenOpaqueOrDimmingWindowState == null) {
4220 mTopFullscreenOpaqueOrDimmingWindowState = win;
4221 }
Jorim Jaggic13fcac2014-09-11 17:36:57 +02004222 if (!mAppsThatDismissKeyguard.isEmpty() &&
4223 mDismissKeyguard == DISMISS_KEYGUARD_NONE) {
4224 if (DEBUG_LAYOUT) Slog.v(TAG,
4225 "Setting mDismissKeyguard true by win " + win);
4226 mDismissKeyguard = mWinDismissingKeyguard == win ?
4227 DISMISS_KEYGUARD_CONTINUE : DISMISS_KEYGUARD_START;
4228 mWinDismissingKeyguard = win;
Jim Millerab954542014-10-10 18:21:49 -07004229 mForceStatusBarFromKeyguard = mShowingLockscreen && mKeyguardSecure;
Jorim Jaggic13fcac2014-09-11 17:36:57 +02004230 } else if (mAppsToBeHidden.isEmpty() && showWhenLocked) {
4231 if (DEBUG_LAYOUT) Slog.v(TAG,
4232 "Setting mHideLockScreen to true by win " + win);
4233 mHideLockScreen = true;
4234 mForceStatusBarFromKeyguard = false;
Craig Mautnerab55e522014-03-03 13:26:03 -08004235 }
Craig Mautner00156ec2014-03-06 22:29:02 -08004236 if ((fl & FLAG_ALLOW_LOCK_WHILE_SCREEN_ON) != 0) {
Craig Mautnerab55e522014-03-03 13:26:03 -08004237 mAllowLockscreenWhenOn = true;
4238 }
Dianne Hackborn5f3063e2010-03-10 16:01:58 -08004239 }
Craig Mautnerc9457fa2014-06-06 14:27:48 -07004240
4241 if (mWinShowWhenLocked != null &&
Adrian Roos602c68e2015-04-24 16:03:47 -07004242 mWinShowWhenLocked.getAppToken() != win.getAppToken() &&
4243 (attrs.flags & FLAG_SHOW_WHEN_LOCKED) == 0) {
Craig Mautnerc9457fa2014-06-06 14:27:48 -07004244 win.hideLw(false);
4245 }
Dianne Hackborn5f3063e2010-03-10 16:01:58 -08004246 }
Adrian Roos602c68e2015-04-24 16:03:47 -07004247 } else if (mTopFullscreenOpaqueWindowState == null && mWinShowWhenLocked == null) {
4248 // No TopFullscreenOpaqueWindow is showing, but we found a SHOW_WHEN_LOCKED window
4249 // that is being hidden in an animation - keep the
4250 // keyguard hidden until the new window shows up and
4251 // we know whether to show the keyguard or not.
4252 if (win.isAnimatingLw() && appWindow && showWhenLocked) {
4253 mHideLockScreen = true;
4254 mWinShowWhenLocked = win;
4255 }
Dianne Hackborn5f3063e2010-03-10 16:01:58 -08004256 }
Adrian Rooscd3884d2015-02-18 17:25:23 +01004257 if (mTopFullscreenOpaqueOrDimmingWindowState == null
4258 && win.isVisibleOrBehindKeyguardLw() && !win.isGoneForLayoutLw()
4259 && win.isDimming()) {
4260 mTopFullscreenOpaqueOrDimmingWindowState = win;
4261 }
Dianne Hackborn5f3063e2010-03-10 16:01:58 -08004262 }
4263
4264 /** {@inheritDoc} */
Craig Mautnerad09bcc2012-10-08 13:33:11 -07004265 @Override
Craig Mautner39834192012-09-02 07:47:24 -07004266 public int finishPostLayoutPolicyLw() {
Craig Mautnerc5e73bf2015-04-21 15:41:26 +00004267 if (mWinShowWhenLocked != null && mTopFullscreenOpaqueWindowState != null &&
4268 mWinShowWhenLocked.getAppToken() != mTopFullscreenOpaqueWindowState.getAppToken()
4269 && isKeyguardLocked()) {
Craig Mautnerc9457fa2014-06-06 14:27:48 -07004270 // A dialog is dismissing the keyguard. Put the wallpaper behind it and hide the
4271 // fullscreen window.
4272 // TODO: Make sure FLAG_SHOW_WALLPAPER is restored when dialog is dismissed. Or not.
4273 mWinShowWhenLocked.getAttrs().flags |= FLAG_SHOW_WALLPAPER;
4274 mTopFullscreenOpaqueWindowState.hideLw(false);
4275 mTopFullscreenOpaqueWindowState = mWinShowWhenLocked;
4276 }
4277
Dianne Hackborn39c2d712009-09-22 11:41:31 -07004278 int changes = 0;
Joe Onorato93056472010-09-10 10:30:46 -04004279 boolean topIsFullscreen = false;
Daniel Sandlere02d8082010-10-08 15:13:22 -04004280
4281 final WindowManager.LayoutParams lp = (mTopFullscreenOpaqueWindowState != null)
4282 ? mTopFullscreenOpaqueWindowState.getAttrs()
4283 : null;
4284
Jeff Brownc8018eb2012-10-29 21:33:27 -07004285 // If we are not currently showing a dream then remember the current
4286 // lockscreen state. We will use this to determine whether the dream
4287 // started while the lockscreen was showing and remember this state
4288 // while the dream is showing.
Dianne Hackborn7ad44382012-10-18 17:46:00 -07004289 if (!mShowingDream) {
4290 mDreamingLockscreen = mShowingLockscreen;
Jeff Brown061ea992015-04-17 19:55:47 -07004291 if (mDreamingSleepTokenNeeded) {
4292 mDreamingSleepTokenNeeded = false;
4293 mHandler.obtainMessage(MSG_UPDATE_DREAMING_SLEEP_TOKEN, 0, 1).sendToTarget();
4294 }
4295 } else {
4296 if (!mDreamingSleepTokenNeeded) {
4297 mDreamingSleepTokenNeeded = true;
4298 mHandler.obtainMessage(MSG_UPDATE_DREAMING_SLEEP_TOKEN, 1, 1).sendToTarget();
4299 }
Dianne Hackborn7ad44382012-10-18 17:46:00 -07004300 }
4301
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004302 if (mStatusBar != null) {
Craig Mautnereda67292013-04-28 13:50:14 -07004303 if (DEBUG_LAYOUT) Slog.i(TAG, "force=" + mForceStatusBar
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07004304 + " forcefkg=" + mForceStatusBarFromKeyguard
Dianne Hackbornd70bc2f2009-10-06 23:25:51 -07004305 + " top=" + mTopFullscreenOpaqueWindowState);
Selim Cinek4a4a2bddc2015-05-07 12:50:19 -07004306 boolean shouldBeTransparent = mForceStatusBarTransparent
4307 && !mForceStatusBar
4308 && !mForceStatusBarFromKeyguard;
4309 if (!shouldBeTransparent) {
4310 mStatusBarController.setShowTransparent(false /* transparent */);
4311 } else if (!mStatusBar.isVisibleLw()) {
4312 mStatusBarController.setShowTransparent(true /* transparent */);
4313 }
4314 if (mForceStatusBar || mForceStatusBarFromKeyguard || mForceStatusBarTransparent) {
Craig Mautnereda67292013-04-28 13:50:14 -07004315 if (DEBUG_LAYOUT) Slog.v(TAG, "Showing status bar: forced");
John Spurlock27735a42013-08-14 17:57:38 -04004316 if (mStatusBarController.setBarShowingLw(true)) {
4317 changes |= FINISH_LAYOUT_REDO_LAYOUT;
4318 }
Craig Mautner81defc72013-10-29 11:10:42 -07004319 // Maintain fullscreen layout until incoming animation is complete.
4320 topIsFullscreen = mTopIsFullscreen && mStatusBar.isAnimatingLw();
John Spurlockf92b6162013-11-11 15:01:16 -05004321 // Transient status bar on the lockscreen is not allowed
4322 if (mForceStatusBarFromKeyguard && mStatusBarController.isTransientShowing()) {
4323 mStatusBarController.updateVisibilityLw(false /*transientAllowed*/,
4324 mLastSystemUiFlags, mLastSystemUiFlags);
4325 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004326 } else if (mTopFullscreenOpaqueWindowState != null) {
John Spurlockc6d1c602014-01-17 15:22:06 -05004327 final int fl = PolicyControl.getWindowFlags(null, lp);
Joe Onorato93056472010-09-10 10:30:46 -04004328 if (localLOGV) {
Craig Mautnereda67292013-04-28 13:50:14 -07004329 Slog.d(TAG, "frame: " + mTopFullscreenOpaqueWindowState.getFrameLw()
Joe Onorato93056472010-09-10 10:30:46 -04004330 + " shown frame: " + mTopFullscreenOpaqueWindowState.getShownFrameLw());
Craig Mautnereda67292013-04-28 13:50:14 -07004331 Slog.d(TAG, "attr: " + mTopFullscreenOpaqueWindowState.getAttrs()
John Spurlockc6d1c602014-01-17 15:22:06 -05004332 + " lp.flags=0x" + Integer.toHexString(fl));
Joe Onorato93056472010-09-10 10:30:46 -04004333 }
John Spurlockc6d1c602014-01-17 15:22:06 -05004334 topIsFullscreen = (fl & WindowManager.LayoutParams.FLAG_FULLSCREEN) != 0
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07004335 || (mLastSystemUiFlags & View.SYSTEM_UI_FLAG_FULLSCREEN) != 0;
Joe Onorato93056472010-09-10 10:30:46 -04004336 // The subtle difference between the window for mTopFullscreenOpaqueWindowState
Mark Dolinerd0646dc2014-08-27 16:04:02 -07004337 // and mTopIsFullscreen is that mTopIsFullscreen is set only if the window
Joe Onorato93056472010-09-10 10:30:46 -04004338 // has the FLAG_FULLSCREEN set. Not sure if there is another way that to be the
4339 // case though.
John Spurlock27735a42013-08-14 17:57:38 -04004340 if (mStatusBarController.isTransientShowing()) {
4341 if (mStatusBarController.setBarShowingLw(true)) {
John Spurlock32beb2c2013-03-11 10:16:47 -04004342 changes |= FINISH_LAYOUT_REDO_LAYOUT;
4343 }
4344 } else if (topIsFullscreen) {
Craig Mautnereda67292013-04-28 13:50:14 -07004345 if (DEBUG_LAYOUT) Slog.v(TAG, "** HIDING status bar");
John Spurlock27735a42013-08-14 17:57:38 -04004346 if (mStatusBarController.setBarShowingLw(false)) {
Dianne Hackbornf87d1962012-04-04 12:48:24 -07004347 changes |= FINISH_LAYOUT_REDO_LAYOUT;
Craig Mautnereda67292013-04-28 13:50:14 -07004348 } else {
Craig Mautnerc5a6e442013-06-05 17:22:35 -07004349 if (DEBUG_LAYOUT) Slog.v(TAG, "Status bar already hiding");
Daniel Sandler40427442010-07-16 11:44:52 -04004350 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004351 } else {
Craig Mautnereda67292013-04-28 13:50:14 -07004352 if (DEBUG_LAYOUT) Slog.v(TAG, "** SHOWING status bar: top is not fullscreen");
John Spurlock27735a42013-08-14 17:57:38 -04004353 if (mStatusBarController.setBarShowingLw(true)) {
4354 changes |= FINISH_LAYOUT_REDO_LAYOUT;
4355 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004356 }
4357 }
4358 }
Daniel Sandlere02d8082010-10-08 15:13:22 -04004359
Craig Mautner81defc72013-10-29 11:10:42 -07004360 if (mTopIsFullscreen != topIsFullscreen) {
4361 if (!topIsFullscreen) {
4362 // Force another layout when status bar becomes fully shown.
4363 changes |= FINISH_LAYOUT_REDO_LAYOUT;
4364 }
4365 mTopIsFullscreen = topIsFullscreen;
4366 }
Daniel Sandlere02d8082010-10-08 15:13:22 -04004367
Craig Mautner39834192012-09-02 07:47:24 -07004368 // Hide the key guard if a visible window explicitly specifies that it wants to be
4369 // displayed when the screen is locked.
Jorim Jaggi5cf17872014-03-26 18:31:48 +01004370 if (mKeyguardDelegate != null && mStatusBar != null) {
4371 if (localLOGV) Slog.v(TAG, "finishPostLayoutPolicyLw: mHideKeyguard="
4372 + mHideLockScreen);
Jim Millerab954542014-10-10 18:21:49 -07004373 if (mDismissKeyguard != DISMISS_KEYGUARD_NONE && !mKeyguardSecure) {
Jorim Jaggi5cf17872014-03-26 18:31:48 +01004374 mKeyguardHidden = true;
Jim Millerab954542014-10-10 18:21:49 -07004375 if (setKeyguardOccludedLw(true)) {
Dianne Hackborn39c2d712009-09-22 11:41:31 -07004376 changes |= FINISH_LAYOUT_REDO_LAYOUT
4377 | FINISH_LAYOUT_REDO_CONFIG
4378 | FINISH_LAYOUT_REDO_WALLPAPER;
4379 }
Jorim Jaggi5cf17872014-03-26 18:31:48 +01004380 if (mKeyguardDelegate.isShowing()) {
4381 mHandler.post(new Runnable() {
4382 @Override
4383 public void run() {
4384 mKeyguardDelegate.keyguardDone(false, false);
4385 }
4386 });
4387 }
4388 } else if (mHideLockScreen) {
4389 mKeyguardHidden = true;
Jim Millerab954542014-10-10 18:21:49 -07004390 if (setKeyguardOccludedLw(true)) {
Jorim Jaggi5cf17872014-03-26 18:31:48 +01004391 changes |= FINISH_LAYOUT_REDO_LAYOUT
4392 | FINISH_LAYOUT_REDO_CONFIG
4393 | FINISH_LAYOUT_REDO_WALLPAPER;
4394 }
4395 } else if (mDismissKeyguard != DISMISS_KEYGUARD_NONE) {
4396 // This is the case of keyguard isSecure() and not mHideLockScreen.
4397 if (mDismissKeyguard == DISMISS_KEYGUARD_START) {
4398 // Only launch the next keyguard unlock window once per window.
4399 mKeyguardHidden = false;
Jim Millerab954542014-10-10 18:21:49 -07004400 if (setKeyguardOccludedLw(false)) {
Jorim Jaggi5cf17872014-03-26 18:31:48 +01004401 changes |= FINISH_LAYOUT_REDO_LAYOUT
4402 | FINISH_LAYOUT_REDO_CONFIG
4403 | FINISH_LAYOUT_REDO_WALLPAPER;
Jorim Jaggi380ecb82014-03-14 17:25:20 +01004404 }
Jorim Jaggi5cf17872014-03-26 18:31:48 +01004405 mHandler.post(new Runnable() {
4406 @Override
4407 public void run() {
4408 mKeyguardDelegate.dismiss();
4409 }
4410 });
4411 }
4412 } else {
4413 mWinDismissingKeyguard = null;
4414 mKeyguardHidden = false;
Jim Millerab954542014-10-10 18:21:49 -07004415 if (setKeyguardOccludedLw(false)) {
Jorim Jaggi5cf17872014-03-26 18:31:48 +01004416 changes |= FINISH_LAYOUT_REDO_LAYOUT
4417 | FINISH_LAYOUT_REDO_CONFIG
4418 | FINISH_LAYOUT_REDO_WALLPAPER;
4419 }
Suchi Amalapurapu9cdc9032009-05-14 18:01:07 -07004420 }
4421 }
Joe Onorato664644d2011-01-23 17:53:23 -08004422
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07004423 if ((updateSystemUiVisibilityLw()&SYSTEM_UI_CHANGING_LAYOUT) != 0) {
Dianne Hackborndf89e652011-10-06 22:35:11 -07004424 // If the navigation bar has been hidden or shown, we need to do another
4425 // layout pass to update that window.
4426 changes |= FINISH_LAYOUT_REDO_LAYOUT;
4427 }
Joe Onorato664644d2011-01-23 17:53:23 -08004428
Mike Lockwood28569302010-01-28 11:54:40 -05004429 // update since mAllowLockscreenWhenOn might have changed
4430 updateLockScreenTimeout();
Dianne Hackborn39c2d712009-09-22 11:41:31 -07004431 return changes;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004432 }
4433
Jorim Jaggi380ecb82014-03-14 17:25:20 +01004434 /**
Jim Millerab954542014-10-10 18:21:49 -07004435 * Updates the occluded state of the Keyguard.
Jorim Jaggi380ecb82014-03-14 17:25:20 +01004436 *
Jorim Jaggi380ecb82014-03-14 17:25:20 +01004437 * @return Whether the flags have changed and we have to redo the layout.
4438 */
Jim Millerab954542014-10-10 18:21:49 -07004439 private boolean setKeyguardOccludedLw(boolean isOccluded) {
4440 boolean wasOccluded = mKeyguardOccluded;
4441 boolean showing = mKeyguardDelegate.isShowing();
4442 if (wasOccluded && !isOccluded && showing) {
4443 mKeyguardOccluded = false;
4444 mKeyguardDelegate.setOccluded(false);
Jorim Jaggi380ecb82014-03-14 17:25:20 +01004445 mStatusBar.getAttrs().privateFlags |= PRIVATE_FLAG_KEYGUARD;
4446 mStatusBar.getAttrs().flags |= FLAG_SHOW_WALLPAPER;
4447 return true;
Jim Millerab954542014-10-10 18:21:49 -07004448 } else if (!wasOccluded && isOccluded && showing) {
4449 mKeyguardOccluded = true;
4450 mKeyguardDelegate.setOccluded(true);
Jorim Jaggi380ecb82014-03-14 17:25:20 +01004451 mStatusBar.getAttrs().privateFlags &= ~PRIVATE_FLAG_KEYGUARD;
4452 mStatusBar.getAttrs().flags &= ~FLAG_SHOW_WALLPAPER;
4453 return true;
4454 } else {
4455 return false;
4456 }
4457 }
4458
4459 private boolean isStatusBarKeyguard() {
4460 return mStatusBar != null
4461 && (mStatusBar.getAttrs().privateFlags & PRIVATE_FLAG_KEYGUARD) != 0;
4462 }
4463
Jose Lima9546b202014-07-02 17:21:51 -07004464 @Override
Dianne Hackborn08743722009-12-21 12:16:51 -08004465 public boolean allowAppAnimationsLw() {
Jorim Jaggi380ecb82014-03-14 17:25:20 +01004466 if (isStatusBarKeyguard() || mShowingDream) {
Craig Mautner28816302013-10-10 20:31:00 -07004467 // If keyguard or dreams is currently visible, no reason to animate behind it.
Dianne Hackborn08743722009-12-21 12:16:51 -08004468 return false;
4469 }
Dianne Hackborn08743722009-12-21 12:16:51 -08004470 return true;
4471 }
4472
Jose Lima9546b202014-07-02 17:21:51 -07004473 @Override
Dianne Hackborndf89e652011-10-06 22:35:11 -07004474 public int focusChangedLw(WindowState lastFocus, WindowState newFocus) {
Joe Onorato664644d2011-01-23 17:53:23 -08004475 mFocusedWindow = newFocus;
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07004476 if ((updateSystemUiVisibilityLw()&SYSTEM_UI_CHANGING_LAYOUT) != 0) {
Dianne Hackborndf89e652011-10-06 22:35:11 -07004477 // If the navigation bar has been hidden or shown, we need to do another
4478 // layout pass to update that window.
4479 return FINISH_LAYOUT_REDO_LAYOUT;
4480 }
4481 return 0;
Joe Onorato664644d2011-01-23 17:53:23 -08004482 }
4483
Dianne Hackborn0ecadf72009-03-31 18:00:37 -07004484 /** {@inheritDoc} */
Jose Lima9546b202014-07-02 17:21:51 -07004485 @Override
Jeff Brown46b9ac02010-04-22 18:58:52 -07004486 public void notifyLidSwitchChanged(long whenNanos, boolean lidOpen) {
4487 // lid changed state
Jeff Brownc458ce92012-04-30 14:58:40 -07004488 final int newLidState = lidOpen ? LID_OPEN : LID_CLOSED;
4489 if (newLidState == mLidState) {
4490 return;
4491 }
Jeff Brown01a98dd2011-09-20 15:08:29 -07004492
Jeff Brownc458ce92012-04-30 14:58:40 -07004493 mLidState = newLidState;
4494 applyLidSwitchState();
Jeff Brown01a98dd2011-09-20 15:08:29 -07004495 updateRotation(true);
Jeff Brownc458ce92012-04-30 14:58:40 -07004496
4497 if (lidOpen) {
Bryce Lee584a4452014-10-21 15:55:55 -07004498 wakeUp(SystemClock.uptimeMillis(), mAllowTheaterModeWakeFromLidSwitch);
Jeff Brownc458ce92012-04-30 14:58:40 -07004499 } else if (!mLidControlsSleep) {
Jeff Brown96307042012-07-27 15:51:34 -07004500 mPowerManager.userActivity(SystemClock.uptimeMillis(), false);
Jeff Brown46b9ac02010-04-22 18:58:52 -07004501 }
4502 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004503
Michael Wright3818c922014-09-02 13:59:07 -07004504 @Override
4505 public void notifyCameraLensCoverSwitchChanged(long whenNanos, boolean lensCovered) {
4506 int lensCoverState = lensCovered ? CAMERA_LENS_COVERED : CAMERA_LENS_UNCOVERED;
4507 if (mCameraLensCoverState == lensCoverState) {
4508 return;
4509 }
4510 if (mCameraLensCoverState == CAMERA_LENS_COVERED &&
4511 lensCoverState == CAMERA_LENS_UNCOVERED) {
4512 Intent intent;
4513 final boolean keyguardActive = mKeyguardDelegate == null ? false :
4514 mKeyguardDelegate.isShowing();
4515 if (keyguardActive) {
4516 intent = new Intent(MediaStore.INTENT_ACTION_STILL_IMAGE_CAMERA_SECURE);
4517 } else {
4518 intent = new Intent(MediaStore.INTENT_ACTION_STILL_IMAGE_CAMERA);
4519 }
Bryce Lee584a4452014-10-21 15:55:55 -07004520 wakeUp(whenNanos / 1000000, mAllowTheaterModeWakeFromCameraLens);
Bart Sears8b1c27c2015-03-18 23:51:02 +00004521 startActivityAsUser(intent, UserHandle.CURRENT_OR_SELF);
Michael Wright3818c922014-09-02 13:59:07 -07004522 }
4523 mCameraLensCoverState = lensCoverState;
4524 }
4525
Dianne Hackbornad7fa7f2011-01-07 14:06:50 -08004526 void setHdmiPlugged(boolean plugged) {
4527 if (mHdmiPlugged != plugged) {
4528 mHdmiPlugged = plugged;
Dianne Hackbornf87d1962012-04-04 12:48:24 -07004529 updateRotation(true, true);
Dianne Hackbornad7fa7f2011-01-07 14:06:50 -08004530 Intent intent = new Intent(ACTION_HDMI_PLUGGED);
Joe Onoratodc100302011-01-11 17:07:41 -08004531 intent.addFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY_BEFORE_BOOT);
Dianne Hackbornad7fa7f2011-01-07 14:06:50 -08004532 intent.putExtra(EXTRA_HDMI_PLUGGED_STATE, plugged);
Dianne Hackborn5ac72a22012-08-29 18:32:08 -07004533 mContext.sendStickyBroadcastAsUser(intent, UserHandle.ALL);
Dianne Hackbornad7fa7f2011-01-07 14:06:50 -08004534 }
4535 }
4536
Joe Onoratoea495d42011-04-06 11:41:11 -07004537 void initializeHdmiState() {
Joe Onorato7ba631f2011-05-04 15:28:00 -07004538 boolean plugged = false;
Joe Onoratoea495d42011-04-06 11:41:11 -07004539 // watch for HDMI plug messages if the hdmi switch exists
4540 if (new File("/sys/devices/virtual/switch/hdmi/state").exists()) {
4541 mHDMIObserver.startObserving("DEVPATH=/devices/virtual/switch/hdmi");
4542
Joe Onoratoea495d42011-04-06 11:41:11 -07004543 final String filename = "/sys/class/switch/hdmi/state";
4544 FileReader reader = null;
4545 try {
4546 reader = new FileReader(filename);
4547 char[] buf = new char[15];
4548 int n = reader.read(buf);
4549 if (n > 1) {
4550 plugged = 0 != Integer.parseInt(new String(buf, 0, n-1));
4551 }
4552 } catch (IOException ex) {
4553 Slog.w(TAG, "Couldn't read hdmi state from " + filename + ": " + ex);
4554 } catch (NumberFormatException ex) {
4555 Slog.w(TAG, "Couldn't read hdmi state from " + filename + ": " + ex);
4556 } finally {
4557 if (reader != null) {
4558 try {
4559 reader.close();
4560 } catch (IOException ex) {
4561 }
Joe Onoratodc100302011-01-11 17:07:41 -08004562 }
4563 }
4564 }
Joe Onorato7ba631f2011-05-04 15:28:00 -07004565 // This dance forces the code in setHdmiPlugged to run.
4566 // Always do this so the sticky intent is stuck (to false) if there is no hdmi.
4567 mHdmiPlugged = !plugged;
4568 setHdmiPlugged(!mHdmiPlugged);
Joe Onoratodc100302011-01-11 17:07:41 -08004569 }
4570
Dianne Hackbornc0e3f242011-08-19 14:19:10 -07004571 final Object mScreenshotLock = new Object();
Dianne Hackbornfc8fa632011-08-17 16:20:47 -07004572 ServiceConnection mScreenshotConnection = null;
Dianne Hackbornfc8fa632011-08-17 16:20:47 -07004573
Jeff Brownd5bb82d2011-10-12 13:57:59 -07004574 final Runnable mScreenshotTimeout = new Runnable() {
4575 @Override public void run() {
4576 synchronized (mScreenshotLock) {
4577 if (mScreenshotConnection != null) {
4578 mContext.unbindService(mScreenshotConnection);
4579 mScreenshotConnection = null;
Dianne Hackbornfc8fa632011-08-17 16:20:47 -07004580 }
Winson Chung9112ec32011-06-27 13:15:32 -07004581 }
Jeff Brownd5bb82d2011-10-12 13:57:59 -07004582 }
4583 };
4584
4585 // Assume this is called from the Handler thread.
4586 private void takeScreenshot() {
4587 synchronized (mScreenshotLock) {
4588 if (mScreenshotConnection != null) {
4589 return;
4590 }
4591 ComponentName cn = new ComponentName("com.android.systemui",
4592 "com.android.systemui.screenshot.TakeScreenshotService");
4593 Intent intent = new Intent();
4594 intent.setComponent(cn);
4595 ServiceConnection conn = new ServiceConnection() {
4596 @Override
4597 public void onServiceConnected(ComponentName name, IBinder service) {
4598 synchronized (mScreenshotLock) {
4599 if (mScreenshotConnection != this) {
4600 return;
4601 }
4602 Messenger messenger = new Messenger(service);
4603 Message msg = Message.obtain(null, 1);
4604 final ServiceConnection myConn = this;
4605 Handler h = new Handler(mHandler.getLooper()) {
4606 @Override
4607 public void handleMessage(Message msg) {
4608 synchronized (mScreenshotLock) {
4609 if (mScreenshotConnection == myConn) {
4610 mContext.unbindService(mScreenshotConnection);
4611 mScreenshotConnection = null;
4612 mHandler.removeCallbacks(mScreenshotTimeout);
4613 }
4614 }
4615 }
4616 };
4617 msg.replyTo = new Messenger(h);
Winson Chunga63bb842011-10-17 10:26:28 -07004618 msg.arg1 = msg.arg2 = 0;
4619 if (mStatusBar != null && mStatusBar.isVisibleLw())
4620 msg.arg1 = 1;
4621 if (mNavigationBar != null && mNavigationBar.isVisibleLw())
4622 msg.arg2 = 1;
Jeff Brownd5bb82d2011-10-12 13:57:59 -07004623 try {
4624 messenger.send(msg);
4625 } catch (RemoteException e) {
4626 }
4627 }
4628 }
4629 @Override
4630 public void onServiceDisconnected(ComponentName name) {}
4631 };
Amith Yamasani27b89e62013-01-16 12:30:11 -08004632 if (mContext.bindServiceAsUser(
4633 intent, conn, Context.BIND_AUTO_CREATE, UserHandle.CURRENT)) {
Jeff Brownd5bb82d2011-10-12 13:57:59 -07004634 mScreenshotConnection = conn;
4635 mHandler.postDelayed(mScreenshotTimeout, 10000);
4636 }
4637 }
Winson Chung9112ec32011-06-27 13:15:32 -07004638 }
4639
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004640 /** {@inheritDoc} */
Jeff Brown00fa7bd2010-07-02 15:37:36 -07004641 @Override
Jeff Brown037c33e2014-04-09 00:31:55 -07004642 public int interceptKeyBeforeQueueing(KeyEvent event, int policyFlags) {
Jeff Brown96307042012-07-27 15:51:34 -07004643 if (!mSystemBooted) {
4644 // If we have not yet booted, don't let key events do anything.
4645 return 0;
4646 }
4647
Jeff Brown037c33e2014-04-09 00:31:55 -07004648 final boolean interactive = (policyFlags & FLAG_INTERACTIVE) != 0;
Jeff Brown1f245102010-11-18 20:53:46 -08004649 final boolean down = event.getAction() == KeyEvent.ACTION_DOWN;
4650 final boolean canceled = event.isCanceled();
4651 final int keyCode = event.getKeyCode();
Jeff Browne20c9e02010-10-11 14:20:19 -07004652
Jeff Brown3122e442010-10-11 23:32:49 -07004653 final boolean isInjected = (policyFlags & WindowManagerPolicy.FLAG_INJECTED) != 0;
Jeff Brown3122e442010-10-11 23:32:49 -07004654
Mike Lockwoodc72b15f2009-11-28 20:58:22 -05004655 // If screen is off then we treat the case where the keyguard is open but hidden
4656 // the same as if it were open and in front.
4657 // This will prevent any keys other than the power button from waking the screen
4658 // when the keyguard is hidden by another activity.
Jim Miller5ecd8112013-01-09 18:50:26 -08004659 final boolean keyguardActive = (mKeyguardDelegate == null ? false :
Jeff Brown037c33e2014-04-09 00:31:55 -07004660 (interactive ?
Jim Millerab954542014-10-10 18:21:49 -07004661 isKeyguardShowingAndNotOccluded() :
Jim Miller5ecd8112013-01-09 18:50:26 -08004662 mKeyguardDelegate.isShowing()));
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004663
Jeff Brown40013652012-05-16 21:22:36 -07004664 if (DEBUG_INPUT) {
Jeff Brown00fa7bd2010-07-02 15:37:36 -07004665 Log.d(TAG, "interceptKeyTq keycode=" + keyCode
Jeff Brown037c33e2014-04-09 00:31:55 -07004666 + " interactive=" + interactive + " keyguardActive=" + keyguardActive
Jeff Brown26875502014-01-30 21:47:47 -08004667 + " policyFlags=" + Integer.toHexString(policyFlags));
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004668 }
4669
Jeff Brown037c33e2014-04-09 00:31:55 -07004670 // Basic policy based on interactive state.
Jeff Brown4d396052010-10-29 21:50:21 -07004671 int result;
Michael Wright337d9d22014-04-22 15:03:48 -07004672 boolean isWakeKey = (policyFlags & WindowManagerPolicy.FLAG_WAKE) != 0
4673 || event.isWakeKey();
Michael Wrightfc01f042014-09-08 14:12:24 -07004674 if (interactive || (isInjected && !isWakeKey)) {
RoboErikde9ba392014-09-26 12:51:01 -07004675 // When the device is interactive or the key is injected pass the
4676 // key to the application.
Jeff Brown4d396052010-10-29 21:50:21 -07004677 result = ACTION_PASS_TO_USER;
Jose Lima9546b202014-07-02 17:21:51 -07004678 isWakeKey = false;
Michael Wrightfc01f042014-09-08 14:12:24 -07004679 } else if (!interactive && shouldDispatchInputWhenNonInteractive()) {
4680 // If we're currently dozing with the screen on and the keyguard showing, pass the key
4681 // to the application but preserve its wake key status to make sure we still move
4682 // from dozing to fully interactive if we would normally go from off to fully
4683 // interactive.
4684 result = ACTION_PASS_TO_USER;
Jeff Brown4d396052010-10-29 21:50:21 -07004685 } else {
4686 // When the screen is off and the key is not injected, determine whether
4687 // to wake the device but don't pass the key to the application.
4688 result = 0;
Jeff Brown26875502014-01-30 21:47:47 -08004689 if (isWakeKey && (!down || !isWakeKeyWhenScreenOff(keyCode))) {
4690 isWakeKey = false;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004691 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004692 }
4693
Justin Kohd378ad72013-04-01 12:18:26 -07004694 // If the key would be handled globally, just return the result, don't worry about special
4695 // key processing.
Jeff Brown13f00f02014-10-31 14:45:50 -07004696 if (isValidGlobalKey(keyCode)
4697 && mGlobalKeyManager.shouldHandleGlobalKey(keyCode, event)) {
Michael Wright85b1af62014-06-04 14:51:58 -07004698 if (isWakeKey) {
Jeff Brown13f00f02014-10-31 14:45:50 -07004699 wakeUp(event.getEventTime(), mAllowTheaterModeWakeFromKey);
Michael Wright85b1af62014-06-04 14:51:58 -07004700 }
Justin Kohd378ad72013-04-01 12:18:26 -07004701 return result;
4702 }
4703
Jeff Brownbae8e772014-06-12 19:59:45 -07004704 boolean useHapticFeedback = down
4705 && (policyFlags & WindowManagerPolicy.FLAG_VIRTUAL) != 0
4706 && event.getRepeatCount() == 0;
4707
Jeff Brown4d396052010-10-29 21:50:21 -07004708 // Handle special keys.
4709 switch (keyCode) {
4710 case KeyEvent.KEYCODE_VOLUME_DOWN:
Jeff Brownb0418da2010-11-01 15:24:01 -07004711 case KeyEvent.KEYCODE_VOLUME_UP:
4712 case KeyEvent.KEYCODE_VOLUME_MUTE: {
RoboErik001c59c2015-01-26 15:53:51 -08004713 if (mUseTvRouting) {
4714 // On TVs volume keys never go to the foreground app
4715 result &= ~ACTION_PASS_TO_USER;
4716 }
Jeff Brownd5bb82d2011-10-12 13:57:59 -07004717 if (keyCode == KeyEvent.KEYCODE_VOLUME_DOWN) {
4718 if (down) {
Jeff Brown13f00f02014-10-31 14:45:50 -07004719 if (interactive && !mScreenshotChordVolumeDownKeyTriggered
Jeff Brownd5bb82d2011-10-12 13:57:59 -07004720 && (event.getFlags() & KeyEvent.FLAG_FALLBACK) == 0) {
Jeff Brown13f00f02014-10-31 14:45:50 -07004721 mScreenshotChordVolumeDownKeyTriggered = true;
4722 mScreenshotChordVolumeDownKeyTime = event.getDownTime();
4723 mScreenshotChordVolumeDownKeyConsumed = false;
Jeff Brownd5bb82d2011-10-12 13:57:59 -07004724 cancelPendingPowerKeyAction();
4725 interceptScreenshotChord();
4726 }
4727 } else {
Jeff Brown13f00f02014-10-31 14:45:50 -07004728 mScreenshotChordVolumeDownKeyTriggered = false;
Jeff Brownd5bb82d2011-10-12 13:57:59 -07004729 cancelPendingScreenshotChordAction();
4730 }
4731 } else if (keyCode == KeyEvent.KEYCODE_VOLUME_UP) {
4732 if (down) {
Jeff Brown13f00f02014-10-31 14:45:50 -07004733 if (interactive && !mScreenshotChordVolumeUpKeyTriggered
Jeff Brownd5bb82d2011-10-12 13:57:59 -07004734 && (event.getFlags() & KeyEvent.FLAG_FALLBACK) == 0) {
Jeff Brown13f00f02014-10-31 14:45:50 -07004735 mScreenshotChordVolumeUpKeyTriggered = true;
Jeff Brownd5bb82d2011-10-12 13:57:59 -07004736 cancelPendingPowerKeyAction();
4737 cancelPendingScreenshotChordAction();
4738 }
4739 } else {
Jeff Brown13f00f02014-10-31 14:45:50 -07004740 mScreenshotChordVolumeUpKeyTriggered = false;
Jeff Brownd5bb82d2011-10-12 13:57:59 -07004741 cancelPendingScreenshotChordAction();
4742 }
4743 }
Jeff Brown4d396052010-10-29 21:50:21 -07004744 if (down) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -07004745 TelecomManager telecomManager = getTelecommService();
4746 if (telecomManager != null) {
4747 if (telecomManager.isRinging()) {
Santos Cordon6848f722014-05-21 15:22:12 -07004748 // If an incoming call is ringing, either VOLUME key means
4749 // "silence ringer". We handle these keys here, rather than
4750 // in the InCallScreen, to make sure we'll respond to them
4751 // even if the InCallScreen hasn't come to the foreground yet.
4752 // Look for the DOWN event here, to agree with the "fallback"
4753 // behavior in the InCallScreen.
4754 Log.i(TAG, "interceptKeyBeforeQueueing:"
4755 + " VOLUME key-down while ringing: Silence ringer!");
Jeff Brown4d396052010-10-29 21:50:21 -07004756
Santos Cordon6848f722014-05-21 15:22:12 -07004757 // Silence the ringer. (It's safe to call this
4758 // even if the ringer has already been silenced.)
Tyler Gunnef9f6f92014-09-12 22:16:17 -07004759 telecomManager.silenceRinger();
Jeff Brown4d396052010-10-29 21:50:21 -07004760
Santos Cordon6848f722014-05-21 15:22:12 -07004761 // And *don't* pass this key thru to the current activity
4762 // (which is probably the InCallScreen.)
4763 result &= ~ACTION_PASS_TO_USER;
4764 break;
4765 }
Tyler Gunnef9f6f92014-09-12 22:16:17 -07004766 if (telecomManager.isInCall()
Santos Cordon6848f722014-05-21 15:22:12 -07004767 && (result & ACTION_PASS_TO_USER) == 0) {
4768 // If we are in call but we decided not to pass the key to
RoboErik430fc482014-06-12 15:49:20 -07004769 // the application, just pass it to the session service.
4770
4771 MediaSessionLegacyHelper.getHelper(mContext)
RoboErik3c45c292014-07-08 16:47:31 -07004772 .sendVolumeKeyEvent(event, false);
Santos Cordon6848f722014-05-21 15:22:12 -07004773 break;
Jeff Brown4d396052010-10-29 21:50:21 -07004774 }
4775 }
4776
RoboErik430fc482014-06-12 15:49:20 -07004777 if ((result & ACTION_PASS_TO_USER) == 0) {
RoboErik001c59c2015-01-26 15:53:51 -08004778 if (mUseTvRouting) {
4779 dispatchDirectAudioEvent(event);
4780 } else {
4781 // If we aren't passing to the user and no one else
4782 // handled it send it to the session manager to
4783 // figure out.
4784 MediaSessionLegacyHelper.getHelper(mContext)
4785 .sendVolumeKeyEvent(event, true);
4786 }
Jeff Brown4d396052010-10-29 21:50:21 -07004787 break;
4788 }
4789 }
4790 break;
4791 }
4792
4793 case KeyEvent.KEYCODE_ENDCALL: {
4794 result &= ~ACTION_PASS_TO_USER;
4795 if (down) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -07004796 TelecomManager telecomManager = getTelecommService();
Jeff Brown4d396052010-10-29 21:50:21 -07004797 boolean hungUp = false;
Tyler Gunnef9f6f92014-09-12 22:16:17 -07004798 if (telecomManager != null) {
4799 hungUp = telecomManager.endCall();
Jeff Brown4d396052010-10-29 21:50:21 -07004800 }
Jeff Brown13f00f02014-10-31 14:45:50 -07004801 if (interactive && !hungUp) {
4802 mEndCallKeyHandled = false;
4803 mHandler.postDelayed(mEndCallLongPress,
4804 ViewConfiguration.get(mContext).getDeviceGlobalActionKeyTimeout());
4805 } else {
4806 mEndCallKeyHandled = true;
4807 }
Jeff Brown4d396052010-10-29 21:50:21 -07004808 } else {
Jeff Brown13f00f02014-10-31 14:45:50 -07004809 if (!mEndCallKeyHandled) {
4810 mHandler.removeCallbacks(mEndCallLongPress);
4811 if (!canceled) {
4812 if ((mEndcallBehavior
4813 & Settings.System.END_BUTTON_BEHAVIOR_HOME) != 0) {
4814 if (goHome()) {
4815 break;
4816 }
Dianne Hackborn0041e972009-07-24 17:14:43 -07004817 }
Jeff Brown13f00f02014-10-31 14:45:50 -07004818 if ((mEndcallBehavior
4819 & Settings.System.END_BUTTON_BEHAVIOR_SLEEP) != 0) {
4820 mPowerManager.goToSleep(event.getEventTime(),
4821 PowerManager.GO_TO_SLEEP_REASON_POWER_BUTTON, 0);
4822 isWakeKey = false;
4823 }
Jeff Brown4d396052010-10-29 21:50:21 -07004824 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004825 }
Jeff Brown4d396052010-10-29 21:50:21 -07004826 }
4827 break;
4828 }
4829
4830 case KeyEvent.KEYCODE_POWER: {
4831 result &= ~ACTION_PASS_TO_USER;
Jeff Brown13f00f02014-10-31 14:45:50 -07004832 isWakeKey = false; // wake-up will be handled separately
Jeff Brown4d396052010-10-29 21:50:21 -07004833 if (down) {
Jeff Brown13f00f02014-10-31 14:45:50 -07004834 interceptPowerKeyDown(event, interactive);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004835 } else {
Jeff Brown13f00f02014-10-31 14:45:50 -07004836 interceptPowerKeyUp(event, interactive, canceled);
Jeff Brown4d396052010-10-29 21:50:21 -07004837 }
4838 break;
4839 }
4840
Jeff Brown6212a492014-03-07 13:58:47 -08004841 case KeyEvent.KEYCODE_SLEEP: {
4842 result &= ~ACTION_PASS_TO_USER;
Filip Gruszczynskia483a1d2015-03-17 19:06:58 +00004843 isWakeKey = false;
Jeff Brownbae8e772014-06-12 19:59:45 -07004844 if (!mPowerManager.isInteractive()) {
4845 useHapticFeedback = false; // suppress feedback if already non-interactive
4846 }
Filip Gruszczynskia483a1d2015-03-17 19:06:58 +00004847 sleepPress(event);
Jeff Brown6212a492014-03-07 13:58:47 -08004848 break;
4849 }
4850
4851 case KeyEvent.KEYCODE_WAKEUP: {
4852 result &= ~ACTION_PASS_TO_USER;
Jose Lima9546b202014-07-02 17:21:51 -07004853 isWakeKey = true;
Jeff Brown6212a492014-03-07 13:58:47 -08004854 break;
4855 }
4856
Jeff Brown4d396052010-10-29 21:50:21 -07004857 case KeyEvent.KEYCODE_MEDIA_PLAY:
4858 case KeyEvent.KEYCODE_MEDIA_PAUSE:
4859 case KeyEvent.KEYCODE_MEDIA_PLAY_PAUSE:
Jeff Brown4d396052010-10-29 21:50:21 -07004860 case KeyEvent.KEYCODE_HEADSETHOOK:
4861 case KeyEvent.KEYCODE_MUTE:
4862 case KeyEvent.KEYCODE_MEDIA_STOP:
4863 case KeyEvent.KEYCODE_MEDIA_NEXT:
4864 case KeyEvent.KEYCODE_MEDIA_PREVIOUS:
4865 case KeyEvent.KEYCODE_MEDIA_REWIND:
4866 case KeyEvent.KEYCODE_MEDIA_RECORD:
Jaekyun Seokbfdad8e2013-07-08 13:53:21 +09004867 case KeyEvent.KEYCODE_MEDIA_FAST_FORWARD:
4868 case KeyEvent.KEYCODE_MEDIA_AUDIO_TRACK: {
RoboErikde9ba392014-09-26 12:51:01 -07004869 if (MediaSessionLegacyHelper.getHelper(mContext).isGlobalPriorityActive()) {
4870 // If the global session is active pass all media keys to it
4871 // instead of the active window.
4872 result &= ~ACTION_PASS_TO_USER;
4873 }
Jeff Brown4d396052010-10-29 21:50:21 -07004874 if ((result & ACTION_PASS_TO_USER) == 0) {
4875 // Only do this if we would otherwise not pass it to the user. In that
4876 // case, the PhoneWindow class will do the same thing, except it will
4877 // only do it if the showing app doesn't process the key on its own.
Jeff Brown40013652012-05-16 21:22:36 -07004878 // Note that we need to make a copy of the key event here because the
4879 // original key event will be recycled when we return.
Jeff Brown4d396052010-10-29 21:50:21 -07004880 mBroadcastWakeLock.acquire();
Jeff Brown40013652012-05-16 21:22:36 -07004881 Message msg = mHandler.obtainMessage(MSG_DISPATCH_MEDIA_KEY_WITH_WAKE_LOCK,
4882 new KeyEvent(event));
4883 msg.setAsynchronous(true);
4884 msg.sendToTarget();
Jeff Brown4d396052010-10-29 21:50:21 -07004885 }
4886 break;
Jeff Brown00fa7bd2010-07-02 15:37:36 -07004887 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004888
Jeff Brown4d396052010-10-29 21:50:21 -07004889 case KeyEvent.KEYCODE_CALL: {
4890 if (down) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -07004891 TelecomManager telecomManager = getTelecommService();
4892 if (telecomManager != null) {
4893 if (telecomManager.isRinging()) {
Santos Cordon6848f722014-05-21 15:22:12 -07004894 Log.i(TAG, "interceptKeyBeforeQueueing:"
4895 + " CALL key-down while ringing: Answer the call!");
Tyler Gunnef9f6f92014-09-12 22:16:17 -07004896 telecomManager.acceptRingingCall();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004897
Santos Cordon6848f722014-05-21 15:22:12 -07004898 // And *don't* pass this key thru to the current activity
4899 // (which is presumably the InCallScreen.)
4900 result &= ~ACTION_PASS_TO_USER;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004901 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004902 }
Jeff Brown00fa7bd2010-07-02 15:37:36 -07004903 }
Jeff Brown4d396052010-10-29 21:50:21 -07004904 break;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004905 }
Michael Wright869a67c2014-08-26 19:33:06 -07004906 case KeyEvent.KEYCODE_VOICE_ASSIST: {
4907 // Only do this if we would otherwise not pass it to the user. In that case,
4908 // interceptKeyBeforeDispatching would apply a similar but different policy in
4909 // order to invoke voice assist actions. Note that we need to make a copy of the
4910 // key event here because the original key event will be recycled when we return.
4911 if ((result & ACTION_PASS_TO_USER) == 0 && !down) {
4912 mBroadcastWakeLock.acquire();
4913 Message msg = mHandler.obtainMessage(MSG_LAUNCH_VOICE_ASSIST_WITH_WAKE_LOCK,
4914 keyguardActive ? 1 : 0, 0);
4915 msg.setAsynchronous(true);
4916 msg.sendToTarget();
4917 }
4918 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004919 }
Jeff Brown26875502014-01-30 21:47:47 -08004920
Jeff Brownbae8e772014-06-12 19:59:45 -07004921 if (useHapticFeedback) {
4922 performHapticFeedbackLw(null, HapticFeedbackConstants.VIRTUAL_KEY, false);
4923 }
4924
Jeff Brown26875502014-01-30 21:47:47 -08004925 if (isWakeKey) {
Jeff Brown13f00f02014-10-31 14:45:50 -07004926 wakeUp(event.getEventTime(), mAllowTheaterModeWakeFromKey);
Jeff Brown26875502014-01-30 21:47:47 -08004927 }
Bryce Lee584a4452014-10-21 15:55:55 -07004928
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004929 return result;
4930 }
4931
Jeff Brown1c2e4942012-11-06 16:32:01 -08004932 /**
Jeff Brown13f00f02014-10-31 14:45:50 -07004933 * Returns true if the key can have global actions attached to it.
4934 * We reserve all power management keys for the system since they require
4935 * very careful handling.
4936 */
4937 private static boolean isValidGlobalKey(int keyCode) {
4938 switch (keyCode) {
4939 case KeyEvent.KEYCODE_POWER:
4940 case KeyEvent.KEYCODE_WAKEUP:
4941 case KeyEvent.KEYCODE_SLEEP:
4942 return false;
4943 default:
4944 return true;
4945 }
4946 }
4947
4948 /**
Jeff Brown1c2e4942012-11-06 16:32:01 -08004949 * When the screen is off we ignore some keys that might otherwise typically
4950 * be considered wake keys. We filter them out here.
4951 *
4952 * {@link KeyEvent#KEYCODE_POWER} is notably absent from this list because it
4953 * is always considered a wake key.
4954 */
4955 private boolean isWakeKeyWhenScreenOff(int keyCode) {
4956 switch (keyCode) {
4957 // ignore volume keys unless docked
4958 case KeyEvent.KEYCODE_VOLUME_UP:
4959 case KeyEvent.KEYCODE_VOLUME_DOWN:
4960 case KeyEvent.KEYCODE_VOLUME_MUTE:
4961 return mDockMode != Intent.EXTRA_DOCK_STATE_UNDOCKED;
4962
4963 // ignore media and camera keys
4964 case KeyEvent.KEYCODE_MUTE:
4965 case KeyEvent.KEYCODE_HEADSETHOOK:
4966 case KeyEvent.KEYCODE_MEDIA_PLAY:
4967 case KeyEvent.KEYCODE_MEDIA_PAUSE:
4968 case KeyEvent.KEYCODE_MEDIA_PLAY_PAUSE:
4969 case KeyEvent.KEYCODE_MEDIA_STOP:
4970 case KeyEvent.KEYCODE_MEDIA_NEXT:
4971 case KeyEvent.KEYCODE_MEDIA_PREVIOUS:
4972 case KeyEvent.KEYCODE_MEDIA_REWIND:
4973 case KeyEvent.KEYCODE_MEDIA_RECORD:
4974 case KeyEvent.KEYCODE_MEDIA_FAST_FORWARD:
Jaekyun Seokbfdad8e2013-07-08 13:53:21 +09004975 case KeyEvent.KEYCODE_MEDIA_AUDIO_TRACK:
Jeff Brown1c2e4942012-11-06 16:32:01 -08004976 case KeyEvent.KEYCODE_CAMERA:
4977 return false;
4978 }
4979 return true;
4980 }
4981
4982
Jeff Brown56194eb2011-03-02 19:23:13 -08004983 /** {@inheritDoc} */
4984 @Override
Michael Wright70af00a2014-09-03 19:30:20 -07004985 public int interceptMotionBeforeQueueingNonInteractive(long whenNanos, int policyFlags) {
4986 if ((policyFlags & FLAG_WAKE) != 0) {
Bryce Lee5c138322014-11-03 08:26:09 -08004987 if (wakeUp(whenNanos / 1000000, mAllowTheaterModeWakeFromMotion)) {
4988 return 0;
4989 }
Michael Wright70af00a2014-09-03 19:30:20 -07004990 }
Bryce Lee5c138322014-11-03 08:26:09 -08004991
Michael Wright70af00a2014-09-03 19:30:20 -07004992 if (shouldDispatchInputWhenNonInteractive()) {
4993 return ACTION_PASS_TO_USER;
4994 }
Bryce Lee5c138322014-11-03 08:26:09 -08004995
Bryce Lee812d7022014-11-10 13:33:28 -08004996 // If we have not passed the action up and we are in theater mode without dreaming,
4997 // there will be no dream to intercept the touch and wake into ambient. The device should
4998 // wake up in this case.
4999 if (isTheaterModeEnabled() && (policyFlags & FLAG_WAKE) != 0) {
5000 wakeUp(whenNanos / 1000000, mAllowTheaterModeWakeFromMotionWhenNotDreaming);
5001 }
5002
Jeff Brown037c33e2014-04-09 00:31:55 -07005003 return 0;
Jeff Brown56194eb2011-03-02 19:23:13 -08005004 }
5005
Michael Wright70af00a2014-09-03 19:30:20 -07005006 private boolean shouldDispatchInputWhenNonInteractive() {
Bryce Lee5c138322014-11-03 08:26:09 -08005007 // Send events to keyguard while the screen is on.
Jim Millerab954542014-10-10 18:21:49 -07005008 if (isKeyguardShowingAndNotOccluded() && mDisplay != null
5009 && mDisplay.getState() != Display.STATE_OFF) {
Bryce Lee5c138322014-11-03 08:26:09 -08005010 return true;
5011 }
5012
5013 // Send events to a dozing dream even if the screen is off since the dream
5014 // is in control of the state of the screen.
5015 IDreamManager dreamManager = getDreamManager();
5016
5017 try {
5018 if (dreamManager != null && dreamManager.isDreaming()) {
5019 return true;
5020 }
5021 } catch (RemoteException e) {
5022 Slog.e(TAG, "RemoteException when checking if dreaming", e);
5023 }
5024
5025 // Otherwise, consume events since the user can't see what is being
5026 // interacted with.
5027 return false;
Michael Wright70af00a2014-09-03 19:30:20 -07005028 }
5029
RoboErik001c59c2015-01-26 15:53:51 -08005030 private void dispatchDirectAudioEvent(KeyEvent event) {
5031 if (event.getAction() != KeyEvent.ACTION_DOWN) {
5032 return;
5033 }
5034 int keyCode = event.getKeyCode();
John Spurlockb94f2d62015-03-17 14:11:57 -04005035 int flags = AudioManager.FLAG_SHOW_UI | AudioManager.FLAG_PLAY_SOUND
5036 | AudioManager.FLAG_FROM_KEY;
RoboErik001c59c2015-01-26 15:53:51 -08005037 String pkgName = mContext.getOpPackageName();
5038 switch (keyCode) {
5039 case KeyEvent.KEYCODE_VOLUME_UP:
5040 try {
John Spurlockee5ad722015-03-03 16:17:21 -05005041 getAudioService().adjustSuggestedStreamVolume(AudioManager.ADJUST_RAISE,
John Spurlock90874332015-03-10 16:00:54 -04005042 AudioManager.USE_DEFAULT_STREAM_TYPE, flags, pkgName, TAG);
RoboErik001c59c2015-01-26 15:53:51 -08005043 } catch (RemoteException e) {
5044 Log.e(TAG, "Error dispatching volume up in dispatchTvAudioEvent.", e);
5045 }
5046 break;
5047 case KeyEvent.KEYCODE_VOLUME_DOWN:
5048 try {
John Spurlockee5ad722015-03-03 16:17:21 -05005049 getAudioService().adjustSuggestedStreamVolume(AudioManager.ADJUST_LOWER,
John Spurlock90874332015-03-10 16:00:54 -04005050 AudioManager.USE_DEFAULT_STREAM_TYPE, flags, pkgName, TAG);
RoboErik001c59c2015-01-26 15:53:51 -08005051 } catch (RemoteException e) {
5052 Log.e(TAG, "Error dispatching volume down in dispatchTvAudioEvent.", e);
5053 }
5054 break;
5055 case KeyEvent.KEYCODE_VOLUME_MUTE:
5056 try {
5057 if (event.getRepeatCount() == 0) {
John Spurlockee5ad722015-03-03 16:17:21 -05005058 getAudioService().adjustSuggestedStreamVolume(
5059 AudioManager.ADJUST_TOGGLE_MUTE,
John Spurlock90874332015-03-10 16:00:54 -04005060 AudioManager.USE_DEFAULT_STREAM_TYPE, flags, pkgName, TAG);
RoboErik001c59c2015-01-26 15:53:51 -08005061 }
5062 } catch (RemoteException e) {
5063 Log.e(TAG, "Error dispatching mute in dispatchTvAudioEvent.", e);
5064 }
5065 break;
5066 }
5067 }
5068
Jeff Brown40013652012-05-16 21:22:36 -07005069 void dispatchMediaKeyWithWakeLock(KeyEvent event) {
5070 if (DEBUG_INPUT) {
5071 Slog.d(TAG, "dispatchMediaKeyWithWakeLock: " + event);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005072 }
5073
Jeff Brown40013652012-05-16 21:22:36 -07005074 if (mHavePendingMediaKeyRepeatWithWakeLock) {
5075 if (DEBUG_INPUT) {
5076 Slog.d(TAG, "dispatchMediaKeyWithWakeLock: canceled repeat");
5077 }
5078
5079 mHandler.removeMessages(MSG_DISPATCH_MEDIA_KEY_REPEAT_WITH_WAKE_LOCK);
5080 mHavePendingMediaKeyRepeatWithWakeLock = false;
5081 mBroadcastWakeLock.release(); // pending repeat was holding onto the wake lock
5082 }
5083
5084 dispatchMediaKeyWithWakeLockToAudioService(event);
5085
5086 if (event.getAction() == KeyEvent.ACTION_DOWN
5087 && event.getRepeatCount() == 0) {
5088 mHavePendingMediaKeyRepeatWithWakeLock = true;
5089
5090 Message msg = mHandler.obtainMessage(
5091 MSG_DISPATCH_MEDIA_KEY_REPEAT_WITH_WAKE_LOCK, event);
5092 msg.setAsynchronous(true);
5093 mHandler.sendMessageDelayed(msg, ViewConfiguration.getKeyRepeatTimeout());
5094 } else {
5095 mBroadcastWakeLock.release();
5096 }
5097 }
5098
5099 void dispatchMediaKeyRepeatWithWakeLock(KeyEvent event) {
5100 mHavePendingMediaKeyRepeatWithWakeLock = false;
5101
5102 KeyEvent repeatEvent = KeyEvent.changeTimeRepeat(event,
5103 SystemClock.uptimeMillis(), 1, event.getFlags() | KeyEvent.FLAG_LONG_PRESS);
5104 if (DEBUG_INPUT) {
5105 Slog.d(TAG, "dispatchMediaKeyRepeatWithWakeLock: " + repeatEvent);
5106 }
5107
5108 dispatchMediaKeyWithWakeLockToAudioService(repeatEvent);
5109 mBroadcastWakeLock.release();
5110 }
5111
5112 void dispatchMediaKeyWithWakeLockToAudioService(KeyEvent event) {
5113 if (ActivityManagerNative.isSystemReady()) {
RoboErik430fc482014-06-12 15:49:20 -07005114 MediaSessionLegacyHelper.getHelper(mContext).sendMediaButtonEvent(event, true);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005115 }
5116 }
5117
Michael Wright869a67c2014-08-26 19:33:06 -07005118 void launchVoiceAssistWithWakeLock(boolean keyguardActive) {
5119 Intent voiceIntent =
5120 new Intent(RecognizerIntent.ACTION_VOICE_SEARCH_HANDS_FREE);
5121 voiceIntent.putExtra(RecognizerIntent.EXTRA_SECURE, keyguardActive);
Bart Sears8b1c27c2015-03-18 23:51:02 +00005122 startActivityAsUser(voiceIntent, UserHandle.CURRENT_OR_SELF);
Michael Wright869a67c2014-08-26 19:33:06 -07005123 mBroadcastWakeLock.release();
5124 }
5125
Mike Lockwood1753f7f2009-08-24 14:49:07 -07005126 BroadcastReceiver mDockReceiver = new BroadcastReceiver() {
Craig Mautnereee29c42013-01-17 14:44:34 -08005127 @Override
Mike Lockwood1753f7f2009-08-24 14:49:07 -07005128 public void onReceive(Context context, Intent intent) {
Dianne Hackborn867ab6472010-04-29 13:28:56 -07005129 if (Intent.ACTION_DOCK_EVENT.equals(intent.getAction())) {
5130 mDockMode = intent.getIntExtra(Intent.EXTRA_DOCK_STATE,
5131 Intent.EXTRA_DOCK_STATE_UNDOCKED);
Daniel Sandler6396c722013-04-16 20:19:09 -04005132 } else {
5133 try {
5134 IUiModeManager uiModeService = IUiModeManager.Stub.asInterface(
5135 ServiceManager.getService(Context.UI_MODE_SERVICE));
5136 mUiMode = uiModeService.getCurrentModeType();
5137 } catch (RemoteException e) {
5138 }
Dianne Hackborn80fa1662009-10-07 14:02:10 -07005139 }
Jeff Brown01a98dd2011-09-20 15:08:29 -07005140 updateRotation(true);
Craig Mautnereee29c42013-01-17 14:44:34 -08005141 synchronized (mLock) {
5142 updateOrientationListenerLp();
5143 }
Mike Lockwood1753f7f2009-08-24 14:49:07 -07005144 }
5145 };
5146
Jeff Brown6aaf2952012-10-05 16:01:08 -07005147 BroadcastReceiver mDreamReceiver = new BroadcastReceiver() {
5148 @Override
5149 public void onReceive(Context context, Intent intent) {
5150 if (Intent.ACTION_DREAMING_STARTED.equals(intent.getAction())) {
Jim Miller5ecd8112013-01-09 18:50:26 -08005151 if (mKeyguardDelegate != null) {
5152 mKeyguardDelegate.onDreamingStarted();
Jeff Brown6aaf2952012-10-05 16:01:08 -07005153 }
5154 } else if (Intent.ACTION_DREAMING_STOPPED.equals(intent.getAction())) {
Jim Miller5ecd8112013-01-09 18:50:26 -08005155 if (mKeyguardDelegate != null) {
5156 mKeyguardDelegate.onDreamingStopped();
Jeff Brown6aaf2952012-10-05 16:01:08 -07005157 }
5158 }
5159 }
5160 };
5161
Christopher Tate5e08af02012-09-21 17:17:22 -07005162 BroadcastReceiver mMultiuserReceiver = new BroadcastReceiver() {
5163 @Override
5164 public void onReceive(Context context, Intent intent) {
5165 if (Intent.ACTION_USER_SWITCHED.equals(intent.getAction())) {
5166 // tickle the settings observer: this first ensures that we're
5167 // observing the relevant settings for the newly-active user,
5168 // and then updates our own bookkeeping based on the now-
5169 // current user.
5170 mSettingsObserver.onChange(false);
John Spurlockce479d82012-11-29 09:52:21 -05005171
5172 // force a re-application of focused window sysui visibility.
5173 // the window may never have been shown for this user
5174 // e.g. the keyguard when going through the new-user setup flow
John Spurlock04db1762013-05-13 12:46:41 -04005175 synchronized (mWindowManagerFuncs.getWindowManagerLock()) {
John Spurlockce479d82012-11-29 09:52:21 -05005176 mLastSystemUiFlags = 0;
5177 updateSystemUiVisibilityLw();
5178 }
Christopher Tate5e08af02012-09-21 17:17:22 -07005179 }
5180 }
5181 };
5182
John Spurlockd9b70bd2014-02-06 17:02:44 -05005183 private final Runnable mRequestTransientNav = new Runnable() {
5184 @Override
5185 public void run() {
5186 requestTransientBars(mNavigationBar);
5187 }
5188 };
5189
John Spurlocke1f366f2013-08-05 12:22:40 -04005190 private void requestTransientBars(WindowState swipeTarget) {
John Spurlock04db1762013-05-13 12:46:41 -04005191 synchronized (mWindowManagerFuncs.getWindowManagerLock()) {
Maurice Lam99c6e072014-04-28 18:24:28 -07005192 if (!isUserSetupComplete()) {
5193 // Swipe-up for navigation bar is disabled during setup
5194 return;
5195 }
John Spurlock27735a42013-08-14 17:57:38 -04005196 boolean sb = mStatusBarController.checkShowTransientBarLw();
5197 boolean nb = mNavigationBarController.checkShowTransientBarLw();
John Spurlockad3e6cb2013-04-30 08:47:43 -04005198 if (sb || nb) {
Adrian Roos62b65e42015-02-25 18:05:34 +01005199 // Don't show status bar when swiping on already visible navigation bar
5200 if (!nb && swipeTarget == mNavigationBar) {
John Spurlocke1f366f2013-08-05 12:22:40 -04005201 if (DEBUG) Slog.d(TAG, "Not showing transient bar, wrong swipe target");
John Spurlockad3e6cb2013-04-30 08:47:43 -04005202 return;
5203 }
John Spurlock27735a42013-08-14 17:57:38 -04005204 if (sb) mStatusBarController.showTransient();
5205 if (nb) mNavigationBarController.showTransient();
John Spurlockf1a36642013-10-12 17:50:42 -04005206 mImmersiveModeConfirmation.confirmCurrentPrompt();
John Spurlockad3e6cb2013-04-30 08:47:43 -04005207 updateSystemUiVisibilityLw();
John Spurlock32beb2c2013-03-11 10:16:47 -04005208 }
John Spurlockad3e6cb2013-04-30 08:47:43 -04005209 }
5210 }
5211
Jeff Brown3ee549c2014-09-22 20:14:39 -07005212 // Called on the PowerManager's Notifier thread.
Jeff Brownc38c9be2012-10-04 13:16:19 -07005213 @Override
Jeff Brown140ffc72014-05-01 15:18:00 -07005214 public void goingToSleep(int why) {
Dianne Hackborn74489012009-03-24 20:50:09 -07005215 EventLog.writeEvent(70000, 0);
Jeff Brown36c4db82014-09-19 12:05:31 -07005216 if (DEBUG_WAKEUP) Slog.i(TAG, "Going to sleep...");
Jeff Brown3ee549c2014-09-22 20:14:39 -07005217
5218 // We must get this work done here because the power manager will drop
5219 // the wake lock and let the system suspend once this function returns.
The Android Open Source Project0727d222009-03-11 12:11:58 -07005220 synchronized (mLock) {
Jeff Brown3ee549c2014-09-22 20:14:39 -07005221 mAwake = false;
5222 mKeyguardDrawComplete = false;
Jeff Browna20dda42014-05-27 20:57:24 -07005223 updateWakeGestureListenerLp();
The Android Open Source Project0727d222009-03-11 12:11:58 -07005224 updateOrientationListenerLp();
Mike Lockwood28569302010-01-28 11:54:40 -05005225 updateLockScreenTimeout();
The Android Open Source Project0727d222009-03-11 12:11:58 -07005226 }
Jeff Brown3ee549c2014-09-22 20:14:39 -07005227
5228 if (mKeyguardDelegate != null) {
5229 mKeyguardDelegate.onScreenTurnedOff(why);
5230 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005231 }
5232
Jeff Brown13f00f02014-10-31 14:45:50 -07005233 private void wakeUpFromPowerKey(long eventTime) {
5234 wakeUp(eventTime, mAllowTheaterModeWakeFromPowerKey);
5235 }
5236
Bryce Lee5c138322014-11-03 08:26:09 -08005237 private boolean wakeUp(long wakeTime, boolean wakeInTheaterMode) {
Bryce Lee584a4452014-10-21 15:55:55 -07005238 if (!wakeInTheaterMode && isTheaterModeEnabled()) {
Bryce Lee5c138322014-11-03 08:26:09 -08005239 return false;
Bryce Lee584a4452014-10-21 15:55:55 -07005240 }
5241
5242 mPowerManager.wakeUp(wakeTime);
Bryce Lee5c138322014-11-03 08:26:09 -08005243 return true;
Bryce Lee584a4452014-10-21 15:55:55 -07005244 }
5245
Jeff Brown3ee549c2014-09-22 20:14:39 -07005246 // Called on the PowerManager's Notifier thread.
Jeff Brownc38c9be2012-10-04 13:16:19 -07005247 @Override
Jeff Brown36c4db82014-09-19 12:05:31 -07005248 public void wakingUp() {
Dianne Hackborn74489012009-03-24 20:50:09 -07005249 EventLog.writeEvent(70000, 1);
Jeff Brown36c4db82014-09-19 12:05:31 -07005250 if (DEBUG_WAKEUP) Slog.i(TAG, "Waking up...");
Craig Mautner8a0da012014-05-31 15:13:37 -07005251
Jeff Brown3ee549c2014-09-22 20:14:39 -07005252 // Since goToSleep performs these functions synchronously, we must
5253 // do the same here. We cannot post this work to a handler because
5254 // that might cause it to become reordered with respect to what
5255 // may happen in a future call to goToSleep.
The Android Open Source Project0727d222009-03-11 12:11:58 -07005256 synchronized (mLock) {
Jeff Brown3ee549c2014-09-22 20:14:39 -07005257 mAwake = true;
5258 mKeyguardDrawComplete = false;
5259 if (mKeyguardDelegate != null) {
5260 mHandler.removeMessages(MSG_KEYGUARD_DRAWN_TIMEOUT);
5261 mHandler.sendEmptyMessageDelayed(MSG_KEYGUARD_DRAWN_TIMEOUT, 1000);
5262 }
5263
Jeff Browna20dda42014-05-27 20:57:24 -07005264 updateWakeGestureListenerLp();
The Android Open Source Project0727d222009-03-11 12:11:58 -07005265 updateOrientationListenerLp();
Mike Lockwood28569302010-01-28 11:54:40 -05005266 updateLockScreenTimeout();
The Android Open Source Project0727d222009-03-11 12:11:58 -07005267 }
Jeff Brownc38c9be2012-10-04 13:16:19 -07005268
Jim Miller5ecd8112013-01-09 18:50:26 -08005269 if (mKeyguardDelegate != null) {
Craig Mautner8a0da012014-05-31 15:13:37 -07005270 mKeyguardDelegate.onScreenTurnedOn(mKeyguardDelegateCallback);
Jeff Brown36c4db82014-09-19 12:05:31 -07005271 // ... eventually calls finishKeyguardDrawn
Jeff Brownc38c9be2012-10-04 13:16:19 -07005272 } else {
Craig Mautner8a0da012014-05-31 15:13:37 -07005273 if (DEBUG_WAKEUP) Slog.d(TAG, "null mKeyguardDelegate: setting mKeyguardDrawComplete.");
Jeff Brown36c4db82014-09-19 12:05:31 -07005274 finishKeyguardDrawn();
Jeff Brownc38c9be2012-10-04 13:16:19 -07005275 }
Jeff Brown36c4db82014-09-19 12:05:31 -07005276 }
5277
Jeff Brown36c4db82014-09-19 12:05:31 -07005278 private void finishKeyguardDrawn() {
Jeff Brown3ee549c2014-09-22 20:14:39 -07005279 synchronized (mLock) {
5280 if (!mAwake || mKeyguardDrawComplete) {
5281 return; // spurious
5282 }
5283
Jeff Brown36c4db82014-09-19 12:05:31 -07005284 mKeyguardDrawComplete = true;
Jeff Brown3ee549c2014-09-22 20:14:39 -07005285 if (mKeyguardDelegate != null) {
5286 mHandler.removeMessages(MSG_KEYGUARD_DRAWN_TIMEOUT);
5287 }
5288 }
5289
5290 finishScreenTurningOn();
5291 }
5292
5293 // Called on the DisplayManager's DisplayPowerController thread.
5294 @Override
5295 public void screenTurnedOff() {
5296 if (DEBUG_WAKEUP) Slog.i(TAG, "Screen turned off...");
5297
5298 synchronized (mLock) {
5299 mScreenOnEarly = false;
5300 mScreenOnFully = false;
5301 mWindowManagerDrawComplete = false;
5302 mScreenOnListener = null;
5303 updateOrientationListenerLp();
Jeff Brown36c4db82014-09-19 12:05:31 -07005304 }
5305 }
5306
Jeff Brown3ee549c2014-09-22 20:14:39 -07005307 // Called on the DisplayManager's DisplayPowerController thread.
Jeff Brown36c4db82014-09-19 12:05:31 -07005308 @Override
5309 public void screenTurningOn(final ScreenOnListener screenOnListener) {
Jeff Brown36c4db82014-09-19 12:05:31 -07005310 if (DEBUG_WAKEUP) Slog.i(TAG, "Screen turning on...");
Jeff Brown36c4db82014-09-19 12:05:31 -07005311
Jeff Brown3ee549c2014-09-22 20:14:39 -07005312 synchronized (mLock) {
5313 mScreenOnEarly = true;
5314 mScreenOnFully = false;
5315 mWindowManagerDrawComplete = false;
5316 mScreenOnListener = screenOnListener;
5317 updateOrientationListenerLp();
5318 }
Jeff Brown36c4db82014-09-19 12:05:31 -07005319
Craig Mautnerc3daedd2014-09-13 11:17:23 -07005320 mWindowManagerInternal.waitForAllWindowsDrawn(mWindowManagerDrawCallback,
5321 WAITING_FOR_DRAWN_TIMEOUT);
Jeff Brown36c4db82014-09-19 12:05:31 -07005322 // ... eventually calls finishWindowsDrawn
5323 }
5324
Jeff Brown36c4db82014-09-19 12:05:31 -07005325 private void finishWindowsDrawn() {
Jeff Brown3ee549c2014-09-22 20:14:39 -07005326 synchronized (mLock) {
5327 if (!mScreenOnEarly || mWindowManagerDrawComplete) {
5328 return; // spurious
5329 }
5330
Jeff Brown36c4db82014-09-19 12:05:31 -07005331 mWindowManagerDrawComplete = true;
Jeff Brown36c4db82014-09-19 12:05:31 -07005332 }
Jeff Brown3ee549c2014-09-22 20:14:39 -07005333
5334 finishScreenTurningOn();
Jeff Brownc38c9be2012-10-04 13:16:19 -07005335 }
5336
Craig Mautner8a0da012014-05-31 15:13:37 -07005337 private void finishScreenTurningOn() {
Jeff Brown3ee549c2014-09-22 20:14:39 -07005338 final ScreenOnListener listener;
5339 final boolean enableScreen;
Jeff Brown36c4db82014-09-19 12:05:31 -07005340 synchronized (mLock) {
Jeff Brown3ee549c2014-09-22 20:14:39 -07005341 if (DEBUG_WAKEUP) Slog.d(TAG,
5342 "finishScreenTurningOn: mAwake=" + mAwake
5343 + ", mScreenOnEarly=" + mScreenOnEarly
5344 + ", mScreenOnFully=" + mScreenOnFully
5345 + ", mKeyguardDrawComplete=" + mKeyguardDrawComplete
5346 + ", mWindowManagerDrawComplete=" + mWindowManagerDrawComplete);
5347
5348 if (mScreenOnFully || !mScreenOnEarly || !mWindowManagerDrawComplete
5349 || (mAwake && !mKeyguardDrawComplete)) {
5350 return; // spurious or not ready yet
Jeff Brown36c4db82014-09-19 12:05:31 -07005351 }
5352
Jeff Brown3ee549c2014-09-22 20:14:39 -07005353 if (DEBUG_WAKEUP) Slog.i(TAG, "Finished screen turning on...");
5354 listener = mScreenOnListener;
Craig Mautner13f6ea72014-06-23 14:57:02 -07005355 mScreenOnListener = null;
Jeff Brown3ee549c2014-09-22 20:14:39 -07005356 mScreenOnFully = true;
5357
5358 // Remember the first time we draw the keyguard so we know when we're done with
5359 // the main part of booting and can enable the screen and hide boot messages.
5360 if (!mKeyguardDrawnOnce && mAwake) {
5361 mKeyguardDrawnOnce = true;
5362 enableScreen = true;
5363 if (mBootMessageNeedsHiding) {
5364 mBootMessageNeedsHiding = false;
5365 hideBootMessages();
5366 }
5367 } else {
5368 enableScreen = false;
5369 }
Jeff Brownc38c9be2012-10-04 13:16:19 -07005370 }
5371
Jeff Brown3ee549c2014-09-22 20:14:39 -07005372 if (listener != null) {
5373 listener.onScreenOn();
5374 }
Jeff Brown4fc45272012-10-10 18:28:14 -07005375
Jeff Brown3ee549c2014-09-22 20:14:39 -07005376 if (enableScreen) {
5377 try {
5378 mWindowManager.enableScreenIfNeeded();
5379 } catch (RemoteException unhandled) {
Jeff Brown36c4db82014-09-19 12:05:31 -07005380 }
Craig Mautnera631d492014-08-05 15:16:01 -07005381 }
5382 }
5383
5384 private void handleHideBootMessage() {
Jeff Brown3ee549c2014-09-22 20:14:39 -07005385 synchronized (mLock) {
5386 if (!mKeyguardDrawnOnce) {
5387 mBootMessageNeedsHiding = true;
5388 return; // keyguard hasn't drawn the first time yet, not done booting
5389 }
Craig Mautnera631d492014-08-05 15:16:01 -07005390 }
Jeff Brown3ee549c2014-09-22 20:14:39 -07005391
5392 if (mBootMsgDialog != null) {
5393 if (DEBUG_WAKEUP) Slog.d(TAG, "handleHideBootMessage: dismissing");
5394 mBootMsgDialog.dismiss();
5395 mBootMsgDialog = null;
Craig Mautnera631d492014-08-05 15:16:01 -07005396 }
Jeff Brownc38c9be2012-10-04 13:16:19 -07005397 }
5398
5399 @Override
Jeff Brown3ee549c2014-09-22 20:14:39 -07005400 public boolean isScreenOn() {
5401 return mScreenOnFully;
Dianne Hackborn08743722009-12-21 12:16:51 -08005402 }
Jeff Brownc38c9be2012-10-04 13:16:19 -07005403
Dianne Hackborn08743722009-12-21 12:16:51 -08005404 /** {@inheritDoc} */
Jose Lima9546b202014-07-02 17:21:51 -07005405 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005406 public void enableKeyguard(boolean enabled) {
Jim Miller5ecd8112013-01-09 18:50:26 -08005407 if (mKeyguardDelegate != null) {
5408 mKeyguardDelegate.setKeyguardEnabled(enabled);
Mike Lockwood3a74bd32011-08-12 13:55:22 -07005409 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005410 }
5411
5412 /** {@inheritDoc} */
Jose Lima9546b202014-07-02 17:21:51 -07005413 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005414 public void exitKeyguardSecurely(OnKeyguardExitResult callback) {
Jim Miller5ecd8112013-01-09 18:50:26 -08005415 if (mKeyguardDelegate != null) {
5416 mKeyguardDelegate.verifyUnlock(callback);
Mike Lockwood3a74bd32011-08-12 13:55:22 -07005417 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005418 }
5419
Jim Millerab954542014-10-10 18:21:49 -07005420 private boolean isKeyguardShowingAndNotOccluded() {
Jim Miller5ecd8112013-01-09 18:50:26 -08005421 if (mKeyguardDelegate == null) return false;
Jim Millerab954542014-10-10 18:21:49 -07005422 return mKeyguardDelegate.isShowing() && !mKeyguardOccluded;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005423 }
5424
Mike Lockwood520d8bc2011-02-18 13:23:13 -05005425 /** {@inheritDoc} */
Jose Lima9546b202014-07-02 17:21:51 -07005426 @Override
Mike Lockwood520d8bc2011-02-18 13:23:13 -05005427 public boolean isKeyguardLocked() {
5428 return keyguardOn();
5429 }
5430
5431 /** {@inheritDoc} */
Jose Lima9546b202014-07-02 17:21:51 -07005432 @Override
Mike Lockwood520d8bc2011-02-18 13:23:13 -05005433 public boolean isKeyguardSecure() {
Jim Miller5ecd8112013-01-09 18:50:26 -08005434 if (mKeyguardDelegate == null) return false;
5435 return mKeyguardDelegate.isSecure();
Mike Lockwood520d8bc2011-02-18 13:23:13 -05005436 }
5437
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005438 /** {@inheritDoc} */
Jose Lima9546b202014-07-02 17:21:51 -07005439 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005440 public boolean inKeyguardRestrictedKeyInputMode() {
Jim Miller5ecd8112013-01-09 18:50:26 -08005441 if (mKeyguardDelegate == null) return false;
5442 return mKeyguardDelegate.isInputRestricted();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005443 }
5444
Jose Lima9546b202014-07-02 17:21:51 -07005445 @Override
Dianne Hackborn90c52de2011-09-23 12:57:44 -07005446 public void dismissKeyguardLw() {
RoboErik8a2cfc32014-05-16 11:19:38 -07005447 if (mKeyguardDelegate != null && mKeyguardDelegate.isShowing()) {
Craig Mautnerc0d2d0a2014-10-31 16:25:15 -07005448 if (DEBUG_KEYGUARD) Slog.d(TAG, "PWM.dismissKeyguardLw");
Daniel Sandler1ce804392012-11-07 15:07:12 -05005449 mHandler.post(new Runnable() {
Jose Lima9546b202014-07-02 17:21:51 -07005450 @Override
Daniel Sandler1ce804392012-11-07 15:07:12 -05005451 public void run() {
Jorim Jaggi8de4311c2014-08-11 22:36:20 +02005452 // ask the keyguard to prompt the user to authenticate if necessary
5453 mKeyguardDelegate.dismiss();
5454 }
5455 });
5456 }
5457 }
5458
5459 public void notifyActivityDrawnForKeyguardLw() {
5460 if (mKeyguardDelegate != null) {
5461 mHandler.post(new Runnable() {
5462 @Override
5463 public void run() {
5464 mKeyguardDelegate.onActivityDrawn();
Daniel Sandler1ce804392012-11-07 15:07:12 -05005465 }
5466 });
Dianne Hackborn90c52de2011-09-23 12:57:44 -07005467 }
5468 }
5469
Jorim Jaggicff0acb2014-03-31 16:35:15 +02005470 @Override
5471 public boolean isKeyguardDrawnLw() {
5472 synchronized (mLock) {
Jeff Brown3ee549c2014-09-22 20:14:39 -07005473 return mKeyguardDrawnOnce;
Jorim Jaggicff0acb2014-03-31 16:35:15 +02005474 }
5475 }
5476
Jorim Jaggi0d674622014-05-21 01:34:15 +02005477 @Override
Jorim Jaggie29b2db2014-05-30 23:17:03 +02005478 public void startKeyguardExitAnimation(long startTime, long fadeoutDuration) {
Jorim Jaggi0d674622014-05-21 01:34:15 +02005479 if (mKeyguardDelegate != null) {
Craig Mautnerc0d2d0a2014-10-31 16:25:15 -07005480 if (DEBUG_KEYGUARD) Slog.d(TAG, "PWM.startKeyguardExitAnimation");
Jorim Jaggie29b2db2014-05-30 23:17:03 +02005481 mKeyguardDelegate.startKeyguardExitAnimation(startTime, fadeoutDuration);
Jorim Jaggi0d674622014-05-21 01:34:15 +02005482 }
5483 }
5484
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005485 void sendCloseSystemWindows() {
Jorim Jaggib10e33f2015-02-04 21:57:40 +01005486 PhoneWindow.sendCloseSystemWindows(mContext, null);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005487 }
5488
5489 void sendCloseSystemWindows(String reason) {
Jorim Jaggib10e33f2015-02-04 21:57:40 +01005490 PhoneWindow.sendCloseSystemWindows(mContext, reason);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005491 }
Mitsuru Oshima831d0d92009-06-16 18:27:18 -07005492
Jeff Brown01a98dd2011-09-20 15:08:29 -07005493 @Override
5494 public int rotationForOrientationLw(int orientation, int lastRotation) {
Daniel Sandler2ed6ad62011-02-22 14:54:17 -05005495 if (false) {
5496 Slog.v(TAG, "rotationForOrientationLw(orient="
5497 + orientation + ", last=" + lastRotation
5498 + "); user=" + mUserRotation + " "
5499 + ((mUserRotationMode == WindowManagerPolicy.USER_ROTATION_LOCKED)
5500 ? "USER_ROTATION_LOCKED" : "")
5501 );
5502 }
5503
Craig Mautner46ac6fa2013-08-01 10:06:34 -07005504 if (mForceDefaultOrientation) {
5505 return Surface.ROTATION_0;
5506 }
5507
The Android Open Source Project0727d222009-03-11 12:11:58 -07005508 synchronized (mLock) {
Jeff Brownc0347aa2011-09-23 17:26:09 -07005509 int sensorRotation = mOrientationListener.getProposedRotation(); // may be -1
5510 if (sensorRotation < 0) {
Jeff Brown0f862b42012-09-27 21:11:01 -07005511 sensorRotation = lastRotation;
Jeff Brownc0347aa2011-09-23 17:26:09 -07005512 }
Jeff Brown01a98dd2011-09-20 15:08:29 -07005513
Jeff Browndec6cf42011-11-15 14:08:20 -08005514 final int preferredRotation;
Jeff Brown2e7760e2012-04-11 15:14:55 -07005515 if (mLidState == LID_OPEN && mLidOpenRotation >= 0) {
Jeff Brown01a98dd2011-09-20 15:08:29 -07005516 // Ignore sensor when lid switch is open and rotation is forced.
5517 preferredRotation = mLidOpenRotation;
5518 } else if (mDockMode == Intent.EXTRA_DOCK_STATE_CAR
Jeff Brownc0347aa2011-09-23 17:26:09 -07005519 && (mCarDockEnablesAccelerometer || mCarDockRotation >= 0)) {
Jeff Brown01a98dd2011-09-20 15:08:29 -07005520 // Ignore sensor when in car dock unless explicitly enabled.
5521 // This case can override the behavior of NOSENSOR, and can also
5522 // enable 180 degree rotation while docked.
Jeff Brownc0347aa2011-09-23 17:26:09 -07005523 preferredRotation = mCarDockEnablesAccelerometer
Jeff Brown01a98dd2011-09-20 15:08:29 -07005524 ? sensorRotation : mCarDockRotation;
Jeff Brown1a693182011-11-08 14:44:16 -08005525 } else if ((mDockMode == Intent.EXTRA_DOCK_STATE_DESK
5526 || mDockMode == Intent.EXTRA_DOCK_STATE_LE_DESK
5527 || mDockMode == Intent.EXTRA_DOCK_STATE_HE_DESK)
Jeff Brownc0347aa2011-09-23 17:26:09 -07005528 && (mDeskDockEnablesAccelerometer || mDeskDockRotation >= 0)) {
Jeff Brown01a98dd2011-09-20 15:08:29 -07005529 // Ignore sensor when in desk dock unless explicitly enabled.
5530 // This case can override the behavior of NOSENSOR, and can also
5531 // enable 180 degree rotation while docked.
Jeff Brownc0347aa2011-09-23 17:26:09 -07005532 preferredRotation = mDeskDockEnablesAccelerometer
Jeff Brown01a98dd2011-09-20 15:08:29 -07005533 ? sensorRotation : mDeskDockRotation;
Jeff Brownc82c89ed2013-04-17 17:18:15 -07005534 } else if (mHdmiPlugged && mDemoHdmiRotationLock) {
5535 // Ignore sensor when plugged into HDMI when demo HDMI rotation lock enabled.
Jeff Browneb3e4b92011-12-06 19:54:24 -08005536 // Note that the dock orientation overrides the HDMI orientation.
Jeff Brownc82c89ed2013-04-17 17:18:15 -07005537 preferredRotation = mDemoHdmiRotation;
5538 } else if (mHdmiPlugged && mDockMode == Intent.EXTRA_DOCK_STATE_UNDOCKED
5539 && mUndockedHdmiRotation >= 0) {
5540 // Ignore sensor when plugged into HDMI and an undocked orientation has
5541 // been specified in the configuration (only for legacy devices without
5542 // full multi-display support).
5543 // Note that the dock orientation overrides the HDMI orientation.
5544 preferredRotation = mUndockedHdmiRotation;
Chong Zhangae6119ff2014-11-11 18:54:39 -08005545 } else if (mDemoRotationLock) {
5546 // Ignore sensor when demo rotation lock is enabled.
5547 // Note that the dock orientation and HDMI rotation lock override this.
5548 preferredRotation = mDemoRotation;
Dianne Hackbornb9ec1ac2013-04-10 17:34:25 -07005549 } else if (orientation == ActivityInfo.SCREEN_ORIENTATION_LOCKED) {
5550 // Application just wants to remain locked in the last rotation.
5551 preferredRotation = lastRotation;
Jeff Brownbcdfc622014-03-06 19:13:04 -08005552 } else if (!mSupportAutoRotation) {
5553 // If we don't support auto-rotation then bail out here and ignore
5554 // the sensor and any rotation lock settings.
5555 preferredRotation = -1;
Jeff Brown207673cd2012-06-05 17:47:11 -07005556 } else if ((mUserRotationMode == WindowManagerPolicy.USER_ROTATION_FREE
Jeff Brown01a98dd2011-09-20 15:08:29 -07005557 && (orientation == ActivityInfo.SCREEN_ORIENTATION_USER
Dianne Hackbornb9ec1ac2013-04-10 17:34:25 -07005558 || orientation == ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED
5559 || orientation == ActivityInfo.SCREEN_ORIENTATION_USER_LANDSCAPE
5560 || orientation == ActivityInfo.SCREEN_ORIENTATION_USER_PORTRAIT
5561 || orientation == ActivityInfo.SCREEN_ORIENTATION_FULL_USER))
Jeff Brown01a98dd2011-09-20 15:08:29 -07005562 || orientation == ActivityInfo.SCREEN_ORIENTATION_SENSOR
5563 || orientation == ActivityInfo.SCREEN_ORIENTATION_FULL_SENSOR
5564 || orientation == ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE
5565 || orientation == ActivityInfo.SCREEN_ORIENTATION_SENSOR_PORTRAIT) {
5566 // Otherwise, use sensor only if requested by the application or enabled
5567 // by default for USER or UNSPECIFIED modes. Does not apply to NOSENSOR.
Jeff Brownd3187e32011-09-21 19:26:44 -07005568 if (mAllowAllRotations < 0) {
5569 // Can't read this during init() because the context doesn't
5570 // have display metrics at that time so we cannot determine
5571 // tablet vs. phone then.
5572 mAllowAllRotations = mContext.getResources().getBoolean(
5573 com.android.internal.R.bool.config_allowAllRotations) ? 1 : 0;
5574 }
Jeff Brown01a98dd2011-09-20 15:08:29 -07005575 if (sensorRotation != Surface.ROTATION_180
Jeff Brownd3187e32011-09-21 19:26:44 -07005576 || mAllowAllRotations == 1
Dianne Hackbornb9ec1ac2013-04-10 17:34:25 -07005577 || orientation == ActivityInfo.SCREEN_ORIENTATION_FULL_SENSOR
5578 || orientation == ActivityInfo.SCREEN_ORIENTATION_FULL_USER) {
Jeff Brown01a98dd2011-09-20 15:08:29 -07005579 preferredRotation = sensorRotation;
5580 } else {
5581 preferredRotation = lastRotation;
5582 }
Jeff Brown207673cd2012-06-05 17:47:11 -07005583 } else if (mUserRotationMode == WindowManagerPolicy.USER_ROTATION_LOCKED
5584 && orientation != ActivityInfo.SCREEN_ORIENTATION_NOSENSOR) {
5585 // Apply rotation lock. Does not apply to NOSENSOR.
5586 // The idea is that the user rotation expresses a weak preference for the direction
5587 // of gravity and as NOSENSOR is never affected by gravity, then neither should
5588 // NOSENSOR be affected by rotation lock (although it will be affected by docks).
Jeff Brown4dfce202011-10-05 12:00:10 -07005589 preferredRotation = mUserRotation;
Jeff Browndec6cf42011-11-15 14:08:20 -08005590 } else {
5591 // No overriding preference.
5592 // We will do exactly what the application asked us to do.
5593 preferredRotation = -1;
Jeff Brown01a98dd2011-09-20 15:08:29 -07005594 }
5595
Dianne Hackborne5439f22010-10-02 16:53:50 -07005596 switch (orientation) {
5597 case ActivityInfo.SCREEN_ORIENTATION_PORTRAIT:
Jeff Browndec6cf42011-11-15 14:08:20 -08005598 // Return portrait unless overridden.
5599 if (isAnyPortrait(preferredRotation)) {
5600 return preferredRotation;
5601 }
Dianne Hackborne5439f22010-10-02 16:53:50 -07005602 return mPortraitRotation;
Dianne Hackborne5439f22010-10-02 16:53:50 -07005603
Jeff Brown01a98dd2011-09-20 15:08:29 -07005604 case ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE:
Jeff Browndec6cf42011-11-15 14:08:20 -08005605 // Return landscape unless overridden.
5606 if (isLandscapeOrSeascape(preferredRotation)) {
5607 return preferredRotation;
5608 }
Jeff Brown01a98dd2011-09-20 15:08:29 -07005609 return mLandscapeRotation;
5610
5611 case ActivityInfo.SCREEN_ORIENTATION_REVERSE_PORTRAIT:
Jeff Browndec6cf42011-11-15 14:08:20 -08005612 // Return reverse portrait unless overridden.
5613 if (isAnyPortrait(preferredRotation)) {
5614 return preferredRotation;
5615 }
Jeff Brown01a98dd2011-09-20 15:08:29 -07005616 return mUpsideDownRotation;
5617
5618 case ActivityInfo.SCREEN_ORIENTATION_REVERSE_LANDSCAPE:
Jeff Browndec6cf42011-11-15 14:08:20 -08005619 // Return seascape unless overridden.
5620 if (isLandscapeOrSeascape(preferredRotation)) {
5621 return preferredRotation;
5622 }
Jeff Brown01a98dd2011-09-20 15:08:29 -07005623 return mSeascapeRotation;
5624
5625 case ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE:
Dianne Hackbornb9ec1ac2013-04-10 17:34:25 -07005626 case ActivityInfo.SCREEN_ORIENTATION_USER_LANDSCAPE:
Jeff Brown01a98dd2011-09-20 15:08:29 -07005627 // Return either landscape rotation.
5628 if (isLandscapeOrSeascape(preferredRotation)) {
5629 return preferredRotation;
5630 }
5631 if (isLandscapeOrSeascape(lastRotation)) {
Jeff Brown4519f072011-01-23 13:16:01 -08005632 return lastRotation;
5633 }
Jeff Brown01a98dd2011-09-20 15:08:29 -07005634 return mLandscapeRotation;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005635
Jeff Brown01a98dd2011-09-20 15:08:29 -07005636 case ActivityInfo.SCREEN_ORIENTATION_SENSOR_PORTRAIT:
Dianne Hackbornb9ec1ac2013-04-10 17:34:25 -07005637 case ActivityInfo.SCREEN_ORIENTATION_USER_PORTRAIT:
Jeff Brown01a98dd2011-09-20 15:08:29 -07005638 // Return either portrait rotation.
5639 if (isAnyPortrait(preferredRotation)) {
5640 return preferredRotation;
5641 }
5642 if (isAnyPortrait(lastRotation)) {
5643 return lastRotation;
5644 }
5645 return mPortraitRotation;
5646
5647 default:
Jeff Brown4dfce202011-10-05 12:00:10 -07005648 // For USER, UNSPECIFIED, NOSENSOR, SENSOR and FULL_SENSOR,
5649 // just return the preferred orientation we already calculated.
Jeff Brown01a98dd2011-09-20 15:08:29 -07005650 if (preferredRotation >= 0) {
5651 return preferredRotation;
5652 }
Dianne Hackborndacea8c2011-04-21 17:26:39 -07005653 return Surface.ROTATION_0;
Daniel Sandlere7e5ac22011-02-22 16:10:21 -05005654 }
5655 }
Steve Howarda7bfe6a2010-09-23 16:47:49 -07005656 }
5657
Jeff Brown01a98dd2011-09-20 15:08:29 -07005658 @Override
5659 public boolean rotationHasCompatibleMetricsLw(int orientation, int rotation) {
5660 switch (orientation) {
5661 case ActivityInfo.SCREEN_ORIENTATION_PORTRAIT:
5662 case ActivityInfo.SCREEN_ORIENTATION_REVERSE_PORTRAIT:
5663 case ActivityInfo.SCREEN_ORIENTATION_SENSOR_PORTRAIT:
5664 return isAnyPortrait(rotation);
5665
5666 case ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE:
5667 case ActivityInfo.SCREEN_ORIENTATION_REVERSE_LANDSCAPE:
5668 case ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE:
5669 return isLandscapeOrSeascape(rotation);
5670
5671 default:
5672 return true;
5673 }
Steve Howarda7bfe6a2010-09-23 16:47:49 -07005674 }
5675
Jeff Brownc0347aa2011-09-23 17:26:09 -07005676 @Override
5677 public void setRotationLw(int rotation) {
5678 mOrientationListener.setCurrentRotation(rotation);
5679 }
5680
Jeff Brown01a98dd2011-09-20 15:08:29 -07005681 private boolean isLandscapeOrSeascape(int rotation) {
5682 return rotation == mLandscapeRotation || rotation == mSeascapeRotation;
Dianne Hackborne5439f22010-10-02 16:53:50 -07005683 }
5684
Jeff Brown01a98dd2011-09-20 15:08:29 -07005685 private boolean isAnyPortrait(int rotation) {
5686 return rotation == mPortraitRotation || rotation == mUpsideDownRotation;
Dianne Hackborne5439f22010-10-02 16:53:50 -07005687 }
5688
Jose Lima9546b202014-07-02 17:21:51 -07005689 @Override
Svetoslav Ganov80943d82013-01-02 10:25:37 -08005690 public int getUserRotationMode() {
5691 return Settings.System.getIntForUser(mContext.getContentResolver(),
Brett Chabot7e55c402013-05-16 19:38:08 -07005692 Settings.System.ACCELEROMETER_ROTATION, 0, UserHandle.USER_CURRENT) != 0 ?
5693 WindowManagerPolicy.USER_ROTATION_FREE :
5694 WindowManagerPolicy.USER_ROTATION_LOCKED;
Svetoslav Ganov80943d82013-01-02 10:25:37 -08005695 }
Daniel Sandlerb73617d2010-08-17 00:41:00 -04005696
5697 // User rotation: to be used when all else fails in assigning an orientation to the device
Jose Lima9546b202014-07-02 17:21:51 -07005698 @Override
Daniel Sandlerb73617d2010-08-17 00:41:00 -04005699 public void setUserRotationMode(int mode, int rot) {
5700 ContentResolver res = mContext.getContentResolver();
Daniel Sandler2ed6ad62011-02-22 14:54:17 -05005701
5702 // mUserRotationMode and mUserRotation will be assigned by the content observer
Daniel Sandlerb73617d2010-08-17 00:41:00 -04005703 if (mode == WindowManagerPolicy.USER_ROTATION_LOCKED) {
Christopher Tate5e08af02012-09-21 17:17:22 -07005704 Settings.System.putIntForUser(res,
Daniel Sandlerb73617d2010-08-17 00:41:00 -04005705 Settings.System.USER_ROTATION,
Christopher Tate5e08af02012-09-21 17:17:22 -07005706 rot,
5707 UserHandle.USER_CURRENT);
5708 Settings.System.putIntForUser(res,
Daniel Sandler2ed6ad62011-02-22 14:54:17 -05005709 Settings.System.ACCELEROMETER_ROTATION,
Christopher Tate5e08af02012-09-21 17:17:22 -07005710 0,
5711 UserHandle.USER_CURRENT);
Daniel Sandlerb73617d2010-08-17 00:41:00 -04005712 } else {
Christopher Tate5e08af02012-09-21 17:17:22 -07005713 Settings.System.putIntForUser(res,
Daniel Sandlerb73617d2010-08-17 00:41:00 -04005714 Settings.System.ACCELEROMETER_ROTATION,
Christopher Tate5e08af02012-09-21 17:17:22 -07005715 1,
5716 UserHandle.USER_CURRENT);
Daniel Sandlerb73617d2010-08-17 00:41:00 -04005717 }
5718 }
5719
Jose Lima9546b202014-07-02 17:21:51 -07005720 @Override
Jeff Brownac143512012-04-05 18:57:33 -07005721 public void setSafeMode(boolean safeMode) {
5722 mSafeMode = safeMode;
5723 performHapticFeedbackLw(null, safeMode
5724 ? HapticFeedbackConstants.SAFE_MODE_ENABLED
5725 : HapticFeedbackConstants.SAFE_MODE_DISABLED, true);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005726 }
Craig Mautnereda67292013-04-28 13:50:14 -07005727
Dianne Hackborn181ceb52009-08-27 22:16:40 -07005728 static long[] getLongIntArray(Resources r, int resid) {
5729 int[] ar = r.getIntArray(resid);
5730 if (ar == null) {
5731 return null;
5732 }
5733 long[] out = new long[ar.length];
5734 for (int i=0; i<ar.length; i++) {
5735 out[i] = ar[i];
5736 }
5737 return out;
5738 }
Craig Mautnereda67292013-04-28 13:50:14 -07005739
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005740 /** {@inheritDoc} */
Craig Mautnereda67292013-04-28 13:50:14 -07005741 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005742 public void systemReady() {
Jim Millerab954542014-10-10 18:21:49 -07005743 mKeyguardDelegate = new KeyguardServiceDelegate(mContext);
Mike Lockwooded8902d2013-11-15 11:01:47 -08005744 mKeyguardDelegate.onSystemReady();
5745
Michael Wright3818c922014-09-02 13:59:07 -07005746 readCameraLensCoverState();
Jeff Brown4f5fa282014-06-12 19:19:15 -07005747 updateUiMode();
Dianne Hackbornb1a79802009-09-29 15:18:31 -07005748 synchronized (mLock) {
5749 updateOrientationListenerLp();
Dianne Hackbornc777e072010-02-12 13:07:59 -08005750 mSystemReady = true;
5751 mHandler.post(new Runnable() {
Craig Mautnereda67292013-04-28 13:50:14 -07005752 @Override
Dianne Hackbornc777e072010-02-12 13:07:59 -08005753 public void run() {
5754 updateSettings();
5755 }
5756 });
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005757 }
5758 }
Dianne Hackborn661cd522011-08-22 00:26:20 -07005759
Dianne Hackbornba24e4d2011-09-01 11:17:06 -07005760 /** {@inheritDoc} */
Jose Lima9546b202014-07-02 17:21:51 -07005761 @Override
Dianne Hackbornba24e4d2011-09-01 11:17:06 -07005762 public void systemBooted() {
Jim Millere5f910a2013-10-16 18:15:46 -07005763 if (mKeyguardDelegate != null) {
Jason Monk5eeebf52014-09-26 12:36:51 -04005764 mKeyguardDelegate.bindService(mContext);
Jim Millere5f910a2013-10-16 18:15:46 -07005765 mKeyguardDelegate.onBootCompleted();
5766 }
Dianne Hackbornba24e4d2011-09-01 11:17:06 -07005767 synchronized (mLock) {
5768 mSystemBooted = true;
5769 }
Jeff Brown36c4db82014-09-19 12:05:31 -07005770 wakingUp();
5771 screenTurningOn(null);
Dianne Hackbornba24e4d2011-09-01 11:17:06 -07005772 }
5773
Dianne Hackborn661cd522011-08-22 00:26:20 -07005774 ProgressDialog mBootMsgDialog = null;
5775
5776 /** {@inheritDoc} */
Jose Lima9546b202014-07-02 17:21:51 -07005777 @Override
Dianne Hackborn661cd522011-08-22 00:26:20 -07005778 public void showBootMessage(final CharSequence msg, final boolean always) {
5779 mHandler.post(new Runnable() {
5780 @Override public void run() {
5781 if (mBootMsgDialog == null) {
Craig Stout4c0cb8a2014-04-04 13:03:10 -07005782 int theme;
5783 if (mContext.getPackageManager().hasSystemFeature(
5784 PackageManager.FEATURE_WATCH)) {
5785 theme = com.android.internal.R.style.Theme_Micro_Dialog_Alert;
5786 } else if (mContext.getPackageManager().hasSystemFeature(
5787 PackageManager.FEATURE_TELEVISION)) {
5788 theme = com.android.internal.R.style.Theme_Leanback_Dialog_Alert;
5789 } else {
5790 theme = 0;
5791 }
Vinod Krishnanfa8fc412014-04-18 14:35:53 -07005792
5793 mBootMsgDialog = new ProgressDialog(mContext, theme) {
Dianne Hackborn295e3c22011-08-25 13:19:08 -07005794 // This dialog will consume all events coming in to
5795 // it, to avoid it trying to do things too early in boot.
5796 @Override public boolean dispatchKeyEvent(KeyEvent event) {
5797 return true;
5798 }
5799 @Override public boolean dispatchKeyShortcutEvent(KeyEvent event) {
5800 return true;
5801 }
5802 @Override public boolean dispatchTouchEvent(MotionEvent ev) {
5803 return true;
5804 }
5805 @Override public boolean dispatchTrackballEvent(MotionEvent ev) {
5806 return true;
5807 }
5808 @Override public boolean dispatchGenericMotionEvent(MotionEvent ev) {
5809 return true;
5810 }
5811 @Override public boolean dispatchPopulateAccessibilityEvent(
5812 AccessibilityEvent event) {
5813 return true;
5814 }
5815 };
Jeff Hao9f60c082014-10-28 18:51:07 -07005816 if (mContext.getPackageManager().isUpgrade()) {
5817 mBootMsgDialog.setTitle(R.string.android_upgrading_title);
5818 } else {
5819 mBootMsgDialog.setTitle(R.string.android_start_title);
5820 }
Dianne Hackborn661cd522011-08-22 00:26:20 -07005821 mBootMsgDialog.setProgressStyle(ProgressDialog.STYLE_SPINNER);
5822 mBootMsgDialog.setIndeterminate(true);
5823 mBootMsgDialog.getWindow().setType(
Dianne Hackborn29aae6f2011-08-18 18:30:09 -07005824 WindowManager.LayoutParams.TYPE_BOOT_PROGRESS);
Dianne Hackborn661cd522011-08-22 00:26:20 -07005825 mBootMsgDialog.getWindow().addFlags(
5826 WindowManager.LayoutParams.FLAG_DIM_BEHIND
5827 | WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN);
5828 mBootMsgDialog.getWindow().setDimAmount(1);
Dianne Hackbornd9efb952011-12-07 14:56:51 -08005829 WindowManager.LayoutParams lp = mBootMsgDialog.getWindow().getAttributes();
5830 lp.screenOrientation = ActivityInfo.SCREEN_ORIENTATION_NOSENSOR;
5831 mBootMsgDialog.getWindow().setAttributes(lp);
Dianne Hackborn661cd522011-08-22 00:26:20 -07005832 mBootMsgDialog.setCancelable(false);
5833 mBootMsgDialog.show();
5834 }
5835 mBootMsgDialog.setMessage(msg);
5836 }
5837 });
5838 }
5839
5840 /** {@inheritDoc} */
Jose Lima9546b202014-07-02 17:21:51 -07005841 @Override
Dianne Hackborn661cd522011-08-22 00:26:20 -07005842 public void hideBootMessages() {
Craig Mautnera631d492014-08-05 15:16:01 -07005843 mHandler.sendEmptyMessage(MSG_HIDE_BOOT_MESSAGE);
Dianne Hackborn661cd522011-08-22 00:26:20 -07005844 }
5845
Mike Lockwood28569302010-01-28 11:54:40 -05005846 /** {@inheritDoc} */
Jose Lima9546b202014-07-02 17:21:51 -07005847 @Override
Mike Lockwood28569302010-01-28 11:54:40 -05005848 public void userActivity() {
Dianne Hackborndf89e652011-10-06 22:35:11 -07005849 // ***************************************
5850 // NOTE NOTE NOTE NOTE NOTE NOTE NOTE NOTE
5851 // ***************************************
5852 // THIS IS CALLED FROM DEEP IN THE POWER MANAGER
5853 // WITH ITS LOCKS HELD.
5854 //
5855 // This code must be VERY careful about the locks
5856 // it acquires.
5857 // In fact, the current code acquires way too many,
5858 // and probably has lurking deadlocks.
5859
Mike Lockwood28569302010-01-28 11:54:40 -05005860 synchronized (mScreenLockTimeout) {
5861 if (mLockScreenTimerActive) {
5862 // reset the timer
5863 mHandler.removeCallbacks(mScreenLockTimeout);
5864 mHandler.postDelayed(mScreenLockTimeout, mLockScreenTimeout);
5865 }
5866 }
Daniel Sandler0601eb72011-04-13 01:01:32 -04005867 }
5868
Adam Cohenf7522022012-10-03 20:03:18 -07005869 class ScreenLockTimeout implements Runnable {
5870 Bundle options;
5871
5872 @Override
Mike Lockwood28569302010-01-28 11:54:40 -05005873 public void run() {
5874 synchronized (this) {
5875 if (localLOGV) Log.v(TAG, "mScreenLockTimeout activating keyguard");
Jim Miller5ecd8112013-01-09 18:50:26 -08005876 if (mKeyguardDelegate != null) {
5877 mKeyguardDelegate.doKeyguardTimeout(options);
Mike Lockwood3a74bd32011-08-12 13:55:22 -07005878 }
Mike Lockwood28569302010-01-28 11:54:40 -05005879 mLockScreenTimerActive = false;
Adam Cohenf7522022012-10-03 20:03:18 -07005880 options = null;
Mike Lockwood28569302010-01-28 11:54:40 -05005881 }
5882 }
Mike Lockwood28569302010-01-28 11:54:40 -05005883
Adam Cohenf7522022012-10-03 20:03:18 -07005884 public void setLockOptions(Bundle options) {
5885 this.options = options;
5886 }
5887 }
5888
5889 ScreenLockTimeout mScreenLockTimeout = new ScreenLockTimeout();
5890
Jose Lima9546b202014-07-02 17:21:51 -07005891 @Override
Adam Cohenf7522022012-10-03 20:03:18 -07005892 public void lockNow(Bundle options) {
Jim Miller93c518e2012-01-17 15:55:31 -08005893 mContext.enforceCallingOrSelfPermission(android.Manifest.permission.DEVICE_POWER, null);
5894 mHandler.removeCallbacks(mScreenLockTimeout);
Adam Cohenf7522022012-10-03 20:03:18 -07005895 if (options != null) {
5896 // In case multiple calls are made to lockNow, we don't wipe out the options
5897 // until the runnable actually executes.
5898 mScreenLockTimeout.setLockOptions(options);
5899 }
Jim Miller93c518e2012-01-17 15:55:31 -08005900 mHandler.post(mScreenLockTimeout);
5901 }
5902
Mike Lockwood28569302010-01-28 11:54:40 -05005903 private void updateLockScreenTimeout() {
5904 synchronized (mScreenLockTimeout) {
Jeff Brown3ee549c2014-09-22 20:14:39 -07005905 boolean enable = (mAllowLockscreenWhenOn && mAwake &&
Jim Miller5ecd8112013-01-09 18:50:26 -08005906 mKeyguardDelegate != null && mKeyguardDelegate.isSecure());
Mike Lockwood28569302010-01-28 11:54:40 -05005907 if (mLockScreenTimerActive != enable) {
5908 if (enable) {
5909 if (localLOGV) Log.v(TAG, "setting lockscreen timer");
5910 mHandler.postDelayed(mScreenLockTimeout, mLockScreenTimeout);
5911 } else {
5912 if (localLOGV) Log.v(TAG, "clearing lockscreen timer");
5913 mHandler.removeCallbacks(mScreenLockTimeout);
5914 }
5915 mLockScreenTimerActive = enable;
5916 }
5917 }
5918 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005919
Jeff Brown061ea992015-04-17 19:55:47 -07005920 private void updateDreamingSleepToken(boolean acquire) {
5921 if (acquire) {
5922 if (mDreamingSleepToken == null) {
5923 mDreamingSleepToken = mActivityManagerInternal.acquireSleepToken("Dream");
5924 }
5925 } else {
5926 if (mDreamingSleepToken != null) {
5927 mDreamingSleepToken.release();
5928 }
5929 }
5930 }
5931
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005932 /** {@inheritDoc} */
Craig Mautnereda67292013-04-28 13:50:14 -07005933 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005934 public void enableScreenAfterBoot() {
5935 readLidState();
Jeff Brownc458ce92012-04-30 14:58:40 -07005936 applyLidSwitchState();
Jeff Brown01a98dd2011-09-20 15:08:29 -07005937 updateRotation(true);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005938 }
Dianne Hackbornf54c8f92009-09-19 14:03:57 -07005939
Jeff Brownc458ce92012-04-30 14:58:40 -07005940 private void applyLidSwitchState() {
Jeff Brownc458ce92012-04-30 14:58:40 -07005941 if (mLidState == LID_CLOSED && mLidControlsSleep) {
Jeff Brown6d8fd272014-05-20 21:24:38 -07005942 mPowerManager.goToSleep(SystemClock.uptimeMillis(),
Jeff Brownc12035c2014-08-13 18:52:25 -07005943 PowerManager.GO_TO_SLEEP_REASON_LID_SWITCH,
Jeff Brown6d8fd272014-05-20 21:24:38 -07005944 PowerManager.GO_TO_SLEEP_FLAG_NO_DOZE);
Jeff Brownc458ce92012-04-30 14:58:40 -07005945 }
Jeff Browna20dda42014-05-27 20:57:24 -07005946
5947 synchronized (mLock) {
5948 updateWakeGestureListenerLp();
5949 }
Jeff Brown01a98dd2011-09-20 15:08:29 -07005950 }
5951
Jeff Brown4f5fa282014-06-12 19:19:15 -07005952 void updateUiMode() {
5953 if (mUiModeManager == null) {
5954 mUiModeManager = IUiModeManager.Stub.asInterface(
5955 ServiceManager.getService(Context.UI_MODE_SERVICE));
5956 }
5957 try {
5958 mUiMode = mUiModeManager.getCurrentModeType();
5959 } catch (RemoteException e) {
5960 }
5961 }
5962
Jeff Brown01a98dd2011-09-20 15:08:29 -07005963 void updateRotation(boolean alwaysSendConfiguration) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005964 try {
5965 //set orientation on WindowManager
Dianne Hackbornf87d1962012-04-04 12:48:24 -07005966 mWindowManager.updateRotation(alwaysSendConfiguration, false);
5967 } catch (RemoteException e) {
5968 // Ignore
5969 }
5970 }
5971
5972 void updateRotation(boolean alwaysSendConfiguration, boolean forceRelayout) {
5973 try {
5974 //set orientation on WindowManager
5975 mWindowManager.updateRotation(alwaysSendConfiguration, forceRelayout);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005976 } catch (RemoteException e) {
5977 // Ignore
5978 }
5979 }
5980
Daniel Sandler6396c722013-04-16 20:19:09 -04005981 /**
5982 * Return an Intent to launch the currently active dock app as home. Returns
5983 * null if the standard home should be launched, which is the case if any of the following is
5984 * true:
5985 * <ul>
5986 * <li>The device is not in either car mode or desk mode
5987 * <li>The device is in car mode but ENABLE_CAR_DOCK_HOME_CAPTURE is false
5988 * <li>The device is in desk mode but ENABLE_DESK_DOCK_HOME_CAPTURE is false
5989 * <li>The device is in car mode but there's no CAR_DOCK app with METADATA_DOCK_HOME
5990 * <li>The device is in desk mode but there's no DESK_DOCK app with METADATA_DOCK_HOME
5991 * </ul>
Craig Mautnereda67292013-04-28 13:50:14 -07005992 * @return A dock intent.
Daniel Sandler6396c722013-04-16 20:19:09 -04005993 */
5994 Intent createHomeDockIntent() {
5995 Intent intent = null;
5996
5997 // What home does is based on the mode, not the dock state. That
5998 // is, when in car mode you should be taken to car home regardless
5999 // of whether we are actually in a car dock.
6000 if (mUiMode == Configuration.UI_MODE_TYPE_CAR) {
6001 if (ENABLE_CAR_DOCK_HOME_CAPTURE) {
6002 intent = mCarDockIntent;
6003 }
6004 } else if (mUiMode == Configuration.UI_MODE_TYPE_DESK) {
6005 if (ENABLE_DESK_DOCK_HOME_CAPTURE) {
6006 intent = mDeskDockIntent;
6007 }
Jeff Brown4f5fa282014-06-12 19:19:15 -07006008 } else if (mUiMode == Configuration.UI_MODE_TYPE_WATCH
6009 && (mDockMode == Intent.EXTRA_DOCK_STATE_DESK
6010 || mDockMode == Intent.EXTRA_DOCK_STATE_HE_DESK
6011 || mDockMode == Intent.EXTRA_DOCK_STATE_LE_DESK)) {
6012 // Always launch dock home from home when watch is docked, if it exists.
6013 intent = mDeskDockIntent;
Daniel Sandler6396c722013-04-16 20:19:09 -04006014 }
6015
6016 if (intent == null) {
6017 return null;
6018 }
6019
6020 ActivityInfo ai = null;
6021 ResolveInfo info = mContext.getPackageManager().resolveActivityAsUser(
6022 intent,
John Spurlockf56bef12013-07-09 09:51:46 -04006023 PackageManager.MATCH_DEFAULT_ONLY | PackageManager.GET_META_DATA,
Craig Mautnerd625ab22013-09-06 13:40:31 -07006024 mCurrentUserId);
Daniel Sandler6396c722013-04-16 20:19:09 -04006025 if (info != null) {
6026 ai = info.activityInfo;
6027 }
6028 if (ai != null
6029 && ai.metaData != null
6030 && ai.metaData.getBoolean(Intent.METADATA_DOCK_HOME)) {
6031 intent = new Intent(intent);
6032 intent.setClassName(ai.packageName, ai.name);
6033 return intent;
6034 }
6035
6036 return null;
6037 }
6038
Filip Gruszczynskia483a1d2015-03-17 19:06:58 +00006039 void startDockOrHome(boolean fromHomeKey, boolean awakenFromDreams) {
6040 if (awakenFromDreams) {
6041 awakenDreams();
6042 }
Daniel Sandler6396c722013-04-16 20:19:09 -04006043
6044 Intent dock = createHomeDockIntent();
6045 if (dock != null) {
6046 try {
Bryce Lee01b0c5f2015-02-05 18:24:04 -08006047 if (fromHomeKey) {
6048 dock.putExtra(WindowManagerPolicy.EXTRA_FROM_HOME_KEY, fromHomeKey);
6049 }
Bart Sears8b1c27c2015-03-18 23:51:02 +00006050 startActivityAsUser(dock, UserHandle.CURRENT);
Daniel Sandler6396c722013-04-16 20:19:09 -04006051 return;
6052 } catch (ActivityNotFoundException e) {
6053 }
6054 }
6055
Bryce Lee01b0c5f2015-02-05 18:24:04 -08006056 Intent intent;
6057
6058 if (fromHomeKey) {
6059 intent = new Intent(mHomeIntent);
6060 intent.putExtra(WindowManagerPolicy.EXTRA_FROM_HOME_KEY, fromHomeKey);
6061 } else {
6062 intent = mHomeIntent;
6063 }
6064
Bryce Lee9fc0b6f2015-03-19 21:37:45 +00006065 startActivityAsUser(intent, UserHandle.CURRENT);
Dianne Hackborn39c2d712009-09-22 11:41:31 -07006066 }
Craig Mautnereda67292013-04-28 13:50:14 -07006067
Dianne Hackborn39c2d712009-09-22 11:41:31 -07006068 /**
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006069 * goes to the home screen
6070 * @return whether it did anything
6071 */
6072 boolean goHome() {
Bart Sears8b1c27c2015-03-18 23:51:02 +00006073 if (!isUserSetupComplete()) {
6074 Slog.i(TAG, "Not going home because user setup is in progress.");
6075 return false;
6076 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006077 if (false) {
6078 // This code always brings home to the front.
Dianne Hackborn256dd3b2009-05-19 18:51:21 -07006079 try {
6080 ActivityManagerNative.getDefault().stopAppSwitches();
6081 } catch (RemoteException e) {
6082 }
Dianne Hackborn94a679d2009-07-28 17:51:07 -07006083 sendCloseSystemWindows();
Filip Gruszczynskia483a1d2015-03-17 19:06:58 +00006084 startDockOrHome(false /*fromHomeKey*/, true /* awakenFromDreams */);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006085 } else {
6086 // This code brings home to the front or, if it is already
6087 // at the front, puts the device to sleep.
6088 try {
Wink Savilled2e6a332010-02-12 12:12:06 -08006089 if (SystemProperties.getInt("persist.sys.uts-test-mode", 0) == 1) {
6090 /// Roll back EndcallBehavior as the cupcake design to pass P1 lab entry.
6091 Log.d(TAG, "UTS-TEST-MODE");
6092 } else {
6093 ActivityManagerNative.getDefault().stopAppSwitches();
6094 sendCloseSystemWindows();
Daniel Sandler6396c722013-04-16 20:19:09 -04006095 Intent dock = createHomeDockIntent();
6096 if (dock != null) {
6097 int result = ActivityManagerNative.getDefault()
6098 .startActivityAsUser(null, null, dock,
6099 dock.resolveTypeIfNeeded(mContext.getContentResolver()),
6100 null, null, 0,
6101 ActivityManager.START_FLAG_ONLY_IF_NEEDED,
Jeff Hao1b012d32014-08-20 10:35:34 -07006102 null, null, UserHandle.USER_CURRENT);
Daniel Sandler6396c722013-04-16 20:19:09 -04006103 if (result == ActivityManager.START_RETURN_INTENT_TO_CALLER) {
6104 return false;
6105 }
6106 }
Dianne Hackborn39c2d712009-09-22 11:41:31 -07006107 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006108 int result = ActivityManagerNative.getDefault()
Dianne Hackbornf265ea92013-01-31 15:00:51 -08006109 .startActivityAsUser(null, null, mHomeIntent,
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006110 mHomeIntent.resolveTypeIfNeeded(mContext.getContentResolver()),
Dianne Hackborna4972e92012-03-14 10:38:05 -07006111 null, null, 0,
6112 ActivityManager.START_FLAG_ONLY_IF_NEEDED,
Jeff Hao1b012d32014-08-20 10:35:34 -07006113 null, null, UserHandle.USER_CURRENT);
Dianne Hackborna4972e92012-03-14 10:38:05 -07006114 if (result == ActivityManager.START_RETURN_INTENT_TO_CALLER) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006115 return false;
6116 }
6117 } catch (RemoteException ex) {
6118 // bummer, the activity manager, which is in this process, is dead
6119 }
6120 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006121 return true;
6122 }
Craig Mautnereda67292013-04-28 13:50:14 -07006123
6124 @Override
The Android Open Source Project0727d222009-03-11 12:11:58 -07006125 public void setCurrentOrientationLw(int newOrientation) {
6126 synchronized (mLock) {
6127 if (newOrientation != mCurrentAppOrientation) {
6128 mCurrentAppOrientation = newOrientation;
6129 updateOrientationListenerLp();
6130 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006131 }
6132 }
Amith Yamasanic33cb712010-02-10 15:21:49 -08006133
Svetoslav Ganov7befb7d2012-09-27 16:49:23 -07006134 private void performAuditoryFeedbackForAccessibilityIfNeed() {
6135 if (!isGlobalAccessibilityGestureEnabled()) {
6136 return;
6137 }
6138 AudioManager audioManager = (AudioManager) mContext.getSystemService(
6139 Context.AUDIO_SERVICE);
6140 if (audioManager.isSilentMode()) {
6141 return;
6142 }
6143 Ringtone ringTone = RingtoneManager.getRingtone(mContext,
6144 Settings.System.DEFAULT_NOTIFICATION_URI);
6145 ringTone.setStreamType(AudioManager.STREAM_MUSIC);
6146 ringTone.play();
6147 }
Craig Mautnereda67292013-04-28 13:50:14 -07006148
Bryce Lee584a4452014-10-21 15:55:55 -07006149 private boolean isTheaterModeEnabled() {
6150 return Settings.Global.getInt(mContext.getContentResolver(),
6151 Settings.Global.THEATER_MODE_ON, 0) == 1;
6152 }
6153
Svetoslav Ganov7befb7d2012-09-27 16:49:23 -07006154 private boolean isGlobalAccessibilityGestureEnabled() {
6155 return Settings.Global.getInt(mContext.getContentResolver(),
6156 Settings.Global.ENABLE_ACCESSIBILITY_GLOBAL_GESTURE_ENABLED, 0) == 1;
6157 }
6158
Craig Mautnereda67292013-04-28 13:50:14 -07006159 @Override
The Android Open Source Project0727d222009-03-11 12:11:58 -07006160 public boolean performHapticFeedbackLw(WindowState win, int effectId, boolean always) {
Svetoslav Ganov96179212012-10-10 14:17:45 -07006161 if (!mVibrator.hasVibrator()) {
6162 return false;
6163 }
Christopher Tate5e08af02012-09-21 17:17:22 -07006164 final boolean hapticsDisabled = Settings.System.getIntForUser(mContext.getContentResolver(),
6165 Settings.System.HAPTIC_FEEDBACK_ENABLED, 0, UserHandle.USER_CURRENT) == 0;
Jeff Brown82379ba2014-07-25 19:03:28 -07006166 if (hapticsDisabled && !always) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006167 return false;
6168 }
Amith Yamasanic33cb712010-02-10 15:21:49 -08006169 long[] pattern = null;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006170 switch (effectId) {
6171 case HapticFeedbackConstants.LONG_PRESS:
Amith Yamasanic33cb712010-02-10 15:21:49 -08006172 pattern = mLongPressVibePattern;
6173 break;
Dianne Hackbornb1a79802009-09-29 15:18:31 -07006174 case HapticFeedbackConstants.VIRTUAL_KEY:
Amith Yamasanic33cb712010-02-10 15:21:49 -08006175 pattern = mVirtualKeyVibePattern;
6176 break;
6177 case HapticFeedbackConstants.KEYBOARD_TAP:
6178 pattern = mKeyboardTapVibePattern;
6179 break;
Fabrice Di Meglioeeff63a2013-08-05 12:07:24 -07006180 case HapticFeedbackConstants.CLOCK_TICK:
6181 pattern = mClockTickVibePattern;
6182 break;
Fabrice Di Megliobd9152f2013-10-01 11:21:31 -07006183 case HapticFeedbackConstants.CALENDAR_DATE:
6184 pattern = mCalendarDateVibePattern;
6185 break;
Dianne Hackbornb1a79802009-09-29 15:18:31 -07006186 case HapticFeedbackConstants.SAFE_MODE_DISABLED:
Amith Yamasanic33cb712010-02-10 15:21:49 -08006187 pattern = mSafeModeDisabledVibePattern;
6188 break;
Dianne Hackbornb1a79802009-09-29 15:18:31 -07006189 case HapticFeedbackConstants.SAFE_MODE_ENABLED:
Amith Yamasanic33cb712010-02-10 15:21:49 -08006190 pattern = mSafeModeEnabledVibePattern;
6191 break;
Mady Mellore82067b2015-04-30 09:58:35 -07006192 case HapticFeedbackConstants.STYLUS_BUTTON_PRESS:
6193 pattern = mStylusButtonPressVibePattern;
6194 break;
Amith Yamasanic33cb712010-02-10 15:21:49 -08006195 default:
6196 return false;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006197 }
Dianne Hackbornf265ea92013-01-31 15:00:51 -08006198 int owningUid;
6199 String owningPackage;
6200 if (win != null) {
6201 owningUid = win.getOwningUid();
6202 owningPackage = win.getOwningPackage();
6203 } else {
6204 owningUid = android.os.Process.myUid();
Dianne Hackborn95d78532013-09-11 09:51:14 -07006205 owningPackage = mContext.getOpPackageName();
Dianne Hackbornf265ea92013-01-31 15:00:51 -08006206 }
Amith Yamasanic33cb712010-02-10 15:21:49 -08006207 if (pattern.length == 1) {
6208 // One-shot vibration
John Spurlock7b414672014-07-18 13:02:39 -04006209 mVibrator.vibrate(owningUid, owningPackage, pattern[0], VIBRATION_ATTRIBUTES);
Amith Yamasanic33cb712010-02-10 15:21:49 -08006210 } else {
6211 // Pattern vibration
John Spurlock7b414672014-07-18 13:02:39 -04006212 mVibrator.vibrate(owningUid, owningPackage, pattern, -1, VIBRATION_ATTRIBUTES);
Amith Yamasanic33cb712010-02-10 15:21:49 -08006213 }
6214 return true;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006215 }
Jeff Brownc38c9be2012-10-04 13:16:19 -07006216
6217 @Override
6218 public void keepScreenOnStartedLw() {
Daniel Sandler0601eb72011-04-13 01:01:32 -04006219 }
6220
Jeff Brownc38c9be2012-10-04 13:16:19 -07006221 @Override
6222 public void keepScreenOnStoppedLw() {
Jim Millerab954542014-10-10 18:21:49 -07006223 if (isKeyguardShowingAndNotOccluded()) {
Jim Miller25190572013-02-28 17:36:24 -08006224 mPowerManager.userActivity(SystemClock.uptimeMillis(), false);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006225 }
6226 }
Mike Lockwoodfcb39242009-10-21 23:01:07 -04006227
Dianne Hackborndf89e652011-10-06 22:35:11 -07006228 private int updateSystemUiVisibilityLw() {
Joe Onorato664644d2011-01-23 17:53:23 -08006229 // If there is no window focused, there will be nobody to handle the events
6230 // anyway, so just hang on in whatever state we're in until things settle down.
Adrian Roos53f28ec2014-10-29 17:26:12 +01006231 final WindowState win = mFocusedWindow != null ? mFocusedWindow
6232 : mTopFullscreenOpaqueWindowState;
John Spurlock79da8332013-09-20 12:04:47 -04006233 if (win == null) {
Dianne Hackborndf89e652011-10-06 22:35:11 -07006234 return 0;
6235 }
Jorim Jaggi380ecb82014-03-14 17:25:20 +01006236 if ((win.getAttrs().privateFlags & PRIVATE_FLAG_KEYGUARD) != 0 && mHideLockScreen == true) {
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07006237 // We are updating at a point where the keyguard has gotten
6238 // focus, but we were last in a state where the top window is
6239 // hiding it. This is probably because the keyguard as been
6240 // shown while the top window was displayed, so we want to ignore
6241 // it here because this is just a very transient change and it
6242 // will quickly lose focus once it correctly gets hidden.
6243 return 0;
6244 }
John Spurlock32beb2c2013-03-11 10:16:47 -04006245
John Spurlock1db8b682014-02-18 11:18:59 -05006246 int tmpVisibility = PolicyControl.getSystemUiVisibility(win, null)
Dianne Hackborne26ab702011-10-16 13:21:33 -07006247 & ~mResettingSystemUiFlags
6248 & ~mForceClearedSystemUiFlags;
John Spurlock79da8332013-09-20 12:04:47 -04006249 if (mForcingShowNavBar && win.getSurfaceLayer() < mForcingShowNavBarLayer) {
John Spurlockc6d1c602014-01-17 15:22:06 -05006250 tmpVisibility &= ~PolicyControl.adjustClearableFlags(win, View.SYSTEM_UI_CLEARABLE_FLAGS);
Dianne Hackborn891d3fb2013-01-09 18:31:37 -08006251 }
Adrian Rooscd3884d2015-02-18 17:25:23 +01006252 tmpVisibility = updateLightStatusBarLw(tmpVisibility);
John Spurlock79da8332013-09-20 12:04:47 -04006253 final int visibility = updateSystemBarsLw(win, mLastSystemUiFlags, tmpVisibility);
John Spurlockad3e6cb2013-04-30 08:47:43 -04006254 final int diff = visibility ^ mLastSystemUiFlags;
John Spurlock79da8332013-09-20 12:04:47 -04006255 final boolean needsMenu = win.getNeedsMenuLw(mTopFullscreenOpaqueWindowState);
Dianne Hackborne0f085d2011-11-30 18:41:15 -08006256 if (diff == 0 && mLastFocusNeedsMenu == needsMenu
John Spurlock79da8332013-09-20 12:04:47 -04006257 && mFocusedApp == win.getAppToken()) {
Dianne Hackborndf89e652011-10-06 22:35:11 -07006258 return 0;
6259 }
Dianne Hackborne26ab702011-10-16 13:21:33 -07006260 mLastSystemUiFlags = visibility;
Dianne Hackborn4eff8d32011-11-10 19:38:40 -08006261 mLastFocusNeedsMenu = needsMenu;
John Spurlock79da8332013-09-20 12:04:47 -04006262 mFocusedApp = win.getAppToken();
Dianne Hackborndf89e652011-10-06 22:35:11 -07006263 mHandler.post(new Runnable() {
Craig Mautnereda67292013-04-28 13:50:14 -07006264 @Override
Dianne Hackborndf89e652011-10-06 22:35:11 -07006265 public void run() {
Dianne Hackborn42e620c2012-06-24 13:20:51 -07006266 try {
6267 IStatusBarService statusbar = getStatusBarService();
6268 if (statusbar != null) {
Adrian Roos53f28ec2014-10-29 17:26:12 +01006269 statusbar.setSystemUiVisibility(visibility, 0xffffffff, win.toString());
Dianne Hackborn42e620c2012-06-24 13:20:51 -07006270 statusbar.topAppWindowChanged(needsMenu);
Joe Onorato664644d2011-01-23 17:53:23 -08006271 }
Dianne Hackborn42e620c2012-06-24 13:20:51 -07006272 } catch (RemoteException e) {
6273 // re-acquire status bar service next time it is needed.
6274 mStatusBarService = null;
Joe Onorato664644d2011-01-23 17:53:23 -08006275 }
Dianne Hackborndf89e652011-10-06 22:35:11 -07006276 }
6277 });
6278 return diff;
Joe Onorato664644d2011-01-23 17:53:23 -08006279 }
6280
Adrian Rooscd3884d2015-02-18 17:25:23 +01006281 private int updateLightStatusBarLw(int vis) {
6282 WindowState statusColorWin = isStatusBarKeyguard() && !mHideLockScreen
6283 ? mStatusBar
6284 : mTopFullscreenOpaqueOrDimmingWindowState;
6285
6286 if (statusColorWin != null) {
6287 if (statusColorWin == mTopFullscreenOpaqueWindowState) {
6288 // If the top fullscreen-or-dimming window is also the top fullscreen, respect
6289 // its light flag.
6290 vis &= ~View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR;
6291 vis |= PolicyControl.getSystemUiVisibility(statusColorWin, null)
6292 & View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR;
6293 } else if (statusColorWin != null && statusColorWin.isDimming()) {
6294 // Otherwise if it's dimming, clear the light flag.
6295 vis &= ~View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR;
6296 }
6297 }
6298 return vis;
6299 }
6300
John Spurlock79da8332013-09-20 12:04:47 -04006301 private int updateSystemBarsLw(WindowState win, int oldVis, int vis) {
John Spurlockbd957402013-10-03 11:38:39 -04006302 // apply translucent bar vis flags
Jorim Jaggi380ecb82014-03-14 17:25:20 +01006303 WindowState transWin = isStatusBarKeyguard() && !mHideLockScreen
6304 ? mStatusBar
John Spurlockbd957402013-10-03 11:38:39 -04006305 : mTopFullscreenOpaqueWindowState;
6306 vis = mStatusBarController.applyTranslucentFlagLw(transWin, vis, oldVis);
6307 vis = mNavigationBarController.applyTranslucentFlagLw(transWin, vis, oldVis);
6308
John Spurlock27735a42013-08-14 17:57:38 -04006309 // prevent status bar interaction from clearing certain flags
Selim Cinekf83e8242015-05-19 18:08:14 -07006310 int type = win.getAttrs().type;
6311 boolean statusBarHasFocus = type == TYPE_STATUS_BAR;
John Spurlock08ffcf52014-07-11 10:13:46 -04006312 if (statusBarHasFocus && !isStatusBarKeyguard()) {
John Spurlockad3e6cb2013-04-30 08:47:43 -04006313 int flags = View.SYSTEM_UI_FLAG_FULLSCREEN
6314 | View.SYSTEM_UI_FLAG_HIDE_NAVIGATION
John Spurlockcfc359a2013-09-05 10:42:03 -04006315 | View.SYSTEM_UI_FLAG_IMMERSIVE
Jorim Jaggi73fef8d2015-02-16 17:32:28 +01006316 | View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY
6317 | View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR;
John Spurlock08ffcf52014-07-11 10:13:46 -04006318 if (mHideLockScreen) {
Jorim Jaggi5cf17872014-03-26 18:31:48 +01006319 flags |= View.STATUS_BAR_TRANSLUCENT | View.NAVIGATION_BAR_TRANSLUCENT;
6320 }
John Spurlockbd957402013-10-03 11:38:39 -04006321 vis = (vis & ~flags) | (oldVis & flags);
John Spurlockad3e6cb2013-04-30 08:47:43 -04006322 }
Selim Cinekf83e8242015-05-19 18:08:14 -07006323 if (windowTypeToLayerLw(type) > windowTypeToLayerLw(TYPE_INPUT_CONSUMER)) {
6324 // We can't get into fullscreen from this window otherwise the consumer would not get
6325 // the input events.
6326 vis = (vis & ~View.SYSTEM_UI_FLAG_FULLSCREEN);
6327 }
John Spurlockad3e6cb2013-04-30 08:47:43 -04006328
Adrian Roos4fb3ee32014-08-22 19:29:09 +02006329 if (!areTranslucentBarsAllowed() && transWin != mStatusBar) {
Adrian Roosea562512014-05-05 13:33:03 +02006330 vis &= ~(View.NAVIGATION_BAR_TRANSLUCENT | View.STATUS_BAR_TRANSLUCENT
6331 | View.SYSTEM_UI_TRANSPARENT);
Alan Viverette5a0f4ec2013-10-07 15:10:29 -07006332 }
6333
John Spurlock27735a42013-08-14 17:57:38 -04006334 // update status bar
John Spurlockf1a36642013-10-12 17:50:42 -04006335 boolean immersiveSticky =
6336 (vis & View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY) != 0;
John Spurlock27735a42013-08-14 17:57:38 -04006337 boolean hideStatusBarWM =
John Spurlockbd957402013-10-03 11:38:39 -04006338 mTopFullscreenOpaqueWindowState != null &&
John Spurlockc6d1c602014-01-17 15:22:06 -05006339 (PolicyControl.getWindowFlags(mTopFullscreenOpaqueWindowState, null)
John Spurlock27735a42013-08-14 17:57:38 -04006340 & WindowManager.LayoutParams.FLAG_FULLSCREEN) != 0;
6341 boolean hideStatusBarSysui =
6342 (vis & View.SYSTEM_UI_FLAG_FULLSCREEN) != 0;
John Spurlockf1a36642013-10-12 17:50:42 -04006343 boolean hideNavBarSysui =
6344 (vis & View.SYSTEM_UI_FLAG_HIDE_NAVIGATION) != 0;
John Spurlockad3e6cb2013-04-30 08:47:43 -04006345
John Spurlock27735a42013-08-14 17:57:38 -04006346 boolean transientStatusBarAllowed =
6347 mStatusBar != null && (
6348 hideStatusBarWM
John Spurlockf1a36642013-10-12 17:50:42 -04006349 || (hideStatusBarSysui && immersiveSticky)
John Spurlock27735a42013-08-14 17:57:38 -04006350 || statusBarHasFocus);
6351
John Spurlockf1a36642013-10-12 17:50:42 -04006352 boolean transientNavBarAllowed =
6353 mNavigationBar != null &&
6354 hideNavBarSysui && immersiveSticky;
6355
John Spurlockf25706f2013-11-07 18:02:43 -05006356 boolean denyTransientStatus = mStatusBarController.isTransientShowRequested()
John Spurlockf1a36642013-10-12 17:50:42 -04006357 && !transientStatusBarAllowed && hideStatusBarSysui;
John Spurlockf25706f2013-11-07 18:02:43 -05006358 boolean denyTransientNav = mNavigationBarController.isTransientShowRequested()
John Spurlockf1a36642013-10-12 17:50:42 -04006359 && !transientNavBarAllowed;
6360 if (denyTransientStatus || denyTransientNav) {
John Spurlock27735a42013-08-14 17:57:38 -04006361 // clear the clearable flags instead
John Spurlockf1a36642013-10-12 17:50:42 -04006362 clearClearableFlagsLw();
tiger_huangc58d7562014-10-23 20:24:19 +08006363 vis &= ~View.SYSTEM_UI_CLEARABLE_FLAGS;
John Spurlockad3e6cb2013-04-30 08:47:43 -04006364 }
John Spurlock27735a42013-08-14 17:57:38 -04006365
6366 vis = mStatusBarController.updateVisibilityLw(transientStatusBarAllowed, oldVis, vis);
6367
6368 // update navigation bar
John Spurlockf1a36642013-10-12 17:50:42 -04006369 boolean oldImmersiveMode = isImmersiveMode(oldVis);
6370 boolean newImmersiveMode = isImmersiveMode(vis);
6371 if (win != null && oldImmersiveMode != newImmersiveMode) {
John Spurlock79da8332013-09-20 12:04:47 -04006372 final String pkg = win.getOwningPackage();
Maurice Lam99c6e072014-04-28 18:24:28 -07006373 mImmersiveModeConfirmation.immersiveModeChanged(pkg, newImmersiveMode,
6374 isUserSetupComplete());
John Spurlock34e13d92013-08-10 06:52:28 -04006375 }
John Spurlock27735a42013-08-14 17:57:38 -04006376
John Spurlockf1a36642013-10-12 17:50:42 -04006377 vis = mNavigationBarController.updateVisibilityLw(transientNavBarAllowed, oldVis, vis);
6378
John Spurlocke1f366f2013-08-05 12:22:40 -04006379 return vis;
John Spurlockad3e6cb2013-04-30 08:47:43 -04006380 }
6381
John Spurlockf1a36642013-10-12 17:50:42 -04006382 private void clearClearableFlagsLw() {
6383 int newVal = mResettingSystemUiFlags | View.SYSTEM_UI_CLEARABLE_FLAGS;
6384 if (newVal != mResettingSystemUiFlags) {
6385 mResettingSystemUiFlags = newVal;
6386 mWindowManagerFuncs.reevaluateStatusBarVisibility();
6387 }
6388 }
6389
6390 private boolean isImmersiveMode(int vis) {
6391 final int flags = View.SYSTEM_UI_FLAG_IMMERSIVE | View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY;
John Spurlock34e13d92013-08-10 06:52:28 -04006392 return mNavigationBar != null
6393 && (vis & View.SYSTEM_UI_FLAG_HIDE_NAVIGATION) != 0
Daniel Sandler900ece52013-10-18 15:53:27 -04006394 && (vis & flags) != 0
6395 && canHideNavigationBar();
John Spurlock34e13d92013-08-10 06:52:28 -04006396 }
6397
Alan Viverette5a0f4ec2013-10-07 15:10:29 -07006398 /**
Daniel Sandlerdd73ee42013-10-11 22:19:59 -04006399 * @return whether the navigation or status bar can be made translucent
6400 *
6401 * This should return true unless touch exploration is not enabled or
6402 * R.boolean.config_enableTranslucentDecor is false.
Alan Viverette5a0f4ec2013-10-07 15:10:29 -07006403 */
Daniel Sandlerdd73ee42013-10-11 22:19:59 -04006404 private boolean areTranslucentBarsAllowed() {
Svetoslav8e3feb12014-02-24 13:46:47 -08006405 return mTranslucentDecorEnabled
6406 && !mAccessibilityManager.isTouchExplorationEnabled();
Alan Viverette5a0f4ec2013-10-07 15:10:29 -07006407 }
6408
Daniel Sandler0c4ccff2011-10-19 16:39:14 -04006409 // Use this instead of checking config_showNavigationBar so that it can be consistently
6410 // overridden by qemu.hw.mainkeys in the emulator.
Craig Mautnereda67292013-04-28 13:50:14 -07006411 @Override
Daniel Sandler0c4ccff2011-10-19 16:39:14 -04006412 public boolean hasNavigationBar() {
6413 return mHasNavigationBar;
6414 }
6415
satok1bc0a492012-04-25 22:47:12 +09006416 @Override
6417 public void setLastInputMethodWindowLw(WindowState ime, WindowState target) {
6418 mLastInputMethodWindow = ime;
6419 mLastInputMethodTargetWindow = target;
6420 }
6421
Craig Mautnerf1b67412012-09-19 13:18:29 -07006422 @Override
Satoshi Kataoka658c7b82013-10-10 17:03:51 +09006423 public int getInputMethodWindowVisibleHeightLw() {
6424 return mDockBottom - mCurBottom;
6425 }
6426
6427 @Override
Craig Mautnerf1b67412012-09-19 13:18:29 -07006428 public void setCurrentUserLw(int newUserId) {
Craig Mautnerd625ab22013-09-06 13:40:31 -07006429 mCurrentUserId = newUserId;
Jim Miller5ecd8112013-01-09 18:50:26 -08006430 if (mKeyguardDelegate != null) {
6431 mKeyguardDelegate.setCurrentUser(newUserId);
Craig Mautnerf1b67412012-09-19 13:18:29 -07006432 }
John Spurlock13451a22012-09-28 14:40:41 -04006433 if (mStatusBarService != null) {
6434 try {
6435 mStatusBarService.setCurrentUser(newUserId);
6436 } catch (RemoteException e) {
6437 // oh well
6438 }
6439 }
Dianne Hackborn2ea9bae2012-11-02 18:43:48 -07006440 setLastInputMethodWindowLw(null, null);
Craig Mautnerf1b67412012-09-19 13:18:29 -07006441 }
6442
6443 @Override
Svetoslav Ganov545252f2012-12-10 18:29:24 -08006444 public boolean canMagnifyWindow(int windowType) {
6445 switch (windowType) {
6446 case WindowManager.LayoutParams.TYPE_INPUT_METHOD:
6447 case WindowManager.LayoutParams.TYPE_INPUT_METHOD_DIALOG:
6448 case WindowManager.LayoutParams.TYPE_NAVIGATION_BAR:
6449 case WindowManager.LayoutParams.TYPE_MAGNIFICATION_OVERLAY: {
6450 return false;
6451 }
6452 }
6453 return true;
6454 }
6455
6456 @Override
6457 public boolean isTopLevelWindow(int windowType) {
6458 if (windowType >= WindowManager.LayoutParams.FIRST_SUB_WINDOW
6459 && windowType <= WindowManager.LayoutParams.LAST_SUB_WINDOW) {
6460 return (windowType == WindowManager.LayoutParams.TYPE_APPLICATION_ATTACHED_DIALOG);
6461 }
6462 return true;
6463 }
6464
Jim Miller4eeb4f62012-11-08 00:04:29 -08006465 @Override
Jeff Brownd7a04de2012-06-17 14:17:52 -07006466 public void dump(String prefix, PrintWriter pw, String[] args) {
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08006467 pw.print(prefix); pw.print("mSafeMode="); pw.print(mSafeMode);
Dianne Hackbornba24e4d2011-09-01 11:17:06 -07006468 pw.print(" mSystemReady="); pw.print(mSystemReady);
6469 pw.print(" mSystemBooted="); pw.println(mSystemBooted);
Jeff Brown2e7760e2012-04-11 15:14:55 -07006470 pw.print(prefix); pw.print("mLidState="); pw.print(mLidState);
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08006471 pw.print(" mLidOpenRotation="); pw.print(mLidOpenRotation);
Michael Wright3818c922014-09-02 13:59:07 -07006472 pw.print(" mCameraLensCoverState="); pw.print(mCameraLensCoverState);
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08006473 pw.print(" mHdmiPlugged="); pw.println(mHdmiPlugged);
Dianne Hackborne26ab702011-10-16 13:21:33 -07006474 if (mLastSystemUiFlags != 0 || mResettingSystemUiFlags != 0
6475 || mForceClearedSystemUiFlags != 0) {
6476 pw.print(prefix); pw.print("mLastSystemUiFlags=0x");
6477 pw.print(Integer.toHexString(mLastSystemUiFlags));
6478 pw.print(" mResettingSystemUiFlags=0x");
6479 pw.print(Integer.toHexString(mResettingSystemUiFlags));
6480 pw.print(" mForceClearedSystemUiFlags=0x");
6481 pw.println(Integer.toHexString(mForceClearedSystemUiFlags));
Dianne Hackborndf89e652011-10-06 22:35:11 -07006482 }
Dianne Hackborn4eff8d32011-11-10 19:38:40 -08006483 if (mLastFocusNeedsMenu) {
6484 pw.print(prefix); pw.print("mLastFocusNeedsMenu=");
6485 pw.println(mLastFocusNeedsMenu);
6486 }
Jeff Browna20dda42014-05-27 20:57:24 -07006487 pw.print(prefix); pw.print("mWakeGestureEnabledSetting=");
6488 pw.println(mWakeGestureEnabledSetting);
6489
Jeff Brownbcdfc622014-03-06 19:13:04 -08006490 pw.print(prefix); pw.print("mSupportAutoRotation="); pw.println(mSupportAutoRotation);
Daniel Sandler6396c722013-04-16 20:19:09 -04006491 pw.print(prefix); pw.print("mUiMode="); pw.print(mUiMode);
6492 pw.print(" mDockMode="); pw.print(mDockMode);
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08006493 pw.print(" mCarDockRotation="); pw.print(mCarDockRotation);
6494 pw.print(" mDeskDockRotation="); pw.println(mDeskDockRotation);
6495 pw.print(prefix); pw.print("mUserRotationMode="); pw.print(mUserRotationMode);
6496 pw.print(" mUserRotation="); pw.print(mUserRotation);
Daniel Sandler2ed6ad62011-02-22 14:54:17 -05006497 pw.print(" mAllowAllRotations="); pw.println(mAllowAllRotations);
Dianne Hackborn6e2281d2012-06-19 17:48:32 -07006498 pw.print(prefix); pw.print("mCurrentAppOrientation="); pw.println(mCurrentAppOrientation);
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08006499 pw.print(prefix); pw.print("mCarDockEnablesAccelerometer=");
6500 pw.print(mCarDockEnablesAccelerometer);
6501 pw.print(" mDeskDockEnablesAccelerometer=");
6502 pw.println(mDeskDockEnablesAccelerometer);
6503 pw.print(prefix); pw.print("mLidKeyboardAccessibility=");
6504 pw.print(mLidKeyboardAccessibility);
6505 pw.print(" mLidNavigationAccessibility="); pw.print(mLidNavigationAccessibility);
Dianne Hackborn6e2281d2012-06-19 17:48:32 -07006506 pw.print(" mLidControlsSleep="); pw.println(mLidControlsSleep);
Jeff Brown6d8fd272014-05-20 21:24:38 -07006507 pw.print(prefix);
6508 pw.print("mShortPressOnPowerBehavior="); pw.print(mShortPressOnPowerBehavior);
6509 pw.print(" mLongPressOnPowerBehavior="); pw.println(mLongPressOnPowerBehavior);
Jeff Brown13f00f02014-10-31 14:45:50 -07006510 pw.print(prefix);
6511 pw.print("mDoublePressOnPowerBehavior="); pw.print(mDoublePressOnPowerBehavior);
6512 pw.print(" mTriplePressOnPowerBehavior="); pw.println(mTriplePressOnPowerBehavior);
Jeff Brown6d8fd272014-05-20 21:24:38 -07006513 pw.print(prefix); pw.print("mHasSoftInput="); pw.println(mHasSoftInput);
Jeff Brown3ee549c2014-09-22 20:14:39 -07006514 pw.print(prefix); pw.print("mAwake="); pw.println(mAwake);
6515 pw.print(prefix); pw.print("mScreenOnEarly="); pw.print(mScreenOnEarly);
6516 pw.print(" mScreenOnFully="); pw.println(mScreenOnFully);
6517 pw.print(prefix); pw.print("mKeyguardDrawComplete="); pw.print(mKeyguardDrawComplete);
6518 pw.print(" mWindowManagerDrawComplete="); pw.println(mWindowManagerDrawComplete);
6519 pw.print(prefix); pw.print("mOrientationSensorEnabled=");
6520 pw.println(mOrientationSensorEnabled);
Dianne Hackbornc652de82013-02-15 16:32:56 -08006521 pw.print(prefix); pw.print("mOverscanScreen=("); pw.print(mOverscanScreenLeft);
6522 pw.print(","); pw.print(mOverscanScreenTop);
6523 pw.print(") "); pw.print(mOverscanScreenWidth);
6524 pw.print("x"); pw.println(mOverscanScreenHeight);
6525 if (mOverscanLeft != 0 || mOverscanTop != 0
6526 || mOverscanRight != 0 || mOverscanBottom != 0) {
6527 pw.print(prefix); pw.print("mOverscan left="); pw.print(mOverscanLeft);
6528 pw.print(" top="); pw.print(mOverscanTop);
6529 pw.print(" right="); pw.print(mOverscanRight);
6530 pw.print(" bottom="); pw.println(mOverscanBottom);
6531 }
Dianne Hackborn313440842013-02-19 19:22:59 -08006532 pw.print(prefix); pw.print("mRestrictedOverscanScreen=(");
6533 pw.print(mRestrictedOverscanScreenLeft);
6534 pw.print(","); pw.print(mRestrictedOverscanScreenTop);
6535 pw.print(") "); pw.print(mRestrictedOverscanScreenWidth);
6536 pw.print("x"); pw.println(mRestrictedOverscanScreenHeight);
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08006537 pw.print(prefix); pw.print("mUnrestrictedScreen=("); pw.print(mUnrestrictedScreenLeft);
6538 pw.print(","); pw.print(mUnrestrictedScreenTop);
6539 pw.print(") "); pw.print(mUnrestrictedScreenWidth);
6540 pw.print("x"); pw.println(mUnrestrictedScreenHeight);
6541 pw.print(prefix); pw.print("mRestrictedScreen=("); pw.print(mRestrictedScreenLeft);
6542 pw.print(","); pw.print(mRestrictedScreenTop);
6543 pw.print(") "); pw.print(mRestrictedScreenWidth);
6544 pw.print("x"); pw.println(mRestrictedScreenHeight);
Dianne Hackborn5b5cc4d2012-05-16 13:15:00 -07006545 pw.print(prefix); pw.print("mStableFullscreen=("); pw.print(mStableFullscreenLeft);
6546 pw.print(","); pw.print(mStableFullscreenTop);
6547 pw.print(")-("); pw.print(mStableFullscreenRight);
6548 pw.print(","); pw.print(mStableFullscreenBottom); pw.println(")");
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07006549 pw.print(prefix); pw.print("mStable=("); pw.print(mStableLeft);
6550 pw.print(","); pw.print(mStableTop);
6551 pw.print(")-("); pw.print(mStableRight);
6552 pw.print(","); pw.print(mStableBottom); pw.println(")");
Dianne Hackborn5c58de32012-04-28 19:52:37 -07006553 pw.print(prefix); pw.print("mSystem=("); pw.print(mSystemLeft);
6554 pw.print(","); pw.print(mSystemTop);
6555 pw.print(")-("); pw.print(mSystemRight);
6556 pw.print(","); pw.print(mSystemBottom); pw.println(")");
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08006557 pw.print(prefix); pw.print("mCur=("); pw.print(mCurLeft);
6558 pw.print(","); pw.print(mCurTop);
6559 pw.print(")-("); pw.print(mCurRight);
6560 pw.print(","); pw.print(mCurBottom); pw.println(")");
6561 pw.print(prefix); pw.print("mContent=("); pw.print(mContentLeft);
6562 pw.print(","); pw.print(mContentTop);
6563 pw.print(")-("); pw.print(mContentRight);
6564 pw.print(","); pw.print(mContentBottom); pw.println(")");
Dianne Hackborne30e02f2014-05-27 18:24:45 -07006565 pw.print(prefix); pw.print("mVoiceContent=("); pw.print(mVoiceContentLeft);
6566 pw.print(","); pw.print(mVoiceContentTop);
6567 pw.print(")-("); pw.print(mVoiceContentRight);
6568 pw.print(","); pw.print(mVoiceContentBottom); pw.println(")");
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08006569 pw.print(prefix); pw.print("mDock=("); pw.print(mDockLeft);
6570 pw.print(","); pw.print(mDockTop);
6571 pw.print(")-("); pw.print(mDockRight);
6572 pw.print(","); pw.print(mDockBottom); pw.println(")");
Dianne Hackborn5c58de32012-04-28 19:52:37 -07006573 pw.print(prefix); pw.print("mDockLayer="); pw.print(mDockLayer);
6574 pw.print(" mStatusBarLayer="); pw.println(mStatusBarLayer);
Dianne Hackborn7ad44382012-10-18 17:46:00 -07006575 pw.print(prefix); pw.print("mShowingLockscreen="); pw.print(mShowingLockscreen);
6576 pw.print(" mShowingDream="); pw.print(mShowingDream);
Jeff Brown061ea992015-04-17 19:55:47 -07006577 pw.print(" mDreamingLockscreen="); pw.print(mDreamingLockscreen);
6578 pw.print(" mDreamingSleepToken="); pw.println(mDreamingSleepToken);
Dianne Hackborn2ea9bae2012-11-02 18:43:48 -07006579 if (mLastInputMethodWindow != null) {
6580 pw.print(prefix); pw.print("mLastInputMethodWindow=");
6581 pw.println(mLastInputMethodWindow);
6582 }
6583 if (mLastInputMethodTargetWindow != null) {
6584 pw.print(prefix); pw.print("mLastInputMethodTargetWindow=");
6585 pw.println(mLastInputMethodTargetWindow);
6586 }
6587 if (mStatusBar != null) {
6588 pw.print(prefix); pw.print("mStatusBar=");
Dianne Hackbornae6688b2015-02-11 17:02:41 -08006589 pw.print(mStatusBar); pw.print(" isStatusBarKeyguard=");
6590 pw.println(isStatusBarKeyguard());
Dianne Hackborn2ea9bae2012-11-02 18:43:48 -07006591 }
6592 if (mNavigationBar != null) {
6593 pw.print(prefix); pw.print("mNavigationBar=");
6594 pw.println(mNavigationBar);
6595 }
Dianne Hackborn2ea9bae2012-11-02 18:43:48 -07006596 if (mFocusedWindow != null) {
6597 pw.print(prefix); pw.print("mFocusedWindow=");
6598 pw.println(mFocusedWindow);
6599 }
6600 if (mFocusedApp != null) {
6601 pw.print(prefix); pw.print("mFocusedApp=");
6602 pw.println(mFocusedApp);
6603 }
6604 if (mWinDismissingKeyguard != null) {
6605 pw.print(prefix); pw.print("mWinDismissingKeyguard=");
6606 pw.println(mWinDismissingKeyguard);
6607 }
6608 if (mTopFullscreenOpaqueWindowState != null) {
6609 pw.print(prefix); pw.print("mTopFullscreenOpaqueWindowState=");
6610 pw.println(mTopFullscreenOpaqueWindowState);
6611 }
Adrian Rooscd3884d2015-02-18 17:25:23 +01006612 if (mTopFullscreenOpaqueOrDimmingWindowState != null) {
6613 pw.print(prefix); pw.print("mTopFullscreenOpaqueOrDimmingWindowState=");
6614 pw.println(mTopFullscreenOpaqueOrDimmingWindowState);
6615 }
Dianne Hackborn891d3fb2013-01-09 18:31:37 -08006616 if (mForcingShowNavBar) {
6617 pw.print(prefix); pw.print("mForcingShowNavBar=");
6618 pw.println(mForcingShowNavBar); pw.print( "mForcingShowNavBarLayer=");
6619 pw.println(mForcingShowNavBarLayer);
6620 }
Dianne Hackborn7ad44382012-10-18 17:46:00 -07006621 pw.print(prefix); pw.print("mTopIsFullscreen="); pw.print(mTopIsFullscreen);
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08006622 pw.print(" mHideLockScreen="); pw.println(mHideLockScreen);
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07006623 pw.print(prefix); pw.print("mForceStatusBar="); pw.print(mForceStatusBar);
6624 pw.print(" mForceStatusBarFromKeyguard=");
6625 pw.println(mForceStatusBarFromKeyguard);
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08006626 pw.print(prefix); pw.print("mDismissKeyguard="); pw.print(mDismissKeyguard);
Craig Mautnerad09bcc2012-10-08 13:33:11 -07006627 pw.print(" mWinDismissingKeyguard="); pw.print(mWinDismissingKeyguard);
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08006628 pw.print(" mHomePressed="); pw.println(mHomePressed);
6629 pw.print(prefix); pw.print("mAllowLockscreenWhenOn="); pw.print(mAllowLockscreenWhenOn);
6630 pw.print(" mLockScreenTimeout="); pw.print(mLockScreenTimeout);
6631 pw.print(" mLockScreenTimerActive="); pw.println(mLockScreenTimerActive);
6632 pw.print(prefix); pw.print("mEndcallBehavior="); pw.print(mEndcallBehavior);
6633 pw.print(" mIncallPowerBehavior="); pw.print(mIncallPowerBehavior);
6634 pw.print(" mLongPressOnHomeBehavior="); pw.println(mLongPressOnHomeBehavior);
6635 pw.print(prefix); pw.print("mLandscapeRotation="); pw.print(mLandscapeRotation);
6636 pw.print(" mSeascapeRotation="); pw.println(mSeascapeRotation);
6637 pw.print(prefix); pw.print("mPortraitRotation="); pw.print(mPortraitRotation);
6638 pw.print(" mUpsideDownRotation="); pw.println(mUpsideDownRotation);
Jeff Brownc82c89ed2013-04-17 17:18:15 -07006639 pw.print(prefix); pw.print("mDemoHdmiRotation="); pw.print(mDemoHdmiRotation);
6640 pw.print(" mDemoHdmiRotationLock="); pw.println(mDemoHdmiRotationLock);
6641 pw.print(prefix); pw.print("mUndockedHdmiRotation="); pw.println(mUndockedHdmiRotation);
Jeff Brown600f0032014-05-22 17:06:00 -07006642
Tim Kilbournd7c0c2e2014-05-29 16:08:10 -07006643 mGlobalKeyManager.dump(prefix, pw);
John Spurlock27735a42013-08-14 17:57:38 -04006644 mStatusBarController.dump(pw, prefix);
6645 mNavigationBarController.dump(pw, prefix);
John Spurlockc6d1c602014-01-17 15:22:06 -05006646 PolicyControl.dump(prefix, pw);
Jeff Brown600f0032014-05-22 17:06:00 -07006647
Jeff Browna20dda42014-05-27 20:57:24 -07006648 if (mWakeGestureListener != null) {
6649 mWakeGestureListener.dump(pw, prefix);
6650 }
Jeff Brown600f0032014-05-22 17:06:00 -07006651 if (mOrientationListener != null) {
6652 mOrientationListener.dump(pw, prefix);
6653 }
Filip Gruszczynskicfb31852015-02-25 21:47:12 +00006654 if (mBurnInProtectionHelper != null) {
6655 mBurnInProtectionHelper.dump(prefix, pw);
6656 }
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08006657 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006658}